[PATCH 01/14] x86/hw_breakpoint: Add within_area() to check data breakpoints

From: Peter Zijlstra
Date: Fri May 29 2020 - 17:35:05 EST


From: Lai Jiangshan <laijs@xxxxxxxxxxxxxxxxx>

within_area() is added for checking if the data breakpoints overlap
with cpu_entry_area, and will be used for checking if the data
breakpoints overlap with GDT, IDT, or TSS in places other than
cpu_entry_area next patches.

Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Link: https://lkml.kernel.org/r/20200526014221.2119-2-laijs@xxxxxxxxxxxxxxxxx
---
arch/x86/kernel/hw_breakpoint.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

--- a/arch/x86/kernel/hw_breakpoint.c
+++ b/arch/x86/kernel/hw_breakpoint.c
@@ -228,13 +228,22 @@ int arch_check_bp_in_kernelspace(struct
}

/*
+ * Checks whether the range [addr, end], overlaps the area [base, base + size).
+ */
+static inline bool within_area(unsigned long addr, unsigned long end,
+ unsigned long base, unsigned long size)
+{
+ return end >= base && addr < (base + size);
+}
+
+/*
* Checks whether the range from addr to end, inclusive, overlaps the CPU
* entry area range.
*/
static inline bool within_cpu_entry_area(unsigned long addr, unsigned long end)
{
- return end >= CPU_ENTRY_AREA_BASE &&
- addr < (CPU_ENTRY_AREA_BASE + CPU_ENTRY_AREA_TOTAL_SIZE);
+ return within_area(addr, end, CPU_ENTRY_AREA_BASE,
+ CPU_ENTRY_AREA_TOTAL_SIZE);
}

static int arch_build_bp_info(struct perf_event *bp,