s390x/pci: fix set_ind_atomic
commit45175361f1bfc2d3ccdcb4b22570c2352f3de754
authorHalil Pasic <pasic@linux.ibm.com>
Tue, 16 Jun 2020 04:50:35 +0000 (16 06:50 +0200)
committerCornelia Huck <cohuck@redhat.com>
Fri, 3 Jul 2020 09:15:59 +0000 (3 11:15 +0200)
tree411f7e555d907b421add6a2d3458e50f5319d3df
parent1a8242f7c3f53341dd66253b142ecd06ce1d2a97
s390x/pci: fix set_ind_atomic

The atomic_cmpxchg() loop is broken because we occasionally end up with
old and _old having different values (a legit compiler can generate code
that accessed *ind_addr again to pick up a value for _old instead of
using the value of old that was already fetched according to the
rules of the abstract machine). This means the underlying CS instruction
may use a different old (_old) than the one we intended to use if
atomic_cmpxchg() performed the xchg part.

Let us use volatile to force the rules of the abstract machine for
accesses to *ind_addr. Let us also rewrite the loop so, we that the
new old is used to compute the new desired value if the xchg part
is not performed.

Fixes: 8cba80c3a0 ("s390: Add PCI bus support")
Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Message-Id: <20200616045035.51641-3-pasic@linux.ibm.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
hw/s390x/s390-pci-bus.c