From: Thomas Huth <thuth@redhat.com>
To: Cornelia Huck <cohuck@redhat.com>,
Matthew Rosato <mjrosato@linux.ibm.com>
Cc: "Pierre Morel" <pmorel@linux.ibm.com>,
"David Hildenbrand" <david@redhat.com>,
qemu-s390x@nongnu.org,
"Richard Henderson" <richard.henderson@linaro.org>,
qemu-devel@nongnu.org, "Halil Pasic" <pasic@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@de.ibm.com>,
"Alex Williamson" <alex.williamson@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [PATCH for-5.2] s390x/pci: fix endianness issues
Date: Wed, 18 Nov 2020 10:38:00 +0100 [thread overview]
Message-ID: <c5e1c200-768b-561f-a6a8-2db6e811aaa8@redhat.com> (raw)
In-Reply-To: <20201118085154.1299507-1-cohuck@redhat.com>
On 18/11/2020 09.51, Cornelia Huck wrote:
> The zPCI group and function structures are big endian. However, we do
> not consistently store them as big endian locally, and are missing some
> conversions.
>
> Let's just store the structures as host endian instead and convert to
> big endian when actually handling the instructions retrieving the data.
>
> Also fix the layout of ClpReqQueryPciGrp: g is actually only 8 bit. This
> also fixes accesses on little endian hosts.
>
> Fixes: 28dc86a07299 ("s390x/pci: use a PCI Group structure")
> Fixes: 9670ee752727 ("s390x/pci: use a PCI Function structure")
> Fixes: 1e7552ff5c34 ("s390x/pci: get zPCI function info from host")
> Signed-off-by: Cornelia Huck <cohuck@redhat.com>
> ---
>
> Alternative approach to my patch from yesterday. The change is bigger,
> but the end result is arguably nicer.
Looks way better in my eyes, thanks!
[...]
> diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c
> index 58cd041d17fb..6c36201229f3 100644
> --- a/hw/s390x/s390-pci-inst.c
> +++ b/hw/s390x/s390-pci-inst.c
> @@ -281,7 +281,12 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_t ra)
> goto out;
> }
>
> - memcpy(resquery, &pbdev->zpci_fn, sizeof(*resquery));
> + stq_p(&resquery->sdma, pbdev->zpci_fn.sdma);
> + stq_p(&resquery->edma, pbdev->zpci_fn.edma);
> + stw_p(&resquery->pchid, pbdev->zpci_fn.pchid);
> + resquery->pfgid = pbdev->zpci_fn.pfgid;
> + stl_p(&resquery->fid, pbdev->zpci_fn.fid);
> + stl_p(&resquery->uid, pbdev->zpci_fn.uid);
Looking at what had been removed in 9670ee7527279, I think you likely miss
this here:
stw_p(&resquery->ug, pbdev->zpci_fn.ug)
?
> for (i = 0; i < PCI_BAR_COUNT; i++) {
> uint32_t data = pci_get_long(pbdev->pdev->config +
> @@ -313,6 +318,13 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_t ra)
> goto out;
> }
> memcpy(resgrp, &group->zpci_group, sizeof(ClpRspQueryPciGrp));
I think you likely could remove the memcpy now, too?
> + resgrp->fr = group->zpci_group.fr;
> + stq_p(&resgrp->dasm, group->zpci_group.dasm);
> + stq_p(&resgrp->msia, group->zpci_group.msia);
> + stw_p(&resgrp->mui, group->zpci_group.mui);
> + stw_p(&resgrp->i, group->zpci_group.i);
> + stw_p(&resgrp->maxstbl, group->zpci_group.maxstbl);
> + resgrp->version = group->zpci_group.version;
> stw_p(&resgrp->hdr.rsp, CLP_RC_OK);
> break;
> }
[...]
> diff --git a/include/hw/s390x/s390-pci-clp.h b/include/hw/s390x/s390-pci-clp.h
> index ea2b1378cd5a..96b8e3f1331b 100644
> --- a/include/hw/s390x/s390-pci-clp.h
> +++ b/include/hw/s390x/s390-pci-clp.h
> @@ -144,10 +144,10 @@ typedef struct ClpReqQueryPciGrp {
> ClpReqHdr hdr;
> uint32_t fmt;
> uint64_t reserved1;
> -#define CLP_REQ_QPCIG_MASK_PFGID 0xff
> - uint32_t g;
> - uint32_t reserved2;
> - uint64_t reserved3;
> + uint8_t reserved2[3];
> + uint8_t g;
> + uint32_t reserved3;
> + uint64_t reserved4;
> } QEMU_PACKED ClpReqQueryPciGrp;
This might even qualify as a separate patch, since it fixes a separate
problem on big endian hosts, too (g should have been masked with 0xff when
read as 32-bit value).
Thomas
next prev parent reply other threads:[~2020-11-18 9:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-18 8:51 [PATCH for-5.2] s390x/pci: fix endianness issues Cornelia Huck
2020-11-18 8:53 ` Cornelia Huck
2020-11-18 9:38 ` Thomas Huth [this message]
2020-11-18 10:19 ` Cornelia Huck
-- strict thread matches above, loose matches on Subject: below --
2020-11-17 17:13 Cornelia Huck
2020-11-17 17:59 ` Philippe Mathieu-Daudé
2020-11-17 18:19 ` Matthew Rosato
2020-11-17 18:30 ` Philippe Mathieu-Daudé
2020-11-17 18:39 ` Thomas Huth
2020-11-17 18:49 ` Philippe Mathieu-Daudé
2020-11-17 19:23 ` Thomas Huth
2020-11-17 19:20 ` Matthew Rosato
2020-11-17 19:21 ` Thomas Huth
2020-11-17 19:49 ` Matthew Rosato
2020-11-18 7:49 ` 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=c5e1c200-768b-561f-a6a8-2db6e811aaa8@redhat.com \
--to=thuth@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=mjrosato@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=philmd@redhat.com \
--cc=pmorel@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.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).