dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: "Chang S. Bae" <chang.seok.bae@intel.com>
Cc: x86@kernel.org, herbert@gondor.apana.org.au,
	"David S. Miller" <davem@davemloft.net>,
	ardb@kernel.org, dave.hansen@linux.intel.com,
	dan.j.williams@intel.com, linux-kernel@vger.kernel.org,
	charishma1.gairuboyina@intel.com, mingo@kernel.org,
	lalithambika.krishnakumar@intel.com, dm-devel@redhat.com,
	Ingo Molnar <mingo@redhat.com>,
	bp@alien8.de, linux-crypto@vger.kernel.org, luto@kernel.org,
	"H. Peter Anvin" <hpa@zytor.com>,
	bernie.keany@intel.com, tglx@linutronix.de, nhuck@google.com,
	gmazyland@gmail.com, elliott@hpe.com
Subject: Re: [dm-devel] [PATCH v8 10/12] crypto: x86/aesni - Use the proper data type in struct aesni_xts_ctx
Date: Sun, 4 Jun 2023 19:46:23 -0700	[thread overview]
Message-ID: <20230605024623.GA4653@quark.localdomain> (raw)
In-Reply-To: <0925dd9e-3588-38da-8dfb-0ac2ff568655@intel.com>

On Sun, Jun 04, 2023 at 03:02:32PM -0700, Chang S. Bae wrote:
> On 6/4/2023 8:34 AM, Eric Biggers wrote:
> > 
> > To re-iterate what I said on v6, the runtime alignment to a 16-byte boundary
> > should happen when translating the raw crypto_skcipher_ctx() into the pointer to
> > the aes_xts_ctx.  It should not happen when accessing each individual field in
> > the aes_xts_ctx.
> > 
> > Yet, this code is still doing runtime alignment when accessing each individual
> > field, as the second argument to aes_set_key_common() is 'void *raw_ctx' which
> > aes_set_key_common() runtime-aligns to crypto_aes_ctx.
> > 
> > We should keep everything consistent, which means making aes_set_key_common()
> > take a pointer to crypto_aes_ctx and not do the runtime alignment.
> 
> Let me clarify what is the problem this patch tried to solve here. The
> current struct aesni_xts_ctx is ugly. So, the main story is let's fix it
> before using the code for AES-KL.
> 
> Then, the rework part may be applicable for code re-usability. That seems to
> be okay to do here.
> 
> Fixing the runtime alignment entirely seems to be touching other code than
> AES-XTS. Yes, that's ideal cleanup for consistency. But, it seems to be less
> relevant in this series.  I'd be happy to follow up on that improvement
> though.

IMO the issue is that your patch makes the code (including the XTS code)
inconsistent because it makes it use a mix of both approaches: it aligns each
field individually, *and* it aligns the ctx up-front.  I was hoping to switch
fully from the former approach to the latter approach, instead of switching from
the former approach to a mix of the two approaches as you are proposing.

The following on top of this patch is what I am asking for.  I think it would be
appropriate to fold into this patch.

diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
index 589648142c173..ad1ae7a88b59d 100644
--- a/arch/x86/crypto/aesni-intel_glue.c
+++ b/arch/x86/crypto/aesni-intel_glue.c
@@ -228,10 +228,10 @@ static inline struct aesni_xts_ctx *aes_xts_ctx(struct crypto_skcipher *tfm)
 	return (struct aesni_xts_ctx *)aes_align_addr(crypto_skcipher_ctx(tfm));
 }
 
-static int aes_set_key_common(struct crypto_tfm *tfm, void *raw_ctx,
+static int aes_set_key_common(struct crypto_tfm *tfm,
+			      struct crypto_aes_ctx *ctx,
 			      const u8 *in_key, unsigned int key_len)
 {
-	struct crypto_aes_ctx *ctx = aes_ctx(raw_ctx);
 	int err;
 
 	if (key_len != AES_KEYSIZE_128 && key_len != AES_KEYSIZE_192 &&
@@ -252,7 +252,8 @@ static int aes_set_key_common(struct crypto_tfm *tfm, void *raw_ctx,
 static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
 		       unsigned int key_len)
 {
-	return aes_set_key_common(tfm, crypto_tfm_ctx(tfm), in_key, key_len);
+	return aes_set_key_common(tfm, aes_ctx(crypto_tfm_ctx(tfm)),
+				  in_key, key_len);
 }
 
 static void aesni_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
@@ -285,7 +286,7 @@ static int aesni_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
 			         unsigned int len)
 {
 	return aes_set_key_common(crypto_skcipher_tfm(tfm),
-				  crypto_skcipher_ctx(tfm), key, len);
+				  aes_ctx(crypto_skcipher_ctx(tfm)), key, len);
 }
 
 static int ecb_encrypt(struct skcipher_request *req)

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


  reply	other threads:[~2023-06-05  2:46 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-12 21:12 [dm-devel] [PATCH v5 00/12] x86: Support Key Locker Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 01/12] Documentation/x86: Document " Chang S. Bae
2023-06-05 10:52   ` Bagas Sanjaya
2022-01-12 21:12 ` [dm-devel] [PATCH v5 02/12] x86/cpufeature: Enumerate Key Locker feature Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 03/12] x86/insn: Add Key Locker instructions to the opcode map Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 04/12] x86/asm: Add a wrapper function for the LOADIWKEY instruction Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 05/12] x86/msr-index: Add MSRs for Key Locker internal wrapping key Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 06/12] x86/keylocker: Define Key Locker CPUID leaf Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 07/12] x86/cpu/keylocker: Load an internal wrapping key at boot-time Chang S. Bae
2022-08-23 15:49   ` Evan Green
2022-08-24 22:20     ` Chang S. Bae
2022-08-24 22:52       ` Evan Green
2022-08-25  1:06         ` Chang S. Bae
2022-08-25 15:31           ` Evan Green
2022-08-31 23:08             ` Chang S. Bae
2022-09-06 16:22               ` Evan Green
2022-09-06 16:46                 ` Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 08/12] x86/PM/keylocker: Restore internal wrapping key on resume from ACPI S3/4 Chang S. Bae
2022-01-29 17:31   ` [dm-devel] [PATCH v5-fix " Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 09/12] x86/cpu: Add a configuration and command line option for Key Locker Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 10/12] crypto: x86/aes - Prepare for a new AES implementation Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 11/12] crypto: x86/aes-kl - Support AES algorithm using Key Locker instructions Chang S. Bae
2022-01-12 21:12 ` [dm-devel] [PATCH v5 12/12] crypto: x86/aes-kl - Support XTS mode Chang S. Bae
2022-01-13 22:16 ` [dm-devel] [PATCH v5 00/12] x86: Support Key Locker Dave Hansen
2022-01-13 22:34   ` Bae, Chang Seok
2023-04-10 22:59 ` [dm-devel] [PATCH v6 " Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 01/12] Documentation/x86: Document " Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 02/12] x86/cpufeature: Enumerate Key Locker feature Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 03/12] x86/insn: Add Key Locker instructions to the opcode map Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 04/12] x86/asm: Add a wrapper function for the LOADIWKEY instruction Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 05/12] x86/msr-index: Add MSRs for Key Locker internal wrapping key Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 06/12] x86/keylocker: Define Key Locker CPUID leaf Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 07/12] x86/cpu/keylocker: Load an internal wrapping key at boot-time Chang S. Bae
2023-05-05 23:05     ` Eric Biggers
2023-05-08 18:18       ` Chang S. Bae
2023-05-08 21:56         ` Dave Hansen
2023-05-09  0:31           ` Chang S. Bae
2023-05-09  0:51             ` Dave Hansen
2023-05-08 19:18     ` Elliott, Robert (Servers)
2023-05-08 20:15       ` Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 08/12] x86/PM/keylocker: Restore internal wrapping key on resume from ACPI S3/4 Chang S. Bae
2023-05-05 23:09     ` Eric Biggers
2023-05-08 18:18       ` Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 09/12] x86/cpu: Add a configuration and command line option for Key Locker Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 10/12] crypto: x86/aes - Prepare for a new AES implementation Chang S. Bae
2023-05-05 23:27     ` Eric Biggers
2023-05-09  0:55       ` Chang S. Bae
2023-05-11 19:05         ` Chang S. Bae
2023-05-11 21:39           ` Eric Biggers
2023-05-11 23:19             ` Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 11/12] crypto: x86/aes-kl - Support AES algorithm using Key Locker instructions Chang S. Bae
2023-05-06  0:01     ` Eric Biggers
2023-05-08 18:18       ` Chang S. Bae
2023-05-24 17:18         ` Chang S. Bae
2023-05-12 17:52       ` Milan Broz
2023-05-08 19:21     ` Elliott, Robert (Servers)
2023-05-08 19:24       ` Elliott, Robert (Servers)
2023-05-08 20:00         ` Chang S. Bae
2023-04-10 22:59   ` [dm-devel] [PATCH v6 12/12] crypto: x86/aes-kl - Support XTS mode Chang S. Bae
2023-05-24 16:57   ` [dm-devel] [PATCH v7 00/12] x86: Support Key Locker Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 01/12] Documentation/x86: Document " Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 02/12] x86/cpufeature: Enumerate Key Locker feature Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 03/12] x86/insn: Add Key Locker instructions to the opcode map Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 04/12] x86/asm: Add a wrapper function for the LOADIWKEY instruction Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 05/12] x86/msr-index: Add MSRs for Key Locker wrapping key Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 06/12] x86/keylocker: Define Key Locker CPUID leaf Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 07/12] x86/cpu/keylocker: Load a wrapping key at boot-time Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 08/12] x86/PM/keylocker: Restore the wrapping key on the resume from ACPI S3/4 Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 09/12] x86/cpu: Add a configuration and command line option for Key Locker Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 10/12] crypto: x86/aesni - Use the proper data type in struct aesni_xts_ctx Chang S. Bae
2023-05-26  6:54       ` Eric Biggers
2023-05-30 20:50         ` Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 11/12] crypto: x86/aes - Prepare for a new AES implementation Chang S. Bae
2023-05-24 16:57     ` [dm-devel] [PATCH v7 12/12] crypto: x86/aes-kl - Implement the AES-XTS algorithm Chang S. Bae
2023-05-26  7:23       ` Eric Biggers
2023-05-30 20:49         ` Chang S. Bae
2023-06-03 15:22     ` [dm-devel] [PATCH v8 00/12] x86: Support Key Locker Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 01/12] Documentation/x86: Document " Chang S. Bae
2023-06-05 10:54         ` Bagas Sanjaya
2023-06-06  2:17         ` Randy Dunlap
2023-06-06  4:18           ` Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 02/12] x86/cpufeature: Enumerate Key Locker feature Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 03/12] x86/insn: Add Key Locker instructions to the opcode map Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 04/12] x86/asm: Add a wrapper function for the LOADIWKEY instruction Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 05/12] x86/msr-index: Add MSRs for Key Locker wrapping key Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 06/12] x86/keylocker: Define Key Locker CPUID leaf Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 07/12] x86/cpu/keylocker: Load a wrapping key at boot-time Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 08/12] x86/PM/keylocker: Restore the wrapping key on the resume from ACPI S3/4 Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 09/12] x86/cpu: Add a configuration and command line option for Key Locker Chang S. Bae
2023-06-03 16:37         ` Borislav Petkov
2023-06-04 22:13           ` Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 10/12] crypto: x86/aesni - Use the proper data type in struct aesni_xts_ctx Chang S. Bae
2023-06-04 15:34         ` Eric Biggers
2023-06-04 22:02           ` Chang S. Bae
2023-06-05  2:46             ` Eric Biggers [this message]
2023-06-05  4:41               ` Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 11/12] crypto: x86/aes - Prepare for a new AES-XTS implementation Chang S. Bae
2023-06-03 15:22       ` [dm-devel] [PATCH v8 12/12] crypto: x86/aes-kl - Implement the AES-XTS algorithm Chang S. Bae
2023-06-07  5:35         ` Eric Biggers
2023-06-07 22:06           ` Chang S. Bae

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=20230605024623.GA4653@quark.localdomain \
    --to=ebiggers@kernel.org \
    --cc=ardb@kernel.org \
    --cc=bernie.keany@intel.com \
    --cc=bp@alien8.de \
    --cc=chang.seok.bae@intel.com \
    --cc=charishma1.gairuboyina@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=dm-devel@redhat.com \
    --cc=elliott@hpe.com \
    --cc=gmazyland@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=lalithambika.krishnakumar@intel.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=nhuck@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).