From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=80.241.56.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387484; b=gIFfhbKYwoHcCKI31ZLpbEzzXnKAP9JDF8gK1/GXQXhVTKd9FB1qU7C5++IcJbXTxxeN +XsNRuZlfKBPZrgs3TDYYHI8y3cRZQLnbcOkdyKnWwoUvaQ0tlC/RD6JE6SAHGWdzYYkH q+G4lupBQlux/z/FnIdKwfwy9z0J6aYy2mk0SH3+96qP28m9IagscRLCc90bciwhOf8uI l0B/7wK7YvOAdF7lGQJtLUYEj6DK/2FQDBYbFbSGVsecliN6GFrTYT2Q3WmY1okk7Ecvy 4bgo3O87OtTu7IqSbIGup99GMsR3tOfFMBIutYCKNeCWpcjNRV9lYUhLJLEuWpKHilA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387484; h=DMARC-Filter:Received:DKIM-Signature:Message-ID:Subject:From: Reply-To:To:Cc:Date:In-Reply-To:References:Content-Type: Content-Transfer-Encoding:User-Agent:MIME-Version:X-MBO-RS-META: X-MBO-RS-ID; bh=8LO/ruhZW03XTs8t9ok6FoMa6dzLRbDA1xaaIk2UNDM=; b=jiHgGXE6PAIwghlAOPBcqPa6KpyGTZEpOkcb4L44c9cEwJ/SYMEEB43z8QrzhDa+vkKn B39rQbMJZm3xUXUTnL25s+dowLu2a2q1n9nIswzXT1hzA0QVnrvB/xOGY2+Za8bYAez8+ 5vKxD51ebvlQuESoC3gSODeDk9ivGDPj3Vu/h1jkVcWjpABJi2xTJSNXVgb1JNrYRZUmu rULaJQLk1ADFRm/sHNtlcbI3dXDq8ZBSY5K6zU7+fRpTr3oMfdXHc+DZVlz94yF5HuJaU ymVQEHrPlvYG0+KWC6MB94MvsbcPBSv4pVWGK+EwLaFSlN0aoGq5paohMVHdQzyr9Uw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=qR2R5vQn; arc=none smtp.remote-ip=80.241.56.171 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED4EF606A332; Fri, 4 Dec 2026 12:31:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ED4EF606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=qR2R5vQn Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4jgrT4214kzMlfF; Fri, 04 Dec 2026 13:31:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796387480; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8LO/ruhZW03XTs8t9ok6FoMa6dzLRbDA1xaaIk2UNDM=; b=qR2R5vQnm4Co13a//fGugl+nnp7K8MLqjJT/xbZ6a5DbeMlyuI0hy2j5KnrRdi7i2sUlTM xfOvWMg5qcouA74mhDtK7gW1oksF29QYoT4DQCYdWTEy/rt/Lcb7bf/LRCSSKgrukRGymH 1Mtwgb1MULuQVasErkUM9Y6qbTWWr+Nf4cwIOlPAwFBJcel3RFwyjUABaqf5QiOa3b6v8/ vH/rxL0LVnwGGKJpXkSxL8AH0QcKtEZPIiuTHHrZCxb2bMyjhd4RGnImdm4M6paKk9Lmuz fppL3ghMdE4WywNxfhK9f7HbVhDRHRNzQkrcDaCKAreytKKvLxFUlUyq9ROUzA== Message-ID: Subject: Re: [PATCH] rnull: do not zero past the backing page From: Philipp Stanner Reply-To: phasta@kernel.org To: Vitaly Wool , Andreas Hindborg Cc: Boqun Feng , Jens Axboe , Miguel Ojeda , Gary Guo , Bjorn Roy Baron , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , Onur Ozkan , linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 04 Dec 2026 13:31:17 +0100 In-Reply-To: <20261204104434.234417-1-vitaly.wool@konsulko.se> References: <20261204104434.234417-1-vitaly.wool@konsulko.se> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.2 (3.60.2-3.fc44) X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MBO-RS-META: zoecf9zunt5wdh4r9fr9qa171is3kumf X-MBO-RS-ID: 5df77d0cd8a184aef3a On Fri, 2026-12-04 at 11:44 +0100, Vitaly Wool wrote: > When a read hits a backing page that was never written, rnull fills the > segment with zeroes up to the end of the segment's current page, which > is a page of the bio, not of the backing store. If the read does not > start at the beginning of the backing page, the zeroes run on into the > next backing page, which may hold data, and the read returns zeroes for > it. For instance, with 512 byte blocks, a direct read of 4K at sector 7 > into a page aligned buffer, where only sector 8 was written, returns > zeroes for sector 8. Fix this. >=20 > Signed-off-by: Vitaly Wool > Assisted-By: Claude Opus 5.5 So does it need Fixes: ? >=20 [=E2=80=A6] > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // CA= ST: Casting from `usize` to `u64` never overflows. > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 secto= r +=3D copied as u64 >> block::SECTOR_SHIFT; If it always works, can't it be written as u64::from(copied)? > =C2=A0=C2=A0=C2=A0=C2=A0 /// Copy zeroes to the current page of this segm= ent. > =C2=A0=C2=A0=C2=A0=C2=A0 /// > -=C2=A0=C2=A0=C2=A0 /// Copies=C2=A0 `PAGE_SIZE - (self.offset() % PAGE_S= IZE` bytes of data to this > -=C2=A0=C2=A0=C2=A0 /// segment starting at `self.offset()`. This call wi= ll advance offset and reduce length of > -=C2=A0=C2=A0=C2=A0 /// `self`. > +=C2=A0=C2=A0=C2=A0 /// Copies at most `max_len` zero bytes to this segme= nt starting at `self.offset()`, and never > +=C2=A0=C2=A0=C2=A0 /// past the end of the current page, i.e. at most `P= AGE_SIZE - (self.offset() % PAGE_SIZE)` > +=C2=A0=C2=A0=C2=A0 /// bytes. This call will advance offset and reduce l= ength of `self`. > =C2=A0=C2=A0=C2=A0=C2=A0 /// > =C2=A0=C2=A0=C2=A0=C2=A0 /// Returns the number of bytes written to this = segment. > =C2=A0=C2=A0=C2=A0=C2=A0 #[inline] > -=C2=A0=C2=A0=C2=A0 pub fn zero_page(&mut self) -> usize { > +=C2=A0=C2=A0=C2=A0 pub fn zero_page(&mut self, max_len: usize) -> usize = { The function name would make me think that this zeros the entire page. Maybe a different name might make sense? And what about max_len =3D=3D 0? Often API functions use that for "write till the end" Regards, P. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let offset =3D self.offs= et() % PAGE_SIZE; > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let length =3D (PAGE_SIZE - o= ffset).min(self.len() as usize); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let length =3D (PAGE_SIZE - o= ffset).min(self.len() as usize).min(max_len); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let page_idx =3D self.of= fset() / PAGE_SIZE; > =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let dst_page =3D self.pa= ge(page_idx);