Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1993339pxk; Tue, 1 Sep 2020 12:49:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3KIUV+xwNwjDV5sAKx88OE0mqwmcslq8i7bJTBP0QpkmJo/DEulJlCmFDvqnoE7Ps5GNV X-Received: by 2002:a50:a693:: with SMTP id e19mr3231045edc.205.1598989752083; Tue, 01 Sep 2020 12:49:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598989752; cv=none; d=google.com; s=arc-20160816; b=AU8La/F6r9nMkufF6cpbyhrhGiksow2R83Y1iU5wR2bYfGMMIWt+/ba59l5TIPJ0sa KQ1+pchX0gWnvwnDDS8k3lmmaK63TRztum04ct2FfWeSbO/mr+cN3pXNd/7trwUGneCx eXCYe/in02D37gvS+FwcVn3xOLMw1uNZEi3FC11uiw5SobwfqIBA/onmLqpO8n03UQHn aGICs22dJAbZKWhi3AwZ6T1EkrG+oAyzYmwFEI/D+egsyxt4uNSC8BRAWl69KSYevmTp lKhCGEWp6qFCVyYTK9z19ZVC5pVTklZMuYEbOYoQqXjlCxUZKa7f8bXNdnRiQ+YxsCKi lokA== 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=kTur4TszHq9523qD6iPQQf45ohXDEUrbbOabBCfKuUw=; b=NtAUsKAdId3DPP5LrXa7JB8SkCHIVQ6h4Vzu3yOXaAtTBuCkNT9jm9ALiSOto/4HJv rksZzwmXil+fFLO8GCdDq9bUKr6NXianyL9RFeGt5Kz+5E/jCYyA4QPKsY2XUqyieXhj jDXu1W7/ReqQ82KKWRDJLCNL8mBmoOu3RROhCLbs1ALnIRhbbG1GzWIA0IR4m9HSor7x GjxhH4vKfXvualLPzNbaPYxqAWTL8547eXJN5AHk7YGCBbHRdH95CypbXkEuP/GFbErV 6r3dg0/GliWBGO06FTXzwKDjwl8W3MNFNJpaDr7CNTbpP4DzMC8vw56HkWXNdUk0KGpZ djqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CWzyYuoB; 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 s5si1205351edu.65.2020.09.01.12.48.48; Tue, 01 Sep 2020 12:49:12 -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=CWzyYuoB; 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 S1731981AbgIATrU (ORCPT + 99 others); Tue, 1 Sep 2020 15:47:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726936AbgIATrP (ORCPT ); Tue, 1 Sep 2020 15:47:15 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53D2CC061244 for ; Tue, 1 Sep 2020 12:47:15 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id lo4so3374635ejb.8 for ; Tue, 01 Sep 2020 12:47:15 -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=kTur4TszHq9523qD6iPQQf45ohXDEUrbbOabBCfKuUw=; b=CWzyYuoBpHyopcW6UGJzCRrbzhPmoxUBaCxI7bRNujUqWrF5to/QhuZqjrS7nxWu0W jAbOrW/VUjLw5eCygcxnnz4+H4WcP4zPwj0aufjfMcS7bjx3wkayFffr7Z6u5k2s8TFD 8tXV8kM+VzEYM9fO8VnSzWieJ5cQoi7lXniCotDInsAEJFLJ7zfDy2L/kUH4emO0IlvH gpqmf3HLFgBRudRPyT4CD2lBOGN0UFZiJ0WwVcUE7jm9LSNP+IE3hPw9g59DEqCzfSEL THiflFVqtJ+7m5QY2g3VNZ5cZdTzYUjw1h86UqHsaXiHTetSrbuY9+PWlnuAGvW1/UM7 Af1Q== 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=kTur4TszHq9523qD6iPQQf45ohXDEUrbbOabBCfKuUw=; b=kZOvoeb96PUtM2COatqg7KzF48btOEiVH4WQD0mXMQOLQztPN+8N0mfcFSOE+HwWge 2Rdcem2DVD5r7C8h2XOBkFuA/xpVmWNKnjo155T6ccFIAwnAJ3XHcmQJWkcKZgA7kj0T DJSB5gC1oUbbZPEYeunVWMrzIeYbXrxZl5bGjYwmH6x086d0LgkZcjfgoqOquhhe34yc NuTBCCk+YKpjrZvEjPkPx0JzFuvaR2tQz8TubAhneZVTlJvycTXtWsNOzSy7S8W7zAUP Ct9dvus94XYL2xh97I2pUJXE3hr1t5t0+PTUSceBrzQ+ahNf5JQWUMjkv8Qp7Raw5Qax jW3g== X-Gm-Message-State: AOAM533rxV3ghfY1kYr4h7HTtJPnE9loqj8SqJ7Cr/DRdflXhSsziEdc xsH5BlZoYPLpJrqAs2zIwgSQpPZkaa19/4LFOr7zyw== X-Received: by 2002:a17:906:a209:: with SMTP id r9mr3270866ejy.413.1598989633789; Tue, 01 Sep 2020 12:47:13 -0700 (PDT) MIME-Version: 1.0 References: <20200819224030.1615203-1-haoluo@google.com> <20200819224030.1615203-9-haoluo@google.com> In-Reply-To: From: Hao Luo Date: Tue, 1 Sep 2020 12:47:02 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1 8/8] bpf/selftests: Test for 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 Tue, Sep 1, 2020 at 11:12 AM Andrii Nakryiko wrote: > > On Thu, Aug 27, 2020 at 8:42 PM Hao Luo wrote: > > [...] > > > > > > > > -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. > Yeah, no problem. Though not going to add this arch-specific variable in the posted patches, I tried array-typed ksyms locally in my test environment. It worked fine, except that the array size is not checked. For instance, if there is a percpu array in kernel as DEFINE_PER_CPU(u32[64], foo); we can declare a ksym of different size and it passes libbpf checks and kernel verification. extern u32 foo[128] __ksyms; It seems that bpf_core_types_are_compat() doesn't check nr_elem. But it seems the kernel verifier does check out-of-bounds accesses, so this may not be a real problem. Just want to list what I saw. > > > > [...]