From patchwork Fri Jul 14 13:40:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 9841115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7E1F9602BD for ; Fri, 14 Jul 2017 13:42:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7054728796 for ; Fri, 14 Jul 2017 13:42:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6535928798; Fri, 14 Jul 2017 13:42:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB8A328792 for ; Fri, 14 Jul 2017 13:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754090AbdGNNmI (ORCPT ); Fri, 14 Jul 2017 09:42:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:57512 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753635AbdGNNmH (ORCPT ); Fri, 14 Jul 2017 09:42:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 32B33AC29; Fri, 14 Jul 2017 13:42:06 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id DAB86DA8A2; Fri, 14 Jul 2017 15:40:52 +0200 (CEST) From: David Sterba To: linux-block@vger.kernel.org Cc: David Sterba , bo.li.liu@oracle.com, fdmanana@suse.com Subject: [PATCH] block: note about cloned bios and bio_for_each_segment_all Date: Fri, 14 Jul 2017 15:40:51 +0200 Message-Id: <20170714134051.22756-1-dsterba@suse.com> X-Mailer: git-send-email 2.13.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We've switched to cloned bios in btrfs and hit a nasty bug leading to corruptions, when cloned bios are iterated by bio_for_each_segment_all. Report and fix: https://patchwork.kernel.org/patch/9838535/ As a matter of precaution, we've added assertions to btrfs code to catch the bad usage pattern: https://patchwork.kernel.org/patch/9839267/ The cloned/bi_vcnt behaviour seems tobe implementation dependent and is not documented, so this patch at least warns about this one particular case but this might still be insufficient. CC: linux-block@vger.kernel.org Signed-off-by: David Sterba --- include/linux/bio.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 7b1cf4ba0902..f1ac84edcf39 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -156,6 +156,9 @@ static inline void *bio_data(struct bio *bio) /* * drivers should _never_ use the all version - the bio may have been split * before it got to the driver and the driver won't own all of it + * + * Note that cloned bios must not use this as their bi_vcnt may be invalid and + * this could lead to silent corruptions. */ #define bio_for_each_segment_all(bvl, bio, i) \ for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++)