Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2354325pxb; Mon, 20 Sep 2021 19:53:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDXRIhFBuC2AA7LKhJrF1qtXmvwaVv6X9qHMZe1hxhuDVOvCjgBn3DsNSdPVdZQgMF4FSu X-Received: by 2002:a92:c8d2:: with SMTP id c18mr19253540ilq.121.1632192819614; Mon, 20 Sep 2021 19:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192819; cv=none; d=google.com; s=arc-20160816; b=NCB47SWCeAB5ZflYJWLlH7gYpT7uCF4Vo8grsBoxKWsIqoZo5z5JjfAjc9bAbIndkQ 6M0vv47bixlw/HDRew9KUjd/VcZRv4h+hL4J63DOL8LFnOpinel5sQOb+FWxfa9tYRiT Y1xRxm/InIseLkpelfh7UTPWyEqVyliTY5AjE7ydABRZBbK4ML1mwlGfSk6E6kF+sGN7 e9XxWexxUIfUoRmjt2b/OItXbdprNywmNBkIa2zsD1xtg1yy4kmPs3E6K6PjGiS336UZ EwHkqSW/0POwHRuiDxUCqlzk1vDhBRg+iIFt7tSuTbFljhRT2wuttwJOPghNGJvsclld dHrw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mxx5LZSd/gEC2ig2CuSBuQn1NeR3Q3p531sHhOTeIlc=; b=RC16J1TiwkheWzcsYe3pLjp5mqZYRWVzr6bVAflJoGQZs0eQ2+mHf/B2dTfAh1ypRv HPiXx1MxRc9PD8K7YF5UgRkv7FIudaMJaqVM3yYp3WUc/WrITp2mJiCToh/isFqGj08I JzSnUL8RymdkkpP6L6v9iBv1gN3sFWaIoyDbY0yC5CJwlItyHpSd2ncCDYs0y7NhmnQo 2XK84MIQFqTC6LLktt7OB3XSvJEEW17h1dNgqaxFS4GtKOKnJDSaUd9Y4Pe23EdvACs1 Pft075v/7IN5SlgA8IJb5L/wHrN8nuSs6XJshKH6JxvSVqhvjxhZnjQbNnTVFenFW+5G 4wYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XIHGKDEv; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si10718597jak.85.2021.09.20.19.53.27; Mon, 20 Sep 2021 19:53:39 -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=@linuxfoundation.org header.s=korg header.b=XIHGKDEv; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231266AbhITS5N (ORCPT + 99 others); Mon, 20 Sep 2021 14:57:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:33444 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384621AbhITSsa (ORCPT ); Mon, 20 Sep 2021 14:48:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3C72663376; Mon, 20 Sep 2021 17:34:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159250; bh=68CSBNoOkQxtmzCjZxQEbBNMeVx3W16PkVILzt8smsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XIHGKDEvS0QSYCZu2ctUARvHz6mwQQVDJUIGcLlR+Cf0iCWCUnRshVgw466nmcZ5F 1j6Xz7x2ywSLKKzGumV6EgewZSqw5mgHKR4hZdW+AXVf1GNPpDzSABYqdF8Z8qgPpf qpbqglpIP9m2sC7E5jjm4M3tNTh8ZdRj/a9WptTY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Ming Lei , Jens Axboe , Sasha Levin Subject: [PATCH 5.14 146/168] io_uring: retry in case of short read on block device Date: Mon, 20 Sep 2021 18:44:44 +0200 Message-Id: <20210920163926.455947511@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Ming Lei [ Upstream commit 7db304375e11741e5940f9bc549155035bfb4dc1 ] In case of buffered reading from block device, when short read happens, we should retry to read more, otherwise the IO will be completed partially, for example, the following fio expects to read 2MB, but it can only read 1M or less bytes: fio --name=onessd --filename=/dev/nvme0n1 --filesize=2M \ --rw=randread --bs=2M --direct=0 --overwrite=0 --numjobs=1 \ --iodepth=1 --time_based=0 --runtime=2 --ioengine=io_uring \ --registerfiles --fixedbufs --gtod_reduce=1 --group_reporting Fix the issue by allowing short read retry for block device, which sets FMODE_BUF_RASYNC really. Fixes: 9a173346bd9e ("io_uring: fix short read retries for non-reg files") Cc: Pavel Begunkov Signed-off-by: Ming Lei Reviewed-by: Pavel Begunkov Link: https://lore.kernel.org/r/20210821150751.1290434-1-ming.lei@redhat.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 0361c48c9cb0..43aaa3566431 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3286,6 +3286,12 @@ static inline int io_iter_do_read(struct io_kiocb *req, struct iov_iter *iter) return -EINVAL; } +static bool need_read_all(struct io_kiocb *req) +{ + return req->flags & REQ_F_ISREG || + S_ISBLK(file_inode(req->file)->i_mode); +} + static int io_read(struct io_kiocb *req, unsigned int issue_flags) { struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs; @@ -3340,7 +3346,7 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags) } else if (ret == -EIOCBQUEUED) { goto out_free; } else if (ret <= 0 || ret == io_size || !force_nonblock || - (req->flags & REQ_F_NOWAIT) || !(req->flags & REQ_F_ISREG)) { + (req->flags & REQ_F_NOWAIT) || !need_read_all(req)) { /* read all, failed, already did sync or don't want to retry */ goto done; } -- 2.30.2