Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3303343lfo; Mon, 23 May 2022 01:09:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlvNWf4z1opd9zegxl1GZ4oq2I7QhctVQHyC6RBtTpRaVjwOWaZh8hqNEij6LEVC+v7Gdy X-Received: by 2002:a63:9043:0:b0:3f7:a43:635f with SMTP id a64-20020a639043000000b003f70a43635fmr13717227pge.531.1653293385495; Mon, 23 May 2022 01:09:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653293385; cv=none; d=google.com; s=arc-20160816; b=I7LEWiUzMlLmx2LJlalEH6XSpnPNrsA2Da003qotNTnPHPeaVz71g9FJN/9tkCG1R4 S3IDPNntvvsNHPEbGj7/yPR3o/PrOhNm7tEbRgZ7lrpWtOJm0uXHDp76vPD2S66fvBXL BibA/z6FGwlIpo7GDQ5cEREAc/kXesaxrAjq3LmfcIvs3SL/65w5L24q/Z9lKGWwJLLK 8MPbSMwm0SqLonby/l4c6BHnokPlbbtq9Frr749qarxUh2I+L6SI7CRhHVjKtOeEpOqS 6QUK4OLoKe28euKFsHKw6gcKJeNHS6mrOf6ifrsdxW1cwJcANWHM+Ad+ObfJQsT2X2Xg oAKg== 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=7UpZ3vIydYQbJynx9tacn2HIuDZ985w6Pm7fWZXYM7w=; b=mGFdU0602c/C0YehibJl0ZoshTnI0TjFK5prY5pS1XwLSkDt4593kSmnmGShpL/UdJ 4xhVPeLbBgMYrQCjZUUSSqjkAWXnXWFJ95rQCpF01SuH4xguJtG4u0DpgQjwLJ+ufknd cFL7Tdd40UsoBfRBcZV842pqgQ5vpAfC+phbh/vQH7bgKig8NsQdQAb91vSks6Uxggsn ivIKjU07qYorRMz2GQZXSU8G83HLBpFNxP9+JHxyY1QO1pkJpfuBAVe5gAbdUK246P/G yTI6NAy8YSOkMA6cJJ+RmUBW7kxMnnOdhk971mUwSRt+FD0uzAEbwu9RFEG0y1iXN5UC MTQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EJWfcKYn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h4-20020a63e144000000b003dbaa0bd8d5si10055747pgk.537.2022.05.23.01.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 01:09:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EJWfcKYn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 404BA2ACD; Mon, 23 May 2022 00:04:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235725AbiEUNSO (ORCPT + 99 others); Sat, 21 May 2022 09:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355286AbiEUNRV (ORCPT ); Sat, 21 May 2022 09:17:21 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 905015711A; Sat, 21 May 2022 06:16:55 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id z7-20020a17090abd8700b001df78c7c209so13669711pjr.1; Sat, 21 May 2022 06:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7UpZ3vIydYQbJynx9tacn2HIuDZ985w6Pm7fWZXYM7w=; b=EJWfcKYnX1rQp5r6kuYIXe1wjGTHsJYqMxVi5VudrwxjdyVc58p7R1dws9TWHRztkc 2sPS30RSdGAAczzjtJEVTdQAxvXZmr1s4LyJTRGU2FY1j3haLZrEFHdqWmi1UKPjyDya 4Ewiou/3alhfuaGRx2wxx5ibL5yiJ9mpASzUuvDuOnX9rfura0iAFaA/+VqAi5nb5cad szE3YVcWeKekXqNwYJc89glgsLp0JivjUJsVl+qNKxGCbN15DURC0a/UBCd9PtFCoj8w tMONC3Y3I4/yTRuKwJVyZAQJnFVOypUjkapBjnuvUTzLs/hVSjMHr+ddQpiA9B5+2r2f CBjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7UpZ3vIydYQbJynx9tacn2HIuDZ985w6Pm7fWZXYM7w=; b=Bejzkt9J1hH33e8WgNNETHoJrvcmvLWayRkdO2rGjL3bYm6QSPrAw6IiTaEA3iRZ1t P0NJLt2vJ2QhmVhKYnKtFehRF9GRfa5nKIX9F+2ebYCBCawIDJSS6QHG9hFJbdKuq6rC vh3p3RkCGg4UlQK+r9iujhY47cpR5GsJrTNLp440nRYSHapVf5xLoMLHTJUlHtr6jh5m tGevegX8PIOqnArfZxV//RQiE1y51bMV8MkBmT5W0FfQjHljLs4i52ZFfTvXdzuZKana 2cDGs5K9nSykE08BoeBnLkqhnGtReUxb1ObFXkfs9rSVEx0enWSunqJQx9+1e5qjt+Xa faVg== X-Gm-Message-State: AOAM5322nOQpeN5qE1Dz5OCBLFJgG1ebOThwhpyh2xvnIH4mH2KBbxCC pGewJt8GQ1Ka4HwXXR4BmCk1AYJSI9w= X-Received: by 2002:a17:90b:4a8d:b0:1dc:3769:20fc with SMTP id lp13-20020a17090b4a8d00b001dc376920fcmr17013667pjb.114.1653139009561; Sat, 21 May 2022 06:16:49 -0700 (PDT) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id z24-20020a62d118000000b005182d505389sm3514208pfg.72.2022.05.21.06.16.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 May 2022 06:16:49 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Vitaly Kuznetsov , Maxim Levitsky , David Matlack , Lai Jiangshan Subject: [PATCH V3 12/12] KVM: X86/MMU: Remove mmu_alloc_special_roots() Date: Sat, 21 May 2022 21:17:00 +0800 Message-Id: <20220521131700.3661-13-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20220521131700.3661-1-jiangshanlai@gmail.com> References: <20220521131700.3661-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Lai Jiangshan mmu_alloc_special_roots() allocates mmu->pae_root for non-PAE paging (as for shadowing 32bit NPT on 64 bit host) and mmu->pml4_root and mmu->pml5_root. But mmu->pml4_root and mmu->pml5_root is not used, neither mmu->pae_root for non-PAE paging. So remove mmu_alloc_special_roots(), mmu->pml4_root and mmu->pml5_root. Signed-off-by: Lai Jiangshan --- arch/x86/include/asm/kvm_host.h | 3 -- arch/x86/kvm/mmu/mmu.c | 77 --------------------------------- 2 files changed, 80 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index fb9751dfc1a7..ec44e6c3d5ea 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -458,9 +458,6 @@ struct kvm_mmu { u8 permissions[16]; u64 *pae_root; - u64 *pml4_root; - u64 *pml5_root; - /* * check zero bits on shadow page table entries, these * bits include not only hardware reserved bits but also diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 73e6a8e1e1a9..b8eed217314d 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3691,78 +3691,6 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu) return r; } -static int mmu_alloc_special_roots(struct kvm_vcpu *vcpu) -{ - struct kvm_mmu *mmu = vcpu->arch.mmu; - bool need_pml5 = mmu->root_role.level > PT64_ROOT_4LEVEL; - u64 *pml5_root = NULL; - u64 *pml4_root = NULL; - u64 *pae_root; - - /* - * When shadowing 32-bit or PAE NPT with 64-bit NPT, the PML4 and PDP - * tables are allocated and initialized at root creation as there is no - * equivalent level in the guest's NPT to shadow. Allocate the tables - * on demand, as running a 32-bit L1 VMM on 64-bit KVM is very rare. - */ - if (mmu->root_role.direct || - mmu->cpu_role.base.level >= PT64_ROOT_4LEVEL || - mmu->root_role.level < PT64_ROOT_4LEVEL) - return 0; - - /* - * NPT, the only paging mode that uses this horror, uses a fixed number - * of levels for the shadow page tables, e.g. all MMUs are 4-level or - * all MMus are 5-level. Thus, this can safely require that pml5_root - * is allocated if the other roots are valid and pml5 is needed, as any - * prior MMU would also have required pml5. - */ - if (mmu->pae_root && mmu->pml4_root && (!need_pml5 || mmu->pml5_root)) - return 0; - - /* - * The special roots should always be allocated in concert. Yell and - * bail if KVM ends up in a state where only one of the roots is valid. - */ - if (WARN_ON_ONCE(!tdp_enabled || mmu->pae_root || mmu->pml4_root || - (need_pml5 && mmu->pml5_root))) - return -EIO; - - /* - * Unlike 32-bit NPT, the PDP table doesn't need to be in low mem, and - * doesn't need to be decrypted. - */ - pae_root = (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT); - if (!pae_root) - return -ENOMEM; - -#ifdef CONFIG_X86_64 - pml4_root = (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT); - if (!pml4_root) - goto err_pml4; - - if (need_pml5) { - pml5_root = (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT); - if (!pml5_root) - goto err_pml5; - } -#endif - - mmu->pae_root = pae_root; - mmu->pml4_root = pml4_root; - mmu->pml5_root = pml5_root; - - return 0; - -#ifdef CONFIG_X86_64 -err_pml5: - free_page((unsigned long)pml4_root); -err_pml4: - free_page((unsigned long)pae_root); - return -ENOMEM; -#endif -} - static bool is_unsync_root(hpa_t root) { struct kvm_mmu_page *sp; @@ -5166,9 +5094,6 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu) r = mmu_alloc_pae_root(vcpu); if (r) return r; - r = mmu_alloc_special_roots(vcpu); - if (r) - goto out; if (vcpu->arch.mmu->root_role.direct) r = mmu_alloc_direct_roots(vcpu); else @@ -5626,8 +5551,6 @@ static void free_mmu_pages(struct kvm_mmu *mmu) if (!tdp_enabled && mmu->pae_root) set_memory_encrypted((unsigned long)mmu->pae_root, 1); free_page((unsigned long)mmu->pae_root); - free_page((unsigned long)mmu->pml4_root); - free_page((unsigned long)mmu->pml5_root); } static void __kvm_mmu_create(struct kvm_mmu *mmu) -- 2.19.1.6.gb485710b