Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp870093ybh; Tue, 21 Jul 2020 09:48:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPk/hG5S9kWp8d95nkJ3y4C6Df2XF7Yew7BcH6g5i0j4Z+LWDknUHSMKksEySxhB9MARxc X-Received: by 2002:aa7:c504:: with SMTP id o4mr26316985edq.311.1595350125975; Tue, 21 Jul 2020 09:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595350125; cv=none; d=google.com; s=arc-20160816; b=hz3IenptUQD7KOaNw9HjmSrMbobyTzVuqD0ELQ2VOlovWevFiPRO9GU4n/er5gQSLy ioJef59oz7n89hhdZJLxt0/+W+qvdtqiZYh2aGZ5zY5qV+JUyS/4zzP59D7AnLlll0QA id1C2CCHzsSRGrCuo5hsdSsqRwXsxqxpwGqgqeYX7APUHkzChbeqJBUCXt7Eeryt0dyI tDtwj4JePB5EumduM0ALJ+GexODEIFHDXR9mXhWUZ1rK0ROpTyLqCsyGPkbZ8lZrZ0bH 7p1bpWJ2P9GafdUB6YHn/aAJnXLLv/0NnxTl1ConFpR8C+aCAhrKv7Lir8wWVBDZyUqM aDkg== 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=gDLw9Dcw3YPv5eg4D1cNA4KJREZ+5phRSHLKAVCSqo4=; b=Bq+hmTIS6s/3kJ6qifGBeEc9RKp8/r9pm5b+mhmF7t2JreW0wn7TLGTGwhiCK2Hw6d SIfD1E1K/7Q4t6YIinZyYwCp/FUCrKrjSaTGbGgpk4k8yBnh8sh228zSo878VGYuQRqn iXOeJ3iIWNCMb7gkQwfHyf2j412kwm1AmA46W/tWa/juq5QcfIu/hk0nK0LAwaL9sLOF 5Io0K1wtOvCTMgjct3wFXiRKVAj8r2SBoWPyAd0I7uFsvW74A0a02Zk7sXjFtKFe1Eb+ Ink8ljMJqYM9M4GHycKF0HaaxDMunHAevms13qKTA1znu7sQiMLn6er+CESE/jajECi4 njsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sWaGYNFN; 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 p18si12506981ejb.157.2020.07.21.09.48.23; Tue, 21 Jul 2020 09:48:45 -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=sWaGYNFN; 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 S1730651AbgGUQpm (ORCPT + 99 others); Tue, 21 Jul 2020 12:45:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728750AbgGUQpj (ORCPT ); Tue, 21 Jul 2020 12:45:39 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFEE3C061794 for ; Tue, 21 Jul 2020 09:45:38 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id e22so15759035edq.8 for ; Tue, 21 Jul 2020 09:45:38 -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=gDLw9Dcw3YPv5eg4D1cNA4KJREZ+5phRSHLKAVCSqo4=; b=sWaGYNFNvLHfLnFqhWw6qD05fZJ3xzg9qHpo5WavC+HOa4H9WOO8R58q/QpUclGLry 9IL4j0cs6T2tzt1njgxmRIdcHQe5/HHEbENPKtlUivjjo0774Sk4dPYbx6pNd9sj+Hba BGIPr7vGf3Wz1I0ZlD9HrORuybaANBJwq3p9No8LKz53+Z00y2Qe5yTAZzt4xK0KTD14 opOIvzeXklxODdltPMXE0N5/iPdGcCtOPo35S5qmc4oYuzfqMy8yKOjCCu2miu7Qw5xg SL+vKrFM9D2pcb4rxS2e3UFTvCX3US6gxaITccHPkYUeoMaMFGays+1SH64jb+4HGZ6x uO9g== 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=gDLw9Dcw3YPv5eg4D1cNA4KJREZ+5phRSHLKAVCSqo4=; b=N/IxZiWktsoTf86K5Oa4xykcOHNUNWECfFlwvpSFpyvIjWs+7AeeqOhPP1IfxKS5KV qCOUIGKRtjmYFuIlHhitMCkcjdH/of0FikJG8UcU0MCE4hnhcUORpdSnEnYvBHrIPC/A bp/fYnSvidFzQtVl22xgyG62WyjQHK254uioStuCaHsqt3eKY+FR0/kDQ138hz5fLMlU O1Y/S8jSlrA5R//HOpol2zh0krZJ7Juw4FN1jMWfsOly1p4jE78WLQvvnsrg7cL7kBhi 1/xqvUxjiaXBbPLotBwM/ArrmPP9dB1wX/2oiD7lgYlSOqzURdU+yjWAiv0fp9uvHlQk Khnw== X-Gm-Message-State: AOAM530tSeryfJ1VVuLqxR2SF4DbW2zhfD7nBMwfkCGZgn3g4NpXGE3j ikrsOoxwDqa7L4NXnqHyfFOlGdp9bdhiWqTni9A9vHtYL4w= X-Received: by 2002:aa7:d5cd:: with SMTP id d13mr27413638eds.370.1595349937400; Tue, 21 Jul 2020 09:45:37 -0700 (PDT) MIME-Version: 1.0 References: <20200715214312.2266839-1-haoluo@google.com> <20200715214312.2266839-3-haoluo@google.com> In-Reply-To: From: Hao Luo Date: Tue, 21 Jul 2020 09:45:26 -0700 Message-ID: Subject: Re: [RFC PATCH bpf-next 2/2] selftests/bpf: Test __ksym externs with BTF To: Andrii Nakryiko Cc: Networking , bpf , open list , "open list:KERNEL SELFTEST FRAMEWORK" , Shuah Khan , Alexei Starovoitov , Andrii Nakryiko , John Fastabend , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Quentin Monnet 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 Ack. Will have that in v2. Hao On Mon, Jul 20, 2020 at 7:37 PM Andrii Nakryiko wrote: > > On Mon, Jul 20, 2020 at 1:28 PM Hao Luo wrote: > > > > > > > > This should ideally look like a real global variable extern: > > > > > > extern const struct rq runqueues __ksym; > > > > > > > > > But that's the case for non-per-cpu variables. You didn't seem to > > > address per-CPU variables in this patch set. How did you intend to > > > handle that? We should look at a possible BPF helper to access such > > > variables as well and how the verifier will prevent direct memory > > > accesses for such variables. > > > > > > We should have some BPF helper that accepts per-CPU PTR_TO_BTF_ID, and > > > returns PTR_TO_BTF_ID, but adjusted to desired CPU. And verifier > > > ideally would allow direct memory access on that resulting > > > PTR_TO_BTF_ID, but not on per-CPU one. Not sure yet how this should > > > look like, but the verifier probably needs to know that variable > > > itself is per-cpu, no? > > > > > > > Yes, that's what I was unclear about, so I don't have that part in > > this patchset. But your explanation helped me organize my thoughts. :) > > > > Actually, the verifier can tell whether a var is percpu from the > > DATASEC, since we have encoded "percpu" DATASEC in btf. I think the > > following should work: > > > > We may introduce a new PTR_TO_BTF_VAR_ID. In ld_imm, libbpf replaces > > ksyms with btf_id. The btf id points to a KIND_VAR. If the pointed VAR > > is found in the "percpu" DATASEC, dst_reg is set to PTR_TO_BTF_VAR_ID; > > otherwise, it will be a PTR_TO_BTF_ID. For PTR_TO_BTF_VAR_ID, > > reg->btf_id is the id of the VAR. For PTR_TO_BTF_ID, reg->btf_id is > > the id of the actual kernel type. The verifier would reject direct > > memory access on PTR_TO_BTF_VAR_ID, but the new BPF helper can convert > > a PTR_TO_BTF_VAR_ID to PTR_TO_BTF_ID. > > Sounds good to me as a plan, except that PTR_TO_BTF_VAR_ID is a > misleading name. It's always a variable. The per-CPU part is crucial, > though, so maybe something like PTR_TO_PERCPU_BTF_ID? > > > > > Hao