Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 499D5C10F03 for ; Thu, 25 Apr 2019 04:59:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 17C10217FA for ; Thu, 25 Apr 2019 04:59:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728849AbfDYE7j (ORCPT ); Thu, 25 Apr 2019 00:59:39 -0400 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]:37841 "EHLO tama50.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbfDYE7i (ORCPT ); Thu, 25 Apr 2019 00:59:38 -0400 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x3P4xRDD014039; Thu, 25 Apr 2019 13:59:27 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 1A6F6EA7CA1; Thu, 25 Apr 2019 13:59:27 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 0FC58EA748F; Thu, 25 Apr 2019 13:59:27 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.194]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id F240A4003CA; Thu, 25 Apr 2019 13:59:26 +0900 (JST) Subject: Re: virtio_net: suspicious RCU usage with xdp References: <20190424132533-mutt-send-email-mst@kernel.org> From: Toshiaki Makita Message-ID: Date: Thu, 25 Apr 2019 13:58:48 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190424132533-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CC-Mail-RelayStamp: 1 To: "Michael S. Tsirkin" , David Ahern Cc: Jesper Dangaard Brouer , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgensen?= , "netdev@vger.kernel.org" , Jason Wang X-TM-AS-MML: disable Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 2019/04/25 2:37, Michael S. Tsirkin wrote: > On Wed, Apr 24, 2019 at 11:13:42AM -0600, David Ahern wrote: >> seeing an RCU warning testing xdp with virtio net. net-next as of commit >> b2f97f7de2f6a4df8e431330cf467576486651c5. No obvious changes so hoping >> this rings a bell with someone else. >> >> >> [ 121.990304] ============================= >> [ 121.991488] WARNING: suspicious RCU usage >> [ 121.992392] 5.1.0-rc5+ #60 Not tainted >> [ 121.993220] ----------------------------- >> [ 121.994158] /home/dsa/kernel-3.git/drivers/net/virtio_net.c:516 >> suspicious rcu_dereference_check() usage! >> [ 121.996284] >> other info that might help us debug this: >> >> [ 121.997988] >> rcu_scheduler_active = 2, debug_locks = 1 >> [ 121.999321] no locks held by swapper/1/0. >> [ 122.000328] >> stack backtrace: >> [ 122.001253] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.1.0-rc5+ #60 >> [ 122.002474] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), >> BIOS 1.11.1-1 04/01/2014 >> [ 122.004141] Call Trace: >> [ 122.004651] >> [ 122.005082] dump_stack+0x7e/0xbb >> [ 122.005757] lockdep_rcu_suspicious+0x102/0x10b >> [ 122.006654] virtnet_xdp_xmit+0x104/0x4fe >> [ 122.007447] ? kasan_check_read+0x11/0x13 >> [ 122.008267] ? mergeable_rx_buffer_size_show+0x163/0x163 >> [ 122.009299] ? __asan_loadN+0xf/0x11 >> [ 122.010010] ? pvclock_clocksource_read+0xfa/0x189 >> [ 122.010975] bq_xmit_all+0xdc/0x358 >> [ 122.011699] __dev_map_flush+0xc2/0xef >> [ 122.012472] xdp_do_flush_map+0x5b/0x74 >> [ 122.013238] virtnet_poll+0x58f/0x679 > > Well virtnet_xdp_xmit seems to be called from .ndo_xdp_xmit > and that isn't in an RCU read-side critical section. > > Looks like we just need to add RCU read lock/unlock. > Like the below perhaps? > > This issue was introduced by 8dcc5b0ab0 however I find it Probably not 8dcc5b0ab0, but 5d053f9da431 ("bpf: devmap prepare xdp frames for bulking"). > inelegant that we need to do checks in each driver, > and add RCU locks just for a startup initialization issue. > Can't XDP core make sure the callback isn't invoked > at an inappropriate time instead? Before commit 5d053f9da431, .ndo_xdp_xmit() should have always been called under RCU. After the commit, xdp_do_flush_map() also can trigger .ndo_xdp_xmit() but we forgot to add RCU read lock there? I guess veth has the same problem and I feel like it should be fixed in __dev_map_flush(). dev_map_flush_old() needs to be cared too. -- Toshiaki Makita