[PATCH AUTOSEL 4.14 55/73] usb: gadget: udc: atmel: handle at91sam9rl PMC

2018-10-31 Thread Sasha Levin
From: Alexandre Belloni 

[ Upstream commit bb80e4fa57eb75ebd64ae9be4155da6d12c1a997 ]

The at91sam9rl PMC is not quite the same as the at91sam9g45 one and now has
its own compatible string. Add support for that.

Fixes: 217bace8e548 ("ARM: dts: fix PMC compatible")
Acked-by: Cristian Birsan 
Signed-off-by: Alexandre Belloni 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index a884c022df7a..cb66f982c313 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -2071,6 +2071,8 @@ static struct usba_ep * atmel_udc_of_init(struct 
platform_device *pdev,
 
udc->errata = match->data;
udc->pmc = syscon_regmap_lookup_by_compatible("atmel,at91sam9g45-pmc");
+   if (IS_ERR(udc->pmc))
+   udc->pmc = 
syscon_regmap_lookup_by_compatible("atmel,at91sam9rl-pmc");
if (IS_ERR(udc->pmc))
udc->pmc = 
syscon_regmap_lookup_by_compatible("atmel,at91sam9x5-pmc");
if (udc->errata && IS_ERR(udc->pmc))
-- 
2.17.1



[PATCH AUTOSEL 4.14 62/73] crypto: caam - fix implicit casts in endianness helpers

2018-10-31 Thread Sasha Levin
From: Horia Geantă 

[ Upstream commit aae733a3f46f5ef338fbdde26e14cbb205a23de0 ]

Fix the following sparse endianness warnings:

drivers/crypto/caam/regs.h:95:1: sparse: incorrect type in return expression 
(different base types) @@expected unsigned int @@got restricted 
__le32unsigned int @@
drivers/crypto/caam/regs.h:95:1:expected unsigned int
drivers/crypto/caam/regs.h:95:1:got restricted __le32 [usertype] 
drivers/crypto/caam/regs.h:95:1: sparse: incorrect type in return expression 
(different base types) @@expected unsigned int @@got restricted 
__be32unsigned int @@
drivers/crypto/caam/regs.h:95:1:expected unsigned int
drivers/crypto/caam/regs.h:95:1:got restricted __be32 [usertype] 

drivers/crypto/caam/regs.h:92:1: sparse: cast to restricted __le32
drivers/crypto/caam/regs.h:92:1: sparse: cast to restricted __be32

Fixes: 261ea058f016 ("crypto: caam - handle core endianness != caam endianness")
Reported-by: kbuild test robot 
Signed-off-by: Horia Geantă 
Signed-off-by: Herbert Xu 
Signed-off-by: Sasha Levin 
---
 drivers/crypto/caam/regs.h | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h
index fee363865d88..e5513cc59ec3 100644
--- a/drivers/crypto/caam/regs.h
+++ b/drivers/crypto/caam/regs.h
@@ -70,22 +70,22 @@
 extern bool caam_little_end;
 extern bool caam_imx;
 
-#define caam_to_cpu(len)   \
-static inline u##len caam##len ## _to_cpu(u##len val)  \
-{  \
-   if (caam_little_end)\
-   return le##len ## _to_cpu(val); \
-   else\
-   return be##len ## _to_cpu(val); \
+#define caam_to_cpu(len)   \
+static inline u##len caam##len ## _to_cpu(u##len val)  \
+{  \
+   if (caam_little_end)\
+   return le##len ## _to_cpu((__force __le##len)val);  \
+   else\
+   return be##len ## _to_cpu((__force __be##len)val);  \
 }
 
-#define cpu_to_caam(len)   \
-static inline u##len cpu_to_caam##len(u##len val)  \
-{  \
-   if (caam_little_end)\
-   return cpu_to_le##len(val); \
-   else\
-   return cpu_to_be##len(val); \
+#define cpu_to_caam(len)   \
+static inline u##len cpu_to_caam##len(u##len val)  \
+{  \
+   if (caam_little_end)\
+   return (__force u##len)cpu_to_le##len(val); \
+   else\
+   return (__force u##len)cpu_to_be##len(val); \
 }
 
 caam_to_cpu(16)
-- 
2.17.1



[PATCH AUTOSEL 4.14 57/73] MD: fix invalid stored role for a disk

2018-10-31 Thread Sasha Levin
From: Shaohua Li 

[ Upstream commit d595567dc4f0c1d90685ec1e2e296e2cad2643ac ]

If we change the number of array's device after device is removed from array,
then add the device back to array, we can see that device is added as active
role instead of spare which we expected.

Please see the below link for details:
https://marc.info/?l=linux-raid=153736982015076=2

This is caused by that we prefer to use device's previous role which is
recorded by saved_raid_disk, but we should respect the new number of
conf->raid_disks since it could be changed after device is removed.

Reported-by: Gioh Kim 
Tested-by: Gioh Kim 
Acked-by: Guoqing Jiang 
Signed-off-by: Shaohua Li 
Signed-off-by: Sasha Levin 
---
 drivers/md/md.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 5599712d478e..4c1a6abed606 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1766,6 +1766,10 @@ static int super_1_validate(struct mddev *mddev, struct 
md_rdev *rdev)
} else
set_bit(In_sync, >flags);
rdev->raid_disk = role;
+   if (role >= mddev->raid_disks) {
+   rdev->saved_raid_disk = -1;
+   rdev->raid_disk = -1;
+   }
break;
}
if (sb->devflags & WriteMostly1)
-- 
2.17.1



[PATCH AUTOSEL 4.14 57/73] MD: fix invalid stored role for a disk

2018-10-31 Thread Sasha Levin
From: Shaohua Li 

[ Upstream commit d595567dc4f0c1d90685ec1e2e296e2cad2643ac ]

If we change the number of array's device after device is removed from array,
then add the device back to array, we can see that device is added as active
role instead of spare which we expected.

Please see the below link for details:
https://marc.info/?l=linux-raid=153736982015076=2

This is caused by that we prefer to use device's previous role which is
recorded by saved_raid_disk, but we should respect the new number of
conf->raid_disks since it could be changed after device is removed.

Reported-by: Gioh Kim 
Tested-by: Gioh Kim 
Acked-by: Guoqing Jiang 
Signed-off-by: Shaohua Li 
Signed-off-by: Sasha Levin 
---
 drivers/md/md.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 5599712d478e..4c1a6abed606 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1766,6 +1766,10 @@ static int super_1_validate(struct mddev *mddev, struct 
md_rdev *rdev)
} else
set_bit(In_sync, >flags);
rdev->raid_disk = role;
+   if (role >= mddev->raid_disks) {
+   rdev->saved_raid_disk = -1;
+   rdev->raid_disk = -1;
+   }
break;
}
if (sb->devflags & WriteMostly1)
-- 
2.17.1



[PATCH AUTOSEL 4.14 61/73] PCI: dwc: pci-dra7xx: Enable errata i870 for both EP and RC mode

2018-10-31 Thread Sasha Levin
From: Vignesh R 

[ Upstream commit 726d75a6d243bf6730da3216f3592503f6f0f588 ]

Errata i870 is applicable in both EP and RC mode. Therefore rename
function dra7xx_pcie_ep_unaligned_memaccess(), that implements errata
workaround, to dra7xx_pcie_unaligned_memaccess() and call it for both RC
and EP. Make sure driver probe does not fail in case the workaround is not
applied for RC mode in order to maintain DT backward compatibility.

Reported-by: Chris Welch 
Signed-off-by: Vignesh R 
[lorenzo.pieral...@arm.com: reworded the log]
Signed-off-by: Lorenzo Pieralisi 
Acked-by: Kishon Vijay Abraham I 
Signed-off-by: Sasha Levin 
---
 drivers/pci/dwc/pci-dra7xx.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
index 362607f727ee..06eae132aff7 100644
--- a/drivers/pci/dwc/pci-dra7xx.c
+++ b/drivers/pci/dwc/pci-dra7xx.c
@@ -546,7 +546,7 @@ static const struct of_device_id of_dra7xx_pcie_match[] = {
 };
 
 /*
- * dra7xx_pcie_ep_unaligned_memaccess: workaround for AM572x/AM571x Errata i870
+ * dra7xx_pcie_unaligned_memaccess: workaround for AM572x/AM571x Errata i870
  * @dra7xx: the dra7xx device where the workaround should be applied
  *
  * Access to the PCIe slave port that are not 32-bit aligned will result
@@ -556,7 +556,7 @@ static const struct of_device_id of_dra7xx_pcie_match[] = {
  *
  * To avoid this issue set PCIE_SS1_AXI2OCP_LEGACY_MODE_ENABLE to 1.
  */
-static int dra7xx_pcie_ep_unaligned_memaccess(struct device *dev)
+static int dra7xx_pcie_unaligned_memaccess(struct device *dev)
 {
int ret;
struct device_node *np = dev->of_node;
@@ -707,6 +707,11 @@ static int __init dra7xx_pcie_probe(struct platform_device 
*pdev)
case DW_PCIE_RC_TYPE:
dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_DEVICE_TYPE,
   DEVICE_TYPE_RC);
+
+   ret = dra7xx_pcie_unaligned_memaccess(dev);
+   if (ret)
+   dev_err(dev, "WA for Errata i870 not applied\n");
+
ret = dra7xx_add_pcie_port(dra7xx, pdev);
if (ret < 0)
goto err_gpio;
@@ -715,7 +720,7 @@ static int __init dra7xx_pcie_probe(struct platform_device 
*pdev)
dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_DEVICE_TYPE,
   DEVICE_TYPE_EP);
 
-   ret = dra7xx_pcie_ep_unaligned_memaccess(dev);
+   ret = dra7xx_pcie_unaligned_memaccess(dev);
if (ret)
goto err_gpio;
 
-- 
2.17.1



Re: [GIT PULL] RISC-V Patches for the 4.20 Merge Window, Part 2 v2

2018-10-31 Thread Linus Torvalds
On Wed, Oct 31, 2018 at 4:07 PM Palmer Dabbelt  wrote:
>
> RISC-V Patches for the 4.20 Merge Window, Part 2 v2

Pulled.

Linus


Re: [GIT PULL] RISC-V Patches for the 4.20 Merge Window, Part 2 v2

2018-10-31 Thread Linus Torvalds
On Wed, Oct 31, 2018 at 4:07 PM Palmer Dabbelt  wrote:
>
> RISC-V Patches for the 4.20 Merge Window, Part 2 v2

Pulled.

Linus


[PATCH AUTOSEL 4.14 61/73] PCI: dwc: pci-dra7xx: Enable errata i870 for both EP and RC mode

2018-10-31 Thread Sasha Levin
From: Vignesh R 

[ Upstream commit 726d75a6d243bf6730da3216f3592503f6f0f588 ]

Errata i870 is applicable in both EP and RC mode. Therefore rename
function dra7xx_pcie_ep_unaligned_memaccess(), that implements errata
workaround, to dra7xx_pcie_unaligned_memaccess() and call it for both RC
and EP. Make sure driver probe does not fail in case the workaround is not
applied for RC mode in order to maintain DT backward compatibility.

Reported-by: Chris Welch 
Signed-off-by: Vignesh R 
[lorenzo.pieral...@arm.com: reworded the log]
Signed-off-by: Lorenzo Pieralisi 
Acked-by: Kishon Vijay Abraham I 
Signed-off-by: Sasha Levin 
---
 drivers/pci/dwc/pci-dra7xx.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
index 362607f727ee..06eae132aff7 100644
--- a/drivers/pci/dwc/pci-dra7xx.c
+++ b/drivers/pci/dwc/pci-dra7xx.c
@@ -546,7 +546,7 @@ static const struct of_device_id of_dra7xx_pcie_match[] = {
 };
 
 /*
- * dra7xx_pcie_ep_unaligned_memaccess: workaround for AM572x/AM571x Errata i870
+ * dra7xx_pcie_unaligned_memaccess: workaround for AM572x/AM571x Errata i870
  * @dra7xx: the dra7xx device where the workaround should be applied
  *
  * Access to the PCIe slave port that are not 32-bit aligned will result
@@ -556,7 +556,7 @@ static const struct of_device_id of_dra7xx_pcie_match[] = {
  *
  * To avoid this issue set PCIE_SS1_AXI2OCP_LEGACY_MODE_ENABLE to 1.
  */
-static int dra7xx_pcie_ep_unaligned_memaccess(struct device *dev)
+static int dra7xx_pcie_unaligned_memaccess(struct device *dev)
 {
int ret;
struct device_node *np = dev->of_node;
@@ -707,6 +707,11 @@ static int __init dra7xx_pcie_probe(struct platform_device 
*pdev)
case DW_PCIE_RC_TYPE:
dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_DEVICE_TYPE,
   DEVICE_TYPE_RC);
+
+   ret = dra7xx_pcie_unaligned_memaccess(dev);
+   if (ret)
+   dev_err(dev, "WA for Errata i870 not applied\n");
+
ret = dra7xx_add_pcie_port(dra7xx, pdev);
if (ret < 0)
goto err_gpio;
@@ -715,7 +720,7 @@ static int __init dra7xx_pcie_probe(struct platform_device 
*pdev)
dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_DEVICE_TYPE,
   DEVICE_TYPE_EP);
 
-   ret = dra7xx_pcie_ep_unaligned_memaccess(dev);
+   ret = dra7xx_pcie_unaligned_memaccess(dev);
if (ret)
goto err_gpio;
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 60/73] coresight: etb10: Fix handling of perf mode

2018-10-31 Thread Sasha Levin
From: Suzuki K Poulose 

[ Upstream commit 987d1e8dcd370d96029a3d76a0031b043c4a69ae ]

If the ETB is already enabled in sysfs mode, the ETB reports
success even if a perf mode is requested. Fix this by checking
the requested mode.

Cc: Mathieu Poirier 
Signed-off-by: Suzuki K Poulose 
Signed-off-by: Mathieu Poirier 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/hwtracing/coresight/coresight-etb10.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etb10.c 
b/drivers/hwtracing/coresight/coresight-etb10.c
index 56ecd7aff5eb..d14a9cb7959a 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -155,6 +155,10 @@ static int etb_enable(struct coresight_device *csdev, u32 
mode)
if (val == CS_MODE_PERF)
return -EBUSY;
 
+   /* Don't let perf disturb sysFS sessions */
+   if (val == CS_MODE_SYSFS && mode == CS_MODE_PERF)
+   return -EBUSY;
+
/* Nothing to do, the tracer is already enabled. */
if (val == CS_MODE_SYSFS)
goto out;
-- 
2.17.1



[PATCH AUTOSEL 4.14 63/73] usb: chipidea: Prevent unbalanced IRQ disable

2018-10-31 Thread Sasha Levin
From: Loic Poulain 

[ Upstream commit 8b97d73c4d72a2abf58f8e49062a7ee1e5f1334e ]

The ChipIdea IRQ is disabled before scheduling the otg work and
re-enabled on otg work completion. However if the job is already
scheduled we have to undo the effect of disable_irq int order to
balance the IRQ disable-depth value.

Fixes: be6b0c1bd0be ("usb: chipidea: using one inline function to cover queue 
work operations")
Signed-off-by: Loic Poulain 
Signed-off-by: Peter Chen 
Signed-off-by: Sasha Levin 
---
 drivers/usb/chipidea/otg.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/otg.h b/drivers/usb/chipidea/otg.h
index 9ecb598e48f0..a5557c70034a 100644
--- a/drivers/usb/chipidea/otg.h
+++ b/drivers/usb/chipidea/otg.h
@@ -20,7 +20,8 @@ void ci_handle_vbus_change(struct ci_hdrc *ci);
 static inline void ci_otg_queue_work(struct ci_hdrc *ci)
 {
disable_irq_nosync(ci->irq);
-   queue_work(ci->wq, >work);
+   if (queue_work(ci->wq, >work) == false)
+   enable_irq(ci->irq);
 }
 
 #endif /* __DRIVERS_USB_CHIPIDEA_OTG_H */
-- 
2.17.1



[PATCH AUTOSEL 4.14 71/73] dmaengine: dma-jz4780: Return error if not probed from DT

2018-10-31 Thread Sasha Levin
From: Paul Cercueil 

[ Upstream commit 54f919a04cf221bc1601d1193682d4379dacacbd ]

The driver calls clk_get() with the clock name set to NULL, which means
that the driver could only work when probed from devicetree. From now
on, we explicitly require the driver to be probed from devicetree.

Signed-off-by: Paul Cercueil 
Tested-by: Mathieu Malaterre 
Signed-off-by: Vinod Koul 
Signed-off-by: Sasha Levin 
---
 drivers/dma/dma-jz4780.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c
index 7373b7a555ec..803cfb4523b0 100644
--- a/drivers/dma/dma-jz4780.c
+++ b/drivers/dma/dma-jz4780.c
@@ -754,6 +754,11 @@ static int jz4780_dma_probe(struct platform_device *pdev)
struct resource *res;
int i, ret;
 
+   if (!dev->of_node) {
+   dev_err(dev, "This driver must be probed from devicetree\n");
+   return -EINVAL;
+   }
+
jzdma = devm_kzalloc(dev, sizeof(*jzdma), GFP_KERNEL);
if (!jzdma)
return -ENOMEM;
-- 
2.17.1



[PATCH AUTOSEL 4.14 59/73] PCI/MSI: Warn and return error if driver enables MSI/MSI-X twice

2018-10-31 Thread Sasha Levin
From: Tonghao Zhang 

[ Upstream commit 4c1ef72e9b71a19fb405ebfcd37c0a5e16fa44ca ]

It is a serious driver defect to enable MSI or MSI-X more than once.  Doing
so may panic the kernel as in the stack trace below:

  Call Trace:
sysfs_add_one+0xa5/0xd0
create_dir+0x7c/0xe0
sysfs_create_subdir+0x1c/0x20
internal_create_group+0x6d/0x290
sysfs_create_groups+0x4a/0xa0
populate_msi_sysfs+0x1cd/0x210
pci_enable_msix+0x31c/0x3e0
igbuio_pci_open+0x72/0x300 [igb_uio]
uio_open+0xcc/0x120 [uio]
chrdev_open+0xa1/0x1e0
[...]
do_sys_open+0xf3/0x1f0
SyS_open+0x1e/0x20
system_call_fastpath+0x16/0x1b
---[ end trace 11042e2848880209 ]---
Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: 
a056b4fa

We want to keep the WARN_ON() and stack trace so the driver can be fixed,
but we can avoid the kernel panic by returning an error.  We may still get
warnings like this:

  Call Trace:
pci_enable_msix+0x3c9/0x3e0
igbuio_pci_open+0x72/0x300 [igb_uio]
uio_open+0xcc/0x120 [uio]
chrdev_open+0xa1/0x1e0
[...]
do_sys_open+0xf3/0x1f0
SyS_open+0x1e/0x20
system_call_fastpath+0x16/0x1b
[ cut here ]
WARNING: at fs/sysfs/dir.c:526 sysfs_add_one+0xa5/0xd0()
sysfs: cannot create duplicate filename 
'/devices/pci:00/:00:03.0/:01:00.1/msi_irqs'

Signed-off-by: Tonghao Zhang 
[bhelgaas: changelog, fix patch whitespace, remove !!]
Signed-off-by: Bjorn Helgaas 
Signed-off-by: Sasha Levin 
---
 drivers/pci/msi.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 496ed9130600..536e9a5cd2b1 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -958,7 +958,6 @@ static int __pci_enable_msix(struct pci_dev *dev, struct 
msix_entry *entries,
}
}
}
-   WARN_ON(!!dev->msix_enabled);
 
/* Check whether driver already requested for MSI irq */
if (dev->msi_enabled) {
@@ -1028,8 +1027,6 @@ static int __pci_enable_msi_range(struct pci_dev *dev, 
int minvec, int maxvec,
if (!pci_msi_supported(dev, minvec))
return -EINVAL;
 
-   WARN_ON(!!dev->msi_enabled);
-
/* Check whether driver already requested MSI-X irqs */
if (dev->msix_enabled) {
dev_info(>dev,
@@ -1040,6 +1037,9 @@ static int __pci_enable_msi_range(struct pci_dev *dev, 
int minvec, int maxvec,
if (maxvec < minvec)
return -ERANGE;
 
+   if (WARN_ON_ONCE(dev->msi_enabled))
+   return -EINVAL;
+
nvec = pci_msi_vec_count(dev);
if (nvec < 0)
return nvec;
@@ -1088,6 +1088,9 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
if (maxvec < minvec)
return -ERANGE;
 
+   if (WARN_ON_ONCE(dev->msix_enabled))
+   return -EINVAL;
+
for (;;) {
if (affd) {
nvec = irq_calc_affinity_vectors(minvec, nvec, affd);
-- 
2.17.1



[PATCH AUTOSEL 4.14 64/73] driver/dma/ioat: Call del_timer_sync() without holding prep_lock

2018-10-31 Thread Sasha Levin
From: Waiman Long 

[ Upstream commit cfb03be6c7e8a1591285849c361d67b09f5149f7 ]

The following lockdep splat was observed:

[ 1222.241750] ==
[ 1222.271301] WARNING: possible circular locking dependency detected
[ 1222.301060] 4.16.0-10.el8+5.x86_64+debug #1 Not tainted
[ 1222.326659] --
[ 1222.356565] systemd-shutdow/1 is trying to acquire lock:
[ 1222.382660]  ((_chan->timer)){+.-.}, at: [] 
del_timer_sync+0x5/0xf0
[ 1222.422928]
[ 1222.422928] but task is already holding lock:
[ 1222.451743]  (&(_chan->prep_lock)->rlock){+.-.}, at: 
[<8ea98b12>] ioat_shutdown+0x86/0x100 [ioatdma]
   :
[ 1223.524987] Chain exists of:
[ 1223.524987]   (_chan->timer) --> &(_chan->cleanup_lock)->rlock --> 
&(_chan->prep_lock)->rlock
[ 1223.524987]
[ 1223.594082]  Possible unsafe locking scenario:
[ 1223.594082]
[ 1223.622630]CPU0CPU1
[ 1223.645080]
[ 1223.667404]   lock(&(_chan->prep_lock)->rlock);
[ 1223.691535]
lock(&(_chan->cleanup_lock)->rlock);
[ 1223.728657]
lock(&(_chan->prep_lock)->rlock);
[ 1223.765122]   lock((_chan->timer));
[ 1223.784095]
[ 1223.784095]  *** DEADLOCK ***
[ 1223.784095]
[ 1223.813492] 4 locks held by systemd-shutdow/1:
[ 1223.834677]  #0:  (reboot_mutex){+.+.}, at: [<56d33456>] 
SYSC_reboot+0x10f/0x300
[ 1223.873310]  #1:  (>mutex){}, at: [<258dfdd7>] 
device_shutdown+0x1c8/0x660
[ 1223.913604]  #2:  (>mutex){}, at: [<68331147>] 
device_shutdown+0x1d6/0x660
[ 1223.954000]  #3:  (&(_chan->prep_lock)->rlock){+.-.}, at: 
[<8ea98b12>] ioat_shutdown+0x86/0x100 [ioatdma]

In the ioat_shutdown() function:

spin_lock_bh(_chan->prep_lock);
set_bit(IOAT_CHAN_DOWN, _chan->state);
del_timer_sync(_chan->timer);
spin_unlock_bh(_chan->prep_lock);

According to the synchronization rule for the del_timer_sync() function,
the caller must not hold locks which would prevent completion of the
timer's handler.

The timer structure has its own lock that manages its synchronization.
Setting the IOAT_CHAN_DOWN bit should prevent other CPUs from
trying to use that device anyway, there is probably no need to call
del_timer_sync() while holding the prep_lock. So the del_timer_sync()
call is now moved outside of the prep_lock critical section to prevent
the circular lock dependency.

Signed-off-by: Waiman Long 
Reviewed-by: Dave Jiang 
Signed-off-by: Vinod Koul 
Signed-off-by: Sasha Levin 
---
 drivers/dma/ioat/init.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/ioat/init.c b/drivers/dma/ioat/init.c
index 854deb0da07c..68680e4151ea 100644
--- a/drivers/dma/ioat/init.c
+++ b/drivers/dma/ioat/init.c
@@ -1205,8 +1205,15 @@ static void ioat_shutdown(struct pci_dev *pdev)
 
spin_lock_bh(_chan->prep_lock);
set_bit(IOAT_CHAN_DOWN, _chan->state);
-   del_timer_sync(_chan->timer);
spin_unlock_bh(_chan->prep_lock);
+   /*
+* Synchronization rule for del_timer_sync():
+*  - The caller must not hold locks which would prevent
+*completion of the timer's handler.
+* So prep_lock cannot be held before calling it.
+*/
+   del_timer_sync(_chan->timer);
+
/* this should quiesce then reset */
ioat_reset_hw(ioat_chan);
}
-- 
2.17.1



[PATCH AUTOSEL 4.14 68/73] f2fs: report error if quota off error during umount

2018-10-31 Thread Sasha Levin
From: Yunlei He 

[ Upstream commit cda9cc595f0bb6ffa51a4efc4b6533dfa4039b4c ]

Now, we depend on fsck to ensure quota file data is ok,
so we scan whole partition if checkpoint without umount
flag. It's same for quota off error case, which may make
quota file data inconsistent.

generic/019 reports below error:

 __quota_error: 1160 callbacks suppressed
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 VFS: Busy inodes after unmount of zram1. Self-destruct in 5 seconds.  Have a 
nice day...

If we failed in below path due to fail to write dquot block, we will miss
to release quota inode, fix it.

- f2fs_put_super
 - f2fs_quota_off_umount
  - f2fs_quota_off
   - f2fs_quota_sync   <-- failed
   - dquot_quota_off   <-- missed to call

Signed-off-by: Yunlei He 
Signed-off-by: Chao Yu 
Signed-off-by: Jaegeuk Kim 
Signed-off-by: Sasha Levin 
---
 fs/f2fs/super.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index eae35909fa51..7cda685296b2 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1488,7 +1488,9 @@ static int f2fs_quota_off(struct super_block *sb, int 
type)
if (!inode || !igrab(inode))
return dquot_quota_off(sb, type);
 
-   f2fs_quota_sync(sb, type);
+   err = f2fs_quota_sync(sb, type);
+   if (err)
+   goto out_put;
 
err = dquot_quota_off(sb, type);
if (err)
@@ -1507,9 +1509,20 @@ static int f2fs_quota_off(struct super_block *sb, int 
type)
 void f2fs_quota_off_umount(struct super_block *sb)
 {
int type;
+   int err;
 
-   for (type = 0; type < MAXQUOTAS; type++)
-   f2fs_quota_off(sb, type);
+   for (type = 0; type < MAXQUOTAS; type++) {
+   err = f2fs_quota_off(sb, type);
+   if (err) {
+   int ret = dquot_quota_off(sb, type);
+
+   f2fs_msg(sb, KERN_ERR,
+   "Fail to turn off disk quota "
+   "(type: %d, err: %d, ret:%d), Please "
+   "run fsck to fix it.", type, err, ret);
+   set_sbi_flag(F2FS_SB(sb), SBI_NEED_FSCK);
+   }
+   }
 }
 
 int f2fs_get_projid(struct inode *inode, kprojid_t *projid)
-- 
2.17.1



[PATCH AUTOSEL 4.14 66/73] scsi: lpfc: Correct soft lockup when running mds diagnostics

2018-10-31 Thread Sasha Levin
From: James Smart 

[ Upstream commit 0ef01a2d95fd62bb4f536e7ce4d5e8e74b97a244 ]

When running an mds diagnostic that passes frames with the switch, soft
lockups are detected. The driver is in a CQE processing loop and has
sufficient amount of traffic that it never exits the ring processing routine,
thus the "lockup".

Cap the number of elements in the work processing routine to 64 elements. This
ensures that the cpu will be given up and the handler reschedule to process
additional items.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/lpfc/lpfc_sli.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index dc83498024dc..24b6e56f6e97 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -3585,6 +3585,7 @@ lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
struct hbq_dmabuf *dmabuf;
struct lpfc_cq_event *cq_event;
unsigned long iflag;
+   int count = 0;
 
spin_lock_irqsave(>hbalock, iflag);
phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
@@ -3606,16 +3607,22 @@ lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba 
*phba,
if (irspiocbq)
lpfc_sli_sp_handle_rspiocb(phba, pring,
   irspiocbq);
+   count++;
break;
case CQE_CODE_RECEIVE:
case CQE_CODE_RECEIVE_V1:
dmabuf = container_of(cq_event, struct hbq_dmabuf,
  cq_event);
lpfc_sli4_handle_received_buffer(phba, dmabuf);
+   count++;
break;
default:
break;
}
+
+   /* Limit the number of events to 64 to avoid soft lockups */
+   if (count == 64)
+   break;
}
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 65/73] uio: ensure class is registered before devices

2018-10-31 Thread Sasha Levin
From: Alexandre Belloni 

[ Upstream commit ae61cf5b9913027c6953a79ed3894da4f47061bd ]

When both uio and the uio drivers are built in the kernel, it is possible
for a driver to register devices before the uio class is registered.

This may result in a NULL pointer dereference later on in
get_device_parent() when accessing the class glue_dirs spinlock.

The trace looks like that:

Unable to handle kernel NULL pointer dereference at virtual address 0140
[...]
[] _raw_spin_lock+0x14/0x48
[] device_add+0x154/0x6a0
[] device_create_groups_vargs+0x120/0x128
[] device_create+0x54/0x60
[] __uio_register_device+0x120/0x4a8
[] jaguar2_pci_probe+0x2d4/0x558
[] local_pci_probe+0x3c/0xb8
[] pci_device_probe+0x11c/0x180
[] driver_probe_device+0x22c/0x2d8
[] __driver_attach+0xbc/0xc0
[] bus_for_each_dev+0x4c/0x98
[] driver_attach+0x20/0x28
[] bus_add_driver+0x1b8/0x228
[] driver_register+0x60/0xf8
[] __pci_register_driver+0x40/0x48

Return EPROBE_DEFER in that case so the driver can register the device
later.

Signed-off-by: Alexandre Belloni 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/uio/uio.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 41784798c789..0a730136646d 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -249,6 +249,8 @@ static struct class uio_class = {
.dev_groups = uio_groups,
 };
 
+bool uio_class_registered;
+
 /*
  * device functions
  */
@@ -780,6 +782,9 @@ static int init_uio_class(void)
printk(KERN_ERR "class_register failed for uio\n");
goto err_class_register;
}
+
+   uio_class_registered = true;
+
return 0;
 
 err_class_register:
@@ -790,6 +795,7 @@ static int init_uio_class(void)
 
 static void release_uio_class(void)
 {
+   uio_class_registered = false;
class_unregister(_class);
uio_major_cleanup();
 }
@@ -809,6 +815,9 @@ int __uio_register_device(struct module *owner,
struct uio_device *idev;
int ret = 0;
 
+   if (!uio_class_registered)
+   return -EPROBE_DEFER;
+
if (!parent || !info || !info->name || !info->version)
return -EINVAL;
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 69/73] signal: Always deliver the kernel's SIGKILL and SIGSTOP to a pid namespace init

2018-10-31 Thread Sasha Levin
From: "Eric W. Biederman" 

[ Upstream commit 3597dfe01d12f570bc739da67f857fd222a3ea66 ]

Instead of playing whack-a-mole and changing SEND_SIG_PRIV to
SEND_SIG_FORCED throughout the kernel to ensure a pid namespace init
gets signals sent by the kernel, stop allowing a pid namespace init to
ignore SIGKILL or SIGSTOP sent by the kernel.  A pid namespace init is
only supposed to be able to ignore signals sent from itself and
children with SIG_DFL.

Fixes: 921cf9f63089 ("signals: protect cinit from unblocked SIG_DFL signals")
Reviewed-by: Thomas Gleixner 
Signed-off-by: "Eric W. Biederman" 
Signed-off-by: Sasha Levin 
---
 kernel/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index b74acbec9876..7181215e9b64 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1003,7 +1003,7 @@ static int __send_signal(int sig, struct siginfo *info, 
struct task_struct *t,
 
result = TRACE_SIGNAL_IGNORED;
if (!prepare_signal(sig, t,
-   from_ancestor_ns || (info == SEND_SIG_FORCED)))
+   from_ancestor_ns || (info == SEND_SIG_PRIV) || (info == 
SEND_SIG_FORCED)))
goto ret;
 
pending = group ? >signal->shared_pending : >pending;
-- 
2.17.1



[PATCH AUTOSEL 4.14 60/73] coresight: etb10: Fix handling of perf mode

2018-10-31 Thread Sasha Levin
From: Suzuki K Poulose 

[ Upstream commit 987d1e8dcd370d96029a3d76a0031b043c4a69ae ]

If the ETB is already enabled in sysfs mode, the ETB reports
success even if a perf mode is requested. Fix this by checking
the requested mode.

Cc: Mathieu Poirier 
Signed-off-by: Suzuki K Poulose 
Signed-off-by: Mathieu Poirier 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/hwtracing/coresight/coresight-etb10.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etb10.c 
b/drivers/hwtracing/coresight/coresight-etb10.c
index 56ecd7aff5eb..d14a9cb7959a 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -155,6 +155,10 @@ static int etb_enable(struct coresight_device *csdev, u32 
mode)
if (val == CS_MODE_PERF)
return -EBUSY;
 
+   /* Don't let perf disturb sysFS sessions */
+   if (val == CS_MODE_SYSFS && mode == CS_MODE_PERF)
+   return -EBUSY;
+
/* Nothing to do, the tracer is already enabled. */
if (val == CS_MODE_SYSFS)
goto out;
-- 
2.17.1



[PATCH AUTOSEL 4.14 63/73] usb: chipidea: Prevent unbalanced IRQ disable

2018-10-31 Thread Sasha Levin
From: Loic Poulain 

[ Upstream commit 8b97d73c4d72a2abf58f8e49062a7ee1e5f1334e ]

The ChipIdea IRQ is disabled before scheduling the otg work and
re-enabled on otg work completion. However if the job is already
scheduled we have to undo the effect of disable_irq int order to
balance the IRQ disable-depth value.

Fixes: be6b0c1bd0be ("usb: chipidea: using one inline function to cover queue 
work operations")
Signed-off-by: Loic Poulain 
Signed-off-by: Peter Chen 
Signed-off-by: Sasha Levin 
---
 drivers/usb/chipidea/otg.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/otg.h b/drivers/usb/chipidea/otg.h
index 9ecb598e48f0..a5557c70034a 100644
--- a/drivers/usb/chipidea/otg.h
+++ b/drivers/usb/chipidea/otg.h
@@ -20,7 +20,8 @@ void ci_handle_vbus_change(struct ci_hdrc *ci);
 static inline void ci_otg_queue_work(struct ci_hdrc *ci)
 {
disable_irq_nosync(ci->irq);
-   queue_work(ci->wq, >work);
+   if (queue_work(ci->wq, >work) == false)
+   enable_irq(ci->irq);
 }
 
 #endif /* __DRIVERS_USB_CHIPIDEA_OTG_H */
-- 
2.17.1



[PATCH AUTOSEL 4.14 71/73] dmaengine: dma-jz4780: Return error if not probed from DT

2018-10-31 Thread Sasha Levin
From: Paul Cercueil 

[ Upstream commit 54f919a04cf221bc1601d1193682d4379dacacbd ]

The driver calls clk_get() with the clock name set to NULL, which means
that the driver could only work when probed from devicetree. From now
on, we explicitly require the driver to be probed from devicetree.

Signed-off-by: Paul Cercueil 
Tested-by: Mathieu Malaterre 
Signed-off-by: Vinod Koul 
Signed-off-by: Sasha Levin 
---
 drivers/dma/dma-jz4780.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c
index 7373b7a555ec..803cfb4523b0 100644
--- a/drivers/dma/dma-jz4780.c
+++ b/drivers/dma/dma-jz4780.c
@@ -754,6 +754,11 @@ static int jz4780_dma_probe(struct platform_device *pdev)
struct resource *res;
int i, ret;
 
+   if (!dev->of_node) {
+   dev_err(dev, "This driver must be probed from devicetree\n");
+   return -EINVAL;
+   }
+
jzdma = devm_kzalloc(dev, sizeof(*jzdma), GFP_KERNEL);
if (!jzdma)
return -ENOMEM;
-- 
2.17.1



[PATCH AUTOSEL 4.14 59/73] PCI/MSI: Warn and return error if driver enables MSI/MSI-X twice

2018-10-31 Thread Sasha Levin
From: Tonghao Zhang 

[ Upstream commit 4c1ef72e9b71a19fb405ebfcd37c0a5e16fa44ca ]

It is a serious driver defect to enable MSI or MSI-X more than once.  Doing
so may panic the kernel as in the stack trace below:

  Call Trace:
sysfs_add_one+0xa5/0xd0
create_dir+0x7c/0xe0
sysfs_create_subdir+0x1c/0x20
internal_create_group+0x6d/0x290
sysfs_create_groups+0x4a/0xa0
populate_msi_sysfs+0x1cd/0x210
pci_enable_msix+0x31c/0x3e0
igbuio_pci_open+0x72/0x300 [igb_uio]
uio_open+0xcc/0x120 [uio]
chrdev_open+0xa1/0x1e0
[...]
do_sys_open+0xf3/0x1f0
SyS_open+0x1e/0x20
system_call_fastpath+0x16/0x1b
---[ end trace 11042e2848880209 ]---
Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: 
a056b4fa

We want to keep the WARN_ON() and stack trace so the driver can be fixed,
but we can avoid the kernel panic by returning an error.  We may still get
warnings like this:

  Call Trace:
pci_enable_msix+0x3c9/0x3e0
igbuio_pci_open+0x72/0x300 [igb_uio]
uio_open+0xcc/0x120 [uio]
chrdev_open+0xa1/0x1e0
[...]
do_sys_open+0xf3/0x1f0
SyS_open+0x1e/0x20
system_call_fastpath+0x16/0x1b
[ cut here ]
WARNING: at fs/sysfs/dir.c:526 sysfs_add_one+0xa5/0xd0()
sysfs: cannot create duplicate filename 
'/devices/pci:00/:00:03.0/:01:00.1/msi_irqs'

Signed-off-by: Tonghao Zhang 
[bhelgaas: changelog, fix patch whitespace, remove !!]
Signed-off-by: Bjorn Helgaas 
Signed-off-by: Sasha Levin 
---
 drivers/pci/msi.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 496ed9130600..536e9a5cd2b1 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -958,7 +958,6 @@ static int __pci_enable_msix(struct pci_dev *dev, struct 
msix_entry *entries,
}
}
}
-   WARN_ON(!!dev->msix_enabled);
 
/* Check whether driver already requested for MSI irq */
if (dev->msi_enabled) {
@@ -1028,8 +1027,6 @@ static int __pci_enable_msi_range(struct pci_dev *dev, 
int minvec, int maxvec,
if (!pci_msi_supported(dev, minvec))
return -EINVAL;
 
-   WARN_ON(!!dev->msi_enabled);
-
/* Check whether driver already requested MSI-X irqs */
if (dev->msix_enabled) {
dev_info(>dev,
@@ -1040,6 +1037,9 @@ static int __pci_enable_msi_range(struct pci_dev *dev, 
int minvec, int maxvec,
if (maxvec < minvec)
return -ERANGE;
 
+   if (WARN_ON_ONCE(dev->msi_enabled))
+   return -EINVAL;
+
nvec = pci_msi_vec_count(dev);
if (nvec < 0)
return nvec;
@@ -1088,6 +1088,9 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
if (maxvec < minvec)
return -ERANGE;
 
+   if (WARN_ON_ONCE(dev->msix_enabled))
+   return -EINVAL;
+
for (;;) {
if (affd) {
nvec = irq_calc_affinity_vectors(minvec, nvec, affd);
-- 
2.17.1



[PATCH AUTOSEL 4.14 64/73] driver/dma/ioat: Call del_timer_sync() without holding prep_lock

2018-10-31 Thread Sasha Levin
From: Waiman Long 

[ Upstream commit cfb03be6c7e8a1591285849c361d67b09f5149f7 ]

The following lockdep splat was observed:

[ 1222.241750] ==
[ 1222.271301] WARNING: possible circular locking dependency detected
[ 1222.301060] 4.16.0-10.el8+5.x86_64+debug #1 Not tainted
[ 1222.326659] --
[ 1222.356565] systemd-shutdow/1 is trying to acquire lock:
[ 1222.382660]  ((_chan->timer)){+.-.}, at: [] 
del_timer_sync+0x5/0xf0
[ 1222.422928]
[ 1222.422928] but task is already holding lock:
[ 1222.451743]  (&(_chan->prep_lock)->rlock){+.-.}, at: 
[<8ea98b12>] ioat_shutdown+0x86/0x100 [ioatdma]
   :
[ 1223.524987] Chain exists of:
[ 1223.524987]   (_chan->timer) --> &(_chan->cleanup_lock)->rlock --> 
&(_chan->prep_lock)->rlock
[ 1223.524987]
[ 1223.594082]  Possible unsafe locking scenario:
[ 1223.594082]
[ 1223.622630]CPU0CPU1
[ 1223.645080]
[ 1223.667404]   lock(&(_chan->prep_lock)->rlock);
[ 1223.691535]
lock(&(_chan->cleanup_lock)->rlock);
[ 1223.728657]
lock(&(_chan->prep_lock)->rlock);
[ 1223.765122]   lock((_chan->timer));
[ 1223.784095]
[ 1223.784095]  *** DEADLOCK ***
[ 1223.784095]
[ 1223.813492] 4 locks held by systemd-shutdow/1:
[ 1223.834677]  #0:  (reboot_mutex){+.+.}, at: [<56d33456>] 
SYSC_reboot+0x10f/0x300
[ 1223.873310]  #1:  (>mutex){}, at: [<258dfdd7>] 
device_shutdown+0x1c8/0x660
[ 1223.913604]  #2:  (>mutex){}, at: [<68331147>] 
device_shutdown+0x1d6/0x660
[ 1223.954000]  #3:  (&(_chan->prep_lock)->rlock){+.-.}, at: 
[<8ea98b12>] ioat_shutdown+0x86/0x100 [ioatdma]

In the ioat_shutdown() function:

spin_lock_bh(_chan->prep_lock);
set_bit(IOAT_CHAN_DOWN, _chan->state);
del_timer_sync(_chan->timer);
spin_unlock_bh(_chan->prep_lock);

According to the synchronization rule for the del_timer_sync() function,
the caller must not hold locks which would prevent completion of the
timer's handler.

The timer structure has its own lock that manages its synchronization.
Setting the IOAT_CHAN_DOWN bit should prevent other CPUs from
trying to use that device anyway, there is probably no need to call
del_timer_sync() while holding the prep_lock. So the del_timer_sync()
call is now moved outside of the prep_lock critical section to prevent
the circular lock dependency.

Signed-off-by: Waiman Long 
Reviewed-by: Dave Jiang 
Signed-off-by: Vinod Koul 
Signed-off-by: Sasha Levin 
---
 drivers/dma/ioat/init.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/ioat/init.c b/drivers/dma/ioat/init.c
index 854deb0da07c..68680e4151ea 100644
--- a/drivers/dma/ioat/init.c
+++ b/drivers/dma/ioat/init.c
@@ -1205,8 +1205,15 @@ static void ioat_shutdown(struct pci_dev *pdev)
 
spin_lock_bh(_chan->prep_lock);
set_bit(IOAT_CHAN_DOWN, _chan->state);
-   del_timer_sync(_chan->timer);
spin_unlock_bh(_chan->prep_lock);
+   /*
+* Synchronization rule for del_timer_sync():
+*  - The caller must not hold locks which would prevent
+*completion of the timer's handler.
+* So prep_lock cannot be held before calling it.
+*/
+   del_timer_sync(_chan->timer);
+
/* this should quiesce then reset */
ioat_reset_hw(ioat_chan);
}
-- 
2.17.1



[PATCH AUTOSEL 4.14 68/73] f2fs: report error if quota off error during umount

2018-10-31 Thread Sasha Levin
From: Yunlei He 

[ Upstream commit cda9cc595f0bb6ffa51a4efc4b6533dfa4039b4c ]

Now, we depend on fsck to ensure quota file data is ok,
so we scan whole partition if checkpoint without umount
flag. It's same for quota off error case, which may make
quota file data inconsistent.

generic/019 reports below error:

 __quota_error: 1160 callbacks suppressed
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 Quota error (device zram1): write_blk: dquota write failed
 Quota error (device zram1): qtree_write_dquot: Error -28 occurred while 
creating quota
 VFS: Busy inodes after unmount of zram1. Self-destruct in 5 seconds.  Have a 
nice day...

If we failed in below path due to fail to write dquot block, we will miss
to release quota inode, fix it.

- f2fs_put_super
 - f2fs_quota_off_umount
  - f2fs_quota_off
   - f2fs_quota_sync   <-- failed
   - dquot_quota_off   <-- missed to call

Signed-off-by: Yunlei He 
Signed-off-by: Chao Yu 
Signed-off-by: Jaegeuk Kim 
Signed-off-by: Sasha Levin 
---
 fs/f2fs/super.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index eae35909fa51..7cda685296b2 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1488,7 +1488,9 @@ static int f2fs_quota_off(struct super_block *sb, int 
type)
if (!inode || !igrab(inode))
return dquot_quota_off(sb, type);
 
-   f2fs_quota_sync(sb, type);
+   err = f2fs_quota_sync(sb, type);
+   if (err)
+   goto out_put;
 
err = dquot_quota_off(sb, type);
if (err)
@@ -1507,9 +1509,20 @@ static int f2fs_quota_off(struct super_block *sb, int 
type)
 void f2fs_quota_off_umount(struct super_block *sb)
 {
int type;
+   int err;
 
-   for (type = 0; type < MAXQUOTAS; type++)
-   f2fs_quota_off(sb, type);
+   for (type = 0; type < MAXQUOTAS; type++) {
+   err = f2fs_quota_off(sb, type);
+   if (err) {
+   int ret = dquot_quota_off(sb, type);
+
+   f2fs_msg(sb, KERN_ERR,
+   "Fail to turn off disk quota "
+   "(type: %d, err: %d, ret:%d), Please "
+   "run fsck to fix it.", type, err, ret);
+   set_sbi_flag(F2FS_SB(sb), SBI_NEED_FSCK);
+   }
+   }
 }
 
 int f2fs_get_projid(struct inode *inode, kprojid_t *projid)
-- 
2.17.1



[PATCH AUTOSEL 4.14 66/73] scsi: lpfc: Correct soft lockup when running mds diagnostics

2018-10-31 Thread Sasha Levin
From: James Smart 

[ Upstream commit 0ef01a2d95fd62bb4f536e7ce4d5e8e74b97a244 ]

When running an mds diagnostic that passes frames with the switch, soft
lockups are detected. The driver is in a CQE processing loop and has
sufficient amount of traffic that it never exits the ring processing routine,
thus the "lockup".

Cap the number of elements in the work processing routine to 64 elements. This
ensures that the cpu will be given up and the handler reschedule to process
additional items.

Signed-off-by: Dick Kennedy 
Signed-off-by: James Smart 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/lpfc/lpfc_sli.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index dc83498024dc..24b6e56f6e97 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -3585,6 +3585,7 @@ lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
struct hbq_dmabuf *dmabuf;
struct lpfc_cq_event *cq_event;
unsigned long iflag;
+   int count = 0;
 
spin_lock_irqsave(>hbalock, iflag);
phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
@@ -3606,16 +3607,22 @@ lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba 
*phba,
if (irspiocbq)
lpfc_sli_sp_handle_rspiocb(phba, pring,
   irspiocbq);
+   count++;
break;
case CQE_CODE_RECEIVE:
case CQE_CODE_RECEIVE_V1:
dmabuf = container_of(cq_event, struct hbq_dmabuf,
  cq_event);
lpfc_sli4_handle_received_buffer(phba, dmabuf);
+   count++;
break;
default:
break;
}
+
+   /* Limit the number of events to 64 to avoid soft lockups */
+   if (count == 64)
+   break;
}
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 65/73] uio: ensure class is registered before devices

2018-10-31 Thread Sasha Levin
From: Alexandre Belloni 

[ Upstream commit ae61cf5b9913027c6953a79ed3894da4f47061bd ]

When both uio and the uio drivers are built in the kernel, it is possible
for a driver to register devices before the uio class is registered.

This may result in a NULL pointer dereference later on in
get_device_parent() when accessing the class glue_dirs spinlock.

The trace looks like that:

Unable to handle kernel NULL pointer dereference at virtual address 0140
[...]
[] _raw_spin_lock+0x14/0x48
[] device_add+0x154/0x6a0
[] device_create_groups_vargs+0x120/0x128
[] device_create+0x54/0x60
[] __uio_register_device+0x120/0x4a8
[] jaguar2_pci_probe+0x2d4/0x558
[] local_pci_probe+0x3c/0xb8
[] pci_device_probe+0x11c/0x180
[] driver_probe_device+0x22c/0x2d8
[] __driver_attach+0xbc/0xc0
[] bus_for_each_dev+0x4c/0x98
[] driver_attach+0x20/0x28
[] bus_add_driver+0x1b8/0x228
[] driver_register+0x60/0xf8
[] __pci_register_driver+0x40/0x48

Return EPROBE_DEFER in that case so the driver can register the device
later.

Signed-off-by: Alexandre Belloni 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/uio/uio.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 41784798c789..0a730136646d 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -249,6 +249,8 @@ static struct class uio_class = {
.dev_groups = uio_groups,
 };
 
+bool uio_class_registered;
+
 /*
  * device functions
  */
@@ -780,6 +782,9 @@ static int init_uio_class(void)
printk(KERN_ERR "class_register failed for uio\n");
goto err_class_register;
}
+
+   uio_class_registered = true;
+
return 0;
 
 err_class_register:
@@ -790,6 +795,7 @@ static int init_uio_class(void)
 
 static void release_uio_class(void)
 {
+   uio_class_registered = false;
class_unregister(_class);
uio_major_cleanup();
 }
@@ -809,6 +815,9 @@ int __uio_register_device(struct module *owner,
struct uio_device *idev;
int ret = 0;
 
+   if (!uio_class_registered)
+   return -EPROBE_DEFER;
+
if (!parent || !info || !info->name || !info->version)
return -EINVAL;
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 69/73] signal: Always deliver the kernel's SIGKILL and SIGSTOP to a pid namespace init

2018-10-31 Thread Sasha Levin
From: "Eric W. Biederman" 

[ Upstream commit 3597dfe01d12f570bc739da67f857fd222a3ea66 ]

Instead of playing whack-a-mole and changing SEND_SIG_PRIV to
SEND_SIG_FORCED throughout the kernel to ensure a pid namespace init
gets signals sent by the kernel, stop allowing a pid namespace init to
ignore SIGKILL or SIGSTOP sent by the kernel.  A pid namespace init is
only supposed to be able to ignore signals sent from itself and
children with SIG_DFL.

Fixes: 921cf9f63089 ("signals: protect cinit from unblocked SIG_DFL signals")
Reviewed-by: Thomas Gleixner 
Signed-off-by: "Eric W. Biederman" 
Signed-off-by: Sasha Levin 
---
 kernel/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index b74acbec9876..7181215e9b64 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1003,7 +1003,7 @@ static int __send_signal(int sig, struct siginfo *info, 
struct task_struct *t,
 
result = TRACE_SIGNAL_IGNORED;
if (!prepare_signal(sig, t,
-   from_ancestor_ns || (info == SEND_SIG_FORCED)))
+   from_ancestor_ns || (info == SEND_SIG_PRIV) || (info == 
SEND_SIG_FORCED)))
goto ret;
 
pending = group ? >signal->shared_pending : >pending;
-- 
2.17.1



[PATCH AUTOSEL 4.9 09/48] perf tools: Cleanup trace-event-info 'tdata' leak

2018-10-31 Thread Sasha Levin
From: Sanskriti Sharma 

[ Upstream commit faedbf3fd19f2511a39397f76359e4cc6ee93072 ]

Free tracing_data structure in tracing_data_get() error paths.

Fixes the following coverity complaint:

  Error: RESOURCE_LEAK (CWE-772):
  leaked_storage: Variable "tdata" going out of scope leaks the storage

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-3-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/trace-event-info.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/trace-event-info.c 
b/tools/perf/util/trace-event-info.c
index d995743cb673..58ce62088a39 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -507,12 +507,14 @@ struct tracing_data *tracing_data_get(struct list_head 
*pattrs,
 "/tmp/perf-XX");
if (!mkstemp(tdata->temp_file)) {
pr_debug("Can't make temp file");
+   free(tdata);
return NULL;
}
 
temp_fd = open(tdata->temp_file, O_RDWR);
if (temp_fd < 0) {
pr_debug("Can't read '%s'", tdata->temp_file);
+   free(tdata);
return NULL;
}
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 05/48] tun: Consistently configure generic netdev params via rtnetlink

2018-10-31 Thread Sasha Levin
From: Serhey Popovych 

[ Upstream commit df52eab23d703142c766ac00bdb8db19d71238d0 ]

Configuring generic network device parameters on tun will fail in
presence of IFLA_INFO_KIND attribute in IFLA_LINKINFO nested attribute
since tun_validate() always return failure.

This can be visualized with following ip-link(8) command sequences:

  # ip link set dev tun0 group 100
  # ip link set dev tun0 group 100 type tun
  RTNETLINK answers: Invalid argument

with contrast to dummy and veth drivers:

  # ip link set dev dummy0 group 100
  # ip link set dev dummy0 type dummy

  # ip link set dev veth0 group 100
  # ip link set dev veth0 group 100 type veth

Fix by returning zero in tun_validate() when @data is NULL that is
always in case since rtnl_link_ops->maxtype is zero in tun driver.

Fixes: f019a7a594d9 ("tun: Implement ip link del tunXXX")
Signed-off-by: Serhey Popovych 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/tun.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index eb6dc28e5e52..0260bc15bc0c 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1570,6 +1570,8 @@ static void tun_setup(struct net_device *dev)
  */
 static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
 {
+   if (!data)
+   return 0;
return -EINVAL;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 09/48] perf tools: Cleanup trace-event-info 'tdata' leak

2018-10-31 Thread Sasha Levin
From: Sanskriti Sharma 

[ Upstream commit faedbf3fd19f2511a39397f76359e4cc6ee93072 ]

Free tracing_data structure in tracing_data_get() error paths.

Fixes the following coverity complaint:

  Error: RESOURCE_LEAK (CWE-772):
  leaked_storage: Variable "tdata" going out of scope leaks the storage

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-3-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/trace-event-info.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/trace-event-info.c 
b/tools/perf/util/trace-event-info.c
index d995743cb673..58ce62088a39 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -507,12 +507,14 @@ struct tracing_data *tracing_data_get(struct list_head 
*pattrs,
 "/tmp/perf-XX");
if (!mkstemp(tdata->temp_file)) {
pr_debug("Can't make temp file");
+   free(tdata);
return NULL;
}
 
temp_fd = open(tdata->temp_file, O_RDWR);
if (temp_fd < 0) {
pr_debug("Can't read '%s'", tdata->temp_file);
+   free(tdata);
return NULL;
}
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 05/48] tun: Consistently configure generic netdev params via rtnetlink

2018-10-31 Thread Sasha Levin
From: Serhey Popovych 

[ Upstream commit df52eab23d703142c766ac00bdb8db19d71238d0 ]

Configuring generic network device parameters on tun will fail in
presence of IFLA_INFO_KIND attribute in IFLA_LINKINFO nested attribute
since tun_validate() always return failure.

This can be visualized with following ip-link(8) command sequences:

  # ip link set dev tun0 group 100
  # ip link set dev tun0 group 100 type tun
  RTNETLINK answers: Invalid argument

with contrast to dummy and veth drivers:

  # ip link set dev dummy0 group 100
  # ip link set dev dummy0 type dummy

  # ip link set dev veth0 group 100
  # ip link set dev veth0 group 100 type veth

Fix by returning zero in tun_validate() when @data is NULL that is
always in case since rtnl_link_ops->maxtype is zero in tun driver.

Fixes: f019a7a594d9 ("tun: Implement ip link del tunXXX")
Signed-off-by: Serhey Popovych 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/tun.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index eb6dc28e5e52..0260bc15bc0c 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1570,6 +1570,8 @@ static void tun_setup(struct net_device *dev)
  */
 static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
 {
+   if (!data)
+   return 0;
return -EINVAL;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 72/73] IB/rxe: fix for duplicate request processing and ack psns

2018-10-31 Thread Sasha Levin
From: Vijay Immanuel 

[ Upstream commit b97db58557f4aa6d9903f8e1deea6b3d1ed0ba43 ]

Don't reset the resp opcode for a replayed read response.
The resp opcode could be in the middle of a write or send
sequence, when the duplicate read request was received.
An example sequence is as follows:
- Receive read request for 12KB PSN 20. Transmit read response
  first, middle and last with PSNs 20,21,22.
- Receive write first PSN 23.
  At this point the resp psn is 24 and resp opcode is write first.
- The sender notices that PSN 20 is dropped and retransmits.
  Receive read request for 12KB PSN 20. Transmit read response
  first, middle and last with PSNs 20,21,22. The resp opcode is
  set to -1, the resp psn remains 24.
- Receive write first PSN 23. This is processed by duplicate_request().
  The resp opcode remains -1 and resp psn remains 24.
- Receive write middle PSN 24. check_op_seq() reports a missing
  first error since the resp opcode is -1.

When sending an ack for a duplicate send or write request,
use the psn of the previous ack sent. Do not use the psn
of a read response for the ack.
An example sequence is as follows:
- Receive write PSN 30. Transmit ACK for PSN 30.
- Receive read request 4KB PSN 31. Transmit read response with
  PSN 31. The resp psn is now 32.
- The sender notices that PSN 30 is dropped and retransmits.
  Receive write PSN 30. duplicate_request() sends an ACK with
  PSN 31. That is incorrect since PSN 31 was a read request.

Signed-off-by: Vijay Immanuel 
Signed-off-by: Doug Ledford 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/sw/rxe/rxe_resp.c  | 8 ++--
 drivers/infiniband/sw/rxe/rxe_verbs.h | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c 
b/drivers/infiniband/sw/rxe/rxe_resp.c
index bd43c1c7a42f..4d84b010b3ee 100644
--- a/drivers/infiniband/sw/rxe/rxe_resp.c
+++ b/drivers/infiniband/sw/rxe/rxe_resp.c
@@ -683,6 +683,7 @@ static enum resp_states read_reply(struct rxe_qp *qp,
rxe_advance_resp_resource(qp);
 
res->type   = RXE_READ_MASK;
+   res->replay = 0;
 
res->read.va= qp->resp.va;
res->read.va_org= qp->resp.va;
@@ -753,7 +754,8 @@ static enum resp_states read_reply(struct rxe_qp *qp,
state = RESPST_DONE;
} else {
qp->resp.res = NULL;
-   qp->resp.opcode = -1;
+   if (!res->replay)
+   qp->resp.opcode = -1;
if (psn_compare(res->cur_psn, qp->resp.psn) >= 0)
qp->resp.psn = res->cur_psn;
state = RESPST_CLEANUP;
@@ -815,6 +817,7 @@ static enum resp_states execute(struct rxe_qp *qp, struct 
rxe_pkt_info *pkt)
 
/* next expected psn, read handles this separately */
qp->resp.psn = (pkt->psn + 1) & BTH_PSN_MASK;
+   qp->resp.ack_psn = qp->resp.psn;
 
qp->resp.opcode = pkt->opcode;
qp->resp.status = IB_WC_SUCCESS;
@@ -1071,7 +1074,7 @@ static enum resp_states duplicate_request(struct rxe_qp 
*qp,
  struct rxe_pkt_info *pkt)
 {
enum resp_states rc;
-   u32 prev_psn = (qp->resp.psn - 1) & BTH_PSN_MASK;
+   u32 prev_psn = (qp->resp.ack_psn - 1) & BTH_PSN_MASK;
 
if (pkt->mask & RXE_SEND_MASK ||
pkt->mask & RXE_WRITE_MASK) {
@@ -1114,6 +1117,7 @@ static enum resp_states duplicate_request(struct rxe_qp 
*qp,
res->state = (pkt->psn == res->first_psn) ?
rdatm_res_state_new :
rdatm_res_state_replay;
+   res->replay = 1;
 
/* Reset the resource, except length. */
res->read.va_org = iova;
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h 
b/drivers/infiniband/sw/rxe/rxe_verbs.h
index 1019f5e7dbdd..59f6a24db064 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.h
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.h
@@ -173,6 +173,7 @@ enum rdatm_res_state {
 
 struct resp_res {
int type;
+   int replay;
u32 first_psn;
u32 last_psn;
u32 cur_psn;
@@ -197,6 +198,7 @@ struct rxe_resp_info {
enum rxe_qp_state   state;
u32 msn;
u32 psn;
+   u32 ack_psn;
int opcode;
int drop_msg;
int goto_error;
-- 
2.17.1



[PATCH AUTOSEL 4.14 73/73] ALSA: hda: Check the non-cached stream buffers more explicitly

2018-10-31 Thread Sasha Levin
From: Takashi Iwai 

[ Upstream commit 78c9be61c3a5cd9e2439fd27a5ffad73a81958c7 ]

Introduce a new flag, uc_buffer, to indicate that the controller
requires the non-cached pages for stream buffers, either as a
chip-specific requirement or specified via snoop=0 option.
This improves the code-readability.

Also, this patch fixes the incorrect behavior for C-Media chip where
the stream buffers were never handled as non-cached due to the check
of driver_type even if you pass snoop=0 option.

Signed-off-by: Takashi Iwai 
Signed-off-by: Sasha Levin 
---
 sound/pci/hda/hda_controller.h |  1 +
 sound/pci/hda/hda_intel.c  | 11 ---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h
index a68e75b00ea3..53c3cd28bc99 100644
--- a/sound/pci/hda/hda_controller.h
+++ b/sound/pci/hda/hda_controller.h
@@ -160,6 +160,7 @@ struct azx {
unsigned int msi:1;
unsigned int probing:1; /* codec probing phase */
unsigned int snoop:1;
+   unsigned int uc_buffer:1; /* non-cached pages for stream buffers */
unsigned int align_buffer_size:1;
unsigned int region_requested:1;
unsigned int disabled:1; /* disabled by vga_switcheroo */
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 873d9824fbcf..4e38905bc47d 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -410,7 +410,7 @@ static void __mark_pages_wc(struct azx *chip, struct 
snd_dma_buffer *dmab, bool
 #ifdef CONFIG_SND_DMA_SGBUF
if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_SG) {
struct snd_sg_buf *sgbuf = dmab->private_data;
-   if (chip->driver_type == AZX_DRIVER_CMEDIA)
+   if (!chip->uc_buffer)
return; /* deal with only CORB/RIRB buffers */
if (on)
set_pages_array_wc(sgbuf->page_table, sgbuf->pages);
@@ -1634,6 +1634,7 @@ static void azx_check_snoop_available(struct azx *chip)
dev_info(chip->card->dev, "Force to %s mode by module option\n",
 snoop ? "snoop" : "non-snoop");
chip->snoop = snoop;
+   chip->uc_buffer = !snoop;
return;
}
 
@@ -1654,8 +1655,12 @@ static void azx_check_snoop_available(struct azx *chip)
snoop = false;
 
chip->snoop = snoop;
-   if (!snoop)
+   if (!snoop) {
dev_info(chip->card->dev, "Force to non-snoop mode\n");
+   /* C-Media requires non-cached pages only for CORB/RIRB */
+   if (chip->driver_type != AZX_DRIVER_CMEDIA)
+   chip->uc_buffer = true;
+   }
 }
 
 static void azx_probe_work(struct work_struct *work)
@@ -2094,7 +2099,7 @@ static void pcm_mmap_prepare(struct snd_pcm_substream 
*substream,
 #ifdef CONFIG_X86
struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
struct azx *chip = apcm->chip;
-   if (!azx_snoop(chip) && chip->driver_type != AZX_DRIVER_CMEDIA)
+   if (chip->uc_buffer)
area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
 #endif
 }
-- 
2.17.1



[PATCH AUTOSEL 4.14 72/73] IB/rxe: fix for duplicate request processing and ack psns

2018-10-31 Thread Sasha Levin
From: Vijay Immanuel 

[ Upstream commit b97db58557f4aa6d9903f8e1deea6b3d1ed0ba43 ]

Don't reset the resp opcode for a replayed read response.
The resp opcode could be in the middle of a write or send
sequence, when the duplicate read request was received.
An example sequence is as follows:
- Receive read request for 12KB PSN 20. Transmit read response
  first, middle and last with PSNs 20,21,22.
- Receive write first PSN 23.
  At this point the resp psn is 24 and resp opcode is write first.
- The sender notices that PSN 20 is dropped and retransmits.
  Receive read request for 12KB PSN 20. Transmit read response
  first, middle and last with PSNs 20,21,22. The resp opcode is
  set to -1, the resp psn remains 24.
- Receive write first PSN 23. This is processed by duplicate_request().
  The resp opcode remains -1 and resp psn remains 24.
- Receive write middle PSN 24. check_op_seq() reports a missing
  first error since the resp opcode is -1.

When sending an ack for a duplicate send or write request,
use the psn of the previous ack sent. Do not use the psn
of a read response for the ack.
An example sequence is as follows:
- Receive write PSN 30. Transmit ACK for PSN 30.
- Receive read request 4KB PSN 31. Transmit read response with
  PSN 31. The resp psn is now 32.
- The sender notices that PSN 30 is dropped and retransmits.
  Receive write PSN 30. duplicate_request() sends an ACK with
  PSN 31. That is incorrect since PSN 31 was a read request.

Signed-off-by: Vijay Immanuel 
Signed-off-by: Doug Ledford 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/sw/rxe/rxe_resp.c  | 8 ++--
 drivers/infiniband/sw/rxe/rxe_verbs.h | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c 
b/drivers/infiniband/sw/rxe/rxe_resp.c
index bd43c1c7a42f..4d84b010b3ee 100644
--- a/drivers/infiniband/sw/rxe/rxe_resp.c
+++ b/drivers/infiniband/sw/rxe/rxe_resp.c
@@ -683,6 +683,7 @@ static enum resp_states read_reply(struct rxe_qp *qp,
rxe_advance_resp_resource(qp);
 
res->type   = RXE_READ_MASK;
+   res->replay = 0;
 
res->read.va= qp->resp.va;
res->read.va_org= qp->resp.va;
@@ -753,7 +754,8 @@ static enum resp_states read_reply(struct rxe_qp *qp,
state = RESPST_DONE;
} else {
qp->resp.res = NULL;
-   qp->resp.opcode = -1;
+   if (!res->replay)
+   qp->resp.opcode = -1;
if (psn_compare(res->cur_psn, qp->resp.psn) >= 0)
qp->resp.psn = res->cur_psn;
state = RESPST_CLEANUP;
@@ -815,6 +817,7 @@ static enum resp_states execute(struct rxe_qp *qp, struct 
rxe_pkt_info *pkt)
 
/* next expected psn, read handles this separately */
qp->resp.psn = (pkt->psn + 1) & BTH_PSN_MASK;
+   qp->resp.ack_psn = qp->resp.psn;
 
qp->resp.opcode = pkt->opcode;
qp->resp.status = IB_WC_SUCCESS;
@@ -1071,7 +1074,7 @@ static enum resp_states duplicate_request(struct rxe_qp 
*qp,
  struct rxe_pkt_info *pkt)
 {
enum resp_states rc;
-   u32 prev_psn = (qp->resp.psn - 1) & BTH_PSN_MASK;
+   u32 prev_psn = (qp->resp.ack_psn - 1) & BTH_PSN_MASK;
 
if (pkt->mask & RXE_SEND_MASK ||
pkt->mask & RXE_WRITE_MASK) {
@@ -1114,6 +1117,7 @@ static enum resp_states duplicate_request(struct rxe_qp 
*qp,
res->state = (pkt->psn == res->first_psn) ?
rdatm_res_state_new :
rdatm_res_state_replay;
+   res->replay = 1;
 
/* Reset the resource, except length. */
res->read.va_org = iova;
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h 
b/drivers/infiniband/sw/rxe/rxe_verbs.h
index 1019f5e7dbdd..59f6a24db064 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.h
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.h
@@ -173,6 +173,7 @@ enum rdatm_res_state {
 
 struct resp_res {
int type;
+   int replay;
u32 first_psn;
u32 last_psn;
u32 cur_psn;
@@ -197,6 +198,7 @@ struct rxe_resp_info {
enum rxe_qp_state   state;
u32 msn;
u32 psn;
+   u32 ack_psn;
int opcode;
int drop_msg;
int goto_error;
-- 
2.17.1



[PATCH AUTOSEL 4.14 73/73] ALSA: hda: Check the non-cached stream buffers more explicitly

2018-10-31 Thread Sasha Levin
From: Takashi Iwai 

[ Upstream commit 78c9be61c3a5cd9e2439fd27a5ffad73a81958c7 ]

Introduce a new flag, uc_buffer, to indicate that the controller
requires the non-cached pages for stream buffers, either as a
chip-specific requirement or specified via snoop=0 option.
This improves the code-readability.

Also, this patch fixes the incorrect behavior for C-Media chip where
the stream buffers were never handled as non-cached due to the check
of driver_type even if you pass snoop=0 option.

Signed-off-by: Takashi Iwai 
Signed-off-by: Sasha Levin 
---
 sound/pci/hda/hda_controller.h |  1 +
 sound/pci/hda/hda_intel.c  | 11 ---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h
index a68e75b00ea3..53c3cd28bc99 100644
--- a/sound/pci/hda/hda_controller.h
+++ b/sound/pci/hda/hda_controller.h
@@ -160,6 +160,7 @@ struct azx {
unsigned int msi:1;
unsigned int probing:1; /* codec probing phase */
unsigned int snoop:1;
+   unsigned int uc_buffer:1; /* non-cached pages for stream buffers */
unsigned int align_buffer_size:1;
unsigned int region_requested:1;
unsigned int disabled:1; /* disabled by vga_switcheroo */
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 873d9824fbcf..4e38905bc47d 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -410,7 +410,7 @@ static void __mark_pages_wc(struct azx *chip, struct 
snd_dma_buffer *dmab, bool
 #ifdef CONFIG_SND_DMA_SGBUF
if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_SG) {
struct snd_sg_buf *sgbuf = dmab->private_data;
-   if (chip->driver_type == AZX_DRIVER_CMEDIA)
+   if (!chip->uc_buffer)
return; /* deal with only CORB/RIRB buffers */
if (on)
set_pages_array_wc(sgbuf->page_table, sgbuf->pages);
@@ -1634,6 +1634,7 @@ static void azx_check_snoop_available(struct azx *chip)
dev_info(chip->card->dev, "Force to %s mode by module option\n",
 snoop ? "snoop" : "non-snoop");
chip->snoop = snoop;
+   chip->uc_buffer = !snoop;
return;
}
 
@@ -1654,8 +1655,12 @@ static void azx_check_snoop_available(struct azx *chip)
snoop = false;
 
chip->snoop = snoop;
-   if (!snoop)
+   if (!snoop) {
dev_info(chip->card->dev, "Force to non-snoop mode\n");
+   /* C-Media requires non-cached pages only for CORB/RIRB */
+   if (chip->driver_type != AZX_DRIVER_CMEDIA)
+   chip->uc_buffer = true;
+   }
 }
 
 static void azx_probe_work(struct work_struct *work)
@@ -2094,7 +2099,7 @@ static void pcm_mmap_prepare(struct snd_pcm_substream 
*substream,
 #ifdef CONFIG_X86
struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
struct azx *chip = apcm->chip;
-   if (!azx_snoop(chip) && chip->driver_type != AZX_DRIVER_CMEDIA)
+   if (chip->uc_buffer)
area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
 #endif
 }
-- 
2.17.1



[PATCH AUTOSEL 4.9 04/48] swim: fix cleanup on setup error

2018-10-31 Thread Sasha Levin
From: Omar Sandoval 

[ Upstream commit 1448a2a5360ae06f25e2edc61ae070dff5c0beb4 ]

If we fail to allocate the request queue for a disk, we still need to
free that disk, not just the previous ones. Additionally, we need to
cleanup the previous request queues.

Signed-off-by: Omar Sandoval 
Signed-off-by: Jens Axboe 
Signed-off-by: Sasha Levin 
---
 drivers/block/swim.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index b5afd495d482..eec6e393c124 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -868,8 +868,17 @@ static int swim_floppy_init(struct swim_priv *swd)
 
 exit_put_disks:
unregister_blkdev(FLOPPY_MAJOR, "fd");
-   while (drive--)
-   put_disk(swd->unit[drive].disk);
+   do {
+   struct gendisk *disk = swd->unit[drive].disk;
+
+   if (disk) {
+   if (disk->queue) {
+   blk_cleanup_queue(disk->queue);
+   disk->queue = NULL;
+   }
+   put_disk(disk);
+   }
+   } while (drive--);
return err;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 03/48] ataflop: fix error handling during setup

2018-10-31 Thread Sasha Levin
From: Omar Sandoval 

[ Upstream commit 71327f547ee3a46ec5c39fdbbd268401b2578d0e ]

Move queue allocation next to disk allocation to fix a couple of issues:

- If add_disk() hasn't been called, we should clear disk->queue before
  calling put_disk().
- If we fail to allocate a request queue, we still need to put all of
  the disks, not just the ones that we allocated queues for.

Signed-off-by: Omar Sandoval 
Signed-off-by: Jens Axboe 
Signed-off-by: Sasha Levin 
---
 drivers/block/ataflop.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 2104b1b4ccda..9ab759bcebd5 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1933,6 +1933,11 @@ static int __init atari_floppy_init (void)
unit[i].disk = alloc_disk(1);
if (!unit[i].disk)
goto Enomem;
+
+   unit[i].disk->queue = blk_init_queue(do_fd_request,
+_lock);
+   if (!unit[i].disk->queue)
+   goto Enomem;
}
 
if (UseTrackbuffer < 0)
@@ -1964,10 +1969,6 @@ static int __init atari_floppy_init (void)
sprintf(unit[i].disk->disk_name, "fd%d", i);
unit[i].disk->fops = _fops;
unit[i].disk->private_data = [i];
-   unit[i].disk->queue = blk_init_queue(do_fd_request,
-   _lock);
-   if (!unit[i].disk->queue)
-   goto Enomem;
set_capacity(unit[i].disk, MAX_DISK_SIZE * 2);
add_disk(unit[i].disk);
}
@@ -1982,13 +1983,17 @@ static int __init atari_floppy_init (void)
 
return 0;
 Enomem:
-   while (i--) {
-   struct request_queue *q = unit[i].disk->queue;
+   do {
+   struct gendisk *disk = unit[i].disk;
 
-   put_disk(unit[i].disk);
-   if (q)
-   blk_cleanup_queue(q);
-   }
+   if (disk) {
+   if (disk->queue) {
+   blk_cleanup_queue(disk->queue);
+   disk->queue = NULL;
+   }
+   put_disk(unit[i].disk);
+   }
+   } while (i--);
 
unregister_blkdev(FLOPPY_MAJOR, "fd");
return -ENOMEM;
-- 
2.17.1



[PATCH AUTOSEL 4.9 06/48] s390/sthyi: Fix machine name validity indication

2018-10-31 Thread Sasha Levin
From: Janosch Frank 

[ Upstream commit b5130dc2224d1881f24224c0590c6d97f2168d6a ]

When running as a level 3 guest with no host provided sthyi support
sclp_ocf_cpc_name_copy() will only return zeroes. Zeroes are not a
valid group name, so let's not indicate that the group name field is
valid.

Also the group name is not dependent on stsi, let's not return based
on stsi before setting it.

Fixes: 95ca2cb57985 ("KVM: s390: Add sthyi emulation")
Signed-off-by: Janosch Frank 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Sasha Levin 
---
 arch/s390/kvm/sthyi.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/s390/kvm/sthyi.c b/arch/s390/kvm/sthyi.c
index 2f04ad1ea01c..029fd5e707b4 100644
--- a/arch/s390/kvm/sthyi.c
+++ b/arch/s390/kvm/sthyi.c
@@ -174,17 +174,19 @@ static void fill_hdr(struct sthyi_sctns *sctns)
 static void fill_stsi_mac(struct sthyi_sctns *sctns,
  struct sysinfo_1_1_1 *sysinfo)
 {
+   sclp_ocf_cpc_name_copy(sctns->mac.infmname);
+   if (*(u64 *)sctns->mac.infmname != 0)
+   sctns->mac.infmval1 |= MAC_NAME_VLD;
+
if (stsi(sysinfo, 1, 1, 1))
return;
 
-   sclp_ocf_cpc_name_copy(sctns->mac.infmname);
-
memcpy(sctns->mac.infmtype, sysinfo->type, sizeof(sctns->mac.infmtype));
memcpy(sctns->mac.infmmanu, sysinfo->manufacturer, 
sizeof(sctns->mac.infmmanu));
memcpy(sctns->mac.infmpman, sysinfo->plant, 
sizeof(sctns->mac.infmpman));
memcpy(sctns->mac.infmseq, sysinfo->sequence, 
sizeof(sctns->mac.infmseq));
 
-   sctns->mac.infmval1 |= MAC_ID_VLD | MAC_NAME_VLD;
+   sctns->mac.infmval1 |= MAC_ID_VLD;
 }
 
 static void fill_stsi_par(struct sthyi_sctns *sctns,
-- 
2.17.1



[PATCH AUTOSEL 4.9 04/48] swim: fix cleanup on setup error

2018-10-31 Thread Sasha Levin
From: Omar Sandoval 

[ Upstream commit 1448a2a5360ae06f25e2edc61ae070dff5c0beb4 ]

If we fail to allocate the request queue for a disk, we still need to
free that disk, not just the previous ones. Additionally, we need to
cleanup the previous request queues.

Signed-off-by: Omar Sandoval 
Signed-off-by: Jens Axboe 
Signed-off-by: Sasha Levin 
---
 drivers/block/swim.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index b5afd495d482..eec6e393c124 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -868,8 +868,17 @@ static int swim_floppy_init(struct swim_priv *swd)
 
 exit_put_disks:
unregister_blkdev(FLOPPY_MAJOR, "fd");
-   while (drive--)
-   put_disk(swd->unit[drive].disk);
+   do {
+   struct gendisk *disk = swd->unit[drive].disk;
+
+   if (disk) {
+   if (disk->queue) {
+   blk_cleanup_queue(disk->queue);
+   disk->queue = NULL;
+   }
+   put_disk(disk);
+   }
+   } while (drive--);
return err;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 03/48] ataflop: fix error handling during setup

2018-10-31 Thread Sasha Levin
From: Omar Sandoval 

[ Upstream commit 71327f547ee3a46ec5c39fdbbd268401b2578d0e ]

Move queue allocation next to disk allocation to fix a couple of issues:

- If add_disk() hasn't been called, we should clear disk->queue before
  calling put_disk().
- If we fail to allocate a request queue, we still need to put all of
  the disks, not just the ones that we allocated queues for.

Signed-off-by: Omar Sandoval 
Signed-off-by: Jens Axboe 
Signed-off-by: Sasha Levin 
---
 drivers/block/ataflop.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 2104b1b4ccda..9ab759bcebd5 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1933,6 +1933,11 @@ static int __init atari_floppy_init (void)
unit[i].disk = alloc_disk(1);
if (!unit[i].disk)
goto Enomem;
+
+   unit[i].disk->queue = blk_init_queue(do_fd_request,
+_lock);
+   if (!unit[i].disk->queue)
+   goto Enomem;
}
 
if (UseTrackbuffer < 0)
@@ -1964,10 +1969,6 @@ static int __init atari_floppy_init (void)
sprintf(unit[i].disk->disk_name, "fd%d", i);
unit[i].disk->fops = _fops;
unit[i].disk->private_data = [i];
-   unit[i].disk->queue = blk_init_queue(do_fd_request,
-   _lock);
-   if (!unit[i].disk->queue)
-   goto Enomem;
set_capacity(unit[i].disk, MAX_DISK_SIZE * 2);
add_disk(unit[i].disk);
}
@@ -1982,13 +1983,17 @@ static int __init atari_floppy_init (void)
 
return 0;
 Enomem:
-   while (i--) {
-   struct request_queue *q = unit[i].disk->queue;
+   do {
+   struct gendisk *disk = unit[i].disk;
 
-   put_disk(unit[i].disk);
-   if (q)
-   blk_cleanup_queue(q);
-   }
+   if (disk) {
+   if (disk->queue) {
+   blk_cleanup_queue(disk->queue);
+   disk->queue = NULL;
+   }
+   put_disk(unit[i].disk);
+   }
+   } while (i--);
 
unregister_blkdev(FLOPPY_MAJOR, "fd");
return -ENOMEM;
-- 
2.17.1



[PATCH AUTOSEL 4.9 06/48] s390/sthyi: Fix machine name validity indication

2018-10-31 Thread Sasha Levin
From: Janosch Frank 

[ Upstream commit b5130dc2224d1881f24224c0590c6d97f2168d6a ]

When running as a level 3 guest with no host provided sthyi support
sclp_ocf_cpc_name_copy() will only return zeroes. Zeroes are not a
valid group name, so let's not indicate that the group name field is
valid.

Also the group name is not dependent on stsi, let's not return based
on stsi before setting it.

Fixes: 95ca2cb57985 ("KVM: s390: Add sthyi emulation")
Signed-off-by: Janosch Frank 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Sasha Levin 
---
 arch/s390/kvm/sthyi.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/s390/kvm/sthyi.c b/arch/s390/kvm/sthyi.c
index 2f04ad1ea01c..029fd5e707b4 100644
--- a/arch/s390/kvm/sthyi.c
+++ b/arch/s390/kvm/sthyi.c
@@ -174,17 +174,19 @@ static void fill_hdr(struct sthyi_sctns *sctns)
 static void fill_stsi_mac(struct sthyi_sctns *sctns,
  struct sysinfo_1_1_1 *sysinfo)
 {
+   sclp_ocf_cpc_name_copy(sctns->mac.infmname);
+   if (*(u64 *)sctns->mac.infmname != 0)
+   sctns->mac.infmval1 |= MAC_NAME_VLD;
+
if (stsi(sysinfo, 1, 1, 1))
return;
 
-   sclp_ocf_cpc_name_copy(sctns->mac.infmname);
-
memcpy(sctns->mac.infmtype, sysinfo->type, sizeof(sctns->mac.infmtype));
memcpy(sctns->mac.infmmanu, sysinfo->manufacturer, 
sizeof(sctns->mac.infmmanu));
memcpy(sctns->mac.infmpman, sysinfo->plant, 
sizeof(sctns->mac.infmpman));
memcpy(sctns->mac.infmseq, sysinfo->sequence, 
sizeof(sctns->mac.infmseq));
 
-   sctns->mac.infmval1 |= MAC_ID_VLD | MAC_NAME_VLD;
+   sctns->mac.infmval1 |= MAC_ID_VLD;
 }
 
 static void fill_stsi_par(struct sthyi_sctns *sctns,
-- 
2.17.1



[PATCH AUTOSEL 4.9 07/48] hwmon: (pwm-fan) Set fan speed to 0 on suspend

2018-10-31 Thread Sasha Levin
From: Thierry Reding 

[ Upstream commit 95dcd64bc5a27080beaa344edfe5bdcca3d2e7dc ]

Technically this is not required because disabling the PWM should be
enough. However, when support for atomic operations was implemented in
the PWM subsystem, only actual changes to the PWM channel are applied
during pwm_config(), which means that during after resume from suspend
the old settings won't be applied.

One possible solution is for the PWM driver to implement its own PM
operations such that settings from before suspend get applied on resume.
This has the disadvantage of completely ignoring any particular ordering
requirements that PWM user drivers might have, so it is best to leave it
up to the user drivers to apply the settings that they want at the
appropriate time.

Another way to solve this would be to read back the current state of the
PWM at the time of resume. That way, in case the configuration was lost
during suspend, applying the old settings in PWM user drivers would
actually get them applied because they differ from the current settings.
However, not all PWM drivers support reading the hardware state, and not
all hardware may support it.

The best workaround at this point seems to be to let PWM user drivers
tell the PWM subsystem that the PWM is turned off by, in addition to
disabling it, also setting the duty cycle to 0. This causes the resume
operation to apply a configuration that is different from the current
configuration, resulting in the proper state from before suspend getting
restored.

Signed-off-by: Thierry Reding 
Signed-off-by: Guenter Roeck 
Signed-off-by: Sasha Levin 
---
 drivers/hwmon/pwm-fan.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index f9af3935b427..fb03449de2e0 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -306,9 +306,19 @@ static int pwm_fan_remove(struct platform_device *pdev)
 static int pwm_fan_suspend(struct device *dev)
 {
struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
+   struct pwm_args args;
+   int ret;
+
+   pwm_get_args(ctx->pwm, );
+
+   if (ctx->pwm_value) {
+   ret = pwm_config(ctx->pwm, 0, args.period);
+   if (ret < 0)
+   return ret;
 
-   if (ctx->pwm_value)
pwm_disable(ctx->pwm);
+   }
+
return 0;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 07/48] hwmon: (pwm-fan) Set fan speed to 0 on suspend

2018-10-31 Thread Sasha Levin
From: Thierry Reding 

[ Upstream commit 95dcd64bc5a27080beaa344edfe5bdcca3d2e7dc ]

Technically this is not required because disabling the PWM should be
enough. However, when support for atomic operations was implemented in
the PWM subsystem, only actual changes to the PWM channel are applied
during pwm_config(), which means that during after resume from suspend
the old settings won't be applied.

One possible solution is for the PWM driver to implement its own PM
operations such that settings from before suspend get applied on resume.
This has the disadvantage of completely ignoring any particular ordering
requirements that PWM user drivers might have, so it is best to leave it
up to the user drivers to apply the settings that they want at the
appropriate time.

Another way to solve this would be to read back the current state of the
PWM at the time of resume. That way, in case the configuration was lost
during suspend, applying the old settings in PWM user drivers would
actually get them applied because they differ from the current settings.
However, not all PWM drivers support reading the hardware state, and not
all hardware may support it.

The best workaround at this point seems to be to let PWM user drivers
tell the PWM subsystem that the PWM is turned off by, in addition to
disabling it, also setting the duty cycle to 0. This causes the resume
operation to apply a configuration that is different from the current
configuration, resulting in the proper state from before suspend getting
restored.

Signed-off-by: Thierry Reding 
Signed-off-by: Guenter Roeck 
Signed-off-by: Sasha Levin 
---
 drivers/hwmon/pwm-fan.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index f9af3935b427..fb03449de2e0 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -306,9 +306,19 @@ static int pwm_fan_remove(struct platform_device *pdev)
 static int pwm_fan_suspend(struct device *dev)
 {
struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
+   struct pwm_args args;
+   int ret;
+
+   pwm_get_args(ctx->pwm, );
+
+   if (ctx->pwm_value) {
+   ret = pwm_config(ctx->pwm, 0, args.period);
+   if (ret < 0)
+   return ret;
 
-   if (ctx->pwm_value)
pwm_disable(ctx->pwm);
+   }
+
return 0;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 08/48] perf tools: Free temporary 'sys' string in read_event_files()

2018-10-31 Thread Sasha Levin
From: Sanskriti Sharma 

[ Upstream commit 1e44224fb0528b4c0cc176bde2bb31e9127eb14b ]

For each system in a given pevent, read_event_files() reads in a
temporary 'sys' string.  Be sure to free this string before moving onto
to the next system and/or leaving read_event_files().

Fixes the following coverity complaints:

  Error: RESOURCE_LEAK (CWE-772):

  tools/perf/util/trace-event-read.c:343: overwrite_var: Overwriting
  "sys" in "sys = read_string()" leaks the storage that "sys" points to.

  tools/perf/util/trace-event-read.c:353: leaked_storage: Variable "sys"
  going out of scope leaks the storage it points to.

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-6-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/trace-event-read.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/trace-event-read.c 
b/tools/perf/util/trace-event-read.c
index b67a0ccf5ab9..23baee7b786a 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -334,9 +334,12 @@ static int read_event_files(struct pevent *pevent)
for (x=0; x < count; x++) {
size = read8(pevent);
ret = read_event_file(pevent, sys, size);
-   if (ret)
+   if (ret) {
+   free(sys);
return ret;
+   }
}
+   free(sys);
}
return 0;
 }
-- 
2.17.1



[PATCH AUTOSEL 4.9 12/48] mmc: sdhci-pci-o2micro: Add quirk for O2 Micro dev 0x8620 rev 0x01

2018-10-31 Thread Sasha Levin
From: Yu Zhao 

[ Upstream commit 5169894982bb67486d93cc1e10151712bb86bcb6 ]

This device reports SDHCI_CLOCK_INT_STABLE even though it's not
ready to take SDHCI_CLOCK_CARD_EN. The symptom is that reading
SDHCI_CLOCK_CONTROL after enabling the clock shows absence of the
bit from the register (e.g. expecting 0xfa07 = 0xfa03 |
SDHCI_CLOCK_CARD_EN but only observed the first operand).

mmc1: Timeout waiting for hardware cmd interrupt.
mmc1: sdhci:  SDHCI REGISTER DUMP ===
mmc1: sdhci: Sys addr:  0x | Version:  0x0603
mmc1: sdhci: Blk size:  0x | Blk cnt:  0x
mmc1: sdhci: Argument:  0x | Trn mode: 0x
mmc1: sdhci: Present:   0x01ff0001 | Host ctl: 0x0001
mmc1: sdhci: Power: 0x000f | Blk gap:  0x
mmc1: sdhci: Wake-up:   0x | Clock:0xfa03
mmc1: sdhci: Timeout:   0x | Int stat: 0x
mmc1: sdhci: Int enab:  0x00ff0083 | Sig enab: 0x00ff0083
mmc1: sdhci: AC12 err:  0x | Slot int: 0x
mmc1: sdhci: Caps:  0x25fcc8bf | Caps_1:   0x2077
mmc1: sdhci: Cmd:   0x | Max curr: 0x005800c8
mmc1: sdhci: Resp[0]:   0x | Resp[1]:  0x
mmc1: sdhci: Resp[2]:   0x | Resp[3]:  0x
mmc1: sdhci: Host ctl2: 0x0008
mmc1: sdhci: ADMA Err:  0x | ADMA Ptr: 0x
mmc1: sdhci: 

The problem happens during wakeup from S3. Adding a delay quirk
after power up reliably fixes the problem.

Signed-off-by: Yu Zhao 
Signed-off-by: Ulf Hansson 
Signed-off-by: Sasha Levin 
---
 drivers/mmc/host/sdhci-pci-o2micro.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mmc/host/sdhci-pci-o2micro.c 
b/drivers/mmc/host/sdhci-pci-o2micro.c
index d48f03104b5b..e417e4274d66 100644
--- a/drivers/mmc/host/sdhci-pci-o2micro.c
+++ b/drivers/mmc/host/sdhci-pci-o2micro.c
@@ -334,6 +334,9 @@ int sdhci_pci_o2_probe(struct sdhci_pci_chip *chip)
pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
break;
case PCI_DEVICE_ID_O2_SEABIRD0:
+   if (chip->pdev->revision == 0x01)
+   chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
+   /* fall through */
case PCI_DEVICE_ID_O2_SEABIRD1:
/* UnLock WP */
ret = pci_read_config_byte(chip->pdev,
-- 
2.17.1



[PATCH AUTOSEL 4.9 08/48] perf tools: Free temporary 'sys' string in read_event_files()

2018-10-31 Thread Sasha Levin
From: Sanskriti Sharma 

[ Upstream commit 1e44224fb0528b4c0cc176bde2bb31e9127eb14b ]

For each system in a given pevent, read_event_files() reads in a
temporary 'sys' string.  Be sure to free this string before moving onto
to the next system and/or leaving read_event_files().

Fixes the following coverity complaints:

  Error: RESOURCE_LEAK (CWE-772):

  tools/perf/util/trace-event-read.c:343: overwrite_var: Overwriting
  "sys" in "sys = read_string()" leaks the storage that "sys" points to.

  tools/perf/util/trace-event-read.c:353: leaked_storage: Variable "sys"
  going out of scope leaks the storage it points to.

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-6-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/trace-event-read.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/trace-event-read.c 
b/tools/perf/util/trace-event-read.c
index b67a0ccf5ab9..23baee7b786a 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -334,9 +334,12 @@ static int read_event_files(struct pevent *pevent)
for (x=0; x < count; x++) {
size = read8(pevent);
ret = read_event_file(pevent, sys, size);
-   if (ret)
+   if (ret) {
+   free(sys);
return ret;
+   }
}
+   free(sys);
}
return 0;
 }
-- 
2.17.1



[PATCH AUTOSEL 4.9 12/48] mmc: sdhci-pci-o2micro: Add quirk for O2 Micro dev 0x8620 rev 0x01

2018-10-31 Thread Sasha Levin
From: Yu Zhao 

[ Upstream commit 5169894982bb67486d93cc1e10151712bb86bcb6 ]

This device reports SDHCI_CLOCK_INT_STABLE even though it's not
ready to take SDHCI_CLOCK_CARD_EN. The symptom is that reading
SDHCI_CLOCK_CONTROL after enabling the clock shows absence of the
bit from the register (e.g. expecting 0xfa07 = 0xfa03 |
SDHCI_CLOCK_CARD_EN but only observed the first operand).

mmc1: Timeout waiting for hardware cmd interrupt.
mmc1: sdhci:  SDHCI REGISTER DUMP ===
mmc1: sdhci: Sys addr:  0x | Version:  0x0603
mmc1: sdhci: Blk size:  0x | Blk cnt:  0x
mmc1: sdhci: Argument:  0x | Trn mode: 0x
mmc1: sdhci: Present:   0x01ff0001 | Host ctl: 0x0001
mmc1: sdhci: Power: 0x000f | Blk gap:  0x
mmc1: sdhci: Wake-up:   0x | Clock:0xfa03
mmc1: sdhci: Timeout:   0x | Int stat: 0x
mmc1: sdhci: Int enab:  0x00ff0083 | Sig enab: 0x00ff0083
mmc1: sdhci: AC12 err:  0x | Slot int: 0x
mmc1: sdhci: Caps:  0x25fcc8bf | Caps_1:   0x2077
mmc1: sdhci: Cmd:   0x | Max curr: 0x005800c8
mmc1: sdhci: Resp[0]:   0x | Resp[1]:  0x
mmc1: sdhci: Resp[2]:   0x | Resp[3]:  0x
mmc1: sdhci: Host ctl2: 0x0008
mmc1: sdhci: ADMA Err:  0x | ADMA Ptr: 0x
mmc1: sdhci: 

The problem happens during wakeup from S3. Adding a delay quirk
after power up reliably fixes the problem.

Signed-off-by: Yu Zhao 
Signed-off-by: Ulf Hansson 
Signed-off-by: Sasha Levin 
---
 drivers/mmc/host/sdhci-pci-o2micro.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mmc/host/sdhci-pci-o2micro.c 
b/drivers/mmc/host/sdhci-pci-o2micro.c
index d48f03104b5b..e417e4274d66 100644
--- a/drivers/mmc/host/sdhci-pci-o2micro.c
+++ b/drivers/mmc/host/sdhci-pci-o2micro.c
@@ -334,6 +334,9 @@ int sdhci_pci_o2_probe(struct sdhci_pci_chip *chip)
pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
break;
case PCI_DEVICE_ID_O2_SEABIRD0:
+   if (chip->pdev->revision == 0x01)
+   chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
+   /* fall through */
case PCI_DEVICE_ID_O2_SEABIRD1:
/* UnLock WP */
ret = pci_read_config_byte(chip->pdev,
-- 
2.17.1



[PATCH AUTOSEL 4.9 13/48] iwlwifi: pcie: avoid empty free RB queue

2018-10-31 Thread Sasha Levin
From: Shaul Triebitz 

[ Upstream commit 868a1e863f95183f00809363fefba6d4f5bcd116 ]

If all free RB queues are empty, the driver will never restock the
free RB queue.  That's because the restocking happens in the Rx flow,
and if the free queue is empty there will be no Rx.

Although there's a background worker (a.k.a. allocator) allocating
memory for RBs so that the Rx handler can restock them, the worker may
run only after the free queue has become empty (and then it is too
late for restocking as explained above).

There is a solution for that called 'emergency': If the number of used
RB's reaches half the amount of all RB's, the Rx handler will not wait
for the allocator but immediately allocate memory for the used RB's
and restock the free queue.

But, since the used RB's is per queue, it may happen that the used
RB's are spread between the queues such that the emergency check will
fail for each of the queues
(and still run out of RBs, causing the above symptom).

To fix it, move to emergency mode if the sum of *all* used RBs (for
all Rx queues) reaches half the amount of all RB's

Signed-off-by: Shaul Triebitz 
Signed-off-by: Luca Coelho 
Signed-off-by: Sasha Levin 
---
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 32 +---
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c 
b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
index 996a928142ad..e58a50d31d96 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
@@ -1030,6 +1030,14 @@ void iwl_pcie_rx_free(struct iwl_trans *trans)
kfree(trans_pcie->rxq);
 }
 
+static void iwl_pcie_rx_move_to_allocator(struct iwl_rxq *rxq,
+ struct iwl_rb_allocator *rba)
+{
+   spin_lock(>lock);
+   list_splice_tail_init(>rx_used, >rbd_empty);
+   spin_unlock(>lock);
+}
+
 /*
  * iwl_pcie_rx_reuse_rbd - Recycle used RBDs
  *
@@ -1061,9 +1069,7 @@ static void iwl_pcie_rx_reuse_rbd(struct iwl_trans *trans,
if ((rxq->used_count % RX_CLAIM_REQ_ALLOC) == RX_POST_REQ_ALLOC) {
/* Move the 2 RBDs to the allocator ownership.
 Allocator has another 6 from pool for the request completion*/
-   spin_lock(>lock);
-   list_splice_tail_init(>rx_used, >rbd_empty);
-   spin_unlock(>lock);
+   iwl_pcie_rx_move_to_allocator(rxq, rba);
 
atomic_inc(>req_pending);
queue_work(rba->alloc_wq, >rx_alloc);
@@ -1233,10 +1239,18 @@ static void iwl_pcie_rx_handle(struct iwl_trans *trans, 
int queue)
IWL_DEBUG_RX(trans, "Q %d: HW = SW = %d\n", rxq->id, r);
 
while (i != r) {
+   struct iwl_rb_allocator *rba = _pcie->rba;
struct iwl_rx_mem_buffer *rxb;
-
-   if (unlikely(rxq->used_count == rxq->queue_size / 2))
+   /* number of RBDs still waiting for page allocation */
+   u32 rb_pending_alloc =
+   atomic_read(_pcie->rba.req_pending) *
+   RX_CLAIM_REQ_ALLOC;
+
+   if (unlikely(rb_pending_alloc >= rxq->queue_size / 2 &&
+!emergency)) {
+   iwl_pcie_rx_move_to_allocator(rxq, rba);
emergency = true;
+   }
 
if (trans->cfg->mq_rx_supported) {
/*
@@ -1279,17 +1293,13 @@ static void iwl_pcie_rx_handle(struct iwl_trans *trans, 
int queue)
iwl_pcie_rx_allocator_get(trans, rxq);
 
if (rxq->used_count % RX_CLAIM_REQ_ALLOC == 0 && !emergency) {
-   struct iwl_rb_allocator *rba = _pcie->rba;
-
/* Add the remaining empty RBDs for allocator use */
-   spin_lock(>lock);
-   list_splice_tail_init(>rx_used, >rbd_empty);
-   spin_unlock(>lock);
+   iwl_pcie_rx_move_to_allocator(rxq, rba);
} else if (emergency) {
count++;
if (count == 8) {
count = 0;
-   if (rxq->used_count < rxq->queue_size / 3)
+   if (rb_pending_alloc < rxq->queue_size / 3)
emergency = false;
 
rxq->read = i;
-- 
2.17.1



[PATCH AUTOSEL 4.9 13/48] iwlwifi: pcie: avoid empty free RB queue

2018-10-31 Thread Sasha Levin
From: Shaul Triebitz 

[ Upstream commit 868a1e863f95183f00809363fefba6d4f5bcd116 ]

If all free RB queues are empty, the driver will never restock the
free RB queue.  That's because the restocking happens in the Rx flow,
and if the free queue is empty there will be no Rx.

Although there's a background worker (a.k.a. allocator) allocating
memory for RBs so that the Rx handler can restock them, the worker may
run only after the free queue has become empty (and then it is too
late for restocking as explained above).

There is a solution for that called 'emergency': If the number of used
RB's reaches half the amount of all RB's, the Rx handler will not wait
for the allocator but immediately allocate memory for the used RB's
and restock the free queue.

But, since the used RB's is per queue, it may happen that the used
RB's are spread between the queues such that the emergency check will
fail for each of the queues
(and still run out of RBs, causing the above symptom).

To fix it, move to emergency mode if the sum of *all* used RBs (for
all Rx queues) reaches half the amount of all RB's

Signed-off-by: Shaul Triebitz 
Signed-off-by: Luca Coelho 
Signed-off-by: Sasha Levin 
---
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 32 +---
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c 
b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
index 996a928142ad..e58a50d31d96 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
@@ -1030,6 +1030,14 @@ void iwl_pcie_rx_free(struct iwl_trans *trans)
kfree(trans_pcie->rxq);
 }
 
+static void iwl_pcie_rx_move_to_allocator(struct iwl_rxq *rxq,
+ struct iwl_rb_allocator *rba)
+{
+   spin_lock(>lock);
+   list_splice_tail_init(>rx_used, >rbd_empty);
+   spin_unlock(>lock);
+}
+
 /*
  * iwl_pcie_rx_reuse_rbd - Recycle used RBDs
  *
@@ -1061,9 +1069,7 @@ static void iwl_pcie_rx_reuse_rbd(struct iwl_trans *trans,
if ((rxq->used_count % RX_CLAIM_REQ_ALLOC) == RX_POST_REQ_ALLOC) {
/* Move the 2 RBDs to the allocator ownership.
 Allocator has another 6 from pool for the request completion*/
-   spin_lock(>lock);
-   list_splice_tail_init(>rx_used, >rbd_empty);
-   spin_unlock(>lock);
+   iwl_pcie_rx_move_to_allocator(rxq, rba);
 
atomic_inc(>req_pending);
queue_work(rba->alloc_wq, >rx_alloc);
@@ -1233,10 +1239,18 @@ static void iwl_pcie_rx_handle(struct iwl_trans *trans, 
int queue)
IWL_DEBUG_RX(trans, "Q %d: HW = SW = %d\n", rxq->id, r);
 
while (i != r) {
+   struct iwl_rb_allocator *rba = _pcie->rba;
struct iwl_rx_mem_buffer *rxb;
-
-   if (unlikely(rxq->used_count == rxq->queue_size / 2))
+   /* number of RBDs still waiting for page allocation */
+   u32 rb_pending_alloc =
+   atomic_read(_pcie->rba.req_pending) *
+   RX_CLAIM_REQ_ALLOC;
+
+   if (unlikely(rb_pending_alloc >= rxq->queue_size / 2 &&
+!emergency)) {
+   iwl_pcie_rx_move_to_allocator(rxq, rba);
emergency = true;
+   }
 
if (trans->cfg->mq_rx_supported) {
/*
@@ -1279,17 +1293,13 @@ static void iwl_pcie_rx_handle(struct iwl_trans *trans, 
int queue)
iwl_pcie_rx_allocator_get(trans, rxq);
 
if (rxq->used_count % RX_CLAIM_REQ_ALLOC == 0 && !emergency) {
-   struct iwl_rb_allocator *rba = _pcie->rba;
-
/* Add the remaining empty RBDs for allocator use */
-   spin_lock(>lock);
-   list_splice_tail_init(>rx_used, >rbd_empty);
-   spin_unlock(>lock);
+   iwl_pcie_rx_move_to_allocator(rxq, rba);
} else if (emergency) {
count++;
if (count == 8) {
count = 0;
-   if (rxq->used_count < rxq->queue_size / 3)
+   if (rb_pending_alloc < rxq->queue_size / 3)
emergency = false;
 
rxq->read = i;
-- 
2.17.1



[PATCH AUTOSEL 4.9 19/48] pinctrl: qcom: spmi-mpp: Fix err handling of pmic_mpp_set_mux

2018-10-31 Thread Sasha Levin
From: YueHaibing 

[ Upstream commit 69f8455f6cc78fa6cdf80d0105d7a748106271dc ]

'ret' should be returned while pmic_mpp_write_mode_ctl fails.

Fixes: 0e948042c420 ("pinctrl: qcom: spmi-mpp: Implement support for sink mode")
Signed-off-by: YueHaibing 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
---
 drivers/pinctrl/qcom/pinctrl-spmi-mpp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c 
b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
index 6556dbeae65e..418bc40df7ca 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
@@ -319,6 +319,8 @@ static int pmic_mpp_set_mux(struct pinctrl_dev *pctldev, 
unsigned function,
pad->function = function;
 
ret = pmic_mpp_write_mode_ctl(state, pad);
+   if (ret < 0)
+   return ret;
 
val = pad->is_enabled << PMIC_MPP_REG_MASTER_EN_SHIFT;
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 16/48] regulator: fixed: Default enable high on DT regulators

2018-10-31 Thread Sasha Levin
From: Linus Walleij 

[ Upstream commit 28be5f15df2ee6882b0a122693159c96a28203c7 ]

commit efdfeb079cc3
("regulator: fixed: Convert to use GPIO descriptor only")
switched to use gpiod_get() to look up the regulator from the
gpiolib core whether that is device tree or boardfile.

This meant that we activate the code in
a603a2b8d86e ("gpio: of: Add special quirk to parse regulator flags")
which means the descriptors coming from the device tree already
have the right inversion and open drain semantics set up from
the gpiolib core.

As the fixed regulator was inspected again we got the
inverted inversion and things broke.

Fix it by ignoring the config in the device tree for now: the
later patches in the series will push all inversion handling
over to the gpiolib core and set it up properly in the
boardfiles for legacy devices, but I did not finish that
for this kernel cycle.

Fixes: commit efdfeb079cc3 ("regulator: fixed: Convert to use GPIO descriptor 
only")
Reported-by: Leonard Crestez 
Reported-by: Fabio Estevam 
Reported-by: John Stultz 
Reported-by: Anders Roxell 
Signed-off-by: Linus Walleij 
Tested-by: John Stultz 
Signed-off-by: Mark Brown 
Signed-off-by: Sasha Levin 
---
 drivers/regulator/fixed.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 988a7472c2ab..d68ff65a5adc 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -84,9 +84,14 @@ of_get_fixed_voltage_config(struct device *dev,
 
of_property_read_u32(np, "startup-delay-us", >startup_delay);
 
-   config->enable_high = of_property_read_bool(np, "enable-active-high");
-   config->gpio_is_open_drain = of_property_read_bool(np,
-  "gpio-open-drain");
+   /*
+* FIXME: we pulled active low/high and open drain handling into
+* gpiolib so it will be handled there. Delete this in the second
+* step when we also remove the custom inversion handling for all
+* legacy boardfiles.
+*/
+   config->enable_high = 1;
+   config->gpio_is_open_drain = 0;
 
if (of_find_property(np, "vin-supply", NULL))
config->input_supply = "vin";
-- 
2.17.1



[PATCH AUTOSEL 4.9 19/48] pinctrl: qcom: spmi-mpp: Fix err handling of pmic_mpp_set_mux

2018-10-31 Thread Sasha Levin
From: YueHaibing 

[ Upstream commit 69f8455f6cc78fa6cdf80d0105d7a748106271dc ]

'ret' should be returned while pmic_mpp_write_mode_ctl fails.

Fixes: 0e948042c420 ("pinctrl: qcom: spmi-mpp: Implement support for sink mode")
Signed-off-by: YueHaibing 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
---
 drivers/pinctrl/qcom/pinctrl-spmi-mpp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c 
b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
index 6556dbeae65e..418bc40df7ca 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
@@ -319,6 +319,8 @@ static int pmic_mpp_set_mux(struct pinctrl_dev *pctldev, 
unsigned function,
pad->function = function;
 
ret = pmic_mpp_write_mode_ctl(state, pad);
+   if (ret < 0)
+   return ret;
 
val = pad->is_enabled << PMIC_MPP_REG_MASTER_EN_SHIFT;
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 16/48] regulator: fixed: Default enable high on DT regulators

2018-10-31 Thread Sasha Levin
From: Linus Walleij 

[ Upstream commit 28be5f15df2ee6882b0a122693159c96a28203c7 ]

commit efdfeb079cc3
("regulator: fixed: Convert to use GPIO descriptor only")
switched to use gpiod_get() to look up the regulator from the
gpiolib core whether that is device tree or boardfile.

This meant that we activate the code in
a603a2b8d86e ("gpio: of: Add special quirk to parse regulator flags")
which means the descriptors coming from the device tree already
have the right inversion and open drain semantics set up from
the gpiolib core.

As the fixed regulator was inspected again we got the
inverted inversion and things broke.

Fix it by ignoring the config in the device tree for now: the
later patches in the series will push all inversion handling
over to the gpiolib core and set it up properly in the
boardfiles for legacy devices, but I did not finish that
for this kernel cycle.

Fixes: commit efdfeb079cc3 ("regulator: fixed: Convert to use GPIO descriptor 
only")
Reported-by: Leonard Crestez 
Reported-by: Fabio Estevam 
Reported-by: John Stultz 
Reported-by: Anders Roxell 
Signed-off-by: Linus Walleij 
Tested-by: John Stultz 
Signed-off-by: Mark Brown 
Signed-off-by: Sasha Levin 
---
 drivers/regulator/fixed.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 988a7472c2ab..d68ff65a5adc 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -84,9 +84,14 @@ of_get_fixed_voltage_config(struct device *dev,
 
of_property_read_u32(np, "startup-delay-us", >startup_delay);
 
-   config->enable_high = of_property_read_bool(np, "enable-active-high");
-   config->gpio_is_open_drain = of_property_read_bool(np,
-  "gpio-open-drain");
+   /*
+* FIXME: we pulled active low/high and open drain handling into
+* gpiolib so it will be handled there. Delete this in the second
+* step when we also remove the custom inversion handling for all
+* legacy boardfiles.
+*/
+   config->enable_high = 1;
+   config->gpio_is_open_drain = 0;
 
if (of_find_property(np, "vin-supply", NULL))
config->input_supply = "vin";
-- 
2.17.1



[PATCH AUTOSEL 4.9 15/48] cpufreq: dt: Try freeing static OPPs only if we have added them

2018-10-31 Thread Sasha Levin
From: Viresh Kumar 

[ Upstream commit 51c99dd2c06b234575661fa1e0a1dea6c3ef566f ]

We can not call dev_pm_opp_of_cpumask_remove_table() freely anymore
since the latest OPP core updates as that uses reference counting to
free resources. There are cases where no static OPPs are added (using
DT) for a platform and trying to remove the OPP table may end up
decrementing refcount which is already zero and hence generating
warnings.

Lets track if we were able to add static OPPs or not and then only
remove the table based on that. Some reshuffling of code is also done to
do that.

Reported-by: Niklas Cassel 
Tested-by: Niklas Cassel 
Signed-off-by: Viresh Kumar 
Signed-off-by: Sasha Levin 
---
 drivers/cpufreq/cpufreq-dt.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 4d3ec92cbabf..1496617b05d5 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -32,6 +32,7 @@ struct private_data {
struct device *cpu_dev;
struct thermal_cooling_device *cdev;
const char *reg_name;
+   bool have_static_opps;
 };
 
 static struct freq_attr *cpufreq_dt_attr[] = {
@@ -197,6 +198,15 @@ static int cpufreq_init(struct cpufreq_policy *policy)
}
}
 
+   priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+   if (!priv) {
+   ret = -ENOMEM;
+   goto out_put_regulator;
+   }
+
+   priv->reg_name = name;
+   priv->opp_table = opp_table;
+
/*
 * Initialize OPP tables for all policy->cpus. They will be shared by
 * all CPUs which have marked their CPUs shared with OPP bindings.
@@ -207,7 +217,8 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 *
 * OPPs might be populated at runtime, don't check for error here
 */
-   dev_pm_opp_of_cpumask_add_table(policy->cpus);
+   if (!dev_pm_opp_of_cpumask_add_table(policy->cpus))
+   priv->have_static_opps = true;
 
/*
 * But we need OPP table to function so if it is not there let's
@@ -233,19 +244,10 @@ static int cpufreq_init(struct cpufreq_policy *policy)
__func__, ret);
}
 
-   priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-   if (!priv) {
-   ret = -ENOMEM;
-   goto out_free_opp;
-   }
-
-   priv->reg_name = name;
-   priv->opp_table = opp_table;
-
ret = dev_pm_opp_init_cpufreq_table(cpu_dev, _table);
if (ret) {
dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
-   goto out_free_priv;
+   goto out_free_opp;
}
 
priv->cpu_dev = cpu_dev;
@@ -284,10 +286,11 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 
 out_free_cpufreq_table:
dev_pm_opp_free_cpufreq_table(cpu_dev, _table);
-out_free_priv:
-   kfree(priv);
 out_free_opp:
-   dev_pm_opp_of_cpumask_remove_table(policy->cpus);
+   if (priv->have_static_opps)
+   dev_pm_opp_of_cpumask_remove_table(policy->cpus);
+   kfree(priv);
+out_put_regulator:
if (name)
dev_pm_opp_put_regulator(opp_table);
 out_put_clk:
@@ -302,7 +305,8 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
 
cpufreq_cooling_unregister(priv->cdev);
dev_pm_opp_free_cpufreq_table(priv->cpu_dev, >freq_table);
-   dev_pm_opp_of_cpumask_remove_table(policy->related_cpus);
+   if (priv->have_static_opps)
+   dev_pm_opp_of_cpumask_remove_table(policy->related_cpus);
if (priv->reg_name)
dev_pm_opp_put_regulator(priv->opp_table);
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 14/48] x86/olpc: Indicate that legacy PC XO-1 platform should not register RTC

2018-10-31 Thread Sasha Levin
From: Lubomir Rintel 

[ Upstream commit d92116b800fb79a72ad26121f5011f6aa3ad94c2 ]

On OLPC XO-1, the RTC is discovered via device tree from the arch
initcall. Don't let the PC platform register another one from its device
initcall, it's not going to work:

  sysfs: cannot create duplicate filename '/devices/platform/rtc_cmos'
  CPU: 0 PID: 1 Comm: swapper Not tainted 4.19.0-rc6 #12
  Hardware name: OLPC XO/XO, BIOS OLPC Ver 1.00.01 06/11/2014
  Call Trace:
   dump_stack+0x16/0x18
   sysfs_warn_dup+0x46/0x58
   sysfs_create_dir_ns+0x76/0x9b
   kobject_add_internal+0xed/0x209
   ? __schedule+0x3fa/0x447
   kobject_add+0x5b/0x66
   device_add+0x298/0x535
   ? insert_resource_conflict+0x2a/0x3e
   platform_device_add+0x14d/0x192
   ? io_delay_init+0x19/0x19
   platform_device_register+0x1c/0x1f
   add_rtc_cmos+0x16/0x31
   do_one_initcall+0x78/0x14a
   ? do_early_param+0x75/0x75
   kernel_init_freeable+0x152/0x1e0
   ? rest_init+0xa2/0xa2
   kernel_init+0x8/0xd5
   ret_from_fork+0x2e/0x38
  kobject_add_internal failed for rtc_cmos with -EEXIST, don't try to
register things with the same name in the same directory.
  platform rtc_cmos: registered platform RTC device (no PNP device found)

Signed-off-by: Lubomir Rintel 
Signed-off-by: Borislav Petkov 
Acked-by: Thomas Gleixner 
CC: "H. Peter Anvin" 
CC: Ingo Molnar 
CC: x86-ml 
Link: http://lkml.kernel.org/r/20181004160808.307738-1-lkund...@v3.sk
Signed-off-by: Sasha Levin 
---
 arch/x86/platform/olpc/olpc-xo1-rtc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/platform/olpc/olpc-xo1-rtc.c 
b/arch/x86/platform/olpc/olpc-xo1-rtc.c
index a2b4efddd61a..8e7ddd7e313a 100644
--- a/arch/x86/platform/olpc/olpc-xo1-rtc.c
+++ b/arch/x86/platform/olpc/olpc-xo1-rtc.c
@@ -16,6 +16,7 @@
 
 #include 
 #include 
+#include 
 
 static void rtc_wake_on(struct device *dev)
 {
@@ -75,6 +76,8 @@ static int __init xo1_rtc_init(void)
if (r)
return r;
 
+   x86_platform.legacy.rtc = 0;
+
device_init_wakeup(_rtc_device.dev, 1);
return 0;
 }
-- 
2.17.1



[PATCH AUTOSEL 4.9 15/48] cpufreq: dt: Try freeing static OPPs only if we have added them

2018-10-31 Thread Sasha Levin
From: Viresh Kumar 

[ Upstream commit 51c99dd2c06b234575661fa1e0a1dea6c3ef566f ]

We can not call dev_pm_opp_of_cpumask_remove_table() freely anymore
since the latest OPP core updates as that uses reference counting to
free resources. There are cases where no static OPPs are added (using
DT) for a platform and trying to remove the OPP table may end up
decrementing refcount which is already zero and hence generating
warnings.

Lets track if we were able to add static OPPs or not and then only
remove the table based on that. Some reshuffling of code is also done to
do that.

Reported-by: Niklas Cassel 
Tested-by: Niklas Cassel 
Signed-off-by: Viresh Kumar 
Signed-off-by: Sasha Levin 
---
 drivers/cpufreq/cpufreq-dt.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 4d3ec92cbabf..1496617b05d5 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -32,6 +32,7 @@ struct private_data {
struct device *cpu_dev;
struct thermal_cooling_device *cdev;
const char *reg_name;
+   bool have_static_opps;
 };
 
 static struct freq_attr *cpufreq_dt_attr[] = {
@@ -197,6 +198,15 @@ static int cpufreq_init(struct cpufreq_policy *policy)
}
}
 
+   priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+   if (!priv) {
+   ret = -ENOMEM;
+   goto out_put_regulator;
+   }
+
+   priv->reg_name = name;
+   priv->opp_table = opp_table;
+
/*
 * Initialize OPP tables for all policy->cpus. They will be shared by
 * all CPUs which have marked their CPUs shared with OPP bindings.
@@ -207,7 +217,8 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 *
 * OPPs might be populated at runtime, don't check for error here
 */
-   dev_pm_opp_of_cpumask_add_table(policy->cpus);
+   if (!dev_pm_opp_of_cpumask_add_table(policy->cpus))
+   priv->have_static_opps = true;
 
/*
 * But we need OPP table to function so if it is not there let's
@@ -233,19 +244,10 @@ static int cpufreq_init(struct cpufreq_policy *policy)
__func__, ret);
}
 
-   priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-   if (!priv) {
-   ret = -ENOMEM;
-   goto out_free_opp;
-   }
-
-   priv->reg_name = name;
-   priv->opp_table = opp_table;
-
ret = dev_pm_opp_init_cpufreq_table(cpu_dev, _table);
if (ret) {
dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
-   goto out_free_priv;
+   goto out_free_opp;
}
 
priv->cpu_dev = cpu_dev;
@@ -284,10 +286,11 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 
 out_free_cpufreq_table:
dev_pm_opp_free_cpufreq_table(cpu_dev, _table);
-out_free_priv:
-   kfree(priv);
 out_free_opp:
-   dev_pm_opp_of_cpumask_remove_table(policy->cpus);
+   if (priv->have_static_opps)
+   dev_pm_opp_of_cpumask_remove_table(policy->cpus);
+   kfree(priv);
+out_put_regulator:
if (name)
dev_pm_opp_put_regulator(opp_table);
 out_put_clk:
@@ -302,7 +305,8 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
 
cpufreq_cooling_unregister(priv->cdev);
dev_pm_opp_free_cpufreq_table(priv->cpu_dev, >freq_table);
-   dev_pm_opp_of_cpumask_remove_table(policy->related_cpus);
+   if (priv->have_static_opps)
+   dev_pm_opp_of_cpumask_remove_table(policy->related_cpus);
if (priv->reg_name)
dev_pm_opp_put_regulator(priv->opp_table);
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 14/48] x86/olpc: Indicate that legacy PC XO-1 platform should not register RTC

2018-10-31 Thread Sasha Levin
From: Lubomir Rintel 

[ Upstream commit d92116b800fb79a72ad26121f5011f6aa3ad94c2 ]

On OLPC XO-1, the RTC is discovered via device tree from the arch
initcall. Don't let the PC platform register another one from its device
initcall, it's not going to work:

  sysfs: cannot create duplicate filename '/devices/platform/rtc_cmos'
  CPU: 0 PID: 1 Comm: swapper Not tainted 4.19.0-rc6 #12
  Hardware name: OLPC XO/XO, BIOS OLPC Ver 1.00.01 06/11/2014
  Call Trace:
   dump_stack+0x16/0x18
   sysfs_warn_dup+0x46/0x58
   sysfs_create_dir_ns+0x76/0x9b
   kobject_add_internal+0xed/0x209
   ? __schedule+0x3fa/0x447
   kobject_add+0x5b/0x66
   device_add+0x298/0x535
   ? insert_resource_conflict+0x2a/0x3e
   platform_device_add+0x14d/0x192
   ? io_delay_init+0x19/0x19
   platform_device_register+0x1c/0x1f
   add_rtc_cmos+0x16/0x31
   do_one_initcall+0x78/0x14a
   ? do_early_param+0x75/0x75
   kernel_init_freeable+0x152/0x1e0
   ? rest_init+0xa2/0xa2
   kernel_init+0x8/0xd5
   ret_from_fork+0x2e/0x38
  kobject_add_internal failed for rtc_cmos with -EEXIST, don't try to
register things with the same name in the same directory.
  platform rtc_cmos: registered platform RTC device (no PNP device found)

Signed-off-by: Lubomir Rintel 
Signed-off-by: Borislav Petkov 
Acked-by: Thomas Gleixner 
CC: "H. Peter Anvin" 
CC: Ingo Molnar 
CC: x86-ml 
Link: http://lkml.kernel.org/r/20181004160808.307738-1-lkund...@v3.sk
Signed-off-by: Sasha Levin 
---
 arch/x86/platform/olpc/olpc-xo1-rtc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/platform/olpc/olpc-xo1-rtc.c 
b/arch/x86/platform/olpc/olpc-xo1-rtc.c
index a2b4efddd61a..8e7ddd7e313a 100644
--- a/arch/x86/platform/olpc/olpc-xo1-rtc.c
+++ b/arch/x86/platform/olpc/olpc-xo1-rtc.c
@@ -16,6 +16,7 @@
 
 #include 
 #include 
+#include 
 
 static void rtc_wake_on(struct device *dev)
 {
@@ -75,6 +76,8 @@ static int __init xo1_rtc_init(void)
if (r)
return r;
 
+   x86_platform.legacy.rtc = 0;
+
device_init_wakeup(_rtc_device.dev, 1);
return 0;
 }
-- 
2.17.1



[PATCH AUTOSEL 4.9 22/48] ACPI / LPSS: Add alternative ACPI HIDs for Cherry Trail DMA controllers

2018-10-31 Thread Sasha Levin
From: Hans de Goede 

[ Upstream commit 240714061c58e6b1abfb3322398a7634151c06cb ]

Bay and Cherry Trail DSTDs represent a different set of devices depending
on which OS the device think it is booting. One set of decices for Windows
and another set of devices for Android which targets the Android-x86 Linux
kernel fork (which e.g. used to have its own display driver instead of
using the i915 driver).

Which set of devices we are actually going to get is out of our control,
this is controlled by the ACPI OSID variable, which gets either set through
an EFI setup option, or sometimes is autodetected. So we need to support
both.

This commit adds support for the 80862286 and 808622C0 ACPI HIDs which we
get for the first resp. second DMA controller on Cherry Trail devices when
OSID is set to Android.

Signed-off-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Signed-off-by: Rafael J. Wysocki 
Signed-off-by: Sasha Levin 
---
 drivers/acpi/acpi_lpss.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 3cdd2c3a5bfc..957d3fa3b543 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -278,9 +278,11 @@ static const struct acpi_device_id acpi_lpss_device_ids[] 
= {
{ "INT33FC", },
 
/* Braswell LPSS devices */
+   { "80862286", LPSS_ADDR(lpss_dma_desc) },
{ "80862288", LPSS_ADDR(bsw_pwm_dev_desc) },
{ "8086228A", LPSS_ADDR(bsw_uart_dev_desc) },
{ "8086228E", LPSS_ADDR(bsw_spi_dev_desc) },
+   { "808622C0", LPSS_ADDR(lpss_dma_desc) },
{ "808622C1", LPSS_ADDR(bsw_i2c_dev_desc) },
 
/* Broadwell LPSS devices */
-- 
2.17.1



[PATCH AUTOSEL 4.9 18/48] x86: boot: Fix EFI stub alignment

2018-10-31 Thread Sasha Levin
From: Ben Hutchings 

[ Upstream commit 9c1442a9d039a1a3302fa93e9a11001c5f23b624 ]

We currently align the end of the compressed image to a multiple of
16.  However, the PE-COFF header included in the EFI stub says that
the file alignment is 32 bytes, and when adding an EFI signature to
the file it must first be padded to this alignment.

sbsigntool commands warn about this:

  warning: file-aligned section .text extends beyond end of file
  warning: checksum areas are greater than image size. Invalid section table?

Worse, pesign -at least when creating a detached signature- uses the
hash of the unpadded file, resulting in an invalid signature if
padding is required.

Avoid both these problems by increasing alignment to 32 bytes when
CONFIG_EFI_STUB is enabled.

Signed-off-by: Ben Hutchings 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Sasha Levin 
---
 arch/x86/boot/tools/build.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 0702d2531bc7..039c4a66aca4 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -390,6 +390,13 @@ int main(int argc, char ** argv)
die("Unable to mmap '%s': %m", argv[2]);
/* Number of 16-byte paragraphs, including space for a 4-byte CRC */
sys_size = (sz + 15 + 4) / 16;
+#ifdef CONFIG_EFI_STUB
+   /*
+* COFF requires minimum 32-byte alignment of sections, and
+* adding a signature is problematic without that alignment.
+*/
+   sys_size = (sys_size + 1) & ~1;
+#endif
 
/* Patch the setup code with the appropriate size parameters */
buf[0x1f1] = setup_sectors-1;
-- 
2.17.1



[PATCH AUTOSEL 4.9 22/48] ACPI / LPSS: Add alternative ACPI HIDs for Cherry Trail DMA controllers

2018-10-31 Thread Sasha Levin
From: Hans de Goede 

[ Upstream commit 240714061c58e6b1abfb3322398a7634151c06cb ]

Bay and Cherry Trail DSTDs represent a different set of devices depending
on which OS the device think it is booting. One set of decices for Windows
and another set of devices for Android which targets the Android-x86 Linux
kernel fork (which e.g. used to have its own display driver instead of
using the i915 driver).

Which set of devices we are actually going to get is out of our control,
this is controlled by the ACPI OSID variable, which gets either set through
an EFI setup option, or sometimes is autodetected. So we need to support
both.

This commit adds support for the 80862286 and 808622C0 ACPI HIDs which we
get for the first resp. second DMA controller on Cherry Trail devices when
OSID is set to Android.

Signed-off-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Signed-off-by: Rafael J. Wysocki 
Signed-off-by: Sasha Levin 
---
 drivers/acpi/acpi_lpss.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 3cdd2c3a5bfc..957d3fa3b543 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -278,9 +278,11 @@ static const struct acpi_device_id acpi_lpss_device_ids[] 
= {
{ "INT33FC", },
 
/* Braswell LPSS devices */
+   { "80862286", LPSS_ADDR(lpss_dma_desc) },
{ "80862288", LPSS_ADDR(bsw_pwm_dev_desc) },
{ "8086228A", LPSS_ADDR(bsw_uart_dev_desc) },
{ "8086228E", LPSS_ADDR(bsw_spi_dev_desc) },
+   { "808622C0", LPSS_ADDR(lpss_dma_desc) },
{ "808622C1", LPSS_ADDR(bsw_i2c_dev_desc) },
 
/* Broadwell LPSS devices */
-- 
2.17.1



[PATCH AUTOSEL 4.9 18/48] x86: boot: Fix EFI stub alignment

2018-10-31 Thread Sasha Levin
From: Ben Hutchings 

[ Upstream commit 9c1442a9d039a1a3302fa93e9a11001c5f23b624 ]

We currently align the end of the compressed image to a multiple of
16.  However, the PE-COFF header included in the EFI stub says that
the file alignment is 32 bytes, and when adding an EFI signature to
the file it must first be padded to this alignment.

sbsigntool commands warn about this:

  warning: file-aligned section .text extends beyond end of file
  warning: checksum areas are greater than image size. Invalid section table?

Worse, pesign -at least when creating a detached signature- uses the
hash of the unpadded file, resulting in an invalid signature if
padding is required.

Avoid both these problems by increasing alignment to 32 bytes when
CONFIG_EFI_STUB is enabled.

Signed-off-by: Ben Hutchings 
Signed-off-by: Ard Biesheuvel 
Signed-off-by: Sasha Levin 
---
 arch/x86/boot/tools/build.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 0702d2531bc7..039c4a66aca4 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -390,6 +390,13 @@ int main(int argc, char ** argv)
die("Unable to mmap '%s': %m", argv[2]);
/* Number of 16-byte paragraphs, including space for a 4-byte CRC */
sys_size = (sz + 15 + 4) / 16;
+#ifdef CONFIG_EFI_STUB
+   /*
+* COFF requires minimum 32-byte alignment of sections, and
+* adding a signature is problematic without that alignment.
+*/
+   sys_size = (sys_size + 1) & ~1;
+#endif
 
/* Patch the setup code with the appropriate size parameters */
buf[0x1f1] = setup_sectors-1;
-- 
2.17.1



[PATCH AUTOSEL 4.9 20/48] brcmfmac: fix for proper support of 160MHz bandwidth

2018-10-31 Thread Sasha Levin
From: Arend van Spriel 

[ Upstream commit 330994e8e8ec5d0b269a5265e6032b37e29aa336 ]

Decoding of firmware channel information was not complete for 160MHz
support. This resulted in the following warning:

  WARNING: CPU: 2 PID:  at .../broadcom/brcm80211/brcmutil/d11.c:196
brcmu_d11ac_decchspec+0x2e/0x100 [brcmutil]
  Modules linked in: brcmfmac(O) brcmutil(O) sha256_generic cfg80211 ...
  CPU: 2 PID:  Comm: kworker/2:0 Tainted: G   O
  4.17.0-wt-testing-x64-2-gf1bed50 #1
  Hardware name: Dell Inc. Latitude E6410/07XJP9, BIOS A07 02/15/2011
  Workqueue: events request_firmware_work_func
  RIP: 0010:brcmu_d11ac_decchspec+0x2e/0x100 [brcmutil]
  RSP: 0018:c9047bd0 EFLAGS: 00010206
  RAX: e832 RBX: 8801146fe910 RCX: 8801146fd3c0
  RDX: 2800 RSI: 0070 RDI: c9047c30
  RBP: c9047bd0 R08:  R09: a0798c80
  R10: 88012bca55e0 R11: 880110a4ea00 R12: 8801146f8000
  R13: c9047c30 R14: 8801146fe930 R15: 8801138e02e0
  FS:  () GS:88012bc8() knlGS:
  CS:  0010 DS:  ES:  CR0: 80050033
  CR2: 7f18ce8b8070 CR3: 0200a003 CR4: 000206e0
  Call Trace:
   brcmf_setup_wiphybands+0x212/0x780 [brcmfmac]
   brcmf_cfg80211_attach+0xae2/0x11a0 [brcmfmac]
   brcmf_attach+0x1fc/0x4b0 [brcmfmac]
   ? __kmalloc+0x13c/0x1c0
   brcmf_pcie_setup+0x99b/0xe00 [brcmfmac]
   brcmf_fw_request_done+0x16a/0x1f0 [brcmfmac]
   request_firmware_work_func+0x36/0x60
   process_one_work+0x146/0x350
   worker_thread+0x4a/0x3b0
   kthread+0x102/0x140
   ? process_one_work+0x350/0x350
   ? kthread_bind+0x20/0x20
   ret_from_fork+0x35/0x40
  Code: 66 90 0f b7 07 55 48 89 e5 89 c2 88 47 02 88 47 03 66 81 e2 00 38
66 81 fa 00 18 74 6e 66 81 fa 00 20 74 39 66 81 fa 00 10 74 14 <0f>
0b 66 25 00 c0 74 20 66 3d 00 c0 75 20 c6 47 04 01 5d c3 66
  ---[ end trace 550c46682415b26d ]---
  brcmfmac: brcmf_construct_chaninfo: Ignoring unexpected firmware channel 50

This patch adds the missing stuff to properly handle this.

Reviewed-by: Hante Meuleman 
Reviewed-by: Pieter-Paul Giesberts 
Reviewed-by: Franky Lin 
Signed-off-by: Arend van Spriel 
Signed-off-by: Kalle Valo 
Signed-off-by: Sasha Levin 
---
 .../broadcom/brcm80211/brcmutil/d11.c | 34 ++-
 .../broadcom/brcm80211/include/brcmu_wifi.h   |  2 ++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c 
b/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c
index d8b79cb72b58..e7584b842dce 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c
@@ -77,6 +77,8 @@ static u16 d11ac_bw(enum brcmu_chan_bw bw)
return BRCMU_CHSPEC_D11AC_BW_40;
case BRCMU_CHAN_BW_80:
return BRCMU_CHSPEC_D11AC_BW_80;
+   case BRCMU_CHAN_BW_160:
+   return BRCMU_CHSPEC_D11AC_BW_160;
default:
WARN_ON(1);
}
@@ -190,8 +192,38 @@ static void brcmu_d11ac_decchspec(struct brcmu_chan *ch)
break;
}
break;
-   case BRCMU_CHSPEC_D11AC_BW_8080:
case BRCMU_CHSPEC_D11AC_BW_160:
+   switch (ch->sb) {
+   case BRCMU_CHAN_SB_LLL:
+   ch->control_ch_num -= CH_70MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_LLU:
+   ch->control_ch_num -= CH_50MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_LUL:
+   ch->control_ch_num -= CH_30MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_LUU:
+   ch->control_ch_num -= CH_10MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_ULL:
+   ch->control_ch_num += CH_10MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_ULU:
+   ch->control_ch_num += CH_30MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_UUL:
+   ch->control_ch_num += CH_50MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_UUU:
+   ch->control_ch_num += CH_70MHZ_APART;
+   break;
+   default:
+   WARN_ON_ONCE(1);
+   break;
+   }
+   break;
+   case BRCMU_CHSPEC_D11AC_BW_8080:
default:
WARN_ON_ONCE(1);
break;
diff --git a/drivers/net/wireless/broadcom/brcm80211/include/brcmu_wifi.h 
b/drivers/net/wireless/broadcom/brcm80211/include/brcmu_wifi.h
index 7b9a77981df1..75b2a0438cfa 100644
--- a/drivers/net/wireless/broadcom/brcm80211/include/brcmu_wifi.h
+++ 

Re: [PATCH 10/17] prmem: documentation

2018-10-31 Thread Andy Lutomirski
On Wed, Oct 31, 2018 at 4:10 PM Igor Stoppa  wrote:
>
>
>
> On 01/11/2018 00:57, Andy Lutomirski wrote:
> >
> >
> >> On Oct 31, 2018, at 2:00 PM, Peter Zijlstra  wrote:
>
>
>
> >> I _think_ the use-case for atomics is updating the reference counts of
> >> objects that are in this write-rare domain. But I'm not entirely clear
> >> on that myself either. I just really want to avoid duplicating that
> >> stuff.
> >
> > Sounds nuts. Doing a rare-write is many hundreds of cycles at best. Using 
> > that for a reference count sounds wacky.
> >
> > Can we see a *real* use case before we over complicate the API?
> >
>
>
> Does patch #14 of this set not qualify? ima_htable.len ?
>
> https://www.openwall.com/lists/kernel-hardening/2018/10/23/20
>

Do you mean this (sorry for whitespace damage):

+ pratomic_long_inc(_htable.len);

- atomic_long_inc(_htable.len);
  if (update_htable) {
key = ima_hash_key(entry->digest);
-   hlist_add_head_rcu(>hnext, _htable.queue[key]);
+   prhlist_add_head_rcu(>hnext, _htable.queue[key]);
  }

ISTM you don't need that atomic operation -- you could take a spinlock
and then just add one directly to the variable.

--Andy


[PATCH AUTOSEL 4.9 20/48] brcmfmac: fix for proper support of 160MHz bandwidth

2018-10-31 Thread Sasha Levin
From: Arend van Spriel 

[ Upstream commit 330994e8e8ec5d0b269a5265e6032b37e29aa336 ]

Decoding of firmware channel information was not complete for 160MHz
support. This resulted in the following warning:

  WARNING: CPU: 2 PID:  at .../broadcom/brcm80211/brcmutil/d11.c:196
brcmu_d11ac_decchspec+0x2e/0x100 [brcmutil]
  Modules linked in: brcmfmac(O) brcmutil(O) sha256_generic cfg80211 ...
  CPU: 2 PID:  Comm: kworker/2:0 Tainted: G   O
  4.17.0-wt-testing-x64-2-gf1bed50 #1
  Hardware name: Dell Inc. Latitude E6410/07XJP9, BIOS A07 02/15/2011
  Workqueue: events request_firmware_work_func
  RIP: 0010:brcmu_d11ac_decchspec+0x2e/0x100 [brcmutil]
  RSP: 0018:c9047bd0 EFLAGS: 00010206
  RAX: e832 RBX: 8801146fe910 RCX: 8801146fd3c0
  RDX: 2800 RSI: 0070 RDI: c9047c30
  RBP: c9047bd0 R08:  R09: a0798c80
  R10: 88012bca55e0 R11: 880110a4ea00 R12: 8801146f8000
  R13: c9047c30 R14: 8801146fe930 R15: 8801138e02e0
  FS:  () GS:88012bc8() knlGS:
  CS:  0010 DS:  ES:  CR0: 80050033
  CR2: 7f18ce8b8070 CR3: 0200a003 CR4: 000206e0
  Call Trace:
   brcmf_setup_wiphybands+0x212/0x780 [brcmfmac]
   brcmf_cfg80211_attach+0xae2/0x11a0 [brcmfmac]
   brcmf_attach+0x1fc/0x4b0 [brcmfmac]
   ? __kmalloc+0x13c/0x1c0
   brcmf_pcie_setup+0x99b/0xe00 [brcmfmac]
   brcmf_fw_request_done+0x16a/0x1f0 [brcmfmac]
   request_firmware_work_func+0x36/0x60
   process_one_work+0x146/0x350
   worker_thread+0x4a/0x3b0
   kthread+0x102/0x140
   ? process_one_work+0x350/0x350
   ? kthread_bind+0x20/0x20
   ret_from_fork+0x35/0x40
  Code: 66 90 0f b7 07 55 48 89 e5 89 c2 88 47 02 88 47 03 66 81 e2 00 38
66 81 fa 00 18 74 6e 66 81 fa 00 20 74 39 66 81 fa 00 10 74 14 <0f>
0b 66 25 00 c0 74 20 66 3d 00 c0 75 20 c6 47 04 01 5d c3 66
  ---[ end trace 550c46682415b26d ]---
  brcmfmac: brcmf_construct_chaninfo: Ignoring unexpected firmware channel 50

This patch adds the missing stuff to properly handle this.

Reviewed-by: Hante Meuleman 
Reviewed-by: Pieter-Paul Giesberts 
Reviewed-by: Franky Lin 
Signed-off-by: Arend van Spriel 
Signed-off-by: Kalle Valo 
Signed-off-by: Sasha Levin 
---
 .../broadcom/brcm80211/brcmutil/d11.c | 34 ++-
 .../broadcom/brcm80211/include/brcmu_wifi.h   |  2 ++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c 
b/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c
index d8b79cb72b58..e7584b842dce 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c
@@ -77,6 +77,8 @@ static u16 d11ac_bw(enum brcmu_chan_bw bw)
return BRCMU_CHSPEC_D11AC_BW_40;
case BRCMU_CHAN_BW_80:
return BRCMU_CHSPEC_D11AC_BW_80;
+   case BRCMU_CHAN_BW_160:
+   return BRCMU_CHSPEC_D11AC_BW_160;
default:
WARN_ON(1);
}
@@ -190,8 +192,38 @@ static void brcmu_d11ac_decchspec(struct brcmu_chan *ch)
break;
}
break;
-   case BRCMU_CHSPEC_D11AC_BW_8080:
case BRCMU_CHSPEC_D11AC_BW_160:
+   switch (ch->sb) {
+   case BRCMU_CHAN_SB_LLL:
+   ch->control_ch_num -= CH_70MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_LLU:
+   ch->control_ch_num -= CH_50MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_LUL:
+   ch->control_ch_num -= CH_30MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_LUU:
+   ch->control_ch_num -= CH_10MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_ULL:
+   ch->control_ch_num += CH_10MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_ULU:
+   ch->control_ch_num += CH_30MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_UUL:
+   ch->control_ch_num += CH_50MHZ_APART;
+   break;
+   case BRCMU_CHAN_SB_UUU:
+   ch->control_ch_num += CH_70MHZ_APART;
+   break;
+   default:
+   WARN_ON_ONCE(1);
+   break;
+   }
+   break;
+   case BRCMU_CHSPEC_D11AC_BW_8080:
default:
WARN_ON_ONCE(1);
break;
diff --git a/drivers/net/wireless/broadcom/brcm80211/include/brcmu_wifi.h 
b/drivers/net/wireless/broadcom/brcm80211/include/brcmu_wifi.h
index 7b9a77981df1..75b2a0438cfa 100644
--- a/drivers/net/wireless/broadcom/brcm80211/include/brcmu_wifi.h
+++ 

Re: [PATCH 10/17] prmem: documentation

2018-10-31 Thread Andy Lutomirski
On Wed, Oct 31, 2018 at 4:10 PM Igor Stoppa  wrote:
>
>
>
> On 01/11/2018 00:57, Andy Lutomirski wrote:
> >
> >
> >> On Oct 31, 2018, at 2:00 PM, Peter Zijlstra  wrote:
>
>
>
> >> I _think_ the use-case for atomics is updating the reference counts of
> >> objects that are in this write-rare domain. But I'm not entirely clear
> >> on that myself either. I just really want to avoid duplicating that
> >> stuff.
> >
> > Sounds nuts. Doing a rare-write is many hundreds of cycles at best. Using 
> > that for a reference count sounds wacky.
> >
> > Can we see a *real* use case before we over complicate the API?
> >
>
>
> Does patch #14 of this set not qualify? ima_htable.len ?
>
> https://www.openwall.com/lists/kernel-hardening/2018/10/23/20
>

Do you mean this (sorry for whitespace damage):

+ pratomic_long_inc(_htable.len);

- atomic_long_inc(_htable.len);
  if (update_htable) {
key = ima_hash_key(entry->digest);
-   hlist_add_head_rcu(>hnext, _htable.queue[key]);
+   prhlist_add_head_rcu(>hnext, _htable.queue[key]);
  }

ISTM you don't need that atomic operation -- you could take a spinlock
and then just add one directly to the variable.

--Andy


[PATCH AUTOSEL 4.9 26/48] ixgbevf: VF2VF TCP RSS

2018-10-31 Thread Sasha Levin
From: Sebastian Basierski 

[ Upstream commit 7fb94bd58dd6650a0158e68d414e185077d8b57a ]

While VF2VF with RSS communication, RSS Type were wrongly recognized
and RSS hash was not calculated as it should be. Packets was
distributed on various queues by accident.
This commit fixes that behaviour and causes proper RSS Type recognition.

Signed-off-by: Sebastian Basierski 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c 
b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index 029513294984..75607267e656 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -3419,6 +3419,10 @@ static void ixgbevf_tx_csum(struct ixgbevf_ring *tx_ring,
skb_checksum_help(skb);
goto no_csum;
}
+
+   if (first->protocol == htons(ETH_P_IP))
+   type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
+
/* update TX checksum flag */
first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
vlan_macip_lens = skb_checksum_start_offset(skb) -
-- 
2.17.1



[PATCH AUTOSEL 4.9 24/48] pinctrl: spmi-mpp: Fix pmic_mpp_config_get() to be compliant

2018-10-31 Thread Sasha Levin
From: Douglas Anderson 

[ Upstream commit 0d5b476f8f57fcb06c45fe27681ac47254f63fd2 ]

If you look at "pinconf-groups" in debugfs for ssbi-mpp you'll notice
it looks like nonsense.

The problem is fairly well described in commit 1cf86bc21257 ("pinctrl:
qcom: spmi-gpio: Fix pmic_gpio_config_get() to be compliant") and
commit 05e0c828955c ("pinctrl: msm: Fix msm_config_group_get() to be
compliant"), but it was pointed out that ssbi-mpp has the same
problem.  Let's fix it there too.

NOTE: in case it's helpful to someone reading this, the way to tell
whether to do the -EINVAL or not is to look at the PCONFDUMP for a
given attribute.  If the last element (has_arg) is false then you need
to do the -EINVAL trick.

ALSO NOTE: it seems unlikely that the values returned when we try to
get PIN_CONFIG_BIAS_PULL_UP will actually be printed since "has_arg"
is false for that one, but I guess it's still fine to return different
values so I kept doing that.  It seems like another driver (ssbi-gpio)
uses a custom attribute (PM8XXX_QCOM_PULL_UP_STRENGTH) for something
similar so maybe a future change should do that here too.

Fixes: cfb24f6ebd38 ("pinctrl: Qualcomm SPMI PMIC MPP pin controller driver")
Signed-off-by: Douglas Anderson 
Reviewed-by: Stephen Boyd 
Reviewed-by: Bjorn Andersson 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
---
 drivers/pinctrl/qcom/pinctrl-spmi-mpp.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c 
b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
index 7577f133d326..ac251c62bc66 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
@@ -345,13 +345,12 @@ static int pmic_mpp_config_get(struct pinctrl_dev 
*pctldev,
 
switch (param) {
case PIN_CONFIG_BIAS_DISABLE:
-   arg = pad->pullup == PMIC_MPP_PULL_UP_OPEN;
+   if (pad->pullup != PMIC_MPP_PULL_UP_OPEN)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_BIAS_PULL_UP:
switch (pad->pullup) {
-   case PMIC_MPP_PULL_UP_OPEN:
-   arg = 0;
-   break;
case PMIC_MPP_PULL_UP_0P6KOHM:
arg = 600;
break;
@@ -366,13 +365,17 @@ static int pmic_mpp_config_get(struct pinctrl_dev 
*pctldev,
}
break;
case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
-   arg = !pad->is_enabled;
+   if (pad->is_enabled)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_POWER_SOURCE:
arg = pad->power_source;
break;
case PIN_CONFIG_INPUT_ENABLE:
-   arg = pad->input_enabled;
+   if (!pad->input_enabled)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_OUTPUT:
arg = pad->out_value;
@@ -384,7 +387,9 @@ static int pmic_mpp_config_get(struct pinctrl_dev *pctldev,
arg = pad->amux_input;
break;
case PMIC_MPP_CONF_PAIRED:
-   arg = pad->paired;
+   if (!pad->paired)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_DRIVE_STRENGTH:
arg = pad->drive_strength;
-- 
2.17.1



[PATCH AUTOSEL 4.9 23/48] pinctrl: qcom: spmi-mpp: Fix drive strength setting

2018-10-31 Thread Sasha Levin
From: Stephen Boyd 

[ Upstream commit 89c68b102f13f123aaef22b292526d6b92501334 ]

It looks like we parse the drive strength setting here, but never
actually write it into the hardware to update it. Parse the setting and
then write it at the end of the pinconf setting function so that it
actually sticks in the hardware.

Fixes: 0e948042c420 ("pinctrl: qcom: spmi-mpp: Implement support for sink mode")
Cc: Doug Anderson 
Signed-off-by: Stephen Boyd 
Reviewed-by: Bjorn Andersson 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
---
 drivers/pinctrl/qcom/pinctrl-spmi-mpp.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c 
b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
index 418bc40df7ca..7577f133d326 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
@@ -457,7 +457,7 @@ static int pmic_mpp_config_set(struct pinctrl_dev *pctldev, 
unsigned int pin,
pad->dtest = arg;
break;
case PIN_CONFIG_DRIVE_STRENGTH:
-   arg = pad->drive_strength;
+   pad->drive_strength = arg;
break;
case PMIC_MPP_CONF_AMUX_ROUTE:
if (arg >= PMIC_MPP_AMUX_ROUTE_ABUS4)
@@ -504,6 +504,10 @@ static int pmic_mpp_config_set(struct pinctrl_dev 
*pctldev, unsigned int pin,
if (ret < 0)
return ret;
 
+   ret = pmic_mpp_write(state, pad, PMIC_MPP_REG_SINK_CTL, 
pad->drive_strength);
+   if (ret < 0)
+   return ret;
+
val = pad->is_enabled << PMIC_MPP_REG_MASTER_EN_SHIFT;
 
return pmic_mpp_write(state, pad, PMIC_MPP_REG_EN_CTL, val);
-- 
2.17.1



[PATCH AUTOSEL 4.9 25/48] pinctrl: ssbi-gpio: Fix pm8xxx_pin_config_get() to be compliant

2018-10-31 Thread Sasha Levin
From: Douglas Anderson 

[ Upstream commit b432414b996d32a1bd9afe2bd595bd5729c1477f ]

If you look at "pinconf-groups" in debugfs for ssbi-gpio you'll notice
it looks like nonsense.

The problem is fairly well described in commit 1cf86bc21257 ("pinctrl:
qcom: spmi-gpio: Fix pmic_gpio_config_get() to be compliant") and
commit 05e0c828955c ("pinctrl: msm: Fix msm_config_group_get() to be
compliant"), but it was pointed out that ssbi-gpio has the same
problem.  Let's fix it there too.

Fixes: b4c45fe974bc ("pinctrl: qcom: ssbi: Family A gpio & mpp drivers")
Signed-off-by: Douglas Anderson 
Reviewed-by: Stephen Boyd 
Reviewed-by: Bjorn Andersson 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
---
 drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c | 28 ++--
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c 
b/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
index d3f5501d17ee..e86c4de2f6db 100644
--- a/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
+++ b/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
@@ -260,22 +260,32 @@ static int pm8xxx_pin_config_get(struct pinctrl_dev 
*pctldev,
 
switch (param) {
case PIN_CONFIG_BIAS_DISABLE:
-   arg = pin->bias == PM8XXX_GPIO_BIAS_NP;
+   if (pin->bias != PM8XXX_GPIO_BIAS_NP)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_BIAS_PULL_DOWN:
-   arg = pin->bias == PM8XXX_GPIO_BIAS_PD;
+   if (pin->bias != PM8XXX_GPIO_BIAS_PD)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_BIAS_PULL_UP:
-   arg = pin->bias <= PM8XXX_GPIO_BIAS_PU_1P5_30;
+   if (pin->bias > PM8XXX_GPIO_BIAS_PU_1P5_30)
+   return -EINVAL;
+   arg = 1;
break;
case PM8XXX_QCOM_PULL_UP_STRENGTH:
arg = pin->pull_up_strength;
break;
case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
-   arg = pin->disable;
+   if (!pin->disable)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_INPUT_ENABLE:
-   arg = pin->mode == PM8XXX_GPIO_MODE_INPUT;
+   if (pin->mode != PM8XXX_GPIO_MODE_INPUT)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_OUTPUT:
if (pin->mode & PM8XXX_GPIO_MODE_OUTPUT)
@@ -290,10 +300,14 @@ static int pm8xxx_pin_config_get(struct pinctrl_dev 
*pctldev,
arg = pin->output_strength;
break;
case PIN_CONFIG_DRIVE_PUSH_PULL:
-   arg = !pin->open_drain;
+   if (pin->open_drain)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
-   arg = pin->open_drain;
+   if (!pin->open_drain)
+   return -EINVAL;
+   arg = 1;
break;
default:
return -EINVAL;
-- 
2.17.1



[PATCH AUTOSEL 4.9 26/48] ixgbevf: VF2VF TCP RSS

2018-10-31 Thread Sasha Levin
From: Sebastian Basierski 

[ Upstream commit 7fb94bd58dd6650a0158e68d414e185077d8b57a ]

While VF2VF with RSS communication, RSS Type were wrongly recognized
and RSS hash was not calculated as it should be. Packets was
distributed on various queues by accident.
This commit fixes that behaviour and causes proper RSS Type recognition.

Signed-off-by: Sebastian Basierski 
Tested-by: Andrew Bowers 
Signed-off-by: Jeff Kirsher 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c 
b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index 029513294984..75607267e656 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -3419,6 +3419,10 @@ static void ixgbevf_tx_csum(struct ixgbevf_ring *tx_ring,
skb_checksum_help(skb);
goto no_csum;
}
+
+   if (first->protocol == htons(ETH_P_IP))
+   type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
+
/* update TX checksum flag */
first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
vlan_macip_lens = skb_checksum_start_offset(skb) -
-- 
2.17.1



[PATCH AUTOSEL 4.9 24/48] pinctrl: spmi-mpp: Fix pmic_mpp_config_get() to be compliant

2018-10-31 Thread Sasha Levin
From: Douglas Anderson 

[ Upstream commit 0d5b476f8f57fcb06c45fe27681ac47254f63fd2 ]

If you look at "pinconf-groups" in debugfs for ssbi-mpp you'll notice
it looks like nonsense.

The problem is fairly well described in commit 1cf86bc21257 ("pinctrl:
qcom: spmi-gpio: Fix pmic_gpio_config_get() to be compliant") and
commit 05e0c828955c ("pinctrl: msm: Fix msm_config_group_get() to be
compliant"), but it was pointed out that ssbi-mpp has the same
problem.  Let's fix it there too.

NOTE: in case it's helpful to someone reading this, the way to tell
whether to do the -EINVAL or not is to look at the PCONFDUMP for a
given attribute.  If the last element (has_arg) is false then you need
to do the -EINVAL trick.

ALSO NOTE: it seems unlikely that the values returned when we try to
get PIN_CONFIG_BIAS_PULL_UP will actually be printed since "has_arg"
is false for that one, but I guess it's still fine to return different
values so I kept doing that.  It seems like another driver (ssbi-gpio)
uses a custom attribute (PM8XXX_QCOM_PULL_UP_STRENGTH) for something
similar so maybe a future change should do that here too.

Fixes: cfb24f6ebd38 ("pinctrl: Qualcomm SPMI PMIC MPP pin controller driver")
Signed-off-by: Douglas Anderson 
Reviewed-by: Stephen Boyd 
Reviewed-by: Bjorn Andersson 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
---
 drivers/pinctrl/qcom/pinctrl-spmi-mpp.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c 
b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
index 7577f133d326..ac251c62bc66 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
@@ -345,13 +345,12 @@ static int pmic_mpp_config_get(struct pinctrl_dev 
*pctldev,
 
switch (param) {
case PIN_CONFIG_BIAS_DISABLE:
-   arg = pad->pullup == PMIC_MPP_PULL_UP_OPEN;
+   if (pad->pullup != PMIC_MPP_PULL_UP_OPEN)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_BIAS_PULL_UP:
switch (pad->pullup) {
-   case PMIC_MPP_PULL_UP_OPEN:
-   arg = 0;
-   break;
case PMIC_MPP_PULL_UP_0P6KOHM:
arg = 600;
break;
@@ -366,13 +365,17 @@ static int pmic_mpp_config_get(struct pinctrl_dev 
*pctldev,
}
break;
case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
-   arg = !pad->is_enabled;
+   if (pad->is_enabled)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_POWER_SOURCE:
arg = pad->power_source;
break;
case PIN_CONFIG_INPUT_ENABLE:
-   arg = pad->input_enabled;
+   if (!pad->input_enabled)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_OUTPUT:
arg = pad->out_value;
@@ -384,7 +387,9 @@ static int pmic_mpp_config_get(struct pinctrl_dev *pctldev,
arg = pad->amux_input;
break;
case PMIC_MPP_CONF_PAIRED:
-   arg = pad->paired;
+   if (!pad->paired)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_DRIVE_STRENGTH:
arg = pad->drive_strength;
-- 
2.17.1



[PATCH AUTOSEL 4.9 23/48] pinctrl: qcom: spmi-mpp: Fix drive strength setting

2018-10-31 Thread Sasha Levin
From: Stephen Boyd 

[ Upstream commit 89c68b102f13f123aaef22b292526d6b92501334 ]

It looks like we parse the drive strength setting here, but never
actually write it into the hardware to update it. Parse the setting and
then write it at the end of the pinconf setting function so that it
actually sticks in the hardware.

Fixes: 0e948042c420 ("pinctrl: qcom: spmi-mpp: Implement support for sink mode")
Cc: Doug Anderson 
Signed-off-by: Stephen Boyd 
Reviewed-by: Bjorn Andersson 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
---
 drivers/pinctrl/qcom/pinctrl-spmi-mpp.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c 
b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
index 418bc40df7ca..7577f133d326 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
@@ -457,7 +457,7 @@ static int pmic_mpp_config_set(struct pinctrl_dev *pctldev, 
unsigned int pin,
pad->dtest = arg;
break;
case PIN_CONFIG_DRIVE_STRENGTH:
-   arg = pad->drive_strength;
+   pad->drive_strength = arg;
break;
case PMIC_MPP_CONF_AMUX_ROUTE:
if (arg >= PMIC_MPP_AMUX_ROUTE_ABUS4)
@@ -504,6 +504,10 @@ static int pmic_mpp_config_set(struct pinctrl_dev 
*pctldev, unsigned int pin,
if (ret < 0)
return ret;
 
+   ret = pmic_mpp_write(state, pad, PMIC_MPP_REG_SINK_CTL, 
pad->drive_strength);
+   if (ret < 0)
+   return ret;
+
val = pad->is_enabled << PMIC_MPP_REG_MASTER_EN_SHIFT;
 
return pmic_mpp_write(state, pad, PMIC_MPP_REG_EN_CTL, val);
-- 
2.17.1



[PATCH AUTOSEL 4.9 25/48] pinctrl: ssbi-gpio: Fix pm8xxx_pin_config_get() to be compliant

2018-10-31 Thread Sasha Levin
From: Douglas Anderson 

[ Upstream commit b432414b996d32a1bd9afe2bd595bd5729c1477f ]

If you look at "pinconf-groups" in debugfs for ssbi-gpio you'll notice
it looks like nonsense.

The problem is fairly well described in commit 1cf86bc21257 ("pinctrl:
qcom: spmi-gpio: Fix pmic_gpio_config_get() to be compliant") and
commit 05e0c828955c ("pinctrl: msm: Fix msm_config_group_get() to be
compliant"), but it was pointed out that ssbi-gpio has the same
problem.  Let's fix it there too.

Fixes: b4c45fe974bc ("pinctrl: qcom: ssbi: Family A gpio & mpp drivers")
Signed-off-by: Douglas Anderson 
Reviewed-by: Stephen Boyd 
Reviewed-by: Bjorn Andersson 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
---
 drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c | 28 ++--
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c 
b/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
index d3f5501d17ee..e86c4de2f6db 100644
--- a/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
+++ b/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
@@ -260,22 +260,32 @@ static int pm8xxx_pin_config_get(struct pinctrl_dev 
*pctldev,
 
switch (param) {
case PIN_CONFIG_BIAS_DISABLE:
-   arg = pin->bias == PM8XXX_GPIO_BIAS_NP;
+   if (pin->bias != PM8XXX_GPIO_BIAS_NP)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_BIAS_PULL_DOWN:
-   arg = pin->bias == PM8XXX_GPIO_BIAS_PD;
+   if (pin->bias != PM8XXX_GPIO_BIAS_PD)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_BIAS_PULL_UP:
-   arg = pin->bias <= PM8XXX_GPIO_BIAS_PU_1P5_30;
+   if (pin->bias > PM8XXX_GPIO_BIAS_PU_1P5_30)
+   return -EINVAL;
+   arg = 1;
break;
case PM8XXX_QCOM_PULL_UP_STRENGTH:
arg = pin->pull_up_strength;
break;
case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
-   arg = pin->disable;
+   if (!pin->disable)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_INPUT_ENABLE:
-   arg = pin->mode == PM8XXX_GPIO_MODE_INPUT;
+   if (pin->mode != PM8XXX_GPIO_MODE_INPUT)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_OUTPUT:
if (pin->mode & PM8XXX_GPIO_MODE_OUTPUT)
@@ -290,10 +300,14 @@ static int pm8xxx_pin_config_get(struct pinctrl_dev 
*pctldev,
arg = pin->output_strength;
break;
case PIN_CONFIG_DRIVE_PUSH_PULL:
-   arg = !pin->open_drain;
+   if (pin->open_drain)
+   return -EINVAL;
+   arg = 1;
break;
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
-   arg = pin->open_drain;
+   if (!pin->open_drain)
+   return -EINVAL;
+   arg = 1;
break;
default:
return -EINVAL;
-- 
2.17.1



[PATCH AUTOSEL 4.9 30/48] scsi: megaraid_sas: fix a missing-check bug

2018-10-31 Thread Sasha Levin
From: Wenwen Wang 

[ Upstream commit 47db7873136a9c57c45390a53b57019cf73c8259 ]

In megasas_mgmt_compat_ioctl_fw(), to handle the structure
compat_megasas_iocpacket 'cioc', a user-space structure megasas_iocpacket
'ioc' is allocated before megasas_mgmt_ioctl_fw() is invoked to handle
the packet. Since the two data structures have different fields, the data
is copied from 'cioc' to 'ioc' field by field. In the copy process,
'sense_ptr' is prepared if the field 'sense_len' is not null, because it
will be used in megasas_mgmt_ioctl_fw(). To prepare 'sense_ptr', the
user-space data 'ioc->sense_off' and 'cioc->sense_off' are copied and
saved to kernel-space variables 'local_sense_off' and 'user_sense_off'
respectively. Given that 'ioc->sense_off' is also copied from
'cioc->sense_off', 'local_sense_off' and 'user_sense_off' should have the
same value. However, 'cioc' is in the user space and a malicious user can
race to change the value of 'cioc->sense_off' after it is copied to
'ioc->sense_off' but before it is copied to 'user_sense_off'. By doing
so, the attacker can inject different values into 'local_sense_off' and
'user_sense_off'. This can cause undefined behavior in the following
execution, because the two variables are supposed to be same.

This patch enforces a check on the two kernel variables 'local_sense_off'
and 'user_sense_off' to make sure they are the same after the copy. In
case they are not, an error code EINVAL will be returned.

Signed-off-by: Wenwen Wang 
Acked-by: Sumit Saxena 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 090fdcdd15c9..5de024a50e15 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -6901,6 +6901,9 @@ static int megasas_mgmt_compat_ioctl_fw(struct file 
*file, unsigned long arg)
get_user(user_sense_off, >sense_off))
return -EFAULT;
 
+   if (local_sense_off != user_sense_off)
+   return -EINVAL;
+
if (local_sense_len) {
void __user **sense_ioc_ptr =
(void __user **)((u8 *)((unsigned long)>frame.raw) 
+ local_sense_off);
-- 
2.17.1



[PATCH AUTOSEL 4.9 32/48] IB/ipoib: Clear IPCB before icmp_send

2018-10-31 Thread Sasha Levin
From: Denis Drozdov 

[ Upstream commit 4d6e4d12da2c308f8f976d3955c45ee62539ac98 ]

IPCB should be cleared before icmp_send, since it may contain data from
previous layers and the data could be misinterpreted as ip header options,
which later caused the ihl to be set to an invalid value and resulted in
the following stack corruption:

[ 1083.031512] ib0: packet len 57824 (> 2048) too long to send, dropping
[ 1083.031843] ib0: packet len 37904 (> 2048) too long to send, dropping
[ 1083.032004] ib0: packet len 4040 (> 2048) too long to send, dropping
[ 1083.032253] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.032481] ib0: packet len 23960 (> 2048) too long to send, dropping
[ 1083.033149] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.033439] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.033700] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.034124] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.034387] 
==
[ 1083.034602] BUG: KASAN: stack-out-of-bounds in __ip_options_echo+0xf08/0x1310
[ 1083.034798] Write of size 4 at addr 880353457c5f by task kworker/u16:0/7
[ 1083.034990]
[ 1083.035104] CPU: 7 PID: 7 Comm: kworker/u16:0 Tainted: G   O  
4.19.0-rc5+ #1
[ 1083.035316] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
Ubuntu-1.8.2-1ubuntu2 04/01/2014
[ 1083.035573] Workqueue: ipoib_wq ipoib_cm_skb_reap [ib_ipoib]
[ 1083.035750] Call Trace:
[ 1083.035888]  dump_stack+0x9a/0xeb
[ 1083.036031]  print_address_description+0xe3/0x2e0
[ 1083.036213]  kasan_report+0x18a/0x2e0
[ 1083.036356]  ? __ip_options_echo+0xf08/0x1310
[ 1083.036522]  __ip_options_echo+0xf08/0x1310
[ 1083.036688]  icmp_send+0x7b9/0x1cd0
[ 1083.036843]  ? icmp_route_lookup.constprop.9+0x1070/0x1070
[ 1083.037018]  ? netif_schedule_queue+0x5/0x200
[ 1083.037180]  ? debug_show_all_locks+0x310/0x310
[ 1083.037341]  ? rcu_dynticks_curr_cpu_in_eqs+0x85/0x120
[ 1083.037519]  ? debug_locks_off+0x11/0x80
[ 1083.037673]  ? debug_check_no_obj_freed+0x207/0x4c6
[ 1083.037841]  ? check_flags.part.27+0x450/0x450
[ 1083.037995]  ? debug_check_no_obj_freed+0xc3/0x4c6
[ 1083.038169]  ? debug_locks_off+0x11/0x80
[ 1083.038318]  ? skb_dequeue+0x10e/0x1a0
[ 1083.038476]  ? ipoib_cm_skb_reap+0x2b5/0x650 [ib_ipoib]
[ 1083.038642]  ? netif_schedule_queue+0xa8/0x200
[ 1083.038820]  ? ipoib_cm_skb_reap+0x544/0x650 [ib_ipoib]
[ 1083.038996]  ipoib_cm_skb_reap+0x544/0x650 [ib_ipoib]
[ 1083.039174]  process_one_work+0x912/0x1830
[ 1083.039336]  ? wq_pool_ids_show+0x310/0x310
[ 1083.039491]  ? lock_acquire+0x145/0x3a0
[ 1083.042312]  worker_thread+0x87/0xbb0
[ 1083.045099]  ? process_one_work+0x1830/0x1830
[ 1083.047865]  kthread+0x322/0x3e0
[ 1083.050624]  ? kthread_create_worker_on_cpu+0xc0/0xc0
[ 1083.053354]  ret_from_fork+0x3a/0x50

For instance __ip_options_echo is failing to proceed with invalid srr and
optlen passed from another layer via IPCB

[  762.139568] IPv4: __ip_options_echo rr=0 ts=0 srr=43 cipso=0
[  762.139720] IPv4: ip_options_build: IPCB f3cd969e opt 
2ccb3533
[  762.139838] IPv4: __ip_options_echo in srr: optlen 197 soffset 84
[  762.139852] IPv4: ip_options_build srr=0 is_frag=0 rr_needaddr=0 
ts_needaddr=0 ts_needtime=0 rr=0 ts=0
[  762.140269] 
==
[  762.140713] IPv4: __ip_options_echo rr=0 ts=0 srr=0 cipso=0
[  762.141078] BUG: KASAN: stack-out-of-bounds in 
__ip_options_echo+0x12ec/0x1680
[  762.141087] Write of size 4 at addr 880353457c7f by task kworker/u16:0/7

Signed-off-by: Denis Drozdov 
Reviewed-by: Erez Shitrit 
Reviewed-by: Feras Daoud 
Signed-off-by: Leon Romanovsky 
Signed-off-by: Jason Gunthorpe 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/ulp/ipoib/ipoib_cm.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c 
b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index ad9b486ca7ea..95a3e0abd2a4 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -1422,11 +1422,15 @@ static void ipoib_cm_skb_reap(struct work_struct *work)
spin_unlock_irqrestore(>lock, flags);
netif_tx_unlock_bh(dev);
 
-   if (skb->protocol == htons(ETH_P_IP))
+   if (skb->protocol == htons(ETH_P_IP)) {
+   memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, 
htonl(mtu));
+   }
 #if IS_ENABLED(CONFIG_IPV6)
-   else if (skb->protocol == htons(ETH_P_IPV6))
+   else if (skb->protocol == htons(ETH_P_IPV6)) {
+   memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
+   }
 #endif
dev_kfree_skb_any(skb);
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 27/48] ath10k: schedule hardware restart if WMI command times out

2018-10-31 Thread Sasha Levin
From: Martin Willi 

[ Upstream commit a9911937e7d332761e8c4fcbc7ba0426bdc3956f ]

When running in AP mode, ath10k sometimes suffers from TX credit
starvation. The issue is hard to reproduce and shows up once in a
few days, but has been repeatedly seen with QCA9882 and a large
range of firmwares, including 10.2.4.70.67.

Once the module is in this state, TX credits are never replenished,
which results in "SWBA overrun" errors, as no beacons can be sent.
Even worse, WMI commands run in a timeout while holding the conf
mutex for three seconds each, making any further operations slow
and the whole system unresponsive.

The firmware/driver never recovers from that state automatically,
and triggering TX flush or warm restarts won't work over WMI. So
issue a hardware restart if a WMI command times out due to missing
TX credits. This implies a connectivity outage of about 1.4s in AP
mode, but brings back the interface and the whole system to a usable
state. WMI command timeouts have not been seen in absent of this
specific issue, so taking such drastic actions seems legitimate.

Signed-off-by: Martin Willi 
Signed-off-by: Kalle Valo 
Signed-off-by: Sasha Levin 
---
 drivers/net/wireless/ath/ath10k/wmi.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/wireless/ath/ath10k/wmi.c 
b/drivers/net/wireless/ath/ath10k/wmi.c
index 75f7a7b549df..21aec5c252ee 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.c
+++ b/drivers/net/wireless/ath/ath10k/wmi.c
@@ -1822,6 +1822,12 @@ int ath10k_wmi_cmd_send(struct ath10k *ar, struct 
sk_buff *skb, u32 cmd_id)
if (ret)
dev_kfree_skb_any(skb);
 
+   if (ret == -EAGAIN) {
+   ath10k_warn(ar, "wmi command %d timeout, restarting hardware\n",
+   cmd_id);
+   queue_work(ar->workqueue, >restart_work);
+   }
+
return ret;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 29/48] scsi: esp_scsi: Track residual for PIO transfers

2018-10-31 Thread Sasha Levin
From: Finn Thain 

[ Upstream commit fd47d919d0c336e7c22862b51ee94927ffea227a ]

If a target disconnects during a PIO data transfer the command may fail
when the target reconnects:

scsi host1: DMA length is zero!
scsi host1: cur adr[0438] len[]

The scsi bus is then reset. This happens because the residual reached
zero before the transfer was completed.

The usual residual calculation relies on the Transfer Count registers.
That works for DMA transfers but not for PIO transfers. Fix the problem
by storing the PIO transfer residual and using that to correctly
calculate bytes_sent.

Fixes: 6fe07aaffbf0 ("[SCSI] m68k: new mac_esp scsi driver")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Tested-by: Michael Schmitz 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/esp_scsi.c | 1 +
 drivers/scsi/esp_scsi.h | 2 ++
 drivers/scsi/mac_esp.c  | 2 ++
 3 files changed, 5 insertions(+)

diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 71cb05b1c3eb..60be0742e2c8 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -1349,6 +1349,7 @@ static int esp_data_bytes_sent(struct esp *esp, struct 
esp_cmd_entry *ent,
 
bytes_sent = esp->data_dma_len;
bytes_sent -= ecount;
+   bytes_sent -= esp->send_cmd_residual;
 
/*
 * The am53c974 has a DMA 'pecularity'. The doc states:
diff --git a/drivers/scsi/esp_scsi.h b/drivers/scsi/esp_scsi.h
index 84dcbe4a6268..55be43fe7667 100644
--- a/drivers/scsi/esp_scsi.h
+++ b/drivers/scsi/esp_scsi.h
@@ -540,6 +540,8 @@ struct esp {
 
void*dma;
int dmarev;
+
+   u32 send_cmd_residual;
 };
 
 /* A front-end driver for the ESP chip should do the following in
diff --git a/drivers/scsi/mac_esp.c b/drivers/scsi/mac_esp.c
index 26c67c42985c..1002124bd8bf 100644
--- a/drivers/scsi/mac_esp.c
+++ b/drivers/scsi/mac_esp.c
@@ -426,6 +426,8 @@ static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, 
u32 esp_count,
scsi_esp_cmd(esp, ESP_CMD_TI);
}
}
+
+   esp->send_cmd_residual = esp_count;
 }
 
 static int mac_esp_irq_pending(struct esp *esp)
-- 
2.17.1



[PATCH AUTOSEL 4.9 33/48] tpm: suppress transmit cmd error logs when TPM 1.2 is disabled/deactivated

2018-10-31 Thread Sasha Levin
From: Javier Martinez Canillas 

[ Upstream commit 0d6d0d62d9505a9816716aa484ebd0b04c795063 ]

For TPM 1.2 chips the system setup utility allows to set the TPM device in
one of the following states:

  * Active: Security chip is functional
  * Inactive: Security chip is visible, but is not functional
  * Disabled: Security chip is hidden and is not functional

When choosing the "Inactive" state, the TPM 1.2 device is enumerated and
registered, but sending TPM commands fail with either TPM_DEACTIVATED or
TPM_DISABLED depending if the firmware deactivated or disabled the TPM.

Since these TPM 1.2 error codes don't have special treatment, inactivating
the TPM leads to a very noisy kernel log buffer that shows messages like
the following:

  tpm_tis 00:05: 1.2 TPM (device-id 0x0, rev-id 78)
  tpm tpm0: A TPM error (6) occurred attempting to read a pcr value
  tpm tpm0: TPM is disabled/deactivated (0x6)
  tpm tpm0: A TPM error (6) occurred attempting get random
  tpm tpm0: A TPM error (6) occurred attempting to read a pcr value
  ima: No TPM chip found, activating TPM-bypass! (rc=6)
  tpm tpm0: A TPM error (6) occurred attempting get random
  tpm tpm0: A TPM error (6) occurred attempting get random
  tpm tpm0: A TPM error (6) occurred attempting get random
  tpm tpm0: A TPM error (6) occurred attempting get random

Let's just suppress error log messages for the TPM_{DEACTIVATED,DISABLED}
return codes, since this is expected when the TPM 1.2 is set to Inactive.

In that case the kernel log is cleaner and less confusing for users, i.e:

  tpm_tis 00:05: 1.2 TPM (device-id 0x0, rev-id 78)
  tpm tpm0: TPM is disabled/deactivated (0x6)
  ima: No TPM chip found, activating TPM-bypass! (rc=6)

Reported-by: Hans de Goede 
Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Jarkko Sakkinen 
Signed-off-by: Jarkko Sakkinen 
Signed-off-by: Sasha Levin 
---
 drivers/char/tpm/tpm-interface.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index faf2db122ab9..4f0b1945d020 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -420,7 +420,8 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void 
*cmd,
header = cmd;
 
err = be32_to_cpu(header->return_code);
-   if (err != 0 && desc)
+   if (err != 0 && err != TPM_ERR_DISABLED && err != TPM_ERR_DEACTIVATED
+   && desc)
dev_err(>dev, "A TPM error (%d) occurred %s\n", err,
desc);
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 34/48] Drivers: hv: kvp: Fix two "this statement may fall through" warnings

2018-10-31 Thread Sasha Levin
From: Dexuan Cui 

[ Upstream commit fc62c3b1977d62e6374fd6e28d371bb42dfa5c9d ]

We don't need to call process_ib_ipinfo() if message->kvp_hdr.operation is
KVP_OP_GET_IP_INFO in kvp_send_key(), because here we just need to pass on
the op code from the host to the userspace; when the userspace returns
the info requested by the host, we pass the info on to the host in
kvp_respond_to_host() -> process_ob_ipinfo(). BTW, the current buggy code
actually doesn't cause any harm, because only message->kvp_hdr.operation
is used by the userspace, in the case of KVP_OP_GET_IP_INFO.

The patch also adds a missing "break;" in kvp_send_key(). BTW, the current
buggy code actually doesn't cause any harm, because in the case of
KVP_OP_SET, the unexpected fall-through corrupts
message->body.kvp_set.data.key_size, but that is not really used: see
the definition of struct hv_kvp_exchg_msg_value.

Signed-off-by: Dexuan Cui 
Cc: K. Y. Srinivasan 
Cc: Haiyang Zhang 
Cc: Stephen Hemminger 
Cc: 
Signed-off-by: K. Y. Srinivasan 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/hv/hv_kvp.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c
index 2fd0f119a67b..7e3ef92de4b0 100644
--- a/drivers/hv/hv_kvp.c
+++ b/drivers/hv/hv_kvp.c
@@ -340,7 +340,6 @@ static void process_ib_ipinfo(void *in_msg, void *out_msg, 
int op)
 
out->body.kvp_ip_val.dhcp_enabled = in->kvp_ip_val.dhcp_enabled;
 
-   default:
utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.adapter_id,
MAX_ADAPTER_ID_SIZE,
UTF16_LITTLE_ENDIAN,
@@ -393,7 +392,7 @@ kvp_send_key(struct work_struct *dummy)
process_ib_ipinfo(in_msg, message, KVP_OP_SET_IP_INFO);
break;
case KVP_OP_GET_IP_INFO:
-   process_ib_ipinfo(in_msg, message, KVP_OP_GET_IP_INFO);
+   /* We only need to pass on message->kvp_hdr.operation.  */
break;
case KVP_OP_SET:
switch (in_msg->body.kvp_set.data.value_type) {
@@ -433,6 +432,9 @@ kvp_send_key(struct work_struct *dummy)
break;
 
}
+
+   break;
+
case KVP_OP_GET:
message->body.kvp_set.data.key_size =
utf16s_to_utf8s(
-- 
2.17.1



[PATCH AUTOSEL 4.9 27/48] ath10k: schedule hardware restart if WMI command times out

2018-10-31 Thread Sasha Levin
From: Martin Willi 

[ Upstream commit a9911937e7d332761e8c4fcbc7ba0426bdc3956f ]

When running in AP mode, ath10k sometimes suffers from TX credit
starvation. The issue is hard to reproduce and shows up once in a
few days, but has been repeatedly seen with QCA9882 and a large
range of firmwares, including 10.2.4.70.67.

Once the module is in this state, TX credits are never replenished,
which results in "SWBA overrun" errors, as no beacons can be sent.
Even worse, WMI commands run in a timeout while holding the conf
mutex for three seconds each, making any further operations slow
and the whole system unresponsive.

The firmware/driver never recovers from that state automatically,
and triggering TX flush or warm restarts won't work over WMI. So
issue a hardware restart if a WMI command times out due to missing
TX credits. This implies a connectivity outage of about 1.4s in AP
mode, but brings back the interface and the whole system to a usable
state. WMI command timeouts have not been seen in absent of this
specific issue, so taking such drastic actions seems legitimate.

Signed-off-by: Martin Willi 
Signed-off-by: Kalle Valo 
Signed-off-by: Sasha Levin 
---
 drivers/net/wireless/ath/ath10k/wmi.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/wireless/ath/ath10k/wmi.c 
b/drivers/net/wireless/ath/ath10k/wmi.c
index 75f7a7b549df..21aec5c252ee 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.c
+++ b/drivers/net/wireless/ath/ath10k/wmi.c
@@ -1822,6 +1822,12 @@ int ath10k_wmi_cmd_send(struct ath10k *ar, struct 
sk_buff *skb, u32 cmd_id)
if (ret)
dev_kfree_skb_any(skb);
 
+   if (ret == -EAGAIN) {
+   ath10k_warn(ar, "wmi command %d timeout, restarting hardware\n",
+   cmd_id);
+   queue_work(ar->workqueue, >restart_work);
+   }
+
return ret;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 29/48] scsi: esp_scsi: Track residual for PIO transfers

2018-10-31 Thread Sasha Levin
From: Finn Thain 

[ Upstream commit fd47d919d0c336e7c22862b51ee94927ffea227a ]

If a target disconnects during a PIO data transfer the command may fail
when the target reconnects:

scsi host1: DMA length is zero!
scsi host1: cur adr[0438] len[]

The scsi bus is then reset. This happens because the residual reached
zero before the transfer was completed.

The usual residual calculation relies on the Transfer Count registers.
That works for DMA transfers but not for PIO transfers. Fix the problem
by storing the PIO transfer residual and using that to correctly
calculate bytes_sent.

Fixes: 6fe07aaffbf0 ("[SCSI] m68k: new mac_esp scsi driver")
Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Tested-by: Michael Schmitz 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/esp_scsi.c | 1 +
 drivers/scsi/esp_scsi.h | 2 ++
 drivers/scsi/mac_esp.c  | 2 ++
 3 files changed, 5 insertions(+)

diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 71cb05b1c3eb..60be0742e2c8 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -1349,6 +1349,7 @@ static int esp_data_bytes_sent(struct esp *esp, struct 
esp_cmd_entry *ent,
 
bytes_sent = esp->data_dma_len;
bytes_sent -= ecount;
+   bytes_sent -= esp->send_cmd_residual;
 
/*
 * The am53c974 has a DMA 'pecularity'. The doc states:
diff --git a/drivers/scsi/esp_scsi.h b/drivers/scsi/esp_scsi.h
index 84dcbe4a6268..55be43fe7667 100644
--- a/drivers/scsi/esp_scsi.h
+++ b/drivers/scsi/esp_scsi.h
@@ -540,6 +540,8 @@ struct esp {
 
void*dma;
int dmarev;
+
+   u32 send_cmd_residual;
 };
 
 /* A front-end driver for the ESP chip should do the following in
diff --git a/drivers/scsi/mac_esp.c b/drivers/scsi/mac_esp.c
index 26c67c42985c..1002124bd8bf 100644
--- a/drivers/scsi/mac_esp.c
+++ b/drivers/scsi/mac_esp.c
@@ -426,6 +426,8 @@ static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, 
u32 esp_count,
scsi_esp_cmd(esp, ESP_CMD_TI);
}
}
+
+   esp->send_cmd_residual = esp_count;
 }
 
 static int mac_esp_irq_pending(struct esp *esp)
-- 
2.17.1



[PATCH AUTOSEL 4.9 33/48] tpm: suppress transmit cmd error logs when TPM 1.2 is disabled/deactivated

2018-10-31 Thread Sasha Levin
From: Javier Martinez Canillas 

[ Upstream commit 0d6d0d62d9505a9816716aa484ebd0b04c795063 ]

For TPM 1.2 chips the system setup utility allows to set the TPM device in
one of the following states:

  * Active: Security chip is functional
  * Inactive: Security chip is visible, but is not functional
  * Disabled: Security chip is hidden and is not functional

When choosing the "Inactive" state, the TPM 1.2 device is enumerated and
registered, but sending TPM commands fail with either TPM_DEACTIVATED or
TPM_DISABLED depending if the firmware deactivated or disabled the TPM.

Since these TPM 1.2 error codes don't have special treatment, inactivating
the TPM leads to a very noisy kernel log buffer that shows messages like
the following:

  tpm_tis 00:05: 1.2 TPM (device-id 0x0, rev-id 78)
  tpm tpm0: A TPM error (6) occurred attempting to read a pcr value
  tpm tpm0: TPM is disabled/deactivated (0x6)
  tpm tpm0: A TPM error (6) occurred attempting get random
  tpm tpm0: A TPM error (6) occurred attempting to read a pcr value
  ima: No TPM chip found, activating TPM-bypass! (rc=6)
  tpm tpm0: A TPM error (6) occurred attempting get random
  tpm tpm0: A TPM error (6) occurred attempting get random
  tpm tpm0: A TPM error (6) occurred attempting get random
  tpm tpm0: A TPM error (6) occurred attempting get random

Let's just suppress error log messages for the TPM_{DEACTIVATED,DISABLED}
return codes, since this is expected when the TPM 1.2 is set to Inactive.

In that case the kernel log is cleaner and less confusing for users, i.e:

  tpm_tis 00:05: 1.2 TPM (device-id 0x0, rev-id 78)
  tpm tpm0: TPM is disabled/deactivated (0x6)
  ima: No TPM chip found, activating TPM-bypass! (rc=6)

Reported-by: Hans de Goede 
Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Jarkko Sakkinen 
Signed-off-by: Jarkko Sakkinen 
Signed-off-by: Sasha Levin 
---
 drivers/char/tpm/tpm-interface.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index faf2db122ab9..4f0b1945d020 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -420,7 +420,8 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void 
*cmd,
header = cmd;
 
err = be32_to_cpu(header->return_code);
-   if (err != 0 && desc)
+   if (err != 0 && err != TPM_ERR_DISABLED && err != TPM_ERR_DEACTIVATED
+   && desc)
dev_err(>dev, "A TPM error (%d) occurred %s\n", err,
desc);
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 34/48] Drivers: hv: kvp: Fix two "this statement may fall through" warnings

2018-10-31 Thread Sasha Levin
From: Dexuan Cui 

[ Upstream commit fc62c3b1977d62e6374fd6e28d371bb42dfa5c9d ]

We don't need to call process_ib_ipinfo() if message->kvp_hdr.operation is
KVP_OP_GET_IP_INFO in kvp_send_key(), because here we just need to pass on
the op code from the host to the userspace; when the userspace returns
the info requested by the host, we pass the info on to the host in
kvp_respond_to_host() -> process_ob_ipinfo(). BTW, the current buggy code
actually doesn't cause any harm, because only message->kvp_hdr.operation
is used by the userspace, in the case of KVP_OP_GET_IP_INFO.

The patch also adds a missing "break;" in kvp_send_key(). BTW, the current
buggy code actually doesn't cause any harm, because in the case of
KVP_OP_SET, the unexpected fall-through corrupts
message->body.kvp_set.data.key_size, but that is not really used: see
the definition of struct hv_kvp_exchg_msg_value.

Signed-off-by: Dexuan Cui 
Cc: K. Y. Srinivasan 
Cc: Haiyang Zhang 
Cc: Stephen Hemminger 
Cc: 
Signed-off-by: K. Y. Srinivasan 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/hv/hv_kvp.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c
index 2fd0f119a67b..7e3ef92de4b0 100644
--- a/drivers/hv/hv_kvp.c
+++ b/drivers/hv/hv_kvp.c
@@ -340,7 +340,6 @@ static void process_ib_ipinfo(void *in_msg, void *out_msg, 
int op)
 
out->body.kvp_ip_val.dhcp_enabled = in->kvp_ip_val.dhcp_enabled;
 
-   default:
utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.adapter_id,
MAX_ADAPTER_ID_SIZE,
UTF16_LITTLE_ENDIAN,
@@ -393,7 +392,7 @@ kvp_send_key(struct work_struct *dummy)
process_ib_ipinfo(in_msg, message, KVP_OP_SET_IP_INFO);
break;
case KVP_OP_GET_IP_INFO:
-   process_ib_ipinfo(in_msg, message, KVP_OP_GET_IP_INFO);
+   /* We only need to pass on message->kvp_hdr.operation.  */
break;
case KVP_OP_SET:
switch (in_msg->body.kvp_set.data.value_type) {
@@ -433,6 +432,9 @@ kvp_send_key(struct work_struct *dummy)
break;
 
}
+
+   break;
+
case KVP_OP_GET:
message->body.kvp_set.data.key_size =
utf16s_to_utf8s(
-- 
2.17.1



[PATCH AUTOSEL 4.9 30/48] scsi: megaraid_sas: fix a missing-check bug

2018-10-31 Thread Sasha Levin
From: Wenwen Wang 

[ Upstream commit 47db7873136a9c57c45390a53b57019cf73c8259 ]

In megasas_mgmt_compat_ioctl_fw(), to handle the structure
compat_megasas_iocpacket 'cioc', a user-space structure megasas_iocpacket
'ioc' is allocated before megasas_mgmt_ioctl_fw() is invoked to handle
the packet. Since the two data structures have different fields, the data
is copied from 'cioc' to 'ioc' field by field. In the copy process,
'sense_ptr' is prepared if the field 'sense_len' is not null, because it
will be used in megasas_mgmt_ioctl_fw(). To prepare 'sense_ptr', the
user-space data 'ioc->sense_off' and 'cioc->sense_off' are copied and
saved to kernel-space variables 'local_sense_off' and 'user_sense_off'
respectively. Given that 'ioc->sense_off' is also copied from
'cioc->sense_off', 'local_sense_off' and 'user_sense_off' should have the
same value. However, 'cioc' is in the user space and a malicious user can
race to change the value of 'cioc->sense_off' after it is copied to
'ioc->sense_off' but before it is copied to 'user_sense_off'. By doing
so, the attacker can inject different values into 'local_sense_off' and
'user_sense_off'. This can cause undefined behavior in the following
execution, because the two variables are supposed to be same.

This patch enforces a check on the two kernel variables 'local_sense_off'
and 'user_sense_off' to make sure they are the same after the copy. In
case they are not, an error code EINVAL will be returned.

Signed-off-by: Wenwen Wang 
Acked-by: Sumit Saxena 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 090fdcdd15c9..5de024a50e15 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -6901,6 +6901,9 @@ static int megasas_mgmt_compat_ioctl_fw(struct file 
*file, unsigned long arg)
get_user(user_sense_off, >sense_off))
return -EFAULT;
 
+   if (local_sense_off != user_sense_off)
+   return -EINVAL;
+
if (local_sense_len) {
void __user **sense_ioc_ptr =
(void __user **)((u8 *)((unsigned long)>frame.raw) 
+ local_sense_off);
-- 
2.17.1



[PATCH AUTOSEL 4.9 32/48] IB/ipoib: Clear IPCB before icmp_send

2018-10-31 Thread Sasha Levin
From: Denis Drozdov 

[ Upstream commit 4d6e4d12da2c308f8f976d3955c45ee62539ac98 ]

IPCB should be cleared before icmp_send, since it may contain data from
previous layers and the data could be misinterpreted as ip header options,
which later caused the ihl to be set to an invalid value and resulted in
the following stack corruption:

[ 1083.031512] ib0: packet len 57824 (> 2048) too long to send, dropping
[ 1083.031843] ib0: packet len 37904 (> 2048) too long to send, dropping
[ 1083.032004] ib0: packet len 4040 (> 2048) too long to send, dropping
[ 1083.032253] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.032481] ib0: packet len 23960 (> 2048) too long to send, dropping
[ 1083.033149] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.033439] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.033700] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.034124] ib0: packet len 63800 (> 2048) too long to send, dropping
[ 1083.034387] 
==
[ 1083.034602] BUG: KASAN: stack-out-of-bounds in __ip_options_echo+0xf08/0x1310
[ 1083.034798] Write of size 4 at addr 880353457c5f by task kworker/u16:0/7
[ 1083.034990]
[ 1083.035104] CPU: 7 PID: 7 Comm: kworker/u16:0 Tainted: G   O  
4.19.0-rc5+ #1
[ 1083.035316] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
Ubuntu-1.8.2-1ubuntu2 04/01/2014
[ 1083.035573] Workqueue: ipoib_wq ipoib_cm_skb_reap [ib_ipoib]
[ 1083.035750] Call Trace:
[ 1083.035888]  dump_stack+0x9a/0xeb
[ 1083.036031]  print_address_description+0xe3/0x2e0
[ 1083.036213]  kasan_report+0x18a/0x2e0
[ 1083.036356]  ? __ip_options_echo+0xf08/0x1310
[ 1083.036522]  __ip_options_echo+0xf08/0x1310
[ 1083.036688]  icmp_send+0x7b9/0x1cd0
[ 1083.036843]  ? icmp_route_lookup.constprop.9+0x1070/0x1070
[ 1083.037018]  ? netif_schedule_queue+0x5/0x200
[ 1083.037180]  ? debug_show_all_locks+0x310/0x310
[ 1083.037341]  ? rcu_dynticks_curr_cpu_in_eqs+0x85/0x120
[ 1083.037519]  ? debug_locks_off+0x11/0x80
[ 1083.037673]  ? debug_check_no_obj_freed+0x207/0x4c6
[ 1083.037841]  ? check_flags.part.27+0x450/0x450
[ 1083.037995]  ? debug_check_no_obj_freed+0xc3/0x4c6
[ 1083.038169]  ? debug_locks_off+0x11/0x80
[ 1083.038318]  ? skb_dequeue+0x10e/0x1a0
[ 1083.038476]  ? ipoib_cm_skb_reap+0x2b5/0x650 [ib_ipoib]
[ 1083.038642]  ? netif_schedule_queue+0xa8/0x200
[ 1083.038820]  ? ipoib_cm_skb_reap+0x544/0x650 [ib_ipoib]
[ 1083.038996]  ipoib_cm_skb_reap+0x544/0x650 [ib_ipoib]
[ 1083.039174]  process_one_work+0x912/0x1830
[ 1083.039336]  ? wq_pool_ids_show+0x310/0x310
[ 1083.039491]  ? lock_acquire+0x145/0x3a0
[ 1083.042312]  worker_thread+0x87/0xbb0
[ 1083.045099]  ? process_one_work+0x1830/0x1830
[ 1083.047865]  kthread+0x322/0x3e0
[ 1083.050624]  ? kthread_create_worker_on_cpu+0xc0/0xc0
[ 1083.053354]  ret_from_fork+0x3a/0x50

For instance __ip_options_echo is failing to proceed with invalid srr and
optlen passed from another layer via IPCB

[  762.139568] IPv4: __ip_options_echo rr=0 ts=0 srr=43 cipso=0
[  762.139720] IPv4: ip_options_build: IPCB f3cd969e opt 
2ccb3533
[  762.139838] IPv4: __ip_options_echo in srr: optlen 197 soffset 84
[  762.139852] IPv4: ip_options_build srr=0 is_frag=0 rr_needaddr=0 
ts_needaddr=0 ts_needtime=0 rr=0 ts=0
[  762.140269] 
==
[  762.140713] IPv4: __ip_options_echo rr=0 ts=0 srr=0 cipso=0
[  762.141078] BUG: KASAN: stack-out-of-bounds in 
__ip_options_echo+0x12ec/0x1680
[  762.141087] Write of size 4 at addr 880353457c7f by task kworker/u16:0/7

Signed-off-by: Denis Drozdov 
Reviewed-by: Erez Shitrit 
Reviewed-by: Feras Daoud 
Signed-off-by: Leon Romanovsky 
Signed-off-by: Jason Gunthorpe 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/ulp/ipoib/ipoib_cm.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c 
b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index ad9b486ca7ea..95a3e0abd2a4 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -1422,11 +1422,15 @@ static void ipoib_cm_skb_reap(struct work_struct *work)
spin_unlock_irqrestore(>lock, flags);
netif_tx_unlock_bh(dev);
 
-   if (skb->protocol == htons(ETH_P_IP))
+   if (skb->protocol == htons(ETH_P_IP)) {
+   memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, 
htonl(mtu));
+   }
 #if IS_ENABLED(CONFIG_IPV6)
-   else if (skb->protocol == htons(ETH_P_IPV6))
+   else if (skb->protocol == htons(ETH_P_IPV6)) {
+   memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
+   }
 #endif
dev_kfree_skb_any(skb);
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 38/48] MD: fix invalid stored role for a disk

2018-10-31 Thread Sasha Levin
From: Shaohua Li 

[ Upstream commit d595567dc4f0c1d90685ec1e2e296e2cad2643ac ]

If we change the number of array's device after device is removed from array,
then add the device back to array, we can see that device is added as active
role instead of spare which we expected.

Please see the below link for details:
https://marc.info/?l=linux-raid=153736982015076=2

This is caused by that we prefer to use device's previous role which is
recorded by saved_raid_disk, but we should respect the new number of
conf->raid_disks since it could be changed after device is removed.

Reported-by: Gioh Kim 
Tested-by: Gioh Kim 
Acked-by: Guoqing Jiang 
Signed-off-by: Shaohua Li 
Signed-off-by: Sasha Levin 
---
 drivers/md/md.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index a7a0e3acdb2f..efb012b927c9 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1665,6 +1665,10 @@ static int super_1_validate(struct mddev *mddev, struct 
md_rdev *rdev)
} else
set_bit(In_sync, >flags);
rdev->raid_disk = role;
+   if (role >= mddev->raid_disks) {
+   rdev->saved_raid_disk = -1;
+   rdev->raid_disk = -1;
+   }
break;
}
if (sb->devflags & WriteMostly1)
-- 
2.17.1



[PATCH AUTOSEL 4.9 31/48] RDMA/core: Do not expose unsupported counters

2018-10-31 Thread Sasha Levin
From: Parav Pandit 

[ Upstream commit 0f6ef65d1c6ec8deb5d0f11f86631ec4cfe8f22e ]

If the provider driver (such as rdma_rxe) doesn't support pma counters,
avoid exposing its directory similar to optional hw_counters directory.
If core fails to read the PMA counter, return an error so that user can
retry later if needed.

Fixes: 35c4cbb17811 ("IB/core: Create get_perf_mad function in sysfs.c")
Reported-by: Holger Hoffstätte 
Tested-by: Holger Hoffstätte 
Signed-off-by: Parav Pandit 
Signed-off-by: Leon Romanovsky 
Signed-off-by: Doug Ledford 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/core/sysfs.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 42de5f22da93..a1240ddca026 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -485,7 +485,7 @@ static ssize_t show_pma_counter(struct ib_port *p, struct 
port_attribute *attr,
ret = get_perf_mad(p->ibdev, p->port_num, tab_attr->attr_id, ,
40 + offset / 8, sizeof(data));
if (ret < 0)
-   return sprintf(buf, "N/A (no PMA)\n");
+   return ret;
 
switch (width) {
case 4:
@@ -1008,10 +1008,12 @@ static int add_port(struct ib_device *device, int 
port_num,
goto err_put;
}
 
-   p->pma_table = get_counter_table(device, port_num);
-   ret = sysfs_create_group(>kobj, p->pma_table);
-   if (ret)
-   goto err_put_gid_attrs;
+   if (device->process_mad) {
+   p->pma_table = get_counter_table(device, port_num);
+   ret = sysfs_create_group(>kobj, p->pma_table);
+   if (ret)
+   goto err_put_gid_attrs;
+   }
 
p->gid_group.name  = "gids";
p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
@@ -1124,7 +1126,8 @@ static int add_port(struct ib_device *device, int 
port_num,
p->gid_group.attrs = NULL;
 
 err_remove_pma:
-   sysfs_remove_group(>kobj, p->pma_table);
+   if (p->pma_table)
+   sysfs_remove_group(>kobj, p->pma_table);
 
 err_put_gid_attrs:
kobject_put(>gid_attr_group->kobj);
@@ -1236,7 +1239,9 @@ static void free_port_list_attributes(struct ib_device 
*device)
kfree(port->hw_stats);
free_hsag(>kobj, port->hw_stats_ag);
}
-   sysfs_remove_group(p, port->pma_table);
+
+   if (port->pma_table)
+   sysfs_remove_group(p, port->pma_table);
sysfs_remove_group(p, >pkey_group);
sysfs_remove_group(p, >gid_group);
sysfs_remove_group(>gid_attr_group->kobj,
-- 
2.17.1



[PATCH AUTOSEL 4.9 36/48] usb: gadget: udc: atmel: handle at91sam9rl PMC

2018-10-31 Thread Sasha Levin
From: Alexandre Belloni 

[ Upstream commit bb80e4fa57eb75ebd64ae9be4155da6d12c1a997 ]

The at91sam9rl PMC is not quite the same as the at91sam9g45 one and now has
its own compatible string. Add support for that.

Fixes: 217bace8e548 ("ARM: dts: fix PMC compatible")
Acked-by: Cristian Birsan 
Signed-off-by: Alexandre Belloni 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index ad8402906f77..9705bcdbc577 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1922,6 +1922,8 @@ static struct usba_ep * atmel_udc_of_init(struct 
platform_device *pdev,
 
udc->errata = match->data;
udc->pmc = syscon_regmap_lookup_by_compatible("atmel,at91sam9g45-pmc");
+   if (IS_ERR(udc->pmc))
+   udc->pmc = 
syscon_regmap_lookup_by_compatible("atmel,at91sam9rl-pmc");
if (IS_ERR(udc->pmc))
udc->pmc = 
syscon_regmap_lookup_by_compatible("atmel,at91sam9x5-pmc");
if (udc->errata && IS_ERR(udc->pmc))
-- 
2.17.1



[PATCH AUTOSEL 4.9 38/48] MD: fix invalid stored role for a disk

2018-10-31 Thread Sasha Levin
From: Shaohua Li 

[ Upstream commit d595567dc4f0c1d90685ec1e2e296e2cad2643ac ]

If we change the number of array's device after device is removed from array,
then add the device back to array, we can see that device is added as active
role instead of spare which we expected.

Please see the below link for details:
https://marc.info/?l=linux-raid=153736982015076=2

This is caused by that we prefer to use device's previous role which is
recorded by saved_raid_disk, but we should respect the new number of
conf->raid_disks since it could be changed after device is removed.

Reported-by: Gioh Kim 
Tested-by: Gioh Kim 
Acked-by: Guoqing Jiang 
Signed-off-by: Shaohua Li 
Signed-off-by: Sasha Levin 
---
 drivers/md/md.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index a7a0e3acdb2f..efb012b927c9 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1665,6 +1665,10 @@ static int super_1_validate(struct mddev *mddev, struct 
md_rdev *rdev)
} else
set_bit(In_sync, >flags);
rdev->raid_disk = role;
+   if (role >= mddev->raid_disks) {
+   rdev->saved_raid_disk = -1;
+   rdev->raid_disk = -1;
+   }
break;
}
if (sb->devflags & WriteMostly1)
-- 
2.17.1



[PATCH AUTOSEL 4.9 31/48] RDMA/core: Do not expose unsupported counters

2018-10-31 Thread Sasha Levin
From: Parav Pandit 

[ Upstream commit 0f6ef65d1c6ec8deb5d0f11f86631ec4cfe8f22e ]

If the provider driver (such as rdma_rxe) doesn't support pma counters,
avoid exposing its directory similar to optional hw_counters directory.
If core fails to read the PMA counter, return an error so that user can
retry later if needed.

Fixes: 35c4cbb17811 ("IB/core: Create get_perf_mad function in sysfs.c")
Reported-by: Holger Hoffstätte 
Tested-by: Holger Hoffstätte 
Signed-off-by: Parav Pandit 
Signed-off-by: Leon Romanovsky 
Signed-off-by: Doug Ledford 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/core/sysfs.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 42de5f22da93..a1240ddca026 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -485,7 +485,7 @@ static ssize_t show_pma_counter(struct ib_port *p, struct 
port_attribute *attr,
ret = get_perf_mad(p->ibdev, p->port_num, tab_attr->attr_id, ,
40 + offset / 8, sizeof(data));
if (ret < 0)
-   return sprintf(buf, "N/A (no PMA)\n");
+   return ret;
 
switch (width) {
case 4:
@@ -1008,10 +1008,12 @@ static int add_port(struct ib_device *device, int 
port_num,
goto err_put;
}
 
-   p->pma_table = get_counter_table(device, port_num);
-   ret = sysfs_create_group(>kobj, p->pma_table);
-   if (ret)
-   goto err_put_gid_attrs;
+   if (device->process_mad) {
+   p->pma_table = get_counter_table(device, port_num);
+   ret = sysfs_create_group(>kobj, p->pma_table);
+   if (ret)
+   goto err_put_gid_attrs;
+   }
 
p->gid_group.name  = "gids";
p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
@@ -1124,7 +1126,8 @@ static int add_port(struct ib_device *device, int 
port_num,
p->gid_group.attrs = NULL;
 
 err_remove_pma:
-   sysfs_remove_group(>kobj, p->pma_table);
+   if (p->pma_table)
+   sysfs_remove_group(>kobj, p->pma_table);
 
 err_put_gid_attrs:
kobject_put(>gid_attr_group->kobj);
@@ -1236,7 +1239,9 @@ static void free_port_list_attributes(struct ib_device 
*device)
kfree(port->hw_stats);
free_hsag(>kobj, port->hw_stats_ag);
}
-   sysfs_remove_group(p, port->pma_table);
+
+   if (port->pma_table)
+   sysfs_remove_group(p, port->pma_table);
sysfs_remove_group(p, >pkey_group);
sysfs_remove_group(p, >gid_group);
sysfs_remove_group(>gid_attr_group->kobj,
-- 
2.17.1



[PATCH AUTOSEL 4.9 36/48] usb: gadget: udc: atmel: handle at91sam9rl PMC

2018-10-31 Thread Sasha Levin
From: Alexandre Belloni 

[ Upstream commit bb80e4fa57eb75ebd64ae9be4155da6d12c1a997 ]

The at91sam9rl PMC is not quite the same as the at91sam9g45 one and now has
its own compatible string. Add support for that.

Fixes: 217bace8e548 ("ARM: dts: fix PMC compatible")
Acked-by: Cristian Birsan 
Signed-off-by: Alexandre Belloni 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index ad8402906f77..9705bcdbc577 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1922,6 +1922,8 @@ static struct usba_ep * atmel_udc_of_init(struct 
platform_device *pdev,
 
udc->errata = match->data;
udc->pmc = syscon_regmap_lookup_by_compatible("atmel,at91sam9g45-pmc");
+   if (IS_ERR(udc->pmc))
+   udc->pmc = 
syscon_regmap_lookup_by_compatible("atmel,at91sam9rl-pmc");
if (IS_ERR(udc->pmc))
udc->pmc = 
syscon_regmap_lookup_by_compatible("atmel,at91sam9x5-pmc");
if (udc->errata && IS_ERR(udc->pmc))
-- 
2.17.1



[PATCH AUTOSEL 4.9 35/48] VMCI: Resource wildcard match fixed

2018-10-31 Thread Sasha Levin
From: Jorgen Hansen 

[ Upstream commit 11924ba5e671d6caef1516923e2bd8c72929a3fe ]

When adding a VMCI resource, the check for an existing entry
would ignore that the new entry could be a wildcard. This could
result in multiple resource entries that would match a given
handle. One disastrous outcome of this is that the
refcounting used to ensure that delayed callbacks for VMCI
datagrams have run before the datagram is destroyed can be
wrong, since the refcount could be increased on the duplicate
entry. This in turn leads to a use after free bug. This issue
was discovered by Hangbin Liu using KASAN and syzkaller.

Fixes: bc63dedb7d46 ("VMCI: resource object implementation")
Reported-by: Hangbin Liu 
Reviewed-by: Adit Ranadive 
Reviewed-by: Vishnu Dasa 
Signed-off-by: Jorgen Hansen 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/misc/vmw_vmci/vmci_driver.c   | 2 +-
 drivers/misc/vmw_vmci/vmci_resource.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_driver.c 
b/drivers/misc/vmw_vmci/vmci_driver.c
index d7eaf1eb11e7..003bfba40758 100644
--- a/drivers/misc/vmw_vmci/vmci_driver.c
+++ b/drivers/misc/vmw_vmci/vmci_driver.c
@@ -113,5 +113,5 @@ module_exit(vmci_drv_exit);
 
 MODULE_AUTHOR("VMware, Inc.");
 MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
-MODULE_VERSION("1.1.5.0-k");
+MODULE_VERSION("1.1.6.0-k");
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/misc/vmw_vmci/vmci_resource.c 
b/drivers/misc/vmw_vmci/vmci_resource.c
index 9a53a30de445..f1164602cec1 100644
--- a/drivers/misc/vmw_vmci/vmci_resource.c
+++ b/drivers/misc/vmw_vmci/vmci_resource.c
@@ -56,7 +56,8 @@ static struct vmci_resource *vmci_resource_lookup(struct 
vmci_handle handle,
 
if (r->type == type &&
rid == handle.resource &&
-   (cid == handle.context || cid == VMCI_INVALID_ID)) {
+   (cid == handle.context || cid == VMCI_INVALID_ID ||
+handle.context == VMCI_INVALID_ID)) {
resource = r;
break;
}
-- 
2.17.1



[PATCH AUTOSEL 4.9 39/48] PCI/MSI: Warn and return error if driver enables MSI/MSI-X twice

2018-10-31 Thread Sasha Levin
From: Tonghao Zhang 

[ Upstream commit 4c1ef72e9b71a19fb405ebfcd37c0a5e16fa44ca ]

It is a serious driver defect to enable MSI or MSI-X more than once.  Doing
so may panic the kernel as in the stack trace below:

  Call Trace:
sysfs_add_one+0xa5/0xd0
create_dir+0x7c/0xe0
sysfs_create_subdir+0x1c/0x20
internal_create_group+0x6d/0x290
sysfs_create_groups+0x4a/0xa0
populate_msi_sysfs+0x1cd/0x210
pci_enable_msix+0x31c/0x3e0
igbuio_pci_open+0x72/0x300 [igb_uio]
uio_open+0xcc/0x120 [uio]
chrdev_open+0xa1/0x1e0
[...]
do_sys_open+0xf3/0x1f0
SyS_open+0x1e/0x20
system_call_fastpath+0x16/0x1b
---[ end trace 11042e2848880209 ]---
Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: 
a056b4fa

We want to keep the WARN_ON() and stack trace so the driver can be fixed,
but we can avoid the kernel panic by returning an error.  We may still get
warnings like this:

  Call Trace:
pci_enable_msix+0x3c9/0x3e0
igbuio_pci_open+0x72/0x300 [igb_uio]
uio_open+0xcc/0x120 [uio]
chrdev_open+0xa1/0x1e0
[...]
do_sys_open+0xf3/0x1f0
SyS_open+0x1e/0x20
system_call_fastpath+0x16/0x1b
[ cut here ]
WARNING: at fs/sysfs/dir.c:526 sysfs_add_one+0xa5/0xd0()
sysfs: cannot create duplicate filename 
'/devices/pci:00/:00:03.0/:01:00.1/msi_irqs'

Signed-off-by: Tonghao Zhang 
[bhelgaas: changelog, fix patch whitespace, remove !!]
Signed-off-by: Bjorn Helgaas 
Signed-off-by: Sasha Levin 
---
 drivers/pci/msi.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 0e9a9dbeb184..37f393f27efc 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -981,7 +981,6 @@ static int __pci_enable_msix(struct pci_dev *dev, struct 
msix_entry *entries,
}
}
}
-   WARN_ON(!!dev->msix_enabled);
 
/* Check whether driver already requested for MSI irq */
if (dev->msi_enabled) {
@@ -1068,8 +1067,6 @@ static int __pci_enable_msi_range(struct pci_dev *dev, 
int minvec, int maxvec,
if (!pci_msi_supported(dev, minvec))
return -EINVAL;
 
-   WARN_ON(!!dev->msi_enabled);
-
/* Check whether driver already requested MSI-X irqs */
if (dev->msix_enabled) {
dev_info(>dev,
@@ -1080,6 +1077,9 @@ static int __pci_enable_msi_range(struct pci_dev *dev, 
int minvec, int maxvec,
if (maxvec < minvec)
return -ERANGE;
 
+   if (WARN_ON_ONCE(dev->msi_enabled))
+   return -EINVAL;
+
nvec = pci_msi_vec_count(dev);
if (nvec < 0)
return nvec;
@@ -1138,6 +1138,9 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
if (maxvec < minvec)
return -ERANGE;
 
+   if (WARN_ON_ONCE(dev->msix_enabled))
+   return -EINVAL;
+
for (;;) {
if (affinity) {
nvec = irq_calc_affinity_vectors(dev->irq_affinity,
-- 
2.17.1



[PATCH AUTOSEL 4.9 40/48] coresight: etb10: Fix handling of perf mode

2018-10-31 Thread Sasha Levin
From: Suzuki K Poulose 

[ Upstream commit 987d1e8dcd370d96029a3d76a0031b043c4a69ae ]

If the ETB is already enabled in sysfs mode, the ETB reports
success even if a perf mode is requested. Fix this by checking
the requested mode.

Cc: Mathieu Poirier 
Signed-off-by: Suzuki K Poulose 
Signed-off-by: Mathieu Poirier 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/hwtracing/coresight/coresight-etb10.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etb10.c 
b/drivers/hwtracing/coresight/coresight-etb10.c
index d7325c6534ad..ace55385b26f 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -155,6 +155,10 @@ static int etb_enable(struct coresight_device *csdev, u32 
mode)
if (val == CS_MODE_PERF)
return -EBUSY;
 
+   /* Don't let perf disturb sysFS sessions */
+   if (val == CS_MODE_SYSFS && mode == CS_MODE_PERF)
+   return -EBUSY;
+
/* Nothing to do, the tracer is already enabled. */
if (val == CS_MODE_SYSFS)
goto out;
-- 
2.17.1



[PATCH AUTOSEL 4.9 35/48] VMCI: Resource wildcard match fixed

2018-10-31 Thread Sasha Levin
From: Jorgen Hansen 

[ Upstream commit 11924ba5e671d6caef1516923e2bd8c72929a3fe ]

When adding a VMCI resource, the check for an existing entry
would ignore that the new entry could be a wildcard. This could
result in multiple resource entries that would match a given
handle. One disastrous outcome of this is that the
refcounting used to ensure that delayed callbacks for VMCI
datagrams have run before the datagram is destroyed can be
wrong, since the refcount could be increased on the duplicate
entry. This in turn leads to a use after free bug. This issue
was discovered by Hangbin Liu using KASAN and syzkaller.

Fixes: bc63dedb7d46 ("VMCI: resource object implementation")
Reported-by: Hangbin Liu 
Reviewed-by: Adit Ranadive 
Reviewed-by: Vishnu Dasa 
Signed-off-by: Jorgen Hansen 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/misc/vmw_vmci/vmci_driver.c   | 2 +-
 drivers/misc/vmw_vmci/vmci_resource.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_driver.c 
b/drivers/misc/vmw_vmci/vmci_driver.c
index d7eaf1eb11e7..003bfba40758 100644
--- a/drivers/misc/vmw_vmci/vmci_driver.c
+++ b/drivers/misc/vmw_vmci/vmci_driver.c
@@ -113,5 +113,5 @@ module_exit(vmci_drv_exit);
 
 MODULE_AUTHOR("VMware, Inc.");
 MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
-MODULE_VERSION("1.1.5.0-k");
+MODULE_VERSION("1.1.6.0-k");
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/misc/vmw_vmci/vmci_resource.c 
b/drivers/misc/vmw_vmci/vmci_resource.c
index 9a53a30de445..f1164602cec1 100644
--- a/drivers/misc/vmw_vmci/vmci_resource.c
+++ b/drivers/misc/vmw_vmci/vmci_resource.c
@@ -56,7 +56,8 @@ static struct vmci_resource *vmci_resource_lookup(struct 
vmci_handle handle,
 
if (r->type == type &&
rid == handle.resource &&
-   (cid == handle.context || cid == VMCI_INVALID_ID)) {
+   (cid == handle.context || cid == VMCI_INVALID_ID ||
+handle.context == VMCI_INVALID_ID)) {
resource = r;
break;
}
-- 
2.17.1



[PATCH AUTOSEL 4.9 39/48] PCI/MSI: Warn and return error if driver enables MSI/MSI-X twice

2018-10-31 Thread Sasha Levin
From: Tonghao Zhang 

[ Upstream commit 4c1ef72e9b71a19fb405ebfcd37c0a5e16fa44ca ]

It is a serious driver defect to enable MSI or MSI-X more than once.  Doing
so may panic the kernel as in the stack trace below:

  Call Trace:
sysfs_add_one+0xa5/0xd0
create_dir+0x7c/0xe0
sysfs_create_subdir+0x1c/0x20
internal_create_group+0x6d/0x290
sysfs_create_groups+0x4a/0xa0
populate_msi_sysfs+0x1cd/0x210
pci_enable_msix+0x31c/0x3e0
igbuio_pci_open+0x72/0x300 [igb_uio]
uio_open+0xcc/0x120 [uio]
chrdev_open+0xa1/0x1e0
[...]
do_sys_open+0xf3/0x1f0
SyS_open+0x1e/0x20
system_call_fastpath+0x16/0x1b
---[ end trace 11042e2848880209 ]---
Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: 
a056b4fa

We want to keep the WARN_ON() and stack trace so the driver can be fixed,
but we can avoid the kernel panic by returning an error.  We may still get
warnings like this:

  Call Trace:
pci_enable_msix+0x3c9/0x3e0
igbuio_pci_open+0x72/0x300 [igb_uio]
uio_open+0xcc/0x120 [uio]
chrdev_open+0xa1/0x1e0
[...]
do_sys_open+0xf3/0x1f0
SyS_open+0x1e/0x20
system_call_fastpath+0x16/0x1b
[ cut here ]
WARNING: at fs/sysfs/dir.c:526 sysfs_add_one+0xa5/0xd0()
sysfs: cannot create duplicate filename 
'/devices/pci:00/:00:03.0/:01:00.1/msi_irqs'

Signed-off-by: Tonghao Zhang 
[bhelgaas: changelog, fix patch whitespace, remove !!]
Signed-off-by: Bjorn Helgaas 
Signed-off-by: Sasha Levin 
---
 drivers/pci/msi.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 0e9a9dbeb184..37f393f27efc 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -981,7 +981,6 @@ static int __pci_enable_msix(struct pci_dev *dev, struct 
msix_entry *entries,
}
}
}
-   WARN_ON(!!dev->msix_enabled);
 
/* Check whether driver already requested for MSI irq */
if (dev->msi_enabled) {
@@ -1068,8 +1067,6 @@ static int __pci_enable_msi_range(struct pci_dev *dev, 
int minvec, int maxvec,
if (!pci_msi_supported(dev, minvec))
return -EINVAL;
 
-   WARN_ON(!!dev->msi_enabled);
-
/* Check whether driver already requested MSI-X irqs */
if (dev->msix_enabled) {
dev_info(>dev,
@@ -1080,6 +1077,9 @@ static int __pci_enable_msi_range(struct pci_dev *dev, 
int minvec, int maxvec,
if (maxvec < minvec)
return -ERANGE;
 
+   if (WARN_ON_ONCE(dev->msi_enabled))
+   return -EINVAL;
+
nvec = pci_msi_vec_count(dev);
if (nvec < 0)
return nvec;
@@ -1138,6 +1138,9 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
if (maxvec < minvec)
return -ERANGE;
 
+   if (WARN_ON_ONCE(dev->msix_enabled))
+   return -EINVAL;
+
for (;;) {
if (affinity) {
nvec = irq_calc_affinity_vectors(dev->irq_affinity,
-- 
2.17.1



[PATCH AUTOSEL 4.9 40/48] coresight: etb10: Fix handling of perf mode

2018-10-31 Thread Sasha Levin
From: Suzuki K Poulose 

[ Upstream commit 987d1e8dcd370d96029a3d76a0031b043c4a69ae ]

If the ETB is already enabled in sysfs mode, the ETB reports
success even if a perf mode is requested. Fix this by checking
the requested mode.

Cc: Mathieu Poirier 
Signed-off-by: Suzuki K Poulose 
Signed-off-by: Mathieu Poirier 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/hwtracing/coresight/coresight-etb10.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etb10.c 
b/drivers/hwtracing/coresight/coresight-etb10.c
index d7325c6534ad..ace55385b26f 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -155,6 +155,10 @@ static int etb_enable(struct coresight_device *csdev, u32 
mode)
if (val == CS_MODE_PERF)
return -EBUSY;
 
+   /* Don't let perf disturb sysFS sessions */
+   if (val == CS_MODE_SYSFS && mode == CS_MODE_PERF)
+   return -EBUSY;
+
/* Nothing to do, the tracer is already enabled. */
if (val == CS_MODE_SYSFS)
goto out;
-- 
2.17.1



[PATCH AUTOSEL 4.9 37/48] ext4: fix argument checking in EXT4_IOC_MOVE_EXT

2018-10-31 Thread Sasha Levin
From: Theodore Ts'o 

[ Upstream commit f18b2b83a727a3db208308057d2c7945f368e625 ]

If the starting block number of either the source or destination file
exceeds the EOF, EXT4_IOC_MOVE_EXT should return EINVAL.

Also fixed the helper function mext_check_coverage() so that if the
logical block is beyond EOF, make it return immediately, instead of
looping until the block number wraps all the away around.  This takes
long enough that if there are multiple threads trying to do pound on
an the same inode doing non-sensical things, it can end up triggering
the kernel's soft lockup detector.

Reported-by: syzbot+c61979f6f2cba5cb3...@syzkaller.appspotmail.com
Signed-off-by: Theodore Ts'o 
Cc: sta...@kernel.org
Signed-off-by: Sasha Levin 
---
 fs/ext4/move_extent.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index 578f8c33fb44..c4434bdeeea7 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -526,9 +526,13 @@ mext_check_arguments(struct inode *orig_inode,
orig_inode->i_ino, donor_inode->i_ino);
return -EINVAL;
}
-   if (orig_eof < orig_start + *len - 1)
+   if (orig_eof <= orig_start)
+   *len = 0;
+   else if (orig_eof < orig_start + *len - 1)
*len = orig_eof - orig_start;
-   if (donor_eof < donor_start + *len - 1)
+   if (donor_eof <= donor_start)
+   *len = 0;
+   else if (donor_eof < donor_start + *len - 1)
*len = donor_eof - donor_start;
if (!*len) {
ext4_debug("ext4 move extent: len should not be 0 "
-- 
2.17.1



[PATCH AUTOSEL 4.9 44/48] uio: ensure class is registered before devices

2018-10-31 Thread Sasha Levin
From: Alexandre Belloni 

[ Upstream commit ae61cf5b9913027c6953a79ed3894da4f47061bd ]

When both uio and the uio drivers are built in the kernel, it is possible
for a driver to register devices before the uio class is registered.

This may result in a NULL pointer dereference later on in
get_device_parent() when accessing the class glue_dirs spinlock.

The trace looks like that:

Unable to handle kernel NULL pointer dereference at virtual address 0140
[...]
[] _raw_spin_lock+0x14/0x48
[] device_add+0x154/0x6a0
[] device_create_groups_vargs+0x120/0x128
[] device_create+0x54/0x60
[] __uio_register_device+0x120/0x4a8
[] jaguar2_pci_probe+0x2d4/0x558
[] local_pci_probe+0x3c/0xb8
[] pci_device_probe+0x11c/0x180
[] driver_probe_device+0x22c/0x2d8
[] __driver_attach+0xbc/0xc0
[] bus_for_each_dev+0x4c/0x98
[] driver_attach+0x20/0x28
[] bus_add_driver+0x1b8/0x228
[] driver_register+0x60/0xf8
[] __pci_register_driver+0x40/0x48

Return EPROBE_DEFER in that case so the driver can register the device
later.

Signed-off-by: Alexandre Belloni 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/uio/uio.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index f0a9ea2740df..cfbfef08c94a 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -249,6 +249,8 @@ static struct class uio_class = {
.dev_groups = uio_groups,
 };
 
+bool uio_class_registered;
+
 /*
  * device functions
  */
@@ -780,6 +782,9 @@ static int init_uio_class(void)
printk(KERN_ERR "class_register failed for uio\n");
goto err_class_register;
}
+
+   uio_class_registered = true;
+
return 0;
 
 err_class_register:
@@ -790,6 +795,7 @@ static int init_uio_class(void)
 
 static void release_uio_class(void)
 {
+   uio_class_registered = false;
class_unregister(_class);
uio_major_cleanup();
 }
@@ -809,6 +815,9 @@ int __uio_register_device(struct module *owner,
struct uio_device *idev;
int ret = 0;
 
+   if (!uio_class_registered)
+   return -EPROBE_DEFER;
+
if (!parent || !info || !info->name || !info->version)
return -EINVAL;
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 41/48] crypto: caam - fix implicit casts in endianness helpers

2018-10-31 Thread Sasha Levin
From: Horia Geantă 

[ Upstream commit aae733a3f46f5ef338fbdde26e14cbb205a23de0 ]

Fix the following sparse endianness warnings:

drivers/crypto/caam/regs.h:95:1: sparse: incorrect type in return expression 
(different base types) @@expected unsigned int @@got restricted 
__le32unsigned int @@
drivers/crypto/caam/regs.h:95:1:expected unsigned int
drivers/crypto/caam/regs.h:95:1:got restricted __le32 [usertype] 
drivers/crypto/caam/regs.h:95:1: sparse: incorrect type in return expression 
(different base types) @@expected unsigned int @@got restricted 
__be32unsigned int @@
drivers/crypto/caam/regs.h:95:1:expected unsigned int
drivers/crypto/caam/regs.h:95:1:got restricted __be32 [usertype] 

drivers/crypto/caam/regs.h:92:1: sparse: cast to restricted __le32
drivers/crypto/caam/regs.h:92:1: sparse: cast to restricted __be32

Fixes: 261ea058f016 ("crypto: caam - handle core endianness != caam endianness")
Reported-by: kbuild test robot 
Signed-off-by: Horia Geantă 
Signed-off-by: Herbert Xu 
Signed-off-by: Sasha Levin 
---
 drivers/crypto/caam/regs.h | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h
index 84d2f838a063..b03e6f54ec14 100644
--- a/drivers/crypto/caam/regs.h
+++ b/drivers/crypto/caam/regs.h
@@ -68,22 +68,22 @@
 
 extern bool caam_little_end;
 
-#define caam_to_cpu(len)   \
-static inline u##len caam##len ## _to_cpu(u##len val)  \
-{  \
-   if (caam_little_end)\
-   return le##len ## _to_cpu(val); \
-   else\
-   return be##len ## _to_cpu(val); \
+#define caam_to_cpu(len)   \
+static inline u##len caam##len ## _to_cpu(u##len val)  \
+{  \
+   if (caam_little_end)\
+   return le##len ## _to_cpu((__force __le##len)val);  \
+   else\
+   return be##len ## _to_cpu((__force __be##len)val);  \
 }
 
-#define cpu_to_caam(len)   \
-static inline u##len cpu_to_caam##len(u##len val)  \
-{  \
-   if (caam_little_end)\
-   return cpu_to_le##len(val); \
-   else\
-   return cpu_to_be##len(val); \
+#define cpu_to_caam(len)   \
+static inline u##len cpu_to_caam##len(u##len val)  \
+{  \
+   if (caam_little_end)\
+   return (__force u##len)cpu_to_le##len(val); \
+   else\
+   return (__force u##len)cpu_to_be##len(val); \
 }
 
 caam_to_cpu(16)
-- 
2.17.1



[PATCH AUTOSEL 4.9 41/48] crypto: caam - fix implicit casts in endianness helpers

2018-10-31 Thread Sasha Levin
From: Horia Geantă 

[ Upstream commit aae733a3f46f5ef338fbdde26e14cbb205a23de0 ]

Fix the following sparse endianness warnings:

drivers/crypto/caam/regs.h:95:1: sparse: incorrect type in return expression 
(different base types) @@expected unsigned int @@got restricted 
__le32unsigned int @@
drivers/crypto/caam/regs.h:95:1:expected unsigned int
drivers/crypto/caam/regs.h:95:1:got restricted __le32 [usertype] 
drivers/crypto/caam/regs.h:95:1: sparse: incorrect type in return expression 
(different base types) @@expected unsigned int @@got restricted 
__be32unsigned int @@
drivers/crypto/caam/regs.h:95:1:expected unsigned int
drivers/crypto/caam/regs.h:95:1:got restricted __be32 [usertype] 

drivers/crypto/caam/regs.h:92:1: sparse: cast to restricted __le32
drivers/crypto/caam/regs.h:92:1: sparse: cast to restricted __be32

Fixes: 261ea058f016 ("crypto: caam - handle core endianness != caam endianness")
Reported-by: kbuild test robot 
Signed-off-by: Horia Geantă 
Signed-off-by: Herbert Xu 
Signed-off-by: Sasha Levin 
---
 drivers/crypto/caam/regs.h | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h
index 84d2f838a063..b03e6f54ec14 100644
--- a/drivers/crypto/caam/regs.h
+++ b/drivers/crypto/caam/regs.h
@@ -68,22 +68,22 @@
 
 extern bool caam_little_end;
 
-#define caam_to_cpu(len)   \
-static inline u##len caam##len ## _to_cpu(u##len val)  \
-{  \
-   if (caam_little_end)\
-   return le##len ## _to_cpu(val); \
-   else\
-   return be##len ## _to_cpu(val); \
+#define caam_to_cpu(len)   \
+static inline u##len caam##len ## _to_cpu(u##len val)  \
+{  \
+   if (caam_little_end)\
+   return le##len ## _to_cpu((__force __le##len)val);  \
+   else\
+   return be##len ## _to_cpu((__force __be##len)val);  \
 }
 
-#define cpu_to_caam(len)   \
-static inline u##len cpu_to_caam##len(u##len val)  \
-{  \
-   if (caam_little_end)\
-   return cpu_to_le##len(val); \
-   else\
-   return cpu_to_be##len(val); \
+#define cpu_to_caam(len)   \
+static inline u##len cpu_to_caam##len(u##len val)  \
+{  \
+   if (caam_little_end)\
+   return (__force u##len)cpu_to_le##len(val); \
+   else\
+   return (__force u##len)cpu_to_be##len(val); \
 }
 
 caam_to_cpu(16)
-- 
2.17.1



<    3   4   5   6   7   8   9   10   11   12   >