All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH bpf-next 06/10] s390/bpf: Support address space cast instruction
Date: Thu, 27 Jun 2024 11:07:09 +0200	[thread overview]
Message-ID: <20240627090900.20017-7-iii@linux.ibm.com> (raw)
In-Reply-To: <20240627090900.20017-1-iii@linux.ibm.com>

The new address cast instruction translates arena offsets to userspace
addresses. NULL pointers must not be translated.

The common code sets up the mappings in such a way that it's enough to
replace the higher 32 bits to achieve the desired result. s390x has
just an instruction for this: INSERT IMMEDIATE.

Implement the sequence using 3 instruction: LOAD AND TEST, BRANCH
RELATIVE ON CONDITION and INSERT IMMEDIATE.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 arch/s390/net/bpf_jit_comp.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index 4b62b5162dfb..39c1d9aa7f1e 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -54,6 +54,7 @@ struct bpf_jit {
 	int prologue_plt_ret;	/* Return address for prologue hotpatch PLT */
 	int prologue_plt;	/* Start of prologue hotpatch PLT */
 	int kern_arena;		/* Pool offset of kernel arena address */
+	u64 user_arena;		/* User arena address */
 };
 
 #define SEEN_MEM	BIT(0)		/* use mem[] for temporary storage */
@@ -863,6 +864,22 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
 		}
 		break;
 	case BPF_ALU64 | BPF_MOV | BPF_X:
+		if (insn_is_cast_user(insn)) {
+			int patch_brc;
+
+			/* ltgr %dst,%src */
+			EMIT4(0xb9020000, dst_reg, src_reg);
+			/* brc 8,0f */
+			patch_brc = jit->prg;
+			EMIT4_PCREL_RIC(0xa7040000, 8, 0);
+			/* iihf %dst,user_arena>>32 */
+			EMIT6_IMM(0xc0080000, dst_reg, jit->user_arena >> 32);
+			/* 0: */
+			if (jit->prg_buf)
+				*(u16 *)(jit->prg_buf + patch_brc + 2) =
+					(jit->prg - patch_brc) >> 1;
+			break;
+		}
 		switch (insn->off) {
 		case 0: /* DST = SRC */
 			/* lgr %dst,%src */
@@ -2076,6 +2093,7 @@ static int bpf_jit_prog(struct bpf_jit *jit, struct bpf_prog *fp,
 	kern_arena = bpf_arena_get_kern_vm_start(fp->aux->arena);
 	if (kern_arena)
 		jit->kern_arena = _EMIT_CONST_U64(kern_arena);
+	jit->user_arena = bpf_arena_get_user_vm_start(fp->aux->arena);
 
 	bpf_jit_prologue(jit, fp, stack_depth);
 	if (bpf_set_addr(jit, 0) < 0)
-- 
2.45.2


  parent reply	other threads:[~2024-06-27  9:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-27  9:07 [PATCH bpf-next 00/10] s390/bpf: Implement arena Ilya Leoshkevich
2024-06-27  9:07 ` [PATCH bpf-next 01/10] s390/bpf: Factor out emitting probe nops Ilya Leoshkevich
2024-06-27  9:07 ` [PATCH bpf-next 02/10] s390/bpf: Get rid of get_probe_mem_regno() Ilya Leoshkevich
2024-06-27  9:07 ` [PATCH bpf-next 03/10] s390/bpf: Introduce pre- and post- probe functions Ilya Leoshkevich
2024-06-27  9:07 ` [PATCH bpf-next 04/10] s390/bpf: Land on the next JITed instruction after exception Ilya Leoshkevich
2024-06-27  9:07 ` [PATCH bpf-next 05/10] s390/bpf: Support BPF_PROBE_MEM32 Ilya Leoshkevich
2024-06-27  9:07 ` Ilya Leoshkevich [this message]
2024-06-27  9:07 ` [PATCH bpf-next 07/10] s390/bpf: Enable arena Ilya Leoshkevich
2024-06-27  9:07 ` [PATCH bpf-next 08/10] s390/bpf: Support arena atomics Ilya Leoshkevich
2024-06-28  0:43   ` Alexei Starovoitov
2024-06-28  9:09     ` Ilya Leoshkevich
2024-06-27  9:07 ` [PATCH bpf-next 09/10] selftests/bpf: Add UAF tests for " Ilya Leoshkevich
2024-06-28  0:45   ` Alexei Starovoitov
2024-06-28  9:13     ` Ilya Leoshkevich
2024-07-03  2:10   ` kernel test robot
2024-06-27  9:07 ` [PATCH bpf-next 10/10] selftests/bpf: Remove arena tests from DENYLIST.s390x Ilya Leoshkevich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240627090900.20017-7-iii@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.