From: Thorsten Blum <thorsten.blum@linux.dev>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Tyler Hicks <code@tyhicks.com>,
Christian Brauner <brauner@kernel.org>,
Jeff Layton <jlayton@kernel.org>,
Amir Goldstein <amir73il@gmail.com>, Kees Cook <kees@kernel.org>,
Zipeng Zhang <zhangzipeng0@foxmail.com>,
Chuck Lever <chuck.lever@oracle.com>,
ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ecryptfs: streamline offset formatting in ecryptfs_derive_iv
Date: Mon, 30 Mar 2026 02:59:59 +0200 [thread overview]
Message-ID: <acnLDxr4UF1dULrm@linux.dev> (raw)
In-Reply-To: <20260329220505.GB2106@quark>
On Sun, Mar 29, 2026 at 03:05:05PM -0700, Eric Biggers wrote:
> On Sun, Mar 29, 2026 at 11:23:25PM +0200, Thorsten Blum wrote:
> > Use the number of characters written by scnprintf() to zero-pad the
> > remaining bytes, instead of clearing the buffer first and then writing
> > the offset.
> [...]
> > + size_t len;
> [...]
> > memcpy(src, crypt_stat->root_iv, crypt_stat->iv_bytes);
> > - memset((src + crypt_stat->iv_bytes), 0, 16);
> > - snprintf((src + crypt_stat->iv_bytes), 16, "%lld", offset);
> > + len = scnprintf(src + crypt_stat->iv_bytes, 16, "%lld", offset) + 1;
> > + memset(src + crypt_stat->iv_bytes + len, 0, 16 - len);
>
> This isn't exactly "streamlining" the code. memset(p, 0, 16) tends to
> get compiled into just two instructions. In contrast, a variable-length
> memset tends to be several instructions to set up, plus a call
> instruction, and the instructions inside memset() itself. scnprintf()
> is also a few more instructions than snprintf().
>
> So I'd say the old version is more "streamlined", actually. Granted,
> the difference is probably only a few cycles, but it sounds like the
> motivation for this patch is that you assumed the new version is faster?
I meant "streamline" as in write bytes once.
Maybe we should just zero-initialize the 32 bytes in 'src' instead and
keep snprintf(). That removes the need to keep track of 'len' and also
gets rid of the explicit memset(0).
next prev parent reply other threads:[~2026-03-30 1:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 21:23 [PATCH] ecryptfs: streamline offset formatting in ecryptfs_derive_iv Thorsten Blum
2026-03-29 22:05 ` Eric Biggers
2026-03-30 0:59 ` Thorsten Blum [this message]
2026-03-30 7:56 ` Thorsten Blum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=acnLDxr4UF1dULrm@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=code@tyhicks.com \
--cc=ebiggers@kernel.org \
--cc=ecryptfs@vger.kernel.org \
--cc=jlayton@kernel.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=zhangzipeng0@foxmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox