Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp56391ybv; Tue, 18 Feb 2020 17:38:28 -0800 (PST) X-Google-Smtp-Source: APXvYqw1NqhhXk+oTP8nhCxDDvsoe/qV13PTHBCrJkhRMT2enRPY1EmBL3UfzcgSrJqkbshLW5h9 X-Received: by 2002:a9d:7851:: with SMTP id c17mr18366030otm.58.1582076308309; Tue, 18 Feb 2020 17:38:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582076308; cv=none; d=google.com; s=arc-20160816; b=vbFt37aWnFJs25daqpvNeWCg/3lm+qSj98ZWXYgSDO1Y06wmIEk2HR5BizVzQEBSXM Hd9d8n5vHqADyTv6GSxodjFp1JN3sxHdcmEBWG6xTZTOP94GtcKFm/m95pIQq+KrtFuv 7XR3kF/jd+4bbXLIWa6QZcKuu2jrGl3Za13Fn6/HTotey6FKX8wi2nkQ+FSK1FZWSJBK p1P/m7Mq/G8HXwB+qoFset4VKXoR+apVHeW5srzqtnUEKrL9WKNP4Lf9ItU/5aVp70X/ zBatyGJFO0otDMO6HQjU4S8Jckmfkji5vcJJx+bl50743DWZILkVwGYLy7P4Cbcjihz5 mseg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=QDUQe1Hvsy5i4deafl1FSwf8zJrNNExR0vV/O1ups7Y=; b=f2jiJpg6qfbyaqC8Tke58/QvjsEZWZDfF1Q5IbtmdbkkPMcY8WA0cJdWSiRFkDWK5N TTWMlTVGDNx+2iqWpozdIPiUgd0g0B0RcduZSokWIWynDvOQPNo+q+ItSbnecqQJ6E3F hY0AqxUgtDeB1nRw5cokYwGRkx5Zz6D5P/lNQdiyuvNyoJBQt13UwPse+OVo/5n466Ir NFWTBd4HQUztopkZldNTvzRT+WjxYcq8+f/xZONVncVCP3CiukF3knt4vPdy6fVr3uMi u73XRdFs4QcWyu2MYSqrUNEjRLJcXq1aRJfwNBsl6WJ24aPQ2fWeQoD7DidDmta+uF0H lIKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w18si313195otp.48.2020.02.18.17.38.16; Tue, 18 Feb 2020 17:38:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727935AbgBSBiE (ORCPT + 99 others); Tue, 18 Feb 2020 20:38:04 -0500 Received: from mga18.intel.com ([134.134.136.126]:22398 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbgBSBiD (ORCPT ); Tue, 18 Feb 2020 20:38:03 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Feb 2020 17:38:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,458,1574150400"; d="scan'208";a="436061496" Received: from vcostago-desk1.jf.intel.com (HELO vcostago-desk1) ([10.54.70.26]) by fmsmga006.fm.intel.com with ESMTP; 18 Feb 2020 17:38:02 -0800 From: Vinicius Costa Gomes To: Thomas Gleixner , LKML Cc: David Miller , bpf@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Sebastian Sewior , Peter Zijlstra , Clark Williams , Steven Rostedt , Juri Lelli , Ingo Molnar Subject: Re: [RFC patch 09/19] bpf: Use BPF_PROG_RUN_PIN_ON_CPU() at simple call sites. In-Reply-To: <20200214161503.804093748@linutronix.de> References: <20200214133917.304937432@linutronix.de> <20200214161503.804093748@linutronix.de> Date: Tue, 18 Feb 2020 17:39:45 -0800 Message-ID: <87a75ftkwu.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Thomas Gleixner writes: > From: David Miller > > All of these cases are strictly of the form: > > preempt_disable(); > BPF_PROG_RUN(...); > preempt_enable(); > > Replace this with BPF_PROG_RUN_PIN_ON_CPU() which wraps BPF_PROG_RUN() > with: > > migrate_disable(); > BPF_PROG_RUN(...); > migrate_enable(); > > On non RT enabled kernels this maps to preempt_disable/enable() and on RT > enabled kernels this solely prevents migration, which is sufficient as > there is no requirement to prevent reentrancy to any BPF program from a > preempting task. The only requirement is that the program stays on the same > CPU. > > Therefore, this is a trivially correct transformation. > > [ tglx: Converted to BPF_PROG_RUN_PIN_ON_CPU() ] > > Signed-off-by: David S. Miller > Signed-off-by: Thomas Gleixner > > --- > include/linux/filter.h | 4 +--- > kernel/seccomp.c | 4 +--- > net/core/flow_dissector.c | 4 +--- > net/core/skmsg.c | 8 ++------ > net/kcm/kcmsock.c | 4 +--- > 5 files changed, 6 insertions(+), 18 deletions(-) > > --- a/include/linux/filter.h > +++ b/include/linux/filter.h > @@ -713,9 +713,7 @@ static inline u32 bpf_prog_run_clear_cb( > if (unlikely(prog->cb_access)) > memset(cb_data, 0, BPF_SKB_CB_LEN); > > - preempt_disable(); > - res = BPF_PROG_RUN(prog, skb); > - preempt_enable(); > + res = BPF_PROG_RUN_PIN_ON_CPU(prog, skb); > return res; > } > > --- a/kernel/seccomp.c > +++ b/kernel/seccomp.c > @@ -268,16 +268,14 @@ static u32 seccomp_run_filters(const str > * All filters in the list are evaluated and the lowest BPF return > * value always takes priority (ignoring the DATA). > */ > - preempt_disable(); > for (; f; f = f->prev) { > - u32 cur_ret = BPF_PROG_RUN(f->prog, sd); > + u32 cur_ret = BPF_PROG_RUN_PIN_ON_CPU(f->prog, sd); > More a question really, isn't the behavior changing here? i.e. shouldn't migrate_disable()/migrate_enable() be moved to outside the loop? Or is running seccomp filters on different cpus not a problem? -- Vinicius