linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] KVM: x86: Check for rmaps allocation
@ 2022-01-05  4:03 Nikunj A Dadhania
  2022-01-05  9:07 ` Peter Xu
  2022-01-07 17:08 ` Paolo Bonzini
  0 siblings, 2 replies; 6+ messages in thread
From: Nikunj A Dadhania @ 2022-01-05  4:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Peter Xu, kvm,
	linux-kernel, nikunj, vasant.hegde, brijesh.singh

With TDP MMU being the default now, access to mmu_rmaps_stat debugfs
file causes following oops:

BUG: kernel NULL pointer dereference, address: 0000000000000000
PGD 0 P4D 0
Oops: 0000 [#1] PREEMPT SMP NOPTI
CPU: 7 PID: 3185 Comm: cat Not tainted 5.16.0-rc4+ #204
RIP: 0010:pte_list_count+0x6/0x40
 Call Trace:
  <TASK>
  ? kvm_mmu_rmaps_stat_show+0x15e/0x320
  seq_read_iter+0x126/0x4b0
  ? aa_file_perm+0x124/0x490
  seq_read+0xf5/0x140
  full_proxy_read+0x5c/0x80
  vfs_read+0x9f/0x1a0
  ksys_read+0x67/0xe0
  __x64_sys_read+0x19/0x20
  do_syscall_64+0x3b/0xc0
  entry_SYSCALL_64_after_hwframe+0x44/0xae
 RIP: 0033:0x7fca6fc13912

Return early when rmaps are not present.

Reported-by: Vasant Hegde <vasant.hegde@amd.com>
Tested-by: Vasant Hegde <vasant.hegde@amd.com>
Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
---

v1: https://lore.kernel.org/kvm/20220104092814.11553-1-nikunj@amd.com/T/#u

Check the rmaps inside kvm_mmu_rmaps_stat_show() as the rmaps can be
allocated dynamically (Peter Xu)

 arch/x86/kvm/debugfs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
index 543a8c04025c..9240b3b7f8dd 100644
--- a/arch/x86/kvm/debugfs.c
+++ b/arch/x86/kvm/debugfs.c
@@ -95,6 +95,9 @@ static int kvm_mmu_rmaps_stat_show(struct seq_file *m, void *v)
 	unsigned int *log[KVM_NR_PAGE_SIZES], *cur;
 	int i, j, k, l, ret;
 
+	if (!kvm_memslots_have_rmaps(kvm))
+		return 0;
+
 	ret = -ENOMEM;
 	memset(log, 0, sizeof(log));
 	for (i = 0; i < KVM_NR_PAGE_SIZES; i++) {
-- 
2.32.0


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

* Re: [PATCH v2] KVM: x86: Check for rmaps allocation
  2022-01-05  4:03 [PATCH v2] KVM: x86: Check for rmaps allocation Nikunj A Dadhania
@ 2022-01-05  9:07 ` Peter Xu
  2022-01-07 17:01   ` Sean Christopherson
  2022-01-07 17:08 ` Paolo Bonzini
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Xu @ 2022-01-05  9:07 UTC (permalink / raw)
  To: Nikunj A Dadhania
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, kvm,
	linux-kernel, vasant.hegde, brijesh.singh

On Wed, Jan 05, 2022 at 09:33:37AM +0530, Nikunj A Dadhania wrote:
> With TDP MMU being the default now, access to mmu_rmaps_stat debugfs
> file causes following oops:
> 
> BUG: kernel NULL pointer dereference, address: 0000000000000000
> PGD 0 P4D 0
> Oops: 0000 [#1] PREEMPT SMP NOPTI
> CPU: 7 PID: 3185 Comm: cat Not tainted 5.16.0-rc4+ #204
> RIP: 0010:pte_list_count+0x6/0x40
>  Call Trace:
>   <TASK>
>   ? kvm_mmu_rmaps_stat_show+0x15e/0x320
>   seq_read_iter+0x126/0x4b0
>   ? aa_file_perm+0x124/0x490
>   seq_read+0xf5/0x140
>   full_proxy_read+0x5c/0x80
>   vfs_read+0x9f/0x1a0
>   ksys_read+0x67/0xe0
>   __x64_sys_read+0x19/0x20
>   do_syscall_64+0x3b/0xc0
>   entry_SYSCALL_64_after_hwframe+0x44/0xae
>  RIP: 0033:0x7fca6fc13912
> 
> Return early when rmaps are not present.
> 
> Reported-by: Vasant Hegde <vasant.hegde@amd.com>
> Tested-by: Vasant Hegde <vasant.hegde@amd.com>
> Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
> ---
> 
> v1: https://lore.kernel.org/kvm/20220104092814.11553-1-nikunj@amd.com/T/#u
> 
> Check the rmaps inside kvm_mmu_rmaps_stat_show() as the rmaps can be
> allocated dynamically (Peter Xu)
> 
>  arch/x86/kvm/debugfs.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
> index 543a8c04025c..9240b3b7f8dd 100644
> --- a/arch/x86/kvm/debugfs.c
> +++ b/arch/x86/kvm/debugfs.c
> @@ -95,6 +95,9 @@ static int kvm_mmu_rmaps_stat_show(struct seq_file *m, void *v)
>  	unsigned int *log[KVM_NR_PAGE_SIZES], *cur;
>  	int i, j, k, l, ret;
>  
> +	if (!kvm_memslots_have_rmaps(kvm))
> +		return 0;
> +
>  	ret = -ENOMEM;
>  	memset(log, 0, sizeof(log));
>  	for (i = 0; i < KVM_NR_PAGE_SIZES; i++) {
> -- 
> 2.32.0
> 

Reviewed-by: Peter Xu <peterx@redhat.com>

Thanks,

-- 
Peter Xu


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

* Re: [PATCH v2] KVM: x86: Check for rmaps allocation
  2022-01-05  9:07 ` Peter Xu
@ 2022-01-07 17:01   ` Sean Christopherson
  2022-01-07 17:03     ` Paolo Bonzini
  2022-01-07 17:04     ` Paolo Bonzini
  0 siblings, 2 replies; 6+ messages in thread
From: Sean Christopherson @ 2022-01-07 17:01 UTC (permalink / raw)
  To: Peter Xu
  Cc: Nikunj A Dadhania, Paolo Bonzini, Vitaly Kuznetsov, kvm,
	linux-kernel, vasant.hegde, brijesh.singh

On Wed, Jan 05, 2022, Peter Xu wrote:
> On Wed, Jan 05, 2022 at 09:33:37AM +0530, Nikunj A Dadhania wrote:
> > With TDP MMU being the default now, access to mmu_rmaps_stat debugfs
> > file causes following oops:
> > 
> > BUG: kernel NULL pointer dereference, address: 0000000000000000
> > PGD 0 P4D 0
> > Oops: 0000 [#1] PREEMPT SMP NOPTI
> > CPU: 7 PID: 3185 Comm: cat Not tainted 5.16.0-rc4+ #204
> > RIP: 0010:pte_list_count+0x6/0x40
> >  Call Trace:
> >   <TASK>
> >   ? kvm_mmu_rmaps_stat_show+0x15e/0x320
> >   seq_read_iter+0x126/0x4b0
> >   ? aa_file_perm+0x124/0x490
> >   seq_read+0xf5/0x140
> >   full_proxy_read+0x5c/0x80
> >   vfs_read+0x9f/0x1a0
> >   ksys_read+0x67/0xe0
> >   __x64_sys_read+0x19/0x20
> >   do_syscall_64+0x3b/0xc0
> >   entry_SYSCALL_64_after_hwframe+0x44/0xae
> >  RIP: 0033:0x7fca6fc13912
> > 
> > Return early when rmaps are not present.
> > 
> > Reported-by: Vasant Hegde <vasant.hegde@amd.com>
> > Tested-by: Vasant Hegde <vasant.hegde@amd.com>
> > Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
> > ---

Reviewed-by: Sean Christopherson <seanjc@google.com>

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

* Re: [PATCH v2] KVM: x86: Check for rmaps allocation
  2022-01-07 17:01   ` Sean Christopherson
@ 2022-01-07 17:03     ` Paolo Bonzini
  2022-01-07 17:04     ` Paolo Bonzini
  1 sibling, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2022-01-07 17:03 UTC (permalink / raw)
  To: Sean Christopherson, Peter Xu
  Cc: Nikunj A Dadhania, Vitaly Kuznetsov, kvm, linux-kernel,
	vasant.hegde, brijesh.singh

On 1/7/22 18:01, Sean Christopherson wrote:
> On Wed, Jan 05, 2022, Peter Xu wrote:
>> On Wed, Jan 05, 2022 at 09:33:37AM +0530, Nikunj A Dadhania wrote:
>>> With TDP MMU being the default now, access to mmu_rmaps_stat debugfs
>>> file causes following oops:
>>>
>>> BUG: kernel NULL pointer dereference, address: 0000000000000000
>>> PGD 0 P4D 0
>>> Oops: 0000 [#1] PREEMPT SMP NOPTI
>>> CPU: 7 PID: 3185 Comm: cat Not tainted 5.16.0-rc4+ #204
>>> RIP: 0010:pte_list_count+0x6/0x40
>>>   Call Trace:
>>>    <TASK>
>>>    ? kvm_mmu_rmaps_stat_show+0x15e/0x320
>>>    seq_read_iter+0x126/0x4b0
>>>    ? aa_file_perm+0x124/0x490
>>>    seq_read+0xf5/0x140
>>>    full_proxy_read+0x5c/0x80
>>>    vfs_read+0x9f/0x1a0
>>>    ksys_read+0x67/0xe0
>>>    __x64_sys_read+0x19/0x20
>>>    do_syscall_64+0x3b/0xc0
>>>    entry_SYSCALL_64_after_hwframe+0x44/0xae
>>>   RIP: 0033:0x7fca6fc13912
>>>
>>> Return early when rmaps are not present.
>>>
>>> Reported-by: Vasant Hegde <vasant.hegde@amd.com>
>>> Tested-by: Vasant Hegde <vasant.hegde@amd.com>
>>> Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
>>> ---
> 
> Reviewed-by: Sean Christopherson <seanjc@google.com>
> 

Queued, thanks.

paolo


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

* Re: [PATCH v2] KVM: x86: Check for rmaps allocation
  2022-01-07 17:01   ` Sean Christopherson
  2022-01-07 17:03     ` Paolo Bonzini
@ 2022-01-07 17:04     ` Paolo Bonzini
  1 sibling, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2022-01-07 17:04 UTC (permalink / raw)
  To: Sean Christopherson, Peter Xu
  Cc: Nikunj A Dadhania, Vitaly Kuznetsov, kvm, linux-kernel,
	vasant.hegde, brijesh.singh

On 1/7/22 18:01, Sean Christopherson wrote:
> On Wed, Jan 05, 2022, Peter Xu wrote:
>> On Wed, Jan 05, 2022 at 09:33:37AM +0530, Nikunj A Dadhania wrote:
>>> With TDP MMU being the default now, access to mmu_rmaps_stat debugfs
>>> file causes following oops:
>>>
>>> BUG: kernel NULL pointer dereference, address: 0000000000000000
>>> PGD 0 P4D 0
>>> Oops: 0000 [#1] PREEMPT SMP NOPTI
>>> CPU: 7 PID: 3185 Comm: cat Not tainted 5.16.0-rc4+ #204
>>> RIP: 0010:pte_list_count+0x6/0x40
>>>   Call Trace:
>>>    <TASK>
>>>    ? kvm_mmu_rmaps_stat_show+0x15e/0x320
>>>    seq_read_iter+0x126/0x4b0
>>>    ? aa_file_perm+0x124/0x490
>>>    seq_read+0xf5/0x140
>>>    full_proxy_read+0x5c/0x80
>>>    vfs_read+0x9f/0x1a0
>>>    ksys_read+0x67/0xe0
>>>    __x64_sys_read+0x19/0x20
>>>    do_syscall_64+0x3b/0xc0
>>>    entry_SYSCALL_64_after_hwframe+0x44/0xae
>>>   RIP: 0033:0x7fca6fc13912
>>>
>>> Return early when rmaps are not present.
>>>
>>> Reported-by: Vasant Hegde <vasant.hegde@amd.com>
>>> Tested-by: Vasant Hegde <vasant.hegde@amd.com>
>>> Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
>>> ---
> 
> Reviewed-by: Sean Christopherson <seanjc@google.com>
> 

Queued, thanks.

Paolo


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

* Re: [PATCH v2] KVM: x86: Check for rmaps allocation
  2022-01-05  4:03 [PATCH v2] KVM: x86: Check for rmaps allocation Nikunj A Dadhania
  2022-01-05  9:07 ` Peter Xu
@ 2022-01-07 17:08 ` Paolo Bonzini
  1 sibling, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2022-01-07 17:08 UTC (permalink / raw)
  To: Nikunj A Dadhania
  Cc: Sean Christopherson, Vitaly Kuznetsov, Peter Xu, kvm,
	linux-kernel, vasant.hegde, brijesh.singh

On 1/5/22 05:03, Nikunj A Dadhania wrote:
> With TDP MMU being the default now, access to mmu_rmaps_stat debugfs
> file causes following oops:
> 
> BUG: kernel NULL pointer dereference, address: 0000000000000000
> PGD 0 P4D 0
> Oops: 0000 [#1] PREEMPT SMP NOPTI
> CPU: 7 PID: 3185 Comm: cat Not tainted 5.16.0-rc4+ #204
> RIP: 0010:pte_list_count+0x6/0x40
>   Call Trace:
>    <TASK>
>    ? kvm_mmu_rmaps_stat_show+0x15e/0x320
>    seq_read_iter+0x126/0x4b0
>    ? aa_file_perm+0x124/0x490
>    seq_read+0xf5/0x140
>    full_proxy_read+0x5c/0x80
>    vfs_read+0x9f/0x1a0
>    ksys_read+0x67/0xe0
>    __x64_sys_read+0x19/0x20
>    do_syscall_64+0x3b/0xc0
>    entry_SYSCALL_64_after_hwframe+0x44/0xae
>   RIP: 0033:0x7fca6fc13912
> 
> Return early when rmaps are not present.
> 
> Reported-by: Vasant Hegde <vasant.hegde@amd.com>
> Tested-by: Vasant Hegde <vasant.hegde@amd.com>
> Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
> ---
> 
> v1: https://lore.kernel.org/kvm/20220104092814.11553-1-nikunj@amd.com/T/#u
> 
> Check the rmaps inside kvm_mmu_rmaps_stat_show() as the rmaps can be
> allocated dynamically (Peter Xu)
> 
>   arch/x86/kvm/debugfs.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
> index 543a8c04025c..9240b3b7f8dd 100644
> --- a/arch/x86/kvm/debugfs.c
> +++ b/arch/x86/kvm/debugfs.c
> @@ -95,6 +95,9 @@ static int kvm_mmu_rmaps_stat_show(struct seq_file *m, void *v)
>   	unsigned int *log[KVM_NR_PAGE_SIZES], *cur;
>   	int i, j, k, l, ret;
>   
> +	if (!kvm_memslots_have_rmaps(kvm))
> +		return 0;
> +
>   	ret = -ENOMEM;
>   	memset(log, 0, sizeof(log));
>   	for (i = 0; i < KVM_NR_PAGE_SIZES; i++) {

Queued, thanks.

Paolo


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

end of thread, other threads:[~2022-01-07 17:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05  4:03 [PATCH v2] KVM: x86: Check for rmaps allocation Nikunj A Dadhania
2022-01-05  9:07 ` Peter Xu
2022-01-07 17:01   ` Sean Christopherson
2022-01-07 17:03     ` Paolo Bonzini
2022-01-07 17:04     ` Paolo Bonzini
2022-01-07 17:08 ` 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).