Skip to contentSkip to conversation

x86/sev: Remove bogus virtual address check

PATCH In review Ard Biesheuvel 4 participants 10 messages Oct 10, 2025 – Apr 1 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/sev: Remove bogus virtual address check

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

Cc Borislav Petkov (AMD) <[email protected]>
Cc Tom Lendacky <[email protected]>
---
 arch/x86/coco/sev/core.c | 9 ---------
 1 file changed, 9 deletions(-)
arch/x86/coco/sev/core.c +0 -9
index 9ae3b11754e6..c4e2de3687a9 100644
@@ -2249,15 +2249,6 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req
 	u64 seqno;
 	int rc;
 
-	/*
-	 * enc_payload() calls aesgcm_encrypt(), which can potentially offload to HW.
-	 * The offload's DMA SG list of data to encrypt has to be in linear mapping.
-	 */
-	if (!virt_addr_valid(req->req_buf) || !virt_addr_valid(req->resp_buf)) {
-		pr_warn("AES-GSM buffers must be in linear mapping");
-		return -EINVAL;
-	}
-
 	guard(mutex)(&snp_cmd_mutex);
 
 	/* Check if the VMPCK is not empty */
Signature · 1 line
2.51.0.740.g6adb054d12-goog
#1 lore raw

(cc Eric)

Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

Quoted 7 lines
Cc Borislav Petkov (AMD) <[email protected]>
Cc Tom Lendacky <[email protected]>
---
 arch/x86/coco/sev/core.c | 9 ---------
 1 file changed, 9 deletions(-)

Ping?

Quoted 23 lines
arch/x86/coco/sev/core.c +0 -9
index 9ae3b11754e6..c4e2de3687a9 100644
@@ -2249,15 +2249,6 @@ int snp_send_guest_request(struct snp_msg_desc 
 *mdesc, struct snp_guest_req *req
 	u64 seqno;
 	int rc;
 
-	/*
-	 * enc_payload() calls aesgcm_encrypt(), which can potentially offload to HW.
-	 * The offload's DMA SG list of data to encrypt has to be in linear mapping.
-	 */
-	if (!virt_addr_valid(req->req_buf) || !virt_addr_valid(req->resp_buf)) {
-		pr_warn("AES-GSM buffers must be in linear mapping");
-		return -EINVAL;
-	}
-
 	guard(mutex)(&snp_cmd_mutex);
 

/* Check if the VMPCK is not empty */

Signature · 1 line
2.51.0.740.g6adb054d12-goog
maintainer
#2 lore raw
In reply to Ard Biesheuvel
Quoted 24 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

Cc Borislav Petkov (AMD) <[email protected]>
Cc Tom Lendacky <[email protected]>
---
 arch/x86/coco/sev/core.c | 9 ---------
 1 file changed, 9 deletions(-)
arch/x86/coco/sev/core.c +0 -2
index 9ae3b11754e6..c4e2de3687a9 100644
@@ -2249,15 +2249,6 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req
 	u64 seqno;
 	int rc;
 
-	/*
-	 * enc_payload() calls aesgcm_encrypt(), which can potentially offload to HW.

arch/x86/coco/sev/core.c int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req · line 2254

Quoted 10 lines
arch/x86/coco/sev/core.c +0 -7
-	 * The offload's DMA SG list of data to encrypt has to be in linear mapping.
-	 */
-	if (!virt_addr_valid(req->req_buf) || !virt_addr_valid(req->resp_buf)) {
-		pr_warn("AES-GSM buffers must be in linear mapping");
-		return -EINVAL;
-	}
-
 	guard(mutex)(&snp_cmd_mutex);
 
 	/* Check if the VMPCK is not empty */

This came from:

7ffeb2fc2670 ("x86/sev: Document requirement for linear mapping of guest request buffers")

and there was some speculation about the potential of using a crypto accelerator which wants addresses in linear mapping...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw
Quoted 38 lines · Borislav Petkov
Quoted 24 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

Cc Borislav Petkov (AMD) <[email protected]>
Cc Tom Lendacky <[email protected]>
---
 arch/x86/coco/sev/core.c | 9 ---------
 1 file changed, 9 deletions(-)
arch/x86/coco/sev/core.c +0 -2
index 9ae3b11754e6..c4e2de3687a9 100644
@@ -2249,15 +2249,6 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req
 	u64 seqno;
 	int rc;
 
-	/*
-	 * enc_payload() calls aesgcm_encrypt(), which can potentially offload to HW.

arch/x86/coco/sev/core.c int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req · line 2254

Quoted 10 lines
arch/x86/coco/sev/core.c +0 -7
-	 * The offload's DMA SG list of data to encrypt has to be in linear mapping.
-	 */
-	if (!virt_addr_valid(req->req_buf) || !virt_addr_valid(req->resp_buf)) {
-		pr_warn("AES-GSM buffers must be in linear mapping");
-		return -EINVAL;
-	}
-
 	guard(mutex)(&snp_cmd_mutex);
 
 	/* Check if the VMPCK is not empty */

This came from:

Quoted 6 lines

7ffeb2fc2670 ("x86/sev: Document requirement for linear mapping of
guest request buffers")

and there was some speculation about the potential of using a crypto accelerator which wants addresses in linear mapping...

Sure, but that speculation was entirely misguided, so we can remove this again.

#4 lore raw

(add Eric back to cc)

Please keep Eric on cc - I added him for a reason, thanks.

Quoted 47 lines · Ard Biesheuvel
Quoted 38 lines · Borislav Petkov
Quoted 24 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

Cc Borislav Petkov (AMD) <[email protected]>
Cc Tom Lendacky <[email protected]>
---
 arch/x86/coco/sev/core.c | 9 ---------
 1 file changed, 9 deletions(-)
arch/x86/coco/sev/core.c +0 -2
index 9ae3b11754e6..c4e2de3687a9 100644
@@ -2249,15 +2249,6 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req
 	u64 seqno;
 	int rc;
 
-	/*
-	 * enc_payload() calls aesgcm_encrypt(), which can potentially offload to HW.

arch/x86/coco/sev/core.c int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req · line 2254

Quoted 10 lines
arch/x86/coco/sev/core.c +0 -7
-	 * The offload's DMA SG list of data to encrypt has to be in linear mapping.
-	 */
-	if (!virt_addr_valid(req->req_buf) || !virt_addr_valid(req->resp_buf)) {
-		pr_warn("AES-GSM buffers must be in linear mapping");
-		return -EINVAL;
-	}
-
 	guard(mutex)(&snp_cmd_mutex);
 
 	/* Check if the VMPCK is not empty */

This came from:

Quoted 6 lines

7ffeb2fc2670 ("x86/sev: Document requirement for linear mapping of
guest request buffers")

and there was some speculation about the potential of using a crypto accelerator which wants addresses in linear mapping...

Sure, but that speculation was entirely misguided, so we can remove this again.

#5 lore raw
Quoted 47 lines · Ard Biesheuvel

(add Eric back to cc)

Please keep Eric on cc - I added him for a reason, thanks.

Quoted 41 lines · Ard Biesheuvel
Quoted 40 lines · Borislav Petkov
Quoted 24 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

Cc Borislav Petkov (AMD) <[email protected]>
Cc Tom Lendacky <[email protected]>
---
  arch/x86/coco/sev/core.c | 9 ---------
  1 file changed, 9 deletions(-)
arch/x86/coco/sev/core.c +0 -2
index 9ae3b11754e6..c4e2de3687a9 100644
@@ -2249,15 +2249,6 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req
  	u64 seqno;
  	int rc;
 
-	/*
-	 * enc_payload() calls aesgcm_encrypt(), which can potentially offload to HW.

arch/x86/coco/sev/core.c int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req · line 2254

Quoted 10 lines
arch/x86/coco/sev/core.c +0 -7
-	 * The offload's DMA SG list of data to encrypt has to be in linear mapping.
-	 */
-	if (!virt_addr_valid(req->req_buf) || !virt_addr_valid(req->resp_buf)) {
-		pr_warn("AES-GSM buffers must be in linear mapping");
-		return -EINVAL;
-	}
-
  	guard(mutex)(&snp_cmd_mutex);
 
  	/* Check if the VMPCK is not empty */

This came from:

7ffeb2fc2670 ("x86/sev: Document requirement for linear mapping of
guest request buffers")

Nah, this is because of
db10cb9b574675402b virt: sevguest: Fix passing a stack buffer as a scatterlist target

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and there was some speculation about the potential of using a crypto accelerator which wants addresses in linear mapping...

If the pr_warn() above is removed, then we get this BUG_ON back:

===
static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
unsigned int buflen)
{

#ifdef CONFIG_DEBUG_SG
        BUG_ON(!virt_addr_valid(buf));
#endif
        sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
}

===

So if you really insist on removing my pr_warn(), then post a patch removing the BUG_ON too. Thanks,

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Sure, but that speculation was entirely misguided, so we can remove this again.

Signature · 1 line
Alexey
#6 lore raw

[ replying a second time since the first one seems to have evaporated - apologies if you are seeing two replies that look vaguely but not exactly the same]

Quoted 15 lines · Alexey Kardashevskiy
Quoted 14 lines · Ard Biesheuvel

(add Eric back to cc)

Please keep Eric on cc - I added him for a reason, thanks.

Quoted 8 lines · Ard Biesheuvel
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

...

Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This came from:

7ffeb2fc2670 ("x86/sev: Document requirement for linear mapping of guest request buffers")

Nah, this is because of db10cb9b574675402b virt: sevguest: Fix passing a stack buffer as a scatterlist target

Is that change still needed after

f3476bc77057 ("virt: sev-guest: Use AES GCM crypto library")

If not, should we revert db10cb9b574675402b too?

Using the crypto API for simple operations where the algorithm is known at build time was always a mistake. But moving stack allocations to the heap just to placate a clunky API that can only be used meaningfully in an asynchronous manner in the first place is just pointless.

Reviewed-by Tested-by
#7 lore raw
Quoted 27 lines · Ard Biesheuvel

[ replying a second time since the first one seems to have evaporated - apologies if you are seeing two replies that look vaguely but not exactly the same]

Quoted 15 lines · Alexey Kardashevskiy
Quoted 14 lines · Ard Biesheuvel

(add Eric back to cc)

Please keep Eric on cc - I added him for a reason, thanks.

Quoted 8 lines · Ard Biesheuvel
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

...

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This came from:

7ffeb2fc2670 ("x86/sev: Document requirement for linear mapping of guest request buffers")

Quoted 7 lines
Quoted 3 lines

Nah, this is because of db10cb9b574675402b virt: sevguest: Fix passing a stack buffer as a scatterlist target

Is that change still needed after

f3476bc77057 ("virt: sev-guest: Use AES GCM crypto library")

huh. You're right, looks like it is not, I missed that.

Quoted 1 line

If not, should we revert db10cb9b574675402b too?

Nah, we do not want these structures on stack anyway (they might get too big in the future).

Quoted 4 lines

Using the crypto API for simple operations where the algorithm is known at build time was always a mistake. But moving stack allocations to the heap just to placate a clunky API that can only be used meaningfully in an asynchronous manner in the first place is just pointless.

True.

or should I reply with these to the original mail?

Thanks,

Signature · 1 line
Alexey
#8 lore raw
Quoted 44 lines · Alexey Kardashevskiy
Quoted 23 lines · Ard Biesheuvel
Quoted 15 lines · Alexey Kardashevskiy
Quoted 14 lines · Ard Biesheuvel

(add Eric back to cc)

Please keep Eric on cc - I added him for a reason, thanks.

Quoted 8 lines · Ard Biesheuvel
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

...

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This came from:

7ffeb2fc2670 ("x86/sev: Document requirement for linear mapping of guest request buffers")

Quoted 7 lines
Quoted 3 lines

Nah, this is because of db10cb9b574675402b virt: sevguest: Fix passing a stack buffer as a scatterlist target

Is that change still needed after

f3476bc77057 ("virt: sev-guest: Use AES GCM crypto library")

huh. You're right, looks like it is not, I missed that.

Quoted 1 line

If not, should we revert db10cb9b574675402b too?

Nah, we do not want these structures on stack anyway (they might get too big in the future).

Quoted 4 lines

Using the crypto API for simple operations where the algorithm is known at build time was always a mistake. But moving stack allocations to the heap just to placate a clunky API that can only be used meaningfully in an asynchronous manner in the first place is just pointless.

Quoted 7 lines

True.

or should I reply with these to the original mail?

Thanks. I think it should be fine like this.

maintainer
#9 lore raw
Quoted 48 lines · Ard Biesheuvel
Quoted 46 lines · Alexey Kardashevskiy
Quoted 23 lines · Ard Biesheuvel
Quoted 15 lines · Alexey Kardashevskiy
Quoted 14 lines · Ard Biesheuvel

(add Eric back to cc)

Please keep Eric on cc - I added him for a reason, thanks.

Quoted 8 lines · Ard Biesheuvel
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

The AES-GCM crypto library operates strictly on virtual addresses, and never performs any H/W offload, and so calling virt_addr_valid() is not needed.

...

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This came from:

7ffeb2fc2670 ("x86/sev: Document requirement for linear mapping of guest request buffers")

Quoted 7 lines
Quoted 3 lines

Nah, this is because of db10cb9b574675402b virt: sevguest: Fix passing a stack buffer as a scatterlist target

Is that change still needed after

f3476bc77057 ("virt: sev-guest: Use AES GCM crypto library")

huh. You're right, looks like it is not, I missed that.

Quoted 1 line

If not, should we revert db10cb9b574675402b too?

Nah, we do not want these structures on stack anyway (they might get too big in the future).

Quoted 4 lines

Using the crypto API for simple operations where the algorithm is known at build time was always a mistake. But moving stack allocations to the heap just to placate a clunky API that can only be used meaningfully in an asynchronous manner in the first place is just pointless.

True.

Quoted 7 lines
Quoted 5 lines

or should I reply with these to the original mail?

Thanks. I think it should be fine like this.

And now let's invite the folks from

db10cb9b5746 ("virt: sevguest: Fix passing a stack buffer as a scatterlist target")

to the party so that the circle is complete. :-)

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette