Skip to content

Commit f47239f

Browse files
berrangelnykryn
authored andcommitted
confidential-virt: add detection for s390x target
The s390x platform provides confidential VMs using the "Secure Execution" technology, which is also referred to as "Protected Virtualization" or just "prot virt" in Linux / QEMU. This can be detected through a simple sysfs attribute. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> (cherry picked from commit 6c35e0a51cc6a852ce239ea46cd75c133212a68e) Related: RHEL-50651
1 parent 59055cd commit f47239f

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/basic/confidential-virt.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "confidential-virt.h"
1313
#include "fd-util.h"
14+
#include "fileio.h"
1415
#include "missing_threads.h"
1516
#include "string-table.h"
1617
#include "utf8.h"
@@ -269,6 +270,24 @@ static ConfidentialVirtualization detect_confidential_virtualization_impl(void)
269270

270271
return CONFIDENTIAL_VIRTUALIZATION_NONE;
271272
}
273+
#elif defined(__s390x__)
274+
static ConfidentialVirtualization detect_confidential_virtualization_impl(void) {
275+
_cleanup_free_ char *s = NULL;
276+
size_t readsize;
277+
int r;
278+
279+
r = read_full_virtual_file("/sys/firmware/uv/prot_virt_guest", &s, &readsize);
280+
if (r < 0) {
281+
log_debug_errno(r, "Unable to read /sys/firmware/uv/prot_virt_guest: %m");
282+
return CONFIDENTIAL_VIRTUALIZATION_NONE;
283+
}
284+
285+
if (readsize >= 1 && s[0] == '1')
286+
return CONFIDENTIAL_VIRTUALIZATION_PROTVIRT;
287+
288+
return CONFIDENTIAL_VIRTUALIZATION_NONE;
289+
}
290+
272291
#else /* ! x86_64 */
273292
static ConfidentialVirtualization detect_confidential_virtualization_impl(void) {
274293
log_debug("No confidential virtualization detection on this architecture");
@@ -286,11 +305,12 @@ ConfidentialVirtualization detect_confidential_virtualization(void) {
286305
}
287306

288307
static const char *const confidential_virtualization_table[_CONFIDENTIAL_VIRTUALIZATION_MAX] = {
289-
[CONFIDENTIAL_VIRTUALIZATION_NONE] = "none",
290-
[CONFIDENTIAL_VIRTUALIZATION_SEV] = "sev",
291-
[CONFIDENTIAL_VIRTUALIZATION_SEV_ES] = "sev-es",
292-
[CONFIDENTIAL_VIRTUALIZATION_SEV_SNP] = "sev-snp",
293-
[CONFIDENTIAL_VIRTUALIZATION_TDX] = "tdx",
308+
[CONFIDENTIAL_VIRTUALIZATION_NONE] = "none",
309+
[CONFIDENTIAL_VIRTUALIZATION_SEV] = "sev",
310+
[CONFIDENTIAL_VIRTUALIZATION_SEV_ES] = "sev-es",
311+
[CONFIDENTIAL_VIRTUALIZATION_SEV_SNP] = "sev-snp",
312+
[CONFIDENTIAL_VIRTUALIZATION_TDX] = "tdx",
313+
[CONFIDENTIAL_VIRTUALIZATION_PROTVIRT] = "protvirt",
294314
};
295315

296316
DEFINE_STRING_TABLE_LOOKUP(confidential_virtualization, ConfidentialVirtualization);

src/basic/confidential-virt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ typedef enum ConfidentialVirtualization {
1313
CONFIDENTIAL_VIRTUALIZATION_SEV_ES,
1414
CONFIDENTIAL_VIRTUALIZATION_SEV_SNP,
1515
CONFIDENTIAL_VIRTUALIZATION_TDX,
16+
CONFIDENTIAL_VIRTUALIZATION_PROTVIRT,
1617

1718
_CONFIDENTIAL_VIRTUALIZATION_MAX,
1819
_CONFIDENTIAL_VIRTUALIZATION_INVALID = -EINVAL,

0 commit comments

Comments
 (0)