From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from hr2.samba.org (hr2.samba.org [144.76.82.148]) (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 385B619E839; Thu, 9 Apr 2026 08:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=144.76.82.148 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775724456; cv=none; b=WEjpF0ETA4Ev7DoRMBh9V8DGrkBEDkETr1T8reSgx84SGuh4oxAeoeUmL/ARzsPnQivT3g2P5wjQGZtDa9mos2DVs8O54DMxhl9P+App3+FXKQy5F9elITm2PJV2Oq/4mOYqcDEXew28cd+eQauec3rCPemnY2HTUmSel0pDT0o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775724456; c=relaxed/simple; bh=uWfpcH/Aq8NLPtNxzg+ifTHzZUkluCT0p2AKfAgtp1g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rK3s9wgiK6NwEyOhfoag/kOdhmeqsovVqizVzHyfxd3cerQlPBGi7JGE9LwjMIVqtLscGYJunR/IyukbLNTm7ptGtHJOmcnV6kpLMTzaMdjohAX2O3it9RpyPCiRW672OO9onilAbdujle9QZgU5tiHUffsd3/QI2qbwwqKS2js= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=samba.org; spf=pass smtp.mailfrom=samba.org; dkim=pass (3072-bit key) header.d=samba.org header.i=@samba.org header.b=LP69PJVB; arc=none smtp.client-ip=144.76.82.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=samba.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samba.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (3072-bit key) header.d=samba.org header.i=@samba.org header.b="LP69PJVB" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=From:Cc:To:Date:Message-ID; bh=fw4Fi2J7rWpChzRbVh6OVQ83bjYAyOleBcAdAZEagLQ=; b=LP69PJVBp2AAvvJhb+h7sgwMOA jk5BLH+tq9NMURwyv0gBh5ZXq9bXgfx2E1pJwSAPFsAzXcrBZ2dvOQfwJyjb8gnSLKm116gEYAUz4 ggk0+72oTcH+RLJPWW3Lg0hd+2pryKTMClpXT7WqnpDUHpgMUbtLhdIQgbK55u7y66HHiKDCdknvE aif4QA+dufYcnvZ/BYhJ3WhPTff9SJt7xNHt2IEq+YgZFtrQs6dXrV2/YtvKaYR4XOFAZCGy1SNE3 UIQ1KtimHodn9jQrwH9q/Xdp5IClUlit/vsClSmNzlEtmXZfNnVMOe0mIAPKAgujXA2ZKCLj8yore ih5GrRpBzwvlVLcLhCIVlNU7Rzzb99VxuAoNC8GBvHSONdaVcn0983O0sHxFZNChzlaW/6gzhnkL9 /4SbDog1AHcsZbRhji/O4xG7wStB0Z7rEjQOkBhSNKCwgxiH5PgG1kTcNa8k5g9JOv1vSukA80UMl itZM/m4V6TIf6P6qSK+pX1CR; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1wAl2v-000000087mr-3yWE; Thu, 09 Apr 2026 08:47:30 +0000 Message-ID: Date: Thu, 9 Apr 2026 10:47:29 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/5] uaccess: add copy_struct_{from,to}_bounce_buffer() helpers To: David Laight Cc: linux-kernel@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com>, Dmitry Safonov , Francesco Ruggeri , Salam Noureddine , David Ahern , "David S . Miller" , Michal Luczaj , David Wei , Luiz Augusto von Dentz , Luiz Augusto von Dentz , Marcel Holtmann , Xin Long , Eric Dumazet , Kuniyuki Iwashima , Paolo Abeni , Willem de Bruijn , Neal Cardwell , Jakub Kicinski , Simon Horman , Aleksa Sarai , Christian Brauner , Kees Cook , netdev@vger.kernel.org, linux-bluetooth@vger.kernel.org References: <20260407192540.321f3879@pumpkin> Content-Language: en-US From: Stefan Metzmacher In-Reply-To: <20260407192540.321f3879@pumpkin> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi David, > On Tue, 7 Apr 2026 18:03:15 +0200 > Stefan Metzmacher wrote: > >> These are similar to copy_struct_{from,to}_user() but operate >> on kernel buffers instead of user buffers. >> >> They can be used when there is a temporary bounce buffer used, >> e.g. in msg_control or similar places. >> >> It allows us to have the same logic to handle old vs. current >> and current vs. new structures in the same compatible way. >> >> copy_struct_from_sockptr() will also be able to >> use copy_struct_from_bounce_buffer() for the kernel >> case as follow us patch. >> >> I'll use this in my IPPROTO_SMBDIRECT work, >> but maybe it will also be useful for others... >> IPPROTO_QUIC will likely also use it. >> >> Cc: Dmitry Safonov <0x7f454c46@gmail.com> >> Cc: Dmitry Safonov >> Cc: Francesco Ruggeri >> Cc: Salam Noureddine >> Cc: David Ahern >> Cc: David S. Miller >> Cc: Michal Luczaj >> Cc: David Wei >> Cc: Luiz Augusto von Dentz >> Cc: Luiz Augusto von Dentz >> Cc: Marcel Holtmann >> Cc: Xin Long >> Cc: Eric Dumazet >> Cc: Kuniyuki Iwashima >> Cc: Paolo Abeni >> Cc: Willem de Bruijn >> Cc: Neal Cardwell >> Cc: Jakub Kicinski >> Cc: Simon Horman >> Cc: Aleksa Sarai >> Cc: Christian Brauner >> CC: Kees Cook >> Cc: netdev@vger.kernel.org >> Cc: linux-bluetooth@vger.kernel.org >> Cc: linux-kernel@vger.kernel.org >> Signed-off-by: Stefan Metzmacher >> --- >> include/linux/uaccess.h | 63 +++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 63 insertions(+) >> >> diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h >> index 1234b5fa4761..a6cd4f48bb99 100644 >> --- a/include/linux/uaccess.h >> +++ b/include/linux/uaccess.h >> @@ -513,6 +513,69 @@ copy_struct_to_user(void __user *dst, size_t usize, const void *src, >> return 0; >> } >> >> +static __always_inline void >> +__copy_struct_generic_bounce_buffer(void *dst, size_t dstsize, >> + const void *src, size_t srcsize, >> + bool *ignored_trailing) >> +{ >> + size_t size = min(dstsize, srcsize); >> + size_t rest = max(dstsize, srcsize) - size; >> + >> + /* Deal with trailing bytes. */ >> + if (dstsize > srcsize) >> + memset(dst + size, 0, rest); >> + if (ignored_trailing) >> + *ignored_trailing = dstsize < srcsize && >> + memchr_inv(src + size, 0, rest) != NULL; >> + /* Copy the interoperable parts of the struct. */ >> + memcpy(dst, src, size); >> +} > > Return 'ignored_trailing' rather than pass by reference. I also thought about that but it makes the copy_struct_to_ case more complex. I'm not sure but my guess would be that the compiler would have the chance to skip the ignore_trailing logic if (as all current callers do) NULL is passed. > And this is probably too big to inline. In the next patch this replace open coded logic in copy_struct_from_sockptr. So as all of copy_struct_* consists of inline functions I thought it would be good to keep it that way. So unless there a real good reason to change it I'd like to keep it as is. Thanks! metze