Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4123298rwb; Sun, 7 Aug 2022 15:43:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR6dni1KG1yEjES3plDo5C4oAuzlIZUSnjj459F8gEBD2/BtnNzl4qxgWXqwCj/I+N8/wur6 X-Received: by 2002:aa7:919a:0:b0:52a:eeef:3e65 with SMTP id x26-20020aa7919a000000b0052aeeef3e65mr15787109pfa.15.1659912205524; Sun, 07 Aug 2022 15:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659912205; cv=none; d=google.com; s=arc-20160816; b=F1HdJXb2W7lp1MhHecrzfvzSumdJCLpTlSkMyY/hCqmQTCKGtPS8fCPO+pQ4VVGn9H fB3HZwEEqEbj3D4D47BDON8GIgq9gNPLhTyqHYzdzhQlTodlr0wzLzMtWLGKfm2U5dPJ pxXuUJ2ZnmFr6kY2sNrP0jjpmHGmn+rU4/N4vBWHEyDOX/NS3WSM0QgbRcKpsovNaOFh GUPDloS5DrSpseQEfnnoIBlOTuTVz2YyjBoHIuKTHN1dBvjg2FNeTeA8LPL3epc476Xi SgyVt0wzRKuF7xa2+v+MKbYu8wgaN1zZJ8f6gFap+V/Pr7zTSIBiZb152tBsLiURnVG0 ZPfQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OltGsbxVHBnzgOpRYG6mwzCjuo6soSQUUDD3jVDgWb8=; b=e2H9+DluJjGqeqDO0H2JM//xwiNhddc7Hs9bC0M4iwsZ7WRv/x0dBQSowwUaFI4hk9 ioHTdsn/e/OWkBke5mHYxmujgeLXQav6kHMIZKqPwPkueahUmBKPmKZpda87ABdEFhkY XQcz13d3SdtltfZxkVqW4ErTDhC9WUlfeBYgKbsXw15zS2+cKpvygdFFJGgc5zYr16OV T1ohx26zqRpVJneD6QjuGvqTfjReWuBunW097xQP9pPN1eOQVEsP70XxsJhXGJUNiZEb BZTrgUT0qQVYBYCnnfik96Qw/glf1qLH2qeeXvbKyArPMT7s/e2T6L82Bp0oxH26SLTE oEAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=F2cVsO3m; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l5-20020a170903120500b0016c1a1bb2fasi3936593plh.569.2022.08.07.15.43.12; Sun, 07 Aug 2022 15:43:25 -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=@intel.com header.s=Intel header.b=F2cVsO3m; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235398AbiHGWcY (ORCPT + 99 others); Sun, 7 Aug 2022 18:32:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242221AbiHGWbj (ORCPT ); Sun, 7 Aug 2022 18:31:39 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3297D18362; Sun, 7 Aug 2022 15:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659910731; x=1691446731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CC+oCHJCHlL6/p6anZ5hH11kfUqGKD9/J/qtkJCwbqE=; b=F2cVsO3mNoGfp5SZA9ucssD6/NYTc5U63IcUpGWCwMICiQhlvriUK1Wu cFQ+4lRzl4O4TZM6sfhtt/cImlf+eovs/hg/AAARjKQbspf/IEXUqFHl0 gWTL5uvXoUOwRj0YLeTkwKNCCPkinwrswlHHnRV7VHEOpLcCmRsvG3RiF jvfWjwapYKGuqtb2gehLFAokjKSzH/dJKm4dEU/Zj19ciXdtO6lRNuEsu P0QyvxLy4aOX3zWd7QphXQs9iFN39bu3PAbqLF1viN1jk3Tz0I+9ClDmb +hD1hRu43g4RnaFJ3aQRHnXkFhvRo5VMGFdkbmt9GGgMxufYMo8QqufqV g==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="270852835" X-IronPort-AV: E=Sophos;i="5.93,221,1654585200"; d="scan'208";a="270852835" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:18:50 -0700 X-IronPort-AV: E=Sophos;i="5.93,221,1654585200"; d="scan'208";a="632642321" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:18:50 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar Subject: [RFC PATCH 07/13] KVM: TDX: Update tdx_sept_{set,drop}_private_spte() to support large page Date: Sun, 7 Aug 2022 15:18:40 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Xiaoyao Li Allow large page level AUG and REMOVE for TDX pages. Signed-off-by: Xiaoyao Li Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/tdx.c | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 0b9f9075e1ea..cdd421fb5024 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1458,20 +1458,18 @@ static void __tdx_sept_set_private_spte(struct kvm *kvm, gfn_t gfn, struct tdx_module_output out; hpa_t source_pa; u64 err; + int i; if (WARN_ON_ONCE(is_error_noslot_pfn(pfn) || !kvm_pfn_to_refcounted_page(pfn))) return; /* To prevent page migration, do nothing on mmu notifier. */ - get_page(pfn_to_page(pfn)); + for (i = 0; i < KVM_PAGES_PER_HPAGE(level); i++) + get_page(pfn_to_page(pfn + i)); /* Build-time faults are induced and handled via TDH_MEM_PAGE_ADD. */ if (likely(is_td_finalized(kvm_tdx))) { - /* TODO: handle large pages. */ - if (KVM_BUG_ON(level != PG_LEVEL_4K, kvm)) - return; - err = tdh_mem_page_aug(kvm_tdx->tdr.pa, gpa, tdx_level, hpa, &out); if (KVM_BUG_ON(err, kvm)) { pr_tdx_error(TDH_MEM_PAGE_AUG, err, &out); @@ -1530,38 +1528,40 @@ static void tdx_sept_drop_private_spte( hpa_t hpa_with_hkid; struct tdx_module_output out; u64 err = 0; + int i; - /* TODO: handle large pages. */ - if (KVM_BUG_ON(level != PG_LEVEL_4K, kvm)) - return; - - spin_lock(&kvm_tdx->seamcall_lock); if (is_hkid_assigned(kvm_tdx)) { + spin_lock(&kvm_tdx->seamcall_lock); err = tdh_mem_page_remove(kvm_tdx->tdr.pa, gpa, tdx_level, &out); + spin_unlock(&kvm_tdx->seamcall_lock); if (KVM_BUG_ON(err, kvm)) { pr_tdx_error(TDH_MEM_PAGE_REMOVE, err, &out); - goto unlock; + return; } - hpa_with_hkid = set_hkid_to_hpa(hpa, (u16)kvm_tdx->hkid); - err = tdh_phymem_page_wbinvd(hpa_with_hkid); - if (WARN_ON_ONCE(err)) { - pr_tdx_error(TDH_PHYMEM_PAGE_WBINVD, err, NULL); - goto unlock; + for (i = 0; i < KVM_PAGES_PER_HPAGE(level); i++) { + hpa_with_hkid = set_hkid_to_hpa(hpa, (u16)kvm_tdx->hkid); + spin_lock(&kvm_tdx->seamcall_lock); + err = tdh_phymem_page_wbinvd(hpa_with_hkid); + spin_unlock(&kvm_tdx->seamcall_lock); + if (WARN_ON_ONCE(err)) + pr_tdx_error(TDH_PHYMEM_PAGE_WBINVD, err, NULL); + else + tdx_unpin(kvm, gfn + i, pfn + i); + hpa += PAGE_SIZE; } - } else + } else { /* * The HKID assigned to this TD was already freed and cache * was already flushed. We don't have to flush again. */ + spin_lock(&kvm_tdx->seamcall_lock); err = tdx_reclaim_page((unsigned long)__va(hpa), hpa, level, false, 0); - -unlock: - spin_unlock(&kvm_tdx->seamcall_lock); - - if (!err) - tdx_unpin_pfn(kvm, pfn); + spin_unlock(&kvm_tdx->seamcall_lock); + if (!err) + tdx_unpin(kvm, gfn, pfn); + } } static int tdx_sept_link_private_sp(struct kvm *kvm, gfn_t gfn, -- 2.25.1