All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: "Shukla, Manali" <mashukla@amd.com>
Cc: pbonzini@redhat.com, kvm@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH v4 4/8] x86: Improve set_mmu_range() to implement npt
Date: Fri, 24 Jun 2022 00:46:06 +0000	[thread overview]
Message-ID: <YrUJTt1wfMPotyvW@google.com> (raw)
In-Reply-To: <aed29a6c-5e59-d924-f3ed-a3cef91aac79@amd.com>

On Wed, Jun 22, 2022, Shukla, Manali wrote:
> 
> On 6/16/2022 5:34 AM, Sean Christopherson wrote:
> > void __setup_mmu_range(pgd_t *cr3, phys_addr_t start, size_t len, bool nested_mmu)
> > {
> >         u64 orig_opt_mask = pte_opt_mask;
> > 	u64 max = (u64)len + (u64)start;
> > 	u64 phys = start;
> > 
> > 	/* comment goes here. */
> > 	pte_opt_mask |= PT_USER_MASK;
> > 
> >         if (use_hugepages) {
> >                 while (phys + LARGE_PAGE_SIZE <= max) {
> >                         install_large_page(cr3, phys, (void *)(ulong)phys);
> > 		        phys += LARGE_PAGE_SIZE;
> > 	        }
> > 	}
> > 	install_pages(cr3, phys, max - phys, (void *)(ulong)phys);
> > 
> > 	pte_opt_mask = orig_opt_mask;
> > }
> 
> Hi Sean,
> 
> Thank you so much for reviewing my changes.
> 
> RSVD bit test case will start failing with above implementation as we will be
> setting PT_USER_MASK bit for all host PTEs (in order to toggle CR4.SMEP)
> which will defeat one of the purpose of this patch. 

/facepalm

> Right now, pte_opt_mask value which is set from setup_vm(), is overwritten in
> setup_mmu_range() for all the conditions.  How about setting PT_USER_MASK
> only for nested mmu in setup_mmu_range()?  It will retain the same value of
> pte_opt_mask which is set from setup_vm() in all the other cases.

Ya, that should work.

> #define IS_NESTED_MMU 1ULL
> #define USE_HUGEPAGES 2ULL

Use BIT().  And not the ULL single the param is an unsigned long, not a u64.

> void __setup_mmu_range(pgd_t *cr3, phys_addr_t start, size_t len, unsigned long mmu_flags) {

Brace goes on its own line.

>         u64 orig_opt_mask = pte_opt_mask;
>         u64 max = (u64)len + (u64)start;
>         u64 phys = start;
> 
>         /* Allocate 4k pages only for nested page table, PT_USER_MASK needs to
	
	/*
	 * Multi-line comments look like this.
	 * Line 2.
	 */

>          * be enabled for nested page.
>          */
>         if (mmu_flags & IS_NESTED_MMU)
>                 pte_opt_mask |= PT_USER_MASK;
> 
>         if (mmu_flags & USE_HUGEPAGES) {
>                 while (phys + LARGE_PAGE_SIZE <= max) {
>                         install_large_page(cr3, phys, (void *)(ulong)phys);
>                         phys += LARGE_PAGE_SIZE;
>                 }
>         }
>         install_pages(cr3, phys, max - phys, (void *)(ulong)phys);
> 
>         pte_opt_mask = orig_opt_mask;
> }
> 
> static inline void setup_mmu_range(pgd_t *cr3, phys_addr_t start, size_t len) {
>         __setup_mmu_range(cr3, start, len, USE_HUGEPAGES);
> }
> 
> Thank you,
> Manali

  reply	other threads:[~2022-06-24  0:46 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 [this message]
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
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=YrUJTt1wfMPotyvW@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=mashukla@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 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.