mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "Michael S. Tsirkin" <mst@redhat.com>,
	"Wolfram Gloger" <wmglo@dent.med.uni-muenchen.de>,
	"David S. Miller" <davem@davemloft.net>
Subject: [27/84] virtio: support unlocked queue poll
Date: Wed, 31 Jul 2013 15:23:09 +0200	[thread overview]
Message-ID: <lsq.1375276989.488553581@decadent.org.uk> (raw)
In-Reply-To: <lsq.1375276989.251749228@decadent.org.uk>

3.2.50-rc1 review patch.  If anyone has any objections, please let me know.

------------------

From: Michael S. Tsirkin <mst@redhat.com>

commit cc229884d3f77ec3b1240e467e0236c3e0647c0c upstream.

This adds a way to check ring empty state after enable_cb outside any
locks. Will be used by virtio_net.

Note: there's room for more optimization: caller is likely to have a
memory barrier already, which means we might be able to get rid of a
barrier here.  Deferring this optimization until we do some
benchmarking.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[wg: Backported to 3.2]
Signed-off-by: Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
diff -upr linux-3.2.49/drivers/virtio/virtio_ring.c linux-3.2.49wg/drivers/virtio/virtio_ring.c
--- linux-3.2.49/drivers/virtio/virtio_ring.c	2013-07-27 18:13:40.000000000 +0200
+++ linux-3.2.49wg/drivers/virtio/virtio_ring.c	2013-07-27 13:57:28.000000000 +0200
@@ -360,9 +360,22 @@ void virtqueue_disable_cb(struct virtque
 }
 EXPORT_SYMBOL_GPL(virtqueue_disable_cb);
 
-bool virtqueue_enable_cb(struct virtqueue *_vq)
+/**
+ * virtqueue_enable_cb_prepare - restart callbacks after disable_cb
+ * @vq: the struct virtqueue we're talking about.
+ *
+ * This re-enables callbacks; it returns current queue state
+ * in an opaque unsigned value. This value should be later tested by
+ * virtqueue_poll, to detect a possible race between the driver checking for
+ * more work, and enabling callbacks.
+ *
+ * Caller must ensure we don't call this with other virtqueue
+ * operations at the same time (except where noted).
+ */
+unsigned virtqueue_enable_cb_prepare(struct virtqueue *_vq)
 {
 	struct vring_virtqueue *vq = to_vvq(_vq);
+	u16 last_used_idx;
 
 	START_USE(vq);
 
@@ -372,15 +385,45 @@ bool virtqueue_enable_cb(struct virtqueu
 	 * either clear the flags bit or point the event index at the next
 	 * entry. Always do both to keep code simple. */
 	vq->vring.avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT;
-	vring_used_event(&vq->vring) = vq->last_used_idx;
+	vring_used_event(&vq->vring) = last_used_idx = vq->last_used_idx;
+	END_USE(vq);
+	return last_used_idx;
+}
+EXPORT_SYMBOL_GPL(virtqueue_enable_cb_prepare);
+
+/**
+ * virtqueue_poll - query pending used buffers
+ * @vq: the struct virtqueue we're talking about.
+ * @last_used_idx: virtqueue state (from call to virtqueue_enable_cb_prepare).
+ *
+ * Returns "true" if there are pending used buffers in the queue.
+ *
+ * This does not need to be serialized.
+ */
+bool virtqueue_poll(struct virtqueue *_vq, unsigned last_used_idx)
+{
+	struct vring_virtqueue *vq = to_vvq(_vq);
+
 	virtio_mb();
-	if (unlikely(more_used(vq))) {
-		END_USE(vq);
-		return false;
-	}
+	return (u16)last_used_idx != vq->vring.used->idx;
+}
+EXPORT_SYMBOL_GPL(virtqueue_poll);
 
-	END_USE(vq);
-	return true;
+/**
+ * virtqueue_enable_cb - restart callbacks after disable_cb.
+ * @vq: the struct virtqueue we're talking about.
+ *
+ * This re-enables callbacks; it returns "false" if there are pending
+ * buffers in the queue, to detect a possible race between the driver
+ * checking for more work, and enabling callbacks.
+ *
+ * Caller must ensure we don't call this with other virtqueue
+ * operations at the same time (except where noted).
+ */
+bool virtqueue_enable_cb(struct virtqueue *_vq)
+{
+	unsigned last_used_idx = virtqueue_enable_cb_prepare(_vq);
+	return !virtqueue_poll(_vq, last_used_idx);
 }
 EXPORT_SYMBOL_GPL(virtqueue_enable_cb);
 
diff -upr linux-3.2.49/include/linux/virtio.h linux-3.2.49wg/include/linux/virtio.h
--- linux-3.2.49/include/linux/virtio.h	2012-01-05 00:55:44.000000000 +0100
+++ linux-3.2.49wg/include/linux/virtio.h	2013-07-27 13:57:28.000000000 +0200
@@ -96,6 +96,10 @@ void virtqueue_disable_cb(struct virtque
 
 bool virtqueue_enable_cb(struct virtqueue *vq);
 
+unsigned virtqueue_enable_cb_prepare(struct virtqueue *vq);
+
+bool virtqueue_poll(struct virtqueue *vq, unsigned);
+
 bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
 
 void *virtqueue_detach_unused_buf(struct virtqueue *vq);


  parent reply	other threads:[~2013-07-31 13:26 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-31 13:23 [00/84] 3.2.50-rc1 review Ben Hutchings
2013-07-31 13:23 ` [43/84] ALSA: 6fire: Fix unlocked snd_pcm_stop() call Ben Hutchings
2013-07-31 13:23 ` [55/84] Btrfs: re-add root to dead root list if we stop dropping it Ben Hutchings
2013-07-31 13:23 ` [11/84] l2tp: add missing .owner to struct pppox_proto Ben Hutchings
2013-07-31 13:23 ` [33/84] xen/blkback: Check for insane amounts of request on the ring (v6) Ben Hutchings
2013-07-31 13:23 ` [68/84] [SCSI] sd: fix crash when UA received on DIF enabled device Ben Hutchings
2013-07-31 13:23 ` [20/84] atl1e: fix dma mapping warnings Ben Hutchings
2013-07-31 13:23 ` [16/84] macvtap: correctly linearize skb when zerocopy is used Ben Hutchings
2013-07-31 13:23 ` [53/84] ACPI / video: ignore BIOS initial backlight value for Fujitsu E753 Ben Hutchings
2013-08-02 13:46   ` Luis Henriques
2013-08-02 14:24     ` Ben Hutchings
2013-07-31 13:23 ` [06/84] sh_eth: fix unhandled RFE interrupt Ben Hutchings
2013-07-31 13:23 ` [08/84] x25: Fix broken locking in ioctl error paths Ben Hutchings
2013-07-31 13:23 ` [31/84] tracing: Use current_uid() for critical time tracing Ben Hutchings
2013-07-31 13:23 ` [28/84] virtio_net: fix race in RX VQ processing Ben Hutchings
2013-07-31 13:23 ` [23/84] sparc32: vm_area_struct access for old Sun SPARCs Ben Hutchings
2013-07-31 13:23 ` [62/84] USB: cp210x: add MMB and PI ZigBee USB Device Support Ben Hutchings
2013-07-31 13:23 ` [15/84] ifb: fix rcu_sched self-detected stalls Ben Hutchings
2013-07-31 13:23 ` [18/84] dummy: fix oops when loading the dummy failed Ben Hutchings
2013-07-31 13:23 ` [13/84] ipv6: ip6_append_data_mtu did not care about pmtudisc and frag_size Ben Hutchings
2013-07-31 13:23 ` [65/84] drm/radeon: fix combios tables on older cards Ben Hutchings
2013-07-31 13:23 ` [25/84] sparc: tsb must be flushed before tlb Ben Hutchings
2013-07-31 13:23 ` [21/84] atl1e: unmap partially mapped skb on dma error and free skb Ben Hutchings
2013-07-31 13:23 ` [56/84] ALSA: usb-audio: 6fire: return correct XRUN indication Ben Hutchings
2013-07-31 13:23 ` [48/84] ASoC: s6000: Fix unlocked snd_pcm_stop() call Ben Hutchings
2013-07-31 13:23 ` [61/84] usb: cp210x support SEL C662 Vendor/Device Ben Hutchings
2013-07-31 13:23 ` [34/84] ASoC: sglt5000: Fix the default value of CHIP_SSS_CTRL Ben Hutchings
2013-07-31 13:23 ` Ben Hutchings [this message]
2013-07-31 13:23 ` [67/84] [SCSI] qla2xxx: Properly set the tagging for commands Ben Hutchings
2013-07-31 13:23 ` [22/84] vlan: fix a race in egress prio management Ben Hutchings
2013-07-31 13:23 ` [80/84] usb: serial: option: blacklist ONDA MT689DC QMI interface Ben Hutchings
2013-07-31 13:23 ` [09/84] net: Swap ver and type in pppoe_hdr Ben Hutchings
2013-07-31 13:23 ` [14/84] sunvnet: vnet_port_remove must call unregister_netdev Ben Hutchings
2013-07-31 13:23 ` [47/84] ALSA: pxa2xx: Fix unlocked snd_pcm_stop() call Ben Hutchings
2013-07-31 13:23 ` [76/84] usb: serial: option: Add ONYX 3G device support Ben Hutchings
2013-07-31 13:23 ` [82/84] usb: serial: option.c: remove ONDA MT825UP product ID fromdriver Ben Hutchings
2013-07-31 13:23 ` [57/84] usb: serial: cp210x: Add USB ID for Netgear Switches embedded serial adapter Ben Hutchings
2013-07-31 13:23 ` [69/84] nfsd: nfsd_open: when dentry_open returns an error do not propagate as struct file Ben Hutchings
2013-07-31 13:23 ` [59/84] USB: misc: Add Manhattan Hi-Speed USB DVI Converter to sisusbvga Ben Hutchings
2013-07-31 13:23 ` [46/84] ALSA: usx2y: Fix unlocked snd_pcm_stop() call Ben Hutchings
2013-07-31 13:23 ` [58/84] USB: storage: Add MicroVault Flash Drive to unusual_devs Ben Hutchings
2013-07-31 13:23 ` [60/84] USB: option: append Petatel NP10T device to GSM modems list Ben Hutchings
2013-07-31 13:23 ` [81/84] usb: serial: option: add Olivetti Olicard 200 Ben Hutchings
2013-07-31 13:23 ` [63/84] drm/radeon: Another card with wrong primary dac adj Ben Hutchings
2013-07-31 13:23 ` [24/84] sparc64 address-congruence property Ben Hutchings
2013-07-31 13:23 ` [19/84] ifb: fix oops when loading the ifb failed Ben Hutchings
2013-07-31 13:23 ` [79/84] xhci: fix null pointer dereference on ring_doorbell_for_active_rings Ben Hutchings
2013-07-31 13:23 ` [05/84] af_key: fix info leaks in notify messages Ben Hutchings
2013-07-31 13:23 ` [45/84] ALSA: ua101: Fix unlocked snd_pcm_stop() call Ben Hutchings
2013-07-31 13:23 ` [66/84] [SCSI] isci: Fix a race condition in the SSP task management path Ben Hutchings
2013-07-31 13:23 ` [74/84] powerpc/modules: Module CRC relocation fix causes perf issues Ben Hutchings
2013-07-31 13:23 ` [29/84] [SCSI] Fix incorrect memset in bnx2fc_parse_fcp_rsp Ben Hutchings
2013-07-31 13:23 ` [83/84] USB: mos7840: fix memory leak in open Ben Hutchings
2013-07-31 13:23 ` [84/84] usb: Clear both buffers when clearing a control transfer TT buffer Ben Hutchings
2013-07-31 13:23 ` [35/84] ASoC: sglt5000: Fix SGTL5000_PLL_FRAC_DIV_MASK Ben Hutchings
2013-07-31 13:23 ` [40/84] usb: dwc3: fix wrong bit mask in dwc3_event_type Ben Hutchings
2013-07-31 13:23 ` [02/84] ipv6: don't call addrconf_dst_alloc again when enable lo Ben Hutchings
2013-07-31 13:23 ` [64/84] drm/radeon: improve dac adjust heuristics for legacy pdac Ben Hutchings
2013-07-31 13:23 ` [26/84] ARM: OMAP: RX-51: change probe order of touchscreen and panel SPI devices Ben Hutchings
2013-08-01  5:49   ` Tomi Valkeinen
2013-08-01  9:32     ` Ben Hutchings
2013-08-02 20:14       ` Ben Hutchings
2013-07-31 13:23 ` [36/84] lockd: protect nlm_blocked access in nlmsvc_retry_blocked Ben Hutchings
2013-07-31 13:23 ` [54/84] Btrfs: fix lock leak when resuming snapshot deletion Ben Hutchings
2013-07-31 13:23 ` [38/84] ACPI / memhotplug: Fix a stale pointer in error path Ben Hutchings
2013-07-31 13:23 ` [32/84] xen/io/ring.h: new macro to detect whether there are too many requests on the ring Ben Hutchings
2013-07-31 13:23 ` [37/84] ext4: don't allow ext4_free_blocks() to fail due to ENOMEM Ben Hutchings
2013-07-31 13:23 ` [41/84] ALSA: asihpi: Fix unlocked snd_pcm_stop() call Ben Hutchings
2013-07-31 13:23 ` [04/84] ipv6: ip6_sk_dst_check() must not assume ipv6 dst Ben Hutchings
2013-07-31 13:23 ` [44/84] ASoC: max98088 - fix element type of the register cache Ben Hutchings
2013-07-31 13:23 ` [42/84] ALSA: atiixp: Fix unlocked snd_pcm_stop() call Ben Hutchings
2013-07-31 13:23 ` [72/84] staging: comedi: fix a race between do_cmd_ioctl() and read/write Ben Hutchings
2013-07-31 13:23 ` [01/84] bridge: fix switched interval for MLD Query types Ben Hutchings
2013-07-31 13:23 ` [70/84] USB: option: add D-Link DWM-152/C1 and DWM-156/C1 Ben Hutchings
2013-07-31 13:23 ` [30/84] fanotify: info leak in copy_event_to_user() Ben Hutchings
2013-07-31 13:23 ` [03/84] macvtap: fix recovery from gup errors Ben Hutchings
2013-07-31 13:23 ` [49/84] staging: line6: Fix unlocked snd_pcm_stop() call Ben Hutchings
2013-07-31 13:23 ` [71/84] staging: comedi: COMEDI_CANCEL ioctl should wake up read/write Ben Hutchings
2013-07-31 13:23 ` [39/84] usb: dwc3: gadget: don't prevent gadget from being probed if we fail Ben Hutchings
2013-07-31 13:23 ` [07/84] neighbour: fix a race in neigh_destroy() Ben Hutchings
2013-07-31 13:23 ` [12/84] ipv6: call udp_push_pending_frames when uncorking a socket with AF_INET pending data Ben Hutchings
2013-07-31 13:23 ` [17/84] 9p: fix off by one causing access violations and memory corruption Ben Hutchings
2013-07-31 13:23 ` [50/84] ALSA: hda - Add new GPU codec ID to snd-hda Ben Hutchings
2013-07-31 13:23 ` [78/84] usb: host: xhci: Enable XHCI_SPURIOUS_SUCCESS for all controllers with xhci 1.0 Ben Hutchings
2013-07-31 13:23 ` [75/84] USB: ti_usb_3410_5052: fix dynamic-id matching Ben Hutchings
2013-07-31 13:23 ` [77/84] xhci: Avoid NULL pointer deref when host dies Ben Hutchings
2013-07-31 13:23 ` [73/84] usb: option: add TP-LINK MA260 Ben Hutchings
2013-07-31 13:23 ` [52/84] ata: Fix DVD not dectected at some platform with Wellsburg PCH Ben Hutchings
2013-07-31 13:23 ` [10/84] ipv6,mcast: always hold idev->lock before mca_lock Ben Hutchings
2013-07-31 13:23 ` [51/84] ALSA: hda - Add new GPU codec ID to snd-hda Ben Hutchings
2013-08-01  9:30 ` [00/84] 3.2.50-rc1 review Ben Hutchings

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=lsq.1375276989.488553581@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=wmglo@dent.med.uni-muenchen.de \
    /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

Powered by JetHome