RFC: AMD support for paging
We started hashing out some AMD support for mem_paging and mem_access. Right now my VMs boot, page out a bit, and then die on an HVM triple fault.
Most importantly, I want to get somebody from AMD to comment/help out on this. It feels like we're inches away from enabling support for this very nice feature. I'm not sure who exactly on AMD monitors the list for these kinds of things. It'd be great to have you on board!
For starters, the changes to the p2m code are relatively mild, but it'd be great if somebody spots a red flag.
Another issue: comments indicate that bits 59-62 in NPT entries are used for IOMMU flags but effectively bits 61-62 are. Repossessing one bit (59) would give us enough space to support mem_access. Right now we only have 7 bits available for Xen flags and that is not enough for paging and access. Is bit 59 effectively reserved?
Finally, the triple fault. Maybe I'm missing something obvious. Comments welcome.
Patch inline below, thanks!
Andres
Enable AMD support for paging.
xen/arch/x86/mm/mem_event.c +0 -4
@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )
xen/arch/x86/mm/p2m-pt.c +22 -4
@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff +* value tramples over the higher-order bits used for flags (NX, p2mt, +* etc.) This happens for paging entries. Thus we do this clip/unclip +* juggle for l1 entries only (no paging superpages!) */ +#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn) & ((1UL << EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;
@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:
@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;
@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content =l1e_empty ();
@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);
@@ -615,11 +633,12 @@ pod_retry_l1:
sizeof(l1e));
if ( ret == 0 ) {
+ unsigned long l1e_mfn = unclip_mfn(l1e_get_pfn(l1e));
p2mt = p2m_flags_to_type(l1e_get_flags(l1e));- ASSERT(l1e_get_pfn(l1e) != INVALID_MFN || !p2m_is_ram(p2mt));
+ ASSERT( (l1e_mfn != INVALID_MFN || !p2m_is_ram(p2mt)) ||
+ (l1e_mfn == INVALID_MFN && p2m_is_paging(p2mt)) );
- if ( p2m_flags_to_type(l1e_get_flags(l1e))
- == p2m_populate_on_demand )
+ if ( p2mt == p2m_populate_on_demand )
{
/* The read has succeeded, so we know that the mapping
* exits at this point. */
@@ -641,7 +660,7 @@ pod_retry_l1:
}
if ( p2m_is_valid(p2mt) || p2m_is_grant(p2mt) )
- mfn = _mfn(l1e_get_pfn(l1e));
+ mfn = _mfn(l1e_mfn);
else
/* XXX see above */
p2mt = p2m_mmio_dm;
@@ -783,18 +802,26 @@ pod_retry_l2:
pod_retry_l1:
if ( (l1e_get_flags(*l1e) & _PAGE_PRESENT) == 0 )
{
+ p2m_type_t l1t = p2m_flags_to_type(l1e_get_flags(*l1e));
/* PoD: Try to populate */
- if ( p2m_flags_to_type(l1e_get_flags(*l1e)) ==
p2m_populate_on_demand )
+ if ( l1t == p2m_populate_on_demand )
{
if ( q != p2m_query ) {
if ( !p2m_pod_demand_populate(p2m, gfn, PAGE_ORDER_4K, q) )
goto pod_retry_l1;
} else
*t = p2m_populate_on_demand;
+ } else {
+ if ( p2m_is_paging(l1t) )
+ {
+ *t = l1t;
+ /* No need to unclip due to check below */
+ mfn = _mfn(l1e_get_pfn(*l1e));
+ }
}
unmap_domain_page(l1e);
- return _mfn(INVALID_MFN);
+ return (l1t == p2m_ram_paging_out) ? mfn : _mfn(INVALID_MFN);
}
mfn = _mfn(l1e_get_pfn(*l1e));
*t = p2m_flags_to_type(l1e_get_flags(*l1e));
@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc
flags = l1e_get_flags(l1e[i1]);
if ( p2m_flags_to_type(flags) != ot )
continue;
- mfn = l1e_get_pfn(l1e[i1]);
+ mfn = unclip_mfn(l1e_get_pfn(l1e[i1]));
gfn = i1 + (i2 + (i3
#if CONFIG_PAGING_LEVELS >= 4
+ (i4 * L3_PAGETABLE_ENTRIES)
@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc
* L2_PAGETABLE_ENTRIES) * L1_PAGETABLE_ENTRIES;
/* create a new 1le entry with the new type */
flags = p2m_type_to_flags(nt, _mfn(mfn));
- l1e_content = l1e_from_pfn(mfn, flags);
+ l1e_content = l1e_from_pfn(clipped_mfn(mfn), flags);
p2m->write_p2m_entry(p2m, gfn, &l1e[i1],
l1mfn, l1e_content, 1);
}
@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain
entry_count++;
continue;
}
- mfn = l1e_get_pfn(l1e[i1]);
+ mfn = unclip_mfn(l1e_get_pfn(l1e[i1]));
ASSERT(mfn_valid(_mfn(mfn)));
m2pfn = get_gpfn_from_mfn(mfn);
if ( m2pfn != gfn &&Quoted 1 line · Andres Lagar-Cavilla
Finally, the triple fault.
"Me too!"
Thats how far I got as well in my attempt.
Olaf
Quoted 6 lines · Andres Lagar-Cavilla
Quoted 2 lines
Finally, the triple fault.
"Me too!"
Thats how far I got as well in my attempt.
Hey, awesome you're trying this out so quickly :)
I just realized the unclip_mfn macro in my patch is broken. It should instead be
+#define unclip_mfn(mfn) (((mfn) == clipped_mfn(INVALID_MFN)) ? \
+ INVALID_MFN : (mfn))
If you have a couple cycles...
Thanks a lot!
Andres
Quoted 3 lines
Olaf
Quoted 8 lines · Andres Lagar-Cavilla
Quoted 6 lines · Andres Lagar-Cavilla
Quoted 2 lines
Finally, the triple fault.
"Me too!"
Thats how far I got as well in my attempt.Hey, awesome you're trying this out so quickly :)
I meant my attempt a few weeks ago.
Quoted 1 line
If you have a couple cycles...
Does your pager do anything? I just get this:
xc: detail: xenpaging init
xc: detail: watching '/local/domain/1/memory/target-tot_pages'
xc: detail: max_pages = 263168
xc: detail: starting /usr/lib/xen/bin/xenpaging for domain_id 1 with pagefile /dev/shm/pagefile-sles11sp2_full_xenpaging
xc: detail: confirming startup in /local/domain/1/xenpaging/state
xc: detail: Got event from xenstore
xc: detail: path '@releaseDomain' token '1'
xc: detail: Got event from evtchn
xc: detail: Got event from xenstore
xc: detail: path '/local/domain/1/memory/target-tot_pages' token ''
xc: detail: new target_tot_pages 59904
xc: detail: Got event from Xen
xc: detail: Need to evict 202213 pages to reach 59904 target_tot_pages
xc: error: Error mapping page 20201 (22 = Invalid argument): Internal error
xc: debug: hypercall buffer: total allocations:9 total releases:9
xc: debug: hypercall buffer: current allocations:0 maximum allocations:2
xc: debug: hypercall buffer: cache current size:2
xc: debug: hypercall buffer: cache hits:7 misses:2 toobig:0
Olaf
Quoted 17 lines · Andres Lagar-Cavilla
Quoted 9 lines
Quoted 7 lines · Andres Lagar-Cavilla
Quoted 2 lines
Finally, the triple fault.
"Me too!"
Thats how far I got as well in my attempt.Hey, awesome you're trying this out so quickly :)
I meant my attempt a few weeks ago.
Quoted 1 line
If you have a couple cycles...
Does your pager do anything? I just get this:
Quoted 16 lines
xc: detail: xenpaging init
xc: detail: watching '/local/domain/1/memory/target-tot_pages'
xc: detail:max_pages= 263168
xc: detail: starting/usr/lib/xen/bin/xenpagingfordomain_id1 with pagefile/dev/shm/pagefile-sles11sp2_full_xenpaging
xc: detail: confirming startup in /local/domain/1/xenpaging/state
xc: detail: Got event from xenstore
xc: detail: path '@releaseDomain' token '1'
xc: detail: Got event from evtchn
xc: detail: Got event from xenstore
xc: detail: path '/local/domain/1/memory/target-tot_pages' token ''
xc: detail: newtarget_tot_pages59904
xc: detail: Got event from Xen
xc: detail: Need to evict 202213 pages to reach 59904target_tot_pages
xc: error: Error mapping page 20201 (22 = Invalid argument): Internal error
Those are the kinds of errors I was getting until I finished my patch. Basically, the p2m gets confused and returns p2m_mmio_dm as the type for anything it doesn't understand. If you end up giving my patch a spin, let me know if it gets you past that hump.
Andres
Quoted 8 lines
xc: debug: hypercall buffer: total allocations:9 total releases:9
xc: debug: hypercall buffer: current allocations:0 maximum allocations:2
xc: debug: hypercall buffer: cache current size:2
xc: debug: hypercall buffer: cache hits:7 misses:2 toobig:0Olaf
Quoted 4 lines · Andres Lagar-Cavilla
Those are the kinds of errors I was getting until I finished my patch. Basically, the p2m gets confused and returns
p2m_mmio_dmas the type for anything it doesn't understand. If you end up giving my patch a spin, let me know if it gets you past that hump.
No, it does not work for me, still EINVAL during mapping.
Perhaps the cpu is not new enough?
processor : 11vendor_id : AuthenticAMD
cpu family : 16
model : 8
model name : AMD Engineering Sample
stepping : 0
cpu MHz : 2400.204
cache size : 512 KB
Olaf
Quoted 8 lines · Olaf Hering
Quoted 4 lines · Andres Lagar-Cavilla
Those are the kinds of errors I was getting until I finished my patch. Basically, the p2m gets confused and returns
p2m_mmio_dmas the type for anything it doesn't understand. If you end up giving my patch a spin, let me know if it gets you past that hump.No, it does not work for me, still EINVAL during mapping.
And this also happens with a recent system:
processor : 2vendor_id : AuthenticAMD
cpu family : 16
model : 5
model name : AMD Phenom(tm) II N830 Triple-Core Processor
stepping : 3
cpu MHz : 2094.846
Olaf
Quoted 6 lines · Olaf Hering
Quoted 5 lines · Andres Lagar-Cavilla
Quoted 3 lines
Those are the kinds of errors I was getting until I finished my patch. Basically, the p2m gets confused and returns
p2m_mmio_dmas the type
Quoted 8 lines
Quoted 6 lines
for
Quoted 1 line
anything it doesn't understand. If you end up giving my patch a spin,
let
Quoted 1 line
me know if it gets you past that hump.
No, it does not work for me, still EINVAL during mapping.
And this also happens with a recent system:
Ok, most likely the p2m is not returning the proper values for entries that are p2m_ram_paging_out. Although eviction after nominate does work. Ummhhh. I'll look into it. Thanks Olaf for the report
Andres
Quoted 12 lines
processor : 2
vendor_id: AuthenticAMD
cpu family : 16
model : 5
model name : AMD Phenom(tm) II N830 Triple-Core Processor
stepping : 3
cpu MHz : 2094.846Olaf
Quoted 9 lines · Andres Lagar-Cavilla
We started hashing out some AMD support for
mem_pagingandmem_access. Right now my VMs boot, page out a bit, and then die on an HVM triple fault.Most importantly, I want to get somebody from AMD to comment/help out on this. It feels like we're inches away from enabling support for this very nice feature. I'm not sure who exactly on AMD monitors the list for these kinds of things. It'd be great to have you on board!
Quoted 8 lines
For starters, the changes to the p2m code are relatively mild, but it'd be great if somebody spots a red flag.
Another issue: comments indicate that bits 59-62 in NPT entries are used for IOMMU flags but effectively bits 61-62 are. Repossessing one bit (59) would give us enough space to support
mem_access. Right now we only have 7 bits available for Xen flags and that is not enough for paging and access. Is bit 59 effectively reserved?
Hi
bit 59 is used by iommu hardware for ATS response. In most cases, for p2m_ram_rw pages, U bit must be 0. But maybe for other page types that are not potentially used by DMA, this bit could be non-zero. I could tested it on my iommu machines if you had some patches that use U bits.
Thanks,
Wei
Quoted 180 lines
Finally, the triple fault. Maybe I'm missing something obvious. Comments welcome.
Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla<[email protected]>Signed-off-by Adin Scannell<[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +22
-4@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff +* value tramples over the higher-order bits used for flags (NX, p2mt, +* etc.) This happens for paging entries. Thus we do this clip/unclip +* juggle for l1 entries only (no paging superpages!) */ +#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn)& ((1UL<< EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content =l1e_empty ();@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +15
-6@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram (p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping * exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e)& _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); +return (l1t == p2m_ram_paging_out) ? mfn :_mfn (INVALID_MFN ); } mfn =_mfn (l1e_get_pfn (*l1e));*t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +3
-3@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS>= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) * L1_PAGETABLE_ENTRIES;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry (p2m, gfn,&l1e[i1], l1mfn, l1e_content,1 ); }@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn&&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 25 lines · Andres Lagar-Cavilla
Quoted 15 lines
We started hashing out some AMD support for
mem_pagingandmem_access. Right now my VMs boot, page out a bit, and then die on an HVM triple fault.Most importantly, I want to get somebody from AMD to comment/help out on this. It feels like we're inches away from enabling support for this very
nice feature. I'm not sure who exactly on AMD monitors the list for these
kinds of things. It'd be great to have you on board!For starters, the changes to the p2m code are relatively mild, but it'd be
great if somebody spots a red flag.Quoted 8 lines
Another issue: comments indicate that bits 59-62 in NPT entries are used for IOMMU flags but effectively bits 61-62 are. Repossessing one bit
(59)
would give us enough space to supportmem_access. Right now we only have 7
bits available for Xen flags and that is not enough for paging and access.
Is bit 59 effectively reserved?
Quoted 5 lines
Hi
bit 59 is used by iommu hardware for ATS response. In most cases, forp2m_ram_rwpages, U bit must be 0. But maybe for other page types that are not potentially used by DMA, this bit could be non-zero. I could tested it on my iommu machines if you had some patches that use U bits.
Hi Wei, thanks for pitching in! I assume you're talking about table 14 (and fig 9) in http://support.amd.com/us/Processor_TechDocs/48882.pdf
I don't think this will work. The p2m access value is arbitrary, and independent of the p2m type. So bit 59 is out of reach and we're stuck with 7 bits for Xen use. Thanks for the clarification.
An alternative to enabling mem_access on AMD processors will be to limit the access types to 3 bits. This would force disabling support for two modes. I'm inclined to disable two out of X, W and WX. I don't think they make sense without R permissions.
Thanks!
Andres
Quoted 192 lines
Thanks,
WeiQuoted 185 lines
Finally, the triple fault. Maybe I'm missing something obvious. Comments welcome.
Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla<[email protected]>Signed-off-by Adin Scannell<[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +2
-0@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff
+ * value tramples over the higher-order bits used for flags (NX, p2mt,
+ * etc.) This happens for paging entries. Thus we do this clip/unclip
+ * juggle for l1 entries only (no paging superpages!) */xen/arch/x86/mm/p2m-pt.c +16
-3+#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn)& ((1UL<< EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content = l1e_empty();xen/arch/x86/mm/p2m-pt.c +1
-1@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +15
-6@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram (p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping * exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e)& _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); +return (l1t == p2m_ram_paging_out) ? mfn :_mfn (INVALID_MFN ); }mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +2
-2@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS>= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) *L1_PAGETABLE_ENTRIES ;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry(p2m, gfn,&l1e[i1],l1mfn, l1e_content, 1); }xen/arch/x86/mm/p2m-pt.c +1
-1@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn&&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 25 lines · Andres Lagar-Cavilla
Quoted 25 lines · Andres Lagar-Cavilla
Quoted 23 lines
We started hashing out some AMD support for
mem_pagingandmem_access. Right now my VMs boot, page out a bit, and then die on an HVM triple fault.Most importantly, I want to get somebody from AMD to comment/help out on this. It feels like we're inches away from enabling support for this very
nice feature. I'm not sure who exactly on AMD monitors the list for these
kinds of things. It'd be great to have you on board!For starters, the changes to the p2m code are relatively mild, but it'd be
great if somebody spots a red flag.Another issue: comments indicate that bits 59-62 in NPT entries are used for IOMMU flags but effectively bits 61-62 are. Repossessing one bit
(59)
would give us enough space to supportmem_access. Right now we only have 7
bits available for Xen flags and that is not enough for paging and access.
Is bit 59 effectively reserved?
Quoted 8 lines
Quoted 5 lines
Hi
bit 59 is used by iommu hardware for ATS response. In most cases, forp2m_ram_rwpages, U bit must be 0. But maybe for other page types that are not potentially used by DMA, this bit could be non-zero. I could tested it on my iommu machines if you had some patches that use U bits.Hi Wei, thanks for pitching in! I assume you're talking about table 14 (and fig 9) in http://support.amd.com/us/Processor_TechDocs/48882.pdf
Yes, indeed.
Quoted 3 lines
I don't think this will work. The p2m access value is arbitrary, and independent of the p2m type. So bit 59 is out of reach and we're stuck with 7 bits for Xen use. Thanks for the clarification.
Where will p2m access bit be stored? Please note that bit 52 - bit 58 for pte must be zero for p2m_ram_rw pages. For iommu pte, only bit 63 and bit 1 - bit 8 are free to use if PR bit = 1.
Thanks,
Wei
Quoted 202 lines
An alternative to enabling
mem_accesson AMD processors will be to limit the access types to 3 bits. This would force disabling support for two modes. I'm inclined to disable two out of X, W and WX. I don't think they make sense without R permissions.
Thanks!
AndresQuoted 192 lines
Thanks,
WeiQuoted 185 lines
Finally, the triple fault. Maybe I'm missing something obvious. Comments welcome.
Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla<[email protected]>Signed-off-by Adin Scannell<[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +2
-0@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff
+ * value tramples over the higher-order bits used for flags (NX, p2mt,
+ * etc.) This happens for paging entries. Thus we do this clip/unclip
+ * juggle for l1 entries only (no paging superpages!) */xen/arch/x86/mm/p2m-pt.c +16
-3+#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn)& ((1UL<< EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content = l1e_empty();xen/arch/x86/mm/p2m-pt.c +1
-1@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +15
-6@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram (p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping * exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e)& _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); +return (l1t == p2m_ram_paging_out) ? mfn :_mfn (INVALID_MFN ); }mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +2
-2@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS>= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) *L1_PAGETABLE_ENTRIES ;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry(p2m, gfn,&l1e[i1],l1mfn, l1e_content, 1); }xen/arch/x86/mm/p2m-pt.c +1
-1@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn&&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 41 lines · Andres Lagar-Cavilla
Quoted 29 lines
Quoted 29 lines · Andres Lagar-Cavilla
Quoted 27 lines
We started hashing out some AMD support for
mem_pagingandmem_access. Right now my VMs boot, page out a bit, and then die on an HVM triple fault.Most importantly, I want to get somebody from AMD to comment/help out on
this. It feels like we're inches away from enabling support for this very
nice feature. I'm not sure who exactly on AMD monitors the list for these
kinds of things. It'd be great to have you on board!For starters, the changes to the p2m code are relatively mild, but it'd
be
great if somebody spots a red flag.Another issue: comments indicate that bits 59-62 in NPT entries are used
for IOMMU flags but effectively bits 61-62 are. Repossessing one bit
(59)
would give us enough space to supportmem_access. Right now we only have
7
bits available for Xen flags and that is not enough for paging and access.
Is bit 59 effectively reserved?Quoted 8 lines
Quoted 5 lines
Hi
bit 59 is used by iommu hardware for ATS response. In most cases, forp2m_ram_rwpages, U bit must be 0. But maybe for other page types that are not potentially used by DMA, this bit could be non-zero. I could tested it on my iommu machines if you had some patches that use U bits.Hi Wei, thanks for pitching in! I assume you're talking about table 14 (and fig 9) in http://support.amd.com/us/Processor_TechDocs/48882.pdf
Yes, indeed.
Quoted 7 lines
Quoted 3 lines
I don't think this will work. The p2m access value is arbitrary, and independent of the p2m type. So bit 59 is out of reach and we're stuck with 7 bits for Xen use. Thanks for the clarification.
Where will p2m access bit be stored? Please note that bit 52 - bit 58 for pte must be zero for
p2m_ram_rwpages. For iommu pte, only bit 63 and bit 1 - bit 8 are free to use if PR bit = 1.
Wei,
Why *must* bits 52-58 be zero for p2m_ram_rw pages? Or is it just the current convention?
I propose limiting p2m type to bits 52-55, and storing p2m access on bits 56-58. So, p2m_ram_rw pages with a non-zero access would break the "must be zero" requirement/convention.
Right now, without any considerations for paging, we're storing the p2m type in bits 52-58 when PR=1. That p2m type can be non zero. p2m_ram_ro, p2m_mmio_dm, p2m_logdirty, p2m_populate_on_demand are all par for the course. Given your statement above, and table 14 in the IOMMU manual, how is this even working? Or is it not working?
Would a violation of these rules cause a VMEXIT_SHUTDOWN?
Thanks a lot for the info!
Andres
Quoted 214 lines
Thanks,
WeiQuoted 207 lines
An alternative to enabling
mem_accesson AMD processors will be to limit the access types to 3 bits. This would force disabling support for two modes. I'm inclined to disable two out of X, W and WX. I don't think they
make sense without R permissions.
Thanks!
AndresQuoted 196 lines
Thanks,
WeiQuoted 189 lines
Finally, the triple fault. Maybe I'm missing something obvious. Comments
welcome.Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla<[email protected]>Signed-off-by Adin Scannell<[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +2
-0@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff
+ * value tramples over the higher-order bits used for flags (NX, p2mt,
+ * etc.) This happens for paging entries. Thus we do this clip/unclip
+ * juggle for l1 entries only (no paging superpages!) */xen/arch/x86/mm/p2m-pt.c +16
-3+#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn)& ((1UL<< EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content = l1e_empty();xen/arch/x86/mm/p2m-pt.c +1
-1@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +15
-6@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram (p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping * exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e)& _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); +return (l1t == p2m_ram_paging_out) ? mfn :_mfn (INVALID_MFN );} mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +2
-2@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS>= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) *L1_PAGETABLE_ENTRIES ;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry(p2m, gfn,&l1e[i1],l1mfn, l1e_content, 1); }xen/arch/x86/mm/p2m-pt.c +1
-1@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn&&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 4 lines · Andres Lagar-Cavilla
Quoted 3 lines
Where will p2m access bit be stored? Please note that bit 52 - bit 58 for pte must be zero for
p2m_ram_rwpages. For iommu pte, only bit 63 and bit 1 - bit 8 are free to use if PR bit = 1.
Quoted 8 lines
Wei,
Why *must* bits 52-58 be zero for
p2m_ram_rwpages? Or is it just the current convention?I propose limiting p2m type to bits 52-55, and storing p2m access on bits 56-58. So,
p2m_ram_rwpages with a non-zero access would break the "must be zero" requirement/convention.
Eh, let's step back a bit from this. The problem is that the IOMMU can't handle these bits being set, but the IOMMU can't handle paged-out or CoW memory either (because there's no way to cause the peripheral to retry a DMA that faulted).
So can we just say that any VM that's going to use paging, sharing or access can't have a unified p2m and IOMMU table? That's a bit ugly since the admin will have to make the choice, but it seems like the hardware is forcing us into it.
Maybe the sensible choice is to default to _not_ sharing p2m and IOMMU tables, and have thet be something an expert user can turn on (and which disables the other features)?
Should we have a hypervisor-level interlock between PCI passthrough and paging/sharing/access anyway? Doing both is unlikely to lead to happiness.
Tim.
Quoted 226 lines
Right now, without any considerations for paging, we're storing the p2m type in bits 52-58 when PR=1. That p2m type can be non zero.
p2m_ram_ro,p2m_mmio_dm,p2m_logdirty,p2m_populate_on_demandare all par for the course. Given your statement above, and table 14 in the IOMMU manual, how is this even working? Or is it not working?Would a violation of these rules cause a
VMEXIT_SHUTDOWN?Thanks a lot for the info!
AndresQuoted 214 lines
Thanks,
WeiQuoted 207 lines
An alternative to enabling
mem_accesson AMD processors will be to limit the access types to 3 bits. This would force disabling support for two modes. I'm inclined to disable two out of X, W and WX. I don't think they
make sense without R permissions.
Thanks!
AndresQuoted 196 lines
Thanks,
WeiQuoted 189 lines
Finally, the triple fault. Maybe I'm missing something obvious. Comments
welcome.Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla<[email protected]>Signed-off-by Adin Scannell<[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +2
-0@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff
+ * value tramples over the higher-order bits used for flags (NX, p2mt,
+ * etc.) This happens for paging entries. Thus we do this clip/unclip
+ * juggle for l1 entries only (no paging superpages!) */xen/arch/x86/mm/p2m-pt.c +16
-3+#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn)& ((1UL<< EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content = l1e_empty();xen/arch/x86/mm/p2m-pt.c +1
-1@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +15
-6@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram (p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping * exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e)& _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); +return (l1t == p2m_ram_paging_out) ? mfn :_mfn (INVALID_MFN );} mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +2
-2@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS>= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) *L1_PAGETABLE_ENTRIES ;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry(p2m, gfn,&l1e[i1],l1mfn, l1e_content, 1); }xen/arch/x86/mm/p2m-pt.c +1
-1@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn&&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 25 lines
Quoted 6 lines · Andres Lagar-Cavilla
Quoted 3 lines
Where will p2m access bit be stored? Please note that bit 52 - bit 58 for pte must be zero for
p2m_ram_rwpages. For iommu pte, only bit 63 and bit 1 - bit 8 are free to use if PR bit = 1.Wei,
Quoted 7 lines
Why *must* bits 52-58 be zero for
p2m_ram_rwpages? Or is it just the current convention?I propose limiting p2m type to bits 52-55, and storing p2m access on bits
56-58. So,p2m_ram_rwpages with a non-zero access would break the "must be zero" requirement/convention.Eh, let's step back a bit from this. The problem is that the IOMMU can't handle these bits being set, but the IOMMU can't handle paged-out or CoW memory either (because there's no way to cause the peripheral to retry a DMA that faulted).
So can we just say that any VM that's going to use paging, sharing or access can't have a unified p2m and IOMMU table? That's a bit ugly since the admin will have to make the choice, but it seems like the hardware is forcing us into it.
Quoted 7 lines
Maybe the sensible choice is to default to _not_ sharing p2m and IOMMU tables, and have thet be something an expert user can turn on (and which disables the other features)?
Should we have a hypervisor-level interlock between PCI passthrough and paging/sharing/access anyway? Doing both is unlikely to lead to happiness.
That's basically my thinking, these are mutually exclusive conditions. And I'm curious as to whether that is causing the triple fault that's killing my domains. You seem to imply that p2m+IOMMU unification is turned on by default -- that would crash PoD domains on AMD, wouldn't it?
Andres
Quoted 243 lines
Tim.
Quoted 239 lines
Right now, without any considerations for paging, we're storing the p2m type in bits 52-58 when PR=1. That p2m type can be non zero.
p2m_ram_ro,p2m_mmio_dm,p2m_logdirty,p2m_populate_on_demandare all par for the course. Given your statement above, and table 14 in the IOMMU manual, how
is this even working? Or is it not working?Would a violation of these rules cause a
VMEXIT_SHUTDOWN?Thanks a lot for the info!
AndresQuoted 5 lines
Thanks,
WeiQuoted 1 line
An alternative to enabling
mem_accesson AMD processors will be tolimit
Quoted 1 line
Quoted 1 line
the access types to 3 bits. This would force disabling support for
two
Quoted 30 lines
Quoted 30 lines
modes. I'm inclined to disable two out of X, W and WX. I don't think they
make sense without R permissions.
Thanks!
AndresQuoted 24 lines
Thanks,
WeiQuoted 20 lines
Finally, the triple fault. Maybe I'm missing something obvious. Comments
welcome.Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla<[email protected]>Signed-off-by Adin Scannell<[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-0@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ;Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/mm/mem_event.c +0
-4-/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;Quoted 8 lines
Quoted 8 lines
xen/arch/x86/mm/p2m-pt.c line 54
Quoted 8 lines
xen/arch/x86/mm/mem_event.c +0
-0/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +0
-0@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY |
_PAGE_ACCESSED)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/mm/p2m-pt.c +2
-0+#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff
+ * value tramples over the higher-order bits used for flags (NX, p2mt,
+ * etc.) This happens for paging entries. Thus we do thisclip/unclip
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
xen/arch/x86/mm/p2m-pt.c
Quoted 3 lines
+ * juggle for l1 entries only (no paging superpages!) */
xen/arch/x86/mm/p2m-pt.c +2
-0+#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn)& ((1UL<< EFF_MFN_WIDTH) -1))
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+#define
unclip_mfn(mfn)((clipped_mfn((mfn)) ==INVALID_MFN) ?\
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
xen/arch/x86/mm/p2m-pt.c +10
-1+ INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry);Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-pt.c p2m_set_entry(struct p2m_domain *p2m, un
Quoted 4 lines
xen/arch/x86/mm/p2m-pt.c +2
-2-if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content = l1e_from_pfn(mfn_x(mfn), + if ( mfn_valid(mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt ==
p2m_ram_paging_in) )Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/mm/p2m-pt.c +1
-0+ entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn)); elseentry_content = l1e_empty();xen/arch/x86/mm/p2m-pt.c +1
-1@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +0
-0@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-pt.c pod_retry_l1: · line 619
Quoted 4 lines
xen/arch/x86/mm/p2m-pt.c +1
-1if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); - ASSERT(l1e_get_pfn(l1e) != INVALID_MFN ||!p2m_is_ram(p2mt));
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
xen/arch/x86/mm/p2m-pt.c pod_retry_l1: · line 639
Quoted 2 lines
xen/arch/x86/mm/p2m-pt.c +2
-0+ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn == INVALID_MFN&& p2m_is_paging(p2mt)));
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/mm/p2m-pt.c pod_retry_l1: · line 642
Quoted 6 lines
xen/arch/x86/mm/p2m-pt.c +1
-2-if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
xen/arch/x86/mm/p2m-pt.c +10
-2* exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e)& _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
xen/arch/x86/mm/p2m-pt.c pod_retry_l2: · line 827
Quoted 3 lines
xen/arch/x86/mm/p2m-pt.c +1
-1unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); + return (l1t == p2m_ram_paging_out) ? mfn :
_mfn(INVALID_MFN);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
} mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +0
-1@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/mm/p2m-pt.c static void p2m_change_type_global(struc · line 952
Quoted 8 lines
xen/arch/x86/mm/p2m-pt.c +1
-0+ mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS>= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) *L1_PAGETABLE_ENTRIES ;/* create a new 1le entry with the new type */
Quoted 32 lines
Quoted 29 lines
Quoted 26 lines
Quoted 23 lines
xen/arch/x86/mm/p2m-pt.c +1
-1flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry(p2m, gfn,&l1e[i1],l1mfn, l1e_content, 1); }xen/arch/x86/mm/p2m-pt.c +1
-1@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn&&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines · Andres Lagar-Cavilla
That's basically my thinking, these are mutually exclusive conditions. And I'm curious as to whether that is causing the triple fault that's killing my domains.
I doubt it - at least not directly. Have you passed through a PCI[e] card to them?
Quoted 2 lines
You seem to imply that p2m+IOMMU unification is turned on by default -- that would crash PoD domains on AMD, wouldn't it?
Only PoD + passthrough, if you happened to DMA to a non-populated address. But the same is true on Intel (though not all Intel h/w has compatible EPT and VT-D tables).
Cheers,
Tim.
Am 15.02.2012 18:02, schrieb Tim Deegan:
Quoted 19 lines
Quoted 4 lines · Andres Lagar-Cavilla
Quoted 3 lines
Where will p2m access bit be stored? Please note that bit 52 - bit 58 for pte must be zero for
p2m_ram_rwpages. For iommu pte, only bit 63 and bit 1 - bit 8 are free to use if PR bit = 1.Quoted 8 lines
Wei,
Why *must* bits 52-58 be zero for
p2m_ram_rwpages? Or is it just the current convention?I propose limiting p2m type to bits 52-55, and storing p2m access on bits 56-58. So,
p2m_ram_rwpages with a non-zero access would break the "must be zero" requirement/convention.Eh, let's step back a bit from this. The problem is that the IOMMU can't handle these bits being set, but the IOMMU can't handle paged-out or CoW memory either (because there's no way to cause the peripheral to retry a DMA that faulted).
Quoted 4 lines
So can we just say that any VM that's going to use paging, sharing or access can't have a unified p2m and IOMMU table? That's a bit ugly since the admin will have to make the choice, but it seems like the hardware is forcing us into it.
Seems true. Although iommuv2 support demand paging, it only works for guest OS process context. And we also need support from device side to do that.
Quoted 4 lines
Maybe the sensible choice is to default to _not_ sharing p2m and IOMMU tables, and have thet be something an expert user can turn on (and which disables the other features)?
That looks good to me.
Quoted 2 lines
Should we have a hypervisor-level interlock between PCI passthrough and paging/sharing/access anyway? Doing both is unlikely to lead to happiness.
I think we should. DMA might result miserable errors when paging happens.
Thanks
Wei
Quoted 229 lines
Tim.
Quoted 226 lines
Right now, without any considerations for paging, we're storing the p2m type in bits 52-58 when PR=1. That p2m type can be non zero.
p2m_ram_ro,p2m_mmio_dm,p2m_logdirty,p2m_populate_on_demandare all par for the course. Given your statement above, and table 14 in the IOMMU manual, how is this even working? Or is it not working?Would a violation of these rules cause a
VMEXIT_SHUTDOWN?Thanks a lot for the info!
AndresQuoted 214 lines
Thanks,
WeiQuoted 207 lines
An alternative to enabling
mem_accesson AMD processors will be to limit the access types to 3 bits. This would force disabling support for two modes. I'm inclined to disable two out of X, W and WX. I don't think they
make sense without R permissions.
Thanks!
AndresQuoted 196 lines
Thanks,
WeiQuoted 189 lines
Finally, the triple fault. Maybe I'm missing something obvious. Comments
welcome.Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla<[email protected]>Signed-off-by Adin Scannell<[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +2
-0@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff
+ * value tramples over the higher-order bits used for flags (NX, p2mt,
+ * etc.) This happens for paging entries. Thus we do this clip/unclip
+ * juggle for l1 entries only (no paging superpages!) */xen/arch/x86/mm/p2m-pt.c +16
-3+#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn)& ((1UL<< EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content = l1e_empty();xen/arch/x86/mm/p2m-pt.c +1
-1@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +15
-6@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram (p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping * exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e)& _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); +return (l1t == p2m_ram_paging_out) ? mfn :_mfn (INVALID_MFN );} mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +2
-2@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS>= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) *L1_PAGETABLE_ENTRIES ;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry(p2m, gfn,&l1e[i1],l1mfn, l1e_content, 1); }xen/arch/x86/mm/p2m-pt.c +1
-1@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn&&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 58 lines · Andres Lagar-Cavilla
Quoted 41 lines · Andres Lagar-Cavilla
Quoted 29 lines
Quoted 29 lines · Andres Lagar-Cavilla
Quoted 27 lines
We started hashing out some AMD support for
mem_pagingandmem_access. Right now my VMs boot, page out a bit, and then die on an HVM triple fault.Most importantly, I want to get somebody from AMD to comment/help out on
this. It feels like we're inches away from enabling support for this very
nice feature. I'm not sure who exactly on AMD monitors the list for these
kinds of things. It'd be great to have you on board!For starters, the changes to the p2m code are relatively mild, but it'd
be
great if somebody spots a red flag.Another issue: comments indicate that bits 59-62 in NPT entries are used
for IOMMU flags but effectively bits 61-62 are. Repossessing one bit
(59)
would give us enough space to supportmem_access. Right now we only have
7
bits available for Xen flags and that is not enough for paging and access.
Is bit 59 effectively reserved?Quoted 8 lines
Quoted 5 lines
Hi
bit 59 is used by iommu hardware for ATS response. In most cases, forp2m_ram_rwpages, U bit must be 0. But maybe for other page types that are not potentially used by DMA, this bit could be non-zero. I could tested it on my iommu machines if you had some patches that use U bits.Hi Wei, thanks for pitching in! I assume you're talking about table 14 (and fig 9) in http://support.amd.com/us/Processor_TechDocs/48882.pdf
Yes, indeed.
Quoted 7 lines
Quoted 3 lines
I don't think this will work. The p2m access value is arbitrary, and independent of the p2m type. So bit 59 is out of reach and we're stuck with 7 bits for Xen use. Thanks for the clarification.
Where will p2m access bit be stored? Please note that bit 52 - bit 58 for pte must be zero for
p2m_ram_rwpages. For iommu pte, only bit 63 and bit 1 - bit 8 are free to use if PR bit = 1.Wei,
Why *must* bits 52-58 be zero for
p2m_ram_rwpages? Or is it just the current convention?I propose limiting p2m type to bits 52-55, and storing p2m access on bits 56-58. So,
p2m_ram_rwpages with a non-zero access would break the "must be zero" requirement/convention.
Quoted 5 lines
Right now, without any considerations for paging, we're storing the p2m type in bits 52-58 when PR=1. That p2m type can be non zero.
p2m_ram_ro,p2m_mmio_dm,p2m_logdirty,p2m_populate_on_demandare all par for the course. Given your statement above, and table 14 in the IOMMU manual, how is this even working? Or is it not working?
It works because only p2m_ram_rw (which is 0) pages suppose to be used by DMA. But, indeed, if iommu tries to access pages with non-zero types, like p2m_ram_ro,,it will have io page faults. It seems that we don't have use cases like this.
If mem access bits are independent to p2m types, I think we might have a few solutions here:
1) reverse iommu pt sharing for amd iommu totally.
2) disable iommu pt sharing when xen paging enabled.
I am open for both of them.
Thanks,
Wei
Quoted 221 lines
Would a violation of these rules cause a
VMEXIT_SHUTDOWN?Thanks a lot for the info!
AndresQuoted 214 lines
Thanks,
WeiQuoted 207 lines
An alternative to enabling
mem_accesson AMD processors will be to limit the access types to 3 bits. This would force disabling support for two modes. I'm inclined to disable two out of X, W and WX. I don't think they
make sense without R permissions.
Thanks!
AndresQuoted 196 lines
Thanks,
WeiQuoted 189 lines
Finally, the triple fault. Maybe I'm missing something obvious. Comments
welcome.Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla<[email protected]>Signed-off-by Adin Scannell<[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +2
-0@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff
+ * value tramples over the higher-order bits used for flags (NX, p2mt,
+ * etc.) This happens for paging entries. Thus we do this clip/unclip
+ * juggle for l1 entries only (no paging superpages!) */xen/arch/x86/mm/p2m-pt.c +16
-3+#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn)& ((1UL<< EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content = l1e_empty();xen/arch/x86/mm/p2m-pt.c +1
-1@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +15
-6@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram (p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping * exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e)& _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); +return (l1t == p2m_ram_paging_out) ? mfn :_mfn (INVALID_MFN );} mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +2
-2@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS>= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) *L1_PAGETABLE_ENTRIES ;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry(p2m, gfn,&l1e[i1],l1mfn, l1e_content, 1); }xen/arch/x86/mm/p2m-pt.c +1
-1@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn&&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 71 lines · Andres Lagar-Cavilla
Quoted 63 lines
Quoted 45 lines · Andres Lagar-Cavilla
Quoted 39 lines
Quoted 31 lines · Andres Lagar-Cavilla
Quoted 19 lines
We started hashing out some AMD support for
mem_pagingandmem_access.
Right now my VMs boot, page out a bit, and then die on an HVM triple fault.Most importantly, I want to get somebody from AMD to comment/help out
on
this. It feels like we're inches away from enabling support for this very
nice feature. I'm not sure who exactly on AMD monitors the list for these
kinds of things. It'd be great to have you on board!For starters, the changes to the p2m code are relatively mild, but it'd
be
great if somebody spots a red flag.Quoted 10 lines
Another issue: comments indicate that bits 59-62 in NPT entries are used
for IOMMU flags but effectively bits 61-62 are. Repossessing one bit
(59)
would give us enough space to supportmem_access. Right now we only have
7
bits available for Xen flags and that is not enough for paging and access.
Is bit 59 effectively reserved?Quoted 7 lines
Hi
bit 59 is used by iommu hardware for ATS response. In most cases, forp2m_ram_rwpages, U bit must be 0. But maybe for other page types that
are not potentially used by DMA, this bit could be non-zero. I could tested it on my iommu machines if you had some patches that use U bits.Quoted 2 lines
Hi Wei, thanks for pitching in! I assume you're talking about table 14 (and fig 9) in http://support.amd.com/us/Processor_TechDocs/48882.pdf
Yes, indeed.
Quoted 7 lines
Quoted 3 lines
I don't think this will work. The p2m access value is arbitrary, and independent of the p2m type. So bit 59 is out of reach and we're stuck with 7 bits for Xen use. Thanks for the clarification.
Where will p2m access bit be stored? Please note that bit 52 - bit 58 for pte must be zero for
p2m_ram_rwpages. For iommu pte, only bit 63 and bit 1 - bit 8 are free to use if PR bit = 1.Wei,
Why *must* bits 52-58 be zero for
p2m_ram_rwpages? Or is it just the current convention?I propose limiting p2m type to bits 52-55, and storing p2m access on bits
56-58. So,p2m_ram_rwpages with a non-zero access would break the "must be zero" requirement/convention.Quoted 6 lines
Right now, without any considerations for paging, we're storing the p2m type in bits 52-58 when PR=1. That p2m type can be non zero.
p2m_ram_ro,p2m_mmio_dm,p2m_logdirty,p2m_populate_on_demandare all par for the course. Given your statement above, and table 14 in the IOMMU manual, how
is this even working? Or is it not working?
Quoted 5 lines
It works because only
p2m_ram_rw(which is 0) pages suppose to be used by DMA. But, indeed, if iommu tries to access pages with non-zero types, like p2m_ram_ro,,it will have io page faults. It seems that we don't have use cases like this.
I guess no one unleashed log dirty on a domain doing DMA. Rightly so.
Quoted 6 lines
If mem access bits are independent to p2m types, I think we might have a few solutions here:
1) reverse iommu pt sharing for amd iommu totally.
2) disable iommu pt sharing when xen paging enabled.I am open for both of them.
Great. When I get back to this, I'll look into making the two feature sets mutually exclusive. And then we can enjoy full mem_access on AMD platforms.
Thanks,
Andres
Quoted 241 lines
Thanks,
Wei
Quoted 232 lines
Would a violation of these rules cause a
VMEXIT_SHUTDOWN?Thanks a lot for the info!
AndresQuoted 225 lines
Thanks,
WeiQuoted 218 lines
An alternative to enabling
mem_accesson AMD processors will be to limit
the access types to 3 bits. This would force disabling support for two modes. I'm inclined to disable two out of X, W and WX. I don't think they
make sense without R permissions.
Thanks!
AndresQuoted 206 lines
Thanks,
WeiQuoted 199 lines
Finally, the triple fault. Maybe I'm missing something obvious. Comments
welcome.Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla<[email protected]>Signed-off-by Adin Scannell<[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +2
-0@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff
+ * value tramples over the higher-order bits used for flags (NX, p2mt,
+ * etc.) This happens for paging entries. Thus we do this clip/unclip
+ * juggle for l1 entries only (no paging superpages!) */xen/arch/x86/mm/p2m-pt.c +2
-0+#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn)& ((1UL<< EFF_MFN_WIDTH) -1))
+#defineunclip_mfn(mfn)((clipped_mfn((mfn)) ==INVALID_MFN) ?
\xen/arch/x86/mm/p2m-pt.c +13
-3+ INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content = l1e_empty();xen/arch/x86/mm/p2m-pt.c +1
-1@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +4
-3@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram(p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that themapping
* exits at this point. */xen/arch/x86/mm/p2m-pt.c +11
-3@@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e)& _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); + return (l1t == p2m_ram_paging_out) ? mfn :_mfn(INVALID_MFN); } mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +2
-2@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS>= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) *L1_PAGETABLE_ENTRIES ;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags);p2m->write_p2m_entry(p2m, gfn,&l1e[i1], l1mfn, l1e_content, 1); }xen/arch/x86/mm/p2m-pt.c +1
-1@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn&&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 159 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Andres Lagar-Cavilla
Sent: Wednesday, February 15, 2012 3:05 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [Xen-devel] RFC: AMD support for pagingWe started hashing out some AMD support for
mem_pagingandmem_access. Right now my VMs boot, page out a bit, and then die on an HVM triple fault.Most importantly, I want to get somebody from AMD to comment/help out on this. It feels like we're inches away from enabling support for this very nice feature. I'm not sure who exactly on AMD monitors the list for these kinds of things. It'd be great to have you on board!
For starters, the changes to the p2m code are relatively mild, but it'd be great if somebody spots a red flag.
Another issue: comments indicate that bits 59-62 in NPT entries are used for IOMMU flags but effectively bits 61-62 are. Repossessing one bit (59) would give us enough space to support
mem_access. Right now we only have 7 bits available for Xen flags and that is not enough for paging and access. Is bit 59 effectively reserved?Finally, the triple fault. Maybe I'm missing something obvious. Comments welcome.
Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla <[email protected]>Signed-off-by Adin Scannell <[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +22
-4@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff +* value tramples over the higher-order bits used for flags (NX, p2mt, +* etc.) This happens for paging entries. Thus we do this clip/unclip +* juggle for l1 entries only (no paging superpages!) */ +#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn) & ((1UL << EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content =l1e_empty ();@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +9
-5@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram (p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping * exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e) & _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) )
xen/arch/x86/mm/p2m-pt.c pod_retry_l2: · line 825
Quoted 10 lines
xen/arch/x86/mm/p2m-pt.c +6
-1+ { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); +return (l1t == p2m_ram_paging_out) ? mfn :_mfn (INVALID_MFN );
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This means when p2mt is p2m_ram_paging_in, the mfn must be INVALID_MFN;
But in p2m_type_to_flags,when p2m_ram_paging_in or p2m_ram_paged, the _PAGE_PRESENT is not set.My idea shows like this:
In p2m_gfn_to_mfn function:
@@ -1370,6 +1379,7 @@
paddr_t addr = ((paddr_t)gfn) << PAGE_SHIFT;
l2_pgentry_t *l2e;
l1_pgentry_t *l1e;+ unsigned long flags;
ASSERT(paging_mode_translate(d));
@@ -1455,7 +1465,8 @@
l1e = map_domain_page(mfn_x(mfn));
l1e += l1_table_offset(addr);
pod_retry_l1:
- if ( (l1e_get_flags(*l1e) & _PAGE_PRESENT) == 0 )
+ flags = l1e_get_flags(*l1e);
+ if ((( flags & _PAGE_PRESENT) == 0) && (!p2m_is_paging(p2m_flags_to_type(flags))))
{
/* PoD: Try to populate */
if ( p2m_flags_to_type(l1e_get_flags(*l1e)) == p2m_populate_on_demand )
{
if ( q != p2m_query ) {
if ( !p2m_pod_check_and_populate(p2m, gfn,
(l1_pgentry_t *)l1e, PAGE_ORDER_4K, q) )
goto pod_retry_l1;
} else
*t = p2m_populate_on_demand;
}
unmap_domain_page(l1e);
return _mfn(INVALID_MFN);
}
mfn = _mfn(l1e_get_pfn(*l1e));
*t = p2m_flags_to_type(l1e_get_flags(*l1e));
unmap_domain_page(l1e);Quoted 36 lines
xen/arch/x86/mm/p2m-pt.c +0
-0} mfn =_mfn (l1e_get_pfn (*l1e));*t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +3
-3@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS >= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) * L1_PAGETABLE_ENTRIES;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry (p2m, gfn, &l1e[i1], l1mfn, l1e_content,1 ); }@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn &&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 177 lines
Quoted 177 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Andres Lagar-Cavilla
Sent: Wednesday, February 15, 2012 3:05 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [Xen-devel] RFC: AMD support for pagingWe started hashing out some AMD support for
mem_pagingandmem_access. Right now my VMs boot, page out a bit, and then die on an HVM triple fault.Most importantly, I want to get somebody from AMD to comment/help out on this. It feels like we're inches away from enabling support for this very
nice feature. I'm not sure who exactly on AMD monitors the list for these
kinds of things. It'd be great to have you on board!For starters, the changes to the p2m code are relatively mild, but it'd be
great if somebody spots a red flag.Another issue: comments indicate that bits 59-62 in NPT entries are used for IOMMU flags but effectively bits 61-62 are. Repossessing one bit
(59)
would give us enough space to supportmem_access. Right now we only have 7
bits available for Xen flags and that is not enough for paging and access.
Is bit 59 effectively reserved?Finally, the triple fault. Maybe I'm missing something obvious. Comments welcome.
Patch inline below, thanks!
AndresEnable AMD support for paging.
Signed-off-by Andres Lagar-Cavilla <[email protected]>Signed-off-by Adin Scannell <[email protected]>diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/mem_event.cxen/arch/x86/mm/mem_event.c +0
-4@@ -537,10 +537,6 @@ int mem_event_domctl(struct domain *d, xif ( !hap_enabled (d) )break ; -/* Currently only EPT is supported */ -if ( boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL ) -break ; - rc = -EXDEV ;/* Disallow paging in a PoD guest */ if ( p2m->pod.entry_count )diff -r
25ca78889ed4-r10ca4e4293cexen/arch/x86/mm/p2m-pt.cxen/arch/x86/mm/p2m-pt.c +2
-0@@ -53,6 +53,20 @@#define P2M_BASE_FLAGS \ (_PAGE_PRESENT | _PAGE_USER | _PAGE_DIRTY | _PAGE_ACCESSED) +#ifdef __x86_64__ +/* l1e_from_pfn is not designed to have INVALID_MFN stored. The 0xff..ff
+ * value tramples over the higher-order bits used for flags (NX, p2mt,
+ * etc.) This happens for paging entries. Thus we do this clip/unclip
+ * juggle for l1 entries only (no paging superpages!) */xen/arch/x86/mm/p2m-pt.c +17
-4+#define EFF_MFN_WIDTH (PADDR_BITS-PAGE_SHIFT)/* 40 bits */ +#define clipped_mfn (mfn) ((mfn) & ((1UL << EFF_MFN_WIDTH) - 1)) +#define unclip_mfn (mfn) ((clipped_mfn((mfn)) == INVALID_MFN) ? \ + INVALID_MFN : (mfn)) +#else +#define clipped_mfn (mfn) (mfn) +#define unclip_mfn (mfn) (mfn) +#endif /* __x86_64__ */ +static unsigned long p2m_type_to_flags (p2m_type_t t,mfn_t mfn) {unsigned long flags;@@ -77,6 +91,9 @@ static unsigned long p2m_type_to_flags(pcase p2m_invalid:case p2m_mmio_dm:case p2m_populate_on_demand: +case p2m_ram_paging_out: +case p2m_ram_paged: +case p2m_ram_paging_in:default :return flags;case p2m_ram_ro:@@ -168,7 +185,7 @@ p2m_next_level(struct p2m_domain *p2m, m shift, max)) )return 0 ; -/* PoD: Not present doesn't imply empty. */ +/* PoD/paging: Not present doesn't imply empty. */ if ( !l1e_get_flags (*p2m_entry) ) {struct page_info *pg;@@ -384,8 +401,9 @@ p2m_set_entry(struct p2m_domain *p2m, un 0, L1_PAGETABLE_ENTRIES);ASSERT (p2m_entry); -if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) ) - entry_content =l1e_from_pfn (mfn_x (mfn), +if (mfn_valid (mfn) || (p2mt == p2m_mmio_direct) || + (p2mt == p2m_ram_paged) || (p2mt == p2m_ram_paging_in) ) + entry_content =l1e_from_pfn (clipped_mfn (mfn_x (mfn)),p2m_type_to_flags (p2mt, mfn));else entry_content =l1e_empty ();@@ -393,7 +411,7 @@ p2m_set_entry(struct p2m_domain *p2m, unif ( entry_content.l1 !=0 ) {p2m_add_iommu_flags (&entry_content,0 , iommu_pte_flags); - old_mfn =l1e_get_pfn (*p2m_entry); + old_mfn =unclip_mfn (l1e_get_pfn (*p2m_entry)); }/* level 1 entry */ p2m->write_p2m_entry(p2m, gfn, p2m_entry, table_mfn,
entry_content, 1);xen/arch/x86/mm/p2m-pt.c +14
-5@@ -615,11 +633,12 @@ pod_retry_l1: sizeof(l1e));if ( ret ==0 ) { +unsigned long l1e_mfn =unclip_mfn (l1e_get_pfn (l1e)); p2mt =p2m_flags_to_type (l1e_get_flags (l1e)); -ASSERT (l1e_get_pfn (l1e) !=INVALID_MFN || !p2m_is_ram (p2mt)); +ASSERT ( (l1e_mfn !=INVALID_MFN || !p2m_is_ram (p2mt)) || + (l1e_mfn ==INVALID_MFN &&p2m_is_paging (p2mt)) ); -if (p2m_flags_to_type (l1e_get_flags (l1e)) - == p2m_populate_on_demand ) +if ( p2mt == p2m_populate_on_demand ) {/* The read has succeeded, so we know that the mapping * exits at this point. */ @@ -641,7 +660,7 @@ pod_retry_l1: }if (p2m_is_valid (p2mt) ||p2m_is_grant (p2mt) ) - mfn =_mfn (l1e_get_pfn (l1e)); + mfn =_mfn (l1e_mfn);else /* XXX see above */ p2mt = p2m_mmio_dm;@@ -783,18 +802,26 @@ pod_retry_l2: pod_retry_l1:if ( (l1e_get_flags (*l1e) & _PAGE_PRESENT) ==0 ) { +p2m_type_t l1t =p2m_flags_to_type (l1e_get_flags (*l1e));/* PoD: Try to populate */ -if (p2m_flags_to_type (l1e_get_flags (*l1e)) == p2m_populate_on_demand ) +if ( l1t == p2m_populate_on_demand ) {if ( q != p2m_query ) {if ( !p2m_pod_demand_populate (p2m, gfn,PAGE_ORDER_4K , q) ) goto pod_retry_l1; }else *t = p2m_populate_on_demand; + }else { +if (p2m_is_paging (l1t) ) + { + *t = l1t; +/* No need to unclip due to check below */ + mfn =_mfn (l1e_get_pfn (*l1e)); + } }
Quoted 8 lines
xen/arch/x86/mm/p2m-pt.c pod_retry_l2: · line 826
Quoted 3 lines
xen/arch/x86/mm/p2m-pt.c +1
-1unmap_domain_page (l1e); -return _mfn (INVALID_MFN ); +return (l1t == p2m_ram_paging_out) ? mfn :_mfn (INVALID_MFN );~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This means when p2mt isp2m_ram_paging_in, the mfn must
beINVALID_MFN;
But in p2m_type_to_flags,whenp2m_ram_paging_inorp2m_ram_paged, the_PAGE_PRESENTis not set.
Your patch below looks reasonable. I'll give it a try. Andres
Quoted 83 lines
My idea shows like this:
Inp2m_gfn_to_mfnfunction:(quoted diff) +3
-1@@ -1370,6 +1379,7 @@ paddr_t addr = ((paddr_t)gfn) << PAGE_SHIFT; l2_pgentry_t *l2e; l1_pgentry_t *l1e; + unsigned long flags; ASSERT(paging_mode_translate(d));@@ -1455,7 +1465,8 @@ l1e = map_domain_page(mfn_x(mfn)); l1e += l1_table_offset(addr); pod_retry_l1: - if ( (l1e_get_flags(*l1e) & _PAGE_PRESENT) == 0 ) + flags = l1e_get_flags(*l1e); + if ((( flags & _PAGE_PRESENT) == 0) && (!p2m_is_paging(p2m_flags_to_type(flags)))) { /* PoD: Try to populate */if ( p2m_flags_to_type(l1e_get_flags(*l1e)) == p2m_populate_on_demand ) { if ( q != p2m_query ) { if ( !p2m_pod_check_and_populate(p2m, gfn, (l1_pgentry_t *)l1e, PAGE_ORDER_4K, q) ) goto pod_retry_l1; } else *t = p2m_populate_on_demand; } unmap_domain_page(l1e); return _mfn(INVALID_MFN); } mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e)); unmap_domain_page(l1e);Quoted 38 lines
xen/arch/x86/mm/p2m-pt.c +0
-0}mfn = _mfn(l1e_get_pfn(*l1e)); *t = p2m_flags_to_type(l1e_get_flags(*l1e));xen/arch/x86/mm/p2m-pt.c +2
-2@@ -914,7 +941,7 @@ static void p2m_change_type_global(struc flags =l1e_get_flags (l1e[i1]);if (p2m_flags_to_type (flags) != ot )continue ; - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1])); gfn = i1 + (i2 + (i3 #if CONFIG_PAGING_LEVELS >= 4 + (i4 * L3_PAGETABLE_ENTRIES)@@ -923,7 +950,7 @@ static void p2m_change_type_global(struc * L2_PAGETABLE_ENTRIES) *L1_PAGETABLE_ENTRIES ;/* create a new 1le entry with the new type */ flags =p2m_type_to_flags (nt,_mfn (mfn)); - l1e_content =l1e_from_pfn (mfn, flags); + l1e_content =l1e_from_pfn (clipped_mfn (mfn), flags); p2m->write_p2m_entry(p2m, gfn, &l1e[i1],l1mfn, l1e_content, 1); }xen/arch/x86/mm/p2m-pt.c +1
-1@@ -1073,7 +1100,7 @@ long p2m_pt_audit_p2m(struct p2m_domain entry_count++;continue ; } - mfn =l1e_get_pfn (l1e[i1]); + mfn =unclip_mfn (l1e_get_pfn (l1e[i1]));ASSERT (mfn_valid (_mfn (mfn))); m2pfn =get_gpfn_from_mfn (mfn); if ( m2pfn != gfn &&_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel