Skip to contentSkip to conversation

Patch "arm64: KVM: Fix stage-2 PGD allocation to have per-page refcounting" has been added to the 3.19-stable tree

PATCH [email protected] 1 participant 1 message May 2, 2015

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

arm64: KVM: Fix stage-2 PGD allocation to have per-page refcounting

to the 3.19-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
arm64-kvm-fix-stage-2-pgd-allocation-to-have-per-page-refcounting.patch
and it can be found in the queue-3.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From a987370f8e7a1677ae385042644326d9cd145a20 Mon Sep 17 00:00:00 2001

From: Marc Zyngier <[email protected]>
Date: Tue, 10 Mar 2015 19:06:59 +0000
Subject: arm64: KVM: Fix stage-2 PGD allocation to have per-page refcounting

From: Marc Zyngier <[email protected]>

commit a987370f8e7a1677ae385042644326d9cd145a20 upstream.

We're using __get_free_pages with to allocate the guest's stage-2 PGD. The standard behaviour of this function is to return a set of pages where only the head page has a valid refcount.

This behaviour gets us into trouble when we're trying to increment the refcount on a non-head page:

page:ffff7c00cfb693c0 count:0 mapcount:0 mapping: (null) index:0x0
flags: 0x4000000000000000()

page dumped because: VM_BUG_ON_PAGE((*({ __attribute__((unused)) typeof((&page->_count)->counter) __var = ( typeof((&page->_count)->counter)) 0; (volatile typeof((&page->_count)->counter) *)&((&page->_count)->counter); })) <= 0)
BUG: failure at include/linux/mm.h:548/get_page()!
Kernel panic - not syncing: BUG!
CPU: 1 PID: 1695 Comm: kvm-vcpu-0 Not tainted 4.0.0-rc1+ #3825
Hardware name: APM X-Gene Mustang board (DT)
Call trace:
[<ffff80000008a09c>] dump_backtrace+0x0/0x13c
[<ffff80000008a1e8>] show_stack+0x10/0x1c
[<ffff800000691da8>] dump_stack+0x74/0x94
[<ffff800000690d78>] panic+0x100/0x240
[<ffff8000000a0bc4>] stage2_get_pmd+0x17c/0x2bc
[<ffff8000000a1dc4>] kvm_handle_guest_abort+0x4b4/0x6b0
[<ffff8000000a420c>] handle_exit+0x58/0x180
[<ffff80000009e7a4>] kvm_arch_vcpu_ioctl_run+0x114/0x45c
[<ffff800000099df4>] kvm_vcpu_ioctl+0x2e0/0x754
[<ffff8000001c0a18>] do_vfs_ioctl+0x424/0x5c8
[<ffff8000001c0bfc>] SyS_ioctl+0x40/0x78

CPU0: stopping

A possible approach for this is to split the compound page using split_page() at allocation time, and change the teardown path to free one page at a time. It turns out that alloc_pages_exact() and free_pages_exact() does exactly that.

While we're at it, the PGD allocation code is reworked to reduce duplication.

This has been tested on an X-Gene platform with a 4kB/48bit-VA host kernel, and kvmtool hacked to place memory in the second page of the hardware PGD (PUD for the host kernel). Also regression-tested on a Cubietruck (Cortex-A7).

[ Reworked to use alloc_pages_exact() and free_pages_exact() and to
return pointers directly instead of by reference as arguments
- Christoffer ]

---
 arch/arm/include/asm/kvm_mmu.h   |   10 ++---
 arch/arm/kvm/mmu.c               |   67 ++++++++++++++++++++++++++++-----------
 arch/arm64/include/asm/kvm_mmu.h |   46 ++------------------------
 3 files changed, 57 insertions(+), 66 deletions(-)
arch/arm/include/asm/kvm_mmu.h +4 -6
@@ -141,16 +141,14 @@ static inline bool kvm_page_empty(void *
 
 #define KVM_PREALLOC_LEVEL	0
 
-static inline int kvm_prealloc_hwpgd(struct kvm *kvm, pgd_t *pgd)
+static inline void *kvm_get_hwpgd(struct kvm *kvm)
 {
-	return 0;
+	return kvm->arch.pgd;
 }
 
-static inline void kvm_free_hwpgd(struct kvm *kvm) { }
-
-static inline void *kvm_get_hwpgd(struct kvm *kvm)
+static inline unsigned int kvm_get_hwpgd_size(void)
 {
-	return kvm->arch.pgd;
+	return PTRS_PER_S2_PGD * sizeof(pgd_t);
 }
 
 struct kvm;
arch/arm/kvm/mmu.c +49 -18

111 lines not on this page · raw message

arch/arm64/include/asm/kvm_mmu.h +4 -42

59 lines not on this page · raw message

Patches currently in stable-queue which might be from [email protected] are

queue-3.19/arm64-kvm-do-not-use-pgd_index-to-index-stage-2-pgd.patch queue-3.19/arm-arm64-kvm-keep-elrsr-aisr-in-sync-with-software-model.patch queue-3.19/kvm-arm-arm64-check-irq-number-on-userland-injection.patch queue-3.19/arm64-kvm-fix-stage-2-pgd-allocation-to-have-per-page-refcounting.patch