From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (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 4D557202C29 for ; Mon, 30 Mar 2026 01:00:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774832417; cv=none; b=r+etb4HoESZslHhx+CYQUycI4MmLM5Dw9M9INLpDI07PVTAUZni0OxM2+eJFL9Z5XddHXxaPQV/8h7rzHJXbMpAk5F8TCeM0r0OziGau52X3E7XQ7dyMmj0jNYnanCPxXvR8+diJJRHLbBOinOIV9ZO2uWRYpG4lvehpr0T02DY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774832417; c=relaxed/simple; bh=+J7pPGEUpKBcW+QOzkRfuIByZT9NG9m+m8SvCRtj5Ro=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AwhNhYrJwvp1K6VT+YUgim2Gdb8TMXmTmYPR2xHsCPleZpRus7BqEngrhgm05b0M7KZSYPmI54wPAdjIaSrvWmZRs+KXXMIdljZgG/tV/O/n+PrcQJV41m7ymGnBtuA2oM9MUcsu14tVadcNbsW3e6E4lImrLaIYT1A8mQK33KA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=J/6K/Zgk; arc=none smtp.client-ip=91.218.175.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="J/6K/Zgk" Date: Mon, 30 Mar 2026 02:59:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1774832404; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ugBzSA5QR6FRemSPq+/Fu3zXNcqHwz0L7cwtobdfOIE=; b=J/6K/Zgkjj59VbIaKkxIIILd76+2ykBE5LZBiwUojx2iiWyBUAPvTziCildbmanqoIPcbM zOBYU7MPo5FJmsmbh4tF6PukL0FFvO+SqlICc46kn8egQ33CzrZqBHVfU06WYETK3IDYII l5Y5EMYgLQTth3Y57hYhaQf+TwdVAnY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Thorsten Blum To: Eric Biggers Cc: Tyler Hicks , Christian Brauner , Jeff Layton , Amir Goldstein , Kees Cook , Zipeng Zhang , Chuck Lever , ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ecryptfs: streamline offset formatting in ecryptfs_derive_iv Message-ID: References: <20260329212325.371720-2-thorsten.blum@linux.dev> <20260329220505.GB2106@quark> 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: <20260329220505.GB2106@quark> X-Migadu-Flow: FLOW_OUT 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).