Skip to contentSkip to conversation

x86/emulate: Check current->arch.vm_event in hvmemul_virtual_to_linear()

PATCH In review Razvan Cojocaru 2 participants 6 messages Apr 7, 2016 – Apr 8, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/emulate: Check current->arch.vm_event in hvmemul_virtual_to_linear()

Theoretically it is possible for mem_access_emulate_each_rep to be true even when current->arch.vm_event == NULL, so add an extra check to hvmemul_virtual_to_linear().

---
 xen/arch/x86/hvm/emulate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/emulate.c +1 -1
index f5ab5bc..91413d2 100644
@@ -514,7 +514,7 @@ static int hvmemul_virtual_to_linear(
      * vm_event being triggered for repeated writes to a whole page.
      */
     if ( unlikely(current->domain->arch.mem_access_emulate_each_rep) &&
-         current->arch.vm_event->emulate_flags != 0 )
+         current->arch.vm_event && current->arch.vm_event->emulate_flags != 0 )
        max_reps = 1;
 
     /*
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 10:39, <[email protected]> wrote:

Theoretically it is possible for mem_access_emulate_each_rep to be true even when current->arch.vm_event == NULL, so add an extra check to hvmemul_virtual_to_linear().

Mind saying what those theoretical conditions are when this might happen?

xen/arch/x86/hvm/emulate.c static int hvmemul_virtual_to_linear( · line 517

Quoted 8 lines
xen/arch/x86/hvm/emulate.c +1 -1
@@ -514,7 +514,7 @@ static int hvmemul_virtual_to_linear(
      * vm_event being triggered for repeated writes to a whole page.
      */
     if ( unlikely(current->domain->arch.mem_access_emulate_each_rep) &&
-         current->arch.vm_event->emulate_flags != 0 )
+         current->arch.vm_event && current->arch.vm_event->emulate_flags != 0 )

That's then the third instance of "current" here - this needs latching into a local variable.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 10:39, <[email protected]> wrote:

Theoretically it is possible for mem_access_emulate_each_rep to be true even when current->arch.vm_event == NULL, so add an extra check to hvmemul_virtual_to_linear().

Mind saying what those theoretical conditions are when this might happen?

This could happen if someone were to call xc_monitor_emulate_each_rep(), but not xc_monitor_enable() (when current->arch.vm_event gets allocated), or after someone called both, but afterwards called xc_monitor_disable() (when current->arch.vm_event gets freed).

Quoted 11 lines

xen/arch/x86/hvm/emulate.c static int hvmemul_virtual_to_linear( · line 517

Quoted 8 lines
xen/arch/x86/hvm/emulate.c +1 -1
@@ -514,7 +514,7 @@ static int hvmemul_virtual_to_linear(
      * vm_event being triggered for repeated writes to a whole page.
      */
     if ( unlikely(current->domain->arch.mem_access_emulate_each_rep) &&
-         current->arch.vm_event->emulate_flags != 0 )
+         current->arch.vm_event && current->arch.vm_event->emulate_flags != 0 )

That's then the third instance of "current" here - this needs latching into a local variable.

No problem.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 6 lines · Razvan Cojocaru
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 10:39, <[email protected]> wrote:

Theoretically it is possible for mem_access_emulate_each_rep to be true even when current->arch.vm_event == NULL, so add an extra check to hvmemul_virtual_to_linear().

Quoted 7 lines
Quoted 2 lines

Mind saying what those theoretical conditions are when this might happen?

This could happen if someone were to call xc_monitor_emulate_each_rep(), but not xc_monitor_enable() (when current->arch.vm_event gets allocated), or after someone called both, but afterwards called xc_monitor_disable() (when current->arch.vm_event gets freed).

Actually, I need to correct myself here: only the first case applies. I was looking at older Xen source code, but there's a "d->arch.mem_access_emulate_each_rep = 0;" statement in vm_event_cleanup_domain() now, so calling xc_monitor_disable() would not cause a problem.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw
In reply to Razvan Cojocaru
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 19:54, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 10:39, <[email protected]> wrote:

Theoretically it is possible for mem_access_emulate_each_rep to be true even when current->arch.vm_event == NULL, so add an extra check to hvmemul_virtual_to_linear().

Quoted 7 lines
Quoted 2 lines

Mind saying what those theoretical conditions are when this might happen?

This could happen if someone were to call xc_monitor_emulate_each_rep(), but not xc_monitor_enable() (when current->arch.vm_event gets allocated), or after someone called both, but afterwards called xc_monitor_disable() (when current->arch.vm_event gets freed).

Then wouldn't the correct action be to fail xc_monitor_emulate_each_rep() (i.e. whatever hypercall this resolves to) when the monitor is not enabled? (You did already clarify that the other variant isn't applicable)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
Quoted 15 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 19:54, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 10:39, <[email protected]> wrote:

Theoretically it is possible for mem_access_emulate_each_rep to be true even when current->arch.vm_event == NULL, so add an extra check to hvmemul_virtual_to_linear().

Quoted 7 lines
Quoted 2 lines

Mind saying what those theoretical conditions are when this might happen?

This could happen if someone were to call xc_monitor_emulate_each_rep(), but not xc_monitor_enable() (when current->arch.vm_event gets allocated), or after someone called both, but afterwards called xc_monitor_disable() (when current->arch.vm_event gets freed).

Quoted 4 lines

Then wouldn't the correct action be to fail xc_monitor_emulate_each_rep() (i.e. whatever hypercall this resolves to) when the monitor is not enabled? (You did already clarify that the other variant isn't applicable)?

Yes, I think that's better. I'll do that instead.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel