kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Oliver Upton <oupton@google.com>, kvm@vger.kernel.org
Cc: "Radim Krčmář" <rkrcmar@redhat.com>, "Peter Shier" <pshier@google.com>
Subject: Re: [kvm-unit-tests PATCH] x86: VMX: Check EPT AD bits when enabled in ept_access_paddr()
Date: Tue, 21 Jan 2020 13:29:54 +0100	[thread overview]
Message-ID: <07f09d7b-b97d-1cb9-fc7c-417182c82b80@redhat.com> (raw)
In-Reply-To: <20191128095422.26757-1-oupton@google.com>

On 28/11/19 10:54, Oliver Upton wrote:
> Modify the test helper, ept_access_paddr(), to test the correctness
> of the L1's EPT AD bits when enabled. After a successful guest access,
> assert that the accessed bit (bit 8) has been set on all EPT entries
> which were used in the translation of the guest-physical address.
> 
> Since ept_access_paddr() tests an EPT mapping that backs a guest paging
> structure, processor accesses are treated as writes and the dirty bit
> (bit 9) is set accordingly. Assert that the dirty bit is set on the leaf
> EPT entry.
> 
> Signed-off-by: Oliver Upton <oupton@google.com>
> ---
>  x86/vmx_tests.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> index a456bd1..325dde7 100644
> --- a/x86/vmx_tests.c
> +++ b/x86/vmx_tests.c
> @@ -1135,6 +1135,11 @@ static void ept_disable_ad_bits(void)
>  	vmcs_write(EPTP, eptp);
>  }
>  
> +static int ept_ad_enabled(void)
> +{
> +	return eptp & EPTP_AD_FLAG;
> +}
> +
>  static void ept_enable_ad_bits_or_skip_test(void)
>  {
>  	if (!ept_ad_bits_supported())
> @@ -2500,6 +2505,8 @@ static void ept_access_paddr(unsigned long ept_access, unsigned long pte_ad,
>  	unsigned long *ptep;
>  	unsigned long gpa;
>  	unsigned long orig_epte;
> +	unsigned long epte;
> +	int i;
>  
>  	/* Modify the guest PTE mapping data->gva according to @pte_ad.  */
>  	ptep = get_pte_level(current_page_table(), data->gva, /*level=*/1);
> @@ -2536,6 +2543,17 @@ static void ept_access_paddr(unsigned long ept_access, unsigned long pte_ad,
>  		do_ept_access_op(op);
>  	} else {
>  		do_ept_access_op(op);
> +		if (ept_ad_enabled()) {
> +			for (i = EPT_PAGE_LEVEL; i > 0; i--) {
> +				TEST_ASSERT(get_ept_pte(pml4, gpa, i, &epte));
> +				TEST_ASSERT(epte & EPT_ACCESS_FLAG);
> +				if (i == 1)
> +					TEST_ASSERT(epte & EPT_DIRTY_FLAG);
> +				else
> +					TEST_ASSERT_EQ(epte & EPT_DIRTY_FLAG, 0);
> +			}
> +		}
> +
>  		ept_untwiddle(gpa, /*level=*/1, orig_epte);
>  	}
>  
> 

Queued, thanks.

Paolo


      reply	other threads:[~2020-01-21 12:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28  9:54 [kvm-unit-tests PATCH] x86: VMX: Check EPT AD bits when enabled in ept_access_paddr() Oliver Upton
2020-01-21 12:29 ` Paolo Bonzini [this message]

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=07f09d7b-b97d-1cb9-fc7c-417182c82b80@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=oupton@google.com \
    --cc=pshier@google.com \
    --cc=rkrcmar@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;
as well as URLs for NNTP newsgroup(s).