Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5575328iob; Mon, 9 May 2022 21:14:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDtlnUvewxiEI6OXPRd+KaQdUMmjFWGIaJTUbXB2zlJNQ4j31EplpEqwfv/mQThNkKocl4 X-Received: by 2002:a17:90b:694:b0:1d9:6a2e:bc9 with SMTP id m20-20020a17090b069400b001d96a2e0bc9mr29329817pjz.169.1652156053336; Mon, 09 May 2022 21:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652156053; cv=none; d=google.com; s=arc-20160816; b=z5iJF/lEcfNoNhBQCBYbO7Vk8PsDjAV2Q3vVg1CPqA7CfWSlZ4IEU/78hgH3fmJzrM QGPZtetvwrSpH9eUbPRwU+fNaP2ifK6psDIeRvWTXL7kUdWr+WAclnPpLzy4q5VoJLvp FyQlc8ZumKTBuEGob3VIZSIP7/Intvgt1A16mmqigXVnzv5ptCA+CWd1uzo2gJnW7F0O b8NYX9dlMAFb+v0nEIp6q44tLiogzrWWT9lG5b6vsFMh88n1X0z+5Djvv/W+YNBZmNso 0fNAPSOfkYomUKvrG9giJI1qu2umb2C2HsK5np5AA61bbnEr8q8W7QR40DzZjOiVYZ7k 0A3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4karCgB0MC1BnR8W1B+6xeveKW1nLUhu/KIW4e11r7E=; b=ucl6qP+Dmd8/FCW+ymt6HOdYYnSZZ6yJvyhkOcAG/6V/+G4RnJr/dGRdN2VFmQ1/Yi ameU0YLdUYx0wNAW6zrzRt/EpFuGbxazf/i+Gc7dUiiPANV6ia/SfagSxpDoP2rfpyty qcVljWRnplDeP9RwGHV7979VtDvxdyYQaafh55Dz9B+n47a8GPWgOH1hAEwShVSgcZK4 TFQ36hcflrGC62hbxKgkMEGE810hnNKUwU2atL6IIMqQLqsWIho35o9K6BCAPbC3dkhx GQ+syRjYcj7qrUejP2ypnPCb+Fh+vLgJDU0z6g78cxRhqLZpZpW6ESyR/zoW3eUbTB+q ft9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="gPV/WNtm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s15-20020a63770f000000b003c5e1870580si15723397pgc.775.2022.05.09.21.13.58; Mon, 09 May 2022 21:14:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="gPV/WNtm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233807AbiEJAi2 (ORCPT + 99 others); Mon, 9 May 2022 20:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233751AbiEJAi0 (ORCPT ); Mon, 9 May 2022 20:38:26 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 114F42AC6FD; Mon, 9 May 2022 17:34:31 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id b5so10413034ile.0; Mon, 09 May 2022 17:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4karCgB0MC1BnR8W1B+6xeveKW1nLUhu/KIW4e11r7E=; b=gPV/WNtmjhKATU3NOJJ2pJw0iSift/HVTYr5YFJsS1JUov3T3P2sugNCw4ICoi2aNI DN+uDBJG7kkKevRYgmg0JQ/nZIy3pnAhVVdsTOD9BWnVU1xH5Ixx4fwIM61GxmRKmKjL nBTx2psO/Mytl/Lx70vvQozaObWeysSydsSWlDGnlF6X4mw4JLrZvYcIRrBk0PvzQ5Lz pp7oNz4kWk1X6Lvyl9yPJBIE6Pzussr/T8e/CgwZFGRVcrEgBbK01QRaAN336Wkhr3Vv gRSZV3tAx8vrptWz++Iwlyv1KsvlnpmCtj31YZ3N+YYP0dAvAlZ+IXRbWWKBGW7WnHNF +jQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4karCgB0MC1BnR8W1B+6xeveKW1nLUhu/KIW4e11r7E=; b=NPbxDXGMJEO7lrhPJGmy/qU4XF5IPwxMKXb3Fwk3zZPtjaEPcnnxm7hBGRVWAM5wwZ fe4lhQDBf/ID7gWuAdOKxbby8jqKynS4xj8yBPtYTIqDTtTgP3FqmUuOTaIXPCLw56Po 2KMlA/lQRuX/9GYrSo1uP7fzz5z6NTdtpNpYYKIfoKcHiLkNDm40cdnbAU2pnrUGyCFv TmXAo6g/tmdKEqwyU9ZzTJb/RPQJoZGPGM0keD7GBax+6Ks0QBDSRX+scXV7UwJwK6DT 36VUADX7DW7DNzGYuQHWIoAB3bMQIG38aeamW8xhMWJw4997ue604Eut+mZ2aPWLTZ/u x80Q== X-Gm-Message-State: AOAM533SLKYZznHDdQKyS7sFWtgQc8I+E49sbDgxLr9eIwkMn5Dh7roo L+hIKwutuhAgG12CGNgq0trfBdveah+voK94wD0= X-Received: by 2002:a05:6e02:1d8d:b0:2cf:2112:2267 with SMTP id h13-20020a056e021d8d00b002cf21122267mr7869217ila.239.1652142870407; Mon, 09 May 2022 17:34:30 -0700 (PDT) MIME-Version: 1.0 References: <20220507024840.42662-1-zhoufeng.zf@bytedance.com> In-Reply-To: <20220507024840.42662-1-zhoufeng.zf@bytedance.com> From: Andrii Nakryiko Date: Mon, 9 May 2022 17:34:19 -0700 Message-ID: Subject: Re: [PATCH bpf-next] bpf: add bpf_map_lookup_percpu_elem for percpu map To: Feng zhou Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , Steven Rostedt , Ingo Molnar , Jiri Olsa , Dave Marchevsky , Joanne Koong , Geliang Tang , Networking , bpf , open list , duanxiongchun@bytedance.com, Muchun Song , Dongdong Wang , Cong Wang , zhouchengming@bytedance.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 6, 2022 at 7:49 PM Feng zhou wrote: > > From: Feng Zhou > > Trace some functions, such as enqueue_task_fair, need to access the > corresponding cpu, not the current cpu, and bpf_map_lookup_elem percpu map > cannot do it. So add bpf_map_lookup_percpu_elem to accomplish it for > percpu_array_map, percpu_hash_map, lru_percpu_hash_map. > > The implementation method is relatively simple, refer to the implementation > method of map_lookup_elem of percpu map, increase the parameters of cpu, and > obtain it according to the specified cpu. > I don't think it's safe in general to access per-cpu data from another CPU. I'd suggest just having either a ARRAY_OF_MAPS or adding CPU ID as part of the key, if you need such a custom access pattern. > Signed-off-by: Feng Zhou > --- > include/linux/bpf.h | 2 ++ > include/uapi/linux/bpf.h | 9 +++++++++ > kernel/bpf/arraymap.c | 15 +++++++++++++++ > kernel/bpf/core.c | 1 + > kernel/bpf/hashtab.c | 32 ++++++++++++++++++++++++++++++++ > kernel/bpf/helpers.c | 18 ++++++++++++++++++ > kernel/bpf/verifier.c | 17 +++++++++++++++-- > kernel/trace/bpf_trace.c | 2 ++ > tools/include/uapi/linux/bpf.h | 9 +++++++++ > 9 files changed, 103 insertions(+), 2 deletions(-) > [...]