Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6834919pxv; Fri, 30 Jul 2021 03:39:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtUKjgXy8Y/08PiGn3M8APGk8Y5UpTVXLmef0ZqDMG4qFsQcmSqYS7YjID/0wsOUKz40x0 X-Received: by 2002:a05:6e02:190d:: with SMTP id w13mr720760ilu.53.1627641599397; Fri, 30 Jul 2021 03:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627641599; cv=none; d=google.com; s=arc-20160816; b=VSX4d8PkCvA2NSV8atzOzV9dUXDNkucHreLdZdzImYjKSMFCqcanhKrTPTnGw1nz8J yQdE7IDYAPdD9N+lAtDtuVbec8vOazhmMAassi7oEPXIqrbk9lndNsaKJT96SGTPjS3S Okkdp5LuWPPD5VZgZ3haX4rMEkb4poN0c3y+ce0nocTcd6du3sqpucn/oIesX1iFgxaR 8TKHY3C+Vsd5ap58eFHYrs4CChqTMpkS1GLgJo9nQottIzQi3SWxMICfZMZdhkd4hrK9 GHygYiDIiMsP4K2yu2k2al2KAN38bOiS55R8PfqDRInAhcCB0G8ftZvOyX/3Jfu5htre 5i5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W95cbauG07UE5MXy/pX7569F2n6zVdQ3MffM9g12IwM=; b=DciHaM0BTDZh4YblJevCPaSSDFun7Tib/zxlEGAgNz9qcYzTMInxBs8pBga/t6L3Pa gBaVCGYzChYVMKI4flEkiHRx0Z8IGM9i10TaSJxEbdYtpdz2yXFOw0Fja41n/ed1qwzU RcNTknet8PQqtVx3nP05PioqPt8/PE54kqCLkbh8JAUviWefPyclvkZqxJ6bKYcPDvUG SlAtXBkXKcZwQFYM6ZiIrv0wlxhIFprp5ifwULNM/EuRQZGcCRKUw/t/DotOYU9C2z1+ QRYkLlzTKZWsL8U/eHlY7jAczdl/LLy6gP1ucSQO3YePR8+5Q+lfMmaILT8w9Prk8Nmc SG/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=LomOsk91; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si1655078ilf.35.2021.07.30.03.39.47; Fri, 30 Jul 2021 03:39:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=LomOsk91; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238550AbhG3KjF (ORCPT + 99 others); Fri, 30 Jul 2021 06:39:05 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:52084 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238452AbhG3KjD (ORCPT ); Fri, 30 Jul 2021 06:39:03 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D295A20232; Fri, 30 Jul 2021 10:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1627641537; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W95cbauG07UE5MXy/pX7569F2n6zVdQ3MffM9g12IwM=; b=LomOsk913X41D6qB6XhpN71WDo5ikRSfS7EGiNTAyCwrhlOWUpLbYu1pAByNIXE5D6PlPE dF43zwmH0cjHh6uNnxT+1pHauIuf1f/5f1wvFKHV90qN/p79VFKGE3gABKt9uuWeBLnDtm G6qQiospr4xgQvQSZOwAsedHKB4OyhE= Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 8F465137DF; Fri, 30 Jul 2021 10:38:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id EBrIIcHWA2HPOAAAGKfGzw (envelope-from ); Fri, 30 Jul 2021 10:38:57 +0000 From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jens Axboe , Jan Beulich Subject: [PATCH v3 1/3] xen/blkfront: read response from backend only once Date: Fri, 30 Jul 2021 12:38:52 +0200 Message-Id: <20210730103854.12681-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210730103854.12681-1-jgross@suse.com> References: <20210730103854.12681-1-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to avoid problems in case the backend is modifying a response on the ring page while the frontend has already seen it, just read the response into a local buffer in one go and then operate on that buffer only. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich Acked-by: Roger Pau Monné --- drivers/block/xen-blkfront.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index d83fee21f6c5..15e840287734 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1496,7 +1496,7 @@ static bool blkif_completion(unsigned long *id, static irqreturn_t blkif_interrupt(int irq, void *dev_id) { struct request *req; - struct blkif_response *bret; + struct blkif_response bret; RING_IDX i, rp; unsigned long flags; struct blkfront_ring_info *rinfo = (struct blkfront_ring_info *)dev_id; @@ -1513,8 +1513,9 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) for (i = rinfo->ring.rsp_cons; i != rp; i++) { unsigned long id; - bret = RING_GET_RESPONSE(&rinfo->ring, i); - id = bret->id; + RING_COPY_RESPONSE(&rinfo->ring, i, &bret); + id = bret.id; + /* * The backend has messed up and given us an id that we would * never have given to it (we stamp it up to BLK_RING_SIZE - @@ -1522,39 +1523,39 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) */ if (id >= BLK_RING_SIZE(info)) { WARN(1, "%s: response to %s has incorrect id (%ld)\n", - info->gd->disk_name, op_name(bret->operation), id); + info->gd->disk_name, op_name(bret.operation), id); /* We can't safely get the 'struct request' as * the id is busted. */ continue; } req = rinfo->shadow[id].request; - if (bret->operation != BLKIF_OP_DISCARD) { + if (bret.operation != BLKIF_OP_DISCARD) { /* * We may need to wait for an extra response if the * I/O request is split in 2 */ - if (!blkif_completion(&id, rinfo, bret)) + if (!blkif_completion(&id, rinfo, &bret)) continue; } if (add_id_to_freelist(rinfo, id)) { WARN(1, "%s: response to %s (id %ld) couldn't be recycled!\n", - info->gd->disk_name, op_name(bret->operation), id); + info->gd->disk_name, op_name(bret.operation), id); continue; } - if (bret->status == BLKIF_RSP_OKAY) + if (bret.status == BLKIF_RSP_OKAY) blkif_req(req)->error = BLK_STS_OK; else blkif_req(req)->error = BLK_STS_IOERR; - switch (bret->operation) { + switch (bret.operation) { case BLKIF_OP_DISCARD: - if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) { + if (unlikely(bret.status == BLKIF_RSP_EOPNOTSUPP)) { struct request_queue *rq = info->rq; printk(KERN_WARNING "blkfront: %s: %s op failed\n", - info->gd->disk_name, op_name(bret->operation)); + info->gd->disk_name, op_name(bret.operation)); blkif_req(req)->error = BLK_STS_NOTSUPP; info->feature_discard = 0; info->feature_secdiscard = 0; @@ -1564,15 +1565,15 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) break; case BLKIF_OP_FLUSH_DISKCACHE: case BLKIF_OP_WRITE_BARRIER: - if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) { + if (unlikely(bret.status == BLKIF_RSP_EOPNOTSUPP)) { printk(KERN_WARNING "blkfront: %s: %s op failed\n", - info->gd->disk_name, op_name(bret->operation)); + info->gd->disk_name, op_name(bret.operation)); blkif_req(req)->error = BLK_STS_NOTSUPP; } - if (unlikely(bret->status == BLKIF_RSP_ERROR && + if (unlikely(bret.status == BLKIF_RSP_ERROR && rinfo->shadow[id].req.u.rw.nr_segments == 0)) { printk(KERN_WARNING "blkfront: %s: empty %s op failed\n", - info->gd->disk_name, op_name(bret->operation)); + info->gd->disk_name, op_name(bret.operation)); blkif_req(req)->error = BLK_STS_NOTSUPP; } if (unlikely(blkif_req(req)->error)) { @@ -1585,9 +1586,9 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) fallthrough; case BLKIF_OP_READ: case BLKIF_OP_WRITE: - if (unlikely(bret->status != BLKIF_RSP_OKAY)) + if (unlikely(bret.status != BLKIF_RSP_OKAY)) dev_dbg(&info->xbdev->dev, "Bad return from blkdev data " - "request: %x\n", bret->status); + "request: %x\n", bret.status); break; default: -- 2.26.2