From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB40CC83F10 for ; Sat, 12 Jul 2025 20:59:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A0AD6B00AE; Sat, 12 Jul 2025 16:59:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 578426B00BA; Sat, 12 Jul 2025 16:59:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4675C6B00BC; Sat, 12 Jul 2025 16:59:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 33D246B00AE for ; Sat, 12 Jul 2025 16:59:08 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AD429160298 for ; Sat, 12 Jul 2025 20:59:07 +0000 (UTC) X-FDA: 83656827534.01.C415649 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf20.hostedemail.com (Postfix) with ESMTP id CA5961C0004 for ; Sat, 12 Jul 2025 20:59:05 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TOhdGFWY; spf=pass (imf20.hostedemail.com: domain of chris.bazley.wg14@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=chris.bazley.wg14@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752353945; h=from:from:sender: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:dkim-signature; bh=1ZuS0G5loQ6VTp2rtwXZCwwcpkBS4A9zfG+scNKGaJg=; b=n0KKOSs3GYMM9/lddJipht2YYY2cxImRpO3yfKTd7cy2PCU9YiFKKz8hz0XbetLO4n9U7K jtpHl3M2CQ/EHfJEy3ffcUg+urDDFU7AlTfJw/SMjKIbPmfLgpfJ0xN+CA6XusdLYzohVE MMIgg1jqaBmRJCex4jRGCOWPm2j8tWg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TOhdGFWY; spf=pass (imf20.hostedemail.com: domain of chris.bazley.wg14@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=chris.bazley.wg14@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752353945; a=rsa-sha256; cv=none; b=tLzZfvgPfhSBAt0VihKAi57qgf2nnin9YC2HwPtvebIVX9NbS9SlkFJfdFsD76y8f2qR2r 9nHkkPjWyWSi3LNxhrNNvzYZcLUM3zhaWUOuhzuJiu7g9LcrNdivF7fLWEoxgxMmsz52Yu pZTcAX7rxjmQ5qu6LdZe7NUWc96wNLg= Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-315cd33fa79so2435225a91.3 for ; Sat, 12 Jul 2025 13:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752353944; x=1752958744; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1ZuS0G5loQ6VTp2rtwXZCwwcpkBS4A9zfG+scNKGaJg=; b=TOhdGFWYxD2+Vn7Jg/r1zhXM5BuFnNdEzCUzEWKYSd7O8YlOrBjqCLuLjaIkZuxM8g h1SjrJ7oHurLosUH8p8Lvd3E0OmBRp/klnyrtHxthM7e8ax2DEpZEFYfUz+Lizj75Uhx M2KKcwv1SdoT1KC7MReosIMHbmsLZGl9CCHi8JE+0RbzX8E4LQK4OoixeFb2q2dTcKzC oYwRzDOHMCZIn00D5kmD10lPYcG9fhMEthb+JZFw4tTKqZ/bBurvCZjsz9ytEWNtwdUB jU1EgahXkNcSsub4LhO3TmqxpBC/gWD34ZlbKgrjtPMjChWa/rufTom5rgXKww3LthBd yiGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752353944; x=1752958744; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1ZuS0G5loQ6VTp2rtwXZCwwcpkBS4A9zfG+scNKGaJg=; b=dg3xMGudAAYgdJ83KtCSIrgPqDKwwZevGHZJf+6E9Kcz4ObfH/NjOizLNWAUIrGWj3 0j3Fhtin9sc3R8u/9pWD5jQgbw+LrPcByY8dluGm7WsklVPVAW1epXyZMfzaZqwM5Ehv gnFb1tfDHh3yaZf9bkPvW1uOZnNOvU0FomE+l3OfDQzVFLgds+mkXqTk6NP5+CmIrzcf UOSm3Jgqeq+fViwqcZkqY5FQA7/loTIx4dK0QOUuWXm9CK+lZqR8BcRFPFyjMpaB8l3i 867bhEISUhKj+GuZlAIGyrshwsPmvhGC2LO3y62ektIygeuLji/WYiXo8m5dOQ5jYkel kw2A== X-Forwarded-Encrypted: i=1; AJvYcCVOkQ19k/Z9XRJvRjzxMLGPZLHlsVuXpe6cqaadOaIxFdGSug2TColNMjYcB+oGt5D4AWvY3QXcPA==@kvack.org X-Gm-Message-State: AOJu0Yzm6cw5hEShIYyU0oqgcp7KFjG7KJxVOLb/dn/hLc5RZiHxQU9A gIyKsIWr3pkBQc8I390aLoT1BqzbXnHcY+zrj/r0iXJCuBYGmp7DLe7ZuF1Zo6C3G7D0gbNG90t 2l7QrZXilU3VJW+5m++KAJ0ed9WNbRPI= X-Gm-Gg: ASbGnctu8o8RXb75LW2vvGbQY6f9MupOP21JPCeI7IXIpNTFz1yFZUpIpT+dLliklSn nM0Eve6OPq5MLHUbpsT43C+Jok1CJ24LuWn+HFolwvskI7ThcHJX0eDdml3AybzcKt68rom8xVO 6op58XJlDHPHGHZtfR66TvArf5ecAIeLYRaRlH97yMsk12MrvsVjGVvWbiaKFddJQjqwc6lRGF3 WUmwT/MdDb1eocyR198gbWum+9poc6WvmTChWhAjGNN0mu3nFM= X-Google-Smtp-Source: AGHT+IGWc/bsSjfCk72zM+sQY+wNB8gvwjDVcV29c75JkSwrzzUlbnd+fsKQQzCW9smTm3J6SKcCBpYHBPBehSjJtRw= X-Received: by 2002:a17:90b:5804:b0:311:b005:93d4 with SMTP id 98e67ed59e1d1-31c50e2c50dmr10076417a91.25.1752353944580; Sat, 12 Jul 2025 13:59:04 -0700 (PDT) MIME-Version: 1.0 References: <033bf00f1fcf808245ae150346019aa7b997ea11.1751862634.git.alx@kernel.org> In-Reply-To: From: Christopher Bazley Date: Sat, 12 Jul 2025 21:58:53 +0100 X-Gm-Features: Ac12FXzabVR3CNZ1e6s3vvkMYX7Q2knC-RQiMrmuvB567KXzcfJDo2IIzUb977w Message-ID: Subject: Re: [RFC v3 3/7] mm: Use seprintf() instead of less ergonomic APIs To: Linus Torvalds Cc: Alejandro Colomar , linux-mm@kvack.org, linux-hardening@vger.kernel.org, Kees Cook , shadow <~hallyn/shadow@lists.sr.ht>, linux-kernel@vger.kernel.org, Andrew Morton , kasan-dev@googlegroups.com, Dmitry Vyukov , Alexander Potapenko , Marco Elver , Christoph Lameter , David Rientjes , Vlastimil Babka , Roman Gushchin , Harry Yoo , Andrew Clayton , Sven Schnelle , Heiko Carstens , Tvrtko Ursulin , "Huang, Ying" , Lee Schermerhorn , Christophe JAILLET , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Chao Yu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: CA5961C0004 X-Rspamd-Server: rspam06 X-Stat-Signature: cehmfs85yeewi3win7uk74m536f17sni X-HE-Tag: 1752353945-477489 X-HE-Meta: U2FsdGVkX18jH0uAM3lFiaYYmufaTHriz8tEEpAUhWhnpjedjANkUDCq0Ufv2MPvVFr3tSdx4yfes7JSNXlBnaPP4i6CyoJgUDGmHVBgBAipFdUL0ZudXCn5qlrvFhCqaUPWn6Z3jRQGgaOS1O47u5Qe2Fsqsi88O4SNzKCjgab3LUNckdO0cjZV6F3NMZwc6AgyB/UHlh7gHBfIlYONn+cBXx4tgpDJPPGMFodFi/MinNUvjPeMB0rU0cMPS+9915R2ObclVchjlCqzstH91sYYcW+qVNWcCZiFldgepU1BDrCrPXGyR3DmLHEaJdodJ93wEG1yU7T/zwr13g6HnH2M8k3zq8nH/K6eeqG+3XZRhYecE4/wWEFdy/5pU2jl2wsGZ6S49UiscXxgfaB6arkbANMnZYIi414vuEZPHo+uOUoFAVqfeX3JudL5Q8KEgj6JltnsASno8Gp/4BcjHHNLj4qt710LQY31bGwVHD2JuktuRgeew7jLgyWHNURHT5Nco6l2T3NCfucUF0PqrMizP6MA5Sk0G/irL0QRYr0i+m8xFaWCjsDv5dNslLokH77Tau+x11SjUVK1unDML/kV6qK1xEEdAZPmwrCJh2RaRS0DvtbJNJHwyw6tllMEYPTvV5NsgBcNXIzyKroj2acBvqBwIPR4HGKIge2pLMON2p9Swy5a+aBsNxyj0dfBnq06PlBscLSJ/VkKreLU3xgQRBigl6TW/+06CgYeWk6D4joeGPtU4eNqLRizWX7gALAtevorG6pu2Vsb3Aag6MtvibZ1Zey+8qvESNs7NJdf+U2Q0TjXjOn9woMaiJ9ygP8HRB7uP6X6oq2uLhVEGzSJITsBuwPpm49omtFLbvnLnESWLnAX3fmaJ7O6AJWdUpZwiajRAlyJQvs7TvDJBXjVpaTKK3v5l/Ph7b1sdNkFJVkVKj6WalJ5PvJVRX/9PJDwP4Bh2GI4uK50zG5 YQUJiy+T 1YmPNIkUY2fYiyfdsLJ0yY41CLR4HMj5steHc/3Vxzpn2CnfYVMAN30kFkPC2S21QlvmiVcqDXal5Nl1QCr85gdtAphetduc+DQss1ScwZ1lKnf29I85Uqh8I2rKuVbVvfp4PROMi9wXbqVW0Y7rCkUZJEwtUetYUOBxPKEWmJCwxiMbUJc6GzYmQK0h2Ot+iIL3f8ZJd6F316QUngWJGNpPPcdCTr5HI1G54wHCoWiSj2CxNPzb8JifGxIpcfOJ4mN9tPUCVEeDtHF9LU5nfhxHva5pV6qmBr/t9DCGMmWg2ga0pQjVPgUh7QmaKp07GeU0Dsd08/vqHYwsZFR0HyknAG6ZpNW1zWDgUoxqOGi4+89IiiWRy5aMGiBi70C7OkeIOMvqZH6qHOiGlkag6lBsWMhYma7UgqzqUpdW71KGpwzYtmMmfUV49l6f1/lOEt9+vGHZ5vU9Fx/M/75UzZ6eYX0qDSeQK7mloxVzeY0jc6zs6fkbPJ/XhPePDJHwxHqqYOW8okauzJS9PogeZyvyG2uQlFzReAG7QCxTfLGzfNmdMibbnD4dYDNFfJzSXbglderGvPldhcdKUhQc1UkCJKqpUEuXyoa6B2SsCbQfQY57msv8F7yIY0A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Linus, On Mon, Jul 7, 2025 at 8:17=E2=80=AFPM Linus Torvalds wrote: > > On Sun, 6 Jul 2025 at 22:06, Alejandro Colomar wrote: > > > > - p +=3D snprintf(p, ID_STR_LENGTH - (p - name), "%07u", s->size)= ; > > + p =3D seprintf(p, e, "%07u", s->size); > > I am *really* not a fan of introducing yet another random non-standard > string function. > > This 'seprintf' thing really seems to be a completely made-up thing. > Let's not go there. It just adds more confusion - it may be a simpler > interface, but it's another cogniitive load thing, and honestly, that > "beginning and end" interface is not great. > > I think we'd be better off with real "character buffer" interfaces, > and they should be *named* that way, not be yet another "random > character added to the printf family". I was really interested to see this comment because I presented a design for a standard character buffer interface, "strb_t", to WG14 in summer of 2014. The latest published version of that paper is https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3306.pdf (very long) and the slides (which cover most of the important points) are https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3276.pdf I contacted you beforehand, for permission to include kasprintf and kvasprintf in the 'prior art' section of my paper. At the time, you gave me useful information about the history of those and related functions. (As an aside, Alejandro has since written a proposal to standardise a similar function named aprintf, which I support: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3630.txt ) Going back to "strb_t", I did not bother you about it again because I didn't anticipate it being used in kernel space, which has its own interfaces for most things. I'd be interested to hear what you think of it though. My intent was to make it impossible to abuse, insofar as that is possible. That led me to make choices (such as use of an incomplete struct type) that some might consider strange or overengineered. I didn't see the point in trying to replace one set of error-prone functions with another. Alejandro has put a lot of thought into his proposed seprintf function, but it still fundamentally relies on the programmer passing the right arguments and it doesn't seem to extend the functionality of snprintf in any way that I actually need. For example, some of my goals for the character buffer interface were: - A buffer should be specified using a single parameter. - Impossible to accidentally shallow-copy a buffer instead of copying a reference to it. - No aspect of character consumption delegated to character producers, e.g.= : * whether to insert or overwrite. * whether to prepend, insert or append. * whether to allocate extra storage, and how to do that. - Minimize the effect of ignoring return values and not require ubiquitous error-handling. - Able to put strings directly into a buffer from any source. - Allow diverse implementations (mostly to allow tailoring to different platforms). This small program demonstrates some of those ideas: https://godbolt.org/z/66Gnre6dx It uses my ugly hacked-together prototype. Chris