From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 79612361667 for ; Thu, 21 May 2026 14:54:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779375248; cv=none; b=UwvG4UEywI93b4mVRiy9xJgMa4GtvbDJtzduIc+yMK5PPUe5umbfMMxJlkatpfuJ++nNFK8rJTkUY9HaO0to0IlxNsLsuwV5roCPGI+2CItVZpxE60tAvSPalimlt5Pe5VwXZiJ8UG3zWZg+Xet9nwZjiPSuRXsd6TRAtdTzFW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779375248; c=relaxed/simple; bh=XZ5M1gRMaGtFZ82Dds+EuBf/IAlYptn+Pk4c4/avnNM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=adb4O44oCtDypX2O1n3zLM30hvNpi2H7KpwjIO6sPXtg8bo8PNf8kimYETyxq3qSpdeCYpRjIP5aG1gYi3TvRpKp8aYyk3+szDYMN56KfNE3y55DseqXLEywUQotoYNFhNc+/t2qvPUSToEsJSjkr2+EdiFMOz9NAUoG9UdFP4U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NG8vu/Xs; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NG8vu/Xs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D84D81F000E9; Thu, 21 May 2026 14:54:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779375245; bh=UZo8ckPnFvPQyJdHWs7MYZ7908EuicBWVqEq3mObAuA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=NG8vu/Xs9DPqW2P52N7VKEN526es7gFqS2foZuknV4N8AV7EEg3JdRxuzKHQ+TLqU ytZah9/qmQ1pyZD0n++JQJkgPUXPzZnRkKjGSBaV/CnTmR+9bkWqQH+oJrWUB9JhDM f07OHwDRuelSltFL+Vps2YtlQCN8bpJ5dg/8tkhvgoHRVzNTz1t9+vse8eFv05TpZ9 c9LLc5/VgSzMPk63RJLJG65f4xJ+511c3h4rQGd+AzzDnuyM4NOp8z/c0H4/jRUR3/ FUT7z5DJNlwvA9qeA8C55omXjw/xxK8Jp35BIsfF/ktj86SER0PG0BMGH/bSjUVBMp DSwWU4z9G0dmw== Date: Thu, 21 May 2026 15:53:58 +0100 From: Lorenzo Stoakes To: Thorsten Blum Cc: Andrew Morton , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Kees Cook , Andy Shevchenko , Yury Norov , David Laight , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] string: use offset_in_page() in sized_strscpy() Message-ID: References: <20260521090655.160282-4-thorsten.blum@linux.dev> <20260521090655.160282-6-thorsten.blum@linux.dev> 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=us-ascii Content-Disposition: inline In-Reply-To: NAK. I guess I wasn't clear before :) On Thu, May 21, 2026 at 03:47:25PM +0200, Thorsten Blum wrote: > On Thu, May 21, 2026 at 12:31:25PM +0100, Lorenzo Stoakes wrote: > > On Thu, May 21, 2026 at 11:06:58AM +0200, Thorsten Blum wrote: > > > Replace the open-coded implementation with offset_in_page() to simplify > > > sized_strscpy(). > > > > > > Signed-off-by: Thorsten Blum > > > > I feel this patch actually makes sized_strscpy() more difficult to understand > > unfortunately, so not really in favour of us taking it. > > > > > --- > > > lib/string.c | 3 ++- > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > diff --git a/lib/string.c b/lib/string.c > > > index 1f9297e9776a..7c72adc7377c 100644 > > > --- a/lib/string.c > > > +++ b/lib/string.c > > > @@ -25,6 +25,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > #include > > > #include > > > @@ -127,7 +128,7 @@ ssize_t sized_strscpy(char *dest, const char *src, size_t count) > > > * since we don't know if the next page is mapped. > > > */ > > > if ((long)src & (sizeof(long) - 1)) > > > - max = min(PAGE_SIZE - ((long)src & (PAGE_SIZE - 1)), max); > > > + max = min(PAGE_SIZE - offset_in_page(src), max); > > > > This isn't strictly the same code, offset_in_page() is: > > > > #define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK) > > > > So this is now, effectively: > > > > - max = min(PAGE_SIZE - ((long)src & (PAGE_SIZE - 1)), max); > > + max = min(PAGE_SIZE - ((unsigned long)src & (PAGE_SIZE -1)), max); > > > > So there could be some issues here with type conversions at least in theory. > > I think this should have used unsigned long from the start, as long > seems a bit odd for a pointer, and PAGE_SIZE - offset_in_page() is a > common kernel idiom for this exact calculation. > > Andrew also commented [1] on this line recently. Yup, but it makes no sense as a singular change, it actively worsens the code. Hypotheticals about what should or should not be with you not changing anything isn't useful. > > > But in any case you're now making the logic inconsistent (the next line uses > > bitwise operations directly). > > Agreed, maybe there are other helpers we can use here too, but that > should probably be a follow-up patch. No, this patch is bad, we're not taking it. > > > So I'd rather we didn't make this change. > > FWIW, using offset_in_page() in lib/string.c (as suggested by Andy [2]) > was the initial motivation for moving it out of mm.h, so I'd prefer to > keep the use-site in this series if possible. Nope. > > Thanks, > Thorsten > > [1] https://lore.kernel.org/lkml/20260519123740.458d905f958f39d41cb130fd@linux-foundation.org/ > [2] https://lore.kernel.org/lkml/CAHp75VfQNkqEYsO4Uup0c-uiYuVyAWit=tmCz2BsYLp-sjXsZw@mail.gmail.com/ Thanks, Lorenzo