From: "Michael S. Tsirkin" <mst@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] virtio-pci: implement cfg capability
Date: Sat, 4 Jul 2015 23:19:33 +0200 [thread overview]
Message-ID: <20150704230256-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <55958AE2.1020600@redhat.com>
On Thu, Jul 02, 2015 at 09:02:58PM +0200, Paolo Bonzini wrote:
>
>
> On 02/07/2015 21:00, Michael S. Tsirkin wrote:
> > On Thu, Jul 02, 2015 at 08:48:14PM +0200, Paolo Bonzini wrote:
> >>
> >>
> >> On 02/07/2015 15:00, Michael S. Tsirkin wrote:
> >>> + cfg = (void *)(proxy->pci_dev.config + proxy->config_cap);
> >>> + off = le32_to_cpu(cfg->cap.offset);
> >>> + len = le32_to_cpu(cfg->cap.length);
> >>> +
> >>> + if ((len == 1 || len == 2 || len == 4)) {
> >>> + address_space_write(&proxy->modern_as, off,
> >>> + MEMTXATTRS_UNSPECIFIED,
> >>> + cfg->pci_cfg_data, len);
> >>> + }
> >>
> >> This parses pci_cfg_data in target endianness I think. You just want to
> >> move the little-endian value from the config cap to the little-endian
> >> value in the modern_as, so you need to use ldl_le_p and
> >> address_space_stl_le.
> >
> > but isn't that two byteswaps? why isn't this same as memcpy?
>
> It is a memcpy if you write to RAM, but the MMIO ops take an unsigned
> integer, so you can still have one byteswap hiding; you have to be
> careful when you have this kind of "forwarder", and the simplest way to
> do it is to use an ldl/stl pair with the same endianness.
>
> Paolo
The fact that address_space_write/_read actually does a byteswap if
host!=target endian should probably be documented.
Or maybe it should be changed: it seems likely that non-target-specific devices
that use it do this incorrectly ATM. In particular, dma_memory_rw_relaxed calls
address_space_rw and since DMA originates with devices I think there's very
little chance that these actually want a different behaviour depending on the
target endian-ness.
Most likely, these only work correctly because DMA outside RAM
is highly unusual.
> >>> + }
> >>> +}
> >>> +
> >>> +static uint32_t virtio_read_config(PCIDevice *pci_dev,
> >>> + uint32_t address, int len)
> >>> +{
> >>> + VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> >>> + struct virtio_pci_cfg_cap *cfg;
> >>> +
> >>> + if (proxy->config_cap &&
> >>> + ranges_overlap(address, len, proxy->config_cap + offsetof(struct virtio_pci_cfg_cap,
> >>> + pci_cfg_data),
> >>> + sizeof cfg->pci_cfg_data)) {
> >>> + uint32_t off;
> >>> + uint32_t len;
> >>> +
> >>> + cfg = (void *)(proxy->pci_dev.config + proxy->config_cap);
> >>> + off = le32_to_cpu(cfg->cap.offset);
> >>> + len = le32_to_cpu(cfg->cap.length);
> >>> +
> >>> + if ((len == 1 || len == 2 || len == 4)) {
> >>> + address_space_read(&proxy->modern_as, off,
> >>> + MEMTXATTRS_UNSPECIFIED,
> >>> + cfg->pci_cfg_data, len);
> >>
> >> Same here, use address_space_ldl_le to read into an int, and stl_le_p to
> >> write into cfg->pci_cfg_data.
> >>
> >> The best way to check it, of course, is to write a unit test! :) But
> >> you could also use a Linux BE guest on LE host.
> >>
> >> Everything else looks good.
> >>
> >> Paolo
next prev parent reply other threads:[~2015-07-04 21:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-02 13:00 [Qemu-devel] [PATCH] virtio-pci: implement cfg capability Michael S. Tsirkin
2015-07-02 18:48 ` Paolo Bonzini
2015-07-02 19:00 ` Michael S. Tsirkin
2015-07-02 19:02 ` Paolo Bonzini
2015-07-04 21:19 ` Michael S. Tsirkin [this message]
2015-07-06 7:46 ` Paolo Bonzini
2015-07-06 8:33 ` Michael S. Tsirkin
2015-07-06 8:46 ` Paolo Bonzini
2015-07-06 9:06 ` Michael S. Tsirkin
2015-07-06 9:11 ` Peter Maydell
2015-07-06 10:03 ` Michael S. Tsirkin
2015-07-06 10:04 ` Peter Maydell
2015-07-06 10:31 ` Michael S. Tsirkin
2015-07-06 11:50 ` Peter Maydell
2015-07-06 12:04 ` Paolo Bonzini
2015-07-06 12:15 ` Michael S. Tsirkin
2015-07-06 12:12 ` Michael S. Tsirkin
2015-07-06 12:23 ` Paolo Bonzini
2015-07-03 9:34 ` Gerd Hoffmann
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=20150704230256-mutt-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@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).