The branch stable/15 has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=0dce4f2a39dcdc30c3176720a4f86c69b9a1d707

commit 0dce4f2a39dcdc30c3176720a4f86c69b9a1d707
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-09-19 07:43:34 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-09-29 00:27:15 +0000

    amd64: cache MSR_MEMORY_CTL in pcpu
    
    (cherry picked from commit 74d325fee2dbcb5f8541819481ce76f87c151a21)
---
 sys/amd64/amd64/initcpu.c    | 11 +++++++++++
 sys/amd64/amd64/machdep.c    |  7 +++----
 sys/amd64/amd64/mp_machdep.c |  2 ++
 sys/amd64/include/md_var.h   |  1 +
 sys/amd64/include/pcpu.h     |  3 ++-
 5 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/sys/amd64/amd64/initcpu.c b/sys/amd64/amd64/initcpu.c
index 4ae79693addf..2d2f5835e3b3 100644
--- a/sys/amd64/amd64/initcpu.c
+++ b/sys/amd64/amd64/initcpu.c
@@ -458,3 +458,14 @@ amd64_init_splitlock(void)
                ia32_splitlock_force = 0;
        }
 }
+
+void
+amd64_cpu_init_msr_memctl(void)
+{
+       uint64_t msr;
+
+       if ((cpu_stdext_feature3 & CPUID_STDEXT3_CORE_CAP) != 0 &&
+           rdmsr_safe(MSR_IA32_CORE_CAP, &msr) == 0 &&
+           (msr & IA32_CORE_CAP_SPLITLOCK) != 0)
+               PCPU_SET(msr_memctl, rdmsr(MSR_MEMORY_CTL));
+}
diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 0b72a1043b40..c871838c9c7b 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -1659,6 +1659,7 @@ hammer_time(u_int64_t modulep, u_int64_t physfree)
        thread0.td_pcb->pcb_flags = 0;
 
        amd64_init_splitlock();
+       amd64_cpu_init_msr_memctl();
 
         env = kern_getenv("kernelname");
        if (env != NULL)
@@ -1933,8 +1934,7 @@ void
 enable_splitlock_ac(void)
 {
        MPASS(ia32_splitlock);
-       wrmsr(MSR_MEMORY_CTL, rdmsr(MSR_MEMORY_CTL) |
-           MSR_MEMORY_CTL_SPLITLOCK);
+       wrmsr(MSR_MEMORY_CTL, PCPU_GET(msr_memctl) | MSR_MEMORY_CTL_SPLITLOCK);
 }
 
 void
@@ -1951,8 +1951,7 @@ void
 disable_splitlock_ac(void)
 {
        MPASS(ia32_splitlock);
-       wrmsr(MSR_MEMORY_CTL, rdmsr(MSR_MEMORY_CTL) &
-           ~MSR_MEMORY_CTL_SPLITLOCK);
+       wrmsr(MSR_MEMORY_CTL, PCPU_GET(msr_memctl) & ~MSR_MEMORY_CTL_SPLITLOCK);
 }
 
 void
diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index 96e91b59834e..41aa8fa7e281 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
@@ -296,6 +296,8 @@ init_secondary(void)
        else
                lidt(&r_idt);
 
+       amd64_cpu_init_msr_memctl();
+
        gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
        ltr(gsel_tss);
 
diff --git a/sys/amd64/include/md_var.h b/sys/amd64/include/md_var.h
index f73cb916d53a..c3b5f2050212 100644
--- a/sys/amd64/include/md_var.h
+++ b/sys/amd64/include/md_var.h
@@ -68,6 +68,7 @@ struct trapframe;
 
 void   amd64_conf_fast_syscall(void);
 void   amd64_cpu_init_fred(void);
+void   amd64_cpu_init_msr_memctl(void);
 void   amd64_db_resume_dbreg(void);
 void   amd64_init_splitlock(void);
 vm_paddr_t amd64_loadaddr(void);
diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h
index 213790d245dc..6a91122eb2ec 100644
--- a/sys/amd64/include/pcpu.h
+++ b/sys/amd64/include/pcpu.h
@@ -101,7 +101,8 @@ _Static_assert(sizeof(struct monitorbuf) == 128, "2x cache 
line");
        u_int   pc_small_core;                                          \
        u_int   pc_pcid_invlpg_workaround;                              \
        struct pmap_pcid pc_kpmap_store;                                \
-       char    __pad[2900]             /* pad to UMA_PCPU_ALLOC_SIZE */
+       uint64_t pc_msr_memctl;                                         \
+       char    __pad[2892]             /* pad to UMA_PCPU_ALLOC_SIZE */
 
 #define        PC_DBREG_CMD_NONE       0
 #define        PC_DBREG_CMD_LOAD       1

Reply via email to