Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp817113pxa; Sat, 22 Aug 2020 00:51:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9RVmT7QuyHvT4YfE54n6YjC1NAdAMY06Mf7wiyvBdBD4Jx8GmzxCaYpZ3aEz//pFfVBGY X-Received: by 2002:aa7:c6c2:: with SMTP id b2mr6564039eds.173.1598082691136; Sat, 22 Aug 2020 00:51:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598082691; cv=none; d=google.com; s=arc-20160816; b=GVxruO3GtOPdDJstAShI7sYszBtLsylXM2fPob0jFSuw8wIqtkZ76GT4FfAQacab+P agPcRL7km7LyuWteLwhUHrIIf2p6dYek3JXMX7AHTP6v941e6F1X+RsmtsoX1vUIKqac xJCWhndebq/Po5J84gTllsmQUk04LUiTnkIAGvYkAzKBjM3puNVfvUWxXFbYaOYIYrrI tgaVW0iCP7bgd9NK/b5Ktl4lvTfkxcpuh4iGzmlWs2JzqsDcyn1IvV4O3mB9R9PHXOd1 6Fs8u0vh6rYD6yqPl8kGe26OU9Mzs+3b0fphDHewVlpayVbHj+XWxbQyxGZfFGkv/A76 1OdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ucDpivhSHRtEV7HP6/CuGlE8yRxOlZBKt8o/Etn070o=; b=Slgy/1I0AXoFR47JvQKmXfMF1X3Tbi2OzaR7dCTY+EUYZan1stD/O60UXyRdXyKeGc zEnpF1m7gleAq5DPdDjgiXFRZWn28sqm/4EDEgWE7dkajavaHzF8AavsJtLFM2RuSfb+ 5Kl85oJKdNtpmSVdBFHT/R8vl61a58ASFNLHtNVOVQU34ub1zapIOejjpiySfxTteH7x Bcgv9Cj7t8pxYJYIk6rEA7xjUKv+bx6dtrHP0MuYCbbC+1v9HulEt968PBuuVUgoNYqn j/lFnGT6SLMAxibmNi272MbC9Xah2O+L4gUEhR+4X527go4TiDrCau5QY7tNvnhYJNuV 2EAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RzJpaGei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si2668814ejk.747.2020.08.22.00.51.07; Sat, 22 Aug 2020 00:51:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RzJpaGei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727820AbgHVHtg (ORCPT + 99 others); Sat, 22 Aug 2020 03:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727775AbgHVHte (ORCPT ); Sat, 22 Aug 2020 03:49:34 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF710C061575 for ; Sat, 22 Aug 2020 00:49:34 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id c10so3467045edk.6 for ; Sat, 22 Aug 2020 00:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ucDpivhSHRtEV7HP6/CuGlE8yRxOlZBKt8o/Etn070o=; b=RzJpaGeivfYrZB6/8QpMgePNgXSZgxvjjCmNdgzLkTFuK2BCrKzDyGmo+dCwY81gUe KQfdvuLcJF3/ThhUGTD10KOF053iWUDlb5u8fvCSmrbtUEX4U5Y7DT4o9QiVvGFQzBjU UlWqeq+aPsyqwtVdAvBmnSYOoqVQIMiLzu6+4D8IxS/7UYEefiVANyf/vc4G1ZaY4cpt 5xywE/sKNUurpiR0fiYcKqPZ/n550px8T14eAy0ayieaDNz73uPwLXVdQ2iAyCw3wjPR PfAjnJrCU+g4zGt49Zeb60V/97lXpHYWNnhaiGSdhJAP0IsHgv+7E1Mim6Bc8V3Cfr/w W87Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ucDpivhSHRtEV7HP6/CuGlE8yRxOlZBKt8o/Etn070o=; b=OHul61QD4BE6KODapj82X62w3kzVBZnrBS5MkxfncdtStsdnL5mPDkaswrPP0Rg1qb S2lC4C3gMYmpN/57ei8p6/eE6ow/6soINVi9AMyHaje8aG9yx52qT9n7qx8kUWkjaD1T LteVyryGmYbrApb6uYe0Q6TfuYhuwYF7XkWAXSrVPpLsv1bqVsWR4yaOvF2ByXZyRIVS Zd0QXuRt7Eblcoqtwb+n6A2rZ6MK/H2XkHJUVv4j0t2X9Cg7SU9aXv4NYo0E4y6pG3Fp JJbNw1lNh5F7FknyRSTGW9i5CipEo0vLxfx8KZL1oW91qoad6dH5clL6A30mhyw72i7g PxHw== X-Gm-Message-State: AOAM531xEPla00imEKvWqgosWyqRTLqFh8D4rNpaAfjwOaqCHVP4Iaqu TgXzUU974vdEwYK+74jcKJXf5g3/GameC/oF4FC5PA== X-Received: by 2002:a50:ee92:: with SMTP id f18mr6367467edr.80.1598082572822; Sat, 22 Aug 2020 00:49:32 -0700 (PDT) MIME-Version: 1.0 References: <20200819224030.1615203-1-haoluo@google.com> <20200819224030.1615203-7-haoluo@google.com> In-Reply-To: From: Hao Luo Date: Sat, 22 Aug 2020 00:49:21 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1 6/8] bpf: Introduce bpf_per_cpu_ptr() To: Andrii Nakryiko Cc: Networking , bpf , open list , "open list:KERNEL SELFTEST FRAMEWORK" , Shuah Khan , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Quentin Monnet , Steven Rostedt , Ingo Molnar , Andrey Ignatov , Jakub Sitnicki Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 21, 2020 at 8:31 PM Andrii Nakryiko wrote: > > On Fri, Aug 21, 2020 at 8:26 PM Andrii Nakryiko > wrote: > > > > On Wed, Aug 19, 2020 at 3:42 PM Hao Luo wrote: > > > > > > Add bpf_per_cpu_ptr() to help bpf programs access percpu vars. > > > bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the kernel > > > except that it may return NULL. This happens when the cpu parameter is > > > out of range. So the caller must check the returned value. > > > > > > Signed-off-by: Hao Luo > > > --- > > > > The logic looks correct, few naming nits, but otherwise: > > > > Acked-by: Andrii Nakryiko > > > > > include/linux/bpf.h | 3 ++ > > > include/linux/btf.h | 11 +++++++ > > > include/uapi/linux/bpf.h | 14 +++++++++ > > > kernel/bpf/btf.c | 10 ------- > > > kernel/bpf/verifier.c | 64 ++++++++++++++++++++++++++++++++++++++-- > > > kernel/trace/bpf_trace.c | 18 +++++++++++ > > > 6 files changed, 107 insertions(+), 13 deletions(-) [...] > > btw, having bpf_this_cpu_ptr(const void *ptr) seems worthwhile as well, WDYT? > It's probably not a good idea, IMHO. How does it interact with preemption? Should we treat it as __this_cpu_ptr()? If so, I feel it's easy to be misused, if the bpf program is called in a preemptible context. Btw, is bpf programs always called with preemption disabled? How about interrupts? I haven't thought about these questions before but I think they matter as we start to have more ways for bpf programs to interact with the kernel. Best, Hao