Skip to contentSkip to conversation

AArch64 Linux kernel port

PATCH Superseded Catalin Marinas 19 participants 170 messages Aug 14, 2012 – Sep 16, 2012 Page 1 of 2

Subsystems (15)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Catalin Marinas

author maintainer
#0 lore raw

v2 cover AArch64 Linux kernel port

This is the 2nd version of the set of patches implementing Linux kernel support for the 64-bit ARM architecture (AArch64). Thanks to all who provided feedback on the previous version.

The Linux kernel patches are available on this tree:

git://git.kernel.org/pub/scm/linux/kernel/git/cmarinas/linux-aarch64.git upstream

The "master" branch in the above repository tracks the development history.

Main changes from the previous version (for the full log see the "master" branch above):

- Kernel port directory and related functions renamed to "arm64". "uname -m" reports "aarch64" as per the official name.
- NO_BOOTMEM enabled.
- "mem=" is now used for limiting the amount of memory rather than specifying the memory banks (already done via FDT).
- struct mem_type removed as static definitions are enough for ioremap().
- Support for ZONE_DMA32.
- Replaced "user_debug" with "/proc/sys/debug/exception-trace".
- Added a generic defconfig file.
- More clean-up (comments, code) and bug-fixes.

The generic patches were dropped from this series as they have been pushed separately (and most of them already merged into mainline).

Background to the 64-bit ARM architecture:

ARM introduced AArch64 as part of the ARMv8 architecture and consists of a substantially revised exception model (with 4 exception levels: EL0 - user, EL1 - kernel, EL2 - hypervisor, EL3 - secure monitor), new A64 instruction set based on larger register file, new FP/SIMD instructions. The new ABI is LP64 and takes advantage of the larger register file. It also mandates FP.

AArch64 documentation currently available (publicly, though click-through agreement required):

- Instruction Set Overview:
http://infocenter.arm.com/help/topic/com.arm.doc.genc010197a/index.html

- ABI (PCS, ELF, DWARF, C++):
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0059a/index.html

Regards,

Catalin

Catalin Marinas (23):
arm64: Assembly macros and definitions
arm64: Kernel booting and initialisation
arm64: Exception handling
arm64: MMU definitions
arm64: MMU initialisation
arm64: MMU fault handling and page table management
arm64: Process management
arm64: CPU support
arm64: Cache maintenance routines
arm64: TLB maintenance functionality
arm64: Atomic operations
arm64: Device specific operations
arm64: DMA mapping API
arm64: SMP support
arm64: ELF definitions
arm64: System calls handling
arm64: Signal handling support
arm64: User access library functions
arm64: Floating point and SIMD
arm64: Add support for /proc/sys/debug/exception-trace
arm64: Miscellaneous header files
arm64: Build infrastructure
arm64: MAINTAINERS update

Marc Zyngier (3):
arm64: IRQ handling
arm64: Miscellaneous library functions
arm64: Generic timers support

Will Deacon (5):
arm64: VDSO support
arm64: 32-bit (compat) applications support
arm64: Debugging support
arm64: Performance counters support
arm64: Loadable modules

 Documentation/arm64/booting.txt               |  141 +++
 Documentation/arm64/memory.txt                |   69 ++
 MAINTAINERS                                   |    6 +
 arch/arm64/Kconfig                            |  261 +++++
 arch/arm64/Kconfig.debug                      |   27 +
 arch/arm64/Makefile                           |   71 ++
 arch/arm64/boot/.gitignore                    |    2 +
 arch/arm64/boot/Makefile                      |   38 +
 arch/arm64/boot/install.sh                    |   52 +
 arch/arm64/configs/generic_defconfig          |   85 ++
 arch/arm64/include/asm/Kbuild                 |   51 +
 arch/arm64/include/asm/asm-offsets.h          |    1 +
 arch/arm64/include/asm/assembler.h            |  109 ++
 arch/arm64/include/asm/atomic.h               |  306 ++++++
 arch/arm64/include/asm/auxvec.h               |   22 +
 arch/arm64/include/asm/barrier.h              |   52 +
 arch/arm64/include/asm/bitops.h               |   74 ++
 arch/arm64/include/asm/bitsperlong.h          |   23 +
 arch/arm64/include/asm/byteorder.h            |   21 +
 arch/arm64/include/asm/cache.h                |   32 +
 arch/arm64/include/asm/cacheflush.h           |  209 ++++
 arch/arm64/include/asm/cachetype.h            |   48 +
 arch/arm64/include/asm/cmpxchg.h              |  180 ++++
 arch/arm64/include/asm/compat.h               |  232 +++++
 arch/arm64/include/asm/compiler.h             |   30 +
 arch/arm64/include/asm/cputype.h              |   49 +
 arch/arm64/include/asm/debug-monitors.h       |   88 ++
 arch/arm64/include/asm/device.h               |   26 +
 arch/arm64/include/asm/dma-mapping.h          |  124 +++
 arch/arm64/include/asm/elf.h                  |  176 ++++
 arch/arm64/include/asm/exception.h            |   23 +
 arch/arm64/include/asm/exec.h                 |   23 +
 arch/arm64/include/asm/fb.h                   |   34 +
 arch/arm64/include/asm/fcntl.h                |   29 +
 arch/arm64/include/asm/fpsimd.h               |   64 ++
 arch/arm64/include/asm/futex.h                |  134 +++
 arch/arm64/include/asm/hardirq.h              |   52 +
 arch/arm64/include/asm/hw_breakpoint.h        |  137 +++
 arch/arm64/include/asm/hwcap.h                |   57 +
 arch/arm64/include/asm/io.h                   |  263 +++++
 arch/arm64/include/asm/irq.h                  |    8 +
 arch/arm64/include/asm/irqflags.h             |   91 ++
 arch/arm64/include/asm/memblock.h             |   21 +
 arch/arm64/include/asm/memory.h               |  144 +++
 arch/arm64/include/asm/mmu.h                  |   27 +
 arch/arm64/include/asm/mmu_context.h          |  152 +++
 arch/arm64/include/asm/module.h               |   23 +
 arch/arm64/include/asm/page.h                 |   67 ++
 arch/arm64/include/asm/param.h                |   23 +
 arch/arm64/include/asm/perf_event.h           |   22 +
 arch/arm64/include/asm/pgalloc.h              |  113 ++
 arch/arm64/include/asm/pgtable-2level-hwdef.h |   43 +
 arch/arm64/include/asm/pgtable-2level-types.h |   60 ++
 arch/arm64/include/asm/pgtable-3level-hwdef.h |   50 +
 arch/arm64/include/asm/pgtable-3level-types.h |   66 ++
 arch/arm64/include/asm/pgtable-hwdef.h        |   94 ++
 arch/arm64/include/asm/pgtable.h              |  328 ++++++
 arch/arm64/include/asm/pmu.h                  |   82 ++
 arch/arm64/include/asm/proc-fns.h             |   51 +
 arch/arm64/include/asm/processor.h            |  174 ++++
 arch/arm64/include/asm/procinfo.h             |   44 +
 arch/arm64/include/asm/prom.h                 |    1 +
 arch/arm64/include/asm/ptrace.h               |  206 ++++
 arch/arm64/include/asm/setup.h                |   26 +
 arch/arm64/include/asm/shmparam.h             |   28 +
 arch/arm64/include/asm/sigcontext.h           |   69 ++
 arch/arm64/include/asm/siginfo.h              |   23 +
 arch/arm64/include/asm/signal.h               |   24 +
 arch/arm64/include/asm/signal32.h             |   54 +
 arch/arm64/include/asm/smp.h                  |   69 ++
 arch/arm64/include/asm/sparsemem.h            |   24 +
 arch/arm64/include/asm/spinlock.h             |  199 ++++
 arch/arm64/include/asm/spinlock_types.h       |   38 +
 arch/arm64/include/asm/stacktrace.h           |   29 +
 arch/arm64/include/asm/stat.h                 |   63 ++
 arch/arm64/include/asm/statfs.h               |   23 +
 arch/arm64/include/asm/syscall.h              |  101 ++
 arch/arm64/include/asm/syscalls.h             |   40 +
 arch/arm64/include/asm/system_misc.h          |   54 +
 arch/arm64/include/asm/thread_info.h          |  124 +++
 arch/arm64/include/asm/timex.h                |   32 +
 arch/arm64/include/asm/tlb.h                  |  190 ++++
 arch/arm64/include/asm/tlbflush.h             |  123 +++
 arch/arm64/include/asm/traps.h                |   30 +
 arch/arm64/include/asm/uaccess.h              |  377 +++++++
 arch/arm64/include/asm/ucontext.h             |   30 +
 arch/arm64/include/asm/unistd.h               |   27 +
 arch/arm64/include/asm/unistd32.h             |  758 ++++++++++++++
 arch/arm64/include/asm/vdso.h                 |   41 +
 arch/arm64/include/asm/vdso_datapage.h        |   43 +
 arch/arm64/kernel/.gitignore                  |    1 +
 arch/arm64/kernel/Makefile                    |   27 +
 arch/arm64/kernel/arm64ksyms.c                |   55 +
 arch/arm64/kernel/asm-offsets.c               |  108 ++
 arch/arm64/kernel/debug-monitors.c            |  288 ++++++
 arch/arm64/kernel/elf.c                       |   41 +
 arch/arm64/kernel/entry-fpsimd.S              |   80 ++
 arch/arm64/kernel/entry.S                     |  695 +++++++++++++
 arch/arm64/kernel/fpsimd.c                    |  106 ++
 arch/arm64/kernel/head.S                      |  521 ++++++++++
 arch/arm64/kernel/hw_breakpoint.c             |  880 ++++++++++++++++
 arch/arm64/kernel/io.c                        |   64 ++
 arch/arm64/kernel/irq.c                       |   84 ++
 arch/arm64/kernel/kuser32.S                   |   77 ++
 arch/arm64/kernel/module.c                    |  456 ++++++++
 arch/arm64/kernel/perf_event.c                | 1368 +++++++++++++++++++++++++
 arch/arm64/kernel/process.c                   |  416 ++++++++
 arch/arm64/kernel/ptrace.c                    |  834 +++++++++++++++
 arch/arm64/kernel/setup.c                     |  357 +++++++
 arch/arm64/kernel/signal.c                    |  436 ++++++++
 arch/arm64/kernel/signal32.c                  |  876 ++++++++++++++++
 arch/arm64/kernel/smp.c                       |  469 +++++++++
 arch/arm64/kernel/stacktrace.c                |  127 +++
 arch/arm64/kernel/sys.c                       |  138 +++
 arch/arm64/kernel/sys32.S                     |  283 +++++
 arch/arm64/kernel/sys_compat.c                |  177 ++++
 arch/arm64/kernel/time.c                      |   65 ++
 arch/arm64/kernel/traps.c                     |  357 +++++++
 arch/arm64/kernel/vdso.c                      |  261 +++++
 arch/arm64/kernel/vdso/.gitignore             |    2 +
 arch/arm64/kernel/vdso/Makefile               |   63 ++
 arch/arm64/kernel/vdso/gen_vdso_offsets.sh    |   15 +
 arch/arm64/kernel/vdso/gettimeofday.S         |  242 +++++
 arch/arm64/kernel/vdso/note.S                 |   28 +
 arch/arm64/kernel/vdso/sigreturn.S            |   37 +
 arch/arm64/kernel/vdso/vdso.S                 |   33 +
 arch/arm64/kernel/vdso/vdso.lds.S             |  100 ++
 arch/arm64/kernel/vmlinux.lds.S               |  146 +++
 arch/arm64/lib/Makefile                       |    5 +
 arch/arm64/lib/bitops.c                       |   25 +
 arch/arm64/lib/clear_page.S                   |   39 +
 arch/arm64/lib/clear_user.S                   |   58 ++
 arch/arm64/lib/copy_from_user.S               |   66 ++
 arch/arm64/lib/copy_in_user.S                 |   63 ++
 arch/arm64/lib/copy_page.S                    |   46 +
 arch/arm64/lib/copy_to_user.S                 |   61 ++
 arch/arm64/lib/delay.c                        |   55 +
 arch/arm64/lib/getuser.S                      |   75 ++
 arch/arm64/lib/putuser.S                      |   73 ++
 arch/arm64/lib/strncpy_from_user.S            |   50 +
 arch/arm64/lib/strnlen_user.S                 |   47 +
 arch/arm64/mm/Kconfig                         |    5 +
 arch/arm64/mm/Makefile                        |    6 +
 arch/arm64/mm/cache.S                         |  279 +++++
 arch/arm64/mm/context.c                       |  159 +++
 arch/arm64/mm/copypage.c                      |   34 +
 arch/arm64/mm/dma-mapping.c                   |  208 ++++
 arch/arm64/mm/extable.c                       |   17 +
 arch/arm64/mm/fault.c                         |  534 ++++++++++
 arch/arm64/mm/flush.c                         |  132 +++
 arch/arm64/mm/init.c                          |  416 ++++++++
 arch/arm64/mm/ioremap.c                       |   84 ++
 arch/arm64/mm/mm.h                            |    2 +
 arch/arm64/mm/mmap.c                          |  144 +++
 arch/arm64/mm/mmu.c                           |  395 +++++++
 arch/arm64/mm/pgd.c                           |   49 +
 arch/arm64/mm/proc-macros.S                   |   55 +
 arch/arm64/mm/proc-syms.c                     |   31 +
 arch/arm64/mm/proc.S                          |  193 ++++
 arch/arm64/mm/tlb.S                           |   71 ++
 drivers/clocksource/Kconfig                   |    5 +
 drivers/clocksource/Makefile                  |    1 +
 drivers/clocksource/arm_generic.c             |  309 ++++++
 include/clocksource/arm_generic.h             |   21 +
 init/Kconfig                                  |    3 +-
 kernel/sysctl.c                               |    2 +-
 lib/Kconfig.debug                             |    6 +-
 tools/perf/perf.h                             |    6 +
 168 files changed, 22089 insertions(+), 4 deletions(-)
author maintainer
#1 lore raw

PATCH v2 1/31 arm64: Assembly macros and definitions

This patch introduces several assembly macros and definitions used in the .S files across arch/arm64/ like IRQ disabling/enabling, together with asm-offsets.c.

---
 arch/arm64/include/asm/asm-offsets.h |    1 +
 arch/arm64/include/asm/assembler.h   |  109 ++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/asm-offsets.c      |  108 +++++++++++++++++++++++++++++++++
 arch/arm64/mm/proc-macros.S          |   55 +++++++++++++++++
 4 files changed, 273 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/asm-offsets.h
 create mode 100644 arch/arm64/include/asm/assembler.h
 create mode 100644 arch/arm64/kernel/asm-offsets.c
 create mode 100644 arch/arm64/mm/proc-macros.S
arch/arm64/include/asm/asm-offsets.h new file +1 -0
new file mode 100644
index 0000000..d370ee3
@@ -0,0 +1 @@
+#include <generated/asm-offsets.h>
arch/arm64/include/asm/assembler.h new file +109 -0

109 lines not on this page · raw message

arch/arm64/kernel/asm-offsets.c new file +108 -0

108 lines not on this page · raw message

arch/arm64/mm/proc-macros.S new file +55 -0

55 lines not on this page · raw message

author maintainer
#3 lore raw

PATCH v2 2/31 arm64: Kernel booting and initialisation

In reply to Catalin Marinas

The patch adds the kernel booting and the initial setup code. Documentation/arm64/booting.txt describes the booting protocol on the AArch64 Linux kernel. This is subject to change following the work on boot standardisation, ACPI.

---
 Documentation/arm64/booting.txt |  141 +++++++++++
 arch/arm64/include/asm/setup.h  |   26 ++
 arch/arm64/kernel/head.S        |  521 +++++++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/setup.c       |  357 +++++++++++++++++++++++++++
 4 files changed, 1045 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/arm64/booting.txt
 create mode 100644 arch/arm64/include/asm/setup.h
 create mode 100644 arch/arm64/kernel/head.S
 create mode 100644 arch/arm64/kernel/setup.c
Documentation/arm64/booting.txt new file +141 -0
new file mode 100644
index 0000000..3197820
@@ -0,0 +1,141 @@
+			Booting AArch64 Linux
+			=====================
+
+Author: Will Deacon <[email protected]>
+Date  : 25 April 2012
+
+This document is based on the ARM booting document by Russell King and
+is relevant to all public releases of the AArch64 Linux kernel.
+
+The AArch64 exception model is made up of a number of exception levels
+(EL0 - EL3), with EL0 and EL1 having a secure and a non-secure
+counterpart.  EL2 is the hypervisor level and exists only in non-secure
+mode. EL3 is the highest priority level and exists only in secure mode.
+
+For the purposes of this document, we will use the term `boot loader'
+simply to define all software that executes on the CPU(s) before control
+is passed to the Linux kernel.  This may include secure monitor and
+hypervisor code, or it may just be a handful of instructions for
+preparing a minimal boot environment.
+
+Essentially, the boot loader should provide (as a minimum) the
+following:
+
+1. Setup and initialise the RAM
+2. Setup the device tree
+3. Decompress the kernel image
+4. Call the kernel image
+
+
+1. Setup and initialise RAM
+---------------------------
+
+Requirement: MANDATORY
+
+The boot loader is expected to find and initialise all RAM that the
+kernel will use for volatile data storage in the system.  It performs
+this in a machine dependent manner.  (It may use internal algorithms
+to automatically locate and size all RAM, or it may use knowledge of
+the RAM in the machine, or any other method the boot loader designer
+sees fit.)
+
+
+2. Setup the device tree
+-------------------------
+
+Requirement: MANDATORY
+
+The device tree blob (dtb) must be no bigger than 2 megabytes in size
+and placed at a 2-megabyte boundary within the first 512 megabytes from
+the start of the kernel image. This is to allow the kernel to map the
+blob using a single section mapping in the initial page tables.
+
+
+3. Decompress the kernel image
+------------------------------
+
+Requirement: OPTIONAL
+
+The AArch64 kernel does not provide a decompressor and therefore
+requires gzip decompression to be performed by the boot loader if the
+default Image.gz target is used.  For bootloaders that do not implement
+this requirement, the larger Image target is available instead.
+
+
+4. Call the kernel image
+------------------------
+
+Requirement: MANDATORY
+
+The decompressed kernel image contains a 32-byte header as follows:
+
+  u32 magic	= 0x14000008;	/* branch to stext, little-endian */
+  u32 res0	= 0;		/* reserved */
+  u64 text_offset;		/* Image load offset */
+  u64 res1	= 0;		/* reserved */
+  u64 res2	= 0;		/* reserved */
+
+The image must be placed at the specified offset (currently 0x80000)
+from the start of the system RAM and called there. The start of the
+system RAM must be aligned to 2MB.
+
+Before jumping into the kernel, the following conditions must be met:
+
+- Quiesce all DMA capable devices so that memory does not get
+  corrupted by bogus network packets or disk data.  This will save
+  you many hours of debug.
+
+- Primary CPU general-purpose register settings
+  x0 = physical address of device tree blob (dtb) in system RAM.
+
+- CPU mode
+  All forms of interrupts must be masked in PSTATE.DAIF (Debug, SError,
+  IRQ and FIQ).
+  The CPU must be in either EL2 (RECOMMENDED in order to have access to
+  the virtualisation extensions) or non-secure EL1.
+
+- Caches, MMUs
+  The MMU must be off.
+  Instruction cache may be on or off.
+  Data cache must be off and invalidated.
+
+- Architected timers
+  CNTFRQ must be programmed with the timer frequency.
+  If entering the kernel at EL1, CNTHCTL_EL2 must have EL1PCTEN (bit 0)
+  set where available.
+
+- Coherency
+  All CPUs to be booted by the kernel must be part of the same coherency
+  domain on entry to the kernel.  This may require IMPLEMENTATION DEFINED
+  initialisation to enable the receiving of maintenance operations on
+  each CPU.
+
+- System registers
+  All writable architected system registers at the exception level where
+  the kernel image will be entered must be initialised by software at a
+  higher exception level to prevent execution in an UNKNOWN state.
+
+The boot loader is expected to enter the kernel on each CPU in the
+following manner:
+
+- The primary CPU must jump directly to the first instruction of the
+  kernel image.  The device tree blob passed by this CPU must contain
+  for each CPU node:
+
+    1. An 'enable-method' property. Currently, the only supported value
+       for this field is the string "spin-table".
+
+    2. A 'cpu-release-addr' property identifying a 64-bit,
+       zero-initialised memory location.
+
+  It is expected that the bootloader will generate these device tree
+  properties and insert them into the blob prior to kernel entry.
+
+- Any secondary CPUs must spin outside of the kernel in a reserved area
+  of memory (communicated to the kernel by a /memreserve/ region in the
+  device tree) polling their cpu-release-addr location, which must be
+  contained in the reserved region.  A wfe instruction may be inserted
+  to reduce the overhead of the busy-loop and a sev will be issued by
+  the primary CPU.  When a read of the location pointed to by the
+  cpu-release-addr returns a non-zero value, the CPU must jump directly
+  to this value.
arch/arm64/include/asm/setup.h new file +26 -0
new file mode 100644
index 0000000..d766493
@@ -0,0 +1,26 @@
+/*
+ * Based on arch/arm/include/asm/setup.h
+ *
+ * Copyright (C) 1997-1999 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SETUP_H
+#define __ASM_SETUP_H
+
+#include <linux/types.h>
+
+#define COMMAND_LINE_SIZE 1024
+
+#endif
arch/arm64/kernel/head.S new file +521 -0

521 lines not on this page · raw message

arch/arm64/kernel/setup.c new file +357 -0

357 lines not on this page · raw message

author maintainer
#22 lore raw

PATCH v2 3/31 arm64: Exception handling

In reply to Catalin Marinas

The patch contains the exception entry code (kernel/entry.S), pt_regs structure and related accessors, undefined instruction trapping and stack tracing.

AArch64 Linux kernel (including kernel threads) runs in EL1 mode using the SP1 stack. The vectors don't have a fixed address, only alignment (2^11) requirements.

---
 arch/arm64/include/asm/ptrace.h     |  206 +++++++++++
 arch/arm64/include/asm/stacktrace.h |   29 ++
 arch/arm64/include/asm/traps.h      |   30 ++
 arch/arm64/kernel/entry.S           |  695 +++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/stacktrace.c      |  127 +++++++
 arch/arm64/kernel/traps.c           |  357 ++++++++++++++++++
 6 files changed, 1444 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/ptrace.h
 create mode 100644 arch/arm64/include/asm/stacktrace.h
 create mode 100644 arch/arm64/include/asm/traps.h
 create mode 100644 arch/arm64/kernel/entry.S
 create mode 100644 arch/arm64/kernel/stacktrace.c
 create mode 100644 arch/arm64/kernel/traps.c
arch/arm64/include/asm/ptrace.h new file +206 -0
new file mode 100644
index 0000000..a9abace
@@ -0,0 +1,206 @@
+/*
+ * Based on arch/arm/include/asm/ptrace.h
+ *
+ * Copyright (C) 1996-2003 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_PTRACE_H
+#define __ASM_PTRACE_H
+
+#include <linux/types.h>
+
+#include <asm/hwcap.h>
+
+#define PTRACE_GETREGS		12
+#define PTRACE_SETREGS		13
+#define PTRACE_GETFPSIMDREGS	14
+#define PTRACE_SETFPSIMDREGS	15
+/* PTRACE_ATTACH is 16 */
+/* PTRACE_DETACH is 17 */
+#define PTRACE_GET_THREAD_AREA	22
+#define PTRACE_SET_SYSCALL	23
+#define PTRACE_GETHBPREGS	29
+#define PTRACE_SETHBPREGS	30
+
+/* AArch32-specific ptrace requests */
+#define COMPAT_PTRACE_GETVFPREGS	27
+#define COMPAT_PTRACE_SETVFPREGS	28
+
+/*
+ * PSR bits
+ */
+#define PSR_MODE_EL0t	0x00000000
+#define PSR_MODE_EL1t	0x00000004
+#define PSR_MODE_EL1h	0x00000005
+#define PSR_MODE_EL2t	0x00000008
+#define PSR_MODE_EL2h	0x00000009
+#define PSR_MODE_EL3t	0x0000000c
+#define PSR_MODE_EL3h	0x0000000d
+#define PSR_MODE_MASK	0x0000000f
+
+/* AArch32 CPSR bits */
+#define PSR_MODE32_BIT		0x00000010
+#define COMPAT_PSR_MODE_USR	0x00000010
+#define COMPAT_PSR_T_BIT	0x00000020
+#define COMPAT_PSR_IT_MASK	0x0600fc00	/* If-Then execution state mask */
+
+/* AArch64 SPSR bits */
+#define PSR_F_BIT	0x00000040
+#define PSR_I_BIT	0x00000080
+#define PSR_A_BIT	0x00000100
+#define PSR_D_BIT	0x00000200
+#define PSR_Q_BIT	0x08000000
+#define PSR_V_BIT	0x10000000
+#define PSR_C_BIT	0x20000000
+#define PSR_Z_BIT	0x40000000
+#define PSR_N_BIT	0x80000000
+
+/*
+ * Groups of PSR bits
+ */
+#define PSR_f		0xff000000	/* Flags		*/
+#define PSR_s		0x00ff0000	/* Status		*/
+#define PSR_x		0x0000ff00	/* Extension		*/
+#define PSR_c		0x000000ff	/* Control		*/
+
+/*
+ * These are 'magic' values for PTRACE_PEEKUSR that return info about where a
+ * process is located in memory.
+ */
+#define PT_TEXT_ADDR		0x10000
+#define PT_DATA_ADDR		0x10004
+#define PT_TEXT_END_ADDR	0x10008
+
+#ifndef __ASSEMBLY__
+
+/*
+ * User structures for general purpose and floating point registers.
+ */
+struct user_pt_regs {
+	__u64		regs[31];
+	__u64		sp;
+	__u64		pc;
+	__u64		pstate;
+};
+
+struct user_fpsimd_state {
+	__uint128_t	vregs[32];
+	__u32		fpsr;
+	__u32		fpcr;
+};
+
+#ifdef __KERNEL__
+
+#ifdef CONFIG_AARCH32_EMULATION
+/* sizeof(struct user) for AArch32 */
+#define COMPAT_USER_SZ	296
+/* AArch32 uses x13 as the stack pointer... */
+#define compat_sp	regs[13]
+/* ... and x14 as the link register. */
+#define compat_lr	regs[14]
+#endif
+
+/*
+ * This struct defines the way the registers are stored on the stack during an
+ * exception. Note that sizeof(struct pt_regs) has to be a multiple of 16 (for
+ * stack alignment). struct user_pt_regs must form a prefix of struct pt_regs.
+ */
+struct pt_regs {
+	union {
+		struct user_pt_regs user_regs;
+		struct {
+			u64 regs[31];
+			u64 sp;
+			u64 pc;
+			u64 pstate;
+		};
+	};
+	u64 orig_x0;
+	u64 syscallno;
+};
+
+#define arch_has_single_step()	(1)
+
+#ifdef CONFIG_AARCH32_EMULATION
+#define compat_thumb_mode(regs) \
+	(((regs)->pstate & COMPAT_PSR_T_BIT))
+#else
+#define compat_thumb_mode(regs) (0)
+#endif
+
+#define user_mode(regs)	\
+	(((regs)->pstate & PSR_MODE_MASK) == PSR_MODE_EL0t)
+
+#define compat_user_mode(regs)	\
+	(((regs)->pstate & (PSR_MODE32_BIT | PSR_MODE_MASK)) == \
+	 (PSR_MODE32_BIT | PSR_MODE_EL0t))
+
+#define processor_mode(regs) \
+	((regs)->pstate & PSR_MODE_MASK)
+
+#define interrupts_enabled(regs) \
+	(!((regs)->pstate & PSR_I_BIT))
+
+#define fast_interrupts_enabled(regs) \
+	(!((regs)->pstate & PSR_F_BIT))
+
+#define user_stack_pointer(regs) \
+	((regs)->sp)
+
+/*
+ * Are the current registers suitable for user mode? (used to maintain
+ * security in signal handlers)
+ */
+static inline int valid_user_regs(struct user_pt_regs *regs)
+{
+	if (user_mode(regs) && (regs->pstate & PSR_I_BIT) == 0) {
+		regs->pstate &= ~(PSR_F_BIT | PSR_A_BIT);
+
+		/* The T bit is reserved for AArch64 */
+		if (!(regs->pstate & PSR_MODE32_BIT))
+			regs->pstate &= ~COMPAT_PSR_T_BIT;
+
+		return 1;
+	}
+
+	/*
+	 * Force PSR to something logical...
+	 */
+	regs->pstate &= PSR_f | PSR_s | (PSR_x & ~PSR_A_BIT) | \
+			COMPAT_PSR_T_BIT | PSR_MODE32_BIT;
+
+	if (!(regs->pstate & PSR_MODE32_BIT)) {
+		regs->pstate &= ~COMPAT_PSR_T_BIT;
+		regs->pstate |= PSR_MODE_EL0t;
+	}
+
+	return 0;
+}
+
+#define instruction_pointer(regs)	(regs)->pc
+
+#ifdef CONFIG_SMP
+extern unsigned long profile_pc(struct pt_regs *regs);
+#else
+#define profile_pc(regs) instruction_pointer(regs)
+#endif
+
+extern int aarch32_break_trap(struct pt_regs *regs);
+
+#endif /* __KERNEL__ */
+
+#endif /* __ASSEMBLY__ */
+
+#endif
arch/arm64/include/asm/stacktrace.h new file +29 -0
new file mode 100644
index 0000000..7318f6d
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_STACKTRACE_H
+#define __ASM_STACKTRACE_H
+
+struct stackframe {
+	unsigned long fp;
+	unsigned long sp;
+	unsigned long pc;
+};
+
+extern int unwind_frame(struct stackframe *frame);
+extern void walk_stackframe(struct stackframe *frame,
+			    int (*fn)(struct stackframe *, void *), void *data);
+
+#endif	/* __ASM_STACKTRACE_H */
arch/arm64/include/asm/traps.h new file +30 -0
new file mode 100644
index 0000000..10ca8ff
@@ -0,0 +1,30 @@
+/*
+ * Based on arch/arm/include/asm/traps.h
+ *
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_TRAP_H
+#define __ASM_TRAP_H
+
+static inline int in_exception_text(unsigned long ptr)
+{
+	extern char __exception_text_start[];
+	extern char __exception_text_end[];
+
+	return ptr >= (unsigned long)&__exception_text_start &&
+	       ptr < (unsigned long)&__exception_text_end;
+}
+
+#endif
arch/arm64/kernel/entry.S new file +695 -0

695 lines not on this page · raw message

arch/arm64/kernel/stacktrace.c new file +127 -0

127 lines not on this page · raw message

arch/arm64/kernel/traps.c new file +357 -0

357 lines not on this page · raw message

author maintainer
#28 lore raw

PATCH v2 4/31 arm64: MMU definitions

In reply to Catalin Marinas

The virtual memory layout is described in Documentation/arm64/memory.txt. This patch adds the MMU definitions for the 4KB and 64KB translation table configurations. The SECTION_SIZE is 2MB with 4KB page and 512MB with 64KB page configuration.

PHYS_OFFSET is calculated at run-time and stored in a variable (no run-time code patching at this stage).

On the current implementation, both user and kernel address spaces are 512G (39-bit) each with a maximum of 256G for the RAM linear mapping. Linux uses 3 levels of translation tables with the 4K page configuration and 2 levels with the 64K configuration. Extending the memory space beyond 39-bit with the 4K pages or 42-bit with 64K pages requires an additional level of translation tables.

The SPARSEMEM configuration is global to all AArch64 platforms and allows for 1GB sections with SPARSEMEM_VMEMMAP enabled by default.

---
 Documentation/arm64/memory.txt                |   69 +++++
 arch/arm64/include/asm/memory.h               |  144 +++++++++++
 arch/arm64/include/asm/mmu.h                  |   27 ++
 arch/arm64/include/asm/pgtable-2level-hwdef.h |   43 ++++
 arch/arm64/include/asm/pgtable-2level-types.h |   60 +++++
 arch/arm64/include/asm/pgtable-3level-hwdef.h |   50 ++++
 arch/arm64/include/asm/pgtable-3level-types.h |   66 +++++
 arch/arm64/include/asm/pgtable-hwdef.h        |   94 +++++++
 arch/arm64/include/asm/pgtable.h              |  328 +++++++++++++++++++++++++
 arch/arm64/include/asm/sparsemem.h            |   24 ++
 10 files changed, 905 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/arm64/memory.txt
 create mode 100644 arch/arm64/include/asm/memory.h
 create mode 100644 arch/arm64/include/asm/mmu.h
 create mode 100644 arch/arm64/include/asm/pgtable-2level-hwdef.h
 create mode 100644 arch/arm64/include/asm/pgtable-2level-types.h
 create mode 100644 arch/arm64/include/asm/pgtable-3level-hwdef.h
 create mode 100644 arch/arm64/include/asm/pgtable-3level-types.h
 create mode 100644 arch/arm64/include/asm/pgtable-hwdef.h
 create mode 100644 arch/arm64/include/asm/pgtable.h
 create mode 100644 arch/arm64/include/asm/sparsemem.h
Documentation/arm64/memory.txt new file +69 -0
new file mode 100644
index 0000000..7210af7
@@ -0,0 +1,69 @@
+		     Memory Layout on AArch64 Linux
+		     ==============================
+
+Author: Catalin Marinas <[email protected]>
+Date  : 20 February 2012
+
+This document describes the virtual memory layout used by the AArch64
+Linux kernel. The architecture allows up to 4 levels of translation
+tables with a 4KB page size and up to 3 levels with a 64KB page size.
+
+AArch64 Linux uses 3 levels of translation tables with the 4KB page
+configuration, allowing 39-bit (512GB) virtual addresses for both user
+and kernel. With 64KB pages, only 2 levels of translation tables are
+used but the memory layout is the same.
+
+User addresses have bits 63:39 set to 0 while the kernel addresses have
+the same bits set to 1. TTBRx selection is given by bit 63 of the
+virtual address. The swapper_pg_dir contains only kernel (global)
+mappings while the user pgd contains only user (non-global) mappings.
+The swapper_pgd_dir address is written to TTBR1 and never written to
+TTBR0.
+
+
+AArch64 Linux memory layout:
+
+Start			End			Size		Use
+-----------------------------------------------------------------------
+0000000000000000	0000007fffffffff	 512GB		user
+
+ffffff8000000000	ffffffbbfffeffff	~240GB		vmalloc
+
+ffffffbbffff0000	ffffffbcffffffff	  64KB		[guard page]
+
+ffffffbc00000000	ffffffbdffffffff	   8GB		vmemmap
+
+ffffffbe00000000	ffffffbffbffffff	  ~8GB		[guard, future vmmemap]
+
+ffffffbffc000000	ffffffbfffffffff	  64MB		modules
+
+ffffffc000000000	ffffffffffffffff	 256GB		memory
+
+
+Translation table lookup with 4KB pages:
+
++--------+--------+--------+--------+--------+--------+--------+--------+
+|63    56|55    48|47    40|39    32|31    24|23    16|15     8|7      0|
++--------+--------+--------+--------+--------+--------+--------+--------+
+ |                 |         |         |         |         |
+ |                 |         |         |         |         v
+ |                 |         |         |         |   [11:0]  in-page offset
+ |                 |         |         |         +-> [20:12] L3 index
+ |                 |         |         +-----------> [29:21] L2 index
+ |                 |         +---------------------> [38:30] L1 index
+ |                 +-------------------------------> [47:39] L0 index (not used)
+ +-------------------------------------------------> [63] TTBR0/1
+
+
+Translation table lookup with 64KB pages:
+
++--------+--------+--------+--------+--------+--------+--------+--------+
+|63    56|55    48|47    40|39    32|31    24|23    16|15     8|7      0|
++--------+--------+--------+--------+--------+--------+--------+--------+
+ |                 |    |               |              |
+ |                 |    |               |              v
+ |                 |    |               |            [15:0]  in-page offset
+ |                 |    |               +----------> [28:16] L3 index
+ |                 |    +--------------------------> [41:29] L2 index (only 38:29 used)
+ |                 +-------------------------------> [47:42] L1 index (not used)
+ +-------------------------------------------------> [63] TTBR0/1
arch/arm64/include/asm/memory.h new file +144 -0

144 lines not on this page · raw message

arch/arm64/include/asm/mmu.h new file +27 -0
new file mode 100644
index 0000000..981498a
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_MMU_H
+#define __ASM_MMU_H
+
+typedef struct {
+	unsigned int id;
+	spinlock_t id_lock;
+	void *vdso;
+} mm_context_t;
+
+#define ASID(mm)	((mm)->context.id & 0xffff)
+
+#endif
arch/arm64/include/asm/pgtable-2level-hwdef.h new file +43 -0

43 lines not on this page · raw message

arch/arm64/include/asm/pgtable-2level-types.h new file +60 -0

60 lines not on this page · raw message

arch/arm64/include/asm/pgtable-3level-hwdef.h new file +50 -0

50 lines not on this page · raw message

arch/arm64/include/asm/pgtable-3level-types.h new file +66 -0

66 lines not on this page · raw message

arch/arm64/include/asm/pgtable-hwdef.h new file +94 -0

94 lines not on this page · raw message

arch/arm64/include/asm/pgtable.h new file +328 -0

328 lines not on this page · raw message

arch/arm64/include/asm/sparsemem.h new file +24 -0
new file mode 100644
index 0000000..1be62bc
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SPARSEMEM_H
+#define __ASM_SPARSEMEM_H
+
+#ifdef CONFIG_SPARSEMEM
+#define MAX_PHYSMEM_BITS	40
+#define SECTION_SIZE_BITS	30
+#endif
+
+#endif
author maintainer
#36 lore raw

PATCH v2 5/31 arm64: MMU initialisation

In reply to Catalin Marinas

This patch contains the initialisation of the memory blocks, MMU attributes and the memory map. Only five memory types are defined:
Device nGnRnE (equivalent to Strongly Ordered), Device nGnRE (classic Device memory), Device GRE, Normal Non-cacheable and Normal Cacheable. Cache policies are supported via the memory attributes register (MAIR_EL1) and only affect the Normal Cacheable mappings.

This patch also adds the SPARSEMEM_VMEMMAP initialisation.

---
 arch/arm64/include/asm/memblock.h |   21 ++
 arch/arm64/mm/init.c              |  416 +++++++++++++++++++++++++++++++++++++
 arch/arm64/mm/mmu.c               |  395 +++++++++++++++++++++++++++++++++++
 3 files changed, 832 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/memblock.h
 create mode 100644 arch/arm64/mm/init.c
 create mode 100644 arch/arm64/mm/mmu.c
arch/arm64/include/asm/memblock.h new file +21 -0
new file mode 100644
index 0000000..6afeed2
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_MEMBLOCK_H
+#define __ASM_MEMBLOCK_H
+
+extern void arm64_memblock_init(void);
+
+#endif
arch/arm64/mm/init.c new file +416 -0

416 lines not on this page · raw message

arch/arm64/mm/mmu.c new file +395 -0

395 lines not on this page · raw message

author maintainer
#41 lore raw

PATCH v2 6/31 arm64: MMU fault handling and page table management

In reply to Catalin Marinas

This patch adds support for the handling of the MMU faults (exception entry code introduced by a previous patch) and page table management.

The user translation table is pointed to by TTBR0 and the kernel one (swapper_pg_dir) by TTBR1. There is no translation information shared or address space overlapping between user and kernel page tables.

---
 arch/arm64/include/asm/page.h    |   67 +++++
 arch/arm64/include/asm/pgalloc.h |  113 ++++++++
 arch/arm64/mm/copypage.c         |   34 +++
 arch/arm64/mm/extable.c          |   17 ++
 arch/arm64/mm/fault.c            |  534 ++++++++++++++++++++++++++++++++++++++
 arch/arm64/mm/mm.h               |    2 +
 arch/arm64/mm/mmap.c             |  144 ++++++++++
 arch/arm64/mm/pgd.c              |   49 ++++
 8 files changed, 960 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/page.h
 create mode 100644 arch/arm64/include/asm/pgalloc.h
 create mode 100644 arch/arm64/mm/copypage.c
 create mode 100644 arch/arm64/mm/extable.c
 create mode 100644 arch/arm64/mm/fault.c
 create mode 100644 arch/arm64/mm/mm.h
 create mode 100644 arch/arm64/mm/mmap.c
 create mode 100644 arch/arm64/mm/pgd.c
arch/arm64/include/asm/page.h new file +67 -0
new file mode 100644
index 0000000..46bf666
@@ -0,0 +1,67 @@
+/*
+ * Based on arch/arm/include/asm/page.h
+ *
+ * Copyright (C) 1995-2003 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_PAGE_H
+#define __ASM_PAGE_H
+
+/* PAGE_SHIFT determines the page size */
+#ifdef CONFIG_ARM64_64K_PAGES
+#define PAGE_SHIFT		16
+#else
+#define PAGE_SHIFT		12
+#endif
+#define PAGE_SIZE		(_AC(1,UL) << PAGE_SHIFT)
+#define PAGE_MASK		(~(PAGE_SIZE-1))
+
+/* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */
+#define __HAVE_ARCH_GATE_AREA		1
+
+#ifndef __ASSEMBLY__
+
+#ifdef CONFIG_ARM64_64K_PAGES
+#include <asm/pgtable-2level-types.h>
+#else
+#include <asm/pgtable-3level-types.h>
+#endif
+
+extern void __cpu_clear_user_page(void *p, unsigned long user);
+extern void __cpu_copy_user_page(void *to, const void *from,
+				 unsigned long user);
+extern void copy_page(void *to, const void *from);
+extern void clear_page(void *to);
+
+#define clear_user_page(addr,vaddr,pg)  __cpu_clear_user_page(addr, vaddr)
+#define copy_user_page(to,from,vaddr,pg) __cpu_copy_user_page(to, from, vaddr)
+
+typedef struct page *pgtable_t;
+
+#ifdef CONFIG_HAVE_ARCH_PFN_VALID
+extern int pfn_valid(unsigned long);
+#endif
+
+#include <asm/memory.h>
+
+#endif /* !__ASSEMBLY__ */
+
+#define VM_DATA_DEFAULT_FLAGS \
+	(((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
+	 VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
+
+#include <asm-generic/getorder.h>
+
+#endif
arch/arm64/include/asm/pgalloc.h new file +113 -0

113 lines not on this page · raw message

arch/arm64/mm/copypage.c new file +34 -0
new file mode 100644
index 0000000..9361662
@@ -0,0 +1,34 @@
+/*
+ * Based on arch/arm/mm/copypage.c
+ *
+ * Copyright (C) 2002 Deep Blue Solutions Ltd, All Rights Reserved.
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/mm.h>
+
+#include <asm/page.h>
+#include <asm/cacheflush.h>
+
+void __cpu_copy_user_page(void *kto, const void *kfrom, unsigned long vaddr)
+{
+	copy_page(kto, kfrom);
+	__cpuc_flush_dcache_area(kto, PAGE_SIZE);
+}
+
+void __cpu_clear_user_page(void *kaddr, unsigned long vaddr)
+{
+	clear_page(kaddr);
+}
arch/arm64/mm/extable.c new file +17 -0
new file mode 100644
index 0000000..7944427
@@ -0,0 +1,17 @@
+/*
+ * Based on arch/arm/mm/extable.c
+ */
+
+#include <linux/module.h>
+#include <linux/uaccess.h>
+
+int fixup_exception(struct pt_regs *regs)
+{
+	const struct exception_table_entry *fixup;
+
+	fixup = search_exception_tables(instruction_pointer(regs));
+	if (fixup)
+		regs->pc = fixup->fixup;
+
+	return fixup != NULL;
+}
arch/arm64/mm/fault.c new file +534 -0

534 lines not on this page · raw message

arch/arm64/mm/mm.h new file +2 -0
new file mode 100644
index 0000000..c84f68b
@@ -0,0 +1,2 @@
+extern void __flush_dcache_page(struct address_space *mapping, struct page *page);
+extern void __init bootmem_init(void);
arch/arm64/mm/mmap.c new file +144 -0

144 lines not on this page · raw message

arch/arm64/mm/pgd.c new file +49 -0

49 lines not on this page · raw message

author maintainer
#44 lore raw

PATCH v2 7/31 arm64: Process management

In reply to Catalin Marinas

The patch adds support for thread creation and context switching. The context switching CPU specific code is introduced with the CPU support patch (part of the arch/arm64/mm/proc.S file). AArch64 supports ASID-tagged TLBs and the ASID can be either 8 or 16-bit wide (detectable via the ID_AA64AFR0_EL1 register).

---
 arch/arm64/include/asm/mmu_context.h |  152 +++++++++++++
 arch/arm64/include/asm/thread_info.h |  124 ++++++++++
 arch/arm64/kernel/process.c          |  416 ++++++++++++++++++++++++++++++++++
 arch/arm64/mm/context.c              |  159 +++++++++++++
 4 files changed, 851 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/mmu_context.h
 create mode 100644 arch/arm64/include/asm/thread_info.h
 create mode 100644 arch/arm64/kernel/process.c
 create mode 100644 arch/arm64/mm/context.c
arch/arm64/include/asm/mmu_context.h new file +152 -0
new file mode 100644
index 0000000..f68465d
@@ -0,0 +1,152 @@
+/*
+ * Based on arch/arm/include/asm/mmu_context.h
+ *
+ * Copyright (C) 1996 Russell King.
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_MMU_CONTEXT_H
+#define __ASM_MMU_CONTEXT_H
+
+#include <linux/compiler.h>
+#include <linux/sched.h>
+
+#include <asm/cacheflush.h>
+#include <asm/proc-fns.h>
+#include <asm-generic/mm_hooks.h>
+#include <asm/cputype.h>
+#include <asm/pgtable.h>
+
+#define MAX_ASID_BITS	16
+
+extern unsigned int cpu_last_asid;
+
+void __init_new_context(struct task_struct *tsk, struct mm_struct *mm);
+void __new_context(struct mm_struct *mm);
+
+/*
+ * Set TTBR0 to empty_zero_page. No translations will be possible via TTBR0.
+ */
+static inline void cpu_set_reserved_ttbr0(void)
+{
+	unsigned long ttbr = page_to_phys(empty_zero_page);
+
+	asm(
+	"	msr	ttbr0_el1, %0			// set TTBR0\n"
+	"	isb"
+	:
+	: "r" (ttbr));
+}
+
+static inline void switch_new_context(struct mm_struct *mm)
+{
+	unsigned long flags;
+
+	__new_context(mm);
+
+	local_irq_save(flags);
+	cpu_switch_mm(mm->pgd, mm);
+	local_irq_restore(flags);
+}
+
+static inline void check_and_switch_context(struct mm_struct *mm,
+					    struct task_struct *tsk)
+{
+	/*
+	 * Required during context switch to avoid speculative page table
+	 * walking with the wrong TTBR.
+	 */
+	cpu_set_reserved_ttbr0();
+
+	if (!((mm->context.id ^ cpu_last_asid) >> MAX_ASID_BITS))
+		/*
+		 * The ASID is from the current generation, just switch to the
+		 * new pgd. This condition is only true for calls from
+		 * context_switch() and interrupts are already disabled.
+		 */
+		cpu_switch_mm(mm->pgd, mm);
+	else if (irqs_disabled())
+		/*
+		 * Defer the new ASID allocation until after the context
+		 * switch critical region since __new_context() cannot be
+		 * called with interrupts disabled.
+		 */
+		set_ti_thread_flag(task_thread_info(tsk), TIF_SWITCH_MM);
+	else
+		/*
+		 * That is a direct call to switch_mm() or activate_mm() with
+		 * interrupts enabled and a new context.
+		 */
+		switch_new_context(mm);
+}
+
+#define init_new_context(tsk,mm)	(__init_new_context(tsk,mm),0)
+#define destroy_context(mm)		do { } while(0)
+
+#define finish_arch_post_lock_switch \
+	finish_arch_post_lock_switch
+static inline void finish_arch_post_lock_switch(void)
+{
+	if (test_and_clear_thread_flag(TIF_SWITCH_MM)) {
+		struct mm_struct *mm = current->mm;
+		unsigned long flags;
+
+		__new_context(mm);
+
+		local_irq_save(flags);
+		cpu_switch_mm(mm->pgd, mm);
+		local_irq_restore(flags);
+	}
+}
+
+/*
+ * This is called when "tsk" is about to enter lazy TLB mode.
+ *
+ * mm:  describes the currently active mm context
+ * tsk: task which is entering lazy tlb
+ * cpu: cpu number which is entering lazy tlb
+ *
+ * tsk->mm will be NULL
+ */
+static inline void
+enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
+{
+}
+
+/*
+ * This is the actual mm switch as far as the scheduler
+ * is concerned.  No registers are touched.  We avoid
+ * calling the CPU specific function when the mm hasn't
+ * actually changed.
+ */
+static inline void
+switch_mm(struct mm_struct *prev, struct mm_struct *next,
+	  struct task_struct *tsk)
+{
+	unsigned int cpu = smp_processor_id();
+
+#ifdef CONFIG_SMP
+	/* check for possible thread migration */
+	if (!cpumask_empty(mm_cpumask(next)) &&
+	    !cpumask_test_cpu(cpu, mm_cpumask(next)))
+		__flush_icache_all();
+#endif
+	if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next)
+		check_and_switch_context(next, tsk);
+}
+
+#define deactivate_mm(tsk,mm)	do { } while (0)
+#define activate_mm(prev,next)	switch_mm(prev, next, NULL)
+
+#endif
arch/arm64/include/asm/thread_info.h new file +124 -0

124 lines not on this page · raw message

arch/arm64/kernel/process.c new file +416 -0

416 lines not on this page · raw message

arch/arm64/mm/context.c new file +159 -0

159 lines not on this page · raw message

author maintainer
#51 lore raw

PATCH v2 8/31 arm64: CPU support

In reply to Catalin Marinas

This patch adds AArch64 CPU specific functionality. It assumes that the implementation is generic to AArch64 and does not require specific identification. Different CPU implementations may require the setting of various ACTLR_EL1 bits but such information is not currently available and it should ideally be pushed to firmware.

---
 arch/arm64/include/asm/cputype.h   |   49 +++++++++
 arch/arm64/include/asm/proc-fns.h  |   51 ++++++++++
 arch/arm64/include/asm/processor.h |  174 ++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/procinfo.h  |   44 ++++++++
 arch/arm64/mm/proc-syms.c          |   31 ++++++
 arch/arm64/mm/proc.S               |  193 ++++++++++++++++++++++++++++++++++++
 6 files changed, 542 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/cputype.h
 create mode 100644 arch/arm64/include/asm/proc-fns.h
 create mode 100644 arch/arm64/include/asm/processor.h
 create mode 100644 arch/arm64/include/asm/procinfo.h
 create mode 100644 arch/arm64/mm/proc-syms.c
 create mode 100644 arch/arm64/mm/proc.S
arch/arm64/include/asm/cputype.h new file +49 -0
new file mode 100644
index 0000000..ef54125
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_CPUTYPE_H
+#define __ASM_CPUTYPE_H
+
+#define ID_MIDR_EL1		"midr_el1"
+#define ID_CTR_EL0		"ctr_el0"
+
+#define ID_AA64PFR0_EL1		"id_aa64pfr0_el1"
+#define ID_AA64DFR0_EL1		"id_aa64dfr0_el1"
+#define ID_AA64AFR0_EL1		"id_aa64afr0_el1"
+#define ID_AA64ISAR0_EL1	"id_aa64isar0_el1"
+#define ID_AA64MMFR0_EL1	"id_aa64mmfr0_el1"
+
+#define read_cpuid(reg) ({						\
+	u64 __val;							\
+	asm("mrs	%0, " reg : "=r" (__val));			\
+	__val;								\
+})
+
+/*
+ * The CPU ID never changes at run time, so we might as well tell the
+ * compiler that it's constant.  Use this function to read the CPU ID
+ * rather than directly reading processor_id or read_cpuid() directly.
+ */
+static inline u32 __attribute_const__ read_cpuid_id(void)
+{
+	return read_cpuid(ID_MIDR_EL1);
+}
+
+static inline u32 __attribute_const__ read_cpuid_cachetype(void)
+{
+	return read_cpuid(ID_CTR_EL0);
+}
+
+#endif
arch/arm64/include/asm/proc-fns.h new file +51 -0

51 lines not on this page · raw message

arch/arm64/include/asm/processor.h new file +174 -0

174 lines not on this page · raw message

arch/arm64/include/asm/procinfo.h new file +44 -0

44 lines not on this page · raw message

arch/arm64/mm/proc-syms.c new file +31 -0
new file mode 100644
index 0000000..2d99ef9
@@ -0,0 +1,31 @@
+/*
+ * Based on arch/arm/mm/proc-syms.c
+ *
+ * Copyright (C) 2000-2002 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/export.h>
+#include <linux/mm.h>
+
+#include <asm/cacheflush.h>
+#include <asm/proc-fns.h>
+#include <asm/tlbflush.h>
+#include <asm/page.h>
+
+EXPORT_SYMBOL(__cpuc_flush_kern_all);
+EXPORT_SYMBOL(__cpuc_flush_user_all);
+EXPORT_SYMBOL(__cpuc_flush_user_range);
+EXPORT_SYMBOL(__cpuc_coherent_kern_range);
+EXPORT_SYMBOL(__cpuc_flush_dcache_area);
arch/arm64/mm/proc.S new file +193 -0

193 lines not on this page · raw message

author maintainer
#59 lore raw

PATCH v2 9/31 arm64: Cache maintenance routines

In reply to Catalin Marinas

The patch adds functionality required for cache maintenance. The AArch64 architecture mandates non-aliasing VIPT or PIPT D-cache and VIPT (may have aliases) or ASID-tagged VIVT I-cache. Cache maintenance operations are automatically broadcast in hardware between CPUs.

---
 arch/arm64/include/asm/cache.h      |   32 ++++
 arch/arm64/include/asm/cacheflush.h |  209 ++++++++++++++++++++++++++
 arch/arm64/include/asm/cachetype.h  |   48 ++++++
 arch/arm64/mm/cache.S               |  279 +++++++++++++++++++++++++++++++++++
 arch/arm64/mm/flush.c               |  132 +++++++++++++++++
 5 files changed, 700 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/cache.h
 create mode 100644 arch/arm64/include/asm/cacheflush.h
 create mode 100644 arch/arm64/include/asm/cachetype.h
 create mode 100644 arch/arm64/mm/cache.S
 create mode 100644 arch/arm64/mm/flush.c
arch/arm64/include/asm/cache.h new file +32 -0
new file mode 100644
index 0000000..390308a
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_CACHE_H
+#define __ASM_CACHE_H
+
+#define L1_CACHE_SHIFT		6
+#define L1_CACHE_BYTES		(1 << L1_CACHE_SHIFT)
+
+/*
+ * Memory returned by kmalloc() may be used for DMA, so we must make
+ * sure that all such allocations are cache aligned. Otherwise,
+ * unrelated code may cause parts of the buffer to be read into the
+ * cache before the transfer is done, causing old data to be seen by
+ * the CPU.
+ */
+#define ARCH_DMA_MINALIGN	L1_CACHE_BYTES
+#define ARCH_SLAB_MINALIGN	8
+
+#endif
arch/arm64/include/asm/cacheflush.h new file +209 -0

209 lines not on this page · raw message

arch/arm64/include/asm/cachetype.h new file +48 -0

48 lines not on this page · raw message

arch/arm64/mm/cache.S new file +279 -0

279 lines not on this page · raw message

arch/arm64/mm/flush.c new file +132 -0

132 lines not on this page · raw message

author maintainer
#63 lore raw

PATCH v2 10/31 arm64: TLB maintenance functionality

In reply to Catalin Marinas

This patch adds the TLB maintenance functions. There is no distinction made between the I and D TLBs. TLB maintenance operations are automatically broadcast between CPUs in hardware. The inner-shareable operations are always present, even on UP systems.

NOTE: Large part of this patch to be dropped once Peter Z's generic mmu_gather patches are merged.

---
 arch/arm64/include/asm/tlb.h      |  190 +++++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/tlbflush.h |  123 ++++++++++++++++++++++++
 arch/arm64/mm/tlb.S               |   71 ++++++++++++++
 3 files changed, 384 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/tlb.h
 create mode 100644 arch/arm64/include/asm/tlbflush.h
 create mode 100644 arch/arm64/mm/tlb.S
arch/arm64/include/asm/tlb.h new file +190 -0
new file mode 100644
index 0000000..654f096
@@ -0,0 +1,190 @@
+/*
+ * Based on arch/arm/include/asm/tlb.h
+ *
+ * Copyright (C) 2002 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_TLB_H
+#define __ASM_TLB_H
+
+#include <linux/pagemap.h>
+#include <linux/swap.h>
+
+#include <asm/pgalloc.h>
+#include <asm/tlbflush.h>
+
+#define MMU_GATHER_BUNDLE	8
+
+/*
+ * TLB handling.  This allows us to remove pages from the page
+ * tables, and efficiently handle the TLB issues.
+ */
+struct mmu_gather {
+	struct mm_struct	*mm;
+	unsigned int		fullmm;
+	struct vm_area_struct	*vma;
+	unsigned long		range_start;
+	unsigned long		range_end;
+	unsigned int		nr;
+	unsigned int		max;
+	struct page		**pages;
+	struct page		*local[MMU_GATHER_BUNDLE];
+};
+
+/*
+ * This is unnecessarily complex.  There's three ways the TLB shootdown
+ * code is used:
+ *  1. Unmapping a range of vmas.  See zap_page_range(), unmap_region().
+ *     tlb->fullmm = 0, and tlb_start_vma/tlb_end_vma will be called.
+ *     tlb->vma will be non-NULL.
+ *  2. Unmapping all vmas.  See exit_mmap().
+ *     tlb->fullmm = 1, and tlb_start_vma/tlb_end_vma will be called.
+ *     tlb->vma will be non-NULL.  Additionally, page tables will be freed.
+ *  3. Unmapping argument pages.  See shift_arg_pages().
+ *     tlb->fullmm = 0, but tlb_start_vma/tlb_end_vma will not be called.
+ *     tlb->vma will be NULL.
+ */
+static inline void tlb_flush(struct mmu_gather *tlb)
+{
+	if (tlb->fullmm || !tlb->vma)
+		flush_tlb_mm(tlb->mm);
+	else if (tlb->range_end > 0) {
+		flush_tlb_range(tlb->vma, tlb->range_start, tlb->range_end);
+		tlb->range_start = TASK_SIZE;
+		tlb->range_end = 0;
+	}
+}
+
+static inline void tlb_add_flush(struct mmu_gather *tlb, unsigned long addr)
+{
+	if (!tlb->fullmm) {
+		if (addr < tlb->range_start)
+			tlb->range_start = addr;
+		if (addr + PAGE_SIZE > tlb->range_end)
+			tlb->range_end = addr + PAGE_SIZE;
+	}
+}
+
+static inline void __tlb_alloc_page(struct mmu_gather *tlb)
+{
+	unsigned long addr = __get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0);
+
+	if (addr) {
+		tlb->pages = (void *)addr;
+		tlb->max = PAGE_SIZE / sizeof(struct page *);
+	}
+}
+
+static inline void tlb_flush_mmu(struct mmu_gather *tlb)
+{
+	tlb_flush(tlb);
+	free_pages_and_swap_cache(tlb->pages, tlb->nr);
+	tlb->nr = 0;
+	if (tlb->pages == tlb->local)
+		__tlb_alloc_page(tlb);
+}
+
+static inline void
+tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned int fullmm)
+{
+	tlb->mm = mm;
+	tlb->fullmm = fullmm;
+	tlb->vma = NULL;
+	tlb->max = ARRAY_SIZE(tlb->local);
+	tlb->pages = tlb->local;
+	tlb->nr = 0;
+	__tlb_alloc_page(tlb);
+}
+
+static inline void
+tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
+{
+	tlb_flush_mmu(tlb);
+
+	/* keep the page table cache within bounds */
+	check_pgt_cache();
+
+	if (tlb->pages != tlb->local)
+		free_pages((unsigned long)tlb->pages, 0);
+}
+
+/*
+ * Memorize the range for the TLB flush.
+ */
+static inline void
+tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long addr)
+{
+	tlb_add_flush(tlb, addr);
+}
+
+/*
+ * In the case of tlb vma handling, we can optimise these away in the
+ * case where we're doing a full MM flush.  When we're doing a munmap,
+ * the vmas are adjusted to only cover the region to be torn down.
+ */
+static inline void
+tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
+{
+	if (!tlb->fullmm) {
+		tlb->vma = vma;
+		tlb->range_start = TASK_SIZE;
+		tlb->range_end = 0;
+	}
+}
+
+static inline void
+tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
+{
+	if (!tlb->fullmm)
+		tlb_flush(tlb);
+}
+
+static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
+{
+	tlb->pages[tlb->nr++] = page;
+	VM_BUG_ON(tlb->nr > tlb->max);
+	return tlb->max - tlb->nr;
+}
+
+static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
+{
+	if (!__tlb_remove_page(tlb, page))
+		tlb_flush_mmu(tlb);
+}
+
+static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
+	unsigned long addr)
+{
+	pgtable_page_dtor(pte);
+	tlb_add_flush(tlb, addr);
+	tlb_remove_page(tlb, pte);
+}
+
+#ifndef CONFIG_ARM64_64K_PAGES
+static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
+				  unsigned long addr)
+{
+	tlb_add_flush(tlb, addr);
+	tlb_remove_page(tlb, virt_to_page(pmdp));
+}
+#endif
+
+#define pte_free_tlb(tlb, ptep, addr)	__pte_free_tlb(tlb, ptep, addr)
+#define pmd_free_tlb(tlb, pmdp, addr)	__pmd_free_tlb(tlb, pmdp, addr)
+#define pud_free_tlb(tlb, pudp, addr)	pud_free((tlb)->mm, pudp)
+
+#define tlb_migrate_finish(mm)		do { } while (0)
+
+#endif
arch/arm64/include/asm/tlbflush.h new file +123 -0

123 lines not on this page · raw message

arch/arm64/mm/tlb.S new file +71 -0

71 lines not on this page · raw message

author maintainer
#64 lore raw

PATCH v2 11/31 arm64: IRQ handling

In reply to Catalin Marinas

From: Marc Zyngier <[email protected]>

This patch adds the support for IRQ handling. The actual interrupt controller will be part of a separate patch (going into drivers/irqchip/).

---
 arch/arm64/include/asm/hardirq.h  |   47 +++++++++++++++++++
 arch/arm64/include/asm/irq.h      |    8 +++
 arch/arm64/include/asm/irqflags.h |   91 +++++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/irq.c           |   84 ++++++++++++++++++++++++++++++++++
 4 files changed, 230 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/hardirq.h
 create mode 100644 arch/arm64/include/asm/irq.h
 create mode 100644 arch/arm64/include/asm/irqflags.h
 create mode 100644 arch/arm64/kernel/irq.c
arch/arm64/include/asm/hardirq.h new file +47 -0
new file mode 100644
index 0000000..c6c9514
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_HARDIRQ_H
+#define __ASM_HARDIRQ_H
+
+#include <linux/cache.h>
+#include <linux/threads.h>
+#include <asm/irq.h>
+
+typedef struct {
+	unsigned int __softirq_pending;
+} ____cacheline_aligned irq_cpustat_t;
+
+#include <linux/irq_cpustat.h>	/* Standard mappings for irq_cpustat_t above */
+
+#define __inc_irq_stat(cpu, member)	__IRQ_STAT(cpu, member)++
+#define __get_irq_stat(cpu, member)	__IRQ_STAT(cpu, member)
+
+#ifdef CONFIG_SMP
+u64 smp_irq_stat_cpu(unsigned int cpu);
+#define arch_irq_stat_cpu	smp_irq_stat_cpu
+#endif
+
+#define __ARCH_IRQ_EXIT_IRQS_DISABLED	1
+
+static inline void ack_bad_irq(unsigned int irq)
+{
+	extern unsigned long irq_err_count;
+	irq_err_count++;
+}
+
+extern void handle_IRQ(unsigned int, struct pt_regs *);
+
+#endif /* __ASM_HARDIRQ_H */
arch/arm64/include/asm/irq.h new file +8 -0
new file mode 100644
index 0000000..a4e1cad
@@ -0,0 +1,8 @@
+#ifndef __ASM_IRQ_H
+#define __ASM_IRQ_H
+
+#include <asm-generic/irq.h>
+
+extern void (*handle_arch_irq)(struct pt_regs *);
+
+#endif
arch/arm64/include/asm/irqflags.h new file +91 -0

91 lines not on this page · raw message

arch/arm64/kernel/irq.c new file +84 -0

84 lines not on this page · raw message

author maintainer
#66 lore raw

PATCH v2 12/31 arm64: Atomic operations

In reply to Catalin Marinas

This patch introduces the atomic, mutex and futex operations. Many atomic operations use the load-acquire and store-release operations which imply barriers, avoiding the need for explicit DMB.

---
 arch/arm64/include/asm/atomic.h |  306 +++++++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/futex.h  |  134 +++++++++++++++++
 2 files changed, 440 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/atomic.h
 create mode 100644 arch/arm64/include/asm/futex.h
arch/arm64/include/asm/atomic.h new file +306 -0
new file mode 100644
index 0000000..fa60c8b
@@ -0,0 +1,306 @@
+/*
+ * Based on arch/arm/include/asm/atomic.h
+ *
+ * Copyright (C) 1996 Russell King.
+ * Copyright (C) 2002 Deep Blue Solutions Ltd.
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_ATOMIC_H
+#define __ASM_ATOMIC_H
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+#include <asm/barrier.h>
+#include <asm/cmpxchg.h>
+
+#define ATOMIC_INIT(i)	{ (i) }
+
+#ifdef __KERNEL__
+
+/*
+ * On ARM, ordinary assignment (str instruction) doesn't clear the local
+ * strex/ldrex monitor on some implementations. The reason we can use it for
+ * atomic_set() is the clrex or dummy strex done on every exception return.
+ */
+#define atomic_read(v)	(*(volatile int *)&(v)->counter)
+#define atomic_set(v,i)	(((v)->counter) = (i))
+
+/*
+ * AArch64 UP and SMP safe atomic ops.  We use load exclusive and
+ * store exclusive to ensure that these are atomic.  We may loop
+ * to ensure that the update happens.
+ */
+static inline void atomic_add(int i, atomic_t *v)
+{
+	unsigned long tmp;
+	int result;
+
+	asm volatile("// atomic_add\n"
+"1:	ldxr	%w0, [%3]\n"
+"	add	%w0, %w0, %w4\n"
+"	stxr	%w1, %w0, [%3]\n"
+"	cbnz	%w1,1b"
+	: "=&r" (result), "=&r" (tmp), "+o" (v->counter)
+	: "r" (&v->counter), "Ir" (i)
+	: "cc");
+}
+
+static inline int atomic_add_return(int i, atomic_t *v)
+{
+	unsigned long tmp;
+	int result;
+
+	asm volatile("// atomic_add_return\n"
+"1:	ldaxr	%w0, [%3]\n"
+"	add	%w0, %w0, %w4\n"
+"	stlxr	%w1, %w0, [%3]\n"
+"	cbnz	%w1, 1b"
+	: "=&r" (result), "=&r" (tmp), "+o" (v->counter)
+	: "r" (&v->counter), "Ir" (i)
+	: "cc");
+
+	return result;
+}
+
+static inline void atomic_sub(int i, atomic_t *v)
+{
+	unsigned long tmp;
+	int result;
+
+	asm volatile("// atomic_sub\n"
+"1:	ldxr	%w0, [%3]\n"
+"	sub	%w0, %w0, %w4\n"
+"	stxr	%w1, %w0, [%3]\n"
+"	cbnz	%w1, 1b"
+	: "=&r" (result), "=&r" (tmp), "+o" (v->counter)
+	: "r" (&v->counter), "Ir" (i)
+	: "cc");
+}
+
+static inline int atomic_sub_return(int i, atomic_t *v)
+{
+	unsigned long tmp;
+	int result;
+
+	asm volatile("// atomic_sub_return\n"
+"1:	ldaxr	%w0, [%3]\n"
+"	sub	%w0, %w0, %w4\n"
+"	stlxr	%w1, %w0, [%3]\n"
+"	cbnz	%w1, 1b"
+	: "=&r" (result), "=&r" (tmp), "+o" (v->counter)
+	: "r" (&v->counter), "Ir" (i)
+	: "cc");
+
+	return result;
+}
+
+static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
+{
+	unsigned long tmp;
+	int oldval;
+
+	asm volatile("// atomic_cmpxchg\n"
+"1:	ldaxr	%w1, [%3]\n"
+"	cmp	%w1, %w4\n"
+"	b.ne	2f\n"
+"	stlxr	%w0, %w5, [%3]\n"
+"	cbnz	%w0, 1b\n"
+"2:"
+	: "=&r" (tmp), "=&r" (oldval), "+o" (ptr->counter)
+	: "r" (&ptr->counter), "Ir" (old), "r" (new)
+	: "cc");
+
+	return oldval;
+}
+
+static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
+{
+	unsigned long tmp, tmp2;
+
+	asm volatile("// atomic_clear_mask\n"
+"1:	ldxr	%0, [%3]\n"
+"	bic	%0, %0, %4\n"
+"	stxr	%w1, %0, [%3]\n"
+"	cbnz	%w1, 1b"
+	: "=&r" (tmp), "=&r" (tmp2), "+o" (*addr)
+	: "r" (addr), "Ir" (mask)
+	: "cc");
+}
+
+#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
+
+static inline int __atomic_add_unless(atomic_t *v, int a, int u)
+{
+	int c, old;
+
+	c = atomic_read(v);
+	while (c != u && (old = atomic_cmpxchg((v), c, c + a)) != c)
+		c = old;
+	return c;
+}
+
+#define atomic_inc(v)		atomic_add(1, v)
+#define atomic_dec(v)		atomic_sub(1, v)
+
+#define atomic_inc_and_test(v)	(atomic_add_return(1, v) == 0)
+#define atomic_dec_and_test(v)	(atomic_sub_return(1, v) == 0)
+#define atomic_inc_return(v)    (atomic_add_return(1, v))
+#define atomic_dec_return(v)    (atomic_sub_return(1, v))
+#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
+
+#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
+
+#define smp_mb__before_atomic_dec()	smp_mb()
+#define smp_mb__after_atomic_dec()	smp_mb()
+#define smp_mb__before_atomic_inc()	smp_mb()
+#define smp_mb__after_atomic_inc()	smp_mb()
+
+/*
+ * 64-bit atomic operations.
+ */
+#define ATOMIC64_INIT(i) { (i) }
+
+#define atomic64_read(v)	(*(volatile long long *)&(v)->counter)
+#define atomic64_set(v,i)	(((v)->counter) = (i))
+
+static inline void atomic64_add(u64 i, atomic64_t *v)
+{
+	long result;
+	unsigned long tmp;
+
+	asm volatile("// atomic64_add\n"
+"1:	ldxr	%0, [%3]\n"
+"	add	%0, %0, %4\n"
+"	stxr	%w1, %0, [%3]\n"
+"	cbnz	%w1, 1b"
+	: "=&r" (result), "=&r" (tmp), "+o" (v->counter)
+	: "r" (&v->counter), "Ir" (i)
+	: "cc");
+}
+
+static inline long atomic64_add_return(long i, atomic64_t *v)
+{
+	long result;
+	unsigned long tmp;
+
+	asm volatile("// atomic64_add_return\n"
+"1:	ldaxr	%0, [%3]\n"
+"	add	%0, %0, %4\n"
+"	stlxr	%w1, %0, [%3]\n"
+"	cbnz	%w1, 1b"
+	: "=&r" (result), "=&r" (tmp), "+o" (v->counter)
+	: "r" (&v->counter), "Ir" (i)
+	: "cc");
+
+	return result;
+}
+
+static inline void atomic64_sub(u64 i, atomic64_t *v)
+{
+	long result;
+	unsigned long tmp;
+
+	asm volatile("// atomic64_sub\n"
+"1:	ldxr	%0, [%3]\n"
+"	sub	%0, %0, %4\n"
+"	stxr	%w1, %0, [%3]\n"
+"	cbnz	%w1, 1b"
+	: "=&r" (result), "=&r" (tmp), "+o" (v->counter)
+	: "r" (&v->counter), "Ir" (i)
+	: "cc");
+}
+
+static inline long atomic64_sub_return(long i, atomic64_t *v)
+{
+	long result;
+	unsigned long tmp;
+
+	asm volatile("// atomic64_sub_return\n"
+"1:	ldaxr	%0, [%3]\n"
+"	sub	%0, %0, %4\n"
+"	stlxr	%w1, %0, [%3]\n"
+"	cbnz	%w1, 1b"
+	: "=&r" (result), "=&r" (tmp), "+o" (v->counter)
+	: "r" (&v->counter), "Ir" (i)
+	: "cc");
+
+	return result;
+}
+
+static inline long atomic64_cmpxchg(atomic64_t *ptr, long old, long new)
+{
+	long oldval;
+	unsigned long res;
+
+	asm volatile("// atomic64_cmpxchg\n"
+"1:	ldaxr	%1, [%3]\n"
+"	cmp	%1, %4\n"
+"	b.ne	2f\n"
+"	stlxr	%w0, %5, [%3]\n"
+"	cbnz	%w0, 1b\n"
+"2:"
+	: "=&r" (res), "=&r" (oldval), "+o" (ptr->counter)
+	: "r" (&ptr->counter), "Ir" (old), "r" (new)
+	: "cc");
+
+	return oldval;
+}
+
+#define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
+
+#define ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
+static inline long atomic64_dec_if_positive(atomic64_t *v)
+{
+	long result;
+	unsigned long tmp;
+
+	asm volatile("// atomic64_dec_if_positive\n"
+"1:	ldaxr	%0, [%3]\n"
+"	subs	%0, %0, #1\n"
+"	b.mi	2f\n"
+"	stlxr	%w1, %0, [%3]\n"
+"	cbnz	%w1, 1b\n"
+"2:"
+	: "=&r" (result), "=&r" (tmp), "+o" (v->counter)
+	: "r" (&v->counter)
+	: "cc");
+
+	return result;
+}
+
+static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
+{
+	long c, old;
+
+	c = atomic64_read(v);
+	while (c != u && (old = atomic64_cmpxchg((v), c, c + a)) != c)
+		c = old;
+
+	return c != u;
+}
+
+#define atomic64_add_negative(a, v)	(atomic64_add_return((a), (v)) < 0)
+#define atomic64_inc(v)			atomic64_add(1LL, (v))
+#define atomic64_inc_return(v)		atomic64_add_return(1LL, (v))
+#define atomic64_inc_and_test(v)	(atomic64_inc_return(v) == 0)
+#define atomic64_sub_and_test(a, v)	(atomic64_sub_return((a), (v)) == 0)
+#define atomic64_dec(v)			atomic64_sub(1LL, (v))
+#define atomic64_dec_return(v)		atomic64_sub_return(1LL, (v))
+#define atomic64_dec_and_test(v)	(atomic64_dec_return((v)) == 0)
+#define atomic64_inc_not_zero(v)	atomic64_add_unless((v), 1LL, 0LL)
+
+#endif
+#endif
arch/arm64/include/asm/futex.h new file +134 -0

134 lines not on this page · raw message

author maintainer
#68 lore raw

PATCH v2 13/31 arm64: Device specific operations

In reply to Catalin Marinas

This patch adds several definitions for device communication, including I/O accessors and ioremap(). The __raw_* accessors are implemented as inline asm to avoid compiler generation of post-indexed accesses (less efficient to emulate in a virtualised environment).

---
 arch/arm64/include/asm/device.h |   26 ++++
 arch/arm64/include/asm/fb.h     |   34 +++++
 arch/arm64/include/asm/io.h     |  263 +++++++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/io.c          |   64 ++++++++++
 arch/arm64/mm/ioremap.c         |   84 +++++++++++++
 5 files changed, 471 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/device.h
 create mode 100644 arch/arm64/include/asm/fb.h
 create mode 100644 arch/arm64/include/asm/io.h
 create mode 100644 arch/arm64/kernel/io.c
 create mode 100644 arch/arm64/mm/ioremap.c
arch/arm64/include/asm/device.h new file +26 -0
new file mode 100644
index 0000000..0d8453c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_DEVICE_H
+#define __ASM_DEVICE_H
+
+struct dev_archdata {
+	struct dma_map_ops *dma_ops;
+};
+
+struct pdev_archdata {
+};
+
+#endif
arch/arm64/include/asm/fb.h new file +34 -0
new file mode 100644
index 0000000..adb88a6
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_FB_H_
+#define __ASM_FB_H_
+
+#include <linux/fb.h>
+#include <linux/fs.h>
+#include <asm/page.h>
+
+static inline void fb_pgprotect(struct file *file, struct vm_area_struct *vma,
+				unsigned long off)
+{
+	vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+}
+
+static inline int fb_is_primary_device(struct fb_info *info)
+{
+	return 0;
+}
+
+#endif /* __ASM_FB_H_ */
arch/arm64/include/asm/io.h new file +263 -0

263 lines not on this page · raw message

arch/arm64/kernel/io.c new file +64 -0

64 lines not on this page · raw message

arch/arm64/mm/ioremap.c new file +84 -0

84 lines not on this page · raw message

author maintainer
#76 lore raw

PATCH v2 14/31 arm64: DMA mapping API

In reply to Catalin Marinas

This patch adds support for the DMA mapping API. It uses dma_map_ops for flexibility and it currently supports swiotlb. This patch could be simplified further if the DMA accesses are coherent (not mandated by the architecture) or if corresponding hooks are placed in the generic swiotlb code to deal with cache maintenance.

---
 arch/arm64/include/asm/dma-mapping.h |  124 ++++++++++++++++++++
 arch/arm64/mm/dma-mapping.c          |  208 ++++++++++++++++++++++++++++++++++
 2 files changed, 332 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/dma-mapping.h
 create mode 100644 arch/arm64/mm/dma-mapping.c
arch/arm64/include/asm/dma-mapping.h new file +124 -0
new file mode 100644
index 0000000..538f4b4
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_DMA_MAPPING_H
+#define __ASM_DMA_MAPPING_H
+
+#ifdef __KERNEL__
+
+#include <linux/types.h>
+#include <linux/vmalloc.h>
+
+#include <asm-generic/dma-coherent.h>
+
+#define ARCH_HAS_DMA_GET_REQUIRED_MASK
+
+extern struct dma_map_ops *dma_ops;
+
+static inline struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	if (unlikely(!dev) || !dev->archdata.dma_ops)
+		return dma_ops;
+	else
+		return dev->archdata.dma_ops;
+}
+
+#include <asm-generic/dma-mapping-common.h>
+
+static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
+{
+	return (dma_addr_t)paddr;
+}
+
+static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
+{
+	return (phys_addr_t)dev_addr;
+}
+
+static inline int dma_mapping_error(struct device *dev, dma_addr_t dev_addr)
+{
+	struct dma_map_ops *ops = get_dma_ops(dev);
+	return ops->mapping_error(dev, dev_addr);
+}
+
+static inline int dma_supported(struct device *dev, u64 mask)
+{
+	struct dma_map_ops *ops = get_dma_ops(dev);
+	return ops->dma_supported(dev, mask);
+}
+
+static inline int dma_set_mask(struct device *dev, u64 mask)
+{
+	if (!dev->dma_mask || !dma_supported(dev, mask))
+		return -EIO;
+	*dev->dma_mask = mask;
+
+	return 0;
+}
+
+static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
+{
+	if (!dev->dma_mask)
+		return 0;
+
+	return addr + size - 1 <= *dev->dma_mask;
+}
+
+static inline void dma_mark_clean(void *addr, size_t size)
+{
+}
+
+static inline void *dma_alloc_coherent(struct device *dev, size_t size,
+				       dma_addr_t *dma_handle, gfp_t flags)
+{
+	struct dma_map_ops *ops = get_dma_ops(dev);
+	void *vaddr;
+
+	if (dma_alloc_from_coherent(dev, size, dma_handle, &vaddr))
+		return vaddr;
+
+	vaddr = ops->alloc(dev, size, dma_handle, flags, NULL);
+	debug_dma_alloc_coherent(dev, size, *dma_handle, vaddr);
+	return vaddr;
+}
+
+static inline void dma_free_coherent(struct device *dev, size_t size,
+				     void *vaddr, dma_addr_t dev_addr)
+{
+	struct dma_map_ops *ops = get_dma_ops(dev);
+
+	if (dma_release_from_coherent(dev, get_order(size), vaddr))
+		return;
+
+	debug_dma_free_coherent(dev, size, vaddr, dev_addr);
+	ops->free(dev, size, vaddr, dev_addr, NULL);
+}
+
+/*
+ * There is no dma_cache_sync() implementation, so just return NULL here.
+ */
+static inline void *dma_alloc_noncoherent(struct device *dev, size_t size,
+					  dma_addr_t *handle, gfp_t flags)
+{
+	return NULL;
+}
+
+static inline void dma_free_noncoherent(struct device *dev, size_t size,
+					void *cpu_addr, dma_addr_t handle)
+{
+}
+
+#endif	/* __KERNEL__ */
+#endif	/* __ASM_DMA_MAPPING_H */
arch/arm64/mm/dma-mapping.c new file +208 -0

208 lines not on this page · raw message

author maintainer
#81 lore raw

PATCH v2 15/31 arm64: SMP support

In reply to Catalin Marinas

This patch adds SMP initialisation and spinlocks implementation for AArch64. The spinlock support uses the new load-acquire/store-release instructions to avoid explicit barriers. The architecture also specifies that an event is automatically generated when clearing the exclusive monitor state to wake up processors in WFE, so there is no need for an explicit DSB/SEV instruction sequence. The SEVL instruction is used to set the exclusive monitor locally as there is no conditional WFE and a branch is more expensive.

For the SMP booting protocol, see Documentation/arm64/booting.txt.

---
 arch/arm64/include/asm/hardirq.h        |    5 +
 arch/arm64/include/asm/smp.h            |   69 +++++
 arch/arm64/include/asm/spinlock.h       |  199 +++++++++++++
 arch/arm64/include/asm/spinlock_types.h |   38 +++
 arch/arm64/kernel/smp.c                 |  469 +++++++++++++++++++++++++++++++
 5 files changed, 780 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/smp.h
 create mode 100644 arch/arm64/include/asm/spinlock.h
 create mode 100644 arch/arm64/include/asm/spinlock_types.h
 create mode 100644 arch/arm64/kernel/smp.c
arch/arm64/include/asm/hardirq.h +5 -0
index c6c9514..5075463 100644
@@ -20,8 +20,13 @@
 #include <linux/threads.h>
 #include <asm/irq.h>
 
+#define NR_IPI	4
+
 typedef struct {
 	unsigned int __softirq_pending;
+#ifdef CONFIG_SMP
+	unsigned int ipi_irqs[NR_IPI];
+#endif
 } ____cacheline_aligned irq_cpustat_t;
 
 #include <linux/irq_cpustat.h>	/* Standard mappings for irq_cpustat_t above */
arch/arm64/include/asm/smp.h new file +69 -0

69 lines not on this page · raw message

arch/arm64/include/asm/spinlock.h new file +199 -0

199 lines not on this page · raw message

arch/arm64/include/asm/spinlock_types.h new file +38 -0
new file mode 100644
index 0000000..9a49434
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SPINLOCK_TYPES_H
+#define __ASM_SPINLOCK_TYPES_H
+
+#if !defined(__LINUX_SPINLOCK_TYPES_H) && !defined(__ASM_SPINLOCK_H)
+# error "please don't include this file directly"
+#endif
+
+/* We only require natural alignment for exclusive accesses. */
+#define __lock_aligned
+
+typedef struct {
+	volatile unsigned int lock;
+} arch_spinlock_t;
+
+#define __ARCH_SPIN_LOCK_UNLOCKED	{ 0 }
+
+typedef struct {
+	volatile unsigned int lock;
+} arch_rwlock_t;
+
+#define __ARCH_RW_LOCK_UNLOCKED		{ 0 }
+
+#endif
arch/arm64/kernel/smp.c new file +469 -0

469 lines not on this page · raw message

author maintainer
#87 lore raw

PATCH v2 16/31 arm64: ELF definitions

In reply to Catalin Marinas

This patch adds definitions for the ELF format, including personality personality setting and EXEC_PAGESIZE. The are only two hwcap definitions for 64-bit applications - HWCAP_FP and HWCAP_ASIMD.

---
 arch/arm64/include/asm/auxvec.h   |   22 +++++
 arch/arm64/include/asm/elf.h      |  176 +++++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/hwcap.h    |   57 ++++++++++++
 arch/arm64/include/asm/param.h    |   23 +++++
 arch/arm64/include/asm/shmparam.h |   28 ++++++
 arch/arm64/kernel/elf.c           |   41 +++++++++
 6 files changed, 347 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/auxvec.h
 create mode 100644 arch/arm64/include/asm/elf.h
 create mode 100644 arch/arm64/include/asm/hwcap.h
 create mode 100644 arch/arm64/include/asm/param.h
 create mode 100644 arch/arm64/include/asm/shmparam.h
 create mode 100644 arch/arm64/kernel/elf.c
arch/arm64/include/asm/auxvec.h new file +22 -0
new file mode 100644
index 0000000..22d6d88
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_AUXVEC_H
+#define __ASM_AUXVEC_H
+
+/* vDSO location */
+#define AT_SYSINFO_EHDR	33
+
+#endif
arch/arm64/include/asm/elf.h new file +176 -0

176 lines not on this page · raw message

arch/arm64/include/asm/hwcap.h new file +57 -0

57 lines not on this page · raw message

arch/arm64/include/asm/param.h new file +23 -0
new file mode 100644
index 0000000..8e3a281
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_PARAM_H
+#define __ASM_PARAM_H
+
+#define EXEC_PAGESIZE	65536
+
+#include <asm-generic/param.h>
+
+#endif
arch/arm64/include/asm/shmparam.h new file +28 -0
new file mode 100644
index 0000000..4df608a
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SHMPARAM_H
+#define __ASM_SHMPARAM_H
+
+/*
+ * For IPC syscalls from compat tasks, we need to use the legacy 16k
+ * alignment value. Since we don't have aliasing D-caches, the rest of
+ * the time we can safely use PAGE_SIZE.
+ */
+#define COMPAT_SHMLBA	0x4000
+
+#include <asm-generic/shmparam.h>
+
+#endif /* __ASM_SHMPARAM_H */
arch/arm64/kernel/elf.c new file +41 -0

41 lines not on this page · raw message

author maintainer
#97 lore raw

PATCH v2 17/31 arm64: System calls handling

In reply to Catalin Marinas

This patch adds support for system calls coming from 64-bit applications. It uses the asm-generic/unistd.h definitions with the canonical set of system calls. The private system calls are only used for 32-bit (compat) applications as 64-bit ones can set the TLS and flush the caches entirely from user space.

The sys_call_table is just an array defined in a C file and it contains pointers to the syscall functions. The array is 4KB aligned to allow the use of the ADRP instruction (longer range ADR) in entry.S.

---
 arch/arm64/include/asm/stat.h     |   63 +++++++++++++++++
 arch/arm64/include/asm/statfs.h   |   23 ++++++
 arch/arm64/include/asm/syscalls.h |   40 +++++++++++
 arch/arm64/include/asm/unistd.h   |   27 +++++++
 arch/arm64/kernel/sys.c           |  138 +++++++++++++++++++++++++++++++++++++
 5 files changed, 291 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/stat.h
 create mode 100644 arch/arm64/include/asm/statfs.h
 create mode 100644 arch/arm64/include/asm/syscalls.h
 create mode 100644 arch/arm64/include/asm/unistd.h
 create mode 100644 arch/arm64/kernel/sys.c
arch/arm64/include/asm/stat.h new file +63 -0
new file mode 100644
index 0000000..f63a680
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_STAT_H
+#define __ASM_STAT_H
+
+#include <asm-generic/stat.h>
+
+#if defined(__KERNEL__) && defined(CONFIG_AARCH32_EMULATION)
+
+#include <asm/compat.h>
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ * Note: The kernel zero's the padded region because glibc might read them
+ * in the hope that the kernel has stretched to using larger sizes.
+ */
+struct stat64 {
+	compat_u64	st_dev;
+	unsigned char   __pad0[4];
+
+#define STAT64_HAS_BROKEN_ST_INO	1
+	compat_ulong_t	__st_ino;
+	compat_uint_t	st_mode;
+	compat_uint_t	st_nlink;
+
+	compat_ulong_t	st_uid;
+	compat_ulong_t	st_gid;
+
+	compat_u64	st_rdev;
+	unsigned char   __pad3[4];
+
+	compat_s64	st_size;
+	compat_ulong_t	st_blksize;
+	compat_u64	st_blocks;	/* Number 512-byte blocks allocated. */
+
+	compat_ulong_t	st_atime;
+	compat_ulong_t	st_atime_nsec;
+
+	compat_ulong_t	st_mtime;
+	compat_ulong_t	st_mtime_nsec;
+
+	compat_ulong_t	st_ctime;
+	compat_ulong_t	st_ctime_nsec;
+
+	compat_u64	st_ino;
+};
+
+#endif
+
+#endif
arch/arm64/include/asm/statfs.h new file +23 -0
new file mode 100644
index 0000000..6f62190
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_STATFS_H
+#define __ASM_STATFS_H
+
+#define ARCH_PACK_COMPAT_STATFS64 __attribute__((packed,aligned(4)))
+
+#include <asm-generic/statfs.h>
+
+#endif
arch/arm64/include/asm/syscalls.h new file +40 -0
new file mode 100644
index 0000000..09ff335
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SYSCALLS_H
+#define __ASM_SYSCALLS_H
+
+#include <linux/linkage.h>
+#include <linux/compiler.h>
+#include <linux/signal.h>
+
+/*
+ * System call wrappers implemented in kernel/entry.S.
+ */
+asmlinkage long sys_execve_wrapper(const char __user *filename,
+				   const char __user *const __user *argv,
+				   const char __user *const __user *envp);
+asmlinkage long sys_clone_wrapper(unsigned long clone_flags,
+				  unsigned long newsp,
+				  void __user *parent_tid,
+				  unsigned long tls_val,
+				  void __user *child_tid);
+asmlinkage long sys_rt_sigreturn_wrapper(void);
+asmlinkage long sys_sigaltstack_wrapper(const stack_t __user *uss,
+					stack_t __user *uoss);
+
+#include <asm-generic/syscalls.h>
+
+#endif	/* __ASM_SYSCALLS_H */
arch/arm64/include/asm/unistd.h new file +27 -0
new file mode 100644
index 0000000..b00718c
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#if !defined(__ASM_UNISTD_H) || defined(__SYSCALL)
+#define __ASM_UNISTD_H
+
+#ifndef __SYSCALL_COMPAT
+#include <asm-generic/unistd.h>
+#endif
+
+#if defined(__KERNEL__) && defined(CONFIG_AARCH32_EMULATION)
+#include <asm/unistd32.h>
+#endif
+
+#endif /* __ASM_UNISTD_H */
arch/arm64/kernel/sys.c new file +138 -0

138 lines not on this page · raw message

author maintainer
#108 lore raw

PATCH v2 18/31 arm64: VDSO support

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

This patch adds VDSO support for 64-bit applications. The VDSO code is currently used for sys_rt_sigreturn() and optimised gettimeofday() (using the user-accessible generic counter).

---
 arch/arm64/include/asm/vdso.h              |   41 +++++
 arch/arm64/include/asm/vdso_datapage.h     |   43 +++++
 arch/arm64/kernel/vdso.c                   |  261 ++++++++++++++++++++++++++++
 arch/arm64/kernel/vdso/.gitignore          |    2 +
 arch/arm64/kernel/vdso/Makefile            |   63 +++++++
 arch/arm64/kernel/vdso/gen_vdso_offsets.sh |   15 ++
 arch/arm64/kernel/vdso/gettimeofday.S      |  242 ++++++++++++++++++++++++++
 arch/arm64/kernel/vdso/note.S              |   28 +++
 arch/arm64/kernel/vdso/sigreturn.S         |   37 ++++
 arch/arm64/kernel/vdso/vdso.S              |   33 ++++
 arch/arm64/kernel/vdso/vdso.lds.S          |  100 +++++++++++
 11 files changed, 865 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/vdso.h
 create mode 100644 arch/arm64/include/asm/vdso_datapage.h
 create mode 100644 arch/arm64/kernel/vdso.c
 create mode 100644 arch/arm64/kernel/vdso/.gitignore
 create mode 100644 arch/arm64/kernel/vdso/Makefile
 create mode 100755 arch/arm64/kernel/vdso/gen_vdso_offsets.sh
 create mode 100644 arch/arm64/kernel/vdso/gettimeofday.S
 create mode 100644 arch/arm64/kernel/vdso/note.S
 create mode 100644 arch/arm64/kernel/vdso/sigreturn.S
 create mode 100644 arch/arm64/kernel/vdso/vdso.S
 create mode 100644 arch/arm64/kernel/vdso/vdso.lds.S
arch/arm64/include/asm/vdso.h new file +41 -0
new file mode 100644
index 0000000..839ce00
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012 ARM Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_VDSO_H
+#define __ASM_VDSO_H
+
+#ifdef __KERNEL__
+
+/*
+ * Default link address for the vDSO.
+ * Since we randomise the VDSO mapping, there's little point in trying
+ * to prelink this.
+ */
+#define VDSO_LBASE	0x0
+
+#ifndef __ASSEMBLY__
+
+#include <generated/vdso-offsets.h>
+
+#define VDSO_SYMBOL(base, name)						   \
+({									   \
+	(void *)(vdso_offset_##name - VDSO_LBASE + (unsigned long)(base)); \
+})
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* __ASM_VDSO_H */
arch/arm64/include/asm/vdso_datapage.h new file +43 -0

43 lines not on this page · raw message

arch/arm64/kernel/vdso.c new file +261 -0

261 lines not on this page · raw message

arch/arm64/kernel/vdso/.gitignore new file +2 -0
new file mode 100644
index 0000000..b8cc94e
@@ -0,0 +1,2 @@
+vdso.lds
+vdso-offsets.h
arch/arm64/kernel/vdso/Makefile new file +63 -0

63 lines not on this page · raw message

arch/arm64/kernel/vdso/gen_vdso_offsets.sh new file +15 -0
new file mode 100755
index 0000000..01924ff
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#
+# Match symbols in the DSO that look like VDSO_*; produce a header file
+# of constant offsets into the shared object.
+#
+# Doing this inside the Makefile will break the $(filter-out) function,
+# causing Kbuild to rebuild the vdso-offsets header file every time.
+#
+# Author: Will Deacon <[email protected]
+#
+
+LC_ALL=C
+sed -n -e 's/^00*/0/' -e \
+'s/^\([0-9a-fA-F]*\) . VDSO_\([a-zA-Z0-9_]*\)$/\#define vdso_offset_\2\t0x\1/p'
arch/arm64/kernel/vdso/gettimeofday.S new file +242 -0

242 lines not on this page · raw message

arch/arm64/kernel/vdso/note.S new file +28 -0
new file mode 100644
index 0000000..b82c85e
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012 ARM Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Will Deacon <[email protected]>
+ *
+ * This supplies .note.* sections to go into the PT_NOTE inside the vDSO text.
+ * Here we can supply some information useful to userland.
+ */
+
+#include <linux/uts.h>
+#include <linux/version.h>
+#include <linux/elfnote.h>
+
+ELFNOTE_START(Linux, 0, "a")
+	.long LINUX_VERSION_CODE
+ELFNOTE_END
arch/arm64/kernel/vdso/sigreturn.S new file +37 -0
new file mode 100644
index 0000000..20d98ef
@@ -0,0 +1,37 @@
+/*
+ * Sigreturn trampoline for returning from a signal when the SA_RESTORER
+ * flag is not set.
+ *
+ * Copyright (C) 2012 ARM Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Will Deacon <[email protected]>
+ */
+
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+
+	.text
+
+	nop
+ENTRY(__kernel_rt_sigreturn)
+	.cfi_startproc
+	.cfi_signal_frame
+	.cfi_def_cfa	x29, 0
+	.cfi_offset	x29, 0 * 8
+	.cfi_offset	x30, 1 * 8
+	mov	x8, #__NR_rt_sigreturn
+	svc	#0
+	.cfi_endproc
+ENDPROC(__kernel_rt_sigreturn)
arch/arm64/kernel/vdso/vdso.S new file +33 -0
new file mode 100644
index 0000000..60c1db5
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 ARM Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Will Deacon <[email protected]>
+ */
+
+#include <linux/init.h>
+#include <linux/linkage.h>
+#include <linux/const.h>
+#include <asm/page.h>
+
+	__PAGE_ALIGNED_DATA
+
+	.globl vdso_start, vdso_end
+	.balign PAGE_SIZE
+vdso_start:
+	.incbin "arch/arm64/kernel/vdso/vdso.so"
+	.balign PAGE_SIZE
+vdso_end:
+
+	.previous
arch/arm64/kernel/vdso/vdso.lds.S new file +100 -0

100 lines not on this page · raw message

author maintainer
#109 lore raw

PATCH v2 19/31 arm64: Signal handling support

In reply to Catalin Marinas

This patch adds support for signal handling. The sigreturn is done via VDSO, introduced by a previous patch. The SA_RESTORER is still defined as it is required for 32-bit (compat) support but it is not to be used for 64-bit applications.

---
 arch/arm64/include/asm/sigcontext.h |   69 ++++++
 arch/arm64/include/asm/siginfo.h    |   23 ++
 arch/arm64/include/asm/signal.h     |   24 ++
 arch/arm64/include/asm/ucontext.h   |   30 +++
 arch/arm64/kernel/signal.c          |  436 +++++++++++++++++++++++++++++++++++
 5 files changed, 582 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/sigcontext.h
 create mode 100644 arch/arm64/include/asm/siginfo.h
 create mode 100644 arch/arm64/include/asm/signal.h
 create mode 100644 arch/arm64/include/asm/ucontext.h
 create mode 100644 arch/arm64/kernel/signal.c
arch/arm64/include/asm/sigcontext.h new file +69 -0
new file mode 100644
index 0000000..573cec7
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SIGCONTEXT_H
+#define __ASM_SIGCONTEXT_H
+
+#include <linux/types.h>
+
+/*
+ * Signal context structure - contains all info to do with the state
+ * before the signal handler was invoked.
+ */
+struct sigcontext {
+	__u64 fault_address;
+	/* AArch64 registers */
+	__u64 regs[31];
+	__u64 sp;
+	__u64 pc;
+	__u64 pstate;
+	/* 4K reserved for FP/SIMD state and future expansion */
+	__u8 __reserved[4096] __attribute__((__aligned__(16)));
+};
+
+/*
+ * Header to be used at the beginning of structures extending the user
+ * context. Such structures must be placed after the rt_sigframe on the stack
+ * and be 16-byte aligned. The last structure must be a dummy one with the
+ * magic and size set to 0.
+ */
+struct _aarch64_ctx {
+	__u32 magic;
+	__u32 size;
+};
+
+#define FPSIMD_MAGIC	0x46508001
+
+struct fpsimd_context {
+	struct _aarch64_ctx head;
+	__u32 fpsr;
+	__u32 fpcr;
+	__uint128_t vregs[32];
+};
+
+#ifdef __KERNEL__
+/*
+ * Auxiliary context saved in the sigcontext.__reserved array. Not exported to
+ * user space as it will change with the addition of new context. User space
+ * should check the magic/size information.
+ */
+struct aux_context {
+	struct fpsimd_context fpsimd;
+	/* additional context to be added before "end" */
+	struct _aarch64_ctx end;
+};
+#endif
+
+#endif
arch/arm64/include/asm/siginfo.h new file +23 -0
new file mode 100644
index 0000000..5a74a08
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SIGINFO_H
+#define __ASM_SIGINFO_H
+
+#define __ARCH_SI_PREAMBLE_SIZE	(4 * sizeof(int))
+
+#include <asm-generic/siginfo.h>
+
+#endif
arch/arm64/include/asm/signal.h new file +24 -0
new file mode 100644
index 0000000..8d1e723
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SIGNAL_H
+#define __ASM_SIGNAL_H
+
+/* Required for AArch32 compatibility. */
+#define SA_RESTORER	0x04000000
+
+#include <asm-generic/signal.h>
+
+#endif
arch/arm64/include/asm/ucontext.h new file +30 -0
new file mode 100644
index 0000000..bde9607
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_UCONTEXT_H
+#define __ASM_UCONTEXT_H
+
+struct ucontext {
+	unsigned long	  uc_flags;
+	struct ucontext	 *uc_link;
+	stack_t		  uc_stack;
+	sigset_t	  uc_sigmask;
+	/* glibc uses a 1024-bit sigset_t */
+	__u8		  __unused[(1024 - sizeof(sigset_t)) / 8];
+	/* last for future expansion */
+	struct sigcontext uc_mcontext;
+};
+
+#endif /* __ASM_UCONTEXT_H */
arch/arm64/kernel/signal.c new file +436 -0

436 lines not on this page · raw message

author maintainer
#110 lore raw

PATCH v2 20/31 arm64: User access library functions

In reply to Catalin Marinas

This patch add support for various user access functions. These functions use the standard LDR/STR instructions and not the LDRT/STRT variants in order to allow kernel addresses (after set_fs(KERNEL_DS)).

---
 arch/arm64/include/asm/uaccess.h   |  377 ++++++++++++++++++++++++++++++++++++
 arch/arm64/lib/clear_user.S        |   58 ++++++
 arch/arm64/lib/copy_from_user.S    |   66 +++++++
 arch/arm64/lib/copy_in_user.S      |   63 ++++++
 arch/arm64/lib/copy_to_user.S      |   61 ++++++
 arch/arm64/lib/getuser.S           |   75 +++++++
 arch/arm64/lib/putuser.S           |   73 +++++++
 arch/arm64/lib/strncpy_from_user.S |   50 +++++
 arch/arm64/lib/strnlen_user.S      |   47 +++++
 9 files changed, 870 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/uaccess.h
 create mode 100644 arch/arm64/lib/clear_user.S
 create mode 100644 arch/arm64/lib/copy_from_user.S
 create mode 100644 arch/arm64/lib/copy_in_user.S
 create mode 100644 arch/arm64/lib/copy_to_user.S
 create mode 100644 arch/arm64/lib/getuser.S
 create mode 100644 arch/arm64/lib/putuser.S
 create mode 100644 arch/arm64/lib/strncpy_from_user.S
 create mode 100644 arch/arm64/lib/strnlen_user.S
arch/arm64/include/asm/uaccess.h new file +377 -0
new file mode 100644
index 0000000..09d7b53
@@ -0,0 +1,377 @@
+/*
+ * Based on arch/arm/include/asm/uaccess.h
+ *
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_UACCESS_H
+#define __ASM_UACCESS_H
+
+/*
+ * User space memory access functions
+ */
+#include <linux/string.h>
+#include <linux/thread_info.h>
+
+#include <asm/ptrace.h>
+#include <asm/errno.h>
+#include <asm/memory.h>
+#include <asm/compiler.h>
+
+#define VERIFY_READ 0
+#define VERIFY_WRITE 1
+
+/*
+ * The exception table consists of pairs of addresses: the first is the
+ * address of an instruction that is allowed to fault, and the second is
+ * the address at which the program should continue.  No registers are
+ * modified, so it is entirely up to the continuation code to figure out
+ * what to do.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path.  This means when everything is well,
+ * we don't even have to jump over them.  Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+
+struct exception_table_entry
+{
+	unsigned long insn, fixup;
+};
+
+extern int fixup_exception(struct pt_regs *regs);
+
+/*
+ * These two are intentionally not defined anywhere - if the kernel
+ * code generates any references to them, that's a bug.
+ */
+extern long __get_user_bad(void);
+extern long __put_user_bad(void);
+
+#define KERNEL_DS	(-1UL)
+#define get_ds()	(KERNEL_DS)
+
+#define USER_DS		TASK_SIZE_64
+#define get_fs()	(current_thread_info()->addr_limit)
+
+static inline void set_fs(mm_segment_t fs)
+{
+	current_thread_info()->addr_limit = fs;
+}
+
+#define segment_eq(a,b)	((a) == (b))
+
+/*
+ * Return 1 if addr < current->addr_limit, 0 otherwise.
+ */
+#define __addr_ok(addr)							\
+({									\
+	unsigned long flag;						\
+	asm("cmp %1, %0; cset %0, lo"				\
+		: "=&r" (flag)						\
+		: "r" (addr), "0" (current_thread_info()->addr_limit)	\
+		: "cc");						\
+	flag;								\
+})
+
+/*
+ * Test whether a block of memory is a valid user space address.
+ * Returns 1 if the range is valid, 0 otherwise.
+ *
+ * This is equivalent to the following test:
+ * (u65)addr + (u65)size < (u65)current->addr_limit
+ *
+ * This needs 65-bit arithmetic.
+ */
+#define __range_ok(addr,size)						\
+({									\
+	unsigned long flag, roksum;					\
+	__chk_user_ptr(addr);						\
+	asm("adds %1, %1, %3; ccmp %1, %4, #2, cc; cset %0, cc"	\
+		: "=&r" (flag), "=&r" (roksum)				\
+		: "1" (addr), "Ir" (size),				\
+		  "r" (current_thread_info()->addr_limit)		\
+		: "cc");						\
+	flag;								\
+})
+
+/*
+ * Single-value transfer routines.  They automatically use the right
+ * size if we just have the right pointer type.  Note that the functions
+ * which read from user space (*get_*) need to take care not to leak
+ * kernel data even if the calling code is buggy and fails to check
+ * the return value.  This means zeroing out the destination variable
+ * or buffer on error.  Normally this is done out of line by the
+ * fixup code, but there are a few places where it intrudes on the
+ * main code path.  When we only write to user space, there is no
+ * problem.
+ */
+extern long __get_user_1(void *);
+extern long __get_user_2(void *);
+extern long __get_user_4(void *);
+extern long __get_user_8(void *);
+
+#define __get_user_x(__r2,__p,__e,__s,__i...)				\
+	   asm volatile(						\
+		__asmeq("%0", "x0") __asmeq("%1", "x2")			\
+		"bl	__get_user_" #__s				\
+		: "=&r" (__e), "=r" (__r2)				\
+		: "0" (__p)						\
+		: __i, "cc")
+
+#define get_user(x,p)							\
+	({								\
+		register const typeof(*(p)) __user *__p asm("x0") = (p);\
+		register unsigned long __r2 asm("x2");			\
+		register long __e asm("x0");				\
+		switch (sizeof(*(__p))) {				\
+		case 1:							\
+			__get_user_x(__r2, __p, __e, 1, "x30");		\
+			break;						\
+		case 2:							\
+			__get_user_x(__r2, __p, __e, 2, "x3", "x30");	\
+			break;						\
+		case 4:							\
+			__get_user_x(__r2, __p, __e, 4, "x30");		\
+			break;						\
+		case 8:							\
+			__get_user_x(__r2, __p, __e, 8, "x30");		\
+			break;						\
+		default: __e = __get_user_bad(); break;			\
+		}							\
+		x = (typeof(*(p))) __r2;				\
+		__e;							\
+	})
+
+#define __get_user_unaligned __get_user
+
+extern long __put_user_1(void *, unsigned long);
+extern long __put_user_2(void *, unsigned long);
+extern long __put_user_4(void *, unsigned long);
+extern long __put_user_8(void *, unsigned long);
+
+#define __put_user_x(__r2,__p,__e,__s)					\
+	   asm volatile(						\
+		__asmeq("%0", "x0") __asmeq("%2", "x2")			\
+		"bl	__put_user_" #__s				\
+		: "=&r" (__e)						\
+		: "0" (__p), "r" (__r2)					\
+		: "x8", "x30", "cc")
+
+#define put_user(x,p)							\
+	({								\
+		register const typeof(*(p)) __r2 asm("x2") = (x);	\
+		register const typeof(*(p)) __user *__p asm("x0") = (p);\
+		register long __e asm("x0");				\
+		switch (sizeof(*(__p))) {				\
+		case 1:							\
+			__put_user_x(__r2, __p, __e, 1);		\
+			break;						\
+		case 2:							\
+			__put_user_x(__r2, __p, __e, 2);		\
+			break;						\
+		case 4:							\
+			__put_user_x(__r2, __p, __e, 4);		\
+			break;						\
+		case 8:							\
+			__put_user_x(__r2, __p, __e, 8);		\
+			break;						\
+		default: __e = __put_user_bad(); break;			\
+		}							\
+		__e;							\
+	})
+
+#define __put_user_unaligned __put_user
+
+#define access_ok(type,addr,size)	__range_ok(addr,size)
+
+/*
+ * The "__xxx" versions of the user access functions do not verify the
+ * address space - it must have been done previously with a separate
+ * "access_ok()" call.
+ *
+ * The "xxx_error" versions set the third argument to EFAULT if an
+ * error occurs, and leave it unchanged on success.  Note that these
+ * versions are void (ie, don't return a value as such).
+ */
+#define __get_user(x,ptr)						\
+({									\
+	long __gu_err = 0;						\
+	__get_user_err((x),(ptr),__gu_err);				\
+	__gu_err;							\
+})
+
+#define __get_user_error(x,ptr,err)					\
+({									\
+	__get_user_err((x),(ptr),err);					\
+	(void) 0;							\
+})
+
+#define __get_user_err(x,ptr,err)					\
+do {									\
+	unsigned long __gu_addr = (unsigned long)(ptr);			\
+	unsigned long __gu_val;						\
+	__chk_user_ptr(ptr);						\
+	switch (sizeof(*(ptr))) {					\
+	case 1:								\
+		__get_user_asm("ldrb", "%w", __gu_val, __gu_addr, err);	\
+		break;							\
+	case 2:								\
+		__get_user_asm("ldrh", "%w", __gu_val, __gu_addr, err);	\
+		break;							\
+	case 4:								\
+		__get_user_asm("ldr", "%w", __gu_val, __gu_addr, err);	\
+		break;							\
+	case 8:								\
+		__get_user_asm("ldr", "%",  __gu_val, __gu_addr, err);	\
+		break;							\
+	default:							\
+		(__gu_val) = __get_user_bad();				\
+	}								\
+	(x) = (__typeof__(*(ptr)))__gu_val;				\
+} while (0)
+
+#define __get_user_asm(instr, reg, x, addr, err)			\
+	asm volatile(							\
+	"1:	" instr "	" reg "1, [%2]\n"			\
+	"2:\n"								\
+	"	.section .fixup, \"ax\"\n"				\
+	"	.align	2\n"						\
+	"3:	mov	%0, %3\n"					\
+	"	mov	%1, #0\n"					\
+	"	b	2b\n"						\
+	"	.previous\n"						\
+	"	.section __ex_table,\"a\"\n"				\
+	"	.align	3\n"						\
+	"	.quad	1b, 3b\n"					\
+	"	.previous"						\
+	: "+r" (err), "=&r" (x)						\
+	: "r" (addr), "i" (-EFAULT)					\
+	: "cc")
+
+#define __put_user(x,ptr)						\
+({									\
+	long __pu_err = 0;						\
+	__put_user_err((x),(ptr),__pu_err);				\
+	__pu_err;							\
+})
+
+#define __put_user_error(x,ptr,err)					\
+({									\
+	__put_user_err((x),(ptr),err);					\
+	(void) 0;							\
+})
+
+#define __put_user_err(x,ptr,err)					\
+do {									\
+	unsigned long __pu_addr = (unsigned long)(ptr);			\
+	__typeof__(*(ptr)) __pu_val = (x);				\
+	__chk_user_ptr(ptr);						\
+	switch (sizeof(*(ptr))) {					\
+	case 1:								\
+		__put_user_asm("strb", "%w", __pu_val, __pu_addr, err);	\
+		break;							\
+	case 2:								\
+		__put_user_asm("strh", "%w", __pu_val, __pu_addr, err);	\
+		break;							\
+	case 4:								\
+		__put_user_asm("str",  "%w", __pu_val, __pu_addr, err);	\
+		break;							\
+	case 8:								\
+		__put_user_asm("str",  "%",  __pu_val, __pu_addr, err);	\
+		break;							\
+	default:							\
+		__put_user_bad();					\
+	}								\
+} while (0)
+
+#define __put_user_asm(instr, reg, x, __pu_addr, err)			\
+	asm volatile(							\
+	"1:	" instr "	" reg "1, [%2]\n"			\
+	"2:\n"								\
+	"	.section .fixup,\"ax\"\n"				\
+	"	.align	2\n"						\
+	"3:	mov	%0, %3\n"					\
+	"	b	2b\n"						\
+	"	.previous\n"						\
+	"	.section __ex_table,\"a\"\n"				\
+	"	.align	3\n"						\
+	"	.quad	1b, 3b\n"					\
+	"	.previous"						\
+	: "+r" (err)							\
+	: "r" (x), "r" (__pu_addr), "i" (-EFAULT)			\
+	: "cc")
+
+extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
+extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
+extern unsigned long __must_check __copy_in_user(void __user *to, const void __user *from, unsigned long n);
+extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
+
+extern unsigned long __must_check __strncpy_from_user(char *to, const char __user *from, unsigned long count);
+extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
+
+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
+{
+	if (access_ok(VERIFY_READ, from, n))
+		n = __copy_from_user(to, from, n);
+	else /* security hole - plug it */
+		memset(to, 0, n);
+	return n;
+}
+
+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
+{
+	if (access_ok(VERIFY_WRITE, to, n))
+		n = __copy_to_user(to, from, n);
+	return n;
+}
+
+static inline unsigned long __must_check copy_in_user(void __user *to, const void __user *from, unsigned long n)
+{
+	if (access_ok(VERIFY_READ, from, n) && access_ok(VERIFY_WRITE, to, n))
+		n = __copy_in_user(to, from, n);
+	return n;
+}
+
+#define __copy_to_user_inatomic __copy_to_user
+#define __copy_from_user_inatomic __copy_from_user
+
+static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
+{
+	if (access_ok(VERIFY_WRITE, to, n))
+		n = __clear_user(to, n);
+	return n;
+}
+
+static inline long __must_check strncpy_from_user(char *dst, const char __user *src, long count)
+{
+	long res = -EFAULT;
+	if (access_ok(VERIFY_READ, src, 1))
+		res = __strncpy_from_user(dst, src, count);
+	return res;
+}
+
+#define strlen_user(s)	strnlen_user(s, ~0UL >> 1)
+
+static inline long __must_check strnlen_user(const char __user *s, long n)
+{
+	unsigned long res = 0;
+
+	if (__addr_ok(s))
+		res = __strnlen_user(s, n);
+
+	return res;
+}
+
+#endif /* __ASM_UACCESS_H */
arch/arm64/lib/clear_user.S new file +58 -0

58 lines not on this page · raw message

arch/arm64/lib/copy_from_user.S new file +66 -0

66 lines not on this page · raw message

arch/arm64/lib/copy_in_user.S new file +63 -0

63 lines not on this page · raw message

arch/arm64/lib/copy_to_user.S new file +61 -0

61 lines not on this page · raw message

arch/arm64/lib/getuser.S new file +75 -0

75 lines not on this page · raw message

arch/arm64/lib/putuser.S new file +73 -0

73 lines not on this page · raw message

arch/arm64/lib/strncpy_from_user.S new file +50 -0

50 lines not on this page · raw message

arch/arm64/lib/strnlen_user.S new file +47 -0

47 lines not on this page · raw message

author maintainer
#117 lore raw

PATCH v2 21/31 arm64: 32-bit (compat) applications support

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

This patch adds support for 32-bit applications. The vectors page is a binary blob mapped into the application user space at 0xffff0000 (the AArch64 toolchain does not support compilation of AArch32 code). Full compatibility with ARMv7 user space is supported. The use of deprecated ARMv7 functionality (SWP, CP15 barriers) has been disabled by default on AArch64 kernels and unaligned LDM/STM is not supported.

Please note that only the ARM 32-bit EABI is supported, so no OABI compatibility.

---
 arch/arm64/include/asm/compat.h   |  232 ++++++++++
 arch/arm64/include/asm/signal32.h |   54 +++
 arch/arm64/include/asm/unistd32.h |  758 ++++++++++++++++++++++++++++++++
 arch/arm64/kernel/kuser32.S       |   77 ++++
 arch/arm64/kernel/signal32.c      |  876 +++++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/sys32.S         |  283 ++++++++++++
 arch/arm64/kernel/sys_compat.c    |  177 ++++++++
 7 files changed, 2457 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/compat.h
 create mode 100644 arch/arm64/include/asm/signal32.h
 create mode 100644 arch/arm64/include/asm/unistd32.h
 create mode 100644 arch/arm64/kernel/kuser32.S
 create mode 100644 arch/arm64/kernel/signal32.c
 create mode 100644 arch/arm64/kernel/sys32.S
 create mode 100644 arch/arm64/kernel/sys_compat.c
arch/arm64/include/asm/compat.h new file +232 -0
new file mode 100644
index 0000000..91e72b7
@@ -0,0 +1,232 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_COMPAT_H
+#define __ASM_COMPAT_H
+#ifdef __KERNEL__
+#ifdef CONFIG_COMPAT
+
+/*
+ * Architecture specific compatibility types
+ */
+#include <linux/types.h>
+#include <linux/sched.h>
+
+#define COMPAT_USER_HZ		100
+#define COMPAT_UTS_MACHINE	"armv8l\0\0"
+
+typedef u32		compat_size_t;
+typedef s32		compat_ssize_t;
+typedef s32		compat_time_t;
+typedef s32		compat_clock_t;
+typedef s32		compat_pid_t;
+typedef u32		__compat_uid_t;
+typedef u32		__compat_gid_t;
+typedef u32		__compat_uid32_t;
+typedef u32		__compat_gid32_t;
+typedef u32		compat_mode_t;
+typedef u32		compat_ino_t;
+typedef u32		compat_dev_t;
+typedef s32		compat_off_t;
+typedef s64		compat_loff_t;
+typedef s16		compat_nlink_t;
+typedef u16		compat_ipc_pid_t;
+typedef s32		compat_daddr_t;
+typedef u32		compat_caddr_t;
+typedef __kernel_fsid_t	compat_fsid_t;
+typedef s32		compat_key_t;
+typedef s32		compat_timer_t;
+
+typedef s32		compat_int_t;
+typedef s32		compat_long_t;
+typedef s64		compat_s64;
+typedef u32		compat_uint_t;
+typedef u32		compat_ulong_t;
+typedef u64		compat_u64;
+
+struct compat_timespec {
+	compat_time_t	tv_sec;
+	s32		tv_nsec;
+};
+
+struct compat_timeval {
+	compat_time_t	tv_sec;
+	s32		tv_usec;
+};
+
+struct compat_stat {
+	compat_dev_t	st_dev;
+	compat_ino_t	st_ino;
+	compat_mode_t	st_mode;
+	compat_nlink_t	st_nlink;
+	__compat_uid32_t	st_uid;
+	__compat_gid32_t	st_gid;
+	compat_dev_t	st_rdev;
+	compat_off_t	st_size;
+	compat_off_t	st_blksize;
+	compat_off_t	st_blocks;
+	compat_time_t	st_atime;
+	u32		st_atime_nsec;
+	compat_time_t	st_mtime;
+	u32		st_mtime_nsec;
+	compat_time_t	st_ctime;
+	u32		st_ctime_nsec;
+	u32		__unused4[2];
+};
+
+struct compat_flock {
+	short		l_type;
+	short		l_whence;
+	compat_off_t	l_start;
+	compat_off_t	l_len;
+	compat_pid_t	l_pid;
+};
+
+#define F_GETLK64	12	/*  using 'struct flock64' */
+#define F_SETLK64	13
+#define F_SETLKW64	14
+
+struct compat_flock64 {
+	short		l_type;
+	short		l_whence;
+	compat_loff_t	l_start;
+	compat_loff_t	l_len;
+	compat_pid_t	l_pid;
+};
+
+struct compat_statfs {
+	int		f_type;
+	int		f_bsize;
+	int		f_blocks;
+	int		f_bfree;
+	int		f_bavail;
+	int		f_files;
+	int		f_ffree;
+	compat_fsid_t	f_fsid;
+	int		f_namelen;	/* SunOS ignores this field. */
+	int		f_frsize;
+	int		f_flags;
+	int		f_spare[4];
+};
+
+#define COMPAT_RLIM_INFINITY		0xffffffff
+
+typedef u32		compat_old_sigset_t;
+
+#define _COMPAT_NSIG		64
+#define _COMPAT_NSIG_BPW	32
+
+typedef u32		compat_sigset_word;
+
+#define COMPAT_OFF_T_MAX	0x7fffffff
+#define COMPAT_LOFF_T_MAX	0x7fffffffffffffffL
+
+/*
+ * A pointer passed in from user mode. This should not
+ * be used for syscall parameters, just declare them
+ * as pointers because the syscall entry code will have
+ * appropriately converted them already.
+ */
+typedef	u32		compat_uptr_t;
+
+static inline void __user *compat_ptr(compat_uptr_t uptr)
+{
+	return (void __user *)(unsigned long)uptr;
+}
+
+static inline compat_uptr_t ptr_to_compat(void __user *uptr)
+{
+	return (u32)(unsigned long)uptr;
+}
+
+static inline void __user *arch_compat_alloc_user_space(long len)
+{
+	struct pt_regs *regs = task_pt_regs(current);
+	return (void __user *)regs->compat_sp - len;
+}
+
+struct compat_ipc64_perm {
+	compat_key_t key;
+	__compat_uid32_t uid;
+	__compat_gid32_t gid;
+	__compat_uid32_t cuid;
+	__compat_gid32_t cgid;
+	unsigned short mode;
+	unsigned short __pad1;
+	unsigned short seq;
+	unsigned short __pad2;
+	compat_ulong_t unused1;
+	compat_ulong_t unused2;
+};
+
+struct compat_semid64_ds {
+	struct compat_ipc64_perm sem_perm;
+	compat_time_t  sem_otime;
+	compat_ulong_t __unused1;
+	compat_time_t  sem_ctime;
+	compat_ulong_t __unused2;
+	compat_ulong_t sem_nsems;
+	compat_ulong_t __unused3;
+	compat_ulong_t __unused4;
+};
+
+struct compat_msqid64_ds {
+	struct compat_ipc64_perm msg_perm;
+	compat_time_t  msg_stime;
+	compat_ulong_t __unused1;
+	compat_time_t  msg_rtime;
+	compat_ulong_t __unused2;
+	compat_time_t  msg_ctime;
+	compat_ulong_t __unused3;
+	compat_ulong_t msg_cbytes;
+	compat_ulong_t msg_qnum;
+	compat_ulong_t msg_qbytes;
+	compat_pid_t   msg_lspid;
+	compat_pid_t   msg_lrpid;
+	compat_ulong_t __unused4;
+	compat_ulong_t __unused5;
+};
+
+struct compat_shmid64_ds {
+	struct compat_ipc64_perm shm_perm;
+	compat_size_t  shm_segsz;
+	compat_time_t  shm_atime;
+	compat_ulong_t __unused1;
+	compat_time_t  shm_dtime;
+	compat_ulong_t __unused2;
+	compat_time_t  shm_ctime;
+	compat_ulong_t __unused3;
+	compat_pid_t   shm_cpid;
+	compat_pid_t   shm_lpid;
+	compat_ulong_t shm_nattch;
+	compat_ulong_t __unused4;
+	compat_ulong_t __unused5;
+};
+
+static inline int is_compat_task(void)
+{
+	return test_thread_flag(TIF_32BIT);
+}
+
+#else /* !CONFIG_COMPAT */
+
+static inline int is_compat_task(void)
+{
+	return 0;
+}
+
+#endif /* CONFIG_COMPAT */
+#endif /* __KERNEL__ */
+#endif /* __ASM_COMPAT_H */
arch/arm64/include/asm/signal32.h new file +54 -0

54 lines not on this page · raw message

arch/arm64/include/asm/unistd32.h new file +758 -0

758 lines not on this page · raw message

arch/arm64/kernel/kuser32.S new file +77 -0

77 lines not on this page · raw message

arch/arm64/kernel/signal32.c new file +876 -0

876 lines not on this page · raw message

arch/arm64/kernel/sys32.S new file +283 -0

283 lines not on this page · raw message

arch/arm64/kernel/sys_compat.c new file +177 -0

177 lines not on this page · raw message

author maintainer
#129 lore raw

PATCH v2 22/31 arm64: Floating point and SIMD

In reply to Catalin Marinas

This patch adds support for FP/ASIMD register bank saving and restoring during context switch and FP exception handling to generate SIGFPE. There are 32 128-bit registers and the context switching is currently done non-lazily. Benchmarks on real hardware are required before implementing lazy FP state saving/restoring.

---
 arch/arm64/include/asm/fpsimd.h  |   64 +++++++++++++++++++++++
 arch/arm64/kernel/entry-fpsimd.S |   80 ++++++++++++++++++++++++++++
 arch/arm64/kernel/fpsimd.c       |  106 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 250 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/fpsimd.h
 create mode 100644 arch/arm64/kernel/entry-fpsimd.S
 create mode 100644 arch/arm64/kernel/fpsimd.c
arch/arm64/include/asm/fpsimd.h new file +64 -0
new file mode 100644
index 0000000..7ea4711
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_FP_H
+#define __ASM_FP_H
+
+#include <asm/ptrace.h>
+
+#ifndef __ASSEMBLY__
+
+/*
+ * FP/SIMD storage area has:
+ *  - FPSR and FPCR
+ *  - 32 128-bit data registers
+ *
+ * Note that user_fp forms a prefix of this structure, which is relied
+ * upon in the ptrace FP/SIMD accessors. struct user_fpsimd_state must
+ * form a prefix of struct fpsimd_state.
+ */
+struct fpsimd_state {
+	union {
+		struct user_fpsimd_state user_fpsimd;
+		struct {
+			__uint128_t vregs[32];
+			u32 fpsr;
+			u32 fpcr;
+		};
+	};
+};
+
+#if defined(__KERNEL__) && defined(CONFIG_AARCH32_EMULATION)
+/* Masks for extracting the FPSR and FPCR from the FPSCR */
+#define VFP_FPSCR_STAT_MASK	0xf800009f
+#define VFP_FPSCR_CTRL_MASK	0x07f79f00
+/*
+ * The VFP state has 32x64-bit registers and a single 32-bit
+ * control/status register.
+ */
+#define VFP_STATE_SIZE		((32 * 8) + 4)
+#endif
+
+struct task_struct;
+
+extern void fpsimd_save_state(struct fpsimd_state *state);
+extern void fpsimd_load_state(struct fpsimd_state *state);
+
+extern void fpsimd_thread_switch(struct task_struct *next);
+extern void fpsimd_flush_thread(void);
+
+#endif
+
+#endif
arch/arm64/kernel/entry-fpsimd.S new file +80 -0

80 lines not on this page · raw message

arch/arm64/kernel/fpsimd.c new file +106 -0

106 lines not on this page · raw message

author maintainer
#131 lore raw

PATCH v2 23/31 arm64: Debugging support

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

This patch adds ptrace, debug monitors and hardware breakpoints support.

---
 arch/arm64/include/asm/debug-monitors.h |   88 +++
 arch/arm64/include/asm/hw_breakpoint.h  |  137 +++++
 arch/arm64/kernel/debug-monitors.c      |  288 ++++++++++
 arch/arm64/kernel/hw_breakpoint.c       |  880 +++++++++++++++++++++++++++++++
 arch/arm64/kernel/ptrace.c              |  834 +++++++++++++++++++++++++++++
 5 files changed, 2227 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/debug-monitors.h
 create mode 100644 arch/arm64/include/asm/hw_breakpoint.h
 create mode 100644 arch/arm64/kernel/debug-monitors.c
 create mode 100644 arch/arm64/kernel/hw_breakpoint.c
 create mode 100644 arch/arm64/kernel/ptrace.c
arch/arm64/include/asm/debug-monitors.h new file +88 -0
new file mode 100644
index 0000000..7eaa0b3
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_DEBUG_MONITORS_H
+#define __ASM_DEBUG_MONITORS_H
+
+#ifdef __KERNEL__
+
+#define	DBG_ESR_EVT(x)		(((x) >> 27) & 0x7)
+
+/* AArch64 */
+#define DBG_ESR_EVT_HWBP	0x0
+#define DBG_ESR_EVT_HWSS	0x1
+#define DBG_ESR_EVT_HWWP	0x2
+#define DBG_ESR_EVT_BRK		0x6
+
+enum debug_el {
+	DBG_ACTIVE_EL0 = 0,
+	DBG_ACTIVE_EL1,
+};
+
+/* AArch32 */
+#define DBG_ESR_EVT_BKPT	0x4
+#define DBG_ESR_EVT_VECC	0x5
+
+#define AARCH32_BREAK_ARM	0x07f001f0
+#define AARCH32_BREAK_THUMB	0xde01
+#define AARCH32_BREAK_THUMB2_LO	0xf7f0
+#define AARCH32_BREAK_THUMB2_HI	0xa000
+
+#ifndef __ASSEMBLY__
+struct task_struct;
+
+#define local_dbg_save(flags)							\
+	do {									\
+		typecheck(unsigned long, flags);				\
+		asm volatile(							\
+		"mrs	%0, daif			// local_dbg_save\n"	\
+		"msr	daifset, #8"						\
+		: "=r" (flags) : : "memory");					\
+	} while (0)
+
+#define local_dbg_restore(flags)						\
+	do {									\
+		typecheck(unsigned long, flags);				\
+		asm volatile(							\
+		"msr	daif, %0			// local_dbg_restore\n"	\
+		: : "r" (flags) : "memory");					\
+	} while (0)
+
+#define DBG_ARCH_ID_RESERVED	0	/* In case of ptrace ABI updates. */
+
+u8 debug_monitors_arch(void);
+
+void enable_debug_monitors(enum debug_el el);
+void disable_debug_monitors(enum debug_el el);
+
+void user_rewind_single_step(struct task_struct *task);
+void user_fastforward_single_step(struct task_struct *task);
+
+void kernel_enable_single_step(struct pt_regs *regs);
+void kernel_disable_single_step(void);
+int kernel_active_single_step(void);
+
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+int reinstall_suspended_bps(struct pt_regs *regs);
+#else
+static inline int reinstall_suspended_bps(struct pt_regs *regs)
+{
+	return -ENODEV;
+}
+#endif
+
+#endif	/* __ASSEMBLY */
+#endif	/* __KERNEL__ */
+#endif	/* __ASM_DEBUG_MONITORS_H */
arch/arm64/include/asm/hw_breakpoint.h new file +137 -0

137 lines not on this page · raw message

arch/arm64/kernel/debug-monitors.c new file +288 -0

288 lines not on this page · raw message

arch/arm64/kernel/hw_breakpoint.c new file +880 -0

880 lines not on this page · raw message

arch/arm64/kernel/ptrace.c new file +834 -0

834 lines not on this page · raw message

author maintainer
#140 lore raw

PATCH v2 24/31 arm64: Add support for /proc/sys/debug/exception-trace

In reply to Catalin Marinas

This patch allows setting of the show_unhandled_signals variable via /proc/sys/debug/exception-trace. The default value is currently 1 showing unhandled user faults (undefined instructions, data aborts) and invalid signal stack frames.

---
 kernel/sysctl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sysctl.c +1 -1
index 87174ef..79dcb00 100644
@@ -1544,7 +1544,7 @@ static struct ctl_table fs_table[] = {
 
 static struct ctl_table debug_table[] = {
 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
-    defined(CONFIG_S390) || defined(CONFIG_TILE)
+    defined(CONFIG_S390) || defined(CONFIG_TILE) || defined(CONFIG_ARM64)
 	{
 		.procname	= "exception-trace",
 		.data		= &show_unhandled_signals,
author maintainer
#142 lore raw

PATCH v2 25/31 arm64: Performance counters support

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

This patch adds support for the AArch64 performance counters.

---
 arch/arm64/include/asm/perf_event.h |   22 +
 arch/arm64/include/asm/pmu.h        |   82 +++
 arch/arm64/kernel/perf_event.c      | 1368 +++++++++++++++++++++++++++++++++++
 tools/perf/perf.h                   |    6 +
 4 files changed, 1478 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/perf_event.h
 create mode 100644 arch/arm64/include/asm/pmu.h
 create mode 100644 arch/arm64/kernel/perf_event.c
arch/arm64/include/asm/perf_event.h new file +22 -0
new file mode 100644
index 0000000..a6fffd5
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_PERF_EVENT_H
+#define __ASM_PERF_EVENT_H
+
+/* It's quiet around here... */
+
+#endif
arch/arm64/include/asm/pmu.h new file +82 -0

82 lines not on this page · raw message

arch/arm64/kernel/perf_event.c new file +1368 -0

1,368 lines not on this page · raw message

tools/perf/perf.h +6 -0
index f960ccb..8c36763 100644
@@ -88,6 +88,12 @@ void get_term_dimensions(struct winsize *ws);
 #define CPUINFO_PROC	"Processor"
 #endif
 
+#ifdef __aarch64__
+#include "../../arch/arm64/include/asm/unistd.h"
+#define rmb()		asm volatile("dmb ld" ::: "memory")
+#define cpu_relax()	asm volatile("yield" ::: "memory")
+#endif
+
 #ifdef __mips__
 #include "../../arch/mips/include/asm/unistd.h"
 #define rmb()		asm volatile(					\
author maintainer
#145 lore raw

PATCH v2 26/31 arm64: Miscellaneous library functions

In reply to Catalin Marinas

From: Marc Zyngier <[email protected]>

This patch adds udelay, memory and bit operations together with the ksyms exports.

---
 arch/arm64/include/asm/bitops.h  |   74 ++++++++++++++++++++++++++++
 arch/arm64/include/asm/syscall.h |  101 ++++++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/arm64ksyms.c   |   55 ++++++++++++++++++++
 arch/arm64/lib/Makefile          |    5 ++
 arch/arm64/lib/bitops.c          |   25 +++++++++
 arch/arm64/lib/clear_page.S      |   39 +++++++++++++++
 arch/arm64/lib/copy_page.S       |   46 +++++++++++++++++
 arch/arm64/lib/delay.c           |   55 ++++++++++++++++++++
 8 files changed, 400 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/bitops.h
 create mode 100644 arch/arm64/include/asm/syscall.h
 create mode 100644 arch/arm64/kernel/arm64ksyms.c
 create mode 100644 arch/arm64/lib/Makefile
 create mode 100644 arch/arm64/lib/bitops.c
 create mode 100644 arch/arm64/lib/clear_page.S
 create mode 100644 arch/arm64/lib/copy_page.S
 create mode 100644 arch/arm64/lib/delay.c
arch/arm64/include/asm/bitops.h new file +74 -0
new file mode 100644
index 0000000..67df4d2
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_BITOPS_H
+#define __ASM_BITOPS_H
+
+#include <linux/compiler.h>
+
+#include <asm/barrier.h>
+
+/*
+ * clear_bit may not imply a memory barrier
+ */
+#ifndef smp_mb__before_clear_bit
+#define smp_mb__before_clear_bit()	smp_mb()
+#define smp_mb__after_clear_bit()	smp_mb()
+#endif
+
+/*
+ * Use compiler builtins for simple inline operations.
+ */
+static inline unsigned long __ffs(unsigned long word)
+{
+	return __builtin_ffsl(word) - 1;
+}
+
+static inline int ffs(int x)
+{
+	return __builtin_ffs(x);
+}
+
+static inline unsigned long __fls(unsigned long word)
+{
+	return BITS_PER_LONG - 1 - __builtin_clzl(word);
+}
+
+static inline int fls(int x)
+{
+	return x ? sizeof(x) * BITS_PER_BYTE - __builtin_clz(x) : 0;
+}
+
+/*
+ * Mainly use the generic routines for now.
+ */
+#ifndef _LINUX_BITOPS_H
+#error only <linux/bitops.h> can be included directly
+#endif
+
+#include <asm-generic/bitops/ffz.h>
+#include <asm-generic/bitops/fls64.h>
+#include <asm-generic/bitops/find.h>
+
+#include <asm-generic/bitops/sched.h>
+#include <asm-generic/bitops/hweight.h>
+#include <asm-generic/bitops/lock.h>
+
+#include <asm-generic/bitops/atomic.h>
+#include <asm-generic/bitops/non-atomic.h>
+#include <asm-generic/bitops/le.h>
+#include <asm-generic/bitops/ext2-atomic.h>
+
+#endif /* __ASM_BITOPS_H */
arch/arm64/include/asm/syscall.h new file +101 -0

101 lines not on this page · raw message

arch/arm64/kernel/arm64ksyms.c new file +55 -0

55 lines not on this page · raw message

arch/arm64/lib/Makefile new file +5 -0
new file mode 100644
index 0000000..ae71bae
@@ -0,0 +1,5 @@
+lib-y		:= bitops.o delay.o					\
+		   strncpy_from_user.o strnlen_user.o			\
+		   clear_user.o getuser.o putuser.o			\
+		   copy_from_user.o copy_to_user.o copy_in_user.o	\
+		   copy_page.o clear_page.o
arch/arm64/lib/bitops.c new file +25 -0
new file mode 100644
index 0000000..aa4965e
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 ARM Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/kernel.h>
+#include <linux/spinlock.h>
+#include <linux/atomic.h>
+
+#ifdef CONFIG_SMP
+arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = {
+       [0 ... (ATOMIC_HASH_SIZE-1)]  = __ARCH_SPIN_LOCK_UNLOCKED
+};
+#endif
arch/arm64/lib/clear_page.S new file +39 -0
new file mode 100644
index 0000000..ef08e90
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/linkage.h>
+#include <linux/const.h>
+#include <asm/assembler.h>
+#include <asm/page.h>
+
+/*
+ * Clear page @dest
+ *
+ * Parameters:
+ *	x0 - dest
+ */
+ENTRY(clear_page)
+	mrs	x1, dczid_el0
+	and	w1, w1, #0xf
+	mov	x2, #4
+	lsl	x1, x2, x1
+
+1:	dc	zva, x0
+	add	x0, x0, x1
+	tst	x0, #(PAGE_SIZE - 1)
+	b.ne	1b
+	ret
+ENDPROC(clear_page)
arch/arm64/lib/copy_page.S new file +46 -0

46 lines not on this page · raw message

arch/arm64/lib/delay.c new file +55 -0

55 lines not on this page · raw message

author maintainer
#150 lore raw

PATCH v2 27/31 arm64: Loadable modules

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

This patch adds support for loadable modules. Loadable modules are loaded 64MB below the kernel image due to branch relocation restrictions (see Documentation/arm64/memory.txt).

---
 arch/arm64/include/asm/module.h |   23 ++
 arch/arm64/kernel/module.c      |  456 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 479 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/module.h
 create mode 100644 arch/arm64/kernel/module.c
arch/arm64/include/asm/module.h new file +23 -0
new file mode 100644
index 0000000..e80e232
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_MODULE_H
+#define __ASM_MODULE_H
+
+#include <asm-generic/module.h>
+
+#define MODULE_ARCH_VERMAGIC	"aarch64"
+
+#endif /* __ASM_MODULE_H */
arch/arm64/kernel/module.c new file +456 -0

456 lines not on this page · raw message

author maintainer
#154 lore raw

PATCH v2 28/31 arm64: Generic timers support

In reply to Catalin Marinas

From: Marc Zyngier <[email protected]>

This patch adds support for the ARM generic timers with A64 instructions for accessing the timer registers. It uses the physical counter as the clock source and the virtual counter as sched_clock.

The timer frequency can be specified via DT or read from the CNTFRQ_EL0 register. The physical counter is also accessible from user space allowing fast gettimeofday() implementation.

---
 arch/arm64/include/asm/timex.h    |   32 ++++
 arch/arm64/kernel/time.c          |   65 ++++++++
 drivers/clocksource/Kconfig       |    5 +
 drivers/clocksource/Makefile      |    1 +
 drivers/clocksource/arm_generic.c |  309 +++++++++++++++++++++++++++++++++++++
 include/clocksource/arm_generic.h |   21 +++
 6 files changed, 433 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/timex.h
 create mode 100644 arch/arm64/kernel/time.c
 create mode 100644 drivers/clocksource/arm_generic.c
 create mode 100644 include/clocksource/arm_generic.h
arch/arm64/include/asm/timex.h new file +32 -0
new file mode 100644
index 0000000..88f74de
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_TIMEX_H
+#define __ASM_TIMEX_H
+
+/*
+ * Use the current timer as a cycle counter since this is what we use for
+ * the delay loop.
+ */
+#define get_cycles()	({ cycles_t c; read_current_timer(&c); c; })
+
+#include <asm-generic/timex.h>
+
+#define ARCH_HAS_READ_CURRENT_TIMER
+
+/* This isn't really used any more */
+#define CLOCK_TICK_RATE 1000
+
+#endif
arch/arm64/kernel/time.c new file +65 -0

65 lines not on this page · raw message

drivers/clocksource/Kconfig +5 -0
index d53cd0a..6a78073 100644
@@ -35,3 +35,8 @@ config CLKSRC_DBX500_PRCMU_SCHED_CLOCK
 	default y
 	help
 	  Use the always on PRCMU Timer as sched_clock
+
+config CLKSRC_ARM_GENERIC
+	def_bool y if ARM64
+	help
+	  This option enables support for the ARM generic timer.
drivers/clocksource/Makefile +1 -0
index b65d0c5..6591990 100644
@@ -13,3 +13,4 @@ obj-$(CONFIG_DW_APB_TIMER)	+= dw_apb_timer.o
 obj-$(CONFIG_DW_APB_TIMER_OF)	+= dw_apb_timer_of.o
 obj-$(CONFIG_CLKSRC_DBX500_PRCMU)	+= clksrc-dbx500-prcmu.o
 obj-$(CONFIG_ARMADA_370_XP_TIMER)	+= time-armada-370-xp.o
+obj-$(CONFIG_CLKSRC_ARM_GENERIC)	+= arm_generic.o
drivers/clocksource/arm_generic.c new file +309 -0

309 lines not on this page · raw message

include/clocksource/arm_generic.h new file +21 -0
new file mode 100644
index 0000000..5b41b0d
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __CLKSOURCE_ARM_GENERIC_H
+#define __CLKSOURCE_ARM_GENERIC_H
+
+extern int arm_generic_timer_init(void);
+
+#endif
author maintainer
#160 lore raw

PATCH v2 29/31 arm64: Miscellaneous header files

In reply to Catalin Marinas

This patch introduces a few AArch64-specific header files together with Kbuild entries for generic headers.

---
 arch/arm64/include/asm/Kbuild        |   51 ++++++++++
 arch/arm64/include/asm/barrier.h     |   52 ++++++++++
 arch/arm64/include/asm/bitsperlong.h |   23 +++++
 arch/arm64/include/asm/byteorder.h   |   21 ++++
 arch/arm64/include/asm/cmpxchg.h     |  180 ++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/compiler.h    |   30 ++++++
 arch/arm64/include/asm/exception.h   |   23 +++++
 arch/arm64/include/asm/exec.h        |   23 +++++
 arch/arm64/include/asm/fcntl.h       |   29 ++++++
 arch/arm64/include/asm/system_misc.h |   54 ++++++++++
 10 files changed, 486 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/Kbuild
 create mode 100644 arch/arm64/include/asm/barrier.h
 create mode 100644 arch/arm64/include/asm/bitsperlong.h
 create mode 100644 arch/arm64/include/asm/byteorder.h
 create mode 100644 arch/arm64/include/asm/cmpxchg.h
 create mode 100644 arch/arm64/include/asm/compiler.h
 create mode 100644 arch/arm64/include/asm/exception.h
 create mode 100644 arch/arm64/include/asm/exec.h
 create mode 100644 arch/arm64/include/asm/fcntl.h
 create mode 100644 arch/arm64/include/asm/system_misc.h
arch/arm64/include/asm/Kbuild new file +51 -0
new file mode 100644
index 0000000..35924a5
@@ -0,0 +1,51 @@
+include include/asm-generic/Kbuild.asm
+
+header-y += hwcap.h
+
+generic-y += bug.h
+generic-y += bugs.h
+generic-y += checksum.h
+generic-y += cputime.h
+generic-y += current.h
+generic-y += delay.h
+generic-y += div64.h
+generic-y += dma.h
+generic-y += emergency-restart.h
+generic-y += errno.h
+generic-y += ftrace.h
+generic-y += hw_irq.h
+generic-y += ioctl.h
+generic-y += ioctls.h
+generic-y += ipcbuf.h
+generic-y += irq_regs.h
+generic-y += kdebug.h
+generic-y += kmap_types.h
+generic-y += linkage.h
+generic-y += local.h
+generic-y += local64.h
+generic-y += mman.h
+generic-y += msgbuf.h
+generic-y += mutex.h
+generic-y += pci.h
+generic-y += percpu.h
+generic-y += poll.h
+generic-y += posix_types.h
+generic-y += resource.h
+generic-y += scatterlist.h
+generic-y += sections.h
+generic-y += segment.h
+generic-y += sembuf.h
+generic-y += serial.h
+generic-y += shmbuf.h
+generic-y += sizes.h
+generic-y += socket.h
+generic-y += sockios.h
+generic-y += string.h
+generic-y += switch_to.h
+generic-y += swab.h
+generic-y += termbits.h
+generic-y += termios.h
+generic-y += topology.h
+generic-y += types.h
+generic-y += unaligned.h
+generic-y += user.h
arch/arm64/include/asm/barrier.h new file +52 -0

52 lines not on this page · raw message

arch/arm64/include/asm/bitsperlong.h new file +23 -0
new file mode 100644
index 0000000..fce9c29
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_BITSPERLONG_H
+#define __ASM_BITSPERLONG_H
+
+#define __BITS_PER_LONG 64
+
+#include <asm-generic/bitsperlong.h>
+
+#endif	/* __ASM_BITSPERLONG_H */
arch/arm64/include/asm/byteorder.h new file +21 -0
new file mode 100644
index 0000000..2b92046
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_BYTEORDER_H
+#define __ASM_BYTEORDER_H
+
+#include <linux/byteorder/little_endian.h>
+
+#endif	/* __ASM_BYTEORDER_H */
arch/arm64/include/asm/cmpxchg.h new file +180 -0

180 lines not on this page · raw message

arch/arm64/include/asm/compiler.h new file +30 -0
new file mode 100644
index 0000000..ee35fd0
@@ -0,0 +1,30 @@
+/*
+ * Based on arch/arm/include/asm/compiler.h
+ *
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_COMPILER_H
+#define __ASM_COMPILER_H
+
+/*
+ * This is used to ensure the compiler did actually allocate the register we
+ * asked it for some inline assembly sequences.  Apparently we can't trust the
+ * compiler from one version to another so a bit of paranoia won't hurt.  This
+ * string is meant to be concatenated with the inline asm string and will
+ * cause compilation to stop on mismatch.  (for details, see gcc PR 15089)
+ */
+#define __asmeq(x, y)  ".ifnc " x "," y " ; .err ; .endif\n\t"
+
+#endif	/* __ASM_COMPILER_H */
arch/arm64/include/asm/exception.h new file +23 -0
new file mode 100644
index 0000000..ac63519
@@ -0,0 +1,23 @@
+/*
+ * Based on arch/arm/include/asm/exception.h
+ *
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_EXCEPTION_H
+#define __ASM_EXCEPTION_H
+
+#define __exception	__attribute__((section(".exception.text")))
+
+#endif	/* __ASM_EXCEPTION_H */
arch/arm64/include/asm/exec.h new file +23 -0
new file mode 100644
index 0000000..db0563c
@@ -0,0 +1,23 @@
+/*
+ * Based on arch/arm/include/asm/exec.h
+ *
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_EXEC_H
+#define __ASM_EXEC_H
+
+extern unsigned long arch_align_stack(unsigned long sp);
+
+#endif	/* __ASM_EXEC_H */
arch/arm64/include/asm/fcntl.h new file +29 -0
new file mode 100644
index 0000000..cd2e630
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_FCNTL_H
+#define __ASM_FCNTL_H
+
+/*
+ * Using our own definitions for AArch32 (compat) support.
+ */
+#define O_DIRECTORY	 040000	/* must be a directory */
+#define O_NOFOLLOW	0100000	/* don't follow links */
+#define O_DIRECT	0200000	/* direct disk access hint - currently ignored */
+#define O_LARGEFILE	0400000
+
+#include <asm-generic/fcntl.h>
+
+#endif
arch/arm64/include/asm/system_misc.h new file +54 -0

54 lines not on this page · raw message

author maintainer
#162 lore raw

PATCH v2 30/31 arm64: Build infrastructure

In reply to Catalin Marinas

This patch adds Makefile and Kconfig files required for building an AArch64 kernel.

---
 arch/arm64/Kconfig                   |  261 ++++++++++++++++++++++++++++++++++
 arch/arm64/Kconfig.debug             |   27 ++++
 arch/arm64/Makefile                  |   71 +++++++++
 arch/arm64/boot/.gitignore           |    2 +
 arch/arm64/boot/Makefile             |   38 +++++
 arch/arm64/boot/install.sh           |   52 +++++++
 arch/arm64/configs/generic_defconfig |   85 +++++++++++
 arch/arm64/include/asm/prom.h        |    1 +
 arch/arm64/kernel/.gitignore         |    1 +
 arch/arm64/kernel/Makefile           |   27 ++++
 arch/arm64/kernel/vmlinux.lds.S      |  146 +++++++++++++++++++
 arch/arm64/mm/Kconfig                |    5 +
 arch/arm64/mm/Makefile               |    6 +
 init/Kconfig                         |    3 +-
 lib/Kconfig.debug                    |    6 +-
 15 files changed, 728 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm64/Kconfig
 create mode 100644 arch/arm64/Kconfig.debug
 create mode 100644 arch/arm64/Makefile
 create mode 100644 arch/arm64/boot/.gitignore
 create mode 100644 arch/arm64/boot/Makefile
 create mode 100644 arch/arm64/boot/install.sh
 create mode 100644 arch/arm64/configs/generic_defconfig
 create mode 100644 arch/arm64/include/asm/prom.h
 create mode 100644 arch/arm64/kernel/.gitignore
 create mode 100644 arch/arm64/kernel/Makefile
 create mode 100644 arch/arm64/kernel/vmlinux.lds.S
 create mode 100644 arch/arm64/mm/Kconfig
 create mode 100644 arch/arm64/mm/Makefile
arch/arm64/Kconfig new file +261 -0
new file mode 100644
index 0000000..1ce3d04
@@ -0,0 +1,261 @@
+config ARM64
+	def_bool y
+	select OF
+	select OF_EARLY_FLATTREE
+	select IRQ_DOMAIN
+	select HAVE_AOUT
+	select HAVE_DMA_ATTRS
+	select HAVE_DMA_API_DEBUG
+	select HAVE_IDE
+	select HAVE_MEMBLOCK
+	select RTC_LIB
+	select SYS_SUPPORTS_APM_EMULATION
+	select HAVE_GENERIC_DMA_COHERENT
+	select GENERIC_IOMAP
+	select HAVE_IRQ_WORK
+	select HAVE_PERF_EVENTS
+	select HAVE_ARCH_TRACEHOOK
+	select PERF_USE_VMALLOC
+	select HAVE_HW_BREAKPOINT if PERF_EVENTS
+	select HAVE_GENERIC_HARDIRQS
+	select GENERIC_HARDIRQS_NO_DEPRECATED
+	select HAVE_SPARSE_IRQ
+	select SPARSE_IRQ
+	select GENERIC_IRQ_SHOW
+	select GENERIC_SMP_IDLE_THREAD
+	select NO_BOOTMEM
+	help
+	  ARM 64-bit (AArch64) Linux support.
+
+config 64BIT
+	def_bool y
+
+config ARCH_PHYS_ADDR_T_64BIT
+	def_bool y
+
+config HAVE_PWM
+	bool
+
+config SYS_SUPPORTS_APM_EMULATION
+	bool
+
+config NO_IOPORT
+	def_bool y
+
+config GENERIC_GPIO
+	bool
+
+config GENERIC_TIME_VSYSCALL
+	def_bool y
+
+config GENERIC_CLOCKEVENTS
+	def_bool y
+
+config STACKTRACE_SUPPORT
+	def_bool y
+
+config LOCKDEP_SUPPORT
+	def_bool y
+
+config TRACE_IRQFLAGS_SUPPORT
+	def_bool y
+
+config HARDIRQS_SW_RESEND
+	def_bool y
+
+config GENERIC_IRQ_PROBE
+	def_bool y
+
+config GENERIC_LOCKBREAK
+	def_bool y
+	depends on SMP && PREEMPT
+
+config RWSEM_GENERIC_SPINLOCK
+	def_bool y
+
+config RWSEM_XCHGADD_ALGORITHM
+	bool
+
+config ARCH_HAS_ILOG2_U32
+	bool
+
+config ARCH_HAS_ILOG2_U64
+	bool
+
+config ARCH_HAS_CPUFREQ
+	bool
+	help
+	  Internal node to signify that the ARCH has CPUFREQ support
+	  and that the relevant menu configurations are displayed for
+	  it.
+
+config GENERIC_HWEIGHT
+	def_bool y
+
+config GENERIC_CSUM
+        def_bool y
+
+config GENERIC_CALIBRATE_DELAY
+	def_bool y
+
+config ZONE_DMA32
+	def_bool y
+
+config ARCH_DMA_ADDR_T_64BIT
+	def_bool y
+
+config NEED_DMA_MAP_STATE
+	def_bool y
+
+config NEED_SG_DMA_LENGTH
+	def_bool y
+
+config SWIOTLB
+	def_bool y
+
+config IOMMU_HELPER
+	def_bool SWIOTLB
+
+source "init/Kconfig"
+
+source "kernel/Kconfig.freezer"
+
+menu "System Type"
+
+source "arch/arm64/mm/Kconfig"
+
+endmenu
+
+menu "Bus support"
+
+config ARM_AMBA
+	bool
+
+endmenu
+
+menu "Kernel Features"
+
+source "kernel/time/Kconfig"
+
+config ARM64_64K_PAGES
+	bool "Enable 64KB pages support"
+	help
+	  This feature enables 64KB pages support (4KB by default)
+	  allowing only two levels of page tables and faster TLB
+	  look-up. AArch32 emulation is not available when this feature
+	  is enabled.
+
+config SMP
+	bool "Symmetric Multi-Processing"
+	depends on GENERIC_CLOCKEVENTS
+	select USE_GENERIC_SMP_HELPERS
+	help
+	  This enables support for systems with more than one CPU.  If
+	  you say N here, the kernel will run on single and
+	  multiprocessor machines, but will use only one CPU of a
+	  multiprocessor machine. If you say Y here, the kernel will run
+	  on many, but not all, single processor machines. On a single
+	  processor machine, the kernel will run faster if you say N
+	  here.
+
+	  If you don't know what to do here, say N.
+
+config NR_CPUS
+	int "Maximum number of CPUs (2-32)"
+	range 2 32
+	depends on SMP
+	default "4"
+
+source kernel/Kconfig.preempt
+
+config HZ
+	int
+	default 100
+
+config ARCH_HAS_HOLES_MEMORYMODEL
+	def_bool y if SPARSEMEM
+
+config ARCH_SPARSEMEM_ENABLE
+	def_bool y
+	select SPARSEMEM_VMEMMAP_ENABLE
+
+config ARCH_SPARSEMEM_DEFAULT
+	def_bool ARCH_SPARSEMEM_ENABLE
+
+config ARCH_SELECT_MEMORY_MODEL
+	def_bool ARCH_SPARSEMEM_ENABLE
+
+config HAVE_ARCH_PFN_VALID
+	def_bool ARCH_HAS_HOLES_MEMORYMODEL || !SPARSEMEM
+
+config HW_PERF_EVENTS
+	bool "Enable hardware performance counter support for perf events"
+	depends on PERF_EVENTS
+	default y
+	help
+	  Enable hardware performance counter support for perf events. If
+	  disabled, perf events will use software events only.
+
+source "mm/Kconfig"
+
+endmenu
+
+menu "Boot options"
+
+config CMDLINE
+	string "Default kernel command string"
+	default ""
+	help
+	  Provide a set of default command-line options at build time by
+	  entering them here. As a minimum, you should specify the the
+	  root device (e.g. root=/dev/nfs).
+
+config CMDLINE_FORCE
+	bool "Always use the default kernel command string"
+	help
+	  Always use the default kernel command string, even if the boot
+	  loader passes other arguments to the kernel.
+	  This is useful if you cannot or don't want to change the
+	  command-line options your boot loader passes to the kernel.
+
+endmenu
+
+menu "Userspace binary formats"
+
+source "fs/Kconfig.binfmt"
+
+config AARCH32_EMULATION
+	bool "Kernel support for 32-bit EL0"
+	depends on !ARM64_64K_PAGES
+	select COMPAT_BINFMT_ELF
+	help
+	  This option enables support for a 32-bit EL0 running under a 64-bit
+	  kernel at EL1. AArch32-specific components such as system calls,
+	  the user helper functions, VFP support and the ptrace interface are
+	  handled appropriately by the kernel.
+
+	  If you want to execute 32-bit userspace applications, say Y.
+
+config COMPAT
+	def_bool y
+	depends on AARCH32_EMULATION
+
+config SYSVIPC_COMPAT
+	def_bool y
+	depends on COMPAT && SYSVIPC
+
+endmenu
+
+source "net/Kconfig"
+
+source "drivers/Kconfig"
+
+source "fs/Kconfig"
+
+source "arch/arm64/Kconfig.debug"
+
+source "security/Kconfig"
+
+source "crypto/Kconfig"
+
+source "lib/Kconfig"
arch/arm64/Kconfig.debug new file +27 -0
new file mode 100644
index 0000000..d7553f2
@@ -0,0 +1,27 @@
+menu "Kernel hacking"
+
+source "lib/Kconfig.debug"
+
+config FRAME_POINTER
+	bool
+	default y
+
+config DEBUG_ERRORS
+	bool "Verbose kernel error messages"
+	depends on DEBUG_KERNEL
+	help
+	  This option controls verbose debugging information which can be
+	  printed when the kernel detects an internal error. This debugging
+	  information is useful to kernel hackers when tracking down problems,
+	  but mostly meaningless to other people. It's safe to say Y unless
+	  you are concerned with the code size or don't want to see these
+	  messages.
+
+config DEBUG_STACK_USAGE
+	bool "Enable stack utilization instrumentation"
+	depends on DEBUG_KERNEL
+	help
+	  Enables the display of the minimum amount of free stack which each
+	  task has ever had available in the sysrq-T output.
+
+endmenu
arch/arm64/Makefile new file +71 -0

71 lines not on this page · raw message

arch/arm64/boot/.gitignore new file +2 -0
new file mode 100644
index 0000000..8dab0bb
@@ -0,0 +1,2 @@
+Image
+Image.gz
arch/arm64/boot/Makefile new file +38 -0
new file mode 100644
index 0000000..15a58a8
@@ -0,0 +1,38 @@
+#
+# arch/arm64/boot/Makefile
+#
+# This file is included by the global makefile so that you can add your own
+# architecture-specific flags and dependencies.
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# License.  See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+# Copyright (C) 2012, ARM Ltd.
+# Author: Will Deacon <[email protected]>
+#
+# Based on the ia64 boot/Makefile.
+#
+
+targets := Image Image.gz
+
+$(obj)/Image: vmlinux FORCE
+	$(call if_changed,objcopy)
+	@echo '  Kernel: $@ is ready'
+
+$(obj)/Image.gz: $(obj)/Image FORCE
+	$(call if_changed,gzip)
+	@echo '  Kernel: $@ is ready'
+
+$(obj)/%.dtb: $(src)/dts/%.dts
+	$(call cmd,dtc)
+
+install: $(obj)/Image
+	$(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \
+	$(obj)/Image System.map "$(INSTALL_PATH)"
+
+zinstall: $(obj)/Image.gz
+	$(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \
+	$(obj)/Image.gz System.map "$(INSTALL_PATH)"
+
+clean-files += *.dtb
arch/arm64/boot/install.sh new file +52 -0

52 lines not on this page · raw message

arch/arm64/configs/generic_defconfig new file +85 -0

85 lines not on this page · raw message

arch/arm64/include/asm/prom.h new file +1 -0
new file mode 100644
index 0000000..68b90e6
@@ -0,0 +1 @@
+/* Empty for now */
arch/arm64/kernel/.gitignore new file +1 -0
new file mode 100644
index 0000000..c5f676c
@@ -0,0 +1 @@
+vmlinux.lds
arch/arm64/kernel/Makefile new file +27 -0
new file mode 100644
index 0000000..59fbdef
@@ -0,0 +1,27 @@
+#
+# Makefile for the linux kernel.
+#
+
+CPPFLAGS_vmlinux.lds	:= -DTEXT_OFFSET=$(TEXT_OFFSET)
+AFLAGS_head.o		:= -DTEXT_OFFSET=$(TEXT_OFFSET)
+
+# Object file lists.
+arm64-obj-y		:= debug-monitors.o elf.o entry.o irq.o	fpsimd.o	\
+			   entry-fpsimd.o process.o ptrace.o setup.o signal.o	\
+			   sys.o stacktrace.o time.o traps.o io.o vdso.o
+
+arm64-obj-$(CONFIG_AARCH32_EMULATION)	+= sys32.o kuser32.o signal32.o 	\
+					   sys_compat.o
+arm64-obj-$(CONFIG_MODULES)		+= arm64ksyms.o module.o
+arm64-obj-$(CONFIG_SMP)			+= smp.o
+arm64-obj-$(CONFIG_HW_PERF_EVENTS)	+= perf_event.o
+arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT)+= hw_breakpoint.o
+
+obj-y					+= $(arm64-obj-y) vdso/
+obj-m					+= $(arm64-obj-m)
+head-y					:= head.o
+extra-y					:= $(head-y) vmlinux.lds
+
+# vDSO - this must be built first to generate the symbol offsets
+$(call objectify,$(arm64-obj-y)): $(obj)/vdso/vdso-offsets.h
+$(obj)/vdso/vdso-offsets.h: $(obj)/vdso
arch/arm64/kernel/vmlinux.lds.S new file +146 -0

146 lines not on this page · raw message

arch/arm64/mm/Kconfig new file +5 -0
new file mode 100644
index 0000000..8e94e52
@@ -0,0 +1,5 @@
+config MMU
+	def_bool y
+
+config CPU_64
+	def_bool y
arch/arm64/mm/Makefile new file +6 -0
new file mode 100644
index 0000000..81a9d8b
@@ -0,0 +1,6 @@
+obj-y				:= dma-mapping.o extable.o fault.o init.o \
+				   cache.o copypage.o flush.o \
+				   ioremap.o mmap.o pgd.o mmu.o \
+				   context.o tlb.o proc.o
+
+obj-$(CONFIG_MODULES)		+= proc-syms.o
init/Kconfig +2 -1
index af6c7f8..8bfda46 100644
@@ -1153,7 +1153,8 @@ menuconfig EXPERT
 
 config UID16
 	bool "Enable 16-bit UID system calls" if EXPERT
-	depends on ARM || BLACKFIN || CRIS || FRV || H8300 || X86_32 || M68K || (S390 && !64BIT) || SUPERH || SPARC32 || (SPARC64 && COMPAT) || UML || (X86_64 && IA32_EMULATION)
+	depends on ARM || BLACKFIN || CRIS || FRV || H8300 || X86_32 || M68K || (S390 && !64BIT) || SUPERH || SPARC32 || (SPARC64 && COMPAT) || UML || (X86_64 && IA32_EMULATION) \
+		|| AARCH32_EMULATION
 	default y
 	help
 	  This enables the legacy 16-bit UID syscall wrappers.
lib/Kconfig.debug +4 -2
index 2403a63..cfb4578 100644
@@ -452,7 +452,8 @@ config SLUB_STATS
 config DEBUG_KMEMLEAK
 	bool "Kernel memory leak detector"
 	depends on DEBUG_KERNEL && EXPERIMENTAL && \
-		(X86 || ARM || PPC || MIPS || S390 || SPARC64 || SUPERH || MICROBLAZE || TILE)
+		(X86 || ARM || PPC || MIPS || S390 || SPARC64 || SUPERH || \
+		 MICROBLAZE || TILE || ARM64)
 
 	select DEBUG_FS
 	select STACKTRACE if STACKTRACE_SUPPORT
@@ -739,7 +740,8 @@ config DEBUG_BUGVERBOSE
 	bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EXPERT
 	depends on BUG
 	depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \
-		   FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 || TILE
+		   FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300 || \
+		   TILE || ARM64
 	default y
 	help
 	  Say Y here to make BUG() panics output the file name and line number
author maintainer
#167 lore raw

PATCH v2 31/31 arm64: MAINTAINERS update

In reply to Catalin Marinas

This patch updates the MAINTAINERS file for the AArch64 Linux kernel port.

---
 MAINTAINERS |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
MAINTAINERS +6 -0
index 94b823f..6d7c5f4 100644
@@ -1204,6 +1204,12 @@ S:	Maintained
 F:	arch/arm/mach-pxa/z2.c
 F:	arch/arm/mach-pxa/include/mach/z2.h
 
+ARM64 PORT (AARCH64 ARCHITECTURE)
+M:	Catalin Marinas <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+S:	Maintained
+F:	arch/arm64/
+
 ASC7621 HARDWARE MONITOR DRIVER
 M:	George Joseph <[email protected]>
 L:	[email protected]
#163 lore raw

Re: [PATCH v2 30/31] arm64: Build infrastructure

In reply to Catalin Marinas
Quoted 23 lines
arch/arm64/Kconfig new file +16 -0
new file mode 100644
index 0000000..1ce3d04
@@ -0,0 +1,261 @@
+config ARM64
+	def_bool y
+	select OF
+	select OF_EARLY_FLATTREE
+	select IRQ_DOMAIN
+	select HAVE_AOUT
+	select HAVE_DMA_ATTRS
+	select HAVE_DMA_API_DEBUG
+	select HAVE_IDE
+	select HAVE_MEMBLOCK
+	select RTC_LIB
+	select SYS_SUPPORTS_APM_EMULATION
+	select HAVE_GENERIC_DMA_COHERENT
+	select GENERIC_IOMAP
+	select HAVE_IRQ_WORK
+	select HAVE_PERF_EVENTS

arch/arm64/Kconfig line 26

Quoted 10 lines
arch/arm64/Kconfig new file +10 -0
+	select HAVE_ARCH_TRACEHOOK
+	select PERF_USE_VMALLOC
+	select HAVE_HW_BREAKPOINT if PERF_EVENTS
+	select HAVE_GENERIC_HARDIRQS
+	select GENERIC_HARDIRQS_NO_DEPRECATED
+	select HAVE_SPARSE_IRQ
+	select SPARSE_IRQ
+	select GENERIC_IRQ_SHOW
+	select GENERIC_SMP_IDLE_THREAD
+	select NO_BOOTMEM

If you keep this list sorted then merge conflicts are less likely.

Quoted 13 lines
arch/arm64/Kconfig new file +13 -0
+	help
+	  ARM 64-bit (AArch64) Linux support.
+
+config 64BIT
+	def_bool y
+
+config ARCH_PHYS_ADDR_T_64BIT
+	def_bool y
+
+config HAVE_PWM
+	bool
+
+config SYS_SUPPORTS_APM_EMULATION

arch/arm64/Kconfig line 49

Quoted 10 lines
arch/arm64/Kconfig new file +10 -0
+	bool
+
+config NO_IOPORT
+	def_bool y
+
+config GENERIC_GPIO
+	bool
+
+config GENERIC_TIME_VSYSCALL
+	def_bool y

Please use select like all other archs do.

arch/arm64/Kconfig line 52

Quoted 3 lines
arch/arm64/Kconfig new file +3 -0
+
+config GENERIC_CLOCKEVENTS
+	def_bool y

Again - please use select.

arch/arm64/Kconfig line 64

Quoted 12 lines
arch/arm64/Kconfig new file +12 -0
+
+config STACKTRACE_SUPPORT
+	def_bool y
+
+config LOCKDEP_SUPPORT
+	def_bool y
+
+config TRACE_IRQFLAGS_SUPPORT
+	def_bool y
+
+config HARDIRQS_SW_RESEND
+	def_bool y

Please use select.

arch/arm64/Kconfig line 67

Quoted 3 lines
arch/arm64/Kconfig new file +3 -0
+
+config GENERIC_IRQ_PROBE
+	def_bool y

Please use select.

Quoted 41 lines
arch/arm64/Kconfig new file +41 -0
+
+config GENERIC_LOCKBREAK
+	def_bool y
+	depends on SMP && PREEMPT
+
+config RWSEM_GENERIC_SPINLOCK
+	def_bool y
+
+config RWSEM_XCHGADD_ALGORITHM
+	bool
+
+config ARCH_HAS_ILOG2_U32
+	bool
+
+config ARCH_HAS_ILOG2_U64
+	bool
+
+config ARCH_HAS_CPUFREQ
+	bool
+	help
+	  Internal node to signify that the ARCH has CPUFREQ support
+	  and that the relevant menu configurations are displayed for
+	  it.
+
+config GENERIC_HWEIGHT
+	def_bool y
+
+config GENERIC_CSUM
+        def_bool y
+
+config GENERIC_CALIBRATE_DELAY
+	def_bool y
+
+config ZONE_DMA32
+	def_bool y
+
+config ARCH_DMA_ADDR_T_64BIT
+	def_bool y
+
+config NEED_DMA_MAP_STATE
+	def_bool y

arch/arm64/Kconfig line 118

Quoted 10 lines
arch/arm64/Kconfig new file +10 -0
+
+config NEED_SG_DMA_LENGTH
+	def_bool y
+
+config SWIOTLB
+	def_bool y
+
+config IOMMU_HELPER
+	def_bool SWIOTLB
+

Sam

#4 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Catalin Marinas

Hi,

Quoted 25 lines · Catalin Marinas
Documentation/arm64/booting.txt new file +25 -0
+Before jumping into the kernel, the following conditions must be met:
+
+- Quiesce all DMA capable devices so that memory does not get
+  corrupted by bogus network packets or disk data.  This will save
+  you many hours of debug.
+
+- Primary CPU general-purpose register settings
+  x0 = physical address of device tree blob (dtb) in system RAM.
+
+- CPU mode
+  All forms of interrupts must be masked in PSTATE.DAIF (Debug, SError,
+  IRQ and FIQ).
+  The CPU must be in either EL2 (RECOMMENDED in order to have access to
+  the virtualisation extensions) or non-secure EL1.
+
+- Caches, MMUs
+  The MMU must be off.
+  Instruction cache may be on or off.
+  Data cache must be off and invalidated.
+
+- Architected timers
+  CNTFRQ must be programmed with the timer frequency.
+  If entering the kernel at EL1, CNTHCTL_EL2 must have EL1PCTEN (bit 0)
+  set where available.
+

Documentation/arm64/booting.txt line 116

Quoted 10 lines
Documentation/arm64/booting.txt new file +10 -0
+- Coherency
+  All CPUs to be booted by the kernel must be part of the same coherency
+  domain on entry to the kernel.  This may require IMPLEMENTATION DEFINED
+  initialisation to enable the receiving of maintenance operations on
+  each CPU.
+
+- System registers
+  All writable architected system registers at the exception level where
+  the kernel image will be entered must be initialised by software at a
+  higher exception level to prevent execution in an UNKNOWN state.

Given the recent development of ARM platforms, you might want to mandate the state of IOMMUs as well (they should probably be off, since there should be no active DMA activity). Graphics would be the exception to this, since if you want to keep scanning out a splash screen, you'll have to keep doing DMA...

Documentation/arm64/booting.txt line 129

Quoted 9 lines

+- The primary CPU must jump directly to the first instruction of the

Documentation/arm64/booting.txt new file +8 -0
+  kernel image.  The device tree blob passed by this CPU must contain
+  for each CPU node:
+
+    1. An 'enable-method' property. Currently, the only supported value
+       for this field is the string "spin-table".
+
+    2. A 'cpu-release-addr' property identifying a 64-bit,
+       zero-initialised memory location.

These would be good to have documented in the Documentation/devicetree/bindings hierarchy as well.

Quoted 18 lines

index 0000000..d766493

arch/arm64/include/asm/setup.h new file +14 -0
@@ -0,0 +1,26 @@
+/*
+ * Based on arch/arm/include/asm/setup.h
+ *
+ * Copyright (C) 1997-1999 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.

arch/arm64/include/asm/setup.h line 24

Quoted 10 lines
arch/arm64/include/asm/setup.h new file +10 -0
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SETUP_H
+#define __ASM_SETUP_H
+
+#include <linux/types.h>
+
+#define COMMAND_LINE_SIZE 1024

Probably not a huge deal, and other architectures seem to be all over the map on this, but you might want to go with a larger value now rather than later. 2048 or 4096 perhaps?

Quoted 5 lines
arch/arm64/kernel/head.S new file +0 -0
new file mode 100644
index 0000000..34ccdc0

[...]

arch/arm64/kernel/head.S line 253

Quoted 8 lines
arch/arm64/kernel/head.S new file +8 -0
+/*
+ * Setup common bits before finally enabling the MMU. Essentially this is just
+ * loading the page table pointer and vector base registers.
+ *
+ * On entry to this code, x0 must contain the SCTLR_EL1 value for turning on
+ * the MMU.
+ */
+__enable_mmu:

ENTRY()?

arch/arm64/kernel/head.S line 260

Quoted 7 lines
arch/arm64/kernel/head.S new file +7 -0
+	ldr	x5, =vectors
+	msr	vbar_el1, x5
+	msr	ttbr0_el1, x25			// load TTBR0
+	msr	ttbr1_el1, x26			// load TTBR1
+	isb
+	b	__turn_mmu_on
+ENDPROC(__enable_mmu)

...or just END()? Same for a few of the other functions below.

Quoted 5 lines
arch/arm64/kernel/setup.c new file +0 -0
new file mode 100644
index 0000000..f25186f

[...]

arch/arm64/kernel/setup.c line 112

Quoted 9 lines
arch/arm64/kernel/setup.c new file +9 -0
+static void __init setup_processor(void)
+{
+	struct proc_info_list *list;
+
+	/*
+	 * locate processor in the list of supported processor
+	 * types.  The linker builds this table for us from the
+	 * entries in arch/arm/mm/proc.S
+	 */

Probably from arch/arm64/... somewhere?

[...]

Quoted 4 lines
arch/arm64/kernel/setup.c new file +4 -0
+	printk("CPU: %s [%08x] revision %d\n",
+	       cpu_name, read_cpuid_id(), read_cpuid_id() & 15);
+
+	sprintf(init_utsname()->machine, "aarch64");

arch/arm64/kernel/setup.c line 171

Quoted 10 lines
arch/arm64/kernel/setup.c new file +9 -0
 
+	initial_boot_params = devtree;
+	dt_root = of_get_flat_dt_root();
+
+	machine_name = of_get_flat_dt_prop(dt_root, "model", NULL);
+	if (!machine_name)
+		machine_name = of_get_flat_dt_prop(dt_root, "compatible", NULL);
+	if (!machine_name)
+		machine_name = "<unknown>";
+	pr_info("Machine: %s\n", machine_name);

This property is an array of strings. It would be more valuable to print out the entry that was matched for a platform instead of the provided one from the device tree.

-Olof

#65 lore raw

Re: [PATCH v2 11/31] arm64: IRQ handling

In reply to Catalin Marinas

Hi,

arch/arm64/kernel/irq.c line 60

Quoted 13 lines · Catalin Marinas
arch/arm64/kernel/irq.c new file +13 -0
+void handle_IRQ(unsigned int irq, struct pt_regs *regs)
+{
+	struct pt_regs *old_regs = set_irq_regs(regs);
+
+	irq_enter();
+
+	/*
+	 * Some hardware gives randomly wrong interrupts.  Rather
+	 * than crashing, do something sensible.
+	 */
+	if (unlikely(irq >= nr_irqs)) {
+		if (printk_ratelimit())
+			pr_warning("Bad IRQ%u\n", irq);

I guess pr_warn_ratelimited() should be used for new code.

(See include/linux/printk.h, "Please don't use printk_ratelimit()...")

A.

#23 lore raw

Re: [PATCH v2 03/31] arm64: Exception handling

In reply to Catalin Marinas

Hi,

This one is a bit denser, so just a quick first pass with a couple of minor comments. I'll revisit the rest.

arch/arm64/kernel/entry.S line 286

Quoted 12 lines · Catalin Marinas
arch/arm64/kernel/entry.S new file +12 -0
+el1_sp_pc:
+	/*
+	 *Stack or PC alignment exception handling
+	 */
+	mrs	x0, far_el1
+	mov	x1, x25
+	mov	x2, sp
+	b	do_sp_pc_abort
+el1_undef:
+	/*
+	 *Undefined instruction
+	 */

Nit: Missing spaces in the comment here and the one above.

arch/arm64/kernel/entry.S line 471

Quoted 6 lines
arch/arm64/kernel/entry.S new file +6 -0
+el0_undef:
+	/*
+	 *Undefined instruction
+	 */
+	mov	x0, sp
+	b	do_undefinstr

Here too.

Quoted 5 lines
arch/arm64/kernel/traps.c new file +0 -0
new file mode 100644
index 0000000..8712a8e

[...]

Quoted 1 line

+DEFINE_SPINLOCK(die_lock);

Should probably be static.

#24 lore raw

Re: [PATCH v2 03/31] arm64: Exception handling

Quoted 9 lines · Olof Johansson
Quoted 5 lines
arch/arm64/kernel/traps.c new file +0 -0
new file mode 100644
index 0000000..8712a8e

[...]

Quoted 1 line

+DEFINE_SPINLOCK(die_lock);

Should probably be static.

And RAW_

#45 lore raw

Re: [PATCH v2 07/31] arm64: Process management

In reply to Catalin Marinas

Hi,

Quoted 6 lines · Catalin Marinas
arch/arm64/kernel/process.c new file +0 -0
new file mode 100644
index 0000000..c4a4e1c
@@ -0,0 +1,416 @@

[...]

Quoted 8 lines
arch/arm64/kernel/process.c new file +8 -0
+/*
+ * Function pointers to optional machine specific functions
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+void (*pm_restart)(const char *cmd);
+EXPORT_SYMBOL_GPL(pm_restart);

[...]

arch/arm64/kernel/process.c line 102

Quoted 2 lines
arch/arm64/kernel/process.c new file +2 -0
+void (*pm_idle)(void) = default_idle;
+EXPORT_SYMBOL(pm_idle);

Does it really make sense to export these to modules?

I find the powerpc way of having a machine descriptor structure with these (and other) function pointers in it a bit cleaner, since it gives you one place to plug it all in. I'd recommend that you consider doing that here as well, for these three and potentially other cases in the future.

(See arch/powerpc/include/asm/machdep.h, struct machdep_calls).

arch/arm64/kernel/process.c line 163

Quoted 12 lines
arch/arm64/kernel/process.c new file +12 -0
+void machine_halt(void)
+{
+	machine_shutdown();
+	while (1);
+}
+
+void machine_power_off(void)
+{
+	machine_shutdown();
+	if (pm_power_off)
+		pm_power_off();
+}

Printing something here along the lines of "System halted, OK to power off" is useful.

-Olof

#52 lore raw

Re: [PATCH v2 08/31] arm64: CPU support

In reply to Catalin Marinas

Hi,

Quoted 43 lines · Catalin Marinas
arch/arm64/include/asm/cputype.h new file +37 -0
new file mode 100644
index 0000000..ef54125
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_CPUTYPE_H
+#define __ASM_CPUTYPE_H
+
+#define ID_MIDR_EL1		"midr_el1"
+#define ID_CTR_EL0		"ctr_el0"
+
+#define ID_AA64PFR0_EL1		"id_aa64pfr0_el1"
+#define ID_AA64DFR0_EL1		"id_aa64dfr0_el1"
+#define ID_AA64AFR0_EL1		"id_aa64afr0_el1"
+#define ID_AA64ISAR0_EL1	"id_aa64isar0_el1"
+#define ID_AA64MMFR0_EL1	"id_aa64mmfr0_el1"
+
+#define read_cpuid(reg) ({						\
+	u64 __val;							\
+	asm("mrs	%0, " reg : "=r" (__val));			\
+	__val;								\
+})
+
+/*
+ * The CPU ID never changes at run time, so we might as well tell the
+ * compiler that it's constant.  Use this function to read the CPU ID
+ * rather than directly reading processor_id or read_cpuid() directly.

arch/arm64/include/asm/cputype.h line 47

Quoted 10 lines
arch/arm64/include/asm/cputype.h new file +10 -0
+ */
+static inline u32 __attribute_const__ read_cpuid_id(void)
+{
+	return read_cpuid(ID_MIDR_EL1);
+}
+
+static inline u32 __attribute_const__ read_cpuid_cachetype(void)
+{
+	return read_cpuid(ID_CTR_EL0);
+}

Is this perhaps a carry-over from arch/arm? Abstracting out read_cpuid() doesn't seem to buy anything here, just opencode the one-line assembly in each.

Might as well cleanup the naming a little too while you're at it, i.e. read_cpu_id() and read_cpu_cachetype().

Quoted 23 lines
arch/arm64/include/asm/procinfo.h new file +17 -0
new file mode 100644
index 0000000..81fece9
@@ -0,0 +1,44 @@
+/*
+ * Based on arch/arm/include/asm/procinfo.h
+ *
+ * Copyright (C) 1996-1999 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.

arch/arm64/include/asm/procinfo.h line 27

Quoted 10 lines
arch/arm64/include/asm/procinfo.h new file +10 -0
+ */
+#ifndef __ASM_PROCINFO_H
+#define __ASM_PROCINFO_H
+
+#ifdef __KERNEL__
+
+/*
+ * Note!  struct processor is always defined if we're
+ * using MULTI_CPU, otherwise this entry is unused,
+ * but still exists.

Stale comment?

arch/arm64/include/asm/procinfo.h line 31

Quoted 4 lines
arch/arm64/include/asm/procinfo.h new file +4 -0
+ *
+ * NOTE! The following structure is defined by assembly
+ * language, NOT C code.  For more information, check:
+ *  arch/arm/mm/proc-*.S and arch/arm/kernel/head.S

Stale references. Also, no current arm64 implementation uses this. Premature abstraction perhaps?

Quoted 39 lines
arch/arm64/include/asm/procinfo.h new file +12 -0
+struct proc_info_list {
+	unsigned int		cpu_val;
+	unsigned int		cpu_mask;
+	unsigned long		__cpu_flush;		/* used by head.S */
+	const char		*cpu_name;
+};
+
+#else	/* __KERNEL__ */
+#include <asm/elf.h>
+#warning "Please include asm/elf.h instead"
+#endif	/* __KERNEL__ */
+#endif
arch/arm64/mm/proc-syms.c new file +21 -0
new file mode 100644
index 0000000..2d99ef9
@@ -0,0 +1,31 @@
+/*
+ * Based on arch/arm/mm/proc-syms.c
+ *
+ * Copyright (C) 2000-2002 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/export.h>
+#include <linux/mm.h>
+

arch/arm64/mm/proc-syms.c line 31

Quoted 10 lines
arch/arm64/mm/proc-syms.c new file +10 -0
+#include <asm/cacheflush.h>
+#include <asm/proc-fns.h>
+#include <asm/tlbflush.h>
+#include <asm/page.h>
+
+EXPORT_SYMBOL(__cpuc_flush_kern_all);
+EXPORT_SYMBOL(__cpuc_flush_user_all);
+EXPORT_SYMBOL(__cpuc_flush_user_range);
+EXPORT_SYMBOL(__cpuc_coherent_kern_range);
+EXPORT_SYMBOL(__cpuc_flush_dcache_area);

See comment on other email about putting function pointers in a struct instead.

Quoted 7 lines
arch/arm64/mm/proc.S new file +1 -0
new file mode 100644
index 0000000..453f517
@@ -0,0 +1,193 @@
+	.section ".proc.info.init", #alloc, #execinstr

arch/arm64/mm/proc.S line 11

Quoted 10 lines
arch/arm64/mm/proc.S new file +10 -0
+
+	.type	__v8_proc_info, #object
+__v8_proc_info:
+	.long	0x000f0000			// Required ID value
+	.long	0x000f0000			// Mask for ID
+	b	__cpu_setup
+	nop
+	.quad	cpu_name
+	.long	0
+	.size	__v8_proc_info, . - __v8_proc_info

I know this is a carry-over from arch/arm, but how about moving this to more of a C construct similar to arch/powerpc/kernel/cputable.c instead? It's considerably easier to read that way, and it's convenient to have the definitions all in one place, making it easier to share some of the functions, etc.

-Olof

#67 lore raw

Re: [PATCH v2 12/31] arm64: Atomic operations

In reply to Catalin Marinas

Hi,

Quoted 64 lines · Catalin Marinas

This patch introduces the atomic, mutex and futex operations. Many atomic operations use the load-acquire and store-release operations which imply barriers, avoiding the need for explicit DMB.

---
 arch/arm64/include/asm/atomic.h |  306 +++++++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/futex.h  |  134 +++++++++++++++++
 2 files changed, 440 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/atomic.h
 create mode 100644 arch/arm64/include/asm/futex.h
arch/arm64/include/asm/atomic.h new file +45 -0
new file mode 100644
index 0000000..fa60c8b
@@ -0,0 +1,306 @@
+/*
+ * Based on arch/arm/include/asm/atomic.h
+ *
+ * Copyright (C) 1996 Russell King.
+ * Copyright (C) 2002 Deep Blue Solutions Ltd.
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_ATOMIC_H
+#define __ASM_ATOMIC_H
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+#include <asm/barrier.h>
+#include <asm/cmpxchg.h>
+
+#define ATOMIC_INIT(i)	{ (i) }
+
+#ifdef __KERNEL__
+
+/*
+ * On ARM, ordinary assignment (str instruction) doesn't clear the local
+ * strex/ldrex monitor on some implementations. The reason we can use it for
+ * atomic_set() is the clrex or dummy strex done on every exception return.
+ */
+#define atomic_read(v)	(*(volatile int *)&(v)->counter)
+#define atomic_set(v,i)	(((v)->counter) = (i))
+
+/*
+ * AArch64 UP and SMP safe atomic ops.  We use load exclusive and
+ * store exclusive to ensure that these are atomic.  We may loop
+ * to ensure that the update happens.
+ */

arch/arm64/include/asm/atomic.h line 55

Quoted 10 lines
arch/arm64/include/asm/atomic.h new file +10 -0
+static inline void atomic_add(int i, atomic_t *v)
+{
+	unsigned long tmp;
+	int result;
+
+	asm volatile("// atomic_add\n"
+"1:	ldxr	%w0, [%3]\n"
+"	add	%w0, %w0, %w4\n"
+"	stxr	%w1, %w0, [%3]\n"
+"	cbnz	%w1,1b"

Nit: space before 1b

[...]

Quoted 31 lines
arch/arm64/include/asm/futex.h new file +25 -0
new file mode 100644
index 0000000..0745e82
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_FUTEX_H
+#define __ASM_FUTEX_H
+
+#ifdef __KERNEL__
+
+#include <linux/futex.h>
+#include <linux/uaccess.h>
+#include <asm/errno.h>
+
+#define __futex_atomic_op(insn, ret, oldval, uaddr, tmp, oparg)		\

arch/arm64/include/asm/futex.h line 35

Quoted 10 lines
arch/arm64/include/asm/futex.h new file +10 -0
+	asm volatile(							\
+"1:	ldaxr	%w1, %2\n"						\
+	insn "\n"							\
+"2:	stlxr	%w3, %w0, %2\n"						\
+"	cbnz	%w3, 1b\n"						\
+"3:	.pushsection __ex_table,\"a\"\n"				\
+"	.align	3\n"							\
+"	.quad	1b, 4f, 2b, 4f\n"					\
+"	.popsection\n"							\
+"	.pushsection .fixup,\"ax\"\n"					\

Moving the exception table below the body of the code makes the flow easier to read, please do that.

Also, don't you need a barrier here?

Quoted 76 lines
arch/arm64/include/asm/futex.h new file +76 -0
+"4:	mov	%w0, %w5\n"						\
+"	b	3b\n"							\
+"	.popsection"							\
+	: "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp)	\
+	: "r" (oparg), "Ir" (-EFAULT)					\
+	: "cc")
+
+static inline int
+futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
+{
+	int op = (encoded_op >> 28) & 7;
+	int cmp = (encoded_op >> 24) & 15;
+	int oparg = (encoded_op << 8) >> 20;
+	int cmparg = (encoded_op << 20) >> 20;
+	int oldval = 0, ret, tmp;
+
+	if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
+		oparg = 1 << oparg;
+
+	if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
+		return -EFAULT;
+
+	pagefault_disable();	/* implies preempt_disable() */
+
+	switch (op) {
+	case FUTEX_OP_SET:
+		__futex_atomic_op("mov	%w0, %w4",
+				  ret, oldval, uaddr, tmp, oparg);
+		break;
+	case FUTEX_OP_ADD:
+		__futex_atomic_op("add	%w0, %w1, %w4",
+				  ret, oldval, uaddr, tmp, oparg);
+		break;
+	case FUTEX_OP_OR:
+		__futex_atomic_op("orr	%w0, %w1, %w4",
+				  ret, oldval, uaddr, tmp, oparg);
+		break;
+	case FUTEX_OP_ANDN:
+		__futex_atomic_op("and	%w0, %w1, %w4",
+				  ret, oldval, uaddr, tmp, ~oparg);
+		break;
+	case FUTEX_OP_XOR:
+		__futex_atomic_op("eor	%w0, %w1, %w4",
+				  ret, oldval, uaddr, tmp, oparg);
+		break;
+	default:
+		ret = -ENOSYS;
+	}
+
+	pagefault_enable();	/* subsumes preempt_enable() */
+
+	if (!ret) {
+		switch (cmp) {
+		case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
+		case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
+		case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
+		case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
+		case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
+		case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
+		default: ret = -ENOSYS;
+		}
+	}
+	return ret;
+}
+
+static inline int
+futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
+			      u32 oldval, u32 newval)
+{
+	int ret = 0;
+	u32 val, tmp;
+
+	if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
+		return -EFAULT;
+
+	asm volatile("// futex_atomic_cmpxchg_inatomic\n"

arch/arm64/include/asm/futex.h line 121

Quoted 10 lines
arch/arm64/include/asm/futex.h new file +10 -0
+"1:	ldaxr	%w1, %2\n"
+"	sub	%w3, %w1, %w4\n"
+"	cbnz	%w3, 3f\n"
+"2:	stlxr	%w3, %w5, %2\n"
+"	cbnz	%w3, 1b\n"
+"3:	.pushsection __ex_table,\"a\"\n"
+"	.align	3\n"
+"	.quad	1b, 4f, 2b, 4f\n"
+"	.popsection\n"
+"	.pushsection .fixup,\"ax\"\n"

Same here w.r.t. exception table location and barrier.

arch/arm64/include/asm/futex.h line 134

Quoted 13 lines
arch/arm64/include/asm/futex.h new file +13 -0
+"4:	mov	%w0, %w6\n"
+"	b	3b\n"
+"	.popsection"
+	: "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp)
+	: "r" (oldval), "r" (newval), "Ir" (-EFAULT)
+	: "cc", "memory");
+
+	*uval = val;
+	return ret;
+}
+
+#endif /* __KERNEL__ */
+#endif /* __ASM_FUTEX_H */

-Olof

#69 lore raw

Re: [PATCH v2 13/31] arm64: Device specific operations

In reply to Catalin Marinas
Quoted 25 lines · Catalin Marinas

This patch adds several definitions for device communication, including I/O accessors and ioremap(). The __raw_* accessors are implemented as inline asm to avoid compiler generation of post-indexed accesses (less efficient to emulate in a virtualised environment).

---
 arch/arm64/include/asm/device.h |   26 ++++
 arch/arm64/include/asm/fb.h     |   34 +++++
 arch/arm64/include/asm/io.h     |  263 +++++++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/io.c          |   64 ++++++++++
 arch/arm64/mm/ioremap.c         |   84 +++++++++++++
 5 files changed, 471 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/device.h
 create mode 100644 arch/arm64/include/asm/fb.h
 create mode 100644 arch/arm64/include/asm/io.h
 create mode 100644 arch/arm64/kernel/io.c
 create mode 100644 arch/arm64/mm/ioremap.c
arch/arm64/include/asm/io.h new file +0 -0
new file mode 100644
index 0000000..48fa83f

[...]

arch/arm64/include/asm/io.h line 122

Quoted 10 lines
arch/arm64/include/asm/io.h new file +10 -0
+/*
+ *  I/O port access primitives.
+ */
+#define IO_SPACE_LIMIT		0xffff
+
+/*
+ * We currently don't have any platform with PCI support, so just leave this
+ * defined to 0 until needed.
+ */
+#define PCI_IOBASE		((void __iomem *)0)

You could just leave out the PCI / I/O code alltogether instead.

Quoted 60 lines
arch/arm64/kernel/io.c new file +54 -0
new file mode 100644
index 0000000..7d37ead
@@ -0,0 +1,64 @@
+/*
+ * Based on arch/arm/kernel/io.c
+ *
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/export.h>
+#include <linux/types.h>
+#include <linux/io.h>
+
+/*
+ * Copy data from IO memory space to "real" memory space.
+ */
+void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
+{
+	unsigned char *t = to;
+	while (count) {
+		count--;
+		*t = readb(from);
+		t++;
+		from++;
+	}
+}
+EXPORT_SYMBOL(__memcpy_fromio);
+
+/*
+ * Copy data from "real" memory space to IO memory space.
+ */
+void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
+{
+	const unsigned char *f = from;
+	while (count) {
+		count--;
+		writeb(*f, to);
+		f++;
+		to++;
+	}
+}
+EXPORT_SYMBOL(__memcpy_toio);
+
+/*
+ * "memset" on IO memory space.

arch/arm64/kernel/io.c line 64

Quoted 10 lines
arch/arm64/kernel/io.c new file +10 -0
+ */
+void __memset_io(volatile void __iomem *dst, int c, size_t count)
+{
+	while (count) {
+		count--;
+		writeb(c, dst);
+		dst++;
+	}
+}
+EXPORT_SYMBOL(__memset_io);

Doing all of the above a byte at a time is horribly inefficient. Feel free to borrow the implementations from arch/powerpc/kernel/io.c instead of from ARM.

-Olof

#77 lore raw

Re: [PATCH v2 14/31] arm64: DMA mapping API

In reply to Catalin Marinas

Hi,

Quoted 46 lines · Catalin Marinas

This patch adds support for the DMA mapping API. It uses dma_map_ops for flexibility and it currently supports swiotlb. This patch could be simplified further if the DMA accesses are coherent (not mandated by the architecture) or if corresponding hooks are placed in the generic swiotlb code to deal with cache maintenance.

---
 arch/arm64/include/asm/dma-mapping.h |  124 ++++++++++++++++++++
 arch/arm64/mm/dma-mapping.c          |  208 ++++++++++++++++++++++++++++++++++
 2 files changed, 332 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm64/include/asm/dma-mapping.h
 create mode 100644 arch/arm64/mm/dma-mapping.c
arch/arm64/include/asm/dma-mapping.h new file +26 -0
new file mode 100644
index 0000000..538f4b4
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_DMA_MAPPING_H
+#define __ASM_DMA_MAPPING_H
+
+#ifdef __KERNEL__
+
+#include <linux/types.h>
+#include <linux/vmalloc.h>
+
+#include <asm-generic/dma-coherent.h>
+
+#define ARCH_HAS_DMA_GET_REQUIRED_MASK

arch/arm64/include/asm/dma-mapping.h line 36

Quoted 10 lines
arch/arm64/include/asm/dma-mapping.h new file +9 -0
+
+extern struct dma_map_ops *dma_ops;
 
+static inline struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	if (unlikely(!dev) || !dev->archdata.dma_ops)
+		return dma_ops;
+	else
+		return dev->archdata.dma_ops;
+}

Does it make sense to add the concept of a global dma ops on arm64, instead of requiring the dma ops pointer per device similar to how some other platforms do it (including powerpc)? For devices that lack archdata.dma_ops, dma_supported() should return 0 (and the other ops should return error).

-Olof

#82 lore raw

Re: [PATCH v2 15/31] arm64: SMP support

In reply to Catalin Marinas

Hi,

Quoted 40 lines · Catalin Marinas

This patch adds SMP initialisation and spinlocks implementation for AArch64. The spinlock support uses the new load-acquire/store-release instructions to avoid explicit barriers. The architecture also specifies that an event is automatically generated when clearing the exclusive monitor state to wake up processors in WFE, so there is no need for an explicit DSB/SEV instruction sequence. The SEVL instruction is used to set the exclusive monitor locally as there is no conditional WFE and a branch is more expensive.

For the SMP booting protocol, see Documentation/arm64/booting.txt.

---

arch/arm64/include/asm/spinlock.h new file +18 -0
new file mode 100644
index 0000000..34a37fb
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SPINLOCK_H
+#define __ASM_SPINLOCK_H
+

arch/arm64/include/asm/spinlock.h line 28

Quoted 10 lines
arch/arm64/include/asm/spinlock.h new file +10 -0
+#include <asm/spinlock_types.h>
+#include <asm/processor.h>
+
+/*
+ * AArch64 Spin-locking.
+ *
+ * We exclusively read the old value.  If it is zero, we may have
+ * won the lock, so we try exclusively storing it.  A memory barrier
+ * is required after we get a lock, and before we release it, because
+ * V6 CPUs are assumed to have weakly ordered memory.

This comment should be updated, to mention the implicit locking and remove the reference to V6?

Also, ignore previous questions on another reply about need for barriers, obviously not needed given the load-acquire/store-release semantics.

-Olof

maintainer
#25 lore raw

Re: [PATCH v2 03/31] arm64: Exception handling

In reply to Catalin Marinas

arch/arm64/include/asm/ptrace.h line 141

Quoted 6 lines · Catalin Marinas
arch/arm64/include/asm/ptrace.h new file +6 -0
+#ifdef CONFIG_AARCH32_EMULATION
+#define compat_thumb_mode(regs) \
+	(((regs)->pstate & COMPAT_PSR_T_BIT))
+#else
+#define compat_thumb_mode(regs) (0)
+#endif

The symbol we use on other platforms is CONFIG_COMPAT. I don't think you need to have a separate CONFIG_AARCH32_EMULATION

arch/arm64/kernel/traps.c line 338

Quoted 8 lines
arch/arm64/kernel/traps.c new file +8 -0
+void __bad_xchg(volatile void *ptr, int size)
+{
+	printk("xchg: bad data size: pc 0x%p, ptr 0x%p, size %d\n",
+		__builtin_return_address(0), ptr, size);
+	BUG();
+}
+EXPORT_SYMBOL(__bad_xchg);
+

I think we're better off not defining this function. My guess is that initially the idea on ARM was that it was meant as a BUILD_BUG_ON replacement, but the someone added this function. And you copied it.

Microblaze has the same declaration, but (correctly) misses the definition, which produces a much more helpful link failure than a run-time BUG(). Using BUILD_BUG_ON would be even better.

Arnd

maintainer Acked-by on v2 15/31
#83 lore raw

Re: [PATCH v2 15/31] arm64: SMP support

In reply to Catalin Marinas
Quoted 9 lines · Catalin Marinas

This patch adds SMP initialisation and spinlocks implementation for AArch64. The spinlock support uses the new load-acquire/store-release instructions to avoid explicit barriers. The architecture also specifies that an event is automatically generated when clearing the exclusive monitor state to wake up processors in WFE, so there is no need for an explicit DSB/SEV instruction sequence. The SEVL instruction is used to set the exclusive monitor locally as there is no conditional WFE and a branch is more expensive.

Quoted 5 lines

For the SMP booting protocol, see Documentation/arm64/booting.txt.

maintainer
#8 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Catalin Marinas

Documentation/arm64/booting.txt line 13

Quoted 4 lines · Catalin Marinas
Documentation/arm64/booting.txt new file +4 -0
+The AArch64 exception model is made up of a number of exception levels
+(EL0 - EL3), with EL0 and EL1 having a secure and a non-secure
+counterpart.  EL2 is the hypervisor level and exists only in non-secure
+mode. EL3 is the highest priority level and exists only in secure mode.

I'm always confused by a description like this. It sounds like you cannot have a hypervisor if you have code running in secure mode in EL3. What I instead understand is that you enter non-secure mode by going from EL3 into EL2.

Documentation/arm64/booting.txt line 51

Quoted 9 lines

+2. Setup the device tree
+-------------------------

Documentation/arm64/booting.txt new file +7 -0
+
+Requirement: MANDATORY
+
+The device tree blob (dtb) must be no bigger than 2 megabytes in size
+and placed at a 2-megabyte boundary within the first 512 megabytes from
+the start of the kernel image. This is to allow the kernel to map the
+blob using a single section mapping in the initial page tables.

I've seen people put firmware for some peripherals into the device tree, so that a device driver can grab a blob from there and load it into the device, rather than calling request_firmware() which would fail if the OS running on the system does not contain the blob. If such firmware is too large, you end up violating the 2 MB limit you impose here.

Should we keep that limit and declare those use cases as invalid, or should we try to make the boot protocol more flexible?

Quoted 6 lines
arch/arm64/include/asm/setup.h new file +0 -0
new file mode 100644
index 0000000..d766493

arch/arm64/include/asm/setup.h line 8

Quoted 8 lines
arch/arm64/include/asm/setup.h new file +8 -0
@@ -0,0 +1,26 @@
+#ifndef __ASM_SETUP_H
+#define __ASM_SETUP_H
+
+#include <linux/types.h>
+
+#define COMMAND_LINE_SIZE 1024
+
+#endif

Is this necessary? The asm-generic version of this file allows 512 bytes, which seems plenty.

arch/arm64/include/asm/setup.h line 13

Quoted 5 lines
arch/arm64/include/asm/setup.h new file +5 -0
+unsigned int processor_id;
+EXPORT_SYMBOL(processor_id);
+
+unsigned int elf_hwcap __read_mostly;
+EXPORT_SYMBOL(elf_hwcap);

EXPORT_SYMBOL_GPL?

Neither of these looks like they should be used in drivers.

Arnd

maintainer
#29 lore raw

Re: [PATCH v2 04/31] arm64: MMU definitions

In reply to Catalin Marinas
Quoted 11 lines · Catalin Marinas
arch/arm64/include/asm/pgtable-hwdef.h new file +10 -0
+/*
+ * TCR flags.
+ */
+#define TCR_TxSZ(x)		(((64 - (x)) << 16) | ((64 - (x)) << 0))
+#define TCR_IRGN_NC		((0 << 8) | (0 << 24))
+#define TCR_IRGN_WBWA		((1 << 8) | (1 << 24))
+#define TCR_IRGN_WT		((2 << 8) | (2 << 24))
+#define TCR_IRGN_WBnWA		((3 << 8) | (3 << 24))
+#define TCR_IRGN_MASK		((3 << 8) | (3 << 24))
+#define TCR_ORGN_NC		((0 << 10) | (0 << 26))

arch/arm64/include/asm/pgtable-hwdef.h line 93

Quoted 10 lines
arch/arm64/include/asm/pgtable-hwdef.h new file +10 -0
+#define TCR_ORGN_WBWA		((1 << 10) | (1 << 26))
+#define TCR_ORGN_WT		((2 << 10) | (2 << 26))
+#define TCR_ORGN_WBnWA		((3 << 10) | (3 << 26))
+#define TCR_ORGN_MASK		((3 << 10) | (3 << 26))
+#define TCR_SHARED		((3 << 12) | (3 << 28))
+#define TCR_TG0_64K		(1 << 14)
+#define TCR_TG1_64K		(1 << 30)
+#define TCR_IPS_40BIT		(2 << 32)
+#define TCR_ASID16		(1 << 36)
+

As a matter of coding style, I would much prefer tables like this to be written as

#define TCR_IRGN_MASK 0x0000000003000300
#define TCR_IRGN_WBnWA 0x0000000003000300
#define TCR_IRGN_WT 0x0000000002000200
#define TCR_IRGN_WBWA 0x0000000001000100
#define TCR_IRGN_NC 0x0000000000000000

#define TCR_ORGN_MASK 0x000000000c000c00
#define TCR_ORGN_WBnWA 0x000000000c000c00
#define TCR_ORGN_WT 0x0000000008000800
#define TCR_ORGN_WBWA 0x0000000004000400
#define TCR_ORGN_NC 0x0000000000000000

The advantage of this is that you can visually compare the bitmasks to a hex dump, and if you are suffering from endian-confused documentation authors, there is no ambiguity about which end of the word is bit zero.

Arnd

author maintainer
#30 lore raw

Re: [PATCH v2 04/31] arm64: MMU definitions

Hi Arnd,

Quoted 37 lines · Arnd Bergmann
Quoted 10 lines · Catalin Marinas
arch/arm64/include/asm/pgtable-hwdef.h new file +10 -0
+/*
+ * TCR flags.
+ */
+#define TCR_TxSZ(x)		(((64 - (x)) << 16) | ((64 - (x)) << 0))
+#define TCR_IRGN_NC		((0 << 8) | (0 << 24))
+#define TCR_IRGN_WBWA		((1 << 8) | (1 << 24))
+#define TCR_IRGN_WT		((2 << 8) | (2 << 24))
+#define TCR_IRGN_WBnWA		((3 << 8) | (3 << 24))
+#define TCR_IRGN_MASK		((3 << 8) | (3 << 24))
+#define TCR_ORGN_NC		((0 << 10) | (0 << 26))

arch/arm64/include/asm/pgtable-hwdef.h line 93

Quoted 10 lines
arch/arm64/include/asm/pgtable-hwdef.h new file +10 -0
+#define TCR_ORGN_WBWA		((1 << 10) | (1 << 26))
+#define TCR_ORGN_WT		((2 << 10) | (2 << 26))
+#define TCR_ORGN_WBnWA		((3 << 10) | (3 << 26))
+#define TCR_ORGN_MASK		((3 << 10) | (3 << 26))
+#define TCR_SHARED		((3 << 12) | (3 << 28))
+#define TCR_TG0_64K		(1 << 14)
+#define TCR_TG1_64K		(1 << 30)
+#define TCR_IPS_40BIT		(2 << 32)
+#define TCR_ASID16		(1 << 36)
+

As a matter of coding style, I would much prefer tables like this to be written as

#define TCR_IRGN_MASK 0x0000000003000300
#define TCR_IRGN_WBnWA 0x0000000003000300
#define TCR_IRGN_WT 0x0000000002000200
#define TCR_IRGN_WBWA 0x0000000001000100
#define TCR_IRGN_NC 0x0000000000000000

#define TCR_ORGN_MASK 0x000000000c000c00
#define TCR_ORGN_WBnWA 0x000000000c000c00
#define TCR_ORGN_WT 0x0000000008000800
#define TCR_ORGN_WBWA 0x0000000004000400
#define TCR_ORGN_NC 0x0000000000000000

Quoted 3 lines

The advantage of this is that you can visually compare the bitmasks to a hex dump, and if you are suffering from endian-confused documentation authors, there is no ambiguity about which end of the word is bit zero.

That depends on the case, in some places it's more readable like this. In the above case, I find it easier to compare against the documentation which, for example, has groups of 2 bits at position 8 and 24 or 10 and 26 (for TTBR0 and TTBR1). The meaning of a group of 2 bits is described separately as 0b00 (NC), 0b01(WBWA) etc. Same goes for the shareability bits (12 and 28).

So I think at least for code writing it's less error-prone to write the explicit bit position than a magic long hex.

Signature · 1 line
Catalin
maintainer Acked-by on v2 5/31
#37 lore raw

Re: [PATCH v2 05/31] arm64: MMU initialisation

In reply to Catalin Marinas
Quoted 6 lines · Catalin Marinas

This patch contains the initialisation of the memory blocks, MMU attributes and the memory map. Only five memory types are defined:
Device nGnRnE (equivalent to Strongly Ordered), Device nGnRE (classic Device memory), Device GRE, Normal Non-cacheable and Normal Cacheable. Cache policies are supported via the memory attributes register (MAIR_EL1) and only affect the Normal Cacheable mappings.

It looks like you've managed to eliminate bootmem as I suggested earlier, very nice!

Arnd

maintainer
#42 lore raw

Re: [PATCH v2 06/31] arm64: MMU fault handling and page table management

In reply to Catalin Marinas
Quoted 8 lines · Catalin Marinas
arch/arm64/mm/pgd.c new file +8 -0
+
+pgd_t *pgd_alloc(struct mm_struct *mm)
+{
+	pgd_t *new_pgd;
+
+	new_pgd = (pgd_t *)__get_free_pages(GFP_KERNEL, PGD_ORDER);
+	if (!new_pgd)
+		return NULL;

arch/arm64/mm/pgd.c line 49

Quoted 10 lines
arch/arm64/mm/pgd.c new file +10 -0
+
+	memset(new_pgd, 0, PAGE_SIZE << PGD_ORDER);
+
+	return new_pgd;
+}
+
+void pgd_free(struct mm_struct *mm, pgd_t *pgd)
+{
+	free_pages((unsigned long)pgd, PGD_ORDER);
+}

According to the documentation, you should only need 8kb for the pgd on a 64kb page system. Is it required that you use up a full page here?

Arnd

maintainer
#48 lore raw

Re: [PATCH v2 07/31] arm64: Process management

In reply to Catalin Marinas

arch/arm64/include/asm/thread_info.h line 28

Quoted 3 lines · Catalin Marinas
arch/arm64/include/asm/thread_info.h new file +3 -0
+#define THREAD_SIZE_ORDER	1
+#define THREAD_SIZE		8192
+#define THREAD_START_SP		(THREAD_SIZE - 16)

THREAD_SIZE_ORDER looks wrong for 64kb-page kernels. It also doesn't seem to be used, so better remove it.

Arnd

maintainer
#57 lore raw

Re: [PATCH v2 08/31] arm64: CPU support

In reply to Catalin Marinas
Quoted 40 lines · Catalin Marinas
arch/arm64/include/asm/procinfo.h new file +34 -0
new file mode 100644
index 0000000..81fece9
@@ -0,0 +1,44 @@
+/*
+ * Based on arch/arm/include/asm/procinfo.h
+ *
+ * Copyright (C) 1996-1999 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_PROCINFO_H
+#define __ASM_PROCINFO_H
+
+#ifdef __KERNEL__
+
+/*
+ * Note!  struct processor is always defined if we're
+ * using MULTI_CPU, otherwise this entry is unused,
+ * but still exists.
+ *
+ * NOTE! The following structure is defined by assembly
+ * language, NOT C code.  For more information, check:
+ *  arch/arm/mm/proc-*.S and arch/arm/kernel/head.S
+ */
+struct proc_info_list {
+	unsigned int		cpu_val;

arch/arm64/include/asm/procinfo.h line 44

Quoted 10 lines
arch/arm64/include/asm/procinfo.h new file +10 -0
+	unsigned int		cpu_mask;
+	unsigned long		__cpu_flush;		/* used by head.S */
+	const char		*cpu_name;
+};
+
+#else	/* __KERNEL__ */
+#include <asm/elf.h>
+#warning "Please include asm/elf.h instead"
+#endif	/* __KERNEL__ */
+#endif

I think you forgot to remove this file when you removed MULTI_CPU.

Arnd

maintainer
#88 lore raw

Re: [PATCH v2 16/31] arm64: ELF definitions

In reply to Catalin Marinas
Quoted 9 lines · Catalin Marinas
arch/arm64/kernel/elf.c new file +9 -0
+
+void elf_set_personality(int personality)
+{
+       switch (personality & PER_MASK) {
+       case PER_LINUX:
+               clear_thread_flag(TIF_32BIT);
+               break;
+       case PER_LINUX32:
+               set_thread_flag(TIF_32BIT);

arch/arm64/kernel/elf.c line 41

Quoted 10 lines
arch/arm64/kernel/elf.c new file +10 -0
+               break;
+       default:
+               pr_warning("Process %s tried to assume unknown personality %d\n",
+                          current->comm, personality);
+               return;
+       }
+
+       current->personality = personality;
+}
+EXPORT_SYMBOL(elf_set_personality);

This looks wrong: PER_LINUX/PER_LINUX32 decides over the output of the uname system call, while TIF_32BIT decides over the instruction set when returning to user space. You definitely should not set the personality to the value you pass from the elf loader. Instead, just do

#define SET_PERSONALITY(ex) clear_thread_flag(TIF_32BIT); #defined COMPAT_SET_PERSONALITY(ex) set_thread_flag(TIF_32BIT);

I also don't see a reason to export this. You'd have trouble loading the elf interpreter module from user space without the elf interpreter.

Arnd

maintainer
#98 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

In reply to Catalin Marinas
Quoted 26 lines · Catalin Marinas
arch/arm64/include/asm/stat.h new file +26 -0
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ * Note: The kernel zero's the padded region because glibc might read them
+ * in the hope that the kernel has stretched to using larger sizes.
+ */
+struct stat64 {
+	compat_u64	st_dev;
+	unsigned char   __pad0[4];
+
+#define STAT64_HAS_BROKEN_ST_INO	1
+	compat_ulong_t	__st_ino;
+	compat_uint_t	st_mode;
+	compat_uint_t	st_nlink;
+
+	compat_ulong_t	st_uid;
+	compat_ulong_t	st_gid;
+
+	compat_u64	st_rdev;
+	unsigned char   __pad3[4];
+
+	compat_s64	st_size;
+	compat_ulong_t	st_blksize;
+	compat_u64	st_blocks;	/* Number 512-byte blocks allocated. */
+
+	compat_ulong_t	st_atime;

arch/arm64/include/asm/stat.h line 59

Quoted 10 lines
arch/arm64/include/asm/stat.h new file +10 -0
+	compat_ulong_t	st_atime_nsec;
+
+	compat_ulong_t	st_mtime;
+	compat_ulong_t	st_mtime_nsec;
+
+	compat_ulong_t	st_ctime;
+	compat_ulong_t	st_ctime_nsec;
+
+	compat_u64	st_ino;
+};

The comment above struct stat64 is completely irrelevant here. I would instead explain why you need your own stat64 in the first place.

Quoted 32 lines
arch/arm64/kernel/sys.c new file +32 -0
+int kernel_execve(const char *filename,
+		  const char *const argv[],
+		  const char *const envp[])
+{
+	struct pt_regs regs;
+	int ret;
+
+	memset(&regs, 0, sizeof(struct pt_regs));
+	ret = do_execve(filename,
+			(const char __user *const __user *)argv,
+			(const char __user *const __user *)envp, &regs);
+	if (ret < 0)
+		goto out;
+
+	/*
+	 * Save argc to the register structure for userspace.
+	 */
+	regs.regs[0] = ret;
+
+	/*
+	 * We were successful.  We won't be returning to our caller, but
+	 * instead to user space by manipulating the kernel stack.
+	 */
+	asm(	"add	x0, %0, %1\n\t"
+		"mov	x1, %2\n\t"
+		"mov	x2, %3\n\t"
+		"bl	memmove\n\t"	/* copy regs to top of stack */
+		"mov	x27, #0\n\t"	/* not a syscall */
+		"mov	x28, %0\n\t"	/* thread structure */
+		"mov	sp, x0\n\t"	/* reposition stack pointer */
+		"b	ret_to_user"
+		:

arch/arm64/kernel/sys.c line 106

Quoted 10 lines
arch/arm64/kernel/sys.c new file +10 -0
+		: "r" (current_thread_info()),
+		  "Ir" (THREAD_START_SP - sizeof(regs)),
+		  "r" (&regs),
+		  "Ir" (sizeof(regs))
+		: "x0", "x1", "x2", "x27", "x28", "x30", "memory");
+
+ out:
+	return ret;
+}
+EXPORT_SYMBOL(kernel_execve);

Al Viro was recently talking about a generic implementation of execve. I can't find that now, but I think you should use that.

Quoted 8 lines
arch/arm64/kernel/sys.c new file +8 -0
+
+asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
+			 unsigned long prot, unsigned long flags,
+			 unsigned long fd, off_t off)
+{
+	if (offset_in_page(off) != 0)
+		return -EINVAL;
+

arch/arm64/kernel/sys.c line 124

Quoted 10 lines
arch/arm64/kernel/sys.c new file +10 -0
+	return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+}
+
+/*
+ * Wrappers to pass the pt_regs argument.
+ */
+#define sys_execve		sys_execve_wrapper
+#define sys_clone		sys_clone_wrapper
+#define sys_rt_sigreturn	sys_rt_sigreturn_wrapper
+#define sys_sigaltstack		sys_sigaltstack_wrapper

I think

#define sys_mmap sys_mmap_pgoff

would be more appropriate than defining your own sys_mmap function here. We should probably make that the default in asm-generic/unistd.h and change the architectures that have their own implementation to override it.

Arnd

maintainer
#118 lore raw

Re: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

In reply to Catalin Marinas
Quoted 10 lines · Catalin Marinas
arch/arm64/include/asm/signal32.h new file +10 -0
+#ifdef CONFIG_AARCH32_EMULATION
+#include <linux/compat.h>
+
+#define AARCH32_KERN_SIGRET_CODE_OFFSET	0x500
+
+extern const compat_ulong_t aarch32_sigret_code[6];
+
+int compat_setup_frame(int usig, struct k_sigaction *ka, sigset_t *set,
+		       struct pt_regs *regs);
+int compat_setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,

arch/arm64/include/asm/signal32.h line 39

Quoted 10 lines
arch/arm64/include/asm/signal32.h new file +10 -0
+			  sigset_t *set, struct pt_regs *regs);
+
+void compat_setup_restart_syscall(struct pt_regs *regs);
+#else
+
+static inline int compat_setup_frame(int usid, struct k_sigaction *ka,
+				     sigset_t *set, struct pt_regs *regs)
+{
+	BUG();
+}

What good is the run-time BUG() here? Nothing should be calling these when CONFIG_COMPAT is disabled, so I think you should just remove the #ifdef around the declarations, and the entire #else case.

Quoted 24 lines
arch/arm64/kernel/sys_compat.c new file +24 -0
+asmlinkage int compat_sys_sched_rr_get_interval(compat_pid_t pid,
+						struct compat_timespec __user *interval)
+{
+	struct timespec t;
+	int ret;
+	mm_segment_t old_fs = get_fs();
+
+	set_fs(KERNEL_DS);
+	ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
+	set_fs(old_fs);
+	if (put_compat_timespec(&t, interval))
+		return -EFAULT;
+	return ret;
+}
+
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+				   compat_off_t __user *offset, s32 count)
+{
+	mm_segment_t old_fs = get_fs();
+	int ret;
+	off_t of;
+
+	if (offset && get_user(of, offset))
+		return -EFAULT;

arch/arm64/kernel/sys_compat.c line 118

Quoted 10 lines
arch/arm64/kernel/sys_compat.c new file +10 -0
+
+	set_fs(KERNEL_DS);
+	ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
+			   count);
+	set_fs(old_fs);
+
+	if (offset && put_user(of, offset))
+		return -EFAULT;
+	return ret;
+}

I guess it's time to move these two into common code. They look like they should be shared across most architectures that have compat support.

arch/arm64/kernel/sys_compat.c line 98

Quoted 12 lines
arch/arm64/kernel/sys_compat.c new file +12 -0
+asmlinkage int compat_sys_personality(compat_ulong_t personality)
+{
+	int ret;
+
+	if (personality(current->personality) == PER_LINUX32 &&
+		personality == PER_LINUX)
+		personality = PER_LINUX32;
+	ret = sys_personality(personality);
+	if (ret == PER_LINUX32)
+		ret = PER_LINUX;
+	return ret;
+}

Where did you get this from?

You should not need compat_sys_personality, just call the native function.

Arnd

maintainer Acked-by on v2 22/31
#130 lore raw

Re: [PATCH v2 22/31] arm64: Floating point and SIMD

In reply to Catalin Marinas
Quoted 8 lines · Catalin Marinas

This patch adds support for FP/ASIMD register bank saving and restoring during context switch and FP exception handling to generate SIGFPE. There are 32 128-bit registers and the context switching is currently done non-lazily. Benchmarks on real hardware are required before implementing lazy FP state saving/restoring.

maintainer
#111 lore raw

Re: [PATCH v2 20/31] arm64: User access library function

In reply to Catalin Marinas
Quoted 37 lines · Catalin Marinas
arch/arm64/include/asm/uaccess.h new file +37 -0
+/*
+ * Single-value transfer routines.  They automatically use the right
+ * size if we just have the right pointer type.  Note that the functions
+ * which read from user space (*get_*) need to take care not to leak
+ * kernel data even if the calling code is buggy and fails to check
+ * the return value.  This means zeroing out the destination variable
+ * or buffer on error.  Normally this is done out of line by the
+ * fixup code, but there are a few places where it intrudes on the
+ * main code path.  When we only write to user space, there is no
+ * problem.
+ */
+extern long __get_user_1(void *);
+extern long __get_user_2(void *);
+extern long __get_user_4(void *);
+extern long __get_user_8(void *);
+
+#define __get_user_x(__r2,__p,__e,__s,__i...)				\
+	   asm volatile(						\
+		__asmeq("%0", "x0") __asmeq("%1", "x2")			\
+		"bl	__get_user_" #__s				\
+		: "=&r" (__e), "=r" (__r2)				\
+		: "0" (__p)						\
+		: __i, "cc")
+
+#define get_user(x,p)							\
+	({								\
+		register const typeof(*(p)) __user *__p asm("x0") = (p);\
+		register unsigned long __r2 asm("x2");			\
+		register long __e asm("x0");				\
+		switch (sizeof(*(__p))) {				\
+		case 1:							\
+			__get_user_x(__r2, __p, __e, 1, "x30");		\
+			break;						\
+		case 2:							\
+			__get_user_x(__r2, __p, __e, 2, "x3", "x30");	\
+			break;						\
+		case 4:							\

arch/arm64/include/asm/uaccess.h line 155

Quoted 10 lines
arch/arm64/include/asm/uaccess.h new file +10 -0
+			__get_user_x(__r2, __p, __e, 4, "x30");		\
+			break;						\
+		case 8:							\
+			__get_user_x(__r2, __p, __e, 8, "x30");		\
+			break;						\
+		default: __e = __get_user_bad(); break;			\
+		}							\
+		x = (typeof(*(p))) __r2;				\
+		__e;							\
+	})

It's fairly unusual to have out of line get_user/put_user functions. What is the reason for this, other than copying from ARM?

arch/arm64/lib/getuser.S line 69

Quoted 12 lines
arch/arm64/lib/getuser.S new file +11 -0
+
+__get_user_bad:
+	mov	x2, #0
+	mov	x0, #-EFAULT
+	ret
+ENDPROC(__get_user_bad)
 
+__put_user_bad:
+	mov	x0, #-EFAULT
+	ret
+ENDPROC(__put_user_bad)
+

The purpose of these symbols is to provoke a link error when you pass the wrong data into get_user/put_user. Actually defining them completely breaks this logic, so you should remove these!

Arnd

maintainer
#132 lore raw

Re: [PATCH v2 23/31] arm64: Debugging support

In reply to Catalin Marinas

arch/arm64/kernel/ptrace.c line 572

Quoted 8 lines · Catalin Marinas
arch/arm64/kernel/ptrace.c new file +8 -0
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+#ifdef CONFIG_AARCH32_EMULATION
+	if (test_tsk_thread_flag(task, TIF_32BIT))
+		return &user_aarch32_view;
+#endif
+	return &user_aarch64_view;
+}

Ah, nice. So you support 64 bit debuggers debugging 32 bit processes, right?

Quoted 1 line

From what I can tell, there is no support for 32 bit processes debugging

64 bit ones. Is that something you plan to add in the future, or do you consider that out of scope? In either case, a comment would be helpful.

Quoted 18 lines
arch/arm64/kernel/ptrace.c new file +18 -0
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
+{
+	int ret;
+	unsigned long *datap = (unsigned long __user *)data;
+
+	switch (request) {
+		case PTRACE_GET_THREAD_AREA:
+			ret = put_user(child->thread.tp_value, datap);
+			break;
+
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+		case PTRACE_GETHBPREGS:
+			ret = ptrace_gethbpregs(child, addr, datap);
+			break;
+
+		case PTRACE_SETHBPREGS:
+			ret = ptrace_sethbpregs(child, addr, datap);

arch/arm64/kernel/ptrace.c line 601

Quoted 10 lines
arch/arm64/kernel/ptrace.c new file +10 -0
+			break;
+#endif
+
+		default:
+			ret = ptrace_request(child, request, addr, data);
+			break;
+	}
+
+	return ret;
+}

Is there a reaons why these are not regsets but have their own ptrace commands? I believe new architectures should generally not add ptrace commands any more.

Arnd

maintainer Acked-by on v2 24/31
#141 lore raw

Re: [PATCH v2 24/31] arm64: Add support for /proc/sys/debug/exception-trace

In reply to Catalin Marinas
Quoted 7 lines · Catalin Marinas

This patch allows setting of the show_unhandled_signals variable via /proc/sys/debug/exception-trace. The default value is currently 1 showing unhandled user faults (undefined instructions, data aborts) and invalid signal stack frames.

maintainer
#143 lore raw

Re: [PATCH v2 25/31] arm64: Performance counters support

In reply to Catalin Marinas
Quoted 11 lines · Catalin Marinas

From: Will Deacon <[email protected]>

This patch adds support for the AArch64 performance counters.

---
 arch/arm64/include/asm/perf_event.h |   22 +
 arch/arm64/include/asm/pmu.h        |   82 +++
 arch/arm64/kernel/perf_event.c      | 1368 +++++++++++++++++++++++++++++++++++
 tools/perf/perf.h                   |    6 +

Can you explain how AArch64 performance counters differ from the 32 bit ones? Do they work for AArch32 user space under AArch64 kernels? Is it possible to share parts of the implementation with arch/arm?

Arnd

maintainer
#146 lore raw

Re: [PATCH v2 26/31] arm64: Miscellaneous library functions

In reply to Catalin Marinas
Quoted 13 lines · Catalin Marinas
arch/arm64/include/asm/bitops.h new file +13 -0
+
+/*
+ * Use compiler builtins for simple inline operations.
+ */
+static inline unsigned long __ffs(unsigned long word)
+{
+	return __builtin_ffsl(word) - 1;
+}
+
+static inline int ffs(int x)
+{
+	return __builtin_ffs(x);
+}

arch/arm64/include/asm/bitops.h line 52

Quoted 10 lines
arch/arm64/include/asm/bitops.h new file +10 -0
+
+static inline unsigned long __fls(unsigned long word)
+{
+	return BITS_PER_LONG - 1 - __builtin_clzl(word);
+}
+
+static inline int fls(int x)
+{
+	return x ? sizeof(x) * BITS_PER_BYTE - __builtin_clz(x) : 0;
+}

These are all great, but I think whether to use them or not should depend on the compiler version rather than the architecture in general. Do we know a minimum gcc version that supports all of the above? Then we could put that code into the generic files.

If that's not possible, we could still make the implementation available for other architectures by moving it to

asm-generic/bitops/builtin-__ffs.h
asm-generic/bitops/builtin-ffs.h
asm-generic/bitops/builtin-__fls.h
asm-generic/bitops/builtin-fls.h

Quoted 18 lines
arch/arm64/lib/bitops.c new file +15 -0
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 ARM Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */

arch/arm64/lib/bitops.c line 25

Quoted 10 lines
arch/arm64/lib/bitops.c new file +10 -0
+
+#include <linux/kernel.h>
+#include <linux/spinlock.h>
+#include <linux/atomic.h>
+
+#ifdef CONFIG_SMP
+arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = {
+       [0 ... (ATOMIC_HASH_SIZE-1)]  = __ARCH_SPIN_LOCK_UNLOCKED
+};
+#endif

What?

I suppose this is a leftover from an earlier version using the generic bitops, right?

Arnd

maintainer
#151 lore raw

Re: [PATCH v2 27/31] arm64: Loadable modules

In reply to Catalin Marinas

arch/arm64/kernel/module.c line 35

Quoted 8 lines · Catalin Marinas
arch/arm64/kernel/module.c new file +8 -0
+
+void *module_alloc(unsigned long size)
+{
+       return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
+                                   GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
+                                   __builtin_return_address(0));
+}
+

What is the reason for using a separate virtual address range for the modules instead of falling back to the default module_alloc function that uses vmalloc_exec()?

Arnd

author maintainer
#152 lore raw

Re: [PATCH v2 27/31] arm64: Loadable modules

Quoted 13 lines · Arnd Bergmann

arch/arm64/kernel/module.c line 35

Quoted 8 lines · Catalin Marinas
arch/arm64/kernel/module.c new file +8 -0
+
+void *module_alloc(unsigned long size)
+{
+       return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
+                                   GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
+                                   __builtin_return_address(0));
+}
+

What is the reason for using a separate virtual address range for the modules instead of falling back to the default module_alloc function that uses vmalloc_exec()?

Primarily branch relocation, we have a limitation to 128MB branch range. The alternative would be to always compile the modules with a large memory model but we may lose some performance and could make the relocation handling even harder. What we do now is pretty much similar to static linking but at module load time.

Signature · 1 line
Catalin
maintainer
#155 lore raw

Re: [PATCH v2 28/31] arm64: Generic timers support

In reply to Catalin Marinas
Quoted 26 lines · Catalin Marinas
drivers/clocksource/arm_generic.c new file +26 -0
+static void arch_timer_reg_write(int reg, u32 val)
+{
+       switch (reg) {
+       case ARCH_TIMER_REG_CTRL:
+               asm volatile("msr cntp_ctl_el0,  %0" : : "r" (val));
+               break;
+       case ARCH_TIMER_REG_TVAL:
+               asm volatile("msr cntp_tval_el0, %0" : : "r" (val));
+               break;
+       default:
+               BUG();
+       }
+
+       isb();
+}
+
+static u32 arch_timer_reg_read(int reg)
+{
+       u32 val;
+
+       switch (reg) {
+       case ARCH_TIMER_REG_CTRL:
+               asm volatile("mrs %0,  cntp_ctl_el0" : "=r" (val));
+               break;
+       case ARCH_TIMER_REG_FREQ:
+               asm volatile("mrs %0,   cntfrq_el0" : "=r" (val));

drivers/clocksource/arm_generic.c line 85

Quoted 10 lines
drivers/clocksource/arm_generic.c new file +10 -0
+               break;
+       case ARCH_TIMER_REG_TVAL:
+               asm volatile("mrs %0, cntp_tval_el0" : "=r" (val));
+               break;
+       default:
+               BUG();
+       }
+
+       return val;
+}

Are the inline assemblies the only things in this driver that are specific to AArch64?
Are you planning to use the same file for 32 bit ARM as well, e.g. when running a 32 bit guest kernel on a 64 bit host?

Arnd

maintainer
#161 lore raw

Re: [PATCH v2 29/31] arm64: Miscellaneous header files

In reply to Catalin Marinas

arch/arm64/include/asm/cmpxchg.h line 151

Quoted 10 lines · Catalin Marinas
arch/arm64/include/asm/cmpxchg.h new file +4 -0
new file mode 100644
index 0000000..dc50de7
 
+	default:
+		__bad_cmpxchg(ptr, size);
+		oldval = 0;
+	}

I did not see a definition for __bad_cmpxchg but I may have missed that. Please make sure that none exists, or just use BUILD_BUG_ON().

Arnd

maintainer
#164 lore raw

Re: [PATCH v2 30/31] arm64: Build infrastructure

In reply to Catalin Marinas
Quoted 6 lines · Catalin Marinas
arch/arm64/Kconfig new file +0 -0
new file mode 100644
index 0000000..1ce3d04

arch/arm64/Kconfig line 9

Quoted 9 lines
arch/arm64/Kconfig new file +9 -0
@@ -0,0 +1,261 @@
+config ARM64
+	def_bool y
+	select OF
+	select OF_EARLY_FLATTREE
+	select IRQ_DOMAIN
+	select HAVE_AOUT
+	select HAVE_DMA_ATTRS
+	select HAVE_DMA_API_DEBUG
+	select HAVE_IDE

Please remove HAVE_AOUT and HAVE_IDE

arch/arm64/Kconfig line 12

Quoted 3 lines
arch/arm64/Kconfig new file +3 -0
+	select HAVE_MEMBLOCK
+	select RTC_LIB
+	select SYS_SUPPORTS_APM_EMULATION

APM_EMULATION can probably go too

arch/arm64/Kconfig line 37

Quoted 6 lines
arch/arm64/Kconfig new file +6 -0
+
+config ARCH_PHYS_ADDR_T_64BIT
+	def_bool y
+
+config HAVE_PWM
+	bool

HAVE_PWM is going away soon.

Quoted 5 lines
arch/arm64/Kconfig new file +5 -0
+config AARCH32_EMULATION
+	bool "Kernel support for 32-bit EL0"
+	depends on !ARM64_64K_PAGES
+	select COMPAT_BINFMT_ELF
+	help

arch/arm64/Kconfig line 241

Quoted 10 lines
arch/arm64/Kconfig new file +10 -0
+	  This option enables support for a 32-bit EL0 running under a 64-bit
+	  kernel at EL1. AArch32-specific components such as system calls,
+	  the user helper functions, VFP support and the ptrace interface are
+	  handled appropriately by the kernel.
+
+	  If you want to execute 32-bit userspace applications, say Y.
+
+config COMPAT
+	def_bool y
+	depends on AARCH32_EMULATION

As mentioned, you can just merge the two into CONFIG_COMPAT.

arch/arm64/Kconfig line 42

Quoted 9 lines
arch/arm64/Kconfig new file +9 -0
+targets := Image Image.gz
+
+$(obj)/Image: vmlinux FORCE
+	$(call if_changed,objcopy)
+	@echo '  Kernel: $@ is ready'
+
+$(obj)/Image.gz: $(obj)/Image FORCE
+	$(call if_changed,gzip)
+	@echo '  Kernel: $@ is ready'

Drop the useless output, at least when building with make -s.

arch/arm64/Kconfig line 47

Quoted 5 lines
arch/arm64/Kconfig new file +5 -0
+if [ -x /sbin/loadmap ]; then
+  /sbin/loadmap
+else
+  echo "You have to install it yourself"
+fi

What is loadmap?

arch/arm64/configs/generic_defconfig

Quoted 5 lines
arch/arm64/configs/generic_defconfig new file +0 -0
new file mode 100644
index 0000000..d9aac95

I think it can just be called "defconfig".

arch/arm64/mm/Kconfig line 5

Quoted 11 lines
arch/arm64/mm/Kconfig new file +5 -0
new file mode 100644
index 0000000..8e94e52
@@ -0,0 +1,5 @@
+config MMU
+	def_bool y
+
+config CPU_64
+	def_bool y

This file can be dropped. You can unconditionally enable CONFIG_MMU, and the CPU_64 symbol is pointless, just use CONFIG_64BIT.

Arnd

maintainer Acked-by on v2 13/31
#74 lore raw

Re: [PATCH v2 13/31] arm64: Device specific operations

In reply to Catalin Marinas
Quoted 8 lines · Catalin Marinas

This patch adds several definitions for device communication, including I/O accessors and ioremap(). The __raw_* accessors are implemented as inline asm to avoid compiler generation of post-indexed accesses (less efficient to emulate in a virtualised environment).

maintainer
#79 lore raw

Re: [PATCH v2 14/31] arm64: DMA mapping API

In reply to Catalin Marinas
Quoted 12 lines · Catalin Marinas
arch/arm64/mm/dma-mapping.c new file +12 -0
+static struct dma_map_ops arm64_swiotlb_dma_ops = {
+       .alloc = arm64_swiotlb_alloc_coherent,
+       .free = arm64_swiotlb_free_coherent,
+       .map_page = arm64_swiotlb_map_page,
+       .unmap_page = arm64_swiotlb_unmap_page,
+       .map_sg = arm64_swiotlb_map_sg_attrs,
+       .unmap_sg = arm64_swiotlb_unmap_sg_attrs,
+       .sync_single_for_cpu = arm64_swiotlb_sync_single_for_cpu,
+       .sync_single_for_device = arm64_swiotlb_sync_single_for_device,
+       .sync_sg_for_cpu = arm64_swiotlb_sync_sg_for_cpu,
+       .sync_sg_for_device = arm64_swiotlb_sync_sg_for_device,
+       .dma_supported = swiotlb_dma_supported,

arch/arm64/mm/dma-mapping.c line 199

Quoted 10 lines
arch/arm64/mm/dma-mapping.c new file +10 -0
+       .mapping_error = swiotlb_dma_mapping_error,
+};
+
+void __init swiotlb_init_with_default_size(size_t default_size, int verbose);
+
+void __init arm64_swiotlb_init(size_t max_size)
+{
+       dma_ops = &arm64_swiotlb_dma_ops;
+       swiotlb_init_with_default_size(min((size_t)SZ_64M, max_size), 1);
+}

Why is swiotlb the default? I would expect that most devices can in fact use the entire 64 bit address space, so you can use a simple linear implementation for those.

Arnd

maintainer
#153 lore raw

Re: [PATCH v2 27/31] arm64: Loadable modules

In reply to Catalin Marinas
Quoted 5 lines · Catalin Marinas

Primarily branch relocation, we have a limitation to 128MB branch range. The alternative would be to always compile the modules with a large memory model but we may lose some performance and could make the relocation handling even harder. What we do now is pretty much similar to static linking but at module load time.

Ok, makes sense.

Arnd

#31 lore raw

Re: [PATCH v2 04/31] arm64: MMU definitions

In reply to Arnd Bergmann
Quoted 1 line · Arnd Bergmann
Quoted 1 line

+#define TCR_IPS_40BIT (2 << 32)

By default, constants are int, i.e. 32-bit. So you must write

2ULL << 32

Quoted 1 line
Quoted 1 line

+#define TCR_ASID16 (1 << 36)

1ULL

Quoted 4 lines

As a matter of coding style, I would much prefer tables like this to be written as

#define TCR_IRGN_MASK 0x0000000003000300

0x0000000003000300ULL, to be safe

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#32 lore raw

Re: [PATCH v2 04/31] arm64: MMU definitions

Quoted 10 lines · Geert Uytterhoeven
Quoted 1 line · Arnd Bergmann
Quoted 1 line

+#define TCR_IPS_40BIT (2 << 32)

By default, constants are int, i.e. 32-bit. So you must write

2ULL << 32

Quoted 1 line
Quoted 1 line

+#define TCR_ASID16 (1 << 36)

1ULL

Those higher constants are only used in assembly currently, so no side-effects. But I agree that I should use something like:

	(_AC(1, UL) << 36)

(UL is sufficient on a 64-bit system)

Thanks.

Signature · 1 line
Catalin
#9 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Arnd Bergmann
Quoted 40 lines · Arnd Bergmann

Documentation/arm64/booting.txt line 13

Quoted 4 lines · Catalin Marinas
Documentation/arm64/booting.txt new file +4 -0
+The AArch64 exception model is made up of a number of exception levels
+(EL0 - EL3), with EL0 and EL1 having a secure and a non-secure
+counterpart.  EL2 is the hypervisor level and exists only in non-secure
+mode. EL3 is the highest priority level and exists only in secure mode.

I'm always confused by a description like this. It sounds like you cannot have a hypervisor if you have code running in secure mode in EL3. What I instead understand is that you enter non-secure mode by going from EL3 into EL2.

Documentation/arm64/booting.txt line 51

Quoted 9 lines

+2. Setup the device tree
+-------------------------

Documentation/arm64/booting.txt new file +7 -0
+
+Requirement: MANDATORY
+
+The device tree blob (dtb) must be no bigger than 2 megabytes in size
+and placed at a 2-megabyte boundary within the first 512 megabytes from
+the start of the kernel image. This is to allow the kernel to map the
+blob using a single section mapping in the initial page tables.

I've seen people put firmware for some peripherals into the device tree, so that a device driver can grab a blob from there and load it into the device, rather than calling request_firmware() which would fail if the OS running on the system does not contain the blob. If such firmware is too large, you end up violating the 2 MB limit you impose here.

Should we keep that limit and declare those use cases as invalid, or should we try to make the boot protocol more flexible?

Quoted 9 lines
arch/arm64/include/asm/setup.h new file +3 -0
new file mode 100644
index 0000000..d766493
@@ -0,0 +1,26 @@
+#ifndef __ASM_SETUP_H
+#define __ASM_SETUP_H
+
Quoted 8 lines

arch/arm64/include/asm/setup.h line 26

Quoted 5 lines
arch/arm64/include/asm/setup.h new file +5 -0
+#include <linux/types.h>
+
+#define COMMAND_LINE_SIZE 1024
+
+#endif

Is this necessary? The asm-generic version of this file allows 512 bytes, which seems plenty.

Chrome OS on my system today uses a 553 character cmdline, in particular because some of the device mapper arguments are in there (since we boot without ramdisk). It adds up quickly.

I suggest keeping it common with x86 since those limits are what people will be used to (2048).

-Olof

author maintainer
#5 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Olof Johansson

Hi Olof,

Quoted 34 lines · Olof Johansson
Quoted 33 lines · Catalin Marinas
Documentation/arm64/booting.txt new file +33 -0
+Before jumping into the kernel, the following conditions must be met:
+
+- Quiesce all DMA capable devices so that memory does not get
+  corrupted by bogus network packets or disk data.  This will save
+  you many hours of debug.
+
+- Primary CPU general-purpose register settings
+  x0 = physical address of device tree blob (dtb) in system RAM.
+
+- CPU mode
+  All forms of interrupts must be masked in PSTATE.DAIF (Debug, SError,
+  IRQ and FIQ).
+  The CPU must be in either EL2 (RECOMMENDED in order to have access to
+  the virtualisation extensions) or non-secure EL1.
+
+- Caches, MMUs
+  The MMU must be off.
+  Instruction cache may be on or off.
+  Data cache must be off and invalidated.
+
+- Architected timers
+  CNTFRQ must be programmed with the timer frequency.
+  If entering the kernel at EL1, CNTHCTL_EL2 must have EL1PCTEN (bit 0)
+  set where available.
+
+- Coherency
+  All CPUs to be booted by the kernel must be part of the same coherency
+  domain on entry to the kernel.  This may require IMPLEMENTATION DEFINED
+  initialisation to enable the receiving of maintenance operations on
+  each CPU.
+
+- System registers
+  All writable architected system registers at the exception level where
Quoted 8 lines

Documentation/arm64/booting.txt line 116

Quoted 2 lines
Documentation/arm64/booting.txt new file +2 -0
+  the kernel image will be entered must be initialised by software at a
+  higher exception level to prevent execution in an UNKNOWN state.

Given the recent development of ARM platforms, you might want to mandate the state of IOMMUs as well (they should probably be off, since there should be no active DMA activity). Graphics would be the exception to this, since if you want to keep scanning out a splash screen, you'll have to keep doing DMA...

We'll enhance this document as we get hardware as it's not clear whether we can simply mandate it to be off. We may have situations with some simple IOMMU that is previously set up by the firmware and the kernel doesn't get access to it. One example is the System MMU from ARM that supports stage 2 (hypervisor) translations and you just run a guest kernel without any control of the IOMMU.

Quoted 4 lines
Quoted 4 lines

+- The primary CPU must jump directly to the first instruction of the

Documentation/arm64/booting.txt new file +3 -0
+  kernel image.  The device tree blob passed by this CPU must contain
+  for each CPU node:
+
Quoted 8 lines

Documentation/arm64/booting.txt line 129

Quoted 5 lines
Documentation/arm64/booting.txt new file +5 -0
+    1. An 'enable-method' property. Currently, the only supported value
+       for this field is the string "spin-table".
+
+    2. A 'cpu-release-addr' property identifying a 64-bit,
+       zero-initialised memory location.

These would be good to have documented in the Documentation/devicetree/bindings hierarchy as well.

OK.

Quoted 24 lines
Quoted 24 lines

index 0000000..d766493

arch/arm64/include/asm/setup.h new file +20 -0
@@ -0,0 +1,26 @@
+/*
+ * Based on arch/arm/include/asm/setup.h
+ *
+ * Copyright (C) 1997-1999 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SETUP_H
+#define __ASM_SETUP_H
Quoted 8 lines

arch/arm64/include/asm/setup.h line 24

Quoted 4 lines
arch/arm64/include/asm/setup.h new file +4 -0
+
+#include <linux/types.h>
+
+#define COMMAND_LINE_SIZE 1024

Probably not a huge deal, and other architectures seem to be all over the map on this, but you might want to go with a larger value now rather than later. 2048 or 4096 perhaps?

It looks like there are many different values, including the asm-generic one which is 512. I'm happy to follow the x86 example and change it to 2048, it doesn't really matter.

Quoted 8 lines
Quoted 5 lines
arch/arm64/kernel/head.S new file +0 -0
new file mode 100644
index 0000000..34ccdc0

[...]

Quoted 10 lines

arch/arm64/kernel/head.S line 253

Quoted 8 lines
arch/arm64/kernel/head.S new file +8 -0
+/*
+ * Setup common bits before finally enabling the MMU. Essentially this is just
+ * loading the page table pointer and vector base registers.
+ *
+ * On entry to this code, x0 must contain the SCTLR_EL1 value for turning on
+ * the MMU.
+ */
+__enable_mmu:

ENTRY()?

__enable_mmu is not used outside this file, so no need for ENTRY().

Quoted 9 lines

arch/arm64/kernel/head.S line 260

Quoted 7 lines
arch/arm64/kernel/head.S new file +7 -0
+	ldr	x5, =vectors
+	msr	vbar_el1, x5
+	msr	ttbr0_el1, x25			// load TTBR0
+	msr	ttbr1_el1, x26			// load TTBR1
+	isb
+	b	__turn_mmu_on
+ENDPROC(__enable_mmu)

...or just END()? Same for a few of the other functions below.

ENDPROC() gives us ".type @function" in addition to END(). This proved to be useful in the past for debugging symbols, unwind table (though we don't have the latter on AArch64).

Quoted 8 lines
Quoted 5 lines
arch/arm64/kernel/setup.c new file +0 -0
new file mode 100644
index 0000000..f25186f

[...]

Quoted 11 lines

arch/arm64/kernel/setup.c line 112

Quoted 9 lines
arch/arm64/kernel/setup.c new file +9 -0
+static void __init setup_processor(void)
+{
+	struct proc_info_list *list;
+
+	/*
+	 * locate processor in the list of supported processor
+	 * types.  The linker builds this table for us from the
+	 * entries in arch/arm/mm/proc.S
+	 */

Probably from arch/arm64/... somewhere?

Yes, I did a grep and found a few more.

Quoted 5 lines
Quoted 4 lines
arch/arm64/kernel/setup.c new file +4 -0
+	printk("CPU: %s [%08x] revision %d\n",
+	       cpu_name, read_cpuid_id(), read_cpuid_id() & 15);
+
+	sprintf(init_utsname()->machine, "aarch64");
Quoted 13 lines

arch/arm64/kernel/setup.c line 171

Quoted 9 lines
arch/arm64/kernel/setup.c new file +9 -0
+	initial_boot_params = devtree;
+	dt_root = of_get_flat_dt_root();
+
+	machine_name = of_get_flat_dt_prop(dt_root, "model", NULL);
+	if (!machine_name)
+		machine_name = of_get_flat_dt_prop(dt_root, "compatible", NULL);
+	if (!machine_name)
+		machine_name = "<unknown>";
+	pr_info("Machine: %s\n", machine_name);

This property is an array of strings. It would be more valuable to print out the entry that was matched for a platform instead of the provided one from the device tree.

If we add machine_desc structure back, we could print which machine was matched. But so far I try to keep the SoC code to a minimum and just do the probing later in the SoC code (of_find_matching_node). Ideally we shouldn't have any SoC code and just keep code in drivers but we'll see how far we can get. We can discuss more details at the KS as I would like the arm-soc team to get involved here.

Thanks.

Signature · 1 line
Catalin
#6 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

Hi,

Quoted 8 lines · Catalin Marinas

Hi Olof,

Quoted 5 lines

Given the recent development of ARM platforms, you might want to mandate the state of IOMMUs as well (they should probably be off, since there should be no active DMA activity). Graphics would be the exception to this, since if you want to keep scanning out a splash screen, you'll have to keep doing DMA...

Quoted 6 lines

We'll enhance this document as we get hardware as it's not clear whether we can simply mandate it to be off. We may have situations with some simple IOMMU that is previously set up by the firmware and the kernel doesn't get access to it. One example is the System MMU from ARM that supports stage 2 (hypervisor) translations and you just run a guest kernel without any control of the IOMMU.

Ok, fair enough.

Quoted 23 lines
Quoted 10 lines

arch/arm64/kernel/head.S line 253

Quoted 8 lines
arch/arm64/kernel/head.S new file +8 -0
+/*
+ * Setup common bits before finally enabling the MMU. Essentially this is just
+ * loading the page table pointer and vector base registers.
+ *
+ * On entry to this code, x0 must contain the SCTLR_EL1 value for turning on
+ * the MMU.
+ */
+__enable_mmu:

ENTRY()?

__enable_mmu is not used outside this file, so no need for ENTRY().

Quoted 9 lines

arch/arm64/kernel/head.S line 260

Quoted 7 lines
arch/arm64/kernel/head.S new file +7 -0
+	ldr	x5, =vectors
+	msr	vbar_el1, x5
+	msr	ttbr0_el1, x25			// load TTBR0
+	msr	ttbr1_el1, x26			// load TTBR1
+	isb
+	b	__turn_mmu_on
+ENDPROC(__enable_mmu)

...or just END()? Same for a few of the other functions below.

Quoted 3 lines

ENDPROC() gives us ".type @function" in addition to END(). This proved to be useful in the past for debugging symbols, unwind table (though we don't have the latter on AArch64).

A good as reason as any, sounds good.

Quoted 12 lines
Quoted 11 lines

arch/arm64/kernel/setup.c line 112

Quoted 9 lines
arch/arm64/kernel/setup.c new file +9 -0
+static void __init setup_processor(void)
+{
+	struct proc_info_list *list;
+
+	/*
+	 * locate processor in the list of supported processor
+	 * types.  The linker builds this table for us from the
+	 * entries in arch/arm/mm/proc.S
+	 */

Probably from arch/arm64/... somewhere?

Quoted 1 line

Yes, I did a grep and found a few more.

Yeah, I pointed out some other stale ARM-derived comments in other patches.

Quoted 19 lines
Quoted 5 lines
Quoted 4 lines
arch/arm64/kernel/setup.c new file +4 -0
+	printk("CPU: %s [%08x] revision %d\n",
+	       cpu_name, read_cpuid_id(), read_cpuid_id() & 15);
+
+	sprintf(init_utsname()->machine, "aarch64");
Quoted 13 lines

arch/arm64/kernel/setup.c line 171

Quoted 9 lines
arch/arm64/kernel/setup.c new file +9 -0
+	initial_boot_params = devtree;
+	dt_root = of_get_flat_dt_root();
+
+	machine_name = of_get_flat_dt_prop(dt_root, "model", NULL);
+	if (!machine_name)
+		machine_name = of_get_flat_dt_prop(dt_root, "compatible", NULL);
+	if (!machine_name)
+		machine_name = "<unknown>";
+	pr_info("Machine: %s\n", machine_name);

This property is an array of strings. It would be more valuable to print out the entry that was matched for a platform instead of the provided one from the device tree.

Quoted 6 lines

If we add machine_desc structure back, we could print which machine was matched. But so far I try to keep the SoC code to a minimum and just do the probing later in the SoC code (of_find_matching_node). Ideally we shouldn't have any SoC code and just keep code in drivers but we'll see how far we can get. We can discuss more details at the KS as I would like the arm-soc team to get involved here.

Interesting approach, I wonder if it'll scale, in particular if it comes to needing to do early setup and init. For device-level setup, generic will probably work just fine. And if it doesn't, things can be changed later. So it sounds like a good start.

Definitely something we should discuss. I suggest not doing it at KS though, since only half of the arm-soc team is invited there. So the ARM mini-summit or hallway around LPC is a better venue.

-Olof

author maintainer
#7 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

Quoted 8 lines · Olof Johansson
Quoted 6 lines · Catalin Marinas

If we add machine_desc structure back, we could print which machine was matched. But so far I try to keep the SoC code to a minimum and just do the probing later in the SoC code (of_find_matching_node). Ideally we shouldn't have any SoC code and just keep code in drivers but we'll see how far we can get. We can discuss more details at the KS as I would like the arm-soc team to get involved here.

Quoted 8 lines

Interesting approach, I wonder if it'll scale, in particular if it comes to needing to do early setup and init. For device-level setup, generic will probably work just fine. And if it doesn't, things can be changed later. So it sounds like a good start.

Definitely something we should discuss. I suggest not doing it at KS though, since only half of the arm-soc team is invited there. So the ARM mini-summit or hallway around LPC is a better venue.

I was indeed thinking of the ARM mini-summit or hallway discussions. The KS has different topics and it wouldn't have been of wide interest anyway.

Signature · 1 line
Catalin
#26 lore raw

Re: [PATCH v2 03/31] arm64: Exception handling

In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

arch/arm64/include/asm/ptrace.h line 141

Quoted 6 lines · Catalin Marinas
arch/arm64/include/asm/ptrace.h new file +6 -0
+#ifdef CONFIG_AARCH32_EMULATION
+#define compat_thumb_mode(regs) \
+	(((regs)->pstate & COMPAT_PSR_T_BIT))
+#else
+#define compat_thumb_mode(regs) (0)
+#endif

The symbol we use on other platforms is CONFIG_COMPAT. I don't think you need to have a separate CONFIG_AARCH32_EMULATION

Using COMPAT does preclude the possibility of doing something like the x32 ABI later on though. Some other architectures seem to do something similar (MIPS32_COMPAT, IA32_EMULATION).

Will

#89 lore raw

Re: [PATCH v2 16/31] arm64: ELF definitions

In reply to Arnd Bergmann
Quoted 26 lines · Arnd Bergmann
Quoted 9 lines · Catalin Marinas
arch/arm64/kernel/elf.c new file +9 -0
+
+void elf_set_personality(int personality)
+{
+       switch (personality & PER_MASK) {
+       case PER_LINUX:
+               clear_thread_flag(TIF_32BIT);
+               break;
+       case PER_LINUX32:
+               set_thread_flag(TIF_32BIT);

arch/arm64/kernel/elf.c line 41

Quoted 10 lines
arch/arm64/kernel/elf.c new file +10 -0
+               break;
+       default:
+               pr_warning("Process %s tried to assume unknown personality %d\n",
+                          current->comm, personality);
+               return;
+       }
+
+       current->personality = personality;
+}
+EXPORT_SYMBOL(elf_set_personality);

This looks wrong: PER_LINUX/PER_LINUX32 decides over the output of the uname system call, while TIF_32BIT decides over the instruction set when returning to user space. You definitely should not set the personality to the value you pass from the elf loader. Instead, just do

Quoted 2 lines

#define SET_PERSONALITY(ex) clear_thread_flag(TIF_32BIT); #defined COMPAT_SET_PERSONALITY(ex) set_thread_flag(TIF_32BIT);

In this case, won't uname be incorrect (aarch64l) for aarch32 tasks (which expect something like armv8l)?

Will

#119 lore raw

Re: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

In reply to Arnd Bergmann
Quoted 16 lines · Arnd Bergmann

arch/arm64/kernel/sys_compat.c line 98

Quoted 12 lines · Catalin Marinas
arch/arm64/kernel/sys_compat.c new file +12 -0
+asmlinkage int compat_sys_personality(compat_ulong_t personality)
+{
+	int ret;
+
+	if (personality(current->personality) == PER_LINUX32 &&
+		personality == PER_LINUX)
+		personality = PER_LINUX32;
+	ret = sys_personality(personality);
+	if (ret == PER_LINUX32)
+		ret = PER_LINUX;
+	return ret;
+}

Where did you get this from?

Quoted 1 line

You should not need compat_sys_personality, just call the native function.

Hmm, but in that case an aarch32 application doing a personality(PER_LINUX) syscall will start seeing the wrong uname.

Will

#133 lore raw

Re: [PATCH v2 23/31] arm64: Debugging support

In reply to Arnd Bergmann
Quoted 12 lines · Arnd Bergmann

arch/arm64/kernel/ptrace.c line 572

Quoted 8 lines · Catalin Marinas
arch/arm64/kernel/ptrace.c new file +8 -0
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+#ifdef CONFIG_AARCH32_EMULATION
+	if (test_tsk_thread_flag(task, TIF_32BIT))
+		return &user_aarch32_view;
+#endif
+	return &user_aarch64_view;
+}

Ah, nice. So you support 64 bit debuggers debugging 32 bit processes, right?

That should work if the debugger can deal with it, yes.

Quoted 3 lines

From what I can tell, there is no support for 32 bit processes debugging 64 bit ones. Is that something you plan to add in the future, or do you consider that out of scope? In either case, a comment would be helpful.

That can't really work because the debugger won't be able to manipulate child pointers properly without us adding a new ptrace interface (and then, I still wonder about how feasible it really is). I can add a comment.

Quoted 24 lines
Quoted 24 lines
arch/arm64/kernel/ptrace.c new file +24 -0
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
+{
+	int ret;
+	unsigned long *datap = (unsigned long __user *)data;
+
+	switch (request) {
+		case PTRACE_GET_THREAD_AREA:
+			ret = put_user(child->thread.tp_value, datap);
+			break;
+
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+		case PTRACE_GETHBPREGS:
+			ret = ptrace_gethbpregs(child, addr, datap);
+			break;
+
+		case PTRACE_SETHBPREGS:
+			ret = ptrace_sethbpregs(child, addr, datap);
+			break;
+#endif
+
+		default:
+			ret = ptrace_request(child, request, addr, data);
+			break;
Quoted 8 lines

arch/arm64/kernel/hw_breakpoint.c line 472

Quoted 4 lines
arch/arm64/kernel/hw_breakpoint.c new file +4 -0
+	}
+
+	return ret;
+}

Is there a reaons why these are not regsets but have their own ptrace commands? I believe new architectures should generally not add ptrace commands any more.

I could probably add some regset wrappers about the hbp accessors (which we have to keep for the compat ptrace interface). I'll have a think as it might even make sense to have different regsets for breakpoints and watchpoints.

As for the the tls, is it worth having a regset with only one register?

Will

#144 lore raw

Re: [PATCH v2 25/31] arm64: Performance counters support

In reply to Arnd Bergmann
Quoted 13 lines · Arnd Bergmann
Quoted 11 lines · Catalin Marinas

From: Will Deacon <[email protected]>

This patch adds support for the AArch64 performance counters.

---
 arch/arm64/include/asm/perf_event.h |   22 +
 arch/arm64/include/asm/pmu.h        |   82 +++
 arch/arm64/kernel/perf_event.c      | 1368 +++++++++++++++++++++++++++++++++++
 tools/perf/perf.h                   |    6 +
Quoted 3 lines

Can you explain how AArch64 performance counters differ from the 32 bit ones? Do they work for AArch32 user space under AArch64 kernels? Is it possible to share parts of the implementation with arch/arm?

Perf should work for compat tasks, yes. I'd like to share some of the code with arch/arm/ and I've started reworking the arch/arm/ stuff to accomodate this better:

git://git.kernel.org/pub/scm/linux/kernel/git/will/linux.git perf/updates

I'm not sure how well it will fit in drivers/ but I'm certainly willing to give it a try.

Will

#147 lore raw

Re: [PATCH v2 26/31] arm64: Miscellaneous library functions

In reply to Arnd Bergmann
Quoted 22 lines · Arnd Bergmann
Quoted 20 lines · Catalin Marinas
arch/arm64/include/asm/bitops.h new file +20 -0
+
+/*
+ * Use compiler builtins for simple inline operations.
+ */
+static inline unsigned long __ffs(unsigned long word)
+{
+	return __builtin_ffsl(word) - 1;
+}
+
+static inline int ffs(int x)
+{
+	return __builtin_ffs(x);
+}
+
+static inline unsigned long __fls(unsigned long word)
+{
+	return BITS_PER_LONG - 1 - __builtin_clzl(word);
+}
+
+static inline int fls(int x)
Quoted 8 lines

arch/arm64/include/asm/bitops.h line 52

Quoted 3 lines
arch/arm64/include/asm/bitops.h new file +3 -0
+{
+	return x ? sizeof(x) * BITS_PER_BYTE - __builtin_clz(x) : 0;
+}

These are all great, but I think whether to use them or not should depend on the compiler version rather than the architecture in general. Do we know a minimum gcc version that supports all of the above? Then we could put that code into the generic files.

I imagine that the version of GCC that supports these builtins varies for each architecture. For aarch64, the compile will always support these builtins and these particular ones are guaranteed to be inlined.

Quoted 7 lines

If that's not possible, we could still make the implementation available for other architectures by moving it to

asm-generic/bitops/builtin-__ffs.h
asm-generic/bitops/builtin-ffs.h
asm-generic/bitops/builtin-__fls.h
asm-generic/bitops/builtin-fls.h

Yeah, that might be an idea. The architecture can then decide to use them if it knows they are available and usable.

Quoted 31 lines
Quoted 18 lines
arch/arm64/lib/bitops.c new file +15 -0
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2012 ARM Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */

arch/arm64/lib/bitops.c line 25

Quoted 10 lines
arch/arm64/lib/bitops.c new file +10 -0
+
+#include <linux/kernel.h>
+#include <linux/spinlock.h>
+#include <linux/atomic.h>
+
+#ifdef CONFIG_SMP
+arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = {
+       [0 ... (ATOMIC_HASH_SIZE-1)]  = __ARCH_SPIN_LOCK_UNLOCKED
+};
+#endif

What?

Quoted 2 lines

I suppose this is a leftover from an earlier version using the generic bitops, right?

We currently use the generic atomic bitops (asm-generic/bitops/atomic.h) which contains:

# define ATOMIC_HASH(a) (&(__atomic_hash[ (((unsigned long) a)/L1_CACHE_BYTES) & (ATOMIC_HASH_SIZE-1) ]))

so we have to provide a definition for the array. We have additional patches containing optimised assembly implementations of the atomic bitops which we will push later, once we've got some hardware to benchmark with.

Will

maintainer
#27 lore raw

Re: [PATCH v2 03/31] arm64: Exception handling

In reply to Will Deacon
Quoted 13 lines · Will Deacon
Quoted 11 lines · Arnd Bergmann

arch/arm64/include/asm/ptrace.h line 141

Quoted 6 lines · Catalin Marinas
arch/arm64/include/asm/ptrace.h new file +6 -0
+#ifdef CONFIG_AARCH32_EMULATION
+#define compat_thumb_mode(regs) \
+   (((regs)->pstate & COMPAT_PSR_T_BIT))
+#else
+#define compat_thumb_mode(regs) (0)
+#endif

The symbol we use on other platforms is CONFIG_COMPAT. I don't think you need to have a separate CONFIG_AARCH32_EMULATION

Quoted 3 lines

Using COMPAT does preclude the possibility of doing something like the x32 ABI later on though. Some other architectures seem to do something similar (MIPS32_COMPAT, IA32_EMULATION).

Ok, fair enough.

Arnd

maintainer
#90 lore raw

Re: [PATCH v2 16/31] arm64: ELF definitions

In reply to Will Deacon
Quoted 10 lines · Will Deacon
Quoted 7 lines

This looks wrong: PER_LINUX/PER_LINUX32 decides over the output of the uname system call, while TIF_32BIT decides over the instruction set when returning to user space. You definitely should not set the personality to the value you pass from the elf loader. Instead, just do

#define SET_PERSONALITY(ex) clear_thread_flag(TIF_32BIT); #defined COMPAT_SET_PERSONALITY(ex) set_thread_flag(TIF_32BIT);

In this case, won't uname be incorrect (aarch64l) for aarch32 tasks (which expect something like armv8l)?

No, the uname output is meant to tell you about the system, not the instruction set that you are using (you already know that in compiled code).

The main use case is to fool stuff like autoconf into assuming your architecture is the other one, e.g. when building a 32 bit package on using a 64 bit /bin/bash to run ./configure or vice versa.

Arnd

maintainer
#120 lore raw

Re: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

In reply to Will Deacon
Quoted 18 lines · Will Deacon
Quoted 16 lines · Arnd Bergmann

arch/arm64/kernel/sys_compat.c line 98

Quoted 12 lines · Catalin Marinas
arch/arm64/kernel/sys_compat.c new file +12 -0
+asmlinkage int compat_sys_personality(compat_ulong_t personality)
+{
+   int ret;
+
+   if (personality(current->personality) == PER_LINUX32 &&
+           personality == PER_LINUX)
+           personality = PER_LINUX32;
+   ret = sys_personality(personality);
+   if (ret == PER_LINUX32)
+           ret = PER_LINUX;
+   return ret;
+}

Where did you get this from?

Quoted 4 lines
Quoted 1 line

You should not need compat_sys_personality, just call the native function.

Hmm, but in that case an aarch32 application doing a personality(PER_LINUX) syscall will start seeing the wrong uname.

Not the wrong uname, just the default one, which is correct.

Arnd

#156 lore raw

Re: [PATCH v2 28/31] arm64: Generic timers support

In reply to Catalin Marinas
Quoted 1 line · Catalin Marinas

From: Marc Zyngier <[email protected]>

(...)

Quoted 1 line

+static void __init arch_timer_calibrate(void)

I think you wrot in the last review thread that this should be renamed "arch_timer_get_freq()".

drivers/clocksource/arm_generic.c line 184

Quoted 9 lines
drivers/clocksource/arm_generic.c new file +9 -0
+{
+       if (arch_timer_rate == 0) {
+               arch_timer_reg_write(ARCH_TIMER_REG_CTRL, 0);
+               arch_timer_rate = arch_timer_reg_read(ARCH_TIMER_REG_FREQ);
+
+               /* Check the timer frequency. */
+               if (arch_timer_rate == 0)
+                       panic("Architected timer frequency is set to zero.\n"
+                             "You must set this in your .dts file\n");

This comment about the .dts file is completely out-of-place. The error message should be about the register containing 0, right?

Also, at this very point in the code, I think you should convert that panic() to pr_err() and insert:

#include <linux/clk.h>

struct clk *clk;

clk = clk_get_sys("arm_generic_timer", NULL);
if (IS_ERR(clk))

               panic("Not even a clk to get freq off! Giving up.\n");
err = clk_prepare_enable(clk);
if (err) {
           pr_err("smp_twd: clock failed to prepare: %d\n", err);
           clk_put(clk);
           panic("Not even a clk to get freq off! Giving up.\n");
}

arch_timer_rate = clk_get_rate(clk);

Possibly the clk should even be able to override the register value, then it's the other way around.

drivers/clocksource/arm_generic.c line 192

Quoted 8 lines
drivers/clocksource/arm_generic.c new file +8 -0
+       }
+
+       /* Cache the sched_clock multiplier to save a divide in the hot path. */
+
+       sched_clock_mult = NSEC_PER_SEC / arch_timer_rate;
+
+       pr_info("Architected local timer running at %u.%02uMHz.\n",
+                arch_timer_rate / 1000000, (arch_timer_rate / 10000) % 100);

This multiplier and print should be moved below the call site since the DT frequency
overrides it and then you get no print which is sad, and incorrect sched_clock_mult
which is a bug.

Quoted 1 line

+}

(...)

drivers/clocksource/arm_generic.c line 285

Quoted 4 lines
drivers/clocksource/arm_generic.c new file +4 -0
+       /* Try to determine the frequency from the device tree or CNTFRQ */
+       if (!of_property_read_u32(np, "clock-frequency", &freq))
+               arch_timer_rate = freq;
+       arch_timer_calibrate();

rename arch_timer_get_freq()

And move that print here.

Yours,
Linus Walleij

maintainer
#134 lore raw

Re: [PATCH v2 23/31] arm64: Debugging support

In reply to Will Deacon
Quoted 10 lines · Will Deacon
Quoted 5 lines · Arnd Bergmann

On Tuesday 14 August 2012, Catalin Marinas wrote:

From what I can tell, there is no support for 32 bit processes debugging 64 bit ones. Is that something you plan to add in the future, or do you consider that out of scope? In either case, a comment would be helpful.

That can't really work because the debugger won't be able to manipulate child pointers properly without us adding a new ptrace interface (and then, I still wonder about how feasible it really is). I can add a comment.

You can already have a 32 bit gdb that is able to do remote debugging of 64 bit processes using a gdb server process. I guess it wouldn't be too strange to have a ptrace extension to allow the native case as well. I agree it's not a high priority.

Quoted 33 lines
Quoted 24 lines
Quoted 24 lines
arch/arm64/kernel/ptrace.c new file +24 -0
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
+{
+	int ret;
+	unsigned long *datap = (unsigned long __user *)data;
+
+	switch (request) {
+		case PTRACE_GET_THREAD_AREA:
+			ret = put_user(child->thread.tp_value, datap);
+			break;
+
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+		case PTRACE_GETHBPREGS:
+			ret = ptrace_gethbpregs(child, addr, datap);
+			break;
+
+		case PTRACE_SETHBPREGS:
+			ret = ptrace_sethbpregs(child, addr, datap);
+			break;
+#endif
+
+		default:
+			ret = ptrace_request(child, request, addr, data);
+			break;
Quoted 8 lines

arch/arm64/kernel/hw_breakpoint.c line 472

Quoted 4 lines
arch/arm64/kernel/hw_breakpoint.c new file +4 -0
+	}
+
+	return ret;
+}

Is there a reaons why these are not regsets but have their own ptrace commands? I believe new architectures should generally not add ptrace commands any more.

Quoted 5 lines

I could probably add some regset wrappers about the hbp accessors (which we have to keep for the compat ptrace interface). I'll have a think as it might even make sense to have different regsets for breakpoints and watchpoints.

As for the the tls, is it worth having a regset with only one register?

Better ask the gdb folks. I'm adding Uli to Cc, maybe he has some insight.

Arnd

author maintainer
#10 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Arnd Bergmann
Quoted 12 lines · Arnd Bergmann

Documentation/arm64/booting.txt line 13

Quoted 4 lines · Catalin Marinas
Documentation/arm64/booting.txt new file +4 -0
+The AArch64 exception model is made up of a number of exception levels
+(EL0 - EL3), with EL0 and EL1 having a secure and a non-secure
+counterpart.  EL2 is the hypervisor level and exists only in non-secure
+mode. EL3 is the highest priority level and exists only in secure mode.

I'm always confused by a description like this. It sounds like you cannot have a hypervisor if you have code running in secure mode in EL3. What I instead understand is that you enter non-secure mode by going from EL3 into EL2.

Quoted 1 line

From EL3 you can drop to either EL2 (non-secure) or EL1 (secure or

non-secure), it's the highest privilege level. But we don't support the kernel entering at EL3, the SoC firmware runs in this mode. I'll try to make it clearer.

Quoted 16 lines

Documentation/arm64/booting.txt line 51

Quoted 9 lines

+2. Setup the device tree
+-------------------------

Documentation/arm64/booting.txt new file +7 -0
+
+Requirement: MANDATORY
+
+The device tree blob (dtb) must be no bigger than 2 megabytes in size
+and placed at a 2-megabyte boundary within the first 512 megabytes from
+the start of the kernel image. This is to allow the kernel to map the
+blob using a single section mapping in the initial page tables.

I've seen people put firmware for some peripherals into the device tree, so that a device driver can grab a blob from there and load it into the device, rather than calling request_firmware() which would fail if the OS running on the system does not contain the blob. If such firmware is too large, you end up violating the 2 MB limit you impose here.

Quoted 2 lines

Should we keep that limit and declare those use cases as invalid, or should we try to make the boot protocol more flexible?

I would be ok to allowing larger range here but we currently don't get the information about the size of the dtb early enough to know how much to map. We could make some other arbitrary choice if needed like being in the first 16MB of RAM and we map this range.

Signature · 1 line
Catalin
maintainer
#148 lore raw

Re: [PATCH v2 26/31] arm64: Miscellaneous library functions

In reply to Will Deacon
Quoted 16 lines · Will Deacon
Quoted 13 lines

arch/arm64/lib/bitops.c line 25

Quoted 10 lines
arch/arm64/lib/bitops.c new file +10 -0
+
+#include <linux/kernel.h>
+#include <linux/spinlock.h>
+#include <linux/atomic.h>
+
+#ifdef CONFIG_SMP
+arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = {
+       [0 ... (ATOMIC_HASH_SIZE-1)]  = __ARCH_SPIN_LOCK_UNLOCKED
+};
+#endif

What?

Quoted 2 lines

I suppose this is a leftover from an earlier version using the generic bitops, right?

Quoted 9 lines

We currently use the generic atomic bitops (asm-generic/bitops/atomic.h) which contains:

# define ATOMIC_HASH(a) (&(__atomic_hash[ (((unsigned long) a)/L1_CACHE_BYTES) & (ATOMIC_HASH_SIZE-1) ]))

so we have to provide a definition for the array. We have additional patches containing optimised assembly implementations of the atomic bitops which we will push later, once we've got some hardware to benchmark with.

Ah, I was confusing this with the asm/atomic.h stuff, for which you already provide an optimized version.

The generic atomic bitops are really horrible in performance and I would expect that there is just one obvious way to implement bitops using ldaxr/stlxr, so I recommend just doing that even if you have no hardware for benchmarking.

The s390 version should be fairly easy to adapt.

Arnd

author maintainer
#149 lore raw

Re: [PATCH v2 26/31] arm64: Miscellaneous library functions

Quoted 27 lines · Arnd Bergmann
Quoted 16 lines · Will Deacon
Quoted 13 lines

arch/arm64/lib/bitops.c line 25

Quoted 10 lines
arch/arm64/lib/bitops.c new file +10 -0
+
+#include <linux/kernel.h>
+#include <linux/spinlock.h>
+#include <linux/atomic.h>
+
+#ifdef CONFIG_SMP
+arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = {
+       [0 ... (ATOMIC_HASH_SIZE-1)]  = __ARCH_SPIN_LOCK_UNLOCKED
+};
+#endif

What?

Quoted 2 lines

I suppose this is a leftover from an earlier version using the generic bitops, right?

Quoted 9 lines

We currently use the generic atomic bitops (asm-generic/bitops/atomic.h) which contains:

# define ATOMIC_HASH(a) (&(__atomic_hash[ (((unsigned long) a)/L1_CACHE_BYTES) & (ATOMIC_HASH_SIZE-1) ]))

so we have to provide a definition for the array. We have additional patches containing optimised assembly implementations of the atomic bitops which we will push later, once we've got some hardware to benchmark with.

Quoted 6 lines

Ah, I was confusing this with the asm/atomic.h stuff, for which you already provide an optimized version.

The generic atomic bitops are really horrible in performance and I would expect that there is just one obvious way to implement bitops using ldaxr/stlxr, so I recommend just doing that even if you have no hardware for benchmarking.

As Will said, we have the code already but I dropped it from the initial set patches to be reviewed to keep them simpler. They will be added later.

Signature · 1 line
Catalin
#50 lore raw

Re: [PATCH v2 07/31] arm64: Process management

In reply to Catalin Marinas
Quoted 22 lines · Catalin Marinas
arch/arm64/kernel/process.c new file +22 -0
+void cpu_idle(void)
+{
+	local_fiq_enable();
+
+	/* endless idle loop with no priority at all */
+	while (1) {
+		tick_nohz_idle_enter();
+		rcu_idle_enter();
+		while (!need_resched()) {
+			/*
+			 * We need to disable interrupts here to ensure
+			 * we don't miss a wakeup call.
+			 */
+			local_irq_disable();
+			if (!need_resched()) {
+				stop_critical_timings();
+				pm_idle();
+				start_critical_timings();
+				/*
+				 * pm_idle functions should always return
+				 * with IRQs enabled.
+				 */

arch/arm64/kernel/process.c line 141

Quoted 10 lines
arch/arm64/kernel/process.c new file +10 -0
+				WARN_ON(irqs_disabled());
+			} else {
+				local_irq_enable();
+			}
+		}
+		rcu_idle_exit();
+		tick_nohz_idle_exit();
+		preempt_enable_no_resched();
+		schedule();
+		preempt_disable();

You could use schedule_preempt_disabled() instead of the above 3 calls. See http://lkml.kernel.org/n/[email protected]

Cheers
Tobias

Acked-by on v2 2/31
#11 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Catalin Marinas
Quoted 7 lines · Catalin Marinas

The patch adds the kernel booting and the initial setup code. Documentation/arm64/booting.txt describes the booting protocol on the AArch64 Linux kernel. This is subject to change following the work on boot standardisation, ACPI.

A few minor comments below, otherwise...

Quoted 58 lines
---
 Documentation/arm64/booting.txt |  141 +++++++++++
 arch/arm64/include/asm/setup.h  |   26 ++
 arch/arm64/kernel/head.S        |  521 +++++++++++++++++++++++++++++++++++++++
 arch/arm64/kernel/setup.c       |  357 +++++++++++++++++++++++++++
 4 files changed, 1045 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/arm64/booting.txt
 create mode 100644 arch/arm64/include/asm/setup.h
 create mode 100644 arch/arm64/kernel/head.S
 create mode 100644 arch/arm64/kernel/setup.c
Documentation/arm64/booting.txt new file +41 -0
new file mode 100644
index 0000000..3197820
@@ -0,0 +1,141 @@
+			Booting AArch64 Linux
+			=====================
+
+Author: Will Deacon <[email protected]>
+Date  : 25 April 2012
+
+This document is based on the ARM booting document by Russell King and
+is relevant to all public releases of the AArch64 Linux kernel.
+
+The AArch64 exception model is made up of a number of exception levels
+(EL0 - EL3), with EL0 and EL1 having a secure and a non-secure
+counterpart.  EL2 is the hypervisor level and exists only in non-secure
+mode. EL3 is the highest priority level and exists only in secure mode.
+
+For the purposes of this document, we will use the term `boot loader'
+simply to define all software that executes on the CPU(s) before control
+is passed to the Linux kernel.  This may include secure monitor and
+hypervisor code, or it may just be a handful of instructions for
+preparing a minimal boot environment.
+
+Essentially, the boot loader should provide (as a minimum) the
+following:
+
+1. Setup and initialise the RAM
+2. Setup the device tree
+3. Decompress the kernel image
+4. Call the kernel image
+
+
+1. Setup and initialise RAM
+---------------------------
+
+Requirement: MANDATORY
+
+The boot loader is expected to find and initialise all RAM that the
+kernel will use for volatile data storage in the system.  It performs
+this in a machine dependent manner.  (It may use internal algorithms
+to automatically locate and size all RAM, or it may use knowledge of
+the RAM in the machine, or any other method the boot loader designer
+sees fit.)
+

Documentation/arm64/booting.txt line 51

Quoted 10 lines
Documentation/arm64/booting.txt new file +10 -0
+
+2. Setup the device tree
+-------------------------
+
+Requirement: MANDATORY
+
+The device tree blob (dtb) must be no bigger than 2 megabytes in size
+and placed at a 2-megabyte boundary within the first 512 megabytes from
+the start of the kernel image. This is to allow the kernel to map the
+blob using a single section mapping in the initial page tables.

It might be a good idea to specify the minimum information that should be contained in the DTB. Memory size is certainly one such item.

Documentation/arm64/booting.txt line 62

Quoted 9 lines
Documentation/arm64/booting.txt new file +9 -0
+3. Decompress the kernel image
+------------------------------
+
+Requirement: OPTIONAL
+
+The AArch64 kernel does not provide a decompressor and therefore
+requires gzip decompression to be performed by the boot loader if the
+default Image.gz target is used.  For bootloaders that do not implement
+this requirement, the larger Image target is available instead.

Some people will want to use bzip2 or whatever other decompressor du jour. Maybe this shouldn't be gzip specific, or just presented as a possible option?

Quoted 15 lines
Documentation/arm64/booting.txt new file +15 -0
+4. Call the kernel image
+------------------------
+
+Requirement: MANDATORY
+
+The decompressed kernel image contains a 32-byte header as follows:
+
+  u32 magic	= 0x14000008;	/* branch to stext, little-endian */
+  u32 res0	= 0;		/* reserved */
+  u64 text_offset;		/* Image load offset */
+  u64 res1	= 0;		/* reserved */
+  u64 res2	= 0;		/* reserved */
+
+The image must be placed at the specified offset (currently 0x80000)
+from the start of the system RAM and called there. The start of the

Documentation/arm64/booting.txt line 89

Quoted 10 lines
Documentation/arm64/booting.txt new file +10 -0
+system RAM must be aligned to 2MB.
+
+Before jumping into the kernel, the following conditions must be met:
+
+- Quiesce all DMA capable devices so that memory does not get
+  corrupted by bogus network packets or disk data.  This will save
+  you many hours of debug.
+
+- Primary CPU general-purpose register settings
+  x0 = physical address of device tree blob (dtb) in system RAM.

I think you should mandate that some additional registers be explicitly initialized to 0 for possible future usage (and also mentioned in the corresponding code comment). We have that issue on ARM32 where it is unclear if r2 contains a valid ATAG/DTB address or not as its content was not defined before.

[...]

Nicolas

maintainer
#135 lore raw

Re: [PATCH v2 23/31] arm64: Debugging support

In reply to Arnd Bergmann
Quoted 50 lines · Arnd Bergmann
Quoted 10 lines · Will Deacon
Quoted 5 lines · Arnd Bergmann

On Tuesday 14 August 2012, Catalin Marinas wrote:

From what I can tell, there is no support for 32 bit processes debugging 64 bit ones. Is that something you plan to add in the future, or do you consider that out of scope? In either case, a comment would be helpful.

That can't really work because the debugger won't be able to manipulate child pointers properly without us adding a new ptrace interface (and then, I still wonder about how feasible it really is). I can add a comment.

You can already have a 32 bit gdb that is able to do remote debugging of 64 bit processes using a gdb server process. I guess it wouldn't be too strange to have a ptrace extension to allow the native case as well. I agree it's not a high priority.

Quoted 33 lines
Quoted 32 lines
Quoted 18 lines
arch/arm64/kernel/ptrace.c new file +18 -0
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
+{
+	int ret;
+	unsigned long *datap = (unsigned long __user *)data;
+
+	switch (request) {
+		case PTRACE_GET_THREAD_AREA:
+			ret = put_user(child->thread.tp_value, datap);
+			break;
+
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+		case PTRACE_GETHBPREGS:
+			ret = ptrace_gethbpregs(child, addr, datap);
+			break;
+
+		case PTRACE_SETHBPREGS:
+			ret = ptrace_sethbpregs(child, addr, datap);

arch/arm64/kernel/ptrace.c line 601

Quoted 10 lines
arch/arm64/kernel/ptrace.c new file +10 -0
+			break;
+#endif
+
+		default:
+			ret = ptrace_request(child, request, addr, data);
+			break;
+	}
+
+	return ret;
+}

Is there a reaons why these are not regsets but have their own ptrace commands? I believe new architectures should generally not add ptrace commands any more.

Quoted 7 lines
Quoted 5 lines

I could probably add some regset wrappers about the hbp accessors (which we have to keep for the compat ptrace interface). I'll have a think as it might even make sense to have different regsets for breakpoints and watchpoints.

As for the the tls, is it worth having a regset with only one register?

Better ask the gdb folks. I'm adding Uli to Cc, maybe he has some insight.

Sorry for the dumb question, but why do you even need PTRACE_GET_THREAD_AREA for 64 bit tasks? I thought the thread pointer is a GPR, or is this just for compat tasks?

Arnd

Acked-by on v2 2/31
#15 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Catalin Marinas

Documentation/arm64/booting.txt line 62

Quoted 9 lines · Catalin Marinas

+3. Decompress the kernel image
+------------------------------

Documentation/arm64/booting.txt new file +7 -0
+
+Requirement: OPTIONAL
+
+The AArch64 kernel does not provide a decompressor and therefore
+requires gzip decompression to be performed by the boot loader if the
+default Image.gz target is used.  For bootloaders that do not implement
+this requirement, the larger Image target is available instead.

Maybe add something here about why AArch64 does not provide a decompressor? That's something everybody will wonder while reading this part.

Documentation/arm64/booting.txt line 100

Quoted 4 lines

+- Caches, MMUs

Documentation/arm64/booting.txt new file +3 -0
+  The MMU must be off.
+  Instruction cache may be on or off.
+  Data cache must be off and invalidated.

External caches must be configured by bootloader but set to disabled state?

Other than that:

Acked-by on v2 4/31
#33 lore raw

Re: [PATCH v2 04/31] arm64: MMU definitions

In reply to Catalin Marinas
Quoted 7 lines · Catalin Marinas

The virtual memory layout is described in Documentation/arm64/memory.txt. This patch adds the MMU definitions for the 4KB and 64KB translation table configurations. The SECTION_SIZE is 2MB with 4KB page and 512MB with 64KB page configuration.

PHYS_OFFSET is calculated at run-time and stored in a variable (no run-time code patching at this stage).

Care to clarify this part a bit? Is the memory standardized somehow now and not needed? Or do we still need to add that for various SoCs later on?

Other than that:

Acked-by on v2 13/31
#75 lore raw

Re: [PATCH v2 13/31] arm64: Device specific operations

In reply to Catalin Marinas

arch/arm64/mm/ioremap.c line 76

Quoted 9 lines · Catalin Marinas
arch/arm64/mm/ioremap.c new file +7 -0
+
+void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot)
+{
+	return __ioremap_caller(phys_addr, size, prot,
+				__builtin_return_address(0));
+}
+EXPORT_SYMBOL(__ioremap);

From SoC point of view, we're probably going to need __ioremap_exec() here too for programming clocks during runtime in SRAM etc. But that can be added later as needed.

author maintainer
#34 lore raw

Re: [PATCH v2 04/31] arm64: MMU definitions

In reply to Tony Lindgren
Quoted 6 lines · Tony Lindgren
Quoted 5 lines · Catalin Marinas

The virtual memory layout is described in Documentation/arm64/memory.txt. This patch adds the MMU definitions for the 4KB and 64KB translation table configurations. The SECTION_SIZE is 2MB with 4KB page and 512MB with 64KB page configuration.

Quoted 6 lines
Quoted 2 lines

PHYS_OFFSET is calculated at run-time and stored in a variable (no run-time code patching at this stage).

Care to clarify this part a bit? Is the memory standardized somehow now and not needed? Or do we still need to add that for various SoCs later on?

The memory is not standardised but we have FDT to fully specify it. The PHYS_OFFSET does not need to be defined, it is automatically detected at boo-time based on the kernel load address and stored in a variable to be used later.

Quoted 3 lines

Other than that:

Thanks.

Signature · 1 line
Catalin
Acked-by on v2 15/31
#84 lore raw

Re: [PATCH v2 15/31] arm64: SMP support

In reply to Catalin Marinas
Quoted 8 lines · Catalin Marinas

This patch adds SMP initialisation and spinlocks implementation for AArch64. The spinlock support uses the new load-acquire/store-release instructions to avoid explicit barriers. The architecture also specifies that an event is automatically generated when clearing the exclusive monitor state to wake up processors in WFE, so there is no need for an explicit DSB/SEV instruction sequence. The SEVL instruction is used to set the exclusive monitor locally as there is no conditional WFE and a branch is more expensive.

Do we always have SMP hardware on arm64? Or are we going to need to again add smp_on_up support later on?

Other than that:

Acked-by on v2 28/31
#157 lore raw

Re: [PATCH v2 28/31] arm64: Generic timers support

In reply to Catalin Marinas
Quoted 9 lines · Catalin Marinas

From: Marc Zyngier <[email protected]>

This patch adds support for the ARM generic timers with A64 instructions for accessing the timer registers. It uses the physical counter as the clock source and the virtual counter as sched_clock.

The timer frequency can be specified via DT or read from the CNTFRQ_EL0 register. The physical counter is also accessible from user space allowing fast gettimeofday() implementation.

Can we always assume we can boot the kernel with ARM generic timers and interrupts?

If so, maybe that should be mentioned in the booting requirements doc as that means we can delay SoC specific initialization quite a bit and boot with generic kernel to the initramfs ;)

Other than that:

Acked-by on v2 30/31
#165 lore raw

Re: [PATCH v2 30/31] arm64: Build infrastructure

In reply to Catalin Marinas
Quoted 21 lines · Catalin Marinas
arch/arm64/Kconfig new file +18 -0
@@ -0,0 +1,261 @@
+config ARM64
+	def_bool y
+	select OF
+	select OF_EARLY_FLATTREE
+	select IRQ_DOMAIN
+	select HAVE_AOUT
+	select HAVE_DMA_ATTRS
+	select HAVE_DMA_API_DEBUG
+	select HAVE_IDE
+	select HAVE_MEMBLOCK
+	select RTC_LIB
+	select SYS_SUPPORTS_APM_EMULATION
+	select HAVE_GENERIC_DMA_COHERENT
+	select GENERIC_IOMAP
+	select HAVE_IRQ_WORK
+	select HAVE_PERF_EVENTS
+	select HAVE_ARCH_TRACEHOOK
+	select PERF_USE_VMALLOC

arch/arm64/Kconfig line 28

Quoted 10 lines
arch/arm64/Kconfig new file +10 -0
+	select HAVE_HW_BREAKPOINT if PERF_EVENTS
+	select HAVE_GENERIC_HARDIRQS
+	select GENERIC_HARDIRQS_NO_DEPRECATED
+	select HAVE_SPARSE_IRQ
+	select SPARSE_IRQ
+	select GENERIC_IRQ_SHOW
+	select GENERIC_SMP_IDLE_THREAD
+	select NO_BOOTMEM
+	help
+	  ARM 64-bit (AArch64) Linux support.

Anything we should select here for ARM generic timers and interrupts assuming we can always expect to boot using those?

Other than that:

author maintainer
#85 lore raw

Re: [PATCH v2 15/31] arm64: SMP support

In reply to Tony Lindgren
Quoted 10 lines · Tony Lindgren
Quoted 8 lines · Catalin Marinas

This patch adds SMP initialisation and spinlocks implementation for AArch64. The spinlock support uses the new load-acquire/store-release instructions to avoid explicit barriers. The architecture also specifies that an event is automatically generated when clearing the exclusive monitor state to wake up processors in WFE, so there is no need for an explicit DSB/SEV instruction sequence. The SEVL instruction is used to set the exclusive monitor locally as there is no conditional WFE and a branch is more expensive.

Quoted 2 lines

Do we always have SMP hardware on arm64? Or are we going to need to again add smp_on_up support later on?

There isn't anything in the architecture specs that mandates multiple cores but given the current trend it's very likely that we'll always have MP.

An improvement in AArch64 is that we can use the SMP cache/TLB ops (the inner shareable variants) even on a UP system so there is no need for run-time code patching for correct execution.

Signature · 1 line
Catalin
Acked-by on the v2 series
#169 lore raw
In reply to Catalin Marinas
Quoted 3 lines · Catalin Marinas

This is the 2nd version of the set of patches implementing Linux kernel support for the 64-bit ARM architecture (AArch64). Thanks to all who provided feedback on the previous version.

I've looked at these patches mostly from supporting SoCs point of view and made few minor comments. It's nice to see that at least so far I did not spot mutually exlusive #ifdef else stuff that's been causing major issues supporting multiple SoCs with the current ARMs :) So all these patches, feel free to add:

#35 lore raw

Re: [PATCH v2 04/31] arm64: MMU definitions

In reply to Catalin Marinas
Quoted 10 lines · Catalin Marinas
Quoted 9 lines · Tony Lindgren
Quoted 7 lines · Catalin Marinas

The virtual memory layout is described in Documentation/arm64/memory.txt. This patch adds the MMU definitions for the 4KB and 64KB translation table configurations. The SECTION_SIZE is 2MB with 4KB page and 512MB with 64KB page configuration.

PHYS_OFFSET is calculated at run-time and stored in a variable (no run-time code patching at this stage).

Quoted 8 lines
Quoted 3 lines

Care to clarify this part a bit? Is the memory standardized somehow now and not needed? Or do we still need to add that for various SoCs later on?

The memory is not standardised but we have FDT to fully specify it. The PHYS_OFFSET does not need to be defined, it is automatically detected at boo-time based on the kernel load address and stored in a variable to be used later.

OK nice thanks.

Tony

#86 lore raw

Re: [PATCH v2 15/31] arm64: SMP support

In reply to Catalin Marinas
Quoted 14 lines · Catalin Marinas
Quoted 10 lines · Tony Lindgren
Quoted 8 lines · Catalin Marinas

This patch adds SMP initialisation and spinlocks implementation for AArch64. The spinlock support uses the new load-acquire/store-release instructions to avoid explicit barriers. The architecture also specifies that an event is automatically generated when clearing the exclusive monitor state to wake up processors in WFE, so there is no need for an explicit DSB/SEV instruction sequence. The SEVL instruction is used to set the exclusive monitor locally as there is no conditional WFE and a branch is more expensive.

Quoted 2 lines

Do we always have SMP hardware on arm64? Or are we going to need to again add smp_on_up support later on?

Quoted 7 lines

There isn't anything in the architecture specs that mandates multiple cores but given the current trend it's very likely that we'll always have MP.

An improvement in AArch64 is that we can use the SMP cache/TLB ops (the inner shareable variants) even on a UP system so there is no need for run-time code patching for correct execution.

That's good to hear!

Tony

#16 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Catalin Marinas
Quoted 23 lines · Catalin Marinas

The patch adds the kernel booting and the initial setup code. Documentation/arm64/booting.txt describes the booting protocol on the AArch64 Linux kernel. This is subject to change following the work on boot standardisation, ACPI.

---
  Documentation/arm64/booting.txt |  141 +++++++++++
  arch/arm64/include/asm/setup.h  |   26 ++
  arch/arm64/kernel/head.S        |  521 +++++++++++++++++++++++++++++++++++++++
  arch/arm64/kernel/setup.c       |  357 +++++++++++++++++++++++++++
  4 files changed, 1045 insertions(+), 0 deletions(-)

create mode 100644 Documentation/arm64/booting.txt create mode 100644 arch/arm64/include/asm/setup.h create mode 100644 arch/arm64/kernel/head.S create mode 100644 arch/arm64/kernel/setup.c

Documentation/arm64/booting.txt new file +0 -0
new file mode 100644
index 0000000..3197820

[...]

Quoted 15 lines
Documentation/arm64/booting.txt new file +15 -0
+
+The boot loader is expected to enter the kernel on each CPU in the
+following manner:
+
+- The primary CPU must jump directly to the first instruction of the
+  kernel image.  The device tree blob passed by this CPU must contain
+  for each CPU node:
+
+    1. An 'enable-method' property. Currently, the only supported value
+       for this field is the string "spin-table".
+
+    2. A 'cpu-release-addr' property identifying a 64-bit,
+       zero-initialised memory location.
+
+  It is expected that the bootloader will generate these device tree

Documentation/arm64/booting.txt line 141

Quoted 10 lines
Documentation/arm64/booting.txt new file +10 -0
+  properties and insert them into the blob prior to kernel entry.
+
+- Any secondary CPUs must spin outside of the kernel in a reserved area
+  of memory (communicated to the kernel by a /memreserve/ region in the
+  device tree) polling their cpu-release-addr location, which must be
+  contained in the reserved region.  A wfe instruction may be inserted
+  to reduce the overhead of the busy-loop and a sev will be issued by
+  the primary CPU.  When a read of the location pointed to by the
+  cpu-release-addr returns a non-zero value, the CPU must jump directly
+  to this value.

So you expect all the secondary CPUs to be in wakeup state and probably looping in WFE for a signal from kernel to boot. There is one issue with this requirement though. For large CPU system, you need to reset all the CPUs and hit this waiting loop. This will lead to large inrush current need at bootup which may be not be supported. To avoid this issue, secondary CPUs are kept in OFF state and then they are woken up from kernel one by one whenever they need to be brought into the system. This requirement should be considered.

Quoted 60 lines
arch/arm64/include/asm/setup.h new file +26 -0
new file mode 100644
index 0000000..d766493
@@ -0,0 +1,26 @@
+/*
+ * Based on arch/arm/include/asm/setup.h
+ *
+ * Copyright (C) 1997-1999 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see<http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SETUP_H
+#define __ASM_SETUP_H
+
+#include<linux/types.h>
+
+#define COMMAND_LINE_SIZE 1024
+
+#endif
arch/arm64/kernel/head.S new file +22 -0
new file mode 100644
index 0000000..34ccdc0
@@ -0,0 +1,521 @@
+/*
+ * Low-level CPU initialisation
+ * Based on arch/arm/kernel/head.S
+ *
+ * Copyright (C) 1994-2002 Russell King
+ * Copyright (C) 2003-2012 ARM Ltd.
+ * Authors:	Catalin Marinas<[email protected]>
+ *		Will Deacon<[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see<http://www.gnu.org/licenses/>.
+ */
+

[..]

arch/arm64/kernel/head.S line 115

Quoted 10 lines
arch/arm64/kernel/head.S new file +10 -0
+
+	/*
+	 * DO NOT MODIFY. Image header expected by Linux boot-loaders.
+	 */
+	b	stext				// branch to kernel start, magic
+	.long	0				// reserved
+	.quad	TEXT_OFFSET			// Image load offset from start of RAM
+	.quad	0				// reserved
+	.quad	0				// reserved
+

Minor nit. Avoid C++ commenting style "//" here and rest of the patch.

Regards
santosh

author maintainer
#166 lore raw

Re: [PATCH v2 30/31] arm64: Build infrastructure

In reply to Tony Lindgren
Quoted 27 lines · Tony Lindgren
Quoted 26 lines · Catalin Marinas
arch/arm64/Kconfig new file +23 -0
@@ -0,0 +1,261 @@
+config ARM64
+	def_bool y
+	select OF
+	select OF_EARLY_FLATTREE
+	select IRQ_DOMAIN
+	select HAVE_AOUT
+	select HAVE_DMA_ATTRS
+	select HAVE_DMA_API_DEBUG
+	select HAVE_IDE
+	select HAVE_MEMBLOCK
+	select RTC_LIB
+	select SYS_SUPPORTS_APM_EMULATION
+	select HAVE_GENERIC_DMA_COHERENT
+	select GENERIC_IOMAP
+	select HAVE_IRQ_WORK
+	select HAVE_PERF_EVENTS
+	select HAVE_ARCH_TRACEHOOK
+	select PERF_USE_VMALLOC
+	select HAVE_HW_BREAKPOINT if PERF_EVENTS
+	select HAVE_GENERIC_HARDIRQS
+	select GENERIC_HARDIRQS_NO_DEPRECATED
+	select HAVE_SPARSE_IRQ
+	select SPARSE_IRQ
Quoted 8 lines

arch/arm64/Kconfig line 28

Quoted 5 lines
arch/arm64/Kconfig new file +5 -0
+	select GENERIC_IRQ_SHOW
+	select GENERIC_SMP_IDLE_THREAD
+	select NO_BOOTMEM
+	help
+	  ARM 64-bit (AArch64) Linux support.

Anything we should select here for ARM generic timers and interrupts assuming we can always expect to boot using those?

There is an entry in drivers/clocksource/Kconfig:

config CLKSRC_ARM_GENERIC
def_bool y if ARM64

I will have something similar for the GIC but the model does not currently support GICv3 to be able to test. I'll publish a branch with example SoC code (for the model) and that adds GIC support into drivers/irqchip/ with the address information from FDT. The per-CPU GIC initialisation is done via a CPU notifier to decouple this from the SoC code (I think even on 32-bit ARM it could be done in the same way, gic_secondary_init() always takes 0 as argument.

Signature · 1 line
Catalin
#60 lore raw

Re: [PATCH v2 09/31] arm64: Cache maintenance routines

In reply to Catalin Marinas
Quoted 405 lines · Catalin Marinas

The patch adds functionality required for cache maintenance. The AArch64 architecture mandates non-aliasing VIPT or PIPT D-cache and VIPT (may have aliases) or ASID-tagged VIVT I-cache. Cache maintenance operations are automatically broadcast in hardware between CPUs.

---
  arch/arm64/include/asm/cache.h      |   32 ++++
  arch/arm64/include/asm/cacheflush.h |  209 ++++++++++++++++++++++++++
  arch/arm64/include/asm/cachetype.h  |   48 ++++++
  arch/arm64/mm/cache.S               |  279 +++++++++++++++++++++++++++++++++++
  arch/arm64/mm/flush.c               |  132 +++++++++++++++++
  5 files changed, 700 insertions(+), 0 deletions(-)

create mode 100644 arch/arm64/include/asm/cache.h create mode 100644 arch/arm64/include/asm/cacheflush.h create mode 100644 arch/arm64/include/asm/cachetype.h create mode 100644 arch/arm64/mm/cache.S create mode 100644 arch/arm64/mm/flush.c

arch/arm64/include/asm/cache.h new file +32 -0
new file mode 100644
index 0000000..390308a
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see<http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_CACHE_H
+#define __ASM_CACHE_H
+
+#define L1_CACHE_SHIFT		6
+#define L1_CACHE_BYTES		(1<<  L1_CACHE_SHIFT)
+
+/*
+ * Memory returned by kmalloc() may be used for DMA, so we must make
+ * sure that all such allocations are cache aligned. Otherwise,
+ * unrelated code may cause parts of the buffer to be read into the
+ * cache before the transfer is done, causing old data to be seen by
+ * the CPU.
+ */
+#define ARCH_DMA_MINALIGN	L1_CACHE_BYTES
+#define ARCH_SLAB_MINALIGN	8
+
+#endif
arch/arm64/include/asm/cacheflush.h new file +209 -0
new file mode 100644
index 0000000..93b5590
@@ -0,0 +1,209 @@
+/*
+ * Based on arch/arm/include/asm/cacheflush.h
+ *
+ * Copyright (C) 1999-2002 Russell King.
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see<http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_CACHEFLUSH_H
+#define __ASM_CACHEFLUSH_H
+
+#include<linux/mm.h>
+
+/*
+ * This flag is used to indicate that the page pointed to by a pte is clean
+ * and does not require cleaning before returning it to the user.
+ */
+#define PG_dcache_clean PG_arch_1
+
+/*
+ *	MM Cache Management
+ *	===================
+ *
+ *	The arch/arm/mm/cache-*.S and arch/arm/mm/proc-*.S files
+ *	implement these methods.
+ *
+ *	Start addresses are inclusive and end addresses are exclusive;
+ *	start addresses should be rounded down, end addresses up.
+ *
+ *	See Documentation/cachetlb.txt for more information.
+ *	Please note that the implementation of these, and the required
+ *	effects are cache-type (VIVT/VIPT/PIPT) specific.
+ *
+ *	flush_cache_kern_all()
+ *
+ *		Unconditionally clean and invalidate the entire cache.
+ *
+ *	flush_cache_user_mm(mm)
+ *
+ *		Clean and invalidate all user space cache entries
+ *		before a change of page tables.
+ *
+ *	flush_cache_user_range(start, end, flags)
+ *
+ *		Clean and invalidate a range of cache entries in the
+ *		specified address space before a change of page tables.
+ *		- start - user start address (inclusive, page aligned)
+ *		- end   - user end address   (exclusive, page aligned)
+ *		- flags - vma->vm_flags field
+ *
+ *	coherent_kern_range(start, end)
+ *
+ *		Ensure coherency between the Icache and the Dcache in the
+ *		region described by start, end.  If you have non-snooping
+ *		Harvard caches, you need to implement this function.
+ *		- start  - virtual start address
+ *		- end    - virtual end address
+ *
+ *	coherent_user_range(start, end)
+ *
+ *		Ensure coherency between the Icache and the Dcache in the
+ *		region described by start, end.  If you have non-snooping
+ *		Harvard caches, you need to implement this function.
+ *		- start  - virtual start address
+ *		- end    - virtual end address
+ *
+ *	flush_kern_dcache_area(kaddr, size)
+ *
+ *		Ensure that the data held in page is written back.
+ *		- kaddr  - page address
+ *		- size   - region size
+ *
+ *	DMA Cache Coherency
+ *	===================
+ *
+ *	dma_flush_range(start, end)
+ *
+ *		Clean and invalidate the specified virtual address range.
+ *		- start  - virtual start address
+ *		- end    - virtual end address
+ */
+extern void __cpuc_flush_kern_all(void);
+extern void __cpuc_flush_user_all(void);
+extern void __cpuc_flush_user_range(unsigned long, unsigned long, unsigned int);
+extern void __cpuc_coherent_kern_range(unsigned long, unsigned long);
+extern void __cpuc_coherent_user_range(unsigned long, unsigned long);
+extern void __cpuc_flush_dcache_area(void *, size_t);
+
+/*
+ * These are private to the dma-mapping API.  Do not use directly.
+ * Their sole purpose is to ensure that data held in the cache
+ * is visible to DMA, or data written by DMA to system memory is
+ * visible to the CPU.
+ */
+extern void dmac_map_area(const void *, size_t, int);
+extern void dmac_unmap_area(const void *, size_t, int);
+extern void dmac_flush_range(const void *, const void *);
+
+/*
+ * Copy user data from/to a page which is mapped into a different
+ * processes address space.  Really, we want to allow our "user
+ * space" model to handle this.
+ */
+extern void copy_to_user_page(struct vm_area_struct *, struct page *,
+	unsigned long, void *, const void *, unsigned long);
+#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
+	do {							\
+		memcpy(dst, src, len);				\
+	} while (0)
+
+/*
+ * Convert calls to our calling convention.
+ */
+#define flush_cache_all()		__cpuc_flush_kern_all()
+extern void flush_cache_mm(struct mm_struct *mm);
+extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
+extern void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn);
+
+#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
+
+/*
+ * flush_cache_user_range is used when we want to ensure that the
+ * Harvard caches are synchronised for the user space address range.
+ * This is used for the ARM private sys_cacheflush system call.
+ */
+#define flush_cache_user_range(start, end) \
+	__cpuc_coherent_user_range((start)&  PAGE_MASK, PAGE_ALIGN(end))
+
+/*
+ * Perform necessary cache operations to ensure that data previously
+ * stored within this range of addresses can be executed by the CPU.
+ */
+#define flush_icache_range(s,e)		__cpuc_coherent_kern_range(s,e)
+
+/*
+ * flush_dcache_page is used when the kernel has written to the page
+ * cache page at virtual address page->virtual.
+ *
+ * If this page isn't mapped (ie, page_mapping == NULL), or it might
+ * have userspace mappings, then we _must_ always clean + invalidate
+ * the dcache entries associated with the kernel mapping.
+ *
+ * Otherwise we can defer the operation, and clean the cache when we are
+ * about to change to user space.  This is the same method as used on SPARC64.
+ * See update_mmu_cache for the user space part.
+ */
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
+extern void flush_dcache_page(struct page *);
+
+static inline void __flush_icache_all(void)
+{
+	asm("ic	ialluis");
+}
+
+#define ARCH_HAS_FLUSH_ANON_PAGE
+static inline void flush_anon_page(struct vm_area_struct *vma,
+			 struct page *page, unsigned long vmaddr)
+{
+	extern void __flush_anon_page(struct vm_area_struct *vma,
+				struct page *, unsigned long);
+	if (PageAnon(page))
+		__flush_anon_page(vma, page, vmaddr);
+}
+
+#define flush_dcache_mmap_lock(mapping) \
+	spin_lock_irq(&(mapping)->tree_lock)
+#define flush_dcache_mmap_unlock(mapping) \
+	spin_unlock_irq(&(mapping)->tree_lock)
+
+#define flush_icache_user_range(vma,page,addr,len) \
+	flush_dcache_page(page)
+
+/*
+ * We don't appear to need to do anything here.  In fact, if we did, we'd
+ * duplicate cache flushing elsewhere performed by flush_dcache_page().
+ */
+#define flush_icache_page(vma,page)	do { } while (0)
+
+/*
+ * flush_cache_vmap() is used when creating mappings (eg, via vmap,
+ * vmalloc, ioremap etc) in kernel space for pages.  On non-VIPT
+ * caches, since the direct-mappings of these pages may contain cached
+ * data, we need to do a full cache flush to ensure that writebacks
+ * don't corrupt data placed into these pages via the new mappings.
+ */
+static inline void flush_cache_vmap(unsigned long start, unsigned long end)
+{
+	/*
+	 * set_pte_at() called from vmap_pte_range() does not
+	 * have a DSB after cleaning the cache line.
+	 */
+	dsb();
+}
+
+static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
+{
+}
+
+#endif
arch/arm64/include/asm/cachetype.h new file +48 -0
new file mode 100644
index 0000000..85f5f51
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see<http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_CACHETYPE_H
+#define __ASM_CACHETYPE_H
+
+#include<asm/cputype.h>
+
+#define CTR_L1IP_SHIFT		14
+#define CTR_L1IP_MASK		3
+
+#define ICACHE_POLICY_RESERVED	0
+#define ICACHE_POLICY_AIVIVT	1
+#define ICACHE_POLICY_VIPT	2
+#define ICACHE_POLICY_PIPT	3
+
+static inline u32 icache_policy(void)
+{
+	return (read_cpuid_cachetype()>>  CTR_L1IP_SHIFT)&  CTR_L1IP_MASK;
+}
+
+/*
+ * Whilst the D-side always behaves as PIPT on AArch64, aliasing is
+ * permitted in the I-cache.
+ */
+static inline int icache_is_aliasing(void)
+{
+	return icache_policy() != ICACHE_POLICY_PIPT;
+}
+
+static inline int icache_is_aivivt(void)
+{
+	return icache_policy() == ICACHE_POLICY_AIVIVT;
+}
+
+#endif	/* __ASM_CACHETYPE_H */
arch/arm64/mm/cache.S new file +71 -0
new file mode 100644
index 0000000..f4efa04
@@ -0,0 +1,279 @@
+/*
+ * Cache maintenance
+ *
+ * Copyright (C) 2001 Deep Blue Solutions Ltd.
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see<http://www.gnu.org/licenses/>.
+ */
+
+#include<linux/linkage.h>
+#include<linux/init.h>
+#include<asm/assembler.h>
+
+#include "proc-macros.S"
+
+/*
+ *	__cpuc_flush_dcache_all()
+ *
+ *	Flush the whole D-cache.
+ *
+ *	Corrupted registers: x0-x7, x9-x11
+ */
+ENTRY(__cpuc_flush_dcache_all)
+	dsb	sy				// ensure ordering with previous memory accesses
+	mrs	x0, clidr_el1			// read clidr
+	and	x3, x0, #0x7000000		// extract loc from clidr
+	lsr	x3, x3, #23			// left align loc bit field
+	cbz	x3, finished			// if loc is 0, then no need to clean
+	mov	x10, #0				// start clean at cache level 0
+loop1:
+	add	x2, x10, x10, lsr #1		// work out 3x current cache level
+	lsr	x1, x0, x2			// extract cache type bits from clidr
+	and	x1, x1, #7			// mask of the bits for current cache only
+	cmp	x1, #2				// see what cache we have at this level
+	b.lt	skip				// skip if no cache, or just i-cache
+	save_and_disable_irqs x9		// make CSSELR and CCSIDR access atomic
+	msr	csselr_el1, x10			// select current cache level in csselr
+	isb					// isb to sych the new cssr&csidr
+	mrs	x1, ccsidr_el1			// read the new ccsidr
+	restore_irqs x9
+	and	x2, x1, #7			// extract the length of the cache lines
+	add	x2, x2, #4			// add 4 (line length offset)
+	mov	x4, #0x3ff
+	and	x4, x4, x1, lsr #3		// find maximum number on the way size
+	clz	x5, x4				// find bit position of way size increment
+	mov	x7, #0x7fff
+	and	x7, x7, x1, lsr #13		// extract max number of the index size
+loop2:
+	mov	x9, x4				// create working copy of max way size
+loop3:
+	lsl	x6, x9, x5
+	orr	x11, x10, x6			// factor way and cache number into x11
+	lsl	x6, x7, x2
+	orr	x11, x11, x6			// factor index number into x11
+	dc	cisw, x11			// clean&  invalidate by set/way
+	subs	x9, x9, #1			// decrement the way
+	b.ge	loop3
+	subs	x7, x7, #1			// decrement the index
+	b.ge	loop2
+skip:
+	add	x10, x10, #2			// increment cache number

arch/arm64/mm/cache.S line 81

Quoted 10 lines
arch/arm64/mm/cache.S new file +10 -0
+	cmp	x3, x10
+	b.gt	loop1
+finished:
+	mov	x10, #0				// swith back to cache level 0
+	msr	csselr_el1, x10			// select current cache level in csselr
+	dsb	sy
+	isb
+	ret
+ENDPROC(__cpuc_flush_dcache_all)
+

We have discussed the need of cache maintenance by level kind of API for ARMv7 (A15).

Shouldn't we add such API for arm64 as well ?

Regards
Santosh

author maintainer
#17 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Santosh Shilimkar
Quoted 26 lines · Santosh Shilimkar
Quoted 14 lines · Catalin Marinas
Documentation/arm64/booting.txt new file +14 -0
+The boot loader is expected to enter the kernel on each CPU in the
+following manner:
+
+- The primary CPU must jump directly to the first instruction of the
+  kernel image.  The device tree blob passed by this CPU must contain
+  for each CPU node:
+
+    1. An 'enable-method' property. Currently, the only supported value
+       for this field is the string "spin-table".
+
+    2. A 'cpu-release-addr' property identifying a 64-bit,
+       zero-initialised memory location.
+
+  It is expected that the bootloader will generate these device tree

Documentation/arm64/booting.txt line 141

Quoted 10 lines
Documentation/arm64/booting.txt new file +10 -0
+  properties and insert them into the blob prior to kernel entry.
+
+- Any secondary CPUs must spin outside of the kernel in a reserved area
+  of memory (communicated to the kernel by a /memreserve/ region in the
+  device tree) polling their cpu-release-addr location, which must be
+  contained in the reserved region.  A wfe instruction may be inserted
+  to reduce the overhead of the busy-loop and a sev will be issued by
+  the primary CPU.  When a read of the location pointed to by the
+  cpu-release-addr returns a non-zero value, the CPU must jump directly
+  to this value.
Quoted 8 lines

So you expect all the secondary CPUs to be in wakeup state and probably looping in WFE for a signal from kernel to boot. There is one issue with this requirement though. For large CPU system, you need to reset all the CPUs and hit this waiting loop. This will lead to large inrush current need at bootup which may be not be supported. To avoid this issue, secondary CPUs are kept in OFF state and then they are woken up from kernel one by one whenever they need to be brought into the system. This requirement should be considered.

I agree, this part will be extended. That's one method that we currently support and suitable to the model.

The better method is the SMC standardisation that Charles Garcia-Tobin has written (to be made available soon) and was presented at the last Linaro Connect in HK. Given that the CPU power is usually controlled by the secure side, we'll ask for an SMC to be issued for waking up secondary CPUs, so it's up to the secure firmware to write the correct hardware registers.

Quoted 14 lines
Quoted 2 lines
arch/arm64/kernel/head.S new file +0 -0

[..]

arch/arm64/kernel/head.S line 115

Quoted 9 lines
arch/arm64/kernel/head.S new file +9 -0
+	/*
+	 * DO NOT MODIFY. Image header expected by Linux boot-loaders.
+	 */
+	b	stext				// branch to kernel start, magic
+	.long	0				// reserved
+	.quad	TEXT_OFFSET			// Image load offset from start of RAM
+	.quad	0				// reserved
+	.quad	0				// reserved
+

Minor nit. Avoid C++ commenting style "//" here and rest of the patch.

That's not C++ comment style, it's the *official* assembly comment style for AArch64 ('@' is no longer supported).

Signature · 1 line
Catalin
#38 lore raw

Re: [PATCH v2 05/31] arm64: MMU initialisation

In reply to Catalin Marinas
Quoted 7 lines · Catalin Marinas

This patch contains the initialisation of the memory blocks, MMU attributes and the memory map. Only five memory types are defined:
Device nGnRnE (equivalent to Strongly Ordered), Device nGnRE (classic Device memory), Device GRE, Normal Non-cacheable and Normal Cacheable. Cache policies are supported via the memory attributes register (MAIR_EL1) and only affect the Normal Cacheable mappings.

Quoted 5 lines

This patch also adds the SPARSEMEM_VMEMMAP initialisation.

---

Whats the difference between Device nGnRE and Device GRE ? Sorry, I haven't gone through the specs yet and hence the question.

Quoted 115 lines
  arch/arm64/include/asm/memblock.h |   21 ++
  arch/arm64/mm/init.c              |  416 +++++++++++++++++++++++++++++++++++++
  arch/arm64/mm/mmu.c               |  395 +++++++++++++++++++++++++++++++++++
  3 files changed, 832 insertions(+), 0 deletions(-)

create mode 100644 arch/arm64/include/asm/memblock.h create mode 100644 arch/arm64/mm/init.c create mode 100644 arch/arm64/mm/mmu.c

arch/arm64/include/asm/memblock.h new file +21 -0
new file mode 100644
index 0000000..6afeed2
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see<http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_MEMBLOCK_H
+#define __ASM_MEMBLOCK_H
+
+extern void arm64_memblock_init(void);
+
+#endif
arch/arm64/mm/init.c new file +74 -0
new file mode 100644
index 0000000..c87583d
@@ -0,0 +1,416 @@
+/*
+ * Based on arch/arm/mm/init.c
+ *
+ * Copyright (C) 1995-2005 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see<http://www.gnu.org/licenses/>.
+ */
+
+#include<linux/kernel.h>
+#include<linux/export.h>
+#include<linux/errno.h>
+#include<linux/swap.h>
+#include<linux/init.h>
+#include<linux/bootmem.h>
+#include<linux/mman.h>
+#include<linux/nodemask.h>
+#include<linux/initrd.h>
+#include<linux/gfp.h>
+#include<linux/memblock.h>
+#include<linux/sort.h>
+#include<linux/of_fdt.h>
+
+#include<asm/prom.h>
+#include<asm/sections.h>
+#include<asm/setup.h>
+#include<asm/sizes.h>
+#include<asm/tlb.h>
+
+#include "mm.h"
+
+static unsigned long phys_initrd_start __initdata = 0;
+static unsigned long phys_initrd_size __initdata = 0;
+
+phys_addr_t memstart_addr __read_mostly = 0;
+
+void __init early_init_dt_setup_initrd_arch(unsigned long start,
+					    unsigned long end)
+{
+	phys_initrd_start = start;
+	phys_initrd_size = end - start;
+}
+
+static int __init early_initrd(char *p)
+{
+	unsigned long start, size;
+	char *endp;
+
+	start = memparse(p,&endp);
+	if (*endp == ',') {
+		size = memparse(endp + 1, NULL);
+
+		phys_initrd_start = start;
+		phys_initrd_size = size;
+	}
+	return 0;
+}
+early_param("initrd", early_initrd);
+
+#define MAX_DMA32_PFN ((4UL * 1024 * 1024 * 1024)>>  PAGE_SHIFT)
+
+static void __init zone_sizes_init(unsigned long min, unsigned long max)
+{
+	unsigned long zone_size[MAX_NR_ZONES];

arch/arm64/mm/init.c line 84

Quoted 10 lines
arch/arm64/mm/init.c new file +10 -0
+	unsigned long max_dma32 = min;
+
+	memset(zone_size, 0, sizeof(zone_size));
+
+	zone_size[0] = max - min;
+#ifdef CONFIG_ZONE_DMA32
+	/* 4GB maximum for 32-bit only capable devices */
+	max_dma32 = min(max, MAX_DMA32_PFN);
+	zone_size[ZONE_DMA32] = max_dma32 - min;
+#endif

Do you see need of supporting DMA32 on arm64 SOCs ?

[..]

Quoted 60 lines
arch/arm64/mm/mmu.c new file +54 -0
new file mode 100644
index 0000000..d2dd438
@@ -0,0 +1,395 @@
+/*
+ * Based on arch/arm/mm/mmu.c
+ *
+ * Copyright (C) 1995-2005 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see<http://www.gnu.org/licenses/>.
+ */
+
+#include<linux/export.h>
+#include<linux/kernel.h>
+#include<linux/errno.h>
+#include<linux/init.h>
+#include<linux/mman.h>
+#include<linux/nodemask.h>
+#include<linux/memblock.h>
+#include<linux/fs.h>
+
+#include<asm/cputype.h>
+#include<asm/sections.h>
+#include<asm/setup.h>
+#include<asm/sizes.h>
+#include<asm/tlb.h>
+#include<asm/mmu_context.h>
+
+#include "mm.h"
+
+/*
+ * Empty_zero_page is a special page that is used for zero-initialized data
+ * and COW.
+ */
+struct page *empty_zero_page;
+EXPORT_SYMBOL(empty_zero_page);
+
+pgprot_t pgprot_default;
+EXPORT_SYMBOL(pgprot_default);
+
+static pmdval_t prot_sect_kernel;
+
+struct cachepolicy {
+	const char	policy[16];
+	u64		mair;
+	u64		tcr;
+};

arch/arm64/mm/mmu.c line 64

Quoted 10 lines
arch/arm64/mm/mmu.c new file +10 -0
+
+static struct cachepolicy cache_policies[] __initdata = {
+	{
+		.policy		= "uncached",
+		.mair		= 0x44,			/* inner, outer non-cacheable */
+		.tcr		= TCR_IRGN_NC | TCR_ORGN_NC,
+	}, {
+		.policy		= "writethrough",
+		.mair		= 0xaa,			/* inner, outer write-through, read-allocate */
+		.tcr		= TCR_IRGN_WT | TCR_ORGN_WT,

Is WT supported on arm64?
On the recent ARMv7 processors, I think WT wasn't supported.

Regards
Santosh

author maintainer
#61 lore raw

Re: [PATCH v2 09/31] arm64: Cache maintenance routines

In reply to Santosh Shilimkar
Quoted 7 lines · Santosh Shilimkar
Quoted 1 line · Catalin Marinas

+ENTRY(__cpuc_flush_dcache_all)

We have discussed the need of cache maintenance by level kind of API for ARMv7 (A15).

Shouldn't we add such API for arm64 as well ?

Yes, at some point we'll probably add but we'll discuss it again when actually needed. I wouldn't define new API now that's not used by any AArch64 code.

Signature · 1 line
Catalin
#18 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Catalin Marinas
Quoted 45 lines · Catalin Marinas
Quoted 31 lines · Santosh Shilimkar
Quoted 27 lines · Catalin Marinas
Documentation/arm64/booting.txt new file +8 -0
+The boot loader is expected to enter the kernel on each CPU in the
+following manner:
+
+- The primary CPU must jump directly to the first instruction of the
+  kernel image.  The device tree blob passed by this CPU must contain
+  for each CPU node:
+
+    1. An 'enable-method' property. Currently, the only supported

value

Documentation/arm64/booting.txt new file +9 -0
+       for this field is the string "spin-table".
+
+    2. A 'cpu-release-addr' property identifying a 64-bit,
+       zero-initialised memory location.
+
+  It is expected that the bootloader will generate these device tree
+  properties and insert them into the blob prior to kernel entry.
+
+- Any secondary CPUs must spin outside of the kernel in a reserved

area
+ of memory (communicated to the kernel by a /memreserve/ region in the

(quoted diff) +2 -0
+  device tree) polling their cpu-release-addr location, which must be
+  contained in the reserved region.  A wfe instruction may be

inserted

Documentation/arm64/booting.txt new file +3 -0
+  to reduce the overhead of the busy-loop and a sev will be issued by
+  the primary CPU.  When a read of the location pointed to by the
+  cpu-release-addr returns a non-zero value, the CPU must jump
Quoted 2 lines

directly
+ to this value.

Quoted 8 lines

So you expect all the secondary CPUs to be in wakeup state and probably looping in WFE for a signal from kernel to boot. There is one issue with this requirement though. For large CPU system, you need to reset all the CPUs and hit this waiting loop. This will lead to large inrush current need at bootup which may be not be supported. To avoid this issue, secondary CPUs are kept in OFF state and then they are woken up from kernel one by one whenever they need to be brought into the system. This requirement should be considered.

I agree, this part will be extended. That's one method that we currently support and suitable to the model.

Quoted 7 lines

The better method is the SMC standardisation that Charles Garcia-Tobin has written (to be made available soon) and was presented at the last Linaro Connect in HK. Given that the CPU power is usually controlled by the secure side, we'll ask for an SMC to be issued for waking up secondary CPUs, so it's up to the secure firmware to write the correct hardware registers.

Thanks for the information. SMC standardization would indeed help to overcome some of these. Will wait for that information before next set of questions.

Quoted 15 lines
Quoted 15 lines
Quoted 2 lines
arch/arm64/kernel/head.S new file +0 -0

[..]

Quoted 11 lines
arch/arm64/kernel/head.S new file +4 -0
+   /*
+    * DO NOT MODIFY. Image header expected by Linux boot-loaders.
+    */
+   b       stext                           // branch to kernel start,

magic

arch/arm64/kernel/head.S new file +2 -0
+   .long   0                               // reserved
+   .quad   TEXT_OFFSET                     // Image load offset from

start of RAM

arch/arm64/kernel/head.S new file +3 -0
+   .quad   0                               // reserved
+   .quad   0                               // reserved
+
Quoted 5 lines
Quoted 1 line

Minor nit. Avoid C++ commenting style "//" here and rest of the patch.

That's not C++ comment style, it's the *official* assembly comment style for AArch64 ('@' is no longer supported).

Ok. Thanks for clarifying.

Regards
Santosh

#62 lore raw

Re: [PATCH v2 09/31] arm64: Cache maintenance routines

In reply to Catalin Marinas
Quoted 4 lines · Catalin Marinas
Quoted 3 lines · Santosh Shilimkar
Quoted 1 line · Catalin Marinas

+ENTRY(__cpuc_flush_dcache_all)

Quoted 9 lines
Quoted 4 lines

We have discussed the need of cache maintenance by level kind of API for ARMv7 (A15).

Shouldn't we add such API for arm64 as well ?

Yes, at some point we'll probably add but we'll discuss it again when actually needed. I wouldn't define new API now that's not used by any AArch64 code.

The patches are already on the list for ARMv7 and just waiting to merge two approaches.
I agree once it is getting merged for ARMv7 and ARMv8 port can be updated.

Regards
Santosh

author maintainer
#39 lore raw

Re: [PATCH v2 05/31] arm64: MMU initialisation

In reply to Santosh Shilimkar
Quoted 10 lines · Santosh Shilimkar
Quoted 9 lines · Catalin Marinas

This patch contains the initialisation of the memory blocks, MMU attributes and the memory map. Only five memory types are defined:
Device nGnRnE (equivalent to Strongly Ordered), Device nGnRE (classic Device memory), Device GRE, Normal Non-cacheable and Normal Cacheable. Cache policies are supported via the memory attributes register (MAIR_EL1) and only affect the Normal Cacheable mappings.

This patch also adds the SPARSEMEM_VMEMMAP initialisation.

Quoted 7 lines
Quoted 3 lines

---

Whats the difference between Device nGnRE and Device GRE ? Sorry, I haven't gone through the specs yet and hence the question.

G - gathering (multiple reads/writes into one)
R - reordering (reads/writes)
E - early acknowledgement (the write may have not hit the device before
the instruction returns).

The 'n' in front just negates the meaning.

So the Device memory as we know it on ARMv7 is equivalent to nGnRE. The Strongly Ordered is nGnRnE. GRE is pretty much like Normal Non-cacheable memory but with Device mapping, so there are restrictions on unaligned accesses.

Quoted 7 lines

arch/arm64/mm/init.c line 84

Quoted 5 lines
arch/arm64/mm/init.c new file +5 -0
+#ifdef CONFIG_ZONE_DMA32
+	/* 4GB maximum for 32-bit only capable devices */
+	max_dma32 = min(max, MAX_DMA32_PFN);
+	zone_size[ZONE_DMA32] = max_dma32 - min;
+#endif

Do you see need of supporting DMA32 on arm64 SOCs ?

I've got some questions from partners but those devices may just be hidden behind an iommu. For now I left it in.

Quoted 4 lines
Quoted 4 lines
arch/arm64/mm/mmu.c new file +4 -0
+static struct cachepolicy cache_policies[] __initdata = {
+	{
+		.policy		= "uncached",
+		.mair		= 0x44,			/* inner, outer non-cacheable */
Quoted 8 lines

arch/arm64/mm/mmu.c line 64

Quoted 5 lines
arch/arm64/mm/mmu.c new file +5 -0
+		.tcr		= TCR_IRGN_NC | TCR_ORGN_NC,
+	}, {
+		.policy		= "writethrough",
+		.mair		= 0xaa,			/* inner, outer write-through, read-allocate */
+		.tcr		= TCR_IRGN_WT | TCR_ORGN_WT,

Is WT supported on arm64?
On the recent ARMv7 processors, I think WT wasn't supported.

All of WB, WA, WT are just architectural hints. A CPU implementation may or may not ignore them but with Linux we try to follow the architecture rather than specific implementations.

Signature · 1 line
Catalin
#158 lore raw

Re: [PATCH v2 28/31] arm64: Generic timers support

In reply to Catalin Marinas
Quoted 14 lines · Catalin Marinas

From: Marc Zyngier<[email protected]>

This patch adds support for the ARM generic timers with A64 instructions for accessing the timer registers. It uses the physical counter as the clock source and the virtual counter as sched_clock.

The timer frequency can be specified via DT or read from the CNTFRQ_EL0 register. The physical counter is also accessible from user space allowing fast gettimeofday() implementation.

---

[..]

Quoted 5 lines
drivers/clocksource/arm_generic.c new file +0 -0
new file mode 100644
index 0000000..05c898c

[..]

drivers/clocksource/arm_generic.c line 158

Quoted 7 lines
drivers/clocksource/arm_generic.c new file +7 -0
+
+static void __cpuinit arch_timer_setup(struct clock_event_device *clk)
+{
+	/* Let's make sure the timer is off before doing anything else */
+	arch_timer_stop();
+
+	clk->features = CLOCK_EVT_FEAT_ONESHOT;

Are these CPU timers wakeup capable or we need the wakeup capable broadcast timer for low power wakeups ?
In that case C3STOP would be needed here.

Regards
santosh

#40 lore raw

Re: [PATCH v2 05/31] arm64: MMU initialisation

In reply to Catalin Marinas
Quoted 24 lines · Catalin Marinas
Quoted 10 lines · Santosh Shilimkar
Quoted 9 lines · Catalin Marinas

This patch contains the initialisation of the memory blocks, MMU attributes and the memory map. Only five memory types are defined:
Device nGnRnE (equivalent to Strongly Ordered), Device nGnRE (classic Device memory), Device GRE, Normal Non-cacheable and Normal Cacheable. Cache policies are supported via the memory attributes register (MAIR_EL1) and only affect the Normal Cacheable mappings.

This patch also adds the SPARSEMEM_VMEMMAP initialisation.

Quoted 7 lines
Quoted 3 lines

---

Whats the difference between Device nGnRE and Device GRE ? Sorry, I haven't gone through the specs yet and hence the question.

G - gathering (multiple reads/writes into one)
R - reordering (reads/writes)
E - early acknowledgement (the write may have not hit the device before
the instruction returns).

Quoted 7 lines

The 'n' in front just negates the meaning.

So the Device memory as we know it on ARMv7 is equivalent to nGnRE. The Strongly Ordered is nGnRnE. GRE is pretty much like Normal Non-cacheable memory but with Device mapping, so there are restrictions on unaligned accesses.

Thanks for explaining it so clearly.

Quoted 11 lines
Quoted 7 lines

arch/arm64/mm/init.c line 84

Quoted 5 lines
arch/arm64/mm/init.c new file +5 -0
+#ifdef CONFIG_ZONE_DMA32
+   /* 4GB maximum for 32-bit only capable devices */
+   max_dma32 = min(max, MAX_DMA32_PFN);
+   zone_size[ZONE_DMA32] = max_dma32 - min;
+#endif

Do you see need of supporting DMA32 on arm64 SOCs ?

I've got some questions from partners but those devices may just be hidden behind an iommu. For now I left it in.

ok.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
arch/arm64/mm/mmu.c new file +9 -0
+static struct cachepolicy cache_policies[] __initdata = {
+   {
+           .policy         = "uncached",
+           .mair           = 0x44,                 /* inner, outer non-cacheable */
+           .tcr            = TCR_IRGN_NC | TCR_ORGN_NC,
+   }, {
+           .policy         = "writethrough",
+           .mair           = 0xaa,                 /* inner, outer write-through, read-allocate */
+           .tcr            = TCR_IRGN_WT | TCR_ORGN_WT,
Quoted 7 lines
Quoted 2 lines

Is WT supported on arm64?
On the recent ARMv7 processors, I think WT wasn't supported.

All of WB, WA, WT are just architectural hints. A CPU implementation may or may not ignore them but with Linux we try to follow the architecture rather than specific implementations.

Agree.

Regards
Santosh

maintainer
#12 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Nicolas Pitre
Quoted 5 lines · Nicolas Pitre
Quoted 5 lines

+3. Decompress the kernel image
+------------------------------

Documentation/arm64/booting.txt new file +3 -0
+
+Requirement: OPTIONAL
+
Quoted 8 lines

Documentation/arm64/booting.txt line 62

Quoted 4 lines
Documentation/arm64/booting.txt new file +4 -0
+The AArch64 kernel does not provide a decompressor and therefore
+requires gzip decompression to be performed by the boot loader if the
+default Image.gz target is used.  For bootloaders that do not implement
+this requirement, the larger Image target is available instead.

Some people will want to use bzip2 or whatever other decompressor du jour. Maybe this shouldn't be gzip specific, or just presented as a possible option?

Good point. Whether this should be part of this document depends on what assumptions we make about the boot loader getting the image in the first place.

In the strict sense, we are documenting the interface between the boot loader and the kernel here, which already specifies that the kernel must be uncompressed by the time we enter it. If the boot loader wants to add its own encryption or compression methods, or its own headers in front of the binary, the boot protocol isn't really impacted.

That said, I think it's a good idea to also specify what kind of format we want to be used, e.g. a stripped ELF Image compressed with one of gzip/bzip2/lzo/xz and with no other headers added, on a vfat/ext4/btrfs formatted file system. There are probably a lot of other things one might want to specify if we go down this route. Or we could refer to the UEFI spec and mandate that the same format that UEFI uses should be used here independent of what boot loader is used. I think we can still allow other ways to get to the image for deeply embedded systems, e.g. linking the kernel into the boot loader as a blob on tightly constrained systems. For that case, we'd only specify the interface between boot loader and kernel as described above.

Arnd

#19 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Shilimkar, Santosh
Quoted 24 lines · Shilimkar, Santosh
Quoted 15 lines · Catalin Marinas
Quoted 9 lines · Santosh Shilimkar

So you expect all the secondary CPUs to be in wakeup state and probably looping in WFE for a signal from kernel to boot. There is one issue with this requirement though. For large CPU system, you need to reset all the CPUs and hit this waiting loop. This will lead to large inrush current need at bootup which may be not be supported. To avoid this issue, secondary CPUs are kept in OFF state and then they are woken up from kernel one by one whenever they need to be brought into the system. This requirement should be considered.

I agree, this part will be extended. That's one method that we currently support and suitable to the model.

Quoted 7 lines

The better method is the SMC standardisation that Charles Garcia-Tobin has written (to be made available soon) and was presented at the last Linaro Connect in HK. Given that the CPU power is usually controlled by the secure side, we'll ask for an SMC to be issued for waking up secondary CPUs, so it's up to the secure firmware to write the correct hardware registers.

Quoted 3 lines

Thanks for the information. SMC standardization would indeed help to overcome some of these. Will wait for that information before next set of questions.

Yes please. If the SMC is not standardized for most calls at least, we'll end up with a horrible mess of SoC specific calls like we currently have. Related to that, the virtualization calls should be also standardized so we don't end up with multiple different hypervisors with different calls.

Regards,

Tony

author maintainer
#13 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann
Quoted 5 lines · Nicolas Pitre
Quoted 5 lines

+3. Decompress the kernel image
+------------------------------

Documentation/arm64/booting.txt new file +3 -0
+
+Requirement: OPTIONAL
+
Quoted 8 lines

Documentation/arm64/booting.txt line 62

Quoted 4 lines
Documentation/arm64/booting.txt new file +4 -0
+The AArch64 kernel does not provide a decompressor and therefore
+requires gzip decompression to be performed by the boot loader if the
+default Image.gz target is used.  For bootloaders that do not implement
+this requirement, the larger Image target is available instead.

Some people will want to use bzip2 or whatever other decompressor du jour. Maybe this shouldn't be gzip specific, or just presented as a possible option?

Quoted 3 lines

Good point. Whether this should be part of this document depends on what assumptions we make about the boot loader getting the image in the first place.

It ended up here because there is a Makefile target, Image.gz, though I haven't used it at all. I'll expand the text so that it is not restricted to gzip.

Quoted 5 lines

In the strict sense, we are documenting the interface between the boot loader and the kernel here, which already specifies that the kernel must be uncompressed by the time we enter it. If the boot loader wants to add its own encryption or compression methods, or its own headers in front of the binary, the boot protocol isn't really impacted.

Yes.

Quoted 4 lines

That said, I think it's a good idea to also specify what kind of format we want to be used, e.g. a stripped ELF Image compressed with one of gzip/bzip2/lzo/xz and with no other headers added, on a vfat/ext4/btrfs formatted file system. There are probably a

Quoted 8 lines

lot of other things one might want to specify if we go down this route. Or we could refer to the UEFI spec and mandate that the same format that UEFI uses should be used here independent of what boot loader is used. I think we can still allow other ways to get to the image for deeply embedded systems, e.g. linking the kernel into the boot loader as a blob on tightly constrained systems. For that case, we'd only specify the interface between boot loader and kernel as described above.

At least the latter case is used on the model. For the other cases, it's quite early to clearly specify what is needed as we don't currently have a boot-loader other than UEFI. We may expect GRUB as well.

Signature · 1 line
Catalin
author maintainer
#20 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Tony Lindgren
Quoted 29 lines · Tony Lindgren
Quoted 24 lines · Shilimkar, Santosh
Quoted 15 lines · Catalin Marinas
Quoted 9 lines · Santosh Shilimkar

So you expect all the secondary CPUs to be in wakeup state and probably looping in WFE for a signal from kernel to boot. There is one issue with this requirement though. For large CPU system, you need to reset all the CPUs and hit this waiting loop. This will lead to large inrush current need at bootup which may be not be supported. To avoid this issue, secondary CPUs are kept in OFF state and then they are woken up from kernel one by one whenever they need to be brought into the system. This requirement should be considered.

I agree, this part will be extended. That's one method that we currently support and suitable to the model.

Quoted 7 lines

The better method is the SMC standardisation that Charles Garcia-Tobin has written (to be made available soon) and was presented at the last Linaro Connect in HK. Given that the CPU power is usually controlled by the secure side, we'll ask for an SMC to be issued for waking up secondary CPUs, so it's up to the secure firmware to write the correct hardware registers.

Quoted 3 lines

Thanks for the information. SMC standardization would indeed help to overcome some of these. Will wait for that information before next set of questions.

Quoted 5 lines

Yes please. If the SMC is not standardized for most calls at least, we'll end up with a horrible mess of SoC specific calls like we currently have. Related to that, the virtualization calls should be also standardized so we don't end up with multiple different hypervisors with different calls.

For hypervisor, there are two kinds of API - one meant for power management that is pretty much the same as the SMC and another specific to the hypervisor solution (KVM, Xen etc.). The latter is specific to the host kernel that's running as we start it at EL2 but it's not standardised. It would be good indeed and there are other advantages like self-virtualisation but it needs the KVM and Xen guys to come to a common definition.

Signature · 1 line
Catalin
author maintainer
#43 lore raw

Re: [PATCH v2 06/31] arm64: MMU fault handling and page table management

In reply to Arnd Bergmann
Quoted 13 lines · Arnd Bergmann
Quoted 12 lines · Catalin Marinas
arch/arm64/mm/pgd.c new file +12 -0
+pgd_t *pgd_alloc(struct mm_struct *mm)
+{
+	pgd_t *new_pgd;
+
+	new_pgd = (pgd_t *)__get_free_pages(GFP_KERNEL, PGD_ORDER);
+	if (!new_pgd)
+		return NULL;
+
+	memset(new_pgd, 0, PAGE_SIZE << PGD_ORDER);
+
+	return new_pgd;
+}
Quoted 8 lines

arch/arm64/mm/pgd.c line 49

Quoted 5 lines
arch/arm64/mm/pgd.c new file +5 -0
+
+void pgd_free(struct mm_struct *mm, pgd_t *pgd)
+{
+	free_pages((unsigned long)pgd, PGD_ORDER);
+}

According to the documentation, you should only need 8kb for the pgd on a 64kb page system. Is it required that you use up a full page here?

Not with the current virtual memory layout with 39-bit address space for kernel. With 64K pages we can increase the address space to 42-bit while still using 2-level page table, in which case a full page is used.

But for now I'll keep the same virtual memory layout and add a check on (PTRS_PER_PGD * sizeof(pgd_t)), the compiler will choose the right path.

Signature · 1 line
Catalin
author maintainer
#49 lore raw

Re: [PATCH v2 07/31] arm64: Process management

In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

arch/arm64/include/asm/thread_info.h line 28

Quoted 3 lines · Catalin Marinas
arch/arm64/include/asm/thread_info.h new file +3 -0
+#define THREAD_SIZE_ORDER	1
+#define THREAD_SIZE		8192
+#define THREAD_START_SP		(THREAD_SIZE - 16)

THREAD_SIZE_ORDER looks wrong for 64kb-page kernels. It also doesn't seem to be used, so better remove it.

It's used in kernel/fork.c if THREAD_SIZE >= PAGE_SIZE. I'll define it conditionally.

Signature · 1 line
Catalin
#14 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann
Quoted 3 lines · Nicolas Pitre

Some people will want to use bzip2 or whatever other decompressor du jour. Maybe this shouldn't be gzip specific, or just presented as a possible option?

Good point. Whether this should be part of this document depends on what assumptions we make about the boot loader getting the image in the first place.

Quoted 5 lines

In the strict sense, we are documenting the interface between the boot loader and the kernel here, which already specifies that the kernel must be uncompressed by the time we enter it. If the boot loader wants to add its own encryption or compression methods, or its own headers in front of the binary, the boot protocol isn't really impacted.

Right. And someone else will insist on wrapping the kernel into a boot loader specific image format e.g. u-Boot. If all those variations could be kept out of the kernel build that would be a good thing.

That means the kernel should be wrapped/compressed/scrambled at installation time, not at build time. This way the kernel image remains universal and flexibility in its installation is possible.

Quoted 11 lines

That said, I think it's a good idea to also specify what kind of format we want to be used, e.g. a stripped ELF Image compressed with one of gzip/bzip2/lzo/xz and with no other headers added, on a vfat/ext4/btrfs formatted file system. There are probably a lot of other things one might want to specify if we go down this route. Or we could refer to the UEFI spec and mandate that the same format that UEFI uses should be used here independent of what boot loader is used. I think we can still allow other ways to get to the image for deeply embedded systems, e.g. linking the kernel into the boot loader as a blob on tightly constrained systems. For that case, we'd only specify the interface between boot loader and kernel as described above.

I don't think we'll have to concern ourselves with tightly constrained systems that much on ARM64.

Nicolas

#136 lore raw

Re: [PATCH v2 23/31] arm64: Debugging support

In reply to Arnd Bergmann
Quoted 3 lines · Arnd Bergmann

Sorry for the dumb question, but why do you even need PTRACE_GET_THREAD_AREA for 64 bit tasks? I thought the thread pointer is a GPR, or is this just for compat tasks?

The TLS is stored in a co-processor register which is read-only for userspace. However, it's banked, so accessing the TLS of your child (the guy you're ptracing) requires a system call.

Will

#137 lore raw

Re: [PATCH v2 23/31] arm64: Debugging support

Quoted 7 lines · Will Deacon
Quoted 3 lines · Arnd Bergmann

Sorry for the dumb question, but why do you even need PTRACE_GET_THREAD_AREA for 64 bit tasks? I thought the thread pointer is a GPR, or is this just for compat tasks?

The TLS is stored in a co-processor register which is read-only for userspace.

I should elaborate: the register is RW for AArch64 tasks, RO for aarch32 tasks (although that doesn't affect the need for the ptrace request).

Will

#126 lore raw

Re: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

In reply to Catalin Marinas

Hi!

Quoted 10 lines

This patch adds support for 32-bit applications. The vectors page is a binary blob mapped into the application user space at 0xffff0000 (the AArch64 toolchain does not support compilation of AArch32 code). Full compatibility with ARMv7 user space is supported. The use of deprecated ARMv7 functionality (SWP, CP15 barriers) has been disabled by default on AArch64 kernels and unaligned LDM/STM is not supported.

Please note that only the ARM 32-bit EABI is supported, so no OABI compatibility.

arch/arm64/include/asm/compat.h line 118

Quoted 10 lines
arch/arm64/include/asm/compat.h new file +10 -0
+struct compat_statfs {
+	int		f_type;
+	int		f_bsize;
+	int		f_blocks;
+	int		f_bfree;
+	int		f_bavail;
+	int		f_files;
+	int		f_ffree;
+	compat_fsid_t	f_fsid;
+	int		f_namelen;	/* SunOS ignores this field. */

I'm sure it does. But is it good comment?

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author maintainer
#53 lore raw

Re: [PATCH v2 08/31] arm64: CPU support

In reply to Olof Johansson
Quoted 33 lines · Olof Johansson
Quoted 31 lines · Catalin Marinas
arch/arm64/include/asm/cputype.h new file +25 -0
new file mode 100644
index 0000000..ef54125
@@ -0,0 +1,49 @@
+#define ID_MIDR_EL1		"midr_el1"
+#define ID_CTR_EL0		"ctr_el0"
+
+#define ID_AA64PFR0_EL1		"id_aa64pfr0_el1"
+#define ID_AA64DFR0_EL1		"id_aa64dfr0_el1"
+#define ID_AA64AFR0_EL1		"id_aa64afr0_el1"
+#define ID_AA64ISAR0_EL1	"id_aa64isar0_el1"
+#define ID_AA64MMFR0_EL1	"id_aa64mmfr0_el1"
+
+#define read_cpuid(reg) ({						\
+	u64 __val;							\
+	asm("mrs	%0, " reg : "=r" (__val));			\
+	__val;								\
+})
+
+/*
+ * The CPU ID never changes at run time, so we might as well tell the
+ * compiler that it's constant.  Use this function to read the CPU ID
+ * rather than directly reading processor_id or read_cpuid() directly.
+ */
+static inline u32 __attribute_const__ read_cpuid_id(void)
+{
+	return read_cpuid(ID_MIDR_EL1);
+}
+
Quoted 8 lines

arch/arm64/include/asm/cputype.h line 47

Quoted 4 lines
arch/arm64/include/asm/cputype.h new file +4 -0
+static inline u32 __attribute_const__ read_cpuid_cachetype(void)
+{
+	return read_cpuid(ID_CTR_EL0);
+}

Is this perhaps a carry-over from arch/arm? Abstracting out read_cpuid() doesn't seem to buy anything here, just opencode the one-line assembly in each.

It doesn't buy much but it's more readable to use read_cpuid() in places like hw_breakpoint.c than open coding the assembly.

I could get rid of the ID_* macros and just pass the register name direcly to read_cpuid().

Quoted 2 lines

Might as well cleanup the naming a little too while you're at it, i.e. read_cpu_id() and read_cpu_cachetype().

These were defined for convenience, a bit less typing. But they have the intended name.

Quoted 2 lines
Quoted 2 lines
arch/arm64/mm/proc-syms.c new file +0 -0

...

Quoted 8 lines

arch/arm64/mm/proc-syms.c line 31

Quoted 5 lines
arch/arm64/mm/proc-syms.c new file +5 -0
+EXPORT_SYMBOL(__cpuc_flush_kern_all);
+EXPORT_SYMBOL(__cpuc_flush_user_all);
+EXPORT_SYMBOL(__cpuc_flush_user_range);
+EXPORT_SYMBOL(__cpuc_coherent_kern_range);
+EXPORT_SYMBOL(__cpuc_flush_dcache_area);

See comment on other email about putting function pointers in a struct instead.

There is no need to support multiple CPU architectures with different implementations, so allowing these functions to be called without indirection is better.

Quoted 15 lines
Quoted 15 lines
arch/arm64/mm/proc.S new file +9 -0
new file mode 100644
index 0000000..453f517
@@ -0,0 +1,193 @@
+	.section ".proc.info.init", #alloc, #execinstr
+
+	.type	__v8_proc_info, #object
+__v8_proc_info:
+	.long	0x000f0000			// Required ID value
+	.long	0x000f0000			// Mask for ID
+	b	__cpu_setup
+	nop
+	.quad	cpu_name
Quoted 8 lines

arch/arm64/mm/proc.S line 193

Quoted 2 lines
arch/arm64/mm/proc.S new file +2 -0
+	.long	0
+	.size	__v8_proc_info, . - __v8_proc_info

I know this is a carry-over from arch/arm, but how about moving this to more of a C construct similar to arch/powerpc/kernel/cputable.c instead? It's considerably easier to read that way, and it's convenient to have the definitions all in one place, making it easier to share some of the functions, etc.

I can do this, it would be indeed cleaner.

Signature · 1 line
Catalin
author maintainer
#58 lore raw

Re: [PATCH v2 08/31] arm64: CPU support

In reply to Arnd Bergmann
Quoted 3 lines · Arnd Bergmann
Quoted 2 lines · Catalin Marinas
arch/arm64/include/asm/procinfo.h new file +0 -0

...

Quoted 6 lines
Quoted 6 lines
arch/arm64/include/asm/procinfo.h new file +6 -0
+struct proc_info_list {
+	unsigned int		cpu_val;
+	unsigned int		cpu_mask;
+	unsigned long		__cpu_flush;		/* used by head.S */
+	const char		*cpu_name;
+};
Quoted 8 lines

arch/arm64/include/asm/procinfo.h line 44

Quoted 6 lines
arch/arm64/include/asm/procinfo.h new file +6 -0
+
+#else	/* __KERNEL__ */
+#include <asm/elf.h>
+#warning "Please include asm/elf.h instead"
+#endif	/* __KERNEL__ */
+#endif

I think you forgot to remove this file when you removed MULTI_CPU.

proc_info_list() structure is still used just for the CPU name and setup function (e.g. we need to apply errata workaround on a certain CPU). But as Olof suggested, I better move all this to a cputable.c file.

Signature · 1 line
Catalin
maintainer
#138 lore raw

Re: [PATCH v2 23/31] arm64: Debugging support

In reply to Will Deacon
Quoted 11 lines · Will Deacon
Quoted 7 lines · Will Deacon
Quoted 3 lines · Arnd Bergmann

Sorry for the dumb question, but why do you even need PTRACE_GET_THREAD_AREA for 64 bit tasks? I thought the thread pointer is a GPR, or is this just for compat tasks?

The TLS is stored in a co-processor register which is read-only for userspace.

I should elaborate: the register is RW for AArch64 tasks, RO for aarch32 tasks (although that doesn't affect the need for the ptrace request).

So can't you just /add/ that register to the GPR regset?

Arnd

maintainer
#127 lore raw

Re: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

In reply to Pavel Machek
Quoted 21 lines · Pavel Machek
Quoted 10 lines

This patch adds support for 32-bit applications. The vectors page is a binary blob mapped into the application user space at 0xffff0000 (the AArch64 toolchain does not support compilation of AArch32 code). Full compatibility with ARMv7 user space is supported. The use of deprecated ARMv7 functionality (SWP, CP15 barriers) has been disabled by default on AArch64 kernels and unaligned LDM/STM is not supported.

Please note that only the ARM 32-bit EABI is supported, so no OABI compatibility.

arch/arm64/include/asm/compat.h line 118

Quoted 10 lines
arch/arm64/include/asm/compat.h new file +10 -0
+struct compat_statfs {
+     int             f_type;
+     int             f_bsize;
+     int             f_blocks;
+     int             f_bfree;
+     int             f_bavail;
+     int             f_files;
+     int             f_ffree;
+     compat_fsid_t   f_fsid;
+     int             f_namelen;      /* SunOS ignores this field. */
Quoted 1 line

I'm sure it does. But is it good comment?

Good catch. It seems that some of the other compat platforms (x86, sparc, powerpc) have the same thing. I guess the real solution would be to introduce an asm-generic/compat.h file that contains a bunch of those definitions, like

#ifndef compat_timespec

struct compat_timespec {
        compat_time_t   tv_sec;
        s32             tv_nsec;
};

#endif

#ifndef compat_timeval

struct compat_timeval {
        compat_time_t   tv_sec;
        s32             tv_usec;
};

#endif

#ifndef compat_sysctl

struct compat_sysctl {
        unsigned int    name;
        int             nlen;
        unsigned int    oldval;
        unsigned int    oldlenp;
        unsigned int    newval;
        unsigned int    newlen;
        unsigned int    __unused[4];
};

#endif

For the most part, arch/tile should have useful defaults, though not in the case of struct statfs, because its 32 bit version does not have a statfs syscall (it only has statfs64).

Arnd

maintainer
#54 lore raw

Re: [PATCH v2 08/31] arm64: CPU support

In reply to Catalin Marinas
Quoted 12 lines · Catalin Marinas
Quoted 2 lines
Quoted 2 lines
arch/arm64/mm/proc-syms.c new file +0 -0

...

Quoted 8 lines

arch/arm64/mm/proc-syms.c line 31

Quoted 5 lines
arch/arm64/mm/proc-syms.c new file +5 -0
+EXPORT_SYMBOL(__cpuc_flush_kern_all);
+EXPORT_SYMBOL(__cpuc_flush_user_all);
+EXPORT_SYMBOL(__cpuc_flush_user_range);
+EXPORT_SYMBOL(__cpuc_coherent_kern_range);
+EXPORT_SYMBOL(__cpuc_flush_dcache_area);

See comment on other email about putting function pointers in a struct instead.

Quoted 3 lines

There is no need to support multiple CPU architectures with different implementations, so allowing these functions to be called without indirection is better.

What is the __cpuc prefix about then? Could you just drop it?

Arnd

#139 lore raw

Re: [PATCH v2 23/31] arm64: Debugging support

In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann
Quoted 6 lines · Will Deacon
Quoted 5 lines · Will Deacon
Quoted 3 lines · Arnd Bergmann

Sorry for the dumb question, but why do you even need PTRACE_GET_THREAD_AREA for 64 bit tasks? I thought the thread pointer is a GPR, or is this just for compat tasks?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

The TLS is stored in a co-processor register which is read-only for userspace.

I should elaborate: the register is RW for AArch64 tasks, RO for aarch32 tasks (although that doesn't affect the need for the ptrace request).

So can't you just /add/ that register to the GPR regset?

We *could*, but it doesn't feel right to me. The TLS register:

- Can only be manipulated by msr/mrs instructions
- Is not part of the PCS
- Is not accessed explicitly by user applications
- Can not be written via ptrace

so I think it sticks out like a sore thumb if we bundle it up with the GPRs.

Will

author maintainer
#55 lore raw

Re: [PATCH v2 08/31] arm64: CPU support

In reply to Arnd Bergmann
Quoted 13 lines · Arnd Bergmann
Quoted 12 lines · Catalin Marinas
Quoted 2 lines
Quoted 2 lines
arch/arm64/mm/proc-syms.c new file +0 -0

...

Quoted 8 lines

arch/arm64/mm/proc-syms.c line 31

Quoted 5 lines
arch/arm64/mm/proc-syms.c new file +5 -0
+EXPORT_SYMBOL(__cpuc_flush_kern_all);
+EXPORT_SYMBOL(__cpuc_flush_user_all);
+EXPORT_SYMBOL(__cpuc_flush_user_range);
+EXPORT_SYMBOL(__cpuc_coherent_kern_range);
+EXPORT_SYMBOL(__cpuc_flush_dcache_area);

See comment on other email about putting function pointers in a struct instead.

Quoted 5 lines
Quoted 3 lines

There is no need to support multiple CPU architectures with different implementations, so allowing these functions to be called without indirection is better.

What is the __cpuc prefix about then? Could you just drop it?

It can be dropped indeed.

Signature · 1 line
Catalin
#128 lore raw

Re: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

In reply to Arnd Bergmann
Quoted 34 lines · Arnd Bergmann
Quoted 21 lines · Pavel Machek
Quoted 10 lines

This patch adds support for 32-bit applications. The vectors page is a binary blob mapped into the application user space at 0xffff0000 (the AArch64 toolchain does not support compilation of AArch32 code). Full compatibility with ARMv7 user space is supported. The use of deprecated ARMv7 functionality (SWP, CP15 barriers) has been disabled by default on AArch64 kernels and unaligned LDM/STM is not supported.

Please note that only the ARM 32-bit EABI is supported, so no OABI compatibility.

arch/arm64/include/asm/compat.h line 118

Quoted 10 lines
arch/arm64/include/asm/compat.h new file +10 -0
+struct compat_statfs {
+     int             f_type;
+     int             f_bsize;
+     int             f_blocks;
+     int             f_bfree;
+     int             f_bavail;
+     int             f_files;
+     int             f_ffree;
+     compat_fsid_t   f_fsid;
+     int             f_namelen;      /* SunOS ignores this field. */
Quoted 1 line

I'm sure it does. But is it good comment?

Good catch. It seems that some of the other compat platforms (x86, sparc, powerpc) have the same thing. I guess the real solution would be to introduce an asm-generic/compat.h file that contains a bunch of those definitions, like

#ifndef compat_timespec

struct compat_timespec {
        compat_time_t   tv_sec;
        s32             tv_nsec;
};
Quoted 8 lines

#endif

#ifndef compat_timeval

struct compat_timeval {
        compat_time_t   tv_sec;
        s32             tv_usec;
};

#endif

Yes, I guess that would be very good.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author maintainer
#80 lore raw

Re: [PATCH v2 14/31] arm64: DMA mapping API

In reply to Arnd Bergmann
Quoted 19 lines · Arnd Bergmann
Quoted 18 lines · Catalin Marinas
arch/arm64/mm/dma-mapping.c new file +18 -0
+static struct dma_map_ops arm64_swiotlb_dma_ops = {
+       .alloc = arm64_swiotlb_alloc_coherent,
+       .free = arm64_swiotlb_free_coherent,
+       .map_page = arm64_swiotlb_map_page,
+       .unmap_page = arm64_swiotlb_unmap_page,
+       .map_sg = arm64_swiotlb_map_sg_attrs,
+       .unmap_sg = arm64_swiotlb_unmap_sg_attrs,
+       .sync_single_for_cpu = arm64_swiotlb_sync_single_for_cpu,
+       .sync_single_for_device = arm64_swiotlb_sync_single_for_device,
+       .sync_sg_for_cpu = arm64_swiotlb_sync_sg_for_cpu,
+       .sync_sg_for_device = arm64_swiotlb_sync_sg_for_device,
+       .dma_supported = swiotlb_dma_supported,
+       .mapping_error = swiotlb_dma_mapping_error,
+};
+
+void __init swiotlb_init_with_default_size(size_t default_size, int verbose);
+
+void __init arm64_swiotlb_init(size_t max_size)
Quoted 8 lines

arch/arm64/mm/dma-mapping.c line 199

Quoted 4 lines
arch/arm64/mm/dma-mapping.c new file +4 -0
+{
+       dma_ops = &arm64_swiotlb_dma_ops;
+       swiotlb_init_with_default_size(min((size_t)SZ_64M, max_size), 1);
+}

Why is swiotlb the default? I would expect that most devices can in fact use the entire 64 bit address space, so you can use a simple linear implementation for those.

That was my worry, devices not capable of accessing the full 64-bit address space. We can hope that those SoCs would have an IOMMU but I can't tell for sure at this stage.

The default implementation could be simpler. I can even drop it altogether from the initial patchset given that no SoC makes use of it yet.

Signature · 1 line
Catalin
author maintainer
#78 lore raw

Re: [PATCH v2 14/31] arm64: DMA mapping API

In reply to Olof Johansson
Quoted 14 lines · Olof Johansson

arch/arm64/include/asm/dma-mapping.h line 36

Quoted 7 lines · Catalin Marinas
arch/arm64/include/asm/dma-mapping.h new file +7 -0
+static inline struct dma_map_ops *get_dma_ops(struct device *dev)
+{
+	if (unlikely(!dev) || !dev->archdata.dma_ops)
+		return dma_ops;
+	else
+		return dev->archdata.dma_ops;
+}

Does it make sense to add the concept of a global dma ops on arm64, instead of requiring the dma ops pointer per device similar to how some other platforms do it (including powerpc)? For devices that lack archdata.dma_ops, dma_supported() should return 0 (and the other ops should return error).

If the device doesn't have archdata.dma_ops we return the default implementation which is currently based on swiotlb. Do you mean that this shouldn't be the case and just let the device always set archdata.dma_ops?

Signature · 1 line
Catalin
author maintainer
#91 lore raw

Re: [PATCH v2 16/31] arm64: ELF definitions

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · Will Deacon
Quoted 7 lines

This looks wrong: PER_LINUX/PER_LINUX32 decides over the output of the uname system call, while TIF_32BIT decides over the instruction set when returning to user space. You definitely should not set the personality to the value you pass from the elf loader. Instead, just do

#define SET_PERSONALITY(ex) clear_thread_flag(TIF_32BIT); #defined COMPAT_SET_PERSONALITY(ex) set_thread_flag(TIF_32BIT);

Quoted 6 lines
Quoted 2 lines

In this case, won't uname be incorrect (aarch64l) for aarch32 tasks (which expect something like armv8l)?

No, the uname output is meant to tell you about the system, not the instruction set that you are using (you already know that in compiled code).

OK, so we assumed that compat tasks should get a uname as close as possible to a 32-bit system, i.e. armv8l, for full compatibility. This would allow us to run something like 32-bit Debian on an AArch64 kernel without worrying about any scripts failing.

But I can see on x86 that it always reports x86_64 even if the task is x86_32.

Signature · 1 line
Catalin
author maintainer
#99 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

In reply to Arnd Bergmann
Quoted 14 lines · Arnd Bergmann

arch/arm64/include/asm/stat.h line 32

Quoted 9 lines · Catalin Marinas
arch/arm64/include/asm/stat.h new file +9 -0
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ * Note: The kernel zero's the padded region because glibc might read them
+ * in the hope that the kernel has stretched to using larger sizes.
+ */
+struct stat64 {
+	compat_u64	st_dev;
+	unsigned char   __pad0[4];

The comment above struct stat64 is completely irrelevant here. I would instead explain why you need your own stat64 in the first place.

OK, I added a comment. It's only needed for compat.

Quoted 6 lines

arch/arm64/kernel/sys.c line 67

Quoted 3 lines
arch/arm64/kernel/sys.c new file +3 -0
+int kernel_execve(const char *filename,
+		  const char *const argv[],
+		  const char *const envp[])

Al Viro was recently talking about a generic implementation of execve. I can't find that now, but I think you should use that.

I've seen these but I'm waiting for the generic sys_execve and kernel_execve to get into mainline before switch arch/arm64 to them.

Quoted 12 lines

arch/arm64/kernel/sys.c line 116

Quoted 9 lines
arch/arm64/kernel/sys.c new file +9 -0
+asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
+			 unsigned long prot, unsigned long flags,
+			 unsigned long fd, off_t off)
+{
+	if (offset_in_page(off) != 0)
+		return -EINVAL;
+
+	return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+}

I think

Quoted 1 line

#define sys_mmap sys_mmap_pgoff

There are slightly different semantics with the last argument of sys_mmap() which takes a byte offset. The sys_mmap_pgoff() function takes the offset shifted by PAGE_SHIFT (which is the same as sys_mmap2).

Looking at the other architectures, it makes sense to use a generic sys_mmap() implementation similar to the one above (or the ia-64, seems to be the most complete).

Signature · 1 line
Catalin
#92 lore raw

Re: [PATCH v2 16/31] arm64: ELF definitions

In reply to Catalin Marinas
Quoted 2 lines · Catalin Marinas

But I can see on x86 that it always reports x86_64 even if the task is x86_32.

Really?

$ uname -m
x86_64
$ linux32 uname -m
i686
$

On Ubuntu 2.6.32-42-generic

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#93 lore raw

Re: [PATCH v2 16/31] arm64: ELF definitions

Quoted 5 lines · Geert Uytterhoeven
Quoted 2 lines · Catalin Marinas

But I can see on x86 that it always reports x86_64 even if the task is x86_32.

Quoted 7 lines

Really?

$ uname -m
x86_64
$ linux32 uname -m
i686
$

Well, you set the personality explicitly with linux32. What I tested was with an x86_32 uname called directly (without linux32) and even though the ELF was a 32-bit one, it was reporting x86_64. In this AArch64 patch, a compat task was automatically setting the linux32 personality (which x86 does not do).

Arnd's point is that the ELF file should not affect the personality and hence the uname value. This should only be done by an explicit call to sys_personality().

Signature · 1 line
Catalin
#94 lore raw

Re: [PATCH v2 16/31] arm64: ELF definitions

Quoted 13 lines · On Tuesday 21 August 2012 14:27:31 Catalin Marinas wrote:
Quoted 11 lines · Geert Uytterhoeven
Quoted 2 lines · Catalin Marinas

But I can see on x86 that it always reports x86_64 even if the task is x86_32.

Really?

$ uname -m
x86_64
$ linux32 uname -m
i686
$
Quoted 5 lines

Well, you set the personality explicitly with linux32. What I tested was with an x86_32 uname called directly (without linux32) and even though the ELF was a 32-bit one, it was reporting x86_64. In this AArch64 patch, a compat task was automatically setting the linux32 personality (which x86 does not do).

i don't think any arch does this.

$ uname -m
ppc64
$ linux32 uname -m
ppc
$ uname -m
sparc64
$ linux32 uname -m
sparc
$ uname -m
x86_64
$ linux32 uname -m
i686
$ uname -m
s390x
$ linux32 uname -m
s390
Quoted 3 lines

Arnd's point is that the ELF file should not affect the personality and hence the uname value. This should only be done by an explicit call to sys_personality().

correct. if someone really wants to launch their whole userland with the adjusted personality, they could always boot the kernel with:
init=/usr/bin/linux32 /sbin/init
but the kernel shouldn't be doing this automatically.
-mike

#159 lore raw

Re: [PATCH v2 28/31] arm64: Generic timers support

In reply to Catalin Marinas
Quoted 9 lines · Catalin Marinas

From: Marc Zyngier <[email protected]>

This patch adds support for the ARM generic timers with A64 instructions for accessing the timer registers. It uses the physical counter as the clock source and the virtual counter as sched_clock.

The timer frequency can be specified via DT or read from the CNTFRQ_EL0 register. The physical counter is also accessible from user space allowing fast gettimeofday() implementation.

[...]

Quoted 1 line

+++ b/drivers/clocksource/arm_generic.c

[...]

Quoted 5 lines
drivers/clocksource/arm_generic.c new file +5 -0
+static void arch_timer_reg_write(int reg, u32 val)
+{
+	switch (reg) {
+	case ARCH_TIMER_REG_CTRL:
+		asm volatile("msr cntp_ctl_el0,  %0" : : "r" (val));

drivers/clocksource/arm_generic.c line 64

Quoted 10 lines
drivers/clocksource/arm_generic.c new file +10 -0
+		break;
+	case ARCH_TIMER_REG_TVAL:
+		asm volatile("msr cntp_tval_el0, %0" : : "r" (val));
+		break;
+	default:
+		BUG();
+	}
+
+	isb();
+}

Doesn't architecture-specific assembly need to go in the arch directory rather than the drivers directory?

Christopher

Signature · 2 lines
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
maintainer
#100 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

In reply to Catalin Marinas
Quoted 14 lines · Catalin Marinas
Quoted 12 lines

arch/arm64/kernel/sys.c line 116

Quoted 9 lines
arch/arm64/kernel/sys.c new file +9 -0
+asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
+                    unsigned long prot, unsigned long flags,
+                    unsigned long fd, off_t off)
+{
+   if (offset_in_page(off) != 0)
+           return -EINVAL;
+
+   return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+}

I think

Quoted 1 line

#define sys_mmap sys_mmap_pgoff

Quoted 8 lines

There are slightly different semantics with the last argument of sys_mmap() which takes a byte offset. The sys_mmap_pgoff() function takes the offset shifted by PAGE_SHIFT (which is the same as sys_mmap2).

Looking at the other architectures, it makes sense to use a generic sys_mmap() implementation similar to the one above (or the ia-64, seems to be the most complete).

Why that? The generic sys_mmap_pgoff was specifically added so new architectures could just use that instead of having their own wrappers, see f8b72560.

Arnd

maintainer
#95 lore raw

Re: [PATCH v2 16/31] arm64: ELF definitions

In reply to Catalin Marinas
Quoted 13 lines · Catalin Marinas
Quoted 12 lines · Arnd Bergmann
Quoted 10 lines · Will Deacon
Quoted 7 lines

This looks wrong: PER_LINUX/PER_LINUX32 decides over the output of the uname system call, while TIF_32BIT decides over the instruction set when returning to user space. You definitely should not set the personality to the value you pass from the elf loader. Instead, just do

#define SET_PERSONALITY(ex) clear_thread_flag(TIF_32BIT); #defined COMPAT_SET_PERSONALITY(ex) set_thread_flag(TIF_32BIT);

In this case, won't uname be incorrect (aarch64l) for aarch32 tasks (which expect something like armv8l)?

Quoted 8 lines
Quoted 3 lines

No, the uname output is meant to tell you about the system, not the instruction set that you are using (you already know that in compiled code).

OK, so we assumed that compat tasks should get a uname as close as possible to a 32-bit system, i.e. armv8l, for full compatibility. This would allow us to run something like 32-bit Debian on an AArch64 kernel without worrying about any scripts failing.

You can still do that, just boot with init="/sbin/setarch armv7 /sbin/init".

Quoted 2 lines

But I can see on x86 that it always reports x86_64 even if the task is x86_32.

Not just x86, the same behavior is used on powerpc, s390, mips, sparc and parisc. Not sure about tile though.

Arnd

author maintainer
#101 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

In reply to Arnd Bergmann
Quoted 19 lines · Arnd Bergmann
Quoted 18 lines · Catalin Marinas
Quoted 12 lines

arch/arm64/kernel/sys.c line 116

Quoted 9 lines
arch/arm64/kernel/sys.c new file +9 -0
+asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
+                    unsigned long prot, unsigned long flags,
+                    unsigned long fd, off_t off)
+{
+   if (offset_in_page(off) != 0)
+           return -EINVAL;
+
+   return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+}

I think

Quoted 1 line

#define sys_mmap sys_mmap_pgoff

There are slightly different semantics with the last argument of sys_mmap() which takes a byte offset. The sys_mmap_pgoff() function takes the offset shifted by PAGE_SHIFT (which is the same as sys_mmap2).

Quoted 6 lines
Quoted 3 lines

Looking at the other architectures, it makes sense to use a generic sys_mmap() implementation similar to the one above (or the ia-64, seems to be the most complete).

Why that? The generic sys_mmap_pgoff was specifically added so new architectures could just use that instead of having their own wrappers, see f8b72560.

As I understand, sys_mmap_pgoff can be used instead of sys_mmap2 on new 32-bit architectures. But on 64-bit architectures we don't have sys_mmap2, only sys_mmap with the difference that the last argument is the offset in bytes (and multiple of PAGE_SIZE) rather than in pages. So unless we change the meaning of this last argument for sys_mmap, we cannot just define it to sys_mmap_pgoff.

Since the other 64-bit architectures seem to have a sys_mmap wrapper that does this:

	sys_mmap_pgoff(..., off >> PAGE_SHIFT);

I think AArch64 should also use the same sys_mmap convention. We can make this wrapper generic.

Signature · 1 line
Catalin
maintainer
#102 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

Quoted 7 lines · Catalin Marinas

As I understand, sys_mmap_pgoff can be used instead of sys_mmap2 on new 32-bit architectures. But on 64-bit architectures we don't have sys_mmap2, only sys_mmap with the difference that the last argument is the offset in bytes (and multiple of PAGE_SIZE) rather than in pages. So unless we change the meaning of this last argument for sys_mmap, we cannot just define it to sys_mmap_pgoff.

Quoted 7 lines

Since the other 64-bit architectures seem to have a sys_mmap wrapper that does this:

        sys_mmap_pgoff(..., off >> PAGE_SHIFT);

I think AArch64 should also use the same sys_mmap convention. We can make this wrapper generic.

But the wrapper can just as well be part of glibc, which already has one. There is no reason for the kernel to export two generic interfaces for mmap when one of them only works on 64 bit and the other one is good for both 32 and 64 bit.

All the other 64 bit architectures (besides tile) were added to the kernel before we had sys_mmap_pgoff.

Arnd

author maintainer
#103 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

Quoted 13 lines · Arnd Bergmann
Quoted 12 lines · Catalin Marinas

As I understand, sys_mmap_pgoff can be used instead of sys_mmap2 on new 32-bit architectures. But on 64-bit architectures we don't have sys_mmap2, only sys_mmap with the difference that the last argument is the offset in bytes (and multiple of PAGE_SIZE) rather than in pages. So unless we change the meaning of this last argument for sys_mmap, we cannot just define it to sys_mmap_pgoff.

Since the other 64-bit architectures seem to have a sys_mmap wrapper that does this:

        sys_mmap_pgoff(..., off >> PAGE_SHIFT);
Quoted 7 lines
Quoted 2 lines

I think AArch64 should also use the same sys_mmap convention. We can make this wrapper generic.

But the wrapper can just as well be part of glibc, which already has one. There is no reason for the kernel to export two generic interfaces for mmap when one of them only works on 64 bit and the other one is good for both 32 and 64 bit.

The kernel only exports a single interface for 64-bit, that's sys_mmap(). For compat we only export sys_mmap2() (which, of course, would not work for 64-bit).

The generic prototypes for sys_mmap and sys_mmap2 are different with regards to the last argument: off_t vs unsigned long. While in practice it's the same size, off_t is used throughout the kernel as offset in bytes rather than pages (hence the prototype change in sys_mmap2 and sys_mmap_pgoff).

But what's more important - moving this wrapper to glibc causes issues with the page size. We support both 4KB and 64KB pages on 64-bit systems (the latter without compat support). The kernel is in a better position to do the shift by a compile-time constant. Glibc would need to enquire the actual page size to do the shift before calling sys_mmap_pgoff. If we assume in glibc that the shift is always 12, we need another wrapper in the kernel anyway for 64KB page configuration. So passing the offset in bytes worked best for us.

Quoted 2 lines

All the other 64 bit architectures (besides tile) were added to the kernel before we had sys_mmap_pgoff.

So there is no new 64-bit architecture that defines sys_mmap to sys_mmap_pgoff. I don't think that AArch64 should introduce this, given the restrictions I mentioned above. sys_mmap2/sys_mmap_pgoff are a way to extend the file offset beyond 32-bit but that's not needed on a 64-bit system.

Signature · 1 line
Catalin
maintainer
#104 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

Quoted 8 lines · Catalin Marinas

But what's more important - moving this wrapper to glibc causes issues with the page size. We support both 4KB and 64KB pages on 64-bit systems (the latter without compat support). The kernel is in a better position to do the shift by a compile-time constant. Glibc would need to enquire the actual page size to do the shift before calling sys_mmap_pgoff. If we assume in glibc that the shift is always 12, we need another wrapper in the kernel anyway for 64KB page configuration. So passing the offset in bytes worked best for us.

Right, the kernel interface should really be independent of the page size, as sys_mmap2 normally is, and sys_mmap2 is not provided here.

Arnd

author maintainer
#105 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · Catalin Marinas

But what's more important - moving this wrapper to glibc causes issues with the page size. We support both 4KB and 64KB pages on 64-bit systems (the latter without compat support). The kernel is in a better position to do the shift by a compile-time constant. Glibc would need to enquire the actual page size to do the shift before calling sys_mmap_pgoff. If we assume in glibc that the shift is always 12, we need another wrapper in the kernel anyway for 64KB page configuration. So passing the offset in bytes worked best for us.

Quoted 2 lines

Right, the kernel interface should really be independent of the page size, as sys_mmap2 normally is, and sys_mmap2 is not provided here.

sys_mmap2 is indeed independent of the page size on most architectures assuming that the last argument represents the offset in units of 4096. The cris and ia64 seem to differ (one being 8K, the other variable).

sys_mmap is also independent of the page size.

But using sys_mmap2 for a 64-bit architecture, especially when the page size is not always 4K, does not bring any advantages. We end up doing a shift by 12 in glibc and another shift by (PAGE_SHIFT - 12) in the kernel wrapper. Unless I missed your point, I don't see the reason for using sys_mmap2 on a 64-bit architecture, apart from it being newer (and compat support should not have any relevance, we have different syscall tables anyway).

Signature · 1 line
Catalin
maintainer
#121 lore raw

PER_LINUX32, Was: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

In reply to Will Deacon
Quoted 17 lines · Will Deacon
Quoted 16 lines · Arnd Bergmann

arch/arm64/kernel/sys_compat.c line 98

Quoted 12 lines · Catalin Marinas
arch/arm64/kernel/sys_compat.c new file +12 -0
+asmlinkage int compat_sys_personality(compat_ulong_t personality)
+{
+	int ret;
+
+	if (personality(current->personality) == PER_LINUX32 &&
+		personality == PER_LINUX)
+		personality = PER_LINUX32;
+	ret = sys_personality(personality);
+	if (ret == PER_LINUX32)
+		ret = PER_LINUX;
+	return ret;
+}

Where did you get this from?

Quoted 4 lines
Quoted 1 line

You should not need compat_sys_personality, just call the native function.

Hmm, but in that case an aarch32 application doing a personality(PER_LINUX) syscall will start seeing the wrong uname.

Coming back at this topic, I noticed another issue. Jiri Kosina has recently posted patches to fix this function in the other architectures in order to mask out the other personality bits, which is a correct fix, but the above function is odd for other reasons.

* On MIPS, it is used only for compat tasks, like you have it above.
* On PA-RISC, it is used for native 32 bit tasks and for compat 32 bit tasks, but not for native 64 bit ones.
* On IA64, it was used for compat tasks (support for which has since been removed from the kernel), plus all 32 bit tasks would start with PER_LINUX32.
* On PowerPC, Sparc and s390, it is used for native 64 bit tasks and for compat 32 bit tasks, but not for native 32 bit ones.
* On Tile, it was never used.
* On x86_64, it used to be defined (copied from ia64) but not used throughout the git history.

The semantics of the function are also interesting: The intention seems to be that to a compat task, PER_LINUX32 would appear as PER_LINUX. The effect is that any process can set PER_LINUX32 but it can never be unset except by a 64 bit MIPS or PA-RISC task.

Since x86_64 does not implement this behavior at all, I suspect that there are now lots of things depending on not having it, while all the other architectures might also have some (even predating the x86_64 port) use cases that depend on depend on not being able to observe PER_LINUX32 in 32 bit compat tasks.

I think we should try to agree on how this is all supposed to work and use common code, either put the ppc/sparc/s390 version into sys_personality, or remove all of them and just do what x86 and tile do, using the regular sys_personality for all tasks.

Arnd

author maintainer
#122 lore raw

Re: PER_LINUX32, Was: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

Quoted 40 lines · Arnd Bergmann
Quoted 17 lines · Will Deacon
Quoted 16 lines · Arnd Bergmann

arch/arm64/kernel/sys_compat.c line 98

Quoted 12 lines · Catalin Marinas
arch/arm64/kernel/sys_compat.c new file +12 -0
+asmlinkage int compat_sys_personality(compat_ulong_t personality)
+{
+	int ret;
+
+	if (personality(current->personality) == PER_LINUX32 &&
+		personality == PER_LINUX)
+		personality = PER_LINUX32;
+	ret = sys_personality(personality);
+	if (ret == PER_LINUX32)
+		ret = PER_LINUX;
+	return ret;
+}

Where did you get this from?

Quoted 4 lines
Quoted 1 line

You should not need compat_sys_personality, just call the native function.

Hmm, but in that case an aarch32 application doing a personality(PER_LINUX) syscall will start seeing the wrong uname.

Coming back at this topic, I noticed another issue. Jiri Kosina has recently posted patches to fix this function in the other architectures in order to mask out the other personality bits, which is a correct fix, but the above function is odd for other reasons.

* On MIPS, it is used only for compat tasks, like you have it above.
* On PA-RISC, it is used for native 32 bit tasks and for compat 32 bit tasks, but not for native 64 bit ones.
* On IA64, it was used for compat tasks (support for which has since been removed from the kernel), plus all 32 bit tasks would start with PER_LINUX32.
* On PowerPC, Sparc and s390, it is used for native 64 bit tasks and for compat 32 bit tasks, but not for native 32 bit ones.
* On Tile, it was never used.
* On x86_64, it used to be defined (copied from ia64) but not used throughout the git history.

Quoted 4 lines

The semantics of the function are also interesting: The intention seems to be that to a compat task, PER_LINUX32 would appear as PER_LINUX. The effect is that any process can set PER_LINUX32 but it can never be unset except by a 64 bit MIPS or PA-RISC task.

IMHO, it makes sense to keep the compat_sys_personality() as implemented above. You may want to start a chroot ARMv7 environment using "linux32" but don't want some 32-bit app calling personality(PER_LINUX) (as that's the default personality on an ARMv7 system) and unknowingly changing the personality that you wanted to enforce via "linux32".

I agree with not setting the personality based on the ELF type, but that's different from the compat_sys_personality().

Quoted 10 lines

Since x86_64 does not implement this behavior at all, I suspect that there are now lots of things depending on not having it, while all the other architectures might also have some (even predating the x86_64 port) use cases that depend on depend on not being able to observe PER_LINUX32 in 32 bit compat tasks.

I think we should try to agree on how this is all supposed to work and use common code, either put the ppc/sparc/s390 version into sys_personality, or remove all of them and just do what x86 and tile do, using the regular sys_personality for all tasks.

Late topic for the KS :).

I don't think we can move this behaviour to sys_personality. We may want to add a generic compat_sys_personality() if we agree on the above use-case.

Signature · 1 line
Catalin
author maintainer
#21 lore raw

Re: [PATCH v2 02/31] arm64: Kernel booting and initialisation

In reply to Tony Lindgren
Quoted 29 lines · Tony Lindgren
Quoted 24 lines · Shilimkar, Santosh
Quoted 15 lines · Catalin Marinas
Quoted 9 lines · Santosh Shilimkar

So you expect all the secondary CPUs to be in wakeup state and probably looping in WFE for a signal from kernel to boot. There is one issue with this requirement though. For large CPU system, you need to reset all the CPUs and hit this waiting loop. This will lead to large inrush current need at bootup which may be not be supported. To avoid this issue, secondary CPUs are kept in OFF state and then they are woken up from kernel one by one whenever they need to be brought into the system. This requirement should be considered.

I agree, this part will be extended. That's one method that we currently support and suitable to the model.

Quoted 7 lines

The better method is the SMC standardisation that Charles Garcia-Tobin has written (to be made available soon) and was presented at the last Linaro Connect in HK. Given that the CPU power is usually controlled by the secure side, we'll ask for an SMC to be issued for waking up secondary CPUs, so it's up to the secure firmware to write the correct hardware registers.

Quoted 3 lines

Thanks for the information. SMC standardization would indeed help to overcome some of these. Will wait for that information before next set of questions.

Quoted 5 lines

Yes please. If the SMC is not standardized for most calls at least, we'll end up with a horrible mess of SoC specific calls like we currently have. Related to that, the virtualization calls should be also standardized so we don't end up with multiple different hypervisors with different calls.

The Power State Coordination Interface initial proposal has been published here:

http://infocenter.arm.com/help/topic/com.arm.doc.den0022a/index.html

(as with other ARM documents, they are public but free registration required).

Signature · 1 line
Catalin
author maintainer
#124 lore raw

Re: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

In reply to Arnd Bergmann
Quoted 18 lines · Arnd Bergmann
Quoted 16 lines · Catalin Marinas
arch/arm64/include/asm/signal32.h new file +16 -0
+#ifdef CONFIG_AARCH32_EMULATION
+#include <linux/compat.h>
+
+#define AARCH32_KERN_SIGRET_CODE_OFFSET	0x500
+
+extern const compat_ulong_t aarch32_sigret_code[6];
+
+int compat_setup_frame(int usig, struct k_sigaction *ka, sigset_t *set,
+		       struct pt_regs *regs);
+int compat_setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
+			  sigset_t *set, struct pt_regs *regs);
+
+void compat_setup_restart_syscall(struct pt_regs *regs);
+#else
+
+static inline int compat_setup_frame(int usid, struct k_sigaction *ka,
Quoted 8 lines

arch/arm64/include/asm/signal32.h line 39

Quoted 4 lines
arch/arm64/include/asm/signal32.h new file +4 -0
+				     sigset_t *set, struct pt_regs *regs)
+{
+	BUG();
+}

What good is the run-time BUG() here? Nothing should be calling these when CONFIG_COMPAT is disabled, so I think you should just remove the #ifdef around the declarations, and the entire #else case.

They are called from handle_signal(), so that's to avoid #ifdef inside functions. I can drop the BUG() (but keep the empty function) and change the checks to is_compat_task() so that the compiler optimises the condition out when !COMPAT.

Signature · 1 line
Catalin
maintainer
#125 lore raw

Re: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

Quoted 9 lines · Catalin Marinas
Quoted 3 lines

What good is the run-time BUG() here? Nothing should be calling these when CONFIG_COMPAT is disabled, so I think you should just remove the #ifdef around the declarations, and the entire #else case.

They are called from handle_signal(), so that's to avoid #ifdef inside functions. I can drop the BUG() (but keep the empty function) and change the checks to is_compat_task() so that the compiler optimises the condition out when !COMPAT.

Sounds good. Note that you can turn a lot of #ifdef into if(IS_ENABLED(CONFIG_FOO)) as well, even if there is no other runtime check for them.

Arnd

#123 lore raw

Re: PER_LINUX32, Was: [PATCH v2 21/31] arm64: 32-bit (compat) applications support

In reply to Arnd Bergmann
Quoted 15 lines · Arnd Bergmann
Quoted 15 lines
Quoted 15 lines

arch/arm64/kernel/sys_compat.c line 98

Quoted 12 lines
arch/arm64/kernel/sys_compat.c new file +12 -0
+asmlinkage int compat_sys_personality(compat_ulong_t personality)
+{
+	int ret;
+
+	if (personality(current->personality) == PER_LINUX32 &&
+		personality == PER_LINUX)
+		personality = PER_LINUX32;
+	ret = sys_personality(personality);
+	if (ret == PER_LINUX32)
+		ret = PER_LINUX;
+	return ret;
+}

Where did you get this from?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

You should not need compat_sys_personality, just call the native function.

Hmm, but in that case an aarch32 application doing a personality(PER_LINUX) syscall will start seeing the wrong uname.

Coming back at this topic, I noticed another issue. Jiri Kosina has recently posted patches to fix this function in the other architectures

Yeah, there were quite a few broken ones, some of them since the beginning of time.

Quoted 26 lines

in order to mask out the other personality bits, which is a correct fix, but the above function is odd for other reasons.

* On MIPS, it is used only for compat tasks, like you have it above.
* On PA-RISC, it is used for native 32 bit tasks and for compat 32 bit tasks, but not for native 64 bit ones.
* On IA64, it was used for compat tasks (support for which has since been removed from the kernel), plus all 32 bit tasks would start with PER_LINUX32.
* On PowerPC, Sparc and s390, it is used for native 64 bit tasks and for compat 32 bit tasks, but not for native 32 bit ones.
* On Tile, it was never used.
* On x86_64, it used to be defined (copied from ia64) but not used throughout the git history.

The semantics of the function are also interesting: The intention seems to be that to a compat task, PER_LINUX32 would appear as PER_LINUX. The effect is that any process can set PER_LINUX32 but it can never be unset except by a 64 bit MIPS or PA-RISC task.

Since x86_64 does not implement this behavior at all, I suspect that there are now lots of things depending on not having it, while all the other architectures might also have some (even predating the x86_64 port) use cases that depend on depend on not being able to observe PER_LINUX32 in 32 bit compat tasks.

Quoted 4 lines

I think we should try to agree on how this is all supposed to work and use common code, either put the ppc/sparc/s390 version into sys_personality, or remove all of them and just do what x86 and tile do, using the regular sys_personality for all tasks.

How about rather introducing common compat_sys_personality() and switching the archs that are using it to it? Unifying the behavior (PER_LINUX / PER_LINUX32 masquerading) should be painless.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
author maintainer
#106 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

In reply to Catalin Marinas

Hi Arnd,

Quoted 20 lines · Catalin Marinas
Quoted 10 lines · Arnd Bergmann
Quoted 8 lines · Catalin Marinas

But what's more important - moving this wrapper to glibc causes issues with the page size. We support both 4KB and 64KB pages on 64-bit systems (the latter without compat support). The kernel is in a better position to do the shift by a compile-time constant. Glibc would need to enquire the actual page size to do the shift before calling sys_mmap_pgoff. If we assume in glibc that the shift is always 12, we need another wrapper in the kernel anyway for 64KB page configuration. So passing the offset in bytes worked best for us.

Quoted 2 lines

Right, the kernel interface should really be independent of the page size, as sys_mmap2 normally is, and sys_mmap2 is not provided here.

sys_mmap2 is indeed independent of the page size on most architectures assuming that the last argument represents the offset in units of 4096. The cris and ia64 seem to differ (one being 8K, the other variable).

sys_mmap is also independent of the page size.

Quoted 7 lines

But using sys_mmap2 for a 64-bit architecture, especially when the page size is not always 4K, does not bring any advantages. We end up doing a shift by 12 in glibc and another shift by (PAGE_SHIFT - 12) in the kernel wrapper. Unless I missed your point, I don't see the reason for using sys_mmap2 on a 64-bit architecture, apart from it being newer (and compat support should not have any relevance, we have different syscall tables anyway).

I forgot about this at the KS and we haven't got to a clear conclusion.

Do we (1) stick with the sys_mmap() for 64-bit systems and avoid offset conversion in both glibc and kernel or (2) use sys_mmap2() with a 12 shift in glibc and (PAGE_SHIFT - 12) in the kernel wrapper?

I personally prefer (1) as it doesn't require a kernel wrapper and we avoid the double shifting. A reason for (2) would be if we ever need file offsets greater than 16EB.

Signature · 1 line
Catalin
maintainer
#107 lore raw

Re: [PATCH v2 17/31] arm64: System calls handling

Quoted 8 lines · Catalin Marinas

I forgot about this at the KS and we haven't got to a clear conclusion.

Do we (1) stick with the sys_mmap() for 64-bit systems and avoid offset conversion in both glibc and kernel or (2) use sys_mmap2() with a 12 shift in glibc and (PAGE_SHIFT - 12) in the kernel wrapper?

I personally prefer (1) as it doesn't require a kernel wrapper and we avoid the double shifting.

Yes, I think it's ok this way.

Quoted 1 line

A reason for (2) would be if we ever need file offsets greater than 16EB.

Let's not worry about this for now, all the other architectures will have the same problem when we get there.

Arnd

author maintainer
#112 lore raw

Re: [PATCH v2 20/31] arm64: User access library function

In reply to Arnd Bergmann
Quoted 44 lines · Arnd Bergmann
Quoted 42 lines · Catalin Marinas
arch/arm64/include/asm/uaccess.h new file +42 -0
+/*
+ * Single-value transfer routines.  They automatically use the right
+ * size if we just have the right pointer type.  Note that the functions
+ * which read from user space (*get_*) need to take care not to leak
+ * kernel data even if the calling code is buggy and fails to check
+ * the return value.  This means zeroing out the destination variable
+ * or buffer on error.  Normally this is done out of line by the
+ * fixup code, but there are a few places where it intrudes on the
+ * main code path.  When we only write to user space, there is no
+ * problem.
+ */
+extern long __get_user_1(void *);
+extern long __get_user_2(void *);
+extern long __get_user_4(void *);
+extern long __get_user_8(void *);
+
+#define __get_user_x(__r2,__p,__e,__s,__i...)				\
+	   asm volatile(						\
+		__asmeq("%0", "x0") __asmeq("%1", "x2")			\
+		"bl	__get_user_" #__s				\
+		: "=&r" (__e), "=r" (__r2)				\
+		: "0" (__p)						\
+		: __i, "cc")
+
+#define get_user(x,p)							\
+	({								\
+		register const typeof(*(p)) __user *__p asm("x0") = (p);\
+		register unsigned long __r2 asm("x2");			\
+		register long __e asm("x0");				\
+		switch (sizeof(*(__p))) {				\
+		case 1:							\
+			__get_user_x(__r2, __p, __e, 1, "x30");		\
+			break;						\
+		case 2:							\
+			__get_user_x(__r2, __p, __e, 2, "x3", "x30");	\
+			break;						\
+		case 4:							\
+			__get_user_x(__r2, __p, __e, 4, "x30");		\
+			break;						\
+		case 8:							\
+			__get_user_x(__r2, __p, __e, 8, "x30");		\
+			break;						\
Quoted 8 lines

arch/arm64/include/asm/uaccess.h line 155

Quoted 5 lines
arch/arm64/include/asm/uaccess.h new file +5 -0
+		default: __e = __get_user_bad(); break;			\
+		}							\
+		x = (typeof(*(p))) __r2;				\
+		__e;							\
+	})

It's fairly unusual to have out of line get_user/put_user functions. What is the reason for this, other than copying from ARM?

I changed these to inline asm. The only reason which I don't think matters much in this case is a few KB increase in Image size.

Signature · 1 line
Catalin
#113 lore raw

Re: [PATCH v2 20/31] arm64: User access library function

In reply to Arnd Bergmann
Quoted 2 lines · Arnd Bergmann

It's fairly unusual to have out of line get_user/put_user functions. What is the reason for this, other than copying from ARM?

Actually, we never used to out of line on ARM, and then I experimented, and found there was a net benefit - not only in code size but also there appeared to be a performance benefit by out of lining them.

#96 lore raw

Re: [PATCH v2 16/31] arm64: ELF definitions

In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · Catalin Marinas
Quoted 3 lines · Arnd Bergmann

No, the uname output is meant to tell you about the system, not the instruction set that you are using (you already know that in compiled code).

OK, so we assumed that compat tasks should get a uname as close as possible to a 32-bit system, i.e. armv8l, for full compatibility. This would allow us to run something like 32-bit Debian on an AArch64 kernel without worrying about any scripts failing.

Quoted 7 lines

You can still do that, just boot with init="/sbin/setarch armv7 /sbin/init".

Quoted 2 lines

But I can see on x86 that it always reports x86_64 even if the task is x86_32.

Not just x86, the same behavior is used on powerpc, s390, mips, sparc and parisc. Not sure about tile though.

tile also reports "tilegx" regardless of whether the task is 64-bit or 32-bit compat.

Signature · 2 lines
Chris Metcalf, Tilera Corp.
http://www.tilera.com
author maintainer
#114 lore raw

Re: [PATCH v2 20/31] arm64: User access library function

In reply to Russell King - ARM Linux
Quoted 7 lines · Russell King - ARM Linux
Quoted 2 lines · Arnd Bergmann

It's fairly unusual to have out of line get_user/put_user functions. What is the reason for this, other than copying from ARM?

Actually, we never used to out of line on ARM, and then I experimented, and found there was a net benefit - not only in code size but also there appeared to be a performance benefit by out of lining them.

There are indeed a few KB gain in code size but that's probably coming from the exception table since otherwise you just replace a bl with ldrt. It depends on what the compiler does as well, the arm code has some carefully chosen registers when calling the __get_user_x function.

If you do the access_ok inline and the __get_user_x separately, the size increase is even greater (at least in the arm64 case it can get to over 20KB). I think x86 does the access_ok check out of line.

For now I changed the arm64 code to inline as most of the other architectures but I'll revisit this when I get some hardware. Another thing to be optimised is the size of the exception table entry. I use two .quad declarations for the fault address and branch but I guess they could be made relative to PAGE_OFFSET and only use .long (or some prel31).

Signature · 1 line
Catalin
#115 lore raw

Re: [PATCH v2 20/31] arm64: User access library function

Quoted 4 lines · Catalin Marinas

There are indeed a few KB gain in code size but that's probably coming from the exception table since otherwise you just replace a bl with ldrt. It depends on what the compiler does as well, the arm code has some carefully chosen registers when calling the __get_user_x function.

It's more than that - it's not just the ldr but also a zeroing of a temporary register to hold the error code should the instruction fault. So it's not only the exception tables but also an increase in the main path - and that's where you benefit from having it out of line and thereby a hotter i-cache.

Quoted 3 lines

If you do the access_ok inline and the __get_user_x separately, the size increase is even greater (at least in the arm64 case it can get to over 20KB). I think x86 does the access_ok check out of line.

Please talk to Will about get_user() and put_user(). Afterwards you will definitely want to keep them out of line on 64-bit ARM.

author maintainer
#116 lore raw

Re: [PATCH v2 20/31] arm64: User access library function

Quoted 11 lines · Russell King - ARM Linux
Quoted 4 lines · Catalin Marinas

There are indeed a few KB gain in code size but that's probably coming from the exception table since otherwise you just replace a bl with ldrt. It depends on what the compiler does as well, the arm code has some carefully chosen registers when calling the __get_user_x function.

It's more than that - it's not just the ldr but also a zeroing of a temporary register to hold the error code should the instruction fault. So it's not only the exception tables but also an increase in the main path - and that's where you benefit from having it out of line and thereby a hotter i-cache.

On 32-bit we have __get_user() inline and get_user() out of line. What was the history behind this?

Quoted 6 lines
Quoted 3 lines

If you do the access_ok inline and the __get_user_x separately, the size increase is even greater (at least in the arm64 case it can get to over 20KB). I think x86 does the access_ok check out of line.

Please talk to Will about get_user() and put_user(). Afterwards you will definitely want to keep them out of line on 64-bit ARM.

As I said, I already made the change to always inline get_user/put_user with some penalty in the Image size but it makes the code cleaner. I'm not entirely convinced of the performance gain/loss especially on ARMv8 cores with physically tagged caches. There is room for optimisation when I get real silicon.

Signature · 1 line
Catalin
author maintainer
#70 lore raw

Re: [PATCH v2 13/31] arm64: Device specific operations

In reply to Olof Johansson

(revisiting unanswered emails :))

Quoted 13 lines · Olof Johansson

arch/arm64/include/asm/io.h line 122

Quoted 10 lines · Catalin Marinas
arch/arm64/include/asm/io.h new file +10 -0
+/*
+ *  I/O port access primitives.
+ */
+#define IO_SPACE_LIMIT		0xffff
+
+/*
+ * We currently don't have any platform with PCI support, so just leave this
+ * defined to 0 until needed.
+ */
+#define PCI_IOBASE		((void __iomem *)0)

You could just leave out the PCI / I/O code alltogether instead.

I would leave this in as some of the first platforms to appear will have PCIe. At some point we'll add a fixed address where the PCI_IOBASE is mapped.

Signature · 1 line
Catalin
maintainer
#71 lore raw

Re: [PATCH v2 13/31] arm64: Device specific operations

Quoted 17 lines · Catalin Marinas

(revisiting unanswered emails :))

Quoted 13 lines · Olof Johansson

arch/arm64/include/asm/io.h line 122

Quoted 10 lines · Catalin Marinas
arch/arm64/include/asm/io.h new file +10 -0
+/*
+ *  I/O port access primitives.
+ */
+#define IO_SPACE_LIMIT             0xffff
+
+/*
+ * We currently don't have any platform with PCI support, so just leave this
+ * defined to 0 until needed.
+ */
+#define PCI_IOBASE         ((void __iomem *)0)

You could just leave out the PCI / I/O code alltogether instead.

Quoted 4 lines

I would leave this in as some of the first platforms to appear will have PCIe. At some point we'll add a fixed address where the PCI_IOBASE is mapped.

I guess the cleanest way would be to reserve a virtual memory region right away and document it in the file where you describe the memory layout. Then you can fill the value in here.

Arnd