From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.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 B15C7352927 for ; Thu, 19 Mar 2026 10:36:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773916595; cv=none; b=m1Apt/mNtu6kPq0I6qk2Xj2Kio4paVfKpITnGBN7QQwbxHvreLahNJgdV4zPJfuG6b7Mwg3QJ8SwpeLnkv2pI8Q+nC2aoy2Y87Lad05IT7LS0CDH4aZ2osPgRL/Y5L0mtnsvPKj539F1cdp1MZWWLYIR5V1L4Sl8lQOawx/15OM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773916595; c=relaxed/simple; bh=wB2b0s+ktvfwLnTnUkSpwabGq0SltXGWA5XrWxYfvLc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=c2zaywtq2UY9gee7IFAafwBbQEuOhOxDUlmU4iFjuq5npOUcW8E+Ky6dJ9xnNHV8dm67zE3WduNy1NMO/PIIDXJmta3qezlnCZl5TfrMiHOpc1T4WmxSu7D/RguuHXpNCtqH4ov3X8u2kuTwpeOMB8K8jnCxfPMbw0QalZAM/rc= 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=GIOkzKAF; arc=none smtp.client-ip=209.85.167.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="GIOkzKAF" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-59de8155501so757289e87.3 for ; Thu, 19 Mar 2026 03:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773916592; x=1774521392; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=tvZnxNdQMkwiTW3tDu7XCVsslkr30HbaMvbGALgZS0Q=; b=GIOkzKAFxFnlA8xSK0BJu85AJeN/txjhOXumtD4RNgaWUP+Wp01RObLnOXWgZ4z4pt xt0ohI090hYuMtTtyi4h6mejauDnhELgURxM+1QOBcLDImj7xw6zqmwQeqkeMDe7s+Pj Mm+2FMye1q2SJv+DpH7L0cMGhSm51mD1MkUvwkl4YMcru3OHp4b4gsMxbtHvgmJTur1f r+b55kJVN3EWSY4RWBZ5W6PpMI/chMLuihFxjar4sz1bdX6cNbYo928YWNFx6sSoN9By uXavRHpXXFINcR0ed4a+CmHUhK6epeEF14JysDqRz35JVEaGOov8tlwwRroRpDG0ET5I msoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773916592; x=1774521392; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tvZnxNdQMkwiTW3tDu7XCVsslkr30HbaMvbGALgZS0Q=; b=pkazjPpqF/WIW2BeLCt966NFgBgpLfPXulmxgz2UJWuq2H2Xp5Qfd/KXik1hQbMzvw gV9n5w+0gkn5P+gQozpBRbTlmseaUHL9eUx+vyTQELM2NmoLwDn6iKrkK9+bhagGeVaU cG6RsY64lSNj5MSaRed2eqRvTO2QdlPIgrQFPXzjetmoleKy9clweLFhsEVa6BXdJdk/ YslNVyFKoc+3FNU0xNmLtcPVhnqO0km3zThsEg6ClFSUYY+gnur/CbMXLzn0AQTPRSDF hGrFWfz4plka21xZbjBVi+P+dLNgaTLdyol0WQZA55QcNF0giLS/y3hOrzUFCZUAJoK5 AwQQ== X-Forwarded-Encrypted: i=1; AJvYcCXe4XuLr1k79LzLVnIlbc7ITtYdcaWu0eUQBGj8U6vigZjgDGzYt1NmJ0TI8Pi/7kbO4OHTdb87CVMsy8I=@vger.kernel.org X-Gm-Message-State: AOJu0Yx36nsfc714amDgdTEfXEipysqodiGfYrKFbuRDv1yW/dzA1H05 hAP1AUWUnCsA0nz1VtkUzdiQxTKInu7BkuyhTmqPosHoZybgW8C0et0j X-Gm-Gg: ATEYQzy3Kko8UNBodme3X/aUSpJW3395jIgLu/SD38TPHwk9fBvkKUHO+bBFtLqzdww nNRadAVtmvI/+uMQM19riXZGS3VY+4yqlky8PM4FdmcotE7VQtwLfVnW80VFNkgv9vFUZtZN8Xd +hey/ttdM4v5LGxyBzNTBlDyuA0teuuw+6YUrOYNPmp3QQByro67mXfRAYCBsFf5z5xcF1Xzm0r 9cKvdefbRwaqt46STAfdq6h8GwkxpUZttFYRLoQN9IyicLMR6itaQS2cYz4Z5A/3uDSgHIr1DhT 3D3RtsY6cspyLHZgToXSYbFC1hhQf/A8y2Ro8iFCsWC8FAj+ZfAIOOTzvcUDURztoUxnHml5Egi GaVkiCU7jmliMKMd6WwlRal4p5SPAIMhk/w+RvbNSw5qYybnRkb9gyNTDWSuPNkYBpHUHKN4WSe nJdjsr+UCZU4z/6cVkcQNw3Yz8rGUcrphrl+Bfj8c= X-Received: by 2002:a05:6512:1193:b0:5a2:7c1c:749 with SMTP id 2adb3069b0e04-5a27c1c088fmr2333426e87.39.1773916591523; Thu, 19 Mar 2026 03:36:31 -0700 (PDT) Received: from imamay-pc ([46.73.133.192]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a279c27575sm1120034e87.17.2026.03.19.03.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 03:36:31 -0700 (PDT) Date: Thu, 19 Mar 2026 13:36:29 +0300 From: Ilya Mamay To: Himanshu Chauhan Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, shuah@kernel.org Subject: Re: [PATCH v3 1/2] riscv: Introduce support for hardware break/watchpoints Message-ID: <20260319103629.by3bw3qeev26jvqq@imamay-pc> References: <20260223044918.1359983-1-himanshu.chauhan@oss.qualcomm.com> <20260223044918.1359983-2-himanshu.chauhan@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260223044918.1359983-2-himanshu.chauhan@oss.qualcomm.com> Hi, Himanshu I have been using your previous HBP implementation for some time and have encountered some of its shortcomings, which this implementation has also inherited. On Mon, Feb 23, 2026 at 10:19:17AM +0530, Himanshu Chauhan wrote: > +/* > + * HW Breakpoint/watchpoint handler > + */ > +static int hw_breakpoint_handler(struct die_args *args) > +{ > + int ret = NOTIFY_DONE; > + struct arch_hw_breakpoint *bp; > + struct perf_event *event; > + int i; > + > + for (i = 0; i < dbtr_total_num; i++) { > + event = this_cpu_read(pcpu_hw_bp_events[i]); > + if (!event) > + continue; > + > + bp = counter_arch_bp(event); > + switch (bp->type) { > + /* Breakpoint */ > + case RV_DBTR_BP: > + if (bp->address == args->regs->epc) { > + perf_bp_event(event, args->regs); > + ret = NOTIFY_STOP; > + } > + break; > + > + /* Watchpoint */ > + case RV_DBTR_WP: > + if (bp->address == csr_read(CSR_STVAL)) { Sdtrig spec (5.7.11 and 5.7.12 in the tdata1.select field description) states that: "There is at least (!) one compare value and it contains the lowest virtual address of the access. In addition, it is recommended that there are additional compare values for the other accessed virtual addresses match. (E.g. on a 32-bit read from 0x4000, the lowest address is 0x4000 and the other addresses are 0x4001, 0x4002, and 0x4003". A 32-bit read from 0x4000 will definitely have compare value 0x4000 (the lowest virtual address), but may also have compare values at 0x4001, 0x4002, and 0x4003. This means that a 16-bit watchpoint at 0x4002 will fire on this 32-bit read, yet stval will be 0x4000, and the current hw_breakpoint_handler implementation will not detect it. Therefore, it is important to check tdata1.hit bit (which indicates that the trigger condition was definitely met) and only use the comparison between bp->address and CSR_STVAL as a fallback (if tdata1.hit is not supported by the hardware). > +/* atomic: counter->ctx->lock is held */ > +int arch_install_hw_breakpoint(struct perf_event *event) > +{ > + struct arch_hw_breakpoint *bp = counter_arch_bp(event); > + union sbi_dbtr_shmem_entry *shmem = this_cpu_ptr(sbi_dbtr_shmem); > + struct sbi_dbtr_data_msg *xmit; > + struct sbi_dbtr_id_msg *recv; > + struct perf_event **slot; > + unsigned long idx; > + struct sbiret ret; > + int err = 0; > + > + raw_spin_lock_irqsave(this_cpu_ptr(&ecall_lock), > + *this_cpu_ptr(&ecall_lock_flags)); > + > + xmit = &shmem->data; > + recv = &shmem->id; > + xmit->tdata1 = cpu_to_le(bp->tdata1); > + xmit->tdata2 = cpu_to_le(bp->tdata2); > + xmit->tdata3 = cpu_to_le(bp->tdata3); > + > + ret = sbi_ecall(SBI_EXT_DBTR, SBI_EXT_DBTR_TRIG_INSTALL, > + 1, 0, 0, 0, 0, 0); perf installs breakpoints (via the call chain pmu.add->arch_install_hw_breakpoint) during context rotation after a perf_event_open or ptrace call finishes. So, if the hardware does not support the given tdata1, tdata2 and tdata3 configuration and OpenSBI fails to set up the trigger, the kernel will still report that the breakpoint was successfully installed. A probing stage is therefore needed before or during perf event registration to ensure that all breakpoints can be installed successfully during context rotation. > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv