From nobody Sat Oct 10 12:36:52 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4j23Br75m5z6vdZm for ; Sat, 10 Oct 2026 12:36:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4j23Br5kz5z4q2G for ; Sat, 10 Oct 2026 12:36:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791635812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eGrbUJIsxEb8tzdlTvY0g/NnEQ/pKS5ObR71KxHdVRE=; b=qfWb/UoSVelV+c8M3YU5mM87X7FbpaJgYq4ISi+SS3lOcJsUNgXihCanhfUFspRUPdYPJs 44FiMQriVLoeeuttYbTYgBjHNQPuRuBXfF8l+aeUKBM76oXgOCEjfthmeNaof49mY9f4JB Pl+1wMG48jO2UWxmXvE9lcCxfnRm3/lozXtsOu5e0uGshKV+lC9GMNW51mzu507XiskZGn XSL4Mwzy8td7fUdkD3+ZexAGdxHnJ/A87soKWVZpzoqqKjXAXtv5Bu7+5sTtwGxaLXStYb KsKuinLQnkn5v0cViWOR4iHjuHFgq5Kt1SZljwztMSEd8WXHdBP8aFFgMoceIA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791635812; b=eP+5jTb6Cd96pcSIsutP2qfrI8gVOVp1wWvQraDok4IWKvS76k0bzJKrsODNvAfKiUNBZP pZDj1VScJm4c1WdGlHOWxzoJkqPluLrbaIaLDTkmBi4mSzNXi4Kri5qFF6NMzGfkX5Jhv+ +s3t16CuXZeCPwUvzoW8hlkm7pmyzIoWDMwPcWArwerJ9yF38rMDpOBEtLjlmjo4b8dRcN 8mT0h28KOF4fv0tZ11gupz6lm1VPYmIBxLMB3o8CXKWZfcl/H39RH0fT6FLI0dutRgl725 fVMEchLWtigSXbqKsGafUDLQgF8oWxkmMPTyGZjoB1Y+zntAPFCdltucD0WAmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791635812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eGrbUJIsxEb8tzdlTvY0g/NnEQ/pKS5ObR71KxHdVRE=; b=bjYNq7qXnx9xa1XcRXS1w9HrlD0tcDTeHqsF4Yy48oTc7zIWmzZUxgjvM8qkOzOnkugvX1 vqiI/FtFaXTGa8AiQyOWJL7a7usuTM7+QxwadHTi0c4sWimLyKXYk2/ktWcdhFCsOe8glf dVkYOj/nZjDu4eXybGFr/6p87aMxKA0nHvVZzNpEblgFuX2lm/ZOD5cG5NOwkjJbytNL/h C3fGoTriQTga6J2jeXsjQYEaHrvAFvdxptnVKa2YkbgjZa726lWRoaGoffi8MyrDSRW3fN KihLg1E6prqNByN20ld4lVRJlPx9HYpA2vvrqrSxszpS0+cHxfUZjHT3ctzrig== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j23Br426SzvrQ for ; Sat, 10 Oct 2026 12:36:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 25204 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 10 Oct 2026 12:36:52 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bojan Novk=?utf-8?Q?ovi=C4=87?= Subject: git: f627ff51b76c - main - riscv/pmap.c: Don't pass hartid map to 'smp_rendezvous_cpus' List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bnovkov X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f627ff51b76c728b8c6c4a7e5490ce3803c562ad Auto-Submitted: auto-generated Date: Sat, 10 Oct 2026 12:36:52 +0000 Message-Id: <6aca3164.25204.1e43e2f8@gitrepo.freebsd.org> The branch main has been updated by bnovkov: URL: https://cgit.FreeBSD.org/src/commit/?id=f627ff51b76c728b8c6c4a7e5490ce3803c562ad commit f627ff51b76c728b8c6c4a7e5490ce3803c562ad Author: Bojan Novković AuthorDate: 2026-09-27 18:25:22 +0000 Commit: Bojan Novković CommitDate: 2026-10-10 12:34:57 +0000 riscv/pmap.c: Don't pass hartid map to 'smp_rendezvous_cpus' The pm_active bitmask is indexed by hart IDs which can differ from CPU IDs. `pmap_invalidate_range_svinval` assumes that the map is indexed by CPU IDs, which is wrong and causes remote TLB invalidations on unrelated CPUs. Fix this by adding a routine that converts a hart-indexed bitmask to a CPU ID-indexed bitmask. While we're here, fix a similar issue in `pmap_active_cpus`. Fixes: 99360212c739 ("riscv/pmap.c: Add an Svinval-aware variant of pmap_invalidate_range") Reported by: markj Reviewed by: markj, mhorne Differential Revision: https://reviews.freebsd.org/D60072 --- sys/riscv/include/cpu.h | 3 +++ sys/riscv/include/smp.h | 1 - sys/riscv/riscv/mp_machdep.c | 39 +++++++++++++++++++++++++++++++-------- sys/riscv/riscv/pmap.c | 11 ++++++----- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/sys/riscv/include/cpu.h b/sys/riscv/include/cpu.h index 59214f05f595..05d3c4c834a5 100644 --- a/sys/riscv/include/cpu.h +++ b/sys/riscv/include/cpu.h @@ -36,6 +36,8 @@ #define _MACHINE_CPU_H_ #ifndef LOCORE +#include + #include #include #include @@ -105,6 +107,7 @@ void cpu_reset(void) __dead2; void fork_trampoline(void); void identify_cpu(u_int cpu); void printcpuinfo(u_int cpu); +cpuset_t hartmask_to_cpumask(const cpuset_t); static __inline uint64_t get_cyclecount(void) diff --git a/sys/riscv/include/smp.h b/sys/riscv/include/smp.h index 863f0bbd6d21..bc1f77f32135 100644 --- a/sys/riscv/include/smp.h +++ b/sys/riscv/include/smp.h @@ -50,5 +50,4 @@ enum { void ipi_all_but_self(u_int ipi); void ipi_cpu(int cpu, u_int ipi); void ipi_selected(cpuset_t cpus, u_int ipi); - #endif /* !_MACHINE_SMP_H_ */ diff --git a/sys/riscv/riscv/mp_machdep.c b/sys/riscv/riscv/mp_machdep.c index 5402c6d388ed..1d5c85f8b13a 100644 --- a/sys/riscv/riscv/mp_machdep.c +++ b/sys/riscv/riscv/mp_machdep.c @@ -110,6 +110,19 @@ static volatile int aps_ready; /* Temporary variables for init_secondary() */ void *dpcpu[MAXCPU - 1]; +static u_int +hartid_to_cpuid(u_int hart) +{ + u_int cpuid; + + cpuid = hart; + if (cpuid < boot_hart) + cpuid += mp_maxid + 1; + cpuid -= boot_hart; + + return (cpuid); +} + static void release_aps(void *dummy __unused) { @@ -154,10 +167,7 @@ init_secondary(uint64_t hart) u_int cpuid; /* Renumber this cpu */ - cpuid = hart; - if (cpuid < boot_hart) - cpuid += mp_maxid + 1; - cpuid -= boot_hart; + cpuid = hartid_to_cpuid(hart); /* Setup the pcpu pointer */ pcpup = &__pcpu[cpuid]; @@ -366,10 +376,7 @@ cpu_init_fdt(u_int id, phandle_t node, u_int addr_size, pcell_t *reg) * Rotate the CPU IDs to put the boot CPU as CPU 0. * We keep the other CPUs ordered. */ - cpuid = hart; - if (cpuid < boot_hart) - cpuid += mp_maxid + 1; - cpuid -= boot_hart; + cpuid = hartid_to_cpuid(hart); /* Check if we are able to start this cpu */ if (cpuid > mp_maxid) @@ -525,3 +532,19 @@ ipi_selected(cpuset_t cpus, u_int ipi) CTR1(KTR_SMP, "ipi_selected: ipi: %x", ipi); intr_ipi_send(cpus, ipi); } + +cpuset_t +hartmask_to_cpumask(const cpuset_t harts) +{ + u_int hart; + u_int cpu; + cpuset_t cpumask; + + CPU_ZERO(&cpumask); + CPU_FOREACH_ISSET(hart, &harts) { + cpu = hartid_to_cpuid(hart); + CPU_SET(cpu, &cpumask); + } + + return (cpumask); +} diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index b3f03eeaab9f..66dd65747f13 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -157,6 +157,7 @@ #include #include +#include #include #include #include @@ -1149,11 +1150,11 @@ pmap_invalidate_range_svinval(pmap_t pmap, vm_offset_t sva, vm_offset_t eva) args.sva = sva; args.eva = eva; fence(); - if (smp_started) - smp_rendezvous_cpus(pmap->pm_active, smp_no_rendezvous_barrier, - pmap_invalidate_range_svinval_cb, + if (smp_started) { + smp_rendezvous_cpus(hartmask_to_cpumask(pmap->pm_active), + smp_no_rendezvous_barrier, pmap_invalidate_range_svinval_cb, smp_no_rendezvous_barrier, &args); - else + } else pmap_invalidate_range_svinval_cb(&args); sched_unpin(); } @@ -5323,7 +5324,7 @@ pmap_activate_boot(pmap_t pmap) void pmap_active_cpus(pmap_t pmap, cpuset_t *res) { - *res = pmap->pm_active; + *res = hartmask_to_cpumask(pmap->pm_active); } void