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: 13925095 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 EC80FE77188 for ; Fri, 3 Jan 2025 02:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:Mime-Version:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Ig6glpfwApy1o7Mm7Uu+S1mQRfa0XZ6/LLKszoVVhZ4=; b=fLf1J3QXq++CEtdB6XF2RbTuQo IyY+bY3xdgqC3wA0yJsmVVKmgNiqH9kLYItBdnsJoyouLGJvYp3rBrdVM7FsDtZdPXld2V6+ILwMd eZ3LLh8ElZENVZWifyoJQqQ8x2IjnumO+VMh8LAEmcD+h7hLi2pI3IKoqWaYvvkrXQv11vqDhQUX7 CcbCDU6Aua0BH/YB9FLNlP/uEdnFwJPPQYfXlQBGVqccnax3BmUSDpEWIUYuy5iW1qMByOLhPIoK7 +y77NoJ2ygOqZ7PE/ScX0jhPfL6jdKdJlEGZIdhEs7I+b0bWkyc1YtweLa6NyBoCCL2FxNcY4BFry o+52smAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTX3F-0000000BspY-2GOc; Fri, 03 Jan 2025 02:04:37 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTX23-0000000BscH-3vBC for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 02:03:25 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2ef79403c5eso24564193a91.0 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=lists.infradead.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=qUHF3zgZZp4At99cbLw9TmI4HCwyWQYTewKdBoldGA3MEwc/TCSokINCHlkpNb/LFi VMtlGkMXMaCYt7fjKJLPNc0J/jkWGrSPNTQVQ94u9vT27F6iXAutpY2jfSuB1lY8cQ9D GCP/gatVYpGJ08osHeRjclnFzi4BDVh2GI+8+MqjoCNDlfwXe4UiKblP8d0roIWbkLry WNHXzMCvH3INtcTwxcnEYxINHh66/BE/lmj/JYrYf26FSLSszcvDoMkt9t77ip+Z7aqY fKeKIPC7nHw15qvn22yfJcERzEXtwDatSwj2SKBp67ewl0pCDheAOqM+s1sxUInToG5y vm3g== 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=LzxhUhYNaMs6pYj0uCDkWou6RxDXxgk4mOnML5Njx9s50J36OavzA/HsqhfgaoO2jZ lHubnBNAcCakGGPbHEIaypU3hdNTXnxsqZIghzOZKBMmbS+iuxbEdtcRzRbW9YACOCaF 0XwzujPSd2mYwWBjS7UaQEFzPfvQGV10QemKqLrKUAUG+ONfJFZQr9BNDvmlL2IP5pHT PMJ/qW4ec4LhUNjG2kBhrjKTcIrRfuvdYE7eWPnVw2aMIc6pxNXlLhMKdeEZrb5bSIKd sLh5PW46lUvHZTk8/hAdBJWC4RctaAfUZFDcnrBuujs+tskEK0sRs5gDka3Y+kHprYuu Dggw== X-Forwarded-Encrypted: i=1; AJvYcCUxb+InZS46BXv90gnJE4X32Qc4du0zriiw0aQM5Xjr21eVnIra6R1zPdc0r0e/CSKo5JxAmmNPNwa0HesuTL6V@lists.infradead.org X-Gm-Message-State: AOJu0YxIYgxR4YLer2GDbfKEEBIFxrnQGIOeMjAaNDrFmB2XpRydBn/f ObzqHuEUeazBs6XtTcCIObyBiF0UL8/5RyN13H4lESdjo0q1jHVOZggEcNlP/vZHeU9u93OdNul 7K6+wNYWwlA== 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250102_180323_989852_9300FEDB X-CRM114-Status: GOOD ( 10.04 ) 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 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: 13925096 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 A51E8E77197 for ; Fri, 3 Jan 2025 02:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CRJO5sUVsBrx9NfUdY8awEzhAYM8yo71RmYXdt5ov18=; b=boL3Zk1tQmDFeSaEJujhBsPloC uE1/oq9dhOkFEiBiqH480xKzFw7QE02YpEZVTyKkL4IoSNh18AYYzvjXewLuFqUsR/o8O7HygczoX Fm603szPkQ9Q1F+oEpXZpDUn/41+5quJAz04WIFMnR/TU9OxozycvApRWdsex/P1EePpzpChkkgDY bkKI3ydnkaREnDvy74wRp/ZQyP2OGuHpOsc37ik/fjwsR4j53j1bnGefS/XLrdjnVuDYPD1nNPvcd XwuFTE/IXuQgHFrT31PyZFlt4IqqvrdeJpubXWLZ30Fa10qAAMNJMbZkONyX3E/ox51vyqpx/8acy vYxNtCsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTX4S-0000000Bt2u-0ubL; Fri, 03 Jan 2025 02:05:52 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTX2t-0000000Bskn-1bus for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 02:04:16 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2ef909597d9so24544865a91.3 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=lists.infradead.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=YCCZyKcnifMGsIM1WDTmpMSz+oaWz52hSl5M5iSDc6DOpfOL3gpKoqhTV12P/qPruu PkJScagFFY8Pf3/UQ2tbBDZniDYJaCR1ZhqBZvgkmvaJn0XokAuKaE8ZTyRirH4264bw lEwX9FQSsQNwLDeFBiBLYwF00p1cdxAqVJYhJVdt4iFY/ftpIWXKLbAz0kJtUpM3Dv95 y9qZG/4fkIRyuw5MXHsbXdj7gbHI5LJ42XI/5/qc2j9LQ+9duow4ZTEQRIgApVcLmbs/ wgUh59bewtDgKTfZ326g93uo71UmLFaQQ95TVhu9bvEkRIQl7yZ2WcNKC0/kh1uXBXhi pONA== 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=d/nG2neYXaiFtYM/Z7M67TaT8wIordzEgGvXxOnnGj0v0d0qYyiP4zBSi9fm+4hdHr pTI4k3bzwI45bzWy7WLtDd7Su1aAVMOsbQ2rlDA7HdGhQDzf19+RvEHtnZhG2ocNIrr+ quFYTrx9U+kCYPNu+K0eWS6gqSygttf51ZHNfshhpURvMkoSKiFE2P1rOHpSW4hP3iyc vA7ShvA0nRhyYxvLaQQ7XRkH8BH59JqwpRtkMtdkpuBp7SegjOmedgL5fzLlgUaWVnyG xB9GI41dhz6yzd1ouXTfjlQcwzGNuSHGxZj9hNSsGOfMOBTjZBpLbi43pHz7aiYobTT3 GCYg== X-Forwarded-Encrypted: i=1; AJvYcCVeVIf+oLve+KzO/OIFnD2sfI4y8IMYL7dUE9CRHWBH1BUpLsx/j25w/7olU3IQGECAIYUTzFea6E8iD8JiPzea@lists.infradead.org X-Gm-Message-State: AOJu0YwGWkUt51rQjACvFAQgcz+h9wmKjITL8aDc0MA9jHj4DQfhnYdY 3MJpSVliks5OC6NSjkRGcJytKBmkcFxZRDQa74dUYE/9WtPXblAK8pTCwpj14E+9XBNnoxp3nw6 IylxelNFqZg== 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: 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250102_180415_420222_632FB4AF X-CRM114-Status: GOOD ( 12.11 ) 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 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: 13925097 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 04C2EE77197 for ; Fri, 3 Jan 2025 02:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4UjZolz5E/NeRAD/hPdz8QuR6mdLUg8da+IaKtziAes=; b=LcCnjs2ZipbONalW8RgS8ufrNq nEv4vxMZvZ2w/GwNwknpBnxPtTmgQKcuqW+g6ydaYNgOJ8DnLCAjgMy5RUogVOTxgAaZZawTgfsjR VCVgpSYFFjFXe8qUIV/9FM8iLJ6obKLvVlIrjYpDRZIhF454qoPK8bcPEDjWYiyQ4LP8jYjOFZMVU QL6C6T4mB4iQyO8hss3hR1o4rHEndgy/x3No/6IEV24JE0L1pZT2Pxqb8pgE13tTT/KLHk89GzBaj 2NG7TINDYQ2VRQTr/WKEzMBD+vmYFDtOtDZEypt8y2pY9DQMz4Edguo6KIUsFyBQ3I9RoMUZLxPU5 mdgqAHEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tTX5h-0000000BtHJ-0hj8; Fri, 03 Jan 2025 02:07:09 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tTX3Q-0000000Bssd-3pzl for linux-arm-kernel@lists.infradead.org; Fri, 03 Jan 2025 02:04:50 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-21631cbf87dso143788735ad.3 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=1735869887; x=1736474687; darn=lists.infradead.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=muyLex0FEF3J44w5Voh0f4xO237bjkHPOU7bToNo38cN9LeAwJdD+0XiBctc0pFkxR 1+JlNYxXd0o8V0XB/SLwTK4gTGHcFaRSrK+cSBTTkanoR8EpvYdS01usZYrz1lUZ/pUx lxJ1I5Tfen7YtxcZS6HV/OyZETFshEC5ukEvWHAf3vTWaM8Ts/rbANUFutugrOZ1lkIn YZQ8eiJpdpc2IvKjGFwnAvlWiLd9uII+V2KF4KVi9ZtpoYcRaNDTt/P9tAz/BhNGNf3P zHkBvbwcKozMxsiLPIqYyjggrZ5n1GjB1pDrlt8OKZ30G7AMUY/Cjekri92z76bbE6NU Y2Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735869887; x=1736474687; 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=tNSYGJ+PhEI5x57iBNemecggfMlgajnppobBLF1OOJcztJQTp1HQY4Ca1lrXPvEEc4 ne/0O75MD3suLlFbvUL7pwb9rS0RBK+KaA8aDYxXg4mCJU1s6XynO8n+mOnzv/V2MCpx 6RXbhYwY7PxtPyL8buJ8K5vuAVONq3EDHAjA+RRQmTzGjcM/LLU2cNpfLdrwyojK8+W2 tp/KizqUbJqBqOtX8q7XleRPwT37okT9TmFv7GZckWoX+k27DbH1xA8ZUkBigokqDHLW 8dwqPf42wXN25HoxCXoqKjd3h+Yl0jl6mbzMHq4eF/6vQTk8l2XgHRX9gArRrlpNv4el KiHw== X-Forwarded-Encrypted: i=1; AJvYcCX1KDDDMciQD0oPaPdsbYIjxnJ/8k1V04+VLn8oivG3PidNLKt/VSX+enZrzyEQ2Cnvw+FuGMsPcdgEuzBRCh7I@lists.infradead.org X-Gm-Message-State: AOJu0YyOYIlLtbsvwGFF2ibyXbXebkLysThTzF9x594aQM5gKg3kiGLV TBDcJI+0ZzjaGknjlqAtqf7i8cox9FBk/Houaq4ur4v3iKmTMUphBZE/oRt0cqkki7obtBQBT3b 3FJdjK/0nlQ== 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: 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250102_180448_965680_5DA5356B X-CRM114-Status: GOOD ( 14.42 ) 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 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; }