From patchwork Mon Aug 7 23:01:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 132459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1774907vqr; Mon, 7 Aug 2023 16:43:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdcwmSXs79TnBiWPRPHCnXbcUpXr/JKMLwOVrxz15DWby/jWNQxrBic57uEuebx6qVXEzo X-Received: by 2002:a17:907:a058:b0:99b:eb9c:4fb9 with SMTP id gz24-20020a170907a05800b0099beb9c4fb9mr7598472ejc.69.1691451779763; Mon, 07 Aug 2023 16:42:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691451779; cv=none; d=google.com; s=arc-20160816; b=LNZEl1WLzDiMLGzQLurCUG85MiKg0GH78EEheJTgXVVb3X9qQH62tByUuonzgLZoxC 7rLH8VhXIjvL+OZ77Gy77SZkk9Ljl8KRQGe4yUayQ2YU3o6/iazPB+oqaC+KhtSqaQ8R ou9wFR++SDyjCxQ3/vC2lKBz9rYnaoEKQDXDdS6t46Qtm+J4dETnq1njl7wndhQRZ1Iy 5m7Bk6lPz0jz+wmGLr5O1kXJucStOd24wJnwMkdt/+4d3RYLzPMDmgN43pXE3qG/bHQA eJHF9cqNwEOKjxce1zyYOkuPlwrSL8ytcTlycAQQV8g1825CFrkysYlpzyS9EAqX8kGA pppg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j20-20020a1709066dd400b0099bce4aa78dsi6366525ejt.865.2023.08.07.16.42.35; Mon, 07 Aug 2023 16:42:59 -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 S231419AbjHGXCP (ORCPT + 99 others); Mon, 7 Aug 2023 19:02:15 -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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773615741530179171 X-GMAIL-MSGID: 1773615741530179171 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: