From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Stefano Stabellini <stefano.stabellini@xilinx.com>,
qemu-stable@nongnu.org, Greg Kurz <groug@kaod.org>
Subject: [PATCH 15/77] xen/9pfs: yield when there isn't enough room on the ring
Date: Thu, 3 Sep 2020 15:58:33 -0500 [thread overview]
Message-ID: <20200903205935.27832-16-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <20200903205935.27832-1-mdroth@linux.vnet.ibm.com>
From: Stefano Stabellini <stefano.stabellini@xilinx.com>
Instead of truncating replies, which is problematic, wait until the
client reads more data and frees bytes on the reply ring.
Do that by calling qemu_coroutine_yield(). The corresponding
qemu_coroutine_enter_if_inactive() is called from xen_9pfs_bh upon
receiving the next notification from the client.
We need to be careful to avoid races in case xen_9pfs_bh and the
coroutine are both active at the same time. In xen_9pfs_bh, wait until
either the critical section is over (ring->co == NULL) or until the
coroutine becomes inactive (qemu_coroutine_yield() was called) before
continuing. Then, simply wake up the coroutine if it is inactive.
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Message-Id: <20200521192627.15259-2-sstabellini@kernel.org>
Signed-off-by: Greg Kurz <groug@kaod.org>
(cherry picked from commit a4c4d462729466c4756bac8a0a8d77eb63b21ef7)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
hw/9pfs/xen-9p-backend.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
index fc197f6c8a..3c84c86ab8 100644
--- a/hw/9pfs/xen-9p-backend.c
+++ b/hw/9pfs/xen-9p-backend.c
@@ -37,6 +37,7 @@ typedef struct Xen9pfsRing {
struct iovec *sg;
QEMUBH *bh;
+ Coroutine *co;
/* local copies, so that we can read/write PDU data directly from
* the ring */
@@ -198,16 +199,20 @@ static void xen_9pfs_init_in_iov_from_pdu(V9fsPDU *pdu,
g_free(ring->sg);
ring->sg = g_new0(struct iovec, 2);
- xen_9pfs_in_sg(ring, ring->sg, &num, pdu->idx, size);
+ ring->co = qemu_coroutine_self();
+ /* make sure other threads see ring->co changes before continuing */
+ smp_wmb();
+again:
+ xen_9pfs_in_sg(ring, ring->sg, &num, pdu->idx, size);
buf_size = iov_size(ring->sg, num);
if (buf_size < size) {
- xen_pv_printf(&xen_9pfs->xendev, 0, "Xen 9pfs request type %d"
- "needs %zu bytes, buffer has %zu\n", pdu->id, size,
- buf_size);
- xen_be_set_state(&xen_9pfs->xendev, XenbusStateClosing);
- xen_9pfs_disconnect(&xen_9pfs->xendev);
+ qemu_coroutine_yield();
+ goto again;
}
+ ring->co = NULL;
+ /* make sure other threads see ring->co changes before continuing */
+ smp_wmb();
*piov = ring->sg;
*pniov = num;
@@ -292,6 +297,20 @@ static int xen_9pfs_receive(Xen9pfsRing *ring)
static void xen_9pfs_bh(void *opaque)
{
Xen9pfsRing *ring = opaque;
+ bool wait;
+
+again:
+ wait = ring->co != NULL && qemu_coroutine_entered(ring->co);
+ /* paired with the smb_wmb barriers in xen_9pfs_init_in_iov_from_pdu */
+ smp_rmb();
+ if (wait) {
+ cpu_relax();
+ goto again;
+ }
+
+ if (ring->co != NULL) {
+ qemu_coroutine_enter_if_inactive(ring->co);
+ }
xen_9pfs_receive(ring);
}
--
2.17.1
next prev parent reply other threads:[~2020-09-03 21:20 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-03 20:58 [PATCH 00/77] Patch Round-up for stable 5.0.1, freeze on 2020-09-10 Michael Roth
2020-09-03 20:58 ` [PATCH 01/77] hostmem: don't use mbind() if host-nodes is empty Michael Roth
2020-09-03 20:58 ` [PATCH 02/77] target/arm: Clear tail in gvec_fmul_idx_*, gvec_fmla_idx_* Michael Roth
2020-09-03 20:58 ` [PATCH 03/77] qemu-nbd: Close inherited stderr Michael Roth
2020-09-03 20:58 ` [PATCH 04/77] 9p: Lock directory streams with a CoMutex Michael Roth
2020-09-03 20:58 ` [PATCH 05/77] net: Do not include a newline in the id of -nic devices Michael Roth
2020-09-03 20:58 ` [PATCH 06/77] nbd/server: Avoid long error message assertions CVE-2020-10761 Michael Roth
2020-09-03 20:58 ` [PATCH 07/77] virtio-balloon: fix free page hinting without an iothread Michael Roth
2020-09-03 20:58 ` [PATCH 08/77] virtio-balloon: fix free page hinting check on unrealize Michael Roth
2020-09-03 20:58 ` [PATCH 09/77] virtio-balloon: unref the iothread when unrealizing Michael Roth
2020-09-03 20:58 ` [PATCH 10/77] block: Call attention to truncation of long NBD exports Michael Roth
2020-09-03 20:58 ` [PATCH 11/77] 9pfs: local: ignore O_NOATIME if we don't have permissions Michael Roth
2020-09-03 20:58 ` [PATCH 12/77] 9pfs: include linux/limits.h for XATTR_SIZE_MAX Michael Roth
2020-09-03 20:58 ` [PATCH 13/77] xen-9pfs: Fix log messages of reply errors Michael Roth
2020-09-03 20:58 ` [PATCH 14/77] Revert "9p: init_in_iov_from_pdu can truncate the size" Michael Roth
2020-09-03 20:58 ` Michael Roth [this message]
2020-09-04 10:59 ` [PATCH 15/77] xen/9pfs: yield when there isn't enough room on the ring Christian Schoenebeck
2020-09-03 20:58 ` [PATCH 16/77] ati-vga: check mm_index before recursive call (CVE-2020-13800) Michael Roth
2020-09-03 20:58 ` [PATCH 17/77] es1370: check total frame count against current frame Michael Roth
2020-09-03 20:58 ` [PATCH 18/77] Fix tulip breakage Michael Roth
2020-09-03 20:58 ` [PATCH 19/77] iotests/283: Use consistent size for source and target Michael Roth
2020-09-03 20:58 ` [PATCH 20/77] virtiofsd: add --rlimit-nofile=NUM option Michael Roth
2020-09-03 20:58 ` [PATCH 21/77] virtiofsd: stay below fs.file-max sysctl value (CVE-2020-10717) Michael Roth
2020-09-03 20:58 ` [PATCH 22/77] net: use peer when purging queue in qemu_flush_or_purge_queue_packets() Michael Roth
2020-09-03 20:58 ` [PATCH 23/77] KVM: x86: believe what KVM says about WAITPKG Michael Roth
2020-09-03 20:58 ` [PATCH 24/77] aio-posix: don't duplicate fd handler deletion in fdmon_io_uring_destroy() Michael Roth
2020-09-03 20:58 ` [PATCH 25/77] aio-posix: disable fdmon-io_uring when GSource is used Michael Roth
2020-09-03 20:58 ` [PATCH 26/77] linux-user/strace.list: fix epoll_create{, 1} -strace output Michael Roth
2020-09-03 20:58 ` [PATCH 27/77] libqos: usb-hcd-ehci: use 32-bit write for config register Michael Roth
2020-09-03 20:58 ` [PATCH 28/77] libqos: pci-pc: use 32-bit write for EJ register Michael Roth
2020-09-03 20:58 ` [PATCH 29/77] memory: Revert "memory: accept mismatching sizes in memory_region_access_valid" Michael Roth
2020-09-03 20:58 ` [PATCH 30/77] hw/riscv: Allow 64 bit access to SiFive CLINT Michael Roth
2020-09-03 20:58 ` [PATCH 31/77] xhci: fix valid.max_access_size to access address registers Michael Roth
2020-09-03 20:58 ` [PATCH 32/77] acpi: accept byte and word access to core ACPI registers Michael Roth
2020-09-03 20:58 ` [PATCH 33/77] hw/display/artist: Unbreak size mismatch memory accesses Michael Roth
2020-09-03 20:58 ` [PATCH 34/77] hw/net/e1000e: Do not abort() on invalid PSRCTL register value Michael Roth
2020-09-03 20:58 ` [PATCH 35/77] virtiofsd: Whitelist fchmod Michael Roth
2020-09-03 20:58 ` [PATCH 36/77] hw/audio/gus: Fix registers 32-bit access Michael Roth
2020-09-03 20:58 ` [PATCH 37/77] net/virtio: Fix failover_replug_primary() return value regression Michael Roth
2020-09-03 20:58 ` [PATCH 38/77] error: Use error_reportf_err() where appropriate Michael Roth
2020-09-03 20:58 ` [PATCH 39/77] usb/dev-mtp: Fix Error double free after inotify failure Michael Roth
2020-09-03 20:58 ` [PATCH 40/77] nbd: Avoid off-by-one in long export name truncation Michael Roth
2020-09-03 20:58 ` [PATCH 41/77] chardev/tcp: Fix error message double free error Michael Roth
2020-09-03 20:59 ` [PATCH 42/77] qga: fix assert regression on guest-shutdown Michael Roth
2020-09-03 20:59 ` [PATCH 43/77] util: Introduce qemu_get_host_name() Michael Roth
2020-09-03 20:59 ` [PATCH 44/77] qga: Use qemu_get_host_name() instead of g_get_host_name() Michael Roth
2020-09-03 20:59 ` [PATCH 45/77] docs/orangepi: Add instructions for resizing SD image to power of two Michael Roth
2020-09-03 20:59 ` [PATCH 46/77] tests/acceptance/boot_linux: Tag tests using a SD card with 'device:sd' Michael Roth
2020-09-03 20:59 ` [PATCH 47/77] tests/acceptance: allow console interaction with specific VMs Michael Roth
2020-09-03 20:59 ` [PATCH 48/77] tests/acceptance: refactor boot_linux to allow code reuse Michael Roth
2020-09-03 20:59 ` [PATCH 49/77] tests/acceptance: refactor boot_linux_console test " Michael Roth
2020-09-03 20:59 ` [PATCH 50/77] tests/acceptance/boot_linux: Expand SD card image to power of 2 Michael Roth
2020-09-03 20:59 ` [PATCH 51/77] hw/sd/sdcard: Restrict Class 6 commands to SCSD cards Michael Roth
2020-09-03 20:59 ` [PATCH 52/77] hw/sd/sdcard: Simplify realize() a bit Michael Roth
2020-09-03 20:59 ` [PATCH 53/77] hw/sd/sdcard: Do not allow invalid SD card sizes Michael Roth
2020-09-03 20:59 ` [PATCH 54/77] hw/sd/sdcard: Update coding style to make checkpatch.pl happy Michael Roth
2020-09-03 20:59 ` [PATCH 55/77] hw/sd/sdcard: Do not switch to ReceivingData if address is invalid Michael Roth
2020-09-03 20:59 ` [PATCH 56/77] target/hppa: Free some temps in do_sub Michael Roth
2020-09-03 20:59 ` [PATCH 57/77] tpm: tpm_spapr: Exit on TPM backend failures Michael Roth
2020-09-03 20:59 ` [PATCH 58/77] tests: tpm: Skip over pcrUpdateCounter byte in result comparison Michael Roth
2020-09-03 20:59 ` [PATCH 59/77] qdev: Fix device_add DRIVER,help to print to monitor Michael Roth
2020-09-03 20:59 ` [PATCH 60/77] virtio-balloon: Prevent guest from starting a report when we didn't request one Michael Roth
2020-09-03 20:59 ` [PATCH 61/77] virtio-balloon: Add locking to prevent possible race when starting hinting Michael Roth
2020-09-03 20:59 ` [PATCH 62/77] virtio-balloon: always indicate S_DONE when migration fails Michael Roth
2020-09-03 20:59 ` [PATCH 63/77] linux-headers: update against Linux 5.7-rc3 Michael Roth
2020-09-03 20:59 ` [PATCH 64/77] virtio-balloon: Replace free page hinting references to 'report' with 'hint' Michael Roth
2020-09-03 20:59 ` [PATCH 65/77] virtio: list legacy-capable devices Michael Roth
2020-09-03 20:59 ` [PATCH 66/77] virtio: verify that legacy support is not accidentally on Michael Roth
2020-09-07 12:18 ` Cornelia Huck
2020-09-03 20:59 ` [PATCH 67/77] intel_iommu: Use correct shift for 256 bits qi descriptor Michael Roth
2020-09-03 20:59 ` [PATCH 68/77] virtio-pci: Changed vdev to proxy for VirtIO PCI BAR callbacks Michael Roth
2020-09-03 20:59 ` [PATCH 69/77] libvhost-user: Report descriptor index on panic Michael Roth
2020-09-03 20:59 ` [PATCH 70/77] Update OpenBIOS images to 7f28286f built from submodule Michael Roth
2020-09-03 20:59 ` [PATCH 71/77] migration/block-dirty-bitmap: fix dirty_bitmap_mig_before_vm_start Michael Roth
2020-09-03 20:59 ` [PATCH 72/77] block: Fix bdrv_aligned_p*v() for qiov_offset != 0 Michael Roth
2020-09-03 20:59 ` [PATCH 73/77] iotests/028: Add test for cross-base-EOF reads Michael Roth
2020-09-03 20:59 ` [PATCH 74/77] nbd: Fix large trim/zero requests Michael Roth
2020-09-03 20:59 ` [PATCH 75/77] virtio-net: align RSC fields with updated virtio-net header Michael Roth
2020-09-03 20:59 ` [PATCH 76/77] hw/arm/sbsa-ref: fix typo breaking PCIe IRQs Michael Roth
2020-09-03 20:59 ` [PATCH 77/77] usb: fix setup_len init (CVE-2020-14364) Michael Roth
2020-09-04 9:20 ` [PATCH 00/77] Patch Round-up for stable 5.0.1, freeze on 2020-09-10 Philippe Mathieu-Daudé
2020-09-10 18:16 ` Michael Roth
2020-09-10 19:29 ` Philippe Mathieu-Daudé
2020-09-10 20:11 ` Philippe Mathieu-Daudé
2020-09-04 13:17 ` Thomas Huth
2020-09-10 18:14 ` Michael Roth
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=20200903205935.27832-16-mdroth@linux.vnet.ibm.com \
--to=mdroth@linux.vnet.ibm.com \
--cc=groug@kaod.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=stefano.stabellini@xilinx.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).