Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp819340pxa; Sat, 22 Aug 2020 00:58:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ6W8q1tPbAvo/ufjLKBNlah3FUYuVZ9MCxH0hE5EHrAT8288Up2XWNakXoJbq4pARSoeQ X-Received: by 2002:a17:906:90d3:: with SMTP id v19mr1855531ejw.23.1598083106186; Sat, 22 Aug 2020 00:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598083106; cv=none; d=google.com; s=arc-20160816; b=mlnJeQuTixZGvIbGa4aqjiDU6BJUimSmyf9RMr7F8y7oKbqN6WYJNmDfcEL58346dM tBWXkazxOfxGgstRi/ZGo7gMdr6y9gyTUMyuAogKbZpxiG9s8YBotN+YdlbzkOyuktgL YrHkRMdV5D2hfp2RXta03LsXTqkXE/G88P3fG3q1Vsb3qoGhOdjpXojESBkWsaNmdODJ mqCUkAcFSbXmhAghoUBL/TruKFXC4PaNiyyjWJnwkvni9TT19I/3P/RtcmgMSElpxf4L zPyXtHFjWdOs0LYIfZOtvt5Tae14iEl9AWzz7WjSOfFOgtL7LAcL83TspBoRsAcfiHKN O9Bw== 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=3FGIc23gIcAL+scd1gVHTER4ApVxnptisLCy0nOA3ec=; b=Uv4fCJ+hmOoBTfQnqQNYgCF9a7FaygjY3oFH89RjcSgovM1Bg/fhkWwApvSwVLSdEj 6ZNOmWrZTkKsR3Cn/GcF3Nn4XOCJ7lp036X5aS/h5Jy50tpiZGMkJNB2vFp7Cz1lALXO aleNQXY0SmE32AgT1miq8YM5TDE7zALzCEQDVOiTdsAvdng+O2Ih0AI+L8Dr/R/71TUo EtakRgjGOuCVUtqX+Ao4+02Jef0+DbJUVvPosl7CdLJIj9ipaScXttbfpnBHQXpIrp5p 7ZcIIs8THAlfV8pjehjn9Xb0TYlp3bs36Pd2LFURMiM2p85Q0twekON2u9/Dff+ej3b3 eqxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RSzSqkuk; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f1si2818346edm.270.2020.08.22.00.58.02; Sat, 22 Aug 2020 00:58:26 -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=@gmail.com header.s=20161025 header.b=RSzSqkuk; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727845AbgHVHzV (ORCPT + 99 others); Sat, 22 Aug 2020 03:55:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727802AbgHVHzU (ORCPT ); Sat, 22 Aug 2020 03:55:20 -0400 Received: from mail-yb1-xb44.google.com (mail-yb1-xb44.google.com [IPv6:2607:f8b0:4864:20::b44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26D20C061573; Sat, 22 Aug 2020 00:55:20 -0700 (PDT) Received: by mail-yb1-xb44.google.com with SMTP id u6so2303998ybf.1; Sat, 22 Aug 2020 00:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3FGIc23gIcAL+scd1gVHTER4ApVxnptisLCy0nOA3ec=; b=RSzSqkuk2hxMrHDgNEpuWCYiDfGZ3ACWe7ZA3ruJMeA/Y1jKDRp2N7eo+K+HWkuOhT NEcgA6U5EZ4g9jrmuDDYJ0DsiA7/FYDxn5Xb7wvxwT5aguFaEuF3VCxgfovw8q00cD1i V1hPb1wxj3LBqItsJYj0Rw7VzzMLfjgN48w9XQM33H3lzwL2rpXw4uA/JOzicBnQ1zyT 5NzldIftdoAo9G3m/c9gFEBsTu0D4LTmeLNgYvb8etkJViKZvvJ3hmTeHq+I8Im5DxLJ a8teefzkh2SOisuAnh4eXkzwDO07XgfG1v996L6RAHFY94ECcBvIUHBQB00bIQDYqIdJ JT4Q== 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=3FGIc23gIcAL+scd1gVHTER4ApVxnptisLCy0nOA3ec=; b=gVPLfIz4RPt+AjN5bPhwkZe2tFtjhc2VphtVUT2C5OScSTas1GwVOLyMDYefoq4iqJ ss5kQPEtYaFhHGqypHUnvJ0XIlIckZhtLImAprD96m5LwNdQh68n1Ui/Z06LJ7o+v/ht 0liPYi5irNEWaM8PNEAXnhdAHdJZsGc/T4EUxXYLu+XHRIImpJRlOZg5pppy/49F5/as h10IHzK1iG5bL7mUl8ZxCpr/BTn9zRi5bd+WaTRAK36dOCg3eX7btHHOJz4LkCsNbFLX NS0Kd0uv1HomdZHVEzNGqTk5VhV3cgt6atiygTpOY8wbdrHo/39G+a1qeVMploQlpLyf xeJw== X-Gm-Message-State: AOAM533cFpRr2doHB+ILD2Gsqf9hC+JSQBut+z++UqpqjWTiuXBitrmS ASLwd88UK8wDKcMub6HEzrd8c0DlmUqgsx2BC7U= X-Received: by 2002:a25:bc50:: with SMTP id d16mr7987916ybk.230.1598082919371; Sat, 22 Aug 2020 00:55:19 -0700 (PDT) MIME-Version: 1.0 References: <20200819224030.1615203-1-haoluo@google.com> <20200819224030.1615203-7-haoluo@google.com> In-Reply-To: From: Andrii Nakryiko Date: Sat, 22 Aug 2020 00:55:08 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1 6/8] bpf: Introduce bpf_per_cpu_ptr() To: Hao Luo 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 Sat, Aug 22, 2020 at 12:49 AM Hao Luo wrote: > > 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. non-sleepable BPF is always disabling CPU migration, so there is no problem with this_cpu_ptr. For sleepable not sure, but we can disable this helper for sleepable BPF programs, if that's a problem. > > Best, > Hao