From patchwork Sat Feb 20 01:27:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 8365541 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C58C8C0553 for ; Sat, 20 Feb 2016 01:30:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BCBB32057F for ; Sat, 20 Feb 2016 01:30:58 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D270D20571 for ; Sat, 20 Feb 2016 01:30:57 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aWwL2-0004om-HT; Sat, 20 Feb 2016 01:28:00 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aWwL1-0004oh-Bs for xen-devel@lists.xenproject.org; Sat, 20 Feb 2016 01:27:59 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 88/EE-04060-E11C7C65; Sat, 20 Feb 2016 01:27:58 +0000 X-Env-Sender: arei.gonglei@huawei.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1455931672!23740230!1 X-Originating-IP: [119.145.14.66] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTE5LjE0NS4xNC42NiA9PiA4NTI3\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 52111 invoked from network); 20 Feb 2016 01:27:57 -0000 Received: from szxga03-in.huawei.com (HELO szxga03-in.huawei.com) (119.145.14.66) by server-2.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 20 Feb 2016 01:27:57 -0000 Received: from 172.24.1.47 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.47]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BWJ70177; Sat, 20 Feb 2016 09:27:45 +0800 (CST) Received: from localhost (10.177.18.62) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Sat, 20 Feb 2016 09:27:34 +0800 From: Gonglei To: , , Date: Sat, 20 Feb 2016 09:27:26 +0800 Message-ID: <1455931646-5672-1-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.6.3.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.18.62] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0202.56C7C111.00ED, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 63531e1038f28e2d20b1daa534505eae Cc: Gonglei , peter.huangpeng@huawei.com, "David S . Miller" Subject: [Xen-devel] [PATCH] xen-netfront: set real_num_tx_queues to zreo avoid to trigger BUG_ON X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It's possible for a race condition to exist between xennet_open() and talk_to_netback(). After invoking netfront_probe() then other threads or processes invoke xennet_open (such as NetworkManager) immediately may trigger BUG_ON(). Besides, we also should reset real_num_tx_queues in xennet_destroy_queues(). [ 3324.658057] kernel BUG at include/linux/netdevice.h:508! [ 3324.658057] invalid opcode: 0000 [#1] SMP [ 3324.658057] CPU: 0 PID: 662 Comm: NetworkManager Tainted: G [] ? raw_notifier_call_chain+0x16/0x20 [] __dev_open+0xce/0x150 [] __dev_change_flags+0xa1/0x170 [] dev_change_flags+0x29/0x70 [] do_setlink+0x39f/0xb40 [] ? nla_parse+0x32/0x120 [] rtnl_newlink+0x604/0x900 [] ? netlink_unicast+0x193/0x1c0 [] ? security_capable+0x18/0x20 [] ? ns_capable+0x2d/0x60 [] rtnetlink_rcv_msg+0xf5/0x270 [] ? rhashtable_lookup_compare+0x5d/0xa0 [] ? rtnetlink_rcv+0x40/0x40 [] netlink_rcv_skb+0xb9/0xe0 [] rtnetlink_rcv+0x2c/0x40 [] netlink_unicast+0x12d/0x1c0 [] netlink_sendmsg+0x4d3/0x630 [] ? sock_has_perm+0x72/0x90 [] do_sock_sendmsg+0x9f/0xc0 [ 3324.703482] RIP [] xennet_open+0x180/0x182 [xen_netfront] CC: David S. Miller Signed-off-by: Gonglei --- drivers/net/xen-netfront.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index d6abf19..da25555 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -340,7 +340,7 @@ static int xennet_open(struct net_device *dev) unsigned int i = 0; struct netfront_queue *queue = NULL; - for (i = 0; i < num_queues; ++i) { + for (i = 0; i < num_queues && np->queues; ++i) { queue = &np->queues[i]; napi_enable(&queue->napi); @@ -1296,6 +1296,10 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev) np = netdev_priv(netdev); np->xbdev = dev; + /* No need to use rtnl_lock() before the call below as it + * happens before register_netdev(). + */ + netdev->real_num_tx_queues = 0; np->queues = NULL; err = -ENOMEM; @@ -1748,7 +1752,7 @@ static void xennet_destroy_queues(struct netfront_info *info) del_timer_sync(&queue->rx_refill_timer); netif_napi_del(&queue->napi); } - + info->netdev->real_num_tx_queues = 0; rtnl_unlock(); kfree(info->queues); @@ -1951,6 +1955,9 @@ abort_transaction_no_dev_fatal: xennet_disconnect_backend(info); kfree(info->queues); info->queues = NULL; + rtnl_lock(); + info->netdev->real_num_tx_queues = 0; + rtnl_unlock(); out: return err; }