[PATCH 3.18 15/26] tipc: fix cleanup at module unload

2017-12-07 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Parthasarathy Bhuvaragan 


[ Upstream commit 35e22e49a5d6a741ebe7f2dd280b2052c3003ef7 ]

In tipc_server_stop(), we iterate over the connections with limiting
factor as server's idr_in_use. We ignore the fact that this variable
is decremented in tipc_close_conn(), leading to premature exit.

In this commit, we iterate until the we have no connections left.

Acked-by: Ying Xue 
Acked-by: Jon Maloy 
Tested-by: John Thompson 
Signed-off-by: Parthasarathy Bhuvaragan 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 net/tipc/server.c |4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

--- a/net/tipc/server.c
+++ b/net/tipc/server.c
@@ -579,14 +579,12 @@ int tipc_server_start(struct tipc_server
 void tipc_server_stop(struct tipc_server *s)
 {
struct tipc_conn *con;
-   int total = 0;
int id;
 
spin_lock_bh(&s->idr_lock);
-   for (id = 0; total < s->idr_in_use; id++) {
+   for (id = 0; s->idr_in_use; id++) {
con = idr_find(&s->conn_idr, id);
if (con) {
-   total++;
spin_unlock_bh(&s->idr_lock);
tipc_close_conn(con);
spin_lock_bh(&s->idr_lock);




[PATCH 3.18 24/26] USB: devio: Prevent integer overflow in proc_do_submiturb()

2017-12-07 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Dan Carpenter 

commit 57999d1107c1e60c2ca7088f2ac0f819e2f554b3 upstream.

There used to be an integer overflow check in proc_do_submiturb() but
we removed it.  It turns out that it's still required.  The
uurb->buffer_length variable is a signed integer and it's controlled by
the user.  It can lead to an integer overflow when we do:

num_sgs = DIV_ROUND_UP(uurb->buffer_length, USB_SG_SIZE);

If we strip away the macro then that line looks like this:

num_sgs = (uurb->buffer_length + USB_SG_SIZE - 1) / USB_SG_SIZE;
   ^
It's the first addition which can overflow.

Fixes: 1129d270cbfb ("USB: Increase usbfs transfer limit")
Signed-off-by: Dan Carpenter 
Acked-by: Alan Stern 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/devio.c |5 +
 1 file changed, 5 insertions(+)

--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -118,6 +118,9 @@ module_param(usbfs_memory_mb, uint, 0644
 MODULE_PARM_DESC(usbfs_memory_mb,
"maximum MB allowed for usbfs buffers (0 = no limit)");
 
+/* Hard limit, necessary to avoid arithmetic overflow */
+#define USBFS_XFER_MAX (UINT_MAX / 2 - 100)
+
 static atomic64_t usbfs_memory_usage;  /* Total memory currently allocated */
 
 /* Check whether it's okay to allocate more memory for a transfer */
@@ -1295,6 +1298,8 @@ static int proc_do_submiturb(struct usb_
USBDEVFS_URB_ZERO_PACKET |
USBDEVFS_URB_NO_INTERRUPT))
return -EINVAL;
+   if ((unsigned int)uurb->buffer_length >= USBFS_XFER_MAX)
+   return -EINVAL;
if (uurb->buffer_length > 0 && !uurb->buffer)
return -EINVAL;
if (!(uurb->type == USBDEVFS_URB_TYPE_CONTROL &&




[PATCH 3.18 14/26] net: sctp: fix array overrun read on sctp_timer_tbl

2017-12-07 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 


[ Upstream commit 0e73fc9a56f22f2eec4d2b2910c649f7af67b74d ]

The comparison on the timeout can lead to an array overrun
read on sctp_timer_tbl because of an off-by-one error. Fix
this by using < instead of <= and also compare to the array
size rather than SCTP_EVENT_TIMEOUT_MAX.

Fixes CoverityScan CID#1397639 ("Out-of-bounds read")

Signed-off-by: Colin Ian King 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 net/sctp/debug.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/sctp/debug.c
+++ b/net/sctp/debug.c
@@ -166,7 +166,7 @@ static const char *const sctp_timer_tbl[
 /* Lookup timer debug name. */
 const char *sctp_tname(const sctp_subtype_t id)
 {
-   if (id.timeout <= SCTP_EVENT_TIMEOUT_MAX)
+   if (id.timeout < ARRAY_SIZE(sctp_timer_tbl))
return sctp_timer_tbl[id.timeout];
return "unknown_timer";
 }




[PATCH 3.18 09/26] ARM: OMAP1: DMA: Correct the number of logical channels

2017-12-07 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Peter Ujfalusi 


[ Upstream commit 657279778af54f35e54b07b6687918f254a2992c ]

OMAP1510, OMAP5910 and OMAP310 have only 9 logical channels.
OMAP1610, OMAP5912, OMAP1710, OMAP730, and OMAP850 have 16 logical channels
available.

The wired 17 for the lch_count must have been used to cover the 16 + 1
dedicated LCD channel, in reality we can only use 9 or 16 channels.

The d->chan_count is not used by the omap-dma stack, so we can skip the
setup. chan_count was configured to the number of logical channels and not
the actual number of physical channels anyways.

Signed-off-by: Peter Ujfalusi 
Acked-by: Aaro Koskinen 
Signed-off-by: Tony Lindgren 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 arch/arm/mach-omap1/dma.c |   16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

--- a/arch/arm/mach-omap1/dma.c
+++ b/arch/arm/mach-omap1/dma.c
@@ -31,7 +31,6 @@
 #include 
 
 #define OMAP1_DMA_BASE (0xfffed800)
-#define OMAP1_LOGICAL_DMA_CH_COUNT 17
 
 static u32 enable_1510_mode;
 
@@ -311,8 +310,6 @@ static int __init omap1_system_dma_init(
goto exit_iounmap;
}
 
-   d->lch_count= OMAP1_LOGICAL_DMA_CH_COUNT;
-
/* Valid attributes for omap1 plus processors */
if (cpu_is_omap15xx())
d->dev_caps = ENABLE_1510_MODE;
@@ -329,13 +326,14 @@ static int __init omap1_system_dma_init(
d->dev_caps |= CLEAR_CSR_ON_READ;
d->dev_caps |= IS_WORD_16;
 
-   if (cpu_is_omap15xx())
-   d->chan_count = 9;
-   else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
-   if (!(d->dev_caps & ENABLE_1510_MODE))
-   d->chan_count = 16;
+   /* available logical channels */
+   if (cpu_is_omap15xx()) {
+   d->lch_count = 9;
+   } else {
+   if (d->dev_caps & ENABLE_1510_MODE)
+   d->lch_count = 9;
else
-   d->chan_count = 9;
+   d->lch_count = 16;
}
 
p = dma_plat_info;




[PATCH 3.18 08/26] perf test attr: Fix ignored test case result

2017-12-07 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Thomas Richter 


[ Upstream commit 22905582f6dd4bbd0c370fe5732c607452010c04 ]

Command perf test -v 16 (Setup struct perf_event_attr test) always
reports success even if the test case fails.  It works correctly if you
also specify -F (for don't fork).

   root@s35lp76 perf]# ./perf test -v 16
   15: Setup struct perf_event_attr   :
   --- start ---
   running './tests/attr/test-record-no-delay'
   [ perf record: Woken up 1 times to write data ]
   [ perf record: Captured and wrote 0.002 MB /tmp/tmp4E1h7R/perf.data
 (1 samples) ]
   expected task=0, got 1
   expected precise_ip=0, got 3
   expected wakeup_events=1, got 0
   FAILED './tests/attr/test-record-no-delay' - match failure
   test child finished with 0
    end 
   Setup struct perf_event_attr: Ok

The reason for the wrong error reporting is the return value of the
system() library call. It is called in run_dir() file tests/attr.c and
returns the exit status, in above case 0xff00.

This value is given as parameter to the exit() function which can only
handle values 0-0xff.

The child process terminates with exit value of 0 and the parent does
not detect any error.

This patch corrects the error reporting and prints the correct test
result.

Signed-off-by: Thomas-Mich Richter 
Acked-by: Jiri Olsa 
Cc: Heiko Carstens 
Cc: Hendrik Brueckner 
Cc: Martin Schwidefsky 
Cc: Thomas-Mich Richter 
LPU-Reference: 20170913081209.39570-2-tmri...@linux.vnet.ibm.com
Link: http://lkml.kernel.org/n/tip-rdube6rfcjsr1nzue72c7...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 tools/perf/tests/attr.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/tools/perf/tests/attr.c
+++ b/tools/perf/tests/attr.c
@@ -150,7 +150,7 @@ static int run_dir(const char *d, const
snprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s",
 d, d, perf, vcnt, v);
 
-   return system(cmd);
+   return system(cmd) ? TEST_FAIL : TEST_OK;
 }
 
 int test__attr(void)




Re: [PATCH v3 15/16] iommu: introduce page response function

2017-12-07 Thread Jean-Philippe Brucker
On 06/12/17 19:25, Jacob Pan wrote:
[...]
>>   For SMMUv3, the stall buffer may be shared between devices on some
>>   implementations, in which case the guest could prevent other
>> devices to stall by letting the buffer fill up.
>>   -> We might have to keep track of stalls in the host driver and set
>> a credit or timeout to each stall, if it comes to that.
>>   -> In addition, send a terminate-all-stalls command when changing
>> the device's domain.
>>
> We have the same situation in VT-d with shared queue which in turn may
> affect other guests. Letting host driver maintain record of pending page
> request seems the best way to go. VT-d has a way to drain PRQ per PASID
> and RID combination. I guess this is the same as your
> "terminate-all-stalls" but with finer control? Or
> "terminate-all-stalls" only applies to a given device.

That command terminates all stalls for a given device (for all PASIDs).
It's a bit awkward to implement but should be enough to ensure that we
don't leak any outstanding faults to the next VM.

> Seems we can implement a generic timeout/credit mechanism in IOMMU
> driver with model specific action to drain/terminate. The timeout value
> can also be model specific.

Sounds good. Timeout seems a bit complicated to implement (and how do we
guess what timeout would work?), so maybe it's simpler to enforce a quota
of outstanding faults per VM, for example half of the shared queue size
(the number can be chosen by the IOMMU driver). If a VM has that many
outstanding faults, then any new fault is immediately terminated by the
host. A bit rough but it might be enough to mitigate the problem
initially, and we can always tweak it later (for instance disable faulting
if a guest doesn't ever reply).

Seems like VFIO should enforce this quota, since the IOMMU layer doesn't
know which device is assigned to which VM. If it's the IOMMU that enforces
quotas per device and a VM has 15 devices assigned, then the guest can
still DoS the IOMMU.

[...]
>>> + * @type: group or stream response  
>>
>> The page request doesn't provide this information
>>
> this is vt-d specific. it is in the vt-d page request descriptor and
> response descriptors are different depending on the type.
> Since we intend the generic data to be super set of models, I add this
> field.

But don't you need to add the stream type to enum iommu_fault_type, in
patch 8? Otherwise the guest can't know what type to set in the response.

Thanks,
Jean



[PATCH 3.18 07/26] usbip: tools: Install all headers needed for libusbip development

2017-12-07 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Ben Hutchings 


[ Upstream commit c15562c0dcb2c7f26e891923b784cf1926b8c833 ]

usbip_host_driver.h now depends on several additional headers, which
need to be installed along with it.

Fixes: 021aed845303 ("staging: usbip: userspace: migrate usbip_host_driver ...")
Fixes: 3391ba0e2792 ("usbip: tools: Extract generic code to be shared with ...")
Signed-off-by: Ben Hutchings 
Acked-by: Shuah Khan 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 tools/usb/usbip/Makefile.am |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/tools/usb/usbip/Makefile.am
+++ b/tools/usb/usbip/Makefile.am
@@ -1,6 +1,7 @@
 SUBDIRS := libsrc src
 includedir = @includedir@/usbip
 include_HEADERS := $(addprefix libsrc/, \
-usbip_common.h vhci_driver.h usbip_host_driver.h)
+usbip_common.h vhci_driver.h usbip_host_driver.h \
+list.h sysfs_utils.h usbip_host_common.h)
 
 dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8)




[PATCH 3.18 12/26] nfs: Dont take a reference on fl->fl_file for LOCK operation

2017-12-07 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Benjamin Coddington 


[ Upstream commit 4b09ec4b14a168bf2c687e1f598140c3c11e9222 ]

I have reports of a crash that look like __fput() was called twice for
a NFSv4.0 file.  It seems possible that the state manager could try to
reclaim a lock and take a reference on the fl->fl_file at the same time the
file is being released if, during the close(), a signal interrupts the wait
for outstanding IO while removing locks which then skips the removal
of that lock.

Since 83bfff23e9ed ("nfs4: have do_vfs_lock take an inode pointer") has
removed the need to traverse fl->fl_file->f_inode in nfs4_lock_done(),
taking that reference is no longer necessary.

Signed-off-by: Benjamin Coddington 
Reviewed-by: Jeff Layton 
Signed-off-by: Trond Myklebust 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 fs/nfs/nfs4proc.c |3 ---
 1 file changed, 3 deletions(-)

--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -38,7 +38,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -5544,7 +5543,6 @@ static struct nfs4_lockdata *nfs4_alloc_
p->server = server;
atomic_inc(&lsp->ls_count);
p->ctx = get_nfs_open_context(ctx);
-   get_file(fl->fl_file);
memcpy(&p->fl, fl, sizeof(p->fl));
return p;
 out_free_seqid:
@@ -5634,7 +5632,6 @@ static void nfs4_lock_release(void *call
nfs_free_seqid(data->arg.lock_seqid);
nfs4_put_lock_state(data->lsp);
put_nfs_open_context(data->ctx);
-   fput(data->fl.fl_file);
kfree(data);
dprintk("%s: done!\n", __func__);
 }




[PATCH 3.18 02/26] bcache: recover data from backing when data is clean

2017-12-07 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Rui Hua 

commit e393aa2446150536929140739f09c6ecbcbea7f0 upstream.

When we send a read request and hit the clean data in cache device, there
is a situation called cache read race in bcache(see the commit in the tail
of cache_look_up(), the following explaination just copy from there):
The bucket we're reading from might be reused while our bio is in flight,
and we could then end up reading the wrong data. We guard against this
by checking (in bch_cache_read_endio()) if the pointer is stale again;
if so, we treat it as an error (s->iop.error = -EINTR) and reread from
the backing device (but we don't pass that error up anywhere)

It should be noted that cache read race happened under normal
circumstances, not the circumstance when SSD failed, it was counted
and shown in  /sys/fs/bcache/XXX/internal/cache_read_races.

Without this patch, when we use writeback mode, we will never reread from
the backing device when cache read race happened, until the whole cache
device is clean, because the condition
(s->recoverable && (dc && !atomic_read(&dc->has_dirty))) is false in
cached_dev_read_error(). In this situation, the s->iop.error(= -EINTR)
will be passed up, at last, user will receive -EINTR when it's bio end,
this is not suitable, and wield to up-application.

In this patch, we use s->read_dirty_data to judge whether the read
request hit dirty data in cache device, it is safe to reread data from
the backing device when the read request hit clean data. This can not
only handle cache read race, but also recover data when failed read
request from cache device.

[edited by mlyle to fix up whitespace, commit log title, comment
spelling]

Fixes: d59b23795933 ("bcache: only permit to recovery read error when cache 
device is clean")
Signed-off-by: Hua Rui 
Reviewed-by: Michael Lyle 
Reviewed-by: Coly Li 
Signed-off-by: Michael Lyle 
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/md/bcache/request.c |   13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -705,16 +705,15 @@ static void cached_dev_read_error(struct
 {
struct search *s = container_of(cl, struct search, cl);
struct bio *bio = &s->bio.bio;
-   struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
 
/*
-* If cache device is dirty (dc->has_dirty is non-zero), then
-* recovery a failed read request from cached device may get a
-* stale data back. So read failure recovery is only permitted
-* when cache device is clean.
+* If read request hit dirty data (s->read_dirty_data is true),
+* then recovery a failed read request from cached device may
+* get a stale data back. So read failure recovery is only
+* permitted when read request hit clean data in cache device,
+* or when cache read race happened.
 */
-   if (s->recoverable &&
-   (dc && !atomic_read(&dc->has_dirty))) {
+   if (s->recoverable && !s->read_dirty_data) {
/* Retry from the backing device: */
trace_bcache_read_retry(s->orig_bio);
 




[PATCH 3.18 10/26] vti6: fix device register to report IFLA_INFO_KIND

2017-12-07 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: David Forster 


[ Upstream commit 93e246f783e6bd1bc64fdfbfe68b18161f69b28e ]

vti6 interface is registered before the rtnl_link_ops block
is attached. As a result the resulting RTM_NEWLINK is missing
IFLA_INFO_KIND. Re-order attachment of rtnl_link_ops block to fix.

Signed-off-by: Dave Forster 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 net/ipv6/ip6_vti.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/ipv6/ip6_vti.c
+++ b/net/ipv6/ip6_vti.c
@@ -172,12 +172,12 @@ static int vti6_tnl_create2(struct net_d
struct vti6_net *ip6n = net_generic(net, vti6_net_id);
int err;
 
+   dev->rtnl_link_ops = &vti6_link_ops;
err = register_netdevice(dev);
if (err < 0)
goto out;
 
strcpy(t->parms.name, dev->name);
-   dev->rtnl_link_ops = &vti6_link_ops;
 
dev_hold(dev);
vti6_tnl_link(ip6n, t);




Re: [PATCH] cpufreq: longhaul: Set transition_delay_us to 20 ms

2017-12-07 Thread Rafael J. Wysocki
On Thursday, December 7, 2017 1:51:04 PM CET Meelis Roos wrote:
> > On 06-12-17, 20:21, Meelis Roos wrote:
> > > 3 was not reliable.
> > > 
> > > I created root cron job
> > > @reboot sleep 120; /sbin/reboot
> > > 
> > > and by the evening it was dead again.
> > > 
> > > Will try 5 tomorrow.
> > 
> > Lets make it similar to what it was before my original patch modified
> > it, to avoid all corner cases.
> > 
> > Please test against 200 ms, 20 value here.
> 
> I tried
> 
> policy->transition_delay_us = 20;
> 
> and it still hangs on top of mainline.
> 
> What next?

Well, please try to revert the commit you bisected the problem to and see
if that doesn't hang.



Re: [RFC] vfio/type1: Add IOVA_RANGE capability support

2017-12-07 Thread Pierre Morel

On 06/12/2017 17:15, Shameerali Kolothum Thodi wrote:

Hi Pierre,


-Original Message-
From: Shameerali Kolothum Thodi
Sent: Wednesday, December 06, 2017 4:08 PM
To: alex.william...@redhat.com; eric.au...@redhat.com;
pmo...@linux.vnet.ibm.com
Cc: k...@vger.kernel.org; linux-kernel@vger.kernel.org; Linuxarm
; Shameerali Kolothum Thodi

Subject: [RFC] vfio/type1: Add IOVA_RANGE capability support

This patch allows the user-space to retrieve the supported
IOVA range(s), excluding any reserved regions. The implementation
is based on capability chains, added to the VFIO_IOMMU_GET_INFO ioctl.

This is following the discussions here[1] and is based on the RFC patch[2].

ToDo:
  - This currently derives the default supported iova range from the first
iommu domain. This needs to be changed to go through the domain_list
instead.
  - Sync with Pierre's patch[3].


Thanks to Eric[1], came to know that you have posted a patch to retrieve the
iommu aperture info. This RFC does a similar thing but try to take care of
any reserved regions and adds to the capability chain.

Please take a look and if there is a possibility to sync up your next revision
and this, please let me know.


Hi Shameer,

Indeed it is close to what I was developing.

I have a single concern, the aperture is strongly hardware related while 
reserved areas are much more flexible.


As a consequence, I think it would be better if they were handled in 
separate capabilities and let the user space decide if it wants to know 
about one or the other.


For my immediate needs, this patch would be OK since we (s390x) do not 
use reserved regions.


@Alex: what do you prefer
If we need two capabilities, I will send the patch serie I made on the 
aperture capability for VFIO IOMMU.

If not I will use Shameer's patch.

Thanks,

Best regards,

Pierre



Thanks,
Shameer

1. https://patchwork.kernel.org/patch/10056967/


1.https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg03651.html
2.https://lists.linuxfoundation.org/pipermail/iommu/2016-
November/019002.html
3.https://patchwork.kernel.org/patch/10084655/

Signed-off-by: Shameer Kolothum 
---
  drivers/vfio/vfio_iommu_type1.c | 172
+++-
  include/uapi/linux/vfio.h   |  13 +++
  2 files changed, 184 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index e30e29a..72ca78a 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -28,6 +28,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -92,6 +93,12 @@ struct vfio_group {
struct list_headnext;
  };

+struct vfio_iommu_iova {
+   struct list_headlist;
+   phys_addr_t start;
+   phys_addr_t end;
+};
+
  /*
   * Guest RAM pinning working set or DMA target
   */
@@ -1537,6 +1544,144 @@ static int vfio_domains_have_iommu_cache(struct
vfio_iommu *iommu)
return ret;
  }

+static int vfio_add_iova_cap(struct vfio_info_cap *caps, u64 start, u64 end)
+{
+   struct vfio_iommu_type1_info_cap_iova_range *cap;
+   struct vfio_info_cap_header *header;
+
+   header = vfio_info_cap_add(caps, sizeof(*cap),
+   VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE, 1);
+   if (IS_ERR(header))
+   return PTR_ERR(header);
+
+   cap = container_of(header,
+  struct vfio_iommu_type1_info_cap_iova_range,
+  header);
+
+   cap->start = start;
+   cap->end = end;
+
+   return 0;
+}
+
+static int vfio_insert_iova(phys_addr_t start, phys_addr_t end,
+   struct list_head *head)
+{
+   struct vfio_iommu_iova *region;
+
+   region = kzalloc(sizeof(*region), GFP_KERNEL);
+   if (!region)
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(®ion->list);
+   region->start = start;
+   region->end = end;
+
+   list_add_tail(®ion->list, head);
+   return 0;
+}
+
+/*
+ * Check and update iova region list in case a reserved region
+ * overlaps the iommu iova range.
+ */
+static int vfio_update_iommu_iova_range(phys_addr_t start, phys_addr_t end,
+   struct list_head *iova)
+{
+   struct vfio_iommu_iova *node;
+   phys_addr_t a, b;
+   int ret = 0;
+
+   if (list_empty(iova))
+   return -ENODEV;
+
+   node = list_last_entry(iova, struct vfio_iommu_iova, list);
+   a = node->start;
+   b = node->end;
+
+   /* No overlap */
+   if ((start > b) || (end < a))
+   return 0;
+
+   if (start > a)
+   ret = vfio_insert_iova(a, start - 1, &node->list);
+   if (ret)
+   goto done;
+   if (end < b)
+   ret = vfio_insert_iova(end + 1, b, &node->list);
+
+done:
+   list_del(&node->list);
+   kfree(node);
+
+   return ret;
+}
+
+static int vfio_resv_cmp(v

Re: [PATCH] s390/decompressor: add fortify_panic as x86 has.

2017-12-07 Thread Martin Schwidefsky
On Thu,  7 Dec 2017 11:37:27 +0100
Michal Suchanek  wrote:

> Fix following error:
> 
>   LD  arch/s390/boot/compressed/vmlinux
> drivers/s390/char/sclp_early_core.o: In function `memcpy':
> ../include/linux/string.h:340: undefined reference to `fortify_panic'
> make[4]: *** [../arch/s390/boot/compressed/Makefile:29: 
> arch/s390/boot/compressed/vmlinux] Error 1
> 
> Fixes: 79962038dffa ("s390: add support for FORTIFY_SOURCE")
> Signed-off-by: Michal Suchanek 
> ---
>  arch/s390/boot/compressed/misc.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/s390/boot/compressed/misc.c 
> b/arch/s390/boot/compressed/misc.c
> index cecf38b9ec82..e79c4499c548 100644
> --- a/arch/s390/boot/compressed/misc.c
> +++ b/arch/s390/boot/compressed/misc.c
> @@ -174,3 +174,7 @@ unsigned long decompress_kernel(void)
>   return (unsigned long) output;
>  }
> 
> +void fortify_panic(const char *name)
> +{
> + error("detected buffer overflow");
> +}

Odd, the current linux master tree builds just fine with 
CONFIG_FORTIFY_SOURCE=y.
There *is* a reference to fortify_panic in drivers/s390/char/sclp_early.o.
This object is included in the link for the compressed vmlinux, but the
function  that contains the call to fortify_panic is not included in the
compressed image. I wonder what causes this difference in behavior.

The patch makes sense though and I will add it to the queue.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.



[PATCH 4.9 001/109] bcache: only permit to recovery read error when cache device is clean

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Coly Li 

commit d59b23795933678c9638fd20c942d2b4f3cd6185 upstream.

When bcache does read I/Os, for example in writeback or writethrough mode,
if a read request on cache device is failed, bcache will try to recovery
the request by reading from cached device. If the data on cached device is
not synced with cache device, then requester will get a stale data.

For critical storage system like database, providing stale data from
recovery may result an application level data corruption, which is
unacceptible.

With this patch, for a failed read request in writeback or writethrough
mode, recovery a recoverable read request only happens when cache device
is clean. That is to say, all data on cached device is up to update.

For other cache modes in bcache, read request will never hit
cached_dev_read_error(), they don't need this patch.

Please note, because cache mode can be switched arbitrarily in run time, a
writethrough mode might be switched from a writeback mode. Therefore
checking dc->has_data in writethrough mode still makes sense.

Changelog:
V4: Fix parens error pointed by Michael Lyle.
v3: By response from Kent Oversteet, he thinks recovering stale data is a
bug to fix, and option to permit it is unnecessary. So this version
the sysfs file is removed.
v2: rename sysfs entry from allow_stale_data_on_failure  to
allow_stale_data_on_failure, and fix the confusing commit log.
v1: initial patch posted.

[small change to patch comment spelling by mlyle]

Signed-off-by: Coly Li 
Signed-off-by: Michael Lyle 
Reported-by: Arne Wolf 
Reviewed-by: Michael Lyle 
Cc: Kent Overstreet 
Cc: Nix 
Cc: Kai Krakow 
Cc: Eric Wheeler 
Cc: Junhui Tang 
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/md/bcache/request.c |   10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -702,8 +702,16 @@ static void cached_dev_read_error(struct
 {
struct search *s = container_of(cl, struct search, cl);
struct bio *bio = &s->bio.bio;
+   struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
 
-   if (s->recoverable) {
+   /*
+* If cache device is dirty (dc->has_dirty is non-zero), then
+* recovery a failed read request from cached device may get a
+* stale data back. So read failure recovery is only permitted
+* when cache device is clean.
+*/
+   if (s->recoverable &&
+   (dc && !atomic_read(&dc->has_dirty))) {
/* Retry from the backing device: */
trace_bcache_read_retry(s->orig_bio);
 




[PATCH 4.9 023/109] usb: dwc2: Error out of dwc2_hsotg_ep_disable() if were in host mode

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: John Stultz 


[ Upstream commit 9b481092c2a31a6b630aff9c28f0145bf6683787 ]

We've found that while in host mode, using Android, if one runs
the command:
  stop adbd

The existing usb devices being utilized in host mode are disconnected.
This is most visible with usb networking devices.

This seems to be due to adbd closing the file:
  /dev/usb-ffs/adb/ep0
Which calls ffs_ep0_release() and the following backtrace:

[] dwc2_hsotg_ep_disable+0x148/0x150
[] dwc2_hsotg_udc_stop+0x60/0x110
[] usb_gadget_remove_driver+0x58/0x78
[] usb_gadget_unregister_driver+0x74/0xe8
[] unregister_gadget+0x28/0x58
[] unregister_gadget_item+0x2c/0x40
[] ffs_data_clear+0xe8/0xf8
[] ffs_data_reset+0x20/0x58
[] ffs_data_closed+0x98/0xe8
[] ffs_ep0_release+0x20/0x30

Then when dwc2_hsotg_ep_disable() is called, we call
kill_all_requests() which causes a bunch of the following
messages:

dwc2 f72c.usb: Mode Mismatch Interrupt: currently in Host mode
dwc2 f72c.usb: Mode Mismatch Interrupt: currently in Host mode
dwc2 f72c.usb: Mode Mismatch Interrupt: currently in Host mode
dwc2 f72c.usb: Mode Mismatch Interrupt: currently in Host mode
dwc2 f72c.usb: Mode Mismatch Interrupt: currently in Host mode
dwc2 f72c.usb: Mode Mismatch Interrupt: currently in Host mode
dwc2 f72c.usb: Mode Mismatch Interrupt: currently in Host mode
dwc2 f72c.usb: Mode Mismatch Interrupt: currently in Host mode
init: Service 'adbd' (pid 1915) killed by signal 9
init: Sending signal 9 to service 'adbd' (pid 1915) process group...
init: Successfully killed process cgroup uid 0 pid 1915 in 0ms
init: processing action (init.svc.adbd=stopped) from (/init.usb.configfs.rc:15)
dwc2 f72c.usb: dwc2_hc_chhltd_intr_dma: Channel 8 - ChHltd set, but reason 
is unknown
dwc2 f72c.usb: hcint 0x0002, intsts 0x04200029
dwc2 f72c.usb: dwc2_hc_chhltd_intr_dma: Channel 12 - ChHltd set, but reason 
is unknown
dwc2 f72c.usb: hcint 0x0002, intsts 0x04200029
dwc2 f72c.usb: dwc2_hc_chhltd_intr_dma: Channel 15 - ChHltd set, but reason 
is unknown
dwc2 f72c.usb: hcint 0x0002, intsts 0x04200029
dwc2 f72c.usb: dwc2_hc_chhltd_intr_dma: Channel 3 - ChHltd set, but reason 
is unknown
dwc2 f72c.usb: hcint 0x0002, intsts 0x04200029
dwc2 f72c.usb: dwc2_hc_chhltd_intr_dma: Channel 4 - ChHltd set, but reason 
is unknown
dwc2 f72c.usb: hcint 0x0002, intsts 0x04200029
dwc2 f72c.usb: dwc2_update_urb_state_abn(): trimming xfer length

And the usb devices connected are basically hung at this point.

It seems like if we're in host mode, we probably shouldn't run
the dwc2_hostg_ep_disable logic, so this patch returns an error
in that case.

With this patch (along with the previous patch in this set), we avoid
the mismatched interrupts and connected usb devices continue to function.

I'm not sure if some other solution would be better here, but this seems
to work, so I wanted to send it out for input on what the right approach
should be.

Cc: Wei Xu 
Cc: Guodong Xu 
Cc: Amit Pundir 
Cc: YongQin Liu 
Cc: John Youn 
Cc: Minas Harutyunyan 
Cc: Douglas Anderson 
Cc: Chen Yu 
Cc: Felipe Balbi 
Cc: Greg Kroah-Hartman 
Cc: linux-...@vger.kernel.org
Acked-by: Minas Harutyunyan 
Tested-by: Minas Harutyunyan 
Reported-by: YongQin Liu 
Signed-off-by: John Stultz 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/usb/dwc2/gadget.c |5 +
 1 file changed, 5 insertions(+)

--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3117,6 +3117,11 @@ static int dwc2_hsotg_ep_disable(struct
return -EINVAL;
}
 
+   if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) {
+   dev_err(hsotg->dev, "%s: called in host mode?\n", __func__);
+   return -EINVAL;
+   }
+
epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index);
 
spin_lock_irqsave(&hsotg->lock, flags);




[PATCH 4.9 008/109] usb: quirks: Add no-lpm quirk for KY-688 USB 3.1 Type-C Hub

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Kai-Heng Feng 

commit e43a12f1793ae1fe006e26fe9327a8840a92233c upstream.

KY-688 USB 3.1 Type-C Hub internally uses a Genesys Logic hub to connect
to Realtek r8153.

Similar to commit ("7496cfe5431f2 usb: quirks: Add no-lpm quirk for Moshi
USB to Ethernet Adapter"), no-lpm can make r8153 ethernet work.

Signed-off-by: Kai-Heng Feng 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/quirks.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -151,6 +151,9 @@ static const struct usb_device_id usb_qu
/* appletouch */
{ USB_DEVICE(0x05ac, 0x021a), .driver_info = USB_QUIRK_RESET_RESUME },
 
+   /* Genesys Logic hub, internally used by KY-688 USB 3.1 Type-C Hub */
+   { USB_DEVICE(0x05e3, 0x0612), .driver_info = USB_QUIRK_NO_LPM },
+
/* Genesys Logic hub, internally used by Moshi USB to Ethernet Adapter 
*/
{ USB_DEVICE(0x05e3, 0x0616), .driver_info = USB_QUIRK_NO_LPM },
 




[PATCH 4.9 003/109] drm/fsl-dcu: avoid disabling pixel clock twice on suspend

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Stefan Agner 

commit 9306e996574f7f57136a62e49cd0075f85713623 upstream.

With commit 0a70c998d0c5 ("drm/fsl-dcu: enable pixel clock when
enabling CRTC") the pixel clock is controlled by the CRTC code.
Disabling the pixel clock in suspend leads to a warning due to
the second clk_disable_unprepare call:
  WARNING: CPU: 0 PID: 359 at drivers/clk/clk.c:594 clk_core_disable+0x8c/0x90

Remove clk_disable_unprepare call for pixel clock to avoid
unbalanced clock disable on suspend.

Fixes: 0a70c998d0c5 ("drm/fsl-dcu: enable pixel clock when enabling CRTC")
Signed-off-by: Stefan Agner 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c |1 -
 1 file changed, 1 deletion(-)

--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
@@ -243,7 +243,6 @@ static int fsl_dcu_drm_pm_suspend(struct
return PTR_ERR(fsl_dev->state);
}
 
-   clk_disable_unprepare(fsl_dev->pix_clk);
clk_disable_unprepare(fsl_dev->clk);
 
return 0;




[PATCH 4.9 000/109] 4.9.68-stable review

2017-12-07 Thread Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.9.68 release.
There are 109 patches in this series, all will be posted as a response
to this one.  If anyone has any issues with these being applied, please
let me know.

Responses should be made by Sat Dec  9 12:56:03 UTC 2017.
Anything received after that time might be too late.

The whole patch series can be found in one patch at:
kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.68-rc1.gz
or in the git tree and branch at:
  git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git 
linux-4.9.y
and the diffstat can be found below.

thanks,

greg k-h

-
Pseudo-Shortlog of commits:

Greg Kroah-Hartman 
Linux 4.9.68-rc1

Colin Ian King 
usb: host: fix incorrect updating of offset

Oliver Neukum 
USB: usbfs: Filter flags passed in from user space

Dan Carpenter 
USB: devio: Prevent integer overflow in proc_do_submiturb()

Mateusz Berezecki 
USB: Increase usbfs transfer limit

Masakazu Mokuno 
USB: core: Add type-specific length check of BOS descriptors

Yu Chen 
usb: xhci: fix panic in xhci_free_virt_devices_depth_first

Mike Looijmans 
usb: hub: Cycle HUB power when initialization fails

Daniel Vetter 
dma-buf: Update kerneldoc for sync_file_create

Gustavo Padovan 
dma-buf/sync_file: hold reference to fence when creating sync_file

Dominik Behr 
dma-buf/sw_sync: force signal all unsignaled fences on dying timeline

Chris Wilson 
dma-fence: Introduce drm_fence_set_error() helper

Chris Wilson 
dma-fence: Wrap querying the fence->status

Chris Wilson 
dma-fence: Clear fence->status during dma_fence_init()

Gustavo Padovan 
dma-buf/sw_sync: clean up list before signaling the fence

Gustavo Padovan 
dma-buf/sw_sync: move timeline_fence_ops around

Chris Wilson 
dma-buf/sw-sync: Use an rbtree to sort fences in the timeline

Chris Wilson 
dma-buf/sw-sync: Fix locking around sync_timeline lists

Chris Wilson 
dma-buf/sw-sync: sync_pt is private and of fixed size

Chris Wilson 
dma-buf/sw-sync: Reduce irqsave/irqrestore from known context

Chris Wilson 
dma-buf/sw-sync: Prevent user overflow on timeline advance

Chris Wilson 
dma-buf/sw-sync: Fix the is-signaled test to handle u32 wraparound

Chris Wilson 
dma-buf/dma-fence: Extract __dma_fence_is_later()

Rui Sousa 
net: fec: fix multicast filtering hardware setup

Mart van Santen 
xen-netback: vif counters from int/long to u64

Hans Verkuil 
cec: initiator should be the same as the destination for, poll

Ross Lagerwall 
xen-netfront: Improve error handling during initialization

Jan Kara 
mm: avoid returning VM_FAULT_RETRY from ->page_mkwrite handlers

Alexey Kardashevskiy 
vfio/spapr: Fix missing mutex unlock when creating a window

Ivan Vecera 
be2net: fix initial MAC setting

Vincent 
net: thunderx: avoid dereferencing xcv when NULL

Sean Nyekjaer 
net: phy: micrel: KSZ8795 do not set SUPPORTED_[Asym_]Pause

Andreas Schultz 
gtp: fix cross netns recv on gtp socket

Andreas Schultz 
gtp: clear DF bit on GTP packet tx

Sagi Grimberg 
nvmet: cancel fatal error and flush async work before free controller

Mike Looijmans 
i2c: i2c-cadence: Initialize configuration before probing devices

Jason Baron 
tcp: correct memory barrier usage in tcp_check_space()

Iago Abal 
dmaengine: pl330: fix double lock

Parthasarathy Bhuvaragan 
tipc: fix cleanup at module unload

Parthasarathy Bhuvaragan 
tipc: fix nametbl_lock soft lockup at module exit

Ram Amrani 
RDMA/qedr: Fix RDMA CM loopback

Ram Amrani 
RDMA/qedr: Return success when not changing QP state

Johannes Berg 
mac80211: don't try to sleep in rate_control_rate_init()

Xiangliang Yu 
drm/amdgpu: fix unload driver issue for virtual display

Kevin Hao 
x86/fpu: Set the xcomp_bv when we fake up a XSAVES area

Colin Ian King 
net: sctp: fix array overrun read on sctp_timer_tbl

Andrzej Hajda 
drm/exynos/decon5433: set STANDALONE_UPDATE_F on output enablement

Rex Zhu 
drm/amdgpu: fix bug set incorrect value to vce register

Quinn Tran 
qla2xxx: Fix wrong IOCB type assumption

Reza Arbab 
powerpc/mm: Fix memory hotplug BUG() on radix

Jiri Olsa 
perf/x86/intel: Account interrupts for PEBS errors

Trond Myklebust 
NFSv4: Fix client recovery when server reboots multiple times

Michal Kazior 
mac80211: prevent skb/txq mismatch

Christoffer Dall 
KVM: arm/arm64: Fix occasional warning from the timer work function

Andrzej Hajda 
drm/exynos/decon5433: set STANDALONE_UPDATE_F also if planes are disabled

Andrzej Hajda 
drm/exynos/decon5433: update shadow registers iff there are active windows

Benjamin Coddington 
nfs: Don't take a reference on fl->fl_file for LOCK operation

Kazuya Mizuguchi 
ravb: Remove Rx overflow log messages

Johannes Berg 
mac80211: calculate min channel width correctly

Mich

[PATCH 4.9 019/109] spi: sh-msiof: Fix DMA transfer size check

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Hiromitsu Yamasaki 


[ Upstream commit 36735783fdb599c94b9c86824583df367c65900b ]

DMA supports 32-bit words only,
even if BITLEN1 of SITMDR2 register is 16bit.

Fixes: b0d0ce8b6b91 ("spi: sh-msiof: Add DMA support")
Signed-off-by: Hiromitsu Yamasaki 
Signed-off-by: Simon Horman 
Acked-by: Geert Uytterhoeven 
Acked-by: Dirk Behme 
Signed-off-by: Mark Brown 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/spi/spi-sh-msiof.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -862,7 +862,7 @@ static int sh_msiof_transfer_one(struct
break;
copy32 = copy_bswap32;
} else if (bits <= 16) {
-   if (l & 1)
+   if (l & 3)
break;
copy32 = copy_wswap32;
} else {




[PATCH 4.9 016/109] m68k: fix ColdFire node shift size calculation

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Greg Ungerer 


[ Upstream commit f55ab8f27548ff3431a6567d400c6757c49fd520 ]

The m68k pg_data_table is a fix size array defined in arch/m68k/mm/init.c.
Index numbers within it are defined based on memory size. But for Coldfire
these don't take into account a non-zero physical RAM base address, and this
causes us to access past the end of this array at system start time.

Change the node shift calculation so that we keep the index inside its range.

Reported-by: Angelo Dureghello 
Tested-by: Angelo Dureghello 
Signed-off-by: Greg Ungerer 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 arch/m68k/mm/mcfmmu.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/m68k/mm/mcfmmu.c
+++ b/arch/m68k/mm/mcfmmu.c
@@ -169,7 +169,7 @@ void __init cf_bootmem_alloc(void)
max_pfn = max_low_pfn = PFN_DOWN(_ramend);
high_memory = (void *)_ramend;
 
-   m68k_virt_to_node_shift = fls(_ramend - _rambase - 1) - 6;
+   m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
module_fixup(NULL, __start_fixup, __stop_fixup);
 
/* setup bootmem data */




[PATCH 4.9 004/109] drm/fsl-dcu: enable IRQ before drm_atomic_helper_resume()

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Stefan Agner 

commit 9fd99f4f3f5e13ce959900ae57d64b1bdb51d823 upstream.

The resume helpers wait for a vblank to occurre hence IRQ need
to be enabled. This avoids a warning as follows during resume:
  WARNING: CPU: 0 PID: 314 at drivers/gpu/drm/drm_atomic_helper.c:1249 
drm_atomic_helper_wait_for_vblanks.part.1+0x284/0x288
  [CRTC:28:crtc-0] vblank wait timed out

Signed-off-by: Stefan Agner 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
@@ -265,6 +265,7 @@ static int fsl_dcu_drm_pm_resume(struct
if (fsl_dev->tcon)
fsl_tcon_bypass_enable(fsl_dev->tcon);
fsl_dcu_drm_init_planes(fsl_dev->drm);
+   enable_irq(fsl_dev->irq);
drm_atomic_helper_resume(fsl_dev->drm, fsl_dev->state);
 
console_lock();
@@ -272,7 +273,6 @@ static int fsl_dcu_drm_pm_resume(struct
console_unlock();
 
drm_kms_helper_poll_enable(fsl_dev->drm);
-   enable_irq(fsl_dev->irq);
 
return 0;
 }




[PATCH 4.9 009/109] serial: 8250_pci: Add Amazon PCI serial device ID

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Matt Wilson 

commit 3bfd1300abfe3adb18e84a89d97a0e82a22124bb upstream.

This device will be used in future Amazon EC2 instances as the primary
serial port (i.e., data sent to this port will be available via the
GetConsoleOuput [1] EC2 API).

[1] 
http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_GetConsoleOutput.html

Signed-off-by: Matt Wilson 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/tty/serial/8250/8250_pci.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -5568,6 +5568,9 @@ static struct pci_device_id serial_pci_t
{ PCI_DEVICE(0x1601, 0x0800), .driver_data = pbn_b0_4_125 },
{ PCI_DEVICE(0x1601, 0xa801), .driver_data = pbn_b0_4_125 },
 
+   /* Amazon PCI serial device */
+   { PCI_DEVICE(0x1d0f, 0x8250), .driver_data = pbn_b0_1_115200 },
+
/*
 * These entries match devices with class COMMUNICATION_SERIAL,
 * COMMUNICATION_MODEM or COMMUNICATION_MULTISERIAL




[PATCH 4.9 022/109] usb: dwc2: Fix UDC state tracking

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: John Stultz 


[ Upstream commit ce2b21a4e5ce042c0a42c9db8fa9e0f849427d5e ]

It has been noticed that the dwc2 udc state reporting doesn't
seem to work (at least on HiKey boards). Where after the initial
setup, the sysfs /sys/class/udc/f72c.usb/state file would
report "configured" no matter the state of the OTG port.

This patch adds a call so that we report to the UDC layer when
the gadget device is disconnected.

This patch does depend on the previous patch ("usb: dwc2:
Improve gadget state disconnection handling") in this patch set
in order to properly work.

Cc: Wei Xu 
Cc: Guodong Xu 
Cc: Amit Pundir 
Cc: YongQin Liu 
Cc: John Youn 
Cc: Minas Harutyunyan 
Cc: Douglas Anderson 
Cc: Chen Yu 
Cc: Felipe Balbi 
Cc: Greg Kroah-Hartman 
Cc: linux-...@vger.kernel.org
Acked-by: Minas Harutyunyan 
Tested-by: Minas Harutyunyan 
Reported-by: Amit Pundir 
Signed-off-by: John Stultz 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/usb/dwc2/gadget.c |2 ++
 1 file changed, 2 insertions(+)

--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2467,6 +2467,8 @@ void dwc2_hsotg_disconnect(struct dwc2_h
 
call_gadget(hsotg, disconnect);
hsotg->lx_state = DWC2_L3;
+
+   usb_gadget_set_state(&hsotg->gadget, USB_STATE_NOTATTACHED);
 }
 
 /**




[PATCH 4.9 025/109] serial: 8250: Preserve DLD[7:4] for PORT_XR17V35X

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Aaron Sierra 


[ Upstream commit 0ab84da2e076948c49d36197ee7d254125c53eab ]

The upper four bits of the XR17V35x fractional divisor register (DLD)
control general chip function (RS-485 direction pin polarity, multidrop
mode, XON/XOFF parity check, and fast IR mode). Don't allow these bits
to be clobbered when setting the baudrate.

Signed-off-by: Aaron Sierra 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/tty/serial/8250/8250_port.c |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2526,8 +2526,11 @@ static void serial8250_set_divisor(struc
serial_dl_write(up, quot);
 
/* XR17V35x UARTs have an extra fractional divisor register (DLD) */
-   if (up->port.type == PORT_XR17V35X)
+   if (up->port.type == PORT_XR17V35X) {
+   /* Preserve bits not related to baudrate; DLD[7:4]. */
+   quot_frac |= serial_port_in(port, 0x2) & 0xf0;
serial_port_out(port, 0x2, quot_frac);
+   }
 }
 
 static unsigned int serial8250_get_baud_rate(struct uart_port *port,




[PATCH 4.9 017/109] serial: 8250_fintek: Fix rs485 disablement on invalid ioctl()

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Lukas Wunner 


[ Upstream commit 3236a965486ba0c6043cf2c7b51943d8b382ae29 ]

This driver's ->rs485_config callback checks if SER_RS485_RTS_ON_SEND
and SER_RS485_RTS_AFTER_SEND have the same value.  If they do, it means
the user has passed in invalid data with the TIOCSRS485 ioctl()
since RTS must have a different polarity when sending and when not
sending.  In this case, rs485 mode is not enabled (the RS485_URA bit
is not set in the RS485 Enable Register) and this is supposed to be
signaled back to the user by clearing the SER_RS485_ENABLED bit in
struct serial_rs485 ... except a missing tilde character is preventing
that from happening.

Fixes: 28e3fb6c4dce ("serial: Add support for Fintek F81216A LPC to 4 UART")
Cc: Ricardo Ribalda Delgado 
Cc: "Ji-Ze Hong (Peter Hong)" 
Signed-off-by: Lukas Wunner 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/tty/serial/8250/8250_fintek.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/tty/serial/8250/8250_fintek.c
+++ b/drivers/tty/serial/8250/8250_fintek.c
@@ -121,7 +121,7 @@ static int fintek_8250_rs485_config(stru
 
if ((!!(rs485->flags & SER_RS485_RTS_ON_SEND)) ==
(!!(rs485->flags & SER_RS485_RTS_AFTER_SEND)))
-   rs485->flags &= SER_RS485_ENABLED;
+   rs485->flags &= ~SER_RS485_ENABLED;
else
config |= RS485_URA;
 




[PATCH 4.9 039/109] usb: gadget: f_fs: Fix ExtCompat descriptor validation

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Vincent Pelletier 


[ Upstream commit 354bc45bf329494ef6051f3229ef50b9e2a7ea2a ]

Reserved1 is documented as expected to be set to 0, but this test fails
when it it set to 0. Reverse the condition.

Signed-off-by: Vincent Pelletier 
Signed-off-by: Felipe Balbi 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/usb/gadget/function/f_fs.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -2263,7 +2263,7 @@ static int __ffs_data_do_os_desc(enum ff
 
if (len < sizeof(*d) ||
d->bFirstInterfaceNumber >= ffs->interfaces_count ||
-   !d->Reserved1)
+   d->Reserved1)
return -EINVAL;
for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i)
if (d->Reserved2[i])




[PATCH 4.9 029/109] usbip: tools: Install all headers needed for libusbip development

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Ben Hutchings 


[ Upstream commit c15562c0dcb2c7f26e891923b784cf1926b8c833 ]

usbip_host_driver.h now depends on several additional headers, which
need to be installed along with it.

Fixes: 021aed845303 ("staging: usbip: userspace: migrate usbip_host_driver ...")
Fixes: 3391ba0e2792 ("usbip: tools: Extract generic code to be shared with ...")
Signed-off-by: Ben Hutchings 
Acked-by: Shuah Khan 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 tools/usb/usbip/Makefile.am |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/tools/usb/usbip/Makefile.am
+++ b/tools/usb/usbip/Makefile.am
@@ -1,6 +1,7 @@
 SUBDIRS := libsrc src
 includedir = @includedir@/usbip
 include_HEADERS := $(addprefix libsrc/, \
-usbip_common.h vhci_driver.h usbip_host_driver.h)
+usbip_common.h vhci_driver.h usbip_host_driver.h \
+list.h sysfs_utils.h usbip_host_common.h)
 
 dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8)




[PATCH 4.9 030/109] perf test attr: Fix ignored test case result

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Thomas Richter 


[ Upstream commit 22905582f6dd4bbd0c370fe5732c607452010c04 ]

Command perf test -v 16 (Setup struct perf_event_attr test) always
reports success even if the test case fails.  It works correctly if you
also specify -F (for don't fork).

   root@s35lp76 perf]# ./perf test -v 16
   15: Setup struct perf_event_attr   :
   --- start ---
   running './tests/attr/test-record-no-delay'
   [ perf record: Woken up 1 times to write data ]
   [ perf record: Captured and wrote 0.002 MB /tmp/tmp4E1h7R/perf.data
 (1 samples) ]
   expected task=0, got 1
   expected precise_ip=0, got 3
   expected wakeup_events=1, got 0
   FAILED './tests/attr/test-record-no-delay' - match failure
   test child finished with 0
    end 
   Setup struct perf_event_attr: Ok

The reason for the wrong error reporting is the return value of the
system() library call. It is called in run_dir() file tests/attr.c and
returns the exit status, in above case 0xff00.

This value is given as parameter to the exit() function which can only
handle values 0-0xff.

The child process terminates with exit value of 0 and the parent does
not detect any error.

This patch corrects the error reporting and prints the correct test
result.

Signed-off-by: Thomas-Mich Richter 
Acked-by: Jiri Olsa 
Cc: Heiko Carstens 
Cc: Hendrik Brueckner 
Cc: Martin Schwidefsky 
Cc: Thomas-Mich Richter 
LPU-Reference: 20170913081209.39570-2-tmri...@linux.vnet.ibm.com
Link: http://lkml.kernel.org/n/tip-rdube6rfcjsr1nzue72c7...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 tools/perf/tests/attr.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/tools/perf/tests/attr.c
+++ b/tools/perf/tests/attr.c
@@ -150,7 +150,7 @@ static int run_dir(const char *d, const
snprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s",
 d, d, perf, vcnt, v);
 
-   return system(cmd);
+   return system(cmd) ? TEST_FAIL : TEST_OK;
 }
 
 int test__attr(int subtest __maybe_unused)




[PATCH 4.9 038/109] dmaengine: stm32-dma: Fix null pointer dereference in stm32_dma_tx_status

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: M'boumba Cedric Madianga 


[ Upstream commit 57b5a32135c813f2ab669039fb4ec16b30cb3305 ]

chan->desc is always set to NULL when a DMA transfer is complete.
As a DMA transfer could be complete during the call of stm32_dma_tx_status,
we need to be sure that chan->desc is not NULL before using this variable
to avoid a null pointer deference issue.

Signed-off-by: M'boumba Cedric Madianga 
Reviewed-by: Ludovic BARRE 
Signed-off-by: Vinod Koul 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/dma/stm32-dma.c |   10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -884,7 +884,7 @@ static enum dma_status stm32_dma_tx_stat
struct virt_dma_desc *vdesc;
enum dma_status status;
unsigned long flags;
-   u32 residue;
+   u32 residue = 0;
 
status = dma_cookie_status(c, cookie, state);
if ((status == DMA_COMPLETE) || (!state))
@@ -892,16 +892,12 @@ static enum dma_status stm32_dma_tx_stat
 
spin_lock_irqsave(&chan->vchan.lock, flags);
vdesc = vchan_find_desc(&chan->vchan, cookie);
-   if (cookie == chan->desc->vdesc.tx.cookie) {
+   if (chan->desc && cookie == chan->desc->vdesc.tx.cookie)
residue = stm32_dma_desc_residue(chan, chan->desc,
 chan->next_sg);
-   } else if (vdesc) {
+   else if (vdesc)
residue = stm32_dma_desc_residue(chan,
 to_stm32_dma_desc(vdesc), 0);
-   } else {
-   residue = 0;
-   }
-
dma_set_residue(state, residue);
 
spin_unlock_irqrestore(&chan->vchan.lock, flags);




[PATCH 4.9 027/109] EDAC, sb_edac: Fix missing break in switch

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: "Gustavo A. R. Silva" 


[ Upstream commit a8e9b186f153a44690ad0363a56716e7077ad28c ]

Add missing break statement in order to prevent the code from falling
through.

Signed-off-by: Gustavo A. R. Silva 
Cc: Qiuxu Zhuo 
Cc: linux-edac 
Link: http://lkml.kernel.org/r/20171016174029.ga19...@embeddedor.com
Signed-off-by: Borislav Petkov 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/edac/sb_edac.c |1 +
 1 file changed, 1 insertion(+)

--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -2510,6 +2510,7 @@ static int ibridge_mci_bind_devs(struct
break;
case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA:
pvt->pci_ta = pdev;
+   break;
case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS:
pvt->pci_ras = pdev;
break;




[PATCH 4.9 035/109] net/mlx4_en: Fix type mismatch for 32-bit systems

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Slava Shwartsman 


[ Upstream commit 61b6034c6cfdcb265bb453505c3d688e7567727a ]

is_power_of_2 expects unsigned long and we pass u64 max_val_cycles,
this will be truncated on 32 bit systems, and the result is not what we
were expecting.
div_u64 expects u32 as a second argument and we pass
max_val_cycles_rounded which is u64 hence it will always be truncated.
Fix was tested on both 64 and 32 bit systems and got same results for
max_val_cycles and max_val_cycles_rounded.

Fixes: 4850cf458157 ("net/mlx4_en: Resolve dividing by zero in 32-bit system")
Signed-off-by: Slava Shwartsman 
Signed-off-by: Tariq Toukan 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/mellanox/mlx4/en_clock.c |8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
@@ -251,13 +251,9 @@ static u32 freq_to_shift(u16 freq)
 {
u32 freq_khz = freq * 1000;
u64 max_val_cycles = freq_khz * 1000 * MLX4_EN_WRAP_AROUND_SEC;
-   u64 tmp_rounded =
-   roundup_pow_of_two(max_val_cycles) > max_val_cycles ?
-   roundup_pow_of_two(max_val_cycles) - 1 : UINT_MAX;
-   u64 max_val_cycles_rounded = is_power_of_2(max_val_cycles + 1) ?
-   max_val_cycles : tmp_rounded;
+   u64 max_val_cycles_rounded = 1ULL << fls64(max_val_cycles - 1);
/* calculate max possible multiplier in order to fit in 64bit */
-   u64 max_mul = div_u64(0xULL, max_val_cycles_rounded);
+   u64 max_mul = div64_u64(ULLONG_MAX, max_val_cycles_rounded);
 
/* This comes from the reverse of clocksource_khz2mult */
return ilog2(div_u64(max_mul * freq_khz, 100));




[PATCH 4.9 041/109] net: systemport: Utilize skb_put_padto()

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Fainelli 


[ Upstream commit bb7da333d0a9f3bddc08f84187b7579a3f68fd24 ]

Since we need to pad our packets, utilize skb_put_padto() which
increases skb->len by how much we need to pad, allowing us to eliminate
the test on skb->len right below.

Signed-off-by: Florian Fainelli 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/broadcom/bcmsysport.c |5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

--- a/drivers/net/ethernet/broadcom/bcmsysport.c
+++ b/drivers/net/ethernet/broadcom/bcmsysport.c
@@ -1039,13 +1039,12 @@ static netdev_tx_t bcm_sysport_xmit(stru
 * (including FCS and tag) because the length verification is done after
 * the Broadcom tag is stripped off the ingress packet.
 */
-   if (skb_padto(skb, ETH_ZLEN + ENET_BRCM_TAG_LEN)) {
+   if (skb_put_padto(skb, ETH_ZLEN + ENET_BRCM_TAG_LEN)) {
ret = NETDEV_TX_OK;
goto out;
}
 
-   skb_len = skb->len < ETH_ZLEN + ENET_BRCM_TAG_LEN ?
-   ETH_ZLEN + ENET_BRCM_TAG_LEN : skb->len;
+   skb_len = skb->len;
 
mapping = dma_map_single(kdev, skb->data, skb_len, DMA_TO_DEVICE);
if (dma_mapping_error(kdev, mapping)) {




[PATCH 4.9 042/109] net: systemport: Pad packet before inserting TSB

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Fainelli 


[ Upstream commit 38e5a85562a6cd911fc26d951d576551a688574c ]

Inserting the TSB means adding an extra 8 bytes in front the of packet
that is going to be used as metadata information by the TDMA engine, but
stripped off, so it does not really help with the packet padding.

For some odd packet sizes that fall below the 60 bytes payload (e.g: ARP)
we can end-up padding them after the TSB insertion, thus making them 64
bytes, but with the TDMA stripping off the first 8 bytes, they could
still be smaller than 64 bytes which is required to ingress the switch.

Fix this by swapping the padding and TSB insertion, guaranteeing that
the packets have the right sizes.

Fixes: 80105befdb4b ("net: systemport: add Broadcom SYSTEMPORT Ethernet MAC 
driver")
Signed-off-by: Florian Fainelli 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/broadcom/bcmsysport.c |   18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

--- a/drivers/net/ethernet/broadcom/bcmsysport.c
+++ b/drivers/net/ethernet/broadcom/bcmsysport.c
@@ -1023,15 +1023,6 @@ static netdev_tx_t bcm_sysport_xmit(stru
goto out;
}
 
-   /* Insert TSB and checksum infos */
-   if (priv->tsb_en) {
-   skb = bcm_sysport_insert_tsb(skb, dev);
-   if (!skb) {
-   ret = NETDEV_TX_OK;
-   goto out;
-   }
-   }
-
/* The Ethernet switch we are interfaced with needs packets to be at
 * least 64 bytes (including FCS) otherwise they will be discarded when
 * they enter the switch port logic. When Broadcom tags are enabled, we
@@ -1044,6 +1035,15 @@ static netdev_tx_t bcm_sysport_xmit(stru
goto out;
}
 
+   /* Insert TSB and checksum infos */
+   if (priv->tsb_en) {
+   skb = bcm_sysport_insert_tsb(skb, dev);
+   if (!skb) {
+   ret = NETDEV_TX_OK;
+   goto out;
+   }
+   }
+
skb_len = skb->len;
 
mapping = dma_map_single(kdev, skb->data, skb_len, DMA_TO_DEVICE);




[PATCH 4.9 044/109] ARM: OMAP1: DMA: Correct the number of logical channels

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Peter Ujfalusi 


[ Upstream commit 657279778af54f35e54b07b6687918f254a2992c ]

OMAP1510, OMAP5910 and OMAP310 have only 9 logical channels.
OMAP1610, OMAP5912, OMAP1710, OMAP730, and OMAP850 have 16 logical channels
available.

The wired 17 for the lch_count must have been used to cover the 16 + 1
dedicated LCD channel, in reality we can only use 9 or 16 channels.

The d->chan_count is not used by the omap-dma stack, so we can skip the
setup. chan_count was configured to the number of logical channels and not
the actual number of physical channels anyways.

Signed-off-by: Peter Ujfalusi 
Acked-by: Aaro Koskinen 
Signed-off-by: Tony Lindgren 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 arch/arm/mach-omap1/dma.c |   16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

--- a/arch/arm/mach-omap1/dma.c
+++ b/arch/arm/mach-omap1/dma.c
@@ -32,7 +32,6 @@
 #include "soc.h"
 
 #define OMAP1_DMA_BASE (0xfffed800)
-#define OMAP1_LOGICAL_DMA_CH_COUNT 17
 
 static u32 enable_1510_mode;
 
@@ -348,8 +347,6 @@ static int __init omap1_system_dma_init(
goto exit_iounmap;
}
 
-   d->lch_count= OMAP1_LOGICAL_DMA_CH_COUNT;
-
/* Valid attributes for omap1 plus processors */
if (cpu_is_omap15xx())
d->dev_caps = ENABLE_1510_MODE;
@@ -366,13 +363,14 @@ static int __init omap1_system_dma_init(
d->dev_caps |= CLEAR_CSR_ON_READ;
d->dev_caps |= IS_WORD_16;
 
-   if (cpu_is_omap15xx())
-   d->chan_count = 9;
-   else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
-   if (!(d->dev_caps & ENABLE_1510_MODE))
-   d->chan_count = 16;
+   /* available logical channels */
+   if (cpu_is_omap15xx()) {
+   d->lch_count = 9;
+   } else {
+   if (d->dev_caps & ENABLE_1510_MODE)
+   d->lch_count = 9;
else
-   d->chan_count = 9;
+   d->lch_count = 16;
}
 
p = dma_plat_info;




[PATCH 4.9 046/109] be2net: fix accesses to unicast list

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Ivan Vecera 


[ Upstream commit 1d0f110a2c6c4bca3dbcc4b0e27f1e3dc2d44a2c ]

Commit 988d44b "be2net: Avoid redundant addition of mac address in HW"
introduced be_dev_mac_add & be_uc_mac_add helpers that incorrectly
access adapter->uc_list as an array of bytes instead of an array of
be_eth_addr. Consequently NIC is not filled with valid data so unicast
filtering is broken.

Cc: Sathya Perla 
Cc: Ajit Khaparde 
Cc: Sriharsha Basavapatna 
Cc: Somnath Kotur 
Fixes: 988d44b be2net: Avoid redundant addition of mac address in HW
Signed-off-by: Ivan Vecera 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/emulex/benet/be_main.c |9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -275,8 +275,7 @@ static int be_dev_mac_add(struct be_adap
 
/* Check if mac has already been added as part of uc-list */
for (i = 0; i < adapter->uc_macs; i++) {
-   if (ether_addr_equal((u8 *)&adapter->uc_list[i * ETH_ALEN],
-mac)) {
+   if (ether_addr_equal(adapter->uc_list[i].mac, mac)) {
/* mac already added, skip addition */
adapter->pmac_id[0] = adapter->pmac_id[i + 1];
return 0;
@@ -1679,14 +1678,12 @@ static void be_clear_mc_list(struct be_a
 
 static int be_uc_mac_add(struct be_adapter *adapter, int uc_idx)
 {
-   if (ether_addr_equal((u8 *)&adapter->uc_list[uc_idx * ETH_ALEN],
-adapter->dev_mac)) {
+   if (ether_addr_equal(adapter->uc_list[uc_idx].mac, adapter->dev_mac)) {
adapter->pmac_id[uc_idx + 1] = adapter->pmac_id[0];
return 0;
}
 
-   return be_cmd_pmac_add(adapter,
-  (u8 *)&adapter->uc_list[uc_idx * ETH_ALEN],
+   return be_cmd_pmac_add(adapter, adapter->uc_list[uc_idx].mac,
   adapter->if_handle,
   &adapter->pmac_id[uc_idx + 1], 0);
 }




[PATCH 4.9 026/109] x86/entry: Use SYSCALL_DEFINE() macros for sys_modify_ldt()

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Dave Hansen 


[ Upstream commit da20ab35180780e4a6eadc804544f1fa967f3567 ]

We do not have tracepoints for sys_modify_ldt() because we define
it directly instead of using the normal SYSCALL_DEFINEx() macros.

However, there is a reason sys_modify_ldt() does not use the macros:
it has an 'int' return type instead of 'unsigned long'.  This is
a bug, but it's a bug cemented in the ABI.

What does this mean?  If we return -EINVAL from a function that
returns 'int', we have 0xffea in %rax.  But, if we
return -EINVAL from a function returning 'unsigned long', we end
up with 0xffea in %rax, which is wrong.

To work around this and maintain the 'int' behavior while using
the SYSCALL_DEFINEx() macros, so we add a cast to 'unsigned int'
in both implementations of sys_modify_ldt().

Signed-off-by: Dave Hansen 
Reviewed-by: Andy Lutomirski 
Reviewed-by: Brian Gerst 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: http://lkml.kernel.org/r/20171018172107.1a79c...@viggo.jf.intel.com
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 arch/x86/include/asm/syscalls.h |2 +-
 arch/x86/kernel/ldt.c   |   16 +---
 arch/x86/um/ldt.c   |7 +--
 3 files changed, 19 insertions(+), 6 deletions(-)

--- a/arch/x86/include/asm/syscalls.h
+++ b/arch/x86/include/asm/syscalls.h
@@ -21,7 +21,7 @@ asmlinkage long sys_ioperm(unsigned long
 asmlinkage long sys_iopl(unsigned int);
 
 /* kernel/ldt.c */
-asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
+asmlinkage long sys_modify_ldt(int, void __user *, unsigned long);
 
 /* kernel/signal.c */
 asmlinkage long sys_rt_sigreturn(void);
--- a/arch/x86/kernel/ldt.c
+++ b/arch/x86/kernel/ldt.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -271,8 +272,8 @@ out:
return error;
 }
 
-asmlinkage int sys_modify_ldt(int func, void __user *ptr,
- unsigned long bytecount)
+SYSCALL_DEFINE3(modify_ldt, int , func , void __user * , ptr ,
+   unsigned long , bytecount)
 {
int ret = -ENOSYS;
 
@@ -290,5 +291,14 @@ asmlinkage int sys_modify_ldt(int func,
ret = write_ldt(ptr, bytecount, 0);
break;
}
-   return ret;
+   /*
+* The SYSCALL_DEFINE() macros give us an 'unsigned long'
+* return type, but tht ABI for sys_modify_ldt() expects
+* 'int'.  This cast gives us an int-sized value in %rax
+* for the return code.  The 'unsigned' is necessary so
+* the compiler does not try to sign-extend the negative
+* return codes into the high half of the register when
+* taking the value from int->long.
+*/
+   return (unsigned int)ret;
 }
--- a/arch/x86/um/ldt.c
+++ b/arch/x86/um/ldt.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -369,7 +370,9 @@ void free_ldt(struct mm_context *mm)
mm->arch.ldt.entry_count = 0;
 }
 
-int sys_modify_ldt(int func, void __user *ptr, unsigned long bytecount)
+SYSCALL_DEFINE3(modify_ldt, int , func , void __user * , ptr ,
+   unsigned long , bytecount)
 {
-   return do_modify_ldt_skas(func, ptr, bytecount);
+   /* See non-um modify_ldt() for why we do this cast */
+   return (unsigned int)do_modify_ldt_skas(func, ptr, bytecount);
 }




[PATCH 4.9 048/109] net/appletalk: Fix kernel memory disclosure

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Vlad Tsyrklevich 


[ Upstream commit ce7e40c432ba84da104438f6799d460a4cad41bc ]

ipddp_route structs contain alignment padding so kernel heap memory
is leaked when they are copied to user space in
ipddp_ioctl(SIOCFINDIPDDPRT). Change kmalloc() to kzalloc() to clear
that memory.

Signed-off-by: Vlad Tsyrklevich 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/appletalk/ipddp.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/appletalk/ipddp.c
+++ b/drivers/net/appletalk/ipddp.c
@@ -191,7 +191,7 @@ static netdev_tx_t ipddp_xmit(struct sk_
  */
 static int ipddp_create(struct ipddp_route *new_rt)
 {
-struct ipddp_route *rt = kmalloc(sizeof(*rt), GFP_KERNEL);
+struct ipddp_route *rt = kzalloc(sizeof(*rt), GFP_KERNEL);
 
 if (rt == NULL)
 return -ENOMEM;




[PATCH 4.9 040/109] libcxgb: fix error check for ip6_route_output()

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Varun Prakash 


[ Upstream commit a9a8cdb368d99bb655b5cdabea560446db0527cc ]

ip6_route_output() never returns NULL so
check dst->error instead of !dst.

Signed-off-by: Varun Prakash 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.c |   12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

--- a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.c
+++ b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.c
@@ -133,17 +133,15 @@ cxgb_find_route6(struct cxgb4_lld_info *
if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
fl6.flowi6_oif = sin6_scope_id;
dst = ip6_route_output(&init_net, NULL, &fl6);
-   if (!dst)
-   goto out;
-   if (!cxgb_our_interface(lldi, get_real_dev,
-   ip6_dst_idev(dst)->dev) &&
-   !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
+   if (dst->error ||
+   (!cxgb_our_interface(lldi, get_real_dev,
+ip6_dst_idev(dst)->dev) &&
+!(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK))) {
dst_release(dst);
-   dst = NULL;
+   return NULL;
}
}
 
-out:
return dst;
 }
 EXPORT_SYMBOL(cxgb_find_route6);




[PATCH 4.9 055/109] drm/exynos/decon5433: update shadow registers iff there are active windows

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Andrzej Hajda 


[ Upstream commit f65a7c9cb3770ed4d3e7c57c66d7032689081b5e ]

Improper usage of DECON_UPDATE register leads to subtle errors.
If it set in decon_commit when there are no active windows it results
in slow registry updates - all subsequent shadow registry updates takes more
than full vblank. On the other side if it is not set when there are
active windows it results in garbage on the screen after suspend/resume of
FB console.

The patch hopefully fixes it.

Signed-off-by: Andrzej Hajda 
Signed-off-by: Inki Dae 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c |7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

--- a/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
+++ b/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
@@ -188,8 +188,6 @@ static void decon_commit(struct exynos_d
 
/* enable output and display signal */
decon_set_bits(ctx, DECON_VIDCON0, VIDCON0_ENVID | VIDCON0_ENVID_F, ~0);
-
-   decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0);
 }
 
 static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win,
@@ -340,8 +338,9 @@ static void decon_atomic_flush(struct ex
for (i = ctx->first_win; i < WINDOWS_NR; i++)
decon_shadow_protect_win(ctx, i, false);
 
-   /* standalone update */
-   decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0);
+   /* update iff there are active windows */
+   if (crtc->base.state->plane_mask)
+   decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0);
 
if (ctx->out_type & IFTYPE_I80)
set_bit(BIT_WIN_UPDATED, &ctx->flags);




[PATCH 4.9 058/109] mac80211: prevent skb/txq mismatch

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Michal Kazior 


[ Upstream commit dbef53621116474bb883f76f0ba6b7640bc42332 ]

Station structure is considered as not uploaded
(to driver) until drv_sta_state() finishes. This
call is however done after the structure is
attached to mac80211 internal lists and hashes.
This means mac80211 can lookup (and use) station
structure before it is uploaded to a driver.

If this happens (structure exists, but
sta->uploaded is false) fast_tx path can still be
taken. Deep in the fastpath call the sta->uploaded
is checked against to derive "pubsta" argument for
ieee80211_get_txq(). If sta->uploaded is false
(and sta is actually non-NULL) ieee80211_get_txq()
effectively downgraded to vif->txq.

At first glance this may look innocent but coerces
mac80211 into a state that is almost guaranteed
(codel may drop offending skb) to crash because a
station-oriented skb gets queued up on
vif-oriented txq. The ieee80211_tx_dequeue() ends
up looking at info->control.flags and tries to use
txq->sta which in the fail case is NULL.

It's probably pointless to pretend one can
downgrade skb from sta-txq to vif-txq.

Since downgrading unicast traffic to vif->txq must
not be done there's no txq to put a frame on if
sta->uploaded is false. Therefore the code is made
to fall back to regular tx() op path if the
described condition is hit.

Only drivers using wake_tx_queue were affected.

Example crash dump before fix:

 Unable to handle kernel paging request at virtual address e26c
 PC is at ieee80211_tx_dequeue+0x204/0x690 [mac80211]
 [] (ieee80211_tx_dequeue [mac80211]) from
 [] (ath10k_mac_tx_push_txq+0x54/0x1c0 [ath10k_core])
 [] (ath10k_mac_tx_push_txq [ath10k_core]) from
 [] (ath10k_htt_txrx_compl_task+0xd78/0x11d0 [ath10k_core])
 [] (ath10k_htt_txrx_compl_task [ath10k_core])
 [] (ath10k_pci_napi_poll+0x54/0xe8 [ath10k_pci])
 [] (ath10k_pci_napi_poll [ath10k_pci]) from
 [] (net_rx_action+0xac/0x160)

Reported-by: Mohammed Shafi Shajakhan 
Signed-off-by: Michal Kazior 
Signed-off-by: Johannes Berg 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 net/mac80211/tx.c |   17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1244,7 +1244,7 @@ ieee80211_tx_prepare(struct ieee80211_su
 
 static struct txq_info *ieee80211_get_txq(struct ieee80211_local *local,
  struct ieee80211_vif *vif,
- struct ieee80211_sta *pubsta,
+ struct sta_info *sta,
  struct sk_buff *skb)
 {
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -1258,10 +1258,13 @@ static struct txq_info *ieee80211_get_tx
if (!ieee80211_is_data(hdr->frame_control))
return NULL;
 
-   if (pubsta) {
+   if (sta) {
u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
 
-   txq = pubsta->txq[tid];
+   if (!sta->uploaded)
+   return NULL;
+
+   txq = sta->sta.txq[tid];
} else if (vif) {
txq = vif->txq;
}
@@ -1499,23 +1502,17 @@ static bool ieee80211_queue_skb(struct i
struct fq *fq = &local->fq;
struct ieee80211_vif *vif;
struct txq_info *txqi;
-   struct ieee80211_sta *pubsta;
 
if (!local->ops->wake_tx_queue ||
sdata->vif.type == NL80211_IFTYPE_MONITOR)
return false;
 
-   if (sta && sta->uploaded)
-   pubsta = &sta->sta;
-   else
-   pubsta = NULL;
-
if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
sdata = container_of(sdata->bss,
 struct ieee80211_sub_if_data, u.ap);
 
vif = &sdata->vif;
-   txqi = ieee80211_get_txq(local, vif, pubsta, skb);
+   txqi = ieee80211_get_txq(local, vif, sta, skb);
 
if (!txqi)
return false;




[PATCH 4.9 064/109] drm/exynos/decon5433: set STANDALONE_UPDATE_F on output enablement

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Andrzej Hajda 


[ Upstream commit 11d8bcef7a0399e1d2519f207fd575fc404306b4 ]

DECON_TV requires STANDALONE_UPDATE after output enabling, otherwise it does
not start. This change is neutral for DECON.

Signed-off-by: Andrzej Hajda 
Signed-off-by: Inki Dae 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c |2 ++
 1 file changed, 2 insertions(+)

--- a/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
+++ b/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
@@ -189,6 +189,8 @@ static void decon_commit(struct exynos_d
 
/* enable output and display signal */
decon_set_bits(ctx, DECON_VIDCON0, VIDCON0_ENVID | VIDCON0_ENVID_F, ~0);
+
+   decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0);
 }
 
 static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win,




[PATCH 4.9 065/109] net: sctp: fix array overrun read on sctp_timer_tbl

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 


[ Upstream commit 0e73fc9a56f22f2eec4d2b2910c649f7af67b74d ]

The comparison on the timeout can lead to an array overrun
read on sctp_timer_tbl because of an off-by-one error. Fix
this by using < instead of <= and also compare to the array
size rather than SCTP_EVENT_TIMEOUT_MAX.

Fixes CoverityScan CID#1397639 ("Out-of-bounds read")

Signed-off-by: Colin Ian King 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 net/sctp/debug.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/sctp/debug.c
+++ b/net/sctp/debug.c
@@ -166,7 +166,7 @@ static const char *const sctp_timer_tbl[
 /* Lookup timer debug name. */
 const char *sctp_tname(const sctp_subtype_t id)
 {
-   if (id.timeout <= SCTP_EVENT_TIMEOUT_MAX)
+   if (id.timeout < ARRAY_SIZE(sctp_timer_tbl))
return sctp_timer_tbl[id.timeout];
return "unknown_timer";
 }




[PATCH 4.9 059/109] NFSv4: Fix client recovery when server reboots multiple times

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Trond Myklebust 


[ Upstream commit c6180a6237174f481dc856ed6e890d8196b6f0fb ]

If the server reboots multiple times, the client should rely on the
server to tell it that it cannot reclaim state as per section 9.6.3.4
in RFC7530 and section 8.4.2.1 in RFC5661.
Currently, the client is being to conservative, and is assuming that
if the server reboots while state recovery is in progress, then it must
ignore state that was not recovered before the reboot.

Signed-off-by: Trond Myklebust 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 fs/nfs/nfs4state.c |1 -
 1 file changed, 1 deletion(-)

--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1718,7 +1718,6 @@ static int nfs4_recovery_handle_error(st
break;
case -NFS4ERR_STALE_CLIENTID:
set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
-   nfs4_state_clear_reclaim_reboot(clp);
nfs4_state_start_reclaim_reboot(clp);
break;
case -NFS4ERR_EXPIRED:




[PATCH 4.9 079/109] net: phy: micrel: KSZ8795 do not set SUPPORTED_[Asym_]Pause

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Sean Nyekjaer 


[ Upstream commit cf626c3b252b2c9d131be0dd66096ec3bf729e54 ]

As pr commit "net: phy: phy drivers should not set SUPPORTED_[Asym_]Pause"
this phy driver should not set these feature bits.

Signed-off-by: Sean Nyekjaer 
Fixes: 9d162ed69f51 ("net: phy: micrel: add support for KSZ8795")
Reviewed-by: Florian Fainelli 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/phy/micrel.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -1020,7 +1020,7 @@ static struct phy_driver ksphy_driver[]
.phy_id = PHY_ID_KSZ8795,
.phy_id_mask= MICREL_PHY_ID_MASK,
.name   = "Micrel KSZ8795",
-   .features   = (SUPPORTED_Pause | SUPPORTED_Asym_Pause),
+   .features   = PHY_BASIC_FEATURES,
.flags  = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
.config_init= kszphy_config_init,
.config_aneg= ksz8873mll_config_aneg,




[PATCH 4.9 078/109] gtp: fix cross netns recv on gtp socket

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Andreas Schultz 


[ Upstream commit 3ab1b469e847ba425af3c5ad5068cc94b55b38d0 ]

The use of the passed through netlink src_net to check for a
cross netns operation was wrong. Using the GTP socket and the
GTP netdevice is always correct (even if the netdev has been
moved to new netns after link creation).

Remove the now obsolete net field from gtp_dev.

Signed-off-by: Andreas Schultz 
Acked-by: Pablo Neira Ayuso 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/gtp.c |   10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -69,7 +69,6 @@ struct gtp_dev {
struct socket   *sock0;
struct socket   *sock1u;
 
-   struct net  *net;
struct net_device   *dev;
 
unsigned inthash_size;
@@ -316,7 +315,7 @@ static int gtp_encap_recv(struct sock *s
 
netdev_dbg(gtp->dev, "encap_recv sk=%p\n", sk);
 
-   xnet = !net_eq(gtp->net, dev_net(gtp->dev));
+   xnet = !net_eq(sock_net(sk), dev_net(gtp->dev));
 
switch (udp_sk(sk)->encap_type) {
case UDP_ENCAP_GTP0:
@@ -658,7 +657,7 @@ static void gtp_link_setup(struct net_de
 static int gtp_hashtable_new(struct gtp_dev *gtp, int hsize);
 static void gtp_hashtable_free(struct gtp_dev *gtp);
 static int gtp_encap_enable(struct net_device *dev, struct gtp_dev *gtp,
-   int fd_gtp0, int fd_gtp1, struct net *src_net);
+   int fd_gtp0, int fd_gtp1);
 
 static int gtp_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[])
@@ -675,7 +674,7 @@ static int gtp_newlink(struct net *src_n
fd0 = nla_get_u32(data[IFLA_GTP_FD0]);
fd1 = nla_get_u32(data[IFLA_GTP_FD1]);
 
-   err = gtp_encap_enable(dev, gtp, fd0, fd1, src_net);
+   err = gtp_encap_enable(dev, gtp, fd0, fd1);
if (err < 0)
goto out_err;
 
@@ -821,7 +820,7 @@ static void gtp_hashtable_free(struct gt
 }
 
 static int gtp_encap_enable(struct net_device *dev, struct gtp_dev *gtp,
-   int fd_gtp0, int fd_gtp1, struct net *src_net)
+   int fd_gtp0, int fd_gtp1)
 {
struct udp_tunnel_sock_cfg tuncfg = {NULL};
struct socket *sock0, *sock1u;
@@ -858,7 +857,6 @@ static int gtp_encap_enable(struct net_d
 
gtp->sock0 = sock0;
gtp->sock1u = sock1u;
-   gtp->net = src_net;
 
tuncfg.sk_user_data = gtp;
tuncfg.encap_rcv = gtp_encap_recv;




Re: [PATCH v9 4/4] [media] platform: Add Synopsys DesignWare HDMI RX Controller Driver

2017-12-07 Thread Jose Abreu
Hi Hans,

On 07-12-2017 12:33, Hans Verkuil wrote:
> Hi Jose,
>
> Some (small) comments below:

Thanks for the review!

>
> On 12/07/17 10:47, Jose Abreu wrote:
>> This is an initial submission for the Synopsys DesignWare HDMI RX
>> Controller Driver. This driver interacts with a phy driver so that
>> a communication between them is created and a video pipeline is
>> configured.
>>
>> The controller + phy pipeline can then be integrated into a fully
>> featured system that can be able to receive video up to 4k@60Hz
>> with deep color 48bit RGB, depending on the platform. Although,
>> this initial version does not yet handle deep color modes.
>>
>> This driver was implemented as a standard V4L2 subdevice and its
>> main features are:
>>  - Internal state machine that reconfigures phy until the
>>  video is not stable
>>  - JTAG communication with phy
>>  - Inter-module communication with phy driver
>>  - Debug write/read ioctls
>>
>> Some notes:
>>  - RX sense controller (cable connection/disconnection) must
>>  be handled by the platform wrapper as this is not integrated
>>  into the controller RTL
>>  - The same goes for EDID ROM's
>>  - ZCAL calibration is needed only in FPGA platforms, in ASIC
>>  this is not needed
>>  - The state machine is not an ideal solution as it creates a
>>  kthread but it is needed because some sources might not be
>>  very stable at sending the video (i.e. we must react
>>  accordingly).
>>
>> Signed-off-by: Jose Abreu 
>> Cc: Joao Pinto 
>> Cc: Mauro Carvalho Chehab 
>> Cc: Hans Verkuil 
>> Cc: Sylwester Nawrocki 
>> Cc: Sakari Ailus 
>> ---
>> Changes from v8:
>>  - Incorporate Sakari's work on ASYNC subdevs
>> Changes from v6:
>>  - edid-phandle now also looks for parent node (Sylwester)
>>  - Fix kbuild build warnings
>> Changes from v5:
>>  - Removed HDCP 1.4 support (Hans)
>>  - Removed some CEC debug messages (Hans)
>>  - Add s_dv_timings callback (Hans)
>>  - Add V4L2_CID_DV_RX_POWER_PRESENT ctrl (Hans)
>> Changes from v4:
>>  - Add flag V4L2_SUBDEV_FL_HAS_DEVNODE (Sylwester)
>>  - Remove some comments and change some messages to dev_dbg (Sylwester)
>>  - Use v4l2_async_subnotifier_register() (Sylwester)
>> Changes from v3:
>>  - Use v4l2 async API (Sylwester)
>>  - Do not block waiting for phy
>>  - Do not use busy waiting delays (Sylwester)
>>  - Simplify dw_hdmi_power_on (Sylwester)
>>  - Use clock API (Sylwester)
>>  - Use compatible string (Sylwester)
>>  - Minor fixes (Sylwester)
>> Changes from v2:
>>  - Address review comments from Hans regarding CEC
>>  - Use CEC notifier
>>  - Enable SCDC
>> Changes from v1:
>>  - Add support for CEC
>>  - Correct typo errors
>>  - Correctly detect interlaced video modes
>>  - Correct VIC parsing
>> Changes from RFC:
>>  - Add support for HDCP 1.4
>>  - Fixup HDMI_VIC not being parsed (Hans)
>>  - Send source change signal when powering off (Hans)
>>  - Add a "wait stable delay"
>>  - Detect interlaced video modes (Hans)
>>  - Restrain g/s_register from reading/writing to HDCP regs (Hans)
>> ---
>>  drivers/media/platform/dwc/Kconfig  |   15 +
>>  drivers/media/platform/dwc/Makefile |1 +
>>  drivers/media/platform/dwc/dw-hdmi-rx.c | 1834 
>> +++
>>  drivers/media/platform/dwc/dw-hdmi-rx.h |  441 
>>  include/media/dwc/dw-hdmi-rx-pdata.h|   70 ++
>>  5 files changed, 2361 insertions(+)
>>  create mode 100644 drivers/media/platform/dwc/dw-hdmi-rx.c
>>  create mode 100644 drivers/media/platform/dwc/dw-hdmi-rx.h
>>  create mode 100644 include/media/dwc/dw-hdmi-rx-pdata.h
>>
> 
>
>> +static void dw_hdmi_cec_tx_raw_status(struct dw_hdmi_dev *dw_dev, u32 stat)
>> +{
>> +if (hdmi_readl(dw_dev, HDMI_CEC_CTRL) & HDMI_CEC_CTRL_SEND_MASK) {
>> +dev_dbg(dw_dev->dev, "%s: tx is busy\n", __func__);
>> +return;
>> +}
>> +
>> +if (stat & HDMI_AUD_CEC_ISTS_ARBLST) {
>> +cec_transmit_attempt_done(dw_dev->cec_adap,
>> +CEC_TX_STATUS_ARB_LOST);
>> +return;
>> +}
>> +
>> +if (stat & HDMI_AUD_CEC_ISTS_NACK) {
>> +cec_transmit_attempt_done(dw_dev->cec_adap, CEC_TX_STATUS_NACK);
>> +return;
>> +}
>> +
>> +if (stat & HDMI_AUD_CEC_ISTS_ERROR_INIT) {
>> +dev_dbg(dw_dev->dev, "%s: got initiator error\n", __func__);
>> +cec_transmit_attempt_done(dw_dev->cec_adap, 
>> CEC_TX_STATUS_ERROR);
> There is no separate 'low drive' interrupt? Do you know what happens if a low 
> drive
> is received during a transmit?

I think it launches this interrupt, i.e. Initiator Error.

>
> FYI: I've been working on error injection support for my cec-gpio driver, 
> allowing
> me to test all these nasty little corner cases. And that includes Arbitration 
> Lost.
> It's available here:
>
> https://

[PATCH 4.9 068/109] mac80211: dont try to sleep in rate_control_rate_init()

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Johannes Berg 


[ Upstream commit 115865fa0826ed18ca04717cf72d0fe874c0fe7f ]

In my previous patch, I missed that rate_control_rate_init() is
called from some places that cannot sleep, so it cannot call
ieee80211_recalc_min_chandef(). Remove that call for now to fix
the context bug, we'll have to find a different way to fix the
minimum channel width issue.

Fixes: 96aa2e7cf126 ("mac80211: calculate min channel width correctly")
Reported-by: Xiaolong Ye (via lkp-robot) 
Signed-off-by: Johannes Berg 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 net/mac80211/rate.c |2 --
 1 file changed, 2 deletions(-)

--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -40,8 +40,6 @@ void rate_control_rate_init(struct sta_i
 
ieee80211_sta_set_rx_nss(sta);
 
-   ieee80211_recalc_min_chandef(sta->sdata);
-
if (!ref)
return;
 




[PATCH 4.9 094/109] dma-buf/sw-sync: Use an rbtree to sort fences in the timeline

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Chris Wilson 

commit f1e8c67123cf171e2b0357e885e426328b241d7d upstream.

Reduce the list iteration when incrementing the timeline by storing the
fences in increasing order.

v2: Prevent spinlock recursion on free during create
v3: Fixup rebase conflict inside comments that escaped the compiler.

Signed-off-by: Chris Wilson 
Cc: Sumit Semwal 
Cc: Sean Paul 
Cc: Gustavo Padovan 
Reviewed-by: Sean Paul 
Signed-off-by: Gustavo Padovan 
Link: 
http://patchwork.freedesktop.org/patch/msgid/20170629211253.22766-1-ch...@chris-wilson.co.uk
[s/dma_fence/fence/g - gregkh]
Cc: Jisheng Zhang 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/dma-buf/sw_sync.c|   49 +--
 drivers/dma-buf/sync_debug.h |5 
 2 files changed, 48 insertions(+), 6 deletions(-)

--- a/drivers/dma-buf/sw_sync.c
+++ b/drivers/dma-buf/sw_sync.c
@@ -96,6 +96,7 @@ struct sync_timeline *sync_timeline_crea
obj->context = fence_context_alloc(1);
strlcpy(obj->name, name, sizeof(obj->name));
 
+   obj->pt_tree = RB_ROOT;
INIT_LIST_HEAD(&obj->pt_list);
spin_lock_init(&obj->lock);
 
@@ -142,9 +143,13 @@ static void sync_timeline_signal(struct
 
obj->value += inc;
 
-   list_for_each_entry_safe(pt, next, &obj->pt_list, link)
-   if (fence_is_signaled_locked(&pt->base))
-   list_del_init(&pt->link);
+   list_for_each_entry_safe(pt, next, &obj->pt_list, link) {
+   if (!fence_is_signaled_locked(&pt->base))
+   break;
+
+   list_del_init(&pt->link);
+   rb_erase(&pt->node, &obj->pt_tree);
+   }
 
spin_unlock_irq(&obj->lock);
 }
@@ -174,8 +179,38 @@ static struct sync_pt *sync_pt_create(st
INIT_LIST_HEAD(&pt->link);
 
spin_lock_irq(&obj->lock);
-   if (!fence_is_signaled_locked(&pt->base))
-   list_add_tail(&pt->link, &obj->pt_list);
+   if (!fence_is_signaled_locked(&pt->base)) {
+   struct rb_node **p = &obj->pt_tree.rb_node;
+   struct rb_node *parent = NULL;
+
+   while (*p) {
+   struct sync_pt *other;
+   int cmp;
+
+   parent = *p;
+   other = rb_entry(parent, typeof(*pt), node);
+   cmp = value - other->base.seqno;
+   if (cmp > 0) {
+   p = &parent->rb_right;
+   } else if (cmp < 0) {
+   p = &parent->rb_left;
+   } else {
+   if (fence_get_rcu(&other->base)) {
+   fence_put(&pt->base);
+   pt = other;
+   goto unlock;
+   }
+   p = &parent->rb_left;
+   }
+   }
+   rb_link_node(&pt->node, parent, p);
+   rb_insert_color(&pt->node, &obj->pt_tree);
+
+   parent = rb_next(&pt->node);
+   list_add_tail(&pt->link,
+ parent ? &rb_entry(parent, typeof(*pt), 
node)->link : &obj->pt_list);
+   }
+unlock:
spin_unlock_irq(&obj->lock);
 
return pt;
@@ -202,8 +237,10 @@ static void timeline_fence_release(struc
unsigned long flags;
 
spin_lock_irqsave(fence->lock, flags);
-   if (!list_empty(&pt->link))
+   if (!list_empty(&pt->link)) {
list_del(&pt->link);
+   rb_erase(&pt->node, &parent->pt_tree);
+   }
spin_unlock_irqrestore(fence->lock, flags);
}
 
--- a/drivers/dma-buf/sync_debug.h
+++ b/drivers/dma-buf/sync_debug.h
@@ -14,6 +14,7 @@
 #define _LINUX_SYNC_H
 
 #include 
+#include 
 #include 
 #include 
 
@@ -25,6 +26,7 @@
  * @kref:  reference count on fence.
  * @name:  name of the sync_timeline. Useful for debugging
  * @lock:  lock protecting @pt_list and @value
+ * @pt_tree:   rbtree of active (unsignaled/errored) sync_pts
  * @pt_list:   list of active (unsignaled/errored) sync_pts
  * @sync_timeline_list:membership in global sync_timeline_list
  */
@@ -36,6 +38,7 @@ struct sync_timeline {
u64 context;
int value;
 
+   struct rb_root  pt_tree;
struct list_headpt_list;
spinlock_t  lock;
 
@@ -51,10 +54,12 @@ static inline struct sync_timeline *fenc
  * struct sync_pt - sync_pt object
  * @base: base fence object
  * @link: link on the sync timeline's list
+ * @node: node in the sync timeline's tree
  */
 struct sync_pt {
struct fence base;
struct list

[PATCH 4.9 092/109] dma-buf/sw-sync: sync_pt is private and of fixed size

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Chris Wilson 

commit 3b52ce44e720c240afc4c4b03140d7b7811b23bd upstream.

Since sync_pt is only allocated from a single location and is no longer
the base class for fences (that is struct dma_fence) it no longer needs
a generic unsized allocator.

Signed-off-by: Chris Wilson 
Cc: Sumit Semwal 
Cc: Sean Paul 
Cc: Gustavo Padovan 
Reviewed-by: Sean Paul 
Signed-off-by: Gustavo Padovan 
Link: 
http://patchwork.freedesktop.org/patch/msgid/20170629125930.821-5-ch...@chris-wilson.co.uk
[s/dma_fence/fence/g - gregkh]
Cc: Jisheng Zhang 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/dma-buf/sw_sync.c |   12 
 1 file changed, 4 insertions(+), 8 deletions(-)

--- a/drivers/dma-buf/sw_sync.c
+++ b/drivers/dma-buf/sw_sync.c
@@ -155,7 +155,6 @@ static void sync_timeline_signal(struct
 /**
  * sync_pt_create() - creates a sync pt
  * @parent:fence's parent sync_timeline
- * @size:  size to allocate for this pt
  * @inc:   value of the fence
  *
  * Creates a new sync_pt as a child of @parent.  @size bytes will be
@@ -163,15 +162,12 @@ static void sync_timeline_signal(struct
  * the generic sync_timeline struct. Returns the sync_pt object or
  * NULL in case of error.
  */
-static struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size,
-unsigned int value)
+static struct sync_pt *sync_pt_create(struct sync_timeline *obj,
+ unsigned int value)
 {
struct sync_pt *pt;
 
-   if (size < sizeof(*pt))
-   return NULL;
-
-   pt = kzalloc(size, GFP_KERNEL);
+   pt = kzalloc(sizeof(*pt), GFP_KERNEL);
if (!pt)
return NULL;
 
@@ -312,7 +308,7 @@ static long sw_sync_ioctl_create_fence(s
goto err;
}
 
-   pt = sync_pt_create(obj, sizeof(*pt), data.value);
+   pt = sync_pt_create(obj, data.value);
if (!pt) {
err = -ENOMEM;
goto err;




[PATCH 4.9 069/109] RDMA/qedr: Return success when not changing QP state

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Ram Amrani 


[ Upstream commit 865cea40b69741c3da2574176876463233b2b67c ]

If the user is requesting us to change the QP state to the same state
that it is already in, return success instead of failure.

Signed-off-by: Ram Amrani 
Signed-off-by: Michal Kalderon 
Signed-off-by: Doug Ledford 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/infiniband/hw/qedr/verbs.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/infiniband/hw/qedr/verbs.c
+++ b/drivers/infiniband/hw/qedr/verbs.c
@@ -1653,7 +1653,7 @@ static int qedr_update_qp_state(struct q
int status = 0;
 
if (new_state == qp->state)
-   return 1;
+   return 0;
 
switch (qp->state) {
case QED_ROCE_QP_STATE_RESET:




[PATCH 4.9 087/109] net: fec: fix multicast filtering hardware setup

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Rui Sousa 


[ Upstream commit 01f8902bcf3ff124d0aeb88a774180ebcec20ace ]

Fix hardware setup of multicast address hash:
- Never clear the hardware hash (to avoid packet loss)
- Construct the hash register values in software and then write once
to hardware

Signed-off-by: Rui Sousa 
Signed-off-by: Fugang Duan 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/freescale/fec_main.c |   23 +--
 1 file changed, 9 insertions(+), 14 deletions(-)

--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -2923,6 +2923,7 @@ static void set_multicast_list(struct ne
struct netdev_hw_addr *ha;
unsigned int i, bit, data, crc, tmp;
unsigned char hash;
+   unsigned int hash_high = 0, hash_low = 0;
 
if (ndev->flags & IFF_PROMISC) {
tmp = readl(fep->hwp + FEC_R_CNTRL);
@@ -2945,11 +2946,7 @@ static void set_multicast_list(struct ne
return;
}
 
-   /* Clear filter and add the addresses in hash register
-*/
-   writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
-   writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
-
+   /* Add the addresses in hash register */
netdev_for_each_mc_addr(ha, ndev) {
/* calculate crc32 value of mac address */
crc = 0x;
@@ -2967,16 +2964,14 @@ static void set_multicast_list(struct ne
 */
hash = (crc >> (32 - FEC_HASH_BITS)) & 0x3f;
 
-   if (hash > 31) {
-   tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
-   tmp |= 1 << (hash - 32);
-   writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
-   } else {
-   tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW);
-   tmp |= 1 << hash;
-   writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
-   }
+   if (hash > 31)
+   hash_high |= 1 << (hash - 32);
+   else
+   hash_low |= 1 << hash;
}
+
+   writel(hash_high, fep->hwp + FEC_GRP_HASH_TABLE_HIGH);
+   writel(hash_low, fep->hwp + FEC_GRP_HASH_TABLE_LOW);
 }
 
 /* Set a MAC change in hardware. */




[PATCH 4.9 076/109] nvmet: cancel fatal error and flush async work before free controller

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Sagi Grimberg 


[ Upstream commit 06406d81a2d7cfb8abcc4fa6cdfeb8e5897007c5 ]

Make sure they are not running and we can free the controller
safely.

Signed-off-by: Roy Shterman 
Signed-off-by: Sagi Grimberg 
Reviewed-by: Christoph Hellwig 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/nvme/target/core.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -816,6 +816,9 @@ static void nvmet_ctrl_free(struct kref
list_del(&ctrl->subsys_entry);
mutex_unlock(&subsys->lock);
 
+   flush_work(&ctrl->async_event_work);
+   cancel_work_sync(&ctrl->fatal_err_work);
+
ida_simple_remove(&subsys->cntlid_ida, ctrl->cntlid);
nvmet_subsys_put(subsys);
 




[PATCH 4.9 088/109] dma-buf/dma-fence: Extract __dma_fence_is_later()

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Chris Wilson 

commit 8111477663813caa1a4469cfe6afaae36cd04513 upstream.

Often we have the task of comparing two seqno known to be on the same
context, so provide a common __dma_fence_is_later().

Signed-off-by: Chris Wilson 
Cc: Sumit Semwal 
Cc: Sean Paul 
Cc: Gustavo Padovan 
Reviewed-by: Sean Paul 
Signed-off-by: Gustavo Padovan 
Link: 
http://patchwork.freedesktop.org/patch/msgid/20170629125930.821-1-ch...@chris-wilson.co.uk
[renamed to __fence_is_later() - gregkh]
Cc: Jisheng Zhang 
Signed-off-by: Greg Kroah-Hartman 

---
 include/linux/fence.h |   15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -281,6 +281,19 @@ fence_is_signaled(struct fence *fence)
 }
 
 /**
+ * __fence_is_later - return if f1 is chronologically later than f2
+ * @f1:[in]the first fence's seqno
+ * @f2:[in]the second fence's seqno from the same context
+ *
+ * Returns true if f1 is chronologically later than f2. Both fences must be
+ * from the same context, since a seqno is not common across contexts.
+ */
+static inline bool __fence_is_later(u32 f1, u32 f2)
+{
+   return (int)(f1 - f2) > 0;
+}
+
+/**
  * fence_is_later - return if f1 is chronologically later than f2
  * @f1:[in]the first fence from the same context
  * @f2:[in]the second fence from the same context
@@ -293,7 +306,7 @@ static inline bool fence_is_later(struct
if (WARN_ON(f1->context != f2->context))
return false;
 
-   return (int)(f1->seqno - f2->seqno) > 0;
+   return __fence_is_later(f1->seqno, f2->seqno);
 }
 
 /**




[PATCH 4.9 081/109] be2net: fix initial MAC setting

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Ivan Vecera 


[ Upstream commit 4993b39ab04b083ff6ee1147e7e7f120feb6bf7f ]

Recent commit 34393529163a ("be2net: fix MAC addr setting on privileged
BE3 VFs") allows privileged BE3 VFs to set its MAC address during
initialization. Although the initial MAC for such VFs is already
programmed by parent PF the subsequent setting performed by VF is OK,
but in certain cases (after fresh boot) this command in VF can fail.

The MAC should be initialized only when:
1) no MAC is programmed (always except BE3 VFs during first init)
2) programmed MAC is different from requested (e.g. MAC is set when
   interface is down). In this case the initial MAC programmed by PF
   needs to be deleted.

The adapter->dev_mac contains MAC address currently programmed in HW so
it should be zeroed when the MAC is deleted from HW and should not be
filled when MAC is set when interface is down in be_mac_addr_set() as
no programming is performed in this case.

Example of failure without the fix (immediately after fresh boot):

# ip link set eth0 up  <- eth0 is BE3 PF
be2net :01:00.0 eth0: Link is Up

# echo 1 > /sys/class/net/eth0/device/sriov_numvfs  <- Create 1 VF
...
be2net :01:04.0: Emulex OneConnect(be3): VF  port 0

# ip link set eth8 up  <- eth8 is created privileged VF
be2net :01:04.0: opcode 59-1 failed:status 1-76
RTNETLINK answers: Input/output error

# echo 0 > /sys/class/net/eth0/device/sriov_numvfs  <- Delete VF
iommu: Removing device :01:04.0 from group 33
...

# echo 1 > /sys/class/net/eth0/device/sriov_numvfs  <- Create it again
iommu: Removing device :01:04.0 from group 33
...

# ip link set eth8 up
be2net :01:04.0 eth8: Link is Up

Initialization is now OK.

v2 - Corrected the comment and condition check suggested by Suresh & Harsha

Fixes: 34393529163a ("be2net: fix MAC addr setting on privileged BE3 VFs")
Cc: Sathya Perla 
Cc: Ajit Khaparde 
Cc: Sriharsha Basavapatna 
Cc: Somnath Kotur 
Signed-off-by: Ivan Vecera 
Acked-by: Sriharsha Basavapatna 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/emulex/benet/be_main.c |   33 +++-
 1 file changed, 28 insertions(+), 5 deletions(-)

--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -362,8 +362,10 @@ static int be_mac_addr_set(struct net_de
status = -EPERM;
goto err;
}
-done:
+
+   /* Remember currently programmed MAC */
ether_addr_copy(adapter->dev_mac, addr->sa_data);
+done:
ether_addr_copy(netdev->dev_addr, addr->sa_data);
dev_info(dev, "MAC address changed to %pM\n", addr->sa_data);
return 0;
@@ -3635,8 +3637,10 @@ static void be_disable_if_filters(struct
 {
/* Don't delete MAC on BE3 VFs without FILTMGMT privilege  */
if (!BEx_chip(adapter) || !be_virtfn(adapter) ||
-   check_privilege(adapter, BE_PRIV_FILTMGMT))
+   check_privilege(adapter, BE_PRIV_FILTMGMT)) {
be_dev_mac_del(adapter, adapter->pmac_id[0]);
+   eth_zero_addr(adapter->dev_mac);
+   }
 
be_clear_uc_list(adapter);
be_clear_mc_list(adapter);
@@ -3790,12 +3794,27 @@ static int be_enable_if_filters(struct b
if (status)
return status;
 
-   /* Don't add MAC on BE3 VFs without FILTMGMT privilege */
-   if (!BEx_chip(adapter) || !be_virtfn(adapter) ||
-   check_privilege(adapter, BE_PRIV_FILTMGMT)) {
+   /* Normally this condition usually true as the ->dev_mac is zeroed.
+* But on BE3 VFs the initial MAC is pre-programmed by PF and
+* subsequent be_dev_mac_add() can fail (after fresh boot)
+*/
+   if (!ether_addr_equal(adapter->dev_mac, adapter->netdev->dev_addr)) {
+   int old_pmac_id = -1;
+
+   /* Remember old programmed MAC if any - can happen on BE3 VF */
+   if (!is_zero_ether_addr(adapter->dev_mac))
+   old_pmac_id = adapter->pmac_id[0];
+
status = be_dev_mac_add(adapter, adapter->netdev->dev_addr);
if (status)
return status;
+
+   /* Delete the old programmed MAC as we successfully programmed
+* a new MAC
+*/
+   if (old_pmac_id >= 0 && old_pmac_id != adapter->pmac_id[0])
+   be_dev_mac_del(adapter, old_pmac_id);
+
ether_addr_copy(adapter->dev_mac, adapter->netdev->dev_addr);
}
 
@@ -4569,6 +4588,10 @@ static int be_mac_setup(struct be_adapte
 
memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN);
memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN);
+
+   /* Initial MAC for BE3 VFs is already programmed by PF */
+   if (BEx_chip(adapter) && be_virtf

[PATCH 4.9 083/109] mm: avoid returning VM_FAULT_RETRY from ->page_mkwrite handlers

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Jan Kara 


[ Upstream commit 0911d0041c2298ca52a977d7b0b0159fee4b ]

Some ->page_mkwrite handlers may return VM_FAULT_RETRY as its return
code (GFS2 or Lustre can definitely do this).  However VM_FAULT_RETRY
from ->page_mkwrite is completely unhandled by the mm code and results
in locking and writeably mapping the page which definitely is not what
the caller wanted.

Fix Lustre and block_page_mkwrite_ret() used by other filesystems
(notably GFS2) to return VM_FAULT_NOPAGE instead which results in
bailing out from the fault code, the CPU then retries the access, and we
fault again effectively doing what the handler wanted.

Link: http://lkml.kernel.org/r/20170203150729.15863-1-j...@suse.cz
Signed-off-by: Jan Kara 
Reported-by: Al Viro 
Reviewed-by: Jinshan Xiong 
Cc: Matthew Wilcox 
Signed-off-by: Andrew Morton 
Signed-off-by: Linus Torvalds 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/staging/lustre/lustre/llite/llite_mmap.c |4 +---
 include/linux/buffer_head.h  |4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

--- a/drivers/staging/lustre/lustre/llite/llite_mmap.c
+++ b/drivers/staging/lustre/lustre/llite/llite_mmap.c
@@ -401,15 +401,13 @@ static int ll_page_mkwrite(struct vm_are
result = VM_FAULT_LOCKED;
break;
case -ENODATA:
+   case -EAGAIN:
case -EFAULT:
result = VM_FAULT_NOPAGE;
break;
case -ENOMEM:
result = VM_FAULT_OOM;
break;
-   case -EAGAIN:
-   result = VM_FAULT_RETRY;
-   break;
default:
result = VM_FAULT_SIGBUS;
break;
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -239,12 +239,10 @@ static inline int block_page_mkwrite_ret
 {
if (err == 0)
return VM_FAULT_LOCKED;
-   if (err == -EFAULT)
+   if (err == -EFAULT || err == -EAGAIN)
return VM_FAULT_NOPAGE;
if (err == -ENOMEM)
return VM_FAULT_OOM;
-   if (err == -EAGAIN)
-   return VM_FAULT_RETRY;
/* -ENOSPC, -EDQUOT, -EIO ... */
return VM_FAULT_SIGBUS;
 }




[PATCH 4.9 090/109] dma-buf/sw-sync: Prevent user overflow on timeline advance

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Chris Wilson 

commit 8f66d3aa1735bc95ae58d846a157357e8d41abb8 upstream.

The timeline is u32, which limits any single advance to INT_MAX so that
we can detect all fences that need signaling.

Signed-off-by: Chris Wilson 
Cc: Sumit Semwal 
Cc: Sean Paul 
Cc: Gustavo Padovan 
Reviewed-by: Sean Paul 
Signed-off-by: Gustavo Padovan 
Link: 
http://patchwork.freedesktop.org/patch/msgid/20170629125930.821-3-ch...@chris-wilson.co.uk
[s/dma_fence/fence/g - gregkh]
Cc: Jisheng Zhang 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/dma-buf/sw_sync.c |5 +
 1 file changed, 5 insertions(+)

--- a/drivers/dma-buf/sw_sync.c
+++ b/drivers/dma-buf/sw_sync.c
@@ -345,6 +345,11 @@ static long sw_sync_ioctl_inc(struct syn
if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
return -EFAULT;
 
+   while (value > INT_MAX)  {
+   sync_timeline_signal(obj, INT_MAX);
+   value -= INT_MAX;
+   }
+
sync_timeline_signal(obj, value);
 
return 0;




[PATCH 4.9 084/109] xen-netfront: Improve error handling during initialization

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Ross Lagerwall 


[ Upstream commit e2e004acc7cbe3c531e752a270a74e95cde3ea48 ]

This fixes a crash when running out of grant refs when creating many
queues across many netdevs.

* If creating queues fails (i.e. there are no grant refs available),
call xenbus_dev_fatal() to ensure that the xenbus device is set to the
closed state.
* If no queues are created, don't call xennet_disconnect_backend as
netdev->real_num_tx_queues will not have been set correctly.
* If setup_netfront() fails, ensure that all the queues created are
cleaned up, not just those that have been set up.
* If any queues were set up and an error occurs, call
xennet_destroy_queues() to clean up the napi context.
* If any fatal error occurs, unregister and destroy the netdev to avoid
leaving around a half setup network device.

Signed-off-by: Ross Lagerwall 
Reviewed-by: Boris Ostrovsky 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/xen-netfront.c |   29 +++--
 1 file changed, 11 insertions(+), 18 deletions(-)

--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -1854,27 +1854,19 @@ static int talk_to_netback(struct xenbus
xennet_destroy_queues(info);
 
err = xennet_create_queues(info, &num_queues);
-   if (err < 0)
-   goto destroy_ring;
+   if (err < 0) {
+   xenbus_dev_fatal(dev, err, "creating queues");
+   kfree(info->queues);
+   info->queues = NULL;
+   goto out;
+   }
 
/* Create shared ring, alloc event channel -- for each queue */
for (i = 0; i < num_queues; ++i) {
queue = &info->queues[i];
err = setup_netfront(dev, queue, feature_split_evtchn);
-   if (err) {
-   /* setup_netfront() will tidy up the current
-* queue on error, but we need to clean up
-* those already allocated.
-*/
-   if (i > 0) {
-   rtnl_lock();
-   netif_set_real_num_tx_queues(info->netdev, i);
-   rtnl_unlock();
-   goto destroy_ring;
-   } else {
-   goto out;
-   }
-   }
+   if (err)
+   goto destroy_ring;
}
 
 again:
@@ -1964,9 +1956,10 @@ abort_transaction_no_dev_fatal:
xenbus_transaction_end(xbt, 1);
  destroy_ring:
xennet_disconnect_backend(info);
-   kfree(info->queues);
-   info->queues = NULL;
+   xennet_destroy_queues(info);
  out:
+   unregister_netdev(info->netdev);
+   xennet_free_netdev(info->netdev);
return err;
 }
 




[PATCH 4.9 099/109] dma-fence: Introduce drm_fence_set_error() helper

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Chris Wilson 

commit a009e975da5c7d42a7f5eaadc54946eb5f76c9af upstream.

The dma_fence.error field (formerly known as dma_fence.status) is an
optional field that may be set by drivers before calling
dma_fence_signal(). The field can be used to indicate that the fence was
completed in err rather than with success, and is visible to other
consumers of the fence and to userspace via sync_file.

This patch renames the field from status to error so that its meaning is
hopefully more clear (and distinct from dma_fence_get_status() which is
a composite between the error state and signal state) and adds a helper
that validates the preconditions of when it is suitable to adjust the
error field.

Signed-off-by: Chris Wilson 
Reviewed-by: Daniel Vetter 
Reviewed-by: Sumit Semwal 
Signed-off-by: Sumit Semwal 
Link: 
http://patchwork.freedesktop.org/patch/msgid/20170104141222.6992-3-ch...@chris-wilson.co.uk
[s/dma_fence/fence/g - gregkh]
Cc: Jisheng Zhang 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/dma-buf/fence.c |2 +-
 include/linux/fence.h   |   30 +-
 2 files changed, 26 insertions(+), 6 deletions(-)

--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -551,7 +551,7 @@ fence_init(struct fence *fence, const st
fence->context = context;
fence->seqno = seqno;
fence->flags = 0UL;
-   fence->status = 0;
+   fence->error = 0;
 
trace_fence_init(fence);
 }
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -47,7 +47,7 @@ struct fence_cb;
  * can be compared to decide which fence would be signaled later.
  * @flags: A mask of FENCE_FLAG_* defined below
  * @timestamp: Timestamp when the fence was signaled.
- * @status: Optional, only valid if < 0, must be set before calling
+ * @error: Optional, only valid if < 0, must be set before calling
  * fence_signal, indicates that the fence has completed with an error.
  *
  * the flags member must be manipulated and read using the appropriate
@@ -79,7 +79,7 @@ struct fence {
unsigned seqno;
unsigned long flags;
ktime_t timestamp;
-   int status;
+   int error;
 };
 
 enum fence_flag_bits {
@@ -132,7 +132,7 @@ struct fence_cb {
  * or some failure occurred that made it impossible to enable
  * signaling. True indicates successful enabling.
  *
- * fence->status may be set in enable_signaling, but only when false is
+ * fence->error may be set in enable_signaling, but only when false is
  * returned.
  *
  * Calling fence_signal before enable_signaling is called allows
@@ -144,7 +144,7 @@ struct fence_cb {
  * the second time will be a noop since it was already signaled.
  *
  * Notes on signaled:
- * May set fence->status if returning true.
+ * May set fence->error if returning true.
  *
  * Notes on wait:
  * Must not be NULL, set to fence_default_wait for default implementation.
@@ -351,13 +351,33 @@ static inline struct fence *fence_later(
 static inline int fence_get_status_locked(struct fence *fence)
 {
if (fence_is_signaled_locked(fence))
-   return fence->status < 0 ? fence->status : 1;
+   return fence->error ?: 1;
else
return 0;
 }
 
 int fence_get_status(struct fence *fence);
 
+/**
+ * fence_set_error - flag an error condition on the fence
+ * @fence: [in]the fence
+ * @error: [in]the error to store
+ *
+ * Drivers can supply an optional error status condition before they signal
+ * the fence, to indicate that the fence was completed due to an error
+ * rather than success. This must be set before signaling (so that the value
+ * is visible before any waiters on the signal callback are woken). This
+ * helper exists to help catching erroneous setting of #fence.error.
+ */
+static inline void fence_set_error(struct fence *fence,
+  int error)
+{
+   BUG_ON(test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags));
+   BUG_ON(error >= 0 || error < -MAX_ERRNO);
+
+   fence->error = error;
+}
+
 signed long fence_wait_timeout(struct fence *, bool intr, signed long timeout);
 signed long fence_wait_any_timeout(struct fence **fences, uint32_t count,
   bool intr, signed long timeout);




[PATCH 4.9 098/109] dma-fence: Wrap querying the fence->status

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Chris Wilson 

commit d6c99f4bf093a58d3ab47caaec74b81f18bc4e3f upstream.

The fence->status is an optional field that is only valid once the fence
has been signaled. (Driver may fill the fence->status with an error code
prior to calling dma_fence_signal().) Given the restriction upon its
validity, wrap querying of the fence->status into a helper
dma_fence_get_status().

Signed-off-by: Chris Wilson 
Reviewed-by: Daniel Vetter 
Reviewed-by: Sumit Semwal 
Signed-off-by: Sumit Semwal 
Link: 
http://patchwork.freedesktop.org/patch/msgid/20170104141222.6992-2-ch...@chris-wilson.co.uk
[s/dma_fence/fence/g - gregkh]
Cc: Jisheng Zhang 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/dma-buf/fence.c  |   25 +
 drivers/dma-buf/sync_debug.c |   20 ++--
 drivers/dma-buf/sync_file.c  |6 ++
 include/linux/fence.h|   24 
 4 files changed, 61 insertions(+), 14 deletions(-)

--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -281,6 +281,31 @@ int fence_add_callback(struct fence *fen
 EXPORT_SYMBOL(fence_add_callback);
 
 /**
+ * fence_get_status - returns the status upon completion
+ * @fence: [in]the fence to query
+ *
+ * This wraps fence_get_status_locked() to return the error status
+ * condition on a signaled fence. See fence_get_status_locked() for more
+ * details.
+ *
+ * Returns 0 if the fence has not yet been signaled, 1 if the fence has
+ * been signaled without an error condition, or a negative error code
+ * if the fence has been completed in err.
+ */
+int fence_get_status(struct fence *fence)
+{
+   unsigned long flags;
+   int status;
+
+   spin_lock_irqsave(fence->lock, flags);
+   status = fence_get_status_locked(fence);
+   spin_unlock_irqrestore(fence->lock, flags);
+
+   return status;
+}
+EXPORT_SYMBOL(fence_get_status);
+
+/**
  * fence_remove_callback - remove a callback from the signaling list
  * @fence: [in]the fence to wait on
  * @cb:[in]the callback to remove
--- a/drivers/dma-buf/sync_debug.c
+++ b/drivers/dma-buf/sync_debug.c
@@ -62,29 +62,29 @@ void sync_file_debug_remove(struct sync_
 
 static const char *sync_status_str(int status)
 {
-   if (status == 0)
-   return "signaled";
+   if (status < 0)
+   return "error";
 
if (status > 0)
-   return "active";
+   return "signaled";
 
-   return "error";
+   return "active";
 }
 
-static void sync_print_fence(struct seq_file *s, struct fence *fence, bool 
show)
+static void sync_print_fence(struct seq_file *s,
+struct fence *fence, bool show)
 {
-   int status = 1;
struct sync_timeline *parent = fence_parent(fence);
+   int status;
 
-   if (fence_is_signaled_locked(fence))
-   status = fence->status;
+   status = fence_get_status_locked(fence);
 
seq_printf(s, "  %s%sfence %s",
   show ? parent->name : "",
   show ? "_" : "",
   sync_status_str(status));
 
-   if (status <= 0) {
+   if (status) {
struct timespec64 ts64 =
ktime_to_timespec64(fence->timestamp);
 
@@ -133,7 +133,7 @@ static void sync_print_sync_file(struct
int i;
 
seq_printf(s, "[%p] %s: %s\n", sync_file, sync_file->name,
-  sync_status_str(!fence_is_signaled(sync_file->fence)));
+  sync_status_str(fence_get_status(sync_file->fence)));
 
if (fence_is_array(sync_file->fence)) {
struct fence_array *array = to_fence_array(sync_file->fence);
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -377,10 +377,8 @@ static void sync_fill_fence_info(struct
sizeof(info->obj_name));
strlcpy(info->driver_name, fence->ops->get_driver_name(fence),
sizeof(info->driver_name));
-   if (fence_is_signaled(fence))
-   info->status = fence->status >= 0 ? 1 : fence->status;
-   else
-   info->status = 0;
+
+   info->status = fence_get_status(fence);
info->timestamp_ns = ktime_to_ns(fence->timestamp);
 }
 
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -334,6 +334,30 @@ static inline struct fence *fence_later(
return fence_is_signaled(f2) ? NULL : f2;
 }
 
+/**
+ * fence_get_status_locked - returns the status upon completion
+ * @fence: [in]the fence to query
+ *
+ * Drivers can supply an optional error status condition before they signal
+ * the fence (to indicate whether the fence was completed due to an error
+ * rather than success). The value of the status condition is only valid
+ * if the fence has been signaled, fence_get_status_locked() first checks
+ * the signal state before reporting the error 

[PATCH 4.9 106/109] USB: Increase usbfs transfer limit

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Mateusz Berezecki 

commit 1129d270cbfbb7e2b1ec3dede4a13930bdd10e41 upstream.

Promote a variable keeping track of USB transfer memory usage to a
wider data type and allow for higher bandwidth transfers from a large
number of USB devices connected to a single host.

Signed-off-by: Mateusz Berezecki 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/devio.c |   43 ---
 1 file changed, 16 insertions(+), 27 deletions(-)

--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -134,42 +134,35 @@ enum snoop_when {
 #define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0)
 
 /* Limit on the total amount of memory we can allocate for transfers */
-static unsigned usbfs_memory_mb = 16;
+static u32 usbfs_memory_mb = 16;
 module_param(usbfs_memory_mb, uint, 0644);
 MODULE_PARM_DESC(usbfs_memory_mb,
"maximum MB allowed for usbfs buffers (0 = no limit)");
 
-/* Hard limit, necessary to avoid arithmetic overflow */
-#define USBFS_XFER_MAX (UINT_MAX / 2 - 100)
-
-static atomic_t usbfs_memory_usage;/* Total memory currently allocated */
+static atomic64_t usbfs_memory_usage;  /* Total memory currently allocated */
 
 /* Check whether it's okay to allocate more memory for a transfer */
-static int usbfs_increase_memory_usage(unsigned amount)
+static int usbfs_increase_memory_usage(u64 amount)
 {
-   unsigned lim;
+   u64 lim;
 
-   /*
-* Convert usbfs_memory_mb to bytes, avoiding overflows.
-* 0 means use the hard limit (effectively unlimited).
-*/
lim = ACCESS_ONCE(usbfs_memory_mb);
-   if (lim == 0 || lim > (USBFS_XFER_MAX >> 20))
-   lim = USBFS_XFER_MAX;
-   else
-   lim <<= 20;
+   lim <<= 20;
 
-   atomic_add(amount, &usbfs_memory_usage);
-   if (atomic_read(&usbfs_memory_usage) <= lim)
-   return 0;
-   atomic_sub(amount, &usbfs_memory_usage);
-   return -ENOMEM;
+   atomic64_add(amount, &usbfs_memory_usage);
+
+   if (lim > 0 && atomic64_read(&usbfs_memory_usage) > lim) {
+   atomic64_sub(amount, &usbfs_memory_usage);
+   return -ENOMEM;
+   }
+
+   return 0;
 }
 
 /* Memory for a transfer is being deallocated */
-static void usbfs_decrease_memory_usage(unsigned amount)
+static void usbfs_decrease_memory_usage(u64 amount)
 {
-   atomic_sub(amount, &usbfs_memory_usage);
+   atomic64_sub(amount, &usbfs_memory_usage);
 }
 
 static int connected(struct usb_dev_state *ps)
@@ -1191,7 +1184,7 @@ static int proc_bulk(struct usb_dev_stat
if (!usb_maxpacket(dev, pipe, !(bulk.ep & USB_DIR_IN)))
return -EINVAL;
len1 = bulk.len;
-   if (len1 >= USBFS_XFER_MAX)
+   if (len1 >= (INT_MAX - sizeof(struct urb)))
return -EINVAL;
ret = usbfs_increase_memory_usage(len1 + sizeof(struct urb));
if (ret)
@@ -1584,10 +1577,6 @@ static int proc_do_submiturb(struct usb_
return -EINVAL;
}
 
-   if (uurb->buffer_length >= USBFS_XFER_MAX) {
-   ret = -EINVAL;
-   goto error;
-   }
if (uurb->buffer_length > 0 &&
!access_ok(is_in ? VERIFY_WRITE : VERIFY_READ,
uurb->buffer, uurb->buffer_length)) {




[PATCH 4.9 096/109] dma-buf/sw_sync: clean up list before signaling the fence

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Gustavo Padovan 

commit 3792b7c1a70815fe4e954221c096f9278638fd21 upstream.

If userspace already dropped its own reference by closing the sw_sync
fence fd we might end up in a deadlock where
dma_fence_is_signaled_locked() will trigger the release of the fence and
thus try to hold the lock to remove the fence from the list.

dma_fence_is_signaled_locked() tries to release/free the fence and hold
the lock in the process.

We fix that by changing the order operation and clean up the list and
rb-tree first.

v2: Drop fence get/put dance and manipulate the list first (Chris Wilson)

Cc: Chris Wilson 
Signed-off-by: Gustavo Padovan 
Reviewed-by: Chris Wilson 
Link: 
https://patchwork.freedesktop.org/patch/msgid/20170729152217.8362-2-gust...@padovan.org
[s/dma_fence/fence/g - gregkh]
Cc: Jisheng Zhang 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/dma-buf/sw_sync.c |   12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

--- a/drivers/dma-buf/sw_sync.c
+++ b/drivers/dma-buf/sw_sync.c
@@ -213,11 +213,21 @@ static void sync_timeline_signal(struct
obj->value += inc;
 
list_for_each_entry_safe(pt, next, &obj->pt_list, link) {
-   if (!fence_is_signaled_locked(&pt->base))
+   if (!timeline_fence_signaled(&pt->base))
break;
 
list_del_init(&pt->link);
rb_erase(&pt->node, &obj->pt_tree);
+
+   /*
+* A signal callback may release the last reference to this
+* fence, causing it to be freed. That operation has to be
+* last to avoid a use after free inside this loop, and must
+* be after we remove the fence from the timeline in order to
+* prevent deadlocking on timeline->lock inside
+* timeline_fence_release().
+*/
+   fence_signal_locked(&pt->base);
}
 
spin_unlock_irq(&obj->lock);




[PATCH 4.9 104/109] usb: xhci: fix panic in xhci_free_virt_devices_depth_first

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Yu Chen 

commit 80e457699a8dbdd70f2d26911e46f538645c55fc upstream.

Check vdev->real_port 0 to avoid panic
[9.261347] [] 
xhci_free_virt_devices_depth_first+0x58/0x108
[9.261352] [] xhci_mem_cleanup+0x1bc/0x570
[9.261355] [] xhci_stop+0x140/0x1c8
[9.261365] [] usb_remove_hcd+0xfc/0x1d0
[9.261369] [] xhci_plat_remove+0x6c/0xa8
[9.261377] [] platform_drv_remove+0x2c/0x70
[9.261384] [] __device_release_driver+0x80/0x108
[9.261387] [] device_release_driver+0x2c/0x40
[9.261392] [] bus_remove_device+0xe0/0x120
[9.261396] [] device_del+0x114/0x210
[9.261399] [] platform_device_del+0x30/0xa0
[9.261403] [] dwc3_otg_work+0x204/0x488
[9.261407] [] event_work+0x304/0x5b8
[9.261414] [] process_one_work+0x148/0x490
[9.261417] [] worker_thread+0x50/0x4a0
[9.261421] [] kthread+0xe8/0x100
[9.261427] [] ret_from_fork+0x10/0x50

The problem can occur if xhci_plat_remove() is called shortly after
xhci_plat_probe(). While xhci_free_virt_devices_depth_first been
called before the device has been setup and get real_port initialized.
The problem occurred on Hikey960 and was reproduced by Guenter Roeck
on Kevin with chromeos-4.4.

Fixes: ee8665e28e8d ("xhci: free xhci virtual devices with leaf nodes first")
Cc: Guenter Roeck 
Reviewed-by: Guenter Roeck 
Tested-by: Guenter Roeck 
Signed-off-by: Fan Ning 
Signed-off-by: Li Rui 
Signed-off-by: yangdi 
Signed-off-by: Yu Chen 
Signed-off-by: Mathias Nyman 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/host/xhci-mem.c |7 +++
 1 file changed, 7 insertions(+)

--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -996,6 +996,12 @@ void xhci_free_virt_devices_depth_first(
if (!vdev)
return;
 
+   if (vdev->real_port == 0 ||
+   vdev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) {
+   xhci_dbg(xhci, "Bad vdev->real_port.\n");
+   goto out;
+   }
+
tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts);
list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) {
/* is this a hub device that added a tt_info to the tts list */
@@ -1009,6 +1015,7 @@ void xhci_free_virt_devices_depth_first(
}
}
}
+out:
/* we are now at a leaf device */
xhci_free_virt_device(xhci, slot_id);
 }




[PATCH 4.9 108/109] USB: usbfs: Filter flags passed in from user space

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Oliver Neukum 

commit 446f666da9f019ce2ffd03800995487e79a91462 upstream.

USBDEVFS_URB_ISO_ASAP must be accepted only for ISO endpoints.
Improve sanity checking.

Reported-by: Andrey Konovalov 
Signed-off-by: Oliver Neukum 
Acked-by: Alan Stern 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/devio.c |   14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1454,14 +1454,18 @@ static int proc_do_submiturb(struct usb_
int number_of_packets = 0;
unsigned int stream_id = 0;
void *buf;
-
-   if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP |
-   USBDEVFS_URB_SHORT_NOT_OK |
+   unsigned long mask =USBDEVFS_URB_SHORT_NOT_OK |
USBDEVFS_URB_BULK_CONTINUATION |
USBDEVFS_URB_NO_FSBR |
USBDEVFS_URB_ZERO_PACKET |
-   USBDEVFS_URB_NO_INTERRUPT))
-   return -EINVAL;
+   USBDEVFS_URB_NO_INTERRUPT;
+   /* USBDEVFS_URB_ISO_ASAP is a special case */
+   if (uurb->type == USBDEVFS_URB_TYPE_ISO)
+   mask |= USBDEVFS_URB_ISO_ASAP;
+
+   if (uurb->flags & ~mask)
+   return -EINVAL;
+
if ((unsigned int)uurb->buffer_length >= USBFS_XFER_MAX)
return -EINVAL;
if (uurb->buffer_length > 0 && !uurb->buffer)




[PATCH 4.9 105/109] USB: core: Add type-specific length check of BOS descriptors

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Masakazu Mokuno 

commit 81cf4a45360f70528f1f64ba018d61cb5767249a upstream.

As most of BOS descriptors are longer in length than their header
'struct usb_dev_cap_header', comparing solely with it is not sufficient
to avoid out-of-bounds access to BOS descriptors.

This patch adds descriptor type specific length check in
usb_get_bos_descriptor() to fix the issue.

Signed-off-by: Masakazu Mokuno 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/config.c|   28 
 include/uapi/linux/usb/ch9.h |3 +++
 2 files changed, 27 insertions(+), 4 deletions(-)

--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -900,14 +900,25 @@ void usb_release_bos_descriptor(struct u
}
 }
 
+static const __u8 bos_desc_len[256] = {
+   [USB_CAP_TYPE_WIRELESS_USB] = USB_DT_USB_WIRELESS_CAP_SIZE,
+   [USB_CAP_TYPE_EXT]  = USB_DT_USB_EXT_CAP_SIZE,
+   [USB_SS_CAP_TYPE]   = USB_DT_USB_SS_CAP_SIZE,
+   [USB_SSP_CAP_TYPE]  = USB_DT_USB_SSP_CAP_SIZE(1),
+   [CONTAINER_ID_TYPE] = USB_DT_USB_SS_CONTN_ID_SIZE,
+   [USB_PTM_CAP_TYPE]  = USB_DT_USB_PTM_ID_SIZE,
+};
+
 /* Get BOS descriptor set */
 int usb_get_bos_descriptor(struct usb_device *dev)
 {
struct device *ddev = &dev->dev;
struct usb_bos_descriptor *bos;
struct usb_dev_cap_header *cap;
+   struct usb_ssp_cap_descriptor *ssp_cap;
unsigned char *buffer;
-   int length, total_len, num, i;
+   int length, total_len, num, i, ssac;
+   __u8 cap_type;
int ret;
 
bos = kzalloc(sizeof(struct usb_bos_descriptor), GFP_KERNEL);
@@ -960,7 +971,13 @@ int usb_get_bos_descriptor(struct usb_de
dev->bos->desc->bNumDeviceCaps = i;
break;
}
+   cap_type = cap->bDevCapabilityType;
length = cap->bLength;
+   if (bos_desc_len[cap_type] && length < bos_desc_len[cap_type]) {
+   dev->bos->desc->bNumDeviceCaps = i;
+   break;
+   }
+
total_len -= length;
 
if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {
@@ -968,7 +985,7 @@ int usb_get_bos_descriptor(struct usb_de
continue;
}
 
-   switch (cap->bDevCapabilityType) {
+   switch (cap_type) {
case USB_CAP_TYPE_WIRELESS_USB:
/* Wireless USB cap descriptor is handled by wusb */
break;
@@ -981,8 +998,11 @@ int usb_get_bos_descriptor(struct usb_de
(struct usb_ss_cap_descriptor *)buffer;
break;
case USB_SSP_CAP_TYPE:
-   dev->bos->ssp_cap =
-   (struct usb_ssp_cap_descriptor *)buffer;
+   ssp_cap = (struct usb_ssp_cap_descriptor *)buffer;
+   ssac = (le32_to_cpu(ssp_cap->bmAttributes) &
+   USB_SSP_SUBLINK_SPEED_ATTRIBS) + 1;
+   if (length >= USB_DT_USB_SSP_CAP_SIZE(ssac))
+   dev->bos->ssp_cap = ssp_cap;
break;
case CONTAINER_ID_TYPE:
dev->bos->ss_id =
--- a/include/uapi/linux/usb/ch9.h
+++ b/include/uapi/linux/usb/ch9.h
@@ -854,6 +854,8 @@ struct usb_wireless_cap_descriptor {/*
__u8  bReserved;
 } __attribute__((packed));
 
+#define USB_DT_USB_WIRELESS_CAP_SIZE   11
+
 /* USB 2.0 Extension descriptor */
 #defineUSB_CAP_TYPE_EXT2
 
@@ -1046,6 +1048,7 @@ struct usb_ptm_cap_descriptor {
__u8  bDevCapabilityType;
 } __attribute__((packed));
 
+#define USB_DT_USB_PTM_ID_SIZE 3
 /*
  * The size of the descriptor for the Sublink Speed Attribute Count
  * (SSAC) specified in bmAttributes[4:0].




[PATCH 4.9 109/109] usb: host: fix incorrect updating of offset

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 

commit 1d5a31582ef046d3b233f0da1a68ae26519b2f0a upstream.

The variable temp is incorrectly being updated, instead it should
be offset otherwise the loop just reads the same capability value
and loops forever.  Thanks to Alan Stern for pointing out the
correct fix to my original fix.  Fix also cleans up clang warning:

drivers/usb/host/ehci-dbg.c:840:4: warning: Value stored to 'temp'
is never read

Fixes: d49d43174400 ("USB: misc ehci updates")
Signed-off-by: Colin Ian King 
Acked-by: Alan Stern 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/host/ehci-dbg.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -837,7 +837,7 @@ static ssize_t fill_registers_buffer(str
default:/* unknown */
break;
}
-   temp = (cap >> 8) & 0xff;
+   offset = (cap >> 8) & 0xff;
}
}
 #endif




Re: [PATCH v3] leds: trigger: Introduce a NETDEV trigger

2017-12-07 Thread Philippe Ombredanne
Ben,

On Thu, Dec 7, 2017 at 12:46 PM, Ben Whitten  wrote:
> From: Ben Whitten 
>
> This commit introduces a NETDEV trigger for named device
> activity. Available triggers are link, rx, and tx.
>
> Signed-off-by: Ben Whitten 
[]
> --- /dev/null
> +++ b/drivers/leds/trigger/ledtrig-netdev.c
> @@ -0,0 +1,503 @@
> +/*
> + * LED Kernel Netdev Trigger
> + *
> + * Toggles the LED to reflect the link and traffic state of a named net 
> device
> + *
> + * Copyright 2017 Ben Whitten 
> + *
> + * Copyright 2007 Oliver Jowett 
> + *
> + * Derived from ledtrig-timer.c which is:
> + *  Copyright 2005-2006 Openedhand Ltd.
> + *  Author: Richard Purdie 
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + */

Have you considered using the new SPDX id instead ? See Thomas doc
patches and Greg and Linus comments on the topic
Here this would likely come out this way (yes, using a C++ comment at the top):

> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * LED Kernel Netdev Trigger
> + *
> + * Toggles the LED to reflect the link and traffic state of a named net 
> device
> + *
> + * Copyright 2017 Ben Whitten 
> + *
> + * Copyright 2007 Oliver Jowett 
> + *
> + * Derived from ledtrig-timer.c which is:
> + *  Copyright 2005-2006 Openedhand Ltd.
> + *  Author: Richard Purdie 
> + *
> + */


This is cleaner and simpler, don't you think?

-- 
Cordially
Philippe Ombredanne


[PATCH V7 09/12] clk: sprd: Add dt-bindings include file for SC9860

2017-12-07 Thread Chunyan Zhang
This file defines all SC9860 clock indexes, it should be included in the
device tree in which there's device using the clocks.

Signed-off-by: Chunyan Zhang 
Acked-by: Rob Herring 
---
 include/dt-bindings/clock/sprd,sc9860-clk.h | 404 
 1 file changed, 404 insertions(+)
 create mode 100644 include/dt-bindings/clock/sprd,sc9860-clk.h

diff --git a/include/dt-bindings/clock/sprd,sc9860-clk.h 
b/include/dt-bindings/clock/sprd,sc9860-clk.h
new file mode 100644
index 000..4cb202f
--- /dev/null
+++ b/include/dt-bindings/clock/sprd,sc9860-clk.h
@@ -0,0 +1,404 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+//
+// Spreadtrum SC9860 platform clocks
+//
+// Copyright (C) 2017, Spreadtrum Communications Inc.
+
+#ifndef _DT_BINDINGS_CLK_SC9860_H_
+#define _DT_BINDINGS_CLK_SC9860_H_
+
+#defineCLK_FAC_4M  0
+#defineCLK_FAC_2M  1
+#defineCLK_FAC_1M  2
+#defineCLK_FAC_250K3
+#defineCLK_FAC_RPLL0_26M   4
+#defineCLK_FAC_RPLL1_26M   5
+#defineCLK_FAC_RCO25M  6
+#defineCLK_FAC_RCO4M   7
+#defineCLK_FAC_RCO2M   8
+#defineCLK_FAC_3K2 9
+#defineCLK_FAC_1K  10
+#defineCLK_MPLL0_GATE  11
+#defineCLK_MPLL1_GATE  12
+#defineCLK_DPLL0_GATE  13
+#defineCLK_DPLL1_GATE  14
+#defineCLK_LTEPLL0_GATE15
+#defineCLK_TWPLL_GATE  16
+#defineCLK_LTEPLL1_GATE17
+#defineCLK_RPLL0_GATE  18
+#defineCLK_RPLL1_GATE  19
+#defineCLK_CPPLL_GATE  20
+#defineCLK_GPLL_GATE   21
+#define CLK_PMU_GATE_NUM   (CLK_GPLL_GATE + 1)
+
+#defineCLK_MPLL0   0
+#defineCLK_MPLL1   1
+#defineCLK_DPLL0   2
+#defineCLK_DPLL1   3
+#defineCLK_RPLL0   4
+#defineCLK_RPLL1   5
+#defineCLK_TWPLL   6
+#defineCLK_LTEPLL0 7
+#defineCLK_LTEPLL1 8
+#defineCLK_GPLL9
+#defineCLK_CPPLL   10
+#defineCLK_GPLL_42M5   11
+#defineCLK_TWPLL_768M  12
+#defineCLK_TWPLL_384M  13
+#defineCLK_TWPLL_192M  14
+#defineCLK_TWPLL_96M   15
+#defineCLK_TWPLL_48M   16
+#defineCLK_TWPLL_24M   17
+#defineCLK_TWPLL_12M   18
+#defineCLK_TWPLL_512M  19
+#defineCLK_TWPLL_256M  20
+#defineCLK_TWPLL_128M  21
+#defineCLK_TWPLL_64M   22
+#defineCLK_TWPLL_307M2 23
+#defineCLK_TWPLL_153M6 24
+#defineCLK_TWPLL_76M8  25
+#defineCLK_TWPLL_51M2  26
+#defineCLK_TWPLL_38M4  27
+#defineCLK_TWPLL_19M2  28
+#defineCLK_L0_614M429
+#defineCLK_L0_409M630
+#defineCLK_L0_38M  31
+#defineCLK_L1_38M  32
+#defineCLK_RPLL0_192M  33
+#defineCLK_RPLL0_96M   34
+#defineCLK_RPLL0_48M   35
+#defineCLK_RPLL1_468M  36
+#defineCLK_RPLL1_192M  37
+#defineCLK_RPLL1_96M   38
+#defineCLK_RPLL1_64M   39
+#defineCLK_RPLL1_48M   40
+#defineCLK_DPLL0_50M   41
+#defineCLK_DPLL1_50M   42
+#defineCLK_CPPLL_50M   43
+#defineCLK_M0_39M  44
+#defineCLK_M1_63M  45
+#define CLK_PLL_NUM(CLK_M1_63M + 1)
+
+
+#defineCLK_AP_APB  0
+#defineCLK_AP_USB3 1
+#defineCLK_UART0   2
+#defineCLK_UART1   3
+#defineCLK_UART2   4
+#defineCLK_UART3   5
+#defineCLK_UART4   6
+#defineCLK_I2C07
+#defineCLK_I2C18
+#defineCLK_I2C29
+#defineCLK_I2C310
+#defineCLK_I2C411
+#defineCLK_I2C512
+#defineCLK_SPI013
+#defineCLK_SPI114
+#defineCLK_SPI215
+#defineCLK_SPI316
+#defineCLK_IIS017
+#defineCLK_IIS118
+#defineCLK_IIS219
+#defineCLK_IIS320
+#define CLK_AP_CLK_NUM (CLK_IIS3 + 1)
+
+#defineCLK_AON_APB 0
+#defineCLK_AUX01
+#defineCLK_AUX12
+#defineCLK_AUX23
+#defineCLK_PROBE   4
+#defineC

[PATCH V7 01/12] drivers: move clock common macros out from vendor directories

2017-12-07 Thread Chunyan Zhang
These macros are used by more than one SoC vendor platforms, avoid to
have many copies of these code, this patch moves them to the common
header file which every clock drivers can access to.

Signed-off-by: Chunyan Zhang 
---
 drivers/clk/sunxi-ng/ccu_common.h | 29 -
 drivers/clk/zte/clk.h | 18 --
 include/linux/clk-provider.h  | 38 ++
 3 files changed, 38 insertions(+), 47 deletions(-)

diff --git a/drivers/clk/sunxi-ng/ccu_common.h 
b/drivers/clk/sunxi-ng/ccu_common.h
index 5d684ce..568cfae 100644
--- a/drivers/clk/sunxi-ng/ccu_common.h
+++ b/drivers/clk/sunxi-ng/ccu_common.h
@@ -31,35 +31,6 @@
 
 struct device_node;
 
-#define CLK_HW_INIT(_name, _parent, _ops, _flags)  \
-   &(struct clk_init_data) {   \
-   .flags  = _flags,   \
-   .name   = _name,\
-   .parent_names   = (const char *[]) { _parent }, \
-   .num_parents= 1,\
-   .ops= _ops, \
-   }
-
-#define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
-   &(struct clk_init_data) {   \
-   .flags  = _flags,   \
-   .name   = _name,\
-   .parent_names   = _parents, \
-   .num_parents= ARRAY_SIZE(_parents), \
-   .ops= _ops, \
-   }
-
-#define CLK_FIXED_FACTOR(_struct, _name, _parent,  \
-   _div, _mult, _flags)\
-   struct clk_fixed_factor _struct = { \
-   .div= _div, \
-   .mult   = _mult,\
-   .hw.init= CLK_HW_INIT(_name,\
- _parent,  \
- &clk_fixed_factor_ops,\
- _flags),  \
-   }
-
 struct ccu_common {
void __iomem*base;
u16 reg;
diff --git a/drivers/clk/zte/clk.h b/drivers/clk/zte/clk.h
index 4df0f12..f1041e3 100644
--- a/drivers/clk/zte/clk.h
+++ b/drivers/clk/zte/clk.h
@@ -14,24 +14,6 @@
 
 #define PNAME(x) static const char *x[]
 
-#define CLK_HW_INIT(_name, _parent, _ops, _flags)  \
-   &(struct clk_init_data) {   \
-   .flags  = _flags,   \
-   .name   = _name,\
-   .parent_names   = (const char *[]) { _parent }, \
-   .num_parents= 1,\
-   .ops= _ops, \
-   }
-
-#define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
-   &(struct clk_init_data) {   \
-   .flags  = _flags,   \
-   .name   = _name,\
-   .parent_names   = _parents, \
-   .num_parents= ARRAY_SIZE(_parents), \
-   .ops= _ops, \
-   }
-
 struct zx_pll_config {
unsigned long rate;
u32 cfg0;
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 7c925e6..26ea037 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -806,6 +806,44 @@ extern struct of_device_id __clk_of_table;
}   \
OF_DECLARE_1(clk, name, compat, name##_of_clk_init_driver)
 
+#define CLK_HW_INIT(_name, _parent, _ops, _flags)  \
+   (&(struct clk_init_data) {  \
+   .flags  = _flags,   \
+   .name   = _name,\
+   .parent_names   = (const char *[]) { _parent }, \
+   .num_parents= 1,\
+   .ops= _ops, \
+   })
+
+#define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
+   (&(struct clk_init_data) {  \
+   .flags  = _flags,   \
+   .name   = _name,   

Re: [RFC PATCH] cpuidle/coupled: Handle broadcast enter failures

2017-12-07 Thread Daniel Lezcano
On 07/12/2017 12:47, James Hogan wrote:
> On Thu, Dec 07, 2017 at 12:17:25PM +0100, Daniel Lezcano wrote:
>> On 05/12/2017 23:55, James Hogan wrote:
>>> From: James Hogan 
>>>
>>> If the hrtimer based broadcast tick device is in use, the enabling of
>>> broadcast ticks by cpuidle may fail when the next broadcast event is
>>> brought forward to match the next event due on the local tick device,
>>> This is because setting the next event may migrate the hrtimer based
>>> broadcast tick to the current CPU, which then makes
>>> broadcast_needs_cpu() fail.
>>>
>>> This isn't normally a problem as cpuidle handles it by falling back to
>>> the deepest idle state not needing broadcast ticks, however when coupled
>>> cpuidle is used it can happen after the coupled CPUs have all agreed on
>>> a particular idle state, resulting in only one of the CPUs falling back
>>> to a shallower state, and an attempt to couple two completely different
>>> idle states which may not be safe.
>>>
>>> Therefore extend cpuidle_enter_state_coupled() to be able to handle the
>>> enabling of broadcast ticks directly, so that a failure can be detected
>>> at the higher level, and all coupled CPUs can be made to fall back to
>>> the same idle state.
>>>
>>> This takes place after the idle state has been initially agreed. Each
>>> CPU will then attempt to enable broadcast ticks (if necessary), and upon
>>> failure it will update the requested_state[] array before a second
>>> coupled parallel barrier so that all coupled CPUs can recognise the
>>> change.
>>>
>>> Signed-off-by: James Hogan 
>>> Cc: "Rafael J. Wysocki" 
>>> Cc: Daniel Lezcano 
>>> Cc: Frederic Weisbecker 
>>> Cc: Thomas Gleixner 
>>> Cc: Ingo Molnar 
>>> Cc: Preeti U Murthy 
>>> Cc: Ralf Baechle 
>>> Cc: Paul Burton 
>>> Cc: linux...@vger.kernel.org
>>> Cc: linux-kernel@vger.kernel.org
>>> Cc: linux-m...@linux-mips.org
>>> ---
>>> Is this an acceptable approach in principle?
>>>
>>> Better/cleaner ideas to handle this are most welcome.
>>>
>>> This doesn't directly address the problem that some of the time it won't
>>> be possible to enter deeper idle states because of the hrtimer based
>>> broadcast tick's affinity. The actual case I'm looking at is on MIPS
>>> with cpuidle-cps, where the first core cannot (currently) go into a deep
>>> idle state requiring broadcast ticks, so it'd be nice if the hrtimer
>>> based broadcast tick device could just stay on core 0.
>>> ---
>>
>> Before commenting this patch, I would like to understand why the couple
>> idle state is needed for the MIPS, what in the architecture forces the
>> usage of the couple idle state?
> 
> Hardware multithreading.
> 
> Each physical core may have more than one hardware thread (VPE or VP in
> MIPS lingo), each of which appears as a separate CPU to Linux. The lower
> power states are all effective at the core level though:
> - non-coherent wait - the hardware threads share physical caches, so
>   coherency can only be turned off when all hardware threads are in a
>   safe state, else they (1) wouldn't be coherent with the rest of the
>   system and (2) could bring stuff into the cache which isn't kept
>   coherent, requiring I presume a second cache flush.
> - clock gated - must go non-coherent first, and applies to the whole
>   core and all the physical resources shared by the VP(E)s.
> - power gated - again must go non-coherent first, and applies to the
>   whole core and all the physical resources shared by the VP(E)s.

The couple idle state was introduced to compensate hardware mis-design.

There are a couple of examples omap4 and exynos4 where only CPU0 can do
some PM operations. AFAICT, from the feedbacks I got, couple idle state
consume more energy than it saves (very likely because of the busy loop
sync mechanism).

I did some tests with a 4 cores system and the overhead was so high the
system had a very bad response time, so dropped the cluster idle state.

So before going further in the couple idle path, I suggest you
investigate first a sync mechanism which may be implemented by the
hardware. One good example is the cpuidle-ux500.c.

With a proper last man standing sync, we can then take care of the timer
broadcast thing. I can give you a hand for that if you need.

>> The hrtimer broadcast mechanism is only needed if there isn't a backup
>> timer outside of the idle state's power domain. That's the case on this
>> platform?
> 
> I believe there is an external timer, and I believe we recommend
> customers implement one for use as a clocksource anyway (in case of
> frequency scaling), but on this particular platform the driver isn't
> upstream yet.

Perhaps, you can upstream the external timer driver first?

> If its something that shouldn't be supported in Linux, perhaps a simple
> WARN_ON is the better approach (i.e. if the broadcast tick can't be
> enabled in the current place and its a coupled idle state), though it
> does at least seem to work now with this and a couple of other patches
> (th

[PATCH V7 02/12] clk: sprd: Add common infrastructure

2017-12-07 Thread Chunyan Zhang
Added Spreadtrum's clock driver framework together with common
structures and interface functions.

Signed-off-by: Chunyan Zhang 
---
 drivers/clk/Kconfig   |  1 +
 drivers/clk/Makefile  |  1 +
 drivers/clk/sprd/Kconfig  |  4 ++
 drivers/clk/sprd/Makefile |  3 ++
 drivers/clk/sprd/common.c | 96 +++
 drivers/clk/sprd/common.h | 38 +++
 6 files changed, 143 insertions(+)
 create mode 100644 drivers/clk/sprd/Kconfig
 create mode 100644 drivers/clk/sprd/Makefile
 create mode 100644 drivers/clk/sprd/common.c
 create mode 100644 drivers/clk/sprd/common.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 1c4e1aa..ce1a32be 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -236,6 +236,7 @@ source "drivers/clk/mvebu/Kconfig"
 source "drivers/clk/qcom/Kconfig"
 source "drivers/clk/renesas/Kconfig"
 source "drivers/clk/samsung/Kconfig"
+source "drivers/clk/sprd/Kconfig"
 source "drivers/clk/sunxi-ng/Kconfig"
 source "drivers/clk/tegra/Kconfig"
 source "drivers/clk/ti/Kconfig"
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index f7f761b..d880d13 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -85,6 +85,7 @@ obj-$(CONFIG_COMMON_CLK_SAMSUNG)  += samsung/
 obj-$(CONFIG_ARCH_SIRF)+= sirf/
 obj-$(CONFIG_ARCH_SOCFPGA) += socfpga/
 obj-$(CONFIG_PLAT_SPEAR)   += spear/
+obj-$(CONFIG_ARCH_SPRD)+= sprd/
 obj-$(CONFIG_ARCH_STI) += st/
 obj-$(CONFIG_ARCH_SUNXI)   += sunxi/
 obj-$(CONFIG_ARCH_SUNXI)   += sunxi-ng/
diff --git a/drivers/clk/sprd/Kconfig b/drivers/clk/sprd/Kconfig
new file mode 100644
index 000..67a3287
--- /dev/null
+++ b/drivers/clk/sprd/Kconfig
@@ -0,0 +1,4 @@
+config SPRD_COMMON_CLK
+   tristate "Clock support for Spreadtrum SoCs"
+   depends on ARCH_SPRD || COMPILE_TEST
+   default ARCH_SPRD
diff --git a/drivers/clk/sprd/Makefile b/drivers/clk/sprd/Makefile
new file mode 100644
index 000..74f4b80
--- /dev/null
+++ b/drivers/clk/sprd/Makefile
@@ -0,0 +1,3 @@
+obj-$(CONFIG_SPRD_COMMON_CLK)  += clk-sprd.o
+
+clk-sprd-y += common.o
diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c
new file mode 100644
index 000..e038b044
--- /dev/null
+++ b/drivers/clk/sprd/common.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum clock infrastructure
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "common.h"
+
+static const struct regmap_config sprdclk_regmap_config = {
+   .reg_bits   = 32,
+   .reg_stride = 4,
+   .val_bits   = 32,
+   .max_register   = 0x,
+   .fast_io= true,
+};
+
+static void sprd_clk_set_regmap(const struct sprd_clk_desc *desc,
+struct regmap *regmap)
+{
+   int i;
+   struct sprd_clk_common *cclk;
+
+   for (i = 0; i < desc->num_clk_clks; i++) {
+   cclk = desc->clk_clks[i];
+   if (!cclk)
+   continue;
+
+   cclk->regmap = regmap;
+   }
+}
+
+int sprd_clk_regmap_init(struct platform_device *pdev,
+const struct sprd_clk_desc *desc)
+{
+   void __iomem *base;
+   struct device_node *node = pdev->dev.of_node;
+   struct regmap *regmap;
+
+   if (of_find_property(node, "sprd,syscon", NULL)) {
+   regmap = syscon_regmap_lookup_by_phandle(node, "sprd,syscon");
+   if (IS_ERR_OR_NULL(regmap)) {
+   pr_err("%s: failed to get syscon regmap\n", __func__);
+   return PTR_ERR(regmap);
+   }
+   } else {
+   base = of_iomap(node, 0);
+   regmap = devm_regmap_init_mmio(&pdev->dev, base,
+  &sprdclk_regmap_config);
+   if (IS_ERR_OR_NULL(regmap)) {
+   pr_err("failed to init regmap\n");
+   return PTR_ERR(regmap);
+   }
+   }
+
+   sprd_clk_set_regmap(desc, regmap);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(sprd_clk_regmap_init);
+
+int sprd_clk_probe(struct device *dev, struct clk_hw_onecell_data *clkhw)
+{
+   int i, ret;
+   struct clk_hw *hw;
+
+   for (i = 0; i < clkhw->num; i++) {
+
+   hw = clkhw->hws[i];
+
+   if (!hw)
+   continue;
+
+   ret = devm_clk_hw_register(dev, hw);
+   if (ret) {
+   dev_err(dev, "Couldn't register clock %d - %s\n",
+   i, hw->init->name);
+   return ret;
+   }
+   }
+
+   ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clkhw);
+   if (ret)
+   dev_err(dev, "Failed to add clock provider\n");
+
+   return ret;
+

[PATCH V7 04/12] clk: sprd: add mux clock support

2017-12-07 Thread Chunyan Zhang
This patch adds clock multiplexor support for Spreadtrum platforms,
the mux clocks also can be found in sprd composite clocks, so
provides two helpers that can be reused later on.

Signed-off-by: Chunyan Zhang 
---
 drivers/clk/sprd/Makefile |  1 +
 drivers/clk/sprd/mux.c| 76 +++
 drivers/clk/sprd/mux.h| 74 +
 3 files changed, 151 insertions(+)
 create mode 100644 drivers/clk/sprd/mux.c
 create mode 100644 drivers/clk/sprd/mux.h

diff --git a/drivers/clk/sprd/Makefile b/drivers/clk/sprd/Makefile
index 8cd5592..cee36b5 100644
--- a/drivers/clk/sprd/Makefile
+++ b/drivers/clk/sprd/Makefile
@@ -2,3 +2,4 @@ obj-$(CONFIG_SPRD_COMMON_CLK)   += clk-sprd.o
 
 clk-sprd-y += common.o
 clk-sprd-y += gate.o
+clk-sprd-y += mux.o
diff --git a/drivers/clk/sprd/mux.c b/drivers/clk/sprd/mux.c
new file mode 100644
index 000..624041b
--- /dev/null
+++ b/drivers/clk/sprd/mux.c
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum multiplexer clock driver
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#include 
+#include 
+#include 
+
+#include "mux.h"
+
+u8 sprd_mux_helper_get_parent(const struct sprd_clk_common *common,
+ const struct sprd_mux_ssel *mux)
+{
+   unsigned int reg;
+   u8 parent;
+   int num_parents;
+   int i;
+
+   regmap_read(common->regmap, common->reg, ®);
+   parent = reg >> mux->shift;
+   parent &= (1 << mux->width) - 1;
+
+   if (!mux->table)
+   return parent;
+
+   num_parents = clk_hw_get_num_parents(&common->hw);
+
+   for (i = 0; i < num_parents - 1; i++)
+   if (parent >= mux->table[i] && parent < mux->table[i + 1])
+   return i;
+
+   return num_parents - 1;
+}
+EXPORT_SYMBOL_GPL(sprd_mux_helper_get_parent);
+
+static u8 sprd_mux_get_parent(struct clk_hw *hw)
+{
+   struct sprd_mux *cm = hw_to_sprd_mux(hw);
+
+   return sprd_mux_helper_get_parent(&cm->common, &cm->mux);
+}
+
+int sprd_mux_helper_set_parent(const struct sprd_clk_common *common,
+  const struct sprd_mux_ssel *mux,
+  u8 index)
+{
+   unsigned int reg;
+
+   if (mux->table)
+   index = mux->table[index];
+
+   regmap_read(common->regmap, common->reg, ®);
+   reg &= ~GENMASK(mux->width + mux->shift - 1, mux->shift);
+   regmap_write(common->regmap, common->reg,
+ reg | (index << mux->shift));
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(sprd_mux_helper_set_parent);
+
+static int sprd_mux_set_parent(struct clk_hw *hw, u8 index)
+{
+   struct sprd_mux *cm = hw_to_sprd_mux(hw);
+
+   return sprd_mux_helper_set_parent(&cm->common, &cm->mux, index);
+}
+
+const struct clk_ops sprd_mux_ops = {
+   .get_parent = sprd_mux_get_parent,
+   .set_parent = sprd_mux_set_parent,
+   .determine_rate = __clk_mux_determine_rate,
+};
+EXPORT_SYMBOL_GPL(sprd_mux_ops);
diff --git a/drivers/clk/sprd/mux.h b/drivers/clk/sprd/mux.h
new file mode 100644
index 000..548cfa0
--- /dev/null
+++ b/drivers/clk/sprd/mux.h
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum multiplexer clock driver
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#ifndef _SPRD_MUX_H_
+#define _SPRD_MUX_H_
+
+#include "common.h"
+
+/**
+ * struct sprd_mux_ssel - Mux clock's source select bits in its register
+ * @shift: Bit offset of the divider in its register
+ * @width: Width of the divider field in its register
+ * @table: For some mux clocks, not all sources are used on some special
+ *chips, this matches the value of mux clock's register and the
+ *sources which are used for this mux clock
+ */
+struct sprd_mux_ssel {
+   u8  shift;
+   u8  width;
+   const u8*table;
+};
+
+struct sprd_mux {
+   struct sprd_mux_ssel mux;
+   struct sprd_clk_common  common;
+};
+
+#define _SPRD_MUX_CLK(_shift, _width, _table)  \
+   {   \
+   .shift  = _shift,   \
+   .width  = _width,   \
+   .table  = _table,   \
+   }
+
+#define SPRD_MUX_CLK_TABLE(_struct, _name, _parents, _table,   \
+_reg, _shift, _width,  \
+_flags)\
+   struct sprd_mux _struct = { \
+   .mux= _SPRD_MUX_CLK(_shift, _width, _table),\
+   .common = { \
+   .regmap = NULL, \
+   .reg= _reg, \
+   

[PATCH V7 07/12] clk: sprd: add adjustable pll support

2017-12-07 Thread Chunyan Zhang
Introduced a common adjustable pll clock driver for Spreadtrum SoCs.

Signed-off-by: Chunyan Zhang 
---
 drivers/clk/sprd/Makefile |   1 +
 drivers/clk/sprd/pll.c| 266 ++
 drivers/clk/sprd/pll.h| 108 +++
 3 files changed, 375 insertions(+)
 create mode 100644 drivers/clk/sprd/pll.c
 create mode 100644 drivers/clk/sprd/pll.h

diff --git a/drivers/clk/sprd/Makefile b/drivers/clk/sprd/Makefile
index 2262e76..d693969 100644
--- a/drivers/clk/sprd/Makefile
+++ b/drivers/clk/sprd/Makefile
@@ -5,3 +5,4 @@ clk-sprd-y  += gate.o
 clk-sprd-y += mux.o
 clk-sprd-y += div.o
 clk-sprd-y += composite.o
+clk-sprd-y += pll.o
diff --git a/drivers/clk/sprd/pll.c b/drivers/clk/sprd/pll.c
new file mode 100644
index 000..36b4402
--- /dev/null
+++ b/drivers/clk/sprd/pll.c
@@ -0,0 +1,266 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum pll clock driver
+//
+// Copyright (C) 2015~2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "pll.h"
+
+#define CLK_PLL_1M 100
+#define CLK_PLL_10M(CLK_PLL_1M * 10)
+
+#define pindex(pll, member)\
+   (pll->factors[member].shift / (8 * sizeof(pll->regs_num)))
+
+#define pshift(pll, member)\
+   (pll->factors[member].shift % (8 * sizeof(pll->regs_num)))
+
+#define pwidth(pll, member)\
+   pll->factors[member].width
+
+#define pmask(pll, member) \
+   ((pwidth(pll, member)) ?\
+   GENMASK(pwidth(pll, member) + pshift(pll, member) - 1,  \
+   pshift(pll, member)) : 0)
+
+#define pinternal(pll, cfg, member)\
+   (cfg[pindex(pll, member)] & pmask(pll, member))
+
+#define pinternal_val(pll, cfg, member)\
+   (pinternal(pll, cfg, member) >> pshift(pll, member))
+
+static inline unsigned int
+sprd_pll_read(const struct sprd_pll *pll, u8 index)
+{
+   const struct sprd_clk_common *common = &pll->common;
+   unsigned int val = 0;
+
+   if (WARN_ON(index >= pll->regs_num))
+   return 0;
+
+   regmap_read(common->regmap, common->reg + index * 4, &val);
+
+   return val;
+}
+
+static inline void
+sprd_pll_write(const struct sprd_pll *pll, u8 index,
+ u32 msk, u32 val)
+{
+   const struct sprd_clk_common *common = &pll->common;
+   unsigned int offset, reg;
+   int ret = 0;
+
+   if (WARN_ON(index >= pll->regs_num))
+   return;
+
+   offset = common->reg + index * 4;
+   ret = regmap_read(common->regmap, offset, ®);
+   if (!ret)
+   regmap_write(common->regmap, offset, (reg & ~msk) | val);
+}
+
+static unsigned long pll_get_refin(const struct sprd_pll *pll)
+{
+   u32 shift, mask, index, refin_id = 3;
+   const unsigned long refin[4] = { 2, 4, 13, 26 };
+
+   if (pwidth(pll, PLL_REFIN)) {
+   index = pindex(pll, PLL_REFIN);
+   shift = pshift(pll, PLL_REFIN);
+   mask = pmask(pll, PLL_REFIN);
+   refin_id = (sprd_pll_read(pll, index) & mask) >> shift;
+   if (refin_id > 3)
+   refin_id = 3;
+   }
+
+   return refin[refin_id];
+}
+
+static u32 pll_get_ibias(u64 rate, const u64 *table)
+{
+   u32 i, num = table[0];
+
+   for (i = 1; i < num + 1; i++)
+   if (rate <= table[i])
+   break;
+
+   return (i == num + 1) ? num : i;
+}
+
+static unsigned long _sprd_pll_recalc_rate(const struct sprd_pll *pll,
+  unsigned long parent_rate)
+{
+   u32 *cfg;
+   u32 i, mask, regs_num = pll->regs_num;
+   unsigned long rate, nint, kint = 0;
+   u64 refin;
+   u16 k1, k2;
+
+   cfg = kcalloc(regs_num, sizeof(*cfg), GFP_KERNEL);
+   if (!cfg)
+   return -ENOMEM;
+
+   for (i = 0; i < regs_num; i++)
+   cfg[i] = sprd_pll_read(pll, i);
+
+   refin = pll_get_refin(pll);
+
+   if (pinternal(pll, cfg, PLL_PREDIV))
+   refin = refin * 2;
+
+   if (pwidth(pll, PLL_POSTDIV) &&
+   ((pll->fflag == 1 && pinternal(pll, cfg, PLL_POSTDIV)) ||
+(!pll->fflag && !pinternal(pll, cfg, PLL_POSTDIV
+   refin = refin / 2;
+
+   if (!pinternal(pll, cfg, PLL_DIV_S)) {
+   rate = refin * pinternal_val(pll, cfg, PLL_N) * CLK_PLL_10M;
+   } else {
+   nint = pinternal_val(pll, cfg, PLL_NINT);
+   if (pinternal(pll, cfg, PLL_SDM_EN))
+   kint = pinternal_val(pll, cfg, PLL_KINT);
+
+   mask = pmask(pll, PLL_KINT);
+
+   k1 = pll->k1;
+   k2 = pll->k2;
+   rate = DIV_ROUND_CLOSEST_ULL(refin * kint * k1,
+((mask >> __ffs(mask)) + 1)) *
+k2 + refin

[PATCH V7 06/12] clk: sprd: add composite clock support

2017-12-07 Thread Chunyan Zhang
This patch introduced composite driver for Spreadtrum's SoCs. The
functions of this composite clock simply consist of divider and
mux clocks.

Signed-off-by: Chunyan Zhang 
---
 drivers/clk/sprd/Makefile|  1 +
 drivers/clk/sprd/composite.c | 60 
 drivers/clk/sprd/composite.h | 51 +
 3 files changed, 112 insertions(+)
 create mode 100644 drivers/clk/sprd/composite.c
 create mode 100644 drivers/clk/sprd/composite.h

diff --git a/drivers/clk/sprd/Makefile b/drivers/clk/sprd/Makefile
index 80e6039..2262e76 100644
--- a/drivers/clk/sprd/Makefile
+++ b/drivers/clk/sprd/Makefile
@@ -4,3 +4,4 @@ clk-sprd-y  += common.o
 clk-sprd-y += gate.o
 clk-sprd-y += mux.o
 clk-sprd-y += div.o
+clk-sprd-y += composite.o
diff --git a/drivers/clk/sprd/composite.c b/drivers/clk/sprd/composite.c
new file mode 100644
index 000..ebb6448
--- /dev/null
+++ b/drivers/clk/sprd/composite.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum composite clock driver
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#include 
+
+#include "composite.h"
+
+static long sprd_comp_round_rate(struct clk_hw *hw, unsigned long rate,
+   unsigned long *parent_rate)
+{
+   struct sprd_comp *cc = hw_to_sprd_comp(hw);
+
+   return sprd_div_helper_round_rate(&cc->common, &cc->div,
+rate, parent_rate);
+}
+
+static unsigned long sprd_comp_recalc_rate(struct clk_hw *hw,
+ unsigned long parent_rate)
+{
+   struct sprd_comp *cc = hw_to_sprd_comp(hw);
+
+   return sprd_div_helper_recalc_rate(&cc->common, &cc->div, parent_rate);
+}
+
+static int sprd_comp_set_rate(struct clk_hw *hw, unsigned long rate,
+unsigned long parent_rate)
+{
+   struct sprd_comp *cc = hw_to_sprd_comp(hw);
+
+   return sprd_div_helper_set_rate(&cc->common, &cc->div,
+  rate, parent_rate);
+}
+
+static u8 sprd_comp_get_parent(struct clk_hw *hw)
+{
+   struct sprd_comp *cc = hw_to_sprd_comp(hw);
+
+   return sprd_mux_helper_get_parent(&cc->common, &cc->mux);
+}
+
+static int sprd_comp_set_parent(struct clk_hw *hw, u8 index)
+{
+   struct sprd_comp *cc = hw_to_sprd_comp(hw);
+
+   return sprd_mux_helper_set_parent(&cc->common, &cc->mux, index);
+}
+
+const struct clk_ops sprd_comp_ops = {
+   .get_parent = sprd_comp_get_parent,
+   .set_parent = sprd_comp_set_parent,
+
+   .round_rate = sprd_comp_round_rate,
+   .recalc_rate= sprd_comp_recalc_rate,
+   .set_rate   = sprd_comp_set_rate,
+};
+EXPORT_SYMBOL_GPL(sprd_comp_ops);
diff --git a/drivers/clk/sprd/composite.h b/drivers/clk/sprd/composite.h
new file mode 100644
index 000..0984e9e
--- /dev/null
+++ b/drivers/clk/sprd/composite.h
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum composite clock driver
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#ifndef _SPRD_COMPOSITE_H_
+#define _SPRD_COMPOSITE_H_
+
+#include "common.h"
+#include "mux.h"
+#include "div.h"
+
+struct sprd_comp {
+   struct sprd_mux_sselmux;
+   struct sprd_div_internaldiv;
+   struct sprd_clk_common  common;
+};
+
+#define SPRD_COMP_CLK_TABLE(_struct, _name, _parent, _reg, _table, \
+   _mshift, _mwidth, _dshift, _dwidth, _flags) \
+   struct sprd_comp _struct = {\
+   .mux= _SPRD_MUX_CLK(_mshift, _mwidth, _table),  \
+   .div= _SPRD_DIV_CLK(_dshift, _dwidth),  \
+   .common = { \
+   .regmap = NULL, \
+   .reg= _reg, \
+   .hw.init = CLK_HW_INIT_PARENTS(_name,   \
+  _parent, \
+  &sprd_comp_ops,  \
+  _flags), \
+}  \
+   }
+
+#define SPRD_COMP_CLK(_struct, _name, _parent, _reg, _mshift,  \
+   _mwidth, _dshift, _dwidth, _flags)  \
+   SPRD_COMP_CLK_TABLE(_struct, _name, _parent, _reg,  \
+   NULL, _mshift, _mwidth, \
+   _dshift, _dwidth, _flags)
+
+static inline struct sprd_comp *hw_to_sprd_comp(const struct clk_hw *hw)
+{
+   struct sprd_clk_common *common = hw_to_sprd_clk_common(hw);
+
+   return container_of(common, struct sprd_comp, common);
+}
+
+extern const struct clk_ops sprd_comp_ops;
+
+#endif /* _SPRD_COMPOSITE_H_ */
-- 
2.7.4



[PATCH V7 10/12] clk: sprd: add clocks support for SC9860

2017-12-07 Thread Chunyan Zhang
This patch added the list of clocks for Spreadtrum's SC9860 SoC,
together with clock initialization code.

Signed-off-by: Chunyan Zhang 
---
 drivers/clk/sprd/Kconfig  |   10 +
 drivers/clk/sprd/Makefile |3 +
 drivers/clk/sprd/sc9860-clk.c | 1974 +
 3 files changed, 1987 insertions(+)
 create mode 100644 drivers/clk/sprd/sc9860-clk.c

diff --git a/drivers/clk/sprd/Kconfig b/drivers/clk/sprd/Kconfig
index 67a3287..8789247 100644
--- a/drivers/clk/sprd/Kconfig
+++ b/drivers/clk/sprd/Kconfig
@@ -2,3 +2,13 @@ config SPRD_COMMON_CLK
tristate "Clock support for Spreadtrum SoCs"
depends on ARCH_SPRD || COMPILE_TEST
default ARCH_SPRD
+
+if SPRD_COMMON_CLK
+
+# SoC Drivers
+
+config SPRD_SC9860_CLK
+   tristate "Support for the Spreadtrum SC9860 clocks"
+   depends on (ARM64 && ARCH_SPRD) || COMPILE_TEST
+   default ARM64 && ARCH_SPRD
+endif
diff --git a/drivers/clk/sprd/Makefile b/drivers/clk/sprd/Makefile
index d693969..b0d81e5 100644
--- a/drivers/clk/sprd/Makefile
+++ b/drivers/clk/sprd/Makefile
@@ -6,3 +6,6 @@ clk-sprd-y  += mux.o
 clk-sprd-y += div.o
 clk-sprd-y += composite.o
 clk-sprd-y += pll.o
+
+## SoC support
+obj-$(CONFIG_SPRD_SC9860_CLK)  += sc9860-clk.o
diff --git a/drivers/clk/sprd/sc9860-clk.c b/drivers/clk/sprd/sc9860-clk.c
new file mode 100644
index 000..ed5c027
--- /dev/null
+++ b/drivers/clk/sprd/sc9860-clk.c
@@ -0,0 +1,1974 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreatrum SC9860 clock driver
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "common.h"
+#include "composite.h"
+#include "div.h"
+#include "gate.h"
+#include "mux.h"
+#include "pll.h"
+
+static CLK_FIXED_FACTOR(fac_4m,"fac-4m",   "ext-26m",
+   6, 1, 0);
+static CLK_FIXED_FACTOR(fac_2m,"fac-2m",   "ext-26m",
+   13, 1, 0);
+static CLK_FIXED_FACTOR(fac_1m,"fac-1m",   "ext-26m",
+   26, 1, 0);
+static CLK_FIXED_FACTOR(fac_250k,  "fac-250k", "ext-26m",
+   104, 1, 0);
+static CLK_FIXED_FACTOR(fac_rpll0_26m, "rpll0-26m","ext-26m",
+   1, 1, 0);
+static CLK_FIXED_FACTOR(fac_rpll1_26m, "rpll1-26m","ext-26m",
+   1, 1, 0);
+static CLK_FIXED_FACTOR(fac_rco_25m,   "rco-25m",  "ext-rc0-100m",
+   4, 1, 0);
+static CLK_FIXED_FACTOR(fac_rco_4m,"rco-4m",   "ext-rc0-100m",
+   25, 1, 0);
+static CLK_FIXED_FACTOR(fac_rco_2m,"rco-2m",   "ext-rc0-100m",
+   50, 1, 0);
+static CLK_FIXED_FACTOR(fac_3k2,   "fac-3k2",  "ext-32k",
+   10, 1, 0);
+static CLK_FIXED_FACTOR(fac_1k,"fac-1k",   "ext-32k",
+   32, 1, 0);
+
+static SPRD_SC_GATE_CLK(mpll0_gate,"mpll0-gate",   "ext-26m", 0xb0,
+0x1000, BIT(2), CLK_IGNORE_UNUSED, 0);
+static SPRD_SC_GATE_CLK(mpll1_gate,"mpll1-gate",   "ext-26m", 0xb0,
+0x1000, BIT(18), CLK_IGNORE_UNUSED, 0);
+static SPRD_SC_GATE_CLK(dpll0_gate,"dpll0-gate",   "ext-26m", 0xb4,
+0x1000, BIT(2), CLK_IGNORE_UNUSED, 0);
+static SPRD_SC_GATE_CLK(dpll1_gate,"dpll1-gate",   "ext-26m", 0xb4,
+0x1000, BIT(18), CLK_IGNORE_UNUSED, 0);
+static SPRD_SC_GATE_CLK(ltepll0_gate,  "ltepll0-gate", "ext-26m", 0xb8,
+0x1000, BIT(2), CLK_IGNORE_UNUSED, 0);
+static SPRD_SC_GATE_CLK(twpll_gate,"twpll-gate",   "ext-26m", 0xbc,
+0x1000, BIT(2), CLK_IGNORE_UNUSED, 0);
+static SPRD_SC_GATE_CLK(ltepll1_gate,  "ltepll1-gate", "ext-26m", 0x10c,
+0x1000, BIT(2), CLK_IGNORE_UNUSED, 0);
+static SPRD_SC_GATE_CLK(rpll0_gate,"rpll0-gate",   "ext-26m", 0x16c,
+0x1000, BIT(2), 0, 0);
+static SPRD_SC_GATE_CLK(rpll1_gate,"rpll1-gate",   "ext-26m", 0x16c,
+0x1000, BIT(18), 0, 0);
+static SPRD_SC_GATE_CLK(cppll_gate,"cppll-gate",   "ext-26m", 0x2b4,
+0x1000, BIT(2), CLK_IGNORE_UNUSED, 0);
+static SPRD_SC_GATE_CLK(gpll_gate, "gpll-gate","ext-26m", 0x32c,
+   0x1000, BIT(0), CLK_IGNORE_UNUSED, CLK_GATE_SET_TO_DISABLE);
+
+static struct sprd_clk_common *sc9860_pmu_gate_clks[] = {
+   /* address base is 0x402b */
+   &mpll0_gate.common,
+   &mpll1_gate.common,
+   &dpll0_gate.common,
+   &dpll1_gate.common,
+   

[PATCH V7 12/12] arm64: dts: add clocks for SC9860

2017-12-07 Thread Chunyan Zhang
Some clocks on SC9860 are in the same address area with syscon devices,
those are what have a property of 'sprd,syscon' which would refer to
syscon devices, others would have a reg property indicated their address
ranges.

Signed-off-by: Chunyan Zhang 
---
 arch/arm64/boot/dts/sprd/sc9860.dtsi | 115 +++
 arch/arm64/boot/dts/sprd/whale2.dtsi |  18 +-
 2 files changed, 131 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/sprd/sc9860.dtsi 
b/arch/arm64/boot/dts/sprd/sc9860.dtsi
index 7b7d8ce..bf03da4 100644
--- a/arch/arm64/boot/dts/sprd/sc9860.dtsi
+++ b/arch/arm64/boot/dts/sprd/sc9860.dtsi
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include "whale2.dtsi"
 
 / {
@@ -183,6 +184,120 @@
};
 
soc {
+   pmu_gate: pmu-gate {
+   compatible = "sprd,sc9860-pmu-gate";
+   sprd,syscon = <&pmu_regs>; /* 0x402b */
+   clocks = <&ext_26m>;
+   #clock-cells = <1>;
+   };
+
+   pll: pll {
+   compatible = "sprd,sc9860-pll";
+   sprd,syscon = <&ana_regs>; /* 0x4040 */
+   clocks = <&pmu_gate 0>;
+   #clock-cells = <1>;
+   };
+
+   ap_clk: clock-controller@2000 {
+   compatible = "sprd,sc9860-ap-clk";
+   reg = <0 0x2000 0 0x400>;
+   clocks = <&ext_26m>, <&pll 0>,
+<&pmu_gate 0>;
+   #clock-cells = <1>;
+   };
+
+   aon_prediv: aon-prediv {
+   compatible = "sprd,sc9860-aon-prediv";
+   reg = <0 0x402d 0 0x400>;
+   clocks = <&ext_26m>, <&pll 0>,
+<&pmu_gate 0>;
+   #clock-cells = <1>;
+   };
+
+   apahb_gate: apahb-gate {
+   compatible = "sprd,sc9860-apahb-gate";
+   sprd,syscon = <&ap_ahb_regs>; /* 0x2021 */
+   clocks = <&aon_prediv 0>;
+   #clock-cells = <1>;
+   };
+
+   aon_gate: aon-gate {
+   compatible = "sprd,sc9860-aon-gate";
+   sprd,syscon = <&aon_regs>; /* 0x402e */
+   clocks = <&aon_prediv 0>;
+   #clock-cells = <1>;
+   };
+
+   aonsecure_clk: clock-controller@4088 {
+   compatible = "sprd,sc9860-aonsecure-clk";
+   reg = <0 0x4088 0 0x400>;
+   clocks = <&ext_26m>, <&pll 0>;
+   #clock-cells = <1>;
+   };
+
+   agcp_gate: agcp-gate {
+   compatible = "sprd,sc9860-agcp-gate";
+   sprd,syscon = <&agcp_regs>; /* 0x415e */
+   clocks = <&aon_prediv 0>;
+   #clock-cells = <1>;
+   };
+
+   gpu_clk: clock-controller@6020 {
+   compatible = "sprd,sc9860-gpu-clk";
+   reg = <0 0x6020 0 0x400>;
+   clocks = <&pll 0>;
+   #clock-cells = <1>;
+   };
+
+   vsp_clk: clock-controller@6100 {
+   compatible = "sprd,sc9860-vsp-clk";
+   reg = <0 0x6100 0 0x400>;
+   clocks = <&ext_26m>, <&pll 0>;
+   #clock-cells = <1>;
+   };
+
+   vsp_gate: vsp-gate {
+   compatible = "sprd,sc9860-vsp-gate";
+   sprd,syscon = <&vsp_regs>; /* 0x6110 */
+   clocks = <&vsp_clk 0>;
+   #clock-cells = <1>;
+   };
+
+   cam_clk: clock-controller@6200 {
+   compatible = "sprd,sc9860-cam-clk";
+   reg = <0 0x6200 0 0x4000>;
+   clocks = <&ext_26m>, <&pll 0>;
+   #clock-cells = <1>;
+   };
+
+   cam_gate: cam-gate {
+   compatible = "sprd,sc9860-cam-gate";
+   sprd,syscon = <&cam_regs>; /* 0x6210 */
+   clocks = <&cam_clk 0>;
+   #clock-cells = <1>;
+   };
+
+   disp_clk: clock-controller@6300 {
+   compatible = "sprd,sc9860-disp-clk";
+   reg = <0 0x6300 0 0x400>;
+   clocks = <&ext_26m>, <&pll 0>;
+   #clock-cells = <1>;
+   };
+
+   disp_gate: disp-gate {
+   compatible = "sprd,sc9860-disp-gate";
+   sprd,syscon = <&disp_regs>; /* 0x6310 */
+   

[PATCH V7 08/12] dt-bindings: Add Spreadtrum clock binding documentation

2017-12-07 Thread Chunyan Zhang
Introduce a new binding with its documentation for Spreadtrum clock
sub-framework.

Signed-off-by: Chunyan Zhang 
Acked-by: Rob Herring 
---
 Documentation/devicetree/bindings/clock/sprd.txt | 63 
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/sprd.txt

diff --git a/Documentation/devicetree/bindings/clock/sprd.txt 
b/Documentation/devicetree/bindings/clock/sprd.txt
new file mode 100644
index 000..e9d179e
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/sprd.txt
@@ -0,0 +1,63 @@
+Spreadtrum Clock Binding
+
+
+Required properties:
+- compatible: should contain the following compatible strings:
+   - "sprd,sc9860-pmu-gate"
+   - "sprd,sc9860-pll"
+   - "sprd,sc9860-ap-clk"
+   - "sprd,sc9860-aon-prediv"
+   - "sprd,sc9860-apahb-gate"
+   - "sprd,sc9860-aon-gate"
+   - "sprd,sc9860-aonsecure-clk"
+   - "sprd,sc9860-agcp-gate"
+   - "sprd,sc9860-gpu-clk"
+   - "sprd,sc9860-vsp-clk"
+   - "sprd,sc9860-vsp-gate"
+   - "sprd,sc9860-cam-clk"
+   - "sprd,sc9860-cam-gate"
+   - "sprd,sc9860-disp-clk"
+   - "sprd,sc9860-disp-gate"
+   - "sprd,sc9860-apapb-gate"
+
+- #clock-cells: must be 1
+
+- clocks : Should be the input parent clock(s) phandle for the clock, this
+  property here just simply shows which clock group the clocks'
+  parents are in, since each clk node would represent many clocks
+  which are defined in the driver.  The detailed dependency
+  relationship (i.e. how many parents and which are the parents)
+  are implemented in driver code.
+
+Optional properties:
+
+- reg: Contain the registers base address and length. It must be configured
+   only if no 'sprd,syscon' under the node.
+
+- sprd,syscon: phandle to the syscon which is in the same address area with
+  the clock, and so we can get regmap for the clocks from the
+  syscon device.
+
+Example:
+
+   pmu_gate: pmu-gate {
+   compatible = "sprd,sc9860-pmu-gate";
+   sprd,syscon = <&pmu_regs>;
+   clocks = <&ext_26m>;
+   #clock-cells = <1>;
+   };
+
+   pll: pll {
+   compatible = "sprd,sc9860-pll";
+   sprd,syscon = <&ana_regs>;
+   clocks = <&pmu_gate 0>;
+   #clock-cells = <1>;
+   };
+
+   ap_clk: clock-controller@2000 {
+   compatible = "sprd,sc9860-ap-clk";
+   reg = <0 0x2000 0 0x400>;
+   clocks = <&ext_26m>, <&pll 0>,
+<&pmu_gate 0>;
+   #clock-cells = <1>;
+   };
-- 
2.7.4



[PATCH V7 11/12] arm64: dts: add syscon for whale2 platform

2017-12-07 Thread Chunyan Zhang
Some clocks on SC9860 are in the same address area with syscon
devices, the proper syscon node will be quoted under the
definitions of those clocks in DT.

Signed-off-by: Chunyan Zhang 
---
 arch/arm64/boot/dts/sprd/whale2.dtsi | 46 +++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/sprd/whale2.dtsi 
b/arch/arm64/boot/dts/sprd/whale2.dtsi
index 7c217c5..6ea3a75 100644
--- a/arch/arm64/boot/dts/sprd/whale2.dtsi
+++ b/arch/arm64/boot/dts/sprd/whale2.dtsi
@@ -17,6 +17,51 @@
#size-cells = <2>;
ranges;
 
+   ap_ahb_regs: syscon@2021 {
+   compatible = "syscon";
+   reg = <0 0x2021 0 0x1>;
+   };
+
+   pmu_regs: syscon@402b {
+   compatible = "syscon";
+   reg = <0 0x402b 0 0x1>;
+   };
+
+   aon_regs: syscon@402e {
+   compatible = "syscon";
+   reg = <0 0x402e 0 0x1>;
+   };
+
+   ana_regs: syscon@4040 {
+   compatible = "syscon";
+   reg = <0 0x4040 0 0x1>;
+   };
+
+   agcp_regs: syscon@415e {
+   compatible = "syscon";
+   reg = <0 0x415e 0 0x100>;
+   };
+
+   vsp_regs: syscon@6110 {
+   compatible = "syscon";
+   reg = <0 0x6110 0 0x1>;
+   };
+
+   cam_regs: syscon@6210 {
+   compatible = "syscon";
+   reg = <0 0x6210 0 0x1>;
+   };
+
+   disp_regs: syscon@6310 {
+   compatible = "syscon";
+   reg = <0 0x6310 0 0x1>;
+   };
+
+   ap_apb_regs: syscon@70b0 {
+   compatible = "syscon";
+   reg = <0 0x70b0 0 0x4>;
+   };
+
ap-apb {
compatible = "simple-bus";
#address-cells = <1>;
@@ -59,7 +104,6 @@
status = "disabled";
};
};
-
};
 
ext_26m: ext-26m {
-- 
2.7.4



Re: [PATCH 4.9 038/109] dmaengine: stm32-dma: Fix null pointer dereference in stm32_dma_tx_status

2017-12-07 Thread Ludovic BARRE

add Pierre-yves Mordret

acked-by: Ludovic BARRE 

On 12/07/2017 01:56 PM, Greg Kroah-Hartman wrote:

4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: M'boumba Cedric Madianga 


[ Upstream commit 57b5a32135c813f2ab669039fb4ec16b30cb3305 ]

chan->desc is always set to NULL when a DMA transfer is complete.
As a DMA transfer could be complete during the call of stm32_dma_tx_status,
we need to be sure that chan->desc is not NULL before using this variable
to avoid a null pointer deference issue.

Signed-off-by: M'boumba Cedric Madianga 
Reviewed-by: Ludovic BARRE 
Signed-off-by: Vinod Koul 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
  drivers/dma/stm32-dma.c |   10 +++---
  1 file changed, 3 insertions(+), 7 deletions(-)

--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -884,7 +884,7 @@ static enum dma_status stm32_dma_tx_stat
struct virt_dma_desc *vdesc;
enum dma_status status;
unsigned long flags;
-   u32 residue;
+   u32 residue = 0;
  
  	status = dma_cookie_status(c, cookie, state);

if ((status == DMA_COMPLETE) || (!state))
@@ -892,16 +892,12 @@ static enum dma_status stm32_dma_tx_stat
  
  	spin_lock_irqsave(&chan->vchan.lock, flags);

vdesc = vchan_find_desc(&chan->vchan, cookie);
-   if (cookie == chan->desc->vdesc.tx.cookie) {
+   if (chan->desc && cookie == chan->desc->vdesc.tx.cookie)
residue = stm32_dma_desc_residue(chan, chan->desc,
 chan->next_sg);
-   } else if (vdesc) {
+   else if (vdesc)
residue = stm32_dma_desc_residue(chan,
 to_stm32_dma_desc(vdesc), 0);
-   } else {
-   residue = 0;
-   }
-
dma_set_residue(state, residue);
  
  	spin_unlock_irqrestore(&chan->vchan.lock, flags);





[PATCH V7 05/12] clk: sprd: add divider clock support

2017-12-07 Thread Chunyan Zhang
This is a feature that can also be found in sprd composite clocks,
provide a bunch of helpers that can be reused later on.

Signed-off-by: Chunyan Zhang 
---
 drivers/clk/sprd/Makefile |  1 +
 drivers/clk/sprd/div.c| 90 +++
 drivers/clk/sprd/div.h| 75 +++
 3 files changed, 166 insertions(+)
 create mode 100644 drivers/clk/sprd/div.c
 create mode 100644 drivers/clk/sprd/div.h

diff --git a/drivers/clk/sprd/Makefile b/drivers/clk/sprd/Makefile
index cee36b5..80e6039 100644
--- a/drivers/clk/sprd/Makefile
+++ b/drivers/clk/sprd/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_SPRD_COMMON_CLK)   += clk-sprd.o
 clk-sprd-y += common.o
 clk-sprd-y += gate.o
 clk-sprd-y += mux.o
+clk-sprd-y += div.o
diff --git a/drivers/clk/sprd/div.c b/drivers/clk/sprd/div.c
new file mode 100644
index 000..887a863
--- /dev/null
+++ b/drivers/clk/sprd/div.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum divider clock driver
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#include 
+
+#include "div.h"
+
+long sprd_div_helper_round_rate(struct sprd_clk_common *common,
+   const struct sprd_div_internal *div,
+   unsigned long rate,
+   unsigned long *parent_rate)
+{
+   return divider_round_rate(&common->hw, rate, parent_rate,
+ NULL, div->width, 0);
+}
+EXPORT_SYMBOL_GPL(sprd_div_helper_round_rate);
+
+static long sprd_div_round_rate(struct clk_hw *hw, unsigned long rate,
+   unsigned long *parent_rate)
+{
+   struct sprd_div *cd = hw_to_sprd_div(hw);
+
+   return sprd_div_helper_round_rate(&cd->common, &cd->div,
+ rate, parent_rate);
+}
+
+unsigned long sprd_div_helper_recalc_rate(struct sprd_clk_common *common,
+ const struct sprd_div_internal *div,
+ unsigned long parent_rate)
+{
+   unsigned long val;
+   unsigned int reg;
+
+   regmap_read(common->regmap, common->reg, ®);
+   val = reg >> div->shift;
+   val &= (1 << div->width) - 1;
+
+   return divider_recalc_rate(&common->hw, parent_rate, val, NULL, 0);
+}
+EXPORT_SYMBOL_GPL(sprd_div_helper_recalc_rate);
+
+static unsigned long sprd_div_recalc_rate(struct clk_hw *hw,
+ unsigned long parent_rate)
+{
+   struct sprd_div *cd = hw_to_sprd_div(hw);
+
+   return sprd_div_helper_recalc_rate(&cd->common, &cd->div, parent_rate);
+}
+
+int sprd_div_helper_set_rate(const struct sprd_clk_common *common,
+const struct sprd_div_internal *div,
+unsigned long rate,
+unsigned long parent_rate)
+{
+   unsigned long val;
+   unsigned int reg;
+
+   val = divider_get_val(rate, parent_rate, NULL,
+ div->width, 0);
+
+   regmap_read(common->regmap, common->reg, ®);
+   reg &= ~GENMASK(div->width + div->shift - 1, div->shift);
+
+   regmap_write(common->regmap, common->reg,
+ reg | (val << div->shift));
+
+   return 0;
+
+}
+EXPORT_SYMBOL_GPL(sprd_div_helper_set_rate);
+
+static int sprd_div_set_rate(struct clk_hw *hw, unsigned long rate,
+unsigned long parent_rate)
+{
+   struct sprd_div *cd = hw_to_sprd_div(hw);
+
+   return sprd_div_helper_set_rate(&cd->common, &cd->div,
+   rate, parent_rate);
+}
+
+const struct clk_ops sprd_div_ops = {
+   .recalc_rate = sprd_div_recalc_rate,
+   .round_rate = sprd_div_round_rate,
+   .set_rate = sprd_div_set_rate,
+};
+EXPORT_SYMBOL_GPL(sprd_div_ops);
diff --git a/drivers/clk/sprd/div.h b/drivers/clk/sprd/div.h
new file mode 100644
index 000..b3033d2
--- /dev/null
+++ b/drivers/clk/sprd/div.h
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum divider clock driver
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#ifndef _SPRD_DIV_H_
+#define _SPRD_DIV_H_
+
+#include "common.h"
+
+/**
+ * struct sprd_div_internal - Internal divider description
+ * @shift: Bit offset of the divider in its register
+ * @width: Width of the divider field in its register
+ *
+ * That structure represents a single divider, and is meant to be
+ * embedded in other structures representing the various clock
+ * classes.
+ */
+struct sprd_div_internal {
+   u8  shift;
+   u8  width;
+};
+
+#define _SPRD_DIV_CLK(_shift, _width)  \
+   {   \
+   .shift  = _shift,   \
+   .width  = _width,   \
+   }
+
+struct sprd_div {
+   struct sprd_div_internaldiv;
+   struct sprd_clk_common  common;
+};
+
+#define SPRD_D

Re: [PATCH 4.9 037/109] dmaengine: stm32-dma: Set correct args number for DMA request from DT

2017-12-07 Thread Ludovic BARRE

add Pierre-yves Mordret

acked-by: Ludovic BARRE 

On 12/07/2017 01:56 PM, Greg Kroah-Hartman wrote:

4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: M'boumba Cedric Madianga 


[ Upstream commit 7e96304d99477de1f70db42035071e56439da817 ]

This patch sets the right number of arguments to be used for DMA clients
which request channels from DT.

Signed-off-by: M'boumba Cedric Madianga 
Reviewed-by: Ludovic BARRE 
Signed-off-by: Vinod Koul 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
  drivers/dma/stm32-dma.c |7 ++-
  1 file changed, 2 insertions(+), 5 deletions(-)

--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -976,21 +976,18 @@ static struct dma_chan *stm32_dma_of_xla
struct stm32_dma_chan *chan;
struct dma_chan *c;
  
-	if (dma_spec->args_count < 3)

+   if (dma_spec->args_count < 4)
return NULL;
  
  	cfg.channel_id = dma_spec->args[0];

cfg.request_line = dma_spec->args[1];
cfg.stream_config = dma_spec->args[2];
-   cfg.threshold = 0;
+   cfg.threshold = dma_spec->args[3];
  
  	if ((cfg.channel_id >= STM32_DMA_MAX_CHANNELS) || (cfg.request_line >=

STM32_DMA_MAX_REQUEST_ID))
return NULL;
  
-	if (dma_spec->args_count > 3)

-   cfg.threshold = dma_spec->args[3];
-
chan = &dmadev->chan[cfg.channel_id];
  
  	c = dma_get_slave_channel(&chan->vchan.chan);





[PATCH V7 00/12] add clock driver for Spreadtrum platforms

2017-12-07 Thread Chunyan Zhang
From: Chunyan Zhang 

This series adds Spreadtrum clock support together with its binding
documentation and devicetree data.

Any comments would be greatly appreciated.

Thanks,
Chunyan

Changes from V6: (https://lkml.org/lkml/2017/11/27/217)
* Changed to use "//" format for the file header
* Addressed Stephen's comments:
  - Put the common macros in clk-provider.h instead of clk_common.h, also 
removed
the same macros from sunxi-ng/ccu_common.h and zte/clk.h;
  - Removed CLK_FIXED_RATE(), and moved the fixed rate clocks from driver to DT;
  - Use devm_of_clk_add_hw_provider() instead;
  - Removed sprd_regmap_{read|write}(), use regmap API directly;
  - Removed all full stop on error messages.
* Use IS_ERR_OR_NULL() instead of IS_ERR() for checking regmap pointers;

Changes from V5: (https://lkml.org/lkml/2017/11/20/21)
* Rebased the whole patch-set to 4.15-rc1;
* Fixed kbuild-test warnings;
* Switched to use devm_clk_hw_register() instead of clk_hw_register();
* Removed useless debug information from sc9860-clk.c.

Changes from V4: (https://lkml.org/lkml/2017/11/10/30)
* Added acked-by of Rob Herring;
* Removed spin lock from Spreadtrum's gate, mux, div drivers, since we have
  switched to use regmap.

Changes from V3: (https://lkml.org/lkml/2017/11/2/61)
* Addressed comments from Julien Thierry:
  - Clean the if branch of sprd_mux_helper_get_parent()
  - Have the Gate clock macros and ops for both mode (i.e. sc_gate and gate) 
separate;
  - Have the Mux clock macros with/without table separate, and same changes
for the composite clock.
* Switched the function name from _endisable to _toggle;
* Fixed Kbuild test error:
  - Added exporting sprd_clk_regmap_init() which would be used in other 
module(s);
* Change the function sprd_clk_set_regmap() to the static one, and removed the
  declear from the include file;
* Addressed comments from Rob:
  - Separate the dt-binding include file from the driver patch;
  - Documented more for the property "clocks"
* Changed the syscon device names;
* Changed the name of 'sprd_mux_internal' to 'sprd_mux_ssel'
  

Changes from V2: (http://lkml.iu.edu/hypermail/linux/kernel/1707.1/01504.html)
* Switch to use regmap to access registers;
* Splited all clocks into 16 separated nodes, for each belongs to a single 
address area; 
* Rearranged the order of clock declaration in sc9860-clk.c, sorted them upon 
the address area;
* Added syscon device tree nodes which will be quoted by the node of clocks 
which are in
  the same address area with the syscon device;
* Revised the binding documentation according to the dt modification. 

Changes from V1: (https://lkml.org/lkml/2017/6/17/356)
* Address Stephen's comments:
  - Switch to use platform device driver instead of the DT probing mechanism.
  - Move the common clock macro out from vendor directory, but need to remove 
those
overlap code from other vendors (such as sunxi-ng) once this get merged.
  - Add support to be built as a module.
  - Add 'sprd_' prefix for all spin locks used in these drivers.
  - Mark input parameter of sprd_x with const.
  - Remove unreasonable dependencies to CONFIG_64BIT.
  - Add readl() after writing the same register.
  - Remove CLK_IS_BASIC which is no longer used.
  - Remove unnecessery CLK_IGNORE_UNUSED when defining a clock.
  - Change to expose all clock index.
  - Use clk_ instead of ccu.
  - Add Kconfig for sprd clocks.
  - Move the fixed clocks out from the soc node.
  - Switch to use 64-bit math in pll driver instead of 32-bit math.
* Revise binding documentation according to dt modification.
* Rename sc9860.c to sc9860-clk.c


Chunyan Zhang (12):
  drivers: move clock common macros out from vendor directories
  clk: sprd: Add common infrastructure
  clk: sprd: add gate clock support
  clk: sprd: add mux clock support
  clk: sprd: add divider clock support
  clk: sprd: add composite clock support
  clk: sprd: add adjustable pll support
  dt-bindings: Add Spreadtrum clock binding documentation
  clk: sprd: Add dt-bindings include file for SC9860
  clk: sprd: add clocks support for SC9860
  arm64: dts: add syscon for whale2 platform
  arm64: dts: add clocks for SC9860

 Documentation/devicetree/bindings/clock/sprd.txt |   63 +
 arch/arm64/boot/dts/sprd/sc9860.dtsi |  115 ++
 arch/arm64/boot/dts/sprd/whale2.dtsi |   62 +-
 drivers/clk/Kconfig  |1 +
 drivers/clk/Makefile |1 +
 drivers/clk/sprd/Kconfig |   14 +
 drivers/clk/sprd/Makefile|   11 +
 drivers/clk/sprd/common.c|   96 ++
 drivers/clk/sprd/common.h|   38 +
 drivers/clk/sprd/composite.c |   60 +
 drivers/clk/sprd/composite.h |   51 +
 drivers/clk/sprd/div.c   |   90 +
 drivers/clk/sprd/div.h   |   75 +
 drivers/clk/sprd/gate.c  |  111 

[PATCH V7 03/12] clk: sprd: add gate clock support

2017-12-07 Thread Chunyan Zhang
Some clocks on the Spreadtrum's SoCs are just simple gates. Add
support for those clocks.

Signed-off-by: Chunyan Zhang 
---
 drivers/clk/sprd/Makefile |   1 +
 drivers/clk/sprd/gate.c   | 111 ++
 drivers/clk/sprd/gate.h   |  59 
 3 files changed, 171 insertions(+)
 create mode 100644 drivers/clk/sprd/gate.c
 create mode 100644 drivers/clk/sprd/gate.h

diff --git a/drivers/clk/sprd/Makefile b/drivers/clk/sprd/Makefile
index 74f4b80..8cd5592 100644
--- a/drivers/clk/sprd/Makefile
+++ b/drivers/clk/sprd/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_SPRD_COMMON_CLK)  += clk-sprd.o
 
 clk-sprd-y += common.o
+clk-sprd-y += gate.o
diff --git a/drivers/clk/sprd/gate.c b/drivers/clk/sprd/gate.c
new file mode 100644
index 000..f59d193
--- /dev/null
+++ b/drivers/clk/sprd/gate.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum gate clock driver
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#include 
+#include 
+
+#include "gate.h"
+
+static void clk_gate_toggle(const struct sprd_gate *sg, bool en)
+{
+   const struct sprd_clk_common *common = &sg->common;
+   unsigned int reg;
+   bool set = sg->flags & CLK_GATE_SET_TO_DISABLE ? true : false;
+
+   set ^= en;
+
+   regmap_read(common->regmap, common->reg, ®);
+
+   if (set)
+   reg |= sg->enable_mask;
+   else
+   reg &= ~sg->enable_mask;
+
+   regmap_write(common->regmap, common->reg, reg);
+}
+
+static void clk_sc_gate_toggle(const struct sprd_gate *sg, bool en)
+{
+   const struct sprd_clk_common *common = &sg->common;
+   bool set = sg->flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0;
+   unsigned int offset;
+
+   set ^= en;
+
+   /*
+* Each set/clear gate clock has three registers:
+* common->reg  - base register
+* common->reg + offset - set register
+* common->reg + 2 * offset - clear register
+*/
+   offset = set ? sg->sc_offset : sg->sc_offset * 2;
+
+   regmap_write(common->regmap, common->reg + offset,
+ sg->enable_mask);
+}
+
+static void sprd_gate_disable(struct clk_hw *hw)
+{
+   struct sprd_gate *sg = hw_to_sprd_gate(hw);
+
+   clk_gate_toggle(sg, false);
+}
+
+static int sprd_gate_enable(struct clk_hw *hw)
+{
+   struct sprd_gate *sg = hw_to_sprd_gate(hw);
+
+   clk_gate_toggle(sg, true);
+
+   return 0;
+}
+
+static void sprd_sc_gate_disable(struct clk_hw *hw)
+{
+   struct sprd_gate *sg = hw_to_sprd_gate(hw);
+
+   clk_sc_gate_toggle(sg, false);
+}
+
+static int sprd_sc_gate_enable(struct clk_hw *hw)
+{
+   struct sprd_gate *sg = hw_to_sprd_gate(hw);
+
+   clk_sc_gate_toggle(sg, true);
+
+   return 0;
+}
+static int sprd_gate_is_enabled(struct clk_hw *hw)
+{
+   struct sprd_gate *sg = hw_to_sprd_gate(hw);
+   struct sprd_clk_common *common = &sg->common;
+   unsigned int reg;
+
+   regmap_read(common->regmap, common->reg, ®);
+
+   if (sg->flags & CLK_GATE_SET_TO_DISABLE)
+   reg ^= sg->enable_mask;
+
+   reg &= sg->enable_mask;
+
+   return reg ? 1 : 0;
+}
+
+const struct clk_ops sprd_gate_ops = {
+   .disable= sprd_gate_disable,
+   .enable = sprd_gate_enable,
+   .is_enabled = sprd_gate_is_enabled,
+};
+EXPORT_SYMBOL_GPL(sprd_gate_ops);
+
+const struct clk_ops sprd_sc_gate_ops = {
+   .disable= sprd_sc_gate_disable,
+   .enable = sprd_sc_gate_enable,
+   .is_enabled = sprd_gate_is_enabled,
+};
+EXPORT_SYMBOL_GPL(sprd_sc_gate_ops);
+
diff --git a/drivers/clk/sprd/gate.h b/drivers/clk/sprd/gate.h
new file mode 100644
index 000..2e582c6
--- /dev/null
+++ b/drivers/clk/sprd/gate.h
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Spreadtrum gate clock driver
+//
+// Copyright (C) 2017 Spreadtrum, Inc.
+// Author: Chunyan Zhang 
+
+#ifndef _SPRD_GATE_H_
+#define _SPRD_GATE_H_
+
+#include "common.h"
+
+struct sprd_gate {
+   u32 enable_mask;
+   u16 flags;
+   u16 sc_offset;
+
+   struct sprd_clk_common  common;
+};
+
+#define SPRD_SC_GATE_CLK_OPS(_struct, _name, _parent, _reg, _sc_offset,
\
+_enable_mask, _flags, _gate_flags, _ops)   \
+   struct sprd_gate _struct = {\
+   .enable_mask= _enable_mask, \
+   .sc_offset  = _sc_offset,   \
+   .flags  = _gate_flags,  \
+   .common = { \
+   .regmap = NULL, \
+   .reg= _reg, \
+   .hw.init= CLK_HW_IN

[PATCH 4.4 00/49] 4.4.105-stable review

2017-12-07 Thread Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.4.105 release.
There are 49 patches in this series, all will be posted as a response
to this one.  If anyone has any issues with these being applied, please
let me know.

Responses should be made by Sat Dec  9 12:46:41 UTC 2017.
Anything received after that time might be too late.

The whole patch series can be found in one patch at:
kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.4.105-rc1.gz
or in the git tree and branch at:
  git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git 
linux-4.4.y
and the diffstat can be found below.

thanks,

greg k-h

-
Pseudo-Shortlog of commits:

Greg Kroah-Hartman 
Linux 4.4.105-rc1

Colin Ian King 
usb: host: fix incorrect updating of offset

Oliver Neukum 
USB: usbfs: Filter flags passed in from user space

Dan Carpenter 
USB: devio: Prevent integer overflow in proc_do_submiturb()

Mateusz Berezecki 
USB: Increase usbfs transfer limit

Masakazu Mokuno 
USB: core: Add type-specific length check of BOS descriptors

John Youn 
usb: ch9: Add size macro for SSP dev cap descriptor

Mathias Nyman 
usb: Add USB 3.1 Precision time measurement capability descriptor support

Yu Chen 
usb: xhci: fix panic in xhci_free_virt_devices_depth_first

Mike Looijmans 
usb: hub: Cycle HUB power when initialization fails

Greg Kroah-Hartman 
Revert "ocfs2: should wait dio before inode lock in ocfs2_setattr()"

Rui Sousa 
net: fec: fix multicast filtering hardware setup

Ross Lagerwall 
xen-netfront: Improve error handling during initialization

Jan Kara 
mm: avoid returning VM_FAULT_RETRY from ->page_mkwrite handlers

Jason Baron 
tcp: correct memory barrier usage in tcp_check_space()

Iago Abal 
dmaengine: pl330: fix double lock

Parthasarathy Bhuvaragan 
tipc: fix cleanup at module unload

Colin Ian King 
net: sctp: fix array overrun read on sctp_timer_tbl

Andrzej Hajda 
drm/exynos/decon5433: set STANDALONE_UPDATE_F on output enablement

Trond Myklebust 
NFSv4: Fix client recovery when server reboots multiple times

Christoffer Dall 
KVM: arm/arm64: Fix occasional warning from the timer work function

Benjamin Coddington 
nfs: Don't take a reference on fl->fl_file for LOCK operation

Kazuya Mizuguchi 
ravb: Remove Rx overflow log messages

Vlad Tsyrklevich 
net/appletalk: Fix kernel memory disclosure

David Forster 
vti6: fix device register to report IFLA_INFO_KIND

Peter Ujfalusi 
ARM: OMAP1: DMA: Correct the number of logical channels

Florian Fainelli 
net: systemport: Pad packet before inserting TSB

Florian Fainelli 
net: systemport: Utilize skb_put_padto()

Masami Hiramatsu 
kprobes/x86: Disable preemption in ftrace-based jprobes

Thomas Richter 
perf test attr: Fix ignored test case result

Ben Hutchings 
usbip: tools: Install all headers needed for libusbip development

Jibin Xu 
sysrq : fix Show Regs call trace on ARM

Gustavo A. R. Silva 
EDAC, sb_edac: Fix missing break in switch

Dave Hansen 
x86/entry: Use SYSCALL_DEFINE() macros for sys_modify_ldt()

Aaron Sierra 
serial: 8250: Preserve DLD[7:4] for PORT_XR17V35X

Alexey Khoroshilov 
usb: phy: tahvo: fix error handling in tahvo_usb_probe()

John Stultz 
usb: dwc2: Error out of dwc2_hsotg_ep_disable() if we're in host mode

John Stultz 
usb: dwc2: Fix UDC state tracking

Hiromitsu Yamasaki 
spi: sh-msiof: Fix DMA transfer size check

Lukas Wunner 
serial: 8250_fintek: Fix rs485 disablement on invalid ioctl()

Andy Lutomirski 
selftests/x86/ldt_get: Add a few additional tests for limits

Christian Borntraeger 
s390/pci: do not require AIS facility

Boshi Wang 
ima: fix hash algorithm initialization

Sebastian Sjoholm 
USB: serial: option: add Quectel BG96 id

Heiko Carstens 
s390/runtime instrumentation: simplify task exit handling

Matt Wilson 
serial: 8250_pci: Add Amazon PCI serial device ID

Kai-Heng Feng 
usb: quirks: Add no-lpm quirk for KY-688 USB 3.1 Type-C Hub

Hans de Goede 
uas: Always apply US_FL_NO_ATA_1X quirk to Seagate devices

Rui Hua 
bcache: recover data from backing when data is clean

Coly Li 
bcache: only permit to recovery read error when cache device is clean


-

Diffstat:

 Makefile |  4 +-
 arch/arm/mach-omap1/dma.c| 16 +++
 arch/s390/include/asm/pci_insn.h |  2 +-
 arch/s390/include/asm/runtime_instr.h|  4 +-
 arch/s390/kernel/process.c   |  2 +-
 arch/s390/kernel/runtime_instr.c | 30 ++---
 arch/s390/pci/pci.c  |  5 ++-
 arch/s390/pci/pci_insn.c |  6 ++-
 arch/x86/include/asm/syscalls.h  |  2 +-
 arch/x86/kernel/kprobes/ftrace.c | 23 ++
 arch/x86/kernel/ldt.c

[PATCH 4.9 103/109] usb: hub: Cycle HUB power when initialization fails

2017-12-07 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Mike Looijmans 

commit 973593a960ddac0f14f0d8877d2d0abe0afda795 upstream.

Sometimes the USB device gets confused about the state of the initialization and
the connection fails. In particular, the device thinks that it's already set up
and running while the host thinks the device still needs to be configured. To
work around this issue, power-cycle the hub's output to issue a sort of "reset"
to the device. This makes the device restart its state machine and then the
initialization succeeds.

This fixes problems where the kernel reports a list of errors like this:

usb 1-1.3: device not accepting address 19, error -71

The end result is a non-functioning device. After this patch, the sequence
becomes like this:

usb 1-1.3: new high-speed USB device number 18 using ci_hdrc
usb 1-1.3: device not accepting address 18, error -71
usb 1-1.3: new high-speed USB device number 19 using ci_hdrc
usb 1-1.3: device not accepting address 19, error -71
usb 1-1-port3: attempt power cycle
usb 1-1.3: new high-speed USB device number 21 using ci_hdrc
usb-storage 1-1.3:1.2: USB Mass Storage device detected

Signed-off-by: Mike Looijmans 
Acked-by: Alan Stern 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/hub.c |9 +
 1 file changed, 9 insertions(+)

--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -4925,6 +4925,15 @@ loop:
usb_put_dev(udev);
if ((status == -ENOTCONN) || (status == -ENOTSUPP))
break;
+
+   /* When halfway through our retry count, power-cycle the port */
+   if (i == (SET_CONFIG_TRIES / 2) - 1) {
+   dev_info(&port_dev->dev, "attempt power cycle\n");
+   usb_hub_set_port_power(hdev, hub, port1, false);
+   msleep(2 * hub_power_on_good_delay(hub));
+   usb_hub_set_port_power(hdev, hub, port1, true);
+   msleep(hub_power_on_good_delay(hub));
+   }
}
if (hub->hdev->parent ||
!hcd->driver->port_handed_over ||




[PATCH 4.4 02/49] bcache: recover data from backing when data is clean

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Rui Hua 

commit e393aa2446150536929140739f09c6ecbcbea7f0 upstream.

When we send a read request and hit the clean data in cache device, there
is a situation called cache read race in bcache(see the commit in the tail
of cache_look_up(), the following explaination just copy from there):
The bucket we're reading from might be reused while our bio is in flight,
and we could then end up reading the wrong data. We guard against this
by checking (in bch_cache_read_endio()) if the pointer is stale again;
if so, we treat it as an error (s->iop.error = -EINTR) and reread from
the backing device (but we don't pass that error up anywhere)

It should be noted that cache read race happened under normal
circumstances, not the circumstance when SSD failed, it was counted
and shown in  /sys/fs/bcache/XXX/internal/cache_read_races.

Without this patch, when we use writeback mode, we will never reread from
the backing device when cache read race happened, until the whole cache
device is clean, because the condition
(s->recoverable && (dc && !atomic_read(&dc->has_dirty))) is false in
cached_dev_read_error(). In this situation, the s->iop.error(= -EINTR)
will be passed up, at last, user will receive -EINTR when it's bio end,
this is not suitable, and wield to up-application.

In this patch, we use s->read_dirty_data to judge whether the read
request hit dirty data in cache device, it is safe to reread data from
the backing device when the read request hit clean data. This can not
only handle cache read race, but also recover data when failed read
request from cache device.

[edited by mlyle to fix up whitespace, commit log title, comment
spelling]

Fixes: d59b23795933 ("bcache: only permit to recovery read error when cache 
device is clean")
Signed-off-by: Hua Rui 
Reviewed-by: Michael Lyle 
Reviewed-by: Coly Li 
Signed-off-by: Michael Lyle 
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/md/bcache/request.c |   13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -707,16 +707,15 @@ static void cached_dev_read_error(struct
 {
struct search *s = container_of(cl, struct search, cl);
struct bio *bio = &s->bio.bio;
-   struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
 
/*
-* If cache device is dirty (dc->has_dirty is non-zero), then
-* recovery a failed read request from cached device may get a
-* stale data back. So read failure recovery is only permitted
-* when cache device is clean.
+* If read request hit dirty data (s->read_dirty_data is true),
+* then recovery a failed read request from cached device may
+* get a stale data back. So read failure recovery is only
+* permitted when read request hit clean data in cache device,
+* or when cache read race happened.
 */
-   if (s->recoverable &&
-   (dc && !atomic_read(&dc->has_dirty))) {
+   if (s->recoverable && !s->read_dirty_data) {
/* Retry from the backing device: */
trace_bcache_read_retry(s->orig_bio);
 




[PATCH 4.4 10/49] selftests/x86/ldt_get: Add a few additional tests for limits

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Andy Lutomirski 


[ Upstream commit fec8f5ae1715a01c72ad52cb2ecd8aacaf142302 ]

We weren't testing the .limit and .limit_in_pages fields very well.
Add more tests.

This addition seems to trigger the "bits 16:19 are undefined" issue
that was fixed in an earlier patch.  I think that, at least on my
CPU, the high nibble of the limit ends in LAR bits 16:19.

Signed-off-by: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: 
http://lkml.kernel.org/r/5601c15ea9b3113d288953fd2838b18bedf6bc67.1509794321.git.l...@kernel.org
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 tools/testing/selftests/x86/ldt_gdt.c |   17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

--- a/tools/testing/selftests/x86/ldt_gdt.c
+++ b/tools/testing/selftests/x86/ldt_gdt.c
@@ -351,9 +351,24 @@ static void do_simple_tests(void)
install_invalid(&desc, false);
 
desc.seg_not_present = 0;
-   desc.read_exec_only = 0;
desc.seg_32bit = 1;
+   desc.read_exec_only = 0;
+   desc.limit = 0xf;
+
install_valid(&desc, AR_DPL3 | AR_TYPE_RWDATA | AR_S | AR_P | AR_DB);
+
+   desc.limit_in_pages = 1;
+
+   install_valid(&desc, AR_DPL3 | AR_TYPE_RWDATA | AR_S | AR_P | AR_DB | 
AR_G);
+   desc.read_exec_only = 1;
+   install_valid(&desc, AR_DPL3 | AR_TYPE_RODATA | AR_S | AR_P | AR_DB | 
AR_G);
+   desc.contents = 1;
+   desc.read_exec_only = 0;
+   install_valid(&desc, AR_DPL3 | AR_TYPE_RWDATA_EXPDOWN | AR_S | AR_P | 
AR_DB | AR_G);
+   desc.read_exec_only = 1;
+   install_valid(&desc, AR_DPL3 | AR_TYPE_RODATA_EXPDOWN | AR_S | AR_P | 
AR_DB | AR_G);
+
+   desc.limit = 0;
install_invalid(&desc, true);
 }
 




[PATCH 4.4 06/49] s390/runtime instrumentation: simplify task exit handling

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Heiko Carstens 

commit 8d9047f8b967ce6181fd824ae922978e1b055cc0 upstream.

Free data structures required for runtime instrumentation from
arch_release_task_struct(). This allows to simplify the code a bit,
and also makes the semantics a bit easier: arch_release_task_struct()
is never called from the task that is being removed.

In addition this allows to get rid of exit_thread() in a later patch.

Signed-off-by: Heiko Carstens 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 


---
 arch/s390/include/asm/runtime_instr.h |4 +++-
 arch/s390/kernel/process.c|2 +-
 arch/s390/kernel/runtime_instr.c  |   30 +++---
 3 files changed, 19 insertions(+), 17 deletions(-)

--- a/arch/s390/include/asm/runtime_instr.h
+++ b/arch/s390/include/asm/runtime_instr.h
@@ -85,6 +85,8 @@ static inline void restore_ri_cb(struct
load_runtime_instr_cb(&runtime_instr_empty_cb);
 }
 
-void exit_thread_runtime_instr(void);
+struct task_struct;
+
+void runtime_instr_release(struct task_struct *tsk);
 
 #endif /* _RUNTIME_INSTR_H */
--- a/arch/s390/kernel/process.c
+++ b/arch/s390/kernel/process.c
@@ -72,7 +72,6 @@ extern void kernel_thread_starter(void);
  */
 void exit_thread(void)
 {
-   exit_thread_runtime_instr();
 }
 
 void flush_thread(void)
@@ -87,6 +86,7 @@ void arch_release_task_struct(struct tas
 {
/* Free either the floating-point or the vector register save area */
kfree(tsk->thread.fpu.regs);
+   runtime_instr_release(tsk);
 }
 
 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
--- a/arch/s390/kernel/runtime_instr.c
+++ b/arch/s390/kernel/runtime_instr.c
@@ -18,11 +18,24 @@
 /* empty control block to disable RI by loading it */
 struct runtime_instr_cb runtime_instr_empty_cb;
 
+void runtime_instr_release(struct task_struct *tsk)
+{
+   kfree(tsk->thread.ri_cb);
+}
+
 static void disable_runtime_instr(void)
 {
-   struct pt_regs *regs = task_pt_regs(current);
+   struct task_struct *task = current;
+   struct pt_regs *regs;
 
+   if (!task->thread.ri_cb)
+   return;
+   regs = task_pt_regs(task);
+   preempt_disable();
load_runtime_instr_cb(&runtime_instr_empty_cb);
+   kfree(task->thread.ri_cb);
+   task->thread.ri_cb = NULL;
+   preempt_enable();
 
/*
 * Make sure the RI bit is deleted from the PSW. If the user did not
@@ -43,19 +56,6 @@ static void init_runtime_instr_cb(struct
cb->valid = 1;
 }
 
-void exit_thread_runtime_instr(void)
-{
-   struct task_struct *task = current;
-
-   preempt_disable();
-   if (!task->thread.ri_cb)
-   return;
-   disable_runtime_instr();
-   kfree(task->thread.ri_cb);
-   task->thread.ri_cb = NULL;
-   preempt_enable();
-}
-
 SYSCALL_DEFINE1(s390_runtime_instr, int, command)
 {
struct runtime_instr_cb *cb;
@@ -64,7 +64,7 @@ SYSCALL_DEFINE1(s390_runtime_instr, int,
return -EOPNOTSUPP;
 
if (command == S390_RUNTIME_INSTR_STOP) {
-   exit_thread_runtime_instr();
+   disable_runtime_instr();
return 0;
}
 




[PATCH 4.4 09/49] s390/pci: do not require AIS facility

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Christian Borntraeger 


[ Upstream commit 48070c73058be6de9c0d754d441ed7092dfc8f12 ]

As of today QEMU does not provide the AIS facility to its guest.  This
prevents Linux guests from using PCI devices as the ais facility is
checked during init. As this is just a performance optimization, we can
move the ais check into the code where we need it (calling the SIC
instruction). This is used at initialization and on interrupt. Both
places do not require any serialization, so we can simply skip the
instruction.

Since we will now get all interrupts, we can also avoid the 2nd scan.
As we can have multiple interrupts in parallel we might trigger spurious
irqs more often for the non-AIS case but the core code can handle that.

Signed-off-by: Christian Borntraeger 
Reviewed-by: Pierre Morel 
Reviewed-by: Halil Pasic 
Acked-by: Sebastian Ott 
Signed-off-by: Heiko Carstens 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 arch/s390/include/asm/pci_insn.h |2 +-
 arch/s390/pci/pci.c  |5 +++--
 arch/s390/pci/pci_insn.c |6 +-
 3 files changed, 9 insertions(+), 4 deletions(-)

--- a/arch/s390/include/asm/pci_insn.h
+++ b/arch/s390/include/asm/pci_insn.h
@@ -81,6 +81,6 @@ int zpci_refresh_trans(u64 fn, u64 addr,
 int zpci_load(u64 *data, u64 req, u64 offset);
 int zpci_store(u64 data, u64 req, u64 offset);
 int zpci_store_block(const u64 *data, u64 req, u64 offset);
-void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc);
+int zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc);
 
 #endif
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -359,7 +359,8 @@ static void zpci_irq_handler(struct airq
/* End of second scan with interrupts on. */
break;
/* First scan complete, reenable interrupts. */
-   zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, NULL, PCI_ISC);
+   if (zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE, NULL, 
PCI_ISC))
+   break;
si = 0;
continue;
}
@@ -921,7 +922,7 @@ static int __init pci_base_init(void)
if (!s390_pci_probe)
return 0;
 
-   if (!test_facility(69) || !test_facility(71) || !test_facility(72))
+   if (!test_facility(69) || !test_facility(71))
return 0;
 
rc = zpci_debug_init();
--- a/arch/s390/pci/pci_insn.c
+++ b/arch/s390/pci/pci_insn.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -91,11 +92,14 @@ int zpci_refresh_trans(u64 fn, u64 addr,
 }
 
 /* Set Interruption Controls */
-void zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
+int zpci_set_irq_ctrl(u16 ctl, char *unused, u8 isc)
 {
+   if (!test_facility(72))
+   return -EIO;
asm volatile (
"   .insn   rsy,0xebd1,%[ctl],%[isc],%[u]\n"
: : [ctl] "d" (ctl), [isc] "d" (isc << 27), [u] "Q" (*unused));
+   return 0;
 }
 
 /* PCI Load */




[PATCH 4.4 07/49] USB: serial: option: add Quectel BG96 id

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Sebastian Sjoholm 

commit c654b21ede93845863597de9ad774fd30db5f2ab upstream.

Quectel BG96 is an Qualcomm MDM9206 based IoT modem, supporting both
CAT-M and NB-IoT. Tested hardware is BG96 mounted on Quectel
development board (EVB). The USB id is added to option.c to allow
DIAG,GPS,AT and modem communication with the BG96.

Signed-off-by: Sebastian Sjoholm 
Signed-off-by: Johan Hovold 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/serial/option.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -241,6 +241,7 @@ static void option_instat_callback(struc
 /* These Quectel products use Quectel's vendor ID */
 #define QUECTEL_PRODUCT_EC21   0x0121
 #define QUECTEL_PRODUCT_EC25   0x0125
+#define QUECTEL_PRODUCT_BG96   0x0296
 
 #define CMOTECH_VENDOR_ID  0x16d8
 #define CMOTECH_PRODUCT_6001   0x6001
@@ -1185,6 +1186,8 @@ static const struct usb_device_id option
  .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
{ USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC25),
  .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
+   { USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_BG96),
+ .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
{ USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6001) },
{ USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_CMU_300) },
{ USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6003),




[PATCH 4.4 23/49] net: systemport: Utilize skb_put_padto()

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Fainelli 


[ Upstream commit bb7da333d0a9f3bddc08f84187b7579a3f68fd24 ]

Since we need to pad our packets, utilize skb_put_padto() which
increases skb->len by how much we need to pad, allowing us to eliminate
the test on skb->len right below.

Signed-off-by: Florian Fainelli 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/broadcom/bcmsysport.c |5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

--- a/drivers/net/ethernet/broadcom/bcmsysport.c
+++ b/drivers/net/ethernet/broadcom/bcmsysport.c
@@ -1061,13 +1061,12 @@ static netdev_tx_t bcm_sysport_xmit(stru
 * (including FCS and tag) because the length verification is done after
 * the Broadcom tag is stripped off the ingress packet.
 */
-   if (skb_padto(skb, ETH_ZLEN + ENET_BRCM_TAG_LEN)) {
+   if (skb_put_padto(skb, ETH_ZLEN + ENET_BRCM_TAG_LEN)) {
ret = NETDEV_TX_OK;
goto out;
}
 
-   skb_len = skb->len < ETH_ZLEN + ENET_BRCM_TAG_LEN ?
-   ETH_ZLEN + ENET_BRCM_TAG_LEN : skb->len;
+   skb_len = skb->len;
 
mapping = dma_map_single(kdev, skb->data, skb_len, DMA_TO_DEVICE);
if (dma_mapping_error(kdev, mapping)) {




[PATCH 4.4 30/49] KVM: arm/arm64: Fix occasional warning from the timer work function

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Christoffer Dall 


[ Upstream commit 63e41226afc3f7a044b70325566fa86ac3142538 ]

When a VCPU blocks (WFI) and has programmed the vtimer, we program a
soft timer to expire in the future to wake up the vcpu thread when
appropriate.  Because such as wake up involves a vcpu kick, and the
timer expire function can get called from interrupt context, and the
kick may sleep, we have to schedule the kick in the work function.

The work function currently has a warning that gets raised if it turns
out that the timer shouldn't fire when it's run, which was added because
the idea was that in that case the work should never have been cancelled.

However, it turns out that this whole thing is racy and we can get
spurious warnings.  The problem is that we clear the armed flag in the
work function, which may run in parallel with the
kvm_timer_unschedule->timer_disarm() call.  This results in a possible
situation where the timer_disarm() call does not call
cancel_work_sync(), which effectively synchronizes the completion of the
work function with running the VCPU.  As a result, the VCPU thread
proceeds before the work function completees, causing changes to the
timer state such that kvm_timer_should_fire(vcpu) returns false in the
work function.

All we do in the work function is to kick the VCPU, and an occasional
rare extra kick never harmed anyone.  Since the race above is extremely
rare, we don't bother checking if the race happens but simply remove the
check and the clearing of the armed flag from the work function.

Reported-by: Matthias Brugger 
Reviewed-by: Marc Zyngier 
Signed-off-by: Christoffer Dall 
Signed-off-by: Marc Zyngier 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 virt/kvm/arm/arch_timer.c |3 ---
 1 file changed, 3 deletions(-)

--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -84,9 +84,6 @@ static void kvm_timer_inject_irq_work(st
struct kvm_vcpu *vcpu;
 
vcpu = container_of(work, struct kvm_vcpu, arch.timer_cpu.expired);
-   vcpu->arch.timer_cpu.armed = false;
-
-   WARN_ON(!kvm_timer_should_fire(vcpu));
 
/*
 * If the vcpu is blocked we want to wake it up so that it will see




[PATCH 4.4 28/49] ravb: Remove Rx overflow log messages

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Kazuya Mizuguchi 


[ Upstream commit 18a3ed59d09cf81a6447aadf6931bf0c9ffec5e0 ]

Remove Rx overflow log messages as in an environment where logging results
in network traffic logging may cause further overflows.

Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper")
Signed-off-by: Kazuya Mizuguchi 
[simon: reworked changelog]
Signed-off-by: Simon Horman 
Acked-by: Sergei Shtylyov 
Signed-off-by: David S. Miller 

Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/renesas/ravb_main.c |8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -831,14 +831,10 @@ static int ravb_poll(struct napi_struct
/* Receive error message handling */
priv->rx_over_errors =  priv->stats[RAVB_BE].rx_over_errors;
priv->rx_over_errors += priv->stats[RAVB_NC].rx_over_errors;
-   if (priv->rx_over_errors != ndev->stats.rx_over_errors) {
+   if (priv->rx_over_errors != ndev->stats.rx_over_errors)
ndev->stats.rx_over_errors = priv->rx_over_errors;
-   netif_err(priv, rx_err, ndev, "Receive Descriptor Empty\n");
-   }
-   if (priv->rx_fifo_errors != ndev->stats.rx_fifo_errors) {
+   if (priv->rx_fifo_errors != ndev->stats.rx_fifo_errors)
ndev->stats.rx_fifo_errors = priv->rx_fifo_errors;
-   netif_err(priv, rx_err, ndev, "Receive FIFO Overflow\n");
-   }
 out:
return budget - quota;
 }




[PATCH 4.4 24/49] net: systemport: Pad packet before inserting TSB

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Fainelli 


[ Upstream commit 38e5a85562a6cd911fc26d951d576551a688574c ]

Inserting the TSB means adding an extra 8 bytes in front the of packet
that is going to be used as metadata information by the TDMA engine, but
stripped off, so it does not really help with the packet padding.

For some odd packet sizes that fall below the 60 bytes payload (e.g: ARP)
we can end-up padding them after the TSB insertion, thus making them 64
bytes, but with the TDMA stripping off the first 8 bytes, they could
still be smaller than 64 bytes which is required to ingress the switch.

Fix this by swapping the padding and TSB insertion, guaranteeing that
the packets have the right sizes.

Fixes: 80105befdb4b ("net: systemport: add Broadcom SYSTEMPORT Ethernet MAC 
driver")
Signed-off-by: Florian Fainelli 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/ethernet/broadcom/bcmsysport.c |   18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

--- a/drivers/net/ethernet/broadcom/bcmsysport.c
+++ b/drivers/net/ethernet/broadcom/bcmsysport.c
@@ -1045,15 +1045,6 @@ static netdev_tx_t bcm_sysport_xmit(stru
goto out;
}
 
-   /* Insert TSB and checksum infos */
-   if (priv->tsb_en) {
-   skb = bcm_sysport_insert_tsb(skb, dev);
-   if (!skb) {
-   ret = NETDEV_TX_OK;
-   goto out;
-   }
-   }
-
/* The Ethernet switch we are interfaced with needs packets to be at
 * least 64 bytes (including FCS) otherwise they will be discarded when
 * they enter the switch port logic. When Broadcom tags are enabled, we
@@ -1066,6 +1057,15 @@ static netdev_tx_t bcm_sysport_xmit(stru
goto out;
}
 
+   /* Insert TSB and checksum infos */
+   if (priv->tsb_en) {
+   skb = bcm_sysport_insert_tsb(skb, dev);
+   if (!skb) {
+   ret = NETDEV_TX_OK;
+   goto out;
+   }
+   }
+
skb_len = skb->len;
 
mapping = dma_map_single(kdev, skb->data, skb_len, DMA_TO_DEVICE);




[PATCH 4.4 33/49] net: sctp: fix array overrun read on sctp_timer_tbl

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 


[ Upstream commit 0e73fc9a56f22f2eec4d2b2910c649f7af67b74d ]

The comparison on the timeout can lead to an array overrun
read on sctp_timer_tbl because of an off-by-one error. Fix
this by using < instead of <= and also compare to the array
size rather than SCTP_EVENT_TIMEOUT_MAX.

Fixes CoverityScan CID#1397639 ("Out-of-bounds read")

Signed-off-by: Colin Ian King 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 net/sctp/debug.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/sctp/debug.c
+++ b/net/sctp/debug.c
@@ -166,7 +166,7 @@ static const char *const sctp_timer_tbl[
 /* Lookup timer debug name. */
 const char *sctp_tname(const sctp_subtype_t id)
 {
-   if (id.timeout <= SCTP_EVENT_TIMEOUT_MAX)
+   if (id.timeout < ARRAY_SIZE(sctp_timer_tbl))
return sctp_timer_tbl[id.timeout];
return "unknown_timer";
 }




[PATCH 4.4 35/49] dmaengine: pl330: fix double lock

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Iago Abal 


[ Upstream commit 91539eb1fda2d530d3b268eef542c5414e54bf1a ]

The static bug finder EBA (http://www.iagoabal.eu/eba/) reported the
following double-lock bug:

Double lock:
1. spin_lock_irqsave(pch->lock, flags) at pl330_free_chan_resources:2236;
2. call to function `pl330_release_channel' immediately after;
3. call to function `dma_pl330_rqcb' in line 1753;
4. spin_lock_irqsave(pch->lock, flags) at dma_pl330_rqcb:1505.

I have fixed it as suggested by Marek Szyprowski.

First, I have replaced `pch->lock' with `pl330->lock' in functions
`pl330_alloc_chan_resources' and `pl330_free_chan_resources'. This avoids
the double-lock by acquiring a different lock than `dma_pl330_rqcb'.

NOTE that, as a result, `pl330_free_chan_resources' executes
`list_splice_tail_init' on `pch->work_list' under lock `pl330->lock',
whereas in the rest of the code `pch->work_list' is protected by
`pch->lock'. I don't know if this may cause race conditions. Similarly
`pch->cyclic' is written by `pl330_alloc_chan_resources' under
`pl330->lock' but read by `pl330_tx_submit' under `pch->lock'.

Second, I have removed locking from `pl330_request_channel' and
`pl330_release_channel' functions. Function `pl330_request_channel' is
only called from `pl330_alloc_chan_resources', so the lock is already
held. Function `pl330_release_channel' is called from
`pl330_free_chan_resources', which already holds the lock, and from
`pl330_del'. Function `pl330_del' is called in an error path of
`pl330_probe' and at the end of `pl330_remove', but I assume that there
cannot be concurrent accesses to the protected data at those points.

Signed-off-by: Iago Abal 
Reviewed-by: Marek Szyprowski 
Signed-off-by: Vinod Koul 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/dma/pl330.c |   19 ++-
 1 file changed, 6 insertions(+), 13 deletions(-)

--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -1657,7 +1657,6 @@ static bool _chan_ns(const struct pl330_
 static struct pl330_thread *pl330_request_channel(struct pl330_dmac *pl330)
 {
struct pl330_thread *thrd = NULL;
-   unsigned long flags;
int chans, i;
 
if (pl330->state == DYING)
@@ -1665,8 +1664,6 @@ static struct pl330_thread *pl330_reques
 
chans = pl330->pcfg.num_chan;
 
-   spin_lock_irqsave(&pl330->lock, flags);
-
for (i = 0; i < chans; i++) {
thrd = &pl330->channels[i];
if ((thrd->free) && (!_manager_ns(thrd) ||
@@ -1684,8 +1681,6 @@ static struct pl330_thread *pl330_reques
thrd = NULL;
}
 
-   spin_unlock_irqrestore(&pl330->lock, flags);
-
return thrd;
 }
 
@@ -1703,7 +1698,6 @@ static inline void _free_event(struct pl
 static void pl330_release_channel(struct pl330_thread *thrd)
 {
struct pl330_dmac *pl330;
-   unsigned long flags;
 
if (!thrd || thrd->free)
return;
@@ -1715,10 +1709,8 @@ static void pl330_release_channel(struct
 
pl330 = thrd->dmac;
 
-   spin_lock_irqsave(&pl330->lock, flags);
_free_event(thrd, thrd->ev);
thrd->free = true;
-   spin_unlock_irqrestore(&pl330->lock, flags);
 }
 
 /* Initialize the structure for PL330 configuration, that can be used
@@ -2085,20 +2077,20 @@ static int pl330_alloc_chan_resources(st
struct pl330_dmac *pl330 = pch->dmac;
unsigned long flags;
 
-   spin_lock_irqsave(&pch->lock, flags);
+   spin_lock_irqsave(&pl330->lock, flags);
 
dma_cookie_init(chan);
pch->cyclic = false;
 
pch->thread = pl330_request_channel(pl330);
if (!pch->thread) {
-   spin_unlock_irqrestore(&pch->lock, flags);
+   spin_unlock_irqrestore(&pl330->lock, flags);
return -ENOMEM;
}
 
tasklet_init(&pch->task, pl330_tasklet, (unsigned long) pch);
 
-   spin_unlock_irqrestore(&pch->lock, flags);
+   spin_unlock_irqrestore(&pl330->lock, flags);
 
return 1;
 }
@@ -2201,12 +2193,13 @@ static int pl330_pause(struct dma_chan *
 static void pl330_free_chan_resources(struct dma_chan *chan)
 {
struct dma_pl330_chan *pch = to_pchan(chan);
+   struct pl330_dmac *pl330 = pch->dmac;
unsigned long flags;
 
tasklet_kill(&pch->task);
 
pm_runtime_get_sync(pch->dmac->ddma.dev);
-   spin_lock_irqsave(&pch->lock, flags);
+   spin_lock_irqsave(&pl330->lock, flags);
 
pl330_release_channel(pch->thread);
pch->thread = NULL;
@@ -2214,7 +2207,7 @@ static void pl330_free_chan_resources(st
if (pch->cyclic)
list_splice_tail_init(&pch->work_list, &pch->dmac->desc_pool);
 
-   spin_unlock_irqrestore(&pch->lock, flags);
+   spin_unlock_irqrestore(&pl330->lock, flags);
pm_runtime_mark_last_busy(pch->dmac->ddma.dev);
pm_runtime_pu

[PATCH 4.4 31/49] NFSv4: Fix client recovery when server reboots multiple times

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Trond Myklebust 


[ Upstream commit c6180a6237174f481dc856ed6e890d8196b6f0fb ]

If the server reboots multiple times, the client should rely on the
server to tell it that it cannot reclaim state as per section 9.6.3.4
in RFC7530 and section 8.4.2.1 in RFC5661.
Currently, the client is being to conservative, and is assuming that
if the server reboots while state recovery is in progress, then it must
ignore state that was not recovered before the reboot.

Signed-off-by: Trond Myklebust 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 fs/nfs/nfs4state.c |1 -
 1 file changed, 1 deletion(-)

--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1680,7 +1680,6 @@ static int nfs4_recovery_handle_error(st
break;
case -NFS4ERR_STALE_CLIENTID:
set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
-   nfs4_state_clear_reclaim_reboot(clp);
nfs4_state_start_reclaim_reboot(clp);
break;
case -NFS4ERR_EXPIRED:




[PATCH 4.4 36/49] tcp: correct memory barrier usage in tcp_check_space()

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Jason Baron 


[ Upstream commit 56d806222ace4c3aeae516cd7a855340fb2839d8 ]

sock_reset_flag() maps to __clear_bit() not the atomic version clear_bit().
Thus, we need smp_mb(), smp_mb__after_atomic() is not sufficient.

Fixes: 3c7151275c0c ("tcp: add memory barriers to write space paths")
Cc: Eric Dumazet 
Cc: Oleg Nesterov 
Signed-off-by: Jason Baron 
Acked-by: Eric Dumazet 
Reported-by: Oleg Nesterov 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 net/ipv4/tcp_input.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4942,7 +4942,7 @@ static void tcp_check_space(struct sock
if (sock_flag(sk, SOCK_QUEUE_SHRUNK)) {
sock_reset_flag(sk, SOCK_QUEUE_SHRUNK);
/* pairs with tcp_poll() */
-   smp_mb__after_atomic();
+   smp_mb();
if (sk->sk_socket &&
test_bit(SOCK_NOSPACE, &sk->sk_socket->flags))
tcp_new_space(sk);




[PATCH 4.4 38/49] xen-netfront: Improve error handling during initialization

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Ross Lagerwall 


[ Upstream commit e2e004acc7cbe3c531e752a270a74e95cde3ea48 ]

This fixes a crash when running out of grant refs when creating many
queues across many netdevs.

* If creating queues fails (i.e. there are no grant refs available),
call xenbus_dev_fatal() to ensure that the xenbus device is set to the
closed state.
* If no queues are created, don't call xennet_disconnect_backend as
netdev->real_num_tx_queues will not have been set correctly.
* If setup_netfront() fails, ensure that all the queues created are
cleaned up, not just those that have been set up.
* If any queues were set up and an error occurs, call
xennet_destroy_queues() to clean up the napi context.
* If any fatal error occurs, unregister and destroy the netdev to avoid
leaving around a half setup network device.

Signed-off-by: Ross Lagerwall 
Reviewed-by: Boris Ostrovsky 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/net/xen-netfront.c |   29 +++--
 1 file changed, 11 insertions(+), 18 deletions(-)

--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -1840,27 +1840,19 @@ static int talk_to_netback(struct xenbus
xennet_destroy_queues(info);
 
err = xennet_create_queues(info, &num_queues);
-   if (err < 0)
-   goto destroy_ring;
+   if (err < 0) {
+   xenbus_dev_fatal(dev, err, "creating queues");
+   kfree(info->queues);
+   info->queues = NULL;
+   goto out;
+   }
 
/* Create shared ring, alloc event channel -- for each queue */
for (i = 0; i < num_queues; ++i) {
queue = &info->queues[i];
err = setup_netfront(dev, queue, feature_split_evtchn);
-   if (err) {
-   /* setup_netfront() will tidy up the current
-* queue on error, but we need to clean up
-* those already allocated.
-*/
-   if (i > 0) {
-   rtnl_lock();
-   netif_set_real_num_tx_queues(info->netdev, i);
-   rtnl_unlock();
-   goto destroy_ring;
-   } else {
-   goto out;
-   }
-   }
+   if (err)
+   goto destroy_ring;
}
 
 again:
@@ -1950,9 +1942,10 @@ abort_transaction_no_dev_fatal:
xenbus_transaction_end(xbt, 1);
  destroy_ring:
xennet_disconnect_backend(info);
-   kfree(info->queues);
-   info->queues = NULL;
+   xennet_destroy_queues(info);
  out:
+   unregister_netdev(info->netdev);
+   xennet_free_netdev(info->netdev);
return err;
 }
 




[PATCH 4.4 43/49] usb: Add USB 3.1 Precision time measurement capability descriptor support

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Mathias Nyman 

commit faee822c5a7ab99de25cd34fcde3f8d37b6b9923 upstream.

USB 3.1 devices that support precision time measurement have an
additional PTM cabaility descriptor as part of the full BOS descriptor

Look for this descriptor while parsing the BOS descriptor, and store it in
struct usb_hub_bos if it exists.

Signed-off-by: Mathias Nyman 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/config.c|3 +++
 include/linux/usb.h  |1 +
 include/uapi/linux/usb/ch9.h |   10 ++
 3 files changed, 14 insertions(+)

--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -959,6 +959,9 @@ int usb_get_bos_descriptor(struct usb_de
dev->bos->ss_id =
(struct usb_ss_container_id_descriptor *)buffer;
break;
+   case USB_PTM_CAP_TYPE:
+   dev->bos->ptm_cap =
+   (struct usb_ptm_cap_descriptor *)buffer;
default:
break;
}
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -330,6 +330,7 @@ struct usb_host_bos {
struct usb_ss_cap_descriptor*ss_cap;
struct usb_ssp_cap_descriptor   *ssp_cap;
struct usb_ss_container_id_descriptor   *ss_id;
+   struct usb_ptm_cap_descriptor   *ptm_cap;
 };
 
 int __usb_get_extra_descriptor(char *buffer, unsigned size,
--- a/include/uapi/linux/usb/ch9.h
+++ b/include/uapi/linux/usb/ch9.h
@@ -895,6 +895,16 @@ struct usb_ssp_cap_descriptor {
 #define USB_SSP_SUBLINK_SPEED_LSM  (0xff << 16)/* Lanespeed mantissa */
 } __attribute__((packed));
 
+/*
+ * Precision time measurement capability descriptor: advertised by devices and
+ * hubs that support PTM
+ */
+#defineUSB_PTM_CAP_TYPE0xb
+struct usb_ptm_cap_descriptor {
+   __u8  bLength;
+   __u8  bDescriptorType;
+   __u8  bDevCapabilityType;
+} __attribute__((packed));
 
 /*-*/
 




[PATCH 4.4 16/49] serial: 8250: Preserve DLD[7:4] for PORT_XR17V35X

2017-12-07 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Aaron Sierra 


[ Upstream commit 0ab84da2e076948c49d36197ee7d254125c53eab ]

The upper four bits of the XR17V35x fractional divisor register (DLD)
control general chip function (RS-485 direction pin polarity, multidrop
mode, XON/XOFF parity check, and fast IR mode). Don't allow these bits
to be clobbered when setting the baudrate.

Signed-off-by: Aaron Sierra 
Signed-off-by: Greg Kroah-Hartman 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/tty/serial/8250/8250_port.c |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2223,8 +2223,11 @@ static void serial8250_set_divisor(struc
serial_dl_write(up, quot);
 
/* XR17V35x UARTs have an extra fractional divisor register (DLD) */
-   if (up->port.type == PORT_XR17V35X)
+   if (up->port.type == PORT_XR17V35X) {
+   /* Preserve bits not related to baudrate; DLD[7:4]. */
+   quot_frac |= serial_port_in(port, 0x2) & 0xf0;
serial_port_out(port, 0x2, quot_frac);
+   }
 }
 
 static unsigned int




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