Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2547119pxa; Mon, 24 Aug 2020 18:07:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy36PTI5y9XKJ/Ejlm9cMlAKSt45GWRAz7BYa1Pqh/qkGW5SBNFhygx/8q5U5EE3ezW+2v4 X-Received: by 2002:a17:906:5495:: with SMTP id r21mr7941352ejo.33.1598317626397; Mon, 24 Aug 2020 18:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598317626; cv=none; d=google.com; s=arc-20160816; b=Wab6U/TS4Cyc+BZcf/dIu9GJgOQVmEGFiDC1X9yRDSgKj/N7fPfNmEPQ7O4YXzMcx2 Wiys3v1PAh2WZB4a8AqU5S/r8oLp84lvOHOyekN1fsrfGhXfNR+oSXEIUEpjCS/rSuKV E9kPsNmhQbuNuPSyZjGnz1U7DV1ApVDbuzBD7GsgkZyjT5EC58QuGlK+IT0BmrhQvq49 fWY2UN0WoDc8iD6evMKXf76MihCjWcEfLVGLWGcfkQgPrTsivhIv9zaMeLqikYG9gcuc eOkXhfWh7whhytwzBt2QzJcLh6NQQ9lRfW/vKfhRhTu07xXYMGV1AX3RzIMli8vcSpru lqIg== 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=ve340FBnE1IFfQ0W0GtQ2RPw5r9LpjCO3O73FDEbehQ=; b=iHPT42LDBolaQlT4Ouo5HNakwuo8VnMJYvrXR+qqBfOsC3R1I5WUt4cAqiVTxHe2Fu IAros1tpFCTfzkpgVN5zRtCw/UInW5RwzK1znlFw9qH4pAd2+RCIF1z7XPhhCPiDOgHC m0QOfc2GC29SmKNX8BU+/kmELwvldZlvtozx0sopMVK+TJZt3cchWvZWyjox/pvG2+/4 NCrLuIaYn8/sc4VRjoeZCxP9spe+QOg62/C6OB41W/5bQG3pnSPeClcUkhFsO3/o2dYZ W5oRwj5bCISAr4YbOQwhgLuCmc0wwFByKC6sDdGcq+1IoPO7gmaUr4i5zx6X0Wg2nHKn dJ6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZVSlGEmP; 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 w23si7217524edu.32.2020.08.24.18.06.42; Mon, 24 Aug 2020 18:07:06 -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=ZVSlGEmP; 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 S1728379AbgHYBDs (ORCPT + 99 others); Mon, 24 Aug 2020 21:03:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727950AbgHYBDp (ORCPT ); Mon, 24 Aug 2020 21:03:45 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A038EC0613ED for ; Mon, 24 Aug 2020 18:03:44 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id di22so9731367edb.12 for ; Mon, 24 Aug 2020 18:03:44 -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=ve340FBnE1IFfQ0W0GtQ2RPw5r9LpjCO3O73FDEbehQ=; b=ZVSlGEmPWwd7gWYd9D33C6IPSJ1bADML54SZ4oGBBcAx6QjuZc609Nwwiyv0dfvLr4 lztF+M4JcAQla0H8qITYK1KIRboJkvaxb9dXaxTkUUnNreZ7TMkfUZyVgaE3S8WpkL7M mRJLCoPwWEOR/gzP5qb1coo8WhvBr757QM7ooR7S18gzTPIBIrT/MT85oMsBfxxJc34m E9L1V3KV+kLCDVQhFIrYxQ63YR7UfG80Wpk9QlKaVAw9p+e/vU5lKDwfXnMXshgSGE3x BJhrFFjAH0vQUs27NFMoeBGqBDXQUtNM36h9WVoayiHLuTBbn90pE9zsSRpl453witZq qF1g== 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=ve340FBnE1IFfQ0W0GtQ2RPw5r9LpjCO3O73FDEbehQ=; b=MeSulV9aKmRVKhqaV/FhSKtwO9nxeQqAS+Nz7TQMFfY/vtl9l2D+3v2Bk56PxRhcfN mq2UfEmNR8FZxwnR5r8DAXrpZ/rJ0hBR/3swPo8dwPA6KBe0LFqCjTcU5ecNSmvdGhYS oasPuP/AUpS4m+nzLKHF9QVC6F7cHo5GPTEDrA+iUrWpZA8OdlfaMaHTUhWBZjmzlt69 URjGwgpqoir8pVgQQACsshAVAsuv5Pku41Ic4qUZuYh4FfeWUGFoP1qkiU8Be+U+Yben a4SXhiB88SHpqd798UjjpwJC3kYtkpgyoDJu5c29hFxgi2ELAnb88yiM2sTHIDQiz3vP QJ+g== X-Gm-Message-State: AOAM531BcDx+vuhO1dRvojOmTQZGxHFjb+G/x+xEladLebjsZW2EbOwE xb3ec4AbzW3Zie7HE4n7xosaAJDRlMjaWQkQpEoyYA== X-Received: by 2002:aa7:d912:: with SMTP id a18mr96788edr.18.1598317422894; Mon, 24 Aug 2020 18:03:42 -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: Mon, 24 Aug 2020 18:03:31 -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 Sat, Aug 22, 2020 at 12:55 AM Andrii Nakryiko wrote: > > 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. > Sounds good. I see there is bpf_get_smp_processor_id() and we are already doing this. I can add this_cpu_ptr() in v2. Hao