Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3959123pxb; Mon, 4 Oct 2021 13:42:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL7E4j/5luH4oB6d2sol1GyCefb3Xx9vN1vStC/pZ2DIbAa5g8mkGy4SMQlvJjTRlH29Ko X-Received: by 2002:a05:6402:5186:: with SMTP id q6mr21160725edd.64.1633380167475; Mon, 04 Oct 2021 13:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633380167; cv=none; d=google.com; s=arc-20160816; b=XhZ8ijYh1dRDF0JavvYIiKVfZ/XW1ARowkqB3npejE5mLWoORyrB/rmATKAArJffGW PUhYFGkT3AOCjCJO7r8Ws1NwtsS1f7VJkpiTSxAzfBKNFa/jFjjKaVQ8NRCsnHxB630/ YN/bydESTJAC+Jm+smD2AqzJnYJ+3BoX1JTu9sqGKn/DMMv5vOkKqBdUtWw1fnm0Kxk0 kFxZK7LQ/iNm3kFbzVmFU7S9EsVbcIVAuUzqLy7IfdWlri9kuuaJyxN9qNye5Q8nMi1f 94Tm9nyLGBToqHEYlXi7+F6sRKCFeWi1SgZTcZu6cvNHsfVUgerl3OVc0pzaWyoXgvb5 C2dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Fy/7pDnVZ3b2m5pMtuPPNE+1gPIEhgfn8mEFxpbz6Ak=; b=K8feaIvaHrIfQBLZin9X3dx5BPSVQv7hTfsjiaSXRDhGpVq7/HREpws+EghlrZ93Yr tynzYwXaJAOoCR+ceKoxDsX6adZaxytUj1kN0KvMG4uW/oBMNVD5br1NqozygAMCClIT QtpI0O/WwD8hnRDoYd5wTv2nuFYUpUod8VLZLFTP+FugSyZAJCV0ulRJIEDqj7Wa06V8 4AjZ55aeykz6jPWYisbCW9KJN2mxsCj1suNg24JjVepfQjLI1zvVh1wfQ7gTWE2RaAw4 VPcsrAatjbZuNpRKRbP3kQsaLeVCsD2OsDWzk99gF/DvGanQ0PNXm7cYfuIBtwR0bEAc pm0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XO4t4BjC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si17610528ejj.426.2021.10.04.13.42.22; Mon, 04 Oct 2021 13:42:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XO4t4BjC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237944AbhJDNhb (ORCPT + 99 others); Mon, 4 Oct 2021 09:37:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:48662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237885AbhJDNfa (ORCPT ); Mon, 4 Oct 2021 09:35:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CA3B461BAA; Mon, 4 Oct 2021 13:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353366; bh=HSo0HeoTq6932krhI7dspLP/+JlyL66tOuDir8PxY7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XO4t4BjCqebfSnyNCwtvPA42rP4Pvi+m4OnhCAkddvLXF4YuLKkLBvoaX05K3oM+F SRC70qkdBOOlDBxTl5TPoDXhkn8826GbQsSILsFh35+SJUm9PObUQ7fAszdZiVLB+3 UvLoOxwc2Qx3shlJwn2eAhEy0f0WJ412LH2SVllo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Gonda , Marc Orr , Nathan Tempelman , Paolo Bonzini , Sean Christopherson , Steve Rutherford , Brijesh Singh , kvm@vger.kernel.org Subject: [PATCH 5.14 058/172] KVM: SEV: Allow some commands for mirror VM Date: Mon, 4 Oct 2021 14:51:48 +0200 Message-Id: <20211004125046.868220573@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Gonda commit 5b92b6ca92b65bef811048c481e4446f4828500a upstream. A mirrored SEV-ES VM will need to call KVM_SEV_LAUNCH_UPDATE_VMSA to setup its vCPUs and have them measured, and their VMSAs encrypted. Without this change, it is impossible to have mirror VMs as part of SEV-ES VMs. Also allow the guest status check and debugging commands since they do not change any guest state. Signed-off-by: Peter Gonda Cc: Marc Orr Cc: Nathan Tempelman Cc: Paolo Bonzini Cc: Sean Christopherson Cc: Steve Rutherford Cc: Brijesh Singh Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Fixes: 54526d1fd593 ("KVM: x86: Support KVM VMs sharing SEV context", 2021-04-21) Message-Id: <20210921150345.2221634-3-pgonda@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm/sev.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1509,6 +1509,20 @@ static int sev_receive_finish(struct kvm return sev_issue_cmd(kvm, SEV_CMD_RECEIVE_FINISH, &data, &argp->error); } +static bool cmd_allowed_from_miror(u32 cmd_id) +{ + /* + * Allow mirrors VM to call KVM_SEV_LAUNCH_UPDATE_VMSA to enable SEV-ES + * active mirror VMs. Also allow the debugging and status commands. + */ + if (cmd_id == KVM_SEV_LAUNCH_UPDATE_VMSA || + cmd_id == KVM_SEV_GUEST_STATUS || cmd_id == KVM_SEV_DBG_DECRYPT || + cmd_id == KVM_SEV_DBG_ENCRYPT) + return true; + + return false; +} + int svm_mem_enc_op(struct kvm *kvm, void __user *argp) { struct kvm_sev_cmd sev_cmd; @@ -1525,8 +1539,9 @@ int svm_mem_enc_op(struct kvm *kvm, void mutex_lock(&kvm->lock); - /* enc_context_owner handles all memory enc operations */ - if (is_mirroring_enc_context(kvm)) { + /* Only the enc_context_owner handles some memory enc operations. */ + if (is_mirroring_enc_context(kvm) && + !cmd_allowed_from_miror(sev_cmd.id)) { r = -EINVAL; goto out; }