Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3656328rwb; Mon, 7 Aug 2023 18:08:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUZLpFCET5g5OMC2dAZzKEJSmeXc/B0MDEdgLyrEhvUkXChmaXk169UorGgPZtXz5KqDLv X-Received: by 2002:a17:90b:38c5:b0:268:325e:ee1a with SMTP id nn5-20020a17090b38c500b00268325eee1amr7194896pjb.27.1691456936250; Mon, 07 Aug 2023 18:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691456936; cv=none; d=google.com; s=arc-20160816; b=rodTK+3/t5Cdg/LY5TfbItkSR1J93zyE6OmscLBE/zNuSEpxn0/1Ny7Z9lbDf9H9lh sgnTr0NpsKZPo/pJBe8iNqjCIaDhPpX1Haw2MfBZEribN7b9fELKR633CSEV2Ik7o/B9 EjzqN+26BdxPKYp7kqdLMGb9N7G40VJKb5LEaZVniQ1TmUFO+VmbQM3XX3xqGVqOWnBb P54z3vGk1SriE338hgIs6iwhYaQNFm+DIIfayjDGztGfTjDfbv8mcFNKWg6SdpRqbZ53 SWjkjPyjM32VvjTEkCRRZgI4rPzalSBncWUUJjF1G+1LCKU5Ak+ZAOTYQJxfJrBiJzDp CB7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=4dErXtZJPA2B8bwHAUFICQ3V58GoU0WO1AR+4rLGR9U=; fh=HbRmZS+XZk9IdI9bC1USVLouzBEe1WLRItFSyknhPLs=; b=FWKqrmyY4PkF/U1YY2AJXYo3KFjynBFjJMw4mm/1z5NhfBRrjSOQwdALapEGVFoc6a 07MOAtCbfodFJOpfVdsCmqHPlJB2OAoFnMTEpt9PS4XUXsgH7pMi9Xv7U4Pd4ZipsFzT 0FlCdl2OAN+YEvhjhY7xABN6ROXpJr6Humdx9wqA70EBwEsFeI0teFMWnSw3WpOSnyVi C71Fkb4+Ljwm7Va85Qeb3MiNyWsccls515jpB+Dwwx3M5Wxu5zb7nAhW11Ju6aGVuiIE DRrznhI4gvQEW++nY0BAZCVoQMnovt45/cay5gSSPRqVclbRJkNjKgQ7iclycLytlSCF 6XPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ZxlSKTI+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u6-20020a17090a410600b00263a985aba5si4095867pjf.149.2023.08.07.18.08.43; Mon, 07 Aug 2023 18:08:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ZxlSKTI+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbjHGXCO (ORCPT + 99 others); Mon, 7 Aug 2023 19:02:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231174AbjHGXCH (ORCPT ); Mon, 7 Aug 2023 19:02:07 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 041A919AD for ; Mon, 7 Aug 2023 16:01:45 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-569e7aec37bso43889447b3.2 for ; Mon, 07 Aug 2023 16:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691449304; x=1692054104; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4dErXtZJPA2B8bwHAUFICQ3V58GoU0WO1AR+4rLGR9U=; b=ZxlSKTI+laVNBuO8UTZ+ZCGmUs6BNo5I74TnUdV85ACjNmtDKARsLhiKqNMkPh3Mk/ 9RaigGGI96R+oAax6t0XcVzh8hAtDE96WW6YBkgzVqUaGgZ4WbSfnL1Mxr1I+7KubkRZ aaRhDkQDreqT1nDjrN2f4k06gs9+NCb45aivwY5/OAY6/QXCQhJngzrRQGNBLIUz8Cyt hlP0O+Y8+CM3VuMtiAJtfNe0nW6FbV1OSPxS/FzhNkedO0KnlSQqZ9O7eheS8Rab6j0x 7Wn5l0azCIiJBUoh4czhdZ8N3ivr5kK4ri1VgZ0oq/SFtrBJ5mIx+xdOg+mJb52yDZkP lTxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691449304; x=1692054104; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4dErXtZJPA2B8bwHAUFICQ3V58GoU0WO1AR+4rLGR9U=; b=OgKy/UcN9FV80ovIBMR4zyiv34nGpL+7zqZYxcFX3aUBP/NFjwQ3hAed7VagTEZ9pI to3LxTdg/X1BkKCHrJ2pmGcXBUJRd7BYPDkxrHnOtcTfB4otgnBp980yM6TOSk1Uh9QK mccagx/lseuDE1mcI8oSLWDbf/jSDn5IY2Ico4FsNyL2F22OfP8li2peL/V1UQW0DQzO 7Na0rqkQ0+rOPsuVuFjo8n1wUHm5zg7kb5smf2gFf/acFMXnmDep9OGU0iM9nhoXlkj3 nSlHv6oJkRCetyjMFitlwuLZI2LdWq0L0kr3CT1Hrm3dO/mMEzmN4Uob9Qbjj1t4lg1b 5hUw== X-Gm-Message-State: AOJu0YwFJu7DZpxklMzsJAlrdZMgRjO7xZu1QP61FUTitSiV8uY7ScYi cBbvmy3omzx0fI+AjATFTPqpVbs8mBVY0eqFEA== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a05:6902:1588:b0:d3b:12d3:564e with SMTP id k8-20020a056902158800b00d3b12d3564emr65596ybu.2.1691449304218; Mon, 07 Aug 2023 16:01:44 -0700 (PDT) Date: Mon, 7 Aug 2023 23:01:11 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Message-ID: <196a2130f155cbc0201cce06579f122352c8b236.1691446946.git.ackerleytng@google.com> Subject: [RFC PATCH 08/11] KVM: x86: Let moving encryption context be configurable From: Ackerley Tng To: pbonzini@redhat.com, seanjc@google.com, tglx@linutronix.de, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, shuah@kernel.org, andrew.jones@linux.dev, ricarkol@google.com, chao.p.peng@linux.intel.com, tabba@google.com, jarkko@kernel.org, yu.c.zhang@linux.intel.com, vannapurve@google.com, ackerleytng@google.com, erdemaktas@google.com, mail@maciej.szmigiero.name, vbabka@suse.cz, david@redhat.com, qperret@google.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SEV-capable VMs may also use the KVM_X86_SW_PROTECTED_VM type, but they will still need architecture-specific handling to move encryption context. Hence, we let moving of encryption context be configurable and store that configuration in a flag. Co-developed-by: Vishal Annapurve Signed-off-by: Vishal Annapurve Signed-off-by: Ackerley Tng --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/svm/sev.c | 2 ++ arch/x86/kvm/x86.c | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 71c1236e4f18..ab45a3d3c867 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1445,6 +1445,8 @@ struct kvm_arch { */ #define SPLIT_DESC_CACHE_MIN_NR_OBJECTS (SPTE_ENT_PER_PAGE + 1) struct kvm_mmu_memory_cache split_desc_cache; + + bool vm_move_enc_ctxt_supported; }; struct kvm_vm_stat { diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index e0e206aa3e62..b09e6477e309 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -256,6 +256,8 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) goto e_no_asid; sev->asid = asid; + kvm->arch.vm_move_enc_ctxt_supported = true; + ret = sev_platform_init(&argp->error); if (ret) goto e_free; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 75d48379d94d..a1a28dd77b94 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6351,7 +6351,14 @@ static int kvm_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd) if (r) goto out_mark_migration_done; - r = static_call(kvm_x86_vm_move_enc_context_from)(kvm, source_kvm); + /* + * Different types of VMs will allow userspace to define if moving + * encryption context should be supported. + */ + if (kvm->arch.vm_move_enc_ctxt_supported && + kvm_x86_ops.vm_move_enc_context_from) { + r = static_call(kvm_x86_vm_move_enc_context_from)(kvm, source_kvm); + } kvm_unlock_two_vms(kvm, source_kvm); out_mark_migration_done: -- 2.41.0.640.ga95def55d0-goog