linux-stable/drivers/staging/unisys/visorbus/visorchannel.c

617 lines
16 KiB
C
Raw Normal View History

/* visorchannel_funcs.c
*
* Copyright (C) 2010 - 2013 UNISYS CORPORATION
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
* NON INFRINGEMENT. See the GNU General Public License for more
* details.
*/
/*
* This provides Supervisor channel communication primitives, which are
* independent of the mechanism used to access the channel data.
*/
#include <linux/uuid.h>
#include "version.h"
#include "visorbus.h"
#include "controlvmchannel.h"
#define MYDRVNAME "visorchannel"
#define SPAR_CONSOLEVIDEO_CHANNEL_PROTOCOL_GUID \
UUID_LE(0x3cd6e705, 0xd6a2, 0x4aa5, \
0xad, 0x5c, 0x7b, 0x8, 0x88, 0x9d, 0xff, 0xe2)
static const uuid_le spar_video_guid = SPAR_CONSOLEVIDEO_CHANNEL_PROTOCOL_GUID;
struct visorchannel {
u64 physaddr;
ulong nbytes;
void __iomem *mapped;
bool requested;
struct channel_header chan_hdr;
uuid_le guid;
ulong size;
bool needs_lock; /* channel creator knows if more than one
* thread will be inserting or removing */
spinlock_t insert_lock; /* protect head writes in chan_hdr */
spinlock_t remove_lock; /* protect tail writes in chan_hdr */
struct {
struct signal_queue_header req_queue;
struct signal_queue_header rsp_queue;
struct signal_queue_header event_queue;
struct signal_queue_header ack_queue;
} safe_uis_queue;
uuid_le type;
uuid_le inst;
};
/* Creates the struct visorchannel abstraction for a data area in memory,
* but does NOT modify this data area.
*/
static struct visorchannel *
visorchannel_create_guts(u64 physaddr, unsigned long channel_bytes,
gfp_t gfp, unsigned long off,
uuid_le guid, bool needs_lock)
{
struct visorchannel *channel;
int err;
size_t size = sizeof(struct channel_header);
if (physaddr == 0)
return NULL;
channel = kzalloc(sizeof(*channel), gfp);
if (!channel)
goto cleanup;
channel->needs_lock = needs_lock;
spin_lock_init(&channel->insert_lock);
spin_lock_init(&channel->remove_lock);
/* Video driver constains the efi framebuffer so it will get a
* conflict resource when requesting its full mem region. Since
* we are only using the efi framebuffer for video we can ignore
* this. Remember that we haven't requested it so we don't try to
* release later on.
*/
channel->requested = request_mem_region(physaddr, size, MYDRVNAME);
if (!channel->requested) {
if (uuid_le_cmp(guid, spar_video_guid)) {
/* Not the video channel we care about this */
goto cleanup;
}
}
channel->mapped = ioremap_cache(physaddr, size);
if (!channel->mapped) {
release_mem_region(physaddr, size);
goto cleanup;
}
channel->physaddr = physaddr;
channel->nbytes = size;
err = visorchannel_read(channel, 0, &channel->chan_hdr,
sizeof(struct channel_header));
if (err)
goto cleanup;
/* we had better be a CLIENT of this channel */
if (channel_bytes == 0)
channel_bytes = (ulong)channel->chan_hdr.size;
if (uuid_le_cmp(guid, NULL_UUID_LE) == 0)
guid = channel->chan_hdr.chtype;
iounmap(channel->mapped);
if (channel->requested)
release_mem_region(channel->physaddr, channel->nbytes);
channel->mapped = NULL;
channel->requested = request_mem_region(channel->physaddr,
channel_bytes, MYDRVNAME);
if (!channel->requested) {
if (uuid_le_cmp(guid, spar_video_guid)) {
/* Different we care about this */
goto cleanup;
}
}
channel->mapped = ioremap_cache(channel->physaddr, channel_bytes);
if (!channel->mapped) {
release_mem_region(channel->physaddr, channel_bytes);
goto cleanup;
}
channel->nbytes = channel_bytes;
channel->size = channel_bytes;
channel->guid = guid;
return channel;
cleanup:
visorchannel_destroy(channel);
return NULL;
}
struct visorchannel *
visorchannel_create(u64 physaddr, unsigned long channel_bytes,
gfp_t gfp, uuid_le guid)
{
return visorchannel_create_guts(physaddr, channel_bytes, gfp, 0, guid,
false);
}
EXPORT_SYMBOL_GPL(visorchannel_create);
struct visorchannel *
visorchannel_create_with_lock(u64 physaddr, unsigned long channel_bytes,
gfp_t gfp, uuid_le guid)
{
return visorchannel_create_guts(physaddr, channel_bytes, gfp, 0, guid,
true);
}
EXPORT_SYMBOL_GPL(visorchannel_create_with_lock);
void
visorchannel_destroy(struct visorchannel *channel)
{
if (!channel)
return;
if (channel->mapped) {
iounmap(channel->mapped);
if (channel->requested)
release_mem_region(channel->physaddr, channel->nbytes);
}
kfree(channel);
}
EXPORT_SYMBOL_GPL(visorchannel_destroy);
u64
visorchannel_get_physaddr(struct visorchannel *channel)
{
return channel->physaddr;
}
EXPORT_SYMBOL_GPL(visorchannel_get_physaddr);
ulong
visorchannel_get_nbytes(struct visorchannel *channel)
{
return channel->size;
}
EXPORT_SYMBOL_GPL(visorchannel_get_nbytes);
char *
visorchannel_uuid_id(uuid_le *guid, char *s)
{
sprintf(s, "%pUL", guid);
return s;
}
EXPORT_SYMBOL_GPL(visorchannel_uuid_id);
char *
visorchannel_id(struct visorchannel *channel, char *s)
{
return visorchannel_uuid_id(&channel->guid, s);
}
EXPORT_SYMBOL_GPL(visorchannel_id);
char *
visorchannel_zoneid(struct visorchannel *channel, char *s)
{
return visorchannel_uuid_id(&channel->chan_hdr.zone_uuid, s);
}
EXPORT_SYMBOL_GPL(visorchannel_zoneid);
u64
visorchannel_get_clientpartition(struct visorchannel *channel)
{
return channel->chan_hdr.partition_handle;
}
EXPORT_SYMBOL_GPL(visorchannel_get_clientpartition);
int
visorchannel_set_clientpartition(struct visorchannel *channel,
u64 partition_handle)
{
channel->chan_hdr.partition_handle = partition_handle;
return 0;
}
EXPORT_SYMBOL_GPL(visorchannel_set_clientpartition);
uuid_le
visorchannel_get_uuid(struct visorchannel *channel)
{
return channel->guid;
}
EXPORT_SYMBOL_GPL(visorchannel_get_uuid);
int
visorchannel_read(struct visorchannel *channel, ulong offset,
void *local, ulong nbytes)
{
if (offset + nbytes > channel->nbytes)
return -EIO;
memcpy_fromio(local, channel->mapped + offset, nbytes);
return 0;
}
EXPORT_SYMBOL_GPL(visorchannel_read);
int
visorchannel_write(struct visorchannel *channel, ulong offset,
void *local, ulong nbytes)
{
size_t chdr_size = sizeof(struct channel_header);
size_t copy_size;
if (offset + nbytes > channel->nbytes)
return -EIO;
if (offset < chdr_size) {
copy_size = min(chdr_size - offset, nbytes);
memcpy(((char *)(&channel->chan_hdr)) + offset,
local, copy_size);
}
memcpy_toio(channel->mapped + offset, local, nbytes);
return 0;
}
EXPORT_SYMBOL_GPL(visorchannel_write);
int
visorchannel_clear(struct visorchannel *channel, ulong offset, u8 ch,
ulong nbytes)
{
int err;
int bufsize = PAGE_SIZE;
int written = 0;
u8 *buf;
buf = (u8 *) __get_free_page(GFP_KERNEL);
if (!buf)
return -ENOMEM;
memset(buf, ch, bufsize);
while (nbytes > 0) {
int thisbytes = bufsize;
if (nbytes < thisbytes)
thisbytes = nbytes;
err = visorchannel_write(channel, offset + written,
buf, thisbytes);
if (err)
goto cleanup;
written += thisbytes;
nbytes -= thisbytes;
}
err = 0;
cleanup:
free_page((unsigned long) buf);
return err;
}
EXPORT_SYMBOL_GPL(visorchannel_clear);
void __iomem *
visorchannel_get_header(struct visorchannel *channel)
{
return (void __iomem *)&channel->chan_hdr;
}
EXPORT_SYMBOL_GPL(visorchannel_get_header);
/** Return offset of a specific SIGNAL_QUEUE_HEADER from the beginning of a
* channel header
*/
#define SIG_QUEUE_OFFSET(chan_hdr, q) \
((chan_hdr)->ch_space_offset + \
((q) * sizeof(struct signal_queue_header)))
/** Return offset of a specific queue entry (data) from the beginning of a
* channel header
*/
#define SIG_DATA_OFFSET(chan_hdr, q, sig_hdr, slot) \
(SIG_QUEUE_OFFSET(chan_hdr, q) + (sig_hdr)->sig_base_offset + \
((slot) * (sig_hdr)->signal_size))
/** Write the contents of a specific field within a SIGNAL_QUEUE_HEADER back
* into host memory
*/
#define SIG_WRITE_FIELD(channel, queue, sig_hdr, FIELD) \
(visorchannel_write(channel, \
SIG_QUEUE_OFFSET(&channel->chan_hdr, queue)+ \
offsetof(struct signal_queue_header, FIELD), \
&((sig_hdr)->FIELD), \
sizeof((sig_hdr)->FIELD)) >= 0)
static bool
sig_read_header(struct visorchannel *channel, u32 queue,
struct signal_queue_header *sig_hdr)
{
int err;
if (channel->chan_hdr.ch_space_offset < sizeof(struct channel_header))
return false;
/* Read the appropriate SIGNAL_QUEUE_HEADER into local memory. */
err = visorchannel_read(channel,
SIG_QUEUE_OFFSET(&channel->chan_hdr, queue),
sig_hdr, sizeof(struct signal_queue_header));
if (err)
return false;
return true;
}
static inline bool
sig_read_data(struct visorchannel *channel, u32 queue,
struct signal_queue_header *sig_hdr, u32 slot, void *data)
{
int err;
int signal_data_offset = SIG_DATA_OFFSET(&channel->chan_hdr, queue,
sig_hdr, slot);
err = visorchannel_read(channel, signal_data_offset,
data, sig_hdr->signal_size);
if (err)
return false;
return true;
}
static inline bool
sig_write_data(struct visorchannel *channel, u32 queue,
struct signal_queue_header *sig_hdr, u32 slot, void *data)
{
int err;
int signal_data_offset = SIG_DATA_OFFSET(&channel->chan_hdr, queue,
sig_hdr, slot);
err = visorchannel_write(channel, signal_data_offset,
data, sig_hdr->signal_size);
if (err)
return false;
return true;
}
static bool
signalremove_inner(struct visorchannel *channel, u32 queue, void *msg)
{
struct signal_queue_header sig_hdr;
if (!sig_read_header(channel, queue, &sig_hdr))
return false;
if (sig_hdr.head == sig_hdr.tail)
return false; /* no signals to remove */
sig_hdr.tail = (sig_hdr.tail + 1) % sig_hdr.max_slots;
if (!sig_read_data(channel, queue, &sig_hdr, sig_hdr.tail, msg))
return false;
sig_hdr.num_received++;
/* For each data field in SIGNAL_QUEUE_HEADER that was modified,
* update host memory.
*/
mb(); /* required for channel synch */
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, tail))
return false;
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_received))
return false;
return true;
}
bool
visorchannel_signalremove(struct visorchannel *channel, u32 queue, void *msg)
{
bool rc;
staging: unisys: fix random hangs with network stress in visornic We learned that it was possible for the core networking code to call visornic_xmit() within ISR context, resulting in the need for us to use spin_lock_irqsave() / spin_lock_irqrestore() to lock accesses to our virtual device channels. Without the correct locking added in this patch, random hangs would occur on typical kernels while stressing the netork. When using a kernel with CONFIG_DEBUG_SPINLOCK=y, a stackdump would occur at the time of the hang reporting: BUG: spinlock recursion on CPU#0, vnic_incoming/<pid> (see below for more details) We considered the possibility of adding a protocol between a visordriver and visorbus where the visordriver could specify which type of locking it required for its virtual device channels (essentially indicating whether or not it was possible for the channel to be accessed in ISR context), but decided this extra complexity was NOT needed, and that channel queues should always be accessed with the most-stringent locking. So that is what is implemented in this commit. Below is an example stackdump illustrating the spinlock recursion that is fixed by this commit. Note that we are first in virtnic_rx() writing to the device channel when an APIC timer interrupt occurs. Within the core networking code, net_rx_action() calls process_backlog(), which eventually lands up back up in virtnic_xmit() in the code attempting to also write to the device channel. BUG: spinlock recursion on CPU#0, vnic_incoming/262 lock: 0xffff88002db810c0, .magic: dead4ead, .owner: vnic_incoming/262, .owner_cpu: 0 CPU: 0 PID: 262 Comm: vnic_incoming Tainted: G C 4.2.0-rc1-ARCH+ #56 Hardware name: Dell Inc. PowerEdge T110/ , BIOS 1.23 12/15/2009 ffff8800216ac200 ffff88002c803388 ffffffff81476364 0000000000000106 ffff88002db810c0 ffff88002c8033a8 ffffffff8109e2bc ffff88002db810c0 ffffffff817631d4 ffff88002c8033c8 ffffffff8109e330 ffff88002db810c0 Call Trace: <IRQ> [<ffffffff81476364>] dump_stack+0x4f/0x73 [<ffffffff8109e2bc>] spin_dump+0x7c/0xc0 [<ffffffff8109e330>] spin_bug+0x30/0x40 [<ffffffff8109e547>] do_raw_spin_lock+0x127/0x140 [<ffffffff8147bad0>] _raw_spin_lock+0x40/0x50 [<ffffffffa0151fa6>] ? visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa0151fa6>] visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa01683a2>] visornic_xmit+0x302/0x5d0 [visornic] [<ffffffff813b2f30>] dev_hard_start_xmit+0x2e0/0x510 [<ffffffff813b2b75>] ? validate_xmit_skb+0x235/0x310 [<ffffffff813d79e7>] sch_direct_xmit+0xf7/0x1d0 [<ffffffff813b34d3>] __dev_queue_xmit+0x203/0x640 [<ffffffff813b3320>] ? __dev_queue_xmit+0x50/0x640 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff813b3933>] dev_queue_xmit_sk+0x13/0x20 [<ffffffff813f3a5c>] ip_finish_output2+0x22c/0x470 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813f3f6f>] ip_finish_output+0x1df/0x310 [<ffffffff813f4c31>] ip_output+0xb1/0x100 [<ffffffff813f41be>] ip_local_out_sk+0x3e/0x80 [<ffffffff813f4388>] ip_queue_xmit+0x188/0x4a0 [<ffffffff813f4200>] ? ip_local_out_sk+0x80/0x80 [<ffffffff8139fcd6>] ? __alloc_skb+0x86/0x1e0 [<ffffffff8140bd5b>] tcp_transmit_skb+0x4cb/0x9c0 [<ffffffff8139f0dc>] ? __kmalloc_reserve+0x3c/0x90 [<ffffffff8139fcea>] ? __alloc_skb+0x9a/0x1e0 [<ffffffff8140c47d>] tcp_send_ack+0x10d/0x150 [<ffffffff814060ee>] __tcp_ack_snd_check+0x5e/0x90 [<ffffffff81408eb4>] tcp_rcv_established+0x354/0x710 [<ffffffff81412182>] tcp_v4_do_rcv+0x162/0x3f0 [<ffffffff81414412>] tcp_v4_rcv+0xb22/0xb50 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee350>] ip_local_deliver_finish+0xe0/0x2d0 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee72e>] ip_local_deliver+0xae/0xc0 [<ffffffff813edeaf>] ip_rcv_finish+0x14f/0x510 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff813eea13>] ip_rcv+0x2d3/0x3b0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff813ab0f3>] __netif_receive_skb_core+0x663/0xb70 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff810971a9>] ? cpuacct_charge+0x99/0xb0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813ab72c>] ? process_backlog+0xbc/0x150 [<ffffffff813ab78b>] ? process_backlog+0x11b/0x150 [<ffffffff813ab627>] __netif_receive_skb+0x27/0x70 [<ffffffff813ab702>] process_backlog+0x92/0x150 [<ffffffff813afffd>] net_rx_action+0x13d/0x350 [<ffffffff81036b2d>] ? lapic_next_event+0x1d/0x30 [<ffffffff81058694>] __do_softirq+0x104/0x320 [<ffffffff810c0788>] ? hrtimer_interrupt+0xc8/0x1a0 [<ffffffff81074e70>] ? blocking_notifier_chain_cond_register+0x70/0x70 [<ffffffff81058ab9>] irq_exit+0x79/0xa0 [<ffffffff8147ecca>] smp_apic_timer_interrupt+0x4a/0x60 [<ffffffff8147d2c8>] apic_timer_interrupt+0x68/0x70 <EOI> [<ffffffff81271c02>] ? __memcpy+0x12/0x20 [<ffffffffa01517da>] ? visorchannel_write+0x4a/0x80 [visorbus] [<ffffffffa0151eb8>] signalinsert_inner+0x88/0x130 [visorbus] [<ffffffffa0151fb5>] visorchannel_signalinsert+0x55/0x70 [visorbus] [<ffffffffa0166e57>] visornic_rx+0x12e7/0x19d0 [visornic] [<ffffffffa01677c9>] process_incoming_rsps+0x289/0x690 [visornic] [<ffffffff814771c5>] ? preempt_schedule+0x25/0x30 [<ffffffff81001026>] ? ___preempt_schedule+0x12/0x14 [<ffffffff81093080>] ? wait_woken+0x90/0x90 [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffff81073a39>] kthread+0xe9/0x110 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 [<ffffffff8147c89f>] ret_from_fork+0x3f/0x70 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 Fixes: b12fdf7da ('staging: unisys: rework signal remove/insert to avoid sparse lock warnings') Signed-off-by: Tim Sell <Timothy.Sell@unisys.com> Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-07-14 18:43:30 +00:00
unsigned long flags;
if (channel->needs_lock) {
staging: unisys: fix random hangs with network stress in visornic We learned that it was possible for the core networking code to call visornic_xmit() within ISR context, resulting in the need for us to use spin_lock_irqsave() / spin_lock_irqrestore() to lock accesses to our virtual device channels. Without the correct locking added in this patch, random hangs would occur on typical kernels while stressing the netork. When using a kernel with CONFIG_DEBUG_SPINLOCK=y, a stackdump would occur at the time of the hang reporting: BUG: spinlock recursion on CPU#0, vnic_incoming/<pid> (see below for more details) We considered the possibility of adding a protocol between a visordriver and visorbus where the visordriver could specify which type of locking it required for its virtual device channels (essentially indicating whether or not it was possible for the channel to be accessed in ISR context), but decided this extra complexity was NOT needed, and that channel queues should always be accessed with the most-stringent locking. So that is what is implemented in this commit. Below is an example stackdump illustrating the spinlock recursion that is fixed by this commit. Note that we are first in virtnic_rx() writing to the device channel when an APIC timer interrupt occurs. Within the core networking code, net_rx_action() calls process_backlog(), which eventually lands up back up in virtnic_xmit() in the code attempting to also write to the device channel. BUG: spinlock recursion on CPU#0, vnic_incoming/262 lock: 0xffff88002db810c0, .magic: dead4ead, .owner: vnic_incoming/262, .owner_cpu: 0 CPU: 0 PID: 262 Comm: vnic_incoming Tainted: G C 4.2.0-rc1-ARCH+ #56 Hardware name: Dell Inc. PowerEdge T110/ , BIOS 1.23 12/15/2009 ffff8800216ac200 ffff88002c803388 ffffffff81476364 0000000000000106 ffff88002db810c0 ffff88002c8033a8 ffffffff8109e2bc ffff88002db810c0 ffffffff817631d4 ffff88002c8033c8 ffffffff8109e330 ffff88002db810c0 Call Trace: <IRQ> [<ffffffff81476364>] dump_stack+0x4f/0x73 [<ffffffff8109e2bc>] spin_dump+0x7c/0xc0 [<ffffffff8109e330>] spin_bug+0x30/0x40 [<ffffffff8109e547>] do_raw_spin_lock+0x127/0x140 [<ffffffff8147bad0>] _raw_spin_lock+0x40/0x50 [<ffffffffa0151fa6>] ? visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa0151fa6>] visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa01683a2>] visornic_xmit+0x302/0x5d0 [visornic] [<ffffffff813b2f30>] dev_hard_start_xmit+0x2e0/0x510 [<ffffffff813b2b75>] ? validate_xmit_skb+0x235/0x310 [<ffffffff813d79e7>] sch_direct_xmit+0xf7/0x1d0 [<ffffffff813b34d3>] __dev_queue_xmit+0x203/0x640 [<ffffffff813b3320>] ? __dev_queue_xmit+0x50/0x640 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff813b3933>] dev_queue_xmit_sk+0x13/0x20 [<ffffffff813f3a5c>] ip_finish_output2+0x22c/0x470 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813f3f6f>] ip_finish_output+0x1df/0x310 [<ffffffff813f4c31>] ip_output+0xb1/0x100 [<ffffffff813f41be>] ip_local_out_sk+0x3e/0x80 [<ffffffff813f4388>] ip_queue_xmit+0x188/0x4a0 [<ffffffff813f4200>] ? ip_local_out_sk+0x80/0x80 [<ffffffff8139fcd6>] ? __alloc_skb+0x86/0x1e0 [<ffffffff8140bd5b>] tcp_transmit_skb+0x4cb/0x9c0 [<ffffffff8139f0dc>] ? __kmalloc_reserve+0x3c/0x90 [<ffffffff8139fcea>] ? __alloc_skb+0x9a/0x1e0 [<ffffffff8140c47d>] tcp_send_ack+0x10d/0x150 [<ffffffff814060ee>] __tcp_ack_snd_check+0x5e/0x90 [<ffffffff81408eb4>] tcp_rcv_established+0x354/0x710 [<ffffffff81412182>] tcp_v4_do_rcv+0x162/0x3f0 [<ffffffff81414412>] tcp_v4_rcv+0xb22/0xb50 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee350>] ip_local_deliver_finish+0xe0/0x2d0 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee72e>] ip_local_deliver+0xae/0xc0 [<ffffffff813edeaf>] ip_rcv_finish+0x14f/0x510 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff813eea13>] ip_rcv+0x2d3/0x3b0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff813ab0f3>] __netif_receive_skb_core+0x663/0xb70 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff810971a9>] ? cpuacct_charge+0x99/0xb0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813ab72c>] ? process_backlog+0xbc/0x150 [<ffffffff813ab78b>] ? process_backlog+0x11b/0x150 [<ffffffff813ab627>] __netif_receive_skb+0x27/0x70 [<ffffffff813ab702>] process_backlog+0x92/0x150 [<ffffffff813afffd>] net_rx_action+0x13d/0x350 [<ffffffff81036b2d>] ? lapic_next_event+0x1d/0x30 [<ffffffff81058694>] __do_softirq+0x104/0x320 [<ffffffff810c0788>] ? hrtimer_interrupt+0xc8/0x1a0 [<ffffffff81074e70>] ? blocking_notifier_chain_cond_register+0x70/0x70 [<ffffffff81058ab9>] irq_exit+0x79/0xa0 [<ffffffff8147ecca>] smp_apic_timer_interrupt+0x4a/0x60 [<ffffffff8147d2c8>] apic_timer_interrupt+0x68/0x70 <EOI> [<ffffffff81271c02>] ? __memcpy+0x12/0x20 [<ffffffffa01517da>] ? visorchannel_write+0x4a/0x80 [visorbus] [<ffffffffa0151eb8>] signalinsert_inner+0x88/0x130 [visorbus] [<ffffffffa0151fb5>] visorchannel_signalinsert+0x55/0x70 [visorbus] [<ffffffffa0166e57>] visornic_rx+0x12e7/0x19d0 [visornic] [<ffffffffa01677c9>] process_incoming_rsps+0x289/0x690 [visornic] [<ffffffff814771c5>] ? preempt_schedule+0x25/0x30 [<ffffffff81001026>] ? ___preempt_schedule+0x12/0x14 [<ffffffff81093080>] ? wait_woken+0x90/0x90 [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffff81073a39>] kthread+0xe9/0x110 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 [<ffffffff8147c89f>] ret_from_fork+0x3f/0x70 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 Fixes: b12fdf7da ('staging: unisys: rework signal remove/insert to avoid sparse lock warnings') Signed-off-by: Tim Sell <Timothy.Sell@unisys.com> Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-07-14 18:43:30 +00:00
spin_lock_irqsave(&channel->remove_lock, flags);
rc = signalremove_inner(channel, queue, msg);
staging: unisys: fix random hangs with network stress in visornic We learned that it was possible for the core networking code to call visornic_xmit() within ISR context, resulting in the need for us to use spin_lock_irqsave() / spin_lock_irqrestore() to lock accesses to our virtual device channels. Without the correct locking added in this patch, random hangs would occur on typical kernels while stressing the netork. When using a kernel with CONFIG_DEBUG_SPINLOCK=y, a stackdump would occur at the time of the hang reporting: BUG: spinlock recursion on CPU#0, vnic_incoming/<pid> (see below for more details) We considered the possibility of adding a protocol between a visordriver and visorbus where the visordriver could specify which type of locking it required for its virtual device channels (essentially indicating whether or not it was possible for the channel to be accessed in ISR context), but decided this extra complexity was NOT needed, and that channel queues should always be accessed with the most-stringent locking. So that is what is implemented in this commit. Below is an example stackdump illustrating the spinlock recursion that is fixed by this commit. Note that we are first in virtnic_rx() writing to the device channel when an APIC timer interrupt occurs. Within the core networking code, net_rx_action() calls process_backlog(), which eventually lands up back up in virtnic_xmit() in the code attempting to also write to the device channel. BUG: spinlock recursion on CPU#0, vnic_incoming/262 lock: 0xffff88002db810c0, .magic: dead4ead, .owner: vnic_incoming/262, .owner_cpu: 0 CPU: 0 PID: 262 Comm: vnic_incoming Tainted: G C 4.2.0-rc1-ARCH+ #56 Hardware name: Dell Inc. PowerEdge T110/ , BIOS 1.23 12/15/2009 ffff8800216ac200 ffff88002c803388 ffffffff81476364 0000000000000106 ffff88002db810c0 ffff88002c8033a8 ffffffff8109e2bc ffff88002db810c0 ffffffff817631d4 ffff88002c8033c8 ffffffff8109e330 ffff88002db810c0 Call Trace: <IRQ> [<ffffffff81476364>] dump_stack+0x4f/0x73 [<ffffffff8109e2bc>] spin_dump+0x7c/0xc0 [<ffffffff8109e330>] spin_bug+0x30/0x40 [<ffffffff8109e547>] do_raw_spin_lock+0x127/0x140 [<ffffffff8147bad0>] _raw_spin_lock+0x40/0x50 [<ffffffffa0151fa6>] ? visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa0151fa6>] visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa01683a2>] visornic_xmit+0x302/0x5d0 [visornic] [<ffffffff813b2f30>] dev_hard_start_xmit+0x2e0/0x510 [<ffffffff813b2b75>] ? validate_xmit_skb+0x235/0x310 [<ffffffff813d79e7>] sch_direct_xmit+0xf7/0x1d0 [<ffffffff813b34d3>] __dev_queue_xmit+0x203/0x640 [<ffffffff813b3320>] ? __dev_queue_xmit+0x50/0x640 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff813b3933>] dev_queue_xmit_sk+0x13/0x20 [<ffffffff813f3a5c>] ip_finish_output2+0x22c/0x470 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813f3f6f>] ip_finish_output+0x1df/0x310 [<ffffffff813f4c31>] ip_output+0xb1/0x100 [<ffffffff813f41be>] ip_local_out_sk+0x3e/0x80 [<ffffffff813f4388>] ip_queue_xmit+0x188/0x4a0 [<ffffffff813f4200>] ? ip_local_out_sk+0x80/0x80 [<ffffffff8139fcd6>] ? __alloc_skb+0x86/0x1e0 [<ffffffff8140bd5b>] tcp_transmit_skb+0x4cb/0x9c0 [<ffffffff8139f0dc>] ? __kmalloc_reserve+0x3c/0x90 [<ffffffff8139fcea>] ? __alloc_skb+0x9a/0x1e0 [<ffffffff8140c47d>] tcp_send_ack+0x10d/0x150 [<ffffffff814060ee>] __tcp_ack_snd_check+0x5e/0x90 [<ffffffff81408eb4>] tcp_rcv_established+0x354/0x710 [<ffffffff81412182>] tcp_v4_do_rcv+0x162/0x3f0 [<ffffffff81414412>] tcp_v4_rcv+0xb22/0xb50 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee350>] ip_local_deliver_finish+0xe0/0x2d0 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee72e>] ip_local_deliver+0xae/0xc0 [<ffffffff813edeaf>] ip_rcv_finish+0x14f/0x510 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff813eea13>] ip_rcv+0x2d3/0x3b0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff813ab0f3>] __netif_receive_skb_core+0x663/0xb70 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff810971a9>] ? cpuacct_charge+0x99/0xb0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813ab72c>] ? process_backlog+0xbc/0x150 [<ffffffff813ab78b>] ? process_backlog+0x11b/0x150 [<ffffffff813ab627>] __netif_receive_skb+0x27/0x70 [<ffffffff813ab702>] process_backlog+0x92/0x150 [<ffffffff813afffd>] net_rx_action+0x13d/0x350 [<ffffffff81036b2d>] ? lapic_next_event+0x1d/0x30 [<ffffffff81058694>] __do_softirq+0x104/0x320 [<ffffffff810c0788>] ? hrtimer_interrupt+0xc8/0x1a0 [<ffffffff81074e70>] ? blocking_notifier_chain_cond_register+0x70/0x70 [<ffffffff81058ab9>] irq_exit+0x79/0xa0 [<ffffffff8147ecca>] smp_apic_timer_interrupt+0x4a/0x60 [<ffffffff8147d2c8>] apic_timer_interrupt+0x68/0x70 <EOI> [<ffffffff81271c02>] ? __memcpy+0x12/0x20 [<ffffffffa01517da>] ? visorchannel_write+0x4a/0x80 [visorbus] [<ffffffffa0151eb8>] signalinsert_inner+0x88/0x130 [visorbus] [<ffffffffa0151fb5>] visorchannel_signalinsert+0x55/0x70 [visorbus] [<ffffffffa0166e57>] visornic_rx+0x12e7/0x19d0 [visornic] [<ffffffffa01677c9>] process_incoming_rsps+0x289/0x690 [visornic] [<ffffffff814771c5>] ? preempt_schedule+0x25/0x30 [<ffffffff81001026>] ? ___preempt_schedule+0x12/0x14 [<ffffffff81093080>] ? wait_woken+0x90/0x90 [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffff81073a39>] kthread+0xe9/0x110 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 [<ffffffff8147c89f>] ret_from_fork+0x3f/0x70 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 Fixes: b12fdf7da ('staging: unisys: rework signal remove/insert to avoid sparse lock warnings') Signed-off-by: Tim Sell <Timothy.Sell@unisys.com> Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-07-14 18:43:30 +00:00
spin_unlock_irqrestore(&channel->remove_lock, flags);
} else {
rc = signalremove_inner(channel, queue, msg);
}
return rc;
}
EXPORT_SYMBOL_GPL(visorchannel_signalremove);
static bool
signalinsert_inner(struct visorchannel *channel, u32 queue, void *msg)
{
struct signal_queue_header sig_hdr;
if (!sig_read_header(channel, queue, &sig_hdr))
return false;
sig_hdr.head = ((sig_hdr.head + 1) % sig_hdr.max_slots);
if (sig_hdr.head == sig_hdr.tail) {
sig_hdr.num_overflows++;
visorchannel_write(channel,
SIG_QUEUE_OFFSET(&channel->chan_hdr, queue) +
offsetof(struct signal_queue_header,
num_overflows),
&(sig_hdr.num_overflows),
sizeof(sig_hdr.num_overflows));
return false;
}
if (!sig_write_data(channel, queue, &sig_hdr, sig_hdr.head, msg))
return false;
sig_hdr.num_sent++;
/* For each data field in SIGNAL_QUEUE_HEADER that was modified,
* update host memory.
*/
mb(); /* required for channel synch */
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, head))
return false;
if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_sent))
return false;
return true;
}
bool
visorchannel_signalinsert(struct visorchannel *channel, u32 queue, void *msg)
{
bool rc;
staging: unisys: fix random hangs with network stress in visornic We learned that it was possible for the core networking code to call visornic_xmit() within ISR context, resulting in the need for us to use spin_lock_irqsave() / spin_lock_irqrestore() to lock accesses to our virtual device channels. Without the correct locking added in this patch, random hangs would occur on typical kernels while stressing the netork. When using a kernel with CONFIG_DEBUG_SPINLOCK=y, a stackdump would occur at the time of the hang reporting: BUG: spinlock recursion on CPU#0, vnic_incoming/<pid> (see below for more details) We considered the possibility of adding a protocol between a visordriver and visorbus where the visordriver could specify which type of locking it required for its virtual device channels (essentially indicating whether or not it was possible for the channel to be accessed in ISR context), but decided this extra complexity was NOT needed, and that channel queues should always be accessed with the most-stringent locking. So that is what is implemented in this commit. Below is an example stackdump illustrating the spinlock recursion that is fixed by this commit. Note that we are first in virtnic_rx() writing to the device channel when an APIC timer interrupt occurs. Within the core networking code, net_rx_action() calls process_backlog(), which eventually lands up back up in virtnic_xmit() in the code attempting to also write to the device channel. BUG: spinlock recursion on CPU#0, vnic_incoming/262 lock: 0xffff88002db810c0, .magic: dead4ead, .owner: vnic_incoming/262, .owner_cpu: 0 CPU: 0 PID: 262 Comm: vnic_incoming Tainted: G C 4.2.0-rc1-ARCH+ #56 Hardware name: Dell Inc. PowerEdge T110/ , BIOS 1.23 12/15/2009 ffff8800216ac200 ffff88002c803388 ffffffff81476364 0000000000000106 ffff88002db810c0 ffff88002c8033a8 ffffffff8109e2bc ffff88002db810c0 ffffffff817631d4 ffff88002c8033c8 ffffffff8109e330 ffff88002db810c0 Call Trace: <IRQ> [<ffffffff81476364>] dump_stack+0x4f/0x73 [<ffffffff8109e2bc>] spin_dump+0x7c/0xc0 [<ffffffff8109e330>] spin_bug+0x30/0x40 [<ffffffff8109e547>] do_raw_spin_lock+0x127/0x140 [<ffffffff8147bad0>] _raw_spin_lock+0x40/0x50 [<ffffffffa0151fa6>] ? visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa0151fa6>] visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa01683a2>] visornic_xmit+0x302/0x5d0 [visornic] [<ffffffff813b2f30>] dev_hard_start_xmit+0x2e0/0x510 [<ffffffff813b2b75>] ? validate_xmit_skb+0x235/0x310 [<ffffffff813d79e7>] sch_direct_xmit+0xf7/0x1d0 [<ffffffff813b34d3>] __dev_queue_xmit+0x203/0x640 [<ffffffff813b3320>] ? __dev_queue_xmit+0x50/0x640 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff813b3933>] dev_queue_xmit_sk+0x13/0x20 [<ffffffff813f3a5c>] ip_finish_output2+0x22c/0x470 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813f3f6f>] ip_finish_output+0x1df/0x310 [<ffffffff813f4c31>] ip_output+0xb1/0x100 [<ffffffff813f41be>] ip_local_out_sk+0x3e/0x80 [<ffffffff813f4388>] ip_queue_xmit+0x188/0x4a0 [<ffffffff813f4200>] ? ip_local_out_sk+0x80/0x80 [<ffffffff8139fcd6>] ? __alloc_skb+0x86/0x1e0 [<ffffffff8140bd5b>] tcp_transmit_skb+0x4cb/0x9c0 [<ffffffff8139f0dc>] ? __kmalloc_reserve+0x3c/0x90 [<ffffffff8139fcea>] ? __alloc_skb+0x9a/0x1e0 [<ffffffff8140c47d>] tcp_send_ack+0x10d/0x150 [<ffffffff814060ee>] __tcp_ack_snd_check+0x5e/0x90 [<ffffffff81408eb4>] tcp_rcv_established+0x354/0x710 [<ffffffff81412182>] tcp_v4_do_rcv+0x162/0x3f0 [<ffffffff81414412>] tcp_v4_rcv+0xb22/0xb50 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee350>] ip_local_deliver_finish+0xe0/0x2d0 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee72e>] ip_local_deliver+0xae/0xc0 [<ffffffff813edeaf>] ip_rcv_finish+0x14f/0x510 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff813eea13>] ip_rcv+0x2d3/0x3b0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff813ab0f3>] __netif_receive_skb_core+0x663/0xb70 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff810971a9>] ? cpuacct_charge+0x99/0xb0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813ab72c>] ? process_backlog+0xbc/0x150 [<ffffffff813ab78b>] ? process_backlog+0x11b/0x150 [<ffffffff813ab627>] __netif_receive_skb+0x27/0x70 [<ffffffff813ab702>] process_backlog+0x92/0x150 [<ffffffff813afffd>] net_rx_action+0x13d/0x350 [<ffffffff81036b2d>] ? lapic_next_event+0x1d/0x30 [<ffffffff81058694>] __do_softirq+0x104/0x320 [<ffffffff810c0788>] ? hrtimer_interrupt+0xc8/0x1a0 [<ffffffff81074e70>] ? blocking_notifier_chain_cond_register+0x70/0x70 [<ffffffff81058ab9>] irq_exit+0x79/0xa0 [<ffffffff8147ecca>] smp_apic_timer_interrupt+0x4a/0x60 [<ffffffff8147d2c8>] apic_timer_interrupt+0x68/0x70 <EOI> [<ffffffff81271c02>] ? __memcpy+0x12/0x20 [<ffffffffa01517da>] ? visorchannel_write+0x4a/0x80 [visorbus] [<ffffffffa0151eb8>] signalinsert_inner+0x88/0x130 [visorbus] [<ffffffffa0151fb5>] visorchannel_signalinsert+0x55/0x70 [visorbus] [<ffffffffa0166e57>] visornic_rx+0x12e7/0x19d0 [visornic] [<ffffffffa01677c9>] process_incoming_rsps+0x289/0x690 [visornic] [<ffffffff814771c5>] ? preempt_schedule+0x25/0x30 [<ffffffff81001026>] ? ___preempt_schedule+0x12/0x14 [<ffffffff81093080>] ? wait_woken+0x90/0x90 [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffff81073a39>] kthread+0xe9/0x110 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 [<ffffffff8147c89f>] ret_from_fork+0x3f/0x70 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 Fixes: b12fdf7da ('staging: unisys: rework signal remove/insert to avoid sparse lock warnings') Signed-off-by: Tim Sell <Timothy.Sell@unisys.com> Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-07-14 18:43:30 +00:00
unsigned long flags;
if (channel->needs_lock) {
staging: unisys: fix random hangs with network stress in visornic We learned that it was possible for the core networking code to call visornic_xmit() within ISR context, resulting in the need for us to use spin_lock_irqsave() / spin_lock_irqrestore() to lock accesses to our virtual device channels. Without the correct locking added in this patch, random hangs would occur on typical kernels while stressing the netork. When using a kernel with CONFIG_DEBUG_SPINLOCK=y, a stackdump would occur at the time of the hang reporting: BUG: spinlock recursion on CPU#0, vnic_incoming/<pid> (see below for more details) We considered the possibility of adding a protocol between a visordriver and visorbus where the visordriver could specify which type of locking it required for its virtual device channels (essentially indicating whether or not it was possible for the channel to be accessed in ISR context), but decided this extra complexity was NOT needed, and that channel queues should always be accessed with the most-stringent locking. So that is what is implemented in this commit. Below is an example stackdump illustrating the spinlock recursion that is fixed by this commit. Note that we are first in virtnic_rx() writing to the device channel when an APIC timer interrupt occurs. Within the core networking code, net_rx_action() calls process_backlog(), which eventually lands up back up in virtnic_xmit() in the code attempting to also write to the device channel. BUG: spinlock recursion on CPU#0, vnic_incoming/262 lock: 0xffff88002db810c0, .magic: dead4ead, .owner: vnic_incoming/262, .owner_cpu: 0 CPU: 0 PID: 262 Comm: vnic_incoming Tainted: G C 4.2.0-rc1-ARCH+ #56 Hardware name: Dell Inc. PowerEdge T110/ , BIOS 1.23 12/15/2009 ffff8800216ac200 ffff88002c803388 ffffffff81476364 0000000000000106 ffff88002db810c0 ffff88002c8033a8 ffffffff8109e2bc ffff88002db810c0 ffffffff817631d4 ffff88002c8033c8 ffffffff8109e330 ffff88002db810c0 Call Trace: <IRQ> [<ffffffff81476364>] dump_stack+0x4f/0x73 [<ffffffff8109e2bc>] spin_dump+0x7c/0xc0 [<ffffffff8109e330>] spin_bug+0x30/0x40 [<ffffffff8109e547>] do_raw_spin_lock+0x127/0x140 [<ffffffff8147bad0>] _raw_spin_lock+0x40/0x50 [<ffffffffa0151fa6>] ? visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa0151fa6>] visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa01683a2>] visornic_xmit+0x302/0x5d0 [visornic] [<ffffffff813b2f30>] dev_hard_start_xmit+0x2e0/0x510 [<ffffffff813b2b75>] ? validate_xmit_skb+0x235/0x310 [<ffffffff813d79e7>] sch_direct_xmit+0xf7/0x1d0 [<ffffffff813b34d3>] __dev_queue_xmit+0x203/0x640 [<ffffffff813b3320>] ? __dev_queue_xmit+0x50/0x640 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff813b3933>] dev_queue_xmit_sk+0x13/0x20 [<ffffffff813f3a5c>] ip_finish_output2+0x22c/0x470 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813f3f6f>] ip_finish_output+0x1df/0x310 [<ffffffff813f4c31>] ip_output+0xb1/0x100 [<ffffffff813f41be>] ip_local_out_sk+0x3e/0x80 [<ffffffff813f4388>] ip_queue_xmit+0x188/0x4a0 [<ffffffff813f4200>] ? ip_local_out_sk+0x80/0x80 [<ffffffff8139fcd6>] ? __alloc_skb+0x86/0x1e0 [<ffffffff8140bd5b>] tcp_transmit_skb+0x4cb/0x9c0 [<ffffffff8139f0dc>] ? __kmalloc_reserve+0x3c/0x90 [<ffffffff8139fcea>] ? __alloc_skb+0x9a/0x1e0 [<ffffffff8140c47d>] tcp_send_ack+0x10d/0x150 [<ffffffff814060ee>] __tcp_ack_snd_check+0x5e/0x90 [<ffffffff81408eb4>] tcp_rcv_established+0x354/0x710 [<ffffffff81412182>] tcp_v4_do_rcv+0x162/0x3f0 [<ffffffff81414412>] tcp_v4_rcv+0xb22/0xb50 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee350>] ip_local_deliver_finish+0xe0/0x2d0 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee72e>] ip_local_deliver+0xae/0xc0 [<ffffffff813edeaf>] ip_rcv_finish+0x14f/0x510 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff813eea13>] ip_rcv+0x2d3/0x3b0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff813ab0f3>] __netif_receive_skb_core+0x663/0xb70 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff810971a9>] ? cpuacct_charge+0x99/0xb0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813ab72c>] ? process_backlog+0xbc/0x150 [<ffffffff813ab78b>] ? process_backlog+0x11b/0x150 [<ffffffff813ab627>] __netif_receive_skb+0x27/0x70 [<ffffffff813ab702>] process_backlog+0x92/0x150 [<ffffffff813afffd>] net_rx_action+0x13d/0x350 [<ffffffff81036b2d>] ? lapic_next_event+0x1d/0x30 [<ffffffff81058694>] __do_softirq+0x104/0x320 [<ffffffff810c0788>] ? hrtimer_interrupt+0xc8/0x1a0 [<ffffffff81074e70>] ? blocking_notifier_chain_cond_register+0x70/0x70 [<ffffffff81058ab9>] irq_exit+0x79/0xa0 [<ffffffff8147ecca>] smp_apic_timer_interrupt+0x4a/0x60 [<ffffffff8147d2c8>] apic_timer_interrupt+0x68/0x70 <EOI> [<ffffffff81271c02>] ? __memcpy+0x12/0x20 [<ffffffffa01517da>] ? visorchannel_write+0x4a/0x80 [visorbus] [<ffffffffa0151eb8>] signalinsert_inner+0x88/0x130 [visorbus] [<ffffffffa0151fb5>] visorchannel_signalinsert+0x55/0x70 [visorbus] [<ffffffffa0166e57>] visornic_rx+0x12e7/0x19d0 [visornic] [<ffffffffa01677c9>] process_incoming_rsps+0x289/0x690 [visornic] [<ffffffff814771c5>] ? preempt_schedule+0x25/0x30 [<ffffffff81001026>] ? ___preempt_schedule+0x12/0x14 [<ffffffff81093080>] ? wait_woken+0x90/0x90 [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffff81073a39>] kthread+0xe9/0x110 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 [<ffffffff8147c89f>] ret_from_fork+0x3f/0x70 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 Fixes: b12fdf7da ('staging: unisys: rework signal remove/insert to avoid sparse lock warnings') Signed-off-by: Tim Sell <Timothy.Sell@unisys.com> Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-07-14 18:43:30 +00:00
spin_lock_irqsave(&channel->insert_lock, flags);
rc = signalinsert_inner(channel, queue, msg);
staging: unisys: fix random hangs with network stress in visornic We learned that it was possible for the core networking code to call visornic_xmit() within ISR context, resulting in the need for us to use spin_lock_irqsave() / spin_lock_irqrestore() to lock accesses to our virtual device channels. Without the correct locking added in this patch, random hangs would occur on typical kernels while stressing the netork. When using a kernel with CONFIG_DEBUG_SPINLOCK=y, a stackdump would occur at the time of the hang reporting: BUG: spinlock recursion on CPU#0, vnic_incoming/<pid> (see below for more details) We considered the possibility of adding a protocol between a visordriver and visorbus where the visordriver could specify which type of locking it required for its virtual device channels (essentially indicating whether or not it was possible for the channel to be accessed in ISR context), but decided this extra complexity was NOT needed, and that channel queues should always be accessed with the most-stringent locking. So that is what is implemented in this commit. Below is an example stackdump illustrating the spinlock recursion that is fixed by this commit. Note that we are first in virtnic_rx() writing to the device channel when an APIC timer interrupt occurs. Within the core networking code, net_rx_action() calls process_backlog(), which eventually lands up back up in virtnic_xmit() in the code attempting to also write to the device channel. BUG: spinlock recursion on CPU#0, vnic_incoming/262 lock: 0xffff88002db810c0, .magic: dead4ead, .owner: vnic_incoming/262, .owner_cpu: 0 CPU: 0 PID: 262 Comm: vnic_incoming Tainted: G C 4.2.0-rc1-ARCH+ #56 Hardware name: Dell Inc. PowerEdge T110/ , BIOS 1.23 12/15/2009 ffff8800216ac200 ffff88002c803388 ffffffff81476364 0000000000000106 ffff88002db810c0 ffff88002c8033a8 ffffffff8109e2bc ffff88002db810c0 ffffffff817631d4 ffff88002c8033c8 ffffffff8109e330 ffff88002db810c0 Call Trace: <IRQ> [<ffffffff81476364>] dump_stack+0x4f/0x73 [<ffffffff8109e2bc>] spin_dump+0x7c/0xc0 [<ffffffff8109e330>] spin_bug+0x30/0x40 [<ffffffff8109e547>] do_raw_spin_lock+0x127/0x140 [<ffffffff8147bad0>] _raw_spin_lock+0x40/0x50 [<ffffffffa0151fa6>] ? visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa0151fa6>] visorchannel_signalinsert+0x46/0x70 [visorbus] [<ffffffffa01683a2>] visornic_xmit+0x302/0x5d0 [visornic] [<ffffffff813b2f30>] dev_hard_start_xmit+0x2e0/0x510 [<ffffffff813b2b75>] ? validate_xmit_skb+0x235/0x310 [<ffffffff813d79e7>] sch_direct_xmit+0xf7/0x1d0 [<ffffffff813b34d3>] __dev_queue_xmit+0x203/0x640 [<ffffffff813b3320>] ? __dev_queue_xmit+0x50/0x640 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff813b3933>] dev_queue_xmit_sk+0x13/0x20 [<ffffffff813f3a5c>] ip_finish_output2+0x22c/0x470 [<ffffffff813f3f6f>] ? ip_finish_output+0x1df/0x310 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813f3f6f>] ip_finish_output+0x1df/0x310 [<ffffffff813f4c31>] ip_output+0xb1/0x100 [<ffffffff813f41be>] ip_local_out_sk+0x3e/0x80 [<ffffffff813f4388>] ip_queue_xmit+0x188/0x4a0 [<ffffffff813f4200>] ? ip_local_out_sk+0x80/0x80 [<ffffffff8139fcd6>] ? __alloc_skb+0x86/0x1e0 [<ffffffff8140bd5b>] tcp_transmit_skb+0x4cb/0x9c0 [<ffffffff8139f0dc>] ? __kmalloc_reserve+0x3c/0x90 [<ffffffff8139fcea>] ? __alloc_skb+0x9a/0x1e0 [<ffffffff8140c47d>] tcp_send_ack+0x10d/0x150 [<ffffffff814060ee>] __tcp_ack_snd_check+0x5e/0x90 [<ffffffff81408eb4>] tcp_rcv_established+0x354/0x710 [<ffffffff81412182>] tcp_v4_do_rcv+0x162/0x3f0 [<ffffffff81414412>] tcp_v4_rcv+0xb22/0xb50 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee350>] ip_local_deliver_finish+0xe0/0x2d0 [<ffffffff813ee2bc>] ? ip_local_deliver_finish+0x4c/0x2d0 [<ffffffff813ee72e>] ip_local_deliver+0xae/0xc0 [<ffffffff813edeaf>] ip_rcv_finish+0x14f/0x510 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff813eea13>] ip_rcv+0x2d3/0x3b0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff813ab0f3>] __netif_receive_skb_core+0x663/0xb70 [<ffffffff813aab2d>] ? __netif_receive_skb_core+0x9d/0xb70 [<ffffffff810971a9>] ? cpuacct_charge+0x99/0xb0 [<ffffffff81097110>] ? cpuacct_css_alloc+0xb0/0xb0 [<ffffffff810987e0>] ? __lock_is_held+0x50/0x70 [<ffffffff813ab72c>] ? process_backlog+0xbc/0x150 [<ffffffff813ab78b>] ? process_backlog+0x11b/0x150 [<ffffffff813ab627>] __netif_receive_skb+0x27/0x70 [<ffffffff813ab702>] process_backlog+0x92/0x150 [<ffffffff813afffd>] net_rx_action+0x13d/0x350 [<ffffffff81036b2d>] ? lapic_next_event+0x1d/0x30 [<ffffffff81058694>] __do_softirq+0x104/0x320 [<ffffffff810c0788>] ? hrtimer_interrupt+0xc8/0x1a0 [<ffffffff81074e70>] ? blocking_notifier_chain_cond_register+0x70/0x70 [<ffffffff81058ab9>] irq_exit+0x79/0xa0 [<ffffffff8147ecca>] smp_apic_timer_interrupt+0x4a/0x60 [<ffffffff8147d2c8>] apic_timer_interrupt+0x68/0x70 <EOI> [<ffffffff81271c02>] ? __memcpy+0x12/0x20 [<ffffffffa01517da>] ? visorchannel_write+0x4a/0x80 [visorbus] [<ffffffffa0151eb8>] signalinsert_inner+0x88/0x130 [visorbus] [<ffffffffa0151fb5>] visorchannel_signalinsert+0x55/0x70 [visorbus] [<ffffffffa0166e57>] visornic_rx+0x12e7/0x19d0 [visornic] [<ffffffffa01677c9>] process_incoming_rsps+0x289/0x690 [visornic] [<ffffffff814771c5>] ? preempt_schedule+0x25/0x30 [<ffffffff81001026>] ? ___preempt_schedule+0x12/0x14 [<ffffffff81093080>] ? wait_woken+0x90/0x90 [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffffa0167540>] ? visornic_rx+0x19d0/0x19d0 [visornic] [<ffffffff81073a39>] kthread+0xe9/0x110 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 [<ffffffff8147c89f>] ret_from_fork+0x3f/0x70 [<ffffffff81073950>] ? __init_kthread_worker+0x70/0x70 Fixes: b12fdf7da ('staging: unisys: rework signal remove/insert to avoid sparse lock warnings') Signed-off-by: Tim Sell <Timothy.Sell@unisys.com> Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-07-14 18:43:30 +00:00
spin_unlock_irqrestore(&channel->insert_lock, flags);
} else {
rc = signalinsert_inner(channel, queue, msg);
}
return rc;
}
EXPORT_SYMBOL_GPL(visorchannel_signalinsert);
int
visorchannel_signalqueue_slots_avail(struct visorchannel *channel, u32 queue)
{
struct signal_queue_header sig_hdr;
u32 slots_avail, slots_used;
u32 head, tail;
if (!sig_read_header(channel, queue, &sig_hdr))
return 0;
head = sig_hdr.head;
tail = sig_hdr.tail;
if (head < tail)
head = head + sig_hdr.max_slots;
slots_used = (head - tail);
slots_avail = sig_hdr.max_signals - slots_used;
return (int)slots_avail;
}
EXPORT_SYMBOL_GPL(visorchannel_signalqueue_slots_avail);
int
visorchannel_signalqueue_max_slots(struct visorchannel *channel, u32 queue)
{
struct signal_queue_header sig_hdr;
if (!sig_read_header(channel, queue, &sig_hdr))
return 0;
return (int)sig_hdr.max_signals;
}
EXPORT_SYMBOL_GPL(visorchannel_signalqueue_max_slots);
static void
sigqueue_debug(struct signal_queue_header *q, int which, struct seq_file *seq)
{
seq_printf(seq, "Signal Queue #%d\n", which);
seq_printf(seq, " VersionId = %lu\n", (ulong)q->version);
seq_printf(seq, " Type = %lu\n", (ulong)q->chtype);
seq_printf(seq, " oSignalBase = %llu\n",
(long long)q->sig_base_offset);
seq_printf(seq, " SignalSize = %lu\n", (ulong)q->signal_size);
seq_printf(seq, " MaxSignalSlots = %lu\n",
(ulong)q->max_slots);
seq_printf(seq, " MaxSignals = %lu\n", (ulong)q->max_signals);
seq_printf(seq, " FeatureFlags = %-16.16Lx\n",
(long long)q->features);
seq_printf(seq, " NumSignalsSent = %llu\n",
(long long)q->num_sent);
seq_printf(seq, " NumSignalsReceived = %llu\n",
(long long)q->num_received);
seq_printf(seq, " NumOverflows = %llu\n",
(long long)q->num_overflows);
seq_printf(seq, " Head = %lu\n", (ulong)q->head);
seq_printf(seq, " Tail = %lu\n", (ulong)q->tail);
}
void
visorchannel_debug(struct visorchannel *channel, int num_queues,
struct seq_file *seq, u32 off)
{
u64 addr = 0;
ulong nbytes = 0, nbytes_region = 0;
struct channel_header hdr;
struct channel_header *phdr = &hdr;
int i = 0;
int errcode = 0;
if (!channel)
return;
addr = visorchannel_get_physaddr(channel);
nbytes_region = visorchannel_get_nbytes(channel);
errcode = visorchannel_read(channel, off,
phdr, sizeof(struct channel_header));
if (errcode < 0) {
seq_printf(seq,
"Read of channel header failed with errcode=%d)\n",
errcode);
if (off == 0) {
phdr = &channel->chan_hdr;
seq_puts(seq, "(following data may be stale)\n");
} else {
return;
}
}
nbytes = (ulong)(phdr->size);
seq_printf(seq, "--- Begin channel @0x%-16.16Lx for 0x%lx bytes (region=0x%lx bytes) ---\n",
addr + off, nbytes, nbytes_region);
seq_printf(seq, "Type = %pUL\n", &phdr->chtype);
seq_printf(seq, "ZoneGuid = %pUL\n", &phdr->zone_uuid);
seq_printf(seq, "Signature = 0x%-16.16Lx\n",
(long long)phdr->signature);
seq_printf(seq, "LegacyState = %lu\n", (ulong)phdr->legacy_state);
seq_printf(seq, "SrvState = %lu\n", (ulong)phdr->srv_state);
seq_printf(seq, "CliStateBoot = %lu\n", (ulong)phdr->cli_state_boot);
seq_printf(seq, "CliStateOS = %lu\n", (ulong)phdr->cli_state_os);
seq_printf(seq, "HeaderSize = %lu\n", (ulong)phdr->header_size);
seq_printf(seq, "Size = %llu\n", (long long)phdr->size);
seq_printf(seq, "Features = 0x%-16.16llx\n",
(long long)phdr->features);
seq_printf(seq, "PartitionHandle = 0x%-16.16llx\n",
(long long)phdr->partition_handle);
seq_printf(seq, "Handle = 0x%-16.16llx\n",
(long long)phdr->handle);
seq_printf(seq, "VersionId = %lu\n", (ulong)phdr->version_id);
seq_printf(seq, "oChannelSpace = %llu\n",
(long long)phdr->ch_space_offset);
if ((phdr->ch_space_offset == 0) || (errcode < 0))
;
else
for (i = 0; i < num_queues; i++) {
struct signal_queue_header q;
errcode = visorchannel_read(channel,
off +
phdr->ch_space_offset +
(i * sizeof(q)),
&q, sizeof(q));
if (errcode < 0) {
seq_printf(seq,
"failed to read signal queue #%d from channel @0x%-16.16Lx errcode=%d\n",
i, addr, errcode);
continue;
}
sigqueue_debug(&q, i, seq);
}
seq_printf(seq, "--- End channel @0x%-16.16Lx for 0x%lx bytes ---\n",
addr + off, nbytes);
}
EXPORT_SYMBOL_GPL(visorchannel_debug);