[PATCH] mcs_spin_lock() is inline, but comment says it isn't

2014-03-16 Thread Palmer Dabbelt
I was reading the mcs_spinlock code today and I noticed a comment that
didn't appear to match the code.  This appears to have just been an
oversight during some restructuring of the mcs_spinlock code where
this function was made inline but the comment wasn't updated.

Signed-off-by: Palmer Dabbelt pal...@dabbelt.com
---
 kernel/locking/mcs_spinlock.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
index a2dbac4..f4e94af 100644
--- a/kernel/locking/mcs_spinlock.h
+++ b/kernel/locking/mcs_spinlock.h
@@ -56,9 +56,6 @@ do {  
\
  * If the lock has already been acquired, then this will proceed to spin
  * on this node-locked until the previous lock holder sets the node-locked
  * in mcs_spin_unlock().
- *
- * We don't inline mcs_spin_lock() so that perf can correctly account for the
- * time spent in this lock function.
  */
 static inline
 void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/3] Change all uses of JOBCTL_* from int to long

2015-04-30 Thread Palmer Dabbelt
c56fb6564dcd (Fix a misaligned load inside ptrace_attach()) makes
jobctl an unsigned long.  It makes sense to have the masks applied
to it match that type.  This is currently just a cosmetic change, but
it will prevent the mask from being unexpectedly truncated if we ever
end up with masks with more bits.

One instance of signr is an int, but I left this alone because the
mask ensures that it will never overflow.

Reviewed-by: Chris Metcalf cmetc...@ezchip.com
Signed-off-by: Palmer Dabbelt pal...@dabbelt.com
---
 include/linux/sched.h | 18 +-
 kernel/signal.c   |  6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 391827db0a2d..9251155bf27f 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2077,22 +2077,22 @@ TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab)
 #define JOBCTL_TRAPPING_BIT21  /* switching to TRACED */
 #define JOBCTL_LISTENING_BIT   22  /* ptracer is listening for events */
 
-#define JOBCTL_STOP_DEQUEUED   (1  JOBCTL_STOP_DEQUEUED_BIT)
-#define JOBCTL_STOP_PENDING(1  JOBCTL_STOP_PENDING_BIT)
-#define JOBCTL_STOP_CONSUME(1  JOBCTL_STOP_CONSUME_BIT)
-#define JOBCTL_TRAP_STOP   (1  JOBCTL_TRAP_STOP_BIT)
-#define JOBCTL_TRAP_NOTIFY (1  JOBCTL_TRAP_NOTIFY_BIT)
-#define JOBCTL_TRAPPING(1  JOBCTL_TRAPPING_BIT)
-#define JOBCTL_LISTENING   (1  JOBCTL_LISTENING_BIT)
+#define JOBCTL_STOP_DEQUEUED   (1UL  JOBCTL_STOP_DEQUEUED_BIT)
+#define JOBCTL_STOP_PENDING(1UL  JOBCTL_STOP_PENDING_BIT)
+#define JOBCTL_STOP_CONSUME(1UL  JOBCTL_STOP_CONSUME_BIT)
+#define JOBCTL_TRAP_STOP   (1UL  JOBCTL_TRAP_STOP_BIT)
+#define JOBCTL_TRAP_NOTIFY (1UL  JOBCTL_TRAP_NOTIFY_BIT)
+#define JOBCTL_TRAPPING(1UL  JOBCTL_TRAPPING_BIT)
+#define JOBCTL_LISTENING   (1UL  JOBCTL_LISTENING_BIT)
 
 #define JOBCTL_TRAP_MASK   (JOBCTL_TRAP_STOP | JOBCTL_TRAP_NOTIFY)
 #define JOBCTL_PENDING_MASK(JOBCTL_STOP_PENDING | JOBCTL_TRAP_MASK)
 
 extern bool task_set_jobctl_pending(struct task_struct *task,
-   unsigned int mask);
+   unsigned long mask);
 extern void task_clear_jobctl_trapping(struct task_struct *task);
 extern void task_clear_jobctl_pending(struct task_struct *task,
- unsigned int mask);
+ unsigned long mask);
 
 static inline void rcu_copy_process(struct task_struct *p)
 {
diff --git a/kernel/signal.c b/kernel/signal.c
index d51c5ddd855c..f19833b5db3c 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -245,7 +245,7 @@ static inline void print_dropped_signal(int sig)
  * RETURNS:
  * %true if @mask is set, %false if made noop because @task was dying.
  */
-bool task_set_jobctl_pending(struct task_struct *task, unsigned int mask)
+bool task_set_jobctl_pending(struct task_struct *task, unsigned long mask)
 {
BUG_ON(mask  ~(JOBCTL_PENDING_MASK | JOBCTL_STOP_CONSUME |
JOBCTL_STOP_SIGMASK | JOBCTL_TRAPPING));
@@ -297,7 +297,7 @@ void task_clear_jobctl_trapping(struct task_struct *task)
  * CONTEXT:
  * Must be called with @task-sighand-siglock held.
  */
-void task_clear_jobctl_pending(struct task_struct *task, unsigned int mask)
+void task_clear_jobctl_pending(struct task_struct *task, unsigned long mask)
 {
BUG_ON(mask  ~JOBCTL_PENDING_MASK);
 
@@ -2000,7 +2000,7 @@ static bool do_signal_stop(int signr)
struct signal_struct *sig = current-signal;
 
if (!(current-jobctl  JOBCTL_STOP_PENDING)) {
-   unsigned int gstop = JOBCTL_STOP_PENDING | JOBCTL_STOP_CONSUME;
+   unsigned long gstop = JOBCTL_STOP_PENDING | JOBCTL_STOP_CONSUME;
struct task_struct *t;
 
/* signr will be recorded in task-jobctl for retries */
-- 
2.0.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/3] Fix a misaligned load inside ptrace_attach()

2015-04-30 Thread Palmer Dabbelt
The misaligned load exception arises when running ptrace_attach() on
the RISC-V (which hasn't been upstreamed yet).  The problem is that
wait_on_bit() takes a void* but then proceeds to call test_bit(),
which takes a long*.  This allows an int-aligned pointer to be passed
to test_bit(), which promptly fails.  This will manifest on any other
asm-generic port where unaligned loads trap, where sizeof(long) 
sizeof(int), and where task_struct.jobctl ends up not being
long-aligned.

This patch changes task_struct.jobctl to be a long, which ensures it
has the correct alignment.

Reviewed-by: Chris Metcalf cmetc...@ezchip.com
Signed-off-by: Palmer Dabbelt pal...@dabbelt.com
---
 include/linux/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 26a2e6122734..391827db0a2d 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1369,7 +1369,7 @@ struct task_struct {
int exit_state;
int exit_code, exit_signal;
int pdeath_signal;  /*  The signal sent when the parent dies  */
-   unsigned int jobctl;/* JOBCTL_*, siglock protected */
+   unsigned long jobctl;   /* JOBCTL_*, siglock protected */
 
/* Used for emulating ABI behavior of previous Linux versions */
unsigned int personality;
-- 
2.0.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3] Change wait_on_bit*() to take an unsigned long*, not a void*

2015-04-30 Thread Palmer Dabbelt
The implementations of wait_on_bit*() will only work with long-aligned
memory on systems that don't support misaligned loads and stores.
This patch changes the function prototypes to ensure that the compiler
will enforce alignment.

Running

  make defconfig
  make KFLAGS=-Werror

seems to indicate that, as of c56fb6564dcd (Fix a misaligned load
inside ptrace_attach()), there are now no users of non-long-aligned
calls to wait_on_bit*().  I additionally tried a few make randconfig
attempts, none of which failed to compile for this reason.

Reviewed-by: Chris Metcalf cmetc...@ezchip.com
Signed-off-by: Palmer Dabbelt pal...@dabbelt.com
---
 include/linux/wait.h | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/include/linux/wait.h b/include/linux/wait.h
index 2db83349865b..d69ac4ecc88b 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -969,7 +969,7 @@ extern int bit_wait_io_timeout(struct wait_bit_key *);
  * on that signal.
  */
 static inline int
-wait_on_bit(void *word, int bit, unsigned mode)
+wait_on_bit(unsigned long *word, int bit, unsigned mode)
 {
might_sleep();
if (!test_bit(bit, word))
@@ -994,7 +994,7 @@ wait_on_bit(void *word, int bit, unsigned mode)
  * on that signal.
  */
 static inline int
-wait_on_bit_io(void *word, int bit, unsigned mode)
+wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
 {
might_sleep();
if (!test_bit(bit, word))
@@ -1020,7 +1020,8 @@ wait_on_bit_io(void *word, int bit, unsigned mode)
  * received a signal and the mode permitted wakeup on that signal.
  */
 static inline int
-wait_on_bit_timeout(void *word, int bit, unsigned mode, unsigned long timeout)
+wait_on_bit_timeout(unsigned long *word, int bit, unsigned mode,
+   unsigned long timeout)
 {
might_sleep();
if (!test_bit(bit, word))
@@ -1047,7 +1048,8 @@ wait_on_bit_timeout(void *word, int bit, unsigned mode, 
unsigned long timeout)
  * on that signal.
  */
 static inline int
-wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned 
mode)
+wait_on_bit_action(unsigned long *word, int bit, wait_bit_action_f *action,
+  unsigned mode)
 {
might_sleep();
if (!test_bit(bit, word))
@@ -1075,7 +1077,7 @@ wait_on_bit_action(void *word, int bit, wait_bit_action_f 
*action, unsigned mode
  * the @mode allows that signal to wake the process.
  */
 static inline int
-wait_on_bit_lock(void *word, int bit, unsigned mode)
+wait_on_bit_lock(unsigned long *word, int bit, unsigned mode)
 {
might_sleep();
if (!test_and_set_bit(bit, word))
@@ -1099,7 +1101,7 @@ wait_on_bit_lock(void *word, int bit, unsigned mode)
  * the @mode allows that signal to wake the process.
  */
 static inline int
-wait_on_bit_lock_io(void *word, int bit, unsigned mode)
+wait_on_bit_lock_io(unsigned long *word, int bit, unsigned mode)
 {
might_sleep();
if (!test_and_set_bit(bit, word))
@@ -1125,7 +1127,8 @@ wait_on_bit_lock_io(void *word, int bit, unsigned mode)
  * the @mode allows that signal to wake the process.
  */
 static inline int
-wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, 
unsigned mode)
+wait_on_bit_lock_action(unsigned long *word, int bit, wait_bit_action_f 
*action,
+   unsigned mode)
 {
might_sleep();
if (!test_and_set_bit(bit, word))
-- 
2.0.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/3] Fix a misaligned load inside ptrace_attach()

2015-04-30 Thread Palmer Dabbelt
I ran across what I believe is a bug in some asm-generic code while
working on the RISC-V Linux port.  Essentially the problem is that
wait_on_bit() takes a void *, but then perfroms long-aligned
operation.  As far as I can tell, this bug could manifest on any other
architecture that doesn't support misaligned operations and uses this
particular asm-generic implementation.

The patch set is split into three parts:

* #1 fixes the bug by making task_struct.jobctl an unsigned long,
   which ensures wait_on_bit() always ends up with a long-aligned
   argument.

* #2 changes the prototype of wait_on_bit() and friends to take a
   unsigned long * instead of a void *, with the intent of
   ensuring these problems don't happen again.

* #3 is a bit more intrusive: it goes and changes all uses of
   task_struct.jobctl from int to long.

I'm not sure if #3 has gone too far, but I think #1 and #2 are sane.
The cost is making task_struct larger on machines where
sizeof(long)sizeof(int), but since it's so big already this isn't too
much cost.  I thought about making test_bit() perform byte-aligned
accesses to avoid this cost, but since there are very similar looking
atomic functions I thought that would be too odd.

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5] Remove #ifdef CONFIG_* from all userspace headers

2015-11-09 Thread Palmer Dabbelt
I think this should _actually_ be ready to go this time, the buildbot found
some errors in arches that I didn't test for.

Changes since v4 (<1446579994-9937-1-git-send-email-pal...@dabbelt.com>)

 * #9 was changed to work on arm by moving the enum to an in-kernel header
   file.

 * #13 was added, this fixes a problem on blackfin.

Changes since v3 (<1442271047-4908-1-git-send-email-pal...@dabbelt.com>)

 * #4 is very different: rather than defining a canonical value for
   MAP_UNINITIALIZED, it just punts on the problem and lets arch maintainers
   deal with it.  There's still an #ifndef MAP_UNINITIALIZED in there, but that
   shouldn't get triggered by anything because the arch headers should set it
   to whatever they actually want.

 * #11 defines MAX_RAW_MINORS to 2^20 instead of 2^16.

 * #13 moves the variable around a bit so it gets initialized.  I forgot I was
   in perl and not C :).

Changes since v2 (<1441832902-28993-1-git-send-email-pal...@dabbelt.com>)

 * Patch set renamed.

 * #2 is rewritten to use sys_ni.c instead of an #ifdef

 * #3, #6, #8, #9, #10, and #11 no longer use "#ifdef __KERNEL__" but
   have instead moved the offending lines to the correct, kernel-only
   files.

 * #4 has been rewritten to always define MAP_UNINITIALIZED to
   non-zero, rather than defining it to zero when in userspace.

 * #5 got a whole lot longer -- rather than just always hiding these
   fields from userspace, there is now a second "struct
   elf_fdpic_prstatus" structure.  This should allow userspace to
   parse core dumps correctly.

 * Rebased onto 9c488de24f7264f08d341024bffdd637b4d04c96.

Changes since v1 (<1441152610-22566-1-git-send-email-pal...@dabbelt.com>)

 * All patches but #1 were added.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 04/14] Always expose MAP_UNINITIALIZED to userspace

2015-11-09 Thread Palmer Dabbelt
This used to be hidden behind CONFIG_MMAP_ALLOW_UNINITIALIZED, so
userspace wouldn't actually ever see it be non-zero.  While I had
originally hoped to avoid hiding it, it looks like this conflicts with
MAP_HUGE_SHIFT so I think it's safer to just keep this 0.

Architectures that want to define this can still override it.  In
fact, the Xtensa port already overrides it in a very similar manner to
the previously broken one (but due to lots of conflicting opinions on
how to solve this correctly, I'm just taking the easy way out and
letting their arch maintainers deal with it -- sorry).

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/mman-common.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/uapi/asm-generic/mman-common.h 
b/include/uapi/asm-generic/mman-common.h
index a74dd84..25ca92c 100644
--- a/include/uapi/asm-generic/mman-common.h
+++ b/include/uapi/asm-generic/mman-common.h
@@ -19,9 +19,7 @@
 #define MAP_TYPE   0x0f/* Mask for type of mapping */
 #define MAP_FIXED  0x10/* Interpret addr exactly */
 #define MAP_ANONYMOUS  0x20/* don't use a file */
-#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
-# define MAP_UNINITIALIZED 0x400   /* For anonymous mmap, memory could be 
uninitialized */
-#else
+#ifndef MAP_UNINITIALIZED
 # define MAP_UNINITIALIZED 0x0 /* Don't support this flag */
 #endif
 
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 13/14] Hide CONFIG_PHY_RAM_BASE_ADDRESS from userspace

2015-11-09 Thread Palmer Dabbelt
This feels a bit odd, but I couldn't really come up with a better way to
do it.  There already appears to be a workaround for this macro not
being defined in userspace, so I figured I'd better leave that in place,
since someone is probably using it.

The result is that unless you include  before
 then you'll get the wrong offsets.  The only
user of  is currently , so it's
at least safe for now.  There's a CPP error in there to check for this.
---
 arch/blackfin/include/asm/fixed_code.h  |  6 +
 arch/blackfin/include/uapi/asm/fixed_code.h | 35 -
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/arch/blackfin/include/asm/fixed_code.h 
b/arch/blackfin/include/asm/fixed_code.h
index bc330f0..7e03b9b 100644
--- a/arch/blackfin/include/asm/fixed_code.h
+++ b/arch/blackfin/include/asm/fixed_code.h
@@ -9,6 +9,12 @@
 #ifndef __BFIN_ASM_FIXED_CODE_H__
 #define __BFIN_ASM_FIXED_CODE_H__
 
+#ifdef CONFIG_PHY_RAM_BASE_ADDRESS
+#define CONFIG_PHY_RAM_BASE_ADDRESS 0x0
+#endif
+
+#define PHY_RAM_BASE_ADDRESS CONFIG_PHY_RAM_BASE_ADDRESS
+
 #include 
 
 #ifndef __ASSEMBLY__
diff --git a/arch/blackfin/include/uapi/asm/fixed_code.h 
b/arch/blackfin/include/uapi/asm/fixed_code.h
index 3bef1dc..50b70a0 100644
--- a/arch/blackfin/include/uapi/asm/fixed_code.h
+++ b/arch/blackfin/include/uapi/asm/fixed_code.h
@@ -10,29 +10,32 @@
 #ifndef _UAPI__BFIN_ASM_FIXED_CODE_H__
 #define _UAPI__BFIN_ASM_FIXED_CODE_H__
 
-
-#ifndef CONFIG_PHY_RAM_BASE_ADDRESS
-#define CONFIG_PHY_RAM_BASE_ADDRESS0x0
+#ifndef PHY_RAM_BASE_ADDRESS
+#ifdef __KERNEL__
+#error "Don't include , include "
+#else
+#define PHY_RAM_BASE_ADDRESS   0x0
+#endif
 #endif
 
-#define FIXED_CODE_START   (CONFIG_PHY_RAM_BASE_ADDRESS + 0x400)
+#define FIXED_CODE_START   (PHY_RAM_BASE_ADDRESS + 0x400)
 
-#define SIGRETURN_STUB (CONFIG_PHY_RAM_BASE_ADDRESS + 0x400)
+#define SIGRETURN_STUB (PHY_RAM_BASE_ADDRESS + 0x400)
 
-#define ATOMIC_SEQS_START  (CONFIG_PHY_RAM_BASE_ADDRESS + 0x410)
+#define ATOMIC_SEQS_START  (PHY_RAM_BASE_ADDRESS + 0x410)
 
-#define ATOMIC_XCHG32  (CONFIG_PHY_RAM_BASE_ADDRESS + 0x410)
-#define ATOMIC_CAS32   (CONFIG_PHY_RAM_BASE_ADDRESS + 0x420)
-#define ATOMIC_ADD32   (CONFIG_PHY_RAM_BASE_ADDRESS + 0x430)
-#define ATOMIC_SUB32   (CONFIG_PHY_RAM_BASE_ADDRESS + 0x440)
-#define ATOMIC_IOR32   (CONFIG_PHY_RAM_BASE_ADDRESS + 0x450)
-#define ATOMIC_AND32   (CONFIG_PHY_RAM_BASE_ADDRESS + 0x460)
-#define ATOMIC_XOR32   (CONFIG_PHY_RAM_BASE_ADDRESS + 0x470)
+#define ATOMIC_XCHG32  (PHY_RAM_BASE_ADDRESS + 0x410)
+#define ATOMIC_CAS32   (PHY_RAM_BASE_ADDRESS + 0x420)
+#define ATOMIC_ADD32   (PHY_RAM_BASE_ADDRESS + 0x430)
+#define ATOMIC_SUB32   (PHY_RAM_BASE_ADDRESS + 0x440)
+#define ATOMIC_IOR32   (PHY_RAM_BASE_ADDRESS + 0x450)
+#define ATOMIC_AND32   (PHY_RAM_BASE_ADDRESS + 0x460)
+#define ATOMIC_XOR32   (PHY_RAM_BASE_ADDRESS + 0x470)
 
-#define ATOMIC_SEQS_END(CONFIG_PHY_RAM_BASE_ADDRESS + 0x480)
+#define ATOMIC_SEQS_END(PHY_RAM_BASE_ADDRESS + 0x480)
 
-#define SAFE_USER_INSTRUCTION   (CONFIG_PHY_RAM_BASE_ADDRESS + 0x480)
+#define SAFE_USER_INSTRUCTION   (PHY_RAM_BASE_ADDRESS + 0x480)
 
-#define FIXED_CODE_END (CONFIG_PHY_RAM_BASE_ADDRESS + 0x490)
+#define FIXED_CODE_END (PHY_RAM_BASE_ADDRESS + 0x490)
 
 #endif /* _UAPI__BFIN_ASM_FIXED_CODE_H__ */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 12/14] Remove AT_VECTOR_SIZE_ARCH on x86

2015-11-09 Thread Palmer Dabbelt
It looks like there aren't actually users of this macro anywhere:

 * The kernel doesn't use it on x86 because we don't suppor ELF FDPIC.

 * The only Google results point to LMKL patches, both the one that
   wrote this (from 2010) and my patch to hide it behind __KERNEL__.

 * I grep'd through all the source tarballs on my machine, and the
   only packages that matched were the kernel and crui (which copied a
   PPC kernel header).

Since I'm not sure how to actually provide the right answer (if I
understand correctly, CONFIG_IA32_EMULATION is not __i386__), the only
thing I can think of to do is to just remove the definition.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 arch/x86/include/uapi/asm/auxvec.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/arch/x86/include/uapi/asm/auxvec.h 
b/arch/x86/include/uapi/asm/auxvec.h
index 77203ac..1316b4c 100644
--- a/arch/x86/include/uapi/asm/auxvec.h
+++ b/arch/x86/include/uapi/asm/auxvec.h
@@ -9,11 +9,4 @@
 #endif
 #define AT_SYSINFO_EHDR33
 
-/* entries in ARCH_DLINFO: */
-#if defined(CONFIG_IA32_EMULATION) || !defined(CONFIG_X86_64)
-# define AT_VECTOR_SIZE_ARCH 2
-#else /* else it's non-compat x86-64 */
-# define AT_VECTOR_SIZE_ARCH 1
-#endif
-
 #endif /* _ASM_X86_AUXVEC_H */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 06/14] Move ep_take_care_of_epollwakeup() to fs/eventpoll.c

2015-11-09 Thread Palmer Dabbelt
This doesn't make any sense to expose to userspace, so it's been moved
to the one user.  This was introduced by commit 95f19f658ce1 ("epoll:
drop EPOLLWAKEUP if PM_SLEEP is disabled").

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 fs/eventpoll.c | 13 +
 include/uapi/linux/eventpoll.h | 12 
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 1e009ca..aadee3d 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1812,6 +1812,19 @@ SYSCALL_DEFINE1(epoll_create, int, size)
return sys_epoll_create1(0);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
+{
+   if ((epev->events & EPOLLWAKEUP) && !capable(CAP_BLOCK_SUSPEND))
+   epev->events &= ~EPOLLWAKEUP;
+}
+#else
+static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
+{
+   epev->events &= ~EPOLLWAKEUP;
+}
+#endif
+
 /*
  * The following function implements the controller interface for
  * the eventpoll file that enables the insertion/removal/change of
diff --git a/include/uapi/linux/eventpoll.h b/include/uapi/linux/eventpoll.h
index bc81fb2..7850373 100644
--- a/include/uapi/linux/eventpoll.h
+++ b/include/uapi/linux/eventpoll.h
@@ -61,16 +61,4 @@ struct epoll_event {
__u64 data;
 } EPOLL_PACKED;
 
-#ifdef CONFIG_PM_SLEEP
-static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
-{
-   if ((epev->events & EPOLLWAKEUP) && !capable(CAP_BLOCK_SUSPEND))
-   epev->events &= ~EPOLLWAKEUP;
-}
-#else
-static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
-{
-   epev->events &= ~EPOLLWAKEUP;
-}
-#endif
 #endif /* _UAPI_LINUX_EVENTPOLL_H */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 11/14] Always define MAX_RAW_MINORS as 2**20 in userspace

2015-11-09 Thread Palmer Dabbelt
While I don't think this was ever meant to be exposed to userspace, if
anyone is using it then this will at least provide a correct (if
unlikely) definition.

MAX_RAW_MINORS used to be used in the kernel, where it's been replaced
with CONFIG_MAX_RAW_MINORS.

Note that there's a checkpatch.pl warning about a split config string
here, but I've left that alone.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 drivers/char/raw.c   | 7 ---
 include/uapi/linux/raw.h | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 60316fb..2a69117 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -36,7 +36,7 @@ static struct raw_device_data *raw_devices;
 static DEFINE_MUTEX(raw_mutex);
 static const struct file_operations raw_ctl_fops; /* forward declaration */
 
-static int max_raw_minors = MAX_RAW_MINORS;
+static int max_raw_minors = CONFIG_MAX_RAW_DEVS;
 
 module_param(max_raw_minors, int, 0);
 MODULE_PARM_DESC(max_raw_minors, "Maximum number of raw devices (1-65536)");
@@ -317,8 +317,9 @@ static int __init raw_init(void)
 
if (max_raw_minors < 1 || max_raw_minors > 65536) {
printk(KERN_WARNING "raw: invalid max_raw_minors (must be"
-   " between 1 and 65536), using %d\n", MAX_RAW_MINORS);
-   max_raw_minors = MAX_RAW_MINORS;
+   " between 1 and 65536), using %d\n",
+  max_raw_minors);
+   max_raw_minors = 65536;
}
 
raw_devices = vzalloc(sizeof(struct raw_device_data) * max_raw_minors);
diff --git a/include/uapi/linux/raw.h b/include/uapi/linux/raw.h
index 62d543e..f3d009b 100644
--- a/include/uapi/linux/raw.h
+++ b/include/uapi/linux/raw.h
@@ -13,6 +13,6 @@ struct raw_config_request
__u64   block_minor;
 };
 
-#define MAX_RAW_MINORS CONFIG_MAX_RAW_DEVS
+#define MAX_RAW_MINORS (1 << 20)
 
 #endif /* __LINUX_RAW_H */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 09/14] Move bp_type_idx to include/linux/hw_breakpoint.h

2015-11-09 Thread Palmer Dabbelt
This has a "#ifdef CONFIG_*" that used to be exposed to userspace.

The names in here are so generic that I don't think it's a good idea
to expose them to userspace (or even the rest of the kernel).  There are
multiple in-kernel users, so it's been moved to a kernel header file.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/linux/hw_breakpoint.h  | 10 ++
 include/uapi/linux/hw_breakpoint.h | 10 --
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h
index 0464c85..dfe0376 100644
--- a/include/linux/hw_breakpoint.h
+++ b/include/linux/hw_breakpoint.h
@@ -6,6 +6,16 @@
 
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
 
+enum bp_type_idx {
+   TYPE_INST   = 0,
+#if defined(CONFIG_HAVE_MIXED_BREAKPOINTS_REGS)
+   TYPE_DATA   = 0,
+#else
+   TYPE_DATA   = 1,
+#endif
+   TYPE_MAX
+};
+
 extern int __init init_hw_breakpoint(void);
 
 static inline void hw_breakpoint_init(struct perf_event_attr *attr)
diff --git a/include/uapi/linux/hw_breakpoint.h 
b/include/uapi/linux/hw_breakpoint.h
index b04000a..7a6a5a7 100644
--- a/include/uapi/linux/hw_breakpoint.h
+++ b/include/uapi/linux/hw_breakpoint.h
@@ -17,14 +17,4 @@ enum {
HW_BREAKPOINT_INVALID   = HW_BREAKPOINT_RW | HW_BREAKPOINT_X,
 };
 
-enum bp_type_idx {
-   TYPE_INST   = 0,
-#ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
-   TYPE_DATA   = 0,
-#else
-   TYPE_DATA   = 1,
-#endif
-   TYPE_MAX
-};
-
 #endif /* _UAPI_LINUX_HW_BREAKPOINT_H */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/14] Use sys_ni.c instead of #ifdef to disable fork on CONFIG_NOMMU

2015-11-09 Thread Palmer Dabbelt
I think this change actually doesn't do anything: __NR_fork was still
being defined either way, and on my machine fork() in  comes
from libc.

This just moves to the standard mechanism for defining syscalls that
aren't implemented instead, which has the side-effect of no longer
having an #ifdef CONFIG_* in a user-visible header.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/unistd.h | 4 
 kernel/sys_ni.c   | 1 +
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/include/uapi/asm-generic/unistd.h 
b/include/uapi/asm-generic/unistd.h
index 1324b02..9a95912 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -871,11 +871,7 @@ __SYSCALL(__NR_uselib, sys_uselib)
 __SYSCALL(__NR__sysctl, sys_sysctl)
 
 #define __NR_fork 1079
-#ifdef CONFIG_MMU
 __SYSCALL(__NR_fork, sys_fork)
-#else
-__SYSCALL(__NR_fork, sys_ni_syscall)
-#endif /* CONFIG_MMU */
 
 #undef __NR_syscalls
 #define __NR_syscalls (__NR_fork+1)
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 0623787..e251b30 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -174,6 +174,7 @@ cond_syscall(sys_setfsuid);
 cond_syscall(sys_setfsgid);
 cond_syscall(sys_capget);
 cond_syscall(sys_capset);
+cond_syscall(sys_fork);
 
 /* arch-specific weak syscall entries */
 cond_syscall(sys_pciconfig_read);
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 14/14] Re-enable and clean up "check_config()" in headers_check.pl

2015-11-09 Thread Palmer Dabbelt
I recently got bit by a CONFIG_ in userspace bug.  This has apparently
happened before, but the check got disabled for triggering too much.
In order to reduce false positives, I added some hueristics to avoid
detecting comments.

Since these tests all pass, I've now re-enabled them.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 scripts/headers_check.pl | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/scripts/headers_check.pl b/scripts/headers_check.pl
index 62320f9..1634b51 100755
--- a/scripts/headers_check.pl
+++ b/scripts/headers_check.pl
@@ -27,6 +27,7 @@ my $ret = 0;
 my $line;
 my $lineno = 0;
 my $filename;
+my $check_config_in_multiline_comment = 0;
 
 foreach my $file (@files) {
$filename = $file;
@@ -40,7 +41,7 @@ foreach my $file (@files) {
_asm_types();
_sizetypes();
_declarations();
-   # Dropped for now. Too much noise _config();
+   _config();
}
close $fh;
 }
@@ -78,7 +79,21 @@ sub check_declarations
 
 sub check_config
 {
-   if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
+   my $nocomments = $line;
+   $nocomments =~ s/\/\*.*\*\///; # Remove ANSI-style comments (/* to */)
+   $nocomments =~ s/\/\/.*//; # Remove C99-style comments (// to EOL)
+
+   # Check to see if we're within a multiline comment, and if so
+   # just remove the whole line.  I tried matching on '^ * ', but
+   # there's one header that doesn't prepend multi-line comments
+   # with * so that won't work.
+   if ($nocomments =~ m/\/\*/) { $check_config_in_multiline_comment = 1; }
+   if ($nocomments =~ m/\*\//) { $check_config_in_multiline_comment = 0; }
+   if ($check_config_in_multiline_comment == 1) { $nocomments = "" }
+
+   # Check to see if there is something that looks like CONFIG_
+   # inside a userspace-accessible header file and if so, print that out.
+   if ($nocomments =~ 
m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace 
where it is not valid\n";
}
 }
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/14] Move MAX_SHARED_LIBS to fs/binfmt_flat.c

2015-11-09 Thread Palmer Dabbelt
I'm not sure what this is, but it doesn't feel like something that
should be exposed to userspace here.  I'm assuming this file was
exposed for the structure in it, which doesn't depend on
MAX_SHARED_LIBS.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 fs/binfmt_flat.c  | 6 ++
 include/uapi/linux/flat.h | 6 --
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index f723cd3..e89fb43 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -72,6 +72,12 @@
 #define RELOC_FAILED 0xff00ff01/* Relocation incorrect 
somewhere */
 #define UNLOADED_LIB 0x7ff000ff/* Placeholder for unused 
library */
 
+#ifdef CONFIG_BINFMT_SHARED_FLAT
+#defineMAX_SHARED_LIBS (4)
+#else
+#defineMAX_SHARED_LIBS (1)
+#endif
+
 struct lib_info {
struct {
unsigned long start_code;   /* Start of text 
segment */
diff --git a/include/uapi/linux/flat.h b/include/uapi/linux/flat.h
index 88cd6ba..1b177c7 100644
--- a/include/uapi/linux/flat.h
+++ b/include/uapi/linux/flat.h
@@ -13,12 +13,6 @@
 
 #defineFLAT_VERSION0x0004L
 
-#ifdef CONFIG_BINFMT_SHARED_FLAT
-#defineMAX_SHARED_LIBS (4)
-#else
-#defineMAX_SHARED_LIBS (1)
-#endif
-
 /*
  * To make everything easier to port and manage cross platform
  * development,  all fields are in network byte order.
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/14] Make FB_BACKLIGHT_{LEVELS,MAX} always visible

2015-11-09 Thread Palmer Dabbelt
Nothing else in the kernel defines this, and this header is visible to
userspace.  Rather than hiding it in an #ifdef, I think it's sane to
just make this visible to userspace.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/fb.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/uapi/linux/fb.h b/include/uapi/linux/fb.h
index fb795c3..8926f13 100644
--- a/include/uapi/linux/fb.h
+++ b/include/uapi/linux/fb.h
@@ -392,11 +392,8 @@ struct fb_cursor {
struct fb_image image;  /* Cursor image */
 };
 
-#ifdef CONFIG_FB_BACKLIGHT
 /* Settings for the generic backlight code */
 #define FB_BACKLIGHT_LEVELS128
 #define FB_BACKLIGHT_MAX   0xFF
-#endif
-
 
 #endif /* _UAPI_LINUX_FB_H */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/14] Move USE_WCACHING to drivers/block/pktcdvd.c

2015-11-09 Thread Palmer Dabbelt
I don't think this was ever intended to be exposed to userspace, but
it did require an "#ifdef CONFIG_*".  Since the name is kind of
generic and was only used in one place, I've moved the definition to
the one user.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 drivers/block/pktcdvd.c  | 11 +++
 include/uapi/linux/pktcdvd.h | 11 ---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 2f477d4..55f0df3 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -90,6 +90,17 @@ do { 
\
 
 #define MAX_SPEED 0x
 
+/*
+ * use drive write caching -- we need deferred error handling to be
+ * able to successfully recover with this option (drive will return good
+ * status as soon as the cdb is validated).
+ */
+#if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
+#define USE_WCACHING   1
+#else
+#define USE_WCACHING   0
+#endif
+
 static DEFINE_MUTEX(pktcdvd_mutex);
 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
 static struct proc_dir_entry *pkt_proc;
diff --git a/include/uapi/linux/pktcdvd.h b/include/uapi/linux/pktcdvd.h
index 2640b9d..05c2bee 100644
--- a/include/uapi/linux/pktcdvd.h
+++ b/include/uapi/linux/pktcdvd.h
@@ -29,17 +29,6 @@
 #define PACKET_WAIT_TIME   (HZ * 5 / 1000)
 
 /*
- * use drive write caching -- we need deferred error handling to be
- * able to successfully recover with this option (drive will return good
- * status as soon as the cdb is validated).
- */
-#if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
-#define USE_WCACHING   1
-#else
-#define USE_WCACHING   0
-#endif
-
-/*
  * No user-servicable parts beyond this point ->
  */
 
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 01/14] Remove #ifdef CONFIG_64BIT from all asm-generic/fcntl.h

2015-11-09 Thread Palmer Dabbelt
When working on the RISC-V port I noticed that F_SETLK64 was being
defined on our 64-bit platform, despite our port being so new that
we've only ever had the 64-bit file ops.  Since there's not compat
layer for these, this causes fcntl to bail out.

It turns out that one of the ways in with F_SETLK64 was being defined
(there's some more in glibc, but that's a whole different story... :))
is the result of CONFIG_64BIT showing up in this user-visible header.
 confirms this isn't sane, so I replaced it
with a __BITS_PER_LONG check.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
Reviewed-by: Arnd Bergmann <a...@arndb.de>
---
 include/uapi/asm-generic/fcntl.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h
index e063eff..14a5c82 100644
--- a/include/uapi/asm-generic/fcntl.h
+++ b/include/uapi/asm-generic/fcntl.h
@@ -1,6 +1,7 @@
 #ifndef _ASM_GENERIC_FCNTL_H
 #define _ASM_GENERIC_FCNTL_H
 
+#include 
 #include 
 
 /*
@@ -115,7 +116,7 @@
 #define F_GETSIG   11  /* for sockets. */
 #endif
 
-#ifndef CONFIG_64BIT
+#if (__BITS_PER_LONG == 32)
 #ifndef F_GETLK64
 #define F_GETLK64  12  /*  using 'struct flock64' */
 #define F_SETLK64  13
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/14] Split FDPIC "struct elf_prstatus" to "struct elf_fdpic_prstatus"

2015-11-09 Thread Palmer Dabbelt
This is a pretty big change that I haven't tested any, which worries
me a lot.  The general idea here is that "struct elf_prstatus" can be
visible to userspace (from )

  "
   Generic ptrace interface that exports the architecture specific
   regsets using the corresponding NT_* types (which are also used in
   the core dump).  Please note that the NT_PRSTATUS note type in a
   core dump contains a full 'struct elf_prstatus'. But the
   user_regset for NT_PRSTATUS contains just the elf_gregset_t that is
   the pr_reg field of 'struct elf_prstatus'. For all the other
   user_regset flavors, the user_regset layout and the ELF core dump
   note payload are exactly the same layout.
  "

so it shouldn't have an "#ifdef CONFIG_" in there.

This splits the structure into two different structures, one still
named "struct elf_prstatus", and one for ELF FDPIC that is named
"struct elf_fdpic_prstatus" -- the idea here is that most users are
standard ELF, so that's the name that didn't change.

I tried to fix all the users of "struct elf_prstatus" that should now
be using "struct elf_fdpic_prstatus".  The only testing I did here was
to build a Blackfin defconfig with "struct elf_prstatus" not defined,
and to build an x86 defconfig with "struct elf_fdpic_prstatus" not
defined.

Note that this fails checkpatch.pl with a complaint about wanting open
braces on the same line as struct definitions.  The existing struct
definitions in this file have the brace a line afterwards, so I'm
going to leave this alone.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 fs/binfmt_elf_fdpic.c|  6 +++---
 fs/proc/kcore.c  | 16 
 include/linux/kexec.h|  4 
 include/uapi/linux/elfcore.h | 37 +++--
 kernel/kexec_core.c  |  4 
 5 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index d3634bf..587bf04 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -1323,7 +1323,7 @@ static inline void fill_note(struct memelfnote *note, 
const char *name, int type
  * fill up all the fields in prstatus from the given task struct, except
  * registers which need to be filled up separately.
  */
-static void fill_prstatus(struct elf_prstatus *prstatus,
+static void fill_prstatus(struct elf_fdpic_prstatus *prstatus,
  struct task_struct *p, long signr)
 {
prstatus->pr_info.si_signo = prstatus->pr_cursig = signr;
@@ -1406,7 +1406,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, 
struct task_struct *p,
 struct elf_thread_status
 {
struct list_head list;
-   struct elf_prstatus prstatus;   /* NT_PRSTATUS */
+   struct elf_fdpic_prstatus prstatus; /* NT_PRSTATUS */
elf_fpregset_t fpu; /* NT_PRFPREG */
struct task_struct *thread;
 #ifdef ELF_CORE_COPY_XFPREGS
@@ -1539,7 +1539,7 @@ static int elf_fdpic_core_dump(struct coredump_params 
*cprm)
loff_t offset = 0, dataoff;
int numnote;
struct memelfnote *notes = NULL;
-   struct elf_prstatus *prstatus = NULL;   /* NT_PRSTATUS */
+   struct elf_fdpic_prstatus *prstatus = NULL; /* NT_PRSTATUS */
struct elf_prpsinfo *psinfo = NULL; /* NT_PRPSINFO */
LIST_HEAD(thread_list);
struct list_head *t;
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 92e6726..b1edd77e 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -90,7 +90,11 @@ static size_t get_kcore_size(int *nphdr, size_t *elf_buflen)
(*nphdr + 2)*sizeof(struct elf_phdr) + 
3 * ((sizeof(struct elf_note)) +
 roundup(sizeof(CORE_STR), 4)) +
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+   roundup(sizeof(struct elf_fdpic_prstatus), 4) +
+#else
roundup(sizeof(struct elf_prstatus), 4) +
+#endif
roundup(sizeof(struct elf_prpsinfo), 4) +
roundup(arch_task_struct_size, 4);
*elf_buflen = PAGE_ALIGN(*elf_buflen);
@@ -318,7 +322,11 @@ static char *storenote(struct memelfnote *men, char *bufp)
  */
 static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
 {
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+   struct elf_fdpic_prstatus prstatus; /* NT_PRSTATUS */
+#else
struct elf_prstatus prstatus;   /* NT_PRSTATUS */
+#endif
struct elf_prpsinfo prpsinfo;   /* NT_PRPSINFO */
struct elf_phdr *nhdr, *phdr;
struct elfhdr *elf;
@@ -387,10 +395,18 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, 
int dataoff)
/* set up the process status */
notes[0].name = CORE_STR;
notes[0].type = NT_PRSTATUS;
+#ifdef CONFIG_BIN

[PATCH 03/14] Move COMPAT_ATM_ADDPARTY to net/atm/svc.c

2015-11-09 Thread Palmer Dabbelt
This used to be behind an #ifdef COMPAT_COMPAT, so most of userspace
wouldn't have seen the definition before.  Unfortunately this header
file became visible to userspace, so the definition has instead been
moved to net/atm/svc.c (the only user).

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/atmdev.h | 4 
 net/atm/svc.c   | 5 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/atmdev.h b/include/uapi/linux/atmdev.h
index 93e0ec0..3dcec70 100644
--- a/include/uapi/linux/atmdev.h
+++ b/include/uapi/linux/atmdev.h
@@ -100,10 +100,6 @@ struct atm_dev_stats {
/* use backend to make new if */
 #define ATM_ADDPARTY   _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
/* add party to p2mp call */
-#ifdef CONFIG_COMPAT
-/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
-#define COMPAT_ATM_ADDPARTY_IOW('a', ATMIOC_SPECIAL+4,struct 
compat_atm_iobuf)
-#endif
 #define ATM_DROPPARTY  _IOW('a', ATMIOC_SPECIAL+5,int)
/* drop party from p2mp call */
 
diff --git a/net/atm/svc.c b/net/atm/svc.c
index 3fa0a9e..9e2e6ef 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -27,6 +27,11 @@
 #include "signaling.h"
 #include "addr.h"
 
+#ifdef CONFIG_COMPAT
+/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
+#define COMPAT_ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4, struct 
compat_atm_iobuf)
+#endif
+
 static int svc_create(struct net *net, struct socket *sock, int protocol,
  int kern);
 
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 09/13] Move bp_type_idx to kernel/event/hw_breakpoint.c

2015-11-06 Thread Palmer Dabbelt
On Wed, 04 Nov 2015 04:21:51 PST (-0800), pet...@infradead.org wrote:
> On Wed, Nov 04, 2015 at 12:41:06PM +0100, Peter Zijlstra wrote:
>> On Tue, Nov 03, 2015 at 11:46:30AM -0800, Palmer Dabbelt wrote:
>> > This has a "#ifdef CONFIG_*" that used to be exposed to userspace.
>> >
>> > The names in here are so generic that I don't think it's a good idea
>> > to expose them to userspace (or even the rest of the kernel).  Since
>> > there's only one kernel user, it's been moved to that file.
>> >
>> > Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
>> > Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
>> > Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
>>
>> Assuming you want to keep all these patches together in a tree or so.
>> Let me know if you want me to take this patch.

Well, the plan was to try to get the whole patch set all upstream together.
I'd prefer that, because it'll be easier to make sure everything gets in before
the last checker patch.  Since it touches so many different places I'd be OK
with doing it peicemeal.

I'm kind of new to this whole process: do you think someone is likely to take
this patch set all together?

>> Acked-by: Peter Zijlstra (Intel) <pet...@infradead.org>
>
> Ah, build-bot finds your change is broken and you didn't grep right. It
> is used in more places.

Sorry about that, I must have mis-grep'd.  I guess that's what the build-bot is
for :).

> How about moving it to include/linux/hw_breakpoint.h, instead of having
> it in the uapi crud?

Yep, that makes sense.

I'm going to re-submit a v5 of this patch set, since there was also a missing
patch for blackfin that the buildbot found.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4] Remove #ifdef CONFIG_* from all userspace headers

2015-11-03 Thread Palmer Dabbelt
I think this is good to go.  There are two acks, but I wasn't sure if I was
supposed to collect them in the patches or not.  Arnd Bergman acked #1 and #7.

Changes since v3 (<1442271047-4908-1-git-send-email-pal...@dabbelt.com>)

 * #4 is very different: rather than defining a canonical value for
   MAP_UNINITIALIZED, it just punts on the problem and lets arch maintainers
   deal with it.  There's still an #ifndef MAP_UNINITIALIZED in there, but that
   shouldn't get triggered by anything because the arch headers should set it
   to whatever they actually want.

 * #11 defines MAX_RAW_MINORS to 2^20 instead of 2^16.

 * #13 moves the variable around a bit so it gets initialized.  I forgot I was
   in perl and not C :).

Changes since v2 (<1441832902-28993-1-git-send-email-pal...@dabbelt.com>)

 * Patch set renamed.

 * #2 is rewritten to use sys_ni.c instead of an #ifdef

 * #3, #6, #8, #9, #10, and #11 no longer use "#ifdef __KERNEL__" but
   have instead moved the offending lines to the correct, kernel-only
   files.

 * #4 has been rewritten to always define MAP_UNINITIALIZED to
   non-zero, rather than defining it to zero when in userspace.

 * #5 got a whole lot longer -- rather than just always hiding these
   fields from userspace, there is now a second "struct
   elf_fdpic_prstatus" structure.  This should allow userspace to
   parse core dumps correctly.

 * Rebased onto 9c488de24f7264f08d341024bffdd637b4d04c96.

Changes since v1 (<1441152610-22566-1-git-send-email-pal...@dabbelt.com>)

 * All patches but #1 were added.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 13/13] Re-enable and clean up "check_config()" in headers_check.pl

2015-11-03 Thread Palmer Dabbelt
I recently got bit by a CONFIG_ in userspace bug.  This has apparently
happened before, but the check got disabled for triggering too much.
In order to reduce false positives, I added some hueristics to avoid
detecting comments.

Since these tests all pass, I've now re-enabled them.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 scripts/headers_check.pl | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/scripts/headers_check.pl b/scripts/headers_check.pl
index 62320f9..1634b51 100755
--- a/scripts/headers_check.pl
+++ b/scripts/headers_check.pl
@@ -27,6 +27,7 @@ my $ret = 0;
 my $line;
 my $lineno = 0;
 my $filename;
+my $check_config_in_multiline_comment = 0;
 
 foreach my $file (@files) {
$filename = $file;
@@ -40,7 +41,7 @@ foreach my $file (@files) {
_asm_types();
_sizetypes();
_declarations();
-   # Dropped for now. Too much noise _config();
+   _config();
}
close $fh;
 }
@@ -78,7 +79,21 @@ sub check_declarations
 
 sub check_config
 {
-   if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
+   my $nocomments = $line;
+   $nocomments =~ s/\/\*.*\*\///; # Remove ANSI-style comments (/* to */)
+   $nocomments =~ s/\/\/.*//; # Remove C99-style comments (// to EOL)
+
+   # Check to see if we're within a multiline comment, and if so
+   # just remove the whole line.  I tried matching on '^ * ', but
+   # there's one header that doesn't prepend multi-line comments
+   # with * so that won't work.
+   if ($nocomments =~ m/\/\*/) { $check_config_in_multiline_comment = 1; }
+   if ($nocomments =~ m/\*\//) { $check_config_in_multiline_comment = 0; }
+   if ($check_config_in_multiline_comment == 1) { $nocomments = "" }
+
+   # Check to see if there is something that looks like CONFIG_
+   # inside a userspace-accessible header file and if so, print that out.
+   if ($nocomments =~ 
m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace 
where it is not valid\n";
}
 }
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/13] Make FB_BACKLIGHT_{LEVELS,MAX} always visible

2015-11-03 Thread Palmer Dabbelt
Nothing else in the kernel defines this, and this header is visible to
userspace.  Rather than hiding it in an #ifdef, I think it's sane to
just make this visible to userspace.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/fb.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/uapi/linux/fb.h b/include/uapi/linux/fb.h
index fb795c3..8926f13 100644
--- a/include/uapi/linux/fb.h
+++ b/include/uapi/linux/fb.h
@@ -392,11 +392,8 @@ struct fb_cursor {
struct fb_image image;  /* Cursor image */
 };
 
-#ifdef CONFIG_FB_BACKLIGHT
 /* Settings for the generic backlight code */
 #define FB_BACKLIGHT_LEVELS128
 #define FB_BACKLIGHT_MAX   0xFF
-#endif
-
 
 #endif /* _UAPI_LINUX_FB_H */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 09/13] Move bp_type_idx to kernel/event/hw_breakpoint.c

2015-11-03 Thread Palmer Dabbelt
This has a "#ifdef CONFIG_*" that used to be exposed to userspace.

The names in here are so generic that I don't think it's a good idea
to expose them to userspace (or even the rest of the kernel).  Since
there's only one kernel user, it's been moved to that file.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/hw_breakpoint.h | 10 --
 kernel/events/hw_breakpoint.c  | 10 ++
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/uapi/linux/hw_breakpoint.h 
b/include/uapi/linux/hw_breakpoint.h
index b04000a..7a6a5a7 100644
--- a/include/uapi/linux/hw_breakpoint.h
+++ b/include/uapi/linux/hw_breakpoint.h
@@ -17,14 +17,4 @@ enum {
HW_BREAKPOINT_INVALID   = HW_BREAKPOINT_RW | HW_BREAKPOINT_X,
 };
 
-enum bp_type_idx {
-   TYPE_INST   = 0,
-#ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
-   TYPE_DATA   = 0,
-#else
-   TYPE_DATA   = 1,
-#endif
-   TYPE_MAX
-};
-
 #endif /* _UAPI_LINUX_HW_BREAKPOINT_H */
diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index 92ce5f4..5ad117e 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -58,6 +58,16 @@ struct bp_cpuinfo {
unsigned intflexible; /* XXX: placeholder, see fetch_this_slot() */
 };
 
+enum bp_type_idx {
+   TYPE_INST   = 0,
+#if defined(CONFIG_HAVE_MIXED_BREAKPOINTS_REGS)
+   TYPE_DATA   = 0,
+#else
+   TYPE_DATA   = 1,
+#endif
+   TYPE_MAX
+};
+
 static DEFINE_PER_CPU(struct bp_cpuinfo, bp_cpuinfo[TYPE_MAX]);
 static int nr_slots[TYPE_MAX];
 
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 01/13] Remove #ifdef CONFIG_64BIT from all asm-generic/fcntl.h

2015-11-03 Thread Palmer Dabbelt
When working on the RISC-V port I noticed that F_SETLK64 was being
defined on our 64-bit platform, despite our port being so new that
we've only ever had the 64-bit file ops.  Since there's not compat
layer for these, this causes fcntl to bail out.

It turns out that one of the ways in with F_SETLK64 was being defined
(there's some more in glibc, but that's a whole different story... :))
is the result of CONFIG_64BIT showing up in this user-visible header.
 confirms this isn't sane, so I replaced it
with a __BITS_PER_LONG check.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/fcntl.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h
index e063eff..14a5c82 100644
--- a/include/uapi/asm-generic/fcntl.h
+++ b/include/uapi/asm-generic/fcntl.h
@@ -1,6 +1,7 @@
 #ifndef _ASM_GENERIC_FCNTL_H
 #define _ASM_GENERIC_FCNTL_H
 
+#include 
 #include 
 
 /*
@@ -115,7 +116,7 @@
 #define F_GETSIG   11  /* for sockets. */
 #endif
 
-#ifndef CONFIG_64BIT
+#if (__BITS_PER_LONG == 32)
 #ifndef F_GETLK64
 #define F_GETLK64  12  /*  using 'struct flock64' */
 #define F_SETLK64  13
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/13] Split FDPIC "struct elf_prstatus" to "struct elf_fdpic_prstatus"

2015-11-03 Thread Palmer Dabbelt
This is a pretty big change that I haven't tested any, which worries
me a lot.  The general idea here is that "struct elf_prstatus" can be
visible to userspace (from )

  "
   Generic ptrace interface that exports the architecture specific
   regsets using the corresponding NT_* types (which are also used in
   the core dump).  Please note that the NT_PRSTATUS note type in a
   core dump contains a full 'struct elf_prstatus'. But the
   user_regset for NT_PRSTATUS contains just the elf_gregset_t that is
   the pr_reg field of 'struct elf_prstatus'. For all the other
   user_regset flavors, the user_regset layout and the ELF core dump
   note payload are exactly the same layout.
  "

so it shouldn't have an "#ifdef CONFIG_" in there.

This splits the structure into two different structures, one still
named "struct elf_prstatus", and one for ELF FDPIC that is named
"struct elf_fdpic_prstatus" -- the idea here is that most users are
standard ELF, so that's the name that didn't change.

I tried to fix all the users of "struct elf_prstatus" that should now
be using "struct elf_fdpic_prstatus".  The only testing I did here was
to build a Blackfin defconfig with "struct elf_prstatus" not defined,
and to build an x86 defconfig with "struct elf_fdpic_prstatus" not
defined.

Note that this fails checkpatch.pl with a complaint about wanting open
braces on the same line as struct definitions.  The existing struct
definitions in this file have the brace a line afterwards, so I'm
going to leave this alone.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 fs/binfmt_elf_fdpic.c|  6 +++---
 fs/proc/kcore.c  | 16 
 include/linux/kexec.h|  4 
 include/uapi/linux/elfcore.h | 37 +++--
 kernel/kexec_core.c  |  4 
 5 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index d3634bf..587bf04 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -1323,7 +1323,7 @@ static inline void fill_note(struct memelfnote *note, 
const char *name, int type
  * fill up all the fields in prstatus from the given task struct, except
  * registers which need to be filled up separately.
  */
-static void fill_prstatus(struct elf_prstatus *prstatus,
+static void fill_prstatus(struct elf_fdpic_prstatus *prstatus,
  struct task_struct *p, long signr)
 {
prstatus->pr_info.si_signo = prstatus->pr_cursig = signr;
@@ -1406,7 +1406,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, 
struct task_struct *p,
 struct elf_thread_status
 {
struct list_head list;
-   struct elf_prstatus prstatus;   /* NT_PRSTATUS */
+   struct elf_fdpic_prstatus prstatus; /* NT_PRSTATUS */
elf_fpregset_t fpu; /* NT_PRFPREG */
struct task_struct *thread;
 #ifdef ELF_CORE_COPY_XFPREGS
@@ -1539,7 +1539,7 @@ static int elf_fdpic_core_dump(struct coredump_params 
*cprm)
loff_t offset = 0, dataoff;
int numnote;
struct memelfnote *notes = NULL;
-   struct elf_prstatus *prstatus = NULL;   /* NT_PRSTATUS */
+   struct elf_fdpic_prstatus *prstatus = NULL; /* NT_PRSTATUS */
struct elf_prpsinfo *psinfo = NULL; /* NT_PRPSINFO */
LIST_HEAD(thread_list);
struct list_head *t;
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 92e6726..b1edd77e 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -90,7 +90,11 @@ static size_t get_kcore_size(int *nphdr, size_t *elf_buflen)
(*nphdr + 2)*sizeof(struct elf_phdr) + 
3 * ((sizeof(struct elf_note)) +
 roundup(sizeof(CORE_STR), 4)) +
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+   roundup(sizeof(struct elf_fdpic_prstatus), 4) +
+#else
roundup(sizeof(struct elf_prstatus), 4) +
+#endif
roundup(sizeof(struct elf_prpsinfo), 4) +
roundup(arch_task_struct_size, 4);
*elf_buflen = PAGE_ALIGN(*elf_buflen);
@@ -318,7 +322,11 @@ static char *storenote(struct memelfnote *men, char *bufp)
  */
 static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
 {
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+   struct elf_fdpic_prstatus prstatus; /* NT_PRSTATUS */
+#else
struct elf_prstatus prstatus;   /* NT_PRSTATUS */
+#endif
struct elf_prpsinfo prpsinfo;   /* NT_PRPSINFO */
struct elf_phdr *nhdr, *phdr;
struct elfhdr *elf;
@@ -387,10 +395,18 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, 
int dataoff)
/* set up the process status */
notes[0].name = CORE_STR;
notes[0].type = NT_PRSTATUS;
+#ifdef CONFIG_BIN

[PATCH 04/13] Always expose MAP_UNINITIALIZED to userspace

2015-11-03 Thread Palmer Dabbelt
This used to be hidden behind CONFIG_MMAP_ALLOW_UNINITIALIZED, so
userspace wouldn't actually ever see it be non-zero.  While I had
originally hoped to avoid hiding it, it looks like this conflicts with
MAP_HUGE_SHIFT so I think it's safer to just keep this 0.

Architectures that want to define this can still override it.  In
fact, the Xtensa port already overrides it in a very similar manner to
the previously broken one (but due to lots of conflicting opinions on
how to solve this correctly, I'm just taking the easy way out and
letting their arch maintainers deal with it -- sorry).

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/mman-common.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/uapi/asm-generic/mman-common.h 
b/include/uapi/asm-generic/mman-common.h
index ddc3b36..0ce2a13 100644
--- a/include/uapi/asm-generic/mman-common.h
+++ b/include/uapi/asm-generic/mman-common.h
@@ -19,9 +19,7 @@
 #define MAP_TYPE   0x0f/* Mask for type of mapping */
 #define MAP_FIXED  0x10/* Interpret addr exactly */
 #define MAP_ANONYMOUS  0x20/* don't use a file */
-#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
-# define MAP_UNINITIALIZED 0x400   /* For anonymous mmap, memory could be 
uninitialized */
-#else
+#ifndef MAP_UNINITIALIZED
 # define MAP_UNINITIALIZED 0x0 /* Don't support this flag */
 #endif
 
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/13] Move USE_WCACHING to drivers/block/pktcdvd.c

2015-11-03 Thread Palmer Dabbelt
I don't think this was ever intended to be exposed to userspace, but
it did require an "#ifdef CONFIG_*".  Since the name is kind of
generic and was only used in one place, I've moved the definition to
the one user.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 drivers/block/pktcdvd.c  | 11 +++
 include/uapi/linux/pktcdvd.h | 11 ---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 7be2375..18d2d05 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -90,6 +90,17 @@ do { 
\
 
 #define MAX_SPEED 0x
 
+/*
+ * use drive write caching -- we need deferred error handling to be
+ * able to successfully recover with this option (drive will return good
+ * status as soon as the cdb is validated).
+ */
+#if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
+#define USE_WCACHING   1
+#else
+#define USE_WCACHING   0
+#endif
+
 static DEFINE_MUTEX(pktcdvd_mutex);
 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
 static struct proc_dir_entry *pkt_proc;
diff --git a/include/uapi/linux/pktcdvd.h b/include/uapi/linux/pktcdvd.h
index 2640b9d..05c2bee 100644
--- a/include/uapi/linux/pktcdvd.h
+++ b/include/uapi/linux/pktcdvd.h
@@ -29,17 +29,6 @@
 #define PACKET_WAIT_TIME   (HZ * 5 / 1000)
 
 /*
- * use drive write caching -- we need deferred error handling to be
- * able to successfully recover with this option (drive will return good
- * status as soon as the cdb is validated).
- */
-#if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
-#define USE_WCACHING   1
-#else
-#define USE_WCACHING   0
-#endif
-
-/*
  * No user-servicable parts beyond this point ->
  */
 
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/13] Use sys_ni.c instead of #ifdef to disable fork on CONFIG_NOMMU

2015-11-03 Thread Palmer Dabbelt
I think this change actually doesn't do anything: __NR_fork was still
being defined either way, and on my machine fork() in  comes
from libc.

This just moves to the standard mechanism for defining syscalls that
aren't implemented instead, which has the side-effect of no longer
having an #ifdef CONFIG_* in a user-visible header.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/unistd.h | 4 
 kernel/sys_ni.c   | 1 +
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/include/uapi/asm-generic/unistd.h 
b/include/uapi/asm-generic/unistd.h
index ee12400..ffd2957 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -869,11 +869,7 @@ __SYSCALL(__NR_uselib, sys_uselib)
 __SYSCALL(__NR__sysctl, sys_sysctl)
 
 #define __NR_fork 1079
-#ifdef CONFIG_MMU
 __SYSCALL(__NR_fork, sys_fork)
-#else
-__SYSCALL(__NR_fork, sys_ni_syscall)
-#endif /* CONFIG_MMU */
 
 #undef __NR_syscalls
 #define __NR_syscalls (__NR_fork+1)
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index a02decf..c830f7f 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -174,6 +174,7 @@ cond_syscall(sys_setfsuid);
 cond_syscall(sys_setfsgid);
 cond_syscall(sys_capget);
 cond_syscall(sys_capset);
+cond_syscall(sys_fork);
 
 /* arch-specific weak syscall entries */
 cond_syscall(sys_pciconfig_read);
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 11/13] Always define MAX_RAW_MINORS as 2**20 in userspace

2015-11-03 Thread Palmer Dabbelt
While I don't think this was ever meant to be exposed to userspace, if
anyone is using it then this will at least provide a correct (if
unlikely) definition.

MAX_RAW_MINORS used to be used in the kernel, where it's been replaced
with CONFIG_MAX_RAW_MINORS.

Note that there's a checkpatch.pl warning about a split config string
here, but I've left that alone.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 drivers/char/raw.c   | 7 ---
 include/uapi/linux/raw.h | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 60316fb..362d7a6 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -36,7 +36,7 @@ static struct raw_device_data *raw_devices;
 static DEFINE_MUTEX(raw_mutex);
 static const struct file_operations raw_ctl_fops; /* forward declaration */
 
-static int max_raw_minors = MAX_RAW_MINORS;
+static int max_raw_minors = CONFIG_MAX_RAW_MINORS;
 
 module_param(max_raw_minors, int, 0);
 MODULE_PARM_DESC(max_raw_minors, "Maximum number of raw devices (1-65536)");
@@ -317,8 +317,9 @@ static int __init raw_init(void)
 
if (max_raw_minors < 1 || max_raw_minors > 65536) {
printk(KERN_WARNING "raw: invalid max_raw_minors (must be"
-   " between 1 and 65536), using %d\n", MAX_RAW_MINORS);
-   max_raw_minors = MAX_RAW_MINORS;
+   " between 1 and 65536), using %d\n",
+  CONFIG_MAX_RAW_MINORS);
+   max_raw_minors = CONFIG_MAX_RAW_MINORS;
}
 
raw_devices = vzalloc(sizeof(struct raw_device_data) * max_raw_minors);
diff --git a/include/uapi/linux/raw.h b/include/uapi/linux/raw.h
index 62d543e..f3d009b 100644
--- a/include/uapi/linux/raw.h
+++ b/include/uapi/linux/raw.h
@@ -13,6 +13,6 @@ struct raw_config_request
__u64   block_minor;
 };
 
-#define MAX_RAW_MINORS CONFIG_MAX_RAW_DEVS
+#define MAX_RAW_MINORS (1 << 20)
 
 #endif /* __LINUX_RAW_H */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/13] Move MAX_SHARED_LIBS to fs/binfmt_flat.c

2015-11-03 Thread Palmer Dabbelt
I'm not sure what this is, but it doesn't feel like something that
should be exposed to userspace here.  I'm assuming this file was
exposed for the structure in it, which doesn't depend on
MAX_SHARED_LIBS.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 fs/binfmt_flat.c  | 6 ++
 include/uapi/linux/flat.h | 6 --
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index f723cd3..e89fb43 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -72,6 +72,12 @@
 #define RELOC_FAILED 0xff00ff01/* Relocation incorrect 
somewhere */
 #define UNLOADED_LIB 0x7ff000ff/* Placeholder for unused 
library */
 
+#ifdef CONFIG_BINFMT_SHARED_FLAT
+#defineMAX_SHARED_LIBS (4)
+#else
+#defineMAX_SHARED_LIBS (1)
+#endif
+
 struct lib_info {
struct {
unsigned long start_code;   /* Start of text 
segment */
diff --git a/include/uapi/linux/flat.h b/include/uapi/linux/flat.h
index 88cd6ba..1b177c7 100644
--- a/include/uapi/linux/flat.h
+++ b/include/uapi/linux/flat.h
@@ -13,12 +13,6 @@
 
 #defineFLAT_VERSION0x0004L
 
-#ifdef CONFIG_BINFMT_SHARED_FLAT
-#defineMAX_SHARED_LIBS (4)
-#else
-#defineMAX_SHARED_LIBS (1)
-#endif
-
 /*
  * To make everything easier to port and manage cross platform
  * development,  all fields are in network byte order.
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 06/13] Move ep_take_care_of_epollwakeup() to fs/eventpoll.c

2015-11-03 Thread Palmer Dabbelt
This doesn't make any sense to expose to userspace, so it's been moved
to the one user.  This was introduced by commit 95f19f658ce1 ("epoll:
drop EPOLLWAKEUP if PM_SLEEP is disabled").

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 fs/eventpoll.c | 13 +
 include/uapi/linux/eventpoll.h | 12 
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 1e009ca..aadee3d 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1812,6 +1812,19 @@ SYSCALL_DEFINE1(epoll_create, int, size)
return sys_epoll_create1(0);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
+{
+   if ((epev->events & EPOLLWAKEUP) && !capable(CAP_BLOCK_SUSPEND))
+   epev->events &= ~EPOLLWAKEUP;
+}
+#else
+static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
+{
+   epev->events &= ~EPOLLWAKEUP;
+}
+#endif
+
 /*
  * The following function implements the controller interface for
  * the eventpoll file that enables the insertion/removal/change of
diff --git a/include/uapi/linux/eventpoll.h b/include/uapi/linux/eventpoll.h
index bc81fb2..7850373 100644
--- a/include/uapi/linux/eventpoll.h
+++ b/include/uapi/linux/eventpoll.h
@@ -61,16 +61,4 @@ struct epoll_event {
__u64 data;
 } EPOLL_PACKED;
 
-#ifdef CONFIG_PM_SLEEP
-static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
-{
-   if ((epev->events & EPOLLWAKEUP) && !capable(CAP_BLOCK_SUSPEND))
-   epev->events &= ~EPOLLWAKEUP;
-}
-#else
-static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
-{
-   epev->events &= ~EPOLLWAKEUP;
-}
-#endif
 #endif /* _UAPI_LINUX_EVENTPOLL_H */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 03/13] Move COMPAT_ATM_ADDPARTY to net/atm/svc.c

2015-11-03 Thread Palmer Dabbelt
This used to be behind an #ifdef COMPAT_COMPAT, so most of userspace
wouldn't have seen the definition before.  Unfortunately this header
file became visible to userspace, so the definition has instead been
moved to net/atm/svc.c (the only user).

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/atmdev.h | 4 
 net/atm/svc.c   | 5 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/atmdev.h b/include/uapi/linux/atmdev.h
index 93e0ec0..3dcec70 100644
--- a/include/uapi/linux/atmdev.h
+++ b/include/uapi/linux/atmdev.h
@@ -100,10 +100,6 @@ struct atm_dev_stats {
/* use backend to make new if */
 #define ATM_ADDPARTY   _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
/* add party to p2mp call */
-#ifdef CONFIG_COMPAT
-/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
-#define COMPAT_ATM_ADDPARTY_IOW('a', ATMIOC_SPECIAL+4,struct 
compat_atm_iobuf)
-#endif
 #define ATM_DROPPARTY  _IOW('a', ATMIOC_SPECIAL+5,int)
/* drop party from p2mp call */
 
diff --git a/net/atm/svc.c b/net/atm/svc.c
index 3fa0a9e..9e2e6ef 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -27,6 +27,11 @@
 #include "signaling.h"
 #include "addr.h"
 
+#ifdef CONFIG_COMPAT
+/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
+#define COMPAT_ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4, struct 
compat_atm_iobuf)
+#endif
+
 static int svc_create(struct net *net, struct socket *sock, int protocol,
  int kern);
 
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 12/13] Remove AT_VECTOR_SIZE_ARCH on x86

2015-11-03 Thread Palmer Dabbelt
It looks like there aren't actually users of this macro anywhere:

 * The kernel doesn't use it on x86 because we don't suppor ELF FDPIC.

 * The only Google results point to LMKL patches, both the one that
   wrote this (from 2010) and my patch to hide it behind __KERNEL__.

 * I grep'd through all the source tarballs on my machine, and the
   only packages that matched were the kernel and crui (which copied a
   PPC kernel header).

Since I'm not sure how to actually provide the right answer (if I
understand correctly, CONFIG_IA32_EMULATION is not __i386__), the only
thing I can think of to do is to just remove the definition.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 arch/x86/include/uapi/asm/auxvec.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/arch/x86/include/uapi/asm/auxvec.h 
b/arch/x86/include/uapi/asm/auxvec.h
index 77203ac..1316b4c 100644
--- a/arch/x86/include/uapi/asm/auxvec.h
+++ b/arch/x86/include/uapi/asm/auxvec.h
@@ -9,11 +9,4 @@
 #endif
 #define AT_SYSINFO_EHDR33
 
-/* entries in ARCH_DLINFO: */
-#if defined(CONFIG_IA32_EMULATION) || !defined(CONFIG_X86_64)
-# define AT_VECTOR_SIZE_ARCH 2
-#else /* else it's non-compat x86-64 */
-# define AT_VECTOR_SIZE_ARCH 1
-#endif
-
 #endif /* _ASM_X86_AUXVEC_H */
-- 
2.4.10

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] Remove #ifdef CONFIG_64BIT from all asm-generic/fcntl.h

2015-09-02 Thread Palmer Dabbelt
From: Palmer Dabbelt <palmer.dabb...@eecs.berkeley.edu>

When working on the RISC-V port I noticed that F_SETLK64 was being
defined on our 64-bit platform, despite our port being so new that
we've only ever had the 64-bit file ops.  Since there's not compat
layer for these, this causes fcntl to bail out.

It turns out that one of the ways in with F_SETLK64 was being defined
(there's some more in glibc, but that's a whole different story... :))
is the result of CONFIG_64BIT showing up in this user-visible header.
 confirms this isn't sane, so I replaced it
with a __BITS_PER_LONG check.

I went ahead and grep'd for any more of these (with
headers_install_all), and this was the only one I found.

Signed-off-by: Palmer Dabbelt <palmer.dabb...@eecs.berkeley.edu>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/fcntl.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h
index e063effe0cc1..14a5c8237d84 100644
--- a/include/uapi/asm-generic/fcntl.h
+++ b/include/uapi/asm-generic/fcntl.h
@@ -1,6 +1,7 @@
 #ifndef _ASM_GENERIC_FCNTL_H
 #define _ASM_GENERIC_FCNTL_H
 
+#include 
 #include 
 
 /*
@@ -115,7 +116,7 @@
 #define F_GETSIG   11  /* for sockets. */
 #endif
 
-#ifndef CONFIG_64BIT
+#if (__BITS_PER_LONG == 32)
 #ifndef F_GETLK64
 #define F_GETLK64  12  /*  using 'struct flock64' */
 #define F_SETLK64  13
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Remove #ifdef CONFIG_64BIT from all asm-generic/fcntl.h

2015-09-07 Thread Palmer Dabbelt
On Mon, 07 Sep 2015 06:16:37 PDT (-0700), a...@arndb.de wrote:
> On Tuesday 01 September 2015 17:10:10 Palmer Dabbelt wrote:
>> From: Palmer Dabbelt <palmer.dabb...@eecs.berkeley.edu>
>>
>> When working on the RISC-V port I noticed that F_SETLK64 was being
>> defined on our 64-bit platform, despite our port being so new that
>> we've only ever had the 64-bit file ops.  Since there's not compat
>> layer for these, this causes fcntl to bail out.
>>
>> It turns out that one of the ways in with F_SETLK64 was being defined
>> (there's some more in glibc, but that's a whole different story... :))
>> is the result of CONFIG_64BIT showing up in this user-visible header.
>>  confirms this isn't sane, so I replaced it
>> with a __BITS_PER_LONG check.
>>
>> I went ahead and grep'd for any more of these (with
>> headers_install_all), and this was the only one I found.
>>
>> Signed-off-by: Palmer Dabbelt <palmer.dabb...@eecs.berkeley.edu>
>> Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
>> Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
>
> Looks good to me. Are you planning to submit the RISC-V port upstream
> any time soon? If so, just keep the patch in your tree and add my
>
> Acked-by: Arnd Bergmann <a...@arndb.de>

The RISC-V stuff is still a few months off, that's why I submitted this
upstream stand-alone.  The supervisor specification isn't 100% set in
stone yet, and we're waiting on that before upstreaming anything
significant.

> However, I did see a lot of similar bugs now that you point me to it:
>
> $  grep -r \\\ obj-tmp/usr/include/asm-generic/fcntl.h:#ifndef CONFIG_64BIT
> obj-tmp/usr/include/asm-generic/mman-common.h:#ifdef 
> CONFIG_MMAP_ALLOW_UNINITIALIZED
> obj-tmp/usr/include/asm-generic/unistd.h:#ifdef CONFIG_MMU
> obj-tmp/usr/include/asm-generic/unistd.h:#endif /* CONFIG_MMU */
> obj-tmp/usr/include/linux/atmdev.h:#ifdef CONFIG_COMPAT
> obj-tmp/usr/include/linux/elfcore.h:#ifdef CONFIG_BINFMT_ELF_FDPIC
> obj-tmp/usr/include/linux/eventpoll.h:#ifdef CONFIG_PM_SLEEP
> obj-tmp/usr/include/linux/fb.h:#ifdef CONFIG_FB_BACKLIGHT
> obj-tmp/usr/include/linux/flat.h:#ifdef CONFIG_BINFMT_SHARED_FLAT
> obj-tmp/usr/include/linux/hw_breakpoint.h:#ifdef 
> CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
> obj-tmp/usr/include/linux/pktcdvd.h:#if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
> obj-tmp/usr/include/linux/raw.h:#define MAX_RAW_MINORS CONFIG_MAX_RAW_DEVS
> obj-tmp/usr/include/asm/ptrace.h:#ifdef CONFIG_CPU_ENDIAN_BE8
>
> These all have the same problem, and we should fix them, as well as
> (probably) adding an automated check to scripts/headers_install.sh.

Well, I was going to go fix them all and ran a very similar grep, but
I think I got a lot of false-positives.  If I understand correctly,
it's allowed to have CONFIG_* when guarded by __KERNEL__ in
user-visible headers?

Now that I've written that, I realize it'd be pretty easy to just use
cpp to drop everything inside __KERNEL__ and then look for CONFIG_*.
If you want, I can try to do that, fix what triggers the check, and
re-submit everything together?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3] Remove #ifdef CONFIG_* from all userspace headers

2015-09-14 Thread Palmer Dabbelt
This patch set used to be called "[PATCH] Remove #ifdef CONFIG_64BIT
from all asm-generic/fcntl.h".

This is version 3 of the patch set.  I think things are kind of
cleaning up, but there's still some questions I have:

 * #4 might be dangerous, but I think this is the best way to do it
   because otherwise arch maintainers will have to #define this to
   something.  Since Xtensa already had exactly the same bug as the
   asm-generic header did, I think it'd be best to avoid those if
   possible.

   I'm OK changing this to define the value to 0 by default (though
   thinking now, I think it'd be better to not define it by default),
   since most kernels aren't going to have MAP_UNINITIALIZED do
   anything anyway.

 * #5 is big and I don't really understand what's going on, so it's
   probably broken somewhere.

Also, there's some checkpatch warnings that I purposely haven't fixed:

 * In #5, there's a checkpatch.pl complaint about same-line struct
   braces.  I've left that in to match the rest of the file, but I can
   also fix all of them if that would be better.

 * In #10, there's a checkpatch.pl complaint about a split printk
   format string, but that was there before and I don't see a way to
   make it a lot cleaner, so I'm leaving it alone.

 * In #13, there's two checkpatch.pl complains.  One is about block
   comments that is bogus, and one is about long lines but there's
   more of those so I think it's OK.

Thanks to everyone who looked at v2!




Changes since v2 (<1441832902-28993-1-git-send-email-pal...@dabbelt.com>)

* Patch set renamed.

* #2 is rewritten to use sys_ni.c instead of an #ifdef

* #3, #6, #8, #9, #10, and #11 no longer use "#ifdef __KERNEL__" but
   have instead moved the offending lines to the correct, kernel-only
   files.

* #4 has been rewritten to always define MAP_UNINITIALIZED to
   non-zero, rather than defining it to zero when in userspace.

* #5 got a whole lot longer -- rather than just always hiding these
   fields from userspace, there is now a second "struct
   elf_fdpic_prstatus" structure.  This should allow userspace to
   parse core dumps correctly.

* Rebased onto 9c488de24f7264f08d341024bffdd637b4d04c96.

Changes since v1 (<1441152610-22566-1-git-send-email-pal...@dabbelt.com>)

* All patches but #1 were added.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 04/13] Always expose MAP_UNINITIALIZED to userspace

2015-09-14 Thread Palmer Dabbelt
This used to be hidden behind CONFIG_MMAP_ALLOW_UNINITIALIZED, so
userspace wouldn't actually ever see it be non-zero.  While I could
have kept hiding it, the man pages seem to indicate that
MAP_UNINITIALIZED should be visible:

  mmap(2)
  MAP_UNINITIALIZED (since Linux 2.6.33)
Don't clear anonymous pages.  This flag is intended to improve
performance on embedded devices.  This flag is honored only if the
kernel was configured with the CONFIG_MMAP_ALLOW_UNINITIALIZED
option.  Because of the security implications, that option is
normally enabled only on embedded devices (i.e., devices where one
has complete control of the contents of user memory).

and since the only time it shows up in my /usr/include is in this
header I believe this should have been visible to userspace (as
non-zero, which wouldn't do anything when or'd into the flags) all
along.

This change also applies to the xtensa version of this definition,
whic is the same as the generic one.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 arch/xtensa/include/uapi/asm/mman.h| 4 +---
 include/uapi/asm-generic/mman-common.h | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/xtensa/include/uapi/asm/mman.h 
b/arch/xtensa/include/uapi/asm/mman.h
index 201aec0e0446..2cbc1e717082 100644
--- a/arch/xtensa/include/uapi/asm/mman.h
+++ b/arch/xtensa/include/uapi/asm/mman.h
@@ -55,11 +55,9 @@
 #define MAP_NONBLOCK   0x2 /* do not block on IO */
 #define MAP_STACK  0x4 /* give out an address that is best 
suited for process/thread stacks */
 #define MAP_HUGETLB0x8 /* create a huge page mapping */
-#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
+#ifndef MAP_UNINITIALIZED
 # define MAP_UNINITIALIZED 0x400   /* For anonymous mmap, memory could be
 * uninitialized */
-#else
-# define MAP_UNINITIALIZED 0x0 /* Don't support this flag */
 #endif
 
 /*
diff --git a/include/uapi/asm-generic/mman-common.h 
b/include/uapi/asm-generic/mman-common.h
index ddc3b36f1046..7aeeb12db193 100644
--- a/include/uapi/asm-generic/mman-common.h
+++ b/include/uapi/asm-generic/mman-common.h
@@ -19,10 +19,8 @@
 #define MAP_TYPE   0x0f/* Mask for type of mapping */
 #define MAP_FIXED  0x10/* Interpret addr exactly */
 #define MAP_ANONYMOUS  0x20/* don't use a file */
-#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
+#ifndef MAP_UNINITIALIZED
 # define MAP_UNINITIALIZED 0x400   /* For anonymous mmap, memory could be 
uninitialized */
-#else
-# define MAP_UNINITIALIZED 0x0 /* Don't support this flag */
 #endif
 
 #define MS_ASYNC   1   /* sync memory asynchronously */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/13] Use sys_ni.c instead of #ifdef to disable fork on CONFIG_NOMMU

2015-09-14 Thread Palmer Dabbelt
I think this change actually doesn't do anything: __NR_fork was still
being defined either way, and on my machine fork() in  comes
from libc.

This just moves to the standard mechanism for defining syscalls that
aren't implemented instead, which has the side-effect of no longer
having an #ifdef CONFIG_* in a user-visible header.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/unistd.h | 4 
 kernel/sys_ni.c   | 1 +
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/include/uapi/asm-generic/unistd.h 
b/include/uapi/asm-generic/unistd.h
index 8da542a2874d..21689284360b 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -867,11 +867,7 @@ __SYSCALL(__NR_uselib, sys_uselib)
 __SYSCALL(__NR__sysctl, sys_sysctl)
 
 #define __NR_fork 1079
-#ifdef CONFIG_MMU
 __SYSCALL(__NR_fork, sys_fork)
-#else
-__SYSCALL(__NR_fork, sys_ni_syscall)
-#endif /* CONFIG_MMU */
 
 #undef __NR_syscalls
 #define __NR_syscalls (__NR_fork+1)
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index a02decf15583..c830f7f9e36d 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -174,6 +174,7 @@ cond_syscall(sys_setfsuid);
 cond_syscall(sys_setfsgid);
 cond_syscall(sys_capget);
 cond_syscall(sys_capset);
+cond_syscall(sys_fork);
 
 /* arch-specific weak syscall entries */
 cond_syscall(sys_pciconfig_read);
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 12/13] Remove AT_VECTOR_SIZE_ARCH on x86

2015-09-14 Thread Palmer Dabbelt
It looks like there aren't actually users of this macro anywhere:

 * The kernel doesn't use it on x86 because we don't suppor ELF FDPIC.

 * The only Google results point to LMKL patches, both the one that
   wrote this (from 2010) and my patch to hide it behind __KERNEL__.

 * I grep'd through all the source tarballs on my machine, and the
   only packages that matched were the kernel and crui (which copied a
   PPC kernel header).

Since I'm not sure how to actually provide the right answer (if I
understand correctly, CONFIG_IA32_EMULATION is not __i386__), the only
thing I can think of to do is to just remove the definition.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 arch/x86/include/uapi/asm/auxvec.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/arch/x86/include/uapi/asm/auxvec.h 
b/arch/x86/include/uapi/asm/auxvec.h
index 77203ac352de..1316b4c35425 100644
--- a/arch/x86/include/uapi/asm/auxvec.h
+++ b/arch/x86/include/uapi/asm/auxvec.h
@@ -9,11 +9,4 @@
 #endif
 #define AT_SYSINFO_EHDR33
 
-/* entries in ARCH_DLINFO: */
-#if defined(CONFIG_IA32_EMULATION) || !defined(CONFIG_X86_64)
-# define AT_VECTOR_SIZE_ARCH 2
-#else /* else it's non-compat x86-64 */
-# define AT_VECTOR_SIZE_ARCH 1
-#endif
-
 #endif /* _ASM_X86_AUXVEC_H */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 13/13] Re-enable and clean up "check_config()" in headers_check.pl

2015-09-14 Thread Palmer Dabbelt
I recently got bit by a CONFIG_ in userspace bug.  This has apparently
happened before, but the check got disabled for triggering too much.
In order to reduce false positives, I added some hueristics to avoid
detecting comments.

Since these tests all pass, I've now re-enabled them.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 scripts/headers_check.pl | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/scripts/headers_check.pl b/scripts/headers_check.pl
index 62320f93e903..dd413ad9c850 100755
--- a/scripts/headers_check.pl
+++ b/scripts/headers_check.pl
@@ -40,7 +40,7 @@ foreach my $file (@files) {
_asm_types();
_sizetypes();
_declarations();
-   # Dropped for now. Too much noise _config();
+   _config();
}
close $fh;
 }
@@ -76,9 +76,24 @@ sub check_declarations
}
 }
 
+my $check_config_in_multiline_comment = 0;
 sub check_config
 {
-   if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
+   my $nocomments = $line;
+   $nocomments =~ s/\/\*.*\*\///; # Remove ANSI-style comments (/* to */)
+   $nocomments =~ s/\/\/.*//; # Remove C99-style comments (// to EOL)
+
+   # Check to see if we're within a multiline comment, and if so
+   # just remove the whole line.  I tried matching on '^ * ', but
+   # there's one header that doesn't prepend multi-line comments
+   # with * so that won't work.
+   if ($nocomments =~ m/\/\*/) { $check_config_in_multiline_comment = 1; }
+   if ($nocomments =~ m/\*\//) { $check_config_in_multiline_comment = 0; }
+   if ($check_config_in_multiline_comment == 1) { $nocomments = "" }
+
+   # Check to see if there is something that looks like CONFIG_
+   # inside a userspace-accessible header file and if so, print that out.
+   if ($nocomments =~ 
m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace 
where it is not valid\n";
}
 }
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/13] Move MAX_SHARED_LIBS to fs/binfmt_flat.c

2015-09-14 Thread Palmer Dabbelt
I'm not sure what this is, but it doesn't feel like something that
should be exposed to userspace here.  I'm assuming this file was
exposed for the structure in it, which doesn't depend on
MAX_SHARED_LIBS.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 fs/binfmt_flat.c  | 6 ++
 include/uapi/linux/flat.h | 6 --
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index f723cd3a455c..e89fb43c2a10 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -72,6 +72,12 @@
 #define RELOC_FAILED 0xff00ff01/* Relocation incorrect 
somewhere */
 #define UNLOADED_LIB 0x7ff000ff/* Placeholder for unused 
library */
 
+#ifdef CONFIG_BINFMT_SHARED_FLAT
+#defineMAX_SHARED_LIBS (4)
+#else
+#defineMAX_SHARED_LIBS (1)
+#endif
+
 struct lib_info {
struct {
unsigned long start_code;   /* Start of text 
segment */
diff --git a/include/uapi/linux/flat.h b/include/uapi/linux/flat.h
index 88cd6baba8f3..1b177c7637c4 100644
--- a/include/uapi/linux/flat.h
+++ b/include/uapi/linux/flat.h
@@ -13,12 +13,6 @@
 
 #defineFLAT_VERSION0x0004L
 
-#ifdef CONFIG_BINFMT_SHARED_FLAT
-#defineMAX_SHARED_LIBS (4)
-#else
-#defineMAX_SHARED_LIBS (1)
-#endif
-
 /*
  * To make everything easier to port and manage cross platform
  * development,  all fields are in network byte order.
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/13] Make FB_BACKLIGHT_{LEVELS,MAX} always visible

2015-09-14 Thread Palmer Dabbelt
Nothing else in the kernel defines this, and this header is visible to
userspace.  Rather than hiding it in an #ifdef, I think it's sane to
just make this visible to userspace.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/fb.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/uapi/linux/fb.h b/include/uapi/linux/fb.h
index fb795c3b3c17..8926f13bc19f 100644
--- a/include/uapi/linux/fb.h
+++ b/include/uapi/linux/fb.h
@@ -392,11 +392,8 @@ struct fb_cursor {
struct fb_image image;  /* Cursor image */
 };
 
-#ifdef CONFIG_FB_BACKLIGHT
 /* Settings for the generic backlight code */
 #define FB_BACKLIGHT_LEVELS128
 #define FB_BACKLIGHT_MAX   0xFF
-#endif
-
 
 #endif /* _UAPI_LINUX_FB_H */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 01/13] Remove #ifdef CONFIG_64BIT from all asm-generic/fcntl.h

2015-09-14 Thread Palmer Dabbelt
When working on the RISC-V port I noticed that F_SETLK64 was being
defined on our 64-bit platform, despite our port being so new that
we've only ever had the 64-bit file ops.  Since there's not compat
layer for these, this causes fcntl to bail out.

It turns out that one of the ways in with F_SETLK64 was being defined
(there's some more in glibc, but that's a whole different story... :))
is the result of CONFIG_64BIT showing up in this user-visible header.
 confirms this isn't sane, so I replaced it
with a __BITS_PER_LONG check.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/fcntl.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h
index e063effe0cc1..14a5c8237d84 100644
--- a/include/uapi/asm-generic/fcntl.h
+++ b/include/uapi/asm-generic/fcntl.h
@@ -1,6 +1,7 @@
 #ifndef _ASM_GENERIC_FCNTL_H
 #define _ASM_GENERIC_FCNTL_H
 
+#include 
 #include 
 
 /*
@@ -115,7 +116,7 @@
 #define F_GETSIG   11  /* for sockets. */
 #endif
 
-#ifndef CONFIG_64BIT
+#if (__BITS_PER_LONG == 32)
 #ifndef F_GETLK64
 #define F_GETLK64  12  /*  using 'struct flock64' */
 #define F_SETLK64  13
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 11/13] Always define MAX_RAW_MINORS as 65535 in userspace

2015-09-14 Thread Palmer Dabbelt
While I don't think this was ever meant to be exposed to userspace, if
anyone is using it then this will at least provide a correct (if
unlikely) definition.

MAX_RAW_MINORS used to be used in the kernel, where it's been replaced
with CONFIG_MAX_RAW_MINORS.

Note that there's a checkpatch.pl warning about a split config string
here, but I've left that alone.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 drivers/char/raw.c   | 7 ---
 include/uapi/linux/raw.h | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 60316fbaf295..362d7a6511b9 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -36,7 +36,7 @@ static struct raw_device_data *raw_devices;
 static DEFINE_MUTEX(raw_mutex);
 static const struct file_operations raw_ctl_fops; /* forward declaration */
 
-static int max_raw_minors = MAX_RAW_MINORS;
+static int max_raw_minors = CONFIG_MAX_RAW_MINORS;
 
 module_param(max_raw_minors, int, 0);
 MODULE_PARM_DESC(max_raw_minors, "Maximum number of raw devices (1-65536)");
@@ -317,8 +317,9 @@ static int __init raw_init(void)
 
if (max_raw_minors < 1 || max_raw_minors > 65536) {
printk(KERN_WARNING "raw: invalid max_raw_minors (must be"
-   " between 1 and 65536), using %d\n", MAX_RAW_MINORS);
-   max_raw_minors = MAX_RAW_MINORS;
+   " between 1 and 65536), using %d\n",
+  CONFIG_MAX_RAW_MINORS);
+   max_raw_minors = CONFIG_MAX_RAW_MINORS;
}
 
raw_devices = vzalloc(sizeof(struct raw_device_data) * max_raw_minors);
diff --git a/include/uapi/linux/raw.h b/include/uapi/linux/raw.h
index 62d543e70603..f0390b3e8530 100644
--- a/include/uapi/linux/raw.h
+++ b/include/uapi/linux/raw.h
@@ -13,6 +13,6 @@ struct raw_config_request
__u64   block_minor;
 };
 
-#define MAX_RAW_MINORS CONFIG_MAX_RAW_DEVS
+#define MAX_RAW_MINORS 65535
 
 #endif /* __LINUX_RAW_H */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/13] Move USE_WCACHING to drivers/block/pktcdvd.c

2015-09-14 Thread Palmer Dabbelt
I don't think this was ever intended to be exposed to userspace, but
it did require an "#ifdef CONFIG_*".  Since the name is kind of
generic and was only used in one place, I've moved the definition to
the one user.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 drivers/block/pktcdvd.c  | 11 +++
 include/uapi/linux/pktcdvd.h | 11 ---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 7be2375db7f2..18d2d05f5ac9 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -90,6 +90,17 @@ do { 
\
 
 #define MAX_SPEED 0x
 
+/*
+ * use drive write caching -- we need deferred error handling to be
+ * able to successfully recover with this option (drive will return good
+ * status as soon as the cdb is validated).
+ */
+#if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
+#define USE_WCACHING   1
+#else
+#define USE_WCACHING   0
+#endif
+
 static DEFINE_MUTEX(pktcdvd_mutex);
 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
 static struct proc_dir_entry *pkt_proc;
diff --git a/include/uapi/linux/pktcdvd.h b/include/uapi/linux/pktcdvd.h
index 2640b9d4e243..05c2bee70d6c 100644
--- a/include/uapi/linux/pktcdvd.h
+++ b/include/uapi/linux/pktcdvd.h
@@ -29,17 +29,6 @@
 #define PACKET_WAIT_TIME   (HZ * 5 / 1000)
 
 /*
- * use drive write caching -- we need deferred error handling to be
- * able to successfully recover with this option (drive will return good
- * status as soon as the cdb is validated).
- */
-#if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
-#define USE_WCACHING   1
-#else
-#define USE_WCACHING   0
-#endif
-
-/*
  * No user-servicable parts beyond this point ->
  */
 
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 09/13] Move bp_type_idx to kernel/event/hw_breakpoint.c

2015-09-14 Thread Palmer Dabbelt
This has a "#ifdef CONFIG_*" that used to be exposed to userspace.

The names in here are so generic that I don't think it's a good idea
to expose them to userspace (or even the rest of the kernel).  Since
there's only one kernel user, it's been moved to that file.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/hw_breakpoint.h | 10 --
 kernel/events/hw_breakpoint.c  | 10 ++
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/uapi/linux/hw_breakpoint.h 
b/include/uapi/linux/hw_breakpoint.h
index b04000a2296a..7a6a5a7f9511 100644
--- a/include/uapi/linux/hw_breakpoint.h
+++ b/include/uapi/linux/hw_breakpoint.h
@@ -17,14 +17,4 @@ enum {
HW_BREAKPOINT_INVALID   = HW_BREAKPOINT_RW | HW_BREAKPOINT_X,
 };
 
-enum bp_type_idx {
-   TYPE_INST   = 0,
-#ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
-   TYPE_DATA   = 0,
-#else
-   TYPE_DATA   = 1,
-#endif
-   TYPE_MAX
-};
-
 #endif /* _UAPI_LINUX_HW_BREAKPOINT_H */
diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index 92ce5f4ccc26..5ad117e0f55b 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -58,6 +58,16 @@ struct bp_cpuinfo {
unsigned intflexible; /* XXX: placeholder, see fetch_this_slot() */
 };
 
+enum bp_type_idx {
+   TYPE_INST   = 0,
+#if defined(CONFIG_HAVE_MIXED_BREAKPOINTS_REGS)
+   TYPE_DATA   = 0,
+#else
+   TYPE_DATA   = 1,
+#endif
+   TYPE_MAX
+};
+
 static DEFINE_PER_CPU(struct bp_cpuinfo, bp_cpuinfo[TYPE_MAX]);
 static int nr_slots[TYPE_MAX];
 
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Remove #ifdef CONFIG_64BIT from all asm-generic/fcntl.h

2015-09-14 Thread Palmer Dabbelt
On Thu, 10 Sep 2015 04:18:05 PDT (-0700), dhowe...@redhat.com wrote:
> David Howells  wrote:
>
>> Rather than iterating through all the rest of your patches and saying the 
>> same
>> thing, if there's something in a UAPI header that needs wrapping in 
>> __KERNEL__
>> to exclude it from userspace's use, then it should be transferred to the
>> non-UAPI variant of that header (which should #include the UAPI variant).
>
> I should mention that there is the odd case where this is difficult to
> achieve.  See include/uapi/linux/acct.h for an example...

OK, sorry about that.  I'm submitting a v3 that should fix these
problems.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 06/13] Move ep_take_care_of_epollwakeup() to fs/eventpoll.c

2015-09-14 Thread Palmer Dabbelt
This doesn't make any sense to expose to userspace, so it's been moved
to the one user.  This was introduced by commit 95f19f658ce1 ("epoll:
drop EPOLLWAKEUP if PM_SLEEP is disabled").

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 fs/eventpoll.c | 13 +
 include/uapi/linux/eventpoll.h | 12 
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 1e009cad8d5c..aadee3d1931a 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1812,6 +1812,19 @@ SYSCALL_DEFINE1(epoll_create, int, size)
return sys_epoll_create1(0);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
+{
+   if ((epev->events & EPOLLWAKEUP) && !capable(CAP_BLOCK_SUSPEND))
+   epev->events &= ~EPOLLWAKEUP;
+}
+#else
+static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
+{
+   epev->events &= ~EPOLLWAKEUP;
+}
+#endif
+
 /*
  * The following function implements the controller interface for
  * the eventpoll file that enables the insertion/removal/change of
diff --git a/include/uapi/linux/eventpoll.h b/include/uapi/linux/eventpoll.h
index bc81fb2e1f0e..7850373079ee 100644
--- a/include/uapi/linux/eventpoll.h
+++ b/include/uapi/linux/eventpoll.h
@@ -61,16 +61,4 @@ struct epoll_event {
__u64 data;
 } EPOLL_PACKED;
 
-#ifdef CONFIG_PM_SLEEP
-static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
-{
-   if ((epev->events & EPOLLWAKEUP) && !capable(CAP_BLOCK_SUSPEND))
-   epev->events &= ~EPOLLWAKEUP;
-}
-#else
-static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
-{
-   epev->events &= ~EPOLLWAKEUP;
-}
-#endif
 #endif /* _UAPI_LINUX_EVENTPOLL_H */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/13] Split FDPIC "struct elf_prstatus" to "struct elf_fdpic_prstatus"

2015-09-14 Thread Palmer Dabbelt
This is a pretty big change that I haven't tested any, which worries
me a lot.  The general idea here is that "struct elf_prstatus" can be
visible to userspace (from )

  "
   Generic ptrace interface that exports the architecture specific
   regsets using the corresponding NT_* types (which are also used in
   the core dump).  Please note that the NT_PRSTATUS note type in a
   core dump contains a full 'struct elf_prstatus'. But the
   user_regset for NT_PRSTATUS contains just the elf_gregset_t that is
   the pr_reg field of 'struct elf_prstatus'. For all the other
   user_regset flavors, the user_regset layout and the ELF core dump
   note payload are exactly the same layout.
  "

so it shouldn't have an "#ifdef CONFIG_" in there.

This splits the structure into two different structures, one still
named "struct elf_prstatus", and one for ELF FDPIC that is named
"struct elf_fdpic_prstatus" -- the idea here is that most users are
standard ELF, so that's the name that didn't change.

I tried to fix all the users of "struct elf_prstatus" that should now
be using "struct elf_fdpic_prstatus".  The only testing I did here was
to build a Blackfin defconfig with "struct elf_prstatus" not defined,
and to build an x86 defconfig with "struct elf_fdpic_prstatus" not
defined.

Note that this fails checkpatch.pl with a complaint about wanting open
braces on the same line as struct definitions.  The existing struct
definitions in this file have the brace a line afterwards, so I'm
going to leave this alone.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 fs/binfmt_elf_fdpic.c|  6 +++---
 fs/proc/kcore.c  | 16 
 include/linux/kexec.h|  4 
 include/uapi/linux/elfcore.h | 37 +++--
 kernel/kexec_core.c  |  4 
 5 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index d3634bfb7fe1..587bf0466d71 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -1323,7 +1323,7 @@ static inline void fill_note(struct memelfnote *note, 
const char *name, int type
  * fill up all the fields in prstatus from the given task struct, except
  * registers which need to be filled up separately.
  */
-static void fill_prstatus(struct elf_prstatus *prstatus,
+static void fill_prstatus(struct elf_fdpic_prstatus *prstatus,
  struct task_struct *p, long signr)
 {
prstatus->pr_info.si_signo = prstatus->pr_cursig = signr;
@@ -1406,7 +1406,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, 
struct task_struct *p,
 struct elf_thread_status
 {
struct list_head list;
-   struct elf_prstatus prstatus;   /* NT_PRSTATUS */
+   struct elf_fdpic_prstatus prstatus; /* NT_PRSTATUS */
elf_fpregset_t fpu; /* NT_PRFPREG */
struct task_struct *thread;
 #ifdef ELF_CORE_COPY_XFPREGS
@@ -1539,7 +1539,7 @@ static int elf_fdpic_core_dump(struct coredump_params 
*cprm)
loff_t offset = 0, dataoff;
int numnote;
struct memelfnote *notes = NULL;
-   struct elf_prstatus *prstatus = NULL;   /* NT_PRSTATUS */
+   struct elf_fdpic_prstatus *prstatus = NULL; /* NT_PRSTATUS */
struct elf_prpsinfo *psinfo = NULL; /* NT_PRPSINFO */
LIST_HEAD(thread_list);
struct list_head *t;
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 92e6726f6e37..b1edd77ec854 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -90,7 +90,11 @@ static size_t get_kcore_size(int *nphdr, size_t *elf_buflen)
(*nphdr + 2)*sizeof(struct elf_phdr) + 
3 * ((sizeof(struct elf_note)) +
 roundup(sizeof(CORE_STR), 4)) +
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+   roundup(sizeof(struct elf_fdpic_prstatus), 4) +
+#else
roundup(sizeof(struct elf_prstatus), 4) +
+#endif
roundup(sizeof(struct elf_prpsinfo), 4) +
roundup(arch_task_struct_size, 4);
*elf_buflen = PAGE_ALIGN(*elf_buflen);
@@ -318,7 +322,11 @@ static char *storenote(struct memelfnote *men, char *bufp)
  */
 static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
 {
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+   struct elf_fdpic_prstatus prstatus; /* NT_PRSTATUS */
+#else
struct elf_prstatus prstatus;   /* NT_PRSTATUS */
+#endif
struct elf_prpsinfo prpsinfo;   /* NT_PRPSINFO */
struct elf_phdr *nhdr, *phdr;
struct elfhdr *elf;
@@ -387,10 +395,18 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, 
int dataoff)
/* set up the process status */
notes[0].name = CORE_STR;
notes[0].type = NT_PRSTATUS;
+

[PATCH 03/13] Move COMPAT_ATM_ADDPARTY to net/atm/svc.c

2015-09-14 Thread Palmer Dabbelt
This used to be behind an #ifdef COMPAT_COMPAT, so most of userspace
wouldn't have seen the definition before.  Unfortunately this header
file became visible to userspace, so the definition has instead been
moved to net/atm/svc.c (the only user).

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/atmdev.h | 4 
 net/atm/svc.c   | 5 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/atmdev.h b/include/uapi/linux/atmdev.h
index 93e0ec008ca8..3dcec701501c 100644
--- a/include/uapi/linux/atmdev.h
+++ b/include/uapi/linux/atmdev.h
@@ -100,10 +100,6 @@ struct atm_dev_stats {
/* use backend to make new if */
 #define ATM_ADDPARTY   _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
/* add party to p2mp call */
-#ifdef CONFIG_COMPAT
-/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
-#define COMPAT_ATM_ADDPARTY_IOW('a', ATMIOC_SPECIAL+4,struct 
compat_atm_iobuf)
-#endif
 #define ATM_DROPPARTY  _IOW('a', ATMIOC_SPECIAL+5,int)
/* drop party from p2mp call */
 
diff --git a/net/atm/svc.c b/net/atm/svc.c
index 3fa0a9ee98d1..9e2e6ef285e8 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -27,6 +27,11 @@
 #include "signaling.h"
 #include "addr.h"
 
+#ifdef CONFIG_COMPAT
+/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
+#define COMPAT_ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4, struct 
compat_atm_iobuf)
+#endif
+
 static int svc_create(struct net *net, struct socket *sock, int protocol,
  int kern);
 
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 04/13] Always expose MAP_UNINITIALIZED to userspace

2015-09-14 Thread Palmer Dabbelt
On Mon, 14 Sep 2015 17:23:58 PDT (-0700), kir...@shutemov.name wrote:
> On Mon, Sep 14, 2015 at 03:50:38PM -0700, Palmer Dabbelt wrote:
>> This used to be hidden behind CONFIG_MMAP_ALLOW_UNINITIALIZED, so
>> userspace wouldn't actually ever see it be non-zero.  While I could
>> have kept hiding it, the man pages seem to indicate that
>> MAP_UNINITIALIZED should be visible:
>>
>>   mmap(2)
>>   MAP_UNINITIALIZED (since Linux 2.6.33)
>> Don't clear anonymous pages.  This flag is intended to improve
>> performance on embedded devices.  This flag is honored only if the
>> kernel was configured with the CONFIG_MMAP_ALLOW_UNINITIALIZED
>> option.  Because of the security implications, that option is
>> normally enabled only on embedded devices (i.e., devices where one
>> has complete control of the contents of user memory).
>>
>> and since the only time it shows up in my /usr/include is in this
>> header I believe this should have been visible to userspace (as
>> non-zero, which wouldn't do anything when or'd into the flags) all
>> along.
>
> Are you sure about "wouldn't do anything"?

That was bad writing for me.  I'd originally written something like "I
believe this should have been visible to userspace all along", but
then added the ()'s.  I meant to say:

 * I think MAP_UNINITIALIZED should have been non-zero in userspace.
 * MAP_UNINITAILIZED was zero in userspace.
 * A zero MAP_UNINITIALIZED does nothing when OR'd in.

> Suspiciously, 0x400 is also (1 << MAP_HUGE_SHIFT). I'm not sure if any
> architecture has order-1 huge pages, but still looks like we have conflict
> here.
>
> I think it's harmful to expose non-zero MAP_UNINITIALIZED to system which
> potentially can handle multiple users. Or non-trivial user space in
> general.

This doesn't have MAP_UNINITIALIZED do anything by default, it just
defines the flag the same way on all systems.  I was under the
impression that this just happened if I set MAP_UNINITIALIZED.
Looking at MAP_HUGE_SHIFT it mmap.c, that's definitely why my mmap()
test case ignored the set MAP_UNINITIALIZED on my PC.

I'm going to make this

 #ifndef MAP_UNINITAILIZED
 #define MAP_UNINITAILIZED 0
 #endif

and then leave Xtensa's port alone.  This is what Arnd suggested
originally, sorry for the extra work!

> Should we leave it at least under '#ifndef CONFIG_MMU'? I don't think it's
> possible to have single ABI for MMU and MMU-less systems anyway. And we
> can avoid conflict with MAP_HUGE_SHIFT this way.

The whole goal here was to eliminate "#ifndef CONFIG_*" from the
user-visible headers.  This all started because I got bit by a very
similar-looking bug (see patch #1), so I'd prefer not to go down that
route.

> P.S. MAP_UNINITIALIZED itself looks very broken to me. I probably need dig
> mailing list on why it was allowed.
> But that's other topic.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 09/13] Move bp_type_idx to kernel/event/hw_breakpoint.c

2015-09-15 Thread Palmer Dabbelt
On Tue, 15 Sep 2015 01:06:07 PDT (-0700), pet...@infradead.org wrote:
> On Mon, Sep 14, 2015 at 03:50:43PM -0700, Palmer Dabbelt wrote:
>> This has a "#ifdef CONFIG_*" that used to be exposed to userspace.
>>
>> The names in here are so generic that I don't think it's a good idea
>> to expose them to userspace (or even the rest of the kernel).  Since
>> there's only one kernel user, it's been moved to that file.
>>
>> Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
>> Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
>> Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
>> ---
>>  include/uapi/linux/hw_breakpoint.h | 10 --
>>  kernel/events/hw_breakpoint.c  | 10 ++
>>  2 files changed, 10 insertions(+), 10 deletions(-)
>>
>> diff --git a/include/uapi/linux/hw_breakpoint.h 
>> b/include/uapi/linux/hw_breakpoint.h
>> index b04000a2296a..7a6a5a7f9511 100644
>> --- a/include/uapi/linux/hw_breakpoint.h
>> +++ b/include/uapi/linux/hw_breakpoint.h
>> @@ -17,14 +17,4 @@ enum {
>>  HW_BREAKPOINT_INVALID   = HW_BREAKPOINT_RW | HW_BREAKPOINT_X,
>>  };
>>
>> -enum bp_type_idx {
>> -TYPE_INST   = 0,
>> -#ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
>> -TYPE_DATA   = 0,
>> -#else
>> -TYPE_DATA   = 1,
>> -#endif
>> -TYPE_MAX
>> -};
>
> This is rather unfortunate; you are correct that the naming is too
> generic (and I tend to agree), but I think these values are required by
> userspace to fill out:
>
>   perf_event_attr::bp_type
>
> So removing them will break things.
>
> Frederic?

perf_event_open(2) says

   bp_type (since Linux 2.6.33)
  This chooses the breakpoint type.  It is one of:

  HW_BREAKPOINT_EMPTY
 No breakpoint.

  HW_BREAKPOINT_R
 Count when we read the memory location.

  HW_BREAKPOINT_W
 Count when we write the memory location.

  HW_BREAKPOINT_RW
 Count when we read or write the memory location.

  HW_BREAKPOINT_X
 Count when we execute code at the memory location.

  The values can be combined via a bitwise or, but the combination
  of HW_BREAKPOINT_R or HW_BREAKPOINT_W  with  HW_BREAKPOINT_X  is
  not allowed.

so I think removing this enum from userspace is OK.  Did I miss
something?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 11/13] Always define MAX_RAW_MINORS as 65535 in userspace

2015-09-16 Thread Palmer Dabbelt
On Tue, 15 Sep 2015 13:42:47 PDT (-0700), h...@zytor.com wrote:
> On 09/14/2015 03:50 PM, Palmer Dabbelt wrote:
>> While I don't think this was ever meant to be exposed to userspace, if
>> anyone is using it then this will at least provide a correct (if
>> unlikely) definition.
>>
>> MAX_RAW_MINORS used to be used in the kernel, where it's been replaced
>> with CONFIG_MAX_RAW_MINORS.
>>
>> Note that there's a checkpatch.pl warning about a split config string
>> here, but I've left that alone.
>
> From a UAPI perspective I would think the right value would be 2^20.

Wow, I'm super surprised.  For some reason I thought major/minor
numbers were 16 bits, but according to glibc I just have no idea what
I'm doing :).

Thanks for catching this!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 09/13] Move bp_type_idx to kernel/event/hw_breakpoint.c

2015-09-16 Thread Palmer Dabbelt
On Tue, 15 Sep 2015 12:39:10 PDT (-0700), pet...@infradead.org wrote:
> On Tue, Sep 15, 2015 at 11:40:11AM -0700, Palmer Dabbelt wrote:
>> On Tue, 15 Sep 2015 01:06:07 PDT (-0700), pet...@infradead.org wrote:
>> > On Mon, Sep 14, 2015 at 03:50:43PM -0700, Palmer Dabbelt wrote:
>> >> This has a "#ifdef CONFIG_*" that used to be exposed to userspace.
>> >>
>> >> The names in here are so generic that I don't think it's a good idea
>> >> to expose them to userspace (or even the rest of the kernel).  Since
>> >> there's only one kernel user, it's been moved to that file.
>> >>
>> >> Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
>> >> Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
>> >> Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
>> >> ---
>> >>  include/uapi/linux/hw_breakpoint.h | 10 --
>> >>  kernel/events/hw_breakpoint.c  | 10 ++
>> >>  2 files changed, 10 insertions(+), 10 deletions(-)
>> >>
>> >> diff --git a/include/uapi/linux/hw_breakpoint.h 
>> >> b/include/uapi/linux/hw_breakpoint.h
>> >> index b04000a2296a..7a6a5a7f9511 100644
>> >> --- a/include/uapi/linux/hw_breakpoint.h
>> >> +++ b/include/uapi/linux/hw_breakpoint.h
>> >> @@ -17,14 +17,4 @@ enum {
>> >>   HW_BREAKPOINT_INVALID   = HW_BREAKPOINT_RW | HW_BREAKPOINT_X,
>> >>  };
>> >>
>> >> -enum bp_type_idx {
>> >> - TYPE_INST   = 0,
>> >> -#ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
>> >> - TYPE_DATA   = 0,
>> >> -#else
>> >> - TYPE_DATA   = 1,
>> >> -#endif
>> >> - TYPE_MAX
>> >> -};
>> >
>> > This is rather unfortunate; you are correct that the naming is too
>> > generic (and I tend to agree), but I think these values are required by
>> > userspace to fill out:
>> >
>> >   perf_event_attr::bp_type
>> >
>> > So removing them will break things.
>> >
>> > Frederic?
>>
>> perf_event_open(2) says
>>
>>bp_type (since Linux 2.6.33)
>>   This chooses the breakpoint type.  It is one of:
>>
>>   HW_BREAKPOINT_EMPTY
>>  No breakpoint.
>>
>>   HW_BREAKPOINT_R
>>  Count when we read the memory location.
>>
>>   HW_BREAKPOINT_W
>>  Count when we write the memory location.
>>
>>   HW_BREAKPOINT_RW
>>  Count when we read or write the memory location.
>>
>>   HW_BREAKPOINT_X
>>  Count when we execute code at the memory location.
>>
>>   The values can be combined via a bitwise or, but the 
>> combination
>>   of HW_BREAKPOINT_R or HW_BREAKPOINT_W  with  HW_BREAKPOINT_X  
>> is
>>   not allowed.
>>
>> so I think removing this enum from userspace is OK.  Did I miss
>> something?
>
> Nah, could've just been me not being awake. Unless Frederic says
> otherwise I'll chalk it up to not having drank enough morning juice.

Well, I'm going to leave this alone, then -- as Arnd pointed out in a
later email that got mis-threaded, this would be super tricky to fix
if userspace actually relied on it (which is why I was scared I was
wrong).

v4 (which is hopefully the final version of the patch set) will leave
this as it is.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 03/13] Move COMPAT_ATM_ADDPARTY to net/atm/svc.c

2015-09-17 Thread Palmer Dabbelt
On Thu, 17 Sep 2015 02:57:12 PDT (-0700), dhowe...@redhat.com wrote:
> Palmer Dabbelt <pal...@dabbelt.com> wrote:
>
>> +#ifdef CONFIG_COMPAT
>> +/* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
>> +#define COMPAT_ATM_ADDPARTY _IOW('a', ATMIOC_SPECIAL+4, struct 
>> compat_atm_iobuf)
>> +#endif
>
> I wonder if it would hurt to ditch the conditionals entirely.  It only eats
> cpp namespace, not C namespace so it won't affect the output if it is not used
> because the code that uses it is compiled out.

Makes sense to me.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 01/13] Remove #ifdef CONFIG_64BIT from all asm-generic/fcntl.h

2015-09-09 Thread Palmer Dabbelt
When working on the RISC-V port I noticed that F_SETLK64 was being
defined on our 64-bit platform, despite our port being so new that
we've only ever had the 64-bit file ops.  Since there's not compat
layer for these, this causes fcntl to bail out.

It turns out that one of the ways in with F_SETLK64 was being defined
(there's some more in glibc, but that's a whole different story... :))
is the result of CONFIG_64BIT showing up in this user-visible header.
 confirms this isn't sane, so I replaced it
with a __BITS_PER_LONG check.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/fcntl.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h
index e063effe0cc1..14a5c8237d84 100644
--- a/include/uapi/asm-generic/fcntl.h
+++ b/include/uapi/asm-generic/fcntl.h
@@ -1,6 +1,7 @@
 #ifndef _ASM_GENERIC_FCNTL_H
 #define _ASM_GENERIC_FCNTL_H
 
+#include 
 #include 
 
 /*
@@ -115,7 +116,7 @@
 #define F_GETSIG   11  /* for sockets. */
 #endif
 
-#ifndef CONFIG_64BIT
+#if (__BITS_PER_LONG == 32)
 #ifndef F_GETLK64
 #define F_GETLK64  12  /*  using 'struct flock64' */
 #define F_SETLK64  13
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/13] Make FB_BACKLIGHT_{LEVELS,MAX} always visible

2015-09-09 Thread Palmer Dabbelt
Nothing else in the kernel defines this, and this header is visible to
userspace.  Rather than hiding it in an #ifdef, I think it's sane to
just make this visible to userspace.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/fb.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/uapi/linux/fb.h b/include/uapi/linux/fb.h
index fb795c3b3c17..8926f13bc19f 100644
--- a/include/uapi/linux/fb.h
+++ b/include/uapi/linux/fb.h
@@ -392,11 +392,8 @@ struct fb_cursor {
struct fb_image image;  /* Cursor image */
 };
 
-#ifdef CONFIG_FB_BACKLIGHT
 /* Settings for the generic backlight code */
 #define FB_BACKLIGHT_LEVELS128
 #define FB_BACKLIGHT_MAX   0xFF
-#endif
-
 
 #endif /* _UAPI_LINUX_FB_H */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] Remove #ifdef CONFIG_64BIT from all asm-generic/fcntl.h

2015-09-09 Thread Palmer Dabbelt
I cut the RISC-V stuff, but I intend to reply to it later.  As you
said, it's just a different topic.

>>> However, I did see a lot of similar bugs now that you point me to it:
>>>
>>> $  grep -r \\\>> obj-tmp/usr/include/asm-generic/fcntl.h:#ifndef CONFIG_64BIT
>>> obj-tmp/usr/include/asm-generic/mman-common.h:#ifdef 
>>> CONFIG_MMAP_ALLOW_UNINITIALIZED
>>> obj-tmp/usr/include/asm-generic/unistd.h:#ifdef CONFIG_MMU
>>> obj-tmp/usr/include/asm-generic/unistd.h:#endif /* CONFIG_MMU */
>>> obj-tmp/usr/include/linux/atmdev.h:#ifdef CONFIG_COMPAT
>>> obj-tmp/usr/include/linux/elfcore.h:#ifdef CONFIG_BINFMT_ELF_FDPIC
>>> obj-tmp/usr/include/linux/eventpoll.h:#ifdef CONFIG_PM_SLEEP
>>> obj-tmp/usr/include/linux/fb.h:#ifdef CONFIG_FB_BACKLIGHT
>>> obj-tmp/usr/include/linux/flat.h:#ifdef CONFIG_BINFMT_SHARED_FLAT
>>> obj-tmp/usr/include/linux/hw_breakpoint.h:#ifdef 
>>> CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
>>> obj-tmp/usr/include/linux/pktcdvd.h:#if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
>>> obj-tmp/usr/include/linux/raw.h:#define MAX_RAW_MINORS CONFIG_MAX_RAW_DEVS
>>> obj-tmp/usr/include/asm/ptrace.h:#ifdef CONFIG_CPU_ENDIAN_BE8
>>>
>>> These all have the same problem, and we should fix them, as well as
>>> (probably) adding an automated check to scripts/headers_install.sh.
>>
>> Well, I was going to go fix them all and ran a very similar grep, but
>> I think I got a lot of false-positives.  If I understand correctly,
>> it's allowed to have CONFIG_* when guarded by __KERNEL__ in
>> user-visible headers?
>
> That is right.

It turns out there was actually a header checking script
(scripts/headers_check.pl), and it already had a check for this.  The
check was just disabled because there was "too much noise".  Rather
than putting it in headers_install I've just fixed that script.  I'm
definately lacking in perl powers, so I have no idea if what I've done
is sane.  Specifically: there's a global variable and a line over 80
characters, but since there's a bunch of other violations I figure
it's fine.

>> Now that I've written that, I realize it'd be pretty easy to just use
>> cpp to drop everything inside __KERNEL__ and then look for CONFIG_*.
>
> The lines quoted above are from the output of 'make headers_install',
> which already drops everything inside of __KERNEL__. A lot of them
> probably just need to add that #ifdef, or move the portion of the
> header file to the normal (non-uabi) file.
>
>> If you want, I can try to do that, fix what triggers the check, and
>> re-submit everything together?
>
> That would be great, yes.

OK.  I think this has turned into more of a RFC than a PATCH,
though...  I've just #ifdef'd things for now to reduce the diff size,
though I think it might be cleaner to move some of them to the
non-user headers (ep_take_care_of_epollwakeup(), USE_WCACHING,
MAX_RAW_MINORS).

I'm pretty far out of my depth here, so these should all be carefully
considered, but there's a few that scare me more ("struct
elf_prstatus", "enum by_type_idx", AT_VECTOR_SIZE_ARCH).  I think
there's only one actual bug here (MAP_UNINITIALIZED), the rest just
quiet the checking script.  Each patch has my rationale for what I
did.

Since this touches a whole lot of stuff, I've added a whole bunch of
CCs.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 13/13] Re-enable and clean up "check_config()" in headers_check.pl

2015-09-09 Thread Palmer Dabbelt
I recently got bit by a CONFIG_ in userspace bug.  This has apparently
happened before, but the check got disabled for triggering too much.
In order to reduce false positives, I added some hueristics to avoid
detecting comments.

Since these tests all pass, I've now re-enabled them.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 scripts/headers_check.pl | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/scripts/headers_check.pl b/scripts/headers_check.pl
index 62320f93e903..dd413ad9c850 100755
--- a/scripts/headers_check.pl
+++ b/scripts/headers_check.pl
@@ -40,7 +40,7 @@ foreach my $file (@files) {
_asm_types();
_sizetypes();
_declarations();
-   # Dropped for now. Too much noise _config();
+   _config();
}
close $fh;
 }
@@ -76,9 +76,24 @@ sub check_declarations
}
 }
 
+my $check_config_in_multiline_comment = 0;
 sub check_config
 {
-   if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
+   my $nocomments = $line;
+   $nocomments =~ s/\/\*.*\*\///; # Remove ANSI-style comments (/* to */)
+   $nocomments =~ s/\/\/.*//; # Remove C99-style comments (// to EOL)
+
+   # Check to see if we're within a multiline comment, and if so
+   # just remove the whole line.  I tried matching on '^ * ', but
+   # there's one header that doesn't prepend multi-line comments
+   # with * so that won't work.
+   if ($nocomments =~ m/\/\*/) { $check_config_in_multiline_comment = 1; }
+   if ($nocomments =~ m/\*\//) { $check_config_in_multiline_comment = 0; }
+   if ($check_config_in_multiline_comment == 1) { $nocomments = "" }
+
+   # Check to see if there is something that looks like CONFIG_
+   # inside a userspace-accessible header file and if so, print that out.
+   if ($nocomments =~ 
m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) {
printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace 
where it is not valid\n";
}
 }
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 08/13] Hide MAX_SHARED_LIBS behind #ifdef __KERNEL__

2015-09-09 Thread Palmer Dabbelt
I'm not sure what this is, but it doesn't feel like something that
should be exposed to userspace here.  I'm assuming this file was
exposed for the structure in it, which doesn't depend on
MAX_SHARED_LIBS.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/flat.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/uapi/linux/flat.h b/include/uapi/linux/flat.h
index 88cd6baba8f3..4ed679f3591e 100644
--- a/include/uapi/linux/flat.h
+++ b/include/uapi/linux/flat.h
@@ -13,11 +13,13 @@
 
 #defineFLAT_VERSION0x0004L
 
+#ifdef __KERNEL__
 #ifdef CONFIG_BINFMT_SHARED_FLAT
 #defineMAX_SHARED_LIBS (4)
 #else
 #defineMAX_SHARED_LIBS (1)
 #endif
+#endif /*__KERNEL__*/
 
 /*
  * To make everything easier to port and manage cross platform
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 09/13] Hide bp_type_idx behind #ifdef __KERNEL__

2015-09-09 Thread Palmer Dabbelt
I'm actually not sure what to do here: if this enum is meant to be
used by userspace, then it has to be the same regardless of kernel
configuration.  One option would be to have the kernel expose all the
values to userspace and then map them internally if
CONFIG_HAVE_MIXED_BREAKPOINT_REGS isn't set, but that feels like it'd
be more invasive.

Here I took the simple and fail-fast route to hide all the
definitions.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/hw_breakpoint.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/hw_breakpoint.h 
b/include/uapi/linux/hw_breakpoint.h
index b04000a2296a..2498bfbf56c4 100644
--- a/include/uapi/linux/hw_breakpoint.h
+++ b/include/uapi/linux/hw_breakpoint.h
@@ -17,14 +17,16 @@ enum {
HW_BREAKPOINT_INVALID   = HW_BREAKPOINT_RW | HW_BREAKPOINT_X,
 };
 
+#ifdef __KERNEL__
 enum bp_type_idx {
TYPE_INST   = 0,
-#ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
+#if defined(CONFIG_HAVE_MIXED_BREAKPOINTS_REGS)
TYPE_DATA   = 0,
 #else
TYPE_DATA   = 1,
 #endif
TYPE_MAX
 };
+#endif /* __KERNEL__ */
 
 #endif /* _UAPI_LINUX_HW_BREAKPOINT_H */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/13] Hide USE_WCACHING behind #ifdef __KERNEL__

2015-09-09 Thread Palmer Dabbelt
I don't think this was ever intended to be exposed to userspace.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/pktcdvd.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/uapi/linux/pktcdvd.h b/include/uapi/linux/pktcdvd.h
index 2640b9d4e243..e2a49bfee74e 100644
--- a/include/uapi/linux/pktcdvd.h
+++ b/include/uapi/linux/pktcdvd.h
@@ -33,11 +33,13 @@
  * able to successfully recover with this option (drive will return good
  * status as soon as the cdb is validated).
  */
+#ifdef __KERNEL__
 #if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
 #define USE_WCACHING   1
 #else
 #define USE_WCACHING   0
 #endif
+#endif /* __KERNEL__ */
 
 /*
  * No user-servicable parts beyond this point ->
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 12/13] Hide AT_VECTOR_SIZE_ARCH behind #ifdef __KERNEL__

2015-09-09 Thread Palmer Dabbelt
I think this actually isn't a good idea, but I can't find anything
outside of the kernel that's using this so I'm going to hide it.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 arch/x86/include/uapi/asm/auxvec.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/include/uapi/asm/auxvec.h 
b/arch/x86/include/uapi/asm/auxvec.h
index 77203ac352de..88e5fa6d97e7 100644
--- a/arch/x86/include/uapi/asm/auxvec.h
+++ b/arch/x86/include/uapi/asm/auxvec.h
@@ -9,11 +9,13 @@
 #endif
 #define AT_SYSINFO_EHDR33
 
+#ifdef __KERNEL__
 /* entries in ARCH_DLINFO: */
 #if defined(CONFIG_IA32_EMULATION) || !defined(CONFIG_X86_64)
 # define AT_VECTOR_SIZE_ARCH 2
 #else /* else it's non-compat x86-64 */
 # define AT_VECTOR_SIZE_ARCH 1
 #endif
+#endif /* __KERNEL__ */
 
 #endif /* _ASM_X86_AUXVEC_H */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 11/13] Hide MAX_RAW_MINORS behind #ifdef __KERNEL__

2015-09-09 Thread Palmer Dabbelt
I don't think this was ever meant to be exposed to userspace.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/raw.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/uapi/linux/raw.h b/include/uapi/linux/raw.h
index 62d543e70603..6d8d87524ff2 100644
--- a/include/uapi/linux/raw.h
+++ b/include/uapi/linux/raw.h
@@ -13,6 +13,8 @@ struct raw_config_request
__u64   block_minor;
 };
 
+#ifdef __KERNEL__
 #define MAX_RAW_MINORS CONFIG_MAX_RAW_DEVS
+#endif
 
 #endif /* __LINUX_RAW_H */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 04/13] Always expose MAP_UNINITIALIZED to userspace

2015-09-09 Thread Palmer Dabbelt
This used to be hidden behind CONFIG_MMAP_ALLOW_UNINITIALIZED, so
userspace wouldn't actually ever see it.  While I could have kept
hiding it, the man pages seem to indicate that MAP_UNINITIALIZED
should be visible:

  mmap(2)
  MAP_UNINITIALIZED (since Linux 2.6.33)
Don't clear anonymous pages.  This flag is intended to improve
performance on embedded devices.  This flag is honored only if the
kernel was configured with the CONFIG_MMAP_ALLOW_UNINITIALIZED
option.  Because of the security implications, that option is
normally enabled only on embedded devices (i.e., devices where one
has complete control of the contents of user memory).

and since the only time it shows up in my /usr/include is in this
header I believe this should have been visible to userspace (as
non-zero, which wouldn't do anything when or'd into the flags) all
along.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/mman-common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/asm-generic/mman-common.h 
b/include/uapi/asm-generic/mman-common.h
index ddc3b36f1046..e58d1911ecc6 100644
--- a/include/uapi/asm-generic/mman-common.h
+++ b/include/uapi/asm-generic/mman-common.h
@@ -19,7 +19,7 @@
 #define MAP_TYPE   0x0f/* Mask for type of mapping */
 #define MAP_FIXED  0x10/* Interpret addr exactly */
 #define MAP_ANONYMOUS  0x20/* don't use a file */
-#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
+#if !defined(__KERNEL__) || defined(CONFIG_MMAP_ALLOW_UNINITIALIZED)
 # define MAP_UNINITIALIZED 0x400   /* For anonymous mmap, memory could be 
uninitialized */
 #else
 # define MAP_UNINITIALIZED 0x0 /* Don't support this flag */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 06/13] Hide ep_take_care_of_epollwakeup() behind #ifdef __KERNEL__

2015-09-09 Thread Palmer Dabbelt
This doesn't make any sense to expose to userspace.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/eventpoll.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/uapi/linux/eventpoll.h b/include/uapi/linux/eventpoll.h
index bc81fb2e1f0e..290426bfb0aa 100644
--- a/include/uapi/linux/eventpoll.h
+++ b/include/uapi/linux/eventpoll.h
@@ -61,6 +61,7 @@ struct epoll_event {
__u64 data;
 } EPOLL_PACKED;
 
+#ifdef __KERNEL__
 #ifdef CONFIG_PM_SLEEP
 static inline void ep_take_care_of_epollwakeup(struct epoll_event *epev)
 {
@@ -73,4 +74,6 @@ static inline void ep_take_care_of_epollwakeup(struct 
epoll_event *epev)
epev->events &= ~EPOLLWAKEUP;
 }
 #endif
+#endif /*__KERNEL__*/
+
 #endif /* _UAPI_LINUX_EVENTPOLL_H */
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 05/13] Hide some of "struct elf_prstatus" behind #ifdef __KERNEL__

2015-09-09 Thread Palmer Dabbelt
This one scares me: while I can't find any system calls that directly
take this as an argument, a comment in 

  "
   Generic ptrace interface that exports the architecture specific
   regsets using the corresponding NT_* types (which are also used in
   the core dump).  Please note that the NT_PRSTATUS note type in a
   core dump contains a full 'struct elf_prstatus'. But the
   user_regset for NT_PRSTATUS contains just the elf_gregset_t that is
   the pr_reg field of 'struct elf_prstatus'. For all the other
   user_regset flavors, the user_regset layout and the ELF core dump
   note payload are exactly the same layout.
  "

seems to indicate that it's possible to see this sometimes.  Since
this would only be visible to userspace in a somewhat convoluted
manner, I'm going to try and keep it as it was.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/elfcore.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/elfcore.h b/include/uapi/linux/elfcore.h
index 569737cfb557..f9320b588937 100644
--- a/include/uapi/linux/elfcore.h
+++ b/include/uapi/linux/elfcore.h
@@ -60,7 +60,7 @@ struct elf_prstatus
longpr_instr;   /* Current instruction */
 #endif
elf_gregset_t pr_reg;   /* GP registers */
-#ifdef CONFIG_BINFMT_ELF_FDPIC
+#if defined(__KERNEL__) && defined(CONFIG_BINFMT_ELF_FDPIC)
/* When using FDPIC, the loadmap addresses need to be communicated
 * to GDB in order for GDB to do the necessary relocations.  The
 * fields (below) used to communicate this information are placed
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 02/13] Always expose __SYSCALL(... fork ...)

2015-09-09 Thread Palmer Dabbelt
I think this change actually doesn't do anything: __NR_fork was still
being defined either way, and on my machine fork() in  comes
from libc.

That said, I don't think there's any way to determine this
automatically, so this at least quiets the checker.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/asm-generic/unistd.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/uapi/asm-generic/unistd.h 
b/include/uapi/asm-generic/unistd.h
index e016bd9b1a04..e027ef7aa01f 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -865,11 +865,11 @@ __SYSCALL(__NR_uselib, sys_uselib)
 __SYSCALL(__NR__sysctl, sys_sysctl)
 
 #define __NR_fork 1079
-#ifdef CONFIG_MMU
+#if !defined(__KERNEL__) || defined(CONFIG_MMU)
 __SYSCALL(__NR_fork, sys_fork)
 #else
 __SYSCALL(__NR_fork, sys_ni_syscall)
-#endif /* CONFIG_MMU */
+#endif /* !__KERNEL__ || CONFIG_MMU */
 
 #undef __NR_syscalls
 #define __NR_syscalls (__NR_fork+1)
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 03/13] Hide COMPAT_ATM_ADDPARTY behind #ifdef __KERNEL__

2015-09-09 Thread Palmer Dabbelt
This used to just be behind an #ifdef COMPAT_COMPAT, so most of
userspace wouldn't have seen the definition before.  This change just
makes the __KERNEL__ part explicit to quiet the header checker.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Andrew Waterman <water...@eecs.berkeley.edu>
Reviewed-by: Albert Ou <a...@eecs.berkeley.edu>
---
 include/uapi/linux/atmdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/atmdev.h b/include/uapi/linux/atmdev.h
index 93e0ec008ca8..f8b6223165da 100644
--- a/include/uapi/linux/atmdev.h
+++ b/include/uapi/linux/atmdev.h
@@ -100,7 +100,7 @@ struct atm_dev_stats {
/* use backend to make new if */
 #define ATM_ADDPARTY   _IOW('a', ATMIOC_SPECIAL+4,struct atm_iobuf)
/* add party to p2mp call */
-#ifdef CONFIG_COMPAT
+#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
 /* It actually takes struct sockaddr_atmsvc, not struct atm_iobuf */
 #define COMPAT_ATM_ADDPARTY_IOW('a', ATMIOC_SPECIAL+4,struct 
compat_atm_iobuf)
 #endif
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/17] pci: Add a generic, weakly-linked pcibios_align_resource

2017-07-13 Thread Palmer Dabbelt
On Wed, 12 Jul 2017 15:50:42 PDT (-0700), helg...@kernel.org wrote:
> On Tue, Jul 11, 2017 at 06:31:15PM -0700, Palmer Dabbelt wrote:
>> Multiple architectures define this as trivial function, and I'm adding
>> another one as part of the RISC-V port.  This adds a __weak version of
>> pcibios_align_resource and deletes the now obselete ones in a handful of
>> ports.
>>
>> The only functional change should be that a handful of ports used to
>> export pcibios_fixup_bus.  Only some architectures export this, so I
>> just dropped it.
>>
>> Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
>> ---
>>  arch/arc/kernel/pcibios.c| 13 -
>>  arch/arm64/kernel/pci.c  | 17 -
>>  arch/ia64/pci/pci.c  |  7 ---
>>  arch/microblaze/pci/pci-common.c |  7 ---
>>  arch/sparc/kernel/leon_pci.c |  6 --
>>  arch/sparc/kernel/pci.c  | 10 --
>>  arch/sparc/kernel/pcic.c |  6 --
>>  arch/tile/kernel/pci.c   | 10 --
>>  arch/tile/kernel/pci_gx.c|  9 -
>>  drivers/pci/setup-res.c  | 12 
>>  10 files changed, 12 insertions(+), 85 deletions(-)
>
> I think you're making your life harder by including these cleanup
> patches in your RISC-V support.  This patch makes sense (after sorting
> out the issues Luis pointed out), but I think the simplest thing to
> expedite merging is to add the empty stubs for RISC-V like everybody
> else does, then come back after RISC-V gets merged and do the cleanup.
> Then the cleanup clearly goes via the PCI tree and isn't entangled
> with anything else.

Works for me.


Re: [PATCH 08/17] tty: New RISC-V SBI console driver

2017-07-13 Thread Palmer Dabbelt
On Thu, 13 Jul 2017 05:32:26 PDT (-0700), james.ho...@imgtec.com wrote:
> On Thu, Jul 13, 2017 at 09:59:53PM +1000, Michael Ellerman wrote:
>> Palmer Dabbelt <pal...@dabbelt.com> writes:
>>
>> > On Wed, 12 Jul 2017 04:04:00 PDT (-0700), m...@ellerman.id.au wrote:
>> >> Palmer Dabbelt <pal...@dabbelt.com> writes:
>> >>
>> >>> On Mon, 10 Jul 2017 23:21:07 PDT (-0700), m...@ellerman.id.au wrote:
>> >>>> Palmer Dabbelt <pal...@dabbelt.com> writes:
>> >>>>>
>> >>>> ...
>> >>>>> +#ifdef CONFIG_EARLY_PRINTK
>> >>>>> +static void sbi_console_write(struct console *co, const char *buf,
>> >>>>> +unsigned int n)
>> >>>>> +{
>> >>>>> +  int i;
>> >>>>> +
>> >>>>> +  for (i = 0; i < n; ++i) {
>> >>>>> +  if (buf[i] == '\n')
>> >>>>> +  sbi_console_putchar('\r');
>> >>>>> +  sbi_console_putchar(buf[i]);
>> >>>>> +  }
>> >>>>> +}
>> >>>>> +
>> >>>>> +static struct console early_console_dev __initdata = {
>> >>>>> +  .name   = "early",
>> >>>>> +  .write  = sbi_console_write,
>> >>>>> +  .flags  = CON_PRINTBUFFER | CON_BOOT,
>> >>>>
>> >>>> AFAICS you could add CON_ANYTIME here, which would mean this console
>> >>>> would print output before the CPU is online.
>> >>>>
>> >>>> I think it doesn't currently matter because you call parse_early_param()
>> >>>> from setup_arch(), at which point the boot CPU has been marked online.
>> >>>>
>> >>>> But if this console can actually work earlier then you might be better
>> >>>> off just registering it unconditionally very early.
>> >>>
>> >>> That seems like a good idea.  I'm not familiar with how all this works, 
>> >>> but
>> >>> from my understanding of this early_initcall() should be sufficient to 
>> >>> make
>> >>> this work?  The only other driver that sets CON_ANYTIME and supports
>> >>> EARLY_PRINTK is hvc_xen, but that installs a header to let init code 
>> >>> register
>> >>> the console directly.  The early_initcall mechanism seems cleaner if it 
>> >>> does
>> >>> the right thing.
>> >>
>> >> Unfortunately early_initcall is not very "early" :)  It's earlier than
>> >> all the other initcalls, but it's late compared to most of the arch boot
>> >> code.
>> >>
>> >> The early_param() will work better, ie. register the console earlier
>> >> and increase the chance of you getting output from an early crash, than
>> >> early_initcall. But it requires you to put earlyprintk on the command 
>> >> line.
>> >>
>> >> The best option is to just register the console as early as you can, ie.
>> >> as soon as it can give you output. So somewhere in your setup_arch(), or
>> >> even earlier (I haven't read your boot code).
>> >
>> > Doing it that way would require either moving the TTY driver into arch 
>> > code (it
>> > was specifically suggested we move it out) or adding a header file to allow
>> > setup_arch() to call into the driver (XEN does this, and we're doing it 
>> > for our
>> > timer, but it seems hacky).
>>
>> I think it's fairly uncontroversial to have the early console in arch
>> code, especially in a case like this where there's no code shared
>> between the console and the TTY driver. But maybe someone will prove me
>> wrong.
>>
>> Doing it the other way is not really hacky IMO, you can just have an
>> extern for the early console in one of your asm headers.
>
> For reference both metag and mips do something like this for JTAG based
> consoles (with drivers both residing in drivers/tty/):
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/metag/kernel/setup.c#n107
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/metag/kernel/setup.c#n234
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/mips/include/asm/cdmm.h#n98
> https://git.kernel.org/pub/scm/linux/kernel/git

Re: [PATCH 16/17] RISC-V: User-facing API

2017-07-13 Thread Palmer Dabbelt
On Wed, 12 Jul 2017 10:09:55 PDT (-0700), james.ho...@imgtec.com wrote:
> On Wed, Jul 12, 2017 at 09:24:24AM -0700, Palmer Dabbelt wrote:
>> On Wed, 12 Jul 2017 04:07:51 PDT (-0700), james.ho...@imgtec.com wrote:
>> > On Tue, Jul 11, 2017 at 06:31:29PM -0700, Palmer Dabbelt wrote:
>> >> diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
>> >> new file mode 100644
>> >> index ..e0a1b89583ef
>> >> --- /dev/null
>> >> +++ b/arch/riscv/kernel/signal.c
>> >> @@ -0,0 +1,289 @@
>> >
>> >> +static long setup_sigcontext(struct rt_sigframe __user *frame,
>> >> + struct pt_regs *regs)
>> >> +{
>> >> + struct sigcontext __user *sc = >uc.uc_mcontext;
>> >> + long err;
>> >> + size_t i;
>> >> + /* sc_regs is structured the same as the start of pt_regs */
>> >> + err = __copy_to_user(>sc_regs, regs, sizeof(sc->sc_regs));
>> >> + /* Save the floating-point state. */
>> >> + err |= save_d_state(regs, >sc_fpregs.d);
>> >> + /* We support no other extension state at this time. */
>> >> + for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++)
>> >> + err |= __put_user(0, >sc_fpregs.q.reserved[i]);
>> >
>> > How should userland determine how to interpret sc_fpregs? It looks like
>> > you couldn't add f or q state without using one of these reserved
>> > fields, so why not just specify a field up front to say which fp format
>> > (if any) to interpret?
>>
>> We considered that, but didn't want to tie ourserves to an extension 
>> mechanism
>> right now because we don't know what the vector extension is going to look
>> like.
>>
>> > That would allow userland wanting to interpret it to safely check that
>> > field in a forward and backward compatible way without assuming a
>> > specific format is in use.
>>
>> We set ELF_HWCAP (which percolates to userspace via the auxvec.  This 
>> contains
>> the entire set of extensions the kernel supports on the current machine, 
>> which
>> allows userspace to figure out what the format of the floating-point state 
>> is.
>
> But then (as far as I understand it) software written now could break
> once support for that extension is made available and the format
> suddenly changes (or to avoid that breakage you may need to split up
> vector values, which is not what the current union describes). Wouldn't
> it be better to define it now in such a way that you hopefully don't
> need to worry about such ABI breakage in future?
>
> E.g. does it make sense to have the fp state as an fcsr and an array of
> 32 unions, each of which can contain a 32bit, 64-bit, or 128-bit
> quantity. That assumes the vector state aliases the FP state, such that
> an FP program on a kernel with vector extensions continues to work, but
> a program using vector extensions can use the same sigcontext sensibly.

We considered the strided vesion, but it imposes a cost on the common case:
extra cache lines will be pulled in on D systems.

> Thats how the MIPS SIMD Architecture (MSA) would ideally have worked,
> but there wasn't space in the fpregs fields, so the upper 64-bits of
> each vector register needed to be added separately in the sigcontext as
> an extension, but the lower 64-bits (aliasing FP state) remaining in the
> fpregs array.
>
> Alternatively if even larger vector extensions are expected it might
> make sense to abstract further and specify the stride between fp
> registers as another field so it can be made larger in future without
> breaking software that properly uses the stride, but admitedly that adds
> complexity.

The V extension won't alias with the state of the F, D, and Q extensions (which
do alias each other).  We're planning on adding a whole extra block to the end
of sigcontext that contains the V extension state.


Re: [PATCH 8/9] RISC-V: User-facing API

2017-07-11 Thread Palmer Dabbelt
On Tue, 11 Jul 2017 06:55:28 PDT (-0700), h...@infradead.org wrote:
> On Tue, Jul 11, 2017 at 02:22:15PM +0100, Will Deacon wrote:
>> The problem is that by supporting these hypothetical designs that can't do
>> atomics, you hurt sensible designs that *can* do the atomics because you
>> force them to take an additional indirection that could otherwise be
>> avoided.
>
> Agreed.  But the new patchset seems to remove it already, so I guess
> we're fine on the kernel side.  Now we just need to make sure the
> glibc API doesn't use any indirections.
>
> Note that it might make sense to emit these for very low end nommu
> designs.  Maybe even running Linux, but in that case they'll just need
> a special non-standard ABI for very limited use cases.

glibc has never used these calls on machines with the A extension.  They're
only used in one specific header file to emulate cmpxchg, and they're guarded
by something like "#ifdef riscv_atomic".  Here's the glibc code (from a
slightly older version, glibc is also in submission so everything's a bit of a
mess there too) for reference

  /* If the A (atomic) extension is not present, we need help from the
 kernel to do atomic accesses.  Linux provides two system calls for
 this purpose.  RISCV_ATOMIC_CMPXCHG will perform an atomic compare
 and exchange operation for a 32-bit value.  RISCV_ATOMIC_CMPXCHG64
 will do the same for a 64-bit value. */

  #include 
  #include 

  #define __HAVE_64B_ATOMICS (__riscv_xlen >= 64)
  #define USE_ATOMIC_COMPILER_BUILTINS 0

  #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
(abort (), (__typeof (*mem)) 0)

  #define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
(abort (), (__typeof (*mem)) 0)

  /* The only basic operation needed is compare and exchange.  */
  #define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
({\
  INTERNAL_SYSCALL_DECL (__err);  \
  (__typeof (*mem)) INTERNAL_SYSCALL (sysriscv, __err, 4, \
  RISCV_ATOMIC_CMPXCHG, mem, oldval, newval); \
})

  #define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
({\
  INTERNAL_SYSCALL_DECL (__err);  \
  (__typeof (*mem)) INTERNAL_SYSCALL (sysriscv, __err, 4, \
  RISCV_ATOMIC_CMPXCHG64, mem, oldval, newval);   \
})

We originally had these as a special Kconfig option, but then it was pointed
out that user binaries built on non-A systems wouldn't run on A systems.  That
seemed like a bad idea, so we just enabled it everywhere.

I think we should just table this discussion for now: we can always add the
system calls back in if people build non-A Linux systems.  We'll mark our glibc
port as requiring the A extension and delete the dead code there so nothing
knows about the syscalls.

Thanks!


Re: [patches] Re: [PATCH 16/17] RISC-V: User-facing API

2017-07-11 Thread Palmer Dabbelt
On Tue, 11 Jul 2017 07:01:32 PDT (-0700), james.ho...@imgtec.com wrote:
> Hi Christoph,
>
> On Tue, Jul 11, 2017 at 06:39:48AM -0700, Christoph Hellwig wrote:
>> > +#ifdef CONFIG_64BIT
>> > +SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
>> > +  unsigned long, prot, unsigned long, flags,
>> > +  unsigned long, fd, off_t, offset)
>> > +{
>> > +  if (unlikely(offset & (~PAGE_MASK)))
>> > +  return -EINVAL;
>> > +  return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
>> > +}
>> > +#else
>> > +SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
>> > +  unsigned long, prot, unsigned long, flags,
>> > +  unsigned long, fd, off_t, offset)
>> > +{
>> > +  /*
>> > +   * Note that the shift for mmap2 is constant (12),
>> > +   * regardless of PAGE_SIZE
>> > +   */
>> > +  if (unlikely(offset & (~PAGE_MASK >> 12)))
>> > +  return -EINVAL;
>> > +  return sys_mmap_pgoff(addr, len, prot, flags, fd,
>> > +  offset >> (PAGE_SHIFT - 12));
>> > +}
>> > +#endif /* !CONFIG_64BIT */
>>
>> Most modern ports seem to expose sys_mmap_pgoff as the
>> syscall directly.  Any reason you're doing this differently?
>
> I think Palmer's patch is probably correct here. Exposing sys_mmap_pgoff
> is only really correct on 32-bit arches where the only page size is 4k.
> If other page sizes are supported then this is the correct way to handle
> it as the page offset from 32-bit userland is supposed to be in 4k
> units.
>
> 64-bit doesn't need to worry about squeezing big file offsets into the
> off_t offset so don't need to do the shift at all.
>
> See the mmap2 man page. It says "the final argument specifies the offset
> into the file in 4096-byte units", and it points out ia64 as an
> exception where it depends on the page size of the system.
>
>>
>> But even the code for the older ones should probably be consolidated..
>
> Quite probably, yes.

This looks like what arm64 does, though I'm OK either way.  Here's my attempt
at consolidating the code, even though there isn't a lot to help with:

  diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c
  index e18fc0ebdd91..4351be7d0533 100644
  --- a/arch/riscv/kernel/sys_riscv.c
  +++ b/arch/riscv/kernel/sys_riscv.c
  @@ -17,14 +17,23 @@
   #include 
   #include 

  +static long riscv_sys_mmap(unsigned long addr, unsigned long len,
  +  unsigned long prot, unsigned long flags,
  +  unsigned long fd, off_t offset,
  +  unsigned long page_shift_offset)
  +{
  +   if (unlikely(offset & (~PAGE_MASK >> page_shift_offset)))
  +   return -EINVAL;
  +   return sys_mmap_pgoff(addr, len, prot, flags, fd,
  + offset >> (PAGE_SHIFT - page_shift_offset));
  +}
  +
   #ifdef CONFIG_64BIT
   SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
  unsigned long, prot, unsigned long, flags,
  unsigned long, fd, off_t, offset)
   {
  -   if (unlikely(offset & (~PAGE_MASK)))
  -   return -EINVAL;
  -   return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> 
PAGE_SHIFT);
  +   return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 0);
   }
   #else
   SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
  @@ -35,9 +44,6 @@ SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, 
len,
   * Note that the shift for mmap2 is constant (12),
   * regardless of PAGE_SIZE
   */
  -   if (unlikely(offset & (~PAGE_MASK >> 12)))
  -   return -EINVAL;
  -   return sys_mmap_pgoff(addr, len, prot, flags, fd,
  -   offset >> (PAGE_SHIFT - 12));
  +   return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 12);
   }
   #endif /* !CONFIG_64BIT */

I'll submit this as part of our v6, which will hopefully be coming out soon.

Thanks!


Re: [PATCH 08/17] tty: New RISC-V SBI console driver

2017-07-11 Thread Palmer Dabbelt
On Mon, 10 Jul 2017 23:21:07 PDT (-0700), m...@ellerman.id.au wrote:
> Palmer Dabbelt <pal...@dabbelt.com> writes:
>>
> ...
>> +#ifdef CONFIG_EARLY_PRINTK
>> +static void sbi_console_write(struct console *co, const char *buf,
>> +  unsigned int n)
>> +{
>> +int i;
>> +
>> +for (i = 0; i < n; ++i) {
>> +if (buf[i] == '\n')
>> +sbi_console_putchar('\r');
>> +sbi_console_putchar(buf[i]);
>> +}
>> +}
>> +
>> +static struct console early_console_dev __initdata = {
>> +.name   = "early",
>> +.write  = sbi_console_write,
>> +.flags  = CON_PRINTBUFFER | CON_BOOT,
>
> AFAICS you could add CON_ANYTIME here, which would mean this console
> would print output before the CPU is online.
>
> I think it doesn't currently matter because you call parse_early_param()
> from setup_arch(), at which point the boot CPU has been marked online.
>
> But if this console can actually work earlier then you might be better
> off just registering it unconditionally very early.

That seems like a good idea.  I'm not familiar with how all this works, but
from my understanding of this early_initcall() should be sufficient to make
this work?  The only other driver that sets CON_ANYTIME and supports
EARLY_PRINTK is hvc_xen, but that installs a header to let init code register
the console directly.  The early_initcall mechanism seems cleaner if it does
the right thing.

How does this look?

  diff --git a/drivers/tty/hvc/hvc_sbi.c b/drivers/tty/hvc/hvc_sbi.c
  index 98114cbd85f1..534d6b75a2c6 100644
  --- a/drivers/tty/hvc/hvc_sbi.c
  +++ b/drivers/tty/hvc/hvc_sbi.c
  @@ -87,11 +87,11 @@ static void sbi_console_write(struct console *co, const 
char *buf,
   static struct console early_console_dev __initdata = {
  .name   = "early",
  .write  = sbi_console_write,
  -   .flags  = CON_PRINTBUFFER | CON_BOOT,
  +   .flags  = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
  .index  = -1
   };

  -static int __init setup_early_printk(char *str)
  +static int __init setup_early_printk(void)
   {
  if (early_console == NULL) {
  early_console = _console_dev;
  @@ -99,5 +99,5 @@ static int __init setup_early_printk(char *str)
  }
  return 0;
   }
  -early_param("earlyprintk", setup_early_printk);
  +early_initcall(setup_early_printk);
   #endif


Re: [PATCH 17/17] RISC-V: Build Infastructure

2017-07-11 Thread Palmer Dabbelt
On Mon, 10 Jul 2017 23:31:18 PDT (-0700), m...@ellerman.id.au wrote:
> Palmer Dabbelt <pal...@dabbelt.com> writes:
>
>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
>> new file mode 100644
>> index ..366f5f2cf106
>> --- /dev/null
>> +++ b/arch/riscv/Kconfig
>> @@ -0,0 +1,294 @@
> ...
>> +
>> +config EARLY_PRINTK
>> +bool "Early printk"
>> +default n
>> +help
>> +  This option enables special console drivers which allow the kernel
>> +  to print messages very early in the bootup process.
>> +
>> +  This is useful for kernel debugging when your machine crashes very
>> +  early before the console code is initialized. For normal operation
>> +  it is not recommended because it looks ugly and doesn't cooperate
>> +  with klogd/syslogd or the X server. You should normally N here,
>> +  unless you want to debug such a crash.
>
> Looks like you copied this text from x86? I think the comment about it
> being ugly refers to the VGA early console which you don't have, so
> that's not really accurate.
>
> And the part about it not cooperating with klogs/syslogd is true, early
> printk output doesn't go to syslog. But if you turn EARLY_PRINTK off
> then early printk output goes nowhere at all:
>
> #ifdef CONFIG_EARLY_PRINTK
> extern asmlinkage __printf(1, 2)
> void early_printk(const char *fmt, ...);
> #else
> static inline __printf(1, 2) __cold
> void early_printk(const char *s, ...) { }
> #endif
>
>
> So if you have a functional early console (which I think you do) then
> you might be better off just making this def_bool y.

I think that's best.  The SBI's EARLY_PRINTK support is quite clean, so I don't
see any reason to disable it.  How does this look?

  diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
  index 366f5f2cf106..cc274bbc29a7 100644
  --- a/arch/riscv/Kconfig
  +++ b/arch/riscv/Kconfig
  @@ -268,18 +268,7 @@ config CMDLINE_OVERRIDE
If you don't know what to do here, say N.

   config EARLY_PRINTK
  -   bool "Early printk"
  -   default n
  -   help
  - This option enables special console drivers which allow the kernel
  - to print messages very early in the bootup process.
  -
  - This is useful for kernel debugging when your machine crashes very
  - early before the console code is initialized. For normal operation
  - it is not recommended because it looks ugly and doesn't cooperate
  - with klogd/syslogd or the X server. You should normally N here,
  - unless you want to debug such a crash.
  -
  +   def_bool y

   source "lib/Kconfig.debug"


Re: RISC-V Linux Port v5

2017-07-11 Thread Palmer Dabbelt
On Tue, 11 Jul 2017 11:39:19 PDT (-0700), mcg...@kernel.org wrote:
> On Mon, Jul 10, 2017 at 06:39:07PM -0700, Palmer Dabbelt wrote:
>> Thanks to everyone who has participated in the review process so far.  I've
>> based this patch set on the current master.  Things have really started to
>> calmn down, so this is fairly similar to the v4 patch set.  The most
>> interesting changes include:
>>
>>  * We've moved back to a single patch set.
>>
>>  * SMP support has been fixed, I was accidentally running on a non-SMP
>>configuration.  There were various mistakes all over the tree as a result 
>> of
>>this.
>>
>>  * The cmpxchg syscalls have been removed, as they were deemed a bad idea.  
>> As
>>a result, RISC-V Linux systems mandate the A extension.  The cooresponding
>>Kconfig entry to enable builds on non-A systems has been removed.
>>
>>  * A few more atomic fixes: mostly fence changes, but those resulted in a
>>handful of additional macros that were no longer necessary.
>>
>>  * riscv_early_sie has been removed.
>>
>> Like last time, in case one gets eaten by the mailing list this is also
>> available as a git tree on our Git Hub
>>
>>   https://github.com/riscv/riscv-linux/tree/riscv-for-submission-arch-v5
>
> Did you forget to push ? I only see v4.

I just used the wrong URL, the patches are no longer split so there's only one
submission.

  https://github.com/riscv/riscv-linux/tree/riscv-for-submission-v5


[PATCH 09/17] RISC-V: Init and Halt Code

2017-07-10 Thread Palmer Dabbelt
This contains the various __init C functions, the initial assembly
kernel entry point, and the code to reset the system.  When a file was
init-related this patch contains the entire file.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/riscv/include/asm/bug.h   |  88 +++
 arch/riscv/include/asm/cache.h |  22 
 arch/riscv/include/asm/smp.h   |  52 +
 arch/riscv/kernel/cacheinfo.c  | 105 ++
 arch/riscv/kernel/cpu.c|  89 +++
 arch/riscv/kernel/head.S   | 151 +
 arch/riscv/kernel/irq.c|  20 
 arch/riscv/kernel/reset.c  |  36 ++
 arch/riscv/kernel/setup.c  | 246 +
 arch/riscv/kernel/smp.c| 110 ++
 arch/riscv/kernel/smpboot.c| 112 +++
 arch/riscv/kernel/time.c   |  76 +
 arch/riscv/kernel/traps.c  | 180 ++
 arch/riscv/kernel/vdso.c   | 125 +
 arch/riscv/mm/init.c   |  70 
 15 files changed, 1482 insertions(+)
 create mode 100644 arch/riscv/include/asm/bug.h
 create mode 100644 arch/riscv/include/asm/cache.h
 create mode 100644 arch/riscv/include/asm/smp.h
 create mode 100644 arch/riscv/kernel/cacheinfo.c
 create mode 100644 arch/riscv/kernel/cpu.c
 create mode 100644 arch/riscv/kernel/head.S
 create mode 100644 arch/riscv/kernel/irq.c
 create mode 100644 arch/riscv/kernel/reset.c
 create mode 100644 arch/riscv/kernel/setup.c
 create mode 100644 arch/riscv/kernel/smp.c
 create mode 100644 arch/riscv/kernel/smpboot.c
 create mode 100644 arch/riscv/kernel/time.c
 create mode 100644 arch/riscv/kernel/traps.c
 create mode 100644 arch/riscv/kernel/vdso.c
 create mode 100644 arch/riscv/mm/init.c

diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h
new file mode 100644
index ..c3e13764a943
--- /dev/null
+++ b/arch/riscv/include/asm/bug.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#ifndef _ASM_RISCV_BUG_H
+#define _ASM_RISCV_BUG_H
+
+#include 
+#include 
+#include 
+
+#include 
+
+#ifdef CONFIG_GENERIC_BUG
+#define __BUG_INSN _AC(0x00100073, UL) /* ebreak */
+
+#ifndef __ASSEMBLY__
+typedef u32 bug_insn_t;
+
+#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
+#define __BUG_ENTRY_ADDR   INT " 1b - 2b"
+#define __BUG_ENTRY_FILE   INT " %0 - 2b"
+#else
+#define __BUG_ENTRY_ADDR   RISCV_PTR " 1b"
+#define __BUG_ENTRY_FILE   RISCV_PTR " %0"
+#endif
+
+#ifdef CONFIG_DEBUG_BUGVERBOSE
+#define __BUG_ENTRY\
+   __BUG_ENTRY_ADDR "\n\t" \
+   __BUG_ENTRY_FILE "\n\t" \
+   SHORT " %1"
+#else
+#define __BUG_ENTRY\
+   __BUG_ENTRY_ADDR
+#endif
+
+#define BUG()  \
+do {   \
+   __asm__ __volatile__ (  \
+   "1:\n\t"\
+   "ebreak\n"  \
+   ".pushsection __bug_table,\"a\"\n\t"\
+   "2:\n\t"\
+   __BUG_ENTRY "\n\t"  \
+   ".org 2b + %2\n\t"  \
+   ".popsection"   \
+   :   \
+   : "i" (__FILE__), "i" (__LINE__),   \
+ "i" (sizeof(struct bug_entry)));  \
+   unreachable();  \
+} while (0)
+#endif /* !__ASSEMBLY__ */
+#else /* CONFIG_GENERIC_BUG */
+#ifndef __ASSEMBLY__
+#define BUG()  \
+do {   \
+   __asm__ __volatile__ ("ebreak\n");  \
+   unreachable();  \
+} while (0)
+#endif /* !__ASSEMBLY__ */
+#endif /* CONFIG_GENERIC_BUG */
+
+#define HAVE_ARCH_BUG
+
+#include 
+
+#ifndef __ASSEMBLY__
+
+struct pt_regs;
+struct task_struct;
+
+extern void die(struct pt_regs *regs, const c

RISC-V Linux Port v5

2017-07-10 Thread Palmer Dabbelt
Thanks to everyone who has participated in the review process so far.  I've
based this patch set on the current master.  Things have really started to
calmn down, so this is fairly similar to the v4 patch set.  The most
interesting changes include:

 * We've moved back to a single patch set.

 * SMP support has been fixed, I was accidentally running on a non-SMP
   configuration.  There were various mistakes all over the tree as a result of
   this.

 * The cmpxchg syscalls have been removed, as they were deemed a bad idea.  As
   a result, RISC-V Linux systems mandate the A extension.  The cooresponding
   Kconfig entry to enable builds on non-A systems has been removed.

 * A few more atomic fixes: mostly fence changes, but those resulted in a
   handful of additional macros that were no longer necessary.

 * riscv_early_sie has been removed.

Like last time, in case one gets eaten by the mailing list this is also
available as a git tree on our Git Hub

  https://github.com/riscv/riscv-linux/tree/riscv-for-submission-arch-v5

Thanks to everyone who has helped review our port!

[PATCH 01/17] lib: Add shared copies of some GCC library routines
[PATCH 02/17] pci: Add a generic, weakly-linked
[PATCH 03/17] pci: Add a generic, weakly-linked pcibios_fixup_bus
[PATCH 04/17] MAINTAINERS: Add RISC-V
[PATCH 05/17] clocksource: New RISC-V SBI timer driver
[PATCH 06/17] irqchip: RISC-V Local Interrupt Controller Driver
[PATCH 07/17] irqchip: New RISC-V PLIC Driver
[PATCH 08/17] tty: New RISC-V SBI console driver
[PATCH 09/17] RISC-V: Init and Halt Code
[PATCH 10/17] RISC-V: Atomic and Locking Code
[PATCH 11/17] RISC-V: Generic library routines and assembly
[PATCH 12/17] RISC-V: ELF and module implementation
[PATCH 13/17] RISC-V: Task implementation
[PATCH 14/17] RISC-V: Device, timer, IRQs, and the SBI
[PATCH 15/17] RISC-V: Paging and MMU
[PATCH 16/17] RISC-V: User-facing API
[PATCH 17/17] RISC-V: Build Infastructure


[PATCH 05/17] clocksource: New RISC-V SBI timer driver

2017-07-10 Thread Palmer Dabbelt
The RISC-V ISA defines a per-hart real-time clock and timer, which is
present on all systems.  The clock is accessed via the 'rdtime'
pseudo-instruction (which reads a CSR), and the timer is set via an SBI
call.

This driver attempts to split out the RISC-V ISA specific mechanisms of
accessing the hardware from the clocksource driver by taking a pair of
function pointers to issue the actual RISC-V specific instructions.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 drivers/clocksource/Kconfig   |  8 +
 drivers/clocksource/Makefile  |  1 +
 drivers/clocksource/riscv_timer.c | 64 +++
 include/linux/timer_riscv.h   | 41 +
 4 files changed, 114 insertions(+)
 create mode 100644 drivers/clocksource/riscv_timer.c
 create mode 100644 include/linux/timer_riscv.h

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index fcae5ca6ac92..a5829c0b3ae4 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -607,4 +607,12 @@ config CLKSRC_ST_LPC
  Enable this option to use the Low Power controller timer
  as clocksource.
 
+config RISCV_TIMER
+   bool "Timer for the RISC-V platform" if COMPILE_TEST
+   depends on RISCV
+   help
+ This enables the per-hart timer built into all RISC-V systems, which
+ is accessed via both the SBI and the rdcycle instruction.  This is
+ required for all RISC-V systems.
+
 endmenu
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 6df949402dfc..20d75b3f22e4 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -73,3 +73,4 @@ obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o
 obj-$(CONFIG_H8300_TPU)+= h8300_tpu.o
 obj-$(CONFIG_CLKSRC_ST_LPC)+= clksrc_st_lpc.o
 obj-$(CONFIG_X86_NUMACHIP) += numachip.o
+obj-$(CONFIG_RISCV_TIMER)  += riscv_timer.o
diff --git a/drivers/clocksource/riscv_timer.c 
b/drivers/clocksource/riscv_timer.c
new file mode 100644
index ..6063c7abe21c
--- /dev/null
+++ b/drivers/clocksource/riscv_timer.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * See  for the rationale behind pre-allocating per-cpu
+ * timers on RISC-V systems.
+ */
+static DEFINE_PER_CPU(struct clocksource, clock_source);
+static DEFINE_PER_CPU(struct clock_event_device, clock_event);
+
+struct clock_event_device *timer_riscv_device(int cpu)
+{
+   return _cpu(clock_event, cpu);
+}
+
+struct clocksource *timer_riscv_source(int cpu)
+{
+   return _cpu(clock_source, cpu);
+}
+
+void timer_riscv_init(int cpu_id,
+ unsigned long riscv_timebase,
+ unsigned long long (*rdtime)(struct clocksource *),
+ int (*next)(unsigned long, struct clock_event_device*))
+{
+   struct clocksource *cs = _cpu(clock_source, cpu_id);
+   struct clock_event_device *ce = _cpu(clock_event, cpu_id);
+
+   *cs = (struct clocksource) {
+   .name = "riscv_clocksource",
+   .rating = 300,
+   .read = rdtime,
+   .mask = CLOCKSOURCE_MASK(BITS_PER_LONG),
+   .flags = CLOCK_SOURCE_IS_CONTINUOUS,
+   };
+   clocksource_register_hz(cs, riscv_timebase);
+
+   *ce = (struct clock_event_device){
+   .name = "riscv_timer_clockevent",
+   .features = CLOCK_EVT_FEAT_ONESHOT,
+   .rating = 300,
+   .cpumask = cpumask_of(cpu_id),
+   .set_next_event = next,
+   .set_state_oneshot  = NULL,
+   .set_state_shutdown = NULL,
+   };
+   clockevents_config_and_register(ce, riscv_timebase, 100, 0x7fff);
+}
diff --git a/include/linux/timer_riscv.h b/include/linux/timer_riscv.h
new file mode 100644
index ..f2f91fe46979
--- /dev/null
+++ b/include/linux/timer_riscv.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FI

[PATCH 14/17] RISC-V: Device, timer, IRQs, and the SBI

2017-07-10 Thread Palmer Dabbelt
This patch contains code that interfaces with devices that are mandated
by the RISC-V supervisor specification and that don't have explicit
drivers anywhere else in the tree.  This includes the staticly defined
interrupts, the CSR-mapped timer, and virtualized SBI devices.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/riscv/include/asm/delay.h   |  28 +
 arch/riscv/include/asm/dma-mapping.h |  38 
 arch/riscv/include/asm/irq.h |  28 +
 arch/riscv/include/asm/irqflags.h|  63 
 arch/riscv/include/asm/pci.h |  48 +++
 arch/riscv/include/asm/sbi.h | 100 +++
 arch/riscv/include/asm/timex.h   |  59 +++
 arch/riscv/lib/delay.c   | 110 +++
 arch/riscv/mm/ioremap.c  |  92 +
 9 files changed, 566 insertions(+)
 create mode 100644 arch/riscv/include/asm/delay.h
 create mode 100644 arch/riscv/include/asm/dma-mapping.h
 create mode 100644 arch/riscv/include/asm/irq.h
 create mode 100644 arch/riscv/include/asm/irqflags.h
 create mode 100644 arch/riscv/include/asm/pci.h
 create mode 100644 arch/riscv/include/asm/sbi.h
 create mode 100644 arch/riscv/include/asm/timex.h
 create mode 100644 arch/riscv/lib/delay.c
 create mode 100644 arch/riscv/mm/ioremap.c

diff --git a/arch/riscv/include/asm/delay.h b/arch/riscv/include/asm/delay.h
new file mode 100644
index ..cbb0c9eb96cb
--- /dev/null
+++ b/arch/riscv/include/asm/delay.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2009 Chen Liqin <liqin.c...@sunplusct.com>
+ * Copyright (C) 2016 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#ifndef _ASM_RISCV_DELAY_H
+#define _ASM_RISCV_DELAY_H
+
+extern unsigned long riscv_timebase;
+
+#define udelay udelay
+extern void udelay(unsigned long usecs);
+
+#define ndelay ndelay
+extern void ndelay(unsigned long nsecs);
+
+extern void __delay(unsigned long cycles);
+
+#endif /* _ASM_RISCV_DELAY_H */
diff --git a/arch/riscv/include/asm/dma-mapping.h 
b/arch/riscv/include/asm/dma-mapping.h
new file mode 100644
index ..3eec1000196d
--- /dev/null
+++ b/arch/riscv/include/asm/dma-mapping.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2003-2004 Hewlett-Packard Co
+ * David Mosberger-Tang <dav...@hpl.hp.com>
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2016 SiFive, Inc.
+ *
+ * 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_RISCV_DMA_MAPPING_H
+#define __ASM_RISCV_DMA_MAPPING_H
+
+/* Use ops->dma_mapping_error (if it exists) or assume success */
+// #undef DMA_ERROR_CODE
+
+static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
+{
+   return _noop_ops;
+}
+
+static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t 
size)
+{
+   if (!dev->dma_mask)
+   return false;
+
+   return addr + size - 1 <= *dev->dma_mask;
+}
+
+#endif /* __ASM_RISCV_DMA_MAPPING_H */
diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h
new file mode 100644
index ..4dee9d4c13c0
--- /dev/null
+++ b/arch/riscv/include/asm/irq.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#ifndef _ASM_RISCV_IRQ_H
+#define _ASM_RISCV_IRQ_H
+
+#define NR_IRQS 0
+
+#define INTERRUPT_CAUSE_SOFTWARE1
+#define INTERRUPT_CAUSE_TIMER   5
+#define I

[PATCH 02/17] pci: Add a generic, weakly-linked pcibios_align_resource

2017-07-10 Thread Palmer Dabbelt
Multiple architectures define this as trivial function, and I'm adding
another one as part of the RISC-V port.  This adds a __weak version of
pcibios_align_resource and deletes the now obselete ones in a handful of
ports.

The only functional change should be that a handful of ports used to
export pcibios_fixup_bus.  Only some architectures export this, so I
just dropped it.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/arc/kernel/pcibios.c| 13 -
 arch/arm64/kernel/pci.c  | 17 -
 arch/ia64/pci/pci.c  |  7 ---
 arch/microblaze/pci/pci-common.c |  7 ---
 arch/sparc/kernel/leon_pci.c |  6 --
 arch/sparc/kernel/pci.c  | 10 --
 arch/sparc/kernel/pcic.c |  6 --
 arch/tile/kernel/pci.c   | 10 --
 arch/tile/kernel/pci_gx.c|  9 -
 drivers/pci/setup-res.c  | 12 
 10 files changed, 12 insertions(+), 85 deletions(-)

diff --git a/arch/arc/kernel/pcibios.c b/arch/arc/kernel/pcibios.c
index 72e1d73d0bd6..05aba5a7b5d2 100644
--- a/arch/arc/kernel/pcibios.c
+++ b/arch/arc/kernel/pcibios.c
@@ -7,16 +7,3 @@
  */
 
 #include 
-
-/*
- * We don't have to worry about legacy ISA devices, so nothing to do here
- */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-   resource_size_t size, resource_size_t align)
-{
-   return res->start;
-}
-
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}
diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c
index e2b7e4f9cc31..0e2ea1c78542 100644
--- a/arch/arm64/kernel/pci.c
+++ b/arch/arm64/kernel/pci.c
@@ -22,23 +22,6 @@
 #include 
 #include 
 
-/*
- * Called after each bus is probed, but before its children are examined
- */
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-   /* nothing to do, expected to be removed in the future */
-}
-
-/*
- * We don't have to worry about legacy ISA devices, so nothing to do here
- */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-   resource_size_t size, resource_size_t align)
-{
-   return res->start;
-}
-
 #ifdef CONFIG_ACPI
 /*
  * Try to assign the IRQ number when probing a new device
diff --git a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c
index 4068bde623dc..f5ec736100ee 100644
--- a/arch/ia64/pci/pci.c
+++ b/arch/ia64/pci/pci.c
@@ -411,13 +411,6 @@ pcibios_disable_device (struct pci_dev *dev)
acpi_pci_irq_disable(dev);
 }
 
-resource_size_t
-pcibios_align_resource (void *data, const struct resource *res,
-   resource_size_t size, resource_size_t align)
-{
-   return res->start;
-}
-
 /**
  * ia64_pci_get_legacy_mem - generic legacy mem routine
  * @bus: bus to get legacy memory base address for
diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c
index 404fb38d06b7..7a332e9f1de0 100644
--- a/arch/microblaze/pci/pci-common.c
+++ b/arch/microblaze/pci/pci-common.c
@@ -829,13 +829,6 @@ EXPORT_SYMBOL(pcibios_fixup_bus);
  * but we want to try to avoid allocating at 0x2900-0x2bff
  * which might have be mirrored at 0x0100-0x03ff..
  */
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-   resource_size_t size, resource_size_t align)
-{
-   return res->start;
-}
-EXPORT_SYMBOL(pcibios_align_resource);
-
 int pcibios_add_device(struct pci_dev *dev)
 {
dev->irq = of_irq_parse_and_map_pci(dev, 0, 0);
diff --git a/arch/sparc/kernel/leon_pci.c b/arch/sparc/kernel/leon_pci.c
index 4371f72ff025..0eafdf3d036d 100644
--- a/arch/sparc/kernel/leon_pci.c
+++ b/arch/sparc/kernel/leon_pci.c
@@ -94,9 +94,3 @@ void pcibios_fixup_bus(struct pci_bus *pbus)
}
}
 }
-
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-   resource_size_t size, resource_size_t align)
-{
-   return res->start;
-}
diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
index 7eceaa10836f..3f8670c92951 100644
--- a/arch/sparc/kernel/pci.c
+++ b/arch/sparc/kernel/pci.c
@@ -690,16 +690,6 @@ struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,
return bus;
 }
 
-void pcibios_fixup_bus(struct pci_bus *pbus)
-{
-}
-
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-   resource_size_t size, resource_size_t align)
-{
-   return res->start;
-}
-
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
u16 cmd, oldcmd;
diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c
index a38787b84322..e038e343f2c1 100644
--- a/arch/sparc/kernel/pcic.c
+++ b/arch/sparc/kernel/pcic.c
@@ -746,12 +746,6 @@ static void watchdog_reset() {
 }
 #endif
 
-resource_size_t pcibios_align_resource(void *data, const struct resource *res,
-

[PATCH 08/17] tty: New RISC-V SBI console driver

2017-07-10 Thread Palmer Dabbelt
The RISC-V ISA defines a simple console that is availiable via SBI calls
on all systems.  This patch adds a driver for this console interface
that can act as both a target for early printk and as the system
console.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 drivers/tty/hvc/Kconfig   |  11 +
 drivers/tty/hvc/Makefile  |   1 +
 drivers/tty/hvc/hvc_sbi.c | 103 ++
 3 files changed, 115 insertions(+)
 create mode 100644 drivers/tty/hvc/hvc_sbi.c

diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig
index b8d5ea0ae26b..24cbaaf47d8d 100644
--- a/drivers/tty/hvc/Kconfig
+++ b/drivers/tty/hvc/Kconfig
@@ -97,6 +97,17 @@ config HVC_BFIN_JTAG
 the HVC driver.  If you don't have JTAG, then you probably don't
 want this option.
 
+config HVC_SBI
+   bool "SBI console support"
+   depends on RISCV
+   select HVC_DRIVER
+   default y
+   help
+ This enables support for console output via RISC-V SBI calls, which
+ is normally used only during boot to output printk.
+
+ If you don't know what do to here, say Y.
+
 config HVCS
tristate "IBM Hypervisor Virtual Console Server support"
depends on PPC_PSERIES && HVC_CONSOLE
diff --git a/drivers/tty/hvc/Makefile b/drivers/tty/hvc/Makefile
index 6a2702be76d1..2d63bfe4a96b 100644
--- a/drivers/tty/hvc/Makefile
+++ b/drivers/tty/hvc/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_HVC_IUCV)+= hvc_iucv.o
 obj-$(CONFIG_HVC_UDBG) += hvc_udbg.o
 obj-$(CONFIG_HVC_BFIN_JTAG)+= hvc_bfin_jtag.o
 obj-$(CONFIG_HVCS) += hvcs.o
+obj-$(CONFIG_HVC_SBI)  += hvc_sbi.o
diff --git a/drivers/tty/hvc/hvc_sbi.c b/drivers/tty/hvc/hvc_sbi.c
new file mode 100644
index ..98114cbd85f1
--- /dev/null
+++ b/drivers/tty/hvc/hvc_sbi.c
@@ -0,0 +1,103 @@
+/*
+ * RISC-V SBI interface to hvc_console.c
+ *  based on drivers-tty/hvc/hvc_udbg.c
+ *
+ * Copyright (C) 2008 David Gibson, IBM Corporation
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "hvc_console.h"
+
+static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
+{
+   int i;
+
+   for (i = 0; i < count; i++)
+   sbi_console_putchar(buf[i]);
+
+   return i;
+}
+
+static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
+{
+   int i, c;
+
+   for (i = 0; i < count; i++) {
+   if ((c = sbi_console_getchar()) < 0)
+   break;
+   buf[i] = c;
+   }
+
+   return i;
+}
+
+static const struct hv_ops hvc_sbi_ops = {
+   .get_chars = hvc_sbi_tty_get,
+   .put_chars = hvc_sbi_tty_put,
+};
+
+static int __init hvc_sbi_init(void)
+{
+   return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, _sbi_ops, 16));
+}
+device_initcall(hvc_sbi_init);
+
+static int __init hvc_sbi_console_init(void)
+{
+   hvc_instantiate(0, 0, _sbi_ops);
+   add_preferred_console("hvc", 0, NULL);
+
+   return 0;
+}
+console_initcall(hvc_sbi_console_init);
+
+#ifdef CONFIG_EARLY_PRINTK
+static void sbi_console_write(struct console *co, const char *buf,
+ unsigned int n)
+{
+   int i;
+
+   for (i = 0; i < n; ++i) {
+   if (buf[i] == '\n')
+   sbi_console_putchar('\r');
+   sbi_console_putchar(buf[i]);
+   }
+}
+
+static struct console early_console_dev __initdata = {
+   .name   = "early",
+   .write  = sbi_console_write,
+   .flags  = CON_PRINTBUFFER | CON_BOOT,
+   .index  = -1
+};
+
+static int __init setup_early_printk(char *str)
+{
+   if (early_console == NULL) {
+   early_console = _console_dev;
+   register_console(early_console);
+   }
+   return 0;
+}
+early_param("earlyprintk", setup_early_printk);
+#endif
-- 
2.13.0



[PATCH 04/17] MAINTAINERS: Add RISC-V

2017-07-10 Thread Palmer Dabbelt
From: Jonathan Neuschäfer <j.neuschae...@gmx.net>

RISC-V needs a MAINTAINERS entry. Let's add one.

Signed-off-by: Jonathan Neuschäfer <j.neuschae...@gmx.net>
Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index d8eab9322ba2..3ead16565003 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11180,6 +11180,14 @@ M: Maxim Levitsky <maximlevit...@gmail.com>
 S: Maintained
 F: drivers/memstick/host/r592.*
 
+RISC-V ARCHITECTURE
+M: Palmer Dabbelt <pal...@sifive.com>
+M: Albert Ou <alb...@sifive.com>
+L: patc...@groups.riscv.org
+T: git https://github.com/riscv/riscv-linux
+S: Supported
+F: arch/riscv/
+
 ROCCAT DRIVERS
 M: Stefan Achatz <erazor...@users.sourceforge.net>
 W: http://sourceforge.net/projects/roccat/
-- 
2.13.0



Re: [PATCH 01/17] lib: Add shared copies of some GCC library routines

2017-07-10 Thread Palmer Dabbelt
On Mon, 10 Jul 2017 19:02:19 PDT (-0700), s...@canb.auug.org.au wrote:
> Hi Palmer,
>
> On Mon, 10 Jul 2017 18:39:08 -0700 Palmer Dabbelt <pal...@dabbelt.com> wrote:
>>
>> This patch adds a new copy of these library routine files, which are
>> functionally identical to the various other copies.  These are
>> availiable via Kconfig as CONFIG_LIB_$ROUTINE, which currently isn't
>
> Umm, the patch actually uses CONFIG_GENERIC_$ROUTINE.

IIRC someone suggested I change the Kconfig name, but I must have forgotten to
change the commit message.  I'll fix that up if we do a v6.

>
>> +config GENERIC_ASHLDI3
>> +def_bool n
>
> Just
>   bool
> is the same.

OK, that'll go in the v6 as well.

Thanks!


Re: [patches] Re: [PATCH 01/17] lib: Add shared copies of some GCC library routines

2017-07-10 Thread Palmer Dabbelt
On Mon, 10 Jul 2017 19:03:44 PDT (-0700), rdun...@infradead.org wrote:
> On 07/10/2017 07:02 PM, Stephen Rothwell wrote:
>> Hi Palmer,
>>
>> On Mon, 10 Jul 2017 18:39:08 -0700 Palmer Dabbelt <pal...@dabbelt.com> wrote:
>>>
>>> This patch adds a new copy of these library routine files, which are
>>> functionally identical to the various other copies.  These are
>>> availiable via Kconfig as CONFIG_LIB_$ROUTINE, which currently isn't
>>
>> Umm, the patch actually uses CONFIG_GENERIC_$ROUTINE.
>>
>>> +config GENERIC_ASHLDI3
>>> +   def_bool n
>>
>> Just
>>  bool
>> is the same.
>>
>
> and several "default n" lines can (should) be removed from Kconfig.

I'm not much of a Kconfig hacker...  How does this look?

commit 4aaad1e6e8a70020dd95b8a13a4075af97cb858f
Author: Palmer Dabbelt <pal...@dabbelt.com>
Date:   Mon Jul 10 19:07:43 2017 -0700

lib: Remove "default n" lines from Kconfig

These lines aren't necessary, as the default is "n" anyway.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>

diff --git a/lib/Kconfig b/lib/Kconfig
index ee7d8bf0b7e1..78dec2408481 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -15,7 +15,6 @@ config BITREVERSE

 config HAVE_ARCH_BITREVERSE
bool
-   default n
depends on BITREVERSE
help
  This option enables the use of hardware bit-reversal instructions on
@@ -48,7 +47,6 @@ config GENERIC_IOMAP

 config GENERIC_IO
bool
-   default n

 config STMP_DEVICE
bool
@@ -199,7 +197,6 @@ config AUDIT_GENERIC

 config AUDIT_ARCH_COMPAT_GENERIC
bool
-   default n

 config AUDIT_COMPAT_GENERIC
bool
@@ -208,7 +205,6 @@ config AUDIT_COMPAT_GENERIC

 config RANDOM32_SELFTEST
bool "PRNG perform self test on init"
-   default n
help
  This option enables the 32 bit PRNG library functions to perform a
  self test on initialization.
@@ -405,12 +401,10 @@ config HAS_DMA
 config DMA_NOOP_OPS
bool
depends on HAS_DMA && (!64BIT || ARCH_DMA_ADDR_T_64BIT)
-   default n

 config DMA_VIRT_OPS
bool
depends on HAS_DMA && (!64BIT || ARCH_DMA_ADDR_T_64BIT)
-   default n

 config CHECK_SIGNATURE
bool



[PATCH 17/17] RISC-V: Build Infastructure

2017-07-10 Thread Palmer Dabbelt
This patch contains all the build infastructure that actually enables
the RISC-V port.  This includes Makefiles, linker scripts, and Kconfig
files.  It also contains the only top-level change, which adds RISC-V to
the list of architectures that need a sed run to produce the ARCH
variable when building locally.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 Makefile  |   3 +-
 arch/riscv/Kconfig| 294 ++
 arch/riscv/Makefile   |  64 +++
 arch/riscv/configs/freedom-u500_defconfig |  52 ++
 arch/riscv/configs/spike32_defconfig  |  50 +
 arch/riscv/configs/spike64_defconfig  |  46 +
 arch/riscv/include/asm/Kbuild |  61 +++
 arch/riscv/kernel/.gitignore  |   1 +
 arch/riscv/kernel/Makefile|  33 
 arch/riscv/kernel/vmlinux.lds.S   |  92 ++
 arch/riscv/lib/Makefile   |   6 +
 arch/riscv/mm/Makefile|   4 +
 12 files changed, 705 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/Kconfig
 create mode 100644 arch/riscv/Makefile
 create mode 100644 arch/riscv/configs/freedom-u500_defconfig
 create mode 100644 arch/riscv/configs/spike32_defconfig
 create mode 100644 arch/riscv/configs/spike64_defconfig
 create mode 100644 arch/riscv/include/asm/Kbuild
 create mode 100644 arch/riscv/kernel/.gitignore
 create mode 100644 arch/riscv/kernel/Makefile
 create mode 100644 arch/riscv/kernel/vmlinux.lds.S
 create mode 100644 arch/riscv/lib/Makefile
 create mode 100644 arch/riscv/mm/Makefile

diff --git a/Makefile b/Makefile
index 06ef9947cf7c..1a68b7b9b627 100644
--- a/Makefile
+++ b/Makefile
@@ -225,7 +225,8 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e 
s/x86_64/x86/ \
  -e s/arm.*/arm/ -e s/sa110/arm/ \
  -e s/s390x/s390/ -e s/parisc64/parisc/ \
  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
- -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
+ -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+ -e s/riscv.*/riscv/)
 
 # Cross compiling and selecting different set of gcc/bin-utils
 # ---
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
new file mode 100644
index ..366f5f2cf106
--- /dev/null
+++ b/arch/riscv/Kconfig
@@ -0,0 +1,294 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config RISCV
+   def_bool y
+   select OF
+   select OF_EARLY_FLATTREE
+   select OF_IRQ
+   select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
+   select ARCH_WANT_FRAME_POINTERS
+   select CLONE_BACKWARDS
+   select COMMON_CLK
+   select GENERIC_CLOCKEVENTS
+   select GENERIC_CPU_DEVICES
+   select GENERIC_IRQ_SHOW
+   select GENERIC_PCI_IOMAP
+   select GENERIC_STRNCPY_FROM_USER
+   select GENERIC_STRNLEN_USER
+   select GENERIC_SMP_IDLE_THREAD
+   select GENERIC_ATOMIC64 if !64BIT || !ISA_A
+   select ARCH_WANT_OPTIONAL_GPIOLIB
+   select HAVE_MEMBLOCK
+   select HAVE_DMA_API_DEBUG
+   select HAVE_DMA_CONTIGUOUS
+   select HAVE_GENERIC_DMA_COHERENT
+   select IRQ_DOMAIN
+   select NO_BOOTMEM
+   select ISA_A if SMP
+   select SYSRISCV_ATOMIC if !ISA_A
+   select SPARSE_IRQ
+   select SYSCTL_EXCEPTION_TRACE
+   select HAVE_ARCH_TRACEHOOK
+   select MODULES_USE_ELF_RELA if MODULES
+   select THREAD_INFO_IN_TASK
+   select RISCV_IRQ_INTC
+   select RISCV_TIMER
+
+config MMU
+   def_bool y
+
+# even on 32-bit, physical (and DMA) addresses are > 32-bits
+config ARCH_PHYS_ADDR_T_64BIT
+   def_bool y
+
+config ARCH_DMA_ADDR_T_64BIT
+   def_bool y
+
+config STACKTRACE_SUPPORT
+   def_bool y
+
+config RWSEM_GENERIC_SPINLOCK
+   def_bool y
+
+config GENERIC_BUG
+   def_bool y
+   depends on BUG
+   select GENERIC_BUG_RELATIVE_POINTERS if 64BIT
+
+config GENERIC_BUG_RELATIVE_POINTERS
+   bool
+
+config GENERIC_CALIBRATE_DELAY
+   def_bool y
+
+config GENERIC_CSUM
+   def_bool y
+
+config GENERIC_HWEIGHT
+   def_bool y
+
+config PGTABLE_LEVELS
+   int
+   default 3 if 64BIT
+   default 2
+
+config HAVE_KPROBES
+   def_bool n
+
+config DMA_NOOP_OPS
+   def_bool y
+
+menu "Platform type"
+
+config SMP
+   bool "Symmetric Multi-Processing"
+   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 pr

[PATCH 10/17] RISC-V: Atomic and Locking Code

2017-07-10 Thread Palmer Dabbelt
This contains all the code that directly interfaces with the RISC-V
memory model.  While this code corforms to the current RISC-V ISA
specifications (user 2.2 and priv 1.10), the memory model is somewhat
underspecified in those documents.  There is a working group that hopes
to produce a formal memory model by the end of the year, but my
understanding is that the basic definitions we're relying on here won't
change significantly.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/riscv/include/asm/atomic.h | 328 
 arch/riscv/include/asm/barrier.h|  68 +++
 arch/riscv/include/asm/bitops.h | 216 +
 arch/riscv/include/asm/cacheflush.h |  39 
 arch/riscv/include/asm/cmpxchg.h| 134 +
 arch/riscv/include/asm/io.h | 180 ++
 arch/riscv/include/asm/spinlock.h   | 165 
 arch/riscv/include/asm/spinlock_types.h |  33 
 arch/riscv/include/asm/tlb.h|  24 +++
 arch/riscv/include/asm/tlbflush.h   |  64 +++
 10 files changed, 1251 insertions(+)
 create mode 100644 arch/riscv/include/asm/atomic.h
 create mode 100644 arch/riscv/include/asm/barrier.h
 create mode 100644 arch/riscv/include/asm/bitops.h
 create mode 100644 arch/riscv/include/asm/cacheflush.h
 create mode 100644 arch/riscv/include/asm/cmpxchg.h
 create mode 100644 arch/riscv/include/asm/io.h
 create mode 100644 arch/riscv/include/asm/spinlock.h
 create mode 100644 arch/riscv/include/asm/spinlock_types.h
 create mode 100644 arch/riscv/include/asm/tlb.h
 create mode 100644 arch/riscv/include/asm/tlbflush.h

diff --git a/arch/riscv/include/asm/atomic.h b/arch/riscv/include/asm/atomic.h
new file mode 100644
index ..ee3ab06e492b
--- /dev/null
+++ b/arch/riscv/include/asm/atomic.h
@@ -0,0 +1,328 @@
+/*
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_RISCV_ATOMIC_H
+#define _ASM_RISCV_ATOMIC_H
+
+#ifdef CONFIG_GENERIC_ATOMIC64
+# include 
+#else
+# if (__riscv_xlen < 64)
+#  error "64-bit atomics require XLEN to be at least 64"
+# endif
+#endif
+
+#include 
+#include 
+
+#define ATOMIC_INIT(i) { (i) }
+static __always_inline int atomic_read(const atomic_t *v)
+{
+   return READ_ONCE(v->counter);
+}
+static __always_inline void atomic_set(atomic_t *v, int i)
+{
+   WRITE_ONCE(v->counter, i);
+}
+
+#ifndef CONFIG_GENERIC_ATOMIC64
+#define ATOMIC64_INIT(i) { (i) }
+static __always_inline int atomic64_read(const atomic64_t *v)
+{
+   return READ_ONCE(v->counter);
+}
+static __always_inline void atomic64_set(atomic64_t *v, int i)
+{
+   WRITE_ONCE(v->counter, i);
+}
+#endif
+
+/*
+ * First, the atomic ops that have no ordering constraints and therefor don't
+ * have the AQ or RL bits set.  These don't return anything, so there's only
+ * one version to worry about.
+ */
+#define ATOMIC_OP(op, asm_op, c_op, I, asm_type, c_type, prefix)   
\
+static __always_inline void atomic##prefix##_##op(c_type i, atomic##prefix##_t 
*v) \
+{  
\
+   __asm__ __volatile__ (  
\
+   "amo" #asm_op "." #asm_type " zero, %1, %0" 
\
+   : "+A" (v->counter) 
\
+   : "r" (I)   
\
+   : "memory");
\
+}
+
+#ifdef CONFIG_GENERIC_ATOMIC64
+#define ATOMIC_OPS(op, asm_op, c_op, I)\
+ATOMIC_OP (op, asm_op, c_op, I, w,  int,   )
+#else
+#define ATOMIC_OPS(op, asm_op, c_op, I)\
+ATOMIC_OP (op, asm_op, c_op, I, w,  int,   )   \
+ATOMIC_OP (op, asm_op, c_op, I, d, long, 64)
+#endif
+
+ATOMIC_OPS(add, add, +,  i)
+ATOMIC_OPS(sub, add, +, -i)
+ATOMIC_OPS(and, and, &,  i)
+ATOMIC_OPS( or,  or, |,  i)
+ATOMIC_OPS(xor, xor, ^,  i)
+
+#undef ATOMIC_OP
+#undef ATOMIC_OPS
+
+/*
+ * Atomic ops that have ordered, relaxed, acquire, and relese variants.
+ * There's two flavors of these: the arithmatic ops have both fetch and return
+ * versions, while the logical ops only have fetch versions.
+ */
+#define ATOMIC_FETCH_OP(op, asm_op, c_op, I, asm_or, c_or, asm_type, c_type, 
prefix) 

[PATCH 11/17] RISC-V: Generic library routines and assembly

2017-07-10 Thread Palmer Dabbelt
This patch contains code that is more specific to the RISC-V ISA than it
is to Linux.  It contains string and math operations, C wrappers for
various assembly instructions, stack walking code, and uaccess.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/riscv/include/asm/asm.h|  76 +
 arch/riscv/include/asm/csr.h| 125 
 arch/riscv/include/asm/linkage.h|  20 ++
 arch/riscv/include/asm/string.h |  26 ++
 arch/riscv/include/asm/uaccess.h| 513 
 arch/riscv/include/asm/word-at-a-time.h |  55 
 arch/riscv/kernel/stacktrace.c  | 177 +++
 arch/riscv/lib/memcpy.S | 115 +++
 arch/riscv/lib/memset.S | 120 
 arch/riscv/lib/uaccess.S| 117 
 arch/riscv/lib/udivdi3.S|  38 +++
 11 files changed, 1382 insertions(+)
 create mode 100644 arch/riscv/include/asm/asm.h
 create mode 100644 arch/riscv/include/asm/csr.h
 create mode 100644 arch/riscv/include/asm/linkage.h
 create mode 100644 arch/riscv/include/asm/string.h
 create mode 100644 arch/riscv/include/asm/uaccess.h
 create mode 100644 arch/riscv/include/asm/word-at-a-time.h
 create mode 100644 arch/riscv/kernel/stacktrace.c
 create mode 100644 arch/riscv/lib/memcpy.S
 create mode 100644 arch/riscv/lib/memset.S
 create mode 100644 arch/riscv/lib/uaccess.S
 create mode 100644 arch/riscv/lib/udivdi3.S

diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h
new file mode 100644
index ..6cbbb6a68d76
--- /dev/null
+++ b/arch/riscv/include/asm/asm.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2015 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#ifndef _ASM_RISCV_ASM_H
+#define _ASM_RISCV_ASM_H
+
+#ifdef __ASSEMBLY__
+#define __ASM_STR(x)   x
+#else
+#define __ASM_STR(x)   #x
+#endif
+
+#if __riscv_xlen == 64
+#define __REG_SEL(a, b)__ASM_STR(a)
+#elif __riscv_xlen == 32
+#define __REG_SEL(a, b)__ASM_STR(b)
+#else
+#error "Unexpected __riscv_xlen"
+#endif
+
+#define REG_L  __REG_SEL(ld, lw)
+#define REG_S  __REG_SEL(sd, sw)
+#define SZREG  __REG_SEL(8, 4)
+#define LGREG  __REG_SEL(3, 2)
+
+#if __SIZEOF_POINTER__ == 8
+#ifdef __ASSEMBLY__
+#define RISCV_PTR  .dword
+#define RISCV_SZPTR8
+#define RISCV_LGPTR3
+#else
+#define RISCV_PTR  ".dword"
+#define RISCV_SZPTR"8"
+#define RISCV_LGPTR"3"
+#endif
+#elif __SIZEOF_POINTER__ == 4
+#ifdef __ASSEMBLY__
+#define RISCV_PTR  .word
+#define RISCV_SZPTR4
+#define RISCV_LGPTR2
+#else
+#define RISCV_PTR  ".word"
+#define RISCV_SZPTR"4"
+#define RISCV_LGPTR"2"
+#endif
+#else
+#error "Unexpected __SIZEOF_POINTER__"
+#endif
+
+#if (__SIZEOF_INT__ == 4)
+#define INT__ASM_STR(.word)
+#define SZINT  __ASM_STR(4)
+#define LGINT  __ASM_STR(2)
+#else
+#error "Unexpected __SIZEOF_INT__"
+#endif
+
+#if (__SIZEOF_SHORT__ == 2)
+#define SHORT  __ASM_STR(.half)
+#define SZSHORT__ASM_STR(2)
+#define LGSHORT__ASM_STR(1)
+#else
+#error "Unexpected __SIZEOF_SHORT__"
+#endif
+
+#endif /* _ASM_RISCV_ASM_H */
diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
new file mode 100644
index ..387d0dbf0073
--- /dev/null
+++ b/arch/riscv/include/asm/csr.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2015 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#ifndef _ASM_RISCV_CSR_H
+#define _ASM_RISCV_CSR_H
+
+#include 
+
+/* Status register flags */
+#define SR_IE   _AC(0x0002, UL) /* Interrupt Enable */
+#define SR_PIE  _AC(0x0020, UL) /* Previous IE */
+#define SR_PS   _AC(0x0100, UL) /* Previously Supervisor */
+#define SR_SUM  _AC(0x0004, UL) /* Supervisor may access User Memory */
+
+#define SR_FS   _AC(0x6000,

[PATCH 03/17] pci: Add a generic, weakly-linked pcibios_fixup_bus

2017-07-10 Thread Palmer Dabbelt
Multiple architectures define this as an empty function, and I'm adding
another one as part of the RISC-V port.  This adds a __weak version of
pci_fixup_bios and deletes the now obselete ones in a handful of ports.

The only functional change should be that microblaze used to export
pcibios_fixup_bus.  None of the other architectures export this, so I
just dropped it.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/cris/arch-v32/drivers/pci/bios.c |  4 
 arch/microblaze/pci/pci-common.c  |  6 --
 arch/s390/pci/pci.c   |  4 
 arch/sh/drivers/pci/pci.c |  8 
 arch/tile/kernel/pci.c|  8 
 arch/tile/kernel/pci_gx.c |  5 -
 drivers/pci/probe.c   | 10 ++
 7 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/arch/cris/arch-v32/drivers/pci/bios.c 
b/arch/cris/arch-v32/drivers/pci/bios.c
index 394c2a73d5e2..5cc622c0225e 100644
--- a/arch/cris/arch-v32/drivers/pci/bios.c
+++ b/arch/cris/arch-v32/drivers/pci/bios.c
@@ -2,10 +2,6 @@
 #include 
 #include 
 
-void pcibios_fixup_bus(struct pci_bus *b)
-{
-}
-
 void pcibios_set_master(struct pci_dev *dev)
 {
u8 lat;
diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c
index 7a332e9f1de0..5835c09c6e26 100644
--- a/arch/microblaze/pci/pci-common.c
+++ b/arch/microblaze/pci/pci-common.c
@@ -810,12 +810,6 @@ void pcibios_setup_bus_devices(struct pci_bus *bus)
}
 }
 
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-   /* nothing to do */
-}
-EXPORT_SYMBOL(pcibios_fixup_bus);
-
 /*
  * We need to avoid collisions with `mirrored' VGA ports
  * and other strange ISA hardware, so we always want the
diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 7b30af5da222..ddb9923fb45d 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -262,10 +262,6 @@ static int zpci_cfg_store(struct zpci_dev *zdev, int 
offset, u32 val, u8 len)
return rc;
 }
 
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}
-
 resource_size_t pcibios_align_resource(void *data, const struct resource *res,
   resource_size_t size,
   resource_size_t align)
diff --git a/arch/sh/drivers/pci/pci.c b/arch/sh/drivers/pci/pci.c
index c99ee286b69f..749642e1272e 100644
--- a/arch/sh/drivers/pci/pci.c
+++ b/arch/sh/drivers/pci/pci.c
@@ -155,14 +155,6 @@ static int __init pcibios_init(void)
 subsys_initcall(pcibios_init);
 
 /*
- *  Called after each bus is probed, but before its children
- *  are examined.
- */
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}
-
-/*
  * We need to avoid collisions with `mirrored' VGA ports
  * and other strange ISA hardware, so we always want the
  * addresses to be allocated in the 0x000-0x0ff region
diff --git a/arch/tile/kernel/pci.c b/arch/tile/kernel/pci.c
index 284ed23b3914..8999a20ed9d1 100644
--- a/arch/tile/kernel/pci.c
+++ b/arch/tile/kernel/pci.c
@@ -359,14 +359,6 @@ int __init pcibios_init(void)
 }
 subsys_initcall(pcibios_init);
 
-/*
- * No bus fixups needed.
- */
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-   /* Nothing needs to be done. */
-}
-
 void pcibios_set_master(struct pci_dev *dev)
 {
/* No special bus mastering setup handling. */
diff --git a/arch/tile/kernel/pci_gx.c b/arch/tile/kernel/pci_gx.c
index bdc623b91f7a..0a7642184a9a 100644
--- a/arch/tile/kernel/pci_gx.c
+++ b/arch/tile/kernel/pci_gx.c
@@ -1029,11 +1029,6 @@ int __init pcibios_init(void)
 }
 subsys_initcall(pcibios_init);
 
-/* No bus fixups needed. */
-void pcibios_fixup_bus(struct pci_bus *bus)
-{
-}
-
 /* Process any "pci=" kernel boot arguments. */
 char *__init pcibios_setup(char *str)
 {
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c31310db0404..2ef1248bf112 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2288,6 +2288,16 @@ void pcie_bus_configure_settings(struct pci_bus *bus)
 }
 EXPORT_SYMBOL_GPL(pcie_bus_configure_settings);
 
+/*
+ * Called after each bus is probed, but before its children are examined.  This
+ * is marked as __weak because multiple architectures define it
+ */
+__attribute__ ((weak))
+void pcibios_fixup_bus(struct pci_bus *bus)
+{
+   /* nothing to do, expected to be removed in the future */
+}
+
 unsigned int pci_scan_child_bus(struct pci_bus *bus)
 {
unsigned int devfn, pass, max = bus->busn_res.start;
-- 
2.13.0



[PATCH 01/17] lib: Add shared copies of some GCC library routines

2017-07-10 Thread Palmer Dabbelt
Many ports (m32r, microblaze, mips, parisc, score, and sparc) use
functionally identical copies of various GCC library routine files,
which came up as we were submitting the RISC-V port (which also uses
some of these).

This patch adds a new copy of these library routine files, which are
functionally identical to the various other copies.  These are
availiable via Kconfig as CONFIG_LIB_$ROUTINE, which currently isn't
used anywhere.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
Reviewed-by: Geert Uytterhoeven <ge...@linux-m68k.org>
---
 include/lib/libgcc.h | 44 
 lib/Kconfig  | 18 +
 lib/Makefile |  8 ++
 lib/ashldi3.c| 45 
 lib/ashrdi3.c| 46 +
 lib/cmpdi2.c | 42 ++
 lib/lshrdi3.c| 45 
 lib/muldi3.c | 72 
 lib/ucmpdi2.c| 35 +
 9 files changed, 355 insertions(+)
 create mode 100644 include/lib/libgcc.h
 create mode 100644 lib/ashldi3.c
 create mode 100644 lib/ashrdi3.c
 create mode 100644 lib/cmpdi2.c
 create mode 100644 lib/lshrdi3.c
 create mode 100644 lib/muldi3.c
 create mode 100644 lib/ucmpdi2.c

diff --git a/include/lib/libgcc.h b/include/lib/libgcc.h
new file mode 100644
index ..a5397e34e005
--- /dev/null
+++ b/include/lib/libgcc.h
@@ -0,0 +1,44 @@
+/*
+ * include/lib/libgcc.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */
+
+
+#ifndef __LIB_LIBGCC_H
+#define __LIB_LIBGCC_H
+
+#include 
+
+typedef int word_type __attribute__ ((mode (__word__)));
+
+#ifdef __BIG_ENDIAN
+struct DWstruct {
+   int high, low;
+};
+#elif defined(__LITTLE_ENDIAN)
+struct DWstruct {
+   int low, high;
+};
+#else
+#error I feel sick.
+#endif
+
+typedef union {
+   struct DWstruct s;
+   long long ll;
+} DWunion;
+
+#endif /* __ASM_LIBGCC_H */
diff --git a/lib/Kconfig b/lib/Kconfig
index 6762529ad9e4..2b53c9247cc3 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -576,3 +576,21 @@ config PRIME_NUMBERS
tristate
 
 endmenu
+
+config GENERIC_ASHLDI3
+   def_bool n
+
+config GENERIC_ASHRDI3
+   def_bool n
+
+config GENERIC_LSHRDI3
+   def_bool n
+
+config GENERIC_MULDI3
+   def_bool n
+
+config GENERIC_CMPDI2
+   def_bool n
+
+config GENERIC_UCMPDI2
+   def_bool n
diff --git a/lib/Makefile b/lib/Makefile
index 5a008329324e..4c90e31012c8 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -241,3 +241,11 @@ UBSAN_SANITIZE_ubsan.o := n
 obj-$(CONFIG_SBITMAP) += sbitmap.o
 
 obj-$(CONFIG_PARMAN) += parman.o
+
+# GCC library routines
+obj-$(CONFIG_GENERIC_ASHLDI3) += ashldi3.o
+obj-$(CONFIG_GENERIC_ASHRDI3) += ashrdi3.o
+obj-$(CONFIG_GENERIC_LSHRDI3) += lshrdi3.o
+obj-$(CONFIG_GENERIC_MULDI3) += muldi3.o
+obj-$(CONFIG_GENERIC_CMPDI2) += cmpdi2.o
+obj-$(CONFIG_GENERIC_UCMPDI2) += ucmpdi2.o
diff --git a/lib/ashldi3.c b/lib/ashldi3.c
new file mode 100644
index ..ff4ec63d2ab6
--- /dev/null
+++ b/lib/ashldi3.c
@@ -0,0 +1,45 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */
+
+
+#include 
+
+#include 
+
+long long notrace __ashldi3(long long u, word_type b)
+{
+   DWunion uu, w;
+   word_type bm;
+
+   if (b == 0)
+   return u;
+
+   uu.ll = u;
+   bm = 32 - b;
+
+   if (bm <= 0) {
+   w.s.low = 0;
+   w.s.high = (unsigned int) uu.s.low << -bm;
+   } else {
+   const unsigned int carries = (unsigned int) uu.s.low >> bm;
+
+   w.s.low = (unsigned int) uu.s.low <

[PATCH 06/17] irqchip: RISC-V Local Interrupt Controller Driver

2017-07-10 Thread Palmer Dabbelt
This patch adds a driver that manages the local interrupts on each
RISC-V hart, as specifiec by the RISC-V supervisor level ISA manual.
The local interrupt controller manages software interrupts, timer
interrupts, and hardware interrupts (which are routed via the
platform level interrupt controller).  Per-hart local interrupt
controllers are found on all RISC-V systems.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 drivers/irqchip/Kconfig  |  14 +++
 drivers/irqchip/Makefile |   1 +
 drivers/irqchip/irq-riscv-intc.c | 213 +++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-intc.c

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index f1fd5f44d1d4..7923d3fa8fae 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -306,3 +306,17 @@ config QCOM_IRQ_COMBINER
help
  Say yes here to add support for the IRQ combiner devices embedded
  in Qualcomm Technologies chips.
+
+config RISCV_INTC
+   def_bool y if RISCV
+   #bool "RISC-V Interrupt Controller"
+   depends on RISCV
+   default y
+   help
+  This enables support for the local interrupt controller found in
+  standard RISC-V systems.  The local interrupt controller handles
+  timer interrupts, software interrupts, and hardware interrupts.
+  Without a local interrupt controller the system will be unable to
+  handle any interrupts, including those passed via the PLIC.
+
+  If you don't know what to do here, say Y.
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index e88d856cc09c..b1aa9114afc4 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -78,3 +78,4 @@ obj-$(CONFIG_EZNPS_GIC)   += irq-eznps.o
 obj-$(CONFIG_ARCH_ASPEED)  += irq-aspeed-vic.o irq-aspeed-i2c-ic.o
 obj-$(CONFIG_STM32_EXTI)   += irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)+= qcom-irq-combiner.o
+obj-$(CONFIG_RISCV_INTC)   += irq-riscv-intc.o
diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c
new file mode 100644
index ..96ae020cf1d5
--- /dev/null
+++ b/drivers/irqchip/irq-riscv-intc.c
@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+struct riscv_irq_data {
+   struct irq_chip chip;
+   struct irq_domain   *domain;
+   int hart;
+   charname[20];
+};
+DEFINE_PER_CPU(struct riscv_irq_data, riscv_irq_data);
+
+static void riscv_software_interrupt(void)
+{
+#ifdef CONFIG_SMP
+   irqreturn_t ret;
+
+   ret = handle_ipi();
+
+   WARN_ON(ret == IRQ_NONE);
+#else
+   /*
+* We currently only use software interrupts to pass inter-processor
+* interrupts, so if a non-SMP system gets a software interrupt then we
+* don't know what to do.
+*/
+   pr_warning("Software Interrupt without CONFIG_SMP\n");
+#endif
+}
+
+asmlinkage void __irq_entry do_IRQ(unsigned int cause, struct pt_regs *regs)
+{
+   struct pt_regs *old_regs = set_irq_regs(regs);
+   struct irq_domain *domain;
+
+   irq_enter();
+
+   /*
+* There are three classes of interrupt: timer, software, and
+* external devices.  We dispatch between them here.  External
+* device interrupts use the generic IRQ mechanisms.
+*/
+   switch (cause) {
+   case INTERRUPT_CAUSE_TIMER:
+   riscv_timer_interrupt();
+   break;
+   case INTERRUPT_CAUSE_SOFTWARE:
+   riscv_software_interrupt();
+   break;
+   default:
+   domain = per_cpu(riscv_irq_data, smp_processor_id()).domain;
+   generic_handle_irq(irq_find_mapping(domain, cause));
+   break;
+   }
+
+   irq_exit();
+   set_irq_regs(old_regs);
+}
+
+static int riscv_irqdomain_map(struct irq_domain *d, unsigned int irq,
+  irq_hw_number_t hwirq)
+{
+   struct riscv_irq_data *data = d->host_data;
+
+   irq_set_chip_and_handler(irq, >chip, handle_simple_irq);
+   irq_set_chip_data(irq, data);
+   irq_set_noprobe(irq);
+   irq_set_aff

[PATCH 07/17] irqchip: New RISC-V PLIC Driver

2017-07-10 Thread Palmer Dabbelt
This patch adds a driver for the Platform Level Interrupt Controller
(PLIC) specified as part of the RISC-V supervisor level ISA manual.
The PLIC connocts global interrupt sources to the local interrupt
controller on each hart.  A PLIC is present on all RISC-V systems.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 drivers/irqchip/Kconfig  |  13 ++
 drivers/irqchip/Makefile |   1 +
 drivers/irqchip/irq-riscv-plic.c | 370 +++
 3 files changed, 384 insertions(+)
 create mode 100644 drivers/irqchip/irq-riscv-plic.c

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 7923d3fa8fae..ae5e27f090ec 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -307,6 +307,19 @@ config QCOM_IRQ_COMBINER
  Say yes here to add support for the IRQ combiner devices embedded
  in Qualcomm Technologies chips.
 
+config RISCV_PLIC
+bool "Platform-Level Interrupt Controller"
+   depends on RISCV
+default y
+help
+  This enables support for the PLIC chip found in standard RISC-V
+  systems.  The PLIC controls devices interrupts and connects them to
+  each core's local interrupt controller.  Aside from timer and
+  software interrupts, all other interrupt sources (MSI, GPIO, etc)
+  are subordinate to the PLIC.
+
+  If you don't know what to do here, say Y.
+
 config RISCV_INTC
def_bool y if RISCV
#bool "RISC-V Interrupt Controller"
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index b1aa9114afc4..7880c9cec40e 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -78,4 +78,5 @@ obj-$(CONFIG_EZNPS_GIC)   += irq-eznps.o
 obj-$(CONFIG_ARCH_ASPEED)  += irq-aspeed-vic.o irq-aspeed-i2c-ic.o
 obj-$(CONFIG_STM32_EXTI)   += irq-stm32-exti.o
 obj-$(CONFIG_QCOM_IRQ_COMBINER)+= qcom-irq-combiner.o
+obj-$(CONFIG_RISCV_PLIC)   += irq-riscv-plic.o
 obj-$(CONFIG_RISCV_INTC)   += irq-riscv-intc.o
diff --git a/drivers/irqchip/irq-riscv-plic.c b/drivers/irqchip/irq-riscv-plic.c
new file mode 100644
index ..e326f239eea7
--- /dev/null
+++ b/drivers/irqchip/irq-riscv-plic.c
@@ -0,0 +1,370 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * From the RISC-V Privlidged Spec v1.10:
+ *
+ * Global interrupt sources are assigned small unsigned integer identifiers,
+ * beginning at the value 1.  An interrupt ID of 0 is reserved to mean “no
+ * interrupt”.  Interrupt identifiers are also used to break ties when two or
+ * more interrupt sources have the same assigned priority. Smaller values of
+ * interrupt ID take precedence over larger values of interrupt ID.
+ *
+ * While the RISC-V supervisor spec doesn't define the maximum number of
+ * devices supported by the PLIC, the largest number supported by devices
+ * marked as 'riscv,plic0' (which is the only device type this driver supports,
+ * and is the only extant PLIC as of now) is 1024.  As mentioned above, device
+ * 0 is defined to be non-existant so this device really only supports 1023
+ * devices.
+ */
+#define MAX_DEVICES1024
+#define MAX_CONTEXTS   15872
+
+/*
+ * The PLIC consists of memory-mapped control registers, with a memory map as
+ * follows:
+ *
+ * base + 0x00: Reserved (interrupt source 0 does not exist)
+ * base + 0x04: Interrupt source 1 priority
+ * base + 0x08: Interrupt source 2 priority
+ * ...
+ * base + 0x000FFC: Interrupt source 1023 priority
+ * base + 0x001000: Pending 0
+ * base + 0x001FFF: Pending
+ * base + 0x002000: Enable bits for sources 0-31 on context 0
+ * base + 0x002004: Enable bits for sources 32-63 on context 0
+ * ...
+ * base + 0x0020FC: Enable bits for sources 992-1023 on context 0
+ * base + 0x002080: Enable bits for sources 0-31 on context 1
+ * ...
+ * base + 0x002100: Enable bits for sources 0-31 on context 2
+ * ...
+ * base + 0x1F1F80: Enable bits for sources 992-1023 on context 15871
+ * base + 0x1F1F84: Reserved
+ * ...  (higher context IDs would fit here, but wouldn't fit
+ *   inside the per-context priority vector)
+ * base + 0x1C: Reserved
+ * base + 0x20: Priority threshold for context 0
+ * base + 0x24: Claim/complete for context 0
+ * base + 0x28:

[PATCH 13/17] RISC-V: Task implementation

2017-07-10 Thread Palmer Dabbelt
This patch contains the implementation of tasks on RISC-V, most of which
is involved in task switching.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/riscv/include/asm/asm-offsets.h |   1 +
 arch/riscv/include/asm/current.h |  45 
 arch/riscv/include/asm/kprobes.h |  22 ++
 arch/riscv/include/asm/processor.h   |  97 
 arch/riscv/include/asm/switch_to.h   |  69 ++
 arch/riscv/include/asm/thread_info.h |  93 +++
 arch/riscv/kernel/asm-offsets.c  | 322 
 arch/riscv/kernel/entry.S| 457 +++
 arch/riscv/kernel/process.c  | 129 ++
 9 files changed, 1235 insertions(+)
 create mode 100644 arch/riscv/include/asm/asm-offsets.h
 create mode 100644 arch/riscv/include/asm/current.h
 create mode 100644 arch/riscv/include/asm/kprobes.h
 create mode 100644 arch/riscv/include/asm/processor.h
 create mode 100644 arch/riscv/include/asm/switch_to.h
 create mode 100644 arch/riscv/include/asm/thread_info.h
 create mode 100644 arch/riscv/kernel/asm-offsets.c
 create mode 100644 arch/riscv/kernel/entry.S
 create mode 100644 arch/riscv/kernel/process.c

diff --git a/arch/riscv/include/asm/asm-offsets.h 
b/arch/riscv/include/asm/asm-offsets.h
new file mode 100644
index ..d370ee36a182
--- /dev/null
+++ b/arch/riscv/include/asm/asm-offsets.h
@@ -0,0 +1 @@
+#include 
diff --git a/arch/riscv/include/asm/current.h b/arch/riscv/include/asm/current.h
new file mode 100644
index ..2cf6336ef600
--- /dev/null
+++ b/arch/riscv/include/asm/current.h
@@ -0,0 +1,45 @@
+/*
+ * Based on arm/arm64/include/asm/current.h
+ *
+ * Copyright (C) 2016 ARM
+ * Copyright (C) 2017 SiFive
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+
+#ifndef __ASM_CURRENT_H
+#define __ASM_CURRENT_H
+
+#include 
+#include 
+
+#ifndef __ASSEMBLY__
+
+struct task_struct;
+
+/*
+ * This only works because "struct thread_info" is at offset 0 from "struct
+ * task_struct".  This constraint seems to be necessary on other architectures
+ * as well, but __switch_to enforces it.  We can't check TASK_TI here because
+ *  includes this, and I can't get the definition of "struct
+ * task_struct" here due to some header ordering problems.
+ */
+static __always_inline struct task_struct *get_current(void)
+{
+   register struct task_struct *tp __asm__("tp");
+   return tp;
+}
+
+#define current get_current()
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __ASM_CURRENT_H */
diff --git a/arch/riscv/include/asm/kprobes.h b/arch/riscv/include/asm/kprobes.h
new file mode 100644
index ..c7eb010d1528
--- /dev/null
+++ b/arch/riscv/include/asm/kprobes.h
@@ -0,0 +1,22 @@
+/*
+ * Copied from arch/arm64/include/asm/kprobes.h
+ *
+ * Copyright (C) 2013 Linaro Limited
+ * Copyright (C) 2017 SiFive
+ *
+ * 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.
+ */
+
+#ifndef _RISCV_KPROBES_H
+#define _RISCV_KPROBES_H
+
+#include 
+
+#endif /* _RISCV_KPROBES_H */
diff --git a/arch/riscv/include/asm/processor.h 
b/arch/riscv/include/asm/processor.h
new file mode 100644
index ..3fe4af8147d2
--- /dev/null
+++ b/arch/riscv/include/asm/processor.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#ifndef _ASM_RISCV_PROCESSOR_H
+#define _ASM_RISCV_PROCESSOR_H
+
+#include 
+
+#include 
+
+/*
+ * This decides where the kernel will search for a free chunk of vm
+ * space during mmap's.
+ */
+#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE >> 1)
+
+#define STACK_TOP  TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
+#define STACK_ALIGN16
+
+#ifndef

[PATCH 15/17] RISC-V: Paging and MMU

2017-07-10 Thread Palmer Dabbelt
This patch contains code to manage the RISC-V MMU, including definitions
of the page tables and the page walking code.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/riscv/include/asm/mmu_context.h  |  69 ++
 arch/riscv/include/asm/page.h | 134 +++
 arch/riscv/include/asm/pgalloc.h  | 124 ++
 arch/riscv/include/asm/pgtable-32.h   |  25 ++
 arch/riscv/include/asm/pgtable-64.h   |  84 +++
 arch/riscv/include/asm/pgtable-bits.h |  48 
 arch/riscv/include/asm/pgtable.h  | 430 ++
 arch/riscv/mm/fault.c | 282 ++
 8 files changed, 1196 insertions(+)
 create mode 100644 arch/riscv/include/asm/mmu_context.h
 create mode 100644 arch/riscv/include/asm/page.h
 create mode 100644 arch/riscv/include/asm/pgalloc.h
 create mode 100644 arch/riscv/include/asm/pgtable-32.h
 create mode 100644 arch/riscv/include/asm/pgtable-64.h
 create mode 100644 arch/riscv/include/asm/pgtable-bits.h
 create mode 100644 arch/riscv/include/asm/pgtable.h
 create mode 100644 arch/riscv/mm/fault.c

diff --git a/arch/riscv/include/asm/mmu_context.h 
b/arch/riscv/include/asm/mmu_context.h
new file mode 100644
index ..de1fc1631fc4
--- /dev/null
+++ b/arch/riscv/include/asm/mmu_context.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#ifndef _ASM_RISCV_MMU_CONTEXT_H
+#define _ASM_RISCV_MMU_CONTEXT_H
+
+#include 
+
+#include 
+#include 
+#include 
+
+static inline void enter_lazy_tlb(struct mm_struct *mm,
+   struct task_struct *task)
+{
+}
+
+/* Initialize context-related info for a new mm_struct */
+static inline int init_new_context(struct task_struct *task,
+   struct mm_struct *mm)
+{
+   return 0;
+}
+
+static inline void destroy_context(struct mm_struct *mm)
+{
+}
+
+static inline pgd_t *current_pgdir(void)
+{
+   return pfn_to_virt(csr_read(sptbr) & SPTBR_PPN);
+}
+
+static inline void set_pgdir(pgd_t *pgd)
+{
+   csr_write(sptbr, virt_to_pfn(pgd) | SPTBR_MODE);
+}
+
+static inline void switch_mm(struct mm_struct *prev,
+   struct mm_struct *next, struct task_struct *task)
+{
+   if (likely(prev != next)) {
+   set_pgdir(next->pgd);
+   local_flush_tlb_all();
+   }
+}
+
+static inline void activate_mm(struct mm_struct *prev,
+  struct mm_struct *next)
+{
+   switch_mm(prev, next, NULL);
+}
+
+static inline void deactivate_mm(struct task_struct *task,
+   struct mm_struct *mm)
+{
+}
+
+#endif /* _ASM_RISCV_MMU_CONTEXT_H */
diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
new file mode 100644
index ..5bbbff2d5a60
--- /dev/null
+++ b/arch/riscv/include/asm/page.h
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2009 Chen Liqin <liqin.c...@sunplusct.com>
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ * Copyright (C) 2017 XiaojingZhu <zhuxi...@ict.ac.cn>
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#ifndef _ASM_RISCV_PAGE_H
+#define _ASM_RISCV_PAGE_H
+
+#include 
+#include 
+
+#define PAGE_SHIFT (12)
+#define PAGE_SIZE  (_AC(1, UL) << PAGE_SHIFT)
+#define PAGE_MASK  (~(PAGE_SIZE - 1))
+
+/*
+ * PAGE_OFFSET -- the first address of the first page of memory.
+ * When not using MMU this corresponds to the first free page in
+ * physical memory (aligned on a page boundary).
+ */
+#ifdef CONFIG_64BIT
+#define PAGE_OFFSET_AC(0x8000, UL)
+#else
+#define PAGE_OFFSET_AC(0xc000, UL)
+#endif
+
+#define KERN_VIRT_SIZE (-PAGE_OFFSET)
+
+#ifndef __ASSEMBLY__
+
+#define PAGE_UP(addr)  (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
+#define PAGE_DOWN(addr)((addr)&(~((PAGE_SIZE)-1)))
+
+/* align addr on a size boundary - adjust address up/down if needed */
+#define _ALIGN_UP(addr, size)  (((addr)+((size)-1))&(~((size)-1)))
+#define _ALIGN_DOWN(addr, size)((addr)&(~((size)-1)))
+
+/* align addr on a size boundary - adjust add

[PATCH 16/17] RISC-V: User-facing API

2017-07-10 Thread Palmer Dabbelt
This patch contains code that is in some way visible to the user:
including via system calls, the VDSO, module loading and signal
handling.  It also contains some generic code that is ABI visible.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/riscv/include/asm/mmu.h  |  26 +++
 arch/riscv/include/asm/ptrace.h   | 116 
 arch/riscv/include/asm/syscall.h  |  90 ++
 arch/riscv/include/asm/unistd.h   |  16 ++
 arch/riscv/include/asm/vdso.h |  32 
 arch/riscv/include/uapi/asm/Kbuild|   5 +
 arch/riscv/include/uapi/asm/auxvec.h  |  24 +++
 arch/riscv/include/uapi/asm/bitsperlong.h |  25 +++
 arch/riscv/include/uapi/asm/byteorder.h   |  23 +++
 arch/riscv/include/uapi/asm/elf.h |  83 +
 arch/riscv/include/uapi/asm/hwcap.h   |  36 
 arch/riscv/include/uapi/asm/ptrace.h  |  90 ++
 arch/riscv/include/uapi/asm/sigcontext.h  |  30 
 arch/riscv/include/uapi/asm/siginfo.h |  24 +++
 arch/riscv/include/uapi/asm/ucontext.h|  35 
 arch/riscv/kernel/cpufeature.c|  61 +++
 arch/riscv/kernel/module.c| 217 ++
 arch/riscv/kernel/ptrace.c| 125 +
 arch/riscv/kernel/riscv_ksyms.c   |  15 ++
 arch/riscv/kernel/signal.c| 289 ++
 arch/riscv/kernel/sys_riscv.c |  43 +
 arch/riscv/kernel/syscall_table.c |  25 +++
 arch/riscv/kernel/vdso/.gitignore |   2 +
 arch/riscv/kernel/vdso/Makefile   |  64 +++
 arch/riscv/kernel/vdso/rt_sigreturn.S |  24 +++
 arch/riscv/kernel/vdso/vdso.S |  27 +++
 arch/riscv/kernel/vdso/vdso.lds.S |  77 
 27 files changed, 1624 insertions(+)
 create mode 100644 arch/riscv/include/asm/mmu.h
 create mode 100644 arch/riscv/include/asm/ptrace.h
 create mode 100644 arch/riscv/include/asm/syscall.h
 create mode 100644 arch/riscv/include/asm/unistd.h
 create mode 100644 arch/riscv/include/asm/vdso.h
 create mode 100644 arch/riscv/include/uapi/asm/Kbuild
 create mode 100644 arch/riscv/include/uapi/asm/auxvec.h
 create mode 100644 arch/riscv/include/uapi/asm/bitsperlong.h
 create mode 100644 arch/riscv/include/uapi/asm/byteorder.h
 create mode 100644 arch/riscv/include/uapi/asm/elf.h
 create mode 100644 arch/riscv/include/uapi/asm/hwcap.h
 create mode 100644 arch/riscv/include/uapi/asm/ptrace.h
 create mode 100644 arch/riscv/include/uapi/asm/sigcontext.h
 create mode 100644 arch/riscv/include/uapi/asm/siginfo.h
 create mode 100644 arch/riscv/include/uapi/asm/ucontext.h
 create mode 100644 arch/riscv/kernel/cpufeature.c
 create mode 100644 arch/riscv/kernel/module.c
 create mode 100644 arch/riscv/kernel/ptrace.c
 create mode 100644 arch/riscv/kernel/riscv_ksyms.c
 create mode 100644 arch/riscv/kernel/signal.c
 create mode 100644 arch/riscv/kernel/sys_riscv.c
 create mode 100644 arch/riscv/kernel/syscall_table.c
 create mode 100644 arch/riscv/kernel/vdso/.gitignore
 create mode 100644 arch/riscv/kernel/vdso/Makefile
 create mode 100644 arch/riscv/kernel/vdso/rt_sigreturn.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.S
 create mode 100644 arch/riscv/kernel/vdso/vdso.lds.S

diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h
new file mode 100644
index ..66805cba9a27
--- /dev/null
+++ b/arch/riscv/include/asm/mmu.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+
+#ifndef _ASM_RISCV_MMU_H
+#define _ASM_RISCV_MMU_H
+
+#ifndef __ASSEMBLY__
+
+typedef struct {
+   void *vdso;
+} mm_context_t;
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_RISCV_MMU_H */
diff --git a/arch/riscv/include/asm/ptrace.h b/arch/riscv/include/asm/ptrace.h
new file mode 100644
index ..340201868842
--- /dev/null
+++ b/arch/riscv/include/asm/ptrace.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation, version 2.
+ *
+ *   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.
+ */
+
+#ifndef _ASM_RISCV_PTRACE_H
+#define _ASM_RISCV_PT

[PATCH 12/17] RISC-V: ELF and module implementation

2017-07-10 Thread Palmer Dabbelt
This patch contains the code that interfaces with ELF objects on RISC-V
systems, the vast majority of which is present to load kernel modules.

Signed-off-by: Palmer Dabbelt <pal...@dabbelt.com>
---
 arch/riscv/include/asm/compat.h | 29 ++
 arch/riscv/include/asm/elf.h| 84 +
 arch/riscv/include/asm/hwcap.h  | 37 ++
 arch/riscv/mm/extable.c | 37 ++
 4 files changed, 187 insertions(+)
 create mode 100644 arch/riscv/include/asm/compat.h
 create mode 100644 arch/riscv/include/asm/elf.h
 create mode 100644 arch/riscv/include/asm/hwcap.h
 create mode 100644 arch/riscv/mm/extable.c

diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compat.h
new file mode 100644
index ..044aecff8854
--- /dev/null
+++ b/arch/riscv/include/asm/compat.h
@@ -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_COMPAT_H
+#define __ASM_COMPAT_H
+#ifdef CONFIG_COMPAT
+
+#if defined(CONFIG_64BIT)
+#define COMPAT_UTS_MACHINE "riscv64\0\0"
+#elif defined(CONFIG_32BIT)
+#define COMPAT_UTS_MACHINE "riscv32\0\0"
+#else
+#error "Unknown RISC-V base ISA"
+#endif
+
+#endif /*CONFIG_COMPAT*/
+#endif /*__ASM_COMPAT_H*/
diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
new file mode 100644
index ..a1ef503d616e
--- /dev/null
+++ b/arch/riscv/include/asm/elf.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2003 Matjaz Breskvar <phoe...@bsemi.com>
+ * Copyright (C) 2010-2011 Jonas Bonn <jo...@southpole.se>
+ * Copyright (C) 2012 Regents of the University of California
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef _ASM_RISCV_ELF_H
+#define _ASM_RISCV_ELF_H
+
+#include 
+#include 
+#include 
+
+/* TODO: Move definition into include/uapi/linux/elf-em.h */
+#define EM_RISCV   0xF3
+
+/*
+ * These are used to set parameters in the core dumps.
+ */
+#define ELF_ARCH   EM_RISCV
+
+#ifdef CONFIG_64BIT
+#define ELF_CLASS  ELFCLASS64
+#else
+#define ELF_CLASS  ELFCLASS32
+#endif
+
+#if defined(__LITTLE_ENDIAN)
+#define ELF_DATA   ELFDATA2LSB
+#elif defined(__BIG_ENDIAN)
+#define ELF_DATA   ELFDATA2MSB
+#else
+#error "Unknown endianness"
+#endif
+
+/*
+ * This is used to ensure we don't load something for the wrong architecture.
+ */
+#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
+
+#define CORE_DUMP_USE_REGSET
+#define ELF_EXEC_PAGESIZE  (PAGE_SIZE)
+
+/*
+ * This is the location that an ET_DYN program is loaded if exec'ed.  Typical
+ * use of this is to invoke "./ld.so someprog" to test out a new version of
+ * the loader.  We need to make sure that it is out of the way of the program
+ * that it will "exec", and that there is sufficient room for the brk.
+ */
+#define ELF_ET_DYN_BASE((TASK_SIZE / 3) * 2)
+
+/*
+ * This yields a mask that user programs can use to figure out what
+ * instruction set this CPU supports.  This could be done in user space,
+ * but it's not easy, and we've already done it here.
+ */
+#define ELF_HWCAP  (elf_hwcap)
+extern unsigned long elf_hwcap;
+
+/*
+ * This yields a string that ld.so will use to load implementation
+ * specific libraries for optimization.  This is more specific in
+ * intent than poking at uname or /proc/cpuinfo.
+ */
+#define ELF_PLATFORM   (NULL)
+
+#define ARCH_DLINFO\
+do {   \
+   NEW_AUX_ENT(AT_SYSINFO_EHDR,\
+   (elf_addr_t)current->mm->context.vdso); \
+} while (0)
+
+
+#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
+struct linux_binprm;
+extern int arch_setup_additional_pages(struct linux_binprm *bprm,
+   int uses_interp);
+
+#endif /* _ASM_RISCV_ELF_H */
diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h
new file mode 100644
index ..8a4ed7bbcbea
--- /dev/null
+++ b/arch/riscv/include/asm/hwcap.h
@@ -0,0 +1,37 @@
+/*
+ * Copied from arch/arm64/include/asm/hwcap.h
+ *
+ * Copyright (

Re: [PATCH 8/9] RISC-V: User-facing API

2017-07-10 Thread Palmer Dabbelt
On Mon, 10 Jul 2017 13:00:29 PDT (-0700), Palmer Dabbelt wrote:
> On Thu, 06 Jul 2017 08:45:13 PDT (-0700), will.dea...@arm.com wrote:
>> On Thu, Jul 06, 2017 at 08:34:27AM -0700, Christoph Hellwig wrote:
>>> On Thu, Jul 06, 2017 at 09:55:03AM +0100, Will Deacon wrote:
>>> > Agreed on the indirection; it feels like this is something that should be 
>>> > in
>>> > the vDSO, which could use the cmpxchg instruction if it's available, or
>>> > otherwise just uses plain loads and stores.
>
> These are already in the vDSO, and use the corresponding atomic instructions 
> on
> systems with the A extension.  The vDSO routines call the system calls in 
> non-A
> systems.  As far as I can tell that's necessary to preserve atomicity, which 
> we
> currently do by disabling scheduling.  If there's a way to do this without
> entering the kernel then I'd be happy to support it, but I'm not sure how we
> could maintain atomicity using only regular loads and stores.
>
>>> Even that seems like a lot of indirection for something that is in
>>> the critical fast path for synchronization.  I really can't understand
>>> how a new ISA / ABI could even come up with an idea as stupid as making
>>> essential synchronization primitives optional.
>>
>> No disagreement there!
>
> The default set of multilibs on Linux are:
>
>  * rv32imac: 32-bit; Multiply, Atomic, and Compressed extensions
>  * rv32imafdc: like above, but with single+double float
>  * rv64imac: 64-bit, Multiply, Atomic and Compressed
>  * rv64imafdc: like above, but with single+double float
>
> all of which support the A extension.  We certainly don't plan on building any
> systems that support Linux without the A extension at SiFive, so I'm fine
> removing the system call -- this was originally added by a user, so there was
> at least enough interest for someone to add the system call.
>
> We've found people are retrofitting other cores to run RISC-V, and I could
> certainly imagine an older design that lacks a beefy enough memory system to
> support our atomics (which are LR/SC based) being a design that might arise.
> There's a lot of systems where people don't seem to care that much about the
> performance and just want something to work -- if they're on such a tiny 
> system
> they can't implement the A extension then they're probably not going to be
> doing a lot of atomics anyway, so maybe it doesn't matter if atomics are slow.
> As the cost for supporting these A-less systems seems fairly small, it seemed
> like the right thing to do -- one of the points of making RISC-V have many
> optional extensions was to let people pick the ones they view as important.
> Since I don't know the performance constraints of their systems or the cost of
> implementing the A extension in their design, I'm not really qualified to tell
> them a cmpxchg syscall is a bad idea.
>
> I'm fine either way here: if someone's core can't support the A extension they
> can always just buy one that does (ideally from us :)).  If it was up to be 
> I'd
> leave the calls in there, as I generally don't like to tell users we won't
> support their use case, but since you guys seem to know a lot more about this
> than I do I'll just leave the decision up to you.
>
> If you want the system call (and the corresponding vDSO entry, which will be
> unnecessary if we mandate A) gone then I'll remove it for our v5.  Just give 
> me
> a heads up.
>
> Thanks, and sorry for wasting your time!

I mangled this message when sending it so I'm trying again.


  1   2   3   4   5   6   7   8   >