From nobody Fri Sep 25 17:49:11 2026 Received: from mx0a-00364e01.pphosted.com (mx0a-00364e01.pphosted.com [148.163.135.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B063A3D8128 for ; Wed, 9 Sep 2026 22:00:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991210; cv=none; b=mYqaBlDT4XyaE6wzwoXGhcNTzaJedyVDCONp/c6jlwDAJKK7Sa0y1YRz36Z+d/VyAjpghT0EM6v6QJm955IYUqo02bZKfOq6bBZmpn3OTq7V8SOKGx6b3Mk9nwhn6RyyS+bB2RnGpQPilXWufxyx9wRAyiTSXemPeu6TPCYhQAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991210; c=relaxed/simple; bh=c22FXI/yBAiFiP+IXJLY78+gOs/orKSY6ViRpYhhCRU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AeOUyZeWER6GuSBc/4/2FXf/lC8MzZAqT73HpTlkvgc4BPWDcbU0xrXinkNHNy4j9GiSOodUEvdU1oFv92budegZJHzeuF1WsS7yRM2AtMCO+cm2lMM0hWubkkhAOeCvFcLnwXQ0XEaFFmp07LYYTteORFS1LZuUUg2RnCzkmow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu; spf=pass smtp.mailfrom=columbia.edu; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=mELivoFW; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=izZ2w6BX; arc=none smtp.client-ip=148.163.135.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=columbia.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="mELivoFW"; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="izZ2w6BX" Received: from pps.filterd (m0167070.ppops.net [127.0.0.1]) by mx0a-00364e01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 689KYb1s713385 for ; Wed, 9 Sep 2026 18:00:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pps01; bh=GFCH X+CoYPEwVk2r0S6WYakXL0Z4yMswhTz3nIDnaZw=; b=mELivoFWRM3Xk/uoxiVB P1UaPobKbdIgy0sRf2QZRfBOzKvek30NrIlJ0MVLYyzklHsnZabk8oRRvrpLcEbn QVgRGC+2RrBuztyXakAXFhg0zVmj++YnjAquXh95KBNNB7876vMrRLtGi/bvi41i FxlydaFqicU0NtQXPK277m0/nJ9Hue6kcrt4hm9C8IhCCQbRsj1qdL7UkjNPhGXv hIGF+Ac+1zEZf0dDJ8afaH3ShAKd01Fz2UMOO3UIQZrDDr6HrcGSvzMKhO1l+QDb x0tX1pGqbfkhqzxXfp//NLNUCNqOpAefrApyxk0itzGgiWGsdtMziTN+Jx3wkcJi fA== Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-00364e01.pphosted.com (PPS) with ESMTPS id 4gkcxy20wr-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 09 Sep 2026 18:00:03 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-9393ac4961fso608664085a.2 for ; Wed, 09 Sep 2026 15:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; s=lionmail; t=1788991201; x=1789596001; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GFCHX+CoYPEwVk2r0S6WYakXL0Z4yMswhTz3nIDnaZw=; b=izZ2w6BX4os50wrqwOuwvt12j9lOlnVzGijRCsT+Qne4r2uXg9wzYmCBdPmbdnWbES p2zUyhjNX7TLiEMzFLRqAMjPhWNkhsfQ7NA1FXhZwxKpMcn0d/0yiE4G3NLCZUGI4MBA VG7U4tK3Hrv4LgSyzSFvOfkDSsXLqvFDiQbKAMJD0u7pzSU47TTTZM0Ee6fwtlMd11hO ngzUyoTVMKF/ygQOiLomHkts5IdZMPmKvtIryIB6yJhTCuZjDv7v3kPlzgodtiN3UBQm 6Z8D99tAD8xecyaOT3a1sEG3ZobZEg1Z0ZXPwiBUAPsV1hIhhoGPTp9xxBMISJdC2+60 /baA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788991201; x=1789596001; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GFCHX+CoYPEwVk2r0S6WYakXL0Z4yMswhTz3nIDnaZw=; b=SZzP7OKsltZZh4t+atIpLmOozN16xV0CD6H1AeyWqVHRiLm9KGxIY4ZhEXZq6Ixejv xqTOdFLZjLzoasDJwvc4TKUAjQ6x5zwycA5QM/8IanE3g4p0MSqk1TLrO/9Yzv2+9Ria C0QixNvKdy3lAc445q0d+KLZ1awd11+loztyPsfC2i0lEJZcGHk+fWq8qtHHgPR0bAcJ wu+bUTZnbgOQpt31F7Mhehum9gPMefblubL2S7GT7cF4imu+lrP4vG9ALFUfqmt5l4pM cRP/SkCPsDJbxl0WEPvLF5EBSze+bT2d6VkOkVHKnhgL5QSeSOXjkJHD4XnQqXY4OcHq WRuw== X-Forwarded-Encrypted: i=1; AKwUvBx/XQzyU/MR+SIAfRYDejJ+ySuVscKU6FOhhd0fQTexTmSYYKyiboYjGfTpNNa5SekT1g4zkMksPva+nrI=@vger.kernel.org X-Gm-Message-State: AFuF++nJzNTjZunuZ8LU4cWYzTf1NngDKI1SUzU1w0mjC/pZgu6oEHu1 2ARdDRx9rcaNI9J1puEYvwqX4YE/ZhxzukSh6hDbsT1wypHWJvTc1YSUnxbI/CWZ6KeYdqwYMJl D6uXKifSY81LCY3LfCPRvDsGAAzJQs9hQbfNjxuaexKP6G/WvdUcWyJhgIXrhOw== X-Gm-Gg: AYBFou1bPR9S/ndHrQc6vcS0foRSy/D5rL1Gvytq+0i8sjCyC1VYR1DZL1pCq2ed0Mp nn03Xx5XzInUBKvt3PI8UllfqIDGw2AWPlNyke9jOAyIOZH+on3b0chQ+n9hsjtJmS3WD5/J2oV hQ/h7rExQ23+BagxvtHgtLgKz8MFIbs5vdvsgoCJAHjBY+ktHflzUwJbHfpScfMMAnftR5iZRdl 6/9wZJmTo4laMU9O18lwqFIoW4pCjoCZqjkzwUCYxWHp07kJbLn1SHOOWKYK2Mt/uzEa/M8VVEp /SxqjQLSVpylB/Um7qTw9iN9hrK7LUVpYILe/gPaK+sCHh1Y4vlLH7BJ7zAUiiTkP6jYjdtkT/n ACCxVFbKIyy8Fr2p/w3q/Efft29tfsiSm1gqFybRLNZWeYAew X-Received: by 2002:a05:620a:2854:b0:939:6dff:c0f0 with SMTP id af79cd13be357-939803f60f2mr3819824085a.13.1788991201339; Wed, 09 Sep 2026 15:00:01 -0700 (PDT) X-Received: by 2002:a05:620a:2854:b0:939:6dff:c0f0 with SMTP id af79cd13be357-939803f60f2mr3819820385a.13.1788991200828; Wed, 09 Sep 2026 15:00:00 -0700 (PDT) Received: from [127.0.1.1] (nat-128-59-176-193.net.columbia.edu. [128.59.176.193]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9397fbe31c6sm1535326985a.46.2026.09.09.14.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2026 14:59:59 -0700 (PDT) From: Tal Zussman Date: Wed, 09 Sep 2026 17:59:39 -0400 Subject: [PATCH v3 1/7] block: use iomap_dirty_folio for block devices Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-blkdev-fixes-v3-1-1a5222c6e8ad@columbia.edu> References: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> In-Reply-To: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> To: Jens Axboe , Christoph Hellwig , Johannes Thumshirn , Luis Chamberlain , Hannes Reinecke , "Matthew Wilcox (Oracle)" , John Garry , Christian Brauner , "Darrick J. Wong" , Keith Busch , "Martin K. Petersen" Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Sashiko , Tal Zussman X-Mailer: b4 0.17-dev-db0b7 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788991197; l=2128; i=tz2294@columbia.edu; s=20250528; h=from:subject:message-id; bh=c22FXI/yBAiFiP+IXJLY78+gOs/orKSY6ViRpYhhCRU=; b=iHokoII25ADN4u/+WlNa0C8AdoUbSX1R/ZQQttl6llmXcfwkgvYlbWun8mQXNqsc1ZZiUin8X Qntxha+O6C3DnCTye+n2buX8TPhr80aw2n4RIz/fHGfh2yR6bvMiu7q X-Developer-Key: i=tz2294@columbia.edu; a=ed25519; pk=BIj5KdACscEOyAC0oIkeZqLB3L94fzBnDccEooxeM5Y= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTA5MDI0NiBTYWx0ZWRfX6WRvDDAe/qCF Z+cUNFYyWUCEt9LWNm83tGndk4yJ5rLwBOdNs4sEiUTLa6VZEv23TNlC8bfuBAyQeRGrrLxZxl6 Ajj7bDovAr/VBGLtw3CuBLY0XANxzdC+Boiu2Nm2qb+etjsWcMajq8+/0SZaGD+QfrhL02+ffVm oj1V5mKe8ju6qldZqm6IKlPmG2P0BjrmRUVKnWgvLG2lviCsm31LzJYLEtSKDGGLNScMXkf39vl bVbWpQaWmrGmnE8ON2Vuh/Uta3oGOhjCinQlyScYCKIN3WaIZprJ8byniu7HlVGt2L4ykbI8Ads IdRH8+6LpdKSYHS43ZlbpRJB5hN7HaFPPQ+XYWveISk4+axnBZgVTpvyVcSjBq4xiYbcIhQik3a xt9wOte/wcrkBZ7qe+/o/r6MqpVtcI3DLwuGkY1fL8RVXpAZHNnK9TBvxOJeNaFRzLp5kNbyjV2 5AfhKwoFivqC54cJaDw== X-Proofpoint-GUID: UWYswG3d8N-4zdEsPmMM7iijtjY2PEC1 X-Proofpoint-ORIG-GUID: UWYswG3d8N-4zdEsPmMM7iijtjY2PEC1 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTA5MDI0NiBTYWx0ZWRfXwDx41i0Tw76e NpQTY2+S1bZGH83FT5rmMLU7TXUxiCBPKM1/Rvs/0L7SCNqbRII3loF1LkvDhhhHj9nDYh8p4uQ cZx/0zYLJBPvjxfpjSSPqs3mIAEkglXRq4K/4WuOsc3JbdqlHbQR X-Authority-Analysis: v=2.4 cv=E/5YNqdl c=1 sm=1 tr=0 ts=6aa1d6e3 cx=c_pps a=HLyN3IcIa5EE8TELMZ618Q==:117 a=fJxgZNdXt3opHMdyAp+FXA==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=x7bEGLp0ZPQA:10 a=A0y_DWxS2BwA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Da8U98TiO7q1upZEImrf:22 a=svvvyxlR1OQQkelhaPoB:22 a=NEAV23lmAAAA:8 a=c92rfblmAAAA:8 a=VwQbUJbxAAAA:8 a=lHyHCDWJ2e6pF_oXpYUA:9 a=QEXdDO2ut3YA:10 a=bTQJ7kPSJx9SKPbeHEYW:22 a=GvGzcOZaWPEFPQC_NcjD:22 X-Proofpoint-Virus-Version: vendor=nai engine=6900 definitions=11900 signatures=596817 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=10 adultscore=0 malwarescore=0 suspectscore=0 phishscore=0 spamscore=0 clxscore=1015 bulkscore=10 priorityscore=1501 lowpriorityscore=10 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609090246 With CONFIG_BUFFER_HEAD=3Dn, block devices are written back through iomap, but def_blk_aops uses filemap_dirty_folio, which only sets PG_dirty. It does not set the per-block dirty bits in the folio's iomap_folio_state, so iomap_writeback_folio() finds no dirty range, submits no I/O and clears PG_dirty, resulting in data loss. Other iomap users set .dirty_folio to iomap_dirty_folio, which marks the folio's blocks dirty before calling filemap_dirty_folio(). This is only observable with block size < folio size. With a single block there is no iomap_folio_state to get out of sync and iomap_writeback_folio() marks the whole folio dirty itself. For a page-aligned device, this may require using the BLKBSZSET ioctl to set the block size, which requires CAP_SYS_ADMIN. A device whose size is not page aligned already gets a sub-page block size from set_init_blocksize(), so no ioctl and no privilege is needed. To reproduce, on a device with a sub-page block size, write a known pattern with O_DIRECT, mmap the same range, store to it, msync() and fsync(), then read it back with O_DIRECT. A reproducer is available at [1]. [1] https://gist.github.com/tzussman/18ab05cba4b3fdc79cce0a69d1fd05b4 Fixes: 925c86a19bac ("fs: add CONFIG_BUFFER_HEAD") Reported-by: Sashiko Link: https://sashiko.dev/#/patchset/20260730-blk-dontcache-v7-0-3e8e685006= 8d%40columbia.edu?part=3D5 Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Signed-off-by: Tal Zussman --- block/fops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/fops.c b/block/fops.c index 2ce7c6c4714e..c57784773fe1 100644 --- a/block/fops.c +++ b/block/fops.c @@ -560,7 +560,7 @@ static int blkdev_writepages(struct address_space *mapp= ing, } =20 const struct address_space_operations def_blk_aops =3D { - .dirty_folio =3D filemap_dirty_folio, + .dirty_folio =3D iomap_dirty_folio, .release_folio =3D iomap_release_folio, .invalidate_folio =3D iomap_invalidate_folio, .read_folio =3D blkdev_read_folio, --=20 2.39.5 From nobody Fri Sep 25 17:49:11 2026 Received: from mx0a-00364e01.pphosted.com (mx0a-00364e01.pphosted.com [148.163.135.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8ACD3D16E4 for ; Wed, 9 Sep 2026 22:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991235; cv=none; b=FAQz3LTIBRH41yDno+9yW/kCpyRjEVP05L+M3S9oiydmI4bvNyAVaKVDMq7MHlTW5R50nA67JiT57q6WwL+TwLbr3XamwOP/s2gKYHOPysqEr2s5NErSUNAtOgtrKTFY597XFLBfftGFbPwb9D/VyRVMovrnN5TglEKJgWaXSRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991235; c=relaxed/simple; bh=O4XevJ8HWjAvUQlUza+/KsywVjvdxM8otqyAjEW2gkk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kS/bDy6VhZWt/F0Ucy7kSoxOP73pkekHf4oR8at2qrKOirMnQL2U9LieQAB1VMjpa7ebtEHp+brX4nwENOPN8NEioAbWRZvEH/nnu1VA9Vbvvuh6j31InxAoL6F3EgBq5IjBoVKydlRTEVQgldofLYFcIaMjAeTWV8HMwOFg4oU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu; spf=pass smtp.mailfrom=columbia.edu; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=GEV4F/Rx; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=x6ZXkQGF; arc=none smtp.client-ip=148.163.135.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=columbia.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="GEV4F/Rx"; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="x6ZXkQGF" Received: from pps.filterd (m0499199.ppops.net [127.0.0.1]) by mx0a-00364e01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 689KYgtb873576 for ; Wed, 9 Sep 2026 18:00:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pps01; bh=OHeu hw4L3n9jZDkIAzrhQrQraRuBwX+0vErB9kq+zus=; b=GEV4F/RxCUljoIaRfCF3 Xo6pHQvbs3ZQKHsDfnOqqwJlEPu6s6eQD115+hIZGlijejz6oIK7d43dqw3Rol40 hzrfCq27HTFri+iZleBpcR6f5R9kngYPzYI90z9WtJkmZBJDxi+K/Oo1BZGON0nf JMyrmw7gaMTC7QI7v0O3HnDGJOYmzoGxct+fMsCJd1oimc5Xv0WVQKmnB2s3sKVj Qd9KlAXBzj4f/GKimXRRw7kviRq/3DWKK/PiXK6Ze+ZiGjWpF7QrSADE9M7y/Bzn 2MK8+EA449zVwGZl0rgCvU3pkw4/J0XEXJzjHmZ4DkCkCWQkIO5FDGRXBtm+EoNQ dQ== Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by mx0a-00364e01.pphosted.com (PPS) with ESMTPS id 4gkcyb1uqr-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 09 Sep 2026 18:00:24 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-9308eafb465so760789285a.2 for ; Wed, 09 Sep 2026 15:00:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; s=lionmail; t=1788991224; x=1789596024; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=OHeuhw4L3n9jZDkIAzrhQrQraRuBwX+0vErB9kq+zus=; b=x6ZXkQGF0+HvhbtGsnIM0yF8R3487jKyXQJeca/XXsoCZkbehCCAO3DEfVpuObbxgI /ktlreN0r3gLHJwIoywFoUaOs8/F2ej1DAyNJrBtIXu9k8jbyACrs7yUO0nvPbRBdLTO Cipnesx1/EpvkUGCVnmNV9M2QWTlpxSPU1M6nfYAYVq0EOoEjCEl/zYE6mmweQS5z2Uj hQv91YqA6jYSHqzFipGPc3YzkqOie3L90ZH7THYAxGOrXTRJAQUMR4esid5PCXW69aG9 6EoAX2snNLCkF6wz97uCpzT/56wWZIxclKnJjY5FDy61lzHgftoBNytrAppKYcJTG9ho zEgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788991224; x=1789596024; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=OHeuhw4L3n9jZDkIAzrhQrQraRuBwX+0vErB9kq+zus=; b=LqSkYF94Wybil1TUPotTNv5RDqbq96TRj2JH1/FTKc8L9mRN3+hIvAJ7Nm5bx95HB0 Kcm9EIgTtj3YXq8bwH0HvrYEHu2QYqBOWwmy2S+NpQnaOjuOkuci9XVqT/GyLlY3dMQ3 d/72HqI1lnWu3N+BOR/art7ZDcFlMlocnqsWFkIrTWW1Zp13snXpNu6ZllGbwMyMh1mo TRxeEqshm3Kq2MCb9wcmCSAferBGk7X6IQBK+tgZ9h6uObwzJWjGqCUHIh17/JKJYkBx wa/WlZmmf3BN5txDBZ9aAgItLq79USlO0JeWLtvaEdIPo2+kdOKV/azJLgAquTGgCTb3 ONaw== X-Forwarded-Encrypted: i=1; AKwUvBzXZEC3r9j6h3TdwF3M2eEefWuBk4yB8FN7pAb576dI7g0O6Q9Rnvovat0K0+eo8aVJDnTlYF1PuGxrG1I=@vger.kernel.org X-Gm-Message-State: AFuF++kMWIm1f8BwHzDJBhv+x90YRTrdmIIz7Se5r7+vIiPZglNQTxaG H0fSJsOswXvacR4IlqT98Du/jaBCNXPk/f6QTVyZgN3P5p6FKB3f03MpRSW1adrkib52GQPxaW3 6+GDBiQoUqaMgVNvjw2/YmblI4zwzX5nBFNHRN9oOUVlhTc1gSkQ7Uoe6jEcKPQ== X-Gm-Gg: AYBFou1ZhvEFcS5ko7EZE5t1pw8CeebWTVOjTmuo6MrTx1O8zjzFshXx7Slmgo9AFAk zxig055LLOhaYC7kPbT9gRhTdjefcxli3kI9s4VLedxxH6mHPzn13d82dX+clp7nzbEWP6gDQuL PWQWBCR8bfbNbJRo32aQ4jI3AhFhan6JB2X1PycPkSGalps/nXypGXs9njuW7odCyXDaKKXzX68 CkcNU4OpWb/wnXkcy7VPxHMFG/5eadNwevam93IiRvciKpoCI323GsH1UqFBl45RDOSEQHwV+K1 3+yMBVmnFegSjY3rmb/Cv5uHwkaTDPHQuaazw3WRR8TjfyXmn/zmlIrBFGeyXRvvYPdJ0rqRpVb Gq/d3W0swwZs2cRDjKtC9YnTF8j6VNyyz2LQGPMyFfiotVA8b X-Received: by 2002:a05:620a:4151:b0:932:ddff:1241 with SMTP id af79cd13be357-93980425ab9mr4372452785a.26.1788991219667; Wed, 09 Sep 2026 15:00:19 -0700 (PDT) X-Received: by 2002:a05:620a:4151:b0:932:ddff:1241 with SMTP id af79cd13be357-93980425ab9mr4372408385a.26.1788991217103; Wed, 09 Sep 2026 15:00:17 -0700 (PDT) Received: from [127.0.1.1] (nat-128-59-176-193.net.columbia.edu. [128.59.176.193]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9397fbe31c6sm1535326985a.46.2026.09.09.15.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2026 15:00:01 -0700 (PDT) From: Tal Zussman Date: Wed, 09 Sep 2026 17:59:40 -0400 Subject: [PATCH v3 2/7] block: take i_rwsem for the direct I/O write fallback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-blkdev-fixes-v3-2-1a5222c6e8ad@columbia.edu> References: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> In-Reply-To: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> To: Jens Axboe , Christoph Hellwig , Johannes Thumshirn , Luis Chamberlain , Hannes Reinecke , "Matthew Wilcox (Oracle)" , John Garry , Christian Brauner , "Darrick J. Wong" , Keith Busch , "Martin K. Petersen" Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Sashiko , Tal Zussman X-Mailer: b4 0.17-dev-db0b7 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788991197; l=4703; i=tz2294@columbia.edu; s=20250528; h=from:subject:message-id; bh=O4XevJ8HWjAvUQlUza+/KsywVjvdxM8otqyAjEW2gkk=; b=L6fykDJbi56xVjU4w3porinRK7hzSl8V57Ps0HUow4zw7jLIDcMxCHMwGd4yyLJn9x7oyz/uo Tx5+x0k6mJtBVJYp+Y3rj9GOqhBK8a9MleNHC3owCSKlSVxLb+yR/Hz X-Developer-Key: i=tz2294@columbia.edu; a=ed25519; pk=BIj5KdACscEOyAC0oIkeZqLB3L94fzBnDccEooxeM5Y= X-Proofpoint-Spam-Info: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfX2qd84a0z9cPP 4zc9HzqBR+IFPkLJNsf1zRa1UtnoFls4r1CCXxlINjwZBiG/tNFrECaVzBEoGYZY2j765pZHa4q nFnjhvOKdw1SKOdj6Fvpx9Ln0rJY0dkVHkbokRA5R3fMLtdMoM+J X-Proofpoint-ORIG-GUID: NYOzKhnWHgIaVhs40kiOqXnRJ3JdgS_w X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfXxIANV5HyHLaZ EiYEKlXW2aNu98yadhm2rIAQavorHdpdVbIobNJvEMbAmgsmyUn3CLWVGfM1m6IBf4jCnEV4We5 pMOXvjdQykfY8wD5sopnX6ZttDW6nb9qNecBfJrDC/Bq4M0Sxaj0OVz+TipxdCNk+l+K6udOTi2 BojxcarkS56v5Lbs7bPSvSfLgcuQKTPTEXtEOfefDM2Us2Ft8zElWXA2oggb3+xnJEPIaIowas+ qLQiQKTWbcdUEuvSroE9IqPLQ9ILWwUkZvckCpBr5YXg3uqtOwaph92wvALGRPR+Rtcu4aS0aLs cznUe2lmLgd4qRglrFZRuATo7DLuWI5bGe5Gg5klssXZlj6vuDLNi/4PcRDhZkzub9PQQh2uiYd UbLOfMDxn5O07c9RisMexIluDZZlHAdd397fpxx5tLOjgUojLvPY/V5XYQJoueufAWCdJ7NViOJ ffoMfy1QqtbfBTL72Sw== X-Proofpoint-GUID: NYOzKhnWHgIaVhs40kiOqXnRJ3JdgS_w X-Authority-Analysis: v=2.4 cv=Nq1E4MdJ c=1 sm=1 tr=0 ts=6aa1d6f8 cx=c_pps a=qKBjSQ1v91RyAK45QCPf5w==:117 a=fJxgZNdXt3opHMdyAp+FXA==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=x7bEGLp0ZPQA:10 a=A0y_DWxS2BwA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Da8U98TiO7q1upZEImrf:22 a=G--0XuH5328wxK7v7Suf:22 a=NEAV23lmAAAA:8 a=c92rfblmAAAA:8 a=VwQbUJbxAAAA:8 a=HaKTZzbUtGO3MgJEFeMA:9 a=QEXdDO2ut3YA:10 a=NFOGd7dJGGMPyQGDc5-O:22 a=GvGzcOZaWPEFPQC_NcjD:22 X-Proofpoint-Virus-Version: vendor=nai engine=6900 definitions=11900 signatures=596817 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 lowpriorityscore=10 impostorscore=10 spamscore=0 phishscore=0 bulkscore=10 priorityscore=1501 suspectscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609090247 Commit c0e473a0d226 ("block: fix race between set_blocksize and read paths") closed a race between set_blocksize() and block device I/O: with large sector size support, set_blocksize() can change i_blkbits and the mapping's minimum folio order while a concurrent reader still holds a folio of the old, smaller order, leading to crashes. In particular, it made blkdev_write_iter() wrap buffered writes in inode_lock_shared(). However, the direct I/O fallback path was missed in that conversion. blkdev_write_iter() passes blkdev_buffered_write() as an argument to direct_write_fallback() with no lock held. A direct write that completes only partially then finishes as a buffered write with no protection. This can cause a BUG by racing partial direct writes against ioctl(BLKBSZSET). Writer threads issue O_DIRECT pwritev() with a two-segment iovec whose second segment is an unreadable PROT_NONE mapping. The direct path then writes the first segment, fails to pin the second, and returns short, entering the fallback. A second thread keeps toggling the second segment's protection so that some fallbacks get past fault_in_iov_iter_readable() and reach the page cache, a third thread populates the page cache with folios of the current block size via pread() and readahead(), and a fourth thread toggles the block size between 512 bytes and 64K with BLKBSZSET. The minimum folio order only moves with block sizes above PAGE_SIZE, i.e. with CONFIG_TRANSPARENT_HUGEPAGE raising BLK_MAX_BLOCK_SIZE to 64K. On a CONFIG_DEBUG_VM kernel this yields the following BUG: page dumped because: VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_fol= io_order(mapping)) kernel BUG at mm/filemap.c:858! Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI RIP: 0010:__filemap_add_folio+0x860/0x8d0 Call Trace: filemap_add_folio+0xc9/0x1f0 __filemap_get_folio_mpol+0x240/0x660 iomap_write_begin+0xa87/0xd70 iomap_file_buffered_write+0x304/0x6a0 blkdev_write_iter+0x255/0x510 do_iter_readv_writev+0x23d/0x3c0 vfs_writev+0x211/0x7d0 do_pwritev+0x121/0x190 do_syscall_64+0x121/0x630 entry_SYSCALL_64_after_hwframe+0x77/0x7f The same workload also trips WARN_ON_ONCE(pos >=3D folio_pos(folio) + fsize) in iomap_trim_folio_range(). Fix this by calling blkdev_buffered_write() in the fallback path under inode_lock_shared(), matching the plain buffered-write branch. With the fix the same workload runs clean. A short IOCB_NOWAIT direct write reaches the same fallback. Taking i_rwsem there can now block behind set_blocksize(), and the fallback already blocks on writeback of the data it copied in direct_write_fallback(). blkdev_write_iter() already rejects a purely buffered IOCB_NOWAIT write with -EOPNOTSUPP, so do not enter the fallback for IOCB_NOWAIT at all: return the bytes the direct path already wrote, or -EAGAIN if none, and let the caller retry. The reproducer used was written by an LLM, and is available at [1]. [1] https://gist.github.com/tzussman/69d06bc57d42a42989eb038b1b5aeb74 Fixes: 3c20917120ce ("block/bdev: enable large folio support for large logi= cal block sizes") Reported-by: Sashiko Link: https://sashiko.dev/#/patchset/20260730-blk-dontcache-v7-0-3e8e685006= 8d%40columbia.edu?part=3D5 Assisted-by: Claude:claude-fable-5 Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Tal Zussman Tested-by: Shin'ichiro Kawasaki --- block/fops.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/block/fops.c b/block/fops.c index c57784773fe1..d5f569333f46 100644 --- a/block/fops.c +++ b/block/fops.c @@ -765,9 +765,26 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, s= truct iov_iter *from) =20 if (iocb->ki_flags & IOCB_DIRECT) { ret =3D blkdev_direct_write(iocb, from); - if (ret >=3D 0 && iov_iter_count(from)) - ret =3D direct_write_fallback(iocb, from, ret, - blkdev_buffered_write(iocb, from)); + if (ret >=3D 0 && iov_iter_count(from)) { + if (iocb->ki_flags & IOCB_NOWAIT) { + /* + * The buffered fallback blocks on i_rwsem and + * on writeback of the data it copied: return + * the short direct write instead and let the + * caller retry. + */ + if (!ret) + ret =3D -EAGAIN; + } else { + ssize_t ret2; + + inode_lock_shared(bd_inode); + ret2 =3D blkdev_buffered_write(iocb, from); + inode_unlock_shared(bd_inode); + ret =3D direct_write_fallback(iocb, from, ret, + ret2); + } + } } else { /* * Take i_rwsem and invalidate_lock to avoid racing with --=20 2.39.5 From nobody Fri Sep 25 17:49:11 2026 Received: from mx0a-00364e01.pphosted.com (mx0a-00364e01.pphosted.com [148.163.135.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CB284195D0 for ; Wed, 9 Sep 2026 22:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991242; cv=none; b=C9091rCONeTa7tCMiX4qPfpi0NxWgMPlhgynnVv8V45oisOE+aV7xQ/tRqkDK6htjY5X1cGD7rs4z+injRFSJsm5xQfkI3ZsZHpQd8qkYyPvoOgASLYpjUmhjgXFZUqvjGEq4404DLjCx7oTCHK8AB0yfWBHnFxx8YC8/8XdNZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991242; c=relaxed/simple; bh=1/t2xY5/Mc66wbO/sq4F65kT1qvvPynaI0dLYwruBvM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O6abHVjf+HCoaWAa186AFHZOEIWm3Rn/2FUdG1XudNV0o5IcUM0qE+FBWa1AZJeCldGTHZ6gPxyXyWDItAqe63mLL6GH5fm0cMqRLj5cqXqYccucdrLcVri0+C+NhQmB2xgxYF4YOKukuHNgWZWmacHU/olOXozuU1WZEo4ShC0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu; spf=pass smtp.mailfrom=columbia.edu; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=ZxnBn1jP; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=qLzXZ5Qf; arc=none smtp.client-ip=148.163.135.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=columbia.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="ZxnBn1jP"; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="qLzXZ5Qf" Received: from pps.filterd (m0167071.ppops.net [127.0.0.1]) by mx0a-00364e01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 689KZ0ks2241465 for ; Wed, 9 Sep 2026 18:00:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pps01; bh=VT8b 3XXMl8Tl4w2lotxN8pWIW4xBLLg9GmZ5x1w6/Oc=; b=ZxnBn1jPWTaFthTbfbvq MyDMY0nNONqwkr0G6NO2lcT+I3oen55ll68re5gVnf1LfjQo3pUoD+OKMV11iN7u YwYbYxWVcqyyp3T9yn6nSZfZjFOTZckhZmNBrhSUrGYRYPd/S4eRNfcG3S7L6V1D KKPn2e2kxi357H/mjwuG8hGENDqXGpHvkiuZpsxOQ+nd2fGIdzNj3ghURXnmNxNs La/07RCvk/lJc3afKv3Cj5jUB3LMZCHiz3KGicxbTrL2JBDPqn0WtqQIwGTl/STY MixI5lMHpfdIM6gJnNSgka11klJ9VpIn67wkUVgT0nZoajR0NDFNLgmPro4mzhgw 6g== Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by mx0a-00364e01.pphosted.com (PPS) with ESMTPS id 4gkcxyj1s8-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 09 Sep 2026 18:00:30 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-9399b66e0e7so806766685a.1 for ; Wed, 09 Sep 2026 15:00:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; s=lionmail; t=1788991229; x=1789596029; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VT8b3XXMl8Tl4w2lotxN8pWIW4xBLLg9GmZ5x1w6/Oc=; b=qLzXZ5Qfgab4OrfCBL3NjUjM1GMBIfmmr8oz+vvcQ2CGgaNb2KknWOT35PqZKznWa+ 35TpVILZ1qyJGbnGAy3lzw2XxPhRQ5GsVD0Op5uZcjmPhHv9TkuOVTBHisC2s4QOjB+4 AFsPgk2AoEQKeP+D+6WCcxC/pGSmBa4j+07+EmeMUwYMrE242A9yABZEIzyOkJyED093 XB+2jW56aqleprRSnURzvHEt6oaxLI8xKSRCO1bA2Ex9fLGrgViu8pP3t06gcVxg9iwa BWQAAlm9YRZVYvGQrRT5QJFpH/W/glF0vDNnKTkqhisTnmFeM+18vxwsyYVumPmumnnE r0xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788991229; x=1789596029; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=VT8b3XXMl8Tl4w2lotxN8pWIW4xBLLg9GmZ5x1w6/Oc=; b=bRH18jTaFFsMK0JmLp734s7YviZ+tEY0tS4pT7mhnzCu9Jncv4rzM118T4fCBPkzYU B1Opexx43VO5I8dsHjTEGwa2yx9R5fA5hmPlDyMRyJl6x1lvepRYDFrkz3LRUX4Tel/y sx5ZqXAS5/VJNKAwJ/z2PlZSBq02nD9HlffNC/Ou/L7ycAdFFF/DWDuxxbWEXpeO0w+c LGTYzBhxRuyj3CibAvRUAsHJ92b85j1fdfRAdiyyfCp2RAyJtCXgAALz+fOp4+SZR2bl wqH85C5R0MbKa1hBvPu1TM9LYwQY70GVIZ4rSrxX0jNQz5EhbZj5AFvds50WfM72amG1 zVHg== X-Forwarded-Encrypted: i=1; AKwUvBwlOiOUHAD/307DibHCLkG+KL3pPa8/yZPKcoM1EN02iiJT0XDStfld4CabH+u9+1LYBKQfmJ+V4eFko+Y=@vger.kernel.org X-Gm-Message-State: AFuF++ncp49cAtv2Cf3lvo+krAGZ+avL9uL4Pz05Hl+4qjl/SqTLxASf OqfzNNFbiCdcKRxxglKqY8W5wUzXhLroN6yn47lC1PpUSbfcQ757Hju+wcGgdsyiYm4W7MIbRDY 2UkA2rkikdubnR1nVGcy65GFl4OCH7TrFRRUECNncMeUQHp05+m06La//K1E2SOCxoWPThMY7 X-Gm-Gg: AYBFou0PVEKwIiUFdkGnU96xUj5Q6HGL76l4Ztrsei1BZl1wCby8RELqKh08x3NJFIw whc1fI8dCSPL/sJVnVYFzncziIEFdYSD6OW0oAWImbr9YbBuOrtkn3HQSPOTNZl5ypva2gWdALn Xm/y0OxvDMSi2IeH00RwktIzdvSVBqtzCIJk0zbyZTWao+XwYKbtjAbeJ3QTQAihTg4O6+DJ0hU I21f4OMWiwmO29jmcN29xr2myOjEfX8SGCTcZVVV491JP9/XE36kpL5XaB4ZVoc31lYtBpR4DR3 7Z++dYhNEqZMVupQD0mavfMmXcU17hywhvUEij7AnTm6zJWvhI3+f2Gl6Rmyst5HXq7jv1+03pj +q/10Nn+xhyw01DLeL87dfxWmgIlA8JFijQf/HY5zagJ3jg4s X-Received: by 2002:a05:620a:f05:b0:936:315b:a5f4 with SMTP id af79cd13be357-939803118bcmr4267367785a.5.1788991227359; Wed, 09 Sep 2026 15:00:27 -0700 (PDT) X-Received: by 2002:a05:620a:f05:b0:936:315b:a5f4 with SMTP id af79cd13be357-939803118bcmr4267299785a.5.1788991224191; Wed, 09 Sep 2026 15:00:24 -0700 (PDT) Received: from [127.0.1.1] (nat-128-59-176-193.net.columbia.edu. [128.59.176.193]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9397fbe31c6sm1535326985a.46.2026.09.09.15.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2026 15:00:17 -0700 (PDT) From: Tal Zussman Date: Wed, 09 Sep 2026 17:59:41 -0400 Subject: [PATCH v3 3/7] block: take i_rwsem for the splice read path Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-blkdev-fixes-v3-3-1a5222c6e8ad@columbia.edu> References: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> In-Reply-To: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> To: Jens Axboe , Christoph Hellwig , Johannes Thumshirn , Luis Chamberlain , Hannes Reinecke , "Matthew Wilcox (Oracle)" , John Garry , Christian Brauner , "Darrick J. Wong" , Keith Busch , "Martin K. Petersen" Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Tal Zussman X-Mailer: b4 0.17-dev-db0b7 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788991197; l=2823; i=tz2294@columbia.edu; s=20250528; h=from:subject:message-id; bh=1/t2xY5/Mc66wbO/sq4F65kT1qvvPynaI0dLYwruBvM=; b=WP8Ldf8P1H8oQEK2mjLFXYLu33CPKzboymXkYr30/fCKh1X1Y0WllXFMtkKQ8/aKbfrpmh4lz JwrehgekqpiAg27ZCAj3VFWrYtv6bdW+y0tTsyoMgyB47Fl8/wCHNQY X-Developer-Key: i=tz2294@columbia.edu; a=ed25519; pk=BIj5KdACscEOyAC0oIkeZqLB3L94fzBnDccEooxeM5Y= X-Authority-Analysis: v=2.4 cv=brnZl0ai c=1 sm=1 tr=0 ts=6aa1d6fe cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=fJxgZNdXt3opHMdyAp+FXA==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=x7bEGLp0ZPQA:10 a=A0y_DWxS2BwA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Da8U98TiO7q1upZEImrf:22 a=79PYxaXUQd1wl-QFWJnA:22 a=VwQbUJbxAAAA:8 a=kXXCQoMOyz17bj_MZH4A:9 a=QEXdDO2ut3YA:10 a=PEH46H7Ffwr30OY-TuGO:22 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfX+uEaBnUMLyhy om4paD9wELkKr3/iswKLmygwHpJff02VDOw+vjQ9ZAXDs99Tq+q82IG+ywzXyWjf18hN+XOgHKC Eh2wJjMuVq+KF2ThO5w9hPfnTjSe23duT/HNKuxaytGpp41xgri6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfX/vrvuNBWasf1 Ly11jnIXRlyXbPTMh3pjr8/0jResW/vPey2KxpyA//fgQOYUxQhmjEY8xIKJrzajCOShAgGFC36 rF36xO78CRAIn6VYRrPpyMOszTMi2nfskR/P+VFurCoBhERazzgwJEUCBVxjNN+DCl6bS2mtLws Ghgin+QJVwp5D1PeNJZAAo0v071YkwtJ8A5TnxhgCIGT/J+IGUN9Ng7KjzdtXaJBSpH4G2ElWjT iAK7Tz2/VBJEJ/YcZwnk5vuKRkSk5IdA2la4iOaurJFga6KfMZka04MKUVt7NfgJSrZkZtEZh3D 3IeXT0FiINJe4hQ/nmi3imUh1odoLzIH4nmKl5cH/ESpS+foj+DxAJ+BS/0++NdqP4qLDaVdtkB 7W+Vsef97vlIlvmmimQ9jTO3DSJfhJrXz0A+WCsjpowo2NVI9+su6c1zsZgiLkpBYQM9ogLU/c5 vBZvI7gERNQ+sKKTo3w== X-Proofpoint-GUID: UPGHebrmIujqXJp7N9F_bLf-oPLJQAZ9 X-Proofpoint-ORIG-GUID: UPGHebrmIujqXJp7N9F_bLf-oPLJQAZ9 X-Proofpoint-Virus-Version: vendor=nai engine=6900 definitions=11900 signatures=596817 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 adultscore=0 suspectscore=0 impostorscore=10 malwarescore=0 phishscore=0 lowpriorityscore=10 bulkscore=10 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609090247 def_blk_fops wires ->splice_read directly to filemap_splice_read(), which allocates folios based on mapping_min_folio_order() without any lock against set_blocksize(). A splice from a block device can race set_blocksize() raising the minimum folio order and insert a folio that is too small for the mapping. blkdev_read_iter() wraps filemap_read() in inode_lock_shared() for this reason, but the splice path was missed. Splicing from a block device while toggling the block size between 512 bytes and 64K with BLKBSZSET hits this within seconds on a CONFIG_DEBUG_VM kernel: page dumped because: VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_fol= io_order(mapping)) kernel BUG at mm/filemap.c:858! Oops: invalid opcode: 0000 [#1] SMP NOPTI RIP: 0010:__filemap_add_folio+0x51c/0x570 Call Trace: filemap_add_folio+0x64/0x140 page_cache_ra_order+0x1dd/0x3d0 filemap_get_pages+0x153/0x760 filemap_splice_read+0x13f/0x300 splice_file_to_pipe+0xc0/0xd0 do_splice+0x6a8/0x890 __do_splice+0xb0/0x210 __x64_sys_splice+0x80/0x100 do_syscall_64+0x10e/0x520 entry_SYSCALL_64_after_hwframe+0x77/0x7f Take inode_lock_shared() around filemap_splice_read(), like the read path does. Fixes: 3c20917120ce ("block/bdev: enable large folio support for large logi= cal block sizes") Assisted-by: Claude:claude-fable-5 Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Tal Zussman Tested-by: Shin'ichiro Kawasaki --- block/fops.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/block/fops.c b/block/fops.c index d5f569333f46..a51814821100 100644 --- a/block/fops.c +++ b/block/fops.c @@ -855,6 +855,22 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, st= ruct iov_iter *to) return ret; } =20 +/* + * Take i_rwsem to avoid racing with set_blocksize changing i_blkbits/folio + * order and punching out the pagecache. + */ +static ssize_t blkdev_splice_read(struct file *in, loff_t *ppos, + struct pipe_inode_info *pipe, size_t len, unsigned int flags) +{ + struct inode *bd_inode =3D bdev_file_inode(in); + ssize_t ret; + + inode_lock_shared(bd_inode); + ret =3D filemap_splice_read(in, ppos, pipe, len, flags); + inode_unlock_shared(bd_inode); + return ret; +} + #define BLKDEV_FALLOC_FL_SUPPORTED \ (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \ FALLOC_FL_ZERO_RANGE | FALLOC_FL_WRITE_ZEROES) @@ -956,7 +972,7 @@ const struct file_operations def_blk_fops =3D { #ifdef CONFIG_COMPAT .compat_ioctl =3D compat_blkdev_ioctl, #endif - .splice_read =3D filemap_splice_read, + .splice_read =3D blkdev_splice_read, .splice_write =3D iter_file_splice_write, .fallocate =3D blkdev_fallocate, .uring_cmd =3D blkdev_uring_cmd, --=20 2.39.5 From nobody Fri Sep 25 17:49:11 2026 Received: from mx0a-00364e01.pphosted.com (mx0a-00364e01.pphosted.com [148.163.135.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 404B5439F9E for ; Wed, 9 Sep 2026 22:01:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991294; cv=none; b=jLnIASQr59OZPE1+u48/MTQcp4X2gkBHYrunwqropDJ171zvazuWaBy0QEPl+d+luHOUN9k+XZEqIfLeow24K7z405Q2wdV/ZsNEGolfNsDJhH1NbyGraGRdcfdTNU0jx0ySmcY9Hw5NgCs5KDcuYz1CZ6JigOVKVY5p2uXinng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991294; c=relaxed/simple; bh=omRobIYeubqYt1ShRwO+xJfwqyahvimqDH0UuCrRjvM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=heyMO0akc39NB7kpWkj2kG4xKJpi9mtP+7PwWbGVb00mRQHqYvJCbOfFUcNcMW4l/hW4AhXydAwvplQU6nYc3H3Rp7k3Cw+Cz9+dzY9+ZWiAG+ryR8yoEd1MTQf8LLGwo5sts5kFX8T6jLFfvr6mcXE8lhJ5DIOqGv05X7vJ9uw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu; spf=pass smtp.mailfrom=columbia.edu; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=JNZo3tnu; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=DjbW7m5I; arc=none smtp.client-ip=148.163.135.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=columbia.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="JNZo3tnu"; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="DjbW7m5I" Received: from pps.filterd (m0167069.ppops.net [127.0.0.1]) by mx0a-00364e01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 689KZFpJ3492670 for ; Wed, 9 Sep 2026 18:01:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pps01; bh=6i89 u0mptbr+Jh3PRt95XNfEgizrGGtLlz3J/in9MkY=; b=JNZo3tnuLOTjfuuFK6SN R9s3lhOUMKEA3JQ6yxj4QLoqkBPKNdx3+WhZgQMRAyWpFYePUVpg86cOMRBBLcJX kW4YnPUzaTHGiPzS3X3YwvXA4oFBVxBCPmLWwyNM1rnpDx2wGva4AQWesPWhyV3z R7O1nRkXXV5SyNZuxU9Q7Vhq8/QoxQ313bwzrA+RUn8pzt/qaxqDFOzu2F7yl/Wz VqxiWUPmJ/wJjz5xgx/BM3x24pt6TeZ6WVKSsUSN7w3LpoXuD4eNectHz0V5mGZN 3m9MAdRjQTMObbuFiQBXgwRksjXQhwZH1M/jAiMvWgeMbYNlr0VX6p/IbnLCMJfv Xw== Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by mx0a-00364e01.pphosted.com (PPS) with ESMTPS id 4gkcyfsree-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 09 Sep 2026 18:01:25 -0400 (EDT) Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-9396e0515dcso369476685a.1 for ; Wed, 09 Sep 2026 15:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; s=lionmail; t=1788991284; x=1789596084; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6i89u0mptbr+Jh3PRt95XNfEgizrGGtLlz3J/in9MkY=; b=DjbW7m5IfCegrl91FmGn2bhu8ZkSTu7y9yL6FBldiBIZdOO+iiUZfFcdycTxZT2mTL 5c4tk5PwHwX0e0nXdip7vmlUwA+ibq5L/FIjkRl5qb5IjYRMCo8dpgyvsCXaB4GT/jo0 /ge7ZdCB6eemr1IZCWFGZMuUW5KOLkHUiYh1acwKlPeqvgXmPC0bntPHrqSwlYz1b6SX f6XQzL1tfTqI3+ovzIZ6Sqw0mcnuQNcCrLZGx2GPphQyPNALDrln8ndWDwpMSitb1o3W /x9O+7/hnziT0sw+EhKMou8+h7iCblj1v2pVc3Si+pCR1+aj1r3AIHMvBmMWf5Ixptpl jiPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788991284; x=1789596084; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6i89u0mptbr+Jh3PRt95XNfEgizrGGtLlz3J/in9MkY=; b=GqwtHz0w17WU4LKZU1/bt6fvb1E909GKkzpRevSiCQU6i9KgJVQv9IGipNRLXqmEgf v/HcUhPQYdC6pvbSKtcwtLzsbcCaN026JOBU5jfAra7PVv/vbuNfXyQH5C5Uu6L3yx2J MNCd66qC+1aw86qzT2Rv/8NsXUB/iKwHDcqVwUKivllk5bg7t965pfNhju59k0cE30Rq mZSuZY9Qlbwm0y7rP+B5+Qr63z7ahFA6Aa1x9DM2FjkoaWJA7eCfNhEi3CEHNmuWunys eVqYicz4VTzaUPjqSDlZ2OTMYiMcUDz2ufyhcQgT9e9cxkLEAI2y/IGch+w8GTqKeMMe J22w== X-Forwarded-Encrypted: i=1; AKwUvBxM7OQ+OPVDA8leVVUFbFapseGjXIdPbxfSt4ZOh/h8V4H4LqnE53o5q22Pde328jVfnycfBNgzpo8rI8Y=@vger.kernel.org X-Gm-Message-State: AFuF++kDzyvgReRK/9yQ4XMCOTR0zHWFfsJfJb9OD5SvdRK3BnZFNRlB gQOFjPTdkYgNcBL+CplvzZYMPti39EKXDXoiIUc6NCLyQLg0pLXrwRb5mwbDOqVh1P6lIbkbANX UGSVoT0iONIAxE+V5Z+hE871iaWqh4bapUhXZ8EV6FbxX5k4+s0fqPRobJdqlHg== X-Gm-Gg: AYBFou3XVGxZU6BbIbaPBej348zgQ+aovxTOCf28uct74T5jCMFUuEDeisiNU8V1RKk N+0FV4RjRoUp4ZeO5sT5JxtKL5Vs6ShemLbXYV/UH17ESV5VxkwH9Gvq/WAc2DpeGqAlkFnz5Z4 hWyHSNDJtBf5zzstH30xjNWYndK2eODw+YQccM6p1jkETw56JrO9n+AZp2gLmk9SSeyg+qL1sio PuPV8TxHop3lMLqqIDod0jGIELwKCi7PLHlpRC15HBy+Ii+tEOzZfWIScKeLcGhPB+LlaJUWlcY 2z5LZ5K9qv7iIeV55jvDxK+uMsJIBq8cOKEkmo4KFlgEQs19KBXy1MP61zMRjO6xRtDdx+rp6I6 p9bRhpB0DN0uhXCXQ8xhHofbTPgmku3z3LmMFEBhYteApV0bD X-Received: by 2002:a05:620a:4551:b0:939:6de9:208b with SMTP id af79cd13be357-9398058371fmr4235670185a.48.1788991264762; Wed, 09 Sep 2026 15:01:04 -0700 (PDT) X-Received: by 2002:a05:620a:4551:b0:939:6de9:208b with SMTP id af79cd13be357-9398058371fmr4235341485a.48.1788991249064; Wed, 09 Sep 2026 15:00:49 -0700 (PDT) Received: from [127.0.1.1] (nat-128-59-176-193.net.columbia.edu. [128.59.176.193]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9397fbe31c6sm1535326985a.46.2026.09.09.15.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2026 15:00:27 -0700 (PDT) From: Tal Zussman Date: Wed, 09 Sep 2026 17:59:42 -0400 Subject: [PATCH v3 4/7] block: honor IOCB_NOWAIT in the block device buffered read path Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-blkdev-fixes-v3-4-1a5222c6e8ad@columbia.edu> References: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> In-Reply-To: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> To: Jens Axboe , Christoph Hellwig , Johannes Thumshirn , Luis Chamberlain , Hannes Reinecke , "Matthew Wilcox (Oracle)" , John Garry , Christian Brauner , "Darrick J. Wong" , Keith Busch , "Martin K. Petersen" Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Sashiko , Tal Zussman X-Mailer: b4 0.17-dev-db0b7 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788991197; l=1869; i=tz2294@columbia.edu; s=20250528; h=from:subject:message-id; bh=omRobIYeubqYt1ShRwO+xJfwqyahvimqDH0UuCrRjvM=; b=9Nl/nBXz4hvk3iMfr00Au+HApKUeQvDeZ6iBBKqO9QJ17SeC8ILbrAXylK0i39U56AAhdqk1p C3uCDh4Mov0C6ijIxOEQBV2lv/lFui4DUz9SbYFWmHNXQ1PAMkEJOfC X-Developer-Key: i=tz2294@columbia.edu; a=ed25519; pk=BIj5KdACscEOyAC0oIkeZqLB3L94fzBnDccEooxeM5Y= X-Authority-Analysis: v=2.4 cv=S/9MU4sP c=1 sm=1 tr=0 ts=6aa1d735 cx=c_pps a=50t2pK5VMbmlHzFWWp8p/g==:117 a=fJxgZNdXt3opHMdyAp+FXA==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=x7bEGLp0ZPQA:10 a=A0y_DWxS2BwA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Da8U98TiO7q1upZEImrf:22 a=JR4YdQiviy7OQf72WyZ1:22 a=c92rfblmAAAA:8 a=VwQbUJbxAAAA:8 a=s8mzj7eOnaliLhoSWqYA:9 a=QEXdDO2ut3YA:10 a=IoWCM6iH3mJn3m4BftBB:22 a=GvGzcOZaWPEFPQC_NcjD:22 X-Proofpoint-GUID: imf63zSO2aPX3amoCYb6OwuL24qwpVlx X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfX+mNBKnMVliOH UoNUdgC04jQLSA8jwDm615F9AASm2ucTEQJ+rc8N9SHRHwadCaot3YVIhXnGdYWdO+9jerkImO/ IVcmSwRXKIRHReMOta+CmNn8/k8ihnnV5ZCMdsSuhXv8sdro8qikPcjBQtn4JA8qQIrtyM8JVFe B3A8dPp81p4g7TSH8LfmSmz+BaiCT13pftnL0ZzMPDo9Gy0IamxZ0nVERaH90zoKuvPIeDtdEpC /icv18tGicCSJ6qN6Xb+VwFFw3xYHHYLeIkw07y49EOmcresOlq63NEC7xGnUC5NV85RdwY2cXU qNzlD0u9Y35cjCEU/RwI1aF3xz4lLMjP/XGeT5+IOnI/zCyFtLXvw0SMCGS+GIt/KxrzPRHhyfO DobJ2jzSY+FyrzWzQvWGx2AN6KbgusxX2HbOsnECwIbVWBYSOL7s/qzGDPy9TT9DPxXH5S6zm/F h0q3MjgPhuARmSBrN0g== X-Proofpoint-Spam-Info: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfX3vxWvCj/UJbk pMFjDq+lLP3vp7VY2lFAvCgf3fXvgK8/Sq9r8f7BLTpUvtGtR7LMA66nHoEh1nlMxj5rXcU6cSl vYpprDgHlHgb7U6rnnCHvP/7eoutn92Vr6QMwlqw6dFECToma8ph X-Proofpoint-ORIG-GUID: imf63zSO2aPX3amoCYb6OwuL24qwpVlx X-Proofpoint-Virus-Version: vendor=nai engine=6900 definitions=11900 signatures=596817 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 lowpriorityscore=10 bulkscore=10 spamscore=0 phishscore=0 adultscore=0 clxscore=1015 impostorscore=10 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609090247 blkdev_read_iter() takes inode_lock_shared() unconditionally around filemap_read(). Unlike blkdev_write_iter(), it does not reject IOCB_NOWAIT for buffered I/O, so a non-blocking read, or the buffered tail of a short IOCB_NOWAIT direct read, blocks behind set_blocksize() holding i_rwsem across sync_blockdev(). A preadv2(RWF_NOWAIT) issued while another thread changes the block size with a dirty page cache blocks for as long as sync_blockdev() takes, 4 to 6 seconds on a scsi_debug device with delay=3D5. Use inode_trylock_shared() for IOCB_NOWAIT and return the bytes the direct path already read, or -EAGAIN if none, when the lock is contended, preserving NOWAIT semantics. Fixes: c0e473a0d226 ("block: fix race between set_blocksize and read paths") Reported-by: Sashiko Link: https://sashiko.dev/#/patchset/20260802-blkdev-fixes-v1-0-a82fc549fd7= 4%40columbia.edu?part=3D2 Assisted-by: Claude:claude-fable-5 Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Tal Zussman --- block/fops.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/block/fops.c b/block/fops.c index a51814821100..a3a709697b40 100644 --- a/block/fops.c +++ b/block/fops.c @@ -845,7 +845,15 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, st= ruct iov_iter *to) * Take i_rwsem and invalidate_lock to avoid racing with set_blocksize * changing i_blkbits/folio order and punching out the pagecache. */ - inode_lock_shared(bd_inode); + if (iocb->ki_flags & IOCB_NOWAIT) { + if (!inode_trylock_shared(bd_inode)) { + if (!ret) + ret =3D -EAGAIN; + goto reexpand; + } + } else { + inode_lock_shared(bd_inode); + } ret =3D filemap_read(iocb, to, ret); inode_unlock_shared(bd_inode); =20 --=20 2.39.5 From nobody Fri Sep 25 17:49:11 2026 Received: from mx0a-00364e01.pphosted.com (mx0a-00364e01.pphosted.com [148.163.135.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 616ED4AB1D9 for ; Wed, 9 Sep 2026 22:05:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991523; cv=none; b=dwNOGQRgdySUPLAK4yySOokwXcFTVykgLkQ2tlnwZAKU7ABJUd2A+XLDa4Q3Nx3p03vbSJHW2lr2dLvKaND4enwZGRrV7Z6Knv7jY06Jrf6Mn8BUuslnyXPinx6LKJu5DvCZLkSYKVNw+WZH4byfZBJWD5oyJjOeX4hdhQYPFH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991523; c=relaxed/simple; bh=Szkl0zQw5FKjt3p7vuSF/DGwtXkOrx336KERuXYlUgU=; h=Message-ID:In-Reply-To:References:From:Subject:To:Cc:Date: MIME-Version:Content-Type; b=APZNMfmtdEMC0Q5Xu1dKjQWxkjVqUYz3ubcZSbUZVBuNaJqZEaAFlv/AfDhUiIIqzcmmmGY9OxZIf3JklUdEJo0RWsNIOtkkd+KwXZri+LRs1Pv099Z1lHB90ua+TQ2p/qw43dr0lH0+pgWhSFsBtmB15jbx96vpjjyzOVmVjaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu; spf=pass smtp.mailfrom=columbia.edu; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=nYFKGuQJ; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=x+s48mdw; arc=none smtp.client-ip=148.163.135.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=columbia.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="nYFKGuQJ"; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="x+s48mdw" Received: from pps.filterd (m0167069.ppops.net [127.0.0.1]) by mx0a-00364e01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 689KYxbB3492224 for ; Wed, 9 Sep 2026 18:05:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pps01; bh=TThN 0a5nP0zzwXQLrTldgh7wXE1up6HbOywS+CznoLM=; b=nYFKGuQJ9zkkW/LzkJK/ 0NDdRd5p2XnarQ8GF3bDAUQFqhJjYt4oxBiwYfHuoSi+JmDgR+b1C3quOIP1eGdy 0tnqoC04YxoM5lgxxkD7lRgSc9LJ+nTuHd+c1L7kNGF+R5UZiQNKtLJpPowXZQql qs8BlEFaXAW53llBZ4DNt0Zd9JE/GouJCfOSYvfohHiQUJzyG2M4qV7XPmQnzvrf GCcL50p+iHN0Cf+XEdNpHpoKrSv/iXbeuTTLbHMKDZY3Qiz4ID0IOcO5Ew4Nmn66 9/3xkpiee0ABogYx1K0p9zM7iF57moAL3lmgYojEugU705T8jlj7wwSZdIe1e5+E pQ== Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by mx0a-00364e01.pphosted.com (PPS) with ESMTPS id 4gkcyfsshn-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 09 Sep 2026 18:05:20 -0400 (EDT) Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-8823e0226edso5234437b3.1 for ; Wed, 09 Sep 2026 15:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; s=lionmail; t=1788991519; x=1789596319; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:date:cc:to :subject:from:references:in-reply-to:message-id:from:to:cc:subject :date:message-id:reply-to:content-type; bh=TThN0a5nP0zzwXQLrTldgh7wXE1up6HbOywS+CznoLM=; b=x+s48mdw0Zxl3sbQR5jnLM4wYcr60n75oNLjKCMZEqpsKsh45FAA1pnbsw6rzi3O21 r/A8f0e1RQW8gyh2MME7VGudkq1wWYsY7J4QYcjX2uWNWjXW/GUiX1116uGDCV9UJXC6 Af9RKjH/msvqwkxyg/J0toxu6QPaTSRWb/qNuJ13uC1Poz4+ltWKK825SiPswnxmNGT1 wE0wNoItwukedDrN7HyPe61E+F6yQBcda9L5dFuD30iF4E80xcbT9iUQKS4OD9QeWtxR D6Ojg+/3wWhOhnK+2CTwcQ7ZCoZym/qHaKOYKDDCy4/VBpwST++av+rpKiG1mSuoEFJo ihNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788991519; x=1789596319; h=content-transfer-encoding:content-type:mime-version:date:cc:to :subject:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=TThN0a5nP0zzwXQLrTldgh7wXE1up6HbOywS+CznoLM=; b=ng/eIDP6SfxmxS4xe7swPqzTaTVEjPFdoEYWVBYT9o7HPSttnIlx5tVoj/8vTRSXZW k8t55+kbvRUToxawLk5wiD6u09yciZycerqkY9H5+2DCaMPuv/t+HeFJjcE9KvlgGTnA zwAGwsTHGDYZj5OU0X8MZ+y4remrxGHU8mwlMElTkPnFo4eN10dXm4yYd8RQBg3Mi5cQ NjvblkKhci8tg/VBy7NnFp77luHGbCHrBUn/CusUgwIGOwbo4LYMjjJfO05Fz4xPbm7D o6aAoVufwPV4ZZckRB7HfBpduEGN+IpQkBDSSmmc+I0N1Ddx48OaR0sTgHN3ojKhvrv2 Ujdw== X-Forwarded-Encrypted: i=1; AKwUvBzr+UxrzsJoEdfuPJaV3W1lDGXnbf/V4juKoAmbINj3Hci1qmsdaOtkcEv7Kgqo0iXbo0Ka7WaDeWhQayQ=@vger.kernel.org X-Gm-Message-State: AFuF++kh/8Jl9O6pHRrcEdUfnNxhYYT8Sy6zS6vtdpWXxrX+C55JPDSe ww7jvhA7EGXAN4gx3QyxEmqwutYZY/7CqwvJS3racf99OY4IerWkpyfrvj1aVBnjRvKxN3oghoF SwM8WWe5f5YG64ryMYEyg0xLhJ8fb/mLA/m/8qrV5DfDEINCY/pQpssD0KNI88Q== X-Gm-Gg: AYBFou1xwKWrccoeWCNHrgnVlZ0uKuPSiUaSOaU52YcZFT6PqoBl/8tnjSYfwy4Vtex ZCBshGvSRPnjK4TvjJuzmi77yud8/V8y5T6wHxWegKcSmhkGFhxEp0KD+0OwJguKBlegRYjRSr0 gsQijiwRBonL3wk/IVQSGPf6JISC05Ez27nVHSxdoBzzewcLNI/pDk1Hmrh0yT+qg/BjxHDZiGM 2BaIYQ8I2Ajm3pJDEHhJnfN3GxgjdYC1omKhZtPd12YAOqBARKSzYbT1neAzkPFioS3sIHSYdBY CDJEAgTJVhkhfY0evRnWYutw33QTydE8B8Kk5D54aaqkSx7lR0/ZYEm/rRzsZXe6bTehZIJvX7J GrV4xFslg98ayzhZ7hOEbOBF3m5VzP++ESC1wK0XvZZztQsbX X-Received: by 2002:a05:690e:1382:b0:667:e855:ecdb with SMTP id 956f58d0204a3-66fb58f806amr13201031d50.3.1788991519467; Wed, 09 Sep 2026 15:05:19 -0700 (PDT) X-Received: by 2002:a05:690e:1382:b0:667:e855:ecdb with SMTP id 956f58d0204a3-66fb58f806amr13200980d50.3.1788991518642; Wed, 09 Sep 2026 15:05:18 -0700 (PDT) Received: from [127.0.1.1] (nat-128-59-176-193.net.columbia.edu. [128.59.176.193]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-91040693f75sm154018806d6.35.2026.09.09.15.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2026 15:05:17 -0700 (PDT) Message-ID: <20260909-blkdev-fixes-v3-5-1a5222c6e8ad@columbia.edu> In-Reply-To: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> References: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> From: Tal Zussman Subject: [PATCH v3 5/7] block: fail atomic writes instead of falling back to buffered I/O To: Jens Axboe , Christoph Hellwig , Johannes Thumshirn , Luis Chamberlain , Hannes Reinecke , "Matthew Wilcox (Oracle)" , John Garry , Christian Brauner , "Darrick J. Wong" , Keith Busch , "Martin K. Petersen" Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Sashiko , Tal Zussman Date: Wed, 09 Sep 2026 18:05:14 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=S/9MU4sP c=1 sm=1 tr=0 ts=6aa1d820 cx=c_pps a=0mLRTIufkjop4KoA/9S1MA==:117 a=fJxgZNdXt3opHMdyAp+FXA==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=x7bEGLp0ZPQA:10 a=A0y_DWxS2BwA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Da8U98TiO7q1upZEImrf:22 a=JR4YdQiviy7OQf72WyZ1:22 a=c92rfblmAAAA:8 a=VwQbUJbxAAAA:8 a=yiLHSb9EnpU49bWIXwUA:9 a=QEXdDO2ut3YA:10 a=WgItmB6HBUc_1uVUp3mg:22 a=GvGzcOZaWPEFPQC_NcjD:22 X-Proofpoint-GUID: DrrViy7Nu7dzrvQViNIzN4KwMpr4aXE5 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfX1u5B8aqfQGOG dez+d4xqxX5qzOAC5x5VpXC+5O3qc2IzFd9H6BINM9uG/otkR8Ilmijklg53gXUIo9MiksXGST7 lMicb9dsQlhq5XOeovgnrg+fLsRrsQfhMG2cCyxIQZO6+AvMFLMp6u36WhymfIyL61zJ6oXkmLM d9Dp61lFKUVeIIWFtHIFG9Mujd8Rz8s8jy5PqWTcmZSflmfBU/uZXJEct6vgzn9/KY49/Ta+60y xL8DnF55NRGFWM7Eg0f6ttBOoAIaDnjdJwpNpNtwgg5Fbt+MasTiNJJI67EJMIiNiByxtgq6kmv IXcV34wihk82p8p2A9UYOR7VGuyG57Pu971S4nuDyIIuPwXcrF9ixVWK25m/8/icKF9IThvhCdv /IAuHqtfcC3AMPHeGkl68NcJrJhVtdfPNqQJdG0Uh5/FxTaeJQ5BHFHRDnKZsoJHoMoHAdENOio AMeNq6xRNOp/Hl+FoyQ== X-Proofpoint-Spam-Info: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfXwAGZBRAI3J87 XtaQ6Q/tdkJ5/f528JJ+VQG4JGPhmd7yuSj6hV1TvnS1LpusJ3tMStJCEcIikKizGjSGEH7aMpp GRUGu8D+pmt4aUgKbqKBfplFYu77GudAt9olgexXMwg021lF5yow X-Proofpoint-ORIG-GUID: DrrViy7Nu7dzrvQViNIzN4KwMpr4aXE5 X-Proofpoint-Virus-Version: vendor=nai engine=6900 definitions=11900 signatures=596817 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 lowpriorityscore=10 bulkscore=10 spamscore=0 phishscore=0 adultscore=0 clxscore=1015 impostorscore=10 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609090247 An IOCB_ATOMIC direct write to a block device can silently lose its torn-write guarantee in two ways: 1. blkdev_direct_write() turns an -EBUSY from page cache invalidation into a 0 return, so the whole write is retried through blkdev_buffered_write(), with no atomicity guarantee. 2. On a partial page pin, __blkdev_direct_IO_simple() and __blkdev_direct_IO_async() submit what was pinned with REQ_ATOMIC set and leave the rest to the buffered fallback. The second case can be triggered deterministically. A 16K pwritev2(RWF_ATOMIC) whose last page is PROT_NONE, on a scsi_debug device with atomic_wr=3D1, completes short with only three of the four pages written, violating RWF_ATOMIC semantics. Fail the I/O instead. Make bio_iov_iter_get_pages() release the pins and return -EINVAL when a REQ_ATOMIC bio doesn't cover the whole iterator, since an atomic write is submitted as a single bio and a short one would be torn. That covers iomap as well, where a partially unmapped buffer could trip the WARN_ON_ONCE() in iomap_dio_bio_iter_one(). The async block device path currently sets REQ_ATOMIC after pinning, so set it before. Skip the buffered fallback in blkdev_write_iter() for IOCB_ATOMIC, as it already does for IOCB_NOWAIT, so the -EBUSY case returns -EAGAIN and the caller retries, matching __iomap_dio_rw(). ext4 has the same fallback and only warns in it. For block devices both ways in can be detected before any I/O is submitted, so fail early instead. Fixes: caf336f81b3a ("block: Add fops atomic write support") Reported-by: Sashiko Link: https://sashiko.dev/#/patchset/20260802-blkdev-fixes-v1-0-a82fc549fd7= 4%40columbia.edu?part=3D2 Assisted-by: Claude:claude-fable-5 Signed-off-by: Tal Zussman --- block/bio.c | 29 ++++++++++++++++++++++------- block/fops.c | 10 +++++----- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/block/bio.c b/block/bio.c index 898b2f5ef8c8..63e266d861f1 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1284,6 +1284,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct io= v_iter *iter, unsigned mem_align_mask, unsigned len_align_mask) { iov_iter_extraction_t flags =3D 0; + int ret; =20 if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED))) return -EIO; @@ -1303,34 +1304,48 @@ int bio_iov_iter_get_pages(struct bio *bio, struct = iov_iter *iter, flags |=3D ITER_ALLOW_P2PDMA; =20 do { - ssize_t ret; + ssize_t len; =20 - ret =3D iov_iter_extract_bvecs(iter, bio->bi_io_vec, + len =3D iov_iter_extract_bvecs(iter, bio->bi_io_vec, BIO_MAX_SIZE - bio->bi_iter.bi_size, &bio->bi_vcnt, bio->bi_max_vecs, mem_align_mask, flags); - if (ret <=3D 0) { + if (len <=3D 0) { /* * A misaligned vector fails the whole I/O. Release any * pages pinned by earlier iterations before returning * since this bio won't be submitted to release them. */ - if (ret =3D=3D -EINVAL) { + if (len =3D=3D -EINVAL) { bio_release_pages(bio, false); bio_clear_flag(bio, BIO_PAGE_PINNED); bio->bi_vcnt =3D 0; } if (!bio->bi_vcnt) - return ret; + return len; break; } - bio->bi_iter.bi_size +=3D ret; + bio->bi_iter.bi_size +=3D len; } while (iov_iter_count(iter) && !bio_full(bio, 0)); =20 if (is_pci_p2pdma_page(bio->bi_io_vec->bv_page)) bio->bi_opf |=3D REQ_NOMERGE; - return bio_iov_iter_align_down(bio, iter, + ret =3D bio_iov_iter_align_down(bio, iter, &bio->bi_io_vec[bio->bi_vcnt - 1], len_align_mask); + if (ret) + return ret; + + /* + * An atomic write is submitted as a single bio, so it has to cover + * the whole iterator or it would be torn. + */ + if ((bio->bi_opf & REQ_ATOMIC) && iov_iter_count(iter)) { + bio_release_pages(bio, false); + bio_clear_flag(bio, BIO_PAGE_PINNED); + bio->bi_vcnt =3D 0; + return -EINVAL; + } + return 0; } =20 static struct folio *folio_alloc_greedy(gfp_t gfp, size_t *size, diff --git a/block/fops.c b/block/fops.c index a3a709697b40..0b614d76d128 100644 --- a/block/fops.c +++ b/block/fops.c @@ -341,6 +341,8 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *i= ocb, bio->bi_write_stream =3D iocb->ki_write_stream; bio->bi_end_io =3D blkdev_bio_end_io_async; bio->bi_ioprio =3D iocb->ki_ioprio; + if (iocb->ki_flags & IOCB_ATOMIC) + bio->bi_opf |=3D REQ_ATOMIC; =20 /* * Users don't rely on the iterator being in any particular @@ -371,9 +373,6 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *i= ocb, goto out_bio_put; } =20 - if (iocb->ki_flags & IOCB_ATOMIC) - bio->bi_opf |=3D REQ_ATOMIC; - if (iocb->ki_flags & IOCB_NOWAIT) bio->bi_opf |=3D REQ_NOWAIT; =20 @@ -766,10 +765,11 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, = struct iov_iter *from) if (iocb->ki_flags & IOCB_DIRECT) { ret =3D blkdev_direct_write(iocb, from); if (ret >=3D 0 && iov_iter_count(from)) { - if (iocb->ki_flags & IOCB_NOWAIT) { + if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_ATOMIC)) { /* * The buffered fallback blocks on i_rwsem and - * on writeback of the data it copied: return + * on writeback of the data it copied, and + * can't provide torn-write protection: return * the short direct write instead and let the * caller retry. */ --=20 2.39.5 From nobody Fri Sep 25 17:49:11 2026 Received: from mx0a-00364e01.pphosted.com (mx0a-00364e01.pphosted.com [148.163.135.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FDA445D92C for ; Wed, 9 Sep 2026 22:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991524; cv=none; b=ZEwhEt0UhGq95jn+Jh7IwMMiNgjEhthRohe3MqSi+2eNA1zPr/6LqvUXpEray+gmwHsTpH+AWBiUXPXb3xQgoIQziqpxmIftM+8n1uIfshSamVWJo3WNAXLihiisFGtTlqBvVyRPDscYc7vPJwxhtJ/DlIzeidTnq2hAhqn2vL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991524; c=relaxed/simple; bh=8sOl9Tikq+zc49svnUxUmgbqOF9i7Se4x0Ssb+suI4M=; h=Message-ID:In-Reply-To:References:From:Subject:To:Cc:Date: MIME-Version:Content-Type; b=Ki77GFg6vkgGt3YaPNPtCZVTNFa/w5jdkMbydv45DhSSoFLYKG6VY5k1sd6ksApHl5V/vhmsVQjIiYcORdIMGU3UVOig1Ws6IjZzpDZXcyJFRiF1i0bB47VPWHeVixD8w2ykBr+URemLE/dTTS+7JYSB4b7ZiGoKaDW1xPT55Zo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu; spf=pass smtp.mailfrom=columbia.edu; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=CnrpPX7u; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=NXX0eJSf; arc=none smtp.client-ip=148.163.135.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=columbia.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="CnrpPX7u"; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="NXX0eJSf" Received: from pps.filterd (m0167069.ppops.net [127.0.0.1]) by mx0a-00364e01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 689KYcqG3491617 for ; Wed, 9 Sep 2026 18:05:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pps01; bh=T0r7 0kRjbgwqQJBa4w0AIH8aVkNi7RMCwgx8DuykEvE=; b=CnrpPX7ucZKRFQjfW/hv 9U8FtKoFX/ZHfYaRCinsQaSrs89pjGKVKHgUMuOVB+qlDrmYlhsYqPdqROP/9MUM WNptYv5MICU/f6nMToQaQHS6WpiDx44g9ufW8MM/sTldOwsopRbAPqvXOosBGGRR 5jjWttvOxfGbkPTJJcf9sFr/JI7yxxCrO+DotXEdhjhvsbiRnL2SBRjP9sRY7RjA VxFEFBE5H/cVGmXrHw0YLLbZiu35sPMdcumKZ/LoNBob82FbWepZVquTXCljN4YV i2cqHxevnlRMoVN2IFEMUknW0jp+Zyt8Ec2JttZEKIxGfCQDF+bnkQvzwooyrPFb bw== Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by mx0a-00364e01.pphosted.com (PPS) with ESMTPS id 4gkcyfssht-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 09 Sep 2026 18:05:21 -0400 (EDT) Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-9103f4ddce5so71291976d6.3 for ; Wed, 09 Sep 2026 15:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; s=lionmail; t=1788991520; x=1789596320; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:date:cc:to :subject:from:references:in-reply-to:message-id:from:to:cc:subject :date:message-id:reply-to:content-type; bh=T0r70kRjbgwqQJBa4w0AIH8aVkNi7RMCwgx8DuykEvE=; b=NXX0eJSfCvmamZYXYkl4/mpieD1TOxUmoYBkqgSf95dB9DJw0JlyiNGqmtn/SDi4xD bZMU4ddotMCqOCU7NiifEPb59UYwzY9cMTcjn5qCMeE08znRZrasksFRNoKgGdkwFht0 hFRB3Rk3n2dz4hM0PBb2zs+GrYpfab/XUAB5cmLoZBQt1c/w4r6IZVUx7qtrVgEZDcA6 UbDPVz3YJhEsUeGUVh7Ezh00z+XBJwu65q2PWDeXPsNaJrApHKhvrKnn7Dg+6eZc8bpI /UR5gUkMtoVgceaGufPZAEYpwo3WSLgd5nKILmXvQUJto0RCu3wtWKhOKiuyPl96TLdU HiQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788991520; x=1789596320; h=content-transfer-encoding:content-type:mime-version:date:cc:to :subject:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=T0r70kRjbgwqQJBa4w0AIH8aVkNi7RMCwgx8DuykEvE=; b=f8wEA9nQjtoJ54b/9zWA6WuMZwpQXjVU9RbUqi/9m0LZ/OgHSi75LXW5g9yNJi/gWM WDyXDqqPt5XDJBW9byjfXjGs5DXWwtkFXBkE6yDyZ65BAQPf4EdAb0xodO37BSR7Es5G WHeZcTXO1Wv1Jb8ZYMep4bVEwdwR0Y9cnwMHZCWGd9Vnq9AtJ48Iaj4ikQR+i6c4PgBt P5gW1iPGgeSazyScWLqaYcxF76Z94ICfp1YZJKVJrcj3utWBd79fDfML1BKrhfZcVbgq StzpVD/nyofhUFY8fpYmZ0EiSsNn7wFTEMrJa9np33nMNveag18Yrolri5t3h6Sufovz jefA== X-Forwarded-Encrypted: i=1; AKwUvBx5YWz2upzDYPy3RbMZ7O/bAWah16A9G1eLHrOA7RDXkQAkHe22Bj/ANABsKm2ObOeQEdxHWBNxfiRgU/o=@vger.kernel.org X-Gm-Message-State: AFuF++nCc9784s4lmDD8GrcQx4XsNYUd8TeK9CvCGl0yCAUe5rq3r5X3 SDVUJL29bpge6bdfuvneGF2ehwPz2SULD3r9TfFICtNZVe25r5DPdi6QjkmZsLt4paEzzgkhxaX BK30V0zORx/nYVIenkW+gs9TIowgMWT6Sy/XBcgCaycK2X87hxN1aYhmCi40XwQ== X-Gm-Gg: AYBFou2Sc+zBy5b4Z8f8g61TCzWPSGAguHhGlf1RCiNEDoc2RPRmuJOYU9tKuB0XU5v m/tCJRcHOPxWviCcoTbT0Qo11VRNPBGiSzx8qQ308luZ+xZo5y3OiQel6+fxXUZtsGfrt3dinlw 8CyAnFVDgOtDBDGgR9cCNAsD1dnIJvXlB23xshETub0yNIJDkbU907tVlLaY9zkyUsSUTXct6OT DRfOKmyXVe2GZTa6iN3HsP8apt4bWz4Yk+HMJ7KL6gUcGek1KbPK6+LnXMpX7ckGZ2qbZOgBo+9 vHyETeXNgiSaaG26ParRQOPEgJU9gaVfljoVuaSfjsv/M4iv590uKsgPF4PSWnJ0QkTty1aVm8y anD/dwWDQWUVkgJUI9hvmMWuWN9EzQwGD4K27/+slCJpxN9Rs X-Received: by 2002:a05:6214:2f0a:b0:90f:b8e3:78de with SMTP id 6a1803df08f44-9103ef59ea5mr535642286d6.16.1788991520041; Wed, 09 Sep 2026 15:05:20 -0700 (PDT) X-Received: by 2002:a05:6214:2f0a:b0:90f:b8e3:78de with SMTP id 6a1803df08f44-9103ef59ea5mr535641566d6.16.1788991519547; Wed, 09 Sep 2026 15:05:19 -0700 (PDT) Received: from [127.0.1.1] (nat-128-59-176-193.net.columbia.edu. [128.59.176.193]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-91040693f75sm154018806d6.35.2026.09.09.15.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2026 15:05:19 -0700 (PDT) Message-ID: <20260909-blkdev-fixes-v3-6-1a5222c6e8ad@columbia.edu> In-Reply-To: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> References: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> From: Tal Zussman Subject: [PATCH v3 6/7] block: unpin all pages of a bvec in bio_iov_iter_align_down() To: Jens Axboe , Christoph Hellwig , Johannes Thumshirn , Luis Chamberlain , Hannes Reinecke , "Matthew Wilcox (Oracle)" , John Garry , Christian Brauner , "Darrick J. Wong" , Keith Busch , "Martin K. Petersen" Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Sashiko , Tal Zussman Date: Wed, 09 Sep 2026 18:05:14 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=S/9MU4sP c=1 sm=1 tr=0 ts=6aa1d821 cx=c_pps a=7E5Bxpl4vBhpaufnMqZlrw==:117 a=fJxgZNdXt3opHMdyAp+FXA==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=x7bEGLp0ZPQA:10 a=A0y_DWxS2BwA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Da8U98TiO7q1upZEImrf:22 a=JR4YdQiviy7OQf72WyZ1:22 a=VwQbUJbxAAAA:8 a=FzqJyQ6YvfuMctRh2gUA:9 a=QEXdDO2ut3YA:10 a=pJ04lnu7RYOZP9TFuWaZ:22 X-Proofpoint-GUID: r7b-D24gHnQ0bg7FLjT3Eb1swxX8HBnd X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfX/LkgWaAyPFdv nh2lh+xqKDumF9cnW4iPfyqTw9IdKjQG2YkWbp/YzaVOcoD+xS3q+OrOrLuCtNyQvfvewHZS2fp FkPfrUNyIz3d2QocZI3gnMscyomCgZuO/GHDQjMRi0dJ9klo7646CuSDbrjlCWQzf4/Ub5Wq+84 QnDXoJqOfK4VenI9/18rSef+jCCQZoAfS/QCcqGQVBG4SYm1CS8dvrDfp28SjwkbIKtL0aUhxE+ EwGgwAAhoGsdzybx0eeqtqQxy/hGTVJI/H0a3rz+mwBEoatLuds8ulisWo4v4GtBqbgzQaCJlHV 6jJZQT0MMUWNTL3fr3FqKKUpqTMgP8EwOHoRYXE+KtoMRN9V7cz1twr9GSsTQa32aTEc53b/oOP LJi8cpqAkmXgQ/+boHKDMi8ryKdfRN6XkypPpqkaCwQ4UWc3dNpPZDsBKJfqrqUZwe6Y1eaJHpD J38zwJbPlLp/P+w3S0w== X-Proofpoint-Spam-Info: AW1haW4tMjYwOTA5MDI0NyBTYWx0ZWRfX8KNd3KnSCCmO pzjMxf5NUmB8SnojAMjQYHpyoCcyJw7u0PR4KSpPp+arFwdsmrZA1cGHivRkcrx7AcAmsfMStFV jUawlpM7Wo7xKaojmmrIWewKw28MrlTy74NEpD2+XzBzkldv6uew X-Proofpoint-ORIG-GUID: r7b-D24gHnQ0bg7FLjT3Eb1swxX8HBnd X-Proofpoint-Virus-Version: vendor=nai engine=6900 definitions=11900 signatures=596817 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 lowpriorityscore=10 bulkscore=10 spamscore=0 phishscore=0 adultscore=0 clxscore=1015 impostorscore=10 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609090247 bio_iov_iter_align_down() drops trailing bvecs with unpin_user_page(), but a bvec built by iov_iter_extract_bvecs() can span several pages of one folio, each with its own pin. All but the first pin leak. The partially trimmed bvec has the same problem. Shrinking bv_len does not release the pins for the pages cut off by the trim, and __bio_release_pages() only unpins the pages bv_len still covers at completion. Both issues occur only with a logical block size above PAGE_SIZE and a large folio backing the user buffer. On a device with a 64K logical block size, an O_DIRECT pwritev() from a hugetlb mapping that ends 16K past a block boundary leaks one huge page per call, whether the remainder is its own bvec or the tail of a larger one. Unpin all pages of a dropped bvec with bvec_unpin(), and unpin the pages trimmed off the last bvec as well. Move bvec_unpin() up and split its page count into a helper so both sites share it. Fixes: 20a0e6276edb ("block: align the bio after building it") Assisted-by: Claude:claude-fable-5 Reviewed-by: Hannes Reinecke Signed-off-by: Tal Zussman Tested-by: Shin'ichiro Kawasaki --- block/bio.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/block/bio.c b/block/bio.c index 63e266d861f1..521c362ae9bf 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1196,6 +1196,21 @@ bool bio_iov_iter_set(struct bio *bio, const struct = iov_iter *iter) return true; } =20 +static unsigned int bvec_nr_pages(const struct bio_vec *bv) +{ + return (bv->bv_offset + bv->bv_len - 1) / PAGE_SIZE - + bv->bv_offset / PAGE_SIZE + 1; +} + +static void bvec_unpin(struct bio_vec *bv, bool mark_dirty) +{ + struct folio *folio =3D bvec_folio(bv); + + if (mark_dirty) + folio_mark_dirty_lock(folio); + unpin_user_folio(folio, bvec_nr_pages(bv)); +} + /* * Aligns the bio size to the len_align_mask, releasing excessive bio vecs= that * __bio_iov_iter_get_pages may have inserted, and reverts the trimmed len= gth @@ -1205,6 +1220,7 @@ static int bio_iov_iter_align_down(struct bio *bio, s= truct iov_iter *iter, struct bio_vec *bv, unsigned len_align_mask) { size_t nbytes =3D bio->bi_iter.bi_size & len_align_mask; + unsigned int npages; =20 if (!nbytes) return 0; @@ -1213,14 +1229,23 @@ static int bio_iov_iter_align_down(struct bio *bio,= struct iov_iter *iter, bio->bi_iter.bi_size -=3D nbytes; while (nbytes >=3D bv->bv_len) { if (bio_flagged(bio, BIO_PAGE_PINNED)) - unpin_user_page(bv->bv_page); + bvec_unpin(bv, false); =20 if (!--bio->bi_vcnt) return -EFAULT; nbytes -=3D bv->bv_len; bv--; } + + /* + * __bio_release_pages() only unpins the pages still covered by + * bv_len, so drop the pins for the pages trimmed off here. + */ + npages =3D bvec_nr_pages(bv); bv->bv_len -=3D nbytes; + npages -=3D bvec_nr_pages(bv); + if (npages && bio_flagged(bio, BIO_PAGE_PINNED)) + unpin_user_folio(bvec_folio(bv), npages); return 0; } =20 @@ -1503,17 +1528,6 @@ int bio_iov_iter_bounce(struct bio *bio, struct iov_= iter *iter, size_t maxlen, return bio_iov_iter_bounce_read(bio, iter, maxlen, minsize); } =20 -static void bvec_unpin(struct bio_vec *bv, bool mark_dirty) -{ - struct folio *folio =3D bvec_folio(bv); - size_t nr_pages =3D (bv->bv_offset + bv->bv_len - 1) / PAGE_SIZE - - bv->bv_offset / PAGE_SIZE + 1; - - if (mark_dirty) - folio_mark_dirty_lock(folio); - unpin_user_folio(folio, nr_pages); -} - static void bio_iov_iter_unbounce_read(struct bio *bio, bool is_error, bool mark_dirty) { --=20 2.39.5 From nobody Fri Sep 25 17:49:11 2026 Received: from mx0b-00364e01.pphosted.com (mx0b-00364e01.pphosted.com [148.163.139.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F62A489FCA for ; Wed, 9 Sep 2026 22:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.139.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991528; cv=none; b=cdA+mOgns1pEH0ybBqUttVOELX9ja8ezRjV8blIOz5l/jRhDcYjERmkqhqcMbaT9m7kIWzvJl6rkYNgz+ughGwsptWUn5V8FmDWBsm/1VdfYoTEG6pNKC+lVk/L73Rn+MdLOPBctiL30du4WF0sGn3LBynYSJYcqv0W7Ta7H3J4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788991528; c=relaxed/simple; bh=gUvUBfvXAIVgjCzdiwV3/TF71eqAveqNX7ByY2W7Bng=; h=Message-ID:In-Reply-To:References:From:Subject:To:Cc:Date: MIME-Version:Content-Type; b=BBRurcEP3aR/K++HfEY+y9rJeT1IXjGAsCPypFo4Tcq2TeG4x/1feBDJT4AoqZG9Ey8FBypJQuziNfHtmdVwBUCPR1u2Lr+HAbz60/9kvflP+cSDIkuGgMdWz1NX/uzu1VlXfyl8FMs7QwQdRS4kmPNK+tnahIQ6Rn4KXc7viQc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu; spf=pass smtp.mailfrom=columbia.edu; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=U440jBa4; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b=tgGO+if4; arc=none smtp.client-ip=148.163.139.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=columbia.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=columbia.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="U440jBa4"; dkim=pass (2048-bit key) header.d=columbia.edu header.i=@columbia.edu header.b="tgGO+if4" Received: from pps.filterd (m0167077.ppops.net [127.0.0.1]) by mx0b-00364e01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 689KYmbb1116630 for ; Wed, 9 Sep 2026 18:05:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pps01; bh=l0kN /rDFN/f55aXR9L0fwoeC0Cq8ZY3zyzxNrCxyk5Q=; b=U440jBa4zt5XZQqSXjr3 h6a8uj+m9eq8F/EPCTVNZhUwxBp7mVm8Js5AJ99ZaGjCfCQ3a+5hjjc4ZFOGf1+l LSPY76FSfg90vUn85AWJLfncpdaFJtDTXdgpdX+e3KzhmPsdcxNelLrqKNDXfG7z nkBryH0eX8CbCYWlbbisAN3gGmRmymvUYYSmdsxRjG1BdmeXViIPSmpJ6bO2arzm gSJfpLEC1ohfcupjxAwkI7V1zAvUxu3Tw21smdXH39M8CRlRcxg3GHYbBPK62HtF bGoIZyqxVYmXobYdtgkFHLzPrtPSjh4BvLbpGYLDNKJYjf3owKXHDDDGuYLOP41L ow== Received: from mail-yx1-f72.google.com (mail-yx1-f72.google.com [74.125.224.72]) by mx0b-00364e01.pphosted.com (PPS) with ESMTPS id 4gkcy11x85-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 09 Sep 2026 18:05:24 -0400 (EDT) Received: by mail-yx1-f72.google.com with SMTP id 956f58d0204a3-66ce3040ea9so8986449d50.2 for ; Wed, 09 Sep 2026 15:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; s=lionmail; t=1788991524; x=1789596324; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:date:cc:to :subject:from:references:in-reply-to:message-id:from:to:cc:subject :date:message-id:reply-to:content-type; bh=l0kN/rDFN/f55aXR9L0fwoeC0Cq8ZY3zyzxNrCxyk5Q=; b=tgGO+if46eWNe/HJIYYTuffi4ReZnwtixyoVGGFlwiMniBADIFuYF9KmAqgIZYr39S jwypkyBFYFllrVF913ECxr3EzA1JrUs5gKq1gvLD2NNiQRQg2Gn9RpYKqmAP42CFi6xP g20N8/oK6h+oO1wPp3Vo8xwIVBjzN49925Cz38O1MOntQL42muP61v6SK4sdrVgqEmFq 0GB9OPcK3F3bmlDQC1NriF+eki76fiu0YTvHcx74Npfei02EFNtRZMK5bWMjcoXbVX2o ZwSVXCwe+kzggmf4NcykTX89nAH1r7DAWu13/cwufAQsY0o2baIcDb52gE6bpCY8fDZV HVnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788991524; x=1789596324; h=content-transfer-encoding:content-type:mime-version:date:cc:to :subject:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=l0kN/rDFN/f55aXR9L0fwoeC0Cq8ZY3zyzxNrCxyk5Q=; b=PCYsRq3qhDiMXyTfhLdnLmJY+DC7Hgfa+oScXqRfIvsU2NmyWyzV/o/KvJ1mwjrPQG K/IcjkJFQxPyR3DjRe/SbDtWkWlUBHr0WhXCFPB/liOb5Nh3S0/YvKwvcQcrsAR2DhZV ho2kGD6xspOFp0j0rDseTr+nf6mwoDwWMA+3LXjb0zrqqc4Urgtrey/fDZR+D+OkCmMx X5MBsju6cpN9OC66R1t8JHR991zFuIIs4689HFpjHYk411TL02RrCpbeD+fhNmVMb5m2 ALbF6X4tYtzUK3ySccEhzAX1M5l3YZnFVoh0Cr9yYAx60aYYiAoXu9y8AxYks7skNOPb DszQ== X-Forwarded-Encrypted: i=1; AKwUvByaRDOfBG2lioFfFTxrCJeRPKvrj9/0xxIUx9vdVT1Y18nHeaRqGnvpa24UoddtsIFapCmtxt1v3y1yEws=@vger.kernel.org X-Gm-Message-State: AFuF++l7iFWSrES8+JjUO8DCDYGGYub0d7f1Ko4V5lHp6Tb5FxD5/8eD dqG3k0v5haFOT37tOr65w2aQfxY28PbMIwFfdQqXruXWraoA8HmfO+N2VHi07mcHCq7MK4VWyWQ jnQ1lWTs7ert3VhIoVeCCT4TryRikYyre6LwNrVh9HvR2K1aNPUfpot5W62UgPA== X-Gm-Gg: AYBFou2+kd3wssBxE0JfgxWGKhmmViSNf6i8KtbfPSepCCMNx5H+Z2Mid88BKhH6ojA dhWGsGZ+dn5Z/NzWxx+nmwVp0m0or0CFuLBMFaadC5aK1FfznfTsvgV7QyEBxC5H9tBtenZkzyU f3l7bAp4gJgkT71R6Wu7ZDAdE9Ed7X4xyp3ygJXoN5SePt3dlhPkWyiM4c2C0UZJuFZQDZfh8bM +FfmCTFdZCeDNO7/+MpoMIkGgpF9jf9HxCX5ykT1MiRf/UKXvWac7tRNvNsLdnCpWROavQIrKX5 TxcWAj4yPcrDlnc9bWseylHzbAwHbI1yFoOBJ+B62RTd4+qoO30H9iAhNU7GIWCf5g2dI6VLqiS YXlmpRmkcUj3Bi/PjYqie/7354E3FvUN0gw1XZJ6jqx+ukipV X-Received: by 2002:a53:c847:0:b0:66d:1c78:5dd2 with SMTP id 956f58d0204a3-66fb5a6d546mr10813810d50.37.1788991524051; Wed, 09 Sep 2026 15:05:24 -0700 (PDT) X-Received: by 2002:a53:c847:0:b0:66d:1c78:5dd2 with SMTP id 956f58d0204a3-66fb5a6d546mr10813779d50.37.1788991523534; Wed, 09 Sep 2026 15:05:23 -0700 (PDT) Received: from [127.0.1.1] (nat-128-59-176-193.net.columbia.edu. [128.59.176.193]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-91040693f75sm154018806d6.35.2026.09.09.15.05.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2026 15:05:20 -0700 (PDT) Message-ID: <20260909-blkdev-fixes-v3-7-1a5222c6e8ad@columbia.edu> In-Reply-To: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> References: <20260909-blkdev-fixes-v3-0-1a5222c6e8ad@columbia.edu> From: Tal Zussman Subject: [PATCH v3 7/7] block: remove dead metadata handling from the async direct I/O path To: Jens Axboe , Christoph Hellwig , Johannes Thumshirn , Luis Chamberlain , Hannes Reinecke , "Matthew Wilcox (Oracle)" , John Garry , Christian Brauner , "Darrick J. Wong" , Keith Busch , "Martin K. Petersen" Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Sashiko , Tal Zussman Date: Wed, 09 Sep 2026 18:05:14 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=FrWQbGrq c=1 sm=1 tr=0 ts=6aa1d824 cx=c_pps a=VEzVgl358Dq0xwHDEbsOzA==:117 a=fJxgZNdXt3opHMdyAp+FXA==:17 a=IkcTkHD0fZMA:10 a=VdqzKS8jKosA:10 a=x7bEGLp0ZPQA:10 a=A0y_DWxS2BwA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Da8U98TiO7q1upZEImrf:22 a=QOCMdifcju39GKoXhKua:22 a=IE87Obj3e0A1gCLlgTsA:9 a=QEXdDO2ut3YA:10 a=uujmmnXaIg8lM0-o0HFK:22 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTA5MDI0OCBTYWx0ZWRfXzoeXG1WMMTBX JgwJipBNAFV1cHz+43ajJHq5m/oQPTCUaP+v7l+8nD+Bu5yGTKOId1pAI3fHEtnBgk1oEMTgpAv GFN1SLtXbwdTUumXZarqHm5x7kyU5+ow80hoKi+pK3vaiv9/tXhh X-Proofpoint-ORIG-GUID: GFlBqJxUp2QcfpbcAM6xMBkJEP28fXvd X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTA5MDI0OCBTYWx0ZWRfX7T2aRBNonqa+ oQ+k9rHb5lZNq4B3ZNSp6KmGHS+nGUCZm4iFvb4Yh5ER4EG/MqrJJCvdyXE4w5yXngWwtKuLbKY M0v39/yoPgVEaiBQ2NfL8Tlk5GgZjnd/7ZaqBkbZfRw67Qyq7BaB+eC+GergHntzVA08Ey5yuo/ rgmtvrX6c56M3fpOcWKUbLaSWjseJaTq2CWA+zFfYQFKX5WcujSBQHuCiuv0qFHYjx9vFyKBQLu 4mqu9QGDNGdY8ZICSUmZ0Y6hHtG0D5DkJqHimvq4jhCp3ZP/Wf3ojmlfqqSYlzPJUOBburMnC60 wATC5oMMel+FHOfGw2vyt/WOfOGBpF7rpfTnoN8YZZ/OVIcn6zBx8OPuxrKqf9Bc9NEJ7AfJthr +6iP8nZEb05BOIsi45R1Cv96cHXZIofoL1i2ajdGfzA+QbhjJ3zydoXSnKS1oHix7jLDbOWAKXa 5P701SOZpT0aCItJCNQ== X-Proofpoint-GUID: GFlBqJxUp2QcfpbcAM6xMBkJEP28fXvd X-Proofpoint-Virus-Version: vendor=nai engine=6900 definitions=11900 signatures=596817 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 spamscore=0 bulkscore=10 lowpriorityscore=10 suspectscore=0 impostorscore=10 phishscore=0 clxscore=1015 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609090248 Since commit 2729a60bbfb9 ("block: don't silently ignore metadata for sync read/write"), blkdev_direct_IO() sends every IOCB_HAS_METADATA request to __blkdev_direct_IO(). Remove the now unreachable metadata mapping in __blkdev_direct_IO_async() and the unmap in its completion handler. No functional change. Assisted-by: Claude:claude-fable-5 Reviewed-by: Christoph Hellwig Signed-off-by: Tal Zussman Reviewed-by: Hannes Reinecke --- block/fops.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/block/fops.c b/block/fops.c index 0b614d76d128..6a86bffafa7a 100644 --- a/block/fops.c +++ b/block/fops.c @@ -306,9 +306,6 @@ static void blkdev_bio_end_io_async(struct bio *bio) ret =3D blk_status_to_errno(bio->bi_status); } =20 - if (bio_integrity(bio)) - bio_integrity_unmap_user(bio); - iocb->ki_complete(iocb, ret); =20 if (dio->flags & DIO_SHOULD_DIRTY) { @@ -366,13 +363,6 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *= iocb, task_io_account_write(bio->bi_iter.bi_size); } =20 - if (iocb->ki_flags & IOCB_HAS_METADATA) { - ret =3D bio_integrity_map_iter(bio, iocb->private); - WRITE_ONCE(iocb->private, NULL); - if (unlikely(ret)) - goto out_bio_put; - } - if (iocb->ki_flags & IOCB_NOWAIT) bio->bi_opf |=3D REQ_NOWAIT; =20 --=20 2.39.5