x86: add p2m_mmio_write_dm
PATCH v4 1/1 x86: add p2m_mmio_write_dm
XenGT (Intel Graphics Virtualization technology, please refer to
https://01.org/xen/blogs/srclarkx/2013/graphics-virtualization-
xengt) driver runs inside Dom0 as a virtual graphics device model, and needs to trap and emulate the guest's write operations to some specific memory pages, like memory pages used by guest graphics driver as PPGTT(per-process graphics translation table). We agreed to add a new p2m type "p2m_mmio_write_dm" to trap the write operation on these graphic page tables.
Handling of this new p2m type are similar with existing p2m_ram_ro in most condition checks, with only difference on final policy of emulation vs. drop. For p2m_mmio_write_dm type pages, writes will go to the device model via ioreq-server.
Previously, the conclusion in our v3 patch review is to provide a more generalized HVMOP_map_io_range_to_ioreq_server hypercall, by seperating rangesets inside a ioreq server to read-protected/write- protected/both-prtected. Yet, after offline discussion with Paul, we believe a more simplified solution may suffice. We can keep the existing HVMOP_map_io_range_to_ioreq_server hypercall, and let the user decide whether or not a p2m type change is necessary, because in most cases the emulator will already use the p2m_mmio_dm type.
Changes from v3:
- Use the existing HVMOP_map_io_range_to_ioreq_server hypercall to add write protected range.
- Modify the HVMOP_set_mem_type hypercall to support the new p2m type for this range
Changes from v2:
- Remove excute attribute of the new p2m type p2m_mmio_write_dm
- Use existing rangeset for keeping the write protection page range instead of introducing hash table.
- Some code style fix.
Changes from v1:
- Changes the new p2m type name from p2m_ram_wp to p2m_mmio_write_dm. This means that we treat the pages as a special mmio range instead of ram.
- Move macros to c file since only this file is using them.
- Address various comments from Jan.
--- xen/arch/x86/hvm/hvm.c | 13 ++++++++++--- xen/arch/x86/mm/p2m-ept.c | 1 + xen/arch/x86/mm/p2m-pt.c | 1 + xen/include/asm-x86/p2m.h | 1 + xen/include/public/hvm/hvm_op.h | 1 + 5 files changed, 14 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/hvm.c +10 -3
@@ -2838,7 +2838,8 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,* to the mmio handler. */ if ( (p2mt == p2m_mmio_dm) || - (npfec.write_access && (p2mt == p2m_ram_ro)) ) + (npfec.write_access && + ((p2mt == p2m_ram_ro) || (p2mt == p2m_mmio_write_dm))) ) {put_gfn (p2m->domain, gfn);
@@ -5922,6 +5923,8 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) a.mem_type = HVMMEM_ram_rw; else if ( p2m_is_grant(t) ) a.mem_type = HVMMEM_ram_rw; + else if ( t == p2m_mmio_write_dm ) + a.mem_type = HVMMEM_mmio_write_dm; else a.mem_type = HVMMEM_mmio_dm; rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ;
@@ -5941,7 +5944,8 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)static const p2m_type_t memtype[] = { [HVMMEM_ram_rw] = p2m_ram_rw, [HVMMEM_ram_ro] = p2m_ram_ro, - [HVMMEM_mmio_dm] = p2m_mmio_dm + [HVMMEM_mmio_dm] = p2m_mmio_dm, + [HVMMEM_mmio_write_dm] = p2m_mmio_write_dm };if (copy_from_guest (&a, arg,1 ) )
@@ -5987,14 +5991,17 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = -EAGAIN ; goto param_fail4; } +if ( !p2m_is_ram (t) && - (!p2m_is_hole (t) || a.hvmmem_type != HVMMEM_mmio_dm) ) + (!p2m_is_hole (t) || a.hvmmem_type != HVMMEM_mmio_dm) && + t != p2m_mmio_write_dm ) {put_gfn (d, pfn); goto param_fail4; } rc =p2m_change_type_one (d, pfn, t, memtype[a.hvmmem_type]); +put_gfn (d, pfn);if ( rc ) goto param_fail4;
xen/arch/x86/mm/p2m-ept.c +1 -0
@@ -136,6 +136,7 @@ static void ept_p2m_type_to_flags(ept_entry_t *entry, p2m_type_t type, p2m_acces entry->x =0 ;break ;case p2m_grant_map_ro: +case p2m_mmio_write_dm: entry->r =1 ; entry->w = entry->x =0 ;break ;
xen/arch/x86/mm/p2m-pt.c +1 -0
@@ -94,6 +94,7 @@ static unsigned long p2m_type_to_flags(p2m_type_t t, mfn_t mfn)default :return flags | _PAGE_NX_BIT;case p2m_grant_map_ro: +case p2m_mmio_write_dm:return flags |P2M_BASE_FLAGS | _PAGE_NX_BIT;case p2m_ram_ro:case p2m_ram_logdirty:
xen/include/asm-x86/p2m.h +1 -0
@@ -72,6 +72,7 @@ typedef enum { p2m_ram_shared =12 ,/* Shared or sharable memory */ p2m_ram_broken =13 ,/* Broken page, access cause domain crash */ p2m_map_foreign =14 ,/* ram pages from foreign domain */ + p2m_mmio_write_dm =15 ,/* Read-only; writes go to the device model */ } p2m_type_t;/* Modifiers to the query */
xen/include/public/hvm/hvm_op.h +1 -0
@@ -81,6 +81,7 @@ typedef enum { HVMMEM_ram_rw,/* Normal read/write guest RAM */ HVMMEM_ram_ro,/* Read-only; writes are discarded */ HVMMEM_mmio_dm,/* Reads and write go to the device model */ + HVMMEM_mmio_write_dm /* Read-only; writes go to the device model */ } hvmmem_type_t;/* Following tools-only interfaces may change in future. */
Signature · 1 line
1.9.1
xen/arch/x86/hvm/hvm.c int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla, · line 2842
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 28.11.14 at 08:59, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2
-1@@ -2838,7 +2838,8 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,* to the mmio handler. */ if ( (p2mt == p2m_mmio_dm) || - (npfec.write_access && (p2mt == p2m_ram_ro)) ) + (npfec.write_access && + ((p2mt == p2m_ram_ro) || (p2mt == p2m_mmio_write_dm))) )
Why are you corrupting indentation here?
Furthermore the code you modify here suggests that p2m_ram_ro already has the needed semantics - writes get passed to the DM. None of the other changes you make, and none of the other uses of p2m_ram_ro appear to be in conflict with your intentions, so you'd really need to explain better why you need the new type.
Quoted 20 lines
xen/arch/x86/hvm/hvm.c +4
-1@@ -5922,6 +5923,8 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) a.mem_type = HVMMEM_ram_rw; else if ( p2m_is_grant(t) ) a.mem_type = HVMMEM_ram_rw; + else if ( t == p2m_mmio_write_dm ) + a.mem_type = HVMMEM_mmio_write_dm; else a.mem_type = HVMMEM_mmio_dm; rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ;@@ -5941,7 +5944,8 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)static const p2m_type_t memtype[] = { [HVMMEM_ram_rw] = p2m_ram_rw, [HVMMEM_ram_ro] = p2m_ram_ro, - [HVMMEM_mmio_dm] = p2m_mmio_dm + [HVMMEM_mmio_dm] = p2m_mmio_dm, + [HVMMEM_mmio_write_dm] = p2m_mmio_write_dm };if (copy_from_guest (&a, arg,1 ) )
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5994
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +1
-0@@ -5987,14 +5991,17 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = -EAGAIN ; goto param_fail4; } +
Stray addition of a blank line?
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5997
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +2
-1if ( !p2m_is_ram (t) && - (!p2m_is_hole (t) || a.hvmmem_type != HVMMEM_mmio_dm) ) + (!p2m_is_hole (t) || a.hvmmem_type != HVMMEM_mmio_dm) && + t != p2m_mmio_write_dm )
Do you really want to permit e.g. transitions between mmio_dm and mmio_write_dm? We should be as restrictive as possible here to not open up paths to security problems.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 6007
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-0{put_gfn (d, pfn); goto param_fail4; } rc =p2m_change_type_one (d, pfn, t, memtype[a.hvmmem_type]); +put_gfn (d, pfn);if ( rc ) goto param_fail4;
Another stray newline addition.
xen/include/asm-x86/p2m.h typedef enum { · line 78
Quoted 11 lines
xen/include/asm-x86/p2m.h +1
-0@@ -72,6 +72,7 @@ typedef enum { p2m_ram_shared =12 ,/* Shared or sharable memory */ p2m_ram_broken =13 ,/* Broken page, access cause domain crash */ p2m_map_foreign =14 ,/* ram pages from foreign domain */ + p2m_mmio_write_dm =15 ,/* Read-only; writes go to the device model */ } p2m_type_t;/* Modifiers to the query */
If the new type is really needed, shouldn't this get added to P2M_RO_TYPES?
Jan
Quoted 12 lines · Jan Beulich
xen/arch/x86/hvm/hvm.c int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla, · line 2842
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 28.11.14 at 08:59, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2
-1@@ -2838,7 +2838,8 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,* to the mmio handler. */ if ( (p2mt == p2m_mmio_dm) || - (npfec.write_access && (p2mt == p2m_ram_ro)) ) + (npfec.write_access && + ((p2mt == p2m_ram_ro) || (p2mt == p2m_mmio_write_dm))) )Why are you corrupting indentation here?
Thanks for your comments, Jan.
The indentation here is to make sure the
((p2mt == p2m_ram_ro) || (p2mt == p2m_mmio_write_dm)) are grouped together. But I am not sure if this is correct according to xen coding style. I may have misunderstood your previous comments on Sep 3, which said "the indentation would need adjustment" in reply to "[Xen-devel] [PATCH v3 1/2] x86: add p2m_mmio_write_dm"
Quoted 7 lines
Furthermore the code you modify here suggests that
p2m_ram_roalready has the needed semantics - writes get passed to the DM. None of the other changes you make, and none of the other uses ofp2m_ram_roappear to be in conflict with your intentions, so you'd really need to explain better why you need the new type.
Thanks Jan.
To my understanding, pages with p2m_ram_ro are not supposed to be modified by guest. So in __hvm_copy(), when p2m type of a page is p2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.
Maybe I need to update my commit message to explain this more clearly. :)
Quoted 58 lines
Quoted 20 lines
xen/arch/x86/hvm/hvm.c +4
-1@@ -5922,6 +5923,8 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) a.mem_type = HVMMEM_ram_rw; else if ( p2m_is_grant(t) ) a.mem_type = HVMMEM_ram_rw; + else if ( t == p2m_mmio_write_dm ) + a.mem_type = HVMMEM_mmio_write_dm; else a.mem_type = HVMMEM_mmio_dm; rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ;@@ -5941,7 +5944,8 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)static const p2m_type_t memtype[] = { [HVMMEM_ram_rw] = p2m_ram_rw, [HVMMEM_ram_ro] = p2m_ram_ro, - [HVMMEM_mmio_dm] = p2m_mmio_dm + [HVMMEM_mmio_dm] = p2m_mmio_dm, + [HVMMEM_mmio_write_dm] = p2m_mmio_write_dm };if (copy_from_guest (&a, arg,1 ) )xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5994
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +1
-0@@ -5987,14 +5991,17 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = -EAGAIN ; goto param_fail4; } +Stray addition of a blank line?
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5997
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +2
-1if ( !p2m_is_ram (t) && - (!p2m_is_hole (t) || a.hvmmem_type != HVMMEM_mmio_dm) ) + (!p2m_is_hole (t) || a.hvmmem_type != HVMMEM_mmio_dm) && + t != p2m_mmio_write_dm )Do you really want to permit e.g. transitions between
mmio_dmandmmio_write_dm? We should be as restrictive as possible here to not open up paths to security problems.xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 6007
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-0{put_gfn (d, pfn); goto param_fail4; } rc =p2m_change_type_one (d, pfn, t, memtype[a.hvmmem_type]); +put_gfn (d, pfn);if ( rc ) goto param_fail4;Another stray newline addition.
Quoted 9 lines
xen/include/asm-x86/p2m.h +1
-0@@ -72,6 +72,7 @@ typedef enum { p2m_ram_shared =12 ,/* Shared or sharable memory */ p2m_ram_broken =13 ,/* Broken page, access cause domain crash */ p2m_map_foreign =14 ,/* ram pages from foreign domain */ + p2m_mmio_write_dm =15 ,/* Read-only; writes go to the device model */ } p2m_type_t;
Quoted 6 lines
xen/include/asm-x86/p2m.h typedef enum { · line 78
Quoted 2 lines
xen/include/asm-x86/p2m.h +0
-0/* Modifiers to the query */ If the new type is really needed, shouldn't this get added to
P2M_RO_TYPES?
Well, previsouly, I wished to differenciate the HVMMEM_ram_ro and the newly added HVMMEM_mmio_write_dm in the HVMOP_get_mem_type/HVMOP_set_mem_type hypercall. I'd rather think of this new type as write protected than read only. But I'll take a look, to see if this can be added to P2M_RO_TYPES. Thanks.
Yu
Quoted 9 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
xen/arch/x86/hvm/hvm.c int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla, · line 2842
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 28.11.14 at 08:59, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2
-1@@ -2838,7 +2838,8 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,* to the mmio handler. */ if ( (p2mt == p2m_mmio_dm) || - (npfec.write_access && (p2mt == p2m_ram_ro)) ) + (npfec.write_access && + ((p2mt == p2m_ram_ro) || (p2mt == p2m_mmio_write_dm))) )Why are you corrupting indentation here?
Quoted 7 lines
Thanks for your comments, Jan.
The indentation here is to make sure the
((p2mt ==p2m_ram_ro) || (p2mt ==p2m_mmio_write_dm)) are grouped together. But I am not sure if this is correct according to xen coding style. I may have misunderstood your previous comments on Sep 3, which said "the indentation would need adjustment" in reply to "[Xen-devel] [PATCH v3 1/2] x86: addp2m_mmio_write_dm"
Getting the alignment right is needed, but no via using hard tabs.
Quoted 6 lines
Quoted 6 lines
Furthermore the code you modify here suggests that
p2m_ram_roalready has the needed semantics - writes get passed to the DM. None of the other changes you make, and none of the other uses ofp2m_ram_roappear to be in conflict with your intentions, so you'd really need to explain better why you need the new type.
Quoted 9 lines
Thanks Jan.
To my understanding, pages withp2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.
__hvm_copy() is only a helper function, and doesn't write to mmio_dm space either; instead its (indirect) callers would invoke hvmemul_do_mmio() upon seeing HVMCOPY_bad_gfn_to_mfn returns. The question hence is about the apparent inconsistency resulting from writes to ram_ro being dropped here but getting passed to the DM by hvm_hap_nested_page_fault(). Tim - is that really intentional?
Quoted 1 line
Maybe I need to update my commit message to explain this more clearly. :)
At the very least, yes.
Jan
Quoted 40 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
xen/arch/x86/hvm/hvm.c int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla, · line 2842
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 28.11.14 at 08:59, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +2
-1@@ -2838,7 +2838,8 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,* to the mmio handler. */ if ( (p2mt == p2m_mmio_dm) || - (npfec.write_access && (p2mt == p2m_ram_ro)) ) + (npfec.write_access && + ((p2mt == p2m_ram_ro) || (p2mt == p2m_mmio_write_dm))) )Why are you corrupting indentation here?
Quoted 7 lines
Thanks for your comments, Jan.
The indentation here is to make sure the
((p2mt ==p2m_ram_ro) || (p2mt ==p2m_mmio_write_dm)) are grouped together. But I am not sure if this is correct according to xen coding style. I may have misunderstood your previous comments on Sep 3, which said "the indentation would need adjustment" in reply to "[Xen-devel] [PATCH v3 1/2] x86: addp2m_mmio_write_dm"Getting the alignment right is needed, but no via using hard tabs.
Quoted 6 lines
Quoted 6 lines
Furthermore the code you modify here suggests that
p2m_ram_roalready has the needed semantics - writes get passed to the DM. None of the other changes you make, and none of the other uses ofp2m_ram_roappear to be in conflict with your intentions, so you'd really need to explain better why you need the new type.Quoted 9 lines
Thanks Jan.
To my understanding, pages withp2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.
Quoted 7 lines
__hvm_copy()is only a helper function, and doesn't write tommio_dmspace either; instead its (indirect) callers would invokehvmemul_do_mmio()upon seeingHVMCOPY_bad_gfn_to_mfnreturns. The question hence is about the apparent inconsistency resulting from writes toram_robeing dropped here but getting passed to the DM byhvm_hap_nested_page_fault(). Tim - is that really intentional?
No - and AFAICT it shouldn't be happening. It _is_ how it was implemented originally, because it involved fewer moving parts and didn't need to be efficient (and after all, writes to entirely missing addresses go to the device model too).
But the code was later updated to log and discard writes to read-only memory (see 4d8aa29 from Trolle Selander).
Early version of p2m_ram_ro were documented in the internal headers as sending the writes to the DM, but the public interface (HVMMEM_ram_ro) has always said that writes are discarded.
During this bit of archaeology I realised that either this new type should _not_ be made part of P2M_RO_TYPES, or, better, we need a new class of P2M types (P2M_DISCARD_WRITE_TYPES, say) that should be used for these paths in emulate_gva_to_mfn() and __hvm_copy(), containing just p2m_ram_ro and p2m_grant_map_ro.
Cheers,
Tim.
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
To my understanding, pages with
p2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.Quoted 7 lines
__hvm_copy()is only a helper function, and doesn't write tommio_dmspace either; instead its (indirect) callers would invokehvmemul_do_mmio()upon seeingHVMCOPY_bad_gfn_to_mfnreturns. The question hence is about the apparent inconsistency resulting from writes toram_robeing dropped here but getting passed to the DM byhvm_hap_nested_page_fault(). Tim - is that really intentional?No - and AFAICT it shouldn't be happening. It _is_ how it was implemented originally, because it involved fewer moving parts and didn't need to be efficient (and after all, writes to entirely missing addresses go to the device model too).
Quoted 6 lines
But the code was later updated to log and discard writes to read-only memory (see 4d8aa29 from Trolle Selander).
Early version of
p2m_ram_rowere documented in the internal headers as sending the writes to the DM, but the public interface (HVMMEM_ram_ro) has always said that writes are discarded.
Hmm, so which way do you recommend resolving the inconsistency then - match what the public interface says or what the apparent original intention for the internal type was? Presumably we need to follow the public interface mandated model, and hence require the new type to be introduced.
Quoted 5 lines
During this bit of archaeology I realised that either this new type should _not_ be made part of
P2M_RO_TYPES, or, better, we need a new class of P2M types (P2M_DISCARD_WRITE_TYPES, say) that should be used for these paths inemulate_gva_to_mfn()and__hvm_copy(), containing justp2m_ram_roandp2m_grant_map_ro.
And I suppose in that latter case the new type could be made part of P2M_RO_TYPES()?
Jan
Quoted 32 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
To my understanding, pages with
p2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.Quoted 7 lines
__hvm_copy()is only a helper function, and doesn't write tommio_dmspace either; instead its (indirect) callers would invokehvmemul_do_mmio()upon seeingHVMCOPY_bad_gfn_to_mfnreturns. The question hence is about the apparent inconsistency resulting from writes toram_robeing dropped here but getting passed to the DM byhvm_hap_nested_page_fault(). Tim - is that really intentional?No - and AFAICT it shouldn't be happening. It _is_ how it was implemented originally, because it involved fewer moving parts and didn't need to be efficient (and after all, writes to entirely missing addresses go to the device model too).
Quoted 6 lines
But the code was later updated to log and discard writes to read-only memory (see 4d8aa29 from Trolle Selander).
Early version of
p2m_ram_rowere documented in the internal headers as sending the writes to the DM, but the public interface (HVMMEM_ram_ro) has always said that writes are discarded.
Quoted 5 lines
Hmm, so which way do you recommend resolving the inconsistency then - match what the public interface says or what the apparent original intention for the internal type was? Presumably we need to follow the public interface mandated model, and hence require the new type to be introduced.
Sorry, I was unclear -- there isn't an inconsistency; both internal and public headers currently say that writes are discarded and AFAICT that is what the code does.
But yes, we ought to follow the established hypercall interface, and so we need the new type.
Quoted 8 lines
Quoted 5 lines
During this bit of archaeology I realised that either this new type should _not_ be made part of
P2M_RO_TYPES, or, better, we need a new class of P2M types (P2M_DISCARD_WRITE_TYPES, say) that should be used for these paths inemulate_gva_to_mfn()and__hvm_copy(), containing justp2m_ram_roandp2m_grant_map_ro.And I suppose in that latter case the new type could be made part of
P2M_RO_TYPES()?
Yes indeed, as P2M_RO_TYPES is defined as "must have the _PAGE_RW bit clear in their PTEs".
Cheers,
Tim.
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 13:13, <[email protected]> wrote:
Quoted 32 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
To my understanding, pages with
p2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.Quoted 7 lines
__hvm_copy()is only a helper function, and doesn't write tommio_dmspace either; instead its (indirect) callers would invokehvmemul_do_mmio()upon seeingHVMCOPY_bad_gfn_to_mfnreturns. The question hence is about the apparent inconsistency resulting from writes toram_robeing dropped here but getting passed to the DM byhvm_hap_nested_page_fault(). Tim - is that really intentional?No - and AFAICT it shouldn't be happening. It _is_ how it was implemented originally, because it involved fewer moving parts and didn't need to be efficient (and after all, writes to entirely missing addresses go to the device model too).
Quoted 6 lines
But the code was later updated to log and discard writes to read-only memory (see 4d8aa29 from Trolle Selander).
Early version of
p2m_ram_rowere documented in the internal headers as sending the writes to the DM, but the public interface (HVMMEM_ram_ro) has always said that writes are discarded.Quoted 5 lines
Hmm, so which way do you recommend resolving the inconsistency then - match what the public interface says or what the apparent original intention for the internal type was? Presumably we need to follow the public interface mandated model, and hence require the new type to be introduced.
Quoted 3 lines
Sorry, I was unclear -- there isn't an inconsistency; both internal and public headers currently say that writes are discarded and AFAICT that is what the code does.
Not for hvm_hap_nested_page_fault() afaict - the forwarding to DM there contradicts the "writes are discarded" model that other code paths follow.
Jan
Quoted 40 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 13:13, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
To my understanding, pages with
p2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.Quoted 7 lines
__hvm_copy()is only a helper function, and doesn't write tommio_dmspace either; instead its (indirect) callers would invokehvmemul_do_mmio()upon seeingHVMCOPY_bad_gfn_to_mfnreturns. The question hence is about the apparent inconsistency resulting from writes toram_robeing dropped here but getting passed to the DM byhvm_hap_nested_page_fault(). Tim - is that really intentional?No - and AFAICT it shouldn't be happening. It _is_ how it was implemented originally, because it involved fewer moving parts and didn't need to be efficient (and after all, writes to entirely missing addresses go to the device model too).
Quoted 6 lines
But the code was later updated to log and discard writes to read-only memory (see 4d8aa29 from Trolle Selander).
Early version of
p2m_ram_rowere documented in the internal headers as sending the writes to the DM, but the public interface (HVMMEM_ram_ro) has always said that writes are discarded.Hmm, so which way do you recommend resolving the inconsistency then - match what the public interface says or what the apparent original intention for the internal type was? Presumably we need to follow the public interface mandated model, and hence require the new type to be introduced.
Quoted 8 lines
Quoted 3 lines
Sorry, I was unclear -- there isn't an inconsistency; both internal and public headers currently say that writes are discarded and AFAICT that is what the code does.
Not for
hvm_hap_nested_page_fault()afaict - the forwarding to DM there contradicts the "writes are discarded" model that other code paths follow.
Thanks, Jan.
By "inconsistency", do you mean the p2m_ram_ro shall not trigger the handle_mmio_with_translation() in hvm_hap_nested_page_fault()?
I'm also a bit confused with the "writes are discarded/dropped" comments in the code. Does this mean writes to the p2m_ram_ro pages should be abandoned without going to the dm, or going to the dm and ignored later? The code seems to be the second one.
Quoted 4 lines
Jan
Quoted 48 lines
Quoted 1 line
Quoted 1 line · On 02.12.14 at 08:48, <[email protected]> wrote:
Quoted 44 lines · Jan Beulich
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 13:13, <[email protected]> wrote:
Quoted 32 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
To my understanding, pages with
p2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.Quoted 7 lines
__hvm_copy()is only a helper function, and doesn't write tommio_dmspace either; instead its (indirect) callers would invokehvmemul_do_mmio()upon seeingHVMCOPY_bad_gfn_to_mfnreturns. The question hence is about the apparent inconsistency resulting from writes toram_robeing dropped here but getting passed to the DM byhvm_hap_nested_page_fault(). Tim - is that really intentional?No - and AFAICT it shouldn't be happening. It _is_ how it was implemented originally, because it involved fewer moving parts and didn't need to be efficient (and after all, writes to entirely missing addresses go to the device model too).
Quoted 6 lines
But the code was later updated to log and discard writes to read-only memory (see 4d8aa29 from Trolle Selander).
Early version of
p2m_ram_rowere documented in the internal headers as sending the writes to the DM, but the public interface (HVMMEM_ram_ro) has always said that writes are discarded.Quoted 5 lines
Hmm, so which way do you recommend resolving the inconsistency then - match what the public interface says or what the apparent original intention for the internal type was? Presumably we need to follow the public interface mandated model, and hence require the new type to be introduced.
Sorry, I was unclear -- there isn't an inconsistency; both internal and public headers currently say that writes are discarded and AFAICT that is what the code does.
Quoted 7 lines
Quoted 4 lines
Not for
hvm_hap_nested_page_fault()afaict - the forwarding to DM there contradicts the "writes are discarded" model that other code paths follow.Thanks, Jan.
By "inconsistency", do you mean thep2m_ram_roshall not trigger thehandle_mmio_with_translation()inhvm_hap_nested_page_fault()?
Yes, pending Tim's agreement.
Quoted 4 lines
I'm also a bit confused with the "writes are discarded/dropped" comments in the code. Does this mean writes to the
p2m_ram_ropages should be abandoned without going to the dm, or going to the dm and ignored later? The code seems to be the second one.
And it would seem to me that it should be the former.
Jan
Quoted 40 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 13:13, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
To my understanding, pages with
p2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.Quoted 7 lines
__hvm_copy()is only a helper function, and doesn't write tommio_dmspace either; instead its (indirect) callers would invokehvmemul_do_mmio()upon seeingHVMCOPY_bad_gfn_to_mfnreturns. The question hence is about the apparent inconsistency resulting from writes toram_robeing dropped here but getting passed to the DM byhvm_hap_nested_page_fault(). Tim - is that really intentional?No - and AFAICT it shouldn't be happening. It _is_ how it was implemented originally, because it involved fewer moving parts and didn't need to be efficient (and after all, writes to entirely missing addresses go to the device model too).
Quoted 6 lines
But the code was later updated to log and discard writes to read-only memory (see 4d8aa29 from Trolle Selander).
Early version of
p2m_ram_rowere documented in the internal headers as sending the writes to the DM, but the public interface (HVMMEM_ram_ro) has always said that writes are discarded.Hmm, so which way do you recommend resolving the inconsistency then - match what the public interface says or what the apparent original intention for the internal type was? Presumably we need to follow the public interface mandated model, and hence require the new type to be introduced.
Quoted 7 lines
Quoted 3 lines
Sorry, I was unclear -- there isn't an inconsistency; both internal and public headers currently say that writes are discarded and AFAICT that is what the code does.
Not for
hvm_hap_nested_page_fault()afaict - the forwarding to DM there contradicts the "writes are discarded" model that other code paths follow.
It calls handle_mmio() to emulate the instruction for it, but handle_mmio() ought not to send anything to the DM. hvmemul_write() will call hvm_copy(), which will drop the write and report success.
The shadow code has its own emulator framework for emulting PT writes, which does much the same thing.
Tim.
Quoted 46 lines
Quoted 1 line
Quoted 1 line · On 02.12.14 at 11:37, <[email protected]> wrote:
Quoted 44 lines · Jan Beulich
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 13:13, <[email protected]> wrote:
Quoted 32 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
To my understanding, pages with
p2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.Quoted 7 lines
__hvm_copy()is only a helper function, and doesn't write tommio_dmspace either; instead its (indirect) callers would invokehvmemul_do_mmio()upon seeingHVMCOPY_bad_gfn_to_mfnreturns. The question hence is about the apparent inconsistency resulting from writes toram_robeing dropped here but getting passed to the DM byhvm_hap_nested_page_fault(). Tim - is that really intentional?No - and AFAICT it shouldn't be happening. It _is_ how it was implemented originally, because it involved fewer moving parts and didn't need to be efficient (and after all, writes to entirely missing addresses go to the device model too).
Quoted 6 lines
But the code was later updated to log and discard writes to read-only memory (see 4d8aa29 from Trolle Selander).
Early version of
p2m_ram_rowere documented in the internal headers as sending the writes to the DM, but the public interface (HVMMEM_ram_ro) has always said that writes are discarded.Quoted 5 lines
Hmm, so which way do you recommend resolving the inconsistency then - match what the public interface says or what the apparent original intention for the internal type was? Presumably we need to follow the public interface mandated model, and hence require the new type to be introduced.
Sorry, I was unclear -- there isn't an inconsistency; both internal and public headers currently say that writes are discarded and AFAICT that is what the code does.
Quoted 7 lines
Quoted 3 lines
Not for
hvm_hap_nested_page_fault()afaict - the forwarding to DM there contradicts the "writes are discarded" model that other code paths follow.It calls
handle_mmio()to emulate the instruction for it, buthandle_mmio()ought not to send anything to the DM.hvmemul_write()will callhvm_copy(), which will drop the write and report success.
Oh, of course - it's really just the wording of the comment there that mislead me to assume the operation gets passed on for actual handling. Thanks for clarifying!
Jan
Quoted 52 lines · Tim Deegan
Quoted 32 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 09:49, <[email protected]> wrote:
To my understanding, pages with
p2m_ram_roare not supposed to be modified by guest. So in__hvm_copy(), when p2m type of a page isp2m_ram_rom, no copy will occur.
However, to our usage, we just wanna this page to be write protected, so that our device model can be triggered to do some emulation. The content written to this page is supposed not to be dropped. This way, if sequentially a read operation is performed by guest to this page, the guest will still see its anticipated value.Quoted 7 lines
__hvm_copy()is only a helper function, and doesn't write tommio_dmspace either; instead its (indirect) callers would invokehvmemul_do_mmio()upon seeingHVMCOPY_bad_gfn_to_mfnreturns. The question hence is about the apparent inconsistency resulting from writes toram_robeing dropped here but getting passed to the DM byhvm_hap_nested_page_fault(). Tim - is that really intentional?No - and AFAICT it shouldn't be happening. It _is_ how it was implemented originally, because it involved fewer moving parts and didn't need to be efficient (and after all, writes to entirely missing addresses go to the device model too).
Quoted 6 lines
But the code was later updated to log and discard writes to read-only memory (see 4d8aa29 from Trolle Selander).
Early version of
p2m_ram_rowere documented in the internal headers as sending the writes to the DM, but the public interface (HVMMEM_ram_ro) has always said that writes are discarded.Quoted 5 lines
Hmm, so which way do you recommend resolving the inconsistency then - match what the public interface says or what the apparent original intention for the internal type was? Presumably we need to follow the public interface mandated model, and hence require the new type to be introduced.
Sorry, I was unclear -- there isn't an inconsistency; both internal and public headers currently say that writes are discarded and AFAICT that is what the code does.
But yes, we ought to follow the established hypercall interface, and so we need the new type.
Quoted 6 lines
Quoted 5 lines
During this bit of archaeology I realised that either this new type should _not_ be made part of
P2M_RO_TYPES, or, better, we need a new class of P2M types (P2M_DISCARD_WRITE_TYPES, say) that should be used for these paths inemulate_gva_to_mfn()and__hvm_copy(), containing justp2m_ram_roandp2m_grant_map_ro.
Quoted 6 lines
Quoted 2 lines
And I suppose in that latter case the new type could be made part of
P2M_RO_TYPES()?Yes indeed, as
P2M_RO_TYPESis defined as "must have the_PAGE_RWbit clear in their PTEs".
Thanks Tim.
Following are my understanding of the P2M_RO_TYPES and your comments.
Not sure if I get it right. Please correct me if anything wrong:
1> The P2M_RO_TYPES now bears 2 meanings: one is "w bit is clear in the pte"; and another being to discard the write operations; 2> We better define another class to bear the second meaning.
Also some questions for the new p2m class, say P2M_DISCARD_WRITE_TYPES, and the new predicates, say p2m_is_discard_write:
1> You mentioned emulate_gva_to_mfn() and __hvm_copy() should discard the write ops, yet I also noticed many other places using the p2m_is_readonly, or only the "p2mt == p2m_ram_ro" judgement(in __hvm_copy/__hvm_clear). Among all these other places, is there any ones also supposed to use the p2m_is_discard_write? 2> p2m_grant_map_ro is also supposed to be discarded? Will handling of this type of pages goes into __hvm_copy()/__hvm_clear(), or should?
I'm a new guy of this area, and sorry for my messed questions. :)
Yu
Quoted 5 lines
Cheers,
Tim.
Quoted 16 lines · Zhang
Quoted 8 lines · Tim Deegan
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
During this bit of archaeology I realised that either this new type should _not_ be made part of
P2M_RO_TYPES, or, better, we need a new class of P2M types (P2M_DISCARD_WRITE_TYPES, say) that should be used for these paths inemulate_gva_to_mfn()and__hvm_copy(), containing justp2m_ram_roandp2m_grant_map_ro.Quoted 6 lines
Quoted 2 lines
And I suppose in that latter case the new type could be made part of
P2M_RO_TYPES()?Yes indeed, as
P2M_RO_TYPESis defined as "must have the_PAGE_RWbit clear in their PTEs".
Quoted 6 lines
Thanks Tim.
Following are my understanding of theP2M_RO_TYPESand your comments. Not sure if I get it right. Please correct me if anything wrong:
1> TheP2M_RO_TYPESnow bears 2 meanings: one is "w bit is clear in the pte"; and another being to discard the write operations;
2> We better define another class to bear the second meaning.
Yes, that's what I meant.
Answering your other questions in reverse order:
Quoted 2 lines
2>
p2m_grant_map_rois also supposed to be discarded? Will handling of this type of pages goes into __hvm_copy()/__hvm_clear(), or should?
I think so, yes. At the moment we inject #GP when the guest writes to a read-only grant, which is OK: the guest really ought to know better. But I think we'll probably end up with neater code if we handle read-only grants the same way as p2m_ram_ro.
Anyone else have an opinion on the right thing to do here?
Quoted 7 lines
Also some questions for the new p2m class, say
P2M_DISCARD_WRITE_TYPES, and the new predicates, sayp2m_is_discard_write:
1> You mentionedemulate_gva_to_mfn()and__hvm_copy()should discard the write ops, yet I also noticed many other places using thep2m_is_readonly, or only the "p2mt ==p2m_ram_ro"judgement(in __hvm_copy/__hvm_clear). Among all these other places, is there any ones also supposed to use thep2m_is_discard_write?
I've just had a look through them all, and I can see exactly four places that should be using the new p2m_is_discard_write() test:
- emulate_gva_to_mfn() (Though in fact it's a no-op as shadow-mode guests never have p2m_ram_shared or p2m_ram_logdirty mappings.)
- __hvm_copy()
- __hvm_clear() and
- hvm_hap_nested_page_fault() (where you should also remove the explicit handling of p2m_grant_map_ro below.)
Looking through that turned up a few other oddities, which I'm listing here to remind myself to look at them later (i.e. you don't need to worry about them for this patch):
- nsvm_get_nvmcb_page() and nestedhap_walk_L0_p2m() need to handle p2m_ram_logdirty or they might spuriously fail duiring live migration.
- __hvm_copy() and __hvm_clear are probably over-strict in their failure to handle grant types.
- P2M_UNMAP_TYPES in vmce.c is a mess. It's not the right place to define this, since it definitely won't be seen my anyone adding a new type, and it already has an 'XXX' comment that says it doesn't cover a lot of cases. :(
I'll have a look at those another time.
Cheers,
Tim.
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 02.12.14 at 12:40, <[email protected]> wrote:
Quoted 2 lines · Zhang
2>
p2m_grant_map_rois also supposed to be discarded? Will handling of this type of pages goes into __hvm_copy()/__hvm_clear(), or should?I think so, yes. At the moment we inject #GP when the guest writes to a read-only grant, which is OK: the guest really ought to know better. But I think we'll probably end up with neater code if we handle read-only grants the same way as
p2m_ram_ro.Anyone else have an opinion on the right thing to do here?
I actually came to the same conclusion.
Jan
Quoted 49 lines · Tim Deegan
Quoted 16 lines · Zhang
Quoted 8 lines · Tim Deegan
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
During this bit of archaeology I realised that either this new type should _not_ be made part of
P2M_RO_TYPES, or, better, we need a new class of P2M types (P2M_DISCARD_WRITE_TYPES, say) that should be used for these paths inemulate_gva_to_mfn()and__hvm_copy(), containing justp2m_ram_roandp2m_grant_map_ro.Quoted 6 lines
Quoted 2 lines
And I suppose in that latter case the new type could be made part of
P2M_RO_TYPES()?Yes indeed, as
P2M_RO_TYPESis defined as "must have the_PAGE_RWbit clear in their PTEs".Quoted 6 lines
Thanks Tim.
Following are my understanding of theP2M_RO_TYPESand your comments. Not sure if I get it right. Please correct me if anything wrong:
1> TheP2M_RO_TYPESnow bears 2 meanings: one is "w bit is clear in the pte"; and another being to discard the write operations;
2> We better define another class to bear the second meaning.Yes, that's what I meant.
Answering your other questions in reverse order:
Quoted 2 lines
2>
p2m_grant_map_rois also supposed to be discarded? Will handling of this type of pages goes into __hvm_copy()/__hvm_clear(), or should?I think so, yes. At the moment we inject #GP when the guest writes to a read-only grant, which is OK: the guest really ought to know better. But I think we'll probably end up with neater code if we handle read-only grants the same way as
p2m_ram_ro.Anyone else have an opinion on the right thing to do here?
Quoted 7 lines
Also some questions for the new p2m class, say
P2M_DISCARD_WRITE_TYPES, and the new predicates, sayp2m_is_discard_write:
1> You mentionedemulate_gva_to_mfn()and__hvm_copy()should discard the write ops, yet I also noticed many other places using thep2m_is_readonly, or only the "p2mt ==p2m_ram_ro"judgement(in __hvm_copy/__hvm_clear). Among all these other places, is there any ones also supposed to use thep2m_is_discard_write?I've just had a look through them all, and I can see exactly four places that should be using the new
p2m_is_discard_write()test:
Quoted 7 lines
-
emulate_gva_to_mfn()(Though in fact it's a no-op as shadow-mode guests never havep2m_ram_sharedorp2m_ram_logdirtymappings.)
-__hvm_copy()
-__hvm_clear()and
-hvm_hap_nested_page_fault()(where you should also remove the explicit handling ofp2m_grant_map_robelow.)
Thank you, Tim & Jan.
To give a summary for all the comments:
1> new p2m type p2m_mmio_write_dm is to be added;
2> new p2m type need to be added to P2M_RO_TYPES class;
3> new p2m class, say P2M_DISCARD_WRITE_TYPES(which only include p2m_ram_ro and p2m_grant_map_ro), and the new predicates, say p2m_is_discard_write are needed to in these 4 places to discard the write op; 4> and of cause hvm_hap_nested_page_fault() do not need the special handling for p2m_grant_map_ro anymore;
5> coding style changes pointed out by Jan
6> clear the commit message
I'll prepare the patch and thanks! :)
Yu
Quoted 21 lines
Looking through that turned up a few other oddities, which I'm listing here to remind myself to look at them later (i.e. you don't need to worry about them for this patch):
-
nsvm_get_nvmcb_page()andnestedhap_walk_L0_p2m()need to handlep2m_ram_logdirtyor they might spuriously fail duiring live migration.
-__hvm_copy()and__hvm_clearare probably over-strict in their failure to handle grant types.
-P2M_UNMAP_TYPESinvmce.cis a mess. It's not the right place to define this, since it definitely won't be seen my anyone adding a new type, and it already has an 'XXX' comment that says it doesn't cover a lot of cases. :(I'll have a look at those another time.
Cheers,
Tim.
Quoted 60 lines · Tim Deegan
Quoted 16 lines · Zhang
Quoted 8 lines · Tim Deegan
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.12.14 at 11:30, <[email protected]> wrote:
During this bit of archaeology I realised that either this new type should _not_ be made part of
P2M_RO_TYPES, or, better, we need a new class of P2M types (P2M_DISCARD_WRITE_TYPES, say) that should be used for these paths inemulate_gva_to_mfn()and__hvm_copy(), containing justp2m_ram_roandp2m_grant_map_ro.Quoted 6 lines
Quoted 2 lines
And I suppose in that latter case the new type could be made part of
P2M_RO_TYPES()?Yes indeed, as
P2M_RO_TYPESis defined as "must have the_PAGE_RWbit clear in their PTEs".Quoted 6 lines
Thanks Tim.
Following are my understanding of theP2M_RO_TYPESand your comments. Not sure if I get it right. Please correct me if anything wrong:
1> TheP2M_RO_TYPESnow bears 2 meanings: one is "w bit is clear in the pte"; and another being to discard the write operations;
2> We better define another class to bear the second meaning.Yes, that's what I meant.
Answering your other questions in reverse order:
Quoted 2 lines
2>
p2m_grant_map_rois also supposed to be discarded? Will handling of this type of pages goes into __hvm_copy()/__hvm_clear(), or should?I think so, yes. At the moment we inject #GP when the guest writes to a read-only grant, which is OK: the guest really ought to know better. But I think we'll probably end up with neater code if we handle read-only grants the same way as
p2m_ram_ro.Anyone else have an opinion on the right thing to do here?
Quoted 7 lines
Also some questions for the new p2m class, say
P2M_DISCARD_WRITE_TYPES, and the new predicates, sayp2m_is_discard_write:
1> You mentionedemulate_gva_to_mfn()and__hvm_copy()should discard the write ops, yet I also noticed many other places using thep2m_is_readonly, or only the "p2mt ==p2m_ram_ro"judgement(in __hvm_copy/__hvm_clear). Among all these other places, is there any ones also supposed to use thep2m_is_discard_write?I've just had a look through them all, and I can see exactly four places that should be using the new
p2m_is_discard_write()test:-
emulate_gva_to_mfn()(Though in fact it's a no-op as shadow-mode guests never havep2m_ram_sharedorp2m_ram_logdirtymappings.)
-__hvm_copy()
-__hvm_clear()and
-hvm_hap_nested_page_fault()(where you should also remove the explicit handling ofp2m_grant_map_robelow.)Looking through that turned up a few other oddities, which I'm listing here to remind myself to look at them later (i.e. you don't need to worry about them for this patch):
Quoted 5 lines
-
nsvm_get_nvmcb_page()andnestedhap_walk_L0_p2m()need to handlep2m_ram_logdirtyor they might spuriously fail duiring live migration.
-__hvm_copy()and__hvm_clearare probably over-strict in their failure to handle grant types.
Hi Tim. Sorry to bother you. :)
I just noticed that in __hvm_copy()/__hvm_clear(), the grant types are handled before the p2m_ram_ro - will return HVMCOPY_unhandleable. So if p2m_is_discard_write() is supposed to replace the handling of p2m_ram_ro, handling of p2m_grant_map_ro will still return HVMCOPY_unhandleable, before the p2m_is_discard_write() predicate. Even we move the testing of p2m_is_discard_write() before the handling of grant types, it seems not quite clean.
By "over-strict in their failure to handle grant types.", do you also mean this?
Thanks
Yu
Quoted 17 lines
-
P2M_UNMAP_TYPESinvmce.cis a mess. It's not the right place to define this, since it definitely won't be seen my anyone adding a new type, and it already has an 'XXX' comment that says it doesn't cover a lot of cases. :(I'll have a look at those another time.
Cheers,
Tim.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Hi,
Quoted 9 lines · Zhang
I just noticed that in __hvm_copy()/__hvm_clear(), the grant types are handled before the
p2m_ram_ro- will returnHVMCOPY_unhandleable. So ifp2m_is_discard_write()is supposed to replace the handling ofp2m_ram_ro, handling ofp2m_grant_map_rowill still returnHVMCOPY_unhandleable, before thep2m_is_discard_write()predicate. Even we move the testing ofp2m_is_discard_write()before the handling of grant types, it seems not quite clean.
By "over-strict in their failure to handle grant types.", do you also mean this?
Yes, that's the sort of thing I meant. I'll try to write a patch for that later today or next week -- in the meantime I think you should ignore it. :)
An unrelated thought: when you send your next version can you send it as a two-patch series, where the first patch does the p2m_is_discard_write() changes and the second adds your new type?
Cheers,
Tim.
Quoted 13 lines · Tim Deegan
Hi,
Quoted 9 lines · Zhang
I just noticed that in __hvm_copy()/__hvm_clear(), the grant types are handled before the
p2m_ram_ro- will returnHVMCOPY_unhandleable. So ifp2m_is_discard_write()is supposed to replace the handling ofp2m_ram_ro, handling ofp2m_grant_map_rowill still returnHVMCOPY_unhandleable, before thep2m_is_discard_write()predicate. Even we move the testing ofp2m_is_discard_write()before the handling of grant types, it seems not quite clean.
By "over-strict in their failure to handle grant types.", do you also mean this?
Quoted 7 lines
Yes, that's the sort of thing I meant. I'll try to write a patch for that later today or next week -- in the meantime I think you should ignore it. :)
An unrelated thought: when you send your next version can you send it as a two-patch series, where the first patch does the
p2m_is_discard_write()changes and the second adds your new type?
Sure, and thank you, Tim. :)
Quoted 11 lines
Cheers,
Tim.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel