All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Lai Jiangshan <jiangshanlai@gmail.com>, linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org, Lai Jiangshan <laijs@linux.alibaba.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Sean Christopherson <seanjc@google.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH 15/15] KVM: X86: Always set gpte_is_8_bytes when direct map
Date: Thu, 18 Nov 2021 12:12:40 +0100	[thread overview]
Message-ID: <16b701db-e277-c4ef-e198-65a2dc6e3fdf@redhat.com> (raw)
In-Reply-To: <20211118110814.2568-16-jiangshanlai@gmail.com>

On 11/18/21 12:08, Lai Jiangshan wrote:
> From: Lai Jiangshan <laijs@linux.alibaba.com>
> 
> When direct map, gpte_is_8_bytes has no meaning, but it is true for all
> other cases except direct map when nonpaping.
> 
> Setting gpte_is_8_bytes to true when nonpaping can ensure that
> !gpte_is_8_bytes means 32-bit gptes for shadow paging.

Then the right thing to do would be to rename it to has_4_byte_gptes and 
invert the direction.  But as things stand, it's a bit more confusing to 
make gpte_is_8_bytes=1 if there are no guest PTEs at all.

Paolo

> Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
> ---
>   Documentation/virt/kvm/mmu.rst | 2 +-
>   arch/x86/kvm/mmu/mmu.c         | 4 ++--
>   2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/virt/kvm/mmu.rst b/Documentation/virt/kvm/mmu.rst
> index f60f5488e121..5d1086602759 100644
> --- a/Documentation/virt/kvm/mmu.rst
> +++ b/Documentation/virt/kvm/mmu.rst
> @@ -179,7 +179,7 @@ Shadow pages contain the following information:
>       unpinned it will be destroyed.
>     role.gpte_is_8_bytes:
>       Reflects the size of the guest PTE for which the page is valid, i.e. '1'
> -    if 64-bit gptes are in use, '0' if 32-bit gptes are in use.
> +    if direct map or 64-bit gptes are in use, '0' if 32-bit gptes are in use.
>     role.efer_nx:
>       Contains the value of efer.nx for which the page is valid.
>     role.cr0_wp:
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 6948f2d696c3..0c92cbc07320 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -2083,7 +2083,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
>   	role.level = level;
>   	role.direct = direct;
>   	role.access = access;
> -	if (!direct_mmu && !role.gpte_is_8_bytes) {
> +	if (!role.gpte_is_8_bytes) {
>   		quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
>   		quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1;
>   		role.quadrant = quadrant;
> @@ -4777,7 +4777,7 @@ kvm_calc_shadow_root_page_role_common(struct kvm_vcpu *vcpu,
>   
>   	role.base.smep_andnot_wp = role.ext.cr4_smep && !____is_cr0_wp(regs);
>   	role.base.smap_andnot_wp = role.ext.cr4_smap && !____is_cr0_wp(regs);
> -	role.base.gpte_is_8_bytes = ____is_cr0_pg(regs) && ____is_cr4_pae(regs);
> +	role.base.gpte_is_8_bytes = !____is_cr0_pg(regs) || ____is_cr4_pae(regs);
>   
>   	return role;
>   }
> 


  reply	other threads:[~2021-11-18 11:15 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 11:07 [PATCH 00/15] KVM: X86: Miscellaneous cleanups Lai Jiangshan
2021-11-18 11:08 ` [PATCH 01/15] KVM: VMX: Use x86 core API to access to fs_base and inactive gs_base Lai Jiangshan
2021-11-18 16:05   ` Paolo Bonzini
2021-11-21 15:17   ` Thomas Gleixner
2021-11-22  3:27     ` Lai Jiangshan
2021-11-18 11:08 ` [PATCH 02/15] KVM: VMX: Avoid to rdmsrl(MSR_IA32_SYSENTER_ESP) Lai Jiangshan
2021-11-18 11:18   ` Paolo Bonzini
2021-11-18 14:17     ` Lai Jiangshan
2021-11-18 14:38       ` Paolo Bonzini
2021-11-18 11:08 ` [PATCH 03/15] KVM: VMX: Update msr value after kvm_set_user_return_msr() succeeds Lai Jiangshan
2021-11-18 11:08 ` [PATCH 04/15] KVM: VMX: Save HOST_CR3 in vmx_prepare_switch_to_guest() Lai Jiangshan
2021-11-18 11:08 ` [PATCH 05/15] KVM: VMX: Add document to state that write to uret msr should always be intercepted Lai Jiangshan
2021-11-18 16:05   ` Paolo Bonzini
2021-12-07 20:38     ` Sean Christopherson
2021-11-18 11:08 ` [PATCH 06/15] KVM: VMX: Use kvm_set_msr_common() for MSR_IA32_TSC_ADJUST in the default way Lai Jiangshan
2021-11-18 11:08 ` [PATCH 07/15] KVM: VMX: Change comments about vmx_get_msr() Lai Jiangshan
2021-11-18 11:08 ` [PATCH 08/15] KVM: SVM: Rename get_max_npt_level() to get_npt_level() Lai Jiangshan
2021-11-18 11:08 ` [PATCH 09/15] KVM: SVM: Allocate sd->save_area with __GFP_ZERO Lai Jiangshan
2021-11-18 11:08 ` [PATCH 10/15] KVM: X86: Skip allocating pae_root for vcpu->arch.guest_mmu when !tdp_enabled Lai Jiangshan
2021-11-18 11:08 ` [PATCH 11/15] KVM: X86: Fix comment in __kvm_mmu_create() Lai Jiangshan
2021-11-18 11:08 ` [PATCH 12/15] KVM: X86: Remove unused declaration of __kvm_mmu_free_some_pages() Lai Jiangshan
2021-11-18 11:08 ` [PATCH 13/15] KVM: X86: Remove useless code to set role.gpte_is_8_bytes when role.direct Lai Jiangshan
2021-11-18 11:08 ` [PATCH 14/15] KVM: X86: Calculate quadrant when !role.gpte_is_8_bytes Lai Jiangshan
2021-11-18 11:08 ` [PATCH 15/15] KVM: X86: Always set gpte_is_8_bytes when direct map Lai Jiangshan
2021-11-18 11:12   ` Paolo Bonzini [this message]
2021-11-18 14:34     ` Lai Jiangshan
2021-11-18 15:01       ` Paolo Bonzini
2021-11-19 10:30         ` Lai Jiangshan
2021-11-19 10:34           ` Paolo Bonzini
2021-11-19 10:42             ` Lai Jiangshan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16b701db-e277-c4ef-e198-65a2dc6e3fdf@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jiangshanlai@gmail.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=laijs@linux.alibaba.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.