From mboxrd@z Thu Jan 1 00:00:00 1970 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 5BE2EEB64DC for ; Mon, 10 Jul 2023 10:52:11 +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=awg/Pd0A1NBO9Ff8zUFeCk7RMjQE4aWAodl7Kr0yTJM=; b=vt1AhoUjezDGO2 /uc26PzoBsocv+qaKAw0WtkoOpLfRG9ycuFOr/gYLNk5fYOlDOmwvkcHcY4ETefAuseePPxq2kWOv PtyXwNOMGlMerWViIjuuO+z2Akvnd+A4HAUH6HK+2sR7KIm8J1pTl7knu9nII6DTayODtPrdKss5G sVDSZC2Jl4VBZ+nHiilzuIn901pkkSbKIxY/kBacvpwvyu4p7L63LNOYRS6ztmIsgbBnEWZbJs/gj oYRvFFcdUPax2uo7xAUibBU6jbwDvL+EzYaxyeAi7DL3kIE1DT4vSy+9p/3dv0UP5XonL1lfjZDMS z7Wl6N1sTCFVigAJyMdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qIoUc-00BNfs-30; Mon, 10 Jul 2023 10:51:46 +0000 Received: from mail-il1-x143.google.com ([2607:f8b0:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qIoUZ-00BNdP-2D for linux-arm-kernel@lists.infradead.org; Mon, 10 Jul 2023 10:51:45 +0000 Received: by mail-il1-x143.google.com with SMTP id e9e14a558f8ab-3459baa237bso22912695ab.3 for ; Mon, 10 Jul 2023 03:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688986302; x=1691578302; 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=n9OF5rBDxNaq2DXKTbLZbdXHNFefw4Fd6mHFek0g5ew=; b=Pj6bEUk7bbrQ24jt74tpb/KwzjGwHGC6+/a+Et1mMEMCBH0GNMyRv+2Ac542F/BtX8 xxRmAH9ZQQd60SczD2HfTkKH6xgs3zPKdPzLoRyiTlsD78+4QaIb4Ag1Xr81uif1Xiry FywA3Fl+evLMrngvcATXuoZjsGiomLn6ovriVqjzQqwB4e0T8oEILkU2rREjLdbGhVn4 PBr4x3vlSbLCZpwQRT+O7yZ//l6/Yt5WAsx3J7cpS8ZPhCLeYtYJcElhtFwXV6x6FOVg /KgSa+/YLuxH3q7H99oUJpWB9LTAwjjp928OT7sGDZTwfwEKFnSvmuRZeMrDTC5JIQZy l6RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688986302; x=1691578302; 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=n9OF5rBDxNaq2DXKTbLZbdXHNFefw4Fd6mHFek0g5ew=; b=CmhegbdCZZWEjGsQoUk2oz8GFRJFiUvvHRpa1mFVMP0Bq/mWS9HYbnEWdky0MuCaLM I4mVB8TBI6II1ioyXBDPfAbAe7uek49TfpiJq6C1ZKEoO5k5OS5K+ue2oMlO8sKamRvH vj01TPIgf0fliM6DDSogAKR8B8EqE+xDThtkyVF1dQYUzwQN4gyPPTpHEOiihRl1n3uV BwxamqOuZTG4Op91qYYDMLqnfhwzAHKvqOloUpcvzhsr/DbqEQH3NKQ7IKWKGW+AQvGc 7sNDEWxasxE2sTAoxBIM5sdvLpQAC6xlcrriQV4uvLjobjGUr2l/V4Y/EfiZoDbB7u98 Oyeg== X-Gm-Message-State: ABy/qLZEPGKq6vnEVpTKukvo+2+SOHhUkJMnhh2uw3rrQdq7JHtTZxV2 F16rXFi7GJ5m1J0XIpeJ9Uk= X-Google-Smtp-Source: APBJJlEqjFnrvKb9nACwwOX7jpspg56BTIFmgbdx1btyclRuFS3qHPuQ7rREV2KdztzJWAl2JUL9uw== X-Received: by 2002:a92:c846:0:b0:346:579f:408 with SMTP id b6-20020a92c846000000b00346579f0408mr4751365ilq.1.1688986302281; Mon, 10 Jul 2023 03:51:42 -0700 (PDT) Received: from localhost.localdomain ([43.132.98.106]) by smtp.gmail.com with ESMTPSA id 17-20020a17090a191100b00263eb5054ebsm6475036pjg.27.2023.07.10.03.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 03:51:41 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: yhs@meta.com, daniel@iogearbox.net, 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, dsahern@kernel.org, jolsa@kernel.org, x86@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Menglong Dong Subject: [PATCH RESEND bpf-next v8 1/3] bpf, x86: save/restore regs with BPF_DW size Date: Mon, 10 Jul 2023 18:48:32 +0800 Message-Id: <20230710104834.947884-2-imagedong@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230710104834.947884-1-imagedong@tencent.com> References: <20230710104834.947884-1-imagedong@tencent.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230710_035143_726426_2555E41E X-CRM114-Status: GOOD ( 13.96 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 438adb695daa..fcbd3b7123a4 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, -- 2.40.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel