From patchwork Fri Jul 14 14:22:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9841219 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 C7CD0602BD for ; Fri, 14 Jul 2017 14:22:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B70C228788 for ; Fri, 14 Jul 2017 14:22:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABD7828794; Fri, 14 Jul 2017 14:22:35 +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.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 146EE28788 for ; Fri, 14 Jul 2017 14:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754007AbdGNOWe (ORCPT ); Fri, 14 Jul 2017 10:22:34 -0400 Received: from mail-it0-f54.google.com ([209.85.214.54]:36676 "EHLO mail-it0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753968AbdGNOWd (ORCPT ); Fri, 14 Jul 2017 10:22:33 -0400 Received: by mail-it0-f54.google.com with SMTP id m68so22451918ith.1 for ; Fri, 14 Jul 2017 07:22:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=iOkCW0ITWYNyzPIKRSw4P317pBFObi2SVrcM9/pWNH0=; b=LHHq5MMIsgqlrPCDDSKH+muuyQdSSj+zSfvq58r5Dt7DsjSYjik5eIU5qVEA4LRGVI +bI5Iiew5gt8POl9W92eHzEkmThGMtAmGoNcPy6xNfD2tCkMLNE22dsDYYkaz5otkj02 /LEtXWLOnqGQnnhTsFmCOx4MCkwqkuUHRphUD+m2XKH1R/7YI6u6wmWZ+5asBMHGkr/F 14HDLOOrAjwFXlmTk4LIanD00FVwS2rO85Z3rCOcVFFW6Xl7aGq+XlNYZS9kotExRawU dhcZTViwI/m5bR/0WcH34Ne1Xm/Z5GJ5Efcti8cCCSr2AMNSVpPvGmJ7WGKljRurpiSN iRHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=iOkCW0ITWYNyzPIKRSw4P317pBFObi2SVrcM9/pWNH0=; b=Sr6hpq6WSFXjl/C1RhzKXYEUBZ6Ml+Dh95zE/04y1mm0Wfrj8ZK4MKf1zi7rCCuTw1 mhZ9I+PuPbHWf1yJlRH0J/cuS7UPqelf8p8fT0UkrlEUPYJj+7H+ZpLFgZbG2xNeJBkO 3cAjb97ue/MvPnawo/D/PGn96FoRXFXcm6J4rjOOO8b2vxWihzSVcwt75RXXfRu5W/Eq JJBHDPQngLk6SVvnWK3OMPNdRzTNFFq6W33U2zdfsR4xG6ar60q2qBi86B/JxsQ3HDmG pTYUjwGDHTwitJbux/m7kxQTy1z6D/ng8FhggMzNw/0+Fei9O1Ho2ZFup3rwUEWelZ2m 6HdQ== X-Gm-Message-State: AIVw111mqExUDxD7O2LR6GlbrvgHeA9ZSvXyOqOSEd8u0dlLFFJRQges iVLaK3okv6jq3Q12o/e+0w== X-Received: by 10.107.182.132 with SMTP id g126mr9491951iof.216.1500042152882; Fri, 14 Jul 2017 07:22:32 -0700 (PDT) Received: from [192.168.1.154] ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id 13sm4851197iod.45.2017.07.14.07.22.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 07:22:32 -0700 (PDT) Subject: Re: [PATCH] block: note about cloned bios and bio_for_each_segment_all To: Ming Lei , David Sterba Cc: linux-block , Liu Bo , fdmanana@suse.com References: <20170714134051.22756-1-dsterba@suse.com> From: Jens Axboe Message-ID: <06376146-e4c3-efd6-8893-155052b14034@kernel.dk> Date: Fri, 14 Jul 2017 08:22:31 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US 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 On 07/14/2017 07:47 AM, Ming Lei wrote: >> @@ -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++) >> -- >> 2.13.0 >> > > Maybe we can add a warning here if it is a cloned bio. I think that's a good idea, it's easy for people to get this wrong, and the consequences can be dire. How about something like this? diff --git a/include/linux/bio.h b/include/linux/bio.h index 7b1cf4ba0902..13b6ac6eae29 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -155,9 +155,12 @@ 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 + * before it got to the driver and the driver won't own all of it. + * + * Don't use this on cloned bio's. */ #define bio_for_each_segment_all(bvl, bio, i) \ + WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)); \ for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++) static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter,