From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 E58FC22172E for ; Tue, 30 Sep 2025 02:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759200273; cv=none; b=LPpjmCIMGc1NPbrF+3/Mh6uEbjaSejN9b0ByGsbAc3pKoXhEy8/r41IISRXmYV6j3ZjrqJrqn4SdE3OFlOTOOtEirDyx0ryeiyQrslyxb14EJJuak1wlv/lAfZomrZY7OBoSg4GLzVIAWgjN5Es641lYNuSJLLBnIIP1B2VgHZo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759200273; c=relaxed/simple; bh=JuRa9sqqB7Pb4oITEW69e6hBS72ry7/vRFUMRsXtE7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ue/KQ77xatjkx4qMnN31+wvtK1ZJx4zHT9fjNwf/c5MH5OSyO0JRf2ouTXqS2eIiJZImlaLCRxCRiMosSdSPk81yDh6IOr5YKnpho0ARpP7v84D31P7jEzFoXGsw8vn1W/nuT8Zvox3MPIcfiAgfNsdgWZ/HaM5LeMeKNt/buJU= 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=Q+8qOqdV; arc=none smtp.client-ip=209.85.210.179 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="Q+8qOqdV" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-781db5068b8so2293872b3a.0 for ; Mon, 29 Sep 2025 19:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759200271; x=1759805071; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l9dguoBkY6LX1N0DOj75LxFoPgkZue82QF3pLTyVov0=; b=Q+8qOqdV8AC4EQF3pP1aEytZWBxcE+sT4TiDkAmgezYuUXMrYfB58/5+yjLPSgm1bK CfGgqFvNF90biaJHP2QdoaCC3rOh6k2XJnWWSeaC8SVaK0YxmeSYbQX06CCVl1WNjp77 KPu8ZvzColFxgOU/4yOqWBW7v6k68Ir34oMbo8NMPcyvZB2RMlmoXFuRVLNZqBsWjUDe 2/wRiPTxiHmwFQxi+E2c5GeUWbHFR3UMmjPIzZy7u67lHSiUUl7OAmAR5qytFo3Tguou hYhRxCYPtrB1Z51N1vlagWRaVNu9iOasEWJi00qQN3hdc52C9MCHP6vwi2J3dIKgg5Dr McSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759200271; x=1759805071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l9dguoBkY6LX1N0DOj75LxFoPgkZue82QF3pLTyVov0=; b=F5eaBlugoo9rFRMTssQQSBRtwfbcLx6eTzO2MINxtI1mwKM7//oEJ2TD4th8lcU4Ju zqyep+OQJnM8+yrGj997MHlFKDtEThITuMdtVMbbqVWQo8nEZJfgTLnJOD7OYT3JxVRs ScZoelT67/OLEHjfU1Ujquz2+65+BwPrakkzhmjQHgtzFsIogBgSmXY1FzIN0q/PIhBr qPRjuU6kpdd9aXuRfFQh3UpEsETAvbEiyzpAzE0XcyzFen33m+zBvTSDb3zpQNJfPjlF /l++8Wp3gV8lTdKQoGkbJcub8VvZ1e3gLXLxNXD9otVEMSAqnXMIbKlUY0fjiTDeufP7 QvbA== X-Forwarded-Encrypted: i=1; AJvYcCXfBIiUmRPujD+wEi48HqZGQkUUgJ1VFFtZrCxnnmFjsJVqqApjVTZqIAP3E4mbEWkiF+9L@lists.linux.dev X-Gm-Message-State: AOJu0YxWsul8QMq9yeJPBkdcGKJDcSNDz0DcsXl4IUYMchKcLl7T+NpP AEuaHT8VZyzKDlCg0FdXPZSiFHkXd82z3PI45NyH+kLQyspfOjncgcIX X-Gm-Gg: ASbGncst90cOvy873dLbnyH2/PtpIpN51j8z+Jr/To+ljcGdRI6dUD0Sw5lLMQQjyFp dKrdRKRc00rE2WFhAd4TXKQ8Qf2mEf7AXFUPmpi66clGo5XPdZ1mFuizjzk6W4hJIL7BnziC2Qv 4z0m4E/6eTSev9HForaL1xYWvp002EHiYvsciXhtNJfdDdF/s3uCMF56xYZR9kdE1kPhioa7iEx cG3AWyQKk8FLy1wxLISiSb6MzwbUZGb/Zk3S3zp80rjhrRWkTzy9VQtEUQjpEZOlqbGFeggL07a R2UbV+42lLSntyV+4DfsYtt0Oxccw9UKKoP4IBNUxwWe2JTFT4GHMC7nO49vWf34Owe32dCixsB TsllmivsllWDgfZ+jUW+8/in2yUs/RMKQyQctjW1FtW6nG0HHl0yMGDKrcwIGF8+axu/agVYELc w7AqV6yToe9bg= X-Google-Smtp-Source: AGHT+IHjrrKfxlAjB9vjrTGyvJK813tH9TeLe0y5kgR3cpWBZ7wuSWlGxxuhJbW7A37WSlnCeWMzQw== X-Received: by 2002:a17:902:f543:b0:24c:b39f:baaa with SMTP id d9443c01a7336-27ed4a98ae9mr223248625ad.49.1759200270921; Mon, 29 Sep 2025 19:44:30 -0700 (PDT) Received: from localhost ([45.142.167.196]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-27ed69bf9bdsm145712165ad.127.2025.09.29.19.44.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Sep 2025 19:44:30 -0700 (PDT) From: Jinchao Wang To: Andrew Morton , Masami Hiramatsu , Peter Zijlstra , Mike Rapoport , Alexander Potapenko , Randy Dunlap , Marco Elver , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Kees Cook , Alice Ryhl , Sami Tolvanen , Miguel Ojeda , Masahiro Yamada , Rong Xu , Naveen N Rao , David Kaplan , Andrii Nakryiko , Jinjie Ruan , Nam Cao , workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev, Andrey Ryabinin , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com, "David S. Miller" , Mathieu Desnoyers , linux-trace-kernel@vger.kernel.org Cc: Jinchao Wang Subject: [PATCH v6 03/23] HWBP: Add modify_wide_hw_breakpoint_local() API Date: Tue, 30 Sep 2025 10:43:24 +0800 Message-ID: <20250930024402.1043776-4-wangjinchao600@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250930024402.1043776-1-wangjinchao600@gmail.com> References: <20250930024402.1043776-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 d1b4ffd6e085..e4787fc814df 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -418,6 +418,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 52c8910ba2ef..4ea313ef3e82 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -247,6 +247,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