From patchwork Tue Jan 16 18:53:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 10167949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 17E28600CA for ; Tue, 16 Jan 2018 18:55:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0392620223 for ; Tue, 16 Jan 2018 18:55:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAC48204FD; Tue, 16 Jan 2018 18:55:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A27920223 for ; Tue, 16 Jan 2018 18:55:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751686AbeAPSzE (ORCPT ); Tue, 16 Jan 2018 13:55:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34152 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751666AbeAPSzC (ORCPT ); Tue, 16 Jan 2018 13:55:02 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1ECDFC054900; Tue, 16 Jan 2018 18:55:02 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CB7A609A7; Tue, 16 Jan 2018 18:54:54 +0000 (UTC) From: Andrew Jones To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, cdall@linaro.org, david@redhat.com, lvivier@redhat.com, thuth@redhat.com Subject: [PATCH kvm-unit-tests 10/11] arm/arm64: allow setup_vm to be skipped Date: Tue, 16 Jan 2018 19:53:11 +0100 Message-Id: <20180116185312.7257-11-drjones@redhat.com> In-Reply-To: <20180116185312.7257-1-drjones@redhat.com> References: <20180116185312.7257-1-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 16 Jan 2018 18:55:02 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #include #include #include @@ -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 #include #include #include @@ -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 #include #include +#include #include #include #include #include -#include #include 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 +#include #include #include #include @@ -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