From patchwork Mon Aug 10 03:19:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 11706949 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E911913 for ; Mon, 10 Aug 2020 03:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DFDD206CD for ; Mon, 10 Aug 2020 03:19:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Tmo9Cxqn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726344AbgHJDTb (ORCPT ); Sun, 9 Aug 2020 23:19:31 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:41356 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726335AbgHJDTb (ORCPT ); Sun, 9 Aug 2020 23:19:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597029570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=peekaH/0IckWn3/1IzYlPPwoLP60dVkB6N6mz90SfA8=; b=Tmo9CxqnXkWks7mqpgym68eVmvis2ahoEtIEqe1r3QfQJGvEJVjWQdSn8jOdTyKwuZnJOq uPYm1F3gqtj4R2qLZWF+ldwvkSslryT2omO8j6nm50jGIHEndcZs3BytOTRKc8pt6nsqxg EYNG/jWXIDZjP+ZO+vu9DaMZvzuAagw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-413-tdH48uhUNauFz49nQKOFSA-1; Sun, 09 Aug 2020 23:19:26 -0400 X-MC-Unique: tdH48uhUNauFz49nQKOFSA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72A1D8015F3; Mon, 10 Aug 2020 03:19:25 +0000 (UTC) Received: from localhost (ovpn-13-99.pek2.redhat.com [10.72.13.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6F48177F9; Mon, 10 Aug 2020 03:19:21 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Ming Lei , Tetsuo Handa , Al Viro , Matthew Wilcox , stable@vger.kernel.org Subject: [PATCH] block: allow for_each_bvec to support zero len bvec Date: Mon, 10 Aug 2020 11:19:15 +0800 Message-Id: <20200810031915.2209658-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Block layer usually doesn't support or allow zero-length bvec. Since commit 1bdc76aea115 ("iov_iter: use bvec iterator to implement iterate_bvec()"), iterate_bvec() switches to bvec iterator. However, Al mentioned that 'Zero-length segments are not disallowed' in iov_iter. Fixes for_each_bvec() so that it can move on after seeing one zero length bvec. Signed-off-by: Ming Lei Link: https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg2262077.html Fixes: 1bdc76aea115 ("iov_iter: use bvec iterator to implement iterate_bvec()") Reported-by: Tetsuo Handa Tested-by: Tetsuo Handa Cc: Al Viro Cc: Matthew Wilcox Cc: Reported-by: syzbot Signed-off-by: Tetsuo Handa --- include/linux/bvec.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index ac0c7299d5b8..9c4fab5f22a7 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -117,11 +117,18 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, return true; } +static inline void bvec_iter_skip_zero_bvec(struct bvec_iter *iter) +{ + iter->bi_bvec_done = 0; + iter->bi_idx++; +} + #define for_each_bvec(bvl, bio_vec, iter, start) \ for (iter = (start); \ (iter).bi_size && \ ((bvl = bvec_iter_bvec((bio_vec), (iter))), 1); \ - bvec_iter_advance((bio_vec), &(iter), (bvl).bv_len)) + (bvl).bv_len ? bvec_iter_advance((bio_vec), &(iter), \ + (bvl).bv_len) : bvec_iter_skip_zero_bvec(&(iter))) /* for iterating one bio from start to end */ #define BVEC_ITER_ALL_INIT (struct bvec_iter) \