From patchwork Fri Jan 3 02:02:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 13925092 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42BFE440C for ; Fri, 3 Jan 2025 02:03:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735869804; cv=none; b=TBhlEi5culJdJkV2ErVADBm2MBBl8WvaUMRRyfKuhvdPYymcNUl/WGOeGMF5rMA2zkBvKbxR39iuuEG5oinE4gPz01lBDsuIWigr6nQYMZPAWKDKQD5OzsgaTOWsrQ/LSYS4xK8/JGk8R2+aYML2QM0V7RtFfDbIr8MgY7UxbQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735869804; c=relaxed/simple; bh=7M8KDiGWZcqb4au6OxwB5Xt1yz5IHJ9IJCKzqqw/0wI=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=H1bdBP35v9MkMLvK77jcbsGTU1UyL4HkU/7B1eKe/YT0OaRf/kH1JzZ5xpwbzDD7yhudmbdqubXa7XrvJgPBSCEZo1GpSppSnx6PBumkBCXAya+9Q3Xc/WKBKMFbg72LzZ0oGv0xDq4aYgSYvxDAnLtRglM3P/QXvqE2BEsPV3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yepeilin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ikJDigS8; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yepeilin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ikJDigS8" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef909597d9so24543890a91.3 for ; Thu, 02 Jan 2025 18:03:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1735869802; x=1736474602; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Ig6glpfwApy1o7Mm7Uu+S1mQRfa0XZ6/LLKszoVVhZ4=; b=ikJDigS8bBMw7iayY5EbWUCtR3YVpvoXaRR7/IzaUOyg8j8imcpyDoKMqWRavwBNkE oayXiBEudvPI2FGSuH/H2gwJId2UPiH3OnN3uO0covVacIJI1U+yz7CKuvQbcVLzoW4/ 3f6qgTXnyBv4iuL9XM+KnBkarETPqrr9JcVTisrNJGWN7WfUc2MM9P/yQXqEAvRLJy3c JKuuyJ8DDxQWKx59cOQ6yYNfeEtWDtMFen8YKi0htSpIJgCyOXoRkhm4wHJiiHkg5jr9 6IeE+YcbBiisBooOENAz7E8kovwKIM2ZwxVVrOaFxxvK97wjHOtETvdvrdp4MlglYxkJ GzVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735869802; x=1736474602; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Ig6glpfwApy1o7Mm7Uu+S1mQRfa0XZ6/LLKszoVVhZ4=; b=dVEgPw6Laedmiz4iiDz7Hc9uPHudjI1PPlmE4BlQEH9WVnULAzohEQNlgNxDtYkFx/ 29pQ+AZlb/Q9SSvklWMnMPqv210rpsw6hRQrFGeHbuRBhM4BuuenmhATUnO3MSQNGfoT cmAEnn/OHVIlYg2DBW6mDxzrs2l6SPW0MyGRNSYZ9r//MBhlgYPz81TXYK7mA8aBmBkq nWF8oawpfqPk+7qPrFOF+O5ZuIxvjKE7ljGCVFU6dAXola2+3pihmo8PexSlTC7Cp9/S TwXaQtDVehueQhQjNQh7Lao/9xSgXkxAjHbLyX0xZ3DfzFRZfVENo5zIdzYtiTyIzfhS rHgA== X-Gm-Message-State: AOJu0Yw7te5QjtX7tRyXABN0sHcAAMnRcGFc+bGBv6l2LyTC17TEzCFT +KKWXdk34DCeZXp6J+QJREnY8T2W70Aq6uoJWG2fUyu3Rd7VJ8IxdF0SwJkafOLLBhkpXvIAJeI mSNm6keMfJQ715aeptKHvtxH2WjnE3p3RzilMXNTtMr2I0k6qT0h+HmJAXHypwwgw3seBF7cXn+ Y0HeMacklFcK2TgOznZxc955ND8ckVsDbNTNxn8+U= X-Google-Smtp-Source: AGHT+IEL5evFIYGE70thXWV9wnfSiMcphGKAQ6COYmizEZzma8el/TiuwM5NuPGwXcKyaiMPRwLa0I52lt/X5Q== X-Received: from pfbct13.prod.google.com ([2002:a05:6a00:f8d:b0:729:69d:93b6]) (user=yepeilin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1944:b0:71d:f4ef:6b3a with SMTP id d2e1a72fcca58-72abdeb6e80mr69465699b3a.21.1735869802431; Thu, 02 Jan 2025 18:03:22 -0800 (PST) Date: Fri, 3 Jan 2025 02:02:53 +0000 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: Subject: [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic() From: Peilin Ye To: bpf@vger.kernel.org Cc: Peilin Ye , Xu Kuohai , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Puranjay Mohan , Catalin Marinas , Will Deacon , Josh Don , Barret Rhoden , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Delete that unnecessary outer if clause. No functional change. Signed-off-by: Peilin Ye Acked-by: Xu Kuohai --- arch/arm64/net/bpf_jit_comp.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 66708b95493a..9040033eb1ea 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -648,16 +648,14 @@ static int emit_lse_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx) const s16 off = insn->off; u8 reg = dst; - if (off || arena) { - if (off) { - emit_a64_mov_i(1, tmp, off, ctx); - emit(A64_ADD(1, tmp, tmp, dst), ctx); - reg = tmp; - } - if (arena) { - emit(A64_ADD(1, tmp, reg, arena_vm_base), ctx); - reg = tmp; - } + if (off) { + emit_a64_mov_i(1, tmp, off, ctx); + emit(A64_ADD(1, tmp, tmp, dst), ctx); + reg = tmp; + } + if (arena) { + emit(A64_ADD(1, tmp, reg, arena_vm_base), ctx); + reg = tmp; } switch (insn->imm) { From patchwork Fri Jan 3 02:03:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 13925093 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B09C881E for ; Fri, 3 Jan 2025 02:04:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735869856; cv=none; b=vGsDLD1P3os39MxI3LFCT1hMt+NuecTDO2VtJUNCkzx7ZG67jAFt3++pbLUZZH5jaTl18DJ967/5tPsQW56Ss0wWFMgNcTlc6KTU18QQSpN2EeF1KWON1y+8uZ8vN5th35BWMluiMaxv6erBJmMG4J/AXPXBr552poxGHgR7RnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735869856; c=relaxed/simple; bh=ZLiyialT+0DxhDmBYMrB/1yqgRGE7s2UacOAT4wHHxk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eHWLSFZRlQE+IgdbbgLdg5Vj4QIKiaDmO9Bl8Se1rrzytJM4V1vv7MBXA6u5PBrljBrtcbjw3Fud7UJKeg/wKc3pQT8qM8TTRS1tWm9/HGYb1PBEcYl/jPlHc2jQVg1AOsSgOvmyBWv19NRjJVYn6uWwxx1ihsRCZQq1g6C19PA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yepeilin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PZH1RjQ8; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yepeilin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PZH1RjQ8" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef9864e006so24546912a91.2 for ; Thu, 02 Jan 2025 18:04:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1735869854; x=1736474654; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CRJO5sUVsBrx9NfUdY8awEzhAYM8yo71RmYXdt5ov18=; b=PZH1RjQ85iCrklNzmn/rPVRrv9+VORNsrIWfK15Boh8qEQWbuUKb1d55TOQFvVud8c tSpQkWjsSqUjFGzphgjL+wAfXE1hUzF29VyXjdBSFzZbbdWK6nH56m4W4HLQei3BjlVU AIqkPAeoY2DEDdVfa6+wHFp9yN241G0p5tbHTr7QHgV50twtEJ8CIEl1sGGuSOf163bl Mjdlnz+1v80p9wDM7s5/0F1jouSXJ+a8g/tT4+xPIo39jJq6cVJfFkhD5bcUkc7YHadF OWxj7k3Dqf8lKNCKbn6itmKGZkgg/CxCdIv2b6TZQaFq0ZVF25oxRVHRfSwrAKF97n2u Z4NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735869854; x=1736474654; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CRJO5sUVsBrx9NfUdY8awEzhAYM8yo71RmYXdt5ov18=; b=fv4Wdc8wZYqVChEEAvEM7mdIz/ln0GFphOHYtsXokHpnABpqoq9vJR6Sl9lpKxySCI AFwjo/TfyolmkXcZVaGlYtN8KYT9mI6AwhKeTKFyUjitFZ5R8sWcajZ0rUoOu/7TwnBp Rv7c3Q2VsQQWG4VW3p3iCPYFRwv54mrxbgvXPyLMxcdlnq0f8xh5E4oHlWDnZ5wNlfWQ UHfCAcDKrzhDe9n0vXlrNfyvhC4UDkaa0EDql2UQnlFyKxs8YCXOK3FQp+z1rpiDZpIg p70qpWbRMAFuNmsdUqB1wBAczHs899Q6q0/giw2eKDQXZ5AbfJCv1Vg8b4An7QkP3Wpp 1w2Q== X-Gm-Message-State: AOJu0Yxo6qP/09YK89651Tn+3fY5dztSJbi4ypUfuPGGwdEbsBK2LDor n24pFtByOk4myPLe1eqeCCfNfBlyx1d+mWVPw3SLysjpYz7K9ySTVnA+ins31nmqUiG5eD6yrhh BCOVxA6MqLShhGVUeT4e/v/TYTAORxRL+XmycdDpmqhSjXJofC8NJhWwBnRH7Ym+CgQg3VeaB0X p8LzTeocQypg4l6aTWQvA4U8qj4DePFdCo5BlvPvk= X-Google-Smtp-Source: AGHT+IHZadCFsRAvM/8s8XCvSBmeC0l850mBUK5zckCFiZPbJN2N7ovFIIHdSAEoiRRH/qyjjHZNBrMLvPsyVA== X-Received: from pjbsm15.prod.google.com ([2002:a17:90b:2e4f:b0:2ea:9d23:79a0]) (user=yepeilin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:50c7:b0:2ee:d96a:5831 with SMTP id 98e67ed59e1d1-2f452ec713fmr73098024a91.30.1735869854278; Thu, 02 Jan 2025 18:04:14 -0800 (PST) Date: Fri, 3 Jan 2025 02:03:42 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: Subject: [PATCH bpf-next v2 2/3] bpf, arm64: Factor out emit_a64_add_i() From: Peilin Ye To: bpf@vger.kernel.org Cc: Peilin Ye , Xu Kuohai , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Puranjay Mohan , Catalin Marinas , Will Deacon , Josh Don , Barret Rhoden , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net As suggested by Xu, factor out emit_a64_add_i() for later use. No functional change. Suggested-by: Xu Kuohai Signed-off-by: Peilin Ye --- arch/arm64/net/bpf_jit_comp.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 9040033eb1ea..8ee9528d8795 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -267,6 +267,19 @@ static bool is_addsub_imm(u32 imm) return !(imm & ~0xfff) || !(imm & ~0xfff000); } +static inline void emit_a64_add_i(const bool is64, const int dst, const int src, + const int tmp, const s32 imm, struct jit_ctx *ctx) +{ + if (is_addsub_imm(imm)) { + emit(A64_ADD_I(is64, dst, src, imm), ctx); + } else if (is_addsub_imm(-imm)) { + emit(A64_SUB_I(is64, dst, src, -imm), ctx); + } else { + emit_a64_mov_i(is64, tmp, imm, ctx); + emit(A64_ADD(is64, dst, src, tmp), ctx); + } +} + /* * There are 3 types of AArch64 LDR/STR (immediate) instruction: * Post-index, Pre-index, Unsigned offset. @@ -1144,14 +1157,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, /* dst = dst OP imm */ case BPF_ALU | BPF_ADD | BPF_K: case BPF_ALU64 | BPF_ADD | BPF_K: - if (is_addsub_imm(imm)) { - emit(A64_ADD_I(is64, dst, dst, imm), ctx); - } else if (is_addsub_imm(-imm)) { - emit(A64_SUB_I(is64, dst, dst, -imm), ctx); - } else { - emit_a64_mov_i(is64, tmp, imm, ctx); - emit(A64_ADD(is64, dst, dst, tmp), ctx); - } + emit_a64_add_i(is64, dst, dst, tmp, imm, ctx); break; case BPF_ALU | BPF_SUB | BPF_K: case BPF_ALU64 | BPF_SUB | BPF_K: From patchwork Fri Jan 3 02:04:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 13925094 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E7BF1862 for ; Fri, 3 Jan 2025 02:04:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735869889; cv=none; b=tiw2XlyAE5c9TG+rdOqIKW7j+eUIXyfQMKux8hs4ujLj44t/CvQeWontBLzn20qruzYZg8FE6dgc2v4Df94vR0hy6nktnzA7EoDf3WstscwE/l46rrzQ2mzgnM3D7m6BFpgk/1emA1vJvKJTT6SLg10F8XYJVR6CNYlagmsp5sI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735869889; c=relaxed/simple; bh=cXAi7bBYPwuN2p39neBGKD3ONxci6buooHsHLy2tIIg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Jr3i1ofACrMQpqMqtq43zgypOubvE1LJBFL1U38OrN/fxcEzx2e+nBSgG/68h5D4n7IQo+ph08xq61JRh1e5nI1NAJthCmeSHm3PuvgqMryzdhu38gkkaeoWngsTK/gtOoJHUklM/1NVwF7Uxl+/GIpgkqSVEfFtjs6qfwTWNKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yepeilin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UedJ4dqh; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yepeilin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UedJ4dqh" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2164fad3792so154847185ad.0 for ; Thu, 02 Jan 2025 18:04:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1735869888; x=1736474688; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4UjZolz5E/NeRAD/hPdz8QuR6mdLUg8da+IaKtziAes=; b=UedJ4dqhgQ+sbcktpUWyYJlkixyb0RTwurNbfY4bOQ+7JjI4GSx5R96WWcgZYQXL2w WYFBJcvnFXpy64EXwUedvQW2dT7wPkdAvMQ6eUqXK849u1ksUg8vDQC203sLN90e9n3j vRutQ8KAS8931Hw+xR1c3iZvXeAGwKYnCsbXY+EdCq7aGuOkJu+XprpbVvBJMh8SGimB 7p8qA9RdOgifcQ0KfpUkkxfSIQNPItCwQwtc/v7BEHiAz5Y8ue2E41eJ3GKZxA/DIbPV sRCg3VkLe5/0Omi+d6vqXxkbNTG2PQbNab3uaSfL/COAi3Wjf8FcDJ0uFO+PZPHrz6Ga iDew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735869888; x=1736474688; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4UjZolz5E/NeRAD/hPdz8QuR6mdLUg8da+IaKtziAes=; b=GivvWXzxeb6BPCq/kD6tGYcSg0bAbGz1nKxcUjTZfmqoDIcwHK9LuhGn3+USlPwY1I 1MBBXjjdBZUx1hcz9xAWlxkJasf2YWXx+hietBT7AZHJJHhskoh8yJTalusJvygHw4Ec GKS+aExHaAzBmmtlRyqtdVOWu5/z8H0DG25UakkwhvE+9Edvug9Cs1YJfBe9vxmyI0Xh 2UqP9YnggZcWCj2Z1r1ZW+UvesNcIshFMys3gwUzCEyyfcRXrloeROLB5Rcj/3Z7qR+5 4xPM7wfSOfkGiVnhabs6Gmo2U5IaPni4+56ld7LrN6kYDG8EScltRn0H/LDl/lLRV4pm IBfA== X-Gm-Message-State: AOJu0YwpY5Pfo0TDAUAZXM+gLTDJkf4WriGQnvMRvLmBnwvM6e2fn5/m i3aWKolPZHaEdlHYSngRpQehrXDTKV7kXyeL2Tp24Y2/gx/rrXeMqgwm/ahmwNTKcEXMKNob4zR 3CJrZS1ShluMn+5rQZi6nUdU6W9VIr6BKlpQRazDwH0qRZkrA5u4RGmHDIe/77b/2otJGBx+jpL LeyMNa15AoEol1oS/38bwN4gPGZ/MVXTLe4jHc+Uk= X-Google-Smtp-Source: AGHT+IFn9sa16Ybx9bMnT3j8/6v7ZyNcSwDP48OOodsufyBW3mKo0tvoS5jljQA1jigXnWx+/SHMhWvEv0+uPw== X-Received: from pfbc2.prod.google.com ([2002:a05:6a00:ad02:b0:725:eeaa:65e2]) (user=yepeilin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7896:b0:1e0:d9a0:4ff7 with SMTP id adf61e73a8af0-1e5e08011d6mr82625682637.32.1735869887482; Thu, 02 Jan 2025 18:04:47 -0800 (PST) Date: Fri, 3 Jan 2025 02:04:18 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <9ad3034a62361d91a99af24efa03f48c4c9e13ea.1735868489.git.yepeilin@google.com> Subject: [PATCH bpf-next v2 3/3] bpf, arm64: Emit A64_{ADD,SUB}_I when possible in emit_{lse,ll_sc}_atomic() From: Peilin Ye To: bpf@vger.kernel.org Cc: Peilin Ye , Xu Kuohai , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Puranjay Mohan , Catalin Marinas , Will Deacon , Josh Don , Barret Rhoden , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Currently in emit_{lse,ll_sc}_atomic(), if there is an offset, we add it to the base address by doing e.g.: if (off) { emit_a64_mov_i(1, tmp, off, ctx); emit(A64_ADD(1, tmp, tmp, dst), ctx); ... As pointed out by Xu, we can use emit_a64_add_i() (added in the previous patch) instead, which tries to combine the above into a single A64_ADD_I or A64_SUB_I when possible. Suggested-by: Xu Kuohai Signed-off-by: Peilin Ye --- change in v2: * move the logic into a helper (added in v2 2/3) and use it (Xu) v1: https://lore.kernel.org/bpf/953c7241e82496cb7a8b5a8724028ad646cd0896.1735342016.git.yepeilin@google.com/ arch/arm64/net/bpf_jit_comp.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 8ee9528d8795..8446848edddb 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -662,8 +662,7 @@ static int emit_lse_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx) u8 reg = dst; if (off) { - emit_a64_mov_i(1, tmp, off, ctx); - emit(A64_ADD(1, tmp, tmp, dst), ctx); + emit_a64_add_i(1, tmp, reg, tmp, off, ctx); reg = tmp; } if (arena) { @@ -734,7 +733,7 @@ static int emit_ll_sc_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx) const s32 imm = insn->imm; const s16 off = insn->off; const bool isdw = BPF_SIZE(code) == BPF_DW; - u8 reg; + u8 reg = dst; s32 jmp_offset; if (BPF_MODE(code) == BPF_PROBE_ATOMIC) { @@ -743,11 +742,8 @@ static int emit_ll_sc_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx) return -EINVAL; } - if (!off) { - reg = dst; - } else { - emit_a64_mov_i(1, tmp, off, ctx); - emit(A64_ADD(1, tmp, tmp, dst), ctx); + if (off) { + emit_a64_add_i(1, tmp, reg, tmp, off, ctx); reg = tmp; }