Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4122447rwb; Sun, 7 Aug 2022 15:41:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR7iYyl8RIjz8LaPq84Qf9avxcU35HyVfx8/qZz9uN6+MpDHCB1Sj94EtYMs+VIrygGPeEr3 X-Received: by 2002:a05:6a00:816:b0:52f:43f9:b644 with SMTP id m22-20020a056a00081600b0052f43f9b644mr2618601pfk.57.1659912108244; Sun, 07 Aug 2022 15:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659912108; cv=none; d=google.com; s=arc-20160816; b=Y5FGLoOAKoZjq4dVGTiIG8pnqY4PjSgJ/j6IG5Qy9YPrvCgOUvZwdnTAH2LW/y2Ruv 1BA5h38rDM8kZ4IfhzoZynmbG+s2+Urd7LvvnSkb036rJa0A/1k0PHg0uZGPGLor7761 bufXDOhTWTAQv6luOFX2axs4fnO0fmIQHn1wXgzVEhjxAXqbW7Dl6GXW2lRtJrF0poz4 +Drp11LTU9d+KkiCUG2TbZhYtLw9gmDsxlbU3GjpVGs+n1jgRpwuZ2MB3twNbh0ftq4/ p6tKDA4Tz44Daoym0Nl5p/idQZWi6znp2IKutMVhgiSAJF/o44H8gPedJedAMoXutRvX p3Kg== 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=L3NfL/jFgHhZTDEXp4ll/s05LjWzdLYTlltPcMBgu2Q=; b=ajvEzlb7zZVUGWLVRYD+jVz6LxONAaL62XR6u/9mSykIZCpTDRpfscbZ5AGOBejJsm /axaCa0ZShmpbdr5ZeqJZR+hurtPDot1d2pus+w638+/JJgfwGFbrZ9TKCOCCgH8Ideq 6JxJrKNg8WRyg9ebsBPouue7Xw7nVwUZpKyB3+IWs9AH0ZXZFIpYo+GVZt6lLqZDT3f7 6fvQegAMiPpbvYHOpTQw9ZpMMgiUI9Ig1q0O+5oFnbY1zJJTCeY/MdSXPHXOLgY4R+FL iU9OrY01PnvGx8uVg6pDa/x7OjxDvNZAIU4fPAzQfHb+4l28t3cSGuapgKTDAjP9P9dk CWJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gn8LeKaO; 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 m12-20020a170902f64c00b0016d4e5ca5fbsi3982730plg.308.2022.08.07.15.41.32; Sun, 07 Aug 2022 15:41:48 -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=gn8LeKaO; 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 S242438AbiHGWcr (ORCPT + 99 others); Sun, 7 Aug 2022 18:32:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242290AbiHGWbk (ORCPT ); Sun, 7 Aug 2022 18:31:40 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAAA91836E; Sun, 7 Aug 2022 15:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659910732; x=1691446732; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vpSLndbfs6RqeobMkXPOe0+TrlAhD95ZYYobrsGmqRk=; b=gn8LeKaOUkE35m8TWsHu8qzlPVV0wTswctvdWp6KiB5FBonCZs/YOSve TzsKPBauYKqi5JnwL8Qkuj+nQR3S5SPUt3ieqcKVIcdQRWzFLzsYrefDn TmqxTwg0newHLHfYE5q5eRwxhoAzFt3af7ncpWODibqaGVXpKflpIRDMQ AxEVeucARptk38FZBeTxs/Pmmt+SyBH5GmNbsjLSHuNhdkDCVI32nPULm PrY0WYvp+6l2hZ1kpNEGfg+VNEffAqklGl034eljytNXG6aZvKVHih6aB Na/kgwRe7STn/BNB1I+VpdDjy7VJNxkunJUYwv3otA4AKy3dIqC3x+aVy Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="270852841" X-IronPort-AV: E=Sophos;i="5.93,221,1654585200"; d="scan'208";a="270852841" 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:52 -0700 X-IronPort-AV: E=Sophos;i="5.93,221,1654585200"; d="scan'208";a="632642339" 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:51 -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 11/13] KVM: TDP_MMU: Split the large page when zap leaf Date: Sun, 7 Aug 2022 15:18:44 -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 When TDX enabled, a large page cannot be zapped if it contains mixed pages. In this case, it has to split the large page. Signed-off-by: Xiaoyao Li --- arch/x86/kvm/mmu/tdp_mmu.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index faf278e0c740..e5d31242677a 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1033,6 +1033,14 @@ bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp) return true; } + +static struct kvm_mmu_page *tdp_mmu_alloc_sp_for_split(struct kvm *kvm, + struct tdp_iter *iter, + bool shared); + +static int tdp_mmu_split_huge_page(struct kvm *kvm, struct tdp_iter *iter, + struct kvm_mmu_page *sp, bool shared); + /* * If can_yield is true, will release the MMU lock and reschedule if the * scheduler needs the CPU or there is contention on the MMU lock. If this @@ -1075,6 +1083,24 @@ static bool tdp_mmu_zap_leafs(struct kvm *kvm, struct kvm_mmu_page *root, !is_last_spte(iter.old_spte, iter.level)) continue; + if (kvm_gfn_shared_mask(kvm) && is_large_pte(iter.old_spte)) { + gfn_t gfn = iter.gfn & ~kvm_gfn_shared_mask(kvm); + gfn_t mask = KVM_PAGES_PER_HPAGE(iter.level) - 1; + struct kvm_memory_slot *slot; + struct kvm_mmu_page *sp; + + slot = gfn_to_memslot(kvm, gfn); + if (kvm_mem_attr_is_mixed(slot, gfn, iter.level) || + (gfn & mask) < start || + end < (gfn & mask) + KVM_PAGES_PER_HPAGE(iter.level)) { + sp = tdp_mmu_alloc_sp_for_split(kvm, &iter, false); + WARN_ON(!sp); + + tdp_mmu_split_huge_page(kvm, &iter, sp, false); + continue; + } + } + tdp_mmu_set_spte(kvm, &iter, SHADOW_NONPRESENT_VALUE); flush = true; } @@ -1642,8 +1668,6 @@ static struct kvm_mmu_page *tdp_mmu_alloc_sp_for_split(struct kvm *kvm, WARN_ON(kvm_mmu_page_role_is_private(role) != is_private_sptep(iter->sptep)); - /* TODO: Large page isn't supported for private SPTE yet. */ - WARN_ON(kvm_mmu_page_role_is_private(role)); /* * Since we are allocating while under the MMU lock we have to be -- 2.25.1