From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Tamas K Lengyel <tamas@tklengyel.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <jbeulich@suse.com>,
Razvan Cojocaru <rcojocaru@bitdefender.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH] x86/vm_event: correctly gather gs_shadow value
Date: Wed, 1 May 2019 18:02:13 +0100 [thread overview]
Message-ID: <cfddf089-496e-d935-2470-20afa280ba78@citrix.com> (raw)
In-Reply-To: <CABfawhk_cCzL0XVUp6h-5QvXBDwqwf87+CqBvPDdeAHqAcrmvw@mail.gmail.com>
On 01/05/2019 15:58, Tamas K Lengyel wrote:
> On Wed, May 1, 2019 at 7:45 AM Tamas K Lengyel <tamas@tklengyel.com> wrote:
>> On Wed, May 1, 2019 at 1:50 AM Andrew Cooper <andrew.cooper3@citrix.com> wrote:
>>> On 01/05/2019 05:22, Tamas K Lengyel wrote:
>>>> Currently the gs_shadow value is only cached when the vCPU is being scheduled
>>>> out by Xen. Reporting this (usually) stale value through vm_event is incorrect,
>>>> since it doesn't represent the actual state of the vCPU at the time the event
>>>> was recorded. This prevents vm_event subscribers from correctly finding kernel
>>>> structures in the guest when it is trapped while in ring3.
>>>>
>>>> Signed-off-by: Tamas K Lengyel <tamas@tklengyel.com>
>>>> Cc: Razvan Cojocaru <rcojocaru@bitdefender.com>
>>>> Cc: Jan Beulich <jbeulich@suse.com>
>>>> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
>>>> Cc: Wei Liu <wei.liu2@citrix.com>
>>>> Cc: Roger Pau Monne <roger.pau@citrix.com>
>>>> ---
>>>> xen/arch/x86/vm_event.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c
>>>> index 51c3493b1d..4464940da7 100644
>>>> --- a/xen/arch/x86/vm_event.c
>>>> +++ b/xen/arch/x86/vm_event.c
>>> Actually, come to think of it, the same is true for the SYSENTER
>>> details, which by default are read/write to the guest while it is
>>> scheduled. As a result, the details reported here will from the last
>>> vcpu context switch, and possibly stale.
>> I'll look into it.
> The sysenter values look fine to me because vmx_save_vmcs_ctxt calls
> vmx_vmcs_save, which refreshes the values from the actual VMCS. It's
> only shadow_gs that is not refreshed.
So, you are correct that we call into vmx_vmcs_save() which causes the
SYSENTER details to be correct.
However, the same path also calls vmx_save_cpu_state() which saves
shadow_gs, and therefore ought to DTRT for the previous use in vm_event.
The problem is that vmx_{save,load}_cpu_state() only function correctly
in remote context, which is why the stale shadow_gs persists.
Contrary to what I said earlier, I now think that a better fix would be
to make the above functions safe to use use in current context (at least
for the save side - the restore side can probably just ASSERT() atm, as
it doesn't seem to have an equivalent use).
That way, the vm_event code doesn't need to contain any
context-sensitive code, which is a better overall, IMO.
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Tamas K Lengyel <tamas@tklengyel.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <jbeulich@suse.com>,
Razvan Cojocaru <rcojocaru@bitdefender.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH] x86/vm_event: correctly gather gs_shadow value
Date: Wed, 1 May 2019 18:02:13 +0100 [thread overview]
Message-ID: <cfddf089-496e-d935-2470-20afa280ba78@citrix.com> (raw)
Message-ID: <20190501170213.HPM6EQzYa2CZH7C2geEVJt_VxFs78GZ1dvFT3hNUP8I@z> (raw)
In-Reply-To: <CABfawhk_cCzL0XVUp6h-5QvXBDwqwf87+CqBvPDdeAHqAcrmvw@mail.gmail.com>
On 01/05/2019 15:58, Tamas K Lengyel wrote:
> On Wed, May 1, 2019 at 7:45 AM Tamas K Lengyel <tamas@tklengyel.com> wrote:
>> On Wed, May 1, 2019 at 1:50 AM Andrew Cooper <andrew.cooper3@citrix.com> wrote:
>>> On 01/05/2019 05:22, Tamas K Lengyel wrote:
>>>> Currently the gs_shadow value is only cached when the vCPU is being scheduled
>>>> out by Xen. Reporting this (usually) stale value through vm_event is incorrect,
>>>> since it doesn't represent the actual state of the vCPU at the time the event
>>>> was recorded. This prevents vm_event subscribers from correctly finding kernel
>>>> structures in the guest when it is trapped while in ring3.
>>>>
>>>> Signed-off-by: Tamas K Lengyel <tamas@tklengyel.com>
>>>> Cc: Razvan Cojocaru <rcojocaru@bitdefender.com>
>>>> Cc: Jan Beulich <jbeulich@suse.com>
>>>> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
>>>> Cc: Wei Liu <wei.liu2@citrix.com>
>>>> Cc: Roger Pau Monne <roger.pau@citrix.com>
>>>> ---
>>>> xen/arch/x86/vm_event.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c
>>>> index 51c3493b1d..4464940da7 100644
>>>> --- a/xen/arch/x86/vm_event.c
>>>> +++ b/xen/arch/x86/vm_event.c
>>> Actually, come to think of it, the same is true for the SYSENTER
>>> details, which by default are read/write to the guest while it is
>>> scheduled. As a result, the details reported here will from the last
>>> vcpu context switch, and possibly stale.
>> I'll look into it.
> The sysenter values look fine to me because vmx_save_vmcs_ctxt calls
> vmx_vmcs_save, which refreshes the values from the actual VMCS. It's
> only shadow_gs that is not refreshed.
So, you are correct that we call into vmx_vmcs_save() which causes the
SYSENTER details to be correct.
However, the same path also calls vmx_save_cpu_state() which saves
shadow_gs, and therefore ought to DTRT for the previous use in vm_event.
The problem is that vmx_{save,load}_cpu_state() only function correctly
in remote context, which is why the stale shadow_gs persists.
Contrary to what I said earlier, I now think that a better fix would be
to make the above functions safe to use use in current context (at least
for the save side - the restore side can probably just ASSERT() atm, as
it doesn't seem to have an equivalent use).
That way, the vm_event code doesn't need to contain any
context-sensitive code, which is a better overall, IMO.
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-05-01 17:03 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-01 4:22 [PATCH] x86/vm_event: correctly gather gs_shadow value Tamas K Lengyel
2019-05-01 4:22 ` [Xen-devel] " Tamas K Lengyel
2019-05-01 7:17 ` Razvan Cojocaru
2019-05-01 7:17 ` [Xen-devel] " Razvan Cojocaru
2019-05-01 7:38 ` Andrew Cooper
2019-05-01 7:38 ` [Xen-devel] " Andrew Cooper
2019-05-01 7:50 ` Andrew Cooper
2019-05-01 7:50 ` [Xen-devel] " Andrew Cooper
2019-05-01 13:45 ` Tamas K Lengyel
2019-05-01 13:45 ` [Xen-devel] " Tamas K Lengyel
2019-05-01 13:58 ` Tamas K Lengyel
2019-05-01 13:58 ` [Xen-devel] " Tamas K Lengyel
2019-05-01 14:19 ` Razvan Cojocaru
2019-05-01 14:19 ` [Xen-devel] " Razvan Cojocaru
2019-05-01 14:53 ` Tamas K Lengyel
2019-05-01 14:53 ` [Xen-devel] " Tamas K Lengyel
2019-05-01 15:01 ` Tamas K Lengyel
2019-05-01 15:01 ` [Xen-devel] " Tamas K Lengyel
2019-05-01 15:43 ` Razvan Cojocaru
2019-05-01 15:43 ` [Xen-devel] " Razvan Cojocaru
2019-05-01 15:52 ` Tamas K Lengyel
2019-05-01 15:52 ` [Xen-devel] " Tamas K Lengyel
2019-05-01 14:58 ` Tamas K Lengyel
2019-05-01 14:58 ` [Xen-devel] " Tamas K Lengyel
2019-05-01 17:02 ` Andrew Cooper [this message]
2019-05-01 17:02 ` Andrew Cooper
2019-05-01 17:10 ` Tamas K Lengyel
2019-05-01 17:10 ` [Xen-devel] " Tamas K Lengyel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cfddf089-496e-d935-2470-20afa280ba78@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=rcojocaru@bitdefender.com \
--cc=roger.pau@citrix.com \
--cc=tamas@tklengyel.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.