[PATCH 4.14 058/165] tools/power turbostat: Read extended processor family from CPUID

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Calvin Walton 

[ Upstream commit 5aa3d1a20a233d4a5f1ec3d62da3f19d9afea682 ]

This fixes the reported family on modern AMD processors (e.g. Ryzen,
which is family 0x17). Previously these processors all showed up as
family 0xf.

See the document
https://support.amd.com/TechDocs/56255_OSRR.pdf
section CPUID_Fn0001_EAX for how to calculate the family
from the BaseFamily and ExtFamily values.

This matches the code in arch/x86/lib/cpu.c

Signed-off-by: Calvin Walton 
Signed-off-by: Len Brown 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 tools/power/x86/turbostat/turbostat.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -4029,7 +4029,9 @@ void process_cpuid()
family = (fms >> 8) & 0xf;
model = (fms >> 4) & 0xf;
stepping = fms & 0xf;
-   if (family == 6 || family == 0xf)
+   if (family == 0xf)
+   family += (fms >> 20) & 0xff;
+   if (family >= 6)
model += ((fms >> 16) & 0xf) << 4;
 
if (!quiet) {




[PATCH 4.14 075/165] drivers: net: lmc: fix case value for target abort error

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 

[ Upstream commit afb41bb039656f0cecb54eeb8b2e2088201295f5 ]

Current value for a target abort error is 0x010, however, this value
should in fact be 0x002.  As it stands, the range of error is 0..7 so
it is currently never being detected.  This bug has been in the driver
since the early 2.6.12 days (or before).

Detected by CoverityScan, CID#744290 ("Logically dead code")

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

--- a/drivers/net/wan/lmc/lmc_main.c
+++ b/drivers/net/wan/lmc/lmc_main.c
@@ -1371,7 +1371,7 @@ static irqreturn_t lmc_interrupt (int ir
 case 0x001:
 printk(KERN_WARNING "%s: Master Abort (naughty)\n", dev->name);
 break;
-case 0x010:
+case 0x002:
 printk(KERN_WARNING "%s: Target Abort (not so naughty)\n", 
dev->name);
 break;
 default:




[PATCH 4.14 140/165] hwmon: (nct6775) Fix potential Spectre v1

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Gustavo A. R. Silva 

commit d49dbfade96d5b0863ca8a90122a805edd5ef50a upstream.

val can be indirectly controlled by user-space, hence leading to
a potential exploitation of the Spectre variant 1 vulnerability.

This issue was detected with the help of Smatch:

vers/hwmon/nct6775.c:2698 store_pwm_weight_temp_sel() warn: potential
spectre issue 'data->temp_src' [r]

Fix this by sanitizing val before using it to index data->temp_src

Notice that given that speculation windows are large, the policy is
to kill the speculation on the first load and not worry if it can be
completed with a dependent load/store [1].

[1] https://marc.info/?l=linux-kernel=152449131114778=2

Cc: sta...@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva 
Signed-off-by: Guenter Roeck 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/hwmon/nct6775.c |2 ++
 1 file changed, 2 insertions(+)

--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -63,6 +63,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "lm75.h"
 
 #define USE_ALTERNATE
@@ -2642,6 +2643,7 @@ store_pwm_weight_temp_sel(struct device
return err;
if (val > NUM_TEMP)
return -EINVAL;
+   val = array_index_nospec(val, NUM_TEMP + 1);
if (val && (!(data->have_temp & BIT(val - 1)) ||
!data->temp_src[val - 1]))
return -EINVAL;




[PATCH 4.18 010/123] cifs: check kmalloc before use

2018-09-03 Thread Greg Kroah-Hartman
4.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Nicholas Mc Guire 

commit 126c97f4d0d1b5b956e8b0740c81a2b2a2ae548c upstream.

The kmalloc was not being checked - if it fails issue a warning
and return -ENOMEM to the caller.

Signed-off-by: Nicholas Mc Guire 
Fixes: b8da344b74c8 ("cifs: dynamic allocation of ntlmssp blob")
Signed-off-by: Steve French 
Reviewed-by: Pavel Shilovsky 
cc: Stable `
Signed-off-by: Greg Kroah-Hartman 

---
 fs/cifs/sess.c |6 ++
 1 file changed, 6 insertions(+)

--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -398,6 +398,12 @@ int build_ntlmssp_auth_blob(unsigned cha
goto setup_ntlmv2_ret;
}
*pbuffer = kmalloc(size_of_ntlmssp_blob(ses), GFP_KERNEL);
+   if (!*pbuffer) {
+   rc = -ENOMEM;
+   cifs_dbg(VFS, "Error %d during NTLMSSP allocation\n", rc);
+   *buflen = 0;
+   goto setup_ntlmv2_ret;
+   }
sec_blob = (AUTHENTICATE_MESSAGE *)*pbuffer;
 
memcpy(sec_blob->Signature, NTLMSSP_SIGNATURE, 8);




[PATCH 4.14 140/165] hwmon: (nct6775) Fix potential Spectre v1

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Gustavo A. R. Silva 

commit d49dbfade96d5b0863ca8a90122a805edd5ef50a upstream.

val can be indirectly controlled by user-space, hence leading to
a potential exploitation of the Spectre variant 1 vulnerability.

This issue was detected with the help of Smatch:

vers/hwmon/nct6775.c:2698 store_pwm_weight_temp_sel() warn: potential
spectre issue 'data->temp_src' [r]

Fix this by sanitizing val before using it to index data->temp_src

Notice that given that speculation windows are large, the policy is
to kill the speculation on the first load and not worry if it can be
completed with a dependent load/store [1].

[1] https://marc.info/?l=linux-kernel=152449131114778=2

Cc: sta...@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva 
Signed-off-by: Guenter Roeck 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/hwmon/nct6775.c |2 ++
 1 file changed, 2 insertions(+)

--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -63,6 +63,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "lm75.h"
 
 #define USE_ALTERNATE
@@ -2642,6 +2643,7 @@ store_pwm_weight_temp_sel(struct device
return err;
if (val > NUM_TEMP)
return -EINVAL;
+   val = array_index_nospec(val, NUM_TEMP + 1);
if (val && (!(data->have_temp & BIT(val - 1)) ||
!data->temp_src[val - 1]))
return -EINVAL;




[PATCH 4.18 010/123] cifs: check kmalloc before use

2018-09-03 Thread Greg Kroah-Hartman
4.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Nicholas Mc Guire 

commit 126c97f4d0d1b5b956e8b0740c81a2b2a2ae548c upstream.

The kmalloc was not being checked - if it fails issue a warning
and return -ENOMEM to the caller.

Signed-off-by: Nicholas Mc Guire 
Fixes: b8da344b74c8 ("cifs: dynamic allocation of ntlmssp blob")
Signed-off-by: Steve French 
Reviewed-by: Pavel Shilovsky 
cc: Stable `
Signed-off-by: Greg Kroah-Hartman 

---
 fs/cifs/sess.c |6 ++
 1 file changed, 6 insertions(+)

--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -398,6 +398,12 @@ int build_ntlmssp_auth_blob(unsigned cha
goto setup_ntlmv2_ret;
}
*pbuffer = kmalloc(size_of_ntlmssp_blob(ses), GFP_KERNEL);
+   if (!*pbuffer) {
+   rc = -ENOMEM;
+   cifs_dbg(VFS, "Error %d during NTLMSSP allocation\n", rc);
+   *buflen = 0;
+   goto setup_ntlmv2_ret;
+   }
sec_blob = (AUTHENTICATE_MESSAGE *)*pbuffer;
 
memcpy(sec_blob->Signature, NTLMSSP_SIGNATURE, 8);




[PATCH 4.14 131/165] ASoC: dpcm: dont merge format from invalid codec dai

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Jerome Brunet 

commit 4febced15ac8ddb9cf3e603edb111842e4863d9a upstream.

When merging codec formats, dpcm_runtime_base_format() should skip
the codecs which are not supporting the current stream direction.

At the moment, if a BE link has more than one codec, and only one
of these codecs has no capture DAI, it becomes impossible to start
a capture stream because the merged format would be 0.

Skipping invalid codec DAI solves the problem.

Fixes: b073ed4e2126 ("ASoC: soc-pcm: DPCM cares BE format")
Signed-off-by: Jerome Brunet 
Signed-off-by: Mark Brown 
Cc: sta...@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman 

---
 sound/soc/soc-pcm.c |8 
 1 file changed, 8 insertions(+)

--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1607,6 +1607,14 @@ static u64 dpcm_runtime_base_format(stru
int i;
 
for (i = 0; i < be->num_codecs; i++) {
+   /*
+* Skip CODECs which don't support the current stream
+* type. See soc_pcm_init_runtime_hw() for more details
+*/
+   if (!snd_soc_dai_stream_valid(be->codec_dais[i],
+ stream))
+   continue;
+
codec_dai_drv = be->codec_dais[i]->driver;
if (stream == SNDRV_PCM_STREAM_PLAYBACK)
codec_stream = _dai_drv->playback;




[PATCH 4.18 011/123] smb3: enumerating snapshots was leaving part of the data off end

2018-09-03 Thread Greg Kroah-Hartman
4.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Steve French 

commit e02789a53d71334b067ad72eee5d4e88a0158083 upstream.

When enumerating snapshots, the last few bytes of the final
snapshot could be left off since we were miscalculating the
length returned (leaving off the sizeof struct SRV_SNAPSHOT_ARRAY)
See MS-SMB2 section 2.2.32.2. In addition fixup the length used
to allow smaller buffer to be passed in, in order to allow
returning the size of the whole snapshot array more easily.

Sample userspace output with a kernel patched with this
(mounted to a Windows volume with two snapshots).
Before this patch, the second snapshot would be missing a
few bytes at the end.

~/cifs-2.6# ~/enum-snapshots /mnt/file
press enter to issue the ioctl to retrieve snapshot information ...

size of snapshot array = 102
Num snapshots: 2 Num returned: 2 Array Size: 102

Snapshot 0:@GMT-2018.06.30-19.34.17
Snapshot 1:@GMT-2018.06.30-19.33.37

CC: Stable 
Signed-off-by: Steve French 
Reviewed-by: Pavel Shilovsky 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/cifs/smb2ops.c |   34 +++---
 1 file changed, 27 insertions(+), 7 deletions(-)

--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -1374,6 +1374,13 @@ smb3_set_integrity(const unsigned int xi
 
 }
 
+/* GMT Token is @GMT-.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
+#define GMT_TOKEN_SIZE 50
+
+/*
+ * Input buffer contains (empty) struct smb_snapshot array with size filled in
+ * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
+ */
 static int
 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
   struct cifsFileInfo *cfile, void __user *ioc_buf)
@@ -1403,14 +1410,27 @@ smb3_enum_snapshots(const unsigned int x
kfree(retbuf);
return rc;
}
-   if (snapshot_in.snapshot_array_size < sizeof(struct 
smb_snapshot_array)) {
-   rc = -ERANGE;
-   kfree(retbuf);
-   return rc;
-   }
 
-   if (ret_data_len > snapshot_in.snapshot_array_size)
-   ret_data_len = snapshot_in.snapshot_array_size;
+   /*
+* Check for min size, ie not large enough to fit even one GMT
+* token (snapshot).  On the first ioctl some users may pass in
+* smaller size (or zero) to simply get the size of the array
+* so the user space caller can allocate sufficient memory
+* and retry the ioctl again with larger array size sufficient
+* to hold all of the snapshot GMT tokens on the second try.
+*/
+   if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
+   ret_data_len = sizeof(struct smb_snapshot_array);
+
+   /*
+* We return struct SRV_SNAPSHOT_ARRAY, followed by
+* the snapshot array (of 50 byte GMT tokens) each
+* representing an available previous version of the data
+*/
+   if (ret_data_len > (snapshot_in.snapshot_array_size +
+   sizeof(struct smb_snapshot_array)))
+   ret_data_len = snapshot_in.snapshot_array_size +
+   sizeof(struct smb_snapshot_array);
 
if (copy_to_user(ioc_buf, retbuf, ret_data_len))
rc = -EFAULT;




[PATCH 4.18 001/123] PATCH scripts/kernel-doc

2018-09-03 Thread Greg Kroah-Hartman
4.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Valdis Kletnieks 

commit 701b3a3c0ac42630f74a5efba8545d61ac0e3293 upstream.

Fix a warning whinge from Perl introduced by "scripts: kernel-doc: parse next 
structs/unions"

Unescaped left brace in regex is deprecated here (and will be fatal in Perl 
5.32), passed through in regex; marked by <-- HERE in m/({ <-- HERE [^\{\}]*})/ 
at ./scripts/kernel-doc line 1155.
Unescaped left brace in regex is deprecated here (and will be fatal in Perl 
5.32), passed through in regex; marked by <-- HERE in m/({ <-- HERE )/ at 
./scripts/kernel-doc line 1179.

Signed-off-by: Valdis Kletnieks 
Reviewed-by: Mauro Carvalho Chehab 
Signed-off-by: Jonathan Corbet 
Cc: Nathan Chancellor 
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/kernel-doc |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -1152,7 +1152,7 @@ sub dump_struct($$) {
}
 
# Ignore other nested elements, like enums
-   $members =~ s/({[^\{\}]*})//g;
+   $members =~ s/(\{[^\{\}]*})//g;
 
create_parameterlist($members, ';', $file, $declaration_name);
check_sections($file, $declaration_name, $decl_type, $sectcheck, 
$struct_actual);
@@ -1176,7 +1176,7 @@ sub dump_struct($$) {
$declaration .= "\t" x $level;
}
$declaration .= "\t" . $clause . "\n";
-   $level++ if ($clause =~ m/({)/ && !($clause =~m/}/));
+   $level++ if ($clause =~ m/(\{)/ && !($clause =~m/}/));
}
output_declaration($declaration_name,
   'struct',




[PATCH 4.14 131/165] ASoC: dpcm: dont merge format from invalid codec dai

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Jerome Brunet 

commit 4febced15ac8ddb9cf3e603edb111842e4863d9a upstream.

When merging codec formats, dpcm_runtime_base_format() should skip
the codecs which are not supporting the current stream direction.

At the moment, if a BE link has more than one codec, and only one
of these codecs has no capture DAI, it becomes impossible to start
a capture stream because the merged format would be 0.

Skipping invalid codec DAI solves the problem.

Fixes: b073ed4e2126 ("ASoC: soc-pcm: DPCM cares BE format")
Signed-off-by: Jerome Brunet 
Signed-off-by: Mark Brown 
Cc: sta...@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman 

---
 sound/soc/soc-pcm.c |8 
 1 file changed, 8 insertions(+)

--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1607,6 +1607,14 @@ static u64 dpcm_runtime_base_format(stru
int i;
 
for (i = 0; i < be->num_codecs; i++) {
+   /*
+* Skip CODECs which don't support the current stream
+* type. See soc_pcm_init_runtime_hw() for more details
+*/
+   if (!snd_soc_dai_stream_valid(be->codec_dais[i],
+ stream))
+   continue;
+
codec_dai_drv = be->codec_dais[i]->driver;
if (stream == SNDRV_PCM_STREAM_PLAYBACK)
codec_stream = _dai_drv->playback;




[PATCH 4.18 011/123] smb3: enumerating snapshots was leaving part of the data off end

2018-09-03 Thread Greg Kroah-Hartman
4.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Steve French 

commit e02789a53d71334b067ad72eee5d4e88a0158083 upstream.

When enumerating snapshots, the last few bytes of the final
snapshot could be left off since we were miscalculating the
length returned (leaving off the sizeof struct SRV_SNAPSHOT_ARRAY)
See MS-SMB2 section 2.2.32.2. In addition fixup the length used
to allow smaller buffer to be passed in, in order to allow
returning the size of the whole snapshot array more easily.

Sample userspace output with a kernel patched with this
(mounted to a Windows volume with two snapshots).
Before this patch, the second snapshot would be missing a
few bytes at the end.

~/cifs-2.6# ~/enum-snapshots /mnt/file
press enter to issue the ioctl to retrieve snapshot information ...

size of snapshot array = 102
Num snapshots: 2 Num returned: 2 Array Size: 102

Snapshot 0:@GMT-2018.06.30-19.34.17
Snapshot 1:@GMT-2018.06.30-19.33.37

CC: Stable 
Signed-off-by: Steve French 
Reviewed-by: Pavel Shilovsky 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/cifs/smb2ops.c |   34 +++---
 1 file changed, 27 insertions(+), 7 deletions(-)

--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -1374,6 +1374,13 @@ smb3_set_integrity(const unsigned int xi
 
 }
 
+/* GMT Token is @GMT-.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
+#define GMT_TOKEN_SIZE 50
+
+/*
+ * Input buffer contains (empty) struct smb_snapshot array with size filled in
+ * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
+ */
 static int
 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
   struct cifsFileInfo *cfile, void __user *ioc_buf)
@@ -1403,14 +1410,27 @@ smb3_enum_snapshots(const unsigned int x
kfree(retbuf);
return rc;
}
-   if (snapshot_in.snapshot_array_size < sizeof(struct 
smb_snapshot_array)) {
-   rc = -ERANGE;
-   kfree(retbuf);
-   return rc;
-   }
 
-   if (ret_data_len > snapshot_in.snapshot_array_size)
-   ret_data_len = snapshot_in.snapshot_array_size;
+   /*
+* Check for min size, ie not large enough to fit even one GMT
+* token (snapshot).  On the first ioctl some users may pass in
+* smaller size (or zero) to simply get the size of the array
+* so the user space caller can allocate sufficient memory
+* and retry the ioctl again with larger array size sufficient
+* to hold all of the snapshot GMT tokens on the second try.
+*/
+   if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
+   ret_data_len = sizeof(struct smb_snapshot_array);
+
+   /*
+* We return struct SRV_SNAPSHOT_ARRAY, followed by
+* the snapshot array (of 50 byte GMT tokens) each
+* representing an available previous version of the data
+*/
+   if (ret_data_len > (snapshot_in.snapshot_array_size +
+   sizeof(struct smb_snapshot_array)))
+   ret_data_len = snapshot_in.snapshot_array_size +
+   sizeof(struct smb_snapshot_array);
 
if (copy_to_user(ioc_buf, retbuf, ret_data_len))
rc = -EFAULT;




[PATCH 4.18 001/123] PATCH scripts/kernel-doc

2018-09-03 Thread Greg Kroah-Hartman
4.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Valdis Kletnieks 

commit 701b3a3c0ac42630f74a5efba8545d61ac0e3293 upstream.

Fix a warning whinge from Perl introduced by "scripts: kernel-doc: parse next 
structs/unions"

Unescaped left brace in regex is deprecated here (and will be fatal in Perl 
5.32), passed through in regex; marked by <-- HERE in m/({ <-- HERE [^\{\}]*})/ 
at ./scripts/kernel-doc line 1155.
Unescaped left brace in regex is deprecated here (and will be fatal in Perl 
5.32), passed through in regex; marked by <-- HERE in m/({ <-- HERE )/ at 
./scripts/kernel-doc line 1179.

Signed-off-by: Valdis Kletnieks 
Reviewed-by: Mauro Carvalho Chehab 
Signed-off-by: Jonathan Corbet 
Cc: Nathan Chancellor 
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/kernel-doc |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -1152,7 +1152,7 @@ sub dump_struct($$) {
}
 
# Ignore other nested elements, like enums
-   $members =~ s/({[^\{\}]*})//g;
+   $members =~ s/(\{[^\{\}]*})//g;
 
create_parameterlist($members, ';', $file, $declaration_name);
check_sections($file, $declaration_name, $decl_type, $sectcheck, 
$struct_actual);
@@ -1176,7 +1176,7 @@ sub dump_struct($$) {
$declaration .= "\t" x $level;
}
$declaration .= "\t" . $clause . "\n";
-   $level++ if ($clause =~ m/({)/ && !($clause =~m/}/));
+   $level++ if ($clause =~ m/(\{)/ && !($clause =~m/}/));
}
output_declaration($declaration_name,
   'struct',




[PATCH 4.14 135/165] x86/vdso: Fix lsl operand order

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Samuel Neves 

commit e78e5a91456fcecaa2efbb3706572fe043766f4d upstream.

In the __getcpu function, lsl is using the wrong target and destination
registers. Luckily, the compiler tends to choose %eax for both variables,
so it has been working so far.

Fixes: a582c540ac1b ("x86/vdso: Use RDPID in preference to LSL when available")
Signed-off-by: Samuel Neves 
Signed-off-by: Thomas Gleixner 
Acked-by: Andy Lutomirski 
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180901201452.27828-1-sne...@dei.uc.pt
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/include/asm/vgtod.h |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/x86/include/asm/vgtod.h
+++ b/arch/x86/include/asm/vgtod.h
@@ -93,7 +93,7 @@ static inline unsigned int __getcpu(void
 *
 * If RDPID is available, use it.
 */
-   alternative_io ("lsl %[p],%[seg]",
+   alternative_io ("lsl %[seg],%[p]",
".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */
X86_FEATURE_RDPID,
[p] "=a" (p), [seg] "r" (__PER_CPU_SEG));




[PATCH 4.14 139/165] x86/speculation/l1tf: Increase l1tf memory limit for Nehalem+

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Andi Kleen 

commit cc51e5428ea54f575d49cfcede1d4cb3a72b4ec4 upstream.

On Nehalem and newer core CPUs the CPU cache internally uses 44 bits
physical address space. The L1TF workaround is limited by this internal
cache address width, and needs to have one bit free there for the
mitigation to work.

Older client systems report only 36bit physical address space so the range
check decides that L1TF is not mitigated for a 36bit phys/32GB system with
some memory holes.

But since these actually have the larger internal cache width this warning
is bogus because it would only really be needed if the system had more than
43bits of memory.

Add a new internal x86_cache_bits field. Normally it is the same as the
physical bits field reported by CPUID, but for Nehalem and newerforce it to
be at least 44bits.

Change the L1TF memory size warning to use the new cache_bits field to
avoid bogus warnings and remove the bogus comment about memory size.

Fixes: 17dbca119312 ("x86/speculation/l1tf: Add sysfs reporting for l1tf")
Reported-by: George Anchev 
Reported-by: Christopher Snowhill 
Signed-off-by: Andi Kleen 
Signed-off-by: Thomas Gleixner 
Cc: x...@kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Michael Hocko 
Cc: vba...@suse.cz
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180824170351.34874-1-a...@firstfloor.org
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/include/asm/processor.h |4 ++-
 arch/x86/kernel/cpu/bugs.c   |   46 ++-
 arch/x86/kernel/cpu/common.c |1 
 3 files changed, 45 insertions(+), 6 deletions(-)

--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -132,6 +132,8 @@ struct cpuinfo_x86 {
/* Index into per_cpu list: */
u16 cpu_index;
u32 microcode;
+   /* Address space bits used by the cache internally */
+   u8  x86_cache_bits;
 } __randomize_layout;
 
 struct cpuid_regs {
@@ -182,7 +184,7 @@ extern void cpu_detect(struct cpuinfo_x8
 
 static inline unsigned long long l1tf_pfn_limit(void)
 {
-   return BIT_ULL(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT);
+   return BIT_ULL(boot_cpu_data.x86_cache_bits - 1 - PAGE_SHIFT);
 }
 
 extern void early_cpu_init(void);
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -652,6 +652,45 @@ EXPORT_SYMBOL_GPL(l1tf_mitigation);
 enum vmx_l1d_flush_state l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_AUTO;
 EXPORT_SYMBOL_GPL(l1tf_vmx_mitigation);
 
+/*
+ * These CPUs all support 44bits physical address space internally in the
+ * cache but CPUID can report a smaller number of physical address bits.
+ *
+ * The L1TF mitigation uses the top most address bit for the inversion of
+ * non present PTEs. When the installed memory reaches into the top most
+ * address bit due to memory holes, which has been observed on machines
+ * which report 36bits physical address bits and have 32G RAM installed,
+ * then the mitigation range check in l1tf_select_mitigation() triggers.
+ * This is a false positive because the mitigation is still possible due to
+ * the fact that the cache uses 44bit internally. Use the cache bits
+ * instead of the reported physical bits and adjust them on the affected
+ * machines to 44bit if the reported bits are less than 44.
+ */
+static void override_cache_bits(struct cpuinfo_x86 *c)
+{
+   if (c->x86 != 6)
+   return;
+
+   switch (c->x86_model) {
+   case INTEL_FAM6_NEHALEM:
+   case INTEL_FAM6_WESTMERE:
+   case INTEL_FAM6_SANDYBRIDGE:
+   case INTEL_FAM6_IVYBRIDGE:
+   case INTEL_FAM6_HASWELL_CORE:
+   case INTEL_FAM6_HASWELL_ULT:
+   case INTEL_FAM6_HASWELL_GT3E:
+   case INTEL_FAM6_BROADWELL_CORE:
+   case INTEL_FAM6_BROADWELL_GT3E:
+   case INTEL_FAM6_SKYLAKE_MOBILE:
+   case INTEL_FAM6_SKYLAKE_DESKTOP:
+   case INTEL_FAM6_KABYLAKE_MOBILE:
+   case INTEL_FAM6_KABYLAKE_DESKTOP:
+   if (c->x86_cache_bits < 44)
+   c->x86_cache_bits = 44;
+   break;
+   }
+}
+
 static void __init l1tf_select_mitigation(void)
 {
u64 half_pa;
@@ -659,6 +698,8 @@ static void __init l1tf_select_mitigatio
if (!boot_cpu_has_bug(X86_BUG_L1TF))
return;
 
+   override_cache_bits(_cpu_data);
+
switch (l1tf_mitigation) {
case L1TF_MITIGATION_OFF:
case L1TF_MITIGATION_FLUSH_NOWARN:
@@ -678,11 +719,6 @@ static void __init l1tf_select_mitigatio
return;
 #endif
 
-   /*
-* This is extremely unlikely to happen because almost all
-* systems have far more MAX_PA/2 than RAM can be fit into
-* DIMM slots.
-*/
half_pa = (u64)l1tf_pfn_limit() << PAGE_SHIFT;
if (e820__mapped_any(half_pa, ULLONG_MAX - half_pa, E820_TYPE_RAM)) {
 

[PATCH 4.14 136/165] x86/nmi: Fix NMI uaccess race against CR3 switching

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Andy Lutomirski 

commit 4012e77a903d114f915fc607d6d2ed54a3d6c9b1 upstream.

A NMI can hit in the middle of context switching or in the middle of
switch_mm_irqs_off().  In either case, CR3 might not match current->mm,
which could cause copy_from_user_nmi() and friends to read the wrong
memory.

Fix it by adding a new nmi_uaccess_okay() helper and checking it in
copy_from_user_nmi() and in __copy_from_user_nmi()'s callers.

Signed-off-by: Andy Lutomirski 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Rik van Riel 
Cc: Nadav Amit 
Cc: Borislav Petkov 
Cc: Jann Horn 
Cc: Peter Zijlstra 
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/r/dd956eba16646fd0b15c3c0741269dfd84452dac.1535557289.git.l...@kernel.org
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/events/core.c  |2 +-
 arch/x86/include/asm/tlbflush.h |   40 
 arch/x86/lib/usercopy.c |5 +
 arch/x86/mm/tlb.c   |7 +++
 4 files changed, 53 insertions(+), 1 deletion(-)

--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2462,7 +2462,7 @@ perf_callchain_user(struct perf_callchai
 
perf_callchain_store(entry, regs->ip);
 
-   if (!current->mm)
+   if (!nmi_uaccess_okay())
return;
 
if (perf_callchain_user32(regs, entry))
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -175,8 +175,16 @@ struct tlb_state {
 * are on.  This means that it may not match current->active_mm,
 * which will contain the previous user mm when we're in lazy TLB
 * mode even if we've already switched back to swapper_pg_dir.
+*
+* During switch_mm_irqs_off(), loaded_mm will be set to
+* LOADED_MM_SWITCHING during the brief interrupts-off window
+* when CR3 and loaded_mm would otherwise be inconsistent.  This
+* is for nmi_uaccess_okay()'s benefit.
 */
struct mm_struct *loaded_mm;
+
+#define LOADED_MM_SWITCHING ((struct mm_struct *)1)
+
u16 loaded_mm_asid;
u16 next_asid;
/* last user mm's ctx id */
@@ -246,6 +254,38 @@ struct tlb_state {
 };
 DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);
 
+/*
+ * Blindly accessing user memory from NMI context can be dangerous
+ * if we're in the middle of switching the current user task or
+ * switching the loaded mm.  It can also be dangerous if we
+ * interrupted some kernel code that was temporarily using a
+ * different mm.
+ */
+static inline bool nmi_uaccess_okay(void)
+{
+   struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm);
+   struct mm_struct *current_mm = current->mm;
+
+   VM_WARN_ON_ONCE(!loaded_mm);
+
+   /*
+* The condition we want to check is
+* current_mm->pgd == __va(read_cr3_pa()).  This may be slow, though,
+* if we're running in a VM with shadow paging, and nmi_uaccess_okay()
+* is supposed to be reasonably fast.
+*
+* Instead, we check the almost equivalent but somewhat conservative
+* condition below, and we rely on the fact that switch_mm_irqs_off()
+* sets loaded_mm to LOADED_MM_SWITCHING before writing to CR3.
+*/
+   if (loaded_mm != current_mm)
+   return false;
+
+   VM_WARN_ON_ONCE(current_mm->pgd != __va(read_cr3_pa()));
+
+   return true;
+}
+
 /* Initialize cr4 shadow for this CPU. */
 static inline void cr4_init_shadow(void)
 {
--- a/arch/x86/lib/usercopy.c
+++ b/arch/x86/lib/usercopy.c
@@ -7,6 +7,8 @@
 #include 
 #include 
 
+#include 
+
 /*
  * We rely on the nested NMI work to allow atomic faults from the NMI path; the
  * nested NMI paths are careful to preserve CR2.
@@ -19,6 +21,9 @@ copy_from_user_nmi(void *to, const void
if (__range_not_ok(from, n, TASK_SIZE))
return n;
 
+   if (!nmi_uaccess_okay())
+   return n;
+
/*
 * Even though this function is typically called from NMI/IRQ context
 * disable pagefaults so that its behaviour is consistent even when
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -292,6 +292,10 @@ void switch_mm_irqs_off(struct mm_struct
 
choose_new_asid(next, next_tlb_gen, _asid, _flush);
 
+   /* Let nmi_uaccess_okay() know that we're changing CR3. */
+   this_cpu_write(cpu_tlbstate.loaded_mm, LOADED_MM_SWITCHING);
+   barrier();
+
if (need_flush) {
this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, 
next->context.ctx_id);
this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, 
next_tlb_gen);
@@ -322,6 +326,9 @@ void switch_mm_irqs_off(struct mm_struct
if (next != _mm)
this_cpu_write(cpu_tlbstate.last_ctx_id, 
next->context.ctx_id);
 
+  

[PATCH 4.14 165/165] gcc-plugins: Use dynamic initializers

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Kees Cook 

commit b86729109c5fd0a480300f40608aac68764b5adf upstream.

GCC 8 changed the order of some fields and is very picky about ordering
in static initializers, so instead just move to dynamic initializers,
and drop the redundant already-zero field assignments.

Suggested-by: Valdis Kletnieks 
Signed-off-by: Kees Cook 
Cc: Lance Albertson 
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/gcc-plugins/latent_entropy_plugin.c   |   17 +
 scripts/gcc-plugins/randomize_layout_plugin.c |   75 +++---
 scripts/gcc-plugins/structleak_plugin.c   |   19 ++
 3 files changed, 33 insertions(+), 78 deletions(-)

--- a/scripts/gcc-plugins/latent_entropy_plugin.c
+++ b/scripts/gcc-plugins/latent_entropy_plugin.c
@@ -255,21 +255,14 @@ static tree handle_latent_entropy_attrib
return NULL_TREE;
 }
 
-static struct attribute_spec latent_entropy_attr = {
-   .name   = "latent_entropy",
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = true,
-   .type_required  = false,
-   .function_type_required = false,
-   .handler= handle_latent_entropy_attribute,
-#if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = false
-#endif
-};
+static struct attribute_spec latent_entropy_attr = { };
 
 static void register_attributes(void *event_data __unused, void *data __unused)
 {
+   latent_entropy_attr.name= "latent_entropy";
+   latent_entropy_attr.decl_required   = true;
+   latent_entropy_attr.handler = 
handle_latent_entropy_attribute;
+
register_attribute(_entropy_attr);
 }
 
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -580,68 +580,35 @@ static void finish_type(void *event_data
return;
 }
 
-static struct attribute_spec randomize_layout_attr = {
-   .name   = "randomize_layout",
-   // related to args
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = false,
-   // need type declaration
-   .type_required  = true,
-   .function_type_required = false,
-   .handler= handle_randomize_layout_attr,
-#if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = true
-#endif
-};
+static struct attribute_spec randomize_layout_attr = { };
+static struct attribute_spec no_randomize_layout_attr = { };
+static struct attribute_spec randomize_considered_attr = { };
+static struct attribute_spec randomize_performed_attr = { };
 
-static struct attribute_spec no_randomize_layout_attr = {
-   .name   = "no_randomize_layout",
-   // related to args
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = false,
-   // need type declaration
-   .type_required  = true,
-   .function_type_required = false,
-   .handler= handle_randomize_layout_attr,
+static void register_attributes(void *event_data, void *data)
+{
+   randomize_layout_attr.name  = "randomize_layout";
+   randomize_layout_attr.type_required = true;
+   randomize_layout_attr.handler   = handle_randomize_layout_attr;
 #if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = true
+   randomize_layout_attr.affects_type_identity = true;
 #endif
-};
 
-static struct attribute_spec randomize_considered_attr = {
-   .name   = "randomize_considered",
-   // related to args
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = false,
-   // need type declaration
-   .type_required  = true,
-   .function_type_required = false,
-   .handler= handle_randomize_considered_attr,
+   no_randomize_layout_attr.name   = "no_randomize_layout";
+   no_randomize_layout_attr.type_required  = true;
+   no_randomize_layout_attr.handler= handle_randomize_layout_attr;
 #if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = false
+   no_randomize_layout_attr.affects_type_identity = true;
 #endif
-};
 
-static struct attribute_spec randomize_performed_attr = {
-   .name   = "randomize_performed",
-   // related to args
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = false,
-   // need type declaration
-   .type_required  = true,
-   .function_type_required = false,
-   .handler= handle_randomize_performed_attr,
-#if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = false
-#endif
-};
+   randomize_considered_attr.name  = "randomize_considered";
+   randomize_considered_attr.type_required = true;
+   

[PATCH 4.14 135/165] x86/vdso: Fix lsl operand order

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Samuel Neves 

commit e78e5a91456fcecaa2efbb3706572fe043766f4d upstream.

In the __getcpu function, lsl is using the wrong target and destination
registers. Luckily, the compiler tends to choose %eax for both variables,
so it has been working so far.

Fixes: a582c540ac1b ("x86/vdso: Use RDPID in preference to LSL when available")
Signed-off-by: Samuel Neves 
Signed-off-by: Thomas Gleixner 
Acked-by: Andy Lutomirski 
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180901201452.27828-1-sne...@dei.uc.pt
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/include/asm/vgtod.h |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/x86/include/asm/vgtod.h
+++ b/arch/x86/include/asm/vgtod.h
@@ -93,7 +93,7 @@ static inline unsigned int __getcpu(void
 *
 * If RDPID is available, use it.
 */
-   alternative_io ("lsl %[p],%[seg]",
+   alternative_io ("lsl %[seg],%[p]",
".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */
X86_FEATURE_RDPID,
[p] "=a" (p), [seg] "r" (__PER_CPU_SEG));




[PATCH 4.14 139/165] x86/speculation/l1tf: Increase l1tf memory limit for Nehalem+

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Andi Kleen 

commit cc51e5428ea54f575d49cfcede1d4cb3a72b4ec4 upstream.

On Nehalem and newer core CPUs the CPU cache internally uses 44 bits
physical address space. The L1TF workaround is limited by this internal
cache address width, and needs to have one bit free there for the
mitigation to work.

Older client systems report only 36bit physical address space so the range
check decides that L1TF is not mitigated for a 36bit phys/32GB system with
some memory holes.

But since these actually have the larger internal cache width this warning
is bogus because it would only really be needed if the system had more than
43bits of memory.

Add a new internal x86_cache_bits field. Normally it is the same as the
physical bits field reported by CPUID, but for Nehalem and newerforce it to
be at least 44bits.

Change the L1TF memory size warning to use the new cache_bits field to
avoid bogus warnings and remove the bogus comment about memory size.

Fixes: 17dbca119312 ("x86/speculation/l1tf: Add sysfs reporting for l1tf")
Reported-by: George Anchev 
Reported-by: Christopher Snowhill 
Signed-off-by: Andi Kleen 
Signed-off-by: Thomas Gleixner 
Cc: x...@kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Michael Hocko 
Cc: vba...@suse.cz
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180824170351.34874-1-a...@firstfloor.org
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/include/asm/processor.h |4 ++-
 arch/x86/kernel/cpu/bugs.c   |   46 ++-
 arch/x86/kernel/cpu/common.c |1 
 3 files changed, 45 insertions(+), 6 deletions(-)

--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -132,6 +132,8 @@ struct cpuinfo_x86 {
/* Index into per_cpu list: */
u16 cpu_index;
u32 microcode;
+   /* Address space bits used by the cache internally */
+   u8  x86_cache_bits;
 } __randomize_layout;
 
 struct cpuid_regs {
@@ -182,7 +184,7 @@ extern void cpu_detect(struct cpuinfo_x8
 
 static inline unsigned long long l1tf_pfn_limit(void)
 {
-   return BIT_ULL(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT);
+   return BIT_ULL(boot_cpu_data.x86_cache_bits - 1 - PAGE_SHIFT);
 }
 
 extern void early_cpu_init(void);
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -652,6 +652,45 @@ EXPORT_SYMBOL_GPL(l1tf_mitigation);
 enum vmx_l1d_flush_state l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_AUTO;
 EXPORT_SYMBOL_GPL(l1tf_vmx_mitigation);
 
+/*
+ * These CPUs all support 44bits physical address space internally in the
+ * cache but CPUID can report a smaller number of physical address bits.
+ *
+ * The L1TF mitigation uses the top most address bit for the inversion of
+ * non present PTEs. When the installed memory reaches into the top most
+ * address bit due to memory holes, which has been observed on machines
+ * which report 36bits physical address bits and have 32G RAM installed,
+ * then the mitigation range check in l1tf_select_mitigation() triggers.
+ * This is a false positive because the mitigation is still possible due to
+ * the fact that the cache uses 44bit internally. Use the cache bits
+ * instead of the reported physical bits and adjust them on the affected
+ * machines to 44bit if the reported bits are less than 44.
+ */
+static void override_cache_bits(struct cpuinfo_x86 *c)
+{
+   if (c->x86 != 6)
+   return;
+
+   switch (c->x86_model) {
+   case INTEL_FAM6_NEHALEM:
+   case INTEL_FAM6_WESTMERE:
+   case INTEL_FAM6_SANDYBRIDGE:
+   case INTEL_FAM6_IVYBRIDGE:
+   case INTEL_FAM6_HASWELL_CORE:
+   case INTEL_FAM6_HASWELL_ULT:
+   case INTEL_FAM6_HASWELL_GT3E:
+   case INTEL_FAM6_BROADWELL_CORE:
+   case INTEL_FAM6_BROADWELL_GT3E:
+   case INTEL_FAM6_SKYLAKE_MOBILE:
+   case INTEL_FAM6_SKYLAKE_DESKTOP:
+   case INTEL_FAM6_KABYLAKE_MOBILE:
+   case INTEL_FAM6_KABYLAKE_DESKTOP:
+   if (c->x86_cache_bits < 44)
+   c->x86_cache_bits = 44;
+   break;
+   }
+}
+
 static void __init l1tf_select_mitigation(void)
 {
u64 half_pa;
@@ -659,6 +698,8 @@ static void __init l1tf_select_mitigatio
if (!boot_cpu_has_bug(X86_BUG_L1TF))
return;
 
+   override_cache_bits(_cpu_data);
+
switch (l1tf_mitigation) {
case L1TF_MITIGATION_OFF:
case L1TF_MITIGATION_FLUSH_NOWARN:
@@ -678,11 +719,6 @@ static void __init l1tf_select_mitigatio
return;
 #endif
 
-   /*
-* This is extremely unlikely to happen because almost all
-* systems have far more MAX_PA/2 than RAM can be fit into
-* DIMM slots.
-*/
half_pa = (u64)l1tf_pfn_limit() << PAGE_SHIFT;
if (e820__mapped_any(half_pa, ULLONG_MAX - half_pa, E820_TYPE_RAM)) {
 

[PATCH 4.14 136/165] x86/nmi: Fix NMI uaccess race against CR3 switching

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Andy Lutomirski 

commit 4012e77a903d114f915fc607d6d2ed54a3d6c9b1 upstream.

A NMI can hit in the middle of context switching or in the middle of
switch_mm_irqs_off().  In either case, CR3 might not match current->mm,
which could cause copy_from_user_nmi() and friends to read the wrong
memory.

Fix it by adding a new nmi_uaccess_okay() helper and checking it in
copy_from_user_nmi() and in __copy_from_user_nmi()'s callers.

Signed-off-by: Andy Lutomirski 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Rik van Riel 
Cc: Nadav Amit 
Cc: Borislav Petkov 
Cc: Jann Horn 
Cc: Peter Zijlstra 
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/r/dd956eba16646fd0b15c3c0741269dfd84452dac.1535557289.git.l...@kernel.org
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/events/core.c  |2 +-
 arch/x86/include/asm/tlbflush.h |   40 
 arch/x86/lib/usercopy.c |5 +
 arch/x86/mm/tlb.c   |7 +++
 4 files changed, 53 insertions(+), 1 deletion(-)

--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2462,7 +2462,7 @@ perf_callchain_user(struct perf_callchai
 
perf_callchain_store(entry, regs->ip);
 
-   if (!current->mm)
+   if (!nmi_uaccess_okay())
return;
 
if (perf_callchain_user32(regs, entry))
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -175,8 +175,16 @@ struct tlb_state {
 * are on.  This means that it may not match current->active_mm,
 * which will contain the previous user mm when we're in lazy TLB
 * mode even if we've already switched back to swapper_pg_dir.
+*
+* During switch_mm_irqs_off(), loaded_mm will be set to
+* LOADED_MM_SWITCHING during the brief interrupts-off window
+* when CR3 and loaded_mm would otherwise be inconsistent.  This
+* is for nmi_uaccess_okay()'s benefit.
 */
struct mm_struct *loaded_mm;
+
+#define LOADED_MM_SWITCHING ((struct mm_struct *)1)
+
u16 loaded_mm_asid;
u16 next_asid;
/* last user mm's ctx id */
@@ -246,6 +254,38 @@ struct tlb_state {
 };
 DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);
 
+/*
+ * Blindly accessing user memory from NMI context can be dangerous
+ * if we're in the middle of switching the current user task or
+ * switching the loaded mm.  It can also be dangerous if we
+ * interrupted some kernel code that was temporarily using a
+ * different mm.
+ */
+static inline bool nmi_uaccess_okay(void)
+{
+   struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm);
+   struct mm_struct *current_mm = current->mm;
+
+   VM_WARN_ON_ONCE(!loaded_mm);
+
+   /*
+* The condition we want to check is
+* current_mm->pgd == __va(read_cr3_pa()).  This may be slow, though,
+* if we're running in a VM with shadow paging, and nmi_uaccess_okay()
+* is supposed to be reasonably fast.
+*
+* Instead, we check the almost equivalent but somewhat conservative
+* condition below, and we rely on the fact that switch_mm_irqs_off()
+* sets loaded_mm to LOADED_MM_SWITCHING before writing to CR3.
+*/
+   if (loaded_mm != current_mm)
+   return false;
+
+   VM_WARN_ON_ONCE(current_mm->pgd != __va(read_cr3_pa()));
+
+   return true;
+}
+
 /* Initialize cr4 shadow for this CPU. */
 static inline void cr4_init_shadow(void)
 {
--- a/arch/x86/lib/usercopy.c
+++ b/arch/x86/lib/usercopy.c
@@ -7,6 +7,8 @@
 #include 
 #include 
 
+#include 
+
 /*
  * We rely on the nested NMI work to allow atomic faults from the NMI path; the
  * nested NMI paths are careful to preserve CR2.
@@ -19,6 +21,9 @@ copy_from_user_nmi(void *to, const void
if (__range_not_ok(from, n, TASK_SIZE))
return n;
 
+   if (!nmi_uaccess_okay())
+   return n;
+
/*
 * Even though this function is typically called from NMI/IRQ context
 * disable pagefaults so that its behaviour is consistent even when
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -292,6 +292,10 @@ void switch_mm_irqs_off(struct mm_struct
 
choose_new_asid(next, next_tlb_gen, _asid, _flush);
 
+   /* Let nmi_uaccess_okay() know that we're changing CR3. */
+   this_cpu_write(cpu_tlbstate.loaded_mm, LOADED_MM_SWITCHING);
+   barrier();
+
if (need_flush) {
this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, 
next->context.ctx_id);
this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, 
next_tlb_gen);
@@ -322,6 +326,9 @@ void switch_mm_irqs_off(struct mm_struct
if (next != _mm)
this_cpu_write(cpu_tlbstate.last_ctx_id, 
next->context.ctx_id);
 
+  

[PATCH 4.14 165/165] gcc-plugins: Use dynamic initializers

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Kees Cook 

commit b86729109c5fd0a480300f40608aac68764b5adf upstream.

GCC 8 changed the order of some fields and is very picky about ordering
in static initializers, so instead just move to dynamic initializers,
and drop the redundant already-zero field assignments.

Suggested-by: Valdis Kletnieks 
Signed-off-by: Kees Cook 
Cc: Lance Albertson 
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/gcc-plugins/latent_entropy_plugin.c   |   17 +
 scripts/gcc-plugins/randomize_layout_plugin.c |   75 +++---
 scripts/gcc-plugins/structleak_plugin.c   |   19 ++
 3 files changed, 33 insertions(+), 78 deletions(-)

--- a/scripts/gcc-plugins/latent_entropy_plugin.c
+++ b/scripts/gcc-plugins/latent_entropy_plugin.c
@@ -255,21 +255,14 @@ static tree handle_latent_entropy_attrib
return NULL_TREE;
 }
 
-static struct attribute_spec latent_entropy_attr = {
-   .name   = "latent_entropy",
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = true,
-   .type_required  = false,
-   .function_type_required = false,
-   .handler= handle_latent_entropy_attribute,
-#if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = false
-#endif
-};
+static struct attribute_spec latent_entropy_attr = { };
 
 static void register_attributes(void *event_data __unused, void *data __unused)
 {
+   latent_entropy_attr.name= "latent_entropy";
+   latent_entropy_attr.decl_required   = true;
+   latent_entropy_attr.handler = 
handle_latent_entropy_attribute;
+
register_attribute(_entropy_attr);
 }
 
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -580,68 +580,35 @@ static void finish_type(void *event_data
return;
 }
 
-static struct attribute_spec randomize_layout_attr = {
-   .name   = "randomize_layout",
-   // related to args
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = false,
-   // need type declaration
-   .type_required  = true,
-   .function_type_required = false,
-   .handler= handle_randomize_layout_attr,
-#if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = true
-#endif
-};
+static struct attribute_spec randomize_layout_attr = { };
+static struct attribute_spec no_randomize_layout_attr = { };
+static struct attribute_spec randomize_considered_attr = { };
+static struct attribute_spec randomize_performed_attr = { };
 
-static struct attribute_spec no_randomize_layout_attr = {
-   .name   = "no_randomize_layout",
-   // related to args
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = false,
-   // need type declaration
-   .type_required  = true,
-   .function_type_required = false,
-   .handler= handle_randomize_layout_attr,
+static void register_attributes(void *event_data, void *data)
+{
+   randomize_layout_attr.name  = "randomize_layout";
+   randomize_layout_attr.type_required = true;
+   randomize_layout_attr.handler   = handle_randomize_layout_attr;
 #if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = true
+   randomize_layout_attr.affects_type_identity = true;
 #endif
-};
 
-static struct attribute_spec randomize_considered_attr = {
-   .name   = "randomize_considered",
-   // related to args
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = false,
-   // need type declaration
-   .type_required  = true,
-   .function_type_required = false,
-   .handler= handle_randomize_considered_attr,
+   no_randomize_layout_attr.name   = "no_randomize_layout";
+   no_randomize_layout_attr.type_required  = true;
+   no_randomize_layout_attr.handler= handle_randomize_layout_attr;
 #if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = false
+   no_randomize_layout_attr.affects_type_identity = true;
 #endif
-};
 
-static struct attribute_spec randomize_performed_attr = {
-   .name   = "randomize_performed",
-   // related to args
-   .min_length = 0,
-   .max_length = 0,
-   .decl_required  = false,
-   // need type declaration
-   .type_required  = true,
-   .function_type_required = false,
-   .handler= handle_randomize_performed_attr,
-#if BUILDING_GCC_VERSION >= 4007
-   .affects_type_identity  = false
-#endif
-};
+   randomize_considered_attr.name  = "randomize_considered";
+   randomize_considered_attr.type_required = true;
+   

[PATCH 4.14 137/165] x86/irqflags: Mark native_restore_fl extern inline

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Nick Desaulniers 

commit 1f59a4581b5ecfe9b4f049a7a2cf904d8352842d upstream.

This should have been marked extern inline in order to pick up the out
of line definition in arch/x86/kernel/irqflags.S.

Fixes: 208cbb325589 ("x86/irqflags: Provide a declaration for native_save_fl")
Reported-by: Ben Hutchings 
Signed-off-by: Nick Desaulniers 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Juergen Gross 
Cc: "H. Peter Anvin" 
Cc: Boris Ostrovsky 
Cc: Greg Kroah-Hartman 
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180827214011.55428-1-ndesaulni...@google.com
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/include/asm/irqflags.h |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -33,7 +33,8 @@ extern inline unsigned long native_save_
return flags;
 }
 
-static inline void native_restore_fl(unsigned long flags)
+extern inline void native_restore_fl(unsigned long flags);
+extern inline void native_restore_fl(unsigned long flags)
 {
asm volatile("push %0 ; popf"
 : /* no output */




[PATCH 4.14 162/165] watchdog: Mark watchdog touch functions as notrace

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Vincent Whitchurch 

commit cb9d7fd51d9fbb329d182423bd7b92d0f8cb0e01 upstream.

Some architectures need to use stop_machine() to patch functions for
ftrace, and the assumption is that the stopped CPUs do not make function
calls to traceable functions when they are in the stopped state.

Commit ce4f06dcbb5d ("stop_machine: Touch_nmi_watchdog() after
MULTI_STOP_PREPARE") added calls to the watchdog touch functions from
the stopped CPUs and those functions lack notrace annotations.  This
leads to crashes when enabling/disabling ftrace on ARM kernels built
with the Thumb-2 instruction set.

Fix it by adding the necessary notrace annotations.

Fixes: ce4f06dcbb5d ("stop_machine: Touch_nmi_watchdog() after 
MULTI_STOP_PREPARE")
Signed-off-by: Vincent Whitchurch 
Signed-off-by: Thomas Gleixner 
Cc: Peter Zijlstra 
Cc: o...@redhat.com
Cc: t...@kernel.org
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/r/20180821152507.18313-1-vincent.whitchu...@axis.com
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/watchdog.c |4 ++--
 kernel/watchdog_hld.c |2 +-
 kernel/workqueue.c|2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -265,7 +265,7 @@ static void __touch_watchdog(void)
  * entering idle state.  This should only be used for scheduler events.
  * Use touch_softlockup_watchdog() for everything else.
  */
-void touch_softlockup_watchdog_sched(void)
+notrace void touch_softlockup_watchdog_sched(void)
 {
/*
 * Preemption can be enabled.  It doesn't matter which CPU's timestamp
@@ -274,7 +274,7 @@ void touch_softlockup_watchdog_sched(voi
raw_cpu_write(watchdog_touch_ts, 0);
 }
 
-void touch_softlockup_watchdog(void)
+notrace void touch_softlockup_watchdog(void)
 {
touch_softlockup_watchdog_sched();
wq_watchdog_touch(raw_smp_processor_id());
--- a/kernel/watchdog_hld.c
+++ b/kernel/watchdog_hld.c
@@ -29,7 +29,7 @@ static struct cpumask dead_events_mask;
 static unsigned long hardlockup_allcpu_dumped;
 static atomic_t watchdog_cpus = ATOMIC_INIT(0);
 
-void arch_touch_nmi_watchdog(void)
+notrace void arch_touch_nmi_watchdog(void)
 {
/*
 * Using __raw here because some code paths have
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5484,7 +5484,7 @@ static void wq_watchdog_timer_fn(unsigne
mod_timer(_watchdog_timer, jiffies + thresh);
 }
 
-void wq_watchdog_touch(int cpu)
+notrace void wq_watchdog_touch(int cpu)
 {
if (cpu >= 0)
per_cpu(wq_watchdog_touched_cpu, cpu) = jiffies;




Re: [PATCH v3 05/30] iio: adc: move SUN4I_GPADC_CHANNEL define to header file

2018-09-03 Thread Jonathan Cameron
On Mon, 3 Sep 2018 16:24:32 +0200
Philipp Rossak  wrote:

> On 02.09.2018 22:01, Jonathan Cameron wrote:
> > On Thu, 30 Aug 2018 17:44:53 +0200
> > Philipp Rossak  wrote:
> >   
> >> We are moving the SUN4I_GPADC_CHANNEL define to the header file.  
> > Maxime has raised this point in other patches...
> > 
> > Why?  Obvious what but I have no idea why you are doing this.
> > 
> > Thanks,
> > 
> > Jonathan  
> There are two reasons:
> 1. Personal taste: I like to have the #define stuff in the header file.
> 2. When I started the rework I had to get some better overview, so I 
> moved it...
> 
> Since those two reasons are no good reasons to submit a patch I will 
> drop it and keep it in the *.c file.
Don't move it.

For a 'utility' type define like this that is just about cutting
down on code repetition it is nice to be able to see what it does near
to where it is used.

Also, as a general rule kernel style is to not put things in a header
unless they are needed in multiple files.  There are exceptions, but
it is generally felt keeping things local to where they are used
leads to easier to review code.

Jonathan
> 
> Philipp
> 
> >>
> >> Signed-off-by: Philipp Rossak 
> >> ---
> >>   drivers/iio/adc/sun4i-gpadc-iio.c | 9 -
> >>   include/linux/mfd/sun4i-gpadc.h   | 9 +
> >>   2 files changed, 9 insertions(+), 9 deletions(-)
> >>
> >> diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c 
> >> b/drivers/iio/adc/sun4i-gpadc-iio.c
> >> index d95dd0fde2a6..666329940e1e 100644
> >> --- a/drivers/iio/adc/sun4i-gpadc-iio.c
> >> +++ b/drivers/iio/adc/sun4i-gpadc-iio.c
> >> @@ -109,15 +109,6 @@ struct sun4i_gpadc_iio {
> >>struct device   *sensor_device;
> >>   };
> >>   
> >> -#define SUN4I_GPADC_ADC_CHANNEL(_channel, _name) {\
> >> -  .type = IIO_VOLTAGE,\
> >> -  .indexed = 1,   \
> >> -  .channel = _channel,\
> >> -  .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
> >> -  .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
> >> -  .datasheet_name = _name,\
> >> -}
> >> -
> >>   static struct iio_map sun4i_gpadc_hwmon_maps[] = {
> >>{
> >>.adc_channel_label = "temp_adc",
> >> diff --git a/include/linux/mfd/sun4i-gpadc.h 
> >> b/include/linux/mfd/sun4i-gpadc.h
> >> index 139872c2e0fe..54c7c9375c1b 100644
> >> --- a/include/linux/mfd/sun4i-gpadc.h
> >> +++ b/include/linux/mfd/sun4i-gpadc.h
> >> @@ -90,6 +90,15 @@
> >>   /* 10s delay before suspending the IP */
> >>   #define SUN4I_GPADC_AUTOSUSPEND_DELAY1
> >>   
> >> +#define SUN4I_GPADC_ADC_CHANNEL(_channel, _name) {\
> >> +  .type = IIO_VOLTAGE,\
> >> +  .indexed = 1,   \
> >> +  .channel = _channel,\
> >> +  .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
> >> +  .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
> >> +  .datasheet_name = _name,\
> >> +}
> >> +
> >>   struct sun4i_gpadc_dev {
> >>struct device   *dev;
> >>struct regmap   *regmap;  
> >   



[PATCH 4.14 161/165] power: generic-adc-battery: check for duplicate properties copied from iio channels

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: H. Nikolaus Schaller 

commit a427503edaaed9b75ed9746a654cece7e93e60a8 upstream.

If an iio channel defines a basic property, there are duplicate entries
in /sys/class/power/*/uevent.

So add a check to avoid duplicates. Since all channels may be duplicates,
we have to modify the related error check.

Signed-off-by: H. Nikolaus Schaller 
Cc: sta...@vger.kernel.org
Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO")
Signed-off-by: Sebastian Reichel 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/power/supply/generic-adc-battery.c |   15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -246,6 +246,7 @@ static int gab_probe(struct platform_dev
int ret = 0;
int chan;
int index = ARRAY_SIZE(gab_props);
+   bool any = false;
 
adc_bat = devm_kzalloc(>dev, sizeof(*adc_bat), GFP_KERNEL);
if (!adc_bat) {
@@ -292,12 +293,22 @@ static int gab_probe(struct platform_dev
adc_bat->channel[chan] = NULL;
} else {
/* copying properties for supported channels only */
-   psy_desc->properties[index++] = gab_dyn_props[chan];
+   int index2;
+
+   for (index2 = 0; index2 < index; index2++) {
+   if (psy_desc->properties[index2] ==
+   gab_dyn_props[chan])
+   break;  /* already known */
+   }
+   if (index2 == index)/* really new */
+   psy_desc->properties[index++] =
+   gab_dyn_props[chan];
+   any = true;
}
}
 
/* none of the channels are supported so let's bail out */
-   if (index == ARRAY_SIZE(gab_props)) {
+   if (!any) {
ret = -ENODEV;
goto second_mem_fail;
}




[PATCH 4.14 160/165] power: generic-adc-battery: fix out-of-bounds write when copying channel properties

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: H. Nikolaus Schaller 

commit 932d47448c3caa0fa99e84d7f5bc302aa286efd8 upstream.

We did have sporadic problems in the pinctrl framework during boot
where a pin group name unexpectedly became NULL leading to a NULL
dereference in strcmp.

Detailled analysis of the failing cases did reveal that there were
two devm allocated objects close to each other. The second one was
the affected group_desc in pinmux and the first one was the
psy_desc->properties buffer of the gab driver.

Review of the gab code showed that the address calculation for
one memcpy() is wrong. It does

properties + sizeof(type) * index

but C is defined to do the index multiplication already for
pointer + integer additions. Hence the factor was applied twice
and the memcpy() does write outside of the properties buffer.
Sometimes it happened to be the pinctrl and triggered the strcmp(NULL).

Anyways, it is overkill to use a memcpy() here instead of a simple
assignment, which is easier to read and has less risk for wrong
address calculations. So we change code to a simple assignment.

If we initialize the index to the first free location, we can even
remove the local variable 'properties'.

This bug seems to exist right from the beginning in 3.7-rc1 in

commit e60fea794e6e ("power: battery: Generic battery driver using IIO")

Signed-off-by: H. Nikolaus Schaller 
Cc: sta...@vger.kernel.org
Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO")
Signed-off-by: Sebastian Reichel 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/power/supply/generic-adc-battery.c |   14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -243,10 +243,9 @@ static int gab_probe(struct platform_dev
struct power_supply_desc *psy_desc;
struct power_supply_config psy_cfg = {};
struct gab_platform_data *pdata = pdev->dev.platform_data;
-   enum power_supply_property *properties;
int ret = 0;
int chan;
-   int index = 0;
+   int index = ARRAY_SIZE(gab_props);
 
adc_bat = devm_kzalloc(>dev, sizeof(*adc_bat), GFP_KERNEL);
if (!adc_bat) {
@@ -280,8 +279,6 @@ static int gab_probe(struct platform_dev
}
 
memcpy(psy_desc->properties, gab_props, sizeof(gab_props));
-   properties = (enum power_supply_property *)
-   ((char *)psy_desc->properties + sizeof(gab_props));
 
/*
 * getting channel from iio and copying the battery properties
@@ -295,15 +292,12 @@ static int gab_probe(struct platform_dev
adc_bat->channel[chan] = NULL;
} else {
/* copying properties for supported channels only */
-   memcpy(properties + sizeof(*(psy_desc->properties)) * 
index,
-   _dyn_props[chan],
-   sizeof(gab_dyn_props[chan]));
-   index++;
+   psy_desc->properties[index++] = gab_dyn_props[chan];
}
}
 
/* none of the channels are supported so let's bail out */
-   if (index == 0) {
+   if (index == ARRAY_SIZE(gab_props)) {
ret = -ENODEV;
goto second_mem_fail;
}
@@ -314,7 +308,7 @@ static int gab_probe(struct platform_dev
 * as come channels may be not be supported by the device.So
 * we need to take care of that.
 */
-   psy_desc->num_properties = ARRAY_SIZE(gab_props) + index;
+   psy_desc->num_properties = index;
 
adc_bat->psy = power_supply_register(>dev, psy_desc, _cfg);
if (IS_ERR(adc_bat->psy)) {




[PATCH 4.14 138/165] x86/spectre: Add missing family 6 check to microcode check

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Andi Kleen 

commit 1ab534e85c93945f7862378d8c8adcf408205b19 upstream.

The check for Spectre microcodes does not check for family 6, only the
model numbers.

Add a family 6 check to avoid ambiguity with other families.

Fixes: a5b296636453 ("x86/cpufeature: Blacklist SPEC_CTRL/PRED_CMD on early 
Spectre v2 microcodes")
Signed-off-by: Andi Kleen 
Signed-off-by: Thomas Gleixner 
Cc: x...@kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180824170351.34874-2-a...@firstfloor.org
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/cpu/intel.c |3 +++
 1 file changed, 3 insertions(+)

--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -150,6 +150,9 @@ static bool bad_spectre_microcode(struct
if (cpu_has(c, X86_FEATURE_HYPERVISOR))
return false;
 
+   if (c->x86 != 6)
+   return false;
+
for (i = 0; i < ARRAY_SIZE(spectre_bad_microcodes); i++) {
if (c->x86_model == spectre_bad_microcodes[i].model &&
c->x86_stepping == spectre_bad_microcodes[i].stepping)




[PATCH 4.14 137/165] x86/irqflags: Mark native_restore_fl extern inline

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Nick Desaulniers 

commit 1f59a4581b5ecfe9b4f049a7a2cf904d8352842d upstream.

This should have been marked extern inline in order to pick up the out
of line definition in arch/x86/kernel/irqflags.S.

Fixes: 208cbb325589 ("x86/irqflags: Provide a declaration for native_save_fl")
Reported-by: Ben Hutchings 
Signed-off-by: Nick Desaulniers 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Juergen Gross 
Cc: "H. Peter Anvin" 
Cc: Boris Ostrovsky 
Cc: Greg Kroah-Hartman 
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180827214011.55428-1-ndesaulni...@google.com
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/include/asm/irqflags.h |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -33,7 +33,8 @@ extern inline unsigned long native_save_
return flags;
 }
 
-static inline void native_restore_fl(unsigned long flags)
+extern inline void native_restore_fl(unsigned long flags);
+extern inline void native_restore_fl(unsigned long flags)
 {
asm volatile("push %0 ; popf"
 : /* no output */




[PATCH 4.14 162/165] watchdog: Mark watchdog touch functions as notrace

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Vincent Whitchurch 

commit cb9d7fd51d9fbb329d182423bd7b92d0f8cb0e01 upstream.

Some architectures need to use stop_machine() to patch functions for
ftrace, and the assumption is that the stopped CPUs do not make function
calls to traceable functions when they are in the stopped state.

Commit ce4f06dcbb5d ("stop_machine: Touch_nmi_watchdog() after
MULTI_STOP_PREPARE") added calls to the watchdog touch functions from
the stopped CPUs and those functions lack notrace annotations.  This
leads to crashes when enabling/disabling ftrace on ARM kernels built
with the Thumb-2 instruction set.

Fix it by adding the necessary notrace annotations.

Fixes: ce4f06dcbb5d ("stop_machine: Touch_nmi_watchdog() after 
MULTI_STOP_PREPARE")
Signed-off-by: Vincent Whitchurch 
Signed-off-by: Thomas Gleixner 
Cc: Peter Zijlstra 
Cc: o...@redhat.com
Cc: t...@kernel.org
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/r/20180821152507.18313-1-vincent.whitchu...@axis.com
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/watchdog.c |4 ++--
 kernel/watchdog_hld.c |2 +-
 kernel/workqueue.c|2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -265,7 +265,7 @@ static void __touch_watchdog(void)
  * entering idle state.  This should only be used for scheduler events.
  * Use touch_softlockup_watchdog() for everything else.
  */
-void touch_softlockup_watchdog_sched(void)
+notrace void touch_softlockup_watchdog_sched(void)
 {
/*
 * Preemption can be enabled.  It doesn't matter which CPU's timestamp
@@ -274,7 +274,7 @@ void touch_softlockup_watchdog_sched(voi
raw_cpu_write(watchdog_touch_ts, 0);
 }
 
-void touch_softlockup_watchdog(void)
+notrace void touch_softlockup_watchdog(void)
 {
touch_softlockup_watchdog_sched();
wq_watchdog_touch(raw_smp_processor_id());
--- a/kernel/watchdog_hld.c
+++ b/kernel/watchdog_hld.c
@@ -29,7 +29,7 @@ static struct cpumask dead_events_mask;
 static unsigned long hardlockup_allcpu_dumped;
 static atomic_t watchdog_cpus = ATOMIC_INIT(0);
 
-void arch_touch_nmi_watchdog(void)
+notrace void arch_touch_nmi_watchdog(void)
 {
/*
 * Using __raw here because some code paths have
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5484,7 +5484,7 @@ static void wq_watchdog_timer_fn(unsigne
mod_timer(_watchdog_timer, jiffies + thresh);
 }
 
-void wq_watchdog_touch(int cpu)
+notrace void wq_watchdog_touch(int cpu)
 {
if (cpu >= 0)
per_cpu(wq_watchdog_touched_cpu, cpu) = jiffies;




Re: [PATCH v3 05/30] iio: adc: move SUN4I_GPADC_CHANNEL define to header file

2018-09-03 Thread Jonathan Cameron
On Mon, 3 Sep 2018 16:24:32 +0200
Philipp Rossak  wrote:

> On 02.09.2018 22:01, Jonathan Cameron wrote:
> > On Thu, 30 Aug 2018 17:44:53 +0200
> > Philipp Rossak  wrote:
> >   
> >> We are moving the SUN4I_GPADC_CHANNEL define to the header file.  
> > Maxime has raised this point in other patches...
> > 
> > Why?  Obvious what but I have no idea why you are doing this.
> > 
> > Thanks,
> > 
> > Jonathan  
> There are two reasons:
> 1. Personal taste: I like to have the #define stuff in the header file.
> 2. When I started the rework I had to get some better overview, so I 
> moved it...
> 
> Since those two reasons are no good reasons to submit a patch I will 
> drop it and keep it in the *.c file.
Don't move it.

For a 'utility' type define like this that is just about cutting
down on code repetition it is nice to be able to see what it does near
to where it is used.

Also, as a general rule kernel style is to not put things in a header
unless they are needed in multiple files.  There are exceptions, but
it is generally felt keeping things local to where they are used
leads to easier to review code.

Jonathan
> 
> Philipp
> 
> >>
> >> Signed-off-by: Philipp Rossak 
> >> ---
> >>   drivers/iio/adc/sun4i-gpadc-iio.c | 9 -
> >>   include/linux/mfd/sun4i-gpadc.h   | 9 +
> >>   2 files changed, 9 insertions(+), 9 deletions(-)
> >>
> >> diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c 
> >> b/drivers/iio/adc/sun4i-gpadc-iio.c
> >> index d95dd0fde2a6..666329940e1e 100644
> >> --- a/drivers/iio/adc/sun4i-gpadc-iio.c
> >> +++ b/drivers/iio/adc/sun4i-gpadc-iio.c
> >> @@ -109,15 +109,6 @@ struct sun4i_gpadc_iio {
> >>struct device   *sensor_device;
> >>   };
> >>   
> >> -#define SUN4I_GPADC_ADC_CHANNEL(_channel, _name) {\
> >> -  .type = IIO_VOLTAGE,\
> >> -  .indexed = 1,   \
> >> -  .channel = _channel,\
> >> -  .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
> >> -  .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
> >> -  .datasheet_name = _name,\
> >> -}
> >> -
> >>   static struct iio_map sun4i_gpadc_hwmon_maps[] = {
> >>{
> >>.adc_channel_label = "temp_adc",
> >> diff --git a/include/linux/mfd/sun4i-gpadc.h 
> >> b/include/linux/mfd/sun4i-gpadc.h
> >> index 139872c2e0fe..54c7c9375c1b 100644
> >> --- a/include/linux/mfd/sun4i-gpadc.h
> >> +++ b/include/linux/mfd/sun4i-gpadc.h
> >> @@ -90,6 +90,15 @@
> >>   /* 10s delay before suspending the IP */
> >>   #define SUN4I_GPADC_AUTOSUSPEND_DELAY1
> >>   
> >> +#define SUN4I_GPADC_ADC_CHANNEL(_channel, _name) {\
> >> +  .type = IIO_VOLTAGE,\
> >> +  .indexed = 1,   \
> >> +  .channel = _channel,\
> >> +  .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
> >> +  .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
> >> +  .datasheet_name = _name,\
> >> +}
> >> +
> >>   struct sun4i_gpadc_dev {
> >>struct device   *dev;
> >>struct regmap   *regmap;  
> >   



[PATCH 4.14 161/165] power: generic-adc-battery: check for duplicate properties copied from iio channels

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: H. Nikolaus Schaller 

commit a427503edaaed9b75ed9746a654cece7e93e60a8 upstream.

If an iio channel defines a basic property, there are duplicate entries
in /sys/class/power/*/uevent.

So add a check to avoid duplicates. Since all channels may be duplicates,
we have to modify the related error check.

Signed-off-by: H. Nikolaus Schaller 
Cc: sta...@vger.kernel.org
Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO")
Signed-off-by: Sebastian Reichel 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/power/supply/generic-adc-battery.c |   15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -246,6 +246,7 @@ static int gab_probe(struct platform_dev
int ret = 0;
int chan;
int index = ARRAY_SIZE(gab_props);
+   bool any = false;
 
adc_bat = devm_kzalloc(>dev, sizeof(*adc_bat), GFP_KERNEL);
if (!adc_bat) {
@@ -292,12 +293,22 @@ static int gab_probe(struct platform_dev
adc_bat->channel[chan] = NULL;
} else {
/* copying properties for supported channels only */
-   psy_desc->properties[index++] = gab_dyn_props[chan];
+   int index2;
+
+   for (index2 = 0; index2 < index; index2++) {
+   if (psy_desc->properties[index2] ==
+   gab_dyn_props[chan])
+   break;  /* already known */
+   }
+   if (index2 == index)/* really new */
+   psy_desc->properties[index++] =
+   gab_dyn_props[chan];
+   any = true;
}
}
 
/* none of the channels are supported so let's bail out */
-   if (index == ARRAY_SIZE(gab_props)) {
+   if (!any) {
ret = -ENODEV;
goto second_mem_fail;
}




[PATCH 4.14 160/165] power: generic-adc-battery: fix out-of-bounds write when copying channel properties

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: H. Nikolaus Schaller 

commit 932d47448c3caa0fa99e84d7f5bc302aa286efd8 upstream.

We did have sporadic problems in the pinctrl framework during boot
where a pin group name unexpectedly became NULL leading to a NULL
dereference in strcmp.

Detailled analysis of the failing cases did reveal that there were
two devm allocated objects close to each other. The second one was
the affected group_desc in pinmux and the first one was the
psy_desc->properties buffer of the gab driver.

Review of the gab code showed that the address calculation for
one memcpy() is wrong. It does

properties + sizeof(type) * index

but C is defined to do the index multiplication already for
pointer + integer additions. Hence the factor was applied twice
and the memcpy() does write outside of the properties buffer.
Sometimes it happened to be the pinctrl and triggered the strcmp(NULL).

Anyways, it is overkill to use a memcpy() here instead of a simple
assignment, which is easier to read and has less risk for wrong
address calculations. So we change code to a simple assignment.

If we initialize the index to the first free location, we can even
remove the local variable 'properties'.

This bug seems to exist right from the beginning in 3.7-rc1 in

commit e60fea794e6e ("power: battery: Generic battery driver using IIO")

Signed-off-by: H. Nikolaus Schaller 
Cc: sta...@vger.kernel.org
Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO")
Signed-off-by: Sebastian Reichel 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/power/supply/generic-adc-battery.c |   14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -243,10 +243,9 @@ static int gab_probe(struct platform_dev
struct power_supply_desc *psy_desc;
struct power_supply_config psy_cfg = {};
struct gab_platform_data *pdata = pdev->dev.platform_data;
-   enum power_supply_property *properties;
int ret = 0;
int chan;
-   int index = 0;
+   int index = ARRAY_SIZE(gab_props);
 
adc_bat = devm_kzalloc(>dev, sizeof(*adc_bat), GFP_KERNEL);
if (!adc_bat) {
@@ -280,8 +279,6 @@ static int gab_probe(struct platform_dev
}
 
memcpy(psy_desc->properties, gab_props, sizeof(gab_props));
-   properties = (enum power_supply_property *)
-   ((char *)psy_desc->properties + sizeof(gab_props));
 
/*
 * getting channel from iio and copying the battery properties
@@ -295,15 +292,12 @@ static int gab_probe(struct platform_dev
adc_bat->channel[chan] = NULL;
} else {
/* copying properties for supported channels only */
-   memcpy(properties + sizeof(*(psy_desc->properties)) * 
index,
-   _dyn_props[chan],
-   sizeof(gab_dyn_props[chan]));
-   index++;
+   psy_desc->properties[index++] = gab_dyn_props[chan];
}
}
 
/* none of the channels are supported so let's bail out */
-   if (index == 0) {
+   if (index == ARRAY_SIZE(gab_props)) {
ret = -ENODEV;
goto second_mem_fail;
}
@@ -314,7 +308,7 @@ static int gab_probe(struct platform_dev
 * as come channels may be not be supported by the device.So
 * we need to take care of that.
 */
-   psy_desc->num_properties = ARRAY_SIZE(gab_props) + index;
+   psy_desc->num_properties = index;
 
adc_bat->psy = power_supply_register(>dev, psy_desc, _cfg);
if (IS_ERR(adc_bat->psy)) {




[PATCH 4.14 138/165] x86/spectre: Add missing family 6 check to microcode check

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Andi Kleen 

commit 1ab534e85c93945f7862378d8c8adcf408205b19 upstream.

The check for Spectre microcodes does not check for family 6, only the
model numbers.

Add a family 6 check to avoid ambiguity with other families.

Fixes: a5b296636453 ("x86/cpufeature: Blacklist SPEC_CTRL/PRED_CMD on early 
Spectre v2 microcodes")
Signed-off-by: Andi Kleen 
Signed-off-by: Thomas Gleixner 
Cc: x...@kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180824170351.34874-2-a...@firstfloor.org
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/cpu/intel.c |3 +++
 1 file changed, 3 insertions(+)

--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -150,6 +150,9 @@ static bool bad_spectre_microcode(struct
if (cpu_has(c, X86_FEATURE_HYPERVISOR))
return false;
 
+   if (c->x86 != 6)
+   return false;
+
for (i = 0; i < ARRAY_SIZE(spectre_bad_microcodes); i++) {
if (c->x86_model == spectre_bad_microcodes[i].model &&
c->x86_stepping == spectre_bad_microcodes[i].stepping)




[PATCH 4.14 164/165] gcc-plugins: Add include required by GCC release 8

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Valdis Kletnieks 

commit 80d172431696482d9acd8d2c4ea78fed8956e2a1 upstream.

GCC requires another #include to get the gcc-plugins to build cleanly.

Signed-off-by: Valdis Kletnieks 
Signed-off-by: Kees Cook 
Cc: Lance Albertson 
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/gcc-plugins/gcc-common.h |4 
 1 file changed, 4 insertions(+)

--- a/scripts/gcc-plugins/gcc-common.h
+++ b/scripts/gcc-plugins/gcc-common.h
@@ -97,6 +97,10 @@
 #include "predict.h"
 #include "ipa-utils.h"
 
+#if BUILDING_GCC_VERSION >= 8000
+#include "stringpool.h"
+#endif
+
 #if BUILDING_GCC_VERSION >= 4009
 #include "attribs.h"
 #include "varasm.h"




[PATCH 4.14 163/165] cdrom: Fix info leak/OOB read in cdrom_ioctl_drive_status

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Scott Bauer 

commit 8f3fafc9c2f0ece10832c25f7ffcb07c97a32ad4 upstream.

Like d88b6d04: "cdrom: information leak in cdrom_ioctl_media_changed()"

There is another cast from unsigned long to int which causes
a bounds check to fail with specially crafted input. The value is
then used as an index in the slot array in cdrom_slot_status().

Signed-off-by: Scott Bauer 
Signed-off-by: Scott Bauer 
Cc: sta...@vger.kernel.org
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/cdrom/cdrom.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2542,7 +2542,7 @@ static int cdrom_ioctl_drive_status(stru
if (!CDROM_CAN(CDC_SELECT_DISC) ||
(arg == CDSL_CURRENT || arg == CDSL_NONE))
return cdi->ops->drive_status(cdi, CDSL_CURRENT);
-   if (((int)arg >= cdi->capacity))
+   if (arg >= cdi->capacity)
return -EINVAL;
return cdrom_slot_status(cdi, arg);
 }




[PATCH 4.14 164/165] gcc-plugins: Add include required by GCC release 8

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Valdis Kletnieks 

commit 80d172431696482d9acd8d2c4ea78fed8956e2a1 upstream.

GCC requires another #include to get the gcc-plugins to build cleanly.

Signed-off-by: Valdis Kletnieks 
Signed-off-by: Kees Cook 
Cc: Lance Albertson 
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/gcc-plugins/gcc-common.h |4 
 1 file changed, 4 insertions(+)

--- a/scripts/gcc-plugins/gcc-common.h
+++ b/scripts/gcc-plugins/gcc-common.h
@@ -97,6 +97,10 @@
 #include "predict.h"
 #include "ipa-utils.h"
 
+#if BUILDING_GCC_VERSION >= 8000
+#include "stringpool.h"
+#endif
+
 #if BUILDING_GCC_VERSION >= 4009
 #include "attribs.h"
 #include "varasm.h"




[PATCH 4.14 163/165] cdrom: Fix info leak/OOB read in cdrom_ioctl_drive_status

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Scott Bauer 

commit 8f3fafc9c2f0ece10832c25f7ffcb07c97a32ad4 upstream.

Like d88b6d04: "cdrom: information leak in cdrom_ioctl_media_changed()"

There is another cast from unsigned long to int which causes
a bounds check to fail with specially crafted input. The value is
then used as an index in the slot array in cdrom_slot_status().

Signed-off-by: Scott Bauer 
Signed-off-by: Scott Bauer 
Cc: sta...@vger.kernel.org
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/cdrom/cdrom.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2542,7 +2542,7 @@ static int cdrom_ioctl_drive_status(stru
if (!CDROM_CAN(CDC_SELECT_DISC) ||
(arg == CDSL_CURRENT || arg == CDSL_NONE))
return cdi->ops->drive_status(cdi, CDSL_CURRENT);
-   if (((int)arg >= cdi->capacity))
+   if (arg >= cdi->capacity)
return -EINVAL;
return cdrom_slot_status(cdi, arg);
 }




[PATCH 4.14 152/165] MIPS: lib: Provide MIPS64r6 __multi3() for GCC < 7

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Paul Burton 

commit 690d9163bf4b8563a2682e619f938e6a0443947f upstream.

Some versions of GCC suboptimally generate calls to the __multi3()
intrinsic for MIPS64r6 builds, resulting in link failures due to the
missing function:

LD  vmlinux.o
MODPOST vmlinux.o
  kernel/bpf/verifier.o: In function `kmalloc_array':
  include/linux/slab.h:631: undefined reference to `__multi3'
  fs/select.o: In function `kmalloc_array':
  include/linux/slab.h:631: undefined reference to `__multi3'
  ...

We already have a workaround for this in which we provide the
instrinsic, but we do so selectively for GCC 7 only. Unfortunately the
issue occurs with older GCC versions too - it has been observed with
both GCC 5.4.0 & GCC 6.4.0.

MIPSr6 support was introduced in GCC 5, so all major GCC versions prior
to GCC 8 are affected and we extend our workaround accordingly to all
MIPS64r6 builds using GCC versions older than GCC 8.

Signed-off-by: Paul Burton 
Reported-by: Vladimir Kondratiev 
Fixes: ebabcf17bcd7 ("MIPS: Implement __multi3 for GCC7 MIPS64r6 builds")
Patchwork: https://patchwork.linux-mips.org/patch/20297/
Cc: James Hogan 
Cc: Ralf Baechle 
Cc: linux-m...@linux-mips.org
Cc: sta...@vger.kernel.org # 4.15+
Signed-off-by: Greg Kroah-Hartman 

diff --git a/arch/mips/lib/multi3.c b/arch/mips/lib/multi3.c
index 111ad475aa0c..4c2483f410c2 100644
--- a/arch/mips/lib/multi3.c
+++ b/arch/mips/lib/multi3.c
@@ -4,12 +4,12 @@
 #include "libgcc.h"
 
 /*
- * GCC 7 suboptimally generates __multi3 calls for mips64r6, so for that
- * specific case only we'll implement it here.
+ * GCC 7 & older can suboptimally generate __multi3 calls for mips64r6, so for
+ * that specific case only we implement that intrinsic here.
  *
  * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82981
  */
-#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPSR6) && (__GNUC__ == 7)
+#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPSR6) && (__GNUC__ < 8)
 
 /* multiply 64-bit values, low 64-bits returned */
 static inline long long notrace dmulu(long long a, long long b)




[PATCH 4.14 152/165] MIPS: lib: Provide MIPS64r6 __multi3() for GCC < 7

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Paul Burton 

commit 690d9163bf4b8563a2682e619f938e6a0443947f upstream.

Some versions of GCC suboptimally generate calls to the __multi3()
intrinsic for MIPS64r6 builds, resulting in link failures due to the
missing function:

LD  vmlinux.o
MODPOST vmlinux.o
  kernel/bpf/verifier.o: In function `kmalloc_array':
  include/linux/slab.h:631: undefined reference to `__multi3'
  fs/select.o: In function `kmalloc_array':
  include/linux/slab.h:631: undefined reference to `__multi3'
  ...

We already have a workaround for this in which we provide the
instrinsic, but we do so selectively for GCC 7 only. Unfortunately the
issue occurs with older GCC versions too - it has been observed with
both GCC 5.4.0 & GCC 6.4.0.

MIPSr6 support was introduced in GCC 5, so all major GCC versions prior
to GCC 8 are affected and we extend our workaround accordingly to all
MIPS64r6 builds using GCC versions older than GCC 8.

Signed-off-by: Paul Burton 
Reported-by: Vladimir Kondratiev 
Fixes: ebabcf17bcd7 ("MIPS: Implement __multi3 for GCC7 MIPS64r6 builds")
Patchwork: https://patchwork.linux-mips.org/patch/20297/
Cc: James Hogan 
Cc: Ralf Baechle 
Cc: linux-m...@linux-mips.org
Cc: sta...@vger.kernel.org # 4.15+
Signed-off-by: Greg Kroah-Hartman 

diff --git a/arch/mips/lib/multi3.c b/arch/mips/lib/multi3.c
index 111ad475aa0c..4c2483f410c2 100644
--- a/arch/mips/lib/multi3.c
+++ b/arch/mips/lib/multi3.c
@@ -4,12 +4,12 @@
 #include "libgcc.h"
 
 /*
- * GCC 7 suboptimally generates __multi3 calls for mips64r6, so for that
- * specific case only we'll implement it here.
+ * GCC 7 & older can suboptimally generate __multi3 calls for mips64r6, so for
+ * that specific case only we implement that intrinsic here.
  *
  * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82981
  */
-#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPSR6) && (__GNUC__ == 7)
+#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPSR6) && (__GNUC__ < 8)
 
 /* multiply 64-bit values, low 64-bits returned */
 static inline long long notrace dmulu(long long a, long long b)




[PATCH 4.14 159/165] PM / clk: signedness bug in of_pm_clk_add_clks()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Dan Carpenter 

commit 5e2e2f9f76e157063a656351728703cb02b068f1 upstream.

"count" needs to be signed for the error handling to work.  I made "i"
signed as well so they match.

Fixes: 02113ba93ea4 (PM / clk: Add support for obtaining clocks from 
device-tree)
Cc: 4.6+  # 4.6+
Signed-off-by: Dan Carpenter 
Signed-off-by: Rafael J. Wysocki 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/base/power/clock_ops.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -185,7 +185,7 @@ EXPORT_SYMBOL_GPL(of_pm_clk_add_clk);
 int of_pm_clk_add_clks(struct device *dev)
 {
struct clk **clks;
-   unsigned int i, count;
+   int i, count;
int ret;
 
if (!dev || !dev->of_node)




[PATCH 4.14 157/165] iscsi target: fix session creation failure handling

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Mike Christie 

commit 26abc916a898d34c5ad159315a2f683def3c upstream.

The problem is that iscsi_login_zero_tsih_s1 sets conn->sess early in
iscsi_login_set_conn_values. If the function fails later like when we
alloc the idr it does kfree(sess) and leaves the conn->sess pointer set.
iscsi_login_zero_tsih_s1 then returns -Exyz and we then call
iscsi_target_login_sess_out and access the freed memory.

This patch has iscsi_login_zero_tsih_s1 either completely setup the
session or completely tear it down, so later in
iscsi_target_login_sess_out we can just check for it being set to the
connection.

Cc: sta...@vger.kernel.org
Fixes: 0957627a9960 ("iscsi-target: Fix sess allocation leak in...")
Signed-off-by: Mike Christie 
Acked-by: Martin K. Petersen 
Signed-off-by: Matthew Wilcox 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/target/iscsi/iscsi_target_login.c |   35 ++
 1 file changed, 21 insertions(+), 14 deletions(-)

--- a/drivers/target/iscsi/iscsi_target_login.c
+++ b/drivers/target/iscsi/iscsi_target_login.c
@@ -345,8 +345,7 @@ static int iscsi_login_zero_tsih_s1(
pr_err("idr_alloc() for sess_idr failed\n");
iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
ISCSI_LOGIN_STATUS_NO_RESOURCES);
-   kfree(sess);
-   return -ENOMEM;
+   goto free_sess;
}
 
sess->creation_time = get_jiffies_64();
@@ -362,20 +361,28 @@ static int iscsi_login_zero_tsih_s1(
ISCSI_LOGIN_STATUS_NO_RESOURCES);
pr_err("Unable to allocate memory for"
" struct iscsi_sess_ops.\n");
-   kfree(sess);
-   return -ENOMEM;
+   goto remove_idr;
}
 
sess->se_sess = transport_init_session(TARGET_PROT_NORMAL);
if (IS_ERR(sess->se_sess)) {
iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
ISCSI_LOGIN_STATUS_NO_RESOURCES);
-   kfree(sess->sess_ops);
-   kfree(sess);
-   return -ENOMEM;
+   goto free_ops;
}
 
return 0;
+
+free_ops:
+   kfree(sess->sess_ops);
+remove_idr:
+   spin_lock_bh(_idr_lock);
+   idr_remove(_idr, sess->session_index);
+   spin_unlock_bh(_idr_lock);
+free_sess:
+   kfree(sess);
+   conn->sess = NULL;
+   return -ENOMEM;
 }
 
 static int iscsi_login_zero_tsih_s2(
@@ -1162,13 +1169,13 @@ void iscsi_target_login_sess_out(struct
   ISCSI_LOGIN_STATUS_INIT_ERR);
if (!zero_tsih || !conn->sess)
goto old_sess_out;
-   if (conn->sess->se_sess)
-   transport_free_session(conn->sess->se_sess);
-   if (conn->sess->session_index != 0) {
-   spin_lock_bh(_idr_lock);
-   idr_remove(_idr, conn->sess->session_index);
-   spin_unlock_bh(_idr_lock);
-   }
+
+   transport_free_session(conn->sess->se_sess);
+
+   spin_lock_bh(_idr_lock);
+   idr_remove(_idr, conn->sess->session_index);
+   spin_unlock_bh(_idr_lock);
+
kfree(conn->sess->sess_ops);
kfree(conn->sess);
conn->sess = NULL;




[PATCH 4.14 159/165] PM / clk: signedness bug in of_pm_clk_add_clks()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Dan Carpenter 

commit 5e2e2f9f76e157063a656351728703cb02b068f1 upstream.

"count" needs to be signed for the error handling to work.  I made "i"
signed as well so they match.

Fixes: 02113ba93ea4 (PM / clk: Add support for obtaining clocks from 
device-tree)
Cc: 4.6+  # 4.6+
Signed-off-by: Dan Carpenter 
Signed-off-by: Rafael J. Wysocki 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/base/power/clock_ops.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -185,7 +185,7 @@ EXPORT_SYMBOL_GPL(of_pm_clk_add_clk);
 int of_pm_clk_add_clks(struct device *dev)
 {
struct clk **clks;
-   unsigned int i, count;
+   int i, count;
int ret;
 
if (!dev || !dev->of_node)




[PATCH 4.14 157/165] iscsi target: fix session creation failure handling

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Mike Christie 

commit 26abc916a898d34c5ad159315a2f683def3c upstream.

The problem is that iscsi_login_zero_tsih_s1 sets conn->sess early in
iscsi_login_set_conn_values. If the function fails later like when we
alloc the idr it does kfree(sess) and leaves the conn->sess pointer set.
iscsi_login_zero_tsih_s1 then returns -Exyz and we then call
iscsi_target_login_sess_out and access the freed memory.

This patch has iscsi_login_zero_tsih_s1 either completely setup the
session or completely tear it down, so later in
iscsi_target_login_sess_out we can just check for it being set to the
connection.

Cc: sta...@vger.kernel.org
Fixes: 0957627a9960 ("iscsi-target: Fix sess allocation leak in...")
Signed-off-by: Mike Christie 
Acked-by: Martin K. Petersen 
Signed-off-by: Matthew Wilcox 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/target/iscsi/iscsi_target_login.c |   35 ++
 1 file changed, 21 insertions(+), 14 deletions(-)

--- a/drivers/target/iscsi/iscsi_target_login.c
+++ b/drivers/target/iscsi/iscsi_target_login.c
@@ -345,8 +345,7 @@ static int iscsi_login_zero_tsih_s1(
pr_err("idr_alloc() for sess_idr failed\n");
iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
ISCSI_LOGIN_STATUS_NO_RESOURCES);
-   kfree(sess);
-   return -ENOMEM;
+   goto free_sess;
}
 
sess->creation_time = get_jiffies_64();
@@ -362,20 +361,28 @@ static int iscsi_login_zero_tsih_s1(
ISCSI_LOGIN_STATUS_NO_RESOURCES);
pr_err("Unable to allocate memory for"
" struct iscsi_sess_ops.\n");
-   kfree(sess);
-   return -ENOMEM;
+   goto remove_idr;
}
 
sess->se_sess = transport_init_session(TARGET_PROT_NORMAL);
if (IS_ERR(sess->se_sess)) {
iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
ISCSI_LOGIN_STATUS_NO_RESOURCES);
-   kfree(sess->sess_ops);
-   kfree(sess);
-   return -ENOMEM;
+   goto free_ops;
}
 
return 0;
+
+free_ops:
+   kfree(sess->sess_ops);
+remove_idr:
+   spin_lock_bh(_idr_lock);
+   idr_remove(_idr, sess->session_index);
+   spin_unlock_bh(_idr_lock);
+free_sess:
+   kfree(sess);
+   conn->sess = NULL;
+   return -ENOMEM;
 }
 
 static int iscsi_login_zero_tsih_s2(
@@ -1162,13 +1169,13 @@ void iscsi_target_login_sess_out(struct
   ISCSI_LOGIN_STATUS_INIT_ERR);
if (!zero_tsih || !conn->sess)
goto old_sess_out;
-   if (conn->sess->se_sess)
-   transport_free_session(conn->sess->se_sess);
-   if (conn->sess->session_index != 0) {
-   spin_lock_bh(_idr_lock);
-   idr_remove(_idr, conn->sess->session_index);
-   spin_unlock_bh(_idr_lock);
-   }
+
+   transport_free_session(conn->sess->se_sess);
+
+   spin_lock_bh(_idr_lock);
+   idr_remove(_idr, conn->sess->session_index);
+   spin_unlock_bh(_idr_lock);
+
kfree(conn->sess->sess_ops);
kfree(conn->sess);
conn->sess = NULL;




[PATCH 4.14 156/165] scsi: core: Avoid that SCSI device removal through sysfs triggers a deadlock

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Bart Van Assche 

commit 0ee223b2e1f67cb2de9c0e3247c510d846e74d63 upstream.

A long time ago the unfortunate decision was taken to add a self-deletion
attribute to the sysfs SCSI device directory. That decision was unfortunate
because self-deletion is really tricky. We can't drop that attribute
because widely used user space software depends on it, namely the
rescan-scsi-bus.sh script. Hence this patch that avoids that writing into
that attribute triggers a deadlock. See also commit 7973cbd9fbd9 ("[PATCH]
add sysfs attributes to scan and delete scsi_devices").

This patch avoids that self-removal triggers the following deadlock:

==
WARNING: possible circular locking dependency detected
4.18.0-rc2-dbg+ #5 Not tainted
--
modprobe/6539 is trying to acquire lock:
8323c4cd (kn->count#202){}, at: kernfs_remove_by_name_ns+0x45/0x90

but task is already holding lock:
a6ec2c69 (>scan_mutex){+.+.}, at: scsi_remove_host+0x21/0x150 
[scsi_mod]

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 (>scan_mutex){+.+.}:
   __mutex_lock+0xfe/0xc70
   mutex_lock_nested+0x1b/0x20
   scsi_remove_device+0x26/0x40 [scsi_mod]
   sdev_store_delete+0x27/0x30 [scsi_mod]
   dev_attr_store+0x3e/0x50
   sysfs_kf_write+0x87/0xa0
   kernfs_fop_write+0x190/0x230
   __vfs_write+0xd2/0x3b0
   vfs_write+0x101/0x270
   ksys_write+0xab/0x120
   __x64_sys_write+0x43/0x50
   do_syscall_64+0x77/0x230
   entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #0 (kn->count#202){}:
   lock_acquire+0xd2/0x260
   __kernfs_remove+0x424/0x4a0
   kernfs_remove_by_name_ns+0x45/0x90
   remove_files.isra.1+0x3a/0x90
   sysfs_remove_group+0x5c/0xc0
   sysfs_remove_groups+0x39/0x60
   device_remove_attrs+0x82/0xb0
   device_del+0x251/0x580
   __scsi_remove_device+0x19f/0x1d0 [scsi_mod]
   scsi_forget_host+0x37/0xb0 [scsi_mod]
   scsi_remove_host+0x9b/0x150 [scsi_mod]
   sdebug_driver_remove+0x4b/0x150 [scsi_debug]
   device_release_driver_internal+0x241/0x360
   device_release_driver+0x12/0x20
   bus_remove_device+0x1bc/0x290
   device_del+0x259/0x580
   device_unregister+0x1a/0x70
   sdebug_remove_adapter+0x8b/0xf0 [scsi_debug]
   scsi_debug_exit+0x76/0xe8 [scsi_debug]
   __x64_sys_delete_module+0x1c1/0x280
   do_syscall_64+0x77/0x230
   entry_SYSCALL_64_after_hwframe+0x49/0xbe

other info that might help us debug this:

 Possible unsafe locking scenario:

   CPU0CPU1
   
  lock(>scan_mutex);
   lock(kn->count#202);
   lock(>scan_mutex);
  lock(kn->count#202);

 *** DEADLOCK ***

2 locks held by modprobe/6539:
 #0: efaf9298 (>mutex){}, at: 
device_release_driver_internal+0x68/0x360
 #1: a6ec2c69 (>scan_mutex){+.+.}, at: 
scsi_remove_host+0x21/0x150 [scsi_mod]

stack backtrace:
CPU: 10 PID: 6539 Comm: modprobe Not tainted 4.18.0-rc2-dbg+ #5
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 
1.0.0-prebuilt.qemu-project.org 04/01/2014
Call Trace:
 dump_stack+0xa4/0xf5
 print_circular_bug.isra.34+0x213/0x221
 __lock_acquire+0x1a7e/0x1b50
 lock_acquire+0xd2/0x260
 __kernfs_remove+0x424/0x4a0
 kernfs_remove_by_name_ns+0x45/0x90
 remove_files.isra.1+0x3a/0x90
 sysfs_remove_group+0x5c/0xc0
 sysfs_remove_groups+0x39/0x60
 device_remove_attrs+0x82/0xb0
 device_del+0x251/0x580
 __scsi_remove_device+0x19f/0x1d0 [scsi_mod]
 scsi_forget_host+0x37/0xb0 [scsi_mod]
 scsi_remove_host+0x9b/0x150 [scsi_mod]
 sdebug_driver_remove+0x4b/0x150 [scsi_debug]
 device_release_driver_internal+0x241/0x360
 device_release_driver+0x12/0x20
 bus_remove_device+0x1bc/0x290
 device_del+0x259/0x580
 device_unregister+0x1a/0x70
 sdebug_remove_adapter+0x8b/0xf0 [scsi_debug]
 scsi_debug_exit+0x76/0xe8 [scsi_debug]
 __x64_sys_delete_module+0x1c1/0x280
 do_syscall_64+0x77/0x230
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

See also https://www.mail-archive.com/linux-scsi@vger.kernel.org/msg54525.html.

Fixes: ac0ece9174ac ("scsi: use device_remove_file_self() instead of 
device_schedule_callback()")
Signed-off-by: Bart Van Assche 
Cc: Greg Kroah-Hartman 
Acked-by: Tejun Heo 
Cc: Johannes Thumshirn 
Cc: 
Signed-off-by: Greg Kroah-Hartman 

Signed-off-by: Martin K. Petersen 

---
 drivers/scsi/scsi_sysfs.c |   20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -721,8 +721,24 @@ static ssize_t
 sdev_store_delete(struct device *dev, struct device_attribute *attr,
  const char *buf, size_t count)
 {
-   if (device_remove_file_self(dev, attr))
- 

[PATCH 4.14 077/165] gpiolib-acpi: make sure we trigger edge events at least once on boot

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Benjamin Tissoires 

[ Upstream commit ca876c7483b697b498868b1f575997191b077885 ]

On some systems using edge triggered ACPI Event Interrupts, the initial
state at boot is not setup by the firmware, instead relying on the edge
irq event handler running at least once to setup the initial state.

2 known examples of this are:

1) The Surface 3 has its _LID state controlled by an ACPI operation region
 triggered by a GPIO event:

 OperationRegion (GPOR, GeneralPurposeIo, Zero, One)
 Field (GPOR, ByteAcc, NoLock, Preserve)
 {
 Connection (
 GpioIo (Shared, PullNone, 0x, 0x, IoRestrictionNone,
 "\\_SB.GPO0", 0x00, ResourceConsumer, ,
 )
 {   // Pin list
 0x004C
 }
 ),
 HELD,   1
 }

 Method (_E4C, 0, Serialized)  // _Exx: Edge-Triggered GPE
 {
 If ((HELD == One))
 {
 ^^LID.LIDB = One
 }
 Else
 {
 ^^LID.LIDB = Zero
 Notify (LID, 0x80) // Status Change
 }

 Notify (^^PCI0.SPI1.NTRG, One) // Device Check
 }

 Currently, the state of LIDB is wrong until the user actually closes or
 open the cover. We need to trigger the GPIO event once to update the
 internal ACPI state.

 Coincidentally, this also enables the Surface 2 integrated HID sensor hub
 which also requires an ACPI gpio operation region to start initialization.

2) Various Bay Trail based tablets come with an external USB mux and
 TI T1210B USB phy to enable USB gadget mode. The mux is controlled by a
 GPIO which is controlled by an edge triggered ACPI Event Interrupt which
 monitors the micro-USB ID pin.

 When the tablet is connected to a PC (or no cable is plugged in), the ID
 pin is high and the tablet should be in gadget mode. But the GPIO
 controlling the mux is initialized by the firmware so that the USB data
 lines are muxed to the host controller.

 This means that if the user wants to use gadget mode, the user needs to
 first plug in a host-cable to force the ID pin low and then unplug it
 and connect the tablet to a PC, to get the ACPI event handler to run and
 switch the mux to device mode,

This commit fixes both by running the event-handler once on boot.

Note that the running of the event-handler is done from a late_initcall,
this is done because the handler AML code may rely on OperationRegions
registered by other builtin drivers. This avoids errors like these:

[0.133026] ACPI Error: No handler for Region [XSCG] ((ptrval)) 
[GenericSerialBus] (20180531/evregion-132)
[0.133036] ACPI Error: Region GenericSerialBus (ID=9) has no handler 
(20180531/exfldio-265)
[0.133046] ACPI Error: Method parse/execution failed \_SB.GPO2._E12, 
AE_NOT_EXIST (20180531/psparse-516)

Signed-off-by: Benjamin Tissoires 
[hdegoede: Document BYT USB mux reliance on initial trigger]
[hdegoede: Run event handler from a late_initcall, rather then immediately]
Signed-off-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Acked-by: Mika Westerberg 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/gpio/gpiolib-acpi.c |   56 +++-
 1 file changed, 55 insertions(+), 1 deletion(-)

--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -25,6 +25,7 @@
 
 struct acpi_gpio_event {
struct list_head node;
+   struct list_head initial_sync_list;
acpi_handle handle;
unsigned int pin;
unsigned int irq;
@@ -50,6 +51,9 @@ struct acpi_gpio_chip {
struct list_head events;
 };
 
+static LIST_HEAD(acpi_gpio_initial_sync_list);
+static DEFINE_MUTEX(acpi_gpio_initial_sync_list_lock);
+
 static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
 {
if (!gc->parent)
@@ -142,6 +146,21 @@ static struct gpio_desc *acpi_get_gpiod(
return gpiochip_get_desc(chip, offset);
 }
 
+static void acpi_gpio_add_to_initial_sync_list(struct acpi_gpio_event *event)
+{
+   mutex_lock(_gpio_initial_sync_list_lock);
+   list_add(>initial_sync_list, _gpio_initial_sync_list);
+   mutex_unlock(_gpio_initial_sync_list_lock);
+}
+
+static void acpi_gpio_del_from_initial_sync_list(struct acpi_gpio_event *event)
+{
+   mutex_lock(_gpio_initial_sync_list_lock);
+   if (!list_empty(>initial_sync_list))
+   list_del_init(>initial_sync_list);
+   mutex_unlock(_gpio_initial_sync_list_lock);
+}
+
 static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
 {
struct acpi_gpio_event *event = data;
@@ -193,7 +212,7 @@ static acpi_status acpi_gpiochip_request
irq_handler_t handler = NULL;
struct gpio_desc *desc;
unsigned long irqflags;
-   int ret, pin, irq;
+   int ret, pin, irq, value;
 
if (!acpi_gpio_get_irq_resource(ares, ))
return AE_OK;
@@ -228,6 +247,8 @@ static acpi_status 

[PATCH 4.14 149/165] MIPS: Correct the 64-bit DSP accumulator register size

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Maciej W. Rozycki 

commit f5958b4cf4fc38ed4583ab83fb7c4cd1ab05f47b upstream.

Use the `unsigned long' rather than `__u32' type for DSP accumulator
registers, like with the regular MIPS multiply/divide accumulator and
general-purpose registers, as all are 64-bit in 64-bit implementations
and using a 32-bit data type leads to contents truncation on context
saving.

Update `arch_ptrace' and `compat_arch_ptrace' accordingly, removing
casts that are similarly not used with multiply/divide accumulator or
general-purpose register accesses.

Signed-off-by: Maciej W. Rozycki 
Signed-off-by: Paul Burton 
Fixes: e50c0a8fa60d ("Support the MIPS32 / MIPS64 DSP ASE.")
Patchwork: https://patchwork.linux-mips.org/patch/19329/
Cc: Alexander Viro 
Cc: James Hogan 
Cc: Ralf Baechle 
Cc: linux-fsde...@vger.kernel.org
Cc: linux-m...@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Cc: sta...@vger.kernel.org # 2.6.15+
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/include/asm/processor.h |2 +-
 arch/mips/kernel/ptrace.c |2 +-
 arch/mips/kernel/ptrace32.c   |2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

--- a/arch/mips/include/asm/processor.h
+++ b/arch/mips/include/asm/processor.h
@@ -141,7 +141,7 @@ struct mips_fpu_struct {
 
 #define NUM_DSP_REGS   6
 
-typedef __u32 dspreg_t;
+typedef unsigned long dspreg_t;
 
 struct mips_dsp_state {
dspreg_tdspr[NUM_DSP_REGS];
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -847,7 +847,7 @@ long arch_ptrace(struct task_struct *chi
goto out;
}
dregs = __get_dsp_regs(child);
-   tmp = (unsigned long) (dregs[addr - DSP_BASE]);
+   tmp = dregs[addr - DSP_BASE];
break;
}
case DSP_CONTROL:
--- a/arch/mips/kernel/ptrace32.c
+++ b/arch/mips/kernel/ptrace32.c
@@ -141,7 +141,7 @@ long compat_arch_ptrace(struct task_stru
goto out;
}
dregs = __get_dsp_regs(child);
-   tmp = (unsigned long) (dregs[addr - DSP_BASE]);
+   tmp = dregs[addr - DSP_BASE];
break;
}
case DSP_CONTROL:




[PATCH 4.14 158/165] clk: rockchip: fix clk_i2sout parent selection bits on rk3399

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Alberto Panizzo 

commit a64ad008980c65d38e6cf6858429c78e6b740c41 upstream.

Register, shift and mask were wrong according to datasheet.

Fixes: 115510053e5e ("clk: rockchip: add clock controller for the RK3399")
Cc: sta...@vger.kernel.org
Signed-off-by: Alberto Panizzo 
Signed-off-by: Anthony Brandon 
Signed-off-by: Heiko Stuebner 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/clk/rockchip/clk-rk3399.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/clk/rockchip/clk-rk3399.c
+++ b/drivers/clk/rockchip/clk-rk3399.c
@@ -630,7 +630,7 @@ static struct rockchip_clk_branch rk3399
MUX(0, "clk_i2sout_src", mux_i2sch_p, CLK_SET_RATE_PARENT,
RK3399_CLKSEL_CON(31), 0, 2, MFLAGS),
COMPOSITE_NODIV(SCLK_I2S_8CH_OUT, "clk_i2sout", mux_i2sout_p, 
CLK_SET_RATE_PARENT,
-   RK3399_CLKSEL_CON(30), 8, 2, MFLAGS,
+   RK3399_CLKSEL_CON(31), 2, 1, MFLAGS,
RK3399_CLKGATE_CON(8), 12, GFLAGS),
 
/* uart */




[PATCH 4.14 155/165] scsi: sysfs: Introduce sysfs_{un,}break_active_protection()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Bart Van Assche 

commit 2afc9166f79b8f6da5f347f48515215ceee4ae37 upstream.

Introduce these two functions and export them such that the next patch
can add calls to these functions from the SCSI core.

Signed-off-by: Bart Van Assche 
Acked-by: Tejun Heo 
Acked-by: Greg Kroah-Hartman 
Cc: 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/sysfs/file.c   |   44 
 include/linux/sysfs.h |   14 ++
 2 files changed, 58 insertions(+)

--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -408,6 +408,50 @@ int sysfs_chmod_file(struct kobject *kob
 EXPORT_SYMBOL_GPL(sysfs_chmod_file);
 
 /**
+ * sysfs_break_active_protection - break "active" protection
+ * @kobj: The kernel object @attr is associated with.
+ * @attr: The attribute to break the "active" protection for.
+ *
+ * With sysfs, just like kernfs, deletion of an attribute is postponed until
+ * all active .show() and .store() callbacks have finished unless this function
+ * is called. Hence this function is useful in methods that implement self
+ * deletion.
+ */
+struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
+ const struct attribute *attr)
+{
+   struct kernfs_node *kn;
+
+   kobject_get(kobj);
+   kn = kernfs_find_and_get(kobj->sd, attr->name);
+   if (kn)
+   kernfs_break_active_protection(kn);
+   return kn;
+}
+EXPORT_SYMBOL_GPL(sysfs_break_active_protection);
+
+/**
+ * sysfs_unbreak_active_protection - restore "active" protection
+ * @kn: Pointer returned by sysfs_break_active_protection().
+ *
+ * Undo the effects of sysfs_break_active_protection(). Since this function
+ * calls kernfs_put() on the kernfs node that corresponds to the 'attr'
+ * argument passed to sysfs_break_active_protection() that attribute may have
+ * been removed between the sysfs_break_active_protection() and
+ * sysfs_unbreak_active_protection() calls, it is not safe to access @kn after
+ * this function has returned.
+ */
+void sysfs_unbreak_active_protection(struct kernfs_node *kn)
+{
+   struct kobject *kobj = kn->parent->priv;
+
+   kernfs_unbreak_active_protection(kn);
+   kernfs_put(kn);
+   kobject_put(kobj);
+}
+EXPORT_SYMBOL_GPL(sysfs_unbreak_active_protection);
+
+/**
  * sysfs_remove_file_ns - remove an object attribute with a custom ns tag
  * @kobj: object we're acting for
  * @attr: attribute descriptor
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -239,6 +239,9 @@ int __must_check sysfs_create_files(stru
   const struct attribute **attr);
 int __must_check sysfs_chmod_file(struct kobject *kobj,
  const struct attribute *attr, umode_t mode);
+struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
+ const struct attribute *attr);
+void sysfs_unbreak_active_protection(struct kernfs_node *kn);
 void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
  const void *ns);
 bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute 
*attr);
@@ -352,6 +355,17 @@ static inline int sysfs_chmod_file(struc
return 0;
 }
 
+static inline struct kernfs_node *
+sysfs_break_active_protection(struct kobject *kobj,
+ const struct attribute *attr)
+{
+   return NULL;
+}
+
+static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn)
+{
+}
+
 static inline void sysfs_remove_file_ns(struct kobject *kobj,
const struct attribute *attr,
const void *ns)




[PATCH 4.14 153/165] tpm: Return the actual size when receiving an unsupported command

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Ricardo Schwarzmeier 

commit 36a11029b07ee30bdc4553274d0efea645ed9d91 upstream.

The userpace expects to read the number of bytes stated in the header.
Returning the size of the buffer instead would be unexpected.

Cc: sta...@vger.kernel.org
Fixes: 095531f891e6 ("tpm: return a TPM_RC_COMMAND_CODE response if command is 
not implemented")
Signed-off-by: Ricardo Schwarzmeier 
Reviewed-by: Jarkko Sakkinen 
Signed-off-by: Jarkko Sakkinen 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/char/tpm/tpm-interface.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -423,7 +423,7 @@ static ssize_t tpm_try_transmit(struct t
header->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS);
header->return_code = cpu_to_be32(TPM2_RC_COMMAND_CODE |
  TSS2_RESMGR_TPM_RC_LAYER);
-   return bufsiz;
+   return sizeof(*header);
}
 
if (bufsiz > TPM_BUFSIZE)




[PATCH 4.14 154/165] scsi: mpt3sas: Fix _transport_smp_handler() error path

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Bart Van Assche 

commit 91b7bdb2c0089cbbb817df6888ab1458c645184e upstream.

This patch avoids that smatch complains about a double unlock on
ioc->transport_cmds.mutex.

Fixes: 651a01364994 ("scsi: scsi_transport_sas: switch to bsg-lib for SMP 
passthrough")
Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Sathya Prakash 
Cc: Chaitra P B 
Cc: Suganath Prabu Subramani 
Cc: sta...@vger.kernel.org
Reviewed-by: Christoph Hellwig 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/scsi/mpt3sas/mpt3sas_transport.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
@@ -1936,12 +1936,12 @@ _transport_smp_handler(struct bsg_job *j
pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
__func__, ioc->name);
rc = -EFAULT;
-   goto out;
+   goto job_done;
}
 
rc = mutex_lock_interruptible(>transport_cmds.mutex);
if (rc)
-   goto out;
+   goto job_done;
 
if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n", ioc->name,
@@ -2066,6 +2066,7 @@ _transport_smp_handler(struct bsg_job *j
  out:
ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
mutex_unlock(>transport_cmds.mutex);
+job_done:
bsg_job_done(job, rc, reslen);
 }
 




[PATCH 4.14 156/165] scsi: core: Avoid that SCSI device removal through sysfs triggers a deadlock

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Bart Van Assche 

commit 0ee223b2e1f67cb2de9c0e3247c510d846e74d63 upstream.

A long time ago the unfortunate decision was taken to add a self-deletion
attribute to the sysfs SCSI device directory. That decision was unfortunate
because self-deletion is really tricky. We can't drop that attribute
because widely used user space software depends on it, namely the
rescan-scsi-bus.sh script. Hence this patch that avoids that writing into
that attribute triggers a deadlock. See also commit 7973cbd9fbd9 ("[PATCH]
add sysfs attributes to scan and delete scsi_devices").

This patch avoids that self-removal triggers the following deadlock:

==
WARNING: possible circular locking dependency detected
4.18.0-rc2-dbg+ #5 Not tainted
--
modprobe/6539 is trying to acquire lock:
8323c4cd (kn->count#202){}, at: kernfs_remove_by_name_ns+0x45/0x90

but task is already holding lock:
a6ec2c69 (>scan_mutex){+.+.}, at: scsi_remove_host+0x21/0x150 
[scsi_mod]

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 (>scan_mutex){+.+.}:
   __mutex_lock+0xfe/0xc70
   mutex_lock_nested+0x1b/0x20
   scsi_remove_device+0x26/0x40 [scsi_mod]
   sdev_store_delete+0x27/0x30 [scsi_mod]
   dev_attr_store+0x3e/0x50
   sysfs_kf_write+0x87/0xa0
   kernfs_fop_write+0x190/0x230
   __vfs_write+0xd2/0x3b0
   vfs_write+0x101/0x270
   ksys_write+0xab/0x120
   __x64_sys_write+0x43/0x50
   do_syscall_64+0x77/0x230
   entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #0 (kn->count#202){}:
   lock_acquire+0xd2/0x260
   __kernfs_remove+0x424/0x4a0
   kernfs_remove_by_name_ns+0x45/0x90
   remove_files.isra.1+0x3a/0x90
   sysfs_remove_group+0x5c/0xc0
   sysfs_remove_groups+0x39/0x60
   device_remove_attrs+0x82/0xb0
   device_del+0x251/0x580
   __scsi_remove_device+0x19f/0x1d0 [scsi_mod]
   scsi_forget_host+0x37/0xb0 [scsi_mod]
   scsi_remove_host+0x9b/0x150 [scsi_mod]
   sdebug_driver_remove+0x4b/0x150 [scsi_debug]
   device_release_driver_internal+0x241/0x360
   device_release_driver+0x12/0x20
   bus_remove_device+0x1bc/0x290
   device_del+0x259/0x580
   device_unregister+0x1a/0x70
   sdebug_remove_adapter+0x8b/0xf0 [scsi_debug]
   scsi_debug_exit+0x76/0xe8 [scsi_debug]
   __x64_sys_delete_module+0x1c1/0x280
   do_syscall_64+0x77/0x230
   entry_SYSCALL_64_after_hwframe+0x49/0xbe

other info that might help us debug this:

 Possible unsafe locking scenario:

   CPU0CPU1
   
  lock(>scan_mutex);
   lock(kn->count#202);
   lock(>scan_mutex);
  lock(kn->count#202);

 *** DEADLOCK ***

2 locks held by modprobe/6539:
 #0: efaf9298 (>mutex){}, at: 
device_release_driver_internal+0x68/0x360
 #1: a6ec2c69 (>scan_mutex){+.+.}, at: 
scsi_remove_host+0x21/0x150 [scsi_mod]

stack backtrace:
CPU: 10 PID: 6539 Comm: modprobe Not tainted 4.18.0-rc2-dbg+ #5
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 
1.0.0-prebuilt.qemu-project.org 04/01/2014
Call Trace:
 dump_stack+0xa4/0xf5
 print_circular_bug.isra.34+0x213/0x221
 __lock_acquire+0x1a7e/0x1b50
 lock_acquire+0xd2/0x260
 __kernfs_remove+0x424/0x4a0
 kernfs_remove_by_name_ns+0x45/0x90
 remove_files.isra.1+0x3a/0x90
 sysfs_remove_group+0x5c/0xc0
 sysfs_remove_groups+0x39/0x60
 device_remove_attrs+0x82/0xb0
 device_del+0x251/0x580
 __scsi_remove_device+0x19f/0x1d0 [scsi_mod]
 scsi_forget_host+0x37/0xb0 [scsi_mod]
 scsi_remove_host+0x9b/0x150 [scsi_mod]
 sdebug_driver_remove+0x4b/0x150 [scsi_debug]
 device_release_driver_internal+0x241/0x360
 device_release_driver+0x12/0x20
 bus_remove_device+0x1bc/0x290
 device_del+0x259/0x580
 device_unregister+0x1a/0x70
 sdebug_remove_adapter+0x8b/0xf0 [scsi_debug]
 scsi_debug_exit+0x76/0xe8 [scsi_debug]
 __x64_sys_delete_module+0x1c1/0x280
 do_syscall_64+0x77/0x230
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

See also https://www.mail-archive.com/linux-scsi@vger.kernel.org/msg54525.html.

Fixes: ac0ece9174ac ("scsi: use device_remove_file_self() instead of 
device_schedule_callback()")
Signed-off-by: Bart Van Assche 
Cc: Greg Kroah-Hartman 
Acked-by: Tejun Heo 
Cc: Johannes Thumshirn 
Cc: 
Signed-off-by: Greg Kroah-Hartman 

Signed-off-by: Martin K. Petersen 

---
 drivers/scsi/scsi_sysfs.c |   20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -721,8 +721,24 @@ static ssize_t
 sdev_store_delete(struct device *dev, struct device_attribute *attr,
  const char *buf, size_t count)
 {
-   if (device_remove_file_self(dev, attr))
- 

[PATCH 4.14 077/165] gpiolib-acpi: make sure we trigger edge events at least once on boot

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Benjamin Tissoires 

[ Upstream commit ca876c7483b697b498868b1f575997191b077885 ]

On some systems using edge triggered ACPI Event Interrupts, the initial
state at boot is not setup by the firmware, instead relying on the edge
irq event handler running at least once to setup the initial state.

2 known examples of this are:

1) The Surface 3 has its _LID state controlled by an ACPI operation region
 triggered by a GPIO event:

 OperationRegion (GPOR, GeneralPurposeIo, Zero, One)
 Field (GPOR, ByteAcc, NoLock, Preserve)
 {
 Connection (
 GpioIo (Shared, PullNone, 0x, 0x, IoRestrictionNone,
 "\\_SB.GPO0", 0x00, ResourceConsumer, ,
 )
 {   // Pin list
 0x004C
 }
 ),
 HELD,   1
 }

 Method (_E4C, 0, Serialized)  // _Exx: Edge-Triggered GPE
 {
 If ((HELD == One))
 {
 ^^LID.LIDB = One
 }
 Else
 {
 ^^LID.LIDB = Zero
 Notify (LID, 0x80) // Status Change
 }

 Notify (^^PCI0.SPI1.NTRG, One) // Device Check
 }

 Currently, the state of LIDB is wrong until the user actually closes or
 open the cover. We need to trigger the GPIO event once to update the
 internal ACPI state.

 Coincidentally, this also enables the Surface 2 integrated HID sensor hub
 which also requires an ACPI gpio operation region to start initialization.

2) Various Bay Trail based tablets come with an external USB mux and
 TI T1210B USB phy to enable USB gadget mode. The mux is controlled by a
 GPIO which is controlled by an edge triggered ACPI Event Interrupt which
 monitors the micro-USB ID pin.

 When the tablet is connected to a PC (or no cable is plugged in), the ID
 pin is high and the tablet should be in gadget mode. But the GPIO
 controlling the mux is initialized by the firmware so that the USB data
 lines are muxed to the host controller.

 This means that if the user wants to use gadget mode, the user needs to
 first plug in a host-cable to force the ID pin low and then unplug it
 and connect the tablet to a PC, to get the ACPI event handler to run and
 switch the mux to device mode,

This commit fixes both by running the event-handler once on boot.

Note that the running of the event-handler is done from a late_initcall,
this is done because the handler AML code may rely on OperationRegions
registered by other builtin drivers. This avoids errors like these:

[0.133026] ACPI Error: No handler for Region [XSCG] ((ptrval)) 
[GenericSerialBus] (20180531/evregion-132)
[0.133036] ACPI Error: Region GenericSerialBus (ID=9) has no handler 
(20180531/exfldio-265)
[0.133046] ACPI Error: Method parse/execution failed \_SB.GPO2._E12, 
AE_NOT_EXIST (20180531/psparse-516)

Signed-off-by: Benjamin Tissoires 
[hdegoede: Document BYT USB mux reliance on initial trigger]
[hdegoede: Run event handler from a late_initcall, rather then immediately]
Signed-off-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Acked-by: Mika Westerberg 
Signed-off-by: Linus Walleij 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/gpio/gpiolib-acpi.c |   56 +++-
 1 file changed, 55 insertions(+), 1 deletion(-)

--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -25,6 +25,7 @@
 
 struct acpi_gpio_event {
struct list_head node;
+   struct list_head initial_sync_list;
acpi_handle handle;
unsigned int pin;
unsigned int irq;
@@ -50,6 +51,9 @@ struct acpi_gpio_chip {
struct list_head events;
 };
 
+static LIST_HEAD(acpi_gpio_initial_sync_list);
+static DEFINE_MUTEX(acpi_gpio_initial_sync_list_lock);
+
 static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
 {
if (!gc->parent)
@@ -142,6 +146,21 @@ static struct gpio_desc *acpi_get_gpiod(
return gpiochip_get_desc(chip, offset);
 }
 
+static void acpi_gpio_add_to_initial_sync_list(struct acpi_gpio_event *event)
+{
+   mutex_lock(_gpio_initial_sync_list_lock);
+   list_add(>initial_sync_list, _gpio_initial_sync_list);
+   mutex_unlock(_gpio_initial_sync_list_lock);
+}
+
+static void acpi_gpio_del_from_initial_sync_list(struct acpi_gpio_event *event)
+{
+   mutex_lock(_gpio_initial_sync_list_lock);
+   if (!list_empty(>initial_sync_list))
+   list_del_init(>initial_sync_list);
+   mutex_unlock(_gpio_initial_sync_list_lock);
+}
+
 static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
 {
struct acpi_gpio_event *event = data;
@@ -193,7 +212,7 @@ static acpi_status acpi_gpiochip_request
irq_handler_t handler = NULL;
struct gpio_desc *desc;
unsigned long irqflags;
-   int ret, pin, irq;
+   int ret, pin, irq, value;
 
if (!acpi_gpio_get_irq_resource(ares, ))
return AE_OK;
@@ -228,6 +247,8 @@ static acpi_status 

[PATCH 4.14 149/165] MIPS: Correct the 64-bit DSP accumulator register size

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Maciej W. Rozycki 

commit f5958b4cf4fc38ed4583ab83fb7c4cd1ab05f47b upstream.

Use the `unsigned long' rather than `__u32' type for DSP accumulator
registers, like with the regular MIPS multiply/divide accumulator and
general-purpose registers, as all are 64-bit in 64-bit implementations
and using a 32-bit data type leads to contents truncation on context
saving.

Update `arch_ptrace' and `compat_arch_ptrace' accordingly, removing
casts that are similarly not used with multiply/divide accumulator or
general-purpose register accesses.

Signed-off-by: Maciej W. Rozycki 
Signed-off-by: Paul Burton 
Fixes: e50c0a8fa60d ("Support the MIPS32 / MIPS64 DSP ASE.")
Patchwork: https://patchwork.linux-mips.org/patch/19329/
Cc: Alexander Viro 
Cc: James Hogan 
Cc: Ralf Baechle 
Cc: linux-fsde...@vger.kernel.org
Cc: linux-m...@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Cc: sta...@vger.kernel.org # 2.6.15+
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/include/asm/processor.h |2 +-
 arch/mips/kernel/ptrace.c |2 +-
 arch/mips/kernel/ptrace32.c   |2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

--- a/arch/mips/include/asm/processor.h
+++ b/arch/mips/include/asm/processor.h
@@ -141,7 +141,7 @@ struct mips_fpu_struct {
 
 #define NUM_DSP_REGS   6
 
-typedef __u32 dspreg_t;
+typedef unsigned long dspreg_t;
 
 struct mips_dsp_state {
dspreg_tdspr[NUM_DSP_REGS];
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -847,7 +847,7 @@ long arch_ptrace(struct task_struct *chi
goto out;
}
dregs = __get_dsp_regs(child);
-   tmp = (unsigned long) (dregs[addr - DSP_BASE]);
+   tmp = dregs[addr - DSP_BASE];
break;
}
case DSP_CONTROL:
--- a/arch/mips/kernel/ptrace32.c
+++ b/arch/mips/kernel/ptrace32.c
@@ -141,7 +141,7 @@ long compat_arch_ptrace(struct task_stru
goto out;
}
dregs = __get_dsp_regs(child);
-   tmp = (unsigned long) (dregs[addr - DSP_BASE]);
+   tmp = dregs[addr - DSP_BASE];
break;
}
case DSP_CONTROL:




[PATCH 4.14 158/165] clk: rockchip: fix clk_i2sout parent selection bits on rk3399

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Alberto Panizzo 

commit a64ad008980c65d38e6cf6858429c78e6b740c41 upstream.

Register, shift and mask were wrong according to datasheet.

Fixes: 115510053e5e ("clk: rockchip: add clock controller for the RK3399")
Cc: sta...@vger.kernel.org
Signed-off-by: Alberto Panizzo 
Signed-off-by: Anthony Brandon 
Signed-off-by: Heiko Stuebner 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/clk/rockchip/clk-rk3399.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/clk/rockchip/clk-rk3399.c
+++ b/drivers/clk/rockchip/clk-rk3399.c
@@ -630,7 +630,7 @@ static struct rockchip_clk_branch rk3399
MUX(0, "clk_i2sout_src", mux_i2sch_p, CLK_SET_RATE_PARENT,
RK3399_CLKSEL_CON(31), 0, 2, MFLAGS),
COMPOSITE_NODIV(SCLK_I2S_8CH_OUT, "clk_i2sout", mux_i2sout_p, 
CLK_SET_RATE_PARENT,
-   RK3399_CLKSEL_CON(30), 8, 2, MFLAGS,
+   RK3399_CLKSEL_CON(31), 2, 1, MFLAGS,
RK3399_CLKGATE_CON(8), 12, GFLAGS),
 
/* uart */




[PATCH 4.14 155/165] scsi: sysfs: Introduce sysfs_{un,}break_active_protection()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Bart Van Assche 

commit 2afc9166f79b8f6da5f347f48515215ceee4ae37 upstream.

Introduce these two functions and export them such that the next patch
can add calls to these functions from the SCSI core.

Signed-off-by: Bart Van Assche 
Acked-by: Tejun Heo 
Acked-by: Greg Kroah-Hartman 
Cc: 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/sysfs/file.c   |   44 
 include/linux/sysfs.h |   14 ++
 2 files changed, 58 insertions(+)

--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -408,6 +408,50 @@ int sysfs_chmod_file(struct kobject *kob
 EXPORT_SYMBOL_GPL(sysfs_chmod_file);
 
 /**
+ * sysfs_break_active_protection - break "active" protection
+ * @kobj: The kernel object @attr is associated with.
+ * @attr: The attribute to break the "active" protection for.
+ *
+ * With sysfs, just like kernfs, deletion of an attribute is postponed until
+ * all active .show() and .store() callbacks have finished unless this function
+ * is called. Hence this function is useful in methods that implement self
+ * deletion.
+ */
+struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
+ const struct attribute *attr)
+{
+   struct kernfs_node *kn;
+
+   kobject_get(kobj);
+   kn = kernfs_find_and_get(kobj->sd, attr->name);
+   if (kn)
+   kernfs_break_active_protection(kn);
+   return kn;
+}
+EXPORT_SYMBOL_GPL(sysfs_break_active_protection);
+
+/**
+ * sysfs_unbreak_active_protection - restore "active" protection
+ * @kn: Pointer returned by sysfs_break_active_protection().
+ *
+ * Undo the effects of sysfs_break_active_protection(). Since this function
+ * calls kernfs_put() on the kernfs node that corresponds to the 'attr'
+ * argument passed to sysfs_break_active_protection() that attribute may have
+ * been removed between the sysfs_break_active_protection() and
+ * sysfs_unbreak_active_protection() calls, it is not safe to access @kn after
+ * this function has returned.
+ */
+void sysfs_unbreak_active_protection(struct kernfs_node *kn)
+{
+   struct kobject *kobj = kn->parent->priv;
+
+   kernfs_unbreak_active_protection(kn);
+   kernfs_put(kn);
+   kobject_put(kobj);
+}
+EXPORT_SYMBOL_GPL(sysfs_unbreak_active_protection);
+
+/**
  * sysfs_remove_file_ns - remove an object attribute with a custom ns tag
  * @kobj: object we're acting for
  * @attr: attribute descriptor
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -239,6 +239,9 @@ int __must_check sysfs_create_files(stru
   const struct attribute **attr);
 int __must_check sysfs_chmod_file(struct kobject *kobj,
  const struct attribute *attr, umode_t mode);
+struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
+ const struct attribute *attr);
+void sysfs_unbreak_active_protection(struct kernfs_node *kn);
 void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
  const void *ns);
 bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute 
*attr);
@@ -352,6 +355,17 @@ static inline int sysfs_chmod_file(struc
return 0;
 }
 
+static inline struct kernfs_node *
+sysfs_break_active_protection(struct kobject *kobj,
+ const struct attribute *attr)
+{
+   return NULL;
+}
+
+static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn)
+{
+}
+
 static inline void sysfs_remove_file_ns(struct kobject *kobj,
const struct attribute *attr,
const void *ns)




[PATCH 4.14 153/165] tpm: Return the actual size when receiving an unsupported command

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Ricardo Schwarzmeier 

commit 36a11029b07ee30bdc4553274d0efea645ed9d91 upstream.

The userpace expects to read the number of bytes stated in the header.
Returning the size of the buffer instead would be unexpected.

Cc: sta...@vger.kernel.org
Fixes: 095531f891e6 ("tpm: return a TPM_RC_COMMAND_CODE response if command is 
not implemented")
Signed-off-by: Ricardo Schwarzmeier 
Reviewed-by: Jarkko Sakkinen 
Signed-off-by: Jarkko Sakkinen 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/char/tpm/tpm-interface.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -423,7 +423,7 @@ static ssize_t tpm_try_transmit(struct t
header->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS);
header->return_code = cpu_to_be32(TPM2_RC_COMMAND_CODE |
  TSS2_RESMGR_TPM_RC_LAYER);
-   return bufsiz;
+   return sizeof(*header);
}
 
if (bufsiz > TPM_BUFSIZE)




[PATCH 4.14 154/165] scsi: mpt3sas: Fix _transport_smp_handler() error path

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Bart Van Assche 

commit 91b7bdb2c0089cbbb817df6888ab1458c645184e upstream.

This patch avoids that smatch complains about a double unlock on
ioc->transport_cmds.mutex.

Fixes: 651a01364994 ("scsi: scsi_transport_sas: switch to bsg-lib for SMP 
passthrough")
Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Sathya Prakash 
Cc: Chaitra P B 
Cc: Suganath Prabu Subramani 
Cc: sta...@vger.kernel.org
Reviewed-by: Christoph Hellwig 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/scsi/mpt3sas/mpt3sas_transport.c |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
@@ -1936,12 +1936,12 @@ _transport_smp_handler(struct bsg_job *j
pr_info(MPT3SAS_FMT "%s: host reset in progress!\n",
__func__, ioc->name);
rc = -EFAULT;
-   goto out;
+   goto job_done;
}
 
rc = mutex_lock_interruptible(>transport_cmds.mutex);
if (rc)
-   goto out;
+   goto job_done;
 
if (ioc->transport_cmds.status != MPT3_CMD_NOT_USED) {
pr_err(MPT3SAS_FMT "%s: transport_cmds in use\n", ioc->name,
@@ -2066,6 +2066,7 @@ _transport_smp_handler(struct bsg_job *j
  out:
ioc->transport_cmds.status = MPT3_CMD_NOT_USED;
mutex_unlock(>transport_cmds.mutex);
+job_done:
bsg_job_done(job, rc, reslen);
 }
 




[PATCH 4.14 150/165] MIPS: Always use -march=, not - shortcuts

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Paul Burton 

commit 344ebf09949c31bcb8818d8458b65add29f1d67b upstream.

The VDSO Makefile filters CFLAGS to select a subset which it uses whilst
building the VDSO ELF. One of the flags it allows through is the -march=
flag that selects the architecture/ISA to target.

Unfortunately in cases where CONFIG_CPU_MIPS32_R{1,2}=y and the
toolchain defaults to building for MIPS64, the main MIPS Makefile ends
up using the short-form - flags in cflags-y. This is because the
calls to cc-option always fail to use the long-form -march= flag
due to the lack of an -mabi= flag in KBUILD_CFLAGS at the point
where the cc-option function is executed. The resulting GCC invocation
is something like:

  $ mips64-linux-gcc -Werror -march=mips32r2 -c -x c /dev/null -o tmp
  cc1: error: '-march=mips32r2' is not compatible with the selected ABI

These short-form - flags are dropped by the VDSO Makefile's
filtering, and so we attempt to build the VDSO without specifying any
architecture. This results in an attempt to build the VDSO using
whatever the compiler's default architecture is, regardless of whether
that is suitable for the kernel configuration.

One encountered build failure resulting from this mismatch is a
rejection of the sync instruction if the kernel is configured for a
MIPS32 or MIPS64 r1 or r2 target but the toolchain defaults to an older
architecture revision such as MIPS1 which did not include the sync
instruction:

CC  arch/mips/vdso/gettimeofday.o
  /tmp/ccGQKoOj.s: Assembler messages:
  /tmp/ccGQKoOj.s:273: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:329: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:520: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:714: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1009: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1066: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1114: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1279: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1334: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1374: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1459: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1514: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1814: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:2002: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:2066: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  make[2]: *** [scripts/Makefile.build:318: arch/mips/vdso/gettimeofday.o] 
Error 1
  make[1]: *** [scripts/Makefile.build:558: arch/mips/vdso] Error 2
  make[1]: *** Waiting for unfinished jobs

This can be reproduced for example by attempting to build
pistachio_defconfig using Arnd's GCC 8.1.0 mips64 toolchain from
kernel.org:

  
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.1.0/x86_64-gcc-8.1.0-nolibc-mips64-linux.tar.xz

Resolve this problem by using the long-form -march= in all cases,
which makes it through the arch/mips/vdso/Makefile's filtering & is thus
consistently used to build both the kernel proper & the VDSO.

The use of cc-option to prefer the long-form & fall back to the
short-form flags makes no sense since the short-form is just an
abbreviation for the also-supported long-form in all GCC versions that
we support building with. This means there is no case in which we have
to use the short-form - flags, so we can simply remove them.

The manual redefinition of _MIPS_ISA is removed naturally along with the
use of the short-form flags that it accompanied, and whilst here we
remove the separate assembler ISA selection. I suspect that both of
these were only required due to the mips32 vs mips2 mismatch that was
introduced by commit 59b3e8e9aac6 ("[MIPS] Makefile crapectomy.") and
fixed but not cleaned up by commit 9200c0b2a07c ("[MIPS] Fix Makefile
bugs for MIPS32/MIPS64 R1 and R2.").

I've marked this for backport as far as v4.4 where the MIPS VDSO was
introduced. In earlier kernels there should be no ill effect to using
the short-form flags.

Signed-off-by: Paul Burton 
Cc: Ralf Baechle 
Cc: linux-m...@linux-mips.org
Cc: sta...@vger.kernel.org # v4.4+
Reviewed-by: James Hogan 
Patchwork: https://patchwork.linux-mips.org/patch/19579/
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/Makefile |   12 
 1 file changed, 4 insertions(+), 8 deletions(-)

--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ 

[PATCH 4.14 148/165] kprobes: Make list and blacklist root user read only

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Masami Hiramatsu 

commit f2a3ab36077222437b4826fc76111caa14562b7c upstream.

Since the blacklist and list files on debugfs indicates
a sensitive address information to reader, it should be
restricted to the root user.

Suggested-by: Thomas Richter 
Suggested-by: Ingo Molnar 
Signed-off-by: Masami Hiramatsu 
Cc: Ananth N Mavinakayanahalli 
Cc: Anil S Keshavamurthy 
Cc: Arnd Bergmann 
Cc: David Howells 
Cc: David S . Miller 
Cc: Heiko Carstens 
Cc: Jon Medhurst 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Tobin C . Harding 
Cc: Will Deacon 
Cc: a...@kernel.org
Cc: a...@linux-foundation.org
Cc: brueck...@linux.vnet.ibm.com
Cc: linux-a...@vger.kernel.org
Cc: rost...@goodmis.org
Cc: schwidef...@de.ibm.com
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/lkml/152491890171.9916.5183693615601334087.stgit@devbox
Signed-off-by: Ingo Molnar 
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/kprobes.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2531,7 +2531,7 @@ static int __init debugfs_kprobe_init(vo
if (!dir)
return -ENOMEM;
 
-   file = debugfs_create_file("list", 0444, dir, NULL,
+   file = debugfs_create_file("list", 0400, dir, NULL,
_kprobes_operations);
if (!file)
goto error;
@@ -2541,7 +2541,7 @@ static int __init debugfs_kprobe_init(vo
if (!file)
goto error;
 
-   file = debugfs_create_file("blacklist", 0444, dir, NULL,
+   file = debugfs_create_file("blacklist", 0400, dir, NULL,
_kprobe_blacklist_ops);
if (!file)
goto error;




[PATCH 4.14 144/165] s390/qdio: reset old sbal_state flags

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Julian Wiedmann 

commit 64e03ff72623b8c2ea89ca3cb660094e019ed4ae upstream.

When allocating a new AOB fails, handle_outbound() is still capable of
transmitting the selected buffer (just without async completion).

But if a previous transfer on this queue slot used async completion, its
sbal_state flags field is still set to QDIO_OUTBUF_STATE_FLAG_PENDING.
So when the upper layer driver sees this stale flag, it expects an async
completion that never happens.

Fix this by unconditionally clearing the flags field.

Fixes: 104ea556ee7f ("qdio: support asynchronous delivery of storage blocks")
Cc:  #v3.2+
Signed-off-by: Julian Wiedmann 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/include/asm/qdio.h |1 -
 drivers/s390/cio/qdio_main.c |5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)

--- a/arch/s390/include/asm/qdio.h
+++ b/arch/s390/include/asm/qdio.h
@@ -262,7 +262,6 @@ struct qdio_outbuf_state {
void *user;
 };
 
-#define QDIO_OUTBUF_STATE_FLAG_NONE0x00
 #define QDIO_OUTBUF_STATE_FLAG_PENDING 0x01
 
 #define CHSC_AC1_INITIATE_INPUTQ   0x80
--- a/drivers/s390/cio/qdio_main.c
+++ b/drivers/s390/cio/qdio_main.c
@@ -641,21 +641,20 @@ static inline unsigned long qdio_aob_for
unsigned long phys_aob = 0;
 
if (!q->use_cq)
-   goto out;
+   return 0;
 
if (!q->aobs[bufnr]) {
struct qaob *aob = qdio_allocate_aob();
q->aobs[bufnr] = aob;
}
if (q->aobs[bufnr]) {
-   q->sbal_state[bufnr].flags = QDIO_OUTBUF_STATE_FLAG_NONE;
q->sbal_state[bufnr].aob = q->aobs[bufnr];
q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
phys_aob = virt_to_phys(q->aobs[bufnr]);
WARN_ON_ONCE(phys_aob & 0xFF);
}
 
-out:
+   q->sbal_state[bufnr].flags = 0;
return phys_aob;
 }
 




[PATCH 4.14 145/165] s390/numa: move initial setup of node_to_cpumask_map

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Martin Schwidefsky 

commit fb7d7518b0d65955f91c7b875c36eae7694c69bd upstream.

The numa_init_early initcall sets the node_to_cpumask_map[0] to the
full cpu_possible_mask. Unfortunately this early_initcall is too late,
the NUMA setup for numa=emu is done even earlier. The order of calls
is numa_setup() -> emu_update_cpu_topology(), then the early_initcalls(),
followed by sched_init_domains().

Starting with git commit 051f3ca02e46432c0965e8948f00c07d8a2f09c0
"sched/topology: Introduce NUMA identity node sched domain"
the incorrect node_to_cpumask_map[0] really screws up the domain
setup and the kernel panics with the follow oops:

Cc:  # v4.15+
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/numa/numa.c |   16 ++--
 1 file changed, 2 insertions(+), 14 deletions(-)

--- a/arch/s390/numa/numa.c
+++ b/arch/s390/numa/numa.c
@@ -134,6 +134,8 @@ void __init numa_setup(void)
 {
pr_info("NUMA mode: %s\n", mode->name);
nodes_clear(node_possible_map);
+   /* Initially attach all possible CPUs to node 0. */
+   cpumask_copy(_to_cpumask_map[0], cpu_possible_mask);
if (mode->setup)
mode->setup();
numa_setup_memory();
@@ -141,20 +143,6 @@ void __init numa_setup(void)
 }
 
 /*
- * numa_init_early() - Initialization initcall
- *
- * This runs when only one CPU is online and before the first
- * topology update is called for by the scheduler.
- */
-static int __init numa_init_early(void)
-{
-   /* Attach all possible CPUs to node 0 for now. */
-   cpumask_copy(_to_cpumask_map[0], cpu_possible_mask);
-   return 0;
-}
-early_initcall(numa_init_early);
-
-/*
  * numa_init_late() - Initialization initcall
  *
  * Register NUMA nodes.




[PATCH 4.14 147/165] kprobes/arm: Fix %p uses in error messages

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Masami Hiramatsu 

commit 75b2f5f5911fe7a2fc82969b2b24dde34e8f820d upstream.

Fix %p uses in error messages by removing it and
using general dumper.

Signed-off-by: Masami Hiramatsu 
Cc: Ananth N Mavinakayanahalli 
Cc: Anil S Keshavamurthy 
Cc: Arnd Bergmann 
Cc: David Howells 
Cc: David S . Miller 
Cc: Heiko Carstens 
Cc: Jon Medhurst 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Richter 
Cc: Tobin C . Harding 
Cc: Will Deacon 
Cc: a...@kernel.org
Cc: a...@linux-foundation.org
Cc: brueck...@linux.vnet.ibm.com
Cc: linux-a...@vger.kernel.org
Cc: rost...@goodmis.org
Cc: schwidef...@de.ibm.com
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/lkml/152491905361.9916.15300852365956231645.stgit@devbox
Signed-off-by: Ingo Molnar 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/arm/probes/kprobes/core.c  |4 ++--
 arch/arm/probes/kprobes/test-core.c |1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

--- a/arch/arm/probes/kprobes/core.c
+++ b/arch/arm/probes/kprobes/core.c
@@ -291,8 +291,8 @@ void __kprobes kprobe_handler(struct pt_
break;
case KPROBE_REENTER:
/* A nested probe was hit in FIQ, it is a BUG */
-   pr_warn("Unrecoverable kprobe detected at 
%p.\n",
-   p->addr);
+   pr_warn("Unrecoverable kprobe detected.\n");
+   dump_kprobe(p);
/* fall through */
default:
/* impossible cases */
--- a/arch/arm/probes/kprobes/test-core.c
+++ b/arch/arm/probes/kprobes/test-core.c
@@ -1517,7 +1517,6 @@ fail:
print_registers(_regs);
 
if (mem) {
-   pr_err("current_stack=%p\n", current_stack);
pr_err("expected_memory:\n");
print_memory(expected_memory, mem_size);
pr_err("result_memory:\n");




[PATCH 4.14 151/165] MIPS: Change definition of cpu_relax() for Loongson-3

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Huacai Chen 

commit a30718868915fbb991a9ae9e45594b059f28e9ae upstream.

Linux expects that if a CPU modifies a memory location, then that
modification will eventually become visible to other CPUs in the system.

Loongson 3 CPUs include a Store Fill Buffer (SFB) which sits between a
core & its L1 data cache, queueing memory accesses & allowing for faster
forwarding of data from pending stores to younger loads from the core.
Unfortunately the SFB prioritizes loads such that a continuous stream of
loads may cause a pending write to be buffered indefinitely. This is
problematic if we end up with 2 CPUs which each perform a store that the
other polls for - one or both CPUs may end up with their stores buffered
in the SFB, never reaching cache due to the continuous reads from the
poll loop. Such a deadlock condition has been observed whilst running
qspinlock code.

This patch changes the definition of cpu_relax() to smp_mb() for
Loongson-3, forcing a flush of the SFB on SMP systems which will cause
any pending writes to make it as far as the L1 caches where they will
become visible to other CPUs. If the kernel is not compiled for SMP
support, this will expand to a barrier() as before.

This workaround matches that currently implemented for ARM when
CONFIG_ARM_ERRATA_754327=y, which was introduced by commit 534be1d5a2da
("ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore").

Although the workaround is only required when the Loongson 3 SFB
functionality is enabled, and we only began explicitly enabling that
functionality in v4.7 with commit 1e820da3c9af ("MIPS: Loongson-3:
Introduce CONFIG_LOONGSON3_ENHANCEMENT"), existing or future firmware
may enable the SFB which means we may need the workaround backported to
earlier kernels too.

[paul.bur...@mips.com:
  - Reword commit message & comment.
  - Limit stable backport to v3.15+ where we support Loongson 3 CPUs.]

Signed-off-by: Huacai Chen 
Signed-off-by: Paul Burton 
References: 534be1d5a2da ("ARM: 6194/1: change definition of cpu_relax() for 
ARM11MPCore")
References: 1e820da3c9af ("MIPS: Loongson-3: Introduce 
CONFIG_LOONGSON3_ENHANCEMENT")
Patchwork: https://patchwork.linux-mips.org/patch/19830/
Cc: Ralf Baechle 
Cc: James Hogan 
Cc: linux-m...@linux-mips.org
Cc: Fuxin Zhang 
Cc: Zhangjin Wu 
Cc: Huacai Chen 
Cc: sta...@vger.kernel.org # v3.15+
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/include/asm/processor.h |   13 +
 1 file changed, 13 insertions(+)

--- a/arch/mips/include/asm/processor.h
+++ b/arch/mips/include/asm/processor.h
@@ -388,7 +388,20 @@ unsigned long get_wchan(struct task_stru
 #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
 #define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
 
+#ifdef CONFIG_CPU_LOONGSON3
+/*
+ * Loongson-3's SFB (Store-Fill-Buffer) may buffer writes indefinitely when a
+ * tight read loop is executed, because reads take priority over writes & the
+ * hardware (incorrectly) doesn't ensure that writes will eventually occur.
+ *
+ * Since spin loops of any kind should have a cpu_relax() in them, force an SFB
+ * flush from cpu_relax() such that any pending writes will become visible as
+ * expected.
+ */
+#define cpu_relax()smp_mb()
+#else
 #define cpu_relax()barrier()
+#endif
 
 /*
  * Return_address is a replacement for __builtin_return_address(count)




[PATCH 4.14 133/165] ASoC: sirf: Fix potential NULL pointer dereference

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Gustavo A. R. Silva 

commit ae1c696a480c67c45fb23b35162183f72c6be0e1 upstream.

There is a potential execution path in which function
platform_get_resource() returns NULL. If this happens,
we will end up having a NULL pointer dereference.

Fix this by replacing devm_ioremap with devm_ioremap_resource,
which has the NULL check and the memory region request.

This code was detected with the help of Coccinelle.

Cc: sta...@vger.kernel.org
Fixes: 2bd8d1d5cf89 ("ASoC: sirf: Add audio usp interface driver")
Signed-off-by: Gustavo A. R. Silva 
Signed-off-by: Mark Brown 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/soc/sirf/sirf-usp.c |7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

--- a/sound/soc/sirf/sirf-usp.c
+++ b/sound/soc/sirf/sirf-usp.c
@@ -370,10 +370,9 @@ static int sirf_usp_pcm_probe(struct pla
platform_set_drvdata(pdev, usp);
 
mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   base = devm_ioremap(>dev, mem_res->start,
-   resource_size(mem_res));
-   if (base == NULL)
-   return -ENOMEM;
+   base = devm_ioremap_resource(>dev, mem_res);
+   if (IS_ERR(base))
+   return PTR_ERR(base);
usp->regmap = devm_regmap_init_mmio(>dev, base,
_usp_regmap_config);
if (IS_ERR(usp->regmap))




[PATCH 4.14 133/165] ASoC: sirf: Fix potential NULL pointer dereference

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Gustavo A. R. Silva 

commit ae1c696a480c67c45fb23b35162183f72c6be0e1 upstream.

There is a potential execution path in which function
platform_get_resource() returns NULL. If this happens,
we will end up having a NULL pointer dereference.

Fix this by replacing devm_ioremap with devm_ioremap_resource,
which has the NULL check and the memory region request.

This code was detected with the help of Coccinelle.

Cc: sta...@vger.kernel.org
Fixes: 2bd8d1d5cf89 ("ASoC: sirf: Add audio usp interface driver")
Signed-off-by: Gustavo A. R. Silva 
Signed-off-by: Mark Brown 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/soc/sirf/sirf-usp.c |7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

--- a/sound/soc/sirf/sirf-usp.c
+++ b/sound/soc/sirf/sirf-usp.c
@@ -370,10 +370,9 @@ static int sirf_usp_pcm_probe(struct pla
platform_set_drvdata(pdev, usp);
 
mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   base = devm_ioremap(>dev, mem_res->start,
-   resource_size(mem_res));
-   if (base == NULL)
-   return -ENOMEM;
+   base = devm_ioremap_resource(>dev, mem_res);
+   if (IS_ERR(base))
+   return PTR_ERR(base);
usp->regmap = devm_regmap_init_mmio(>dev, base,
_usp_regmap_config);
if (IS_ERR(usp->regmap))




[PATCH 4.14 150/165] MIPS: Always use -march=, not - shortcuts

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Paul Burton 

commit 344ebf09949c31bcb8818d8458b65add29f1d67b upstream.

The VDSO Makefile filters CFLAGS to select a subset which it uses whilst
building the VDSO ELF. One of the flags it allows through is the -march=
flag that selects the architecture/ISA to target.

Unfortunately in cases where CONFIG_CPU_MIPS32_R{1,2}=y and the
toolchain defaults to building for MIPS64, the main MIPS Makefile ends
up using the short-form - flags in cflags-y. This is because the
calls to cc-option always fail to use the long-form -march= flag
due to the lack of an -mabi= flag in KBUILD_CFLAGS at the point
where the cc-option function is executed. The resulting GCC invocation
is something like:

  $ mips64-linux-gcc -Werror -march=mips32r2 -c -x c /dev/null -o tmp
  cc1: error: '-march=mips32r2' is not compatible with the selected ABI

These short-form - flags are dropped by the VDSO Makefile's
filtering, and so we attempt to build the VDSO without specifying any
architecture. This results in an attempt to build the VDSO using
whatever the compiler's default architecture is, regardless of whether
that is suitable for the kernel configuration.

One encountered build failure resulting from this mismatch is a
rejection of the sync instruction if the kernel is configured for a
MIPS32 or MIPS64 r1 or r2 target but the toolchain defaults to an older
architecture revision such as MIPS1 which did not include the sync
instruction:

CC  arch/mips/vdso/gettimeofday.o
  /tmp/ccGQKoOj.s: Assembler messages:
  /tmp/ccGQKoOj.s:273: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:329: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:520: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:714: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1009: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1066: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1114: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1279: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1334: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1374: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1459: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1514: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:1814: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:2002: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  /tmp/ccGQKoOj.s:2066: Error: opcode not supported on this processor: mips1 
(mips1) `sync'
  make[2]: *** [scripts/Makefile.build:318: arch/mips/vdso/gettimeofday.o] 
Error 1
  make[1]: *** [scripts/Makefile.build:558: arch/mips/vdso] Error 2
  make[1]: *** Waiting for unfinished jobs

This can be reproduced for example by attempting to build
pistachio_defconfig using Arnd's GCC 8.1.0 mips64 toolchain from
kernel.org:

  
https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.1.0/x86_64-gcc-8.1.0-nolibc-mips64-linux.tar.xz

Resolve this problem by using the long-form -march= in all cases,
which makes it through the arch/mips/vdso/Makefile's filtering & is thus
consistently used to build both the kernel proper & the VDSO.

The use of cc-option to prefer the long-form & fall back to the
short-form flags makes no sense since the short-form is just an
abbreviation for the also-supported long-form in all GCC versions that
we support building with. This means there is no case in which we have
to use the short-form - flags, so we can simply remove them.

The manual redefinition of _MIPS_ISA is removed naturally along with the
use of the short-form flags that it accompanied, and whilst here we
remove the separate assembler ISA selection. I suspect that both of
these were only required due to the mips32 vs mips2 mismatch that was
introduced by commit 59b3e8e9aac6 ("[MIPS] Makefile crapectomy.") and
fixed but not cleaned up by commit 9200c0b2a07c ("[MIPS] Fix Makefile
bugs for MIPS32/MIPS64 R1 and R2.").

I've marked this for backport as far as v4.4 where the MIPS VDSO was
introduced. In earlier kernels there should be no ill effect to using
the short-form flags.

Signed-off-by: Paul Burton 
Cc: Ralf Baechle 
Cc: linux-m...@linux-mips.org
Cc: sta...@vger.kernel.org # v4.4+
Reviewed-by: James Hogan 
Patchwork: https://patchwork.linux-mips.org/patch/19579/
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/Makefile |   12 
 1 file changed, 4 insertions(+), 8 deletions(-)

--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ 

[PATCH 4.14 148/165] kprobes: Make list and blacklist root user read only

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Masami Hiramatsu 

commit f2a3ab36077222437b4826fc76111caa14562b7c upstream.

Since the blacklist and list files on debugfs indicates
a sensitive address information to reader, it should be
restricted to the root user.

Suggested-by: Thomas Richter 
Suggested-by: Ingo Molnar 
Signed-off-by: Masami Hiramatsu 
Cc: Ananth N Mavinakayanahalli 
Cc: Anil S Keshavamurthy 
Cc: Arnd Bergmann 
Cc: David Howells 
Cc: David S . Miller 
Cc: Heiko Carstens 
Cc: Jon Medhurst 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Tobin C . Harding 
Cc: Will Deacon 
Cc: a...@kernel.org
Cc: a...@linux-foundation.org
Cc: brueck...@linux.vnet.ibm.com
Cc: linux-a...@vger.kernel.org
Cc: rost...@goodmis.org
Cc: schwidef...@de.ibm.com
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/lkml/152491890171.9916.5183693615601334087.stgit@devbox
Signed-off-by: Ingo Molnar 
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/kprobes.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2531,7 +2531,7 @@ static int __init debugfs_kprobe_init(vo
if (!dir)
return -ENOMEM;
 
-   file = debugfs_create_file("list", 0444, dir, NULL,
+   file = debugfs_create_file("list", 0400, dir, NULL,
_kprobes_operations);
if (!file)
goto error;
@@ -2541,7 +2541,7 @@ static int __init debugfs_kprobe_init(vo
if (!file)
goto error;
 
-   file = debugfs_create_file("blacklist", 0444, dir, NULL,
+   file = debugfs_create_file("blacklist", 0400, dir, NULL,
_kprobe_blacklist_ops);
if (!file)
goto error;




[PATCH 4.14 144/165] s390/qdio: reset old sbal_state flags

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Julian Wiedmann 

commit 64e03ff72623b8c2ea89ca3cb660094e019ed4ae upstream.

When allocating a new AOB fails, handle_outbound() is still capable of
transmitting the selected buffer (just without async completion).

But if a previous transfer on this queue slot used async completion, its
sbal_state flags field is still set to QDIO_OUTBUF_STATE_FLAG_PENDING.
So when the upper layer driver sees this stale flag, it expects an async
completion that never happens.

Fix this by unconditionally clearing the flags field.

Fixes: 104ea556ee7f ("qdio: support asynchronous delivery of storage blocks")
Cc:  #v3.2+
Signed-off-by: Julian Wiedmann 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/include/asm/qdio.h |1 -
 drivers/s390/cio/qdio_main.c |5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)

--- a/arch/s390/include/asm/qdio.h
+++ b/arch/s390/include/asm/qdio.h
@@ -262,7 +262,6 @@ struct qdio_outbuf_state {
void *user;
 };
 
-#define QDIO_OUTBUF_STATE_FLAG_NONE0x00
 #define QDIO_OUTBUF_STATE_FLAG_PENDING 0x01
 
 #define CHSC_AC1_INITIATE_INPUTQ   0x80
--- a/drivers/s390/cio/qdio_main.c
+++ b/drivers/s390/cio/qdio_main.c
@@ -641,21 +641,20 @@ static inline unsigned long qdio_aob_for
unsigned long phys_aob = 0;
 
if (!q->use_cq)
-   goto out;
+   return 0;
 
if (!q->aobs[bufnr]) {
struct qaob *aob = qdio_allocate_aob();
q->aobs[bufnr] = aob;
}
if (q->aobs[bufnr]) {
-   q->sbal_state[bufnr].flags = QDIO_OUTBUF_STATE_FLAG_NONE;
q->sbal_state[bufnr].aob = q->aobs[bufnr];
q->aobs[bufnr]->user1 = (u64) q->sbal_state[bufnr].user;
phys_aob = virt_to_phys(q->aobs[bufnr]);
WARN_ON_ONCE(phys_aob & 0xFF);
}
 
-out:
+   q->sbal_state[bufnr].flags = 0;
return phys_aob;
 }
 




[PATCH 4.14 145/165] s390/numa: move initial setup of node_to_cpumask_map

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Martin Schwidefsky 

commit fb7d7518b0d65955f91c7b875c36eae7694c69bd upstream.

The numa_init_early initcall sets the node_to_cpumask_map[0] to the
full cpu_possible_mask. Unfortunately this early_initcall is too late,
the NUMA setup for numa=emu is done even earlier. The order of calls
is numa_setup() -> emu_update_cpu_topology(), then the early_initcalls(),
followed by sched_init_domains().

Starting with git commit 051f3ca02e46432c0965e8948f00c07d8a2f09c0
"sched/topology: Introduce NUMA identity node sched domain"
the incorrect node_to_cpumask_map[0] really screws up the domain
setup and the kernel panics with the follow oops:

Cc:  # v4.15+
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/numa/numa.c |   16 ++--
 1 file changed, 2 insertions(+), 14 deletions(-)

--- a/arch/s390/numa/numa.c
+++ b/arch/s390/numa/numa.c
@@ -134,6 +134,8 @@ void __init numa_setup(void)
 {
pr_info("NUMA mode: %s\n", mode->name);
nodes_clear(node_possible_map);
+   /* Initially attach all possible CPUs to node 0. */
+   cpumask_copy(_to_cpumask_map[0], cpu_possible_mask);
if (mode->setup)
mode->setup();
numa_setup_memory();
@@ -141,20 +143,6 @@ void __init numa_setup(void)
 }
 
 /*
- * numa_init_early() - Initialization initcall
- *
- * This runs when only one CPU is online and before the first
- * topology update is called for by the scheduler.
- */
-static int __init numa_init_early(void)
-{
-   /* Attach all possible CPUs to node 0 for now. */
-   cpumask_copy(_to_cpumask_map[0], cpu_possible_mask);
-   return 0;
-}
-early_initcall(numa_init_early);
-
-/*
  * numa_init_late() - Initialization initcall
  *
  * Register NUMA nodes.




[PATCH 4.14 147/165] kprobes/arm: Fix %p uses in error messages

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Masami Hiramatsu 

commit 75b2f5f5911fe7a2fc82969b2b24dde34e8f820d upstream.

Fix %p uses in error messages by removing it and
using general dumper.

Signed-off-by: Masami Hiramatsu 
Cc: Ananth N Mavinakayanahalli 
Cc: Anil S Keshavamurthy 
Cc: Arnd Bergmann 
Cc: David Howells 
Cc: David S . Miller 
Cc: Heiko Carstens 
Cc: Jon Medhurst 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Richter 
Cc: Tobin C . Harding 
Cc: Will Deacon 
Cc: a...@kernel.org
Cc: a...@linux-foundation.org
Cc: brueck...@linux.vnet.ibm.com
Cc: linux-a...@vger.kernel.org
Cc: rost...@goodmis.org
Cc: schwidef...@de.ibm.com
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/lkml/152491905361.9916.15300852365956231645.stgit@devbox
Signed-off-by: Ingo Molnar 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/arm/probes/kprobes/core.c  |4 ++--
 arch/arm/probes/kprobes/test-core.c |1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

--- a/arch/arm/probes/kprobes/core.c
+++ b/arch/arm/probes/kprobes/core.c
@@ -291,8 +291,8 @@ void __kprobes kprobe_handler(struct pt_
break;
case KPROBE_REENTER:
/* A nested probe was hit in FIQ, it is a BUG */
-   pr_warn("Unrecoverable kprobe detected at 
%p.\n",
-   p->addr);
+   pr_warn("Unrecoverable kprobe detected.\n");
+   dump_kprobe(p);
/* fall through */
default:
/* impossible cases */
--- a/arch/arm/probes/kprobes/test-core.c
+++ b/arch/arm/probes/kprobes/test-core.c
@@ -1517,7 +1517,6 @@ fail:
print_registers(_regs);
 
if (mem) {
-   pr_err("current_stack=%p\n", current_stack);
pr_err("expected_memory:\n");
print_memory(expected_memory, mem_size);
pr_err("result_memory:\n");




[PATCH 4.14 151/165] MIPS: Change definition of cpu_relax() for Loongson-3

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Huacai Chen 

commit a30718868915fbb991a9ae9e45594b059f28e9ae upstream.

Linux expects that if a CPU modifies a memory location, then that
modification will eventually become visible to other CPUs in the system.

Loongson 3 CPUs include a Store Fill Buffer (SFB) which sits between a
core & its L1 data cache, queueing memory accesses & allowing for faster
forwarding of data from pending stores to younger loads from the core.
Unfortunately the SFB prioritizes loads such that a continuous stream of
loads may cause a pending write to be buffered indefinitely. This is
problematic if we end up with 2 CPUs which each perform a store that the
other polls for - one or both CPUs may end up with their stores buffered
in the SFB, never reaching cache due to the continuous reads from the
poll loop. Such a deadlock condition has been observed whilst running
qspinlock code.

This patch changes the definition of cpu_relax() to smp_mb() for
Loongson-3, forcing a flush of the SFB on SMP systems which will cause
any pending writes to make it as far as the L1 caches where they will
become visible to other CPUs. If the kernel is not compiled for SMP
support, this will expand to a barrier() as before.

This workaround matches that currently implemented for ARM when
CONFIG_ARM_ERRATA_754327=y, which was introduced by commit 534be1d5a2da
("ARM: 6194/1: change definition of cpu_relax() for ARM11MPCore").

Although the workaround is only required when the Loongson 3 SFB
functionality is enabled, and we only began explicitly enabling that
functionality in v4.7 with commit 1e820da3c9af ("MIPS: Loongson-3:
Introduce CONFIG_LOONGSON3_ENHANCEMENT"), existing or future firmware
may enable the SFB which means we may need the workaround backported to
earlier kernels too.

[paul.bur...@mips.com:
  - Reword commit message & comment.
  - Limit stable backport to v3.15+ where we support Loongson 3 CPUs.]

Signed-off-by: Huacai Chen 
Signed-off-by: Paul Burton 
References: 534be1d5a2da ("ARM: 6194/1: change definition of cpu_relax() for 
ARM11MPCore")
References: 1e820da3c9af ("MIPS: Loongson-3: Introduce 
CONFIG_LOONGSON3_ENHANCEMENT")
Patchwork: https://patchwork.linux-mips.org/patch/19830/
Cc: Ralf Baechle 
Cc: James Hogan 
Cc: linux-m...@linux-mips.org
Cc: Fuxin Zhang 
Cc: Zhangjin Wu 
Cc: Huacai Chen 
Cc: sta...@vger.kernel.org # v3.15+
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/include/asm/processor.h |   13 +
 1 file changed, 13 insertions(+)

--- a/arch/mips/include/asm/processor.h
+++ b/arch/mips/include/asm/processor.h
@@ -388,7 +388,20 @@ unsigned long get_wchan(struct task_stru
 #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
 #define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
 
+#ifdef CONFIG_CPU_LOONGSON3
+/*
+ * Loongson-3's SFB (Store-Fill-Buffer) may buffer writes indefinitely when a
+ * tight read loop is executed, because reads take priority over writes & the
+ * hardware (incorrectly) doesn't ensure that writes will eventually occur.
+ *
+ * Since spin loops of any kind should have a cpu_relax() in them, force an SFB
+ * flush from cpu_relax() such that any pending writes will become visible as
+ * expected.
+ */
+#define cpu_relax()smp_mb()
+#else
 #define cpu_relax()barrier()
+#endif
 
 /*
  * Return_address is a replacement for __builtin_return_address(count)




[PATCH 4.14 143/165] s390: fix br_r1_trampoline for machines without exrl

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Martin Schwidefsky 

commit 26f843848bae973817b3587780ce6b7b0200d3e4 upstream.

For machines without the exrl instruction the BFP jit generates
code that uses an "br %r1" instruction located in the lowcore page.
Unfortunately there is a cut & paste error that puts an additional
"larl %r1,.+14" instruction in the code that clobbers the branch
target address in %r1. Remove the larl instruction.

Cc:  # v4.17+
Fixes: de5cb6eb51 ("s390: use expoline thunks in the BPF JIT")
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/net/bpf_jit_comp.c |2 --
 1 file changed, 2 deletions(-)

--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -518,8 +518,6 @@ static void bpf_jit_epilogue(struct bpf_
/* br %r1 */
_EMIT2(0x07f1);
} else {
-   /* larl %r1,.+14 */
-   EMIT6_PCREL_RILB(0xc000, REG_1, jit->prg + 14);
/* ex 0,S390_lowcore.br_r1_tampoline */
EMIT4_DISP(0x4400, REG_0, REG_0,
   offsetof(struct lowcore, br_r1_trampoline));




[PATCH 4.14 143/165] s390: fix br_r1_trampoline for machines without exrl

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Martin Schwidefsky 

commit 26f843848bae973817b3587780ce6b7b0200d3e4 upstream.

For machines without the exrl instruction the BFP jit generates
code that uses an "br %r1" instruction located in the lowcore page.
Unfortunately there is a cut & paste error that puts an additional
"larl %r1,.+14" instruction in the code that clobbers the branch
target address in %r1. Remove the larl instruction.

Cc:  # v4.17+
Fixes: de5cb6eb51 ("s390: use expoline thunks in the BPF JIT")
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/net/bpf_jit_comp.c |2 --
 1 file changed, 2 deletions(-)

--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -518,8 +518,6 @@ static void bpf_jit_epilogue(struct bpf_
/* br %r1 */
_EMIT2(0x07f1);
} else {
-   /* larl %r1,.+14 */
-   EMIT6_PCREL_RILB(0xc000, REG_1, jit->prg + 14);
/* ex 0,S390_lowcore.br_r1_tampoline */
EMIT4_DISP(0x4400, REG_0, REG_0,
   offsetof(struct lowcore, br_r1_trampoline));




[PATCH 4.14 099/165] arm64: dts: rockchip: corrected uart1 clock-names for rk3328

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Huibin Hong 

commit d0414fdd58eb51ffd6528280fd66705123663964 upstream.

Corrected the uart clock-names or the uart driver might fail.

Fixes: 52e02d377a72 ("arm64: dts: rockchip: add core dtsi file for RK3328 SoCs")
Cc: sta...@vger.kernel.org
Signed-off-by: Huibin Hong 
Signed-off-by: Heiko Stuebner 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/arm64/boot/dts/rockchip/rk3328.dtsi |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/arm64/boot/dts/rockchip/rk3328.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3328.dtsi
@@ -331,7 +331,7 @@
reg = <0x0 0xff12 0x0 0x100>;
interrupts = ;
clocks = < SCLK_UART1>, < PCLK_UART1>;
-   clock-names = "sclk_uart", "pclk_uart";
+   clock-names = "baudclk", "apb_pclk";
dmas = < 4>, < 5>;
#dma-cells = <2>;
pinctrl-names = "default";




[PATCH 4.14 094/165] printk: Split the code for storing a message into the log buffer

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Petr Mladek 

commit ba552399954dde1b388f7749fecad5c349216981 upstream.

It is just a preparation step. The patch does not change
the existing behavior.

Link: http://lkml.kernel.org/r/20180627140817.27764-2-pmla...@suse.com
To: Steven Rostedt 
Cc: Peter Zijlstra 
Cc: Tetsuo Handa 
Cc: Sergey Senozhatsky 
Cc: linux-kernel@vger.kernel.org
Cc: sta...@vger.kernel.org
Acked-by: Sergey Senozhatsky 
Signed-off-by: Petr Mladek 
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/printk/printk.c |   43 ++-
 1 file changed, 26 insertions(+), 17 deletions(-)

--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1680,28 +1680,16 @@ static size_t log_output(int facility, i
return log_store(facility, level, lflags, 0, dict, dictlen, text, 
text_len);
 }
 
-asmlinkage int vprintk_emit(int facility, int level,
-   const char *dict, size_t dictlen,
-   const char *fmt, va_list args)
+/* Must be called under logbuf_lock. */
+int vprintk_store(int facility, int level,
+ const char *dict, size_t dictlen,
+ const char *fmt, va_list args)
 {
static char textbuf[LOG_LINE_MAX];
char *text = textbuf;
size_t text_len;
enum log_flags lflags = 0;
-   unsigned long flags;
-   int printed_len;
-   bool in_sched = false;
-
-   if (level == LOGLEVEL_SCHED) {
-   level = LOGLEVEL_DEFAULT;
-   in_sched = true;
-   }
-
-   boot_delay_msec(level);
-   printk_delay();
 
-   /* This stops the holder of console_sem just where we want him */
-   logbuf_lock_irqsave(flags);
/*
 * The printf needs to come first; we need the syslog
 * prefix which might be passed-in as a parameter.
@@ -1742,8 +1730,29 @@ asmlinkage int vprintk_emit(int facility
if (dict)
lflags |= LOG_PREFIX|LOG_NEWLINE;
 
-   printed_len = log_output(facility, level, lflags, dict, dictlen, text, 
text_len);
+   return log_output(facility, level, lflags,
+ dict, dictlen, text, text_len);
+}
 
+asmlinkage int vprintk_emit(int facility, int level,
+   const char *dict, size_t dictlen,
+   const char *fmt, va_list args)
+{
+   int printed_len;
+   bool in_sched = false;
+   unsigned long flags;
+
+   if (level == LOGLEVEL_SCHED) {
+   level = LOGLEVEL_DEFAULT;
+   in_sched = true;
+   }
+
+   boot_delay_msec(level);
+   printk_delay();
+
+   /* This stops the holder of console_sem just where we want him */
+   logbuf_lock_irqsave(flags);
+   printed_len = vprintk_store(facility, level, dict, dictlen, fmt, args);
logbuf_unlock_irqrestore(flags);
 
/* If called from the scheduler, we can not call up(). */




[PATCH 4.14 100/165] KVM: arm/arm64: Skip updating PMD entry if no change

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Punit Agrawal 

commit 86658b819cd0a9aa584cd84453ed268a6f013770 upstream.

Contention on updating a PMD entry by a large number of vcpus can lead
to duplicate work when handling stage 2 page faults. As the page table
update follows the break-before-make requirement of the architecture,
it can lead to repeated refaults due to clearing the entry and
flushing the tlbs.

This problem is more likely when -

* there are large number of vcpus
* the mapping is large block mapping

such as when using PMD hugepages (512MB) with 64k pages.

Fix this by skipping the page table update if there is no change in
the entry being updated.

Cc: sta...@vger.kernel.org
Fixes: ad361f093c1e ("KVM: ARM: Support hugetlbfs backed huge pages")
Reviewed-by: Suzuki Poulose 
Acked-by: Christoffer Dall 
Signed-off-by: Punit Agrawal 
Signed-off-by: Marc Zyngier 
Signed-off-by: Greg Kroah-Hartman 

---
 virt/kvm/arm/mmu.c |   38 +++---
 1 file changed, 27 insertions(+), 11 deletions(-)

--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -901,19 +901,35 @@ static int stage2_set_pmd_huge(struct kv
pmd = stage2_get_pmd(kvm, cache, addr);
VM_BUG_ON(!pmd);
 
-   /*
-* Mapping in huge pages should only happen through a fault.  If a
-* page is merged into a transparent huge page, the individual
-* subpages of that huge page should be unmapped through MMU
-* notifiers before we get here.
-*
-* Merging of CompoundPages is not supported; they should become
-* splitting first, unmapped, merged, and mapped back in on-demand.
-*/
-   VM_BUG_ON(pmd_present(*pmd) && pmd_pfn(*pmd) != pmd_pfn(*new_pmd));
-
old_pmd = *pmd;
if (pmd_present(old_pmd)) {
+   /*
+* Multiple vcpus faulting on the same PMD entry, can
+* lead to them sequentially updating the PMD with the
+* same value. Following the break-before-make
+* (pmd_clear() followed by tlb_flush()) process can
+* hinder forward progress due to refaults generated
+* on missing translations.
+*
+* Skip updating the page table if the entry is
+* unchanged.
+*/
+   if (pmd_val(old_pmd) == pmd_val(*new_pmd))
+   return 0;
+
+   /*
+* Mapping in huge pages should only happen through a
+* fault.  If a page is merged into a transparent huge
+* page, the individual subpages of that huge page
+* should be unmapped through MMU notifiers before we
+* get here.
+*
+* Merging of CompoundPages is not supported; they
+* should become splitting first, unmapped, merged,
+* and mapped back in on-demand.
+*/
+   VM_BUG_ON(pmd_pfn(old_pmd) != pmd_pfn(*new_pmd));
+
pmd_clear(pmd);
kvm_tlb_flush_vmid_ipa(kvm, addr);
} else {




[PATCH 4.14 130/165] b43/leds: Ensure NUL-termination of LED name string

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Michael Buesch 

commit 2aa650d1950fce94f696ebd7db30b8830c2c946f upstream.

strncpy might not NUL-terminate the string, if the name equals the buffer size.
Use strlcpy instead.

Signed-off-by: Michael Buesch 
Cc: sta...@vger.kernel.org
Signed-off-by: Kalle Valo 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/net/wireless/broadcom/b43/leds.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/wireless/broadcom/b43/leds.c
+++ b/drivers/net/wireless/broadcom/b43/leds.c
@@ -131,7 +131,7 @@ static int b43_register_led(struct b43_w
led->wl = dev->wl;
led->index = led_index;
led->activelow = activelow;
-   strncpy(led->name, name, sizeof(led->name));
+   strlcpy(led->name, name, sizeof(led->name));
atomic_set(>state, 0);
 
led->led_dev.name = led->name;




[PATCH 4.14 101/165] KVM: arm/arm64: Skip updating PTE entry if no change

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Punit Agrawal 

commit 976d34e2dab10ece5ea8fe7090b7692913f89084 upstream.

When there is contention on faulting in a particular page table entry
at stage 2, the break-before-make requirement of the architecture can
lead to additional refaulting due to TLB invalidation.

Avoid this by skipping a page table update if the new value of the PTE
matches the previous value.

Cc: sta...@vger.kernel.org
Fixes: d5d8184d35c9 ("KVM: ARM: Memory virtualization setup")
Reviewed-by: Suzuki Poulose 
Acked-by: Christoffer Dall 
Signed-off-by: Punit Agrawal 
Signed-off-by: Marc Zyngier 
Signed-off-by: Greg Kroah-Hartman 

---
 virt/kvm/arm/mmu.c |4 
 1 file changed, 4 insertions(+)

--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -985,6 +985,10 @@ static int stage2_set_pte(struct kvm *kv
/* Create 2nd stage page table mapping - Level 3 */
old_pte = *pte;
if (pte_present(old_pte)) {
+   /* Skip page table update if there is no change */
+   if (pte_val(old_pte) == pte_val(*new_pte))
+   return 0;
+
kvm_set_pte(pte, __pte(0));
kvm_tlb_flush_vmid_ipa(kvm, addr);
} else {




[PATCH 4.14 132/165] ASoC: zte: Fix incorrect PCM format bit usages

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Takashi Iwai 

commit c889a45d229938a94b50aadb819def8bb11a6a54 upstream.

zx-tdm driver sets the DAI driver definitions with the format bits
wrongly set with SNDRV_PCM_FORMAT_*, instead of SNDRV_PCM_FMTBIT_*.

This patch corrects the definitions.

Spotted by a sparse warning:
  sound/soc/zte/zx-tdm.c:363:35: warning: restricted snd_pcm_format_t degrades 
to integer

Fixes: 870e0ddc4345 ("ASoC: zx-tdm: add zte's tdm controller driver")
Cc: 
Signed-off-by: Takashi Iwai 
Signed-off-by: Mark Brown 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/soc/zte/zx-tdm.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/sound/soc/zte/zx-tdm.c
+++ b/sound/soc/zte/zx-tdm.c
@@ -144,8 +144,8 @@ static void zx_tdm_rx_dma_en(struct zx_t
 #define ZX_TDM_RATES   (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
 
 #define ZX_TDM_FMTBIT \
-   (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_MU_LAW | \
-   SNDRV_PCM_FORMAT_A_LAW)
+   (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_MU_LAW | \
+   SNDRV_PCM_FMTBIT_A_LAW)
 
 static int zx_tdm_dai_probe(struct snd_soc_dai *dai)
 {




[PATCH 4.14 099/165] arm64: dts: rockchip: corrected uart1 clock-names for rk3328

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Huibin Hong 

commit d0414fdd58eb51ffd6528280fd66705123663964 upstream.

Corrected the uart clock-names or the uart driver might fail.

Fixes: 52e02d377a72 ("arm64: dts: rockchip: add core dtsi file for RK3328 SoCs")
Cc: sta...@vger.kernel.org
Signed-off-by: Huibin Hong 
Signed-off-by: Heiko Stuebner 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/arm64/boot/dts/rockchip/rk3328.dtsi |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/arm64/boot/dts/rockchip/rk3328.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3328.dtsi
@@ -331,7 +331,7 @@
reg = <0x0 0xff12 0x0 0x100>;
interrupts = ;
clocks = < SCLK_UART1>, < PCLK_UART1>;
-   clock-names = "sclk_uart", "pclk_uart";
+   clock-names = "baudclk", "apb_pclk";
dmas = < 4>, < 5>;
#dma-cells = <2>;
pinctrl-names = "default";




[PATCH 4.14 094/165] printk: Split the code for storing a message into the log buffer

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Petr Mladek 

commit ba552399954dde1b388f7749fecad5c349216981 upstream.

It is just a preparation step. The patch does not change
the existing behavior.

Link: http://lkml.kernel.org/r/20180627140817.27764-2-pmla...@suse.com
To: Steven Rostedt 
Cc: Peter Zijlstra 
Cc: Tetsuo Handa 
Cc: Sergey Senozhatsky 
Cc: linux-kernel@vger.kernel.org
Cc: sta...@vger.kernel.org
Acked-by: Sergey Senozhatsky 
Signed-off-by: Petr Mladek 
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/printk/printk.c |   43 ++-
 1 file changed, 26 insertions(+), 17 deletions(-)

--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1680,28 +1680,16 @@ static size_t log_output(int facility, i
return log_store(facility, level, lflags, 0, dict, dictlen, text, 
text_len);
 }
 
-asmlinkage int vprintk_emit(int facility, int level,
-   const char *dict, size_t dictlen,
-   const char *fmt, va_list args)
+/* Must be called under logbuf_lock. */
+int vprintk_store(int facility, int level,
+ const char *dict, size_t dictlen,
+ const char *fmt, va_list args)
 {
static char textbuf[LOG_LINE_MAX];
char *text = textbuf;
size_t text_len;
enum log_flags lflags = 0;
-   unsigned long flags;
-   int printed_len;
-   bool in_sched = false;
-
-   if (level == LOGLEVEL_SCHED) {
-   level = LOGLEVEL_DEFAULT;
-   in_sched = true;
-   }
-
-   boot_delay_msec(level);
-   printk_delay();
 
-   /* This stops the holder of console_sem just where we want him */
-   logbuf_lock_irqsave(flags);
/*
 * The printf needs to come first; we need the syslog
 * prefix which might be passed-in as a parameter.
@@ -1742,8 +1730,29 @@ asmlinkage int vprintk_emit(int facility
if (dict)
lflags |= LOG_PREFIX|LOG_NEWLINE;
 
-   printed_len = log_output(facility, level, lflags, dict, dictlen, text, 
text_len);
+   return log_output(facility, level, lflags,
+ dict, dictlen, text, text_len);
+}
 
+asmlinkage int vprintk_emit(int facility, int level,
+   const char *dict, size_t dictlen,
+   const char *fmt, va_list args)
+{
+   int printed_len;
+   bool in_sched = false;
+   unsigned long flags;
+
+   if (level == LOGLEVEL_SCHED) {
+   level = LOGLEVEL_DEFAULT;
+   in_sched = true;
+   }
+
+   boot_delay_msec(level);
+   printk_delay();
+
+   /* This stops the holder of console_sem just where we want him */
+   logbuf_lock_irqsave(flags);
+   printed_len = vprintk_store(facility, level, dict, dictlen, fmt, args);
logbuf_unlock_irqrestore(flags);
 
/* If called from the scheduler, we can not call up(). */




[PATCH 4.14 100/165] KVM: arm/arm64: Skip updating PMD entry if no change

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Punit Agrawal 

commit 86658b819cd0a9aa584cd84453ed268a6f013770 upstream.

Contention on updating a PMD entry by a large number of vcpus can lead
to duplicate work when handling stage 2 page faults. As the page table
update follows the break-before-make requirement of the architecture,
it can lead to repeated refaults due to clearing the entry and
flushing the tlbs.

This problem is more likely when -

* there are large number of vcpus
* the mapping is large block mapping

such as when using PMD hugepages (512MB) with 64k pages.

Fix this by skipping the page table update if there is no change in
the entry being updated.

Cc: sta...@vger.kernel.org
Fixes: ad361f093c1e ("KVM: ARM: Support hugetlbfs backed huge pages")
Reviewed-by: Suzuki Poulose 
Acked-by: Christoffer Dall 
Signed-off-by: Punit Agrawal 
Signed-off-by: Marc Zyngier 
Signed-off-by: Greg Kroah-Hartman 

---
 virt/kvm/arm/mmu.c |   38 +++---
 1 file changed, 27 insertions(+), 11 deletions(-)

--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -901,19 +901,35 @@ static int stage2_set_pmd_huge(struct kv
pmd = stage2_get_pmd(kvm, cache, addr);
VM_BUG_ON(!pmd);
 
-   /*
-* Mapping in huge pages should only happen through a fault.  If a
-* page is merged into a transparent huge page, the individual
-* subpages of that huge page should be unmapped through MMU
-* notifiers before we get here.
-*
-* Merging of CompoundPages is not supported; they should become
-* splitting first, unmapped, merged, and mapped back in on-demand.
-*/
-   VM_BUG_ON(pmd_present(*pmd) && pmd_pfn(*pmd) != pmd_pfn(*new_pmd));
-
old_pmd = *pmd;
if (pmd_present(old_pmd)) {
+   /*
+* Multiple vcpus faulting on the same PMD entry, can
+* lead to them sequentially updating the PMD with the
+* same value. Following the break-before-make
+* (pmd_clear() followed by tlb_flush()) process can
+* hinder forward progress due to refaults generated
+* on missing translations.
+*
+* Skip updating the page table if the entry is
+* unchanged.
+*/
+   if (pmd_val(old_pmd) == pmd_val(*new_pmd))
+   return 0;
+
+   /*
+* Mapping in huge pages should only happen through a
+* fault.  If a page is merged into a transparent huge
+* page, the individual subpages of that huge page
+* should be unmapped through MMU notifiers before we
+* get here.
+*
+* Merging of CompoundPages is not supported; they
+* should become splitting first, unmapped, merged,
+* and mapped back in on-demand.
+*/
+   VM_BUG_ON(pmd_pfn(old_pmd) != pmd_pfn(*new_pmd));
+
pmd_clear(pmd);
kvm_tlb_flush_vmid_ipa(kvm, addr);
} else {




[PATCH 4.14 130/165] b43/leds: Ensure NUL-termination of LED name string

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Michael Buesch 

commit 2aa650d1950fce94f696ebd7db30b8830c2c946f upstream.

strncpy might not NUL-terminate the string, if the name equals the buffer size.
Use strlcpy instead.

Signed-off-by: Michael Buesch 
Cc: sta...@vger.kernel.org
Signed-off-by: Kalle Valo 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/net/wireless/broadcom/b43/leds.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/wireless/broadcom/b43/leds.c
+++ b/drivers/net/wireless/broadcom/b43/leds.c
@@ -131,7 +131,7 @@ static int b43_register_led(struct b43_w
led->wl = dev->wl;
led->index = led_index;
led->activelow = activelow;
-   strncpy(led->name, name, sizeof(led->name));
+   strlcpy(led->name, name, sizeof(led->name));
atomic_set(>state, 0);
 
led->led_dev.name = led->name;




[PATCH 4.14 101/165] KVM: arm/arm64: Skip updating PTE entry if no change

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Punit Agrawal 

commit 976d34e2dab10ece5ea8fe7090b7692913f89084 upstream.

When there is contention on faulting in a particular page table entry
at stage 2, the break-before-make requirement of the architecture can
lead to additional refaulting due to TLB invalidation.

Avoid this by skipping a page table update if the new value of the PTE
matches the previous value.

Cc: sta...@vger.kernel.org
Fixes: d5d8184d35c9 ("KVM: ARM: Memory virtualization setup")
Reviewed-by: Suzuki Poulose 
Acked-by: Christoffer Dall 
Signed-off-by: Punit Agrawal 
Signed-off-by: Marc Zyngier 
Signed-off-by: Greg Kroah-Hartman 

---
 virt/kvm/arm/mmu.c |4 
 1 file changed, 4 insertions(+)

--- a/virt/kvm/arm/mmu.c
+++ b/virt/kvm/arm/mmu.c
@@ -985,6 +985,10 @@ static int stage2_set_pte(struct kvm *kv
/* Create 2nd stage page table mapping - Level 3 */
old_pte = *pte;
if (pte_present(old_pte)) {
+   /* Skip page table update if there is no change */
+   if (pte_val(old_pte) == pte_val(*new_pte))
+   return 0;
+
kvm_set_pte(pte, __pte(0));
kvm_tlb_flush_vmid_ipa(kvm, addr);
} else {




[PATCH 4.14 132/165] ASoC: zte: Fix incorrect PCM format bit usages

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Takashi Iwai 

commit c889a45d229938a94b50aadb819def8bb11a6a54 upstream.

zx-tdm driver sets the DAI driver definitions with the format bits
wrongly set with SNDRV_PCM_FORMAT_*, instead of SNDRV_PCM_FMTBIT_*.

This patch corrects the definitions.

Spotted by a sparse warning:
  sound/soc/zte/zx-tdm.c:363:35: warning: restricted snd_pcm_format_t degrades 
to integer

Fixes: 870e0ddc4345 ("ASoC: zx-tdm: add zte's tdm controller driver")
Cc: 
Signed-off-by: Takashi Iwai 
Signed-off-by: Mark Brown 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/soc/zte/zx-tdm.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/sound/soc/zte/zx-tdm.c
+++ b/sound/soc/zte/zx-tdm.c
@@ -144,8 +144,8 @@ static void zx_tdm_rx_dma_en(struct zx_t
 #define ZX_TDM_RATES   (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
 
 #define ZX_TDM_FMTBIT \
-   (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_MU_LAW | \
-   SNDRV_PCM_FORMAT_A_LAW)
+   (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_MU_LAW | \
+   SNDRV_PCM_FMTBIT_A_LAW)
 
 static int zx_tdm_dai_probe(struct snd_soc_dai *dai)
 {




[PATCH 4.14 102/165] s390/kvm: fix deadlock when killed by oom

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Claudio Imbrenda 

commit 306d6c49ac9ded4cb53b0925da52f2c2ada1 upstream.

When the oom killer kills a userspace process in the page fault handler
while in guest context, the fault handler fails to release the mm_sem
if the FAULT_FLAG_RETRY_NOWAIT option is set. This leads to a deadlock
when tearing down the mm when the process terminates. This bug can only
happen when pfault is enabled, so only KVM clients are affected.

The problem arises in the rare cases in which handle_mm_fault does not
release the mm_sem. This patch fixes the issue by manually releasing
the mm_sem when needed.

Fixes: 24eb3a824c4f3 ("KVM: s390: Add FAULT_FLAG_RETRY_NOWAIT for guest fault")
Cc:  # 3.15+
Signed-off-by: Claudio Imbrenda 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/mm/fault.c |2 ++
 1 file changed, 2 insertions(+)

--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -486,6 +486,8 @@ retry:
/* No reason to continue if interrupted by SIGKILL. */
if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) {
fault = VM_FAULT_SIGNAL;
+   if (flags & FAULT_FLAG_RETRY_NOWAIT)
+   goto out_up;
goto out;
}
if (unlikely(fault & VM_FAULT_ERROR))




[PATCH 4.14 142/165] s390/mm: fix addressing exception after suspend/resume

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Gerald Schaefer 

commit 37a366face294facb9c9d9fdd9f5b64a27456cbd upstream.

Commit c9b5ad546e7d "s390/mm: tag normal pages vs pages used in page tables"
accidentally changed the logic in arch_set_page_states(), which is used by
the suspend/resume code. set_page_stable(page, order) was changed to
set_page_stable_dat(page, 0). After this, only the first page of higher order
pages will be set to stable, and a write to one of the unstable pages will
result in an addressing exception.

Fix this by using "order" again, instead of "0".

Fixes: c9b5ad546e7d ("s390/mm: tag normal pages vs pages used in page tables")
Cc: sta...@vger.kernel.org # 4.14+
Reviewed-by: Heiko Carstens 
Signed-off-by: Gerald Schaefer 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/mm/page-states.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/s390/mm/page-states.c
+++ b/arch/s390/mm/page-states.c
@@ -271,7 +271,7 @@ void arch_set_page_states(int make_stabl
list_for_each(l, >free_area[order].free_list[t]) {
page = list_entry(l, struct page, lru);
if (make_stable)
-   set_page_stable_dat(page, 0);
+   set_page_stable_dat(page, order);
else
set_page_unused(page, order);
}




[PATCH 4.14 098/165] arm64: mm: check for upper PAGE_SHIFT bits in pfn_valid()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Greg Hackmann 

commit 5ad356eabc47d26a92140a0c4b20eba471c10de3 upstream.

ARM64's pfn_valid() shifts away the upper PAGE_SHIFT bits of the input
before seeing if the PFN is valid.  This leads to false positives when
some of the upper bits are set, but the lower bits match a valid PFN.

For example, the following userspace code looks up a bogus entry in
/proc/kpageflags:

int pagemap = open("/proc/self/pagemap", O_RDONLY);
int pageflags = open("/proc/kpageflags", O_RDONLY);
uint64_t pfn, val;

lseek64(pagemap, [...], SEEK_SET);
read(pagemap, , sizeof(pfn));
if (pfn & (1UL << 63)) {/* valid PFN */
pfn &= ((1UL << 55) - 1);   /* clear flag bits */
pfn |= (1UL << 55);
lseek64(pageflags, pfn * sizeof(uint64_t), SEEK_SET);
read(pageflags, , sizeof(val));
}

On ARM64 this causes the userspace process to crash with SIGSEGV rather
than reading (1 << KPF_NOPAGE).  kpageflags_read() treats the offset as
valid, and stable_page_flags() will try to access an address between the
user and kernel address ranges.

Fixes: c1cc1552616d ("arm64: MMU initialisation")
Cc: sta...@vger.kernel.org
Signed-off-by: Greg Hackmann 
Signed-off-by: Will Deacon 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/arm64/mm/init.c |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -287,7 +287,11 @@ static void __init zone_sizes_init(unsig
 #ifdef CONFIG_HAVE_ARCH_PFN_VALID
 int pfn_valid(unsigned long pfn)
 {
-   return memblock_is_map_memory(pfn << PAGE_SHIFT);
+   phys_addr_t addr = pfn << PAGE_SHIFT;
+
+   if ((addr >> PAGE_SHIFT) != pfn)
+   return 0;
+   return memblock_is_map_memory(addr);
 }
 EXPORT_SYMBOL(pfn_valid);
 #endif




[PATCH 4.14 141/165] x86/entry/64: Wipe KASAN stack shadow before rewind_stack_do_exit()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Jann Horn 

commit f12d11c5c184626b4befdee3d573ec8237405a33 upstream.

Reset the KASAN shadow state of the task stack before rewinding RSP.
Without this, a kernel oops will leave parts of the stack poisoned, and
code running under do_exit() can trip over such poisoned regions and cause
nonsensical false-positive KASAN reports about stack-out-of-bounds bugs.

This does not wipe the exception stacks; if an oops happens on an exception
stack, it might result in random KASAN false-positives from other tasks
afterwards. This is probably relatively uninteresting, since if the kernel
oopses on an exception stack, there are most likely bigger things to worry
about. It'd be more interesting if vmapped stacks and KASAN were
compatible, since then handle_stack_overflow() would oops from exception
stack context.

Fixes: 2deb4be28077 ("x86/dumpstack: When OOPSing, rewind the stack before 
do_exit()")
Signed-off-by: Jann Horn 
Signed-off-by: Thomas Gleixner 
Acked-by: Andrey Ryabinin 
Cc: Andy Lutomirski 
Cc: Dmitry Vyukov 
Cc: Alexander Potapenko 
Cc: Kees Cook 
Cc: kasan-...@googlegroups.com
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180828184033.93712-1-ja...@google.com
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/dumpstack.c |4 
 1 file changed, 4 insertions(+)

--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -298,7 +299,10 @@ void oops_end(unsigned long flags, struc
 * We're not going to return, but we might be on an IST stack or
 * have very little stack space left.  Rewind the stack and kill
 * the task.
+* Before we rewind the stack, we have to tell KASAN that we're going to
+* reuse the task stack and that existing poisons are invalid.
 */
+   kasan_unpoison_task_stack(current);
rewind_stack_do_exit(signr);
 }
 NOKPROBE_SYMBOL(oops_end);




[PATCH 4.14 103/165] stop_machine: Reflow cpu_stop_queue_two_works()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Peter Zijlstra 

commit b80a2bfce85e1051056d98d04ecb2d0b55cbbc1c upstream.

The code flow in cpu_stop_queue_two_works() is a little arcane; fix this by
lifting the preempt_disable() to the top to create more natural nesting wrt
the spinlocks and make the wake_up_q() and preempt_enable() unconditional
at the end.

Furthermore, enable preemption in the -EDEADLK case, such that we spin-wait
with preemption enabled.

Suggested-by: Thomas Gleixner 
Signed-off-by: Peter Zijlstra (Intel) 
Signed-off-by: Thomas Gleixner 
Cc: Sebastian Andrzej Siewior 
Cc: isa...@codeaurora.org
Cc: m...@codeblueprint.co.uk
Cc: psoda...@codeaurora.org
Cc: gre...@linuxfoundation.org
Cc: pkond...@codeaurora.org
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/r/20180730112140.gh2...@hirez.programming.kicks-ass.net
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/stop_machine.c |   41 +++--
 1 file changed, 23 insertions(+), 18 deletions(-)

--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -236,13 +236,24 @@ static int cpu_stop_queue_two_works(int
struct cpu_stopper *stopper2 = per_cpu_ptr(_stopper, cpu2);
DEFINE_WAKE_Q(wakeq);
int err;
+
 retry:
+   /*
+* The waking up of stopper threads has to happen in the same
+* scheduling context as the queueing.  Otherwise, there is a
+* possibility of one of the above stoppers being woken up by another
+* CPU, and preempting us. This will cause us to not wake up the other
+* stopper forever.
+*/
+   preempt_disable();
raw_spin_lock_irq(>lock);
raw_spin_lock_nested(>lock, SINGLE_DEPTH_NESTING);
 
-   err = -ENOENT;
-   if (!stopper1->enabled || !stopper2->enabled)
+   if (!stopper1->enabled || !stopper2->enabled) {
+   err = -ENOENT;
goto unlock;
+   }
+
/*
 * Ensure that if we race with __stop_cpus() the stoppers won't get
 * queued up in reverse order leading to system deadlock.
@@ -253,36 +264,30 @@ retry:
 * It can be falsely true but it is safe to spin until it is cleared,
 * queue_stop_cpus_work() does everything under preempt_disable().
 */
-   err = -EDEADLK;
-   if (unlikely(stop_cpus_in_progress))
-   goto unlock;
+   if (unlikely(stop_cpus_in_progress)) {
+   err = -EDEADLK;
+   goto unlock;
+   }
 
err = 0;
__cpu_stop_queue_work(stopper1, work1, );
__cpu_stop_queue_work(stopper2, work2, );
-   /*
-* The waking up of stopper threads has to happen
-* in the same scheduling context as the queueing.
-* Otherwise, there is a possibility of one of the
-* above stoppers being woken up by another CPU,
-* and preempting us. This will cause us to n ot
-* wake up the other stopper forever.
-*/
-   preempt_disable();
+
 unlock:
raw_spin_unlock(>lock);
raw_spin_unlock_irq(>lock);
 
if (unlikely(err == -EDEADLK)) {
+   preempt_enable();
+
while (stop_cpus_in_progress)
cpu_relax();
+
goto retry;
}
 
-   if (!err) {
-   wake_up_q();
-   preempt_enable();
-   }
+   wake_up_q();
+   preempt_enable();
 
return err;
 }




[PATCH 4.14 102/165] s390/kvm: fix deadlock when killed by oom

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Claudio Imbrenda 

commit 306d6c49ac9ded4cb53b0925da52f2c2ada1 upstream.

When the oom killer kills a userspace process in the page fault handler
while in guest context, the fault handler fails to release the mm_sem
if the FAULT_FLAG_RETRY_NOWAIT option is set. This leads to a deadlock
when tearing down the mm when the process terminates. This bug can only
happen when pfault is enabled, so only KVM clients are affected.

The problem arises in the rare cases in which handle_mm_fault does not
release the mm_sem. This patch fixes the issue by manually releasing
the mm_sem when needed.

Fixes: 24eb3a824c4f3 ("KVM: s390: Add FAULT_FLAG_RETRY_NOWAIT for guest fault")
Cc:  # 3.15+
Signed-off-by: Claudio Imbrenda 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/mm/fault.c |2 ++
 1 file changed, 2 insertions(+)

--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -486,6 +486,8 @@ retry:
/* No reason to continue if interrupted by SIGKILL. */
if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) {
fault = VM_FAULT_SIGNAL;
+   if (flags & FAULT_FLAG_RETRY_NOWAIT)
+   goto out_up;
goto out;
}
if (unlikely(fault & VM_FAULT_ERROR))




[PATCH 4.14 142/165] s390/mm: fix addressing exception after suspend/resume

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Gerald Schaefer 

commit 37a366face294facb9c9d9fdd9f5b64a27456cbd upstream.

Commit c9b5ad546e7d "s390/mm: tag normal pages vs pages used in page tables"
accidentally changed the logic in arch_set_page_states(), which is used by
the suspend/resume code. set_page_stable(page, order) was changed to
set_page_stable_dat(page, 0). After this, only the first page of higher order
pages will be set to stable, and a write to one of the unstable pages will
result in an addressing exception.

Fix this by using "order" again, instead of "0".

Fixes: c9b5ad546e7d ("s390/mm: tag normal pages vs pages used in page tables")
Cc: sta...@vger.kernel.org # 4.14+
Reviewed-by: Heiko Carstens 
Signed-off-by: Gerald Schaefer 
Signed-off-by: Martin Schwidefsky 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/mm/page-states.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/s390/mm/page-states.c
+++ b/arch/s390/mm/page-states.c
@@ -271,7 +271,7 @@ void arch_set_page_states(int make_stabl
list_for_each(l, >free_area[order].free_list[t]) {
page = list_entry(l, struct page, lru);
if (make_stable)
-   set_page_stable_dat(page, 0);
+   set_page_stable_dat(page, order);
else
set_page_unused(page, order);
}




[PATCH 4.14 098/165] arm64: mm: check for upper PAGE_SHIFT bits in pfn_valid()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Greg Hackmann 

commit 5ad356eabc47d26a92140a0c4b20eba471c10de3 upstream.

ARM64's pfn_valid() shifts away the upper PAGE_SHIFT bits of the input
before seeing if the PFN is valid.  This leads to false positives when
some of the upper bits are set, but the lower bits match a valid PFN.

For example, the following userspace code looks up a bogus entry in
/proc/kpageflags:

int pagemap = open("/proc/self/pagemap", O_RDONLY);
int pageflags = open("/proc/kpageflags", O_RDONLY);
uint64_t pfn, val;

lseek64(pagemap, [...], SEEK_SET);
read(pagemap, , sizeof(pfn));
if (pfn & (1UL << 63)) {/* valid PFN */
pfn &= ((1UL << 55) - 1);   /* clear flag bits */
pfn |= (1UL << 55);
lseek64(pageflags, pfn * sizeof(uint64_t), SEEK_SET);
read(pageflags, , sizeof(val));
}

On ARM64 this causes the userspace process to crash with SIGSEGV rather
than reading (1 << KPF_NOPAGE).  kpageflags_read() treats the offset as
valid, and stable_page_flags() will try to access an address between the
user and kernel address ranges.

Fixes: c1cc1552616d ("arm64: MMU initialisation")
Cc: sta...@vger.kernel.org
Signed-off-by: Greg Hackmann 
Signed-off-by: Will Deacon 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/arm64/mm/init.c |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -287,7 +287,11 @@ static void __init zone_sizes_init(unsig
 #ifdef CONFIG_HAVE_ARCH_PFN_VALID
 int pfn_valid(unsigned long pfn)
 {
-   return memblock_is_map_memory(pfn << PAGE_SHIFT);
+   phys_addr_t addr = pfn << PAGE_SHIFT;
+
+   if ((addr >> PAGE_SHIFT) != pfn)
+   return 0;
+   return memblock_is_map_memory(addr);
 }
 EXPORT_SYMBOL(pfn_valid);
 #endif




[PATCH 4.14 141/165] x86/entry/64: Wipe KASAN stack shadow before rewind_stack_do_exit()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Jann Horn 

commit f12d11c5c184626b4befdee3d573ec8237405a33 upstream.

Reset the KASAN shadow state of the task stack before rewinding RSP.
Without this, a kernel oops will leave parts of the stack poisoned, and
code running under do_exit() can trip over such poisoned regions and cause
nonsensical false-positive KASAN reports about stack-out-of-bounds bugs.

This does not wipe the exception stacks; if an oops happens on an exception
stack, it might result in random KASAN false-positives from other tasks
afterwards. This is probably relatively uninteresting, since if the kernel
oopses on an exception stack, there are most likely bigger things to worry
about. It'd be more interesting if vmapped stacks and KASAN were
compatible, since then handle_stack_overflow() would oops from exception
stack context.

Fixes: 2deb4be28077 ("x86/dumpstack: When OOPSing, rewind the stack before 
do_exit()")
Signed-off-by: Jann Horn 
Signed-off-by: Thomas Gleixner 
Acked-by: Andrey Ryabinin 
Cc: Andy Lutomirski 
Cc: Dmitry Vyukov 
Cc: Alexander Potapenko 
Cc: Kees Cook 
Cc: kasan-...@googlegroups.com
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180828184033.93712-1-ja...@google.com
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/dumpstack.c |4 
 1 file changed, 4 insertions(+)

--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -298,7 +299,10 @@ void oops_end(unsigned long flags, struc
 * We're not going to return, but we might be on an IST stack or
 * have very little stack space left.  Rewind the stack and kill
 * the task.
+* Before we rewind the stack, we have to tell KASAN that we're going to
+* reuse the task stack and that existing poisons are invalid.
 */
+   kasan_unpoison_task_stack(current);
rewind_stack_do_exit(signr);
 }
 NOKPROBE_SYMBOL(oops_end);




[PATCH 4.14 103/165] stop_machine: Reflow cpu_stop_queue_two_works()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Peter Zijlstra 

commit b80a2bfce85e1051056d98d04ecb2d0b55cbbc1c upstream.

The code flow in cpu_stop_queue_two_works() is a little arcane; fix this by
lifting the preempt_disable() to the top to create more natural nesting wrt
the spinlocks and make the wake_up_q() and preempt_enable() unconditional
at the end.

Furthermore, enable preemption in the -EDEADLK case, such that we spin-wait
with preemption enabled.

Suggested-by: Thomas Gleixner 
Signed-off-by: Peter Zijlstra (Intel) 
Signed-off-by: Thomas Gleixner 
Cc: Sebastian Andrzej Siewior 
Cc: isa...@codeaurora.org
Cc: m...@codeblueprint.co.uk
Cc: psoda...@codeaurora.org
Cc: gre...@linuxfoundation.org
Cc: pkond...@codeaurora.org
Cc: sta...@vger.kernel.org
Link: 
https://lkml.kernel.org/r/20180730112140.gh2...@hirez.programming.kicks-ass.net
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/stop_machine.c |   41 +++--
 1 file changed, 23 insertions(+), 18 deletions(-)

--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -236,13 +236,24 @@ static int cpu_stop_queue_two_works(int
struct cpu_stopper *stopper2 = per_cpu_ptr(_stopper, cpu2);
DEFINE_WAKE_Q(wakeq);
int err;
+
 retry:
+   /*
+* The waking up of stopper threads has to happen in the same
+* scheduling context as the queueing.  Otherwise, there is a
+* possibility of one of the above stoppers being woken up by another
+* CPU, and preempting us. This will cause us to not wake up the other
+* stopper forever.
+*/
+   preempt_disable();
raw_spin_lock_irq(>lock);
raw_spin_lock_nested(>lock, SINGLE_DEPTH_NESTING);
 
-   err = -ENOENT;
-   if (!stopper1->enabled || !stopper2->enabled)
+   if (!stopper1->enabled || !stopper2->enabled) {
+   err = -ENOENT;
goto unlock;
+   }
+
/*
 * Ensure that if we race with __stop_cpus() the stoppers won't get
 * queued up in reverse order leading to system deadlock.
@@ -253,36 +264,30 @@ retry:
 * It can be falsely true but it is safe to spin until it is cleared,
 * queue_stop_cpus_work() does everything under preempt_disable().
 */
-   err = -EDEADLK;
-   if (unlikely(stop_cpus_in_progress))
-   goto unlock;
+   if (unlikely(stop_cpus_in_progress)) {
+   err = -EDEADLK;
+   goto unlock;
+   }
 
err = 0;
__cpu_stop_queue_work(stopper1, work1, );
__cpu_stop_queue_work(stopper2, work2, );
-   /*
-* The waking up of stopper threads has to happen
-* in the same scheduling context as the queueing.
-* Otherwise, there is a possibility of one of the
-* above stoppers being woken up by another CPU,
-* and preempting us. This will cause us to n ot
-* wake up the other stopper forever.
-*/
-   preempt_disable();
+
 unlock:
raw_spin_unlock(>lock);
raw_spin_unlock_irq(>lock);
 
if (unlikely(err == -EDEADLK)) {
+   preempt_enable();
+
while (stop_cpus_in_progress)
cpu_relax();
+
goto retry;
}
 
-   if (!err) {
-   wake_up_q();
-   preempt_enable();
-   }
+   wake_up_q();
+   preempt_enable();
 
return err;
 }




[PATCH 4.14 129/165] b43legacy/leds: Ensure NUL-termination of LED name string

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Michael Buesch 

commit 4d77a89e3924b12f4a5628b21237e57ab4703866 upstream.

strncpy might not NUL-terminate the string, if the name equals the buffer size.
Use strlcpy instead.

Signed-off-by: Michael Buesch 
Cc: sta...@vger.kernel.org
Signed-off-by: Kalle Valo 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/net/wireless/broadcom/b43legacy/leds.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/wireless/broadcom/b43legacy/leds.c
+++ b/drivers/net/wireless/broadcom/b43legacy/leds.c
@@ -101,7 +101,7 @@ static int b43legacy_register_led(struct
led->dev = dev;
led->index = led_index;
led->activelow = activelow;
-   strncpy(led->name, name, sizeof(led->name));
+   strlcpy(led->name, name, sizeof(led->name));
 
led->led_dev.name = led->name;
led->led_dev.default_trigger = default_trigger;




[PATCH 4.14 128/165] udl-kms: avoid division

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Mikulas Patocka 

commit 91ba11fb7d7ca0a3bbe8a512e65e666e2ec1e889 upstream.

Division is slow, so it shouldn't be done by the pixel generating code.
The driver supports only 2 or 4 bytes per pixel, so we can replace
division with a shift.

Signed-off-by: Mikulas Patocka 
Cc: sta...@vger.kernel.org
Signed-off-by: Dave Airlie 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/udl/udl_drv.h  |2 -
 drivers/gpu/drm/udl/udl_fb.c   |   15 --
 drivers/gpu/drm/udl/udl_transfer.c |   39 ++---
 3 files changed, 30 insertions(+), 26 deletions(-)

--- a/drivers/gpu/drm/udl/udl_drv.h
+++ b/drivers/gpu/drm/udl/udl_drv.h
@@ -110,7 +110,7 @@ udl_fb_user_fb_create(struct drm_device
  struct drm_file *file,
  const struct drm_mode_fb_cmd2 *mode_cmd);
 
-int udl_render_hline(struct drm_device *dev, int bpp, struct urb **urb_ptr,
+int udl_render_hline(struct drm_device *dev, int log_bpp, struct urb **urb_ptr,
 const char *front, char **urb_buf_ptr,
 u32 byte_offset, u32 device_byte_offset, u32 byte_width,
 int *ident_ptr, int *sent_ptr);
--- a/drivers/gpu/drm/udl/udl_fb.c
+++ b/drivers/gpu/drm/udl/udl_fb.c
@@ -90,7 +90,10 @@ int udl_handle_damage(struct udl_framebu
int bytes_identical = 0;
struct urb *urb;
int aligned_x;
-   int bpp = fb->base.format->cpp[0];
+   int log_bpp;
+
+   BUG_ON(!is_power_of_2(fb->base.format->cpp[0]));
+   log_bpp = __ffs(fb->base.format->cpp[0]);
 
if (!fb->active_16)
return 0;
@@ -125,12 +128,12 @@ int udl_handle_damage(struct udl_framebu
 
for (i = y; i < y + height ; i++) {
const int line_offset = fb->base.pitches[0] * i;
-   const int byte_offset = line_offset + (x * bpp);
-   const int dev_byte_offset = (fb->base.width * bpp * i) + (x * 
bpp);
-   if (udl_render_hline(dev, bpp, ,
+   const int byte_offset = line_offset + (x << log_bpp);
+   const int dev_byte_offset = (fb->base.width * i + x) << log_bpp;
+   if (udl_render_hline(dev, log_bpp, ,
 (char *) fb->obj->vmapping,
 , byte_offset, dev_byte_offset,
-width * bpp,
+width << log_bpp,
 _identical, _sent))
goto error;
}
@@ -149,7 +152,7 @@ int udl_handle_damage(struct udl_framebu
 error:
atomic_add(bytes_sent, >bytes_sent);
atomic_add(bytes_identical, >bytes_identical);
-   atomic_add(width*height*bpp, >bytes_rendered);
+   atomic_add((width * height) << log_bpp, >bytes_rendered);
end_cycles = get_cycles();
atomic_add(((unsigned int) ((end_cycles - start_cycles)
>> 10)), /* Kcycles */
--- a/drivers/gpu/drm/udl/udl_transfer.c
+++ b/drivers/gpu/drm/udl/udl_transfer.c
@@ -83,12 +83,12 @@ static inline u16 pixel32_to_be16(const
((pixel >> 8) & 0xf800));
 }
 
-static inline u16 get_pixel_val16(const uint8_t *pixel, int bpp)
+static inline u16 get_pixel_val16(const uint8_t *pixel, int log_bpp)
 {
-   u16 pixel_val16 = 0;
-   if (bpp == 2)
+   u16 pixel_val16;
+   if (log_bpp == 1)
pixel_val16 = *(const uint16_t *)pixel;
-   else if (bpp == 4)
+   else
pixel_val16 = pixel32_to_be16(*(const uint32_t *)pixel);
return pixel_val16;
 }
@@ -125,8 +125,9 @@ static void udl_compress_hline16(
const u8 *const pixel_end,
uint32_t *device_address_ptr,
uint8_t **command_buffer_ptr,
-   const uint8_t *const cmd_buffer_end, int bpp)
+   const uint8_t *const cmd_buffer_end, int log_bpp)
 {
+   const int bpp = 1 << log_bpp;
const u8 *pixel = *pixel_start_ptr;
uint32_t dev_addr  = *device_address_ptr;
uint8_t *cmd = *command_buffer_ptr;
@@ -153,12 +154,12 @@ static void udl_compress_hline16(
raw_pixels_count_byte = cmd++; /*  we'll know this later */
raw_pixel_start = pixel;
 
-   cmd_pixel_end = pixel + min3(MAX_CMD_PIXELS + 1UL,
-   (unsigned long)(pixel_end - pixel) / 
bpp,
-   (unsigned long)(cmd_buffer_end - 1 - 
cmd) / 2) * bpp;
+   cmd_pixel_end = pixel + (min3(MAX_CMD_PIXELS + 1UL,
+   (unsigned long)(pixel_end - pixel) >> 
log_bpp,
+   (unsigned long)(cmd_buffer_end - 1 - 
cmd) / 2) << log_bpp);
 
prefetch_range((void *) pixel, cmd_pixel_end - pixel);
-   pixel_val16 = get_pixel_val16(pixel, bpp);
+

[PATCH 4.14 129/165] b43legacy/leds: Ensure NUL-termination of LED name string

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Michael Buesch 

commit 4d77a89e3924b12f4a5628b21237e57ab4703866 upstream.

strncpy might not NUL-terminate the string, if the name equals the buffer size.
Use strlcpy instead.

Signed-off-by: Michael Buesch 
Cc: sta...@vger.kernel.org
Signed-off-by: Kalle Valo 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/net/wireless/broadcom/b43legacy/leds.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/wireless/broadcom/b43legacy/leds.c
+++ b/drivers/net/wireless/broadcom/b43legacy/leds.c
@@ -101,7 +101,7 @@ static int b43legacy_register_led(struct
led->dev = dev;
led->index = led_index;
led->activelow = activelow;
-   strncpy(led->name, name, sizeof(led->name));
+   strlcpy(led->name, name, sizeof(led->name));
 
led->led_dev.name = led->name;
led->led_dev.default_trigger = default_trigger;




[PATCH 4.14 128/165] udl-kms: avoid division

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Mikulas Patocka 

commit 91ba11fb7d7ca0a3bbe8a512e65e666e2ec1e889 upstream.

Division is slow, so it shouldn't be done by the pixel generating code.
The driver supports only 2 or 4 bytes per pixel, so we can replace
division with a shift.

Signed-off-by: Mikulas Patocka 
Cc: sta...@vger.kernel.org
Signed-off-by: Dave Airlie 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/udl/udl_drv.h  |2 -
 drivers/gpu/drm/udl/udl_fb.c   |   15 --
 drivers/gpu/drm/udl/udl_transfer.c |   39 ++---
 3 files changed, 30 insertions(+), 26 deletions(-)

--- a/drivers/gpu/drm/udl/udl_drv.h
+++ b/drivers/gpu/drm/udl/udl_drv.h
@@ -110,7 +110,7 @@ udl_fb_user_fb_create(struct drm_device
  struct drm_file *file,
  const struct drm_mode_fb_cmd2 *mode_cmd);
 
-int udl_render_hline(struct drm_device *dev, int bpp, struct urb **urb_ptr,
+int udl_render_hline(struct drm_device *dev, int log_bpp, struct urb **urb_ptr,
 const char *front, char **urb_buf_ptr,
 u32 byte_offset, u32 device_byte_offset, u32 byte_width,
 int *ident_ptr, int *sent_ptr);
--- a/drivers/gpu/drm/udl/udl_fb.c
+++ b/drivers/gpu/drm/udl/udl_fb.c
@@ -90,7 +90,10 @@ int udl_handle_damage(struct udl_framebu
int bytes_identical = 0;
struct urb *urb;
int aligned_x;
-   int bpp = fb->base.format->cpp[0];
+   int log_bpp;
+
+   BUG_ON(!is_power_of_2(fb->base.format->cpp[0]));
+   log_bpp = __ffs(fb->base.format->cpp[0]);
 
if (!fb->active_16)
return 0;
@@ -125,12 +128,12 @@ int udl_handle_damage(struct udl_framebu
 
for (i = y; i < y + height ; i++) {
const int line_offset = fb->base.pitches[0] * i;
-   const int byte_offset = line_offset + (x * bpp);
-   const int dev_byte_offset = (fb->base.width * bpp * i) + (x * 
bpp);
-   if (udl_render_hline(dev, bpp, ,
+   const int byte_offset = line_offset + (x << log_bpp);
+   const int dev_byte_offset = (fb->base.width * i + x) << log_bpp;
+   if (udl_render_hline(dev, log_bpp, ,
 (char *) fb->obj->vmapping,
 , byte_offset, dev_byte_offset,
-width * bpp,
+width << log_bpp,
 _identical, _sent))
goto error;
}
@@ -149,7 +152,7 @@ int udl_handle_damage(struct udl_framebu
 error:
atomic_add(bytes_sent, >bytes_sent);
atomic_add(bytes_identical, >bytes_identical);
-   atomic_add(width*height*bpp, >bytes_rendered);
+   atomic_add((width * height) << log_bpp, >bytes_rendered);
end_cycles = get_cycles();
atomic_add(((unsigned int) ((end_cycles - start_cycles)
>> 10)), /* Kcycles */
--- a/drivers/gpu/drm/udl/udl_transfer.c
+++ b/drivers/gpu/drm/udl/udl_transfer.c
@@ -83,12 +83,12 @@ static inline u16 pixel32_to_be16(const
((pixel >> 8) & 0xf800));
 }
 
-static inline u16 get_pixel_val16(const uint8_t *pixel, int bpp)
+static inline u16 get_pixel_val16(const uint8_t *pixel, int log_bpp)
 {
-   u16 pixel_val16 = 0;
-   if (bpp == 2)
+   u16 pixel_val16;
+   if (log_bpp == 1)
pixel_val16 = *(const uint16_t *)pixel;
-   else if (bpp == 4)
+   else
pixel_val16 = pixel32_to_be16(*(const uint32_t *)pixel);
return pixel_val16;
 }
@@ -125,8 +125,9 @@ static void udl_compress_hline16(
const u8 *const pixel_end,
uint32_t *device_address_ptr,
uint8_t **command_buffer_ptr,
-   const uint8_t *const cmd_buffer_end, int bpp)
+   const uint8_t *const cmd_buffer_end, int log_bpp)
 {
+   const int bpp = 1 << log_bpp;
const u8 *pixel = *pixel_start_ptr;
uint32_t dev_addr  = *device_address_ptr;
uint8_t *cmd = *command_buffer_ptr;
@@ -153,12 +154,12 @@ static void udl_compress_hline16(
raw_pixels_count_byte = cmd++; /*  we'll know this later */
raw_pixel_start = pixel;
 
-   cmd_pixel_end = pixel + min3(MAX_CMD_PIXELS + 1UL,
-   (unsigned long)(pixel_end - pixel) / 
bpp,
-   (unsigned long)(cmd_buffer_end - 1 - 
cmd) / 2) * bpp;
+   cmd_pixel_end = pixel + (min3(MAX_CMD_PIXELS + 1UL,
+   (unsigned long)(pixel_end - pixel) >> 
log_bpp,
+   (unsigned long)(cmd_buffer_end - 1 - 
cmd) / 2) << log_bpp);
 
prefetch_range((void *) pixel, cmd_pixel_end - pixel);
-   pixel_val16 = get_pixel_val16(pixel, bpp);
+

[PATCH 4.14 118/165] fuse: Dont access pipe->buffers without pipe_lock()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Andrey Ryabinin 

commit a2477b0e67c52f4364a47c3ad70902bc2a61bd4c upstream.

fuse_dev_splice_write() reads pipe->buffers to determine the size of
'bufs' array before taking the pipe_lock(). This is not safe as
another thread might change the 'pipe->buffers' between the allocation
and taking the pipe_lock(). So we end up with too small 'bufs' array.

Move the bufs allocations inside pipe_lock()/pipe_unlock() to fix this.

Fixes: dd3bb14f44a6 ("fuse: support splice() writing to fuse device")
Signed-off-by: Andrey Ryabinin 
Cc:  # v2.6.35
Signed-off-by: Miklos Szeredi 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/fuse/dev.c |7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1941,11 +1941,14 @@ static ssize_t fuse_dev_splice_write(str
if (!fud)
return -EPERM;
 
+   pipe_lock(pipe);
+
bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
-   if (!bufs)
+   if (!bufs) {
+   pipe_unlock(pipe);
return -ENOMEM;
+   }
 
-   pipe_lock(pipe);
nbuf = 0;
rem = 0;
for (idx = 0; idx < pipe->nrbufs && rem < len; idx++)




[PATCH 4.14 115/165] x86/process: Re-export start_thread()

2018-09-03 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Rian Hunter 

commit dc76803e57cc86589c4efcb5362918f9b0c0436f upstream.

The consolidation of the start_thread() functions removed the export
unintentionally. This breaks binfmt handlers built as a module.

Add it back.

Fixes: e634d8fc792c ("x86-64: merge the standard and compat start_thread() 
functions")
Signed-off-by: Rian Hunter 
Signed-off-by: Thomas Gleixner 
Cc: "H. Peter Anvin" 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Vitaly Kuznetsov 
Cc: Joerg Roedel 
Cc: Dmitry Safonov 
Cc: Josh Poimboeuf 
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180819230854.7275-1-r...@alum.mit.edu
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/process_64.c |1 +
 1 file changed, 1 insertion(+)

--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -370,6 +370,7 @@ start_thread(struct pt_regs *regs, unsig
start_thread_common(regs, new_ip, new_sp,
__USER_CS, __USER_DS, 0);
 }
+EXPORT_SYMBOL_GPL(start_thread);
 
 #ifdef CONFIG_COMPAT
 void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp)




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