Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp948461ybb; Fri, 20 Mar 2020 10:43:19 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu0zCcytspOONrU8iebY843yrkFIXx5rcMk35MRL1qQWSNyANGM/44QHsLlmqYRGbZIntDc X-Received: by 2002:aca:ec49:: with SMTP id k70mr7661821oih.80.1584726199755; Fri, 20 Mar 2020 10:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584726199; cv=none; d=google.com; s=arc-20160816; b=z+0eQxqklvdpNgCC/GmuogQpGvgY5VIDadf+vDxZPMtxEwyqlakSNzUpGSZfslMGDl gpHKktvYS0xc3ngdoeUj0Wa5lhOPfHc9bXHAxwNuv9pnCA4JPZItAH07cpfJ1ZJ/jMuv 2OrS3Yct/WHMedGng89n1YiLpjrEg+aqNasBhx28bWNvQx+1CHT1ux/dB/FWyPDSLUeH lvNxcw8nWRAPncHp5rRUzFFK+wVTgZIaD49IpKxRTBOY437I0EA3wpt04qjm03PwKbo5 7xQq3QSBKP8CEcOv9MY6Nqzb3oXd5ZMIekmgCwjudKUDkpljmoQ8j0DtL03M6zKct6kn l3/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=ef36637kDnXkE6FllS0yNPka1X9FChEYgiakf6+7Z7c=; b=rae3fqjNqBpKDatnknhAVAxN0poWtZPovhne9GvNiJuBkeEp4x5EV6bVlyS0R0+LwX FSMir4GZB6f/7xT2y6OH4i9TgZyjy5BPo0s+qfkVjesFyEfAQu719xU9E98CXTLKLIsu ZI0RNGBGoybC+EVCQ5aVzq1shsZjMeJEs8N4v6lttv1vFtPqIws8gXh3mstnfiy39zxP bSWvHKXwvCTq7DgY7HF5gqz6zwrvg9LB7EEMDv7VrV/w5KuUOwAAMPuNXdiCv3+47zbA LAyEdELTuc8kNHzEA6idG4KNzgX1Ttz438mfQqJEbc1ijDrlUmHwh/R03vx86re5Y49b qzZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EXteLxpI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d63si3253318oib.224.2020.03.20.10.43.07; Fri, 20 Mar 2020 10:43:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EXteLxpI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727023AbgCTRmu (ORCPT + 99 others); Fri, 20 Mar 2020 13:42:50 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:51336 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726829AbgCTRmu (ORCPT ); Fri, 20 Mar 2020 13:42:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584726169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=ef36637kDnXkE6FllS0yNPka1X9FChEYgiakf6+7Z7c=; b=EXteLxpIPtvpvuZEpCDVmeV2uOacj9OqidEjQBwSo0KCmWWQ8kt2vqFUnpSZGwDt0yEMd3 IRCpOHiMq2I+M9RalrsJjo1bcIAnPTyQ9bP3KfBYw0td4tJtvxq6TSJhqqMLl4iElLatZD 5fLn436FeLEV6dUcK5301FNIwD8T+uE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-JCGm1F3lNn-DLjAE_M3WPg-1; Fri, 20 Mar 2020 13:42:47 -0400 X-MC-Unique: JCGm1F3lNn-DLjAE_M3WPg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97C389B823; Fri, 20 Mar 2020 17:42:46 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3932D19757; Fri, 20 Mar 2020 17:42:46 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Brijesh Singh Subject: [PATCH] KVM: SVM: document KVM_MEM_ENCRYPT_OP, let userspace detect if SEV is available Date: Fri, 20 Mar 2020 13:42:45 -0400 Message-Id: <20200320174245.5220-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Paolo Bonzini --- .../virt/kvm/amd-memory-encryption.rst | 25 +++++++++++++++++++ arch/x86/kvm/svm.c | 3 +++ 2 files changed, 28 insertions(+) diff --git a/Documentation/virt/kvm/amd-memory-encryption.rst b/Documentation/virt/kvm/amd-memory-encryption.rst index d18c97b4e140..c3129b9ba5cb 100644 --- a/Documentation/virt/kvm/amd-memory-encryption.rst +++ b/Documentation/virt/kvm/amd-memory-encryption.rst @@ -53,6 +53,29 @@ key management interface to perform common hypervisor activities such as encrypting bootstrap code, snapshot, migrating and debugging the guest. For more information, see the SEV Key Management spec [api-spec]_ +The main ioctl to access SEV is KVM_MEM_ENCRYPT_OP. If the argument +to KVM_MEM_ENCRYPT_OP is NULL, the ioctl returns 0 if SEV is enabled +and ``ENOTTY` if it is disabled (on some older versions of Linux, +the ioctl runs normally even with a NULL argument, and therefore will +likely return ``EFAULT``). If non-NULL, the argument to KVM_MEM_ENCRYPT_OP +must be a struct kvm_sev_cmd:: + + struct kvm_sev_cmd { + __u32 id; + __u64 data; + __u32 error; + __u32 sev_fd; + }; + + +The ``id`` field contains the subcommand, and the ``data`` field points to +another struct containing arguments specific to command. The ``sev_fd`` +should point to a file descriptor that is opened on the ``/dev/sev`` +device, if needed (see individual commands). + +On output, ``error`` is zero on success, or an error code. Error codes +are defined in ```. + KVM implements the following commands to support common lifecycle events of SEV guests, such as launching, running, snapshotting, migrating and decommissioning. @@ -90,6 +113,8 @@ Returns: 0 on success, -negative on error On success, the 'handle' field contains a new handle and on error, a negative value. +KVM_SEV_LAUNCH_START requires the ``sev_fd`` field to be valid. + For more details, see SEV spec Section 6.2. 3. KVM_SEV_LAUNCH_UPDATE_DATA diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 91000501756e..f0aa9ff9666f 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -7158,6 +7158,9 @@ static int svm_mem_enc_op(struct kvm *kvm, void __user *argp) if (!svm_sev_enabled()) return -ENOTTY; + if (!argp) + return 0; + if (copy_from_user(&sev_cmd, argp, sizeof(struct kvm_sev_cmd))) return -EFAULT; -- 2.18.2