]> git.baikalelectronics.ru Git - kernel.git/commitdiff
x86/hw_breakpoint: Add within_area() to check data breakpoints
authorLai Jiangshan <laijs@linux.alibaba.com>
Fri, 29 May 2020 21:27:29 +0000 (23:27 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 11 Jun 2020 13:15:20 +0000 (15:15 +0200)
Add a within_area() helper to checking whether the data breakpoints overlap
with cpu_entry_area.

It will be used to completely prevent data breakpoints on GDT, IDT, or TSS.

Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200526014221.2119-2-laijs@linux.alibaba.com
Link: https://lkml.kernel.org/r/20200529213320.784524504@infradead.org
arch/x86/kernel/hw_breakpoint.c

index 9ddf441ccaa87d603a0df7312e19d09e72add16d..c149c7b29ac318143d9341d4daee85509be0a8e1 100644 (file)
@@ -227,14 +227,23 @@ int arch_check_bp_in_kernelspace(struct arch_hw_breakpoint *hw)
        return (va >= TASK_SIZE_MAX) || ((va + len - 1) >= TASK_SIZE_MAX);
 }
 
+/*
+ * 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,