[PATCH RESEND2] [media] usbtv: add a new usbid

2017-04-15 Thread Icenowy Zheng
A new usbid of UTV007 is found in a newly bought device.

The usbid is 1f71:3301.

The ID on the chip is:
UTV007
A89029.1
1520L18K1

Both video and audio is tested with the modified usbtv driver.

Signed-off-by: Icenowy Zheng 
Acked-by: Lubomir Rintel 
---

Added Lubomir's ACK in the second time of resend.

The old patch may be lost because the old aosc.xyz mail is using Yandex's
service -- which is rejected by many mail providers. As part of AOSC mailing
system refactor, we got a new mailing system, so that the patch is now
resent.

 drivers/media/usb/usbtv/usbtv-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/usb/usbtv/usbtv-core.c 
b/drivers/media/usb/usbtv/usbtv-core.c
index ceb953be0770..cae637845876 100644
--- a/drivers/media/usb/usbtv/usbtv-core.c
+++ b/drivers/media/usb/usbtv/usbtv-core.c
@@ -144,6 +144,7 @@ static void usbtv_disconnect(struct usb_interface *intf)
 
 static struct usb_device_id usbtv_id_table[] = {
{ USB_DEVICE(0x1b71, 0x3002) },
+   { USB_DEVICE(0x1f71, 0x3301) },
{}
 };
 MODULE_DEVICE_TABLE(usb, usbtv_id_table);
-- 
2.12.2



Re: [patch 03/20] padata: Make padata_alloc() static

2017-04-15 Thread Jason A. Donenfeld
I rather like this option of padata, which, since it lives in
kernel/padata.c and linux/padata.h, should be generic and useful for
other components. Seems like the ability to allocate it for a
particular set of worker CPUs and callback CPUs could be useful down
the line. Would rather not see it become static.

Jason


Re: [PATCH v2] watchdog: core: Make use of devm_register_reboot_notifier()

2017-04-15 Thread Guenter Roeck

On 04/11/2017 09:06 AM, Andrey Smirnov wrote:

Save a bit of cleanup code by leveraging newly added
devm_register_reboot_notifier().

Cc: cphe...@gmail.com
Cc: linux-kernel@vger.kernel.org
Cc: Wim Van Sebroeck 
Cc: Guenter Roeck 
Cc: Andy Shevchenko 
Cc: Andrew Morton 
Signed-off-by: Andrey Smirnov 


Acked-by: Guenter Roeck 


---

Guenter, Andy:

Here's the second version of the patch originally submitted in
[v1]. This time I tried to follow Guenter's suggestion of moving this
bit on initialization in watchdog_dev_register().

If I missed something obvious why this patch wouldn't work, again,
please let me know.

Patch introducting devm_register_reboot_notifier() can be found in
[other-patch]

Thanks,
Andrey Smirnov

[v1] https://lkml.org/lkml/2017/4/4/388
[other-patch] https://lkml.org/lkml/2017/3/20/671


 drivers/watchdog/watchdog_core.c | 35 ---
 drivers/watchdog/watchdog_dev.c  | 32 
 2 files changed, 32 insertions(+), 35 deletions(-)

diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index 74265b2..8a8d952 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -137,25 +137,6 @@ int watchdog_init_timeout(struct watchdog_device *wdd,
 }
 EXPORT_SYMBOL_GPL(watchdog_init_timeout);

-static int watchdog_reboot_notifier(struct notifier_block *nb,
-   unsigned long code, void *data)
-{
-   struct watchdog_device *wdd = container_of(nb, struct watchdog_device,
-  reboot_nb);
-
-   if (code == SYS_DOWN || code == SYS_HALT) {
-   if (watchdog_active(wdd)) {
-   int ret;
-
-   ret = wdd->ops->stop(wdd);
-   if (ret)
-   return NOTIFY_BAD;
-   }
-   }
-
-   return NOTIFY_DONE;
-}
-
 static int watchdog_restart_notifier(struct notifier_block *nb,
 unsigned long action, void *data)
 {
@@ -244,19 +225,6 @@ static int __watchdog_register_device(struct 
watchdog_device *wdd)
}
}

-   if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
-   wdd->reboot_nb.notifier_call = watchdog_reboot_notifier;
-
-   ret = register_reboot_notifier(&wdd->reboot_nb);
-   if (ret) {
-   pr_err("watchdog%d: Cannot register reboot notifier 
(%d)\n",
-  wdd->id, ret);
-   watchdog_dev_unregister(wdd);
-   ida_simple_remove(&watchdog_ida, wdd->id);
-   return ret;
-   }
-   }
-
if (wdd->ops->restart) {
wdd->restart_nb.notifier_call = watchdog_restart_notifier;

@@ -302,9 +270,6 @@ static void __watchdog_unregister_device(struct 
watchdog_device *wdd)
if (wdd->ops->restart)
unregister_restart_handler(&wdd->restart_nb);

-   if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status))
-   unregister_reboot_notifier(&wdd->reboot_nb);
-
watchdog_dev_unregister(wdd);
ida_simple_remove(&watchdog_ida, wdd->id);
 }
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 32930a0..9a52990 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -42,6 +42,7 @@
 #include /* For handling misc devices */
 #include /* For module stuff/... */
 #include  /* For mutexes */
+#include /* For reboot notifier */
 #include   /* For memory functions */
 #include  /* For standard types (like size_t) */
 #include   /* For watchdog specific items */
@@ -998,6 +999,25 @@ static struct class watchdog_class = {
.dev_groups =   wdt_groups,
 };

+static int watchdog_reboot_notifier(struct notifier_block *nb,
+   unsigned long code, void *data)
+{
+   struct watchdog_device *wdd = container_of(nb, struct watchdog_device,
+  reboot_nb);
+
+   if (code == SYS_DOWN || code == SYS_HALT) {
+   if (watchdog_active(wdd)) {
+   int ret;
+
+   ret = wdd->ops->stop(wdd);
+   if (ret)
+   return NOTIFY_BAD;
+   }
+   }
+
+   return NOTIFY_DONE;
+}
+
 /*
  * watchdog_dev_register: register a watchdog device
  * @wdd: watchdog device
@@ -1031,6 +1051,18 @@ int watchdog_dev_register(struct watchdog_device *wdd)
if (ret) {
device_destroy(&watchdog_class, devno);
watchdog_cdev_unregister(wdd);
+   return ret;
+   }
+
+   if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
+   wdd->reboot_nb.notifier_call = watchdog_reboot_notifier;
+
+   ret = devm_register_reboot_notifier(dev, &wd

Re: [RFC 0/8] Copy Offload with Peer-to-Peer PCI Memory

2017-04-15 Thread Logan Gunthorpe


On 15/04/17 04:17 PM, Benjamin Herrenschmidt wrote:
> You can't. If the iommu is on, everything is remapped. Or do you mean
> to have dma_map_* not do a remapping ?

Well, yes, you'd have to change the code so that iomem pages do not get
remapped and the raw BAR address is passed to the DMA engine. I said
specifically we haven't done this at this time but it really doesn't
seem like an unsolvable problem. It is something we will need to address
before a proper patch set is posted though.

> That's the problem again, same as before, for that to work, the
> dma_map_* ops would have to do something special that depends on *both*
> the source and target device.

No, I don't think you have to do things different based on the source.
Have the p2pmem device layer restrict allocating p2pmem based on the
devices in use (similar to how the RFC code works now) and when the dma
mapping code sees iomem pages it just needs to leave the address alone
so it's used directly by the dma in question.

It's much better to make the decision on which memory to use when you
allocate it. If you wait until you map it, it would be a pain to fall
back to system memory if it doesn't look like it will work. So, if when
you allocate it, you know everything will work you just need the dma
mapping layer to stay out of the way.

> The dma_ops today are architecture specific and have no way to
> differenciate between normal and those special P2P DMA pages.

Correct, unless Dan's idea works (which will need some investigation),
we'd need a flag in struct page or some other similar method to
determine that these are special iomem pages.

>> Though if it does, I'd expect
>> everything would still work you just wouldn't get the performance or
>> traffic flow you are looking for. We've been testing with the software
>> iommu which doesn't have this problem.
> 
> So first, no, it's more than "you wouldn't get the performance". On
> some systems it may also just not work. Also what do you mean by "the
> SW iommu doesn't have this problem" ? It catches the fact that
> addresses don't point to RAM and maps differently ?

I haven't tested it but I can't imagine why an iommu would not correctly
map the memory in the bar. But that's _way_ beside the point. We
_really_ want to avoid that situation anyway. If the iommu maps the
memory it defeats what we are trying to accomplish.

I believe the sotfware iommu only uses bounce buffers if the DMA engine
in use cannot address the memory. So in most cases, with modern
hardware, it just passes the BAR's address to the DMA engine and
everything works. The code posted in the RFC does in fact work without
needing to do any of this fussing.

>>> The problem is that the latter while seemingly easier, is also slower
>>> and not supported by all platforms and architectures (for example,
>>> POWER currently won't allow it, or rather only allows a store-only
>>> subset of it under special circumstances).
>>
>> Yes, I think situations where we have to cross host bridges will remain
>> unsupported by this work for a long time. There are two many cases where
>> it just doesn't work or it performs too poorly to be useful.
> 
> And the situation where you don't cross bridges is the one where you
> need to also take into account the offsets.

I think for the first incarnation we will just not support systems that
have offsets. This makes things much easier and still supports all the
use cases we are interested in.

> So you are designing something that is built from scratch to only work
> on a specific limited category of systems and is also incompatible with
> virtualization.

Yes, we are starting with support for specific use cases. Almost all
technology starts that way. Dax has been in the kernel for years and
only recently has someone submitted patches for it to support pmem on
powerpc. This is not unusual. If you had forced the pmem developers to
support all architectures in existence before allowing them upstream
they couldn't possibly be as far as they are today.

Virtualization specifically would be a _lot_ more difficult than simply
supporting offsets. The actual topology of the bus will probably be lost
on the guest OS and it would therefor have a difficult time figuring out
when it's acceptable to use p2pmem. I also have a difficult time seeing
a use case for it and thus I have a hard time with the argument that we
can't support use cases that do want it because use cases that don't
want it (perhaps yet) won't work.

> This is an interesting experiement to look at I suppose, but if you
> ever want this upstream I would like at least for you to develop a
> strategy to support the wider case, if not an actual implementation.

I think there are plenty of avenues forward to support offsets, etc.
It's just work. Nothing we'd be proposing would be incompatible with it.
We just don't want to have to do it all upfront especially when no one
really knows how well various architecture's hardware supports this or
if anyone

Re: [PATCH RESEND] regulator: rn5t618: Fix out of bounds array access

2017-04-15 Thread Stefan Agner
On 2017-04-15 18:12, Axel Lin wrote:
> 2017-04-16 0:53 GMT+08:00 Stefan Agner :
>> On 2017-04-15 07:52, Axel Lin wrote:
>>> The commit "regulator: rn5t618: Add RN5T567 PMIC support" added
>>> RN5T618_DCDC4 to the enum, then RN5T618_REG_NUM is also changed.
>>> So for rn5t618, there is out of bounds array access when checking
>>> regulators[i].name in the for loop.
>>
>> I use designated initializers ([RN5T618_##rid] = {..), which guarantee
>> that the non initialized elements are zero. The highest element LDORTC2
>> is defined, hence the length of the array should be RN5T618_REG_NUM.
> 
> ok, I missed that. Then current code is fine.
> Though the meaing of RN5T618_REG_NUM seems misleading to me as different
> variant has differnt number of regulators.

Yeah I admit the code is somewhat unobvious as it is now. But it allowed
me to add RN5T567 support without changing the existing array and the
preprocessor macro.

--
Stefan


[PATCH 2/8] Input: rotary-encoder - remove references to platform data from docs

2017-04-15 Thread Dmitry Torokhov
The driver has been converted to use generic device properties, so
stop referring to platform data.

Signed-off-by: Dmitry Torokhov 
---
 Documentation/input/rotary-encoder.rst | 85 ++
 1 file changed, 44 insertions(+), 41 deletions(-)

diff --git a/Documentation/input/rotary-encoder.rst 
b/Documentation/input/rotary-encoder.rst
index 4695bea67f9b..b07b20a295ac 100644
--- a/Documentation/input/rotary-encoder.rst
+++ b/Documentation/input/rotary-encoder.rst
@@ -81,48 +81,51 @@ Board integration
 
 To use this driver in your system, register a platform_device with the
 name 'rotary-encoder' and associate the IRQs and some specific platform
-data with it.
+data with it. Because the driver uses generic device properties, this can
+be done either via device tree, ACPI, or using static board files, like in
+example below:
 
-struct rotary_encoder_platform_data is declared in
-include/linux/rotary-encoder.h and needs to be filled with the number of
-steps the encoder has and can carry information about externally inverted
-signals (because of an inverting buffer or other reasons). The encoder
-can be set up to deliver input information as either an absolute or relative
-axes. For relative axes the input event returns +/-1 for each step. For
-absolute axes the position of the encoder can either roll over between zero
-and the number of steps or will clamp at the maximum and zero depending on
-the configuration.
+::
 
-Because GPIO to IRQ mapping is platform specific, this information must
-be given in separately to the driver. See the example below.
+   /* board support file example */
 
-::
+   #include 
+   #include 
+   #include 
+
+   #define GPIO_ROTARY_A 1
+   #define GPIO_ROTARY_B 2
+
+   static struct gpiod_lookup_table rotary_encoder_gpios = {
+   .dev_id = "rotary-encoder.0",
+   .table = {
+   GPIO_LOOKUP_IDX("gpio-0",
+   GPIO_ROTARY_A, NULL, 0, 
GPIO_ACTIVE_LOW),
+   GPIO_LOOKUP_IDX("gpio-0",
+   GPIO_ROTARY_B, NULL, 1, 
GPIO_ACTIVE_HIGH),
+   { },
+   },
+   };
+
+   static const struct property_entry rotary_encoder_properties[] 
__initconst = {
+   PROPERTY_ENTRY_INTEGER("rotary-encoder,steps-per-period", u32, 
24),
+   PROPERTY_ENTRY_INTEGER("linux,axis",  u32, 
ABS_X),
+   PROPERTY_ENTRY_INTEGER("rotary-encoder,relative_axis",u32, 
0),
+   { },
+   };
+
+   static struct platform_device rotary_encoder_device = {
+   .name   = "rotary-encoder",
+   .id = 0,
+   };
+
+   ...
+
+   gpiod_add_lookup_table(&rotary_encoder_gpios);
+   device_add_properties(&rotary_encoder_device, 
rotary_encoder_properties);
+   platform_device_register(&rotary_encoder_device);
+
+   ...
 
-/* board support file example */
-
-#include 
-#include 
-
-#define GPIO_ROTARY_A 1
-#define GPIO_ROTARY_B 2
-
-static struct rotary_encoder_platform_data my_rotary_encoder_info = {
-   .steps  = 24,
-   .axis   = ABS_X,
-   .relative_axis  = false,
-   .rollover   = false,
-   .gpio_a = GPIO_ROTARY_A,
-   .gpio_b = GPIO_ROTARY_B,
-   .inverted_a = 0,
-   .inverted_b = 0,
-   .half_period= false,
-   .wakeup_source  = false,
-};
-
-static struct platform_device rotary_encoder_device = {
-   .name   = "rotary-encoder",
-   .id = 0,
-   .dev= {
-   .platform_data = &my_rotary_encoder_info,
-   }
-};
+Please consult device tree binding documentation to see all properties
+supported by the driver.
-- 
2.12.2.762.g0e3151a226-goog



[PATCH 3/8] Input: fix "Game console" heading level in joystick documentation

2017-04-15 Thread Dmitry Torokhov
The heading level should be the same as for other devices.

Signed-off-by: Dmitry Torokhov 
---
 Documentation/input/joystick.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/input/joystick.rst b/Documentation/input/joystick.rst
index 202f5a090675..c9c175ffc2ff 100644
--- a/Documentation/input/joystick.rst
+++ b/Documentation/input/joystick.rst
@@ -465,7 +465,7 @@ No more joystick types are supported now, but that should 
change in the
 future if I get an Amiga in the reach of my fingers.
 
 Game console and 8-bit pads and joysticks
-~
+-
 
 See :ref:`joystick-parport` for more info.
 
-- 
2.12.2.762.g0e3151a226-goog



[PATCH 6/8] Input: docs - note that MT-A protocol is obsolete

2017-04-15 Thread Dmitry Torokhov
Everyone should be using multitouch protocol B (slotted) now.

Signed-off-by: Dmitry Torokhov 
---
 Documentation/input/multi-touch-protocol.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/input/multi-touch-protocol.rst 
b/Documentation/input/multi-touch-protocol.rst
index 81775d7c1997..8035868c56bc 100644
--- a/Documentation/input/multi-touch-protocol.rst
+++ b/Documentation/input/multi-touch-protocol.rst
@@ -22,6 +22,9 @@ describes how to send the raw data for all contacts to the 
receiver. For
 devices capable of tracking identifiable contacts (type B), the protocol
 describes how to send updates for individual contacts via event slots.
 
+.. note::
+   MT potocol type A is obsolete, all kernel drivers have been
+   converted to use type B.
 
 Protocol Usage
 --
@@ -400,9 +403,6 @@ in a finger packet must not be recognized as single-touch 
events.
 For type A devices, all finger data bypasses input filtering, since
 subsequent events of the same type refer to different fingers.
 
-For example usage of the type A protocol, see the bcm5974 driver. For
-example usage of the type B protocol, see the hid-egalax driver.
-
 .. [#f1] Also, the difference (TOOL_X - POSITION_X) can be used to model tilt.
 .. [#f2] The list can of course be extended.
 .. [#f3] The mtdev project: http://bitmath.org/code/mtdev/.
-- 
2.12.2.762.g0e3151a226-goog



[PATCH 7/8] Input: docs - split input docs into kernel- and user-facing

2017-04-15 Thread Dmitry Torokhov
Split input documentation into several groups: kernel- and user-facing, and
notes about individual device drivers. Move device drivers docs into a
separate subdirectory.

Signed-off-by: Dmitry Torokhov 
---
 Documentation/input/{ => devices}/alps.rst |  2 +-
 Documentation/input/{ => devices}/amijoy.rst   |  0
 Documentation/input/{ => devices}/appletouch.rst   |  0
 Documentation/input/{ => devices}/atarikbd.rst |  0
 Documentation/input/{ => devices}/bcm5974.rst  |  0
 Documentation/input/{ => devices}/cma3000_d0x.rst  |  4 +-
 Documentation/input/{ => devices}/cs461x.rst   |  8 +---
 Documentation/input/{ => devices}/edt-ft5x06.rst   |  0
 Documentation/input/{ => devices}/elantech.rst |  0
 Documentation/input/{ => devices}/gpio-tilt.rst|  8 ++--
 .../input/{ => devices}/iforce-protocol.rst|  0
 Documentation/input/devices/index.rst  | 19 +
 .../input/{ => devices}/joystick-parport.rst   |  2 +-
 Documentation/input/{ => devices}/ntrig.rst|  0
 .../input/{ => devices}/rotary-encoder.rst |  0
 Documentation/input/{ => devices}/sentelic.rst | 10 ++---
 Documentation/input/{ => devices}/walkera0701.rst  |  0
 Documentation/input/{ => devices}/xpad.rst | 22 +-
 Documentation/input/{ => devices}/yealink.rst  | 47 --
 Documentation/input/gamepad.rst| 10 ++---
 Documentation/input/index.rst  | 39 ++
 Documentation/input/input-programming.rst  |  5 +--
 Documentation/input/input_kapi.rst | 17 
 Documentation/input/input_uapi.rst | 21 ++
 24 files changed, 107 insertions(+), 107 deletions(-)
 rename Documentation/input/{ => devices}/alps.rst (99%)
 rename Documentation/input/{ => devices}/amijoy.rst (100%)
 rename Documentation/input/{ => devices}/appletouch.rst (100%)
 rename Documentation/input/{ => devices}/atarikbd.rst (100%)
 rename Documentation/input/{ => devices}/bcm5974.rst (100%)
 rename Documentation/input/{ => devices}/cma3000_d0x.rst (97%)
 rename Documentation/input/{ => devices}/cs461x.rst (88%)
 rename Documentation/input/{ => devices}/edt-ft5x06.rst (100%)
 rename Documentation/input/{ => devices}/elantech.rst (100%)
 rename Documentation/input/{ => devices}/gpio-tilt.rst (98%)
 rename Documentation/input/{ => devices}/iforce-protocol.rst (100%)
 create mode 100644 Documentation/input/devices/index.rst
 rename Documentation/input/{ => devices}/joystick-parport.rst (99%)
 rename Documentation/input/{ => devices}/ntrig.rst (100%)
 rename Documentation/input/{ => devices}/rotary-encoder.rst (100%)
 rename Documentation/input/{ => devices}/sentelic.rst (99%)
 rename Documentation/input/{ => devices}/walkera0701.rst (100%)
 rename Documentation/input/{ => devices}/xpad.rst (95%)
 rename Documentation/input/{ => devices}/yealink.rst (94%)
 create mode 100644 Documentation/input/input_kapi.rst
 create mode 100644 Documentation/input/input_uapi.rst

diff --git a/Documentation/input/alps.rst b/Documentation/input/devices/alps.rst
similarity index 99%
rename from Documentation/input/alps.rst
rename to Documentation/input/devices/alps.rst
index 76a71a146e50..6779148e428c 100644
--- a/Documentation/input/alps.rst
+++ b/Documentation/input/devices/alps.rst
@@ -5,7 +5,7 @@ ALPS Touchpad Protocol
 Introduction
 
 Currently the ALPS touchpad driver supports seven protocol versions in use by
-ALPS touchpads, called versions 1, 2, 3, 4, 5, 6 and 7.
+ALPS touchpads, called versions 1, 2, 3, 4, 5, 6, 7 and 8.
 
 Since roughly mid-2010 several new ALPS touchpads have been released and
 integrated into a variety of laptops and netbooks.  These new touchpads
diff --git a/Documentation/input/amijoy.rst 
b/Documentation/input/devices/amijoy.rst
similarity index 100%
rename from Documentation/input/amijoy.rst
rename to Documentation/input/devices/amijoy.rst
diff --git a/Documentation/input/appletouch.rst 
b/Documentation/input/devices/appletouch.rst
similarity index 100%
rename from Documentation/input/appletouch.rst
rename to Documentation/input/devices/appletouch.rst
diff --git a/Documentation/input/atarikbd.rst 
b/Documentation/input/devices/atarikbd.rst
similarity index 100%
rename from Documentation/input/atarikbd.rst
rename to Documentation/input/devices/atarikbd.rst
diff --git a/Documentation/input/bcm5974.rst 
b/Documentation/input/devices/bcm5974.rst
similarity index 100%
rename from Documentation/input/bcm5974.rst
rename to Documentation/input/devices/bcm5974.rst
diff --git a/Documentation/input/cma3000_d0x.rst 
b/Documentation/input/devices/cma3000_d0x.rst
similarity index 97%
rename from Documentation/input/cma3000_d0x.rst
rename to Documentation/input/devices/cma3000_d0x.rst
index 6f40c17c1aca..8bc8e61487b0 100644
--- a/Documentation/input/cma3000_d0x.rst
+++ b/Documentation/input/devices/cma3000_d0x.rst
@@ -1,5 +1,5 @@
-Kernel driver for CMA3000-D0x
-

[PATCH 8/8] Input: docs - freshen up introduction

2017-04-15 Thread Dmitry Torokhov
Stop saying that API is experimental and that only USB is supported,
acknowledge that evdev is the preferred interface, and remove paragraph
encouraging people sending snail mail to Vojtech :) along with his email.

Signed-off-by: Dmitry Torokhov 
---
 Documentation/input/event-codes.rst |   2 +
 Documentation/input/input.rst   | 253 +---
 Documentation/input/joydev/joystick-api.rst |   2 +
 Documentation/input/joydev/joystick.rst |   2 +
 4 files changed, 127 insertions(+), 132 deletions(-)

diff --git a/Documentation/input/event-codes.rst 
b/Documentation/input/event-codes.rst
index 92db50954169..00b88f113bda 100644
--- a/Documentation/input/event-codes.rst
+++ b/Documentation/input/event-codes.rst
@@ -1,3 +1,5 @@
+.. _input-event-codes:
+
 =
 Input event codes
 =
diff --git a/Documentation/input/input.rst b/Documentation/input/input.rst
index ac7669ad3e76..3b3a22975106 100644
--- a/Documentation/input/input.rst
+++ b/Documentation/input/input.rst
@@ -1,25 +1,20 @@
 .. include:: 
 
-===
-Linux Input drivers
-===
+
+Introduction
+
 
 :Copyright: |copy| 1999-2001 Vojtech Pavlik  - Sponsored by 
SuSE
 
-Should you need to contact me, the author, you can do so either by e-mail
-- mail your message to , or by paper mail: Vojtech Pavlik,
-Simunkova 1594, Prague 8, 182 00 Czech Republic
-
-Introduction
+Architecture
 
 
-This is a collection of drivers that is designed to support all input
-devices under Linux. While it is currently used only on for USB input
-devices, future use (say 2.5/2.6) is expected to expand to replace
-most of the existing input system, which is why it lives in
-drivers/input/ instead of drivers/usb/.
+Input subsystem  a collection of drivers that is designed to support
+all input devices under Linux. Most of the drivers reside in
+drivers/input, although quite a few live in drivers/hid and
+drivers/platform.
 
-The centre of the input drivers is the input module, which must be
+The core of the input subsystem is the input module, which must be
 loaded before any other of the input modules - it serves as a way of
 communication between two groups of modules:
 
@@ -32,9 +27,9 @@ events (keystrokes, mouse movements) to the input module.
 Event handlers
 --
 
-These modules get events from input and pass them where needed via
-various interfaces - keystrokes to the kernel, mouse movements via a
-simulated PS/2 interface to GPM and X and so on.
+These modules get events from input core and pass them where needed
+via various interfaces - keystrokes to the kernel, mouse movements via
+a simulated PS/2 interface to GPM and X, and so on.
 
 Simple Usage
 
@@ -45,19 +40,18 @@ kernel)::
 
input
mousedev
-   keybdev
usbcore
uhci_hcd or ohci_hcd or ehci_hcd
usbhid
+   hid_generic
 
 After this, the USB keyboard will work straight away, and the USB mouse
 will be available as a character device on major 13, minor 63::
 
crw-r--r--   1 root root  13,  63 Mar 28 22:45 mice
 
-This device has to be created.
-
-The commands to create it by hand are::
+This device usually created automatically by the system. The commands
+to create it by hand are::
 
cd /dev
mkdir input
@@ -81,100 +75,50 @@ When you do all of the above, you can use your USB mouse 
and keyboard.
 Detailed Description
 
 
-Device drivers
+Event handlers
 --
 
-Device drivers are the modules that generate events. The events are
-however not useful without being handled, so you also will need to use some
-of the modules from section 3.2.
-
-usbhid
-~~
-
-usbhid is the largest and most complex driver of the whole suite. It
-handles all HID devices, and because there is a very wide variety of them,
-and because the USB HID specification isn't simple, it needs to be this big.
-
-Currently, it handles USB mice, joysticks, gamepads, steering wheels
-keyboards, trackballs and digitizers.
-
-However, USB uses HID also for monitor controls, speaker controls, UPSs,
-LCDs and many other purposes.
-
-The monitor and speaker controls should be easy to add to the hid/input
-interface, but for the UPSs and LCDs it doesn't make much sense. For this,
-the hiddev interface was designed. See Documentation/hid/hiddev.txt
-for more information about it.
-
-The usage of the usbhid module is very simple, it takes no parameters,
-detects everything automatically and when a HID device is inserted, it
-detects it appropriately.
-
-However, because the devices vary wildly, you might happen to have a
-device that doesn't work well. In that case #define DEBUG at the beginning
-of hid-core.c and send me the syslog traces.
+Event handlers distribute the events from the devices to userspace and
+in-kernel consumers, as needed.
 
-usbmouse
-
-
-For embedded systems, for mice with b

[PATCH 1/8] Input: move documentation for Amiga CD32

2017-04-15 Thread Dmitry Torokhov
Move the documentation for Amiga CD32 together with other parallel port
joysticks.

Signed-off-by: Dmitry Torokhov 
---
 Documentation/input/cd32.rst | 24 -
 Documentation/input/index.rst|  1 -
 Documentation/input/joystick-parport.rst | 37 
 3 files changed, 37 insertions(+), 25 deletions(-)
 delete mode 100644 Documentation/input/cd32.rst

diff --git a/Documentation/input/cd32.rst b/Documentation/input/cd32.rst
deleted file mode 100644
index 935028b957d9..
--- a/Documentation/input/cd32.rst
+++ /dev/null
@@ -1,24 +0,0 @@
-==
-Amiga CD32
-==
-
-I have written a small patch that let's me use my Amiga CD32
-joypad connected to the parallel port. Thought I'd share it with you so
-you can add it to the list of supported joysticks (hopefully someone will
-find it useful).
-
-It needs the following wiring:
-
-====
-CD32 pad   Parallel port
-====
-1 (Up)  2 (D0)
-2 (Down)3 (D1)
-3 (Left)4 (D2)
-4 (Right)   5 (D3)
-5 (Fire3)  14 (AUTOFD)
-6 (Fire1)  17 (SELIN)
-7 (+5V) 1 (STROBE)
-8 (Gnd)18 (Gnd)
-9 (Fire2)   7 (D5)
-====
diff --git a/Documentation/input/index.rst b/Documentation/input/index.rst
index 153f0d476c3e..32c0515fd24b 100644
--- a/Documentation/input/index.rst
+++ b/Documentation/input/index.rst
@@ -54,7 +54,6 @@ Input drivers
appletouch
atarikbd
bcm5974
-   cd32
cma3000_d0x
cs461x
edt-ft5x06
diff --git a/Documentation/input/joystick-parport.rst 
b/Documentation/input/joystick-parport.rst
index 0aa0fb17bf48..fa8cab584793 100644
--- a/Documentation/input/joystick-parport.rst
+++ b/Documentation/input/joystick-parport.rst
@@ -443,6 +443,43 @@ parallel port::
 The other pins (Up, Down, Right, Left, Power, Ground) are the same as for
 Multi joysticks using db9.c
 
+Amiga CD32
+--
+
+Amiga CD32 joypad uses the following pinout::
+
++---> Button 3
+| +-> Right
+| | +---> Left
+| | | +-> Down
+| | | | +---> Up
+| | | | |
+  _
+5 \ o o o o o / 1
+   \ o o o o /
+  9 `~~~' 6
+| | | |
+| | | +> Button 1
+| | +--> Power
+| +> Ground
++--> Button 2
+
+It can be connected to the parallel port and driven by db9.c driver. It needs 
the following wiring:
+
+   =
+   CD32 padParallel port
+   =
+   1 (Up)   2 (D0)
+   2 (Down) 3 (D1)
+   3 (Left) 4 (D2)
+   4 (Right)5 (D3)
+   5 (Button 3)14 (AUTOFD)
+   6 (Button 1)17 (SELIN)
+   7 (+5V)  1 (STROBE)
+   8 (Gnd) 18 (Gnd)
+   9 (Button 2) 7 (D5)
+   =
+
 The drivers
 ===
 
-- 
2.12.2.762.g0e3151a226-goog



[PATCH 4/8] Input: docs - remove disclaimer/GPL notice

2017-04-15 Thread Dmitry Torokhov
This is just a part of kernel documentation, it does not require explicit
license notice.

Signed-off-by: Dmitry Torokhov 
---
 Documentation/input/index.rst | 21 -
 1 file changed, 21 deletions(-)

diff --git a/Documentation/input/index.rst b/Documentation/input/index.rst
index 32c0515fd24b..5887c79173b8 100644
--- a/Documentation/input/index.rst
+++ b/Documentation/input/index.rst
@@ -2,27 +2,6 @@
 The Linux Input Documentation
 =
 
-Disclaimer
-==
-
-This program is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2 of the License, or (at your option)
-any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-more details.
-
-You should have received a copy of the GNU General Public License along
-with this program; if not, write to the Free Software Foundation, Inc., 59
-Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-For your convenience, the GNU General Public License version 2 is included
-in the package: See the file COPYING.
-
-
 Core API
 
 
-- 
2.12.2.762.g0e3151a226-goog



[PATCH 5/8] Input: docs - update joystick documentation a bit

2017-04-15 Thread Dmitry Torokhov
Consolidate use instructions and userspace API notes into the same chapter;
remove completely obsolete references, move into a separate subdirectory.

Signed-off-by: Dmitry Torokhov 
---
 Documentation/input/index.rst |  6 +-
 Documentation/input/joydev/index.rst  | 18 +
 Documentation/input/{ => joydev}/joystick-api.rst | 30 ++--
 Documentation/input/{ => joydev}/joystick.rst | 88 ++-
 Documentation/input/joystick-parport.rst  | 12 ++--
 5 files changed, 71 insertions(+), 83 deletions(-)
 create mode 100644 Documentation/input/joydev/index.rst
 rename Documentation/input/{ => joydev}/joystick-api.rst (89%)
 rename Documentation/input/{ => joydev}/joystick.rst (86%)

diff --git a/Documentation/input/index.rst b/Documentation/input/index.rst
index 5887c79173b8..b25a67198a65 100644
--- a/Documentation/input/index.rst
+++ b/Documentation/input/index.rst
@@ -2,8 +2,7 @@
 The Linux Input Documentation
 =
 
-Core API
-
+Contents:
 
 .. toctree::
:maxdepth: 2
@@ -12,8 +11,7 @@ Core API
input
input-programming
event-codes
-   joystick
-   joystick-api
+   joydev/index
multi-touch-protocol
gamepad
gameport-programming
diff --git a/Documentation/input/joydev/index.rst 
b/Documentation/input/joydev/index.rst
new file mode 100644
index ..8d9666c7561c
--- /dev/null
+++ b/Documentation/input/joydev/index.rst
@@ -0,0 +1,18 @@
+.. include:: 
+
+==
+Linux Joystick support
+==
+
+:Copyright: |copy| 1996-2000 Vojtech Pavlik  - Sponsored by 
SuSE
+
+.. class:: toc-title
+
+   Table of Contents
+
+.. toctree::
+   :maxdepth: 3
+   :numbered:
+
+   joystick
+   joystick-api
diff --git a/Documentation/input/joystick-api.rst 
b/Documentation/input/joydev/joystick-api.rst
similarity index 89%
rename from Documentation/input/joystick-api.rst
rename to Documentation/input/joydev/joystick-api.rst
index 9b9d26833086..42edcfc6e8af 100644
--- a/Documentation/input/joystick-api.rst
+++ b/Documentation/input/joydev/joystick-api.rst
@@ -1,16 +1,36 @@
-==
-Joystick API Documentation
-==
+=
+Programming Interface
+=
 
 :Author: Ragnar Hojland Espinosa  - 7 Aug 1998
 
+Introduction
+
+
+.. important::
+   This document describes legacy ``js`` interface. Newer clients are
+   encouraged to switch to the generic event (``evdev``) interface.
+
+The 1.0 driver uses a new, event based approach to the joystick driver.
+Instead of the user program polling for the joystick values, the joystick
+driver now reports only any changes of its state. See joystick-api.txt,
+joystick.h and jstest.c included in the joystick package for more
+information. The joystick device can be used in either blocking or
+nonblocking mode, and supports select() calls.
+
+For backward compatibility the old (v0.x) interface is still included.
+Any call to the joystick driver using the old interface will return values
+that are compatible to the old interface. This interface is still limited
+to 2 axes, and applications using it usually decode only 2 buttons, although
+the driver provides up to 32.
+
 Initialization
 ==
 
 Open the joystick device following the usual semantics (that is, with open).
 Since the driver now reports events instead of polling for changes,
 immediately after the open it will issue a series of synthetic events
-(JS_EVENT_INIT) that you can read to check the initial state of the
+(JS_EVENT_INIT) that you can read to obtain the initial state of the
 joystick.
 
 By default, the device is opened in blocking mode::
@@ -182,7 +202,7 @@ the actual state of the joystick.
 
 .. note::
 
- As for version 1.2.8, the queue is circular and able to hold 64
+ As of version 1.2.8, the queue is circular and able to hold 64
  events. You can increment this size bumping up JS_BUFF_SIZE in
  joystick.h and recompiling the driver.
 
diff --git a/Documentation/input/joystick.rst 
b/Documentation/input/joydev/joystick.rst
similarity index 86%
rename from Documentation/input/joystick.rst
rename to Documentation/input/joydev/joystick.rst
index c9c175ffc2ff..b90705eb69b1 100644
--- a/Documentation/input/joystick.rst
+++ b/Documentation/input/joydev/joystick.rst
@@ -1,56 +1,17 @@
 .. include:: 
 
-
-Linux Joystick driver v2.0.0
-
-
-:Copyright: |copy| 1996-2000 Vojtech Pavlik  - Sponsored by 
SuSE
-
-
-Disclaimer
-==
-
-This program is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2 of the License, or (at your option)
-any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILI

Re: [RFC 0/8] Copy Offload with Peer-to-Peer PCI Memory

2017-04-15 Thread Logan Gunthorpe


On 15/04/17 09:01 PM, Benjamin Herrenschmidt wrote:
> Are ZONE_DEVICE pages identifiable based on the struct page alone ? (a
> flag ?)

Well you can't use ZONE_DEVICE as an indicator. They may be regular RAM,
(eg. pmem). It would need a separate flag indicating it is backed by iomem.

Logan


Re: [PATCH v4 00/10] Add Basic SoC support for MT6797

2017-04-15 Thread Mars Cheng
Hi Stephen, Matthias

gentle ping. :-)

Thanks.

On Sat, 2017-04-08 at 09:20 +0800, Mars Cheng wrote:
> This patch set adds basic SoC support for mediatek's first 10-core
> chip, X20, also known as MT6797.
> 
> - based on 4.11-rc1
> - support common clk framework
> - apply patches about intpol just accepted to get full feature support:
> http://lists.infradead.org/pipermail/linux-mediatek/2017-March/008371.html
> http://lists.infradead.org/pipermail/linux-mediatek/2017-March/008375.html
> http://lists.infradead.org/pipermail/linux-mediatek/2017-March/008373.html
> 
> Changes since v3:
> - since intpol patches accepted in v3, remove them
> - clk ID header separated from original clk driver submit
> - clean up clk driver, including unnecessary header and fields in structure
> 
> Changes since v2:
> - prevent uncessary #intpol-bases for mtk-sysirq
> - add fast path for mtk-sysirq set_type when introducing multiple bases
> - add acked-by and tested-by
> - remove wrong usage for timer node
> 
> Changes since v1:
> - add multiple base addresses support, v1 only allow 2 bases
> - clean up clk driver
> 
> Kevin-CW Chen (2):
>   dt-bindings: arm: mediatek: document clk bindings for MT6797
>   clk: mediatek: add clk support for MT6797
> 
> Mars Cheng (8):
>   dt-bindings: mediatek: Add bindings for mediatek MT6797 Platform
>   arm64: dts: mediatek: add mt6797 support
>   clk: mediatek: add mt6797 clock IDs
>   soc: mediatek: avoid using fixed spm power status defines
>   soc: mediatek: add vdec item for scpsys
>   dt-bindings: mediatek: add MT6797 power dt-bindings
>   soc: mediatek: add MT6797 scpsys support
>   arm64: dts: mediatek: add clk and scp nodes for MT6797
> 
>  Documentation/devicetree/bindings/arm/mediatek.txt |4 +
>  .../bindings/arm/mediatek/mediatek,apmixedsys.txt  |1 +
>  .../bindings/arm/mediatek/mediatek,imgsys.txt  |1 +
>  .../bindings/arm/mediatek/mediatek,infracfg.txt|1 +
>  .../bindings/arm/mediatek/mediatek,mmsys.txt   |1 +
>  .../bindings/arm/mediatek/mediatek,topckgen.txt|1 +
>  .../bindings/arm/mediatek/mediatek,vdecsys.txt |1 +
>  .../bindings/arm/mediatek/mediatek,vencsys.txt |3 +-
>  .../interrupt-controller/mediatek,sysirq.txt   |1 +
>  .../devicetree/bindings/serial/mtk-uart.txt|1 +
>  .../devicetree/bindings/soc/mediatek/scpsys.txt|6 +-
>  arch/arm64/boot/dts/mediatek/Makefile  |1 +
>  arch/arm64/boot/dts/mediatek/mt6797-evb.dts|   36 +
>  arch/arm64/boot/dts/mediatek/mt6797.dtsi   |  245 +++
>  drivers/clk/mediatek/Kconfig   |   32 +
>  drivers/clk/mediatek/Makefile  |5 +
>  drivers/clk/mediatek/clk-mt6797-img.c  |   76 +++
>  drivers/clk/mediatek/clk-mt6797-mm.c   |  136 
>  drivers/clk/mediatek/clk-mt6797-vdec.c |   93 +++
>  drivers/clk/mediatek/clk-mt6797-venc.c |   78 +++
>  drivers/clk/mediatek/clk-mt6797.c  |  714 
> 
>  drivers/soc/mediatek/mtk-scpsys.c  |  149 +++-
>  include/dt-bindings/clock/mt6797-clk.h |  281 
>  include/dt-bindings/power/mt6797-power.h   |   30 +
>  24 files changed, 1889 insertions(+), 8 deletions(-)
>  create mode 100644 arch/arm64/boot/dts/mediatek/mt6797-evb.dts
>  create mode 100644 arch/arm64/boot/dts/mediatek/mt6797.dtsi
>  create mode 100644 drivers/clk/mediatek/clk-mt6797-img.c
>  create mode 100644 drivers/clk/mediatek/clk-mt6797-mm.c
>  create mode 100644 drivers/clk/mediatek/clk-mt6797-vdec.c
>  create mode 100644 drivers/clk/mediatek/clk-mt6797-venc.c
>  create mode 100644 drivers/clk/mediatek/clk-mt6797.c
>  create mode 100644 include/dt-bindings/clock/mt6797-clk.h
>  create mode 100644 include/dt-bindings/power/mt6797-power.h
> 
> --
> 1.7.9.5




Re: [PATCH RESEND] regulator: rn5t618: Fix out of bounds array access

2017-04-15 Thread Axel Lin
2017-04-16 9:12 GMT+08:00 Axel Lin :
> 2017-04-16 0:53 GMT+08:00 Stefan Agner :
>> On 2017-04-15 07:52, Axel Lin wrote:
>>> The commit "regulator: rn5t618: Add RN5T567 PMIC support" added
>>> RN5T618_DCDC4 to the enum, then RN5T618_REG_NUM is also changed.
>>> So for rn5t618, there is out of bounds array access when checking
>>> regulators[i].name in the for loop.
>>
>> I use designated initializers ([RN5T618_##rid] = {..), which guarantee
>> that the non initialized elements are zero. The highest element LDORTC2
>> is defined, hence the length of the array should be RN5T618_REG_NUM.
>
> ok, I missed that. Then current code is fine.
I just realize my patch is wrong due to the use of designated initializers.

Regards,
Axel


Re: [RFC 0/8] Copy Offload with Peer-to-Peer PCI Memory

2017-04-15 Thread Benjamin Herrenschmidt
On Sat, 2017-04-15 at 15:09 -0700, Dan Williams wrote:
> I'm wondering, since this is limited to support behind a single
> switch, if you could have a software-iommu hanging off that switch
> device object that knows how to catch and translate the non-zero
> offset bus address case. We have something like this with VMD driver,
> and I toyed with a soft pci bridge when trying to support AHCI+NVME
> bar remapping. When the dma api looks up the iommu for its device it
> hits this soft-iommu and that driver checks if the page is host memory
> or device memory to do the dma translation. You wouldn't need a bit in
> struct page, just a lookup to the hosting struct dev_pagemap in the
> is_zone_device_page() case and that can point you to p2p details.

I was thinking about a hook in the arch DMA ops but that kind of
wrapper might work instead indeed. However I'm not sure what's the best
way to "instantiate" it.

The main issue is that the DMA ops are a function of the initiator,
not the target (since the target is supposed to be memory) so things
are a bit awkward.

One (user ?) would have to know that a given device "intends" to DMA
directly to another device.

This is awkward because in the ideal scenario, this isn't something the
device knows. For example, one could want to have an existing NIC DMA
directly to/from NVME pages or GPU pages.

The NIC itself doesn't know the characteristic of these pages, but
*something* needs to insert itself in the DMA ops of that bridge to
make it possible.

That's why I wonder if it's the struct page of the target that should
be "marked" in such a way that the arch dma'ops can immediately catch
that they belong to a device and might require "wrapped" operations.

Are ZONE_DEVICE pages identifiable based on the struct page alone ? (a
flag ?)

That would allow us to keep a fast path for normal memory targets, but
also have some kind of way to handle the special cases of such peer 2
peer (or also handle other type of peer to peer that don't necessarily
involve PCI address wrangling but could require additional iommu bits).

Just thinking out loud ... I don't have a firm idea or a design. But
peer to peer is definitely a problem we need to tackle generically, the
demand for it keeps coming up.

Cheers,
Ben.



Re: [PATCH] microblaze/timer: set ->min_delta_ticks and ->max_delta_ticks

2017-04-15 Thread Nicolai Stange
Hello Daniel,

On Fri, Apr 07 2017, Daniel Lezcano wrote:

> On Thu, Mar 30, 2017 at 09:45:28PM +0200, Nicolai Stange wrote:
>> diff --git a/arch/microblaze/kernel/timer.c b/arch/microblaze/kernel/timer.c
>> index 999066192715..545ccd46edb3 100644
>> --- a/arch/microblaze/kernel/timer.c
>> +++ b/arch/microblaze/kernel/timer.c
>> @@ -178,8 +178,10 @@ static __init int xilinx_clockevent_init(void)
>>  clockevent_xilinx_timer.shift);
>>  clockevent_xilinx_timer.max_delta_ns =
>>  clockevent_delta2ns((u32)~0, &clockevent_xilinx_timer);
>> +clockevent_xilinx_timer.max_delta_ticks = (u32)~0;
>
> Can you take the opportunity to fix the type (unsigned long) ?

Hmm, I personally think that it'd be better to leave the u32 there as it
corresponds to the hardware's counter width?

clockevent_delta2ns()' latch argument has been of type unsigned long
from the beginning and this might indicate that at least this
driver's original author followed this line of reasoning...

OTOH, I think that u32 is equivalent to unsigned long on microblaze, so
it doesn't matter much.

Does the above convince you or do you still want the

  - clockevent_xilinx_timer.max_delta_ticks = (u32)~0;
  + clockevent_xilinx_timer.max_delta_ticks = ~0UL;

change?


Thanks,

Nicolai


Re: [PATCH] ARM: dts: omap4-droid4: add bluetooth

2017-04-15 Thread Rob Herring
On Sat, Apr 15, 2017 at 5:18 PM, Sebastian Reichel  wrote:
> Droid 4 has wl1835 connected to the OMAP's UART4 port, which is
> used for Bluetooth and most likely can also be used for controlling
> the FM radio and GPS receivers.
>
> Signed-off-by: Sebastian Reichel 
> ---
> Hi,
>
> Thanks to the work of Rob adding Bluetooth support for Droid 4 was
> straight forward :) I did a short test scanning for available devices
> using bluetoothctl. For that I had to rebind the bluetooth device,
> since it has been initialized before rootfs/firmware was available
> (builtin driver):
>
> echo serial0-0 > /sys/bus/serial/drivers/hci-ti/unbind
> echo serial0-0 > /sys/bus/serial/drivers/hci-ti/bind
>
> According to my research the FM module should be functional on
> Droid 4 and the wl1835's GPS is also used. Rob, do you have a
> plans for supporting the extra resources?

I don't think the h/w I have can do FM or GPS. At least there's no
headphone jack to serve as the FM antenna. For GPS, it seems support
for that is not publicly available. Maybe an antenna is not needed to
get the control interface working. It would be nice to integrate
though and then we can kill off the shared transport driver. Marcel
had mentioned that the Intel BT driver provides a regmap interface to
its FM driver. Not sure if that would work for TI.

Rob


linux-kernel@vger.kernel.org

2017-04-15 Thread kbuild test robot
Hi Josh,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   d5ff0814fda50f0306e102f39640cf5bb76af08e
commit: 3f135e57a4f76d24ae8d8a490314331f0ced40c5 x86/build: Mostly disable 
'-maccumulate-outgoing-args'
date:   2 weeks ago
config: x86_64-randconfig-s1-04160822 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
reproduce:
git checkout 3f135e57a4f76d24ae8d8a490314331f0ced40c5
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

>> arch/x86//kernel/ftrace.c:35:3: error: #error The following combination is 
>> not supported: ((compiler missing -mfentry) || (CONFIG_X86_32 and 
>> !CONFIG_DYNAMIC_FTRACE)) && CONFIG_FUNCTION_GRAPH_TRACER && 
>> CONFIG_CC_OPTIMIZE_FOR_SIZE

vim +35 arch/x86//kernel/ftrace.c

29  #include 
30  #include 
31  
32  #if defined(CONFIG_FUNCTION_GRAPH_TRACER) && \
33  !defined(CC_USING_FENTRY) && \
34  !defined(CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE)
  > 35  # error The following combination is not supported: ((compiler missing 
-mfentry) || (CONFIG_X86_32 and !CONFIG_DYNAMIC_FTRACE)) && 
CONFIG_FUNCTION_GRAPH_TRACER && CONFIG_CC_OPTIMIZE_FOR_SIZE
36  #endif
37  
38  #ifdef CONFIG_DYNAMIC_FTRACE

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH RESEND] regulator: rn5t618: Fix out of bounds array access

2017-04-15 Thread Axel Lin
2017-04-16 0:53 GMT+08:00 Stefan Agner :
> On 2017-04-15 07:52, Axel Lin wrote:
>> The commit "regulator: rn5t618: Add RN5T567 PMIC support" added
>> RN5T618_DCDC4 to the enum, then RN5T618_REG_NUM is also changed.
>> So for rn5t618, there is out of bounds array access when checking
>> regulators[i].name in the for loop.
>
> I use designated initializers ([RN5T618_##rid] = {..), which guarantee
> that the non initialized elements are zero. The highest element LDORTC2
> is defined, hence the length of the array should be RN5T618_REG_NUM.

ok, I missed that. Then current code is fine.
Though the meaing of RN5T618_REG_NUM seems misleading to me as different
variant has differnt number of regulators.

Thanks for the review,
Axel


[PATCH] Remove ARM errata Workarounds 458693 and 460075

2017-04-15 Thread Nisal Menuka
According to ARM, these errata exist only in a version of Cortex-A8
(r2p0) which was never built. Therefore, I believe there are no platforms
where this workaround should be enabled.
link :http://infocenter.arm.com/help/index.jsp?topic=
/com.arm.doc.faqs/ka15634.html

Signed-off-by: Nisal Menuka 
---
 arch/arm/Kconfig  | 27 ---
 arch/arm/mm/proc-v7.S | 14 --
 2 files changed, 41 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 0d4e71b..d527963 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1005,33 +1005,6 @@ config ARM_ERRATA_430973
  Note that setting specific bits in the ACTLR register may not be
  available in non-secure mode.
 
-config ARM_ERRATA_458693
-   bool "ARM errata: Processor deadlock when a false hazard is created"
-   depends on CPU_V7
-   depends on !ARCH_MULTIPLATFORM
-   help
- This option enables the workaround for the 458693 Cortex-A8 (r2p0)
- erratum. For very specific sequences of memory operations, it is
- possible for a hazard condition intended for a cache line to instead
- be incorrectly associated with a different cache line. This false
- hazard might then cause a processor deadlock. The workaround enables
- the L1 caching of the NEON accesses and disables the PLD instruction
- in the ACTLR register. Note that setting specific bits in the ACTLR
- register may not be available in non-secure mode.
-
-config ARM_ERRATA_460075
-   bool "ARM errata: Data written to the L2 cache can be overwritten with 
stale data"
-   depends on CPU_V7
-   depends on !ARCH_MULTIPLATFORM
-   help
- This option enables the workaround for the 460075 Cortex-A8 (r2p0)
- erratum. Any asynchronous access to the L2 cache may encounter a
- situation in which recent store transactions to the L2 cache are lost
- and overwritten with stale memory contents from external memory. The
- workaround disables the write-allocate mode for the L2 cache via the
- ACTLR register. Note that setting specific bits in the ACTLR register
- may not be available in non-secure mode.
-
 config ARM_ERRATA_742230
bool "ARM errata: DMB operation may be faulty"
depends on CPU_V7 && SMP
diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S
index d00d52c..43a4a12 100644
--- a/arch/arm/mm/proc-v7.S
+++ b/arch/arm/mm/proc-v7.S
@@ -306,20 +306,6 @@ __ca8_errata:
orreq   r0, r0, #(1 << 6)   @ set IBE to 1
mcreq   p15, 0, r0, c1, c0, 1   @ write aux control register
 #endif
-#ifdef CONFIG_ARM_ERRATA_458693
-   teq r6, #0x20   @ only present in r2p0
-   mrceq   p15, 0, r0, c1, c0, 1   @ read aux control register
-   orreq   r0, r0, #(1 << 5)   @ set L1NEON to 1
-   orreq   r0, r0, #(1 << 9)   @ set PLDNOP to 1
-   mcreq   p15, 0, r0, c1, c0, 1   @ write aux control register
-#endif
-#ifdef CONFIG_ARM_ERRATA_460075
-   teq r6, #0x20   @ only present in r2p0
-   mrceq   p15, 1, r0, c9, c0, 2   @ read L2 cache aux ctrl 
register
-   tsteq   r0, #1 << 22
-   orreq   r0, r0, #(1 << 22)  @ set the Write Allocate 
disable bit
-   mcreq   p15, 1, r0, c9, c0, 2   @ write the L2 cache aux ctrl 
register
-#endif
b   __errata_finish
 
 __ca9_errata:
-- 
2.7.4



Re: [PATCH] hugetlbfs: fix offset overflow in huegtlbfs mmap

2017-04-15 Thread Mike Kravetz
On 04/13/2017 08:32 PM, Naoya Horiguchi wrote:
> On Tue, Apr 11, 2017 at 03:51:58PM -0700, Mike Kravetz wrote:
> ...
>> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
>> index 7163fe0..dde8613 100644
>> --- a/fs/hugetlbfs/inode.c
>> +++ b/fs/hugetlbfs/inode.c
>> @@ -136,17 +136,26 @@ static int hugetlbfs_file_mmap(struct file *file, 
>> struct vm_area_struct *vma)
>>  vma->vm_flags |= VM_HUGETLB | VM_DONTEXPAND;
>>  vma->vm_ops = &hugetlb_vm_ops;
>>  
>> +/*
>> + * Offset passed to mmap (before page shift) could have been
>> + * negative when represented as a (l)off_t.
>> + */
>> +if (((loff_t)vma->vm_pgoff << PAGE_SHIFT) < 0)
>> +return -EINVAL;
>> +
>>  if (vma->vm_pgoff & (~huge_page_mask(h) >> PAGE_SHIFT))
>>  return -EINVAL;
>>  
>>  vma_len = (loff_t)(vma->vm_end - vma->vm_start);
>> +len = vma_len + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
>> +/* check for overflow */
>> +if (len < vma_len)
>> +return -EINVAL;
> 
> Andrew sent this patch to Linus today, so I know it's a little too late, but
> I think that getting len directly from vma like below might be a simpler fix.
> 
>   len = (loff_t)(vma->vm_end - vma->vm_start + (vma->vm_pgoff << 
> PAGE_SHIFT)); 
> 
> This shouldn't overflow because vma->vm_{end|start|pgoff} are unsigned long,
> but if worried you can add VM_BUG_ON_VMA(len < 0, vma).

Thanks Naoya,

I am pretty sure the checks are necessary.  You are correct in that
vma->vm_{end|start|pgoff} are unsigned long.  However,  pgoff can be
a REALLY big value that becomes negative when shifted.

Note that pgoff is simply the off_t offset value passed from the user cast
to unsigned long and shifted right by PAGE_SHIFT.  There is nothing to
prevent a user from passing a 'signed' negative value.  In the reproducer
provided, the value passed from user space is 0x8000ULL.

-- 
Mike Kravetz


Re: [patch 06/20] cpufreq: Use cpuhp_setup_state_nocalls_locked()

2017-04-15 Thread Rafael J. Wysocki
On Sat, Apr 15, 2017 at 7:01 PM, Thomas Gleixner  wrote:
> From: Sebastian Andrzej Siewior 
>
> cpufreq holds get_online_cpus() while invoking cpuhp_setup_state_nocalls()
> to make subsys_interface_register() and the registration of hotplug calls
> atomic versus cpu hotplug.
>
> cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
> correct, but prevents the conversion of the hotplug locking to a percpu
> rwsem.
>
> Use cpuhp_setup_state_nocalls_locked() to avoid the nested call.
>
> Signed-off-by: Sebastian Andrzej Siewior 
> Signed-off-by: Thomas Gleixner 
> Cc: "Rafael J. Wysocki" 
> Cc: Viresh Kumar 
> Cc: linux...@vger.kernel.org

Acked-by: Rafael J. Wysocki 

>
> ---
>  drivers/cpufreq/cpufreq.c |9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2473,9 +2473,10 @@ int cpufreq_register_driver(struct cpufr
> goto err_if_unreg;
> }
>
> -   ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "cpufreq:online",
> -   cpuhp_cpufreq_online,
> -   cpuhp_cpufreq_offline);
> +   ret = cpuhp_setup_state_nocalls_locked(CPUHP_AP_ONLINE_DYN,
> +  "cpufreq:online",
> +  cpuhp_cpufreq_online,
> +  cpuhp_cpufreq_offline);
> if (ret < 0)
> goto err_if_unreg;
> hp_online = ret;
> @@ -2519,7 +2520,7 @@ int cpufreq_unregister_driver(struct cpu
> get_online_cpus();
> subsys_interface_unregister(&cpufreq_interface);
> remove_boost_sysfs_file();
> -   cpuhp_remove_state_nocalls(hp_online);
> +   cpuhp_remove_state_nocalls_locked(hp_online);
>
> write_lock_irqsave(&cpufreq_driver_lock, flags);
>
>
>


Re: [RFC 0/8] Copy Offload with Peer-to-Peer PCI Memory

2017-04-15 Thread Benjamin Herrenschmidt
On Sat, 2017-04-15 at 11:41 -0600, Logan Gunthorpe wrote:
> Thanks, Benjamin, for the summary of some of the issues.
> 
> On 14/04/17 04:07 PM, Benjamin Herrenschmidt wrote
> > So I assume the p2p code provides a way to address that too via special
> > dma_ops ? Or wrappers ?
> 
> Not at this time. We will probably need a way to ensure the iommus do
> not attempt to remap these addresses.

You can't. If the iommu is on, everything is remapped. Or do you mean
to have dma_map_* not do a remapping ?

That's the problem again, same as before, for that to work, the
dma_map_* ops would have to do something special that depends on *both*
the source and target device.

The current DMA infrastructure doesn't have anything like that. It's a
rather fundamental issue to your design that you need to address.

The dma_ops today are architecture specific and have no way to
differenciate between normal and those special P2P DMA pages.

> Though if it does, I'd expect
> everything would still work you just wouldn't get the performance or
> traffic flow you are looking for. We've been testing with the software
> iommu which doesn't have this problem.

So first, no, it's more than "you wouldn't get the performance". On
some systems it may also just not work. Also what do you mean by "the
SW iommu doesn't have this problem" ? It catches the fact that
addresses don't point to RAM and maps differently ?

> > The problem is that the latter while seemingly easier, is also slower
> > and not supported by all platforms and architectures (for example,
> > POWER currently won't allow it, or rather only allows a store-only
> > subset of it under special circumstances).
> 
> Yes, I think situations where we have to cross host bridges will remain
> unsupported by this work for a long time. There are two many cases where
> it just doesn't work or it performs too poorly to be useful.

And the situation where you don't cross bridges is the one where you
need to also take into account the offsets.

*both* cases mean that you need somewhat to intervene at the dma_ops
level to handle this. Which means having a way to identify your special
struct pages or PFNs to allow the arch to add a special case to the
dma_ops.

> > I don't fully understand how p2pmem "solves" that by creating struct
> > pages. The offset problem is one issue. But there's the iommu issue as
> > well, the driver cannot just use the normal dma_map ops.
> 
> We are not using a proper iommu and we are dealing with systems that
> have zero offset. This case is also easily supported. I expect fixing
> the iommus to not map these addresses would also be reasonably achievable.

So you are designing something that is built from scratch to only work
on a specific limited category of systems and is also incompatible with
virtualization.

This is an interesting experiement to look at I suppose, but if you
ever want this upstream I would like at least for you to develop a
strategy to support the wider case, if not an actual implementation.

Cheers,
Ben.



[PATCH] ARM: dts: omap4-droid4: add bluetooth

2017-04-15 Thread Sebastian Reichel
Droid 4 has wl1835 connected to the OMAP's UART4 port, which is
used for Bluetooth and most likely can also be used for controlling
the FM radio and GPS receivers.

Signed-off-by: Sebastian Reichel 
---
Hi,

Thanks to the work of Rob adding Bluetooth support for Droid 4 was
straight forward :) I did a short test scanning for available devices
using bluetoothctl. For that I had to rebind the bluetooth device,
since it has been initialized before rootfs/firmware was available
(builtin driver):

echo serial0-0 > /sys/bus/serial/drivers/hci-ti/unbind
echo serial0-0 > /sys/bus/serial/drivers/hci-ti/bind

According to my research the FM module should be functional on
Droid 4 and the wl1835's GPS is also used. Rob, do you have a
plans for supporting the extra resources?

-- Sebastian
---
 arch/arm/boot/dts/omap4-droid4-xt894.dts | 20 
 1 file changed, 20 insertions(+)

diff --git a/arch/arm/boot/dts/omap4-droid4-xt894.dts 
b/arch/arm/boot/dts/omap4-droid4-xt894.dts
index e0fdfe6cc78c..2495faf79a43 100644
--- a/arch/arm/boot/dts/omap4-droid4-xt894.dts
+++ b/arch/arm/boot/dts/omap4-droid4-xt894.dts
@@ -395,6 +395,15 @@
>;
};
 
+   uart4_pins: pinmux_uart4_pins {
+   pinctrl-single,pins = <
+   OMAP4_IOPAD(0x15c, PIN_INPUT | MUX_MODE0)   /* 
uart4_rx */
+   OMAP4_IOPAD(0x15e, PIN_OUTPUT | MUX_MODE0)  /* 
uart4_tx */
+   OMAP4_IOPAD(0x110, PIN_INPUT_PULLUP | MUX_MODE5)/* 
uart4_cts */
+   OMAP4_IOPAD(0x112, PIN_OUTPUT_PULLUP | MUX_MODE5)   /* 
uart4_rts */
+   >;
+   };
+
mcbsp2_pins: pinmux_mcbsp2_pins {
pinctrl-single,pins = <
OMAP4_IOPAD(0x0f6, PIN_INPUT | MUX_MODE0)   /* 
abe_mcbsp2_clkx */
@@ -429,6 +438,17 @@
   &omap4_pmx_core 0x17c>;
 };
 
+&uart4 {
+   pinctrl-names = "default";
+   pinctrl-0 = <&uart4_pins>;
+
+   bluetooth {
+   compatible = "ti,wl1835-st";
+   enable-gpios = <&gpio6 14 GPIO_ACTIVE_HIGH>; /* gpio 174 */
+   max-speed = <3686400>;
+   };
+};
+
 &usbhsehci {
phys = <&hsusb1_phy>;
 };
-- 
2.11.0



Re: [RFC 0/8] Copy Offload with Peer-to-Peer PCI Memory

2017-04-15 Thread Dan Williams
On Sat, Apr 15, 2017 at 10:41 AM, Logan Gunthorpe  wrote:
> Thanks, Benjamin, for the summary of some of the issues.
>
> On 14/04/17 04:07 PM, Benjamin Herrenschmidt wrote
>> So I assume the p2p code provides a way to address that too via special
>> dma_ops ? Or wrappers ?
>
> Not at this time. We will probably need a way to ensure the iommus do
> not attempt to remap these addresses. Though if it does, I'd expect
> everything would still work you just wouldn't get the performance or
> traffic flow you are looking for. We've been testing with the software
> iommu which doesn't have this problem.
>
>> The problem is that the latter while seemingly easier, is also slower
>> and not supported by all platforms and architectures (for example,
>> POWER currently won't allow it, or rather only allows a store-only
>> subset of it under special circumstances).
>
> Yes, I think situations where we have to cross host bridges will remain
> unsupported by this work for a long time. There are two many cases where
> it just doesn't work or it performs too poorly to be useful.
>
>> I don't fully understand how p2pmem "solves" that by creating struct
>> pages. The offset problem is one issue. But there's the iommu issue as
>> well, the driver cannot just use the normal dma_map ops.
>
> We are not using a proper iommu and we are dealing with systems that
> have zero offset. This case is also easily supported. I expect fixing
> the iommus to not map these addresses would also be reasonably achievable.

I'm wondering, since this is limited to support behind a single
switch, if you could have a software-iommu hanging off that switch
device object that knows how to catch and translate the non-zero
offset bus address case. We have something like this with VMD driver,
and I toyed with a soft pci bridge when trying to support AHCI+NVME
bar remapping. When the dma api looks up the iommu for its device it
hits this soft-iommu and that driver checks if the page is host memory
or device memory to do the dma translation. You wouldn't need a bit in
struct page, just a lookup to the hosting struct dev_pagemap in the
is_zone_device_page() case and that can point you to p2p details.


Regression - Linux 4.9: ums_eneub6250 broken: transfer buffer not dma capable - Trace

2017-04-15 Thread Andreas Hartmann
Hello!

Since Linux 4.9, ums_eneub6250 is broken. It's working fine if
CONFIG_VMAP_STACK is disabled.

I would be glad if it would be fixed.


Thanks,
kind regards,
Andreas


Apr 15 17:58:54 notebook2 kernel: usb 1-1.1: new high-speed USB device number 3 
using ehci-pci
Apr 15 17:58:54 notebook2 kernel: usb 1-1.1: New USB device found, 
idVendor=0cf2, idProduct=6250
Apr 15 17:58:54 notebook2 kernel: usb 1-1.1: New USB device strings: Mfr=1, 
Product=2, SerialNumber=4
Apr 15 17:58:54 notebook2 kernel: usb 1-1.1: Product: UB6250   
Apr 15 17:58:54 notebook2 kernel: usb 1-1.1: Manufacturer: ENE Flash  
Apr 15 17:58:54 notebook2 kernel: usb 1-1.1: SerialNumber: 606569746801
Apr 15 17:58:54 notebook2 mtp-probe[2134]: checking bus 1, device 3: 
"/sys/devices/pci:00/:00:1a.0/usb1/1-1/1-1.1"
Apr 15 17:58:54 notebook2 mtp-probe[2134]: bus: 1, device: 3 was not an MTP 
device
Apr 15 17:58:55 notebook2 kernel: usbcore: registered new interface driver 
usb-storage
Apr 15 17:58:55 notebook2 kernel: usbcore: registered new interface driver uas
Apr 15 17:58:55 notebook2 kernel: ums_eneub6250 1-1.1:1.0: USB Mass Storage 
device detected
Apr 15 17:58:55 notebook2 kernel: scsi host6: usb-storage 1-1.1:1.0
Apr 15 17:58:55 notebook2 kernel: [ cut here ]
Apr 15 17:58:55 notebook2 kernel: WARNING: CPU: 2 PID: 2133 at 
../drivers/usb/core/hcd.c:1587 usb_hcd_map_urb_for_dma+0x4ba/0x4f0 [usbcore]
Apr 15 17:58:55 notebook2 kernel: transfer buffer not dma capable
Apr 15 17:58:55 notebook2 kernel: Modules linked in: ums_eneub6250(+) uas 
usb_storage fuse binfmt_misc snd_hda_codec_hdmi snd_hda_codec_realtek 
snd_hda_codec_generic snd_hda_intel snd_hda_codec snd_hda_core snd_hwdep 
snd_pcm_oss msi_wmi iTCO_wdt iTCO_vendor_support snd_pcm wmi snd_seq battery ac 
msi_laptop sparse_keymap rfkill joydev snd_seq_device snd_timer r8169 mii 
snd_mixer_oss intel_powerclamp coretemp kvm_intel snd mei_me mei kvm i2c_i801 
lpc_ich soundcore intel_ips shpchp mfd_core i2c_smbus fjes acpi_cpufreq tpm_tis 
pcspkr thermal tpm_tis_core tpm irqbypass fan dm_crypt crc32c_intel serio_raw 
sr_mod cdrom ehci_pci i915 ehci_hcd i2c_algo_bit usbcore drm_kms_helper 
syscopyarea sysfillrect sysimgblt fb_sys_fops drm video button dm_mirror 
dm_region_hash dm_log sg dm_multipath dm_mod scsi_dh_rdac scsi_dh_emc 
scsi_dh_alua
Apr 15 17:58:55 notebook2 kernel: CPU: 2 PID: 2133 Comm: systemd-udevd Not 
tainted 4.9.21-1-default #1
Apr 15 17:58:55 notebook2 kernel: Hardware name: Micro-Star International 
CR620/CR620, BIOS E1681IMS VER.10C 04/12/2011
Apr 15 17:58:55 notebook2 kernel:  baf681b477f0 af3c854a 
baf681b47840 
Apr 15 17:58:55 notebook2 kernel:  baf681b47830 af085c71 
0633af0bd0de 8d35b2844e40
Apr 15 17:58:55 notebook2 kernel:   0200 
0002 8d360fafd800
Apr 15 17:58:55 notebook2 kernel: Call Trace:
Apr 15 17:58:55 notebook2 kernel:  [] dump_stack+0x63/0x89
Apr 15 17:58:55 notebook2 kernel:  [] __warn+0xd1/0xf0
Apr 15 17:58:55 notebook2 kernel:  [] 
warn_slowpath_fmt+0x4f/0x60
Apr 15 17:58:55 notebook2 kernel:  [] ? 
put_prev_entity+0x48/0x720
Apr 15 17:58:55 notebook2 kernel:  [] 
usb_hcd_map_urb_for_dma+0x4ba/0x4f0 [usbcore]
Apr 15 17:58:55 notebook2 kernel:  [] ? 
finish_task_switch+0x78/0x1e0
Apr 15 17:58:55 notebook2 kernel:  [] 
usb_hcd_submit_urb+0x1c9/0xb30 [usbcore]
Apr 15 17:58:55 notebook2 kernel:  [] ? schedule+0x3d/0x90
Apr 15 17:58:55 notebook2 kernel:  [] ? 
schedule_timeout+0x220/0x3c0
Apr 15 17:58:55 notebook2 kernel:  [] 
usb_submit_urb.part.6+0x295/0x550 [usbcore]
Apr 15 17:58:55 notebook2 kernel:  [] 
usb_submit_urb+0x34/0x70 [usbcore]
Apr 15 17:58:55 notebook2 kernel:  [] 
usb_stor_msg_common+0x9d/0x120 [usb_storage]
Apr 15 17:58:55 notebook2 kernel:  [] 
usb_stor_bulk_transfer_buf+0x56/0xa0 [usb_storage]
Apr 15 17:58:55 notebook2 kernel:  [] 
usb_stor_bulk_transfer_sg+0x4e/0x60 [usb_storage]
Apr 15 17:58:55 notebook2 kernel:  [] 
ene_send_scsi_cmd+0x97/0x160 [ums_eneub6250]
Apr 15 17:58:55 notebook2 kernel:  [] 
ene_get_card_type.constprop.19+0x5b/0x60 [ums_eneub6250]
Apr 15 17:58:55 notebook2 kernel:  [] 
ene_ub6250_probe+0x8f/0x110 [ums_eneub6250]
Apr 15 17:58:55 notebook2 kernel:  [] 
usb_probe_interface+0x157/0x2f0 [usbcore]
Apr 15 17:58:55 notebook2 kernel:  [] 
driver_probe_device+0x227/0x440
Apr 15 17:58:55 notebook2 kernel:  [] 
__driver_attach+0xdd/0xe0
Apr 15 17:58:55 notebook2 kernel:  [] ? 
driver_probe_device+0x440/0x440
Apr 15 17:58:55 notebook2 kernel:  [] 
bus_for_each_dev+0x5d/0x90
Apr 15 17:58:55 notebook2 kernel:  [] driver_attach+0x1e/0x20
Apr 15 17:58:55 notebook2 kernel:  [] 
bus_add_driver+0x45/0x270
Apr 15 17:58:55 notebook2 kernel:  [] 
driver_register+0x60/0xe0
Apr 15 17:58:55 notebook2 kernel:  [] 
usb_register_driver+0x82/0x150 [usbcore]
Apr 15 17:58:55 notebook2 kernel:  [] ? 0xc03b9000
Apr 15 17:58:55 notebook2 kernel:  [] 
ene_ub6250_driver_init+0x38/0x1000 [ums_eneub6250]

[PATCH] Bluetooth: hci_ll: Fix NULL pointer deref on FW upload failure

2017-04-15 Thread Sebastian Reichel
Avoid NULL pointer dereference occurring due to freeing
skb containing an error pointer. It can easily be triggered
by using the driver with broken uart (i.e. due to misconfigured
pinmuxing).

Fixes: 371805522f87 ("bluetooth: hci_uart: add LL protocol serdev driver 
support")
Signed-off-by: Sebastian Reichel 
---
 drivers/bluetooth/hci_ll.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c
index 485e8eb04542..adc444f309a3 100644
--- a/drivers/bluetooth/hci_ll.c
+++ b/drivers/bluetooth/hci_ll.c
@@ -537,8 +537,7 @@ static int read_local_version(struct hci_dev *hdev)
if (IS_ERR(skb)) {
bt_dev_err(hdev, "Reading TI version information failed (%ld)",
   PTR_ERR(skb));
-   err = PTR_ERR(skb);
-   goto out;
+   return PTR_ERR(skb);
}
if (skb->len != sizeof(*ver)) {
err = -EILSEQ;
-- 
2.11.0



Re: v4.10-rc8 (-rc6) boot regression on Intel desktop, does not boot after cold boots, boots after reboot

2017-04-15 Thread Pavel Machek
On Wed 2017-04-12 17:08:35, Frederic Weisbecker wrote:
> On Mon, Apr 03, 2017 at 08:20:50PM +0200, Pavel Machek wrote:
> > > > > > > ...1d.7: PCI fixup... pass 2
> > > > > > > ...1d.7: PCI fixup... pass 3
> > > > > > > ...1d.7: PCI fixup... pass 3 done
> > > > > > > 
> > > > > > > ...followed by hang. So yes, it looks USB related.
> > > > > > > 
> > > > > > > (Sometimes it hangs with some kind backtrace involving secondary 
> > > > > > > CPU
> > > > > > > startup, unfortunately useful info is off screen at that point).
> > > > > > 
> > > > > > Forgot to say, 1d.7 is EHCI controller.
> > > > > > 
> > > > > > 00:1d.7 USB controller: Intel Corporation NM10/ICH7 Family USB2 EHCI
> > > > > > Controller (rev 01)
> > > > > 
> > > > > Ok, I should have access soon to a EeePc 1015CX (which seem to have 
> > > > > this controller).
> > > > > I hope I'll be able to reproduce the issue there. If not, I'm sorry 
> > > > > but I'll have to
> > > > > burden you again :-)
> > > > 
> > > > Go through more mails. It is only reproducible after cold boot. .. so
> > > > I doubt it will be easy to reproduce on another machine.
> > > > 
> > > > Now... I do have serial port, and I even might have serial cable
> > > > somewhere, but Giving how sensitive it is, it is probably going to
> > > > go away with console on ttyS...
> > > 
> > > I also tried on an eeepc (which has ICH7/NM10 as well), with your config.
> > > I even plugged a usb keyboard but even then I have been unable to
> > > reproduce either :-(
> > 
> > Ok, give me some time. I'm no longer using the affected machine, so no
> > promises.
> 
> Actually someone reported me a very similar issue than yours lately. It's 
> probably
> the same. And I have a potential fix.

Got the machine back to work -- I guess it will be useful for distcc.

And yes, you seem to have right fix :-). 

Tested-by: Pavel Machek 

Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


signature.asc
Description: Digital signature


[GIT PULL] ftrace: Fix removing of second function probe

2017-04-15 Thread Steven Rostedt

Linus,

While rewriting the function probe code, I stumbled over a long standing
bug. This bug has been there since function tracing was added way back
when. But my new development depends on this bug being fixed, and it
should be fixed regardless as it causes ftrace to disable itself when
triggered, and a reboot is required to enable it again.

The bug is that the function probe does not disable itself properly
if there's another probe of its type still enabled. For example:

 # cd /sys/kernel/debug/tracing
 # echo schedule:traceoff > set_ftrace_filter
 # echo do_IRQ:traceoff > set_ftrace_filter
 # echo \!do_IRQ:traceoff > /debug/tracing/set_ftrace_filter
 # echo do_IRQ:traceoff > set_ftrace_filter

The above registers two traceoff probes (one for schedule and one for
do_IRQ, and then removes do_IRQ. But since there still exists one for
schedule, it is not done properly. When adding do_IRQ back, the breakage
in the accounting is noticed by the ftrace self tests, and it causes
a warning and disables ftrace.


Please pull the latest trace-v4.11-rc5-2 tree, which can be found at:


  git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v4.11-rc5-2

Tag SHA1: fe8a1251ab0940f3807c2cc1228906681b3880da
Head SHA1: 82cc4fc2e70ec5baeff8f776f2773abc8b2cc0ae


Steven Rostedt (VMware) (1):
  ftrace: Fix removing of second function probe


 kernel/trace/ftrace.c | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)
---
commit 82cc4fc2e70ec5baeff8f776f2773abc8b2cc0ae
Author: Steven Rostedt (VMware) 
Date:   Fri Apr 14 17:45:45 2017 -0400

ftrace: Fix removing of second function probe

When two function probes are added to set_ftrace_filter, and then one of
them is removed, the update to the function locations is not performed, and
the record keeping of the function states are corrupted, and causes an
ftrace_bug() to occur.

This is easily reproducable by adding two probes, removing one, and then
adding it back again.

 # cd /sys/kernel/debug/tracing
 # echo schedule:traceoff > set_ftrace_filter
 # echo do_IRQ:traceoff > set_ftrace_filter
 # echo \!do_IRQ:traceoff > /debug/tracing/set_ftrace_filter
 # echo do_IRQ:traceoff > set_ftrace_filter

Causes:
 [ cut here ]
 WARNING: CPU: 2 PID: 1098 at kernel/trace/ftrace.c:2369 
ftrace_get_addr_curr+0x143/0x220
 Modules linked in: [...]
 CPU: 2 PID: 1098 Comm: bash Not tainted 4.10.0-test+ #405
 Hardware name: Hewlett-Packard HP Compaq Pro 6300 SFF/339A, BIOS K01 
v02.05 05/07/2012
 Call Trace:
  dump_stack+0x68/0x9f
  __warn+0x111/0x130
  ? trace_irq_work_interrupt+0xa0/0xa0
  warn_slowpath_null+0x1d/0x20
  ftrace_get_addr_curr+0x143/0x220
  ? __fentry__+0x10/0x10
  ftrace_replace_code+0xe3/0x4f0
  ? ftrace_int3_handler+0x90/0x90
  ? printk+0x99/0xb5
  ? 0x8100
  ftrace_modify_all_code+0x97/0x110
  arch_ftrace_update_code+0x10/0x20
  ftrace_run_update_code+0x1c/0x60
  ftrace_run_modify_code.isra.48.constprop.62+0x8e/0xd0
  register_ftrace_function_probe+0x4b6/0x590
  ? ftrace_startup+0x310/0x310
  ? debug_lockdep_rcu_enabled.part.4+0x1a/0x30
  ? update_stack_state+0x88/0x110
  ? ftrace_regex_write.isra.43.part.44+0x1d3/0x320
  ? preempt_count_sub+0x18/0xd0
  ? mutex_lock_nested+0x104/0x800
  ? ftrace_regex_write.isra.43.part.44+0x1d3/0x320
  ? __unwind_start+0x1c0/0x1c0
  ? _mutex_lock_nest_lock+0x800/0x800
  ftrace_trace_probe_callback.isra.3+0xc0/0x130
  ? func_set_flag+0xe0/0xe0
  ? __lock_acquire+0x642/0x1790
  ? __might_fault+0x1e/0x20
  ? trace_get_user+0x398/0x470
  ? strcmp+0x35/0x60
  ftrace_trace_onoff_callback+0x48/0x70
  ftrace_regex_write.isra.43.part.44+0x251/0x320
  ? match_records+0x420/0x420
  ftrace_filter_write+0x2b/0x30
  __vfs_write+0xd7/0x330
  ? do_loop_readv_writev+0x120/0x120
  ? locks_remove_posix+0x90/0x2f0
  ? do_lock_file_wait+0x160/0x160
  ? __lock_is_held+0x93/0x100
  ? rcu_read_lock_sched_held+0x5c/0xb0
  ? preempt_count_sub+0x18/0xd0
  ? __sb_start_write+0x10a/0x230
  ? vfs_write+0x222/0x240
  vfs_write+0xef/0x240
  SyS_write+0xab/0x130
  ? SyS_read+0x130/0x130
  ? trace_hardirqs_on_caller+0x182/0x280
  ? trace_hardirqs_on_thunk+0x1a/0x1c
  entry_SYSCALL_64_fastpath+0x18/0xad
 RIP: 0033:0x7fe61c157c30
 RSP: 002b:7ffe87890258 EFLAGS: 0246 ORIG_RAX: 0001
 RAX: ffda RBX: 8114a410 RCX: 7fe61c157c30
 RDX: 0010 RSI: 55814798f5e0 RDI: 0001
 RBP: 8800c9027f98 R08: 7fe61c422740 R09: 7fe61ca53700
 R10: 0073 R11: 0246 R12: 558147a36400
 R13: 7ffe8788f160 R14: 0024 R15: 7ffe8788f15c
   

Re: 4.10.9 nok with realtek wlan, atom

2017-04-15 Thread Larry Finger

On 04/14/2017 03:26 PM, rupert THURNER wrote:

On Thu, Feb 9, 2017 at 9:09 PM, Larry Finger  wrote:

On 02/09/2017 01:43 PM, Bjorn Helgaas wrote:


[+cc rtl8192ce folks in case they've seen this]

On Thu, Feb 09, 2017 at 03:45:01PM +0100, rupert THURNER wrote:


hi,

not technical expert enough, i just wanted to give a short user
feedback. for realtek wlan on atom, kernels up to 4.9.5 are ok, and
kernel 4.10.0-rc7-g926af6273fc6 (arch linux-git version numbering) as
well. kernels 4.9.6, 4.9.7, and 4.9.8 fail, i.e. connection to a WLAN
hotspot is possible then drops, or connecting to wlan fails
alltogether.



Thanks very much for your report, and sorry for the inconvenience.

v4.10-rc7 works, so I guess we don't need to worry about fixing v4.10.

But the stable kernels v4.9.6, v4.9.7, and v4.9.8 are broken, so we
need to figure out why and make sure we fix the v4.9 stable series.

I can't tell yet whether this is PCI-related or not.  If it is,
4922a6a5cfa7 ("PCI: Enumerate switches below PCI-to-PCIe bridges")
appeared in v4.9.6, and there is a known issue with that.  The issue
should be fixed by 610c2b7ff8f6 ("PCI/ASPM: Handle PCI-to-PCIe bridges
as roots of PCIe hierarchies"), which appeared in v4.9.9, so I guess
the first thing to do would be to test v4.9.9.

If it's not fixed in v4.9.9, can you share the complete dmesg log
(output of "dmesg" command) and "lspci -vv" output for v4.9.5 (last
known working version) and v4.9.6 (first known broken version)?  On
v4.9.6, collect the dmesg output after the failure occurs.


24: PCI 300.0: 0282 WLAN controller
  [Created at pci.366]
  Model: "Realtek RTL8188CE 802.11b/g/n WiFi Adapter"
  Device: pci 0x8176 "RTL8188CE 802.11b/g/n WiFi Adapter"
  Revision: 0x01
  Driver: "rtl8192ce"
  Driver Modules: "rtl8192ce"
  Device File: wlp3s0
  Features: WLAN



It would be helpful if someone were to bisect this issue. The only issue
that comes to mind was fixed in commit 52f5631a4c05 ("rtlwifi: rtl8192ce:
Fix loading of incorrect firmware") which is in 4.10-rc7 and will be
backported to 4.9.

The above issue is one that could not be reproduced on my hardware, thus it
took Jurij Smakov to find the fix. Without his bisection of the problem, who
knows how long it would have taken to find my edit mistake.


larry, using the newest kernel 4.10.8 the network connection dropps
again irregular.

# dmesg
[0.00] Linux version 4.10.9-1-ARCH (builduser@tobias) (gcc
version 6.3.1 20170306 (GCC) ) #1 SMP PREEMPT Sat Apr 8 12:39:59 CEST
2017
[   11.933373] rtl8192ce: rtl8192ce: Power Save off (module option)
[   11.933396] rtl8192ce: Using firmware rtlwifi/rtl8192cfw.bin
[   11.978307] ieee80211 phy0: Selected rate control algorithm 'rtl_rc'
[   11.978945] rtlwifi: rtlwifi: wireless switch is on

# lspci -vv
Subsystem: Realtek Semiconductor Co., Ltd. RTL8188CE 802.11b/g/n WiFi Adapter
Kernel driver in use: rtl8192ce


Is firmware rtlwifi/rtl8192cfw.bin also used on kernels that work?

Larry




[PATCH 1/3] mtd: sharpsl: add sharpslpart MTD partition parser

2017-04-15 Thread Andrea Adami
The Sharp SL Series (Zaurus) PXA handhelds have 16/64/128M of NAND flash
and share the same layout of the first 7M partition, managed by Sharp FTL.

The purpose of this self-contained patch is to add a common parser and
remove the hardcoded sizes in the board files (these devices are not yet
converted to devicetree).
Users will have benefits because the mtdparts= tag will not be necessary
anymore and they will be free to repartition the little sized flash.

The obsolete bootloader can not pass the partitioning info to modern
kernels anymore so it has to be read from flash at known logical addresses.
(see http://www.h5.dion.ne.jp/~rimemoon/zaurus/memo_006.htm )

In kernel, under arch/arm/mach-pxa we have already 8 machines:
MACH_POODLE, MACH_CORGI, MACH_SHEPERD, MACH_HUSKY, MACH_AKITA, MACH_SPITZ,
MACH_BORZOI, MACH_TOSA.
Lost after the 2.4 vendor kernel are MACH_BOXER and MACH_TERRIER.

Almost every model has different factory partitioning: add to this the
units can be repartitioned by users with userspace tools (nandlogical)
and installers for popular (back then) linux distributions.

The Parameter Area in the first (boot) partition extends from 0x0004 to
0x0007bfff (176k) and contains two copies of the partition table:
...
0x0006: Partition Info1 16k
0x00064000: Partition Info2 16k
0x00668000: Model   16k
...

The first 7M partition is managed by the Sharp FTL reserving 5% + 1 blocks
for wear-leveling: some blocks are remapped and one layer of translation
(logical to physical) is necessary.

There isn't much documentation about this FTL in the 2.4 sources, just the
MTD methods for reading and writing using logical addresses and the block
management (wear-leveling, use counter).
For the purpose of the MTD parser only the read part of the code was taken.

The NAND drivers that can use this parser are sharpsl.c and tmio_nand.c.

Signed-off-by: Andrea Adami 
---
 drivers/mtd/Kconfig   |   8 ++
 drivers/mtd/Makefile  |   2 +
 drivers/mtd/sharpsl_ftl.c | 309 ++
 drivers/mtd/sharpsl_ftl.h |  34 +
 drivers/mtd/sharpslpart.c | 142 +
 5 files changed, 495 insertions(+)
 create mode 100644 drivers/mtd/sharpsl_ftl.c
 create mode 100644 drivers/mtd/sharpsl_ftl.h
 create mode 100644 drivers/mtd/sharpslpart.c

diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index e83a279..5c96127 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -155,6 +155,14 @@ config MTD_BCM47XX_PARTS
  This provides partitions parser for devices based on BCM47xx
  boards.
 
+config MTD_SHARPSL_PARTS
+   tristate "Sharp SL Series NAND flash partition parser"
+   depends on MTD_NAND_SHARPSL || MTD_NAND_TMIO
+   help
+ This provides the read-only FTL logic necessary to read the partition
+ table from the NAND flash of Sharp SL Series (Zaurus) and the MTD
+ partition parser using this code.
+
 comment "User Modules And Translation Layers"
 
 #
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 99bb9a1..89f707b 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -13,6 +13,8 @@ obj-$(CONFIG_MTD_AFS_PARTS)   += afs.o
 obj-$(CONFIG_MTD_AR7_PARTS)+= ar7part.o
 obj-$(CONFIG_MTD_BCM63XX_PARTS)+= bcm63xxpart.o
 obj-$(CONFIG_MTD_BCM47XX_PARTS)+= bcm47xxpart.o
+obj-$(CONFIG_MTD_SHARPSL_PARTS)+= sharpsl-part.o
+sharpsl-part-objs := sharpsl_ftl.o sharpslpart.o
 
 # 'Users' - code which presents functionality to userspace.
 obj-$(CONFIG_MTD_BLKDEVS)  += mtd_blkdevs.o
diff --git a/drivers/mtd/sharpsl_ftl.c b/drivers/mtd/sharpsl_ftl.c
new file mode 100644
index 000..d8ebefe
--- /dev/null
+++ b/drivers/mtd/sharpsl_ftl.c
@@ -0,0 +1,309 @@
+/*
+ * MTD method for NAND accessing via logical address (SHARP FTL)
+ *
+ * Copyright (C) 2017 Andrea Adami 
+ *
+ * Based on 2.4 sources: drivers/mtd/nand/sharp_sl_logical.c
+ * Copyright (C) 2002  SHARP
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "sharpsl_ftl.h"
+
+/* oob structure */
+#define NAND_NOOB_LOGADDR_00   8
+#define NAND_NOOB_LOGADDR_01   9
+#define NAND_NOOB_LOGADDR_10   10
+#define NAND_NOOB_LOGADDR_11   11
+#define NAND_NOOB_LOGADDR_20   12
+#define NAND_NOOB_LOGADDR_21   13
+
+/* Logical Table */
+struct mtd_logical {
+   u32 size;   /* size of the handled partition */
+   

[PATCH 2/3] mtd: nand: sharpsl.c: prefer sharpslpart MTD partition parser

2017-04-15 Thread Andrea Adami
This is the specific parser for Sharp SL Series (Zaurus).

Signed-off-by: Andrea Adami 
---
 drivers/mtd/nand/sharpsl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 064ca17..2d1ba0e 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -108,6 +108,8 @@ static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, 
const u_char * dat,
 /*
  * Main initialization routine
  */
+static const char * const probes[] = { "sharpslpart", NULL };
+
 static int sharpsl_nand_probe(struct platform_device *pdev)
 {
struct nand_chip *this;
@@ -183,7 +185,7 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
/* Register the partitions */
mtd->name = "sharpsl-nand";
 
-   err = mtd_device_parse_register(mtd, NULL, NULL,
+   err = mtd_device_parse_register(mtd, probes, NULL,
data->partitions, data->nr_partitions);
if (err)
goto err_add;
-- 
2.7.4



[PATCH 3/3] mtd: nand: tmio_nand.c: prefer sharpslpart MTD partition parser

2017-04-15 Thread Andrea Adami
This is the specific parser for Sharp SL Series (Zaurus)

Signed-off-by: Andrea Adami 
---
 drivers/mtd/nand/tmio_nand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c
index fc5e773..f3612ac 100644
--- a/drivers/mtd/nand/tmio_nand.c
+++ b/drivers/mtd/nand/tmio_nand.c
@@ -357,6 +357,8 @@ static void tmio_hw_stop(struct platform_device *dev, 
struct tmio_nand *tmio)
cell->disable(dev);
 }
 
+static const char * const probes[] = { "sharpslpart", NULL };
+
 static int tmio_probe(struct platform_device *dev)
 {
struct tmio_nand_data *data = dev_get_platdata(&dev->dev);
@@ -440,7 +442,7 @@ static int tmio_probe(struct platform_device *dev)
goto err_irq;
 
/* Register the partitions */
-   retval = mtd_device_parse_register(mtd, NULL, NULL,
+   retval = mtd_device_parse_register(mtd, probes, NULL,
   data ? data->partition : NULL,
   data ? data->num_partitions : 0);
if (!retval)
-- 
2.7.4



[PATCH 0/3] mtd: sharpslpart partition parser

2017-04-15 Thread Andrea Adami
This patchset introduces a simple partition parser for the Sharp SL
Series PXA handhelds. More details in the commit text.

I have set in cc the ARM PXA maintainers because this is the MTD part of
a planned wider patchset cleaning the Zaurus board files.

Andrea Adami (3):
  mtd: sharpsl: add sharpslpart MTD partition parser
  mtd: nand: sharpsl.c: prefer sharpslpart MTD partition parser
  mtd: nand: tmio_nand.c: prefer sharpslpart MTD partition parser

 drivers/mtd/Kconfig  |   8 ++
 drivers/mtd/Makefile |   2 +
 drivers/mtd/nand/sharpsl.c   |   4 +-
 drivers/mtd/nand/tmio_nand.c |   4 +-
 drivers/mtd/sharpsl_ftl.c| 309 +++
 drivers/mtd/sharpsl_ftl.h|  34 +
 drivers/mtd/sharpslpart.c| 142 
 7 files changed, 501 insertions(+), 2 deletions(-)
 create mode 100644 drivers/mtd/sharpsl_ftl.c
 create mode 100644 drivers/mtd/sharpsl_ftl.h
 create mode 100644 drivers/mtd/sharpslpart.c

-- 
2.7.4



Re: [PATCH] Revert "mm, page_alloc: only use per-cpu allocator for irq-safe requests"

2017-04-15 Thread Mel Gorman
On Sat, Apr 15, 2017 at 09:28:33PM +0200, Jesper Dangaard Brouer wrote:
> On Sat, 15 Apr 2017 15:53:50 +0100
> Mel Gorman  wrote:
> 
> > This reverts commit 374ad05ab64d696303cec5cc8ec3a65d457b7b1c. While the
> > patch worked great for userspace allocations, the fact that softirq loses
> > the per-cpu allocator caused problems. It needs to be redone taking into
> > account that a separate list is needed for hard/soft IRQs or alternatively
> > find a cheap way of detecting reentry due to an interrupt. Both are possible
> > but sufficiently tricky that it shouldn't be rushed. Jesper had one method
> > for allowing softirqs but reported that the cost was high enough that it
> > performed similarly to a plain revert. His figures for netperf TCP_STREAM
> > were as follows
> > 
> > Baseline v4.10.0  : 60316 Mbit/s
> > Current 4.11.0-rc6: 47491 Mbit/s
> > This patch: 60662 Mbit/s
> (should instead state "Jesper's patch" or "His patch")
> 

Yes, you are correct of course.

> Ran same test (8 parallel netperf TCP_STREAMs) with this patch applied:
> 
>  This patch 60106 Mbit/s (average of 7 iteration 60 sec runs)
> 
> With these speeds I'm starting to hit the memory bandwidth of my machines.
> Thus, the 60 GBit/s measurement cannot be used to validate the
> performance impact of reverting this compared to my softirq patch, it
> only shows we fixed the regression.  (I'm suspicious as I see a higher
> contention on the page allocator lock (4% vs 1.3%) with this patch and
> still same performance... but lets worry about that outside the rc-series).
> 

Well, in itself that limitation highlights that evaluating this is
challenging and needs careful treatment. Otherwise two different
approaches can seem equivalent only because a hardware-related
bottleneck was at play.

-- 
Mel Gorman
SUSE Labs


pinctrl: imx: Checking reuse of grouping functionality

2017-04-15 Thread SF Markus Elfring
Hello,

A preprocessor symbol like “CONFIG_GENERIC_PINCTRL_GROUPS” was introduced
by the commit c033a718f615b6b3ddc83ce3e0a217c30bd09cb5 (“pinctrl: stricten up
generic group code”) on 2017-01-03. Some functions are only available then
when this macro is defined.

I have got the impression that the corresponding programming interface is used
by the source file “drivers/pinctrl/freescale/pinctrl-imx.c” unconditionally.
How do you think about to extend specifications for conditional compilation 
there?

Regards,
Markus


Re: [PATCH] Revert "mm, page_alloc: only use per-cpu allocator for irq-safe requests"

2017-04-15 Thread Jesper Dangaard Brouer
On Sat, 15 Apr 2017 15:53:50 +0100
Mel Gorman  wrote:

> This reverts commit 374ad05ab64d696303cec5cc8ec3a65d457b7b1c. While the
> patch worked great for userspace allocations, the fact that softirq loses
> the per-cpu allocator caused problems. It needs to be redone taking into
> account that a separate list is needed for hard/soft IRQs or alternatively
> find a cheap way of detecting reentry due to an interrupt. Both are possible
> but sufficiently tricky that it shouldn't be rushed. Jesper had one method
> for allowing softirqs but reported that the cost was high enough that it
> performed similarly to a plain revert. His figures for netperf TCP_STREAM
> were as follows
> 
> Baseline v4.10.0  : 60316 Mbit/s
> Current 4.11.0-rc6: 47491 Mbit/s
> This patch: 60662 Mbit/s
(should instead state "Jesper's patch" or "His patch")

Ran same test (8 parallel netperf TCP_STREAMs) with this patch applied:

 This patch 60106 Mbit/s (average of 7 iteration 60 sec runs)

With these speeds I'm starting to hit the memory bandwidth of my machines.
Thus, the 60 GBit/s measurement cannot be used to validate the
performance impact of reverting this compared to my softirq patch, it
only shows we fixed the regression.  (I'm suspicious as I see a higher
contention on the page allocator lock (4% vs 1.3%) with this patch and
still same performance... but lets worry about that outside the rc-series).

I would be interested in Tariq to re-run these benchmarks on some
hardware with enough memory bandwidth for 100Gbit/s throughput.


> As this is a regression, I wish to revert to noirq allocator for now and
> go back to the drawing board.
> 
> Signed-off-by: Mel Gorman 
> Reported-by: Tariq Toukan 

Acked-by: Jesper Dangaard Brouer 

> ---
>  mm/page_alloc.c | 43 ---
>  1 file changed, 20 insertions(+), 23 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 6cbde310abed..3bba4f46214c 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1090,10 +1090,10 @@ static void free_pcppages_bulk(struct zone *zone, int 
> count,
>  {
>   int migratetype = 0;
>   int batch_free = 0;
> - unsigned long nr_scanned, flags;
> + unsigned long nr_scanned;
>   bool isolated_pageblocks;
>  
> - spin_lock_irqsave(&zone->lock, flags);
> + spin_lock(&zone->lock);
>   isolated_pageblocks = has_isolate_pageblock(zone);
>   nr_scanned = node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED);
>   if (nr_scanned)
> @@ -1142,7 +1142,7 @@ static void free_pcppages_bulk(struct zone *zone, int 
> count,
>   trace_mm_page_pcpu_drain(page, 0, mt);
>   } while (--count && --batch_free && !list_empty(list));
>   }
> - spin_unlock_irqrestore(&zone->lock, flags);
> + spin_unlock(&zone->lock);
>  }
>  
>  static void free_one_page(struct zone *zone,
> @@ -1150,9 +1150,8 @@ static void free_one_page(struct zone *zone,
>   unsigned int order,
>   int migratetype)
>  {
> - unsigned long nr_scanned, flags;
> - spin_lock_irqsave(&zone->lock, flags);
> - __count_vm_events(PGFREE, 1 << order);
> + unsigned long nr_scanned;
> + spin_lock(&zone->lock);
>   nr_scanned = node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED);
>   if (nr_scanned)
>   __mod_node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED, 
> -nr_scanned);
> @@ -1162,7 +1161,7 @@ static void free_one_page(struct zone *zone,
>   migratetype = get_pfnblock_migratetype(page, pfn);
>   }
>   __free_one_page(page, pfn, zone, order, migratetype);
> - spin_unlock_irqrestore(&zone->lock, flags);
> + spin_unlock(&zone->lock);
>  }
>  
>  static void __meminit __init_single_page(struct page *page, unsigned long 
> pfn,
> @@ -1240,6 +1239,7 @@ void __meminit reserve_bootmem_region(phys_addr_t 
> start, phys_addr_t end)
>  
>  static void __free_pages_ok(struct page *page, unsigned int order)
>  {
> + unsigned long flags;
>   int migratetype;
>   unsigned long pfn = page_to_pfn(page);
>  
> @@ -1247,7 +1247,10 @@ static void __free_pages_ok(struct page *page, 
> unsigned int order)
>   return;
>  
>   migratetype = get_pfnblock_migratetype(page, pfn);
> + local_irq_save(flags);
> + __count_vm_events(PGFREE, 1 << order);
>   free_one_page(page_zone(page), page, pfn, order, migratetype);
> + local_irq_restore(flags);
>  }
>  
>  static void __init __free_pages_boot_core(struct page *page, unsigned int 
> order)
> @@ -2219,9 +,8 @@ static int rmqueue_bulk(struct zone *zone, unsigned int 
> order,
>   int migratetype, bool cold)
>  {
>   int i, alloced = 0;
> - unsigned long flags;
>  
> - spin_lock_irqsave(&zone->lock, flags);
> + spin_lock(&zone->lock);
>   for (i = 0; i < count; ++i) {
>   struct page *page = __rmqueue(zone, order, migratetype);
>  

[GIT PULL 07/19] lightnvm: don't check for failure from mempool_alloc()

2017-04-15 Thread Matias Bjørling
From: NeilBrown 

mempool_alloc() cannot fail if the gfp flags allow it to
sleep, and both GFP_KERNEL and GFP_NOIO allows for sleeping.

So rrpc_move_valid_pages() and rrpc_make_rq() don't need to
test the return value.

Signed-off-by: NeilBrown 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/rrpc.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c
index 4e4c299..a8acf9e 100644
--- a/drivers/lightnvm/rrpc.c
+++ b/drivers/lightnvm/rrpc.c
@@ -318,10 +318,6 @@ static int rrpc_move_valid_pages(struct rrpc *rrpc, struct 
rrpc_block *rblk)
}
 
page = mempool_alloc(rrpc->page_pool, GFP_NOIO);
-   if (!page) {
-   bio_put(bio);
-   return -ENOMEM;
-   }
 
while ((slot = find_first_zero_bit(rblk->invalid_pages,
nr_sec_per_blk)) < nr_sec_per_blk) {
@@ -1006,11 +1002,6 @@ static blk_qc_t rrpc_make_rq(struct request_queue *q, 
struct bio *bio)
}
 
rqd = mempool_alloc(rrpc->rq_pool, GFP_KERNEL);
-   if (!rqd) {
-   pr_err_ratelimited("rrpc: not able to queue bio.");
-   bio_io_error(bio);
-   return BLK_QC_T_NONE;
-   }
memset(rqd, 0, sizeof(struct nvm_rq));
 
err = rrpc_submit_io(rrpc, bio, rqd, NVM_IOTYPE_NONE);
-- 
2.9.3



[GIT PULL 06/19] lightnvm: enable nvme size compile asserts

2017-04-15 Thread Matias Bjørling
The asserts in _nvme_nvm_check_size are not compiled due to the function
not begin called. Make sure that it is called, and also fix the wrong
sizes of asserts for nvme_nvm_addr_format, and nvme_nvm_bb_tbl, which
checked for number of bits instead of bytes.

Reported-by: Scott Bauer 
Signed-off-by: Matias Bjørling 
---
 drivers/nvme/host/lightnvm.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index 4ea9c93..12c5a40 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -241,9 +241,9 @@ static inline void _nvme_nvm_check_size(void)
BUILD_BUG_ON(sizeof(struct nvme_nvm_l2ptbl) != 64);
BUILD_BUG_ON(sizeof(struct nvme_nvm_erase_blk) != 64);
BUILD_BUG_ON(sizeof(struct nvme_nvm_id_group) != 960);
-   BUILD_BUG_ON(sizeof(struct nvme_nvm_addr_format) != 128);
+   BUILD_BUG_ON(sizeof(struct nvme_nvm_addr_format) != 16);
BUILD_BUG_ON(sizeof(struct nvme_nvm_id) != 4096);
-   BUILD_BUG_ON(sizeof(struct nvme_nvm_bb_tbl) != 512);
+   BUILD_BUG_ON(sizeof(struct nvme_nvm_bb_tbl) != 64);
 }
 
 static int init_grps(struct nvm_id *nvm_id, struct nvme_nvm_id *nvme_nvm_id)
@@ -797,6 +797,8 @@ int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, 
int node)
struct request_queue *q = ns->queue;
struct nvm_dev *dev;
 
+   _nvme_nvm_check_size();
+
dev = nvm_alloc_dev(node);
if (!dev)
return -ENOMEM;
-- 
2.9.3



[GIT PULL 10/19] lightnvm: bad type conversion for nvme control bits

2017-04-15 Thread Matias Bjørling
From: Javier González 

The NVMe I/O command control bits are 16 bytes, but is interpreted as
32 bytes in the lightnvm user I/O data path.

Signed-off-by: Javier González 
Signed-off-by: Matias Bjørling 
---
 drivers/nvme/host/lightnvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index 12c5a40..4b78090 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -754,7 +754,7 @@ static int nvme_nvm_user_vcmd(struct nvme_ns *ns, int admin,
c.common.cdw2[1] = cpu_to_le32(vcmd.cdw3);
/* cdw11-12 */
c.ph_rw.length = cpu_to_le16(vcmd.nppas);
-   c.ph_rw.control  = cpu_to_le32(vcmd.control);
+   c.ph_rw.control  = cpu_to_le16(vcmd.control);
c.common.cdw10[3] = cpu_to_le32(vcmd.cdw13);
c.common.cdw10[4] = cpu_to_le32(vcmd.cdw14);
c.common.cdw10[5] = cpu_to_le32(vcmd.cdw15);
-- 
2.9.3



[GIT PULL 02/19] nvme/lightnvm: Prevent small buffer overflow in nvme_nvm_identify

2017-04-15 Thread Matias Bjørling
From: Scott Bauer 

There are two closely named structs in lightnvm:
struct nvme_nvm_addr_format and
struct nvme_addr_format.

The first struct has 4 reserved bytes at the end, the second does not.
(gdb) p sizeof(struct nvme_nvm_addr_format)
$1 = 16
(gdb) p sizeof(struct nvm_addr_format)
$2 = 12

In the nvme_nvm_identify function we memcpy from the larger struct to the
smaller struct. We incorrectly pass the length of the larger struct
and overflow by 4 bytes, lets not do that.

Signed-off-by: Scott Bauer 
Signed-off-by: Matias Bjørling 
---
 drivers/nvme/host/lightnvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index 21cac85..fd98954 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -324,7 +324,7 @@ static int nvme_nvm_identity(struct nvm_dev *nvmdev, struct 
nvm_id *nvm_id)
nvm_id->cap = le32_to_cpu(nvme_nvm_id->cap);
nvm_id->dom = le32_to_cpu(nvme_nvm_id->dom);
memcpy(&nvm_id->ppaf, &nvme_nvm_id->ppaf,
-   sizeof(struct nvme_nvm_addr_format));
+   sizeof(struct nvm_addr_format));
 
ret = init_grps(nvm_id, nvme_nvm_id);
 out:
-- 
2.9.3



[GIT PULL 09/19] lightnvm: fix cleanup order of disk on init error

2017-04-15 Thread Matias Bjørling
From: Javier González 

Reorder disk allocation such that the disk structure can be put
safely.

Signed-off-by: Javier González 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/core.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 5eea3d5..5f84d2a 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -264,15 +264,15 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct 
nvm_ioctl_create *create)
goto err_t;
}
 
+   tdisk = alloc_disk(0);
+   if (!tdisk)
+   goto err_dev;
+
tqueue = blk_alloc_queue_node(GFP_KERNEL, dev->q->node);
if (!tqueue)
-   goto err_dev;
+   goto err_disk;
blk_queue_make_request(tqueue, tt->make_rq);
 
-   tdisk = alloc_disk(0);
-   if (!tdisk)
-   goto err_queue;
-
sprintf(tdisk->disk_name, "%s", create->tgtname);
tdisk->flags = GENHD_FL_EXT_DEVT;
tdisk->major = 0;
@@ -308,9 +308,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct 
nvm_ioctl_create *create)
if (tt->exit)
tt->exit(targetdata);
 err_init:
-   put_disk(tdisk);
-err_queue:
blk_cleanup_queue(tqueue);
+err_disk:
+   put_disk(tdisk);
 err_dev:
nvm_remove_tgt_dev(tgt_dev, 0);
 err_t:
-- 
2.9.3



[GIT PULL 03/19] lightnvm: submit erases using the I/O path

2017-04-15 Thread Matias Bjørling
From: Javier González 

Until now erases have been submitted as synchronous commands through a
dedicated erase function. In order to enable targets implementing
asynchronous erases, refactor the erase path so that it uses the normal
async I/O submission functions. If a target requires sync I/O, it can
implement it internally. Also, adapt rrpc to use the new erase path.

Signed-off-by: Javier González 
Fixed spelling error.
Signed-off-by: Matias Bjørling 

Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/core.c  | 54 +++-
 drivers/lightnvm/rrpc.c  |  3 +--
 drivers/nvme/host/lightnvm.c | 32 --
 include/linux/lightnvm.h |  8 +++
 4 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 5262ba6..95105c4 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -590,11 +590,11 @@ int nvm_set_tgt_bb_tbl(struct nvm_tgt_dev *tgt_dev, 
struct ppa_addr *ppas,
 
memset(&rqd, 0, sizeof(struct nvm_rq));
 
-   nvm_set_rqd_ppalist(dev, &rqd, ppas, nr_ppas, 1);
+   nvm_set_rqd_ppalist(tgt_dev, &rqd, ppas, nr_ppas, 1);
nvm_rq_tgt_to_dev(tgt_dev, &rqd);
 
ret = dev->ops->set_bb_tbl(dev, &rqd.ppa_addr, rqd.nr_ppas, type);
-   nvm_free_rqd_ppalist(dev, &rqd);
+   nvm_free_rqd_ppalist(tgt_dev, &rqd);
if (ret) {
pr_err("nvm: failed bb mark\n");
return -EINVAL;
@@ -626,34 +626,45 @@ int nvm_submit_io(struct nvm_tgt_dev *tgt_dev, struct 
nvm_rq *rqd)
 }
 EXPORT_SYMBOL(nvm_submit_io);
 
-int nvm_erase_blk(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *ppas, int 
flags)
+static void nvm_end_io_sync(struct nvm_rq *rqd)
 {
-   struct nvm_dev *dev = tgt_dev->parent;
+   struct completion *waiting = rqd->private;
+
+   complete(waiting);
+}
+
+int nvm_erase_sync(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *ppas,
+   int nr_ppas)
+{
+   struct nvm_geo *geo = &tgt_dev->geo;
struct nvm_rq rqd;
int ret;
-
-   if (!dev->ops->erase_block)
-   return 0;
-
-   nvm_map_to_dev(tgt_dev, ppas);
+   DECLARE_COMPLETION_ONSTACK(wait);
 
memset(&rqd, 0, sizeof(struct nvm_rq));
 
-   ret = nvm_set_rqd_ppalist(dev, &rqd, ppas, 1, 1);
+   rqd.opcode = NVM_OP_ERASE;
+   rqd.end_io = nvm_end_io_sync;
+   rqd.private = &wait;
+   rqd.flags = geo->plane_mode >> 1;
+
+   ret = nvm_set_rqd_ppalist(tgt_dev, &rqd, ppas, nr_ppas, 1);
if (ret)
return ret;
 
-   nvm_rq_tgt_to_dev(tgt_dev, &rqd);
+   ret = nvm_submit_io(tgt_dev, &rqd);
+   if (ret) {
+   pr_err("rrpr: erase I/O submission failed: %d\n", ret);
+   goto free_ppa_list;
+   }
+   wait_for_completion_io(&wait);
 
-   rqd.flags = flags;
-
-   ret = dev->ops->erase_block(dev, &rqd);
-
-   nvm_free_rqd_ppalist(dev, &rqd);
+free_ppa_list:
+   nvm_free_rqd_ppalist(tgt_dev, &rqd);
 
return ret;
 }
-EXPORT_SYMBOL(nvm_erase_blk);
+EXPORT_SYMBOL(nvm_erase_sync);
 
 int nvm_get_l2p_tbl(struct nvm_tgt_dev *tgt_dev, u64 slba, u32 nlb,
nvm_l2p_update_fn *update_l2p, void *priv)
@@ -732,10 +743,11 @@ void nvm_put_area(struct nvm_tgt_dev *tgt_dev, sector_t 
begin)
 }
 EXPORT_SYMBOL(nvm_put_area);
 
-int nvm_set_rqd_ppalist(struct nvm_dev *dev, struct nvm_rq *rqd,
+int nvm_set_rqd_ppalist(struct nvm_tgt_dev *tgt_dev, struct nvm_rq *rqd,
const struct ppa_addr *ppas, int nr_ppas, int vblk)
 {
-   struct nvm_geo *geo = &dev->geo;
+   struct nvm_dev *dev = tgt_dev->parent;
+   struct nvm_geo *geo = &tgt_dev->geo;
int i, plane_cnt, pl_idx;
struct ppa_addr ppa;
 
@@ -773,12 +785,12 @@ int nvm_set_rqd_ppalist(struct nvm_dev *dev, struct 
nvm_rq *rqd,
 }
 EXPORT_SYMBOL(nvm_set_rqd_ppalist);
 
-void nvm_free_rqd_ppalist(struct nvm_dev *dev, struct nvm_rq *rqd)
+void nvm_free_rqd_ppalist(struct nvm_tgt_dev *tgt_dev, struct nvm_rq *rqd)
 {
if (!rqd->ppa_list)
return;
 
-   nvm_dev_dma_free(dev, rqd->ppa_list, rqd->dma_ppa_list);
+   nvm_dev_dma_free(tgt_dev->parent, rqd->ppa_list, rqd->dma_ppa_list);
 }
 EXPORT_SYMBOL(nvm_free_rqd_ppalist);
 
diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c
index e68efbc..4e4c299 100644
--- a/drivers/lightnvm/rrpc.c
+++ b/drivers/lightnvm/rrpc.c
@@ -414,7 +414,6 @@ static void rrpc_block_gc(struct work_struct *work)
struct rrpc *rrpc = gcb->rrpc;
struct rrpc_block *rblk = gcb->rblk;
struct rrpc_lun *rlun = rblk->rlun;
-   struct nvm_tgt_dev *dev = rrpc->dev;
struct ppa_addr ppa;
 
mempool_free(gcb, rrpc->gcb_pool);
@@ -430,7 +429,7 @@ static void rrpc_block_gc(struct work_struct *work)
ppa.g.lun = rlun->bppa.g.lun;
ppa.g.blk = rblk->id;
 
-   if 

[GIT PULL 15/19] lightnvm: convert sprintf into strlcpy

2017-04-15 Thread Matias Bjørling
From: Javier González 

Convert sprintf calls to strlcpy in order to make possible buffer
overflow more obvious.

Signed-off-by: Javier González 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 258007a..2c26af3 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -273,7 +273,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct 
nvm_ioctl_create *create)
goto err_disk;
blk_queue_make_request(tqueue, tt->make_rq);
 
-   sprintf(tdisk->disk_name, "%s", create->tgtname);
+   strlcpy(tdisk->disk_name, create->tgtname, sizeof(tdisk->disk_name));
tdisk->flags = GENHD_FL_EXT_DEVT;
tdisk->major = 0;
tdisk->first_minor = 0;
@@ -1198,13 +1198,13 @@ static long nvm_ioctl_get_devices(struct file *file, 
void __user *arg)
list_for_each_entry(dev, &nvm_devices, devices) {
struct nvm_ioctl_device_info *info = &devices->info[i];
 
-   sprintf(info->devname, "%s", dev->name);
+   strlcpy(info->devname, dev->name, sizeof(info->devname));
 
/* kept for compatibility */
info->bmversion[0] = 1;
info->bmversion[1] = 0;
info->bmversion[2] = 0;
-   sprintf(info->bmname, "%s", "gennvm");
+   strlcpy(info->bmname, "gennvm", sizeof(info->bmname));
i++;
 
if (i > 31) {
-- 
2.9.3



[GIT PULL 14/19] lightnvm: fix type checks on rrpc

2017-04-15 Thread Matias Bjørling
From: Javier González 

sector_t is always unsigned, therefore avoid < 0 checks on it.

Signed-off-by: Javier González 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/rrpc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c
index 5dba544..cf0e28a 100644
--- a/drivers/lightnvm/rrpc.c
+++ b/drivers/lightnvm/rrpc.c
@@ -817,7 +817,7 @@ static int rrpc_read_ppalist_rq(struct rrpc *rrpc, struct 
bio *bio,
 
for (i = 0; i < npages; i++) {
/* We assume that mapping occurs at 4KB granularity */
-   BUG_ON(!(laddr + i >= 0 && laddr + i < rrpc->nr_sects));
+   BUG_ON(!(laddr + i < rrpc->nr_sects));
gp = &rrpc->trans_map[laddr + i];
 
if (gp->rblk) {
@@ -846,7 +846,7 @@ static int rrpc_read_rq(struct rrpc *rrpc, struct bio *bio, 
struct nvm_rq *rqd,
if (!is_gc && rrpc_lock_rq(rrpc, bio, rqd))
return NVM_IO_REQUEUE;
 
-   BUG_ON(!(laddr >= 0 && laddr < rrpc->nr_sects));
+   BUG_ON(!(laddr < rrpc->nr_sects));
gp = &rrpc->trans_map[laddr];
 
if (gp->rblk) {
-- 
2.9.3



[GIT PULL 08/19] lightnvm: double-clear of dev->lun_map on target init error

2017-04-15 Thread Matias Bjørling
From: Javier González 

The dev->lun_map bits are cleared twice if an target init error occurs.
First in the target clean routine, and then next in the nvm_tgt_create
error function. Make sure that it is only cleared once by extending
nvm_remove_tgt_devi() with a clear bit, such that clearing of bits can
ignored when cleaning up a successful initialized target.

Signed-off-by: Javier González 
Fix style.
Signed-off-by: Matias Bjørling 

Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/core.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index a14c52c..5eea3d5 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -89,7 +89,7 @@ static void nvm_release_luns_err(struct nvm_dev *dev, int 
lun_begin,
WARN_ON(!test_and_clear_bit(i, dev->lun_map));
 }
 
-static void nvm_remove_tgt_dev(struct nvm_tgt_dev *tgt_dev)
+static void nvm_remove_tgt_dev(struct nvm_tgt_dev *tgt_dev, int clear)
 {
struct nvm_dev *dev = tgt_dev->parent;
struct nvm_dev_map *dev_map = tgt_dev->map;
@@ -100,11 +100,14 @@ static void nvm_remove_tgt_dev(struct nvm_tgt_dev 
*tgt_dev)
int *lun_offs = ch_map->lun_offs;
int ch = i + ch_map->ch_off;
 
-   for (j = 0; j < ch_map->nr_luns; j++) {
-   int lun = j + lun_offs[j];
-   int lunid = (ch * dev->geo.luns_per_chnl) + lun;
+   if (clear) {
+   for (j = 0; j < ch_map->nr_luns; j++) {
+   int lun = j + lun_offs[j];
+   int lunid = (ch * dev->geo.luns_per_chnl) + lun;
 
-   WARN_ON(!test_and_clear_bit(lunid, dev->lun_map));
+   WARN_ON(!test_and_clear_bit(lunid,
+   dev->lun_map));
+   }
}
 
kfree(ch_map->lun_offs);
@@ -309,7 +312,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct 
nvm_ioctl_create *create)
 err_queue:
blk_cleanup_queue(tqueue);
 err_dev:
-   nvm_remove_tgt_dev(tgt_dev);
+   nvm_remove_tgt_dev(tgt_dev, 0);
 err_t:
kfree(t);
 err_reserve:
@@ -332,7 +335,7 @@ static void __nvm_remove_target(struct nvm_target *t)
if (tt->exit)
tt->exit(tdisk->private_data);
 
-   nvm_remove_tgt_dev(t->dev);
+   nvm_remove_tgt_dev(t->dev, 1);
put_disk(tdisk);
 
list_del(&t->list);
-- 
2.9.3



[GIT PULL 19/19] lightnvm: fix some error code in pblk-init.c

2017-04-15 Thread Matias Bjørling
From: Dan Carpenter 

There were a bunch of places in pblk_lines_init() where we didn't set an
error code.  And in pblk_writer_init() we accidentally return 1 instead
of a correct error code, which would result in a Oops later.

Fixes: 11a5d6fdf919 ("lightnvm: physical block device (pblk) target")
Signed-off-by: Dan Carpenter 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/pblk-init.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index 94653b1..3996e4b 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -543,7 +543,7 @@ static int pblk_lines_init(struct pblk *pblk)
long nr_bad_blks, nr_meta_blks, nr_free_blks;
int bb_distance;
int i;
-   int ret = 0;
+   int ret;
 
lm->sec_per_line = geo->sec_per_blk * geo->nr_luns;
lm->blk_per_line = geo->nr_luns;
@@ -638,12 +638,16 @@ static int pblk_lines_init(struct pblk *pblk)
}
 
l_mg->bb_template = kzalloc(lm->sec_bitmap_len, GFP_KERNEL);
-   if (!l_mg->bb_template)
+   if (!l_mg->bb_template) {
+   ret = -ENOMEM;
goto fail_free_meta;
+   }
 
l_mg->bb_aux = kzalloc(lm->sec_bitmap_len, GFP_KERNEL);
-   if (!l_mg->bb_aux)
+   if (!l_mg->bb_aux) {
+   ret = -ENOMEM;
goto fail_free_bb_template;
+   }
 
bb_distance = (geo->nr_luns) * geo->sec_per_pl;
for (i = 0; i < lm->sec_per_line; i += bb_distance)
@@ -667,8 +671,10 @@ static int pblk_lines_init(struct pblk *pblk)
 
pblk->lines = kcalloc(l_mg->nr_lines, sizeof(struct pblk_line),
GFP_KERNEL);
-   if (!pblk->lines)
+   if (!pblk->lines) {
+   ret = -ENOMEM;
goto fail_free_bb_aux;
+   }
 
nr_free_blks = 0;
for (i = 0; i < l_mg->nr_lines; i++) {
@@ -682,8 +688,10 @@ static int pblk_lines_init(struct pblk *pblk)
spin_lock_init(&line->lock);
 
nr_bad_blks = pblk_bb_line(pblk, line);
-   if (nr_bad_blks < 0 || nr_bad_blks > lm->blk_per_line)
+   if (nr_bad_blks < 0 || nr_bad_blks > lm->blk_per_line) {
+   ret = -EINVAL;
goto fail_free_lines;
+   }
 
line->blk_in_line = lm->blk_per_line - nr_bad_blks;
if (line->blk_in_line < lm->min_blk_line) {
@@ -733,7 +741,7 @@ static int pblk_writer_init(struct pblk *pblk)
pblk->writer_ts = kthread_create(pblk_write_ts, pblk, "pblk-writer-t");
if (IS_ERR(pblk->writer_ts)) {
pr_err("pblk: could not allocate writer kthread\n");
-   return 1;
+   return PTR_ERR(pblk->writer_ts);
}
 
return 0;
-- 
2.9.3



[GIT PULL 17/19] lightnvm: pblk-gc: fix an error pointer dereference in init

2017-04-15 Thread Matias Bjørling
From: Dan Carpenter 

These labels are reversed so we could end up dereferencing an error
pointer or leaking.

Fixes: 7f347ba6bb3a ("lightnvm: physical block device (pblk) target")
Signed-off-by: Dan Carpenter 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/pblk-gc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/lightnvm/pblk-gc.c b/drivers/lightnvm/pblk-gc.c
index 9b147cf..f173fd4 100644
--- a/drivers/lightnvm/pblk-gc.c
+++ b/drivers/lightnvm/pblk-gc.c
@@ -527,10 +527,10 @@ int pblk_gc_init(struct pblk *pblk)
 
return 0;
 
-fail_free_main_kthread:
-   kthread_stop(gc->gc_ts);
 fail_free_writer_kthread:
kthread_stop(gc->gc_writer_ts);
+fail_free_main_kthread:
+   kthread_stop(gc->gc_ts);
 
return ret;
 }
-- 
2.9.3



[GIT PULL 18/19] lightnvm: fix some WARN() messages

2017-04-15 Thread Matias Bjørling
From: Dan Carpenter 

WARN_ON() takes a condition, not an error message.  I slightly tweaked
some conditions so hopefully it's more clear.

Signed-off-by: Dan Carpenter 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/pblk-read.c | 12 ++--
 drivers/lightnvm/pblk-recovery.c |  2 +-
 drivers/lightnvm/pblk-write.c|  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/lightnvm/pblk-read.c b/drivers/lightnvm/pblk-read.c
index eff0982..bce7ed5 100644
--- a/drivers/lightnvm/pblk-read.c
+++ b/drivers/lightnvm/pblk-read.c
@@ -49,8 +49,8 @@ static void pblk_read_ppalist_rq(struct pblk *pblk, struct 
nvm_rq *rqd,
int i, j = 0;
 
/* logic error: lba out-of-bounds. Ignore read request */
-   if (!(blba + nr_secs < pblk->rl.nr_secs)) {
-   WARN_ON("pblk: read lbas out of bounds\n");
+   if (blba + nr_secs >= pblk->rl.nr_secs) {
+   WARN(1, "pblk: read lbas out of bounds\n");
return;
}
 
@@ -254,8 +254,8 @@ static void pblk_read_rq(struct pblk *pblk, struct nvm_rq 
*rqd,
sector_t lba = pblk_get_lba(bio);
 
/* logic error: lba out-of-bounds. Ignore read request */
-   if (!(lba < pblk->rl.nr_secs)) {
-   WARN_ON("pblk: read lba out of bounds\n");
+   if (lba >= pblk->rl.nr_secs) {
+   WARN(1, "pblk: read lba out of bounds\n");
return;
}
 
@@ -411,8 +411,8 @@ static int read_rq_gc(struct pblk *pblk, struct nvm_rq *rqd,
int valid_secs = 0;
 
/* logic error: lba out-of-bounds */
-   if (!(lba < pblk->rl.nr_secs)) {
-   WARN_ON("pblk: read lba out of bounds\n");
+   if (lba >= pblk->rl.nr_secs) {
+   WARN(1, "pblk: read lba out of bounds\n");
goto out;
}
 
diff --git a/drivers/lightnvm/pblk-recovery.c b/drivers/lightnvm/pblk-recovery.c
index 0d50f41..f8f8508 100644
--- a/drivers/lightnvm/pblk-recovery.c
+++ b/drivers/lightnvm/pblk-recovery.c
@@ -167,7 +167,7 @@ static int pblk_recov_l2p_from_emeta(struct pblk *pblk, 
struct pblk_line *line)
if (le64_to_cpu(lba_list[i]) == ADDR_EMPTY) {
spin_lock(&line->lock);
if (test_and_set_bit(i, line->invalid_bitmap))
-   WARN_ON_ONCE("pblk: rec. double invalidate:\n");
+   WARN_ONCE(1, "pblk: rec. double invalidate:\n");
else
line->vsc--;
spin_unlock(&line->lock);
diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-write.c
index ee57db9..74f7413 100644
--- a/drivers/lightnvm/pblk-write.c
+++ b/drivers/lightnvm/pblk-write.c
@@ -141,7 +141,7 @@ static void pblk_end_w_fail(struct pblk *pblk, struct 
nvm_rq *rqd)
 
/* Logic error */
if (bit > c_ctx->nr_valid) {
-   WARN_ON_ONCE("pblk: corrupted write request\n");
+   WARN_ONCE(1, "pblk: corrupted write request\n");
goto out;
}
 
-- 
2.9.3



[GIT PULL 12/19] lightnvm: make nvm_free static

2017-04-15 Thread Matias Bjørling
From: Javier González 

Prefix the nvm_free static function with a missing static keyword.

Signed-off-by: Javier González 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index a63b563..eb9ab1a 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -999,7 +999,7 @@ static int nvm_core_init(struct nvm_dev *dev)
return ret;
 }
 
-void nvm_free(struct nvm_dev *dev)
+static void nvm_free(struct nvm_dev *dev)
 {
if (!dev)
return;
-- 
2.9.3



[GIT PULL 13/19] lightnvm: clean unused variable

2017-04-15 Thread Matias Bjørling
From: Javier González 

Clean unused variable on lightnvm core.

Signed-off-by: Javier González 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/core.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index eb9ab1a..258007a 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -501,7 +501,6 @@ void nvm_part_to_tgt(struct nvm_dev *dev, sector_t *entries,
int *lun_roffs;
struct ppa_addr gaddr;
u64 pba = le64_to_cpu(entries[i]);
-   int off;
u64 diff;
 
if (!pba)
@@ -511,8 +510,6 @@ void nvm_part_to_tgt(struct nvm_dev *dev, sector_t *entries,
ch_rmap = &dev_rmap->chnls[gaddr.g.ch];
lun_roffs = ch_rmap->lun_offs;
 
-   off = gaddr.g.ch * geo->luns_per_chnl + gaddr.g.lun;
-
diff = ((ch_rmap->ch_off * geo->luns_per_chnl) +
(lun_roffs[gaddr.g.lun])) * geo->sec_per_lun;
 
-- 
2.9.3



[GIT PULL 11/19] lightnvm: allow to init targets on factory mode

2017-04-15 Thread Matias Bjørling
From: Javier González 

Target initialization has two responsibilities: creating the target
partition and instantiating the target. This patch enables to create a
factory partition (e.g., do not trigger recovery on the given target).
This is useful for target development and for being able to restore the
device state at any moment in time without requiring a full-device
erase.

Signed-off-by: Javier González 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/core.c   | 14 +++---
 drivers/lightnvm/rrpc.c   |  3 ++-
 include/linux/lightnvm.h  |  3 ++-
 include/uapi/linux/lightnvm.h |  4 
 4 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 5f84d2a..a63b563 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -280,7 +280,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct 
nvm_ioctl_create *create)
tdisk->fops = &nvm_fops;
tdisk->queue = tqueue;
 
-   targetdata = tt->init(tgt_dev, tdisk);
+   targetdata = tt->init(tgt_dev, tdisk, create->flags);
if (IS_ERR(targetdata))
goto err_init;
 
@@ -1244,8 +1244,16 @@ static long nvm_ioctl_dev_create(struct file *file, void 
__user *arg)
create.tgtname[DISK_NAME_LEN - 1] = '\0';
 
if (create.flags != 0) {
-   pr_err("nvm: no flags supported\n");
-   return -EINVAL;
+   __u32 flags = create.flags;
+
+   /* Check for valid flags */
+   if (flags & NVM_TARGET_FACTORY)
+   flags &= ~NVM_TARGET_FACTORY;
+
+   if (flags) {
+   pr_err("nvm: flag not supported\n");
+   return -EINVAL;
+   }
}
 
return __nvm_configure_create(&create);
diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c
index a8acf9e..5dba544 100644
--- a/drivers/lightnvm/rrpc.c
+++ b/drivers/lightnvm/rrpc.c
@@ -1506,7 +1506,8 @@ static int rrpc_luns_configure(struct rrpc *rrpc)
 
 static struct nvm_tgt_type tt_rrpc;
 
-static void *rrpc_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk)
+static void *rrpc_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk,
+  int flags)
 {
struct request_queue *bqueue = dev->q;
struct request_queue *tqueue = tdisk->queue;
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index eff7d1f..7dfa56e 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -436,7 +436,8 @@ static inline int ppa_cmp_blk(struct ppa_addr ppa1, struct 
ppa_addr ppa2)
 
 typedef blk_qc_t (nvm_tgt_make_rq_fn)(struct request_queue *, struct bio *);
 typedef sector_t (nvm_tgt_capacity_fn)(void *);
-typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *);
+typedef void *(nvm_tgt_init_fn)(struct nvm_tgt_dev *, struct gendisk *,
+   int flags);
 typedef void (nvm_tgt_exit_fn)(void *);
 typedef int (nvm_tgt_sysfs_init_fn)(struct gendisk *);
 typedef void (nvm_tgt_sysfs_exit_fn)(struct gendisk *);
diff --git a/include/uapi/linux/lightnvm.h b/include/uapi/linux/lightnvm.h
index fd19f36..c8aec4b 100644
--- a/include/uapi/linux/lightnvm.h
+++ b/include/uapi/linux/lightnvm.h
@@ -85,6 +85,10 @@ struct nvm_ioctl_create_conf {
};
 };
 
+enum {
+   NVM_TARGET_FACTORY = 1 << 0,/* Init target in factory mode */
+};
+
 struct nvm_ioctl_create {
char dev[DISK_NAME_LEN];/* open-channel SSD device */
char tgttype[NVM_TTYPE_NAME_MAX];   /* target type name */
-- 
2.9.3



[GIT PULL 05/19] lightnvm: free reverse device map

2017-04-15 Thread Matias Bjørling
From: Javier González 

Free the reverse mapping table correctly on target tear down

Signed-off-by: Javier González 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/core.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 95105c4..a14c52c 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -411,6 +411,18 @@ static int nvm_register_map(struct nvm_dev *dev)
return -ENOMEM;
 }
 
+static void nvm_unregister_map(struct nvm_dev *dev)
+{
+   struct nvm_dev_map *rmap = dev->rmap;
+   int i;
+
+   for (i = 0; i < dev->geo.nr_chnls; i++)
+   kfree(rmap->chnls[i].lun_offs);
+
+   kfree(rmap->chnls);
+   kfree(rmap);
+}
+
 static void nvm_map_to_dev(struct nvm_tgt_dev *tgt_dev, struct ppa_addr *p)
 {
struct nvm_dev_map *dev_map = tgt_dev->map;
@@ -992,7 +1004,7 @@ void nvm_free(struct nvm_dev *dev)
if (dev->dma_pool)
dev->ops->destroy_dma_pool(dev->dma_pool);
 
-   kfree(dev->rmap);
+   nvm_unregister_map(dev);
kfree(dev->lptbl);
kfree(dev->lun_map);
kfree(dev);
-- 
2.9.3



[GIT PULL 01/19] lightnvm: Fix error handling

2017-04-15 Thread Matias Bjørling
From: Christophe JAILLET 

According to error handling in this function, it is likely that going to
'out' was expected here.

Signed-off-by: Christophe JAILLET 
Signed-off-by: Matias Bjørling 
---
 drivers/lightnvm/rrpc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c
index e00b1d7..e68efbc 100644
--- a/drivers/lightnvm/rrpc.c
+++ b/drivers/lightnvm/rrpc.c
@@ -1275,8 +1275,10 @@ static int rrpc_bb_discovery(struct nvm_tgt_dev *dev, 
struct rrpc_lun *rlun)
}
 
nr_blks = nvm_bb_tbl_fold(dev->parent, blks, nr_blks);
-   if (nr_blks < 0)
-   return nr_blks;
+   if (nr_blks < 0) {
+   ret = nr_blks;
+   goto out;
+   }
 
for (i = 0; i < nr_blks; i++) {
if (blks[i] == NVM_BLK_T_FREE)
-- 
2.9.3



[GIT PULL 04/19] lightnvm: rename scrambler controller hint

2017-04-15 Thread Matias Bjørling
From: Javier González 

According to the OCSSD 1.2 specification, the 0x200 hint enables the
media scrambler for the read/write opcode, providing that the controller
has been correctly configured by the firmware. Rename the macro to
represent this meaning.

Signed-off-by: Javier González 
Signed-off-by: Matias Bjørling 
---
 include/linux/lightnvm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index e11163f..eff7d1f 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -123,7 +123,7 @@ enum {
/* NAND Access Modes */
NVM_IO_SUSPEND  = 0x80,
NVM_IO_SLC_MODE = 0x100,
-   NVM_IO_SCRAMBLE_DISABLE = 0x200,
+   NVM_IO_SCRAMBLE_ENABLE  = 0x200,
 
/* Block Types */
NVM_BLK_T_FREE  = 0x0,
-- 
2.9.3



[GIT PULL 00/19] LightNVM patches for 4.12.

2017-04-15 Thread Matias Bjørling
Hi Jens,

With this merge window, we like to push pblk upstream. It is a new
host-side translation layer that implements support for exposing
Open-Channel SSDs as block devices.

We have described pblk in the LightNVM paper "LightNVM: The Linux
Open-Channel SSD Subsystem" that was accepted at FAST 2017. The paper
defines open-channel SSDs, the subsystem, pblk and has an evaluation as
well. Over the past couple of kernel versions we have shipped the
support patches for pblk, and we are now comfortable pushing the core of
pblk upstream.

The core contains the logic to control data placement and I/O scheduling
on open-channel SSDs. Including implementation of translation table
management, GC, recovery, rate-limiting, and similar components. It
assumes that the SSD is media-agnostic, and runs on both 1.2 and 2.0 of
the Open-Channel SSD specification without modifications.

I want to point out two neat features of pblk. First, pblk can be
instantiated multiple times on the same SSD, enabling I/O isolation
between tenants, and makes it able to fulfill strict QoS requirements.
We showed results from this at the NVMW '17 workshop this year, while
presenting the "Multi-Tenant I/O Isolation with Open-Channel SSDs" talk.
Second, now that a full host-side translation layer is implemented, one
can begin to optimize its data placement and I/O scheduling algorithms
to match user workloads. We have shown a couple of the benefits in the
LightNVM paper, and we know of a couple of companies and universities
that have begun making new algorithms.

In detail, this pull request contains:

 - The new host-side FTL pblk from Javier, and other contributors.

 - Add support to the "create" ioctl to force a target to be
   re-initialized at using "factory" flag from Javier.

 - Fix various errors in LightNVM core from Javier and me.

 - An optimization from Neil Brown to skip error checking on mempool
   allocations that can sleep.

 - A buffer overflow fix in nvme_nvm_identify from Scott Bauer.

 - Fix for bad block discovery handle error handling from Christophe
   Jaillet.

 - Fixes from Dan Carpenter to pblk after it went into linux-next.

Please pull from the for-jens branch or apply the patches posted with
this mail:

   https://github.com/OpenChannelSSD/linux.git for-jens

Thanks,
Matias

Christophe JAILLET (1):
  lightnvm: Fix error handling

Dan Carpenter (3):
  lightnvm: pblk-gc: fix an error pointer dereference in init
  lightnvm: fix some WARN() messages
  lightnvm: fix some error code in pblk-init.c

Javier González (12):
  lightnvm: submit erases using the I/O path
  lightnvm: rename scrambler controller hint
  lightnvm: free reverse device map
  lightnvm: double-clear of dev->lun_map on target init error
  lightnvm: fix cleanup order of disk on init error
  lightnvm: bad type conversion for nvme control bits
  lightnvm: allow to init targets on factory mode
  lightnvm: make nvm_free static
  lightnvm: clean unused variable
  lightnvm: fix type checks on rrpc
  lightnvm: convert sprintf into strlcpy
  lightnvm: physical block device (pblk) target

Matias Bjørling (1):
  lightnvm: enable nvme size compile asserts

NeilBrown (1):
  lightnvm: don't check for failure from mempool_alloc()

Scott Bauer (1):
  nvme/lightnvm: Prevent small buffer overflow in nvme_nvm_identify

 Documentation/lightnvm/pblk.txt  |   21 +
 drivers/lightnvm/Kconfig |9 +
 drivers/lightnvm/Makefile|5 +
 drivers/lightnvm/core.c  |  124 +--
 drivers/lightnvm/pblk-cache.c|  114 +++
 drivers/lightnvm/pblk-core.c | 1655 ++
 drivers/lightnvm/pblk-gc.c   |  555 +
 drivers/lightnvm/pblk-init.c |  957 ++
 drivers/lightnvm/pblk-map.c  |  136 
 drivers/lightnvm/pblk-rb.c   |  852 
 drivers/lightnvm/pblk-read.c |  529 
 drivers/lightnvm/pblk-recovery.c |  998 +++
 drivers/lightnvm/pblk-rl.c   |  182 +
 drivers/lightnvm/pblk-sysfs.c|  507 
 drivers/lightnvm/pblk-write.c|  411 ++
 drivers/lightnvm/pblk.h  | 1121 ++
 drivers/lightnvm/rrpc.c  |   25 +-
 drivers/nvme/host/lightnvm.c |   42 +-
 include/linux/lightnvm.h |   13 +-
 include/uapi/linux/lightnvm.h|4 +
 20 files changed, 8165 insertions(+), 95 deletions(-)
 create mode 100644 Documentation/lightnvm/pblk.txt
 create mode 100644 drivers/lightnvm/pblk-cache.c
 create mode 100644 drivers/lightnvm/pblk-core.c
 create mode 100644 drivers/lightnvm/pblk-gc.c
 create mode 100644 drivers/lightnvm/pblk-init.c
 create mode 100644 drivers/lightnvm/pblk-map.c
 create mode 100644 drivers/lightnvm/pblk-rb.c
 create mode 100644 drivers/lightnvm/pblk-read.c
 create mode 100644 drivers/lightnvm/pblk-recovery.c
 create mode 100644 drivers/lightnvm/pblk-rl.c
 create mode 100644 drivers/lightnvm/pblk-sysfs.c
 create mode 100644 drivers/lightnvm/pblk-wri

Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on error

2017-04-15 Thread Wolfgang Bumiller

> On April 15, 2017 at 8:20 PM Cong Wang  wrote:
> 
> 
> On Fri, Apr 14, 2017 at 2:08 AM, Wolfgang Bumiller
>  wrote:
> > Before I do that - trying to wrap my head around the interdependencies
> > here better to be thorough - I noticed that tcf_hash_release() can
> > return ACT_P_DELETED. The ACT_P_CREATED case means tcf_hash_create()
> > was used, in the other case the tc_action's ref & bind count is bumped
> > by tcf_hash_check() and then also decremented by tcf_hash_release() if
> > it existed, iow. kept at 1, but not always: It does always happen in
> > act_police.c but in other files such as act_bpf.c or act_connmark.c if
> > eg. bind is set they return without decrementing, so both ref&bind count
> > are bumped when they return - the refcount logic isn't easy to follow
> > for a newcomer. Now there are two uses of __tcf_hash_release() in
> > act_api.c which check for a return value of ACT_P_DELETED, in which case
> > they call module_put().
> 
> 
> That's the nasty part... IIRC, Jamal has fixed two bugs on action refcnt'ing.
> We really need to clean up the code.
> 
> > So I'm not sure exactly how the module and tc_action counts are related
> > (and I usually like to understand my own patches ;-) ).
> 
> 
> Each action holds a refcnt to its module, each filter holds a refcnt to
> its bound or referenced (unbound) action.
> 
> 
> > Maybe I'm missing something obvious but I'm currently a bit confused as
> > to whether the tcf_hash_release() call there is okay, or should have its
> > return value checked or should depend on ->init()'s ACT_P_CREATED value
> > as well?
> >
> 
> I think it's the same? If we have ACT_P_CREATED here, tcf_hash_release()
> will return ACT_P_DELETED for sure because the newly created action has
> refcnt==1?

Makes sense on the one hand, but for ACT_P_DELETED both ref and bind
count need to reach 0, so I'm still concerned that the different behaviors
I mentioned above might be problematic if we use ACT_P_CREATED only.
(It also means my patches still leak a count - which is probably still
better than the previous underflow, but ultimately doesn't satisfy me.)
Should I still resend it this way for the record with the Acked-bys?
(Since given the fact that with unprivileged containers it's possible to
trigger this access and potentially crash the kernel I strongly feel that
some version of this should end up in the 4.11 release.)



Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on error

2017-04-15 Thread Cong Wang
On Fri, Apr 14, 2017 at 2:08 AM, Wolfgang Bumiller
 wrote:
> Before I do that - trying to wrap my head around the interdependencies
> here better to be thorough - I noticed that tcf_hash_release() can
> return ACT_P_DELETED. The ACT_P_CREATED case means tcf_hash_create()
> was used, in the other case the tc_action's ref & bind count is bumped
> by tcf_hash_check() and then also decremented by tcf_hash_release() if
> it existed, iow. kept at 1, but not always: It does always happen in
> act_police.c but in other files such as act_bpf.c or act_connmark.c if
> eg. bind is set they return without decrementing, so both ref&bind count
> are bumped when they return - the refcount logic isn't easy to follow
> for a newcomer. Now there are two uses of __tcf_hash_release() in
> act_api.c which check for a return value of ACT_P_DELETED, in which case
> they call module_put().


That's the nasty part... IIRC, Jamal has fixed two bugs on action refcnt'ing.
We really need to clean up the code.

> So I'm not sure exactly how the module and tc_action counts are related
> (and I usually like to understand my own patches ;-) ).


Each action holds a refcnt to its module, each filter holds a refcnt to
its bound or referenced (unbound) action.


> Maybe I'm missing something obvious but I'm currently a bit confused as
> to whether the tcf_hash_release() call there is okay, or should have its
> return value checked or should depend on ->init()'s ACT_P_CREATED value
> as well?
>

I think it's the same? If we have ACT_P_CREATED here, tcf_hash_release()
will return ACT_P_DELETED for sure because the newly created action has
refcnt==1?

Thanks.


[PATCH] ASoC: topology: use j for internal loop counter

2017-04-15 Thread Colin King
From: Colin Ian King 

Currently variable i is being for 2 nested for loops. Fix this by
using integer loop counter j for the inside for loop.

Fixes: 1a7dd6e2f1929 ("ASoC: topology: Allow a widget to have multiple enum 
controls")
Signed-off-by: Colin Ian King 
---
 sound/soc/soc-topology.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index 058bc99c6c34..002772e3ba2c 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -495,12 +495,13 @@ static void remove_widget(struct snd_soc_component *comp,
struct snd_kcontrol *kcontrol = w->kcontrols[i];
struct soc_enum *se =
(struct soc_enum *)kcontrol->private_value;
+   int j;
 
snd_ctl_remove(card, kcontrol);
 
kfree(se->dobj.control.dvalues);
-   for (i = 0; i < se->items; i++)
-   kfree(se->dobj.control.dtexts[i]);
+   for (j = 0; j < se->items; j++)
+   kfree(se->dobj.control.dtexts[j]);
 
kfree(se);
}
-- 
2.11.0



Re: [RFC 0/8] Copy Offload with Peer-to-Peer PCI Memory

2017-04-15 Thread Logan Gunthorpe
Thanks, Benjamin, for the summary of some of the issues.

On 14/04/17 04:07 PM, Benjamin Herrenschmidt wrote
> So I assume the p2p code provides a way to address that too via special
> dma_ops ? Or wrappers ?

Not at this time. We will probably need a way to ensure the iommus do
not attempt to remap these addresses. Though if it does, I'd expect
everything would still work you just wouldn't get the performance or
traffic flow you are looking for. We've been testing with the software
iommu which doesn't have this problem.

> The problem is that the latter while seemingly easier, is also slower
> and not supported by all platforms and architectures (for example,
> POWER currently won't allow it, or rather only allows a store-only
> subset of it under special circumstances).

Yes, I think situations where we have to cross host bridges will remain
unsupported by this work for a long time. There are two many cases where
it just doesn't work or it performs too poorly to be useful.

> I don't fully understand how p2pmem "solves" that by creating struct
> pages. The offset problem is one issue. But there's the iommu issue as
> well, the driver cannot just use the normal dma_map ops.

We are not using a proper iommu and we are dealing with systems that
have zero offset. This case is also easily supported. I expect fixing
the iommus to not map these addresses would also be reasonably achievable.

Logan


Re: [PATCH] misc: lkdtm: Add volatile to intentional NULL pointer reference

2017-04-15 Thread Kees Cook
On Fri, Apr 14, 2017 at 2:15 PM, Matthias Kaehlcke  wrote:
> From: Michael Davidson 
>
> Add a volatile qualifier where a NULL pointer is deliberately
> dereferenced to trigger a panic.
>
> Without the volatile qualifier clang will issue the following warning:
> "indirection of non-volatile null pointer will be deleted,
> not trap [-Wnull-dereference]" and replace the pointer reference
> with a __builtin_trap() (which generates a ud2 instruction on x86_64).
>
> Signed-off-by: Michael Davidson 
> Signed-off-by: Matthias Kaehlcke 

Thanks!

Acked-by: Kees Cook 

Greg, please add this to drivers/misc when you get a chance. :)

-Kees

> ---
>  drivers/misc/lkdtm_bugs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/misc/lkdtm_bugs.c b/drivers/misc/lkdtm_bugs.c
> index e3f4cd8876b5..d734d75afade 100644
> --- a/drivers/misc/lkdtm_bugs.c
> +++ b/drivers/misc/lkdtm_bugs.c
> @@ -67,7 +67,7 @@ void lkdtm_WARNING(void)
>
>  void lkdtm_EXCEPTION(void)
>  {
> -   *((int *) 0) = 0;
> +   *((volatile int *) 0) = 0;
>  }
>
>  void lkdtm_LOOP(void)
> --
> 2.12.2.762.g0e3151a226-goog
>



-- 
Kees Cook
Pixel Security


[patch 02/20] stop_machine: Provide stop_machine_locked()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

Some call sites of stop_machine() are within a get_online_cpus() protected
region.

stop_machine() calls get_online_cpus() as well, which is possible in the
current implementation but prevents converting the hotplug locking to a
percpu rwsem.

Provide stop_machine_locked() to avoid nested calls to get_online_cpus().

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 

---
 include/linux/stop_machine.h |   26 +++---
 kernel/stop_machine.c|4 ++--
 2 files changed, 25 insertions(+), 5 deletions(-)

--- a/include/linux/stop_machine.h
+++ b/include/linux/stop_machine.h
@@ -116,15 +116,29 @@ static inline int try_stop_cpus(const st
  * @fn() runs.
  *
  * This can be thought of as a very heavy write lock, equivalent to
- * grabbing every spinlock in the kernel. */
+ * grabbing every spinlock in the kernel.
+ *
+ * Protects against CPU hotplug.
+ */
 int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
 
+/**
+ * stop_machine_locked: freeze the machine on all CPUs and run this function
+ * @fn: the function to run
+ * @data: the data ptr for the @fn()
+ * @cpus: the cpus to run the @fn() on (NULL = any online cpu)
+ *
+ * Same as above. Must be called from with in a get_online_cpus() protected
+ * region. Avoids nested calls to get_online_cpus().
+ */
+int stop_machine_locked(cpu_stop_fn_t fn, void *data, const struct cpumask 
*cpus);
+
 int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
   const struct cpumask *cpus);
 #else  /* CONFIG_SMP || CONFIG_HOTPLUG_CPU */
 
-static inline int stop_machine(cpu_stop_fn_t fn, void *data,
-const struct cpumask *cpus)
+static inline int stop_machine_locked(cpu_stop_fn_t fn, void *data,
+ const struct cpumask *cpus)
 {
unsigned long flags;
int ret;
@@ -134,6 +148,12 @@ static inline int stop_machine(cpu_stop_
return ret;
 }
 
+static inline int stop_machine(cpu_stop_fn_t fn, void *data,
+  const struct cpumask *cpus)
+{
+   return stop_machine_locked(fn, data, cpus);
+}
+
 static inline int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
 const struct cpumask *cpus)
 {
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -552,7 +552,7 @@ static int __init cpu_stop_init(void)
 }
 early_initcall(cpu_stop_init);
 
-static int __stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask 
*cpus)
+int stop_machine_locked(cpu_stop_fn_t fn, void *data, const struct cpumask 
*cpus)
 {
struct multi_stop_data msdata = {
.fn = fn,
@@ -591,7 +591,7 @@ int stop_machine(cpu_stop_fn_t fn, void
 
/* No CPUs can come up or down during this. */
get_online_cpus();
-   ret = __stop_machine(fn, data, cpus);
+   ret = stop_machine_locked(fn, data, cpus);
put_online_cpus();
return ret;
 }




[patch 04/20] padata: Avoid nested calls to get_online_cpus() in pcrypt_init_padata()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

pcrypt_init_padata()
   get_online_cpus()
   padata_alloc_possible()
 padata_alloc()
   get_online_cpus()

The nested call to get_online_cpus() works with the current implementation,
but prevents the conversion to a percpu rwsem.

The other caller of padata_alloc_possible() is pcrypt_init_padata() which
calls from a get_online_cpus() protected region as well.

Remove the get_online_cpus() call in padata_alloc() and document the
calling convention.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Steffen Klassert 
Cc: linux-cry...@vger.kernel.org

---
 kernel/padata.c |8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -913,7 +913,7 @@ static ssize_t padata_sysfs_show(struct
 }
 
 static ssize_t padata_sysfs_store(struct kobject *kobj, struct attribute *attr,
-sconst char *buf, size_t count)
+ const char *buf, size_t count)
 {
struct padata_instance *pinst;
struct padata_sysfs_entry *pentry;
@@ -945,6 +945,8 @@ static struct kobj_type padata_attr_type
  * @wq: workqueue to use for the allocated padata instance
  * @pcpumask: cpumask that will be used for padata parallelization
  * @cbcpumask: cpumask that will be used for padata serialization
+ *
+ * Must be called from a get_online_cpus() protected region
  */
 static struct padata_instance *padata_alloc(struct workqueue_struct *wq,
const struct cpumask *pcpumask,
@@ -957,7 +959,6 @@ static struct padata_instance *padata_al
if (!pinst)
goto err;
 
-   get_online_cpus();
if (!alloc_cpumask_var(&pinst->cpumask.pcpu, GFP_KERNEL))
goto err_free_inst;
if (!alloc_cpumask_var(&pinst->cpumask.cbcpu, GFP_KERNEL)) {
@@ -997,7 +998,6 @@ static struct padata_instance *padata_al
free_cpumask_var(pinst->cpumask.cbcpu);
 err_free_inst:
kfree(pinst);
-   put_online_cpus();
 err:
return NULL;
 }
@@ -1008,6 +1008,8 @@ static struct padata_instance *padata_al
  * parallel workers.
  *
  * @wq: workqueue to use for the allocated padata instance
+ *
+ * Must be called from a get_online_cpus() protected region
  */
 struct padata_instance *padata_alloc_possible(struct workqueue_struct *wq)
 {




[patch 14/20] kernel/hotplug: Use stop_machine_locked() in takedown_cpu()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

takedown_cpu() is a cpu hotplug function invoking stop_machine(). The cpu
hotplug machinery holds the hotplug lock for write.

stop_machine() invokes get_online_cpus() as well. This is correct, but
prevents the conversion of the hotplug locking to a percpu rwsem.

Use stop_machine_locked() to avoid the nested call.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 

---
 kernel/cpu.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -701,7 +701,7 @@ static int takedown_cpu(unsigned int cpu
/*
 * So now all preempt/rcu users must observe !cpu_active().
 */
-   err = stop_machine(take_cpu_down, NULL, cpumask_of(cpu));
+   err = stop_machine_locked(take_cpu_down, NULL, cpumask_of(cpu));
if (err) {
/* CPU refused to die */
irq_unlock_sparse();




[patch 01/20] cpu/hotplug: Provide cpuhp_setup/remove_state[_nocalls]_locked()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

Some call sites of cpuhp_setup/remove_state[_nocalls]() are within a
get_online_cpus() protected region.

cpuhp_setup/remove_state[_nocalls]() call get_online_cpus() as well, which
is possible in the current implementation but prevetns converting the
hotplug locking to a percpu rwsem.

Provide locked versions of the interfaces to avoid nested calls to
get_online_cpus().

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 

---
 include/linux/cpuhotplug.h |   29 +
 kernel/cpu.c   |   45 +
 2 files changed, 62 insertions(+), 12 deletions(-)

--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -151,6 +151,11 @@ int __cpuhp_setup_state(enum cpuhp_state
int (*startup)(unsigned int cpu),
int (*teardown)(unsigned int cpu), bool multi_instance);
 
+int __cpuhp_setup_state_locked(enum cpuhp_state state, const char *name,
+  bool invoke,
+  int (*startup)(unsigned int cpu),
+  int (*teardown)(unsigned int cpu),
+  bool multi_instance);
 /**
  * cpuhp_setup_state - Setup hotplug state callbacks with calling the callbacks
  * @state: The state for which the calls are installed
@@ -169,6 +174,15 @@ static inline int cpuhp_setup_state(enum
return __cpuhp_setup_state(state, name, true, startup, teardown, false);
 }
 
+static inline int cpuhp_setup_state_locked(enum cpuhp_state state,
+  const char *name,
+  int (*startup)(unsigned int cpu),
+  int (*teardown)(unsigned int cpu))
+{
+   return __cpuhp_setup_state_locked(state, name, true, startup, teardown,
+ false);
+}
+
 /**
  * cpuhp_setup_state_nocalls - Setup hotplug state callbacks without calling 
the
  *callbacks
@@ -189,6 +203,15 @@ static inline int cpuhp_setup_state_noca
   false);
 }
 
+static inline int cpuhp_setup_state_nocalls_locked(enum cpuhp_state state,
+  const char *name,
+  int (*startup)(unsigned int 
cpu),
+  int (*teardown)(unsigned int 
cpu))
+{
+   return __cpuhp_setup_state_locked(state, name, false, startup, teardown,
+ false);
+}
+
 /**
  * cpuhp_setup_state_multi - Add callbacks for multi state
  * @state: The state for which the calls are installed
@@ -248,6 +271,7 @@ static inline int cpuhp_state_add_instan
 }
 
 void __cpuhp_remove_state(enum cpuhp_state state, bool invoke);
+void __cpuhp_remove_state_locked(enum cpuhp_state state, bool invoke);
 
 /**
  * cpuhp_remove_state - Remove hotplug state callbacks and invoke the teardown
@@ -271,6 +295,11 @@ static inline void cpuhp_remove_state_no
__cpuhp_remove_state(state, false);
 }
 
+static inline void cpuhp_remove_state_nocalls_locked(enum cpuhp_state state)
+{
+   __cpuhp_remove_state_locked(state, false);
+}
+
 /**
  * cpuhp_remove_multi_state - Remove hotplug multi state callback
  * @state: The state for which the calls are removed
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1457,7 +1457,7 @@ int __cpuhp_state_add_instance(enum cpuh
 EXPORT_SYMBOL_GPL(__cpuhp_state_add_instance);
 
 /**
- * __cpuhp_setup_state - Setup the callbacks for an hotplug machine state
+ * __cpuhp_setup_state_locked - Setup the callbacks for an hotplug machine 
state
  * @state: The state to setup
  * @invoke:If true, the startup function is invoked for cpus where
  * cpu state >= @state
@@ -1466,17 +1466,18 @@ EXPORT_SYMBOL_GPL(__cpuhp_state_add_inst
  * @multi_instance:State is set up for multiple instances which get
  * added afterwards.
  *
+ * The caller needs to hold get_online_cpus() while calling this function.
  * Returns:
  *   On success:
  *  Positive state number if @state is CPUHP_AP_ONLINE_DYN
  *  0 for all other states
  *   On failure: proper (negative) error code
  */
-int __cpuhp_setup_state(enum cpuhp_state state,
-   const char *name, bool invoke,
-   int (*startup)(unsigned int cpu),
-   int (*teardown)(unsigned int cpu),
-   bool multi_instance)
+int __cpuhp_setup_state_locked(enum cpuhp_state state,
+  const char *name, bool invoke,
+  int (*startup)(unsigned int cpu),
+  int (*teardown)(unsigned int cpu),
+  bool multi_instance)
 {
int cpu, ret = 0;
bool dynstate

[patch 08/20] hwtracing/coresight-etm3x: Use the locked version of cpuhp_setup_state_nocalls()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

etm_probe() holds get_online_cpus() while invoking
cpuhp_setup_state_nocalls().

cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
correct, but prevents the conversion of the hotplug locking to a percpu
rwsem.

Use cpuhp_setup_state_nocalls_locked() to avoid the nested call.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Mathieu Poirier 
Cc: linux-arm-ker...@lists.infradead.org

---
 drivers/hwtracing/coresight/coresight-etm3x.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c 
b/drivers/hwtracing/coresight/coresight-etm3x.c
index a51b6b64ecdf..0887265f361d 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x.c
@@ -803,12 +803,12 @@ static int etm_probe(struct amba_device *adev, const 
struct amba_id *id)
dev_err(dev, "ETM arch init failed\n");
 
if (!etm_count++) {
-   cpuhp_setup_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING,
- "arm/coresight:starting",
- etm_starting_cpu, etm_dying_cpu);
-   ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
-   "arm/coresight:online",
-   etm_online_cpu, NULL);
+   
cpuhp_setup_state_nocalls_locked(CPUHP_AP_ARM_CORESIGHT_STARTING,
+"arm/coresight:starting",
+etm_starting_cpu, 
etm_dying_cpu);
+   ret = cpuhp_setup_state_nocalls_locked(CPUHP_AP_ONLINE_DYN,
+  "arm/coresight:online",
+  etm_online_cpu, NULL);
if (ret < 0)
goto err_arch_supported;
hp_online = ret;
-- 
2.11.0






[patch 15/20] x86/perf: Drop EXPORT of perf_check_microcode

2017-04-15 Thread Thomas Gleixner
The only caller is the microcode update, which cannot be modular.

Drop the export.

Signed-off-by: Thomas Gleixner 
Cc: Peter Zijlstra 
Cc: Borislav Petkov 
Cc: x...@kernel.org
---
 arch/x86/events/core.c |1 -
 1 file changed, 1 deletion(-)

--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2224,7 +2224,6 @@ void perf_check_microcode(void)
if (x86_pmu.check_microcode)
x86_pmu.check_microcode();
 }
-EXPORT_SYMBOL_GPL(perf_check_microcode);
 
 static struct pmu pmu = {
.pmu_enable = x86_pmu_enable,




[patch 12/20] s390/kernel: Use stop_machine_locked()

2017-04-15 Thread Thomas Gleixner
stp_work_fn() holds get_online_cpus() while invoking stop_machine().

stop_machine() invokes get_online_cpus() as well. This is correct, but
prevents the conversion of the hotplug locking to a percpu rwsem.

Use stop_machine_locked() to avoid the nested call.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: David Hildenbrand 
Cc: linux-s...@vger.kernel.org

---
 arch/s390/kernel/time.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -636,7 +636,7 @@ static void stp_work_fn(struct work_stru
memset(&stp_sync, 0, sizeof(stp_sync));
get_online_cpus();
atomic_set(&stp_sync.cpus, num_online_cpus() - 1);
-   stop_machine(stp_sync_clock, &stp_sync, cpu_online_mask);
+   stop_machine_locked(stp_sync_clock, &stp_sync, cpu_online_mask);
put_online_cpus();
 
if (!check_sync_clock())




[patch 11/20] ARM/hw_breakpoint: Use cpuhp_setup_state_locked()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

arch_hw_breakpoint_init() holds get_online_cpus() while registerring the
hotplug callbacks.

cpuhp_setup_state() invokes get_online_cpus() as well. This is correct, but
prevents the conversion of the hotplug locking to a percpu rwsem.

Use cpuhp_setup_state_locked() to avoid the nested call.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Will Deacon 
Cc: Mark Rutland 
Cc: Russell King 
Cc: linux-arm-ker...@lists.infradead.org

---
 arch/arm/kernel/hw_breakpoint.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--- a/arch/arm/kernel/hw_breakpoint.c
+++ b/arch/arm/kernel/hw_breakpoint.c
@@ -1098,8 +1098,9 @@ static int __init arch_hw_breakpoint_ini
 * assume that a halting debugger will leave the world in a nice state
 * for us.
 */
-   ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "arm/hw_breakpoint:online",
-   dbg_reset_online, NULL);
+   ret = cpuhp_setup_state_locked(CPUHP_AP_ONLINE_DYN,
+  "arm/hw_breakpoint:online",
+  dbg_reset_online, NULL);
unregister_undef_hook(&debug_reg_hook);
if (WARN_ON(ret < 0) || !cpumask_empty(&debug_err_mask)) {
core_num_brps = 0;




[patch 13/20] powerpc/powernv: Use stop_machine_locked()

2017-04-15 Thread Thomas Gleixner
set_subcores_per_core() holds get_online_cpus() while invoking stop_machine().

stop_machine() invokes get_online_cpus() as well. This is correct, but
prevents the conversion of the hotplug locking to a percpu rwsem.

Use stop_machine_locked() to avoid the nested call.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Benjamin Herrenschmidt 
Cc: Michael Ellerman 
Cc: linuxppc-...@lists.ozlabs.org

---
 arch/powerpc/platforms/powernv/subcore.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/powerpc/platforms/powernv/subcore.c
+++ b/arch/powerpc/platforms/powernv/subcore.c
@@ -356,7 +356,7 @@ static int set_subcores_per_core(int new
/* Ensure state is consistent before we call the other cpus */
mb();
 
-   stop_machine(cpu_update_split_mode, &new_mode, cpu_online_mask);
+   stop_machine_locked(cpu_update_split_mode, &new_mode, cpu_online_mask);
 
put_online_cpus();
 




[patch 20/20] cpu/hotplug: Convert hotplug locking to percpu rwsem

2017-04-15 Thread Thomas Gleixner
There are no more (known) nested calls to get_online_cpus() so it's
possible to remove the nested call magic and convert the mutex to a
percpu-rwsem, which speeds up get/put_online_cpus() significantly for the
uncontended case.

The contended case (write locked for hotplug operations) is slow anyway, so
the slightly more expensive down_write of the percpu rwsem does not matter.

Signed-off-by: Thomas Gleixner 
---
 kernel/cpu.c |  102 ---
 1 file changed, 8 insertions(+), 94 deletions(-)

--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #define CREATE_TRACE_POINTS
@@ -196,121 +197,36 @@ void cpu_maps_update_done(void)
mutex_unlock(&cpu_add_remove_lock);
 }
 
-/* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
+/*
+ * If set, cpu_up and cpu_down will return -EBUSY and do nothing.
  * Should always be manipulated under cpu_add_remove_lock
  */
 static int cpu_hotplug_disabled;
 
 #ifdef CONFIG_HOTPLUG_CPU
 
-static struct {
-   struct task_struct *active_writer;
-   /* wait queue to wake up the active_writer */
-   wait_queue_head_t wq;
-   /* verifies that no writer will get active while readers are active */
-   struct mutex lock;
-   /*
-* Also blocks the new readers during
-* an ongoing cpu hotplug operation.
-*/
-   atomic_t refcount;
-
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-   struct lockdep_map dep_map;
-#endif
-} cpu_hotplug = {
-   .active_writer = NULL,
-   .wq = __WAIT_QUEUE_HEAD_INITIALIZER(cpu_hotplug.wq),
-   .lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-   .dep_map = STATIC_LOCKDEP_MAP_INIT("cpu_hotplug.dep_map", 
&cpu_hotplug.dep_map),
-#endif
-};
-
-/* Lockdep annotations for get/put_online_cpus() and cpu_hotplug_begin/end() */
-#define cpuhp_lock_acquire_read() lock_map_acquire_read(&cpu_hotplug.dep_map)
-#define cpuhp_lock_acquire_tryread() \
- lock_map_acquire_tryread(&cpu_hotplug.dep_map)
-#define cpuhp_lock_acquire()  lock_map_acquire(&cpu_hotplug.dep_map)
-#define cpuhp_lock_release()  lock_map_release(&cpu_hotplug.dep_map)
-
+DEFINE_STATIC_PERCPU_RWSEM(cpu_hotplug_lock);
 
 void get_online_cpus(void)
 {
-   might_sleep();
-   if (cpu_hotplug.active_writer == current)
-   return;
-   cpuhp_lock_acquire_read();
-   mutex_lock(&cpu_hotplug.lock);
-   atomic_inc(&cpu_hotplug.refcount);
-   mutex_unlock(&cpu_hotplug.lock);
+   percpu_down_read(&cpu_hotplug_lock);
 }
 EXPORT_SYMBOL_GPL(get_online_cpus);
 
 void put_online_cpus(void)
 {
-   int refcount;
-
-   if (cpu_hotplug.active_writer == current)
-   return;
-
-   refcount = atomic_dec_return(&cpu_hotplug.refcount);
-   if (WARN_ON(refcount < 0)) /* try to fix things up */
-   atomic_inc(&cpu_hotplug.refcount);
-
-   if (refcount <= 0 && waitqueue_active(&cpu_hotplug.wq))
-   wake_up(&cpu_hotplug.wq);
-
-   cpuhp_lock_release();
-
+   percpu_up_read(&cpu_hotplug_lock);
 }
 EXPORT_SYMBOL_GPL(put_online_cpus);
 
-/*
- * This ensures that the hotplug operation can begin only when the
- * refcount goes to zero.
- *
- * Note that during a cpu-hotplug operation, the new readers, if any,
- * will be blocked by the cpu_hotplug.lock
- *
- * Since cpu_hotplug_begin() is always called after invoking
- * cpu_maps_update_begin(), we can be sure that only one writer is active.
- *
- * Note that theoretically, there is a possibility of a livelock:
- * - Refcount goes to zero, last reader wakes up the sleeping
- *   writer.
- * - Last reader unlocks the cpu_hotplug.lock.
- * - A new reader arrives at this moment, bumps up the refcount.
- * - The writer acquires the cpu_hotplug.lock finds the refcount
- *   non zero and goes to sleep again.
- *
- * However, this is very difficult to achieve in practice since
- * get_online_cpus() not an api which is called all that often.
- *
- */
 void cpu_hotplug_begin(void)
 {
-   DEFINE_WAIT(wait);
-
-   cpu_hotplug.active_writer = current;
-   cpuhp_lock_acquire();
-
-   for (;;) {
-   mutex_lock(&cpu_hotplug.lock);
-   prepare_to_wait(&cpu_hotplug.wq, &wait, TASK_UNINTERRUPTIBLE);
-   if (likely(!atomic_read(&cpu_hotplug.refcount)))
-   break;
-   mutex_unlock(&cpu_hotplug.lock);
-   schedule();
-   }
-   finish_wait(&cpu_hotplug.wq, &wait);
+   percpu_down_write(&cpu_hotplug_lock);
 }
 
 void cpu_hotplug_done(void)
 {
-   cpu_hotplug.active_writer = NULL;
-   mutex_unlock(&cpu_hotplug.lock);
-   cpuhp_lock_release();
+   percpu_up_write(&cpu_hotplug_lock);
 }
 
 /*
@@ -344,8 +260,6 @@ void cpu_hotplug_enable(void)
 EXPORT_SYMBOL_GPL(cpu_hotplug_enable);
 #endif /* CONFIG_HOTPLUG_CPU */
 
-/* Notifier wr

[patch 17/20] PCI: Use cpu_hotplug_disable() instead of get_online_cpus()

2017-04-15 Thread Thomas Gleixner
Converting the hotplug locking, i.e. get_online_cpus(), to a percpu rwsem
unearthed a circular lock dependency which was hidden from lockdep due to
the lockdep annotation of get_online_cpus() which prevents lockdep from
creating full dependency chains. There are several variants of this. And
example is:

Chain exists of:

cpu_hotplug_lock.rw_sem --> drm_global_mutex --> &item->mutex

CPU0CPU1

lock(&item->mutex);
lock(drm_global_mutex);
lock(&item->mutex);
lock(cpu_hotplug_lock.rw_sem);

because there are dependencies through workqueues. The call chain is:

get_online_cpus
apply_workqueue_attrs
__alloc_workqueue_key
ttm_mem_global_init
ast_ttm_mem_global_init
drm_global_item_ref
ast_mm_init
ast_driver_load
drm_dev_register
drm_get_pci_dev
ast_pci_probe
local_pci_probe
work_for_cpu_fn
process_one_work
worker_thread

This is not a problem of get_online_cpus() recursion, it's a possible
deadlock undetected by lockdep so far.

The cure is to use cpu_hotplug_disable() instead of get_online_cpus() to
protect the PCI probing.

There is a side effect to this: cpu_hotplug_disable() makes a concurrent
cpu hotplug attempt via the sysfs interfaces fail with -EBUSY, but PCI
probing usually happens during the boot process where no interaction is
possible. Any later invocations are infrequent enough and concurrent
hotplug attempts are so unlikely that the danger of user space visible
regressions is very close to zero. Anyway, thats preferrable over a real
deadlock.

Signed-off-by: Thomas Gleixner 
Cc: Bjorn Helgaas 
Cc: linux-...@vger.kernel.org
---
 drivers/pci/pci-driver.c |   15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -320,10 +320,19 @@ static long local_pci_probe(void *_ddi)
return 0;
 }
 
+static bool pci_physfn_is_probed(struct pci_dev *dev)
+{
+#ifdef CONFIG_ATS
+   return dev->physfn->is_probed;
+#else
+   return false;
+#endif
+}
+
 static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
  const struct pci_device_id *id)
 {
-   int error, node;
+   int error, node, cpu;
struct drv_dev_and_id ddi = { drv, dev, id };
 
/*
@@ -349,13 +358,13 @@ static int pci_call_probe(struct pci_dri
if (node >= 0 && node != numa_node_id()) {
int cpu;
 
-   get_online_cpus();
+   cpu_hotplug_disable();
cpu = cpumask_any_and(cpumask_of_node(node), cpu_online_mask);
if (cpu < nr_cpu_ids)
error = work_on_cpu(cpu, local_pci_probe, &ddi);
else
error = local_pci_probe(&ddi);
-   put_online_cpus();
+   cpu_hotplug_enable();
} else
error = local_pci_probe(&ddi);
 




[patch 07/20] KVM/PPC/Book3S HV: Use cpuhp_setup_state_nocalls_locked()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

kvmppc_alloc_host_rm_ops() holds get_online_cpus() while invoking
cpuhp_setup_state_nocalls().

cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
correct, but prevents the conversion of the hotplug locking to a percpu
rwsem.

Use cpuhp_setup_state_nocalls_locked() to avoid the nested call.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Alexander Graf 
Cc: Benjamin Herrenschmidt 
Cc: Michael Ellerman 
Cc: k...@vger.kernel.org
Cc: kvm-...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org

---
 arch/powerpc/kvm/book3s_hv.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -3336,10 +3336,10 @@ void kvmppc_alloc_host_rm_ops(void)
return;
}
 
-   cpuhp_setup_state_nocalls(CPUHP_KVM_PPC_BOOK3S_PREPARE,
- "ppc/kvm_book3s:prepare",
- kvmppc_set_host_core,
- kvmppc_clear_host_core);
+   cpuhp_setup_state_nocalls_locked(CPUHP_KVM_PPC_BOOK3S_PREPARE,
+"ppc/kvm_book3s:prepare",
+kvmppc_set_host_core,
+kvmppc_clear_host_core);
put_online_cpus();
 }
 




[patch 03/20] padata: Make padata_alloc() static

2017-04-15 Thread Thomas Gleixner
No users outside of padata.c

Signed-off-by: Thomas Gleixner 
Cc: Steffen Klassert 
Cc: linux-cry...@vger.kernel.org
---
 include/linux/padata.h |3 ---
 kernel/padata.c|   34 +-
 2 files changed, 17 insertions(+), 20 deletions(-)

--- a/include/linux/padata.h
+++ b/include/linux/padata.h
@@ -166,9 +166,6 @@ struct padata_instance {
 
 extern struct padata_instance *padata_alloc_possible(
struct workqueue_struct *wq);
-extern struct padata_instance *padata_alloc(struct workqueue_struct *wq,
-   const struct cpumask *pcpumask,
-   const struct cpumask *cbcpumask);
 extern void padata_free(struct padata_instance *pinst);
 extern int padata_do_parallel(struct padata_instance *pinst,
  struct padata_priv *padata, int cb_cpu);
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -913,7 +913,7 @@ static ssize_t padata_sysfs_show(struct
 }
 
 static ssize_t padata_sysfs_store(struct kobject *kobj, struct attribute *attr,
- const char *buf, size_t count)
+sconst char *buf, size_t count)
 {
struct padata_instance *pinst;
struct padata_sysfs_entry *pentry;
@@ -939,19 +939,6 @@ static struct kobj_type padata_attr_type
 };
 
 /**
- * padata_alloc_possible - Allocate and initialize padata instance.
- * Use the cpu_possible_mask for serial and
- * parallel workers.
- *
- * @wq: workqueue to use for the allocated padata instance
- */
-struct padata_instance *padata_alloc_possible(struct workqueue_struct *wq)
-{
-   return padata_alloc(wq, cpu_possible_mask, cpu_possible_mask);
-}
-EXPORT_SYMBOL(padata_alloc_possible);
-
-/**
  * padata_alloc - allocate and initialize a padata instance and specify
  *cpumasks for serial and parallel workers.
  *
@@ -959,9 +946,9 @@ EXPORT_SYMBOL(padata_alloc_possible);
  * @pcpumask: cpumask that will be used for padata parallelization
  * @cbcpumask: cpumask that will be used for padata serialization
  */
-struct padata_instance *padata_alloc(struct workqueue_struct *wq,
-const struct cpumask *pcpumask,
-const struct cpumask *cbcpumask)
+static struct padata_instance *padata_alloc(struct workqueue_struct *wq,
+   const struct cpumask *pcpumask,
+   const struct cpumask *cbcpumask)
 {
struct padata_instance *pinst;
struct parallel_data *pd = NULL;
@@ -1016,6 +1003,19 @@ struct padata_instance *padata_alloc(str
 }
 
 /**
+ * padata_alloc_possible - Allocate and initialize padata instance.
+ * Use the cpu_possible_mask for serial and
+ * parallel workers.
+ *
+ * @wq: workqueue to use for the allocated padata instance
+ */
+struct padata_instance *padata_alloc_possible(struct workqueue_struct *wq)
+{
+   return padata_alloc(wq, cpu_possible_mask, cpu_possible_mask);
+}
+EXPORT_SYMBOL(padata_alloc_possible);
+
+/**
  * padata_free - free a padata instance
  *
  * @padata_inst: padata instance to free




[patch 18/20] PCI: Replace the racy recursion prevention

2017-04-15 Thread Thomas Gleixner
pci_call_probe() can called recursively when a physcial function is probed
and the probing creates virtual functions, which are populated via
pci_bus_add_device() which in turn can end up calling pci_call_probe()
again.

The code has an interesting way to prevent recursing into the workqueue
code.  That's accomplished by a check whether the current task runs already
on the numa node which is associated with the device.

While that works to prevent the recursion into the workqueue code, it's
racy versus normal execution as there is no guarantee that the node does
not vanish after the check.

Make the detection reliable by:

 - Mark a probed device as 'is_probed' in pci_call_probe()
 
 - Check in pci_call_probe for a virtual function. If it's a virtual
   function and the associated physical function device is marked
   'is_probed' then this is a recursive call, so the call can be invoked in
   the calling context.

Signed-off-by: Thomas Gleixner 
Cc: Bjorn Helgaas 
Cc: linux-...@vger.kernel.org
---
 drivers/pci/pci-driver.c |   35 ++-
 include/linux/pci.h  |1 +
 2 files changed, 15 insertions(+), 21 deletions(-)

--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -341,33 +341,26 @@ static int pci_call_probe(struct pci_dri
 * on the right node.
 */
node = dev_to_node(&dev->dev);
+   dev->is_probed = 1;
+
+   cpu_hotplug_disable();
 
/*
-* On NUMA systems, we are likely to call a PF probe function using
-* work_on_cpu().  If that probe calls pci_enable_sriov() (which
-* adds the VF devices via pci_bus_add_device()), we may re-enter
-* this function to call the VF probe function.  Calling
-* work_on_cpu() again will cause a lockdep warning.  Since VFs are
-* always on the same node as the PF, we can work around this by
-* avoiding work_on_cpu() when we're already on the correct node.
-*
-* Preemption is enabled, so it's theoretically unsafe to use
-* numa_node_id(), but even if we run the probe function on the
-* wrong node, it should be functionally correct.
+* Prevent nesting work_on_cpu() for the case where a Virtual Function
+* device is probed from work_on_cpu() of the Physical device.
 */
-   if (node >= 0 && node != numa_node_id()) {
-   int cpu;
-
-   cpu_hotplug_disable();
+   if (dev->is_virtfn && pci_physfn_is_probed(dev))
+   cpu = nr_cpu_ids;
+   else
cpu = cpumask_any_and(cpumask_of_node(node), cpu_online_mask);
-   if (cpu < nr_cpu_ids)
-   error = work_on_cpu(cpu, local_pci_probe, &ddi);
-   else
-   error = local_pci_probe(&ddi);
-   cpu_hotplug_enable();
-   } else
+
+   if (cpu < nr_cpu_ids)
+   error = work_on_cpu(cpu, local_pci_probe, &ddi);
+   else
error = local_pci_probe(&ddi);
 
+   dev->is_probed = 0;
+   cpu_hotplug_enable();
return error;
 }
 
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -365,6 +365,7 @@ struct pci_dev {
unsigned intirq_managed:1;
unsigned inthas_secondary_link:1;
unsigned intnon_compliant_bars:1;   /* broken BARs; ignore them */
+   unsigned intis_probed:1;/* device probing in progress */
pci_dev_flags_t dev_flags;
atomic_tenable_cnt; /* pci_enable_device has been called */
 




[patch 10/20] perf/x86/intel/cqm: Use cpuhp_setup_state_locked()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

intel_cqm_init() holds get_online_cpus() while registerring the hotplug
callbacks.

cpuhp_setup_state() invokes get_online_cpus() as well. This is correct, but
prevents the conversion of the hotplug locking to a percpu rwsem.

Use cpuhp_setup_state_locked() to avoid the nested call.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Peter Zijlstra 
Cc: x...@kernel.org
Cc: Fenghua Yu 

---
 arch/x86/events/intel/cqm.c |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

--- a/arch/x86/events/intel/cqm.c
+++ b/arch/x86/events/intel/cqm.c
@@ -1746,12 +1746,12 @@ static int __init intel_cqm_init(void)
 * Setup the hot cpu notifier once we are sure cqm
 * is enabled to avoid notifier leak.
 */
-   cpuhp_setup_state(CPUHP_AP_PERF_X86_CQM_STARTING,
- "perf/x86/cqm:starting",
- intel_cqm_cpu_starting, NULL);
-   cpuhp_setup_state(CPUHP_AP_PERF_X86_CQM_ONLINE, "perf/x86/cqm:online",
- NULL, intel_cqm_cpu_exit);
-
+   cpuhp_setup_state_locked(CPUHP_AP_PERF_X86_CQM_STARTING,
+"perf/x86/cqm:starting",
+intel_cqm_cpu_starting, NULL);
+   cpuhp_setup_state_locked(CPUHP_AP_PERF_X86_CQM_ONLINE,
+"perf/x86/cqm:online",
+NULL, intel_cqm_cpu_exit);
 out:
put_online_cpus();
 




[patch 16/20] perf/x86/intel: Drop get_online_cpus() in intel_snb_check_microcode()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

If intel_snb_check_microcode() is invoked via
  microcode_init -> perf_check_microcode -> intel_snb_check_microcode

then get_online_cpus() is invoked nested. This works with the current
implementation of get_online_cpus() but prevents converting it to a percpu
rwsem.

intel_snb_check_microcode() is also invoked from intel_sandybridge_quirk()
unprotected.

Drop get_online_cpus() from intel_snb_check_microcode() and add it to
intel_sandybridge_quirk() so both call sites are protected.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Peter Zijlstra 
Cc: Borislav Petkov 
Cc: x...@kernel.org

---
 arch/x86/events/intel/core.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3389,12 +3389,10 @@ static void intel_snb_check_microcode(vo
int pebs_broken = 0;
int cpu;
 
-   get_online_cpus();
for_each_online_cpu(cpu) {
if ((pebs_broken = intel_snb_pebs_broken(cpu)))
break;
}
-   put_online_cpus();
 
if (pebs_broken == x86_pmu.pebs_broken)
return;
@@ -3467,7 +3465,9 @@ static bool check_msr(unsigned long msr,
 static __init void intel_sandybridge_quirk(void)
 {
x86_pmu.check_microcode = intel_snb_check_microcode;
+   get_online_cpus();
intel_snb_check_microcode();
+   put_online_cpus();
 }
 
 static const struct { int id; char *name; } intel_arch_events_map[] 
__initconst = {




[patch 19/20] ACPI/processor: Use cpu_hotplug_disable() instead of get_online_cpus()

2017-04-15 Thread Thomas Gleixner
Converting the hotplug locking, i.e. get_online_cpus(), to a percpu rwsem
unearthed a circular lock dependency which was hidden from lockdep due to
the lockdep annotation of get_online_cpus() which prevents lockdep from
creating full dependency chains.

CPU0CPU1

lock((&wfc.work));
 lock(cpu_hotplug_lock.rw_sem);
 lock((&wfc.work));
lock(cpu_hotplug_lock.rw_sem);

This dependency is established via acpi_processor_start() which calls into
the work queue code. And the work queue code establishes the reverse
dependency.

This is not a problem of get_online_cpus() recursion, it's a possible
deadlock undetected by lockdep so far.

The cure is to use cpu_hotplug_disable() instead of get_online_cpus() to
protect the probing from acpi_processor_start().

There is a side effect to this: cpu_hotplug_disable() makes a concurrent
cpu hotplug attempt via the sysfs interfaces fail with -EBUSY, but that
probing usually happens during the boot process where no interaction is
possible. Any later invocations are infrequent enough and concurrent
hotplug attempts are so unlikely that the danger of user space visible
regressions is very close to zero. Anyway, thats preferrable over a real
deadlock.

Signed-off-by: Thomas Gleixner 
Cc: "Rafael J. Wysocki" 
Cc: Len Brown 
Cc: linux-a...@vger.kernel.org
---
 drivers/acpi/processor_driver.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -268,9 +268,9 @@ static int acpi_processor_start(struct d
return -ENODEV;
 
/* Protect against concurrent CPU hotplug operations */
-   get_online_cpus();
+   cpu_hotplug_disable();
ret = __acpi_processor_start(device);
-   put_online_cpus();
+   cpu_hotplug_enable();
return ret;
 }
 




[patch 06/20] cpufreq: Use cpuhp_setup_state_nocalls_locked()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

cpufreq holds get_online_cpus() while invoking cpuhp_setup_state_nocalls()
to make subsys_interface_register() and the registration of hotplug calls
atomic versus cpu hotplug.

cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
correct, but prevents the conversion of the hotplug locking to a percpu
rwsem.

Use cpuhp_setup_state_nocalls_locked() to avoid the nested call.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: "Rafael J. Wysocki" 
Cc: Viresh Kumar 
Cc: linux...@vger.kernel.org

---
 drivers/cpufreq/cpufreq.c |9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2473,9 +2473,10 @@ int cpufreq_register_driver(struct cpufr
goto err_if_unreg;
}
 
-   ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "cpufreq:online",
-   cpuhp_cpufreq_online,
-   cpuhp_cpufreq_offline);
+   ret = cpuhp_setup_state_nocalls_locked(CPUHP_AP_ONLINE_DYN,
+  "cpufreq:online",
+  cpuhp_cpufreq_online,
+  cpuhp_cpufreq_offline);
if (ret < 0)
goto err_if_unreg;
hp_online = ret;
@@ -2519,7 +2520,7 @@ int cpufreq_unregister_driver(struct cpu
get_online_cpus();
subsys_interface_unregister(&cpufreq_interface);
remove_boost_sysfs_file();
-   cpuhp_remove_state_nocalls(hp_online);
+   cpuhp_remove_state_nocalls_locked(hp_online);
 
write_lock_irqsave(&cpufreq_driver_lock, flags);
 




[patch 00/20] cpu/hotplug: Convert get_online_cpus() to a percpu_rwsem

2017-04-15 Thread Thomas Gleixner
get_online_cpus() is used in hot pathes in mainline and even more so in
RT. That can show up badly under certain conditions because every locker
contends on a global mutex. RT has it's own homebrewn mitigation which is
an (badly done) open coded implementation of percpu_rwsems with recursion
support.

The proper replacement for that are percpu_rwsems, but that requires to
remove recursion support.

The conversion unearthed real locking issues which were previously not
visible because the get_online_cpus() lockdep annotation was implemented
with recursion support which prevents lockdep from tracking full dependency
chains. These potential deadlocks are not related to recursive calls, they
trigger on the first invocation because lockdep now has the full dependency
chains available.

The following patch series addresses this by

 - Cleaning up places which call get_online_cpus() nested

 - Replacing a few instances with cpu_hotplug_disable() to prevent circular
   locking dependencies.

The series depends on

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core
  plus
Linus tree merged in to avoid conflicts

It's available in git from

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git WIP.hotplug

Thanks,

tglx

---
 arch/arm/kernel/hw_breakpoint.c   |5 
 arch/powerpc/kvm/book3s_hv.c  |8 -
 arch/powerpc/platforms/powernv/subcore.c  |2 
 arch/s390/kernel/time.c   |2 
 arch/x86/events/core.c|1 
 arch/x86/events/intel/core.c  |4 
 arch/x86/events/intel/cqm.c   |   12 +-
 arch/x86/kernel/cpu/mtrr/main.c   |2 
 drivers/acpi/processor_driver.c   |4 
 drivers/cpufreq/cpufreq.c |9 -
 drivers/hwtracing/coresight/coresight-etm3x.c |   12 +-
 drivers/hwtracing/coresight/coresight-etm4x.c |   12 +-
 drivers/pci/pci-driver.c  |   46 
 include/linux/cpuhotplug.h|   29 +
 include/linux/padata.h|3 
 include/linux/pci.h   |1 
 include/linux/stop_machine.h  |   26 
 kernel/cpu.c  |  149 +++---
 kernel/padata.c   |   38 +++---
 kernel/stop_machine.c |4 
 20 files changed, 177 insertions(+), 192 deletions(-)





[patch 05/20] x86/mtrr: Remove get_online_cpus() from mtrr_save_state()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

mtrr_save_state() is invoked from native_cpu_up() which is in the context
of a CPU hotplug operation and therefor calling get_online_cpus() is
pointless.

While this works in the current get_online_cpus() implementation it
prevents from converting the hotplug locking to percpu rwsems.

Remove it.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: x...@kernel.org

---
 arch/x86/kernel/cpu/mtrr/main.c |2 --
 1 file changed, 2 deletions(-)

--- a/arch/x86/kernel/cpu/mtrr/main.c
+++ b/arch/x86/kernel/cpu/mtrr/main.c
@@ -807,10 +807,8 @@ void mtrr_save_state(void)
if (!mtrr_enabled())
return;
 
-   get_online_cpus();
first_cpu = cpumask_first(cpu_online_mask);
smp_call_function_single(first_cpu, mtrr_save_fixed_ranges, NULL, 1);
-   put_online_cpus();
 }
 
 void set_mtrr_aps_delayed_init(void)




[patch 09/20] hwtracing/coresight-etm4x: Use cpuhp_setup_state_nocalls_locked()

2017-04-15 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

etm_probe4() holds get_online_cpus() while invoking
cpuhp_setup_state_nocalls().

cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
correct, but prevents the conversion of the hotplug locking to a percpu
rwsem.

Use cpuhp_setup_state_nocalls_locked() to avoid the nested call.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Mathieu Poirier 
Cc: linux-arm-ker...@lists.infradead.org

---
 drivers/hwtracing/coresight/coresight-etm4x.c |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x.c
@@ -990,12 +990,12 @@ static int etm4_probe(struct amba_device
dev_err(dev, "ETM arch init failed\n");
 
if (!etm4_count++) {
-   cpuhp_setup_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING,
- "arm/coresight4:starting",
- etm4_starting_cpu, etm4_dying_cpu);
-   ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
-   "arm/coresight4:online",
-   etm4_online_cpu, NULL);
+   
cpuhp_setup_state_nocalls_locked(CPUHP_AP_ARM_CORESIGHT_STARTING,
+"arm/coresight4:starting",
+etm4_starting_cpu, 
etm4_dying_cpu);
+   ret = cpuhp_setup_state_nocalls_locked(CPUHP_AP_ONLINE_DYN,
+  "arm/coresight4:online",
+  etm4_online_cpu, NULL);
if (ret < 0)
goto err_arch_supported;
hp_online = ret;




Re: regulator: s2mps11: Use kcalloc() in s2mps11_pmic_probe()

2017-04-15 Thread SF Markus Elfring
>> A multiplication for the size determination of a memory allocation
>> indicated that an array data structure should be processed.
>> Thus use the corresponding function "kcalloc".
>>
>> This issue was detected by using the Coccinelle software.
> 
> Unfortunately you write mostly cryptic commit messages.

Thanks for your feedback.


> This does not answer for the main question - why this change is needed.

My update suggestion affects an aspect for the coding style.


> Code looks okay,

There can be different opinions about related implementation details.


> but you should explain in simple words why this is needed.

Do you find the following wording from the script “checkpatch.pl”
better to understand?

WARNING: Prefer kcalloc over kzalloc with multiply


Regards,
Markus


Re: [patch 0/6] hwmon/coretemp: Hotplug fixes, cleanups and state machine conversion

2017-04-15 Thread Tommi Rantala
2017-04-14 20:35 GMT+03:00 Thomas Gleixner :
> On Wed, 12 Apr 2017, Thomas Gleixner wrote:
>>
>> Can you please try the following:
>>
>> # for STATE in freezer devices platform processors core; do \
>>   echo $STATE; \
>>   echo $STATE >/sys/power/pm_test; \
>>   echo mem >/sys/power/state
>>
>> That should give us at least a hint in which area to dig.
>
> Any news on that?

Sorry, was traveling.

Testing with 4.10.8-200.fc25.x86_64: freezer, devices and platform are
OK, it breaks at "processors".
The screen stays off, and the machine no longer answers to ping.

(Without coretemp loaded, the machine survives all the states. There
are some graphics glitches and radeon error messages)

-Tommi


[GIT PULL] libnvdimm fixes for 4.11-rc7

2017-04-15 Thread Dan Williams
Hi Linus, please pull from:

  git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm libnvdimm-fixes

...to receive:

A small crop of lockdep, sleeping while atomic, and other fixes /
band-aids in advance of the full-blown reworks targeting the next
merge window. The largest change here is "libnvdimm: fix blk free
space accounting" which deletes a pile of buggy code that better
testing would have caught before merging. The next change that is
borderline too big for a late rc is switching the device-dax locking
from rcu to srcu, I couldn't think of a smaller way to make that fix.

The __copy_user_nocache fix will have a full replacement in 4.12 to
move those pmem special case considerations into the pmem driver. The
"libnvdimm: band aid btt vs clear poison locking" commit admits that
our error clearing support for btt went in broken, so we just disable
it in 4.11 and -stable. A replacement / full fix is in the pipeline
for 4.12

Some of these would have been caught earlier had
CONFIG_DEBUG_ATOMIC_SLEEP been enabled on my development station. I
wonder if we should have:

config DEBUG_ATOMIC_SLEEP
default PROVE_LOCKING

...since I mistakenly thought I got both with CONFIG_PROVE_LOCKING=y.

These have received a build success notification from the 0day robot,
and some have appeared in a -next release with no reported issues.

---

The following changes since commit c02ed2e75ef4c74e41e421acb4ef1494671585e8:

  Linux 4.11-rc4 (2017-03-26 14:15:16 -0700)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm libnvdimm-fixes

for you to fetch changes up to 11e63f6d920d6f2dfd3cd421e939a4aec9a58dcd:

  x86, pmem: fix broken __copy_user_nocache cache-bypass assumptions
(2017-04-12 13:45:18 -0700)


Dan Williams (6):
  acpi, nfit, libnvdimm: fix interleave set cookie calculation
(64-bit comparison)
  libnvdimm: fix blk free space accounting
  libnvdimm: fix reconfig_mutex, mmap_sem, and jbd2_handle lockdep splat
  libnvdimm: band aid btt vs clear poison locking
  device-dax: switch to srcu, fix rcu_read_lock() vs pte allocation
  x86, pmem: fix broken __copy_user_nocache cache-bypass assumptions

 arch/x86/include/asm/pmem.h | 42 ++---
 drivers/acpi/nfit/core.c|  6 +++-
 drivers/dax/Kconfig |  1 +
 drivers/dax/dax.c   | 13 
 drivers/nvdimm/bus.c|  6 
 drivers/nvdimm/claim.c  | 10 +-
 drivers/nvdimm/dimm_devs.c  | 77 +++--
 7 files changed, 70 insertions(+), 85 deletions(-)

commit b03b99a329a14b7302f37c3ea6da3848db41c8c5
Author: Dan Williams 
Date:   Mon Mar 27 21:53:38 2017 -0700

acpi, nfit, libnvdimm: fix interleave set cookie calculation
(64-bit comparison)

While reviewing the -stable patch for commit 86ef58a4e35e "nfit,
libnvdimm: fix interleave set cookie calculation" Ben noted:

"This is returning an int, thus it's effectively doing a 32-bit
 comparison and not the 64-bit comparison you say is needed."

Update the compare operation to be immune to this integer demotion problem.

Cc: 
Cc: Nicholas Moulin 
Fixes: 86ef58a4e35e ("nfit, libnvdimm: fix interleave set cookie
calculation")
Reported-by: Ben Hutchings 
Signed-off-by: Dan Williams 

commit fe514739d8538783749d3ce72f78e5a999ea5668
Author: Dan Williams 
Date:   Tue Apr 4 15:08:36 2017 -0700

libnvdimm: fix blk free space accounting

Commit a1f3e4d6a0c3 "libnvdimm, region: update nd_region_available_dpa()
for multi-pmem support" reworked blk dpa (DIMM Physical Address)
accounting to comprehend multiple pmem namespace allocations aliasing
with a given blk-dpa range.

The following call trace is a result of failing to account for allocated
blk capacity.

 WARNING: CPU: 1 PID: 2433 at
tools/testing/nvdimm/../../../drivers/nvdimm/names
4 size_store+0x6f3/0x930 [libnvdimm]
 nd_region region5: allocation underrun: 0x0 of 0x100 bytes
 [..]
 Call Trace:
  dump_stack+0x86/0xc3
  __warn+0xcb/0xf0
  warn_slowpath_fmt+0x5f/0x80
  size_store+0x6f3/0x930 [libnvdimm]
  dev_attr_store+0x18/0x30

If a given blk-dpa allocation does not alias with any pmem ranges then
the full allocation should be accounted as busy space, not the size of
the current pmem contribution to the region.

The thinkos that led to this confusion was not realizing that the struct
resource management is already guaranteeing no collisions between pmem
allocations and blk allocations on the same dimm. Also, we do not try to
support blk allocations in aliased pmem holes.

This patch also fixes a case where the available blk goes negative.

Cc: 
Fixes: a1f3e4d6a0c3 ("libnvdimm, region: update
nd_region_available_dpa() for multi-pmem support").
Reported-by: Dariusz Dokupil 
Reported-b

Re: [git pull] vfs fixes

2017-04-15 Thread Al Viro
On Sat, Apr 15, 2017 at 09:51:40AM -0700, Linus Torvalds wrote:
> On Fri, Apr 14, 2017 at 11:41 PM, Vegard Nossum  
> wrote:
> >
> > I'm seeing the same memfd_create/name_to_handle_at/path_lookupat
> > use-after-free that Dmitry was seeing here:
> 
> Ok, see if that is gone in current git with commit c0eb027e5aef ("vfs:
> don't do RCU lookup of empty pathnames")

FWIW, I'm finishing testing of fixes for crap found during the discussion
of that stuff last week (making sure that mntns_install() can't be abused
into setting ->fs->root/->fs->pwd to dentry of NFS referral and its ilk
and doing that in a sane way).


[PATCHv2 0/2] mfd: omap-usb-tll: Fixes for USB TLL mode

2017-04-15 Thread Tony Lindgren
Hi

Here's v2 of this that move the enabling of ULPIAUTOIDLE bit into a
separate patch as suggested by Roger Quadros .

Both patches can wait for v4.12.

Regards,

Tony


Tony Lindgren (2):
  mfd: omap-usb-tll: Fix inverted bit use for USB TLL mode
  mfd: omap-usb-tll: Configure ULPIAUTOIDLE

 drivers/mfd/omap-usb-tll.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

-- 
2.12.2


[PATCH 2/2] mfd: omap-usb-tll: Configure ULPIAUTOIDLE

2017-04-15 Thread Tony Lindgren
The idle mode needs to be only disabled for UTMIAUTOIDLE while
ULPIAUTOIDLE can be enabled.

This matches the TLL_CHANNEL_CONF_i register configuration for ehci-tll
in the Motorola Linux kernel tree for Wrigley 3G LTE modem on droid 4
and the modem still stays responsive.

Cc: Felipe Balbi 
Cc: Keshava Munegowda 
Cc: Marcel Partap 
Cc: Michael Scott 
Cc: Roger Quadros 
Cc: Sebastian Reichel 
Signed-off-by: Tony Lindgren 
---
 drivers/mfd/omap-usb-tll.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
--- a/drivers/mfd/omap-usb-tll.c
+++ b/drivers/mfd/omap-usb-tll.c
@@ -373,12 +373,13 @@ int omap_tll_init(struct usbhs_omap_platform_data *pdata)
} else if (pdata->port_mode[i] ==
OMAP_EHCI_PORT_MODE_TLL) {
/*
-* Disable AutoIdle, BitStuffing
-* and use SDR Mode
+* Disable UTMI AutoIdle, BitStuffing
+* and use SDR Mode. Enable ULPI AutoIdle.
 */
reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
| OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
reg |= OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF;
+   reg |= OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE;
} else if (pdata->port_mode[i] ==
OMAP_EHCI_PORT_MODE_HSIC) {
/*
-- 
2.12.2


[PATCH 1/2] mfd: omap-usb-tll: Fix inverted bit use for USB TLL mode

2017-04-15 Thread Tony Lindgren
Commit 16fa3dc75c22 ("mfd: omap-usb-tll: HOST TLL platform driver")
added support for USB TLL, but uses OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
bit the wrong way. The comments in the code are correct, but the inverted
use of OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF causes the register to be
enabled instead of disabled unlike what the comments say.

Without this change the Wrigley 3G LTE modem on droid 4 EHCI bus can
be only pinged few times before it stops responding.

Fixes: 16fa3dc75c22 ("mfd: omap-usb-tll: HOST TLL platform driver")
Cc: Felipe Balbi 
Cc: Keshava Munegowda 
Cc: Marcel Partap 
Cc: Michael Scott 
Cc: Roger Quadros 
Cc: Sebastian Reichel 
Signed-off-by: Tony Lindgren 
---
 drivers/mfd/omap-usb-tll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
--- a/drivers/mfd/omap-usb-tll.c
+++ b/drivers/mfd/omap-usb-tll.c
@@ -377,8 +377,8 @@ int omap_tll_init(struct usbhs_omap_platform_data *pdata)
 * and use SDR Mode
 */
reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
-   | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
| OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
+   reg |= OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF;
} else if (pdata->port_mode[i] ==
OMAP_EHCI_PORT_MODE_HSIC) {
/*
-- 
2.12.2


Re: [PATCH RESEND] regulator: rn5t618: Fix out of bounds array access

2017-04-15 Thread Stefan Agner
On 2017-04-15 07:52, Axel Lin wrote:
> The commit "regulator: rn5t618: Add RN5T567 PMIC support" added
> RN5T618_DCDC4 to the enum, then RN5T618_REG_NUM is also changed.
> So for rn5t618, there is out of bounds array access when checking
> regulators[i].name in the for loop.

I use designated initializers ([RN5T618_##rid] = {..), which guarantee
that the non initialized elements are zero. The highest element LDORTC2
is defined, hence the length of the array should be RN5T618_REG_NUM.

See also
https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

--
Stefan


> 
> The number of regulators is different for rn5t567 and rn5t618, so we had
> better remove RN5T618_REG_NUM and get the correct num_regulators during
> probe instead.
> 
> Fixes: ed6d362d8dbc ("regulator: rn5t618: Add RN5T567 PMIC support")
> Signed-off-by: Axel Lin 
> ---
> RESEND: Correct subject line (remove double Fix)
> 
>  drivers/regulator/rn5t618-regulator.c | 8 
>  include/linux/mfd/rn5t618.h   | 1 -
>  2 files changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/regulator/rn5t618-regulator.c
> b/drivers/regulator/rn5t618-regulator.c
> index 8d2819e..0c09143 100644
> --- a/drivers/regulator/rn5t618-regulator.c
> +++ b/drivers/regulator/rn5t618-regulator.c
> @@ -85,14 +85,17 @@ static int rn5t618_regulator_probe(struct
> platform_device *pdev)
>   struct regulator_config config = { };
>   struct regulator_dev *rdev;
>   struct regulator_desc *regulators;
> + int num_regulators;
>   int i;
>  
>   switch (rn5t618->variant) {
>   case RN5T567:
>   regulators = rn5t567_regulators;
> + num_regulators = ARRAY_SIZE(rn5t567_regulators);
>   break;
>   case RN5T618:
>   regulators = rn5t618_regulators;
> + num_regulators = ARRAY_SIZE(rn5t618_regulators);
>   break;
>   default:
>   return -EINVAL;
> @@ -101,10 +104,7 @@ static int rn5t618_regulator_probe(struct
> platform_device *pdev)
>   config.dev = pdev->dev.parent;
>   config.regmap = rn5t618->regmap;
>  
> - for (i = 0; i < RN5T618_REG_NUM; i++) {
> - if (!regulators[i].name)
> - continue;
> -
> + for (i = 0; i < num_regulators; i++) {
>   rdev = devm_regulator_register(&pdev->dev,
>  ®ulators[i],
>  &config);
> diff --git a/include/linux/mfd/rn5t618.h b/include/linux/mfd/rn5t618.h
> index e5a6cde..d7b3155 100644
> --- a/include/linux/mfd/rn5t618.h
> +++ b/include/linux/mfd/rn5t618.h
> @@ -233,7 +233,6 @@ enum {
>   RN5T618_LDO5,
>   RN5T618_LDORTC1,
>   RN5T618_LDORTC2,
> - RN5T618_REG_NUM,
>  };
>  
>  enum {


Re: [git pull] vfs fixes

2017-04-15 Thread Linus Torvalds
On Fri, Apr 14, 2017 at 11:41 PM, Vegard Nossum  wrote:
>
> I'm seeing the same memfd_create/name_to_handle_at/path_lookupat
> use-after-free that Dmitry was seeing here:

Ok, see if that is gone in current git with commit c0eb027e5aef ("vfs:
don't do RCU lookup of empty pathnames")

  Linus


[GIT PULL] SCSI fixes for 4.11-rc6

2017-04-15 Thread James Bottomley
This is larger than it would be: we missed the -rc5 fixes pull request
because of a problem linux-next found with the lowest patch which
necessitated a rebase to fix.

This is seven small fixes which are all for user visible issues that
fortunately only occur in rare circumstances.  The most serious is the
sr one in which QEMU can cause us to read beyond the end of a buffer (I
don't think it's exploitable, but just in case).  The next is the sd
capacity fix which means all non 512 byte sector drives greater than
2TB fail to be correctly sized.  The rest are either in new drivers
(qedf) or on error legs.

The patch is available here:

git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git scsi-fixes

The short changelog is:

Chad Dupuis (1):
  scsi: qedf: Fix crash due to unsolicited FIP VLAN response.

Fam Zheng (1):
  scsi: sd: Consider max_xfer_blocks if opt_xfer_blocks is unusable

Guilherme G. Piccoli (1):
  scsi: aacraid: fix PCI error recovery path

Martin K. Petersen (2):
  scsi: sd: Fix capacity calculation with 32-bit sector_t
  scsi: sr: Sanity check returned mode data

Mauricio Faria de Oliveira (1):
  scsi: ipr: do not set DID_PASSTHROUGH on CHECK CONDITION

Sawan Chandak (1):
  scsi: qla2xxx: Add fix to read correct register value for ISP82xx.

With diffstat:

 drivers/scsi/aacraid/aacraid.h | 11 ---
 drivers/scsi/aacraid/commsup.c |  3 ++-
 drivers/scsi/ipr.c |  7 ++-
 drivers/scsi/qedf/qedf_fip.c   |  3 ++-
 drivers/scsi/qedf/qedf_main.c  |  1 +
 drivers/scsi/qla2xxx/qla_os.c  |  7 ++-
 drivers/scsi/sd.c  | 23 ---
 drivers/scsi/sr.c  |  6 --
 8 files changed, 49 insertions(+), 12 deletions(-)

And full diff below.

James

---

diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index d036a806f31c..d281492009fb 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -1690,9 +1690,6 @@ struct aac_dev
 #define aac_adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, 
r2, r3, r4) \
(dev)->a_ops.adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, 
status, r1, r2, r3, r4)
 
-#define aac_adapter_check_health(dev) \
-   (dev)->a_ops.adapter_check_health(dev)
-
 #define aac_adapter_restart(dev, bled, reset_type) \
((dev)->a_ops.adapter_restart(dev, bled, reset_type))
 
@@ -2615,6 +2612,14 @@ static inline unsigned int cap_to_cyls(sector_t 
capacity, unsigned divisor)
return capacity;
 }
 
+static inline int aac_adapter_check_health(struct aac_dev *dev)
+{
+   if (unlikely(pci_channel_offline(dev->pdev)))
+   return -1;
+
+   return (dev)->a_ops.adapter_check_health(dev);
+}
+
 /* SCp.phase values */
 #define AAC_OWNER_MIDLEVEL 0x101
 #define AAC_OWNER_LOWLEVEL 0x102
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index c8172f16cf33..1f4918355fdb 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -1873,7 +1873,8 @@ int aac_check_health(struct aac_dev * aac)
spin_unlock_irqrestore(&aac->fib_lock, flagv);
 
if (BlinkLED < 0) {
-   printk(KERN_ERR "%s: Host adapter dead %d\n", aac->name, 
BlinkLED);
+   printk(KERN_ERR "%s: Host adapter is dead (or got a PCI error) 
%d\n",
+   aac->name, BlinkLED);
goto out;
}
 
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index b29afafc2885..5d5e272fd815 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -6293,7 +6293,12 @@ static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
break;
case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
case IPR_IOASA_IR_DUAL_IOA_DISABLED:
-   scsi_cmd->result |= (DID_PASSTHROUGH << 16);
+   /*
+* exception: do not set DID_PASSTHROUGH on CHECK CONDITION
+* so SCSI mid-layer and upper layers handle it accordingly.
+*/
+   if (scsi_cmd->result != SAM_STAT_CHECK_CONDITION)
+   scsi_cmd->result |= (DID_PASSTHROUGH << 16);
break;
case IPR_IOASC_BUS_WAS_RESET:
case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
diff --git a/drivers/scsi/qedf/qedf_fip.c b/drivers/scsi/qedf/qedf_fip.c
index ed58b9104f58..e10b91cc3c62 100644
--- a/drivers/scsi/qedf/qedf_fip.c
+++ b/drivers/scsi/qedf/qedf_fip.c
@@ -99,7 +99,8 @@ static void qedf_fcoe_process_vlan_resp(struct qedf_ctx *qedf,
qedf_set_vlan_id(qedf, vid);
 
/* Inform waiter that it's ok to call fcoe_ctlr_link up() */
-   complete(&qedf->fipvlan_compl);
+   if (!completion_done(&qedf->fipvlan_compl))
+   complete(&qedf->fipvlan_compl);
}
 }
 
diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
index 8e2a160490e6..cceddd995a4b 100644
--- a/dr

Re: [backport v4.9] tpm_tis: use default timeout value if chip reports it as zero

2017-04-15 Thread Maciej S. Szmigiero

Hi Jarkko,

On 15.04.2017 17:26, Jarkko Sakkinen wrote:

From: "Maciej S. Szmigiero" 

Since commit 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for
TPM access") Atmel 3203 TPM on ThinkPad X61S (TPM firmware version 13.9)
no longer works.  The initialization proceeds fine until we get and
start using chip-reported timeouts - and the chip reports C and D
timeouts of zero.

It turns out that until commit 8e54caf407b98e ("tpm: Provide a generic
means to override the chip returned timeouts") we had actually let
default timeout values remain in this case, so let's bring back this
behavior to make chips like Atmel 3203 work again.

Use a common code that was introduced by that commit so a warning is
printed in this case and /sys/class/tpm/tpm*/timeouts correctly says the
timeouts aren't chip-original.

Fixes: 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for TPM access")
Cc: sta...@vger.kernel.org
Signed-off-by: Maciej S. Szmigiero 
Reviewed-by: Jarkko Sakkinen 
Signed-off-by: Jarkko Sakkinen 
---
Backport v4.9. Can you test it?
 drivers/char/tpm/tpm-interface.c | 59 ++--
 drivers/char/tpm/tpm_tis.c   |  2 +-
 drivers/char/tpm/tpm_tis_core.c  |  6 ++--
 drivers/char/tpm/tpm_tis_core.h  |  2 +-
 4 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 3a9149cf0110..4c914fe25802 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c

(..)

@@ -537,16 +537,15 @@ int tpm_get_timeouts(struct tpm_chip *chip)
goto duration;
}

-   if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 ||
-   be32_to_cpu(tpm_cmd.header.out.length)
-   != sizeof(tpm_cmd.header.out) + sizeof(u32) + 4 * sizeof(u32))
-   return -EINVAL;
-


Is this part right?
These tests weren't removed by this commit as present in the mainline kernel.

Maciej



[GIT PULL] parisc architecture fix for v4.11-rc7

2017-04-15 Thread Helge Deller
Hi Linus,

please pull one important fix for the parisc architecture for kernel 4.11-rc7 
from:

  git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git 
parisc-4.11-4

Mikulas Patocka fixed a few bugs in our new pa_memcpy() assembler function,
e.g. one bug made the kernel unbootable if source and destination address are
the same.

Thanks,
Helge


Mikulas Patocka (1):
  parisc: fix bugs in pa_memcpy

 arch/parisc/lib/lusercopy.S | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)


Re: [RFC PATCH v5 6/6] mtd: spi-nor: parse SFDP 4-byte Address Instruction Table

2017-04-15 Thread Marek Vasut
On 03/23/2017 12:33 AM, Cyrille Pitchen wrote:
> This patch adds supports for SFDP (JESD216B) 4-byte Address Instruction
> Table. This table is optional but when available, we parse it to get the
> 4-byte address op codes supported by the memory.
> Using these op codes is stateless as opposed to entering the 4-byte
> address mode or setting the Base Address Register (BAR).
> 
> Signed-off-by: Cyrille Pitchen 
> ---
>  drivers/mtd/spi-nor/spi-nor.c | 166 
> +-
>  1 file changed, 165 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index ce8722055a9c..ea044efc4e6d 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -1899,6 +1899,7 @@ struct sfdp_parameter_header {
>  
>  
>  #define SFDP_BFPT_ID 0xff00u /* Basic Flash Parameter Table */
> +#define SFDP_4BAIT_ID0xff84u /* 4-byte Address Instruction 
> Table */
>  
>  #define SFDP_SIGNATURE   0x50444653u
>  #define SFDP_JESD216_MAJOR   1
> @@ -2241,6 +2242,149 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
>   return 0;
>  }
>  
> +struct sfdp_4bait {
> + /* The hardware capability. */
> + u32 hwcaps;
> +
> + /*
> +  * The  bit in DWORD1 of the 4BAIT tells us whether
> +  * the associated 4-byte address op code is supported.
> +  */
> + u32 supported_bit;
> +};
> +
> +static int spi_nor_parse_4bait(struct spi_nor *nor,
> +const struct sfdp_parameter_header *param_header,
> +struct spi_nor_flash_parameter *params)
> +{
> + static const struct sfdp_4bait reads[] = {
> + { SNOR_HWCAPS_READ, BIT(0) },
> + { SNOR_HWCAPS_READ_FAST,BIT(1) },
> + { SNOR_HWCAPS_READ_1_1_2,   BIT(2) },
> + { SNOR_HWCAPS_READ_1_2_2,   BIT(3) },
> + { SNOR_HWCAPS_READ_1_1_4,   BIT(4) },
> + { SNOR_HWCAPS_READ_1_4_4,   BIT(5) },
> + { SNOR_HWCAPS_READ_1_1_1_DTR,   BIT(13) },
> + { SNOR_HWCAPS_READ_1_2_2_DTR,   BIT(14) },
> + { SNOR_HWCAPS_READ_1_4_4_DTR,   BIT(15) },
> + };
> + static const struct sfdp_4bait programs[] = {
> + { SNOR_HWCAPS_PP,   BIT(6) },
> + { SNOR_HWCAPS_PP_1_1_4, BIT(7) },
> + { SNOR_HWCAPS_PP_1_4_4, BIT(8) },
> + };
> + static const struct sfdp_4bait erases[SNOR_CMD_ERASE_MAX] = {
> + { 0u /* not used */,BIT(9) },
> + { 0u /* not used */,BIT(10) },
> + { 0u /* not used */,BIT(11) },
> + { 0u /* not used */,BIT(12) },
> + };
> + u32 dwords[2], addr, discard_hwcaps, read_hwcaps, pp_hwcaps, erase_mask;
> + struct spi_nor_erase_map *map = &nor->erase_map;
> + int i, err;
> +
> + if (param_header->major != SFDP_JESD216_MAJOR ||
> + param_header->length < ARRAY_SIZE(dwords))
> + return -EINVAL;
> +
> + /* Read the 4-byte Address Instruction Table. */
> + addr = SFDP_PARAM_HEADER_PTP(param_header);
> + err = spi_nor_read_sfdp(nor, addr, sizeof(dwords), dwords);
> + if (err)
> + return err;
> +
> + /* Fix endianness of the 4BAIT DWORDs. */
> + for (i = 0; i < ARRAY_SIZE(dwords); i++)
> + dwords[i] = le32_to_cpu(dwords[i]);
> +
> + /*
> +  * Compute the subset of (Fast) Read commands for which the 4-byte
> +  * version is supported.
> +  */
> + discard_hwcaps = 0;
> + read_hwcaps = 0;
> + for (i = 0; i < ARRAY_SIZE(reads); i++) {
> + const struct sfdp_4bait *read = &reads[i];
> +
> + discard_hwcaps |= read->hwcaps;
> + if ((params->hwcaps.mask & read->hwcaps) &&
> + (dwords[0] & read->supported_bit))
> + read_hwcaps |= read->hwcaps;
> + }

Looks like there is a bit of repeated stuff here, maybe this can be
pulled out ?

> + /*
> +  * Compute the subset of Page Program commands for which the 4-byte
> +  * version is supported.
> +  */
> + pp_hwcaps = 0;
> + for (i = 0; i < ARRAY_SIZE(programs); i++) {
> + const struct sfdp_4bait *program = &programs[i];
> +
> + discard_hwcaps |= program->hwcaps;
> + if ((params->hwcaps.mask & program->hwcaps) &&
> + (dwords[0] & program->supported_bit))
> + pp_hwcaps |= program->hwcaps;
> + }
> +
> + /*
> +  * Compute the subet of Sector Erase commands for which the 4-byte
> +  * version is supported.
> +  */
> + erase_mask = 0;
> + for (i = 0; i < SNOR_CMD_ERASE_MAX; i++) {
> + const struct sfdp_4bait *erase = &erases[i];
> +
> + if ((map->commands[i].size > 0) &&
> + (dwords[0] & erase->s

Re: [RFC PATCH v5 4/6] mtd: spi-nor: add support to non-uniform SPI NOR flash memories

2017-04-15 Thread Marek Vasut
On 03/23/2017 12:33 AM, Cyrille Pitchen wrote:

Hr, sigh, took me almost month to review this one, sorry :(

> This patch is a first step in introducing  the support of SPI memories
> with non-uniform erase sizes like Spansion s25fs512s.
> 
> It introduces the memory erase map which splits the memory array into one
> or many erase regions. Each erase region supports up to 4 erase commands,
> as defined by the JEDEC JESD216B (SFDP) specification.
> In turn, an erase command is defined by an op code and a sector size.
> 
> To be backward compatible, the erase map of uniform SPI NOR flash memories
> is initialized so it contains only one erase region and this erase region
> supports only one erase command. Hence a single size is used to erase any
> sector/block of the memory.
> 
> Besides, since the algorithm used to erase sectors on non-uniform SPI NOR
> flash memories is quite expensive, when possible, the erase map is tuned
> to come back to the uniform case.
> 
> This is a transitional patch: non-uniform erase maps will be used later
> when initialized based on the SFDP data.
> 
> Signed-off-by: Cyrille Pitchen 

[...]

Before I dive into the code, I have two questions:

1) On ie. 128 MiB part, how many struct spi_nor_erase_region {}
   instances would be allocated in total (consider you support
   4k, 64k and 32M erase opcodes) ? Three ?

2) Would it make sense to represent the erase regions as a tree instead?
   For example

  [ region with 32MiB die erase opcode , start=0 , count=4 ]
|
V
[ region with 64k erase opcode ][ region with 64k erase opcode ]
[   start=0, count=1   ][  start=0, count=511  ]
|
V
[ region with 4k erase opcode ]
[  start=0, count=16  ]

I think it'd make the lookup for the best-fitting opcode combination
faster if the user decides to erase some arbitrarily-aligned block of
the flash.

What do you think ?

Note this tree-based approach does not handle the cases where erase
regions would overlap, although I doubt that could be a problem .

> diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
> index d270788f5ab6..c12cafe99bee 100644
> --- a/include/linux/mtd/spi-nor.h
> +++ b/include/linux/mtd/spi-nor.h
> @@ -216,6 +216,55 @@ enum spi_nor_option_flags {
>  };
>  
>  /**
> + * struct spi_nor_erase_command - Structure to describe a SPI NOR erase 
> command
> + * @size:the size of the sector/block erased by the command.
> + * @size_shift:  the size shift: if @size is a power of 2 then 
> the shift
> + *   is stored in @size_shift, otherwise @size_shift is zero.
> + * @size_mask:   the size mask based on @size_shift.
> + * @opcode:  the SPI command op code to erase the sector/block.
> + */
> +struct spi_nor_erase_command {
> + u32 size;
> + u32 size_shift;
> + u32 size_mask;
> + u8  opcode;
> +};
> +
> +/**
> + * struct spi_nor_erase_region - Structure to describe a SPI NOR erase region
> + * @offset:  the offset in the data array of erase region start.
> + *   LSB bits are used as a bitmask encoding the erase
> + *   commands supported inside this erase region.
> + * @size:the size of the region in bytes.
> + */
> +struct spi_nor_erase_region {
> + u64 offset;
> + u64 size;
> +};
> +
> +#define SNOR_CMD_ERASE_MAX   4
> +#define SNOR_CMD_ERASE_MASK  GENMASK_ULL(SNOR_CMD_ERASE_MAX - 1, 0)
> +#define SNOR_CMD_ERASE_OFFSET(_cmd_mask, _offset)\
> + u64)(_offset)) & ~SNOR_CMD_ERASE_MASK) |\
> +  (((u64)(_cmd_mask)) & SNOR_CMD_ERASE_MASK))
> +
> +/**
> + * struct spi_nor_erase_map - Structure to describe the SPI NOR erase map
> + * @commands:an array of erase commands shared by all the 
> regions.
> + * @uniform_region:  a pre-allocated erase region for SPI NOR with a uniform
> + *   sector size (legacy implementation).
> + * @regions: point to an array describing the boundaries of the erase
> + *   regions.
> + * @num_regions: the number of elements in the @regions array.
> + */
> +struct spi_nor_erase_map {
> + struct spi_nor_erase_commandcommands[SNOR_CMD_ERASE_MAX];
> + struct spi_nor_erase_region uniform_region;
> + struct spi_nor_erase_region *regions;
> + u32 num_regions;
> +};
> +
> +/**
>   * struct flash_info -   Forward declaration of a structure used 
> internally by
>   *   spi_nor_scan() and spi_nor_init().
>   */
> @@ -238,6 +287,7 @@ struct flash_info;
>   * @write_proto: the SPI protocol for write operations
>   * @reg_protothe SPI protocol for read_reg/write_reg/erase 
> operations
>   * @cmd_buf: used by the write_reg
> + * @erase_map:   the erase map of the SPI NOR
>   * @prepare: [OPTIONAL] do some p

Re: [RFC PATCH v5 5/6] mtd: spi-nor: parse Serial Flash Discoverable Parameters (SFDP) tables

2017-04-15 Thread Marek Vasut
On 03/23/2017 12:33 AM, Cyrille Pitchen wrote:
> This patch adds support to the JESD216B standard and parses the SFDP
> tables to dynamically initialize the 'struct spi_nor_flash_parameter'.
> 
> Signed-off-by: Cyrille Pitchen 

Hi, mostly nits below.

> ---
>  drivers/mtd/spi-nor/spi-nor.c | 558 
> ++
>  include/linux/mtd/spi-nor.h   |   6 +
>  2 files changed, 564 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 2e54792d506d..ce8722055a9c 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -17,6 +17,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include 
>  #include 
> @@ -86,6 +87,7 @@ struct flash_info {
>* to support memory size above 128Mib.
>*/
>  #define NO_CHIP_ERASEBIT(12) /* Chip does not support chip 
> erase */
> +#define SPI_NOR_SKIP_SFDPBIT(13) /* Skip parsing of SFDP tables */
>  };
>  
>  #define JEDEC_MFR(info)  ((info)->id[0])
> @@ -1593,6 +1595,99 @@ static int spansion_quad_enable(struct spi_nor *nor)
>   return 0;
>  }
>  
> +static int spansion_new_quad_enable(struct spi_nor *nor)
> +{
> + u8 sr_cr[2];
> + int ret;
> +
> + /* Check current Quad Enable bit value. */
> + ret = read_cr(nor);
> + if (ret < 0) {
> + dev_err(nor->dev,
> + "error while reading configuration register\n");
> + return -EINVAL;
> + }
> + sr_cr[1] = ret;
> + if (sr_cr[1] & CR_QUAD_EN_SPAN)
> + return 0;
> +
> + dev_info(nor->dev, "setting Spansion Quad Enable (non-volatile) bit\n");
> +
> + /* Keep the current value of the Status Register. */
> + ret = read_sr(nor);
> + if (ret < 0) {
> + dev_err(nor->dev,
> + "error while reading status register\n");
> + return -EINVAL;
> + }
> + sr_cr[0] = ret;
> + sr_cr[1] |= CR_QUAD_EN_SPAN;
> +
> + write_enable(nor);
> +
> + ret = nor->write_reg(nor, SPINOR_OP_WRSR, sr_cr, 2);
> + if (ret < 0) {
> + dev_err(nor->dev,
> + "error while writing configuration register\n");
> + return -EINVAL;
> + }
> +
> + ret = spi_nor_wait_till_ready(nor);
> + if (ret < 0) {
> + dev_err(nor->dev, "error while waiting for WRSR completion\n");
> + return ret;
> + }
> +
> + /* read back and check it */
> + ret = read_cr(nor);
> + if (!(ret > 0 && (ret & CR_QUAD_EN_SPAN))) {

Nit, you might want to align this with sr2_bit7_quad_enable() below, that is

if (ret || !(ret & CR_QUAD_ENABLE_SPAN))
 ...

> + dev_err(nor->dev, "Spansion Quad bit not set\n");
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +static int sr2_bit7_quad_enable(struct spi_nor *nor)
> +{
> + u8 sr2;
> + int ret;
> +
> + /* Check current Quad Enable bit value. */
> + ret = nor->read_reg(nor, SPINOR_OP_RDSR2, &sr2, 1);
> + if (ret)
> + return ret;
> + if (sr2 & SR2_QUAD_EN_BIT7)
> + return 0;
> +
> + /* Update the Quad Enable bit. */
> + sr2 |= SR2_QUAD_EN_BIT7;
> +
> + write_enable(nor);
> +
> + ret = nor->write_reg(nor, SPINOR_OP_WRSR2, &sr2, 1);
> + if (ret < 0) {
> + dev_err(nor->dev,
> + "error while writing status register 2\n");
> + return -EINVAL;
> + }
> +
> + ret = spi_nor_wait_till_ready(nor);
> + if (ret < 0) {
> + dev_err(nor->dev, "error while waiting for WRSR2 completion\n");
> + return ret;
> + }
> +
> + /* Read back and check it. */
> + ret = nor->read_reg(nor, SPINOR_OP_RDSR2, &sr2, 1);
> + if (ret || !(sr2 & SR2_QUAD_EN_BIT7)) {
> + dev_err(nor->dev, "SR2 Quad bit not set\n");
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
>  static int spi_nor_check(struct spi_nor *nor)
>  {
>   if (!nor->dev || !nor->read || !nor->write ||
> @@ -1759,6 +1854,465 @@ spi_nor_init_uniform_erase_map(struct 
> spi_nor_erase_map *map,
>   map->uniform_region.size = flash_size;
>  }
>  
> +
> +/*
> + * SFDP parsing.
> + */
> +
> +static int spi_nor_read_sfdp(struct spi_nor *nor, u32 addr,
> +  size_t len, void *buf)
> +{
> + u8 addr_width, read_opcode, read_dummy;
> + int ret;
> +
> + read_opcode = nor->read_opcode;
> + addr_width = nor->addr_width;
> + read_dummy = nor->read_dummy;
> +
> + nor->read_opcode = SPINOR_OP_RDSFDP;
> + nor->addr_width = 3;
> + nor->read_dummy = 8;
> +
> + ret = nor->read(nor, addr, len, (u8 *)buf);
> +
> + nor->read_opcode = read_opcode;
> + nor->addr_width = addr_width;
> + nor->read_dummy = read_dummy;
> +
> + return (ret < 0) ? ret : 0;
> +}
> +
> +struct sfdp_parameter

[backport v4.9] tpm_tis: use default timeout value if chip reports it as zero

2017-04-15 Thread Jarkko Sakkinen
From: "Maciej S. Szmigiero" 

Since commit 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for
TPM access") Atmel 3203 TPM on ThinkPad X61S (TPM firmware version 13.9)
no longer works.  The initialization proceeds fine until we get and
start using chip-reported timeouts - and the chip reports C and D
timeouts of zero.

It turns out that until commit 8e54caf407b98e ("tpm: Provide a generic
means to override the chip returned timeouts") we had actually let
default timeout values remain in this case, so let's bring back this
behavior to make chips like Atmel 3203 work again.

Use a common code that was introduced by that commit so a warning is
printed in this case and /sys/class/tpm/tpm*/timeouts correctly says the
timeouts aren't chip-original.

Fixes: 1107d065fdf1 ("tpm_tis: Introduce intermediate layer for TPM access")
Cc: sta...@vger.kernel.org
Signed-off-by: Maciej S. Szmigiero 
Reviewed-by: Jarkko Sakkinen 
Signed-off-by: Jarkko Sakkinen 
---
Backport v4.9. Can you test it?
 drivers/char/tpm/tpm-interface.c | 59 ++--
 drivers/char/tpm/tpm_tis.c   |  2 +-
 drivers/char/tpm/tpm_tis_core.c  |  6 ++--
 drivers/char/tpm/tpm_tis_core.h  |  2 +-
 4 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 3a9149cf0110..4c914fe25802 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -489,9 +489,9 @@ static int tpm_startup(struct tpm_chip *chip, __be16 
startup_type)
 int tpm_get_timeouts(struct tpm_chip *chip)
 {
struct tpm_cmd_t tpm_cmd;
-   unsigned long new_timeout[4];
-   unsigned long old_timeout[4];
struct duration_t *duration_cap;
+   cap_t cap;
+   unsigned long timeout_old[4], timeout_chip[4], timeout_eff[4];
ssize_t rc;
 
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
@@ -537,16 +537,15 @@ int tpm_get_timeouts(struct tpm_chip *chip)
goto duration;
}
 
-   if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 ||
-   be32_to_cpu(tpm_cmd.header.out.length)
-   != sizeof(tpm_cmd.header.out) + sizeof(u32) + 4 * sizeof(u32))
-   return -EINVAL;
-
-   old_timeout[0] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.a);
-   old_timeout[1] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.b);
-   old_timeout[2] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.c);
-   old_timeout[3] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.d);
-   memcpy(new_timeout, old_timeout, sizeof(new_timeout));
+   timeout_old[0] = jiffies_to_usecs(chip->timeout_a);
+   timeout_old[1] = jiffies_to_usecs(chip->timeout_b);
+   timeout_old[2] = jiffies_to_usecs(chip->timeout_c);
+   timeout_old[3] = jiffies_to_usecs(chip->timeout_d);
+   timeout_chip[0] = be32_to_cpu(cap.timeout.a);
+   timeout_chip[1] = be32_to_cpu(cap.timeout.b);
+   timeout_chip[2] = be32_to_cpu(cap.timeout.c);
+   timeout_chip[3] = be32_to_cpu(cap.timeout.d);
+   memcpy(timeout_eff, timeout_chip, sizeof(timeout_eff));
 
/*
 * Provide ability for vendor overrides of timeout values in case
@@ -554,16 +553,24 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 */
if (chip->ops->update_timeouts != NULL)
chip->timeout_adjusted =
-   chip->ops->update_timeouts(chip, new_timeout);
+   chip->ops->update_timeouts(chip, timeout_eff);
 
if (!chip->timeout_adjusted) {
-   /* Don't overwrite default if value is 0 */
-   if (new_timeout[0] != 0 && new_timeout[0] < 1000) {
-   int i;
+   /* Restore default if chip reported 0 */
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(timeout_eff); i++) {
+   if (timeout_eff[i])
+   continue;
+
+   timeout_eff[i] = timeout_old[i];
+   chip->timeout_adjusted = true;
+   }
 
+   if (timeout_eff[0] != 0 && timeout_eff[0] < 1000) {
/* timeouts in msec rather usec */
-   for (i = 0; i != ARRAY_SIZE(new_timeout); i++)
-   new_timeout[i] *= 1000;
+   for (i = 0; i != ARRAY_SIZE(timeout_eff); i++)
+   timeout_eff[i] *= 1000;
chip->timeout_adjusted = true;
}
}
@@ -572,16 +579,16 @@ int tpm_get_timeouts(struct tpm_chip *chip)
if (chip->timeout_adjusted) {
dev_info(&chip->dev,
 HW_ERR "Adjusting reported timeouts: A %lu->%luus B 
%lu->%luus C %lu->%luus D %lu->%luus\n",
-old_timeout[0], new_timeout[0],
-old_timeout[1], new_timeout[1],
-old_timeout[2], new_timeout[2],
- 

  1   2   >