Skip to content

Commit 1aa9e0d

Browse files
committed
Accept both 1 and Y as AMD SEV KVM kernel param value
The libvirt virt dirver checks the AMD KVM kernel module parameter SEV to see if that feature is enabled. However it seems that the /sys/module/kvm_amd/parameters/sev file can either contain "1\n" or "Y\n" to indicate that the feature is enabled. Nova only checked for "1\n" so far making the feature disabled on compute nodes with "Y\n" value. Now the logic is extended to accept both. Closes-Bug: #1975686 Change-Id: I737e1d73242430b6756178eb0bf9bd6ec5c94160 (cherry picked from commit ab51a5d) (cherry picked from commit 8a1b497)
1 parent 90c5190 commit 1aa9e0d

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import os
1818

19+
import ddt
1920
import eventlet
2021
from eventlet import greenthread
2122
from eventlet import tpool
@@ -1831,26 +1832,34 @@ def setUp(self):
18311832
self.host = host.Host("qemu:///system")
18321833

18331834

1835+
@ddt.ddt
18341836
class TestLibvirtSEVUnsupported(TestLibvirtSEV):
18351837
@mock.patch.object(os.path, 'exists', return_value=False)
18361838
def test_kernel_parameter_missing(self, fake_exists):
18371839
self.assertFalse(self.host._kernel_supports_amd_sev())
18381840
fake_exists.assert_called_once_with(
18391841
'/sys/module/kvm_amd/parameters/sev')
18401842

1843+
@ddt.data(
1844+
('0\n', False),
1845+
('N\n', False),
1846+
('1\n', True),
1847+
('Y\n', True),
1848+
)
1849+
@ddt.unpack
18411850
@mock.patch.object(os.path, 'exists', return_value=True)
1842-
@mock.patch('builtins.open', mock.mock_open(read_data="0\n"))
1843-
def test_kernel_parameter_zero(self, fake_exists):
1844-
self.assertFalse(self.host._kernel_supports_amd_sev())
1845-
fake_exists.assert_called_once_with(
1846-
'/sys/module/kvm_amd/parameters/sev')
1847-
1848-
@mock.patch.object(os.path, 'exists', return_value=True)
1849-
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
1850-
def test_kernel_parameter_one(self, fake_exists):
1851-
self.assertTrue(self.host._kernel_supports_amd_sev())
1852-
fake_exists.assert_called_once_with(
1853-
'/sys/module/kvm_amd/parameters/sev')
1851+
def test_kernel_parameter(
1852+
self, sev_param_value, expected_support, mock_exists
1853+
):
1854+
with mock.patch(
1855+
'builtins.open', mock.mock_open(read_data=sev_param_value)
1856+
):
1857+
self.assertIs(
1858+
expected_support,
1859+
self.host._kernel_supports_amd_sev()
1860+
)
1861+
mock_exists.assert_called_once_with(
1862+
'/sys/module/kvm_amd/parameters/sev')
18541863

18551864
@mock.patch.object(os.path, 'exists', return_value=True)
18561865
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))

nova/virt/libvirt/host.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from oslo_serialization import jsonutils
4747
from oslo_utils import excutils
4848
from oslo_utils import importutils
49+
from oslo_utils import strutils
4950
from oslo_utils import units
5051
from oslo_utils import versionutils
5152

@@ -1570,9 +1571,9 @@ def _kernel_supports_amd_sev(self) -> bool:
15701571
return False
15711572

15721573
with open(SEV_KERNEL_PARAM_FILE) as f:
1573-
contents = f.read()
1574-
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, contents)
1575-
return contents == "1\n"
1574+
content = f.read()
1575+
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, content)
1576+
return strutils.bool_from_string(content)
15761577

15771578
@property
15781579
def supports_amd_sev(self) -> bool:

0 commit comments

Comments
 (0)