Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6099120rwr; Tue, 9 May 2023 10:10:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7BYPQsDyYS6ZB6ARcdQDQfKO3YpMI6HxTj+61g0Rbteq/nc8397aGZ+7O3gTA6fpPl16QO X-Received: by 2002:a17:90b:3a89:b0:24f:b0d7:9f07 with SMTP id om9-20020a17090b3a8900b0024fb0d79f07mr14786565pjb.17.1683652200800; Tue, 09 May 2023 10:10:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683652200; cv=none; d=google.com; s=arc-20160816; b=R8/boCvAwGtj8qAQ4gj5kOmKFVgD+GAVb4JesjTB1XwUmzH200MxQLokomFSaFkjPd Fn6w/tD15/TXiizdeq8w9o+BopemyEQid7awZsvLbEX0FXfQgpIDc4s+CoOh9pvXuexF uFEI4rAfrx82i1kbcRCEvMu3DK/N+8/1zEIgXi5DArfNuRon9DXJs2bjXyS3Ffox/4E6 /a0G0MuozNi9HT70RO/L64wZP59uXhNcwRhgSTR09RNDC2Jb78TJ++BTKrTn7Fh/V+HT RIv/BwRoCbq38Oo8UHKsMKoG38njNnBT42/rijOZglF9WFdxPUDNqfrKmolEOKCH8cYZ bOGw== 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=; b=gezmV4+ILUqJNnPqpJecNA2bbSzNetMcTSPtopnZ/oMvfR5L+oS/IFkTHpC5zabU2U tmewpGoE0nJHfIYNjy/JV2yBwSc+JSeJx21+7cyRMb3g2qYtY+UIhxUiU1Ek811n5y7D 4SJP7d0oXDfllai+EnB/efQmRQRFGBAQ/g5/xBc0Sor4NRvRFvKSKujyx1CL0Zx4EsJr VnD1BaM4SM3eyC8BHn7pbTEdG917p7PDs0+bhSM3r6tnon59NoStQTmT6E3j/Qo1C2xW ejMVcck2CwVX8QaDUN2GYNS7rCiYgKBYmw3MjxIYR53evibBREAwQCoVEnMWVfxOW1AH pJvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=kdwBwCR3; 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 6-20020a17090a190600b0022915b6dd7asi13461686pjg.145.2023.05.09.10.09.45; Tue, 09 May 2023 10:10:00 -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=kdwBwCR3; 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 S234970AbjEIQ6Y (ORCPT + 99 others); Tue, 9 May 2023 12:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234838AbjEIQ6C (ORCPT ); Tue, 9 May 2023 12:58:02 -0400 Received: from out-62.mta1.migadu.com (out-62.mta1.migadu.com [IPv6:2001:41d0:203:375::3e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9E322126 for ; Tue, 9 May 2023 09:57:21 -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=1683651439; 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=kdwBwCR3xVaP5Jo+IaCVgWgyW4Ce3kcbutp/EEyLJxQ81ZP1QgFIFCBVpPfLZYqpcUSZjS ZqoNakyb6ZKW9/hKVySDM9SU66Z1JNKNd2OyiIQSAZbFpvoIj95fSHFiMJ0M4veDRt2U3L Xb8o/Gae/L7EKhGQ8mj+UEpQfOAFNs4= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-bcachefs@vger.kernel.org Cc: Kent Overstreet , Jens Axboe , linux-block@vger.kernel.org Subject: [PATCH 10/32] block: Allow bio_iov_iter_get_pages() with bio->bi_bdev unset Date: Tue, 9 May 2023 12:56:35 -0400 Message-Id: <20230509165657.1735798-11-kent.overstreet@linux.dev> In-Reply-To: <20230509165657.1735798-1-kent.overstreet@linux.dev> References: <20230509165657.1735798-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