x86/emulate: Send vm_event from emulate
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
This patch aims to have mem access vm events sent from the emulator. This is useful where we want to only emulate a page walk without checking the EPT, but we still want to check the EPT when emulating the instruction that caused the page walk. In this case, the original EPT fault is caused by the walk trying to set the accessed or dirty bits, but executing the instruction itself might also cause an EPT fault if permitted to run, and this second fault should not be lost.
I'm afraid I still can't translate this into what exactly is wanted and why. While typically we don't use examples to demonstrate that is wanted in commit messages, I think this is a rather good candidate for actually using such an approach. This may then ...
Quoted 7 lines
We use
hvmemul_map_linear_addr()to intercept r/w access and__hvm_copy()to intercept exec access.First we try to send a vm event and if the event is sent then emulation returns
X86EMUL_RETRYin order to stop emulation on instructions that use access protected pages. If the event is not sent then the emulation goes on as expected.
... also help understanding this part, which I continue to be confused by, too.
Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 540
Quoted 10 lines
(quoted diff) +6
-0@@ -530,6 +532,57 @@ static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, return hvmemul_do_io_addr(1, mmio_gpa, reps, size, dir, df, ram_gpa); } +bool hvm_emulate_send_vm_event(unsigned long gla, gfn_t gfn, + uint32_t pfec, bool send_event) +{ + xenmem_access_t access; + vm_event_request_t req = {}; + paddr_t gpa = ((gfn_x(gfn) << PAGE_SHIFT) | (gla & ~PAGE_MASK));
gfn_to_gaddr()
Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 542
Quoted 2 lines
(quoted diff) +2
-0+ if ( !send_event || !pfec ) + return false;
I think I've said before that the !pfec part need an explanation (in a comment). Without such an explanation I'm inclined to say it should be deleted. If otoh this is simply mean to be a shortcut, then you should really just check the two bits you actually care about further down.
Similarly I think I've said before that I'm not happy for the common case to now be to call into here just to bail back out (when VM events are disabled on a guest). IOW I don't think you should call into this function in the first place when "send_event" is false.
Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 547
Quoted 5 lines
(quoted diff) +5
-0+ if ( p2m_get_mem_access(current->domain, gfn, &access, + altp2m_vcpu_idx(current)) != 0 ) + return false; + + switch ( access ) {
Style.
Quoted 12 lines
(quoted diff) +12
-0+ case XENMEM_access_x: + case XENMEM_access_rx: + if ( pfec & PFEC_write_access ) + req.u.mem_access.flags = MEM_ACCESS_R | MEM_ACCESS_W; + break; + + case XENMEM_access_w: + case XENMEM_access_rw: + if ( pfec & PFEC_insn_fetch ) + req.u.mem_access.flags = MEM_ACCESS_X; + break; +
Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 569
Quoted 10 lines
(quoted diff) +10
-0+ case XENMEM_access_r: + case XENMEM_access_n: + if ( pfec & PFEC_write_access ) + req.u.mem_access.flags |= MEM_ACCESS_R | MEM_ACCESS_W; + if ( pfec & PFEC_insn_fetch ) + req.u.mem_access.flags |= MEM_ACCESS_X; + break; + + default: + return false;
I think it would be more future proof to not have a default case
here: When a new access enumerator gets introduced, most compilers would tell the developer right away that this new enumerator value needs actively handling here.
Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 573
Quoted 4 lines
(quoted diff) +4
-0+ } + + if ( !req.u.mem_access.flags ) + return false; /* no violation */
How is the "false" here (I think this is the one the description talks about) matching up with the various other ones in the function?
Review static void *hvmemul_map_linear_addr( · line 677
Quoted 10 lines
(quoted diff) +6
-0@@ -615,6 +669,13 @@ static void *hvmemul_map_linear_addr( if ( pfec & PFEC_write_access ) { + if ( hvm_emulate_send_vm_event(addr, gfn, pfec, + hvmemul_ctxt->send_event) ) + { + err = ERR_PTR(~X86EMUL_RETRY); + goto out; + }
How come this sits only on the write path?
Review static int linear_read(unsigned long addr, unsigned int bytes, void *p_data, · line 1180
Quoted 7 lines
(quoted diff) +2
-1@@ -1115,7 +1176,8 @@ static int linear_read(unsigned long addr, unsigned int bytes, void *p_data, * clean up any interim state. */ if ( !hvmemul_find_mmio_cache(vio, addr, IOREQ_READ, false) ) - rc = hvm_copy_from_guest_linear(p_data, addr, bytes, pfec, &pfinfo); + rc = hvm_copy_from_guest_linear(p_data, addr, bytes, pfec, &pfinfo, + hvmemul_ctxt->send_event);
I'm not very happy to see this new parameter/argument addition. Did you consider putting the flag of interest elsewhere (into a structure hanging off of current, or into pagefault_info_t)?
Furthermore, if the parameter is really unavoidable, then please separate the mechanics of introducing it from the actual change you're after.
Review void hvm_emulate_init_per_insn( · line 2695
Quoted 6 lines
(quoted diff) +1
-1@@ -2629,7 +2692,7 @@ void hvm_emulate_init_per_insn( hvm_copy_from_guest_linear(hvmemul_ctxt->insn_buf, addr, sizeof(hvmemul_ctxt->insn_buf), pfec | PFEC_insn_fetch, - NULL) == HVMTRANS_okay) ? + NULL, false) == HVMTRANS_okay) ?
If you pass false here, what's the point of handling insn fetches in the new function you add?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 29 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
This patch aims to have mem access vm events sent from the emulator. This is useful where we want to only emulate a page walk without checking the EPT, but we still want to check the EPT when emulating the instruction that caused the page walk. In this case, the original EPT fault is caused by the walk trying to set the accessed or dirty bits, but executing the instruction itself might also cause an EPT fault if permitted to run, and this second fault should not be lost.
I'm afraid I still can't translate this into what exactly is wanted and why. While typically we don't use examples to demonstrate that is wanted in commit messages, I think this is a rather good candidate for actually using such an approach. This may then ...
Quoted 7 lines
We use
hvmemul_map_linear_addr()to intercept r/w access and__hvm_copy()to intercept exec access.First we try to send a vm event and if the event is sent then emulation returns
X86EMUL_RETRYin order to stop emulation on instructions that use access protected pages. If the event is not sent then the emulation goes on as expected.... also help understanding this part, which I continue to be confused by, too.
Quoted 4 lines
(quoted diff) +0
-0@@ -530,6 +532,57 @@ static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, return hvmemul_do_io_addr(1, mmio_gpa, reps, size, dir, df, ram_gpa); }
Quoted 8 lines
Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 540
Quoted 6 lines
(quoted diff) +6
-0+bool hvm_emulate_send_vm_event(unsigned long gla, gfn_t gfn, + uint32_t pfec, bool send_event) +{ + xenmem_access_t access; + vm_event_request_t req = {}; + paddr_t gpa = ((gfn_x(gfn) << PAGE_SHIFT) | (gla & ~PAGE_MASK));
gfn_to_gaddr()
I will use that
Quoted 9 lines
Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 542
Quoted 3 lines
(quoted diff) +2
-0+ if ( !send_event || !pfec ) + return false;I think I've said before that the !pfec part need an explanation (in a comment). Without such an explanation I'm inclined to say it should be deleted. If otoh this is simply mean to be a shortcut, then you should really just check the two bits you actually care about further down.
The pfec check is done because I encountered pfec 0 in tests. It could save some work if pfec == 0 when calling the function. Is there a must in having this check removed? If so then it can be done. The send_event will be checked before calling the function as you said.
Quoted 33 lines
Similarly I think I've said before that I'm not happy for the common case to now be to call into here just to bail back out (when VM events are disabled on a guest). IOW I don't think you should call into this function in the first place when "
send_event" is false.Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 547
Quoted 5 lines
(quoted diff) +5
-0+ if ( p2m_get_mem_access(current->domain, gfn, &access, + altp2m_vcpu_idx(current)) != 0 ) + return false; + + switch ( access ) {Style.
Quoted 19 lines
(quoted diff) +19
-0+ case XENMEM_access_x: + case XENMEM_access_rx: + if ( pfec & PFEC_write_access ) + req.u.mem_access.flags = MEM_ACCESS_R | MEM_ACCESS_W; + break; + + case XENMEM_access_w: + case XENMEM_access_rw: + if ( pfec & PFEC_insn_fetch ) + req.u.mem_access.flags = MEM_ACCESS_X; + break; + + case XENMEM_access_r: + case XENMEM_access_n: + if ( pfec & PFEC_write_access ) + req.u.mem_access.flags |= MEM_ACCESS_R | MEM_ACCESS_W; + if ( pfec & PFEC_insn_fetch ) + req.u.mem_access.flags |= MEM_ACCESS_X; + break;
Quoted 8 lines
Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 569
Quoted 3 lines
(quoted diff) +3
-0+ + default: + return false;I think it would be more future proof to not have a default case
here: When a new access enumerator gets introduced, most compilers would tell the developer right away that this new enumerator value needs actively handling here.
I will cut the default case and treat all of the enum members.
Quoted 8 lines
Review static int hvmemul_do_mmio_addr(paddr_t mmio_gpa, · line 573
Quoted 5 lines
(quoted diff) +4
-0+ } + + if ( !req.u.mem_access.flags ) + return false; /* no violation */How is the "false" here (I think this is the one the description talks about) matching up with the various other ones in the function?
There should be no event if there is no access violation. So in this case the emulation is continued as expected.
Quoted 13 lines
Review static void *hvmemul_map_linear_addr( · line 677
Quoted 11 lines
(quoted diff) +6
-0@@ -615,6 +669,13 @@ static void *hvmemul_map_linear_addr( if ( pfec & PFEC_write_access ) { + if ( hvm_emulate_send_vm_event(addr, gfn, pfec, + hvmemul_ctxt->send_event) ) + { + err = ERR_PTR(~X86EMUL_RETRY); + goto out; + }How come this sits only on the write path?
We are interested only for the write access on this path. This also ensures that pfec is set.
Quoted 13 lines
Review static int linear_read(unsigned long addr, unsigned int bytes, void *p_data, · line 1180
Quoted 8 lines
(quoted diff) +2
-1@@ -1115,7 +1176,8 @@ static int linear_read(unsigned long addr, unsigned int bytes, void *p_data, * clean up any interim state. */ if ( !hvmemul_find_mmio_cache(vio, addr, IOREQ_READ, false) ) - rc = hvm_copy_from_guest_linear(p_data, addr, bytes, pfec, &pfinfo); + rc = hvm_copy_from_guest_linear(p_data, addr, bytes, pfec, &pfinfo, + hvmemul_ctxt->send_event);I'm not very happy to see this new parameter/argument addition. Did you consider putting the flag of interest elsewhere (into a structure hanging off of current, or into
pagefault_info_t)?
Quoted 3 lines
Furthermore, if the parameter is really unavoidable, then please separate the mechanics of introducing it from the actual change you're after.
I could move the flag to vcpu.arch.vm_event.send_event.
Quoted 10 lines
Review void hvm_emulate_init_per_insn( · line 2695
Quoted 7 lines
(quoted diff) +1
-1@@ -2629,7 +2692,7 @@ void hvm_emulate_init_per_insn( hvm_copy_from_guest_linear(hvmemul_ctxt->insn_buf, addr, sizeof(hvmemul_ctxt->insn_buf), pfec | PFEC_insn_fetch, - NULL) == HVMTRANS_okay) ? + NULL, false) == HVMTRANS_okay) ?If you pass false here, what's the point of handling insn fetches in the new function you add?
This is a good question. By looking at the flow I think I should use call the send_event here also. Assuming that having hvmemul_ctxt->insn_buf_bytes = 0 if the event was send is enough to have the emulation stop then I will give this a test.
Thanks,
Alex
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Alexandru Stefan ISAILA
Quoted 9 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
(quoted diff) +2
-0+ if ( !send_event || !pfec ) + return false;I think I've said before that the !pfec part need an explanation (in a comment). Without such an explanation I'm inclined to say it should be deleted. If otoh this is simply mean to be a shortcut, then you should really just check the two bits you actually care about further down.
Quoted 4 lines
The pfec check is done because I encountered pfec 0 in tests. It could save some work if pfec == 0 when calling the function. Is there a must in having this check removed? If so then it can be done. The
send_eventwill be checked before calling the function as you said.
It's not a requirement for it to be removed, _if_ there's a good reason for it to be there. I don't, however, see how pfec=0 could be a problem - afaict it would return false a few lines further down in that case.
Quoted 8 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if ( !req.u.mem_access.flags ) + return false; /* no violation */How is the "false" here (I think this is the one the description talks about) matching up with the various other ones in the function?
There should be no event if there is no access violation. So in this case the emulation is continued as expected.
But this doesn't answer my question: You use "false" as return value to indicate different things. Only the one here means "no access violation".
Quoted 13 lines
Quoted 12 lines
Review static void *hvmemul_map_linear_addr( · line 677
Quoted 10 lines
(quoted diff) +6
-0@@ -615,6 +669,13 @@ static void *hvmemul_map_linear_addr( if ( pfec & PFEC_write_access ) { + if ( hvm_emulate_send_vm_event(addr, gfn, pfec, + hvmemul_ctxt->send_event) ) + { + err = ERR_PTR(~X86EMUL_RETRY); + goto out; + }How come this sits only on the write path?
Quoted 2 lines
We are interested only for the write access on this path. This also ensures that pfec is set.
I'm sorry, but the event sending should not be tailored to what you need or want. Or if so (i.e. if agreed upon among the VM event maintainers) then this restriction should be clearly spelled out.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 17 lines · Jan Beulich
Quoted 11 lines · Alexandru Stefan ISAILA
Quoted 9 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
(quoted diff) +2
-0+ if ( !send_event || !pfec ) + return false;I think I've said before that the !pfec part need an explanation (in a comment). Without such an explanation I'm inclined to say it should be deleted. If otoh this is simply mean to be a shortcut, then you should really just check the two bits you actually care about further down.
Quoted 4 lines
The pfec check is done because I encountered pfec 0 in tests. It could save some work if pfec == 0 when calling the function. Is there a must in having this check removed? If so then it can be done. The
send_eventwill be checked before calling the function as you said.
Quoted 4 lines
It's not a requirement for it to be removed, _if_ there's a good reason for it to be there. I don't, however, see how pfec=0 could be a problem - afaict it would return false a few lines further down in that case.
You are right, pfec=0 wold not be a problem and it will be caught in the no violation if.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ if ( !req.u.mem_access.flags ) + return false; /* no violation */How is the "false" here (I think this is the one the description talks about) matching up with the various other ones in the function?
Quoted 6 lines
Quoted 2 lines
There should be no event if there is no access violation. So in this case the emulation is continued as expected.
But this doesn't answer my question: You use "false" as return value to indicate different things. Only the one here means "no access violation".
Sorry about that, since this will remain the only return false apart form the main one (return monitor_traps()), false = event was not sent and true = event was sent.
I understand that you are asking about the scenario when there was a violation and the event was not sent. Then I can issue a domain_crash() as that is potentially a big issue.
I hope I got that correctly.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Review static void *hvmemul_map_linear_addr( · line 677
Quoted 11 lines
(quoted diff) +6
-0@@ -615,6 +669,13 @@ static void *hvmemul_map_linear_addr( if ( pfec & PFEC_write_access ) { + if ( hvm_emulate_send_vm_event(addr, gfn, pfec, + hvmemul_ctxt->send_event) ) + { + err = ERR_PTR(~X86EMUL_RETRY); + goto out; + }How come this sits only on the write path?
Quoted 7 lines
Quoted 2 lines
We are interested only for the write access on this path. This also ensures that pfec is set.
I'm sorry, but the event sending should not be tailored to what you need or want. Or if so (i.e. if agreed upon among the VM event maintainers) then this restriction should be clearly spelled out.
On the other hand, this can go outside the write path with no effect on the functionality of this send_event feature.
I will move it after the if(write) in the next version.
Thanks,
Alex
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 21 lines · Alexandru Stefan ISAILA
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Alexandru Stefan ISAILA
Quoted 6 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
(quoted diff) +2
-0+ if ( !req.u.mem_access.flags ) + return false; /* no violation */How is the "false" here (I think this is the one the description talks about) matching up with the various other ones in the function?
Quoted 6 lines
Quoted 2 lines
There should be no event if there is no access violation. So in this case the emulation is continued as expected.
But this doesn't answer my question: You use "false" as return value to indicate different things. Only the one here means "no access violation".
Sorry about that, since this will remain the only return false apart form the main one (return
monitor_traps()), false = event was not sent and true = event was sent.
Quoted 5 lines
I understand that you are asking about the scenario when there was a violation and the event was not sent. Then I can issue a
domain_crash()as that is potentially a big issue.I hope I got that correctly.
I don't get the impression that you did. I count a total of four "return false" in the function, only one of which explicitly means "no access violation" (others may have that meaning implicitly). Let's take the p2m_get_mem_access() failure case as an example: What I don't understand is why this case and the "no access violation" one are both meant to be treated the same.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 26 lines · Jan Beulich
Quoted 25 lines · Alexandru Stefan ISAILA
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Alexandru Stefan ISAILA
Quoted 6 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
(quoted diff) +2
-0+ if ( !req.u.mem_access.flags ) + return false; /* no violation */How is the "false" here (I think this is the one the description talks about) matching up with the various other ones in the function?
Quoted 6 lines
Quoted 2 lines
There should be no event if there is no access violation. So in this case the emulation is continued as expected.
But this doesn't answer my question: You use "false" as return value to indicate different things. Only the one here means "no access violation".
Sorry about that, since this will remain the only return false apart form the main one (return
monitor_traps()), false = event was not sent and true = event was sent.I understand that you are asking about the scenario when there was a violation and the event was not sent. Then I can issue a
domain_crash()as that is potentially a big issue.
Quoted 8 lines
Quoted 1 line
I hope I got that correctly.
I don't get the impression that you did. I count a total of four "return false" in the function, only one of which explicitly means "no access violation" (others may have that meaning implicitly). Let's take the
p2m_get_mem_access()failure case as an example: What I don't understand is why this case and the "no access violation" one are both meant to be treated the same.
Right, at the moment, false means that emulation should continue and true means that emulation should stop. If it is a must that I return different errors I will change that in the next version but in the way that the code is right now they will be treated the same way.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 38 lines · Alexandru Stefan ISAILA
Quoted 26 lines · Jan Beulich
Quoted 25 lines · Alexandru Stefan ISAILA
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Alexandru Stefan ISAILA
Quoted 6 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
(quoted diff) +2
-0+ if ( !req.u.mem_access.flags ) + return false; /* no violation */How is the "false" here (I think this is the one the description talks about) matching up with the various other ones in the function?
Quoted 6 lines
Quoted 2 lines
There should be no event if there is no access violation. So in this case the emulation is continued as expected.
But this doesn't answer my question: You use "false" as return value to indicate different things. Only the one here means "no access violation".
Sorry about that, since this will remain the only return false apart form the main one (return
monitor_traps()), false = event was not sent and true = event was sent.I understand that you are asking about the scenario when there was a violation and the event was not sent. Then I can issue a
domain_crash()as that is potentially a big issue.Quoted 8 lines
Quoted 1 line
I hope I got that correctly.
I don't get the impression that you did. I count a total of four "return false" in the function, only one of which explicitly means "no access violation" (others may have that meaning implicitly). Let's take the
p2m_get_mem_access()failure case as an example: What I don't understand is why this case and the "no access violation" one are both meant to be treated the same.
Quoted 4 lines
Right, at the moment, false means that emulation should continue and true means that emulation should stop. If it is a must that I return different errors I will change that in the next version but in the way that the code is right now they will be treated the same way.
Again - it's not a requirement. It depends on whether the behavior is intended to be that way. If it is, it should be clarified in the description or maybe better in a code comment. But to me, without such a clarification, it doesn't look like it should be that way.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 44 lines · Jan Beulich
Quoted 38 lines · Alexandru Stefan ISAILA
Quoted 26 lines · Jan Beulich
Quoted 25 lines · Alexandru Stefan ISAILA
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Alexandru Stefan ISAILA
Quoted 6 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
(quoted diff) +2
-0+ if ( !req.u.mem_access.flags ) + return false; /* no violation */How is the "false" here (I think this is the one the description talks about) matching up with the various other ones in the function?
Quoted 6 lines
Quoted 2 lines
There should be no event if there is no access violation. So in this case the emulation is continued as expected.
But this doesn't answer my question: You use "false" as return value to indicate different things. Only the one here means "no access violation".
Sorry about that, since this will remain the only return false apart form the main one (return
monitor_traps()), false = event was not sent and true = event was sent.I understand that you are asking about the scenario when there was a violation and the event was not sent. Then I can issue a
domain_crash()as that is potentially a big issue.Quoted 8 lines
Quoted 1 line
I hope I got that correctly.
I don't get the impression that you did. I count a total of four "return false" in the function, only one of which explicitly means "no access violation" (others may have that meaning implicitly). Let's take the
p2m_get_mem_access()failure case as an example: What I don't understand is why this case and the "no access violation" one are both meant to be treated the same.Quoted 4 lines
Right, at the moment, false means that emulation should continue and true means that emulation should stop. If it is a must that I return different errors I will change that in the next version but in the way that the code is right now they will be treated the same way.
Quoted 5 lines
Again - it's not a requirement. It depends on whether the behavior is intended to be that way. If it is, it should be clarified in the description or maybe better in a code comment. But to me, without such a clarification, it doesn't look like it should be that way.
Short answer is yes, the behavior is the same and it does not need any differentiation, I will clarify this in a comment and in the commit comment, sorry for misunderstanding the first comment.
Regards,
Alex
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines · Alexandru Stefan ISAILA
Quoted 17 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
This patch aims to have mem access vm events sent from the emulator. This is useful where we want to only emulate a page walk without checking the EPT, but we still want to check the EPT when emulating the instruction that caused the page walk. In this case, the original EPT fault is caused by the walk trying to set the accessed or dirty bits, but executing the instruction itself might also cause an EPT fault if permitted to run, and this second fault should not be lost.
I'm afraid I still can't translate this into what exactly is wanted and why. While typically we don't use examples to demonstrate that is wanted in commit messages, I think this is a rather good candidate for actually using such an approach. This may then ...
Quoted 3 lines
We use
hvmemul_map_linear_addr()to intercept r/w access and__hvm_copy()to intercept exec access.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
First we try to send a vm event and if the event is sent then emulation returns
X86EMUL_RETRYin order to stop emulation on instructions that use access protected pages. If the event is not sent then the emulation goes on as expected.... also help understanding this part, which I continue to be confused by, too.
Simply put, the introspection agent wants to treat all A/D bit writes as benign. Receiving vm_events about them is a big pessimization, and we want to optimize.
We'd like to filter these events out.
To this end, we're currently (in the present incarnation of the Xen code) fully emulating the instruction at RIP when the hardware sees an EPT fault with npfec.kind != npfec_kind_with_gla. This is, however, incorrect, because the instruction at RIP might legitimately cause an EPT fault of its own (while accessing a _different_ page from the original one, where A/D were set).
We've tried to solve this by actually writing the A/D bits and returning from p2m_mem_access_check(), however that has led to a slightly philosophical discussion about the proper way to achieve our goals while taking into account speculative setting of these bits. The issues raised have not been satisfactorily answered in an authoritative manner to this day.
So the only option we seem to have left at this point is to perform the whole emulation, _while_ ignoring EPT restrictions for the walk part, and taking them into account for the "actual" emulating of the instruction @ RIP.
If we're sending out a vm_event, then we don't want the emulation to complete - since in that case we won't be able to veto whatever is doing. That would mean that we can't actually prevent any malicious activity that happens here, instead we'd only be able to report on it.
So when we see a "send-vm_event" case while emulating, we need to do two things:
1. send the event out;
2. _don't_ complete the emulation (return X86EMUL_RETRY).
When 2. happens, we'll hit hvm_vm_event_do_resume() again _after_ the introspection agent treats the event and resumes the guest. There, the instruction at RIP will be fully emulated (with the EPT ignored) if the introspection application allows it, and the guest will continue to run past the instruction.
That's our plan, anyway. Hopefully we're not going in a wrong direction about it (all help is very much appreciated).
I hope this has made thing clearer. We're not after anything out of the ordinary or fitting a niche case - we just want to filter out vm_events caused by page walks in a manner that remains safe for the guest OS user.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 43 lines · Razvan Cojocaru
Quoted 20 lines · Alexandru Stefan ISAILA
Quoted 17 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.06.19 at 13:49, <[email protected]> wrote:
This patch aims to have mem access vm events sent from the emulator. This is useful where we want to only emulate a page walk without checking the EPT, but we still want to check the EPT when emulating the instruction that caused the page walk. In this case, the original EPT fault is caused by the walk trying to set the accessed or dirty bits, but executing the instruction itself might also cause an EPT fault if permitted to run, and this second fault should not be lost.
I'm afraid I still can't translate this into what exactly is wanted and why. While typically we don't use examples to demonstrate that is wanted in commit messages, I think this is a rather good candidate for actually using such an approach. This may then ...
Quoted 3 lines
We use
hvmemul_map_linear_addr()to intercept r/w access and__hvm_copy()to intercept exec access.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
First we try to send a vm event and if the event is sent then emulation returns
X86EMUL_RETRYin order to stop emulation on instructions that use access protected pages. If the event is not sent then the emulation goes on as expected.... also help understanding this part, which I continue to be confused by, too.
Simply put, the introspection agent wants to treat all A/D bit writes as benign. Receiving
vm_eventsabout them is a big pessimization, and we want to optimize.We'd like to filter these events out.
To this end, we're currently (in the present incarnation of the Xen code) fully emulating the instruction at RIP when the hardware sees an EPT fault with npfec.kind !=
npfec_kind_with_gla. This is, however, incorrect, because the instruction at RIP might legitimately cause an EPT fault of its own (while accessing a _different_ page from the original one, where A/D were set).We've tried to solve this by actually writing the A/D bits and returning from
p2m_mem_access_check(), however that has led to a slightly philosophical discussion about the proper way to achieve our goals while taking into account speculative setting of these bits. The issues raised have not been satisfactorily answered in an authoritative manner to this day.So the only option we seem to have left at this point is to perform the whole emulation, _while_ ignoring EPT restrictions for the walk part, and taking them into account for the "actual" emulating of the instruction @ RIP.
If we're sending out a
vm_event, then we don't want the emulation to complete - since in that case we won't be able to veto whatever is doing. That would mean that we can't actually prevent any malicious activity that happens here, instead we'd only be able to report on it.So when we see a "send-vm_event" case while emulating, we need to do two things:
Quoted 8 lines
1. send the event out;
2. _don't_ complete the emulation (returnX86EMUL_RETRY).When 2. happens, we'll hit
hvm_vm_event_do_resume()again _after_ the introspection agent treats the event and resumes the guest. There, the instruction at RIP will be fully emulated (with the EPT ignored) if the introspection application allows it, and the guest will continue to run past the instruction.That's our plan, anyway. Hopefully we're not going in a wrong direction about it (all help is very much appreciated).
I hope this has made thing clearer.
I think so, yes, and I'm getting the impression that in reply to an earlier version you've already once explained this. The thing is - the explanation needs to come _with_ the patch, not _after_ it.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel