Skip to content

Commit 2da1ed6

Browse files
committed
KVM: SVM: document KVM_MEM_ENCRYPT_OP, let userspace detect if SEV is available
Userspace has no way to query if SEV has been disabled with the sev module parameter of kvm-amd.ko. Actually it has one, but it is a hack: do ioctl(KVM_MEM_ENCRYPT_OP, NULL) and check if it returns EFAULT. Make it a little nicer by returning zero for SEV enabled and NULL argument, and while at it document the ioctl arguments. Cc: Brijesh Singh <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent d332945 commit 2da1ed6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Documentation/virt/kvm/amd-memory-encryption.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ key management interface to perform common hypervisor activities such as
5353
encrypting bootstrap code, snapshot, migrating and debugging the guest. For more
5454
information, see the SEV Key Management spec [api-spec]_
5555

56+
The main ioctl to access SEV is KVM_MEM_ENCRYPT_OP. If the argument
57+
to KVM_MEM_ENCRYPT_OP is NULL, the ioctl returns 0 if SEV is enabled
58+
and ``ENOTTY` if it is disabled (on some older versions of Linux,
59+
the ioctl runs normally even with a NULL argument, and therefore will
60+
likely return ``EFAULT``). If non-NULL, the argument to KVM_MEM_ENCRYPT_OP
61+
must be a struct kvm_sev_cmd::
62+
63+
struct kvm_sev_cmd {
64+
__u32 id;
65+
__u64 data;
66+
__u32 error;
67+
__u32 sev_fd;
68+
};
69+
70+
71+
The ``id`` field contains the subcommand, and the ``data`` field points to
72+
another struct containing arguments specific to command. The ``sev_fd``
73+
should point to a file descriptor that is opened on the ``/dev/sev``
74+
device, if needed (see individual commands).
75+
76+
On output, ``error`` is zero on success, or an error code. Error codes
77+
are defined in ``<linux/psp-dev.h>`.
78+
5679
KVM implements the following commands to support common lifecycle events of SEV
5780
guests, such as launching, running, snapshotting, migrating and decommissioning.
5881
@@ -90,6 +113,8 @@ Returns: 0 on success, -negative on error
90113
91114
On success, the 'handle' field contains a new handle and on error, a negative value.
92115
116+
KVM_SEV_LAUNCH_START requires the ``sev_fd`` field to be valid.
117+
93118
For more details, see SEV spec Section 6.2.
94119

95120
3. KVM_SEV_LAUNCH_UPDATE_DATA

arch/x86/kvm/svm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7158,6 +7158,9 @@ static int svm_mem_enc_op(struct kvm *kvm, void __user *argp)
71587158
if (!svm_sev_enabled())
71597159
return -ENOTTY;
71607160

7161+
if (!argp)
7162+
return 0;
7163+
71617164
if (copy_from_user(&sev_cmd, argp, sizeof(struct kvm_sev_cmd)))
71627165
return -EFAULT;
71637166

0 commit comments

Comments
 (0)