From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9D732877E8 for ; Mon, 10 Nov 2025 16:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762792618; cv=none; b=lCvIxodmKNs1oGxFzVgy+uqOShUAMFBrUjzg2PNg+BbG8tyboAYwD+gypcYvAXdbLcbsQJVAhjJwnuJN+lqJZ3hYeP7Qp214aLM3LPx0pAhwyK9sZgmZtnoa9Dsq+f7knECmjc1lbwBUvVsw+dhTcNIAWW+lCnLbxOEQXGxocQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762792618; c=relaxed/simple; bh=IHekeM/5ALv1Tfapztub9UTNCtQ4Mse7xBlGJh7bRJo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OGmHeG8douNiakqiQfjEiCGlsRfBoTMUJryxjstiaP5z+aftC0ZlkVtXGsqQzGqwJwp2cokKhCA4AagpFhGzesUcGmPypATcYBOCqbj9Xzt61NpO8fbUCRREkVp2XcLkro6V7lY8ClNP6Kv5FZRB3bOBgkQfkNNu723Bi95TEbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JaCqKiOF; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JaCqKiOF" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3436d6bdce8so2601339a91.3 for ; Mon, 10 Nov 2025 08:36:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762792614; x=1763397414; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Rf1O2IW8PmKXDZ3O4r/3b4myYk+kPZmKXtIohIyK/BM=; b=JaCqKiOFrWy+xOepjfLS114Dvaz8VstN+xd+a3q+IQMMk9W1p0eyuCxnQ5Tw3eQ2gJ 8Q1B6ur+VQqm6nvdUne+Orl+Q1GKA1FnNboC1eTpYCWoZuw0NGrqPCynrkMd82wDiSct QHagPTM619M6xS/VgEfAcwm7QQQsmJtEPfelJUq4PQgI1i+DfLWGfnb1HSn5JD94qvg+ KOCJWUuZ1/MB6W4FBtAwjF64pLGdNdTGcjP3fOa/uHiIgO5ak9AZCYyPILhgud/msuWg QTQFNsEJEZPVnpm0Z4+e2PM940x5gcGH7n2QG6muwxNSHtREAcuEBtu4ceoGmQ8ytOCJ zrmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762792614; x=1763397414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Rf1O2IW8PmKXDZ3O4r/3b4myYk+kPZmKXtIohIyK/BM=; b=Y9wKDj7CE8VFQOIyGiQKG7VI5+KnEIpMwwORAK7ld8t0ztDmjB9ExNA+AZQWqrtxxG kq9cuY4weRn72L/ubzJK/KK6A/ZztS/T7oTaXhjF7qGqHw1XQo/6droTw0AOE/1OaBNZ VffdlFvfoC7sBoKTN2lWVa5oG88+Wl1+Tqlsdte3JIgwMiScj/2OP34+7wSTGO5za4zg LajxiLpGCeIq/jIHWZ+pSKTVS3qHwn9gs2QYAKI9XnXo7ExAzkPo8beTHR4qEMFuqcI3 XY99hKGzjkeWRCUoP8Jf2W12AWlvIEEOgwQJVrB0jxvu9CpoRL+xDbkHI3Wq7+TQEqZZ V5bg== X-Forwarded-Encrypted: i=1; AJvYcCU52WhoXYKZVuduBebmrCwXqjTFADN4zYYnS0Vq+F1itcn4OaYa8yj5EYodlr2UYl+64poT@lists.linux.dev X-Gm-Message-State: AOJu0Yyy/dWTiOpWIx7vm0yDj+VbF7w8dU07/7NWRRmVm8sYNCIhyUor H2mNsoq3pHZAYG6DHM8g7/JDRtFIFRGYi3YCEDnHrcvzpGmwsk+6YdZv X-Gm-Gg: ASbGncsfS+Re0VOBv8qTMocX/IQL4HOhceB+2Mzj1QK8EJTis3JTNItxHv1uX7bTo5A loXOlmY4RNjtLLHA5VtMU94EeNHOeMnOKLGLtbMBPpiTeosrrDYhNAcJQ+JR4F3/cswtqsjMy9+ 4q2FJEAw5kvw90xQSeZT6md4kWg1LoZlVSXMUnu5aWAKfbiOm2H2ykuKQxbqz1jLWL18/qsrQwC SPV8drkHu3Zxoddg9CaJJMvgZhQNZyRydcRB51tRmhbGPn0SFF8jmKng+DaZ3WQu5nI1UZWtn6z qn5MbrVqki/HSXcBFWHTzEypzq0aP4cgRTeKAn2v1SDOb5pXLMRQan3s66Rgqrwj615WI9KmAYW gunL02fLg3fhDWe9zEe8VLm5ndS/0bQDLfKeyd/0D9DMCNl+6KbIH9qHq+Zt3e5hBhenvRhtiWA DH8mmYXdjbMkQ= X-Google-Smtp-Source: AGHT+IF/jQs1f7B6cG5SH+bBA2T5zaJBaOf+IxgFwWIZkh8f5KWpsuxpiPdi/QInw6w6XvvtLJa9gQ== X-Received: by 2002:a17:90a:bf06:b0:343:a631:28b1 with SMTP id 98e67ed59e1d1-343a6312b7emr3517293a91.16.1762792613858; Mon, 10 Nov 2025 08:36:53 -0800 (PST) Received: from localhost ([103.88.46.62]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-341d0adc41dsm5956374a91.1.2025.11.10.08.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 08:36:53 -0800 (PST) From: Jinchao Wang To: Andrew Morton , "Masami Hiramatsu (Google)" , Peter Zijlstra , Randy Dunlap , Marco Elver , Mike Rapoport , Alexander Potapenko , Adrian Hunter , Alexander Shishkin , Alice Ryhl , Andrey Konovalov , Andrey Ryabinin , Andrii Nakryiko , Ard Biesheuvel , Arnaldo Carvalho de Melo , Ben Segall , Bill Wendling , Borislav Petkov , Catalin Marinas , Dave Hansen , David Hildenbrand , David Kaplan , "David S. Miller" , Dietmar Eggemann , Dmitry Vyukov , "H. Peter Anvin" , Ian Rogers , Ingo Molnar , James Clark , Jinchao Wang , Jinjie Ruan , Jiri Olsa , Jonathan Corbet , Juri Lelli , Justin Stitt , kasan-dev@googlegroups.com, Kees Cook , "Liam R. Howlett" , "Liang Kan" , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, llvm@lists.linux.dev, Lorenzo Stoakes , Mark Rutland , Masahiro Yamada , Mathieu Desnoyers , Mel Gorman , Michal Hocko , Miguel Ojeda , Nam Cao , Namhyung Kim , Nathan Chancellor , Naveen N Rao , Nick Desaulniers , Rong Xu , Sami Tolvanen , Steven Rostedt , Suren Baghdasaryan , Thomas Gleixner , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Valentin Schneider , Vincent Guittot , Vincenzo Frascino , Vlastimil Babka , Will Deacon , workflows@vger.kernel.org, x86@kernel.org Subject: [PATCH v8 03/27] HWBP: Add modify_wide_hw_breakpoint_local() API Date: Tue, 11 Nov 2025 00:35:58 +0800 Message-ID: <20251110163634.3686676-4-wangjinchao600@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251110163634.3686676-1-wangjinchao600@gmail.com> References: <20251110163634.3686676-1-wangjinchao600@gmail.com> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Masami Hiramatsu (Google)" Add modify_wide_hw_breakpoint_local() arch-wide interface which allows hwbp users to update watch address on-line. This is available if the arch supports CONFIG_HAVE_REINSTALL_HW_BREAKPOINT. Note that this allows to change the type only for compatible types, because it does not release and reserve the hwbp slot based on type. For instance, you can not change HW_BREAKPOINT_W to HW_BREAKPOINT_X. Signed-off-by: Masami Hiramatsu (Google) --- arch/Kconfig | 10 ++++++++++ arch/x86/Kconfig | 1 + include/linux/hw_breakpoint.h | 6 ++++++ kernel/events/hw_breakpoint.c | 37 +++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 61130b88964b..c45fe5366125 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -456,6 +456,16 @@ config HAVE_MIXED_BREAKPOINTS_REGS Select this option if your arch implements breakpoints under the latter fashion. +config HAVE_REINSTALL_HW_BREAKPOINT + bool + depends on HAVE_HW_BREAKPOINT + help + Depending on the arch implementation of hardware breakpoints, + some of them are able to update the breakpoint configuration + without release and reserve the hardware breakpoint register. + What configuration is able to update depends on hardware and + software implementation. + config HAVE_USER_RETURN_NOTIFIER bool diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index fa3b616af03a..4d2ef8a45681 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -245,6 +245,7 @@ config X86 select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS select HAVE_HW_BREAKPOINT + select HAVE_REINSTALL_HW_BREAKPOINT select HAVE_IOREMAP_PROT select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64 select HAVE_IRQ_TIME_ACCOUNTING diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h index db199d653dd1..ea373f2587f8 100644 --- a/include/linux/hw_breakpoint.h +++ b/include/linux/hw_breakpoint.h @@ -81,6 +81,9 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr, perf_overflow_handler_t triggered, void *context); +extern int modify_wide_hw_breakpoint_local(struct perf_event *bp, + struct perf_event_attr *attr); + extern int register_perf_hw_breakpoint(struct perf_event *bp); extern void unregister_hw_breakpoint(struct perf_event *bp); extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events); @@ -124,6 +127,9 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr, perf_overflow_handler_t triggered, void *context) { return NULL; } static inline int +modify_wide_hw_breakpoint_local(struct perf_event *bp, + struct perf_event_attr *attr) { return -ENOSYS; } +static inline int register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } static inline void unregister_hw_breakpoint(struct perf_event *bp) { } static inline void diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c index 8ec2cb688903..5ee1522a99c9 100644 --- a/kernel/events/hw_breakpoint.c +++ b/kernel/events/hw_breakpoint.c @@ -887,6 +887,43 @@ void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) } EXPORT_SYMBOL_GPL(unregister_wide_hw_breakpoint); +/** + * modify_wide_hw_breakpoint_local - update breakpoint config for local CPU + * @bp: the hwbp perf event for this CPU + * @attr: the new attribute for @bp + * + * This does not release and reserve the slot of a HWBP; it just reuses the + * current slot on local CPU. So the users must update the other CPUs by + * themselves. + * Also, since this does not release/reserve the slot, this can not change the + * type to incompatible type of the HWBP. + * Return err if attr is invalid or the CPU fails to update debug register + * for new @attr. + */ +#ifdef CONFIG_HAVE_REINSTALL_HW_BREAKPOINT +int modify_wide_hw_breakpoint_local(struct perf_event *bp, + struct perf_event_attr *attr) +{ + int ret; + + if (find_slot_idx(bp->attr.bp_type) != find_slot_idx(attr->bp_type)) + return -EINVAL; + + ret = hw_breakpoint_arch_parse(bp, attr, counter_arch_bp(bp)); + if (ret) + return ret; + + return arch_reinstall_hw_breakpoint(bp); +} +#else +int modify_wide_hw_breakpoint_local(struct perf_event *bp, + struct perf_event_attr *attr) +{ + return -EOPNOTSUPP; +} +#endif +EXPORT_SYMBOL_GPL(modify_wide_hw_breakpoint_local); + /** * hw_breakpoint_is_used - check if breakpoints are currently used * -- 2.43.0