From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Oleg Nesterov <oleg@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] arm64: hw_breakpoint: Save privilege of access control via ptrace
Date: Tue, 18 Jun 2024 15:10:10 +0800 [thread overview]
Message-ID: <20240618071010.11214-1-yangtiezhu@loongson.cn> (raw)
Currently, decode_ctrl_reg() saves the privilege of access control
which is not used anymore, arch_build_bp_info() checks whether bp
virtual address is in kernel space to construct hw->ctrl.privilege,
the process seems not reasonable.
Add a member "bp_priv" in struct perf_event_attr to make a bridge
between ptrace and hardware breakpoint, it can save the privilege
of access control via ptrace for hardware breakpoint.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
This patch is based on 6.10-rc4, cross compile tested only.
This is a try and preparation for later patch on LoongArch.
arch/arm64/kernel/hw_breakpoint.c | 11 ++---------
arch/arm64/kernel/ptrace.c | 2 ++
include/uapi/linux/perf_event.h | 1 +
kernel/events/hw_breakpoint.c | 1 +
4 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
index 722ac45f9f7b..06e34bcdcf92 100644
--- a/arch/arm64/kernel/hw_breakpoint.c
+++ b/arch/arm64/kernel/hw_breakpoint.c
@@ -486,15 +486,8 @@ static int arch_build_bp_info(struct perf_event *bp,
/* Address */
hw->address = attr->bp_addr;
- /*
- * Privilege
- * Note that we disallow combined EL0/EL1 breakpoints because
- * that would complicate the stepping code.
- */
- if (arch_check_bp_in_kernelspace(hw))
- hw->ctrl.privilege = AARCH64_BREAKPOINT_EL1;
- else
- hw->ctrl.privilege = AARCH64_BREAKPOINT_EL0;
+ /* Privilege */
+ hw->ctrl.privilege = attr->bp_priv;
/* Enabled? */
hw->ctrl.enabled = !attr->disabled;
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index 0d022599eb61..3b37c4a2e0d4 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -309,6 +309,7 @@ static struct perf_event *ptrace_hbp_create(unsigned int note_type,
attr.bp_addr = 0;
attr.bp_len = HW_BREAKPOINT_LEN_4;
attr.bp_type = type;
+ attr.bp_priv = AARCH64_BREAKPOINT_EL0;
attr.disabled = 1;
bp = register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL, tsk);
@@ -352,6 +353,7 @@ static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
attr->bp_len = len;
attr->bp_type = type;
attr->bp_addr += offset;
+ attr->bp_priv = ctrl.privilege;
return 0;
}
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 3a64499b0f5d..88dcaba421cc 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -467,6 +467,7 @@ struct perf_event_attr {
__u32 wakeup_watermark; /* bytes before wakeup */
};
+ __u8 bp_priv;
__u32 bp_type;
union {
__u64 bp_addr;
diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index 6c2cb4e4f48d..3ad16b226e4f 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -754,6 +754,7 @@ static void hw_breakpoint_copy_attr(struct perf_event_attr *to,
to->bp_addr = from->bp_addr;
to->bp_type = from->bp_type;
to->bp_len = from->bp_len;
+ to->bp_priv = from->bp_priv;
to->disabled = from->disabled;
}
--
2.42.0
next reply other threads:[~2024-06-18 7:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 7:10 Tiezhu Yang [this message]
2024-06-19 15:15 ` [PATCH] arm64: hw_breakpoint: Save privilege of access control via ptrace Oleg Nesterov
2024-06-20 2:05 ` Tiezhu Yang
2024-06-20 9:08 ` Oleg Nesterov
2024-06-20 9:30 ` Will Deacon
2024-06-20 9:50 ` Tiezhu Yang
2024-06-20 10:36 ` Oleg Nesterov
2024-06-20 11:31 ` James Clark
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=20240618071010.11214-1-yangtiezhu@loongson.cn \
--to=yangtiezhu@loongson.cn \
--cc=acme@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).