Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp362277ybv; Wed, 19 Feb 2020 01:01:56 -0800 (PST) X-Google-Smtp-Source: APXvYqxuWUwEUYRsU8bggKSqb5u4psxyMY34CFNwRsYIkB2QVqzg9nQXrvUX2Ni5K9tPXzaDqDJw X-Received: by 2002:aca:aa0a:: with SMTP id t10mr3790760oie.156.1582102916196; Wed, 19 Feb 2020 01:01:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582102916; cv=none; d=google.com; s=arc-20160816; b=Z00PV3RY87Zm9a7DfBkOlD6lAOi7s9Q5ucY4jGx1oAoukWJYha7124CDMQB2SEnZdr BoYnwEE5KNwbTVA8nAvhHwHcJbs3OlhapmXuobvzOdItMVS4Ez9G5u/TII55zmVfNOLR wC4G9IZR/CIMhY+qwIGhJr3hYYA8dBVUBjx/9r0CHz2rBFcZNRO2CGDMzQiy1c5PVCZO A4RhXU76/1aEf+KPaxfqrKTXGv3VTfrzBOEr0PzJqKBzwDr7DHXVCCGmVvVFc9vas2NI 7Zq9vUtP+PuTYbpQPAfJVuBqATnvqzmEIWfgDIlhVNDmcI6F0DyoDi0DvPgACrin56pa AIIQ== 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=EHSmN34sDvgwBlsoltDJeTwoQgSf+XUj4CCz8wgLKCg=; b=hW+eqIeE16pfrPl3wjQ/PCaq2f0CI1ns5nfPI0xJZxUFxbblIoJIYs38sWXRQLSNJ6 i6r22RGnUTuWAZJ9beWyyXoiyO03LXhb4778Vd3kXUzSjvDGwOOdQgupztoODmEUaUFu nOePG0j/RkyNGjsqHhujGOJywvXWvpQa8jc2QhwaQ3a4kj6YXFNI3oonSGkIEL+Pql77 AXpstFLMkGvyvgmUgGiMKwsvuGNJjfh1HsI1wnFpoB+3ZsNJSwWIJZqamWXbTkUZ42/q GMRsi5SD+QtUHOsH76/WrwsK5ceWGG4Zr+UPS6Sv9WDjJROS81Pwcs2mOoXG0UHr1hXa k4jg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 10si8981863ois.76.2020.02.19.01.01.43; Wed, 19 Feb 2020 01:01:56 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726558AbgBSJBj (ORCPT + 99 others); Wed, 19 Feb 2020 04:01:39 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:37615 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbgBSJBi (ORCPT ); Wed, 19 Feb 2020 04:01:38 -0500 Received: from p5de0bf0b.dip0.t-ipconnect.de ([93.224.191.11] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1j4LE1-0000bh-BZ; Wed, 19 Feb 2020 10:00:57 +0100 Received: by nanos.tec.linutronix.de (Postfix, from userid 1000) id 6083A100F56; Wed, 19 Feb 2020 10:00:56 +0100 (CET) From: Thomas Gleixner To: Vinicius Costa Gomes , 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 , Kees Cook , Will Drewry , Andy Lutomirski Subject: Re: [RFC patch 09/19] bpf: Use BPF_PROG_RUN_PIN_ON_CPU() at simple call sites. In-Reply-To: <87a75ftkwu.fsf@linux.intel.com> References: <20200214133917.304937432@linutronix.de> <20200214161503.804093748@linutronix.de> <87a75ftkwu.fsf@linux.intel.com> Date: Wed, 19 Feb 2020 10:00:56 +0100 Message-ID: <875zg3q7cn.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Vinicius Costa Gomes writes: Cc+: seccomp folks > Thomas Gleixner writes: > >> From: David Miller Leaving content for reference >> 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? In my understanding this is a list of filters and they are independent of each other. Kees, Will. Andy? Thanks, tglx