* [PATCH] KVM: MMU: fix an IS_ERR() vs NULL bug
@ 2022-04-01 10:01 Dan Carpenter
2022-04-01 14:04 ` Sean Christopherson
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2022-04-01 10:01 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, kvm, kernel-janitors
The alloc_workqueue() function does not return error pointers, it
returns NULL on error. Update the check accordingly.
Fixes: 1a3320dd2939 ("KVM: MMU: propagate alloc_workqueue failure")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Obviously, I noticed that the patch says "propagate alloc_workqueue
failure" so that's a puzzling thing. Merge issue perhaps? In
linux-next it alloc_workqueue() returns NULL.
arch/x86/kvm/mmu/tdp_mmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index a2f9a34a0168..d71d177ae6b8 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -22,8 +22,8 @@ int kvm_mmu_init_tdp_mmu(struct kvm *kvm)
return 0;
wq = alloc_workqueue("kvm", WQ_UNBOUND|WQ_MEM_RECLAIM|WQ_CPU_INTENSIVE, 0);
- if (IS_ERR(wq))
- return PTR_ERR(wq);
+ if (!wq)
+ return -ENOMEM;
/* This should not be changed for the lifetime of the VM. */
kvm->arch.tdp_mmu_enabled = true;
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: MMU: fix an IS_ERR() vs NULL bug
2022-04-01 10:01 [PATCH] KVM: MMU: fix an IS_ERR() vs NULL bug Dan Carpenter
@ 2022-04-01 14:04 ` Sean Christopherson
2022-04-01 14:06 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2022-04-01 14:04 UTC (permalink / raw)
To: Dan Carpenter
Cc: Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, kvm, kernel-janitors
On Fri, Apr 01, 2022, Dan Carpenter wrote:
> The alloc_workqueue() function does not return error pointers, it
> returns NULL on error. Update the check accordingly.
>
> Fixes: 1a3320dd2939 ("KVM: MMU: propagate alloc_workqueue failure")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
Reviewed-by: Sean Christopherson <seanjc@google.com>
> Obviously, I noticed that the patch says "propagate alloc_workqueue
> failure" so that's a puzzling thing. Merge issue perhaps? In
> linux-next it alloc_workqueue() returns NULL.
No merge issue, just a goof. The "propagate" patch was added because KVM neglected
to check for allocation failure, so at least it was a step in the right direction :-)
> arch/x86/kvm/mmu/tdp_mmu.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index a2f9a34a0168..d71d177ae6b8 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -22,8 +22,8 @@ int kvm_mmu_init_tdp_mmu(struct kvm *kvm)
> return 0;
>
> wq = alloc_workqueue("kvm", WQ_UNBOUND|WQ_MEM_RECLAIM|WQ_CPU_INTENSIVE, 0);
> - if (IS_ERR(wq))
> - return PTR_ERR(wq);
> + if (!wq)
> + return -ENOMEM;
>
> /* This should not be changed for the lifetime of the VM. */
> kvm->arch.tdp_mmu_enabled = true;
> --
Paolo, any objection to also returning '0' in all non-error paths? There's no
need to return whether or not the TDP MMU is enabled since that's handled locally,
and the "return 1" is rather odd.
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index dbf46dd98618..dec32b4a13aa 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -5779,7 +5779,7 @@ int kvm_mmu_init_vm(struct kvm *kvm)
spin_lock_init(&kvm->arch.mmu_unsync_pages_lock);
r = kvm_mmu_init_tdp_mmu(kvm);
- if (r < 0)
+ if (r)
return r;
node->track_write = kvm_mmu_pte_write;
diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index a2f9a34a0168..3a60b999e1aa 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -31,7 +31,7 @@ int kvm_mmu_init_tdp_mmu(struct kvm *kvm)
spin_lock_init(&kvm->arch.tdp_mmu_pages_lock);
INIT_LIST_HEAD(&kvm->arch.tdp_mmu_pages);
kvm->arch.tdp_mmu_zap_wq = wq;
- return 1;
+ return 0;
}
/* Arbitrarily returns true so that this may be used in if statements. */
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: MMU: fix an IS_ERR() vs NULL bug
2022-04-01 14:04 ` Sean Christopherson
@ 2022-04-01 14:06 ` Paolo Bonzini
0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2022-04-01 14:06 UTC (permalink / raw)
To: Sean Christopherson, Dan Carpenter
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, kvm, kernel-janitors
On 4/1/22 16:04, Sean Christopherson wrote:
> Paolo, any objection to also returning '0' in all non-error paths? There's no
> need to return whether or not the TDP MMU is enabled since that's handled locally,
> and the "return 1" is rather odd.
Well, I kept that because I thought there was a hidden reason for that.
At this point I was really about to press Enter and send out the pull
request, so...
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-01 14:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-01 10:01 [PATCH] KVM: MMU: fix an IS_ERR() vs NULL bug Dan Carpenter
2022-04-01 14:04 ` Sean Christopherson
2022-04-01 14:06 ` Paolo Bonzini
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).