From patchwork Thu Aug 23 09:20:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 10573647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B9AF112E for ; Thu, 23 Aug 2018 09:20:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 963B62BCDC for ; Thu, 23 Aug 2018 09:20:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 934092BBFE; Thu, 23 Aug 2018 09:20:22 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 08CA82BCBA for ; Thu, 23 Aug 2018 09:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730554AbeHWMs4 (ORCPT ); Thu, 23 Aug 2018 08:48:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35866 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727646AbeHWMs4 (ORCPT ); Thu, 23 Aug 2018 08:48:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1A2B400C3A1; Thu, 23 Aug 2018 09:20:06 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id C968B2157F4A; Thu, 23 Aug 2018 09:20:05 +0000 (UTC) From: Andrew Jones To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, andre.przywara@arm.com Subject: [PATCH kvm-unit-tests 1/2] arm/arm64: prepare to compile arm64 tests relocatable Date: Thu, 23 Aug 2018 11:20:02 +0200 Message-Id: <20180823092003.6076-2-drjones@redhat.com> In-Reply-To: <20180823092003.6076-1-drjones@redhat.com> References: <20180823092003.6076-1-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 23 Aug 2018 09:20:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 23 Aug 2018 09:20:06 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'drjones@redhat.com' RCPT:'' Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Andrew Jones --- arm/Makefile.arm | 6 +++++- arm/Makefile.arm64 | 6 +++++- arm/Makefile.common | 19 +++++++------------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/arm/Makefile.arm b/arm/Makefile.arm index 6b57284382aa..a625267a9c02 100644 --- a/arm/Makefile.arm +++ b/arm/Makefile.arm @@ -5,7 +5,6 @@ # bits = 32 ldarch = elf32-littlearm -kernel_offset = 0x10000 machine = -marm # stack.o relies on frame pointers. @@ -14,6 +13,11 @@ KEEP_FRAME_POINTER := y CFLAGS += $(machine) CFLAGS += -mcpu=$(PROCESSOR) +arch_LDFLAGS = -Ttext=40010000 + +define arch_elf_check = +endef + cstart.o = $(TEST_DIR)/cstart.o cflatobjs += lib/arm/spinlock.o cflatobjs += lib/arm/processor.o diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64 index f04bbf476763..782d4faa5cdc 100644 --- a/arm/Makefile.arm64 +++ b/arm/Makefile.arm64 @@ -5,7 +5,11 @@ # bits = 64 ldarch = elf64-littleaarch64 -kernel_offset = 0x80000 + +arch_LDFLAGS = -Ttext=40080000 + +define arch_elf_check = +endef cstart.o = $(TEST_DIR)/cstart64.o cflatobjs += lib/arm64/processor.o diff --git a/arm/Makefile.common b/arm/Makefile.common index 1cf9cdcf078e..57c3363a36f2 100644 --- a/arm/Makefile.common +++ b/arm/Makefile.common @@ -4,11 +4,6 @@ # Authors: Andrew Jones # -ifeq ($(LOADADDR),) - # qemu mach-virt default load address - LOADADDR = 0x40000000 -endif - tests-common = $(TEST_DIR)/selftest.flat tests-common += $(TEST_DIR)/spinlock-test.flat tests-common += $(TEST_DIR)/pci-test.flat @@ -23,7 +18,6 @@ all: directories $(tests-all) $(TEST_DIR)/sieve.elf: AUXFLAGS = 0x1 ################################################################## -phys_base = $(LOADADDR) AUXFLAGS ?= 0x0 CFLAGS += -std=gnu99 @@ -64,17 +58,18 @@ libeabi = lib/arm/libeabi.a eabiobjs = lib/arm/eabi_compat.o libgcc := $(shell $(CC) $(machine) --print-libgcc-file-name) -start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) ))) FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi) -%.elf: LDFLAGS = $(CFLAGS) -nostdlib +%.elf: LDFLAGS = -nostdlib $(arch_LDFLAGS) %.elf: %.o $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o) - $(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)\" -DAUXFLAGS=$(AUXFLAGS) + $(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c \ + -DPROGNAME=\"$(@:.elf=.flat)\" -DAUXFLAGS=$(AUXFLAGS) + $(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/arm/flat.lds \ + $(filter %.o, $^) $(FLATLIBS) $(@:.elf=.aux.o) + $(RM) $(@:.elf=.aux.o) %.flat: %.elf + $(call arch_elf_check, $^) $(OBJCOPY) -O binary $^ $@ $(libeabi): $(eabiobjs) From patchwork Thu Aug 23 09:20:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 10573649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A854B13B6 for ; Thu, 23 Aug 2018 09:20:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A48B22BCC3 for ; Thu, 23 Aug 2018 09:20:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A20642BCE1; Thu, 23 Aug 2018 09:20:23 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 8A4692BCE3 for ; Thu, 23 Aug 2018 09:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730745AbeHWMs5 (ORCPT ); Thu, 23 Aug 2018 08:48:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35870 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729796AbeHWMs4 (ORCPT ); Thu, 23 Aug 2018 08:48:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EFD24400C3C0; Thu, 23 Aug 2018 09:20:07 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 068552156899; Thu, 23 Aug 2018 09:20:06 +0000 (UTC) From: Andrew Jones To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, andre.przywara@arm.com Subject: [PATCH kvm-unit-tests 2/2] arm64: compile relocatable Date: Thu, 23 Aug 2018 11:20:03 +0200 Message-Id: <20180823092003.6076-3-drjones@redhat.com> In-Reply-To: <20180823092003.6076-1-drjones@redhat.com> References: <20180823092003.6076-1-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 23 Aug 2018 09:20:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 23 Aug 2018 09:20:08 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'drjones@redhat.com' RCPT:'' Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Support R_AARCH64_RELATIVE relocations allowing unit tests to be loaded at different addresses. We also take the opportunity to spruce up flat.lds and to stop pointless stack usage in start. Signed-off-by: Andrew Jones --- arm/Makefile.arm64 | 6 +++++- arm/cstart64.S | 52 +++++++++++++++++++++++++++++++++++----------- arm/flat.lds | 42 +++++++++++++++++++++++++------------ 3 files changed, 74 insertions(+), 26 deletions(-) diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64 index 782d4faa5cdc..38a8a5da0fb8 100644 --- a/arm/Makefile.arm64 +++ b/arm/Makefile.arm64 @@ -6,9 +6,13 @@ bits = 64 ldarch = elf64-littleaarch64 -arch_LDFLAGS = -Ttext=40080000 +arch_LDFLAGS = -pie -n define arch_elf_check = + $(if $(shell ! $(OBJDUMP) -R $(1) >&/dev/null && echo "nok"), + $(error $(shell $(OBJDUMP) -R $(1) 2>&1))) + $(if $(shell $(OBJDUMP) -R $(1) | grep R_ | grep -v R_AARCH64_RELATIVE), + $(error $(1) has unsupported reloc types)) endef cstart.o = $(TEST_DIR)/cstart64.o diff --git a/arm/cstart64.S b/arm/cstart64.S index cbb4fb65683d..b0e8baa1a23a 100644 --- a/arm/cstart64.S +++ b/arm/cstart64.S @@ -15,30 +15,58 @@ .section .init +/* + * Bootloader params are in x0-x3. See kernel doc + * Documentation/arm64/booting.txt + */ .globl start start: + /* get our base address */ + adrp x4, start + add x4, x4, :lo12:start + /* - * bootloader params are in x0-x3 - * The physical address of the dtb is in x0, x1-x3 are reserved - * See the kernel doc Documentation/arm64/booting.txt + * Update all R_AARCH64_RELATIVE relocations using the table + * of Elf64_Rela entries between reloc_start/end. The build + * will not emit other relocation types. + * + * struct Elf64_Rela { + * uint64_t r_offset; + * uint64_t r_info; + * int64_t r_addend; + * } */ + adrp x5, reloc_start + add x5, x5, :lo12:reloc_start + adrp x6, reloc_end + add x6, x6, :lo12:reloc_end +1: + cmp x5, x6 + b.hs 1f + ldr x7, [x5] // r_offset + ldr x8, [x5, #16] // r_addend + add x8, x8, x4 // val = base + r_addend + str x8, [x4, x7] // base[r_offset] = val + add x5, x5, #24 + b 1b + +1: + /* set up stack */ mov x4, #1 msr spsel, x4 isb adrp x4, stackptr add sp, x4, :lo12:stackptr - stp x0, x1, [sp, #-16]! - /* Enable FP/ASIMD */ - mov x0, #(3 << 20) - msr cpacr_el1, x0 + /* enable FP/ASIMD */ + mov x4, #(3 << 20) + msr cpacr_el1, x4 /* set up exception handling */ bl exceptions_init /* complete setup */ - ldp x0, x1, [sp], #16 - bl setup + bl setup // x0 is the addr of the dtb bl get_mmu_off cbnz x0, 1f bl setup_vm @@ -56,9 +84,9 @@ start: b halt exceptions_init: - adrp x0, vector_table - add x0, x0, :lo12:vector_table - msr vbar_el1, x0 + adrp x4, vector_table + add x4, x4, :lo12:vector_table + msr vbar_el1, x4 isb ret diff --git a/arm/flat.lds b/arm/flat.lds index efdf5d7109ff..25f8d03cba87 100644 --- a/arm/flat.lds +++ b/arm/flat.lds @@ -3,25 +3,41 @@ SECTIONS { .text : { *(.init) *(.text) *(.text.*) } . = ALIGN(64K); - etext = .; - .data : { - *(.data) - } - . = ALIGN(16); - .rodata : { *(.rodata) } - . = ALIGN(16); - .bss : { *(.bss) } - . = ALIGN(64K); - edata = .; - . += 64K; + PROVIDE(etext = .); + + PROVIDE(reloc_start = .); + .rela.dyn : { *(.rela.dyn) } + PROVIDE(reloc_end = .); + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .got : { *(.got) *(.got.plt) } + .eh_frame : { *(.eh_frame) } + + .rodata : { *(.rodata*) } + .data : { *(.data) } + .bss : { *(.bss) } . = ALIGN(64K); + PROVIDE(edata = .); + /* * stack depth is 16K for arm and PAGE_SIZE for arm64, see THREAD_SIZE * sp must be 16 byte aligned for arm64, and 8 byte aligned for arm * sp must always be strictly less than the true stacktop */ - stackptr = . - 16; - stacktop = .; + . += 64K; + . = ALIGN(64K); + PROVIDE(stackptr = . - 16); + PROVIDE(stacktop = .); + + /DISCARD/ : { + *(.note*) + *(.interp) + *(.debug*) + *(.comment) + *(.dynamic) + } } ENTRY(start)