All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kai Huang <kai.huang@linux.intel.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
	jbeulich@suse.com, tim@xen.org, kevin.tian@intel.com,
	yang.z.zhang@intel.com, xen-devel@lists.xen.org
Subject: Re: [PATCH 01/10] VMX: Enable EPT A/D bit support
Date: Mon, 30 Mar 2015 14:11:21 +0800	[thread overview]
Message-ID: <5518E909.6050303@linux.intel.com> (raw)
In-Reply-To: <5515BFC5.4000109@citrix.com>



On 03/28/2015 04:38 AM, Andrew Cooper wrote:
> On 27/03/15 02:35, Kai Huang wrote:
>> PML requires A/D bit support so enable it for further use.
>>
>> Signed-off-by: Kai Huang <kai.huang@linux.intel.com>
>> ---
>>   xen/arch/x86/hvm/vmx/vmcs.c        | 1 +
>>   xen/arch/x86/mm/p2m-ept.c          | 8 +++++++-
>>   xen/include/asm-x86/hvm/vmx/vmcs.h | 4 +++-
>>   xen/include/asm-x86/hvm/vmx/vmx.h  | 5 ++++-
>>   4 files changed, 15 insertions(+), 3 deletions(-)
>>
>> diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c
>> index d614638..2f645fe 100644
>> --- a/xen/arch/x86/hvm/vmx/vmcs.c
>> +++ b/xen/arch/x86/hvm/vmx/vmcs.c
>> @@ -103,6 +103,7 @@ static void __init vmx_display_features(void)
>>       P(cpu_has_vmx_tpr_shadow, "APIC TPR shadow");
>>       P(cpu_has_vmx_ept, "Extended Page Tables (EPT)");
>>       P(cpu_has_vmx_vpid, "Virtual-Processor Identifiers (VPID)");
>> +    P(cpu_has_vmx_ept_ad_bit, "EPT A/D bit");
>>       P(cpu_has_vmx_vnmi, "Virtual NMI");
>>       P(cpu_has_vmx_msr_bitmap, "MSR direct-access bitmap");
>>       P(cpu_has_vmx_unrestricted_guest, "Unrestricted Guest");
>> diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
>> index c2d7720..8650092 100644
>> --- a/xen/arch/x86/mm/p2m-ept.c
>> +++ b/xen/arch/x86/mm/p2m-ept.c
>> @@ -233,6 +233,9 @@ static int ept_split_super_page(struct p2m_domain *p2m, ept_entry_t *ept_entry,
>>       if ( !ept_set_middle_entry(p2m, &new_ept) )
>>           return 0;
>>   
>> +    /* It's better to copy A bit of Middle entry from original entry */
>> +    new_ept.a = ept_entry->a;
> Surely d needs to be propagated as well?
No it's not necessary. D-bit is not defined in middle level EPT table. 
Only leaf table entry has D-bit definition.
> Would it make sense to extend
> ept_set_middle_entry() to do all of new_ept setup in one location?
Yes it certainly makes sense to move A-bit propagation into 
ept_set_middle_entry, but this also requires adding additional original 
EPT entry pointer to ept_set_middle_entry as parameter. And 
ept_set_middle_entry is also called by ept_next_level, therefore 
changing it requires more code change, something like below. While I am 
fine with both, which solution do you prefer?

+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -208,7 +208,8 @@ static void ept_p2m_type_to_flags(struct p2m_domain 
*p2m, ept_entry_t *entry,
  #define GUEST_TABLE_POD_PAGE    3

  /* Fill in middle levels of ept table */
-static int ept_set_middle_entry(struct p2m_domain *p2m, ept_entry_t 
*ept_entry)
+static int ept_set_middle_entry(struct p2m_domain *p2m, ept_entry_t 
*new_entry,
+        ept_entry_t *ori_entry)
  {
      struct page_info *pg;

@@ -216,11 +217,13 @@ static int ept_set_middle_entry(struct p2m_domain 
*p2m, ept_entry_t *ept_entry)
      if ( pg == NULL )
          return 0;

-    ept_entry->epte = 0;
-    ept_entry->mfn = page_to_mfn(pg);
-    ept_entry->access = p2m->default_access;
+    new_entry->epte = 0;
+    new_entry->mfn = page_to_mfn(pg);
+    new_entry->access = p2m->default_access;

-    ept_entry->r = ept_entry->w = ept_entry->x = 1;
+    new_entry->r = new_entry->w = new_entry->x = 1;
+
+    new_entry->a = ori_entry->a;

      return 1;
  }
@@ -257,7 +260,7 @@ static int ept_split_super_page(struct p2m_domain 
*p2m, ept_entry_t *ept_entry,

      ASSERT(is_epte_superpage(ept_entry));

-    if ( !ept_set_middle_entry(p2m, &new_ept) )
+    if ( !ept_set_middle_entry(p2m, &new_ept, ept_entry) )
          return 0;

      table = map_domain_page(new_ept.mfn);
@@ -337,7 +340,7 @@ static int ept_next_level(struct p2m_domain *p2m, 
bool_t read_only,
          if ( read_only )
              return GUEST_TABLE_MAP_FAILED;

-        if ( !ept_set_middle_entry(p2m, ept_entry) )
+        if ( !ept_set_middle_entry(p2m, ept_entry, &e) )
              return GUEST_TABLE_MAP_FAILED;
          else
              e = atomic_read_ept_entry(ept_entry); /* Refresh */
>
>> +
>>       table = map_domain_page(new_ept.mfn);
>>       trunk = 1UL << ((level - 1) * EPT_TABLE_ORDER);
>>   
>> @@ -244,7 +247,7 @@ static int ept_split_super_page(struct p2m_domain *p2m, ept_entry_t *ept_entry,
>>           epte->sp = (level > 1);
>>           epte->mfn += i * trunk;
>>           epte->snp = (iommu_enabled && iommu_snoop);
>> -        ASSERT(!epte->rsvd1);
>> +        /* A/D bits are inherited from superpage */
>>           ASSERT(!epte->avail3);
>>   
>>           ept_p2m_type_to_flags(epte, epte->sa_p2mt, epte->access);
>> @@ -1071,6 +1074,9 @@ int ept_p2m_init(struct p2m_domain *p2m)
>>       /* set EPT page-walk length, now it's actual walk length - 1, i.e. 3 */
>>       ept->ept_wl = 3;
>>   
>> +    /* Enable EPT A/D bit if it's supported by hardware */
>> +    ept->ept_ad = cpu_has_vmx_ept_ad_bit ? 1 : 0;
> This will incur overhead on all EPT operations.  It should only be
> enabled if pml is going to be in use.  (I think you need reverse patches
> 1 and 2 in the series, and gate on pml_enable here)
Sure. Will do.

>
>> +
>>       if ( !zalloc_cpumask_var(&ept->synced_mask) )
>>           return -ENOMEM;
>>   
>> diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h
>> index 6fce6aa..4528346 100644
>> --- a/xen/include/asm-x86/hvm/vmx/vmcs.h
>> +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h
>> @@ -62,7 +62,8 @@ struct ept_data {
>>       struct {
>>               u64 ept_mt :3,
>>                   ept_wl :3,
>> -                rsvd   :6,
>> +                ept_ad :1,
>> +                rsvd   :5,
>>                   asr    :52;
> While you are making this change, can you add comments similar to
> ept_entry_t describing the bits?
Sure. I can add a comment for 'ept_ad' bit here. I didn't do it as 
there's no comments for other bits neither.

>
>>           };
>>           u64 eptp;
>> @@ -226,6 +227,7 @@ extern u32 vmx_secondary_exec_control;
>>   #define VMX_EPT_INVEPT_INSTRUCTION              0x00100000
>>   #define VMX_EPT_INVEPT_SINGLE_CONTEXT           0x02000000
>>   #define VMX_EPT_INVEPT_ALL_CONTEXT              0x04000000
>> +#define VMX_EPT_AD_BIT_SUPPORT                  0x00200000
>>   
>>   #define VMX_MISC_VMWRITE_ALL                    0x20000000
>>   
>> diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h
>> index 91c5e18..9afd351 100644
>> --- a/xen/include/asm-x86/hvm/vmx/vmx.h
>> +++ b/xen/include/asm-x86/hvm/vmx/vmx.h
>> @@ -37,7 +37,8 @@ typedef union {
>>           emt         :   3,  /* bits 5:3 - EPT Memory type */
>>           ipat        :   1,  /* bit 6 - Ignore PAT memory type */
>>           sp          :   1,  /* bit 7 - Is this a superpage? */
>> -        rsvd1       :   2,  /* bits 9:8 - Reserved for future use */
>> +        a           :   1,  /* bit 8 - Access bit */
>> +        d           :   1,  /* bit 9 - Dirty bit */
>>           recalc      :   1,  /* bit 10 - Software available 1 */
>>           snp         :   1,  /* bit 11 - VT-d snoop control in shared
>>                                  EPT/VT-d usage */
>> @@ -261,6 +262,8 @@ extern uint8_t posted_intr_vector;
>>       (vmx_ept_vpid_cap & VMX_EPT_SUPERPAGE_2MB)
>>   #define cpu_has_vmx_ept_invept_single_context   \
>>       (vmx_ept_vpid_cap & VMX_EPT_INVEPT_SINGLE_CONTEXT)
>> +#define cpu_has_vmx_ept_ad_bit                  \
>> +    (vmx_ept_vpid_cap & VMX_EPT_AD_BIT_SUPPORT)
> I think cpu_has_vmx_ept_ad is sufficient, without the _bit suffix making
> it longer.
Sure. Will do.

Thanks,
-Kai
>
> ~Andrew
>
>>   
>>   #define EPT_2MB_SHIFT     16
>>   #define EPT_1GB_SHIFT     17
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

  reply	other threads:[~2015-03-30  6:11 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27  2:35 [PATCH 00/10] PML (Paging Modification Logging) support Kai Huang
2015-03-27  2:35 ` [PATCH 01/10] VMX: Enable EPT A/D bit support Kai Huang
2015-03-27 20:38   ` Andrew Cooper
2015-03-30  6:11     ` Kai Huang [this message]
2015-03-30  9:36       ` Andrew Cooper
2015-03-30 13:35         ` Kai Huang
2015-03-30 13:39           ` Andrew Cooper
2015-04-02  6:32     ` Kai Huang
2015-04-02  9:55       ` Andrew Cooper
2015-04-09 11:21   ` Tim Deegan
2015-04-10  6:40     ` Kai Huang
2015-04-10  8:54       ` Tim Deegan
2015-04-10  9:26         ` Kai Huang
2015-04-10  9:51           ` Tim Deegan
2015-04-10 13:14             ` Kai Huang
2015-03-27  2:35 ` [PATCH 02/10] VMX: New parameter to control PML enabling Kai Huang
2015-03-27 20:42   ` Andrew Cooper
2015-03-30  6:16     ` Kai Huang
2015-04-02  5:46     ` Kai Huang
2015-04-02  9:58       ` Andrew Cooper
2015-04-02 13:34         ` Kai Huang
2015-03-27  2:35 ` [PATCH 03/10] VMX: Add PML definition and feature detection Kai Huang
2015-03-27 20:46   ` Andrew Cooper
2015-03-30  6:18     ` Kai Huang
2015-03-27  2:35 ` [PATCH 04/10] VMX: New data structure member to support PML Kai Huang
2015-03-27 20:48   ` Andrew Cooper
2015-03-30  6:19     ` Kai Huang
2015-03-27  2:35 ` [PATCH 05/10] VMX: add help functions " Kai Huang
2015-03-27 21:09   ` Andrew Cooper
2015-03-30  6:43     ` Kai Huang
2015-03-30  9:54       ` Andrew Cooper
2015-03-30 13:40         ` Kai Huang
2015-04-09 12:00   ` Tim Deegan
2015-04-10  7:05     ` Kai Huang
2015-04-10  9:03       ` Tim Deegan
2015-04-10  9:28         ` Kai Huang
2015-04-09 12:31   ` Tim Deegan
2015-04-10  7:07     ` Kai Huang
2015-03-27  2:35 ` [PATCH 06/10] VMX: handle PML buffer full VMEXIT Kai Huang
2015-03-27  2:35 ` [PATCH 07/10] VMX: handle PML enabling in vmx_vcpu_initialise Kai Huang
2015-03-27 21:12   ` Andrew Cooper
2015-03-30  7:03     ` Kai Huang
2015-03-30 10:00       ` Andrew Cooper
2015-03-27  2:35 ` [PATCH 08/10] VMX: disable PML in vmx_vcpu_destroy Kai Huang
2015-04-09 12:04   ` Tim Deegan
2015-04-10  7:25     ` Kai Huang
2015-04-10  9:30       ` Tim Deegan
2015-03-27  2:35 ` [PATCH 09/10] log-dirty: Refine common code to support PML Kai Huang
2015-04-09 12:27   ` Tim Deegan
2015-04-10  7:38     ` Kai Huang
2015-04-10  9:31       ` Tim Deegan
2015-04-10  9:33         ` Kai Huang
2015-03-27  2:35 ` [PATCH 10/10] p2m/ept: Enable PML in p2m-ept for log-dirty Kai Huang
2015-04-09 12:20   ` Tim Deegan
2015-04-10  8:44     ` Kai Huang
2015-04-10  9:46       ` Tim Deegan
2015-04-10 13:18         ` Kai Huang
2015-04-10 14:35           ` Tim Deegan
2015-03-27 21:26 ` [PATCH 00/10] PML (Paging Modification Logging) support Andrew Cooper
2015-03-30  5:50   ` Kai Huang
2015-04-07  8:30     ` Kai Huang
2015-04-07  9:24       ` Tim Deegan
2015-04-08  2:23         ` Kai Huang
2015-04-09 12:32         ` Tim Deegan
2015-04-10  6:40           ` Kai Huang

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=5518E909.6050303@linux.intel.com \
    --to=kai.huang@linux.intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=kevin.tian@intel.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    --cc=yang.z.zhang@intel.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.