Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp341967rwp; Wed, 12 Jul 2023 14:19:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlEftx9L29+PPAaavpeqh3D8IAoiCd+qmwmKD4xRiQPU5T8BJb8rw3VQz7KilKyYqO4Sc/A6 X-Received: by 2002:a5d:5902:0:b0:314:1b64:1919 with SMTP id v2-20020a5d5902000000b003141b641919mr463197wrd.4.1689196793303; Wed, 12 Jul 2023 14:19:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689196793; cv=none; d=google.com; s=arc-20160816; b=gvispeZcxL3pqeEOMGVJqiVGPBE7TT+YEOD9V4FR0ScDhCLJu+HX1afwr0Ehj3rcOL GJy2/VQNObF53UfTsRtPanygU5MwX4Bo/kY4o+QpeJpCmJjpWYFA+CmyeWxvw+dfAuhz 4qR9FU8yJlHEMf1LXjkCqx3efLPJms2/c2mP9a+W2mY3t1cpUHHM2B+Or5ZQ1rBqWpRV 8kHQmY3qVLJ+Km7I+1TdoSPJcUqoKaawG16gd4D2NYbbKt650KHGdVzJ2R0rLuRt5jVd I9Pvy/hmfMqx3L7RwkNKekupO0YUD78jSAMIDIeYtENpRGR9VbjQ3VAuRYTjLt839EqR tS/Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t8R8a1McseA9yHEzYOxyXGPVlvlW3Oa2+9zEDFiMSek=; fh=sJsWSBWPIJkgSwI17z85AO/Im+IjRvWcbiPnY4aG1N4=; b=GySjrAksm5Tpqov6YCaEppyhgX6kDFRQHxfYyvhmw+xo8eFWp8CvonWmbIvCS7CKU8 ay7aQzF8ROM2UvMyYnthFcNPZdI62AcE46BuAv2Y2UVF6sFAA8QfIukeVHYdrPoESZ0H /je6MdARoPkNx9zQOFL6QnODlxVI28iAr1m23pqu2LJQb2Qsra4gCXqC8PueLhe0TEf/ zXqWtL/mArhi1kiuN1aYX+A/dN3QDh2oyVE3sTIINyD3CebD+ygwMhhj5tBg5LBf1GGI twlKgf/VJqI86ywWOD9D0J3uIsvLPe264QkuaAKmKe6sxaSRvnjo2ZmlnGgt6XnKHi5t Xydg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=RDJY9bec; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020aa7da96000000b0051e1b797279si5406193eds.166.2023.07.12.14.19.29; Wed, 12 Jul 2023 14:19:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=RDJY9bec; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229529AbjGLVOJ (ORCPT + 99 others); Wed, 12 Jul 2023 17:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233100AbjGLVNr (ORCPT ); Wed, 12 Jul 2023 17:13:47 -0400 Received: from out-56.mta1.migadu.com (out-56.mta1.migadu.com [IPv6:2001:41d0:203:375::38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C339430E8 for ; Wed, 12 Jul 2023 14:12:07 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1689196294; 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: in-reply-to:in-reply-to:references:references; bh=t8R8a1McseA9yHEzYOxyXGPVlvlW3Oa2+9zEDFiMSek=; b=RDJY9becWM6dp5APPe+W3+AhHdTbbxSheD0BdlQawbutc1QKgpGpErxhWourqz2W7amicS WJCuzEQEwd4JC+IWugS9xG/53kT6/mGiN+z6NXn9BRb98AaQoFAnpkW6neybyy/w9YpJ41 9JHr1hZHa7hMbqYWmdClwFy3NRwx89g= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , Jens Axboe , linux-block@vger.kernel.org Subject: [PATCH 05/20] block: Allow bio_iov_iter_get_pages() with bio->bi_bdev unset Date: Wed, 12 Jul 2023 17:11:00 -0400 Message-Id: <20230712211115.2174650-6-kent.overstreet@linux.dev> In-Reply-To: <20230712211115.2174650-1-kent.overstreet@linux.dev> References: <20230712211115.2174650-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org bio_iov_iter_get_pages() trims the IO based on the block size of the block device the IO will be issued to. However, bcachefs is a multi device filesystem; when we're creating the bio we don't yet know which block device the bio will be submitted to - we have to handle the alignment checks elsewhere. Thus this is needed to avoid a null ptr deref. Signed-off-by: Kent Overstreet Cc: Jens Axboe Cc: linux-block@vger.kernel.org --- block/bio.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/block/bio.c b/block/bio.c index 1e75840d17..e74a04ea14 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1245,7 +1245,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) struct page **pages = (struct page **)bv; ssize_t size, left; unsigned len, i = 0; - size_t offset, trim; + size_t offset; int ret = 0; /* @@ -1274,10 +1274,12 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) nr_pages = DIV_ROUND_UP(offset + size, PAGE_SIZE); - trim = size & (bdev_logical_block_size(bio->bi_bdev) - 1); - iov_iter_revert(iter, trim); + if (bio->bi_bdev) { + size_t trim = size & (bdev_logical_block_size(bio->bi_bdev) - 1); + iov_iter_revert(iter, trim); + size -= trim; + } - size -= trim; if (unlikely(!size)) { ret = -EFAULT; goto out; -- 2.40.1