Skip to content

Commit 62e1a62

Browse files
imranh2kashyapc
authored andcommitted
[nova/libvirt] Support for checking and enabling SMM when needed
Check the features list we get from the firmware descriptor file to see if we need SMM (requires-smm), if so then enable it as we aren't using the libvirt built in mechanism to enable it when grabbing the right firmware. Closes-Bug: 1958636 Change-Id: I890b3021a29fa546d9e36b21b1111e8537cd0020 Signed-off-by: Imran Hussain <[email protected]> (cherry picked from commit 6ad7890)
1 parent eb021be commit 62e1a62

File tree

7 files changed

+82
-5
lines changed

7 files changed

+82
-5
lines changed

nova/exception.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,10 @@ class SecureBootNotSupported(Invalid):
19201920
msg_fmt = _("Secure Boot is not supported by host")
19211921

19221922

1923+
class FirmwareSMMNotSupported(Invalid):
1924+
msg_fmt = _("This firmware doesn't require (support) SMM")
1925+
1926+
19231927
class TriggerCrashDumpNotSupported(Invalid):
19241928
msg_fmt = _("Triggering crash dump is not supported")
19251929

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5066,6 +5066,44 @@ def test_get_guest_config_with_uefi(self):
50665066
self.assertEqual('/usr/share/OVMF/OVMF_CODE.fd', cfg.os_loader)
50675067
self.assertEqual('/usr/share/OVMF/OVMF_VARS.fd', cfg.os_nvram_template)
50685068

5069+
def test_get_guest_config_with_secure_boot_and_smm_required(self):
5070+
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
5071+
# uefi only used with secure boot
5072+
drvr._host._supports_uefi = True
5073+
# smm only used with secure boot
5074+
drvr._host._supports_secure_boot = True
5075+
5076+
# NOTE(imranh2): Current way of gathering firmwares is inflexible
5077+
# nova/tests/fixtures/libvirt.py FakeLoaders has requires-smm
5078+
# defined. do the following to make sure we get this programtically
5079+
# in the future we should test firmwares that both do and don't
5080+
# require smm but the current way firmware is selected doesn't
5081+
# make it possible to do so.
5082+
loader, nvram_template, requires_smm = drvr._host.get_loader(
5083+
'x86_64', 'q35', True)
5084+
5085+
image_meta = objects.ImageMeta.from_dict({
5086+
'disk_format': 'raw',
5087+
# secure boot requires UEFI
5088+
'properties': {
5089+
'hw_firmware_type': 'uefi',
5090+
'hw_machine_type': 'q35',
5091+
'os_secure_boot': 'required',
5092+
},
5093+
})
5094+
instance_ref = objects.Instance(**self.test_instance)
5095+
5096+
disk_info = blockinfo.get_disk_info(
5097+
CONF.libvirt.virt_type, instance_ref, image_meta)
5098+
5099+
cfg = drvr._get_guest_config(
5100+
instance_ref, [], image_meta, disk_info)
5101+
# if we require it make sure it's there
5102+
if requires_smm:
5103+
self.assertTrue(any(isinstance(feature,
5104+
vconfig.LibvirtConfigGuestFeatureSMM)
5105+
for feature in cfg.features))
5106+
50695107
@ddt.data(True, False)
50705108
def test_get_guest_config_with_secure_boot_required(
50715109
self, host_has_support,

nova/tests/unit/virt/libvirt/test_host.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,14 @@ def fake_get_mtype(arch, machine):
18111811
loader = self.host.get_loader('x86_64', 'q35', has_secure_boot=True)
18121812
self.assertIsNotNone(loader)
18131813

1814+
# check that SMM bool is false as we don't need it
1815+
self.assertFalse(loader[2])
1816+
1817+
# check that we get SMM bool correctly (True) when required
1818+
loaders[0]['features'].append('requires-smm')
1819+
loader = self.host.get_loader('x86_64', 'q35', has_secure_boot=True)
1820+
self.assertTrue(loader[2])
1821+
18141822
# while it should fail here since we don't want it now
18151823
self.assertRaises(
18161824
exception.UEFINotSupported,

nova/virt/libvirt/config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,6 +2687,19 @@ def format_dom(self):
26872687
return root
26882688

26892689

2690+
class LibvirtConfigGuestFeatureSMM(LibvirtConfigGuestFeature):
2691+
2692+
def __init__(self, **kwargs):
2693+
super(LibvirtConfigGuestFeatureSMM, self).__init__("smm", **kwargs)
2694+
2695+
def format_dom(self):
2696+
root = super(LibvirtConfigGuestFeatureSMM, self).format_dom()
2697+
2698+
root.append(etree.Element("smm", state="on"))
2699+
2700+
return root
2701+
2702+
26902703
class LibvirtConfigGuestFeaturePMU(LibvirtConfigGuestFeature):
26912704

26922705
def __init__(self, state, **kwargs):

nova/virt/libvirt/driver.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6283,9 +6283,10 @@ def _configure_guest_by_virt_type(
62836283
guest.os_loader_secure = False
62846284

62856285
try:
6286-
loader, nvram_template = self._host.get_loader(
6286+
loader, nvram_template, requires_smm = (
6287+
self._host.get_loader(
62876288
arch, mach_type,
6288-
has_secure_boot=guest.os_loader_secure)
6289+
has_secure_boot=guest.os_loader_secure))
62896290
except exception.UEFINotSupported as exc:
62906291
if guest.os_loader_secure:
62916292
# we raise a specific exception if we requested secure
@@ -6297,6 +6298,11 @@ def _configure_guest_by_virt_type(
62976298
guest.os_loader_type = 'pflash'
62986299
guest.os_nvram_template = nvram_template
62996300

6301+
# if the feature set says we need SMM then enable it
6302+
if requires_smm:
6303+
guest.features.append(
6304+
vconfig.LibvirtConfigGuestFeatureSMM())
6305+
63006306
# NOTE(lyarwood): If the machine type isn't recorded in the stashed
63016307
# image metadata then record it through the system metadata table.
63026308
# This will allow the host configuration to change in the future

nova/virt/libvirt/host.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,11 +1642,11 @@ def get_loader(
16421642
arch: str,
16431643
machine: str,
16441644
has_secure_boot: bool,
1645-
) -> ty.Tuple[str, str]:
1645+
) -> ty.Tuple[str, str, bool]:
16461646
"""Get loader for the specified architecture and machine type.
16471647
1648-
:returns: A tuple of the bootloader executable path and the NVRAM
1649-
template path.
1648+
:returns: A the bootloader executable path and the NVRAM
1649+
template path and a bool indicating if we need to enable SMM.
16501650
"""
16511651

16521652
machine = self.get_canonical_machine_type(arch, machine)
@@ -1676,6 +1676,7 @@ def get_loader(
16761676
return (
16771677
loader['mapping']['executable']['filename'],
16781678
loader['mapping']['nvram-template']['filename'],
1679+
'requires-smm' in loader['features'],
16791680
)
16801681

16811682
raise exception.UEFINotSupported()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
[`bug 1958636 <https://bugs.launchpad.net/nova/+bug/1958636>`_]
5+
Explicitly check for and enable SMM when firmware requires it.
6+
Previously we assumed libvirt would do this for us but this is
7+
not true in all cases.

0 commit comments

Comments
 (0)