Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4927075pxj; Tue, 22 Jun 2021 11:01:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv52DG74tVcxPYEjmucvWLosy9X9LAOIEsN0nCfV/pihz34SnQtWdAonr/y1hGOCF6V1TP X-Received: by 2002:a92:6705:: with SMTP id b5mr3371755ilc.55.1624384861747; Tue, 22 Jun 2021 11:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624384861; cv=none; d=google.com; s=arc-20160816; b=Z5c7U57dqFOfdGzE/MAE3fMn+7Z7P5cj0/f8JNuyjkhSN2J5HK3xSQUGl1xDNCarJc aTpApxcY+NfGavlFe1MGd6K04QvbhQo41ryc5DnhTlsCqoHL00XVC+1UI4/n6B2iKfPy VFn7gEEYwLEKFtzVaWB45DmTwS6qitHUIQpGbrgfiqsYd1aOiJhe+/Xqhe2Nt6PPIE50 CH/R4E18zzGM/e2+Gbfmsr0D2BAGIBWas8jXXzLDGc5Pb5c2PeVrBYQd7B9x814r1KwE K/Vpk6pnRXBkBGyoEehNXSlsttzIgiUoQkBSY5aHXNH1fI0r06sqIjJv7In+57/g2ln6 /G9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=WckRIopBZujqPimPvM/oO/U/oSKI+UjuEVuOH/hGa7M=; b=PWL8mroYLWS5rOnascmL1RxFMmFNcPDmLVaxU55zkfCRIpzJ0C3R/z08NRYufh8SNw nYYcZ1lhgHa+f+e/E0lfqRF5OX4hp3Gyv/Nb4jAj4ycKURul3Y7T/hcbLOTy62/7JTog tPJ9wHOF01bY6BwXOYJp+d7Jn3obOFlRfiqjmOEQLkF/3+CcwE7RDDr9T82/ePNTl5Q6 tVdbbhFr3yasM/eLYqwbrAf/VXkyJZi6+/RuRpdEu4WKRB7rGfDBjsQJ6gmFWRW8qvWw eBmdJIl40hqsWI7GHXxu/1J9DGbF1s8XYLwRy2/WFJBDe0yA7Ac4xaKEzVVxgxGZcz7M Eb5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=T9yfHpql; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x99si54712jah.122.2021.06.22.11.00.46; Tue, 22 Jun 2021 11:01:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=T9yfHpql; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232654AbhFVSBG (ORCPT + 99 others); Tue, 22 Jun 2021 14:01:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232649AbhFVSAk (ORCPT ); Tue, 22 Jun 2021 14:00:40 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C50C06175F for ; Tue, 22 Jun 2021 10:58:19 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 4-20020a6315440000b029022154a87a57so14306449pgv.13 for ; Tue, 22 Jun 2021 10:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=WckRIopBZujqPimPvM/oO/U/oSKI+UjuEVuOH/hGa7M=; b=T9yfHpqlRV49gaT9p3DmZYwhIi1zHM045117HZQdXfkWe97BxhPoL5Hr+sN7dkzCEv f5alEzpKIictZXcSdK8iO/LI6fCxUq0Yf07xSrfxFrCI9sVf3biZPBX8ZA/XKBK3JXyJ 1ymPPY0G8qOhD36obQqknBUOEfJCZPPIO1TbH9wVthEUGgsD0/r140V6+aHsf/Xoc4cz acSaRWRw2JCC/CMkb8vGIAxlhv/8zPHDDpKvluzKVu/IEoocC9EexgGlbxA5cJFvbGvy E8EO+lfTRurlih+hQQh62ngeczQ2RVeDrlv43liawU0EjECbHiBY3YKHDfmk+uoQ08Zp Eb+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=WckRIopBZujqPimPvM/oO/U/oSKI+UjuEVuOH/hGa7M=; b=RJsQqFzq5xy2ACwVyUjMskvIdwNiAbjOWI89uhcpavFB1FhiMaJPz/9EKacVAzoPzq hoJm1c7ZHBrAhgNp+DOwcmDr1vuGrYgPTo+MIuDzMHd3TIfdP4voYZE48J9GakQTTBlB 8BNz7CxuqCpJCoULY54w9SsaIH+Yut3bI+CRXU0Wev3ShEN85qnh1iFQw28o7zZrmUz9 RQcMm8jwU3uCdjysnq0Y7F7RIToU79XCbPJfp7/g0Aa5y9pJZLRNwmtN3028whTCduaX GkDaSKOEm4SkVo41CagRd7ehoiQm9ZEuuQB+gpoYx4J/PtSEAPo/A1G7U9CMxp2CBFQI dJpw== X-Gm-Message-State: AOAM533O/R4vRHyfwp83YsALOosqeV9Jp9hVzS1PbLIK7eEow7FbRw87 D+sgw5msXcrZtL9/EJEn0ugRrWsrZFQ= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:5722:92ce:361f:3832]) (user=seanjc job=sendgmr) by 2002:a17:90a:c796:: with SMTP id gn22mr92986pjb.0.1624384698638; Tue, 22 Jun 2021 10:58:18 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 22 Jun 2021 10:56:55 -0700 In-Reply-To: <20210622175739.3610207-1-seanjc@google.com> Message-Id: <20210622175739.3610207-11-seanjc@google.com> Mime-Version: 1.0 References: <20210622175739.3610207-1-seanjc@google.com> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog Subject: [PATCH 10/54] KVM: x86/mmu: Replace EPT shadow page shenanigans with simpler check From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yu Zhang , Maxim Levitsky Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace the hack to identify nested EPT shadow pages with a simple check that the size of the guest PTEs associated with the shadow page and the current MMU match, which is the intent of the "8 bytes == PAE" test. The nested EPT hack existed to avoid a false negative due to the is_pae() check not matching for 32-bit L2 guests; checking the MMU role directly avoids the indirect calculation of the guest PTE size entirely. Note, this should be a glorified nop now that __kvm_sync_page() is called if and only if the role is an exact match (kvm_mmu_get_page()) or is part of the current MMU context (kvm_mmu_sync_roots()). A future commit will convert the likely-pointless check into a meaningful WARN to enforce that the mmu_roles of the current context and the shadow page are compatible. Cc: Vitaly Kuznetsov Signed-off-by: Sean Christopherson --- Documentation/virt/kvm/mmu.rst | 3 --- arch/x86/kvm/mmu/mmu.c | 16 +++------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Documentation/virt/kvm/mmu.rst b/Documentation/virt/kvm/mmu.rst index 20d85daed395..ddbb23998742 100644 --- a/Documentation/virt/kvm/mmu.rst +++ b/Documentation/virt/kvm/mmu.rst @@ -192,9 +192,6 @@ Shadow pages contain the following information: Contains the value of cr4.smap && !cr0.wp for which the page is valid (pages for which this is true are different from other pages; see the treatment of cr0.wp=0 below). - role.ept_sp: - This is a virtual flag to denote a shadowed nested EPT page. ept_sp - is true if "cr0_wp && smap_andnot_wp", an otherwise invalid combination. role.smm: Is 1 if the page is valid in system management mode. This field determines which of the kvm_memslots array was used to build this diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 99d26859021d..9f277c5bab76 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1780,16 +1780,13 @@ static void kvm_mmu_commit_zap_page(struct kvm *kvm, &(_kvm)->arch.mmu_page_hash[kvm_page_table_hashfn(_gfn)]) \ if ((_sp)->gfn != (_gfn) || (_sp)->role.direct) {} else -static inline bool is_ept_sp(struct kvm_mmu_page *sp) -{ - return sp->role.cr0_wp && sp->role.smap_andnot_wp; -} - /* @sp->gfn should be write-protected at the call site */ static bool __kvm_sync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, struct list_head *invalid_list) { - if ((!is_ept_sp(sp) && sp->role.gpte_is_8_bytes != !!is_pae(vcpu)) || + union kvm_mmu_page_role mmu_role = vcpu->arch.mmu->mmu_role.base; + + if (sp->role.gpte_is_8_bytes != mmu_role.gpte_is_8_bytes || vcpu->arch.mmu->sync_page(vcpu, sp) == 0) { kvm_mmu_prepare_zap_page(vcpu->kvm, sp, invalid_list); return false; @@ -4721,13 +4718,6 @@ kvm_calc_shadow_ept_root_page_role(struct kvm_vcpu *vcpu, bool accessed_dirty, role.base.guest_mode = true; role.base.access = ACC_ALL; - /* - * WP=1 and NOT_WP=1 is an impossible combination, use WP and the - * SMAP variation to denote shadow EPT entries. - */ - role.base.cr0_wp = true; - role.base.smap_andnot_wp = true; - role.ext = kvm_calc_mmu_role_ext(vcpu); role.ext.execonly = execonly; -- 2.32.0.288.g62a8d224e6-goog