From patchwork Tue Jun 27 11:53:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 13294395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6ED9CEB64D9 for ; Tue, 27 Jun 2023 11:54:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ci+v5RioQ6m+FBw206VDr4b9bX1/cwwsHRUACh+pbsI=; b=R9kYq8wjvfAnx7 BfntiLsfHBw1+ADdEO7xo8M3dLG7iLjoaZnf51dYcQFopVzWz1WeCVKlbSndTcA102hyDZYG2uc4H Yaezz+oZ0SKu22ZIm2dg6uGDb3QMaVx8JiS94N7WgFaVk4JoHWIVfO8GxAKrQa9bP2WRLFNm7N5He 1Bw7FNBr1ebCM2g6jC23YZHL3eIdiq8WXDRWF3z6m1dltlJgoa5bHIOkSVGySd7c/9RxXBRocCEHa XV/gA+Lpeaf5+VVTUuzNQ2tjoYivxoe+78BkW2uw0ScCTBUA81lz1YTgobNhU9r1RNI6BMch+mGiJ RFxwFdPbmcGncWBzNMgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qE7Gt-00D6Cl-1v; Tue, 27 Jun 2023 11:54:11 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qE7Gm-00D6A7-07 for linux-arm-kernel@lists.infradead.org; Tue, 27 Jun 2023 11:54:05 +0000 Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-1b7f68f1c9eso22883225ad.2 for ; Tue, 27 Jun 2023 04:54:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687866842; x=1690458842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9UQHgCYMSUpJKwkxCT8Gz4j2ViWlUBZ9rAr/225IOUc=; b=l79nZCW6i+H8KEntEfZJU3WoFNVHt3GJ2ez0IKkzMmhANEfia2mXwZIJmhTOkUUAsA j0n5ehct3U4l+REY4Cq25vGRWuYSR99M/iVT3GYGXUh6/KjDmFjF2zwxvVz379EKWjO0 brZ59B4YjkIsFSwsMNvvEZoKsywq4N9QMACvI32ycB1Rzvo6Lc+B/7f7bZAFL1WwE01H XwcihlaXNzCDCfAVkZH4oxIGFZQvfpPkTYyPfltEYdsKIyuIz0EpikaUA1X2VFPqrN5D prDSeNoAnUjJKLBKzzg7d9wgR3HVKkBCwaAwNqA4quVBaO8EzVSsgioAXlRjsW3DdEK5 weTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687866842; x=1690458842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9UQHgCYMSUpJKwkxCT8Gz4j2ViWlUBZ9rAr/225IOUc=; b=kaXbr2cM03cBlg91Jx2jiqBeNNdf/iXciBDlY2HVouds/pjPLQrh0rKuO4SNiqG86M cI8dcbUWzMBahwc6oJUx/bi5Iti0+JwqgbbEQ0jLKgeyBODzhZnn0D/DIQZYUsKmJHhm KCDNbDhEcPKuKr6ugt3Mvb+EKZD/ygqQ5yQCfgO7CawI4uWDwJ4uMo4wmzDM7ctcrXmK 6ur9EXx56R4Lpus9XuCSD6u7xstElLPM/tb/kHfkf7+o4GBWFZ23cflDfDOMCzPBwtpT xIr1dd0mmKbjo13DUGmojY4dgUFFjyz2vOM4+G0BSBzmPM/T1nGGg8Lkp52DZshiUY0R U42w== X-Gm-Message-State: AC+VfDxsUVgNusqcpcG3IiWCOovsWOlbpQYMDbkQa2U/Z4/cl/rtBTap EqovSwhIS0V2sSqZG93Ehqk= X-Google-Smtp-Source: ACHHUZ4DXwh9A/bc0yLr0zijT2AzhRBJ90cHk+qZmsTTw9nYa8YG2g3qscxJc28RujM+uy222e7VGw== X-Received: by 2002:a17:902:f552:b0:1b5:1e24:8a76 with SMTP id h18-20020a170902f55200b001b51e248a76mr11609716plf.65.1687866842319; Tue, 27 Jun 2023 04:54:02 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 04:54:01 -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 1/3] bpf, x86: save/restore regs with BPF_DW size Date: Tue, 27 Jun 2023 19:53:17 +0800 Message-Id: <20230627115319.13128-2-imagedong@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230627115319.13128-1-imagedong@tencent.com> References: <20230627115319.13128-1-imagedong@tencent.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230627_045404_074440_327C02B6 X-CRM114-Status: GOOD ( 13.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Menglong Dong As we already reserve 8 byte in the stack for each reg, it is ok to store/restore the regs in BPF_DW size. This will make the code in save_regs()/restore_regs() simpler. Signed-off-by: Menglong Dong Acked-by: Yonghong Song --- v6: - adjust the commit log --- arch/x86/net/bpf_jit_comp.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 1056bbf55b17..a407fbbffecd 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -1860,57 +1860,34 @@ st: if (is_imm8(insn->off)) static void save_regs(const struct btf_func_model *m, u8 **prog, int nr_regs, int stack_size) { - int i, j, arg_size; - bool next_same_struct = false; + int i; /* Store function arguments to stack. * For a function that accepts two pointers the sequence will be: * mov QWORD PTR [rbp-0x10],rdi * mov QWORD PTR [rbp-0x8],rsi */ - for (i = 0, j = 0; i < min(nr_regs, 6); i++) { - /* The arg_size is at most 16 bytes, enforced by the verifier. */ - arg_size = m->arg_size[j]; - if (arg_size > 8) { - arg_size = 8; - next_same_struct = !next_same_struct; - } - - emit_stx(prog, bytes_to_bpf_size(arg_size), - BPF_REG_FP, + for (i = 0; i < min(nr_regs, 6); i++) + emit_stx(prog, BPF_DW, BPF_REG_FP, i == 5 ? X86_REG_R9 : BPF_REG_1 + i, -(stack_size - i * 8)); - - j = next_same_struct ? j : j + 1; - } } static void restore_regs(const struct btf_func_model *m, u8 **prog, int nr_regs, int stack_size) { - int i, j, arg_size; - bool next_same_struct = false; + int i; /* Restore function arguments from stack. * For a function that accepts two pointers the sequence will be: * EMIT4(0x48, 0x8B, 0x7D, 0xF0); mov rdi,QWORD PTR [rbp-0x10] * EMIT4(0x48, 0x8B, 0x75, 0xF8); mov rsi,QWORD PTR [rbp-0x8] */ - for (i = 0, j = 0; i < min(nr_regs, 6); i++) { - /* The arg_size is at most 16 bytes, enforced by the verifier. */ - arg_size = m->arg_size[j]; - if (arg_size > 8) { - arg_size = 8; - next_same_struct = !next_same_struct; - } - - emit_ldx(prog, bytes_to_bpf_size(arg_size), + for (i = 0; i < min(nr_regs, 6); i++) + emit_ldx(prog, BPF_DW, i == 5 ? X86_REG_R9 : BPF_REG_1 + i, BPF_REG_FP, -(stack_size - i * 8)); - - j = next_same_struct ? j : j + 1; - } } static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog,