Skip to contentSkip to conversation

fw/msr_feature_control: add support to set MSR_IA32_FEATURE_CONTROL

PATCH Superseded Haozhong Zhang 2 participants 4 messages Jun 16, 2016 – Jun 17, 2016 Kbuild

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fw/msr_feature_control: add support to set MSR_IA32_FEATURE_CONTROL

OS usually expects BIOS to set certain bits in MSR_IA32_FEATURE_CONTROL for some features (e.g. VMX and LMCE). QEMU provides a fw_cfg file "etc/msr_feature_control" to advise bits that should be set in MSR_IA32_FEATURE_CONTROL. If this file exists, SeaBIOS will set the advised bits in that MSR.

---
QEMU patch added fw_cfg file etc/msr_feature_control can be found at [1]. Note I mistakenly used u32 as the type of file content in that patch, which should be u64 and will be fixed.

[1] https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg04389.html

---
 Makefile                     |  2 +-
 src/fw/msr_feature_control.c | 16 ++++++++++++++++
 src/fw/paravirt.c            |  3 +++
 src/fw/smp.c                 |  6 +++++-
 src/util.h                   |  5 +++++
 5 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 src/fw/msr_feature_control.c
Makefile +1 -1
index 4930b3a..f38a075 100644
@@ -43,7 +43,7 @@ SRC32FLAT=$(SRCBOTH) post.c e820map.c malloc.c romfile.c x86.c optionroms.c \
     fw/paravirt.c fw/shadow.c fw/pciinit.c fw/smm.c fw/smp.c fw/mtrr.c fw/xen.c \
     fw/acpi.c fw/mptable.c fw/pirtable.c fw/smbios.c fw/romfile_loader.c \
     hw/virtio-ring.c hw/virtio-pci.c hw/virtio-blk.c hw/virtio-scsi.c \
-    hw/tpm_drivers.c
+    hw/tpm_drivers.c fw/msr_feature_control.c
 SRC32SEG=string.c output.c pcibios.c apm.c stacks.c hw/pci.c hw/serialio.c
 DIRS=src src/hw src/fw vgasrc
 
src/fw/msr_feature_control.c new file +16 -0
new file mode 100644
index 0000000..35d4ab8
@@ -0,0 +1,16 @@
+#include "util.h" // msr_feature_control_setup
+#include "x86.h" // wrmsr
+#include "romfile.h" // romfile_find
+
+u64 feature_control_bits;
+
+void msr_feature_control_setup(void)
+{
+    struct romfile_s *f = romfile_find("etc/msr_feature_control");
+    if (!f)
+        return;
+
+    f->copy(f, &feature_control_bits, sizeof(feature_control_bits));
+    if (feature_control_bits)
+        wrmsr(MSR_IA32_FEATURE_CONTROL, feature_control_bits);
+}
src/fw/paravirt.c +3 -0
index 8ed4380..640ee4c 100644
@@ -153,6 +153,9 @@ qemu_platform_setup(void)
     mtrr_setup();
     smp_setup();
 
+    // Initialize MSR_IA32_FEATURE_CONTROL
+    msr_feature_control_setup();
+
     // Create bios tables
     pirtable_setup();
     mptable_setup();
src/fw/smp.c +5 -1
index 579acdb..8b57bf4 100644
@@ -10,7 +10,7 @@
 #include "output.h" // dprintf
 #include "romfile.h" // romfile_loadint
 #include "stacks.h" // yield
-#include "util.h" // smp_setup
+#include "util.h" // smp_setup, msr_feature_control_setup
 #include "x86.h" // wrmsr
 
 #define APIC_ICR_LOW ((u8*)BUILD_APIC_ADDR + 0x300)
@@ -63,6 +63,10 @@ handle_smp(void)
     for (i=0; i<smp_mtrr_count; i++)
         wrmsr(smp_mtrr[i].index, smp_mtrr[i].val);
 
+    // MSR_IA32_FEATURE_CONTROL setup
+    if (feature_control_bits)
+        wrmsr(MSR_IA32_FEATURE_CONTROL, feature_control_bits);
+
     // Set bit on FoundAPICIDs
     FoundAPICIDs[apic_id/32] |= (1 << (apic_id % 32));
 
src/util.h +5 -0
index 7b41207..fc8e59d 100644
@@ -103,6 +103,11 @@ int csm_bootprio_pci(struct pci_device *pci);
 // fw/mptable.c
 void mptable_setup(void);
 
+// fw/msr_feature_control.c
+#define MSR_IA32_FEATURE_CONTROL 0x0000003a
+extern u64 feature_control_bits;
+void msr_feature_control_setup(void);
+
 // fw/mtrr.c
 void mtrr_setup(void);
 
Signature · 1 line
2.9.0
#1 lore raw
Quoted 5 lines · Haozhong Zhang
src/fw/paravirt.c +0 -0
index 8ed4380..640ee4c 100644

src/fw/paravirt.c qemu_platform_setup(void) · line 161

Quoted 9 lines
src/fw/paravirt.c +3 -0
@@ -153,6 +153,9 @@ qemu_platform_setup(void)
     mtrr_setup();
     smp_setup();
 
+    // Initialize MSR_IA32_FEATURE_CONTROL
+    msr_feature_control_setup();
+
     // Create bios tables
     pirtable_setup();
     mptable_setup();

This must run before smp_setup(), because it is smp_setup() that calls handle_smp() on the APs.

Quoted 11 lines
src/fw/msr_feature_control.c new file +5 -0
new file mode 100644
index 0000000..35d4ab8
@@ -0,0 +1,16 @@
+#include "util.h" // msr_feature_control_setup
+#include "x86.h" // wrmsr
+#include "romfile.h" // romfile_find
+
+u64 feature_control_bits;

src/fw/msr_feature_control.c line 15

Quoted 10 lines
src/fw/msr_feature_control.c new file +10 -0
+
+void msr_feature_control_setup(void)
+{
+    struct romfile_s *f = romfile_find("etc/msr_feature_control");
+    if (!f)
+        return;
+
+    f->copy(f, &feature_control_bits, sizeof(feature_control_bits));
+    if (feature_control_bits)
+        wrmsr(MSR_IA32_FEATURE_CONTROL, feature_control_bits);

You can use wrmsr_smp and avoid the change below to handle_smp(). It also removes the need for the feature_control_bits global variable.

Thanks,

Paolo

Quoted 56 lines
src/fw/msr_feature_control.c new file +1 -0
+}
src/fw/paravirt.c +3 -0
index 8ed4380..640ee4c 100644
@@ -153,6 +153,9 @@ qemu_platform_setup(void)
     mtrr_setup();
     smp_setup();
 
+    // Initialize MSR_IA32_FEATURE_CONTROL
+    msr_feature_control_setup();
+
     // Create bios tables
     pirtable_setup();
     mptable_setup();
src/fw/smp.c +5 -1
index 579acdb..8b57bf4 100644
@@ -10,7 +10,7 @@
 #include "output.h" // dprintf
 #include "romfile.h" // romfile_loadint
 #include "stacks.h" // yield
-#include "util.h" // smp_setup
+#include "util.h" // smp_setup, msr_feature_control_setup
 #include "x86.h" // wrmsr
 
 #define APIC_ICR_LOW ((u8*)BUILD_APIC_ADDR + 0x300)
@@ -63,6 +63,10 @@ handle_smp(void)
     for (i=0; i<smp_mtrr_count; i++)
         wrmsr(smp_mtrr[i].index, smp_mtrr[i].val);
 
+    // MSR_IA32_FEATURE_CONTROL setup
+    if (feature_control_bits)
+        wrmsr(MSR_IA32_FEATURE_CONTROL, feature_control_bits);
+
     // Set bit on FoundAPICIDs
     FoundAPICIDs[apic_id/32] |= (1 << (apic_id % 32));
 
src/util.h +5 -0
index 7b41207..fc8e59d 100644
@@ -103,6 +103,11 @@ int csm_bootprio_pci(struct pci_device *pci);
 // fw/mptable.c
 void mptable_setup(void);
 
+// fw/msr_feature_control.c
+#define MSR_IA32_FEATURE_CONTROL 0x0000003a
+extern u64 feature_control_bits;
+void msr_feature_control_setup(void);
+
 // fw/mtrr.c
 void mtrr_setup(void);
 
#2 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 8 lines · Haozhong Zhang
src/fw/paravirt.c +0 -0
index 8ed4380..640ee4c 100644
@@ -153,6 +153,9 @@ qemu_platform_setup(void)
     mtrr_setup();
     smp_setup();
 
Quoted 10 lines

src/fw/paravirt.c qemu_platform_setup(void) · line 161

Quoted 6 lines
src/fw/paravirt.c +3 -0
+    // Initialize MSR_IA32_FEATURE_CONTROL
+    msr_feature_control_setup();
+
     // Create bios tables
     pirtable_setup();
     mptable_setup();

This must run before smp_setup(), because it is smp_setup() that calls handle_smp() on the APs.

I'll move it before smp_setup().

Quoted 16 lines
Quoted 16 lines
src/fw/msr_feature_control.c new file +10 -0
new file mode 100644
index 0000000..35d4ab8
@@ -0,0 +1,16 @@
+#include "util.h" // msr_feature_control_setup
+#include "x86.h" // wrmsr
+#include "romfile.h" // romfile_find
+
+u64 feature_control_bits;
+
+void msr_feature_control_setup(void)
+{
+    struct romfile_s *f = romfile_find("etc/msr_feature_control");
+    if (!f)
Quoted 9 lines

src/fw/msr_feature_control.c line 15

Quoted 5 lines
src/fw/msr_feature_control.c new file +5 -0
+        return;
+
+    f->copy(f, &feature_control_bits, sizeof(feature_control_bits));
+    if (feature_control_bits)
+        wrmsr(MSR_IA32_FEATURE_CONTROL, feature_control_bits);

You can use wrmsr_smp and avoid the change below to handle_smp(). It also removes the need for the feature_control_bits global variable.

Good idea. I think I should also rename smp_mtrr and smp_mtrr_count to something like smp_msr and smp_msr_count, because they will not be used only for MTRR.

Thanks,
Haozhong

#3 lore raw
Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
src/fw/msr_feature_control.c new file +10 -0
new file mode 100644
index 0000000..35d4ab8
@@ -0,0 +1,16 @@
+#include "util.h" // msr_feature_control_setup
+#include "x86.h" // wrmsr
+#include "romfile.h" // romfile_find
+
+u64 feature_control_bits;
+
+void msr_feature_control_setup(void)
+{
+    struct romfile_s *f = romfile_find("etc/msr_feature_control");
+    if (!f)
Quoted 9 lines

src/fw/msr_feature_control.c line 15

Quoted 5 lines
src/fw/msr_feature_control.c new file +5 -0
+        return;
+
+    f->copy(f, &feature_control_bits, sizeof(feature_control_bits));
+    if (feature_control_bits)
+        wrmsr(MSR_IA32_FEATURE_CONTROL, feature_control_bits);

You can use wrmsr_smp and avoid the change below to handle_smp(). It also removes the need for the feature_control_bits global variable.

Quoted 3 lines

Good idea. I think I should also rename smp_mtrr and smp_mtrr_count to something like smp_msr and smp_msr_count, because they will not be used only for MTRR.

Yes, pleaase do!

Thanks,

Paolo