From patchwork Thu Oct 8 00:10:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 11821985 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 B1AFAC43467 for ; Thu, 8 Oct 2020 00:10:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B5F2207EA for ; Thu, 8 Oct 2020 00:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602115836; bh=Zx8NyjaMC/BDM1OGnmsHQh6UBf6DLQhhIK47/34e1Js=; h=From:To:CC:Subject:Date:List-ID:From; b=jTewYZDzKG9ort93C4c0bwg0POAUoSBQFTwqXlyIfJ+ZiPHSVxX42yapsH89JG24s e+DnBodFlQhgguEDKSJmGn4X4S5c4/fTtZ7i1L2BwVpqZn3lSxv3ZAXNKLYE49uGsP hc5UDUhpXgYWnLPIHaZSofBaN1G3LwfQTeLICHpM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726956AbgJHAKf convert rfc822-to-8bit (ORCPT ); Wed, 7 Oct 2020 20:10:35 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:9174 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726129AbgJHAKf (ORCPT ); Wed, 7 Oct 2020 20:10:35 -0400 Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 09804bPs006079 for ; Wed, 7 Oct 2020 17:10:34 -0700 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 341gpajfdh-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 07 Oct 2020 17:10:34 -0700 Received: from intmgw003.03.ash8.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::5) 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 17:10:33 -0700 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id E57D72EC7C0E; Wed, 7 Oct 2020 17:10:26 -0700 (PDT) From: Andrii Nakryiko To: , , , CC: , , Luka Perkov , Tony Ambardar Subject: [PATCH v3 bpf-next 0/4] libbpf: auto-resize relocatable LOAD/STORE instructions Date: Wed, 7 Oct 2020 17:10:20 -0700 Message-ID: <20201008001025.292064-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 phishscore=0 suspectscore=8 mlxlogscore=570 adultscore=0 mlxscore=0 impostorscore=0 spamscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010070156 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. v2->v3: - fix copyright (Alexei); 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