From patchwork Wed Jul 15 21:43:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Luo X-Patchwork-Id: 1329823 Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=PvN9qtLW; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4B6W8p5N6Yz9sRk for ; Thu, 16 Jul 2020 07:43:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727108AbgGOVnT (ORCPT ); Wed, 15 Jul 2020 17:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbgGOVnS (ORCPT ); Wed, 15 Jul 2020 17:43:18 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30C4C061755 for ; Wed, 15 Jul 2020 14:43:18 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id i203so4593362yba.9 for ; Wed, 15 Jul 2020 14:43:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=WPW2jthcymgJJnDe4srAy8GflGzwLl52ZFtIA0Ixzqw=; b=PvN9qtLWYSDsNHkgj/A27DsYxbLZ/Xnm+V0boSzvB8ey5BIexmosCy7fP6UkN8Zb4C sjRU/+R5zu11ex3BuKYJXCu8Ou4nJO1JBvDeL/VWYvR9Ex4e5VutdUb9RQCUUB8sYUag 2w+3i8jQdmRvbG9KhMIy39jcQELLbsG//2Iy5fj3qTFiC12LFmrkC3diSfvc5Yuxy/9F KtwNHAQwI/2lNQ+CS57Ti7gxaqePN96jkHJ039IoZCkJHRp1e/E5SdJmPZj6+/Kr/vMy 7T5pI1oyS6yTvXp3k+5+h5huvsrNOh7L4gpAnasiC27Ib9QLtf6R2tjZRCDElxuZLeOS 18uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=WPW2jthcymgJJnDe4srAy8GflGzwLl52ZFtIA0Ixzqw=; b=Iz+z3mXPahWelolofW3w7N/MspJItPyD3p6dX8iQSizra9FtKvG7mSBDtydD6sdrls 5ZLVNvUi8DlFFaMF2uZwOwb9quUxqH1CGG2eXF0b4dV3s5+iteXjJKMZ/wb5L8PAMSVz dRVIpwfAShDp5N6CuEKLuv1frnXNSiZH8Lpli0Tq933sx7ElQpAHxLeNf3TdeaLuVvxP g6gjhGPV0hUHn+XANOzJSeMtdQ3zdXQjPi/3yyHXOLMyI7OkAFeoJ6SXHEtrLb61EMAD J0DhHWZJTvbfuXLC2PIcsboLVIrYveeLPzaOln6lb6f+P+Td+8D0xwyzjqsJko8V1yRx 5Z5A== X-Gm-Message-State: AOAM531FZcg/L9gJZZ8xU3+7lfxth8J7ROkz9BeR6vDWDPy6uho6f7uz K/IUD0SQxsA2BkUxnQo1+HMwibNkAoo= X-Google-Smtp-Source: ABdhPJz/qTdRjOyD9NiyHcxQ5X4u25G5pK7DjjWbH8sfOQ6b1U0bIDyl+0KlG5qp/aUt1V0yHVOLYZN+VVE= X-Received: by 2002:a25:6c57:: with SMTP id h84mr1497780ybc.211.1594849397781; Wed, 15 Jul 2020 14:43:17 -0700 (PDT) Date: Wed, 15 Jul 2020 14:43:10 -0700 Message-Id: <20200715214312.2266839-1-haoluo@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.27.0.389.gc38d7665816-goog Subject: [RFC PATCH bpf-next 0/2] BTF support for ksyms From: Hao Luo To: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Shuah Khan , Alexei Starovoitov , Andrii Nakryiko , John Fastabend , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Quentin Monnet , Hao Luo Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org This patch series extends the previously add __ksym externs with btf info. Right now the __ksym externs are treated as pure 64-bit scalar value. Libbpf replaces ld_imm64 insn of __ksym by its kernel address at load time. This patch series extend those extern with their btf info. Note that btf support for __ksym must come with the btf that has VARs encoded to work properly. Therefore, these patches are tested against a btf generated by a patched pahole, whose change will available in released pahole soon. There are a couple of design choices that I would like feedbacks from bpf/btf experts. 1. Because the newly added pseudo_btf_id needs to carry both a kernel address (64 bits) and a btf id (32 bits), I used the 'off' fields of ld_imm insn to carry btf id. I wonder if this breaks anything or if there is a better idea. 2. Since only a subset of vars are going to be encoded into the new btf, if a ksym that doesn't find its btf id, it doesn't get converted into pseudo_btf_id. It is still treated as pure scalar value. But we require kernel btf to be loaded in libbpf if there is any ksym in the bpf prog. This is RFC as it requires pahole changes that encode kernel vars into btf. Hao Luo (2): bpf: BTF support for __ksym externs selftests/bpf: Test __ksym externs with BTF include/uapi/linux/bpf.h | 37 ++++++++++---- kernel/bpf/verifier.c | 26 ++++++++-- tools/include/uapi/linux/bpf.h | 37 ++++++++++---- tools/lib/bpf/libbpf.c | 50 ++++++++++++++++++- .../testing/selftests/bpf/prog_tests/ksyms.c | 2 + .../testing/selftests/bpf/progs/test_ksyms.c | 14 ++++++ 6 files changed, 143 insertions(+), 23 deletions(-)