QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Halil Pasic <pasic@linux.ibm.com>
To: Cornelia Huck <cohuck@redhat.com>
Cc: Thomas Huth <thuth@redhat.com>,
	Matthew Rosato <mjrosato@linux.ibm.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	David Hildenbrand <david@redhat.com>,
	qemu-devel@nongnu.org,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	qemu-s390x@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Andreas Krebbel <krebbel@linux.ibm.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [PATCH 1/2] virtio-ccw: fix virtio_set_ind_atomic
Date: Thu, 18 Jun 2020 01:56:41 +0200
Message-ID: <20200618015641.1db429fc.pasic@linux.ibm.com> (raw)
In-Reply-To: <20200616083333.2d4edfac.cohuck@redhat.com>

On Tue, 16 Jun 2020 08:33:33 +0200
Cornelia Huck <cohuck@redhat.com> wrote:

> >  #define atomic_cmpxchg__nocheck(ptr, old, new)    ({                    \   
> >  
> >      typeof_strip_qual(*ptr) _old = (old);                               \   
> >  
> >      (void)__atomic_compare_exchange_n(ptr, &_old, new, false,           \   
> >  
> >                                __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);      \   
> >  
> >      _old;                                                               \   
> >  
> >  })
> >  
> > ind_old is copied into _old in the macro. Instead of doing the copy from the
> > register the compiler reloads the value from memory. The result is that _old
> > and ind_old end up having different values. _old in r1 with the bits set
> > already and ind_old in r10 with the bits cleared. _old gets updated by CS
> > and matches ind_old afterwards - both with the bits being 0. So the !=
> > compare is false and the loop is left without having set any bits.
> > 
> > 
> > Paolo (to),
> > I am asking myself if it would be safer to add a barrier or something like
> > this in the macros in include/qemu/atomic.h.   
> 
> I'm also wondering whether this has been seen on other architectures as
> well? There are also some callers in non-s390x code, and dealing with
> this in common code would catch them as well.

Quite a bunch of users use something like old = atomic_read(..), where
atomic_read is documented as in docs/devel/atomics.rst:
- ``atomic_read()`` and ``atomic_set()``; these prevent the compiler from
  optimizing accesses out of existence and creating unsolicited
  accesses, but do not otherwise impose any ordering on loads and
  stores: both the compiler and the processor are free to reorder
  them.

Maybe I should have used that instead of volatile, but my problem was
that I didn't fully understand what atomic_read() does, and if it does
more than we need. I found the documentation just now.

Another bunch uses constants as old, which is also fine. And there is
a third bunch where I don't know whats up, partly because I did not
dig deep enough.

Regards,
Halil




  parent reply index

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16  4:50 [PATCH 0/2] two atomic_cmpxchg() related fixes Halil Pasic
2020-06-16  4:50 ` [PATCH 1/2] virtio-ccw: fix virtio_set_ind_atomic Halil Pasic
2020-06-16  5:58   ` Christian Borntraeger
2020-06-16  6:33     ` Cornelia Huck
2020-06-16  6:45       ` Christian Borntraeger
2020-06-19  7:14         ` Cornelia Huck
2020-06-17 23:56       ` Halil Pasic [this message]
2020-06-19  7:33         ` David Hildenbrand
2020-06-19  8:17           ` Halil Pasic
2020-06-16  9:31     ` Halil Pasic
2020-07-01 13:13   ` Christian Borntraeger
2020-07-04 18:34   ` Michael S. Tsirkin
2020-07-06  5:44     ` Christian Borntraeger
2020-07-06 11:19     ` Halil Pasic
2020-06-16  4:50 ` [PATCH 2/2] s390x/pci: fix set_ind_atomic Halil Pasic
2020-07-01 13:14   ` Christian Borntraeger
2020-07-01 12:01 ` [PATCH 0/2] two atomic_cmpxchg() related fixes Cornelia Huck
2020-07-01 12:06   ` Christian Borntraeger
2020-07-01 13:10     ` Cornelia Huck
2020-07-03 13:37     ` Halil Pasic
2020-07-03 14:03       ` Cornelia Huck
2020-07-02 11:18 ` Cornelia Huck

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=20200618015641.1db429fc.pasic@linux.ibm.com \
    --to=pasic@linux.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=krebbel@linux.ibm.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=thuth@redhat.com \
    /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

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git