qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Jagannathan Raman <jag.raman@oracle.com>
Cc: elena.ufimtseva@oracle.com, fam@euphon.net,
	swapnil.ingle@nutanix.com, john.g.johnson@oracle.com,
	qemu-devel@nongnu.org, kraxel@redhat.com, quintela@redhat.com,
	mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com,
	felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com,
	konrad.wilk@oracle.com, dgilbert@redhat.com,
	alex.williamson@redhat.com, thanos.makatos@nutanix.com,
	rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com,
	mreitz@redhat.com, ross.lagerwall@citrix.com,
	marcandre.lureau@gmail.com, pbonzini@redhat.com
Subject: Re: [PATCH v8 13/20] multi-process: PCI BAR read/write handling for proxy & remote endpoints
Date: Tue, 11 Aug 2020 15:04:23 +0100	[thread overview]
Message-ID: <20200811140423.GB18223@stefanha-x1.localdomain> (raw)
In-Reply-To: <3588624b278c97cb3c9d1eeda109ad36af39effc.1596217462.git.jag.raman@oracle.com>

[-- Attachment #1: Type: text/plain, Size: 4778 bytes --]

On Fri, Jul 31, 2020 at 02:20:20PM -0400, Jagannathan Raman wrote:
> +static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **errp)
> +{
> +    BarAccessMsg *bar_access = &msg->data1.bar_access;
> +    AddressSpace *as =
> +        bar_access->memory ? &address_space_memory : &address_space_io;
> +    MPQemuMsg ret = { 0 };
> +    MemTxResult res;
> +    uint64_t val;
> +    Error *local_err = NULL;
> +
> +    if (!is_power_of_2(bar_access->size) ||
> +       (bar_access->size > sizeof(uint64_t))) {
> +        ret.data1.u64 = UINT64_MAX;
> +        goto fail;
> +    }
> +
> +    val = cpu_to_le64(bar_access->val);
> +
> +    res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED,
> +                           (void *)&val, bar_access->size, true);
> +
> +    if (res != MEMTX_OK) {
> +        error_setg(errp, "Could not perform address space write operation,"
> +                   " inaccessible address: %lx in pid %d.",
> +                   bar_access->addr, getpid());
> +        ret.data1.u64 = -1;
> +    }
> +
> +fail:
> +    ret.cmd = RET_MSG;
> +    ret.size = sizeof(ret.data1);
> +
> +    mpqemu_msg_send(&ret, ioc, &local_err);
> +    if (local_err) {
> +        error_setg(errp, "Error while sending message to proxy "
> +                   "in remote process pid=%d", getpid());

There is an assertion failure if res != MEMTX_OK because errp was
already set. error_setg() must not be called on an Error pointer that
has already been set.

It is simplest to do:

  mpqemu_msg_send(&ret, ioc, (errp && *errp) ? NULL : &local_err);

> +    }
> +}
> +
> +static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp)
> +{
> +    BarAccessMsg *bar_access = &msg->data1.bar_access;
> +    MPQemuMsg ret = { 0 };
> +    AddressSpace *as;
> +    MemTxResult res;
> +    uint64_t val = 0;
> +    Error *local_err = NULL;
> +
> +    as = bar_access->memory ? &address_space_memory : &address_space_io;
> +
> +    if (!is_power_of_2(bar_access->size) ||
> +       (bar_access->size > sizeof(uint64_t))) {
> +        val = UINT64_MAX;
> +        goto fail;
> +    }
> +
> +    res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED,
> +                           (void *)&val, bar_access->size, false);
> +
> +    if (res != MEMTX_OK) {
> +        error_setg(errp, "Could not perform address space read operation,"
> +                   " inaccessible address: %lx in pid %d.",
> +                   bar_access->addr, getpid());
> +        val = UINT64_MAX;
> +        goto fail;
> +    }
> +
> +fail:
> +    ret.cmd = RET_MSG;
> +    ret.data1.u64 = le64_to_cpu(val);
> +    ret.size = sizeof(ret.data1);
> +
> +    mpqemu_msg_send(&ret, ioc, &local_err);
> +    if (local_err) {
> +        error_setg(errp, "Error while sending message to proxy "

Same here.

> +static void send_bar_access_msg(PCIProxyDev *pdev, MemoryRegion *mr,
> +                                bool write, hwaddr addr, uint64_t *val,
> +                                unsigned size, bool memory)
> +{
> +    MPQemuMsg msg = { 0 };
> +    long ret = -EINVAL;

long is not guaranteed to be 64-bit. This function supports 64-bit
accesses to BARs so uint64_t is needed here.

> +    Error *local_err = NULL;
> +
> +    msg.bytestream = 0;
> +    msg.size = sizeof(msg.data1);
> +    msg.data1.bar_access.addr = mr->addr + addr;
> +    msg.data1.bar_access.size = size;
> +    msg.data1.bar_access.memory = memory;
> +
> +    if (write) {
> +        msg.cmd = BAR_WRITE;
> +        msg.data1.bar_access.val = *val;
> +    } else {
> +        msg.cmd = BAR_READ;
> +    }
> +
> +    ret = mpqemu_msg_send_and_await_reply(&msg, pdev->ioc, &local_err);
> +    if (local_err) {
> +        error_report("Failed to send BAR command to the remote process.");

Leaks local_err. Please report the error message from local_err and then
free it.

> +const MemoryRegionOps proxy_mr_ops = {
> +    .read = proxy_bar_read,
> +    .write = proxy_bar_write,
> +    .endianness = DEVICE_NATIVE_ENDIAN,
> +    .impl = {
> +        .min_access_size = 1,
> +        .max_access_size = 1,

Should this be .max_access_size = 8?

> diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c
> index 5d04b81..82b8465 100644
> --- a/io/mpqemu-link.c
> +++ b/io/mpqemu-link.c
> @@ -269,6 +269,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)
>              return false;
>          }
>          break;
> +    case BAR_WRITE:
> +    case BAR_READ:
> +        if ((msg->size != sizeof(msg->data1)) || (msg->num_fds != 0)) {

What about bytestream? It would be cleanest not to send bytestream over
the wire. Since it is sent today the receiver can be confused if it has
the wrong value and some mpqemu_msg_valid() cases validate bytestream.
It is not validate here for some reason.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2020-08-11 14:06 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31 18:20 [PATCH v8 00/20] Initial support for multi-process qemu Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 01/20] memory: alloc RAM from file at offset Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 02/20] multi-process: Add config option for multi-process QEMU Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 03/20] multi-process: setup PCI host bridge for remote device Jagannathan Raman
2020-08-04 10:47   ` Stefan Hajnoczi
2020-07-31 18:20 ` [PATCH v8 04/20] multi-process: setup a machine object for remote device process Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 05/20] multi-process: add qio channel function to transmit Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 06/20] multi-process: define MPQemuMsg format and transmission functions Jagannathan Raman
2020-08-04 12:49   ` Stefan Hajnoczi
2020-07-31 18:20 ` [PATCH v8 07/20] multi-process: add co-routines to communicate with remote Jagannathan Raman
2020-08-10 16:02   ` Stefan Hajnoczi
2020-07-31 18:20 ` [PATCH v8 08/20] multi-process: Initialize message handler in remote device Jagannathan Raman
2020-08-04 12:58   ` Stefan Hajnoczi
2020-07-31 18:20 ` [PATCH v8 09/20] multi-process: Associate fd of a PCIDevice with its object Jagannathan Raman
2020-08-07 16:02   ` Stefan Hajnoczi
2020-07-31 18:20 ` [PATCH v8 10/20] multi-process: setup memory manager for remote device Jagannathan Raman
2020-08-10 15:27   ` Stefan Hajnoczi
2020-07-31 18:20 ` [PATCH v8 11/20] multi-process: introduce proxy object Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 12/20] multi-process: Forward PCI config space acceses to the remote process Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 13/20] multi-process: PCI BAR read/write handling for proxy & remote endpoints Jagannathan Raman
2020-08-11 14:04   ` Stefan Hajnoczi [this message]
2020-07-31 18:20 ` [PATCH v8 14/20] multi-process: Synchronize remote memory Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 15/20] multi-process: create IOHUB object to handle irq Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 16/20] multi-process: Retrieve PCI info from remote process Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 17/20] multi-process: heartbeat messages to remote Jagannathan Raman
2020-08-11 14:41   ` Stefan Hajnoczi
2020-08-14 23:01     ` Elena Ufimtseva
2020-08-19  8:00       ` Stefan Hajnoczi
2020-07-31 18:20 ` [PATCH v8 18/20] multi-process: perform device reset in the remote process Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 19/20] multi-process: add the concept description to docs/devel/qemu-multiprocess Jagannathan Raman
2020-07-31 18:20 ` [PATCH v8 20/20] multi-process: add configure and usage information Jagannathan Raman
2020-08-11 14:56 ` [PATCH v8 00/20] Initial support for multi-process qemu Stefan Hajnoczi

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=20200811140423.GB18223@stefanha-x1.localdomain \
    --to=stefanha@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=elena.ufimtseva@oracle.com \
    --cc=fam@euphon.net \
    --cc=felipe@nutanix.com \
    --cc=jag.raman@oracle.com \
    --cc=john.g.johnson@oracle.com \
    --cc=kanth.ghatraju@oracle.com \
    --cc=konrad.wilk@oracle.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=ross.lagerwall@citrix.com \
    --cc=rth@twiddle.net \
    --cc=swapnil.ingle@nutanix.com \
    --cc=thanos.makatos@nutanix.com \
    --cc=thuth@redhat.com \
    /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).