Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp119693iob; Tue, 3 May 2022 12:59:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ752oc2DMd5nzuEFcivwhfW5vfF3rmACwiFbP+oAfWbrRZDQM5bdY6DYj6wDKi3J5pNZX X-Received: by 2002:a05:6402:1a42:b0:424:20bb:3e37 with SMTP id bf2-20020a0564021a4200b0042420bb3e37mr20137289edb.29.1651607974245; Tue, 03 May 2022 12:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607974; cv=none; d=google.com; s=arc-20160816; b=sTuI/FTrKDRHzxtqXDPwSQq1ChituWKiTIqf1jybqPH7vTn0DmBbeaU717ouKVBpJV ixV4cq1ZyvOUi5ITuaCMDspSQ50JEmlWdCL+HfoMz6zQ14MjnWKA/vhkjKRnti/4MTtx xI3D9euhY6AnN//QD9P7ZBpHkOK8Vwz/6YwKWwi3Km/pULj/t1pYDomWxMtmxYOuW/Yj 0+prUOT2SABqUcI0V9H/UfJ4DYg3XnQkOeq5W+pignyXwjrf52SLJ8086N6o/j+LuoZ2 CIUvV3pBt8tafunrNadaEcdDvkYFk9mnH52wcv0ODmrApQ4EtNKjIsp5FfJLIJZQn44d AMAA== 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=kpUXLHmfMO9TwZfWJqVY4XQuTZrvTupEDHXTCZCy2JY=; b=mv5ft2/Q86ikjeIADNM2XOA0Xrs+VXyoExBEAmd9XXa7phUHbyAgUJzBe4XHbWnBb2 jN6X3xc8zW8XZKSsUkem0adAXFiZka8L+nJsP3WnxtFY6rtKXVyZd3Y6uTR9OzurrwkG a/bdLpn/fU31SC67lSEHiD5s6uHko6neeQRUJoHlnDxHuub8mSA3jB+r9anKbPYbns1K 5r4VG7f+X10EsFb7Z3clqZYV7wAIG78eSyUfM041LhLF0ipGU9SRs8qsjoNHSlNTC1tl lIkXJ5aQp156RQWYACR0CcHPvVhng2Ar1Fv5BUv07iCl8fnFG8mMwO8UL5ExQiJHhW2C oGTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HoXU6gI8; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20-20020a056402355400b00427da5fd28fsi3350071edd.309.2022.05.03.12.59.11; Tue, 03 May 2022 12:59:34 -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=@gmail.com header.s=20210112 header.b=HoXU6gI8; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237827AbiECPKj (ORCPT + 99 others); Tue, 3 May 2022 11:10:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237811AbiECPKi (ORCPT ); Tue, 3 May 2022 11:10:38 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B0903A5CA; Tue, 3 May 2022 08:07:05 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id r9so15558241pjo.5; Tue, 03 May 2022 08:07:05 -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=kpUXLHmfMO9TwZfWJqVY4XQuTZrvTupEDHXTCZCy2JY=; b=HoXU6gI8QHQ1RysZ3jac2pj95Mt97LCnMGHEQS+r7qZvbLnWXXLqkTDTftKEdLGIOj 0bQR/jUQ2C+CoD8E/X3gaKEpuO6k8PLtjedukszecQhN8D/FNRLdoTZXtJ8IjkTTugQI xoLB9LoRIJYwGLbP+tC0MvlefiAuzHb15+2S/Wn3yO4jkPVtRBowQ0nvr9/V11a56uwb 9om60dgJ5Z9czP1+msCObQwv4gXpmFMBOcm6zRsyESefa7N0p0sLay5lHbhYzulxMoKa ib0kxtpLYZyQ6afIheefLMZNPGUEJaUwsEmwZ2VejQ6pALcCL0l2cHpt1veeX5E8Rlbd 8Zzg== 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=kpUXLHmfMO9TwZfWJqVY4XQuTZrvTupEDHXTCZCy2JY=; b=vm2Wj3ifIIZvYwXR2KbZf1XRnfQmc1gXmcdbXgOVNYNHyUqdW6PotzBVqtSwJPC4n7 TWJAKho576frwCu000iQDShdIirWMR4AMdXLMFmahfAxFjzrgnUFSdIRQFVL5aWftbBH uAPtX/SBiN7vwWhjR/3wFFqhC9V91N/0UECAhgoGCtsxrvdCjnYY1e3rMyQItlPGdB5Q hrk2ixJlPuGDK9OUGAwuDg9IqHNe6pSAhBiB4XfKotkX2b1gNDijtLIDuJgRy96sRkVd 0sGAriUdwSPaq+jjk7Jx8a0YWwcKMIjCm78lzwChU51wpuRzyOP6wrYx/H8XdGg3fVtS q80g== X-Gm-Message-State: AOAM530HqwuQ/HC9sMBGcJ7m5nmqcRozrGq11eANWB0bDqvPcuPlgwZj NWd0ITe2hZ3aDsImdi3D99OTbKHKJ1s= X-Received: by 2002:a17:90b:3d0:b0:1d9:52e1:de86 with SMTP id go16-20020a17090b03d000b001d952e1de86mr5064916pjb.73.1651590424705; Tue, 03 May 2022 08:07:04 -0700 (PDT) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id v8-20020a170902e8c800b0015e8d4eb2dfsm6421548plg.297.2022.05.03.08.07.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 May 2022 08:07:04 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Lai Jiangshan , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH V2 1/7] KVM: X86/MMU: Add using_special_root_page() Date: Tue, 3 May 2022 23:07:29 +0800 Message-Id: <20220503150735.32723-2-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20220503150735.32723-1-jiangshanlai@gmail.com> References: <20220503150735.32723-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: Lai Jiangshan In some case, special roots are used in mmu. It is often using to_shadow_page(mmu->root.hpa) to check if special roots are used. Add using_special_root_page() to directly check if special roots are used or needed to be used even mmu->root.hpa is not set. Prepare for making to_shadow_page(mmu->root.hpa) return non-NULL via using special shadow pages. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/mmu/mmu.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 909372762363..7f20796af351 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1711,6 +1711,14 @@ static void drop_parent_pte(struct kvm_mmu_page *sp, mmu_spte_clear_no_track(parent_pte); } +static bool using_special_root_page(struct kvm_mmu *mmu) +{ + if (mmu->root_role.direct) + return mmu->root_role.level == PT32E_ROOT_LEVEL; + else + return mmu->cpu_role.base.level <= PT32E_ROOT_LEVEL; +} + static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, int direct) { struct kvm_mmu_page *sp; @@ -4241,10 +4249,10 @@ static bool fast_pgd_switch(struct kvm *kvm, struct kvm_mmu *mmu, { /* * For now, limit the caching to 64-bit hosts+VMs in order to avoid - * having to deal with PDPTEs. We may add support for 32-bit hosts/VMs - * later if necessary. + * having to deal with PDPTEs. Special roots can not be put into + * mmu->prev_roots[]. */ - if (VALID_PAGE(mmu->root.hpa) && !to_shadow_page(mmu->root.hpa)) + if (VALID_PAGE(mmu->root.hpa) && using_special_root_page(mmu)) kvm_mmu_free_roots(kvm, mmu, KVM_MMU_ROOT_CURRENT); if (VALID_PAGE(mmu->root.hpa)) -- 2.19.1.6.gb485710b