[PATCH AUTOSEL 4.19 089/146] MD: Memory leak when flush bio size is zero

2018-10-31 Thread Sasha Levin
From: Xiao Ni 

[ Upstream commit af9b926de9c5986ab009e64917de87c9758bab10 ]

flush_pool is leaked when flush bio size is zero

Fixes: 5a409b4f56d5 ("MD: fix lock contention for flush bios")
Signed-off-by: David Jeffery 
Signed-off-by: Xiao Ni 
Signed-off-by: Shaohua Li 
Signed-off-by: Sasha Levin 
---
 drivers/md/md.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 63ceabb4e020..06f68f19b5f3 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -452,10 +452,11 @@ static void md_end_flush(struct bio *fbio)
rdev_dec_pending(rdev, mddev);
 
if (atomic_dec_and_test(>flush_pending)) {
-   if (bio->bi_iter.bi_size == 0)
+   if (bio->bi_iter.bi_size == 0) {
/* an empty barrier - all done */
bio_endio(bio);
-   else {
+   mempool_free(fi, mddev->flush_pool);
+   } else {
INIT_WORK(>flush_work, submit_flushes);
queue_work(md_wq, >flush_work);
}
@@ -509,10 +510,11 @@ void md_flush_request(struct mddev *mddev, struct bio 
*bio)
rcu_read_unlock();
 
if (atomic_dec_and_test(>flush_pending)) {
-   if (bio->bi_iter.bi_size == 0)
+   if (bio->bi_iter.bi_size == 0) {
/* an empty barrier - all done */
bio_endio(bio);
-   else {
+   mempool_free(fi, mddev->flush_pool);
+   } else {
INIT_WORK(>flush_work, submit_flushes);
queue_work(md_wq, >flush_work);
}
-- 
2.17.1



[PATCH AUTOSEL 4.19 091/146] of: Add missing exports of node name compare functions

2018-10-31 Thread Sasha Levin
From: Rob Herring 

[ Upstream commit 173ee3962959a1985a109f81539a403b5cd07ae7 ]

Commit f42b0e18f2e5 ("of: add node name compare helper functions")
failed to add the module exports to of_node_name_eq() and
of_node_name_prefix(). Add them now.

Fixes: f42b0e18f2e5 ("of: add node name compare helper functions")
Signed-off-by: Rob Herring 
Signed-off-by: Sasha Levin 
---
 drivers/of/base.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 74eaedd5b860..70f5fd08891b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -67,6 +67,7 @@ bool of_node_name_eq(const struct device_node *np, const char 
*name)
 
return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);
 }
+EXPORT_SYMBOL(of_node_name_eq);
 
 bool of_node_name_prefix(const struct device_node *np, const char *prefix)
 {
@@ -75,6 +76,7 @@ bool of_node_name_prefix(const struct device_node *np, const 
char *prefix)
 
return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0;
 }
+EXPORT_SYMBOL(of_node_name_prefix);
 
 int of_n_addr_cells(struct device_node *np)
 {
-- 
2.17.1



[PATCH AUTOSEL 4.19 093/146] scsi: ufs: Schedule clk gating work on correct queue

2018-10-31 Thread Sasha Levin
From: Evan Green 

[ Upstream commit f4bb7704699beee9edfbee875daa9089c86cf724 ]

With commit 10e5e37581fc ("scsi: ufs: Add clock ungating to a separate
workqueue"), clock gating work was moved to a separate work queue with
WQ_MEM_RECLAIM set, since clock gating could occur from a memory reclaim
context. Unfortunately, clk_gating.gate_work was left queued via
schedule_delayed_work, which is a system workqueue that does not have
WQ_MEM_RECLAIM set.  Because ufshcd_ungate_work attempts to cancel
gate_work, the following warning appears:

[   14.174170] workqueue: WQ_MEM_RECLAIM ufs_clk_gating_0:ufshcd_ungate_work is 
flushing !WQ_MEM_RECLAIM events:ufshcd_gate_work
[   14.174179] WARNING: CPU: 4 PID: 173 at kernel/workqueue.c:2440 
check_flush_dependency+0x110/0x118
[   14.205725] CPU: 4 PID: 173 Comm: kworker/u16:3 Not tainted 4.14.68 #1
[   14.212437] Hardware name: Google Cheza (rev1) (DT)
[   14.217459] Workqueue: ufs_clk_gating_0 ufshcd_ungate_work
[   14.223107] task: ffc0f6a40080 task.stack: ff800a49
[   14.229195] PC is at check_flush_dependency+0x110/0x118
[   14.234569] LR is at check_flush_dependency+0x110/0x118
[   14.239944] pc : [] lr : [] pstate: 
60c001c9
[   14.333050] Call trace:
[   14.427767] [] check_flush_dependency+0x110/0x118
[   14.434219] [] start_flush_work+0xac/0x1fc
[   14.440046] [] flush_work+0x40/0x94
[   14.445246] [] __cancel_work_timer+0x11c/0x1b8
[   14.451433] [] cancel_delayed_work_sync+0x20/0x30
[   14.457886] [] ufshcd_ungate_work+0x24/0xd0
[   14.463800] [] process_one_work+0x32c/0x690
[   14.469713] [] worker_thread+0x218/0x338
[   14.475361] [] kthread+0x120/0x130
[   14.480470] [] ret_from_fork+0x10/0x18

The simple solution is to put the gate_work on the same WQ_MEM_RECLAIM
work queue as the ungate_work.

Fixes: 10e5e37581fc ("scsi: ufs: Add clock ungating to a separate workqueue")
Signed-off-by: Evan Green 
Reviewed-by: Douglas Anderson 
Reviewed-by: Stephen Boyd 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/ufs/ufshcd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index c55f38ec391c..54074dd483a7 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -1691,8 +1691,9 @@ static void __ufshcd_release(struct ufs_hba *hba)
 
hba->clk_gating.state = REQ_CLKS_OFF;
trace_ufshcd_clk_gating(dev_name(hba->dev), hba->clk_gating.state);
-   schedule_delayed_work(>clk_gating.gate_work,
-   msecs_to_jiffies(hba->clk_gating.delay_ms));
+   queue_delayed_work(hba->clk_gating.clk_gating_workq,
+  >clk_gating.gate_work,
+  msecs_to_jiffies(hba->clk_gating.delay_ms));
 }
 
 void ufshcd_release(struct ufs_hba *hba)
-- 
2.17.1



[PATCH AUTOSEL 4.19 098/146] RDMA/cm: Respect returned status of cm_init_av_by_path

2018-10-31 Thread Sasha Levin
From: Leon Romanovsky 

[ Upstream commit e54b6a3bcd1ec972b25a164bdf495d9e7120b107 ]

Add missing check for failure of cm_init_av_by_path

Fixes: e1444b5a163e ("IB/cm: Fix automatic path migration support")
Reported-by: Slava Shwartsman 
Reviewed-by: Parav Pandit 
Signed-off-by: Leon Romanovsky 
Signed-off-by: Jason Gunthorpe 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/core/cm.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 6e39c27dca8e..4c533275d1f2 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -3292,8 +3292,11 @@ static int cm_lap_handler(struct cm_work *work)
if (ret)
goto unlock;
 
-   cm_init_av_by_path(param->alternate_path, NULL, _id_priv->alt_av,
-  cm_id_priv);
+   ret = cm_init_av_by_path(param->alternate_path, NULL,
+_id_priv->alt_av, cm_id_priv);
+   if (ret)
+   goto unlock;
+
cm_id_priv->id.lap_state = IB_CM_LAP_RCVD;
cm_id_priv->tid = lap_msg->hdr.tid;
ret = atomic_inc_and_test(_id_priv->work_count);
-- 
2.17.1



[PATCH AUTOSEL 4.19 090/146] md: fix memleak for mempool

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

[ Upstream commit 6aaa58c994277647f8b05ffef3b9b225a2d08f36 ]

I noticed kmemleak report memory leak when run create/stop
md in a loop, backtrace:
[<1ca975e7>] mempool_create_node+0x86/0xd0
[<95576bcd>] md_run+0x1057/0x1410 [md_mod]
[<7b45c5fc>] do_md_run+0x15/0x130 [md_mod]
[<1ede9ec0>] md_ioctl+0x1f49/0x25d0 [md_mod]
[<4142cacf>] blkdev_ioctl+0x680/0xd00

The root cause is we alloc mddev->flush_pool and
mddev->flush_bio_pool in md_run, but from do_md_stop
will not call into md_stop but __md_stop, move the
mempool_destroy to __md_stop fixes the problem for me.

The bug was introduced in 5a409b4f56d5, the fixes should go to
4.18+

Fixes: 5a409b4f56d5 ("MD: fix lock contention for flush bios")
Signed-off-by: Jack Wang 
Reviewed-by: Xiao Ni 
Signed-off-by: Shaohua Li 
Signed-off-by: Sasha Levin 
---
 drivers/md/md.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 06f68f19b5f3..8668793262d0 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5906,14 +5906,6 @@ static void __md_stop(struct mddev *mddev)
mddev->to_remove = _redundancy_group;
module_put(pers->owner);
clear_bit(MD_RECOVERY_FROZEN, >recovery);
-}
-
-void md_stop(struct mddev *mddev)
-{
-   /* stop the array and free an attached data structures.
-* This is called from dm-raid
-*/
-   __md_stop(mddev);
if (mddev->flush_bio_pool) {
mempool_destroy(mddev->flush_bio_pool);
mddev->flush_bio_pool = NULL;
@@ -5922,6 +5914,14 @@ void md_stop(struct mddev *mddev)
mempool_destroy(mddev->flush_pool);
mddev->flush_pool = NULL;
}
+}
+
+void md_stop(struct mddev *mddev)
+{
+   /* stop the array and free an attached data structures.
+* This is called from dm-raid
+*/
+   __md_stop(mddev);
bioset_exit(>bio_set);
bioset_exit(>sync_set);
 }
-- 
2.17.1



[PATCH AUTOSEL 4.19 092/146] 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 c3fc34b9964d..9e5d3f7d29ae 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -1338,6 +1338,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 8163dca2071b..a2777a30 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 eb551f3cc471..71879f2207e0 100644
--- a/drivers/scsi/mac_esp.c
+++ b/drivers/scsi/mac_esp.c
@@ -427,6 +427,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.19 100/146] RDMA/bnxt_re: Avoid accessing nq->bar_reg_iomem in failure case

2018-10-31 Thread Sasha Levin
From: Selvin Xavier 

[ Upstream commit ed51efd2ce44091a858ad829f666727e7c95695e ]

In the failure path, nq->bar_reg_iomem gets accessed without
initializing. Avoid this by calling the bnxt_qplib_nq_stop_irq only if the
initialization is complete.

Reported-by: Dan Carpenter 
Fixes: 1ac5a4047975 ("RDMA/bnxt_re: Add bnxt_re RoCE driver")
Fixes: 6e04b1035689 ("RDMA/bnxt_re: Fix broken RoCE driver due to recent L2 
driver changes")
Signed-off-by: Selvin Xavier 
Signed-off-by: Jason Gunthorpe 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/hw/bnxt_re/qplib_fp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/bnxt_re/qplib_fp.c 
b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
index 6ad0d46ab879..249efa0a6aba 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_fp.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
@@ -360,7 +360,8 @@ void bnxt_qplib_disable_nq(struct bnxt_qplib_nq *nq)
}
 
/* Make sure the HW is stopped! */
-   bnxt_qplib_nq_stop_irq(nq, true);
+   if (nq->requested)
+   bnxt_qplib_nq_stop_irq(nq, true);
 
if (nq->bar_reg_iomem)
iounmap(nq->bar_reg_iomem);
-- 
2.17.1



[PATCH AUTOSEL 4.19 097/146] 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 7fd14ead7b37..ace40bb98624 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -512,7 +512,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:
@@ -1057,10 +1057,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);
@@ -1173,7 +1175,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);
@@ -1285,7 +1288,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.19 092/146] 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 c3fc34b9964d..9e5d3f7d29ae 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -1338,6 +1338,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 8163dca2071b..a2777a30 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 eb551f3cc471..71879f2207e0 100644
--- a/drivers/scsi/mac_esp.c
+++ b/drivers/scsi/mac_esp.c
@@ -427,6 +427,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.19 100/146] RDMA/bnxt_re: Avoid accessing nq->bar_reg_iomem in failure case

2018-10-31 Thread Sasha Levin
From: Selvin Xavier 

[ Upstream commit ed51efd2ce44091a858ad829f666727e7c95695e ]

In the failure path, nq->bar_reg_iomem gets accessed without
initializing. Avoid this by calling the bnxt_qplib_nq_stop_irq only if the
initialization is complete.

Reported-by: Dan Carpenter 
Fixes: 1ac5a4047975 ("RDMA/bnxt_re: Add bnxt_re RoCE driver")
Fixes: 6e04b1035689 ("RDMA/bnxt_re: Fix broken RoCE driver due to recent L2 
driver changes")
Signed-off-by: Selvin Xavier 
Signed-off-by: Jason Gunthorpe 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/hw/bnxt_re/qplib_fp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/bnxt_re/qplib_fp.c 
b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
index 6ad0d46ab879..249efa0a6aba 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_fp.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
@@ -360,7 +360,8 @@ void bnxt_qplib_disable_nq(struct bnxt_qplib_nq *nq)
}
 
/* Make sure the HW is stopped! */
-   bnxt_qplib_nq_stop_irq(nq, true);
+   if (nq->requested)
+   bnxt_qplib_nq_stop_irq(nq, true);
 
if (nq->bar_reg_iomem)
iounmap(nq->bar_reg_iomem);
-- 
2.17.1



[PATCH AUTOSEL 4.19 097/146] 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 7fd14ead7b37..ace40bb98624 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -512,7 +512,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:
@@ -1057,10 +1057,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);
@@ -1173,7 +1175,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);
@@ -1285,7 +1288,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.19 090/146] md: fix memleak for mempool

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

[ Upstream commit 6aaa58c994277647f8b05ffef3b9b225a2d08f36 ]

I noticed kmemleak report memory leak when run create/stop
md in a loop, backtrace:
[<1ca975e7>] mempool_create_node+0x86/0xd0
[<95576bcd>] md_run+0x1057/0x1410 [md_mod]
[<7b45c5fc>] do_md_run+0x15/0x130 [md_mod]
[<1ede9ec0>] md_ioctl+0x1f49/0x25d0 [md_mod]
[<4142cacf>] blkdev_ioctl+0x680/0xd00

The root cause is we alloc mddev->flush_pool and
mddev->flush_bio_pool in md_run, but from do_md_stop
will not call into md_stop but __md_stop, move the
mempool_destroy to __md_stop fixes the problem for me.

The bug was introduced in 5a409b4f56d5, the fixes should go to
4.18+

Fixes: 5a409b4f56d5 ("MD: fix lock contention for flush bios")
Signed-off-by: Jack Wang 
Reviewed-by: Xiao Ni 
Signed-off-by: Shaohua Li 
Signed-off-by: Sasha Levin 
---
 drivers/md/md.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 06f68f19b5f3..8668793262d0 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5906,14 +5906,6 @@ static void __md_stop(struct mddev *mddev)
mddev->to_remove = _redundancy_group;
module_put(pers->owner);
clear_bit(MD_RECOVERY_FROZEN, >recovery);
-}
-
-void md_stop(struct mddev *mddev)
-{
-   /* stop the array and free an attached data structures.
-* This is called from dm-raid
-*/
-   __md_stop(mddev);
if (mddev->flush_bio_pool) {
mempool_destroy(mddev->flush_bio_pool);
mddev->flush_bio_pool = NULL;
@@ -5922,6 +5914,14 @@ void md_stop(struct mddev *mddev)
mempool_destroy(mddev->flush_pool);
mddev->flush_pool = NULL;
}
+}
+
+void md_stop(struct mddev *mddev)
+{
+   /* stop the array and free an attached data structures.
+* This is called from dm-raid
+*/
+   __md_stop(mddev);
bioset_exit(>bio_set);
bioset_exit(>sync_set);
 }
-- 
2.17.1



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

2018-10-31 Thread Palmer Dabbelt
The following changes since commit d26c4bbf992463c043fdee4b3e5efa3f08990862:

  RISC-V: SMP cleanup and new features (2018-10-22 17:41:43 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/palmer/riscv-linux.git 
tags/riscv-for-linus-4.20-mw2

for you to fetch changes up to ef70696a63c773280ef46f5764a6cda39ef2f383:

  lib: Remove umoddi3 and udivmoddi4 (2018-10-31 12:13:54 -0700)


RISC-V Patches for the 4.20 Merge Window, Part 2 v2

This tag contains the follow-on patches I'd like to target for the 4.20
merge window.  I'm being somewhat conservative here, as while there are
a few patches on the mailing list that were posted early in the merge
window I'd like to let those bake for another round -- this was a fairly
big release as far as RISC-V is concerened, and we need to walk before
we can run.

As far as the patches that made it go:

* A patch to ignore offline CPUs when calculating AT_HWCAP.  This should
  fix GDB on the HiFive unleashed, which has an embedded core for hart
  0 which is exposed to Linux as an offline CPU.
* A move of EM_RISCV to elf-em.h, which is where it should have been to
  begin with.
* I've also removed the 64-bit divide routines.  I know I'm not really
  playing by my own rules here because I posted the patches this
  morning, but since they shouldn't be in the kernel I think it's better
  to err on the side of going too fast here.

I don't anticipate any more patch sets for the merge window.

Changes since v1:

* Use a consistent base to merge from so the history isn't a mess.


Andreas Schwab (1):
  RISC-V: properly determine hardware caps

Palmer Dabbelt (4):
  Revert "RISC-V: Select GENERIC_LIB_UMODDI3 on RV32"
  Revert "lib: Add umoddi3 and udivmoddi4 of GCC library routines"
  Move EM_RISCV into elf-em.h
  lib: Remove umoddi3 and udivmoddi4

 arch/riscv/Kconfig |   1 -
 arch/riscv/include/asm/elf.h   |   3 -
 arch/riscv/kernel/cpufeature.c |   8 +-
 include/uapi/linux/elf-em.h|   1 +
 lib/Kconfig|   3 -
 lib/Makefile   |   1 -
 lib/udivmoddi4.c   | 310 -
 lib/umoddi3.c  |  32 -
 8 files changed, 6 insertions(+), 353 deletions(-)
 delete mode 100644 lib/udivmoddi4.c
 delete mode 100644 lib/umoddi3.c


[PATCH AUTOSEL 4.19 102/146] usb: host: ohci-at91: fix request of irq for optional gpio

2018-10-31 Thread Sasha Levin
From: "tudor.amba...@microchip.com" 

[ Upstream commit 325b9313ec3be56c8e2fe03f977fee19cec75820 ]

atmel,oc-gpio is optional. Request its irq only when atmel,oc is set
in device tree.

devm_gpiod_get_index_optional returns NULL if -ENOENT. Check its
return value for NULL before error, because it is more probable that
atmel,oc is not set.

This fixes the following errors on boards where atmel,oc is not set in
device tree:
[0.96] at91_ohci 50.ohci: failed to request gpio "overcurrent" IRQ
[0.96] at91_ohci 50.ohci: failed to request gpio "overcurrent" IRQ
[0.97] at91_ohci 50.ohci: failed to request gpio "overcurrent" IRQ

Signed-off-by: Tudor Ambarus 
Acked-by: Nicolas Ferre 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/usb/host/ohci-at91.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index e98673954020..ec6739ef3129 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -551,6 +551,8 @@ static int ohci_hcd_at91_drv_probe(struct platform_device 
*pdev)
pdata->overcurrent_pin[i] =
devm_gpiod_get_index_optional(>dev, "atmel,oc",
  i, GPIOD_IN);
+   if (!pdata->overcurrent_pin[i])
+   continue;
if (IS_ERR(pdata->overcurrent_pin[i])) {
err = PTR_ERR(pdata->overcurrent_pin[i]);
dev_err(>dev, "unable to claim gpio 
\"overcurrent\": %d\n", err);
-- 
2.17.1



[PATCH AUTOSEL 4.19 102/146] usb: host: ohci-at91: fix request of irq for optional gpio

2018-10-31 Thread Sasha Levin
From: "tudor.amba...@microchip.com" 

[ Upstream commit 325b9313ec3be56c8e2fe03f977fee19cec75820 ]

atmel,oc-gpio is optional. Request its irq only when atmel,oc is set
in device tree.

devm_gpiod_get_index_optional returns NULL if -ENOENT. Check its
return value for NULL before error, because it is more probable that
atmel,oc is not set.

This fixes the following errors on boards where atmel,oc is not set in
device tree:
[0.96] at91_ohci 50.ohci: failed to request gpio "overcurrent" IRQ
[0.96] at91_ohci 50.ohci: failed to request gpio "overcurrent" IRQ
[0.97] at91_ohci 50.ohci: failed to request gpio "overcurrent" IRQ

Signed-off-by: Tudor Ambarus 
Acked-by: Nicolas Ferre 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/usb/host/ohci-at91.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index e98673954020..ec6739ef3129 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -551,6 +551,8 @@ static int ohci_hcd_at91_drv_probe(struct platform_device 
*pdev)
pdata->overcurrent_pin[i] =
devm_gpiod_get_index_optional(>dev, "atmel,oc",
  i, GPIOD_IN);
+   if (!pdata->overcurrent_pin[i])
+   continue;
if (IS_ERR(pdata->overcurrent_pin[i])) {
err = PTR_ERR(pdata->overcurrent_pin[i]);
dev_err(>dev, "unable to claim gpio 
\"overcurrent\": %d\n", err);
-- 
2.17.1



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

2018-10-31 Thread Palmer Dabbelt
The following changes since commit d26c4bbf992463c043fdee4b3e5efa3f08990862:

  RISC-V: SMP cleanup and new features (2018-10-22 17:41:43 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/palmer/riscv-linux.git 
tags/riscv-for-linus-4.20-mw2

for you to fetch changes up to ef70696a63c773280ef46f5764a6cda39ef2f383:

  lib: Remove umoddi3 and udivmoddi4 (2018-10-31 12:13:54 -0700)


RISC-V Patches for the 4.20 Merge Window, Part 2 v2

This tag contains the follow-on patches I'd like to target for the 4.20
merge window.  I'm being somewhat conservative here, as while there are
a few patches on the mailing list that were posted early in the merge
window I'd like to let those bake for another round -- this was a fairly
big release as far as RISC-V is concerened, and we need to walk before
we can run.

As far as the patches that made it go:

* A patch to ignore offline CPUs when calculating AT_HWCAP.  This should
  fix GDB on the HiFive unleashed, which has an embedded core for hart
  0 which is exposed to Linux as an offline CPU.
* A move of EM_RISCV to elf-em.h, which is where it should have been to
  begin with.
* I've also removed the 64-bit divide routines.  I know I'm not really
  playing by my own rules here because I posted the patches this
  morning, but since they shouldn't be in the kernel I think it's better
  to err on the side of going too fast here.

I don't anticipate any more patch sets for the merge window.

Changes since v1:

* Use a consistent base to merge from so the history isn't a mess.


Andreas Schwab (1):
  RISC-V: properly determine hardware caps

Palmer Dabbelt (4):
  Revert "RISC-V: Select GENERIC_LIB_UMODDI3 on RV32"
  Revert "lib: Add umoddi3 and udivmoddi4 of GCC library routines"
  Move EM_RISCV into elf-em.h
  lib: Remove umoddi3 and udivmoddi4

 arch/riscv/Kconfig |   1 -
 arch/riscv/include/asm/elf.h   |   3 -
 arch/riscv/kernel/cpufeature.c |   8 +-
 include/uapi/linux/elf-em.h|   1 +
 lib/Kconfig|   3 -
 lib/Makefile   |   1 -
 lib/udivmoddi4.c   | 310 -
 lib/umoddi3.c  |  32 -
 8 files changed, 6 insertions(+), 353 deletions(-)
 delete mode 100644 lib/udivmoddi4.c
 delete mode 100644 lib/umoddi3.c


[PATCH AUTOSEL 4.19 099/146] 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 3d5424f335cb..0428e01e8f69 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -1438,11 +1438,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.19 101/146] RDMA/bnxt_re: Fix recursive lock warning in debug kernel

2018-10-31 Thread Sasha Levin
From: Selvin Xavier 

[ Upstream commit d455f29f6d76a5f94881ca1289aaa1e90617ff5d ]

Fix possible recursive lock warning. Its a false warning as the locks are
part of two differnt HW Queue data structure - cmdq and creq. Debug kernel
is throwing the following warning and stack trace.

[  783.914967] 
[  783.914970] WARNING: possible recursive locking detected
[  783.914973] 4.19.0-rc2+ #33 Not tainted
[  783.914976] 
[  783.914979] swapper/2/0 is trying to acquire lock:
[  783.914982] 2aa3949d (&(>lock)->rlock){..-.}, at: 
bnxt_qplib_service_creq+0x232/0x350 [bnxt_re]
[  783.914999]
but task is already holding lock:
[  783.915002] be73920d (&(>lock)->rlock){..-.}, at: 
bnxt_qplib_service_creq+0x2a/0x350 [bnxt_re]
[  783.915013]
other info that might help us debug this:
[  783.915016]  Possible unsafe locking scenario:

[  783.915019]CPU0
[  783.915021]
[  783.915034]   lock(&(>lock)->rlock);
[  783.915035]   lock(&(>lock)->rlock);
[  783.915037]
 *** DEADLOCK ***

[  783.915038]  May be due to missing lock nesting notation

[  783.915039] 1 lock held by swapper/2/0:
[  783.915040]  #0: be73920d (&(>lock)->rlock){..-.}, at: 
bnxt_qplib_service_creq+0x2a/0x350 [bnxt_re]
[  783.915044]
stack backtrace:
[  783.915046] CPU: 2 PID: 0 Comm: swapper/2 Not tainted 4.19.0-rc2+ #33
[  783.915047] Hardware name: Dell Inc. PowerEdge R730/0599V5, BIOS 1.0.4 
08/28/2014
[  783.915048] Call Trace:
[  783.915049]  
[  783.915054]  dump_stack+0x90/0xe3
[  783.915058]  __lock_acquire+0x106c/0x1080
[  783.915061]  ? sched_clock+0x5/0x10
[  783.915063]  lock_acquire+0xbd/0x1a0
[  783.915065]  ? bnxt_qplib_service_creq+0x232/0x350 [bnxt_re]
[  783.915069]  _raw_spin_lock_irqsave+0x4a/0x90
[  783.915071]  ? bnxt_qplib_service_creq+0x232/0x350 [bnxt_re]
[  783.915073]  bnxt_qplib_service_creq+0x232/0x350 [bnxt_re]
[  783.915078]  tasklet_action_common.isra.17+0x197/0x1b0
[  783.915081]  __do_softirq+0xcb/0x3a6
[  783.915084]  irq_exit+0xe9/0x100
[  783.915085]  do_IRQ+0x6a/0x120
[  783.915087]  common_interrupt+0xf/0xf
[  783.915088]  

Use nested notation for the spin_lock to avoid this warning.

Signed-off-by: Selvin Xavier 
Signed-off-by: Jason Gunthorpe 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/hw/bnxt_re/qplib_rcfw.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c 
b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
index 2852d350ada1..6637df77d236 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
@@ -309,8 +309,17 @@ static int bnxt_qplib_process_qp_event(struct 
bnxt_qplib_rcfw *rcfw,
rcfw->aeq_handler(rcfw, qp_event, qp);
break;
default:
-   /* Command Response */
-   spin_lock_irqsave(>lock, flags);
+   /*
+* Command Response
+* cmdq->lock needs to be acquired to synchronie
+* the command send and completion reaping. This function
+* is always called with creq->lock held. Using
+* the nested variant of spin_lock.
+*
+*/
+
+   spin_lock_irqsave_nested(>lock, flags,
+SINGLE_DEPTH_NESTING);
cookie = le16_to_cpu(qp_event->cookie);
mcookie = qp_event->cookie;
blocked = cookie & RCFW_CMD_IS_BLOCKING;
-- 
2.17.1



[PATCH AUTOSEL 4.19 106/146] 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 1a803b0cf980..9f61106502a9 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -663,7 +663,8 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct 
tpm_space *space,
return len;
 
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);
if (err)
-- 
2.17.1



[PATCH AUTOSEL 4.19 104/146] PCI: cadence: Use AXI region 0 to signal interrupts from EP

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

[ Upstream commit 0652d4b6b56f73c81abbdbc7e26f772cb2dfe370 ]

The IRQ physical address is allocated from region 0, rather than
the highest region. Update the driver to reserve this region in
the bitmap and to use region 0 for all types of interrupt.

This corrects a problem which prevents the interrupt being
signalled correctly if using the first address in the AXI region,
since an offset of zero will always be mapped to region 0.

Fixes: 37dddf14f1ae ("PCI: cadence: Add EndPoint Controller driver for Cadence 
PCIe controller")
Signed-off-by: Alan Douglas 
Signed-off-by: Lorenzo Pieralisi 
Signed-off-by: Sasha Levin 
---
 drivers/pci/controller/pcie-cadence-ep.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/controller/pcie-cadence-ep.c 
b/drivers/pci/controller/pcie-cadence-ep.c
index 9e87dd7f9ac3..6692654798d4 100644
--- a/drivers/pci/controller/pcie-cadence-ep.c
+++ b/drivers/pci/controller/pcie-cadence-ep.c
@@ -258,7 +258,6 @@ static void cdns_pcie_ep_assert_intx(struct cdns_pcie_ep 
*ep, u8 fn,
 u8 intx, bool is_asserted)
 {
struct cdns_pcie *pcie = >pcie;
-   u32 r = ep->max_regions - 1;
u32 offset;
u16 status;
u8 msg_code;
@@ -268,8 +267,8 @@ static void cdns_pcie_ep_assert_intx(struct cdns_pcie_ep 
*ep, u8 fn,
/* Set the outbound region if needed. */
if (unlikely(ep->irq_pci_addr != CDNS_PCIE_EP_IRQ_PCI_ADDR_LEGACY ||
 ep->irq_pci_fn != fn)) {
-   /* Last region was reserved for IRQ writes. */
-   cdns_pcie_set_outbound_region_for_normal_msg(pcie, fn, r,
+   /* First region was reserved for IRQ writes. */
+   cdns_pcie_set_outbound_region_for_normal_msg(pcie, fn, 0,
 ep->irq_phys_addr);
ep->irq_pci_addr = CDNS_PCIE_EP_IRQ_PCI_ADDR_LEGACY;
ep->irq_pci_fn = fn;
@@ -347,8 +346,8 @@ static int cdns_pcie_ep_send_msi_irq(struct cdns_pcie_ep 
*ep, u8 fn,
/* Set the outbound region if needed. */
if (unlikely(ep->irq_pci_addr != (pci_addr & ~pci_addr_mask) ||
 ep->irq_pci_fn != fn)) {
-   /* Last region was reserved for IRQ writes. */
-   cdns_pcie_set_outbound_region(pcie, fn, ep->max_regions - 1,
+   /* First region was reserved for IRQ writes. */
+   cdns_pcie_set_outbound_region(pcie, fn, 0,
  false,
  ep->irq_phys_addr,
  pci_addr & ~pci_addr_mask,
@@ -517,6 +516,8 @@ static int cdns_pcie_ep_probe(struct platform_device *pdev)
goto free_epc_mem;
}
ep->irq_pci_addr = CDNS_PCIE_EP_IRQ_PCI_ADDR_NONE;
+   /* Reserve region 0 for IRQs */
+   set_bit(0, >ob_region_map);
 
return 0;
 
-- 
2.17.1



[PATCH AUTOSEL 4.19 107/146] f2fs: clear PageError on the read path

2018-10-31 Thread Sasha Levin
From: Jaegeuk Kim 

[ Upstream commit fb7d70db305a1446864227abf711b756568f8242 ]

When running fault injection test, I hit somewhat wrong behavior in f2fs_gc ->
gc_data_segment():

0. fault injection generated some PageError'ed pages

1. gc_data_segment
 -> f2fs_get_read_data_page(REQ_RAHEAD)

2. move_data_page
 -> f2fs_get_lock_data_page()
  -> f2f_get_read_data_page()
   -> f2fs_submit_page_read()
-> submit_bio(READ)
  -> return EIO due to PageError
  -> fail to move data

Signed-off-by: Jaegeuk Kim 
Signed-off-by: Sasha Levin 
---
 fs/f2fs/data.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index cd5d53353a61..f79fb3aa5ae3 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -80,7 +80,8 @@ static void __read_end_io(struct bio *bio)
/* PG_error was set if any post_read step failed */
if (bio->bi_status || PageError(page)) {
ClearPageUptodate(page);
-   SetPageError(page);
+   /* will re-read again later */
+   ClearPageError(page);
} else {
SetPageUptodate(page);
}
@@ -590,6 +591,7 @@ static int f2fs_submit_page_read(struct inode *inode, 
struct page *page,
bio_put(bio);
return -EFAULT;
}
+   ClearPageError(page);
__submit_bio(F2FS_I_SB(inode), bio, DATA);
return 0;
 }
@@ -1565,6 +1567,7 @@ static int f2fs_mpage_readpages(struct address_space 
*mapping,
if (bio_add_page(bio, page, blocksize, 0) < blocksize)
goto submit_and_realloc;
 
+   ClearPageError(page);
last_block_in_bio = block_nr;
goto next_page;
 set_error_page:
-- 
2.17.1



[PATCH AUTOSEL 4.19 099/146] 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 3d5424f335cb..0428e01e8f69 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -1438,11 +1438,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.19 101/146] RDMA/bnxt_re: Fix recursive lock warning in debug kernel

2018-10-31 Thread Sasha Levin
From: Selvin Xavier 

[ Upstream commit d455f29f6d76a5f94881ca1289aaa1e90617ff5d ]

Fix possible recursive lock warning. Its a false warning as the locks are
part of two differnt HW Queue data structure - cmdq and creq. Debug kernel
is throwing the following warning and stack trace.

[  783.914967] 
[  783.914970] WARNING: possible recursive locking detected
[  783.914973] 4.19.0-rc2+ #33 Not tainted
[  783.914976] 
[  783.914979] swapper/2/0 is trying to acquire lock:
[  783.914982] 2aa3949d (&(>lock)->rlock){..-.}, at: 
bnxt_qplib_service_creq+0x232/0x350 [bnxt_re]
[  783.914999]
but task is already holding lock:
[  783.915002] be73920d (&(>lock)->rlock){..-.}, at: 
bnxt_qplib_service_creq+0x2a/0x350 [bnxt_re]
[  783.915013]
other info that might help us debug this:
[  783.915016]  Possible unsafe locking scenario:

[  783.915019]CPU0
[  783.915021]
[  783.915034]   lock(&(>lock)->rlock);
[  783.915035]   lock(&(>lock)->rlock);
[  783.915037]
 *** DEADLOCK ***

[  783.915038]  May be due to missing lock nesting notation

[  783.915039] 1 lock held by swapper/2/0:
[  783.915040]  #0: be73920d (&(>lock)->rlock){..-.}, at: 
bnxt_qplib_service_creq+0x2a/0x350 [bnxt_re]
[  783.915044]
stack backtrace:
[  783.915046] CPU: 2 PID: 0 Comm: swapper/2 Not tainted 4.19.0-rc2+ #33
[  783.915047] Hardware name: Dell Inc. PowerEdge R730/0599V5, BIOS 1.0.4 
08/28/2014
[  783.915048] Call Trace:
[  783.915049]  
[  783.915054]  dump_stack+0x90/0xe3
[  783.915058]  __lock_acquire+0x106c/0x1080
[  783.915061]  ? sched_clock+0x5/0x10
[  783.915063]  lock_acquire+0xbd/0x1a0
[  783.915065]  ? bnxt_qplib_service_creq+0x232/0x350 [bnxt_re]
[  783.915069]  _raw_spin_lock_irqsave+0x4a/0x90
[  783.915071]  ? bnxt_qplib_service_creq+0x232/0x350 [bnxt_re]
[  783.915073]  bnxt_qplib_service_creq+0x232/0x350 [bnxt_re]
[  783.915078]  tasklet_action_common.isra.17+0x197/0x1b0
[  783.915081]  __do_softirq+0xcb/0x3a6
[  783.915084]  irq_exit+0xe9/0x100
[  783.915085]  do_IRQ+0x6a/0x120
[  783.915087]  common_interrupt+0xf/0xf
[  783.915088]  

Use nested notation for the spin_lock to avoid this warning.

Signed-off-by: Selvin Xavier 
Signed-off-by: Jason Gunthorpe 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/hw/bnxt_re/qplib_rcfw.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c 
b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
index 2852d350ada1..6637df77d236 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
@@ -309,8 +309,17 @@ static int bnxt_qplib_process_qp_event(struct 
bnxt_qplib_rcfw *rcfw,
rcfw->aeq_handler(rcfw, qp_event, qp);
break;
default:
-   /* Command Response */
-   spin_lock_irqsave(>lock, flags);
+   /*
+* Command Response
+* cmdq->lock needs to be acquired to synchronie
+* the command send and completion reaping. This function
+* is always called with creq->lock held. Using
+* the nested variant of spin_lock.
+*
+*/
+
+   spin_lock_irqsave_nested(>lock, flags,
+SINGLE_DEPTH_NESTING);
cookie = le16_to_cpu(qp_event->cookie);
mcookie = qp_event->cookie;
blocked = cookie & RCFW_CMD_IS_BLOCKING;
-- 
2.17.1



[PATCH AUTOSEL 4.19 106/146] 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 1a803b0cf980..9f61106502a9 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -663,7 +663,8 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct 
tpm_space *space,
return len;
 
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);
if (err)
-- 
2.17.1



[PATCH AUTOSEL 4.19 104/146] PCI: cadence: Use AXI region 0 to signal interrupts from EP

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

[ Upstream commit 0652d4b6b56f73c81abbdbc7e26f772cb2dfe370 ]

The IRQ physical address is allocated from region 0, rather than
the highest region. Update the driver to reserve this region in
the bitmap and to use region 0 for all types of interrupt.

This corrects a problem which prevents the interrupt being
signalled correctly if using the first address in the AXI region,
since an offset of zero will always be mapped to region 0.

Fixes: 37dddf14f1ae ("PCI: cadence: Add EndPoint Controller driver for Cadence 
PCIe controller")
Signed-off-by: Alan Douglas 
Signed-off-by: Lorenzo Pieralisi 
Signed-off-by: Sasha Levin 
---
 drivers/pci/controller/pcie-cadence-ep.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/controller/pcie-cadence-ep.c 
b/drivers/pci/controller/pcie-cadence-ep.c
index 9e87dd7f9ac3..6692654798d4 100644
--- a/drivers/pci/controller/pcie-cadence-ep.c
+++ b/drivers/pci/controller/pcie-cadence-ep.c
@@ -258,7 +258,6 @@ static void cdns_pcie_ep_assert_intx(struct cdns_pcie_ep 
*ep, u8 fn,
 u8 intx, bool is_asserted)
 {
struct cdns_pcie *pcie = >pcie;
-   u32 r = ep->max_regions - 1;
u32 offset;
u16 status;
u8 msg_code;
@@ -268,8 +267,8 @@ static void cdns_pcie_ep_assert_intx(struct cdns_pcie_ep 
*ep, u8 fn,
/* Set the outbound region if needed. */
if (unlikely(ep->irq_pci_addr != CDNS_PCIE_EP_IRQ_PCI_ADDR_LEGACY ||
 ep->irq_pci_fn != fn)) {
-   /* Last region was reserved for IRQ writes. */
-   cdns_pcie_set_outbound_region_for_normal_msg(pcie, fn, r,
+   /* First region was reserved for IRQ writes. */
+   cdns_pcie_set_outbound_region_for_normal_msg(pcie, fn, 0,
 ep->irq_phys_addr);
ep->irq_pci_addr = CDNS_PCIE_EP_IRQ_PCI_ADDR_LEGACY;
ep->irq_pci_fn = fn;
@@ -347,8 +346,8 @@ static int cdns_pcie_ep_send_msi_irq(struct cdns_pcie_ep 
*ep, u8 fn,
/* Set the outbound region if needed. */
if (unlikely(ep->irq_pci_addr != (pci_addr & ~pci_addr_mask) ||
 ep->irq_pci_fn != fn)) {
-   /* Last region was reserved for IRQ writes. */
-   cdns_pcie_set_outbound_region(pcie, fn, ep->max_regions - 1,
+   /* First region was reserved for IRQ writes. */
+   cdns_pcie_set_outbound_region(pcie, fn, 0,
  false,
  ep->irq_phys_addr,
  pci_addr & ~pci_addr_mask,
@@ -517,6 +516,8 @@ static int cdns_pcie_ep_probe(struct platform_device *pdev)
goto free_epc_mem;
}
ep->irq_pci_addr = CDNS_PCIE_EP_IRQ_PCI_ADDR_NONE;
+   /* Reserve region 0 for IRQs */
+   set_bit(0, >ob_region_map);
 
return 0;
 
-- 
2.17.1



[PATCH AUTOSEL 4.19 107/146] f2fs: clear PageError on the read path

2018-10-31 Thread Sasha Levin
From: Jaegeuk Kim 

[ Upstream commit fb7d70db305a1446864227abf711b756568f8242 ]

When running fault injection test, I hit somewhat wrong behavior in f2fs_gc ->
gc_data_segment():

0. fault injection generated some PageError'ed pages

1. gc_data_segment
 -> f2fs_get_read_data_page(REQ_RAHEAD)

2. move_data_page
 -> f2fs_get_lock_data_page()
  -> f2f_get_read_data_page()
   -> f2fs_submit_page_read()
-> submit_bio(READ)
  -> return EIO due to PageError
  -> fail to move data

Signed-off-by: Jaegeuk Kim 
Signed-off-by: Sasha Levin 
---
 fs/f2fs/data.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index cd5d53353a61..f79fb3aa5ae3 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -80,7 +80,8 @@ static void __read_end_io(struct bio *bio)
/* PG_error was set if any post_read step failed */
if (bio->bi_status || PageError(page)) {
ClearPageUptodate(page);
-   SetPageError(page);
+   /* will re-read again later */
+   ClearPageError(page);
} else {
SetPageUptodate(page);
}
@@ -590,6 +591,7 @@ static int f2fs_submit_page_read(struct inode *inode, 
struct page *page,
bio_put(bio);
return -EFAULT;
}
+   ClearPageError(page);
__submit_bio(F2FS_I_SB(inode), bio, DATA);
return 0;
 }
@@ -1565,6 +1567,7 @@ static int f2fs_mpage_readpages(struct address_space 
*mapping,
if (bio_add_page(bio, page, blocksize, 0) < blocksize)
goto submit_and_realloc;
 
+   ClearPageError(page);
last_block_in_bio = block_nr;
goto next_page;
 set_error_page:
-- 
2.17.1



[PATCH AUTOSEL 4.19 109/146] 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 5eed1e7da15c..57715a0c8120 100644
--- a/drivers/hv/hv_kvp.c
+++ b/drivers/hv/hv_kvp.c
@@ -353,7 +353,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,
@@ -406,7 +405,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) {
@@ -446,6 +445,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.19 109/146] 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 5eed1e7da15c..57715a0c8120 100644
--- a/drivers/hv/hv_kvp.c
+++ b/drivers/hv/hv_kvp.c
@@ -353,7 +353,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,
@@ -406,7 +405,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) {
@@ -446,6 +445,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.19 113/146] irqchip/pdc: Setup all edge interrupts as rising edge at GIC

2018-10-31 Thread Sasha Levin
From: Lina Iyer 

[ Upstream commit 7bae48b22c8d38c5cd50f52b6e15d134e2bb3935 ]

The PDC irqchp can convert a falling edge or level low interrupt to a
rising edge or level high interrupt at the GIC. We just need to setup
the GIC correctly. Set up the interrupt type for the IRQ_TYPE_EDGE_BOTH
as IRQ_TYPE_EDGE_RISING at the GIC.

Fixes: f55c73aef890 ("irqchip/pdc: Add PDC interrupt controller for QCOM SoCs")
Reported-by: Evan Green 
Reviewed-by: Evan Green 
Signed-off-by: Lina Iyer 
Signed-off-by: Marc Zyngier 
Signed-off-by: Sasha Levin 
---
 drivers/irqchip/qcom-pdc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/irqchip/qcom-pdc.c b/drivers/irqchip/qcom-pdc.c
index b1b47a40a278..faa7d61b9d6c 100644
--- a/drivers/irqchip/qcom-pdc.c
+++ b/drivers/irqchip/qcom-pdc.c
@@ -124,6 +124,7 @@ static int qcom_pdc_gic_set_type(struct irq_data *d, 
unsigned int type)
break;
case IRQ_TYPE_EDGE_BOTH:
pdc_type = PDC_EDGE_DUAL;
+   type = IRQ_TYPE_EDGE_RISING;
break;
case IRQ_TYPE_LEVEL_HIGH:
pdc_type = PDC_LEVEL_HIGH;
-- 
2.17.1



[PATCH AUTOSEL 4.19 115/146] usb: dwc2: fix a race with external vbus supply

2018-10-31 Thread Sasha Levin
From: Fabrice Gasnier 

[ Upstream commit 41ee1ea21052583eaf5487dfa0d0c907c9667548 ]

There's a race with root hub resume, when using external vbus supply.
Root hub gets resumed, but runtime pm autosuspend runs as external vbus
supply isn't enabled. So, host never exit from power down properly.
Initialize vbus external supply before, rater that after hub resume.

Fixes: 531ef5ebea96 ("usb: dwc2: add support for host mode external
vbus supply")

Tested-by: Artur Petrosyan 
Acked-by: Minas Harutyunyan 
Signed-off-by: Fabrice Gasnier 
Signed-off-by: Amelie Delaunay 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
---
 drivers/usb/dwc2/hcd.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index befaf1e9d98a..260010abf9d8 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4393,6 +4393,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
struct usb_bus *bus = hcd_to_bus(hcd);
unsigned long flags;
+   int ret;
 
dev_dbg(hsotg->dev, "DWC OTG HCD START\n");
 
@@ -4408,6 +4409,13 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
 
dwc2_hcd_reinit(hsotg);
 
+   /* enable external vbus supply before resuming root hub */
+   spin_unlock_irqrestore(>lock, flags);
+   ret = dwc2_vbus_supply_init(hsotg);
+   if (ret)
+   return ret;
+   spin_lock_irqsave(>lock, flags);
+
/* Initialize and connect root hub if one is not already attached */
if (bus->root_hub) {
dev_dbg(hsotg->dev, "DWC OTG HCD Has Root Hub\n");
@@ -4417,7 +4425,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
 
spin_unlock_irqrestore(>lock, flags);
 
-   return dwc2_vbus_supply_init(hsotg);
+   return 0;
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.19 114/146] usb: dwc2: fix call to vbus supply exit routine, call it unlocked

2018-10-31 Thread Sasha Levin
From: Fabrice Gasnier 

[ Upstream commit 5aa678c7fd5371769efde30763fb43a43a118cd0 ]

dwc2_vbus_supply_exit() may call regulator_disable(). It shouldn't be
called with interrupts disabled as it might sleep.
This is seen with DEBUG_ATOMIC_SLEEP=y.

Fixes: 531ef5ebea96 ("usb: dwc2: add support for host mode external
vbus supply")

Tested-by: Artur Petrosyan 
Acked-by: Minas Harutyunyan 
Signed-off-by: Fabrice Gasnier 
Signed-off-by: Amelie Delaunay 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
---
 drivers/usb/dwc2/hcd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 2bd6e6bfc241..befaf1e9d98a 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4482,7 +4482,9 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
hprt0 |= HPRT0_SUSP;
hprt0 &= ~HPRT0_PWR;
dwc2_writel(hsotg, hprt0, HPRT0);
+   spin_unlock_irqrestore(>lock, flags);
dwc2_vbus_supply_exit(hsotg);
+   spin_lock_irqsave(>lock, flags);
}
 
/* Enter partial_power_down */
-- 
2.17.1



[PATCH AUTOSEL 4.19 117/146] 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 a409ff70d67b..2f5be02fc6f6 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -516,9 +516,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.19 113/146] irqchip/pdc: Setup all edge interrupts as rising edge at GIC

2018-10-31 Thread Sasha Levin
From: Lina Iyer 

[ Upstream commit 7bae48b22c8d38c5cd50f52b6e15d134e2bb3935 ]

The PDC irqchp can convert a falling edge or level low interrupt to a
rising edge or level high interrupt at the GIC. We just need to setup
the GIC correctly. Set up the interrupt type for the IRQ_TYPE_EDGE_BOTH
as IRQ_TYPE_EDGE_RISING at the GIC.

Fixes: f55c73aef890 ("irqchip/pdc: Add PDC interrupt controller for QCOM SoCs")
Reported-by: Evan Green 
Reviewed-by: Evan Green 
Signed-off-by: Lina Iyer 
Signed-off-by: Marc Zyngier 
Signed-off-by: Sasha Levin 
---
 drivers/irqchip/qcom-pdc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/irqchip/qcom-pdc.c b/drivers/irqchip/qcom-pdc.c
index b1b47a40a278..faa7d61b9d6c 100644
--- a/drivers/irqchip/qcom-pdc.c
+++ b/drivers/irqchip/qcom-pdc.c
@@ -124,6 +124,7 @@ static int qcom_pdc_gic_set_type(struct irq_data *d, 
unsigned int type)
break;
case IRQ_TYPE_EDGE_BOTH:
pdc_type = PDC_EDGE_DUAL;
+   type = IRQ_TYPE_EDGE_RISING;
break;
case IRQ_TYPE_LEVEL_HIGH:
pdc_type = PDC_LEVEL_HIGH;
-- 
2.17.1



[PATCH AUTOSEL 4.19 115/146] usb: dwc2: fix a race with external vbus supply

2018-10-31 Thread Sasha Levin
From: Fabrice Gasnier 

[ Upstream commit 41ee1ea21052583eaf5487dfa0d0c907c9667548 ]

There's a race with root hub resume, when using external vbus supply.
Root hub gets resumed, but runtime pm autosuspend runs as external vbus
supply isn't enabled. So, host never exit from power down properly.
Initialize vbus external supply before, rater that after hub resume.

Fixes: 531ef5ebea96 ("usb: dwc2: add support for host mode external
vbus supply")

Tested-by: Artur Petrosyan 
Acked-by: Minas Harutyunyan 
Signed-off-by: Fabrice Gasnier 
Signed-off-by: Amelie Delaunay 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
---
 drivers/usb/dwc2/hcd.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index befaf1e9d98a..260010abf9d8 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4393,6 +4393,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
struct usb_bus *bus = hcd_to_bus(hcd);
unsigned long flags;
+   int ret;
 
dev_dbg(hsotg->dev, "DWC OTG HCD START\n");
 
@@ -4408,6 +4409,13 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
 
dwc2_hcd_reinit(hsotg);
 
+   /* enable external vbus supply before resuming root hub */
+   spin_unlock_irqrestore(>lock, flags);
+   ret = dwc2_vbus_supply_init(hsotg);
+   if (ret)
+   return ret;
+   spin_lock_irqsave(>lock, flags);
+
/* Initialize and connect root hub if one is not already attached */
if (bus->root_hub) {
dev_dbg(hsotg->dev, "DWC OTG HCD Has Root Hub\n");
@@ -4417,7 +4425,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
 
spin_unlock_irqrestore(>lock, flags);
 
-   return dwc2_vbus_supply_init(hsotg);
+   return 0;
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.19 114/146] usb: dwc2: fix call to vbus supply exit routine, call it unlocked

2018-10-31 Thread Sasha Levin
From: Fabrice Gasnier 

[ Upstream commit 5aa678c7fd5371769efde30763fb43a43a118cd0 ]

dwc2_vbus_supply_exit() may call regulator_disable(). It shouldn't be
called with interrupts disabled as it might sleep.
This is seen with DEBUG_ATOMIC_SLEEP=y.

Fixes: 531ef5ebea96 ("usb: dwc2: add support for host mode external
vbus supply")

Tested-by: Artur Petrosyan 
Acked-by: Minas Harutyunyan 
Signed-off-by: Fabrice Gasnier 
Signed-off-by: Amelie Delaunay 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
---
 drivers/usb/dwc2/hcd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 2bd6e6bfc241..befaf1e9d98a 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4482,7 +4482,9 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
hprt0 |= HPRT0_SUSP;
hprt0 &= ~HPRT0_PWR;
dwc2_writel(hsotg, hprt0, HPRT0);
+   spin_unlock_irqrestore(>lock, flags);
dwc2_vbus_supply_exit(hsotg);
+   spin_lock_irqsave(>lock, flags);
}
 
/* Enter partial_power_down */
-- 
2.17.1



[PATCH AUTOSEL 4.19 117/146] 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 a409ff70d67b..2f5be02fc6f6 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -516,9 +516,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.19 119/146] PCI: cadence: Correct probe behaviour when failing to get PHY

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

[ Upstream commit aa77e55d48124d0d78456eabf872fffb5decdbe1 ]

Test the correct value to see whether the PHY get failed.

Use devm_phy_get() instead of devm_phy_optional_get(), since it is
only called if phy name is given in devicetree and so should exist.
If failure when getting or linking PHY, put any PHYs which were
already got and unlink them.

Fixes: dfb80534692ddc5b ("PCI: cadence: Add generic PHY support to host and EP 
drivers")
Reported-by: Colin King 
Signed-off-by: Alan Douglas 
Signed-off-by: Lorenzo Pieralisi 
Signed-off-by: Sasha Levin 
---
 drivers/pci/controller/pcie-cadence.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/controller/pcie-cadence.c 
b/drivers/pci/controller/pcie-cadence.c
index 975bcdd6b5c0..cd795f6fc1e2 100644
--- a/drivers/pci/controller/pcie-cadence.c
+++ b/drivers/pci/controller/pcie-cadence.c
@@ -190,14 +190,16 @@ int cdns_pcie_init_phy(struct device *dev, struct 
cdns_pcie *pcie)
 
for (i = 0; i < phy_count; i++) {
of_property_read_string_index(np, "phy-names", i, );
-   phy[i] = devm_phy_optional_get(dev, name);
-   if (IS_ERR(phy))
-   return PTR_ERR(phy);
-
+   phy[i] = devm_phy_get(dev, name);
+   if (IS_ERR(phy[i])) {
+   ret = PTR_ERR(phy[i]);
+   goto err_phy;
+   }
link[i] = device_link_add(dev, [i]->dev, DL_FLAG_STATELESS);
if (!link[i]) {
+   devm_phy_put(dev, phy[i]);
ret = -EINVAL;
-   goto err_link;
+   goto err_phy;
}
}
 
@@ -207,13 +209,15 @@ int cdns_pcie_init_phy(struct device *dev, struct 
cdns_pcie *pcie)
 
ret =  cdns_pcie_enable_phy(pcie);
if (ret)
-   goto err_link;
+   goto err_phy;
 
return 0;
 
-err_link:
-   while (--i >= 0)
+err_phy:
+   while (--i >= 0) {
device_link_del(link[i]);
+   devm_phy_put(dev, phy[i]);
+   }
 
return ret;
 }
-- 
2.17.1



[PATCH AUTOSEL 4.19 116/146] 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 17147b8c771e..8f267be1745d 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -2017,6 +2017,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.19 112/146] xprtrdma: Reset credit grant properly after a disconnect

2018-10-31 Thread Sasha Levin
From: Chuck Lever 

[ Upstream commit ef739b2175dde9c05594f768cb78149f1ce2ac36 ]

On a fresh connection, an RPC/RDMA client is supposed to send only
one RPC Call until it gets a credit grant in the first RPC Reply
from the server [RFC 8166, Section 3.3.3].

There is a bug in the Linux client's credit accounting mechanism
introduced by commit e7ce710a8802 ("xprtrdma: Avoid deadlock when
credit window is reset"). On connect, it simply dumps all pending
RPC Calls onto the new connection.

Servers have been tolerant of this bad behavior. Currently no server
implementation ever changes its credit grant over reconnects, and
servers always repost enough Receives before connections are fully
established.

To correct this issue, ensure that the client resets both the credit
grant _and_ the congestion window when handling a reconnect.

Fixes: e7ce710a8802 ("xprtrdma: Avoid deadlock when credit ... ")
Signed-off-by: Chuck Lever 
Cc: sta...@kernel.org
Signed-off-by: Anna Schumaker 
Signed-off-by: Sasha Levin 
---
 net/sunrpc/xprtrdma/svc_rdma_backchannel.c | 1 +
 net/sunrpc/xprtrdma/transport.c| 6 ++
 2 files changed, 7 insertions(+)

diff --git a/net/sunrpc/xprtrdma/svc_rdma_backchannel.c 
b/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
index a68180090554..b9827665ff35 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
@@ -248,6 +248,7 @@ static void
 xprt_rdma_bc_close(struct rpc_xprt *xprt)
 {
dprintk("svcrdma: %s: xprt %p\n", __func__, xprt);
+   xprt->cwnd = RPC_CWNDSHIFT;
 }
 
 static void
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 143ce2579ba9..98cbc7b060ba 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -468,6 +468,12 @@ xprt_rdma_close(struct rpc_xprt *xprt)
xprt->reestablish_timeout = 0;
xprt_disconnect_done(xprt);
rpcrdma_ep_disconnect(ep, ia);
+
+   /* Prepare @xprt for the next connection by reinitializing
+* its credit grant to one (see RFC 8166, Section 3.3.3).
+*/
+   r_xprt->rx_buf.rb_credits = 1;
+   xprt->cwnd = RPC_CWNDSHIFT;
 }
 
 /**
-- 
2.17.1



[PATCH AUTOSEL 4.19 111/146] PCI / ACPI: Enable wake automatically for power managed bridges

2018-10-31 Thread Sasha Levin
From: Mika Westerberg 

[ Upstream commit 6299cf9ec3985cac70bede8a855b5087b81a6640 ]

We enable power management automatically for bridges where
pci_bridge_d3_possible() returns true. However, these bridges may have
ACPI methods such as _DSW that need to be called before D3 entry. For
example in Lenovo Thinkpad X1 Carbon 6th _DSW method is used to prepare
D3cold for the PCIe root port hosting Thunderbolt chain. Because wake is
not enabled _DSW method is never called and the port does not enter
D3cold properly consuming more power than necessary.

Users can work this around by writing "enabled" to "wakeup" sysfs file
under the device in question but that is not something an ordinary user
is expected to do.

Since we already automatically enable power management for PCIe ports
with ->bridge_d3 set extend that to enable wake for them as well,
assuming the port has any ACPI wakeup related objects implemented in the
namespace (adev->wakeup.flags.valid is true). This ensures the necessary
ACPI methods get called at appropriate times and allows the root port in
Thinkpad X1 Carbon 6th to go into D3cold.

Signed-off-by: Mika Westerberg 
Signed-off-by: Bjorn Helgaas 
Reviewed-by: Rafael J. Wysocki 
Signed-off-by: Sasha Levin 
---
 drivers/pci/pci-acpi.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index c2ab57705043..f8436d1c4d45 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -762,19 +762,33 @@ static void pci_acpi_setup(struct device *dev)
return;
 
device_set_wakeup_capable(dev, true);
+   /*
+* For bridges that can do D3 we enable wake automatically (as
+* we do for the power management itself in that case). The
+* reason is that the bridge may have additional methods such as
+* _DSW that need to be called.
+*/
+   if (pci_dev->bridge_d3)
+   device_wakeup_enable(dev);
+
acpi_pci_wakeup(pci_dev, false);
 }
 
 static void pci_acpi_cleanup(struct device *dev)
 {
struct acpi_device *adev = ACPI_COMPANION(dev);
+   struct pci_dev *pci_dev = to_pci_dev(dev);
 
if (!adev)
return;
 
pci_acpi_remove_pm_notifier(adev);
-   if (adev->wakeup.flags.valid)
+   if (adev->wakeup.flags.valid) {
+   if (pci_dev->bridge_d3)
+   device_wakeup_disable(dev);
+
device_set_wakeup_capable(dev, false);
+   }
 }
 
 static bool pci_acpi_bus_match(struct device *dev)
-- 
2.17.1



[PATCH AUTOSEL 4.19 118/146] 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 8668793262d0..85459c17cc60 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1776,6 +1776,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 v2 0/5] Add Tegra194 Dual ARM SMMU driver

2018-10-31 Thread Krishna Reddy
NVIDIA's Xavier (Tegra194) SOC has three ARM SMMU(MMU-500) instances.
Two of the SMMU instances are used to interleave IOVA accesses across them.
The IOVA accesses from HW devices are interleaved across these two SMMU 
instances
and they need to be programmed identical.

The existing ARM SMMU driver can't be used in its current form for programming 
the
two SMMU instances identically. But, most of the code can be shared between ARM 
SMMU
driver and Tegra194 SMMU driver.
Page fault handling and TLB sync operations need to know about specific instance
of SMMU for correct fault handling and optimal TLB sync wait. Rest of the code 
doesn't
need to know about number of SMMU instances. Based on this fact, The patch 
series here
rearranges the arm-smmu.c code to allow sharing most of the ARM SMMU 
programming/iommu_ops
code between ARM SMMU driver and Tegra194 SMMU driver and transparently
handles programming of two SMMU instances.

The third SMMU instance would use the existing ARM SMMU driver.

Changes in v2:
* Added CONFIG_ARM_SMMU_TEGRA to protect Tegra194 SMMU driver compilation
* Enabled CONFIG_ARM_SMMU_TEGRA in defconfig
* Added SMMU nodes in Tegra194 device tree

Krishna Reddy (5):
  iommu/arm-smmu: rearrange arm-smmu.c code
  iommu/arm-smmu: Prepare fault, probe, sync functions for sharing code
  iommu/tegra194_smmu: Add Tegra194 SMMU driver
  arm64: defconfig: Enable ARM_SMMU_TEGRA
  arm64: tegra: Add SMMU nodes to Tegra194 device tree

 arch/arm64/boot/dts/nvidia/tegra194.dtsi |  148 ++
 arch/arm64/configs/defconfig |1 +
 drivers/iommu/Kconfig|   10 +
 drivers/iommu/Makefile   |1 +
 drivers/iommu/arm-smmu-common.c  | 1971 +++
 drivers/iommu/arm-smmu-common.h  |  256 
 drivers/iommu/arm-smmu.c | 2167 +-
 drivers/iommu/tegra194-smmu.c|  201 +++
 8 files changed, 2595 insertions(+), 2160 deletions(-)
 create mode 100644 drivers/iommu/arm-smmu-common.c
 create mode 100644 drivers/iommu/arm-smmu-common.h
 create mode 100644 drivers/iommu/tegra194-smmu.c

-- 
2.1.4



[PATCH AUTOSEL 4.19 116/146] 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 17147b8c771e..8f267be1745d 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -2017,6 +2017,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.19 112/146] xprtrdma: Reset credit grant properly after a disconnect

2018-10-31 Thread Sasha Levin
From: Chuck Lever 

[ Upstream commit ef739b2175dde9c05594f768cb78149f1ce2ac36 ]

On a fresh connection, an RPC/RDMA client is supposed to send only
one RPC Call until it gets a credit grant in the first RPC Reply
from the server [RFC 8166, Section 3.3.3].

There is a bug in the Linux client's credit accounting mechanism
introduced by commit e7ce710a8802 ("xprtrdma: Avoid deadlock when
credit window is reset"). On connect, it simply dumps all pending
RPC Calls onto the new connection.

Servers have been tolerant of this bad behavior. Currently no server
implementation ever changes its credit grant over reconnects, and
servers always repost enough Receives before connections are fully
established.

To correct this issue, ensure that the client resets both the credit
grant _and_ the congestion window when handling a reconnect.

Fixes: e7ce710a8802 ("xprtrdma: Avoid deadlock when credit ... ")
Signed-off-by: Chuck Lever 
Cc: sta...@kernel.org
Signed-off-by: Anna Schumaker 
Signed-off-by: Sasha Levin 
---
 net/sunrpc/xprtrdma/svc_rdma_backchannel.c | 1 +
 net/sunrpc/xprtrdma/transport.c| 6 ++
 2 files changed, 7 insertions(+)

diff --git a/net/sunrpc/xprtrdma/svc_rdma_backchannel.c 
b/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
index a68180090554..b9827665ff35 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
@@ -248,6 +248,7 @@ static void
 xprt_rdma_bc_close(struct rpc_xprt *xprt)
 {
dprintk("svcrdma: %s: xprt %p\n", __func__, xprt);
+   xprt->cwnd = RPC_CWNDSHIFT;
 }
 
 static void
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 143ce2579ba9..98cbc7b060ba 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -468,6 +468,12 @@ xprt_rdma_close(struct rpc_xprt *xprt)
xprt->reestablish_timeout = 0;
xprt_disconnect_done(xprt);
rpcrdma_ep_disconnect(ep, ia);
+
+   /* Prepare @xprt for the next connection by reinitializing
+* its credit grant to one (see RFC 8166, Section 3.3.3).
+*/
+   r_xprt->rx_buf.rb_credits = 1;
+   xprt->cwnd = RPC_CWNDSHIFT;
 }
 
 /**
-- 
2.17.1



[PATCH AUTOSEL 4.19 111/146] PCI / ACPI: Enable wake automatically for power managed bridges

2018-10-31 Thread Sasha Levin
From: Mika Westerberg 

[ Upstream commit 6299cf9ec3985cac70bede8a855b5087b81a6640 ]

We enable power management automatically for bridges where
pci_bridge_d3_possible() returns true. However, these bridges may have
ACPI methods such as _DSW that need to be called before D3 entry. For
example in Lenovo Thinkpad X1 Carbon 6th _DSW method is used to prepare
D3cold for the PCIe root port hosting Thunderbolt chain. Because wake is
not enabled _DSW method is never called and the port does not enter
D3cold properly consuming more power than necessary.

Users can work this around by writing "enabled" to "wakeup" sysfs file
under the device in question but that is not something an ordinary user
is expected to do.

Since we already automatically enable power management for PCIe ports
with ->bridge_d3 set extend that to enable wake for them as well,
assuming the port has any ACPI wakeup related objects implemented in the
namespace (adev->wakeup.flags.valid is true). This ensures the necessary
ACPI methods get called at appropriate times and allows the root port in
Thinkpad X1 Carbon 6th to go into D3cold.

Signed-off-by: Mika Westerberg 
Signed-off-by: Bjorn Helgaas 
Reviewed-by: Rafael J. Wysocki 
Signed-off-by: Sasha Levin 
---
 drivers/pci/pci-acpi.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index c2ab57705043..f8436d1c4d45 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -762,19 +762,33 @@ static void pci_acpi_setup(struct device *dev)
return;
 
device_set_wakeup_capable(dev, true);
+   /*
+* For bridges that can do D3 we enable wake automatically (as
+* we do for the power management itself in that case). The
+* reason is that the bridge may have additional methods such as
+* _DSW that need to be called.
+*/
+   if (pci_dev->bridge_d3)
+   device_wakeup_enable(dev);
+
acpi_pci_wakeup(pci_dev, false);
 }
 
 static void pci_acpi_cleanup(struct device *dev)
 {
struct acpi_device *adev = ACPI_COMPANION(dev);
+   struct pci_dev *pci_dev = to_pci_dev(dev);
 
if (!adev)
return;
 
pci_acpi_remove_pm_notifier(adev);
-   if (adev->wakeup.flags.valid)
+   if (adev->wakeup.flags.valid) {
+   if (pci_dev->bridge_d3)
+   device_wakeup_disable(dev);
+
device_set_wakeup_capable(dev, false);
+   }
 }
 
 static bool pci_acpi_bus_match(struct device *dev)
-- 
2.17.1



[PATCH AUTOSEL 4.19 118/146] 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 8668793262d0..85459c17cc60 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1776,6 +1776,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 v2 0/5] Add Tegra194 Dual ARM SMMU driver

2018-10-31 Thread Krishna Reddy
NVIDIA's Xavier (Tegra194) SOC has three ARM SMMU(MMU-500) instances.
Two of the SMMU instances are used to interleave IOVA accesses across them.
The IOVA accesses from HW devices are interleaved across these two SMMU 
instances
and they need to be programmed identical.

The existing ARM SMMU driver can't be used in its current form for programming 
the
two SMMU instances identically. But, most of the code can be shared between ARM 
SMMU
driver and Tegra194 SMMU driver.
Page fault handling and TLB sync operations need to know about specific instance
of SMMU for correct fault handling and optimal TLB sync wait. Rest of the code 
doesn't
need to know about number of SMMU instances. Based on this fact, The patch 
series here
rearranges the arm-smmu.c code to allow sharing most of the ARM SMMU 
programming/iommu_ops
code between ARM SMMU driver and Tegra194 SMMU driver and transparently
handles programming of two SMMU instances.

The third SMMU instance would use the existing ARM SMMU driver.

Changes in v2:
* Added CONFIG_ARM_SMMU_TEGRA to protect Tegra194 SMMU driver compilation
* Enabled CONFIG_ARM_SMMU_TEGRA in defconfig
* Added SMMU nodes in Tegra194 device tree

Krishna Reddy (5):
  iommu/arm-smmu: rearrange arm-smmu.c code
  iommu/arm-smmu: Prepare fault, probe, sync functions for sharing code
  iommu/tegra194_smmu: Add Tegra194 SMMU driver
  arm64: defconfig: Enable ARM_SMMU_TEGRA
  arm64: tegra: Add SMMU nodes to Tegra194 device tree

 arch/arm64/boot/dts/nvidia/tegra194.dtsi |  148 ++
 arch/arm64/configs/defconfig |1 +
 drivers/iommu/Kconfig|   10 +
 drivers/iommu/Makefile   |1 +
 drivers/iommu/arm-smmu-common.c  | 1971 +++
 drivers/iommu/arm-smmu-common.h  |  256 
 drivers/iommu/arm-smmu.c | 2167 +-
 drivers/iommu/tegra194-smmu.c|  201 +++
 8 files changed, 2595 insertions(+), 2160 deletions(-)
 create mode 100644 drivers/iommu/arm-smmu-common.c
 create mode 100644 drivers/iommu/arm-smmu-common.h
 create mode 100644 drivers/iommu/tegra194-smmu.c

-- 
2.1.4



[PATCH AUTOSEL 4.19 119/146] PCI: cadence: Correct probe behaviour when failing to get PHY

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

[ Upstream commit aa77e55d48124d0d78456eabf872fffb5decdbe1 ]

Test the correct value to see whether the PHY get failed.

Use devm_phy_get() instead of devm_phy_optional_get(), since it is
only called if phy name is given in devicetree and so should exist.
If failure when getting or linking PHY, put any PHYs which were
already got and unlink them.

Fixes: dfb80534692ddc5b ("PCI: cadence: Add generic PHY support to host and EP 
drivers")
Reported-by: Colin King 
Signed-off-by: Alan Douglas 
Signed-off-by: Lorenzo Pieralisi 
Signed-off-by: Sasha Levin 
---
 drivers/pci/controller/pcie-cadence.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/controller/pcie-cadence.c 
b/drivers/pci/controller/pcie-cadence.c
index 975bcdd6b5c0..cd795f6fc1e2 100644
--- a/drivers/pci/controller/pcie-cadence.c
+++ b/drivers/pci/controller/pcie-cadence.c
@@ -190,14 +190,16 @@ int cdns_pcie_init_phy(struct device *dev, struct 
cdns_pcie *pcie)
 
for (i = 0; i < phy_count; i++) {
of_property_read_string_index(np, "phy-names", i, );
-   phy[i] = devm_phy_optional_get(dev, name);
-   if (IS_ERR(phy))
-   return PTR_ERR(phy);
-
+   phy[i] = devm_phy_get(dev, name);
+   if (IS_ERR(phy[i])) {
+   ret = PTR_ERR(phy[i]);
+   goto err_phy;
+   }
link[i] = device_link_add(dev, [i]->dev, DL_FLAG_STATELESS);
if (!link[i]) {
+   devm_phy_put(dev, phy[i]);
ret = -EINVAL;
-   goto err_link;
+   goto err_phy;
}
}
 
@@ -207,13 +209,15 @@ int cdns_pcie_init_phy(struct device *dev, struct 
cdns_pcie *pcie)
 
ret =  cdns_pcie_enable_phy(pcie);
if (ret)
-   goto err_link;
+   goto err_phy;
 
return 0;
 
-err_link:
-   while (--i >= 0)
+err_phy:
+   while (--i >= 0) {
device_link_del(link[i]);
+   devm_phy_put(dev, phy[i]);
+   }
 
return ret;
 }
-- 
2.17.1



[PATCH AUTOSEL 4.19 129/146] 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 7e7428e48bfa..4f8b8179ec96 100644
--- a/drivers/usb/chipidea/otg.h
+++ b/drivers/usb/chipidea/otg.h
@@ -17,7 +17,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.19 128/146] 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 4fb91ba39c36..ce3f9ad7120f 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.19 130/146] Smack: ptrace capability use fixes

2018-10-31 Thread Sasha Levin
From: Casey Schaufler 

[ Upstream commit dcb569cf6ac99ca899b8109c128b6ae52477a015 ]

This fixes a pair of problems in the Smack ptrace checks
related to checking capabilities. In both cases, as reported
by Lukasz Pawelczyk, the raw capability calls are used rather
than the Smack wrapper that check addition restrictions.
In one case, as reported by Jann Horn, the wrong task is being
checked for capabilities.

Signed-off-by: Casey Schaufler 
Signed-off-by: Sasha Levin 
---
 security/smack/smack_lsm.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 340fc30ad85d..70d3066e69fe 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -421,6 +421,7 @@ static int smk_ptrace_rule_check(struct task_struct *tracer,
struct smk_audit_info ad, *saip = NULL;
struct task_smack *tsp;
struct smack_known *tracer_known;
+   const struct cred *tracercred;
 
if ((mode & PTRACE_MODE_NOAUDIT) == 0) {
smk_ad_init(, func, LSM_AUDIT_DATA_TASK);
@@ -429,7 +430,8 @@ static int smk_ptrace_rule_check(struct task_struct *tracer,
}
 
rcu_read_lock();
-   tsp = __task_cred(tracer)->security;
+   tracercred = __task_cred(tracer);
+   tsp = tracercred->security;
tracer_known = smk_of_task(tsp);
 
if ((mode & PTRACE_MODE_ATTACH) &&
@@ -439,7 +441,7 @@ static int smk_ptrace_rule_check(struct task_struct *tracer,
rc = 0;
else if (smack_ptrace_rule == SMACK_PTRACE_DRACONIAN)
rc = -EACCES;
-   else if (capable(CAP_SYS_PTRACE))
+   else if (smack_privileged_cred(CAP_SYS_PTRACE, tracercred))
rc = 0;
else
rc = -EACCES;
@@ -1841,6 +1843,7 @@ static int smack_file_send_sigiotask(struct task_struct 
*tsk,
 {
struct smack_known *skp;
struct smack_known *tkp = smk_of_task(tsk->cred->security);
+   const struct cred *tcred;
struct file *file;
int rc;
struct smk_audit_info ad;
@@ -1854,8 +1857,12 @@ static int smack_file_send_sigiotask(struct task_struct 
*tsk,
skp = file->f_security;
rc = smk_access(skp, tkp, MAY_DELIVER, NULL);
rc = smk_bu_note("sigiotask", skp, tkp, MAY_DELIVER, rc);
-   if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
+
+   rcu_read_lock();
+   tcred = __task_cred(tsk);
+   if (rc != 0 && smack_privileged_cred(CAP_MAC_OVERRIDE, tcred))
rc = 0;
+   rcu_read_unlock();
 
smk_ad_init(, __func__, LSM_AUDIT_DATA_TASK);
smk_ad_setfield_u_tsk(, tsk);
-- 
2.17.1



[PATCH AUTOSEL 4.19 125/146] 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 f2ef896464b3..af24ed50a245 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) {
pci_info(dev, "can't enable MSI (MSI-X already enabled)\n");
@@ -1039,6 +1036,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;
@@ -1087,6 +1087,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.19 131/146] 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 4fa4c06c9edb..21a5708985bc 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.19 126/146] 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 306119eaf16a..0dad8626bcfb 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -147,6 +147,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.19 129/146] 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 7e7428e48bfa..4f8b8179ec96 100644
--- a/drivers/usb/chipidea/otg.h
+++ b/drivers/usb/chipidea/otg.h
@@ -17,7 +17,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.19 128/146] 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 4fb91ba39c36..ce3f9ad7120f 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.19 130/146] Smack: ptrace capability use fixes

2018-10-31 Thread Sasha Levin
From: Casey Schaufler 

[ Upstream commit dcb569cf6ac99ca899b8109c128b6ae52477a015 ]

This fixes a pair of problems in the Smack ptrace checks
related to checking capabilities. In both cases, as reported
by Lukasz Pawelczyk, the raw capability calls are used rather
than the Smack wrapper that check addition restrictions.
In one case, as reported by Jann Horn, the wrong task is being
checked for capabilities.

Signed-off-by: Casey Schaufler 
Signed-off-by: Sasha Levin 
---
 security/smack/smack_lsm.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 340fc30ad85d..70d3066e69fe 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -421,6 +421,7 @@ static int smk_ptrace_rule_check(struct task_struct *tracer,
struct smk_audit_info ad, *saip = NULL;
struct task_smack *tsp;
struct smack_known *tracer_known;
+   const struct cred *tracercred;
 
if ((mode & PTRACE_MODE_NOAUDIT) == 0) {
smk_ad_init(, func, LSM_AUDIT_DATA_TASK);
@@ -429,7 +430,8 @@ static int smk_ptrace_rule_check(struct task_struct *tracer,
}
 
rcu_read_lock();
-   tsp = __task_cred(tracer)->security;
+   tracercred = __task_cred(tracer);
+   tsp = tracercred->security;
tracer_known = smk_of_task(tsp);
 
if ((mode & PTRACE_MODE_ATTACH) &&
@@ -439,7 +441,7 @@ static int smk_ptrace_rule_check(struct task_struct *tracer,
rc = 0;
else if (smack_ptrace_rule == SMACK_PTRACE_DRACONIAN)
rc = -EACCES;
-   else if (capable(CAP_SYS_PTRACE))
+   else if (smack_privileged_cred(CAP_SYS_PTRACE, tracercred))
rc = 0;
else
rc = -EACCES;
@@ -1841,6 +1843,7 @@ static int smack_file_send_sigiotask(struct task_struct 
*tsk,
 {
struct smack_known *skp;
struct smack_known *tkp = smk_of_task(tsk->cred->security);
+   const struct cred *tcred;
struct file *file;
int rc;
struct smk_audit_info ad;
@@ -1854,8 +1857,12 @@ static int smack_file_send_sigiotask(struct task_struct 
*tsk,
skp = file->f_security;
rc = smk_access(skp, tkp, MAY_DELIVER, NULL);
rc = smk_bu_note("sigiotask", skp, tkp, MAY_DELIVER, rc);
-   if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
+
+   rcu_read_lock();
+   tcred = __task_cred(tsk);
+   if (rc != 0 && smack_privileged_cred(CAP_MAC_OVERRIDE, tcred))
rc = 0;
+   rcu_read_unlock();
 
smk_ad_init(, __func__, LSM_AUDIT_DATA_TASK);
smk_ad_setfield_u_tsk(, tsk);
-- 
2.17.1



[PATCH AUTOSEL 4.19 125/146] 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 f2ef896464b3..af24ed50a245 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) {
pci_info(dev, "can't enable MSI (MSI-X already enabled)\n");
@@ -1039,6 +1036,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;
@@ -1087,6 +1087,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.19 131/146] 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 4fa4c06c9edb..21a5708985bc 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.19 126/146] 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 306119eaf16a..0dad8626bcfb 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -147,6 +147,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.19 120/146] nvmem: check the return value of nvmem_add_cells()

2018-10-31 Thread Sasha Levin
From: Bartosz Golaszewski 

[ Upstream commit fa72d847d68d7833b77a4bef944cf2c5baf56f49 ]

This function can fail so check its return value in nvmem_register()
and act accordingly.

Signed-off-by: Bartosz Golaszewski 
Signed-off-by: Srinivas Kandagatla 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/nvmem/core.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index aa1657831b70..7c530c88b3fb 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -516,11 +516,17 @@ struct nvmem_device *nvmem_register(const struct 
nvmem_config *config)
goto err_device_del;
}
 
-   if (config->cells)
-   nvmem_add_cells(nvmem, config->cells, config->ncells);
+   if (config->cells) {
+   rval = nvmem_add_cells(nvmem, config->cells, config->ncells);
+   if (rval)
+   goto err_teardown_compat;
+   }
 
return nvmem;
 
+err_teardown_compat:
+   if (config->compat)
+   device_remove_bin_file(nvmem->base_dev, >eeprom);
 err_device_del:
device_del(>dev);
 err_put_device:
-- 
2.17.1



[PATCH AUTOSEL 4.19 121/146] xhci: Avoid USB autosuspend when resuming USB2 ports.

2018-10-31 Thread Sasha Levin
From: Anshuman Gupta 

[ Upstream commit 330e2d61cdd58363eb5e66b2e72f76fe3c5492e0 ]

When USB bus host controller root hub resumes from autosuspend,
it immediately tries to enter auto-suspend, but there can be a
scenario when root hub is resuming its usb2 ports, in that particular
case USB host controller auto suspend fails since it is busy
to resuming its usb2 ports.

This makes multiple failed cycles of auto-suspend until all usb2
ports of host controller root hub do not resume.

This patch uses USB core framework usb_hcd_start_port_resume,
usb_hcd_end_port_resume API's in order to  autoresume/autosuspend
root hub properly.

Signed-off-by: Anshuman Gupta 
Signed-off-by: Mathias Nyman 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/usb/host/xhci-hub.c  | 5 +
 drivers/usb/host/xhci-ring.c | 1 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 7e2a531ba321..12eea73d9f20 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -900,6 +900,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
set_bit(wIndex, _state->resuming_ports);
bus_state->resume_done[wIndex] = timeout;
mod_timer(>rh_timer, timeout);
+   usb_hcd_start_port_resume(>self, wIndex);
}
/* Has resume been signalled for USB_RESUME_TIME yet? */
} else if (time_after_eq(jiffies,
@@ -940,6 +941,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
clear_bit(wIndex, _state->rexit_ports);
}
 
+   usb_hcd_end_port_resume(>self, wIndex);
bus_state->port_c_suspend |= 1 << wIndex;
bus_state->suspended_ports &= ~(1 << wIndex);
} else {
@@ -962,6 +964,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
(raw_port_status & PORT_PLS_MASK) != XDEV_RESUME) {
bus_state->resume_done[wIndex] = 0;
clear_bit(wIndex, _state->resuming_ports);
+   usb_hcd_end_port_resume(>self, wIndex);
}
 
 
@@ -1337,6 +1340,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
goto error;
 
set_bit(wIndex, _state->resuming_ports);
+   usb_hcd_start_port_resume(>self, wIndex);
xhci_set_link_state(xhci, ports[wIndex],
XDEV_RESUME);
spin_unlock_irqrestore(>lock, flags);
@@ -1345,6 +1349,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
xhci_set_link_state(xhci, ports[wIndex],
XDEV_U0);
clear_bit(wIndex, _state->resuming_ports);
+   usb_hcd_end_port_resume(>self, wIndex);
}
bus_state->port_c_suspend |= 1 << wIndex;
 
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index f0a99aa0ac58..cd4659703647 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1602,6 +1602,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
set_bit(HCD_FLAG_POLL_RH, >flags);
mod_timer(>rh_timer,
  bus_state->resume_done[hcd_portnum]);
+   usb_hcd_start_port_resume(>self, hcd_portnum);
bogus_port_status = true;
}
}
-- 
2.17.1



[PATCH AUTOSEL 4.19 120/146] nvmem: check the return value of nvmem_add_cells()

2018-10-31 Thread Sasha Levin
From: Bartosz Golaszewski 

[ Upstream commit fa72d847d68d7833b77a4bef944cf2c5baf56f49 ]

This function can fail so check its return value in nvmem_register()
and act accordingly.

Signed-off-by: Bartosz Golaszewski 
Signed-off-by: Srinivas Kandagatla 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/nvmem/core.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index aa1657831b70..7c530c88b3fb 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -516,11 +516,17 @@ struct nvmem_device *nvmem_register(const struct 
nvmem_config *config)
goto err_device_del;
}
 
-   if (config->cells)
-   nvmem_add_cells(nvmem, config->cells, config->ncells);
+   if (config->cells) {
+   rval = nvmem_add_cells(nvmem, config->cells, config->ncells);
+   if (rval)
+   goto err_teardown_compat;
+   }
 
return nvmem;
 
+err_teardown_compat:
+   if (config->compat)
+   device_remove_bin_file(nvmem->base_dev, >eeprom);
 err_device_del:
device_del(>dev);
 err_put_device:
-- 
2.17.1



[PATCH AUTOSEL 4.19 121/146] xhci: Avoid USB autosuspend when resuming USB2 ports.

2018-10-31 Thread Sasha Levin
From: Anshuman Gupta 

[ Upstream commit 330e2d61cdd58363eb5e66b2e72f76fe3c5492e0 ]

When USB bus host controller root hub resumes from autosuspend,
it immediately tries to enter auto-suspend, but there can be a
scenario when root hub is resuming its usb2 ports, in that particular
case USB host controller auto suspend fails since it is busy
to resuming its usb2 ports.

This makes multiple failed cycles of auto-suspend until all usb2
ports of host controller root hub do not resume.

This patch uses USB core framework usb_hcd_start_port_resume,
usb_hcd_end_port_resume API's in order to  autoresume/autosuspend
root hub properly.

Signed-off-by: Anshuman Gupta 
Signed-off-by: Mathias Nyman 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/usb/host/xhci-hub.c  | 5 +
 drivers/usb/host/xhci-ring.c | 1 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 7e2a531ba321..12eea73d9f20 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -900,6 +900,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
set_bit(wIndex, _state->resuming_ports);
bus_state->resume_done[wIndex] = timeout;
mod_timer(>rh_timer, timeout);
+   usb_hcd_start_port_resume(>self, wIndex);
}
/* Has resume been signalled for USB_RESUME_TIME yet? */
} else if (time_after_eq(jiffies,
@@ -940,6 +941,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
clear_bit(wIndex, _state->rexit_ports);
}
 
+   usb_hcd_end_port_resume(>self, wIndex);
bus_state->port_c_suspend |= 1 << wIndex;
bus_state->suspended_ports &= ~(1 << wIndex);
} else {
@@ -962,6 +964,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
(raw_port_status & PORT_PLS_MASK) != XDEV_RESUME) {
bus_state->resume_done[wIndex] = 0;
clear_bit(wIndex, _state->resuming_ports);
+   usb_hcd_end_port_resume(>self, wIndex);
}
 
 
@@ -1337,6 +1340,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
goto error;
 
set_bit(wIndex, _state->resuming_ports);
+   usb_hcd_start_port_resume(>self, wIndex);
xhci_set_link_state(xhci, ports[wIndex],
XDEV_RESUME);
spin_unlock_irqrestore(>lock, flags);
@@ -1345,6 +1349,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, 
u16 wValue,
xhci_set_link_state(xhci, ports[wIndex],
XDEV_U0);
clear_bit(wIndex, _state->resuming_ports);
+   usb_hcd_end_port_resume(>self, wIndex);
}
bus_state->port_c_suspend |= 1 << wIndex;
 
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index f0a99aa0ac58..cd4659703647 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1602,6 +1602,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
set_bit(HCD_FLAG_POLL_RH, >flags);
mod_timer(>rh_timer,
  bus_state->resume_done[hcd_portnum]);
+   usb_hcd_start_port_resume(>self, hcd_portnum);
bogus_port_status = true;
}
}
-- 
2.17.1



[PATCH AUTOSEL 4.19 122/146] scsi: qla2xxx: Fix recursive mailbox timeout

2018-10-31 Thread Sasha Levin
From: Quinn Tran 

[ Upstream commit 710bc78f829d014eca95ed7ccc4052bc064b1320 ]

This patch prevents user space mailbox request from doing chip reset if the
mailbox timed out. The chip reset is only reserved for the DPC thread to
ensure all mailbox requests are flushed properly. The DPC thread is
responsible for the flushing all MBs and chip reset.

Fixes: b2000805a975 ("scsi: qla2xxx: Flush mailbox commands on chip reset")
Cc: 
Signed-off-by: Quinn Tran 
Reviewed-by: Ewan D. Milne 
Signed-off-by: Himanshu Madhani 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/qla2xxx/qla_mbx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 2c6c2cd5a0d0..596a9b214df1 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -493,7 +493,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t 
*mcp)
set_bit(ISP_ABORT_NEEDED, >dpc_flags);
qla2xxx_wake_dpc(vha);
}
-   } else if (!abort_active) {
+   } else if (current == ha->dpc_thread) {
/* call abort directly since we are in the DPC thread */
ql_dbg(ql_dbg_mbx, vha, 0x101d,
"Timeout, calling abort_isp.\n");
-- 
2.17.1



[PATCH AUTOSEL 4.19 127/146] 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/controller/dwc/pci-dra7xx.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c 
b/drivers/pci/controller/dwc/pci-dra7xx.c
index ce9224a36f62..a32d6dde7a57 100644
--- a/drivers/pci/controller/dwc/pci-dra7xx.c
+++ b/drivers/pci/controller/dwc/pci-dra7xx.c
@@ -542,7 +542,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
@@ -552,7 +552,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;
@@ -704,6 +704,11 @@ static int __init dra7xx_pcie_probe(struct platform_device 
*pdev)
 
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;
@@ -717,7 +722,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.19 123/146] f2fs: fix to recover inode's crtime during POR

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

[ Upstream commit 5cd1f387a13b5188b4edb4c834310302a85a6ea2 ]

Testcase to reproduce this bug:
1. mkfs.f2fs -O extra_attr -O inode_crtime /dev/sdd
2. mount -t f2fs /dev/sdd /mnt/f2fs
3. touch /mnt/f2fs/file
4. xfs_io -f /mnt/f2fs/file -c "fsync"
5. godown /mnt/f2fs
6. umount /mnt/f2fs
7. mount -t f2fs /dev/sdd /mnt/f2fs
8. xfs_io -f /mnt/f2fs/file -c "statx -r"

stat.btime.tv_sec = 0
stat.btime.tv_nsec = 0

This patch fixes to recover inode creation time fields during
mount.

Signed-off-by: Chao Yu 
Signed-off-by: Jaegeuk Kim 
Signed-off-by: Sasha Levin 
---
 fs/f2fs/node.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index dd2e45a661aa..fe5c9ff92772 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -2560,6 +2560,13 @@ int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, 
struct page *page)
F2FS_FITS_IN_INODE(src, le16_to_cpu(src->i_extra_isize),
i_projid))
dst->i_projid = src->i_projid;
+
+   if (f2fs_sb_has_inode_crtime(sbi->sb) &&
+   F2FS_FITS_IN_INODE(src, le16_to_cpu(src->i_extra_isize),
+   i_crtime_nsec)) {
+   dst->i_crtime = src->i_crtime;
+   dst->i_crtime_nsec = src->i_crtime_nsec;
+   }
}
 
new_ni = old_ni;
-- 
2.17.1



[PATCH AUTOSEL 4.19 123/146] f2fs: fix to recover inode's crtime during POR

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

[ Upstream commit 5cd1f387a13b5188b4edb4c834310302a85a6ea2 ]

Testcase to reproduce this bug:
1. mkfs.f2fs -O extra_attr -O inode_crtime /dev/sdd
2. mount -t f2fs /dev/sdd /mnt/f2fs
3. touch /mnt/f2fs/file
4. xfs_io -f /mnt/f2fs/file -c "fsync"
5. godown /mnt/f2fs
6. umount /mnt/f2fs
7. mount -t f2fs /dev/sdd /mnt/f2fs
8. xfs_io -f /mnt/f2fs/file -c "statx -r"

stat.btime.tv_sec = 0
stat.btime.tv_nsec = 0

This patch fixes to recover inode creation time fields during
mount.

Signed-off-by: Chao Yu 
Signed-off-by: Jaegeuk Kim 
Signed-off-by: Sasha Levin 
---
 fs/f2fs/node.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index dd2e45a661aa..fe5c9ff92772 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -2560,6 +2560,13 @@ int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, 
struct page *page)
F2FS_FITS_IN_INODE(src, le16_to_cpu(src->i_extra_isize),
i_projid))
dst->i_projid = src->i_projid;
+
+   if (f2fs_sb_has_inode_crtime(sbi->sb) &&
+   F2FS_FITS_IN_INODE(src, le16_to_cpu(src->i_extra_isize),
+   i_crtime_nsec)) {
+   dst->i_crtime = src->i_crtime;
+   dst->i_crtime_nsec = src->i_crtime_nsec;
+   }
}
 
new_ni = old_ni;
-- 
2.17.1



[PATCH AUTOSEL 4.19 122/146] scsi: qla2xxx: Fix recursive mailbox timeout

2018-10-31 Thread Sasha Levin
From: Quinn Tran 

[ Upstream commit 710bc78f829d014eca95ed7ccc4052bc064b1320 ]

This patch prevents user space mailbox request from doing chip reset if the
mailbox timed out. The chip reset is only reserved for the DPC thread to
ensure all mailbox requests are flushed properly. The DPC thread is
responsible for the flushing all MBs and chip reset.

Fixes: b2000805a975 ("scsi: qla2xxx: Flush mailbox commands on chip reset")
Cc: 
Signed-off-by: Quinn Tran 
Reviewed-by: Ewan D. Milne 
Signed-off-by: Himanshu Madhani 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Sasha Levin 
---
 drivers/scsi/qla2xxx/qla_mbx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 2c6c2cd5a0d0..596a9b214df1 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -493,7 +493,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t 
*mcp)
set_bit(ISP_ABORT_NEEDED, >dpc_flags);
qla2xxx_wake_dpc(vha);
}
-   } else if (!abort_active) {
+   } else if (current == ha->dpc_thread) {
/* call abort directly since we are in the DPC thread */
ql_dbg(ql_dbg_mbx, vha, 0x101d,
"Timeout, calling abort_isp.\n");
-- 
2.17.1



[PATCH AUTOSEL 4.19 127/146] 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/controller/dwc/pci-dra7xx.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c 
b/drivers/pci/controller/dwc/pci-dra7xx.c
index ce9224a36f62..a32d6dde7a57 100644
--- a/drivers/pci/controller/dwc/pci-dra7xx.c
+++ b/drivers/pci/controller/dwc/pci-dra7xx.c
@@ -542,7 +542,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
@@ -552,7 +552,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;
@@ -704,6 +704,11 @@ static int __init dra7xx_pcie_probe(struct platform_device 
*pdev)
 
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;
@@ -717,7 +722,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.19 134/146] IB/ipoib: Use dev_port to expose network interface port numbers

2018-10-31 Thread Sasha Levin
From: Arseny Maslennikov 

[ Upstream commit 9b8b2a323008aedd39a8debb861b825707f01420 ]

Some InfiniBand network devices have multiple ports on the same PCI
function. This initializes the `dev_port' sysfs field of those
network interfaces with their port number.

Prior to this the kernel erroneously used the `dev_id' sysfs
field of those network interfaces to convey the port number to userspace.

The use of `dev_id' was considered correct until Linux 3.15,
when another field, `dev_port', was defined for this particular
purpose and `dev_id' was reserved for distinguishing stacked ifaces
(e.g: VLANs) with the same hardware address as their parent device.

Similar fixes to net/mlx4_en and many other drivers, which started
exporting this information through `dev_id' before 3.15, were accepted
into the kernel 4 years ago.
See 76a066f2a2a0 (`net/mlx4_en: Expose port number through sysfs').

Signed-off-by: Arseny Maslennikov 
Signed-off-by: Doug Ledford 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/ulp/ipoib/ipoib_main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c 
b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index e3d28f9ad9c0..30f840f874b3 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -1880,6 +1880,8 @@ static int ipoib_parent_init(struct net_device *ndev)
   sizeof(union ib_gid));
 
SET_NETDEV_DEV(priv->dev, priv->ca->dev.parent);
+   priv->dev->dev_port = priv->port - 1;
+   /* Let's set this one too for backwards compatibility. */
priv->dev->dev_id = priv->port - 1;
 
return 0;
-- 
2.17.1



[PATCH AUTOSEL 4.19 133/146] firmware: coreboot: Unmap ioregion after device population

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

[ Upstream commit 20edec388277b62ddfddb8b2b376a937a2cd6d1b ]

Both callers of coreboot_table_init() ioremap the pointer that comes in
but they don't unmap the memory on failure. Both of them also fail probe
immediately with the return value of coreboot_table_init(), leaking a
mapping when it fails. The mapping isn't necessary at all after devices
are populated either, so we can just drop the mapping here when we exit
the function. Let's do that to simplify the code a bit and plug the leak.

Cc: Wei-Ning Huang 
Cc: Julius Werner 
Cc: Brian Norris 
Cc: Samuel Holland 
Fixes: 570d30c2823f ("firmware: coreboot: Expose the coreboot table as a bus")
Signed-off-by: Stephen Boyd 
Reviewed-by: Julius Werner 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/firmware/google/coreboot_table.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/google/coreboot_table.c 
b/drivers/firmware/google/coreboot_table.c
index 19db5709ae28..898bb9abc41f 100644
--- a/drivers/firmware/google/coreboot_table.c
+++ b/drivers/firmware/google/coreboot_table.c
@@ -110,7 +110,8 @@ int coreboot_table_init(struct device *dev, void __iomem 
*ptr)
 
if (strncmp(header.signature, "LBIO", sizeof(header.signature))) {
pr_warn("coreboot_table: coreboot table missing or corrupt!\n");
-   return -ENODEV;
+   ret = -ENODEV;
+   goto out;
}
 
ptr_entry = (void *)ptr_header + header.header_bytes;
@@ -137,7 +138,8 @@ int coreboot_table_init(struct device *dev, void __iomem 
*ptr)
 
ptr_entry += entry.size;
}
-
+out:
+   iounmap(ptr);
return ret;
 }
 EXPORT_SYMBOL(coreboot_table_init);
@@ -146,7 +148,6 @@ int coreboot_table_exit(void)
 {
if (ptr_header) {
bus_unregister(_bus_type);
-   iounmap(ptr_header);
ptr_header = NULL;
}
 
-- 
2.17.1



[PATCH AUTOSEL 4.19 132/146] ASoC: AMD: Fix capture unstable in beginning for some runs

2018-10-31 Thread Sasha Levin
From: Akshu Agrawal 

[ Upstream commit c50535ed6a10fcae1b64ae83c0f6b1eeb5535afc ]

alsa_conformance_test -C hw:0,4 -p 1024 --debug
would sometime show:
TIME_DIFF(s)HW_LEVEL   READ  RATE
0.95970 1024   102410670001.041992
0.042609555 1024   2048   24032.168372
0.021330364 1024   3072   48006.681930
0.021339559 1024   4096   47985.996337
The issue is that in dma pointer function we can have stale value
of the register for current descriptor of channel.
The register retains the number of the last descriptor that
was transferred.

Fix ensures that we report position, 0, till the one period worth of
data is transferred.  After one period of data, in handler of period
completion interrupt we update the config and correct value of descriptor
starts reflecting.

Signed-off-by: Akshu Agrawal 
Signed-off-by: Mark Brown 
Signed-off-by: Sasha Levin 
---
 sound/soc/amd/acp-pcm-dma.c | 22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c
index 77b265bd0505..3135e9eafd18 100644
--- a/sound/soc/amd/acp-pcm-dma.c
+++ b/sound/soc/amd/acp-pcm-dma.c
@@ -1036,16 +1036,22 @@ static snd_pcm_uframes_t acp_dma_pointer(struct 
snd_pcm_substream *substream)
 
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
period_bytes = frames_to_bytes(runtime, runtime->period_size);
-   dscr = acp_reg_read(rtd->acp_mmio, rtd->dma_curr_dscr);
-   if (dscr == rtd->dma_dscr_idx_1)
-   pos = period_bytes;
-   else
-   pos = 0;
bytescount = acp_get_byte_count(rtd);
-   if (bytescount > rtd->bytescount)
+   if (bytescount >= rtd->bytescount)
bytescount -= rtd->bytescount;
-   delay = do_div(bytescount, period_bytes);
-   runtime->delay = bytes_to_frames(runtime, delay);
+   if (bytescount < period_bytes) {
+   pos = 0;
+   } else {
+   dscr = acp_reg_read(rtd->acp_mmio, rtd->dma_curr_dscr);
+   if (dscr == rtd->dma_dscr_idx_1)
+   pos = period_bytes;
+   else
+   pos = 0;
+   }
+   if (bytescount > 0) {
+   delay = do_div(bytescount, period_bytes);
+   runtime->delay = bytes_to_frames(runtime, delay);
+   }
} else {
buffersize = frames_to_bytes(runtime, runtime->buffer_size);
bytescount = acp_get_byte_count(rtd);
-- 
2.17.1



[PATCH AUTOSEL 4.19 134/146] IB/ipoib: Use dev_port to expose network interface port numbers

2018-10-31 Thread Sasha Levin
From: Arseny Maslennikov 

[ Upstream commit 9b8b2a323008aedd39a8debb861b825707f01420 ]

Some InfiniBand network devices have multiple ports on the same PCI
function. This initializes the `dev_port' sysfs field of those
network interfaces with their port number.

Prior to this the kernel erroneously used the `dev_id' sysfs
field of those network interfaces to convey the port number to userspace.

The use of `dev_id' was considered correct until Linux 3.15,
when another field, `dev_port', was defined for this particular
purpose and `dev_id' was reserved for distinguishing stacked ifaces
(e.g: VLANs) with the same hardware address as their parent device.

Similar fixes to net/mlx4_en and many other drivers, which started
exporting this information through `dev_id' before 3.15, were accepted
into the kernel 4 years ago.
See 76a066f2a2a0 (`net/mlx4_en: Expose port number through sysfs').

Signed-off-by: Arseny Maslennikov 
Signed-off-by: Doug Ledford 
Signed-off-by: Sasha Levin 
---
 drivers/infiniband/ulp/ipoib/ipoib_main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c 
b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index e3d28f9ad9c0..30f840f874b3 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -1880,6 +1880,8 @@ static int ipoib_parent_init(struct net_device *ndev)
   sizeof(union ib_gid));
 
SET_NETDEV_DEV(priv->dev, priv->ca->dev.parent);
+   priv->dev->dev_port = priv->port - 1;
+   /* Let's set this one too for backwards compatibility. */
priv->dev->dev_id = priv->port - 1;
 
return 0;
-- 
2.17.1



[PATCH AUTOSEL 4.19 133/146] firmware: coreboot: Unmap ioregion after device population

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

[ Upstream commit 20edec388277b62ddfddb8b2b376a937a2cd6d1b ]

Both callers of coreboot_table_init() ioremap the pointer that comes in
but they don't unmap the memory on failure. Both of them also fail probe
immediately with the return value of coreboot_table_init(), leaking a
mapping when it fails. The mapping isn't necessary at all after devices
are populated either, so we can just drop the mapping here when we exit
the function. Let's do that to simplify the code a bit and plug the leak.

Cc: Wei-Ning Huang 
Cc: Julius Werner 
Cc: Brian Norris 
Cc: Samuel Holland 
Fixes: 570d30c2823f ("firmware: coreboot: Expose the coreboot table as a bus")
Signed-off-by: Stephen Boyd 
Reviewed-by: Julius Werner 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
---
 drivers/firmware/google/coreboot_table.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/google/coreboot_table.c 
b/drivers/firmware/google/coreboot_table.c
index 19db5709ae28..898bb9abc41f 100644
--- a/drivers/firmware/google/coreboot_table.c
+++ b/drivers/firmware/google/coreboot_table.c
@@ -110,7 +110,8 @@ int coreboot_table_init(struct device *dev, void __iomem 
*ptr)
 
if (strncmp(header.signature, "LBIO", sizeof(header.signature))) {
pr_warn("coreboot_table: coreboot table missing or corrupt!\n");
-   return -ENODEV;
+   ret = -ENODEV;
+   goto out;
}
 
ptr_entry = (void *)ptr_header + header.header_bytes;
@@ -137,7 +138,8 @@ int coreboot_table_init(struct device *dev, void __iomem 
*ptr)
 
ptr_entry += entry.size;
}
-
+out:
+   iounmap(ptr);
return ret;
 }
 EXPORT_SYMBOL(coreboot_table_init);
@@ -146,7 +148,6 @@ int coreboot_table_exit(void)
 {
if (ptr_header) {
bus_unregister(_bus_type);
-   iounmap(ptr_header);
ptr_header = NULL;
}
 
-- 
2.17.1



[PATCH AUTOSEL 4.19 132/146] ASoC: AMD: Fix capture unstable in beginning for some runs

2018-10-31 Thread Sasha Levin
From: Akshu Agrawal 

[ Upstream commit c50535ed6a10fcae1b64ae83c0f6b1eeb5535afc ]

alsa_conformance_test -C hw:0,4 -p 1024 --debug
would sometime show:
TIME_DIFF(s)HW_LEVEL   READ  RATE
0.95970 1024   102410670001.041992
0.042609555 1024   2048   24032.168372
0.021330364 1024   3072   48006.681930
0.021339559 1024   4096   47985.996337
The issue is that in dma pointer function we can have stale value
of the register for current descriptor of channel.
The register retains the number of the last descriptor that
was transferred.

Fix ensures that we report position, 0, till the one period worth of
data is transferred.  After one period of data, in handler of period
completion interrupt we update the config and correct value of descriptor
starts reflecting.

Signed-off-by: Akshu Agrawal 
Signed-off-by: Mark Brown 
Signed-off-by: Sasha Levin 
---
 sound/soc/amd/acp-pcm-dma.c | 22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c
index 77b265bd0505..3135e9eafd18 100644
--- a/sound/soc/amd/acp-pcm-dma.c
+++ b/sound/soc/amd/acp-pcm-dma.c
@@ -1036,16 +1036,22 @@ static snd_pcm_uframes_t acp_dma_pointer(struct 
snd_pcm_substream *substream)
 
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
period_bytes = frames_to_bytes(runtime, runtime->period_size);
-   dscr = acp_reg_read(rtd->acp_mmio, rtd->dma_curr_dscr);
-   if (dscr == rtd->dma_dscr_idx_1)
-   pos = period_bytes;
-   else
-   pos = 0;
bytescount = acp_get_byte_count(rtd);
-   if (bytescount > rtd->bytescount)
+   if (bytescount >= rtd->bytescount)
bytescount -= rtd->bytescount;
-   delay = do_div(bytescount, period_bytes);
-   runtime->delay = bytes_to_frames(runtime, delay);
+   if (bytescount < period_bytes) {
+   pos = 0;
+   } else {
+   dscr = acp_reg_read(rtd->acp_mmio, rtd->dma_curr_dscr);
+   if (dscr == rtd->dma_dscr_idx_1)
+   pos = period_bytes;
+   else
+   pos = 0;
+   }
+   if (bytescount > 0) {
+   delay = do_div(bytescount, period_bytes);
+   runtime->delay = bytes_to_frames(runtime, delay);
+   }
} else {
buffersize = frames_to_bytes(runtime, runtime->buffer_size);
bytescount = acp_get_byte_count(rtd);
-- 
2.17.1



[PATCH AUTOSEL 4.19 136/146] 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 70a7981b94b3..9916edda5271 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -274,6 +274,8 @@ static struct class uio_class = {
.dev_groups = uio_groups,
 };
 
+bool uio_class_registered;
+
 /*
  * device functions
  */
@@ -876,6 +878,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:
@@ -886,6 +891,7 @@ static int init_uio_class(void)
 
 static void release_uio_class(void)
 {
+   uio_class_registered = false;
class_unregister(_class);
uio_major_cleanup();
 }
@@ -912,6 +918,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.19 142/146] f2fs: fix to flush all dirty inodes recovered in readonly fs

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

[ Upstream commit 1378752b9921e60749eaf18ec6c47b33f9001abb ]

generic/417 reported as blow:

[ cut here ]
kernel BUG at /home/yuchao/git/devf2fs/inode.c:695!
invalid opcode:  [#1] PREEMPT SMP
CPU: 1 PID: 21697 Comm: umount Tainted: GW  O  4.18.0-rc2+ #39
Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
EIP: f2fs_evict_inode+0x556/0x580 [f2fs]
Call Trace:
 ? _raw_spin_unlock+0x2c/0x50
 evict+0xa8/0x170
 dispose_list+0x34/0x40
 evict_inodes+0x118/0x120
 generic_shutdown_super+0x41/0x100
 ? rcu_read_lock_sched_held+0x97/0xa0
 kill_block_super+0x22/0x50
 kill_f2fs_super+0x6f/0x80 [f2fs]
 deactivate_locked_super+0x3d/0x70
 deactivate_super+0x40/0x60
 cleanup_mnt+0x39/0x70
 __cleanup_mnt+0x10/0x20
 task_work_run+0x81/0xa0
 exit_to_usermode_loop+0x59/0xa7
 do_fast_syscall_32+0x1f5/0x22c
 entry_SYSENTER_32+0x53/0x86
EIP: f2fs_evict_inode+0x556/0x580 [f2fs]

It can simply reproduced with scripts:

Enable quota feature during mkfs.

Testcase1:
1. mkfs.f2fs /dev/zram0
2. mount -t f2fs /dev/zram0 /mnt/f2fs
3. xfs_io -f /mnt/f2fs/file -c "pwrite 0 4k" -c "fsync"
4. godown /mnt/f2fs
5. umount /mnt/f2fs
6. mount -t f2fs -o ro /dev/zram0 /mnt/f2fs
7. umount /mnt/f2fs

Testcase2:
1. mkfs.f2fs /dev/zram0
2. mount -t f2fs /dev/zram0 /mnt/f2fs
3. touch /mnt/f2fs/file
4. create process[pid = x] do:
a) open /mnt/f2fs/file;
b) unlink /mnt/f2fs/file
5. godown -f /mnt/f2fs
6. kill process[pid = x]
7. umount /mnt/f2fs
8. mount -t f2fs -o ro /dev/zram0 /mnt/f2fs
9. umount /mnt/f2fs

The reason is: during recovery, i_{c,m}time of inode will be updated, then
the inode can be set dirty w/o being tracked in sbi->inode_list[DIRTY_META]
global list, so later write_checkpoint will not flush such dirty inode into
node page.

Once umount is called, sync_filesystem() in generic_shutdown_super() will
skip syncng dirty inodes due to sb_rdonly check, leaving dirty inodes
there.

To solve this issue, during umount, add remove SB_RDONLY flag in
sb->s_flags, to make sure sync_filesystem() will not be skipped.

Signed-off-by: Chao Yu 

Signed-off-by: Jaegeuk Kim 

Signed-off-by: Sasha Levin 
---
 fs/f2fs/checkpoint.c |  2 ++
 fs/f2fs/f2fs.h   |  1 +
 fs/f2fs/recovery.c   | 14 +-
 fs/f2fs/super.c  |  3 +++
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index e8b6b89bddb8..59d0472013f4 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -696,6 +696,8 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
/* clear Orphan Flag */
clear_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG);
 out:
+   set_sbi_flag(sbi, SBI_IS_RECOVERED);
+
 #ifdef CONFIG_QUOTA
/* Turn quotas off */
if (quota_enabled)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e146e6c443e8..ecb735142276 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1089,6 +1089,7 @@ enum {
SBI_NEED_SB_WRITE,  /* need to recover superblock */
SBI_NEED_CP,/* need to checkpoint */
SBI_IS_SHUTDOWN,/* shutdown by ioctl */
+   SBI_IS_RECOVERED,   /* recovered orphan/data */
 };
 
 enum {
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index 12a3293bcbc9..9a8579fb3a30 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -698,11 +698,15 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, 
bool check_only)
/* let's drop all the directory inodes for clean checkpoint */
destroy_fsync_dnodes(_list);
 
-   if (!err && need_writecp) {
-   struct cp_control cpc = {
-   .reason = CP_RECOVERY,
-   };
-   err = f2fs_write_checkpoint(sbi, );
+   if (need_writecp) {
+   set_sbi_flag(sbi, SBI_IS_RECOVERED);
+
+   if (!err) {
+   struct cp_control cpc = {
+   .reason = CP_RECOVERY,
+   };
+   err = f2fs_write_checkpoint(sbi, );
+   }
}
 
kmem_cache_destroy(fsync_entry_slab);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index d0d016f21307..287c9fe9fff9 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -3188,6 +3188,9 @@ static void kill_f2fs_super(struct super_block *sb)
};
f2fs_write_checkpoint(sbi, );
}
+
+   if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb))
+   sb->s_flags &= ~SB_RDONLY;
}
kill_block_super(sb);
 }
-- 
2.17.1



[PATCH AUTOSEL 4.19 140/146] 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 896b885f504e..d0d016f21307 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1852,7 +1852,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 || f2fs_sb_has_quota_ino(sb))
@@ -1871,9 +1873,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++) {
+   err = f2fs_quota_off(sb, type);
+   if (err) {
+   int ret = dquot_quota_off(sb, type);
 
-   for (type = 0; type < MAXQUOTAS; type++)
-   f2fs_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);
+   }
+   }
 }
 
 static int f2fs_get_projid(struct inode *inode, kprojid_t *projid)
-- 
2.17.1



[PATCH AUTOSEL 4.19 142/146] f2fs: fix to flush all dirty inodes recovered in readonly fs

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

[ Upstream commit 1378752b9921e60749eaf18ec6c47b33f9001abb ]

generic/417 reported as blow:

[ cut here ]
kernel BUG at /home/yuchao/git/devf2fs/inode.c:695!
invalid opcode:  [#1] PREEMPT SMP
CPU: 1 PID: 21697 Comm: umount Tainted: GW  O  4.18.0-rc2+ #39
Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
EIP: f2fs_evict_inode+0x556/0x580 [f2fs]
Call Trace:
 ? _raw_spin_unlock+0x2c/0x50
 evict+0xa8/0x170
 dispose_list+0x34/0x40
 evict_inodes+0x118/0x120
 generic_shutdown_super+0x41/0x100
 ? rcu_read_lock_sched_held+0x97/0xa0
 kill_block_super+0x22/0x50
 kill_f2fs_super+0x6f/0x80 [f2fs]
 deactivate_locked_super+0x3d/0x70
 deactivate_super+0x40/0x60
 cleanup_mnt+0x39/0x70
 __cleanup_mnt+0x10/0x20
 task_work_run+0x81/0xa0
 exit_to_usermode_loop+0x59/0xa7
 do_fast_syscall_32+0x1f5/0x22c
 entry_SYSENTER_32+0x53/0x86
EIP: f2fs_evict_inode+0x556/0x580 [f2fs]

It can simply reproduced with scripts:

Enable quota feature during mkfs.

Testcase1:
1. mkfs.f2fs /dev/zram0
2. mount -t f2fs /dev/zram0 /mnt/f2fs
3. xfs_io -f /mnt/f2fs/file -c "pwrite 0 4k" -c "fsync"
4. godown /mnt/f2fs
5. umount /mnt/f2fs
6. mount -t f2fs -o ro /dev/zram0 /mnt/f2fs
7. umount /mnt/f2fs

Testcase2:
1. mkfs.f2fs /dev/zram0
2. mount -t f2fs /dev/zram0 /mnt/f2fs
3. touch /mnt/f2fs/file
4. create process[pid = x] do:
a) open /mnt/f2fs/file;
b) unlink /mnt/f2fs/file
5. godown -f /mnt/f2fs
6. kill process[pid = x]
7. umount /mnt/f2fs
8. mount -t f2fs -o ro /dev/zram0 /mnt/f2fs
9. umount /mnt/f2fs

The reason is: during recovery, i_{c,m}time of inode will be updated, then
the inode can be set dirty w/o being tracked in sbi->inode_list[DIRTY_META]
global list, so later write_checkpoint will not flush such dirty inode into
node page.

Once umount is called, sync_filesystem() in generic_shutdown_super() will
skip syncng dirty inodes due to sb_rdonly check, leaving dirty inodes
there.

To solve this issue, during umount, add remove SB_RDONLY flag in
sb->s_flags, to make sure sync_filesystem() will not be skipped.

Signed-off-by: Chao Yu 

Signed-off-by: Jaegeuk Kim 

Signed-off-by: Sasha Levin 
---
 fs/f2fs/checkpoint.c |  2 ++
 fs/f2fs/f2fs.h   |  1 +
 fs/f2fs/recovery.c   | 14 +-
 fs/f2fs/super.c  |  3 +++
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index e8b6b89bddb8..59d0472013f4 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -696,6 +696,8 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
/* clear Orphan Flag */
clear_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG);
 out:
+   set_sbi_flag(sbi, SBI_IS_RECOVERED);
+
 #ifdef CONFIG_QUOTA
/* Turn quotas off */
if (quota_enabled)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e146e6c443e8..ecb735142276 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1089,6 +1089,7 @@ enum {
SBI_NEED_SB_WRITE,  /* need to recover superblock */
SBI_NEED_CP,/* need to checkpoint */
SBI_IS_SHUTDOWN,/* shutdown by ioctl */
+   SBI_IS_RECOVERED,   /* recovered orphan/data */
 };
 
 enum {
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index 12a3293bcbc9..9a8579fb3a30 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -698,11 +698,15 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, 
bool check_only)
/* let's drop all the directory inodes for clean checkpoint */
destroy_fsync_dnodes(_list);
 
-   if (!err && need_writecp) {
-   struct cp_control cpc = {
-   .reason = CP_RECOVERY,
-   };
-   err = f2fs_write_checkpoint(sbi, );
+   if (need_writecp) {
+   set_sbi_flag(sbi, SBI_IS_RECOVERED);
+
+   if (!err) {
+   struct cp_control cpc = {
+   .reason = CP_RECOVERY,
+   };
+   err = f2fs_write_checkpoint(sbi, );
+   }
}
 
kmem_cache_destroy(fsync_entry_slab);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index d0d016f21307..287c9fe9fff9 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -3188,6 +3188,9 @@ static void kill_f2fs_super(struct super_block *sb)
};
f2fs_write_checkpoint(sbi, );
}
+
+   if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb))
+   sb->s_flags &= ~SB_RDONLY;
}
kill_block_super(sb);
 }
-- 
2.17.1



[PATCH AUTOSEL 4.19 140/146] 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 896b885f504e..d0d016f21307 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1852,7 +1852,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 || f2fs_sb_has_quota_ino(sb))
@@ -1871,9 +1873,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++) {
+   err = f2fs_quota_off(sb, type);
+   if (err) {
+   int ret = dquot_quota_off(sb, type);
 
-   for (type = 0; type < MAXQUOTAS; type++)
-   f2fs_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);
+   }
+   }
 }
 
 static int f2fs_get_projid(struct inode *inode, kprojid_t *projid)
-- 
2.17.1



[PATCH AUTOSEL 4.19 136/146] 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 70a7981b94b3..9916edda5271 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -274,6 +274,8 @@ static struct class uio_class = {
.dev_groups = uio_groups,
 };
 
+bool uio_class_registered;
+
 /*
  * device functions
  */
@@ -876,6 +878,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:
@@ -886,6 +891,7 @@ static int init_uio_class(void)
 
 static void release_uio_class(void)
 {
+   uio_class_registered = false;
class_unregister(_class);
uio_major_cleanup();
 }
@@ -912,6 +918,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.19 141/146] 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 e4aad0e90882..092fb48ed845 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1035,7 +1035,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 = (type != PIDTYPE_PID) ? >signal->shared_pending : 
>pending;
-- 
2.17.1



[PATCH AUTOSEL 4.19 141/146] 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 e4aad0e90882..092fb48ed845 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1035,7 +1035,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 = (type != PIDTYPE_PID) ? >signal->shared_pending : 
>pending;
-- 
2.17.1



[PATCH AUTOSEL 4.19 143/146] mfd: menelaus: Fix possible race condition and leak

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

[ Upstream commit 9612f8f503804d2fd2f63aa6ba1e58bba4612d96 ]

The IRQ work is added before the struct rtc is allocated and registered,
but this struct is used in the IRQ handler. This may lead to a NULL pointer
dereference.

Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
before calling menelaus_add_irq_work.

Also, this solves a possible leak as the RTC is never released.

Signed-off-by: Alexandre Belloni 
Signed-off-by: Lee Jones 
Signed-off-by: Sasha Levin 
---
 drivers/mfd/menelaus.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/menelaus.c b/drivers/mfd/menelaus.c
index 29b7164a823b..d28ebe7ecd21 100644
--- a/drivers/mfd/menelaus.c
+++ b/drivers/mfd/menelaus.c
@@ -1094,6 +1094,7 @@ static void menelaus_rtc_alarm_work(struct menelaus_chip 
*m)
 static inline void menelaus_rtc_init(struct menelaus_chip *m)
 {
int alarm = (m->client->irq > 0);
+   int err;
 
/* assume 32KDETEN pin is pulled high */
if (!(menelaus_read_reg(MENELAUS_OSC_CTRL) & 0x80)) {
@@ -1101,6 +1102,12 @@ static inline void menelaus_rtc_init(struct 
menelaus_chip *m)
return;
}
 
+   m->rtc = devm_rtc_allocate_device(>client->dev);
+   if (IS_ERR(m->rtc))
+   return;
+
+   m->rtc->ops = _rtc_ops;
+
/* support RTC alarm; it can issue wakeups */
if (alarm) {
if (menelaus_add_irq_work(MENELAUS_RTCALM_IRQ,
@@ -1125,10 +1132,8 @@ static inline void menelaus_rtc_init(struct 
menelaus_chip *m)
menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control);
}
 
-   m->rtc = rtc_device_register(DRIVER_NAME,
-   >client->dev,
-   _rtc_ops, THIS_MODULE);
-   if (IS_ERR(m->rtc)) {
+   err = rtc_register_device(m->rtc);
+   if (err) {
if (alarm) {
menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ);
device_init_wakeup(>client->dev, 0);
-- 
2.17.1



[PATCH AUTOSEL 4.19 138/146] scsi: lpfc: Correct race with abort on completion path

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

[ Upstream commit ca7fb76e091f889cfda1287c07a9358f73832b39 ]

On io completion, the driver is taking an adapter wide lock and nulling the
scsi command back pointer.  The nulling of the back pointer is to signify the
io was completed and the scsi_done() routine was called.  However, the routine
makes no check to see if the abort routine had done the same thing and
possibly nulled the pointer. Thus it may doubly-complete the io.

Make the following mods:

- Check to make sure forward progress (call scsi_done()) only happens if the
  command pointer was non-null.

- As the taking of the lock, which is adapter wide, is very costly on a system
  under load, null the pointer using an xchg operation rather than under lock.

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_scsi.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 5c7858e735c9..200b5bca1f5f 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -4158,9 +4158,17 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct 
lpfc_iocbq *pIocbIn,
}
lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
 
-   spin_lock_irqsave(>hbalock, flags);
-   lpfc_cmd->pCmd = NULL;
-   spin_unlock_irqrestore(>hbalock, flags);
+   /* If pCmd was set to NULL from abort path, do not call scsi_done */
+   if (xchg(_cmd->pCmd, NULL) == NULL) {
+   lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
+"0711 FCP cmd already NULL, sid: 0x%06x, "
+"did: 0x%06x, oxid: 0x%04x\n",
+vport->fc_myDID,
+(pnode) ? pnode->nlp_DID : 0,
+phba->sli_rev == LPFC_SLI_REV4 ?
+lpfc_cmd->cur_iocbq.sli4_xritag : 0x);
+   return;
+   }
 
/* The sdev is not guaranteed to be valid post scsi_done upcall. */
cmd->scsi_done(cmd);
-- 
2.17.1



[PATCH AUTOSEL 4.19 143/146] mfd: menelaus: Fix possible race condition and leak

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

[ Upstream commit 9612f8f503804d2fd2f63aa6ba1e58bba4612d96 ]

The IRQ work is added before the struct rtc is allocated and registered,
but this struct is used in the IRQ handler. This may lead to a NULL pointer
dereference.

Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
before calling menelaus_add_irq_work.

Also, this solves a possible leak as the RTC is never released.

Signed-off-by: Alexandre Belloni 
Signed-off-by: Lee Jones 
Signed-off-by: Sasha Levin 
---
 drivers/mfd/menelaus.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/menelaus.c b/drivers/mfd/menelaus.c
index 29b7164a823b..d28ebe7ecd21 100644
--- a/drivers/mfd/menelaus.c
+++ b/drivers/mfd/menelaus.c
@@ -1094,6 +1094,7 @@ static void menelaus_rtc_alarm_work(struct menelaus_chip 
*m)
 static inline void menelaus_rtc_init(struct menelaus_chip *m)
 {
int alarm = (m->client->irq > 0);
+   int err;
 
/* assume 32KDETEN pin is pulled high */
if (!(menelaus_read_reg(MENELAUS_OSC_CTRL) & 0x80)) {
@@ -1101,6 +1102,12 @@ static inline void menelaus_rtc_init(struct 
menelaus_chip *m)
return;
}
 
+   m->rtc = devm_rtc_allocate_device(>client->dev);
+   if (IS_ERR(m->rtc))
+   return;
+
+   m->rtc->ops = _rtc_ops;
+
/* support RTC alarm; it can issue wakeups */
if (alarm) {
if (menelaus_add_irq_work(MENELAUS_RTCALM_IRQ,
@@ -1125,10 +1132,8 @@ static inline void menelaus_rtc_init(struct 
menelaus_chip *m)
menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control);
}
 
-   m->rtc = rtc_device_register(DRIVER_NAME,
-   >client->dev,
-   _rtc_ops, THIS_MODULE);
-   if (IS_ERR(m->rtc)) {
+   err = rtc_register_device(m->rtc);
+   if (err) {
if (alarm) {
menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ);
device_init_wakeup(>client->dev, 0);
-- 
2.17.1



[PATCH AUTOSEL 4.19 138/146] scsi: lpfc: Correct race with abort on completion path

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

[ Upstream commit ca7fb76e091f889cfda1287c07a9358f73832b39 ]

On io completion, the driver is taking an adapter wide lock and nulling the
scsi command back pointer.  The nulling of the back pointer is to signify the
io was completed and the scsi_done() routine was called.  However, the routine
makes no check to see if the abort routine had done the same thing and
possibly nulled the pointer. Thus it may doubly-complete the io.

Make the following mods:

- Check to make sure forward progress (call scsi_done()) only happens if the
  command pointer was non-null.

- As the taking of the lock, which is adapter wide, is very costly on a system
  under load, null the pointer using an xchg operation rather than under lock.

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_scsi.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 5c7858e735c9..200b5bca1f5f 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -4158,9 +4158,17 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct 
lpfc_iocbq *pIocbIn,
}
lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
 
-   spin_lock_irqsave(>hbalock, flags);
-   lpfc_cmd->pCmd = NULL;
-   spin_unlock_irqrestore(>hbalock, flags);
+   /* If pCmd was set to NULL from abort path, do not call scsi_done */
+   if (xchg(_cmd->pCmd, NULL) == NULL) {
+   lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
+"0711 FCP cmd already NULL, sid: 0x%06x, "
+"did: 0x%06x, oxid: 0x%04x\n",
+vport->fc_myDID,
+(pnode) ? pnode->nlp_DID : 0,
+phba->sli_rev == LPFC_SLI_REV4 ?
+lpfc_cmd->cur_iocbq.sli4_xritag : 0x);
+   return;
+   }
 
/* The sdev is not guaranteed to be valid post scsi_done upcall. */
cmd->scsi_done(cmd);
-- 
2.17.1



[PATCH AUTOSEL 4.18 006/126] 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 0e31884a9519..cbe909c51847 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -887,8 +887,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.18 007/126] arm64: cpufeature: ctr: Fix cpu capability check for late CPUs

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

[ Upstream commit 8ab66cbe63aeaf9e5970fb4aaef1c660fca59321 ]

The matches() routine for a capability must honor the "scope"
passed to it and return the proper results.
i.e, when passed with SCOPE_LOCAL_CPU, it should check the
status of the capability on the current CPU. This is used by
verify_local_cpu_capabilities() on a late secondary CPU to make
sure that it's compliant with the established system features.
However, ARM64_HAS_CACHE_{IDC/DIC} always checks the system wide
registers and this could mean that a late secondary CPU could return
"true" (since the CPU hasn't updated the system wide registers yet)
and thus lead the system in an inconsistent state, where
the system assumes it has IDC/DIC feature, while the new CPU
doesn't.

Fixes: commit 6ae4b6e0578886eb36 ("arm64: Add support for new control bits 
CTR_EL0.DIC and CTR_EL0.IDC")
Cc: Philip Elcan 
Cc: Shanker Donthineni 
Cc: Mark Rutland 
Cc: Will Deacon 
Signed-off-by: Suzuki K Poulose 
Signed-off-by: Catalin Marinas 
Signed-off-by: Sasha Levin 
---
 arch/arm64/kernel/cpufeature.c | 22 ++
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index e4103b718a7c..b687c80a9c10 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -847,15 +847,29 @@ static bool has_no_fpsimd(const struct 
arm64_cpu_capabilities *entry, int __unus
 }
 
 static bool has_cache_idc(const struct arm64_cpu_capabilities *entry,
- int __unused)
+ int scope)
 {
-   return read_sanitised_ftr_reg(SYS_CTR_EL0) & BIT(CTR_IDC_SHIFT);
+   u64 ctr;
+
+   if (scope == SCOPE_SYSTEM)
+   ctr = arm64_ftr_reg_ctrel0.sys_val;
+   else
+   ctr = read_cpuid_cachetype();
+
+   return ctr & BIT(CTR_IDC_SHIFT);
 }
 
 static bool has_cache_dic(const struct arm64_cpu_capabilities *entry,
- int __unused)
+ int scope)
 {
-   return read_sanitised_ftr_reg(SYS_CTR_EL0) & BIT(CTR_DIC_SHIFT);
+   u64 ctr;
+
+   if (scope == SCOPE_SYSTEM)
+   ctr = arm64_ftr_reg_ctrel0.sys_val;
+   else
+   ctr = read_cpuid_cachetype();
+
+   return ctr & BIT(CTR_DIC_SHIFT);
 }
 
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
-- 
2.17.1



[PATCH AUTOSEL 4.18 001/126] net: socionext: Reset tx queue in ndo_stop

2018-10-31 Thread Sasha Levin
From: Masahisa Kojima 

[ Upstream commit 8d5b0bf611ec5b7618d5b772dddc93b8afa78cb8 ]

We observed that packets and bytes count are not reset
when user performs interface down. Eventually, tx queue is
exhausted and packets will not be sent out.
To avoid this problem, resets tx queue in ndo_stop.

Fixes: 533dd11a12f6 ("net: socionext: Add Synquacer NetSec driver")
Signed-off-by: Masahisa Kojima 
Signed-off-by: Yoshitoyo Osaki 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/socionext/netsec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/socionext/netsec.c 
b/drivers/net/ethernet/socionext/netsec.c
index e080d3e7c582..4d7d53fbc0ef 100644
--- a/drivers/net/ethernet/socionext/netsec.c
+++ b/drivers/net/ethernet/socionext/netsec.c
@@ -945,6 +945,9 @@ static void netsec_uninit_pkt_dring(struct netsec_priv 
*priv, int id)
dring->head = 0;
dring->tail = 0;
dring->pkt_cnt = 0;
+
+   if (id == NETSEC_RING_TX)
+   netdev_reset_queue(priv->ndev);
 }
 
 static void netsec_free_dring(struct netsec_priv *priv, int id)
-- 
2.17.1



[PATCH AUTOSEL 4.19 146/146] 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 aa4c672dbaf7..e54e8a552111 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -412,7 +412,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);
@@ -1678,6 +1678,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;
}
 
@@ -1698,8 +1699,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)
@@ -2138,7 +2143,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.18 006/126] 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 0e31884a9519..cbe909c51847 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -887,8 +887,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.18 007/126] arm64: cpufeature: ctr: Fix cpu capability check for late CPUs

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

[ Upstream commit 8ab66cbe63aeaf9e5970fb4aaef1c660fca59321 ]

The matches() routine for a capability must honor the "scope"
passed to it and return the proper results.
i.e, when passed with SCOPE_LOCAL_CPU, it should check the
status of the capability on the current CPU. This is used by
verify_local_cpu_capabilities() on a late secondary CPU to make
sure that it's compliant with the established system features.
However, ARM64_HAS_CACHE_{IDC/DIC} always checks the system wide
registers and this could mean that a late secondary CPU could return
"true" (since the CPU hasn't updated the system wide registers yet)
and thus lead the system in an inconsistent state, where
the system assumes it has IDC/DIC feature, while the new CPU
doesn't.

Fixes: commit 6ae4b6e0578886eb36 ("arm64: Add support for new control bits 
CTR_EL0.DIC and CTR_EL0.IDC")
Cc: Philip Elcan 
Cc: Shanker Donthineni 
Cc: Mark Rutland 
Cc: Will Deacon 
Signed-off-by: Suzuki K Poulose 
Signed-off-by: Catalin Marinas 
Signed-off-by: Sasha Levin 
---
 arch/arm64/kernel/cpufeature.c | 22 ++
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index e4103b718a7c..b687c80a9c10 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -847,15 +847,29 @@ static bool has_no_fpsimd(const struct 
arm64_cpu_capabilities *entry, int __unus
 }
 
 static bool has_cache_idc(const struct arm64_cpu_capabilities *entry,
- int __unused)
+ int scope)
 {
-   return read_sanitised_ftr_reg(SYS_CTR_EL0) & BIT(CTR_IDC_SHIFT);
+   u64 ctr;
+
+   if (scope == SCOPE_SYSTEM)
+   ctr = arm64_ftr_reg_ctrel0.sys_val;
+   else
+   ctr = read_cpuid_cachetype();
+
+   return ctr & BIT(CTR_IDC_SHIFT);
 }
 
 static bool has_cache_dic(const struct arm64_cpu_capabilities *entry,
- int __unused)
+ int scope)
 {
-   return read_sanitised_ftr_reg(SYS_CTR_EL0) & BIT(CTR_DIC_SHIFT);
+   u64 ctr;
+
+   if (scope == SCOPE_SYSTEM)
+   ctr = arm64_ftr_reg_ctrel0.sys_val;
+   else
+   ctr = read_cpuid_cachetype();
+
+   return ctr & BIT(CTR_DIC_SHIFT);
 }
 
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
-- 
2.17.1



[PATCH AUTOSEL 4.18 001/126] net: socionext: Reset tx queue in ndo_stop

2018-10-31 Thread Sasha Levin
From: Masahisa Kojima 

[ Upstream commit 8d5b0bf611ec5b7618d5b772dddc93b8afa78cb8 ]

We observed that packets and bytes count are not reset
when user performs interface down. Eventually, tx queue is
exhausted and packets will not be sent out.
To avoid this problem, resets tx queue in ndo_stop.

Fixes: 533dd11a12f6 ("net: socionext: Add Synquacer NetSec driver")
Signed-off-by: Masahisa Kojima 
Signed-off-by: Yoshitoyo Osaki 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/socionext/netsec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/socionext/netsec.c 
b/drivers/net/ethernet/socionext/netsec.c
index e080d3e7c582..4d7d53fbc0ef 100644
--- a/drivers/net/ethernet/socionext/netsec.c
+++ b/drivers/net/ethernet/socionext/netsec.c
@@ -945,6 +945,9 @@ static void netsec_uninit_pkt_dring(struct netsec_priv 
*priv, int id)
dring->head = 0;
dring->tail = 0;
dring->pkt_cnt = 0;
+
+   if (id == NETSEC_RING_TX)
+   netdev_reset_queue(priv->ndev);
 }
 
 static void netsec_free_dring(struct netsec_priv *priv, int id)
-- 
2.17.1



[PATCH AUTOSEL 4.19 146/146] 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 aa4c672dbaf7..e54e8a552111 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -412,7 +412,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);
@@ -1678,6 +1678,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;
}
 
@@ -1698,8 +1699,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)
@@ -2138,7 +2143,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.18 003/126] locking/lockdep: Fix debug_locks off performance problem

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

[ Upstream commit 9506a7425b094d2f1d9c877ed5a78f416669269b ]

It was found that when debug_locks was turned off because of a problem
found by the lockdep code, the system performance could drop quite
significantly when the lock_stat code was also configured into the
kernel. For instance, parallel kernel build time on a 4-socket x86-64
server nearly doubled.

Further analysis into the cause of the slowdown traced back to the
frequent call to debug_locks_off() from the __lock_acquired() function
probably due to some inconsistent lockdep states with debug_locks
off. The debug_locks_off() function did an unconditional atomic xchg
to write a 0 value into debug_locks which had already been set to 0.
This led to severe cacheline contention in the cacheline that held
debug_locks.  As debug_locks is being referenced in quite a few different
places in the kernel, this greatly slow down the system performance.

To prevent that trashing of debug_locks cacheline, lock_acquired()
and lock_contended() now checks the state of debug_locks before
proceeding. The debug_locks_off() function is also modified to check
debug_locks before calling __debug_locks_off().

Signed-off-by: Waiman Long 
Cc: Andrew Morton 
Cc: Linus Torvalds 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Link: 
http://lkml.kernel.org/r/1539913518-15598-1-git-send-email-long...@redhat.com
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 kernel/locking/lockdep.c | 4 ++--
 lib/debug_locks.c| 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 5fa4d3138bf1..aa6ebb799f16 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -4148,7 +4148,7 @@ void lock_contended(struct lockdep_map *lock, unsigned 
long ip)
 {
unsigned long flags;
 
-   if (unlikely(!lock_stat))
+   if (unlikely(!lock_stat || !debug_locks))
return;
 
if (unlikely(current->lockdep_recursion))
@@ -4168,7 +4168,7 @@ void lock_acquired(struct lockdep_map *lock, unsigned 
long ip)
 {
unsigned long flags;
 
-   if (unlikely(!lock_stat))
+   if (unlikely(!lock_stat || !debug_locks))
return;
 
if (unlikely(current->lockdep_recursion))
diff --git a/lib/debug_locks.c b/lib/debug_locks.c
index 96c4c633d95e..124fdf238b3d 100644
--- a/lib/debug_locks.c
+++ b/lib/debug_locks.c
@@ -37,7 +37,7 @@ EXPORT_SYMBOL_GPL(debug_locks_silent);
  */
 int debug_locks_off(void)
 {
-   if (__debug_locks_off()) {
+   if (debug_locks && __debug_locks_off()) {
if (!debug_locks_silent) {
console_verbose();
return 1;
-- 
2.17.1



[PATCH AUTOSEL 4.18 010/126] 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/kernel/sthyi.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/s390/kernel/sthyi.c b/arch/s390/kernel/sthyi.c
index 0859cde36f75..888cc2f166db 100644
--- a/arch/s390/kernel/sthyi.c
+++ b/arch/s390/kernel/sthyi.c
@@ -183,17 +183,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.18 005/126] 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 dfb2c2622e5a..822e3060d834 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1935,6 +1935,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)
@@ -1966,10 +1971,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);
}
@@ -1984,13 +1985,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.18 004/126] netfilter: xt_nat: fix DNAT target for shifted portmap ranges

2018-10-31 Thread Sasha Levin
From: Paolo Abeni 

[ Upstream commit cb20f2d2c0507d60d94ef896991e95708f051dd1 ]

The commit 2eb0f624b709 ("netfilter: add NAT support for shifted
portmap ranges") did not set the checkentry/destroy callbacks for
the newly added DNAT target. As a result, rulesets using only
such nat targets are not effective, as the relevant conntrack hooks
are not enabled.
The above affect also nft_compat rulesets.
Fix the issue adding the missing initializers.

Fixes: 2eb0f624b709 ("netfilter: add NAT support for shifted portmap ranges")
Signed-off-by: Paolo Abeni 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Sasha Levin 
---
 net/netfilter/xt_nat.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/xt_nat.c b/net/netfilter/xt_nat.c
index 8af9707f8789..ac91170fc8c8 100644
--- a/net/netfilter/xt_nat.c
+++ b/net/netfilter/xt_nat.c
@@ -216,6 +216,8 @@ static struct xt_target xt_nat_target_reg[] __read_mostly = 
{
{
.name   = "DNAT",
.revision   = 2,
+   .checkentry = xt_nat_checkentry,
+   .destroy= xt_nat_destroy,
.target = xt_dnat_target_v2,
.targetsize = sizeof(struct nf_nat_range2),
.table  = "nat",
-- 
2.17.1



<    1   2   3   4   5   6   7   8   9   10   >