From patchwork Tue Sep 14 19:01:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Gonda X-Patchwork-Id: 12494445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 636E8C433EF for ; Tue, 14 Sep 2021 19:01:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43F1060234 for ; Tue, 14 Sep 2021 19:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232274AbhINTCt (ORCPT ); Tue, 14 Sep 2021 15:02:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231210AbhINTCs (ORCPT ); Tue, 14 Sep 2021 15:02:48 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F03BAC061574 for ; Tue, 14 Sep 2021 12:01:30 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id j27-20020a05620a0a5b00b0042874883070so618778qka.19 for ; Tue, 14 Sep 2021 12:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=qXeN+0YjwEWrVRbmWh3uR8N524Lyfl40pJMmG7kpDMQ=; b=l3NOXhYLSb4uR4qCfXv+kIDu6RaW+mh86Oqac9N3/0W8oiw7weakxDFnEWjIaXQdvN IIOJGPaH4B859pASij8XptcTpT2pjissVlrsQ5wpefqrc1w+0gD3VAgCMHH8r7TauYQj ySxAkItpKb5QI+a1Zp0uKUxfWB7zVMERif/fL67YtvPv05x+mH6K8xncGxzeVj58aOxZ hzjo+FvWaHCuMlnNlIDbQ7H1WV6M/jU36au9d9ur7PKj44jQgyb7Qy+0fyc7qTAmAdB/ lD2RgigqVWFSJYOYiQYcUhzRvg6dUonCuhA2JrzCESG7+jezCoEDY2U8BE7w9WdT/DYh NFew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=qXeN+0YjwEWrVRbmWh3uR8N524Lyfl40pJMmG7kpDMQ=; b=sTPMro+yDuAl48KJVuYt8PUPKu3fZoEG3Uz0IPUs33hYDmoWWRETQMlEdxO6aw7SQO 7Xkkmn1c2czDX8IbjYIV5RecHARjmGXf+XVoFh0GyAfbYi7A9E2THgf4MeG8JBF8xoO+ Z1+VSIYG2jOpOlrLtdUQxHTqRYGDJZ6eihmgoxjyogBs9uaUXmhyLTScOgpiob4YlNoz Om/XsEkUkBF117TXLXLVEw4yQuWctctlSNUvqa1H2bK3Vt+zk1kbDUuZF4jiyoh+Ln17 IwfPSbBZacGxwFb65fGEh5V+rTx0oD55PXSX9d/TJAa6I0KkGOWUxVvXgfo+bDW1I3l+ yjHw== X-Gm-Message-State: AOAM530aE9Sq/rYWU1dlx0IA4CNOZob87fmoxTvThy7VurvMu7G6ZN7t 9XY5nlGGFGy9k7X4Xxc9MmU9om03EHPsTWnJQ6ZP0RFnCUSiKsT3WEIcn6WbWNs5B+otNuGE8QM NNjPZ2oS1kt++PEqsjfZqm+5nrXEy9K6S3BgFPbubnc5JjNDrq5ZFihgwJQ== X-Google-Smtp-Source: ABdhPJyKSDtjXlMeEQPNa3EfLfWLutRYhMOrRnGvZvDGH5j1BrBsdMydQKn0s3IIS0BQz+zLsPI4bROmm5A= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:204:b358:1f40:79d5:ab23]) (user=pgonda job=sendgmr) by 2002:a0c:cb10:: with SMTP id o16mr7026938qvk.57.1631646088587; Tue, 14 Sep 2021 12:01:28 -0700 (PDT) Date: Tue, 14 Sep 2021 12:01:25 -0700 Message-Id: <20210914190125.3289256-1-pgonda@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog Subject: [PATCH V2] KVM: SEV: Disable KVM_CAP_VM_COPY_ENC_CONTEXT_FROM for SEV-ES From: Peter Gonda To: kvm@vger.kernel.org Cc: Peter Gonda , Marc Orr , Paolo Bonzini , Sean Christopherson , Nathan Tempelman , Brijesh Singh , stable@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Copying an ASID into new vCPUs will not work for SEV-ES since the vCPUs VMSAs need to be setup and measured before SEV_LAUNCH_FINISH. Return an error if a users tries to KVM_CAP_VM_COPY_ENC_CONTEXT_FROM from an SEV-ES guest. The destination VM is already checked for SEV and SEV-ES with sev_guest(), so this ioctl already fails if the destination is SEV enabled. Enabling mirroring a VM or copying its encryption context with an SEV-ES VM is more involved and should happen in its own feature patch if that's needed. This is because the vCPUs of SEV-ES VMs need to be updated with LAUNCH_UPDATE_VMSA before LAUNCH_FINISH. This needs KVM changes because the mirror VM has all its SEV ioctls blocked and the original VM doesn't know about the mirrors vCPUs. Fixes: 54526d1fd593 ("KVM: x86: Support KVM VMs sharing SEV context") V2: * Updated changelog with more information and added stable CC. Signed-off-by: Peter Gonda Cc: Marc Orr Cc: Paolo Bonzini Cc: Sean Christopherson Cc: Nathan Tempelman Cc: Brijesh Singh Cc: kvm@vger.kernel.org Cc: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Sean Christopherson Reviewed-by: Marc Orr --- arch/x86/kvm/svm/sev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 75e0b21ad07c..8a279027425f 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1728,7 +1728,7 @@ int svm_vm_copy_asid_from(struct kvm *kvm, unsigned int source_fd) source_kvm = source_kvm_file->private_data; mutex_lock(&source_kvm->lock); - if (!sev_guest(source_kvm)) { + if (!sev_guest(source_kvm) || sev_es_guest(source_kvm)) { ret = -EINVAL; goto e_source_unlock; }