From mboxrd@z Thu Jan 1 00:00:00 1970 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 CACD7C43218 for ; Sun, 28 Apr 2019 03:07:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A011B206BB for ; Sun, 28 Apr 2019 03:07:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726495AbfD1DHG (ORCPT ); Sat, 27 Apr 2019 23:07:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51242 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbfD1DHG (ORCPT ); Sat, 27 Apr 2019 23:07:06 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86FA1882EF; Sun, 28 Apr 2019 03:07:05 +0000 (UTC) Received: from [10.72.12.56] (ovpn-12-56.pek2.redhat.com [10.72.12.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id B24E41812A; Sun, 28 Apr 2019 03:06:57 +0000 (UTC) Subject: Re: virtio_net: suspicious RCU usage with xdp To: Jesper Dangaard Brouer Cc: "Michael S. Tsirkin" , Toshiaki Makita , David Ahern , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgensen?= , "netdev@vger.kernel.org" , John Fastabend References: <20190424132533-mutt-send-email-mst@kernel.org> <20190425130319-mutt-send-email-mst@kernel.org> <20190425194117.66093851@carbon> <8bcd6aba-ea18-7e20-b883-3b926b9a2c07@redhat.com> <20190426130550.7bb1d4bd@carbon> From: Jason Wang Message-ID: <87d2b5ce-598f-ca48-68f4-a2631ce49097@redhat.com> Date: Sun, 28 Apr 2019 11:06:56 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190426130550.7bb1d4bd@carbon> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sun, 28 Apr 2019 03:07:05 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 2019/4/26 下午7:05, Jesper Dangaard Brouer wrote: > On Fri, 26 Apr 2019 16:00:28 +0800 > Jason Wang wrote: > >> On 2019/4/26 上午1:41, Jesper Dangaard Brouer wrote: >>> It does sound like my commit 5d053f9da431 ("bpf: devmap prepare xdp >>> frames for bulking") introduced this issue. I guess we can add the RCU >>> section to xdp_do_flush_map(), and then also verify that the devmap >>> (and cpumap) take-down code also have appropriate RCU sections (which >>> they should have). >>> >>> Another requirement for calling .ndo_xdp_xmit is running under NAPI >>> protection, >> >> May I know the reason for this? I'm asking since if the packet was >> redirected from tuntap, ndo_xdp_xmit()  won't be called under the >> protection of NAPI (but bh is disabled). > There are a number of things that rely on this NAPI/softirq protection. > > One is preempt-free access per-cpu struct bpf_redirect_info. Which is > at the core of the XDP and TC redirect feature. > > DEFINE_PER_CPU(struct bpf_redirect_info, bpf_redirect_info); > EXPORT_PER_CPU_SYMBOL_GPL(bpf_redirect_info); > struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info); > > And devmap and cpumap also have per-cpu variables, that we don't use > preempt-disable around. > > Another is xdp_return_frame_rx_napi() that when page_pool is active, > can store frames to be recycled directly into an array, in function > __page_pool_recycle_direct() (but as I don't trust every driver getting > this correct I've added a safe-guard in page-pool via > in_serving_softirq(). I see, if I want to use page pool for tap for VM2VM traffic, this probably means I can only recycle through ptr_ring. > > I guess, disable_bh is sufficient protection, as we are mostly > optimizing away a preempt-disable when accessing per-cpu variables. > Yes, that's what I want for confirm. Thanks