linux-mips
[Top] [All Lists]

[RFC PATCH 02/16] MIPS: bpf: Add emit_load_cpu helper to load current CP

To: Ralf Baechle <ralf@linux-mips.org>, James Hogan <jhogan@kernel.org>
Subject: [RFC PATCH 02/16] MIPS: bpf: Add emit_load_cpu helper to load current CPU ID
From: Matt Redfearn <matt.redfearn@mips.com>
Date: Tue, 12 Dec 2017 09:57:48 +0000
Cc: <linux-mips@linux-mips.org>
In-reply-to: <1513072682-1371-1-git-send-email-matt.redfearn@mips.com>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1513072682-1371-1-git-send-email-matt.redfearn@mips.com>
Sender: linux-mips-bounce@linux-mips.org
Add a helper function to load rA with the current CPU ID. This replaces
the inline version. The SEEN_OFF flag appears redundant as the offset is
a compile time constant and can be inlined into the emitted load
instruction.

Signed-off-by: Matt Redfearn <matt.redfearn@mips.com>
---

 arch/mips/net/bpf_jit.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
index 44b925005dd3..ae2ff1f08d5a 100644
--- a/arch/mips/net/bpf_jit.c
+++ b/arch/mips/net/bpf_jit.c
@@ -518,6 +518,14 @@ static inline void emit_jr(unsigned int reg, struct 
jit_ctx *ctx)
        emit_instr(ctx, jr, reg);
 }
 
+static inline void emit_load_cpu(unsigned int reg, struct jit_ctx *ctx)
+{
+       /* A = current_thread_info()->cpu */
+       BUILD_BUG_ON(FIELD_SIZEOF(struct thread_info, cpu) != 4);
+       /* $28/gp points to the thread_info struct */
+       emit_load(reg, 28, offsetof(struct thread_info, cpu), ctx);
+}
+
 static inline u16 align_sp(unsigned int num)
 {
        /* Double word alignment for 32-bit, quadword for 64-bit */
@@ -1115,14 +1123,9 @@ static int build_body(struct jit_ctx *ctx)
                        }
 #endif
                        break;
-               case BPF_ANC | SKF_AD_CPU:
-                       ctx->flags |= SEEN_A | SEEN_OFF;
-                       /* A = current_thread_info()->cpu */
-                       BUILD_BUG_ON(FIELD_SIZEOF(struct thread_info,
-                                                 cpu) != 4);
-                       off = offsetof(struct thread_info, cpu);
-                       /* $28/gp points to the thread_info struct */
-                       emit_load(r_A, 28, off, ctx);
+               case BPF_ANC |  SKF_AD_CPU:
+                       ctx->flags |= SEEN_A;
+                       emit_load_cpu(r_A, ctx);
                        break;
                case BPF_ANC | SKF_AD_IFINDEX:
                        /* A = skb->dev->ifindex */
-- 
2.7.4


<Prev in Thread] Current Thread [Next in Thread>