From: Thomas Huth <thuth@redhat.com>
To: Cornelia Huck <cohuck@redhat.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
qemu-s390x@nongnu.org, qemu-devel@nongnu.org,
Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [PATCH] pc-bios/s390-ccw: Use memory barriers in virtio code
Date: Tue, 16 Feb 2021 15:21:45 +0100 [thread overview]
Message-ID: <a561530e-d800-67e0-ee2b-fea6efb4638c@redhat.com> (raw)
In-Reply-To: <20210216124757.4eb664e9.cohuck@redhat.com>
On 16/02/2021 12.47, Cornelia Huck wrote:
> On Tue, 16 Feb 2021 12:00:56 +0100
> Thomas Huth <thuth@redhat.com> wrote:
>
>> According to the virtio specification, a memory barrier should be
>> used before incrementing the idx field in the "available" ring.
>> So far, we did not do this in the s390-ccw bios yet, but recently
>> Peter Maydell saw problems with the s390-ccw bios when running
>> the qtests on an aarch64 host (the bios panic'ed with the message:
>> "SCSI cannot report LUNs: response VS RESP=09"), which could
>> maybe be related to the missing memory barriers. Thus let's add
>> those barriers now. Since we've only seen the problem on TCG so far,
>> a "bcr 14,0" should be sufficient here to trigger the tcg_gen_mb()
>> in the TCG translate code.
>>
>> (Note: The virtio spec also talks about using a memory barrier
>> *after* incrementing the idx field, but if I understood correctly
>> this is only required when using notification suppression - which
>> we don't use in the s390-ccw bios here)
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>> pc-bios/s390-ccw/virtio-net.c | 1 +
>> pc-bios/s390-ccw/virtio.c | 1 +
>> pc-bios/s390-ccw/virtio.h | 2 ++
>> 3 files changed, 4 insertions(+)
>>
>> diff --git a/pc-bios/s390-ccw/virtio-net.c b/pc-bios/s390-ccw/virtio-net.c
>> index 2fcb0a58c5..25598a7a97 100644
>> --- a/pc-bios/s390-ccw/virtio-net.c
>> +++ b/pc-bios/s390-ccw/virtio-net.c
>> @@ -127,6 +127,7 @@ int recv(int fd, void *buf, int maxlen, int flags)
>>
>> /* Mark buffer as available to the host again */
>> rxvq->avail->ring[rxvq->avail->idx % rxvq->num] = id;
>> + virtio_mb();
>> rxvq->avail->idx = rxvq->avail->idx + 1;
>> vring_notify(rxvq);
>>
>> diff --git a/pc-bios/s390-ccw/virtio.c b/pc-bios/s390-ccw/virtio.c
>> index ab49840db8..fb9687f9b3 100644
>> --- a/pc-bios/s390-ccw/virtio.c
>> +++ b/pc-bios/s390-ccw/virtio.c
>> @@ -154,6 +154,7 @@ void vring_send_buf(VRing *vr, void *p, int len, int flags)
>>
>> /* Chains only have a single ID */
>> if (!(flags & VRING_DESC_F_NEXT)) {
>> + virtio_mb();
>
> I think you need to also need barriers for changes to the buffers, as
> the spec talks about "manipulating the descriptor table".
Which paragraph in the virtio spec are you refering to here? I can't find
that part right now...
>> vr->avail->idx++;
>> }
>> }
>> diff --git a/pc-bios/s390-ccw/virtio.h b/pc-bios/s390-ccw/virtio.h
>> index 19fceb6495..6ac65482a9 100644
>> --- a/pc-bios/s390-ccw/virtio.h
>> +++ b/pc-bios/s390-ccw/virtio.h
>> @@ -271,6 +271,8 @@ struct VirtioCmd {
>> };
>> typedef struct VirtioCmd VirtioCmd;
>>
>> +#define virtio_mb() asm volatile("bcr 14,0" : : : "memory")
>
> The bios is built for z900, so you probably need a bcr15 here?
I thought about that, too, but for TCG, it currently should not matter since
both, 14 and 15, end up with the same code in op_bc() in
target/s390x/translate.c. And on a real host, we've never seen this problem
to occur, so it should not matter there, too. But if you prefer (e.g. in
case somebody tweaks the TCG implementation one day), I can also switch to
bcr15 instead.
Thomas
next prev parent reply other threads:[~2021-02-16 14:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-16 11:00 [PATCH] pc-bios/s390-ccw: Use memory barriers in virtio code Thomas Huth
2021-02-16 11:43 ` Peter Maydell
2021-02-16 11:47 ` Thomas Huth
2021-02-16 11:47 ` Cornelia Huck
2021-02-16 14:21 ` Thomas Huth [this message]
2021-02-16 14:30 ` Cornelia Huck
2021-02-16 14:32 ` Peter Maydell
2021-02-16 14:35 ` Thomas Huth
2021-02-16 14:37 ` Peter Maydell
2021-02-16 14:49 ` Cornelia Huck
2021-02-16 14:40 ` Halil Pasic
2021-02-16 15:17 ` Cornelia Huck
2021-02-16 16:15 ` Thomas Huth
2021-02-16 16:44 ` Peter Maydell
2021-02-16 17:11 ` Halil Pasic
2021-02-17 4:31 ` Richard Henderson
2021-02-17 11:15 ` Peter Maydell
2021-02-17 15:11 ` Richard Henderson
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=a561530e-d800-67e0-ee2b-fea6efb4638c@redhat.com \
--to=thuth@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).