From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) (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 83B79381EA1 for ; Sun, 26 Jul 2026 12:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785068600; cv=none; b=ChX9dqMdMScSEPNRFOjq/8nu2vhzWdDYm5vj7NyetxWY6KEBaJojBoptpfmjXLh1r0P2Q/uaCbhVsXdAgQFIwfKHIPA06VxYOuLhuC34u5Gh1H6HIwZzMf6JyLkjMn9Mp3fuXnihGzcXUAjqkgHc7HrKKMZZYKWpFCtuBs5vWJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785068600; c=relaxed/simple; bh=9TRu9Q4LwBRql71odhvuw1OhgUcZ5BnFekHOedMS968=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YqXagKEeMRJydo2uSYEibFUEgWgSZApCb3w1SnSFXc4EFophruk4q5yGmvPAVb2vyDE4nwx0wGvhR450ToiQTayibkQkCq1W7qskvCYT36E2qKkd7FFyfUFDAkkQhri7RWQGk9KIEygEfIlf8WQiVphfMBPk8djEqDjhmvj799g= 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=HUUlswz7; arc=none smtp.client-ip=209.85.160.53 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="HUUlswz7" Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-43b7e186a0cso719553fac.0 for ; Sun, 26 Jul 2026 05:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785068597; x=1785673397; darn=vger.kernel.org; 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:content-type; bh=uVtWee8zloihupxojDwrCEq5aoRBKaK6smjn2VfvwR4=; b=HUUlswz7It/qUg9RMzY3/dsC87Hq++LN4erbo3UcENowdxckqGLJHhX1nB6BQkl9da gLHScj1wRZHAYu7uYnrA2nUV6/wOPSHZQPfCv6PKLMir4mEKXhU9ePJEIZ1cqESICz41 eefzNdPRMu2+joii2pXpDRSe4SemT+5YG67FWXVwCF0ojmH8O5f4rVo2x2R3xXfLqgqM QyhxBuAhmfhRJtv8y9Pi/QN+vY4qFczn+iUC51h47OXk4hsSMbOL4zt3rmkWRW/HtqBr f5qJsimx4+zIo7+YK4ZzyQ/fIrSTcrGq4LwCFLL7dxQDRuaI7dPdLbQy8qq7vUUrSwMR g1tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785068597; x=1785673397; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=uVtWee8zloihupxojDwrCEq5aoRBKaK6smjn2VfvwR4=; b=CzTqz84aoG8cTwUKR5Naouz8sDdl9HeG/AH+CWUAV7PyUGiAQaGUN98AGlxM9tpM2f kyjea5Ljgf+tHyt+WsN/nJdAxYtdW3J00ckylqlB131G/WvKkbH3ueyGw9m50B4bSFNM eWX88Ot62kIO0fbg9GvDqedFQ/RkweGWkYfD84iMCqp1R4bNpRtKqYVyNIPb18cTjLqU EriciLXpZMxfjsSuKnOeiniKOuSHsOfjWDj6ezJuROuZeZ22856c90Q0N5jer4CxTYSv TuUC0jGmqocfCF5PBKxy9cpy8IrtHBlCcXF0q+MadzIb0iNIDj5Lh9jSK0iOn+j/Rmkb VBHg== X-Forwarded-Encrypted: i=1; AHgh+Rq3XtfjTt7KKVJrWOhCVqle5nROQfg4tqUB/UG/1jLkKky/GvZ/81UlW+bJ9cckaqUHdNuu3FsG2NbFwsY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+7MXymakwpYo8dahUWKgE2ufW9c1giLGCRRYN5Pshp+qXaOoo yvXjz38RTDyhhQOZ7l327SaBmzBzcZQdcVPWJ3FB8yjRgJZlHUK/IGxO X-Gm-Gg: AR+sD12Nwz+ZF5XUMMIvDqvaquFSna4/4uvnX18cgjiA2WWiXUzK4ZeRN4OGwmoCX4g MrvfdV9x3JipMwxJtUNnrmUK5VCBwNk4cSeaBJlRZ/K5S/Xwbd+a+1spD7ScEdMKNwC+644dFep 9s9RVLuNBcGsExUKXsn0svQxANyOkQB62m2s53Ox2OvVt8Bp26JSYPdUbMHhmw7agM0v2vCEgE7 q0Uc6sJJX6IB41XJa8U2CGoTqX7cnR3z7h2sDLASwd7jiFsEJFIPx7FkGuvzt4nVD09nrzi4NBO O+R5IXCqMcexvmerqLJR7PTOqzx34zyNgOw2/WRO4Kh5pSL18ukJFxjNxAk+cbpFXdE6niWM3Aj yW0MM5+kyjkN6DGwvdoE7H+XOZV6el+OuXmu+R+vfFIjE2xvY33A04QYwnDWLV5QoD5tSYUrpJT Y6sHpdwn1Zt5Yn X-Received: by 2002:a05:6820:1a05:b0:6a3:1dc5:356e with SMTP id 006d021491bc7-6aaffa6232fmr3807138eaf.36.1785068597387; Sun, 26 Jul 2026 05:23:17 -0700 (PDT) Received: from localhost ([144.24.58.22]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-457673d267dsm13112356fac.11.2026.07.26.05.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2026 05:23:17 -0700 (PDT) From: Jinchao Wang To: Masami Hiramatsu , Peter Zijlstra , Thomas Gleixner , Steven Rostedt , x86@kernel.org Cc: Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Mathieu Desnoyers , Tony Luck , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-edac@vger.kernel.org, Jinchao Wang Subject: [PATCH 2/3] x86/hw_breakpoints: Add arch_modify_local_hw_breakpoint_addr() API Date: Sun, 26 Jul 2026 20:22:31 +0800 Message-ID: <59637b96946653393a7ad3c7de094094796b39c2.1785067572.git.wangjinchao600@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: <178476143000.26117.9810509272687580410.stgit@devnote2> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Wprobe needs to move an active per-CPU watchpoint without releasing and reserving its hardware slot. Add arch_modify_local_hw_breakpoint_addr() to find the installed local slot and update only its address shadow and hardware debug address register. Publish the shadow first so hw_breakpoint_restore() observes the new address if an NMI interrupts the update. The caller must provide an installed local event and a valid address. Slot ownership, breakpoint type, length, mask and DR7 remain unchanged. Signed-off-by: Jinchao Wang --- arch/x86/include/asm/hw_breakpoint.h | 2 ++ arch/x86/kernel/hw_breakpoint.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/x86/include/asm/hw_breakpoint.h b/arch/x86/include/asm/hw_breakpoint.h index 0bc931cd0698..a1ecce536074 100644 --- a/arch/x86/include/asm/hw_breakpoint.h +++ b/arch/x86/include/asm/hw_breakpoint.h @@ -59,6 +59,8 @@ extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused, int arch_install_hw_breakpoint(struct perf_event *bp); +void arch_modify_local_hw_breakpoint_addr(struct perf_event *bp, + unsigned long addr); void arch_uninstall_hw_breakpoint(struct perf_event *bp); void hw_breakpoint_pmu_read(struct perf_event *bp); void hw_breakpoint_pmu_unthrottle(struct perf_event *bp); diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c index 9ef24b55737f..ff1b9b78f78c 100644 --- a/arch/x86/kernel/hw_breakpoint.c +++ b/arch/x86/kernel/hw_breakpoint.c @@ -128,6 +128,26 @@ int arch_install_hw_breakpoint(struct perf_event *bp) return 0; } +void arch_modify_local_hw_breakpoint_addr(struct perf_event *bp, + unsigned long addr) +{ + int i; + + lockdep_assert_irqs_disabled(); + + for (i = 0; i < HBP_NUM; i++) { + if (this_cpu_read(bp_per_reg[i]) == bp) + break; + } + + if (WARN_ONCE(i == HBP_NUM, "Can't find any breakpoint slot")) + return; + + this_cpu_write(cpu_debugreg[i], addr); + barrier(); + set_debugreg(addr, i); +} + /* * Uninstall the breakpoint contained in the given counter. * -- 2.53.0