From patchwork Tue Aug 30 20:57:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 9306029 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 DD780607F0 for ; Tue, 30 Aug 2016 20:56:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE2DE28D1E for ; Tue, 30 Aug 2016 20:56:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2CCC28D2A; Tue, 30 Aug 2016 20:56:43 +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 47D5028D1E for ; Tue, 30 Aug 2016 20:56:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754423AbcH3U4m (ORCPT ); Tue, 30 Aug 2016 16:56:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34206 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752388AbcH3U4m (ORCPT ); Tue, 30 Aug 2016 16:56:42 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 485498553C; Tue, 30 Aug 2016 20:56:41 +0000 (UTC) Received: from localhost (vpn-48-54.rdu2.redhat.com [10.10.48.54]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7UKudwL006211 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 30 Aug 2016 16:56:40 -0400 Date: Tue, 30 Aug 2016 16:57:33 -0400 From: Mike Snitzer To: Mikulas Patocka Cc: Ming Lei , Jens Axboe , Eric Wheeler , Christoph Hellwig , "open list:DEVICE-MAPPER (LVM)" , johnstonj.public@codenest.com, linux-block Subject: Re: dm-crypt: Fix error with too large bios Message-ID: <20160830205732.GA53993@redhat.com> References: <24746705-a3af-e634-e675-f2214b6cf356@kernel.dk> <20160826140501.GA1061@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 30 Aug 2016 20:56:41 +0000 (UTC) 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 Tue, Aug 30 2016 at 8:19P -0400, Mikulas Patocka wrote: > > > On Tue, 30 Aug 2016, Ming Lei wrote: > > > On Tue, Aug 30, 2016 at 5:57 AM, Mikulas Patocka wrote: > > > > > > > > > On Mon, 29 Aug 2016, Ming Lei wrote: > > > > > >> On Sat, Aug 27, 2016 at 11:09 PM, Mikulas Patocka wrote: > > >> > > > >> > But this patch won't work for device mapper, blk_bio_segment_split is > > >> > called from blk_queue_split and device mapper doesn't use blk_queue_split > > >> > (it can't because it frees queue->bio_split). > > >> > > > >> > We still need these two patches: > > >> > https://www.redhat.com/archives/dm-devel/2016-May/msg00211.html > > >> > https://www.redhat.com/archives/dm-devel/2016-May/msg00210.html > > >> > > >> About the 2nd patch, it might not be good enough because in theory > > >> a small size bio still may include big bvecs, such as, each bvec points > > >> to 512byte buffer, so strictly speaking the bvec number should > > >> be checked instead of bio size. > > >> > > >> Ming Lei > > > > > > This is not a problem. > > > > I meant the following code in your 2nd patch: > > > > + if (unlikely(bio->bi_iter.bi_size > BIO_MAX_SIZE) && > > + (bio->bi_rw & (REQ_FLUSH | REQ_DISCARD | REQ_WRITE)) == REQ_WRITE) > > + dm_accept_partial_bio(bio, BIO_MAX_SIZE >> SECTOR_SHIFT); > > > > And the check on .bi_size may not work. > > kcryptd_crypt_write_convert calls: > crypt_alloc_buffer(io, io->base_bio->bi_iter.bi_size) > > crypt_alloc_buffer does: > unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; > clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, cc->bs); > > So, if io->base_bio->bi_iter.bi_size <= BIO_MAX_SIZE, then nr_iovecs will > be less or equal than BIO_MAX_PAGES and the function bio_alloc_bioset will > succeed. > > (BTW. BIO_MAX_SIZE was removed in the current kernel, we should use > (BIO_MAX_PAGES << PAGE_SHIFT) instead). Is this revised patch OK with you? From: Mikulas Patocka Date: Tue, 30 Aug 2016 16:38:42 -0400 Subject: [PATCH] dm crypt: fix error with too large bcache bios When dm-crypt processes writes, it allocates a new bio in crypt_alloc_buffer(). The bio is allocated from a bio set and it can have at most BIO_MAX_PAGES vector entries, however the incoming bio can be larger if it was allocated by bcache. If the incoming bio is larger, bio_alloc_bioset() fails and an error is returned. To avoid the error, we test for a too large bio in the function crypt_map() and use dm_accept_partial_bio() to split the bio. dm_accept_partial_bio() trims the current bio to the desired size and asks DM core to send another bio with the rest of the data. This fix is wrapped with a check for CONFIG_BCACHE because there currently isn't any other code that generates too large bios. So unless bcache is configured there is no point wasting time making this check. Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org # v3.16+ --- drivers/md/dm-crypt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index eedba67..743f548 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -1924,6 +1924,12 @@ static int crypt_map(struct dm_target *ti, struct bio *bio) return DM_MAPIO_REMAPPED; } +#ifdef CONFIG_BCACHE + if (unlikely(bio->bi_iter.bi_size > (BIO_MAX_PAGES << PAGE_SHIFT)) && + bio_data_dir(bio) == WRITE) + dm_accept_partial_bio(bio, ((BIO_MAX_PAGES << PAGE_SHIFT) >> SECTOR_SHIFT)); +#endif + io = dm_per_bio_data(bio, cc->per_bio_data_size); crypt_io_init(io, cc, bio, dm_target_offset(ti, bio->bi_iter.bi_sector)); io->ctx.req = (struct skcipher_request *)(io + 1);