Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1935848pxk; Tue, 1 Sep 2020 11:14:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgIgFcOc2Fjk3EoV0Jky4TPgQacrpZnj9rQ39LRgqkn2S52LHewcxGw1QyPkv0qCbSDgDV X-Received: by 2002:a50:aaca:: with SMTP id r10mr3000856edc.307.1598984064933; Tue, 01 Sep 2020 11:14:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598984064; cv=none; d=google.com; s=arc-20160816; b=U8W1KjGRbD79tKTY3lmTqVlrVlVlgUu1CVPuQo2cLeRJRtoX5Kbwsrwi6arTEdvPYv n2N82C72wzp3XmE7hFxgD9Jt2H8IfnZYfrY/rYIKyyLBHaWu6rOVGNaeWv4CK4urUgPW sRaE+r81xEsj0DweinVpCANtPqZzGG8n86OwAa96Rwhh61w9xwzjHSvEaQCZDB90MN3o IkFkpm5AlUi/NPV+asy5ZQ0DytGKAidpZIX1qLJdCMikvhmfK8vKRab4q+M3OwJl7k8Q indPF/HL52RW5Z1Dw52lvRw74t90b/fUjrenm6T3Buy2lh0vbyabBpUZn2FvtvdLL2Ej anHg== 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=Fo76CB7ot38YXOx7Pt8T2DJw7Wwns+OpublnLmsqW58=; b=RC4+jpw4rhDKopEf9q0uo7ocR5mWOsEUgvEgI/toNRfhjs7Lcuo96jbDTo/293b3Up wdIEbEXtpgvq/lzgaAqeKSl/dPTXmZ37WBcYF1o7gq3uHW4KoB8CzEHKQJLoDgIw16m2 w1J/Yvo3NY70cuZ6Rgej2D6dMGhYNu/L36m5WftnRvFLn0SOvXzKbiDi8VCMwe3JmWar 28sdvupW50jb2aJpNhCrwbWr4H3WcRRpJeoX7DlRMus2j9RvsypWeHNLI5Lt0Zx7oZNT hnNSwUJ29fQniyCRjXuTASoLPE2fZTOvvKYnQgPZ3XNT2G4QWAOz/OJ1KJ2/+mRDuQE1 HiUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DWGoneNm; 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 w23si127889eji.79.2020.09.01.11.14.00; Tue, 01 Sep 2020 11:14:24 -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=DWGoneNm; 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 S1729916AbgIASMm (ORCPT + 99 others); Tue, 1 Sep 2020 14:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726377AbgIASMl (ORCPT ); Tue, 1 Sep 2020 14:12:41 -0400 Received: from mail-yb1-xb42.google.com (mail-yb1-xb42.google.com [IPv6:2607:f8b0:4864:20::b42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6A6AC061244; Tue, 1 Sep 2020 11:12:39 -0700 (PDT) Received: by mail-yb1-xb42.google.com with SMTP id i10so1318415ybt.11; Tue, 01 Sep 2020 11:12:39 -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=Fo76CB7ot38YXOx7Pt8T2DJw7Wwns+OpublnLmsqW58=; b=DWGoneNm1E0H2TB0kRrtrEM4Z6g03YA3r+WDj4ntFFFH9GwIGOGQiGBcyz4KakgYdQ ZMsLJWOKJNHY3IVCJ78DN+ZJ49+n/urFRj/hZ0ZwS0CNhqzEA9xo/RYCr+1lR4JZWcgK MKFJeUnWuCzkPmZ13p3LNlIaVuLAyrxCMRRM2qzgtrtSBUxlsTVXl8nRNHpuQLpmwJja P8osFyO/zEqQde54OD2UC9OmaWuz+yWjzfrRBc6IBKS9N67UWS0qzzCAAiri93W6lRwr P5XzlbxVHlpVxbGH8vVEEtYA6RqZUEasi9JUcnrcnXeFRQTud30kGVL9uZsrIToNY7VV mXfw== 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=Fo76CB7ot38YXOx7Pt8T2DJw7Wwns+OpublnLmsqW58=; b=CANnVMOTUKyGBwnvJ1+iCWB4XiFO6raobG+DmSGa2Vk7pVo3dC0wQGo50zBRdjfbmv OGcusG2yG0JzGcUjL0jKEd4qg9rzjUQQGIZ4PNnzpEpAfeXUk2o6ARDL7vcBKgcG83EE q359eb5g5GHbEGLI8QfJZWJKBDQc7HaQ+Uw5v1rmNm2lfRtuZcN9qsptGooivTmcSTPI GNtlX+vs/o0lmdF8ssxGB/V/D/C3Z/yNwnHvPTG4Z/XOKhD7tKZsKkW0rOGVe4txR1Yn 7ky+yx1RA9SwRc4APevdOtosv52euxDNl65MgJKRDzKTwK5fNH9oyIChPg/9VYeHwOj8 IgHA== X-Gm-Message-State: AOAM533WZrLGFH0FFE8j6keRsK0SDgukWXKz+SCLNvjE9j2MgjXYqCOQ fj7dtx9YrJS7+M0lpaN3F4Nq16QOJLqqaf3uLeE= X-Received: by 2002:a25:6885:: with SMTP id d127mr4380112ybc.27.1598983957566; Tue, 01 Sep 2020 11:12:37 -0700 (PDT) MIME-Version: 1.0 References: <20200819224030.1615203-1-haoluo@google.com> <20200819224030.1615203-9-haoluo@google.com> In-Reply-To: From: Andrii Nakryiko Date: Tue, 1 Sep 2020 11:12:26 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1 8/8] bpf/selftests: Test for 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 Thu, Aug 27, 2020 at 8:42 PM Hao Luo wrote: > > Thanks for taking a look! > > On Fri, Aug 21, 2020 at 8:30 PM Andrii Nakryiko > wrote: > > > > On Wed, Aug 19, 2020 at 3:42 PM Hao Luo wrote: > > > > > > Test bpf_per_cpu_ptr(). Test two paths in the kernel. If the base > > > pointer points to a struct, the returned reg is of type PTR_TO_BTF_ID. > > > Direct pointer dereference can be applied on the returned variable. > > > If the base pointer isn't a struct, the returned reg is of type > > > PTR_TO_MEM, which also supports direct pointer dereference. > > > > > > Signed-off-by: Hao Luo > > > --- > > > > Acked-by: Andrii Nakryiko > > > [...] > > > > > > __u64 out__runqueues = -1; > > > __u64 out__bpf_prog_active = -1; > > > +__u32 out__rq_cpu = -1; > > > +unsigned long out__process_counts = -1; > > > > try to not use long for variables, it is 32-bit integer in user-space > > but always 64-bit in BPF. This causes problems when using skeleton on > > 32-bit architecture. > > > > Ack. I will use another variable of type 'int' instead. __u64 is fine as well > > > > > > > -extern const struct rq runqueues __ksym; /* struct type global var. */ > > > +extern const struct rq runqueues __ksym; /* struct type percpu var. */ > > > extern const int bpf_prog_active __ksym; /* int type global var. */ > > > +extern const unsigned long process_counts __ksym; /* int type percpu var. */ > > > > > > SEC("raw_tp/sys_enter") > > > int handler(const void *ctx) > > > { > > > + struct rq *rq; > > > + unsigned long *count; > > > + > > > out__runqueues = (__u64)&runqueues; > > > out__bpf_prog_active = (__u64)&bpf_prog_active; > > > > > > + rq = (struct rq *)bpf_per_cpu_ptr(&runqueues, 1); > > > + if (rq) > > > + out__rq_cpu = rq->cpu; > > > > this is awesome! > > > > Are there any per-cpu variables that are arrays? Would be nice to test > > those too. > > > > > > There are currently per-cpu arrays, but not common. There is a > 'pmc_prev_left' in arch/x86, I can add that in this test. arch-specific variables are bad, because selftests will be failing on other architectures; let's not do this then. > > [...]