Skip to content

Commit 8a1b497

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)
1 parent 52f4e37 commit 8a1b497

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
@@ -1928,26 +1929,34 @@ def setUp(self):
19281929
self.host = host.Host("qemu:///system")
19291930

19301931

1932+
@ddt.ddt
19311933
class TestLibvirtSEVUnsupported(TestLibvirtSEV):
19321934
@mock.patch.object(os.path, 'exists', return_value=False)
19331935
def test_kernel_parameter_missing(self, fake_exists):
19341936
self.assertFalse(self.host._kernel_supports_amd_sev())
19351937
fake_exists.assert_called_once_with(
19361938
'/sys/module/kvm_amd/parameters/sev')
19371939

1940+
@ddt.data(
1941+
('0\n', False),
1942+
('N\n', False),
1943+
('1\n', True),
1944+
('Y\n', True),
1945+
)
1946+
@ddt.unpack
19381947
@mock.patch.object(os.path, 'exists', return_value=True)
1939-
@mock.patch('builtins.open', mock.mock_open(read_data="0\n"))
1940-
def test_kernel_parameter_zero(self, fake_exists):
1941-
self.assertFalse(self.host._kernel_supports_amd_sev())
1942-
fake_exists.assert_called_once_with(
1943-
'/sys/module/kvm_amd/parameters/sev')
1944-
1945-
@mock.patch.object(os.path, 'exists', return_value=True)
1946-
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
1947-
def test_kernel_parameter_one(self, fake_exists):
1948-
self.assertTrue(self.host._kernel_supports_amd_sev())
1949-
fake_exists.assert_called_once_with(
1950-
'/sys/module/kvm_amd/parameters/sev')
1948+
def test_kernel_parameter(
1949+
self, sev_param_value, expected_support, mock_exists
1950+
):
1951+
with mock.patch(
1952+
'builtins.open', mock.mock_open(read_data=sev_param_value)
1953+
):
1954+
self.assertIs(
1955+
expected_support,
1956+
self.host._kernel_supports_amd_sev()
1957+
)
1958+
mock_exists.assert_called_once_with(
1959+
'/sys/module/kvm_amd/parameters/sev')
19511960

19521961
@mock.patch.object(os.path, 'exists', return_value=True)
19531962
@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

@@ -1656,9 +1657,9 @@ def _kernel_supports_amd_sev(self) -> bool:
16561657
return False
16571658

16581659
with open(SEV_KERNEL_PARAM_FILE) as f:
1659-
contents = f.read()
1660-
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, contents)
1661-
return contents == "1\n"
1660+
content = f.read()
1661+
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, content)
1662+
return strutils.bool_from_string(content)
16621663

16631664
@property
16641665
def supports_amd_sev(self) -> bool:

0 commit comments

Comments
 (0)