All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: paul.durrant@citrix.com,
	Razvan Cojocaru <rcojocaru@bitdefender.com>,
	xen-devel@lists.xen.org
Subject: Re: [PATCH RFC] x86/emulate: implement hvmemul_cmpxchg() with an actual CMPXCHG
Date: Tue, 28 Mar 2017 04:44:44 -0600	[thread overview]
Message-ID: <58DA5ABC0200007800148FFC@prv-mh.provo.novell.com> (raw)
In-Reply-To: <f2dbe771-7d45-e0f7-eef2-65ef269933a9@citrix.com>

>>> On 28.03.17 at 12:25, <andrew.cooper3@citrix.com> wrote:
> On 28/03/17 11:03, Jan Beulich wrote:
>>>>> On 28.03.17 at 11:14, <rcojocaru@bitdefender.com> wrote:
>>> I'm not sure that the RETRY model is what the guest OS expects. AFAIK, a
>>> failed CMPXCHG should happen just once, with the proper registers and ZF
>>> set. The guest surely expects neither that the instruction resume until
>>> it succeeds, nor that some hidden loop goes on for an undeterminate
>>> ammount of time until a CMPXCHG succeeds.
>> The guest doesn't observe the CMPXCHG failing - RETRY leads to
>> the instruction being restarted instead of completed.
> 
> And this probably is the root of the problem.  CMPXCHG on a contended
> location should be observed to fail from the guests point of view.

Oops - my reply was imprecise: A _guest_ CMPXCHG would of
course be observed to have failed by the guest. Us using
CMPXCHG to carry out some other atomic op wouldn't.

>>> The picture is further complicated by the two-part handling of
>>> instructions in x86_emulate(). For example, for CMPXCHG we have:
>>> [...]
>>> I now see that this is why using a spinlock only around the writeback
>>> part did not solve the issue: both the compare part and the writeback
>>> part need to be part of the same atomic operation - lock needs to be
>>> aquired before the cmp / ZF part.
>> No exactly: RMW insns require the lock to be acquired ahead of
>> the memory read, and dropped after the memory write.
>>
>>> Opinions and suggestions are appreciated. If I'm not mistaken, it looks
>>> like the smp_lock design is the better solution to the problem.
>> Andrew has told me that the re-work of how we do memory accesses
>> in the emulator is pretty high on his priority list now. Whether we'd
>> want to introduce an interim solution therefore depends on the time
>> scale to possibly reach the only ultimately correct solution (no longer
>> acting on intermediate copies of the data coming from guest memory,
>> which is only correct for plain reads and plain writes).
> 
> This re-enforces my opinion that mapping the destination and pointing a
> stub at the mapping is the only viable option.

Well, you re-state what I was saying.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-03-28 10:44 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24 13:24 [PATCH RFC] x86/emulate: implement hvmemul_cmpxchg() with an actual CMPXCHG Razvan Cojocaru
2017-03-28  9:14 ` Razvan Cojocaru
2017-03-28 10:03   ` Jan Beulich
2017-03-28 10:25     ` Andrew Cooper
2017-03-28 10:44       ` Jan Beulich [this message]
2017-03-29  5:59       ` Jan Beulich
2017-03-29  8:14         ` Razvan Cojocaru
2017-03-28 10:27     ` Razvan Cojocaru
2017-03-28 10:47       ` Jan Beulich
2017-03-28 10:50         ` Razvan Cojocaru
2017-03-28 11:32           ` Jan Beulich
2017-03-29 13:55           ` Jan Beulich
2017-03-29 14:00             ` Razvan Cojocaru
2017-03-29 15:04               ` Razvan Cojocaru
2017-03-29 15:49                 ` Razvan Cojocaru
2017-03-30 12:05                   ` Jan Beulich
2017-03-30 12:25                     ` Razvan Cojocaru
2017-03-30 12:56                     ` Razvan Cojocaru
2017-03-30 14:08                       ` Razvan Cojocaru
2017-03-30 14:21                         ` Jan Beulich
2017-03-30 15:05                           ` Razvan Cojocaru
2017-03-30 15:47                             ` Jan Beulich
2017-03-31  6:17                               ` Razvan Cojocaru
2017-03-31  7:34                                 ` Jan Beulich
2017-03-31  9:56                                   ` Razvan Cojocaru
2017-03-31 14:46                                     ` Jan Beulich
2017-03-31 15:01                                       ` Razvan Cojocaru
2017-03-31 15:04                                         ` Jan Beulich
2017-04-01 16:56                                           ` Razvan Cojocaru
2017-04-03 10:23                                             ` Jan Beulich
2017-04-03 18:20                                             ` Razvan Cojocaru
2017-04-03 18:36                                               ` Razvan Cojocaru
2017-04-04  9:07                                                 ` Jan Beulich
2017-04-04 12:01                                                   ` Razvan Cojocaru
2017-04-08 22:15                                                 ` Razvan Cojocaru
2017-04-09 11:03                                                   ` Razvan Cojocaru
2017-04-10 10:18                                                   ` Jan Beulich
2017-03-29 14:12             ` Razvan Cojocaru

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=58DA5ABC0200007800148FFC@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=paul.durrant@citrix.com \
    --cc=rcojocaru@bitdefender.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.