Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1698482imu; Thu, 17 Jan 2019 01:38:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN7cRnImJf0rPcZ4OYrUlV9SVYK8SAygE79nDumMVsa1OWYON5QYZztzrAuljS99ep3O+aDW X-Received: by 2002:a63:4342:: with SMTP id q63mr12826864pga.63.1547717933720; Thu, 17 Jan 2019 01:38:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547717933; cv=none; d=google.com; s=arc-20160816; b=PAMdB1dUZrCEAT4gepHXDE+e+53QGtSpdgD/Nu4slQj++RLc6Y1cJuCcA1nZA64mEX VQEBJnyFA0dCDlVS1XyDwq0ewcUBajdvVyOb89JAPIUTvijo1PjNvq+uRBb7FbrFU6R4 w6pvOBIbDdD7y8ao0zFxl0iGFmKmMC4265/RQtFDidE0zFaS2KaAaV4NCxZqxuwXa4iw BeZWcUg5/6fG2lUz2szlD+w63oGGCwmbQdEac63iGqOlG4muM+wfnXQDgJI5iI6cQqzs c6WBzWMxvVJvqhNkhGFRyr1qfKGMiX5D8SD7jHBPFHMC4Ak4G6CIobg8uynnnbUuDZ88 JUMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=25nrOL6ovEnyOKENv1bWk0wHwAoaj7KvbT9Gv4Jmdco=; b=LWHrO+037JR8WgZ3j0arkfwz2RyM7XCiYhpZ/3Znh6iwSu+rqvqodkPnUU+RFU6WtY eshKsX4i2aZx7F+AjcGpY6tOZuWQRWJGde2KiswbPx/eJ8OSrPrziHU5Ub2vy4emK2lE fmxnCEVxq/aah3OGJhyKEPja1puOPMVTnDIM2WmxtYgyVawbgSMbNhIFhwVZwLeRK2d4 MV3OgRfgJqBRnfKJ2tPQPnkYHdr9FRXV6IeSxqijLQdzvTRdmOg5BhtLIFUbOtLebACT 3r1uea7TKRXZAtJhCqc0Enl6KbOuiHaQHQ7qt2U3BFAVRtELD+R1/OGiorPpw3BrhA6K Q0qA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k2si1104746pgh.63.2019.01.17.01.38.37; Thu, 17 Jan 2019 01:38:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729839AbfAQIUz (ORCPT + 99 others); Thu, 17 Jan 2019 03:20:55 -0500 Received: from smtp.ctxuk.citrix.com ([185.25.65.24]:7788 "EHLO SMTP.EU.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728331AbfAQIUz (ORCPT ); Thu, 17 Jan 2019 03:20:55 -0500 X-IronPort-AV: E=Sophos;i="5.56,488,1539648000"; d="scan'208";a="84713258" Date: Thu, 17 Jan 2019 09:20:43 +0100 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: Dongli Zhang CC: , , , , Subject: Re: [Xen-devel] [PATCH 1/1] xen-blkback: do not wake up shutdown_wq after xen_blkif_schedule() is stopped Message-ID: <20190117082043.7y4gl4uave5pgawf@mac> References: <1547646461-29803-1-git-send-email-dongli.zhang@oracle.com> <20190116145215.igakzdkklc6f7h6k@mac> <30770f68-34e0-d707-b087-c43f0b51cd81@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <30770f68-34e0-d707-b087-c43f0b51cd81@oracle.com> User-Agent: NeoMutt/20180716 X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To AMSPEX02CL02.citrite.net (10.69.22.126) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 17, 2019 at 10:10:00AM +0800, Dongli Zhang wrote: > Hi Roger, > > On 2019/1/16 下午10:52, Roger Pau Monné wrote: > > On Wed, Jan 16, 2019 at 09:47:41PM +0800, Dongli Zhang wrote: > >> There is no need to wake up xen_blkif_schedule() as kthread_stop() is able > >> to already wake up the kernel thread. > >> > >> Signed-off-by: Dongli Zhang > >> --- > >> drivers/block/xen-blkback/xenbus.c | 4 +--- > >> 1 file changed, 1 insertion(+), 3 deletions(-) > >> > >> diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c > >> index a4bc74e..37ac59e 100644 > >> --- a/drivers/block/xen-blkback/xenbus.c > >> +++ b/drivers/block/xen-blkback/xenbus.c > >> @@ -254,10 +254,8 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif) > >> if (!ring->active) > >> continue; > >> > >> - if (ring->xenblkd) { > >> + if (ring->xenblkd) > >> kthread_stop(ring->xenblkd); > >> - wake_up(&ring->shutdown_wq); > > > > I've now realized that shutdown_wq is basically useless, and should be > > removed, could you please do it in this patch? > > I do not think shutdown_wq is useless. > > It is used to halt the xen_blkif_schedule() kthread when > RING_REQUEST_PROD_OVERFLOW() returns true in __do_block_io_op(): > > 1121 static int > 1122 __do_block_io_op(struct xen_blkif_ring *ring) > ... ... > 1134 if (RING_REQUEST_PROD_OVERFLOW(&blk_rings->common, rp)) { > 1135 rc = blk_rings->common.rsp_prod_pvt; > 1136 pr_warn("Frontend provided bogus ring requests (%d - %d = > %d). Halting ring processing on dev=%04x\n", > 1137 rp, rc, rp - rc, ring->blkif->vbd.pdevice); > 1138 return -EACCES; > 1139 } > > > If there is bogus/invalid ring requests, __do_block_io_op() would return -EACCES > without modifying prod/cons index. > > Without shutdown_wq (just simply assuming we remove the below code without > handling -EACCES in xen_blkif_schedule()), the kernel thread would continue the > while loop. > > 648 if (ret == -EACCES) > 649 wait_event_interruptible(ring->shutdown_wq, > 650 kthread_should_stop()); > > > If xen_blkif_be_int() is triggered again (let's assume there is no optimization > on guest part and guest would send event for every request it puts on ring > buffer), we may come to do_block_io_op() again. > > > As the prod/cons index are not modified last time the code runs into > do_block_io_op() to process bogus request, we would hit the bogus request issue > again. > > > With shutdown_wq, the kernel kthread is blocked forever until such queue/ring is > destroyed. If we remove shutdown_wq, we are changing the policy to handle bogus > requests on ring buffer? AFAICT the only wakeup call to shutdown_wq is removed in this patch, hence waiting on it seems useless. I would replace the wait_event_interruptible call in xen_blkif_schedule with a break, so that the kthread ends as soon as a bogus request is found. I think there's no point in waiting for xen_blkif_disconnect to stop the kthread. Thanks, Roger.