Skip to content

Commit af650eb

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) (cherry picked from commit 1aa9e0d)
1 parent baf0d93 commit af650eb

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
@@ -1813,26 +1814,34 @@ def setUp(self):
18131814
self.host = host.Host("qemu:///system")
18141815

18151816

1817+
@ddt.ddt
18161818
class TestLibvirtSEVUnsupported(TestLibvirtSEV):
18171819
@mock.patch.object(os.path, 'exists', return_value=False)
18181820
def test_kernel_parameter_missing(self, fake_exists):
18191821
self.assertFalse(self.host._kernel_supports_amd_sev())
18201822
fake_exists.assert_called_once_with(
18211823
'/sys/module/kvm_amd/parameters/sev')
18221824

1825+
@ddt.data(
1826+
('0\n', False),
1827+
('N\n', False),
1828+
('1\n', True),
1829+
('Y\n', True),
1830+
)
1831+
@ddt.unpack
18231832
@mock.patch.object(os.path, 'exists', return_value=True)
1824-
@mock.patch('builtins.open', mock.mock_open(read_data="0\n"))
1825-
def test_kernel_parameter_zero(self, fake_exists):
1826-
self.assertFalse(self.host._kernel_supports_amd_sev())
1827-
fake_exists.assert_called_once_with(
1828-
'/sys/module/kvm_amd/parameters/sev')
1829-
1830-
@mock.patch.object(os.path, 'exists', return_value=True)
1831-
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
1832-
def test_kernel_parameter_one(self, fake_exists):
1833-
self.assertTrue(self.host._kernel_supports_amd_sev())
1834-
fake_exists.assert_called_once_with(
1835-
'/sys/module/kvm_amd/parameters/sev')
1833+
def test_kernel_parameter(
1834+
self, sev_param_value, expected_support, mock_exists
1835+
):
1836+
with mock.patch(
1837+
'builtins.open', mock.mock_open(read_data=sev_param_value)
1838+
):
1839+
self.assertIs(
1840+
expected_support,
1841+
self.host._kernel_supports_amd_sev()
1842+
)
1843+
mock_exists.assert_called_once_with(
1844+
'/sys/module/kvm_amd/parameters/sev')
18361845

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

@@ -1553,9 +1554,9 @@ def _kernel_supports_amd_sev(self) -> bool:
15531554
return False
15541555

15551556
with open(SEV_KERNEL_PARAM_FILE) as f:
1556-
contents = f.read()
1557-
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, contents)
1558-
return contents == "1\n"
1557+
content = f.read()
1558+
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, content)
1559+
return strutils.bool_from_string(content)
15591560

15601561
@property
15611562
def supports_amd_sev(self) -> bool:

0 commit comments

Comments
 (0)