Kernel-Janitors Archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: SVM: Remove a useless zeroing of allocated memory
@ 2024-03-09 17:15 Christophe JAILLET
  2024-03-12 18:38 ` Sean Christopherson
  2024-04-10  0:19 ` Sean Christopherson
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2024-03-09 17:15 UTC (permalink / raw
  To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, kvm

Depending of the memory size needed, we clear or not the allocated memory.
This is not consistent.

So remove the zeroing of the memory in the __vmalloc() case.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This is just a guess.

I don't know this code at all, but because of KVM, it is maybe safer to
clear the memory in both cases?
So, maybe it is better to use kzalloc() in the other path.
---
 arch/x86/kvm/svm/sev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 722186601c03..afd9485bef5a 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -434,7 +434,7 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
 	/* Avoid using vmalloc for smaller buffers. */
 	size = npages * sizeof(struct page *);
 	if (size > PAGE_SIZE)
-		pages = __vmalloc(size, GFP_KERNEL_ACCOUNT | __GFP_ZERO);
+		pages = __vmalloc(size, GFP_KERNEL_ACCOUNT);
 	else
 		pages = kmalloc(size, GFP_KERNEL_ACCOUNT);
 
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: SVM: Remove a useless zeroing of allocated memory
  2024-03-09 17:15 [PATCH] KVM: SVM: Remove a useless zeroing of allocated memory Christophe JAILLET
@ 2024-03-12 18:38 ` Sean Christopherson
  2024-04-10  0:19 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2024-03-12 18:38 UTC (permalink / raw
  To: Christophe JAILLET
  Cc: Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, linux-kernel, kernel-janitors,
	kvm

On Sat, Mar 09, 2024, Christophe JAILLET wrote:
> Depending of the memory size needed, we clear or not the allocated memory.
> This is not consistent.
> 
> So remove the zeroing of the memory in the __vmalloc() case.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This is just a guess.
> 
> I don't know this code at all, but because of KVM, it is maybe safer to
> clear the memory in both cases?
> So, maybe it is better to use kzalloc() in the other path.

Not zeroing should be totally fine, the array is only used to hold kernel pointers,
if KVM leaks that state and/or accesses uninitialized data, we have bigger problems :-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: SVM: Remove a useless zeroing of allocated memory
  2024-03-09 17:15 [PATCH] KVM: SVM: Remove a useless zeroing of allocated memory Christophe JAILLET
  2024-03-12 18:38 ` Sean Christopherson
@ 2024-04-10  0:19 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2024-04-10  0:19 UTC (permalink / raw
  To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Christophe JAILLET
  Cc: linux-kernel, kernel-janitors, kvm

On Sat, 09 Mar 2024 18:15:45 +0100, Christophe JAILLET wrote:
> Depending of the memory size needed, we clear or not the allocated memory.
> This is not consistent.
> 
> So remove the zeroing of the memory in the __vmalloc() case.

Applied to kvm-x86 svm, with a massaged changelog to unequivocally state that
not zeroing the memory is a-ok.  Thanks!

[1/1] KVM: SVM: Remove a useless zeroing of allocated memory
      https://github.com/kvm-x86/linux/commit/4710e4fc3e2a

--
https://github.com/kvm-x86/linux/tree/next

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-10  0:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-09 17:15 [PATCH] KVM: SVM: Remove a useless zeroing of allocated memory Christophe JAILLET
2024-03-12 18:38 ` Sean Christopherson
2024-04-10  0:19 ` Sean Christopherson

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 read-only IMAP folder(s) and NNTP newsgroup(s).