xen/blkback: use lateeoi irq binding
authorJuergen Gross <jgross@suse.com>
Tue, 3 Nov 2020 14:35:21 +0000 (15:35 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Nov 2020 17:26:30 +0000 (18:26 +0100)
commit 01263a1fabe30b4d542f34c7e2364a22587ddaf2 upstream.

In order to reduce the chance for the system becoming unresponsive due
to event storms triggered by a misbehaving blkfront use the lateeoi
irq binding for blkback and unmask the event channel only after
processing all pending requests.

As the thread processing requests is used to do purging work in regular
intervals an EOI may be sent only after having received an event. If
there was no pending I/O request flag the EOI as spurious.

This is part of XSA-332.

Cc: stable@vger.kernel.org
Reported-by: Julien Grall <julien@xen.org>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Wei Liu <wl@xen.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/block/xen-blkback/blkback.c
drivers/block/xen-blkback/xenbus.c

index a700e525535ce0c12b173712f00647d8b48273a8..4f643a87f9c7de806669c6939f6b0e887545b904 100644 (file)
@@ -183,7 +183,7 @@ static inline void shrink_free_pagepool(struct xen_blkif_ring *ring, int num)
 
 #define vaddr(page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page)))
 
-static int do_block_io_op(struct xen_blkif_ring *ring);
+static int do_block_io_op(struct xen_blkif_ring *ring, unsigned int *eoi_flags);
 static int dispatch_rw_block_io(struct xen_blkif_ring *ring,
                                struct blkif_request *req,
                                struct pending_req *pending_req);
@@ -608,6 +608,8 @@ int xen_blkif_schedule(void *arg)
        struct xen_vbd *vbd = &blkif->vbd;
        unsigned long timeout;
        int ret;
+       bool do_eoi;
+       unsigned int eoi_flags = XEN_EOI_FLAG_SPURIOUS;
 
        set_freezable();
        while (!kthread_should_stop()) {
@@ -632,16 +634,23 @@ int xen_blkif_schedule(void *arg)
                if (timeout == 0)
                        goto purge_gnt_list;
 
+               do_eoi = ring->waiting_reqs;
+
                ring->waiting_reqs = 0;
                smp_mb(); /* clear flag *before* checking for work */
 
-               ret = do_block_io_op(ring);
+               ret = do_block_io_op(ring, &eoi_flags);
                if (ret > 0)
                        ring->waiting_reqs = 1;
                if (ret == -EACCES)
                        wait_event_interruptible(ring->shutdown_wq,
                                                 kthread_should_stop());
 
+               if (do_eoi && !ring->waiting_reqs) {
+                       xen_irq_lateeoi(ring->irq, eoi_flags);
+                       eoi_flags |= XEN_EOI_FLAG_SPURIOUS;
+               }
+
 purge_gnt_list:
                if (blkif->vbd.feature_gnt_persistent &&
                    time_after(jiffies, ring->next_lru)) {
@@ -1117,7 +1126,7 @@ static void end_block_io_op(struct bio *bio)
  * and transmute  it to the block API to hand it over to the proper block disk.
  */
 static int
-__do_block_io_op(struct xen_blkif_ring *ring)
+__do_block_io_op(struct xen_blkif_ring *ring, unsigned int *eoi_flags)
 {
        union blkif_back_rings *blk_rings = &ring->blk_rings;
        struct blkif_request req;
@@ -1140,6 +1149,9 @@ __do_block_io_op(struct xen_blkif_ring *ring)
                if (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rc))
                        break;
 
+               /* We've seen a request, so clear spurious eoi flag. */
+               *eoi_flags &= ~XEN_EOI_FLAG_SPURIOUS;
+
                if (kthread_should_stop()) {
                        more_to_do = 1;
                        break;
@@ -1198,13 +1210,13 @@ done:
 }
 
 static int
-do_block_io_op(struct xen_blkif_ring *ring)
+do_block_io_op(struct xen_blkif_ring *ring, unsigned int *eoi_flags)
 {
        union blkif_back_rings *blk_rings = &ring->blk_rings;
        int more_to_do;
 
        do {
-               more_to_do = __do_block_io_op(ring);
+               more_to_do = __do_block_io_op(ring, eoi_flags);
                if (more_to_do)
                        break;
 
index 1d1f8665796793fe92ebc262fbd41f111322f4e4..702ebfc4face52755dce8d0af5100ff3c68ec06f 100644 (file)
@@ -236,9 +236,8 @@ static int xen_blkif_map(struct xen_blkif_ring *ring, grant_ref_t *gref,
                BUG();
        }
 
-       err = bind_interdomain_evtchn_to_irqhandler(blkif->domid, evtchn,
-                                                   xen_blkif_be_int, 0,
-                                                   "blkif-backend", ring);
+       err = bind_interdomain_evtchn_to_irqhandler_lateeoi(blkif->domid,
+                       evtchn, xen_blkif_be_int, 0, "blkif-backend", ring);
        if (err < 0) {
                xenbus_unmap_ring_vfree(blkif->be->dev, ring->blk_ring);
                ring->blk_rings.common.sring = NULL;