Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp751474ioo; Sat, 21 May 2022 13:08:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeHRaSzbqx9z+OjmOL3VwQMaDOnVXCYRzk9cLNNb+roGg/rFd/m8JtVBy/VZ9rpWq5N2zd X-Received: by 2002:a17:907:d22:b0:6f4:8766:2042 with SMTP id gn34-20020a1709070d2200b006f487662042mr13562379ejc.259.1653163728274; Sat, 21 May 2022 13:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653163728; cv=none; d=google.com; s=arc-20160816; b=biEI8mucmeP+x+oeFC/vTEj2/Y6AaNKPv7jcniOsxKijK7uDpDAhoC+VryBcnoALOh Ge7jKZGP7K/fOGu9cILbfvBCVNVe747pVn7tcHB+29ZXrwRJ8vWw/IcR9yFk2IlWFMQ/ ayHYkrF1e5fAJBUvT5gKP4MVn/wnbgWXVYYaXqchySmmWVaAa+ceFgfyRegJL0zIYdkl Ajkgyf7YBS1WBNr15VOyiO1x3udoZauiCAiR1jrhmI4Ep1QM/2j+t+h5FJbUOB7YSfo5 1bw7F2EuBQVJtZX9WyGI56RpJnKCR1J0XPg94hi3x21zNmxm8NqU2KoWnSs/jbwqaMYg 4P/g== 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=8ROpEEdq4nhDPA6XwmM5rgE6fsdyhfYYyZpEn0MjbA0=; b=ZvYeJmLvLdLEZrrUnjVrXAUZI6R7QMLogF8vWHJVeqx6ykMzbDsqtai6iHN2fVzQAD fHJqG1D5sMjXqmCQsT9xGyIYgHvE7vc7l1wrpJ7TYG15JVPPDm50dVz2fXYz5CTQd10/ /jMO6hk24L4CqE5nbdX0Cb09S3P7sm5tKt9F4Hr86RmzI+rJLfPyHvD//wAiyIYtvdYc xg0Y5WIAwQSE6Vczvy2bb8jvwEJbYLJaGDLlLmtvELfbgPwei0uO9rlMdCGxPF1r+vsB LQRjwIWW5vqbda9WmLuRmK8EQlak2WheEVMMhysGVVMfA85aP+clLAntHz1XVIfIqBrk XqYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WXJMcvF8; 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 hs29-20020a1709073e9d00b006df76385be4si12297633ejc.132.2022.05.21.13.08.22; Sat, 21 May 2022 13:08: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=@gmail.com header.s=20210112 header.b=WXJMcvF8; 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 S1354947AbiEUNQ4 (ORCPT + 99 others); Sat, 21 May 2022 09:16:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355069AbiEUNQd (ORCPT ); Sat, 21 May 2022 09:16:33 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E7A92F389; Sat, 21 May 2022 06:16:23 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id c14so9895582pfn.2; Sat, 21 May 2022 06:16:23 -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=8ROpEEdq4nhDPA6XwmM5rgE6fsdyhfYYyZpEn0MjbA0=; b=WXJMcvF8UyenHRio4TyF0ZVna5wzsZMKyZeKkf5TsZiN/7a1KmGZLofwZhbOeM2fNz wDH1nspnL1M4pIoZ8RWSbailZpSqNxW4RTyVP4eS32loFVPTKkSgR07AyYNdjbxFWwc9 JJBGfOry3leV5BP++RMrTwrFSE0qp0B4uYCm1yFqC9WsPWTT2J5PCUrEoXqHDLoGxl38 417Yub0Kuf/QpnEKg6+2gYBkwdPx7GzgxPdtTenVifKVqVCpHkXmnNg7uDoi3pLYMUx/ jRMGONc1UVyVu0b2I0zGo2RXRaOeeEgdA58MHBqth0oF2DxJytWXme6uIbtD3r4bSCzd wjVw== 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=8ROpEEdq4nhDPA6XwmM5rgE6fsdyhfYYyZpEn0MjbA0=; b=fuVgE+QVxHxTgUdWn2k1wW22U5jrUd0NbR50dRpgiktAcSOsSLr6hXC9bWmWeQCfq/ 7zhlesp6RXEgC5q7QdIYeH1sF/MXBpH0fwU9CdXu1HQEBQUcBq9fYQw2OB2jm7mhmWxp hpupgeHjU9rjD5ZlJXNX4jPMVRP27lJYImP9Rkb4Wee7E/wLmoM5781ErhL1Jd5DT3DS pXCf8tN3TInxI7JhQ3MIQn7cIBVDp0DLzYlIn0mqBL1o49ScUl66UVueZZD6v1dTymh1 9DEWRwyKxCPXJF4gLY2o++sthCqUBU2gpWa1lgdlj0VNxf5lp89inWIxY6mzuqNa9uXt ZMug== X-Gm-Message-State: AOAM531cvdmh1Q849hpeBHM0x/uShYa/wQNs0siLoD45YmfoaUpCnryy RilqaaZfqZ/3oSNGCSplyCinpjY83AM= X-Received: by 2002:a63:e513:0:b0:3ab:a3fb:f100 with SMTP id r19-20020a63e513000000b003aba3fbf100mr12487336pgh.70.1653138983340; Sat, 21 May 2022 06:16:23 -0700 (PDT) Received: from localhost ([47.251.4.198]) by smtp.gmail.com with ESMTPSA id v11-20020a170902d68b00b0015e8d4eb284sm1552865ply.206.2022.05.21.06.16.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 May 2022 06:16:23 -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 05/12] KVM: X86/MMU: Link PAE root pagetable with its children Date: Sat, 21 May 2022 21:16:53 +0800 Message-Id: <20220521131700.3661-6-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=-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 When local shadow pages are activated, link_shadow_page() might link a local shadow pages which is the PAE root for PAE paging with its children. Add make_pae_pdpte() to handle it. The code is not activated since local shadow pages are not activated yet. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/mmu/mmu.c | 6 +++++- arch/x86/kvm/mmu/spte.c | 7 +++++++ arch/x86/kvm/mmu/spte.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index c941a5931bc3..e1a059dd9621 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2340,7 +2340,11 @@ static void link_shadow_page(struct kvm_vcpu *vcpu, u64 *sptep, BUILD_BUG_ON(VMX_EPT_WRITABLE_MASK != PT_WRITABLE_MASK); - spte = make_nonleaf_spte(sp->spt, sp_ad_disabled(sp)); + if (unlikely(sp->role.level == PT32_ROOT_LEVEL && + vcpu->arch.mmu->root_role.level == PT32E_ROOT_LEVEL)) + spte = make_pae_pdpte(sp->spt); + else + spte = make_nonleaf_spte(sp->spt, sp_ad_disabled(sp)); mmu_spte_set(sptep, spte); diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index b5960bbde7f7..5c31fa1d2b61 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -279,6 +279,13 @@ u64 make_huge_page_split_spte(u64 huge_spte, int huge_level, int index) return child_spte; } +u64 make_pae_pdpte(u64 *child_pt) +{ + /* The only ignore bits in PDPTE are 11:9. */ + BUILD_BUG_ON(!(GENMASK(11,9) & SPTE_MMU_PRESENT_MASK)); + return __pa(child_pt) | PT_PRESENT_MASK | SPTE_MMU_PRESENT_MASK | + shadow_me_value; +} u64 make_nonleaf_spte(u64 *child_pt, bool ad_disabled) { diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 0127bb6e3c7d..2408ba1361d5 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -426,6 +426,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, u64 old_spte, bool prefetch, bool can_unsync, bool host_writable, u64 *new_spte); u64 make_huge_page_split_spte(u64 huge_spte, int huge_level, int index); +u64 make_pae_pdpte(u64 *child_pt); u64 make_nonleaf_spte(u64 *child_pt, bool ad_disabled); u64 make_mmio_spte(struct kvm_vcpu *vcpu, u64 gfn, unsigned int access); u64 mark_spte_for_access_track(u64 spte); -- 2.19.1.6.gb485710b