From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.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 454F220A5EC for ; Tue, 5 Aug 2025 19:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754422800; cv=none; b=MLKW89p/OyLxqQ52xvvZzpGm72F3hkJVHRAgi8TE3Hw75njxKwBdeQmViryc/jaZhryOasrnQ/i69H/8nxtgFdVHE4EmrESMsZtTEDIOHMkniLRMKflslpXHe/rZrP2FZ+iwwqVFG9Ldg0Npee0/OCxpoK8xb1jxxwdVRSS0Lm0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754422800; c=relaxed/simple; bh=+qlcnySMX8H8r8qM3Fwa6oKB8CHMdlILBs2oyCCdlVQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XFqJOxjssRr4ES7c4A34brpTjbaxWODsl4HlG7QqWlpH4Mg3/TAzlUDCtxXQ529nYEqdEc3aQTemZYMz6ctwH3EebxBWmdnvU+aPjdcYwK9BSQGeYeCMQ4RigOsnpYUaNngqlmR9UubMXPgLUe1yhJFgMU850hlLMCm8T5LkPkc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b=gS5q6bHH; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b="gS5q6bHH" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7e806613af8so229451785a.2 for ; Tue, 05 Aug 2025 12:39:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc.com; s=google; t=1754422798; x=1755027598; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Av9ulXUYq8yypH92LgefCWXE0SBG4q/HDQdjt7nKwbs=; b=gS5q6bHHwwqgpwrJhZNvQG/XEsuG5cccTu8L091bJqboPLHuExlcxVjdz7tIheybqi 8cIap9noWifxDLoB65B7TBWgdLKDBflBZfxgmQoL5OlR4Z+EStzVXHTi7MwTUHPrdYj+ oUWxgLWrt1PNk70r7TyXz6kwuYASvBQfZUkugyXqTpnTzChq6Z1qHobD1qr/KANWJhOd H4cRBgnL3fasaoTAI4xSgQYf8AhrnZ4g3O6Lh0oHoPrL/p4oPuiOur84xJLB817ezYYW 29Bi/JC5T2fDDvl9QwSKqZqJs9J64b57QtzIVt2yQW3tMKvfreoH6Js/5e77EHv/ogQl GD7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754422798; x=1755027598; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Av9ulXUYq8yypH92LgefCWXE0SBG4q/HDQdjt7nKwbs=; b=IzXXdAoLJSJ+lG8DVMcHi9xx/eVAS5u8CPHaCJbcXJg3q1fwsABP7oJEEpRPrDDOG/ osCfbjKNHtrqS4AulB7rXgBgMHtHUwD5G4rZZYoA58+LwxPCFzCu3RDBPFqI8ARYwbvL tb3kZFRlBOYntuWRIwF5hI8Yz3zL7yZzQssWq7IIqzWDIJViHvQwaI1sE62S8CsQwEQj zG6oSjBOYOfERoXFvawwYd7zXXk1Kx8Abo497Cz1JJXwFtiBqkqGZrn8u51GwOuOk8ev RKo2TvE2lP8e9rTU6QwirEtzi5+GUtc28i3emUuhIIopGKUCl3TZAm6aE28uVFSfM1oC YXiA== X-Forwarded-Encrypted: i=1; AJvYcCVcH0xyrUQvdrCPFJVHAuVHyQD8q1KIFnWrio4hRfBGDXlSn02pSgpLkru/C+5MMlr5d11iPSiToND/2y4=@vger.kernel.org X-Gm-Message-State: AOJu0YzPk2eSNwtb2C1YjruJEiDM56R750Sooe3K+7d7WQaiCfgAr4D/ 6izrGneuRzJRchZ7S2n0xNh0WqY9eAI8/mqmX8qMOkyPJcDUmR/dOoiUTtumgHO3lrc= X-Gm-Gg: ASbGncst1xZUmH2f9oZOz8YCi2xx5mqFFcUSFABBIDEXgL6ERjPOP4HKiy9d9Yr/lYb OoE5a72WDaCknRt8f/pbbIjHguUwMbNKa+y7ak9tG7FQ2Px/btq3FujVwza4w2jnpGxc7mZWweH hzOUFVe5z4dORJwYdvhRsSJaXQj2TzIx4IesAdpadnXgfeZSob7aJUJFTuRxtaccGsMNXZ9lqYA ryn3CjXtBUnButUlsTIDx4pVzPb+0QzbWeWQN2vQtnO6UJww/nBtpWVJ9bi+I8scUA6/7sUf7Jd n6XUsD99qPYETeJZmjlfPR/DfFsA3KeABwwuq/4iN0jGmsjI8SzuTmJfqoQPROD/Y8Vgh/cXi7i z6iVbm+m3DeKkFCh3zEEJCVqmKO6HJKlLneFOtGOXavrIbxhgcHVr1TYbSLagEAhZ3AmqEVr/SA dWBnZJiw== X-Google-Smtp-Source: AGHT+IGaYz9rbHDaluNVvJAMepELkYucyj+ueO/efwJAG+Ld5Sktyl2JYCmbLDUiGqnvS0NmhNn2LQ== X-Received: by 2002:a05:620a:370f:b0:7e6:67b3:ebf2 with SMTP id af79cd13be357-7e814d1a1e2mr85393985a.27.1754422798022; Tue, 05 Aug 2025 12:39:58 -0700 (PDT) Received: from jesse-lt.jtp-bos.lab (pool-108-26-215-125.bstnma.fios.verizon.net. [108.26.215.125]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7e67f7064b0sm717855685a.54.2025.08.05.12.39.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Aug 2025 12:39:57 -0700 (PDT) From: Jesse Taube To: linux-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Oleg Nesterov , Kees Cook , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Shuah Khan , Jesse Taube , Himanshu Chauhan , Charlie Jenkins , Samuel Holland , Conor Dooley , Deepak Gupta , Andrew Jones , Atish Patra , Anup Patel , Mayuresh Chitale , Evan Green , WangYuli , Huacai Chen , Arnd Bergmann , Andrew Morton , Luis Chamberlain , "Mike Rapoport (Microsoft)" , Nam Cao , Yunhui Cui , Joel Granados , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Sebastian Andrzej Siewior , Celeste Liu , Chunyan Zhang , Nylon Chen , Thomas Gleixner , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Vincenzo Frascino , Joey Gouly , Akihiko Odaki , Ravi Bangoria , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH 0/8] riscv: add initial support for hardware breakpoints Date: Tue, 5 Aug 2025 12:39:47 -0700 Message-ID: <20250805193955.798277-1-jesse@rivosinc.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patchset adds initial support for hardware breakpoints and watchpoints to the RISC-V architecture. The framework is built on top of perf subsystem and SBI debug trigger extension. Currently following features are not supported and are in works: - icount for single stepping - Virtualization of debug triggers - kernel space debug triggers The SBI debug trigger extension can be found at: https://github.com/riscv-non-isa/riscv-sbi-doc/blob/master/src/ext-debug-triggers.adoc The Sdtrig ISA is part of RISC-V debug specification which can be found at: https://github.com/riscv/riscv-debug-spec based off the original RFC by Himanshu Chauhan here: https://lore.kernel.org/lkml/20240222125059.13331-1-hchauhan@ventanamicro.com/ Second RFC by Jesse Taube here: https://lore.kernel.org/lkml/20250722173829.984082-1-jesse@rivosinc.com/ Himanshu Chauhan (2): riscv: Add SBI debug trigger extension and function ids riscv: Introduce support for hardware break/watchpoints Jesse Taube (6): riscv: Add insn.c, consolidate instruction decoding riscv: insn: Add get_insn_nofault riscv: hw_breakpoint: Use icount for single stepping riscv: ptrace: Add hw breakpoint support riscv: ptrace: Add hw breakpoint regset selftests: riscv: Add test for hardware breakpoints arch/riscv/Kconfig | 13 + arch/riscv/include/asm/bug.h | 12 - arch/riscv/include/asm/hw_breakpoint.h | 59 ++ arch/riscv/include/asm/insn.h | 132 ++- arch/riscv/include/asm/kdebug.h | 3 +- arch/riscv/include/asm/processor.h | 4 + arch/riscv/include/asm/sbi.h | 33 +- arch/riscv/include/uapi/asm/ptrace.h | 9 + arch/riscv/kernel/Makefile | 2 + arch/riscv/kernel/hw_breakpoint.c | 769 ++++++++++++++++++ arch/riscv/kernel/insn.c | 165 ++++ arch/riscv/kernel/kgdb.c | 102 +-- arch/riscv/kernel/probes/kprobes.c | 1 + arch/riscv/kernel/process.c | 4 + arch/riscv/kernel/ptrace.c | 169 ++++ arch/riscv/kernel/traps.c | 11 +- arch/riscv/kernel/traps_misaligned.c | 93 +-- include/uapi/linux/elf.h | 2 + tools/include/uapi/linux/elf.h | 1 + tools/perf/tests/tests.h | 3 +- tools/testing/selftests/riscv/Makefile | 2 +- .../selftests/riscv/breakpoints/.gitignore | 1 + .../selftests/riscv/breakpoints/Makefile | 12 + .../riscv/breakpoints/breakpoint_test.c | 246 ++++++ 24 files changed, 1657 insertions(+), 191 deletions(-) create mode 100644 arch/riscv/include/asm/hw_breakpoint.h create mode 100644 arch/riscv/kernel/hw_breakpoint.c create mode 100644 arch/riscv/kernel/insn.c create mode 100644 tools/testing/selftests/riscv/breakpoints/.gitignore create mode 100644 tools/testing/selftests/riscv/breakpoints/Makefile create mode 100644 tools/testing/selftests/riscv/breakpoints/breakpoint_test.c -- 2.43.0