Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp910686pxa; Thu, 27 Aug 2020 20:43:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz8AldEWVxzGvh3xyEDtcxKU8p4e+MchAbUY8X1bEBZjHUhIf97fxDcBYjAn7Ivg5H6FS2 X-Received: by 2002:a17:906:3417:: with SMTP id c23mr24026986ejb.45.1598586223176; Thu, 27 Aug 2020 20:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598586223; cv=none; d=google.com; s=arc-20160816; b=OOMSSbK/aGEpyTOOrnVbHWolTDwnahHYitxGubMt/3Kam4rlNxZlyv/1IIvkPPJLW1 DMD10Cg+iVVJpcD+IeWitmP+Q5Yw1oBsaj8rAaIayal2RcsNr2c6/p6CcoNlYQmDw4Qn 8PwVKxY0+sYXHhNoREWzcXZgU6ZnH+pNIFgHMoYzrEQxsl1xeiraATby2Z4A04JTQfL4 tzgsdxb+oGUZPwvv4ZjpdZfeYvs6qb1wW6zDs8rpXaXSqCHsuRTC1dxrkm8RuOJg+puQ OkOOYH3pxQPIJhk2qwKtzRyHfyJN1S1tkVRwhKHtxj8PHPBiH0CGWWmiKlKL/IphSDWG IMmw== 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=Wl7POtGUJpujC577nqFjmTBAOmvQ4nTIGwkF53IPEDs=; b=qytwXeuaCmmX5XXN3NJBrZimt0OgIXF+R/l98fI0z7wEa/H91rWEdYvpywNIi1nYYb MypKCw5ND/jUZ1ZcnsQWPVFNYys26LRnFq7beq/+zk0/AzDsmFUbMo0Me3CgWxCMQyeU Rs+yOEBf5iGdLxyGxfeIs/l3C2O/Ho8CHMwFoCSxtVda3/UXjsUmOBDUiP8dZ5l9vVEB HQxV8bcUMOhx5LYqED+YFAQOG0AcrurEX+/+P0IZ00rMUlooDfCUTXeVUCu1rfcE3Qj/ 3wZ5UzlnGtNc3KnHkwGgsddDxfUZETac4wl/BhHsF6kidqxP7Kl7FbVwz9ylZmIGGCzU LH6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tq0zGDR9; 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 ng5si2598093ejb.90.2020.08.27.20.43.19; Thu, 27 Aug 2020 20:43:43 -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=tq0zGDR9; 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 S1728122AbgH1Dmt (ORCPT + 99 others); Thu, 27 Aug 2020 23:42:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727817AbgH1Dms (ORCPT ); Thu, 27 Aug 2020 23:42:48 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAABAC061264 for ; Thu, 27 Aug 2020 20:42:47 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id e23so9719284ejb.4 for ; Thu, 27 Aug 2020 20:42:47 -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=Wl7POtGUJpujC577nqFjmTBAOmvQ4nTIGwkF53IPEDs=; b=tq0zGDR93T6ES5KjCAtJcuuPzPguZpOtkbOunk4JUInNQbuoAVAJvp++D4hQ1yRLG9 oVPESLvDSvN/SxHxeQBn/z/jPgT6PJD8LEEIA9IyLij9gJ1K6+1fPJHnJ0EoDT8b3Ey3 WdmEq+7HQmSJcbiUqvgLSodFl+JDqVoT85Ibx6I87W+TjP1QncW/tz9j4q/JVPBsZaj1 gONchDfblDPomG0BR+ZL49xl0Fu5y2j9uQAVCn2UYlnN2/qTkbxSswMf4Mi3d370TMHJ WHUTT1bZSwkkCnhEOOAFbmilHPa4mwjSE7kHdORspUTiVg9cDmo+mshEIyS/3rtOo+yV f8NA== 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=Wl7POtGUJpujC577nqFjmTBAOmvQ4nTIGwkF53IPEDs=; b=oqxRC7rBB1Nb0I00nErg7rvWgxjjXpCGu1pyo6gafS5VX6fpi2cRXdbyATllkYHDqt nGXz6CfzP8mfMM4OfofSp4AQZiQQrDVGA7cQaw3ks6c3zZE8RJbcwE7226Hqz0Q+mC8Z ZJJIyR+LvK0ltPeKxdSG3qHk8tbCLaqyGn8GKZRSp1mc6cM/5fkC9HoTY/gwoTh+zNHf sEdiwbXW3EdEDK37CM6akLAduEU5zigOisHpHgoLxU9ugYtU9QjQ5SDNAzwS22T5IC3l yJpKf1e043VzeAUfJNVONr8RfIdnATiagxK527LoCUjn/HnnJLOL5h1dl8pclea8JB8s TymA== X-Gm-Message-State: AOAM532FlSykAAccXoabEBAPV+eTwCoyjg3s5PRggpzPc++54ywctfyV EmYr35mMs6ttzUvpobEJnXnBd+wPjHoCv2uxbbxAig== X-Received: by 2002:a17:906:6406:: with SMTP id d6mr23310789ejm.30.1598586165507; Thu, 27 Aug 2020 20:42:45 -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: Thu, 27 Aug 2020 20:42:34 -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 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. > > > > -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. [...]