Re: [PATCH v1 2/2] wmi: use generic UUID library

2016-04-09 Thread Darren Hart
On Thu, Apr 07, 2016 at 08:00:55PM +0300, Andy Shevchenko wrote:
> Instead of opencoding let's use generic UUID library functions here.
> 
> Cc: Darren Hart 
> Signed-off-by: Andy Shevchenko 
> ---
>  drivers/platform/x86/wmi.c | 104 
> ++---
>  1 file changed, 13 insertions(+), 91 deletions(-)
> 

My favorite kind of patches :-)

The only functional difference I detected was an additional check/errcode-return
in uuid_le_to_bin, but this is a bug fix in and of itself.

I'm happy to see this go in once the details of the generic uuid library as
discussed in the related threads are ironed out.

Andrew, will you be pulling this in as part of that series?

Reviewed-by: Darren Hart 

> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
> index eb391a2..ceeb8c1 100644
> --- a/drivers/platform/x86/wmi.c
> +++ b/drivers/platform/x86/wmi.c
> @@ -37,6 +37,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  ACPI_MODULE_NAME("wmi");
>  MODULE_AUTHOR("Carlos Corbacho");
> @@ -115,100 +116,21 @@ static struct acpi_driver acpi_wmi_driver = {
>   * GUID parsing functions
>   */
>  
> -/**
> - * wmi_parse_hexbyte - Convert a ASCII hex number to a byte
> - * @src:  Pointer to at least 2 characters to convert.
> - *
> - * Convert a two character ASCII hex string to a number.
> - *
> - * Return:  0-255  Success, the byte was parsed correctly
> - *  -1 Error, an invalid character was supplied
> - */
> -static int wmi_parse_hexbyte(const u8 *src)
> -{
> - int h;
> - int value;
> -
> - /* high part */
> - h = value = hex_to_bin(src[0]);
> - if (value < 0)
> - return -1;
> -
> - /* low part */
> - value = hex_to_bin(src[1]);
> - if (value >= 0)
> - return (h << 4) | value;
> - return -1;
> -}
> -
> -/**
> - * wmi_swap_bytes - Rearrange GUID bytes to match GUID binary
> - * @src:   Memory block holding binary GUID (16 bytes)
> - * @dest:  Memory block to hold byte swapped binary GUID (16 bytes)
> - *
> - * Byte swap a binary GUID to match it's real GUID value
> - */
> -static void wmi_swap_bytes(u8 *src, u8 *dest)
> -{
> - int i;
> -
> - for (i = 0; i <= 3; i++)
> - memcpy(dest + i, src + (3 - i), 1);
> -
> - for (i = 0; i <= 1; i++)
> - memcpy(dest + 4 + i, src + (5 - i), 1);
> -
> - for (i = 0; i <= 1; i++)
> - memcpy(dest + 6 + i, src + (7 - i), 1);
> -
> - memcpy(dest + 8, src + 8, 8);
> -}
> -
> -/**
> - * wmi_parse_guid - Convert GUID from ASCII to binary
> - * @src:   36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
> - * @dest:  Memory block to hold binary GUID (16 bytes)
> - *
> - * N.B. The GUID need not be NULL terminated.
> - *
> - * Return:  'true'   @dest contains binary GUID
> - *  'false'  @dest contents are undefined
> - */
> -static bool wmi_parse_guid(const u8 *src, u8 *dest)
> -{
> - static const int size[] = { 4, 2, 2, 2, 6 };
> - int i, j, v;
> -
> - if (src[8]  != '-' || src[13] != '-' ||
> - src[18] != '-' || src[23] != '-')
> - return false;
> -
> - for (j = 0; j < 5; j++, src++) {
> - for (i = 0; i < size[j]; i++, src += 2, *dest++ = v) {
> - v = wmi_parse_hexbyte(src);
> - if (v < 0)
> - return false;
> - }
> - }
> -
> - return true;
> -}
> -
>  static bool find_guid(const char *guid_string, struct wmi_block **out)
>  {
> - char tmp[16], guid_input[16];
> + uuid_le guid_input;
>   struct wmi_block *wblock;
>   struct guid_block *block;
>   struct list_head *p;
>  
> - wmi_parse_guid(guid_string, tmp);
> - wmi_swap_bytes(tmp, guid_input);
> + if (uuid_le_to_bin(guid_string, _input))
> + return false;
>  
>   list_for_each(p, _block_list) {
>   wblock = list_entry(p, struct wmi_block, list);
>   block = >gblock;
>  
> - if (memcmp(block->guid, guid_input, 16) == 0) {
> + if (memcmp(block->guid, _input, 16) == 0) {
>   if (out)
>   *out = wblock;
>   return true;
> @@ -498,20 +420,20 @@ wmi_notify_handler handler, void *data)
>  {
>   struct wmi_block *block;
>   acpi_status status = AE_NOT_EXIST;
> - char tmp[16], guid_input[16];
> + uuid_le guid_input;
>   struct list_head *p;
>  
>   if (!guid || !handler)
>   return AE_BAD_PARAMETER;
>  
> - wmi_parse_guid(guid, tmp);
> - wmi_swap_bytes(tmp, guid_input);
> + if (uuid_le_to_bin(guid, _input))
> + return AE_BAD_PARAMETER;
>  
>   list_for_each(p, _block_list) {
>   acpi_status wmi_status;
>   block = list_entry(p, struct wmi_block, list);
>  
> - if 

Re: [PATCH v1 2/2] wmi: use generic UUID library

2016-04-09 Thread Darren Hart
On Thu, Apr 07, 2016 at 08:00:55PM +0300, Andy Shevchenko wrote:
> Instead of opencoding let's use generic UUID library functions here.
> 
> Cc: Darren Hart 
> Signed-off-by: Andy Shevchenko 
> ---
>  drivers/platform/x86/wmi.c | 104 
> ++---
>  1 file changed, 13 insertions(+), 91 deletions(-)
> 

My favorite kind of patches :-)

The only functional difference I detected was an additional check/errcode-return
in uuid_le_to_bin, but this is a bug fix in and of itself.

I'm happy to see this go in once the details of the generic uuid library as
discussed in the related threads are ironed out.

Andrew, will you be pulling this in as part of that series?

Reviewed-by: Darren Hart 

> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
> index eb391a2..ceeb8c1 100644
> --- a/drivers/platform/x86/wmi.c
> +++ b/drivers/platform/x86/wmi.c
> @@ -37,6 +37,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  ACPI_MODULE_NAME("wmi");
>  MODULE_AUTHOR("Carlos Corbacho");
> @@ -115,100 +116,21 @@ static struct acpi_driver acpi_wmi_driver = {
>   * GUID parsing functions
>   */
>  
> -/**
> - * wmi_parse_hexbyte - Convert a ASCII hex number to a byte
> - * @src:  Pointer to at least 2 characters to convert.
> - *
> - * Convert a two character ASCII hex string to a number.
> - *
> - * Return:  0-255  Success, the byte was parsed correctly
> - *  -1 Error, an invalid character was supplied
> - */
> -static int wmi_parse_hexbyte(const u8 *src)
> -{
> - int h;
> - int value;
> -
> - /* high part */
> - h = value = hex_to_bin(src[0]);
> - if (value < 0)
> - return -1;
> -
> - /* low part */
> - value = hex_to_bin(src[1]);
> - if (value >= 0)
> - return (h << 4) | value;
> - return -1;
> -}
> -
> -/**
> - * wmi_swap_bytes - Rearrange GUID bytes to match GUID binary
> - * @src:   Memory block holding binary GUID (16 bytes)
> - * @dest:  Memory block to hold byte swapped binary GUID (16 bytes)
> - *
> - * Byte swap a binary GUID to match it's real GUID value
> - */
> -static void wmi_swap_bytes(u8 *src, u8 *dest)
> -{
> - int i;
> -
> - for (i = 0; i <= 3; i++)
> - memcpy(dest + i, src + (3 - i), 1);
> -
> - for (i = 0; i <= 1; i++)
> - memcpy(dest + 4 + i, src + (5 - i), 1);
> -
> - for (i = 0; i <= 1; i++)
> - memcpy(dest + 6 + i, src + (7 - i), 1);
> -
> - memcpy(dest + 8, src + 8, 8);
> -}
> -
> -/**
> - * wmi_parse_guid - Convert GUID from ASCII to binary
> - * @src:   36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
> - * @dest:  Memory block to hold binary GUID (16 bytes)
> - *
> - * N.B. The GUID need not be NULL terminated.
> - *
> - * Return:  'true'   @dest contains binary GUID
> - *  'false'  @dest contents are undefined
> - */
> -static bool wmi_parse_guid(const u8 *src, u8 *dest)
> -{
> - static const int size[] = { 4, 2, 2, 2, 6 };
> - int i, j, v;
> -
> - if (src[8]  != '-' || src[13] != '-' ||
> - src[18] != '-' || src[23] != '-')
> - return false;
> -
> - for (j = 0; j < 5; j++, src++) {
> - for (i = 0; i < size[j]; i++, src += 2, *dest++ = v) {
> - v = wmi_parse_hexbyte(src);
> - if (v < 0)
> - return false;
> - }
> - }
> -
> - return true;
> -}
> -
>  static bool find_guid(const char *guid_string, struct wmi_block **out)
>  {
> - char tmp[16], guid_input[16];
> + uuid_le guid_input;
>   struct wmi_block *wblock;
>   struct guid_block *block;
>   struct list_head *p;
>  
> - wmi_parse_guid(guid_string, tmp);
> - wmi_swap_bytes(tmp, guid_input);
> + if (uuid_le_to_bin(guid_string, _input))
> + return false;
>  
>   list_for_each(p, _block_list) {
>   wblock = list_entry(p, struct wmi_block, list);
>   block = >gblock;
>  
> - if (memcmp(block->guid, guid_input, 16) == 0) {
> + if (memcmp(block->guid, _input, 16) == 0) {
>   if (out)
>   *out = wblock;
>   return true;
> @@ -498,20 +420,20 @@ wmi_notify_handler handler, void *data)
>  {
>   struct wmi_block *block;
>   acpi_status status = AE_NOT_EXIST;
> - char tmp[16], guid_input[16];
> + uuid_le guid_input;
>   struct list_head *p;
>  
>   if (!guid || !handler)
>   return AE_BAD_PARAMETER;
>  
> - wmi_parse_guid(guid, tmp);
> - wmi_swap_bytes(tmp, guid_input);
> + if (uuid_le_to_bin(guid, _input))
> + return AE_BAD_PARAMETER;
>  
>   list_for_each(p, _block_list) {
>   acpi_status wmi_status;
>   block = list_entry(p, struct wmi_block, list);
>  
> - if (memcmp(block->gblock.guid, guid_input, 16) == 0) {
> + if 

Re: [PATCH] cpufreq: Abort cpufreq_update_current_freq() for cpufreq_suspended set

2016-04-09 Thread Viresh Kumar
On 10 April 2016 at 09:38, Rafael J. Wysocki  wrote:
> From: Rafael J. Wysocki 
>
> Since governor operations are generally skipped if cpufreq_suspended
> is set, cpufreq_start_governor() should do nothing in that case.
>
> That function is called in the cpufreq_online() path, and may also
> be called from cpufreq_offline() in some cases, which are invoked
> by the nonboot CPUs disabing/enabling code during system suspend
> to RAM and resume.  That happens when all devices have been
> suspended, so if the cpufreq driver relies on things like I2C to
> get the current frequency, it may not be ready to do that then.
>
> To prevent problems from happening for this reason, make
> cpufreq_update_current_freq(), which is the only function invoked
> by cpufreq_start_governor() that doesn't check cpufreq_suspended
> already, return 0 upfront if cpufreq_suspended is set.
>
> Fixes: 3bbf8fe3ae08 (cpufreq: Always update current frequency before startig 
> governor)
> Signed-off-by: Rafael J. Wysocki 
> ---
>  drivers/cpufreq/cpufreq.c |3 +++
>  1 file changed, 3 insertions(+)
>
> Index: linux-pm/drivers/cpufreq/cpufreq.c
> ===
> --- linux-pm.orig/drivers/cpufreq/cpufreq.c
> +++ linux-pm/drivers/cpufreq/cpufreq.c
> @@ -1565,6 +1565,9 @@ static unsigned int cpufreq_update_curre
>  {
> unsigned int new_freq;
>
> +   if (cpufreq_suspended)
> +   return 0;
> +
> new_freq = cpufreq_driver->get(policy->cpu);
> if (!new_freq)
> return 0;

Acked-by: Viresh Kumar 


Re: [PATCH] cpufreq: Abort cpufreq_update_current_freq() for cpufreq_suspended set

2016-04-09 Thread Viresh Kumar
On 10 April 2016 at 09:38, Rafael J. Wysocki  wrote:
> From: Rafael J. Wysocki 
>
> Since governor operations are generally skipped if cpufreq_suspended
> is set, cpufreq_start_governor() should do nothing in that case.
>
> That function is called in the cpufreq_online() path, and may also
> be called from cpufreq_offline() in some cases, which are invoked
> by the nonboot CPUs disabing/enabling code during system suspend
> to RAM and resume.  That happens when all devices have been
> suspended, so if the cpufreq driver relies on things like I2C to
> get the current frequency, it may not be ready to do that then.
>
> To prevent problems from happening for this reason, make
> cpufreq_update_current_freq(), which is the only function invoked
> by cpufreq_start_governor() that doesn't check cpufreq_suspended
> already, return 0 upfront if cpufreq_suspended is set.
>
> Fixes: 3bbf8fe3ae08 (cpufreq: Always update current frequency before startig 
> governor)
> Signed-off-by: Rafael J. Wysocki 
> ---
>  drivers/cpufreq/cpufreq.c |3 +++
>  1 file changed, 3 insertions(+)
>
> Index: linux-pm/drivers/cpufreq/cpufreq.c
> ===
> --- linux-pm.orig/drivers/cpufreq/cpufreq.c
> +++ linux-pm/drivers/cpufreq/cpufreq.c
> @@ -1565,6 +1565,9 @@ static unsigned int cpufreq_update_curre
>  {
> unsigned int new_freq;
>
> +   if (cpufreq_suspended)
> +   return 0;
> +
> new_freq = cpufreq_driver->get(policy->cpu);
> if (!new_freq)
> return 0;

Acked-by: Viresh Kumar 


[PATCH] intel_pstate: Avoid getting stuck in high P-states when idle

2016-04-09 Thread Rafael J. Wysocki
From: Rafael J. Wysocki 

Jörg Otte reports that commit a4675fbc4a7a (cpufreq: intel_pstate:
Replace timers with utilization update callbacks) caused the CPUs in
his Haswell-based system to stay in the very high frequency region
even if the system is completely idle.

That turns out to be an existing problem in the intel_pstate driver's
P-state selection algorithm for Core processors.  Namely, all
decisions made by that algorithm are based on the average frequency
of the CPU between sampling events and on the P-state requested on
the last invocation, so it may get stuck at a very hight frequency
even if the utilization of the CPU is very low (in fact, it may get
stuck in a inadequate P-state regardless of the CPU utilization).
The only way to kick it out of that limbo is a sufficiently long idle
period (3 times longer than the prescribed sampling interval), but if
that doesn't happen often enough (eg. due to a timing change like
after the above commit), the P-state of the CPU may be inadequate
pretty much all the time.

To address the most egregious manifestations of that issue, reset the
core_busy value used to determine the next P-state to request if the
utilization of the CPU, determined with the help of the MPERF
feedback register and the TSC, is below 1%.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=115771
Reported-and-tested-by: Jörg Otte 
Signed-off-by: Rafael J. Wysocki 
---
 drivers/cpufreq/intel_pstate.c |4 
 1 file changed, 4 insertions(+)

Index: linux-pm/drivers/cpufreq/intel_pstate.c
===
--- linux-pm.orig/drivers/cpufreq/intel_pstate.c
+++ linux-pm/drivers/cpufreq/intel_pstate.c
@@ -995,6 +995,10 @@ static inline int32_t get_target_pstate_
sample_ratio = div_fp(int_tofp(pid_params.sample_rate_ns),
  int_tofp(duration_ns));
core_busy = mul_fp(core_busy, sample_ratio);
+   } else {
+   sample_ratio = div_fp(100 * cpu->sample.mperf, cpu->sample.tsc);
+   if (sample_ratio < int_tofp(1))
+   core_busy = 0;
}
 
cpu->sample.busy_scaled = core_busy;



[PATCH] intel_pstate: Avoid getting stuck in high P-states when idle

2016-04-09 Thread Rafael J. Wysocki
From: Rafael J. Wysocki 

Jörg Otte reports that commit a4675fbc4a7a (cpufreq: intel_pstate:
Replace timers with utilization update callbacks) caused the CPUs in
his Haswell-based system to stay in the very high frequency region
even if the system is completely idle.

That turns out to be an existing problem in the intel_pstate driver's
P-state selection algorithm for Core processors.  Namely, all
decisions made by that algorithm are based on the average frequency
of the CPU between sampling events and on the P-state requested on
the last invocation, so it may get stuck at a very hight frequency
even if the utilization of the CPU is very low (in fact, it may get
stuck in a inadequate P-state regardless of the CPU utilization).
The only way to kick it out of that limbo is a sufficiently long idle
period (3 times longer than the prescribed sampling interval), but if
that doesn't happen often enough (eg. due to a timing change like
after the above commit), the P-state of the CPU may be inadequate
pretty much all the time.

To address the most egregious manifestations of that issue, reset the
core_busy value used to determine the next P-state to request if the
utilization of the CPU, determined with the help of the MPERF
feedback register and the TSC, is below 1%.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=115771
Reported-and-tested-by: Jörg Otte 
Signed-off-by: Rafael J. Wysocki 
---
 drivers/cpufreq/intel_pstate.c |4 
 1 file changed, 4 insertions(+)

Index: linux-pm/drivers/cpufreq/intel_pstate.c
===
--- linux-pm.orig/drivers/cpufreq/intel_pstate.c
+++ linux-pm/drivers/cpufreq/intel_pstate.c
@@ -995,6 +995,10 @@ static inline int32_t get_target_pstate_
sample_ratio = div_fp(int_tofp(pid_params.sample_rate_ns),
  int_tofp(duration_ns));
core_busy = mul_fp(core_busy, sample_ratio);
+   } else {
+   sample_ratio = div_fp(100 * cpu->sample.mperf, cpu->sample.tsc);
+   if (sample_ratio < int_tofp(1))
+   core_busy = 0;
}
 
cpu->sample.busy_scaled = core_busy;



[PATCH] cpufreq: Abort cpufreq_update_current_freq() for cpufreq_suspended set

2016-04-09 Thread Rafael J. Wysocki
From: Rafael J. Wysocki 

Since governor operations are generally skipped if cpufreq_suspended
is set, cpufreq_start_governor() should do nothing in that case.

That function is called in the cpufreq_online() path, and may also
be called from cpufreq_offline() in some cases, which are invoked
by the nonboot CPUs disabing/enabling code during system suspend
to RAM and resume.  That happens when all devices have been
suspended, so if the cpufreq driver relies on things like I2C to
get the current frequency, it may not be ready to do that then.

To prevent problems from happening for this reason, make
cpufreq_update_current_freq(), which is the only function invoked
by cpufreq_start_governor() that doesn't check cpufreq_suspended
already, return 0 upfront if cpufreq_suspended is set.

Fixes: 3bbf8fe3ae08 (cpufreq: Always update current frequency before startig 
governor)
Signed-off-by: Rafael J. Wysocki 
---
 drivers/cpufreq/cpufreq.c |3 +++
 1 file changed, 3 insertions(+)

Index: linux-pm/drivers/cpufreq/cpufreq.c
===
--- linux-pm.orig/drivers/cpufreq/cpufreq.c
+++ linux-pm/drivers/cpufreq/cpufreq.c
@@ -1565,6 +1565,9 @@ static unsigned int cpufreq_update_curre
 {
unsigned int new_freq;
 
+   if (cpufreq_suspended)
+   return 0;
+
new_freq = cpufreq_driver->get(policy->cpu);
if (!new_freq)
return 0;



[PATCH] cpufreq: Abort cpufreq_update_current_freq() for cpufreq_suspended set

2016-04-09 Thread Rafael J. Wysocki
From: Rafael J. Wysocki 

Since governor operations are generally skipped if cpufreq_suspended
is set, cpufreq_start_governor() should do nothing in that case.

That function is called in the cpufreq_online() path, and may also
be called from cpufreq_offline() in some cases, which are invoked
by the nonboot CPUs disabing/enabling code during system suspend
to RAM and resume.  That happens when all devices have been
suspended, so if the cpufreq driver relies on things like I2C to
get the current frequency, it may not be ready to do that then.

To prevent problems from happening for this reason, make
cpufreq_update_current_freq(), which is the only function invoked
by cpufreq_start_governor() that doesn't check cpufreq_suspended
already, return 0 upfront if cpufreq_suspended is set.

Fixes: 3bbf8fe3ae08 (cpufreq: Always update current frequency before startig 
governor)
Signed-off-by: Rafael J. Wysocki 
---
 drivers/cpufreq/cpufreq.c |3 +++
 1 file changed, 3 insertions(+)

Index: linux-pm/drivers/cpufreq/cpufreq.c
===
--- linux-pm.orig/drivers/cpufreq/cpufreq.c
+++ linux-pm/drivers/cpufreq/cpufreq.c
@@ -1565,6 +1565,9 @@ static unsigned int cpufreq_update_curre
 {
unsigned int new_freq;
 
+   if (cpufreq_suspended)
+   return 0;
+
new_freq = cpufreq_driver->get(policy->cpu);
if (!new_freq)
return 0;



Re: [PATCH] cpufreq: Skip all governor-related actions for cpufreq_suspended set

2016-04-09 Thread Rafael J. Wysocki
On Sun, Apr 10, 2016 at 5:16 AM, Viresh Kumar  wrote:
> On 08-04-16, 23:54, Rafael J. Wysocki wrote:
>> From: Rafael J. Wysocki 
>> Subject: [PATCH] cpufreq: Skip all governor-related actions for 
>> cpufreq_suspended set
>>
>> Since governor operations are generally skipped if cpufreq_suspended
>> is set, do nothing at all in cpufreq_start_governor() in that case.
>>
>> That function is called in the cpufreq_online() path, and may also
>> be called from cpufreq_offline() in some cases, which are invoked
>> by the nonboot CPUs disabing/enabling code during system suspend
>> to RAM and resume.  That happens when all devices have been
>> suspended, so if the cpufreq driver relies on things like I2C to
>> get the current frequency, it may not be ready to do that then.
>>
>> The change here prevents problems from happening for this reason.
>>
>> Fixes: 3bbf8fe3ae08 (cpufreq: Always update current frequency before startig 
>> governor)
>> Signed-off-by: Rafael J. Wysocki 
>> Acked-by: Viresh Kumar 
>> ---
>>  drivers/cpufreq/cpufreq.c |6 ++
>>  1 file changed, 6 insertions(+)
>>
>> Index: linux-pm/drivers/cpufreq/cpufreq.c
>> ===
>> --- linux-pm.orig/drivers/cpufreq/cpufreq.c
>> +++ linux-pm/drivers/cpufreq/cpufreq.c
>> @@ -2053,6 +2053,9 @@ static int cpufreq_start_governor(struct
>>  {
>>   int ret;
>>
>> + if (cpufreq_suspended)
>> + return 0;
>> +
>>   if (cpufreq_driver->get && !cpufreq_driver->setpolicy)
>>   cpufreq_update_current_freq(policy);
>
> Since we no longer have the same check in cpufreq_exit_governor(),
> what about moving it to cpufreq_update_current_freq() instead? That's
> all we are trying to protect here anyway, as cpufreq_governor() is
> already protected.

That can be done too.


Re: [PATCH] cpufreq: Skip all governor-related actions for cpufreq_suspended set

2016-04-09 Thread Rafael J. Wysocki
On Sun, Apr 10, 2016 at 5:16 AM, Viresh Kumar  wrote:
> On 08-04-16, 23:54, Rafael J. Wysocki wrote:
>> From: Rafael J. Wysocki 
>> Subject: [PATCH] cpufreq: Skip all governor-related actions for 
>> cpufreq_suspended set
>>
>> Since governor operations are generally skipped if cpufreq_suspended
>> is set, do nothing at all in cpufreq_start_governor() in that case.
>>
>> That function is called in the cpufreq_online() path, and may also
>> be called from cpufreq_offline() in some cases, which are invoked
>> by the nonboot CPUs disabing/enabling code during system suspend
>> to RAM and resume.  That happens when all devices have been
>> suspended, so if the cpufreq driver relies on things like I2C to
>> get the current frequency, it may not be ready to do that then.
>>
>> The change here prevents problems from happening for this reason.
>>
>> Fixes: 3bbf8fe3ae08 (cpufreq: Always update current frequency before startig 
>> governor)
>> Signed-off-by: Rafael J. Wysocki 
>> Acked-by: Viresh Kumar 
>> ---
>>  drivers/cpufreq/cpufreq.c |6 ++
>>  1 file changed, 6 insertions(+)
>>
>> Index: linux-pm/drivers/cpufreq/cpufreq.c
>> ===
>> --- linux-pm.orig/drivers/cpufreq/cpufreq.c
>> +++ linux-pm/drivers/cpufreq/cpufreq.c
>> @@ -2053,6 +2053,9 @@ static int cpufreq_start_governor(struct
>>  {
>>   int ret;
>>
>> + if (cpufreq_suspended)
>> + return 0;
>> +
>>   if (cpufreq_driver->get && !cpufreq_driver->setpolicy)
>>   cpufreq_update_current_freq(policy);
>
> Since we no longer have the same check in cpufreq_exit_governor(),
> what about moving it to cpufreq_update_current_freq() instead? That's
> all we are trying to protect here anyway, as cpufreq_governor() is
> already protected.

That can be done too.


Re: [regression] cross core scheduling frequency drop bisected to 0c313cb20732

2016-04-09 Thread Rafael J. Wysocki
On Sat, Apr 9, 2016 at 6:39 PM, Mike Galbraith  wrote:
>
> Hm, setting gov=performance, and taking the average of 3 30 second
> interval PkgWatt samples as pipe-test runs..
>
> 714KHz/28.03Ws = 25.46
> 877KHz/30.28Ws = 28.96
>
> ..for pipe-test, the tradeoff look a bit more like red than green.

Well, fair enough, but that's just pipe-test, and what about the
people who don't see the performance gain and see the energy loss,
like Doug?

Essentially, this trades performance gains in somewhat special
workloads for increased energy consumption in idle.  Those workloads
need not be run by everybody, but idle is.

That said I applied the patch you're complaining about mostly because
the commit that introduced the change in question in 4.5 claimed that
it wouldn't affect idle power on systems with reasonably fast C1, but
that didn't pass the reality test.  I'm not totally against restoring
that change, but it would need to be based on very solid evidence.


Re: [regression] cross core scheduling frequency drop bisected to 0c313cb20732

2016-04-09 Thread Rafael J. Wysocki
On Sat, Apr 9, 2016 at 6:39 PM, Mike Galbraith  wrote:
>
> Hm, setting gov=performance, and taking the average of 3 30 second
> interval PkgWatt samples as pipe-test runs..
>
> 714KHz/28.03Ws = 25.46
> 877KHz/30.28Ws = 28.96
>
> ..for pipe-test, the tradeoff look a bit more like red than green.

Well, fair enough, but that's just pipe-test, and what about the
people who don't see the performance gain and see the energy loss,
like Doug?

Essentially, this trades performance gains in somewhat special
workloads for increased energy consumption in idle.  Those workloads
need not be run by everybody, but idle is.

That said I applied the patch you're complaining about mostly because
the commit that introduced the change in question in 4.5 claimed that
it wouldn't affect idle power on systems with reasonably fast C1, but
that didn't pass the reality test.  I'm not totally against restoring
that change, but it would need to be based on very solid evidence.


[PATCH 1/2] tty: Remove unused TTY_NUMBER() macro

2016-04-09 Thread Peter Hurley
TTY_NUMBER() has been unused since v2.5.71; removed by
"[PATCH] callout removal: callout is gone".

Signed-off-by: Peter Hurley 
---
 drivers/tty/tty_io.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 320dc4d..3cdd63b 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -230,9 +230,6 @@ static void tty_del_file(struct file *file)
tty_free_file(file);
 }
 
-
-#define TTY_NUMBER(tty) ((tty)->index + (tty)->driver->name_base)
-
 /**
  * tty_name-   return tty naming
  * @tty: tty structure
-- 
2.8.1



[PATCH 2/2] tty: Remove stale parameter comment

2016-04-09 Thread Peter Hurley
noctty was removed as a parameter by commit 216513411937586
("tty: Consolidate noctty check in tty_open()").

Signed-off-by: Peter Hurley 
---
 drivers/tty/tty_io.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 3cdd63b..50979be 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1960,7 +1960,6 @@ static struct tty_struct *tty_open_current_tty(dev_t 
device, struct file *filp)
  * tty_lookup_driver - lookup a tty driver for a given device file
  * @device: device number
  * @filp: file pointer to tty
- * @noctty: set if the device should not become a controlling tty
  * @index: index for the device in the @return driver
  * @return: driver for this inode (with increased refcount)
  *
-- 
2.8.1



[PATCH 1/2] tty: Remove unused TTY_NUMBER() macro

2016-04-09 Thread Peter Hurley
TTY_NUMBER() has been unused since v2.5.71; removed by
"[PATCH] callout removal: callout is gone".

Signed-off-by: Peter Hurley 
---
 drivers/tty/tty_io.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 320dc4d..3cdd63b 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -230,9 +230,6 @@ static void tty_del_file(struct file *file)
tty_free_file(file);
 }
 
-
-#define TTY_NUMBER(tty) ((tty)->index + (tty)->driver->name_base)
-
 /**
  * tty_name-   return tty naming
  * @tty: tty structure
-- 
2.8.1



[PATCH 2/2] tty: Remove stale parameter comment

2016-04-09 Thread Peter Hurley
noctty was removed as a parameter by commit 216513411937586
("tty: Consolidate noctty check in tty_open()").

Signed-off-by: Peter Hurley 
---
 drivers/tty/tty_io.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 3cdd63b..50979be 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1960,7 +1960,6 @@ static struct tty_struct *tty_open_current_tty(dev_t 
device, struct file *filp)
  * tty_lookup_driver - lookup a tty driver for a given device file
  * @device: device number
  * @filp: file pointer to tty
- * @noctty: set if the device should not become a controlling tty
  * @index: index for the device in the @return driver
  * @return: driver for this inode (with increased refcount)
  *
-- 
2.8.1



Re: [PATCH 2/2] asus-laptop: remove unused variable

2016-04-09 Thread Darren Hart
On Thu, Apr 07, 2016 at 11:20:01PM +0300, Giedrius Statkevičius wrote:
> `out' was assigned value but it was never used so remove it
> 
> Signed-off-by: Giedrius Statkevičius 
> ---
>  drivers/platform/x86/asus-laptop.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/platform/x86/asus-laptop.c 
> b/drivers/platform/x86/asus-laptop.c
> index d86d42e..39ddcee 100644
> --- a/drivers/platform/x86/asus-laptop.c
> +++ b/drivers/platform/x86/asus-laptop.c
> @@ -946,11 +946,8 @@ static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
> const char *method)
>  {
>   int rv, value;
> - int out = 0;
>  
>   rv = parse_arg(buf, count, );
> - if (rv > 0)
> - out = value ? 1 : 0;
>  
>   if (write_acpi_int(asus->handle, method, value))

out is indeed unused, however the rv > 0 condition is relevant as <=0 will pass
value uninitialized to write_acpi_int.

-- 
Darren Hart
Intel Open Source Technology Center


Re: [PATCH 2/2] asus-laptop: remove unused variable

2016-04-09 Thread Darren Hart
On Thu, Apr 07, 2016 at 11:20:01PM +0300, Giedrius Statkevičius wrote:
> `out' was assigned value but it was never used so remove it
> 
> Signed-off-by: Giedrius Statkevičius 
> ---
>  drivers/platform/x86/asus-laptop.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/platform/x86/asus-laptop.c 
> b/drivers/platform/x86/asus-laptop.c
> index d86d42e..39ddcee 100644
> --- a/drivers/platform/x86/asus-laptop.c
> +++ b/drivers/platform/x86/asus-laptop.c
> @@ -946,11 +946,8 @@ static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
> const char *method)
>  {
>   int rv, value;
> - int out = 0;
>  
>   rv = parse_arg(buf, count, );
> - if (rv > 0)
> - out = value ? 1 : 0;
>  
>   if (write_acpi_int(asus->handle, method, value))

out is indeed unused, however the rv > 0 condition is relevant as <=0 will pass
value uninitialized to write_acpi_int.

-- 
Darren Hart
Intel Open Source Technology Center


Re: [PATCH] cpufreq: Skip all governor-related actions for cpufreq_suspended set

2016-04-09 Thread Viresh Kumar
On 08-04-16, 23:54, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki 
> Subject: [PATCH] cpufreq: Skip all governor-related actions for 
> cpufreq_suspended set
> 
> Since governor operations are generally skipped if cpufreq_suspended
> is set, do nothing at all in cpufreq_start_governor() in that case.
> 
> That function is called in the cpufreq_online() path, and may also
> be called from cpufreq_offline() in some cases, which are invoked
> by the nonboot CPUs disabing/enabling code during system suspend
> to RAM and resume.  That happens when all devices have been
> suspended, so if the cpufreq driver relies on things like I2C to
> get the current frequency, it may not be ready to do that then.
> 
> The change here prevents problems from happening for this reason.
> 
> Fixes: 3bbf8fe3ae08 (cpufreq: Always update current frequency before startig 
> governor)
> Signed-off-by: Rafael J. Wysocki 
> Acked-by: Viresh Kumar 
> ---
>  drivers/cpufreq/cpufreq.c |6 ++
>  1 file changed, 6 insertions(+)
> 
> Index: linux-pm/drivers/cpufreq/cpufreq.c
> ===
> --- linux-pm.orig/drivers/cpufreq/cpufreq.c
> +++ linux-pm/drivers/cpufreq/cpufreq.c
> @@ -2053,6 +2053,9 @@ static int cpufreq_start_governor(struct
>  {
>   int ret;
>  
> + if (cpufreq_suspended)
> + return 0;
> +
>   if (cpufreq_driver->get && !cpufreq_driver->setpolicy)
>   cpufreq_update_current_freq(policy);

Since we no longer have the same check in cpufreq_exit_governor(),
what about moving it to cpufreq_update_current_freq() instead? That's
all we are trying to protect here anyway, as cpufreq_governor() is
already protected.

-- 
viresh


Re: [PATCH] cpufreq: Skip all governor-related actions for cpufreq_suspended set

2016-04-09 Thread Viresh Kumar
On 08-04-16, 23:54, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki 
> Subject: [PATCH] cpufreq: Skip all governor-related actions for 
> cpufreq_suspended set
> 
> Since governor operations are generally skipped if cpufreq_suspended
> is set, do nothing at all in cpufreq_start_governor() in that case.
> 
> That function is called in the cpufreq_online() path, and may also
> be called from cpufreq_offline() in some cases, which are invoked
> by the nonboot CPUs disabing/enabling code during system suspend
> to RAM and resume.  That happens when all devices have been
> suspended, so if the cpufreq driver relies on things like I2C to
> get the current frequency, it may not be ready to do that then.
> 
> The change here prevents problems from happening for this reason.
> 
> Fixes: 3bbf8fe3ae08 (cpufreq: Always update current frequency before startig 
> governor)
> Signed-off-by: Rafael J. Wysocki 
> Acked-by: Viresh Kumar 
> ---
>  drivers/cpufreq/cpufreq.c |6 ++
>  1 file changed, 6 insertions(+)
> 
> Index: linux-pm/drivers/cpufreq/cpufreq.c
> ===
> --- linux-pm.orig/drivers/cpufreq/cpufreq.c
> +++ linux-pm/drivers/cpufreq/cpufreq.c
> @@ -2053,6 +2053,9 @@ static int cpufreq_start_governor(struct
>  {
>   int ret;
>  
> + if (cpufreq_suspended)
> + return 0;
> +
>   if (cpufreq_driver->get && !cpufreq_driver->setpolicy)
>   cpufreq_update_current_freq(policy);

Since we no longer have the same check in cpufreq_exit_governor(),
what about moving it to cpufreq_update_current_freq() instead? That's
all we are trying to protect here anyway, as cpufreq_governor() is
already protected.

-- 
viresh


Re: [PATCH] nilfs2: constify nilfs_sc_operations structures

2016-04-09 Thread Ryusuke Konishi
On Sat,  9 Apr 2016 10:28:23 +0200, Julia Lawall wrote:
> The nilfs_sc_operations structures are never modified, so declare them
> as const.
> 
> Done with the help of Coccinelle.
> 
> Signed-off-by: Julia Lawall 
> 

Applied, thanks.

Ryusuke Konishi

> ---
>  fs/nilfs2/segment.c |   10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
> index 4317f72..483e663 100644
> --- a/fs/nilfs2/segment.c
> +++ b/fs/nilfs2/segment.c
> @@ -617,7 +617,7 @@ static void nilfs_write_file_node_binfo(struct 
> nilfs_sc_info *sci,
>   *vblocknr = binfo->bi_v.bi_vblocknr;
>  }
>  
> -static struct nilfs_sc_operations nilfs_sc_file_ops = {
> +static const struct nilfs_sc_operations nilfs_sc_file_ops = {
>   .collect_data = nilfs_collect_file_data,
>   .collect_node = nilfs_collect_file_node,
>   .collect_bmap = nilfs_collect_file_bmap,
> @@ -666,7 +666,7 @@ static void nilfs_write_dat_node_binfo(struct 
> nilfs_sc_info *sci,
>   *binfo_dat = binfo->bi_dat;
>  }
>  
> -static struct nilfs_sc_operations nilfs_sc_dat_ops = {
> +static const struct nilfs_sc_operations nilfs_sc_dat_ops = {
>   .collect_data = nilfs_collect_dat_data,
>   .collect_node = nilfs_collect_file_node,
>   .collect_bmap = nilfs_collect_dat_bmap,
> @@ -674,7 +674,7 @@ static struct nilfs_sc_operations nilfs_sc_dat_ops = {
>   .write_node_binfo = nilfs_write_dat_node_binfo,
>  };
>  
> -static struct nilfs_sc_operations nilfs_sc_dsync_ops = {
> +static const struct nilfs_sc_operations nilfs_sc_dsync_ops = {
>   .collect_data = nilfs_collect_file_data,
>   .collect_node = NULL,
>   .collect_bmap = NULL,
> @@ -1043,7 +1043,7 @@ static size_t nilfs_segctor_buffer_rest(struct 
> nilfs_sc_info *sci)
>  
>  static int nilfs_segctor_scan_file(struct nilfs_sc_info *sci,
>  struct inode *inode,
> -struct nilfs_sc_operations *sc_ops)
> +const struct nilfs_sc_operations *sc_ops)
>  {
>   LIST_HEAD(data_buffers);
>   LIST_HEAD(node_buffers);
> @@ -1550,7 +1550,7 @@ nilfs_segctor_update_payload_blocknr(struct 
> nilfs_sc_info *sci,
>   sector_t blocknr;
>   unsigned long nfinfo = segbuf->sb_sum.nfinfo;
>   unsigned long nblocks = 0, ndatablk = 0;
> - struct nilfs_sc_operations *sc_op = NULL;
> + const struct nilfs_sc_operations *sc_op = NULL;
>   struct nilfs_segsum_pointer ssp;
>   struct nilfs_finfo *finfo = NULL;
>   union nilfs_binfo binfo;
> 


Re: [PATCH] nilfs2: constify nilfs_sc_operations structures

2016-04-09 Thread Ryusuke Konishi
On Sat,  9 Apr 2016 10:28:23 +0200, Julia Lawall wrote:
> The nilfs_sc_operations structures are never modified, so declare them
> as const.
> 
> Done with the help of Coccinelle.
> 
> Signed-off-by: Julia Lawall 
> 

Applied, thanks.

Ryusuke Konishi

> ---
>  fs/nilfs2/segment.c |   10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
> index 4317f72..483e663 100644
> --- a/fs/nilfs2/segment.c
> +++ b/fs/nilfs2/segment.c
> @@ -617,7 +617,7 @@ static void nilfs_write_file_node_binfo(struct 
> nilfs_sc_info *sci,
>   *vblocknr = binfo->bi_v.bi_vblocknr;
>  }
>  
> -static struct nilfs_sc_operations nilfs_sc_file_ops = {
> +static const struct nilfs_sc_operations nilfs_sc_file_ops = {
>   .collect_data = nilfs_collect_file_data,
>   .collect_node = nilfs_collect_file_node,
>   .collect_bmap = nilfs_collect_file_bmap,
> @@ -666,7 +666,7 @@ static void nilfs_write_dat_node_binfo(struct 
> nilfs_sc_info *sci,
>   *binfo_dat = binfo->bi_dat;
>  }
>  
> -static struct nilfs_sc_operations nilfs_sc_dat_ops = {
> +static const struct nilfs_sc_operations nilfs_sc_dat_ops = {
>   .collect_data = nilfs_collect_dat_data,
>   .collect_node = nilfs_collect_file_node,
>   .collect_bmap = nilfs_collect_dat_bmap,
> @@ -674,7 +674,7 @@ static struct nilfs_sc_operations nilfs_sc_dat_ops = {
>   .write_node_binfo = nilfs_write_dat_node_binfo,
>  };
>  
> -static struct nilfs_sc_operations nilfs_sc_dsync_ops = {
> +static const struct nilfs_sc_operations nilfs_sc_dsync_ops = {
>   .collect_data = nilfs_collect_file_data,
>   .collect_node = NULL,
>   .collect_bmap = NULL,
> @@ -1043,7 +1043,7 @@ static size_t nilfs_segctor_buffer_rest(struct 
> nilfs_sc_info *sci)
>  
>  static int nilfs_segctor_scan_file(struct nilfs_sc_info *sci,
>  struct inode *inode,
> -struct nilfs_sc_operations *sc_ops)
> +const struct nilfs_sc_operations *sc_ops)
>  {
>   LIST_HEAD(data_buffers);
>   LIST_HEAD(node_buffers);
> @@ -1550,7 +1550,7 @@ nilfs_segctor_update_payload_blocknr(struct 
> nilfs_sc_info *sci,
>   sector_t blocknr;
>   unsigned long nfinfo = segbuf->sb_sum.nfinfo;
>   unsigned long nblocks = 0, ndatablk = 0;
> - struct nilfs_sc_operations *sc_op = NULL;
> + const struct nilfs_sc_operations *sc_op = NULL;
>   struct nilfs_segsum_pointer ssp;
>   struct nilfs_finfo *finfo = NULL;
>   union nilfs_binfo binfo;
> 


RE: [PATCH v2] gpio: pca953x: add PCAL9535 interrupt support for Galileo Gen2

2016-04-09 Thread Li, Yong B
Thanks Linus. I think the below patch(in fixes branch) should be merged into 
devel branch too, since the below patch is depended by this one in devel branch.

commit 9b8e3ec34318663affced3c14d960e78d760dd9a
Author: Yong Li 
Date:   Wed Mar 30 14:49:14 2016 +0800

gpio: pca953x: Use correct u16 value for register word write

The current implementation only uses the first byte in val,
the second byte is always 0. Change it to use cpu_to_le16
to write the two bytes into the register

Cc: sta...@vger.kernel.org
Signed-off-by: Yong Li 
Reviewed-by: Phil Reid 
Signed-off-by: Linus Walleij 

Yong
> -Original Message-
> From: Linus Walleij [mailto:linus.wall...@linaro.org]
> Sent: Friday, April 08, 2016 21:21
> To: Li, Yong B 
> Cc: linux-g...@vger.kernel.org; linux-kernel@vger.kernel.org; Alexandre
> Courbot ; Andy Shevchenko
> ; Puustinen, Ismo
> ; Phil Reid 
> Subject: Re: [PATCH v2] gpio: pca953x: add PCAL9535 interrupt support for
> Galileo Gen2
> 
> n Thu, Apr 7, 2016 at 6:56 AM, Yong Li  wrote:
> 
> > Galileo Gen2 board uses the PCAL9535 as the GPIO expansion, it is
> > different from PCA9535 and includes interrupt mask/status registers,
> > The current driver does not support the interrupt registers
> > configuration, it causes some gpio pins cannot trigger interrupt
> > events, this patch fix this issue. The original patch was submitted by
> > Josef Ahmad 
> > http://git.yoctoproject.org/cgit/cgit.cgi/meta-intel-quark/tree/recipe
> > s-kernel/linux/files/0015-Quark-GPIO-1-2-quark.patch
> >
> > Signed-off-by: Yong Li 
> 
> Patch applied with Andy's review tag.
> 
> Yours,
> Linus Walleij


RE: [PATCH v2] gpio: pca953x: add PCAL9535 interrupt support for Galileo Gen2

2016-04-09 Thread Li, Yong B
Thanks Linus. I think the below patch(in fixes branch) should be merged into 
devel branch too, since the below patch is depended by this one in devel branch.

commit 9b8e3ec34318663affced3c14d960e78d760dd9a
Author: Yong Li 
Date:   Wed Mar 30 14:49:14 2016 +0800

gpio: pca953x: Use correct u16 value for register word write

The current implementation only uses the first byte in val,
the second byte is always 0. Change it to use cpu_to_le16
to write the two bytes into the register

Cc: sta...@vger.kernel.org
Signed-off-by: Yong Li 
Reviewed-by: Phil Reid 
Signed-off-by: Linus Walleij 

Yong
> -Original Message-
> From: Linus Walleij [mailto:linus.wall...@linaro.org]
> Sent: Friday, April 08, 2016 21:21
> To: Li, Yong B 
> Cc: linux-g...@vger.kernel.org; linux-kernel@vger.kernel.org; Alexandre
> Courbot ; Andy Shevchenko
> ; Puustinen, Ismo
> ; Phil Reid 
> Subject: Re: [PATCH v2] gpio: pca953x: add PCAL9535 interrupt support for
> Galileo Gen2
> 
> n Thu, Apr 7, 2016 at 6:56 AM, Yong Li  wrote:
> 
> > Galileo Gen2 board uses the PCAL9535 as the GPIO expansion, it is
> > different from PCA9535 and includes interrupt mask/status registers,
> > The current driver does not support the interrupt registers
> > configuration, it causes some gpio pins cannot trigger interrupt
> > events, this patch fix this issue. The original patch was submitted by
> > Josef Ahmad 
> > http://git.yoctoproject.org/cgit/cgit.cgi/meta-intel-quark/tree/recipe
> > s-kernel/linux/files/0015-Quark-GPIO-1-2-quark.patch
> >
> > Signed-off-by: Yong Li 
> 
> Patch applied with Andy's review tag.
> 
> Yours,
> Linus Walleij


Re: [PATCH] platform:x86 decouple telemetry driver from the optional IPC resources

2016-04-09 Thread Darren Hart
On Thu, Mar 31, 2016 at 02:28:09PM -0500, Aubrey Li wrote:
> Currently the optional IPC resources prevent telemetry driver from
> probing if these resources are not in ACPI table. This patch decouples
> telemetry driver from these optional resources, so that telemetry driver
> has dependency only on the necessary ACPI resources.
> 
> Signed-off-by: Aubrey Li 

Given the impact to their recent contributions, I'm looking for reviews from
Qipeng and Souvik before I merge this.

Qipeng, as the listed maintainer for these two files, I particularly need to
hear from you.

Thanks,

> ---
>  drivers/platform/x86/intel_pmc_ipc.c   |   48 
> +++-
>  drivers/platform/x86/intel_punit_ipc.c |   48 
> +---
>  2 files changed, 54 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel_pmc_ipc.c 
> b/drivers/platform/x86/intel_pmc_ipc.c
> index 092519e..29d9c02 100644
> --- a/drivers/platform/x86/intel_pmc_ipc.c
> +++ b/drivers/platform/x86/intel_pmc_ipc.c
> @@ -686,8 +686,8 @@ static int ipc_plat_get_res(struct platform_device *pdev)
>   ipcdev.acpi_io_size = size;
>   dev_info(>dev, "io res: %pR\n", res);
>  
> - /* This is index 0 to cover BIOS data register */
>   punit_res = punit_res_array;
> + /* This is index 0 to cover BIOS data register */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_BIOS_DATA_INDEX);
>   if (!res) {
> @@ -697,55 +697,51 @@ static int ipc_plat_get_res(struct platform_device 
> *pdev)
>   *punit_res = *res;
>   dev_info(>dev, "punit BIOS data res: %pR\n", res);
>  
> + /* This is index 1 to cover BIOS interface register */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_BIOS_IFACE_INDEX);
>   if (!res) {
>   dev_err(>dev, "Failed to get res of punit BIOS iface\n");
>   return -ENXIO;
>   }
> - /* This is index 1 to cover BIOS interface register */
>   *++punit_res = *res;
>   dev_info(>dev, "punit BIOS interface res: %pR\n", res);
>  
> + /* This is index 2 to cover ISP data register, optional */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_ISP_DATA_INDEX);
> - if (!res) {
> - dev_err(>dev, "Failed to get res of punit ISP data\n");
> - return -ENXIO;
> + ++punit_res;
> + if (res) {
> + *punit_res = *res;
> + dev_info(>dev, "punit ISP data res: %pR\n", res);
>   }
> - /* This is index 2 to cover ISP data register */
> - *++punit_res = *res;
> - dev_info(>dev, "punit ISP data res: %pR\n", res);
>  
> + /* This is index 3 to cover ISP interface register, optional */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_ISP_IFACE_INDEX);
> - if (!res) {
> - dev_err(>dev, "Failed to get res of punit ISP iface\n");
> - return -ENXIO;
> + ++punit_res;
> + if (res) {
> + *punit_res = *res;
> + dev_info(>dev, "punit ISP interface res: %pR\n", res);
>   }
> - /* This is index 3 to cover ISP interface register */
> - *++punit_res = *res;
> - dev_info(>dev, "punit ISP interface res: %pR\n", res);
>  
> + /* This is index 4 to cover GTD data register, optional */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_GTD_DATA_INDEX);
> - if (!res) {
> - dev_err(>dev, "Failed to get res of punit GTD data\n");
> - return -ENXIO;
> + ++punit_res;
> + if (res) {
> + *punit_res = *res;
> + dev_info(>dev, "punit GTD data res: %pR\n", res);
>   }
> - /* This is index 4 to cover GTD data register */
> - *++punit_res = *res;
> - dev_info(>dev, "punit GTD data res: %pR\n", res);
>  
> + /* This is index 5 to cover GTD interface register, optional */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_GTD_IFACE_INDEX);
> - if (!res) {
> - dev_err(>dev, "Failed to get res of punit GTD iface\n");
> - return -ENXIO;
> + ++punit_res;
> + if (res) {
> + *punit_res = *res;
> + dev_info(>dev, "punit GTD interface res: %pR\n", res);
>   }
> - /* This is index 5 to cover GTD interface register */
> - *++punit_res = *res;
> - dev_info(>dev, "punit GTD interface res: %pR\n", res);
>  
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_IPC_INDEX);
> diff --git a/drivers/platform/x86/intel_punit_ipc.c 
> b/drivers/platform/x86/intel_punit_ipc.c
> index bd87540..a47a41f 100644
> --- a/drivers/platform/x86/intel_punit_ipc.c
> +++ 

Re: [PATCH] platform:x86 decouple telemetry driver from the optional IPC resources

2016-04-09 Thread Darren Hart
On Thu, Mar 31, 2016 at 02:28:09PM -0500, Aubrey Li wrote:
> Currently the optional IPC resources prevent telemetry driver from
> probing if these resources are not in ACPI table. This patch decouples
> telemetry driver from these optional resources, so that telemetry driver
> has dependency only on the necessary ACPI resources.
> 
> Signed-off-by: Aubrey Li 

Given the impact to their recent contributions, I'm looking for reviews from
Qipeng and Souvik before I merge this.

Qipeng, as the listed maintainer for these two files, I particularly need to
hear from you.

Thanks,

> ---
>  drivers/platform/x86/intel_pmc_ipc.c   |   48 
> +++-
>  drivers/platform/x86/intel_punit_ipc.c |   48 
> +---
>  2 files changed, 54 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel_pmc_ipc.c 
> b/drivers/platform/x86/intel_pmc_ipc.c
> index 092519e..29d9c02 100644
> --- a/drivers/platform/x86/intel_pmc_ipc.c
> +++ b/drivers/platform/x86/intel_pmc_ipc.c
> @@ -686,8 +686,8 @@ static int ipc_plat_get_res(struct platform_device *pdev)
>   ipcdev.acpi_io_size = size;
>   dev_info(>dev, "io res: %pR\n", res);
>  
> - /* This is index 0 to cover BIOS data register */
>   punit_res = punit_res_array;
> + /* This is index 0 to cover BIOS data register */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_BIOS_DATA_INDEX);
>   if (!res) {
> @@ -697,55 +697,51 @@ static int ipc_plat_get_res(struct platform_device 
> *pdev)
>   *punit_res = *res;
>   dev_info(>dev, "punit BIOS data res: %pR\n", res);
>  
> + /* This is index 1 to cover BIOS interface register */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_BIOS_IFACE_INDEX);
>   if (!res) {
>   dev_err(>dev, "Failed to get res of punit BIOS iface\n");
>   return -ENXIO;
>   }
> - /* This is index 1 to cover BIOS interface register */
>   *++punit_res = *res;
>   dev_info(>dev, "punit BIOS interface res: %pR\n", res);
>  
> + /* This is index 2 to cover ISP data register, optional */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_ISP_DATA_INDEX);
> - if (!res) {
> - dev_err(>dev, "Failed to get res of punit ISP data\n");
> - return -ENXIO;
> + ++punit_res;
> + if (res) {
> + *punit_res = *res;
> + dev_info(>dev, "punit ISP data res: %pR\n", res);
>   }
> - /* This is index 2 to cover ISP data register */
> - *++punit_res = *res;
> - dev_info(>dev, "punit ISP data res: %pR\n", res);
>  
> + /* This is index 3 to cover ISP interface register, optional */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_ISP_IFACE_INDEX);
> - if (!res) {
> - dev_err(>dev, "Failed to get res of punit ISP iface\n");
> - return -ENXIO;
> + ++punit_res;
> + if (res) {
> + *punit_res = *res;
> + dev_info(>dev, "punit ISP interface res: %pR\n", res);
>   }
> - /* This is index 3 to cover ISP interface register */
> - *++punit_res = *res;
> - dev_info(>dev, "punit ISP interface res: %pR\n", res);
>  
> + /* This is index 4 to cover GTD data register, optional */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_GTD_DATA_INDEX);
> - if (!res) {
> - dev_err(>dev, "Failed to get res of punit GTD data\n");
> - return -ENXIO;
> + ++punit_res;
> + if (res) {
> + *punit_res = *res;
> + dev_info(>dev, "punit GTD data res: %pR\n", res);
>   }
> - /* This is index 4 to cover GTD data register */
> - *++punit_res = *res;
> - dev_info(>dev, "punit GTD data res: %pR\n", res);
>  
> + /* This is index 5 to cover GTD interface register, optional */
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_GTD_IFACE_INDEX);
> - if (!res) {
> - dev_err(>dev, "Failed to get res of punit GTD iface\n");
> - return -ENXIO;
> + ++punit_res;
> + if (res) {
> + *punit_res = *res;
> + dev_info(>dev, "punit GTD interface res: %pR\n", res);
>   }
> - /* This is index 5 to cover GTD interface register */
> - *++punit_res = *res;
> - dev_info(>dev, "punit GTD interface res: %pR\n", res);
>  
>   res = platform_get_resource(pdev, IORESOURCE_MEM,
>   PLAT_RESOURCE_IPC_INDEX);
> diff --git a/drivers/platform/x86/intel_punit_ipc.c 
> b/drivers/platform/x86/intel_punit_ipc.c
> index bd87540..a47a41f 100644
> --- a/drivers/platform/x86/intel_punit_ipc.c
> +++ 

Re: [PATCH] Don't audit SECCOMP_KILL/RET_ERRNO when syscall auditing is disabled

2016-04-09 Thread Andi Kleen
> What kernel version are you using?  I believe we fixed that in Linux
> 4.5 with the following:

This is 4.6-rc2.
> 
>   commit 96368701e1c89057bbf39222e965161c68a85b4b
>   From: Paul Moore 
>   Date: Wed, 13 Jan 2016 10:18:55 -0400 (09:18 -0500)
> 
>   audit: force seccomp event logging to honor the audit_enabled flag

No you didn't fix it because audit_enabled is always enabled by systemd
for user space auditing, see the original description of my patch.

-Andi


Re: [PATCH] Don't audit SECCOMP_KILL/RET_ERRNO when syscall auditing is disabled

2016-04-09 Thread Andi Kleen
> What kernel version are you using?  I believe we fixed that in Linux
> 4.5 with the following:

This is 4.6-rc2.
> 
>   commit 96368701e1c89057bbf39222e965161c68a85b4b
>   From: Paul Moore 
>   Date: Wed, 13 Jan 2016 10:18:55 -0400 (09:18 -0500)
> 
>   audit: force seccomp event logging to honor the audit_enabled flag

No you didn't fix it because audit_enabled is always enabled by systemd
for user space auditing, see the original description of my patch.

-Andi


Re: [PATCH] intel_menlow: set cdev after null device check to avoid null pointer dereference

2016-04-09 Thread Darren Hart
On Tue, Mar 29, 2016 at 03:13:43PM +0200, Rafael Wysocki wrote:
> On Monday, March 28, 2016 11:18:05 AM Darren Hart wrote:
> > On Mon, Mar 28, 2016 at 05:18:39PM +0100, Colin King wrote:
> > > From: Colin Ian King 
> > > 
> > > intel_menlow_memory_remove sanity checks to see if device is null, 
> > > however,
> > > this check is performed after we have already passed device into a call
> > > to acpi_driver_data.  If device is null, then acpi_driver_data will 
> > > produce
> > > a null pointer dereference on device. The correct action is to sanity 
> > > check
> > > device, then assign cdev, then check if cdev is null.
> > > 
> > 
> > Hrm, looking at this locally, that all makes sense.
> > 
> > Taking a step back however, I notice that intel_menlow_memory_remove is an 
> > ops
> > function pointer inside the acpi_driver structure itself, which is called 
> > from
> > acpi_device_remove() (and probe) (drivers/acpi/bus.c). This already verifies
> > acpi_driver is not NULL and can't get acpi_driver if acpi_device is NULL. So
> > unless there is some other use case for this callback I'm unaware of 
> > (certainly
> > possible) it appears to be totally redundant to do this checking here.
> > 
> > +Rafael - is there a best practices for these acpi callbacks with respect to
> > input validation?
> 
> No best practices I'm aware of, but if the core does this checks anyway before
> calling this, they are clearly not necessary here.

My position as well.

Colin, would you care to respin these 2?

-- 
Darren Hart
Intel Open Source Technology Center


Re: [PATCH] intel_menlow: set cdev after null device check to avoid null pointer dereference

2016-04-09 Thread Darren Hart
On Tue, Mar 29, 2016 at 03:13:43PM +0200, Rafael Wysocki wrote:
> On Monday, March 28, 2016 11:18:05 AM Darren Hart wrote:
> > On Mon, Mar 28, 2016 at 05:18:39PM +0100, Colin King wrote:
> > > From: Colin Ian King 
> > > 
> > > intel_menlow_memory_remove sanity checks to see if device is null, 
> > > however,
> > > this check is performed after we have already passed device into a call
> > > to acpi_driver_data.  If device is null, then acpi_driver_data will 
> > > produce
> > > a null pointer dereference on device. The correct action is to sanity 
> > > check
> > > device, then assign cdev, then check if cdev is null.
> > > 
> > 
> > Hrm, looking at this locally, that all makes sense.
> > 
> > Taking a step back however, I notice that intel_menlow_memory_remove is an 
> > ops
> > function pointer inside the acpi_driver structure itself, which is called 
> > from
> > acpi_device_remove() (and probe) (drivers/acpi/bus.c). This already verifies
> > acpi_driver is not NULL and can't get acpi_driver if acpi_device is NULL. So
> > unless there is some other use case for this callback I'm unaware of 
> > (certainly
> > possible) it appears to be totally redundant to do this checking here.
> > 
> > +Rafael - is there a best practices for these acpi callbacks with respect to
> > input validation?
> 
> No best practices I'm aware of, but if the core does this checks anyway before
> calling this, they are clearly not necessary here.

My position as well.

Colin, would you care to respin these 2?

-- 
Darren Hart
Intel Open Source Technology Center


Re: [PATCH] fujitsu-laptop: Support radio LED

2016-04-09 Thread Darren Hart
On Thu, Mar 24, 2016 at 10:05:14PM +1030, Jonathan Woithe wrote:
> This is a quick reply with preliminary information.  I'll follow up in the
> next few days with further details.
> 
> On Tue, Mar 22, 2016 at 02:30:51PM +0100, Micha?? K??pie?? wrote:
> > > > As for detecting whether the LED is present on a given machine, I had to
> > > > resort to educated guesswork.  I assumed this LED is present on all
> > > > devices which have a radio toggle button instead of a slider.  My
> > > > Lifebook E744 holds 0x01010001 in BTNI.  By comparing the bits and
> > > > buttons with those of a Lifebook E8420 (BTNI=0x000F0101, has a slider),
> > > > I put my money on bit 24 as the indicator of the radio toggle button
> > > > being present.
> > > 
> > > The other question is how consistent the bit layout is across all devices
> > > which might make use of this driver.  The set of potential devices spans
> > > nearly 10 years, and in many ways it would be surprising if the bit
> > > definitions were kept the same over that time.  Testing would be the only
> > > way to get a feeling for that.
> > 
> > My thoughts exactly.
> > 
> > > If you could let me know how you went about
> > > acquiring the values on your machine I could try the exact same steps on 
> > > the
> > > S7020 to see what we get.
> > 
> > The BTNI value is printed to the kernel log buffer by
> > acpi_fujitsu_hotkey_add(), so all it takes to retrieve it is:
> > 
> > dmesg | grep BTNI
> 
> Here's what's reported by the S7020:
> 
>   fujitsu_laptop: BTNI: [0xf0001]
> 
> The S7020 doesn't have any LEDs.  It also has a physical slider to enable RF
> and an "RF enabled" indicator in the LCD panel.  The LCD indicator is under
> hardware control; software cannot influence it.
> 
> Clearly bit 24 is *not* set on the S7020.  Using this bit as a test for the
> button's presence therefore should not cause trouble for the S7020 and
> probably other similar models from that time.  Obviously we don't have
> access to every single model, but the apparent consistency back to the S7020
> is encouraging.
> 
> > > > While it's not essential, it would be nice to initialize soft rfkill
> > > > state of all radio transmitters to the value of RFSW upon boot.
> > > 
> > > I think this would only be necessary for those machines with the RF button
> > > in place of the hard slider switch, right?
> > 
> > Yes.  On the E8420 I tested, moving the slider switch to "off" position
> > caused the Bluetooth device to be removed from the system altogether
> > while iwlwifi reacted by hard-blocking phy0.
> 
> I haven't noticed anything that dramatic on the S7020, but anything's
> possible.

Jonathan, Michał,

Where are we with this? The above reads as "Doesn't appear to break existing
systems on hand". Jonathan, are you happy with this patch?

Michał, do you have plans for a v2?

-- 
Darren Hart
Intel Open Source Technology Center


Re: [PATCH] fujitsu-laptop: Support radio LED

2016-04-09 Thread Darren Hart
On Thu, Mar 24, 2016 at 10:05:14PM +1030, Jonathan Woithe wrote:
> This is a quick reply with preliminary information.  I'll follow up in the
> next few days with further details.
> 
> On Tue, Mar 22, 2016 at 02:30:51PM +0100, Micha?? K??pie?? wrote:
> > > > As for detecting whether the LED is present on a given machine, I had to
> > > > resort to educated guesswork.  I assumed this LED is present on all
> > > > devices which have a radio toggle button instead of a slider.  My
> > > > Lifebook E744 holds 0x01010001 in BTNI.  By comparing the bits and
> > > > buttons with those of a Lifebook E8420 (BTNI=0x000F0101, has a slider),
> > > > I put my money on bit 24 as the indicator of the radio toggle button
> > > > being present.
> > > 
> > > The other question is how consistent the bit layout is across all devices
> > > which might make use of this driver.  The set of potential devices spans
> > > nearly 10 years, and in many ways it would be surprising if the bit
> > > definitions were kept the same over that time.  Testing would be the only
> > > way to get a feeling for that.
> > 
> > My thoughts exactly.
> > 
> > > If you could let me know how you went about
> > > acquiring the values on your machine I could try the exact same steps on 
> > > the
> > > S7020 to see what we get.
> > 
> > The BTNI value is printed to the kernel log buffer by
> > acpi_fujitsu_hotkey_add(), so all it takes to retrieve it is:
> > 
> > dmesg | grep BTNI
> 
> Here's what's reported by the S7020:
> 
>   fujitsu_laptop: BTNI: [0xf0001]
> 
> The S7020 doesn't have any LEDs.  It also has a physical slider to enable RF
> and an "RF enabled" indicator in the LCD panel.  The LCD indicator is under
> hardware control; software cannot influence it.
> 
> Clearly bit 24 is *not* set on the S7020.  Using this bit as a test for the
> button's presence therefore should not cause trouble for the S7020 and
> probably other similar models from that time.  Obviously we don't have
> access to every single model, but the apparent consistency back to the S7020
> is encouraging.
> 
> > > > While it's not essential, it would be nice to initialize soft rfkill
> > > > state of all radio transmitters to the value of RFSW upon boot.
> > > 
> > > I think this would only be necessary for those machines with the RF button
> > > in place of the hard slider switch, right?
> > 
> > Yes.  On the E8420 I tested, moving the slider switch to "off" position
> > caused the Bluetooth device to be removed from the system altogether
> > while iwlwifi reacted by hard-blocking phy0.
> 
> I haven't noticed anything that dramatic on the S7020, but anything's
> possible.

Jonathan, Michał,

Where are we with this? The above reads as "Doesn't appear to break existing
systems on hand". Jonathan, are you happy with this patch?

Michał, do you have plans for a v2?

-- 
Darren Hart
Intel Open Source Technology Center


Re: [GIT PULL] ext4 bug fixes for 4.6

2016-04-09 Thread Greg Thelen

Theodore Ts'o wrote:

> The following changes since commit 243d50678583100855862bc084b8b307eea67f68:
>
>   Merge branch 'overlayfs-linus' of 
> git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs (2016-03-22 
> 13:11:15 -0700)
>
n> are available in the git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git 
> tags/ext4_for_linus_stable
>
> for you to fetch changes up to c325a67c72903e1cc30e990a15ce745bda0dbfde:
>
>   ext4: ignore quota mount options if the quota feature is enabled 
> (2016-04-03 17:03:37 -0400)
>
> 
> These changes contains a fix for overlayfs interacting with some
> (badly behaved) dentry code in various file systems.  These have been
> reviewed by Al and the respective file system mtinainers and are going
> through the ext4 tree for convenience.
>
> This also has a few ext4 encryption bug fixes that were discovered in
> Android testing (yes, we will need to get these sync'ed up with the
> fs/crypto code; I'll take care of that).  It also has some bug fixes
> and a change to ignore the legacy quota options to allow for xfstests
> regression testing of ext4's internal quota feature and to be more
> consistent with how xfs handles this case.
>
> 
> Dan Carpenter (1):
>   ext4 crypto: fix some error handling
>
> Filipe Manana (1):
>   btrfs: fix crash/invalid memory access on fsync when using overlayfs
>
> Jan Kara (1):
>   ext4: retry block allocation for failed DIO and DAX writes
>
> Miklos Szeredi (4):
>   fs: add file_dentry()
>   nfs: use file_dentry()
>   ext4: use dget_parent() in ext4_file_open()
>   ext4: use file_dentry()
>
> Theodore Ts'o (7):
>   ext4: check if in-inode xattr is corrupted in 
> ext4_expand_extra_isize_ea()
>   ext4 crypto: don't let data integrity writebacks fail with ENOMEM
>   ext4 crypto: use dget_parent() in ext4_d_revalidate()
>   ext4: allow readdir()'s of large empty directories to be interrupted

Ted,

I've been testing 5b5b7fd185e9 (linus/master) and seeing that
interrupted readdir() now returns duplicate dirents.

Reverting commit 1028b55bafb7 ("ext4: allow readdir()'s of large empty
directories to be interrupted") avoids duplicates.

On 5b5b7fd185e9 a SIGPROF to the test program below occasionally causes
"already seen name" error.  On older kernels, it runs indefinitely
without error.

/*
  mkdir /tmp/foo
  cd /tmp/foo
  for i in $(seq 0 599); do touch $i; done
  /tmp/scanner &
  kill -PROF %1
 */

#include 
#include 
#include 
#include 
#include 
#include 

static void handler(int unused)
{
}

int main() {
enum { count = 600 };
char seen[count];
struct dirent *ent;
DIR *dir;
struct sigaction sa = {0};

sa.sa_handler = handler;
if (sigemptyset(_mask))
err(1, "sigemptyset");
sa.sa_flags = SA_RESTART;
if (sigaction(SIGPROF, , NULL))
err(1, "sigaction");

for (;;) {
memset(seen, 0, sizeof(seen));
dir = opendir(".");
if (dir == NULL)
err(1, "opendir(.)");
while ((ent = readdir(dir)) != NULL) {
int idx;

if ((strcmp(ent->d_name, ".") == 0) ||
(strcmp(ent->d_name, "..") == 0)) {
continue;
}
idx = atoi(ent->d_name);
if (idx >= count) {
errx(1, "bogus name %s index %d", ent->d_name, 
idx);
}
if (seen[idx]) {
errx(1, "already seen name %s index %d", 
ent->d_name, idx);
}
seen[idx] = 1;
}
if (closedir(dir))
err(1, "closedir(.)");
}
}

>   ext4: add lockdep annotations for i_data_sem
>   ext4: avoid calling dquot_get_next_id() if quota is not enabled
>   ext4: ignore quota mount options if the quota feature is enabled
>
>  fs/btrfs/file.c|  2 +-
>  fs/dcache.c|  5 -
>  fs/ext4/crypto.c   | 49 +
>  fs/ext4/dir.c  |  5 +
>  fs/ext4/ext4.h | 29 +++--
>  fs/ext4/file.c | 12 
>  fs/ext4/inode.c| 58 
> --
>  fs/ext4/move_extent.c  | 11 +--
>  fs/ext4/namei.c|  5 +
>  fs/ext4/page-io.c  | 14 +-
>  fs/ext4/readpage.c |  2 +-
>  fs/ext4/super.c| 61 
> +++--
>  fs/ext4/xattr.c| 32 
>  fs/nfs/dir.c   |  6 +++---

Re: [GIT PULL] ext4 bug fixes for 4.6

2016-04-09 Thread Greg Thelen

Theodore Ts'o wrote:

> The following changes since commit 243d50678583100855862bc084b8b307eea67f68:
>
>   Merge branch 'overlayfs-linus' of 
> git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs (2016-03-22 
> 13:11:15 -0700)
>
n> are available in the git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git 
> tags/ext4_for_linus_stable
>
> for you to fetch changes up to c325a67c72903e1cc30e990a15ce745bda0dbfde:
>
>   ext4: ignore quota mount options if the quota feature is enabled 
> (2016-04-03 17:03:37 -0400)
>
> 
> These changes contains a fix for overlayfs interacting with some
> (badly behaved) dentry code in various file systems.  These have been
> reviewed by Al and the respective file system mtinainers and are going
> through the ext4 tree for convenience.
>
> This also has a few ext4 encryption bug fixes that were discovered in
> Android testing (yes, we will need to get these sync'ed up with the
> fs/crypto code; I'll take care of that).  It also has some bug fixes
> and a change to ignore the legacy quota options to allow for xfstests
> regression testing of ext4's internal quota feature and to be more
> consistent with how xfs handles this case.
>
> 
> Dan Carpenter (1):
>   ext4 crypto: fix some error handling
>
> Filipe Manana (1):
>   btrfs: fix crash/invalid memory access on fsync when using overlayfs
>
> Jan Kara (1):
>   ext4: retry block allocation for failed DIO and DAX writes
>
> Miklos Szeredi (4):
>   fs: add file_dentry()
>   nfs: use file_dentry()
>   ext4: use dget_parent() in ext4_file_open()
>   ext4: use file_dentry()
>
> Theodore Ts'o (7):
>   ext4: check if in-inode xattr is corrupted in 
> ext4_expand_extra_isize_ea()
>   ext4 crypto: don't let data integrity writebacks fail with ENOMEM
>   ext4 crypto: use dget_parent() in ext4_d_revalidate()
>   ext4: allow readdir()'s of large empty directories to be interrupted

Ted,

I've been testing 5b5b7fd185e9 (linus/master) and seeing that
interrupted readdir() now returns duplicate dirents.

Reverting commit 1028b55bafb7 ("ext4: allow readdir()'s of large empty
directories to be interrupted") avoids duplicates.

On 5b5b7fd185e9 a SIGPROF to the test program below occasionally causes
"already seen name" error.  On older kernels, it runs indefinitely
without error.

/*
  mkdir /tmp/foo
  cd /tmp/foo
  for i in $(seq 0 599); do touch $i; done
  /tmp/scanner &
  kill -PROF %1
 */

#include 
#include 
#include 
#include 
#include 
#include 

static void handler(int unused)
{
}

int main() {
enum { count = 600 };
char seen[count];
struct dirent *ent;
DIR *dir;
struct sigaction sa = {0};

sa.sa_handler = handler;
if (sigemptyset(_mask))
err(1, "sigemptyset");
sa.sa_flags = SA_RESTART;
if (sigaction(SIGPROF, , NULL))
err(1, "sigaction");

for (;;) {
memset(seen, 0, sizeof(seen));
dir = opendir(".");
if (dir == NULL)
err(1, "opendir(.)");
while ((ent = readdir(dir)) != NULL) {
int idx;

if ((strcmp(ent->d_name, ".") == 0) ||
(strcmp(ent->d_name, "..") == 0)) {
continue;
}
idx = atoi(ent->d_name);
if (idx >= count) {
errx(1, "bogus name %s index %d", ent->d_name, 
idx);
}
if (seen[idx]) {
errx(1, "already seen name %s index %d", 
ent->d_name, idx);
}
seen[idx] = 1;
}
if (closedir(dir))
err(1, "closedir(.)");
}
}

>   ext4: add lockdep annotations for i_data_sem
>   ext4: avoid calling dquot_get_next_id() if quota is not enabled
>   ext4: ignore quota mount options if the quota feature is enabled
>
>  fs/btrfs/file.c|  2 +-
>  fs/dcache.c|  5 -
>  fs/ext4/crypto.c   | 49 +
>  fs/ext4/dir.c  |  5 +
>  fs/ext4/ext4.h | 29 +++--
>  fs/ext4/file.c | 12 
>  fs/ext4/inode.c| 58 
> --
>  fs/ext4/move_extent.c  | 11 +--
>  fs/ext4/namei.c|  5 +
>  fs/ext4/page-io.c  | 14 +-
>  fs/ext4/readpage.c |  2 +-
>  fs/ext4/super.c| 61 
> +++--
>  fs/ext4/xattr.c| 32 
>  fs/nfs/dir.c   |  6 +++---

OFFICIAL COMPLAINT AGAINST THE SINGAPORE GOVERNMENT FOR ALLEGEDLY FALSIFYING TEO EN MING'S MEDICAL RECORDS

2016-04-09 Thread Teo En Ming
Dear Sir/Madam,

Please refer to the following letter (PDF format), addressed to the
United Nations Human Rights Council, for more information and details
about my predicament. The letter was dated 10th October 2014 Friday.

Link: 
https://www.scribd.com/doc/250712695/Teo-En-Ming-Filed-An-Official-Complaint-Against-the-Singapore-Government-at-the-United-Nations-Human-Rights-Council-Dated-10-Oct-2014

Thank you very much for your kind attention.

Yours sincerely,

Mr. Teo En Ming (Zhang Enming)
SINGAPORE CITIZEN
TARGETED INDIVIDUAL (TI)
Mr. Teo En Ming (Zhang Enming) is Persecuted, Targeted, and
Blacklisted by the Singapore Government led by Prime Minister Lee
Hsien Loong
10th April 2016 Sunday 10:03 AM Singapore Time GMT+8
Age: 38 Years Old


OFFICIAL COMPLAINT AGAINST THE SINGAPORE GOVERNMENT FOR ALLEGEDLY FALSIFYING TEO EN MING'S MEDICAL RECORDS

2016-04-09 Thread Teo En Ming
Dear Sir/Madam,

Please refer to the following letter (PDF format), addressed to the
United Nations Human Rights Council, for more information and details
about my predicament. The letter was dated 10th October 2014 Friday.

Link: 
https://www.scribd.com/doc/250712695/Teo-En-Ming-Filed-An-Official-Complaint-Against-the-Singapore-Government-at-the-United-Nations-Human-Rights-Council-Dated-10-Oct-2014

Thank you very much for your kind attention.

Yours sincerely,

Mr. Teo En Ming (Zhang Enming)
SINGAPORE CITIZEN
TARGETED INDIVIDUAL (TI)
Mr. Teo En Ming (Zhang Enming) is Persecuted, Targeted, and
Blacklisted by the Singapore Government led by Prime Minister Lee
Hsien Loong
10th April 2016 Sunday 10:03 AM Singapore Time GMT+8
Age: 38 Years Old


Subtle Denial of Medical Treatment by the Singapore Government for Mr. Teo En Ming (Zhang Enming)

2016-04-09 Thread Teo En Ming
Dear Sir/Madam,

Please refer to the following letter (PDF format), addressed to the
United Nations Human Rights Council, for more information and details
about my predicament. The letter was dated 14th March 2015 Saturday.

Link: 
https://www.scribd.com/doc/258700156/Subtle-Denial-of-Medical-Treatment-by-the-Singapore-Government-for-Mr-Teo-En-Ming-Zhang-Enming

Thank you very much for your kind attention.

Yours sincerely,

Mr. Teo En Ming (Zhang Enming)
SINGAPORE CITIZEN
TARGETED INDIVIDUAL (TI)
Mr. Teo En Ming (Zhang Enming) is Persecuted, Targeted, and
Blacklisted by the Singapore Government led by Prime Minister Lee
Hsien Loong
10th April 2016 Sunday 10:03 AM Singapore Time GMT+8
Age: 38 Years Old


Subtle Denial of Medical Treatment by the Singapore Government for Mr. Teo En Ming (Zhang Enming)

2016-04-09 Thread Teo En Ming
Dear Sir/Madam,

Please refer to the following letter (PDF format), addressed to the
United Nations Human Rights Council, for more information and details
about my predicament. The letter was dated 14th March 2015 Saturday.

Link: 
https://www.scribd.com/doc/258700156/Subtle-Denial-of-Medical-Treatment-by-the-Singapore-Government-for-Mr-Teo-En-Ming-Zhang-Enming

Thank you very much for your kind attention.

Yours sincerely,

Mr. Teo En Ming (Zhang Enming)
SINGAPORE CITIZEN
TARGETED INDIVIDUAL (TI)
Mr. Teo En Ming (Zhang Enming) is Persecuted, Targeted, and
Blacklisted by the Singapore Government led by Prime Minister Lee
Hsien Loong
10th April 2016 Sunday 10:03 AM Singapore Time GMT+8
Age: 38 Years Old


Re: [PATCH v2 1/2] lib: lz4: fixed zram with lz4 on big endian machines

2016-04-09 Thread Sergey Senozhatsky
On (04/09/16 22:05), Rui Salvaterra wrote:
> Note that the 64-bit preprocessor test is not a cleanup, it's part of
> the fix, since those identifiers are bogus (for example, __ppc64__
> isn't defined anywhere else in the kernel, which means we'd fall into
> the 32-bit definitions on ppc64).

good find.

> Tested on ppc64 with no regression on x86_64.
> 
> [1] http://marc.info/?l=linux-kernel=145994470805853=4
> 
> Cc: sta...@vger.kernel.org
> Suggested-by: Sergey Senozhatsky 
> Signed-off-by: Rui Salvaterra 

Reviewed-by: Sergey Senozhatsky 

-ss


Re: [PATCH v2 1/2] lib: lz4: fixed zram with lz4 on big endian machines

2016-04-09 Thread Sergey Senozhatsky
On (04/09/16 22:05), Rui Salvaterra wrote:
> Note that the 64-bit preprocessor test is not a cleanup, it's part of
> the fix, since those identifiers are bogus (for example, __ppc64__
> isn't defined anywhere else in the kernel, which means we'd fall into
> the 32-bit definitions on ppc64).

good find.

> Tested on ppc64 with no regression on x86_64.
> 
> [1] http://marc.info/?l=linux-kernel=145994470805853=4
> 
> Cc: sta...@vger.kernel.org
> Suggested-by: Sergey Senozhatsky 
> Signed-off-by: Rui Salvaterra 

Reviewed-by: Sergey Senozhatsky 

-ss


Re: [PATCH v2 2/2] lib: lz4: cleanup unaligned access efficiency detection

2016-04-09 Thread Sergey Senozhatsky
On (04/09/16 22:05), Rui Salvaterra wrote:
> These identifiers are bogus. The interested architectures should define
> HAVE_EFFICIENT_UNALIGNED_ACCESS whenever relevant to do so. If this
> isn't true for some arch, it should be fixed in the arch definition.

yes, besides ARM_EFFICIENT_UNALIGNED_ACCESS exists only in lib/lz4/lz4defs.h

> Signed-off-by: Rui Salvaterra 

Reviewed-by: Sergey Senozhatsky 


-ss

> ---
>  lib/lz4/lz4defs.h | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/lib/lz4/lz4defs.h b/lib/lz4/lz4defs.h
> index 0710a62..c79d7ea 100644
> --- a/lib/lz4/lz4defs.h
> +++ b/lib/lz4/lz4defs.h
> @@ -24,9 +24,7 @@
>  typedef struct _U16_S { u16 v; } U16_S;
>  typedef struct _U32_S { u32 v; } U32_S;
>  typedef struct _U64_S { u64 v; } U64_S;
> -#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)  \
> - || defined(CONFIG_ARM) && __LINUX_ARM_ARCH__ >= 6   \
> - && defined(ARM_EFFICIENT_UNALIGNED_ACCESS)
> +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
>  
>  #define A16(x) (((U16_S *)(x))->v)
>  #define A32(x) (((U32_S *)(x))->v)
> -- 
> 2.7.4
> 


Re: [PATCH v2 2/2] lib: lz4: cleanup unaligned access efficiency detection

2016-04-09 Thread Sergey Senozhatsky
On (04/09/16 22:05), Rui Salvaterra wrote:
> These identifiers are bogus. The interested architectures should define
> HAVE_EFFICIENT_UNALIGNED_ACCESS whenever relevant to do so. If this
> isn't true for some arch, it should be fixed in the arch definition.

yes, besides ARM_EFFICIENT_UNALIGNED_ACCESS exists only in lib/lz4/lz4defs.h

> Signed-off-by: Rui Salvaterra 

Reviewed-by: Sergey Senozhatsky 


-ss

> ---
>  lib/lz4/lz4defs.h | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/lib/lz4/lz4defs.h b/lib/lz4/lz4defs.h
> index 0710a62..c79d7ea 100644
> --- a/lib/lz4/lz4defs.h
> +++ b/lib/lz4/lz4defs.h
> @@ -24,9 +24,7 @@
>  typedef struct _U16_S { u16 v; } U16_S;
>  typedef struct _U32_S { u32 v; } U32_S;
>  typedef struct _U64_S { u64 v; } U64_S;
> -#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)  \
> - || defined(CONFIG_ARM) && __LINUX_ARM_ARCH__ >= 6   \
> - && defined(ARM_EFFICIENT_UNALIGNED_ACCESS)
> +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
>  
>  #define A16(x) (((U16_S *)(x))->v)
>  #define A32(x) (((U32_S *)(x))->v)
> -- 
> 2.7.4
> 


Re: [PATCH] Don't audit SECCOMP_KILL/RET_ERRNO when syscall auditing is disabled

2016-04-09 Thread Paul Moore
On Sat, Apr 9, 2016 at 11:07 AM, Andi Kleen  wrote:
> From: Andi Kleen 
>
> When I run chrome on my opensuse system every time I open
> a new tab the system log is spammed with:
>
> audit[16857]: SECCOMP auid=1000 uid=1000 gid=100 ses=1 pid=16857
> comm="chrome" exe="/opt/google/chrome/chrome" sig=0 arch=c03e
> syscall=273 compat=0 ip=0x7fe27c11a444 code=0x5
>
> This happens because chrome uses SECCOMP for its sandbox,
> and for some reason always reaches a SECCOMP_KILL or more likely
> SECCOMP_RET_ERRNO in the rule set.
>
> The seccomp auditing was originally added ...

Hi Andi,

What kernel version are you using?  I believe we fixed that in Linux
4.5 with the following:

  commit 96368701e1c89057bbf39222e965161c68a85b4b
  From: Paul Moore 
  Date: Wed, 13 Jan 2016 10:18:55 -0400 (09:18 -0500)

  audit: force seccomp event logging to honor the audit_enabled flag

  Previously we were emitting seccomp audit records regardless of the
  audit_enabled setting, a deparature from the rest of audit.  This
  patch makes seccomp auditing consistent with the rest of the audit
  record generation code in that when audit_enabled=0 nothing is logged
  by the audit subsystem.

  The bulk of this patch is moving the CONFIG_AUDIT block ahead of the
  CONFIG_AUDITSYSCALL block in include/linux/audit.h; the only real
  code change was in the audit_seccomp() definition.

  Signed-off-by: Tony Jones 
  Signed-off-by: Paul Moore 

-- 
paul moore
www.paul-moore.com


Re: [PATCH] Don't audit SECCOMP_KILL/RET_ERRNO when syscall auditing is disabled

2016-04-09 Thread Paul Moore
On Sat, Apr 9, 2016 at 11:07 AM, Andi Kleen  wrote:
> From: Andi Kleen 
>
> When I run chrome on my opensuse system every time I open
> a new tab the system log is spammed with:
>
> audit[16857]: SECCOMP auid=1000 uid=1000 gid=100 ses=1 pid=16857
> comm="chrome" exe="/opt/google/chrome/chrome" sig=0 arch=c03e
> syscall=273 compat=0 ip=0x7fe27c11a444 code=0x5
>
> This happens because chrome uses SECCOMP for its sandbox,
> and for some reason always reaches a SECCOMP_KILL or more likely
> SECCOMP_RET_ERRNO in the rule set.
>
> The seccomp auditing was originally added ...

Hi Andi,

What kernel version are you using?  I believe we fixed that in Linux
4.5 with the following:

  commit 96368701e1c89057bbf39222e965161c68a85b4b
  From: Paul Moore 
  Date: Wed, 13 Jan 2016 10:18:55 -0400 (09:18 -0500)

  audit: force seccomp event logging to honor the audit_enabled flag

  Previously we were emitting seccomp audit records regardless of the
  audit_enabled setting, a deparature from the rest of audit.  This
  patch makes seccomp auditing consistent with the rest of the audit
  record generation code in that when audit_enabled=0 nothing is logged
  by the audit subsystem.

  The bulk of this patch is moving the CONFIG_AUDIT block ahead of the
  CONFIG_AUDITSYSCALL block in include/linux/audit.h; the only real
  code change was in the audit_seccomp() definition.

  Signed-off-by: Tony Jones 
  Signed-off-by: Paul Moore 

-- 
paul moore
www.paul-moore.com


[PATCH 4/8] tty: Replace ASYNC_CHECK_CD and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_CHECK_CD bit in the tty_port::flags field with
TTY_PORT_CHECK_CD bit in the tty_port::iflags field. Introduce helpers
tty_port_set_check_carrier() and tty_port_check_carrier() to abstract
the atomic bit ops.

Signed-off-by: Peter Hurley 
---
 drivers/char/pcmcia/synclink_cs.c   |  8 ++--
 drivers/isdn/i4l/isdn_tty.c |  8 ++--
 drivers/tty/amiserial.c |  9 +++--
 drivers/tty/cyclades.c  | 14 --
 drivers/tty/isicom.c|  7 ++-
 drivers/tty/mxser.c |  9 +++--
 drivers/tty/synclink.c  |  8 ++--
 drivers/tty/synclink_gt.c   |  8 ++--
 drivers/tty/synclinkmp.c|  8 ++--
 include/linux/tty.h | 13 +
 net/irda/ircomm/ircomm_tty.c|  4 ++--
 net/irda/ircomm/ircomm_tty_attach.c |  2 +-
 net/irda/ircomm/ircomm_tty_ioctl.c  |  5 +
 13 files changed, 39 insertions(+), 64 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index bdf41ac..bf54f4e 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1101,7 +1101,7 @@ static void dcd_change(MGSLPC_INFO *info, struct 
tty_struct *tty)
wake_up_interruptible(>status_event_wait_q);
wake_up_interruptible(>event_wait_q);
 
-   if (info->port.flags & ASYNC_CHECK_CD) {
+   if (tty_port_check_carrier(>port)) {
if (debug_level >= DEBUG_LEVEL_ISR)
printk("%s CD now %s...", info->device_name,
   (info->serial_signals & SerialSignal_DCD) ? "on" 
: "off");
@@ -1467,11 +1467,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info, 
struct tty_struct *tty)
info->timeout += HZ/50; /* Add .02 seconds of slop */
 
tty_port_set_cts_flow(>port, cflag & CRTSCTS);
-
-   if (cflag & CLOCAL)
-   info->port.flags &= ~ASYNC_CHECK_CD;
-   else
-   info->port.flags |= ASYNC_CHECK_CD;
+   tty_port_set_check_carrier(>port, ~cflag & CLOCAL);
 
/* process tty input control flags */
 
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index d8468f3..023a350a 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1043,11 +1043,7 @@ isdn_tty_change_speed(modem_info *info)
if (!(cflag & PARODD))
cval |= UART_LCR_EPAR;
 
-   if (cflag & CLOCAL)
-   port->flags &= ~ASYNC_CHECK_CD;
-   else {
-   port->flags |= ASYNC_CHECK_CD;
-   }
+   tty_port_set_check_carrier(port, ~cflag & CLOCAL);
 }
 
 static int
@@ -2526,7 +2522,7 @@ isdn_tty_modem_result(int code, modem_info *info)
if (info->closing || (!info->port.tty))
return;
 
-   if (info->port.flags & ASYNC_CHECK_CD)
+   if (tty_port_check_carrier(>port))
tty_hangup(info->port.tty);
}
 }
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 80d6165..b4ab97d 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -398,7 +398,7 @@ static void check_modem_status(struct serial_state *info)
wake_up_interruptible(>delta_msr_wait);
}
 
-   if ((port->flags & ASYNC_CHECK_CD) && (dstatus & SER_DCD)) {
+   if (tty_port_check_carrier(port) && (dstatus & SER_DCD)) {
 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
printk("ttyS%d CD now %s...", info->line,
   (!(status & SER_DCD)) ? "on" : "off");
@@ -730,12 +730,9 @@ static void change_speed(struct tty_struct *tty, struct 
serial_state *info,
tty_port_set_cts_flow(port, cflag & CRTSCTS);
if (cflag & CRTSCTS)
info->IER |= UART_IER_MSI;
-   if (cflag & CLOCAL)
-   port->flags &= ~ASYNC_CHECK_CD;
-   else {
-   port->flags |= ASYNC_CHECK_CD;
+   tty_port_set_check_carrier(port, ~cflag & CLOCAL);
+   if (~cflag & CLOCAL)
info->IER |= UART_IER_MSI;
-   }
/* TBD:
 * Does clearing IER_MSI imply that we should disable the VBL interrupt 
?
 */
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index 1a12776..9d1e19b 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -714,7 +714,7 @@ static void cyy_chip_modem(struct cyclades_card *cinfo, int 
chip,
wake_up_interruptible(>port.delta_msr_wait);
}
 
-   if ((mdm_change & CyDCD) && (info->port.flags & ASYNC_CHECK_CD)) {
+   if ((mdm_change & CyDCD) && tty_port_check_carrier(>port)) {
if (mdm_status & CyDCD)
wake_up_interruptible(>port.open_wait);
else
@@ -1119,7 +1119,7 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
case C_CM_MDCD:

[PATCH 1/8] tty: Define ASYNC_ replacement bits

2016-04-09 Thread Peter Hurley
Prepare for relocating kernel private state bits out of tty_port::flags
field; tty_port::flags field is not atomic and can become corrupted
by concurrent updates. It also suffers from the complication of sharing
in a userspace-visible field which must be masked.

Define new tty_port::iflags field and new, substitute bit definitions
for the former ASYNC_* flags.

Signed-off-by: Peter Hurley 
---
 include/linux/tty.h| 16 +++-
 include/uapi/linux/tty_flags.h |  9 -
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/include/linux/tty.h b/include/linux/tty.h
index 89f9c91..4e0dbda0 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -228,7 +228,8 @@ struct tty_port {
int count;  /* Usage count */
wait_queue_head_t   open_wait;  /* Open waiters */
wait_queue_head_t   delta_msr_wait; /* Modem status change */
-   unsigned long   flags;  /* TTY flags ASY_*/
+   unsigned long   flags;  /* User TTY flags ASYNC_ */
+   unsigned long   iflags; /* Internal flags TTY_PORT_ */
unsigned char   console:1,  /* port is a console */
low_latency:1;  /* optional: tune for latency */
struct mutexmutex;  /* Locking */
@@ -242,6 +243,19 @@ struct tty_port {
struct kref kref;   /* Ref counter */
 };
 
+/* tty_port::iflags bits -- use atomic bit ops */
+#define TTY_PORT_INITIALIZED   0   /* device is initialized */
+#define TTY_PORT_SUSPENDED 1   /* device is suspended */
+#define TTY_PORT_ACTIVE2   /* device is open */
+
+/*
+ * uart drivers: use the uart_port::status field and the UPSTAT_* defines
+ * for s/w-based flow control steering and carrier detection status
+ */
+#define TTY_PORT_CTS_FLOW  3   /* h/w flow control enabled */
+#define TTY_PORT_CHECK_CD  4   /* carrier detect enabled */
+
+
 /*
  * Where all of the state associated with a tty is kept while the tty
  * is open.  Since the termios state should be kept even if the tty
diff --git a/include/uapi/linux/tty_flags.h b/include/uapi/linux/tty_flags.h
index 072e41e..8e1a436 100644
--- a/include/uapi/linux/tty_flags.h
+++ b/include/uapi/linux/tty_flags.h
@@ -32,7 +32,12 @@
 #define ASYNCB_MAGIC_MULTIPLIER16 /* Use special CLK or divisor */
 #define ASYNCB_LAST_USER   16
 
-/* Internal flags used only by kernel */
+/*
+ * Internal flags used only by kernel (read-only)
+ *
+ * WARNING: These flags are no longer used and have been superceded by the
+ * TTY_PORT_ flags in the iflags field (and not userspace-visible)
+ */
 #define ASYNCB_INITIALIZED 31 /* Serial port was initialized */
 #define ASYNCB_SUSPENDED   30 /* Serial port is suspended */
 #define ASYNCB_NORMAL_ACTIVE   29 /* Normal device is active */
@@ -44,6 +49,7 @@
 #define ASYNCB_CONS_FLOW   23 /* flow control for console  */
 #define ASYNCB_FIRST_KERNEL22
 
+/* Masks */
 #define ASYNC_HUP_NOTIFY   (1U << ASYNCB_HUP_NOTIFY)
 #define ASYNC_SUSPENDED(1U << ASYNCB_SUSPENDED)
 #define ASYNC_FOURPORT (1U << ASYNCB_FOURPORT)
@@ -72,6 +78,7 @@
 #define ASYNC_SPD_WARP (ASYNC_SPD_HI|ASYNC_SPD_SHI)
 #define ASYNC_SPD_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI|ASYNC_SPD_SHI)
 
+/* These flags are no longer used (and were always masked from userspace) */
 #define ASYNC_INITIALIZED  (1U << ASYNCB_INITIALIZED)
 #define ASYNC_NORMAL_ACTIVE(1U << ASYNCB_NORMAL_ACTIVE)
 #define ASYNC_BOOT_AUTOCONF(1U << ASYNCB_BOOT_AUTOCONF)
-- 
2.8.1



[PATCH 7/8] tty: mxser: Remove unused ASYNC_SHARE_IRQ flag

2016-04-09 Thread Peter Hurley
ASYNC*_SHARE_IRQ is no longer used; remove.

Signed-off-by: Peter Hurley 
---
 drivers/tty/mxser.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 7e8c27b..98d2bd1 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -2392,7 +2392,6 @@ static int mxser_initbrd(struct mxser_board *brd,
if (brd->chip_flag != MOXA_OTHER_UART)
mxser_enable_must_enchance_mode(info->ioaddr);
 
-   info->port.flags = ASYNC_SHARE_IRQ;
info->type = brd->uart_type;
 
process_txrx_fifo(info);
-- 
2.8.1



[PATCH 3/8] tty: Replace ASYNC_NORMAL_ACTIVE bit and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_NORMAL_ACTIVE bit in the tty_port::flags field with
TTY_PORT_ACTIVE bit in the tty_port::iflags field. Introduce helpers
tty_port_set_active() and tty_port_active() to abstract atomic bit ops.

Extract state changes from port lock sections, as this usage is
broken and confused; the state transitions are protected by the
tty lock (which mutually excludes parallel open/close/hangup),
and no user tests the active state while holding the port lock.

Signed-off-by: Peter Hurley 
---
 drivers/isdn/i4l/isdn_tty.c  | 20 +---
 drivers/tty/amiserial.c  |  2 +-
 drivers/tty/rocket.c |  5 +++--
 drivers/tty/serial/crisv10.c |  8 
 drivers/tty/serial/serial_core.c |  8 
 drivers/tty/synclink.c   |  6 +++---
 drivers/tty/synclink_gt.c|  6 +++---
 drivers/tty/synclinkmp.c |  6 +++---
 drivers/tty/tty_port.c   | 12 ++--
 include/linux/tty.h  | 12 
 net/irda/ircomm/ircomm_tty.c | 10 +-
 11 files changed, 53 insertions(+), 42 deletions(-)

diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index f1edc08..d8468f3 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1622,7 +1622,7 @@ isdn_tty_hangup(struct tty_struct *tty)
return;
isdn_tty_shutdown(info);
port->count = 0;
-   port->flags &= ~ASYNC_NORMAL_ACTIVE;
+   tty_port_set_active(port, 0);
port->tty = NULL;
wake_up_interruptible(>open_wait);
 }
@@ -1979,7 +1979,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
 #endif
if (
 #ifndef FIX_FILE_TRANSFER
-   (info->port.flags & ASYNC_NORMAL_ACTIVE) &&
+   tty_port_active(>port) &&
 #endif
(info->isdn_driver == -1) &&
(info->isdn_channel == -1) &&
@@ -2018,8 +2018,6 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
return (wret == 2) ? 3 : 0;
 }
 
-#define TTY_IS_ACTIVE(info)(info->port.flags & ASYNC_NORMAL_ACTIVE)
-
 int
 isdn_tty_stat_callback(int i, isdn_ctrl *c)
 {
@@ -2077,7 +2075,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 #ifdef ISDN_TTY_STAT_DEBUG
printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", 
info->line);
 #endif
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
if (info->dialing == 1) {
info->dialing = 2;
return 1;
@@ -2088,7 +2086,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 #ifdef ISDN_TTY_STAT_DEBUG
printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line);
 #endif
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
if (info->dialing == 1)
isdn_tty_modem_result(RESULT_BUSY, 
info);
if (info->dialing > 1)
@@ -2118,7 +2116,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 * waiting for it and
 * set DCD-bit of its modem-status.
 */
-   if (TTY_IS_ACTIVE(info) ||
+   if (tty_port_active(>port) ||
(info->port.blocked_open &&
 (info->emu.mdmreg[REG_DCD] & BIT_DCD))) {
info->msr |= UART_MSR_DCD;
@@ -2145,7 +2143,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 #ifdef ISDN_TTY_STAT_DEBUG
printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line);
 #endif
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
 #ifdef ISDN_DEBUG_MODEM_HUP
printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n");
 #endif
@@ -2157,7 +2155,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 #ifdef ISDN_TTY_STAT_DEBUG
printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", 
info->line);
 #endif
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
if (info->dialing) {
info->dialing = 0;
info->last_l2 = -1;
@@ -2183,14 +2181,14 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
return 1;
 #ifdef CONFIG_ISDN_TTY_FAX
case ISDN_STAT_FAXIND:
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
isdn_tty_fax_command(info, c);
}
break;
 #endif
 #ifdef CONFIG_ISDN_AUDIO
case ISDN_STAT_AUDIO:
-

[PATCH 1/8] tty: Define ASYNC_ replacement bits

2016-04-09 Thread Peter Hurley
Prepare for relocating kernel private state bits out of tty_port::flags
field; tty_port::flags field is not atomic and can become corrupted
by concurrent updates. It also suffers from the complication of sharing
in a userspace-visible field which must be masked.

Define new tty_port::iflags field and new, substitute bit definitions
for the former ASYNC_* flags.

Signed-off-by: Peter Hurley 
---
 include/linux/tty.h| 16 +++-
 include/uapi/linux/tty_flags.h |  9 -
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/include/linux/tty.h b/include/linux/tty.h
index 89f9c91..4e0dbda0 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -228,7 +228,8 @@ struct tty_port {
int count;  /* Usage count */
wait_queue_head_t   open_wait;  /* Open waiters */
wait_queue_head_t   delta_msr_wait; /* Modem status change */
-   unsigned long   flags;  /* TTY flags ASY_*/
+   unsigned long   flags;  /* User TTY flags ASYNC_ */
+   unsigned long   iflags; /* Internal flags TTY_PORT_ */
unsigned char   console:1,  /* port is a console */
low_latency:1;  /* optional: tune for latency */
struct mutexmutex;  /* Locking */
@@ -242,6 +243,19 @@ struct tty_port {
struct kref kref;   /* Ref counter */
 };
 
+/* tty_port::iflags bits -- use atomic bit ops */
+#define TTY_PORT_INITIALIZED   0   /* device is initialized */
+#define TTY_PORT_SUSPENDED 1   /* device is suspended */
+#define TTY_PORT_ACTIVE2   /* device is open */
+
+/*
+ * uart drivers: use the uart_port::status field and the UPSTAT_* defines
+ * for s/w-based flow control steering and carrier detection status
+ */
+#define TTY_PORT_CTS_FLOW  3   /* h/w flow control enabled */
+#define TTY_PORT_CHECK_CD  4   /* carrier detect enabled */
+
+
 /*
  * Where all of the state associated with a tty is kept while the tty
  * is open.  Since the termios state should be kept even if the tty
diff --git a/include/uapi/linux/tty_flags.h b/include/uapi/linux/tty_flags.h
index 072e41e..8e1a436 100644
--- a/include/uapi/linux/tty_flags.h
+++ b/include/uapi/linux/tty_flags.h
@@ -32,7 +32,12 @@
 #define ASYNCB_MAGIC_MULTIPLIER16 /* Use special CLK or divisor */
 #define ASYNCB_LAST_USER   16
 
-/* Internal flags used only by kernel */
+/*
+ * Internal flags used only by kernel (read-only)
+ *
+ * WARNING: These flags are no longer used and have been superceded by the
+ * TTY_PORT_ flags in the iflags field (and not userspace-visible)
+ */
 #define ASYNCB_INITIALIZED 31 /* Serial port was initialized */
 #define ASYNCB_SUSPENDED   30 /* Serial port is suspended */
 #define ASYNCB_NORMAL_ACTIVE   29 /* Normal device is active */
@@ -44,6 +49,7 @@
 #define ASYNCB_CONS_FLOW   23 /* flow control for console  */
 #define ASYNCB_FIRST_KERNEL22
 
+/* Masks */
 #define ASYNC_HUP_NOTIFY   (1U << ASYNCB_HUP_NOTIFY)
 #define ASYNC_SUSPENDED(1U << ASYNCB_SUSPENDED)
 #define ASYNC_FOURPORT (1U << ASYNCB_FOURPORT)
@@ -72,6 +78,7 @@
 #define ASYNC_SPD_WARP (ASYNC_SPD_HI|ASYNC_SPD_SHI)
 #define ASYNC_SPD_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI|ASYNC_SPD_SHI)
 
+/* These flags are no longer used (and were always masked from userspace) */
 #define ASYNC_INITIALIZED  (1U << ASYNCB_INITIALIZED)
 #define ASYNC_NORMAL_ACTIVE(1U << ASYNCB_NORMAL_ACTIVE)
 #define ASYNC_BOOT_AUTOCONF(1U << ASYNCB_BOOT_AUTOCONF)
-- 
2.8.1



[PATCH 7/8] tty: mxser: Remove unused ASYNC_SHARE_IRQ flag

2016-04-09 Thread Peter Hurley
ASYNC*_SHARE_IRQ is no longer used; remove.

Signed-off-by: Peter Hurley 
---
 drivers/tty/mxser.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 7e8c27b..98d2bd1 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -2392,7 +2392,6 @@ static int mxser_initbrd(struct mxser_board *brd,
if (brd->chip_flag != MOXA_OTHER_UART)
mxser_enable_must_enchance_mode(info->ioaddr);
 
-   info->port.flags = ASYNC_SHARE_IRQ;
info->type = brd->uart_type;
 
process_txrx_fifo(info);
-- 
2.8.1



[PATCH 3/8] tty: Replace ASYNC_NORMAL_ACTIVE bit and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_NORMAL_ACTIVE bit in the tty_port::flags field with
TTY_PORT_ACTIVE bit in the tty_port::iflags field. Introduce helpers
tty_port_set_active() and tty_port_active() to abstract atomic bit ops.

Extract state changes from port lock sections, as this usage is
broken and confused; the state transitions are protected by the
tty lock (which mutually excludes parallel open/close/hangup),
and no user tests the active state while holding the port lock.

Signed-off-by: Peter Hurley 
---
 drivers/isdn/i4l/isdn_tty.c  | 20 +---
 drivers/tty/amiserial.c  |  2 +-
 drivers/tty/rocket.c |  5 +++--
 drivers/tty/serial/crisv10.c |  8 
 drivers/tty/serial/serial_core.c |  8 
 drivers/tty/synclink.c   |  6 +++---
 drivers/tty/synclink_gt.c|  6 +++---
 drivers/tty/synclinkmp.c |  6 +++---
 drivers/tty/tty_port.c   | 12 ++--
 include/linux/tty.h  | 12 
 net/irda/ircomm/ircomm_tty.c | 10 +-
 11 files changed, 53 insertions(+), 42 deletions(-)

diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index f1edc08..d8468f3 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1622,7 +1622,7 @@ isdn_tty_hangup(struct tty_struct *tty)
return;
isdn_tty_shutdown(info);
port->count = 0;
-   port->flags &= ~ASYNC_NORMAL_ACTIVE;
+   tty_port_set_active(port, 0);
port->tty = NULL;
wake_up_interruptible(>open_wait);
 }
@@ -1979,7 +1979,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
 #endif
if (
 #ifndef FIX_FILE_TRANSFER
-   (info->port.flags & ASYNC_NORMAL_ACTIVE) &&
+   tty_port_active(>port) &&
 #endif
(info->isdn_driver == -1) &&
(info->isdn_channel == -1) &&
@@ -2018,8 +2018,6 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
return (wret == 2) ? 3 : 0;
 }
 
-#define TTY_IS_ACTIVE(info)(info->port.flags & ASYNC_NORMAL_ACTIVE)
-
 int
 isdn_tty_stat_callback(int i, isdn_ctrl *c)
 {
@@ -2077,7 +2075,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 #ifdef ISDN_TTY_STAT_DEBUG
printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", 
info->line);
 #endif
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
if (info->dialing == 1) {
info->dialing = 2;
return 1;
@@ -2088,7 +2086,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 #ifdef ISDN_TTY_STAT_DEBUG
printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line);
 #endif
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
if (info->dialing == 1)
isdn_tty_modem_result(RESULT_BUSY, 
info);
if (info->dialing > 1)
@@ -2118,7 +2116,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 * waiting for it and
 * set DCD-bit of its modem-status.
 */
-   if (TTY_IS_ACTIVE(info) ||
+   if (tty_port_active(>port) ||
(info->port.blocked_open &&
 (info->emu.mdmreg[REG_DCD] & BIT_DCD))) {
info->msr |= UART_MSR_DCD;
@@ -2145,7 +2143,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 #ifdef ISDN_TTY_STAT_DEBUG
printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line);
 #endif
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
 #ifdef ISDN_DEBUG_MODEM_HUP
printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n");
 #endif
@@ -2157,7 +2155,7 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
 #ifdef ISDN_TTY_STAT_DEBUG
printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", 
info->line);
 #endif
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
if (info->dialing) {
info->dialing = 0;
info->last_l2 = -1;
@@ -2183,14 +2181,14 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
return 1;
 #ifdef CONFIG_ISDN_TTY_FAX
case ISDN_STAT_FAXIND:
-   if (TTY_IS_ACTIVE(info)) {
+   if (tty_port_active(>port)) {
isdn_tty_fax_command(info, c);
}
break;
 #endif
 #ifdef CONFIG_ISDN_AUDIO
case ISDN_STAT_AUDIO:
-   if 

[PATCH 4/8] tty: Replace ASYNC_CHECK_CD and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_CHECK_CD bit in the tty_port::flags field with
TTY_PORT_CHECK_CD bit in the tty_port::iflags field. Introduce helpers
tty_port_set_check_carrier() and tty_port_check_carrier() to abstract
the atomic bit ops.

Signed-off-by: Peter Hurley 
---
 drivers/char/pcmcia/synclink_cs.c   |  8 ++--
 drivers/isdn/i4l/isdn_tty.c |  8 ++--
 drivers/tty/amiserial.c |  9 +++--
 drivers/tty/cyclades.c  | 14 --
 drivers/tty/isicom.c|  7 ++-
 drivers/tty/mxser.c |  9 +++--
 drivers/tty/synclink.c  |  8 ++--
 drivers/tty/synclink_gt.c   |  8 ++--
 drivers/tty/synclinkmp.c|  8 ++--
 include/linux/tty.h | 13 +
 net/irda/ircomm/ircomm_tty.c|  4 ++--
 net/irda/ircomm/ircomm_tty_attach.c |  2 +-
 net/irda/ircomm/ircomm_tty_ioctl.c  |  5 +
 13 files changed, 39 insertions(+), 64 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index bdf41ac..bf54f4e 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1101,7 +1101,7 @@ static void dcd_change(MGSLPC_INFO *info, struct 
tty_struct *tty)
wake_up_interruptible(>status_event_wait_q);
wake_up_interruptible(>event_wait_q);
 
-   if (info->port.flags & ASYNC_CHECK_CD) {
+   if (tty_port_check_carrier(>port)) {
if (debug_level >= DEBUG_LEVEL_ISR)
printk("%s CD now %s...", info->device_name,
   (info->serial_signals & SerialSignal_DCD) ? "on" 
: "off");
@@ -1467,11 +1467,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info, 
struct tty_struct *tty)
info->timeout += HZ/50; /* Add .02 seconds of slop */
 
tty_port_set_cts_flow(>port, cflag & CRTSCTS);
-
-   if (cflag & CLOCAL)
-   info->port.flags &= ~ASYNC_CHECK_CD;
-   else
-   info->port.flags |= ASYNC_CHECK_CD;
+   tty_port_set_check_carrier(>port, ~cflag & CLOCAL);
 
/* process tty input control flags */
 
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index d8468f3..023a350a 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1043,11 +1043,7 @@ isdn_tty_change_speed(modem_info *info)
if (!(cflag & PARODD))
cval |= UART_LCR_EPAR;
 
-   if (cflag & CLOCAL)
-   port->flags &= ~ASYNC_CHECK_CD;
-   else {
-   port->flags |= ASYNC_CHECK_CD;
-   }
+   tty_port_set_check_carrier(port, ~cflag & CLOCAL);
 }
 
 static int
@@ -2526,7 +2522,7 @@ isdn_tty_modem_result(int code, modem_info *info)
if (info->closing || (!info->port.tty))
return;
 
-   if (info->port.flags & ASYNC_CHECK_CD)
+   if (tty_port_check_carrier(>port))
tty_hangup(info->port.tty);
}
 }
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 80d6165..b4ab97d 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -398,7 +398,7 @@ static void check_modem_status(struct serial_state *info)
wake_up_interruptible(>delta_msr_wait);
}
 
-   if ((port->flags & ASYNC_CHECK_CD) && (dstatus & SER_DCD)) {
+   if (tty_port_check_carrier(port) && (dstatus & SER_DCD)) {
 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
printk("ttyS%d CD now %s...", info->line,
   (!(status & SER_DCD)) ? "on" : "off");
@@ -730,12 +730,9 @@ static void change_speed(struct tty_struct *tty, struct 
serial_state *info,
tty_port_set_cts_flow(port, cflag & CRTSCTS);
if (cflag & CRTSCTS)
info->IER |= UART_IER_MSI;
-   if (cflag & CLOCAL)
-   port->flags &= ~ASYNC_CHECK_CD;
-   else {
-   port->flags |= ASYNC_CHECK_CD;
+   tty_port_set_check_carrier(port, ~cflag & CLOCAL);
+   if (~cflag & CLOCAL)
info->IER |= UART_IER_MSI;
-   }
/* TBD:
 * Does clearing IER_MSI imply that we should disable the VBL interrupt 
?
 */
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index 1a12776..9d1e19b 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -714,7 +714,7 @@ static void cyy_chip_modem(struct cyclades_card *cinfo, int 
chip,
wake_up_interruptible(>port.delta_msr_wait);
}
 
-   if ((mdm_change & CyDCD) && (info->port.flags & ASYNC_CHECK_CD)) {
+   if ((mdm_change & CyDCD) && tty_port_check_carrier(>port)) {
if (mdm_status & CyDCD)
wake_up_interruptible(>port.open_wait);
else
@@ -1119,7 +1119,7 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
case C_CM_MDCD:
info->icount.dcd++;

[PATCH 8/8] tty: core: Undefine ASYNC_* flags superceded by TTY_PORT* flags

2016-04-09 Thread Peter Hurley
Purposefully break out-of-tree driver compiles using kernel
ASYNC_* bits which have been superceded by TTY_PORT* flags and
their respective helper functions.

Signed-off-by: Peter Hurley 
---
 include/uapi/linux/tty_flags.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/uapi/linux/tty_flags.h b/include/uapi/linux/tty_flags.h
index 8e1a436..66e4d8b 100644
--- a/include/uapi/linux/tty_flags.h
+++ b/include/uapi/linux/tty_flags.h
@@ -38,6 +38,7 @@
  * WARNING: These flags are no longer used and have been superceded by the
  * TTY_PORT_ flags in the iflags field (and not userspace-visible)
  */
+#ifndef _KERNEL_
 #define ASYNCB_INITIALIZED 31 /* Serial port was initialized */
 #define ASYNCB_SUSPENDED   30 /* Serial port is suspended */
 #define ASYNCB_NORMAL_ACTIVE   29 /* Normal device is active */
@@ -48,6 +49,7 @@
 #define ASYNCB_SHARE_IRQ   24 /* for multifunction cards, no longer used */
 #define ASYNCB_CONS_FLOW   23 /* flow control for console  */
 #define ASYNCB_FIRST_KERNEL22
+#endif
 
 /* Masks */
 #define ASYNC_HUP_NOTIFY   (1U << ASYNCB_HUP_NOTIFY)
@@ -78,6 +80,7 @@
 #define ASYNC_SPD_WARP (ASYNC_SPD_HI|ASYNC_SPD_SHI)
 #define ASYNC_SPD_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI|ASYNC_SPD_SHI)
 
+#ifndef _KERNEL_
 /* These flags are no longer used (and were always masked from userspace) */
 #define ASYNC_INITIALIZED  (1U << ASYNCB_INITIALIZED)
 #define ASYNC_NORMAL_ACTIVE(1U << ASYNCB_NORMAL_ACTIVE)
@@ -88,5 +91,6 @@
 #define ASYNC_SHARE_IRQ(1U << ASYNCB_SHARE_IRQ)
 #define ASYNC_CONS_FLOW(1U << ASYNCB_CONS_FLOW)
 #define ASYNC_INTERNAL_FLAGS   (~((1U << ASYNCB_FIRST_KERNEL) - 1))
+#endif
 
 #endif
-- 
2.8.1



[PATCH 0/8] Replace kernel-defined ASYNC_ bits

2016-04-09 Thread Peter Hurley
As outlined in my January email ("RFC: out-of-tree tty driver breakage"),
the tty/serial core uses 5 bits in the tty_port.flags field to manage
state. They are:

ASYNCB_INITIALIZED
ASYNCB_SUSPENDED
ASYNCB_NORMAL_ACTIVE
ASYNCB_CTS_FLOW
ASYNCB_CHECK_CD

(NB: ASYNC_CLOSING was recently removed)

However, updates to this field (tty_port.flags) can be and often are
non-atomic. Additionally, the field is visible to/modifiable by userspace
(the state bits above are not modifiable by userspace though).

This series moves these state bits into a different tty_port field
(iflags) and abstracts state tests and changes with trivial helpers.

The last patch of the series purposefully breaks out-of-tree driver
builds to ensure they update state test/change methods to the helpers
instead.

REQUIRES: "tty: Replace TTY_IO_ERROR bit tests with tty_io_error()"
  "tty: Replace TTY_THROTTLED bit tests with tty_throttled()"

Regards,

Peter Hurley (8):
  tty: Define ASYNC_ replacement bits
  tty: Replace ASYNC_CTS_FLOW bit and update atomically
  tty: Replace ASYNC_NORMAL_ACTIVE bit and update atomically
  tty: Replace ASYNC_CHECK_CD and update atomically
  tty: Replace ASYNC_SUSPENDED bit and update atomically
  tty: Replace ASYNC_INITIALIZED bit and update atomically
  tty: mxser: Remove unused ASYNC_SHARE_IRQ flag
  tty: core: Undefine ASYNC_* flags superceded by TTY_PORT* flags

 drivers/char/pcmcia/synclink_cs.c   | 25 +---
 drivers/ipack/devices/ipoctal.c |  5 +--
 drivers/isdn/i4l/isdn_tty.c | 38 --
 drivers/s390/char/con3215.c | 22 +--
 drivers/tty/amiserial.c | 31 +++
 drivers/tty/cyclades.c  | 38 --
 drivers/tty/isicom.c| 19 -
 drivers/tty/moxa.c  | 10 ++---
 drivers/tty/mxser.c | 28 +-
 drivers/tty/n_gsm.c |  8 ++--
 drivers/tty/rocket.c| 13 ---
 drivers/tty/serial/crisv10.c| 25 ++--
 drivers/tty/serial/serial_core.c| 40 ++-
 drivers/tty/synclink.c  | 65 ++-
 drivers/tty/synclink_gt.c   | 35 +++--
 drivers/tty/synclinkmp.c| 35 +++--
 drivers/tty/tty_port.c  | 25 ++--
 drivers/usb/class/cdc-acm.c |  4 +-
 drivers/usb/serial/console.c|  4 +-
 drivers/usb/serial/generic.c|  6 +--
 drivers/usb/serial/mxuport.c|  6 +--
 drivers/usb/serial/sierra.c |  4 +-
 drivers/usb/serial/usb-serial.c |  2 +-
 drivers/usb/serial/usb_wwan.c   |  4 +-
 include/linux/tty.h | 77 -
 include/uapi/linux/tty_flags.h  | 13 ++-
 net/irda/ircomm/ircomm_tty.c| 29 +++---
 net/irda/ircomm/ircomm_tty_attach.c |  2 +-
 net/irda/ircomm/ircomm_tty_ioctl.c  | 10 ++---
 29 files changed, 320 insertions(+), 303 deletions(-)

-- 
2.8.1



[PATCH 6/8] tty: Replace ASYNC_INITIALIZED bit and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_INITIALIZED bit in the tty_port::flags field with
TTY_PORT_INITIALIZED bit in the tty_port::iflags field. Introduce helpers
tty_port_set_initialized() and tty_port_initialized() to abstract
atomic bit ops.

Note: the transforms for test_and_set_bit() and test_and_clear_bit()
are unnecessary as the state transitions are already mutually exclusive;
the tty lock prevents concurrent open/close/hangup.

Signed-off-by: Peter Hurley 
---
 drivers/char/pcmcia/synclink_cs.c  | 12 +-
 drivers/ipack/devices/ipoctal.c|  5 ++---
 drivers/isdn/i4l/isdn_tty.c| 10 -
 drivers/s390/char/con3215.c| 12 +-
 drivers/tty/amiserial.c| 14 ++--
 drivers/tty/cyclades.c | 14 ++--
 drivers/tty/isicom.c   |  6 ++---
 drivers/tty/moxa.c | 10 -
 drivers/tty/mxser.c| 14 +---
 drivers/tty/n_gsm.c|  8 +++
 drivers/tty/rocket.c   | 10 -
 drivers/tty/serial/crisv10.c   | 17 +++---
 drivers/tty/serial/serial_core.c   | 24 +++-
 drivers/tty/synclink.c | 46 ++
 drivers/tty/synclink_gt.c  | 16 ++---
 drivers/tty/synclinkmp.c   | 16 ++---
 drivers/tty/tty_port.c | 13 ++-
 drivers/usb/class/cdc-acm.c|  4 ++--
 drivers/usb/serial/console.c   |  4 ++--
 drivers/usb/serial/generic.c   |  6 ++---
 drivers/usb/serial/mxuport.c   |  6 ++---
 drivers/usb/serial/sierra.c|  4 ++--
 drivers/usb/serial/usb-serial.c|  2 +-
 drivers/usb/serial/usb_wwan.c  |  4 ++--
 include/linux/tty.h| 13 +++
 net/irda/ircomm/ircomm_tty.c   | 15 +++--
 net/irda/ircomm/ircomm_tty_ioctl.c |  2 +-
 27 files changed, 157 insertions(+), 150 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index bf54f4e..345ca7c 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1272,7 +1272,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct 
*tty)
if (debug_level >= DEBUG_LEVEL_INFO)
printk("%s(%d):startup(%s)\n", __FILE__, __LINE__, 
info->device_name);
 
-   if (info->port.flags & ASYNC_INITIALIZED)
+   if (tty_port_initialized(>port))
return 0;
 
if (!info->tx_buf) {
@@ -1311,7 +1311,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct 
*tty)
if (tty)
clear_bit(TTY_IO_ERROR, >flags);
 
-   info->port.flags |= ASYNC_INITIALIZED;
+   tty_port_set_initialized(>port, 1);
 
return 0;
 }
@@ -1322,7 +1322,7 @@ static void shutdown(MGSLPC_INFO * info, struct 
tty_struct *tty)
 {
unsigned long flags;
 
-   if (!(info->port.flags & ASYNC_INITIALIZED))
+   if (!tty_port_initialized(>port))
return;
 
if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1361,7 +1361,7 @@ static void shutdown(MGSLPC_INFO * info, struct 
tty_struct *tty)
if (tty)
set_bit(TTY_IO_ERROR, >flags);
 
-   info->port.flags &= ~ASYNC_INITIALIZED;
+   tty_port_set_initialized(>port, 0);
 }
 
 static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty)
@@ -2338,7 +2338,7 @@ static void mgslpc_close(struct tty_struct *tty, struct 
file * filp)
if (tty_port_close_start(port, tty, filp) == 0)
goto cleanup;
 
-   if (port->flags & ASYNC_INITIALIZED)
+   if (tty_port_initialized(port))
mgslpc_wait_until_sent(tty, info->timeout);
 
mgslpc_flush_buffer(tty);
@@ -2371,7 +2371,7 @@ static void mgslpc_wait_until_sent(struct tty_struct 
*tty, int timeout)
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent"))
return;
 
-   if (!(info->port.flags & ASYNC_INITIALIZED))
+   if (!tty_port_initialized(>port))
goto exit;
 
orig_jiffies = jiffies;
diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
index 035d544..75dd15d 100644
--- a/drivers/ipack/devices/ipoctal.c
+++ b/drivers/ipack/devices/ipoctal.c
@@ -629,8 +629,7 @@ static void ipoctal_hangup(struct tty_struct *tty)
tty_port_hangup(>tty_port);
 
ipoctal_reset_channel(channel);
-
-   clear_bit(ASYNCB_INITIALIZED, >tty_port.flags);
+   tty_port_set_initialized(>tty_port, 0);
wake_up_interruptible(>tty_port.open_wait);
 }
 
@@ -642,7 +641,7 @@ static void ipoctal_shutdown(struct tty_struct *tty)
return;
 
ipoctal_reset_channel(channel);
-   clear_bit(ASYNCB_INITIALIZED, >tty_port.flags);
+   tty_port_set_initialized(>tty_port, 0);
 }
 
 static void ipoctal_cleanup(struct tty_struct *tty)
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 023a350a..63eaa0a 100644
--- 

[PATCH 8/8] tty: core: Undefine ASYNC_* flags superceded by TTY_PORT* flags

2016-04-09 Thread Peter Hurley
Purposefully break out-of-tree driver compiles using kernel
ASYNC_* bits which have been superceded by TTY_PORT* flags and
their respective helper functions.

Signed-off-by: Peter Hurley 
---
 include/uapi/linux/tty_flags.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/uapi/linux/tty_flags.h b/include/uapi/linux/tty_flags.h
index 8e1a436..66e4d8b 100644
--- a/include/uapi/linux/tty_flags.h
+++ b/include/uapi/linux/tty_flags.h
@@ -38,6 +38,7 @@
  * WARNING: These flags are no longer used and have been superceded by the
  * TTY_PORT_ flags in the iflags field (and not userspace-visible)
  */
+#ifndef _KERNEL_
 #define ASYNCB_INITIALIZED 31 /* Serial port was initialized */
 #define ASYNCB_SUSPENDED   30 /* Serial port is suspended */
 #define ASYNCB_NORMAL_ACTIVE   29 /* Normal device is active */
@@ -48,6 +49,7 @@
 #define ASYNCB_SHARE_IRQ   24 /* for multifunction cards, no longer used */
 #define ASYNCB_CONS_FLOW   23 /* flow control for console  */
 #define ASYNCB_FIRST_KERNEL22
+#endif
 
 /* Masks */
 #define ASYNC_HUP_NOTIFY   (1U << ASYNCB_HUP_NOTIFY)
@@ -78,6 +80,7 @@
 #define ASYNC_SPD_WARP (ASYNC_SPD_HI|ASYNC_SPD_SHI)
 #define ASYNC_SPD_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI|ASYNC_SPD_SHI)
 
+#ifndef _KERNEL_
 /* These flags are no longer used (and were always masked from userspace) */
 #define ASYNC_INITIALIZED  (1U << ASYNCB_INITIALIZED)
 #define ASYNC_NORMAL_ACTIVE(1U << ASYNCB_NORMAL_ACTIVE)
@@ -88,5 +91,6 @@
 #define ASYNC_SHARE_IRQ(1U << ASYNCB_SHARE_IRQ)
 #define ASYNC_CONS_FLOW(1U << ASYNCB_CONS_FLOW)
 #define ASYNC_INTERNAL_FLAGS   (~((1U << ASYNCB_FIRST_KERNEL) - 1))
+#endif
 
 #endif
-- 
2.8.1



[PATCH 0/8] Replace kernel-defined ASYNC_ bits

2016-04-09 Thread Peter Hurley
As outlined in my January email ("RFC: out-of-tree tty driver breakage"),
the tty/serial core uses 5 bits in the tty_port.flags field to manage
state. They are:

ASYNCB_INITIALIZED
ASYNCB_SUSPENDED
ASYNCB_NORMAL_ACTIVE
ASYNCB_CTS_FLOW
ASYNCB_CHECK_CD

(NB: ASYNC_CLOSING was recently removed)

However, updates to this field (tty_port.flags) can be and often are
non-atomic. Additionally, the field is visible to/modifiable by userspace
(the state bits above are not modifiable by userspace though).

This series moves these state bits into a different tty_port field
(iflags) and abstracts state tests and changes with trivial helpers.

The last patch of the series purposefully breaks out-of-tree driver
builds to ensure they update state test/change methods to the helpers
instead.

REQUIRES: "tty: Replace TTY_IO_ERROR bit tests with tty_io_error()"
  "tty: Replace TTY_THROTTLED bit tests with tty_throttled()"

Regards,

Peter Hurley (8):
  tty: Define ASYNC_ replacement bits
  tty: Replace ASYNC_CTS_FLOW bit and update atomically
  tty: Replace ASYNC_NORMAL_ACTIVE bit and update atomically
  tty: Replace ASYNC_CHECK_CD and update atomically
  tty: Replace ASYNC_SUSPENDED bit and update atomically
  tty: Replace ASYNC_INITIALIZED bit and update atomically
  tty: mxser: Remove unused ASYNC_SHARE_IRQ flag
  tty: core: Undefine ASYNC_* flags superceded by TTY_PORT* flags

 drivers/char/pcmcia/synclink_cs.c   | 25 +---
 drivers/ipack/devices/ipoctal.c |  5 +--
 drivers/isdn/i4l/isdn_tty.c | 38 --
 drivers/s390/char/con3215.c | 22 +--
 drivers/tty/amiserial.c | 31 +++
 drivers/tty/cyclades.c  | 38 --
 drivers/tty/isicom.c| 19 -
 drivers/tty/moxa.c  | 10 ++---
 drivers/tty/mxser.c | 28 +-
 drivers/tty/n_gsm.c |  8 ++--
 drivers/tty/rocket.c| 13 ---
 drivers/tty/serial/crisv10.c| 25 ++--
 drivers/tty/serial/serial_core.c| 40 ++-
 drivers/tty/synclink.c  | 65 ++-
 drivers/tty/synclink_gt.c   | 35 +++--
 drivers/tty/synclinkmp.c| 35 +++--
 drivers/tty/tty_port.c  | 25 ++--
 drivers/usb/class/cdc-acm.c |  4 +-
 drivers/usb/serial/console.c|  4 +-
 drivers/usb/serial/generic.c|  6 +--
 drivers/usb/serial/mxuport.c|  6 +--
 drivers/usb/serial/sierra.c |  4 +-
 drivers/usb/serial/usb-serial.c |  2 +-
 drivers/usb/serial/usb_wwan.c   |  4 +-
 include/linux/tty.h | 77 -
 include/uapi/linux/tty_flags.h  | 13 ++-
 net/irda/ircomm/ircomm_tty.c| 29 +++---
 net/irda/ircomm/ircomm_tty_attach.c |  2 +-
 net/irda/ircomm/ircomm_tty_ioctl.c  | 10 ++---
 29 files changed, 320 insertions(+), 303 deletions(-)

-- 
2.8.1



[PATCH 6/8] tty: Replace ASYNC_INITIALIZED bit and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_INITIALIZED bit in the tty_port::flags field with
TTY_PORT_INITIALIZED bit in the tty_port::iflags field. Introduce helpers
tty_port_set_initialized() and tty_port_initialized() to abstract
atomic bit ops.

Note: the transforms for test_and_set_bit() and test_and_clear_bit()
are unnecessary as the state transitions are already mutually exclusive;
the tty lock prevents concurrent open/close/hangup.

Signed-off-by: Peter Hurley 
---
 drivers/char/pcmcia/synclink_cs.c  | 12 +-
 drivers/ipack/devices/ipoctal.c|  5 ++---
 drivers/isdn/i4l/isdn_tty.c| 10 -
 drivers/s390/char/con3215.c| 12 +-
 drivers/tty/amiserial.c| 14 ++--
 drivers/tty/cyclades.c | 14 ++--
 drivers/tty/isicom.c   |  6 ++---
 drivers/tty/moxa.c | 10 -
 drivers/tty/mxser.c| 14 +---
 drivers/tty/n_gsm.c|  8 +++
 drivers/tty/rocket.c   | 10 -
 drivers/tty/serial/crisv10.c   | 17 +++---
 drivers/tty/serial/serial_core.c   | 24 +++-
 drivers/tty/synclink.c | 46 ++
 drivers/tty/synclink_gt.c  | 16 ++---
 drivers/tty/synclinkmp.c   | 16 ++---
 drivers/tty/tty_port.c | 13 ++-
 drivers/usb/class/cdc-acm.c|  4 ++--
 drivers/usb/serial/console.c   |  4 ++--
 drivers/usb/serial/generic.c   |  6 ++---
 drivers/usb/serial/mxuport.c   |  6 ++---
 drivers/usb/serial/sierra.c|  4 ++--
 drivers/usb/serial/usb-serial.c|  2 +-
 drivers/usb/serial/usb_wwan.c  |  4 ++--
 include/linux/tty.h| 13 +++
 net/irda/ircomm/ircomm_tty.c   | 15 +++--
 net/irda/ircomm/ircomm_tty_ioctl.c |  2 +-
 27 files changed, 157 insertions(+), 150 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index bf54f4e..345ca7c 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1272,7 +1272,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct 
*tty)
if (debug_level >= DEBUG_LEVEL_INFO)
printk("%s(%d):startup(%s)\n", __FILE__, __LINE__, 
info->device_name);
 
-   if (info->port.flags & ASYNC_INITIALIZED)
+   if (tty_port_initialized(>port))
return 0;
 
if (!info->tx_buf) {
@@ -1311,7 +1311,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct 
*tty)
if (tty)
clear_bit(TTY_IO_ERROR, >flags);
 
-   info->port.flags |= ASYNC_INITIALIZED;
+   tty_port_set_initialized(>port, 1);
 
return 0;
 }
@@ -1322,7 +1322,7 @@ static void shutdown(MGSLPC_INFO * info, struct 
tty_struct *tty)
 {
unsigned long flags;
 
-   if (!(info->port.flags & ASYNC_INITIALIZED))
+   if (!tty_port_initialized(>port))
return;
 
if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1361,7 +1361,7 @@ static void shutdown(MGSLPC_INFO * info, struct 
tty_struct *tty)
if (tty)
set_bit(TTY_IO_ERROR, >flags);
 
-   info->port.flags &= ~ASYNC_INITIALIZED;
+   tty_port_set_initialized(>port, 0);
 }
 
 static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty)
@@ -2338,7 +2338,7 @@ static void mgslpc_close(struct tty_struct *tty, struct 
file * filp)
if (tty_port_close_start(port, tty, filp) == 0)
goto cleanup;
 
-   if (port->flags & ASYNC_INITIALIZED)
+   if (tty_port_initialized(port))
mgslpc_wait_until_sent(tty, info->timeout);
 
mgslpc_flush_buffer(tty);
@@ -2371,7 +2371,7 @@ static void mgslpc_wait_until_sent(struct tty_struct 
*tty, int timeout)
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent"))
return;
 
-   if (!(info->port.flags & ASYNC_INITIALIZED))
+   if (!tty_port_initialized(>port))
goto exit;
 
orig_jiffies = jiffies;
diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
index 035d544..75dd15d 100644
--- a/drivers/ipack/devices/ipoctal.c
+++ b/drivers/ipack/devices/ipoctal.c
@@ -629,8 +629,7 @@ static void ipoctal_hangup(struct tty_struct *tty)
tty_port_hangup(>tty_port);
 
ipoctal_reset_channel(channel);
-
-   clear_bit(ASYNCB_INITIALIZED, >tty_port.flags);
+   tty_port_set_initialized(>tty_port, 0);
wake_up_interruptible(>tty_port.open_wait);
 }
 
@@ -642,7 +641,7 @@ static void ipoctal_shutdown(struct tty_struct *tty)
return;
 
ipoctal_reset_channel(channel);
-   clear_bit(ASYNCB_INITIALIZED, >tty_port.flags);
+   tty_port_set_initialized(>tty_port, 0);
 }
 
 static void ipoctal_cleanup(struct tty_struct *tty)
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 023a350a..63eaa0a 100644
--- a/drivers/isdn/i4l/isdn_tty.c

[PATCH 5/8] tty: Replace ASYNC_SUSPENDED bit and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_SUSPENDED bit in the tty_port::flags field with
TTY_PORT_SUSPENDED bit in the tty_port::iflags field. Introduce helpers
tty_port_set_suspended() and tty_port_suspended() to abstract
atomic bit ops.

Signed-off-by: Peter Hurley 
---
 drivers/s390/char/con3215.c  | 12 ++--
 drivers/tty/serial/serial_core.c |  8 
 include/linux/tty.h  | 13 +
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index e7e078b..114fe28 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -289,7 +289,7 @@ static void raw3215_timeout(unsigned long __data)
 
spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
raw->flags &= ~RAW3215_TIMER_RUNS;
-   if (!(raw->port.flags & ASYNC_SUSPENDED)) {
+   if (!tty_port_suspended(>port)) {
raw3215_mk_write_req(raw);
raw3215_start_io(raw);
if ((raw->queued_read || raw->queued_write) &&
@@ -312,7 +312,7 @@ static void raw3215_timeout(unsigned long __data)
 static inline void raw3215_try_io(struct raw3215_info *raw)
 {
if (!(raw->port.flags & ASYNC_INITIALIZED) ||
-   (raw->port.flags & ASYNC_SUSPENDED))
+   tty_port_suspended(>port))
return;
if (raw->queued_read != NULL)
raw3215_start_io(raw);
@@ -494,7 +494,7 @@ static void raw3215_make_room(struct raw3215_info *raw, 
unsigned int length)
/* While console is frozen for suspend we have no other
 * choice but to drop message from the buffer to make
 * room for even more messages. */
-   if (raw->port.flags & ASYNC_SUSPENDED) {
+   if (tty_port_suspended(>port)) {
raw3215_drop_line(raw);
continue;
}
@@ -773,7 +773,7 @@ static int raw3215_pm_stop(struct ccw_device *cdev)
raw = dev_get_drvdata(>dev);
spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
-   raw->port.flags |= ASYNC_SUSPENDED;
+   tty_port_set_suspended(>port, 1);
spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
return 0;
 }
@@ -786,7 +786,7 @@ static int raw3215_pm_start(struct ccw_device *cdev)
/* Allow I/O again and flush output buffer. */
raw = dev_get_drvdata(>dev);
spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
-   raw->port.flags &= ~ASYNC_SUSPENDED;
+   tty_port_set_suspended(>port, 0);
raw->flags |= RAW3215_FLUSHING;
raw3215_try_io(raw);
raw->flags &= ~RAW3215_FLUSHING;
@@ -859,7 +859,7 @@ static void con3215_flush(void)
unsigned long flags;
 
raw = raw3215[0];  /* console 3215 is the first one */
-   if (raw->port.flags & ASYNC_SUSPENDED)
+   if (tty_port_suspended(>port))
/* The console is still frozen for suspend. */
if (ccw_device_force_console(raw->cdev))
/* Forcing didn't work, no panic message .. */
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 2471380..9336067 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -249,7 +249,7 @@ static void uart_shutdown(struct tty_struct *tty, struct 
uart_state *state)
 * a DCD drop (hangup) at just the right time.  Clear suspended bit so
 * we don't try to resume a port that has been shutdown.
 */
-   clear_bit(ASYNCB_SUSPENDED, >flags);
+   tty_port_set_suspended(port, 0);
 
/*
 * Free the transmit buffer page.
@@ -2007,7 +2007,7 @@ int uart_suspend_port(struct uart_driver *drv, struct 
uart_port *uport)
const struct uart_ops *ops = uport->ops;
int tries;
 
-   set_bit(ASYNCB_SUSPENDED, >flags);
+   tty_port_set_suspended(port, 1);
clear_bit(ASYNCB_INITIALIZED, >flags);
 
spin_lock_irq(>lock);
@@ -2088,7 +2088,7 @@ int uart_resume_port(struct uart_driver *drv, struct 
uart_port *uport)
console_start(uport->cons);
}
 
-   if (port->flags & ASYNC_SUSPENDED) {
+   if (tty_port_suspended(port)) {
const struct uart_ops *ops = uport->ops;
int ret;
 
@@ -2118,7 +2118,7 @@ int uart_resume_port(struct uart_driver *drv, struct 
uart_port *uport)
}
}
 
-   clear_bit(ASYNCB_SUSPENDED, >flags);
+   tty_port_set_suspended(port, 0);
}
 
mutex_unlock(>mutex);
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 4254dfb..7ac5add 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -597,6 +597,19 @@ static inline void tty_port_set_check_carrier(struct 
tty_port *port, bool 

[PATCH 2/8] tty: Replace ASYNC_CTS_FLOW bit and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_CTS_FLOW bit in the tty_port::flags field with
TTY_PORT_CTS_FLOW bit in the tty_port::iflags field. Add
tty_port_set_cts_flow() helper to abstract the atomic bit ops.

Signed-off-by: Peter Hurley 
---
 drivers/char/pcmcia/synclink_cs.c  |  5 +
 drivers/tty/amiserial.c|  6 ++
 drivers/tty/cyclades.c | 10 --
 drivers/tty/isicom.c   |  6 ++
 drivers/tty/mxser.c|  4 +---
 drivers/tty/synclink.c |  7 ++-
 drivers/tty/synclink_gt.c  |  5 +
 drivers/tty/synclinkmp.c   |  5 +
 include/linux/tty.h| 12 ++--
 net/irda/ircomm/ircomm_tty_ioctl.c |  3 +--
 10 files changed, 25 insertions(+), 38 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index bcae5bb..bdf41ac 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1466,10 +1466,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info, 
struct tty_struct *tty)
}
info->timeout += HZ/50; /* Add .02 seconds of slop */
 
-   if (cflag & CRTSCTS)
-   info->port.flags |= ASYNC_CTS_FLOW;
-   else
-   info->port.flags &= ~ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(>port, cflag & CRTSCTS);
 
if (cflag & CLOCAL)
info->port.flags &= ~ASYNC_CHECK_CD;
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index e68208e..92717b0 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -727,11 +727,9 @@ static void change_speed(struct tty_struct *tty, struct 
serial_state *info,
info->IER &= ~UART_IER_MSI;
if (port->flags & ASYNC_HARDPPS_CD)
info->IER |= UART_IER_MSI;
-   if (cflag & CRTSCTS) {
-   port->flags |= ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(port, cflag & CRTSCTS);
+   if (cflag & CRTSCTS)
info->IER |= UART_IER_MSI;
-   } else
-   port->flags &= ~ASYNC_CTS_FLOW;
if (cflag & CLOCAL)
port->flags &= ~ASYNC_CHECK_CD;
else {
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index d67e542..1a12776 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -2083,13 +2083,11 @@ static void cy_set_line_char(struct cyclades_port 
*info, struct tty_struct *tty)
info->cor1 |= CyPARITY_NONE;
 
/* CTS flow control flag */
-   if (cflag & CRTSCTS) {
-   info->port.flags |= ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(>port, cflag & CRTSCTS);
+   if (cflag & CRTSCTS)
info->cor2 |= CyCtsAE;
-   } else {
-   info->port.flags &= ~ASYNC_CTS_FLOW;
+   else
info->cor2 &= ~CyCtsAE;
-   }
if (cflag & CLOCAL)
info->port.flags &= ~ASYNC_CHECK_CD;
else
@@ -2234,7 +2232,7 @@ static void cy_set_line_char(struct cyclades_port *info, 
struct tty_struct *tty)
}
/* As the HW flow control is done in firmware, the driver
   doesn't need to care about it */
-   info->port.flags &= ~ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(>port, 0);
 
/* XON/XOFF/XANY flow control flags */
sw_flow = 0;
diff --git a/drivers/tty/isicom.c b/drivers/tty/isicom.c
index 8bf6763..c5f06b5 100644
--- a/drivers/tty/isicom.c
+++ b/drivers/tty/isicom.c
@@ -765,11 +765,9 @@ static void isicom_config_port(struct tty_struct *tty)
 
/* flow control settings ...*/
flow_ctrl = 0;
-   port->port.flags &= ~ASYNC_CTS_FLOW;
-   if (C_CRTSCTS(tty)) {
-   port->port.flags |= ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(>port, C_CRTSCTS(tty));
+   if (C_CRTSCTS(tty))
flow_ctrl |= ISICOM_CTSRTS;
-   }
if (I_IXON(tty))
flow_ctrl |= ISICOM_RESPOND_XONXOFF;
if (I_IXOFF(tty))
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index f23c2a1..8f3fdad 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -711,8 +711,8 @@ static int mxser_change_speed(struct tty_struct *tty,
/* CTS flow control flag and modem status interrupts */
info->IER &= ~UART_IER_MSI;
info->MCR &= ~UART_MCR_AFE;
+   tty_port_set_cts_flow(>port, cflag & CRTSCTS);
if (cflag & CRTSCTS) {
-   info->port.flags |= ASYNC_CTS_FLOW;
info->IER |= UART_IER_MSI;
if ((info->type == PORT_16550A) || (info->board->chip_flag)) {
info->MCR |= UART_MCR_AFE;
@@ -744,8 +744,6 @@ static int mxser_change_speed(struct tty_struct *tty,
}
}
}
-   } else {
-   

[PATCH 5/8] tty: Replace ASYNC_SUSPENDED bit and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_SUSPENDED bit in the tty_port::flags field with
TTY_PORT_SUSPENDED bit in the tty_port::iflags field. Introduce helpers
tty_port_set_suspended() and tty_port_suspended() to abstract
atomic bit ops.

Signed-off-by: Peter Hurley 
---
 drivers/s390/char/con3215.c  | 12 ++--
 drivers/tty/serial/serial_core.c |  8 
 include/linux/tty.h  | 13 +
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index e7e078b..114fe28 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -289,7 +289,7 @@ static void raw3215_timeout(unsigned long __data)
 
spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
raw->flags &= ~RAW3215_TIMER_RUNS;
-   if (!(raw->port.flags & ASYNC_SUSPENDED)) {
+   if (!tty_port_suspended(>port)) {
raw3215_mk_write_req(raw);
raw3215_start_io(raw);
if ((raw->queued_read || raw->queued_write) &&
@@ -312,7 +312,7 @@ static void raw3215_timeout(unsigned long __data)
 static inline void raw3215_try_io(struct raw3215_info *raw)
 {
if (!(raw->port.flags & ASYNC_INITIALIZED) ||
-   (raw->port.flags & ASYNC_SUSPENDED))
+   tty_port_suspended(>port))
return;
if (raw->queued_read != NULL)
raw3215_start_io(raw);
@@ -494,7 +494,7 @@ static void raw3215_make_room(struct raw3215_info *raw, 
unsigned int length)
/* While console is frozen for suspend we have no other
 * choice but to drop message from the buffer to make
 * room for even more messages. */
-   if (raw->port.flags & ASYNC_SUSPENDED) {
+   if (tty_port_suspended(>port)) {
raw3215_drop_line(raw);
continue;
}
@@ -773,7 +773,7 @@ static int raw3215_pm_stop(struct ccw_device *cdev)
raw = dev_get_drvdata(>dev);
spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
-   raw->port.flags |= ASYNC_SUSPENDED;
+   tty_port_set_suspended(>port, 1);
spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
return 0;
 }
@@ -786,7 +786,7 @@ static int raw3215_pm_start(struct ccw_device *cdev)
/* Allow I/O again and flush output buffer. */
raw = dev_get_drvdata(>dev);
spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
-   raw->port.flags &= ~ASYNC_SUSPENDED;
+   tty_port_set_suspended(>port, 0);
raw->flags |= RAW3215_FLUSHING;
raw3215_try_io(raw);
raw->flags &= ~RAW3215_FLUSHING;
@@ -859,7 +859,7 @@ static void con3215_flush(void)
unsigned long flags;
 
raw = raw3215[0];  /* console 3215 is the first one */
-   if (raw->port.flags & ASYNC_SUSPENDED)
+   if (tty_port_suspended(>port))
/* The console is still frozen for suspend. */
if (ccw_device_force_console(raw->cdev))
/* Forcing didn't work, no panic message .. */
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 2471380..9336067 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -249,7 +249,7 @@ static void uart_shutdown(struct tty_struct *tty, struct 
uart_state *state)
 * a DCD drop (hangup) at just the right time.  Clear suspended bit so
 * we don't try to resume a port that has been shutdown.
 */
-   clear_bit(ASYNCB_SUSPENDED, >flags);
+   tty_port_set_suspended(port, 0);
 
/*
 * Free the transmit buffer page.
@@ -2007,7 +2007,7 @@ int uart_suspend_port(struct uart_driver *drv, struct 
uart_port *uport)
const struct uart_ops *ops = uport->ops;
int tries;
 
-   set_bit(ASYNCB_SUSPENDED, >flags);
+   tty_port_set_suspended(port, 1);
clear_bit(ASYNCB_INITIALIZED, >flags);
 
spin_lock_irq(>lock);
@@ -2088,7 +2088,7 @@ int uart_resume_port(struct uart_driver *drv, struct 
uart_port *uport)
console_start(uport->cons);
}
 
-   if (port->flags & ASYNC_SUSPENDED) {
+   if (tty_port_suspended(port)) {
const struct uart_ops *ops = uport->ops;
int ret;
 
@@ -2118,7 +2118,7 @@ int uart_resume_port(struct uart_driver *drv, struct 
uart_port *uport)
}
}
 
-   clear_bit(ASYNCB_SUSPENDED, >flags);
+   tty_port_set_suspended(port, 0);
}
 
mutex_unlock(>mutex);
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 4254dfb..7ac5add 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -597,6 +597,19 @@ static inline void tty_port_set_check_carrier(struct 
tty_port *port, bool val)

[PATCH 2/8] tty: Replace ASYNC_CTS_FLOW bit and update atomically

2016-04-09 Thread Peter Hurley
Replace ASYNC_CTS_FLOW bit in the tty_port::flags field with
TTY_PORT_CTS_FLOW bit in the tty_port::iflags field. Add
tty_port_set_cts_flow() helper to abstract the atomic bit ops.

Signed-off-by: Peter Hurley 
---
 drivers/char/pcmcia/synclink_cs.c  |  5 +
 drivers/tty/amiserial.c|  6 ++
 drivers/tty/cyclades.c | 10 --
 drivers/tty/isicom.c   |  6 ++
 drivers/tty/mxser.c|  4 +---
 drivers/tty/synclink.c |  7 ++-
 drivers/tty/synclink_gt.c  |  5 +
 drivers/tty/synclinkmp.c   |  5 +
 include/linux/tty.h| 12 ++--
 net/irda/ircomm/ircomm_tty_ioctl.c |  3 +--
 10 files changed, 25 insertions(+), 38 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index bcae5bb..bdf41ac 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1466,10 +1466,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info, 
struct tty_struct *tty)
}
info->timeout += HZ/50; /* Add .02 seconds of slop */
 
-   if (cflag & CRTSCTS)
-   info->port.flags |= ASYNC_CTS_FLOW;
-   else
-   info->port.flags &= ~ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(>port, cflag & CRTSCTS);
 
if (cflag & CLOCAL)
info->port.flags &= ~ASYNC_CHECK_CD;
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index e68208e..92717b0 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -727,11 +727,9 @@ static void change_speed(struct tty_struct *tty, struct 
serial_state *info,
info->IER &= ~UART_IER_MSI;
if (port->flags & ASYNC_HARDPPS_CD)
info->IER |= UART_IER_MSI;
-   if (cflag & CRTSCTS) {
-   port->flags |= ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(port, cflag & CRTSCTS);
+   if (cflag & CRTSCTS)
info->IER |= UART_IER_MSI;
-   } else
-   port->flags &= ~ASYNC_CTS_FLOW;
if (cflag & CLOCAL)
port->flags &= ~ASYNC_CHECK_CD;
else {
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index d67e542..1a12776 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -2083,13 +2083,11 @@ static void cy_set_line_char(struct cyclades_port 
*info, struct tty_struct *tty)
info->cor1 |= CyPARITY_NONE;
 
/* CTS flow control flag */
-   if (cflag & CRTSCTS) {
-   info->port.flags |= ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(>port, cflag & CRTSCTS);
+   if (cflag & CRTSCTS)
info->cor2 |= CyCtsAE;
-   } else {
-   info->port.flags &= ~ASYNC_CTS_FLOW;
+   else
info->cor2 &= ~CyCtsAE;
-   }
if (cflag & CLOCAL)
info->port.flags &= ~ASYNC_CHECK_CD;
else
@@ -2234,7 +2232,7 @@ static void cy_set_line_char(struct cyclades_port *info, 
struct tty_struct *tty)
}
/* As the HW flow control is done in firmware, the driver
   doesn't need to care about it */
-   info->port.flags &= ~ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(>port, 0);
 
/* XON/XOFF/XANY flow control flags */
sw_flow = 0;
diff --git a/drivers/tty/isicom.c b/drivers/tty/isicom.c
index 8bf6763..c5f06b5 100644
--- a/drivers/tty/isicom.c
+++ b/drivers/tty/isicom.c
@@ -765,11 +765,9 @@ static void isicom_config_port(struct tty_struct *tty)
 
/* flow control settings ...*/
flow_ctrl = 0;
-   port->port.flags &= ~ASYNC_CTS_FLOW;
-   if (C_CRTSCTS(tty)) {
-   port->port.flags |= ASYNC_CTS_FLOW;
+   tty_port_set_cts_flow(>port, C_CRTSCTS(tty));
+   if (C_CRTSCTS(tty))
flow_ctrl |= ISICOM_CTSRTS;
-   }
if (I_IXON(tty))
flow_ctrl |= ISICOM_RESPOND_XONXOFF;
if (I_IXOFF(tty))
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index f23c2a1..8f3fdad 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -711,8 +711,8 @@ static int mxser_change_speed(struct tty_struct *tty,
/* CTS flow control flag and modem status interrupts */
info->IER &= ~UART_IER_MSI;
info->MCR &= ~UART_MCR_AFE;
+   tty_port_set_cts_flow(>port, cflag & CRTSCTS);
if (cflag & CRTSCTS) {
-   info->port.flags |= ASYNC_CTS_FLOW;
info->IER |= UART_IER_MSI;
if ((info->type == PORT_16550A) || (info->board->chip_flag)) {
info->MCR |= UART_MCR_AFE;
@@ -744,8 +744,6 @@ static int mxser_change_speed(struct tty_struct *tty,
}
}
}
-   } else {
-   info->port.flags &= 

Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread Andy Lutomirski
On Sat, Apr 9, 2016 at 5:16 PM, Linus Torvalds
 wrote:
> On Sat, Apr 9, 2016 at 5:06 PM, H. Peter Anvin  wrote:
>>
>> Fixing the default permissions is trivial, of course.  The intent from the 
>> beginning was to make a ptmx -> pts/ptmx, but user space never did...
>
> That wasn't my point.
>
> Because the permissions have never been usable, I pretty much
> guarantee that no current user space uses /dev/pts/ptmx.
>
> So that node is almost entirely irrelevant. Us fixing the permissions
> at this point isn't going to make it any more relevant, we might as
> well ignore it.
>
> Which all means that the way forward really is to just make /dev/ptmx
> work. It's not going away, and it _is_ fairly easy to fix.
>
> But I don't think the fix should care about permissions - and we might
> as well leave the existing pts/ptmx node with broken permissions.
> Because we've never been actually interested in looking up
> /dev/pts/ptmx - all we actually care about is to look up which devpts
> instance it is.
>
> And that's not about the ptmx node, that's really about the
> mount-point. So the right thing to do - conceptually - is *literally*
> to just say "ok, what is mounted at 'pts'". Note how at no point do we
> want to _open_ anything.
>
> That's why I said that conceptually we could just open /proc/mounts.
> Because *that* is really the operation we care about. We don't care
> about lookup, and we don't care about permissions on the ptmx node.
> Those are completely and utterly irrelevant to what we're actually
> after.
>
> So I think the permission thing is not just extra code with more
> failure points. I think it's conceptually entirely the wrong thing to
> do, and just confuses people into thinking that we're doing something
> that we aren't.

What we *do* want to do, though, is to prevent the following:

Root (or a container manager or whatever) does:

mknod /foo/ptmx c 5 2
chmod 600 /foo/ptmx
chmod 666 /dev/ptmx
mount -t devpts -o newinstance none /foo/pts

Evil user does:

$ unshare -urm
# mount --bind /dev /mnt/foo
# mount --bind /foo/pts /mnt/foo/pts
# open /mnt/foo/ptmx

The issue is that the evil user has the ability to open /mnt/foo/ptmx
(because it's 666), and the relative path 'pts' points to /foo/pts,
which the evil user should *not* be able to access.  IOW, with a naive
implementation, we can match up the ptmx node with the wrong devpts
instance because the evil user unshared their mount namespace and
screwed around.

I don't immediately see how to fix this without playing permission games.

--Andy


Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread Andy Lutomirski
On Sat, Apr 9, 2016 at 5:16 PM, Linus Torvalds
 wrote:
> On Sat, Apr 9, 2016 at 5:06 PM, H. Peter Anvin  wrote:
>>
>> Fixing the default permissions is trivial, of course.  The intent from the 
>> beginning was to make a ptmx -> pts/ptmx, but user space never did...
>
> That wasn't my point.
>
> Because the permissions have never been usable, I pretty much
> guarantee that no current user space uses /dev/pts/ptmx.
>
> So that node is almost entirely irrelevant. Us fixing the permissions
> at this point isn't going to make it any more relevant, we might as
> well ignore it.
>
> Which all means that the way forward really is to just make /dev/ptmx
> work. It's not going away, and it _is_ fairly easy to fix.
>
> But I don't think the fix should care about permissions - and we might
> as well leave the existing pts/ptmx node with broken permissions.
> Because we've never been actually interested in looking up
> /dev/pts/ptmx - all we actually care about is to look up which devpts
> instance it is.
>
> And that's not about the ptmx node, that's really about the
> mount-point. So the right thing to do - conceptually - is *literally*
> to just say "ok, what is mounted at 'pts'". Note how at no point do we
> want to _open_ anything.
>
> That's why I said that conceptually we could just open /proc/mounts.
> Because *that* is really the operation we care about. We don't care
> about lookup, and we don't care about permissions on the ptmx node.
> Those are completely and utterly irrelevant to what we're actually
> after.
>
> So I think the permission thing is not just extra code with more
> failure points. I think it's conceptually entirely the wrong thing to
> do, and just confuses people into thinking that we're doing something
> that we aren't.

What we *do* want to do, though, is to prevent the following:

Root (or a container manager or whatever) does:

mknod /foo/ptmx c 5 2
chmod 600 /foo/ptmx
chmod 666 /dev/ptmx
mount -t devpts -o newinstance none /foo/pts

Evil user does:

$ unshare -urm
# mount --bind /dev /mnt/foo
# mount --bind /foo/pts /mnt/foo/pts
# open /mnt/foo/ptmx

The issue is that the evil user has the ability to open /mnt/foo/ptmx
(because it's 666), and the relative path 'pts' points to /foo/pts,
which the evil user should *not* be able to access.  IOW, with a naive
implementation, we can match up the ptmx node with the wrong devpts
instance because the evil user unshared their mount namespace and
screwed around.

I don't immediately see how to fix this without playing permission games.

--Andy


Re: [PATCH v2] x86/hpet: Reduce HPET counter read contention

2016-04-09 Thread Thomas Gleixner
On Fri, 8 Apr 2016, Waiman Long wrote:
> This patch attempts to reduce HPET read contention by using the fact
> that if more than one task are trying to access HPET at the same time,
> it will be more efficient if one task in the group reads the HPET
> counter and shares it with the rest of the group instead of each
> group member reads the HPET counter individually.

That has nothing to do with tasks. clocksource reads can happen from almost
any context. The problem is concurrent access on multiple cpus.

> This optimization is enabled on systems with more than 32 CPUs. It can
> also be explicitly enabled or disabled by using the new opt_read_hpet
> kernel parameter.

Please not. What's wrong with enabling it unconditionally?
 
> +/*
>   * Clock source related code
>   */
>  static cycle_t read_hpet(struct clocksource *cs)
>  {
> - return (cycle_t)hpet_readl(HPET_COUNTER);
> + int seq, cnt = 0;
> + u32 time;
> +
> + if (opt_read_hpet <= 0)
> + return (cycle_t)hpet_readl(HPET_COUNTER);

This wants to be conditional on CONFIG_SMP. No point in having all that muck
around for an UP kernel.

> + seq = READ_ONCE(hpet_save.seq);
> + if (!HPET_SEQ_LOCKED(seq)) {
> + int old, new = seq + 1;
> + unsigned long flags;
> +
> + local_irq_save(flags);
> + /*
> +  * Set the lock bit (lsb) to get the right to read HPET
> +  * counter directly. If successful, read the counter, save
> +  * its value, and increment the sequence number. Otherwise,
> +  * increment the sequnce number to the expected locked value
> +  * for comparison later on.
> +  */
> + old = cmpxchg(_save.seq, seq, new);
> + if (old == seq) {
> + time = hpet_readl(HPET_COUNTER);
> + WRITE_ONCE(hpet_save.hpet, time);
> +
> + /* Unlock */
> + smp_store_release(_save.seq, new + 1);
> + local_irq_restore(flags);
> + return (cycle_t)time;
> + }
> + local_irq_restore(flags);
> + seq = new;
> + }
> +
> + /*
> +  * Wait until the locked sequence number changes which indicates
> +  * that the saved HPET value is up-to-date.
> +  */
> + while (READ_ONCE(hpet_save.seq) == seq) {
> + /*
> +  * Since reading the HPET is much slower than a single
> +  * cpu_relax() instruction, we use two here in an attempt
> +  * to reduce the amount of cacheline contention in the
> +  * hpet_save.seq cacheline.
> +  */
> + cpu_relax();
> + cpu_relax();
> +
> + if (likely(++cnt <= HPET_RESET_THRESHOLD))
> + continue;
> +
> + /*
> +  * In the unlikely event that it takes too long for the lock
> +  * holder to read the HPET, we do it ourselves and try to
> +  * reset the lock. This will also break a deadlock if it
> +  * happens, for example, when the process context lock holder
> +  * gets killed in the middle of reading the HPET counter.
> +  */
> + time = hpet_readl(HPET_COUNTER);
> + WRITE_ONCE(hpet_save.hpet, time);
> + if (READ_ONCE(hpet_save.seq) == seq) {
> + if (cmpxchg(_save.seq, seq, seq + 1) == seq)
> + pr_warn("read_hpet: reset hpet seq to 0x%x\n",
> + seq + 1);

This is voodoo programming and actively dangerous.

CPU0CPU1CPU2
lock_hpet()
T1=read_hpet()  wait_for_unlock()   
store_hpet(T1)  

T2 = read_hpet()
unlock_hpet()   
lock_hpet()
T3 = read_hpet()
store_hpet(T3)
unlock_hpet()
return T3
lock_hpet()
T4 = read_hpet()wait_for_unlock()
store_hpet(T4)  
store_hpet(T2)  
unlock_hpet()   return T2

CPU2 will observe time going backwards.

Thanks,

tglx


Re: [PATCH v2] x86/hpet: Reduce HPET counter read contention

2016-04-09 Thread Thomas Gleixner
On Fri, 8 Apr 2016, Waiman Long wrote:
> This patch attempts to reduce HPET read contention by using the fact
> that if more than one task are trying to access HPET at the same time,
> it will be more efficient if one task in the group reads the HPET
> counter and shares it with the rest of the group instead of each
> group member reads the HPET counter individually.

That has nothing to do with tasks. clocksource reads can happen from almost
any context. The problem is concurrent access on multiple cpus.

> This optimization is enabled on systems with more than 32 CPUs. It can
> also be explicitly enabled or disabled by using the new opt_read_hpet
> kernel parameter.

Please not. What's wrong with enabling it unconditionally?
 
> +/*
>   * Clock source related code
>   */
>  static cycle_t read_hpet(struct clocksource *cs)
>  {
> - return (cycle_t)hpet_readl(HPET_COUNTER);
> + int seq, cnt = 0;
> + u32 time;
> +
> + if (opt_read_hpet <= 0)
> + return (cycle_t)hpet_readl(HPET_COUNTER);

This wants to be conditional on CONFIG_SMP. No point in having all that muck
around for an UP kernel.

> + seq = READ_ONCE(hpet_save.seq);
> + if (!HPET_SEQ_LOCKED(seq)) {
> + int old, new = seq + 1;
> + unsigned long flags;
> +
> + local_irq_save(flags);
> + /*
> +  * Set the lock bit (lsb) to get the right to read HPET
> +  * counter directly. If successful, read the counter, save
> +  * its value, and increment the sequence number. Otherwise,
> +  * increment the sequnce number to the expected locked value
> +  * for comparison later on.
> +  */
> + old = cmpxchg(_save.seq, seq, new);
> + if (old == seq) {
> + time = hpet_readl(HPET_COUNTER);
> + WRITE_ONCE(hpet_save.hpet, time);
> +
> + /* Unlock */
> + smp_store_release(_save.seq, new + 1);
> + local_irq_restore(flags);
> + return (cycle_t)time;
> + }
> + local_irq_restore(flags);
> + seq = new;
> + }
> +
> + /*
> +  * Wait until the locked sequence number changes which indicates
> +  * that the saved HPET value is up-to-date.
> +  */
> + while (READ_ONCE(hpet_save.seq) == seq) {
> + /*
> +  * Since reading the HPET is much slower than a single
> +  * cpu_relax() instruction, we use two here in an attempt
> +  * to reduce the amount of cacheline contention in the
> +  * hpet_save.seq cacheline.
> +  */
> + cpu_relax();
> + cpu_relax();
> +
> + if (likely(++cnt <= HPET_RESET_THRESHOLD))
> + continue;
> +
> + /*
> +  * In the unlikely event that it takes too long for the lock
> +  * holder to read the HPET, we do it ourselves and try to
> +  * reset the lock. This will also break a deadlock if it
> +  * happens, for example, when the process context lock holder
> +  * gets killed in the middle of reading the HPET counter.
> +  */
> + time = hpet_readl(HPET_COUNTER);
> + WRITE_ONCE(hpet_save.hpet, time);
> + if (READ_ONCE(hpet_save.seq) == seq) {
> + if (cmpxchg(_save.seq, seq, seq + 1) == seq)
> + pr_warn("read_hpet: reset hpet seq to 0x%x\n",
> + seq + 1);

This is voodoo programming and actively dangerous.

CPU0CPU1CPU2
lock_hpet()
T1=read_hpet()  wait_for_unlock()   
store_hpet(T1)  

T2 = read_hpet()
unlock_hpet()   
lock_hpet()
T3 = read_hpet()
store_hpet(T3)
unlock_hpet()
return T3
lock_hpet()
T4 = read_hpet()wait_for_unlock()
store_hpet(T4)  
store_hpet(T2)  
unlock_hpet()   return T2

CPU2 will observe time going backwards.

Thanks,

tglx


Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread Linus Torvalds
On Sat, Apr 9, 2016 at 5:06 PM, H. Peter Anvin  wrote:
>
> Fixing the default permissions is trivial, of course.  The intent from the 
> beginning was to make a ptmx -> pts/ptmx, but user space never did...

That wasn't my point.

Because the permissions have never been usable, I pretty much
guarantee that no current user space uses /dev/pts/ptmx.

So that node is almost entirely irrelevant. Us fixing the permissions
at this point isn't going to make it any more relevant, we might as
well ignore it.

Which all means that the way forward really is to just make /dev/ptmx
work. It's not going away, and it _is_ fairly easy to fix.

But I don't think the fix should care about permissions - and we might
as well leave the existing pts/ptmx node with broken permissions.
Because we've never been actually interested in looking up
/dev/pts/ptmx - all we actually care about is to look up which devpts
instance it is.

And that's not about the ptmx node, that's really about the
mount-point. So the right thing to do - conceptually - is *literally*
to just say "ok, what is mounted at 'pts'". Note how at no point do we
want to _open_ anything.

That's why I said that conceptually we could just open /proc/mounts.
Because *that* is really the operation we care about. We don't care
about lookup, and we don't care about permissions on the ptmx node.
Those are completely and utterly irrelevant to what we're actually
after.

So I think the permission thing is not just extra code with more
failure points. I think it's conceptually entirely the wrong thing to
do, and just confuses people into thinking that we're doing something
that we aren't.

Linus


Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread Linus Torvalds
On Sat, Apr 9, 2016 at 5:06 PM, H. Peter Anvin  wrote:
>
> Fixing the default permissions is trivial, of course.  The intent from the 
> beginning was to make a ptmx -> pts/ptmx, but user space never did...

That wasn't my point.

Because the permissions have never been usable, I pretty much
guarantee that no current user space uses /dev/pts/ptmx.

So that node is almost entirely irrelevant. Us fixing the permissions
at this point isn't going to make it any more relevant, we might as
well ignore it.

Which all means that the way forward really is to just make /dev/ptmx
work. It's not going away, and it _is_ fairly easy to fix.

But I don't think the fix should care about permissions - and we might
as well leave the existing pts/ptmx node with broken permissions.
Because we've never been actually interested in looking up
/dev/pts/ptmx - all we actually care about is to look up which devpts
instance it is.

And that's not about the ptmx node, that's really about the
mount-point. So the right thing to do - conceptually - is *literally*
to just say "ok, what is mounted at 'pts'". Note how at no point do we
want to _open_ anything.

That's why I said that conceptually we could just open /proc/mounts.
Because *that* is really the operation we care about. We don't care
about lookup, and we don't care about permissions on the ptmx node.
Those are completely and utterly irrelevant to what we're actually
after.

So I think the permission thing is not just extra code with more
failure points. I think it's conceptually entirely the wrong thing to
do, and just confuses people into thinking that we're doing something
that we aren't.

Linus


Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread H. Peter Anvin
On April 9, 2016 5:01:27 PM PDT, Linus Torvalds  
wrote:
>On Sat, Apr 9, 2016 at 3:37 PM, H. Peter Anvin  wrote:
>>
>> On the flipside, if we were to allow ourselves to break userspace, at
>this point I would suggest making /dev/pts/ptmx have a different device
>number and make the legacy /dev/ptmx print a warning message, after
>which it can at least eventually be deleted.
>
>You don't need a different device number.
>
>The /dev/pts/ptmx file may look like it's the same node as /dev/ptmx,
>but it is trivial to recognize as the pts one:
>
> if (dentry->d_sb->s_magic == DEVPTS_SUPER_MAGIC)
>
>and you're done.
>
>But nobody actually uses /dev/pts/ptmx, because it has never had sane
>permissions.
>
>So the fact is, /dev/ptmx is what people use, and we're not breaking
>userspace.
>
>But when we fix bad semantics (and always just looking up the initial
>pts mount really is crazy semantics) that doesn't mean that we have to
>bend over backwards to not make the changed semantics visible. We
>don't _break_ user space, but we also don't care about some random
>test-program that checks for particular semantics.
>
>And I can pretty much _guarantee_ that nobody has ever done the "let's
>bind-mount a 'ptmx' node in a /dev directory, and then expect that to
>bind to some _other_ pts thing than the one in /dev/pts/".
>
>Except as a test-program, or possibly as a "why the f*ck doesn't this
>work? Oh, I need to use the single-instance thing because the
>multi-instance pts thing is broken. Damn shitty implementation".
>
>Linus

Fixing the default permissions is trivial, of course.  The intent from the 
beginning was to make a ptmx -> pts/ptmx, but user space never did...
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.


Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread H. Peter Anvin
On April 9, 2016 5:01:27 PM PDT, Linus Torvalds  
wrote:
>On Sat, Apr 9, 2016 at 3:37 PM, H. Peter Anvin  wrote:
>>
>> On the flipside, if we were to allow ourselves to break userspace, at
>this point I would suggest making /dev/pts/ptmx have a different device
>number and make the legacy /dev/ptmx print a warning message, after
>which it can at least eventually be deleted.
>
>You don't need a different device number.
>
>The /dev/pts/ptmx file may look like it's the same node as /dev/ptmx,
>but it is trivial to recognize as the pts one:
>
> if (dentry->d_sb->s_magic == DEVPTS_SUPER_MAGIC)
>
>and you're done.
>
>But nobody actually uses /dev/pts/ptmx, because it has never had sane
>permissions.
>
>So the fact is, /dev/ptmx is what people use, and we're not breaking
>userspace.
>
>But when we fix bad semantics (and always just looking up the initial
>pts mount really is crazy semantics) that doesn't mean that we have to
>bend over backwards to not make the changed semantics visible. We
>don't _break_ user space, but we also don't care about some random
>test-program that checks for particular semantics.
>
>And I can pretty much _guarantee_ that nobody has ever done the "let's
>bind-mount a 'ptmx' node in a /dev directory, and then expect that to
>bind to some _other_ pts thing than the one in /dev/pts/".
>
>Except as a test-program, or possibly as a "why the f*ck doesn't this
>work? Oh, I need to use the single-instance thing because the
>multi-instance pts thing is broken. Damn shitty implementation".
>
>Linus

Fixing the default permissions is trivial, of course.  The intent from the 
beginning was to make a ptmx -> pts/ptmx, but user space never did...
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.


[PATCH] tty: Replace TTY_THROTTLED bit tests with tty_throttled()

2016-04-09 Thread Peter Hurley
Abstract TTY_THROTTLED bit tests with tty_throttled().

Signed-off-by: Peter Hurley 
---
 drivers/char/pcmcia/synclink_cs.c  | 2 +-
 drivers/mmc/card/sdio_uart.c   | 2 +-
 drivers/net/usb/hso.c  | 2 +-
 drivers/staging/fwserial/fwserial.c| 2 +-
 drivers/staging/speakup/selection.c| 2 +-
 drivers/tty/amiserial.c| 2 +-
 drivers/tty/hvc/hvc_console.c  | 2 +-
 drivers/tty/hvc/hvcs.c | 2 +-
 drivers/tty/hvc/hvsi.c | 2 +-
 drivers/tty/moxa.c | 2 +-
 drivers/tty/nozomi.c   | 2 +-
 drivers/tty/serial/serial_core.c   | 2 +-
 drivers/tty/synclink.c | 2 +-
 drivers/tty/synclink_gt.c  | 2 +-
 drivers/tty/synclinkmp.c   | 2 +-
 drivers/tty/tty_ioctl.c| 4 ++--
 drivers/tty/vt/selection.c | 2 +-
 drivers/usb/gadget/function/u_serial.c | 4 ++--
 drivers/usb/serial/digi_acceleport.c   | 3 +--
 include/linux/tty.h| 5 +
 net/irda/ircomm/ircomm_tty_ioctl.c | 2 +-
 21 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index 825db42..bcae5bb 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2316,7 +2316,7 @@ static void mgslpc_set_termios(struct tty_struct *tty, 
struct ktermios *old_term
/* Handle transition away from B0 status */
if (!(old_termios->c_cflag & CBAUD) && C_BAUD(tty)) {
info->serial_signals |= SerialSignal_DTR;
-   if (!C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, >flags))
+   if (!C_CRTSCTS(tty) || !tty_throttled(tty))
info->serial_signals |= SerialSignal_RTS;
spin_lock_irqsave(>lock, flags);
set_signals(info);
diff --git a/drivers/mmc/card/sdio_uart.c b/drivers/mmc/card/sdio_uart.c
index 5415056..5af6fb9 100644
--- a/drivers/mmc/card/sdio_uart.c
+++ b/drivers/mmc/card/sdio_uart.c
@@ -895,7 +895,7 @@ static void sdio_uart_set_termios(struct tty_struct *tty,
/* Handle transition away from B0 status */
if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
unsigned int mask = TIOCM_DTR;
-   if (!(cflag & CRTSCTS) || !test_bit(TTY_THROTTLED, >flags))
+   if (!(cflag & CRTSCTS) || !tty_throttled(tty))
mask |= TIOCM_RTS;
sdio_uart_set_mctrl(port, mask);
}
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 111d907..4b44586 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -2029,7 +2029,7 @@ static int put_rxbuf_data(struct urb *urb, struct 
hso_serial *serial)
 
tty = tty_port_tty_get(>port);
 
-   if (tty && test_bit(TTY_THROTTLED, >flags)) {
+   if (tty && tty_throttled(tty)) {
tty_kref_put(tty);
return -1;
}
diff --git a/drivers/staging/fwserial/fwserial.c 
b/drivers/staging/fwserial/fwserial.c
index 9b23b5c..1f9389d 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -1305,7 +1305,7 @@ static void fwtty_set_termios(struct tty_struct *tty, 
struct ktermios *old)
if ((baud == 0) && (old->c_cflag & CBAUD)) {
port->mctrl &= ~(TIOCM_DTR | TIOCM_RTS);
} else if ((baud != 0) && !(old->c_cflag & CBAUD)) {
-   if (C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, >flags))
+   if (C_CRTSCTS(tty) || !tty_throttled(tty))
port->mctrl |= TIOCM_DTR | TIOCM_RTS;
else
port->mctrl |= TIOCM_DTR;
diff --git a/drivers/staging/speakup/selection.c 
b/drivers/staging/speakup/selection.c
index 41ef099..0149edc 100644
--- a/drivers/staging/speakup/selection.c
+++ b/drivers/staging/speakup/selection.c
@@ -150,7 +150,7 @@ static void __speakup_paste_selection(struct work_struct 
*work)
add_wait_queue(>paste_wait, );
while (sel_buffer && sel_buffer_lth > pasted) {
set_current_state(TASK_INTERRUPTIBLE);
-   if (test_bit(TTY_THROTTLED, >flags)) {
+   if (tty_throttled(tty)) {
schedule();
continue;
}
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 183e98e..e68208e 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1342,7 +1342,7 @@ static void rs_set_termios(struct tty_struct *tty, struct 
ktermios *old_termios)
/* Handle transition away from B0 status */
if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
info->MCR |= SER_DTR;
-   if (!C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, >flags))
+   if (!C_CRTSCTS(tty) || !tty_throttled(tty))
info->MCR |= SER_RTS;

[PATCH] tty: Replace TTY_THROTTLED bit tests with tty_throttled()

2016-04-09 Thread Peter Hurley
Abstract TTY_THROTTLED bit tests with tty_throttled().

Signed-off-by: Peter Hurley 
---
 drivers/char/pcmcia/synclink_cs.c  | 2 +-
 drivers/mmc/card/sdio_uart.c   | 2 +-
 drivers/net/usb/hso.c  | 2 +-
 drivers/staging/fwserial/fwserial.c| 2 +-
 drivers/staging/speakup/selection.c| 2 +-
 drivers/tty/amiserial.c| 2 +-
 drivers/tty/hvc/hvc_console.c  | 2 +-
 drivers/tty/hvc/hvcs.c | 2 +-
 drivers/tty/hvc/hvsi.c | 2 +-
 drivers/tty/moxa.c | 2 +-
 drivers/tty/nozomi.c   | 2 +-
 drivers/tty/serial/serial_core.c   | 2 +-
 drivers/tty/synclink.c | 2 +-
 drivers/tty/synclink_gt.c  | 2 +-
 drivers/tty/synclinkmp.c   | 2 +-
 drivers/tty/tty_ioctl.c| 4 ++--
 drivers/tty/vt/selection.c | 2 +-
 drivers/usb/gadget/function/u_serial.c | 4 ++--
 drivers/usb/serial/digi_acceleport.c   | 3 +--
 include/linux/tty.h| 5 +
 net/irda/ircomm/ircomm_tty_ioctl.c | 2 +-
 21 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index 825db42..bcae5bb 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2316,7 +2316,7 @@ static void mgslpc_set_termios(struct tty_struct *tty, 
struct ktermios *old_term
/* Handle transition away from B0 status */
if (!(old_termios->c_cflag & CBAUD) && C_BAUD(tty)) {
info->serial_signals |= SerialSignal_DTR;
-   if (!C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, >flags))
+   if (!C_CRTSCTS(tty) || !tty_throttled(tty))
info->serial_signals |= SerialSignal_RTS;
spin_lock_irqsave(>lock, flags);
set_signals(info);
diff --git a/drivers/mmc/card/sdio_uart.c b/drivers/mmc/card/sdio_uart.c
index 5415056..5af6fb9 100644
--- a/drivers/mmc/card/sdio_uart.c
+++ b/drivers/mmc/card/sdio_uart.c
@@ -895,7 +895,7 @@ static void sdio_uart_set_termios(struct tty_struct *tty,
/* Handle transition away from B0 status */
if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
unsigned int mask = TIOCM_DTR;
-   if (!(cflag & CRTSCTS) || !test_bit(TTY_THROTTLED, >flags))
+   if (!(cflag & CRTSCTS) || !tty_throttled(tty))
mask |= TIOCM_RTS;
sdio_uart_set_mctrl(port, mask);
}
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 111d907..4b44586 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -2029,7 +2029,7 @@ static int put_rxbuf_data(struct urb *urb, struct 
hso_serial *serial)
 
tty = tty_port_tty_get(>port);
 
-   if (tty && test_bit(TTY_THROTTLED, >flags)) {
+   if (tty && tty_throttled(tty)) {
tty_kref_put(tty);
return -1;
}
diff --git a/drivers/staging/fwserial/fwserial.c 
b/drivers/staging/fwserial/fwserial.c
index 9b23b5c..1f9389d 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -1305,7 +1305,7 @@ static void fwtty_set_termios(struct tty_struct *tty, 
struct ktermios *old)
if ((baud == 0) && (old->c_cflag & CBAUD)) {
port->mctrl &= ~(TIOCM_DTR | TIOCM_RTS);
} else if ((baud != 0) && !(old->c_cflag & CBAUD)) {
-   if (C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, >flags))
+   if (C_CRTSCTS(tty) || !tty_throttled(tty))
port->mctrl |= TIOCM_DTR | TIOCM_RTS;
else
port->mctrl |= TIOCM_DTR;
diff --git a/drivers/staging/speakup/selection.c 
b/drivers/staging/speakup/selection.c
index 41ef099..0149edc 100644
--- a/drivers/staging/speakup/selection.c
+++ b/drivers/staging/speakup/selection.c
@@ -150,7 +150,7 @@ static void __speakup_paste_selection(struct work_struct 
*work)
add_wait_queue(>paste_wait, );
while (sel_buffer && sel_buffer_lth > pasted) {
set_current_state(TASK_INTERRUPTIBLE);
-   if (test_bit(TTY_THROTTLED, >flags)) {
+   if (tty_throttled(tty)) {
schedule();
continue;
}
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 183e98e..e68208e 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1342,7 +1342,7 @@ static void rs_set_termios(struct tty_struct *tty, struct 
ktermios *old_termios)
/* Handle transition away from B0 status */
if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
info->MCR |= SER_DTR;
-   if (!C_CRTSCTS(tty) || !test_bit(TTY_THROTTLED, >flags))
+   if (!C_CRTSCTS(tty) || !tty_throttled(tty))
info->MCR |= SER_RTS;
local_irq_save(flags);
  

[PATCH] tty: Replace TTY_IO_ERROR bit tests with tty_io_error()

2016-04-09 Thread Peter Hurley
Abstract TTY_IO_ERROR status test treewide with tty_io_error().
NB: tty->flags uses atomic bit ops; replace non-atomic bit test
with test_bit().

Signed-off-by: Peter Hurley 
---

v3: redo of an earlier patch titled "tty: Use test_bit() with tty->flags"
v2: rebase

 arch/ia64/hp/sim/simserial.c   | 2 +-
 drivers/char/pcmcia/synclink_cs.c  | 2 +-
 drivers/isdn/i4l/isdn_tty.c| 6 +++---
 drivers/s390/char/tty3270.c| 4 ++--
 drivers/staging/dgnc/dgnc_tty.c| 2 +-
 drivers/tty/amiserial.c| 6 +++---
 drivers/tty/mxser.c| 7 +++
 drivers/tty/pty.c  | 2 +-
 drivers/tty/serial/crisv10.c   | 5 ++---
 drivers/tty/serial/serial_core.c   | 8 
 drivers/tty/synclink.c | 4 ++--
 drivers/tty/synclink_gt.c  | 4 ++--
 drivers/tty/synclinkmp.c   | 4 ++--
 drivers/tty/tty_io.c   | 5 ++---
 drivers/tty/tty_port.c | 2 +-
 include/linux/tty.h| 5 +
 net/irda/ircomm/ircomm_tty.c   | 2 +-
 net/irda/ircomm/ircomm_tty_ioctl.c | 6 +++---
 18 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/arch/ia64/hp/sim/simserial.c b/arch/ia64/hp/sim/simserial.c
index e70cade..21fd50d 100644
--- a/arch/ia64/hp/sim/simserial.c
+++ b/arch/ia64/hp/sim/simserial.c
@@ -300,7 +300,7 @@ static int rs_ioctl(struct tty_struct *tty, unsigned int 
cmd, unsigned long arg)
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
(cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
(cmd != TIOCMIWAIT)) {
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
}
 
diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index 22c2765..825db42 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2246,7 +2246,7 @@ static int mgslpc_ioctl(struct tty_struct *tty,
 
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
(cmd != TIOCMIWAIT)) {
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
}
 
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 947d5c9..f1edc08 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1351,7 +1351,7 @@ isdn_tty_tiocmget(struct tty_struct *tty)
 
if (isdn_tty_paranoia_check(info, tty->name, __func__))
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
 
mutex_lock(_info_mutex);
@@ -1378,7 +1378,7 @@ isdn_tty_tiocmset(struct tty_struct *tty,
 
if (isdn_tty_paranoia_check(info, tty->name, __func__))
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
 
 #ifdef ISDN_DEBUG_MODEM_IOCTL
@@ -1419,7 +1419,7 @@ isdn_tty_ioctl(struct tty_struct *tty, uint cmd, ulong 
arg)
 
if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl"))
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
switch (cmd) {
case TCSBRK:   /* SVID version: non-zero arg --> no break */
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index e96fc7f..080a987 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -1804,7 +1804,7 @@ static int tty3270_ioctl(struct tty_struct *tty, unsigned 
int cmd,
tp = tty->driver_data;
if (!tp)
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
return kbd_ioctl(tp->kbd, cmd, arg);
 }
@@ -1818,7 +1818,7 @@ static long tty3270_compat_ioctl(struct tty_struct *tty,
tp = tty->driver_data;
if (!tp)
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
return kbd_ioctl(tp->kbd, cmd, (unsigned long)compat_ptr(arg));
 }
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index bcd2bdf..5c22159 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -1255,7 +1255,7 @@ static int dgnc_block_til_ready(struct tty_struct *tty,
if (file->f_flags & O_NONBLOCK)
break;
 
-   if (tty->flags & (1 << TTY_IO_ERROR)) {
+   if (tty_io_error(tty)) {
retval = -EIO;
break;
}
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index eacf4c9..183e98e 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1143,7 +1143,7 @@ static int 

[PATCH] tty: Replace TTY_IO_ERROR bit tests with tty_io_error()

2016-04-09 Thread Peter Hurley
Abstract TTY_IO_ERROR status test treewide with tty_io_error().
NB: tty->flags uses atomic bit ops; replace non-atomic bit test
with test_bit().

Signed-off-by: Peter Hurley 
---

v3: redo of an earlier patch titled "tty: Use test_bit() with tty->flags"
v2: rebase

 arch/ia64/hp/sim/simserial.c   | 2 +-
 drivers/char/pcmcia/synclink_cs.c  | 2 +-
 drivers/isdn/i4l/isdn_tty.c| 6 +++---
 drivers/s390/char/tty3270.c| 4 ++--
 drivers/staging/dgnc/dgnc_tty.c| 2 +-
 drivers/tty/amiserial.c| 6 +++---
 drivers/tty/mxser.c| 7 +++
 drivers/tty/pty.c  | 2 +-
 drivers/tty/serial/crisv10.c   | 5 ++---
 drivers/tty/serial/serial_core.c   | 8 
 drivers/tty/synclink.c | 4 ++--
 drivers/tty/synclink_gt.c  | 4 ++--
 drivers/tty/synclinkmp.c   | 4 ++--
 drivers/tty/tty_io.c   | 5 ++---
 drivers/tty/tty_port.c | 2 +-
 include/linux/tty.h| 5 +
 net/irda/ircomm/ircomm_tty.c   | 2 +-
 net/irda/ircomm/ircomm_tty_ioctl.c | 6 +++---
 18 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/arch/ia64/hp/sim/simserial.c b/arch/ia64/hp/sim/simserial.c
index e70cade..21fd50d 100644
--- a/arch/ia64/hp/sim/simserial.c
+++ b/arch/ia64/hp/sim/simserial.c
@@ -300,7 +300,7 @@ static int rs_ioctl(struct tty_struct *tty, unsigned int 
cmd, unsigned long arg)
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
(cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
(cmd != TIOCMIWAIT)) {
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
}
 
diff --git a/drivers/char/pcmcia/synclink_cs.c 
b/drivers/char/pcmcia/synclink_cs.c
index 22c2765..825db42 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2246,7 +2246,7 @@ static int mgslpc_ioctl(struct tty_struct *tty,
 
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
(cmd != TIOCMIWAIT)) {
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
}
 
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 947d5c9..f1edc08 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1351,7 +1351,7 @@ isdn_tty_tiocmget(struct tty_struct *tty)
 
if (isdn_tty_paranoia_check(info, tty->name, __func__))
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
 
mutex_lock(_info_mutex);
@@ -1378,7 +1378,7 @@ isdn_tty_tiocmset(struct tty_struct *tty,
 
if (isdn_tty_paranoia_check(info, tty->name, __func__))
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
 
 #ifdef ISDN_DEBUG_MODEM_IOCTL
@@ -1419,7 +1419,7 @@ isdn_tty_ioctl(struct tty_struct *tty, uint cmd, ulong 
arg)
 
if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl"))
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
switch (cmd) {
case TCSBRK:   /* SVID version: non-zero arg --> no break */
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index e96fc7f..080a987 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -1804,7 +1804,7 @@ static int tty3270_ioctl(struct tty_struct *tty, unsigned 
int cmd,
tp = tty->driver_data;
if (!tp)
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
return kbd_ioctl(tp->kbd, cmd, arg);
 }
@@ -1818,7 +1818,7 @@ static long tty3270_compat_ioctl(struct tty_struct *tty,
tp = tty->driver_data;
if (!tp)
return -ENODEV;
-   if (tty->flags & (1 << TTY_IO_ERROR))
+   if (tty_io_error(tty))
return -EIO;
return kbd_ioctl(tp->kbd, cmd, (unsigned long)compat_ptr(arg));
 }
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index bcd2bdf..5c22159 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -1255,7 +1255,7 @@ static int dgnc_block_til_ready(struct tty_struct *tty,
if (file->f_flags & O_NONBLOCK)
break;
 
-   if (tty->flags & (1 << TTY_IO_ERROR)) {
+   if (tty_io_error(tty)) {
retval = -EIO;
break;
}
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index eacf4c9..183e98e 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1143,7 +1143,7 @@ static int rs_tiocmget(struct 

Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread Linus Torvalds
On Sat, Apr 9, 2016 at 3:37 PM, H. Peter Anvin  wrote:
>
> On the flipside, if we were to allow ourselves to break userspace, at this 
> point I would suggest making /dev/pts/ptmx have a different device number and 
> make the legacy /dev/ptmx print a warning message, after which it can at 
> least eventually be deleted.

You don't need a different device number.

The /dev/pts/ptmx file may look like it's the same node as /dev/ptmx,
but it is trivial to recognize as the pts one:

 if (dentry->d_sb->s_magic == DEVPTS_SUPER_MAGIC)

and you're done.

But nobody actually uses /dev/pts/ptmx, because it has never had sane
permissions.

So the fact is, /dev/ptmx is what people use, and we're not breaking userspace.

But when we fix bad semantics (and always just looking up the initial
pts mount really is crazy semantics) that doesn't mean that we have to
bend over backwards to not make the changed semantics visible. We
don't _break_ user space, but we also don't care about some random
test-program that checks for particular semantics.

And I can pretty much _guarantee_ that nobody has ever done the "let's
bind-mount a 'ptmx' node in a /dev directory, and then expect that to
bind to some _other_ pts thing than the one in /dev/pts/".

Except as a test-program, or possibly as a "why the f*ck doesn't this
work? Oh, I need to use the single-instance thing because the
multi-instance pts thing is broken. Damn shitty implementation".

Linus


Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread Linus Torvalds
On Sat, Apr 9, 2016 at 3:37 PM, H. Peter Anvin  wrote:
>
> On the flipside, if we were to allow ourselves to break userspace, at this 
> point I would suggest making /dev/pts/ptmx have a different device number and 
> make the legacy /dev/ptmx print a warning message, after which it can at 
> least eventually be deleted.

You don't need a different device number.

The /dev/pts/ptmx file may look like it's the same node as /dev/ptmx,
but it is trivial to recognize as the pts one:

 if (dentry->d_sb->s_magic == DEVPTS_SUPER_MAGIC)

and you're done.

But nobody actually uses /dev/pts/ptmx, because it has never had sane
permissions.

So the fact is, /dev/ptmx is what people use, and we're not breaking userspace.

But when we fix bad semantics (and always just looking up the initial
pts mount really is crazy semantics) that doesn't mean that we have to
bend over backwards to not make the changed semantics visible. We
don't _break_ user space, but we also don't care about some random
test-program that checks for particular semantics.

And I can pretty much _guarantee_ that nobody has ever done the "let's
bind-mount a 'ptmx' node in a /dev directory, and then expect that to
bind to some _other_ pts thing than the one in /dev/pts/".

Except as a test-program, or possibly as a "why the f*ck doesn't this
work? Oh, I need to use the single-instance thing because the
multi-instance pts thing is broken. Damn shitty implementation".

Linus


Re: [PATCH 2/6] ARM: xen: Register with kernel restart handler

2016-04-09 Thread Stefano Stabellini
On Sat, 9 Apr 2016, Stefano Stabellini wrote:
> On Fri, 8 Apr 2016, Guenter Roeck wrote:
> > Register with kernel restart handler instead of setting arm_pm_restart
> > directly.
> > 
> > Select a high priority of 192 to ensure that default restart handlers
> > are replaced if Xen is running.
> > 
> > Signed-off-by: Guenter Roeck 
> 
> Reviewed-by: Stefano Stabellini 

and queued for 4.7


> 
> >  arch/arm/xen/enlighten.c | 13 +++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
> > index 75cd7345c654..76a1d12fd27e 100644
> > --- a/arch/arm/xen/enlighten.c
> > +++ b/arch/arm/xen/enlighten.c
> > @@ -27,6 +27,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -193,14 +194,22 @@ after_register_vcpu_info:
> > put_cpu();
> >  }
> >  
> > -static void xen_restart(enum reboot_mode reboot_mode, const char *cmd)
> > +static int xen_restart(struct notifier_block *nb, unsigned long action,
> > +  void *data)
> >  {
> > struct sched_shutdown r = { .reason = SHUTDOWN_reboot };
> > int rc;
> > rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, );
> > BUG_ON(rc);
> > +
> > +   return NOTIFY_DONE;
> >  }
> >  
> > +static struct notifier_block xen_restart_nb = {
> > +   .notifier_call = xen_restart,
> > +   .priority = 192,
> > +};
> > +
> >  static void xen_power_off(void)
> >  {
> > struct sched_shutdown r = { .reason = SHUTDOWN_poweroff };
> > @@ -370,7 +379,7 @@ static int __init xen_pm_init(void)
> > return -ENODEV;
> >  
> > pm_power_off = xen_power_off;
> > -   arm_pm_restart = xen_restart;
> > +   register_restart_handler(_restart_nb);
> > if (!xen_initial_domain()) {
> > struct timespec64 ts;
> > xen_read_wallclock();
> > -- 
> > 2.5.0
> > 
> 


Re: [PATCH 2/6] ARM: xen: Register with kernel restart handler

2016-04-09 Thread Stefano Stabellini
On Sat, 9 Apr 2016, Stefano Stabellini wrote:
> On Fri, 8 Apr 2016, Guenter Roeck wrote:
> > Register with kernel restart handler instead of setting arm_pm_restart
> > directly.
> > 
> > Select a high priority of 192 to ensure that default restart handlers
> > are replaced if Xen is running.
> > 
> > Signed-off-by: Guenter Roeck 
> 
> Reviewed-by: Stefano Stabellini 

and queued for 4.7


> 
> >  arch/arm/xen/enlighten.c | 13 +++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
> > index 75cd7345c654..76a1d12fd27e 100644
> > --- a/arch/arm/xen/enlighten.c
> > +++ b/arch/arm/xen/enlighten.c
> > @@ -27,6 +27,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -193,14 +194,22 @@ after_register_vcpu_info:
> > put_cpu();
> >  }
> >  
> > -static void xen_restart(enum reboot_mode reboot_mode, const char *cmd)
> > +static int xen_restart(struct notifier_block *nb, unsigned long action,
> > +  void *data)
> >  {
> > struct sched_shutdown r = { .reason = SHUTDOWN_reboot };
> > int rc;
> > rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, );
> > BUG_ON(rc);
> > +
> > +   return NOTIFY_DONE;
> >  }
> >  
> > +static struct notifier_block xen_restart_nb = {
> > +   .notifier_call = xen_restart,
> > +   .priority = 192,
> > +};
> > +
> >  static void xen_power_off(void)
> >  {
> > struct sched_shutdown r = { .reason = SHUTDOWN_poweroff };
> > @@ -370,7 +379,7 @@ static int __init xen_pm_init(void)
> > return -ENODEV;
> >  
> > pm_power_off = xen_power_off;
> > -   arm_pm_restart = xen_restart;
> > +   register_restart_handler(_restart_nb);
> > if (!xen_initial_domain()) {
> > struct timespec64 ts;
> > xen_read_wallclock();
> > -- 
> > 2.5.0
> > 
> 


Re: [PATCH 2/6] ARM: xen: Register with kernel restart handler

2016-04-09 Thread Stefano Stabellini
On Fri, 8 Apr 2016, Guenter Roeck wrote:
> Register with kernel restart handler instead of setting arm_pm_restart
> directly.
> 
> Select a high priority of 192 to ensure that default restart handlers
> are replaced if Xen is running.
> 
> Signed-off-by: Guenter Roeck 

Reviewed-by: Stefano Stabellini 


>  arch/arm/xen/enlighten.c | 13 +++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
> index 75cd7345c654..76a1d12fd27e 100644
> --- a/arch/arm/xen/enlighten.c
> +++ b/arch/arm/xen/enlighten.c
> @@ -27,6 +27,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -193,14 +194,22 @@ after_register_vcpu_info:
>   put_cpu();
>  }
>  
> -static void xen_restart(enum reboot_mode reboot_mode, const char *cmd)
> +static int xen_restart(struct notifier_block *nb, unsigned long action,
> +void *data)
>  {
>   struct sched_shutdown r = { .reason = SHUTDOWN_reboot };
>   int rc;
>   rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, );
>   BUG_ON(rc);
> +
> + return NOTIFY_DONE;
>  }
>  
> +static struct notifier_block xen_restart_nb = {
> + .notifier_call = xen_restart,
> + .priority = 192,
> +};
> +
>  static void xen_power_off(void)
>  {
>   struct sched_shutdown r = { .reason = SHUTDOWN_poweroff };
> @@ -370,7 +379,7 @@ static int __init xen_pm_init(void)
>   return -ENODEV;
>  
>   pm_power_off = xen_power_off;
> - arm_pm_restart = xen_restart;
> + register_restart_handler(_restart_nb);
>   if (!xen_initial_domain()) {
>   struct timespec64 ts;
>   xen_read_wallclock();
> -- 
> 2.5.0
> 


Re: [PATCH 2/6] ARM: xen: Register with kernel restart handler

2016-04-09 Thread Stefano Stabellini
On Fri, 8 Apr 2016, Guenter Roeck wrote:
> Register with kernel restart handler instead of setting arm_pm_restart
> directly.
> 
> Select a high priority of 192 to ensure that default restart handlers
> are replaced if Xen is running.
> 
> Signed-off-by: Guenter Roeck 

Reviewed-by: Stefano Stabellini 


>  arch/arm/xen/enlighten.c | 13 +++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
> index 75cd7345c654..76a1d12fd27e 100644
> --- a/arch/arm/xen/enlighten.c
> +++ b/arch/arm/xen/enlighten.c
> @@ -27,6 +27,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -193,14 +194,22 @@ after_register_vcpu_info:
>   put_cpu();
>  }
>  
> -static void xen_restart(enum reboot_mode reboot_mode, const char *cmd)
> +static int xen_restart(struct notifier_block *nb, unsigned long action,
> +void *data)
>  {
>   struct sched_shutdown r = { .reason = SHUTDOWN_reboot };
>   int rc;
>   rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, );
>   BUG_ON(rc);
> +
> + return NOTIFY_DONE;
>  }
>  
> +static struct notifier_block xen_restart_nb = {
> + .notifier_call = xen_restart,
> + .priority = 192,
> +};
> +
>  static void xen_power_off(void)
>  {
>   struct sched_shutdown r = { .reason = SHUTDOWN_poweroff };
> @@ -370,7 +379,7 @@ static int __init xen_pm_init(void)
>   return -ENODEV;
>  
>   pm_power_off = xen_power_off;
> - arm_pm_restart = xen_restart;
> + register_restart_handler(_restart_nb);
>   if (!xen_initial_domain()) {
>   struct timespec64 ts;
>   xen_read_wallclock();
> -- 
> 2.5.0
> 


Re: [PATCH] x86/vdso: Remove direct HPET access through the vDSO

2016-04-09 Thread Thomas Gleixner
On Thu, 7 Apr 2016, Andy Lutomirski wrote:

> Allowing user code to map the HPET is problematic.  HPET
> implementations are notoriously buggy, and there are probably many
> machines on which even MMIO reads from bogus HPET addresses are
> problematic.
> 
> We have a report that the Dell Precision M2800 with:
> 
> ACPI: HPET 0xC8FE6238 38 (v01 DELL   CBX3  01072009 AMI. 0005)
> 
> is either so slow when accessing the HPET or actually hangs in some
> regard, causing soft lockups to be reported if users do unexpected
> things to the HPET.
> 
> The vclock HPET code has also always been a questionable speedup.
> Accessing an HPET is exceedingly slow (on the order of several
> microseconds), so the added overhead in requiring a syscall to read
> the HPET is a small fraction of the total code of accessing it.
> 
> To avoid future problems, let's just delete the code entirely.
> 
> In the long run, this could actually be a speedup.  Waiman Long as a
> patch to optimize the case where multiple CPUs contend for the HPET,
> but that won't help unless all the accesses are mediated by the
> kernel.
> 
> Cc: Waiman Long 
> Reported-by: Rasmus Villemoes 
> Signed-off-by: Andy Lutomirski 

Reviewed-by: Thomas Gleixner 


Re: [PATCH] x86/vdso: Remove direct HPET access through the vDSO

2016-04-09 Thread Thomas Gleixner
On Thu, 7 Apr 2016, Andy Lutomirski wrote:

> Allowing user code to map the HPET is problematic.  HPET
> implementations are notoriously buggy, and there are probably many
> machines on which even MMIO reads from bogus HPET addresses are
> problematic.
> 
> We have a report that the Dell Precision M2800 with:
> 
> ACPI: HPET 0xC8FE6238 38 (v01 DELL   CBX3  01072009 AMI. 0005)
> 
> is either so slow when accessing the HPET or actually hangs in some
> regard, causing soft lockups to be reported if users do unexpected
> things to the HPET.
> 
> The vclock HPET code has also always been a questionable speedup.
> Accessing an HPET is exceedingly slow (on the order of several
> microseconds), so the added overhead in requiring a syscall to read
> the HPET is a small fraction of the total code of accessing it.
> 
> To avoid future problems, let's just delete the code entirely.
> 
> In the long run, this could actually be a speedup.  Waiman Long as a
> patch to optimize the case where multiple CPUs contend for the HPET,
> but that won't help unless all the accesses are mediated by the
> kernel.
> 
> Cc: Waiman Long 
> Reported-by: Rasmus Villemoes 
> Signed-off-by: Andy Lutomirski 

Reviewed-by: Thomas Gleixner 


Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread H. Peter Anvin
On April 9, 2016 7:45:46 AM PDT, ebied...@xmission.com wrote:
>"H. Peter Anvin"  writes:
>
>> On April 9, 2016 6:09:09 AM PDT, One Thousand Gnomes
> wrote:
>>>
 If anyone has a better idea on how userspace should connect the
>>>master
 pty file descriptor the slave file descriptor, I would be willing
>to
 implement that instead.
>>>
>>>If we are willing to go away from the existing mess of a tty
>interface
>>>inflicted on us by BSD and then mashed up by POSIX then a syscall of
>>>
>>>  int err = ptypair(int fd[2], int perms, int flags);
>>>
>>>[where flags is the O_ ones we usually need to cover (CLOEXEC etc)
>and
>>>maybe even some kind of "private" flag to say don't even expose it
>via
>>>devpts).
>>>
>>>would do remarkably sane things to the majoirty of use cases as it
>>>breaks
>>>the dependence on grantpt and also the historic screwup that pty
>pairs
>>>aren't allocated atomically with both file handles returned as pipe()
>>>does.
>>>
>>>Alan
>>
>> We don't even need to do that if we'd be willing to change the user
>> space interface... if we could rely on the POSIX interface then
>> posix_openpt() could simply open /dev/pts/ptmx and everything would
>> just work.
>
>At a quick skim it does look like userspace uses posix_openpt for the
>most part.  Certainly portable apps that can run on FreeBSD do.
>And just grepping through binaries all of the ones I have checked so
>far
>are calling posix_openpt.
>
>Peter if you or someone could start updating the userspace version of
>posix_openpt to use /dev/pts/ptmx when available over /dev/ptmx in
>parallel to the kernel work to always allow mount of devpts to give
>distinct instances that would be great.
>
>> The trick here is how to make it work in the presence of some
>> extremely bad practices in existing userspace.
>
>Yeah.  I am going to look and see if I can move this controversial bit
>to a separate patch so we can discuss it more conviniently.
>
>Eric

On the flipside, if we were to allow ourselves to break userspace, at this 
point I would suggest making /dev/pts/ptmx have a different device number and 
make the legacy /dev/ptmx print a warning message, after which it can at least 
eventually be deleted.

This might not be a bad idea anyway.
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.


Re: [PATCH 01/13] devpts: Teach /dev/ptmx to find the associated devpts via path lookup

2016-04-09 Thread H. Peter Anvin
On April 9, 2016 7:45:46 AM PDT, ebied...@xmission.com wrote:
>"H. Peter Anvin"  writes:
>
>> On April 9, 2016 6:09:09 AM PDT, One Thousand Gnomes
> wrote:
>>>
 If anyone has a better idea on how userspace should connect the
>>>master
 pty file descriptor the slave file descriptor, I would be willing
>to
 implement that instead.
>>>
>>>If we are willing to go away from the existing mess of a tty
>interface
>>>inflicted on us by BSD and then mashed up by POSIX then a syscall of
>>>
>>>  int err = ptypair(int fd[2], int perms, int flags);
>>>
>>>[where flags is the O_ ones we usually need to cover (CLOEXEC etc)
>and
>>>maybe even some kind of "private" flag to say don't even expose it
>via
>>>devpts).
>>>
>>>would do remarkably sane things to the majoirty of use cases as it
>>>breaks
>>>the dependence on grantpt and also the historic screwup that pty
>pairs
>>>aren't allocated atomically with both file handles returned as pipe()
>>>does.
>>>
>>>Alan
>>
>> We don't even need to do that if we'd be willing to change the user
>> space interface... if we could rely on the POSIX interface then
>> posix_openpt() could simply open /dev/pts/ptmx and everything would
>> just work.
>
>At a quick skim it does look like userspace uses posix_openpt for the
>most part.  Certainly portable apps that can run on FreeBSD do.
>And just grepping through binaries all of the ones I have checked so
>far
>are calling posix_openpt.
>
>Peter if you or someone could start updating the userspace version of
>posix_openpt to use /dev/pts/ptmx when available over /dev/ptmx in
>parallel to the kernel work to always allow mount of devpts to give
>distinct instances that would be great.
>
>> The trick here is how to make it work in the presence of some
>> extremely bad practices in existing userspace.
>
>Yeah.  I am going to look and see if I can move this controversial bit
>to a separate patch so we can discuss it more conviniently.
>
>Eric

On the flipside, if we were to allow ourselves to break userspace, at this 
point I would suggest making /dev/pts/ptmx have a different device number and 
make the legacy /dev/ptmx print a warning message, after which it can at least 
eventually be deleted.

This might not be a bad idea anyway.
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.


Re: [RFC 0/4] NFC: pn533: support for pn532 via I2C

2016-04-09 Thread Samuel Ortiz
Hi Michael,

On Fri, Mar 25, 2016 at 03:46:50PM +0100, Michael Thalmeier wrote:
> Michael Thalmeier (4):
>   NFC: pn533: Send ATR_REQ only if NFC_PROTO_NFC_DEP bit is set in
> poll_protocols
>   NFC: pn533: fix deadlock when socket is closed while processing
> command
>   NFC: pn533: Separate pn533 driver in HW dependant and independant
> parts
>   NFC: pn533: add I2C phy driver
This looks very clean, thanks a lot.
I applied and pushed all 4 patches, after cleaning the checkpatch
warnings. I'd like you to address one comment on patch #4 as a
follow up patch.

Cheers,
Samuel.


Re: [RFC 4/4] NFC: pn533: add I2C phy driver

2016-04-09 Thread Samuel Ortiz
Hi Michael,

On Fri, Mar 25, 2016 at 03:46:54PM +0100, Michael Thalmeier wrote:
> This adds the I2C phy interface for the pn533 driver. This way the driver can
> be used to interact with I2C connected pn532.
> 
> Signed-off-by: Michael Thalmeier 
> ---
>  drivers/nfc/pn533/Kconfig  |  11 ++
>  drivers/nfc/pn533/Makefile |   2 +
>  drivers/nfc/pn533/i2c.c| 277 
> +
>  drivers/nfc/pn533/pn533.c  |  29 +
>  drivers/nfc/pn533/pn533.h  |   2 +
>  5 files changed, 321 insertions(+)
>  create mode 100644 drivers/nfc/pn533/i2c.c
> 
> diff --git a/drivers/nfc/pn533/Kconfig b/drivers/nfc/pn533/Kconfig
> index b5a926e..d94122d 100644
> --- a/drivers/nfc/pn533/Kconfig
> +++ b/drivers/nfc/pn533/Kconfig
> @@ -14,3 +14,14 @@ config NFC_PN533_USB
>  
> If you choose to build a module, it'll be called pn533_usb.
> Say N if unsure.
> +
> +config NFC_PN533_I2C
> + tristate "NFC PN533 device support (I2C)"
> + depends on I2C
> + select NFC_PN533
> + ---help---
> +   This module adds support for the NXP pn533 I2C interface.
> +   Select this if your platform is using the I2C bus.
> +
> +   If you choose to build a module, it'll be called pn533_i2c.
> +   Say N if unsure.
> diff --git a/drivers/nfc/pn533/Makefile b/drivers/nfc/pn533/Makefile
> index 12c6be4..51d24c6 100644
> --- a/drivers/nfc/pn533/Makefile
> +++ b/drivers/nfc/pn533/Makefile
> @@ -2,6 +2,8 @@
>  # Makefile for PN533 NFC driver
>  #
>  pn533_usb-objs  = usb.o
> +pn533_i2c-objs  = i2c.o
>  
>  obj-$(CONFIG_NFC_PN533) += pn533.o
>  obj-$(CONFIG_NFC_PN533_USB) += pn533_usb.o
> +obj-$(CONFIG_NFC_PN533_I2C) += pn533_i2c.o
> diff --git a/drivers/nfc/pn533/i2c.c b/drivers/nfc/pn533/i2c.c
> new file mode 100644
> index 000..35066b30
> --- /dev/null
> +++ b/drivers/nfc/pn533/i2c.c
> @@ -0,0 +1,277 @@
> +/*
> + * Driver for NXP PN533 NFC Chip - I2C transport layer
> + *
> + * Copyright (C) 2011 Instituto Nokia de Tecnologia
> + * Copyright (C) 2012-2013 Tieto Poland
> + * Copyright (C) 2016 HALE electronic
> + *
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, see .
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "pn533.h"
> +
> +#define VERSION "0.1"
> +
> +#define PN533_I2C_DRIVER_NAME "pn533_i2c"
> +
> +struct pn533_i2c_phy {
> + struct i2c_client *i2c_dev;
> + struct pn533 *priv;
> +
> + int hard_fault; /*
> +  * < 0 if hardware error occured (e.g. i2c err)
> +  * and prevents normal operation.
> +  */
> +};
> +
> +static int pn533_i2c_send_ack(struct pn533 *dev, gfp_t flags)
> +{
> + struct pn533_i2c_phy *phy = dev->phy;
> + struct i2c_client *client = phy->i2c_dev;
> + u8 ack[6] = {0x00, 0x00, 0xff, 0x00, 0xff, 0x00};
> + /* spec 6.2.1.3:  Preamble, SoPC (2), ACK Code (2), Postamble */
> + int rc;
> +
> + rc = i2c_master_send(client, ack, 6);
> +
> + return rc;
> +}
> +
> +static int pn533_i2c_send_frame(struct pn533 *dev,
> + struct sk_buff *out)
> +{
> + struct pn533_i2c_phy *phy = dev->phy;
> + struct i2c_client *client = phy->i2c_dev;
> + int rc;
> +
> + if (phy->hard_fault != 0)
> + return phy->hard_fault;
> +
> + if (phy->priv == NULL)
> + phy->priv = dev;
> +
> + print_hex_dump_debug("PN533_i2c TX: ", DUMP_PREFIX_NONE, 16, 1,
> +  out->data, out->len, false);
> +
> + rc = i2c_master_send(client, out->data, out->len);
> +
> + if (rc == -EREMOTEIO) { /* Retry, chip was in power down */
> + usleep_range(6000, 1);
> + rc = i2c_master_send(client, out->data, out->len);
> + }
> +
> + if (rc >= 0) {
> + if (rc != out->len)
> + rc = -EREMOTEIO;
> + else
> + rc = 0;
> + }
> +
> + return rc;
> +}
> +
> +static void pn533_i2c_abort_cmd(struct pn533 *dev, gfp_t flags)
> +{
> + /* An ack will cancel the last issued command */
> + pn533_i2c_send_ack(dev, flags);
> +
> + /* schedule cmd_complete_work to finish current command execution */
> + if (dev->cmd != NULL)
> +

Re: [RFC 0/4] NFC: pn533: support for pn532 via I2C

2016-04-09 Thread Samuel Ortiz
Hi Michael,

On Fri, Mar 25, 2016 at 03:46:50PM +0100, Michael Thalmeier wrote:
> Michael Thalmeier (4):
>   NFC: pn533: Send ATR_REQ only if NFC_PROTO_NFC_DEP bit is set in
> poll_protocols
>   NFC: pn533: fix deadlock when socket is closed while processing
> command
>   NFC: pn533: Separate pn533 driver in HW dependant and independant
> parts
>   NFC: pn533: add I2C phy driver
This looks very clean, thanks a lot.
I applied and pushed all 4 patches, after cleaning the checkpatch
warnings. I'd like you to address one comment on patch #4 as a
follow up patch.

Cheers,
Samuel.


Re: [RFC 4/4] NFC: pn533: add I2C phy driver

2016-04-09 Thread Samuel Ortiz
Hi Michael,

On Fri, Mar 25, 2016 at 03:46:54PM +0100, Michael Thalmeier wrote:
> This adds the I2C phy interface for the pn533 driver. This way the driver can
> be used to interact with I2C connected pn532.
> 
> Signed-off-by: Michael Thalmeier 
> ---
>  drivers/nfc/pn533/Kconfig  |  11 ++
>  drivers/nfc/pn533/Makefile |   2 +
>  drivers/nfc/pn533/i2c.c| 277 
> +
>  drivers/nfc/pn533/pn533.c  |  29 +
>  drivers/nfc/pn533/pn533.h  |   2 +
>  5 files changed, 321 insertions(+)
>  create mode 100644 drivers/nfc/pn533/i2c.c
> 
> diff --git a/drivers/nfc/pn533/Kconfig b/drivers/nfc/pn533/Kconfig
> index b5a926e..d94122d 100644
> --- a/drivers/nfc/pn533/Kconfig
> +++ b/drivers/nfc/pn533/Kconfig
> @@ -14,3 +14,14 @@ config NFC_PN533_USB
>  
> If you choose to build a module, it'll be called pn533_usb.
> Say N if unsure.
> +
> +config NFC_PN533_I2C
> + tristate "NFC PN533 device support (I2C)"
> + depends on I2C
> + select NFC_PN533
> + ---help---
> +   This module adds support for the NXP pn533 I2C interface.
> +   Select this if your platform is using the I2C bus.
> +
> +   If you choose to build a module, it'll be called pn533_i2c.
> +   Say N if unsure.
> diff --git a/drivers/nfc/pn533/Makefile b/drivers/nfc/pn533/Makefile
> index 12c6be4..51d24c6 100644
> --- a/drivers/nfc/pn533/Makefile
> +++ b/drivers/nfc/pn533/Makefile
> @@ -2,6 +2,8 @@
>  # Makefile for PN533 NFC driver
>  #
>  pn533_usb-objs  = usb.o
> +pn533_i2c-objs  = i2c.o
>  
>  obj-$(CONFIG_NFC_PN533) += pn533.o
>  obj-$(CONFIG_NFC_PN533_USB) += pn533_usb.o
> +obj-$(CONFIG_NFC_PN533_I2C) += pn533_i2c.o
> diff --git a/drivers/nfc/pn533/i2c.c b/drivers/nfc/pn533/i2c.c
> new file mode 100644
> index 000..35066b30
> --- /dev/null
> +++ b/drivers/nfc/pn533/i2c.c
> @@ -0,0 +1,277 @@
> +/*
> + * Driver for NXP PN533 NFC Chip - I2C transport layer
> + *
> + * Copyright (C) 2011 Instituto Nokia de Tecnologia
> + * Copyright (C) 2012-2013 Tieto Poland
> + * Copyright (C) 2016 HALE electronic
> + *
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, see .
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "pn533.h"
> +
> +#define VERSION "0.1"
> +
> +#define PN533_I2C_DRIVER_NAME "pn533_i2c"
> +
> +struct pn533_i2c_phy {
> + struct i2c_client *i2c_dev;
> + struct pn533 *priv;
> +
> + int hard_fault; /*
> +  * < 0 if hardware error occured (e.g. i2c err)
> +  * and prevents normal operation.
> +  */
> +};
> +
> +static int pn533_i2c_send_ack(struct pn533 *dev, gfp_t flags)
> +{
> + struct pn533_i2c_phy *phy = dev->phy;
> + struct i2c_client *client = phy->i2c_dev;
> + u8 ack[6] = {0x00, 0x00, 0xff, 0x00, 0xff, 0x00};
> + /* spec 6.2.1.3:  Preamble, SoPC (2), ACK Code (2), Postamble */
> + int rc;
> +
> + rc = i2c_master_send(client, ack, 6);
> +
> + return rc;
> +}
> +
> +static int pn533_i2c_send_frame(struct pn533 *dev,
> + struct sk_buff *out)
> +{
> + struct pn533_i2c_phy *phy = dev->phy;
> + struct i2c_client *client = phy->i2c_dev;
> + int rc;
> +
> + if (phy->hard_fault != 0)
> + return phy->hard_fault;
> +
> + if (phy->priv == NULL)
> + phy->priv = dev;
> +
> + print_hex_dump_debug("PN533_i2c TX: ", DUMP_PREFIX_NONE, 16, 1,
> +  out->data, out->len, false);
> +
> + rc = i2c_master_send(client, out->data, out->len);
> +
> + if (rc == -EREMOTEIO) { /* Retry, chip was in power down */
> + usleep_range(6000, 1);
> + rc = i2c_master_send(client, out->data, out->len);
> + }
> +
> + if (rc >= 0) {
> + if (rc != out->len)
> + rc = -EREMOTEIO;
> + else
> + rc = 0;
> + }
> +
> + return rc;
> +}
> +
> +static void pn533_i2c_abort_cmd(struct pn533 *dev, gfp_t flags)
> +{
> + /* An ack will cancel the last issued command */
> + pn533_i2c_send_ack(dev, flags);
> +
> + /* schedule cmd_complete_work to finish current command execution */
> + if (dev->cmd != NULL)
> + dev->cmd->status = 

[PATCH v2 1/2] lib: lz4: fixed zram with lz4 on big endian machines

2016-04-09 Thread Rui Salvaterra
Based on Sergey's test patch [1], this fixes zram with lz4 compression
on big endian cpus.

Note that the 64-bit preprocessor test is not a cleanup, it's part of
the fix, since those identifiers are bogus (for example, __ppc64__
isn't defined anywhere else in the kernel, which means we'd fall into
the 32-bit definitions on ppc64).

Tested on ppc64 with no regression on x86_64.

[1] http://marc.info/?l=linux-kernel=145994470805853=4

Cc: sta...@vger.kernel.org
Suggested-by: Sergey Senozhatsky 
Signed-off-by: Rui Salvaterra 
---
 lib/lz4/lz4defs.h | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/lib/lz4/lz4defs.h b/lib/lz4/lz4defs.h
index abcecdc..0710a62 100644
--- a/lib/lz4/lz4defs.h
+++ b/lib/lz4/lz4defs.h
@@ -11,8 +11,7 @@
 /*
  * Detects 64 bits mode
  */
-#if (defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) \
-   || defined(__ppc64__) || defined(__LP64__))
+#if defined(CONFIG_64BIT)
 #define LZ4_ARCH64 1
 #else
 #define LZ4_ARCH64 0
@@ -35,6 +34,10 @@ typedef struct _U64_S { u64 v; } U64_S;
 
 #define PUT4(s, d) (A32(d) = A32(s))
 #define PUT8(s, d) (A64(d) = A64(s))
+
+#define LZ4_READ_LITTLEENDIAN_16(d, s, p)  \
+   (d = s - A16(p))
+
 #define LZ4_WRITE_LITTLEENDIAN_16(p, v)\
do {\
A16(p) = v; \
@@ -51,10 +54,13 @@ typedef struct _U64_S { u64 v; } U64_S;
 #define PUT8(s, d) \
put_unaligned(get_unaligned((const u64 *) s), (u64 *) d)
 
-#define LZ4_WRITE_LITTLEENDIAN_16(p, v)\
-   do {\
-   put_unaligned(v, (u16 *)(p)); \
-   p += 2; \
+#define LZ4_READ_LITTLEENDIAN_16(d, s, p)  \
+   (d = s - get_unaligned_le16(p))
+
+#define LZ4_WRITE_LITTLEENDIAN_16(p, v)\
+   do {\
+   put_unaligned_le16(v, (u16 *)(p));  \
+   p += 2; \
} while (0)
 #endif
 
@@ -140,9 +146,6 @@ typedef struct _U64_S { u64 v; } U64_S;
 
 #endif
 
-#define LZ4_READ_LITTLEENDIAN_16(d, s, p) \
-   (d = s - get_unaligned_le16(p))
-
 #define LZ4_WILDCOPY(s, d, e)  \
do {\
LZ4_COPYPACKET(s, d);   \
-- 
2.7.4



[PATCH v2 1/2] lib: lz4: fixed zram with lz4 on big endian machines

2016-04-09 Thread Rui Salvaterra
Based on Sergey's test patch [1], this fixes zram with lz4 compression
on big endian cpus.

Note that the 64-bit preprocessor test is not a cleanup, it's part of
the fix, since those identifiers are bogus (for example, __ppc64__
isn't defined anywhere else in the kernel, which means we'd fall into
the 32-bit definitions on ppc64).

Tested on ppc64 with no regression on x86_64.

[1] http://marc.info/?l=linux-kernel=145994470805853=4

Cc: sta...@vger.kernel.org
Suggested-by: Sergey Senozhatsky 
Signed-off-by: Rui Salvaterra 
---
 lib/lz4/lz4defs.h | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/lib/lz4/lz4defs.h b/lib/lz4/lz4defs.h
index abcecdc..0710a62 100644
--- a/lib/lz4/lz4defs.h
+++ b/lib/lz4/lz4defs.h
@@ -11,8 +11,7 @@
 /*
  * Detects 64 bits mode
  */
-#if (defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) \
-   || defined(__ppc64__) || defined(__LP64__))
+#if defined(CONFIG_64BIT)
 #define LZ4_ARCH64 1
 #else
 #define LZ4_ARCH64 0
@@ -35,6 +34,10 @@ typedef struct _U64_S { u64 v; } U64_S;
 
 #define PUT4(s, d) (A32(d) = A32(s))
 #define PUT8(s, d) (A64(d) = A64(s))
+
+#define LZ4_READ_LITTLEENDIAN_16(d, s, p)  \
+   (d = s - A16(p))
+
 #define LZ4_WRITE_LITTLEENDIAN_16(p, v)\
do {\
A16(p) = v; \
@@ -51,10 +54,13 @@ typedef struct _U64_S { u64 v; } U64_S;
 #define PUT8(s, d) \
put_unaligned(get_unaligned((const u64 *) s), (u64 *) d)
 
-#define LZ4_WRITE_LITTLEENDIAN_16(p, v)\
-   do {\
-   put_unaligned(v, (u16 *)(p)); \
-   p += 2; \
+#define LZ4_READ_LITTLEENDIAN_16(d, s, p)  \
+   (d = s - get_unaligned_le16(p))
+
+#define LZ4_WRITE_LITTLEENDIAN_16(p, v)\
+   do {\
+   put_unaligned_le16(v, (u16 *)(p));  \
+   p += 2; \
} while (0)
 #endif
 
@@ -140,9 +146,6 @@ typedef struct _U64_S { u64 v; } U64_S;
 
 #endif
 
-#define LZ4_READ_LITTLEENDIAN_16(d, s, p) \
-   (d = s - get_unaligned_le16(p))
-
 #define LZ4_WILDCOPY(s, d, e)  \
do {\
LZ4_COPYPACKET(s, d);   \
-- 
2.7.4



[PATCH v2 2/2] lib: lz4: cleanup unaligned access efficiency detection

2016-04-09 Thread Rui Salvaterra
These identifiers are bogus. The interested architectures should define
HAVE_EFFICIENT_UNALIGNED_ACCESS whenever relevant to do so. If this
isn't true for some arch, it should be fixed in the arch definition.

Signed-off-by: Rui Salvaterra 
---
 lib/lz4/lz4defs.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/lz4/lz4defs.h b/lib/lz4/lz4defs.h
index 0710a62..c79d7ea 100644
--- a/lib/lz4/lz4defs.h
+++ b/lib/lz4/lz4defs.h
@@ -24,9 +24,7 @@
 typedef struct _U16_S { u16 v; } U16_S;
 typedef struct _U32_S { u32 v; } U32_S;
 typedef struct _U64_S { u64 v; } U64_S;
-#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)\
-   || defined(CONFIG_ARM) && __LINUX_ARM_ARCH__ >= 6   \
-   && defined(ARM_EFFICIENT_UNALIGNED_ACCESS)
+#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
 
 #define A16(x) (((U16_S *)(x))->v)
 #define A32(x) (((U32_S *)(x))->v)
-- 
2.7.4



[PATCH v2 0/2] lib: lz4: fix for big endian and cleanup

2016-04-09 Thread Rui Salvaterra
v2:
 - Addressed GregKH's review and comments.


Hi,

The first patch fixes zram with lz4 compression on ppc64 (and big endian
architectures with efficient unaligned access), the second is just a
cleanup.

Thanks,

Rui


Rui Salvaterra (2):
  lib: lz4: fixed zram with lz4 on big endian machines
  lib: lz4: cleanup unaligned access efficiency detection

 lib/lz4/lz4defs.h | 25 +
 1 file changed, 13 insertions(+), 12 deletions(-)

-- 
2.7.4



[PATCH v2 2/2] lib: lz4: cleanup unaligned access efficiency detection

2016-04-09 Thread Rui Salvaterra
These identifiers are bogus. The interested architectures should define
HAVE_EFFICIENT_UNALIGNED_ACCESS whenever relevant to do so. If this
isn't true for some arch, it should be fixed in the arch definition.

Signed-off-by: Rui Salvaterra 
---
 lib/lz4/lz4defs.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/lz4/lz4defs.h b/lib/lz4/lz4defs.h
index 0710a62..c79d7ea 100644
--- a/lib/lz4/lz4defs.h
+++ b/lib/lz4/lz4defs.h
@@ -24,9 +24,7 @@
 typedef struct _U16_S { u16 v; } U16_S;
 typedef struct _U32_S { u32 v; } U32_S;
 typedef struct _U64_S { u64 v; } U64_S;
-#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)\
-   || defined(CONFIG_ARM) && __LINUX_ARM_ARCH__ >= 6   \
-   && defined(ARM_EFFICIENT_UNALIGNED_ACCESS)
+#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
 
 #define A16(x) (((U16_S *)(x))->v)
 #define A32(x) (((U32_S *)(x))->v)
-- 
2.7.4



[PATCH v2 0/2] lib: lz4: fix for big endian and cleanup

2016-04-09 Thread Rui Salvaterra
v2:
 - Addressed GregKH's review and comments.


Hi,

The first patch fixes zram with lz4 compression on ppc64 (and big endian
architectures with efficient unaligned access), the second is just a
cleanup.

Thanks,

Rui


Rui Salvaterra (2):
  lib: lz4: fixed zram with lz4 on big endian machines
  lib: lz4: cleanup unaligned access efficiency detection

 lib/lz4/lz4defs.h | 25 +
 1 file changed, 13 insertions(+), 12 deletions(-)

-- 
2.7.4



[PATCH 6/6] cifs: don't bother with kmap on read_pages side

2016-04-09 Thread Al Viro
just do ITER_BVEC recvmsg

Signed-off-by: Al Viro 
---
 fs/cifs/cifsproto.h |  7 +++---
 fs/cifs/connect.c   | 65 -
 fs/cifs/file.c  | 53 ++-
 3 files changed, 55 insertions(+), 70 deletions(-)

diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 7d5f53a..0f9a6bc 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -179,10 +179,9 @@ extern int set_cifs_acl(struct cifs_ntsd *, __u32, struct 
inode *,
 
 extern void dequeue_mid(struct mid_q_entry *mid, bool malformed);
 extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
-unsigned int to_read);
-extern int cifs_readv_from_socket(struct TCP_Server_Info *server,
-   struct kvec *iov_orig, unsigned int nr_segs,
-   unsigned int to_read);
+unsigned int to_read);
+extern int cifs_read_page_from_socket(struct TCP_Server_Info *server,
+ struct page *page, unsigned int to_read);
 extern void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
   struct cifs_sb_info *cifs_sb);
 extern int cifs_match_super(struct super_block *, void *);
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index eb42665..e33c5e0 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -501,39 +501,34 @@ server_unresponsive(struct TCP_Server_Info *server)
return false;
 }
 
-int
-cifs_readv_from_socket(struct TCP_Server_Info *server, struct kvec *iov_orig,
-  unsigned int nr_segs, unsigned int to_read)
+static int
+cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg)
 {
int length = 0;
int total_read;
-   struct msghdr smb_msg;
 
-   smb_msg.msg_control = NULL;
-   smb_msg.msg_controllen = 0;
-   iov_iter_kvec(_msg.msg_iter, READ | ITER_KVEC,
- iov_orig, nr_segs, to_read);
+   smb_msg->msg_control = NULL;
+   smb_msg->msg_controllen = 0;
 
-   for (total_read = 0; msg_data_left(_msg); total_read += length) {
+   for (total_read = 0; msg_data_left(smb_msg); total_read += length) {
try_to_freeze();
 
-   if (server_unresponsive(server)) {
-   total_read = -ECONNABORTED;
-   break;
-   }
+   if (server_unresponsive(server))
+   return -ECONNABORTED;
 
-   length = sock_recvmsg(server->ssocket, _msg, 0);
+   length = sock_recvmsg(server->ssocket, smb_msg, 0);
 
-   if (server->tcpStatus == CifsExiting) {
-   total_read = -ESHUTDOWN;
-   break;
-   } else if (server->tcpStatus == CifsNeedReconnect) {
+   if (server->tcpStatus == CifsExiting)
+   return -ESHUTDOWN;
+
+   if (server->tcpStatus == CifsNeedReconnect) {
cifs_reconnect(server);
-   total_read = -ECONNABORTED;
-   break;
-   } else if (length == -ERESTARTSYS ||
-  length == -EAGAIN ||
-  length == -EINTR) {
+   return -ECONNABORTED;
+   }
+
+   if (length == -ERESTARTSYS ||
+   length == -EAGAIN ||
+   length == -EINTR) {
/*
 * Minimum sleep to prevent looping, allowing socket
 * to clear and app threads to set tcpStatus
@@ -542,11 +537,12 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, 
struct kvec *iov_orig,
usleep_range(1000, 2000);
length = 0;
continue;
-   } else if (length <= 0) {
+   }
+
+   if (length <= 0) {
cifs_dbg(FYI, "Received no data or error: %d\n", 
length);
cifs_reconnect(server);
-   total_read = -ECONNABORTED;
-   break;
+   return -ECONNABORTED;
}
}
return total_read;
@@ -556,12 +552,21 @@ int
 cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
  unsigned int to_read)
 {
-   struct kvec iov;
+   struct msghdr smb_msg;
+   struct kvec iov = {.iov_base = buf, .iov_len = to_read};
+   iov_iter_kvec(_msg.msg_iter, READ | ITER_KVEC, , 1, to_read);
 
-   iov.iov_base = buf;
-   iov.iov_len = to_read;
+   return cifs_readv_from_socket(server, _msg);
+}
 
-   return cifs_readv_from_socket(server, , 1, to_read);
+int
+cifs_read_page_from_socket(struct TCP_Server_Info *server, struct page *page,
+ unsigned int to_read)
+{
+   struct msghdr smb_msg;
+   

[PATCH 5/6] cifs_readv_receive: use cifs_read_from_socket()

2016-04-09 Thread Al Viro
Signed-off-by: Al Viro 
---
 fs/cifs/cifssmb.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 76fcb50..3da077a 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -1447,10 +1447,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, 
struct mid_q_entry *mid)
len = min_t(unsigned int, buflen, server->vals->read_rsp_size) -
HEADER_SIZE(server) + 1;
 
-   rdata->iov.iov_base = buf + HEADER_SIZE(server) - 1;
-   rdata->iov.iov_len = len;
-
-   length = cifs_readv_from_socket(server, >iov, 1, len);
+   length = cifs_read_from_socket(server,
+  buf + HEADER_SIZE(server) - 1, len);
if (length < 0)
return length;
server->total_read += length;
@@ -1502,9 +1500,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct 
mid_q_entry *mid)
len = data_offset - server->total_read;
if (len > 0) {
/* read any junk before data into the rest of smallbuf */
-   rdata->iov.iov_base = buf + server->total_read;
-   rdata->iov.iov_len = len;
-   length = cifs_readv_from_socket(server, >iov, 1, len);
+   length = cifs_read_from_socket(server,
+  buf + server->total_read, len);
if (length < 0)
return length;
server->total_read += length;
-- 
2.8.0.rc3



[PATCH 5/6] cifs_readv_receive: use cifs_read_from_socket()

2016-04-09 Thread Al Viro
Signed-off-by: Al Viro 
---
 fs/cifs/cifssmb.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 76fcb50..3da077a 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -1447,10 +1447,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, 
struct mid_q_entry *mid)
len = min_t(unsigned int, buflen, server->vals->read_rsp_size) -
HEADER_SIZE(server) + 1;
 
-   rdata->iov.iov_base = buf + HEADER_SIZE(server) - 1;
-   rdata->iov.iov_len = len;
-
-   length = cifs_readv_from_socket(server, >iov, 1, len);
+   length = cifs_read_from_socket(server,
+  buf + HEADER_SIZE(server) - 1, len);
if (length < 0)
return length;
server->total_read += length;
@@ -1502,9 +1500,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct 
mid_q_entry *mid)
len = data_offset - server->total_read;
if (len > 0) {
/* read any junk before data into the rest of smallbuf */
-   rdata->iov.iov_base = buf + server->total_read;
-   rdata->iov.iov_len = len;
-   length = cifs_readv_from_socket(server, >iov, 1, len);
+   length = cifs_read_from_socket(server,
+  buf + server->total_read, len);
if (length < 0)
return length;
server->total_read += length;
-- 
2.8.0.rc3



[PATCH 6/6] cifs: don't bother with kmap on read_pages side

2016-04-09 Thread Al Viro
just do ITER_BVEC recvmsg

Signed-off-by: Al Viro 
---
 fs/cifs/cifsproto.h |  7 +++---
 fs/cifs/connect.c   | 65 -
 fs/cifs/file.c  | 53 ++-
 3 files changed, 55 insertions(+), 70 deletions(-)

diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 7d5f53a..0f9a6bc 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -179,10 +179,9 @@ extern int set_cifs_acl(struct cifs_ntsd *, __u32, struct 
inode *,
 
 extern void dequeue_mid(struct mid_q_entry *mid, bool malformed);
 extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
-unsigned int to_read);
-extern int cifs_readv_from_socket(struct TCP_Server_Info *server,
-   struct kvec *iov_orig, unsigned int nr_segs,
-   unsigned int to_read);
+unsigned int to_read);
+extern int cifs_read_page_from_socket(struct TCP_Server_Info *server,
+ struct page *page, unsigned int to_read);
 extern void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
   struct cifs_sb_info *cifs_sb);
 extern int cifs_match_super(struct super_block *, void *);
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index eb42665..e33c5e0 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -501,39 +501,34 @@ server_unresponsive(struct TCP_Server_Info *server)
return false;
 }
 
-int
-cifs_readv_from_socket(struct TCP_Server_Info *server, struct kvec *iov_orig,
-  unsigned int nr_segs, unsigned int to_read)
+static int
+cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg)
 {
int length = 0;
int total_read;
-   struct msghdr smb_msg;
 
-   smb_msg.msg_control = NULL;
-   smb_msg.msg_controllen = 0;
-   iov_iter_kvec(_msg.msg_iter, READ | ITER_KVEC,
- iov_orig, nr_segs, to_read);
+   smb_msg->msg_control = NULL;
+   smb_msg->msg_controllen = 0;
 
-   for (total_read = 0; msg_data_left(_msg); total_read += length) {
+   for (total_read = 0; msg_data_left(smb_msg); total_read += length) {
try_to_freeze();
 
-   if (server_unresponsive(server)) {
-   total_read = -ECONNABORTED;
-   break;
-   }
+   if (server_unresponsive(server))
+   return -ECONNABORTED;
 
-   length = sock_recvmsg(server->ssocket, _msg, 0);
+   length = sock_recvmsg(server->ssocket, smb_msg, 0);
 
-   if (server->tcpStatus == CifsExiting) {
-   total_read = -ESHUTDOWN;
-   break;
-   } else if (server->tcpStatus == CifsNeedReconnect) {
+   if (server->tcpStatus == CifsExiting)
+   return -ESHUTDOWN;
+
+   if (server->tcpStatus == CifsNeedReconnect) {
cifs_reconnect(server);
-   total_read = -ECONNABORTED;
-   break;
-   } else if (length == -ERESTARTSYS ||
-  length == -EAGAIN ||
-  length == -EINTR) {
+   return -ECONNABORTED;
+   }
+
+   if (length == -ERESTARTSYS ||
+   length == -EAGAIN ||
+   length == -EINTR) {
/*
 * Minimum sleep to prevent looping, allowing socket
 * to clear and app threads to set tcpStatus
@@ -542,11 +537,12 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, 
struct kvec *iov_orig,
usleep_range(1000, 2000);
length = 0;
continue;
-   } else if (length <= 0) {
+   }
+
+   if (length <= 0) {
cifs_dbg(FYI, "Received no data or error: %d\n", 
length);
cifs_reconnect(server);
-   total_read = -ECONNABORTED;
-   break;
+   return -ECONNABORTED;
}
}
return total_read;
@@ -556,12 +552,21 @@ int
 cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
  unsigned int to_read)
 {
-   struct kvec iov;
+   struct msghdr smb_msg;
+   struct kvec iov = {.iov_base = buf, .iov_len = to_read};
+   iov_iter_kvec(_msg.msg_iter, READ | ITER_KVEC, , 1, to_read);
 
-   iov.iov_base = buf;
-   iov.iov_len = to_read;
+   return cifs_readv_from_socket(server, _msg);
+}
 
-   return cifs_readv_from_socket(server, , 1, to_read);
+int
+cifs_read_page_from_socket(struct TCP_Server_Info *server, struct page *page,
+ unsigned int to_read)
+{
+   struct msghdr smb_msg;
+   struct bio_vec bv = 

[PATCH 3/6] cifs: quit playing games with draining iovecs

2016-04-09 Thread Al Viro
... and use ITER_BVEC for the page part of request to send

Signed-off-by: Al Viro 
---
 fs/cifs/cifsproto.h |   2 -
 fs/cifs/transport.c | 141 +++-
 2 files changed, 41 insertions(+), 102 deletions(-)

diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index d9b4f44..7d5f53a 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -37,8 +37,6 @@ extern void cifs_buf_release(void *);
 extern struct smb_hdr *cifs_small_buf_get(void);
 extern void cifs_small_buf_release(void *);
 extern void free_rsp_buf(int, void *);
-extern void cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx,
-   struct kvec *iov);
 extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *,
unsigned int /* length */);
 extern unsigned int _get_xid(void);
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index 87abe8e..206a597 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -124,41 +124,32 @@ cifs_delete_mid(struct mid_q_entry *mid)
 /*
  * smb_send_kvec - send an array of kvecs to the server
  * @server:Server to send the data to
- * @iov:   Pointer to array of kvecs
- * @n_vec: length of kvec array
+ * @smb_msg:   Message to send
  * @sent:  amount of data sent on socket is stored here
  *
  * Our basic "send data to server" function. Should be called with srv_mutex
  * held. The caller is responsible for handling the results.
  */
 static int
-smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec,
-   size_t *sent)
+smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg,
+ size_t *sent)
 {
int rc = 0;
-   int i = 0;
-   struct msghdr smb_msg;
-   unsigned int remaining;
-   size_t first_vec = 0;
+   int retries = 0;
struct socket *ssocket = server->ssocket;
 
*sent = 0;
 
-   smb_msg.msg_name = (struct sockaddr *) >dstaddr;
-   smb_msg.msg_namelen = sizeof(struct sockaddr);
-   smb_msg.msg_control = NULL;
-   smb_msg.msg_controllen = 0;
+   smb_msg->msg_name = (struct sockaddr *) >dstaddr;
+   smb_msg->msg_namelen = sizeof(struct sockaddr);
+   smb_msg->msg_control = NULL;
+   smb_msg->msg_controllen = 0;
if (server->noblocksnd)
-   smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL;
+   smb_msg->msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL;
else
-   smb_msg.msg_flags = MSG_NOSIGNAL;
-
-   remaining = 0;
-   for (i = 0; i < n_vec; i++)
-   remaining += iov[i].iov_len;
+   smb_msg->msg_flags = MSG_NOSIGNAL;
 
-   i = 0;
-   while (remaining) {
+   while (msg_data_left(smb_msg)) {
/*
 * If blocking send, we try 3 times, since each can block
 * for 5 seconds. For nonblocking  we have to try more
@@ -177,35 +168,21 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec 
*iov, size_t n_vec,
 * after the retries we will kill the socket and
 * reconnect which may clear the network problem.
 */
-   rc = kernel_sendmsg(ssocket, _msg, [first_vec],
-   n_vec - first_vec, remaining);
+   rc = sock_sendmsg(ssocket, smb_msg);
if (rc == -EAGAIN) {
-   i++;
-   if (i >= 14 || (!server->noblocksnd && (i > 2))) {
+   retries++;
+   if (retries >= 14 ||
+   (!server->noblocksnd && (retries > 2))) {
cifs_dbg(VFS, "sends on sock %p stuck for 15 
seconds\n",
 ssocket);
-   rc = -EAGAIN;
-   break;
+   return -EAGAIN;
}
-   msleep(1 << i);
+   msleep(1 << retries);
continue;
}
 
if (rc < 0)
-   break;
-
-   /* send was at least partially successful */
-   *sent += rc;
-
-   if (rc == remaining) {
-   remaining = 0;
-   break;
-   }
-
-   if (rc > remaining) {
-   cifs_dbg(VFS, "sent %d requested %d\n", rc, remaining);
-   break;
-   }
+   return rc;
 
if (rc == 0) {
/* should never happen, letting socket clear before
@@ -215,59 +192,11 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec 
*iov, size_t n_vec,
continue;
}
 
-   remaining -= rc;
-
-   /* the line below resets i */
-   for (i = 

[PATCH 4/6] cifs: no need to wank with copying and advancing iovec on recvmsg side either

2016-04-09 Thread Al Viro
Signed-off-by: Al Viro 
---
 fs/cifs/cifsglob.h |  2 --
 fs/cifs/connect.c  | 72 --
 2 files changed, 5 insertions(+), 69 deletions(-)

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index d21da9f..df03c5e 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -615,8 +615,6 @@ struct TCP_Server_Info {
boolsec_mskerberos; /* supports legacy MS Kerberos */
boollarge_buf;  /* is current buffer large? */
struct delayed_work echo; /* echo ping workqueue job */
-   struct kvec *iov;   /* reusable kvec array for receives */
-   unsigned int nr_iov;/* number of kvecs in array */
char*smallbuf;  /* pointer to current "small" buffer */
char*bigbuf;/* pointer to current "big" buffer */
unsigned int total_read; /* total amount of data read in this pass */
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index a763cd3..eb42665 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -501,77 +501,20 @@ server_unresponsive(struct TCP_Server_Info *server)
return false;
 }
 
-/*
- * kvec_array_init - clone a kvec array, and advance into it
- * @new:   pointer to memory for cloned array
- * @iov:   pointer to original array
- * @nr_segs:   number of members in original array
- * @bytes: number of bytes to advance into the cloned array
- *
- * This function will copy the array provided in iov to a section of memory
- * and advance the specified number of bytes into the new array. It returns
- * the number of segments in the new array. "new" must be at least as big as
- * the original iov array.
- */
-static unsigned int
-kvec_array_init(struct kvec *new, struct kvec *iov, unsigned int nr_segs,
-   size_t bytes)
-{
-   size_t base = 0;
-
-   while (bytes || !iov->iov_len) {
-   int copy = min(bytes, iov->iov_len);
-
-   bytes -= copy;
-   base += copy;
-   if (iov->iov_len == base) {
-   iov++;
-   nr_segs--;
-   base = 0;
-   }
-   }
-   memcpy(new, iov, sizeof(*iov) * nr_segs);
-   new->iov_base += base;
-   new->iov_len -= base;
-   return nr_segs;
-}
-
-static struct kvec *
-get_server_iovec(struct TCP_Server_Info *server, unsigned int nr_segs)
-{
-   struct kvec *new_iov;
-
-   if (server->iov && nr_segs <= server->nr_iov)
-   return server->iov;
-
-   /* not big enough -- allocate a new one and release the old */
-   new_iov = kmalloc(sizeof(*new_iov) * nr_segs, GFP_NOFS);
-   if (new_iov) {
-   kfree(server->iov);
-   server->iov = new_iov;
-   server->nr_iov = nr_segs;
-   }
-   return new_iov;
-}
-
 int
 cifs_readv_from_socket(struct TCP_Server_Info *server, struct kvec *iov_orig,
   unsigned int nr_segs, unsigned int to_read)
 {
int length = 0;
int total_read;
-   unsigned int segs;
struct msghdr smb_msg;
-   struct kvec *iov;
-
-   iov = get_server_iovec(server, nr_segs);
-   if (!iov)
-   return -ENOMEM;
 
smb_msg.msg_control = NULL;
smb_msg.msg_controllen = 0;
+   iov_iter_kvec(_msg.msg_iter, READ | ITER_KVEC,
+ iov_orig, nr_segs, to_read);
 
-   for (total_read = 0; to_read; total_read += length, to_read -= length) {
+   for (total_read = 0; msg_data_left(_msg); total_read += length) {
try_to_freeze();
 
if (server_unresponsive(server)) {
@@ -579,10 +522,7 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, 
struct kvec *iov_orig,
break;
}
 
-   segs = kvec_array_init(iov, iov_orig, nr_segs, total_read);
-
-   length = kernel_recvmsg(server->ssocket, _msg,
-   iov, segs, to_read, 0);
+   length = sock_recvmsg(server->ssocket, _msg, 0);
 
if (server->tcpStatus == CifsExiting) {
total_read = -ESHUTDOWN;
@@ -603,8 +543,7 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, 
struct kvec *iov_orig,
length = 0;
continue;
} else if (length <= 0) {
-   cifs_dbg(FYI, "Received no data or error: expecting 
%d\n"
-"got %d", to_read, length);
+   cifs_dbg(FYI, "Received no data or error: %d\n", 
length);
cifs_reconnect(server);
total_read = -ECONNABORTED;
break;
@@ -783,7 +722,6 @@ static void clean_demultiplex_info(struct TCP_Server_Info 
*server)
}
 
kfree(server->hostname);
-   kfree(server->iov);
kfree(server);
 

  1   2   3   >