From patchwork Tue Jun 27 11:53:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 11339 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8152066vqr; Tue, 27 Jun 2023 05:21:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7pLs4QfzylraArve2ys+tR6x846KHWurA1SFdy/S/mh/sk0uu4+S7tmmJRgKQ80QF2hVtt X-Received: by 2002:a05:6a21:1510:b0:114:f112:d8f0 with SMTP id nq16-20020a056a21151000b00114f112d8f0mr24895652pzb.35.1687868477214; Tue, 27 Jun 2023 05:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687868477; cv=none; d=google.com; s=arc-20160816; b=xyYISPY29TRhshL7nnfrFzOw/bqi73oMl0mT+dRDtoPc1GjuRCfftUXStzn76C8f18 8ODjq3ewStvfA++YmyON9aaOKORIBJltd/TH2A00u4LKeHekvnAqlW5cQhCLeT+Wjl3J ZoHHuarnA9NrM8Vvmbwo1j9CXsqdA7AkLiiBWe1PxwONNrbxrDrrz7XV91w9JqWlOnoK 6ZBAgefbnfPhnQkJ6Nc9EHWjKhzBCBvN4Nv23uYBVqdQqhvWbIr02XJqjPkcdIe2Z/ht SAqgIeeh/K4Quhb7jZy3d+c4LXKW5nOwdvlUkErcbbzEBiofzZQc3oxRsynMebg+qWol t3Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DC8eCS1n/CqPPownotds85d4i2CHzR+X63I8C5DwGqs=; fh=oOyr5eKAhccn18uZj16GqOzyJa7ePeXikTQWMgPs4Qg=; b=Ja/EVOFxoL2mLOz7YUKyBnYBCo5gJii7C/bhe9hE09Ipq//edUwmoIqnqTmVIptp9V dWWTrJQjiUD0KcuuNEyZHlBgq11EV/lG7jFx2u3eOo08CJqTjClVECDFppSAMh34etTw 9c6FhBoDzfY1R6mHZfLDZn/ZJzoDTeh2S2OEXRNZA5owvqfAqSqlYEitE46t0Ewk7lAm YvQr5MLCiyW04LFPkMr4N7XbI6UBECnhMhNUT9Rj6BS7ySlJL+rFRmldJWbL9mmpTYop 87IlMbobvx7BtGpG/iOMBJdROA7bHoOrykydf69sKb+WaI3jpxaLn7K/KvZwjVnHcGke 4z7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=J+FA3HqA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d1-20020a170902854100b001b3c66afaaesi6709886plo.185.2023.06.27.05.21.04; Tue, 27 Jun 2023 05:21:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=J+FA3HqA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230445AbjF0LyA (ORCPT + 99 others); Tue, 27 Jun 2023 07:54:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjF0Lx7 (ORCPT ); Tue, 27 Jun 2023 07:53:59 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69F30DA; Tue, 27 Jun 2023 04:53:58 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id d2e1a72fcca58-66f5faba829so1815450b3a.3; Tue, 27 Jun 2023 04:53:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687866838; x=1690458838; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DC8eCS1n/CqPPownotds85d4i2CHzR+X63I8C5DwGqs=; b=J+FA3HqAGy0keXFdKQ+mmKFY6L4ay6ZdVGTdiXlHApv5lt6lO/+cWlqXXp1psvyhpr xJMMw0poN4MSd+jKyQg11EErgupFl4NZwRO5anv5tmA8HXsAhN2wnC38DJYTMQgx2hCU 2k0/e/vNzaJzPU6gt+Xqn+uGZY+KpCbzWzsKPDRuiwmf30VHcaXoSxNEa7g1QZSWrY2E fyts9EJPGTanPq7z65rqRnTW3KwoUtvPAm/G3HHz/NuybJQLWa0KEa/SQ6niHxqcsPmR Pk1bKNhZO0bMTZY3qDmpo35bFhawth9ZT9mx38ohN6lLspewZOGM3XwcvUPCu/juLjDB sx6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687866838; x=1690458838; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DC8eCS1n/CqPPownotds85d4i2CHzR+X63I8C5DwGqs=; b=jn19+qOvbXIasg0Btn6Uwk85obY8NJZWfWgwu2F9urVN9yOSIXYlrmrOgCGl1Nn0QU ZzumOj+mhUgTfG1m8/vFRHVzV8RuDt+puya9j+fvNqOF+fuU7NZdisY7Hrs7pCMua2bm JM/R1dZb3oAGfidV6sDMPfnMbH2ELpGsgs4IBMYaen8/PPcBfYes8UXqUVX+iUFtq7Aq IYQpNogCdYRLYEsxZfM2Daaes3ffsPIexbdV13xMjBZRxR2PQM3nNDN+cjWH0prGlf3/ HmE/zRdRih5v0IkzMt8x+bMYzECDr5PNa+Shf9KhEylCnlVNlGfNIcDEB/eMviDqKFMi qfZA== X-Gm-Message-State: AC+VfDxK7Bto9e2cKGwK+wK2OuisIEmOKKb+fEOYU5cPJKqgd+WWJAZS TnNxv6flJdLrQ9cJ3JapnACFh9Bn1nAcnc0J X-Received: by 2002:a05:6a20:54a7:b0:125:517c:4f18 with SMTP id i39-20020a056a2054a700b00125517c4f18mr14154689pzk.8.1687866837767; Tue, 27 Jun 2023 04:53:57 -0700 (PDT) Received: from localhost.localdomain ([43.132.98.112]) by smtp.gmail.com with ESMTPSA id jg3-20020a17090326c300b001a2104d706fsm4961236plb.225.2023.06.27.04.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 04:53:57 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: daniel@iogearbox.net, yhs@meta.com, alexei.starovoitov@gmail.com Cc: ast@kernel.org, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Menglong Dong Subject: [PATCH bpf-next v8 0/3] bpf, x86: allow function arguments up to 12 for TRACING Date: Tue, 27 Jun 2023 19:53:16 +0800 Message-Id: <20230627115319.13128-1-imagedong@tencent.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769858376499280738?= X-GMAIL-MSGID: =?utf-8?q?1769858376499280738?= From: Menglong Dong For now, the BPF program of type BPF_PROG_TYPE_TRACING can only be used on the kernel functions whose arguments count less than or equal to 6, if not considering '> 8 bytes' struct argument. This is not friendly at all, as too many functions have arguments count more than 6. According to the current kernel version, below is a statistics of the function arguments count: argument count | function count 7 | 704 8 | 270 9 | 84 10 | 47 11 | 47 12 | 27 13 | 22 14 | 5 15 | 0 16 | 1 Therefore, let's enhance it by increasing the function arguments count allowed in arch_prepare_bpf_trampoline(), for now, only x86_64. In the 1st patch, we save/restore regs with BPF_DW size to make the code in save_regs()/restore_regs() simpler. In the 2nd patch, we make arch_prepare_bpf_trampoline() support to copy function arguments in stack for x86 arch. Therefore, the maximum arguments can be up to MAX_BPF_FUNC_ARGS for FENTRY, FEXIT and MODIFY_RETURN. Meanwhile, we clean the potential garbage value when we copy the arguments on-stack. And the 3rd patch is for the testcases of the this series. Changes since v7: - split the testcases, and add fentry_many_args/fexit_many_args to DENYLIST.aarch64 in 3rd patch Changes since v6: - somit nits from commit message and comment in the 1st patch - remove the inline in get_nr_regs() in the 1st patch - rename some function and various in the 1st patch Changes since v5: - adjust the commit log of the 1st patch, avoiding confusing people that bugs exist in current code - introduce get_nr_regs() to get the space that used to pass args on stack correct in the 2nd patch - add testcases to tracing_struct.c instead of fentry_test.c and fexit_test.c Changes since v4: - consider the case of the struct in arguments can't be hold by regs - add comment for some code - add testcases for MODIFY_RETURN - rebase to the latest Changes since v3: - try make the stack pointer 16-byte aligned. Not sure if I'm right :) - introduce clean_garbage() to clean the grabage when argument count is 7 - use different data type in bpf_testmod_fentry_test{7,12} - add testcase for grabage values in ctx Changes since v2: - keep MAX_BPF_FUNC_ARGS still - clean garbage value in upper bytes in the 2nd patch - move bpf_fentry_test{7,12} to bpf_testmod.c and rename them to bpf_testmod_fentry_test{7,12} meanwhile in the 3rd patch Changes since v1: - change the maximun function arguments to 14 from 12 - add testcases (Jiri Olsa) - instead EMIT4 with EMIT3_off32 for "lea" to prevent overflow Menglong Dong (3): bpf, x86: save/restore regs with BPF_DW size bpf, x86: allow function arguments up to 12 for TRACING selftests/bpf: add testcase for TRACING with 6+ arguments arch/x86/net/bpf_jit_comp.c | 246 +++++++++++++++--- net/bpf/test_run.c | 23 +- tools/testing/selftests/bpf/DENYLIST.aarch64 | 2 + .../selftests/bpf/bpf_testmod/bpf_testmod.c | 49 +++- .../selftests/bpf/prog_tests/fentry_test.c | 43 ++- .../selftests/bpf/prog_tests/fexit_test.c | 43 ++- .../selftests/bpf/prog_tests/modify_return.c | 20 +- .../selftests/bpf/prog_tests/tracing_struct.c | 19 ++ .../selftests/bpf/progs/fentry_many_args.c | 39 +++ .../selftests/bpf/progs/fexit_many_args.c | 40 +++ .../selftests/bpf/progs/modify_return.c | 40 +++ .../selftests/bpf/progs/tracing_struct.c | 54 ++++ 12 files changed, 561 insertions(+), 57 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/fentry_many_args.c create mode 100644 tools/testing/selftests/bpf/progs/fexit_many_args.c