All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature
@ 2018-01-16 18:53 Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 01/11] arm/arm64: cleanup alloc.h includes Andrew Jones
                   ` (11 more replies)
  0 siblings, 12 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

The fixes are getting tests to run on 32-bit ARM again and also
fixing virt_to_phys(). The feature is to allow a unit test to start
with the MMU disabled. Couple minor cleanups thrown in too.

I tested x86 and ppc64 over TCG, but not s390 (please-test: David).

Andrew Jones (11):
  arm/arm64: cleanup alloc.h includes
  arm/arm64: add pgtable to thread_info
  arm/arm64: fix virt_to_phys
  arm/arm64: flush page table cache when installing entries
  arm/arm64: setup: don't allow gaps in phys range
  phys_alloc: ensure we account all allocations
  page_alloc: allow initialization before setup_vm call
  page_alloc: add yet another memalign
  lib/auxinfo: add flags field
  arm/arm64: allow setup_vm to be skipped
  arm/arm64: sieve should start with the mmu off

 arm/Makefile.common       |  5 ++++-
 arm/cstart.S              | 19 ++++++++++++++++++-
 arm/cstart64.S            | 17 ++++++++++++++++-
 lib/alloc_page.c          | 33 +++++++++++++++++++++++++++++++++
 lib/alloc_page.h          |  2 ++
 lib/alloc_phys.c          | 10 ++++++++++
 lib/alloc_phys.h          |  6 ++++--
 lib/arm/asm/mmu.h         |  5 +++++
 lib/arm/asm/page.h        |  8 +++-----
 lib/arm/asm/pgtable.h     | 16 ++++++++++++----
 lib/arm/asm/setup.h       |  1 -
 lib/arm/asm/thread_info.h |  1 +
 lib/arm/mmu.c             | 43 ++++++++++++++++++++++++++++++++++++++-----
 lib/arm/processor.c       |  1 +
 lib/arm/setup.c           | 22 ++++++++++++++--------
 lib/arm/smp.c             |  7 ++++++-
 lib/arm64/asm/mmu.h       |  5 +++++
 lib/arm64/asm/page.h      | 10 +++-------
 lib/arm64/asm/pgtable.h   | 12 ++++++++++--
 lib/arm64/processor.c     |  1 +
 lib/arm64/spinlock.c      |  1 +
 lib/auxinfo.c             | 13 ++++++++++++-
 lib/auxinfo.h             |  6 ++++++
 lib/vmalloc.c             |  9 ++++++---
 24 files changed, 211 insertions(+), 42 deletions(-)

-- 
2.13.6

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

* [PATCH kvm-unit-tests 01/11] arm/arm64: cleanup alloc.h includes
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 02/11] arm/arm64: add pgtable to thread_info Andrew Jones
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

It used to be necessary for the phys_addr_t typedef, but now
it doesn't make sense in a few places.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/asm/setup.h  | 1 -
 lib/arm/mmu.c        | 1 -
 lib/arm64/asm/page.h | 2 --
 lib/arm64/spinlock.c | 1 +
 4 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/arm/asm/setup.h b/lib/arm/asm/setup.h
index b0d51f5f0721..42bf9ba8c716 100644
--- a/lib/arm/asm/setup.h
+++ b/lib/arm/asm/setup.h
@@ -6,7 +6,6 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #include <libcflat.h>
-#include <alloc.h>	/* phys_addr_t */
 #include <asm/page.h>
 #include <asm/pgtable-hwdef.h>
 
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index 2e5c993f1e7f..9e420269f1c0 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -12,7 +12,6 @@
 #include <asm/setup.h>
 #include <asm/page.h>
 
-#include "alloc.h"
 #include "alloc_page.h"
 #include "vmalloc.h"
 #include <asm/pgtable-hwdef.h>
diff --git a/lib/arm64/asm/page.h b/lib/arm64/asm/page.h
index 01b4cf664aff..f06a6941971c 100644
--- a/lib/arm64/asm/page.h
+++ b/lib/arm64/asm/page.h
@@ -23,8 +23,6 @@
 
 #define PAGE_ALIGN(addr)	ALIGN(addr, PAGE_SIZE)
 
-#include <alloc.h>
-
 typedef u64 pteval_t;
 typedef u64 pmdval_t;
 typedef u64 pgdval_t;
diff --git a/lib/arm64/spinlock.c b/lib/arm64/spinlock.c
index a3907f03cacd..fac4fc9a7c20 100644
--- a/lib/arm64/spinlock.c
+++ b/lib/arm64/spinlock.c
@@ -5,6 +5,7 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
+#include <libcflat.h>
 #include <asm/spinlock.h>
 #include <asm/barrier.h>
 #include <asm/mmu.h>
-- 
2.13.6

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

* [PATCH kvm-unit-tests 02/11] arm/arm64: add pgtable to thread_info
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 01/11] arm/arm64: cleanup alloc.h includes Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 03/11] arm/arm64: fix virt_to_phys Andrew Jones
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/asm/thread_info.h | 1 +
 lib/arm/mmu.c             | 5 +++--
 lib/arm/processor.c       | 1 +
 lib/arm/smp.c             | 1 +
 lib/arm64/processor.c     | 1 +
 5 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/arm/asm/thread_info.h b/lib/arm/asm/thread_info.h
index c2ecebb47d5a..80ab3954a6b0 100644
--- a/lib/arm/asm/thread_info.h
+++ b/lib/arm/asm/thread_info.h
@@ -47,6 +47,7 @@ static inline void *thread_stack_alloc(void)
 struct thread_info {
 	int cpu;
 	unsigned int flags;
+	void *pgtable;
 #ifdef __arm__
 	exception_fn exception_handlers[EXCPTN_MAX];
 #else
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index 9e420269f1c0..b9387efe0065 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -54,12 +54,13 @@ void mmu_mark_disabled(int cpu)
 extern void asm_mmu_enable(phys_addr_t pgtable);
 void mmu_enable(pgd_t *pgtable)
 {
-	int cpu = current_thread_info()->cpu;
+	struct thread_info *info = current_thread_info();
 
 	asm_mmu_enable(__pa(pgtable));
 	flush_tlb_all();
 
-	mmu_mark_enabled(cpu);
+	info->pgtable = pgtable;
+	mmu_mark_enabled(info->cpu);
 }
 
 extern void asm_mmu_disable(void);
diff --git a/lib/arm/processor.c b/lib/arm/processor.c
index 54fdb87ef019..49e852c06527 100644
--- a/lib/arm/processor.c
+++ b/lib/arm/processor.c
@@ -124,6 +124,7 @@ void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr)
 	sp_usr &= (~7UL); /* stack ptr needs 8-byte alignment */
 
 	thread_info_init(thread_info_sp(sp_usr), TIF_USER_MODE);
+	thread_info_sp(sp_usr)->pgtable = current_thread_info()->pgtable;
 
 	asm volatile(
 		"mrs	r0, cpsr\n"
diff --git a/lib/arm/smp.c b/lib/arm/smp.c
index 3c4e307489b2..27f6fcd07109 100644
--- a/lib/arm/smp.c
+++ b/lib/arm/smp.c
@@ -33,6 +33,7 @@ secondary_entry_fn secondary_cinit(void)
 	secondary_entry_fn entry;
 
 	thread_info_init(ti, 0);
+	ti->pgtable = mmu_idmap;
 	mmu_mark_enabled(ti->cpu);
 
 	/*
diff --git a/lib/arm64/processor.c b/lib/arm64/processor.c
index 165980a97d44..96995ccb7733 100644
--- a/lib/arm64/processor.c
+++ b/lib/arm64/processor.c
@@ -238,6 +238,7 @@ void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr)
 	sp_usr &= (~15UL); /* stack ptr needs 16-byte alignment */
 
 	__thread_info_init(thread_info_sp(sp_usr), TIF_USER_MODE);
+	thread_info_sp(sp_usr)->pgtable = current_thread_info()->pgtable;
 
 	asm volatile(
 		"mov	x0, %0\n"
-- 
2.13.6

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

* [PATCH kvm-unit-tests 03/11] arm/arm64: fix virt_to_phys
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 01/11] arm/arm64: cleanup alloc.h includes Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 02/11] arm/arm64: add pgtable to thread_info Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 04/11] arm/arm64: flush page table cache when installing entries Andrew Jones
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

Since switching to the vm_memalign() allocator virt_to_phys() hasn't
been returning the correct address, as it was assuming an identity map.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/asm/page.h      |  8 +++-----
 lib/arm/asm/pgtable.h   | 16 ++++++++++++----
 lib/arm/mmu.c           | 20 ++++++++++++++++++++
 lib/arm64/asm/page.h    |  8 +++-----
 lib/arm64/asm/pgtable.h | 12 ++++++++++--
 5 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/lib/arm/asm/page.h b/lib/arm/asm/page.h
index fc1b30e95567..039c9f7b3d49 100644
--- a/lib/arm/asm/page.h
+++ b/lib/arm/asm/page.h
@@ -34,16 +34,14 @@ typedef struct { pteval_t pgprot; } pgprot_t;
 #define __pgd(x)		((pgd_t) { (x) } )
 #define __pgprot(x)		((pgprot_t) { (x) } )
 
-#ifndef __virt_to_phys
-#define __phys_to_virt(x)	((unsigned long) (x))
-#define __virt_to_phys(x)	(x)
-#endif
-
 #define __va(x)			((void *)__phys_to_virt((phys_addr_t)(x)))
 #define __pa(x)			__virt_to_phys((unsigned long)(x))
 
 #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
 #define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
 
+extern phys_addr_t __virt_to_phys(unsigned long addr);
+extern unsigned long __phys_to_virt(phys_addr_t addr);
+
 #endif /* !__ASSEMBLY__ */
 #endif /* _ASMARM_PAGE_H_ */
diff --git a/lib/arm/asm/pgtable.h b/lib/arm/asm/pgtable.h
index a95e63002ef3..b614bce9528a 100644
--- a/lib/arm/asm/pgtable.h
+++ b/lib/arm/asm/pgtable.h
@@ -14,6 +14,14 @@
  * This work is licensed under the terms of the GNU GPL, version 2.
  */
 
+/*
+ * We can convert va <=> pa page table addresses with simple casts
+ * because we always allocate their pages with alloc_page(), and
+ * alloc_page() always returns identity mapped pages.
+ */
+#define pgtable_va(x)		((void *)(unsigned long)(x))
+#define pgtable_pa(x)		((unsigned long)(x))
+
 #define pgd_none(pgd)		(!pgd_val(pgd))
 #define pmd_none(pmd)		(!pmd_val(pmd))
 #define pte_none(pte)		(!pte_val(pte))
@@ -32,7 +40,7 @@ static inline pgd_t *pgd_alloc(void)
 
 static inline pmd_t *pgd_page_vaddr(pgd_t pgd)
 {
-	return __va(pgd_val(pgd) & PHYS_MASK & (s32)PAGE_MASK);
+	return pgtable_va(pgd_val(pgd) & PHYS_MASK & (s32)PAGE_MASK);
 }
 
 #define pmd_index(addr) \
@@ -52,14 +60,14 @@ static inline pmd_t *pmd_alloc(pgd_t *pgd, unsigned long addr)
 {
 	if (pgd_none(*pgd)) {
 		pmd_t *pmd = pmd_alloc_one();
-		pgd_val(*pgd) = __pa(pmd) | PMD_TYPE_TABLE;
+		pgd_val(*pgd) = pgtable_pa(pmd) | PMD_TYPE_TABLE;
 	}
 	return pmd_offset(pgd, addr);
 }
 
 static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 {
-	return __va(pmd_val(pmd) & PHYS_MASK & (s32)PAGE_MASK);
+	return pgtable_va(pmd_val(pmd) & PHYS_MASK & (s32)PAGE_MASK);
 }
 
 #define pte_index(addr) \
@@ -79,7 +87,7 @@ static inline pte_t *pte_alloc(pmd_t *pmd, unsigned long addr)
 {
 	if (pmd_none(*pmd)) {
 		pte_t *pte = pte_alloc_one();
-		pmd_val(*pmd) = __pa(pte) | PMD_TYPE_TABLE;
+		pmd_val(*pmd) = pgtable_pa(pte) | PMD_TYPE_TABLE;
 	}
 	return pte_offset(pmd, addr);
 }
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index b9387efe0065..9da3be38b339 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -171,3 +171,23 @@ void *setup_mmu(phys_addr_t phys_end)
 	mmu_enable(mmu_idmap);
 	return mmu_idmap;
 }
+
+phys_addr_t __virt_to_phys(unsigned long addr)
+{
+	if (mmu_enabled()) {
+		pgd_t *pgtable = current_thread_info()->pgtable;
+		return virt_to_pte_phys(pgtable, (void *)addr);
+	}
+	return addr;
+}
+
+unsigned long __phys_to_virt(phys_addr_t addr)
+{
+	/*
+	 * We don't guarantee that phys_to_virt(virt_to_phys(vaddr)) == vaddr, but
+	 * the default page tables do identity map all physical addresses, which
+	 * means phys_to_virt(virt_to_phys((void *)paddr)) == paddr.
+	 */
+	assert(!mmu_enabled() || __virt_to_phys(addr) == addr);
+	return addr;
+}
diff --git a/lib/arm64/asm/page.h b/lib/arm64/asm/page.h
index f06a6941971c..46af552b91c7 100644
--- a/lib/arm64/asm/page.h
+++ b/lib/arm64/asm/page.h
@@ -42,16 +42,14 @@ typedef struct { pgd_t pgd; } pmd_t;
 #define pmd_val(x)		(pgd_val((x).pgd))
 #define __pmd(x)		((pmd_t) { __pgd(x) } )
 
-#ifndef __virt_to_phys
-#define __phys_to_virt(x)	((unsigned long) (x))
-#define __virt_to_phys(x)	(x)
-#endif
-
 #define __va(x)			((void *)__phys_to_virt((phys_addr_t)(x)))
 #define __pa(x)			__virt_to_phys((unsigned long)(x))
 
 #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
 #define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
 
+extern phys_addr_t __virt_to_phys(unsigned long addr);
+extern unsigned long __phys_to_virt(phys_addr_t addr);
+
 #endif /* !__ASSEMBLY__ */
 #endif /* _ASMARM64_PAGE_H_ */
diff --git a/lib/arm64/asm/pgtable.h b/lib/arm64/asm/pgtable.h
index 941a850c3f30..5860abe5b08b 100644
--- a/lib/arm64/asm/pgtable.h
+++ b/lib/arm64/asm/pgtable.h
@@ -18,6 +18,14 @@
 #include <asm/page.h>
 #include <asm/pgtable-hwdef.h>
 
+/*
+ * We can convert va <=> pa page table addresses with simple casts
+ * because we always allocate their pages with alloc_page(), and
+ * alloc_page() always returns identity mapped pages.
+ */
+#define pgtable_va(x)		((void *)(unsigned long)(x))
+#define pgtable_pa(x)		((unsigned long)(x))
+
 #define pgd_none(pgd)		(!pgd_val(pgd))
 #define pmd_none(pmd)		(!pmd_val(pmd))
 #define pte_none(pte)		(!pte_val(pte))
@@ -40,7 +48,7 @@ static inline pgd_t *pgd_alloc(void)
 
 static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 {
-	return __va(pmd_val(pmd) & PHYS_MASK & (s32)PAGE_MASK);
+	return pgtable_va(pmd_val(pmd) & PHYS_MASK & (s32)PAGE_MASK);
 }
 
 #define pte_index(addr) \
@@ -60,7 +68,7 @@ static inline pte_t *pte_alloc(pmd_t *pmd, unsigned long addr)
 {
 	if (pmd_none(*pmd)) {
 		pte_t *pte = pte_alloc_one();
-		pmd_val(*pmd) = __pa(pte) | PMD_TYPE_TABLE;
+		pmd_val(*pmd) = pgtable_pa(pte) | PMD_TYPE_TABLE;
 	}
 	return pte_offset(pmd, addr);
 }
-- 
2.13.6

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

* [PATCH kvm-unit-tests 04/11] arm/arm64: flush page table cache when installing entries
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
                   ` (2 preceding siblings ...)
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 03/11] arm/arm64: fix virt_to_phys Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 05/11] arm/arm64: setup: don't allow gaps in phys range Andrew Jones
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

This fixes the use of non-identity mapped page table entries for
arm32 and AArch32 unit tests.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/asm/mmu.h   |  5 +++++
 lib/arm/mmu.c       | 17 +++++++++++++++--
 lib/arm64/asm/mmu.h |  5 +++++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/lib/arm/asm/mmu.h b/lib/arm/asm/mmu.h
index a31e19cd6652..915c2b07dead 100644
--- a/lib/arm/asm/mmu.h
+++ b/lib/arm/asm/mmu.h
@@ -37,6 +37,11 @@ static inline void flush_tlb_page(unsigned long vaddr)
 	isb();
 }
 
+static inline void flush_dcache_addr(unsigned long vaddr)
+{
+	asm volatile("mcr p15, 0, %0, c7, c14, 1" :: "r" (vaddr));
+}
+
 #include <asm/mmu-api.h>
 
 #endif /* __ASMARM_MMU_H_ */
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index 9da3be38b339..548ec88277bc 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -73,6 +73,17 @@ void mmu_disable(void)
 	asm_mmu_disable();
 }
 
+static void flush_entry(pgd_t *pgtable, uintptr_t vaddr)
+{
+	pgd_t *pgd = pgd_offset(pgtable, vaddr);
+	pmd_t *pmd = pmd_offset(pgd, vaddr);
+
+	flush_dcache_addr((ulong)pgd);
+	flush_dcache_addr((ulong)pmd);
+	flush_dcache_addr((ulong)pte_offset(pmd, vaddr));
+	flush_tlb_page(vaddr);
+}
+
 static pteval_t *get_pte(pgd_t *pgtable, uintptr_t vaddr)
 {
 	pgd_t *pgd = pgd_offset(pgtable, vaddr);
@@ -85,8 +96,9 @@ static pteval_t *get_pte(pgd_t *pgtable, uintptr_t vaddr)
 static pteval_t *install_pte(pgd_t *pgtable, uintptr_t vaddr, pteval_t pte)
 {
 	pteval_t *p_pte = get_pte(pgtable, vaddr);
+
 	*p_pte = pte;
-	flush_tlb_page(vaddr);
+	flush_entry(pgtable, vaddr);
 	return p_pte;
 }
 
@@ -136,8 +148,9 @@ void mmu_set_range_sect(pgd_t *pgtable, uintptr_t virt_offset,
 		pgd_val(*pgd) = paddr;
 		pgd_val(*pgd) |= PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S;
 		pgd_val(*pgd) |= pgprot_val(prot);
+		flush_dcache_addr((ulong)pgd);
+		flush_tlb_page(vaddr);
 	}
-	flush_tlb_all();
 }
 
 void *setup_mmu(phys_addr_t phys_end)
diff --git a/lib/arm64/asm/mmu.h b/lib/arm64/asm/mmu.h
index 9df99cc8871e..fa554b0c20ae 100644
--- a/lib/arm64/asm/mmu.h
+++ b/lib/arm64/asm/mmu.h
@@ -26,6 +26,11 @@ static inline void flush_tlb_page(unsigned long vaddr)
 	dsb(ish);
 }
 
+static inline void flush_dcache_addr(unsigned long vaddr)
+{
+	asm volatile("dc civac, %0" :: "r" (vaddr));
+}
+
 #include <asm/mmu-api.h>
 
 #endif /* __ASMARM64_MMU_H_ */
-- 
2.13.6

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

* [PATCH kvm-unit-tests 05/11] arm/arm64: setup: don't allow gaps in phys range
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
                   ` (3 preceding siblings ...)
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 04/11] arm/arm64: flush page table cache when installing entries Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 06/11] phys_alloc: ensure we account all allocations Andrew Jones
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

Set the basic range parameters PHYS_OFFSET and PHYS_END to the
primary memory region range parameters to ensure there are no
gaps, as the regions in the device tree may not be contiguous.
If a unit test wants to use memory in another region, then it
can get it from mem_regions.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/setup.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index 326e78f15ecd..04169da179bc 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -75,7 +75,7 @@ static void mem_init(phys_addr_t freemem_start)
 	nr_regs = dt_get_memory_params(regs, NR_MEM_REGIONS);
 	assert(nr_regs > 0);
 
-	primary.end = 0;
+	primary = (struct mem_region){ 0 };
 
 	for (i = 0; i < nr_regs; ++i) {
 		mem_regions[i].start = regs[i].addr;
@@ -102,8 +102,8 @@ static void mem_init(phys_addr_t freemem_start)
 	assert(primary.end != 0);
 	assert(!(mem.start & ~PHYS_MASK) && !((mem.end - 1) & ~PHYS_MASK));
 
-	__phys_offset = mem.start;	/* PHYS_OFFSET */
-	__phys_end = mem.end;		/* PHYS_END */
+	__phys_offset = primary.start;	/* PHYS_OFFSET */
+	__phys_end = primary.end;	/* PHYS_END */
 
 	phys_alloc_init(freemem_start, primary.end - freemem_start);
 	phys_alloc_set_minimum_alignment(SMP_CACHE_BYTES);
-- 
2.13.6

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

* [PATCH kvm-unit-tests 06/11] phys_alloc: ensure we account all allocations
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
                   ` (4 preceding siblings ...)
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 05/11] arm/arm64: setup: don't allow gaps in phys range Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 07/11] page_alloc: allow initialization before setup_vm call Andrew Jones
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

Also throw another assert into phys_alloc_aligned_safe.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/alloc_phys.c | 10 ++++++++++
 lib/alloc_phys.h |  6 ++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/alloc_phys.c b/lib/alloc_phys.c
index d09395d1010c..736c3129fc02 100644
--- a/lib/alloc_phys.c
+++ b/lib/alloc_phys.c
@@ -81,6 +81,8 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size,
 	if (safe && sizeof(long) == 4)
 		top_safe = MIN(top_safe, 1ULL << 32);
 
+	assert(base < top_safe);
+
 	addr = ALIGN(base, align);
 	size += addr - base;
 
@@ -116,6 +118,14 @@ void phys_alloc_get_unused(phys_addr_t *p_base, phys_addr_t *p_top)
 {
 	*p_base = base;
 	*p_top = top;
+	if (base == top)
+		return;
+	spin_lock(&lock);
+	regions[nr_regions].base = base;
+	regions[nr_regions].size = top - base;
+	++nr_regions;
+	base = top;
+	spin_unlock(&lock);
 }
 
 static void *early_memalign(size_t alignment, size_t size)
diff --git a/lib/alloc_phys.h b/lib/alloc_phys.h
index 848d3db23a1e..7cf59a661180 100644
--- a/lib/alloc_phys.h
+++ b/lib/alloc_phys.h
@@ -37,8 +37,10 @@ extern void phys_alloc_set_minimum_alignment(phys_addr_t align);
 extern void phys_alloc_show(void);
 
 /*
- * phys_alloc_get_unused returns the addresses for the still-unused part
- * of the initial free memory region passed to phys_alloc_init.
+ * phys_alloc_get_unused allocates all remaining memory from the region
+ * passed to phys_alloc_init, returning the newly allocated memory's base
+ * and top addresses. phys_allo_get_unused will still return base and top
+ * when no free memory is remaining, but base will equal top.
  */
 extern void phys_alloc_get_unused(phys_addr_t *p_base, phys_addr_t *p_top);
 
-- 
2.13.6

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

* [PATCH kvm-unit-tests 07/11] page_alloc: allow initialization before setup_vm call
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
                   ` (5 preceding siblings ...)
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 06/11] phys_alloc: ensure we account all allocations Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 08/11] page_alloc: add yet another memalign Andrew Jones
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/alloc_page.c | 5 +++++
 lib/alloc_page.h | 1 +
 lib/vmalloc.c    | 9 ++++++---
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/alloc_page.c b/lib/alloc_page.c
index f0d46d7ac201..ca11496829a0 100644
--- a/lib/alloc_page.c
+++ b/lib/alloc_page.c
@@ -13,6 +13,11 @@
 static struct spinlock lock;
 static void *freelist = 0;
 
+bool page_alloc_initialized(void)
+{
+	return freelist != 0;
+}
+
 void free_pages(void *mem, unsigned long size)
 {
 	void *old_freelist;
diff --git a/lib/alloc_page.h b/lib/alloc_page.h
index 1884c7a34ffc..1c2b3ec9add6 100644
--- a/lib/alloc_page.h
+++ b/lib/alloc_page.h
@@ -8,6 +8,7 @@
 #ifndef ALLOC_PAGE_H
 #define ALLOC_PAGE_H 1
 
+bool page_alloc_initialized(void);
 void *alloc_page();
 void *alloc_pages(unsigned long order);
 void free_page(void *page);
diff --git a/lib/vmalloc.c b/lib/vmalloc.c
index ca36bf87579a..b583786e2647 100644
--- a/lib/vmalloc.c
+++ b/lib/vmalloc.c
@@ -94,9 +94,12 @@ void setup_vm()
 		return;
 
 	phys_alloc_get_unused(&base, &top);
-	base = (base + PAGE_SIZE - 1) & -PAGE_SIZE;
-	top = top & -PAGE_SIZE;
-	free_pages(phys_to_virt(base), top - base);
+	assert(base != top || page_alloc_initialized());
+	if (!page_alloc_initialized()) {
+		base = (base + PAGE_SIZE - 1) & -PAGE_SIZE;
+		top = top & -PAGE_SIZE;
+		free_pages(phys_to_virt(base), top - base);
+	}
 	page_root = setup_mmu(top);
 	alloc_ops = &vmalloc_ops;
 }
-- 
2.13.6

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

* [PATCH kvm-unit-tests 08/11] page_alloc: add yet another memalign
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
                   ` (6 preceding siblings ...)
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 07/11] page_alloc: allow initialization before setup_vm call Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 09/11] lib/auxinfo: add flags field Andrew Jones
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

If we want both early alloc ops and alloc_page(), then it's best
to just give all the memory to page_alloc and then base the
early alloc ops on that.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/alloc_page.c | 28 ++++++++++++++++++++++++++++
 lib/alloc_page.h |  1 +
 2 files changed, 29 insertions(+)

diff --git a/lib/alloc_page.c b/lib/alloc_page.c
index ca11496829a0..70214e262b1b 100644
--- a/lib/alloc_page.c
+++ b/lib/alloc_page.c
@@ -5,6 +5,7 @@
  * with page granularity.
  */
 #include "libcflat.h"
+#include "alloc.h"
 #include "alloc_phys.h"
 #include <asm/page.h>
 #include <asm/io.h>
@@ -134,3 +135,30 @@ void free_page(void *page)
 	freelist = page;
 	spin_unlock(&lock);
 }
+
+static void *page_memalign(size_t alignment, size_t size)
+{
+	unsigned long order;
+
+	if (!size)
+		return NULL;
+
+	order = 64 - __builtin_clzll(ALIGN(size, PAGE_SIZE) >> PAGE_SHIFT) - 1;
+	return alloc_pages(order);
+}
+
+static void page_free(void *mem, size_t size)
+{
+	free_pages(mem, size);
+}
+
+static struct alloc_ops page_alloc_ops = {
+	.memalign = page_memalign,
+	.free = page_free,
+	.align_min = PAGE_SIZE,
+};
+
+void page_alloc_ops_enable(void)
+{
+	alloc_ops = &page_alloc_ops;
+}
diff --git a/lib/alloc_page.h b/lib/alloc_page.h
index 1c2b3ec9add6..51d48414a47e 100644
--- a/lib/alloc_page.h
+++ b/lib/alloc_page.h
@@ -9,6 +9,7 @@
 #define ALLOC_PAGE_H 1
 
 bool page_alloc_initialized(void);
+void page_alloc_ops_enable(void);
 void *alloc_page();
 void *alloc_pages(unsigned long order);
 void free_page(void *page);
-- 
2.13.6

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

* [PATCH kvm-unit-tests 09/11] lib/auxinfo: add flags field
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
                   ` (7 preceding siblings ...)
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 08/11] page_alloc: add yet another memalign Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 10/11] arm/arm64: allow setup_vm to be skipped Andrew Jones
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/Makefile.common |  3 ++-
 lib/auxinfo.c       | 13 ++++++++++++-
 lib/auxinfo.h       |  1 +
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/arm/Makefile.common b/arm/Makefile.common
index 0a039cff5f94..b4174af6b692 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -22,6 +22,7 @@ all: directories $(tests-all)
 
 ##################################################################
 phys_base = $(LOADADDR)
+AUXFLAGS ?= 0x0
 
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
@@ -69,7 +70,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
 	$(CC) $(LDFLAGS) -o $@ \
 		-Wl,-T,$(SRCDIR)/arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
 		$(filter %.o, $^) $(FLATLIBS) \
-		$(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$(@:.elf=.flat)\"
+		$(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$(@:.elf=.flat)\" -DAUXFLAGS=$(AUXFLAGS)
 
 %.flat: %.elf
 	$(OBJCOPY) -O binary $^ $@
diff --git a/lib/auxinfo.c b/lib/auxinfo.c
index bffeac2f7ecb..a646306364b7 100644
--- a/lib/auxinfo.c
+++ b/lib/auxinfo.c
@@ -1,2 +1,13 @@
 #include "auxinfo.h"
-struct auxinfo auxinfo = { PROGNAME };
+
+#ifndef PROGNAME
+#define PROGNAME ((void *)0)
+#endif
+#ifndef AUXFLAGS
+#define AUXFLAGS 0
+#endif
+
+struct auxinfo auxinfo = {
+	.progname = PROGNAME,
+	.flags = AUXFLAGS,
+};
diff --git a/lib/auxinfo.h b/lib/auxinfo.h
index 669ba5dabefe..c074f43a0b83 100644
--- a/lib/auxinfo.h
+++ b/lib/auxinfo.h
@@ -6,6 +6,7 @@
 #define _AUXINFO_H_
 struct auxinfo {
 	const char *progname;
+	unsigned long flags;
 };
 
 /* No extern!  Define a common symbol.  */
-- 
2.13.6

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

* [PATCH kvm-unit-tests 10/11] arm/arm64: allow setup_vm to be skipped
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
                   ` (8 preceding siblings ...)
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 09/11] lib/auxinfo: add flags field Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 11/11] arm/arm64: sieve should start with the mmu off Andrew Jones
  2018-01-16 19:50 ` [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature David Hildenbrand
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

Determine whether or not to enable the MMU during setup with
an auxinfo flag. This gives unit tests that need to start cpu0
at main() with the MMU off, and no page tables constructed, the
option to do so. The physical page allocator is now used as the
basis for alloc_ops, allowing both malloc() and page_alloc() to
work without a setup_vm() call. The unit test can still call
setup_vm() itself later. Secondaries will also start in their
entry points with the MMU off. If page tables have already been
constructed by another CPU, and are pointed to by e.g. 'pgtable',
then the secondary can easily enable the MMU with
mmu_enable(pgtable).

Naturally unit tests that start multiple CPUs with the MMU off
need to keep track of each CPU's MMU enable status and which set
of ops are pointed to by alloc_ops. Also note, spinlocks may not
work as expected with the MMU off. IOW, this option gives a unit
test plenty of rope to shoot itself with.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/cstart.S    | 19 ++++++++++++++++++-
 arm/cstart64.S  | 17 ++++++++++++++++-
 lib/arm/setup.c | 16 +++++++++++-----
 lib/arm/smp.c   |  8 ++++++--
 lib/auxinfo.h   |  5 +++++
 5 files changed, 56 insertions(+), 9 deletions(-)

diff --git a/arm/cstart.S b/arm/cstart.S
index 86d879ec7b35..114726feab82 100644
--- a/arm/cstart.S
+++ b/arm/cstart.S
@@ -6,6 +6,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #define __ASSEMBLY__
+#include <auxinfo.h>
 #include <asm/thread_info.h>
 #include <asm/asm-offsets.h>
 #include <asm/ptrace.h>
@@ -57,7 +58,12 @@ start:
 	/* complete setup */
 	pop	{r0-r1}
 	bl	setup
+	bl	get_mmu_off
+	cmp	r0, #0
+	bne	1f
+	bl	setup_vm
 
+1:
 	/* run the test */
 	ldr	r0, =__argc
 	ldr	r0, [r0]
@@ -96,14 +102,25 @@ exceptions_init:
 
 .text
 
+.global get_mmu_off
+get_mmu_off:
+	ldr	r0, =auxinfo
+	ldr	r0, [r0, #4]
+	and	r0, #AUXINFO_MMU_OFF
+	mov	pc, lr
+
 .global secondary_entry
 secondary_entry:
-	/* enable the MMU */
+	/* enable the MMU unless requested off */
+	bl	get_mmu_off
+	cmp	r0, #0
+	bne	1f
 	mov	r1, #0
 	ldr	r0, =mmu_idmap
 	ldr	r0, [r0]
 	bl	asm_mmu_enable
 
+1:
 	/*
 	 * Set the stack, and set up vector table
 	 * and exception stacks. Exception stacks
diff --git a/arm/cstart64.S b/arm/cstart64.S
index 0a2658746a4d..cbb4fb65683d 100644
--- a/arm/cstart64.S
+++ b/arm/cstart64.S
@@ -6,6 +6,7 @@
  * This work is licensed under the terms of the GNU GPL, version 2.
  */
 #define __ASSEMBLY__
+#include <auxinfo.h>
 #include <asm/asm-offsets.h>
 #include <asm/ptrace.h>
 #include <asm/processor.h>
@@ -38,7 +39,11 @@ start:
 	/* complete setup */
 	ldp	x0, x1, [sp], #16
 	bl	setup
+	bl	get_mmu_off
+	cbnz	x0, 1f
+	bl	setup_vm
 
+1:
 	/* run the test */
 	adrp	x0, __argc
 	ldr	x0, [x0, :lo12:__argc]
@@ -59,6 +64,13 @@ exceptions_init:
 
 .text
 
+.globl get_mmu_off
+get_mmu_off:
+	adrp	x0, auxinfo
+	ldr	x0, [x0, :lo12:auxinfo + 8]
+	and	x0, x0, #AUXINFO_MMU_OFF
+	ret
+
 .globl secondary_entry
 secondary_entry:
 	/* Enable FP/ASIMD */
@@ -68,11 +80,14 @@ secondary_entry:
 	/* set up exception handling */
 	bl	exceptions_init
 
-	/* enable the MMU */
+	/* enable the MMU unless requested off */
+	bl	get_mmu_off
+	cbnz	x0, 1f
 	adrp	x0, mmu_idmap
 	ldr	x0, [x0, :lo12:mmu_idmap]
 	bl	asm_mmu_enable
 
+1:
 	/* set the stack */
 	adrp	x0, secondary_data
 	ldr	x0, [x0, :lo12:secondary_data]
diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index 04169da179bc..d9458a888b55 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -15,11 +15,11 @@
 #include <devicetree.h>
 #include <alloc.h>
 #include <alloc_phys.h>
+#include <alloc_page.h>
 #include <argv.h>
 #include <asm/thread_info.h>
 #include <asm/setup.h>
 #include <asm/page.h>
-#include <asm/mmu.h>
 #include <asm/smp.h>
 
 extern unsigned long stacktop;
@@ -70,6 +70,7 @@ static void mem_init(phys_addr_t freemem_start)
 	struct mem_region primary, mem = {
 		.start = (phys_addr_t)-1,
 	};
+	phys_addr_t base, top;
 	int nr_regs, i;
 
 	nr_regs = dt_get_memory_params(regs, NR_MEM_REGIONS);
@@ -108,7 +109,14 @@ static void mem_init(phys_addr_t freemem_start)
 	phys_alloc_init(freemem_start, primary.end - freemem_start);
 	phys_alloc_set_minimum_alignment(SMP_CACHE_BYTES);
 
-	setup_vm();
+	phys_alloc_get_unused(&base, &top);
+	base = PAGE_ALIGN(base);
+	top = top & PAGE_MASK;
+	assert(sizeof(long) == 8 || !(base >> 32));
+	if (sizeof(long) != 8 && (top >> 32) != 0)
+		top = ((uint64_t)1 << 32);
+	free_pages((void *)(unsigned long)base, top - base);
+	page_alloc_ops_enable();
 }
 
 void setup(const void *fdt)
@@ -156,14 +164,12 @@ void setup(const void *fdt)
 	}
 
 	/* call init functions */
+	mem_init(PAGE_ALIGN((unsigned long)freemem));
 	cpu_init();
 
 	/* cpu_init must be called before thread_info_init */
 	thread_info_init(current_thread_info(), 0);
 
-	/* thread_info_init must be called before mem_init */
-	mem_init(PAGE_ALIGN((unsigned long)freemem));
-
 	/* mem_init must be called before io_init */
 	io_init();
 
diff --git a/lib/arm/smp.c b/lib/arm/smp.c
index 27f6fcd07109..3a4151e2da12 100644
--- a/lib/arm/smp.c
+++ b/lib/arm/smp.c
@@ -6,6 +6,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #include <libcflat.h>
+#include <auxinfo.h>
 #include <asm/thread_info.h>
 #include <asm/spinlock.h>
 #include <asm/cpumask.h>
@@ -33,8 +34,11 @@ secondary_entry_fn secondary_cinit(void)
 	secondary_entry_fn entry;
 
 	thread_info_init(ti, 0);
-	ti->pgtable = mmu_idmap;
-	mmu_mark_enabled(ti->cpu);
+
+	if (!(auxinfo.flags & AUXINFO_MMU_OFF)) {
+		ti->pgtable = mmu_idmap;
+		mmu_mark_enabled(ti->cpu);
+	}
 
 	/*
 	 * Save secondary_data.entry locally to avoid opening a race
diff --git a/lib/auxinfo.h b/lib/auxinfo.h
index c074f43a0b83..08b96f8ece4c 100644
--- a/lib/auxinfo.h
+++ b/lib/auxinfo.h
@@ -4,6 +4,10 @@
  */
 #ifndef _AUXINFO_H_
 #define _AUXINFO_H_
+
+#define AUXINFO_MMU_OFF (1 << 0)
+
+#ifndef __ASSEMBLY__
 struct auxinfo {
 	const char *progname;
 	unsigned long flags;
@@ -12,3 +16,4 @@ struct auxinfo {
 /* No extern!  Define a common symbol.  */
 struct auxinfo auxinfo;
 #endif
+#endif
-- 
2.13.6

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

* [PATCH kvm-unit-tests 11/11] arm/arm64: sieve should start with the mmu off
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
                   ` (9 preceding siblings ...)
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 10/11] arm/arm64: allow setup_vm to be skipped Andrew Jones
@ 2018-01-16 18:53 ` Andrew Jones
  2018-01-16 19:50 ` [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature David Hildenbrand
  11 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-16 18:53 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, cdall, david, lvivier, thuth

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/Makefile.common | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arm/Makefile.common b/arm/Makefile.common
index b4174af6b692..1cf9cdcf078e 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -20,6 +20,8 @@ tests-common += $(TEST_DIR)/sieve.flat
 tests-all = $(tests-common) $(tests)
 all: directories $(tests-all)
 
+$(TEST_DIR)/sieve.elf: AUXFLAGS = 0x1
+
 ##################################################################
 phys_base = $(LOADADDR)
 AUXFLAGS ?= 0x0
-- 
2.13.6

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

* Re: [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature
  2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
                   ` (10 preceding siblings ...)
  2018-01-16 18:53 ` [PATCH kvm-unit-tests 11/11] arm/arm64: sieve should start with the mmu off Andrew Jones
@ 2018-01-16 19:50 ` David Hildenbrand
  2018-01-17  9:12   ` Andrew Jones
  11 siblings, 1 reply; 16+ messages in thread
From: David Hildenbrand @ 2018-01-16 19:50 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: pbonzini, rkrcmar, cdall, lvivier, thuth

On 16.01.2018 19:53, Andrew Jones wrote:
> The fixes are getting tests to run on 32-bit ARM again and also
> fixing virt_to_phys(). The feature is to allow a unit test to start
> with the MMU disabled. Couple minor cleanups thrown in too.
> 
> I tested x86 and ppc64 over TCG, but not s390 (please-test: David).
> 
> Andrew Jones (11):
>   arm/arm64: cleanup alloc.h includes
>   arm/arm64: add pgtable to thread_info
>   arm/arm64: fix virt_to_phys
>   arm/arm64: flush page table cache when installing entries
>   arm/arm64: setup: don't allow gaps in phys range
>   phys_alloc: ensure we account all allocations
>   page_alloc: allow initialization before setup_vm call
>   page_alloc: add yet another memalign
>   lib/auxinfo: add flags field
>   arm/arm64: allow setup_vm to be skipped
>   arm/arm64: sieve should start with the mmu off
> 
>  arm/Makefile.common       |  5 ++++-
>  arm/cstart.S              | 19 ++++++++++++++++++-
>  arm/cstart64.S            | 17 ++++++++++++++++-
>  lib/alloc_page.c          | 33 +++++++++++++++++++++++++++++++++
>  lib/alloc_page.h          |  2 ++
>  lib/alloc_phys.c          | 10 ++++++++++
>  lib/alloc_phys.h          |  6 ++++--
>  lib/arm/asm/mmu.h         |  5 +++++
>  lib/arm/asm/page.h        |  8 +++-----
>  lib/arm/asm/pgtable.h     | 16 ++++++++++++----
>  lib/arm/asm/setup.h       |  1 -
>  lib/arm/asm/thread_info.h |  1 +
>  lib/arm/mmu.c             | 43 ++++++++++++++++++++++++++++++++++++++-----
>  lib/arm/processor.c       |  1 +
>  lib/arm/setup.c           | 22 ++++++++++++++--------
>  lib/arm/smp.c             |  7 ++++++-
>  lib/arm64/asm/mmu.h       |  5 +++++
>  lib/arm64/asm/page.h      | 10 +++-------
>  lib/arm64/asm/pgtable.h   | 12 ++++++++++--
>  lib/arm64/processor.c     |  1 +
>  lib/arm64/spinlock.c      |  1 +
>  lib/auxinfo.c             | 13 ++++++++++++-
>  lib/auxinfo.h             |  6 ++++++
>  lib/vmalloc.c             |  9 ++++++---
>  24 files changed, 211 insertions(+), 42 deletions(-)
> 

lib/libcflat.a(alloc_page.o): In function `page_memalign':
/home/dhildenb/git/kvm-unit-tests/lib/alloc_page.c:146: undefined
reference to `__clzdi2'
collect2: error: ld returned 1 exit status
make: *** [/home/dhildenb/git/kvm-unit-tests/s390x/Makefile:44:
s390x/selftest.elf] Error 1


-- 

Thanks,

David / dhildenb

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

* Re: [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature
  2018-01-16 19:50 ` [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature David Hildenbrand
@ 2018-01-17  9:12   ` Andrew Jones
  2018-01-17  9:16     ` David Hildenbrand
  0 siblings, 1 reply; 16+ messages in thread
From: Andrew Jones @ 2018-01-17  9:12 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: kvm, pbonzini, rkrcmar, cdall, lvivier, thuth

On Tue, Jan 16, 2018 at 08:50:27PM +0100, David Hildenbrand wrote:
> On 16.01.2018 19:53, Andrew Jones wrote:
> > The fixes are getting tests to run on 32-bit ARM again and also
> > fixing virt_to_phys(). The feature is to allow a unit test to start
> > with the MMU disabled. Couple minor cleanups thrown in too.
> > 
> > I tested x86 and ppc64 over TCG, but not s390 (please-test: David).
> > 
> > Andrew Jones (11):
> >   arm/arm64: cleanup alloc.h includes
> >   arm/arm64: add pgtable to thread_info
> >   arm/arm64: fix virt_to_phys
> >   arm/arm64: flush page table cache when installing entries
> >   arm/arm64: setup: don't allow gaps in phys range
> >   phys_alloc: ensure we account all allocations
> >   page_alloc: allow initialization before setup_vm call
> >   page_alloc: add yet another memalign
> >   lib/auxinfo: add flags field
> >   arm/arm64: allow setup_vm to be skipped
> >   arm/arm64: sieve should start with the mmu off
> > 
> >  arm/Makefile.common       |  5 ++++-
> >  arm/cstart.S              | 19 ++++++++++++++++++-
> >  arm/cstart64.S            | 17 ++++++++++++++++-
> >  lib/alloc_page.c          | 33 +++++++++++++++++++++++++++++++++
> >  lib/alloc_page.h          |  2 ++
> >  lib/alloc_phys.c          | 10 ++++++++++
> >  lib/alloc_phys.h          |  6 ++++--
> >  lib/arm/asm/mmu.h         |  5 +++++
> >  lib/arm/asm/page.h        |  8 +++-----
> >  lib/arm/asm/pgtable.h     | 16 ++++++++++++----
> >  lib/arm/asm/setup.h       |  1 -
> >  lib/arm/asm/thread_info.h |  1 +
> >  lib/arm/mmu.c             | 43 ++++++++++++++++++++++++++++++++++++++-----
> >  lib/arm/processor.c       |  1 +
> >  lib/arm/setup.c           | 22 ++++++++++++++--------
> >  lib/arm/smp.c             |  7 ++++++-
> >  lib/arm64/asm/mmu.h       |  5 +++++
> >  lib/arm64/asm/page.h      | 10 +++-------
> >  lib/arm64/asm/pgtable.h   | 12 ++++++++++--
> >  lib/arm64/processor.c     |  1 +
> >  lib/arm64/spinlock.c      |  1 +
> >  lib/auxinfo.c             | 13 ++++++++++++-
> >  lib/auxinfo.h             |  6 ++++++
> >  lib/vmalloc.c             |  9 ++++++---
> >  24 files changed, 211 insertions(+), 42 deletions(-)
> > 
> 
> lib/libcflat.a(alloc_page.o): In function `page_memalign':
> /home/dhildenb/git/kvm-unit-tests/lib/alloc_page.c:146: undefined
> reference to `__clzdi2'
> collect2: error: ld returned 1 exit status
> make: *** [/home/dhildenb/git/kvm-unit-tests/s390x/Makefile:44:
> s390x/selftest.elf] Error 1
>

Eh, I guess the s390 compiler doesn't have that builtin. I should
properly add an fls() to asm/bitops.h for each arch then. s390 can
use a generic implementation, like the kernel's generic binary search,
__fls.

Thanks,
drew

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

* Re: [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature
  2018-01-17  9:12   ` Andrew Jones
@ 2018-01-17  9:16     ` David Hildenbrand
  2018-01-17 10:41       ` Andrew Jones
  0 siblings, 1 reply; 16+ messages in thread
From: David Hildenbrand @ 2018-01-17  9:16 UTC (permalink / raw)
  To: Andrew Jones; +Cc: kvm, pbonzini, rkrcmar, cdall, lvivier, thuth

On 17.01.2018 10:12, Andrew Jones wrote:
> On Tue, Jan 16, 2018 at 08:50:27PM +0100, David Hildenbrand wrote:
>> On 16.01.2018 19:53, Andrew Jones wrote:
>>> The fixes are getting tests to run on 32-bit ARM again and also
>>> fixing virt_to_phys(). The feature is to allow a unit test to start
>>> with the MMU disabled. Couple minor cleanups thrown in too.
>>>
>>> I tested x86 and ppc64 over TCG, but not s390 (please-test: David).
>>>
>>> Andrew Jones (11):
>>>   arm/arm64: cleanup alloc.h includes
>>>   arm/arm64: add pgtable to thread_info
>>>   arm/arm64: fix virt_to_phys
>>>   arm/arm64: flush page table cache when installing entries
>>>   arm/arm64: setup: don't allow gaps in phys range
>>>   phys_alloc: ensure we account all allocations
>>>   page_alloc: allow initialization before setup_vm call
>>>   page_alloc: add yet another memalign
>>>   lib/auxinfo: add flags field
>>>   arm/arm64: allow setup_vm to be skipped
>>>   arm/arm64: sieve should start with the mmu off
>>>
>>>  arm/Makefile.common       |  5 ++++-
>>>  arm/cstart.S              | 19 ++++++++++++++++++-
>>>  arm/cstart64.S            | 17 ++++++++++++++++-
>>>  lib/alloc_page.c          | 33 +++++++++++++++++++++++++++++++++
>>>  lib/alloc_page.h          |  2 ++
>>>  lib/alloc_phys.c          | 10 ++++++++++
>>>  lib/alloc_phys.h          |  6 ++++--
>>>  lib/arm/asm/mmu.h         |  5 +++++
>>>  lib/arm/asm/page.h        |  8 +++-----
>>>  lib/arm/asm/pgtable.h     | 16 ++++++++++++----
>>>  lib/arm/asm/setup.h       |  1 -
>>>  lib/arm/asm/thread_info.h |  1 +
>>>  lib/arm/mmu.c             | 43 ++++++++++++++++++++++++++++++++++++++-----
>>>  lib/arm/processor.c       |  1 +
>>>  lib/arm/setup.c           | 22 ++++++++++++++--------
>>>  lib/arm/smp.c             |  7 ++++++-
>>>  lib/arm64/asm/mmu.h       |  5 +++++
>>>  lib/arm64/asm/page.h      | 10 +++-------
>>>  lib/arm64/asm/pgtable.h   | 12 ++++++++++--
>>>  lib/arm64/processor.c     |  1 +
>>>  lib/arm64/spinlock.c      |  1 +
>>>  lib/auxinfo.c             | 13 ++++++++++++-
>>>  lib/auxinfo.h             |  6 ++++++
>>>  lib/vmalloc.c             |  9 ++++++---
>>>  24 files changed, 211 insertions(+), 42 deletions(-)
>>>
>>
>> lib/libcflat.a(alloc_page.o): In function `page_memalign':
>> /home/dhildenb/git/kvm-unit-tests/lib/alloc_page.c:146: undefined
>> reference to `__clzdi2'
>> collect2: error: ld returned 1 exit status
>> make: *** [/home/dhildenb/git/kvm-unit-tests/s390x/Makefile:44:
>> s390x/selftest.elf] Error 1
>>
> 
> Eh, I guess the s390 compiler doesn't have that builtin. I should
> properly add an fls() to asm/bitops.h for each arch then. s390 can
> use a generic implementation, like the kernel's generic binary search,
> __fls.

I wonder if that is a compiler bug. Will try with an older (!cross)
compiler.

> 
> Thanks,
> drew
> 


-- 

Thanks,

David / dhildenb

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

* Re: [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature
  2018-01-17  9:16     ` David Hildenbrand
@ 2018-01-17 10:41       ` Andrew Jones
  0 siblings, 0 replies; 16+ messages in thread
From: Andrew Jones @ 2018-01-17 10:41 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: kvm, pbonzini, rkrcmar, cdall, lvivier, thuth

On Wed, Jan 17, 2018 at 10:16:43AM +0100, David Hildenbrand wrote:
> On 17.01.2018 10:12, Andrew Jones wrote:
> > On Tue, Jan 16, 2018 at 08:50:27PM +0100, David Hildenbrand wrote:
> >> On 16.01.2018 19:53, Andrew Jones wrote:
> >>> The fixes are getting tests to run on 32-bit ARM again and also
> >>> fixing virt_to_phys(). The feature is to allow a unit test to start
> >>> with the MMU disabled. Couple minor cleanups thrown in too.
> >>>
> >>> I tested x86 and ppc64 over TCG, but not s390 (please-test: David).
> >>>
> >>> Andrew Jones (11):
> >>>   arm/arm64: cleanup alloc.h includes
> >>>   arm/arm64: add pgtable to thread_info
> >>>   arm/arm64: fix virt_to_phys
> >>>   arm/arm64: flush page table cache when installing entries
> >>>   arm/arm64: setup: don't allow gaps in phys range
> >>>   phys_alloc: ensure we account all allocations
> >>>   page_alloc: allow initialization before setup_vm call
> >>>   page_alloc: add yet another memalign
> >>>   lib/auxinfo: add flags field
> >>>   arm/arm64: allow setup_vm to be skipped
> >>>   arm/arm64: sieve should start with the mmu off
> >>>
> >>>  arm/Makefile.common       |  5 ++++-
> >>>  arm/cstart.S              | 19 ++++++++++++++++++-
> >>>  arm/cstart64.S            | 17 ++++++++++++++++-
> >>>  lib/alloc_page.c          | 33 +++++++++++++++++++++++++++++++++
> >>>  lib/alloc_page.h          |  2 ++
> >>>  lib/alloc_phys.c          | 10 ++++++++++
> >>>  lib/alloc_phys.h          |  6 ++++--
> >>>  lib/arm/asm/mmu.h         |  5 +++++
> >>>  lib/arm/asm/page.h        |  8 +++-----
> >>>  lib/arm/asm/pgtable.h     | 16 ++++++++++++----
> >>>  lib/arm/asm/setup.h       |  1 -
> >>>  lib/arm/asm/thread_info.h |  1 +
> >>>  lib/arm/mmu.c             | 43 ++++++++++++++++++++++++++++++++++++++-----
> >>>  lib/arm/processor.c       |  1 +
> >>>  lib/arm/setup.c           | 22 ++++++++++++++--------
> >>>  lib/arm/smp.c             |  7 ++++++-
> >>>  lib/arm64/asm/mmu.h       |  5 +++++
> >>>  lib/arm64/asm/page.h      | 10 +++-------
> >>>  lib/arm64/asm/pgtable.h   | 12 ++++++++++--
> >>>  lib/arm64/processor.c     |  1 +
> >>>  lib/arm64/spinlock.c      |  1 +
> >>>  lib/auxinfo.c             | 13 ++++++++++++-
> >>>  lib/auxinfo.h             |  6 ++++++
> >>>  lib/vmalloc.c             |  9 ++++++---
> >>>  24 files changed, 211 insertions(+), 42 deletions(-)
> >>>
> >>
> >> lib/libcflat.a(alloc_page.o): In function `page_memalign':
> >> /home/dhildenb/git/kvm-unit-tests/lib/alloc_page.c:146: undefined
> >> reference to `__clzdi2'
> >> collect2: error: ld returned 1 exit status
> >> make: *** [/home/dhildenb/git/kvm-unit-tests/s390x/Makefile:44:
> >> s390x/selftest.elf] Error 1
> >>
> > 
> > Eh, I guess the s390 compiler doesn't have that builtin. I should
> > properly add an fls() to asm/bitops.h for each arch then. s390 can
> > use a generic implementation, like the kernel's generic binary search,
> > __fls.
> 
> I wonder if that is a compiler bug. Will try with an older (!cross)
> compiler.

I just sent a v2 with the bitops fix, which I think was the right way
to go from the start. If s390x does have a working builtin or better
way to implement fls, then it can be changed with a later patch.

Thanks,
drew

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

end of thread, other threads:[~2018-01-17 10:41 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-16 18:53 [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 01/11] arm/arm64: cleanup alloc.h includes Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 02/11] arm/arm64: add pgtable to thread_info Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 03/11] arm/arm64: fix virt_to_phys Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 04/11] arm/arm64: flush page table cache when installing entries Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 05/11] arm/arm64: setup: don't allow gaps in phys range Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 06/11] phys_alloc: ensure we account all allocations Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 07/11] page_alloc: allow initialization before setup_vm call Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 08/11] page_alloc: add yet another memalign Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 09/11] lib/auxinfo: add flags field Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 10/11] arm/arm64: allow setup_vm to be skipped Andrew Jones
2018-01-16 18:53 ` [PATCH kvm-unit-tests 11/11] arm/arm64: sieve should start with the mmu off Andrew Jones
2018-01-16 19:50 ` [PATCH kvm-unit-tests 00/11] arm/arm64: mmu fixes and feature David Hildenbrand
2018-01-17  9:12   ` Andrew Jones
2018-01-17  9:16     ` David Hildenbrand
2018-01-17 10:41       ` Andrew Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.