Skip to contentSkip to conversation

KVM: x86: Check for rmaps allocation

PATCH Applied Nikunj A Dadhania 4 participants 6 messages Jan 5, 2022 – Jan 7, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM: x86: Check for rmaps allocation

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.

---

v1: https://lore.kernel.org/kvm/[email protected]/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(+)
arch/x86/kvm/debugfs.c +3 -0
index 543a8c04025c..9240b3b7f8dd 100644
@@ -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++) {
Signature · 1 line
2.32.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 54 lines · Nikunj A Dadhania

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.

---

v1: https://lore.kernel.org/kvm/[email protected]/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(+)
arch/x86/kvm/debugfs.c +3 -0
index 543a8c04025c..9240b3b7f8dd 100644
@@ -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++) {
Signature · 1 line
2.32.0

Thanks,

Signature · 1 line
Peter Xu
maintainer Reviewed-by
#2 lore raw
Quoted 23 lines · Peter Xu
Quoted 22 lines · Nikunj A Dadhania

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
Quoted 6 lines
Quoted 6 lines

Return early when rmaps are not present.

---

maintainer Applied
#3 lore raw
Quoted 24 lines · Sean Christopherson
Quoted 23 lines · Peter Xu
Quoted 22 lines · Nikunj A Dadhania

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
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

Return early when rmaps are not present.

---

Queued, thanks.

paolo

maintainer Applied
#4 lore raw
In reply to Sean Christopherson
Quoted 24 lines · Sean Christopherson
Quoted 23 lines · Peter Xu
Quoted 22 lines · Nikunj A Dadhania

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
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

Return early when rmaps are not present.

---

Queued, thanks.

Paolo

maintainer Applied
#5 lore raw
In reply to Nikunj A Dadhania
Quoted 42 lines · Nikunj A Dadhania

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.

---

v1: https://lore.kernel.org/kvm/[email protected]/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(+)
arch/x86/kvm/debugfs.c +0 -0
index 543a8c04025c..9240b3b7f8dd 100644

arch/x86/kvm/debugfs.c static int kvm_mmu_rmaps_stat_show(struct seq_file *m, void *v) · line 103

Quoted 9 lines
arch/x86/kvm/debugfs.c +3 -0
@@ -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