public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Manali Shukla <manali.shukla@amd.com>
Cc: pbonzini@redhat.com, kvm@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH v4 5/8] x86: nSVM: Build up the nested page table dynamically
Date: Thu, 16 Jun 2022 00:06:56 +0000	[thread overview]
Message-ID: <Yqp0IP+qnp9qFrDM@google.com> (raw)
In-Reply-To: <20220428070851.21985-6-manali.shukla@amd.com>

On Thu, Apr 28, 2022, Manali Shukla wrote:
> Current implementation of nested page table does the page table build
> up statistically with 2048 PTEs and one pml4 entry.
> That is why current implementation is not extensible.
> 
> New implementation does page table build up dynamically based on the
> RAM size of the VM which enables us to have separate memory range to
> test various npt test cases.

I'm guessing you know the drill :-)

> Signed-off-by: Manali Shukla <manali.shukla@amd.com>
> ---
>  x86/svm.c     | 75 ++++++++++++++++-----------------------------------
>  x86/svm.h     |  4 ++-
>  x86/svm_npt.c |  5 ++--
>  3 files changed, 29 insertions(+), 55 deletions(-)
> 
> diff --git a/x86/svm.c b/x86/svm.c
> index ec825c7..e66c801 100644
> --- a/x86/svm.c
> +++ b/x86/svm.c
> @@ -8,6 +8,7 @@
>  #include "desc.h"
>  #include "msr.h"
>  #include "vm.h"
> +#include "fwcfg.h"
>  #include "smp.h"
>  #include "types.h"
>  #include "alloc_page.h"
> @@ -16,43 +17,32 @@
>  #include "vmalloc.h"
>  
>  /* for the nested page table*/
> -u64 *pte[2048];
> -u64 *pde[4];
> -u64 *pdpe;
>  u64 *pml4e;
>  
>  struct vmcb *vmcb;
>  
>  u64 *npt_get_pte(u64 address)
>  {
> -	int i1, i2;
> -
> -	address >>= 12;
> -	i1 = (address >> 9) & 0x7ff;
> -	i2 = address & 0x1ff;
> -
> -	return &pte[i1][i2];
> +        return get_pte(npt_get_pml4e(), (void*)address);
>  }
>  
>  u64 *npt_get_pde(u64 address)
>  {
> -	int i1, i2;
> -
> -	address >>= 21;
> -	i1 = (address >> 9) & 0x3;
> -	i2 = address & 0x1ff;
> -
> -	return &pde[i1][i2];
> +    struct pte_search search;
> +    search = find_pte_level(npt_get_pml4e(), (void*)address, 2);
> +    return search.pte;
>  }
>  
> -u64 *npt_get_pdpe(void)
> +u64 *npt_get_pdpe(u64 address)
>  {
> -	return pdpe;
> +    struct pte_search search;
> +    search = find_pte_level(npt_get_pml4e(), (void*)address, 3);
> +    return search.pte;
>  }
>  
>  u64 *npt_get_pml4e(void)
>  {
> -	return pml4e;
> +    return pml4e;
>  }
>  
>  bool smp_supported(void)
> @@ -300,11 +290,21 @@ static void set_additional_vcpu_msr(void *msr_efer)
>  	wrmsr(MSR_EFER, (ulong)msr_efer | EFER_SVME);
>  }
>  
> +void setup_npt(void) {

Function braces go on a new line.

> +    u64 end_of_memory;
> +    pml4e = alloc_page();
> +

...

> diff --git a/x86/svm_npt.c b/x86/svm_npt.c
> index 53e8a90..ab4dcf4 100644
> --- a/x86/svm_npt.c
> +++ b/x86/svm_npt.c
> @@ -209,7 +209,8 @@ static void __svm_npt_rsvd_bits_test(u64 * pxe, u64 rsvd_bits, u64 efer,
>  	       "Wanted #NPF on rsvd bits = 0x%lx, got exit = 0x%x", rsvd_bits,
>  	       exit_reason);
>  
> -	if (pxe == npt_get_pdpe() || pxe == npt_get_pml4e()) {
> +	if (pxe == npt_get_pdpe((u64) basic_guest_main)
> +	    || pxe == npt_get_pml4e()) {

The "||" should be on the previous line.

>  		/*
>  		 * The guest's page tables will blow up on a bad PDPE/PML4E,
>  		 * before starting the final walk of the guest page.
> @@ -338,7 +339,7 @@ skip_pte_test:
>  				get_random_bits(20, 13) | PT_PAGE_SIZE_MASK,
>  				host_efer, host_cr4, guest_efer, guest_cr4);
>  
> -	_svm_npt_rsvd_bits_test(npt_get_pdpe(),
> +	_svm_npt_rsvd_bits_test(npt_get_pdpe((u64) basic_guest_main),
>  				PT_PAGE_SIZE_MASK |
>  				(this_cpu_has(X86_FEATURE_GBPAGES) ?
>  				 get_random_bits(29, 13) : 0), host_efer,
> -- 
> 2.30.2
> 

  reply	other threads:[~2022-06-16  0:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28  7:08 [kvm-unit-tests PATCH v4 0/8] Move npt test cases and NPT code improvements Manali Shukla
2022-04-28  7:08 ` [kvm-unit-tests PATCH v4 1/8] x86: nSVM: Move common functionality of the main() to helper run_svm_tests Manali Shukla
2022-04-28  7:08 ` [kvm-unit-tests PATCH v4 2/8] x86: nSVM: Move all nNPT test cases from svm_tests.c to a separate file Manali Shukla
2022-06-15 23:43   ` Sean Christopherson
2022-06-20  2:03     ` Shukla, Manali
2022-04-28  7:08 ` [kvm-unit-tests PATCH v4 3/8] x86: nSVM: Allow nSVM tests run with PT_USER_MASK enabled Manali Shukla
2022-06-15 23:47   ` Sean Christopherson
2022-04-28  7:08 ` [kvm-unit-tests PATCH v4 4/8] x86: Improve set_mmu_range() to implement npt Manali Shukla
2022-06-15 23:58   ` Sean Christopherson
2022-06-16  0:04     ` Sean Christopherson
2022-06-22 15:32       ` Shukla, Manali
2022-06-24  0:46         ` Sean Christopherson
2022-04-28  7:08 ` [kvm-unit-tests PATCH v4 5/8] x86: nSVM: Build up the nested page table dynamically Manali Shukla
2022-06-16  0:06   ` Sean Christopherson [this message]
2022-04-28  7:08 ` [kvm-unit-tests PATCH v4 6/8] x86: nSVM: Correct indentation for svm.c Manali Shukla
2022-04-28  7:16 ` [kvm-unit-tests PATCH v4 7/8] x86: nSVM: Correct indentation for svm_tests.c part-1 Manali Shukla
2022-04-28  8:05 ` [kvm-unit-tests PATCH v4 8/8] x86: nSVM: Correct indentation for svm_tests.c part-2 Manali Shukla
2022-05-09  4:12 ` [kvm-unit-tests PATCH v4 0/8] Move npt test cases and NPT code improvements Shukla, Manali
2022-05-16  4:45   ` Shukla, Manali
2022-06-09  7:29     ` Shukla, Manali
2022-06-14  0:56       ` Sean Christopherson

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=Yqp0IP+qnp9qFrDM@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=manali.shukla@amd.com \
    --cc=pbonzini@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox