From patchwork Wed Oct 7 20:29:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 11821715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB3C4C47420 for ; Wed, 7 Oct 2020 20:30:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7664F2083B for ; Wed, 7 Oct 2020 20:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602102605; bh=XEou1rU9ybH1ZQ8kfxcrur9eVBHQSywF1HP+pAYLJKo=; h=From:To:CC:Subject:Date:List-ID:From; b=0CmMa/lb+KoMBQo8f82zrn3/ZXAcyDygxFCec2KkW4YP6mvurb+wkOhCfb6/aIE2r KCB9pBvz5GNrdN4EnFVGxkCNV33sEpInYnbhoX4llQfS1WDA0IJEf1ZCGHDHio3Ykv +2doAG/VxKIO4QLJyhJtgjuhpfEh8ZMu1p/o0wxs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728476AbgJGUaE convert rfc822-to-8bit (ORCPT ); Wed, 7 Oct 2020 16:30:04 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:63158 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728313AbgJGUaD (ORCPT ); Wed, 7 Oct 2020 16:30:03 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 097KTQcb007517 for ; Wed, 7 Oct 2020 13:30:02 -0700 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 341408vj03-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 07 Oct 2020 13:30:02 -0700 Received: from intmgw002.08.frc2.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 7 Oct 2020 13:30:01 -0700 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id CF9CB2EC7B90; Wed, 7 Oct 2020 13:29:47 -0700 (PDT) From: Andrii Nakryiko To: , , , CC: , , Luka Perkov , Tony Ambardar Subject: [PATCH v2 bpf-next 0/4] libbpf: auto-resize relocatable LOAD/STORE instructions Date: Wed, 7 Oct 2020 13:29:42 -0700 Message-ID: <20201007202946.3684483-1-andrii@kernel.org> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-10-07_10:2020-10-07,2020-10-07 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 malwarescore=0 mlxscore=0 mlxlogscore=589 impostorscore=0 lowpriorityscore=0 suspectscore=8 adultscore=0 spamscore=0 clxscore=1015 priorityscore=1501 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010070131 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Patch set implements logic in libbpf to auto-adjust memory size (1-, 2-, 4-, 8-bytes) of load/store (LD/ST/STX) instructions which have BPF CO-RE field offset relocation associated with it. In practice this means transparent handling of 32-bit kernels, both pointer and unsigned integers. Signed integers are not relocatable with zero-extending loads/stores, so libbpf poisons them and generates a warning. If/when BPF gets support for sign-extending loads/stores, it would be possible to automatically relocate them as well. All the details are contained in patch #2 comments and commit message. Patch #3 is a simple change in libbpf to make advanced testing with custom BTF easier. Patch #4 validates correct uses of auto-resizable loads, as well as check that libbpf fails invalid uses. Patch #1 skips CO-RE relocation for programs that had bpf_program__set_autoload(prog, false) set on them, reducing warnings and noise. v1->v2: - more consistent names for instruction mem size convertion routines (Alexei); - extended selftests to use relocatable STX instructions (Alexei); - added a fix for skipping CO-RE relocation for non-loadable programs. Cc: Luka Perkov Cc: Tony Ambardar Andrii Nakryiko (4): libbpf: skip CO-RE relocations for not loaded BPF programs libbpf: support safe subset of load/store instruction resizing with CO-RE libbpf: allow specifying both ELF and raw BTF for CO-RE BTF override selftests/bpf: validate libbpf's auto-sizing of LD/ST/STX instructions tools/lib/bpf/libbpf.c | 151 +++++++++++- .../selftests/bpf/prog_tests/core_autosize.c | 225 ++++++++++++++++++ .../selftests/bpf/progs/test_core_autosize.c | 172 +++++++++++++ 3 files changed, 539 insertions(+), 9 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/core_autosize.c create mode 100644 tools/testing/selftests/bpf/progs/test_core_autosize.c