Skip to contentSkip to conversation

x86/msr: Drop 32-bit MSR interfaces

PATCH Applied Juergen Gross 16 participants 121 messages Jun 29 – Jul 19 Page 1 of 2

Subsystems (47)
x86 KVM ACPI PCI +43 more subsystems

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore

Juergen Gross

author maintainer
#0 lore raw

cover x86/msr: Drop 32-bit MSR interfaces

For accessing the MSR registers on the local CPU, there are 2 types of
interfaces: the "modern" 64-bit ones (rdmsrq() etc.) and the 32-bit ones (rdmsr() etc.) which are using the upper and lower 32-bit halves of the 64-bit wide MSR register values.

The 32-bit interfaces are not optimal for 3 reasons:

- They are based on primitives using 64-bit sized values anyway.

- Modern x86 CPUs have added support for MSR access instructions using an immediate value instead of a register for addressing the MSR, while the value is in a 64-bit register.

- rdmsr() is a macro storing the upper and lower 32-bit halves in variables specified as macro parameters. This is obscuring variable assignment through a macro. Additionally rdmsrq() is mimicking this pattern by being a macro, too, with the target variable specified as a parameter as well.

For those reasons drop the 32-bit interfaces for accessing the x86 MSR registers completely and only use the 64-bit variants.

This allows to switch all "high-level" MSR access macros to inline functions in the end.

This series will be used as the base for further reorganisation of the MSR access functions, especially for completely inlining the MSR access instructions even with paravirtualization being active.

Note that most patches of this series are independent from each other. Only the patches removing a specific interface (patches 7, 15, 26 and
30) and the last two patches of the series depend on all previous patches.

Based on kernel 7.2-rc1, tested with and without parvirtualization active, compile tested for x86 with 64- and 32-bit allyes and allno configs.

Juergen Gross (32):
thermal/intel: Stop using 32-bit MSR interfaces
powercap: Stop using 32-bit MSR interfaces
edac: Stop using 32-bit MSR interfaces
acpi: Stop using 32-bit MSR interfaces
x86/mtrr: Stop using 32-bit MSR interfaces
x86/msr: Stop using 32-bit MSR interfaces in lib/msr-smp.c x86/msr: Remove wrmsr_safe()
x86/mce: Stop using 32-bit MSR interfaces
KVM/x86: Stop using 32-bit MSR interfaces x86/hygon: Stop using 32-bit MSR interfaces x86/pci: Stop using 32-bit MSR interfaces
x86/amd: Stop using 32-bit MSR interfaces x86/featctl: Stop using 32-bit MSR interfaces x86/tsc: Stop using 32-bit MSR interfaces
x86/msr: Remove rdmsr_safe()
cpufreq: Stop using 32-bit MSR interfaces x86/resctrl: Stop using 32-bit MSR interfaces x86/apic: Stop using 32-bit MSR interfaces
x86/cpu: Stop using 32-bit MSR interfaces drivers/ata: Stop using 32-bit MSR interfaces agp/nvidia: Stop using 32-bit MSR interfaces fbdev/geode: Stop using 32-bit MSR interfaces hw_random/via-rng: Stop using 32-bit MSR interfaces drivers/gpio: Stop using 32-bit MSR interfaces drivers/misc: Stop using 32-bit MSR interfaces x86/msr: Remove wrmsr()
x86/hyperv: Stop using 32-bit MSR interfaces x86/olpc: Stop using 32-bit MSR interfaces
hwmon: Stop using 32-bit MSR interfaces
x86/msr: Remove rdmsr()
treewide: convert rdmsrq() from a macro to an inline function x86/msr: Simplify some rdmsrq() use cases

 arch/x86/coco/sev/core.c                      |  2 +-
 arch/x86/events/amd/brs.c                     |  4 +-
 arch/x86/events/amd/core.c                    |  8 +-
 arch/x86/events/amd/ibs.c                     | 18 ++--
 arch/x86/events/amd/lbr.c                     | 16 +--
 arch/x86/events/amd/power.c                   |  8 +-
 arch/x86/events/amd/uncore.c                  |  4 +-
 arch/x86/events/core.c                        | 20 ++--
 arch/x86/events/intel/core.c                  | 14 +--
 arch/x86/events/intel/cstate.c                |  5 +-
 arch/x86/events/intel/ds.c                    |  2 +-
 arch/x86/events/intel/knc.c                   | 10 +-
 arch/x86/events/intel/lbr.c                   | 25 ++---
 arch/x86/events/intel/p4.c                    |  6 +-
 arch/x86/events/intel/p6.c                    |  4 +-
 arch/x86/events/intel/pt.c                    | 12 +--
 arch/x86/events/intel/uncore.c                |  6 +-
 arch/x86/events/intel/uncore_nhmex.c          |  4 +-
 arch/x86/events/intel/uncore_snb.c            |  2 +-
 arch/x86/events/intel/uncore_snbep.c          |  6 +-
 arch/x86/events/msr.c                         |  2 +-
 arch/x86/events/perf_event.h                  |  6 +-
 arch/x86/events/rapl.c                        |  6 +-
 arch/x86/events/zhaoxin/core.c                | 10 +-
 arch/x86/hyperv/hv_apic.c                     | 17 ++--
 arch/x86/hyperv/hv_init.c                     | 26 ++---
 arch/x86/hyperv/hv_spinlock.c                 |  2 +-
 arch/x86/include/asm/apic.h                   |  7 +-
 arch/x86/include/asm/debugreg.h               |  6 +-
 arch/x86/include/asm/fsgsbase.h               |  2 +-
 arch/x86/include/asm/kvm_host.h               |  5 +-
 arch/x86/include/asm/msr.h                    | 39 +-------
 arch/x86/include/asm/paravirt.h               | 26 +----
 arch/x86/include/asm/resctrl.h                |  5 +-
 arch/x86/kernel/acpi/sleep.c                  | 20 ++--
 arch/x86/kernel/apic/apic.c                   | 45 ++++-----
 arch/x86/kernel/apic/apic_numachip.c          |  6 +-
 arch/x86/kernel/cet.c                         |  2 +-
 arch/x86/kernel/cpu/amd.c                     | 42 ++++----
 arch/x86/kernel/cpu/aperfmperf.c              |  8 +-
 arch/x86/kernel/cpu/bugs.c                    | 12 +--
 arch/x86/kernel/cpu/bus_lock.c                |  8 +-
 arch/x86/kernel/cpu/centaur.c                 | 35 +++----
 arch/x86/kernel/cpu/common.c                  | 22 +++--
 arch/x86/kernel/cpu/feat_ctl.c                | 27 +++---
 arch/x86/kernel/cpu/hygon.c                   |  9 +-
 arch/x86/kernel/cpu/intel.c                   | 12 +--
 arch/x86/kernel/cpu/intel_epb.c               |  4 +-
 arch/x86/kernel/cpu/mce/amd.c                 | 89 ++++++++---------
 arch/x86/kernel/cpu/mce/core.c                | 10 +-
 arch/x86/kernel/cpu/mce/inject.c              |  2 +-
 arch/x86/kernel/cpu/mce/intel.c               | 18 ++--
 arch/x86/kernel/cpu/mce/p5.c                  | 16 +--
 arch/x86/kernel/cpu/mce/winchip.c             | 10 +-
 arch/x86/kernel/cpu/microcode/intel.c         |  2 +-
 arch/x86/kernel/cpu/mshyperv.c                |  6 +-
 arch/x86/kernel/cpu/mtrr/amd.c                | 36 ++++---
 arch/x86/kernel/cpu/mtrr/centaur.c            | 18 ++--
 arch/x86/kernel/cpu/mtrr/cleanup.c            | 18 ++--
 arch/x86/kernel/cpu/mtrr/generic.c            | 97 ++++++++++---------
 arch/x86/kernel/cpu/mtrr/mtrr.c               |  4 +-
 arch/x86/kernel/cpu/resctrl/core.c            |  9 +-
 arch/x86/kernel/cpu/resctrl/monitor.c         | 27 +++---
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c     | 12 +--
 arch/x86/kernel/cpu/resctrl/rdtgroup.c        |  2 +-
 arch/x86/kernel/cpu/topology.c                |  2 +-
 arch/x86/kernel/cpu/topology_amd.c            |  4 +-
 arch/x86/kernel/cpu/transmeta.c               |  9 +-
 arch/x86/kernel/cpu/tsx.c                     | 10 +-
 arch/x86/kernel/cpu/umwait.c                  |  2 +-
 arch/x86/kernel/cpu/zhaoxin.c                 | 12 +--
 arch/x86/kernel/fpu/core.c                    |  2 +-
 arch/x86/kernel/hpet.c                        |  2 +-
 arch/x86/kernel/kvm.c                         |  2 +-
 arch/x86/kernel/mmconf-fam10h_64.c            |  6 +-
 arch/x86/kernel/process.c                     |  4 +-
 arch/x86/kernel/process_64.c                  | 14 +--
 arch/x86/kernel/shstk.c                       |  8 +-
 arch/x86/kernel/traps.c                       |  4 +-
 arch/x86/kernel/tsc.c                         |  8 +-
 arch/x86/kernel/tsc_msr.c                     | 15 +--
 arch/x86/kernel/tsc_sync.c                    |  6 +-
 arch/x86/kvm/svm/pmu.c                        |  4 +-
 arch/x86/kvm/svm/svm.c                        |  4 +-
 arch/x86/kvm/vmx/nested.c                     |  4 +-
 arch/x86/kvm/vmx/pmu_intel.c                  |  8 +-
 arch/x86/kvm/vmx/sgx.c                        |  6 +-
 arch/x86/kvm/vmx/vmx.c                        | 54 ++++++-----
 arch/x86/kvm/x86.c                            | 12 +--
 arch/x86/lib/insn-eval.c                      |  6 +-
 arch/x86/lib/msr-smp.c                        |  8 +-
 arch/x86/mm/pat/memtype.c                     |  2 +-
 arch/x86/pci/amd_bus.c                        |  8 +-
 arch/x86/pci/mmconfig-shared.c                |  8 +-
 arch/x86/platform/olpc/olpc-xo1-rtc.c         |  6 +-
 arch/x86/platform/olpc/olpc-xo1-sci.c         | 11 ++-
 arch/x86/power/cpu.c                          | 10 +-
 arch/x86/realmode/init.c                      |  2 +-
 arch/x86/virt/hw.c                            |  8 +-
 arch/x86/virt/svm/sev.c                       | 18 ++--
 arch/x86/virt/vmx/tdx/tdx.c                   |  8 +-
 arch/x86/xen/suspend.c                        |  2 +-
 drivers/acpi/processor_perflib.c              | 11 ++-
 drivers/acpi/processor_throttling.c           | 14 +--
 drivers/ata/pata_cs5535.c                     | 20 ++--
 drivers/ata/pata_cs5536.c                     | 17 ++--
 drivers/char/agp/nvidia-agp.c                 | 32 +++---
 drivers/char/hw_random/via-rng.c              | 29 +++---
 drivers/cpufreq/acpi-cpufreq.c                | 24 ++---
 drivers/cpufreq/amd-pstate.c                  |  4 +-
 drivers/cpufreq/e_powersaver.c                | 52 +++++-----
 drivers/cpufreq/intel_pstate.c                | 30 +++---
 drivers/cpufreq/longhaul.c                    | 23 ++---
 drivers/cpufreq/longrun.c                     | 78 ++++++++-------
 drivers/cpufreq/powernow-k6.c                 | 12 +--
 drivers/cpufreq/powernow-k7.c                 | 10 +-
 drivers/cpufreq/powernow-k8.c                 | 67 ++++++-------
 drivers/cpufreq/speedstep-centrino.c          | 16 +--
 drivers/cpufreq/speedstep-lib.c               | 63 ++++++------
 drivers/edac/amd64_edac.c                     |  6 +-
 drivers/edac/ie31200_edac.c                   | 10 +-
 drivers/edac/mce_amd.c                        |  8 +-
 drivers/gpio/gpio-cs5535.c                    | 10 +-
 drivers/hv/mshv_vtl_main.c                    |  2 +-
 drivers/hwmon/hwmon-vid.c                     | 11 ++-
 drivers/idle/intel_idle.c                     | 26 ++---
 drivers/misc/cs5535-mfgpt.c                   | 33 +++----
 drivers/mtd/nand/raw/cs553x_nand.c            |  6 +-
 drivers/platform/x86/intel/ifs/load.c         | 10 +-
 drivers/platform/x86/intel/ifs/runtest.c      |  8 +-
 drivers/platform/x86/intel/pmc/cnp.c          |  2 +-
 .../intel/speed_select_if/isst_if_mbox_msr.c  |  6 +-
 .../intel/speed_select_if/isst_tpmi_core.c    |  2 +-
 drivers/platform/x86/intel_ips.c              | 20 ++--
 drivers/powercap/intel_rapl_common.c          | 20 ++--
 drivers/powercap/intel_rapl_msr.c             |  2 +-
 drivers/thermal/intel/intel_hfi.c             |  8 +-
 drivers/thermal/intel/intel_tcc.c             | 10 +-
 drivers/thermal/intel/therm_throt.c           | 74 +++++++-------
 drivers/thermal/intel/x86_pkg_temp_thermal.c  | 32 +++---
 drivers/video/fbdev/geode/display_gx.c        |  8 +-
 drivers/video/fbdev/geode/gxfb_core.c         |  2 +-
 drivers/video/fbdev/geode/lxfb_ops.c          | 50 +++++-----
 drivers/video/fbdev/geode/suspend_gx.c        | 24 ++---
 drivers/video/fbdev/geode/video_gx.c          |  8 +-
 include/linux/cs5535.h                        | 10 +-
 146 files changed, 1044 insertions(+), 1128 deletions(-)
Signature · 1 line
2.54.0
author maintainer
#1 lore raw

PATCH 1/32 thermal/intel: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/thermal/intel/intel_tcc.c            | 10 +--
 drivers/thermal/intel/therm_throt.c          | 68 +++++++++-----------
 drivers/thermal/intel/x86_pkg_temp_thermal.c | 32 +++++----
 3 files changed, 52 insertions(+), 58 deletions(-)
drivers/thermal/intel/intel_tcc.c +5 -5
index 59f70bb5ffa5..d1fa3c63d554 100644
@@ -185,7 +185,7 @@ int intel_tcc_get_tjmax(int cpu)
 	int val, err;
 
 	if (cpu < 0)
-		err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &msrval.l, &msrval.h);
+		err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &msrval.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &msrval.q);
 	if (err)
@@ -212,7 +212,7 @@ int intel_tcc_get_offset(int cpu)
 	int err;
 
 	if (cpu < 0)
-		err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &val.l, &val.h);
+		err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	if (err)
@@ -245,7 +245,7 @@ int intel_tcc_set_offset(int cpu, int offset)
 		return -EINVAL;
 
 	if (cpu < 0)
-		err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &val.l, &val.h);
+		err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	if (err)
@@ -259,7 +259,7 @@ int intel_tcc_set_offset(int cpu, int offset)
 	val.l |= offset << 24;
 
 	if (cpu < 0)
-		return wrmsr_safe(MSR_IA32_TEMPERATURE_TARGET, val.l, val.h);
+		return wrmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, val.q);
 	else
 		return wrmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, val.q);
 }
@@ -288,7 +288,7 @@ int intel_tcc_get_temp(int cpu, int *temp, bool pkg)
 		return tjmax;
 
 	if (cpu < 0)
-		err = rdmsr_safe(msr, &val.l, &val.h);
+		err = rdmsrq_safe(msr, &val.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, msr, &val.q);
 	if (err)
drivers/thermal/intel/therm_throt.c +32 -36

119 lines not on this page · raw message

drivers/thermal/intel/x86_pkg_temp_thermal.c +15 -17
index 688e04c63761..43fd5bdf1d8d 100644
@@ -51,8 +51,7 @@ MODULE_PARM_DESC(notify_delay_ms,
 struct zone_device {
 	int				cpu;
 	bool				work_scheduled;
-	u32				msr_pkg_therm_low;
-	u32				msr_pkg_therm_high;
+	u64				msr_pkg_therm;
 	struct delayed_work		work;
 	struct thermal_zone_device	*tzone;
 	struct cpumask			cpumask;
@@ -186,28 +185,28 @@ static bool pkg_thermal_rate_control(void)
 static inline void enable_pkg_thres_interrupt(void)
 {
 	u8 thres_0, thres_1;
-	u32 l, h;
+	struct msr val;
 
-	rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 	/* only enable/disable if it had valid threshold value */
-	thres_0 = (l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
-	thres_1 = (l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
+	thres_0 = (val.l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
+	thres_1 = (val.l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
 	if (thres_0)
-		l |= THERM_INT_THRESHOLD0_ENABLE;
+		val.l |= THERM_INT_THRESHOLD0_ENABLE;
 	if (thres_1)
-		l |= THERM_INT_THRESHOLD1_ENABLE;
-	wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+		val.l |= THERM_INT_THRESHOLD1_ENABLE;
+	wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 /* Disable threshold interrupt on local package/cpu */
 static inline void disable_pkg_thres_interrupt(void)
 {
-	u32 l, h;
+	struct msr val;
 
-	rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 
-	l &= ~(THERM_INT_THRESHOLD0_ENABLE | THERM_INT_THRESHOLD1_ENABLE);
-	wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	val.l &= ~(THERM_INT_THRESHOLD0_ENABLE | THERM_INT_THRESHOLD1_ENABLE);
+	wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
@@ -357,8 +356,7 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
 		goto out_unregister_tz;
 
 	/* Store MSR value for package thermal interrupt, to restore at exit */
-	rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm_low,
-	      zonedev->msr_pkg_therm_high);
+	rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm);
 
 	cpumask_set_cpu(cpu, &zonedev->cpumask);
 	raw_spin_lock_irq(&pkg_temp_lock);
@@ -426,8 +424,8 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
 	if (lastcpu) {
 		zones[topology_logical_die_id(cpu)] = NULL;
 		/* After this point nothing touches the MSR anymore. */
-		wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
-		      zonedev->msr_pkg_therm_low, zonedev->msr_pkg_therm_high);
+		wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT,
+		       zonedev->msr_pkg_therm);
 	}
 
 	/*
Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH 01/32] thermal/intel: Stop using 32-bit MSR interfaces

drivers/thermal/intel/therm_throt.c void intel_init_thermal(struct cpuinfo_x86 *c) · line 779

Quoted 8 lines · Juergen Gross
drivers/thermal/intel/therm_throt.c +3 -4
-	rdmsr(MSR_IA32_THERM_INTERRUPT, l, h);
+	rdmsrq(MSR_IA32_THERM_INTERRUPT, val.q);
 	if (cpu_has(c, X86_FEATURE_PLN) && !int_pln_enable)
-		wrmsr(MSR_IA32_THERM_INTERRUPT,
-			(l | (THERM_INT_LOW_ENABLE
-			| THERM_INT_HIGH_ENABLE)) & ~THERM_INT_PLN_ENABLE, h);
+		val.l = (val.l | THERM_INT_LOW_ENABLE | THERM_INT_HIGH_ENABLE) &
+			~THERM_INT_PLN_ENABLE;

This could be written as something like:

		val.l |= THERM_INT_LOW_ENABLE | THERM_INT_HIGH_ENABLE;
		val.l &= ~THERM_INT_PLN_ENABLE;

Which would be far more readable than the multi-line statement.

drivers/thermal/intel/therm_throt.c void intel_init_thermal(struct cpuinfo_x86 *c) · line 792

Quoted 3 lines
drivers/thermal/intel/therm_throt.c +3 -0
+			val.l = (val.l | PACKAGE_THERM_INT_LOW_ENABLE |
+				 PACKAGE_THERM_INT_HIGH_ENABLE) &
+				~PACKAGE_THERM_INT_PLN_ENABLE;

Ditto.

Thanks,

Ingo

author maintainer
#3 lore raw

Re: [PATCH 01/32] thermal/intel: Stop using 32-bit MSR interfaces

Quoted 14 lines · Ingo Molnar

drivers/thermal/intel/therm_throt.c void intel_init_thermal(struct cpuinfo_x86 *c) · line 779

Quoted 8 lines · Juergen Gross
drivers/thermal/intel/therm_throt.c +3 -4
-	rdmsr(MSR_IA32_THERM_INTERRUPT, l, h);
+	rdmsrq(MSR_IA32_THERM_INTERRUPT, val.q);
  	if (cpu_has(c, X86_FEATURE_PLN) && !int_pln_enable)
-		wrmsr(MSR_IA32_THERM_INTERRUPT,
-			(l | (THERM_INT_LOW_ENABLE
-			| THERM_INT_HIGH_ENABLE)) & ~THERM_INT_PLN_ENABLE, h);
+		val.l = (val.l | THERM_INT_LOW_ENABLE | THERM_INT_HIGH_ENABLE) &
+			~THERM_INT_PLN_ENABLE;

This could be written as something like:

Quoted 8 lines
		val.l |= THERM_INT_LOW_ENABLE | THERM_INT_HIGH_ENABLE;
		val.l &= ~THERM_INT_PLN_ENABLE;

Which would be far more readable than the multi-line statement.

drivers/thermal/intel/therm_throt.c void intel_init_thermal(struct cpuinfo_x86 *c) · line 792

Quoted 3 lines
drivers/thermal/intel/therm_throt.c +3 -0
+			val.l = (val.l | PACKAGE_THERM_INT_LOW_ENABLE |
+				 PACKAGE_THERM_INT_HIGH_ENABLE) &
+				~PACKAGE_THERM_INT_PLN_ENABLE;

Okay, will change.

Juergen

author maintainer
#4 lore raw

PATCH v2 1/32 thermal/intel: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
V2:
- make bit modifications more readable (Ingo Molnar)

---
 drivers/thermal/intel/intel_tcc.c            | 10 +--
 drivers/thermal/intel/therm_throt.c          | 76 ++++++++++----------
 drivers/thermal/intel/x86_pkg_temp_thermal.c | 32 ++++-----
 3 files changed, 56 insertions(+), 62 deletions(-)
drivers/thermal/intel/intel_tcc.c +5 -5
index 59f70bb5ffa5..d1fa3c63d554 100644
@@ -185,7 +185,7 @@ int intel_tcc_get_tjmax(int cpu)
 	int val, err;
 
 	if (cpu < 0)
-		err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &msrval.l, &msrval.h);
+		err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &msrval.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &msrval.q);
 	if (err)
@@ -212,7 +212,7 @@ int intel_tcc_get_offset(int cpu)
 	int err;
 
 	if (cpu < 0)
-		err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &val.l, &val.h);
+		err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	if (err)
@@ -245,7 +245,7 @@ int intel_tcc_set_offset(int cpu, int offset)
 		return -EINVAL;
 
 	if (cpu < 0)
-		err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &val.l, &val.h);
+		err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	if (err)
@@ -259,7 +259,7 @@ int intel_tcc_set_offset(int cpu, int offset)
 	val.l |= offset << 24;
 
 	if (cpu < 0)
-		return wrmsr_safe(MSR_IA32_TEMPERATURE_TARGET, val.l, val.h);
+		return wrmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, val.q);
 	else
 		return wrmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, val.q);
 }
@@ -288,7 +288,7 @@ int intel_tcc_get_temp(int cpu, int *temp, bool pkg)
 		return tjmax;
 
 	if (cpu < 0)
-		err = rdmsr_safe(msr, &val.l, &val.h);
+		err = rdmsrq_safe(msr, &val.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, msr, &val.q);
 	if (err)
drivers/thermal/intel/therm_throt.c +36 -40

123 lines not on this page · raw message

drivers/thermal/intel/x86_pkg_temp_thermal.c +15 -17
index 688e04c63761..43fd5bdf1d8d 100644
@@ -51,8 +51,7 @@ MODULE_PARM_DESC(notify_delay_ms,
 struct zone_device {
 	int				cpu;
 	bool				work_scheduled;
-	u32				msr_pkg_therm_low;
-	u32				msr_pkg_therm_high;
+	u64				msr_pkg_therm;
 	struct delayed_work		work;
 	struct thermal_zone_device	*tzone;
 	struct cpumask			cpumask;
@@ -186,28 +185,28 @@ static bool pkg_thermal_rate_control(void)
 static inline void enable_pkg_thres_interrupt(void)
 {
 	u8 thres_0, thres_1;
-	u32 l, h;
+	struct msr val;
 
-	rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 	/* only enable/disable if it had valid threshold value */
-	thres_0 = (l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
-	thres_1 = (l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
+	thres_0 = (val.l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
+	thres_1 = (val.l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
 	if (thres_0)
-		l |= THERM_INT_THRESHOLD0_ENABLE;
+		val.l |= THERM_INT_THRESHOLD0_ENABLE;
 	if (thres_1)
-		l |= THERM_INT_THRESHOLD1_ENABLE;
-	wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+		val.l |= THERM_INT_THRESHOLD1_ENABLE;
+	wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 /* Disable threshold interrupt on local package/cpu */
 static inline void disable_pkg_thres_interrupt(void)
 {
-	u32 l, h;
+	struct msr val;
 
-	rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 
-	l &= ~(THERM_INT_THRESHOLD0_ENABLE | THERM_INT_THRESHOLD1_ENABLE);
-	wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	val.l &= ~(THERM_INT_THRESHOLD0_ENABLE | THERM_INT_THRESHOLD1_ENABLE);
+	wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
@@ -357,8 +356,7 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
 		goto out_unregister_tz;
 
 	/* Store MSR value for package thermal interrupt, to restore at exit */
-	rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm_low,
-	      zonedev->msr_pkg_therm_high);
+	rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm);
 
 	cpumask_set_cpu(cpu, &zonedev->cpumask);
 	raw_spin_lock_irq(&pkg_temp_lock);
@@ -426,8 +424,8 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
 	if (lastcpu) {
 		zones[topology_logical_die_id(cpu)] = NULL;
 		/* After this point nothing touches the MSR anymore. */
-		wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
-		      zonedev->msr_pkg_therm_low, zonedev->msr_pkg_therm_high);
+		wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT,
+		       zonedev->msr_pkg_therm);
 	}
 
 	/*
Signature · 1 line
2.54.0
maintainer Acked-by on v2 1/32
#5 lore raw

Re: [PATCH v2 01/32] thermal/intel: Stop using 32-bit MSR interfaces

Quoted 6 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

LGTM

Quoted 267 lines

---
V2:
- make bit modifications more readable (Ingo Molnar)

---
 drivers/thermal/intel/intel_tcc.c            | 10 +--
 drivers/thermal/intel/therm_throt.c          | 76 ++++++++++----------
 drivers/thermal/intel/x86_pkg_temp_thermal.c | 32 ++++-----
 3 files changed, 56 insertions(+), 62 deletions(-)
drivers/thermal/intel/intel_tcc.c +5 -5
index 59f70bb5ffa5..d1fa3c63d554 100644
@@ -185,7 +185,7 @@ int intel_tcc_get_tjmax(int cpu)
        int val, err;
 
        if (cpu < 0)
-               err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &msrval.l, &msrval.h);
+               err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &msrval.q);
        else
                err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &msrval.q);
        if (err)
@@ -212,7 +212,7 @@ int intel_tcc_get_offset(int cpu)
        int err;
 
        if (cpu < 0)
-               err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &val.l, &val.h);
+               err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &val.q);
        else
                err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &val.q);
        if (err)
@@ -245,7 +245,7 @@ int intel_tcc_set_offset(int cpu, int offset)
                return -EINVAL;
 
        if (cpu < 0)
-               err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &val.l, &val.h);
+               err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &val.q);
        else
                err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &val.q);
        if (err)
@@ -259,7 +259,7 @@ int intel_tcc_set_offset(int cpu, int offset)
        val.l |= offset << 24;
 
        if (cpu < 0)
-               return wrmsr_safe(MSR_IA32_TEMPERATURE_TARGET, val.l, val.h);
+               return wrmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, val.q);
        else
                return wrmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, val.q);
 }
@@ -288,7 +288,7 @@ int intel_tcc_get_temp(int cpu, int *temp, bool pkg)
                return tjmax;
 
        if (cpu < 0)
-               err = rdmsr_safe(msr, &val.l, &val.h);
+               err = rdmsrq_safe(msr, &val.q);
        else
                err = rdmsrq_safe_on_cpu(cpu, msr, &val.q);
        if (err)
drivers/thermal/intel/therm_throt.c +36 -40
index 45a8ef4a608b..1dfd4491c9f6 100644
@@ -722,8 +722,8 @@ void __init therm_lvt_init(void)
 void intel_init_thermal(struct cpuinfo_x86 *c)
 {
        unsigned int cpu = smp_processor_id();
+       struct msr val;
        int tm2 = 0;
-       u32 l, h;
 
        if (!intel_thermal_supported(c))
                return;
@@ -733,9 +733,9 @@ void intel_init_thermal(struct cpuinfo_x86 *c)
         * be some SMM goo which handles it, so we can't even put a handler
         * since it might be delivered via SMI already:
         */
-       rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+       rdmsrq(MSR_IA32_MISC_ENABLE, val.q);
 
-       h = lvtthmr_init;
+       val.h = lvtthmr_init;
        /*
         * The initial value of thermal LVT entries on all APs always reads
         * 0x10000 because APs are woken up by BSP issuing INIT-SIPI-SIPI
@@ -746,11 +746,11 @@ void intel_init_thermal(struct cpuinfo_x86 *c)
         * BIOS has programmed on AP based on BSP's info we saved since BIOS
         * is always setting the same value for all threads/cores.
         */
-       if ((h & APIC_DM_FIXED_MASK) != APIC_DM_FIXED)
+       if ((val.h & APIC_DM_FIXED_MASK) != APIC_DM_FIXED)
                apic_write(APIC_LVTTHMR, lvtthmr_init);
 
 
-       if ((l & MSR_IA32_MISC_ENABLE_TM1) && (h & APIC_DM_SMI)) {
+       if ((val.l & MSR_IA32_MISC_ENABLE_TM1) && (val.h & APIC_DM_SMI)) {
                if (system_state == SYSTEM_BOOTING)
                        pr_debug("CPU%d: Thermal monitoring handled by SMI\n", cpu);
                return;
@@ -759,59 +759,55 @@ void intel_init_thermal(struct cpuinfo_x86 *c)
        /* early Pentium M models use different method for enabling TM2 */
        if (cpu_has(c, X86_FEATURE_TM2)) {
                if (c->x86 == 6 && (c->x86_model == 9 || c->x86_model == 13)) {
-                       rdmsr(MSR_THERM2_CTL, l, h);
-                       if (l & MSR_THERM2_CTL_TM_SELECT)
+                       rdmsrq(MSR_THERM2_CTL, val.q);
+                       if (val.l & MSR_THERM2_CTL_TM_SELECT)
                                tm2 = 1;
-               } else if (l & MSR_IA32_MISC_ENABLE_TM2)
+               } else if (val.l & MSR_IA32_MISC_ENABLE_TM2)
                        tm2 = 1;
        }
 
        /* We'll mask the thermal vector in the lapic till we're ready: */
-       h = THERMAL_APIC_VECTOR | APIC_DM_FIXED | APIC_LVT_MASKED;
-       apic_write(APIC_LVTTHMR, h);
+       val.h = THERMAL_APIC_VECTOR | APIC_DM_FIXED | APIC_LVT_MASKED;
+       apic_write(APIC_LVTTHMR, val.h);
 
        thermal_intr_init_core_clear_mask();
        thermal_intr_init_pkg_clear_mask();
 
-       rdmsr(MSR_IA32_THERM_INTERRUPT, l, h);
-       if (cpu_has(c, X86_FEATURE_PLN) && !int_pln_enable)
-               wrmsr(MSR_IA32_THERM_INTERRUPT,
-                       (l | (THERM_INT_LOW_ENABLE
-                       | THERM_INT_HIGH_ENABLE)) & ~THERM_INT_PLN_ENABLE, h);
-       else if (cpu_has(c, X86_FEATURE_PLN) && int_pln_enable)
-               wrmsr(MSR_IA32_THERM_INTERRUPT,
-                       l | (THERM_INT_LOW_ENABLE
-                       | THERM_INT_HIGH_ENABLE | THERM_INT_PLN_ENABLE), h);
+       rdmsrq(MSR_IA32_THERM_INTERRUPT, val.q);
+       if (cpu_has(c, X86_FEATURE_PLN) && !int_pln_enable) {
+               val.l |= THERM_INT_LOW_ENABLE | THERM_INT_HIGH_ENABLE;
+               val.l &= ~THERM_INT_PLN_ENABLE;
+       } else if (cpu_has(c, X86_FEATURE_PLN) && int_pln_enable)
+               val.l |= THERM_INT_LOW_ENABLE | THERM_INT_HIGH_ENABLE |
+                        THERM_INT_PLN_ENABLE;
        else
-               wrmsr(MSR_IA32_THERM_INTERRUPT,
-                     l | (THERM_INT_LOW_ENABLE | THERM_INT_HIGH_ENABLE), h);
+               val.l |= THERM_INT_LOW_ENABLE | THERM_INT_HIGH_ENABLE;
+       wrmsrq(MSR_IA32_THERM_INTERRUPT, val.q);
 
        if (cpu_has(c, X86_FEATURE_PTS)) {
-               rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
-               if (cpu_has(c, X86_FEATURE_PLN) && !int_pln_enable)
-                       wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
-                               (l | (PACKAGE_THERM_INT_LOW_ENABLE
-                               | PACKAGE_THERM_INT_HIGH_ENABLE))
-                               & ~PACKAGE_THERM_INT_PLN_ENABLE, h);
-               else if (cpu_has(c, X86_FEATURE_PLN) && int_pln_enable)
-                       wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
-                               l | (PACKAGE_THERM_INT_LOW_ENABLE
-                               | PACKAGE_THERM_INT_HIGH_ENABLE
-                               | PACKAGE_THERM_INT_PLN_ENABLE), h);
+               rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
+               if (cpu_has(c, X86_FEATURE_PLN) && !int_pln_enable) {
+                       val.l |= PACKAGE_THERM_INT_LOW_ENABLE |
+                                PACKAGE_THERM_INT_HIGH_ENABLE;
+                       val.l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
+               } else if (cpu_has(c, X86_FEATURE_PLN) && int_pln_enable)
+                       val.l |= PACKAGE_THERM_INT_LOW_ENABLE |
+                                PACKAGE_THERM_INT_HIGH_ENABLE |
+                                PACKAGE_THERM_INT_PLN_ENABLE;
                else
-                       wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
-                             l | (PACKAGE_THERM_INT_LOW_ENABLE
-                               | PACKAGE_THERM_INT_HIGH_ENABLE), h);
+                       val.l |= PACKAGE_THERM_INT_LOW_ENABLE |
+                                PACKAGE_THERM_INT_HIGH_ENABLE;
+               wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 
                if (cpu_has(c, X86_FEATURE_HFI)) {
-                       rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
-                       wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
-                             l | PACKAGE_THERM_INT_HFI_ENABLE, h);
+                       rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
+                       wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT,
+                              val.q | PACKAGE_THERM_INT_HFI_ENABLE);
                }
        }
 
-       rdmsr(MSR_IA32_MISC_ENABLE, l, h);
-       wrmsr(MSR_IA32_MISC_ENABLE, l | MSR_IA32_MISC_ENABLE_TM1, h);
+       rdmsrq(MSR_IA32_MISC_ENABLE, val.q);
+       wrmsrq(MSR_IA32_MISC_ENABLE, val.q | MSR_IA32_MISC_ENABLE_TM1);
 
        pr_info_once("CPU0: Thermal monitoring enabled (%s)\n",
                      tm2 ? "TM2" : "TM1");
drivers/thermal/intel/x86_pkg_temp_thermal.c +15 -18
index 688e04c63761..43fd5bdf1d8d 100644
@@ -51,8 +51,7 @@ MODULE_PARM_DESC(notify_delay_ms,
 struct zone_device {
        int                             cpu;
        bool                            work_scheduled;
-       u32                             msr_pkg_therm_low;
-       u32                             msr_pkg_therm_high;
+       u64                             msr_pkg_therm;
        struct delayed_work             work;
        struct thermal_zone_device      *tzone;
        struct cpumask                  cpumask;
@@ -186,28 +185,28 @@ static bool pkg_thermal_rate_control(void)
 static inline void enable_pkg_thres_interrupt(void)
 {
        u8 thres_0, thres_1;
-       u32 l, h;
+       struct msr val;
 
-       rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+       rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
        /* only enable/disable if it had valid threshold value */
-       thres_0 = (l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
-       thres_1 = (l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
+       thres_0 = (val.l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
+       thres_1 = (val.l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
        if (thres_0)
-               l |= THERM_INT_THRESHOLD0_ENABLE;
+               val.l |= THERM_INT_THRESHOLD0_ENABLE;
        if (thres_1)
-               l |= THERM_INT_THRESHOLD1_ENABLE;
-       wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+               val.l |= THERM_INT_THRESHOLD1_ENABLE;
+       wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 /* Disable threshold interrupt on local package/cpu */
 static inline void disable_pkg_thres_interrupt(void)
 {
-       u32 l, h;
+       struct msr val;
 
-       rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+       rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 
-       l &= ~(THERM_INT_THRESHOLD0_ENABLE | THERM_INT_THRESHOLD1_ENABLE);
-       wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+       val.l &= ~(THERM_INT_THRESHOLD0_ENABLE | THERM_INT_THRESHOLD1_ENABLE);
+       wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
@@ -357,8 +356,7 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
                goto out_unregister_tz;
 
        /* Store MSR value for package thermal interrupt, to restore at exit */
-       rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm_low,
-             zonedev->msr_pkg_therm_high);
+       rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm);
 
        cpumask_set_cpu(cpu, &zonedev->cpumask);
        raw_spin_lock_irq(&pkg_temp_lock);
@@ -426,8 +424,8 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
        if (lastcpu) {
                zones[topology_logical_die_id(cpu)] = NULL;
                /* After this point nothing touches the MSR anymore. */
-               wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
-                     zonedev->msr_pkg_therm_low, zonedev->msr_pkg_therm_high);
+               wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT,
+                      zonedev->msr_pkg_therm);
        }
 
        /*
--

2.54.0

merge bot Applied
#6 lore raw

[tip: x86/msr] thermal/intel: Stop using 32-bit MSR interfaces

In reply to Juergen Gross
The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     cdf3ab55a9b95e7ac847177920d3e03ae4cf8b93
Gitweb:        https://git.kernel.org/tip/cdf3ab55a9b95e7ac847177920d3e03ae4cf8b93
Author:        Juergen Gross <[email protected]>
AuthorDate:    Fri, 03 Jul 2026 13:22:32 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 17 Jul 2026 10:26:49 +02:00

thermal/intel: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/thermal/intel/intel_tcc.c            | 10 +--
 drivers/thermal/intel/therm_throt.c          | 76 +++++++++----------
 drivers/thermal/intel/x86_pkg_temp_thermal.c | 32 +++-----
 3 files changed, 56 insertions(+), 62 deletions(-)
drivers/thermal/intel/intel_tcc.c +5 -5
index 59f70bb..d1fa3c6 100644
@@ -185,7 +185,7 @@ int intel_tcc_get_tjmax(int cpu)
 	int val, err;
 
 	if (cpu < 0)
-		err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &msrval.l, &msrval.h);
+		err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &msrval.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &msrval.q);
 	if (err)
@@ -212,7 +212,7 @@ int intel_tcc_get_offset(int cpu)
 	int err;
 
 	if (cpu < 0)
-		err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &val.l, &val.h);
+		err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	if (err)
@@ -245,7 +245,7 @@ int intel_tcc_set_offset(int cpu, int offset)
 		return -EINVAL;
 
 	if (cpu < 0)
-		err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &val.l, &val.h);
+		err = rdmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &val.q);
 	if (err)
@@ -259,7 +259,7 @@ int intel_tcc_set_offset(int cpu, int offset)
 	val.l |= offset << 24;
 
 	if (cpu < 0)
-		return wrmsr_safe(MSR_IA32_TEMPERATURE_TARGET, val.l, val.h);
+		return wrmsrq_safe(MSR_IA32_TEMPERATURE_TARGET, val.q);
 	else
 		return wrmsrq_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, val.q);
 }
@@ -288,7 +288,7 @@ int intel_tcc_get_temp(int cpu, int *temp, bool pkg)
 		return tjmax;
 
 	if (cpu < 0)
-		err = rdmsr_safe(msr, &val.l, &val.h);
+		err = rdmsrq_safe(msr, &val.q);
 	else
 		err = rdmsrq_safe_on_cpu(cpu, msr, &val.q);
 	if (err)
drivers/thermal/intel/therm_throt.c +36 -40

123 lines not on this page · raw message

drivers/thermal/intel/x86_pkg_temp_thermal.c +15 -17
index 688e04c..43fd5bd 100644
@@ -51,8 +51,7 @@ MODULE_PARM_DESC(notify_delay_ms,
 struct zone_device {
 	int				cpu;
 	bool				work_scheduled;
-	u32				msr_pkg_therm_low;
-	u32				msr_pkg_therm_high;
+	u64				msr_pkg_therm;
 	struct delayed_work		work;
 	struct thermal_zone_device	*tzone;
 	struct cpumask			cpumask;
@@ -186,28 +185,28 @@ static bool pkg_thermal_rate_control(void)
 static inline void enable_pkg_thres_interrupt(void)
 {
 	u8 thres_0, thres_1;
-	u32 l, h;
+	struct msr val;
 
-	rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 	/* only enable/disable if it had valid threshold value */
-	thres_0 = (l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
-	thres_1 = (l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
+	thres_0 = (val.l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
+	thres_1 = (val.l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
 	if (thres_0)
-		l |= THERM_INT_THRESHOLD0_ENABLE;
+		val.l |= THERM_INT_THRESHOLD0_ENABLE;
 	if (thres_1)
-		l |= THERM_INT_THRESHOLD1_ENABLE;
-	wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+		val.l |= THERM_INT_THRESHOLD1_ENABLE;
+	wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 /* Disable threshold interrupt on local package/cpu */
 static inline void disable_pkg_thres_interrupt(void)
 {
-	u32 l, h;
+	struct msr val;
 
-	rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 
-	l &= ~(THERM_INT_THRESHOLD0_ENABLE | THERM_INT_THRESHOLD1_ENABLE);
-	wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	val.l &= ~(THERM_INT_THRESHOLD0_ENABLE | THERM_INT_THRESHOLD1_ENABLE);
+	wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
@@ -357,8 +356,7 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
 		goto out_unregister_tz;
 
 	/* Store MSR value for package thermal interrupt, to restore at exit */
-	rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm_low,
-	      zonedev->msr_pkg_therm_high);
+	rdmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm);
 
 	cpumask_set_cpu(cpu, &zonedev->cpumask);
 	raw_spin_lock_irq(&pkg_temp_lock);
@@ -426,8 +424,8 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
 	if (lastcpu) {
 		zones[topology_logical_die_id(cpu)] = NULL;
 		/* After this point nothing touches the MSR anymore. */
-		wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
-		      zonedev->msr_pkg_therm_low, zonedev->msr_pkg_therm_high);
+		wrmsrq(MSR_IA32_PACKAGE_THERM_INTERRUPT,
+		       zonedev->msr_pkg_therm);
 	}
 
 	/*
author maintainer
#7 lore raw

PATCH 2/32 powercap: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

Drop a pointless initializer.

---
 drivers/powercap/intel_rapl_common.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/powercap/intel_rapl_common.c +10 -10
index 1006d183d508..3cee4ccb7997 100644
@@ -752,17 +752,17 @@ EXPORT_SYMBOL_NS_GPL(rapl_default_check_unit, "INTEL_RAPL");
 
 static void power_limit_irq_save_cpu(void *info)
 {
-	u32 l, h = 0;
+	struct msr val;
 	struct rapl_package *rp = (struct rapl_package *)info;
 
 	/* save the state of PLN irq mask bit before disabling it */
-	rdmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &l, &h);
+	rdmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &val.q);
 	if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED)) {
-		rp->power_limit_irq = l & PACKAGE_THERM_INT_PLN_ENABLE;
+		rp->power_limit_irq = val.l & PACKAGE_THERM_INT_PLN_ENABLE;
 		rp->power_limit_irq |= PACKAGE_PLN_INT_SAVED;
 	}
-	l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
-	wrmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	val.l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
+	wrmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 /* REVISIT:
@@ -792,7 +792,7 @@ static void package_power_limit_irq_save(struct rapl_package *rp)
  */
 static void package_power_limit_irq_restore(struct rapl_package *rp)
 {
-	u32 l, h;
+	struct msr val;
 
 	if (rp->lead_cpu < 0)
 		return;
@@ -804,14 +804,14 @@ static void package_power_limit_irq_restore(struct rapl_package *rp)
 	if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED))
 		return;
 
-	rdmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &l, &h);
+	rdmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &val.q);
 
 	if (rp->power_limit_irq & PACKAGE_THERM_INT_PLN_ENABLE)
-		l |= PACKAGE_THERM_INT_PLN_ENABLE;
+		val.l |= PACKAGE_THERM_INT_PLN_ENABLE;
 	else
-		l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
+		val.l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
 
-	wrmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	wrmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 void rapl_default_set_floor_freq(struct rapl_domain *rd, bool mode)
Signature · 1 line
2.54.0
#8 lore raw

Re: [PATCH 02/32] powercap: Stop using 32-bit MSR interfaces

Quoted 4 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

Drop a pointless initializer.

Was the initializer really 'pointless'? IIRC it suppressed a build warning on 32-bit builds, at least in some past iterations of these APIs.

So maybe this should say: 'Drop initializer that became pointless'?

Thanks,

Ingo

author maintainer
#9 lore raw

Re: [PATCH 02/32] powercap: Stop using 32-bit MSR interfaces

Quoted 10 lines · Ingo Molnar
Quoted 4 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

Drop a pointless initializer.

Was the initializer really 'pointless'? IIRC it suppressed a build warning on 32-bit builds, at least in some past iterations of these APIs.

I don't see the connection to 32-bit builds. Either the uninitialized variable is a problem or not. And I don't see why "l" didn't need an initial value (it is modified in this function only via a "&=" operation, so some bits would still be random in case it is seen not to be set by rdmsr_safe()).

In reality it should never be a problem, as rdmsr_safe() will always set both output variables to a value (0 in case of error, MSR contents else).

Quoted 2 lines

So maybe this should say: 'Drop initializer that became pointless'?

I don't think so.

Juergen

#10 lore raw

Re: [PATCH 02/32] powercap: Stop using 32-bit MSR interfaces

Quoted 12 lines · Jürgen Groß
Quoted 10 lines · Ingo Molnar
Quoted 4 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

Drop a pointless initializer.

Was the initializer really 'pointless'? IIRC it suppressed a build warning on 32-bit builds, at least in some past iterations of these APIs.

Quoted 7 lines

I don't see the connection to 32-bit builds. Either the uninitialized variable is a problem or not. And I don't see why "l" didn't need an initial value (it is modified in this function only via a "&=" operation, so some bits would still be random in case it is seen not to be set by rdmsr_safe()).

In reality it should never be a problem, as rdmsr_safe() will always set both output variables to a value (0 in case of error, MSR contents else).

So it's not rdmsr_safe() but rdmsr(), but we had this:

10a5d65856b9 ("x86/process: Convert rdmsr() to rdmsrq() in arch_post_acpi_subsys_init() to address W=1 warning")

Which addressed this W=1 warning:

arch/x86/kernel/process.c: In function 'arch_post_acpi_subsys_init':
arch/x86/kernel/process.c:972:17: warning: variable 'hi' set but not used

By the pattern the 'pointless' hi=0 initialization looks similar and may not be as pointless as it seems. :-)

Thanks,

Ingo

author maintainer
#11 lore raw

Re: [PATCH 02/32] powercap: Stop using 32-bit MSR interfaces

Quoted 27 lines · Ingo Molnar
Quoted 12 lines · Jürgen Groß
Quoted 10 lines · Ingo Molnar
Quoted 4 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

Drop a pointless initializer.

Was the initializer really 'pointless'? IIRC it suppressed a build warning on 32-bit builds, at least in some past iterations of these APIs.

Quoted 7 lines

I don't see the connection to 32-bit builds. Either the uninitialized variable is a problem or not. And I don't see why "l" didn't need an initial value (it is modified in this function only via a "&=" operation, so some bits would still be random in case it is seen not to be set by rdmsr_safe()).

In reality it should never be a problem, as rdmsr_safe() will always set both output variables to a value (0 in case of error, MSR contents else).

So it's not rdmsr_safe() but rdmsr(), but we had this:

   10a5d65856b9 ("x86/process: Convert rdmsr() to rdmsrq() in arch_post_acpi_subsys_init() to address W=1 warning")
Quoted 7 lines

Which addressed this W=1 warning:

arch/x86/kernel/process.c: In function 'arch_post_acpi_subsys_init':
arch/x86/kernel/process.c:972:17: warning: variable 'hi' set but not used

By the pattern the 'pointless' hi=0 initialization looks similar and may not be as pointless as it seems. :-)

Maybe I'm not getting something here, but 10a5d65856b9 was not about a missing initializer, but about "hi" just not being consumed after setting it. "hi" wasn't initialized before 10a5d65856b9 and it was removed by this commit.

I don't see how a pointless initializer would help in such a case.

It would mean that setting a variable twice fixes a "variable set but not used" warning, which sounds a little bit weird.

BTW, the "hi=0" initializer was added _before_ rdmsr() would return with the value being set in case of an error. So at the time of the patch setting hi to 0 it was correct, but this reason vanished only 2 months later.

Juergen

maintainer Acked-by on v1 2/32
#12 lore raw

Re: [PATCH 02/32] powercap: Stop using 32-bit MSR interfaces

In reply to Juergen Gross
Quoted 7 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

Drop a pointless initializer.

LGTM

Quoted 63 lines
---
 drivers/powercap/intel_rapl_common.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/powercap/intel_rapl_common.c +10 -11
index 1006d183d508..3cee4ccb7997 100644
@@ -752,17 +752,17 @@ EXPORT_SYMBOL_NS_GPL(rapl_default_check_unit, "INTEL_RAPL");
 
 static void power_limit_irq_save_cpu(void *info)
 {
-       u32 l, h = 0;
+       struct msr val;
        struct rapl_package *rp = (struct rapl_package *)info;
 
        /* save the state of PLN irq mask bit before disabling it */
-       rdmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &l, &h);
+       rdmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &val.q);
        if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED)) {
-               rp->power_limit_irq = l & PACKAGE_THERM_INT_PLN_ENABLE;
+               rp->power_limit_irq = val.l & PACKAGE_THERM_INT_PLN_ENABLE;
                rp->power_limit_irq |= PACKAGE_PLN_INT_SAVED;
        }
-       l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
-       wrmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+       val.l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
+       wrmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 /* REVISIT:
@@ -792,7 +792,7 @@ static void package_power_limit_irq_save(struct rapl_package *rp)
  */
 static void package_power_limit_irq_restore(struct rapl_package *rp)
 {
-       u32 l, h;
+       struct msr val;
 
        if (rp->lead_cpu < 0)
                return;
@@ -804,14 +804,14 @@ static void package_power_limit_irq_restore(struct rapl_package *rp)
        if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED))
                return;
 
-       rdmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &l, &h);
+       rdmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &val.q);
 
        if (rp->power_limit_irq & PACKAGE_THERM_INT_PLN_ENABLE)
-               l |= PACKAGE_THERM_INT_PLN_ENABLE;
+               val.l |= PACKAGE_THERM_INT_PLN_ENABLE;
        else
-               l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
+               val.l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
 
-       wrmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+       wrmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 void rapl_default_set_floor_freq(struct rapl_domain *rd, bool mode)
--

2.54.0

merge bot Applied
#13 lore raw

[tip: x86/msr] powercap: Stop using 32-bit MSR interfaces

In reply to Juergen Gross
The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     f0a1575221d1bb45d8548a3fbc49a1a3bfaea24d
Gitweb:        https://git.kernel.org/tip/f0a1575221d1bb45d8548a3fbc49a1a3bfaea24d
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:04:53 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 17 Jul 2026 10:26:50 +02:00

powercap: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

Drop a pointless initializer while at it.

---
 drivers/powercap/intel_rapl_common.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/powercap/intel_rapl_common.c +10 -10
index 1006d18..3cee4cc 100644
@@ -752,17 +752,17 @@ EXPORT_SYMBOL_NS_GPL(rapl_default_check_unit, "INTEL_RAPL");
 
 static void power_limit_irq_save_cpu(void *info)
 {
-	u32 l, h = 0;
+	struct msr val;
 	struct rapl_package *rp = (struct rapl_package *)info;
 
 	/* save the state of PLN irq mask bit before disabling it */
-	rdmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &l, &h);
+	rdmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &val.q);
 	if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED)) {
-		rp->power_limit_irq = l & PACKAGE_THERM_INT_PLN_ENABLE;
+		rp->power_limit_irq = val.l & PACKAGE_THERM_INT_PLN_ENABLE;
 		rp->power_limit_irq |= PACKAGE_PLN_INT_SAVED;
 	}
-	l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
-	wrmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	val.l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
+	wrmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 /* REVISIT:
@@ -792,7 +792,7 @@ static void package_power_limit_irq_save(struct rapl_package *rp)
  */
 static void package_power_limit_irq_restore(struct rapl_package *rp)
 {
-	u32 l, h;
+	struct msr val;
 
 	if (rp->lead_cpu < 0)
 		return;
@@ -804,14 +804,14 @@ static void package_power_limit_irq_restore(struct rapl_package *rp)
 	if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED))
 		return;
 
-	rdmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &l, &h);
+	rdmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &val.q);
 
 	if (rp->power_limit_irq & PACKAGE_THERM_INT_PLN_ENABLE)
-		l |= PACKAGE_THERM_INT_PLN_ENABLE;
+		val.l |= PACKAGE_THERM_INT_PLN_ENABLE;
 	else
-		l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
+		val.l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
 
-	wrmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
+	wrmsrq_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, val.q);
 }
 
 void rapl_default_set_floor_freq(struct rapl_domain *rd, bool mode)
author maintainer
#14 lore raw

PATCH 3/32 edac: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/edac/ie31200_edac.c | 10 +++++-----
 drivers/edac/mce_amd.c      |  8 ++++----
 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/edac/ie31200_edac.c +5 -5
index e3bd6436669b..94ab80197c2e 100644
@@ -261,11 +261,11 @@ static void ie31200_clear_error_info(struct mem_ctl_info *mci)
 	 * the ECC error log registers in all memory controllers.
 	 */
 	if (cfg->msr_clear_eccerrlog_offset) {
-		if (wrmsr_safe(cfg->msr_clear_eccerrlog_offset,
-			       cfg->reg_eccerrlog_ce_mask |
-			       cfg->reg_eccerrlog_ce_ovfl_mask |
-			       cfg->reg_eccerrlog_ue_mask |
-			       cfg->reg_eccerrlog_ue_ovfl_mask, 0) < 0)
+		if (wrmsrq_safe(cfg->msr_clear_eccerrlog_offset,
+			        cfg->reg_eccerrlog_ce_mask |
+			        cfg->reg_eccerrlog_ce_ovfl_mask |
+			        cfg->reg_eccerrlog_ue_mask |
+			        cfg->reg_eccerrlog_ue_ovfl_mask) < 0)
 			ie31200_printk(KERN_ERR, "Failed to wrmsr.\n");
 
 		return;
drivers/edac/mce_amd.c +4 -4
index bd252cb3c38e..7aee57a25b68 100644
@@ -806,7 +806,7 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 	struct mce *m = (struct mce *)data;
 	struct mce_hw_err *err = to_mce_hw_err(m);
 	unsigned int fam = x86_family(m->cpuid);
-	u32 mca_config_lo = 0, dummy;
+	u64 mca_config = 0;
 	int ecc;
 
 	if (m->kflags & MCE_HANDLED_CEC)
@@ -826,9 +826,9 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 		((m->status & MCI_STATUS_PCC)	? "PCC"	  : "-"));
 
 	if (boot_cpu_has(X86_FEATURE_SMCA)) {
-		rdmsr_safe(MSR_AMD64_SMCA_MCx_CONFIG(m->bank), &mca_config_lo, &dummy);
+		rdmsrq_safe(MSR_AMD64_SMCA_MCx_CONFIG(m->bank), &mca_config);
 
-		if (mca_config_lo & MCI_CONFIG_MCAX)
+		if (mca_config & MCI_CONFIG_MCAX)
 			pr_cont("|%s", ((m->status & MCI_STATUS_TCC) ? "TCC" : "-"));
 
 		pr_cont("|%s", ((m->status & MCI_STATUS_SYNDV) ? "SyndV" : "-"));
@@ -863,7 +863,7 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 
 		if (m->status & MCI_STATUS_SYNDV) {
 			pr_cont(", Syndrome: 0x%016llx\n", m->synd);
-			if (mca_config_lo & MCI_CONFIG_FRUTEXT) {
+			if (mca_config & MCI_CONFIG_FRUTEXT) {
 				char frutext[17];
 
 				frutext[16] = '\0';
Signature · 1 line
2.54.0
Reviewed-by on v1 3/32
#15 lore raw

RE: [PATCH 03/32] edac: Stop using 32-bit MSR interfaces

Quoted 8 lines

From: Juergen Gross <[email protected]>
Sent: Monday, June 29, 2026 2:05 PM
To: [email protected]; [email protected]
Cc: Juergen Gross <[email protected]>; Jason Baron <[email protected]>; Borislav Petkov <[email protected]>; Luck, Tony <[email protected]>; Yazen Ghannam <[email protected]>
Subject: [PATCH 03/32] edac: Stop using 32-bit MSR interfaces

Quoted 8 lines

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/edac/ie31200_edac.c | 10 +++++-----
 drivers/edac/mce_amd.c      |  8 ++++----
 2 files changed, 9 insertions(+), 9 deletions(-)

For this patch, LGTM.

merge bot Applied
#16 lore raw

[tip: x86/msr] EDAC: Stop using 32-bit MSR interfaces

In reply to Juergen Gross
The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     3e8ca6691e9d6695e36cafa84217bb8b955face1
Gitweb:        https://git.kernel.org/tip/3e8ca6691e9d6695e36cafa84217bb8b955face1
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:04:54 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:53 +02:00

EDAC: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/edac/ie31200_edac.c | 10 +++++-----
 drivers/edac/mce_amd.c      |  8 ++++----
 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/edac/ie31200_edac.c +5 -5
index e3bd643..94ab801 100644
@@ -261,11 +261,11 @@ static void ie31200_clear_error_info(struct mem_ctl_info *mci)
 	 * the ECC error log registers in all memory controllers.
 	 */
 	if (cfg->msr_clear_eccerrlog_offset) {
-		if (wrmsr_safe(cfg->msr_clear_eccerrlog_offset,
-			       cfg->reg_eccerrlog_ce_mask |
-			       cfg->reg_eccerrlog_ce_ovfl_mask |
-			       cfg->reg_eccerrlog_ue_mask |
-			       cfg->reg_eccerrlog_ue_ovfl_mask, 0) < 0)
+		if (wrmsrq_safe(cfg->msr_clear_eccerrlog_offset,
+			        cfg->reg_eccerrlog_ce_mask |
+			        cfg->reg_eccerrlog_ce_ovfl_mask |
+			        cfg->reg_eccerrlog_ue_mask |
+			        cfg->reg_eccerrlog_ue_ovfl_mask) < 0)
 			ie31200_printk(KERN_ERR, "Failed to wrmsr.\n");
 
 		return;
drivers/edac/mce_amd.c +4 -4
index bd252cb..7aee57a 100644
@@ -806,7 +806,7 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 	struct mce *m = (struct mce *)data;
 	struct mce_hw_err *err = to_mce_hw_err(m);
 	unsigned int fam = x86_family(m->cpuid);
-	u32 mca_config_lo = 0, dummy;
+	u64 mca_config = 0;
 	int ecc;
 
 	if (m->kflags & MCE_HANDLED_CEC)
@@ -826,9 +826,9 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 		((m->status & MCI_STATUS_PCC)	? "PCC"	  : "-"));
 
 	if (boot_cpu_has(X86_FEATURE_SMCA)) {
-		rdmsr_safe(MSR_AMD64_SMCA_MCx_CONFIG(m->bank), &mca_config_lo, &dummy);
+		rdmsrq_safe(MSR_AMD64_SMCA_MCx_CONFIG(m->bank), &mca_config);
 
-		if (mca_config_lo & MCI_CONFIG_MCAX)
+		if (mca_config & MCI_CONFIG_MCAX)
 			pr_cont("|%s", ((m->status & MCI_STATUS_TCC) ? "TCC" : "-"));
 
 		pr_cont("|%s", ((m->status & MCI_STATUS_SYNDV) ? "SyndV" : "-"));
@@ -863,7 +863,7 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 
 		if (m->status & MCI_STATUS_SYNDV) {
 			pr_cont(", Syndrome: 0x%016llx\n", m->synd);
-			if (mca_config_lo & MCI_CONFIG_FRUTEXT) {
+			if (mca_config & MCI_CONFIG_FRUTEXT) {
 				char frutext[17];
 
 				frutext[16] = '\0';
author maintainer
#17 lore raw

PATCH 4/32 acpi: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

In processor_throttling.c drop needless initializers.

---
 arch/x86/kernel/acpi/sleep.c        | 20 ++++++++------------
 drivers/acpi/processor_perflib.c    | 11 ++++++-----
 drivers/acpi/processor_throttling.c | 14 ++------------
 3 files changed, 16 insertions(+), 29 deletions(-)
arch/x86/kernel/acpi/sleep.c +8 -12
index 91fa262f0e30..8dfe98784bf9 100644
@@ -61,6 +61,7 @@ int x86_acpi_suspend_lowlevel(void)
 {
 	struct wakeup_header *header =
 		(struct wakeup_header *) __va(real_mode_header->wakeup_header);
+	struct msr val;
 
 	if (header->signature != WAKEUP_HEADER_SIGNATURE) {
 		printk(KERN_ERR "wakeup header does not match\n");
@@ -82,13 +83,10 @@ int x86_acpi_suspend_lowlevel(void)
 	 * with 2-MB L2 Cache and Intel® Processor A100 and A110 on 90
 	 * nm process with 512-KB L2 Cache Specification Update".
 	 */
-	if (!rdmsr_safe(MSR_EFER,
-			&header->pmode_efer_low,
-			&header->pmode_efer_high) &&
-	    !wrmsr_safe(MSR_EFER,
-			header->pmode_efer_low,
-			header->pmode_efer_high))
+	if (!rdmsrq_safe(MSR_EFER, &val.q) && !wrmsrq_safe(MSR_EFER, val.q))
 		header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_EFER);
+	header->pmode_efer_low = val.l;
+	header->pmode_efer_high = val.h;
 #endif /* !CONFIG_64BIT */
 
 	header->pmode_cr0 = read_cr0();
@@ -96,14 +94,12 @@ int x86_acpi_suspend_lowlevel(void)
 		header->pmode_cr4 = __read_cr4();
 		header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_CR4);
 	}
-	if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
-			&header->pmode_misc_en_low,
-			&header->pmode_misc_en_high) &&
-	    !wrmsr_safe(MSR_IA32_MISC_ENABLE,
-			header->pmode_misc_en_low,
-			header->pmode_misc_en_high))
+	if (!rdmsrq_safe(MSR_IA32_MISC_ENABLE, &val.q) &&
+	    !wrmsrq_safe(MSR_IA32_MISC_ENABLE, val.q))
 		header->pmode_behavior |=
 			(1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
+	header->pmode_misc_en_low = val.l;
+	header->pmode_misc_en_high = val.h;
 	header->realmode_flags = acpi_realmode_flags;
 	header->real_magic = 0x12345678;
 
drivers/acpi/processor_perflib.c +6 -5
index fdf55c285c9a..9e25d6124efd 100644
@@ -287,7 +287,8 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr)
  */
 static void amd_fixup_frequency(struct acpi_processor_px *px, int i)
 {
-	u32 hi, lo, fid, did;
+	struct msr val;
+	u32 fid, did;
 	int index = px->control & 0x00000007;
 
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
@@ -295,16 +296,16 @@ static void amd_fixup_frequency(struct acpi_processor_px *px, int i)
 
 	if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) ||
 	    boot_cpu_data.x86 == 0x11) {
-		rdmsr(MSR_AMD_PSTATE_DEF_BASE + index, lo, hi);
+		rdmsrq(MSR_AMD_PSTATE_DEF_BASE + index, val.q);
 		/*
 		 * MSR C001_0064+:
 		 * Bit 63: PstateEn. Read-write. If set, the P-state is valid.
 		 */
-		if (!(hi & BIT(31)))
+		if (!(val.h & BIT(31)))
 			return;
 
-		fid = lo & 0x3f;
-		did = (lo >> 6) & 7;
+		fid = val.l & 0x3f;
+		did = (val.l >> 6) & 7;
 		if (boot_cpu_data.x86 == 0x10)
 			px->core_frequency = (100 * (fid + 0x10)) >> did;
 		else
drivers/acpi/processor_throttling.c +2 -12
index c0f92b93747d..d1605e0ab61f 100644
@@ -698,20 +698,13 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
 #ifdef CONFIG_X86
 static int acpi_throttling_rdmsr(u64 *value)
 {
-	u64 msr_high, msr_low;
-	u64 msr = 0;
 	int ret = -1;
 
 	if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) ||
 		!this_cpu_has(X86_FEATURE_ACPI)) {
 		pr_err("HARDWARE addr space,NOT supported yet\n");
 	} else {
-		msr_low = 0;
-		msr_high = 0;
-		rdmsr_safe(MSR_IA32_THERM_CONTROL,
-			(u32 *)&msr_low, (u32 *) &msr_high);
-		msr = (msr_high << 32) | msr_low;
-		*value = (u64) msr;
+		rdmsrq_safe(MSR_IA32_THERM_CONTROL, value);
 		ret = 0;
 	}
 	return ret;
@@ -720,15 +713,12 @@ static int acpi_throttling_rdmsr(u64 *value)
 static int acpi_throttling_wrmsr(u64 value)
 {
 	int ret = -1;
-	u64 msr;
 
 	if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) ||
 		!this_cpu_has(X86_FEATURE_ACPI)) {
 		pr_err("HARDWARE addr space,NOT supported yet\n");
 	} else {
-		msr = value;
-		wrmsr_safe(MSR_IA32_THERM_CONTROL,
-			msr & 0xffffffff, msr >> 32);
+		wrmsrq_safe(MSR_IA32_THERM_CONTROL, value);
 		ret = 0;
 	}
 	return ret;
Signature · 1 line
2.54.0
#18 lore raw

Re: [PATCH 04/32] acpi: Stop using 32-bit MSR interfaces

Quoted 8 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

In processor_throttling.c drop needless initializers.

LGTM overall.

Do you want me to pick it up or do you prefer to route it along with the rest of the series?

Quoted 136 lines
---
 arch/x86/kernel/acpi/sleep.c        | 20 ++++++++------------
 drivers/acpi/processor_perflib.c    | 11 ++++++-----
 drivers/acpi/processor_throttling.c | 14 ++------------
 3 files changed, 16 insertions(+), 29 deletions(-)
arch/x86/kernel/acpi/sleep.c +8 -12
index 91fa262f0e30..8dfe98784bf9 100644
@@ -61,6 +61,7 @@ int x86_acpi_suspend_lowlevel(void)
 {
        struct wakeup_header *header =
                (struct wakeup_header *) __va(real_mode_header->wakeup_header);
+       struct msr val;
 
        if (header->signature != WAKEUP_HEADER_SIGNATURE) {
                printk(KERN_ERR "wakeup header does not match\n");
@@ -82,13 +83,10 @@ int x86_acpi_suspend_lowlevel(void)
         * with 2-MB L2 Cache and Intel® Processor A100 and A110 on 90
         * nm process with 512-KB L2 Cache Specification Update".
         */
-       if (!rdmsr_safe(MSR_EFER,
-                       &header->pmode_efer_low,
-                       &header->pmode_efer_high) &&
-           !wrmsr_safe(MSR_EFER,
-                       header->pmode_efer_low,
-                       header->pmode_efer_high))
+       if (!rdmsrq_safe(MSR_EFER, &val.q) && !wrmsrq_safe(MSR_EFER, val.q))
                header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_EFER);
+       header->pmode_efer_low = val.l;
+       header->pmode_efer_high = val.h;
 #endif /* !CONFIG_64BIT */
 
        header->pmode_cr0 = read_cr0();
@@ -96,14 +94,12 @@ int x86_acpi_suspend_lowlevel(void)
                header->pmode_cr4 = __read_cr4();
                header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_CR4);
        }
-       if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
-                       &header->pmode_misc_en_low,
-                       &header->pmode_misc_en_high) &&
-           !wrmsr_safe(MSR_IA32_MISC_ENABLE,
-                       header->pmode_misc_en_low,
-                       header->pmode_misc_en_high))
+       if (!rdmsrq_safe(MSR_IA32_MISC_ENABLE, &val.q) &&
+           !wrmsrq_safe(MSR_IA32_MISC_ENABLE, val.q))
                header->pmode_behavior |=
                        (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
+       header->pmode_misc_en_low = val.l;
+       header->pmode_misc_en_high = val.h;
        header->realmode_flags = acpi_realmode_flags;
        header->real_magic = 0x12345678;
 
drivers/acpi/processor_perflib.c +6 -5
index fdf55c285c9a..9e25d6124efd 100644
@@ -287,7 +287,8 @@ static int acpi_processor_get_performance_control(struct acpi_processor *pr)
  */
 static void amd_fixup_frequency(struct acpi_processor_px *px, int i)
 {
-       u32 hi, lo, fid, did;
+       struct msr val;
+       u32 fid, did;
        int index = px->control & 0x00000007;
 
        if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
@@ -295,16 +296,16 @@ static void amd_fixup_frequency(struct acpi_processor_px *px, int i)
 
        if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) ||
            boot_cpu_data.x86 == 0x11) {
-               rdmsr(MSR_AMD_PSTATE_DEF_BASE + index, lo, hi);
+               rdmsrq(MSR_AMD_PSTATE_DEF_BASE + index, val.q);
                /*
                 * MSR C001_0064+:
                 * Bit 63: PstateEn. Read-write. If set, the P-state is valid.
                 */
-               if (!(hi & BIT(31)))
+               if (!(val.h & BIT(31)))
                        return;
 
-               fid = lo & 0x3f;
-               did = (lo >> 6) & 7;
+               fid = val.l & 0x3f;
+               did = (val.l >> 6) & 7;
                if (boot_cpu_data.x86 == 0x10)
                        px->core_frequency = (100 * (fid + 0x10)) >> did;
                else
drivers/acpi/processor_throttling.c +2 -13
index c0f92b93747d..d1605e0ab61f 100644
@@ -698,20 +698,13 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
 #ifdef CONFIG_X86
 static int acpi_throttling_rdmsr(u64 *value)
 {
-       u64 msr_high, msr_low;
-       u64 msr = 0;
        int ret = -1;
 
        if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) ||
                !this_cpu_has(X86_FEATURE_ACPI)) {
                pr_err("HARDWARE addr space,NOT supported yet\n");
        } else {
-               msr_low = 0;
-               msr_high = 0;
-               rdmsr_safe(MSR_IA32_THERM_CONTROL,
-                       (u32 *)&msr_low, (u32 *) &msr_high);
-               msr = (msr_high << 32) | msr_low;
-               *value = (u64) msr;
+               rdmsrq_safe(MSR_IA32_THERM_CONTROL, value);
                ret = 0;
        }
        return ret;
@@ -720,15 +713,12 @@ static int acpi_throttling_rdmsr(u64 *value)
 static int acpi_throttling_wrmsr(u64 value)
 {
        int ret = -1;
-       u64 msr;
 
        if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) ||
                !this_cpu_has(X86_FEATURE_ACPI)) {
                pr_err("HARDWARE addr space,NOT supported yet\n");
        } else {
-               msr = value;
-               wrmsr_safe(MSR_IA32_THERM_CONTROL,
-                       msr & 0xffffffff, msr >> 32);
+               wrmsrq_safe(MSR_IA32_THERM_CONTROL, value);
                ret = 0;
        }
        return ret;
--

2.54.0

author maintainer
#19 lore raw

Re: [PATCH 04/32] acpi: Stop using 32-bit MSR interfaces

Quoted 11 lines · Rafael J. Wysocki (Intel)
Quoted 8 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

In processor_throttling.c drop needless initializers.

LGTM overall.

Thanks.

Quoted 2 lines

Do you want me to pick it up or do you prefer to route it along with the rest of the series?

I'm fine with you picking it up.

Juergen

#20 lore raw

Re: [PATCH 04/32] acpi: Stop using 32-bit MSR interfaces

In reply to Rafael J. Wysocki (Intel)
Quoted 6 lines · Rafael J. Wysocki (Intel)
Quoted 5 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

Quoted 8 lines
Quoted 3 lines

In processor_throttling.c drop needless initializers.

LGTM overall.

Do you want me to pick it up or do you prefer to route it along with the rest of the series?

I'd like to keep this series together if you don't mind, so that followup changes can be done more easily.

Thanks,

Ingo

#21 lore raw

Re: [PATCH 04/32] acpi: Stop using 32-bit MSR interfaces

Quoted 14 lines · Ingo Molnar
Quoted 10 lines · Rafael J. Wysocki (Intel)
Quoted 8 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

In processor_throttling.c drop needless initializers.

Quoted 7 lines
Quoted 4 lines

LGTM overall.

Do you want me to pick it up or do you prefer to route it along with the rest of the series?

I'd like to keep this series together if you don't mind, so that followup changes can be done more easily.

Sure.

I will be assuming that tip will be taking care of this change going forward.

Thanks!

#22 lore raw

Re: [PATCH 04/32] acpi: Stop using 32-bit MSR interfaces

Quoted 20 lines · Rafael J. Wysocki (Intel)
Quoted 19 lines · Ingo Molnar
Quoted 14 lines · Rafael J. Wysocki (Intel)
Quoted 8 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

In processor_throttling.c drop needless initializers.

LGTM overall.

Do you want me to pick it up or do you prefer to route it along with the rest of the series?

Quoted 6 lines
Quoted 2 lines

I'd like to keep this series together if you don't mind, so that followup changes can be done more easily.

Sure.

I will be assuming that tip will be taking care of this change going forward.

Thank you!

Can I also add your Acked-by to these two patches:

[PATCH 01/32] thermal/intel: Stop using 32-bit MSR interfaces [PATCH 02/32] powercap: Stop using 32-bit MSR interfaces

? They both look fine to me.

Thanks,

Ingo

#23 lore raw

Re: [PATCH 04/32] acpi: Stop using 32-bit MSR interfaces

Quoted 31 lines · Ingo Molnar
Quoted 20 lines · Rafael J. Wysocki (Intel)
Quoted 19 lines · Ingo Molnar
Quoted 14 lines · Rafael J. Wysocki (Intel)
Quoted 8 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

In processor_throttling.c drop needless initializers.

LGTM overall.

Do you want me to pick it up or do you prefer to route it along with the rest of the series?

Quoted 6 lines
Quoted 2 lines

I'd like to keep this series together if you don't mind, so that followup changes can be done more easily.

Sure.

I will be assuming that tip will be taking care of this change going forward.

Quoted 8 lines

Thank you!

Can I also add your Acked-by to these two patches:

[PATCH 01/32] thermal/intel: Stop using 32-bit MSR interfaces [PATCH 02/32] powercap: Stop using 32-bit MSR interfaces

? They both look fine to me.

Done.

Please also feel free to add my ACK to the $subject patch.

Thanks!

merge bot Applied
#24 lore raw

[tip: x86/msr] acpi: Stop using 32-bit MSR interfaces

In reply to Juergen Gross
The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     f2309cca1acbfa723a036f1e2ba3bef882ed81aa
Gitweb:        https://git.kernel.org/tip/f2309cca1acbfa723a036f1e2ba3bef882ed81aa
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:04:55 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 17 Jul 2026 10:26:50 +02:00

acpi: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

In processor_throttling.c drop needless initializers.

---
 arch/x86/kernel/acpi/sleep.c        | 20 ++++++++------------
 drivers/acpi/processor_perflib.c    | 11 ++++++-----
 drivers/acpi/processor_throttling.c | 14 ++------------
 3 files changed, 16 insertions(+), 29 deletions(-)
arch/x86/kernel/acpi/sleep.c +8 -12
index 91fa262..8dfe987 100644
@@ -61,6 +61,7 @@ int x86_acpi_suspend_lowlevel(void)
 {
 	struct wakeup_header *header =
 		(struct wakeup_header *) __va(real_mode_header->wakeup_header);
+	struct msr val;
 
 	if (header->signature != WAKEUP_HEADER_SIGNATURE) {
 		printk(KERN_ERR "wakeup header does not match\n");
@@ -82,13 +83,10 @@ int x86_acpi_suspend_lowlevel(void)
 	 * with 2-MB L2 Cache and Intel® Processor A100 and A110 on 90
 	 * nm process with 512-KB L2 Cache Specification Update".
 	 */
-	if (!rdmsr_safe(MSR_EFER,
-			&header->pmode_efer_low,
-			&header->pmode_efer_high) &&
-	    !wrmsr_safe(MSR_EFER,
-			header->pmode_efer_low,
-			header->pmode_efer_high))
+	if (!rdmsrq_safe(MSR_EFER, &val.q) && !wrmsrq_safe(MSR_EFER, val.q))
 		header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_EFER);
+	header->pmode_efer_low = val.l;
+	header->pmode_efer_high = val.h;
 #endif /* !CONFIG_64BIT */
 
 	header->pmode_cr0 = read_cr0();
@@ -96,14 +94,12 @@ int x86_acpi_suspend_lowlevel(void)
 		header->pmode_cr4 = __read_cr4();
 		header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_CR4);
 	}
-	if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
-			&header->pmode_misc_en_low,
-			&header->pmode_misc_en_high) &&
-	    !wrmsr_safe(MSR_IA32_MISC_ENABLE,
-			header->pmode_misc_en_low,
-			header->pmode_misc_en_high))
+	if (!rdmsrq_safe(MSR_IA32_MISC_ENABLE, &val.q) &&
+	    !wrmsrq_safe(MSR_IA32_MISC_ENABLE, val.q))
 		header->pmode_behavior |=
 			(1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
+	header->pmode_misc_en_low = val.l;
+	header->pmode_misc_en_high = val.h;
 	header->realmode_flags = acpi_realmode_flags;
 	header->real_magic = 0x12345678;
 
drivers/acpi/processor_perflib.c +6 -5
index fdf55c2..9e25d61 100644
@@ -287,7 +287,8 @@ end:
  */
 static void amd_fixup_frequency(struct acpi_processor_px *px, int i)
 {
-	u32 hi, lo, fid, did;
+	struct msr val;
+	u32 fid, did;
 	int index = px->control & 0x00000007;
 
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
@@ -295,16 +296,16 @@ static void amd_fixup_frequency(struct acpi_processor_px *px, int i)
 
 	if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) ||
 	    boot_cpu_data.x86 == 0x11) {
-		rdmsr(MSR_AMD_PSTATE_DEF_BASE + index, lo, hi);
+		rdmsrq(MSR_AMD_PSTATE_DEF_BASE + index, val.q);
 		/*
 		 * MSR C001_0064+:
 		 * Bit 63: PstateEn. Read-write. If set, the P-state is valid.
 		 */
-		if (!(hi & BIT(31)))
+		if (!(val.h & BIT(31)))
 			return;
 
-		fid = lo & 0x3f;
-		did = (lo >> 6) & 7;
+		fid = val.l & 0x3f;
+		did = (val.l >> 6) & 7;
 		if (boot_cpu_data.x86 == 0x10)
 			px->core_frequency = (100 * (fid + 0x10)) >> did;
 		else
drivers/acpi/processor_throttling.c +2 -12
index c0f92b9..d1605e0 100644
@@ -698,20 +698,13 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
 #ifdef CONFIG_X86
 static int acpi_throttling_rdmsr(u64 *value)
 {
-	u64 msr_high, msr_low;
-	u64 msr = 0;
 	int ret = -1;
 
 	if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) ||
 		!this_cpu_has(X86_FEATURE_ACPI)) {
 		pr_err("HARDWARE addr space,NOT supported yet\n");
 	} else {
-		msr_low = 0;
-		msr_high = 0;
-		rdmsr_safe(MSR_IA32_THERM_CONTROL,
-			(u32 *)&msr_low, (u32 *) &msr_high);
-		msr = (msr_high << 32) | msr_low;
-		*value = (u64) msr;
+		rdmsrq_safe(MSR_IA32_THERM_CONTROL, value);
 		ret = 0;
 	}
 	return ret;
@@ -720,15 +713,12 @@ static int acpi_throttling_rdmsr(u64 *value)
 static int acpi_throttling_wrmsr(u64 value)
 {
 	int ret = -1;
-	u64 msr;
 
 	if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) ||
 		!this_cpu_has(X86_FEATURE_ACPI)) {
 		pr_err("HARDWARE addr space,NOT supported yet\n");
 	} else {
-		msr = value;
-		wrmsr_safe(MSR_IA32_THERM_CONTROL,
-			msr & 0xffffffff, msr >> 32);
+		wrmsrq_safe(MSR_IA32_THERM_CONTROL, value);
 		ret = 0;
 	}
 	return ret;
author maintainer
#25 lore raw

PATCH 5/32 x86/mtrr: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/mtrr/amd.c     | 36 ++++++-----
 arch/x86/kernel/cpu/mtrr/centaur.c | 18 +++---
 arch/x86/kernel/cpu/mtrr/cleanup.c | 18 +++---
 arch/x86/kernel/cpu/mtrr/generic.c | 97 ++++++++++++++++--------------
 arch/x86/kernel/cpu/mtrr/mtrr.c    |  4 +-
 5 files changed, 93 insertions(+), 80 deletions(-)
arch/x86/kernel/cpu/mtrr/amd.c +21 -15
index ef3e8e42b782..fad93cbf6869 100644
@@ -10,20 +10,23 @@ static void
 amd_get_mtrr(unsigned int reg, unsigned long *base,
 	     unsigned long *size, mtrr_type *type)
 {
-	unsigned long low, high;
+	unsigned long val;
+	struct msr msr;
 
-	rdmsr(MSR_K6_UWCCR, low, high);
+	rdmsrq(MSR_K6_UWCCR, msr.q);
 	/* Upper dword is region 1, lower is region 0 */
 	if (reg == 1)
-		low = high;
+		val = msr.h;
+	else
+		val = msr.l;
 	/* The base masks off on the right alignment */
-	*base = (low & 0xFFFE0000) >> PAGE_SHIFT;
+	*base = (val & 0xFFFE0000) >> PAGE_SHIFT;
 	*type = 0;
-	if (low & 1)
+	if (val & 1)
 		*type = MTRR_TYPE_UNCACHABLE;
-	if (low & 2)
+	if (val & 2)
 		*type = MTRR_TYPE_WRCOMB;
-	if (!(low & 3)) {
+	if (!(val & 3)) {
 		*size = 0;
 		return;
 	}
@@ -42,8 +45,8 @@ amd_get_mtrr(unsigned int reg, unsigned long *base,
 	 * +1              000 0000 0000 0100
 	 * *128K   ...
 	 */
-	low = (~low) & 0x1FFFC;
-	*size = (low + 4) << (15 - PAGE_SHIFT);
+	val = (~val) & 0x1FFFC;
+	*size = (val + 4) << (15 - PAGE_SHIFT);
 }
 
 /**
@@ -59,17 +62,20 @@ amd_get_mtrr(unsigned int reg, unsigned long *base,
 static void
 amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type)
 {
-	u32 regs[2];
+	union {
+		u32 regs[2];
+		u64 val;
+	} msr;
 
 	/*
 	 * Low is MTRR0, High MTRR 1
 	 */
-	rdmsr(MSR_K6_UWCCR, regs[0], regs[1]);
+	rdmsrq(MSR_K6_UWCCR, msr.val);
 	/*
 	 * Blank to disable
 	 */
 	if (size == 0) {
-		regs[reg] = 0;
+		msr.regs[reg] = 0;
 	} else {
 		/*
 		 * Set the register to the base, the type (off by one) and an
@@ -80,8 +86,8 @@ amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type
 		 *
 		 *  But ~(x - 1) == ~x + 1 == -x. Two's complement rocks!
 		 */
-		regs[reg] = (-size >> (15 - PAGE_SHIFT) & 0x0001FFFC)
-		    | (base << PAGE_SHIFT) | (type + 1);
+		msr.regs[reg] = (-size >> (15 - PAGE_SHIFT) & 0x0001FFFC)
+				| (base << PAGE_SHIFT) | (type + 1);
 	}
 
 	/*
@@ -89,7 +95,7 @@ amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type
 	 * disable local interrupts, write back the cache, set the mtrr
 	 */
 	wbinvd();
-	wrmsr(MSR_K6_UWCCR, regs[0], regs[1]);
+	wrmsrq(MSR_K6_UWCCR, msr.val);
 }
 
 static int
arch/x86/kernel/cpu/mtrr/centaur.c +9 -9
index 6f6c3ae92943..e32cca1caf59 100644
@@ -65,26 +65,26 @@ static void
 centaur_set_mcr(unsigned int reg, unsigned long base,
 		unsigned long size, mtrr_type type)
 {
-	unsigned long low, high;
+	struct msr val;
 
 	if (size == 0) {
 		/* Disable */
-		high = low = 0;
+		val.q = 0;
 	} else {
-		high = base << PAGE_SHIFT;
+		val.h = base << PAGE_SHIFT;
 		if (centaur_mcr_type == 0) {
 			/* Only support write-combining... */
-			low = -size << PAGE_SHIFT | 0x1f;
+			val.l = -size << PAGE_SHIFT | 0x1f;
 		} else {
 			if (type == MTRR_TYPE_UNCACHABLE)
-				low = -size << PAGE_SHIFT | 0x02; /* NC */
+				val.l = -size << PAGE_SHIFT | 0x02; /* NC */
 			else
-				low = -size << PAGE_SHIFT | 0x09; /* WWO, WC */
+				val.l = -size << PAGE_SHIFT | 0x09; /* WWO, WC */
 		}
 	}
-	centaur_mcr[reg].high = high;
-	centaur_mcr[reg].low = low;
-	wrmsr(MSR_IDT_MCR0 + reg, low, high);
+	centaur_mcr[reg].high = val.h;
+	centaur_mcr[reg].low = val.l;
+	wrmsrq(MSR_IDT_MCR0 + reg, val.q);
 }
 
 static int
arch/x86/kernel/cpu/mtrr/cleanup.c +9 -9
index e3eee9ae4141..cd1a6dec4064 100644
@@ -658,8 +658,8 @@ static int __init mtrr_search_optimal_index(void)
 int __init mtrr_cleanup(void)
 {
 	unsigned long x_remove_base, x_remove_size;
-	unsigned long base, size, def, dummy;
-	u64 chunk_size, gran_size;
+	u64 def, chunk_size, gran_size;
+	unsigned long base, size;
 	mtrr_type type;
 	int index_good;
 	int i;
@@ -670,7 +670,7 @@ int __init mtrr_cleanup(void)
 	if (!cpu_feature_enabled(X86_FEATURE_MTRR) || enable_mtrr_cleanup < 1)
 		return 0;
 
-	rdmsr(MSR_MTRRdefType, def, dummy);
+	rdmsrq(MSR_MTRRdefType, def);
 	def &= 0xff;
 	if (def != MTRR_TYPE_UNCACHABLE)
 		return 0;
@@ -806,7 +806,7 @@ early_param("disable_mtrr_trim", disable_mtrr_trim_setup);
 
 int __init amd_special_default_mtrr(void)
 {
-	u32 l, h;
+	u64 q;
 
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
 	    boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
@@ -814,13 +814,13 @@ int __init amd_special_default_mtrr(void)
 	if (boot_cpu_data.x86 < 0xf)
 		return 0;
 	/* In case some hypervisor doesn't pass SYSCFG through: */
-	if (rdmsr_safe(MSR_AMD64_SYSCFG, &l, &h) < 0)
+	if (rdmsrq_safe(MSR_AMD64_SYSCFG, &q) < 0)
 		return 0;
 	/*
 	 * Memory between 4GB and top of mem is forced WB by this magic bit.
 	 * Reserved before K8RevF, but should be zero there.
 	 */
-	if ((l & (Tom2Enabled | Tom2ForceMemTypeWB)) ==
+	if ((q & (Tom2Enabled | Tom2ForceMemTypeWB)) ==
 		 (Tom2Enabled | Tom2ForceMemTypeWB))
 		return 1;
 	return 0;
@@ -854,9 +854,9 @@ real_trim_memory(unsigned long start_pfn, unsigned long limit_pfn)
  */
 int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 {
-	unsigned long i, base, size, highest_pfn = 0, def, dummy;
+	unsigned long i, base, size, highest_pfn = 0;
 	mtrr_type type;
-	u64 total_trim_size;
+	u64 def, total_trim_size;
 	/* extra one for all 0 */
 	int num[MTRR_NUM_TYPES + 1];
 
@@ -870,7 +870,7 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 	if (!cpu_feature_enabled(X86_FEATURE_MTRR) || disable_mtrr_trim)
 		return 0;
 
-	rdmsr(MSR_MTRRdefType, def, dummy);
+	rdmsrq(MSR_MTRRdefType, def);
 	def &= MTRR_DEF_TYPE_TYPE;
 	if (def != MTRR_TYPE_UNCACHABLE)
 		return 0;
arch/x86/kernel/cpu/mtrr/generic.c +52 -45

219 lines not on this page · raw message

arch/x86/kernel/cpu/mtrr/mtrr.c +2 -2
index 4b3d492afe17..468c53b20acf 100644
@@ -547,7 +547,7 @@ void __init mtrr_bp_init(void)
 {
 	bool generic_mtrrs = cpu_feature_enabled(X86_FEATURE_MTRR);
 	const char *why = "(not available)";
-	unsigned long config, dummy;
+	unsigned long config;
 
 	phys_hi_rsvd = GENMASK(31, boot_cpu_data.x86_phys_bits - 32);
 
@@ -571,7 +571,7 @@ void __init mtrr_bp_init(void)
 	if (mtrr_enabled()) {
 		/* Get the number of variable MTRR ranges. */
 		if (mtrr_if == &generic_mtrr_ops)
-			rdmsr(MSR_MTRRcap, config, dummy);
+			rdmsrq(MSR_MTRRcap, config);
 		else
 			config = mtrr_if->var_regs;
 		num_var_ranges = config & MTRR_CAP_VCNT;
Signature · 1 line
2.54.0
#26 lore raw

Re: [PATCH 05/32] x86/mtrr: Stop using 32-bit MSR interfaces

arch/x86/kernel/cpu/mtrr/amd.c static void · line 14

Quoted 6 lines · Juergen Gross

amd_get_mtrr(unsigned int reg, unsigned long *base,

arch/x86/kernel/cpu/mtrr/amd.c +2 -1
 	     unsigned long *size, mtrr_type *type)
 {
-	unsigned long low, high;
+	unsigned long val;
+	struct msr msr;

So, 'struct msr' is defined in <asm/msr.h>, but:

arch/x86/kernel/cpu/mtrr/amd.c amd_get_mtrr(unsigned int reg, unsigned long *base, · line 68

Quoted 8 lines

static void
amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type) {

arch/x86/kernel/cpu/mtrr/amd.c +4 -1
-	u32 regs[2];
+	union {
+		u32 regs[2];
+		u64 val;
+	} msr;

Why do we use a local anonymous union here with overlapping nomenclature and a confusingly different but (AFAICS) functionally equivalent definition to 'struct msr'?

Thanks,

Ingo

author maintainer
#27 lore raw

Re: [PATCH 05/32] x86/mtrr: Stop using 32-bit MSR interfaces

Quoted 12 lines · Ingo Molnar

arch/x86/kernel/cpu/mtrr/amd.c static void · line 14

Quoted 6 lines · Juergen Gross

amd_get_mtrr(unsigned int reg, unsigned long *base,
unsigned long *size, mtrr_type *type)
{

arch/x86/kernel/cpu/mtrr/amd.c +2 -1
-	unsigned long low, high;
+	unsigned long val;
+	struct msr msr;

So, 'struct msr' is defined in <asm/msr.h>, but:

Quoted 12 lines

arch/x86/kernel/cpu/mtrr/amd.c amd_get_mtrr(unsigned int reg, unsigned long *base, · line 68

Quoted 8 lines

static void
amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type) {

arch/x86/kernel/cpu/mtrr/amd.c +4 -1
-	u32 regs[2];
+	union {
+		u32 regs[2];
+		u64 val;
+	} msr;

Why do we use a local anonymous union here with overlapping nomenclature and a confusingly different but (AFAICS) functionally equivalent definition to 'struct msr'?

This is done in order to avoid having to change the code too much. As an alternative I could use struct msr by doing:

  rdmsrq(MSR_K6_UWCCR, msr.q);
  regs[0] = msr.l;
  regs[1] = msr.h;

...

  msr.l = regs[0];
  msr.h = regs[1];
  wrmsrq(MSR_K6_UWCCR, msr.q);

Juergen

#28 lore raw

Re: [PATCH 05/32] x86/mtrr: Stop using 32-bit MSR interfaces

Quoted 26 lines · Jürgen Groß
Quoted 12 lines · Ingo Molnar

arch/x86/kernel/cpu/mtrr/amd.c static void · line 14

Quoted 6 lines · Juergen Gross

amd_get_mtrr(unsigned int reg, unsigned long *base,
unsigned long *size, mtrr_type *type)
{

arch/x86/kernel/cpu/mtrr/amd.c +2 -1
-	unsigned long low, high;
+	unsigned long val;
+	struct msr msr;

So, 'struct msr' is defined in <asm/msr.h>, but:

Quoted 12 lines

arch/x86/kernel/cpu/mtrr/amd.c amd_get_mtrr(unsigned int reg, unsigned long *base, · line 68

Quoted 8 lines

static void
amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type) {

arch/x86/kernel/cpu/mtrr/amd.c +4 -1
-	u32 regs[2];
+	union {
+		u32 regs[2];
+		u64 val;
+	} msr;

Why do we use a local anonymous union here with overlapping nomenclature and a confusingly different but (AFAICS) functionally equivalent definition to 'struct msr'?

Quoted 1 line

This is done in order to avoid having to change the code too much.

That's OK, but I'd suggest a followup cleanup in a separate patch:

Quoted 11 lines

alternative I could use struct msr by doing:

  rdmsrq(MSR_K6_UWCCR, msr.q);
  regs[0] = msr.l;
  regs[1] = msr.h;

...

  msr.l = regs[0];
  msr.h = regs[1];
  wrmsrq(MSR_K6_UWCCR, msr.q);

Or just move regs[] over to a struct msr variable use?

Thanks,

Ingo

author maintainer
#29 lore raw

Re: [PATCH 05/32] x86/mtrr: Stop using 32-bit MSR interfaces

Quoted 29 lines · Ingo Molnar
Quoted 26 lines · Jürgen Groß
Quoted 24 lines · Ingo Molnar

arch/x86/kernel/cpu/mtrr/amd.c static void · line 14

Quoted 6 lines · Juergen Gross

amd_get_mtrr(unsigned int reg, unsigned long *base,
unsigned long *size, mtrr_type *type)
{

arch/x86/kernel/cpu/mtrr/amd.c +2 -1
-	unsigned long low, high;
+	unsigned long val;
+	struct msr msr;

So, 'struct msr' is defined in <asm/msr.h>, but:

arch/x86/kernel/cpu/mtrr/amd.c amd_get_mtrr(unsigned int reg, unsigned long *base, · line 68

Quoted 8 lines

static void
amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type) {

arch/x86/kernel/cpu/mtrr/amd.c +4 -1
-	u32 regs[2];
+	union {
+		u32 regs[2];
+		u64 val;
+	} msr;

Why do we use a local anonymous union here with overlapping nomenclature and a confusingly different but (AFAICS) functionally equivalent definition to 'struct msr'?

Quoted 15 lines
Quoted 1 line

This is done in order to avoid having to change the code too much.

That's OK, but I'd suggest a followup cleanup in a separate patch:

Quoted 11 lines

alternative I could use struct msr by doing:

   rdmsrq(MSR_K6_UWCCR, msr.q);
   regs[0] = msr.l;
   regs[1] = msr.h;
   ...

   msr.l = regs[0];
   msr.h = regs[1];
   wrmsrq(MSR_K6_UWCCR, msr.q);

I think it would be easier to just use that initially. I can change the patch accordingly.

Quoted 1 line

Or just move regs[] over to a struct msr variable use?

That would be nasty, as the index used for addressing the correct regs[] member is _calculated_, so for each access there would need to be an "if".

Juergen

#30 lore raw

Re: [PATCH 05/32] x86/mtrr: Stop using 32-bit MSR interfaces

Quoted 12 lines · Jürgen Groß
Quoted 11 lines
Quoted 11 lines

alternative I could use struct msr by doing:

   rdmsrq(MSR_K6_UWCCR, msr.q);
   regs[0] = msr.l;
   regs[1] = msr.h;
   ...

   msr.l = regs[0];
   msr.h = regs[1];
   wrmsrq(MSR_K6_UWCCR, msr.q);
Quoted 7 lines

I think it would be easier to just use that initially. I can change the patch accordingly.

Quoted 1 line

Or just move regs[] over to a struct msr variable use?

That would be nasty, as the index used for addressing the correct regs[] member is _calculated_, so for each access there would need to be an "if".

Ok, fair enough.

Thanks,

Ingo

author maintainer
#31 lore raw

PATCH v2 5/32 x86/mtrr: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
V2:
- use struct msr instead of anonymous union (Ingo Molnar)

---
 arch/x86/kernel/cpu/mtrr/amd.c     | 31 ++++++----
 arch/x86/kernel/cpu/mtrr/centaur.c | 18 +++---
 arch/x86/kernel/cpu/mtrr/cleanup.c | 18 +++---
 arch/x86/kernel/cpu/mtrr/generic.c | 97 ++++++++++++++++--------------
 arch/x86/kernel/cpu/mtrr/mtrr.c    |  4 +-
 5 files changed, 92 insertions(+), 76 deletions(-)
arch/x86/kernel/cpu/mtrr/amd.c +20 -11
index ef3e8e42b782..a73715d6f05c 100644
@@ -10,20 +10,23 @@ static void
 amd_get_mtrr(unsigned int reg, unsigned long *base,
 	     unsigned long *size, mtrr_type *type)
 {
-	unsigned long low, high;
+	unsigned long val;
+	struct msr msr;
 
-	rdmsr(MSR_K6_UWCCR, low, high);
+	rdmsrq(MSR_K6_UWCCR, msr.q);
 	/* Upper dword is region 1, lower is region 0 */
 	if (reg == 1)
-		low = high;
+		val = msr.h;
+	else
+		val = msr.l;
 	/* The base masks off on the right alignment */
-	*base = (low & 0xFFFE0000) >> PAGE_SHIFT;
+	*base = (val & 0xFFFE0000) >> PAGE_SHIFT;
 	*type = 0;
-	if (low & 1)
+	if (val & 1)
 		*type = MTRR_TYPE_UNCACHABLE;
-	if (low & 2)
+	if (val & 2)
 		*type = MTRR_TYPE_WRCOMB;
-	if (!(low & 3)) {
+	if (!(val & 3)) {
 		*size = 0;
 		return;
 	}
@@ -42,8 +45,8 @@ amd_get_mtrr(unsigned int reg, unsigned long *base,
 	 * +1              000 0000 0000 0100
 	 * *128K   ...
 	 */
-	low = (~low) & 0x1FFFC;
-	*size = (low + 4) << (15 - PAGE_SHIFT);
+	val = (~val) & 0x1FFFC;
+	*size = (val + 4) << (15 - PAGE_SHIFT);
 }
 
 /**
@@ -59,12 +62,16 @@ amd_get_mtrr(unsigned int reg, unsigned long *base,
 static void
 amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type)
 {
+	struct msr msr;
 	u32 regs[2];
 
 	/*
 	 * Low is MTRR0, High MTRR 1
 	 */
-	rdmsr(MSR_K6_UWCCR, regs[0], regs[1]);
+	rdmsrq(MSR_K6_UWCCR, msr.q);
+	regs[0] = msr.l;
+	regs[1] = msr.h;
+
 	/*
 	 * Blank to disable
 	 */
@@ -89,7 +96,9 @@ amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type
 	 * disable local interrupts, write back the cache, set the mtrr
 	 */
 	wbinvd();
-	wrmsr(MSR_K6_UWCCR, regs[0], regs[1]);
+	msr.l = regs[0];
+	msr.h = regs[1];
+	wrmsrq(MSR_K6_UWCCR, msr.q);
 }
 
 static int
arch/x86/kernel/cpu/mtrr/centaur.c +9 -9
index 6f6c3ae92943..e32cca1caf59 100644
@@ -65,26 +65,26 @@ static void
 centaur_set_mcr(unsigned int reg, unsigned long base,
 		unsigned long size, mtrr_type type)
 {
-	unsigned long low, high;
+	struct msr val;
 
 	if (size == 0) {
 		/* Disable */
-		high = low = 0;
+		val.q = 0;
 	} else {
-		high = base << PAGE_SHIFT;
+		val.h = base << PAGE_SHIFT;
 		if (centaur_mcr_type == 0) {
 			/* Only support write-combining... */
-			low = -size << PAGE_SHIFT | 0x1f;
+			val.l = -size << PAGE_SHIFT | 0x1f;
 		} else {
 			if (type == MTRR_TYPE_UNCACHABLE)
-				low = -size << PAGE_SHIFT | 0x02; /* NC */
+				val.l = -size << PAGE_SHIFT | 0x02; /* NC */
 			else
-				low = -size << PAGE_SHIFT | 0x09; /* WWO, WC */
+				val.l = -size << PAGE_SHIFT | 0x09; /* WWO, WC */
 		}
 	}
-	centaur_mcr[reg].high = high;
-	centaur_mcr[reg].low = low;
-	wrmsr(MSR_IDT_MCR0 + reg, low, high);
+	centaur_mcr[reg].high = val.h;
+	centaur_mcr[reg].low = val.l;
+	wrmsrq(MSR_IDT_MCR0 + reg, val.q);
 }
 
 static int
arch/x86/kernel/cpu/mtrr/cleanup.c +9 -9
index e3eee9ae4141..cd1a6dec4064 100644
@@ -658,8 +658,8 @@ static int __init mtrr_search_optimal_index(void)
 int __init mtrr_cleanup(void)
 {
 	unsigned long x_remove_base, x_remove_size;
-	unsigned long base, size, def, dummy;
-	u64 chunk_size, gran_size;
+	u64 def, chunk_size, gran_size;
+	unsigned long base, size;
 	mtrr_type type;
 	int index_good;
 	int i;
@@ -670,7 +670,7 @@ int __init mtrr_cleanup(void)
 	if (!cpu_feature_enabled(X86_FEATURE_MTRR) || enable_mtrr_cleanup < 1)
 		return 0;
 
-	rdmsr(MSR_MTRRdefType, def, dummy);
+	rdmsrq(MSR_MTRRdefType, def);
 	def &= 0xff;
 	if (def != MTRR_TYPE_UNCACHABLE)
 		return 0;
@@ -806,7 +806,7 @@ early_param("disable_mtrr_trim", disable_mtrr_trim_setup);
 
 int __init amd_special_default_mtrr(void)
 {
-	u32 l, h;
+	u64 q;
 
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
 	    boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
@@ -814,13 +814,13 @@ int __init amd_special_default_mtrr(void)
 	if (boot_cpu_data.x86 < 0xf)
 		return 0;
 	/* In case some hypervisor doesn't pass SYSCFG through: */
-	if (rdmsr_safe(MSR_AMD64_SYSCFG, &l, &h) < 0)
+	if (rdmsrq_safe(MSR_AMD64_SYSCFG, &q) < 0)
 		return 0;
 	/*
 	 * Memory between 4GB and top of mem is forced WB by this magic bit.
 	 * Reserved before K8RevF, but should be zero there.
 	 */
-	if ((l & (Tom2Enabled | Tom2ForceMemTypeWB)) ==
+	if ((q & (Tom2Enabled | Tom2ForceMemTypeWB)) ==
 		 (Tom2Enabled | Tom2ForceMemTypeWB))
 		return 1;
 	return 0;
@@ -854,9 +854,9 @@ real_trim_memory(unsigned long start_pfn, unsigned long limit_pfn)
  */
 int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 {
-	unsigned long i, base, size, highest_pfn = 0, def, dummy;
+	unsigned long i, base, size, highest_pfn = 0;
 	mtrr_type type;
-	u64 total_trim_size;
+	u64 def, total_trim_size;
 	/* extra one for all 0 */
 	int num[MTRR_NUM_TYPES + 1];
 
@@ -870,7 +870,7 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 	if (!cpu_feature_enabled(X86_FEATURE_MTRR) || disable_mtrr_trim)
 		return 0;
 
-	rdmsr(MSR_MTRRdefType, def, dummy);
+	rdmsrq(MSR_MTRRdefType, def);
 	def &= MTRR_DEF_TYPE_TYPE;
 	if (def != MTRR_TYPE_UNCACHABLE)
 		return 0;
arch/x86/kernel/cpu/mtrr/generic.c +52 -45

219 lines not on this page · raw message

arch/x86/kernel/cpu/mtrr/mtrr.c +2 -2
index 4b3d492afe17..468c53b20acf 100644
@@ -547,7 +547,7 @@ void __init mtrr_bp_init(void)
 {
 	bool generic_mtrrs = cpu_feature_enabled(X86_FEATURE_MTRR);
 	const char *why = "(not available)";
-	unsigned long config, dummy;
+	unsigned long config;
 
 	phys_hi_rsvd = GENMASK(31, boot_cpu_data.x86_phys_bits - 32);
 
@@ -571,7 +571,7 @@ void __init mtrr_bp_init(void)
 	if (mtrr_enabled()) {
 		/* Get the number of variable MTRR ranges. */
 		if (mtrr_if == &generic_mtrr_ops)
-			rdmsr(MSR_MTRRcap, config, dummy);
+			rdmsrq(MSR_MTRRcap, config);
 		else
 			config = mtrr_if->var_regs;
 		num_var_ranges = config & MTRR_CAP_VCNT;
Signature · 1 line
2.54.0
merge bot Applied
#32 lore raw

[tip: x86/msr] x86/mtrr: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     a415e3520545e2a83f9c22a45d5cbebb1b64e1f0
Gitweb:        https://git.kernel.org/tip/a415e3520545e2a83f9c22a45d5cbebb1b64e1f0
Author:        Juergen Gross <[email protected]>
AuthorDate:    Fri, 03 Jul 2026 13:23:44 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 17 Jul 2026 11:25:49 +02:00

x86/mtrr: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/mtrr/amd.c     | 31 +++++----
 arch/x86/kernel/cpu/mtrr/centaur.c | 18 ++---
 arch/x86/kernel/cpu/mtrr/cleanup.c | 18 ++---
 arch/x86/kernel/cpu/mtrr/generic.c | 97 +++++++++++++++--------------
 arch/x86/kernel/cpu/mtrr/mtrr.c    |  4 +-
 5 files changed, 92 insertions(+), 76 deletions(-)
arch/x86/kernel/cpu/mtrr/amd.c +20 -11
index ef3e8e4..a73715d 100644
@@ -10,20 +10,23 @@ static void
 amd_get_mtrr(unsigned int reg, unsigned long *base,
 	     unsigned long *size, mtrr_type *type)
 {
-	unsigned long low, high;
+	unsigned long val;
+	struct msr msr;
 
-	rdmsr(MSR_K6_UWCCR, low, high);
+	rdmsrq(MSR_K6_UWCCR, msr.q);
 	/* Upper dword is region 1, lower is region 0 */
 	if (reg == 1)
-		low = high;
+		val = msr.h;
+	else
+		val = msr.l;
 	/* The base masks off on the right alignment */
-	*base = (low & 0xFFFE0000) >> PAGE_SHIFT;
+	*base = (val & 0xFFFE0000) >> PAGE_SHIFT;
 	*type = 0;
-	if (low & 1)
+	if (val & 1)
 		*type = MTRR_TYPE_UNCACHABLE;
-	if (low & 2)
+	if (val & 2)
 		*type = MTRR_TYPE_WRCOMB;
-	if (!(low & 3)) {
+	if (!(val & 3)) {
 		*size = 0;
 		return;
 	}
@@ -42,8 +45,8 @@ amd_get_mtrr(unsigned int reg, unsigned long *base,
 	 * +1              000 0000 0000 0100
 	 * *128K   ...
 	 */
-	low = (~low) & 0x1FFFC;
-	*size = (low + 4) << (15 - PAGE_SHIFT);
+	val = (~val) & 0x1FFFC;
+	*size = (val + 4) << (15 - PAGE_SHIFT);
 }
 
 /**
@@ -59,12 +62,16 @@ amd_get_mtrr(unsigned int reg, unsigned long *base,
 static void
 amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type)
 {
+	struct msr msr;
 	u32 regs[2];
 
 	/*
 	 * Low is MTRR0, High MTRR 1
 	 */
-	rdmsr(MSR_K6_UWCCR, regs[0], regs[1]);
+	rdmsrq(MSR_K6_UWCCR, msr.q);
+	regs[0] = msr.l;
+	regs[1] = msr.h;
+
 	/*
 	 * Blank to disable
 	 */
@@ -89,7 +96,9 @@ amd_set_mtrr(unsigned int reg, unsigned long base, unsigned long size, mtrr_type
 	 * disable local interrupts, write back the cache, set the mtrr
 	 */
 	wbinvd();
-	wrmsr(MSR_K6_UWCCR, regs[0], regs[1]);
+	msr.l = regs[0];
+	msr.h = regs[1];
+	wrmsrq(MSR_K6_UWCCR, msr.q);
 }
 
 static int
arch/x86/kernel/cpu/mtrr/centaur.c +9 -9
index 6f6c3ae..e32cca1 100644
@@ -65,26 +65,26 @@ static void
 centaur_set_mcr(unsigned int reg, unsigned long base,
 		unsigned long size, mtrr_type type)
 {
-	unsigned long low, high;
+	struct msr val;
 
 	if (size == 0) {
 		/* Disable */
-		high = low = 0;
+		val.q = 0;
 	} else {
-		high = base << PAGE_SHIFT;
+		val.h = base << PAGE_SHIFT;
 		if (centaur_mcr_type == 0) {
 			/* Only support write-combining... */
-			low = -size << PAGE_SHIFT | 0x1f;
+			val.l = -size << PAGE_SHIFT | 0x1f;
 		} else {
 			if (type == MTRR_TYPE_UNCACHABLE)
-				low = -size << PAGE_SHIFT | 0x02; /* NC */
+				val.l = -size << PAGE_SHIFT | 0x02; /* NC */
 			else
-				low = -size << PAGE_SHIFT | 0x09; /* WWO, WC */
+				val.l = -size << PAGE_SHIFT | 0x09; /* WWO, WC */
 		}
 	}
-	centaur_mcr[reg].high = high;
-	centaur_mcr[reg].low = low;
-	wrmsr(MSR_IDT_MCR0 + reg, low, high);
+	centaur_mcr[reg].high = val.h;
+	centaur_mcr[reg].low = val.l;
+	wrmsrq(MSR_IDT_MCR0 + reg, val.q);
 }
 
 static int
arch/x86/kernel/cpu/mtrr/cleanup.c +9 -9
index e3eee9a..cd1a6de 100644
@@ -658,8 +658,8 @@ static int __init mtrr_search_optimal_index(void)
 int __init mtrr_cleanup(void)
 {
 	unsigned long x_remove_base, x_remove_size;
-	unsigned long base, size, def, dummy;
-	u64 chunk_size, gran_size;
+	u64 def, chunk_size, gran_size;
+	unsigned long base, size;
 	mtrr_type type;
 	int index_good;
 	int i;
@@ -670,7 +670,7 @@ int __init mtrr_cleanup(void)
 	if (!cpu_feature_enabled(X86_FEATURE_MTRR) || enable_mtrr_cleanup < 1)
 		return 0;
 
-	rdmsr(MSR_MTRRdefType, def, dummy);
+	rdmsrq(MSR_MTRRdefType, def);
 	def &= 0xff;
 	if (def != MTRR_TYPE_UNCACHABLE)
 		return 0;
@@ -806,7 +806,7 @@ early_param("disable_mtrr_trim", disable_mtrr_trim_setup);
 
 int __init amd_special_default_mtrr(void)
 {
-	u32 l, h;
+	u64 q;
 
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
 	    boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
@@ -814,13 +814,13 @@ int __init amd_special_default_mtrr(void)
 	if (boot_cpu_data.x86 < 0xf)
 		return 0;
 	/* In case some hypervisor doesn't pass SYSCFG through: */
-	if (rdmsr_safe(MSR_AMD64_SYSCFG, &l, &h) < 0)
+	if (rdmsrq_safe(MSR_AMD64_SYSCFG, &q) < 0)
 		return 0;
 	/*
 	 * Memory between 4GB and top of mem is forced WB by this magic bit.
 	 * Reserved before K8RevF, but should be zero there.
 	 */
-	if ((l & (Tom2Enabled | Tom2ForceMemTypeWB)) ==
+	if ((q & (Tom2Enabled | Tom2ForceMemTypeWB)) ==
 		 (Tom2Enabled | Tom2ForceMemTypeWB))
 		return 1;
 	return 0;
@@ -854,9 +854,9 @@ real_trim_memory(unsigned long start_pfn, unsigned long limit_pfn)
  */
 int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 {
-	unsigned long i, base, size, highest_pfn = 0, def, dummy;
+	unsigned long i, base, size, highest_pfn = 0;
 	mtrr_type type;
-	u64 total_trim_size;
+	u64 def, total_trim_size;
 	/* extra one for all 0 */
 	int num[MTRR_NUM_TYPES + 1];
 
@@ -870,7 +870,7 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 	if (!cpu_feature_enabled(X86_FEATURE_MTRR) || disable_mtrr_trim)
 		return 0;
 
-	rdmsr(MSR_MTRRdefType, def, dummy);
+	rdmsrq(MSR_MTRRdefType, def);
 	def &= MTRR_DEF_TYPE_TYPE;
 	if (def != MTRR_TYPE_UNCACHABLE)
 		return 0;
arch/x86/kernel/cpu/mtrr/generic.c +52 -45

219 lines not on this page · raw message

arch/x86/kernel/cpu/mtrr/mtrr.c +2 -2
index 4b3d492..468c53b 100644
@@ -547,7 +547,7 @@ void __init mtrr_bp_init(void)
 {
 	bool generic_mtrrs = cpu_feature_enabled(X86_FEATURE_MTRR);
 	const char *why = "(not available)";
-	unsigned long config, dummy;
+	unsigned long config;
 
 	phys_hi_rsvd = GENMASK(31, boot_cpu_data.x86_phys_bits - 32);
 
@@ -571,7 +571,7 @@ void __init mtrr_bp_init(void)
 	if (mtrr_enabled()) {
 		/* Get the number of variable MTRR ranges. */
 		if (mtrr_if == &generic_mtrr_ops)
-			rdmsr(MSR_MTRRcap, config, dummy);
+			rdmsrq(MSR_MTRRcap, config);
 		else
 			config = mtrr_if->var_regs;
 		num_var_ranges = config & MTRR_CAP_VCNT;
author maintainer
#33 lore raw

PATCH 6/32 x86/msr: Stop using 32-bit MSR interfaces in lib/msr-smp.c

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/lib/msr-smp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/lib/msr-smp.c +4 -4
index 0c6627773c80..7b6cfc2c0970 100644
@@ -15,7 +15,7 @@ static void __rdmsr_on_cpu(void *info)
 	else
 		reg = &rv->reg;
 
-	rdmsr(rv->msr_no, reg->l, reg->h);
+	rdmsrq(rv->msr_no, reg->q);
 }
 
 static void __wrmsr_on_cpu(void *info)
@@ -28,7 +28,7 @@ static void __wrmsr_on_cpu(void *info)
 	else
 		reg = &rv->reg;
 
-	wrmsr(rv->msr_no, reg->l, reg->h);
+	wrmsrq(rv->msr_no, reg->q);
 }
 
 int rdmsrq_on_cpu(unsigned int cpu, u32 msr_no, u64 *q)
@@ -121,7 +121,7 @@ static void __rdmsr_safe_on_cpu(void *info)
 {
 	struct msr_info_completion *rv = info;
 
-	rv->msr.err = rdmsr_safe(rv->msr.msr_no, &rv->msr.reg.l, &rv->msr.reg.h);
+	rv->msr.err = rdmsrq_safe(rv->msr.msr_no, &rv->msr.reg.q);
 	complete(&rv->done);
 }
 
@@ -129,7 +129,7 @@ static void __wrmsr_safe_on_cpu(void *info)
 {
 	struct msr_info *rv = info;
 
-	rv->err = wrmsr_safe(rv->msr_no, rv->reg.l, rv->reg.h);
+	rv->err = wrmsrq_safe(rv->msr_no, rv->reg.q);
 }
 
 int wrmsrq_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
Signature · 1 line
2.54.0
merge bot Applied
#34 lore raw

[tip: x86/msr] x86/msr: Stop using 32-bit MSR interfaces in lib/msr-smp.c

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     c69d7feb8d124e5f82d502ce0d93d8be6bd80dd1
Gitweb:        https://git.kernel.org/tip/c69d7feb8d124e5f82d502ce0d93d8be6bd80dd1
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:04:57 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:51 +02:00

x86/msr: Stop using 32-bit MSR interfaces in lib/msr-smp.c

The 32-bit MSR interfaces rdmsr(), wrmsr(), rdmsr_safe() and wrmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/lib/msr-smp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/lib/msr-smp.c +4 -4
index 0c66277..7b6cfc2 100644
@@ -15,7 +15,7 @@ static void __rdmsr_on_cpu(void *info)
 	else
 		reg = &rv->reg;
 
-	rdmsr(rv->msr_no, reg->l, reg->h);
+	rdmsrq(rv->msr_no, reg->q);
 }
 
 static void __wrmsr_on_cpu(void *info)
@@ -28,7 +28,7 @@ static void __wrmsr_on_cpu(void *info)
 	else
 		reg = &rv->reg;
 
-	wrmsr(rv->msr_no, reg->l, reg->h);
+	wrmsrq(rv->msr_no, reg->q);
 }
 
 int rdmsrq_on_cpu(unsigned int cpu, u32 msr_no, u64 *q)
@@ -121,7 +121,7 @@ static void __rdmsr_safe_on_cpu(void *info)
 {
 	struct msr_info_completion *rv = info;
 
-	rv->msr.err = rdmsr_safe(rv->msr.msr_no, &rv->msr.reg.l, &rv->msr.reg.h);
+	rv->msr.err = rdmsrq_safe(rv->msr.msr_no, &rv->msr.reg.q);
 	complete(&rv->done);
 }
 
@@ -129,7 +129,7 @@ static void __wrmsr_safe_on_cpu(void *info)
 {
 	struct msr_info *rv = info;
 
-	rv->err = wrmsr_safe(rv->msr_no, rv->reg.l, rv->reg.h);
+	rv->err = wrmsrq_safe(rv->msr_no, rv->reg.q);
 }
 
 int wrmsrq_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
author maintainer
#35 lore raw

PATCH 7/32 x86/msr: Remove wrmsr_safe()

In reply to Juergen Gross

wrmsr_safe() has no users left. Delete it.

---
 arch/x86/include/asm/msr.h | 8 --------
 1 file changed, 8 deletions(-)
arch/x86/include/asm/msr.h +0 -8
index 2f41a9289d79..6fb7125608c7 100644
@@ -242,14 +242,6 @@ static __always_inline void wrmsrns(u32 msr, u64 val)
 		     : : "c" (msr), "a" ((u32)val), "d" ((u32)(val >> 32)));
 }
 
-/*
- * Dual u32 version of wrmsrq_safe():
- */
-static inline int wrmsr_safe(u32 msr, u32 low, u32 high)
-{
-	return wrmsrq_safe(msr, (u64)high << 32 | low);
-}
-
 struct msr __percpu *msrs_alloc(void);
 void msrs_free(struct msr __percpu *msrs);
 int msr_set_bit(u32 msr, u8 bit);
Signature · 1 line
2.54.0
author maintainer
#36 lore raw

PATCH 8/32 x86/mce: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/mce/amd.c     | 87 ++++++++++++++++---------------
 arch/x86/kernel/cpu/mce/core.c    |  2 +-
 arch/x86/kernel/cpu/mce/p5.c      | 16 +++---
 arch/x86/kernel/cpu/mce/winchip.c | 10 ++--
 4 files changed, 58 insertions(+), 57 deletions(-)
arch/x86/kernel/cpu/mce/amd.c +44 -43
index 36e0df4d1342..f916fb4c5d13 100644
@@ -280,11 +280,11 @@ static void smca_configure(unsigned int bank, unsigned int cpu)
 	u8 *bank_counts = this_cpu_ptr(smca_bank_counts);
 	const struct smca_hwid *s_hwid;
 	unsigned int i, hwid_mcatype;
-	u32 high, low;
+	struct msr val;
 	u32 smca_config = MSR_AMD64_SMCA_MCx_CONFIG(bank);
 
 	/* Set appropriate bits in MCA_CONFIG */
-	if (!rdmsr_safe(smca_config, &low, &high)) {
+	if (!rdmsrq_safe(smca_config, &val.q)) {
 		/*
 		 * OS is required to set the MCAX bit to acknowledge that it is
 		 * now using the new MSR ranges and new registers under each
@@ -294,7 +294,7 @@ static void smca_configure(unsigned int bank, unsigned int cpu)
 		 *
 		 * MCA_CONFIG[MCAX] is bit 32 (0 in the high portion of the MSR.)
 		 */
-		high |= BIT(0);
+		val.h |= BIT(0);
 
 		/*
 		 * SMCA sets the Deferred Error Interrupt type per bank.
@@ -307,9 +307,9 @@ static void smca_configure(unsigned int bank, unsigned int cpu)
 		 * APIC based interrupt. First, check that no interrupt has been
 		 * set.
 		 */
-		if ((low & BIT(5)) && !((high >> 5) & 0x3) && data->dfr_intr_en) {
+		if ((val.l & BIT(5)) && !((val.h >> 5) & 0x3) && data->dfr_intr_en) {
 			__set_bit(bank, data->dfr_intr_banks);
-			high |= BIT(5);
+			val.h |= BIT(5);
 		}
 
 		/*
@@ -324,33 +324,33 @@ static void smca_configure(unsigned int bank, unsigned int cpu)
 		 * The OS should set this to inform the platform that the OS is ready
 		 * to handle the MCA Thresholding interrupt.
 		 */
-		if ((low & BIT(10)) && data->thr_intr_en) {
+		if ((val.l & BIT(10)) && data->thr_intr_en) {
 			__set_bit(bank, data->thr_intr_banks);
-			high |= BIT(8);
+			val.h |= BIT(8);
 		}
 
-		this_cpu_ptr(mce_banks_array)[bank].lsb_in_status = !!(low & BIT(8));
+		this_cpu_ptr(mce_banks_array)[bank].lsb_in_status = !!(val.l & BIT(8));
 
-		if (low & MCI_CONFIG_PADDRV)
+		if (val.l & MCI_CONFIG_PADDRV)
 			this_cpu_ptr(smca_banks)[bank].paddrv = 1;
 
-		wrmsr(smca_config, low, high);
+		wrmsrq(smca_config, val.q);
 	}
 
-	if (rdmsr_safe(MSR_AMD64_SMCA_MCx_IPID(bank), &low, &high)) {
+	if (rdmsrq_safe(MSR_AMD64_SMCA_MCx_IPID(bank), &val.q)) {
 		pr_warn("Failed to read MCA_IPID for bank %d\n", bank);
 		return;
 	}
 
-	hwid_mcatype = HWID_MCATYPE(high & MCI_IPID_HWID,
-				    (high & MCI_IPID_MCATYPE) >> 16);
+	hwid_mcatype = HWID_MCATYPE(val.h & MCI_IPID_HWID,
+				    (val.h & MCI_IPID_MCATYPE) >> 16);
 
 	for (i = 0; i < ARRAY_SIZE(smca_hwid_mcatypes); i++) {
 		s_hwid = &smca_hwid_mcatypes[i];
 
 		if (hwid_mcatype == s_hwid->hwid_mcatype) {
 			this_cpu_ptr(smca_banks)[bank].hwid = s_hwid;
-			this_cpu_ptr(smca_banks)[bank].id = low;
+			this_cpu_ptr(smca_banks)[bank].id = val.l;
 			this_cpu_ptr(smca_banks)[bank].sysfs_id = bank_counts[s_hwid->bank_type]++;
 			break;
 		}
@@ -432,50 +432,50 @@ static bool lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
 static void threshold_restart_block(void *_tr)
 {
 	struct thresh_restart *tr = _tr;
-	u32 hi, lo;
+	struct msr val;
 
 	/* sysfs write might race against an offline operation */
 	if (!this_cpu_read(threshold_banks) && !tr->set_lvt_off)
 		return;
 
-	rdmsr(tr->b->address, lo, hi);
+	rdmsrq(tr->b->address, val.q);
 
 	/*
 	 * Reset error count and overflow bit.
 	 * This is done during init or after handling an interrupt.
 	 */
-	if (hi & MASK_OVERFLOW_HI || tr->set_lvt_off) {
-		hi &= ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI);
-		hi |= THRESHOLD_MAX - tr->b->threshold_limit;
+	if (val.h & MASK_OVERFLOW_HI || tr->set_lvt_off) {
+		val.h &= ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI);
+		val.h |= THRESHOLD_MAX - tr->b->threshold_limit;
 	} else if (tr->old_limit) {	/* change limit w/o reset */
-		int new_count = (hi & THRESHOLD_MAX) +
+		int new_count = (val.h & THRESHOLD_MAX) +
 		    (tr->old_limit - tr->b->threshold_limit);
 
-		hi = (hi & ~MASK_ERR_COUNT_HI) |
+		val.h = (val.h & ~MASK_ERR_COUNT_HI) |
 		    (new_count & THRESHOLD_MAX);
 	}
 
 	/* clear IntType */
-	hi &= ~MASK_INT_TYPE_HI;
+	val.h &= ~MASK_INT_TYPE_HI;
 
 	if (!tr->b->interrupt_capable)
 		goto done;
 
 	if (tr->set_lvt_off) {
-		if (lvt_off_valid(tr->b, tr->lvt_off, lo, hi)) {
+		if (lvt_off_valid(tr->b, tr->lvt_off, val.l, val.h)) {
 			/* set new lvt offset */
-			hi &= ~MASK_LVTOFF_HI;
-			hi |= tr->lvt_off << 20;
+			val.h &= ~MASK_LVTOFF_HI;
+			val.h |= tr->lvt_off << 20;
 		}
 	}
 
 	if (tr->b->interrupt_enable)
-		hi |= INT_TYPE_APIC;
+		val.h |= INT_TYPE_APIC;
 
  done:
 
-	hi |= MASK_COUNT_EN_HI;
-	wrmsr(tr->b->address, lo, hi);
+	val.h |= MASK_COUNT_EN_HI;
+	wrmsrq(tr->b->address, val.q);
 }
 
 static void threshold_restart_bank(unsigned int bank, bool intr_en)
@@ -726,7 +726,8 @@ static void smca_enable_interrupt_vectors(void)
 void mce_amd_feature_init(struct cpuinfo_x86 *c)
 {
 	unsigned int bank, block, cpu = smp_processor_id();
-	u32 low = 0, high = 0, address = 0;
+	struct msr val = { .q = 0 };
+	u32 address = 0;
 	int offset = -1;
 
 	amd_apply_cpu_quirks(c);
@@ -746,21 +747,21 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
 		disable_err_thresholding(c, bank);
 
 		for (block = 0; block < NR_BLOCKS; ++block) {
-			address = get_block_address(address, low, high, bank, block, cpu);
+			address = get_block_address(address, val.l, val.h, bank, block, cpu);
 			if (!address)
 				break;
 
-			if (rdmsr_safe(address, &low, &high))
+			if (rdmsrq_safe(address, &val.q))
 				break;
 
-			if (!(high & MASK_VALID_HI))
+			if (!(val.h & MASK_VALID_HI))
 				continue;
 
-			if (!(high & MASK_CNTP_HI)  ||
-			     (high & MASK_LOCKED_HI))
+			if (!(val.h & MASK_CNTP_HI)  ||
+			     (val.h & MASK_LOCKED_HI))
 				continue;
 
-			offset = prepare_threshold_block(bank, block, address, offset, high);
+			offset = prepare_threshold_block(bank, block, address, offset, val.h);
 		}
 	}
 }
@@ -1083,24 +1084,24 @@ static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb
 				     u32 address)
 {
 	struct threshold_block *b = NULL;
-	u32 low, high;
+	struct msr val;
 	int err;
 
 	if ((bank >= this_cpu_read(mce_num_banks)) || (block >= NR_BLOCKS))
 		return 0;
 
-	if (rdmsr_safe(address, &low, &high))
+	if (rdmsrq_safe(address, &val.q))
 		return 0;
 
-	if (!(high & MASK_VALID_HI)) {
+	if (!(val.h & MASK_VALID_HI)) {
 		if (block)
 			goto recurse;
 		else
 			return 0;
 	}
 
-	if (!(high & MASK_CNTP_HI)  ||
-	     (high & MASK_LOCKED_HI))
+	if (!(val.h & MASK_CNTP_HI)  ||
+	     (val.h & MASK_LOCKED_HI))
 		goto recurse;
 
 	b = kzalloc_obj(struct threshold_block);
@@ -1112,7 +1113,7 @@ static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb
 	b->cpu			= cpu;
 	b->address		= address;
 	b->interrupt_enable	= 0;
-	b->interrupt_capable	= lvt_interrupt_supported(bank, high);
+	b->interrupt_capable	= lvt_interrupt_supported(bank, val.h);
 	b->threshold_limit	= get_thr_limit();
 
 	if (b->interrupt_capable) {
@@ -1124,13 +1125,13 @@ static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb
 
 	list_add(&b->miscj, &tb->miscj);
 
-	mce_threshold_block_init(b, (high & MASK_LVTOFF_HI) >> 20);
+	mce_threshold_block_init(b, (val.h & MASK_LVTOFF_HI) >> 20);
 
 	err = kobject_init_and_add(&b->kobj, &threshold_ktype, tb->kobj, get_name(cpu, bank, b));
 	if (err)
 		goto out_free;
 recurse:
-	address = get_block_address(address, low, high, bank, ++block, cpu);
+	address = get_block_address(address, val.l, val.h, bank, ++block, cpu);
 	if (!address)
 		return 0;
 
arch/x86/kernel/cpu/mce/core.c +1 -1
index 9bba1e2f03af..017aaf57ba47 100644
@@ -1866,7 +1866,7 @@ static void __mcheck_cpu_init_generic(void)
 
 	rdmsrq(MSR_IA32_MCG_CAP, cap);
 	if (cap & MCG_CTL_P)
-		wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
+		wrmsrq(MSR_IA32_MCG_CTL, ~0ULL);
 }
 
 static void __mcheck_cpu_init_prepare_banks(void)
arch/x86/kernel/cpu/mce/p5.c +8 -8
index 2272ad53fc33..eb99f384d747 100644
@@ -23,16 +23,16 @@ int mce_p5_enabled __read_mostly;
 /* Machine check handler for Pentium class Intel CPUs: */
 noinstr void pentium_machine_check(struct pt_regs *regs)
 {
-	u32 loaddr, hi, lotype;
+	u64 addr, type;
 
 	instrumentation_begin();
-	rdmsr(MSR_IA32_P5_MC_ADDR, loaddr, hi);
-	rdmsr(MSR_IA32_P5_MC_TYPE, lotype, hi);
+	rdmsrq(MSR_IA32_P5_MC_ADDR, addr);
+	rdmsrq(MSR_IA32_P5_MC_TYPE, type);
 
 	pr_emerg("CPU#%d: Machine Check Exception:  0x%8X (type 0x%8X).\n",
-		 smp_processor_id(), loaddr, lotype);
+		 smp_processor_id(), (u32)addr, (u32)type);
 
-	if (lotype & (1<<5)) {
+	if (type & (1<<5)) {
 		pr_emerg("CPU#%d: Possible thermal failure (CPU on fire ?).\n",
 			 smp_processor_id());
 	}
@@ -44,7 +44,7 @@ noinstr void pentium_machine_check(struct pt_regs *regs)
 /* Set up machine check reporting for processors with Intel style MCE: */
 void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
 {
-	u32 l, h;
+	u64 q;
 
 	/* Default P5 to off as its often misconnected: */
 	if (!mce_p5_enabled)
@@ -55,8 +55,8 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
 		return;
 
 	/* Read registers before enabling: */
-	rdmsr(MSR_IA32_P5_MC_ADDR, l, h);
-	rdmsr(MSR_IA32_P5_MC_TYPE, l, h);
+	rdmsrq(MSR_IA32_P5_MC_ADDR, q);
+	rdmsrq(MSR_IA32_P5_MC_TYPE, q);
 	pr_info("Intel old style machine check architecture supported.\n");
 
 	/* Enable MCE: */
arch/x86/kernel/cpu/mce/winchip.c +5 -5
index 6c99f2941909..7040243533d9 100644
@@ -28,12 +28,12 @@ noinstr void winchip_machine_check(struct pt_regs *regs)
 /* Set up machine check reporting on the Winchip C6 series */
 void winchip_mcheck_init(struct cpuinfo_x86 *c)
 {
-	u32 lo, hi;
+	struct msr val;
 
-	rdmsr(MSR_IDT_FCR1, lo, hi);
-	lo |= (1<<2);	/* Enable EIERRINT (int 18 MCE) */
-	lo &= ~(1<<4);	/* Enable MCE */
-	wrmsr(MSR_IDT_FCR1, lo, hi);
+	rdmsrq(MSR_IDT_FCR1, val.q);
+	val.l |= (1<<2);	/* Enable EIERRINT (int 18 MCE) */
+	val.l &= ~(1<<4);	/* Enable MCE */
+	wrmsrq(MSR_IDT_FCR1, val.q);
 
 	cr4_set_bits(X86_CR4_MCE);
 
Signature · 1 line
2.54.0
merge bot Applied
#37 lore raw

[tip: x86/msr] x86/mce: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     cff219368bd066d67cc66e8fcdd2c4b13f5101ce
Gitweb:        https://git.kernel.org/tip/cff219368bd066d67cc66e8fcdd2c4b13f5101ce
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:04:59 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:51 +02:00

x86/mce: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr(), wrmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/mce/amd.c     | 87 +++++++++++++++---------------
 arch/x86/kernel/cpu/mce/core.c    |  2 +-
 arch/x86/kernel/cpu/mce/p5.c      | 16 +++---
 arch/x86/kernel/cpu/mce/winchip.c | 10 +--
 4 files changed, 58 insertions(+), 57 deletions(-)
arch/x86/kernel/cpu/mce/amd.c +44 -43
index 36e0df4..f916fb4 100644
@@ -280,11 +280,11 @@ static void smca_configure(unsigned int bank, unsigned int cpu)
 	u8 *bank_counts = this_cpu_ptr(smca_bank_counts);
 	const struct smca_hwid *s_hwid;
 	unsigned int i, hwid_mcatype;
-	u32 high, low;
+	struct msr val;
 	u32 smca_config = MSR_AMD64_SMCA_MCx_CONFIG(bank);
 
 	/* Set appropriate bits in MCA_CONFIG */
-	if (!rdmsr_safe(smca_config, &low, &high)) {
+	if (!rdmsrq_safe(smca_config, &val.q)) {
 		/*
 		 * OS is required to set the MCAX bit to acknowledge that it is
 		 * now using the new MSR ranges and new registers under each
@@ -294,7 +294,7 @@ static void smca_configure(unsigned int bank, unsigned int cpu)
 		 *
 		 * MCA_CONFIG[MCAX] is bit 32 (0 in the high portion of the MSR.)
 		 */
-		high |= BIT(0);
+		val.h |= BIT(0);
 
 		/*
 		 * SMCA sets the Deferred Error Interrupt type per bank.
@@ -307,9 +307,9 @@ static void smca_configure(unsigned int bank, unsigned int cpu)
 		 * APIC based interrupt. First, check that no interrupt has been
 		 * set.
 		 */
-		if ((low & BIT(5)) && !((high >> 5) & 0x3) && data->dfr_intr_en) {
+		if ((val.l & BIT(5)) && !((val.h >> 5) & 0x3) && data->dfr_intr_en) {
 			__set_bit(bank, data->dfr_intr_banks);
-			high |= BIT(5);
+			val.h |= BIT(5);
 		}
 
 		/*
@@ -324,33 +324,33 @@ static void smca_configure(unsigned int bank, unsigned int cpu)
 		 * The OS should set this to inform the platform that the OS is ready
 		 * to handle the MCA Thresholding interrupt.
 		 */
-		if ((low & BIT(10)) && data->thr_intr_en) {
+		if ((val.l & BIT(10)) && data->thr_intr_en) {
 			__set_bit(bank, data->thr_intr_banks);
-			high |= BIT(8);
+			val.h |= BIT(8);
 		}
 
-		this_cpu_ptr(mce_banks_array)[bank].lsb_in_status = !!(low & BIT(8));
+		this_cpu_ptr(mce_banks_array)[bank].lsb_in_status = !!(val.l & BIT(8));
 
-		if (low & MCI_CONFIG_PADDRV)
+		if (val.l & MCI_CONFIG_PADDRV)
 			this_cpu_ptr(smca_banks)[bank].paddrv = 1;
 
-		wrmsr(smca_config, low, high);
+		wrmsrq(smca_config, val.q);
 	}
 
-	if (rdmsr_safe(MSR_AMD64_SMCA_MCx_IPID(bank), &low, &high)) {
+	if (rdmsrq_safe(MSR_AMD64_SMCA_MCx_IPID(bank), &val.q)) {
 		pr_warn("Failed to read MCA_IPID for bank %d\n", bank);
 		return;
 	}
 
-	hwid_mcatype = HWID_MCATYPE(high & MCI_IPID_HWID,
-				    (high & MCI_IPID_MCATYPE) >> 16);
+	hwid_mcatype = HWID_MCATYPE(val.h & MCI_IPID_HWID,
+				    (val.h & MCI_IPID_MCATYPE) >> 16);
 
 	for (i = 0; i < ARRAY_SIZE(smca_hwid_mcatypes); i++) {
 		s_hwid = &smca_hwid_mcatypes[i];
 
 		if (hwid_mcatype == s_hwid->hwid_mcatype) {
 			this_cpu_ptr(smca_banks)[bank].hwid = s_hwid;
-			this_cpu_ptr(smca_banks)[bank].id = low;
+			this_cpu_ptr(smca_banks)[bank].id = val.l;
 			this_cpu_ptr(smca_banks)[bank].sysfs_id = bank_counts[s_hwid->bank_type]++;
 			break;
 		}
@@ -432,50 +432,50 @@ static bool lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
 static void threshold_restart_block(void *_tr)
 {
 	struct thresh_restart *tr = _tr;
-	u32 hi, lo;
+	struct msr val;
 
 	/* sysfs write might race against an offline operation */
 	if (!this_cpu_read(threshold_banks) && !tr->set_lvt_off)
 		return;
 
-	rdmsr(tr->b->address, lo, hi);
+	rdmsrq(tr->b->address, val.q);
 
 	/*
 	 * Reset error count and overflow bit.
 	 * This is done during init or after handling an interrupt.
 	 */
-	if (hi & MASK_OVERFLOW_HI || tr->set_lvt_off) {
-		hi &= ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI);
-		hi |= THRESHOLD_MAX - tr->b->threshold_limit;
+	if (val.h & MASK_OVERFLOW_HI || tr->set_lvt_off) {
+		val.h &= ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI);
+		val.h |= THRESHOLD_MAX - tr->b->threshold_limit;
 	} else if (tr->old_limit) {	/* change limit w/o reset */
-		int new_count = (hi & THRESHOLD_MAX) +
+		int new_count = (val.h & THRESHOLD_MAX) +
 		    (tr->old_limit - tr->b->threshold_limit);
 
-		hi = (hi & ~MASK_ERR_COUNT_HI) |
+		val.h = (val.h & ~MASK_ERR_COUNT_HI) |
 		    (new_count & THRESHOLD_MAX);
 	}
 
 	/* clear IntType */
-	hi &= ~MASK_INT_TYPE_HI;
+	val.h &= ~MASK_INT_TYPE_HI;
 
 	if (!tr->b->interrupt_capable)
 		goto done;
 
 	if (tr->set_lvt_off) {
-		if (lvt_off_valid(tr->b, tr->lvt_off, lo, hi)) {
+		if (lvt_off_valid(tr->b, tr->lvt_off, val.l, val.h)) {
 			/* set new lvt offset */
-			hi &= ~MASK_LVTOFF_HI;
-			hi |= tr->lvt_off << 20;
+			val.h &= ~MASK_LVTOFF_HI;
+			val.h |= tr->lvt_off << 20;
 		}
 	}
 
 	if (tr->b->interrupt_enable)
-		hi |= INT_TYPE_APIC;
+		val.h |= INT_TYPE_APIC;
 
  done:
 
-	hi |= MASK_COUNT_EN_HI;
-	wrmsr(tr->b->address, lo, hi);
+	val.h |= MASK_COUNT_EN_HI;
+	wrmsrq(tr->b->address, val.q);
 }
 
 static void threshold_restart_bank(unsigned int bank, bool intr_en)
@@ -726,7 +726,8 @@ static void smca_enable_interrupt_vectors(void)
 void mce_amd_feature_init(struct cpuinfo_x86 *c)
 {
 	unsigned int bank, block, cpu = smp_processor_id();
-	u32 low = 0, high = 0, address = 0;
+	struct msr val = { .q = 0 };
+	u32 address = 0;
 	int offset = -1;
 
 	amd_apply_cpu_quirks(c);
@@ -746,21 +747,21 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
 		disable_err_thresholding(c, bank);
 
 		for (block = 0; block < NR_BLOCKS; ++block) {
-			address = get_block_address(address, low, high, bank, block, cpu);
+			address = get_block_address(address, val.l, val.h, bank, block, cpu);
 			if (!address)
 				break;
 
-			if (rdmsr_safe(address, &low, &high))
+			if (rdmsrq_safe(address, &val.q))
 				break;
 
-			if (!(high & MASK_VALID_HI))
+			if (!(val.h & MASK_VALID_HI))
 				continue;
 
-			if (!(high & MASK_CNTP_HI)  ||
-			     (high & MASK_LOCKED_HI))
+			if (!(val.h & MASK_CNTP_HI)  ||
+			     (val.h & MASK_LOCKED_HI))
 				continue;
 
-			offset = prepare_threshold_block(bank, block, address, offset, high);
+			offset = prepare_threshold_block(bank, block, address, offset, val.h);
 		}
 	}
 }
@@ -1083,24 +1084,24 @@ static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb
 				     u32 address)
 {
 	struct threshold_block *b = NULL;
-	u32 low, high;
+	struct msr val;
 	int err;
 
 	if ((bank >= this_cpu_read(mce_num_banks)) || (block >= NR_BLOCKS))
 		return 0;
 
-	if (rdmsr_safe(address, &low, &high))
+	if (rdmsrq_safe(address, &val.q))
 		return 0;
 
-	if (!(high & MASK_VALID_HI)) {
+	if (!(val.h & MASK_VALID_HI)) {
 		if (block)
 			goto recurse;
 		else
 			return 0;
 	}
 
-	if (!(high & MASK_CNTP_HI)  ||
-	     (high & MASK_LOCKED_HI))
+	if (!(val.h & MASK_CNTP_HI)  ||
+	     (val.h & MASK_LOCKED_HI))
 		goto recurse;
 
 	b = kzalloc_obj(struct threshold_block);
@@ -1112,7 +1113,7 @@ static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb
 	b->cpu			= cpu;
 	b->address		= address;
 	b->interrupt_enable	= 0;
-	b->interrupt_capable	= lvt_interrupt_supported(bank, high);
+	b->interrupt_capable	= lvt_interrupt_supported(bank, val.h);
 	b->threshold_limit	= get_thr_limit();
 
 	if (b->interrupt_capable) {
@@ -1124,13 +1125,13 @@ static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb
 
 	list_add(&b->miscj, &tb->miscj);
 
-	mce_threshold_block_init(b, (high & MASK_LVTOFF_HI) >> 20);
+	mce_threshold_block_init(b, (val.h & MASK_LVTOFF_HI) >> 20);
 
 	err = kobject_init_and_add(&b->kobj, &threshold_ktype, tb->kobj, get_name(cpu, bank, b));
 	if (err)
 		goto out_free;
 recurse:
-	address = get_block_address(address, low, high, bank, ++block, cpu);
+	address = get_block_address(address, val.l, val.h, bank, ++block, cpu);
 	if (!address)
 		return 0;
 
arch/x86/kernel/cpu/mce/core.c +1 -1
index 9bba1e2..017aaf5 100644
@@ -1866,7 +1866,7 @@ static void __mcheck_cpu_init_generic(void)
 
 	rdmsrq(MSR_IA32_MCG_CAP, cap);
 	if (cap & MCG_CTL_P)
-		wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
+		wrmsrq(MSR_IA32_MCG_CTL, ~0ULL);
 }
 
 static void __mcheck_cpu_init_prepare_banks(void)
arch/x86/kernel/cpu/mce/p5.c +8 -8
index 2272ad5..eb99f38 100644
@@ -23,16 +23,16 @@ int mce_p5_enabled __read_mostly;
 /* Machine check handler for Pentium class Intel CPUs: */
 noinstr void pentium_machine_check(struct pt_regs *regs)
 {
-	u32 loaddr, hi, lotype;
+	u64 addr, type;
 
 	instrumentation_begin();
-	rdmsr(MSR_IA32_P5_MC_ADDR, loaddr, hi);
-	rdmsr(MSR_IA32_P5_MC_TYPE, lotype, hi);
+	rdmsrq(MSR_IA32_P5_MC_ADDR, addr);
+	rdmsrq(MSR_IA32_P5_MC_TYPE, type);
 
 	pr_emerg("CPU#%d: Machine Check Exception:  0x%8X (type 0x%8X).\n",
-		 smp_processor_id(), loaddr, lotype);
+		 smp_processor_id(), (u32)addr, (u32)type);
 
-	if (lotype & (1<<5)) {
+	if (type & (1<<5)) {
 		pr_emerg("CPU#%d: Possible thermal failure (CPU on fire ?).\n",
 			 smp_processor_id());
 	}
@@ -44,7 +44,7 @@ noinstr void pentium_machine_check(struct pt_regs *regs)
 /* Set up machine check reporting for processors with Intel style MCE: */
 void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
 {
-	u32 l, h;
+	u64 q;
 
 	/* Default P5 to off as its often misconnected: */
 	if (!mce_p5_enabled)
@@ -55,8 +55,8 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
 		return;
 
 	/* Read registers before enabling: */
-	rdmsr(MSR_IA32_P5_MC_ADDR, l, h);
-	rdmsr(MSR_IA32_P5_MC_TYPE, l, h);
+	rdmsrq(MSR_IA32_P5_MC_ADDR, q);
+	rdmsrq(MSR_IA32_P5_MC_TYPE, q);
 	pr_info("Intel old style machine check architecture supported.\n");
 
 	/* Enable MCE: */
arch/x86/kernel/cpu/mce/winchip.c +5 -5
index 6c99f29..7040243 100644
@@ -28,12 +28,12 @@ noinstr void winchip_machine_check(struct pt_regs *regs)
 /* Set up machine check reporting on the Winchip C6 series */
 void winchip_mcheck_init(struct cpuinfo_x86 *c)
 {
-	u32 lo, hi;
+	struct msr val;
 
-	rdmsr(MSR_IDT_FCR1, lo, hi);
-	lo |= (1<<2);	/* Enable EIERRINT (int 18 MCE) */
-	lo &= ~(1<<4);	/* Enable MCE */
-	wrmsr(MSR_IDT_FCR1, lo, hi);
+	rdmsrq(MSR_IDT_FCR1, val.q);
+	val.l |= (1<<2);	/* Enable EIERRINT (int 18 MCE) */
+	val.l &= ~(1<<4);	/* Enable MCE */
+	wrmsrq(MSR_IDT_FCR1, val.q);
 
 	cr4_set_bits(X86_CR4_MCE);
 
author maintainer
#38 lore raw

PATCH 1/1 x86/mce: Fix build warning after MSR-interface switch

In reply to Juergen Gross

The recent switch to 64-bit MSR interfaces introduced a build warning.

Fix it.

Fixes cff219368bd0 ("x86/mce: Stop using 32-bit MSR interfaces")

---
Said patch is in tip only right now, so this patch could either be added on top or be folded into the original patch.

---
 arch/x86/kernel/cpu/mce/p5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/p5.c +1 -1
index eb99f384d747..3c2b6cc918b1 100644
@@ -44,7 +44,7 @@ noinstr void pentium_machine_check(struct pt_regs *regs)
 /* Set up machine check reporting for processors with Intel style MCE: */
 void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
 {
-	u64 q;
+	u64 __maybe_unused q;
 
 	/* Default P5 to off as its often misconnected: */
 	if (!mce_p5_enabled)
Signature · 1 line
2.54.0
#39 lore raw

Re: [PATCH] x86/mce: Fix build warning after MSR-interface switch

Quoted 20 lines · Juergen Gross

The recent switch to 64-bit MSR interfaces introduced a build warning.

Fix it.

Fixes cff219368bd0 ("x86/mce: Stop using 32-bit MSR interfaces")

---
Said patch is in tip only right now, so this patch could either be added on top or be folded into the original patch.

---
 arch/x86/kernel/cpu/mce/p5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/p5.c +0 -0
index eb99f384d747..3c2b6cc918b1 100644

arch/x86/kernel/cpu/mce/p5.c noinstr void pentium_machine_check(struct pt_regs *regs) · line 47

Quoted 5 lines
arch/x86/kernel/cpu/mce/p5.c +1 -1
@@ -44,7 +44,7 @@ noinstr void pentium_machine_check(struct pt_regs *regs)
 /* Set up machine check reporting for processors with Intel style MCE: */
 void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
 {
-	u64 q;
+	u64 __maybe_unused q;

Could we just fix the API to always assign 'q', instead of this ugly & vague annotation?

Thanks,

Ingo

author maintainer
#40 lore raw

Re: [PATCH] x86/mce: Fix build warning after MSR-interface switch

Quoted 18 lines · Ingo Molnar
Quoted 15 lines · Juergen Gross

The recent switch to 64-bit MSR interfaces introduced a build warning.

Fix it.

Fixes cff219368bd0 ("x86/mce: Stop using 32-bit MSR interfaces")

---
Said patch is in tip only right now, so this patch could either be added on top or be folded into the original patch.

---
  arch/x86/kernel/cpu/mce/p5.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

arch/x86/kernel/cpu/mce/p5.c noinstr void pentium_machine_check(struct pt_regs *regs) · line 47

Quoted 10 lines
arch/x86/kernel/cpu/mce/p5.c +1 -1
index eb99f384d747..3c2b6cc918b1 100644
@@ -44,7 +44,7 @@ noinstr void pentium_machine_check(struct pt_regs *regs)
  /* Set up machine check reporting for processors with Intel style MCE: */
  void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
  {
-	u64 q;
+	u64 __maybe_unused q;

Could we just fix the API to always assign 'q', instead of this ugly & vague annotation?

q is always assigned. I believe the problem is that it is never read.

OTOH this problem can be fixed easily after patch 31 of this series. I can send a V2 of patch 32 to just drop the assignment to q. This will be possible as rdmsrq() will be a function then, and not a macro requiring a variable being passed as parameter.

Juergen

#41 lore raw

Re: [PATCH] x86/mce: Fix build warning after MSR-interface switch

Quoted 33 lines · Jürgen Groß
Quoted 18 lines · Ingo Molnar
Quoted 15 lines · Juergen Gross

The recent switch to 64-bit MSR interfaces introduced a build warning.

Fix it.

Fixes cff219368bd0 ("x86/mce: Stop using 32-bit MSR interfaces")

---
Said patch is in tip only right now, so this patch could either be added on top or be folded into the original patch.

---
  arch/x86/kernel/cpu/mce/p5.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

arch/x86/kernel/cpu/mce/p5.c noinstr void pentium_machine_check(struct pt_regs *regs) · line 47

Quoted 10 lines
arch/x86/kernel/cpu/mce/p5.c +1 -1
index eb99f384d747..3c2b6cc918b1 100644
@@ -44,7 +44,7 @@ noinstr void pentium_machine_check(struct pt_regs *regs)
  /* Set up machine check reporting for processors with Intel style MCE: */
  void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
  {
-	u64 q;
+	u64 __maybe_unused q;

Could we just fix the API to always assign 'q', instead of this ugly & vague annotation?

Quoted 1 line

q is always assigned. I believe the problem is that it is never read.

Indeed.

Quoted 4 lines

OTOH this problem can be fixed easily after patch 31 of this series. I can send a V2 of patch 32 to just drop the assignment to q. This will be possible as rdmsrq() will be a function then, and not a macro requiring a variable being passed as parameter.

That's fine with me, as long as the build failure is only for this i386 randconfig. If a new warning is generated for any of the more prominent configs we'll have to make it go away for the interim tree. (Because it's still not 100% clear whether we'll be able to do patch 31 in this cycle.)

Thanks,

Ingo

author maintainer
#42 lore raw

Re: [PATCH] x86/mce: Fix build warning after MSR-interface switch

Quoted 45 lines · Ingo Molnar
Quoted 33 lines · Jürgen Groß
Quoted 18 lines · Ingo Molnar
Quoted 15 lines · Juergen Gross

The recent switch to 64-bit MSR interfaces introduced a build warning.

Fix it.

Fixes cff219368bd0 ("x86/mce: Stop using 32-bit MSR interfaces")

---
Said patch is in tip only right now, so this patch could either be added on top or be folded into the original patch.

---
   arch/x86/kernel/cpu/mce/p5.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

arch/x86/kernel/cpu/mce/p5.c noinstr void pentium_machine_check(struct pt_regs *regs) · line 47

Quoted 10 lines
arch/x86/kernel/cpu/mce/p5.c +1 -1
index eb99f384d747..3c2b6cc918b1 100644
@@ -44,7 +44,7 @@ noinstr void pentium_machine_check(struct pt_regs *regs)
   /* Set up machine check reporting for processors with Intel style MCE: */
   void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
   {
-	u64 q;
+	u64 __maybe_unused q;

Could we just fix the API to always assign 'q', instead of this ugly & vague annotation?

Quoted 1 line

q is always assigned. I believe the problem is that it is never read.

Indeed.

Quoted 4 lines

OTOH this problem can be fixed easily after patch 31 of this series. I can send a V2 of patch 32 to just drop the assignment to q. This will be possible as rdmsrq() will be a function then, and not a macro requiring a variable being passed as parameter.

Quoted 5 lines

That's fine with me, as long as the build failure is only for this i386 randconfig. If a new warning is generated for any of the more prominent configs we'll have to make it go away for the interim tree. (Because it's still not 100% clear whether we'll be able to do patch 31 in this cycle.)

You have my patch for that case. :-)

Juergen

merge bot Applied
#43 lore raw

[tip: x86/msr] x86/mce: Work around build warning after MSR-interface switch

In reply to Juergen Gross
The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     a7187ca1e72505fd6785b0ce537ae066773a5532
Gitweb:        https://git.kernel.org/tip/a7187ca1e72505fd6785b0ce537ae066773a5532
Author:        Juergen Gross <[email protected]>
AuthorDate:    Fri, 03 Jul 2026 12:55:55 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Sun, 19 Jul 2026 11:39:18 +02:00

x86/mce: Work around build warning after MSR-interface switch

The recent switch to 64-bit MSR interfaces introduced a build warning.

Work it around with a __maybe_unused annotation. After the full conversion of the APIs we'll be able to address this more robustly by making sure the APIs consume all the values as far the compiler is concerned, so that the compiler doesn't emit such nuisance warnings.

[ mingo: Updated the changelog. ]

---
 arch/x86/kernel/cpu/mce/p5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/p5.c +1 -1
index eb99f38..3c2b6cc 100644
@@ -44,7 +44,7 @@ noinstr void pentium_machine_check(struct pt_regs *regs)
 /* Set up machine check reporting for processors with Intel style MCE: */
 void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
 {
-	u64 q;
+	u64 __maybe_unused q;
 
 	/* Default P5 to off as its often misconnected: */
 	if (!mce_p5_enabled)
author maintainer
#44 lore raw

PATCH 9/32 KVM/x86: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kvm/vmx/vmx.c      | 24 +++++++++++++-----------
 arch/x86/kvm/x86.c          |  4 ++--
 arch/x86/virt/vmx/tdx/tdx.c |  6 ++++--
 3 files changed, 19 insertions(+), 15 deletions(-)
arch/x86/kvm/vmx/vmx.c +13 -11
index 2325be57d3d7..49948bbaf2de 100644
@@ -2676,13 +2676,13 @@ static bool cpu_has_sgx(void)
 
 static int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, u32 msr, u32 *result)
 {
-	u32 vmx_msr_low, vmx_msr_high;
+	struct msr vmx_msr;
 	u32 ctl = ctl_min | ctl_opt;
 
-	rdmsr(msr, vmx_msr_low, vmx_msr_high);
+	rdmsrq(msr, vmx_msr.q);
 
-	ctl &= vmx_msr_high; /* bit == 0 in high word ==> must be zero */
-	ctl |= vmx_msr_low;  /* bit == 1 in low word  ==> must be one  */
+	ctl &= vmx_msr.h;  /* bit == 0 in high word ==> must be zero */
+	ctl |= vmx_msr.l;  /* bit == 1 in low word  ==> must be one  */
 
 	/* Ensure minimum (required) set of control bits are supported. */
 	if (ctl_min & ~ctl)
@@ -2738,6 +2738,7 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 	u64 _cpu_based_3rd_exec_control = 0;
 	u32 _vmexit_control = 0;
 	u32 _vmentry_control = 0;
+	struct msr val;
 	u64 basic_msr;
 	u64 misc_msr;
 
@@ -2787,8 +2788,9 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 				SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE |
 				SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY);
 
-	rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP,
-		&vmx_cap->ept, &vmx_cap->vpid);
+	rdmsrq_safe(MSR_IA32_VMX_EPT_VPID_CAP, &val.q);
+	vmx_cap->ept = val.l;
+	vmx_cap->vpid = val.h;
 
 	if (!(_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_EPT) &&
 	    vmx_cap->ept) {
@@ -4435,7 +4437,7 @@ void vmx_deliver_interrupt(struct kvm_lapic *apic, int delivery_mode,
  */
 void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
 {
-	u32 low32, high32;
+	struct msr val;
 	unsigned long tmpl;
 	unsigned long cr0, cr3, cr4;
 
@@ -4476,8 +4478,8 @@ void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
 
 	vmcs_writel(HOST_RIP, (unsigned long)vmx_vmexit); /* 22.2.5 */
 
-	rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
-	vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
+	rdmsrq(MSR_IA32_SYSENTER_CS, val.q);
+	vmcs_write32(HOST_IA32_SYSENTER_CS, val.l);
 
 	/*
 	 * SYSENTER is used for 32-bit system calls on either 32-bit or
@@ -4492,8 +4494,8 @@ void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
 	vmcs_writel(HOST_IA32_SYSENTER_EIP, tmpl);   /* 22.2.3 */
 
 	if (vmcs_config.vmexit_ctrl & VM_EXIT_LOAD_IA32_PAT) {
-		rdmsr(MSR_IA32_CR_PAT, low32, high32);
-		vmcs_write64(HOST_IA32_PAT, low32 | ((u64) high32 << 32));
+		rdmsrq(MSR_IA32_CR_PAT, val.q);
+		vmcs_write64(HOST_IA32_PAT, val.q);
 	}
 
 	if (cpu_has_load_ia32_efer())
arch/x86/kvm/x86.c +2 -2
index afcac1042947..9b645563ece9 100644
@@ -7633,9 +7633,9 @@ static void kvm_probe_feature_msr(u32 msr_index)
 
 static void kvm_probe_msr_to_save(u32 msr_index)
 {
-	u32 dummy[2];
+	u64 dummy;
 
-	if (rdmsr_safe(msr_index, &dummy[0], &dummy[1]))
+	if (rdmsrq_safe(msr_index, &dummy))
 		return;
 
 	/*
arch/x86/virt/vmx/tdx/tdx.c +4 -2
index 42df8ea464c4..1b9ff749dd8e 100644
@@ -1430,6 +1430,7 @@ static __init int record_keyid_partitioning(u32 *tdx_keyid_start,
 					    u32 *nr_tdx_keyids)
 {
 	u32 _nr_mktme_keyids, _tdx_keyid_start, _nr_tdx_keyids;
+	struct msr val;
 	int ret;
 
 	/*
@@ -1437,8 +1438,9 @@ static __init int record_keyid_partitioning(u32 *tdx_keyid_start,
 	 *   Bit [31:0]:	Number of MKTME KeyIDs.
 	 *   Bit [63:32]:	Number of TDX private KeyIDs.
 	 */
-	ret = rdmsr_safe(MSR_IA32_MKTME_KEYID_PARTITIONING, &_nr_mktme_keyids,
-			&_nr_tdx_keyids);
+	ret = rdmsrq_safe(MSR_IA32_MKTME_KEYID_PARTITIONING, &val.q);
+	_nr_mktme_keyids = val.l;
+	_nr_tdx_keyids = val.h;
 	if (ret || !_nr_tdx_keyids)
 		return -EINVAL;
 
Signature · 1 line
2.54.0
merge bot Applied
#45 lore raw

[tip: x86/msr] KVM/x86: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     1620ddc0dcefc6ffb85f4718086e880335d1a7f5
Gitweb:        https://git.kernel.org/tip/1620ddc0dcefc6ffb85f4718086e880335d1a7f5
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:00 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 17 Jul 2026 11:30:00 +02:00

KVM/x86: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr(), wrmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

No change in functionality intended.

---
 arch/x86/kvm/vmx/vmx.c      | 24 +++++++++++++-----------
 arch/x86/kvm/x86.c          |  4 ++--
 arch/x86/virt/vmx/tdx/tdx.c |  6 ++++--
 3 files changed, 19 insertions(+), 15 deletions(-)
arch/x86/kvm/vmx/vmx.c +13 -11
index 2325be5..49948bb 100644
@@ -2676,13 +2676,13 @@ static bool cpu_has_sgx(void)
 
 static int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, u32 msr, u32 *result)
 {
-	u32 vmx_msr_low, vmx_msr_high;
+	struct msr vmx_msr;
 	u32 ctl = ctl_min | ctl_opt;
 
-	rdmsr(msr, vmx_msr_low, vmx_msr_high);
+	rdmsrq(msr, vmx_msr.q);
 
-	ctl &= vmx_msr_high; /* bit == 0 in high word ==> must be zero */
-	ctl |= vmx_msr_low;  /* bit == 1 in low word  ==> must be one  */
+	ctl &= vmx_msr.h;  /* bit == 0 in high word ==> must be zero */
+	ctl |= vmx_msr.l;  /* bit == 1 in low word  ==> must be one  */
 
 	/* Ensure minimum (required) set of control bits are supported. */
 	if (ctl_min & ~ctl)
@@ -2738,6 +2738,7 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 	u64 _cpu_based_3rd_exec_control = 0;
 	u32 _vmexit_control = 0;
 	u32 _vmentry_control = 0;
+	struct msr val;
 	u64 basic_msr;
 	u64 misc_msr;
 
@@ -2787,8 +2788,9 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 				SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE |
 				SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY);
 
-	rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP,
-		&vmx_cap->ept, &vmx_cap->vpid);
+	rdmsrq_safe(MSR_IA32_VMX_EPT_VPID_CAP, &val.q);
+	vmx_cap->ept = val.l;
+	vmx_cap->vpid = val.h;
 
 	if (!(_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_EPT) &&
 	    vmx_cap->ept) {
@@ -4435,7 +4437,7 @@ void vmx_deliver_interrupt(struct kvm_lapic *apic, int delivery_mode,
  */
 void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
 {
-	u32 low32, high32;
+	struct msr val;
 	unsigned long tmpl;
 	unsigned long cr0, cr3, cr4;
 
@@ -4476,8 +4478,8 @@ void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
 
 	vmcs_writel(HOST_RIP, (unsigned long)vmx_vmexit); /* 22.2.5 */
 
-	rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
-	vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
+	rdmsrq(MSR_IA32_SYSENTER_CS, val.q);
+	vmcs_write32(HOST_IA32_SYSENTER_CS, val.l);
 
 	/*
 	 * SYSENTER is used for 32-bit system calls on either 32-bit or
@@ -4492,8 +4494,8 @@ void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
 	vmcs_writel(HOST_IA32_SYSENTER_EIP, tmpl);   /* 22.2.3 */
 
 	if (vmcs_config.vmexit_ctrl & VM_EXIT_LOAD_IA32_PAT) {
-		rdmsr(MSR_IA32_CR_PAT, low32, high32);
-		vmcs_write64(HOST_IA32_PAT, low32 | ((u64) high32 << 32));
+		rdmsrq(MSR_IA32_CR_PAT, val.q);
+		vmcs_write64(HOST_IA32_PAT, val.q);
 	}
 
 	if (cpu_has_load_ia32_efer())
arch/x86/kvm/x86.c +2 -2
index afcac10..9b64556 100644
@@ -7633,9 +7633,9 @@ static void kvm_probe_feature_msr(u32 msr_index)
 
 static void kvm_probe_msr_to_save(u32 msr_index)
 {
-	u32 dummy[2];
+	u64 dummy;
 
-	if (rdmsr_safe(msr_index, &dummy[0], &dummy[1]))
+	if (rdmsrq_safe(msr_index, &dummy))
 		return;
 
 	/*
arch/x86/virt/vmx/tdx/tdx.c +4 -2
index 42df8ea..1b9ff74 100644
@@ -1430,6 +1430,7 @@ static __init int record_keyid_partitioning(u32 *tdx_keyid_start,
 					    u32 *nr_tdx_keyids)
 {
 	u32 _nr_mktme_keyids, _tdx_keyid_start, _nr_tdx_keyids;
+	struct msr val;
 	int ret;
 
 	/*
@@ -1437,8 +1438,9 @@ static __init int record_keyid_partitioning(u32 *tdx_keyid_start,
 	 *   Bit [31:0]:	Number of MKTME KeyIDs.
 	 *   Bit [63:32]:	Number of TDX private KeyIDs.
 	 */
-	ret = rdmsr_safe(MSR_IA32_MKTME_KEYID_PARTITIONING, &_nr_mktme_keyids,
-			&_nr_tdx_keyids);
+	ret = rdmsrq_safe(MSR_IA32_MKTME_KEYID_PARTITIONING, &val.q);
+	_nr_mktme_keyids = val.l;
+	_nr_tdx_keyids = val.h;
 	if (ret || !_nr_tdx_keyids)
 		return -EINVAL;
 
author maintainer
#46 lore raw

PATCH 10/32 x86/hygon: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interface rdmsr_safe()is planned to be removed. Use the related 64-bit variant instead.

---
 arch/x86/kernel/cpu/hygon.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/hygon.c +3 -2
index 3e8891a9caf2..ec51c2b9a257 100644
@@ -125,11 +125,12 @@ static void bsp_init_hygon(struct cpuinfo_x86 *c)
 
 static void early_init_hygon(struct cpuinfo_x86 *c)
 {
-	u32 dummy;
+	u64 val;
 
 	set_cpu_cap(c, X86_FEATURE_K8);
 
-	rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy);
+	rdmsrq_safe(MSR_AMD64_PATCH_LEVEL, &val);
+	c->microcode = (u32)val;
 
 	/*
 	 * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
Signature · 1 line
2.54.0
merge bot Applied
#47 lore raw

[tip: x86/msr] x86/hygon: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     c36c3d7e5dc49f0085e26ee4bcd2cb6493b0120e
Gitweb:        https://git.kernel.org/tip/c36c3d7e5dc49f0085e26ee4bcd2cb6493b0120e
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:01 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:51 +02:00

x86/hygon: Stop using 32-bit MSR interfaces

The 32-bit MSR interface rdmsr_safe()is planned to be removed. Use the related 64-bit variant instead.

---
 arch/x86/kernel/cpu/hygon.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/hygon.c +3 -2
index 3e8891a..ec51c2b 100644
@@ -125,11 +125,12 @@ static void bsp_init_hygon(struct cpuinfo_x86 *c)
 
 static void early_init_hygon(struct cpuinfo_x86 *c)
 {
-	u32 dummy;
+	u64 val;
 
 	set_cpu_cap(c, X86_FEATURE_K8);
 
-	rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy);
+	rdmsrq_safe(MSR_AMD64_PATCH_LEVEL, &val);
+	c->microcode = (u32)val;
 
 	/*
 	 * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
author maintainer
#48 lore raw

PATCH 11/32 x86/pci: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interface rdmsr_safe()is planned to be removed. Use the related 64-bit variant instead.

---
 arch/x86/pci/mmconfig-shared.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/pci/mmconfig-shared.c +2 -6
index acdb8dcaeb52..9749820f68f7 100644
@@ -189,7 +189,7 @@ static const char *__init pci_mmcfg_intel_945(void)
 
 static const char *__init pci_mmcfg_amd_fam10h(void)
 {
-	u32 low, high, address;
+	u32 address;
 	u64 base, msr;
 	int i;
 	unsigned segnbits = 0, busnbits, end_bus;
@@ -198,13 +198,9 @@ static const char *__init pci_mmcfg_amd_fam10h(void)
 		return NULL;
 
 	address = MSR_FAM10H_MMIO_CONF_BASE;
-	if (rdmsr_safe(address, &low, &high))
+	if (rdmsrq_safe(address, &msr))
 		return NULL;
 
-	msr = high;
-	msr <<= 32;
-	msr |= low;
-
 	/* ECAM is not enabled */
 	if (!(msr & FAM10H_MMIO_CONF_ENABLE))
 		return NULL;
Signature · 1 line
2.54.0
#49 lore raw

Re: [PATCH 11/32] x86/pci: Stop using 32-bit MSR interfaces

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines

The 32-bit MSR interface rdmsr_safe()is planned to be removed. Use the related 64-bit variant instead.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
merge bot Applied
#50 lore raw

[tip: x86/msr] x86/pci: Stop using 32-bit MSR interfaces

In reply to Juergen Gross
The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     b67096f9dbbb4295c892e266a80b816f24c32f7c
Gitweb:        https://git.kernel.org/tip/b67096f9dbbb4295c892e266a80b816f24c32f7c
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:02 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:52 +02:00

x86/pci: Stop using 32-bit MSR interfaces

The 32-bit MSR interface rdmsr_safe()is planned to be removed. Use the related 64-bit variant instead.

---
 arch/x86/pci/mmconfig-shared.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/pci/mmconfig-shared.c +2 -6
index acdb8dc..9749820 100644
@@ -189,7 +189,7 @@ static const char *__init pci_mmcfg_intel_945(void)
 
 static const char *__init pci_mmcfg_amd_fam10h(void)
 {
-	u32 low, high, address;
+	u32 address;
 	u64 base, msr;
 	int i;
 	unsigned segnbits = 0, busnbits, end_bus;
@@ -198,13 +198,9 @@ static const char *__init pci_mmcfg_amd_fam10h(void)
 		return NULL;
 
 	address = MSR_FAM10H_MMIO_CONF_BASE;
-	if (rdmsr_safe(address, &low, &high))
+	if (rdmsrq_safe(address, &msr))
 		return NULL;
 
-	msr = high;
-	msr <<= 32;
-	msr |= low;
-
 	/* ECAM is not enabled */
 	if (!(msr & FAM10H_MMIO_CONF_ENABLE))
 		return NULL;
#51 lore raw

Re: [tip: x86/msr] x86/pci: Stop using 32-bit MSR interfaces

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Calculation of the segment address overflows when the number of bus bits causes i to reach 8 or more. --

commit 67dc02af5b380e39ab1fd3fd3aa7e4552b01de23
Author: Juergen Gross <[email protected]>
Subject: x86/pci: Stop using 32-bit MSR interfaces

This commit replaces the 32-bit rdmsr_safe() MSR interface with the 64-bit variant rdmsrq_safe() in the AMD Family 10h PCI MMConfig initialization code. This simplifies the logic by directly fetching the 64-bit MSR value.

Quoted 3 lines
arch/x86/pci/mmconfig-shared.c +0 -0

[ ... ]

Quoted 15 lines
arch/x86/pci/mmconfig-shared.c +1 -5
@@ -198,13 +198,9 @@ static const char *__init pci_mmcfg_amd_fam10h(void)
 		return NULL;
 
 	address = MSR_FAM10H_MMIO_CONF_BASE;
-	if (rdmsr_safe(address, &low, &high))
+	if (rdmsrq_safe(address, &msr))
 		return NULL;
 
-	msr = high;
-	msr <<= 32;
-	msr |= low;
-
 	/* ECAM is not enabled */
 	if (!(msr & FAM10H_MMIO_CONF_ENABLE))
 		return NULL;

[ ... ]

Quoted 4 lines
	end_bus = (1 << busnbits) - 1;
	for (i = 0; i < (1 << segnbits); i++)
		if (pci_mmconfig_add(i, 0, end_bus,
				     base + (1<<28) * i) == NULL) {

[Severity: High]
This isn't a bug introduced by this patch, but does this calculation overflow when i reaches 8 or more in pci_mmcfg_amd_fam10h()?

The expression (1<<28) * i uses 32-bit signed arithmetic. When i >= 8, the result reaches 2147483648, which exceeds INT_MAX and overflows to -2147483648.

Because base is a 64-bit value, this negative number will be sign-extended and subtracted from the base instead of added to it.

If busnbits from the MSR is 12 or greater, segnbits will be 4 or more, allowing the loop variable i to reach 8 and trigger this overflow.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/178298736191.3843924.4213710231240809260.tip-bot2@tip-bot2?part=1
author maintainer
#52 lore raw

PATCH 12/32 x86/amd: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr(), wrmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/amd.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/amd.c +18 -16
index 487ac147e11f..169e373418bb 100644
@@ -113,7 +113,7 @@ static void init_amd_k5(struct cpuinfo_x86 *c)
 static void init_amd_k6(struct cpuinfo_x86 *c)
 {
 #ifdef CONFIG_X86_32
-	u32 l, h;
+	struct msr val;
 	int mbytes = get_num_physpages() >> (20-PAGE_SHIFT);
 
 	if (c->x86_model < 6) {
@@ -160,13 +160,13 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
 		if (mbytes > 508)
 			mbytes = 508;
 
-		rdmsr(MSR_K6_WHCR, l, h);
-		if ((l&0x0000FFFF) == 0) {
+		rdmsrq(MSR_K6_WHCR, val.q);
+		if ((val.l & 0x0000FFFF) == 0) {
 			unsigned long flags;
-			l = (1<<0)|((mbytes/4)<<1);
+			val.l = (1 << 0) | ((mbytes / 4) << 1);
 			local_irq_save(flags);
 			wbinvd();
-			wrmsr(MSR_K6_WHCR, l, h);
+			wrmsrq(MSR_K6_WHCR, val.q);
 			local_irq_restore(flags);
 			pr_info("Enabling old style K6 write allocation for %d Mb\n",
 				mbytes);
@@ -181,13 +181,13 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
 		if (mbytes > 4092)
 			mbytes = 4092;
 
-		rdmsr(MSR_K6_WHCR, l, h);
-		if ((l&0xFFFF0000) == 0) {
+		rdmsrq(MSR_K6_WHCR, val.q);
+		if ((val.l & 0xFFFF0000) == 0) {
 			unsigned long flags;
-			l = ((mbytes>>2)<<22)|(1<<16);
+			val.l = ((mbytes >> 2) << 22) | (1 << 16);
 			local_irq_save(flags);
 			wbinvd();
-			wrmsr(MSR_K6_WHCR, l, h);
+			wrmsrq(MSR_K6_WHCR, val.q);
 			local_irq_restore(flags);
 			pr_info("Enabling new style K6 write allocation for %d Mb\n",
 				mbytes);
@@ -207,7 +207,7 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
 static void init_amd_k7(struct cpuinfo_x86 *c)
 {
 #ifdef CONFIG_X86_32
-	u32 l, h;
+	struct msr val;
 
 	/*
 	 * Bit 15 of Athlon specific MSR 15, needs to be 0
@@ -228,11 +228,12 @@ static void init_amd_k7(struct cpuinfo_x86 *c)
 	 * As per AMD technical note 27212 0.2
 	 */
 	if ((c->x86_model == 8 && c->x86_stepping >= 1) || (c->x86_model > 8)) {
-		rdmsr(MSR_K7_CLK_CTL, l, h);
-		if ((l & 0xfff00000) != 0x20000000) {
+		rdmsrq(MSR_K7_CLK_CTL, val.q);
+		if ((val.l & 0xfff00000) != 0x20000000) {
 			pr_info("CPU: CLK_CTL MSR was %x. Reprogramming to %x\n",
-				l, ((l & 0x000fffff)|0x20000000));
-			wrmsr(MSR_K7_CLK_CTL, (l & 0x000fffff)|0x20000000, h);
+				val.l, ((val.l & 0x000fffff) | 0x20000000));
+			val.l = (val.l & 0x000fffff) | 0x20000000;
+			wrmsrq(MSR_K7_CLK_CTL, val.q);
 		}
 	}
 
@@ -614,12 +615,13 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86 *c)
 
 static void early_init_amd(struct cpuinfo_x86 *c)
 {
-	u32 dummy;
+	u64 val;
 
 	if (c->x86 >= 0xf)
 		set_cpu_cap(c, X86_FEATURE_K8);
 
-	rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy);
+	rdmsrq_safe(MSR_AMD64_PATCH_LEVEL, &val);
+	c->microcode = (u32)val;
 
 	/*
 	 * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
Signature · 1 line
2.54.0
merge bot Applied
#53 lore raw

[tip: x86/msr] x86/amd: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     9c6be5e789818f6577507ce42fc4b70f0fd44303
Gitweb:        https://git.kernel.org/tip/9c6be5e789818f6577507ce42fc4b70f0fd44303
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:03 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:52 +02:00

x86/amd: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr(), wrmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/amd.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/amd.c +18 -16
index 487ac14..169e373 100644
@@ -113,7 +113,7 @@ static void init_amd_k5(struct cpuinfo_x86 *c)
 static void init_amd_k6(struct cpuinfo_x86 *c)
 {
 #ifdef CONFIG_X86_32
-	u32 l, h;
+	struct msr val;
 	int mbytes = get_num_physpages() >> (20-PAGE_SHIFT);
 
 	if (c->x86_model < 6) {
@@ -160,13 +160,13 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
 		if (mbytes > 508)
 			mbytes = 508;
 
-		rdmsr(MSR_K6_WHCR, l, h);
-		if ((l&0x0000FFFF) == 0) {
+		rdmsrq(MSR_K6_WHCR, val.q);
+		if ((val.l & 0x0000FFFF) == 0) {
 			unsigned long flags;
-			l = (1<<0)|((mbytes/4)<<1);
+			val.l = (1 << 0) | ((mbytes / 4) << 1);
 			local_irq_save(flags);
 			wbinvd();
-			wrmsr(MSR_K6_WHCR, l, h);
+			wrmsrq(MSR_K6_WHCR, val.q);
 			local_irq_restore(flags);
 			pr_info("Enabling old style K6 write allocation for %d Mb\n",
 				mbytes);
@@ -181,13 +181,13 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
 		if (mbytes > 4092)
 			mbytes = 4092;
 
-		rdmsr(MSR_K6_WHCR, l, h);
-		if ((l&0xFFFF0000) == 0) {
+		rdmsrq(MSR_K6_WHCR, val.q);
+		if ((val.l & 0xFFFF0000) == 0) {
 			unsigned long flags;
-			l = ((mbytes>>2)<<22)|(1<<16);
+			val.l = ((mbytes >> 2) << 22) | (1 << 16);
 			local_irq_save(flags);
 			wbinvd();
-			wrmsr(MSR_K6_WHCR, l, h);
+			wrmsrq(MSR_K6_WHCR, val.q);
 			local_irq_restore(flags);
 			pr_info("Enabling new style K6 write allocation for %d Mb\n",
 				mbytes);
@@ -207,7 +207,7 @@ static void init_amd_k6(struct cpuinfo_x86 *c)
 static void init_amd_k7(struct cpuinfo_x86 *c)
 {
 #ifdef CONFIG_X86_32
-	u32 l, h;
+	struct msr val;
 
 	/*
 	 * Bit 15 of Athlon specific MSR 15, needs to be 0
@@ -228,11 +228,12 @@ static void init_amd_k7(struct cpuinfo_x86 *c)
 	 * As per AMD technical note 27212 0.2
 	 */
 	if ((c->x86_model == 8 && c->x86_stepping >= 1) || (c->x86_model > 8)) {
-		rdmsr(MSR_K7_CLK_CTL, l, h);
-		if ((l & 0xfff00000) != 0x20000000) {
+		rdmsrq(MSR_K7_CLK_CTL, val.q);
+		if ((val.l & 0xfff00000) != 0x20000000) {
 			pr_info("CPU: CLK_CTL MSR was %x. Reprogramming to %x\n",
-				l, ((l & 0x000fffff)|0x20000000));
-			wrmsr(MSR_K7_CLK_CTL, (l & 0x000fffff)|0x20000000, h);
+				val.l, ((val.l & 0x000fffff) | 0x20000000));
+			val.l = (val.l & 0x000fffff) | 0x20000000;
+			wrmsrq(MSR_K7_CLK_CTL, val.q);
 		}
 	}
 
@@ -614,12 +615,13 @@ clear_sev:
 
 static void early_init_amd(struct cpuinfo_x86 *c)
 {
-	u32 dummy;
+	u64 val;
 
 	if (c->x86 >= 0xf)
 		set_cpu_cap(c, X86_FEATURE_K8);
 
-	rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy);
+	rdmsrq_safe(MSR_AMD64_PATCH_LEVEL, &val);
+	c->microcode = (u32)val;
 
 	/*
 	 * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
author maintainer
#54 lore raw

PATCH 13/32 x86/featctl: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/feat_ctl.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/feat_ctl.c +16 -11
index d69757246bde..1ce30a5c26ce 100644
@@ -25,7 +25,8 @@ enum vmx_feature_leafs {
 
 static void init_vmx_capabilities(struct cpuinfo_x86 *c)
 {
-	u32 supported, funcs, ept, vpid, ign, low, high;
+	struct msr val;
+	u32 supported, funcs, ept, vpid;
 
 	BUILD_BUG_ON(NVMXINTS != NR_VMX_FEATURE_WORDS);
 
@@ -39,25 +40,29 @@ static void init_vmx_capabilities(struct cpuinfo_x86 *c)
 	 * as they exist on any CPU that supports VMX, i.e. we want the WARN if
 	 * the RDMSR faults.
 	 */
-	rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, ign, supported);
-	c->vmx_capability[PRIMARY_CTLS] = supported;
+	rdmsrq(MSR_IA32_VMX_PROCBASED_CTLS, val.q);
+	c->vmx_capability[PRIMARY_CTLS] = val.h;
 
-	rdmsr_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &ign, &supported);
-	c->vmx_capability[SECONDARY_CTLS] = supported;
+	rdmsrq_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &val.q);
+	c->vmx_capability[SECONDARY_CTLS] = val.h;
 
 	/* All 64 bits of tertiary controls MSR are allowed-1 settings. */
-	rdmsr_safe(MSR_IA32_VMX_PROCBASED_CTLS3, &low, &high);
-	c->vmx_capability[TERTIARY_CTLS_LOW] = low;
-	c->vmx_capability[TERTIARY_CTLS_HIGH] = high;
+	rdmsrq_safe(MSR_IA32_VMX_PROCBASED_CTLS3, &val.q);
+	c->vmx_capability[TERTIARY_CTLS_LOW] = val.l;
+	c->vmx_capability[TERTIARY_CTLS_HIGH] = val.h;
 
-	rdmsr(MSR_IA32_VMX_PINBASED_CTLS, ign, supported);
-	rdmsr_safe(MSR_IA32_VMX_VMFUNC, &ign, &funcs);
+	rdmsrq(MSR_IA32_VMX_PINBASED_CTLS, val.q);
+	supported = val.h;
+	rdmsrq_safe(MSR_IA32_VMX_VMFUNC, &val.q);
+	funcs = val.h;
 
 	/*
 	 * Except for EPT+VPID, which enumerates support for both in a single
 	 * MSR, low for EPT, high for VPID.
 	 */
-	rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP, &ept, &vpid);
+	rdmsrq_safe(MSR_IA32_VMX_EPT_VPID_CAP, &val.q);
+	ept = val.l;
+	vpid = val.h;
 
 	/* Pin, EPT, VPID and VM-Func are merged into a single word. */
 	WARN_ON_ONCE(supported >> 16);
Signature · 1 line
2.54.0
#55 lore raw

Re: [PATCH 13/32] x86/featctl: Stop using 32-bit MSR interfaces

arch/x86/kernel/cpu/feat_ctl.c static void init_vmx_capabilities(struct cpuinfo_x86 *c) · line 44

Quoted 4 lines · Juergen Gross
arch/x86/kernel/cpu/feat_ctl.c +2 -2
-	rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, ign, supported);
-	c->vmx_capability[PRIMARY_CTLS] = supported;
+	rdmsrq(MSR_IA32_VMX_PROCBASED_CTLS, val.q);
+	c->vmx_capability[PRIMARY_CTLS] = val.h;

Please keep the original assignment that puts this into the 'supported' variable - which semi-documents the meaning of this field - even though its use is arguably minimal:

	rdmsrq(MSR_IA32_VMX_PROCBASED_CTLS, val.q);
	supported = val.h;
	c->vmx_capability[PRIMARY_CTLS] = supported;

arch/x86/kernel/cpu/feat_ctl.c static void init_vmx_capabilities(struct cpuinfo_x86 *c) · line 47

Quoted 4 lines
arch/x86/kernel/cpu/feat_ctl.c +2 -2
-	rdmsr_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &ign, &supported);
-	c->vmx_capability[SECONDARY_CTLS] = supported;
+	rdmsrq_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &val.q);
+	c->vmx_capability[SECONDARY_CTLS] = val.h;

Ditto.

Thanks,

Ingo

author maintainer
#56 lore raw

Re: [PATCH 13/32] x86/featctl: Stop using 32-bit MSR interfaces

Quoted 12 lines · Ingo Molnar

arch/x86/kernel/cpu/feat_ctl.c static void init_vmx_capabilities(struct cpuinfo_x86 *c) · line 44

Quoted 4 lines · Juergen Gross
arch/x86/kernel/cpu/feat_ctl.c +2 -2
-	rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, ign, supported);
-	c->vmx_capability[PRIMARY_CTLS] = supported;
+	rdmsrq(MSR_IA32_VMX_PROCBASED_CTLS, val.q);
+	c->vmx_capability[PRIMARY_CTLS] = val.h;

Please keep the original assignment that puts this into the 'supported' variable - which semi-documents the meaning of this field - even though its use is arguably minimal:

Quoted 8 lines
	rdmsrq(MSR_IA32_VMX_PROCBASED_CTLS, val.q);
	supported = val.h;
	c->vmx_capability[PRIMARY_CTLS] = supported;

arch/x86/kernel/cpu/feat_ctl.c static void init_vmx_capabilities(struct cpuinfo_x86 *c) · line 47

Quoted 4 lines
arch/x86/kernel/cpu/feat_ctl.c +2 -2
-	rdmsr_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &ign, &supported);
-	c->vmx_capability[SECONDARY_CTLS] = supported;
+	rdmsrq_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &val.q);
+	c->vmx_capability[SECONDARY_CTLS] = val.h;

Fine with me.

Juergen

author maintainer
#57 lore raw

PATCH v2 13/32 x86/featctl: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
V2:
- keep using "supported" (Ingo Molnar)

---
 arch/x86/kernel/cpu/feat_ctl.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/feat_ctl.c +16 -9
index d69757246bde..10a92927a515 100644
@@ -25,7 +25,8 @@ enum vmx_feature_leafs {
 
 static void init_vmx_capabilities(struct cpuinfo_x86 *c)
 {
-	u32 supported, funcs, ept, vpid, ign, low, high;
+	struct msr val;
+	u32 supported, funcs, ept, vpid;
 
 	BUILD_BUG_ON(NVMXINTS != NR_VMX_FEATURE_WORDS);
 
@@ -39,25 +40,31 @@ static void init_vmx_capabilities(struct cpuinfo_x86 *c)
 	 * as they exist on any CPU that supports VMX, i.e. we want the WARN if
 	 * the RDMSR faults.
 	 */
-	rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, ign, supported);
+	rdmsrq(MSR_IA32_VMX_PROCBASED_CTLS, val.q);
+	supported = val.h;
 	c->vmx_capability[PRIMARY_CTLS] = supported;
 
-	rdmsr_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &ign, &supported);
+	rdmsrq_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &val.q);
+	supported = val.h;
 	c->vmx_capability[SECONDARY_CTLS] = supported;
 
 	/* All 64 bits of tertiary controls MSR are allowed-1 settings. */
-	rdmsr_safe(MSR_IA32_VMX_PROCBASED_CTLS3, &low, &high);
-	c->vmx_capability[TERTIARY_CTLS_LOW] = low;
-	c->vmx_capability[TERTIARY_CTLS_HIGH] = high;
+	rdmsrq_safe(MSR_IA32_VMX_PROCBASED_CTLS3, &val.q);
+	c->vmx_capability[TERTIARY_CTLS_LOW] = val.l;
+	c->vmx_capability[TERTIARY_CTLS_HIGH] = val.h;
 
-	rdmsr(MSR_IA32_VMX_PINBASED_CTLS, ign, supported);
-	rdmsr_safe(MSR_IA32_VMX_VMFUNC, &ign, &funcs);
+	rdmsrq(MSR_IA32_VMX_PINBASED_CTLS, val.q);
+	supported = val.h;
+	rdmsrq_safe(MSR_IA32_VMX_VMFUNC, &val.q);
+	funcs = val.h;
 
 	/*
 	 * Except for EPT+VPID, which enumerates support for both in a single
 	 * MSR, low for EPT, high for VPID.
 	 */
-	rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP, &ept, &vpid);
+	rdmsrq_safe(MSR_IA32_VMX_EPT_VPID_CAP, &val.q);
+	ept = val.l;
+	vpid = val.h;
 
 	/* Pin, EPT, VPID and VM-Func are merged into a single word. */
 	WARN_ON_ONCE(supported >> 16);
Signature · 1 line
2.54.0
merge bot Applied
#58 lore raw

[tip: x86/msr] x86/featctl: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     f44da125bcecd78705ab506f6e18a4a5db1a35e1
Gitweb:        https://git.kernel.org/tip/f44da125bcecd78705ab506f6e18a4a5db1a35e1
Author:        Juergen Gross <[email protected]>
AuthorDate:    Fri, 03 Jul 2026 13:24:26 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 17 Jul 2026 11:30:36 +02:00

x86/featctl: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/feat_ctl.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/feat_ctl.c +16 -9
index d697572..10a9292 100644
@@ -25,7 +25,8 @@ enum vmx_feature_leafs {
 
 static void init_vmx_capabilities(struct cpuinfo_x86 *c)
 {
-	u32 supported, funcs, ept, vpid, ign, low, high;
+	struct msr val;
+	u32 supported, funcs, ept, vpid;
 
 	BUILD_BUG_ON(NVMXINTS != NR_VMX_FEATURE_WORDS);
 
@@ -39,25 +40,31 @@ static void init_vmx_capabilities(struct cpuinfo_x86 *c)
 	 * as they exist on any CPU that supports VMX, i.e. we want the WARN if
 	 * the RDMSR faults.
 	 */
-	rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, ign, supported);
+	rdmsrq(MSR_IA32_VMX_PROCBASED_CTLS, val.q);
+	supported = val.h;
 	c->vmx_capability[PRIMARY_CTLS] = supported;
 
-	rdmsr_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &ign, &supported);
+	rdmsrq_safe(MSR_IA32_VMX_PROCBASED_CTLS2, &val.q);
+	supported = val.h;
 	c->vmx_capability[SECONDARY_CTLS] = supported;
 
 	/* All 64 bits of tertiary controls MSR are allowed-1 settings. */
-	rdmsr_safe(MSR_IA32_VMX_PROCBASED_CTLS3, &low, &high);
-	c->vmx_capability[TERTIARY_CTLS_LOW] = low;
-	c->vmx_capability[TERTIARY_CTLS_HIGH] = high;
+	rdmsrq_safe(MSR_IA32_VMX_PROCBASED_CTLS3, &val.q);
+	c->vmx_capability[TERTIARY_CTLS_LOW] = val.l;
+	c->vmx_capability[TERTIARY_CTLS_HIGH] = val.h;
 
-	rdmsr(MSR_IA32_VMX_PINBASED_CTLS, ign, supported);
-	rdmsr_safe(MSR_IA32_VMX_VMFUNC, &ign, &funcs);
+	rdmsrq(MSR_IA32_VMX_PINBASED_CTLS, val.q);
+	supported = val.h;
+	rdmsrq_safe(MSR_IA32_VMX_VMFUNC, &val.q);
+	funcs = val.h;
 
 	/*
 	 * Except for EPT+VPID, which enumerates support for both in a single
 	 * MSR, low for EPT, high for VPID.
 	 */
-	rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP, &ept, &vpid);
+	rdmsrq_safe(MSR_IA32_VMX_EPT_VPID_CAP, &val.q);
+	ept = val.l;
+	vpid = val.h;
 
 	/* Pin, EPT, VPID and VM-Func are merged into a single word. */
 	WARN_ON_ONCE(supported >> 16);
author maintainer
#59 lore raw

PATCH 14/32 x86/tsc: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/tsc.c     |  6 +++---
 arch/x86/kernel/tsc_msr.c | 15 ++++++++-------
 2 files changed, 11 insertions(+), 10 deletions(-)
arch/x86/kernel/tsc.c +3 -3
index ce10ae4b298b..723347e2cf7f 100644
@@ -1221,11 +1221,11 @@ static void __init check_system_tsc_reliable(void)
 	if (is_geode_lx()) {
 		/* RTSC counts during suspend */
 #define RTSC_SUSP 0x100
-		unsigned long res_low, res_high;
+		u64 res;
 
-		rdmsr_safe(MSR_GEODE_BUSCONT_CONF0, &res_low, &res_high);
+		rdmsrq_safe(MSR_GEODE_BUSCONT_CONF0, &res);
 		/* Geode_LX - the OLPC CPU has a very reliable TSC */
-		if (res_low & RTSC_SUSP)
+		if (res & RTSC_SUSP)
 			tsc_clocksource_reliable = 1;
 	}
 #endif
arch/x86/kernel/tsc_msr.c +8 -7
index 48e6cc1cb017..d74743c8d2a4 100644
@@ -165,7 +165,8 @@ static const struct x86_cpu_id tsc_msr_cpu_ids[] = {
  */
 unsigned long cpu_khz_from_msr(void)
 {
-	u32 lo, hi, ratio, freq, tscref;
+	u32 ratio, freq, tscref;
+	struct msr val;
 	const struct freq_desc *freq_desc;
 	const struct x86_cpu_id *id;
 	const struct muldiv *md;
@@ -178,16 +179,16 @@ unsigned long cpu_khz_from_msr(void)
 
 	freq_desc = (struct freq_desc *)id->driver_data;
 	if (freq_desc->use_msr_plat) {
-		rdmsr(MSR_PLATFORM_INFO, lo, hi);
-		ratio = (lo >> 8) & 0xff;
+		rdmsrq(MSR_PLATFORM_INFO, val.q);
+		ratio = (val.l >> 8) & 0xff;
 	} else {
-		rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-		ratio = (hi >> 8) & 0x1f;
+		rdmsrq(MSR_IA32_PERF_STATUS, val.q);
+		ratio = (val.h >> 8) & 0x1f;
 	}
 
 	/* Get FSB FREQ ID */
-	rdmsr(MSR_FSB_FREQ, lo, hi);
-	index = lo & freq_desc->mask;
+	rdmsrq(MSR_FSB_FREQ, val.q);
+	index = val.l & freq_desc->mask;
 	md = &freq_desc->muldiv[index];
 
 	/*
Signature · 1 line
2.54.0
merge bot Applied
#60 lore raw

[tip: x86/msr] x86/tsc: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     4ff91f7b8fbfb56424f3b63a3b69286df961bb75
Gitweb:        https://git.kernel.org/tip/4ff91f7b8fbfb56424f3b63a3b69286df961bb75
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:05 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:52 +02:00

x86/tsc: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr() and rdmsr_safe() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/tsc.c     |  6 +++---
 arch/x86/kernel/tsc_msr.c | 15 ++++++++-------
 2 files changed, 11 insertions(+), 10 deletions(-)
arch/x86/kernel/tsc.c +3 -3
index ce10ae4..723347e 100644
@@ -1221,11 +1221,11 @@ static void __init check_system_tsc_reliable(void)
 	if (is_geode_lx()) {
 		/* RTSC counts during suspend */
 #define RTSC_SUSP 0x100
-		unsigned long res_low, res_high;
+		u64 res;
 
-		rdmsr_safe(MSR_GEODE_BUSCONT_CONF0, &res_low, &res_high);
+		rdmsrq_safe(MSR_GEODE_BUSCONT_CONF0, &res);
 		/* Geode_LX - the OLPC CPU has a very reliable TSC */
-		if (res_low & RTSC_SUSP)
+		if (res & RTSC_SUSP)
 			tsc_clocksource_reliable = 1;
 	}
 #endif
arch/x86/kernel/tsc_msr.c +8 -7
index 48e6cc1..d74743c 100644
@@ -165,7 +165,8 @@ static const struct x86_cpu_id tsc_msr_cpu_ids[] = {
  */
 unsigned long cpu_khz_from_msr(void)
 {
-	u32 lo, hi, ratio, freq, tscref;
+	u32 ratio, freq, tscref;
+	struct msr val;
 	const struct freq_desc *freq_desc;
 	const struct x86_cpu_id *id;
 	const struct muldiv *md;
@@ -178,16 +179,16 @@ unsigned long cpu_khz_from_msr(void)
 
 	freq_desc = (struct freq_desc *)id->driver_data;
 	if (freq_desc->use_msr_plat) {
-		rdmsr(MSR_PLATFORM_INFO, lo, hi);
-		ratio = (lo >> 8) & 0xff;
+		rdmsrq(MSR_PLATFORM_INFO, val.q);
+		ratio = (val.l >> 8) & 0xff;
 	} else {
-		rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-		ratio = (hi >> 8) & 0x1f;
+		rdmsrq(MSR_IA32_PERF_STATUS, val.q);
+		ratio = (val.h >> 8) & 0x1f;
 	}
 
 	/* Get FSB FREQ ID */
-	rdmsr(MSR_FSB_FREQ, lo, hi);
-	index = lo & freq_desc->mask;
+	rdmsrq(MSR_FSB_FREQ, val.q);
+	index = val.l & freq_desc->mask;
 	md = &freq_desc->muldiv[index];
 
 	/*
author maintainer
#61 lore raw

PATCH 15/32 x86/msr: Remove rdmsr_safe()

In reply to Juergen Gross

rdmsr_safe() has no users left. Delete it.

---
 arch/x86/include/asm/msr.h      | 10 ----------
 arch/x86/include/asm/paravirt.h | 10 ----------
 2 files changed, 20 deletions(-)
arch/x86/include/asm/msr.h +0 -10
index 6fb7125608c7..776a2daa2ba2 100644
@@ -205,16 +205,6 @@ static inline int wrmsrq_safe(u32 msr, u64 val)
 	return native_write_msr_safe(msr, val);
 }
 
-/* rdmsr with exception handling */
-#define rdmsr_safe(msr, low, high)				\
-({								\
-	u64 __val;						\
-	int __err = native_read_msr_safe((msr), &__val);	\
-	(*low) = (u32)__val;					\
-	(*high) = (u32)(__val >> 32);				\
-	__err;							\
-})
-
 static inline int rdmsrq_safe(u32 msr, u64 *p)
 {
 	return native_read_msr_safe(msr, p);
arch/x86/include/asm/paravirt.h +0 -10
index 0591aa38fd85..97b082095572 100644
@@ -177,16 +177,6 @@ static inline int wrmsrq_safe(u32 msr, u64 val)
 	return paravirt_write_msr_safe(msr, val);
 }
 
-/* rdmsr with exception handling */
-#define rdmsr_safe(msr, a, b)				\
-({							\
-	u64 _l;						\
-	int _err = paravirt_read_msr_safe((msr), &_l);	\
-	(*a) = (u32)_l;					\
-	(*b) = (u32)(_l >> 32);				\
-	_err;						\
-})
-
 static __always_inline int rdmsrq_safe(u32 msr, u64 *p)
 {
 	return paravirt_read_msr_safe(msr, p);
Signature · 1 line
2.54.0
author maintainer
#62 lore raw

PATCH 16/32 cpufreq: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/cpufreq/acpi-cpufreq.c       | 22 ++++----
 drivers/cpufreq/e_powersaver.c       | 48 ++++++++---------
 drivers/cpufreq/longhaul.c           | 15 +++---
 drivers/cpufreq/longrun.c            | 78 +++++++++++++++-------------
 drivers/cpufreq/powernow-k6.c        | 12 ++---
 drivers/cpufreq/powernow-k8.c        | 67 ++++++++++++------------
 drivers/cpufreq/speedstep-centrino.c | 16 +++---
 drivers/cpufreq/speedstep-lib.c      | 63 +++++++++++-----------
 8 files changed, 166 insertions(+), 155 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +11 -11
index 21639d9ac753..b40fa99b5ab2 100644
@@ -246,32 +246,32 @@ static unsigned extract_freq(struct cpufreq_policy *policy, u32 val)
 
 static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)
 {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_IA32_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_IA32_PERF_CTL, val);
+	return (u32)val;
 }
 
 static void cpu_freq_write_intel(struct acpi_pct_register *not_used, u32 val)
 {
-	u32 lo, hi;
+	struct msr msrval;
 
-	rdmsr(MSR_IA32_PERF_CTL, lo, hi);
-	lo = (lo & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
-	wrmsr(MSR_IA32_PERF_CTL, lo, hi);
+	rdmsrq(MSR_IA32_PERF_CTL, msrval.q);
+	msrval.h = (msrval.h & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
+	wrmsrq(MSR_IA32_PERF_CTL, msrval.q);
 }
 
 static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)
 {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_AMD_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_AMD_PERF_CTL, val);
+	return (u32)val;
 }
 
 static void cpu_freq_write_amd(struct acpi_pct_register *not_used, u32 val)
 {
-	wrmsr(MSR_AMD_PERF_CTL, val, 0);
+	wrmsrq(MSR_AMD_PERF_CTL, val);
 }
 
 static u32 cpu_freq_read_io(struct acpi_pct_register *reg)
drivers/cpufreq/e_powersaver.c +24 -24

117 lines not on this page · raw message

drivers/cpufreq/longhaul.c +8 -7
index a18d1d11725f..4c2599264333 100644
@@ -118,13 +118,14 @@ static unsigned int calc_speed(int mult)
 
 static int longhaul_get_cpu_mult(void)
 {
-	unsigned long invalue = 0, lo, hi;
+	unsigned long invalue = 0;
+	u64 val;
 
-	rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi);
-	invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22;
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, val);
+	invalue = (val & (1<<22|1<<23|1<<24|1<<25))>>22;
 	if (longhaul_version == TYPE_LONGHAUL_V2 ||
 	    longhaul_version == TYPE_POWERSAVER) {
-		if (lo & (1<<27))
+		if (val & (1<<27))
 			invalue += 16;
 	}
 	return eblcr[invalue];
@@ -761,7 +762,7 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
 	struct cpuinfo_x86 *c = &cpu_data(0);
 	char *cpuname = NULL;
 	int ret;
-	u32 lo, hi;
+	u64 val;
 
 	/* Check what we have on this motherboard */
 	switch (c->x86_model) {
@@ -835,8 +836,8 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
 	}
 	/* Check Longhaul ver. 2 */
 	if (longhaul_version == TYPE_LONGHAUL_V2) {
-		rdmsr(MSR_VIA_LONGHAUL, lo, hi);
-		if (lo == 0 && hi == 0)
+		rdmsrq(MSR_VIA_LONGHAUL, val);
+		if (val == 0)
 			/* Looks like MSR isn't present */
 			longhaul_version = TYPE_LONGHAUL_V1;
 	}
drivers/cpufreq/longrun.c +41 -37

146 lines not on this page · raw message

drivers/cpufreq/powernow-k6.c +6 -6
index 99d2244e03b0..2044e8a336ec 100644
@@ -83,15 +83,15 @@ static const struct {
 static int powernow_k6_get_cpu_multiplier(void)
 {
 	unsigned long invalue = 0;
-	u32 msrval;
+	u64 msrval;
 
 	local_irq_disable();
 
 	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
 	invalue = inl(POWERNOW_IOPORT + 0x8);
 	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
 	local_irq_enable();
 
@@ -101,8 +101,8 @@ static int powernow_k6_get_cpu_multiplier(void)
 static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
 {
 	unsigned long outvalue, invalue;
-	unsigned long msrval;
 	unsigned long cr0;
+	u64 msrval;
 
 	/* we now need to transform best_i to the BVC format, see AMD#23446 */
 
@@ -118,13 +118,13 @@ static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
 	outvalue = (1<<12) | (1<<10) | (1<<9) | (index_to_register[best_i]<<5);
 
 	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
 	invalue = inl(POWERNOW_IOPORT + 0x8);
 	invalue = invalue & 0x1f;
 	outvalue = outvalue | invalue;
 	outl(outvalue, (POWERNOW_IOPORT + 0x8));
 	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
 	write_cr0(cr0);
 	local_irq_enable();
drivers/cpufreq/powernow-k8.c +34 -33

138 lines not on this page · raw message

drivers/cpufreq/speedstep-centrino.c +8 -8
index 9237ed8f2b1f..de50fb367c6b 100644
@@ -345,7 +345,7 @@ static unsigned int get_cur_freq(unsigned int cpu)
 static int centrino_cpu_init(struct cpufreq_policy *policy)
 {
 	struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu);
-	unsigned l, h;
+	u64 q;
 	int i;
 
 	/* Only Intel makes Enhanced Speedstep-capable CPUs */
@@ -378,16 +378,16 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
 
 	/* Check to see if Enhanced SpeedStep is enabled, and try to
 	   enable it if not. */
-	rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+	rdmsrq(MSR_IA32_MISC_ENABLE, q);
 
-	if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
-		l |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
-		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", l);
-		wrmsr(MSR_IA32_MISC_ENABLE, l, h);
+	if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		q |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
+		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", (u32)q);
+		wrmsrq(MSR_IA32_MISC_ENABLE, q);
 
 		/* check to see if it stuck */
-		rdmsr(MSR_IA32_MISC_ENABLE, l, h);
-		if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		rdmsrq(MSR_IA32_MISC_ENABLE, q);
+		if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
 			pr_info("couldn't enable Enhanced SpeedStep\n");
 			return -ENODEV;
 		}
drivers/cpufreq/speedstep-lib.c +34 -29

149 lines not on this page · raw message

Signature · 1 line
2.54.0
#63 lore raw

Re: [PATCH 16/32] cpufreq: Stop using 32-bit MSR interfaces

Quoted 2 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

Hello Juergen,

Quoted 30 lines
---
  drivers/cpufreq/acpi-cpufreq.c       | 22 ++++----
  drivers/cpufreq/e_powersaver.c       | 48 ++++++++---------
  drivers/cpufreq/longhaul.c           | 15 +++---
  drivers/cpufreq/longrun.c            | 78 +++++++++++++++-------------
  drivers/cpufreq/powernow-k6.c        | 12 ++---
  drivers/cpufreq/powernow-k8.c        | 67 ++++++++++++------------
  drivers/cpufreq/speedstep-centrino.c | 16 +++---
  drivers/cpufreq/speedstep-lib.c      | 63 +++++++++++-----------
  8 files changed, 166 insertions(+), 155 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +3 -3
index 21639d9ac753..b40fa99b5ab2 100644
@@ -246,32 +246,32 @@ static unsigned extract_freq(struct cpufreq_policy *policy, u32 val)
 
  static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)
  {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_IA32_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_IA32_PERF_CTL, val);
+	return (u32)val;
  }
 

drivers/cpufreq/acpi-cpufreq.c static unsigned extract_freq(struct cpufreq_policy *policy, u32 val) · line 260

Quoted 10 lines
drivers/cpufreq/acpi-cpufreq.c +3 -4
  static void cpu_freq_write_intel(struct acpi_pct_register *not_used, u32 val)
  {
-	u32 lo, hi;
+	struct msr msrval;
 
-	rdmsr(MSR_IA32_PERF_CTL, lo, hi);
-	lo = (lo & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
-	wrmsr(MSR_IA32_PERF_CTL, lo, hi);
+	rdmsrq(MSR_IA32_PERF_CTL, msrval.q);
+	msrval.h = (msrval.h & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);

msrval.l?

please feel free to correct me if there is any misunderstanding.

how about using u64 directly?

    u64 msrval;
    rdmsrq(MSR_IA32_PERF_CTL, msrval);
    msrval = (msrval & ~(u64)INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
    wrmsrq(MSR_IA32_PERF_CTL, msrval);

As per my understanding, we can use u64 instead of struct msr in many other places in this patch as well.

Quoted 68 lines
drivers/cpufreq/acpi-cpufreq.c +5 -4
+	wrmsrq(MSR_IA32_PERF_CTL, msrval.q);
  }
 
  static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)
  {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_AMD_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_AMD_PERF_CTL, val);
+	return (u32)val;
  }
 
  static void cpu_freq_write_amd(struct acpi_pct_register *not_used, u32 val)
  {
-	wrmsr(MSR_AMD_PERF_CTL, val, 0);
+	wrmsrq(MSR_AMD_PERF_CTL, val);
  }
 
  static u32 cpu_freq_read_io(struct acpi_pct_register *reg)
drivers/cpufreq/e_powersaver.c +7 -8
index eb5a9209d828..13709f9667ea 100644
@@ -90,7 +90,7 @@ static int eps_acpi_exit(struct cpufreq_policy *policy)
  static unsigned int eps_get(unsigned int cpu)
  {
  	struct eps_cpu_data *centaur;
-	u32 lo, hi;
+	u64 val;
 
  	if (cpu)
  		return 0;
@@ -99,35 +99,35 @@ static unsigned int eps_get(unsigned int cpu)
  		return 0;
 
  	/* Return current frequency */
-	rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-	return centaur->fsb * ((lo >> 8) & 0xff);
+	rdmsrq(MSR_IA32_PERF_STATUS, val);
+	return centaur->fsb * ((val >> 8) & 0xff);
  }
 
  static int eps_set_state(struct eps_cpu_data *centaur,
  			 struct cpufreq_policy *policy,
  			 u32 dest_state)
  {
-	u32 lo, hi;
+	u64 val;
  	int i;
 
  	/* Wait while CPU is busy */
-	rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
+	rdmsrq(MSR_IA32_PERF_STATUS, val);
  	i = 0;
-	while (lo & ((1 << 16) | (1 << 17))) {
+	while (val & ((1 << 16) | (1 << 17))) {
  		udelay(16);
-		rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
+		rdmsrq(MSR_IA32_PERF_STATUS, val);
  		i++;
  		if (unlikely(i > 64)) {
  			return -ENODEV;
  		}
  	}
  	/* Set new multiplier and voltage */
-	wrmsr(MSR_IA32_PERF_CTL, dest_state & 0xffff, 0);

drivers/cpufreq/e_powersaver.c static unsigned int eps_get(unsigned int cpu) · line 133

Quoted 10 lines
drivers/cpufreq/e_powersaver.c +2 -1
+	wrmsrq(MSR_IA32_PERF_CTL, dest_state & 0xffff);
  	/* Wait until transition end */
  	i = 0;
  	do {
  		udelay(16);
-		rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
+		rdmsrq(MSR_IA32_PERF_STATUS, val);
  		i++;
  		if (unlikely(i > 64)) {
  			return -ENODEV;
	do {
		udelay(16);
		rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
		i++;
		if (unlikely(i > 64)) {
			return -ENODEV;
		}
	} while (lo & ((1 << 16) | (1 << 17)));-->lo has been deleted?
Quoted 258 lines
drivers/cpufreq/e_powersaver.c +15 -15
@@ -139,10 +139,10 @@ static int eps_set_state(struct eps_cpu_data *centaur,
  	u8 current_multiplier, current_voltage;
 
  	/* Print voltage and multiplier */
-	rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-	current_voltage = lo & 0xff;
+	rdmsrq(MSR_IA32_PERF_STATUS, val);
+	current_voltage = val & 0xff;
  	pr_info("Current voltage = %dmV\n", current_voltage * 16 + 700);
-	current_multiplier = (lo >> 8) & 0xff;
+	current_multiplier = (val >> 8) & 0xff;
  	pr_info("Current multiplier = %d\n", current_multiplier);
  	}
  #endif
@@ -171,8 +171,8 @@ static int eps_target(struct cpufreq_policy *policy, unsigned int index)
  static int eps_cpu_init(struct cpufreq_policy *policy)
  {
  	unsigned int i;
-	u32 lo, hi;
  	u64 val;
+	struct msr status;
  	u8 current_multiplier, current_voltage;
  	u8 max_multiplier, max_voltage;
  	u8 min_multiplier, min_voltage;
@@ -195,13 +195,13 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
 
  	switch (c->x86_model) {
  	case 10:
-		rdmsr(0x1153, lo, hi);
-		brand = (((lo >> 2) ^ lo) >> 18) & 3;
+		rdmsrq(0x1153, val);
+		brand = (((val >> 2) ^ val) >> 18) & 3;
  		pr_cont("Model A ");
  		break;
  	case 13:
-		rdmsr(0x1154, lo, hi);
-		brand = (((lo >> 4) ^ (lo >> 2))) & 0x000000ff;
+		rdmsrq(0x1154, val);
+		brand = (((val >> 4) ^ (val >> 2))) & 0x000000ff;
  		pr_cont("Model D ");
  		break;
  	}
@@ -237,20 +237,20 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
  	}
 
  	/* Print voltage and multiplier */
-	rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-	current_voltage = lo & 0xff;
+	rdmsrq(MSR_IA32_PERF_STATUS, status.q);
+	current_voltage = status.l & 0xff;
  	pr_info("Current voltage = %dmV\n", current_voltage * 16 + 700);
-	current_multiplier = (lo >> 8) & 0xff;
+	current_multiplier = (status.l >> 8) & 0xff;
  	pr_info("Current multiplier = %d\n", current_multiplier);
 
  	/* Print limits */
-	max_voltage = hi & 0xff;
+	max_voltage = status.h & 0xff;
  	pr_info("Highest voltage = %dmV\n", max_voltage * 16 + 700);
-	max_multiplier = (hi >> 8) & 0xff;
+	max_multiplier = (status.h >> 8) & 0xff;
  	pr_info("Highest multiplier = %d\n", max_multiplier);
-	min_voltage = (hi >> 16) & 0xff;
+	min_voltage = (status.h >> 16) & 0xff;
  	pr_info("Lowest voltage = %dmV\n", min_voltage * 16 + 700);
-	min_multiplier = (hi >> 24) & 0xff;
+	min_multiplier = (status.h >> 24) & 0xff;
  	pr_info("Lowest multiplier = %d\n", min_multiplier);
 
  	/* Sanity checks */
drivers/cpufreq/longhaul.c +8 -7
index a18d1d11725f..4c2599264333 100644
@@ -118,13 +118,14 @@ static unsigned int calc_speed(int mult)
 
  static int longhaul_get_cpu_mult(void)
  {
-	unsigned long invalue = 0, lo, hi;
+	unsigned long invalue = 0;
+	u64 val;
 
-	rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi);
-	invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22;
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, val);
+	invalue = (val & (1<<22|1<<23|1<<24|1<<25))>>22;
  	if (longhaul_version == TYPE_LONGHAUL_V2 ||
  	    longhaul_version == TYPE_POWERSAVER) {
-		if (lo & (1<<27))
+		if (val & (1<<27))
  			invalue += 16;
  	}
  	return eblcr[invalue];
@@ -761,7 +762,7 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
  	struct cpuinfo_x86 *c = &cpu_data(0);
  	char *cpuname = NULL;
  	int ret;
-	u32 lo, hi;
+	u64 val;
 
  	/* Check what we have on this motherboard */
  	switch (c->x86_model) {
@@ -835,8 +836,8 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
  	}
  	/* Check Longhaul ver. 2 */
  	if (longhaul_version == TYPE_LONGHAUL_V2) {
-		rdmsr(MSR_VIA_LONGHAUL, lo, hi);
-		if (lo == 0 && hi == 0)
+		rdmsrq(MSR_VIA_LONGHAUL, val);
+		if (val == 0)
  			/* Looks like MSR isn't present */
  			longhaul_version = TYPE_LONGHAUL_V1;
  	}
drivers/cpufreq/longrun.c +38 -36
index f3aaca0496a4..99abef32e7e5 100644
@@ -35,27 +35,27 @@ static unsigned int longrun_low_freq, longrun_high_freq;
   */
  static void longrun_get_policy(struct cpufreq_policy *policy)
  {
-	u32 msr_lo, msr_hi;
+	struct msr msr;
 
-	rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
-	pr_debug("longrun flags are %x - %x\n", msr_lo, msr_hi);
-	if (msr_lo & 0x01)
+	rdmsrq(MSR_TMTA_LONGRUN_FLAGS, msr.q);
+	pr_debug("longrun flags are %x - %x\n", msr.l, msr.h);
+	if (msr.l & 0x01)
  		policy->policy = CPUFREQ_POLICY_PERFORMANCE;
  	else
  		policy->policy = CPUFREQ_POLICY_POWERSAVE;
 
-	rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
-	pr_debug("longrun ctrl is %x - %x\n", msr_lo, msr_hi);
-	msr_lo &= 0x0000007F;
-	msr_hi &= 0x0000007F;
+	rdmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
+	pr_debug("longrun ctrl is %x - %x\n", msr.l, msr.h);
+	msr.l &= 0x0000007F;
+	msr.h &= 0x0000007F;
 
  	if (longrun_high_freq <= longrun_low_freq) {
  		/* Assume degenerate Longrun table */
  		policy->min = policy->max = longrun_high_freq;
  	} else {
-		policy->min = longrun_low_freq + msr_lo *
+		policy->min = longrun_low_freq + msr.l *
  			((longrun_high_freq - longrun_low_freq) / 100);
-		policy->max = longrun_low_freq + msr_hi *
+		policy->max = longrun_low_freq + msr.h *
  			((longrun_high_freq - longrun_low_freq) / 100);
  	}
  	policy->cpu = 0;
@@ -71,7 +71,7 @@ static void longrun_get_policy(struct cpufreq_policy *policy)
   */
  static int longrun_set_policy(struct cpufreq_policy *policy)
  {
-	u32 msr_lo, msr_hi;
+	struct msr msr;
  	u32 pctg_lo, pctg_hi;
 
  	if (!policy)
@@ -93,24 +93,24 @@ static int longrun_set_policy(struct cpufreq_policy *policy)
  		pctg_lo = pctg_hi;
 
  	/* performance or economy mode */
-	rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
-	msr_lo &= 0xFFFFFFFE;
+	rdmsrq(MSR_TMTA_LONGRUN_FLAGS, msr.q);
+	msr.l &= 0xFFFFFFFE;
  	switch (policy->policy) {
  	case CPUFREQ_POLICY_PERFORMANCE:
-		msr_lo |= 0x00000001;
+		msr.l |= 0x00000001;
  		break;
  	case CPUFREQ_POLICY_POWERSAVE:
  		break;
  	}
-	wrmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
+	wrmsrq(MSR_TMTA_LONGRUN_FLAGS, msr.q);
 
  	/* lower and upper boundary */
-	rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
-	msr_lo &= 0xFFFFFF80;
-	msr_hi &= 0xFFFFFF80;
-	msr_lo |= pctg_lo;
-	msr_hi |= pctg_hi;
-	wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
+	rdmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
+	msr.l &= 0xFFFFFF80;
+	msr.h &= 0xFFFFFF80;
+	msr.l |= pctg_lo;
+	msr.h |= pctg_hi;
+	wrmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
 
  	return 0;
  }
@@ -160,7 +160,7 @@ static unsigned int longrun_get(unsigned int cpu)
  static int longrun_determine_freqs(unsigned int *low_freq,
  						      unsigned int *high_freq)
  {
-	u32 msr_lo, msr_hi;
+	struct msr msr;
  	u32 save_lo, save_hi;
  	u32 eax, ebx, ecx, edx;
  	u32 try_hi;
@@ -178,15 +178,17 @@ static int longrun_determine_freqs(unsigned int *low_freq,
  		 * For maximum frequency, read out level zero.
  		 */
  		/* minimum */
-		rdmsr(MSR_TMTA_LRTI_READOUT, msr_lo, msr_hi);
-		wrmsr(MSR_TMTA_LRTI_READOUT, msr_hi, msr_hi);
-		rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi);
-		*low_freq = msr_lo * 1000; /* to kHz */
+		rdmsrq(MSR_TMTA_LRTI_READOUT, msr.q);
+		msr.l = msr.h;
+		wrmsrq(MSR_TMTA_LRTI_READOUT, msr.q);
+		rdmsrq(MSR_TMTA_LRTI_VOLT_MHZ, msr.q);
+		*low_freq = msr.l * 1000; /* to kHz */
 
  		/* maximum */
-		wrmsr(MSR_TMTA_LRTI_READOUT, 0, msr_hi);
-		rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi);
-		*high_freq = msr_lo * 1000; /* to kHz */
+		msr.l = 0;
+		wrmsrq(MSR_TMTA_LRTI_READOUT, msr.q);
+		rdmsrq(MSR_TMTA_LRTI_VOLT_MHZ, msr.q);
+		*high_freq = msr.l * 1000; /* to kHz */
 
  		pr_debug("longrun table interface told %u - %u kHz\n",
  				*low_freq, *high_freq);
@@ -202,9 +204,9 @@ static int longrun_determine_freqs(unsigned int *low_freq,
  	pr_debug("high frequency is %u kHz\n", *high_freq);
 
  	/* get current borders */
-	rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
-	save_lo = msr_lo & 0x0000007F;
-	save_hi = msr_hi & 0x0000007F;
+	rdmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
+	save_lo = msr.l & 0x0000007F;
+	save_hi = msr.h & 0x0000007F;
 
  	/* if current perf_pctg is larger than 90%, we need to decrease the
  	 * upper limit to make the calculation more accurate.
@@ -214,16 +216,18 @@ static int longrun_determine_freqs(unsigned int *low_freq,
  	 * on some barrier values */
  	for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -= 10) {
  		/* set to 0 to try_hi perf_pctg */
-		msr_lo &= 0xFFFFFF80;
-		msr_hi &= 0xFFFFFF80;
-		msr_hi |= try_hi;
-		wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
+		msr.l &= 0xFFFFFF80;
+		msr.h &= 0xFFFFFF80;
+		msr.h |= try_hi;
+		wrmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);

drivers/cpufreq/longrun.c static int longrun_determine_freqs(unsigned int *low_freq, · line 231

Quoted 10 lines
drivers/cpufreq/longrun.c +3 -1
 
  		/* read out current core MHz and current perf_pctg */
  		cpuid(0x80860007, &eax, &ebx, &ecx, &edx);
 
  		/* restore values */
-		wrmsr(MSR_TMTA_LONGRUN_CTRL, save_lo, save_hi);
+		msr.l = save_lo;
+		msr.h = save_hi;
+		wrmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
  	}

As sashiko.dev pointed, from the second iter, this patch code will clear upper 25 bits to zero.

https://sashiko.dev/#/patchset/20260629060526.3638272-1-jgross%40suse.com

for (try_hi = 80; ...; ...) {

-   msr_lo &= 0xFFFFFF80;    /* iter 1: X.lo[31:7]; iter 2+: same */
-   msr_hi &= 0xFFFFFF80;
-   msr_hi |= try_hi;
-   wrmsr(reg, msr_lo, msr_hi);/* writes X.hi[31:7] | try_hi    */
+   msr.l &= 0xFFFFFF80;      /* iter 2+: locals=0 -> mask = 0  */
+   msr.h &= 0xFFFFFF80;
+   msr.h |= try_hi;
+   wrmsrq(reg, msr.q);   /* <-- iter 2+ writes 0 (vs X.hi[31:7])*/
    cpuid(...);

    /* restore */
-   wrmsr(reg, save_lo, save_hi);  /* locals untouched */
+   msr.l = save_lo;              /* poisons locals ->next iter bug  */
+   msr.h = save_hi;
+   wrmsrq(reg, msr.q);

}

I'm not sure whether the upper 25 bits are reserved, but the original code preserved them across iterations. It might be safer to keep that behavior unchanged.

Quoted 70 lines
drivers/cpufreq/longrun.c +0 -0
  	pr_debug("percentage is %u %%, freq is %u MHz\n", ecx, eax);
 
drivers/cpufreq/powernow-k6.c +6 -6
index 99d2244e03b0..2044e8a336ec 100644
@@ -83,15 +83,15 @@ static const struct {
  static int powernow_k6_get_cpu_multiplier(void)
  {
  	unsigned long invalue = 0;
-	u32 msrval;
+	u64 msrval;
 
  	local_irq_disable();
 
  	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
  	invalue = inl(POWERNOW_IOPORT + 0x8);
  	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
  	local_irq_enable();
 
@@ -101,8 +101,8 @@ static int powernow_k6_get_cpu_multiplier(void)
  static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
  {
  	unsigned long outvalue, invalue;
-	unsigned long msrval;
  	unsigned long cr0;
+	u64 msrval;
 
  	/* we now need to transform best_i to the BVC format, see AMD#23446 */
 
@@ -118,13 +118,13 @@ static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
  	outvalue = (1<<12) | (1<<10) | (1<<9) | (index_to_register[best_i]<<5);
 
  	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
  	invalue = inl(POWERNOW_IOPORT + 0x8);
  	invalue = invalue & 0x1f;
  	outvalue = outvalue | invalue;
  	outl(outvalue, (POWERNOW_IOPORT + 0x8));
  	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
  	write_cr0(cr0);
  	local_irq_enable();
drivers/cpufreq/powernow-k8.c +3 -3
index 2b791f1ec51b..fe1f499b4fc0 100644
@@ -87,10 +87,10 @@ static u32 convert_fid_to_vco_fid(u32 fid)
   */
  static int pending_bit_stuck(void)
  {
-	u32 lo, hi __always_unused;
+	u64 msr;
 
-	rdmsr(MSR_FIDVID_STATUS, lo, hi);
-	return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0;
+	rdmsrq(MSR_FIDVID_STATUS, msr);
+	return msr & MSR_S_LO_CHANGE_PENDING ? 1 : 0;
  }
 
  /*

drivers/cpufreq/powernow-k8.c static int pending_bit_stuck(void) · line 102

Quoted 5 lines
drivers/cpufreq/powernow-k8.c +1 -1
@@ -99,7 +99,7 @@ static int pending_bit_stuck(void)
   */
  static int query_current_values_with_pending_wait(struct powernow_k8_data *data)
  {
-	u32 lo, hi;
+	struct msr msr;

msrval?

Quoted 327 lines
drivers/cpufreq/powernow-k8.c +30 -29
  	u32 i = 0;
 
  	do {
@@ -107,11 +107,11 @@ static int query_current_values_with_pending_wait(struct powernow_k8_data *data)
  			pr_debug("detected change pending stuck\n");
  			return 1;
  		}
-		rdmsr(MSR_FIDVID_STATUS, lo, hi);
-	} while (lo & MSR_S_LO_CHANGE_PENDING);
+		rdmsrq(MSR_FIDVID_STATUS, msr.q);
+	} while (msr.l & MSR_S_LO_CHANGE_PENDING);
 
-	data->currvid = hi & MSR_S_HI_CURRENT_VID;
-	data->currfid = lo & MSR_S_LO_CURRENT_FID;
+	data->currvid = msr.h & MSR_S_HI_CURRENT_VID;
+	data->currfid = msr.l & MSR_S_LO_CURRENT_FID;
 
  	return 0;
  }
@@ -131,22 +131,22 @@ static void count_off_vst(struct powernow_k8_data *data)
  /* need to init the control msr to a safe value (for each cpu) */
  static void fidvid_msr_init(void)
  {
-	u32 lo, hi;
+	struct msr msr;
  	u8 fid, vid;
 
-	rdmsr(MSR_FIDVID_STATUS, lo, hi);
-	vid = hi & MSR_S_HI_CURRENT_VID;
-	fid = lo & MSR_S_LO_CURRENT_FID;
-	lo = fid | (vid << MSR_C_LO_VID_SHIFT);
-	hi = MSR_C_HI_STP_GNT_BENIGN;
-	pr_debug("cpu%d, init lo 0x%x, hi 0x%x\n", smp_processor_id(), lo, hi);
-	wrmsr(MSR_FIDVID_CTL, lo, hi);
+	rdmsrq(MSR_FIDVID_STATUS, msr.q);
+	vid = msr.h & MSR_S_HI_CURRENT_VID;
+	fid = msr.l & MSR_S_LO_CURRENT_FID;
+	msr.l = fid | (vid << MSR_C_LO_VID_SHIFT);
+	msr.h = MSR_C_HI_STP_GNT_BENIGN;
+	pr_debug("cpu%d, init lo 0x%x, hi 0x%x\n", smp_processor_id(), msr.l, msr.h);
+	wrmsrq(MSR_FIDVID_CTL, msr.q);
  }
 
  /* write the new fid value along with the other control fields to the msr */
  static int write_new_fid(struct powernow_k8_data *data, u32 fid)
  {
-	u32 lo;
+	struct msr msr;
  	u32 savevid = data->currvid;
  	u32 i = 0;
 
@@ -155,15 +155,15 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
  		return 1;
  	}
 
-	lo = fid;
-	lo |= (data->currvid << MSR_C_LO_VID_SHIFT);
-	lo |= MSR_C_LO_INIT_FID_VID;
+	msr.l = fid;
+	msr.l |= (data->currvid << MSR_C_LO_VID_SHIFT);
+	msr.l |= MSR_C_LO_INIT_FID_VID;
+	msr.h = data->plllock * PLL_LOCK_CONVERSION;
 
-	pr_debug("writing fid 0x%x, lo 0x%x, hi 0x%x\n",
-		fid, lo, data->plllock * PLL_LOCK_CONVERSION);
+	pr_debug("writing fid 0x%x, lo 0x%x, hi 0x%x\n", fid, msr.l, msr.h);
 
  	do {
-		wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION);
+		wrmsrq(MSR_FIDVID_CTL, msr.q);
  		if (i++ > 100) {
  			pr_err("Hardware error - pending bit very stuck - no further pstate changes possible\n");
  			return 1;
@@ -190,7 +190,7 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
  /* Write a new vid to the hardware */
  static int write_new_vid(struct powernow_k8_data *data, u32 vid)
  {
-	u32 lo;
+	struct msr msr;
  	u32 savefid = data->currfid;
  	int i = 0;
 
@@ -199,15 +199,15 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
  		return 1;
  	}
 
-	lo = data->currfid;
-	lo |= (vid << MSR_C_LO_VID_SHIFT);
-	lo |= MSR_C_LO_INIT_FID_VID;
+	msr.l = data->currfid;
+	msr.l |= (vid << MSR_C_LO_VID_SHIFT);
+	msr.l |= MSR_C_LO_INIT_FID_VID;
+	msr.h = STOP_GRANT_5NS;
 
-	pr_debug("writing vid 0x%x, lo 0x%x, hi 0x%x\n",
-		vid, lo, STOP_GRANT_5NS);
+	pr_debug("writing vid 0x%x, lo 0x%x, hi 0x%x\n", vid, msr.l, msr.h);
 
  	do {
-		wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
+		wrmsrq(MSR_FIDVID_CTL, msr.q);
  		if (i++ > 100) {
  			pr_err("internal error - pending bit very stuck - no further pstate changes possible\n");
  			return 1;
@@ -281,9 +281,10 @@ static int transition_fid_vid(struct powernow_k8_data *data,
  static int core_voltage_pre_transition(struct powernow_k8_data *data,
  		u32 reqvid, u32 reqfid)
  {
+	struct msr msr;
  	u32 rvosteps = data->rvo;
  	u32 savefid = data->currfid;
-	u32 maxvid, lo __always_unused, rvomult = 1;
+	u32 maxvid, rvomult = 1;
 
  	pr_debug("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, reqvid 0x%x, rvo 0x%x\n",
  		smp_processor_id(),
@@ -292,8 +293,8 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data,
  	if ((savefid < LO_FID_TABLE_TOP) && (reqfid < LO_FID_TABLE_TOP))
  		rvomult = 2;
  	rvosteps *= rvomult;
-	rdmsr(MSR_FIDVID_STATUS, lo, maxvid);
-	maxvid = 0x1f & (maxvid >> 16);
+	rdmsrq(MSR_FIDVID_STATUS, msr.q);
+	maxvid = 0x1f & (msr.h >> 16);
  	pr_debug("ph1 maxvid=0x%x\n", maxvid);
  	if (reqvid < maxvid) /* lower numbers are higher voltages */
  		reqvid = maxvid;
drivers/cpufreq/speedstep-centrino.c +8 -8
index 9237ed8f2b1f..de50fb367c6b 100644
@@ -345,7 +345,7 @@ static unsigned int get_cur_freq(unsigned int cpu)
  static int centrino_cpu_init(struct cpufreq_policy *policy)
  {
  	struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu);
-	unsigned l, h;
+	u64 q;
  	int i;
 
  	/* Only Intel makes Enhanced Speedstep-capable CPUs */
@@ -378,16 +378,16 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
 
  	/* Check to see if Enhanced SpeedStep is enabled, and try to
  	   enable it if not. */
-	rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+	rdmsrq(MSR_IA32_MISC_ENABLE, q);
 
-	if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
-		l |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
-		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", l);
-		wrmsr(MSR_IA32_MISC_ENABLE, l, h);
+	if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		q |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
+		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", (u32)q);
+		wrmsrq(MSR_IA32_MISC_ENABLE, q);
 
  		/* check to see if it stuck */
-		rdmsr(MSR_IA32_MISC_ENABLE, l, h);
-		if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		rdmsrq(MSR_IA32_MISC_ENABLE, q);
+		if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
  			pr_info("couldn't enable Enhanced SpeedStep\n");
  			return -ENODEV;
  		}
drivers/cpufreq/speedstep-lib.c +34 -29
index 973716c1c29c..2afc3f177a29 100644
@@ -69,13 +69,14 @@ static unsigned int pentium3_get_frequency(enum speedstep_processor processor)
  		{   0, 0xff}
  	};
 
+	struct msr msr;
  	u32 msr_lo, msr_tmp;
  	int i = 0, j = 0;
 
  	/* read MSR 0x2a - we only need the low 32 bits */
-	rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp);
-	pr_debug("P3 - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp);
-	msr_tmp = msr_lo;
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, msr.q);
+	pr_debug("P3 - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr.l, msr.h);
+	msr_tmp = msr_lo = msr.l;
 
  	/* decode the FSB */
  	msr_tmp &= 0x00c0000;
@@ -108,19 +109,20 @@ static unsigned int pentium3_get_frequency(enum speedstep_processor processor)
 
  static unsigned int pentiumM_get_frequency(void)
  {
-	u32 msr_lo, msr_tmp;
+	struct msr msr;
+	u32 msr_tmp;
 
-	rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp);
-	pr_debug("PM - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp);
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, msr.q);
+	pr_debug("PM - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr.l, msr.h);
 
  	/* see table B-2 of 24547212.pdf */
-	if (msr_lo & 0x00040000) {
+	if (msr.l & 0x00040000) {
  		printk(KERN_DEBUG PFX "PM - invalid FSB: 0x%x 0x%x\n",
-				msr_lo, msr_tmp);
+				msr.l, msr.h);
  		return 0;
  	}
 
-	msr_tmp = (msr_lo >> 22) & 0x1f;
+	msr_tmp = (msr.l >> 22) & 0x1f;
  	pr_debug("bits 22-26 are 0x%x, speed is %u\n",
  			msr_tmp, (msr_tmp * 100 * 1000));
 
@@ -129,13 +131,14 @@ static unsigned int pentiumM_get_frequency(void)
 
  static unsigned int pentium_core_get_frequency(void)
  {
+	struct msr msr;
  	u32 fsb = 0;
-	u32 msr_lo, msr_tmp;
+	u32 msr_tmp;
  	int ret;
 
-	rdmsr(MSR_FSB_FREQ, msr_lo, msr_tmp);
+	rdmsrq(MSR_FSB_FREQ, msr.q);
  	/* see table B-2 of 25366920.pdf */
-	switch (msr_lo & 0x07) {
+	switch (msr.l & 0x07) {
  	case 5:
  		fsb = 100000;
  		break;
@@ -158,11 +161,11 @@ static unsigned int pentium_core_get_frequency(void)
  		pr_err("PCORE - MSR_FSB_FREQ undefined value\n");
  	}
 
-	rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp);
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, msr.q);
  	pr_debug("PCORE - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n",
-			msr_lo, msr_tmp);
+			msr.l, msr.h);
 
-	msr_tmp = (msr_lo >> 22) & 0x1f;
+	msr_tmp = (msr.l >> 22) & 0x1f;
  	pr_debug("bits 22-26 are 0x%x, speed is %u\n",
  			msr_tmp, (msr_tmp * fsb));
 
@@ -174,7 +177,8 @@ static unsigned int pentium_core_get_frequency(void)
  static unsigned int pentium4_get_frequency(void)
  {
  	struct cpuinfo_x86 *c = &boot_cpu_data;
-	u32 msr_lo, msr_hi, mult;
+	struct msr msr;
+	u32 mult;
  	unsigned int fsb = 0;
  	unsigned int ret;
  	u8 fsb_code;
@@ -187,16 +191,16 @@ static unsigned int pentium4_get_frequency(void)
  	if (c->x86_model < 2)
  		return cpu_khz;
 
-	rdmsr(0x2c, msr_lo, msr_hi);
+	rdmsrq(0x2c, msr.q);
 
-	pr_debug("P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr_lo, msr_hi);
+	pr_debug("P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr.l, msr.h);
 
  	/* decode the FSB: see IA-32 Intel (C) Architecture Software
  	 * Developer's Manual, Volume 3: System Prgramming Guide,
  	 * revision #12 in Table B-1: MSRs in the Pentium 4 and
  	 * Intel Xeon Processors, on page B-4 and B-5.
  	 */
-	fsb_code = (msr_lo >> 16) & 0x7;
+	fsb_code = (msr.l >> 16) & 0x7;
  	switch (fsb_code) {
  	case 0:
  		fsb = 100 * 1000;
@@ -214,7 +218,7 @@ static unsigned int pentium4_get_frequency(void)
  				"Please send an e-mail to <[email protected]>\n");
 
  	/* Multiplier. */
-	mult = msr_lo >> 24;
+	mult = msr.l >> 24;
 
  	pr_debug("P4 - FSB %u kHz; Multiplier %u; Speed %u kHz\n",
  			fsb, mult, (fsb * mult));
@@ -255,7 +259,8 @@ EXPORT_SYMBOL_GPL(speedstep_get_frequency);
  enum speedstep_processor speedstep_detect_processor(void)
  {
  	struct cpuinfo_x86 *c = &cpu_data(0);
-	u32 ebx, msr_lo, msr_hi;
+	struct msr msr;
+	u32 ebx;
 
  	pr_debug("x86: %x, model: %x\n", c->x86, c->x86_model);
 
@@ -343,11 +348,11 @@ enum speedstep_processor speedstep_detect_processor(void)
 
  		/* all mobile PIII Coppermines have FSB 100 MHz
  		 * ==> sort out a few desktop PIIIs. */
-		rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_hi);
+		rdmsrq(MSR_IA32_EBL_CR_POWERON, msr.q);
  		pr_debug("Coppermine: MSR_IA32_EBL_CR_POWERON is 0x%x, 0x%x\n",
-				msr_lo, msr_hi);
-		msr_lo &= 0x00c0000;
-		if (msr_lo != 0x0080000)
+				msr.l, msr.h);
+		msr.l &= 0x00c0000;
+		if (msr.l != 0x0080000)
  			return 0;
 
  		/*
@@ -356,11 +361,11 @@ enum speedstep_processor speedstep_detect_processor(void)
  		 * it has SpeedStep technology if either
  		 * bit 56 or 57 is set
  		 */
-		rdmsr(MSR_IA32_PLATFORM_ID, msr_lo, msr_hi);
+		rdmsrq(MSR_IA32_PLATFORM_ID, msr.q);
  		pr_debug("Coppermine: MSR_IA32_PLATFORM ID is 0x%x, 0x%x\n",
-				msr_lo, msr_hi);
-		if ((msr_hi & (1<<18)) &&
-		    (relaxed_check ? 1 : (msr_hi & (3<<24)))) {
+				msr.l, msr.h);
+		if ((msr.h & (1<<18)) &&
+		    (relaxed_check ? 1 : (msr.h & (3<<24)))) {
  			if (c->x86_stepping == 0x01) {
  				pr_debug("early PIII version\n");
  				return SPEEDSTEP_CPU_PIII_C_EARLY;
Signature · 2 lines
Thx and BRs,
Zhongqiu Han
author maintainer
#64 lore raw

Re: [PATCH 16/32] cpufreq: Stop using 32-bit MSR interfaces

Quoted 37 lines · Zhongqiu Han
Quoted 2 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

Hello Juergen,

Quoted 31 lines

---
  drivers/cpufreq/acpi-cpufreq.c       | 22 ++++---- drivers/cpufreq/e_powersaver.c       | 48 ++++++++--------- drivers/cpufreq/longhaul.c           | 15 +++--- drivers/cpufreq/longrun.c            | 78 +++++++++++++++------------- drivers/cpufreq/powernow-k6.c        | 12 ++--- drivers/cpufreq/powernow-k8.c        | 67 ++++++++++++------------ drivers/cpufreq/speedstep-centrino.c | 16 +++--- drivers/cpufreq/speedstep-lib.c      | 63 +++++++++++-----------

  8 files changed, 166 insertions(+), 155 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +3 -4
index 21639d9ac753..b40fa99b5ab2 100644
@@ -246,32 +246,32 @@ static unsigned extract_freq(struct cpufreq_policy 
 *policy, u32 val)
   static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)
   {
-    u32 val, dummy __always_unused;
+    u64 val;
-    rdmsr(MSR_IA32_PERF_CTL, val, dummy);
-    return val;
+    rdmsrq(MSR_IA32_PERF_CTL, val);
+    return (u32)val;
   }
   static void cpu_freq_write_intel(struct acpi_pct_register *not_used, u32 val)
   {
-    u32 lo, hi;
Quoted 8 lines

drivers/cpufreq/acpi-cpufreq.c static unsigned extract_freq(struct cpufreq_policy *policy, u32 val) · line 260

Quoted 6 lines
drivers/cpufreq/acpi-cpufreq.c +3 -3
+    struct msr msrval;
-    rdmsr(MSR_IA32_PERF_CTL, lo, hi);
-    lo = (lo & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
-    wrmsr(MSR_IA32_PERF_CTL, lo, hi);
+    rdmsrq(MSR_IA32_PERF_CTL, msrval.q);
+    msrval.h = (msrval.h & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);

msrval.l

Oh, indeed.

Quoted 5 lines

please feel free to correct me if there is any misunderstanding.

how about using u64 directly?

Quoted 7 lines

    u64 msrval;
    rdmsrq(MSR_IA32_PERF_CTL, msrval);
    msrval = (msrval & ~(u64)INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE); wrmsrq(MSR_IA32_PERF_CTL, msrval);

As per my understanding, we can use u64 instead of struct msr in many other places in this patch as well.

I didn't look at all the MSR definitions to find out whether a plain u64 would work.

Will look into this in more detail.

Quoted 73 lines
Quoted 61 lines
drivers/cpufreq/acpi-cpufreq.c +5 -4
+    wrmsrq(MSR_IA32_PERF_CTL, msrval.q);
   }
   static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)
   {
-    u32 val, dummy __always_unused;
+    u64 val;
-    rdmsr(MSR_AMD_PERF_CTL, val, dummy);
-    return val;
+    rdmsrq(MSR_AMD_PERF_CTL, val);
+    return (u32)val;
   }
   static void cpu_freq_write_amd(struct acpi_pct_register *not_used, u32 val)
   {
-    wrmsr(MSR_AMD_PERF_CTL, val, 0);
+    wrmsrq(MSR_AMD_PERF_CTL, val);
   }
   static u32 cpu_freq_read_io(struct acpi_pct_register *reg)
drivers/cpufreq/e_powersaver.c +7 -8
index eb5a9209d828..13709f9667ea 100644
@@ -90,7 +90,7 @@ static int eps_acpi_exit(struct cpufreq_policy *policy)
   static unsigned int eps_get(unsigned int cpu)
   {
       struct eps_cpu_data *centaur;
-    u32 lo, hi;
+    u64 val;
       if (cpu)
           return 0;
@@ -99,35 +99,35 @@ static unsigned int eps_get(unsigned int cpu)
           return 0;
       /* Return current frequency */
-    rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-    return centaur->fsb * ((lo >> 8) & 0xff);
+    rdmsrq(MSR_IA32_PERF_STATUS, val);
+    return centaur->fsb * ((val >> 8) & 0xff);
   }
   static int eps_set_state(struct eps_cpu_data *centaur,
                struct cpufreq_policy *policy,
                u32 dest_state)
   {
-    u32 lo, hi;
+    u64 val;
       int i;
       /* Wait while CPU is busy */
-    rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
+    rdmsrq(MSR_IA32_PERF_STATUS, val);
       i = 0;
-    while (lo & ((1 << 16) | (1 << 17))) {
+    while (val & ((1 << 16) | (1 << 17))) {
           udelay(16);
-        rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
+        rdmsrq(MSR_IA32_PERF_STATUS, val);
           i++;
           if (unlikely(i > 64)) {
               return -ENODEV;
           }
       }
       /* Set new multiplier and voltage */
-    wrmsr(MSR_IA32_PERF_CTL, dest_state & 0xffff, 0);

drivers/cpufreq/e_powersaver.c static unsigned int eps_get(unsigned int cpu) · line 130

Quoted 10 lines
drivers/cpufreq/e_powersaver.c +2 -1
+    wrmsrq(MSR_IA32_PERF_CTL, dest_state & 0xffff);
       /* Wait until transition end */
       i = 0;
       do {
           udelay(16);
-        rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
+        rdmsrq(MSR_IA32_PERF_STATUS, val);
           i++;
           if (unlikely(i > 64)) {
               return -ENODEV;
Quoted 8 lines

    do {
        udelay(16);
        rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
        i++;
        if (unlikely(i > 64)) {
            return -ENODEV;
        }
    } while (lo & ((1 << 16) | (1 << 17)));-->lo has been deleted?

Thanks for spotting that. Seems by 32-bit allyesconfig tree lost the config entry needed for building this source.

Will fix this.

Quoted 278 lines
Quoted 243 lines
drivers/cpufreq/e_powersaver.c +4 -4
@@ -139,10 +139,10 @@ static int eps_set_state(struct eps_cpu_data *centaur,
       u8 current_multiplier, current_voltage;
       /* Print voltage and multiplier */
-    rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-    current_voltage = lo & 0xff;
+    rdmsrq(MSR_IA32_PERF_STATUS, val);
+    current_voltage = val & 0xff;
       pr_info("Current voltage = %dmV\n", current_voltage * 16 + 700);
-    current_multiplier = (lo >> 8) & 0xff;
+    current_multiplier = (val >> 8) & 0xff;
       pr_info("Current multiplier = %d\n", current_multiplier);
       }
   #endif
@@ -171,8 +171,8 @@ static int eps_target(struct cpufreq_policy *policy, 
 unsigned int index)
   static int eps_cpu_init(struct cpufreq_policy *policy)
   {
       unsigned int i;
-    u32 lo, hi;
       u64 val;
+    struct msr status;
       u8 current_multiplier, current_voltage;
       u8 max_multiplier, max_voltage;

      u8 min_multiplier, min_voltage;

drivers/cpufreq/e_powersaver.c +0 -0
@@ -195,13 +195,13 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
       switch (c->x86_model) {

      case 10:
-        rdmsr(0x1153, lo, hi);
-        brand = (((lo >> 2) ^ lo) >> 18) & 3;
+        rdmsrq(0x1153, val);
+        brand = (((val >> 2) ^ val) >> 18) & 3; pr_cont("Model A ");
          break;
      case 13:
-        rdmsr(0x1154, lo, hi);
-        brand = (((lo >> 4) ^ (lo >> 2))) & 0x000000ff; +        rdmsrq(0x1154, val);
+        brand = (((val >> 4) ^ (val >> 2))) & 0x000000ff; pr_cont("Model D ");
          break;
      }

drivers/cpufreq/e_powersaver.c +7 -7
@@ -237,20 +237,20 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
       }
       /* Print voltage and multiplier */
-    rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-    current_voltage = lo & 0xff;
+    rdmsrq(MSR_IA32_PERF_STATUS, status.q);
+    current_voltage = status.l & 0xff;
       pr_info("Current voltage = %dmV\n", current_voltage * 16 + 700);
-    current_multiplier = (lo >> 8) & 0xff;
+    current_multiplier = (status.l >> 8) & 0xff;
       pr_info("Current multiplier = %d\n", current_multiplier);
       /* Print limits */
-    max_voltage = hi & 0xff;
+    max_voltage = status.h & 0xff;
       pr_info("Highest voltage = %dmV\n", max_voltage * 16 + 700);
-    max_multiplier = (hi >> 8) & 0xff;
+    max_multiplier = (status.h >> 8) & 0xff;
       pr_info("Highest multiplier = %d\n", max_multiplier);
-    min_voltage = (hi >> 16) & 0xff;
+    min_voltage = (status.h >> 16) & 0xff;
       pr_info("Lowest voltage = %dmV\n", min_voltage * 16 + 700);
-    min_multiplier = (hi >> 24) & 0xff;
+    min_multiplier = (status.h >> 24) & 0xff;
       pr_info("Lowest multiplier = %d\n", min_multiplier);
       /* Sanity checks */
drivers/cpufreq/longhaul.c +4 -3
index a18d1d11725f..4c2599264333 100644
@@ -118,13 +118,14 @@ static unsigned int calc_speed(int mult)
   static int longhaul_get_cpu_mult(void)
   {
-    unsigned long invalue = 0, lo, hi;
+    unsigned long invalue = 0;
+    u64 val;
-    rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi);
-    invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22;
+    rdmsrq(MSR_IA32_EBL_CR_POWERON, val);
+    invalue = (val & (1<<22|1<<23|1<<24|1<<25))>>22;

      if (longhaul_version == TYPE_LONGHAUL_V2 ||
          longhaul_version == TYPE_POWERSAVER) {
-        if (lo & (1<<27))
+        if (val & (1<<27))
              invalue += 16;
      }
      return eblcr[invalue];

drivers/cpufreq/longhaul.c +3 -3
@@ -761,7 +762,7 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
       struct cpuinfo_x86 *c = &cpu_data(0);
       char *cpuname = NULL;
       int ret;
-    u32 lo, hi;
+    u64 val;
       /* Check what we have on this motherboard */
       switch (c->x86_model) {
@@ -835,8 +836,8 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
       }
       /* Check Longhaul ver. 2 */
       if (longhaul_version == TYPE_LONGHAUL_V2) {
-        rdmsr(MSR_VIA_LONGHAUL, lo, hi);
-        if (lo == 0 && hi == 0)
+        rdmsrq(MSR_VIA_LONGHAUL, val);
+        if (val == 0)
               /* Looks like MSR isn't present */
               longhaul_version = TYPE_LONGHAUL_V1;
       }
drivers/cpufreq/longrun.c +4 -4
index f3aaca0496a4..99abef32e7e5 100644
@@ -35,27 +35,27 @@ static unsigned int longrun_low_freq, longrun_high_freq;
    */
   static void longrun_get_policy(struct cpufreq_policy *policy)
   {
-    u32 msr_lo, msr_hi;
+    struct msr msr;
-    rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
-    pr_debug("longrun flags are %x - %x\n", msr_lo, msr_hi);
-    if (msr_lo & 0x01)
+    rdmsrq(MSR_TMTA_LONGRUN_FLAGS, msr.q);
+    pr_debug("longrun flags are %x - %x\n", msr.l, msr.h);
+    if (msr.l & 0x01)
           policy->policy = CPUFREQ_POLICY_PERFORMANCE;

      else
          policy->policy = CPUFREQ_POLICY_POWERSAVE; -    rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); -    pr_debug("longrun ctrl is %x - %x\n", msr_lo, msr_hi); -    msr_lo &= 0x0000007F;
-    msr_hi &= 0x0000007F;
+    rdmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
+    pr_debug("longrun ctrl is %x - %x\n", msr.l, msr.h); +    msr.l &= 0x0000007F;
+    msr.h &= 0x0000007F;
      if (longrun_high_freq <= longrun_low_freq) { /* Assume degenerate Longrun table */ policy->min = policy->max = longrun_high_freq; } else {
-        policy->min = longrun_low_freq + msr_lo * +        policy->min = longrun_low_freq + msr.l * ((longrun_high_freq - longrun_low_freq) / 100); -        policy->max = longrun_low_freq + msr_hi * +        policy->max = longrun_low_freq + msr.h * ((longrun_high_freq - longrun_low_freq) / 100); }
      policy->cpu = 0;

drivers/cpufreq/longrun.c +3 -3
@@ -71,7 +71,7 @@ static void longrun_get_policy(struct cpufreq_policy *policy)
    */
   static int longrun_set_policy(struct cpufreq_policy *policy)
   {
-    u32 msr_lo, msr_hi;
+    struct msr msr;
       u32 pctg_lo, pctg_hi;
       if (!policy)
@@ -93,24 +93,24 @@ static int longrun_set_policy(struct cpufreq_policy *policy)
           pctg_lo = pctg_hi;
       /* performance or economy mode */
-    rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
-    msr_lo &= 0xFFFFFFFE;
+    rdmsrq(MSR_TMTA_LONGRUN_FLAGS, msr.q);
+    msr.l &= 0xFFFFFFFE;
       switch (policy->policy) {

      case CPUFREQ_POLICY_PERFORMANCE:
-        msr_lo |= 0x00000001;
+        msr.l |= 0x00000001;
          break;
      case CPUFREQ_POLICY_POWERSAVE:
          break;
      }
-    wrmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); +    wrmsrq(MSR_TMTA_LONGRUN_FLAGS, msr.q); /* lower and upper boundary */
-    rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); -    msr_lo &= 0xFFFFFF80;
-    msr_hi &= 0xFFFFFF80;
-    msr_lo |= pctg_lo;
-    msr_hi |= pctg_hi;
-    wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); +    rdmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q); +    msr.l &= 0xFFFFFF80;
+    msr.h &= 0xFFFFFF80;
+    msr.l |= pctg_lo;
+    msr.h |= pctg_hi;
+    wrmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q); return 0;
  }

drivers/cpufreq/longrun.c +15 -15
@@ -160,7 +160,7 @@ static unsigned int longrun_get(unsigned int cpu)
   static int longrun_determine_freqs(unsigned int *low_freq,
                                 unsigned int *high_freq)
   {
-    u32 msr_lo, msr_hi;
+    struct msr msr;
       u32 save_lo, save_hi;
       u32 eax, ebx, ecx, edx;
       u32 try_hi;
@@ -178,15 +178,17 @@ static int longrun_determine_freqs(unsigned int *low_freq,
            * For maximum frequency, read out level zero.
            */
           /* minimum */
-        rdmsr(MSR_TMTA_LRTI_READOUT, msr_lo, msr_hi);
-        wrmsr(MSR_TMTA_LRTI_READOUT, msr_hi, msr_hi);
-        rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi);
-        *low_freq = msr_lo * 1000; /* to kHz */
+        rdmsrq(MSR_TMTA_LRTI_READOUT, msr.q);
+        msr.l = msr.h;
+        wrmsrq(MSR_TMTA_LRTI_READOUT, msr.q);
+        rdmsrq(MSR_TMTA_LRTI_VOLT_MHZ, msr.q);
+        *low_freq = msr.l * 1000; /* to kHz */
           /* maximum */
-        wrmsr(MSR_TMTA_LRTI_READOUT, 0, msr_hi);
-        rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi);
-        *high_freq = msr_lo * 1000; /* to kHz */
+        msr.l = 0;
+        wrmsrq(MSR_TMTA_LRTI_READOUT, msr.q);
+        rdmsrq(MSR_TMTA_LRTI_VOLT_MHZ, msr.q);
+        *high_freq = msr.l * 1000; /* to kHz */
           pr_debug("longrun table interface told %u - %u kHz\n",
                   *low_freq, *high_freq);
@@ -202,9 +204,9 @@ static int longrun_determine_freqs(unsigned int *low_freq,
       pr_debug("high frequency is %u kHz\n", *high_freq);
       /* get current borders */
-    rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
-    save_lo = msr_lo & 0x0000007F;
-    save_hi = msr_hi & 0x0000007F;
+    rdmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
+    save_lo = msr.l & 0x0000007F;
+    save_hi = msr.h & 0x0000007F;
       /* if current perf_pctg is larger than 90%, we need to decrease the
        * upper limit to make the calculation more accurate.
@@ -214,16 +216,18 @@ static int longrun_determine_freqs(unsigned int *low_freq,
        * on some barrier values */
       for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -= 10) {
           /* set to 0 to try_hi perf_pctg */
-        msr_lo &= 0xFFFFFF80;
-        msr_hi &= 0xFFFFFF80;
-        msr_hi |= try_hi;
-        wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
+        msr.l &= 0xFFFFFF80;
+        msr.h &= 0xFFFFFF80;

drivers/cpufreq/longrun.c static int longrun_determine_freqs(unsigned int *low_freq, · line 229

Quoted 10 lines
drivers/cpufreq/longrun.c +5 -1
+        msr.h |= try_hi;
+        wrmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
           /* read out current core MHz and current perf_pctg */
           cpuid(0x80860007, &eax, &ebx, &ecx, &edx);
           /* restore values */
-        wrmsr(MSR_TMTA_LONGRUN_CTRL, save_lo, save_hi);
+        msr.l = save_lo;
+        msr.h = save_hi;
+        wrmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
       }

As sashiko.dev pointed, from the second iter, this patch code will clear upper 25 bits to zero.

https://sashiko.dev/#/patchset/20260629060526.3638272-1-jgross%40suse.com

for (try_hi = 80; ...; ...) {
-   msr_lo &= 0xFFFFFF80;    /* iter 1: X.lo[31:7]; iter 2+: same */ -   msr_hi &= 0xFFFFFF80;
-   msr_hi |= try_hi;
-   wrmsr(reg, msr_lo, msr_hi);/* writes X.hi[31:7] | try_hi    */ +   msr.l &= 0xFFFFFF80;      /* iter 2+: locals=0 -> mask = 0  */ +   msr.h &= 0xFFFFFF80;
+   msr.h |= try_hi;
+   wrmsrq(reg, msr.q);   /* <-- iter 2+ writes 0 (vs X.hi[31:7])*/

    cpuid(...);

    /* restore */
-   wrmsr(reg, save_lo, save_hi);  /* locals untouched */
+   msr.l = save_lo;              /* poisons locals ->next iter bug  */ +   msr.h = save_hi;
+   wrmsrq(reg, msr.q);
}

Quoted 3 lines

I'm not sure whether the upper 25 bits are reserved, but the original code preserved them across iterations. It might be safer to keep that behavior unchanged.

Will fix that.

Juergen

author maintainer
#65 lore raw

PATCH v2 16/32 cpufreq: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
V2:
- fix bug in cpu_freq_write_intel() (Zhongqiu Han)
- fix bug in eps_set_state() (Zhongqiu Han)
- fix bug in longrun_determine_freqs() (Zhongqiu Han)
- use u64 instead of struct msr in some places (Zhongqiu Han)

---
 drivers/cpufreq/acpi-cpufreq.c       | 22 ++++----
 drivers/cpufreq/e_powersaver.c       | 49 +++++++++---------
 drivers/cpufreq/longhaul.c           | 15 +++---
 drivers/cpufreq/longrun.c            | 77 ++++++++++++++--------------
 drivers/cpufreq/powernow-k6.c        | 12 ++---
 drivers/cpufreq/powernow-k8.c        | 67 ++++++++++++------------
 drivers/cpufreq/speedstep-centrino.c | 16 +++---
 drivers/cpufreq/speedstep-lib.c      | 63 ++++++++++++-----------
 8 files changed, 164 insertions(+), 157 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +11 -11
index 21639d9ac753..10ea6035f4ad 100644
@@ -246,32 +246,32 @@ static unsigned extract_freq(struct cpufreq_policy *policy, u32 val)
 
 static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)
 {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_IA32_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_IA32_PERF_CTL, val);
+	return (u32)val;
 }
 
 static void cpu_freq_write_intel(struct acpi_pct_register *not_used, u32 val)
 {
-	u32 lo, hi;
+	u64 msrval;
 
-	rdmsr(MSR_IA32_PERF_CTL, lo, hi);
-	lo = (lo & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
-	wrmsr(MSR_IA32_PERF_CTL, lo, hi);
+	rdmsrq(MSR_IA32_PERF_CTL, msrval);
+	msrval = (msrval & ~(u64)INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
+	wrmsrq(MSR_IA32_PERF_CTL, msrval);
 }
 
 static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)
 {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_AMD_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_AMD_PERF_CTL, val);
+	return (u32)val;
 }
 
 static void cpu_freq_write_amd(struct acpi_pct_register *not_used, u32 val)
 {
-	wrmsr(MSR_AMD_PERF_CTL, val, 0);
+	wrmsrq(MSR_AMD_PERF_CTL, val);
 }
 
 static u32 cpu_freq_read_io(struct acpi_pct_register *reg)
drivers/cpufreq/e_powersaver.c +24 -25

121 lines not on this page · raw message

drivers/cpufreq/longhaul.c +8 -7
index a18d1d11725f..4c2599264333 100644
@@ -118,13 +118,14 @@ static unsigned int calc_speed(int mult)
 
 static int longhaul_get_cpu_mult(void)
 {
-	unsigned long invalue = 0, lo, hi;
+	unsigned long invalue = 0;
+	u64 val;
 
-	rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi);
-	invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22;
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, val);
+	invalue = (val & (1<<22|1<<23|1<<24|1<<25))>>22;
 	if (longhaul_version == TYPE_LONGHAUL_V2 ||
 	    longhaul_version == TYPE_POWERSAVER) {
-		if (lo & (1<<27))
+		if (val & (1<<27))
 			invalue += 16;
 	}
 	return eblcr[invalue];
@@ -761,7 +762,7 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
 	struct cpuinfo_x86 *c = &cpu_data(0);
 	char *cpuname = NULL;
 	int ret;
-	u32 lo, hi;
+	u64 val;
 
 	/* Check what we have on this motherboard */
 	switch (c->x86_model) {
@@ -835,8 +836,8 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
 	}
 	/* Check Longhaul ver. 2 */
 	if (longhaul_version == TYPE_LONGHAUL_V2) {
-		rdmsr(MSR_VIA_LONGHAUL, lo, hi);
-		if (lo == 0 && hi == 0)
+		rdmsrq(MSR_VIA_LONGHAUL, val);
+		if (val == 0)
 			/* Looks like MSR isn't present */
 			longhaul_version = TYPE_LONGHAUL_V1;
 	}
drivers/cpufreq/longrun.c +39 -38

145 lines not on this page · raw message

drivers/cpufreq/powernow-k6.c +6 -6
index 99d2244e03b0..2044e8a336ec 100644
@@ -83,15 +83,15 @@ static const struct {
 static int powernow_k6_get_cpu_multiplier(void)
 {
 	unsigned long invalue = 0;
-	u32 msrval;
+	u64 msrval;
 
 	local_irq_disable();
 
 	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
 	invalue = inl(POWERNOW_IOPORT + 0x8);
 	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
 	local_irq_enable();
 
@@ -101,8 +101,8 @@ static int powernow_k6_get_cpu_multiplier(void)
 static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
 {
 	unsigned long outvalue, invalue;
-	unsigned long msrval;
 	unsigned long cr0;
+	u64 msrval;
 
 	/* we now need to transform best_i to the BVC format, see AMD#23446 */
 
@@ -118,13 +118,13 @@ static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
 	outvalue = (1<<12) | (1<<10) | (1<<9) | (index_to_register[best_i]<<5);
 
 	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
 	invalue = inl(POWERNOW_IOPORT + 0x8);
 	invalue = invalue & 0x1f;
 	outvalue = outvalue | invalue;
 	outl(outvalue, (POWERNOW_IOPORT + 0x8));
 	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
 	write_cr0(cr0);
 	local_irq_enable();
drivers/cpufreq/powernow-k8.c +34 -33

138 lines not on this page · raw message

drivers/cpufreq/speedstep-centrino.c +8 -8
index 9237ed8f2b1f..de50fb367c6b 100644
@@ -345,7 +345,7 @@ static unsigned int get_cur_freq(unsigned int cpu)
 static int centrino_cpu_init(struct cpufreq_policy *policy)
 {
 	struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu);
-	unsigned l, h;
+	u64 q;
 	int i;
 
 	/* Only Intel makes Enhanced Speedstep-capable CPUs */
@@ -378,16 +378,16 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
 
 	/* Check to see if Enhanced SpeedStep is enabled, and try to
 	   enable it if not. */
-	rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+	rdmsrq(MSR_IA32_MISC_ENABLE, q);
 
-	if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
-		l |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
-		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", l);
-		wrmsr(MSR_IA32_MISC_ENABLE, l, h);
+	if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		q |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
+		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", (u32)q);
+		wrmsrq(MSR_IA32_MISC_ENABLE, q);
 
 		/* check to see if it stuck */
-		rdmsr(MSR_IA32_MISC_ENABLE, l, h);
-		if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		rdmsrq(MSR_IA32_MISC_ENABLE, q);
+		if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
 			pr_info("couldn't enable Enhanced SpeedStep\n");
 			return -ENODEV;
 		}
drivers/cpufreq/speedstep-lib.c +34 -29

149 lines not on this page · raw message

Signature · 1 line
2.54.0
Reviewed-by on v2 16/32
#66 lore raw

Re: [PATCH v2 16/32] cpufreq: Stop using 32-bit MSR interfaces

Quoted 10 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
V2:
- fix bug in cpu_freq_write_intel() (Zhongqiu Han)
- fix bug in eps_set_state() (Zhongqiu Han)
- fix bug in longrun_determine_freqs() (Zhongqiu Han)
- use u64 instead of struct msr in some places (Zhongqiu Han)

Looks good to me, thanks Juergen.

Quoted 788 lines
---
  drivers/cpufreq/acpi-cpufreq.c       | 22 ++++----
  drivers/cpufreq/e_powersaver.c       | 49 +++++++++---------
  drivers/cpufreq/longhaul.c           | 15 +++---
  drivers/cpufreq/longrun.c            | 77 ++++++++++++++--------------
  drivers/cpufreq/powernow-k6.c        | 12 ++---
  drivers/cpufreq/powernow-k8.c        | 67 ++++++++++++------------
  drivers/cpufreq/speedstep-centrino.c | 16 +++---
  drivers/cpufreq/speedstep-lib.c      | 63 ++++++++++++-----------
  8 files changed, 164 insertions(+), 157 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +11 -11
index 21639d9ac753..10ea6035f4ad 100644
@@ -246,32 +246,32 @@ static unsigned extract_freq(struct cpufreq_policy *policy, u32 val)
 
  static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)
  {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_IA32_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_IA32_PERF_CTL, val);
+	return (u32)val;
  }
 
  static void cpu_freq_write_intel(struct acpi_pct_register *not_used, u32 val)
  {
-	u32 lo, hi;
+	u64 msrval;
 
-	rdmsr(MSR_IA32_PERF_CTL, lo, hi);
-	lo = (lo & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
-	wrmsr(MSR_IA32_PERF_CTL, lo, hi);
+	rdmsrq(MSR_IA32_PERF_CTL, msrval);
+	msrval = (msrval & ~(u64)INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
+	wrmsrq(MSR_IA32_PERF_CTL, msrval);
  }
 
  static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)
  {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_AMD_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_AMD_PERF_CTL, val);
+	return (u32)val;
  }
 
  static void cpu_freq_write_amd(struct acpi_pct_register *not_used, u32 val)
  {
-	wrmsr(MSR_AMD_PERF_CTL, val, 0);
+	wrmsrq(MSR_AMD_PERF_CTL, val);
  }
 
  static u32 cpu_freq_read_io(struct acpi_pct_register *reg)
drivers/cpufreq/e_powersaver.c +24 -25
index eb5a9209d828..54689ebadeb2 100644
@@ -90,7 +90,7 @@ static int eps_acpi_exit(struct cpufreq_policy *policy)
  static unsigned int eps_get(unsigned int cpu)
  {
  	struct eps_cpu_data *centaur;
-	u32 lo, hi;
+	u64 val;
 
  	if (cpu)
  		return 0;
@@ -99,50 +99,50 @@ static unsigned int eps_get(unsigned int cpu)
  		return 0;
 
  	/* Return current frequency */
-	rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-	return centaur->fsb * ((lo >> 8) & 0xff);
+	rdmsrq(MSR_IA32_PERF_STATUS, val);
+	return centaur->fsb * ((val >> 8) & 0xff);
  }
 
  static int eps_set_state(struct eps_cpu_data *centaur,
  			 struct cpufreq_policy *policy,
  			 u32 dest_state)
  {
-	u32 lo, hi;
+	u64 val;
  	int i;
 
  	/* Wait while CPU is busy */
-	rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
+	rdmsrq(MSR_IA32_PERF_STATUS, val);
  	i = 0;
-	while (lo & ((1 << 16) | (1 << 17))) {
+	while (val & ((1 << 16) | (1 << 17))) {
  		udelay(16);
-		rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
+		rdmsrq(MSR_IA32_PERF_STATUS, val);
  		i++;
  		if (unlikely(i > 64)) {
  			return -ENODEV;
  		}
  	}
  	/* Set new multiplier and voltage */
-	wrmsr(MSR_IA32_PERF_CTL, dest_state & 0xffff, 0);
+	wrmsrq(MSR_IA32_PERF_CTL, dest_state & 0xffff);
  	/* Wait until transition end */
  	i = 0;
  	do {
  		udelay(16);
-		rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
+		rdmsrq(MSR_IA32_PERF_STATUS, val);
  		i++;
  		if (unlikely(i > 64)) {
  			return -ENODEV;
  		}
-	} while (lo & ((1 << 16) | (1 << 17)));
+	} while (val & ((1 << 16) | (1 << 17)));
 
  #ifdef DEBUG
  	{
  	u8 current_multiplier, current_voltage;
 
  	/* Print voltage and multiplier */
-	rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-	current_voltage = lo & 0xff;
+	rdmsrq(MSR_IA32_PERF_STATUS, val);
+	current_voltage = val & 0xff;
  	pr_info("Current voltage = %dmV\n", current_voltage * 16 + 700);
-	current_multiplier = (lo >> 8) & 0xff;
+	current_multiplier = (val >> 8) & 0xff;
  	pr_info("Current multiplier = %d\n", current_multiplier);
  	}
  #endif
@@ -171,7 +171,6 @@ static int eps_target(struct cpufreq_policy *policy, unsigned int index)
  static int eps_cpu_init(struct cpufreq_policy *policy)
  {
  	unsigned int i;
-	u32 lo, hi;
  	u64 val;
  	u8 current_multiplier, current_voltage;
  	u8 max_multiplier, max_voltage;
@@ -195,13 +194,13 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
 
  	switch (c->x86_model) {
  	case 10:
-		rdmsr(0x1153, lo, hi);
-		brand = (((lo >> 2) ^ lo) >> 18) & 3;
+		rdmsrq(0x1153, val);
+		brand = (((val >> 2) ^ val) >> 18) & 3;
  		pr_cont("Model A ");
  		break;
  	case 13:
-		rdmsr(0x1154, lo, hi);
-		brand = (((lo >> 4) ^ (lo >> 2))) & 0x000000ff;
+		rdmsrq(0x1154, val);
+		brand = (((val >> 4) ^ (val >> 2))) & 0x000000ff;
  		pr_cont("Model D ");
  		break;
  	}
@@ -237,20 +236,20 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
  	}
 
  	/* Print voltage and multiplier */
-	rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
-	current_voltage = lo & 0xff;
+	rdmsrq(MSR_IA32_PERF_STATUS, val);
+	current_voltage = val & 0xff;
  	pr_info("Current voltage = %dmV\n", current_voltage * 16 + 700);
-	current_multiplier = (lo >> 8) & 0xff;
+	current_multiplier = (val >> 8) & 0xff;
  	pr_info("Current multiplier = %d\n", current_multiplier);
 
  	/* Print limits */
-	max_voltage = hi & 0xff;
+	max_voltage = (val >> 32) & 0xff;
  	pr_info("Highest voltage = %dmV\n", max_voltage * 16 + 700);
-	max_multiplier = (hi >> 8) & 0xff;
+	max_multiplier = (val >> 40) & 0xff;
  	pr_info("Highest multiplier = %d\n", max_multiplier);
-	min_voltage = (hi >> 16) & 0xff;
+	min_voltage = (val >> 48) & 0xff;
  	pr_info("Lowest voltage = %dmV\n", min_voltage * 16 + 700);
-	min_multiplier = (hi >> 24) & 0xff;
+	min_multiplier = (val >> 56) & 0xff;
  	pr_info("Lowest multiplier = %d\n", min_multiplier);
 
  	/* Sanity checks */
drivers/cpufreq/longhaul.c +8 -7
index a18d1d11725f..4c2599264333 100644
@@ -118,13 +118,14 @@ static unsigned int calc_speed(int mult)
 
  static int longhaul_get_cpu_mult(void)
  {
-	unsigned long invalue = 0, lo, hi;
+	unsigned long invalue = 0;
+	u64 val;
 
-	rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi);
-	invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22;
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, val);
+	invalue = (val & (1<<22|1<<23|1<<24|1<<25))>>22;
  	if (longhaul_version == TYPE_LONGHAUL_V2 ||
  	    longhaul_version == TYPE_POWERSAVER) {
-		if (lo & (1<<27))
+		if (val & (1<<27))
  			invalue += 16;
  	}
  	return eblcr[invalue];
@@ -761,7 +762,7 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
  	struct cpuinfo_x86 *c = &cpu_data(0);
  	char *cpuname = NULL;
  	int ret;
-	u32 lo, hi;
+	u64 val;
 
  	/* Check what we have on this motherboard */
  	switch (c->x86_model) {
@@ -835,8 +836,8 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
  	}
  	/* Check Longhaul ver. 2 */
  	if (longhaul_version == TYPE_LONGHAUL_V2) {
-		rdmsr(MSR_VIA_LONGHAUL, lo, hi);
-		if (lo == 0 && hi == 0)
+		rdmsrq(MSR_VIA_LONGHAUL, val);
+		if (val == 0)
  			/* Looks like MSR isn't present */
  			longhaul_version = TYPE_LONGHAUL_V1;
  	}
drivers/cpufreq/longrun.c +39 -38
index f3aaca0496a4..82a7bb69c401 100644
@@ -35,27 +35,27 @@ static unsigned int longrun_low_freq, longrun_high_freq;
   */
  static void longrun_get_policy(struct cpufreq_policy *policy)
  {
-	u32 msr_lo, msr_hi;
+	struct msr msr;
 
-	rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
-	pr_debug("longrun flags are %x - %x\n", msr_lo, msr_hi);
-	if (msr_lo & 0x01)
+	rdmsrq(MSR_TMTA_LONGRUN_FLAGS, msr.q);
+	pr_debug("longrun flags are %x - %x\n", msr.l, msr.h);
+	if (msr.l & 0x01)
  		policy->policy = CPUFREQ_POLICY_PERFORMANCE;
  	else
  		policy->policy = CPUFREQ_POLICY_POWERSAVE;
 
-	rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
-	pr_debug("longrun ctrl is %x - %x\n", msr_lo, msr_hi);
-	msr_lo &= 0x0000007F;
-	msr_hi &= 0x0000007F;
+	rdmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
+	pr_debug("longrun ctrl is %x - %x\n", msr.l, msr.h);
+	msr.l &= 0x0000007F;
+	msr.h &= 0x0000007F;
 
  	if (longrun_high_freq <= longrun_low_freq) {
  		/* Assume degenerate Longrun table */
  		policy->min = policy->max = longrun_high_freq;
  	} else {
-		policy->min = longrun_low_freq + msr_lo *
+		policy->min = longrun_low_freq + msr.l *
  			((longrun_high_freq - longrun_low_freq) / 100);
-		policy->max = longrun_low_freq + msr_hi *
+		policy->max = longrun_low_freq + msr.h *
  			((longrun_high_freq - longrun_low_freq) / 100);
  	}
  	policy->cpu = 0;
@@ -71,7 +71,7 @@ static void longrun_get_policy(struct cpufreq_policy *policy)
   */
  static int longrun_set_policy(struct cpufreq_policy *policy)
  {
-	u32 msr_lo, msr_hi;
+	struct msr msr;
  	u32 pctg_lo, pctg_hi;
 
  	if (!policy)
@@ -93,24 +93,24 @@ static int longrun_set_policy(struct cpufreq_policy *policy)
  		pctg_lo = pctg_hi;
 
  	/* performance or economy mode */
-	rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
-	msr_lo &= 0xFFFFFFFE;
+	rdmsrq(MSR_TMTA_LONGRUN_FLAGS, msr.q);
+	msr.l &= 0xFFFFFFFE;
  	switch (policy->policy) {
  	case CPUFREQ_POLICY_PERFORMANCE:
-		msr_lo |= 0x00000001;
+		msr.l |= 0x00000001;
  		break;
  	case CPUFREQ_POLICY_POWERSAVE:
  		break;
  	}
-	wrmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi);
+	wrmsrq(MSR_TMTA_LONGRUN_FLAGS, msr.q);
 
  	/* lower and upper boundary */
-	rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
-	msr_lo &= 0xFFFFFF80;
-	msr_hi &= 0xFFFFFF80;
-	msr_lo |= pctg_lo;
-	msr_hi |= pctg_hi;
-	wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
+	rdmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
+	msr.l &= 0xFFFFFF80;
+	msr.h &= 0xFFFFFF80;
+	msr.l |= pctg_lo;
+	msr.h |= pctg_hi;
+	wrmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
 
  	return 0;
  }
@@ -160,8 +160,7 @@ static unsigned int longrun_get(unsigned int cpu)
  static int longrun_determine_freqs(unsigned int *low_freq,
  						      unsigned int *high_freq)
  {
-	u32 msr_lo, msr_hi;
-	u32 save_lo, save_hi;
+	struct msr msr, save;
  	u32 eax, ebx, ecx, edx;
  	u32 try_hi;
  	struct cpuinfo_x86 *c = &cpu_data(0);
@@ -178,15 +177,17 @@ static int longrun_determine_freqs(unsigned int *low_freq,
  		 * For maximum frequency, read out level zero.
  		 */
  		/* minimum */
-		rdmsr(MSR_TMTA_LRTI_READOUT, msr_lo, msr_hi);
-		wrmsr(MSR_TMTA_LRTI_READOUT, msr_hi, msr_hi);
-		rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi);
-		*low_freq = msr_lo * 1000; /* to kHz */
+		rdmsrq(MSR_TMTA_LRTI_READOUT, msr.q);
+		msr.l = msr.h;
+		wrmsrq(MSR_TMTA_LRTI_READOUT, msr.q);
+		rdmsrq(MSR_TMTA_LRTI_VOLT_MHZ, msr.q);
+		*low_freq = msr.l * 1000; /* to kHz */
 
  		/* maximum */
-		wrmsr(MSR_TMTA_LRTI_READOUT, 0, msr_hi);
-		rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi);
-		*high_freq = msr_lo * 1000; /* to kHz */
+		msr.l = 0;
+		wrmsrq(MSR_TMTA_LRTI_READOUT, msr.q);
+		rdmsrq(MSR_TMTA_LRTI_VOLT_MHZ, msr.q);
+		*high_freq = msr.l * 1000; /* to kHz */
 
  		pr_debug("longrun table interface told %u - %u kHz\n",
  				*low_freq, *high_freq);
@@ -202,9 +203,9 @@ static int longrun_determine_freqs(unsigned int *low_freq,
  	pr_debug("high frequency is %u kHz\n", *high_freq);
 
  	/* get current borders */
-	rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
-	save_lo = msr_lo & 0x0000007F;
-	save_hi = msr_hi & 0x0000007F;
+	rdmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
+	save.l = msr.l & 0x0000007F;
+	save.h = msr.h & 0x0000007F;
 
  	/* if current perf_pctg is larger than 90%, we need to decrease the
  	 * upper limit to make the calculation more accurate.
@@ -214,16 +215,16 @@ static int longrun_determine_freqs(unsigned int *low_freq,
  	 * on some barrier values */
  	for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -= 10) {
  		/* set to 0 to try_hi perf_pctg */
-		msr_lo &= 0xFFFFFF80;
-		msr_hi &= 0xFFFFFF80;
-		msr_hi |= try_hi;
-		wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi);
+		msr.l &= 0xFFFFFF80;
+		msr.h &= 0xFFFFFF80;
+		msr.h |= try_hi;
+		wrmsrq(MSR_TMTA_LONGRUN_CTRL, msr.q);
 
  		/* read out current core MHz and current perf_pctg */
  		cpuid(0x80860007, &eax, &ebx, &ecx, &edx);
 
  		/* restore values */
-		wrmsr(MSR_TMTA_LONGRUN_CTRL, save_lo, save_hi);
+		wrmsrq(MSR_TMTA_LONGRUN_CTRL, save.q);
  	}
  	pr_debug("percentage is %u %%, freq is %u MHz\n", ecx, eax);
 
drivers/cpufreq/powernow-k6.c +6 -6
index 99d2244e03b0..2044e8a336ec 100644
@@ -83,15 +83,15 @@ static const struct {
  static int powernow_k6_get_cpu_multiplier(void)
  {
  	unsigned long invalue = 0;
-	u32 msrval;
+	u64 msrval;
 
  	local_irq_disable();
 
  	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
  	invalue = inl(POWERNOW_IOPORT + 0x8);
  	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
  	local_irq_enable();
 
@@ -101,8 +101,8 @@ static int powernow_k6_get_cpu_multiplier(void)
  static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
  {
  	unsigned long outvalue, invalue;
-	unsigned long msrval;
  	unsigned long cr0;
+	u64 msrval;
 
  	/* we now need to transform best_i to the BVC format, see AMD#23446 */
 
@@ -118,13 +118,13 @@ static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
  	outvalue = (1<<12) | (1<<10) | (1<<9) | (index_to_register[best_i]<<5);
 
  	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
  	invalue = inl(POWERNOW_IOPORT + 0x8);
  	invalue = invalue & 0x1f;
  	outvalue = outvalue | invalue;
  	outl(outvalue, (POWERNOW_IOPORT + 0x8));
  	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
  	write_cr0(cr0);
  	local_irq_enable();
drivers/cpufreq/powernow-k8.c +34 -33
index 2b791f1ec51b..fe1f499b4fc0 100644
@@ -87,10 +87,10 @@ static u32 convert_fid_to_vco_fid(u32 fid)
   */
  static int pending_bit_stuck(void)
  {
-	u32 lo, hi __always_unused;
+	u64 msr;
 
-	rdmsr(MSR_FIDVID_STATUS, lo, hi);
-	return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0;
+	rdmsrq(MSR_FIDVID_STATUS, msr);
+	return msr & MSR_S_LO_CHANGE_PENDING ? 1 : 0;
  }
 
  /*
@@ -99,7 +99,7 @@ static int pending_bit_stuck(void)
   */
  static int query_current_values_with_pending_wait(struct powernow_k8_data *data)
  {
-	u32 lo, hi;
+	struct msr msr;
  	u32 i = 0;
 
  	do {
@@ -107,11 +107,11 @@ static int query_current_values_with_pending_wait(struct powernow_k8_data *data)
  			pr_debug("detected change pending stuck\n");
  			return 1;
  		}
-		rdmsr(MSR_FIDVID_STATUS, lo, hi);
-	} while (lo & MSR_S_LO_CHANGE_PENDING);
+		rdmsrq(MSR_FIDVID_STATUS, msr.q);
+	} while (msr.l & MSR_S_LO_CHANGE_PENDING);
 
-	data->currvid = hi & MSR_S_HI_CURRENT_VID;
-	data->currfid = lo & MSR_S_LO_CURRENT_FID;
+	data->currvid = msr.h & MSR_S_HI_CURRENT_VID;
+	data->currfid = msr.l & MSR_S_LO_CURRENT_FID;
 
  	return 0;
  }
@@ -131,22 +131,22 @@ static void count_off_vst(struct powernow_k8_data *data)
  /* need to init the control msr to a safe value (for each cpu) */
  static void fidvid_msr_init(void)
  {
-	u32 lo, hi;
+	struct msr msr;
  	u8 fid, vid;
 
-	rdmsr(MSR_FIDVID_STATUS, lo, hi);
-	vid = hi & MSR_S_HI_CURRENT_VID;
-	fid = lo & MSR_S_LO_CURRENT_FID;
-	lo = fid | (vid << MSR_C_LO_VID_SHIFT);
-	hi = MSR_C_HI_STP_GNT_BENIGN;
-	pr_debug("cpu%d, init lo 0x%x, hi 0x%x\n", smp_processor_id(), lo, hi);
-	wrmsr(MSR_FIDVID_CTL, lo, hi);
+	rdmsrq(MSR_FIDVID_STATUS, msr.q);
+	vid = msr.h & MSR_S_HI_CURRENT_VID;
+	fid = msr.l & MSR_S_LO_CURRENT_FID;
+	msr.l = fid | (vid << MSR_C_LO_VID_SHIFT);
+	msr.h = MSR_C_HI_STP_GNT_BENIGN;
+	pr_debug("cpu%d, init lo 0x%x, hi 0x%x\n", smp_processor_id(), msr.l, msr.h);
+	wrmsrq(MSR_FIDVID_CTL, msr.q);
  }
 
  /* write the new fid value along with the other control fields to the msr */
  static int write_new_fid(struct powernow_k8_data *data, u32 fid)
  {
-	u32 lo;
+	struct msr msr;
  	u32 savevid = data->currvid;
  	u32 i = 0;
 
@@ -155,15 +155,15 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
  		return 1;
  	}
 
-	lo = fid;
-	lo |= (data->currvid << MSR_C_LO_VID_SHIFT);
-	lo |= MSR_C_LO_INIT_FID_VID;
+	msr.l = fid;
+	msr.l |= (data->currvid << MSR_C_LO_VID_SHIFT);
+	msr.l |= MSR_C_LO_INIT_FID_VID;
+	msr.h = data->plllock * PLL_LOCK_CONVERSION;
 
-	pr_debug("writing fid 0x%x, lo 0x%x, hi 0x%x\n",
-		fid, lo, data->plllock * PLL_LOCK_CONVERSION);
+	pr_debug("writing fid 0x%x, lo 0x%x, hi 0x%x\n", fid, msr.l, msr.h);
 
  	do {
-		wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION);
+		wrmsrq(MSR_FIDVID_CTL, msr.q);
  		if (i++ > 100) {
  			pr_err("Hardware error - pending bit very stuck - no further pstate changes possible\n");
  			return 1;
@@ -190,7 +190,7 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
  /* Write a new vid to the hardware */
  static int write_new_vid(struct powernow_k8_data *data, u32 vid)
  {
-	u32 lo;
+	struct msr msr;
  	u32 savefid = data->currfid;
  	int i = 0;
 
@@ -199,15 +199,15 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
  		return 1;
  	}
 
-	lo = data->currfid;
-	lo |= (vid << MSR_C_LO_VID_SHIFT);
-	lo |= MSR_C_LO_INIT_FID_VID;
+	msr.l = data->currfid;
+	msr.l |= (vid << MSR_C_LO_VID_SHIFT);
+	msr.l |= MSR_C_LO_INIT_FID_VID;
+	msr.h = STOP_GRANT_5NS;
 
-	pr_debug("writing vid 0x%x, lo 0x%x, hi 0x%x\n",
-		vid, lo, STOP_GRANT_5NS);
+	pr_debug("writing vid 0x%x, lo 0x%x, hi 0x%x\n", vid, msr.l, msr.h);
 
  	do {
-		wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
+		wrmsrq(MSR_FIDVID_CTL, msr.q);
  		if (i++ > 100) {
  			pr_err("internal error - pending bit very stuck - no further pstate changes possible\n");
  			return 1;
@@ -281,9 +281,10 @@ static int transition_fid_vid(struct powernow_k8_data *data,
  static int core_voltage_pre_transition(struct powernow_k8_data *data,
  		u32 reqvid, u32 reqfid)
  {
+	struct msr msr;
  	u32 rvosteps = data->rvo;
  	u32 savefid = data->currfid;
-	u32 maxvid, lo __always_unused, rvomult = 1;
+	u32 maxvid, rvomult = 1;
 
  	pr_debug("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, reqvid 0x%x, rvo 0x%x\n",
  		smp_processor_id(),
@@ -292,8 +293,8 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data,
  	if ((savefid < LO_FID_TABLE_TOP) && (reqfid < LO_FID_TABLE_TOP))
  		rvomult = 2;
  	rvosteps *= rvomult;
-	rdmsr(MSR_FIDVID_STATUS, lo, maxvid);
-	maxvid = 0x1f & (maxvid >> 16);
+	rdmsrq(MSR_FIDVID_STATUS, msr.q);
+	maxvid = 0x1f & (msr.h >> 16);
  	pr_debug("ph1 maxvid=0x%x\n", maxvid);
  	if (reqvid < maxvid) /* lower numbers are higher voltages */
  		reqvid = maxvid;
drivers/cpufreq/speedstep-centrino.c +8 -8
index 9237ed8f2b1f..de50fb367c6b 100644
@@ -345,7 +345,7 @@ static unsigned int get_cur_freq(unsigned int cpu)
  static int centrino_cpu_init(struct cpufreq_policy *policy)
  {
  	struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu);
-	unsigned l, h;
+	u64 q;
  	int i;
 
  	/* Only Intel makes Enhanced Speedstep-capable CPUs */
@@ -378,16 +378,16 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
 
  	/* Check to see if Enhanced SpeedStep is enabled, and try to
  	   enable it if not. */
-	rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+	rdmsrq(MSR_IA32_MISC_ENABLE, q);
 
-	if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
-		l |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
-		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", l);
-		wrmsr(MSR_IA32_MISC_ENABLE, l, h);
+	if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		q |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
+		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", (u32)q);
+		wrmsrq(MSR_IA32_MISC_ENABLE, q);
 
  		/* check to see if it stuck */
-		rdmsr(MSR_IA32_MISC_ENABLE, l, h);
-		if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		rdmsrq(MSR_IA32_MISC_ENABLE, q);
+		if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
  			pr_info("couldn't enable Enhanced SpeedStep\n");
  			return -ENODEV;
  		}
drivers/cpufreq/speedstep-lib.c +34 -29
index 973716c1c29c..2afc3f177a29 100644
@@ -69,13 +69,14 @@ static unsigned int pentium3_get_frequency(enum speedstep_processor processor)
  		{   0, 0xff}
  	};
 
+	struct msr msr;
  	u32 msr_lo, msr_tmp;
  	int i = 0, j = 0;
 
  	/* read MSR 0x2a - we only need the low 32 bits */
-	rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp);
-	pr_debug("P3 - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp);
-	msr_tmp = msr_lo;
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, msr.q);
+	pr_debug("P3 - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr.l, msr.h);
+	msr_tmp = msr_lo = msr.l;
 
  	/* decode the FSB */
  	msr_tmp &= 0x00c0000;
@@ -108,19 +109,20 @@ static unsigned int pentium3_get_frequency(enum speedstep_processor processor)
 
  static unsigned int pentiumM_get_frequency(void)
  {
-	u32 msr_lo, msr_tmp;
+	struct msr msr;
+	u32 msr_tmp;
 
-	rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp);
-	pr_debug("PM - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp);
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, msr.q);
+	pr_debug("PM - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr.l, msr.h);
 
  	/* see table B-2 of 24547212.pdf */
-	if (msr_lo & 0x00040000) {
+	if (msr.l & 0x00040000) {
  		printk(KERN_DEBUG PFX "PM - invalid FSB: 0x%x 0x%x\n",
-				msr_lo, msr_tmp);
+				msr.l, msr.h);
  		return 0;
  	}
 
-	msr_tmp = (msr_lo >> 22) & 0x1f;
+	msr_tmp = (msr.l >> 22) & 0x1f;
  	pr_debug("bits 22-26 are 0x%x, speed is %u\n",
  			msr_tmp, (msr_tmp * 100 * 1000));
 
@@ -129,13 +131,14 @@ static unsigned int pentiumM_get_frequency(void)
 
  static unsigned int pentium_core_get_frequency(void)
  {
+	struct msr msr;
  	u32 fsb = 0;
-	u32 msr_lo, msr_tmp;
+	u32 msr_tmp;
  	int ret;
 
-	rdmsr(MSR_FSB_FREQ, msr_lo, msr_tmp);
+	rdmsrq(MSR_FSB_FREQ, msr.q);
  	/* see table B-2 of 25366920.pdf */
-	switch (msr_lo & 0x07) {
+	switch (msr.l & 0x07) {
  	case 5:
  		fsb = 100000;
  		break;
@@ -158,11 +161,11 @@ static unsigned int pentium_core_get_frequency(void)
  		pr_err("PCORE - MSR_FSB_FREQ undefined value\n");
  	}
 
-	rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp);
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, msr.q);
  	pr_debug("PCORE - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n",
-			msr_lo, msr_tmp);
+			msr.l, msr.h);
 
-	msr_tmp = (msr_lo >> 22) & 0x1f;
+	msr_tmp = (msr.l >> 22) & 0x1f;
  	pr_debug("bits 22-26 are 0x%x, speed is %u\n",
  			msr_tmp, (msr_tmp * fsb));
 
@@ -174,7 +177,8 @@ static unsigned int pentium_core_get_frequency(void)
  static unsigned int pentium4_get_frequency(void)
  {
  	struct cpuinfo_x86 *c = &boot_cpu_data;
-	u32 msr_lo, msr_hi, mult;
+	struct msr msr;
+	u32 mult;
  	unsigned int fsb = 0;
  	unsigned int ret;
  	u8 fsb_code;
@@ -187,16 +191,16 @@ static unsigned int pentium4_get_frequency(void)
  	if (c->x86_model < 2)
  		return cpu_khz;
 
-	rdmsr(0x2c, msr_lo, msr_hi);
+	rdmsrq(0x2c, msr.q);
 
-	pr_debug("P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr_lo, msr_hi);
+	pr_debug("P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr.l, msr.h);
 
  	/* decode the FSB: see IA-32 Intel (C) Architecture Software
  	 * Developer's Manual, Volume 3: System Prgramming Guide,
  	 * revision #12 in Table B-1: MSRs in the Pentium 4 and
  	 * Intel Xeon Processors, on page B-4 and B-5.
  	 */
-	fsb_code = (msr_lo >> 16) & 0x7;
+	fsb_code = (msr.l >> 16) & 0x7;
  	switch (fsb_code) {
  	case 0:
  		fsb = 100 * 1000;
@@ -214,7 +218,7 @@ static unsigned int pentium4_get_frequency(void)
  				"Please send an e-mail to <[email protected]>\n");
 
  	/* Multiplier. */
-	mult = msr_lo >> 24;
+	mult = msr.l >> 24;
 
  	pr_debug("P4 - FSB %u kHz; Multiplier %u; Speed %u kHz\n",
  			fsb, mult, (fsb * mult));
@@ -255,7 +259,8 @@ EXPORT_SYMBOL_GPL(speedstep_get_frequency);
  enum speedstep_processor speedstep_detect_processor(void)
  {
  	struct cpuinfo_x86 *c = &cpu_data(0);
-	u32 ebx, msr_lo, msr_hi;
+	struct msr msr;
+	u32 ebx;
 
  	pr_debug("x86: %x, model: %x\n", c->x86, c->x86_model);
 
@@ -343,11 +348,11 @@ enum speedstep_processor speedstep_detect_processor(void)
 
  		/* all mobile PIII Coppermines have FSB 100 MHz
  		 * ==> sort out a few desktop PIIIs. */
-		rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_hi);
+		rdmsrq(MSR_IA32_EBL_CR_POWERON, msr.q);
  		pr_debug("Coppermine: MSR_IA32_EBL_CR_POWERON is 0x%x, 0x%x\n",
-				msr_lo, msr_hi);
-		msr_lo &= 0x00c0000;
-		if (msr_lo != 0x0080000)
+				msr.l, msr.h);
+		msr.l &= 0x00c0000;
+		if (msr.l != 0x0080000)
  			return 0;
 
  		/*
@@ -356,11 +361,11 @@ enum speedstep_processor speedstep_detect_processor(void)
  		 * it has SpeedStep technology if either
  		 * bit 56 or 57 is set
  		 */
-		rdmsr(MSR_IA32_PLATFORM_ID, msr_lo, msr_hi);
+		rdmsrq(MSR_IA32_PLATFORM_ID, msr.q);
  		pr_debug("Coppermine: MSR_IA32_PLATFORM ID is 0x%x, 0x%x\n",
-				msr_lo, msr_hi);
-		if ((msr_hi & (1<<18)) &&
-		    (relaxed_check ? 1 : (msr_hi & (3<<24)))) {
+				msr.l, msr.h);
+		if ((msr.h & (1<<18)) &&
+		    (relaxed_check ? 1 : (msr.h & (3<<24)))) {
  			if (c->x86_stepping == 0x01) {
  				pr_debug("early PIII version\n");
  				return SPEEDSTEP_CPU_PIII_C_EARLY;
Signature · 2 lines
Thx and BRs,
Zhongqiu Han
merge bot Applied
#67 lore raw

[tip: x86/msr] cpufreq: Stop using 32-bit MSR interfaces

In reply to Juergen Gross
The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     e8caa0abfbf0283874582e8160cef5fca845ffb8
Gitweb:        https://git.kernel.org/tip/e8caa0abfbf0283874582e8160cef5fca845ffb8
Author:        Juergen Gross <[email protected]>
AuthorDate:    Fri, 03 Jul 2026 13:24:45 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 17 Jul 2026 11:31:25 +02:00

cpufreq: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/cpufreq/acpi-cpufreq.c       | 22 ++++----
 drivers/cpufreq/e_powersaver.c       | 49 ++++++++---------
 drivers/cpufreq/longhaul.c           | 15 ++---
 drivers/cpufreq/longrun.c            | 77 +++++++++++++--------------
 drivers/cpufreq/powernow-k6.c        | 12 ++--
 drivers/cpufreq/powernow-k8.c        | 67 +++++++++++------------
 drivers/cpufreq/speedstep-centrino.c | 16 +++---
 drivers/cpufreq/speedstep-lib.c      | 63 +++++++++++-----------
 8 files changed, 164 insertions(+), 157 deletions(-)
drivers/cpufreq/acpi-cpufreq.c +11 -11
index 21639d9..10ea603 100644
@@ -246,32 +246,32 @@ static unsigned extract_freq(struct cpufreq_policy *policy, u32 val)
 
 static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)
 {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_IA32_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_IA32_PERF_CTL, val);
+	return (u32)val;
 }
 
 static void cpu_freq_write_intel(struct acpi_pct_register *not_used, u32 val)
 {
-	u32 lo, hi;
+	u64 msrval;
 
-	rdmsr(MSR_IA32_PERF_CTL, lo, hi);
-	lo = (lo & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
-	wrmsr(MSR_IA32_PERF_CTL, lo, hi);
+	rdmsrq(MSR_IA32_PERF_CTL, msrval);
+	msrval = (msrval & ~(u64)INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
+	wrmsrq(MSR_IA32_PERF_CTL, msrval);
 }
 
 static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)
 {
-	u32 val, dummy __always_unused;
+	u64 val;
 
-	rdmsr(MSR_AMD_PERF_CTL, val, dummy);
-	return val;
+	rdmsrq(MSR_AMD_PERF_CTL, val);
+	return (u32)val;
 }
 
 static void cpu_freq_write_amd(struct acpi_pct_register *not_used, u32 val)
 {
-	wrmsr(MSR_AMD_PERF_CTL, val, 0);
+	wrmsrq(MSR_AMD_PERF_CTL, val);
 }
 
 static u32 cpu_freq_read_io(struct acpi_pct_register *reg)
drivers/cpufreq/e_powersaver.c +24 -25

121 lines not on this page · raw message

drivers/cpufreq/longhaul.c +8 -7
index a18d1d1..4c25992 100644
@@ -118,13 +118,14 @@ static unsigned int calc_speed(int mult)
 
 static int longhaul_get_cpu_mult(void)
 {
-	unsigned long invalue = 0, lo, hi;
+	unsigned long invalue = 0;
+	u64 val;
 
-	rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi);
-	invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22;
+	rdmsrq(MSR_IA32_EBL_CR_POWERON, val);
+	invalue = (val & (1<<22|1<<23|1<<24|1<<25))>>22;
 	if (longhaul_version == TYPE_LONGHAUL_V2 ||
 	    longhaul_version == TYPE_POWERSAVER) {
-		if (lo & (1<<27))
+		if (val & (1<<27))
 			invalue += 16;
 	}
 	return eblcr[invalue];
@@ -761,7 +762,7 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
 	struct cpuinfo_x86 *c = &cpu_data(0);
 	char *cpuname = NULL;
 	int ret;
-	u32 lo, hi;
+	u64 val;
 
 	/* Check what we have on this motherboard */
 	switch (c->x86_model) {
@@ -835,8 +836,8 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
 	}
 	/* Check Longhaul ver. 2 */
 	if (longhaul_version == TYPE_LONGHAUL_V2) {
-		rdmsr(MSR_VIA_LONGHAUL, lo, hi);
-		if (lo == 0 && hi == 0)
+		rdmsrq(MSR_VIA_LONGHAUL, val);
+		if (val == 0)
 			/* Looks like MSR isn't present */
 			longhaul_version = TYPE_LONGHAUL_V1;
 	}
drivers/cpufreq/longrun.c +39 -38

145 lines not on this page · raw message

drivers/cpufreq/powernow-k6.c +6 -6
index 99d2244..2044e8a 100644
@@ -83,15 +83,15 @@ static const struct {
 static int powernow_k6_get_cpu_multiplier(void)
 {
 	unsigned long invalue = 0;
-	u32 msrval;
+	u64 msrval;
 
 	local_irq_disable();
 
 	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
 	invalue = inl(POWERNOW_IOPORT + 0x8);
 	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
 	local_irq_enable();
 
@@ -101,8 +101,8 @@ static int powernow_k6_get_cpu_multiplier(void)
 static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
 {
 	unsigned long outvalue, invalue;
-	unsigned long msrval;
 	unsigned long cr0;
+	u64 msrval;
 
 	/* we now need to transform best_i to the BVC format, see AMD#23446 */
 
@@ -118,13 +118,13 @@ static void powernow_k6_set_cpu_multiplier(unsigned int best_i)
 	outvalue = (1<<12) | (1<<10) | (1<<9) | (index_to_register[best_i]<<5);
 
 	msrval = POWERNOW_IOPORT + 0x1;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
+	wrmsrq(MSR_K6_EPMR, msrval); /* enable the PowerNow port */
 	invalue = inl(POWERNOW_IOPORT + 0x8);
 	invalue = invalue & 0x1f;
 	outvalue = outvalue | invalue;
 	outl(outvalue, (POWERNOW_IOPORT + 0x8));
 	msrval = POWERNOW_IOPORT + 0x0;
-	wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */
+	wrmsrq(MSR_K6_EPMR, msrval); /* disable it again */
 
 	write_cr0(cr0);
 	local_irq_enable();
drivers/cpufreq/powernow-k8.c +34 -33

138 lines not on this page · raw message

drivers/cpufreq/speedstep-centrino.c +8 -8
index 9237ed8..de50fb3 100644
@@ -345,7 +345,7 @@ static unsigned int get_cur_freq(unsigned int cpu)
 static int centrino_cpu_init(struct cpufreq_policy *policy)
 {
 	struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu);
-	unsigned l, h;
+	u64 q;
 	int i;
 
 	/* Only Intel makes Enhanced Speedstep-capable CPUs */
@@ -378,16 +378,16 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
 
 	/* Check to see if Enhanced SpeedStep is enabled, and try to
 	   enable it if not. */
-	rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+	rdmsrq(MSR_IA32_MISC_ENABLE, q);
 
-	if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
-		l |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
-		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", l);
-		wrmsr(MSR_IA32_MISC_ENABLE, l, h);
+	if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		q |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP;
+		pr_debug("trying to enable Enhanced SpeedStep (%x)\n", (u32)q);
+		wrmsrq(MSR_IA32_MISC_ENABLE, q);
 
 		/* check to see if it stuck */
-		rdmsr(MSR_IA32_MISC_ENABLE, l, h);
-		if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
+		rdmsrq(MSR_IA32_MISC_ENABLE, q);
+		if (!(q & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
 			pr_info("couldn't enable Enhanced SpeedStep\n");
 			return -ENODEV;
 		}
drivers/cpufreq/speedstep-lib.c +34 -29

149 lines not on this page · raw message

author maintainer
#68 lore raw

PATCH 17/32 x86/resctrl: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/include/asm/resctrl.h            |  5 ++++-
 arch/x86/kernel/cpu/resctrl/core.c        |  7 ++++--
 arch/x86/kernel/cpu/resctrl/monitor.c     | 27 +++++++++++++----------
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 12 +++++-----
 4 files changed, 30 insertions(+), 21 deletions(-)
arch/x86/include/asm/resctrl.h +4 -1
index 575f8408a9e7..8f6edcdcfd87 100644
@@ -102,6 +102,7 @@ static inline void __resctrl_sched_in(struct task_struct *tsk)
 	struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state);
 	u32 closid = READ_ONCE(state->default_closid);
 	u32 rmid = READ_ONCE(state->default_rmid);
+	struct msr val;
 	u32 tmp;
 
 	/*
@@ -123,7 +124,9 @@ static inline void __resctrl_sched_in(struct task_struct *tsk)
 	if (closid != state->cur_closid || rmid != state->cur_rmid) {
 		state->cur_closid = closid;
 		state->cur_rmid = rmid;
-		wrmsr(MSR_IA32_PQR_ASSOC, rmid, closid);
+		val.l = rmid;
+		val.h = closid;
+		wrmsrq(MSR_IA32_PQR_ASSOC, val.q);
 	}
 }
 
arch/x86/kernel/cpu/resctrl/core.c +5 -2
index 9c01d2562b7a..f452e8ce4cef 100644
@@ -725,13 +725,16 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
 static void clear_closid_rmid(int cpu)
 {
 	struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state);
+	struct msr val = {
+		.l = RESCTRL_RESERVED_RMID,
+		.h = RESCTRL_RESERVED_CLOSID
+	};
 
 	state->default_closid = RESCTRL_RESERVED_CLOSID;
 	state->default_rmid = RESCTRL_RESERVED_RMID;
 	state->cur_closid = RESCTRL_RESERVED_CLOSID;
 	state->cur_rmid = RESCTRL_RESERVED_RMID;
-	wrmsr(MSR_IA32_PQR_ASSOC, RESCTRL_RESERVED_RMID,
-	      RESCTRL_RESERVED_CLOSID);
+	wrmsrq(MSR_IA32_PQR_ASSOC, val.q);
 }
 
 static int resctrl_arch_online_cpu(unsigned int cpu)
arch/x86/kernel/cpu/resctrl/monitor.c +15 -12
index 03ee6102ab07..153dc5a268a4 100644
@@ -136,7 +136,7 @@ static int logical_rmid_to_physical_rmid(int cpu, int lrmid)
 
 static int __rmid_read_phys(u32 prmid, enum resctrl_event_id eventid, u64 *val)
 {
-	u64 msr_val;
+	struct msr msr_val = { .l = eventid, .h = prmid };
 
 	/*
 	 * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured
@@ -146,15 +146,15 @@ static int __rmid_read_phys(u32 prmid, enum resctrl_event_id eventid, u64 *val)
 	 * IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62)
 	 * are error bits.
 	 */
-	wrmsr(MSR_IA32_QM_EVTSEL, eventid, prmid);
-	rdmsrq(MSR_IA32_QM_CTR, msr_val);
+	wrmsrq(MSR_IA32_QM_EVTSEL, msr_val.q);
+	rdmsrq(MSR_IA32_QM_CTR, msr_val.q);
 
-	if (msr_val & RMID_VAL_ERROR)
+	if (msr_val.q & RMID_VAL_ERROR)
 		return -EIO;
-	if (msr_val & RMID_VAL_UNAVAIL)
+	if (msr_val.q & RMID_VAL_UNAVAIL)
 		return -EINVAL;
 
-	*val = msr_val;
+	*val = msr_val.q;
 	return 0;
 }
 
@@ -278,7 +278,10 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
 
 static int __cntr_id_read(u32 cntr_id, u64 *val)
 {
-	u64 msr_val;
+	struct msr msr_val = {
+		.l = ABMC_EXTENDED_EVT_ID | ABMC_EVT_ID,
+		.h = cntr_id
+	};
 
 	/*
 	 * QM_EVTSEL Register definition:
@@ -301,15 +304,15 @@ static int __cntr_id_read(u32 cntr_id, u64 *val)
 	 * ID is set in the QM_EVTSEL.RMID field.  The RMID_VAL_UNAVAIL bit
 	 * is set if the counter data is unavailable.
 	 */
-	wrmsr(MSR_IA32_QM_EVTSEL, ABMC_EXTENDED_EVT_ID | ABMC_EVT_ID, cntr_id);
-	rdmsrq(MSR_IA32_QM_CTR, msr_val);
+	wrmsrq(MSR_IA32_QM_EVTSEL, msr_val.q);
+	rdmsrq(MSR_IA32_QM_CTR, msr_val.q);
 
-	if (msr_val & RMID_VAL_ERROR)
+	if (msr_val.q & RMID_VAL_ERROR)
 		return -EIO;
-	if (msr_val & RMID_VAL_UNAVAIL)
+	if (msr_val.q & RMID_VAL_UNAVAIL)
 		return -EINVAL;
 
-	*val = msr_val;
+	*val = msr_val.q;
 	return 0;
 }
 
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +6 -6
index de580eca3363..d7caab0409b6 100644
@@ -241,16 +241,16 @@ int resctrl_arch_pseudo_lock_fn(void *_plr)
 int resctrl_arch_measure_cycles_lat_fn(void *_plr)
 {
 	struct pseudo_lock_region *plr = _plr;
-	u32 saved_low, saved_high;
 	unsigned long i;
 	u64 start, end;
 	void *mem_r;
+	u64 saved;
 
 	local_irq_disable();
 	/*
 	 * Disable hardware prefetchers.
 	 */
-	rdmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
+	rdmsrq(MSR_MISC_FEATURE_CONTROL, saved);
 	wrmsrq(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits);
 	mem_r = READ_ONCE(plr->kmem);
 	/*
@@ -267,7 +267,7 @@ int resctrl_arch_measure_cycles_lat_fn(void *_plr)
 		end = rdtsc_ordered();
 		trace_pseudo_lock_mem_latency((u32)(end - start));
 	}
-	wrmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
+	wrmsrq(MSR_MISC_FEATURE_CONTROL, saved);
 	local_irq_enable();
 	plr->thread_done = 1;
 	wake_up_interruptible(&plr->lock_thread_wq);
@@ -312,11 +312,11 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
 	u64 hits_before = 0, hits_after = 0, miss_before = 0, miss_after = 0;
 	struct perf_event *miss_event, *hit_event;
 	int hit_pmcnum, miss_pmcnum;
-	u32 saved_low, saved_high;
 	unsigned int line_size;
 	unsigned int size;
 	unsigned long i;
 	void *mem_r;
+	u64 saved;
 	u64 tmp;
 
 	miss_event = perf_event_create_kernel_counter(miss_attr, plr->cpu,
@@ -346,7 +346,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
 	/*
 	 * Disable hardware prefetchers.
 	 */
-	rdmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
+	rdmsrq(MSR_MISC_FEATURE_CONTROL, saved);
 	wrmsrq(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits);
 
 	/* Initialize rest of local variables */
@@ -405,7 +405,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
 	 */
 	rmb();
 	/* Re-enable hardware prefetchers */
-	wrmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
+	wrmsrq(MSR_MISC_FEATURE_CONTROL, saved);
 	local_irq_enable();
 out_hit:
 	perf_event_release_kernel(hit_event);
Signature · 1 line
2.54.0
merge bot Applied
#70 lore raw

[tip: x86/msr] x86/resctrl: Stop using 32-bit MSR interfaces

In reply to Juergen Gross
The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     4967c466ca3860fcc3ae70fee286f220020774fe
Gitweb:        https://git.kernel.org/tip/4967c466ca3860fcc3ae70fee286f220020774fe
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:08 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:52 +02:00

x86/resctrl: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/include/asm/resctrl.h            |  5 +++-
 arch/x86/kernel/cpu/resctrl/core.c        |  7 ++++--
 arch/x86/kernel/cpu/resctrl/monitor.c     | 27 ++++++++++++----------
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 12 +++++-----
 4 files changed, 30 insertions(+), 21 deletions(-)
arch/x86/include/asm/resctrl.h +4 -1
index 575f840..8f6edcd 100644
@@ -102,6 +102,7 @@ static inline void __resctrl_sched_in(struct task_struct *tsk)
 	struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state);
 	u32 closid = READ_ONCE(state->default_closid);
 	u32 rmid = READ_ONCE(state->default_rmid);
+	struct msr val;
 	u32 tmp;
 
 	/*
@@ -123,7 +124,9 @@ static inline void __resctrl_sched_in(struct task_struct *tsk)
 	if (closid != state->cur_closid || rmid != state->cur_rmid) {
 		state->cur_closid = closid;
 		state->cur_rmid = rmid;
-		wrmsr(MSR_IA32_PQR_ASSOC, rmid, closid);
+		val.l = rmid;
+		val.h = closid;
+		wrmsrq(MSR_IA32_PQR_ASSOC, val.q);
 	}
 }
 
arch/x86/kernel/cpu/resctrl/core.c +5 -2
index 9c01d25..f452e8c 100644
@@ -725,13 +725,16 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
 static void clear_closid_rmid(int cpu)
 {
 	struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state);
+	struct msr val = {
+		.l = RESCTRL_RESERVED_RMID,
+		.h = RESCTRL_RESERVED_CLOSID
+	};
 
 	state->default_closid = RESCTRL_RESERVED_CLOSID;
 	state->default_rmid = RESCTRL_RESERVED_RMID;
 	state->cur_closid = RESCTRL_RESERVED_CLOSID;
 	state->cur_rmid = RESCTRL_RESERVED_RMID;
-	wrmsr(MSR_IA32_PQR_ASSOC, RESCTRL_RESERVED_RMID,
-	      RESCTRL_RESERVED_CLOSID);
+	wrmsrq(MSR_IA32_PQR_ASSOC, val.q);
 }
 
 static int resctrl_arch_online_cpu(unsigned int cpu)
arch/x86/kernel/cpu/resctrl/monitor.c +15 -12
index 03ee610..153dc5a 100644
@@ -136,7 +136,7 @@ static int logical_rmid_to_physical_rmid(int cpu, int lrmid)
 
 static int __rmid_read_phys(u32 prmid, enum resctrl_event_id eventid, u64 *val)
 {
-	u64 msr_val;
+	struct msr msr_val = { .l = eventid, .h = prmid };
 
 	/*
 	 * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured
@@ -146,15 +146,15 @@ static int __rmid_read_phys(u32 prmid, enum resctrl_event_id eventid, u64 *val)
 	 * IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62)
 	 * are error bits.
 	 */
-	wrmsr(MSR_IA32_QM_EVTSEL, eventid, prmid);
-	rdmsrq(MSR_IA32_QM_CTR, msr_val);
+	wrmsrq(MSR_IA32_QM_EVTSEL, msr_val.q);
+	rdmsrq(MSR_IA32_QM_CTR, msr_val.q);
 
-	if (msr_val & RMID_VAL_ERROR)
+	if (msr_val.q & RMID_VAL_ERROR)
 		return -EIO;
-	if (msr_val & RMID_VAL_UNAVAIL)
+	if (msr_val.q & RMID_VAL_UNAVAIL)
 		return -EINVAL;
 
-	*val = msr_val;
+	*val = msr_val.q;
 	return 0;
 }
 
@@ -278,7 +278,10 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *hdr,
 
 static int __cntr_id_read(u32 cntr_id, u64 *val)
 {
-	u64 msr_val;
+	struct msr msr_val = {
+		.l = ABMC_EXTENDED_EVT_ID | ABMC_EVT_ID,
+		.h = cntr_id
+	};
 
 	/*
 	 * QM_EVTSEL Register definition:
@@ -301,15 +304,15 @@ static int __cntr_id_read(u32 cntr_id, u64 *val)
 	 * ID is set in the QM_EVTSEL.RMID field.  The RMID_VAL_UNAVAIL bit
 	 * is set if the counter data is unavailable.
 	 */
-	wrmsr(MSR_IA32_QM_EVTSEL, ABMC_EXTENDED_EVT_ID | ABMC_EVT_ID, cntr_id);
-	rdmsrq(MSR_IA32_QM_CTR, msr_val);
+	wrmsrq(MSR_IA32_QM_EVTSEL, msr_val.q);
+	rdmsrq(MSR_IA32_QM_CTR, msr_val.q);
 
-	if (msr_val & RMID_VAL_ERROR)
+	if (msr_val.q & RMID_VAL_ERROR)
 		return -EIO;
-	if (msr_val & RMID_VAL_UNAVAIL)
+	if (msr_val.q & RMID_VAL_UNAVAIL)
 		return -EINVAL;
 
-	*val = msr_val;
+	*val = msr_val.q;
 	return 0;
 }
 
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +6 -6
index de580ec..d7caab0 100644
@@ -241,16 +241,16 @@ int resctrl_arch_pseudo_lock_fn(void *_plr)
 int resctrl_arch_measure_cycles_lat_fn(void *_plr)
 {
 	struct pseudo_lock_region *plr = _plr;
-	u32 saved_low, saved_high;
 	unsigned long i;
 	u64 start, end;
 	void *mem_r;
+	u64 saved;
 
 	local_irq_disable();
 	/*
 	 * Disable hardware prefetchers.
 	 */
-	rdmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
+	rdmsrq(MSR_MISC_FEATURE_CONTROL, saved);
 	wrmsrq(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits);
 	mem_r = READ_ONCE(plr->kmem);
 	/*
@@ -267,7 +267,7 @@ int resctrl_arch_measure_cycles_lat_fn(void *_plr)
 		end = rdtsc_ordered();
 		trace_pseudo_lock_mem_latency((u32)(end - start));
 	}
-	wrmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
+	wrmsrq(MSR_MISC_FEATURE_CONTROL, saved);
 	local_irq_enable();
 	plr->thread_done = 1;
 	wake_up_interruptible(&plr->lock_thread_wq);
@@ -312,11 +312,11 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
 	u64 hits_before = 0, hits_after = 0, miss_before = 0, miss_after = 0;
 	struct perf_event *miss_event, *hit_event;
 	int hit_pmcnum, miss_pmcnum;
-	u32 saved_low, saved_high;
 	unsigned int line_size;
 	unsigned int size;
 	unsigned long i;
 	void *mem_r;
+	u64 saved;
 	u64 tmp;
 
 	miss_event = perf_event_create_kernel_counter(miss_attr, plr->cpu,
@@ -346,7 +346,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
 	/*
 	 * Disable hardware prefetchers.
 	 */
-	rdmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
+	rdmsrq(MSR_MISC_FEATURE_CONTROL, saved);
 	wrmsrq(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits);
 
 	/* Initialize rest of local variables */
@@ -405,7 +405,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
 	 */
 	rmb();
 	/* Re-enable hardware prefetchers */
-	wrmsr(MSR_MISC_FEATURE_CONTROL, saved_low, saved_high);
+	wrmsrq(MSR_MISC_FEATURE_CONTROL, saved);
 	local_irq_enable();
 out_hit:
 	perf_event_release_kernel(hit_event);
author maintainer
#71 lore raw

PATCH 18/32 x86/apic: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/apic/apic.c | 39 +++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
arch/x86/kernel/apic/apic.c +20 -19
index aa1e19979aa8..90025451ace2 100644
@@ -1191,11 +1191,11 @@ void disable_local_APIC(void)
 	 * restore the disabled state.
 	 */
 	if (enabled_via_apicbase) {
-		unsigned int l, h;
+		struct msr val;
 
-		rdmsr(MSR_IA32_APICBASE, l, h);
-		l &= ~MSR_IA32_APICBASE_ENABLE;
-		wrmsr(MSR_IA32_APICBASE, l, h);
+		rdmsrq(MSR_IA32_APICBASE, val.q);
+		val.l &= ~MSR_IA32_APICBASE_ENABLE;
+		wrmsrq(MSR_IA32_APICBASE, val.q);
 	}
 #endif
 }
@@ -1960,7 +1960,8 @@ static bool __init detect_init_APIC(void)
 
 static bool __init apic_verify(unsigned long addr)
 {
-	u32 features, h, l;
+	struct msr val;
+	u32 features;
 
 	/*
 	 * The APIC feature bit should now be enabled
@@ -1975,9 +1976,9 @@ static bool __init apic_verify(unsigned long addr)
 
 	/* The BIOS may have set up the APIC at some other address */
 	if (boot_cpu_data.x86 >= 6) {
-		rdmsr(MSR_IA32_APICBASE, l, h);
-		if (l & MSR_IA32_APICBASE_ENABLE)
-			addr = l & MSR_IA32_APICBASE_BASE;
+		rdmsrq(MSR_IA32_APICBASE, val.q);
+		if (val.l & MSR_IA32_APICBASE_ENABLE)
+			addr = val.l & MSR_IA32_APICBASE_BASE;
 	}
 
 	register_lapic_address(addr);
@@ -1987,7 +1988,7 @@ static bool __init apic_verify(unsigned long addr)
 
 bool __init apic_force_enable(unsigned long addr)
 {
-	u32 h, l;
+	struct msr val;
 
 	if (apic_is_disabled)
 		return false;
@@ -1998,12 +1999,12 @@ bool __init apic_force_enable(unsigned long addr)
 	 * and AMD K7 (Model > 1) or later.
 	 */
 	if (boot_cpu_data.x86 >= 6) {
-		rdmsr(MSR_IA32_APICBASE, l, h);
-		if (!(l & MSR_IA32_APICBASE_ENABLE)) {
+		rdmsrq(MSR_IA32_APICBASE, val.q);
+		if (!(val.l & MSR_IA32_APICBASE_ENABLE)) {
 			pr_info("Local APIC disabled by BIOS -- reenabling.\n");
-			l &= ~MSR_IA32_APICBASE_BASE;
-			l |= MSR_IA32_APICBASE_ENABLE | addr;
-			wrmsr(MSR_IA32_APICBASE, l, h);
+			val.l &= ~MSR_IA32_APICBASE_BASE;
+			val.l |= MSR_IA32_APICBASE_ENABLE | addr;
+			wrmsrq(MSR_IA32_APICBASE, val.q);
 			enabled_via_apicbase = 1;
 		}
 	}
@@ -2442,7 +2443,7 @@ static int lapic_suspend(void *data)
 
 static void lapic_resume(void *data)
 {
-	unsigned int l, h;
+	struct msr val;
 	unsigned long flags;
 	int maxlvt;
 
@@ -2475,10 +2476,10 @@ static void lapic_resume(void *data)
 		 * SMP! We'll need to do this as part of the CPU restore!
 		 */
 		if (boot_cpu_data.x86 >= 6) {
-			rdmsr(MSR_IA32_APICBASE, l, h);
-			l &= ~MSR_IA32_APICBASE_BASE;
-			l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
-			wrmsr(MSR_IA32_APICBASE, l, h);
+			rdmsrq(MSR_IA32_APICBASE, val.q);
+			val.l &= ~MSR_IA32_APICBASE_BASE;
+			val.l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
+			wrmsrq(MSR_IA32_APICBASE, val.q);
 		}
 	}
 
Signature · 1 line
2.54.0
merge bot Applied
#72 lore raw

[tip: x86/msr] x86/apic: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     7920900e53dd9cff1f95a8edfeac3f7c24a1b723
Gitweb:        https://git.kernel.org/tip/7920900e53dd9cff1f95a8edfeac3f7c24a1b723
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:09 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:52 +02:00

x86/apic: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/apic/apic.c | 39 ++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
arch/x86/kernel/apic/apic.c +20 -19
index aa1e199..9002545 100644
@@ -1191,11 +1191,11 @@ void disable_local_APIC(void)
 	 * restore the disabled state.
 	 */
 	if (enabled_via_apicbase) {
-		unsigned int l, h;
+		struct msr val;
 
-		rdmsr(MSR_IA32_APICBASE, l, h);
-		l &= ~MSR_IA32_APICBASE_ENABLE;
-		wrmsr(MSR_IA32_APICBASE, l, h);
+		rdmsrq(MSR_IA32_APICBASE, val.q);
+		val.l &= ~MSR_IA32_APICBASE_ENABLE;
+		wrmsrq(MSR_IA32_APICBASE, val.q);
 	}
 #endif
 }
@@ -1960,7 +1960,8 @@ static bool __init detect_init_APIC(void)
 
 static bool __init apic_verify(unsigned long addr)
 {
-	u32 features, h, l;
+	struct msr val;
+	u32 features;
 
 	/*
 	 * The APIC feature bit should now be enabled
@@ -1975,9 +1976,9 @@ static bool __init apic_verify(unsigned long addr)
 
 	/* The BIOS may have set up the APIC at some other address */
 	if (boot_cpu_data.x86 >= 6) {
-		rdmsr(MSR_IA32_APICBASE, l, h);
-		if (l & MSR_IA32_APICBASE_ENABLE)
-			addr = l & MSR_IA32_APICBASE_BASE;
+		rdmsrq(MSR_IA32_APICBASE, val.q);
+		if (val.l & MSR_IA32_APICBASE_ENABLE)
+			addr = val.l & MSR_IA32_APICBASE_BASE;
 	}
 
 	register_lapic_address(addr);
@@ -1987,7 +1988,7 @@ static bool __init apic_verify(unsigned long addr)
 
 bool __init apic_force_enable(unsigned long addr)
 {
-	u32 h, l;
+	struct msr val;
 
 	if (apic_is_disabled)
 		return false;
@@ -1998,12 +1999,12 @@ bool __init apic_force_enable(unsigned long addr)
 	 * and AMD K7 (Model > 1) or later.
 	 */
 	if (boot_cpu_data.x86 >= 6) {
-		rdmsr(MSR_IA32_APICBASE, l, h);
-		if (!(l & MSR_IA32_APICBASE_ENABLE)) {
+		rdmsrq(MSR_IA32_APICBASE, val.q);
+		if (!(val.l & MSR_IA32_APICBASE_ENABLE)) {
 			pr_info("Local APIC disabled by BIOS -- reenabling.\n");
-			l &= ~MSR_IA32_APICBASE_BASE;
-			l |= MSR_IA32_APICBASE_ENABLE | addr;
-			wrmsr(MSR_IA32_APICBASE, l, h);
+			val.l &= ~MSR_IA32_APICBASE_BASE;
+			val.l |= MSR_IA32_APICBASE_ENABLE | addr;
+			wrmsrq(MSR_IA32_APICBASE, val.q);
 			enabled_via_apicbase = 1;
 		}
 	}
@@ -2442,7 +2443,7 @@ static int lapic_suspend(void *data)
 
 static void lapic_resume(void *data)
 {
-	unsigned int l, h;
+	struct msr val;
 	unsigned long flags;
 	int maxlvt;
 
@@ -2475,10 +2476,10 @@ static void lapic_resume(void *data)
 		 * SMP! We'll need to do this as part of the CPU restore!
 		 */
 		if (boot_cpu_data.x86 >= 6) {
-			rdmsr(MSR_IA32_APICBASE, l, h);
-			l &= ~MSR_IA32_APICBASE_BASE;
-			l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
-			wrmsr(MSR_IA32_APICBASE, l, h);
+			rdmsrq(MSR_IA32_APICBASE, val.q);
+			val.l &= ~MSR_IA32_APICBASE_BASE;
+			val.l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
+			wrmsrq(MSR_IA32_APICBASE, val.q);
 		}
 	}
 
author maintainer
#73 lore raw

PATCH 19/32 x86/cpu: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/centaur.c   | 35 +++++++++++++++++----------------
 arch/x86/kernel/cpu/common.c    | 12 ++++++-----
 arch/x86/kernel/cpu/intel.c     |  8 ++++----
 arch/x86/kernel/cpu/transmeta.c |  9 +++++----
 arch/x86/kernel/cpu/zhaoxin.c   | 12 +++++------
 5 files changed, 39 insertions(+), 37 deletions(-)
arch/x86/kernel/cpu/centaur.c +18 -17
index 681d2da49341..513fa1f640f9 100644
@@ -22,7 +22,7 @@
 
 static void init_c3(struct cpuinfo_x86 *c)
 {
-	u32  lo, hi;
+	u64 msr;
 
 	/* Test for Centaur Extended Feature Flags presence */
 	if (cpuid_eax(0xC0000000) >= 0xC0000001) {
@@ -30,17 +30,17 @@ static void init_c3(struct cpuinfo_x86 *c)
 
 		/* enable ACE unit, if present and disabled */
 		if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
-			rdmsr(MSR_VIA_FCR, lo, hi);
-			lo |= ACE_FCR;		/* enable ACE unit */
-			wrmsr(MSR_VIA_FCR, lo, hi);
+			rdmsrq(MSR_VIA_FCR, msr);
+			/* enable ACE unit */
+			wrmsrq(MSR_VIA_FCR, msr | ACE_FCR);
 			pr_info("CPU: Enabled ACE h/w crypto\n");
 		}
 
 		/* enable RNG unit, if present and disabled */
 		if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
-			rdmsr(MSR_VIA_RNG, lo, hi);
-			lo |= RNG_ENABLE;	/* enable RNG unit */
-			wrmsr(MSR_VIA_RNG, lo, hi);
+			rdmsrq(MSR_VIA_RNG, msr);
+			/* enable RNG unit */
+			wrmsrq(MSR_VIA_RNG, msr | RNG_ENABLE);
 			pr_info("CPU: Enabled h/w RNG\n");
 		}
 
@@ -52,9 +52,8 @@ static void init_c3(struct cpuinfo_x86 *c)
 #ifdef CONFIG_X86_32
 	/* Cyrix III family needs CX8 & PGE explicitly enabled. */
 	if (c->x86_model >= 6 && c->x86_model <= 13) {
-		rdmsr(MSR_VIA_FCR, lo, hi);
-		lo |= (1<<1 | 1<<7);
-		wrmsr(MSR_VIA_FCR, lo, hi);
+		rdmsrq(MSR_VIA_FCR, msr);
+		wrmsrq(MSR_VIA_FCR, msr | (1 << 1 | 1 << 7));
 		set_cpu_cap(c, X86_FEATURE_CX8);
 	}
 
@@ -115,8 +114,9 @@ static void init_centaur(struct cpuinfo_x86 *c)
 	char *name;
 	u32  fcr_set = 0;
 	u32  fcr_clr = 0;
-	u32  lo, hi, newlo;
+	u32  newlo;
 	u32  aa, bb, cc, dd;
+	struct msr val;
 #endif
 	early_init_centaur(c);
 	init_intel_cacheinfo(c);
@@ -169,15 +169,16 @@ static void init_centaur(struct cpuinfo_x86 *c)
 			name = "??";
 		}
 
-		rdmsr(MSR_IDT_FCR1, lo, hi);
-		newlo = (lo|fcr_set) & (~fcr_clr);
+		rdmsrq(MSR_IDT_FCR1, val.q);
+		newlo = (val.l | fcr_set) & (~fcr_clr);
 
-		if (newlo != lo) {
+		if (newlo != val.l) {
 			pr_info("Centaur FCR was 0x%X now 0x%X\n",
-				lo, newlo);
-			wrmsr(MSR_IDT_FCR1, newlo, hi);
+				val.l, newlo);
+			val.l = newlo;
+			wrmsrq(MSR_IDT_FCR1, val.q);
 		} else {
-			pr_info("Centaur FCR is 0x%X\n", lo);
+			pr_info("Centaur FCR is 0x%X\n", val.l);
 		}
 		/* Emulate MTRRs using Centaur's MCR. */
 		set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR);
arch/x86/kernel/cpu/common.c +7 -5
index a3df21d26460..cbef2c6c8478 100644
@@ -339,16 +339,16 @@ bool cpuid_feature(void)
 
 static void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
 {
-	unsigned long lo, hi;
+	struct msr val;
 
 	if (!cpu_has(c, X86_FEATURE_PN) || !disable_x86_serial_nr)
 		return;
 
 	/* Disable processor serial number: */
 
-	rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
-	lo |= 0x200000;
-	wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
+	rdmsrq(MSR_IA32_BBL_CR_CTL, val.q);
+	val.l |= 0x200000;
+	wrmsrq(MSR_IA32_BBL_CR_CTL, val.q);
 
 	pr_notice("CPU serial number disabled.\n");
 	clear_cpu_cap(c, X86_FEATURE_PN);
@@ -2299,8 +2299,10 @@ static inline void idt_syscall_init(void)
 /* May not be marked __init: used by software suspend */
 void syscall_init(void)
 {
+	struct msr val = { .h = (__USER32_CS << 16) | __KERNEL_CS };
+
 	/* The default user and kernel segments */
-	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
+	wrmsrq(MSR_STAR, val.q);
 
 	/*
 	 * Except the IA32_STAR MSR, there is NO need to setup SYSCALL and
arch/x86/kernel/cpu/intel.c +4 -4
index abb3984336eb..076bdd0d3f85 100644
@@ -542,12 +542,12 @@ static void init_intel(struct cpuinfo_x86 *c)
 		set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
 
 	if (boot_cpu_has(X86_FEATURE_DS)) {
-		unsigned int l1, l2;
+		u64 l;
 
-		rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
-		if (!(l1 & MSR_IA32_MISC_ENABLE_BTS_UNAVAIL))
+		rdmsrq(MSR_IA32_MISC_ENABLE, l);
+		if (!(l & MSR_IA32_MISC_ENABLE_BTS_UNAVAIL))
 			set_cpu_cap(c, X86_FEATURE_BTS);
-		if (!(l1 & MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL))
+		if (!(l & MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL))
 			set_cpu_cap(c, X86_FEATURE_PEBS);
 	}
 
arch/x86/kernel/cpu/transmeta.c +5 -4
index 1fdcd69c625c..c670fbb6ee50 100644
@@ -24,7 +24,8 @@ static void early_init_transmeta(struct cpuinfo_x86 *c)
 
 static void init_transmeta(struct cpuinfo_x86 *c)
 {
-	unsigned int cap_mask, uk, max, dummy;
+	u64 msr;
+	unsigned int max, dummy;
 	unsigned int cms_rev1, cms_rev2;
 	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
 	char cpu_info[65];
@@ -86,10 +87,10 @@ static void init_transmeta(struct cpuinfo_x86 *c)
 	}
 
 	/* Unhide possibly hidden capability flags */
-	rdmsr(0x80860004, cap_mask, uk);
-	wrmsr(0x80860004, ~0, uk);
+	rdmsrq(0x80860004, msr);
+	wrmsrq(0x80860004, msr | ~0U);
 	c->x86_capability[CPUID_1_EDX] = cpuid_edx(0x00000001);
-	wrmsr(0x80860004, cap_mask, uk);
+	wrmsrq(0x80860004, msr);
 
 	/* All Transmeta CPUs have a constant TSC */
 	set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
arch/x86/kernel/cpu/zhaoxin.c +5 -7
index 761aef5590ac..fe504fd43c77 100644
@@ -21,7 +21,7 @@
 
 static void init_zhaoxin_cap(struct cpuinfo_x86 *c)
 {
-	u32  lo, hi;
+	u64 msr;
 
 	/* Test for Extended Feature Flags presence */
 	if (cpuid_eax(0xC0000000) >= 0xC0000001) {
@@ -29,19 +29,17 @@ static void init_zhaoxin_cap(struct cpuinfo_x86 *c)
 
 		/* Enable ACE unit, if present and disabled */
 		if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
-			rdmsr(MSR_ZHAOXIN_FCR57, lo, hi);
+			rdmsrq(MSR_ZHAOXIN_FCR57, msr);
 			/* Enable ACE unit */
-			lo |= ACE_FCR;
-			wrmsr(MSR_ZHAOXIN_FCR57, lo, hi);
+			wrmsrq(MSR_ZHAOXIN_FCR57, msr | ACE_FCR);
 			pr_info("CPU: Enabled ACE h/w crypto\n");
 		}
 
 		/* Enable RNG unit, if present and disabled */
 		if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
-			rdmsr(MSR_ZHAOXIN_FCR57, lo, hi);
+			rdmsrq(MSR_ZHAOXIN_FCR57, msr);
 			/* Enable RNG unit */
-			lo |= RNG_ENABLE;
-			wrmsr(MSR_ZHAOXIN_FCR57, lo, hi);
+			wrmsrq(MSR_ZHAOXIN_FCR57, msr | RNG_ENABLE);
 			pr_info("CPU: Enabled h/w RNG\n");
 		}
 
Signature · 1 line
2.54.0
merge bot Applied
#74 lore raw

[tip: x86/msr] x86/cpu: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     2e9e6edbad45fe9078dfb2d35d1213c9969de49d
Gitweb:        https://git.kernel.org/tip/2e9e6edbad45fe9078dfb2d35d1213c9969de49d
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:10 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 02 Jul 2026 11:54:52 +02:00

x86/cpu: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 arch/x86/kernel/cpu/centaur.c   | 35 ++++++++++++++++----------------
 arch/x86/kernel/cpu/common.c    | 12 ++++++-----
 arch/x86/kernel/cpu/intel.c     |  8 +++----
 arch/x86/kernel/cpu/transmeta.c |  9 ++++----
 arch/x86/kernel/cpu/zhaoxin.c   | 12 ++++-------
 5 files changed, 39 insertions(+), 37 deletions(-)
arch/x86/kernel/cpu/centaur.c +18 -17
index 681d2da..513fa1f 100644
@@ -22,7 +22,7 @@
 
 static void init_c3(struct cpuinfo_x86 *c)
 {
-	u32  lo, hi;
+	u64 msr;
 
 	/* Test for Centaur Extended Feature Flags presence */
 	if (cpuid_eax(0xC0000000) >= 0xC0000001) {
@@ -30,17 +30,17 @@ static void init_c3(struct cpuinfo_x86 *c)
 
 		/* enable ACE unit, if present and disabled */
 		if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
-			rdmsr(MSR_VIA_FCR, lo, hi);
-			lo |= ACE_FCR;		/* enable ACE unit */
-			wrmsr(MSR_VIA_FCR, lo, hi);
+			rdmsrq(MSR_VIA_FCR, msr);
+			/* enable ACE unit */
+			wrmsrq(MSR_VIA_FCR, msr | ACE_FCR);
 			pr_info("CPU: Enabled ACE h/w crypto\n");
 		}
 
 		/* enable RNG unit, if present and disabled */
 		if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
-			rdmsr(MSR_VIA_RNG, lo, hi);
-			lo |= RNG_ENABLE;	/* enable RNG unit */
-			wrmsr(MSR_VIA_RNG, lo, hi);
+			rdmsrq(MSR_VIA_RNG, msr);
+			/* enable RNG unit */
+			wrmsrq(MSR_VIA_RNG, msr | RNG_ENABLE);
 			pr_info("CPU: Enabled h/w RNG\n");
 		}
 
@@ -52,9 +52,8 @@ static void init_c3(struct cpuinfo_x86 *c)
 #ifdef CONFIG_X86_32
 	/* Cyrix III family needs CX8 & PGE explicitly enabled. */
 	if (c->x86_model >= 6 && c->x86_model <= 13) {
-		rdmsr(MSR_VIA_FCR, lo, hi);
-		lo |= (1<<1 | 1<<7);
-		wrmsr(MSR_VIA_FCR, lo, hi);
+		rdmsrq(MSR_VIA_FCR, msr);
+		wrmsrq(MSR_VIA_FCR, msr | (1 << 1 | 1 << 7));
 		set_cpu_cap(c, X86_FEATURE_CX8);
 	}
 
@@ -115,8 +114,9 @@ static void init_centaur(struct cpuinfo_x86 *c)
 	char *name;
 	u32  fcr_set = 0;
 	u32  fcr_clr = 0;
-	u32  lo, hi, newlo;
+	u32  newlo;
 	u32  aa, bb, cc, dd;
+	struct msr val;
 #endif
 	early_init_centaur(c);
 	init_intel_cacheinfo(c);
@@ -169,15 +169,16 @@ static void init_centaur(struct cpuinfo_x86 *c)
 			name = "??";
 		}
 
-		rdmsr(MSR_IDT_FCR1, lo, hi);
-		newlo = (lo|fcr_set) & (~fcr_clr);
+		rdmsrq(MSR_IDT_FCR1, val.q);
+		newlo = (val.l | fcr_set) & (~fcr_clr);
 
-		if (newlo != lo) {
+		if (newlo != val.l) {
 			pr_info("Centaur FCR was 0x%X now 0x%X\n",
-				lo, newlo);
-			wrmsr(MSR_IDT_FCR1, newlo, hi);
+				val.l, newlo);
+			val.l = newlo;
+			wrmsrq(MSR_IDT_FCR1, val.q);
 		} else {
-			pr_info("Centaur FCR is 0x%X\n", lo);
+			pr_info("Centaur FCR is 0x%X\n", val.l);
 		}
 		/* Emulate MTRRs using Centaur's MCR. */
 		set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR);
arch/x86/kernel/cpu/common.c +7 -5
index a3df21d..cbef2c6 100644
@@ -339,16 +339,16 @@ bool cpuid_feature(void)
 
 static void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
 {
-	unsigned long lo, hi;
+	struct msr val;
 
 	if (!cpu_has(c, X86_FEATURE_PN) || !disable_x86_serial_nr)
 		return;
 
 	/* Disable processor serial number: */
 
-	rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
-	lo |= 0x200000;
-	wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
+	rdmsrq(MSR_IA32_BBL_CR_CTL, val.q);
+	val.l |= 0x200000;
+	wrmsrq(MSR_IA32_BBL_CR_CTL, val.q);
 
 	pr_notice("CPU serial number disabled.\n");
 	clear_cpu_cap(c, X86_FEATURE_PN);
@@ -2299,8 +2299,10 @@ static inline void idt_syscall_init(void)
 /* May not be marked __init: used by software suspend */
 void syscall_init(void)
 {
+	struct msr val = { .h = (__USER32_CS << 16) | __KERNEL_CS };
+
 	/* The default user and kernel segments */
-	wrmsr(MSR_STAR, 0, (__USER32_CS << 16) | __KERNEL_CS);
+	wrmsrq(MSR_STAR, val.q);
 
 	/*
 	 * Except the IA32_STAR MSR, there is NO need to setup SYSCALL and
arch/x86/kernel/cpu/intel.c +4 -4
index abb3984..076bdd0 100644
@@ -542,12 +542,12 @@ static void init_intel(struct cpuinfo_x86 *c)
 		set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
 
 	if (boot_cpu_has(X86_FEATURE_DS)) {
-		unsigned int l1, l2;
+		u64 l;
 
-		rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
-		if (!(l1 & MSR_IA32_MISC_ENABLE_BTS_UNAVAIL))
+		rdmsrq(MSR_IA32_MISC_ENABLE, l);
+		if (!(l & MSR_IA32_MISC_ENABLE_BTS_UNAVAIL))
 			set_cpu_cap(c, X86_FEATURE_BTS);
-		if (!(l1 & MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL))
+		if (!(l & MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL))
 			set_cpu_cap(c, X86_FEATURE_PEBS);
 	}
 
arch/x86/kernel/cpu/transmeta.c +5 -4
index 1fdcd69..c670fbb 100644
@@ -24,7 +24,8 @@ static void early_init_transmeta(struct cpuinfo_x86 *c)
 
 static void init_transmeta(struct cpuinfo_x86 *c)
 {
-	unsigned int cap_mask, uk, max, dummy;
+	u64 msr;
+	unsigned int max, dummy;
 	unsigned int cms_rev1, cms_rev2;
 	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
 	char cpu_info[65];
@@ -86,10 +87,10 @@ static void init_transmeta(struct cpuinfo_x86 *c)
 	}
 
 	/* Unhide possibly hidden capability flags */
-	rdmsr(0x80860004, cap_mask, uk);
-	wrmsr(0x80860004, ~0, uk);
+	rdmsrq(0x80860004, msr);
+	wrmsrq(0x80860004, msr | ~0U);
 	c->x86_capability[CPUID_1_EDX] = cpuid_edx(0x00000001);
-	wrmsr(0x80860004, cap_mask, uk);
+	wrmsrq(0x80860004, msr);
 
 	/* All Transmeta CPUs have a constant TSC */
 	set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
arch/x86/kernel/cpu/zhaoxin.c +5 -7
index 761aef5..fe504fd 100644
@@ -21,7 +21,7 @@
 
 static void init_zhaoxin_cap(struct cpuinfo_x86 *c)
 {
-	u32  lo, hi;
+	u64 msr;
 
 	/* Test for Extended Feature Flags presence */
 	if (cpuid_eax(0xC0000000) >= 0xC0000001) {
@@ -29,19 +29,17 @@ static void init_zhaoxin_cap(struct cpuinfo_x86 *c)
 
 		/* Enable ACE unit, if present and disabled */
 		if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
-			rdmsr(MSR_ZHAOXIN_FCR57, lo, hi);
+			rdmsrq(MSR_ZHAOXIN_FCR57, msr);
 			/* Enable ACE unit */
-			lo |= ACE_FCR;
-			wrmsr(MSR_ZHAOXIN_FCR57, lo, hi);
+			wrmsrq(MSR_ZHAOXIN_FCR57, msr | ACE_FCR);
 			pr_info("CPU: Enabled ACE h/w crypto\n");
 		}
 
 		/* Enable RNG unit, if present and disabled */
 		if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
-			rdmsr(MSR_ZHAOXIN_FCR57, lo, hi);
+			rdmsrq(MSR_ZHAOXIN_FCR57, msr);
 			/* Enable RNG unit */
-			lo |= RNG_ENABLE;
-			wrmsr(MSR_ZHAOXIN_FCR57, lo, hi);
+			wrmsrq(MSR_ZHAOXIN_FCR57, msr | RNG_ENABLE);
 			pr_info("CPU: Enabled h/w RNG\n");
 		}
 
maintainer
#75 lore raw

Re: [tip: x86/msr] x86/cpu: Stop using 32-bit MSR interfaces

Quoted 5 lines · On Thu, Jul 02, 2026 at 10:15:54AM -0000, tip-bot2 for Juergen Gross wrote:
arch/x86/kernel/cpu/transmeta.c +0 -0
index 1fdcd69..c670fbb 100644

arch/x86/kernel/cpu/transmeta.c static void early_init_transmeta(struct cpuinfo_x86 *c) · line 31

Quoted 9 lines
arch/x86/kernel/cpu/transmeta.c +2 -1
@@ -24,7 +24,8 @@ static void early_init_transmeta(struct cpuinfo_x86 *c)
 
 static void init_transmeta(struct cpuinfo_x86 *c)
 {
-	unsigned int cap_mask, uk, max, dummy;
+	u64 msr;
+	unsigned int max, dummy;
 	unsigned int cms_rev1, cms_rev2;
 	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
 	char cpu_info[65];

The tip-tree preferred ordering of variable declarations at the beginning of a function is reverse fir tree order::

	struct long_struct_name *descriptive_name;
	unsigned long foo, bar;
	unsigned int tmp;
	int ret;

The above is faster to parse than the reverse ordering::

	int ret;
	unsigned int tmp;
	unsigned long foo, bar;
	struct long_struct_name *descriptive_name;

And even more so than random ordering::

	unsigned long foo, bar;
	int ret;
	struct long_struct_name *descriptive_name;
	unsigned int tmp;
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#76 lore raw

Re: [tip: x86/msr] x86/cpu: Stop using 32-bit MSR interfaces

Quoted 31 lines · Borislav Petkov
Quoted 5 lines · On Thu, Jul 02, 2026 at 10:15:54AM -0000, tip-bot2 for Juergen Gross wrote:
arch/x86/kernel/cpu/transmeta.c +0 -0
index 1fdcd69..c670fbb 100644

arch/x86/kernel/cpu/transmeta.c static void early_init_transmeta(struct cpuinfo_x86 *c) · line 31

Quoted 9 lines
arch/x86/kernel/cpu/transmeta.c +2 -1
@@ -24,7 +24,8 @@ static void early_init_transmeta(struct cpuinfo_x86 *c)
 
  static void init_transmeta(struct cpuinfo_x86 *c)
  {
-	unsigned int cap_mask, uk, max, dummy;
+	u64 msr;
+	unsigned int max, dummy;
  	unsigned int cms_rev1, cms_rev2;
  	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
  	char cpu_info[65];

The tip-tree preferred ordering of variable declarations at the beginning of a function is reverse fir tree order::

	struct long_struct_name *descriptive_name;
	unsigned long foo, bar;
	unsigned int tmp;
	int ret;

The above is faster to parse than the reverse ordering::

	int ret;
	unsigned int tmp;
	unsigned long foo, bar;
	struct long_struct_name *descriptive_name;
Quoted 7 lines

And even more so than random ordering::

	unsigned long foo, bar;
	int ret;
	struct long_struct_name *descriptive_name;
	unsigned int tmp;

What are the expectations regarding this patch now?

I could:

- do nothing

- send a V2 of the patch

- send an incremental patch

Juergen

maintainer
#77 lore raw

Re: [tip: x86/msr] x86/cpu: Stop using 32-bit MSR interfaces

Quoted 5 lines · Juergen Gross

What are the expectations regarding this patch now?

I could:

- do nothing

yes, and pls think about it when doing future patches.

We have everything about tip coding style etc documented here:

https://docs.kernel.org/process/maintainer-tip.html

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#78 lore raw

Re: [tip: x86/msr] x86/cpu: Stop using 32-bit MSR interfaces

Quoted 8 lines · Borislav Petkov
Quoted 5 lines · Juergen Gross

What are the expectations regarding this patch now?

I could:

- do nothing

yes, and pls think about it when doing future patches.

Will do.

Quoted 3 lines

We have everything about tip coding style etc documented here:

https://docs.kernel.org/process/maintainer-tip.html

Right.

I tried to follow that for source files which seemed to obey to that style, which didn't seem to be the case for this patch. I'll adapt touched variable declarations in future.

Juergen

#79 lore raw

Re: [tip: x86/msr] x86/cpu: Stop using 32-bit MSR interfaces

In reply to Borislav Petkov
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · On Thu, Jul 02, 2026 at 10:15:54AM -0000, tip-bot2 for Juergen Gross wrote:
arch/x86/kernel/cpu/transmeta.c +0 -0
index 1fdcd69..c670fbb 100644
@@ -24,7 +24,8 @@ static void early_init_transmeta(struct cpuinfo_x86 *c)
 
Quoted 11 lines

arch/x86/kernel/cpu/transmeta.c static void early_init_transmeta(struct cpuinfo_x86 *c) · line 31

Quoted 8 lines
arch/x86/kernel/cpu/transmeta.c +2 -1
 static void init_transmeta(struct cpuinfo_x86 *c)
 {
-	unsigned int cap_mask, uk, max, dummy;
+	u64 msr;
+	unsigned int max, dummy;
 	unsigned int cms_rev1, cms_rev2;
 	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
 	char cpu_info[65];

The tip-tree preferred ordering of variable declarations at the beginning of a function is reverse fir tree order::

While that's true, the style violation is a pre-existing condition in the current code:

	unsigned int cap_mask, uk, max, dummy;
	unsigned int cms_rev1, cms_rev2;
	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
	char cpu_info[65];

... and the best policy regarding API conversion patches like this is to keep the original style, to not mix several changes together, which only makes review harder.

But I agree with fixing the style problems of course, but it should be done either in a preparatory patch, or in a followup patch. Either ordering is fine to me.

Thanks,

Ingo

author maintainer
#80 lore raw

Re: [tip: x86/msr] x86/cpu: Stop using 32-bit MSR interfaces

Quoted 30 lines · Ingo Molnar
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · On Thu, Jul 02, 2026 at 10:15:54AM -0000, tip-bot2 for Juergen Gross wrote:
arch/x86/kernel/cpu/transmeta.c +0 -0
index 1fdcd69..c670fbb 100644
@@ -24,7 +24,8 @@ static void early_init_transmeta(struct cpuinfo_x86 *c)
 
Quoted 11 lines

arch/x86/kernel/cpu/transmeta.c static void early_init_transmeta(struct cpuinfo_x86 *c) · line 31

Quoted 8 lines
arch/x86/kernel/cpu/transmeta.c +2 -1
  static void init_transmeta(struct cpuinfo_x86 *c)
  {
-	unsigned int cap_mask, uk, max, dummy;
+	u64 msr;
+	unsigned int max, dummy;
  	unsigned int cms_rev1, cms_rev2;
  	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
  	char cpu_info[65];

The tip-tree preferred ordering of variable declarations at the beginning of a function is reverse fir tree order::

While that's true, the style violation is a pre-existing condition in the current code:

	unsigned int cap_mask, uk, max, dummy;
	unsigned int cms_rev1, cms_rev2;
	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
	char cpu_info[65];
Quoted 7 lines

... and the best policy regarding API conversion patches like this is to keep the original style, to not mix several changes together, which only makes review harder.

But I agree with fixing the style problems of course, but it should be done either in a preparatory patch, or in a followup patch. Either ordering is fine to me.

I'll send a followup patch.

Juergen

#81 lore raw

Re: [tip: x86/msr] x86/cpu: Stop using 32-bit MSR interfaces

Quoted 34 lines · Jürgen Groß
Quoted 33 lines · Ingo Molnar
Quoted 17 lines · Borislav Petkov

arch/x86/kernel/cpu/transmeta.c static void early_init_transmeta(struct cpuinfo_x86 *c) · line 30

Quoted 13 lines · On Thu, Jul 02, 2026 at 10:15:54AM -0000, tip-bot2 for Juergen Gross wrote:
arch/x86/kernel/cpu/transmeta.c +2 -1
index 1fdcd69..c670fbb 100644
@@ -24,7 +24,8 @@ static void early_init_transmeta(struct cpuinfo_x86 *c)
  static void init_transmeta(struct cpuinfo_x86 *c)
  {
-	unsigned int cap_mask, uk, max, dummy;
+	u64 msr;
+	unsigned int max, dummy;
  	unsigned int cms_rev1, cms_rev2;
  	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
  	char cpu_info[65];

The tip-tree preferred ordering of variable declarations at the beginning of a function is reverse fir tree order::

While that's true, the style violation is a pre-existing condition in the current code:

	unsigned int cap_mask, uk, max, dummy;
	unsigned int cms_rev1, cms_rev2;
	unsigned int cpu_rev, cpu_freq = 0, cpu_flags, new_cpu_rev;
	char cpu_info[65];

... and the best policy regarding API conversion patches like this is to keep the original style, to not mix several changes together, which only makes review harder.

Quoted 5 lines
Quoted 3 lines

But I agree with fixing the style problems of course, but it should be done either in a preparatory patch, or in a followup patch. Either ordering is fine to me.

I'll send a followup patch.

Thank you!

Ingo

author maintainer
#82 lore raw

PATCH 20/32 drivers/ata: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

In drivers/ata/pata_cs5536.c don't redefine rdmsr() and wrmsr() as empty macros for avoiding misuse, but guard the affected code via

---
 drivers/ata/pata_cs5535.c | 20 ++++++++++----------
 drivers/ata/pata_cs5536.c | 17 ++++++++---------
 2 files changed, 18 insertions(+), 19 deletions(-)
drivers/ata/pata_cs5535.c +10 -10
index d793fc441b46..da98390cc49e 100644
@@ -90,7 +90,7 @@ static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev)
 	static const u16 pio_cmd_timings[5] = {
 		0xF7F4, 0x53F3, 0x13F1, 0x5131, 0x1131
 	};
-	u32 reg, __maybe_unused dummy;
+	u32 reg;
 	struct ata_device *pair = ata_dev_pair(adev);
 
 	int mode = adev->pio_mode - XFER_PIO_0;
@@ -102,16 +102,16 @@ static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev)
 		cmdmode = min(mode, pairmode);
 		/* Write the other drive timing register if it changed */
 		if (cmdmode < pairmode)
-			wrmsr(ATAC_CH0D0_PIO + 2 * pair->devno,
-				pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode], 0);
+			wrmsrq(ATAC_CH0D0_PIO + 2 * pair->devno,
+				pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode]);
 	}
 	/* Write the drive timing register */
-	wrmsr(ATAC_CH0D0_PIO + 2 * adev->devno,
-		pio_cmd_timings[cmdmode] << 16 | pio_timings[mode], 0);
+	wrmsrq(ATAC_CH0D0_PIO + 2 * adev->devno,
+		pio_cmd_timings[cmdmode] << 16 | pio_timings[mode]);
 
 	/* Set the PIO "format 1" bit in the DMA timing register */
-	rdmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, dummy);
-	wrmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg | 0x80000000UL, 0);
+	rdmsrq(ATAC_CH0D0_DMA + 2 * adev->devno, reg);
+	wrmsrq(ATAC_CH0D0_DMA + 2 * adev->devno, reg | 0x80000000UL);
 }
 
 /**
@@ -129,16 +129,16 @@ static void cs5535_set_dmamode(struct ata_port *ap, struct ata_device *adev)
 	static const u32 mwdma_timings[3] = {
 		0x7F0FFFF3, 0x7F035352, 0x7F024241
 	};
-	u32 reg, __maybe_unused dummy;
+	u32 reg;
 	int mode = adev->dma_mode;
 
-	rdmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, dummy);
+	rdmsrq(ATAC_CH0D0_DMA + 2 * adev->devno, reg);
 	reg &= 0x80000000UL;
 	if (mode >= XFER_UDMA_0)
 		reg |= udma_timings[mode - XFER_UDMA_0];
 	else
 		reg |= mwdma_timings[mode - XFER_MW_DMA_0];
-	wrmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, 0);
+	wrmsrq(ATAC_CH0D0_DMA + 2 * adev->devno, reg);
 }
 
 static const struct scsi_host_template cs5535_sht = {
drivers/ata/pata_cs5536.c +8 -9
index 73e81e160c91..61d232a82b5e 100644
@@ -32,11 +32,8 @@
 static int use_msr;
 module_param_named(msr, use_msr, int, 0644);
 MODULE_PARM_DESC(msr, "Force using MSR to configure IDE function (Default: 0)");
+#define MAYBE_USE_MSR
 #else
-#undef rdmsr	/* avoid accidental MSR usage on, e.g. x86-64 */
-#undef wrmsr
-#define rdmsr(x, y, z) do { } while (0)
-#define wrmsr(x, y, z) do { } while (0)
 #define use_msr 0
 #endif
 
@@ -85,22 +82,24 @@ static const struct dmi_system_id udma_quirk_dmi_table[] = {
 
 static int cs5536_read(struct pci_dev *pdev, int reg, u32 *val)
 {
+#ifdef MAYBE_USE_MSR
 	if (unlikely(use_msr)) {
-		u32 dummy __maybe_unused;
-
-		rdmsr(MSR_IDE_CFG + reg, *val, dummy);
+		rdmsrq(MSR_IDE_CFG + reg, *val);
 		return 0;
 	}
+#endif
 
 	return pci_read_config_dword(pdev, PCI_IDE_CFG + reg * 4, val);
 }
 
-static int cs5536_write(struct pci_dev *pdev, int reg, int val)
+static int cs5536_write(struct pci_dev *pdev, int reg, u32 val)
 {
+#ifdef MAYBE_USE_MSR
 	if (unlikely(use_msr)) {
-		wrmsr(MSR_IDE_CFG + reg, val, 0);
+		wrmsrq(MSR_IDE_CFG + reg, val);
 		return 0;
 	}
+#endif
 
 	return pci_write_config_dword(pdev, PCI_IDE_CFG + reg * 4, val);
 }
Signature · 1 line
2.54.0
#83 lore raw

Re: [PATCH 20/32] drivers/ata: Stop using 32-bit MSR interfaces

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Critical] The change to `wrmsrq()` in `cs5535_set_piomode` introduces a critical sign-extension bug…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] The change to wrmsrq() in cs5535_set_piomode introduces a critical sign-extension bug, writing 0xFFFFFFFF to the upper 32 bits of the MSR.
- [Low] The commit message is incomplete and truncated mid-sentence.
--

commit 9a4c6821b4ef60316ec2b36e0f505f4148809966
Author: Juergen Gross <[email protected]>

drivers/ata: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. This patch switches the pata_cs5535 and pata_cs5536 drivers to use the 64-bit variants instead.

Quoted 2 lines

In drivers/ata/pata_cs5536.c don't redefine rdmsr() and wrmsr() as empty macros for avoiding misuse, but guard the affected code via

[Severity: Low]
This isn't a bug, but the commit message appears to be truncated mid-sentence.

Quoted 8 lines
drivers/ata/pata_cs5535.c +0 -0
index d793fc441b467..da98390cc49e8 100644
@@ -102,16 +102,16 @@ static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev)
 		cmdmode = min(mode, pairmode);
 		/* Write the other drive timing register if it changed */
 		if (cmdmode < pairmode)

drivers/ata/pata_cs5535.c static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev) · line 110

Quoted 10 lines
drivers/ata/pata_cs5535.c +4 -4
-			wrmsr(ATAC_CH0D0_PIO + 2 * pair->devno,
-				pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode], 0);
+			wrmsrq(ATAC_CH0D0_PIO + 2 * pair->devno,
+				pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode]);
 	}
 	/* Write the drive timing register */
-	wrmsr(ATAC_CH0D0_PIO + 2 * adev->devno,
-		pio_cmd_timings[cmdmode] << 16 | pio_timings[mode], 0);
+	wrmsrq(ATAC_CH0D0_PIO + 2 * adev->devno,
+		pio_cmd_timings[cmdmode] << 16 | pio_timings[mode]);

[Severity: Critical]
Will these wrmsrq() calls write 0xFFFFFFFF into the upper 32 bits of the MSR for PIO mode 0?

Because pio_cmd_timings contains u16 values, C integer promotion rules will promote pio_cmd_timings[cmdmode] to a signed 32-bit int before the shift.

For PIO mode 0 (0xF7F4), the shift results in a negative 32-bit integer (0xF7F40000).

Since wrmsrq() takes a u64 parameter, this negative 32-bit int is implicitly sign-extended to 64 bits (0xFFFFFFFFF7F4XXXX). This corrupts the upper 32 bits of the timing registers, which could trigger a General Protection Fault.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
author maintainer
#84 lore raw

Re: [PATCH 20/32] drivers/ata: Stop using 32-bit MSR interfaces

Quoted 14 lines · On 29.06.26 08:23, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] The change to wrmsrq() in cs5535_set_piomode introduces a critical sign-extension bug, writing 0xFFFFFFFF to the upper 32 bits of the MSR.
- [Low] The commit message is incomplete and truncated mid-sentence.
--

commit 9a4c6821b4ef60316ec2b36e0f505f4148809966
Author: Juergen Gross <[email protected]>

drivers/ata: Stop using 32-bit MSR interfaces

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. This patch switches the pata_cs5535 and pata_cs5536 drivers to use the 64-bit variants instead.

Quoted 5 lines
Quoted 2 lines

In drivers/ata/pata_cs5536.c don't redefine rdmsr() and wrmsr() as empty macros for avoiding misuse, but guard the affected code via

[Severity: Low]
This isn't a bug, but the commit message appears to be truncated mid-sentence.

Oh, sorry, will update.

Quoted 27 lines
Quoted 9 lines
drivers/ata/pata_cs5535.c +0 -0
index d793fc441b467..da98390cc49e8 100644
@@ -102,16 +102,16 @@ static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev)
  		cmdmode = min(mode, pairmode);
  		/* Write the other drive timing register if it changed */
  		if (cmdmode < pairmode)

drivers/ata/pata_cs5535.c static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev) · line 110

Quoted 10 lines
drivers/ata/pata_cs5535.c +4 -4
-			wrmsr(ATAC_CH0D0_PIO + 2 * pair->devno,
-				pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode], 0);
+			wrmsrq(ATAC_CH0D0_PIO + 2 * pair->devno,
+				pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode]);
  	}
  	/* Write the drive timing register */
-	wrmsr(ATAC_CH0D0_PIO + 2 * adev->devno,
-		pio_cmd_timings[cmdmode] << 16 | pio_timings[mode], 0);
+	wrmsrq(ATAC_CH0D0_PIO + 2 * adev->devno,
+		pio_cmd_timings[cmdmode] << 16 | pio_timings[mode]);

[Severity: Critical]
Will these wrmsrq() calls write 0xFFFFFFFF into the upper 32 bits of the MSR for PIO mode 0?

Because pio_cmd_timings contains u16 values, C integer promotion rules will promote pio_cmd_timings[cmdmode] to a signed 32-bit int before the shift.

Quoted 8 lines

For PIO mode 0 (0xF7F4), the shift results in a negative 32-bit integer (0xF7F40000).

Since wrmsrq() takes a u64 parameter, this negative 32-bit int is implicitly sign-extended to 64 bits (0xFFFFFFFFF7F4XXXX). This corrupts the upper 32 bits of the timing registers, which could trigger a General Protection Fault.

Right, will fix that.

Juergen

author maintainer
#85 lore raw

PATCH v2 20/32 drivers/ata: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

In drivers/ata/pata_cs5536.c don't redefine rdmsr() and wrmsr() as empty macros for avoiding misuse, but guard the affected code via a simple #ifdef.

---
V2:
- avoid sign extension when using wrmsrq() (Sashiko bot)

---
 drivers/ata/pata_cs5535.c | 20 ++++++++++----------
 drivers/ata/pata_cs5536.c | 17 ++++++++---------
 2 files changed, 18 insertions(+), 19 deletions(-)
drivers/ata/pata_cs5535.c +10 -10
index d793fc441b46..e16c7f4c7c27 100644
@@ -90,7 +90,7 @@ static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev)
 	static const u16 pio_cmd_timings[5] = {
 		0xF7F4, 0x53F3, 0x13F1, 0x5131, 0x1131
 	};
-	u32 reg, __maybe_unused dummy;
+	u32 reg;
 	struct ata_device *pair = ata_dev_pair(adev);
 
 	int mode = adev->pio_mode - XFER_PIO_0;
@@ -102,16 +102,16 @@ static void cs5535_set_piomode(struct ata_port *ap, struct ata_device *adev)
 		cmdmode = min(mode, pairmode);
 		/* Write the other drive timing register if it changed */
 		if (cmdmode < pairmode)
-			wrmsr(ATAC_CH0D0_PIO + 2 * pair->devno,
-				pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode], 0);
+			wrmsrq(ATAC_CH0D0_PIO + 2 * pair->devno,
+				(u32)pio_cmd_timings[cmdmode] << 16 | pio_timings[pairmode]);
 	}
 	/* Write the drive timing register */
-	wrmsr(ATAC_CH0D0_PIO + 2 * adev->devno,
-		pio_cmd_timings[cmdmode] << 16 | pio_timings[mode], 0);
+	wrmsrq(ATAC_CH0D0_PIO + 2 * adev->devno,
+		(u32)pio_cmd_timings[cmdmode] << 16 | pio_timings[mode]);
 
 	/* Set the PIO "format 1" bit in the DMA timing register */
-	rdmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, dummy);
-	wrmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg | 0x80000000UL, 0);
+	rdmsrq(ATAC_CH0D0_DMA + 2 * adev->devno, reg);
+	wrmsrq(ATAC_CH0D0_DMA + 2 * adev->devno, reg | 0x80000000UL);
 }
 
 /**
@@ -129,16 +129,16 @@ static void cs5535_set_dmamode(struct ata_port *ap, struct ata_device *adev)
 	static const u32 mwdma_timings[3] = {
 		0x7F0FFFF3, 0x7F035352, 0x7F024241
 	};
-	u32 reg, __maybe_unused dummy;
+	u32 reg;
 	int mode = adev->dma_mode;
 
-	rdmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, dummy);
+	rdmsrq(ATAC_CH0D0_DMA + 2 * adev->devno, reg);
 	reg &= 0x80000000UL;
 	if (mode >= XFER_UDMA_0)
 		reg |= udma_timings[mode - XFER_UDMA_0];
 	else
 		reg |= mwdma_timings[mode - XFER_MW_DMA_0];
-	wrmsr(ATAC_CH0D0_DMA + 2 * adev->devno, reg, 0);
+	wrmsrq(ATAC_CH0D0_DMA + 2 * adev->devno, reg);
 }
 
 static const struct scsi_host_template cs5535_sht = {
drivers/ata/pata_cs5536.c +8 -9
index 73e81e160c91..61d232a82b5e 100644
@@ -32,11 +32,8 @@
 static int use_msr;
 module_param_named(msr, use_msr, int, 0644);
 MODULE_PARM_DESC(msr, "Force using MSR to configure IDE function (Default: 0)");
+#define MAYBE_USE_MSR
 #else
-#undef rdmsr	/* avoid accidental MSR usage on, e.g. x86-64 */
-#undef wrmsr
-#define rdmsr(x, y, z) do { } while (0)
-#define wrmsr(x, y, z) do { } while (0)
 #define use_msr 0
 #endif
 
@@ -85,22 +82,24 @@ static const struct dmi_system_id udma_quirk_dmi_table[] = {
 
 static int cs5536_read(struct pci_dev *pdev, int reg, u32 *val)
 {
+#ifdef MAYBE_USE_MSR
 	if (unlikely(use_msr)) {
-		u32 dummy __maybe_unused;
-
-		rdmsr(MSR_IDE_CFG + reg, *val, dummy);
+		rdmsrq(MSR_IDE_CFG + reg, *val);
 		return 0;
 	}
+#endif
 
 	return pci_read_config_dword(pdev, PCI_IDE_CFG + reg * 4, val);
 }
 
-static int cs5536_write(struct pci_dev *pdev, int reg, int val)
+static int cs5536_write(struct pci_dev *pdev, int reg, u32 val)
 {
+#ifdef MAYBE_USE_MSR
 	if (unlikely(use_msr)) {
-		wrmsr(MSR_IDE_CFG + reg, val, 0);
+		wrmsrq(MSR_IDE_CFG + reg, val);
 		return 0;
 	}
+#endif
 
 	return pci_write_config_dword(pdev, PCI_IDE_CFG + reg * 4, val);
 }
Signature · 1 line
2.54.0
author maintainer
#86 lore raw

PATCH 21/32 agp/nvidia: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/char/agp/nvidia-agp.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)
drivers/char/agp/nvidia-agp.c +15 -17
index 4787391bb6b4..3e760bc00afa 100644
@@ -65,22 +65,20 @@ static int nvidia_fetch_size(void)
 
 static int nvidia_init_iorr(u32 base, u32 size)
 {
-	u32 base_hi, base_lo;
-	u32 mask_hi, mask_lo;
-	u32 sys_hi, sys_lo;
+	struct msr base_msr, mask_msr, sys_msr;
 	u32 iorr_addr, free_iorr_addr;
 
 	/* Find the iorr that is already used for the base */
 	/* If not found, determine the uppermost available iorr */
 	free_iorr_addr = AMD_K7_NUM_IORR;
 	for (iorr_addr = 0; iorr_addr < AMD_K7_NUM_IORR; iorr_addr++) {
-		rdmsr(IORR_BASE0 + 2 * iorr_addr, base_lo, base_hi);
-		rdmsr(IORR_MASK0 + 2 * iorr_addr, mask_lo, mask_hi);
+		rdmsrq(IORR_BASE0 + 2 * iorr_addr, base_msr.q);
+		rdmsrq(IORR_MASK0 + 2 * iorr_addr, mask_msr.q);
 
-		if ((base_lo & 0xfffff000) == (base & 0xfffff000))
+		if ((base_msr.l & 0xfffff000) == (base & 0xfffff000))
 			break;
 
-		if ((mask_lo & 0x00000800) == 0)
+		if ((mask_msr.l & 0x00000800) == 0)
 			free_iorr_addr = iorr_addr;
 	}
 
@@ -89,16 +87,16 @@ static int nvidia_init_iorr(u32 base, u32 size)
 		if (iorr_addr >= AMD_K7_NUM_IORR)
 			return -EINVAL;
 	}
-    base_hi = 0x0;
-    base_lo = (base & ~0xfff) | 0x18;
-    mask_hi = 0xf;
-    mask_lo = ((~(size - 1)) & 0xfffff000) | 0x800;
-    wrmsr(IORR_BASE0 + 2 * iorr_addr, base_lo, base_hi);
-    wrmsr(IORR_MASK0 + 2 * iorr_addr, mask_lo, mask_hi);
-
-    rdmsr(SYSCFG, sys_lo, sys_hi);
-    sys_lo |= 0x00100000;
-    wrmsr(SYSCFG, sys_lo, sys_hi);
+    base_msr.h = 0x0;
+    base_msr.l = (base & ~0xfff) | 0x18;
+    mask_msr.h = 0xf;
+    mask_msr.l = ((~(size - 1)) & 0xfffff000) | 0x800;
+    wrmsrq(IORR_BASE0 + 2 * iorr_addr, base_msr.q);
+    wrmsrq(IORR_MASK0 + 2 * iorr_addr, mask_msr.q);
+
+    rdmsrq(SYSCFG, sys_msr.q);
+    sys_msr.l |= 0x00100000;
+    wrmsrq(SYSCFG, sys_msr.q);
 
 	return 0;
 }
Signature · 1 line
2.54.0
#87 lore raw

Re: [PATCH 21/32] agp/nvidia: Stop using 32-bit MSR interfaces

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but there is a memory leak of the ioremap virtual memory area on suspend/resume.
- [High] This problem wasn't introduced by this patch, but an ignored initialization error on resume leads to a guaranteed NULL pointer dereference in the hardware TLB flush path.
- [High] This problem wasn't introduced by this patch, but a missing break in a timeout loop causes a soft lockup if the hardware fails to complete a TLB flush. --

commit 809ee345f7a00dcaa6e844219a8b666a3f9ffadb
Author: Juergen Gross <[email protected]>

agp/nvidia: Stop using 32-bit MSR interfaces

This commit replaces the deprecated 32-bit MSR interfaces rdmsr() and wrmsr() with their 64-bit equivalents in the NVIDIA AGP driver. This is part of a planned removal of the 32-bit variants.

drivers/char/agp/nvidia-agp.c

Quoted 4 lines
drivers/char/agp/nvidia-agp.c +0 -0
index 4787391bb6b4f..3e760bc00afaa 100644

[ ... ]

[Severity: High]
This isn't a bug introduced by this patch, but I noticed a potential memory leak on suspend/resume.

Does this code leak the vmap area leading to vmalloc space exhaustion after repeated suspend/resume cycles?

drivers/char/agp/nvidia-agp.c:nvidia_configure() {
...

	/* map aperture */
	apbase_phys = pci_resource_start(agp_bridge->dev, AGP_APERTURE_BAR);
	nvidia_private.aperture =
		(volatile u32 __iomem *) ioremap(apbase_phys, 33 * PAGE_SIZE);

...
}

Because the driver defines no suspend hook:

drivers/char/agp/nvidia-agp.c:
...
static DEFINE_SIMPLE_DEV_PM_OPS(agp_nvidia_pm_ops, NULL, agp_nvidia_resume);
...

The previous ioremap allocation is never unmapped via iounmap() when the system suspends.

[Severity: High]
This is a pre-existing issue, but I spotted a potential NULL pointer dereference in the hardware TLB flush path.

Could a failure in nvidia_configure() during resume lead to a kernel crash?

drivers/char/agp/nvidia-agp.c:agp_nvidia_resume() {
...

	/* reconfigure AGP hardware again */
	nvidia_configure();

	return 0;
}

The return value of nvidia_configure() is ignored. If ioremap fails during resume, nvidia_configure() returns -ENOMEM and nvidia_private.aperture remains NULL.

Later, when nvidia_tlbflush() is called, it unconditionally dereferences nvidia_private.aperture:

drivers/char/agp/nvidia-agp.c:nvidia_tlbflush() {
...

	/* flush TLB entries */
	for (i = 0; i < 32 + 1; i++)
		temp = readl(nvidia_private.aperture+(i * PAGE_SIZE / sizeof(u32)));

...
}

[Severity: High]
This isn't a bug introduced by this patch, but the timeout loop in nvidia_tlbflush() appears to be missing a break statement.

Can this cause a soft lockup if the hardware fails to complete a TLB flush?

drivers/char/agp/nvidia-agp.c:nvidia_tlbflush() {
...

		end = jiffies + 3*HZ;
		do {
			pci_read_config_dword(nvidia_private.dev_1,
					NVIDIA_1_WBC, &wbc_reg);
			if (time_before_eq(end, jiffies)) {
				printk(KERN_ERR PFX
				    "TLB flush took more than 3 seconds.\n");
			}
		} while (wbc_reg & nvidia_private.wbc_mask);

...
}

If the hardware enters an unexpected state and the timeout expires, the code prints an error message but lacks a break statement to exit the loop, which could trap the kernel in an infinite loop.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
author maintainer
#88 lore raw

PATCH 22/32 fbdev/geode: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/video/fbdev/geode/display_gx.c |  8 +++---
 drivers/video/fbdev/geode/lxfb_ops.c   | 38 +++++++++++++-------------
 drivers/video/fbdev/geode/suspend_gx.c | 20 ++++++++------
 3 files changed, 34 insertions(+), 32 deletions(-)
drivers/video/fbdev/geode/display_gx.c +4 -4
index 099322cefce0..b93aa21a1d2b 100644
@@ -23,15 +23,15 @@ unsigned int gx_frame_buffer_size(void)
 	unsigned int val;
 
 	if (!cs5535_has_vsa2()) {
-		uint32_t hi, lo;
+		struct msr msr;
 
 		/* The number of pages is (PMAX - PMIN)+1 */
-		rdmsr(MSR_GLIU_P2D_RO0, lo, hi);
+		rdmsrq(MSR_GLIU_P2D_RO0, msr.q);
 
 		/* PMAX */
-		val = ((hi & 0xff) << 12) | ((lo & 0xfff00000) >> 20);
+		val = ((msr.h & 0xff) << 12) | ((msr.l & 0xfff00000) >> 20);
 		/* PMIN */
-		val -= (lo & 0x000fffff);
+		val -= (msr.l & 0x000fffff);
 		val += 1;
 
 		/* The page size is 4k */
drivers/video/fbdev/geode/lxfb_ops.c +19 -19
index 2e33da9849b0..f5f1134cae9a 100644
@@ -124,19 +124,19 @@ static const struct {
 
 static void lx_set_dotpll(u32 pllval)
 {
-	u32 dotpll_lo, dotpll_hi;
+	struct msr dotpll;
 	int i;
 
-	rdmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
+	rdmsrq(MSR_GLCP_DOTPLL, dotpll.q);
 
-	if ((dotpll_lo & MSR_GLCP_DOTPLL_LOCK) && (dotpll_hi == pllval))
+	if ((dotpll.l & MSR_GLCP_DOTPLL_LOCK) && (dotpll.h == pllval))
 		return;
 
-	dotpll_hi = pllval;
-	dotpll_lo &= ~(MSR_GLCP_DOTPLL_BYPASS | MSR_GLCP_DOTPLL_HALFPIX);
-	dotpll_lo |= MSR_GLCP_DOTPLL_DOTRESET;
+	dotpll.h = pllval;
+	dotpll.l &= ~(MSR_GLCP_DOTPLL_BYPASS | MSR_GLCP_DOTPLL_HALFPIX);
+	dotpll.l |= MSR_GLCP_DOTPLL_DOTRESET;
 
-	wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
+	wrmsrq(MSR_GLCP_DOTPLL, dotpll.q);
 
 	/* Wait 100us for the PLL to lock */
 
@@ -145,15 +145,15 @@ static void lx_set_dotpll(u32 pllval)
 	/* Now, loop for the lock bit */
 
 	for (i = 0; i < 1000; i++) {
-		rdmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
-		if (dotpll_lo & MSR_GLCP_DOTPLL_LOCK)
+		rdmsrq(MSR_GLCP_DOTPLL, dotpll.q);
+		if (dotpll.l & MSR_GLCP_DOTPLL_LOCK)
 			break;
 	}
 
 	/* Clear the reset bit */
 
-	dotpll_lo &= ~MSR_GLCP_DOTPLL_DOTRESET;
-	wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
+	dotpll.l &= ~MSR_GLCP_DOTPLL_DOTRESET;
+	wrmsrq(MSR_GLCP_DOTPLL, dotpll.q);
 }
 
 /* Set the clock based on the frequency specified by the current mode */
@@ -268,7 +268,7 @@ static void lx_graphics_enable(struct fb_info *info)
 		config |= VP_DCFG_CRT_VSYNC_POL;
 
 	if (par->output & OUTPUT_PANEL) {
-		u32 msrlo, msrhi;
+		struct msr val;
 
 		write_fp(par, FP_PT1, 0);
 		temp = FP_PT2_SCRC;
@@ -282,10 +282,10 @@ static void lx_graphics_enable(struct fb_info *info)
 		write_fp(par, FP_PT2, temp);
 		write_fp(par, FP_DFC, FP_DFC_BC);
 
-		msrlo = MSR_LX_MSR_PADSEL_TFT_SEL_LOW;
-		msrhi = MSR_LX_MSR_PADSEL_TFT_SEL_HIGH;
+		val.l = MSR_LX_MSR_PADSEL_TFT_SEL_LOW;
+		val.h = MSR_LX_MSR_PADSEL_TFT_SEL_HIGH;
 
-		wrmsr(MSR_LX_MSR_PADSEL, msrlo, msrhi);
+		wrmsrq(MSR_LX_MSR_PADSEL, val.q);
 	}
 
 	if (par->output & OUTPUT_CRT) {
@@ -313,15 +313,15 @@ unsigned int lx_framebuffer_size(void)
 	unsigned int val;
 
 	if (!cs5535_has_vsa2()) {
-		uint32_t hi, lo;
+		struct msr msr;
 
 		/* The number of pages is (PMAX - PMIN)+1 */
-		rdmsr(MSR_GLIU_P2D_RO0, lo, hi);
+		rdmsrq(MSR_GLIU_P2D_RO0, msr.q);
 
 		/* PMAX */
-		val = ((hi & 0xff) << 12) | ((lo & 0xfff00000) >> 20);
+		val = ((msr.h & 0xff) << 12) | ((msr.l & 0xfff00000) >> 20);
 		/* PMIN */
-		val -= (lo & 0x000fffff);
+		val -= (msr.l & 0x000fffff);
 		val += 1;
 
 		/* The page size is 4k */
drivers/video/fbdev/geode/suspend_gx.c +11 -9
index 73307f42e343..6c0a526ee8a2 100644
@@ -40,25 +40,27 @@ static void gx_save_regs(struct gxfb_par *par)
 
 static void gx_set_dotpll(uint32_t dotpll_hi)
 {
-	uint32_t dotpll_lo;
+	struct msr dotpll;
 	int i;
 
-	rdmsrq(MSR_GLCP_DOTPLL, dotpll_lo);
-	dotpll_lo |= MSR_GLCP_DOTPLL_DOTRESET;
-	dotpll_lo &= ~MSR_GLCP_DOTPLL_BYPASS;
-	wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
+	rdmsrq(MSR_GLCP_DOTPLL, dotpll.q);
+	dotpll.l |= MSR_GLCP_DOTPLL_DOTRESET;
+	dotpll.l &= ~MSR_GLCP_DOTPLL_BYPASS;
+	dotpll.h = dotpll_hi;
+	wrmsrq(MSR_GLCP_DOTPLL, dotpll.q);
 
 	/* wait for the PLL to lock */
 	for (i = 0; i < 200; i++) {
-		rdmsrq(MSR_GLCP_DOTPLL, dotpll_lo);
-		if (dotpll_lo & MSR_GLCP_DOTPLL_LOCK)
+		rdmsrq(MSR_GLCP_DOTPLL, dotpll.q);
+		if (dotpll.l & MSR_GLCP_DOTPLL_LOCK)
 			break;
 		udelay(1);
 	}
 
 	/* PLL set, unlock */
-	dotpll_lo &= ~MSR_GLCP_DOTPLL_DOTRESET;
-	wrmsr(MSR_GLCP_DOTPLL, dotpll_lo, dotpll_hi);
+	dotpll.l &= ~MSR_GLCP_DOTPLL_DOTRESET;
+	dotpll.h = dotpll_hi;
+	wrmsrq(MSR_GLCP_DOTPLL, dotpll.q);
 }
 
 static void gx_restore_gfx_proc(struct gxfb_par *par)
Signature · 1 line
2.54.0
author maintainer
#89 lore raw

PATCH 23/32 hw_random/via-rng: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/char/hw_random/via-rng.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/char/hw_random/via-rng.c +15 -14
index a9a0a3b09c8b..b718e78d3c1c 100644
@@ -129,7 +129,8 @@ static int via_rng_data_read(struct hwrng *rng, u32 *data)
 static int via_rng_init(struct hwrng *rng)
 {
 	struct cpuinfo_x86 *c = &cpu_data(0);
-	u32 lo, hi, old_lo;
+	u32 old_lo;
+	struct msr val;
 
 	/* VIA Nano CPUs don't have the MSR_VIA_RNG anymore.  The RNG
 	 * is always enabled if CPUID rng_en is set.  There is no
@@ -150,32 +151,32 @@ static int via_rng_init(struct hwrng *rng)
 	 * does not say to write them as zero, so I make a guess that
 	 * we restore the values we find in the register.
 	 */
-	rdmsr(MSR_VIA_RNG, lo, hi);
+	rdmsrq(MSR_VIA_RNG, val.q);
 
-	old_lo = lo;
-	lo &= ~(0x7f << VIA_STRFILT_CNT_SHIFT);
-	lo &= ~VIA_XSTORE_CNT_MASK;
-	lo &= ~(VIA_STRFILT_ENABLE | VIA_STRFILT_FAIL | VIA_RAWBITS_ENABLE);
-	lo |= VIA_RNG_ENABLE;
-	lo |= VIA_NOISESRC1;
+	old_lo = val.l;
+	val.l &= ~(0x7f << VIA_STRFILT_CNT_SHIFT);
+	val.l &= ~VIA_XSTORE_CNT_MASK;
+	val.l &= ~(VIA_STRFILT_ENABLE | VIA_STRFILT_FAIL | VIA_RAWBITS_ENABLE);
+	val.l |= VIA_RNG_ENABLE;
+	val.l |= VIA_NOISESRC1;
 
 	/* Enable secondary noise source on CPUs where it is present. */
 
 	/* Nehemiah stepping 8 and higher */
 	if ((c->x86_model == 9) && (c->x86_stepping > 7))
-		lo |= VIA_NOISESRC2;
+		val.l |= VIA_NOISESRC2;
 
 	/* Esther */
 	if (c->x86_model >= 10)
-		lo |= VIA_NOISESRC2;
+		val.l |= VIA_NOISESRC2;
 
-	if (lo != old_lo)
-		wrmsr(MSR_VIA_RNG, lo, hi);
+	if (val.l != old_lo)
+		wrmsrq(MSR_VIA_RNG, val.q);
 
 	/* perhaps-unnecessary sanity check; remove after testing if
 	   unneeded */
-	rdmsr(MSR_VIA_RNG, lo, hi);
-	if ((lo & VIA_RNG_ENABLE) == 0) {
+	rdmsrq(MSR_VIA_RNG, val.q);
+	if ((val.l & VIA_RNG_ENABLE) == 0) {
 		pr_err(PFX "cannot enable VIA C3 RNG, aborting\n");
 		return -ENODEV;
 	}
Signature · 1 line
2.54.0
author maintainer
#90 lore raw

PATCH 24/32 drivers/gpio: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/gpio/gpio-cs5535.c | 10 +++++-----
 include/linux/cs5535.h     | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpio/gpio-cs5535.c +5 -5
index 5f5373d86397..a97ec7561889 100644
@@ -143,17 +143,17 @@ EXPORT_SYMBOL_GPL(cs5535_gpio_isset);
 
 int cs5535_gpio_set_irq(unsigned group, unsigned irq)
 {
-	uint32_t lo, hi;
+	struct msr val;
 
 	if (group > 7 || irq > 15)
 		return -EINVAL;
 
-	rdmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
+	rdmsrq(MSR_PIC_ZSEL_HIGH, val.q);
 
-	lo &= ~(0xF << (group * 4));
-	lo |= (irq & 0xF) << (group * 4);
+	val.l &= ~(0xF << (group * 4));
+	val.l |= (irq & 0xF) << (group * 4);
 
-	wrmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
+	wrmsrq(MSR_PIC_ZSEL_HIGH, val.q);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(cs5535_gpio_set_irq);
include/linux/cs5535.h +5 -5
index 2be1120174eb..5ec2aca537bb 100644
@@ -49,12 +49,12 @@
 static inline int cs5535_pic_unreqz_select_high(unsigned int group,
 						unsigned int irq)
 {
-	uint32_t lo, hi;
+	struct msr val;
 
-	rdmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
-	lo &= ~(0xF << (group * 4));
-	lo |= (irq & 0xF) << (group * 4);
-	wrmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
+	rdmsrq(MSR_PIC_ZSEL_HIGH, val.q);
+	val.l &= ~(0xF << (group * 4));
+	val.l |= (irq & 0xF) << (group * 4);
+	wrmsrq(MSR_PIC_ZSEL_HIGH, val.q);
 	return 0;
 }
 
Signature · 1 line
2.54.0
maintainer
#92 lore raw

Re: [PATCH 24/32] drivers/gpio: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

Hi Jürgen,

Quoted 4 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

Is this something the subsystem maintainera are supposed to apply directly on a per-subsystem basis? I was under that impression.

Yours,
Linus Walleij

author maintainer
#93 lore raw

Re: [PATCH 24/32] drivers/gpio: Stop using 32-bit MSR interfaces

Quoted 11 lines · Linus Walleij

Hi Jürgen,

Quoted 4 lines · Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

Is this something the subsystem maintainera are supposed to apply directly on a per-subsystem basis? I was under that impression.

Yes, please do so.

Juergen

author maintainer
#94 lore raw

PATCH 25/32 drivers/misc: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interfaces rdmsr() and wrmsr() are planned to be removed. Use the related 64-bit variants instead.

---
 drivers/misc/cs5535-mfgpt.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)
drivers/misc/cs5535-mfgpt.c +16 -17
index cdd0e7bda68d..9abfc44f70f4 100644
@@ -45,7 +45,8 @@ static struct cs5535_mfgpt_chip {
 int cs5535_mfgpt_toggle_event(struct cs5535_mfgpt_timer *timer, int cmp,
 		int event, int enable)
 {
-	uint32_t msr, mask, value, dummy;
+	uint32_t msr, mask;
+	struct msr val;
 	int shift = (cmp == MFGPT_CMP1) ? 0 : 8;
 
 	if (!timer) {
@@ -82,14 +83,14 @@ int cs5535_mfgpt_toggle_event(struct cs5535_mfgpt_timer *timer, int cmp,
 		return -EIO;
 	}
 
-	rdmsr(msr, value, dummy);
+	rdmsrq(msr, val.q);
 
 	if (enable)
-		value |= mask;
+		val.l |= mask;
 	else
-		value &= ~mask;
+		val.l &= ~mask;
 
-	wrmsr(msr, value, dummy);
+	wrmsrq(msr, val.q);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(cs5535_mfgpt_toggle_event);
@@ -97,7 +98,7 @@ EXPORT_SYMBOL_GPL(cs5535_mfgpt_toggle_event);
 int cs5535_mfgpt_set_irq(struct cs5535_mfgpt_timer *timer, int cmp, int *irq,
 		int enable)
 {
-	uint32_t zsel, lpc, dummy;
+	struct msr zsel, lpc;
 	int shift;
 
 	if (!timer) {
@@ -113,30 +114,31 @@ int cs5535_mfgpt_set_irq(struct cs5535_mfgpt_timer *timer, int cmp, int *irq,
 	 * IRQ of the 1st. This can only happen if forcing an IRQ, calling this
 	 * with *irq==0 is safe. Currently there _are_ no 2 drivers.
 	 */
-	rdmsr(MSR_PIC_ZSEL_LOW, zsel, dummy);
+	rdmsrq(MSR_PIC_ZSEL_LOW, zsel.q);
 	shift = ((cmp == MFGPT_CMP1 ? 0 : 4) + timer->nr % 4) * 4;
-	if (((zsel >> shift) & 0xF) == 2)
+	if (((zsel.l >> shift) & 0xF) == 2)
 		return -EIO;
 
 	/* Choose IRQ: if none supplied, keep IRQ already set or use default */
 	if (!*irq)
-		*irq = (zsel >> shift) & 0xF;
+		*irq = (zsel.l >> shift) & 0xF;
 	if (!*irq)
 		*irq = CONFIG_CS5535_MFGPT_DEFAULT_IRQ;
 
 	/* Can't use IRQ if it's 0 (=disabled), 2, or routed to LPC */
 	if (*irq < 1 || *irq == 2 || *irq > 15)
 		return -EIO;
-	rdmsr(MSR_PIC_IRQM_LPC, lpc, dummy);
-	if (lpc & (1 << *irq))
+	rdmsrq(MSR_PIC_IRQM_LPC, lpc.q);
+	if (lpc.l & (1 << *irq))
 		return -EIO;
 
 	/* All chosen and checked - go for it */
 	if (cs5535_mfgpt_toggle_event(timer, cmp, MFGPT_EVENT_IRQ, enable))
 		return -EIO;
 	if (enable) {
-		zsel = (zsel & ~(0xF << shift)) | (*irq << shift);
-		wrmsr(MSR_PIC_ZSEL_LOW, zsel, dummy);
+		zsel.l = (zsel.l & ~(0xF << shift)) | (*irq << shift);
+		zsel.h = lpc.h;
+		wrmsrq(MSR_PIC_ZSEL_LOW, zsel.q);
 	}
 
 	return 0;
@@ -249,11 +251,8 @@ EXPORT_SYMBOL_GPL(cs5535_mfgpt_write);
  */
 static void reset_all_timers(void)
 {
-	uint32_t val, dummy;
-
 	/* The following undocumented bit resets the MFGPT timers */
-	val = 0xFF; dummy = 0;
-	wrmsr(MSR_MFGPT_SETUP, val, dummy);
+	wrmsrq(MSR_MFGPT_SETUP, 0xff);
 }
 
 /*
Signature · 1 line
2.54.0
author maintainer
#95 lore raw

PATCH 26/32 x86/msr: Remove wrmsr()

In reply to Juergen Gross

wrmsr() has no users left. Delete it.

---
 arch/x86/include/asm/msr.h      | 5 -----
 arch/x86/include/asm/paravirt.h | 5 -----
 2 files changed, 10 deletions(-)
arch/x86/include/asm/msr.h +0 -5
index 776a2daa2ba2..badab5762f3a 100644
@@ -186,11 +186,6 @@ do {								\
 	(void)((high) = (u32)(__val >> 32));			\
 } while (0)
 
-static inline void wrmsr(u32 msr, u32 low, u32 high)
-{
-	native_write_msr(msr, (u64)high << 32 | low);
-}
-
 #define rdmsrq(msr, val)			\
 	((val) = native_read_msr((msr)))
 
arch/x86/include/asm/paravirt.h +0 -5
index 97b082095572..47d4e36d14cb 100644
@@ -157,11 +157,6 @@ do {						\
 	val2 = _l >> 32;			\
 } while (0)
 
-static __always_inline void wrmsr(u32 msr, u32 low, u32 high)
-{
-	paravirt_write_msr(msr, (u64)high << 32 | low);
-}
-
 #define rdmsrq(msr, val)			\
 do {						\
 	val = paravirt_read_msr(msr);		\
Signature · 1 line
2.54.0
author maintainer
#96 lore raw

PATCH 27/32 x86/hyperv: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interface rdmsr() is planned to be removed. Use the related 64-bit variant instead.

---
 arch/x86/hyperv/hv_apic.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
arch/x86/hyperv/hv_apic.c +5 -7
index a8de503def37..95f1782d1e17 100644
@@ -60,17 +60,15 @@ void hv_enable_coco_interrupt(unsigned int cpu, unsigned int vector, bool set)
 
 static u32 hv_apic_read(u32 reg)
 {
-	u32 reg_val, hi;
+	struct msr reg_val;
 
 	switch (reg) {
 	case APIC_EOI:
-		rdmsr(HV_X64_MSR_EOI, reg_val, hi);
-		(void)hi;
-		return reg_val;
+		rdmsrq(HV_X64_MSR_EOI, reg_val.q);
+		return reg_val.l;
 	case APIC_TASKPRI:
-		rdmsr(HV_X64_MSR_TPR, reg_val, hi);
-		(void)hi;
-		return reg_val;
+		rdmsrq(HV_X64_MSR_TPR, reg_val.q);
+		return reg_val.l;
 
 	default:
 		return native_apic_mem_read(reg);
Signature · 1 line
2.54.0
merge bot Applied
#97 lore raw

[tip: x86/msr] x86/hyperv: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     f1b599106414c72695298a70605efc36ea4988cc
Gitweb:        https://git.kernel.org/tip/f1b599106414c72695298a70605efc36ea4988cc
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:18 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 03 Jul 2026 11:33:59 +02:00

x86/hyperv: Stop using 32-bit MSR interfaces

The 32-bit MSR interface rdmsr() is planned to be removed. Use the related 64-bit variant instead.

This conversion also simplifies the code a bit.

---
 arch/x86/hyperv/hv_apic.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
arch/x86/hyperv/hv_apic.c +5 -7
index a8de503..95f1782 100644
@@ -60,17 +60,15 @@ void hv_enable_coco_interrupt(unsigned int cpu, unsigned int vector, bool set)
 
 static u32 hv_apic_read(u32 reg)
 {
-	u32 reg_val, hi;
+	struct msr reg_val;
 
 	switch (reg) {
 	case APIC_EOI:
-		rdmsr(HV_X64_MSR_EOI, reg_val, hi);
-		(void)hi;
-		return reg_val;
+		rdmsrq(HV_X64_MSR_EOI, reg_val.q);
+		return reg_val.l;
 	case APIC_TASKPRI:
-		rdmsr(HV_X64_MSR_TPR, reg_val, hi);
-		(void)hi;
-		return reg_val;
+		rdmsrq(HV_X64_MSR_TPR, reg_val.q);
+		return reg_val.l;
 
 	default:
 		return native_apic_mem_read(reg);
author maintainer
#98 lore raw

PATCH 28/32 x86/olpc: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interface rdmsr() is planned to be removed. Use the related 64-bit variant instead.

---
 arch/x86/platform/olpc/olpc-xo1-sci.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/x86/platform/olpc/olpc-xo1-sci.c +6 -5
index 30751b42d54e..97eb4738d602 100644
@@ -311,12 +311,13 @@ static int xo1_sci_resume(struct platform_device *pdev)
 
 static int setup_sci_interrupt(struct platform_device *pdev)
 {
-	u32 lo, hi;
+	u64 msr;
+	u32 lo;
 	u32 sts;
 	int r;
 
-	rdmsr(0x51400020, lo, hi);
-	sci_irq = (lo >> 20) & 15;
+	rdmsrq(0x51400020, msr);
+	sci_irq = (msr >> 20) & 15;
 
 	if (sci_irq) {
 		dev_info(&pdev->dev, "SCI is mapped to IRQ %d\n", sci_irq);
@@ -324,8 +325,8 @@ static int setup_sci_interrupt(struct platform_device *pdev)
 		/* Zero means masked */
 		dev_info(&pdev->dev, "SCI unmapped. Mapping to IRQ 3\n");
 		sci_irq = 3;
-		lo |= 0x00300000;
-		wrmsrq(0x51400020, lo);
+		msr |= 0x00300000;
+		wrmsrq(0x51400020, msr);
 	}
 
 	/* Select level triggered in PIC */
Signature · 1 line
2.54.0
merge bot Applied
#99 lore raw

[tip: x86/msr] x86/olpc: Stop using 32-bit MSR interfaces

The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     2db442843e4e8ec468842306f7c9a83a595c430f
Gitweb:        https://git.kernel.org/tip/2db442843e4e8ec468842306f7c9a83a595c430f
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:19 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 03 Jul 2026 11:33:59 +02:00

x86/olpc: Stop using 32-bit MSR interfaces

The 32-bit MSR interface rdmsr() is planned to be removed. Use the related 64-bit variant instead.

---
 arch/x86/platform/olpc/olpc-xo1-sci.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/x86/platform/olpc/olpc-xo1-sci.c +6 -5
index 30751b4..97eb473 100644
@@ -311,12 +311,13 @@ static int xo1_sci_resume(struct platform_device *pdev)
 
 static int setup_sci_interrupt(struct platform_device *pdev)
 {
-	u32 lo, hi;
+	u64 msr;
+	u32 lo;
 	u32 sts;
 	int r;
 
-	rdmsr(0x51400020, lo, hi);
-	sci_irq = (lo >> 20) & 15;
+	rdmsrq(0x51400020, msr);
+	sci_irq = (msr >> 20) & 15;
 
 	if (sci_irq) {
 		dev_info(&pdev->dev, "SCI is mapped to IRQ %d\n", sci_irq);
@@ -324,8 +325,8 @@ static int setup_sci_interrupt(struct platform_device *pdev)
 		/* Zero means masked */
 		dev_info(&pdev->dev, "SCI unmapped. Mapping to IRQ 3\n");
 		sci_irq = 3;
-		lo |= 0x00300000;
-		wrmsrq(0x51400020, lo);
+		msr |= 0x00300000;
+		wrmsrq(0x51400020, msr);
 	}
 
 	/* Select level triggered in PIC */
author maintainer
#100 lore raw

PATCH 29/32 hwmon: Stop using 32-bit MSR interfaces

In reply to Juergen Gross

The 32-bit MSR interface rdmsr() is planned to be removed. Use the related 64-bit variant instead.

---
 drivers/hwmon/hwmon-vid.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/hwmon/hwmon-vid.c +6 -5
index 2df4956296ed..dee42c163d92 100644
@@ -237,16 +237,17 @@ static struct vrm_model vrm_models[] = {
  */
 static u8 get_via_model_d_vrm(void)
 {
-	unsigned int vid, brand, __maybe_unused dummy;
+	u64 msr;
+	unsigned int vid, brand;
 	static const char *brands[4] = {
 		"C7-M", "C7", "Eden", "C7-D"
 	};
 
-	rdmsr(0x198, dummy, vid);
-	vid &= 0xff;
+	rdmsrq(0x198, msr);
+	vid = (msr >> 32) & 0xff;
 
-	rdmsr(0x1154, brand, dummy);
-	brand = ((brand >> 4) ^ (brand >> 2)) & 0x03;
+	rdmsrq(0x1154, msr);
+	brand = ((msr >> 4) ^ (msr >> 2)) & 0x03;
 
 	if (vid > 0x3f) {
 		pr_info("Using %d-bit VID table for VIA %s CPU\n",
Signature · 1 line
2.54.0
#101 lore raw

Re: [PATCH 29/32] hwmon: Stop using 32-bit MSR interfaces

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines

The 32-bit MSR interface rdmsr() is planned to be removed. Use the related 64-bit variant instead.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
merge bot Applied
#103 lore raw

[tip: x86/msr] hwmon: Stop using 32-bit MSR interfaces

In reply to Juergen Gross
The following commit has been merged into the x86/msr branch of tip:

The following commit has been merged into the x86/msr branch of tip:

Commit-ID:     cd5102479d29842bc6e730401ec6e53a045a2994
Gitweb:        https://git.kernel.org/tip/cd5102479d29842bc6e730401ec6e53a045a2994
Author:        Juergen Gross <[email protected]>
AuthorDate:    Mon, 29 Jun 2026 08:05:20 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 03 Jul 2026 11:33:59 +02:00

hwmon: Stop using 32-bit MSR interfaces

The 32-bit MSR interface rdmsr() is planned to be removed. Use the related 64-bit variant instead.

---
 drivers/hwmon/hwmon-vid.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/hwmon/hwmon-vid.c +6 -5
index 2df4956..dee42c1 100644
@@ -237,16 +237,17 @@ static struct vrm_model vrm_models[] = {
  */
 static u8 get_via_model_d_vrm(void)
 {
-	unsigned int vid, brand, __maybe_unused dummy;
+	u64 msr;
+	unsigned int vid, brand;
 	static const char *brands[4] = {
 		"C7-M", "C7", "Eden", "C7-D"
 	};
 
-	rdmsr(0x198, dummy, vid);
-	vid &= 0xff;
+	rdmsrq(0x198, msr);
+	vid = (msr >> 32) & 0xff;
 
-	rdmsr(0x1154, brand, dummy);
-	brand = ((brand >> 4) ^ (brand >> 2)) & 0x03;
+	rdmsrq(0x1154, msr);
+	brand = ((msr >> 4) ^ (msr >> 2)) & 0x03;
 
 	if (vid > 0x3f) {
 		pr_info("Using %d-bit VID table for VIA %s CPU\n",
author maintainer
#104 lore raw

PATCH 30/32 x86/msr: Remove rdmsr()

In reply to Juergen Gross

rdmsr() has no users left. Delete it.

---
 arch/x86/include/asm/msr.h      | 7 -------
 arch/x86/include/asm/paravirt.h | 7 -------
 2 files changed, 14 deletions(-)
arch/x86/include/asm/msr.h +0 -7
index badab5762f3a..6d7bab33af71 100644
@@ -179,13 +179,6 @@ static inline u64 native_read_pmc(int counter)
  * pointer indirection), this allows gcc to optimize better
  */
 
-#define rdmsr(msr, low, high)					\
-do {								\
-	u64 __val = native_read_msr((msr));			\
-	(void)((low) = (u32)__val);				\
-	(void)((high) = (u32)(__val >> 32));			\
-} while (0)
-
 #define rdmsrq(msr, val)			\
 	((val) = native_read_msr((msr)))
 
arch/x86/include/asm/paravirt.h +0 -7
index 47d4e36d14cb..93754aa60d5e 100644
@@ -150,13 +150,6 @@ static inline int paravirt_write_msr_safe(u32 msr, u64 val)
 	return PVOP_CALL2(int, pv_ops, cpu.write_msr_safe, msr, val);
 }
 
-#define rdmsr(msr, val1, val2)			\
-do {						\
-	u64 _l = paravirt_read_msr(msr);	\
-	val1 = (u32)_l;				\
-	val2 = _l >> 32;			\
-} while (0)
-
 #define rdmsrq(msr, val)			\
 do {						\
 	val = paravirt_read_msr(msr);		\
Signature · 1 line
2.54.0