From patchwork Tue Aug 16 21:14:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Drewry X-Patchwork-Id: 1072422 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7GLD0pU002275 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 16 Aug 2011 21:13:22 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QtQwD-0001Wp-1Q; Tue, 16 Aug 2011 21:12:41 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QtQwC-0008Go-6S; Tue, 16 Aug 2011 21:12:40 +0000 Received: from mail-vx0-f177.google.com ([209.85.220.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QtQw7-0008GU-UZ for linux-arm-kernel@lists.infradead.org; Tue, 16 Aug 2011 21:12:37 +0000 Received: by vxj2 with SMTP id 2so373072vxj.36 for ; Tue, 16 Aug 2011 14:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:x-mailer; bh=EwFQvjLgompXCBWW7HgKcsr97bUH3NjMPfMdCNNfymg=; b=MT2nAPtFFOweOMH656x0cZ0HsdUpy06DGW7x1WjO9wihP3vLWvxK6FpuWv4T24obU8 X7xt0oMAuQjPWyrE31u7d4eUenrd99MRcDVZkEsU/m88p7MdCY9WI+btkFD1M+fBFDQs BO/RgaM3vXrJFl3KMEZFUNY4D/w/VYJi9cTGw= Received: by 10.52.76.134 with SMTP id k6mr207642vdw.418.1313529145740; Tue, 16 Aug 2011 14:12:25 -0700 (PDT) Received: from localhost.localdomain (173-164-30-66-Nashville.hfc.comcastbusiness.net [173.164.30.66]) by mx.google.com with ESMTPS id bp11sm303342vcb.24.2011.08.16.14.12.22 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 16 Aug 2011 14:12:23 -0700 (PDT) From: Will Drewry To: linux-kernel@vger.kernel.org Subject: [RFC,PATCH] arch/arm: compute and export NR_syscalls Date: Tue, 16 Aug 2011 16:14:26 -0500 Message-Id: <1313529267-4428-1-git-send-email-wad@chromium.org> X-Mailer: git-send-email 1.7.0.4 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110816_171236_410288_CD4D9E9C X-CRM114-Status: GOOD ( 22.16 ) X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.177 listed in list.dnswl.org] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Mikael Pettersson , Mike Frysinger , Will Drewry , "Eric W. Biederman" , Russell King , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 16 Aug 2011 21:13:22 +0000 (UTC) At present, there is no way to determine, at compile-time, the number of system calls for arm. This change provides NR_syscalls via unistd.h much like other arches. Historically, there hasn't been a need to pull NR_syscalls into unistd.h for ARM. Prior lkml threads indicate as much. However, NR_syscalls is a prerequisite for enabling CONFIG_FTRACE_SYSCALLS on the platform (along with asm/syscall.h population and arch_syscall_addr). This patch is similar to x86-64 in that the system call count is established using the Kbuild assembly generation trick to extract constant values. It adds three files: - arch/arm/kernel/asm-exports.c - arch/arm/kernel/Makefile.exports The C file provides the location to export assembly resident values, like the number of syscalls. The makefile mimics Kbuild for extracting the values from the partially compiled file. Also included are simple fixups to make calls.S safe to #include in asm-exports.c and exporting of asm-exports.h in unistd.h. In particular, this change yields an NR_syscalls value that matches the number of allocated calls via calls.S and not the aligned, padded syscall table size needed for optimal assembly. asm-exports.c is added instead of reusing asm-offsets.c to avoid a variety of collisions (VM_EXEC, DMA_*, etc). It is possible to use the same calls.S mechanism but add NR_syscalls to asm-offsets.c. However, at inclusion time for generated/asm-offsets.h, conflicting defines will need to be #undef'd if !__ASSEMBLY__ since it appears that the purpose of asm-offsets.h is to safely bind C language definitions to assembly and not the reverse. - Is this approach palatable? - Should I resend only when paired with the other ftrace-needed patches? Thanks! Signed-off-by: Will Drewry --- arch/arm/Makefile | 3 +- arch/arm/include/asm/unistd.h | 5 ++++ arch/arm/kernel/Makefile.exports | 42 ++++++++++++++++++++++++++++++++++++++ arch/arm/kernel/asm-exports.c | 36 ++++++++++++++++++++++++++++++++ arch/arm/kernel/calls.S | 2 + 5 files changed, 87 insertions(+), 1 deletions(-) create mode 100644 arch/arm/kernel/Makefile.exports create mode 100644 arch/arm/kernel/asm-exports.c diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 70c424e..62abc9a 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -270,8 +270,9 @@ all: $(KBUILD_IMAGE) boot := arch/arm/boot -archprepare: +archprepare: Kbuild $(Q)$(MAKE) $(build)=arch/arm/tools include/generated/mach-types.h + $(Q)$(MAKE) $(build)=arch/arm/kernel -f $(src)/arch/arm/kernel/Makefile.exports include/generated/asm-exports.h # Convert bzImage to zImage bzImage: zImage diff --git a/arch/arm/include/asm/unistd.h b/arch/arm/include/asm/unistd.h index 2c04ed5..77d4928 100644 --- a/arch/arm/include/asm/unistd.h +++ b/arch/arm/include/asm/unistd.h @@ -481,5 +481,10 @@ #define __IGNORE_fadvise64_64 1 #define __IGNORE_migrate_pages 1 +#if !defined(COMPILER_OFFSETS) && !defined(__ASSEMBLY__) +#include +#define NR_syscalls (__NR_syscall_max + 1) +#endif + #endif /* __KERNEL__ */ #endif /* __ASM_ARM_UNISTD_H */ diff --git a/arch/arm/kernel/Makefile.exports b/arch/arm/kernel/Makefile.exports new file mode 100644 index 0000000..5ec6553 --- /dev/null +++ b/arch/arm/kernel/Makefile.exports @@ -0,0 +1,42 @@ +# +# linux/arch/arm/kernel/Makefile.exports +# +# Copyright (C) 2011 Chromium OS Authors +# +# Generate asm-exports.h based on Kbuild's asm-offsets.h +# + +exports-file := include/generated/asm-exports.h + +# Default sed regexp - multiline due to syntax constraints +define sed-y + "/^->/{s:->#\(.*\):/* \1 */:; \ + s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \ + s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ + s:->::; p;}" +endef + +quiet_cmd_exports = GEN $@ +define cmd_exports + (set -e; \ + echo "#ifndef __ASM_EXPORTS_H__"; \ + echo "#define __ASM_EXPORTS_H__"; \ + echo "/*"; \ + echo " * DO NOT MODIFY."; \ + echo " *"; \ + echo " * This file was generated by arch/arm/tools/Makefile"; \ + echo " *"; \ + echo " */"; \ + echo ""; \ + sed -ne $(sed-y) $<; \ + echo ""; \ + echo "#endif" ) > $@ +endef + +# We use internal kbuild rules to avoid the "is up to date" message from make +$(src)/../asm-exports.s: $(src)/../kernel/asm-exports.c FORCE + $(Q)mkdir -p $(dir $@) + $(call if_changed_dep,cc_s_c) + +$(exports-file): $(src)/../kernel/asm-exports.s Kbuild + $(call cmd,exports) diff --git a/arch/arm/kernel/asm-exports.c b/arch/arm/kernel/asm-exports.c new file mode 100644 index 0000000..a2aec12 --- /dev/null +++ b/arch/arm/kernel/asm-exports.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2011 Chromium OS Authors + * + * Generate definitions needed by C language modules from data resident + * in assembly language modules. Nothing exported here should be supplied + * by any C language headers in common use. + * + * This code generates raw asm output which is post-processed to extract + * and format the required data. + * + * 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. + */ +#define COMPILE_OFFSETS +#include + +/* + * Make sure that the compiler and target are compatible. + */ +#if defined(__APCS_26__) +#error Sorry, your compiler targets APCS-26 but this kernel requires APCS-32 +#endif + +#define CALL(x) 1 + +#define syscalls_counted +#define NO_PAD_SYSCALLS 1 +static const long syscall_count = + #include "calls.S" + 0; + +int main(void) +{ + DEFINE(__NR_syscall_max, syscall_count - 1); + return 0; +} diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S index 80f7896..02cdece 100644 --- a/arch/arm/kernel/calls.S +++ b/arch/arm/kernel/calls.S @@ -385,6 +385,7 @@ CALL(sys_syncfs) CALL(sys_sendmmsg) /* 375 */ CALL(sys_setns) +#ifndef NO_PAD_SYSCALLS #ifndef syscalls_counted .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls #define syscalls_counted @@ -392,3 +393,4 @@ .rept syscalls_padding CALL(sys_ni_syscall) .endr +#endif