From: Razvan Cojocaru <rcojocaru@bitdefender.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: wei.liu2@citrix.com, george.dunlap@eu.citrix.com,
ian.jackson@eu.citrix.com, tim@xen.org,
George Dunlap <george.dunlap@citrix.com>,
xen-devel@lists.xen.org, paul.durrant@citrix.com,
david.vrabel@citrix.com, andrew.cooper3@citrix.com, keir@xen.org
Subject: Re: [for-4.7] x86/emulate: synchronize LOCKed instruction emulation
Date: Tue, 3 May 2016 17:20:51 +0300 [thread overview]
Message-ID: <cdebd72f-39c8-e91e-010d-09c99ae948cb@bitdefender.com> (raw)
In-Reply-To: <fc7bece1-0dce-892d-103a-8e7d3df914af@bitdefender.com>
On 04/27/2016 10:14 AM, Razvan Cojocaru wrote:
> On 04/27/2016 09:22 AM, Jan Beulich wrote:
>>>>> On 26.04.16 at 19:23, <rcojocaru@bitdefender.com> wrote:
>>> On 04/26/16 19:03, George Dunlap wrote:
>>>> On 19/04/16 17:35, Jan Beulich wrote:
>>>>>>>> Razvan Cojocaru <rcojocaru@bitdefender.com> 04/19/16 1:01 PM >>>
>>>>>> I think this might be because the LOCK prefix should guarantee that the
>>>>>> instruction that follows it has exclusive use of shared memory (for both
>>>>>> reads and writes) but I might be misreading the docs:
>>>>>
>>>>> LOCK definitely has no effect on other than the instruction it gets applied
>>>>> to.
>>>>
>>>> Sorry I wasn't involved in this discussion -- what was the conclusion here?
>>>>
>>>> FWIW Andy's suggestion of using a stub seemed like the most robust
>>>> solution, if that could be made to work.
>>>>
>>>> If you're going to submit a patch substantially similar to this one, let
>>>> me know so I can review the mm bits of the original patch.
>>>
>>> I'm not really sure.
>>>
>>> Regarding this version of the patch, Jan has asked for more information
>>> on the performance impact, but I'm not sure how to obtain it in a
>>> rigorous manner.
>>
>> That was only one half, which Andrew has now answered. The
>> other was the not understood issue with a later variant you had
>> tried.
>
> Right, there's the fact that this version (with read / write locking the
> whole function) works whereas just synchonizing hvmemul_cmpxchg() with a
> spin lock does not. It is not yet fully clear why (the part of the
> conversation at the very top of this email was an early attempt to
> elucidate it).
I've kept experimenting with the patch but can't quite figure out why
minimizing the lock scope to the writeback part would not be sufficient,
but it isn't.
I.e. with this code:
3824 writeback:
3825 ops->smp_lock(lock_prefix);
3826 switch ( dst.type )
3827 {
3828 case OP_REG:
3829 /* The 4-byte case *is* correct: in 64-bit mode we
zero-extend. */
3830 switch ( dst.bytes )
3831 {
3832 case 1: *(uint8_t *)dst.reg = (uint8_t)dst.val; break;
3833 case 2: *(uint16_t *)dst.reg = (uint16_t)dst.val; break;
3834 case 4: *dst.reg = (uint32_t)dst.val; break; /* 64b:
zero-ext */
3835 case 8: *dst.reg = dst.val; break;
3836 }
3837 break;
3838 case OP_MEM:
3839 if ( !(d & Mov) && (dst.orig_val == dst.val) &&
3840 !ctxt->force_writeback )
3841 /* nothing to do */;
3842 else if ( lock_prefix )
3843 rc = ops->cmpxchg(
3844 dst.mem.seg, dst.mem.off, &dst.orig_val,
3845 &dst.val, dst.bytes, ctxt);
3846 else
3847 rc = ops->write(
3848 dst.mem.seg, dst.mem.off, &dst.val, dst.bytes, ctxt);
3849 if ( rc != 0 )
3850 {
3851 ops->smp_unlock(lock_prefix);
3852 goto done;
3853 }
3854 default:
3855 break;
3856 }
3857 ops->smp_unlock(lock_prefix);
I can still reproduce the guest hang. But if I lock at the very
beginning of x86_emulate() and unlock before each return, no more hangs.
I would appreciate any suggestions on how to go about trying to narrow
the scope of the lock, or figure out what subtlety is at work here.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-05-03 14:20 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-13 12:26 [for-4.7] x86/emulate: synchronize LOCKed instruction emulation Razvan Cojocaru
2016-04-14 4:35 ` Jan Beulich
2016-04-14 5:56 ` Razvan Cojocaru
2016-04-14 6:09 ` Juergen Gross
2016-04-14 6:31 ` Razvan Cojocaru
2016-04-14 7:46 ` Juergen Gross
2016-04-14 8:01 ` Andrew Cooper
2016-04-14 8:18 ` Juergen Gross
2016-04-14 8:25 ` Razvan Cojocaru
2016-04-14 8:07 ` Andrew Cooper
2016-04-14 8:09 ` Razvan Cojocaru
2016-04-14 9:08 ` Razvan Cojocaru
2016-04-14 15:33 ` Jan Beulich
2016-04-14 15:44 ` Jan Beulich
2016-04-14 16:00 ` Razvan Cojocaru
2016-04-14 16:11 ` Jan Beulich
2016-04-14 8:51 ` Razvan Cojocaru
2016-04-14 15:31 ` Jan Beulich
2016-04-14 15:40 ` Razvan Cojocaru
2016-04-14 10:35 ` David Vrabel
2016-04-14 11:43 ` Razvan Cojocaru
2016-04-14 15:40 ` Jan Beulich
2016-04-14 15:45 ` Andrew Cooper
2016-04-14 16:09 ` Jan Beulich
2016-04-14 15:45 ` Razvan Cojocaru
2016-04-14 16:08 ` Jan Beulich
2016-04-18 12:14 ` Razvan Cojocaru
2016-04-18 16:45 ` Jan Beulich
2016-04-19 11:01 ` Razvan Cojocaru
2016-04-19 16:35 ` Jan Beulich
2016-04-26 16:03 ` George Dunlap
2016-04-26 17:23 ` Razvan Cojocaru
2016-04-26 17:39 ` Andrew Cooper
2016-04-27 6:25 ` Jan Beulich
2016-04-27 7:36 ` Andrew Cooper
2016-04-27 6:22 ` Jan Beulich
2016-04-27 7:14 ` Razvan Cojocaru
2016-05-03 14:20 ` Razvan Cojocaru [this message]
2016-05-03 14:30 ` Jan Beulich
2016-05-03 14:41 ` Razvan Cojocaru
2016-05-03 15:13 ` Jan Beulich
2016-05-04 11:32 ` Razvan Cojocaru
2016-05-04 13:42 ` Jan Beulich
2016-05-05 9:25 ` Razvan Cojocaru
2016-05-05 16:38 ` Jan Beulich
2016-05-13 15:27 ` Wei Liu
2016-05-13 15:51 ` Jan Beulich
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=cdebd72f-39c8-e91e-010d-09c99ae948cb@bitdefender.com \
--to=rcojocaru@bitdefender.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=david.vrabel@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=keir@xen.org \
--cc=paul.durrant@citrix.com \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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.