Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp173873ybh; Mon, 20 Jul 2020 13:29:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2ilOGXKzfOUrj3+1d45QqpizpCYyFHGevQWG5PC4lqItVkF/xfaG4btMfmt3iEhWUW40m X-Received: by 2002:aa7:d814:: with SMTP id v20mr23035928edq.296.1595276950771; Mon, 20 Jul 2020 13:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595276950; cv=none; d=google.com; s=arc-20160816; b=wzMZ1C6n81bWobgAWxlo0qeB87XZ1b99DYuFgks/yAtkQ68wJPMZOEAPWfxndhEkDr jvHLGx3JLvTJ6N1N2AJRXpBIMTh14rmH8YHv2YH7srcFKbuDUnDPvPWJuXzAbRCBwulK KlWuObdjn60NbZO3jAj+6hdtYBJOdUKwhohr8peW5JpjWjuFyxhZWpc6VrcgPtPFhJgz BTUw6Pn6hlIYaZNV5IQ7C0jHpw9cvniLTkGrXLUs6XsN4pjQ2mN3w8xm1z+5wJ4otifi s4OVKO4NCpFGhH8RjFU7YlWyf/gG6WQNJIJNSAPDWERU2dkzncfAVdO/i+Tn/PjlAg3m MDIg== 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=jnROxpLTebfdg0VQxLM+qOeJIWXx+3VtqAPYTCwBg5A=; b=UyyqBYkijG8XYkMDh++xa7muUwqdhJ88FM4V79qMMAga6cqUxDFTD6dz/JR9GUq6dW YGAihTCOKy/myaup6psqfLSoV7X2HGvwPThrHyVJ9chmMDOu4R3m3CW1t7YmMmz/peKp 28+bsR7xpWnIAO7JMOeZ0FPGDLSMbF/M9XsS0wGC6CRtnzKLkJQYzhFmy1RkJi43z8jl NaiUGzz2XoOhjpy9PnYtYjA94DridLi7I+eSx2+n7pd0YU0iERy+ipmDapxJvj2w+uAs CmMmntKF9eu/mBSDyC3i7nVfqdMRQZJm9s14fQDpsxjsT3L9lbyXsRZ9kJFFjygNlMd4 Pv8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=e+YdMIZb; 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 g4si10934555edq.459.2020.07.20.13.28.47; Mon, 20 Jul 2020 13:29:10 -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=e+YdMIZb; 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 S1729265AbgGTU2Q (ORCPT + 99 others); Mon, 20 Jul 2020 16:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728324AbgGTU2P (ORCPT ); Mon, 20 Jul 2020 16:28:15 -0400 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52E6AC0619D4 for ; Mon, 20 Jul 2020 13:28:14 -0700 (PDT) Received: by mail-il1-x143.google.com with SMTP id e18so14471350ilr.7 for ; Mon, 20 Jul 2020 13:28:14 -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=jnROxpLTebfdg0VQxLM+qOeJIWXx+3VtqAPYTCwBg5A=; b=e+YdMIZbfHuIN71zlAV9pte6XTKkIrMTuKqwzmQZxOkC954LaZlH12s9VMPeezYI/f Jzv9Vzo+NY9vuVMW7D959S2Cdvs9ichUR+pxGCUw8tgcn9EqQtUg+gaQcJ0/MHWorqZG /UDNGpn0SIDSdKMAMJQOHR7Re670rfu9J3bP/upy5wVU8JbcSWFw7jSVkEhpbdUvmmwy 2XkrGG80hp9CMfvxOaOhxtD9ErS7CIYgMtAd9PUGPwpxpdRbgachvMNiitkCzU4SDh6e WfI7egJn+xCqdGw1WJUiGfrYepxPaHbyfX45EeOp+TCrHvYYLqEQ82fwEjcD0Fx5Lj35 diTA== 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=jnROxpLTebfdg0VQxLM+qOeJIWXx+3VtqAPYTCwBg5A=; b=g02xyPXae6Xcu5TnFnUdcsZ9Emt7Fnt9YGTR9cSr4h1/kJhnDBO8QUz1DHImldwaXi TYHgVqjWpkcMun5dkKAfQAO7oXgXDZPGCWhfdl0YxpknI8p07AgLqBt/Pw6cjOTi44cA w53HDg1UXJWxPOSlNZ5u8xL1Zji5j8xGvrKKYiyb0y6kOejmoeFPtdqjGEPJKM1vkh6D 0tJgBPBnhf2+qW8M9KcKR7iWX6x3nJcM9zjvl9u+dVxvcNlX1LS2uy4v5YBEJnCaY+P9 RnvJO8BEh6m+XGFLR+2lP887E9vct1hQtLRMuRfu8WQZUZ6CFK8why/G0NgUdVLRBqeU iByA== X-Gm-Message-State: AOAM531udxG+VEd0sBdTbCJOXwtsiXDhRgSdfvTBsLMsP8U7apYV/4bk tDNMcvjYRlOcHQ2UQm5P6JEA01PVGnpyfO5ZSuKa4A== X-Received: by 2002:a92:bb57:: with SMTP id w84mr25017823ili.104.1595276893343; Mon, 20 Jul 2020 13:28:13 -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: Mon, 20 Jul 2020 13:28:02 -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 > > 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. Hao