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 42D0DC43219 for ; Fri, 26 Apr 2019 11:06:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1AD662077B for ; Fri, 26 Apr 2019 11:06:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726065AbfDZLGE convert rfc822-to-8bit (ORCPT ); Fri, 26 Apr 2019 07:06:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42318 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbfDZLGE (ORCPT ); Fri, 26 Apr 2019 07:06:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FE5230832CF; Fri, 26 Apr 2019 11:06:04 +0000 (UTC) Received: from carbon (ovpn-200-51.brq.redhat.com [10.40.200.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE2605D717; Fri, 26 Apr 2019 11:05:53 +0000 (UTC) Date: Fri, 26 Apr 2019 13:05:50 +0200 From: Jesper Dangaard Brouer To: Jason Wang Cc: "Michael S. Tsirkin" , Toshiaki Makita , David Ahern , Toke =?UTF-8?B?SMO4aWxhbmQtSsO4cmdlbnNlbg==?= , "netdev@vger.kernel.org" , brouer@redhat.com, John Fastabend Subject: Re: virtio_net: suspicious RCU usage with xdp Message-ID: <20190426130550.7bb1d4bd@carbon> In-Reply-To: <8bcd6aba-ea18-7e20-b883-3b926b9a2c07@redhat.com> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 26 Apr 2019 11:06:04 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 guess, disable_bh is sufficient protection, as we are mostly optimizing away a preempt-disable when accessing per-cpu variables. -- Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer