Re: [PATCH V3] staging: ks7010: use netdev_* instead of printk()

2016-10-09 Thread Joe Perches
On Mon, 2016-10-10 at 11:14 +0530, Sabitha George wrote:
> 1. Fixes checkpatch warning on printk usage in ks_hostif.c
> 2. Dropped "ks_wlan" prefix from the messages
> 3. Removed the "Memory squeeze,dropping packet" messages
[]
> diff --git a/drivers/staging/ks7010/ks_hostif.c 
> b/drivers/staging/ks7010/ks_hostif.c
[]
> @@ -549,7 +545,8 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
>   dev->dev_addr[5] = priv->eth_addr[5];
>   dev->dev_addr[6] = 0x00;
>   dev->dev_addr[7] = 0x00;
> - printk(KERN_INFO "ks_wlan: MAC ADDRESS = %pM\n", 
> priv->eth_addr);
> + netdev_info(dev, "MAC ADDRESS = %pM\n",
> + priv->eth_addr);

Do please use all 80 columns where possible.

netdev_info(dev, "MAC ADDRESS = %pM\n", priv->eth_addr);



Re: [PATCH V3] staging: ks7010: use netdev_* instead of printk()

2016-10-09 Thread Joe Perches
On Mon, 2016-10-10 at 11:14 +0530, Sabitha George wrote:
> 1. Fixes checkpatch warning on printk usage in ks_hostif.c
> 2. Dropped "ks_wlan" prefix from the messages
> 3. Removed the "Memory squeeze,dropping packet" messages
[]
> diff --git a/drivers/staging/ks7010/ks_hostif.c 
> b/drivers/staging/ks7010/ks_hostif.c
[]
> @@ -549,7 +545,8 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
>   dev->dev_addr[5] = priv->eth_addr[5];
>   dev->dev_addr[6] = 0x00;
>   dev->dev_addr[7] = 0x00;
> - printk(KERN_INFO "ks_wlan: MAC ADDRESS = %pM\n", 
> priv->eth_addr);
> + netdev_info(dev, "MAC ADDRESS = %pM\n",
> + priv->eth_addr);

Do please use all 80 columns where possible.

netdev_info(dev, "MAC ADDRESS = %pM\n", priv->eth_addr);



[PATCH] locking/osq: Provide proper lock/unlock and relaxed flavors

2016-10-09 Thread Davidlohr Bueso

Because osq has only been used for mutex/rwsem spinning logic,
we have gotten away with being rather flexible in any of the
traditional lock/unlock ACQUIRE/RELEASE minimal guarantees.
However, if wanted to be used as a _real_ lock, then it would
be in trouble. To this end, this patch provides the two
alternatives, where osq_lock/unlock() calls have the required
semantics, and a _relaxed() call, for no ordering guarantees
at all.

- node->locked is now completely without ordering for _relaxed()
(currently its under smp_load_acquire, which does not match and
the race is harmless to begin with as we just iterate again. For
the ACQUIRE flavor, it is always formed with ctr dep + smp_rmb().

- In order to avoid more code duplication via macros, the common
osq_wait_next() call is completely unordered, but the caller
can provide the necessary barriers, if required - ie the case for
osq_unlock(): similar to the node->locked case, this also relies
on ctrl dep + smp_wmb() to form RELEASE.

- If osq_lock() fails we never guarantee any ordering (obviously
same goes for _relaxed).

Both mutexes and rwsems have been updated to continue using the
relaxed versions, but this will obviously change for the later.

Signed-off-by: Davidlohr Bueso 
---
XXX: This obviously needs a lot of testing.

include/asm-generic/barrier.h |   9 ++
include/linux/osq_lock.h  |  10 ++
kernel/locking/mutex.c|   6 +-
kernel/locking/osq_lock.c | 279 +++---
kernel/locking/rwsem-xadd.c   |   4 +-
5 files changed, 177 insertions(+), 131 deletions(-)

diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
index fe297b599b0a..0036b08151c3 100644
--- a/include/asm-generic/barrier.h
+++ b/include/asm-generic/barrier.h
@@ -221,6 +221,15 @@ do {   
\
#endif

/**
+ * smp_release__after_ctrl_dep() - Provide RELEASE ordering after a control 
dependency
+ *
+ * A control dependency provides a LOAD->STORE order, the additional WMB
+ * provides STORE->STORE order, together they provide {LOAD,STORE}->STORE 
order,
+ * aka. (store)-RELEASE.
+ */
+#define smp_release__after_ctrl_dep()  smp_wmb()
+
+/**
 * smp_cond_load_acquire() - (Spin) wait for cond with ACQUIRE ordering
 * @ptr: pointer to the variable to wait on
 * @cond: boolean expression to wait for
diff --git a/include/linux/osq_lock.h b/include/linux/osq_lock.h
index 703ea5c30a33..a63ffa95aa70 100644
--- a/include/linux/osq_lock.h
+++ b/include/linux/osq_lock.h
@@ -29,6 +29,16 @@ static inline void osq_lock_init(struct 
optimistic_spin_queue *lock)
atomic_set(>tail, OSQ_UNLOCKED_VAL);
}

+/*
+ * Versions of osq_lock/unlock that do not imply or guarantee (load)-ACQUIRE
+ * (store)-RELEASE barrier semantics.
+ *
+ * Note that a failed call to either osq_lock() or osq_lock_relaxed() does
+ * not imply barriers... we are next to block.
+ */
+extern bool osq_lock_relaxed(struct optimistic_spin_queue *lock);
+extern void osq_unlock_relaxed(struct optimistic_spin_queue *lock);
+
extern bool osq_lock(struct optimistic_spin_queue *lock);
extern void osq_unlock(struct optimistic_spin_queue *lock);

diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index a70b90db3909..b1bf1e057565 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -316,7 +316,7 @@ static bool mutex_optimistic_spin(struct mutex *lock,
 * acquire the mutex all at once, the spinners need to take a
 * MCS (queued) lock first before spinning on the owner field.
 */
-   if (!osq_lock(>osq))
+   if (!osq_lock_relaxed(>osq))
goto done;

while (true) {
@@ -358,7 +358,7 @@ static bool mutex_optimistic_spin(struct mutex *lock,
}

mutex_set_owner(lock);
-   osq_unlock(>osq);
+   osq_unlock_relaxed(>osq);
return true;
}

@@ -380,7 +380,7 @@ static bool mutex_optimistic_spin(struct mutex *lock,
cpu_relax_lowlatency();
}

-   osq_unlock(>osq);
+   osq_unlock_relaxed(>osq);
done:
/*
 * If we fell out of the spin path because of need_resched(),
diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
index 05a37857ab55..d3d1042a509c 100644
--- a/kernel/locking/osq_lock.c
+++ b/kernel/locking/osq_lock.c
@@ -28,6 +28,17 @@ static inline struct optimistic_spin_node *decode_cpu(int 
encoded_cpu_val)
return per_cpu_ptr(_node, cpu_nr);
}

+static inline void set_node_locked_release(struct optimistic_spin_node *node)
+{
+   smp_store_release(>locked, 1);
+}
+
+static inline void set_node_locked_relaxed(struct optimistic_spin_node *node)
+{
+   WRITE_ONCE(node->locked, 1);
+
+}
+
/*
 * Get a stable @node->next pointer, either for unlock() or unqueue() purposes.
 * Can return NULL in case we were the last queued and we 

[PATCH] locking/osq: Provide proper lock/unlock and relaxed flavors

2016-10-09 Thread Davidlohr Bueso

Because osq has only been used for mutex/rwsem spinning logic,
we have gotten away with being rather flexible in any of the
traditional lock/unlock ACQUIRE/RELEASE minimal guarantees.
However, if wanted to be used as a _real_ lock, then it would
be in trouble. To this end, this patch provides the two
alternatives, where osq_lock/unlock() calls have the required
semantics, and a _relaxed() call, for no ordering guarantees
at all.

- node->locked is now completely without ordering for _relaxed()
(currently its under smp_load_acquire, which does not match and
the race is harmless to begin with as we just iterate again. For
the ACQUIRE flavor, it is always formed with ctr dep + smp_rmb().

- In order to avoid more code duplication via macros, the common
osq_wait_next() call is completely unordered, but the caller
can provide the necessary barriers, if required - ie the case for
osq_unlock(): similar to the node->locked case, this also relies
on ctrl dep + smp_wmb() to form RELEASE.

- If osq_lock() fails we never guarantee any ordering (obviously
same goes for _relaxed).

Both mutexes and rwsems have been updated to continue using the
relaxed versions, but this will obviously change for the later.

Signed-off-by: Davidlohr Bueso 
---
XXX: This obviously needs a lot of testing.

include/asm-generic/barrier.h |   9 ++
include/linux/osq_lock.h  |  10 ++
kernel/locking/mutex.c|   6 +-
kernel/locking/osq_lock.c | 279 +++---
kernel/locking/rwsem-xadd.c   |   4 +-
5 files changed, 177 insertions(+), 131 deletions(-)

diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
index fe297b599b0a..0036b08151c3 100644
--- a/include/asm-generic/barrier.h
+++ b/include/asm-generic/barrier.h
@@ -221,6 +221,15 @@ do {   
\
#endif

/**
+ * smp_release__after_ctrl_dep() - Provide RELEASE ordering after a control 
dependency
+ *
+ * A control dependency provides a LOAD->STORE order, the additional WMB
+ * provides STORE->STORE order, together they provide {LOAD,STORE}->STORE 
order,
+ * aka. (store)-RELEASE.
+ */
+#define smp_release__after_ctrl_dep()  smp_wmb()
+
+/**
 * smp_cond_load_acquire() - (Spin) wait for cond with ACQUIRE ordering
 * @ptr: pointer to the variable to wait on
 * @cond: boolean expression to wait for
diff --git a/include/linux/osq_lock.h b/include/linux/osq_lock.h
index 703ea5c30a33..a63ffa95aa70 100644
--- a/include/linux/osq_lock.h
+++ b/include/linux/osq_lock.h
@@ -29,6 +29,16 @@ static inline void osq_lock_init(struct 
optimistic_spin_queue *lock)
atomic_set(>tail, OSQ_UNLOCKED_VAL);
}

+/*
+ * Versions of osq_lock/unlock that do not imply or guarantee (load)-ACQUIRE
+ * (store)-RELEASE barrier semantics.
+ *
+ * Note that a failed call to either osq_lock() or osq_lock_relaxed() does
+ * not imply barriers... we are next to block.
+ */
+extern bool osq_lock_relaxed(struct optimistic_spin_queue *lock);
+extern void osq_unlock_relaxed(struct optimistic_spin_queue *lock);
+
extern bool osq_lock(struct optimistic_spin_queue *lock);
extern void osq_unlock(struct optimistic_spin_queue *lock);

diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index a70b90db3909..b1bf1e057565 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -316,7 +316,7 @@ static bool mutex_optimistic_spin(struct mutex *lock,
 * acquire the mutex all at once, the spinners need to take a
 * MCS (queued) lock first before spinning on the owner field.
 */
-   if (!osq_lock(>osq))
+   if (!osq_lock_relaxed(>osq))
goto done;

while (true) {
@@ -358,7 +358,7 @@ static bool mutex_optimistic_spin(struct mutex *lock,
}

mutex_set_owner(lock);
-   osq_unlock(>osq);
+   osq_unlock_relaxed(>osq);
return true;
}

@@ -380,7 +380,7 @@ static bool mutex_optimistic_spin(struct mutex *lock,
cpu_relax_lowlatency();
}

-   osq_unlock(>osq);
+   osq_unlock_relaxed(>osq);
done:
/*
 * If we fell out of the spin path because of need_resched(),
diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
index 05a37857ab55..d3d1042a509c 100644
--- a/kernel/locking/osq_lock.c
+++ b/kernel/locking/osq_lock.c
@@ -28,6 +28,17 @@ static inline struct optimistic_spin_node *decode_cpu(int 
encoded_cpu_val)
return per_cpu_ptr(_node, cpu_nr);
}

+static inline void set_node_locked_release(struct optimistic_spin_node *node)
+{
+   smp_store_release(>locked, 1);
+}
+
+static inline void set_node_locked_relaxed(struct optimistic_spin_node *node)
+{
+   WRITE_ONCE(node->locked, 1);
+
+}
+
/*
 * Get a stable @node->next pointer, either for unlock() or unqueue() purposes.
 * Can return NULL in case we were the last queued and we updated @lock 

Re: ppc64 qemu test failure since commit f9aa67142 ("powerpc/64s: Consolidate Alignment 0x600 interrupt")

2016-10-09 Thread Nicholas Piggin
On Sun, 9 Oct 2016 08:21:21 -0700
Guenter Roeck  wrote:

> Nicholas,
> 
> some of my qemu tests for ppc64 started failing on mainline (and -next).
> You can find a test log at
> http://kerneltests.org/builders/qemu-ppc64-master/builds/580/steps/qemubuildcommand/logs/stdio
> 
> The scripts to run the test are available at
> https://github.com/groeck/linux-build-test/tree/master/rootfs/ppc64
> 
> Bisect points to commit f9aa67142ef26 ("powerpc/64s: Consolidate Alignment 
> 0x600
> interrupt"). Bisect log is attached.
> 
> Since I don't have the means to run the code on a real system, I have no idea
> if the problem is caused by qemu or by the code. It is interesting, though, 
> that
> only the 'mac99' tests are affected.
> 
> Please let me know if there is anything I can do to help tracking down the
> problem.

Thanks for this. That patch just moves a small amount of code, so it's likely
that it's caused something to get placed out of range of its caller, or the
linker started generating a stub for some reason. I can't immediately see the
problem, but it could be specific to your exact toolchain.

Something that might help, would you be able to put the compiled vmlinux 
binaries
from before/after the bad patch somewhere I can grab them?

Thanks,
Nick


Re: ppc64 qemu test failure since commit f9aa67142 ("powerpc/64s: Consolidate Alignment 0x600 interrupt")

2016-10-09 Thread Nicholas Piggin
On Sun, 9 Oct 2016 08:21:21 -0700
Guenter Roeck  wrote:

> Nicholas,
> 
> some of my qemu tests for ppc64 started failing on mainline (and -next).
> You can find a test log at
> http://kerneltests.org/builders/qemu-ppc64-master/builds/580/steps/qemubuildcommand/logs/stdio
> 
> The scripts to run the test are available at
> https://github.com/groeck/linux-build-test/tree/master/rootfs/ppc64
> 
> Bisect points to commit f9aa67142ef26 ("powerpc/64s: Consolidate Alignment 
> 0x600
> interrupt"). Bisect log is attached.
> 
> Since I don't have the means to run the code on a real system, I have no idea
> if the problem is caused by qemu or by the code. It is interesting, though, 
> that
> only the 'mac99' tests are affected.
> 
> Please let me know if there is anything I can do to help tracking down the
> problem.

Thanks for this. That patch just moves a small amount of code, so it's likely
that it's caused something to get placed out of range of its caller, or the
linker started generating a stub for some reason. I can't immediately see the
problem, but it could be specific to your exact toolchain.

Something that might help, would you be able to put the compiled vmlinux 
binaries
from before/after the bad patch somewhere I can grab them?

Thanks,
Nick


Re: [GIT PULL] trivial for 4.9

2016-10-09 Thread Joe Perches
On Fri, 2016-10-07 at 14:37 -0700, Linus Torvalds wrote:
> On Fri, Oct 7, 2016 at 2:06 PM, Linus Torvalds
>  wrote:
> > 
> > And btw, even without an explicit KERN_, you should still not
> > get any interleaving. Only an _explicit_ KERN_CONT should cause
> > interleaving
> 
> 
> Btw, note the "should" there. Because we do seem to have broken that
> _again_.  It worked fine at some point, but lookie here:

So, I've gone back to each release from 3.6 to 3.3 looking for a case
where interleaving printks inserted newlines automatically for different
processes.

I can't find one.  Neither in dmesg nor in /dev/kmsg.

What version of the kernel do _you_ think had this behavior?

> commit 61e99ab8e35a88b8c4d0f80d3df9ee16df471be5
> Author: Joe Perches 
> Date:   Mon Jul 30 14:40:21 2012 -0700
> 
> printk: remove the now unnecessary "C" annotation for KERN_CONT
> 
> Now that all KERN_ uses are prefixed with ASCII SOH, there is no
> need for a KERN_CONT.  Keep it backward compatible by adding #define
> KERN_CONT ""
> 
> Joe, you *are* the problem here.

It's not any release version from 3.3 to 3.6 that I can find.
Perhaps you have faster processes than I have to isolate this.

> So you are literally the person who broke this.

No, I don't think so.  Not with the patch above.
Nor with any patch I wrote from 3.3 to 3.6.

> Goddammit, I don't want to hear another peep from you.

Try again, this time with feeling.

> You broke this because you wanted to save a few bytes in those strings,

Saving code size is generally good.
I didn't break any existing behavior.

> Fuck me sideways.

I trust and hope you prefer to be the big spoon.

Newlines added to formats today _do_ help prevent
interleaving from other processes.

Is that optimal?  No.
Would I prefer no newlines for these formats?  Sure.
Does your proposal to eliminate newlines work today?  No.
Is it an easy problem to fix?  No.

For today, it's better to add newlines to formats to help
avoid random interleaving.



Re: [GIT PULL] trivial for 4.9

2016-10-09 Thread Joe Perches
On Fri, 2016-10-07 at 14:37 -0700, Linus Torvalds wrote:
> On Fri, Oct 7, 2016 at 2:06 PM, Linus Torvalds
>  wrote:
> > 
> > And btw, even without an explicit KERN_, you should still not
> > get any interleaving. Only an _explicit_ KERN_CONT should cause
> > interleaving
> 
> 
> Btw, note the "should" there. Because we do seem to have broken that
> _again_.  It worked fine at some point, but lookie here:

So, I've gone back to each release from 3.6 to 3.3 looking for a case
where interleaving printks inserted newlines automatically for different
processes.

I can't find one.  Neither in dmesg nor in /dev/kmsg.

What version of the kernel do _you_ think had this behavior?

> commit 61e99ab8e35a88b8c4d0f80d3df9ee16df471be5
> Author: Joe Perches 
> Date:   Mon Jul 30 14:40:21 2012 -0700
> 
> printk: remove the now unnecessary "C" annotation for KERN_CONT
> 
> Now that all KERN_ uses are prefixed with ASCII SOH, there is no
> need for a KERN_CONT.  Keep it backward compatible by adding #define
> KERN_CONT ""
> 
> Joe, you *are* the problem here.

It's not any release version from 3.3 to 3.6 that I can find.
Perhaps you have faster processes than I have to isolate this.

> So you are literally the person who broke this.

No, I don't think so.  Not with the patch above.
Nor with any patch I wrote from 3.3 to 3.6.

> Goddammit, I don't want to hear another peep from you.

Try again, this time with feeling.

> You broke this because you wanted to save a few bytes in those strings,

Saving code size is generally good.
I didn't break any existing behavior.

> Fuck me sideways.

I trust and hope you prefer to be the big spoon.

Newlines added to formats today _do_ help prevent
interleaving from other processes.

Is that optimal?  No.
Would I prefer no newlines for these formats?  Sure.
Does your proposal to eliminate newlines work today?  No.
Is it an easy problem to fix?  No.

For today, it's better to add newlines to formats to help
avoid random interleaving.



[PATCH] perf: implement --delay on perf trace

2016-10-09 Thread Alexis Berlemont
Signed-off-by: Alexis Berlemont 
---
 tools/perf/builtin-trace.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c298bd3..0bae454 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2310,12 +2310,17 @@ static int trace__run(struct trace *trace, int argc, 
const char **argv)
if (err < 0)
goto out_error_mmap;
 
-   if (!target__none(>opts.target))
+   if (!target__none(>opts.target) && !trace->opts.initial_delay)
perf_evlist__enable(evlist);
 
if (forks)
perf_evlist__start_workload(evlist);
 
+   if (trace->opts.initial_delay) {
+   usleep(trace->opts.initial_delay * 1000);
+   perf_evlist__enable(evlist);
+   }
+
trace->multiple_threads = thread_map__pid(evlist->threads, 0) == -1 ||
  evlist->threads->nr > 1 ||
  perf_evlist__first(evlist)->attr.inherit;
@@ -2816,6 +2821,9 @@ int cmd_trace(int argc, const char **argv, const char 
*prefix __maybe_unused)
 "Default: kernel.perf_event_max_stack or " 
__stringify(PERF_MAX_STACK_DEPTH)),
OPT_UINTEGER(0, "proc-map-timeout", _map_timeout,
"per thread proc mmap processing timeout in ms"),
+   OPT_UINTEGER('D', "delay", _delay,
+"ms to wait before starting measurement after program "
+"start"),
OPT_END()
};
bool __maybe_unused max_stack_user_set = true;
-- 
2.10.0



[PATCH] perf: implement --delay on perf trace

2016-10-09 Thread Alexis Berlemont
Signed-off-by: Alexis Berlemont 
---
 tools/perf/builtin-trace.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c298bd3..0bae454 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2310,12 +2310,17 @@ static int trace__run(struct trace *trace, int argc, 
const char **argv)
if (err < 0)
goto out_error_mmap;
 
-   if (!target__none(>opts.target))
+   if (!target__none(>opts.target) && !trace->opts.initial_delay)
perf_evlist__enable(evlist);
 
if (forks)
perf_evlist__start_workload(evlist);
 
+   if (trace->opts.initial_delay) {
+   usleep(trace->opts.initial_delay * 1000);
+   perf_evlist__enable(evlist);
+   }
+
trace->multiple_threads = thread_map__pid(evlist->threads, 0) == -1 ||
  evlist->threads->nr > 1 ||
  perf_evlist__first(evlist)->attr.inherit;
@@ -2816,6 +2821,9 @@ int cmd_trace(int argc, const char **argv, const char 
*prefix __maybe_unused)
 "Default: kernel.perf_event_max_stack or " 
__stringify(PERF_MAX_STACK_DEPTH)),
OPT_UINTEGER(0, "proc-map-timeout", _map_timeout,
"per thread proc mmap processing timeout in ms"),
+   OPT_UINTEGER('D', "delay", _delay,
+"ms to wait before starting measurement after program "
+"start"),
OPT_END()
};
bool __maybe_unused max_stack_user_set = true;
-- 
2.10.0



[PATCH] Implement --delay on perf trace

2016-10-09 Thread Alexis Berlemont
Hi,

In the perf wiki todo-list, there is an entry regarding initial-delay and
perf trace; the following small patch tries to fulfill this point. It
has been generated against the branch tip/perf/core.

It has only been implemented in the "trace__run" case.

Ex.:

$ sudo strace -- ./perf trace --delay 5 sleep 1 2>&1
...
fcntl(7, F_SETFL, O_RDONLY|O_NONBLOCK)  = 0
ioctl(7, PERF_EVENT_IOC_ID, 0x7ffc8fd35718) = 0
ioctl(11, PERF_EVENT_IOC_SET_OUTPUT, 0x7) = 0
fcntl(11, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
ioctl(11, PERF_EVENT_IOC_ID, 0x7ffc8fd35718) = 0
write(6, "\0", 1)   = 1
close(6)= 0
nanosleep({0, 500}, NULL)   = 0  # DELAY OF 5 MS BEFORE ENABLING 
THE EVNTS
ioctl(3, PERF_EVENT_IOC_ENABLE, 0)  = 0
ioctl(4, PERF_EVENT_IOC_ENABLE, 0)  = 0
ioctl(5, PERF_EVENT_IOC_ENABLE, 0)  = 0
ioctl(7, PERF_EVENT_IOC_ENABLE, 0)  = 0
...

Alexis.

Alexis Berlemont (1):
  perf: implement --delay on perf trace

 tools/perf/builtin-trace.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

-- 
2.10.0



[PATCH] Implement --delay on perf trace

2016-10-09 Thread Alexis Berlemont
Hi,

In the perf wiki todo-list, there is an entry regarding initial-delay and
perf trace; the following small patch tries to fulfill this point. It
has been generated against the branch tip/perf/core.

It has only been implemented in the "trace__run" case.

Ex.:

$ sudo strace -- ./perf trace --delay 5 sleep 1 2>&1
...
fcntl(7, F_SETFL, O_RDONLY|O_NONBLOCK)  = 0
ioctl(7, PERF_EVENT_IOC_ID, 0x7ffc8fd35718) = 0
ioctl(11, PERF_EVENT_IOC_SET_OUTPUT, 0x7) = 0
fcntl(11, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
ioctl(11, PERF_EVENT_IOC_ID, 0x7ffc8fd35718) = 0
write(6, "\0", 1)   = 1
close(6)= 0
nanosleep({0, 500}, NULL)   = 0  # DELAY OF 5 MS BEFORE ENABLING 
THE EVNTS
ioctl(3, PERF_EVENT_IOC_ENABLE, 0)  = 0
ioctl(4, PERF_EVENT_IOC_ENABLE, 0)  = 0
ioctl(5, PERF_EVENT_IOC_ENABLE, 0)  = 0
ioctl(7, PERF_EVENT_IOC_ENABLE, 0)  = 0
...

Alexis.

Alexis Berlemont (1):
  perf: implement --delay on perf trace

 tools/perf/builtin-trace.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

-- 
2.10.0



[PATCH V3] staging: ks7010: use netdev_* instead of printk()

2016-10-09 Thread Sabitha George
1. Fixes checkpatch warning on printk usage in ks_hostif.c
2. Dropped "ks_wlan" prefix from the messages
3. Removed the "Memory squeeze,dropping packet" messages

Signed-off-by: Sabitha George 
---
 drivers/staging/ks7010/ks_hostif.c | 23 ++-
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index 5714cf7..e1188c0 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -465,8 +465,6 @@ void hostif_data_indication(struct ks_wlan_private *priv)
skb->dev->last_rx = jiffies;
netif_rx(skb);
} else {
-   printk(KERN_WARNING
-  "ks_wlan: Memory squeeze, dropping packet.\n");
priv->nstats.rx_dropped++;
}
break;
@@ -500,8 +498,6 @@ void hostif_data_indication(struct ks_wlan_private *priv)
skb->dev->last_rx = jiffies;
netif_rx(skb);
} else {
-   printk(KERN_WARNING
-  "ks_wlan: Memory squeeze, dropping packet.\n");
priv->nstats.rx_dropped++;
}
break;
@@ -549,7 +545,8 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
dev->dev_addr[5] = priv->eth_addr[5];
dev->dev_addr[6] = 0x00;
dev->dev_addr[7] = 0x00;
-   printk(KERN_INFO "ks_wlan: MAC ADDRESS = %pM\n", 
priv->eth_addr);
+   netdev_info(dev, "MAC ADDRESS = %pM\n",
+   priv->eth_addr);
break;
case DOT11_PRODUCT_VERSION:
/* firmware version */
@@ -557,8 +554,8 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
priv->version_size = priv->rx_size;
memcpy(priv->firmware_version, priv->rxp, priv->rx_size);
priv->firmware_version[priv->rx_size] = '\0';
-   printk(KERN_INFO "ks_wlan: firmware ver. = %s\n",
-  priv->firmware_version);
+   netdev_info(dev, "firmware ver. = %s\n",
+   priv->firmware_version);
hostif_sme_enqueue(priv, SME_GET_PRODUCT_VERSION);
/* wake_up_interruptible_all(>confirm_wait); */
complete(>confirm_wait);
@@ -578,12 +575,12 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
} else if (priv->eeprom_sum.type == 1) {
if (priv->eeprom_sum.result == 0) {
priv->eeprom_checksum = EEPROM_NG;
-   printk("LOCAL_EEPROM_SUM NG\n");
+   netdev_info(dev, "LOCAL_EEPROM_SUM NG\n");
} else if (priv->eeprom_sum.result == 1) {
priv->eeprom_checksum = EEPROM_OK;
}
} else {
-   printk("LOCAL_EEPROM_SUM error!\n");
+   netdev_err(dev, "LOCAL_EEPROM_SUM error!\n");
}
break;
default:
@@ -880,7 +877,7 @@ void hostif_stop_confirm(struct ks_wlan_private *priv)
netif_carrier_off(netdev);
tmp = FORCE_DISCONNECT & priv->connect_status;
priv->connect_status = tmp | DISCONNECT_STATUS;
-   printk("IWEVENT: disconnect\n");
+   netdev_info(netdev, "IWEVENT: disconnect\n");
 
wrqu0.data.length = 0;
wrqu0.data.flags = 0;
@@ -890,7 +887,7 @@ void hostif_stop_confirm(struct ks_wlan_private *priv)
&& (old_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
eth_zero_addr(wrqu0.ap_addr.sa_data);
DPRINTK(3, "IWEVENT: disconnect\n");
-   printk("IWEVENT: disconnect\n");
+   netdev_info(netdev, "IWEVENT: disconnect\n");
DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
priv->scan_ind_count);
wireless_send_event(netdev, SIOCGIWAP, , NULL);
@@ -1096,7 +1093,7 @@ void hostif_event_check(struct ks_wlan_private *priv)
case HIF_AP_SET_CONF:
default:
//DPRINTK(1, "undefined event[%04X]\n", event);
-   printk("undefined event[%04X]\n", event);
+   netdev_err(priv->net_dev, "undefined event[%04X]\n", event);
/* wake_up_all(>confirm_wait); */
complete(>confirm_wait);
break;
@@ -2644,7 +2641,7 @@ void hostif_sme_enqueue(struct ks_wlan_private *priv, 
unsigned short event)
} else {
/* in case of buffer overflow */
//DPRINTK(2,"sme queue buffer overflow\n");
-

[PATCH V3] staging: ks7010: use netdev_* instead of printk()

2016-10-09 Thread Sabitha George
1. Fixes checkpatch warning on printk usage in ks_hostif.c
2. Dropped "ks_wlan" prefix from the messages
3. Removed the "Memory squeeze,dropping packet" messages

Signed-off-by: Sabitha George 
---
 drivers/staging/ks7010/ks_hostif.c | 23 ++-
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index 5714cf7..e1188c0 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -465,8 +465,6 @@ void hostif_data_indication(struct ks_wlan_private *priv)
skb->dev->last_rx = jiffies;
netif_rx(skb);
} else {
-   printk(KERN_WARNING
-  "ks_wlan: Memory squeeze, dropping packet.\n");
priv->nstats.rx_dropped++;
}
break;
@@ -500,8 +498,6 @@ void hostif_data_indication(struct ks_wlan_private *priv)
skb->dev->last_rx = jiffies;
netif_rx(skb);
} else {
-   printk(KERN_WARNING
-  "ks_wlan: Memory squeeze, dropping packet.\n");
priv->nstats.rx_dropped++;
}
break;
@@ -549,7 +545,8 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
dev->dev_addr[5] = priv->eth_addr[5];
dev->dev_addr[6] = 0x00;
dev->dev_addr[7] = 0x00;
-   printk(KERN_INFO "ks_wlan: MAC ADDRESS = %pM\n", 
priv->eth_addr);
+   netdev_info(dev, "MAC ADDRESS = %pM\n",
+   priv->eth_addr);
break;
case DOT11_PRODUCT_VERSION:
/* firmware version */
@@ -557,8 +554,8 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
priv->version_size = priv->rx_size;
memcpy(priv->firmware_version, priv->rxp, priv->rx_size);
priv->firmware_version[priv->rx_size] = '\0';
-   printk(KERN_INFO "ks_wlan: firmware ver. = %s\n",
-  priv->firmware_version);
+   netdev_info(dev, "firmware ver. = %s\n",
+   priv->firmware_version);
hostif_sme_enqueue(priv, SME_GET_PRODUCT_VERSION);
/* wake_up_interruptible_all(>confirm_wait); */
complete(>confirm_wait);
@@ -578,12 +575,12 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
} else if (priv->eeprom_sum.type == 1) {
if (priv->eeprom_sum.result == 0) {
priv->eeprom_checksum = EEPROM_NG;
-   printk("LOCAL_EEPROM_SUM NG\n");
+   netdev_info(dev, "LOCAL_EEPROM_SUM NG\n");
} else if (priv->eeprom_sum.result == 1) {
priv->eeprom_checksum = EEPROM_OK;
}
} else {
-   printk("LOCAL_EEPROM_SUM error!\n");
+   netdev_err(dev, "LOCAL_EEPROM_SUM error!\n");
}
break;
default:
@@ -880,7 +877,7 @@ void hostif_stop_confirm(struct ks_wlan_private *priv)
netif_carrier_off(netdev);
tmp = FORCE_DISCONNECT & priv->connect_status;
priv->connect_status = tmp | DISCONNECT_STATUS;
-   printk("IWEVENT: disconnect\n");
+   netdev_info(netdev, "IWEVENT: disconnect\n");
 
wrqu0.data.length = 0;
wrqu0.data.flags = 0;
@@ -890,7 +887,7 @@ void hostif_stop_confirm(struct ks_wlan_private *priv)
&& (old_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
eth_zero_addr(wrqu0.ap_addr.sa_data);
DPRINTK(3, "IWEVENT: disconnect\n");
-   printk("IWEVENT: disconnect\n");
+   netdev_info(netdev, "IWEVENT: disconnect\n");
DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
priv->scan_ind_count);
wireless_send_event(netdev, SIOCGIWAP, , NULL);
@@ -1096,7 +1093,7 @@ void hostif_event_check(struct ks_wlan_private *priv)
case HIF_AP_SET_CONF:
default:
//DPRINTK(1, "undefined event[%04X]\n", event);
-   printk("undefined event[%04X]\n", event);
+   netdev_err(priv->net_dev, "undefined event[%04X]\n", event);
/* wake_up_all(>confirm_wait); */
complete(>confirm_wait);
break;
@@ -2644,7 +2641,7 @@ void hostif_sme_enqueue(struct ks_wlan_private *priv, 
unsigned short event)
} else {
/* in case of buffer overflow */
//DPRINTK(2,"sme queue buffer overflow\n");
-   printk("sme 

Re: [PATCH V2] staging: ks7010: use netdev_* instead of printk()

2016-10-09 Thread Greg KH
On Sun, Oct 09, 2016 at 10:46:26AM -0700, Joe Perches wrote:
> On Sun, 2016-10-09 at 22:04 +0530, Sabitha George wrote:
> > Fixes checkpatch warning on printk usage in ks_hostif.c
> []
> > diff --git a/drivers/staging/ks7010/ks_hostif.c 
> > b/drivers/staging/ks7010/ks_hostif.c
> []
> > @@ -465,8 +465,7 @@ void hostif_data_indication(struct ks_wlan_private 
> > *priv)
> > skb->dev->last_rx = jiffies;
> > netif_rx(skb);
> > } else {
> > -   printk(KERN_WARNING
> > -  "ks_wlan: Memory squeeze, dropping packet.\n");
> > +   netdev_warn(priv->net_dev, "ks_wlan: Memory squeeze, 
> > dropping packet.\n");
> 
> You could probably drop all the "ks_wlan: " prefixes here
> and the rx_dropped increase generally removes the need
> for a non-rate-limited warning message so these
> memory squeeze messages could be removed as well.

I agree, ks_wlan: should be removed.

thanks,

greg k-h


Re: [PATCH V2] staging: ks7010: use netdev_* instead of printk()

2016-10-09 Thread Greg KH
On Sun, Oct 09, 2016 at 10:46:26AM -0700, Joe Perches wrote:
> On Sun, 2016-10-09 at 22:04 +0530, Sabitha George wrote:
> > Fixes checkpatch warning on printk usage in ks_hostif.c
> []
> > diff --git a/drivers/staging/ks7010/ks_hostif.c 
> > b/drivers/staging/ks7010/ks_hostif.c
> []
> > @@ -465,8 +465,7 @@ void hostif_data_indication(struct ks_wlan_private 
> > *priv)
> > skb->dev->last_rx = jiffies;
> > netif_rx(skb);
> > } else {
> > -   printk(KERN_WARNING
> > -  "ks_wlan: Memory squeeze, dropping packet.\n");
> > +   netdev_warn(priv->net_dev, "ks_wlan: Memory squeeze, 
> > dropping packet.\n");
> 
> You could probably drop all the "ks_wlan: " prefixes here
> and the rx_dropped increase generally removes the need
> for a non-rate-limited warning message so these
> memory squeeze messages could be removed as well.

I agree, ks_wlan: should be removed.

thanks,

greg k-h


Re: Change CONFIG_DEVKMEM default value to n

2016-10-09 Thread Dave Young
On 10/10/16 at 07:12am, Greg Kroah-Hartman wrote:
> On Mon, Oct 10, 2016 at 10:50:50AM +0800, Dave Young wrote:
> > On 10/10/16 at 10:44am, Dave Young wrote:
> > > On 10/07/16 at 05:57am, Greg Kroah-Hartman wrote:
> > > > On Fri, Oct 07, 2016 at 10:04:11AM +0800, Dave Young wrote:
> > > > > Kconfig comment suggests setting it as "n" if in doubt thus move the
> > > > > default value to 'n'.
> > > > > 
> > > > > Signed-off-by: Dave Young 
> > > > > Suggested-by: Kees Cook 
> > > > > ---
> > > > >  drivers/char/Kconfig |2 +-
> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > 
> > > > > --- linux-x86.orig/drivers/char/Kconfig
> > > > > +++ linux-x86/drivers/char/Kconfig
> > > > > @@ -17,7 +17,7 @@ config DEVMEM
> > > > >  
> > > > >  config DEVKMEM
> > > > >   bool "/dev/kmem virtual device support"
> > > > > - default y
> > > > > + default n
> > > > 
> > > > If you remove the "default" line, it defaults to 'n'.
> > > 
> > > I personally perfer a "default n", but I can update it..
> > 
> > Greg, here is an update with dropping the default line:
> 
> 
> 
> Can you resend it in a format I can apply it in?

Done, thanks you!

> 
> thanks,
> 
> greg k-h


Re: Change CONFIG_DEVKMEM default value to n

2016-10-09 Thread Dave Young
On 10/10/16 at 07:12am, Greg Kroah-Hartman wrote:
> On Mon, Oct 10, 2016 at 10:50:50AM +0800, Dave Young wrote:
> > On 10/10/16 at 10:44am, Dave Young wrote:
> > > On 10/07/16 at 05:57am, Greg Kroah-Hartman wrote:
> > > > On Fri, Oct 07, 2016 at 10:04:11AM +0800, Dave Young wrote:
> > > > > Kconfig comment suggests setting it as "n" if in doubt thus move the
> > > > > default value to 'n'.
> > > > > 
> > > > > Signed-off-by: Dave Young 
> > > > > Suggested-by: Kees Cook 
> > > > > ---
> > > > >  drivers/char/Kconfig |2 +-
> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > 
> > > > > --- linux-x86.orig/drivers/char/Kconfig
> > > > > +++ linux-x86/drivers/char/Kconfig
> > > > > @@ -17,7 +17,7 @@ config DEVMEM
> > > > >  
> > > > >  config DEVKMEM
> > > > >   bool "/dev/kmem virtual device support"
> > > > > - default y
> > > > > + default n
> > > > 
> > > > If you remove the "default" line, it defaults to 'n'.
> > > 
> > > I personally perfer a "default n", but I can update it..
> > 
> > Greg, here is an update with dropping the default line:
> 
> 
> 
> Can you resend it in a format I can apply it in?

Done, thanks you!

> 
> thanks,
> 
> greg k-h


[PATCH v2] Move CONFIG_DEVKMEM default to n

2016-10-09 Thread Dave Young
Kconfig comment suggests setting it as "n" if in doubt thus move the
default value to 'n'.

Signed-off-by: Dave Young 
Suggested-by: Kees Cook 
---
Greg: drop the "default" line will set the default as n
 drivers/char/Kconfig |1 -
 1 file changed, 1 deletion(-)

--- linux-x86.orig/drivers/char/Kconfig
+++ linux-x86/drivers/char/Kconfig
@@ -17,7 +17,6 @@ config DEVMEM
 
 config DEVKMEM
bool "/dev/kmem virtual device support"
-   default y
help
  Say Y here if you want to support the /dev/kmem device. The
  /dev/kmem device is rarely used, but can be used for certain


[PATCH v2] Move CONFIG_DEVKMEM default to n

2016-10-09 Thread Dave Young
Kconfig comment suggests setting it as "n" if in doubt thus move the
default value to 'n'.

Signed-off-by: Dave Young 
Suggested-by: Kees Cook 
---
Greg: drop the "default" line will set the default as n
 drivers/char/Kconfig |1 -
 1 file changed, 1 deletion(-)

--- linux-x86.orig/drivers/char/Kconfig
+++ linux-x86/drivers/char/Kconfig
@@ -17,7 +17,6 @@ config DEVMEM
 
 config DEVKMEM
bool "/dev/kmem virtual device support"
-   default y
help
  Say Y here if you want to support the /dev/kmem device. The
  /dev/kmem device is rarely used, but can be used for certain


Re: Change CONFIG_DEVKMEM default value to n

2016-10-09 Thread Greg Kroah-Hartman
On Mon, Oct 10, 2016 at 10:50:50AM +0800, Dave Young wrote:
> On 10/10/16 at 10:44am, Dave Young wrote:
> > On 10/07/16 at 05:57am, Greg Kroah-Hartman wrote:
> > > On Fri, Oct 07, 2016 at 10:04:11AM +0800, Dave Young wrote:
> > > > Kconfig comment suggests setting it as "n" if in doubt thus move the
> > > > default value to 'n'.
> > > > 
> > > > Signed-off-by: Dave Young 
> > > > Suggested-by: Kees Cook 
> > > > ---
> > > >  drivers/char/Kconfig |2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > --- linux-x86.orig/drivers/char/Kconfig
> > > > +++ linux-x86/drivers/char/Kconfig
> > > > @@ -17,7 +17,7 @@ config DEVMEM
> > > >  
> > > >  config DEVKMEM
> > > > bool "/dev/kmem virtual device support"
> > > > -   default y
> > > > +   default n
> > > 
> > > If you remove the "default" line, it defaults to 'n'.
> > 
> > I personally perfer a "default n", but I can update it..
> 
> Greg, here is an update with dropping the default line:



Can you resend it in a format I can apply it in?

thanks,

greg k-h


Re: Change CONFIG_DEVKMEM default value to n

2016-10-09 Thread Greg Kroah-Hartman
On Mon, Oct 10, 2016 at 10:50:50AM +0800, Dave Young wrote:
> On 10/10/16 at 10:44am, Dave Young wrote:
> > On 10/07/16 at 05:57am, Greg Kroah-Hartman wrote:
> > > On Fri, Oct 07, 2016 at 10:04:11AM +0800, Dave Young wrote:
> > > > Kconfig comment suggests setting it as "n" if in doubt thus move the
> > > > default value to 'n'.
> > > > 
> > > > Signed-off-by: Dave Young 
> > > > Suggested-by: Kees Cook 
> > > > ---
> > > >  drivers/char/Kconfig |2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > --- linux-x86.orig/drivers/char/Kconfig
> > > > +++ linux-x86/drivers/char/Kconfig
> > > > @@ -17,7 +17,7 @@ config DEVMEM
> > > >  
> > > >  config DEVKMEM
> > > > bool "/dev/kmem virtual device support"
> > > > -   default y
> > > > +   default n
> > > 
> > > If you remove the "default" line, it defaults to 'n'.
> > 
> > I personally perfer a "default n", but I can update it..
> 
> Greg, here is an update with dropping the default line:



Can you resend it in a format I can apply it in?

thanks,

greg k-h


Re: perf TUI fails with "failed to process type: 64"

2016-10-09 Thread Michael Ellerman
Anton Blanchard  writes:

> Hi,
>
> Updating to mainline as of last night, I started seeing the following
> error when running the perf report TUI:
>
> 0x46068 [0x8]: failed to process type: 68
>
> This event is just PERF_RECORD_FINISHED_ROUND:
>
> 0x46068 [0x8]: event: 68
> .
> . ... raw event: size 8 bytes
> .  :  44 00 00 00 00 00 08 00  D...
>
> 0x46068 [0x8]: PERF_RECORD_FINISHED_ROUND
>
> Which of course is not our error. It took me a while to find the real
> culprit:
>
>  14c00-14c00 g exc_virt_0x4c00_system_call
   ^
   What's this? The address? If so it's wrong?
   

> A zero length symbol, which __symbol__inc_addr_samples() barfs on:
>
> if (addr < sym->start || addr >= sym->end) {
> ...
>   return -ERANGE;
>
> Seems like we have 3 bugs here:
...
>
> 3. Why do we have zero length symbols in the first place? Does the recent
>ppc64 exception clean up have something to do with it?

Seems likely. But I can't see why.

AFAICS we have never emitted a size for those symbols:

Old:
$ nm --print-size build/vmlinux | grep -w system_call_relon_pSeries
c0004c00 T system_call_relon_pSeries

New:
$ nm --print-size build/vmlinux | grep -w exc_virt_0x4c00_system_call
c0004c00 T exc_virt_0x4c00_system_call


It also doesn't look like we're emitting another symbol with the same
address, which has caused confusion in the past:

Old:
c0004c00 T exc_virt_0x4c00_system_call
c0004d00 T exc_virt_0x4d00_single_step

New:
c0004c00 T system_call_relon_pSeries
c0004d00 T single_step_relon_pSeries


So more digging required.

cheers


Re: perf TUI fails with "failed to process type: 64"

2016-10-09 Thread Michael Ellerman
Anton Blanchard  writes:

> Hi,
>
> Updating to mainline as of last night, I started seeing the following
> error when running the perf report TUI:
>
> 0x46068 [0x8]: failed to process type: 68
>
> This event is just PERF_RECORD_FINISHED_ROUND:
>
> 0x46068 [0x8]: event: 68
> .
> . ... raw event: size 8 bytes
> .  :  44 00 00 00 00 00 08 00  D...
>
> 0x46068 [0x8]: PERF_RECORD_FINISHED_ROUND
>
> Which of course is not our error. It took me a while to find the real
> culprit:
>
>  14c00-14c00 g exc_virt_0x4c00_system_call
   ^
   What's this? The address? If so it's wrong?
   

> A zero length symbol, which __symbol__inc_addr_samples() barfs on:
>
> if (addr < sym->start || addr >= sym->end) {
> ...
>   return -ERANGE;
>
> Seems like we have 3 bugs here:
...
>
> 3. Why do we have zero length symbols in the first place? Does the recent
>ppc64 exception clean up have something to do with it?

Seems likely. But I can't see why.

AFAICS we have never emitted a size for those symbols:

Old:
$ nm --print-size build/vmlinux | grep -w system_call_relon_pSeries
c0004c00 T system_call_relon_pSeries

New:
$ nm --print-size build/vmlinux | grep -w exc_virt_0x4c00_system_call
c0004c00 T exc_virt_0x4c00_system_call


It also doesn't look like we're emitting another symbol with the same
address, which has caused confusion in the past:

Old:
c0004c00 T exc_virt_0x4c00_system_call
c0004d00 T exc_virt_0x4d00_single_step

New:
c0004c00 T system_call_relon_pSeries
c0004d00 T single_step_relon_pSeries


So more digging required.

cheers


Re: [tpmdd-devel] [PATCH RFC 1/3] tpm_crb: expand struct crb_control_area to struct crb_regs

2016-10-09 Thread Jarkko Sakkinen
On Mon, Oct 10, 2016 at 12:25:11AM +, Winkler, Tomas wrote:
> 
> 
> > -Original Message-
> > From: Jason Gunthorpe [mailto:jguntho...@obsidianresearch.com]
> > Sent: Monday, October 10, 2016 02:08
> > To: Jarkko Sakkinen 
> > Cc: moderated list:TPM DEVICE DRIVER ;
> > open list 
> > Subject: Re: [tpmdd-devel] [PATCH RFC 1/3] tpm_crb: expand struct
> > crb_control_area to struct crb_regs
> > 
> > On Sun, Oct 09, 2016 at 09:33:58PM +0300, Jarkko Sakkinen wrote:
> > 
> > > > Sorry I missed this part.
> > > >
> > > > Here are the constraints for existing hardware:
> > > >
> > > > 1. All the existing CRB start only hardware has the iomem covering the
> > > >control area and registers for multiple localities.
> > > > 2. All the existing ACPI start hardware has only the control area.
> > > >
> > > > If you assume that SSDT does not have malicous behavior caused by
> > > > either a BIOS bug or maybe a rootkit, then the current patch works
> > > > for all the existing hardware.
> > > >
> > > > To counter-measure for unexpected behavior in non-existing hardware
> > > > and buggy or malicious firmware it probably make sense to use
> > > > crb_map_res to validate the part of the CRB registers that is not
> > > > part of the control area.
> > 
> > I don't know how much I'd assume BIOS authors do what you think - the spec I
> > saw for this seems very vauge.
> > 
> > Certainly checking that locality region falls within the acpi mapping seems
> > essential.
> > 
> > > > Doing it in the way you proposed does not work for ACPI start devices.
> > > >
> > > > For them it should be done in the same way as I'm doing in the
> > > > existing patch as for ACPI start devices the address below the
> > > > control area are never accessed. Having a separate crb_map_res for
> > > > CRB start only devices is sane thing to do for validation.
> > >
> > > Alternative is to do two structures crb_regs_head and crb_regs_tail,
> > > which might be cleaner. I'm fine with going either route.
> > 
> > Since the iomem doesn't actually exist for a configuration having two 
> > pointers
> > is the better choice. Make sure one is null for the configuration that does 
> > not
> > support it.
> > 
> > The negative offset thing is way too subtle.
> 
> I addition I believe it should be always on offset FED4_0xxxh by the
> Spec, so all this arithmetic is a bit of overkill.

It's all done to workaround ACPI start. Even if CRB start devices would
always be in that offset it still would be needed.

> Thanks
> Tomas

/Jarkko


Re: [tpmdd-devel] [PATCH RFC 1/3] tpm_crb: expand struct crb_control_area to struct crb_regs

2016-10-09 Thread Jarkko Sakkinen
On Mon, Oct 10, 2016 at 12:25:11AM +, Winkler, Tomas wrote:
> 
> 
> > -Original Message-
> > From: Jason Gunthorpe [mailto:jguntho...@obsidianresearch.com]
> > Sent: Monday, October 10, 2016 02:08
> > To: Jarkko Sakkinen 
> > Cc: moderated list:TPM DEVICE DRIVER ;
> > open list 
> > Subject: Re: [tpmdd-devel] [PATCH RFC 1/3] tpm_crb: expand struct
> > crb_control_area to struct crb_regs
> > 
> > On Sun, Oct 09, 2016 at 09:33:58PM +0300, Jarkko Sakkinen wrote:
> > 
> > > > Sorry I missed this part.
> > > >
> > > > Here are the constraints for existing hardware:
> > > >
> > > > 1. All the existing CRB start only hardware has the iomem covering the
> > > >control area and registers for multiple localities.
> > > > 2. All the existing ACPI start hardware has only the control area.
> > > >
> > > > If you assume that SSDT does not have malicous behavior caused by
> > > > either a BIOS bug or maybe a rootkit, then the current patch works
> > > > for all the existing hardware.
> > > >
> > > > To counter-measure for unexpected behavior in non-existing hardware
> > > > and buggy or malicious firmware it probably make sense to use
> > > > crb_map_res to validate the part of the CRB registers that is not
> > > > part of the control area.
> > 
> > I don't know how much I'd assume BIOS authors do what you think - the spec I
> > saw for this seems very vauge.
> > 
> > Certainly checking that locality region falls within the acpi mapping seems
> > essential.
> > 
> > > > Doing it in the way you proposed does not work for ACPI start devices.
> > > >
> > > > For them it should be done in the same way as I'm doing in the
> > > > existing patch as for ACPI start devices the address below the
> > > > control area are never accessed. Having a separate crb_map_res for
> > > > CRB start only devices is sane thing to do for validation.
> > >
> > > Alternative is to do two structures crb_regs_head and crb_regs_tail,
> > > which might be cleaner. I'm fine with going either route.
> > 
> > Since the iomem doesn't actually exist for a configuration having two 
> > pointers
> > is the better choice. Make sure one is null for the configuration that does 
> > not
> > support it.
> > 
> > The negative offset thing is way too subtle.
> 
> I addition I believe it should be always on offset FED4_0xxxh by the
> Spec, so all this arithmetic is a bit of overkill.

It's all done to workaround ACPI start. Even if CRB start devices would
always be in that offset it still would be needed.

> Thanks
> Tomas

/Jarkko


[PATCH v3 03/12] scsi/atari_scsi: Make device register accessors re-entrant

2016-10-09 Thread Finn Thain
This patch fixes an old bug: accesses to device registers from the
interrupt handler (after reselection, DMA completion etc.) could mess
up a device register access elsewhere, if the latter takes place outside
of an irq lock (during selection etc.).

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Michael Schmitz 
---
 drivers/scsi/atari_scsi.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index a59ad94..862f30c 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -670,14 +670,26 @@ static void atari_scsi_tt_reg_write(unsigned char reg, 
unsigned char value)
 
 static unsigned char atari_scsi_falcon_reg_read(unsigned char reg)
 {
-   dma_wd.dma_mode_status= (u_short)(0x88 + reg);
-   return (u_char)dma_wd.fdc_acces_seccount;
+   unsigned long flags;
+   unsigned char result;
+
+   reg += 0x88;
+   local_irq_save(flags);
+   dma_wd.dma_mode_status = (u_short)reg;
+   result = (u_char)dma_wd.fdc_acces_seccount;
+   local_irq_restore(flags);
+   return result;
 }
 
 static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value)
 {
-   dma_wd.dma_mode_status = (u_short)(0x88 + reg);
+   unsigned long flags;
+
+   reg += 0x88;
+   local_irq_save(flags);
+   dma_wd.dma_mode_status = (u_short)reg;
dma_wd.fdc_acces_seccount = (u_short)value;
+   local_irq_restore(flags);
 }
 
 
-- 
2.7.3



[PATCH v3 10/12] scsi/ncr5380: Expedite register polling

2016-10-09 Thread Finn Thain
Avoid the call to NCR5380_poll_politely2() when possible. The call is
easily short-circuited on the PIO fast path, using the inline wrapper.
This requires that the NCR5380_read macro be made available before
any #include "NCR5380.h" so a few declarations have to be moved too.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.h  | 3 +++
 drivers/scsi/arm/cumana_1.c | 4 
 drivers/scsi/atari_scsi.c   | 6 +++---
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index 4682baa..b2c560c 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -310,6 +310,9 @@ static inline int NCR5380_poll_politely(struct 
NCR5380_hostdata *hostdata,
 unsigned int reg, u8 bit, u8 val,
 unsigned long wait)
 {
+   if ((NCR5380_read(reg) & bit) == val)
+   return 0;
+
return NCR5380_poll_politely2(hostdata, reg, bit, val,
reg, bit, val, wait);
 }
diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index ae1d4c6..fb7600d 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -29,6 +29,10 @@
 #define NCR5380_implementation_fields  \
unsigned ctrl
 
+struct NCR5380_hostdata;
+static u8 cumanascsi_read(struct NCR5380_hostdata *, unsigned int);
+static void cumanascsi_write(struct NCR5380_hostdata *, unsigned int, u8);
+
 #include "../NCR5380.h"
 
 #define CTRL   0x16fc
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index aed69ac..f77c311 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -57,6 +57,9 @@
 
 #define NCR5380_implementation_fields   /* none */
 
+static u8 (*atari_scsi_reg_read)(unsigned int);
+static void (*atari_scsi_reg_write)(unsigned int, u8);
+
 #define NCR5380_read(reg)   atari_scsi_reg_read(reg)
 #define NCR5380_write(reg, value)   atari_scsi_reg_write(reg, value)
 
@@ -126,9 +129,6 @@ static inline unsigned long SCSI_DMA_GETADR(void)
 
 static void atari_scsi_fetch_restbytes(void);
 
-static u8 (*atari_scsi_reg_read)(unsigned int);
-static void (*atari_scsi_reg_write)(unsigned int, u8);
-
 static unsigned long   atari_dma_residual, atari_dma_startaddr;
 static short   atari_dma_active;
 /* pointer to the dribble buffer */
-- 
2.7.3



[PATCH v3 01/12] scsi/g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio drivers

2016-10-09 Thread Finn Thain
From: Ondrej Zary 

Merge the port-mapped IO and memory-mapped IO support (with the help of
ioport_map) into the g_NCR5380 module and delete g_NCR5380_mmio.

Signed-off-by: Ondrej Zary 
Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
---
 MAINTAINERS   |   1 -
 drivers/scsi/Kconfig  |  32 +-
 drivers/scsi/Makefile |   1 -
 drivers/scsi/g_NCR5380.c  | 252 --
 drivers/scsi/g_NCR5380.h  |  33 ++
 drivers/scsi/g_NCR5380_mmio.c |  10 --
 6 files changed, 134 insertions(+), 195 deletions(-)
 delete mode 100644 drivers/scsi/g_NCR5380_mmio.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f0ee7a6..29ffef5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8048,7 +8048,6 @@ F:drivers/scsi/arm/oak.c
 F: drivers/scsi/atari_scsi.*
 F: drivers/scsi/dmx3191d.c
 F: drivers/scsi/g_NCR5380.*
-F: drivers/scsi/g_NCR5380_mmio.c
 F: drivers/scsi/mac_scsi.*
 F: drivers/scsi/sun3_scsi.*
 F: drivers/scsi/sun3_scsi_vme.c
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 3e2bdb9..98451fe 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -743,40 +743,18 @@ config SCSI_ISCI
  control unit found in the Intel(R) C600 series chipset.
 
 config SCSI_GENERIC_NCR5380
-   tristate "Generic NCR5380/53c400 SCSI PIO support"
+   tristate "Generic NCR5380/53c400 SCSI ISA card support"
depends on ISA && SCSI
select SCSI_SPI_ATTRS
---help---
- This is a driver for the old NCR 53c80 series of SCSI controllers
- on boards using PIO. Most boards such as the Trantor T130 fit this
- category, along with a large number of ISA 8bit controllers shipped
- for free with SCSI scanners. If you have a PAS16, T128 or DMX3191
- you should select the specific driver for that card rather than
- generic 5380 support.
-
- It is explained in section 3.8 of the SCSI-HOWTO, available from
- .  If it doesn't work out
- of the box, you may have to change some settings in
- .
+ This is a driver for old ISA card SCSI controllers based on a
+ NCR 5380, 53C80, 53C400, 53C400A, or DTC 436 device.
+ Most boards such as the Trantor T130 fit this category, as do
+ various 8-bit and 16-bit ISA cards bundled with SCSI scanners.
 
  To compile this driver as a module, choose M here: the
  module will be called g_NCR5380.
 
-config SCSI_GENERIC_NCR5380_MMIO
-   tristate "Generic NCR5380/53c400 SCSI MMIO support"
-   depends on ISA && SCSI
-   select SCSI_SPI_ATTRS
-   ---help---
- This is a driver for the old NCR 53c80 series of SCSI controllers
- on boards using memory mapped I/O. 
- It is explained in section 3.8 of the SCSI-HOWTO, available from
- .  If it doesn't work out
- of the box, you may have to change some settings in
- .
-
- To compile this driver as a module, choose M here: the
- module will be called g_NCR5380_mmio.
-
 config SCSI_IPS
tristate "IBM ServeRAID support"
depends on PCI && SCSI
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 38d938d..2ac1b9f 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -74,7 +74,6 @@ obj-$(CONFIG_SCSI_ISCI)   += isci/
 obj-$(CONFIG_SCSI_IPS) += ips.o
 obj-$(CONFIG_SCSI_FUTURE_DOMAIN)+= fdomain.o
 obj-$(CONFIG_SCSI_GENERIC_NCR5380) += g_NCR5380.o
-obj-$(CONFIG_SCSI_GENERIC_NCR5380_MMIO) += g_NCR5380_mmio.o
 obj-$(CONFIG_SCSI_NCR53C406A)  += NCR53c406a.o
 obj-$(CONFIG_SCSI_NCR_D700)+= 53c700.o NCR_D700.o
 obj-$(CONFIG_SCSI_NCR_Q720)+= NCR_Q720_mod.o
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index cbf0103..4d7a9de 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -64,9 +64,9 @@ static int card[] = { -1, -1, -1, -1, -1, -1, -1, -1 };
 module_param_array(card, int, NULL, 0);
 MODULE_PARM_DESC(card, "card type (0=NCR5380, 1=NCR53C400, 2=NCR53C400A, 
3=DTC3181E, 4=HP C2502)");
 
+MODULE_ALIAS("g_NCR5380_mmio");
 MODULE_LICENSE("GPL");
 
-#ifndef SCSI_G_NCR5380_MEM
 /*
  * Configure I/O address of 53C400A or DTC436 by writing magic numbers
  * to ports 0x779 and 0x379.
@@ -88,40 +88,35 @@ static void magic_configure(int idx, u8 irq, u8 magic[])
cfg = 0x80 | idx | (irq << 4);
outb(cfg, 0x379);
 }
-#endif
+
+static unsigned int ncr_53c400a_ports[] = {
+   0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0
+};
+static unsigned int dtc_3181e_ports[] = {
+   0x220, 0x240, 0x280, 0x2a0, 0x2c0, 0x300, 0x320, 0x340, 0
+};
+static u8 ncr_53c400a_magic[] = {  /* 53C400A & 

[PATCH v3 03/12] scsi/atari_scsi: Make device register accessors re-entrant

2016-10-09 Thread Finn Thain
This patch fixes an old bug: accesses to device registers from the
interrupt handler (after reselection, DMA completion etc.) could mess
up a device register access elsewhere, if the latter takes place outside
of an irq lock (during selection etc.).

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Michael Schmitz 
---
 drivers/scsi/atari_scsi.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index a59ad94..862f30c 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -670,14 +670,26 @@ static void atari_scsi_tt_reg_write(unsigned char reg, 
unsigned char value)
 
 static unsigned char atari_scsi_falcon_reg_read(unsigned char reg)
 {
-   dma_wd.dma_mode_status= (u_short)(0x88 + reg);
-   return (u_char)dma_wd.fdc_acces_seccount;
+   unsigned long flags;
+   unsigned char result;
+
+   reg += 0x88;
+   local_irq_save(flags);
+   dma_wd.dma_mode_status = (u_short)reg;
+   result = (u_char)dma_wd.fdc_acces_seccount;
+   local_irq_restore(flags);
+   return result;
 }
 
 static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value)
 {
-   dma_wd.dma_mode_status = (u_short)(0x88 + reg);
+   unsigned long flags;
+
+   reg += 0x88;
+   local_irq_save(flags);
+   dma_wd.dma_mode_status = (u_short)reg;
dma_wd.fdc_acces_seccount = (u_short)value;
+   local_irq_restore(flags);
 }
 
 
-- 
2.7.3



[PATCH v3 10/12] scsi/ncr5380: Expedite register polling

2016-10-09 Thread Finn Thain
Avoid the call to NCR5380_poll_politely2() when possible. The call is
easily short-circuited on the PIO fast path, using the inline wrapper.
This requires that the NCR5380_read macro be made available before
any #include "NCR5380.h" so a few declarations have to be moved too.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.h  | 3 +++
 drivers/scsi/arm/cumana_1.c | 4 
 drivers/scsi/atari_scsi.c   | 6 +++---
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index 4682baa..b2c560c 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -310,6 +310,9 @@ static inline int NCR5380_poll_politely(struct 
NCR5380_hostdata *hostdata,
 unsigned int reg, u8 bit, u8 val,
 unsigned long wait)
 {
+   if ((NCR5380_read(reg) & bit) == val)
+   return 0;
+
return NCR5380_poll_politely2(hostdata, reg, bit, val,
reg, bit, val, wait);
 }
diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index ae1d4c6..fb7600d 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -29,6 +29,10 @@
 #define NCR5380_implementation_fields  \
unsigned ctrl
 
+struct NCR5380_hostdata;
+static u8 cumanascsi_read(struct NCR5380_hostdata *, unsigned int);
+static void cumanascsi_write(struct NCR5380_hostdata *, unsigned int, u8);
+
 #include "../NCR5380.h"
 
 #define CTRL   0x16fc
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index aed69ac..f77c311 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -57,6 +57,9 @@
 
 #define NCR5380_implementation_fields   /* none */
 
+static u8 (*atari_scsi_reg_read)(unsigned int);
+static void (*atari_scsi_reg_write)(unsigned int, u8);
+
 #define NCR5380_read(reg)   atari_scsi_reg_read(reg)
 #define NCR5380_write(reg, value)   atari_scsi_reg_write(reg, value)
 
@@ -126,9 +129,6 @@ static inline unsigned long SCSI_DMA_GETADR(void)
 
 static void atari_scsi_fetch_restbytes(void);
 
-static u8 (*atari_scsi_reg_read)(unsigned int);
-static void (*atari_scsi_reg_write)(unsigned int, u8);
-
 static unsigned long   atari_dma_residual, atari_dma_startaddr;
 static short   atari_dma_active;
 /* pointer to the dribble buffer */
-- 
2.7.3



[PATCH v3 01/12] scsi/g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio drivers

2016-10-09 Thread Finn Thain
From: Ondrej Zary 

Merge the port-mapped IO and memory-mapped IO support (with the help of
ioport_map) into the g_NCR5380 module and delete g_NCR5380_mmio.

Signed-off-by: Ondrej Zary 
Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
---
 MAINTAINERS   |   1 -
 drivers/scsi/Kconfig  |  32 +-
 drivers/scsi/Makefile |   1 -
 drivers/scsi/g_NCR5380.c  | 252 --
 drivers/scsi/g_NCR5380.h  |  33 ++
 drivers/scsi/g_NCR5380_mmio.c |  10 --
 6 files changed, 134 insertions(+), 195 deletions(-)
 delete mode 100644 drivers/scsi/g_NCR5380_mmio.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f0ee7a6..29ffef5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8048,7 +8048,6 @@ F:drivers/scsi/arm/oak.c
 F: drivers/scsi/atari_scsi.*
 F: drivers/scsi/dmx3191d.c
 F: drivers/scsi/g_NCR5380.*
-F: drivers/scsi/g_NCR5380_mmio.c
 F: drivers/scsi/mac_scsi.*
 F: drivers/scsi/sun3_scsi.*
 F: drivers/scsi/sun3_scsi_vme.c
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 3e2bdb9..98451fe 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -743,40 +743,18 @@ config SCSI_ISCI
  control unit found in the Intel(R) C600 series chipset.
 
 config SCSI_GENERIC_NCR5380
-   tristate "Generic NCR5380/53c400 SCSI PIO support"
+   tristate "Generic NCR5380/53c400 SCSI ISA card support"
depends on ISA && SCSI
select SCSI_SPI_ATTRS
---help---
- This is a driver for the old NCR 53c80 series of SCSI controllers
- on boards using PIO. Most boards such as the Trantor T130 fit this
- category, along with a large number of ISA 8bit controllers shipped
- for free with SCSI scanners. If you have a PAS16, T128 or DMX3191
- you should select the specific driver for that card rather than
- generic 5380 support.
-
- It is explained in section 3.8 of the SCSI-HOWTO, available from
- .  If it doesn't work out
- of the box, you may have to change some settings in
- .
+ This is a driver for old ISA card SCSI controllers based on a
+ NCR 5380, 53C80, 53C400, 53C400A, or DTC 436 device.
+ Most boards such as the Trantor T130 fit this category, as do
+ various 8-bit and 16-bit ISA cards bundled with SCSI scanners.
 
  To compile this driver as a module, choose M here: the
  module will be called g_NCR5380.
 
-config SCSI_GENERIC_NCR5380_MMIO
-   tristate "Generic NCR5380/53c400 SCSI MMIO support"
-   depends on ISA && SCSI
-   select SCSI_SPI_ATTRS
-   ---help---
- This is a driver for the old NCR 53c80 series of SCSI controllers
- on boards using memory mapped I/O. 
- It is explained in section 3.8 of the SCSI-HOWTO, available from
- .  If it doesn't work out
- of the box, you may have to change some settings in
- .
-
- To compile this driver as a module, choose M here: the
- module will be called g_NCR5380_mmio.
-
 config SCSI_IPS
tristate "IBM ServeRAID support"
depends on PCI && SCSI
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 38d938d..2ac1b9f 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -74,7 +74,6 @@ obj-$(CONFIG_SCSI_ISCI)   += isci/
 obj-$(CONFIG_SCSI_IPS) += ips.o
 obj-$(CONFIG_SCSI_FUTURE_DOMAIN)+= fdomain.o
 obj-$(CONFIG_SCSI_GENERIC_NCR5380) += g_NCR5380.o
-obj-$(CONFIG_SCSI_GENERIC_NCR5380_MMIO) += g_NCR5380_mmio.o
 obj-$(CONFIG_SCSI_NCR53C406A)  += NCR53c406a.o
 obj-$(CONFIG_SCSI_NCR_D700)+= 53c700.o NCR_D700.o
 obj-$(CONFIG_SCSI_NCR_Q720)+= NCR_Q720_mod.o
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index cbf0103..4d7a9de 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -64,9 +64,9 @@ static int card[] = { -1, -1, -1, -1, -1, -1, -1, -1 };
 module_param_array(card, int, NULL, 0);
 MODULE_PARM_DESC(card, "card type (0=NCR5380, 1=NCR53C400, 2=NCR53C400A, 
3=DTC3181E, 4=HP C2502)");
 
+MODULE_ALIAS("g_NCR5380_mmio");
 MODULE_LICENSE("GPL");
 
-#ifndef SCSI_G_NCR5380_MEM
 /*
  * Configure I/O address of 53C400A or DTC436 by writing magic numbers
  * to ports 0x779 and 0x379.
@@ -88,40 +88,35 @@ static void magic_configure(int idx, u8 irq, u8 magic[])
cfg = 0x80 | idx | (irq << 4);
outb(cfg, 0x379);
 }
-#endif
+
+static unsigned int ncr_53c400a_ports[] = {
+   0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0
+};
+static unsigned int dtc_3181e_ports[] = {
+   0x220, 0x240, 0x280, 0x2a0, 0x2c0, 0x300, 0x320, 0x340, 0
+};
+static u8 ncr_53c400a_magic[] = {  /* 53C400A & DTC436 */
+   0x59, 0xb9, 0xc5, 0xae, 0xa6
+};
+static u8 hp_c2502_magic[] = { /* HP C2502 */
+   0x0f, 0x22, 0xf0, 0x20, 

[PATCH v3 06/12] scsi/ncr5380: Improve hostdata struct member alignment and cache-ability

2016-10-09 Thread Finn Thain
Re-order struct members so that hot data lies at the beginning of the
struct and cold data at the end. Improve the comments while we're here.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.h | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index f0eea44..ceafa0c 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -219,27 +219,27 @@
 #define FLAG_TOSHIBA_DELAY 128 /* Allow for borken CD-ROMs */
 
 struct NCR5380_hostdata {
-   NCR5380_implementation_fields;  /* implementation specific */
-   struct Scsi_Host *host; /* Host backpointer */
-   unsigned char id_mask, id_higher_mask;  /* 1 << id, all bits greater */
-   unsigned char busy[8];  /* index = target, bit = lun */
-   int dma_len;/* requested length of DMA */
-   unsigned char last_message; /* last message OUT */
-   struct scsi_cmnd *connected;/* currently connected cmnd */
-   struct scsi_cmnd *selecting;/* cmnd to be connected */
-   struct list_head unissued;  /* waiting to be issued */
-   struct list_head autosense; /* priority issue queue */
-   struct list_head disconnected;  /* waiting for reconnect */
-   spinlock_t lock;/* protects this struct */
-   int flags;
-   struct scsi_eh_save ses;
-   struct scsi_cmnd *sensing;
+   NCR5380_implementation_fields;  /* Board-specific data */
+   unsigned long poll_loops;   /* Register polling limit */
+   spinlock_t lock;/* Protects this struct */
+   struct scsi_cmnd *connected;/* Currently connected cmnd */
+   struct list_head disconnected;  /* Waiting for reconnect */
+   struct Scsi_Host *host; /* SCSI host backpointer */
+   struct workqueue_struct *work_q;/* SCSI host work queue */
+   struct work_struct main_task;   /* Work item for main loop */
+   int flags;  /* Board-specific quirks */
+   int dma_len;/* Requested length of DMA */
+   int read_overruns;  /* Transfer size reduction for DMA erratum */
+   struct list_head unissued;  /* Waiting to be issued */
+   struct scsi_cmnd *selecting;/* Cmnd to be connected */
+   struct list_head autosense; /* Priority cmnd queue */
+   struct scsi_cmnd *sensing;  /* Cmnd needing autosense */
+   struct scsi_eh_save ses;/* Cmnd state saved for EH */
+   unsigned char busy[8];  /* Index = target, bit = lun */
+   unsigned char id_mask;  /* 1 << Host ID */
+   unsigned char id_higher_mask;   /* All bits above id_mask */
+   unsigned char last_message; /* Last Message Out */
char info[256];
-   int read_overruns;/* number of bytes to cut from a
-  * transfer to handle chip overruns */
-   struct work_struct main_task;
-   struct workqueue_struct *work_q;
-   unsigned long poll_loops;   /* register polling limit */
 };
 
 #ifdef __KERNEL__
-- 
2.7.3



[PATCH v3 06/12] scsi/ncr5380: Improve hostdata struct member alignment and cache-ability

2016-10-09 Thread Finn Thain
Re-order struct members so that hot data lies at the beginning of the
struct and cold data at the end. Improve the comments while we're here.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.h | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index f0eea44..ceafa0c 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -219,27 +219,27 @@
 #define FLAG_TOSHIBA_DELAY 128 /* Allow for borken CD-ROMs */
 
 struct NCR5380_hostdata {
-   NCR5380_implementation_fields;  /* implementation specific */
-   struct Scsi_Host *host; /* Host backpointer */
-   unsigned char id_mask, id_higher_mask;  /* 1 << id, all bits greater */
-   unsigned char busy[8];  /* index = target, bit = lun */
-   int dma_len;/* requested length of DMA */
-   unsigned char last_message; /* last message OUT */
-   struct scsi_cmnd *connected;/* currently connected cmnd */
-   struct scsi_cmnd *selecting;/* cmnd to be connected */
-   struct list_head unissued;  /* waiting to be issued */
-   struct list_head autosense; /* priority issue queue */
-   struct list_head disconnected;  /* waiting for reconnect */
-   spinlock_t lock;/* protects this struct */
-   int flags;
-   struct scsi_eh_save ses;
-   struct scsi_cmnd *sensing;
+   NCR5380_implementation_fields;  /* Board-specific data */
+   unsigned long poll_loops;   /* Register polling limit */
+   spinlock_t lock;/* Protects this struct */
+   struct scsi_cmnd *connected;/* Currently connected cmnd */
+   struct list_head disconnected;  /* Waiting for reconnect */
+   struct Scsi_Host *host; /* SCSI host backpointer */
+   struct workqueue_struct *work_q;/* SCSI host work queue */
+   struct work_struct main_task;   /* Work item for main loop */
+   int flags;  /* Board-specific quirks */
+   int dma_len;/* Requested length of DMA */
+   int read_overruns;  /* Transfer size reduction for DMA erratum */
+   struct list_head unissued;  /* Waiting to be issued */
+   struct scsi_cmnd *selecting;/* Cmnd to be connected */
+   struct list_head autosense; /* Priority cmnd queue */
+   struct scsi_cmnd *sensing;  /* Cmnd needing autosense */
+   struct scsi_eh_save ses;/* Cmnd state saved for EH */
+   unsigned char busy[8];  /* Index = target, bit = lun */
+   unsigned char id_mask;  /* 1 << Host ID */
+   unsigned char id_higher_mask;   /* All bits above id_mask */
+   unsigned char last_message; /* Last Message Out */
char info[256];
-   int read_overruns;/* number of bytes to cut from a
-  * transfer to handle chip overruns */
-   struct work_struct main_task;
-   struct workqueue_struct *work_q;
-   unsigned long poll_loops;   /* register polling limit */
 };
 
 #ifdef __KERNEL__
-- 
2.7.3



[PATCH v3 09/12] scsi/ncr5380: Pass hostdata pointer to register polling routines

2016-10-09 Thread Finn Thain
Pass a NCR5380_hostdata struct pointer to the board-specific routines
instead of a Scsi_Host struct pointer. This reduces pointer chasing in
the PIO and PDMA fast paths. The old way was a mistake because it is
slow and the board-specific code is not concerned with the mid-layer.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c  | 33 -
 drivers/scsi/NCR5380.h  |  6 +++---
 drivers/scsi/mac_scsi.c | 10 +-
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index eb40561..3f2bfd2 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -178,7 +178,7 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
 
 /**
  * NCR5380_poll_politely2 - wait for two chip register values
- * @instance: controller to poll
+ * @hostdata: host private data
  * @reg1: 5380 register to poll
  * @bit1: Bitmask to check
  * @val1: Expected value
@@ -195,12 +195,11 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
  * Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT.
  */
 
-static int NCR5380_poll_politely2(struct Scsi_Host *instance,
+static int NCR5380_poll_politely2(struct NCR5380_hostdata *hostdata,
   unsigned int reg1, u8 bit1, u8 val1,
   unsigned int reg2, u8 bit2, u8 val2,
   unsigned long wait)
 {
-   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned long n = hostdata->poll_loops;
unsigned long deadline = jiffies + wait;
 
@@ -561,7 +560,7 @@ static int NCR5380_maybe_reset_bus(struct Scsi_Host 
*instance)
case 3:
case 5:
shost_printk(KERN_ERR, instance, "SCSI bus busy, 
waiting up to five seconds\n");
-   NCR5380_poll_politely(instance,
+   NCR5380_poll_politely(hostdata,
  STATUS_REG, SR_BSY, 0, 5 * HZ);
break;
case 2:
@@ -1076,7 +1075,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host 
*instance,
 */
 
spin_unlock_irq(>lock);
-   err = NCR5380_poll_politely2(instance, MODE_REG, MR_ARBITRATE, 0,
+   err = NCR5380_poll_politely2(hostdata, MODE_REG, MR_ARBITRATE, 0,
INITIATOR_COMMAND_REG, ICR_ARBITRATION_PROGRESS,
   ICR_ARBITRATION_PROGRESS, HZ);
spin_lock_irq(>lock);
@@ -1202,7 +1201,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host 
*instance,
 * selection.
 */
 
-   err = NCR5380_poll_politely(instance, STATUS_REG, SR_BSY, SR_BSY,
+   err = NCR5380_poll_politely(hostdata, STATUS_REG, SR_BSY, SR_BSY,
msecs_to_jiffies(250));
 
if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) {
@@ -1248,7 +1247,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host 
*instance,
 
/* Wait for start of REQ/ACK handshake */
 
-   err = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ);
+   err = NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, HZ);
spin_lock_irq(>lock);
if (err < 0) {
shost_printk(KERN_ERR, instance, "select: REQ timeout\n");
@@ -1338,7 +1337,7 @@ static int NCR5380_transfer_pio(struct Scsi_Host 
*instance,
 * valid
 */
 
-   if (NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, 
HZ) < 0)
+   if (NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, 
HZ) < 0)
break;
 
dsprintk(NDEBUG_HANDSHAKE, instance, "REQ asserted\n");
@@ -1383,7 +1382,7 @@ static int NCR5380_transfer_pio(struct Scsi_Host 
*instance,
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | 
ICR_ASSERT_ACK);
}
 
-   if (NCR5380_poll_politely(instance,
+   if (NCR5380_poll_politely(hostdata,
  STATUS_REG, SR_REQ, 0, 5 * HZ) < 0)
break;
 
@@ -1483,7 +1482,7 @@ static int do_abort(struct Scsi_Host *instance)
 * the target sees, so we just handshake.
 */
 
-   rc = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, 10 * 
HZ);
+   rc = NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, 10 * 
HZ);
if (rc < 0)
goto timeout;
 
@@ -1494,7 +1493,7 @@ static int do_abort(struct Scsi_Host *instance)
if (tmp != PHASE_MSGOUT) {
NCR5380_write(INITIATOR_COMMAND_REG,
  ICR_BASE | ICR_ASSERT_ATN | ICR_ASSERT_ACK);

[PATCH v3 09/12] scsi/ncr5380: Pass hostdata pointer to register polling routines

2016-10-09 Thread Finn Thain
Pass a NCR5380_hostdata struct pointer to the board-specific routines
instead of a Scsi_Host struct pointer. This reduces pointer chasing in
the PIO and PDMA fast paths. The old way was a mistake because it is
slow and the board-specific code is not concerned with the mid-layer.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c  | 33 -
 drivers/scsi/NCR5380.h  |  6 +++---
 drivers/scsi/mac_scsi.c | 10 +-
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index eb40561..3f2bfd2 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -178,7 +178,7 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
 
 /**
  * NCR5380_poll_politely2 - wait for two chip register values
- * @instance: controller to poll
+ * @hostdata: host private data
  * @reg1: 5380 register to poll
  * @bit1: Bitmask to check
  * @val1: Expected value
@@ -195,12 +195,11 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
  * Returns 0 if either or both event(s) occurred otherwise -ETIMEDOUT.
  */
 
-static int NCR5380_poll_politely2(struct Scsi_Host *instance,
+static int NCR5380_poll_politely2(struct NCR5380_hostdata *hostdata,
   unsigned int reg1, u8 bit1, u8 val1,
   unsigned int reg2, u8 bit2, u8 val2,
   unsigned long wait)
 {
-   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned long n = hostdata->poll_loops;
unsigned long deadline = jiffies + wait;
 
@@ -561,7 +560,7 @@ static int NCR5380_maybe_reset_bus(struct Scsi_Host 
*instance)
case 3:
case 5:
shost_printk(KERN_ERR, instance, "SCSI bus busy, 
waiting up to five seconds\n");
-   NCR5380_poll_politely(instance,
+   NCR5380_poll_politely(hostdata,
  STATUS_REG, SR_BSY, 0, 5 * HZ);
break;
case 2:
@@ -1076,7 +1075,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host 
*instance,
 */
 
spin_unlock_irq(>lock);
-   err = NCR5380_poll_politely2(instance, MODE_REG, MR_ARBITRATE, 0,
+   err = NCR5380_poll_politely2(hostdata, MODE_REG, MR_ARBITRATE, 0,
INITIATOR_COMMAND_REG, ICR_ARBITRATION_PROGRESS,
   ICR_ARBITRATION_PROGRESS, HZ);
spin_lock_irq(>lock);
@@ -1202,7 +1201,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host 
*instance,
 * selection.
 */
 
-   err = NCR5380_poll_politely(instance, STATUS_REG, SR_BSY, SR_BSY,
+   err = NCR5380_poll_politely(hostdata, STATUS_REG, SR_BSY, SR_BSY,
msecs_to_jiffies(250));
 
if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) {
@@ -1248,7 +1247,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host 
*instance,
 
/* Wait for start of REQ/ACK handshake */
 
-   err = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, HZ);
+   err = NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, HZ);
spin_lock_irq(>lock);
if (err < 0) {
shost_printk(KERN_ERR, instance, "select: REQ timeout\n");
@@ -1338,7 +1337,7 @@ static int NCR5380_transfer_pio(struct Scsi_Host 
*instance,
 * valid
 */
 
-   if (NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, 
HZ) < 0)
+   if (NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, 
HZ) < 0)
break;
 
dsprintk(NDEBUG_HANDSHAKE, instance, "REQ asserted\n");
@@ -1383,7 +1382,7 @@ static int NCR5380_transfer_pio(struct Scsi_Host 
*instance,
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | 
ICR_ASSERT_ACK);
}
 
-   if (NCR5380_poll_politely(instance,
+   if (NCR5380_poll_politely(hostdata,
  STATUS_REG, SR_REQ, 0, 5 * HZ) < 0)
break;
 
@@ -1483,7 +1482,7 @@ static int do_abort(struct Scsi_Host *instance)
 * the target sees, so we just handshake.
 */
 
-   rc = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, SR_REQ, 10 * 
HZ);
+   rc = NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, 10 * 
HZ);
if (rc < 0)
goto timeout;
 
@@ -1494,7 +1493,7 @@ static int do_abort(struct Scsi_Host *instance)
if (tmp != PHASE_MSGOUT) {
NCR5380_write(INITIATOR_COMMAND_REG,
  ICR_BASE | ICR_ASSERT_ATN | ICR_ASSERT_ACK);
-   rc = NCR5380_poll_politely(instance, STATUS_REG, SR_REQ, 0, 3 * 
HZ);
+   

[PATCH v3 11/12] scsi/ncr5380: Use correct types for DMA routines

2016-10-09 Thread Finn Thain
Apply prototypes to get consistent function signatures for the DMA
functions implemented in the board-specific drivers. To avoid using
macros to alter actual parameters, some of those functions are reworked
slightly.

This is a step toward the goal of passing the board-specific routines
to the core driver using an ops struct (as in a platform driver or
library module).

This also helps fix some inconsistent types: where the core driver uses
ints (cmd->SCp.this_residual and hostdata->dma_len) for keeping track of
transfers, certain board-specific routines used unsigned long.

While we are fixing these function signatures, pass the hostdata pointer
to DMA routines instead of a Scsi_Host pointer, for shorter and faster
code.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c  | 74 +
 drivers/scsi/NCR5380.h  | 25 +++
 drivers/scsi/arm/cumana_1.c | 26 ++--
 drivers/scsi/arm/oak.c  | 13 
 drivers/scsi/atari_scsi.c   | 45 +++
 drivers/scsi/dmx3191d.c |  8 ++---
 drivers/scsi/g_NCR5380.c| 13 +++-
 drivers/scsi/g_NCR5380.h|  5 ++-
 drivers/scsi/mac_scsi.c | 36 +++---
 drivers/scsi/sun3_scsi.c| 45 +++
 10 files changed, 176 insertions(+), 114 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 3f2bfd2..72ac31cd 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -121,9 +121,10 @@
  *
  * Either real DMA *or* pseudo DMA may be implemented
  *
- * NCR5380_dma_write_setup(instance, src, count) - initialize
- * NCR5380_dma_read_setup(instance, dst, count) - initialize
- * NCR5380_dma_residual(instance); - residual count
+ * NCR5380_dma_xfer_len   - determine size of DMA/PDMA transfer
+ * NCR5380_dma_send_setup - execute DMA/PDMA from memory to 5380
+ * NCR5380_dma_recv_setup - execute DMA/PDMA from 5380 to memory
+ * NCR5380_dma_residual   - residual byte count
  *
  * The generic driver is initialized by calling NCR5380_init(instance),
  * after setting the appropriate host specific fields and ID.  If the
@@ -871,7 +872,7 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
NCR5380_read(RESET_PARITY_INTERRUPT_REG);
 
-   transferred = hostdata->dma_len - NCR5380_dma_residual(instance);
+   transferred = hostdata->dma_len - NCR5380_dma_residual(hostdata);
hostdata->dma_len = 0;
 
data = (unsigned char **)>connected->SCp.ptr;
@@ -1578,9 +1579,9 @@ static int NCR5380_transfer_dma(struct Scsi_Host 
*instance,
 * starting the NCR. This is also the cleaner way for the TT.
 */
if (p & SR_IO)
-   result = NCR5380_dma_recv_setup(instance, d, c);
+   result = NCR5380_dma_recv_setup(hostdata, d, c);
else
-   result = NCR5380_dma_send_setup(instance, d, c);
+   result = NCR5380_dma_send_setup(hostdata, d, c);
}
 
/*
@@ -1612,9 +1613,9 @@ static int NCR5380_transfer_dma(struct Scsi_Host 
*instance,
 * NCR access, else the DMA setup gets trashed!
 */
if (p & SR_IO)
-   result = NCR5380_dma_recv_setup(instance, d, c);
+   result = NCR5380_dma_recv_setup(hostdata, d, c);
else
-   result = NCR5380_dma_send_setup(instance, d, c);
+   result = NCR5380_dma_send_setup(hostdata, d, c);
}
 
/* On failure, NCR5380_dma__setup() returns a negative int. */
@@ -1754,22 +1755,26 @@ static void NCR5380_information_transfer(struct 
Scsi_Host *instance)
NCR5380_dprint_phase(NDEBUG_INFORMATION, 
instance);
}
 #ifdef CONFIG_SUN3
-   if (phase == PHASE_CMDOUT) {
-   void *d;
-   unsigned long count;
+   if (phase == PHASE_CMDOUT &&
+   sun3_dma_setup_done != cmd) {
+   int count;
 
if (!cmd->SCp.this_residual && 
cmd->SCp.buffers_residual) {
-   count = cmd->SCp.buffer->length;
-   d = sg_virt(cmd->SCp.buffer);
-   } else {
-   count = cmd->SCp.this_residual;
-   d = cmd->SCp.ptr;
+   ++cmd->SCp.buffer;
+   --cmd->SCp.buffers_residual;
+  

[PATCH v3 12/12] scsi/ncr5380: Suppress unhelpful "interrupt without IRQ bit" message

2016-10-09 Thread Finn Thain
If a NCR5380 host instance ends up on a shared interrupt line then
this printk will be a problem. It is already a problem on some Mac
models: when testing mac_scsi on a PowerBook 180 I found that PDMA
transfers (but not PIO transfers) cause the message to be logged.

These spurious interrupts don't appear to come from the DRQ signal from
the 5380. And they don't happen at all on the Mac LC III. A comment in
the NetBSD source code mentions this mystery. Testing seems to show
that we can safely ignore these interrupts.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 72ac31cd..0c3c7e6 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -995,7 +995,7 @@ static irqreturn_t __maybe_unused NCR5380_intr(int irq, 
void *dev_id)
}
handled = 1;
} else {
-   shost_printk(KERN_NOTICE, instance, "interrupt without IRQ 
bit\n");
+   dsprintk(NDEBUG_INTR, instance, "interrupt without IRQ bit\n");
 #ifdef SUN3_SCSI_VME
dregs->csr |= CSR_DMA_ENABLE;
 #endif
-- 
2.7.3



[PATCH v3 11/12] scsi/ncr5380: Use correct types for DMA routines

2016-10-09 Thread Finn Thain
Apply prototypes to get consistent function signatures for the DMA
functions implemented in the board-specific drivers. To avoid using
macros to alter actual parameters, some of those functions are reworked
slightly.

This is a step toward the goal of passing the board-specific routines
to the core driver using an ops struct (as in a platform driver or
library module).

This also helps fix some inconsistent types: where the core driver uses
ints (cmd->SCp.this_residual and hostdata->dma_len) for keeping track of
transfers, certain board-specific routines used unsigned long.

While we are fixing these function signatures, pass the hostdata pointer
to DMA routines instead of a Scsi_Host pointer, for shorter and faster
code.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c  | 74 +
 drivers/scsi/NCR5380.h  | 25 +++
 drivers/scsi/arm/cumana_1.c | 26 ++--
 drivers/scsi/arm/oak.c  | 13 
 drivers/scsi/atari_scsi.c   | 45 +++
 drivers/scsi/dmx3191d.c |  8 ++---
 drivers/scsi/g_NCR5380.c| 13 +++-
 drivers/scsi/g_NCR5380.h|  5 ++-
 drivers/scsi/mac_scsi.c | 36 +++---
 drivers/scsi/sun3_scsi.c| 45 +++
 10 files changed, 176 insertions(+), 114 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 3f2bfd2..72ac31cd 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -121,9 +121,10 @@
  *
  * Either real DMA *or* pseudo DMA may be implemented
  *
- * NCR5380_dma_write_setup(instance, src, count) - initialize
- * NCR5380_dma_read_setup(instance, dst, count) - initialize
- * NCR5380_dma_residual(instance); - residual count
+ * NCR5380_dma_xfer_len   - determine size of DMA/PDMA transfer
+ * NCR5380_dma_send_setup - execute DMA/PDMA from memory to 5380
+ * NCR5380_dma_recv_setup - execute DMA/PDMA from 5380 to memory
+ * NCR5380_dma_residual   - residual byte count
  *
  * The generic driver is initialized by calling NCR5380_init(instance),
  * after setting the appropriate host specific fields and ID.  If the
@@ -871,7 +872,7 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
NCR5380_read(RESET_PARITY_INTERRUPT_REG);
 
-   transferred = hostdata->dma_len - NCR5380_dma_residual(instance);
+   transferred = hostdata->dma_len - NCR5380_dma_residual(hostdata);
hostdata->dma_len = 0;
 
data = (unsigned char **)>connected->SCp.ptr;
@@ -1578,9 +1579,9 @@ static int NCR5380_transfer_dma(struct Scsi_Host 
*instance,
 * starting the NCR. This is also the cleaner way for the TT.
 */
if (p & SR_IO)
-   result = NCR5380_dma_recv_setup(instance, d, c);
+   result = NCR5380_dma_recv_setup(hostdata, d, c);
else
-   result = NCR5380_dma_send_setup(instance, d, c);
+   result = NCR5380_dma_send_setup(hostdata, d, c);
}
 
/*
@@ -1612,9 +1613,9 @@ static int NCR5380_transfer_dma(struct Scsi_Host 
*instance,
 * NCR access, else the DMA setup gets trashed!
 */
if (p & SR_IO)
-   result = NCR5380_dma_recv_setup(instance, d, c);
+   result = NCR5380_dma_recv_setup(hostdata, d, c);
else
-   result = NCR5380_dma_send_setup(instance, d, c);
+   result = NCR5380_dma_send_setup(hostdata, d, c);
}
 
/* On failure, NCR5380_dma__setup() returns a negative int. */
@@ -1754,22 +1755,26 @@ static void NCR5380_information_transfer(struct 
Scsi_Host *instance)
NCR5380_dprint_phase(NDEBUG_INFORMATION, 
instance);
}
 #ifdef CONFIG_SUN3
-   if (phase == PHASE_CMDOUT) {
-   void *d;
-   unsigned long count;
+   if (phase == PHASE_CMDOUT &&
+   sun3_dma_setup_done != cmd) {
+   int count;
 
if (!cmd->SCp.this_residual && 
cmd->SCp.buffers_residual) {
-   count = cmd->SCp.buffer->length;
-   d = sg_virt(cmd->SCp.buffer);
-   } else {
-   count = cmd->SCp.this_residual;
-   d = cmd->SCp.ptr;
+   ++cmd->SCp.buffer;
+   --cmd->SCp.buffers_residual;
+   cmd->SCp.this_residual = 
cmd->SCp.buffer->length;
+   

[PATCH v3 12/12] scsi/ncr5380: Suppress unhelpful "interrupt without IRQ bit" message

2016-10-09 Thread Finn Thain
If a NCR5380 host instance ends up on a shared interrupt line then
this printk will be a problem. It is already a problem on some Mac
models: when testing mac_scsi on a PowerBook 180 I found that PDMA
transfers (but not PIO transfers) cause the message to be logged.

These spurious interrupts don't appear to come from the DRQ signal from
the 5380. And they don't happen at all on the Mac LC III. A comment in
the NetBSD source code mentions this mystery. Testing seems to show
that we can safely ignore these interrupts.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 72ac31cd..0c3c7e6 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -995,7 +995,7 @@ static irqreturn_t __maybe_unused NCR5380_intr(int irq, 
void *dev_id)
}
handled = 1;
} else {
-   shost_printk(KERN_NOTICE, instance, "interrupt without IRQ 
bit\n");
+   dsprintk(NDEBUG_INTR, instance, "interrupt without IRQ bit\n");
 #ifdef SUN3_SCSI_VME
dregs->csr |= CSR_DMA_ENABLE;
 #endif
-- 
2.7.3



[PATCH v3 05/12] scsi/ncr5380: Increase register polling limit

2016-10-09 Thread Finn Thain
If NCR5380_poll_politely() is called under irq lock, the polling time
limit is clamped to avoid a spike in interrupt latency. When not under
irq lock, the same polling time limit acts as the worst case delay
between schedule() calls.

During PDMA (under irq lock) I've found that the 10 ms time limit is
sometimes too short, and leads to the error message,
sd 0:0:0:0: [sda] tag#1 macscsi_pread: !REQ and !ACK

This particular target identifies itself as a QUANTUM DAYTONA514S. It
seems to be slower to assert ACK than the other targets I've tested.
This patch solves the problem by increasing the polling timeout.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
When irqs are disabled, this change will make no difference unless the
driver or target happens to suffer from timeout errors. In the irqs
enabled case, this patch may delay the next call to schedule() by an
additional 5 ms (in all 5380 drivers). Normally that would only happen
for a target selection timeout during a SCSI bus scan, which should not
bother anyone too much.
---
 drivers/scsi/NCR5380.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index cbb29d6..f0eea44 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -253,7 +253,7 @@ struct NCR5380_cmd {
 #define NCR5380_PIO_CHUNK_SIZE 256
 
 /* Time limit (ms) to poll registers when IRQs are disabled, e.g. during PDMA 
*/
-#define NCR5380_REG_POLL_TIME  10
+#define NCR5380_REG_POLL_TIME  15
 
 static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr)
 {
-- 
2.7.3



[PATCH v3 07/12] scsi/ncr5380: Store IO ports and addresses in host private data

2016-10-09 Thread Finn Thain
The various 5380 drivers inconsistently store register pointers
either in the Scsi_Host struct "legacy crap" area or in special,
board-specific members of the NCR5380_hostdata struct. Uniform
use of the latter struct makes for simpler and faster code (see
the following patches) and helps to reduce use of the
NCR5380_implementation_fields macro.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c  |  8 +++---
 drivers/scsi/NCR5380.h  |  5 
 drivers/scsi/arm/cumana_1.c | 60 
 drivers/scsi/arm/oak.c  | 23 
 drivers/scsi/dmx3191d.c | 14 +++---
 drivers/scsi/g_NCR5380.c| 67 +++--
 drivers/scsi/g_NCR5380.h|  6 ++--
 drivers/scsi/mac_scsi.c | 27 ++
 drivers/scsi/sun3_scsi.c|  5 +++-
 9 files changed, 118 insertions(+), 97 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 25ee5be..82fd37d 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -437,14 +437,14 @@ static void prepare_info(struct Scsi_Host *instance)
struct NCR5380_hostdata *hostdata = shost_priv(instance);
 
snprintf(hostdata->info, sizeof(hostdata->info),
-"%s, io_port 0x%lx, n_io_port %d, "
-"base 0x%lx, irq %d, "
+"%s, irq %d, "
+"io_port 0x%lx, base 0x%lx, "
 "can_queue %d, cmd_per_lun %d, "
 "sg_tablesize %d, this_id %d, "
 "flags { %s%s%s}, "
 "options { %s} ",
-instance->hostt->name, instance->io_port, instance->n_io_port,
-instance->base, instance->irq,
+instance->hostt->name, instance->irq,
+hostdata->io_port, hostdata->base,
 instance->can_queue, instance->cmd_per_lun,
 instance->sg_tablesize, instance->this_id,
 hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "",
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index ceafa0c..02f20ff 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -220,6 +220,8 @@
 
 struct NCR5380_hostdata {
NCR5380_implementation_fields;  /* Board-specific data */
+   u8 __iomem *io; /* Remapped 5380 address */
+   u8 __iomem *pdma_io;/* Remapped PDMA address */
unsigned long poll_loops;   /* Register polling limit */
spinlock_t lock;/* Protects this struct */
struct scsi_cmnd *connected;/* Currently connected cmnd */
@@ -230,6 +232,8 @@ struct NCR5380_hostdata {
int flags;  /* Board-specific quirks */
int dma_len;/* Requested length of DMA */
int read_overruns;  /* Transfer size reduction for DMA erratum */
+   unsigned long io_port;  /* Device IO port */
+   unsigned long base; /* Device base address */
struct list_head unissued;  /* Waiting to be issued */
struct scsi_cmnd *selecting;/* Cmnd to be connected */
struct list_head autosense; /* Priority cmnd queue */
@@ -239,6 +243,7 @@ struct NCR5380_hostdata {
unsigned char id_mask;  /* 1 << Host ID */
unsigned char id_higher_mask;   /* All bits above id_mask */
unsigned char last_message; /* Last Message Out */
+   unsigned long region_size;  /* Size of address/port range */
char info[256];
 };
 
diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index f616756..88db281 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -27,9 +27,7 @@
 #define NCR5380_info   cumanascsi_info
 
 #define NCR5380_implementation_fields  \
-   unsigned ctrl;  \
-   void __iomem *base; \
-   void __iomem *dma
+   unsigned ctrl
 
 #include "../NCR5380.h"
 
@@ -42,17 +40,18 @@ static inline int cumanascsi_pwrite(struct Scsi_Host *host,
 unsigned char *addr, int len)
 {
   unsigned long *laddr;
-  void __iomem *dma = priv(host)->dma + 0x2000;
+  u8 __iomem *base = priv(host)->io;
+  u8 __iomem *dma = priv(host)->pdma_io + 0x2000;
 
   if(!len) return 0;
 
-  writeb(0x02, priv(host)->base + CTRL);
+  writeb(0x02, base + CTRL);
   laddr = (unsigned long *)addr;
   while(len >= 32)
   {
 unsigned int status;
 unsigned long v;
-status = readb(priv(host)->base + STAT);
+status = readb(base + STAT);
 if(status & 0x80)
   goto end;
 if(!(status & 0x40))
@@ -71,12 +70,12 

[PATCH v3 04/12] scsi/ncr5380: Simplify register polling limit

2016-10-09 Thread Finn Thain
When polling a device register under irq lock the polling loop terminates
after a given number of jiffies. Make this timeout independent of the HZ
setting.

All 5380 drivers benefit from this patch, which optimizes the PIO fast
path, because they all use PIO transfers (for phases other than DATA IN
and DATA OUT). Some cards support only PIO transfers (even for DATA
phases). CPU cycles are scarce on some of these systems, so a small
improvement here makes a big difference.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
This patch eliminates a call to jiffies_to_usecs from the fast path.
For g_NCR5380 it also eliminates a mul instruction and an imul instruction.
For ARM drivers like oak, this change eliminates an __aeabi_uidiv call.
---
 drivers/scsi/NCR5380.c | 10 --
 drivers/scsi/NCR5380.h |  5 -
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index db27390..25ee5be 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -200,13 +200,9 @@ static int NCR5380_poll_politely2(struct Scsi_Host 
*instance,
   int reg2, int bit2, int val2, int wait)
 {
struct NCR5380_hostdata *hostdata = shost_priv(instance);
+   unsigned long n = hostdata->poll_loops;
unsigned long deadline = jiffies + wait;
-   unsigned long n;
 
-   /* Busy-wait for up to 10 ms */
-   n = min(1U, jiffies_to_usecs(wait));
-   n *= hostdata->accesses_per_ms;
-   n /= 2000;
do {
if ((NCR5380_read(reg1) & bit1) == val1)
return 0;
@@ -482,6 +478,7 @@ static int NCR5380_init(struct Scsi_Host *instance, int 
flags)
struct NCR5380_hostdata *hostdata = shost_priv(instance);
int i;
unsigned long deadline;
+   unsigned long accesses_per_ms;
 
instance->max_lun = 7;
 
@@ -530,7 +527,8 @@ static int NCR5380_init(struct Scsi_Host *instance, int 
flags)
++i;
cpu_relax();
} while (time_is_after_jiffies(deadline));
-   hostdata->accesses_per_ms = i / 256;
+   accesses_per_ms = i / 256;
+   hostdata->poll_loops = NCR5380_REG_POLL_TIME * accesses_per_ms / 2;
 
return 0;
 }
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index 965d923..cbb29d6 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -239,7 +239,7 @@ struct NCR5380_hostdata {
   * transfer to handle chip overruns */
struct work_struct main_task;
struct workqueue_struct *work_q;
-   unsigned long accesses_per_ms;  /* chip register accesses per ms */
+   unsigned long poll_loops;   /* register polling limit */
 };
 
 #ifdef __KERNEL__
@@ -252,6 +252,9 @@ struct NCR5380_cmd {
 
 #define NCR5380_PIO_CHUNK_SIZE 256
 
+/* Time limit (ms) to poll registers when IRQs are disabled, e.g. during PDMA 
*/
+#define NCR5380_REG_POLL_TIME  10
+
 static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr)
 {
return ((struct scsi_cmnd *)ncmd_ptr) - 1;
-- 
2.7.3



[PATCH v3 05/12] scsi/ncr5380: Increase register polling limit

2016-10-09 Thread Finn Thain
If NCR5380_poll_politely() is called under irq lock, the polling time
limit is clamped to avoid a spike in interrupt latency. When not under
irq lock, the same polling time limit acts as the worst case delay
between schedule() calls.

During PDMA (under irq lock) I've found that the 10 ms time limit is
sometimes too short, and leads to the error message,
sd 0:0:0:0: [sda] tag#1 macscsi_pread: !REQ and !ACK

This particular target identifies itself as a QUANTUM DAYTONA514S. It
seems to be slower to assert ACK than the other targets I've tested.
This patch solves the problem by increasing the polling timeout.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
When irqs are disabled, this change will make no difference unless the
driver or target happens to suffer from timeout errors. In the irqs
enabled case, this patch may delay the next call to schedule() by an
additional 5 ms (in all 5380 drivers). Normally that would only happen
for a target selection timeout during a SCSI bus scan, which should not
bother anyone too much.
---
 drivers/scsi/NCR5380.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index cbb29d6..f0eea44 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -253,7 +253,7 @@ struct NCR5380_cmd {
 #define NCR5380_PIO_CHUNK_SIZE 256
 
 /* Time limit (ms) to poll registers when IRQs are disabled, e.g. during PDMA 
*/
-#define NCR5380_REG_POLL_TIME  10
+#define NCR5380_REG_POLL_TIME  15
 
 static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr)
 {
-- 
2.7.3



[PATCH v3 07/12] scsi/ncr5380: Store IO ports and addresses in host private data

2016-10-09 Thread Finn Thain
The various 5380 drivers inconsistently store register pointers
either in the Scsi_Host struct "legacy crap" area or in special,
board-specific members of the NCR5380_hostdata struct. Uniform
use of the latter struct makes for simpler and faster code (see
the following patches) and helps to reduce use of the
NCR5380_implementation_fields macro.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c  |  8 +++---
 drivers/scsi/NCR5380.h  |  5 
 drivers/scsi/arm/cumana_1.c | 60 
 drivers/scsi/arm/oak.c  | 23 
 drivers/scsi/dmx3191d.c | 14 +++---
 drivers/scsi/g_NCR5380.c| 67 +++--
 drivers/scsi/g_NCR5380.h|  6 ++--
 drivers/scsi/mac_scsi.c | 27 ++
 drivers/scsi/sun3_scsi.c|  5 +++-
 9 files changed, 118 insertions(+), 97 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 25ee5be..82fd37d 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -437,14 +437,14 @@ static void prepare_info(struct Scsi_Host *instance)
struct NCR5380_hostdata *hostdata = shost_priv(instance);
 
snprintf(hostdata->info, sizeof(hostdata->info),
-"%s, io_port 0x%lx, n_io_port %d, "
-"base 0x%lx, irq %d, "
+"%s, irq %d, "
+"io_port 0x%lx, base 0x%lx, "
 "can_queue %d, cmd_per_lun %d, "
 "sg_tablesize %d, this_id %d, "
 "flags { %s%s%s}, "
 "options { %s} ",
-instance->hostt->name, instance->io_port, instance->n_io_port,
-instance->base, instance->irq,
+instance->hostt->name, instance->irq,
+hostdata->io_port, hostdata->base,
 instance->can_queue, instance->cmd_per_lun,
 instance->sg_tablesize, instance->this_id,
 hostdata->flags & FLAG_DMA_FIXUP ? "DMA_FIXUP " : "",
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index ceafa0c..02f20ff 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -220,6 +220,8 @@
 
 struct NCR5380_hostdata {
NCR5380_implementation_fields;  /* Board-specific data */
+   u8 __iomem *io; /* Remapped 5380 address */
+   u8 __iomem *pdma_io;/* Remapped PDMA address */
unsigned long poll_loops;   /* Register polling limit */
spinlock_t lock;/* Protects this struct */
struct scsi_cmnd *connected;/* Currently connected cmnd */
@@ -230,6 +232,8 @@ struct NCR5380_hostdata {
int flags;  /* Board-specific quirks */
int dma_len;/* Requested length of DMA */
int read_overruns;  /* Transfer size reduction for DMA erratum */
+   unsigned long io_port;  /* Device IO port */
+   unsigned long base; /* Device base address */
struct list_head unissued;  /* Waiting to be issued */
struct scsi_cmnd *selecting;/* Cmnd to be connected */
struct list_head autosense; /* Priority cmnd queue */
@@ -239,6 +243,7 @@ struct NCR5380_hostdata {
unsigned char id_mask;  /* 1 << Host ID */
unsigned char id_higher_mask;   /* All bits above id_mask */
unsigned char last_message; /* Last Message Out */
+   unsigned long region_size;  /* Size of address/port range */
char info[256];
 };
 
diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index f616756..88db281 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -27,9 +27,7 @@
 #define NCR5380_info   cumanascsi_info
 
 #define NCR5380_implementation_fields  \
-   unsigned ctrl;  \
-   void __iomem *base; \
-   void __iomem *dma
+   unsigned ctrl
 
 #include "../NCR5380.h"
 
@@ -42,17 +40,18 @@ static inline int cumanascsi_pwrite(struct Scsi_Host *host,
 unsigned char *addr, int len)
 {
   unsigned long *laddr;
-  void __iomem *dma = priv(host)->dma + 0x2000;
+  u8 __iomem *base = priv(host)->io;
+  u8 __iomem *dma = priv(host)->pdma_io + 0x2000;
 
   if(!len) return 0;
 
-  writeb(0x02, priv(host)->base + CTRL);
+  writeb(0x02, base + CTRL);
   laddr = (unsigned long *)addr;
   while(len >= 32)
   {
 unsigned int status;
 unsigned long v;
-status = readb(priv(host)->base + STAT);
+status = readb(base + STAT);
 if(status & 0x80)
   goto end;
 if(!(status & 0x40))
@@ -71,12 +70,12 @@ static inline int cumanascsi_pwrite(struct Scsi_Host *host,
   }
 
   addr = (unsigned 

[PATCH v3 04/12] scsi/ncr5380: Simplify register polling limit

2016-10-09 Thread Finn Thain
When polling a device register under irq lock the polling loop terminates
after a given number of jiffies. Make this timeout independent of the HZ
setting.

All 5380 drivers benefit from this patch, which optimizes the PIO fast
path, because they all use PIO transfers (for phases other than DATA IN
and DATA OUT). Some cards support only PIO transfers (even for DATA
phases). CPU cycles are scarce on some of these systems, so a small
improvement here makes a big difference.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
This patch eliminates a call to jiffies_to_usecs from the fast path.
For g_NCR5380 it also eliminates a mul instruction and an imul instruction.
For ARM drivers like oak, this change eliminates an __aeabi_uidiv call.
---
 drivers/scsi/NCR5380.c | 10 --
 drivers/scsi/NCR5380.h |  5 -
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index db27390..25ee5be 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -200,13 +200,9 @@ static int NCR5380_poll_politely2(struct Scsi_Host 
*instance,
   int reg2, int bit2, int val2, int wait)
 {
struct NCR5380_hostdata *hostdata = shost_priv(instance);
+   unsigned long n = hostdata->poll_loops;
unsigned long deadline = jiffies + wait;
-   unsigned long n;
 
-   /* Busy-wait for up to 10 ms */
-   n = min(1U, jiffies_to_usecs(wait));
-   n *= hostdata->accesses_per_ms;
-   n /= 2000;
do {
if ((NCR5380_read(reg1) & bit1) == val1)
return 0;
@@ -482,6 +478,7 @@ static int NCR5380_init(struct Scsi_Host *instance, int 
flags)
struct NCR5380_hostdata *hostdata = shost_priv(instance);
int i;
unsigned long deadline;
+   unsigned long accesses_per_ms;
 
instance->max_lun = 7;
 
@@ -530,7 +527,8 @@ static int NCR5380_init(struct Scsi_Host *instance, int 
flags)
++i;
cpu_relax();
} while (time_is_after_jiffies(deadline));
-   hostdata->accesses_per_ms = i / 256;
+   accesses_per_ms = i / 256;
+   hostdata->poll_loops = NCR5380_REG_POLL_TIME * accesses_per_ms / 2;
 
return 0;
 }
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index 965d923..cbb29d6 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -239,7 +239,7 @@ struct NCR5380_hostdata {
   * transfer to handle chip overruns */
struct work_struct main_task;
struct workqueue_struct *work_q;
-   unsigned long accesses_per_ms;  /* chip register accesses per ms */
+   unsigned long poll_loops;   /* register polling limit */
 };
 
 #ifdef __KERNEL__
@@ -252,6 +252,9 @@ struct NCR5380_cmd {
 
 #define NCR5380_PIO_CHUNK_SIZE 256
 
+/* Time limit (ms) to poll registers when IRQs are disabled, e.g. during PDMA 
*/
+#define NCR5380_REG_POLL_TIME  10
+
 static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr)
 {
return ((struct scsi_cmnd *)ncmd_ptr) - 1;
-- 
2.7.3



[PATCH v3 00/12] Fixes, cleanup and g_NCR5380_mmio/g_NCR5380 merger

2016-10-09 Thread Finn Thain
This patch series has fixes for compatibility, reliability and
performance issues and some cleanup. It also includes a new version
of Ondrej Zary's patch that merges g_NCR5380_mmio into g_NCR5380.

I've tested this patch series using mac_scsi on a Powerbook 180.
Ondrej tested the g_NCR5380 driver and Michael tested atari_scsi.
The other drivers have been compile-tested.

Changes since v1:
- rebased on 4.9/scsi-queue
- added reviewed-by tags
- tweaked the order of struct members in patch 7/12

Changes since v2:
- added tested-by tags
- fixed typo in log message for patch 3/12


Finn Thain (12):
  scsi/g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio drivers
  scsi/cumana_1: Remove unused cumanascsi_setup() function
  scsi/atari_scsi: Make device register accessors re-entrant
  scsi/ncr5380: Simplify register polling limit
  scsi/ncr5380: Increase register polling limit
  scsi/ncr5380: Improve hostdata struct member alignment and
cache-ability
  scsi/ncr5380: Store IO ports and addresses in host private data
  scsi/ncr5380: Use correct types for device register accessors
  scsi/ncr5380: Pass hostdata pointer to register polling routines
  scsi/ncr5380: Expedite register polling
  scsi/ncr5380: Use correct types for DMA routines
  scsi/ncr5380: Suppress unhelpful "interrupt without IRQ bit" message

 MAINTAINERS   |   1 -
 drivers/scsi/Kconfig  |  32 +
 drivers/scsi/Makefile |   1 -
 drivers/scsi/NCR5380.c| 137 +++-
 drivers/scsi/NCR5380.h|  87 +
 drivers/scsi/arm/cumana_1.c   |  98 +++---
 drivers/scsi/arm/oak.c|  34 +++--
 drivers/scsi/atari_scsi.c |  77 ++-
 drivers/scsi/dmx3191d.c   |  20 +--
 drivers/scsi/g_NCR5380.c  | 290 --
 drivers/scsi/g_NCR5380.h  |  32 +
 drivers/scsi/g_NCR5380_mmio.c |  10 --
 drivers/scsi/mac_scsi.c   |  83 +---
 drivers/scsi/sun3_scsi.c  |  80 ++--
 14 files changed, 495 insertions(+), 487 deletions(-)
 delete mode 100644 drivers/scsi/g_NCR5380_mmio.c

-- 
2.7.3



[PATCH v3 08/12] scsi/ncr5380: Use correct types for device register accessors

2016-10-09 Thread Finn Thain
For timeout values adopt unsigned long, which is the type of jiffies etc.

For chip register values and bit masks pass u8, which is the return type
of readb, inb etc.

For device register offsets adopt unsigned int, as it is suitable for
adding to base addresses.

Pass the NCR5380_hostdata pointer to the board-specific routines instead
of the Scsi_Host pointer. The board-specific code is concerned with
hardware and not with SCSI protocol or the mid-layer.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c  | 10 --
 drivers/scsi/NCR5380.h  |  7 +--
 drivers/scsi/arm/cumana_1.c | 20 +++-
 drivers/scsi/arm/oak.c  |  6 ++
 drivers/scsi/atari_scsi.c   | 16 
 drivers/scsi/dmx3191d.c |  6 ++
 drivers/scsi/g_NCR5380.h|  8 ++--
 drivers/scsi/mac_scsi.c | 22 ++
 drivers/scsi/sun3_scsi.c| 32 +---
 9 files changed, 49 insertions(+), 78 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 82fd37d..eb40561 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -196,8 +196,9 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
  */
 
 static int NCR5380_poll_politely2(struct Scsi_Host *instance,
-  int reg1, int bit1, int val1,
-  int reg2, int bit2, int val2, int wait)
+  unsigned int reg1, u8 bit1, u8 val1,
+  unsigned int reg2, u8 bit2, u8 val2,
+  unsigned long wait)
 {
struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned long n = hostdata->poll_loops;
@@ -284,6 +285,7 @@ mrs[] = {
 
 static void NCR5380_print(struct Scsi_Host *instance)
 {
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char status, data, basr, mr, icr, i;
 
data = NCR5380_read(CURRENT_SCSI_DATA_REG);
@@ -333,6 +335,7 @@ static struct {
 
 static void NCR5380_print_phase(struct Scsi_Host *instance)
 {
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char status;
int i;
 
@@ -1316,6 +1319,7 @@ static int NCR5380_transfer_pio(struct Scsi_Host 
*instance,
unsigned char *phase, int *count,
unsigned char **data)
 {
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char p = *phase, tmp;
int c = *count;
unsigned char *d = *data;
@@ -1438,6 +1442,7 @@ static int NCR5380_transfer_pio(struct Scsi_Host 
*instance,
 
 static void do_reset(struct Scsi_Host *instance)
 {
+   struct NCR5380_hostdata __maybe_unused *hostdata = shost_priv(instance);
unsigned long flags;
 
local_irq_save(flags);
@@ -1460,6 +1465,7 @@ static void do_reset(struct Scsi_Host *instance)
 
 static int do_abort(struct Scsi_Host *instance)
 {
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char *msgptr, phase, tmp;
int len;
int rc;
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index 02f20ff..c2d8b78 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -302,10 +302,13 @@ static void NCR5380_reselect(struct Scsi_Host *instance);
 static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *, struct scsi_cmnd 
*);
 static int NCR5380_transfer_dma(struct Scsi_Host *instance, unsigned char 
*phase, int *count, unsigned char **data);
 static int NCR5380_transfer_pio(struct Scsi_Host *instance, unsigned char 
*phase, int *count, unsigned char **data);
-static int NCR5380_poll_politely2(struct Scsi_Host *, int, int, int, int, int, 
int, int);
+static int NCR5380_poll_politely2(struct Scsi_Host *,
+  unsigned int, u8, u8,
+  unsigned int, u8, u8, unsigned long);
 
 static inline int NCR5380_poll_politely(struct Scsi_Host *instance,
-   int reg, int bit, int val, int wait)
+unsigned int reg, u8 bit, u8 val,
+unsigned long wait)
 {
return NCR5380_poll_politely2(instance, reg, bit, val,
reg, bit, val, wait);
diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index 88db281..ae1d4c6 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -14,8 +14,8 @@
 #include 
 
 #define priv(host) ((struct NCR5380_hostdata 
*)(host)->hostdata)
-#define NCR5380_read(reg)  cumanascsi_read(instance, reg)
-#define NCR5380_write(reg, value)  cumanascsi_write(instance, reg, value)

[PATCH v3 02/12] scsi/cumana_1: Remove unused cumanascsi_setup() function

2016-10-09 Thread Finn Thain
Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
---
 drivers/scsi/arm/cumana_1.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index 8e9cfe8..f616756 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -33,10 +33,6 @@
 
 #include "../NCR5380.h"
 
-void cumanascsi_setup(char *str, int *ints)
-{
-}
-
 #define CTRL   0x16fc
 #define STAT   0x2004
 #define L(v)   (((v)<<16)|((v) & 0x))
-- 
2.7.3



[PATCH v3 00/12] Fixes, cleanup and g_NCR5380_mmio/g_NCR5380 merger

2016-10-09 Thread Finn Thain
This patch series has fixes for compatibility, reliability and
performance issues and some cleanup. It also includes a new version
of Ondrej Zary's patch that merges g_NCR5380_mmio into g_NCR5380.

I've tested this patch series using mac_scsi on a Powerbook 180.
Ondrej tested the g_NCR5380 driver and Michael tested atari_scsi.
The other drivers have been compile-tested.

Changes since v1:
- rebased on 4.9/scsi-queue
- added reviewed-by tags
- tweaked the order of struct members in patch 7/12

Changes since v2:
- added tested-by tags
- fixed typo in log message for patch 3/12


Finn Thain (12):
  scsi/g_NCR5380: Merge g_NCR5380 and g_NCR5380_mmio drivers
  scsi/cumana_1: Remove unused cumanascsi_setup() function
  scsi/atari_scsi: Make device register accessors re-entrant
  scsi/ncr5380: Simplify register polling limit
  scsi/ncr5380: Increase register polling limit
  scsi/ncr5380: Improve hostdata struct member alignment and
cache-ability
  scsi/ncr5380: Store IO ports and addresses in host private data
  scsi/ncr5380: Use correct types for device register accessors
  scsi/ncr5380: Pass hostdata pointer to register polling routines
  scsi/ncr5380: Expedite register polling
  scsi/ncr5380: Use correct types for DMA routines
  scsi/ncr5380: Suppress unhelpful "interrupt without IRQ bit" message

 MAINTAINERS   |   1 -
 drivers/scsi/Kconfig  |  32 +
 drivers/scsi/Makefile |   1 -
 drivers/scsi/NCR5380.c| 137 +++-
 drivers/scsi/NCR5380.h|  87 +
 drivers/scsi/arm/cumana_1.c   |  98 +++---
 drivers/scsi/arm/oak.c|  34 +++--
 drivers/scsi/atari_scsi.c |  77 ++-
 drivers/scsi/dmx3191d.c   |  20 +--
 drivers/scsi/g_NCR5380.c  | 290 --
 drivers/scsi/g_NCR5380.h  |  32 +
 drivers/scsi/g_NCR5380_mmio.c |  10 --
 drivers/scsi/mac_scsi.c   |  83 +---
 drivers/scsi/sun3_scsi.c  |  80 ++--
 14 files changed, 495 insertions(+), 487 deletions(-)
 delete mode 100644 drivers/scsi/g_NCR5380_mmio.c

-- 
2.7.3



[PATCH v3 08/12] scsi/ncr5380: Use correct types for device register accessors

2016-10-09 Thread Finn Thain
For timeout values adopt unsigned long, which is the type of jiffies etc.

For chip register values and bit masks pass u8, which is the return type
of readb, inb etc.

For device register offsets adopt unsigned int, as it is suitable for
adding to base addresses.

Pass the NCR5380_hostdata pointer to the board-specific routines instead
of the Scsi_Host pointer. The board-specific code is concerned with
hardware and not with SCSI protocol or the mid-layer.

Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
Tested-by: Ondrej Zary 
Tested-by: Michael Schmitz 
---
 drivers/scsi/NCR5380.c  | 10 --
 drivers/scsi/NCR5380.h  |  7 +--
 drivers/scsi/arm/cumana_1.c | 20 +++-
 drivers/scsi/arm/oak.c  |  6 ++
 drivers/scsi/atari_scsi.c   | 16 
 drivers/scsi/dmx3191d.c |  6 ++
 drivers/scsi/g_NCR5380.h|  8 ++--
 drivers/scsi/mac_scsi.c | 22 ++
 drivers/scsi/sun3_scsi.c| 32 +---
 9 files changed, 49 insertions(+), 78 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 82fd37d..eb40561 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -196,8 +196,9 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
  */
 
 static int NCR5380_poll_politely2(struct Scsi_Host *instance,
-  int reg1, int bit1, int val1,
-  int reg2, int bit2, int val2, int wait)
+  unsigned int reg1, u8 bit1, u8 val1,
+  unsigned int reg2, u8 bit2, u8 val2,
+  unsigned long wait)
 {
struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned long n = hostdata->poll_loops;
@@ -284,6 +285,7 @@ mrs[] = {
 
 static void NCR5380_print(struct Scsi_Host *instance)
 {
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char status, data, basr, mr, icr, i;
 
data = NCR5380_read(CURRENT_SCSI_DATA_REG);
@@ -333,6 +335,7 @@ static struct {
 
 static void NCR5380_print_phase(struct Scsi_Host *instance)
 {
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char status;
int i;
 
@@ -1316,6 +1319,7 @@ static int NCR5380_transfer_pio(struct Scsi_Host 
*instance,
unsigned char *phase, int *count,
unsigned char **data)
 {
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char p = *phase, tmp;
int c = *count;
unsigned char *d = *data;
@@ -1438,6 +1442,7 @@ static int NCR5380_transfer_pio(struct Scsi_Host 
*instance,
 
 static void do_reset(struct Scsi_Host *instance)
 {
+   struct NCR5380_hostdata __maybe_unused *hostdata = shost_priv(instance);
unsigned long flags;
 
local_irq_save(flags);
@@ -1460,6 +1465,7 @@ static void do_reset(struct Scsi_Host *instance)
 
 static int do_abort(struct Scsi_Host *instance)
 {
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
unsigned char *msgptr, phase, tmp;
int len;
int rc;
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index 02f20ff..c2d8b78 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -302,10 +302,13 @@ static void NCR5380_reselect(struct Scsi_Host *instance);
 static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *, struct scsi_cmnd 
*);
 static int NCR5380_transfer_dma(struct Scsi_Host *instance, unsigned char 
*phase, int *count, unsigned char **data);
 static int NCR5380_transfer_pio(struct Scsi_Host *instance, unsigned char 
*phase, int *count, unsigned char **data);
-static int NCR5380_poll_politely2(struct Scsi_Host *, int, int, int, int, int, 
int, int);
+static int NCR5380_poll_politely2(struct Scsi_Host *,
+  unsigned int, u8, u8,
+  unsigned int, u8, u8, unsigned long);
 
 static inline int NCR5380_poll_politely(struct Scsi_Host *instance,
-   int reg, int bit, int val, int wait)
+unsigned int reg, u8 bit, u8 val,
+unsigned long wait)
 {
return NCR5380_poll_politely2(instance, reg, bit, val,
reg, bit, val, wait);
diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index 88db281..ae1d4c6 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -14,8 +14,8 @@
 #include 
 
 #define priv(host) ((struct NCR5380_hostdata 
*)(host)->hostdata)
-#define NCR5380_read(reg)  cumanascsi_read(instance, reg)
-#define NCR5380_write(reg, value)  cumanascsi_write(instance, reg, value)
+#define NCR5380_read(reg)  cumanascsi_read(hostdata, reg)
+#define 

[PATCH v3 02/12] scsi/cumana_1: Remove unused cumanascsi_setup() function

2016-10-09 Thread Finn Thain
Signed-off-by: Finn Thain 
Reviewed-by: Hannes Reinecke 
---
 drivers/scsi/arm/cumana_1.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index 8e9cfe8..f616756 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -33,10 +33,6 @@
 
 #include "../NCR5380.h"
 
-void cumanascsi_setup(char *str, int *ints)
-{
-}
-
 #define CTRL   0x16fc
 #define STAT   0x2004
 #define L(v)   (((v)<<16)|((v) & 0x))
-- 
2.7.3



Re: [PATCH RFC 1/3] tpm_crb: expand struct crb_control_area to struct crb_regs

2016-10-09 Thread Jarkko Sakkinen
On Sun, Oct 09, 2016 at 05:07:37PM -0600, Jason Gunthorpe wrote:
> On Sun, Oct 09, 2016 at 09:33:58PM +0300, Jarkko Sakkinen wrote:
> 
> > > Sorry I missed this part.
> > > 
> > > Here are the constraints for existing hardware:
> > > 
> > > 1. All the existing CRB start only hardware has the iomem covering the
> > >control area and registers for multiple localities.
> > > 2. All the existing ACPI start hardware has only the control area.
> > > 
> > > If you assume that SSDT does not have malicous behavior caused by either
> > > a BIOS bug or maybe a rootkit, then the current patch works for all the
> > > existing hardware.
> > > 
> > > To counter-measure for unexpected behavior in non-existing hardware and
> > > buggy or malicious firmware it probably make sense to use crb_map_res to
> > > validate the part of the CRB registers that is not part of the control
> > > area.
> 
> I don't know how much I'd assume BIOS authors do what you think - the
> spec I saw for this seems very vauge.
> 
> Certainly checking that locality region falls within the acpi mapping
> seems essential.
> 
> > > Doing it in the way you proposed does not work for ACPI start devices.
> > > 
> > > For them it should be done in the same way as I'm doing in the existing
> > > patch as for ACPI start devices the address below the control area are
> > > never accessed. Having a separate crb_map_res for CRB start only devices
> > > is sane thing to do for validation.
> > 
> > Alternative is to do two structures crb_regs_head and crb_regs_tail,
> > which might be cleaner. I'm fine with going either route.
> 
> Since the iomem doesn't actually exist for a configuration having two
> pointers is the better choice. Make sure one is null for the
> configuration that does not support it.
> 
> The negative offset thing is way too subtle.

Yeah, I do agree with you on this. Even if it was functionalliy correct,
it is hard to understand if you don't proactively work on the driver.

> Jason

/Jarkko


Re: [PATCH RFC 1/3] tpm_crb: expand struct crb_control_area to struct crb_regs

2016-10-09 Thread Jarkko Sakkinen
On Sun, Oct 09, 2016 at 05:07:37PM -0600, Jason Gunthorpe wrote:
> On Sun, Oct 09, 2016 at 09:33:58PM +0300, Jarkko Sakkinen wrote:
> 
> > > Sorry I missed this part.
> > > 
> > > Here are the constraints for existing hardware:
> > > 
> > > 1. All the existing CRB start only hardware has the iomem covering the
> > >control area and registers for multiple localities.
> > > 2. All the existing ACPI start hardware has only the control area.
> > > 
> > > If you assume that SSDT does not have malicous behavior caused by either
> > > a BIOS bug or maybe a rootkit, then the current patch works for all the
> > > existing hardware.
> > > 
> > > To counter-measure for unexpected behavior in non-existing hardware and
> > > buggy or malicious firmware it probably make sense to use crb_map_res to
> > > validate the part of the CRB registers that is not part of the control
> > > area.
> 
> I don't know how much I'd assume BIOS authors do what you think - the
> spec I saw for this seems very vauge.
> 
> Certainly checking that locality region falls within the acpi mapping
> seems essential.
> 
> > > Doing it in the way you proposed does not work for ACPI start devices.
> > > 
> > > For them it should be done in the same way as I'm doing in the existing
> > > patch as for ACPI start devices the address below the control area are
> > > never accessed. Having a separate crb_map_res for CRB start only devices
> > > is sane thing to do for validation.
> > 
> > Alternative is to do two structures crb_regs_head and crb_regs_tail,
> > which might be cleaner. I'm fine with going either route.
> 
> Since the iomem doesn't actually exist for a configuration having two
> pointers is the better choice. Make sure one is null for the
> configuration that does not support it.
> 
> The negative offset thing is way too subtle.

Yeah, I do agree with you on this. Even if it was functionalliy correct,
it is hard to understand if you don't proactively work on the driver.

> Jason

/Jarkko


Re: parisc crash on boot with 4.8+git

2016-10-09 Thread Meelis Roos
>  Even if you fix the kernel with the patches above, you still may run
>  into the palo bug. I've just pushed a fix for it into the palo tree:
>  https://git.kernel.org/cgit/linux/kernel/git/deller/palo.git/commit/?id=70bd7a9a41e318c0575755a78c4d18ad97495c47
> 
>  If you rebuild palo, please make sure to install the new ipl boot loader 
>  into
>  the palo partition of your boot disc. palo should report at bootup 
>  version 1.96.
> >>
> >> Same here. Please pull latest version, and install it:
> >> https://git.kernel.org/cgit/linux/kernel/git/deller/palo.git/
> > 
> > palo ipl 1.96 http://www.parisc-linux.org - Sun, 08 Oct 2016 22:40:31 +0100
> > 
> > Just palo with newst upstream kernel git did not change anything, so 
> > it's not palo.
> > 
> > 
> > Pulled 
> > git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git 
> > but it seems to be alreay up to date - these commits are in my tested 
> > upstream that broke the booting?
> 
> Really? I just updated it a few hours ago. Please pull the "for-next" branch.
> 
> Can you send the last line of your "System.map" file, e.g.
> 41f0 B _end
> 
> What is the output of palo when booting ?

Sorry, I pulled from the default branch before, now for-next and it did 
pull stuff.

System.map ends with

4090 B _end



HARD Booted.
palo ipl 1.96 http://www.parisc-linux.org - Sun, 08 Oct 2016 22:40:31 +0100

Partition Start(MB) End(MB) Id Type
1   1  32   f0 Palo
2  33 224   83 ext2
3 225   31696   83 ext2
4   31697   34715   82 swap

PALO(F0) partition contains:

Command line for kernel: 'root=/dev/sdb3 console=ttyS1 
palo_kernel=2/vmlinux'
Selected kernel: /vmlinux from partition 2
ELF64 executable
Entry 0010 first 0010 n 5
Segment 0 load 0010 size 135536 mediaptr 0x1000
Segment 1 load 00122000 size 23320 mediaptr 0x23000
Segment 2 load 0020 size 4541488 mediaptr 0x29000
Segment 3 load 00655000 size 1393916 mediaptr 0x47e000
Segment 4 load 0080 size 1045640 mediaptr 0x5d3000
Branching to kernel entry point 0x0010.  If this is the last
message you see, you may need to switch your console.  This is
a common symptom -- search the FAQ and mailing list at parisc-linux.org

Linux version 4.8.0-11292-gf79b076 (mroos@rp3410) (gcc version 5.4.0 (Gentoo 
5.4.0 p1.0) ) #82 Mon Oct 10 01:25:58 EEST 2016
unwind_init: start = 0x40770e1c, end = 0x407a94fc, entries = 14446
FP[0] enabled: Rev 1 Model 20
The 64-bit Kernel has started...
Kernel default page size is 4 KB. Huge pages enabled with 1 MB physical and 2 
MB virtual size.
bootconsole [ttyB0] enabled
Initialized PDC Console for debugging.
Determining PDC firmware type: 64 bit PAT.
model 8860 0491  0002 3e45475d0860fe3d 10f0 0008 
00b2 00b2
vers  0302
CPUID vers 20 rev 5 (0x0285)
capabilities 0x35
model 9000/800/rp3410  
parisc_cache_init: Only equivalent aliasing supported!
Memory Ranges:
 0) Start 0x End 0x3fff Size   1024 MB
 1) Start 0x00404000 End 0x00407fdf Size   1022 MB
Total Memory: 2046 MB
Backtrace:
 [<40102d40>] paging_init+0x5e0/0x740
 [<40103744>] setup_arch+0x16c/0x1b0
 [<40100ce0>] start_kernel+0xb8/0x668


Bad Address (null pointer deref?): Code=15 regs=408004c0 
(Addr=006cbe693000)
CPU: 0 PID: 0 Comm: swapper Not tainted 4.8.0-11292-gf79b076 #82
task: 4087ba20 task.stack: 4080

 YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI
PSW: 11001110 Not tainted
r00-03  00ff0804ff0e 0090 401024c4 408003b0
r04-07  406b45c0 40ae 00404000 4088b104
r08-11  40800490 00407fe0 00404000 0020
r12-15  406d85c0 40122928 4000 0323
r16-19  00408000 0400  006cbe693000
r20-23  1000 009e2000 0001 0001
r24-27  6c7e693e 408eec90 00408000 406b45c0
r28-31  00404323 40800510 408004c0 006cbe693000
sr00-03     
sr04-07     

IASQ:   IAOQ: 4010251c 40102520
 IIR: 0ffc12c0ISR:   IOR: 006cbe693000
 CPU:0   CR30: 4080 CR31: fff0f0e05ee0
 ORIG_R28: 408006d0
 IAOQ[0]: map_pages+0x234/0x320
 IAOQ[1]: map_pages+0x238/0x320
 RP(r2): map_pages+0x1dc/0x320
Backtrace:
 [<40102d40>] paging_init+0x5e0/0x740
 [<40103744>] setup_arch+0x16c/0x1b0
 [<40100ce0>] start_kernel+0xb8/0x668

Kernel panic - not syncing: Bad Address (null pointer deref?)
---[ end Kernel panic - not syncing: Bad Address (null pointer deref?)



-- 
Meelis 

Re: parisc crash on boot with 4.8+git

2016-10-09 Thread Meelis Roos
>  Even if you fix the kernel with the patches above, you still may run
>  into the palo bug. I've just pushed a fix for it into the palo tree:
>  https://git.kernel.org/cgit/linux/kernel/git/deller/palo.git/commit/?id=70bd7a9a41e318c0575755a78c4d18ad97495c47
> 
>  If you rebuild palo, please make sure to install the new ipl boot loader 
>  into
>  the palo partition of your boot disc. palo should report at bootup 
>  version 1.96.
> >>
> >> Same here. Please pull latest version, and install it:
> >> https://git.kernel.org/cgit/linux/kernel/git/deller/palo.git/
> > 
> > palo ipl 1.96 http://www.parisc-linux.org - Sun, 08 Oct 2016 22:40:31 +0100
> > 
> > Just palo with newst upstream kernel git did not change anything, so 
> > it's not palo.
> > 
> > 
> > Pulled 
> > git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git 
> > but it seems to be alreay up to date - these commits are in my tested 
> > upstream that broke the booting?
> 
> Really? I just updated it a few hours ago. Please pull the "for-next" branch.
> 
> Can you send the last line of your "System.map" file, e.g.
> 41f0 B _end
> 
> What is the output of palo when booting ?

Sorry, I pulled from the default branch before, now for-next and it did 
pull stuff.

System.map ends with

4090 B _end



HARD Booted.
palo ipl 1.96 http://www.parisc-linux.org - Sun, 08 Oct 2016 22:40:31 +0100

Partition Start(MB) End(MB) Id Type
1   1  32   f0 Palo
2  33 224   83 ext2
3 225   31696   83 ext2
4   31697   34715   82 swap

PALO(F0) partition contains:

Command line for kernel: 'root=/dev/sdb3 console=ttyS1 
palo_kernel=2/vmlinux'
Selected kernel: /vmlinux from partition 2
ELF64 executable
Entry 0010 first 0010 n 5
Segment 0 load 0010 size 135536 mediaptr 0x1000
Segment 1 load 00122000 size 23320 mediaptr 0x23000
Segment 2 load 0020 size 4541488 mediaptr 0x29000
Segment 3 load 00655000 size 1393916 mediaptr 0x47e000
Segment 4 load 0080 size 1045640 mediaptr 0x5d3000
Branching to kernel entry point 0x0010.  If this is the last
message you see, you may need to switch your console.  This is
a common symptom -- search the FAQ and mailing list at parisc-linux.org

Linux version 4.8.0-11292-gf79b076 (mroos@rp3410) (gcc version 5.4.0 (Gentoo 
5.4.0 p1.0) ) #82 Mon Oct 10 01:25:58 EEST 2016
unwind_init: start = 0x40770e1c, end = 0x407a94fc, entries = 14446
FP[0] enabled: Rev 1 Model 20
The 64-bit Kernel has started...
Kernel default page size is 4 KB. Huge pages enabled with 1 MB physical and 2 
MB virtual size.
bootconsole [ttyB0] enabled
Initialized PDC Console for debugging.
Determining PDC firmware type: 64 bit PAT.
model 8860 0491  0002 3e45475d0860fe3d 10f0 0008 
00b2 00b2
vers  0302
CPUID vers 20 rev 5 (0x0285)
capabilities 0x35
model 9000/800/rp3410  
parisc_cache_init: Only equivalent aliasing supported!
Memory Ranges:
 0) Start 0x End 0x3fff Size   1024 MB
 1) Start 0x00404000 End 0x00407fdf Size   1022 MB
Total Memory: 2046 MB
Backtrace:
 [<40102d40>] paging_init+0x5e0/0x740
 [<40103744>] setup_arch+0x16c/0x1b0
 [<40100ce0>] start_kernel+0xb8/0x668


Bad Address (null pointer deref?): Code=15 regs=408004c0 
(Addr=006cbe693000)
CPU: 0 PID: 0 Comm: swapper Not tainted 4.8.0-11292-gf79b076 #82
task: 4087ba20 task.stack: 4080

 YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI
PSW: 11001110 Not tainted
r00-03  00ff0804ff0e 0090 401024c4 408003b0
r04-07  406b45c0 40ae 00404000 4088b104
r08-11  40800490 00407fe0 00404000 0020
r12-15  406d85c0 40122928 4000 0323
r16-19  00408000 0400  006cbe693000
r20-23  1000 009e2000 0001 0001
r24-27  6c7e693e 408eec90 00408000 406b45c0
r28-31  00404323 40800510 408004c0 006cbe693000
sr00-03     
sr04-07     

IASQ:   IAOQ: 4010251c 40102520
 IIR: 0ffc12c0ISR:   IOR: 006cbe693000
 CPU:0   CR30: 4080 CR31: fff0f0e05ee0
 ORIG_R28: 408006d0
 IAOQ[0]: map_pages+0x234/0x320
 IAOQ[1]: map_pages+0x238/0x320
 RP(r2): map_pages+0x1dc/0x320
Backtrace:
 [<40102d40>] paging_init+0x5e0/0x740
 [<40103744>] setup_arch+0x16c/0x1b0
 [<40100ce0>] start_kernel+0xb8/0x668

Kernel panic - not syncing: Bad Address (null pointer deref?)
---[ end Kernel panic - not syncing: Bad Address (null pointer deref?)



-- 
Meelis 

linux-next: Tree for Oct 10

2016-10-09 Thread Stephen Rothwell
Hi all,

Please do *not* add any v4.10 material to your linux-next included trees
until v4.9-rc1 has been released i.e. the merge window closes.

Changes since 20161006:

The vfs tree gained conflicts against Linus', the overlayfs and the
ubifs trees.

The rdma tree gained conflicts against Linus' tree.

Non-merge commits (relative to Linus' tree): 3521
 3780 files changed, 193431 insertions(+), 103838 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc and an allmodconfig (with
CONFIG_BUILD_DOCSRC=n) for x86_64, a multi_v7_defconfig for arm and a
native build of tools/perf. After the final fixups (if any), I do an
x86_64 modules_install followed by builds for x86_64 allnoconfig,
powerpc allnoconfig (32 and 64 bit), ppc44x_defconfig, allyesconfig
(this fails its final link) and pseries_le_defconfig and i386, sparc
and sparc64 defconfig.

Below is a summary of the state of the merge.

I am currently merging 243 trees (counting Linus' and 34 trees of patches
pending for Linus' tree).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (b66484cd7470 Merge branch 'akpm' (patches from Andrew))
Merging fixes/master (a6930aaee067 Merge branch 'for-next' of 
git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu)
Merging kbuild-current/rc-fixes (d3e2773c4ede builddeb: Skip gcc-plugins when 
not configured)
Merging arc-current/for-curr (8df0cc75f530 ARC: [build] Support gz, lzma 
compressed uImage)
Merging arm-current/fixes (fb833b1fbb68 ARM: fix delays)
Merging m68k-current/for-linus (6736e65effc3 m68k: Migrate exception table 
users off module.h and onto extable.h)
Merging metag-fixes/fixes (35d04077ad96 metag: Only define 
atomic_dec_if_positive conditionally)
Merging powerpc-fixes/fixes (b79331a5eb9f powerpc/powernv/pci: Fix m64 checks 
for SR-IOV and window alignment)
Merging sparc/master (4c1fad64eff4 Merge tag 'for-f2fs-4.9' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs)
Merging net/master (2f7c68d8e6d4 Merge branch 'for-upstream' of 
git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth)
Merging ipsec/master (b1f2beb87bb0 Merge tag 'media/v4.8-7' of 
git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media)
Merging netfilter/master (4c1fad64eff4 Merge tag 'for-f2fs-4.9' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs)
Merging ipvs/master (ea43f860d984 Merge branch 'ethoc-fixes')
Merging wireless-drivers/master (29d5e6fbd65b rtl8xxxu: Fix rtl8192eu driver 
reload issue)
Merging mac80211/master (7aa6ec229661 drivers: net: phy: Correct duplicate 
MDIO_XGENE entry)
Merging sound-current/for-linus (eeea8b40cd28 Merge tag 'asoc-v4.9' of 
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into for-next)
Merging pci-current/for-linus (035ee288ae7a PCI: Fix bridge_d3 update on device 
removal)
Merging driver-core.current/driver-core-linus (b66484cd7470 Merge branch 'akpm' 
(patches from Andrew))
Merging tty.current/tty-linus (b66484cd7470 Merge branch 'akpm' (patches from 
Andrew))
Merging usb.current/usb-linus (b66484cd7470 Merge branch 'akpm' (patches from 
Andrew))
Merging usb-gadget-fixes/fixes (d8a4100ddc75 usb: gadget: udc: atmel: fix 
endpoint name)
Merging usb-serial-fixes/usb-linus (f190fd92458d USB: serial: simple: add 
support for another Infineon flashloader)
Merging usb-chipidea-fixes/ci-for-usb-stable (6b7f456e67a1 usb: chipidea: host: 
fix NULL ptr dereference during shutdown)
Merging staging.current/staging-linus (b66484cd7470 Merge branch 'akpm' 
(patches from Andrew))
Merging char-misc.current/char-misc-linus (b66484cd7470 Merge branch 'akpm' 
(patches from Andrew))
Merging input-current/for-linus (c758f96a8c34 Merge branch 'next' into 
for-linus)
Merging crypto-current/master (80da44c29d99 crypto: vmx - Fix memory corruption 
caused by p8_ghash)
Merging ide/master (797cee982eef Merge branch 'stable-4.8' of 

linux-next: Tree for Oct 10

2016-10-09 Thread Stephen Rothwell
Hi all,

Please do *not* add any v4.10 material to your linux-next included trees
until v4.9-rc1 has been released i.e. the merge window closes.

Changes since 20161006:

The vfs tree gained conflicts against Linus', the overlayfs and the
ubifs trees.

The rdma tree gained conflicts against Linus' tree.

Non-merge commits (relative to Linus' tree): 3521
 3780 files changed, 193431 insertions(+), 103838 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc and an allmodconfig (with
CONFIG_BUILD_DOCSRC=n) for x86_64, a multi_v7_defconfig for arm and a
native build of tools/perf. After the final fixups (if any), I do an
x86_64 modules_install followed by builds for x86_64 allnoconfig,
powerpc allnoconfig (32 and 64 bit), ppc44x_defconfig, allyesconfig
(this fails its final link) and pseries_le_defconfig and i386, sparc
and sparc64 defconfig.

Below is a summary of the state of the merge.

I am currently merging 243 trees (counting Linus' and 34 trees of patches
pending for Linus' tree).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (b66484cd7470 Merge branch 'akpm' (patches from Andrew))
Merging fixes/master (a6930aaee067 Merge branch 'for-next' of 
git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu)
Merging kbuild-current/rc-fixes (d3e2773c4ede builddeb: Skip gcc-plugins when 
not configured)
Merging arc-current/for-curr (8df0cc75f530 ARC: [build] Support gz, lzma 
compressed uImage)
Merging arm-current/fixes (fb833b1fbb68 ARM: fix delays)
Merging m68k-current/for-linus (6736e65effc3 m68k: Migrate exception table 
users off module.h and onto extable.h)
Merging metag-fixes/fixes (35d04077ad96 metag: Only define 
atomic_dec_if_positive conditionally)
Merging powerpc-fixes/fixes (b79331a5eb9f powerpc/powernv/pci: Fix m64 checks 
for SR-IOV and window alignment)
Merging sparc/master (4c1fad64eff4 Merge tag 'for-f2fs-4.9' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs)
Merging net/master (2f7c68d8e6d4 Merge branch 'for-upstream' of 
git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth)
Merging ipsec/master (b1f2beb87bb0 Merge tag 'media/v4.8-7' of 
git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media)
Merging netfilter/master (4c1fad64eff4 Merge tag 'for-f2fs-4.9' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs)
Merging ipvs/master (ea43f860d984 Merge branch 'ethoc-fixes')
Merging wireless-drivers/master (29d5e6fbd65b rtl8xxxu: Fix rtl8192eu driver 
reload issue)
Merging mac80211/master (7aa6ec229661 drivers: net: phy: Correct duplicate 
MDIO_XGENE entry)
Merging sound-current/for-linus (eeea8b40cd28 Merge tag 'asoc-v4.9' of 
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into for-next)
Merging pci-current/for-linus (035ee288ae7a PCI: Fix bridge_d3 update on device 
removal)
Merging driver-core.current/driver-core-linus (b66484cd7470 Merge branch 'akpm' 
(patches from Andrew))
Merging tty.current/tty-linus (b66484cd7470 Merge branch 'akpm' (patches from 
Andrew))
Merging usb.current/usb-linus (b66484cd7470 Merge branch 'akpm' (patches from 
Andrew))
Merging usb-gadget-fixes/fixes (d8a4100ddc75 usb: gadget: udc: atmel: fix 
endpoint name)
Merging usb-serial-fixes/usb-linus (f190fd92458d USB: serial: simple: add 
support for another Infineon flashloader)
Merging usb-chipidea-fixes/ci-for-usb-stable (6b7f456e67a1 usb: chipidea: host: 
fix NULL ptr dereference during shutdown)
Merging staging.current/staging-linus (b66484cd7470 Merge branch 'akpm' 
(patches from Andrew))
Merging char-misc.current/char-misc-linus (b66484cd7470 Merge branch 'akpm' 
(patches from Andrew))
Merging input-current/for-linus (c758f96a8c34 Merge branch 'next' into 
for-linus)
Merging crypto-current/master (80da44c29d99 crypto: vmx - Fix memory corruption 
caused by p8_ghash)
Merging ide/master (797cee982eef Merge branch 'stable-4.8' of 

[PATCH] sched/core: Fix kick offline cpu to do nohz idle load balance

2016-10-09 Thread Wanpeng Li
From: Wanpeng Li 

 WARNING: CPU: 0 PID: 3404 at arch/x86/kernel/smp.c:125 
native_smp_send_reschedule+0x3f/0x50
 CPU: 0 PID: 3404 Comm: qemu-system-x86 Not tainted 4.8.0+ #21
 Call Trace:
   __warn+0xd1/0xf0
   warn_slowpath_null+0x1d/0x20
   native_smp_send_reschedule+0x3f/0x50
   trigger_load_balance+0x29c/0x4a0
   ? trigger_load_balance+0x72/0x4a0
   scheduler_tick+0x9f/0xd0
   ? tick_sched_do_timer+0x50/0x50
   update_process_times+0x47/0x60
   tick_sched_handle.isra.24+0x25/0x60
   tick_sched_timer+0x3d/0x70
   __hrtimer_run_queues+0xf4/0x510
   hrtimer_interrupt+0xb7/0x1d0
   local_apic_timer_interrupt+0x35/0x60
   smp_apic_timer_interrupt+0x3d/0x50
   apic_timer_interrupt+0x96/0xa0

If there is a need to kick the idle load balancer, an ILB will be selected 
to perform nohz idle load balance, however, if the selected ILB is in the 
process of offline, smp_sched_reschedule() which generates a sched IPI will 
splat as above.

   CPU0  CPU1 
 
 find_new_ilb() 
set_rq_offline() 
 smp_sched_reschedule()  Oops
nohz_balance_exit_idle() 

This patch fix it by exiting nohz idle balance before set cpu offline.

Cc: Ingo Molnar 
Cc: Mike Galbraith 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Signed-off-by: Wanpeng Li 
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 94732d1..7c83f99 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7412,6 +7412,7 @@ int sched_cpu_dying(unsigned int cpu)
 
/* Handle pending wakeups and then migrate everything off */
sched_ttwu_pending();
+   nohz_balance_exit_idle(cpu);
raw_spin_lock_irqsave(>lock, flags);
if (rq->rd) {
BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
@@ -7422,7 +7423,6 @@ int sched_cpu_dying(unsigned int cpu)
raw_spin_unlock_irqrestore(>lock, flags);
calc_load_migrate(rq);
update_max_interval();
-   nohz_balance_exit_idle(cpu);
hrtick_clear(rq);
return 0;
 }
-- 
1.9.1



[PATCH] sched/core: Fix kick offline cpu to do nohz idle load balance

2016-10-09 Thread Wanpeng Li
From: Wanpeng Li 

 WARNING: CPU: 0 PID: 3404 at arch/x86/kernel/smp.c:125 
native_smp_send_reschedule+0x3f/0x50
 CPU: 0 PID: 3404 Comm: qemu-system-x86 Not tainted 4.8.0+ #21
 Call Trace:
   __warn+0xd1/0xf0
   warn_slowpath_null+0x1d/0x20
   native_smp_send_reschedule+0x3f/0x50
   trigger_load_balance+0x29c/0x4a0
   ? trigger_load_balance+0x72/0x4a0
   scheduler_tick+0x9f/0xd0
   ? tick_sched_do_timer+0x50/0x50
   update_process_times+0x47/0x60
   tick_sched_handle.isra.24+0x25/0x60
   tick_sched_timer+0x3d/0x70
   __hrtimer_run_queues+0xf4/0x510
   hrtimer_interrupt+0xb7/0x1d0
   local_apic_timer_interrupt+0x35/0x60
   smp_apic_timer_interrupt+0x3d/0x50
   apic_timer_interrupt+0x96/0xa0

If there is a need to kick the idle load balancer, an ILB will be selected 
to perform nohz idle load balance, however, if the selected ILB is in the 
process of offline, smp_sched_reschedule() which generates a sched IPI will 
splat as above.

   CPU0  CPU1 
 
 find_new_ilb() 
set_rq_offline() 
 smp_sched_reschedule()  Oops
nohz_balance_exit_idle() 

This patch fix it by exiting nohz idle balance before set cpu offline.

Cc: Ingo Molnar 
Cc: Mike Galbraith 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Signed-off-by: Wanpeng Li 
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 94732d1..7c83f99 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7412,6 +7412,7 @@ int sched_cpu_dying(unsigned int cpu)
 
/* Handle pending wakeups and then migrate everything off */
sched_ttwu_pending();
+   nohz_balance_exit_idle(cpu);
raw_spin_lock_irqsave(>lock, flags);
if (rq->rd) {
BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
@@ -7422,7 +7423,6 @@ int sched_cpu_dying(unsigned int cpu)
raw_spin_unlock_irqrestore(>lock, flags);
calc_load_migrate(rq);
update_max_interval();
-   nohz_balance_exit_idle(cpu);
hrtick_clear(rq);
return 0;
 }
-- 
1.9.1



Re: [RFC][PATCH 6/7] printk: use alternative printk buffers

2016-10-09 Thread Sergey Senozhatsky
On (10/06/16 13:32), Petr Mladek wrote:
> On Thu 2016-10-06 13:22:48, Sergey Senozhatsky wrote:
> > On (10/05/16 11:50), Petr Mladek wrote:
> > [..]
> > > > well, it solves a number of problems that the existing implementation
> > > > cannot handle.
> > > 
> > > Please, provide a summary. I wonder if these are real life problems.
> > 
> > 1) some pathces/reports from Byungchul Park
> > 2) a report from Viresh Kumar.
> > 4) sleeping function called from inside logbuf lock
> > 5) ARM specific
> > 6) logbuf_lock corruption
> 
> It is great that you have such a list in hands. It might help
> to push this solution.
> 
> I actually have one more reason for this approach:
> 
> It seems that we will need to keep printk_deferred()/WARN_*DEFERRED().
> We do not know about a better solution for the deadlocks caused
> by scheduler/timekeeping/console_drivers locks.

yes, seems so.

> The pain is that the list of affected locations is hard to maintain.
> It would definitely help if such problems are reported by lockdep
> in advance. But lockdep is disabled because it creates the deadlock
> on its own.

right. another issue is that those potentially recursive printk/WARN_ON
calls may be coming from error-handling branches, not all of which are
easily reachable for automated solutions. so in order to find out there
is a problem we must hit it [in some cases].

it may look that lockdep *probably* can report the issues via 'safe' printk,
but that's a notably huge behavior breakage -- if lockdep report comes from
an about-to-deadlock irq handler, then we won't see anything from that CPU
unless there is a panic/nmi panic.

so it probably has to be semi-automatic/semi-manual:
- add might_printk() that would acquire/release console sem; or
  logbuf_lock (which is probably even better)
- find all functions that do printk/WARN in kernel/time and kernel/sched
- add might_printk() to those functions (just like might_sleep())
- run the kernel
- ...
- profit

#ifdef CONFIG_VALIDATE_PRINTK_CALLS

#define might_printk()  \
do {\
if (!printk_in_safe_mode()) {   \
unsigned long flags;\
\
printk_safe_enter(flags);   \
mutex_acquire(_lock_dep_map...);\
mutex_release(_lock_dep_map...);\
/*  \
 * or printk_deferred("");  \
 */ \
printk_safe_exit(flags);\
}   \
} while (0)

#else

#define might_printk()

#endif


may be that will make it easier. need to think more.


> BTW: I would like to ask you to slow down a bit. More versions
> of such a non-trivial patchset, that are sent within few days,
> are far too much. I have some other tasks that I need to work on.
> Also I would like to hear opinion from other people. Note that
> many people are busy with the merge window at the moment.

sure, sorry about that! wasn't really happy with that as well.
and thanks for your help.

-ss


Re: [RFC][PATCH 6/7] printk: use alternative printk buffers

2016-10-09 Thread Sergey Senozhatsky
On (10/06/16 13:32), Petr Mladek wrote:
> On Thu 2016-10-06 13:22:48, Sergey Senozhatsky wrote:
> > On (10/05/16 11:50), Petr Mladek wrote:
> > [..]
> > > > well, it solves a number of problems that the existing implementation
> > > > cannot handle.
> > > 
> > > Please, provide a summary. I wonder if these are real life problems.
> > 
> > 1) some pathces/reports from Byungchul Park
> > 2) a report from Viresh Kumar.
> > 4) sleeping function called from inside logbuf lock
> > 5) ARM specific
> > 6) logbuf_lock corruption
> 
> It is great that you have such a list in hands. It might help
> to push this solution.
> 
> I actually have one more reason for this approach:
> 
> It seems that we will need to keep printk_deferred()/WARN_*DEFERRED().
> We do not know about a better solution for the deadlocks caused
> by scheduler/timekeeping/console_drivers locks.

yes, seems so.

> The pain is that the list of affected locations is hard to maintain.
> It would definitely help if such problems are reported by lockdep
> in advance. But lockdep is disabled because it creates the deadlock
> on its own.

right. another issue is that those potentially recursive printk/WARN_ON
calls may be coming from error-handling branches, not all of which are
easily reachable for automated solutions. so in order to find out there
is a problem we must hit it [in some cases].

it may look that lockdep *probably* can report the issues via 'safe' printk,
but that's a notably huge behavior breakage -- if lockdep report comes from
an about-to-deadlock irq handler, then we won't see anything from that CPU
unless there is a panic/nmi panic.

so it probably has to be semi-automatic/semi-manual:
- add might_printk() that would acquire/release console sem; or
  logbuf_lock (which is probably even better)
- find all functions that do printk/WARN in kernel/time and kernel/sched
- add might_printk() to those functions (just like might_sleep())
- run the kernel
- ...
- profit

#ifdef CONFIG_VALIDATE_PRINTK_CALLS

#define might_printk()  \
do {\
if (!printk_in_safe_mode()) {   \
unsigned long flags;\
\
printk_safe_enter(flags);   \
mutex_acquire(_lock_dep_map...);\
mutex_release(_lock_dep_map...);\
/*  \
 * or printk_deferred("");  \
 */ \
printk_safe_exit(flags);\
}   \
} while (0)

#else

#define might_printk()

#endif


may be that will make it easier. need to think more.


> BTW: I would like to ask you to slow down a bit. More versions
> of such a non-trivial patchset, that are sent within few days,
> are far too much. I have some other tasks that I need to work on.
> Also I would like to hear opinion from other people. Note that
> many people are busy with the merge window at the moment.

sure, sorry about that! wasn't really happy with that as well.
and thanks for your help.

-ss


Re: slab corruption with current -git

2016-10-09 Thread David Miller
From: Linus Torvalds 
Date: Sun, 9 Oct 2016 20:41:17 -0700

> Note that the "correct way" of doing list operations also almost
> inevitably is the shortest way by far, since it gets rid of all the
> special cases. So the patch looks nice. It gets rid of the magic
> "nf_set_hooks_head()" thing too, because once you do list following
> right, the head is no different from any other pointer in the list.

Perhaps we should have some "slist" primitives added to
include/linux/list.h but since the comparison differs for each user I
guess it's hard to abstract in a way that's generic and inlines
properly.

I'll start taking a look at your patch and this stuff as well, thanks
Linus.


Re: slab corruption with current -git

2016-10-09 Thread David Miller
From: Linus Torvalds 
Date: Sun, 9 Oct 2016 20:41:17 -0700

> Note that the "correct way" of doing list operations also almost
> inevitably is the shortest way by far, since it gets rid of all the
> special cases. So the patch looks nice. It gets rid of the magic
> "nf_set_hooks_head()" thing too, because once you do list following
> right, the head is no different from any other pointer in the list.

Perhaps we should have some "slist" primitives added to
include/linux/list.h but since the comparison differs for each user I
guess it's hard to abstract in a way that's generic and inlines
properly.

I'll start taking a look at your patch and this stuff as well, thanks
Linus.


[PATCH] mm: init gfp mask in kcompactd_do_work()

2016-10-09 Thread Xishi Qiu
We will use gfp_mask in the following path, but it's not init.

kcompactd_do_work
compact_zone
gfpflags_to_migratetype

However if not init, gfp_mask is always 0, and the result of
gfpflags_to_migratetype(0) and gfpflags_to_migratetype(GFP_KERNEL)
are the same, but it's a little confusion, so init it first.

Signed-off-by: Xishi Qiu 
---
 mm/compaction.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 9affb29..4b9a9d1 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1895,10 +1895,10 @@ static void kcompactd_do_work(pg_data_t *pgdat)
struct zone *zone;
struct compact_control cc = {
.order = pgdat->kcompactd_max_order,
+   .gfp_mask = GFP_KERNEL,
.classzone_idx = pgdat->kcompactd_classzone_idx,
.mode = MIGRATE_SYNC_LIGHT,
.ignore_skip_hint = true,
-
};
bool success = false;
 
-- 
1.8.3.1




Re: [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-09 Thread Dan Williams
On Sun, Oct 9, 2016 at 5:35 PM, Haozhong Zhang  wrote:
> Overview
> 
> This RFC kernel patch series along with corresponding patch series of
> Xen, QEMU and ndctl implements Xen vNVDIMM, which can map the host
> NVDIMM devices to Xen HVM domU as vNVDIMM devices.
>
> Xen hypervisor does not include an NVDIMM driver, so it needs the
> assistance from the driver in Dom0 Linux kernel to manage NVDIMM
> devices. We currently only supports NVDIMM devices in pmem mode.
>
> Design and Implementation
> =
> The complete design can be found at
>   https://lists.xenproject.org/archives/html/xen-devel/2016-07/msg01921.html.

The KVM enabling for persistent memory does not need this support from
the kernel, and as far as I can see neither does Xen. If the
hypervisor needs to reserve some space it can simply trim the amount
that it hands to the guest.

The usage of fiemap and the sysfs resource for the pmem device, as
mentioned in the design document, does not seem to comprehend that
file block allocations may be discontiguous and may change over time
depending on the file.


Re: [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-09 Thread Dan Williams
On Sun, Oct 9, 2016 at 5:35 PM, Haozhong Zhang  wrote:
> Overview
> 
> This RFC kernel patch series along with corresponding patch series of
> Xen, QEMU and ndctl implements Xen vNVDIMM, which can map the host
> NVDIMM devices to Xen HVM domU as vNVDIMM devices.
>
> Xen hypervisor does not include an NVDIMM driver, so it needs the
> assistance from the driver in Dom0 Linux kernel to manage NVDIMM
> devices. We currently only supports NVDIMM devices in pmem mode.
>
> Design and Implementation
> =
> The complete design can be found at
>   https://lists.xenproject.org/archives/html/xen-devel/2016-07/msg01921.html.

The KVM enabling for persistent memory does not need this support from
the kernel, and as far as I can see neither does Xen. If the
hypervisor needs to reserve some space it can simply trim the amount
that it hands to the guest.

The usage of fiemap and the sysfs resource for the pmem device, as
mentioned in the design document, does not seem to comprehend that
file block allocations may be discontiguous and may change over time
depending on the file.


[PATCH] mm: init gfp mask in kcompactd_do_work()

2016-10-09 Thread Xishi Qiu
We will use gfp_mask in the following path, but it's not init.

kcompactd_do_work
compact_zone
gfpflags_to_migratetype

However if not init, gfp_mask is always 0, and the result of
gfpflags_to_migratetype(0) and gfpflags_to_migratetype(GFP_KERNEL)
are the same, but it's a little confusion, so init it first.

Signed-off-by: Xishi Qiu 
---
 mm/compaction.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 9affb29..4b9a9d1 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1895,10 +1895,10 @@ static void kcompactd_do_work(pg_data_t *pgdat)
struct zone *zone;
struct compact_control cc = {
.order = pgdat->kcompactd_max_order,
+   .gfp_mask = GFP_KERNEL,
.classzone_idx = pgdat->kcompactd_classzone_idx,
.mode = MIGRATE_SYNC_LIGHT,
.ignore_skip_hint = true,
-
};
bool success = false;
 
-- 
1.8.3.1




Re: btrfs_direct_IO oops

2016-10-09 Thread Al Viro
On Sun, Oct 09, 2016 at 11:11:06AM -0400, Dave Jones wrote:
> idx = 0, offset = 0

== starts at slot 0, nothing put into it yet, but

> curbuf = 0, nrbufs = 1, buffers = 16
> [9fa21100 ea00065f6d80 0 4096]

the underlying pipe has something stored into slot 0.  That definitely
should not happen.

> WARNING: CPU: 0 PID: 29610 at lib/iov_iter.c:327 sanity+0x102/0x150
> CPU: 0 PID: 29610 Comm: trinity-c9 Not tainted 4.8.0-think+ #8 
>  c97b7ae8
>  9f3e2011
>  
>  

>  9fc1e22b
>  9f3fa2f2
>  c97b7b28
>  9f08b010
> 
>  014734c3d60f
>  9fc1e22b
>  0147
>  0010

*blink*

where have those come from?
 
> Call Trace:
>  [] dump_stack+0x6c/0x9b
>  [] ? sanity+0x102/0x150
>  [] __warn+0x110/0x130
>  [] warn_slowpath_null+0x2c/0x40
>  [] sanity+0x102/0x150
>  [] copy_page_to_iter+0x2be/0x480
>  [] ? pagecache_get_page+0xba/0x4f0
>  [] generic_file_read_iter+0x245/0xd30
>  [] generic_file_splice_read+0xfd/0x230
>  [] ? pipe_to_user+0x40/0x40
>  [] do_splice_to+0x98/0xd0
>  [] splice_direct_to_actor+0xd4/0x2c0
>  [] ? generic_pipe_buf_nosteal+0x10/0x10
>  [] do_splice_direct+0xc5/0x110
>  [] do_sendfile+0x242/0x470
>  [] SyS_sendfile64+0x7d/0xf0
>  [] do_syscall_64+0x7f/0x200
>  [] entry_SYSCALL64_slow_path+0x25/0x25
> ---[ end trace 2c7bd411d4aa0491 ]---

Very interesting.  Could you slap something like
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 0ce3411..1ef00e7 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -682,8 +682,9 @@ static void pipe_advance(struct iov_iter *i, size_t size)
 {
struct pipe_inode_info *pipe = i->pipe;
struct pipe_buffer *buf;
-   int idx = i->idx;
-   size_t off = i->iov_offset;
+   int old_idx = idx = i->idx;
+   size_t old_off = off = i->iov_offset;
+   size_t old_size = size;

if (unlikely(i->count < size))
size = i->count;
@@ -713,6 +714,9 @@ static void pipe_advance(struct iov_iter *i, size_t size)
pipe->nrbufs--;
}
}
+   if (!sanity(i))
+   printk(KERN_ERR "buggered pipe_advance(%zd) [%d,%zd]",
+   old_size, old_idx, old_off);
 }
 
 void iov_iter_advance(struct iov_iter *i, size_t size)

in there and try to reproduce that one?


Re: btrfs_direct_IO oops

2016-10-09 Thread Al Viro
On Sun, Oct 09, 2016 at 11:11:06AM -0400, Dave Jones wrote:
> idx = 0, offset = 0

== starts at slot 0, nothing put into it yet, but

> curbuf = 0, nrbufs = 1, buffers = 16
> [9fa21100 ea00065f6d80 0 4096]

the underlying pipe has something stored into slot 0.  That definitely
should not happen.

> WARNING: CPU: 0 PID: 29610 at lib/iov_iter.c:327 sanity+0x102/0x150
> CPU: 0 PID: 29610 Comm: trinity-c9 Not tainted 4.8.0-think+ #8 
>  c97b7ae8
>  9f3e2011
>  
>  

>  9fc1e22b
>  9f3fa2f2
>  c97b7b28
>  9f08b010
> 
>  014734c3d60f
>  9fc1e22b
>  0147
>  0010

*blink*

where have those come from?
 
> Call Trace:
>  [] dump_stack+0x6c/0x9b
>  [] ? sanity+0x102/0x150
>  [] __warn+0x110/0x130
>  [] warn_slowpath_null+0x2c/0x40
>  [] sanity+0x102/0x150
>  [] copy_page_to_iter+0x2be/0x480
>  [] ? pagecache_get_page+0xba/0x4f0
>  [] generic_file_read_iter+0x245/0xd30
>  [] generic_file_splice_read+0xfd/0x230
>  [] ? pipe_to_user+0x40/0x40
>  [] do_splice_to+0x98/0xd0
>  [] splice_direct_to_actor+0xd4/0x2c0
>  [] ? generic_pipe_buf_nosteal+0x10/0x10
>  [] do_splice_direct+0xc5/0x110
>  [] do_sendfile+0x242/0x470
>  [] SyS_sendfile64+0x7d/0xf0
>  [] do_syscall_64+0x7f/0x200
>  [] entry_SYSCALL64_slow_path+0x25/0x25
> ---[ end trace 2c7bd411d4aa0491 ]---

Very interesting.  Could you slap something like
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 0ce3411..1ef00e7 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -682,8 +682,9 @@ static void pipe_advance(struct iov_iter *i, size_t size)
 {
struct pipe_inode_info *pipe = i->pipe;
struct pipe_buffer *buf;
-   int idx = i->idx;
-   size_t off = i->iov_offset;
+   int old_idx = idx = i->idx;
+   size_t old_off = off = i->iov_offset;
+   size_t old_size = size;

if (unlikely(i->count < size))
size = i->count;
@@ -713,6 +714,9 @@ static void pipe_advance(struct iov_iter *i, size_t size)
pipe->nrbufs--;
}
}
+   if (!sanity(i))
+   printk(KERN_ERR "buggered pipe_advance(%zd) [%d,%zd]",
+   old_size, old_idx, old_off);
 }
 
 void iov_iter_advance(struct iov_iter *i, size_t size)

in there and try to reproduce that one?


Re: slab corruption with current -git (was Re: [git pull] vfs pile 1 (splice))

2016-10-09 Thread Linus Torvalds
On Sun, Oct 9, 2016 at 7:49 PM, Linus Torvalds
 wrote:
>
> There is one *correct* way to remove an entry from a singly linked
> list, and it looks like this:
>
> struct entry **pp, *p;
>
> pp = 
> while ((p = *pp) != NULL) {
> if (right_entry(p)) {
> *pp = p->next;
> break;
> }
> pp = >next;
> }
>
> and that's it. Nothing else.

This COMPLETELY UNTESTED patch tries to fix the nf_hook_entry code to do this.

I repeat: it's ENTIRELY UNTESTED. I just converted the insertion and
deletion to the proper pattern, but I could easily have gotten the
insertion priority test the wrong way around entirely, for example. Or
it could simply have some other completely broken bug in it. It
compiles for me, but that's all I actually checked.

Note that the "correct way" of doing list operations also almost
inevitably is the shortest way by far, since it gets rid of all the
special cases. So the patch looks nice. It gets rid of the magic
"nf_set_hooks_head()" thing too, because once you do list following
right, the head is no different from any other pointer in the list.

So the patch stats look good:

 net/netfilter/core.c | 108 ---
 1 file changed, 33 insertions(+), 75 deletions(-)

but again, it's entirely *entirely* untested. Please consider this
just a "this is generally how list insert/delete operations should be
done, avoiding special cases for the first entry".

ALSO NOTE! The code assumes that the "nf_hook_mutex" locking only
protects the actual *lists*, and that the address to the list can be
looked up without holding the lock. That's generally how things are
done, and it simplifies error handling (because you can do the "there
is no such list at all" test before you do anything else. But again, I
don't actually know the code, and if there is something that actually
expands the number of lists etc that depends on that mutex, then the
list head lookup may need to be inside the lock too.

   Linus
 net/netfilter/core.c | 108 ---
 1 file changed, 33 insertions(+), 75 deletions(-)

diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index c9d90eb64046..814258641fcc 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -65,49 +65,24 @@ static DEFINE_MUTEX(nf_hook_mutex);
 #define nf_entry_dereference(e) \
rcu_dereference_protected(e, lockdep_is_held(_hook_mutex))
 
-static struct nf_hook_entry *nf_hook_entry_head(struct net *net,
-   const struct nf_hook_ops *reg)
+static struct nf_hook_entry __rcu **nf_hook_entry_head(struct net *net, const 
struct nf_hook_ops *reg)
 {
-   struct nf_hook_entry *hook_head = NULL;
-
if (reg->pf != NFPROTO_NETDEV)
-   hook_head = nf_entry_dereference(net->nf.hooks[reg->pf]
-[reg->hooknum]);
-   else if (reg->hooknum == NF_NETDEV_INGRESS) {
+   return net->nf.hooks[reg->pf]+reg->hooknum;
+
 #ifdef CONFIG_NETFILTER_INGRESS
+   if (reg->hooknum == NF_NETDEV_INGRESS) {
if (reg->dev && dev_net(reg->dev) == net)
-   hook_head =
-   nf_entry_dereference(
-   reg->dev->nf_hooks_ingress);
-#endif
+   return >dev->nf_hooks_ingress;
}
-   return hook_head;
-}
-
-/* must hold nf_hook_mutex */
-static void nf_set_hooks_head(struct net *net, const struct nf_hook_ops *reg,
- struct nf_hook_entry *entry)
-{
-   switch (reg->pf) {
-   case NFPROTO_NETDEV:
-#ifdef CONFIG_NETFILTER_INGRESS
-   /* We already checked in nf_register_net_hook() that this is
-* used from ingress.
-*/
-   rcu_assign_pointer(reg->dev->nf_hooks_ingress, entry);
 #endif
-   break;
-   default:
-   rcu_assign_pointer(net->nf.hooks[reg->pf][reg->hooknum],
-  entry);
-   break;
-   }
+   return NULL;
 }
 
 int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg)
 {
-   struct nf_hook_entry *hooks_entry;
-   struct nf_hook_entry *entry;
+   struct nf_hook_entry __rcu **pp;
+   struct nf_hook_entry *entry, *p;
 
if (reg->pf == NFPROTO_NETDEV) {
 #ifndef CONFIG_NETFILTER_INGRESS
@@ -119,6 +94,10 @@ int nf_register_net_hook(struct net *net, const struct 
nf_hook_ops *reg)
return -EINVAL;
}
 
+   pp = nf_hook_entry_head(net, reg);
+   if (!pp)
+   return -EINVAL;
+
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
if (!entry)
return -ENOMEM;
@@ -128,26 +107,15 @@ int nf_register_net_hook(struct net *net, const struct 
nf_hook_ops *reg)
entry->next = NULL;
 
 

Re: slab corruption with current -git (was Re: [git pull] vfs pile 1 (splice))

2016-10-09 Thread Linus Torvalds
On Sun, Oct 9, 2016 at 7:49 PM, Linus Torvalds
 wrote:
>
> There is one *correct* way to remove an entry from a singly linked
> list, and it looks like this:
>
> struct entry **pp, *p;
>
> pp = 
> while ((p = *pp) != NULL) {
> if (right_entry(p)) {
> *pp = p->next;
> break;
> }
> pp = >next;
> }
>
> and that's it. Nothing else.

This COMPLETELY UNTESTED patch tries to fix the nf_hook_entry code to do this.

I repeat: it's ENTIRELY UNTESTED. I just converted the insertion and
deletion to the proper pattern, but I could easily have gotten the
insertion priority test the wrong way around entirely, for example. Or
it could simply have some other completely broken bug in it. It
compiles for me, but that's all I actually checked.

Note that the "correct way" of doing list operations also almost
inevitably is the shortest way by far, since it gets rid of all the
special cases. So the patch looks nice. It gets rid of the magic
"nf_set_hooks_head()" thing too, because once you do list following
right, the head is no different from any other pointer in the list.

So the patch stats look good:

 net/netfilter/core.c | 108 ---
 1 file changed, 33 insertions(+), 75 deletions(-)

but again, it's entirely *entirely* untested. Please consider this
just a "this is generally how list insert/delete operations should be
done, avoiding special cases for the first entry".

ALSO NOTE! The code assumes that the "nf_hook_mutex" locking only
protects the actual *lists*, and that the address to the list can be
looked up without holding the lock. That's generally how things are
done, and it simplifies error handling (because you can do the "there
is no such list at all" test before you do anything else. But again, I
don't actually know the code, and if there is something that actually
expands the number of lists etc that depends on that mutex, then the
list head lookup may need to be inside the lock too.

   Linus
 net/netfilter/core.c | 108 ---
 1 file changed, 33 insertions(+), 75 deletions(-)

diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index c9d90eb64046..814258641fcc 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -65,49 +65,24 @@ static DEFINE_MUTEX(nf_hook_mutex);
 #define nf_entry_dereference(e) \
rcu_dereference_protected(e, lockdep_is_held(_hook_mutex))
 
-static struct nf_hook_entry *nf_hook_entry_head(struct net *net,
-   const struct nf_hook_ops *reg)
+static struct nf_hook_entry __rcu **nf_hook_entry_head(struct net *net, const 
struct nf_hook_ops *reg)
 {
-   struct nf_hook_entry *hook_head = NULL;
-
if (reg->pf != NFPROTO_NETDEV)
-   hook_head = nf_entry_dereference(net->nf.hooks[reg->pf]
-[reg->hooknum]);
-   else if (reg->hooknum == NF_NETDEV_INGRESS) {
+   return net->nf.hooks[reg->pf]+reg->hooknum;
+
 #ifdef CONFIG_NETFILTER_INGRESS
+   if (reg->hooknum == NF_NETDEV_INGRESS) {
if (reg->dev && dev_net(reg->dev) == net)
-   hook_head =
-   nf_entry_dereference(
-   reg->dev->nf_hooks_ingress);
-#endif
+   return >dev->nf_hooks_ingress;
}
-   return hook_head;
-}
-
-/* must hold nf_hook_mutex */
-static void nf_set_hooks_head(struct net *net, const struct nf_hook_ops *reg,
- struct nf_hook_entry *entry)
-{
-   switch (reg->pf) {
-   case NFPROTO_NETDEV:
-#ifdef CONFIG_NETFILTER_INGRESS
-   /* We already checked in nf_register_net_hook() that this is
-* used from ingress.
-*/
-   rcu_assign_pointer(reg->dev->nf_hooks_ingress, entry);
 #endif
-   break;
-   default:
-   rcu_assign_pointer(net->nf.hooks[reg->pf][reg->hooknum],
-  entry);
-   break;
-   }
+   return NULL;
 }
 
 int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg)
 {
-   struct nf_hook_entry *hooks_entry;
-   struct nf_hook_entry *entry;
+   struct nf_hook_entry __rcu **pp;
+   struct nf_hook_entry *entry, *p;
 
if (reg->pf == NFPROTO_NETDEV) {
 #ifndef CONFIG_NETFILTER_INGRESS
@@ -119,6 +94,10 @@ int nf_register_net_hook(struct net *net, const struct 
nf_hook_ops *reg)
return -EINVAL;
}
 
+   pp = nf_hook_entry_head(net, reg);
+   if (!pp)
+   return -EINVAL;
+
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
if (!entry)
return -ENOMEM;
@@ -128,26 +107,15 @@ int nf_register_net_hook(struct net *net, const struct 
nf_hook_ops *reg)
entry->next = NULL;
 
mutex_lock(_hook_mutex);
-  

[PATCH 2/2] arm: futex: Use asm-generic/futex.h instead of redefining the entire header

2016-10-09 Thread Joel Porquet
"asm-generic/futex.h" was refactored and now allows arch ports to only
define arch-specific macros instead of redefining the entire header
file.

This patch adapts "asm/futex.h" for ARM by only defining the macros
required by the generic header (ie __futex_atomic_op_inuser() and
__futex_atomic_cmpxchg_inatomic()).

Compiled (SMP and !SMP) and booted on QEMU with a minimal busybox-based
system.

Signed-off-by: Joel Porquet 
---
 arch/arm/include/asm/futex.h | 203 ++-
 1 file changed, 84 insertions(+), 119 deletions(-)

diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
index 6795368..d3db562 100644
--- a/arch/arm/include/asm/futex.h
+++ b/arch/arm/include/asm/futex.h
@@ -39,41 +39,30 @@
: "r" (uaddr), "r" (oparg), "Ir" (-EFAULT)  \
: "cc", "memory");  \
uaccess_restore(__ua_flags);\
+   smp_mb();   \
 })
 
-static inline int
-futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
- u32 oldval, u32 newval)
-{
-   unsigned int __ua_flags;
-   int ret;
-   u32 val;
-
-   if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
-   return -EFAULT;
-
-   smp_mb();
-   /* Prefetching cannot fault */
-   prefetchw(uaddr);
-   __ua_flags = uaccess_save_and_enable();
-   __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
-   "1: ldrex   %1, [%4]\n"
-   "   teq %1, %2\n"
-   "   ite eq  @ explicit IT needed for the 2b label\n"
-   "2: strexeq %0, %3, [%4]\n"
-   "   movne   %0, #0\n"
-   "   teq %0, #0\n"
-   "   bne 1b\n"
-   __futex_atomic_ex_table("%5")
-   : "=" (ret), "=" (val)
-   : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
-   : "cc", "memory");
-   uaccess_restore(__ua_flags);
-   smp_mb();
-
-   *uval = val;
-   return ret;
-}
+#define __futex_atomic_cmpxchg_op(ret, val, uaddr, oldval, newval) 
\
+({ 
\
+   unsigned int __ua_flags;
\
+   smp_mb();   
\
+   prefetchw(uaddr);   
\
+   __ua_flags = uaccess_save_and_enable(); 
\
+   __asm__ __volatile__(   
\
+   "1: ldrex   %1, [%4]\n" 
\
+   "   teq %1, %2\n"   
\
+   "   ite eq  @ explicit IT needed for the 2b label\n"
\
+   "2: strexeq %0, %3, [%4]\n" 
\
+   "   movne   %0, #0\n"   
\
+   "   teq %0, #0\n"   
\
+   "   bne 1b\n"   
\
+   __futex_atomic_ex_table("%5")   
\
+   : "=" (ret), "=" (val)  
\
+   : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)   
\
+   : "cc", "memory");  
\
+   uaccess_restore(__ua_flags);
\
+   smp_mb();   
\
+})
 
 #else /* !SMP, we can work around lack of atomic ops by disabling preemption */
 
@@ -82,7 +71,9 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
 
 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg)\
 ({ \
-   unsigned int __ua_flags = uaccess_save_and_enable();\
+   unsigned int __ua_flags;\
+   preempt_disable();  \
+   __ua_flags = uaccess_save_and_enable(); \
__asm__ __volatile__(   \
"1: " TUSER(ldr) "  %1, [%3]\n" \
"   " insn "\n" \
@@ -93,98 +84,72 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
: "r" (uaddr), "r" (oparg), "Ir" (-EFAULT)  \
: "cc", "memory");  \
uaccess_restore(__ua_flags);\
+   preempt_disable();  \
 })
 
-static inline int
-futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
- u32 oldval, u32 newval)
-{
-  

[PATCH 2/2] arm: futex: Use asm-generic/futex.h instead of redefining the entire header

2016-10-09 Thread Joel Porquet
"asm-generic/futex.h" was refactored and now allows arch ports to only
define arch-specific macros instead of redefining the entire header
file.

This patch adapts "asm/futex.h" for ARM by only defining the macros
required by the generic header (ie __futex_atomic_op_inuser() and
__futex_atomic_cmpxchg_inatomic()).

Compiled (SMP and !SMP) and booted on QEMU with a minimal busybox-based
system.

Signed-off-by: Joel Porquet 
---
 arch/arm/include/asm/futex.h | 203 ++-
 1 file changed, 84 insertions(+), 119 deletions(-)

diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
index 6795368..d3db562 100644
--- a/arch/arm/include/asm/futex.h
+++ b/arch/arm/include/asm/futex.h
@@ -39,41 +39,30 @@
: "r" (uaddr), "r" (oparg), "Ir" (-EFAULT)  \
: "cc", "memory");  \
uaccess_restore(__ua_flags);\
+   smp_mb();   \
 })
 
-static inline int
-futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
- u32 oldval, u32 newval)
-{
-   unsigned int __ua_flags;
-   int ret;
-   u32 val;
-
-   if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
-   return -EFAULT;
-
-   smp_mb();
-   /* Prefetching cannot fault */
-   prefetchw(uaddr);
-   __ua_flags = uaccess_save_and_enable();
-   __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
-   "1: ldrex   %1, [%4]\n"
-   "   teq %1, %2\n"
-   "   ite eq  @ explicit IT needed for the 2b label\n"
-   "2: strexeq %0, %3, [%4]\n"
-   "   movne   %0, #0\n"
-   "   teq %0, #0\n"
-   "   bne 1b\n"
-   __futex_atomic_ex_table("%5")
-   : "=" (ret), "=" (val)
-   : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
-   : "cc", "memory");
-   uaccess_restore(__ua_flags);
-   smp_mb();
-
-   *uval = val;
-   return ret;
-}
+#define __futex_atomic_cmpxchg_op(ret, val, uaddr, oldval, newval) 
\
+({ 
\
+   unsigned int __ua_flags;
\
+   smp_mb();   
\
+   prefetchw(uaddr);   
\
+   __ua_flags = uaccess_save_and_enable(); 
\
+   __asm__ __volatile__(   
\
+   "1: ldrex   %1, [%4]\n" 
\
+   "   teq %1, %2\n"   
\
+   "   ite eq  @ explicit IT needed for the 2b label\n"
\
+   "2: strexeq %0, %3, [%4]\n" 
\
+   "   movne   %0, #0\n"   
\
+   "   teq %0, #0\n"   
\
+   "   bne 1b\n"   
\
+   __futex_atomic_ex_table("%5")   
\
+   : "=" (ret), "=" (val)  
\
+   : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)   
\
+   : "cc", "memory");  
\
+   uaccess_restore(__ua_flags);
\
+   smp_mb();   
\
+})
 
 #else /* !SMP, we can work around lack of atomic ops by disabling preemption */
 
@@ -82,7 +71,9 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
 
 #define __futex_atomic_op(insn, ret, oldval, tmp, uaddr, oparg)\
 ({ \
-   unsigned int __ua_flags = uaccess_save_and_enable();\
+   unsigned int __ua_flags;\
+   preempt_disable();  \
+   __ua_flags = uaccess_save_and_enable(); \
__asm__ __volatile__(   \
"1: " TUSER(ldr) "  %1, [%3]\n" \
"   " insn "\n" \
@@ -93,98 +84,72 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
: "r" (uaddr), "r" (oparg), "Ir" (-EFAULT)  \
: "cc", "memory");  \
uaccess_restore(__ua_flags);\
+   preempt_disable();  \
 })
 
-static inline int
-futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
- u32 oldval, u32 newval)
-{
-   unsigned int 

Crypto Update for 4.9

2016-10-09 Thread Herbert Xu
Hi Linus:

Here is the crypto update for 4.9:

API:

* The crypto engine code now supports hashes.

Algorithms:

* Allow keys >= 2048 bits in FIPS mode for RSA.

Drivers:

* Memory overwrite fix for vmx ghash.
* Add support for building ARM sha1-neon in Thumb2 mode.
* Reenable ARM ghash-ce code by adding import/export.
* Reenable img-hash by adding import/export.
* Add support for multiple cores in omap-aes.
* Add little-endian support for sha1-powerpc.
* Add Cavium HWRNG driver for ThunderX SoC.


Please pull from

git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6.git linus


Ananth Jasty (1):
  PCI: quirk fixup for cavium invalid sriov link value.

Ard Biesheuvel (3):
  crypto: arm/sha1-neon - add support for building in Thumb2 mode
  crypto: arm/ghash-ce - add missing async import/export
  crypto: arm/ghash - change internal cra_name to "__ghash"

Arnd Bergmann (1):
  crypto: mv_cesa - remove NO_IRQ reference

Arvind Yadav (2):
  hwrng: bcm2835 - handle of_iomap failures
  crypto: caam - Unmap region obtained by of_iomap

Baoyou Xie (2):
  crypto: caam - add missing header dependencies
  crypto: sun4i-ss - mark sun4i_hash() static

Catalin Vasile (2):
  crypto: caam - fix rfc3686(ctr(aes)) IV load
  crypto: caam - fix sg dump

Corentin LABBE (17):
  crypto: xts - fix a little typo
  crypto: sun4i-ss - fix a few signed warning
  crypto: sun4i-ss - unify update/final function
  crypto: sun4i-ss - clean unused ss
  crypto: sun4i-ss - fix spelling
  crypto: sun4i-ss - Always use sun4i_tfm_ctx for storing pointer to dev ss
  crypto: sun4i-ss - fix indentation of two crypto alg
  hwrng: amd - Fix style problem with blank line
  hwrng: amd - use the BIT macro
  hwrng: amd - Be consitent with the driver name
  hwrng: amd - Remove asm/io.h
  hwrng: amd - release_region must be called after hwrng_unregister
  hwrng: amd - Replace global variable with private struct
  hwrng: amd - Access hardware via ioread32/iowrite32
  hwrng: amd - Convert to new hwrng read() API
  crypto: engine - move crypto engine to its own header
  crypto: engine - permit to enqueue ashash_request

Daniel Thompson (1):
  hwrng: core - Improve description of the ->read() interface

Dave Gerlach (1):
  hwrng: omap - Only fail if pm_runtime_get_sync returns < 0

Eric Biggers (1):
  crypto: doc - fix documentation for bulk registration functions

Fabio Estevam (1):
  crypto: mxc-scc - check clk_prepare_enable() error

Gary R Hook (13):
  crypto: ccp - Fix non-conforming comment style
  crypto: ccp - Abstract PCI info for the CCP
  crypto: ccp - Shorten the fields of the action structure
  crypto: ccp - Refactoring: symbol cleanup
  crypto: ccp - Refactor the storage block allocation code
  crypto: ccp - Refactor code supporting the CCP's RNG
  crypto: ccp - Refactor code to enable checks for queue space.
  crypto: ccp - Let a v5 CCP provide the same function as v3
  crypto: ccp - Add support for the RNG in a version 5 CCP
  crypto: ccp - Enable DMA service on a v5 CCP
  crypto: ccp - Enable use of the additional CCP
  crypto: ccp - clean up data structure
  crypto: ccp - Make syslog errors human-readable

Giovanni Cabiddu (1):
  crypto: qat - fix leak on error path

Govindraj Raja (1):
  crypto: img-hash - Add suspend resume hooks for img hash

Herbert Xu (4):
  crypto: xor - Fix warning when XOR_SELECT_TEMPLATE is unset
  crypto: algif_hash - Handle NULL hashes correctly
  PCI: Fix cavium quirk compile failure with PCI_ATS off
  Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

James Hartley (2):
  crypto: img-hash - Add support for export and import
  crypto: img-hash - log a successful probe

Jan Stancek (1):
  crypto: testmgr - add guard to dst buffer for ahash_export

Lokesh Vutla (2):
  crypto: omap-aes - Add support for multiple cores
  crypto: omap-aes - Add fallback support

Maksim Lukoshkov (2):
  crypto: qat - fix constants table DMA
  crypto: qat - fix incorrect accelerator mask for C3X devices

Marcelo Cerri (4):
  crypto: ghash-generic - move common definitions to a new header file
  crypto: vmx - Fix memory corruption caused by p8_ghash
  crypto: sha1-powerpc - little-endian support
  crypto: vmx - Ensure ghash-generic is enabled

Markus Elfring (7):
  hwrng: pic32 - Delete unnecessary assignment for the field "owner"
  crypto: caam - Use kmalloc_array() in ahash_setkey()
  crypto: caam - Rename jump labels in ahash_setkey()
  crypto: caam - Rename a jump label in five functions
  crypto: caam - Return a value directly in caam_hash_cra_init()
  crypto: caam - Delete an unnecessary initialisation in seven functions
  crypto: caam - Move common error handling code in two functions

Martin Schwidefsky (1):
  crypto: xor 

Crypto Update for 4.9

2016-10-09 Thread Herbert Xu
Hi Linus:

Here is the crypto update for 4.9:

API:

* The crypto engine code now supports hashes.

Algorithms:

* Allow keys >= 2048 bits in FIPS mode for RSA.

Drivers:

* Memory overwrite fix for vmx ghash.
* Add support for building ARM sha1-neon in Thumb2 mode.
* Reenable ARM ghash-ce code by adding import/export.
* Reenable img-hash by adding import/export.
* Add support for multiple cores in omap-aes.
* Add little-endian support for sha1-powerpc.
* Add Cavium HWRNG driver for ThunderX SoC.


Please pull from

git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6.git linus


Ananth Jasty (1):
  PCI: quirk fixup for cavium invalid sriov link value.

Ard Biesheuvel (3):
  crypto: arm/sha1-neon - add support for building in Thumb2 mode
  crypto: arm/ghash-ce - add missing async import/export
  crypto: arm/ghash - change internal cra_name to "__ghash"

Arnd Bergmann (1):
  crypto: mv_cesa - remove NO_IRQ reference

Arvind Yadav (2):
  hwrng: bcm2835 - handle of_iomap failures
  crypto: caam - Unmap region obtained by of_iomap

Baoyou Xie (2):
  crypto: caam - add missing header dependencies
  crypto: sun4i-ss - mark sun4i_hash() static

Catalin Vasile (2):
  crypto: caam - fix rfc3686(ctr(aes)) IV load
  crypto: caam - fix sg dump

Corentin LABBE (17):
  crypto: xts - fix a little typo
  crypto: sun4i-ss - fix a few signed warning
  crypto: sun4i-ss - unify update/final function
  crypto: sun4i-ss - clean unused ss
  crypto: sun4i-ss - fix spelling
  crypto: sun4i-ss - Always use sun4i_tfm_ctx for storing pointer to dev ss
  crypto: sun4i-ss - fix indentation of two crypto alg
  hwrng: amd - Fix style problem with blank line
  hwrng: amd - use the BIT macro
  hwrng: amd - Be consitent with the driver name
  hwrng: amd - Remove asm/io.h
  hwrng: amd - release_region must be called after hwrng_unregister
  hwrng: amd - Replace global variable with private struct
  hwrng: amd - Access hardware via ioread32/iowrite32
  hwrng: amd - Convert to new hwrng read() API
  crypto: engine - move crypto engine to its own header
  crypto: engine - permit to enqueue ashash_request

Daniel Thompson (1):
  hwrng: core - Improve description of the ->read() interface

Dave Gerlach (1):
  hwrng: omap - Only fail if pm_runtime_get_sync returns < 0

Eric Biggers (1):
  crypto: doc - fix documentation for bulk registration functions

Fabio Estevam (1):
  crypto: mxc-scc - check clk_prepare_enable() error

Gary R Hook (13):
  crypto: ccp - Fix non-conforming comment style
  crypto: ccp - Abstract PCI info for the CCP
  crypto: ccp - Shorten the fields of the action structure
  crypto: ccp - Refactoring: symbol cleanup
  crypto: ccp - Refactor the storage block allocation code
  crypto: ccp - Refactor code supporting the CCP's RNG
  crypto: ccp - Refactor code to enable checks for queue space.
  crypto: ccp - Let a v5 CCP provide the same function as v3
  crypto: ccp - Add support for the RNG in a version 5 CCP
  crypto: ccp - Enable DMA service on a v5 CCP
  crypto: ccp - Enable use of the additional CCP
  crypto: ccp - clean up data structure
  crypto: ccp - Make syslog errors human-readable

Giovanni Cabiddu (1):
  crypto: qat - fix leak on error path

Govindraj Raja (1):
  crypto: img-hash - Add suspend resume hooks for img hash

Herbert Xu (4):
  crypto: xor - Fix warning when XOR_SELECT_TEMPLATE is unset
  crypto: algif_hash - Handle NULL hashes correctly
  PCI: Fix cavium quirk compile failure with PCI_ATS off
  Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

James Hartley (2):
  crypto: img-hash - Add support for export and import
  crypto: img-hash - log a successful probe

Jan Stancek (1):
  crypto: testmgr - add guard to dst buffer for ahash_export

Lokesh Vutla (2):
  crypto: omap-aes - Add support for multiple cores
  crypto: omap-aes - Add fallback support

Maksim Lukoshkov (2):
  crypto: qat - fix constants table DMA
  crypto: qat - fix incorrect accelerator mask for C3X devices

Marcelo Cerri (4):
  crypto: ghash-generic - move common definitions to a new header file
  crypto: vmx - Fix memory corruption caused by p8_ghash
  crypto: sha1-powerpc - little-endian support
  crypto: vmx - Ensure ghash-generic is enabled

Markus Elfring (7):
  hwrng: pic32 - Delete unnecessary assignment for the field "owner"
  crypto: caam - Use kmalloc_array() in ahash_setkey()
  crypto: caam - Rename jump labels in ahash_setkey()
  crypto: caam - Rename a jump label in five functions
  crypto: caam - Return a value directly in caam_hash_cra_init()
  crypto: caam - Delete an unnecessary initialisation in seven functions
  crypto: caam - Move common error handling code in two functions

Martin Schwidefsky (1):
  crypto: xor 

Re: [tpmdd-devel] [PATCH RFC 1/3] tpm_crb: expand struct crb_control_area to struct crb_regs

2016-10-09 Thread Jason Gunthorpe
On Mon, Oct 10, 2016 at 12:25:11AM +, Winkler, Tomas wrote:

> I addition I believe it should be always on offset FED4_0xxxh by the
> Spec, so all this arithmetic is a bit of overkill.

We don't have any hard coded addresses in the drivers - that seems
very inappropriate these days..

Is that address really not discoverable via ACPI somehow?

Jason


Re: [tpmdd-devel] [PATCH RFC 1/3] tpm_crb: expand struct crb_control_area to struct crb_regs

2016-10-09 Thread Jason Gunthorpe
On Mon, Oct 10, 2016 at 12:25:11AM +, Winkler, Tomas wrote:

> I addition I believe it should be always on offset FED4_0xxxh by the
> Spec, so all this arithmetic is a bit of overkill.

We don't have any hard coded addresses in the drivers - that seems
very inappropriate these days..

Is that address really not discoverable via ACPI somehow?

Jason


Re: [PATCH] mfd: Add HiSilicon Flash Memory Controller(FMC) driver

2016-10-09 Thread linshunquan (A)


On 2016/9/15 5:56, Rob Herring wrote:
> On Wed, Sep 14, 2016 at 4:12 AM, linshunquan (A)
>  wrote:
>>
>>
>> On 2016/9/13 22:56, Rob Herring wrote:
>>> On Tue, Sep 06, 2016 at 10:57:22AM +0800, linshunquan 00354166 wrote:
 From: Shunquan Lin 

 This patch adds driver support for HiSilicon Flash Memory
 Controller(FMC). HiSilicon FMC is a multi-functions device which
 supports SPI Nor flash controller, SPI nand Flash controller and
 parallel nand flash controller.

 Signed-off-by: Shunquan Lin 
 +- spi-nor:
 +Required properties:
 +- compatible : "hisilicon,fmc-spi-nor"
 +see "Documentation/devicetree/bindings/mtd/hisilicon,fmc-spi-nor.txt
 +
 +- spi-nand:
 +Required properties:
 +- compatible : "hisilicon,fmc-spi-nand"
 +- reg : The chipselect for spi-nand devices
 +- address-cells : Should be 1.
 +- size-cells : Should be 0.
 +
 +- nand:
 +Required properties:
 +- compatible : "hisilicon,fmc-nand"
 +- reg : The chipselect for nand devices
 +- address-cells : Should be 1.
 +- size-cells : Should be 0.
 +
 +Example:
 +fmc: spi-nor-controller@1000 {
 + compatible = "hisilicon,hisi-fmc";
 + reg = <0x1000 0x1000>, <0x1400 0x100>;
 + reg-names = "control", "memory";
 + clocks = < FMC_CLK>;
 + #address-cells = <1>;
 + #size-cells = <0>;
 +
 + hisfc:spi-nor@0 {
 +   compatible = "hisilicon,fmc-spi-nor";
>>>
>>> Is this an actual h/w sub-block? If not remove this node and make the
>>> spi-nor the immediate child.
>>>
>>
>> Hi Herring,
>> Thanks for your reply. Firstly I must correct a mistake here:
>>  fmc: spi-nor-controller@1000 {
>>  compatible = "hisilicon,hisi-fmc";
>> ...
>>   correct to:
>>  fmc: flash-memory-controller@1000 {
>>  compatible = "hisilicon,hisi-fmc";
>> ...
>>
>> Spi-nor is a sub block of HiSilicon Flash Memory Controller(FMC), HiSilicon 
>> FMC
>> is a multi-functions device, besides it also supports SPI Nand and Parallel 
>> Nand.
> 
> I understand that, but then were are the registers for the sub-blocks?
> If there is only a single set of chipselects for all devices (i.e. 0
> to N) and no separate register blocks for the sub-blocks, then you
> don't need this intermediate node.
> 

Hi Rob,
I'm sorry it's taken me so long to get back to you.

To the HiSilicon FMC, different devices have different chipselect, and you are 
right,
the register blocks are no separate, but spi nor, spi nand and nand may require
different initial configuration of default sublock clocks and clock 
frequencies, so
I think this node is necessary.

Here is a sample about the soc Hi3519:

in arch/arm/boot/dts/hi3519.dtsi defined:

fmc: flash-memory-controller@1000 {
compatible = "hisilicon,hisi-fmc";
reg = <0x1000 0x1000>, <0x1400 0x100>;
reg-names = "control", "memory";
clocks = < HI3519_FMC_CLK>;
#address-cells = <1>;
#size-cells = <0>;

hisfc:spi-nor {
compatible = "hisilicon,hisi-sfc";
assigned-clocks = < HI3519_FMC_CLK>;
assigned-clock-rates = <2400>;
#address-cells = <1>;
#size-cells = <0>;
};

hisnfc:spi-nand {
compatible = "hisilicon,fmc-spi-nand";
assigned-clocks = < HI3519_FMC_CLK>;
assigned-clock-rates = <300>;
#address-cells = <1>;
#size-cells = <0>;
};
};

in arch/arm/boot/dts/hi3519-demb.dts, which include hi3519.disi, defined:

 {
hi_sfc@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <16000>;
m25p,fast-read;
};
};

 {
hinand@0 {
compatible = "jedec,spi-nand";
reg = <0>;
spi-max-frequency = <2>;
};
};

Maybe I have not well understood on DTS, I hope I can get some suggestions from 
Rob.

Best regards
/Shunquan Lin



Re: [PATCH] mfd: Add HiSilicon Flash Memory Controller(FMC) driver

2016-10-09 Thread linshunquan (A)


On 2016/9/15 5:56, Rob Herring wrote:
> On Wed, Sep 14, 2016 at 4:12 AM, linshunquan (A)
>  wrote:
>>
>>
>> On 2016/9/13 22:56, Rob Herring wrote:
>>> On Tue, Sep 06, 2016 at 10:57:22AM +0800, linshunquan 00354166 wrote:
 From: Shunquan Lin 

 This patch adds driver support for HiSilicon Flash Memory
 Controller(FMC). HiSilicon FMC is a multi-functions device which
 supports SPI Nor flash controller, SPI nand Flash controller and
 parallel nand flash controller.

 Signed-off-by: Shunquan Lin 
 +- spi-nor:
 +Required properties:
 +- compatible : "hisilicon,fmc-spi-nor"
 +see "Documentation/devicetree/bindings/mtd/hisilicon,fmc-spi-nor.txt
 +
 +- spi-nand:
 +Required properties:
 +- compatible : "hisilicon,fmc-spi-nand"
 +- reg : The chipselect for spi-nand devices
 +- address-cells : Should be 1.
 +- size-cells : Should be 0.
 +
 +- nand:
 +Required properties:
 +- compatible : "hisilicon,fmc-nand"
 +- reg : The chipselect for nand devices
 +- address-cells : Should be 1.
 +- size-cells : Should be 0.
 +
 +Example:
 +fmc: spi-nor-controller@1000 {
 + compatible = "hisilicon,hisi-fmc";
 + reg = <0x1000 0x1000>, <0x1400 0x100>;
 + reg-names = "control", "memory";
 + clocks = < FMC_CLK>;
 + #address-cells = <1>;
 + #size-cells = <0>;
 +
 + hisfc:spi-nor@0 {
 +   compatible = "hisilicon,fmc-spi-nor";
>>>
>>> Is this an actual h/w sub-block? If not remove this node and make the
>>> spi-nor the immediate child.
>>>
>>
>> Hi Herring,
>> Thanks for your reply. Firstly I must correct a mistake here:
>>  fmc: spi-nor-controller@1000 {
>>  compatible = "hisilicon,hisi-fmc";
>> ...
>>   correct to:
>>  fmc: flash-memory-controller@1000 {
>>  compatible = "hisilicon,hisi-fmc";
>> ...
>>
>> Spi-nor is a sub block of HiSilicon Flash Memory Controller(FMC), HiSilicon 
>> FMC
>> is a multi-functions device, besides it also supports SPI Nand and Parallel 
>> Nand.
> 
> I understand that, but then were are the registers for the sub-blocks?
> If there is only a single set of chipselects for all devices (i.e. 0
> to N) and no separate register blocks for the sub-blocks, then you
> don't need this intermediate node.
> 

Hi Rob,
I'm sorry it's taken me so long to get back to you.

To the HiSilicon FMC, different devices have different chipselect, and you are 
right,
the register blocks are no separate, but spi nor, spi nand and nand may require
different initial configuration of default sublock clocks and clock 
frequencies, so
I think this node is necessary.

Here is a sample about the soc Hi3519:

in arch/arm/boot/dts/hi3519.dtsi defined:

fmc: flash-memory-controller@1000 {
compatible = "hisilicon,hisi-fmc";
reg = <0x1000 0x1000>, <0x1400 0x100>;
reg-names = "control", "memory";
clocks = < HI3519_FMC_CLK>;
#address-cells = <1>;
#size-cells = <0>;

hisfc:spi-nor {
compatible = "hisilicon,hisi-sfc";
assigned-clocks = < HI3519_FMC_CLK>;
assigned-clock-rates = <2400>;
#address-cells = <1>;
#size-cells = <0>;
};

hisnfc:spi-nand {
compatible = "hisilicon,fmc-spi-nand";
assigned-clocks = < HI3519_FMC_CLK>;
assigned-clock-rates = <300>;
#address-cells = <1>;
#size-cells = <0>;
};
};

in arch/arm/boot/dts/hi3519-demb.dts, which include hi3519.disi, defined:

 {
hi_sfc@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <16000>;
m25p,fast-read;
};
};

 {
hinand@0 {
compatible = "jedec,spi-nand";
reg = <0>;
spi-max-frequency = <2>;
};
};

Maybe I have not well understood on DTS, I hope I can get some suggestions from 
Rob.

Best regards
/Shunquan Lin



Re: net: BUG still has locks held in unix_stream_splice_read

2016-10-09 Thread Al Viro
On Mon, Oct 10, 2016 at 03:46:07AM +0100, Al Viro wrote:
> On Sun, Oct 09, 2016 at 12:06:14PM +0200, Dmitry Vyukov wrote:
> > I suspect this is:
> > 
> > commit 25869262ef7af24ccde988867ac3eb1c3d4b88d4
> > Author: Al Viro 
> > Date:   Sat Sep 17 21:02:10 2016 -0400
> > skb_splice_bits(): get rid of callback
> > since pipe_lock is the outermost now, we don't need to drop/regain
> > socket locks around the call of splice_to_pipe() from skb_splice_bits(),
> > which kills the need to have a socket-specific callback; we can just
> > call splice_to_pipe() and be done with that.
> 
> Unlikely, since that particular commit removes unlocking/relocking ->iolock
> around the call of splice_to_pipe().  Original would've retaken the same
> lock on the way out; it's not as if we could leave the syscall there.
> 
> It might be splice-related, but I don't believe that you've got the right
> commit here.

It's not that commit, all right - it's "can't call unix_stream_read_generic()
with any locks held" stepped onto a couple of commits prior by
"splice: lift pipe_lock out of splice_to_pipe()".  Could somebody explain
what is that about?

E.g what will happen if some code does a read on AF_UNIX socket with
some local mutex held?  AFAICS, there are exactly two callers of
freezable_schedule_timeout() - this one and one in XFS; the latter is
in a kernel thread where we do have good warranties about the locking
environment, but here it's in the bleeding ->recvmsg/->splice_read and
for those assumption that caller doesn't hold any locks is pretty
strong, especially since it's not documented anywhere.

What's going on there?


Re: net: BUG still has locks held in unix_stream_splice_read

2016-10-09 Thread Al Viro
On Mon, Oct 10, 2016 at 03:46:07AM +0100, Al Viro wrote:
> On Sun, Oct 09, 2016 at 12:06:14PM +0200, Dmitry Vyukov wrote:
> > I suspect this is:
> > 
> > commit 25869262ef7af24ccde988867ac3eb1c3d4b88d4
> > Author: Al Viro 
> > Date:   Sat Sep 17 21:02:10 2016 -0400
> > skb_splice_bits(): get rid of callback
> > since pipe_lock is the outermost now, we don't need to drop/regain
> > socket locks around the call of splice_to_pipe() from skb_splice_bits(),
> > which kills the need to have a socket-specific callback; we can just
> > call splice_to_pipe() and be done with that.
> 
> Unlikely, since that particular commit removes unlocking/relocking ->iolock
> around the call of splice_to_pipe().  Original would've retaken the same
> lock on the way out; it's not as if we could leave the syscall there.
> 
> It might be splice-related, but I don't believe that you've got the right
> commit here.

It's not that commit, all right - it's "can't call unix_stream_read_generic()
with any locks held" stepped onto a couple of commits prior by
"splice: lift pipe_lock out of splice_to_pipe()".  Could somebody explain
what is that about?

E.g what will happen if some code does a read on AF_UNIX socket with
some local mutex held?  AFAICS, there are exactly two callers of
freezable_schedule_timeout() - this one and one in XFS; the latter is
in a kernel thread where we do have good warranties about the locking
environment, but here it's in the bleeding ->recvmsg/->splice_read and
for those assumption that caller doesn't hold any locks is pretty
strong, especially since it's not documented anywhere.

What's going on there?


Attn: Sir/Madam

2016-10-09 Thread Barr, Adam Ibrahim
Attn: Sir/Madam

I am Honourable Barrister, Adam Ibrahim, the personal resident
Attorney here in Burkina Faso to Late Mr. Muammar Muhammad Abu Minyar
al-Gaddafi of Libya c. 1942 – 20 October 2011.

Late Mr. Muammar Muhammad Abu Minyar al-Gaddafi has a deposit sum of
($30.4M USD) only with a security finance clearing house affiliated
with African development bank Burkina Faso.

With the above explanation’s I want us to move this money from Burkina
Faso to your country or any destination you chooses as a deal and
after transfer we share the money, kindly contact me with this email
address: ( barradami...@gmail.com )

Thanks,
Honourable Barrister, Adam Ibrahim.


Attn: Sir/Madam

2016-10-09 Thread Barr, Adam Ibrahim
Attn: Sir/Madam

I am Honourable Barrister, Adam Ibrahim, the personal resident
Attorney here in Burkina Faso to Late Mr. Muammar Muhammad Abu Minyar
al-Gaddafi of Libya c. 1942 – 20 October 2011.

Late Mr. Muammar Muhammad Abu Minyar al-Gaddafi has a deposit sum of
($30.4M USD) only with a security finance clearing house affiliated
with African development bank Burkina Faso.

With the above explanation’s I want us to move this money from Burkina
Faso to your country or any destination you chooses as a deal and
after transfer we share the money, kindly contact me with this email
address: ( barradami...@gmail.com )

Thanks,
Honourable Barrister, Adam Ibrahim.


I Hope You Get My Message This Time

2016-10-09 Thread Friedrich Mayrhofer



-- 
This is the second time i am sending you this mail.

I, Friedrich Mayrhofer Donate $ 1,000,000.00 to You, Email  Me personally
for more details.

Regards.
Friedrich Mayrhofer



I Hope You Get My Message This Time

2016-10-09 Thread Friedrich Mayrhofer



-- 
This is the second time i am sending you this mail.

I, Friedrich Mayrhofer Donate $ 1,000,000.00 to You, Email  Me personally
for more details.

Regards.
Friedrich Mayrhofer



Re: Change CONFIG_DEVKMEM default value to n

2016-10-09 Thread Dave Young
On 10/10/16 at 10:44am, Dave Young wrote:
> On 10/07/16 at 05:57am, Greg Kroah-Hartman wrote:
> > On Fri, Oct 07, 2016 at 10:04:11AM +0800, Dave Young wrote:
> > > Kconfig comment suggests setting it as "n" if in doubt thus move the
> > > default value to 'n'.
> > > 
> > > Signed-off-by: Dave Young 
> > > Suggested-by: Kees Cook 
> > > ---
> > >  drivers/char/Kconfig |2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > --- linux-x86.orig/drivers/char/Kconfig
> > > +++ linux-x86/drivers/char/Kconfig
> > > @@ -17,7 +17,7 @@ config DEVMEM
> > >  
> > >  config DEVKMEM
> > >   bool "/dev/kmem virtual device support"
> > > - default y
> > > + default n
> > 
> > If you remove the "default" line, it defaults to 'n'.
> 
> I personally perfer a "default n", but I can update it..

Greg, here is an update with dropping the default line:

Move CONFIG_DEVKMEM default to n

Kconfig comment suggests setting it as "n" if in doubt thus move the
default value to 'n'.

Signed-off-by: Dave Young 
Suggested-by: Kees Cook 
---
 drivers/char/Kconfig |1 -
 1 file changed, 1 deletion(-)

--- linux-x86.orig/drivers/char/Kconfig
+++ linux-x86/drivers/char/Kconfig
@@ -17,7 +17,6 @@ config DEVMEM
 
 config DEVKMEM
bool "/dev/kmem virtual device support"
-   default y
help
  Say Y here if you want to support the /dev/kmem device. The
  /dev/kmem device is rarely used, but can be used for certain


Re: Change CONFIG_DEVKMEM default value to n

2016-10-09 Thread Dave Young
On 10/10/16 at 10:44am, Dave Young wrote:
> On 10/07/16 at 05:57am, Greg Kroah-Hartman wrote:
> > On Fri, Oct 07, 2016 at 10:04:11AM +0800, Dave Young wrote:
> > > Kconfig comment suggests setting it as "n" if in doubt thus move the
> > > default value to 'n'.
> > > 
> > > Signed-off-by: Dave Young 
> > > Suggested-by: Kees Cook 
> > > ---
> > >  drivers/char/Kconfig |2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > --- linux-x86.orig/drivers/char/Kconfig
> > > +++ linux-x86/drivers/char/Kconfig
> > > @@ -17,7 +17,7 @@ config DEVMEM
> > >  
> > >  config DEVKMEM
> > >   bool "/dev/kmem virtual device support"
> > > - default y
> > > + default n
> > 
> > If you remove the "default" line, it defaults to 'n'.
> 
> I personally perfer a "default n", but I can update it..

Greg, here is an update with dropping the default line:

Move CONFIG_DEVKMEM default to n

Kconfig comment suggests setting it as "n" if in doubt thus move the
default value to 'n'.

Signed-off-by: Dave Young 
Suggested-by: Kees Cook 
---
 drivers/char/Kconfig |1 -
 1 file changed, 1 deletion(-)

--- linux-x86.orig/drivers/char/Kconfig
+++ linux-x86/drivers/char/Kconfig
@@ -17,7 +17,6 @@ config DEVMEM
 
 config DEVKMEM
bool "/dev/kmem virtual device support"
-   default y
help
  Say Y here if you want to support the /dev/kmem device. The
  /dev/kmem device is rarely used, but can be used for certain


Re: slab corruption with current -git (was Re: [git pull] vfs pile 1 (splice))

2016-10-09 Thread Linus Torvalds
On Sun, Oct 9, 2016 at 6:35 PM, Aaron Conole  wrote:
>
> I was just about to build and test something similar:

So I haven't actually tested that one, but looking at the code, it
really looks very bogus. In fact, that code just looks like crap. It
does *not* do a proper "remove singly linked list entry". It's exactly
the kind of code that I rail against, and that people should never
write.

Any code that can't even traverse a linked list is not worth looking at.

There is one *correct* way to remove an entry from a singly linked
list, and it looks like this:

struct entry **pp, *p;

pp = 
while ((p = *pp) != NULL) {
if (right_entry(p)) {
*pp = p->next;
break;
}
pp = >next;
}

and that's it. Nothing else. The above code exits the loop with "p"
containing the entry that was removed, or NULL if nothing was. It
can't get any simpler than that, but more importantly, anything more
complicated than that is WRONG.

Seriously, nothing else is acceptable. In particular, any linked list
traversal that makes a special case of the first entry or the last
entry should not be allowed to exist. Note how there is not a single
special case in the above correct code. It JustWorks(tm).

That nf_unregister_net_hook() code has all the signs of exactly that
kind of broken list-handling code: special-casing the head of the
loop, and having the loop condition test both current and that odd
"next to next" pointer etc. It's all very very wrong.

So I really see two options:

 - do that singly-linked list traversal right (and I'm serious:
nothing but the code above can ever be right)

 - don't make up your own list handling code at all, and use the
standard linux list code.

So either e3b37f11e6e4 needs to be reverted, or it needs to be taught
to use real list handling.  If the code doesn't want to use the
regular list.h (either the doubly linked one, or the hlist one), it
needs to at least learn to do list removal right.

   Linus


Re: slab corruption with current -git (was Re: [git pull] vfs pile 1 (splice))

2016-10-09 Thread Linus Torvalds
On Sun, Oct 9, 2016 at 6:35 PM, Aaron Conole  wrote:
>
> I was just about to build and test something similar:

So I haven't actually tested that one, but looking at the code, it
really looks very bogus. In fact, that code just looks like crap. It
does *not* do a proper "remove singly linked list entry". It's exactly
the kind of code that I rail against, and that people should never
write.

Any code that can't even traverse a linked list is not worth looking at.

There is one *correct* way to remove an entry from a singly linked
list, and it looks like this:

struct entry **pp, *p;

pp = 
while ((p = *pp) != NULL) {
if (right_entry(p)) {
*pp = p->next;
break;
}
pp = >next;
}

and that's it. Nothing else. The above code exits the loop with "p"
containing the entry that was removed, or NULL if nothing was. It
can't get any simpler than that, but more importantly, anything more
complicated than that is WRONG.

Seriously, nothing else is acceptable. In particular, any linked list
traversal that makes a special case of the first entry or the last
entry should not be allowed to exist. Note how there is not a single
special case in the above correct code. It JustWorks(tm).

That nf_unregister_net_hook() code has all the signs of exactly that
kind of broken list-handling code: special-casing the head of the
loop, and having the loop condition test both current and that odd
"next to next" pointer etc. It's all very very wrong.

So I really see two options:

 - do that singly-linked list traversal right (and I'm serious:
nothing but the code above can ever be right)

 - don't make up your own list handling code at all, and use the
standard linux list code.

So either e3b37f11e6e4 needs to be reverted, or it needs to be taught
to use real list handling.  If the code doesn't want to use the
regular list.h (either the doubly linked one, or the hlist one), it
needs to at least learn to do list removal right.

   Linus


Re: net: BUG still has locks held in unix_stream_splice_read

2016-10-09 Thread Al Viro
On Sun, Oct 09, 2016 at 12:06:14PM +0200, Dmitry Vyukov wrote:
> I suspect this is:
> 
> commit 25869262ef7af24ccde988867ac3eb1c3d4b88d4
> Author: Al Viro 
> Date:   Sat Sep 17 21:02:10 2016 -0400
> skb_splice_bits(): get rid of callback
> since pipe_lock is the outermost now, we don't need to drop/regain
> socket locks around the call of splice_to_pipe() from skb_splice_bits(),
> which kills the need to have a socket-specific callback; we can just
> call splice_to_pipe() and be done with that.

Unlikely, since that particular commit removes unlocking/relocking ->iolock
around the call of splice_to_pipe().  Original would've retaken the same
lock on the way out; it's not as if we could leave the syscall there.

It might be splice-related, but I don't believe that you've got the right
commit here.


Re: net: BUG still has locks held in unix_stream_splice_read

2016-10-09 Thread Al Viro
On Sun, Oct 09, 2016 at 12:06:14PM +0200, Dmitry Vyukov wrote:
> I suspect this is:
> 
> commit 25869262ef7af24ccde988867ac3eb1c3d4b88d4
> Author: Al Viro 
> Date:   Sat Sep 17 21:02:10 2016 -0400
> skb_splice_bits(): get rid of callback
> since pipe_lock is the outermost now, we don't need to drop/regain
> socket locks around the call of splice_to_pipe() from skb_splice_bits(),
> which kills the need to have a socket-specific callback; we can just
> call splice_to_pipe() and be done with that.

Unlikely, since that particular commit removes unlocking/relocking ->iolock
around the call of splice_to_pipe().  Original would've retaken the same
lock on the way out; it's not as if we could leave the syscall there.

It might be splice-related, but I don't believe that you've got the right
commit here.


Re: Change CONFIG_DEVKMEM default value to n

2016-10-09 Thread Dave Young
On 10/07/16 at 05:57am, Greg Kroah-Hartman wrote:
> On Fri, Oct 07, 2016 at 10:04:11AM +0800, Dave Young wrote:
> > Kconfig comment suggests setting it as "n" if in doubt thus move the
> > default value to 'n'.
> > 
> > Signed-off-by: Dave Young 
> > Suggested-by: Kees Cook 
> > ---
> >  drivers/char/Kconfig |2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > --- linux-x86.orig/drivers/char/Kconfig
> > +++ linux-x86/drivers/char/Kconfig
> > @@ -17,7 +17,7 @@ config DEVMEM
> >  
> >  config DEVKMEM
> > bool "/dev/kmem virtual device support"
> > -   default y
> > +   default n
> 
> If you remove the "default" line, it defaults to 'n'.

I personally perfer a "default n", but I can update it..

> 
> And is it really "safe" to default this to n now?

There is an old article here:
https://lwn.net/Articles/147901/

AFAIK Distributions like Fedora/Debian has disabled it for long time.
If one really need it he can still enable it in his own config file.

> 
> thanks,
> 
> greg k-h

Thanks
Dave


Re: Change CONFIG_DEVKMEM default value to n

2016-10-09 Thread Dave Young
On 10/07/16 at 05:57am, Greg Kroah-Hartman wrote:
> On Fri, Oct 07, 2016 at 10:04:11AM +0800, Dave Young wrote:
> > Kconfig comment suggests setting it as "n" if in doubt thus move the
> > default value to 'n'.
> > 
> > Signed-off-by: Dave Young 
> > Suggested-by: Kees Cook 
> > ---
> >  drivers/char/Kconfig |2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > --- linux-x86.orig/drivers/char/Kconfig
> > +++ linux-x86/drivers/char/Kconfig
> > @@ -17,7 +17,7 @@ config DEVMEM
> >  
> >  config DEVKMEM
> > bool "/dev/kmem virtual device support"
> > -   default y
> > +   default n
> 
> If you remove the "default" line, it defaults to 'n'.

I personally perfer a "default n", but I can update it..

> 
> And is it really "safe" to default this to n now?

There is an old article here:
https://lwn.net/Articles/147901/

AFAIK Distributions like Fedora/Debian has disabled it for long time.
If one really need it he can still enable it in his own config file.

> 
> thanks,
> 
> greg k-h

Thanks
Dave


[PATCH 0/2] make asm-generic/futex.h usable for more arch ports

2016-10-09 Thread Joel Porquet
Hi all,

I've had a patch on my shelf for a couple of years, from when I ported Linux on
a new processor architecture for an academic project, and thought I could send
it and let you decide if it's worth taking or not.

During my port, I basically modified the generic header "asm-generic/futex.h"
and made it into a more generic version so that I could include it in my code
and only redefine the necessary arch-specific bits.

Right now, most of the arch ports redefine their own "asm/futex.h" completely
although, for example for "futex_atomic_op_inuser()", they often share the exact
same preamble and epilogue and could benefit from some code refactoring.

My (short) series is made of two patches: 1/ refactoring "asm-generic/futex.h"
in order to make the arch-specific routines into overload-able macros that arch
ports can redefine when required, 2/ an example of how to use this refactoring
with the ARM port.

Let me know what you think.

Cheers,
Joël

Joel Porquet (2):
  asm-generic/futex.h: code refactoring
  arm: futex: Use asm-generic/futex.h instead of redefining the entire
header

 arch/arm/include/asm/futex.h | 203 +--
 include/asm-generic/futex.h  | 219 ++-
 2 files changed, 196 insertions(+), 226 deletions(-)

-- 
2.10.0



[PATCH 0/2] make asm-generic/futex.h usable for more arch ports

2016-10-09 Thread Joel Porquet
Hi all,

I've had a patch on my shelf for a couple of years, from when I ported Linux on
a new processor architecture for an academic project, and thought I could send
it and let you decide if it's worth taking or not.

During my port, I basically modified the generic header "asm-generic/futex.h"
and made it into a more generic version so that I could include it in my code
and only redefine the necessary arch-specific bits.

Right now, most of the arch ports redefine their own "asm/futex.h" completely
although, for example for "futex_atomic_op_inuser()", they often share the exact
same preamble and epilogue and could benefit from some code refactoring.

My (short) series is made of two patches: 1/ refactoring "asm-generic/futex.h"
in order to make the arch-specific routines into overload-able macros that arch
ports can redefine when required, 2/ an example of how to use this refactoring
with the ARM port.

Let me know what you think.

Cheers,
Joël

Joel Porquet (2):
  asm-generic/futex.h: code refactoring
  arm: futex: Use asm-generic/futex.h instead of redefining the entire
header

 arch/arm/include/asm/futex.h | 203 +--
 include/asm-generic/futex.h  | 219 ++-
 2 files changed, 196 insertions(+), 226 deletions(-)

-- 
2.10.0



[ANNOUNCE] iproute 4.8

2016-10-09 Thread Stephen Hemminger
Release of iproute2 for Linux 4.8, slightly late because of netdev.

Update to iproute2 utility to support new features in Linux 4.8.
Includes support for MACSEC and ILA.
Plus the usual array of documentation and minor fixes.

Source:
  http://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-4.8.0.tar.gz

Repository:
  git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git

Report problems (or enhancements) to the net...@vger.kernel.org mailing list.

---
Andrey Jr. Melnikov (1):
  iproute: disallow ip rule del without parameters

David Ahern (1):
  ip rule: Add support for l3mdev rules

Davide Caratti (5):
  macsec: fix input of 'port', improve documentation of 'address'
  man: ip.8: add missing 'macsec' item to OBJECT list
  macsec: fix byte ordering on input/display of 'sci'
  tc: don't accept qdisc 'handle' greater than 
  macsec: fix input range of 'icvlen' parameter

Eric Dumazet (1):
  ip: report IFLA_GSO_MAX_SIZE and IFLA_GSO_MAX_SEGS

Gustavo Zacarias (1):
  ss: fix build with musl libc

Hangbin Liu (5):
  nstat: add sctp snmp support
  gitignore: Ignore 'tags' file generated by ctags
  ip route: check ftell, fseek return value
  misc/ss: tcp cwnd should be unsigned
  ip: Use specific slave id

Hannes Frederic Sowa (1):
  iptuntap: show processes using tuntap interface

Igor Ryzhov (1):
  fix netlink message length checks

Iskren Chernev (1):
  iproute: fix documentation for ip rule scan order

Jamal Hadi Salim (2):
  actions: skbedit add support for mod-ing skb pkt_type
  tc classifiers: Modernize tcindex classifier

Jiri Benc (2):
  vxlan: group address requires net device
  tunnels: use macros for IPv6 address comparison

Liping Zhang (1):
  ipmonitor: fix ip monitor can't work when NET_NS is not enabled

Nikolay Aleksandrov (1):
  ip: route: fix multicast route dumps

Or Gerlitz (1):
  devlink: Add e-switch support

Phil Sutter (4):
  man: ip-link.8: Document missing geneve options
  ip-link: add missing {min,max}_tx_rate to help text
  ip-route: Prevent some double spaces in output
  iproute: fix documentation for ip rule scan order

Richard Alpe (2):
  tipc: fix UDP bearer synopsis
  tipc: refactor bearer identification

Roman Mashak (3):
  police: add extra space to improve police result printing
  police: improve usage message
  police: bug fix man page

Roopa Prabhu (2):
  bridge: print_vlan: add missing check for json instance
  bridge: print_vlan: add missing check for json instance

Sabrina Dubroca (4):
  libgenl: introduce genl_init_handle
  macsec: show usage even if the module is not available
  fou: show usage even if the module is not available
  ila: show usage even if the module is not available

Simon Horman (1):
  iproute2: correct port in FOU/GRE example

Stephen Hemminger (14):
  minor header update from net-next
  fib_rules.h update header file
  iprule: whitespace cleanup
  update kernel headers (net-next)
  update kernel header (4.7 net-next)
  update headers files to current net-next
  include: update net-next XDP headers
  update kernel headers
  update BPF headers
  devlink: whitespace cleanup
  remove useless return statement
  ip: iptuntap cleanup
  update kernel headers from 4.8-rc4
  v4.8.0

Sushma Sitaram (1):
  tc: f_u32: Fill in 'linkid' provided by user

Thomas Graf (1):
  tuntap: Add name attribute to usage text

Tom Herbert (6):
  ila: Support for checksum neutral translation
  ila: Support for configuring ila to use netfilter hook
  ip6tnl: Support for fou encapsulation
  gre6: Support for fou encapsulation
  fou: Allowing configuring IPv6 listener
  ipila: Fixed unitialized variables

WANG Cong (1):
  tc: fix a misleading failure

Xin Long (1):
  ip route: restore_handler should check tb[RTA_PREFSRC] for local networks

Yotam Gigi (2):
  tc: Add support for the matchall traffic classifier.
  tc: man: Add man entry for the matchall classifier.

anuradhak (1):
  bridge: Fix garbled json output seen if a vlan filter is specified



[ANNOUNCE] iproute 4.8

2016-10-09 Thread Stephen Hemminger
Release of iproute2 for Linux 4.8, slightly late because of netdev.

Update to iproute2 utility to support new features in Linux 4.8.
Includes support for MACSEC and ILA.
Plus the usual array of documentation and minor fixes.

Source:
  http://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-4.8.0.tar.gz

Repository:
  git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git

Report problems (or enhancements) to the net...@vger.kernel.org mailing list.

---
Andrey Jr. Melnikov (1):
  iproute: disallow ip rule del without parameters

David Ahern (1):
  ip rule: Add support for l3mdev rules

Davide Caratti (5):
  macsec: fix input of 'port', improve documentation of 'address'
  man: ip.8: add missing 'macsec' item to OBJECT list
  macsec: fix byte ordering on input/display of 'sci'
  tc: don't accept qdisc 'handle' greater than 
  macsec: fix input range of 'icvlen' parameter

Eric Dumazet (1):
  ip: report IFLA_GSO_MAX_SIZE and IFLA_GSO_MAX_SEGS

Gustavo Zacarias (1):
  ss: fix build with musl libc

Hangbin Liu (5):
  nstat: add sctp snmp support
  gitignore: Ignore 'tags' file generated by ctags
  ip route: check ftell, fseek return value
  misc/ss: tcp cwnd should be unsigned
  ip: Use specific slave id

Hannes Frederic Sowa (1):
  iptuntap: show processes using tuntap interface

Igor Ryzhov (1):
  fix netlink message length checks

Iskren Chernev (1):
  iproute: fix documentation for ip rule scan order

Jamal Hadi Salim (2):
  actions: skbedit add support for mod-ing skb pkt_type
  tc classifiers: Modernize tcindex classifier

Jiri Benc (2):
  vxlan: group address requires net device
  tunnels: use macros for IPv6 address comparison

Liping Zhang (1):
  ipmonitor: fix ip monitor can't work when NET_NS is not enabled

Nikolay Aleksandrov (1):
  ip: route: fix multicast route dumps

Or Gerlitz (1):
  devlink: Add e-switch support

Phil Sutter (4):
  man: ip-link.8: Document missing geneve options
  ip-link: add missing {min,max}_tx_rate to help text
  ip-route: Prevent some double spaces in output
  iproute: fix documentation for ip rule scan order

Richard Alpe (2):
  tipc: fix UDP bearer synopsis
  tipc: refactor bearer identification

Roman Mashak (3):
  police: add extra space to improve police result printing
  police: improve usage message
  police: bug fix man page

Roopa Prabhu (2):
  bridge: print_vlan: add missing check for json instance
  bridge: print_vlan: add missing check for json instance

Sabrina Dubroca (4):
  libgenl: introduce genl_init_handle
  macsec: show usage even if the module is not available
  fou: show usage even if the module is not available
  ila: show usage even if the module is not available

Simon Horman (1):
  iproute2: correct port in FOU/GRE example

Stephen Hemminger (14):
  minor header update from net-next
  fib_rules.h update header file
  iprule: whitespace cleanup
  update kernel headers (net-next)
  update kernel header (4.7 net-next)
  update headers files to current net-next
  include: update net-next XDP headers
  update kernel headers
  update BPF headers
  devlink: whitespace cleanup
  remove useless return statement
  ip: iptuntap cleanup
  update kernel headers from 4.8-rc4
  v4.8.0

Sushma Sitaram (1):
  tc: f_u32: Fill in 'linkid' provided by user

Thomas Graf (1):
  tuntap: Add name attribute to usage text

Tom Herbert (6):
  ila: Support for checksum neutral translation
  ila: Support for configuring ila to use netfilter hook
  ip6tnl: Support for fou encapsulation
  gre6: Support for fou encapsulation
  fou: Allowing configuring IPv6 listener
  ipila: Fixed unitialized variables

WANG Cong (1):
  tc: fix a misleading failure

Xin Long (1):
  ip route: restore_handler should check tb[RTA_PREFSRC] for local networks

Yotam Gigi (2):
  tc: Add support for the matchall traffic classifier.
  tc: man: Add man entry for the matchall classifier.

anuradhak (1):
  bridge: Fix garbled json output seen if a vlan filter is specified



Re: [RFC][PATCHv2 3/7] printk: introduce per-cpu alt_print seq buffer

2016-10-09 Thread Sergey Senozhatsky
On (10/06/16 16:56), Petr Mladek wrote:
[..]
> > there are many WARN_ON_* on
> > vprintk_alt()->alt_printk_log_store()->vsnprintf() path but they all
> > seem to be calling printk():
> > 
> > - WARN_ON_ONCE() from vsnprintf()
> > - WARN_ONCE() from vsnprintf()->format_decode()
> > - WARN_ON vsnprintf()->set_field_width()
> > - WARN_ON from vsnprintf()->set_precision()
> > - WARN_ON from vsnprintf()->pointer()->flags_string()
> > 
> > a side note, some of these WARNs are... 'funny'. e.g., to deadlock a
> > system it's enough to just pass an unsupported flag in format string.
> > vsnprintf() will
> > WARN_ONCE(1, "Please remove unsupported %%%c in format string\n", *fmt)
> > 
> > but the problem is that we are already in printk():
> > 
> >printk()
> > raw_spin_lock(_lock)
> > text_len = vscnprintf(text, sizeof(textbuf), fmt, args)
> > WARN_ONCE(1, "Please remove unsupported ...)
> >  printk()
> >   raw_spin_lock(_lock)   << 
> > deadlock
> 
> Just for record. This vscnprintf() is called when logbuf_cpu is set.
> Therefore this particular recursion is not possible at the moment.

ah, indeed. thanks.

> Anyway, I agree that alt_printk_enter() calls might get nested.
> The direct vprintk_emit() calls are one reason. I guess that
> we will need to use the same counter/enter functions also
> for WARN_*DEFERRED(). And it would cause nesting as well.
> 
> Therefore we need to be careful about loosing the original
> value of irq flags.
> 
> The question is whether we need to store the flags in
> a per-CPU variable. We might also store it on the stack
> of the enter()/exit() function caller. I mean something like

yes, let's keep it on the stack. this particular implementation
was just an experiment, and I hate it. what I currently have in
my tree:

#define alt_printk_enter(flags) \
do {\
local_irq_save(flags);  \
__alt_printk_enter();   \
} while (0)

#define alt_printk_exit(flags)  \
do {\
__alt_printk_exit();\
local_irq_restore(flags);   \
} while (0)

-ss


Re: [RFC][PATCHv2 3/7] printk: introduce per-cpu alt_print seq buffer

2016-10-09 Thread Sergey Senozhatsky
On (10/06/16 16:56), Petr Mladek wrote:
[..]
> > there are many WARN_ON_* on
> > vprintk_alt()->alt_printk_log_store()->vsnprintf() path but they all
> > seem to be calling printk():
> > 
> > - WARN_ON_ONCE() from vsnprintf()
> > - WARN_ONCE() from vsnprintf()->format_decode()
> > - WARN_ON vsnprintf()->set_field_width()
> > - WARN_ON from vsnprintf()->set_precision()
> > - WARN_ON from vsnprintf()->pointer()->flags_string()
> > 
> > a side note, some of these WARNs are... 'funny'. e.g., to deadlock a
> > system it's enough to just pass an unsupported flag in format string.
> > vsnprintf() will
> > WARN_ONCE(1, "Please remove unsupported %%%c in format string\n", *fmt)
> > 
> > but the problem is that we are already in printk():
> > 
> >printk()
> > raw_spin_lock(_lock)
> > text_len = vscnprintf(text, sizeof(textbuf), fmt, args)
> > WARN_ONCE(1, "Please remove unsupported ...)
> >  printk()
> >   raw_spin_lock(_lock)   << 
> > deadlock
> 
> Just for record. This vscnprintf() is called when logbuf_cpu is set.
> Therefore this particular recursion is not possible at the moment.

ah, indeed. thanks.

> Anyway, I agree that alt_printk_enter() calls might get nested.
> The direct vprintk_emit() calls are one reason. I guess that
> we will need to use the same counter/enter functions also
> for WARN_*DEFERRED(). And it would cause nesting as well.
> 
> Therefore we need to be careful about loosing the original
> value of irq flags.
> 
> The question is whether we need to store the flags in
> a per-CPU variable. We might also store it on the stack
> of the enter()/exit() function caller. I mean something like

yes, let's keep it on the stack. this particular implementation
was just an experiment, and I hate it. what I currently have in
my tree:

#define alt_printk_enter(flags) \
do {\
local_irq_save(flags);  \
__alt_printk_enter();   \
} while (0)

#define alt_printk_exit(flags)  \
do {\
__alt_printk_exit();\
local_irq_restore(flags);   \
} while (0)

-ss


  1   2   3   4   5   6   >