All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] virtio-pci: implement cfg capability
Date: Thu, 2 Jul 2015 20:48:14 +0200	[thread overview]
Message-ID: <5595876E.2040803@redhat.com> (raw)
In-Reply-To: <1435842022-13980-1-git-send-email-mst@redhat.com>



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.

> +    }
> +}
> +
> +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

  reply	other threads:[~2015-07-02 18:48 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 [this message]
2015-07-02 19:00   ` Michael S. Tsirkin
2015-07-02 19:02     ` Paolo Bonzini
2015-07-04 21:19       ` Michael S. Tsirkin
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=5595876E.2040803@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=mst@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.