From nobody Tue Dec 2 03:00:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7630432E72C; Mon, 17 Nov 2025 12:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763383293; cv=none; b=iyqsFdDZ7NfWQCumdGE4qf6+G4eREpwP5BvllXMTU4v6AnYmEfGv9cR7QtgLQNpeP6RmaLSG6np3oI+LHQ5QkVTl/s+HSUkVa1EEfBP+hbxJKewtSaktxupJhmJet0rAZWlmMfRS2z/3tGfPXiM6JChPsR524Cmoz6dZZ3CH6pI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763383293; c=relaxed/simple; bh=Pc2GqjM7MdxOb7mFpoyfQ0ABTNPxHcevwQvPSUKgUhI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qVl9f7yZuomlBvyvZ/pRPUxxDx9TKxA1DSo3SW16H2PHNjmQqBd8V2ifXK3i9l9XLqXc9j90LiVkR1/gW4DWqZ8FGmu+3relo8RRYwu6qr5c3A55uNdribKbFNMth0cYO8QkCI3rgRq11RSLw/aVsPYxjwE8rv3/aOaz8fauBsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jf8DnQek; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Jf8DnQek" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A681C19421; Mon, 17 Nov 2025 12:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763383293; bh=Pc2GqjM7MdxOb7mFpoyfQ0ABTNPxHcevwQvPSUKgUhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jf8DnQekLT4UaQQcR6aK3MJ7NRj/Z+9HWHxohGmNBZdhK2MYDsL07DeZAOvgl7siM xXJDie+LqfKek7ZKw2Eu9T+gpXS6k5ZASd2kxSp/3IG7HsDjcws5jLg/IwkuzemCgS jp1k1o7uzGbtkiphUBBFLPEm+PKE9P1oHXclzn3gQNSKZN02Tt3kgovfZDMK8M1xCh QYn7ZBDSWS2WYqa0tkgdwDFpe295V8Mgxjt8kXHyTutZtPr36LIgH37PUxv/BdZ1zz io011Y1NvyTDOJl4KN9uPXLa76zWzkddHNDzJ7Z0vAcFg3D+/FNIIQkiOE0/tu6wF6 W4Q8qWHzbwm7w== From: Jiri Olsa To: Oleg Nesterov , Masami Hiramatsu , Peter Zijlstra , Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, x86@kernel.org, Song Liu , Yonghong Song , John Fastabend , Steven Rostedt , Ingo Molnar , David Laight Subject: [RFC PATCH 2/8] uprobe/x86: Use struct arch_uprobe_xol in emulate callback Date: Mon, 17 Nov 2025 13:40:51 +0100 Message-ID: <20251117124057.687384-3-jolsa@kernel.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251117124057.687384-1-jolsa@kernel.org> References: <20251117124057.687384-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Using struct arch_uprobe_xol also in emulate callback which will help in following changes. Signed-off-by: Jiri Olsa --- arch/x86/kernel/uprobes.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c index fb9457b29dbc..7d7a5e677472 100644 --- a/arch/x86/kernel/uprobes.c +++ b/arch/x86/kernel/uprobes.c @@ -1212,7 +1212,7 @@ static bool can_optimize(struct insn *insn, unsigned = long vaddr) #endif /* CONFIG_X86_64 */ =20 struct uprobe_xol_ops { - bool (*emulate)(struct arch_uprobe *, struct pt_regs *); + bool (*emulate)(struct arch_uprobe*, struct arch_uprobe_xol *, struct pt_= regs *); int (*pre_xol)(struct arch_uprobe *, struct pt_regs *); int (*post_xol)(struct arch_uprobe *, struct pt_regs *); void (*abort)(struct arch_uprobe *, struct pt_regs *); @@ -1291,9 +1291,9 @@ static const struct uprobe_xol_ops default_xol_ops = =3D { .abort =3D default_abort_op, }; =20 -static bool branch_is_call(struct arch_uprobe *auprobe) +static bool branch_is_call(struct arch_uprobe_xol *xol) { - return auprobe->xol.branch.opc1 =3D=3D 0xe8; + return xol->branch.opc1 =3D=3D 0xe8; } =20 #define CASE_COND \ @@ -1325,11 +1325,11 @@ static bool is_cond_jmp_opcode(u8 opcode) } } =20 -static bool check_jmp_cond(struct arch_uprobe *auprobe, struct pt_regs *re= gs) +static bool check_jmp_cond(struct arch_uprobe_xol *xol, struct pt_regs *re= gs) { unsigned long flags =3D regs->flags; =20 - switch (auprobe->xol.branch.opc1) { + switch (xol->branch.opc1) { #define DO(expr) \ return expr; CASE_COND @@ -1344,12 +1344,13 @@ static bool check_jmp_cond(struct arch_uprobe *aupr= obe, struct pt_regs *regs) #undef COND #undef CASE_COND =20 -static bool branch_emulate_op(struct arch_uprobe *auprobe, struct pt_regs = *regs) +static bool branch_emulate_op(struct arch_uprobe *auprobe, struct arch_upr= obe_xol *xol, + struct pt_regs *regs) { - unsigned long new_ip =3D regs->ip +=3D auprobe->xol.branch.ilen; - unsigned long offs =3D (long)auprobe->xol.branch.offs; + unsigned long new_ip =3D regs->ip +=3D xol->branch.ilen; + unsigned long offs =3D (long)xol->branch.offs; =20 - if (branch_is_call(auprobe)) { + if (branch_is_call(xol)) { /* * If it fails we execute this (mangled, see the comment in * branch_clear_offset) insn out-of-line. In the likely case @@ -1361,7 +1362,7 @@ static bool branch_emulate_op(struct arch_uprobe *aup= robe, struct pt_regs *regs) */ if (emulate_push_stack(regs, new_ip)) return false; - } else if (!check_jmp_cond(auprobe, regs)) { + } else if (!check_jmp_cond(xol, regs)) { offs =3D 0; } =20 @@ -1369,19 +1370,20 @@ static bool branch_emulate_op(struct arch_uprobe *a= uprobe, struct pt_regs *regs) return true; } =20 -static bool push_emulate_op(struct arch_uprobe *auprobe, struct pt_regs *r= egs) +static bool push_emulate_op(struct arch_uprobe *auprobe, struct arch_uprob= e_xol *xol, + struct pt_regs *regs) { - unsigned long *src_ptr =3D (void *)regs + auprobe->xol.push.reg_offset; + unsigned long *src_ptr =3D (void *)regs + xol->push.reg_offset; =20 if (emulate_push_stack(regs, *src_ptr)) return false; - regs->ip +=3D auprobe->xol.push.ilen; + regs->ip +=3D xol->push.ilen; return true; } =20 static int branch_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs = *regs) { - BUG_ON(!branch_is_call(auprobe)); + BUG_ON(!branch_is_call(&auprobe->xol)); /* * We can only get here if branch_emulate_op() failed to push the ret * address _and_ another thread expanded our stack before the (mangled) @@ -1767,7 +1769,7 @@ void arch_uprobe_abort_xol(struct arch_uprobe *auprob= e, struct pt_regs *regs) static bool __skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs) { if (auprobe->xol.ops->emulate) - return auprobe->xol.ops->emulate(auprobe, regs); + return auprobe->xol.ops->emulate(auprobe, &auprobe->xol, regs); return false; } =20 --=20 2.51.1