Re: [linux-sunxi] [PATCH v3 -next 2/2] ARM: dts: sunxi: add support for Orange Pi Zero board

2016-12-04 Thread Alexey Kardashevskiy
On 03/12/16 03:41, Chen-Yu Tsai wrote:
> Hi,
> 
> On Fri, Dec 2, 2016 at 11:05 PM, Icenowy Zheng  wrote:
>> Orange Pi Zero is a board that came with the new Allwinner H2+ SoC and a
>> SDIO Wi-Fi chip by Allwinner (XR819).
>>
>> Add a device tree file for it.
>>
>> Signed-off-by: Icenowy Zheng 
>> ---
>> Changes since v2:
>> - Merged SDIO Wi-Fi patch into it.
>> - SDIO Wi-Fi: add a ethernet1 alias to it, as it has no internal NVRAM.
>> - SDIO Wi-Fi: changed pinctrl binding to generic pinconf
>> - removed all gpio pinctrl nodes
>> - changed h2plus to h2-plus
>> Changes since v1:
>> - Convert to generic pinconf bindings.
>> - SDIO Wi-Fi: add patch.
>>
>> Some notes:
>> - The uart1 and uart2 is available on the unsoldered gpio header.
>> - The onboard USB connector has its Vbus directly connected to DCIN-5V (the
>>   power jack)
>>
>>  arch/arm/boot/dts/Makefile|   1 +
>>  arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts | 159 
>> ++
>>  2 files changed, 160 insertions(+)
>>  create mode 100644 arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts
>>
>> diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
>> index 6447abc..59f6e86 100644
>> --- a/arch/arm/boot/dts/Makefile
>> +++ b/arch/arm/boot/dts/Makefile
>> @@ -844,6 +844,7 @@ dtb-$(CONFIG_MACH_SUN8I) += \
>> sun8i-a33-sinlinx-sina33.dtb \
>> sun8i-a83t-allwinner-h8homlet-v2.dtb \
>> sun8i-a83t-cubietruck-plus.dtb \
>> +   sun8i-h2-plus-orangepi-zero.dtb \
>> sun8i-h3-bananapi-m2-plus.dtb \
>> sun8i-h3-nanopi-neo.dtb \
>> sun8i-h3-orangepi-2.dtb \
>> diff --git a/arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts 
>> b/arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts
>> new file mode 100644
>> index 000..d18807f
>> --- /dev/null
>> +++ b/arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dts
>> @@ -0,0 +1,159 @@
>> +/*
>> + * Copyright (C) 2016 Icenowy Zheng 
>> + *
>> + * Based on sun8i-h3-orangepi-one.dts, which is:
>> + *   Copyright (C) 2016 Hans de Goede 
>> + *
>> + * This file is dual-licensed: you can use it either under the terms
>> + * of the GPL or the X11 license, at your option. Note that this dual
>> + * licensing only applies to this file, and not this project as a
>> + * whole.
>> + *
>> + *  a) This file 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 file 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.
>> + *
>> + * Or, alternatively,
>> + *
>> + *  b) Permission is hereby granted, free of charge, to any person
>> + * obtaining a copy of this software and associated documentation
>> + * files (the "Software"), to deal in the Software without
>> + * restriction, including without limitation the rights to use,
>> + * copy, modify, merge, publish, distribute, sublicense, and/or
>> + * sell copies of the Software, and to permit persons to whom the
>> + * Software is furnished to do so, subject to the following
>> + * conditions:
>> + *
>> + * The above copyright notice and this permission notice shall be
>> + * included in all copies or substantial portions of the Software.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
>> + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
>> + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
>> + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
>> + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
>> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
>> + * OTHER DEALINGS IN THE SOFTWARE.
>> + */
>> +
>> +/dts-v1/;
>> +#include "sun8i-h3.dtsi"
>> +#include "sunxi-common-regulators.dtsi"
>> +
>> +#include 
>> +#include 
>> +#include 
>> +
>> +/ {
>> +   model = "Xunlong Orange Pi Zero";
>> +   compatible = "xunlong,orangepi-zero", "allwinner,sun8i-h2-plus";
>> +
>> +   aliases {
>> +   serial0 = &uart0;
>> +   /* ethernet0 is the H3 emac, defined in sun8i-h3.dtsi */
>> +   ethernet1 = &xr819;
>> +   };
>> +
>> +   chosen {
>> +   stdout-path = "serial0:115200n8";
>> +   };
>> +
>> +   leds {
>> +   compatible = "gpio-leds";
>> +
>> +   pwr_led {
>> +   label = "orangepi:green:pwr";
>> +   gpios = <&r_pio 0 10 GPIO_ACTIVE_HIGH>;
>> +   default-state = "on";
>> +   };
>> +

make[2]: *** No rule to make target 'arch/sh/boot/dts/.dtb.o', needed by 'arch/sh/boot/dts/built-in.o'.

2016-12-04 Thread kbuild test robot
Hi Rich,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   0cb65c83304a341b9d09678448d7c8b550689531
commit: 190fe191cfbead9fe089453dd092869c9469c6d4 sh: add support for linking a 
builtin device tree blob in the kernel
date:   4 months ago
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout 190fe191cfbead9fe089453dd092869c9469c6d4
# save the attached .config to linux build tree
make.cross ARCH=sh 

All errors (new ones prefixed by >>):

>> make[2]: *** No rule to make target 'arch/sh/boot/dts/.dtb.o', needed by 
>> 'arch/sh/boot/dts/built-in.o'.
   make[2]: Target '__build' not remade because of errors.

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH] trace: extend trace_clock to support arch_arm clock counter

2016-12-04 Thread Srinivas Ramana

On 12/02/2016 04:38 PM, Will Deacon wrote:

On Fri, Dec 02, 2016 at 01:44:55PM +0530, Srinivas Ramana wrote:

Extend the trace_clock to support the arch timer cycle
counter so that we can get the monotonic cycle count
in the traces. This will help in correlating the traces with the
timestamps/events in other subsystems in the soc which share
this common counter for driving their timers.


I'm not sure I follow this reasoning. What's wrong with nanoseconds? In
particular, the "perf" trace_clock hangs off sched_clock, which should
be backed by the architected counter anyway. What does the cycle counter in
isolation tell you, given that the frequency isn't architected?

I think I'm missing something here.

Will



Having cycle counter would help in the cases where we want to correlate 
the time with other subsystems which are outside cpu subsystem. 
local_clock or even the perf track_clock uses sched_clock which gets 
suspended during system suspend. Yes, they are backed up by the 
architected counter but they ignore the cycles spent in suspend. so, 
when comparing with monotonically increasing cycle counter, other clocks 
doesn't help. It seems X86 uses the TSC counter to help such cases.


Thanks,
-- Srinivas R

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, 
Inc.,

is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.


[PATCH 1/1] net: bnx2x: fix improper return value

2016-12-04 Thread Pan Bian
From: Pan Bian 

Marco BNX2X_ALLOC_AND_SET(arr, lbl, func) calls kmalloc() to allocate
memory, and jumps to label "lbl" if the allocation fails. Label "lbl"
first cleans memory and then returns variable rc. Before calling the
macro, the value of variable rc is 0. Because 0 means no error, the
callers of bnx2x_init_firmware() may be misled. This patch fixes the bug,
assigning "-ENOMEM" to rc before calling macro NX2X_ALLOC_AND_SET().

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189141

Signed-off-by: Pan Bian 
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 0cee4c0..6f9fc20 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13505,6 +13505,7 @@ static int bnx2x_init_firmware(struct bnx2x *bp)
 
/* Initialize the pointers to the init arrays */
/* Blob */
+   rc = -ENOMEM;
BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
 
/* Opcodes */
-- 
1.9.1




[PATCH] perf/core: remove invalid warning from list_update_cgroup_event

2016-12-04 Thread David Carrillo-Cisneros
The warning introduced in commit:

979bfef8607c ("perf/core: Do not set cpuctx->cgrp for unscheduled cgroups")

assumed that a cgroup switch always precedes list_del_event. This is not
the case. Remove warning.

Make sure that cpuctx->cgrp is NULL until a cgroup event is sched in or
ctx->nr_cgroups == 0.

Signed-off-by: David Carrillo-Cisneros 
---
 kernel/events/core.c | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 6ee1feb..02c8421 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -903,17 +903,14 @@ list_update_cgroup_event(struct perf_event *event,
 */
cpuctx = __get_cpu_context(ctx);
 
-   /* Only set/clear cpuctx->cgrp if current task uses event->cgrp. */
-   if (perf_cgroup_from_task(current, ctx) != event->cgrp) {
-   /*
-* We are removing the last cpu event in this context.
-* If that event is not active in this cpu, cpuctx->cgrp
-* should've been cleared by perf_cgroup_switch.
-*/
-   WARN_ON_ONCE(!add && cpuctx->cgrp);
-   return;
-   }
-   cpuctx->cgrp = add ? event->cgrp : NULL;
+   /*
+* cpuctx->cgrp is NULL until a cgroup event is sched in or
+* ctx->nr_cgroup == 0 .
+*/
+   if (add && perf_cgroup_from_task(current, ctx) == event->cgrp)
+   cpuctx->cgrp = event->cgrp;
+   else if (!add)
+   cpuctx->cgrp = NULL;
 }
 
 #else /* !CONFIG_CGROUP_PERF */
-- 
2.8.0.rc3.226.g39d4020



Re: [PATCH] Input: mouse: synaptics - change msleep to usleep_range for small msecs

2016-12-04 Thread Igor Grinberg
Hi Aniroop Mathur,

On 11/29/16 23:02, Aniroop Mathur wrote:
> Dear Mike Rapoport, Igor Grinberg,
> Greetings!
> 
> I am Aniroop Mathur from Samsung R&D Institute, India.
> 
> I have submitted one patch as below for review to Linux Open Source.
> The problem is that we do not have the hardware available with us to
> test it and we would like to test it before actually applying it.
> As you are the author of this driver, I am contacting you to request you
> provide your feedback upon this patch.
> 
> Also if you have the hardware available, could you please help to
> test this patch on your hardware? or could you provide contact points
> of individuals who could support to test it?

This touchpad and the driver was used on an old PXA270 based PDA.
I currently don't have those at hand to test the patch.

> 
> Thank you!
> 
> BR,
> Aniroop Mathur
> 
> On Tue, Nov 29, 2016 at 1:25 AM, Aniroop Mathur  wrote:
>> msleep(1~20) may not do what the caller intends, and will often sleep longer.
>> (~20 ms actual sleep for any value given in the 1~20ms range)

Well, it should be at least 1ms as stated in my comment just before the define.
So, from the correctness perspective larger values will also do the job.
Additionally, since I've taken a spare 2ms, and you are making it even more
precise (3000us + 100us) - it will still do the job and stay correct.
So, there should be no issue from correctness POV.

>> This is not the desired behaviour for many cases like device resume time,
>> device suspend time, device enable time, retry logic, etc.
>> Thus, change msleep to usleep_range for precise wakeups.

This is a human interface touchpad device, even having 20ms soft reset
sleep time will not impact the responsiveness for humans.
IMHO, there is no need for precise wakeups for this device, so I wouldn't
bother.

>>
>> Signed-off-by: Aniroop Mathur 
>> ---
>>  drivers/input/mouse/synaptics_i2c.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/input/mouse/synaptics_i2c.c 
>> b/drivers/input/mouse/synaptics_i2c.c
>> index aa7c5da..4d688a6 100644
>> --- a/drivers/input/mouse/synaptics_i2c.c
>> +++ b/drivers/input/mouse/synaptics_i2c.c
>> @@ -29,7 +29,7 @@
>>   * after soft reset, we should wait for 1 ms
>>   * before the device becomes operational
>>   */
>> -#define SOFT_RESET_DELAY_MS3
>> +#define SOFT_RESET_DELAY_US3000
>>  /* and after hard reset, we should wait for max 500ms */
>>  #define HARD_RESET_DELAY_MS500
>>
>> @@ -311,7 +311,7 @@ static int synaptics_i2c_reset_config(struct i2c_client 
>> *client)
>> if (ret) {
>> dev_err(&client->dev, "Unable to reset device\n");
>> } else {
>> -   msleep(SOFT_RESET_DELAY_MS);
>> +   usleep_range(SOFT_RESET_DELAY_US, SOFT_RESET_DELAY_US + 100);
>> ret = synaptics_i2c_config(client);
>> if (ret)
>> dev_err(&client->dev, "Unable to config device\n");
>> --
>> 2.6.2
>>
> 

-- 
Regards,
Igor.


[PATCH] Staging: ks7010: ks7010_stio.h: fixed coding style error

2016-12-04 Thread Manoj Sawai
Fixed 2 coding style errors about trailing whitespaces.

Signed-off-by: Manoj Sawai 
---
 drivers/staging/ks7010/ks7010_sdio.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/ks7010/ks7010_sdio.h 
b/drivers/staging/ks7010/ks7010_sdio.h
index 0a0951a6..0f5fd848e23d 100644
--- a/drivers/staging/ks7010/ks7010_sdio.h
+++ b/drivers/staging/ks7010/ks7010_sdio.h
@@ -1,5 +1,5 @@
 /*
- *   Driver for KeyStream, KS7010 based SDIO cards. 
+ *   Driver for KeyStream, KS7010 based SDIO cards.
  *
  *   Copyright (C) 2006-2008 KeyStream Corp.
  *   Copyright (C) 2009 Renesas Technology Corp.
@@ -41,7 +41,7 @@
 /* Write Index Register */
 #define WRITE_INDEX0x10
 
-/* Write Status/Read Data Size Register 
+/* Write Status/Read Data Size Register
  * for network packet (less than 2048 bytes data)
  */
 #define WSTATUS_RSIZE  0x14
-- 
2.11.0



[PATCH 2/2] Staging: ks7010: eap_packet.h: fixed coding style issue

2016-12-04 Thread Manoj Sawai
Rearranged comments so that lines are less than 80 characters long

Signed-off-by: Manoj Sawai 
---
 drivers/staging/ks7010/eap_packet.h | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/ks7010/eap_packet.h 
b/drivers/staging/ks7010/eap_packet.h
index df7f760e4110..45d30b8ed0b1 100644
--- a/drivers/staging/ks7010/eap_packet.h
+++ b/drivers/staging/ks7010/eap_packet.h
@@ -58,12 +58,15 @@ struct ieee802_1x_eapol_key {
 * encrypt the Key field; 64-bit NTP timestamp MAY be used here
 */
unsigned char replay_counter[IEEE8021X_REPLAY_COUNTER_LEN];
-   unsigned char key_iv[IEEE8021X_KEY_IV_LEN]; /* cryptographically 
random number */
+
+   /* cryptographically random number */
+   unsigned char key_iv[IEEE8021X_KEY_IV_LEN];
unsigned char key_index;/*
 * key flag in the most significant bit:
 * 0 = broadcast (default key),
-* 1 = unicast (key mapping key); key 
index is in the
-* 7 least significant bits
+* 1 = unicast (key mapping key);
+* key index is in the 7 least
+* significant bits
 */
/*
 * HMAC-MD5 message integrity check computed with MS-MPPE-Send-Key as
-- 
2.11.0



Re: [PATCH 1/1] edac: fix improper return value

2016-12-04 Thread Borislav Petkov
On Sun, Dec 04, 2016 at 02:07:18PM +0800, Pan Bian wrote:
> From: Pan Bian 
> 
> When the call to zalloc_cpumask_var() fails, returning "false" seems
> improper. The real value of macro "false" is 0, and 0 means no error.
> This patch fixes the bug, returning "-ENOMEM".
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189071

That bugzilla entry wasn't really needed.

> Signed-off-by: Pan Bian 
> ---
>  drivers/edac/amd64_edac.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied,
thanks.

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.


Re: [PATCH 1/1] isdn: hisax: set error code on failure

2016-12-04 Thread Sergei Shtylyov

Hello.

On 12/4/2016 8:15 AM, Pan Bian wrote:


From: Pan Bian 

In function hfc4s8s_probe(), the value of return variable err should be
negative on failures. However, when the call to request_region() returns
NULL, the value of err is 0. This patch fixes the bug, assiging
"-ENOMEM" to err on the path that request_region() fails.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188931

Signed-off-by: Pan Bian 
---
 drivers/isdn/hisax/hfc4s8s_l1.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index 9600cd7..3172cee 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -1499,6 +1499,7 @@ struct hfc4s8s_l1 {
printk(KERN_INFO
   "HFC-4S/8S: failed to request address space at 0x%04x\n",
   hw->iobase);
+   err = -ENOMEM;


   -EBUSY fits request_region() better.

[..]

MBR, Sergei



Re: alpha: Checking for a failed kmalloc() in process_reloc_for_got()?

2016-12-04 Thread SF Markus Elfring
>> https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/arch/alpha/kernel/module.c?id=e05f574a0bb1f4502a4b2264fdb0ef6419cf3772#n40
>>
>> Would it be useful to check the return value from a call of the
>> function “kmalloc” also there?
> 
> *drumroll* it'd actually be a proper bugfix.

Which kind of exception handling can be added here when the function
“process_reloc_for_got” has got the return type “void” so far?

Will it be needed to handle such a software failure at more source code places
by a special error code?

Regards,
Markus


Re: [PATCH 1/1] net: bnx2x: fix improper return value

2016-12-04 Thread Sergei Shtylyov

On 12/4/2016 11:39 AM, Pan Bian wrote:


From: Pan Bian 

Marco BNX2X_ALLOC_AND_SET(arr, lbl, func) calls kmalloc() to allocate


   Macro.


memory, and jumps to label "lbl" if the allocation fails. Label "lbl"
first cleans memory and then returns variable rc. Before calling the
macro, the value of variable rc is 0. Because 0 means no error, the
callers of bnx2x_init_firmware() may be misled. This patch fixes the bug,
assigning "-ENOMEM" to rc before calling macro NX2X_ALLOC_AND_SET().

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189141

Signed-off-by: Pan Bian 

[...]

MBR, Sergei



Re: [PATCH] zram: restrict add/remove attributes to root only

2016-12-04 Thread Greg KH
On Sun, Dec 04, 2016 at 11:35:15AM +0900, Sergey Senozhatsky wrote:
> Only root must be able to create a new zram device, therefore
> hot_add attribute must have S_IRUSR mode, not S_IRUGO. Otherwise,
> anyone can create a new zram device (device initialization with
> the disksize attr requires root permission).
> 
> Fixes: 6566d1a32bf72 ("zram: add dynamic device add/remove functionality")
> Reported-by: Steven Allen 
> Cc: [4.2+]
> Signed-off-by: Sergey Senozhatsky 
> ---
>  drivers/block/zram/zram_drv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 5163c8f..ee03464 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -1414,8 +1414,8 @@ static ssize_t hot_remove_store(struct class *class,
>  }
>  
>  static struct class_attribute zram_control_class_attrs[] = {
> - __ATTR_RO(hot_add),
> - __ATTR_WO(hot_remove),
> + __ATTR(hot_add, 0400, hot_add_show, NULL),
> + __ATTR(hot_remove, 0200, NULL, hot_remove_store),

Huh?  The only change you are making here is that a "normal" user can
not read the value, ATTR_WO only allows root to write to the file.

This change doesn't match up with your changelog, what really is the
problem here with the _RO and _WO values that you can not use them?

Why can't a normal user read the attribute?  Does a read actually modify
something?  If so, that's really not a good idea.

confused,

greg k-h


[PATCH 1/1] isdn: hisax: set error code on failure

2016-12-04 Thread Pan Bian
From: Pan Bian 

In function hfc4s8s_probe(), the value of return variable err should be
negative on failures. However, when the call to request_region() returns
NULL, the value of err is 0. This patch fixes the bug, assiging
"-EBUSY" to err on the path that request_region() fails.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188931

Signed-off-by: Pan Bian 
---
 drivers/isdn/hisax/hfc4s8s_l1.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index 9600cd7..3172cee 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -1499,6 +1499,7 @@ struct hfc4s8s_l1 {
printk(KERN_INFO
   "HFC-4S/8S: failed to request address space at 0x%04x\n",
   hw->iobase);
+   err = -EBUSY;
goto out;
}
 
-- 
1.9.1




Re: [PATCH 1/1] isdn: hisax: set error code on failure

2016-12-04 Thread Sergei Shtylyov

On 12/4/2016 1:33 PM, Pan Bian wrote:

  You now need to indicate the patch version in hte subject, like this:

[PATCH 1/1 v2] isdn:...


From: Pan Bian 

In function hfc4s8s_probe(), the value of return variable err should be
negative on failures. However, when the call to request_region() returns
NULL, the value of err is 0. This patch fixes the bug, assiging


   Assigning.


"-EBUSY" to err on the path that request_region() fails.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188931

Signed-off-by: Pan Bian 
---


   And here you're supposed to describe changes in the different patch 
versions...


[...]

MBR, Sergei



[PATCH 1/1] net: bnx2x: fix improper return value

2016-12-04 Thread Pan Bian
From: Pan Bian 

Macro BNX2X_ALLOC_AND_SET(arr, lbl, func) calls kmalloc() to allocate
memory, and jumps to label "lbl" if the allocation fails. Label "lbl"
first cleans memory and then returns variable rc. Before calling the
macro, the value of variable rc is 0. Because 0 means no error, the
callers of bnx2x_init_firmware() may be misled. This patch fixes the bug,
assigning "-ENOMEM" to rc before calling macro NX2X_ALLOC_AND_SET().

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189141

Signed-off-by: Pan Bian 
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 0cee4c0..6f9fc20 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13505,6 +13505,7 @@ static int bnx2x_init_firmware(struct bnx2x *bp)
 
/* Initialize the pointers to the init arrays */
/* Blob */
+   rc = -ENOMEM;
BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
 
/* Opcodes */
-- 
1.9.1




Re: [SPCR] mmio32 iotype access requirements for X-Gene 8250(_dw) UART

2016-12-04 Thread Duc Dang
On Sat, Dec 3, 2016 at 12:33 PM, Jon Masters  wrote:
> Hi Mark,
>
> On 12/03/2016 12:15 PM, Mark Salter wrote:
>> On Sat, 2016-12-03 at 05:06 -0500, Jon Masters wrote:
>
>>> There is a broader problem with X-Gene SPCR support. The problem is
>>> that the 16550 UART in X-Gene requires the 32-bit access quirk (the
>>> iotype is set to UPIO_MEM32 for the APMC0D08 device). This means
>>> that when univ8250_console_match runs later, it will compare the
>>> iotype (MEM32) with the type previously registered with the
>>> kernel when the earlycon setup the preferred console.
>>
>> Linaro has a kernel patch which looks at the bit_width field of the
>> port address:
>>
>> Author: Aleksey Makarov 
>> Date:   Thu Apr 28 19:52:38 2016 +0300
>>
>> serial: SPCR: check bit width for the 16550 UART
>>
>> The SPCR in 3.06.25 firmware has a bit_width field set to 32 and with the
>> above patch, I don't need to use console=. But HP firmware on m400 sets
>> bit width to 8 so that needs a firmware fix to work with above.

Will this patch be posted for upstream?

>
> Indeed, thanks. Graeme also mentioned that last night. I think this
> a good solution for the moment, but still that it makes sense to
> have a new 16650 UART type defined in the DBG2 spec for those
> requiring 32-bit access (to mirror the type D for pl011). I
> heard back from Microsoft this morning that they're looking.

Yes, thanks, Jon. It will be nice to have a new 16550 UART type for
those requiring 32-bit access.

>
> Jon.
>
> --
> Computer Architect | Sent from my Fedora powered laptop
>
Regards,
Duc Dang.


Re: Linux 4.9-rc6

2016-12-04 Thread Thorsten Leemhuis
Lo! On 21.11.2016 14:51, Eric Dumazet wrote:
> On Mon, 2016-11-21 at 05:32 -0800, Eric Dumazet wrote:
>> Oh, this was definitely my intent of course, thanks for noticing this
>> typo ;)
> V2 is fixing this, and brings back NUMA spreading,
> (eg alloc_large_system_hash() done at boot time )

What the status of below patch? From the discussion it looks a lot like
it was developed to fix a regression in 4.9, but the patch afaics has
neither his mainline or linux-next yet. That's why I'm inclined to add
it to this weeks regression report.

Ciao, Thorsten

> lpaa24:~# grep alloc_large /proc/vmallocinfo 
> 0xc9009000-0xc900c000   12288 
> alloc_large_system_hash+0x178/0x238 pages=2 vmalloc N0=1 N1=1
> 0xc900c000-0xc900f000   12288 
> alloc_large_system_hash+0x178/0x238 pages=2 vmalloc N0=1 N1=1
> 0xc901e000-0xc909f000  528384 
> alloc_large_system_hash+0x178/0x238 pages=128 vmalloc N0=64 N1=64
> 0xc909f000-0xc90e  266240 
> alloc_large_system_hash+0x178/0x238 pages=64 vmalloc N0=32 N1=32
> 0xc91d3000-0xc900101d4000 268439552 
> alloc_large_system_hash+0x178/0x238 pages=65536 vmalloc vpages N0=32768 
> N1=32768
> 0xc900101d4000-0xc900181d5000 134221824 
> alloc_large_system_hash+0x178/0x238 pages=32768 vmalloc vpages N0=16384 
> N1=16384
> 0xc900181d5000-0xc900185d6000 4198400 
> alloc_large_system_hash+0x178/0x238 pages=1024 vmalloc vpages N0=512 N1=512
> 0xc900185d6000-0xc900189d7000 4198400 
> alloc_large_system_hash+0x178/0x238 pages=1024 vmalloc vpages N0=512 N1=512
> 0xc9001b271000-0xc9001b672000 4198400 
> alloc_large_system_hash+0x178/0x238 pages=1024 vmalloc vpages N0=512 N1=512
> 0xc9001b672000-0xc9001b675000   12288 
> alloc_large_system_hash+0x178/0x238 pages=2 vmalloc N0=1 N1=1
> 0xc9001b675000-0xc9001b776000 1052672 
> alloc_large_system_hash+0x178/0x238 pages=256 vmalloc N0=128 N1=128
> 0xc9001b776000-0xc9001b977000 2101248 
> alloc_large_system_hash+0x178/0x238 pages=512 vmalloc N0=256 N1=256
> 0xc9001b977000-0xc9001bb78000 2101248 
> alloc_large_system_hash+0x178/0x238 pages=512 vmalloc N0=256 N1=256
> 0xc9001c075000-0xc9001c176000 1052672 
> alloc_large_system_hash+0x178/0x238 pages=256 vmalloc N0=128 N1=128
> 
> 
>  mm/vmalloc.c |   47 +++
>  1 file changed, 39 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index f2481cb4e6b2..f4b9c9238f86 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -21,6 +21,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -1602,9 +1603,11 @@ static void *__vmalloc_area_node(struct vm_struct 
> *area, gfp_t gfp_mask,
>pgprot_t prot, int node)
>  {
>   struct page **pages;
> - unsigned int nr_pages, array_size, i;
> + unsigned int nr_pages, array_size, i, j;
>   const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO;
>   const gfp_t alloc_mask = gfp_mask | __GFP_NOWARN;
> + const gfp_t multi_alloc_mask = (alloc_mask & ~__GFP_DIRECT_RECLAIM) | 
> __GFP_NORETRY;
> + int max_node_order = MAX_ORDER - 1;
>  
>   nr_pages = get_vm_area_size(area) >> PAGE_SHIFT;
>   array_size = (nr_pages * sizeof(struct page *));
> @@ -1624,20 +1627,48 @@ static void *__vmalloc_area_node(struct vm_struct 
> *area, gfp_t gfp_mask,
>   return NULL;
>   }
>  
> - for (i = 0; i < area->nr_pages; i++) {
> - struct page *page;
> + if (IS_ENABLED(CONFIG_NUMA) && nr_online_nodes > 1) {
> + struct mempolicy *policy = current->mempolicy;
> + int pages_per_node;
>  
> - if (node == NUMA_NO_NODE)
> - page = alloc_page(alloc_mask);
> - else
> - page = alloc_pages_node(node, alloc_mask, 0);
> + if (policy && policy->mode == MPOL_INTERLEAVE) {
> + pages_per_node = DIV_ROUND_UP(nr_pages,
> +   nr_online_nodes);
> + max_node_order = min(max_node_order,
> +  ilog2(pages_per_node));
> + }
> + }
> +
> + for (i = 0; i < area->nr_pages;) {
> + unsigned int chunk_order = min(ilog2(area->nr_pages - i),
> +max_node_order);
> + struct page *page = NULL;
> +
> + while (chunk_order) {
> + if (node == NUMA_NO_NODE)
> + page = alloc_pages(multi_alloc_mask, 
> chunk_order);
> + else
> + page = alloc_pages_node(node, multi_alloc_mask, 
> chunk_order);
> + if (page) {
> + split_page(page, chunk_order);
> + break;
> + }
> +  

[PATCH 1/1 v2] isdn: hisax: set error code on failure

2016-12-04 Thread Pan Bian
From: Pan Bian 

In function hfc4s8s_probe(), the value of return variable err should be
negative on failures. However, when the call to request_region() returns
NULL, the value of err is 0. This patch fixes the bug, assigning
"-EBUSY" to err on the path that request_region() fails.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188931

Signed-off-by: Pan Bian 
---
 drivers/isdn/hisax/hfc4s8s_l1.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index 9600cd7..3172cee 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -1499,6 +1499,7 @@ struct hfc4s8s_l1 {
printk(KERN_INFO
   "HFC-4S/8S: failed to request address space at 0x%04x\n",
   hw->iobase);
+   err = -EBUSY;
goto out;
}
 
-- 
1.9.1




[PATCH 1/1 v2] net: bnx2x: fix improper return value

2016-12-04 Thread Pan Bian
From: Pan Bian 

Macro BNX2X_ALLOC_AND_SET(arr, lbl, func) calls kmalloc() to allocate
memory, and jumps to label "lbl" if the allocation fails. Label "lbl"
first cleans memory and then returns variable rc. Before calling the
macro, the value of variable rc is 0. Because 0 means no error, the
callers of bnx2x_init_firmware() may be misled. This patch fixes the bug,
assigning "-ENOMEM" to rc before calling macro NX2X_ALLOC_AND_SET().

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189141

Signed-off-by: Pan Bian 
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 0cee4c0..6f9fc20 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13505,6 +13505,7 @@ static int bnx2x_init_firmware(struct bnx2x *bp)
 
/* Initialize the pointers to the init arrays */
/* Blob */
+   rc = -ENOMEM;
BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
 
/* Opcodes */
-- 
1.9.1




Re: [PATCH] zram: restrict add/remove attributes to root only

2016-12-04 Thread Sergey Senozhatsky
On (12/04/16 11:28), Greg KH wrote:
> On Sun, Dec 04, 2016 at 11:35:15AM +0900, Sergey Senozhatsky wrote:
[..]

> Why can't a normal user read the attribute?  Does a read actually modify
> something?

yes, it does.

reading from a hot_add file creates a new zram device and returns a new
device's device_id. not initialized device (so it does not eat the memory
for handle table, etc.), but with its own set of sysfs attrs, etc. which
consumes memory after all. so a 'normal' user, doing a simple read from a
hot_add file in a loop just for fun, can create a lot of devices and,
quite likely, cause some troubles (as reported by Steven Allen).

-ss


[PATCH v7 2/3] console: Add callback to flush scrollback buffer to consw struct

2016-12-04 Thread Manuel Schölling
This new callback is in preparation for persistent scrollback buffer
support for VGA consoles.
With a single scrollback buffer for all consoles, we could flush the
buffer just by invocating consw->con_switch(). But when each VGA console
has its own scrollback buffer, we need a new callback to tell the
video console driver which buffer to flush.

Signed-off-by: Manuel Schölling 
Reviewed-by: Andrey Utkin 
Tested-by: Andrey Utkin 
Tested-by: Adam Borowski 

---
 drivers/tty/vt/vt.c|  9 +
 drivers/video/console/vgacon.c | 24 +++-
 include/linux/console.h|  4 
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 4c10a9d..9d3ce50 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -625,6 +625,14 @@ static void save_screen(struct vc_data *vc)
vc->vc_sw->con_save_screen(vc);
 }
 
+static void flush_scrollback(struct vc_data *vc)
+{
+   WARN_CONSOLE_UNLOCKED();
+
+   if (vc->vc_sw->con_flush_scrollback)
+   vc->vc_sw->con_flush_scrollback(vc);
+}
+
 /*
  * Redrawing of screen
  */
@@ -1171,6 +1179,7 @@ static void csi_J(struct vc_data *vc, int vpar)
case 3: /* erase scroll-back buffer (and whole display) */
scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char,
vc->vc_screenbuf_size);
+   flush_scrollback(vc);
set_origin(vc);
if (con_is_visible(vc))
update_screen(vc);
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 48b9764..9a7c2bb 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -173,6 +173,16 @@ static struct vgacon_scrollback_info {
int restore;
 } vgacon_scrollback;
 
+static void vgacon_scrollback_reset(size_t reset_size)
+{
+   if (vgacon_scrollback.data && reset_size > 0)
+   memset(vgacon_scrollback.data, 0, reset_size);
+
+   vgacon_scrollback.cnt  = 0;
+   vgacon_scrollback.tail = 0;
+   vgacon_scrollback.cur  = 0;
+}
+
 static void vgacon_scrollback_init(int pitch)
 {
int rows = CONFIG_VGACON_SOFT_SCROLLBACK_SIZE * 1024/pitch;
@@ -305,6 +315,14 @@ static void vgacon_scrolldelta(struct vc_data *c, int 
lines)
} else
vgacon_cursor(c, CM_MOVE);
 }
+
+static void vgacon_flush_scrollback(struct vc_data *c)
+{
+   size_t size = CONFIG_VGACON_SOFT_SCROLLBACK_SIZE * 1024;
+
+   if (c->vc_num == fg_console)
+   vgacon_scrollback_reset(size);
+}
 #else
 #define vgacon_scrollback_startup(...) do { } while (0)
 #define vgacon_scrollback_init(...)do { } while (0)
@@ -322,6 +340,10 @@ static void vgacon_scrolldelta(struct vc_data *c, int 
lines)
vga_vram_size);
vga_set_mem_top(c);
 }
+
+static void vgacon_flush_scrollback(struct vc_data *c)
+{
+}
 #endif /* CONFIG_VGACON_SOFT_SCROLLBACK */
 
 static const char *vgacon_startup(void)
@@ -1329,7 +1351,6 @@ static bool vgacon_scroll(struct vc_data *c, unsigned int 
t, unsigned int b,
return true;
 }
 
-
 /*
  *  The console `switch' structure for the VGA based console
  */
@@ -1362,6 +1383,7 @@ const struct consw vga_con = {
.con_save_screen = vgacon_save_screen,
.con_build_attr = vgacon_build_attr,
.con_invert_region = vgacon_invert_region,
+   .con_flush_scrollback = vgacon_flush_scrollback,
 };
 EXPORT_SYMBOL(vga_con);
 
diff --git a/include/linux/console.h b/include/linux/console.h
index 9c26c66..5949d18 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -73,6 +73,10 @@ struct consw {
u16*(*con_screen_pos)(struct vc_data *, int);
unsigned long (*con_getxy)(struct vc_data *, unsigned long, int *, int 
*);
/*
+* Flush the video console driver's scrollback buffer
+*/
+   void(*con_flush_scrollback)(struct vc_data *);
+   /*
 * Prepare the console for the debugger.  This includes, but is not
 * limited to, unblanking the console, loading an appropriate
 * palette, and allowing debugger generated output.
-- 
2.1.4



[PATCH v7 0/3] console: Add persistent scrollback buffers for all VGA consoles

2016-12-04 Thread Manuel Schölling
Reviewed-by: Andrey Utkin 
Tested-by: Andrey Utkin 
Tested-by: Adam Borowski 

--
Changes in v7:
  - Add new callback to consw struct for flushing video console driver's
scrollback buffer. Fixes issues with escape sequence '\e[3J' reported
by Adam Borowski (kilob...@angband.pl).
  - Fix style issues
Changes in v6:
  - Change of check if feature is enabled in 
vgacon_scrollback_switch()
Changes in v5:
  - Clearify documentation
  - Skip superfluous array initialization
  - Disable scrollback if buffer allocation fails
  - Refactor vgacon_switch_scrollback()
  - Rename vgacon_switch_scrollback() to vgacon_scrollback_switch()
  - Add check for fg_console in vgacon_scrollback_update
Changes in v4.1:
  - Fix compiler error
Changes in v4:
  - Rename from VGACON_SOFT_SCROLLBACK_FOR_EACH_CONSOLE to
VGACON_SOFT_SCROLLBACK_PERSISTENT
  - Split into two patches
  - Rework documentation
  - Remove cosmetic changes in comments (postponed)
Changes in v3:
  - Add config option for this feature
  - Fallback to old scrollback buffer if kcalloc() fails
  - Remove ioctl() call again and add documentation about existing
escape sequence to flush the scrollback buffer
Changes in v2:
  - Add ioctl() call to flush scrollback buffer
  - (Patch v2 was not labeled as such, sorry)

Manuel Schölling (3):
  console: Move scrollback data into its own struct
  console: Add callback to flush scrollback buffer to consw struct
  console: Add persistent scrollback buffers for all VGA consoles

 drivers/tty/vt/vt.c|   9 +++
 drivers/video/console/Kconfig  |  25 ++-
 drivers/video/console/vgacon.c | 165 -
 include/linux/console.h|   4 +
 4 files changed, 148 insertions(+), 55 deletions(-)

-- 
2.1.4



[PATCH v7 1/3] console: Move scrollback data into its own struct

2016-12-04 Thread Manuel Schölling
This refactoring is in preparation for persistent scrollback
support for VGA console.

Signed-off-by: Manuel Schölling 
Reviewed-by: Andrey Utkin 
Tested-by: Andrey Utkin 
Tested-by: Adam Borowski 

---
 drivers/video/console/vgacon.c | 91 ++
 1 file changed, 47 insertions(+), 44 deletions(-)

diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index c22a562..48b9764 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -162,31 +162,34 @@ static inline void vga_set_mem_top(struct vc_data *c)
 
 #ifdef CONFIG_VGACON_SOFT_SCROLLBACK
 /* software scrollback */
-static void *vgacon_scrollback;
-static int vgacon_scrollback_tail;
-static int vgacon_scrollback_size;
-static int vgacon_scrollback_rows;
-static int vgacon_scrollback_cnt;
-static int vgacon_scrollback_cur;
-static int vgacon_scrollback_save;
-static int vgacon_scrollback_restore;
+static struct vgacon_scrollback_info {
+   void *data;
+   int tail;
+   int size;
+   int rows;
+   int cnt;
+   int cur;
+   int save;
+   int restore;
+} vgacon_scrollback;
 
 static void vgacon_scrollback_init(int pitch)
 {
int rows = CONFIG_VGACON_SOFT_SCROLLBACK_SIZE * 1024/pitch;
 
-   if (vgacon_scrollback) {
-   vgacon_scrollback_cnt  = 0;
-   vgacon_scrollback_tail = 0;
-   vgacon_scrollback_cur  = 0;
-   vgacon_scrollback_rows = rows - 1;
-   vgacon_scrollback_size = rows * pitch;
+   if (vgacon_scrollback.data) {
+   vgacon_scrollback.cnt  = 0;
+   vgacon_scrollback.tail = 0;
+   vgacon_scrollback.cur  = 0;
+   vgacon_scrollback.rows = rows - 1;
+   vgacon_scrollback.size = rows * pitch;
}
 }
 
 static void vgacon_scrollback_startup(void)
 {
-   vgacon_scrollback = kcalloc(CONFIG_VGACON_SOFT_SCROLLBACK_SIZE, 1024, 
GFP_NOWAIT);
+   vgacon_scrollback.data = kcalloc(CONFIG_VGACON_SOFT_SCROLLBACK_SIZE,
+   1024, GFP_NOWAIT);
vgacon_scrollback_init(vga_video_num_columns * 2);
 }
 
@@ -194,38 +197,38 @@ static void vgacon_scrollback_update(struct vc_data *c, 
int t, int count)
 {
void *p;
 
-   if (!vgacon_scrollback_size || c->vc_num != fg_console)
+   if (!vgacon_scrollback.size || c->vc_num != fg_console)
return;
 
p = (void *) (c->vc_origin + t * c->vc_size_row);
 
while (count--) {
-   scr_memcpyw(vgacon_scrollback + vgacon_scrollback_tail,
+   scr_memcpyw(vgacon_scrollback.data + vgacon_scrollback.tail,
p, c->vc_size_row);
-   vgacon_scrollback_cnt++;
+   vgacon_scrollback.cnt++;
p += c->vc_size_row;
-   vgacon_scrollback_tail += c->vc_size_row;
+   vgacon_scrollback.tail += c->vc_size_row;
 
-   if (vgacon_scrollback_tail >= vgacon_scrollback_size)
-   vgacon_scrollback_tail = 0;
+   if (vgacon_scrollback.tail >= vgacon_scrollback.size)
+   vgacon_scrollback.tail = 0;
 
-   if (vgacon_scrollback_cnt > vgacon_scrollback_rows)
-   vgacon_scrollback_cnt = vgacon_scrollback_rows;
+   if (vgacon_scrollback.cnt > vgacon_scrollback.rows)
+   vgacon_scrollback.cnt = vgacon_scrollback.rows;
 
-   vgacon_scrollback_cur = vgacon_scrollback_cnt;
+   vgacon_scrollback.cur = vgacon_scrollback.cnt;
}
 }
 
 static void vgacon_restore_screen(struct vc_data *c)
 {
-   vgacon_scrollback_save = 0;
+   vgacon_scrollback.save = 0;
 
-   if (!vga_is_gfx && !vgacon_scrollback_restore) {
+   if (!vga_is_gfx && !vgacon_scrollback.restore) {
scr_memcpyw((u16 *) c->vc_origin, (u16 *) c->vc_screenbuf,
c->vc_screenbuf_size > vga_vram_size ?
vga_vram_size : c->vc_screenbuf_size);
-   vgacon_scrollback_restore = 1;
-   vgacon_scrollback_cur = vgacon_scrollback_cnt;
+   vgacon_scrollback.restore = 1;
+   vgacon_scrollback.cur = vgacon_scrollback.cnt;
}
 }
 
@@ -239,41 +242,41 @@ static void vgacon_scrolldelta(struct vc_data *c, int 
lines)
return;
}
 
-   if (!vgacon_scrollback)
+   if (!vgacon_scrollback.data)
return;
 
-   if (!vgacon_scrollback_save) {
+   if (!vgacon_scrollback.save) {
vgacon_cursor(c, CM_ERASE);
vgacon_save_screen(c);
-   vgacon_scrollback_save = 1;
+   vgacon_scrollback.save = 1;
}
 
-   vgacon_scrollback_restore = 0;
-   start = vgacon_scrollback_cur + lines;
+   vgacon_scrollback.restore = 0;
+   start = vgacon_scrollback.cur + lines;
end = start + abs(lines);
 
if

[PATCH v7 3/3] console: Add persistent scrollback buffers for all VGA consoles

2016-12-04 Thread Manuel Schölling
Add a scrollback buffers for each VGA console. The benefit is that
the scrollback history is not flushed when switching between consoles
but is persistent.
The buffers are allocated on demand when a new console is opened.

This breaks tools like clear_console that rely on flushing the
scrollback history by switching back and forth between consoles
which is why this feature is disabled by default.
Use the escape sequence \e[3J instead for flushing the buffer.

Signed-off-by: Manuel Schölling 
Reviewed-by: Andrey Utkin 
Tested-by: Andrey Utkin 
Tested-by: Adam Borowski 

---
 drivers/video/console/Kconfig  |  25 +++-
 drivers/video/console/vgacon.c | 142 ++---
 2 files changed, 111 insertions(+), 56 deletions(-)

diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index 38da6e2..c5742d2 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -43,9 +43,28 @@ config VGACON_SOFT_SCROLLBACK_SIZE
range 1 1024
default "64"
help
- Enter the amount of System RAM to allocate for the scrollback
-buffer.  Each 64KB will give you approximately 16 80x25
-screenfuls of scrollback buffer
+ Enter the amount of System RAM to allocate for scrollback
+ buffers of VGA consoles. Each 64KB will give you approximately
+ 16 80x25 screenfuls of scrollback buffer.
+
+config VGACON_SOFT_SCROLLBACK_PERSISTENT
+   bool "Persistent Scrollback History for each console"
+   depends on VGACON_SOFT_SCROLLBACK
+   default n
+   help
+ Say Y here if the scrollback history should persist when switching
+ between consoles. Otherwise, the scrollback history will be flushed
+ each time the console is switched.
+
+ This feature might break your tool of choice to flush the scrollback
+ buffer, e.g. clear(1) will work fine but Debian's clear_console(1)
+ will be broken, which might cause security issues.
+ You can use the escape sequence \e[3J instead if this feature is
+ activated.
+
+ Note that a buffer of VGACON_SOFT_SCROLLBACK_SIZE is taken for each
+ created tty device.
+ So if you use a RAM-constrained system, say N here.
 
 config MDA_CONSOLE
depends on !M68K && !PARISC && ISA
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 9a7c2bb..ca23d22 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -162,7 +162,7 @@ static inline void vga_set_mem_top(struct vc_data *c)
 
 #ifdef CONFIG_VGACON_SOFT_SCROLLBACK
 /* software scrollback */
-static struct vgacon_scrollback_info {
+struct vgacon_scrollback_info {
void *data;
int tail;
int size;
@@ -171,74 +171,110 @@ static struct vgacon_scrollback_info {
int cur;
int save;
int restore;
-} vgacon_scrollback;
+};
+
+static struct vgacon_scrollback_info *vgacon_scrollback_cur;
+#ifdef CONFIG_VGACON_SOFT_SCROLLBACK_PERSISTENT
+static struct vgacon_scrollback_info vgacon_scrollbacks[MAX_NR_CONSOLES];
+#else
+static struct vgacon_scrollback_info vgacon_scrollbacks[1];
+#endif
 
-static void vgacon_scrollback_reset(size_t reset_size)
+static void vgacon_scrollback_reset(int vc_num, size_t reset_size)
 {
-   if (vgacon_scrollback.data && reset_size > 0)
-   memset(vgacon_scrollback.data, 0, reset_size);
+   struct vgacon_scrollback_info *scrollback = &vgacon_scrollbacks[vc_num];
+
+   if (scrollback->data && reset_size > 0)
+   memset(scrollback->data, 0, reset_size);
 
-   vgacon_scrollback.cnt  = 0;
-   vgacon_scrollback.tail = 0;
-   vgacon_scrollback.cur  = 0;
+   scrollback->cnt  = 0;
+   scrollback->tail = 0;
+   scrollback->cur  = 0;
 }
 
-static void vgacon_scrollback_init(int pitch)
+static void vgacon_scrollback_init(int vc_num)
 {
-   int rows = CONFIG_VGACON_SOFT_SCROLLBACK_SIZE * 1024/pitch;
-
-   if (vgacon_scrollback.data) {
-   vgacon_scrollback.cnt  = 0;
-   vgacon_scrollback.tail = 0;
-   vgacon_scrollback.cur  = 0;
-   vgacon_scrollback.rows = rows - 1;
-   vgacon_scrollback.size = rows * pitch;
+   int pitch = vga_video_num_columns * 2;
+   size_t size = CONFIG_VGACON_SOFT_SCROLLBACK_SIZE * 1024;
+   int rows = size / pitch;
+   void *data;
+
+   data = kmalloc_array(CONFIG_VGACON_SOFT_SCROLLBACK_SIZE, 1024,
+GFP_NOWAIT);
+
+   vgacon_scrollbacks[vc_num].data = data;
+   vgacon_scrollback_cur = &vgacon_scrollbacks[vc_num];
+
+   vgacon_scrollback_cur->rows = rows - 1;
+   vgacon_scrollback_cur->size = rows * pitch;
+
+   vgacon_scrollback_reset(vc_num, size);
+}
+
+static void vgacon_scrollback_switch(int vc_num)
+{
+#ifndef CONFIG_VGACON_SOFT_SCROLLBACK_PERSISTENT
+   vc_num = 0;
+#endif
+
+   if (!vgacon_scrollba

Re: [PATCH 1/1] iio: light: fix improper return value

2016-12-04 Thread Jonathan Cameron
On 03/12/16 09:24, Pan Bian wrote:
> In function cm3232_reg_init(), it returns 0 even if the last call to
> i2c_smbus_write_byte_data() returns a negative value (indicates error).
> As a result, the return value may be inconsistent with the execution
> status, and the caller of cm3232_reg_init() will not be able to detect
> the error. This patch fixes the bug.
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188641
> 
> Signed-off-by: Pan Bian 
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/light/cm3232.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/cm3232.c b/drivers/iio/light/cm3232.c
> index fe89b68..263e972 100644
> --- a/drivers/iio/light/cm3232.c
> +++ b/drivers/iio/light/cm3232.c
> @@ -119,7 +119,7 @@ static int cm3232_reg_init(struct cm3232_chip *chip)
>   if (ret < 0)
>   dev_err(&chip->client->dev, "Error writing reg_cmd\n");
>  
> - return 0;
> + return ret;
>  }
>  
>  /**
> 



Re: [PATCH 1/1] staging: iio: cdc: fix improper return value

2016-12-04 Thread Jonathan Cameron
On 03/12/16 13:44, Pan Bian wrote:
> From: Pan Bian 
> 
> At the end of function ad7150_write_event_config(), directly returns 0.
> As a result, the errors will be ignored by the callers. It may be better 
> to return variable "ret".
> 
> Signed-off-by: Pan Bian 
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/staging/iio/cdc/ad7150.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/cdc/ad7150.c 
> b/drivers/staging/iio/cdc/ad7150.c
> index 5578a07..50a5b0c2 100644
> --- a/drivers/staging/iio/cdc/ad7150.c
> +++ b/drivers/staging/iio/cdc/ad7150.c
> @@ -274,7 +274,7 @@ static int ad7150_write_event_config(struct iio_dev 
> *indio_dev,
>  error_ret:
>   mutex_unlock(&chip->state_lock);
>  
> - return 0;
> + return ret;
>  }
>  
>  static int ad7150_read_event_value(struct iio_dev *indio_dev,
> 



[PATCH 1/1] net: qed: set error code on failure

2016-12-04 Thread Pan Bian
From: Pan Bian 

When calling dma_mapping_error(), the value of return variable rc is 0.
And when the call returns an unexpected value, rc is not set to a
negative errno. Thus, it will return 0 on the error path, and its
callers cannot detect the bug. This patch fixes the bug, assigning
"-ENOMEM" to err.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189041

Signed-off-by: Pan Bian 
---
 drivers/net/ethernet/qlogic/qed/qed_ll2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/qlogic/qed/qed_ll2.c 
b/drivers/net/ethernet/qlogic/qed/qed_ll2.c
index f95385c..62ae55b 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_ll2.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_ll2.c
@@ -1730,6 +1730,7 @@ static int qed_ll2_start_xmit(struct qed_dev *cdev, 
struct sk_buff *skb)
   mapping))) {
DP_NOTICE(cdev,
  "Unable to map frag - dropping 
packet\n");
+   rc = -ENOMEM;
goto err;
}
} else {
-- 
1.9.1




Re: [PATCH 01/19] staging: iio: isl29028: remove nested if statements

2016-12-04 Thread Jonathan Cameron
On 04/12/16 02:19, Brian Masney wrote:
> There are two callers to the function isl29028_set_als_ir_mode() and
> both instances use a nested if statement to only change the chip state
> if it is not in the proper mode. This patch moves this check into the
> isl29028_set_als_ir_mode() function to remove the nested if
> statements.
> 
> Signed-off-by: Brian Masney 
Sensible little clean up.

Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it. (If I can get a push out in the last 3 mins
of my free 15 of wifi on this train!)

Thanks,

Jonathan
> ---
>  drivers/staging/iio/light/isl29028.c | 30 ++
>  1 file changed, 14 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/isl29028.c 
> b/drivers/staging/iio/light/isl29028.c
> index aa413e5..4e35d00 100644
> --- a/drivers/staging/iio/light/isl29028.c
> +++ b/drivers/staging/iio/light/isl29028.c
> @@ -124,6 +124,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip 
> *chip,
>  {
>   int ret = 0;
>  
> + if (chip->als_ir_mode == mode)
> + return 0;
> +
>   switch (mode) {
>   case ISL29028_MODE_ALS:
>   ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
> @@ -160,6 +163,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip 
> *chip,
>  
>   /* Need to wait for conversion time if ALS/IR mode enabled */
>   mdelay(ISL29028_CONV_TIME_MS);
> +
> + chip->als_ir_mode = mode;
> +
>   return 0;
>  }
>  
> @@ -223,14 +229,10 @@ static int isl29028_als_get(struct isl29028_chip *chip, 
> int *als_data)
>   int ret;
>   int als_ir_data;
>  
> - if (chip->als_ir_mode != ISL29028_MODE_ALS) {
> - ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
> - if (ret < 0) {
> - dev_err(dev,
> - "Error in enabling ALS mode err %d\n", ret);
> - return ret;
> - }
> - chip->als_ir_mode = ISL29028_MODE_ALS;
> + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
> + if (ret < 0) {
> + dev_err(dev, "Error in enabling ALS mode err %d\n", ret);
> + return ret;
>   }
>  
>   ret = isl29028_read_als_ir(chip, &als_ir_data);
> @@ -256,14 +258,10 @@ static int isl29028_ir_get(struct isl29028_chip *chip, 
> int *ir_data)
>   struct device *dev = regmap_get_device(chip->regmap);
>   int ret;
>  
> - if (chip->als_ir_mode != ISL29028_MODE_IR) {
> - ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
> - if (ret < 0) {
> - dev_err(dev,
> - "Error in enabling IR mode err %d\n", ret);
> - return ret;
> - }
> - chip->als_ir_mode = ISL29028_MODE_IR;
> + ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
> + if (ret < 0) {
> + dev_err(dev, "Error in enabling IR mode err %d\n", ret);
> + return ret;
>   }
>   return isl29028_read_als_ir(chip, ir_data);
>  }
> 



Re: Enabling peer to peer device transactions for PCIe devices

2016-12-04 Thread Haggai Eran
On 11/30/2016 7:28 PM, Serguei Sagalovitch wrote:
> On 2016-11-30 11:23 AM, Jason Gunthorpe wrote:
>>> Yes, that sounds fine. Can we simply kill the process from the GPU driver?
>>> Or do we need to extend the OOM killer to manage GPU pages?
>> I don't know..
> We could use send_sig_info to send signal from  kernel  to user space. So 
> theoretically GPU driver
> could issue KILL signal to some process.
> 
>> On Wed, Nov 30, 2016 at 12:45:58PM +0200, Haggai Eran wrote:
>>> I think we can achieve the kernel's needs with ZONE_DEVICE and DMA-API 
>>> support
>>> for peer to peer. I'm not sure we need vmap. We need a way to have a 
>>> scatterlist
>>> of MMIO pfns, and ZONE_DEVICE allows that.
> I do not think that using DMA-API as it is is the best solution (at least in 
> the current form):
> 
> -  It deals with handles/fd for the whole allocation but client could/will 
> use sub-allocation as
> well as theoretically possible to "merge" several allocations in one from GPU 
> perspective.
> -  It require knowledge to export but because "sharing" is controlled from 
> user space it
> means that we must "export" all allocation by default
> - It deals with 'fd'/handles but user application may work with 
> addresses/pointers.

Aren't you confusing DMABUF and DMA-API? DMA-API is how you program the IOMMU 
(dma_map_page/dma_map_sg/etc.).
The comment above is just about the need to extend this API to allow mapping 
peer device pages to bus addresses.

In the past I sent an RFC for using DMABUF for peer to peer. I think it had some
advantages for legacy devices. I agree that working with addresses and pointers 
through
something like HMM/ODP is much more flexible and easier to program from 
user-space.
For legacy, DMABUF would have allowed you a way to pin the pages so the GPU 
knows not to
move them. However, that can probably also be achieved simply via the reference 
count
on ZONE_DEVICE pages. The other nice thing about DMABUF is that it migrate the 
buffer
itself during attachment according to the requirements of the device that is 
attaching,
so you can automatically decide in the exporter whether to use p2p or a staging 
buffer.

> 
> Also current  DMA-API force each time to do all DMA table programming 
> unrelated if
> location was changed or not. With  vma / mmu  we are  able to install 
> notifier to intercept
> changes in location and update  translation tables only as needed (we do not 
> need to keep
> get_user_pages()  lock).
I agree.


Re: [PATCH] zram: restrict add/remove attributes to root only

2016-12-04 Thread Greg KH
On Sun, Dec 04, 2016 at 07:52:08PM +0900, Sergey Senozhatsky wrote:
> On (12/04/16 11:28), Greg KH wrote:
> > On Sun, Dec 04, 2016 at 11:35:15AM +0900, Sergey Senozhatsky wrote:
> [..]
> 
> > Why can't a normal user read the attribute?  Does a read actually modify
> > something?
> 
> yes, it does.

Oh that's totally and completely broken then.

Reading from a sysfs file should NEVER cause side affects to the system.
Please fix up this api.

> reading from a hot_add file creates a new zram device and returns a new
> device's device_id. not initialized device (so it does not eat the memory
> for handle table, etc.), but with its own set of sysfs attrs, etc. which
> consumes memory after all. so a 'normal' user, doing a simple read from a
> hot_add file in a loop just for fun, can create a lot of devices and,
> quite likely, cause some troubles (as reported by Steven Allen).

Please switch this to be a char device node if you wish to "write and
get a device handle back".  I don't know how I missed that in the
original api review, sorry about that.

For now, you need to document the heck out of this in the attribute
declaration that this is what is going on.  Otherwise someone like me
will come along and "fix up" the file to use ATTR_RO again in the
future and you will have the same problem again.

thanks,

greg k-h


RE: [PATCH 1/1] net: ethernet: broadcom: fix improper return value

2016-12-04 Thread Kalderon, Michal
> From: Pan Bian 
> 
> Marco BNX2X_ALLOC_AND_SET(arr, lbl, func) calls kmalloc() to allocate
> memory, and jumps to label "lbl" if the allocation fails. Label "lbl"
> first cleans memory and then returns variable rc. Before calling the macro, 
> the
> value of variable rc is 0. Because 0 means no error, the callers of
> bnx2x_init_firmware() may be misled. This patch fixes the bug, assigning "-
> ENOMEM" to rc before calling macro NX2X_ALLOC_AND_SET().
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189141
> 
> Signed-off-by: Pan Bian 

The title is wrong from net-next; It should have been "bnx2x: Fix improper 
return value".

Acked-by: Michal Kalderon 


Re: [PATCH] zram: restrict add/remove attributes to root only

2016-12-04 Thread Sergey Senozhatsky
On (12/04/16 12:28), Greg KH wrote:
> Date: Sun, 4 Dec 2016 12:28:20 +0100
> From: Greg KH 
> To: Sergey Senozhatsky 
> Cc: Andrew Morton , Minchan Kim
>  , Steven Allen ,
>  linux-kernel@vger.kernel.org, sta...@vger.kernel.org, Sergey Senozhatsky
>  
> Subject: Re: [PATCH] zram: restrict add/remove attributes to root only
> User-Agent: Mutt/1.7.1 (2016-10-04)
> 
> On Sun, Dec 04, 2016 at 07:52:08PM +0900, Sergey Senozhatsky wrote:
> > On (12/04/16 11:28), Greg KH wrote:
> > > On Sun, Dec 04, 2016 at 11:35:15AM +0900, Sergey Senozhatsky wrote:
> > [..]
> > 
> > > Why can't a normal user read the attribute?  Does a read actually modify
> > > something?
> > 
> > yes, it does.

to clarify a bit more:

we allocate a new device ID using idr_alloc(). so the IDs are limited
and, thus, the number of devices is limited as well - signed int. each
new device has NO:
 -- zspoll (zsmalloc pool in zram case)
 -- compression per-CPU backends (working-mem/scratch buffers, etc.)
 -- meta table

so no big memory allocations. (a 'normal' user can't init the device,
he/she can just create it. which is the problem here: we don't want a
'normal' user be able to do this).

every device has:
 -- blk queue
 -- sysfs attrs
 -- gendisk
 -- zram structure allocated.

so each new device consumes some memory, but not insane amounts of it.


> Oh that's totally and completely broken then.
> 
> Reading from a sysfs file should NEVER cause side affects to the system.
> Please fix up this api.

some history. we started with a 'loop device'-like scheme, but
ended up with a sysfs approach

 [1] https://marc.info/?l=linux-kernel&m=142495984002611
 [2] https://marc.info/?l=linux-kernel&m=142507747808572
 [3] https://marc.info/?l=linux-kernel&m=142530591720172
 [4] https://marc.info/?l=linux-kernel&m=142509446812318
 [5] https://marc.info/?l=linux-kernel&m=142509782112819


> > reading from a hot_add file creates a new zram device and returns a new
> > device's device_id. not initialized device (so it does not eat the memory
> > for handle table, etc.), but with its own set of sysfs attrs, etc. which
> > consumes memory after all. so a 'normal' user, doing a simple read from a
> > hot_add file in a loop just for fun, can create a lot of devices and,
> > quite likely, cause some troubles (as reported by Steven Allen).
> 
> Please switch this to be a char device node if you wish to "write and
> get a device handle back".  I don't know how I missed that in the
> original api review, sorry about that.
>
> For now, you need to document the heck out of this in the attribute
> declaration that this is what is going on.  Otherwise someone like me
> will come along and "fix up" the file to use ATTR_RO again in the
> future and you will have the same problem again.


I believe we have a documentation

Documentation/ABI/testing/sysfs-class-zram
and
Documentation/blockdev/zram.txt

both explain this attr.

-ss


Re: [PATCH] zram: restrict add/remove attributes to root only

2016-12-04 Thread Greg KH
On Sun, Dec 04, 2016 at 08:41:17PM +0900, Sergey Senozhatsky wrote:
> On (12/04/16 12:28), Greg KH wrote:
> > Date: Sun, 4 Dec 2016 12:28:20 +0100
> > From: Greg KH 
> > To: Sergey Senozhatsky 
> > Cc: Andrew Morton , Minchan Kim
> >  , Steven Allen ,
> >  linux-kernel@vger.kernel.org, sta...@vger.kernel.org, Sergey Senozhatsky
> >  
> > Subject: Re: [PATCH] zram: restrict add/remove attributes to root only
> > User-Agent: Mutt/1.7.1 (2016-10-04)
> > 
> > On Sun, Dec 04, 2016 at 07:52:08PM +0900, Sergey Senozhatsky wrote:
> > > On (12/04/16 11:28), Greg KH wrote:
> > > > On Sun, Dec 04, 2016 at 11:35:15AM +0900, Sergey Senozhatsky wrote:
> > > [..]
> > > 
> > > > Why can't a normal user read the attribute?  Does a read actually modify
> > > > something?
> > > 
> > > yes, it does.
> 
> to clarify a bit more:
> 
> we allocate a new device ID using idr_alloc(). so the IDs are limited
> and, thus, the number of devices is limited as well - signed int. each
> new device has NO:
>  -- zspoll (zsmalloc pool in zram case)
>  -- compression per-CPU backends (working-mem/scratch buffers, etc.)
>  -- meta table
> 
> so no big memory allocations. (a 'normal' user can't init the device,
> he/she can just create it. which is the problem here: we don't want a
> 'normal' user be able to do this).
> 
> every device has:
>  -- blk queue
>  -- sysfs attrs
>  -- gendisk
>  -- zram structure allocated.
> 
> so each new device consumes some memory, but not insane amounts of it.

That's fine, the issue is that reading a file should not cause the
system state to change.  That's just not a logical thing to have happen,
no other sysfs files do that.  Why is zram "special" in this way?

> > Oh that's totally and completely broken then.
> > 
> > Reading from a sysfs file should NEVER cause side affects to the system.
> > Please fix up this api.
> 
> some history. we started with a 'loop device'-like scheme, but
> ended up with a sysfs approach
> 
>  [1] https://marc.info/?l=linux-kernel&m=142495984002611
>  [2] https://marc.info/?l=linux-kernel&m=142507747808572
>  [3] https://marc.info/?l=linux-kernel&m=142530591720172
>  [4] https://marc.info/?l=linux-kernel&m=142509446812318
>  [5] https://marc.info/?l=linux-kernel&m=142509782112819

you should have stuck with the "write a value to the sysfs file" api,
for some reason that didn't stick...

> > > reading from a hot_add file creates a new zram device and returns a new
> > > device's device_id. not initialized device (so it does not eat the memory
> > > for handle table, etc.), but with its own set of sysfs attrs, etc. which
> > > consumes memory after all. so a 'normal' user, doing a simple read from a
> > > hot_add file in a loop just for fun, can create a lot of devices and,
> > > quite likely, cause some troubles (as reported by Steven Allen).
> > 
> > Please switch this to be a char device node if you wish to "write and
> > get a device handle back".  I don't know how I missed that in the
> > original api review, sorry about that.
> >
> > For now, you need to document the heck out of this in the attribute
> > declaration that this is what is going on.  Otherwise someone like me
> > will come along and "fix up" the file to use ATTR_RO again in the
> > future and you will have the same problem again.
> 
> 
> I believe we have a documentation
> 
>   Documentation/ABI/testing/sysfs-class-zram
> and
>   Documentation/blockdev/zram.txt
> 
> both explain this attr.

Yes, but that's not in the code itself.  You are doing something VERY
different here than any other sysfs file.  The code better explain it
very well so that I don't go and change this back sometime in the future
when I sweep the kernel for "odd sysfs mode values" like I do every few
years.

So comment this please, why would you object to that?

greg k-h


Re: [PATCH] zram: restrict add/remove attributes to root only

2016-12-04 Thread Sergey Senozhatsky
On (12/04/16 12:55), Greg KH wrote:
[..]
> That's fine, the issue is that reading a file should not cause the
> system state to change.  That's just not a logical thing to have happen,
> no other sysfs files do that. Why is zram "special" in this way?

yeah, zram is not really special, we just didn't come up with
anything better than that.

> > some history. we started with a 'loop device'-like scheme, but
> > ended up with a sysfs approach
> > 
> >  [1] https://marc.info/?l=linux-kernel&m=142495984002611
> >  [2] https://marc.info/?l=linux-kernel&m=142507747808572
> >  [3] https://marc.info/?l=linux-kernel&m=142530591720172
> >  [4] https://marc.info/?l=linux-kernel&m=142509446812318
> >  [5] https://marc.info/?l=linux-kernel&m=142509782112819
> 
> you should have stuck with the "write a value to the sysfs file" api,
> for some reason that didn't stick...

yes, we had this 'echo ID > /sys//zram_add' at some point, but it
didn't fly.

> > I believe we have a documentation
> > 
> > Documentation/ABI/testing/sysfs-class-zram
> > and
> > Documentation/blockdev/zram.txt
> > 
> > both explain this attr.
> 
> Yes, but that's not in the code itself.  You are doing something VERY
> different here than any other sysfs file.  The code better explain it
> very well so that I don't go and change this back sometime in the future
> when I sweep the kernel for "odd sysfs mode values" like I do every few
> years.
> 
> So comment this please, why would you object to that?

oh, I'm not objecting. I just gave as much info as possible.
v2 [with a comment]  will be out soon.


will this comment suffice?



diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index ee03464..3a0576f 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1413,6 +1413,13 @@ static ssize_t hot_remove_store(struct class *class,
return ret ? ret : count;
 }
 
+/*
+ * NOTE: hot_add attribute is not the usual read-only sysfs
+ * attribute. In a sence that reading from this file does alter
+ * the state of your system -- it creates a new un-initialized
+ * zram device and returns back this device's device_id (or an
+ * error code if it fails to create a new device).
+ */
 static struct class_attribute zram_control_class_attrs[] = {
__ATTR(hot_add, 0400, hot_add_show, NULL),
__ATTR(hot_remove, 0200, NULL, hot_remove_store),

--

-ss


Re: Enabling peer to peer device transactions for PCIe devices

2016-12-04 Thread Haggai Eran
On 11/30/2016 8:01 PM, Logan Gunthorpe wrote:
> 
> 
> On 30/11/16 09:23 AM, Jason Gunthorpe wrote:
>>> Two cases I can think of are RDMA access to an NVMe device's controller
>>> memory buffer,
>>
>> I'm not sure on the use model there..
> 
> The NVMe fabrics stuff could probably make use of this. It's an
> in-kernel system to allow remote access to an NVMe device over RDMA. So
> they ought to be able to optimize their transfers by DMAing directly to
> the NVMe's CMB -- no userspace interface would be required but there
> would need some kernel infrastructure.

Yes, that's what I was thinking. The NVMe/f driver needs to map the CMB for
RDMA. I guess if it used ZONE_DEVICE like in the iopmem patches it would be
relatively easy to do.



Re: [PATCH] vfio/pci: Support error recovery

2016-12-04 Thread Cao jin


On 12/01/2016 10:55 PM, Alex Williamson wrote:
> On Thu, 1 Dec 2016 21:40:00 +0800

>>> If an AER fault occurs and the user doesn't do a reset, what
>>> happens when that device is released and a host driver tries to make
>>> use of it?  The user makes no commitment to do a reset and there are
>>> only limited configurations where we even allow the user to perform a
>>> reset.
>>>   
>>
>> Limited? Do you mean the things __pci_dev_reset() can do?
> 
> I mean that there are significant device and guest configuration
> restrictions in order to support AER.  For instance, all the functions
> of the slot need to appear in a PCI-e topology in the guest with all
> the functions in the right place such that a guest bus reset translates
> into a host bus reset.  The physical functions cannot be split between
> guests even if IOMMU isolation would otherwise allow it.  The user
> needs to explicitly enable AER support for the devices.  A VM need to
> be specifically configured for AER support in order to set any sort of
> expectations of a guest directed bus reset, let alone a guarantee that
> it will happen.  So all the existing VMs, where functions are split
> between guests, or the topology isn't exactly right, or AER isn't
> enabled see a regression from the above change as the device is no
> longer reset.
> 

I am not clear why set these restrictions in the current design. I take
a glance at older versions of qemu's patchset, their thoughts is:
translate a guest bus reset into a host bus reset(Which is
unreasonable[*] to me). And I guess, that's the *cause* of these
restrictions?  Is there any other stories behind these restrictions?

[*] In physical world, set bridge's secondary bus reset would send
hot-reset TLP to all functions below, trigger every device's reset
separately. Emulated device should behave the same, means just using
each device's DeviceClass->reset method.
-- 
Sincerely,
Cao jin




Linux 4.9: Reported regressions as of Sunday, 2016-12-04

2016-12-04 Thread Thorsten Leemhuis
Hi! Here is my fifth regression report for Linux 4.9. It lists 11
regressions I'm aware of. 4 of them are new; 6 got fixed since 
the last report -- that was two weeks ago, because I yet again
didn't find any spare time to compile a report last Sunday :-/

As always: Are you aware of any other regressions? Then please let me
know (simply CC regressi...@leemhuis.info). And please tell me if there
is anything in the report that shouldn't be there.

Ciao, Thorsten

== Current regressions ==

Desc: System hang up with call trace during doing S3/S4 stress
Repo: 16-12-01 https://bugzilla.kernel.org/show_bug.cgi?id=189421
Stat: n/a 
Note: Brand new

Desc: x86/unwind: Fix guess-unwinder regression // With frame pointers 
disabled, /proc//stack is broken
Repo: 16-11-28 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1281244.html
Stat: n/a 
Note: Fix heading upstream

Desc: [lkp] [mremap] 5d1904204c: will-it-scale.per_thread_ops -13.1% regression
Repo: 16-11-27 https://www.spinics.net/lists/linux-mm/msg117307.html
Stat: n/a 
Note: Aaron could not reproduce the issue on two of his machines

Desc: sched: fix find_idlest_group for fork/performance regression in hackbench
Repo: 16-11-25 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1280514.html
Stat: 16-12-04 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1285936.html
Note: Report contains patch to fix this, testing ongoing

Desc: GPU hang on resume from hibernation
Repo: 16-10-16 https://bugs.freedesktop.org/show_bug.cgi?id=98288#c9 
https://bugzilla.kernel.org/show_bug.cgi?id=177701
Stat: n/a 
Note: confusing bug, but seems the issue is still present

Desc: GPU hang on PlaneShift
Repo: 16-10-16 https://bugs.freedesktop.org/show_bug.cgi?id=98922 
https://bugzilla.kernel.org/show_bug.cgi?id=177701
Stat: n/a 
Note: confusing bug, but the issue might still be present

Desc: [i.MX6 DRM IPUv3] Regression 4.9-rc5: greenish screen with YUV420 video
Repo: 16-11-17 https://www.spinics.net/lists/kernel/msg2385550.html
Stat: 16-12-02 https://www.spinics.net/lists/kernel/msg2396720.html
Note: "patch available: 3fd8b292ae6b (""drm/imx: ipuv3-plane: merge 
ipu_plane_atomic_set_base into atomic_update"")"

Desc: "Failed boots/Package drops bisected to 4cd13c21b207 ""softirq: Let 
ksoftirqd do its job""; "
Repo: 16-11-16 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1273344.html
Stat: 16-11-25 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1280379.html
Note: Stalled

Desc: builddeb: fix cross-building to arm64 producing host-arch debs
Repo: 16-11-04 https://www.spinics.net/lists/linux-kbuild/msg13635.html
Stat: 16-11-11 https://www.spinics.net/lists/linux-kbuild/msg13696.html
Note: Nothing happened when Adam pinged Michael in 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1276268.html


== Stalled, waiting for feedback from reporter ==

Desc: 4.9-rc1 boot regression, ambiguous bisect result
Repo: 2016-10-19 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1253369.html
Stat: 16-10-21 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1255296.html
Note: Waiting for Dan or someone else to look into this

Desc: Skylake gen6 suspend/resume video regression
Repo: 16-10-16 https://bugzilla.kernel.org/show_bug.cgi?id=177731 
https://bugs.freedesktop.org/show_bug.cgi?id=98517
Stat: 16-10-31 https://bugzilla.kernel.org/show_bug.cgi?id=177731#c7
Note: Stalled

== Fixed since last report ==

Desc: module loadling broken due to kbuild changes
Repo: 16-10-15 http://www.gossamer-threads.com/lists/linux/kernel/2544734 and 
various other threads (https://lwn.net/Articles/707520/ )
Fix:  
https://git.kernel.org/torvalds/c/cd3caefb4663e3811d37cc2afad3cce642d60061 
https://git.kernel.org/torvalds/c/faaae2a581435f32781a105dda3501df388fddcb 
(among others)

Desc: "irq 16: nobody cared (try booting with the ""irqpoll"" option) since 
t0b9e2988ab226 (ahci: use pci_alloc_irq_vectors)"
Repo: 16-11-19 https://bugzilla.kernel.org/show_bug.cgi?id=188181
Stat: 16-12-03 https://bugzilla.kernel.org/show_bug.cgi?id=188181#c9
Note: Fixed according to reporter (might be thx to 
https://git.kernel.org/torvalds/c/6929ef385e09c0065b87fda3e7b872a5070ac783 )

Desc: "build regression: make.cross ARCH=mips fails with ""No rule to make 
target 'alchemy/devboards/'. """
Repo: 16-10-30 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1262410.html 
https://marc.info/?l=linux-kernel&m=147780880425626
Fix:  https://git.kernel.org/torvalds/c/818f38c5b7c4482abd71c64ac4d49911fbefaf9e

Desc: "oops due to 493b2ed3f760 (""crypto: algif_hash - Handle NULL hashes 
correctly"")"
Repo: 16-11-17 
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1273867.html
Fix:  https://git.kernel.org/torvalds/c/a8348bca2944d397a528772f5c0ccb47a8b58af4

Desc: MSI is no longer enabled for many/most Intel SATA controllers in 4.9
Repo: 16-11-16 https://bugzilla.kernel.org/show_bug.cgi?id=187821
Fix:  https://git.kernel.org/

[char-misc-next 1/2] mei: synchronize irq before initiating a reset.

2016-12-04 Thread Tomas Winkler
We need to synchronize irqs before issuing reset to make sure that the
clients communication is concluded and doesn't leak to the reset flow
and confusing the state machine.

This issue is happening during suspend/resume stress testing.

Signed-off-by: Tomas Winkler 
---
 drivers/misc/mei/hw-me.c   | 13 +
 drivers/misc/mei/hw-txe.c  | 15 ++-
 drivers/misc/mei/init.c|  6 --
 drivers/misc/mei/mei_dev.h |  8 +++-
 4 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index 998f7fc0e920..e2b56e8cf745 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -285,6 +285,18 @@ static void mei_me_intr_disable(struct mei_device *dev)
 }
 
 /**
+ * mei_me_synchronize_irq - wait for pending IRQ handlers
+ *
+ * @dev: the device structure
+ */
+static void mei_me_synchronize_irq(struct mei_device *dev)
+{
+   struct pci_dev *pdev = to_pci_dev(dev->dev);
+
+   synchronize_irq(pdev->irq);
+}
+
+/**
  * mei_me_hw_reset_release - release device from the reset
  *
  * @dev: the device structure
@@ -1238,6 +1250,7 @@ static const struct mei_hw_ops mei_me_hw_ops = {
.intr_clear = mei_me_intr_clear,
.intr_enable = mei_me_intr_enable,
.intr_disable = mei_me_intr_disable,
+   .synchronize_irq = mei_me_synchronize_irq,
 
.hbuf_free_slots = mei_me_hbuf_empty_slots,
.hbuf_is_ready = mei_me_hbuf_is_empty,
diff --git a/drivers/misc/mei/hw-txe.c b/drivers/misc/mei/hw-txe.c
index b7a2f622f23c..e9f8c0aeec13 100644
--- a/drivers/misc/mei/hw-txe.c
+++ b/drivers/misc/mei/hw-txe.c
@@ -19,7 +19,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 #include 
@@ -441,6 +441,18 @@ static void mei_txe_intr_enable(struct mei_device *dev)
 }
 
 /**
+ * mei_txe_synchronize_irq - wait for pending IRQ handlers
+ *
+ * @dev: the device structure
+ */
+static void mei_txe_synchronize_irq(struct mei_device *dev)
+{
+   struct pci_dev *pdev = to_pci_dev(dev->dev);
+
+   synchronize_irq(pdev->irq);
+}
+
+/**
  * mei_txe_pending_interrupts - check if there are pending interrupts
  * only Aliveness, Input ready, and output doorbell are of relevance
  *
@@ -1168,6 +1180,7 @@ static const struct mei_hw_ops mei_txe_hw_ops = {
.intr_clear = mei_txe_intr_clear,
.intr_enable = mei_txe_intr_enable,
.intr_disable = mei_txe_intr_disable,
+   .synchronize_irq = mei_txe_synchronize_irq,
 
.hbuf_free_slots = mei_txe_hbuf_empty_slots,
.hbuf_is_ready = mei_txe_is_input_ready,
diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c
index 9a9c2484d107..41e5760a6886 100644
--- a/drivers/misc/mei/init.c
+++ b/drivers/misc/mei/init.c
@@ -122,6 +122,10 @@ int mei_reset(struct mei_device *dev)
 mei_dev_state_str(state), fw_sts_str);
}
 
+   mei_clear_interrupts(dev);
+
+   mei_synchronize_irq(dev);
+
/* we're already in reset, cancel the init timer
 * if the reset was called due the hbm protocol error
 * we need to call it before hw start
@@ -273,8 +277,6 @@ int mei_restart(struct mei_device *dev)
 
mutex_lock(&dev->device_lock);
 
-   mei_clear_interrupts(dev);
-
dev->dev_state = MEI_DEV_POWER_UP;
dev->reset_count = 0;
 
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index f16bd1209848..699693cd8c59 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -271,6 +271,7 @@ struct mei_cl {
  * @intr_clear   : clear pending interrupts
  * @intr_enable  : enable interrupts
  * @intr_disable : disable interrupts
+ * @synchronize_irq  : synchronize irqs
  *
  * @hbuf_free_slots  : query for write buffer empty slots
  * @hbuf_is_ready: query if write buffer is empty
@@ -292,7 +293,6 @@ struct mei_hw_ops {
int (*hw_start)(struct mei_device *dev);
void (*hw_config)(struct mei_device *dev);
 
-
int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts);
enum mei_pg_state (*pg_state)(struct mei_device *dev);
bool (*pg_in_transition)(struct mei_device *dev);
@@ -301,6 +301,7 @@ struct mei_hw_ops {
void (*intr_clear)(struct mei_device *dev);
void (*intr_enable)(struct mei_device *dev);
void (*intr_disable)(struct mei_device *dev);
+   void (*synchronize_irq)(struct mei_device *dev);
 
int (*hbuf_free_slots)(struct mei_device *dev);
bool (*hbuf_is_ready)(struct mei_device *dev);
@@ -645,6 +646,11 @@ static inline void mei_disable_interrupts(struct 
mei_device *dev)
dev->ops->intr_disable(dev);
 }
 
+static inline void mei_synchronize_irq(struct mei_device *dev)
+{
+   dev->ops->synchronize_irq(dev);
+}
+
 static inline bool mei_host_is_ready(struct mei_device *dev)
 {
return dev->ops->host_is_ready(dev);
-- 
2.7.4



[char-misc-next 2/2] mei: fix the back to back interrupt handling

2016-12-04 Thread Tomas Winkler
From: Alexander Usyskin 

Since the newer HW sports two interrupts causes we cannot
just simply acknowledge the interrupts directly in the quick handler
and store the cause in the member variable, as the cause
will be overridden upon next interrupt while the interrupt thread
was not yet scheduled handling the previous interrupt.
The simple fix is to disable interrupts in quick handler
and acknowledge and enabled them in the interrupt thread.

Signed-off-by: Alexander Usyskin 
Signed-off-by: Tomas Winkler 
---
 drivers/misc/mei/hw-me.c | 67 
 drivers/misc/mei/hw-me.h |  2 --
 2 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index e2b56e8cf745..a05375a3338a 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -246,6 +246,36 @@ static inline enum mei_pg_state mei_me_pg_state(struct 
mei_device *dev)
return hw->pg_state;
 }
 
+static inline u32 me_intr_src(u32 hcsr)
+{
+   return hcsr & H_CSR_IS_MASK;
+}
+
+/**
+ * me_intr_disable - disables mei device interrupts
+ *  using supplied hcsr register value.
+ *
+ * @dev: the device structure
+ * @hcsr: supplied hcsr register value
+ */
+static inline void me_intr_disable(struct mei_device *dev, u32 hcsr)
+{
+   hcsr &= ~H_CSR_IE_MASK;
+   mei_hcsr_set(dev, hcsr);
+}
+
+/**
+ * mei_me_intr_clear - clear and stop interrupts
+ *
+ * @dev: the device structure
+ * @hcsr: supplied hcsr register value
+ */
+static inline void me_intr_clear(struct mei_device *dev, u32 hcsr)
+{
+   if (me_intr_src(hcsr))
+   mei_hcsr_write(dev, hcsr);
+}
+
 /**
  * mei_me_intr_clear - clear and stop interrupts
  *
@@ -255,8 +285,7 @@ static void mei_me_intr_clear(struct mei_device *dev)
 {
u32 hcsr = mei_hcsr_read(dev);
 
-   if (hcsr & H_CSR_IS_MASK)
-   mei_hcsr_write(dev, hcsr);
+   me_intr_clear(dev, hcsr);
 }
 /**
  * mei_me_intr_enable - enables mei device interrupts
@@ -280,8 +309,7 @@ static void mei_me_intr_disable(struct mei_device *dev)
 {
u32 hcsr = mei_hcsr_read(dev);
 
-   hcsr  &= ~H_CSR_IE_MASK;
-   mei_hcsr_set(dev, hcsr);
+   me_intr_disable(dev, hcsr);
 }
 
 /**
@@ -968,13 +996,14 @@ static void mei_me_pg_legacy_intr(struct mei_device *dev)
  * mei_me_d0i3_intr - perform d0i3 processing in interrupt thread handler
  *
  * @dev: the device structure
+ * @intr_source: interrupt source
  */
-static void mei_me_d0i3_intr(struct mei_device *dev)
+static void mei_me_d0i3_intr(struct mei_device *dev, u32 intr_source)
 {
struct mei_me_hw *hw = to_me_hw(dev);
 
if (dev->pg_event == MEI_PG_EVENT_INTR_WAIT &&
-   (hw->intr_source & H_D0I3C_IS)) {
+   (intr_source & H_D0I3C_IS)) {
dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED;
if (hw->pg_state == MEI_PG_ON) {
hw->pg_state = MEI_PG_OFF;
@@ -993,7 +1022,7 @@ static void mei_me_d0i3_intr(struct mei_device *dev)
wake_up(&dev->wait_pg);
}
 
-   if (hw->pg_state == MEI_PG_ON && (hw->intr_source & H_IS)) {
+   if (hw->pg_state == MEI_PG_ON && (intr_source & H_IS)) {
/*
 * HW sent some data and we are in D0i3, so
 * we got here because of HW initiated exit from D0i3.
@@ -1008,13 +1037,14 @@ static void mei_me_d0i3_intr(struct mei_device *dev)
  * mei_me_pg_intr - perform pg processing in interrupt thread handler
  *
  * @dev: the device structure
+ * @intr_source: interrupt source
  */
-static void mei_me_pg_intr(struct mei_device *dev)
+static void mei_me_pg_intr(struct mei_device *dev, u32 intr_source)
 {
struct mei_me_hw *hw = to_me_hw(dev);
 
if (hw->d0i3_supported)
-   mei_me_d0i3_intr(dev);
+   mei_me_d0i3_intr(dev, intr_source);
else
mei_me_pg_legacy_intr(dev);
 }
@@ -1133,19 +1163,16 @@ static int mei_me_hw_reset(struct mei_device *dev, bool 
intr_enable)
 irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id)
 {
struct mei_device *dev = (struct mei_device *)dev_id;
-   struct mei_me_hw *hw = to_me_hw(dev);
u32 hcsr;
 
hcsr = mei_hcsr_read(dev);
-   if (!(hcsr & H_CSR_IS_MASK))
+   if (!me_intr_src(hcsr))
return IRQ_NONE;
 
-   hw->intr_source = hcsr & H_CSR_IS_MASK;
-   dev_dbg(dev->dev, "interrupt source 0x%08X.\n", hw->intr_source);
-
-   /* clear H_IS and H_D0I3C_IS bits in H_CSR to clear the interrupts */
-   mei_hcsr_write(dev, hcsr);
+   dev_dbg(dev->dev, "interrupt source 0x%08X\n", me_intr_src(hcsr));
 
+   /* disable interrupts on device */
+   me_intr_disable(dev, hcsr);
return IRQ_WAKE_THREAD;
 }
 
@@ -1164,11 +1191,16 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void 
*dev_id)
struct mei_device *dev = (struct mei_device *) dev_id;
struct mei_cl_cb complete_list;
 

drivers/gpu/drm/i915/i915_gem_gtt.c:2367: error: 'gtt_entry' may be used uninitialized in this function

2016-12-04 Thread kbuild test robot
Hi Dave,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   0cb65c83304a341b9d09678448d7c8b550689531
commit: 85d1225ec066b2ef46fbd0ed1bae78ae1f3e6c91 drm/i915: Introduce & use new 
lightweight SGL iterators
date:   7 months ago
config: x86_64-randconfig-s1-12041908 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
reproduce:
git checkout 85d1225ec066b2ef46fbd0ed1bae78ae1f3e6c91
# save the attached .config to linux build tree
make ARCH=x86_64 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All errors (new ones prefixed by >>):

   cc1: warnings being treated as errors
   drivers/gpu/drm/i915/i915_gem_gtt.c: In function 'gen8_ggtt_insert_entries':
>> drivers/gpu/drm/i915/i915_gem_gtt.c:2367: error: 'gtt_entry' may be used 
>> uninitialized in this function
   drivers/gpu/drm/i915/i915_gem_gtt.c: In function 'gen6_ggtt_insert_entries':
   drivers/gpu/drm/i915/i915_gem_gtt.c:2442: error: 'gtt_entry' may be used 
uninitialized in this function

vim +/gtt_entry +2367 drivers/gpu/drm/i915/i915_gem_gtt.c

  2361   enum i915_cache_level level, u32 
unused)
  2362  {
  2363  struct drm_i915_private *dev_priv = to_i915(vm->dev);
  2364  struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
  2365  struct sgt_iter sgt_iter;
  2366  gen8_pte_t __iomem *gtt_entries;
> 2367  gen8_pte_t gtt_entry;
  2368  dma_addr_t addr;
  2369  int rpm_atomic_seq;
  2370  int i = 0;

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


cc1: error: unrecognized command line option "-Wno-maybe-uninitialized"

2016-12-04 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   0cb65c83304a341b9d09678448d7c8b550689531
commit: a76bcf557ef408b368cf26f52a60865bfc27b632 Kbuild: enable 
-Wmaybe-uninitialized warning for "make W=1"
date:   3 weeks ago
config: x86_64-randconfig-s2-12042007 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
reproduce:
git checkout a76bcf557ef408b368cf26f52a60865bfc27b632
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   cc1: warnings being treated as errors
   drivers/gpu/drm/i915/i915_gem_gtt.c: In function 'gen8_ggtt_insert_entries':
   drivers/gpu/drm/i915/i915_gem_gtt.c:2341: error: 'gtt_entry' may be used 
uninitialized in this function
   drivers/gpu/drm/i915/i915_gem_gtt.c: In function 'gen6_ggtt_insert_entries':
   drivers/gpu/drm/i915/i915_gem_gtt.c:2438: error: 'gtt_entry' may be used 
uninitialized in this function
   At top level:
>> cc1: error: unrecognized command line option "-Wno-maybe-uninitialized"
--
   cc1: warnings being treated as errors
   drivers/gpu/drm/i915/i915_gem.c: In function 'i915_gem_object_map':
   drivers/gpu/drm/i915/i915_gem.c:2382: error: 'pgprot.pgprot' may be used 
uninitialized in this function
   At top level:
>> cc1: error: unrecognized command line option "-Wno-maybe-uninitialized"
--
   cc1: warnings being treated as errors
   drivers/gpu/drm/i915/i915_gem_render_state.c: In function 
'i915_gem_render_state_init':
   drivers/gpu/drm/i915/i915_gem_render_state.c:176: error: 
'so.aux_batch_offset' may be used uninitialized in this function
   drivers/gpu/drm/i915/i915_gem_render_state.c:176: error: 'so.aux_batch_size' 
may be used uninitialized in this function
   At top level:
>> cc1: error: unrecognized command line option "-Wno-maybe-uninitialized"
--
   cc1: warnings being treated as errors
   drivers/gpu/drm/i915/intel_sprite.c: In function 'intel_check_sprite_plane':
   drivers/gpu/drm/i915/intel_sprite.c:763: error: 'src_x' may be used 
uninitialized in this function
   drivers/gpu/drm/i915/intel_sprite.c:763: error: 'src_y' may be used 
uninitialized in this function
   drivers/gpu/drm/i915/intel_sprite.c:763: error: 'src_w' may be used 
uninitialized in this function
   drivers/gpu/drm/i915/intel_sprite.c:763: error: 'src_h' may be used 
uninitialized in this function
   At top level:
>> cc1: error: unrecognized command line option "-Wno-maybe-uninitialized"
--
   cc1: warnings being treated as errors
   drivers/gpu/drm/i915/intel_tv.c: In function 'intel_tv_detect':
   drivers/gpu/drm/i915/intel_tv.c:1315: error: 'type' may be used 
uninitialized in this function
   At top level:
>> cc1: error: unrecognized command line option "-Wno-maybe-uninitialized"

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


usb:xhci: support disable usb2 LPM Remote Wakeup

2016-12-04 Thread Thang Q. Nguyen
From: Thang Nguyen 

As per USB 2.0 link power management addendum ECN, table 1-2, page 4,
device or host initiated via resume signaling; device-initiated resumes
can be optionally enabled/disabled by software. This patch adds support
to control enabling the USB2 RWE feature via DT/ACPI attribute.

Signed-off-by: Vu Nguyen 
Signed-off-by: Thang Nguyen 
---
 Documentation/devicetree/bindings/usb/usb-xhci.txt | 1 +
 drivers/usb/host/xhci-plat.c   | 3 +++
 drivers/usb/host/xhci.c| 5 -
 drivers/usb/host/xhci.h| 1 +
 4 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt 
b/Documentation/devicetree/bindings/usb/usb-xhci.txt
index 966885c..9b4cd14 100644
--- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
@@ -25,6 +25,7 @@ Required properties:
 
 Optional properties:
   - clocks: reference to a clock
+  - usb2-rwe-disable: disable USB2 LPM Remote Wakeup capable
   - usb3-lpm-capable: determines if platform is USB3 LPM capable
 
 Example:
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index ed56bf9..15c540d 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -220,6 +220,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
goto disable_clk;
}
 
+   if (device_property_read_bool(&pdev->dev, "usb2-rwe-disable"))
+   xhci->quirks |= XHCI_RWE_DISABLE;
+
if (device_property_read_bool(&pdev->dev, "usb3-lpm-capable"))
xhci->quirks |= XHCI_LPM_SUPPORT;
 
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 1a4ca02..f804868 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4183,7 +4183,10 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
}
 
pm_val &= ~PORT_HIRD_MASK;
-   pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id);
+   if ((xhci->quirks & XHCI_RWE_DISABLE) && (xhci->hci_version <= 
0x100))
+   pm_val |= PORT_HIRD(hird) | PORT_L1DS(udev->slot_id);
+   else
+   pm_val |= PORT_HIRD(hird) | PORT_RWE | 
PORT_L1DS(udev->slot_id);
writel(pm_val, pm_addr);
pm_val = readl(pm_addr);
pm_val |= PORT_HLE;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index f945380..2b9bc33 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1656,6 +1656,7 @@ struct xhci_hcd {
 #define XHCI_SSIC_PORT_UNUSED  (1 << 22)
 #define XHCI_NO_64BIT_SUPPORT  (1 << 23)
 #define XHCI_MISSING_CAS   (1 << 24)
+#define XHCI_RWE_DISABLE   (1 << 25)
unsigned intnum_active_eps;
unsigned intlimit_active_eps;
/* There are two roothubs to keep track of bus suspend info for */
-- 
2.7.4



[PATCHv2] zram: restrict add/remove attributes to root only

2016-12-04 Thread Sergey Senozhatsky
zram hot_add sysfs attribute is a very 'special' attribute - reading
from it creates a new uninitialized zram device. This file, by a mistake,
can be read by a 'normal' user at the moment, while only root must be
able to create a new zram device, therefore hot_add attribute must have
S_IRUSR mode, not S_IRUGO.

Fixes: 6566d1a32bf72 ("zram: add dynamic device add/remove functionality")
Reported-by: Steven Allen 
Cc: [4.2+]
Signed-off-by: Sergey Senozhatsky 
---
 drivers/block/zram/zram_drv.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 5163c8f..3a0576f 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1413,9 +1413,16 @@ static ssize_t hot_remove_store(struct class *class,
return ret ? ret : count;
 }
 
+/*
+ * NOTE: hot_add attribute is not the usual read-only sysfs
+ * attribute. In a sence that reading from this file does alter
+ * the state of your system -- it creates a new un-initialized
+ * zram device and returns back this device's device_id (or an
+ * error code if it fails to create a new device).
+ */
 static struct class_attribute zram_control_class_attrs[] = {
-   __ATTR_RO(hot_add),
-   __ATTR_WO(hot_remove),
+   __ATTR(hot_add, 0400, hot_add_show, NULL),
+   __ATTR(hot_remove, 0200, NULL, hot_remove_store),
__ATTR_NULL,
 };
 
-- 
2.10.2



[PATCH 1/1 linux-next] sunrpc: use DEFINE_SPINLOCK()

2016-12-04 Thread Fabian Frederick
Signed-off-by: Fabian Frederick 
---
 net/sunrpc/svcauth.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/sunrpc/svcauth.c b/net/sunrpc/svcauth.c
index 69841db..e112da8 100644
--- a/net/sunrpc/svcauth.c
+++ b/net/sunrpc/svcauth.c
@@ -124,8 +124,7 @@ EXPORT_SYMBOL_GPL(svc_auth_unregister);
 #defineDN_HASHMAX  (1<

[PATCH 1/1 linux-next] soc/qman: test: use DEFINE_SPINLOCK()

2016-12-04 Thread Fabian Frederick
Signed-off-by: Fabian Frederick 
---
 drivers/soc/fsl/qbman/qman_test_stash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/qbman/qman_test_stash.c 
b/drivers/soc/fsl/qbman/qman_test_stash.c
index b9795f3..e87b654 100644
--- a/drivers/soc/fsl/qbman/qman_test_stash.c
+++ b/drivers/soc/fsl/qbman/qman_test_stash.c
@@ -175,7 +175,7 @@ static DEFINE_PER_CPU(struct hp_cpu, hp_cpus);
 
 /* links together the hp_cpu structs, in first-come first-serve order. */
 static LIST_HEAD(hp_cpu_list);
-static spinlock_t hp_lock = __SPIN_LOCK_UNLOCKED(hp_lock);
+static DEFINE_SPINLOCK(hp_lock);
 
 static unsigned int hp_cpu_list_length;
 
-- 
2.7.4



[PATCH 1/1 linux-next] powerpc/fsl-lbc: use DEFINE_SPINLOCK()

2016-12-04 Thread Fabian Frederick
Signed-off-by: Fabian Frederick 
---
 arch/powerpc/sysdev/fsl_lbc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/sysdev/fsl_lbc.c b/arch/powerpc/sysdev/fsl_lbc.c
index 424b67f..5340a48 100644
--- a/arch/powerpc/sysdev/fsl_lbc.c
+++ b/arch/powerpc/sysdev/fsl_lbc.c
@@ -31,7 +31,7 @@
 #include 
 #include 
 
-static spinlock_t fsl_lbc_lock = __SPIN_LOCK_UNLOCKED(fsl_lbc_lock);
+static DEFINE_SPINLOCK(fsl_lbc_lock);
 struct fsl_lbc_ctrl *fsl_lbc_ctrl_dev;
 EXPORT_SYMBOL(fsl_lbc_ctrl_dev);
 
-- 
2.7.4



Re: [PATCH] Input: mouse: synaptics - change msleep to usleep_range for small msecs

2016-12-04 Thread Aniroop Mathur
Hello Mr. Igor Grinberg

On Sun, Dec 4, 2016 at 1:32 PM, Igor Grinberg  wrote:
> Hi Aniroop Mathur,
>
> On 11/29/16 23:02, Aniroop Mathur wrote:
>> Dear Mike Rapoport, Igor Grinberg,
>> Greetings!
>>
>> I am Aniroop Mathur from Samsung R&D Institute, India.
>>
>> I have submitted one patch as below for review to Linux Open Source.
>> The problem is that we do not have the hardware available with us to
>> test it and we would like to test it before actually applying it.
>> As you are the author of this driver, I am contacting you to request you
>> provide your feedback upon this patch.
>>
>> Also if you have the hardware available, could you please help to
>> test this patch on your hardware? or could you provide contact points
>> of individuals who could support to test it?
>
> This touchpad and the driver was used on an old PXA270 based PDA.
> I currently don't have those at hand to test the patch.
>
>>
>> Thank you!
>>
>> BR,
>> Aniroop Mathur
>>
>> On Tue, Nov 29, 2016 at 1:25 AM, Aniroop Mathur  wrote:
>>> msleep(1~20) may not do what the caller intends, and will often sleep 
>>> longer.
>>> (~20 ms actual sleep for any value given in the 1~20ms range)
>
> Well, it should be at least 1ms as stated in my comment just before the 
> define.
> So, from the correctness perspective larger values will also do the job.
> Additionally, since I've taken a spare 2ms, and you are making it even more
> precise (3000us + 100us) - it will still do the job and stay correct.
> So, there should be no issue from correctness POV.
>

Alright, Thanks!

>>> This is not the desired behaviour for many cases like device resume time,
>>> device suspend time, device enable time, retry logic, etc.
>>> Thus, change msleep to usleep_range for precise wakeups.
>
> This is a human interface touchpad device, even having 20ms soft reset
> sleep time will not impact the responsiveness for humans.
> IMHO, there is no need for precise wakeups for this device, so I wouldn't
> bother.
>

Well, from the point of view of device working and responsiveness for "humans",
I agree that it is okay to sleep for 20 / 40 ms or even 100 ms. However, this
patch is not trying to solve any such issues. This patch is only trying to make
the process sleep for appropriate time as mentioned in the parameter and does
not cause any harm here. I could see that this function is called during device
resume and device probe time. So this change will improve the resume and probe
time for this device and doing the same change in other drivers will
contribute to
improvement in overall kernel resume and boot time a little bit so response time
increases a little bit. Plus, it is recommended and mentioned in kernel
documentation to use usleep_range for delays between 1-10 ms.
So usleep_range should serve better here.
Explained originally here to why not use msleep for 1 - 20 ms:
http://lkml.org/lkml/2007/8/3/250

Thanks.

BR,
Aniroop Mathur

>>>
>>> Signed-off-by: Aniroop Mathur 
>>> ---
>>>  drivers/input/mouse/synaptics_i2c.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/input/mouse/synaptics_i2c.c 
>>> b/drivers/input/mouse/synaptics_i2c.c
>>> index aa7c5da..4d688a6 100644
>>> --- a/drivers/input/mouse/synaptics_i2c.c
>>> +++ b/drivers/input/mouse/synaptics_i2c.c
>>> @@ -29,7 +29,7 @@
>>>   * after soft reset, we should wait for 1 ms
>>>   * before the device becomes operational
>>>   */
>>> -#define SOFT_RESET_DELAY_MS3
>>> +#define SOFT_RESET_DELAY_US3000
>>>  /* and after hard reset, we should wait for max 500ms */
>>>  #define HARD_RESET_DELAY_MS500
>>>
>>> @@ -311,7 +311,7 @@ static int synaptics_i2c_reset_config(struct i2c_client 
>>> *client)
>>> if (ret) {
>>> dev_err(&client->dev, "Unable to reset device\n");
>>> } else {
>>> -   msleep(SOFT_RESET_DELAY_MS);
>>> +   usleep_range(SOFT_RESET_DELAY_US, SOFT_RESET_DELAY_US + 
>>> 100);
>>> ret = synaptics_i2c_config(client);
>>> if (ret)
>>> dev_err(&client->dev, "Unable to config device\n");
>>> --
>>> 2.6.2
>>>
>>
>
> --
> Regards,
> Igor.


Re: [PATCH] zram: restrict add/remove attributes to root only

2016-12-04 Thread Sergey Senozhatsky
On (12/04/16 12:28), Greg KH wrote:
> > [..]
> > 
> > > Why can't a normal user read the attribute?  Does a read actually modify
> > > something?
> > 
> > yes, it does.
> 
> Oh that's totally and completely broken then.
> 
> Reading from a sysfs file should NEVER cause side affects to the system.
> Please fix up this api.

we have a mechanism for such API changes -- there is a bunch of deprecated
sysfs attrs that we will remove in 4.11; so I'll mark hot_add/hot_remove
as deprecated and switch to char device (as you suggested). thanks.

-ss


Re: Enabling peer to peer device transactions for PCIe devices

2016-12-04 Thread Stephen Bates
>>
>> The NVMe fabrics stuff could probably make use of this. It's an
>> in-kernel system to allow remote access to an NVMe device over RDMA. So
>> they ought to be able to optimize their transfers by DMAing directly to
>>  the NVMe's CMB -- no userspace interface would be required but there
>> would need some kernel infrastructure.
>
> Yes, that's what I was thinking. The NVMe/f driver needs to map the CMB
> for RDMA. I guess if it used ZONE_DEVICE like in the iopmem patches it
> would be relatively easy to do.
>

Haggai, yes that was one of the use cases we considered when we put
together the patchset.



[PATCH] dts: sun8i-h3: correct UART3 pin definitions

2016-12-04 Thread jorik
From: Jorik Jonker 

In a previous commit, I made a copy/paste error in the pinmux
definitions of UART3: PG{13,14} instead of PA{13,14}. This commit takes
care of that. I have tested this commit on Orange Pi PC and Orange Pi
Plus, and it works for these boards.

Fixes: e3d11d3c45c5 ("dts: sun8i-h3: add pinmux definitions for
UART2-3")

Signed-off-by: Jorik Jonker 
---
 arch/arm/boot/dts/sun8i-h3.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/sun8i-h3.dtsi b/arch/arm/boot/dts/sun8i-h3.dtsi
index 75a8654..f4ba088 100644
--- a/arch/arm/boot/dts/sun8i-h3.dtsi
+++ b/arch/arm/boot/dts/sun8i-h3.dtsi
@@ -410,7 +410,7 @@
};
 
uart3_pins: uart3 {
-   allwinner,pins = "PG13", "PG14";
+   allwinner,pins = "PA13", "PA14";
allwinner,function = "uart3";
allwinner,drive = ;
allwinner,pull = ;
-- 
2.9.3



RE: [PATCH kernel v5 5/5] virtio-balloon: tell host vm's unused page info

2016-12-04 Thread Li, Liang Z
> On 11/30/2016 12:43 AM, Liang Li wrote:
> > +static void send_unused_pages_info(struct virtio_balloon *vb,
> > +   unsigned long req_id)
> > +{
> > +   struct scatterlist sg_in;
> > +   unsigned long pos = 0;
> > +   struct virtqueue *vq = vb->req_vq;
> > +   struct virtio_balloon_resp_hdr *hdr = vb->resp_hdr;
> > +   int ret, order;
> > +
> > +   mutex_lock(&vb->balloon_lock);
> > +
> > +   for (order = MAX_ORDER - 1; order >= 0; order--) {
> 
> I scratched my head for a bit on this one.  Why are you walking over orders,
> *then* zones.  I *think* you're doing it because you can efficiently fill the
> bitmaps at a given order for all zones, then move to a new bitmap.  But, it
> would be interesting to document this.
> 

Yes, use the order is somewhat strange, but it's helpful to keep the API 
simple. 
Do you think it's acceptable?

> > +   pos = 0;
> > +   ret = get_unused_pages(vb->resp_data,
> > +vb->resp_buf_size / sizeof(unsigned long),
> > +order, &pos);
> 
> FWIW, get_unsued_pages() is a pretty bad name.  "get" usually implies
> bumping reference counts or consuming something.  You're just "recording"
> or "marking" them.
> 

Will change to mark_unused_pages().

> > +   if (ret == -ENOSPC) {
> > +   void *new_resp_data;
> > +
> > +   new_resp_data = kmalloc(2 * vb->resp_buf_size,
> > +   GFP_KERNEL);
> > +   if (new_resp_data) {
> > +   kfree(vb->resp_data);
> > +   vb->resp_data = new_resp_data;
> > +   vb->resp_buf_size *= 2;
> 
> What happens to the data in ->resp_data at this point?  Doesn't this just
> throw it away?
> 

Yes, so we should make sure the data in resp_data is not inuse.

> ...
> > +struct page_info_item {
> > +   __le64 start_pfn : 52; /* start pfn for the bitmap */
> > +   __le64 page_shift : 6; /* page shift width, in bytes */
> > +   __le64 bmap_len : 6;  /* bitmap length, in bytes */ };
> 
> Is 'bmap_len' too short?  a 64-byte buffer is a bit tiny.  Right?
> 

Currently, we just use the 8 bytes and 0 bytes bitmap, should we support more 
than 64 bytes?

> > +static int  mark_unused_pages(struct zone *zone,
> > +   unsigned long *unused_pages, unsigned long size,
> > +   int order, unsigned long *pos)
> > +{
> > +   unsigned long pfn, flags;
> > +   unsigned int t;
> > +   struct list_head *curr;
> > +   struct page_info_item *info;
> > +
> > +   if (zone_is_empty(zone))
> > +   return 0;
> > +
> > +   spin_lock_irqsave(&zone->lock, flags);
> > +
> > +   if (*pos + zone->free_area[order].nr_free > size)
> > +   return -ENOSPC;
> 
> Urg, so this won't partially fill?  So, what the nr_free pages limit where we 
> no
> longer fit in the kmalloc()'d buffer where this simply won't work?
> 

Yes.  My initial implementation is partially fill, it's better for the worst 
case.
I thought the above code is more efficient for most case ...
Do you think partially fill the bitmap is better?
 
> > +   for (t = 0; t < MIGRATE_TYPES; t++) {
> > +   list_for_each(curr, &zone->free_area[order].free_list[t]) {
> > +   pfn = page_to_pfn(list_entry(curr, struct page, lru));
> > +   info = (struct page_info_item *)(unused_pages +
> *pos);
> > +   info->start_pfn = pfn;
> > +   info->page_shift = order + PAGE_SHIFT;
> > +   *pos += 1;
> > +   }
> > +   }
> 
> Do we need to fill in ->bmap_len here?

For integrity, the bmap_len should be filled, will add.
Omit this step just because QEMU assume the ->bmp_len is 0 and ignore this 
field.

Thanks for your comment!

Liang


[PATCH V2 net 06/20] net/ena: fix NULL dereference when removing the driver after device reset faild

2016-12-04 Thread Netanel Belgazal
If for some reason the device stop responding and the device reset failed
to recover the device, the mmio register read datastructure will not be
reinitialized.
On driver removal, the driver will also tries to reset the device
but this time the mmio data structure will be NULL.

To solve this issue perform the device reset in the remove function only if
the device is runnig.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 224302c..ad5f78f 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2516,6 +2516,8 @@ static void ena_fw_reset_device(struct work_struct *work)
 err:
rtnl_unlock();
 
+   clear_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags);
+
dev_err(&pdev->dev,
"Reset attempt failed. Can not reset the device\n");
 }
@@ -3126,7 +3128,9 @@ static void ena_remove(struct pci_dev *pdev)
 
cancel_work_sync(&adapter->resume_io_task);
 
-   ena_com_dev_reset(ena_dev);
+   /* Reset the device only if the device is running. */
+   if (test_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags))
+   ena_com_dev_reset(ena_dev);
 
ena_free_mgmnt_irq(adapter);
 
-- 
2.7.4



[PATCH V2 net 04/20] net/ena: fix ethtool RSS flow configuration

2016-12-04 Thread Netanel Belgazal
ena_flow_data_to_flow_hash and ena_flow_hash_to_flow_type
treat the ena_flow_hash_to_flow_type enum as power of two values.

Change the values of ena_admin_flow_hash_fields to be power of two values.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_admin_defs.h | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h 
b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
index a46e749..f48c886 100644
--- a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
+++ b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
@@ -631,22 +631,22 @@ enum ena_admin_flow_hash_proto {
 /* RSS flow hash fields */
 enum ena_admin_flow_hash_fields {
/* Ethernet Dest Addr */
-   ENA_ADMIN_RSS_L2_DA = 0,
+   ENA_ADMIN_RSS_L2_DA = 0x1,
 
/* Ethernet Src Addr */
-   ENA_ADMIN_RSS_L2_SA = 1,
+   ENA_ADMIN_RSS_L2_SA = 0x2,
 
/* ipv4/6 Dest Addr */
-   ENA_ADMIN_RSS_L3_DA = 2,
+   ENA_ADMIN_RSS_L3_DA = 0x4,
 
/* ipv4/6 Src Addr */
-   ENA_ADMIN_RSS_L3_SA = 5,
+   ENA_ADMIN_RSS_L3_SA = 0x8,
 
/* tcp/udp Dest Port */
-   ENA_ADMIN_RSS_L4_DP = 6,
+   ENA_ADMIN_RSS_L4_DP = 0x10,
 
/* tcp/udp Src Port */
-   ENA_ADMIN_RSS_L4_SP = 7,
+   ENA_ADMIN_RSS_L4_SP = 0x20,
 };
 
 struct ena_admin_proto_input {
-- 
2.7.4



[PATCH V2 net 00/20] Increase ENA driver version to 1.1.2

2016-12-04 Thread Netanel Belgazal
Changes between V1 and V2:
* reorder the patches so the bug fixes will appear first.
* fix the commit message of removing a tuple filter. The first patch
stated mistakenly that it removes RFS.
* add another bug fix (fix RSS default hash configuration).
* split the driver's version increase to a dedicated patch.
* add this patchset description.

This patchset contains mainly bug fixes.
Most of them are critical for the driver and system functionality.
In addition to the bug fixes, this patchset also introduces some minor
Improvements listed below.

Bug fixes:
net/ena: remove ntuple filter support from device feature list
net/ena: fix error handling when probe fails
net/ena: fix queues number calculation
net/ena: fix ethtool RSS flow configuration
net/ena: fix RSS default hash configuration
net/ena: fix NULL dereference when removing the driver after device
reset faild
net/ena: refactor ena_get_stats64 to be atomic context safe
net/ena: add hardware hints capability to the driver
net/ena: fix potential access to freed memory during device reset
net/ena: remove redundant logic in napi callback for busy poll mode
net/ena: use READ_ONCE to access completion descriptors
net/ena: reduce the severity of ena printouts
net/ena: change driver's default timeouts
net/ena: change condition for host attribute configuration
net/ena: change sizeof() argument to be the type pointer

Other improvments:
net/ena: change sizeof() argument to be the type pointer
net/ena: use napi_schedule_irqoff when possible
net/ena: add IPv6 extended protocols to ena_admin_flow_hash_proto
net/ena: remove affinity hint from the driver
net/ena: restructure skb allocation
net/ena: increase driver version to 1.1.2

Netanel Belgazal (20):
  net/ena: remove ntuple filter support from device feature list
  net/ena: fix error handling when probe fails
  net/ena: fix queues number calculation
  net/ena: fix ethtool RSS flow configuration
  net/ena: fix RSS default hash configuration
  net/ena: fix NULL dereference when removing the driver after device
reset faild
  net/ena: refactor ena_get_stats64 to be atomic context safe
  net/ena: add hardware hints capability to the driver
  net/ena: fix potential access to freed memory during device reset
  net/ena: remove redundant logic in napi callback for busy poll mode
  net/ena: use READ_ONCE to access completion descriptors
  net/ena: reduce the severity of ena printouts
  net/ena: change driver's default timeouts
  net/ena: change condition for host attribute configuration
  net/ena: change sizeof() argument to be the type pointer
  net/ena: use napi_schedule_irqoff when possible
  net/ena: add IPv6 extended protocols to ena_admin_flow_hash_proto
  net/ena: remove affinity hint from the driver
  net/ena: restructure skb allocation
  net/ena: increase driver version to 1.1.2

 drivers/net/ethernet/amazon/ena/ena_admin_defs.h |  57 +++-
 drivers/net/ethernet/amazon/ena/ena_com.c|  98 ---
 drivers/net/ethernet/amazon/ena/ena_com.h|   6 +
 drivers/net/ethernet/amazon/ena/ena_eth_com.c|   8 +-
 drivers/net/ethernet/amazon/ena/ena_ethtool.c|   1 -
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 326 ---
 drivers/net/ethernet/amazon/ena/ena_netdev.h |  30 ++-
 drivers/net/ethernet/amazon/ena/ena_regs_defs.h  |   2 +
 8 files changed, 385 insertions(+), 143 deletions(-)

-- 
2.7.4



[PATCH V2 net 19/20] net/ena: restructure skb allocation

2016-12-04 Thread Netanel Belgazal
To increase readability, refactor skb allocation to dedicated function
This change does not impact the performance since the compiler optimize
the code and elimitate the if condition.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 46 
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index ee80472..8d42960 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -787,6 +787,28 @@ static int ena_clean_tx_irq(struct ena_ring *tx_ring, u32 
budget)
return tx_pkts;
 }
 
+static struct sk_buff *ena_alloc_skb(struct ena_ring *rx_ring, bool frags)
+{
+   struct sk_buff *skb;
+
+   if (frags)
+   skb = napi_get_frags(rx_ring->napi);
+   else
+   skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
+   rx_ring->rx_copybreak);
+
+   if (unlikely(!skb)) {
+   u64_stats_update_begin(&rx_ring->syncp);
+   rx_ring->rx_stats.skb_alloc_fail++;
+   u64_stats_update_end(&rx_ring->syncp);
+   netif_err(rx_ring->adapter, rx_err, rx_ring->netdev,
+ "Failed to allocate skb. frags: %d\n", frags);
+   return NULL;
+   }
+
+   return skb;
+}
+
 static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
  struct ena_com_rx_buf_info *ena_bufs,
  u32 descs,
@@ -795,8 +817,7 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
struct sk_buff *skb;
struct ena_rx_buffer *rx_info =
&rx_ring->rx_buffer_info[*next_to_clean];
-   u32 len;
-   u32 buf = 0;
+   u32 len, buf = 0;
void *va;
 
len = ena_bufs[0].len;
@@ -815,16 +836,9 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
prefetch(va + NET_IP_ALIGN);
 
if (len <= rx_ring->rx_copybreak) {
-   skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
-   rx_ring->rx_copybreak);
-   if (unlikely(!skb)) {
-   u64_stats_update_begin(&rx_ring->syncp);
-   rx_ring->rx_stats.skb_alloc_fail++;
-   u64_stats_update_end(&rx_ring->syncp);
-   netif_err(rx_ring->adapter, rx_err, rx_ring->netdev,
- "Failed to allocate skb\n");
+   skb = ena_alloc_skb(rx_ring, false);
+   if (unlikely(!skb))
return NULL;
-   }
 
netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
  "rx allocated small packet. len %d. data_len %d\n",
@@ -848,15 +862,9 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
return skb;
}
 
-   skb = napi_get_frags(rx_ring->napi);
-   if (unlikely(!skb)) {
-   netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
- "Failed allocating skb\n");
-   u64_stats_update_begin(&rx_ring->syncp);
-   rx_ring->rx_stats.skb_alloc_fail++;
-   u64_stats_update_end(&rx_ring->syncp);
+   skb = ena_alloc_skb(rx_ring, true);
+   if (unlikely(!skb))
return NULL;
-   }
 
do {
dma_unmap_page(rx_ring->dev,
-- 
2.7.4



[PATCH V2 net 20/20] net/ena: increase driver version to 1.1.2

2016-12-04 Thread Netanel Belgazal
Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h 
b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index ed42e07..de1e5ac 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -45,7 +45,7 @@
 #include "ena_eth_com.h"
 
 #define DRV_MODULE_VER_MAJOR   1
-#define DRV_MODULE_VER_MINOR   0
+#define DRV_MODULE_VER_MINOR   1
 #define DRV_MODULE_VER_SUBMINOR 2
 
 #define DRV_MODULE_NAME"ena"
-- 
2.7.4



[PATCH V2 net 10/20] net/ena: remove redundant logic in napi callback for busy poll mode

2016-12-04 Thread Netanel Belgazal
sk_busy_loop can call the napi callback few million times a sec.
For each call there is unmask interrupt.
We want to reduce the number of unmasks.

Add an atomic variable that will tell the napi handler if
it was called from irq context or not.
Unmask the interrupt only from irq context.

A schenario where the driver left with missed unmask isn't feasible.
when ena_intr_msix_io is called the driver have 2 options:
1)Before napi completes and call napi_complete_done
2)After calling napi_complete_done

In the former case the napi will unmask the interrupt as needed.
In the latter case napi_complete_done will remove napi from the schedule
list so napi will be rescheduled (by ena_intr_msix_io) and interrupt
will be unmasked as desire in the 2nd napi call.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 46 +++-
 drivers/net/ethernet/amazon/ena/ena_netdev.h |  1 +
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index bb7eeea..5625007 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -1129,26 +1129,41 @@ static int ena_io_poll(struct napi_struct *napi, int 
budget)
tx_work_done = ena_clean_tx_irq(tx_ring, tx_budget);
rx_work_done = ena_clean_rx_irq(rx_ring, napi, budget);
 
-   if ((budget > rx_work_done) && (tx_budget > tx_work_done)) {
+   /* If the device is about to reset or down, avoid unmask
+* the interrupt and return 0 so NAPI won't reschedule
+*/
+   if (unlikely(!test_bit(ENA_FLAG_DEV_UP, &tx_ring->adapter->flags) ||
+test_bit(ENA_FLAG_TRIGGER_RESET, 
&tx_ring->adapter->flags))) {
+   napi_complete_done(napi, 0);
+   ret = 0;
+
+   } else if ((budget > rx_work_done) && (tx_budget > tx_work_done)) {
napi_complete_done(napi, rx_work_done);
 
napi_comp_call = 1;
-   /* Tx and Rx share the same interrupt vector */
-   if (ena_com_get_adaptive_moderation_enabled(rx_ring->ena_dev))
-   ena_adjust_intr_moderation(rx_ring, tx_ring);
-
-   /* Update intr register: rx intr delay, tx intr delay and
-* interrupt unmask
+   /* Update numa and unmask the interrupt only when schedule
+* from the interrupt context (vs from sk_busy_loop)
 */
-   ena_com_update_intr_reg(&intr_reg,
-   rx_ring->smoothed_interval,
-   tx_ring->smoothed_interval,
-   true);
+   if (atomic_cmpxchg(&ena_napi->unmask_interrupt, 1, 0)) {
+   /* Tx and Rx share the same interrupt vector */
+   if 
(ena_com_get_adaptive_moderation_enabled(rx_ring->ena_dev))
+   ena_adjust_intr_moderation(rx_ring, tx_ring);
+
+   /* Update intr register: rx intr delay,
+* tx intr delay and interrupt unmask
+*/
+   ena_com_update_intr_reg(&intr_reg,
+   rx_ring->smoothed_interval,
+   tx_ring->smoothed_interval,
+   true);
+
+   /* It is a shared MSI-X.
+* Tx and Rx CQ have pointer to it.
+* So we use one of them to reach the intr reg
+*/
+   ena_com_unmask_intr(rx_ring->ena_com_io_cq, &intr_reg);
+   }
 
-   /* It is a shared MSI-X. Tx and Rx CQ have pointer to it.
-* So we use one of them to reach the intr reg
-*/
-   ena_com_unmask_intr(rx_ring->ena_com_io_cq, &intr_reg);
 
ena_update_ring_numa_node(tx_ring, rx_ring);
 
@@ -1186,6 +1201,7 @@ static irqreturn_t ena_intr_msix_io(int irq, void *data)
 {
struct ena_napi *ena_napi = data;
 
+   atomic_set(&ena_napi->unmask_interrupt, 1);
napi_schedule(&ena_napi->napi);
 
return IRQ_HANDLED;
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h 
b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index 2897fab..c081fd3 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -135,6 +135,7 @@ struct ena_napi {
struct napi_struct napi cacheline_aligned;
struct ena_ring *tx_ring;
struct ena_ring *rx_ring;
+   atomic_t unmask_interrupt;
u32 qid;
 };
 
-- 
2.7.4



[PATCH V2 net 13/20] net/ena: change driver's default timeouts

2016-12-04 Thread Netanel Belgazal
Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.c| 4 ++--
 drivers/net/ethernet/amazon/ena/ena_netdev.h | 7 ---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index 4147d6e..a550c8a 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -36,9 +36,9 @@
 /*/
 
 /* Timeout in micro-sec */
-#define ADMIN_CMD_TIMEOUT_US (100)
+#define ADMIN_CMD_TIMEOUT_US (300)
 
-#define ENA_ASYNC_QUEUE_DEPTH 4
+#define ENA_ASYNC_QUEUE_DEPTH 16
 #define ENA_ADMIN_QUEUE_DEPTH 32
 
 #define MIN_ENA_VER (((ENA_COMMON_SPEC_VERSION_MAJOR) << \
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h 
b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index c081fd3..ed42e07 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "ena_com.h"
 #include "ena_eth_com.h"
@@ -100,7 +101,7 @@
 /* Number of queues to check for missing queues per timer service */
 #define ENA_MONITORED_TX_QUEUES4
 /* Max timeout packets before device reset */
-#define MAX_NUM_OF_TIMEOUTED_PACKETS 32
+#define MAX_NUM_OF_TIMEOUTED_PACKETS 128
 
 #define ENA_TX_RING_IDX_NEXT(idx, ring_size) (((idx) + 1) & ((ring_size) - 1))
 
@@ -116,9 +117,9 @@
 #define ENA_IO_IRQ_IDX(q)  (ENA_IO_IRQ_FIRST_IDX + (q))
 
 /* ENA device should send keep alive msg every 1 sec.
- * We wait for 3 sec just to be on the safe side.
+ * We wait for 6 sec just to be on the safe side.
  */
-#define ENA_DEVICE_KALIVE_TIMEOUT  (3 * HZ)
+#define ENA_DEVICE_KALIVE_TIMEOUT  (6 * HZ)
 
 #define ENA_MMIO_DISABLE_REG_READ  BIT(0)
 
-- 
2.7.4



[PATCH V2 net 18/20] net/ena: remove affinity hint from the driver

2016-12-04 Thread Netanel Belgazal
To allow irqbalance to better distribute the napi handler,
remove the smp affinity hint from the driver.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 6c49529..ee80472 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -1323,8 +1323,6 @@ static int ena_request_mgmnt_irq(struct ena_adapter 
*adapter)
  "set affinity hint of mgmnt irq.to 0x%lx (irq vector: %d)\n",
  irq->affinity_hint_mask.bits[0], irq->vector);
 
-   irq_set_affinity_hint(irq->vector, &irq->affinity_hint_mask);
-
return rc;
 }
 
@@ -1354,8 +1352,6 @@ static int ena_request_io_irq(struct ena_adapter *adapter)
netif_dbg(adapter, ifup, adapter->netdev,
  "set affinity hint of irq. index %d to 0x%lx (irq 
vector: %d)\n",
  i, irq->affinity_hint_mask.bits[0], irq->vector);
-
-   irq_set_affinity_hint(irq->vector, &irq->affinity_hint_mask);
}
 
return rc;
-- 
2.7.4



[PATCH V2 net 12/20] net/ena: reduce the severity of ena printouts

2016-12-04 Thread Netanel Belgazal
Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.c| 27 +--
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 14 +++---
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index f1e4f04..4147d6e 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -785,7 +785,7 @@ static int ena_com_get_feature_ex(struct ena_com_dev 
*ena_dev,
int ret;
 
if (!ena_com_check_supported_feature_id(ena_dev, feature_id)) {
-   pr_info("Feature %d isn't supported\n", feature_id);
+   pr_debug("Feature %d isn't supported\n", feature_id);
return -EPERM;
}
 
@@ -1127,7 +1127,13 @@ int ena_com_execute_admin_command(struct 
ena_com_admin_queue *admin_queue,
comp_ctx = ena_com_submit_admin_cmd(admin_queue, cmd, cmd_size,
comp, comp_size);
if (unlikely(IS_ERR(comp_ctx))) {
-   pr_err("Failed to submit command [%ld]\n", PTR_ERR(comp_ctx));
+   if (comp_ctx == ERR_PTR(-ENODEV))
+   pr_debug("Failed to submit command [%ld]\n",
+PTR_ERR(comp_ctx));
+   else
+   pr_err("Failed to submit command [%ld]\n",
+  PTR_ERR(comp_ctx));
+
return PTR_ERR(comp_ctx);
}
 
@@ -1918,7 +1924,7 @@ int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int 
mtu)
int ret;
 
if (!ena_com_check_supported_feature_id(ena_dev, ENA_ADMIN_MTU)) {
-   pr_info("Feature %d isn't supported\n", ENA_ADMIN_MTU);
+   pr_debug("Feature %d isn't supported\n", ENA_ADMIN_MTU);
return -EPERM;
}
 
@@ -1971,8 +1977,8 @@ int ena_com_set_hash_function(struct ena_com_dev *ena_dev)
 
if (!ena_com_check_supported_feature_id(ena_dev,
ENA_ADMIN_RSS_HASH_FUNCTION)) {
-   pr_info("Feature %d isn't supported\n",
-   ENA_ADMIN_RSS_HASH_FUNCTION);
+   pr_debug("Feature %d isn't supported\n",
+ENA_ADMIN_RSS_HASH_FUNCTION);
return -EPERM;
}
 
@@ -2135,7 +2141,8 @@ int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev)
 
if (!ena_com_check_supported_feature_id(ena_dev,
ENA_ADMIN_RSS_HASH_INPUT)) {
-   pr_info("Feature %d isn't supported\n", 
ENA_ADMIN_RSS_HASH_INPUT);
+   pr_debug("Feature %d isn't supported\n",
+ENA_ADMIN_RSS_HASH_INPUT);
return -EPERM;
}
 
@@ -2293,8 +2300,8 @@ int ena_com_indirect_table_set(struct ena_com_dev 
*ena_dev)
 
if (!ena_com_check_supported_feature_id(
ena_dev, ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG)) {
-   pr_info("Feature %d isn't supported\n",
-   ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG);
+   pr_debug("Feature %d isn't supported\n",
+ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG);
return -EPERM;
}
 
@@ -2565,8 +2572,8 @@ int ena_com_init_interrupt_moderation(struct ena_com_dev 
*ena_dev)
 
if (rc) {
if (rc == -EPERM) {
-   pr_info("Feature %d isn't supported\n",
-   ENA_ADMIN_INTERRUPT_MODERATION);
+   pr_debug("Feature %d isn't supported\n",
+ENA_ADMIN_INTERRUPT_MODERATION);
rc = 0;
} else {
pr_err("Failed to get interrupt moderation admin cmd. 
rc: %d\n",
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 5625007..7ae1fce 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -570,6 +570,7 @@ static void ena_free_all_rx_bufs(struct ena_adapter 
*adapter)
  */
 static void ena_free_tx_bufs(struct ena_ring *tx_ring)
 {
+   bool print_once = true;
u32 i;
 
for (i = 0; i < tx_ring->ring_size; i++) {
@@ -581,9 +582,16 @@ static void ena_free_tx_bufs(struct ena_ring *tx_ring)
if (!tx_info->skb)
continue;
 
-   netdev_notice(tx_ring->netdev,
- "free uncompleted tx skb qid %d idx 0x%x\n",
- tx_ring->qid, i);
+   if (print_once) {
+   netdev_notice(tx_ring->netdev,
+ "free uncompleted tx skb qid %d idx 
0x%x\n",
+ tx_ring->qid, i);
+   print_once = false;
+   } else {
+

[PATCH V2 net 17/20] net/ena: add IPv6 extended protocols to ena_admin_flow_hash_proto

2016-12-04 Thread Netanel Belgazal
We intend to use those fields in the future.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_admin_defs.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h 
b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
index 35ae511..92bba08 100644
--- a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
+++ b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
@@ -627,6 +627,12 @@ enum ena_admin_flow_hash_proto {
 
ENA_ADMIN_RSS_NOT_IP= 7,
 
+   /* TCPv6 with extension header */
+   ENA_ADMIN_RSS_TCP6_EX   = 8,
+
+   /* IPv6 with extension header */
+   ENA_ADMIN_RSS_IP6_EX= 9,
+
ENA_ADMIN_RSS_PROTO_NUM = 16,
 };
 
-- 
2.7.4



[PATCH V2 net 14/20] net/ena: change condition for host attribute configuration

2016-12-04 Thread Netanel Belgazal
Move the host info config to be the first admin command that is executed.
This change require the driver to remove the 'feature check'
from host info configuration flow.
The check is removed since the supported features bitmask field
is retrieved only after calling ENA_ADMIN_DEVICE_ATTRIBUTES admin command.

If set host info is not supported an error will be returned by the device.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.c| 8 +++-
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 5 +++--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index a550c8a..9deb0dd 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -2474,11 +2474,9 @@ int ena_com_set_host_attributes(struct ena_com_dev 
*ena_dev)
 
int ret;
 
-   if (!ena_com_check_supported_feature_id(ena_dev,
-   ENA_ADMIN_HOST_ATTR_CONFIG)) {
-   pr_warn("Set host attribute isn't supported\n");
-   return -EPERM;
-   }
+   /* Host attribute config is called before ena_com_get_dev_attr_feat
+* so ena_com can't check if the feature is supported.
+*/
 
memset(&cmd, 0x0, sizeof(cmd));
admin_queue = &ena_dev->admin_queue;
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 7ae1fce..8c1e14b 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2426,6 +2426,8 @@ static int ena_device_init(struct ena_com_dev *ena_dev, 
struct pci_dev *pdev,
 */
ena_com_set_admin_polling_mode(ena_dev, true);
 
+   ena_config_host_info(ena_dev);
+
/* Get Device Attributes*/
rc = ena_com_get_dev_attr_feat(ena_dev, get_feat_ctx);
if (rc) {
@@ -2450,11 +2452,10 @@ static int ena_device_init(struct ena_com_dev *ena_dev, 
struct pci_dev *pdev,
 
*wd_state = !!(aenq_groups & BIT(ENA_ADMIN_KEEP_ALIVE));
 
-   ena_config_host_info(ena_dev);
-
return 0;
 
 err_admin_init:
+   ena_com_delete_host_info(ena_dev);
ena_com_admin_destroy(ena_dev);
 err_mmio_read_less:
ena_com_mmio_reg_read_request_destroy(ena_dev);
-- 
2.7.4



[PATCH V2 net 02/20] net/ena: fix error handling when probe fails

2016-12-04 Thread Netanel Belgazal
When driver fails in probe, it will release all resources, including
adapter.
In case of probe failure, ena_remove should not try to free the adapter
resources.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 33a760e..397c9bc 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -3054,6 +3054,7 @@ static int ena_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 err_free_region:
ena_release_bars(ena_dev, pdev);
 err_free_ena_dev:
+   pci_set_drvdata(pdev, NULL);
vfree(ena_dev);
 err_disable_device:
pci_disable_device(pdev);
-- 
2.7.4



[PATCH V2 net 16/20] net/ena: use napi_schedule_irqoff when possible

2016-12-04 Thread Netanel Belgazal
Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 8c1e14b..6c49529 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -1210,7 +1210,7 @@ static irqreturn_t ena_intr_msix_io(int irq, void *data)
struct ena_napi *ena_napi = data;
 
atomic_set(&ena_napi->unmask_interrupt, 1);
-   napi_schedule(&ena_napi->napi);
+   napi_schedule_irqoff(&ena_napi->napi);
 
return IRQ_HANDLED;
 }
-- 
2.7.4



[PATCH V2 net 15/20] net/ena: change sizeof() argument to be the type pointer

2016-12-04 Thread Netanel Belgazal
Instead of using:
memset(ptr, 0x0, sizeof(struct ...))
use:
memset(ptr, 0x0, sizeor(*ptr))

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index 9deb0dd..f2e167b 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -329,7 +329,7 @@ static int ena_com_init_io_sq(struct ena_com_dev *ena_dev,
size_t size;
int dev_node = 0;
 
-   memset(&io_sq->desc_addr, 0x0, sizeof(struct ena_com_io_desc_addr));
+   memset(&io_sq->desc_addr, 0x0, sizeof(io_sq->desc_addr));
 
io_sq->desc_entry_size =
(io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX) ?
@@ -383,7 +383,7 @@ static int ena_com_init_io_cq(struct ena_com_dev *ena_dev,
size_t size;
int prev_node = 0;
 
-   memset(&io_cq->cdesc_addr, 0x0, sizeof(struct ena_com_io_desc_addr));
+   memset(&io_cq->cdesc_addr, 0x0, sizeof(io_cq->cdesc_addr));
 
/* Use the basic completion descriptor for Rx */
io_cq->cdesc_entry_size_in_bytes =
@@ -681,7 +681,7 @@ static int ena_com_destroy_io_sq(struct ena_com_dev 
*ena_dev,
u8 direction;
int ret;
 
-   memset(&destroy_cmd, 0x0, sizeof(struct ena_admin_aq_destroy_sq_cmd));
+   memset(&destroy_cmd, 0x0, sizeof(destroy_cmd));
 
if (io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX)
direction = ENA_ADMIN_SQ_DIRECTION_TX;
@@ -963,7 +963,7 @@ static int ena_com_create_io_sq(struct ena_com_dev *ena_dev,
u8 direction;
int ret;
 
-   memset(&create_cmd, 0x0, sizeof(struct ena_admin_aq_create_sq_cmd));
+   memset(&create_cmd, 0x0, sizeof(create_cmd));
 
create_cmd.aq_common_descriptor.opcode = ENA_ADMIN_CREATE_SQ;
 
@@ -1155,7 +1155,7 @@ int ena_com_create_io_cq(struct ena_com_dev *ena_dev,
struct ena_admin_acq_create_cq_resp_desc cmd_completion;
int ret;
 
-   memset(&create_cmd, 0x0, sizeof(struct ena_admin_aq_create_cq_cmd));
+   memset(&create_cmd, 0x0, sizeof(create_cmd));
 
create_cmd.aq_common_descriptor.opcode = ENA_ADMIN_CREATE_CQ;
 
@@ -1263,7 +1263,7 @@ int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev,
struct ena_admin_acq_destroy_cq_resp_desc destroy_resp;
int ret;
 
-   memset(&destroy_cmd, 0x0, sizeof(struct ena_admin_aq_destroy_sq_cmd));
+   memset(&destroy_cmd, 0x0, sizeof(destroy_cmd));
 
destroy_cmd.cq_idx = io_cq->idx;
destroy_cmd.aq_common_descriptor.opcode = ENA_ADMIN_DESTROY_CQ;
@@ -1613,8 +1613,8 @@ int ena_com_create_io_queue(struct ena_com_dev *ena_dev,
io_sq = &ena_dev->io_sq_queues[ctx->qid];
io_cq = &ena_dev->io_cq_queues[ctx->qid];
 
-   memset(io_sq, 0x0, sizeof(struct ena_com_io_sq));
-   memset(io_cq, 0x0, sizeof(struct ena_com_io_cq));
+   memset(io_sq, 0x0, sizeof(*io_sq));
+   memset(io_cq, 0x0, sizeof(*io_cq));
 
/* Init CQ */
io_cq->q_depth = ctx->queue_size;
-- 
2.7.4



[PATCH V2 net 08/20] net/ena: add hardware hints capability to the driver

2016-12-04 Thread Netanel Belgazal
The ENA device can update the ena driver about the desire timeouts.
The hardware hints are transmitted as Asynchronous event to the driver.

In case the device does not support this capability, the driver
will use its own defines.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_admin_defs.h | 31 +
 drivers/net/ethernet/amazon/ena/ena_com.c| 41 ---
 drivers/net/ethernet/amazon/ena/ena_com.h|  5 ++
 drivers/net/ethernet/amazon/ena/ena_ethtool.c|  1 -
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 86 +++-
 drivers/net/ethernet/amazon/ena/ena_netdev.h | 19 +-
 drivers/net/ethernet/amazon/ena/ena_regs_defs.h  |  2 +
 7 files changed, 157 insertions(+), 28 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h 
b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
index 6d70bf5..35ae511 100644
--- a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
+++ b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
@@ -70,6 +70,8 @@ enum ena_admin_aq_feature_id {
 
ENA_ADMIN_MAX_QUEUES_NUM= 2,
 
+   ENA_ADMIN_HW_HINTS  = 3,
+
ENA_ADMIN_RSS_HASH_FUNCTION = 10,
 
ENA_ADMIN_STATELESS_OFFLOAD_CONFIG  = 11,
@@ -749,6 +751,31 @@ struct ena_admin_feature_rss_ind_table {
struct ena_admin_rss_ind_table_entry inline_entry;
 };
 
+/* When hint value is 0, driver should use it's own predefined value */
+struct ena_admin_ena_hw_hints {
+   /* value in ms */
+   u16 mmio_read_timeout;
+
+   /* value in ms */
+   u16 driver_watchdog_timeout;
+
+   /* Per packet tx completion timeout. value in ms */
+   u16 missing_tx_completion_timeout;
+
+   u16 missed_tx_completion_count_threshold_to_reset;
+
+   /* value in ms */
+   u16 admin_completion_tx_timeout;
+
+   u16 netdev_wd_timeout;
+
+   u16 max_tx_sgl_size;
+
+   u16 max_rx_sgl_size;
+
+   u16 reserved[8];
+};
+
 struct ena_admin_get_feat_cmd {
struct ena_admin_aq_common_desc aq_common_descriptor;
 
@@ -782,6 +809,8 @@ struct ena_admin_get_feat_resp {
struct ena_admin_feature_rss_ind_table ind_table;
 
struct ena_admin_feature_intr_moder_desc intr_moderation;
+
+   struct ena_admin_ena_hw_hints hw_hints;
} u;
 };
 
@@ -857,6 +886,8 @@ enum ena_admin_aenq_notification_syndrom {
ENA_ADMIN_SUSPEND   = 0,
 
ENA_ADMIN_RESUME= 1,
+
+   ENA_ADMIN_UPDATE_HINTS  = 2,
 };
 
 struct ena_admin_aenq_entry {
diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index 46aad3a..f1e4f04 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -508,15 +508,13 @@ static int ena_com_comp_status_to_errno(u8 comp_status)
 static int ena_com_wait_and_process_admin_cq_polling(struct ena_comp_ctx 
*comp_ctx,
 struct ena_com_admin_queue 
*admin_queue)
 {
-   unsigned long flags;
-   u32 start_time;
+   unsigned long flags, timeout;
int ret;
 
-   start_time = ((u32)jiffies_to_usecs(jiffies));
+   timeout = jiffies + usecs_to_jiffies(admin_queue->completion_timeout);
 
while (comp_ctx->status == ENA_CMD_SUBMITTED) {
-   if u32)jiffies_to_usecs(jiffies)) - start_time) >
-   ADMIN_CMD_TIMEOUT_US) {
+   if (time_is_before_jiffies(timeout)) {
pr_err("Wait for completion (polling) timeout\n");
/* ENA didn't have any completion */
spin_lock_irqsave(&admin_queue->q_lock, flags);
@@ -560,7 +558,8 @@ static int 
ena_com_wait_and_process_admin_cq_interrupts(struct ena_comp_ctx *com
int ret;
 
wait_for_completion_timeout(&comp_ctx->wait_event,
-   usecs_to_jiffies(ADMIN_CMD_TIMEOUT_US));
+   usecs_to_jiffies(
+   admin_queue->completion_timeout));
 
/* In case the command wasn't completed find out the root cause.
 * There might be 2 kinds of errors
@@ -600,12 +599,14 @@ static u32 ena_com_reg_bar_read32(struct ena_com_dev 
*ena_dev, u16 offset)
struct ena_com_mmio_read *mmio_read = &ena_dev->mmio_read;
volatile struct ena_admin_ena_mmio_req_read_less_resp *read_resp =
mmio_read->read_resp;
-   u32 mmio_read_reg, ret;
+   u32 mmio_read_reg, timeout, ret;
unsigned long flags;
int i;
 
might_sleep();
 
+   timeout = mmio_read->reg_read_to ? : ENA_REG_READ_TIMEOUT;
+
/* If readless is disabled, perform regular read */
if (!mmio_read->readless_supported)
return readl(ena_dev->reg_bar + offset);
@@ -626,14 +627,14 @@ static u32 ena_com_reg_bar_read32(struct ena_com_dev 

[PATCH V2 net 11/20] net/ena: use READ_ONCE to access completion descriptors

2016-12-04 Thread Netanel Belgazal
Completion descriptors are accessed from the driver and from the device.
To avoid reading the old value, use READ_ONCE macro.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.h | 1 +
 drivers/net/ethernet/amazon/ena/ena_eth_com.c | 8 
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.h 
b/drivers/net/ethernet/amazon/ena/ena_com.h
index 6883ee5..f8cdce0 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.h
+++ b/drivers/net/ethernet/amazon/ena/ena_com.h
@@ -33,6 +33,7 @@
 #ifndef ENA_COM
 #define ENA_COM
 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/net/ethernet/amazon/ena/ena_eth_com.c 
b/drivers/net/ethernet/amazon/ena/ena_eth_com.c
index 539c536..f999305 100644
--- a/drivers/net/ethernet/amazon/ena/ena_eth_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_eth_com.c
@@ -45,7 +45,7 @@ static inline struct ena_eth_io_rx_cdesc_base 
*ena_com_get_next_rx_cdesc(
cdesc = (struct ena_eth_io_rx_cdesc_base *)(io_cq->cdesc_addr.virt_addr
+ (head_masked * io_cq->cdesc_entry_size_in_bytes));
 
-   desc_phase = (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_PHASE_MASK) >>
+   desc_phase = (READ_ONCE(cdesc->status) & 
ENA_ETH_IO_RX_CDESC_BASE_PHASE_MASK) >>
ENA_ETH_IO_RX_CDESC_BASE_PHASE_SHIFT;
 
if (desc_phase != expected_phase)
@@ -141,7 +141,7 @@ static inline u16 ena_com_cdesc_rx_pkt_get(struct 
ena_com_io_cq *io_cq,
 
ena_com_cq_inc_head(io_cq);
count++;
-   last = (cdesc->status & ENA_ETH_IO_RX_CDESC_BASE_LAST_MASK) >>
+   last = (READ_ONCE(cdesc->status) & 
ENA_ETH_IO_RX_CDESC_BASE_LAST_MASK) >>
ENA_ETH_IO_RX_CDESC_BASE_LAST_SHIFT;
} while (!last);
 
@@ -489,13 +489,13 @@ int ena_com_tx_comp_req_id_get(struct ena_com_io_cq 
*io_cq, u16 *req_id)
 * expected, it mean that the device still didn't update
 * this completion.
 */
-   cdesc_phase = cdesc->flags & ENA_ETH_IO_TX_CDESC_PHASE_MASK;
+   cdesc_phase = READ_ONCE(cdesc->flags) & ENA_ETH_IO_TX_CDESC_PHASE_MASK;
if (cdesc_phase != expected_phase)
return -EAGAIN;
 
ena_com_cq_inc_head(io_cq);
 
-   *req_id = cdesc->req_id;
+   *req_id = READ_ONCE(cdesc->req_id);
 
return 0;
 }
-- 
2.7.4



[PATCH V2 net 05/20] net/ena: fix RSS default hash configuration

2016-12-04 Thread Netanel Belgazal
ENA default hash configure IPv4_frag hash twice instead of
configure non ip packets.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c 
b/drivers/net/ethernet/amazon/ena/ena_com.c
index 3066d9c..46aad3a 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -2184,7 +2184,7 @@ int ena_com_set_default_hash_ctrl(struct ena_com_dev 
*ena_dev)
hash_ctrl->selected_fields[ENA_ADMIN_RSS_IP4_FRAG].fields =
ENA_ADMIN_RSS_L3_SA | ENA_ADMIN_RSS_L3_DA;
 
-   hash_ctrl->selected_fields[ENA_ADMIN_RSS_IP4_FRAG].fields =
+   hash_ctrl->selected_fields[ENA_ADMIN_RSS_NOT_IP].fields =
ENA_ADMIN_RSS_L2_DA | ENA_ADMIN_RSS_L2_SA;
 
for (i = 0; i < ENA_ADMIN_RSS_PROTO_NUM; i++) {
-- 
2.7.4



[PATCH V2 net 09/20] net/ena: fix potential access to freed memory during device reset

2016-12-04 Thread Netanel Belgazal
If the ena driver detects that the device is not behave as expected,
it tries to reset the device.
The reset flow calls ena_down, which will frees all the resources
the driver allocates and then it will reset the device.

This flow can cause memory corruption if the device is still writes
to the driver's memory space.
To overcome this potential race, move the reset before the device
resources are freed.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 56 +---
 1 file changed, 43 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 0b718ee..bb7eeea 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -80,14 +80,18 @@ static void ena_tx_timeout(struct net_device *dev)
 {
struct ena_adapter *adapter = netdev_priv(dev);
 
+   /* Change the state of the device to trigger reset
+* Check that we are not in the middle or a trigger already
+*/
+
+   if (test_and_set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))
+   return;
+
u64_stats_update_begin(&adapter->syncp);
adapter->dev_stats.tx_timeout++;
u64_stats_update_end(&adapter->syncp);
 
netif_err(adapter, tx_err, dev, "Transmit time out\n");
-
-   /* Change the state of the device to trigger reset */
-   set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
 }
 
 static void update_rx_ring_mtu(struct ena_adapter *adapter, int mtu)
@@ -1116,7 +1120,8 @@ static int ena_io_poll(struct napi_struct *napi, int 
budget)
 
tx_budget = tx_ring->ring_size / ENA_TX_POLL_BUDGET_DIVIDER;
 
-   if (!test_bit(ENA_FLAG_DEV_UP, &tx_ring->adapter->flags)) {
+   if (!test_bit(ENA_FLAG_DEV_UP, &tx_ring->adapter->flags) ||
+   test_bit(ENA_FLAG_TRIGGER_RESET, &tx_ring->adapter->flags)) {
napi_complete_done(napi, 0);
return 0;
}
@@ -1705,12 +1710,22 @@ static void ena_down(struct ena_adapter *adapter)
adapter->dev_stats.interface_down++;
u64_stats_update_end(&adapter->syncp);
 
-   /* After this point the napi handler won't enable the tx queue */
-   ena_napi_disable_all(adapter);
netif_carrier_off(adapter->netdev);
netif_tx_disable(adapter->netdev);
 
+   /* After this point the napi handler won't enable the tx queue */
+   ena_napi_disable_all(adapter);
+
/* After destroy the queue there won't be any new interrupts */
+
+   if (test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags)) {
+   int rc;
+
+   rc = ena_com_dev_reset(adapter->ena_dev);
+   if (rc)
+   dev_err(&adapter->pdev->dev, "Device reset failed\n");
+   }
+
ena_destroy_all_io_queues(adapter);
 
ena_disable_io_intr_sync(adapter);
@@ -2073,6 +2088,14 @@ static void ena_netpoll(struct net_device *netdev)
struct ena_adapter *adapter = netdev_priv(netdev);
int i;
 
+   /* Dont schedule NAPI if the driver is in the middle of reset
+* or netdev is down.
+*/
+
+   if (!test_bit(ENA_FLAG_DEV_UP, &adapter->flags) ||
+   test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))
+   return;
+
for (i = 0; i < adapter->num_queues; i++)
napi_schedule(&adapter->ena_napi[i].napi);
 }
@@ -2459,6 +2482,14 @@ static void ena_fw_reset_device(struct work_struct *work)
bool dev_up, wd_state;
int rc;
 
+   if (unlikely(!test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))) {
+   dev_err(&pdev->dev,
+   "device reset schedule while reset bit is off\n");
+   return;
+   }
+
+   netif_carrier_off(netdev);
+
del_timer_sync(&adapter->timer_service);
 
rtnl_lock();
@@ -2472,12 +2503,6 @@ static void ena_fw_reset_device(struct work_struct *work)
 */
ena_close(netdev);
 
-   rc = ena_com_dev_reset(ena_dev);
-   if (rc) {
-   dev_err(&pdev->dev, "Device reset failed\n");
-   goto err;
-   }
-
ena_free_mgmnt_irq(adapter);
 
ena_disable_msix(adapter);
@@ -2490,6 +2515,8 @@ static void ena_fw_reset_device(struct work_struct *work)
 
ena_com_mmio_reg_read_request_destroy(ena_dev);
 
+   clear_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
+
/* Finish with the destroy part. Start the init part */
 
rc = ena_device_init(ena_dev, adapter->pdev, &get_feat_ctx, &wd_state);
@@ -2555,6 +2582,9 @@ static void check_for_missing_tx_completions(struct 
ena_adapter *adapter)
if (!test_bit(ENA_FLAG_DEV_UP, &adapter->flags))
return;
 
+   if (test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))
+   return;
+
if (adapter->missing_tx_completion_to == ENA_HW_HINTS_NO_TIMEOUT)
return

[PATCH V2 net 07/20] net/ena: refactor ena_get_stats64 to be atomic context safe

2016-12-04 Thread Netanel Belgazal
ndo_get_stat64 can be called from atomic context.
However the current implementation sends an admin command to retrieve
the statistics from the device.
This admin commands uses sleep.

Refactor the implementation of ena_get_stats64 to take the
{rx,tx}bytes/cnt from the driver's inner counters
and to take the rx drops counter
from the asynchronous keep alive (heart bit) event.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_admin_defs.h |  8 
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 57 +---
 drivers/net/ethernet/amazon/ena/ena_netdev.h |  1 +
 3 files changed, 51 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h 
b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
index f48c886..6d70bf5 100644
--- a/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
+++ b/drivers/net/ethernet/amazon/ena/ena_admin_defs.h
@@ -873,6 +873,14 @@ struct ena_admin_aenq_link_change_desc {
u32 flags;
 };
 
+struct ena_admin_aenq_keep_alive_desc {
+   struct ena_admin_aenq_common_desc aenq_common_desc;
+
+   u32 rx_drops_low;
+
+   u32 rx_drops_high;
+};
+
 struct ena_admin_ena_mmio_req_read_less_resp {
u16 req_id;
 
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index ad5f78f..962ffb5 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2176,28 +2176,46 @@ static struct rtnl_link_stats64 *ena_get_stats64(struct 
net_device *netdev,
 struct rtnl_link_stats64 
*stats)
 {
struct ena_adapter *adapter = netdev_priv(netdev);
-   struct ena_admin_basic_stats ena_stats;
-   int rc;
+   struct ena_ring *rx_ring, *tx_ring;
+   unsigned int start;
+   u64 rx_drops;
+   int i;
 
if (!test_bit(ENA_FLAG_DEV_UP, &adapter->flags))
return NULL;
 
-   rc = ena_com_get_dev_basic_stats(adapter->ena_dev, &ena_stats);
-   if (rc)
-   return NULL;
+   for (i = 0; i < adapter->num_queues; i++) {
+   u64 bytes, packets;
+
+   tx_ring = &adapter->tx_ring[i];
+
+   do {
+   start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
+   packets = tx_ring->tx_stats.cnt;
+   bytes = tx_ring->tx_stats.bytes;
+   } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
+
+   stats->tx_packets += packets;
+   stats->tx_bytes += bytes;
 
-   stats->tx_bytes = ((u64)ena_stats.tx_bytes_high << 32) |
-   ena_stats.tx_bytes_low;
-   stats->rx_bytes = ((u64)ena_stats.rx_bytes_high << 32) |
-   ena_stats.rx_bytes_low;
+   rx_ring = &adapter->rx_ring[i];
+
+   do {
+   start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
+   packets = rx_ring->rx_stats.cnt;
+   bytes = rx_ring->rx_stats.bytes;
+   } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
 
-   stats->rx_packets = ((u64)ena_stats.rx_pkts_high << 32) |
-   ena_stats.rx_pkts_low;
-   stats->tx_packets = ((u64)ena_stats.tx_pkts_high << 32) |
-   ena_stats.tx_pkts_low;
+   stats->rx_packets += packets;
+   stats->rx_bytes += bytes;
+   }
+
+   do {
+   start = u64_stats_fetch_begin_irq(&adapter->syncp);
+   rx_drops = adapter->dev_stats.rx_drops;
+   } while (u64_stats_fetch_retry_irq(&adapter->syncp, start));
 
-   stats->rx_dropped = ((u64)ena_stats.rx_drops_high << 32) |
-   ena_stats.rx_drops_low;
+   stats->rx_dropped = rx_drops;
 
stats->multicast = 0;
stats->collisions = 0;
@@ -3221,8 +3239,17 @@ static void ena_keep_alive_wd(void *adapter_data,
  struct ena_admin_aenq_entry *aenq_e)
 {
struct ena_adapter *adapter = (struct ena_adapter *)adapter_data;
+   struct ena_admin_aenq_keep_alive_desc *desc;
+   u64 rx_drops;
 
+   desc = (struct ena_admin_aenq_keep_alive_desc *)aenq_e;
adapter->last_keep_alive_jiffies = jiffies;
+
+   rx_drops = ((u64)desc->rx_drops_high << 32) | desc->rx_drops_low;
+
+   u64_stats_update_begin(&adapter->syncp);
+   adapter->dev_stats.rx_drops = rx_drops;
+   u64_stats_update_end(&adapter->syncp);
 }
 
 static void ena_notification(void *adapter_data,
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h 
b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index 69d7e9e..f0ddc11 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -241,6 +241,7 @@ struct ena_stats_dev {
u64 interface_up;
u64 interface_down;
u64 admin_q_pause;
+   u64 rx_drops;
 };
 
 enum ena_flags_t {

[PATCH V2 net 01/20] net/ena: remove ntuple filter support from device feature list

2016-12-04 Thread Netanel Belgazal
Remove NETIF_F_NTUPLE from netdev->features.
The ENA device driver does not support ntuple filtering.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index bfeaec5..33a760e 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2729,7 +2729,6 @@ static void ena_set_dev_offloads(struct 
ena_com_dev_get_features_ctx *feat,
netdev->features =
dev_features |
NETIF_F_SG |
-   NETIF_F_NTUPLE |
NETIF_F_RXHASH |
NETIF_F_HIGHDMA;
 
-- 
2.7.4



[PATCH V2 net 03/20] net/ena: fix queues number calculation

2016-12-04 Thread Netanel Belgazal
The ENA driver tries to open a queue per vCPU.
To determine how many vCPUs the instance have it uses num_possible_cpus
while it should have use num_online_cpus instead.

Signed-off-by: Netanel Belgazal 
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c 
b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 397c9bc..224302c 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2667,7 +2667,7 @@ static int ena_calc_io_queue_num(struct pci_dev *pdev,
io_sq_num = get_feat_ctx->max_queues.max_sq_num;
}
 
-   io_queue_num = min_t(int, num_possible_cpus(), ENA_MAX_NUM_IO_QUEUES);
+   io_queue_num = min_t(int, num_online_cpus(), ENA_MAX_NUM_IO_QUEUES);
io_queue_num = min_t(int, io_queue_num, io_sq_num);
io_queue_num = min_t(int, io_queue_num,
 get_feat_ctx->max_queues.max_cq_num);
-- 
2.7.4



Re: Enabling peer to peer device transactions for PCIe devices

2016-12-04 Thread Haggai Eran
On 11/30/2016 6:23 PM, Jason Gunthorpe wrote:
>> and O_DIRECT operations that access GPU memory.
> This goes through user space so there is still a VMA..
> 
>> Also, HMM's migration between two GPUs could use peer to peer in the
>> kernel, although that is intended to be handled by the GPU driver if
>> I understand correctly.
> Hum, presumably these migrations are VMA backed as well...
I guess so.

>>> Presumably in-kernel could use a vmap or something and the same basic
>>> flow?
>> I think we can achieve the kernel's needs with ZONE_DEVICE and DMA-API 
>> support
>> for peer to peer. I'm not sure we need vmap. We need a way to have a 
>> scatterlist
>> of MMIO pfns, and ZONE_DEVICE allows that.
> Well, if there is no virtual map then we are back to how do you do
> migrations and other things people seem to want to do on these
> pages. Maybe the loose 'struct page' flow is not for those users.
I was thinking that kernel use cases would disallow migration, similar to how 
non-ODP MRs would work. Either they are short-lived (like an O_DIRECT transfer)
or they can be longed lived but non-migratable (like perhaps a CMB staging 
buffer).

> But I think if you want kGPU or similar then you probably need vmaps
> or something similar to represent the GPU pages in kernel memory.
Right, although sometimes the GPU pages are simply inaccessible to the CPU.
In any case, I haven't thought about kGPU as a use-case.


Re: Enabling peer to peer device transactions for PCIe devices

2016-12-04 Thread Stephen Bates
Hi All

This has been a great thread (thanks to Alex for kicking it off) and I
wanted to jump in and maybe try and put some summary around the
discussion. I also wanted to propose we include this as a topic for LFS/MM
because I think we need more discussion on the best way to add this
functionality to the kernel.

As far as I can tell the people looking for P2P support in the kernel fall
into two main camps:

1. Those who simply want to expose static BARs on PCIe devices that can be
used as the source/destination for DMAs from another PCIe device. This
group has no need for memory invalidation and are happy to use
physical/bus addresses and not virtual addresses.

2. Those who want to support devices that suffer from occasional memory
pressure and need to invalidate memory regions from time to time. This
camp also would like to use virtual addresses rather than physical ones to
allow for things like migration.

I am wondering if people agree with this assessment?

I think something like the iopmem patches Logan and I submitted recently
come close to addressing use case 1. There are some issues around
routability but based on feedback to date that does not seem to be a
show-stopper for an initial inclusion.

For use-case 2 it looks like there are several options and some of them
(like HMM) have been around for quite some time without gaining
acceptance. I think there needs to be more discussion on this usecase and
it could be some time before we get something upstreamable.

I for one, would really like to see use case 1 get addressed soon because
we have consumers for it coming soon in the form of CMBs for NVMe devices.

Long term I think Jason summed it up really well. CPU vendors will put
high-speed, open, switchable, coherent buses on their processors and all
these problems will vanish. But I ain't holding my breathe for that to
happen ;-).

Cheers

Stephen


[PATCH] block: fix unintended fallthrough in generic_make_request_checks()

2016-12-04 Thread Nicolai Stange
Since commit e73c23ff736e ("block: add async variant of
blkdev_issue_zeroout") messages like the following show up:

  EXT4-fs (dm-1): Delayed block allocation failed for inode 2368848 at
  logical offset 0 with max blocks 1 with error 95
  EXT4-fs (dm-1): This should not happen!! Data will be lost

Due to the following fallthrough introduced with
commit 2d253440b5af ("block: Define zoned block device operations"),
generic_make_request_checks() would accept a REQ_OP_WRITE_SAME bio only
if the block device supports "write same" *and* is a zoned one:

  switch (bio_op(bio)) {
  [...]
  case REQ_OP_WRITE_SAME:
if (!bdev_write_same(bio->bi_bdev))
goto not_supported;
  case REQ_OP_ZONE_REPORT:
  case REQ_OP_ZONE_RESET:
if (!bdev_is_zoned(bio->bi_bdev))
goto not_supported;
break;
  [...]
  }

Thus, although the bio setup as done by __blkdev_issue_write_same() from
commit e73c23ff736e ("block: add async variant of blkdev_issue_zeroout")
would succeed, its actual submission would not, resulting in the
EOPNOTSUPP == 95.

Fix this by removing the fallthrough which, due to the lack of an explicit
comment, seems to be unintended anyway.

Fixes: e73c23ff736e ("block: add async variant of blkdev_issue_zeroout")
Fixes: 2d253440b5af ("block: Define zoned block device operations")
Signed-off-by: Nicolai Stange 
---
Applicable to next-20161202.

Note that after this patch, I'm seeing a single
 EXT4-fs (dm-1): Delayed block allocation failed for inode 2625094 at
 logical offset 2032 with max blocks 2 with error 121
with 121 == EREMOTEIO

This is because my SATA sda reports 0x20 (invalid command) back
in response to 0x41 (WRITE_SAME).

After this has happened, sd_done() disables "write same" once and for
all, hence only this single message.

I expect this to get fixed by
  https://patchwork.kernel.org/patch/9321963/

 block/blk-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/blk-core.c b/block/blk-core.c
index 24de87d..1998aa4 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1947,6 +1947,7 @@ generic_make_request_checks(struct bio *bio)
case REQ_OP_WRITE_SAME:
if (!bdev_write_same(bio->bi_bdev))
goto not_supported;
+   break;
case REQ_OP_ZONE_REPORT:
case REQ_OP_ZONE_RESET:
if (!bdev_is_zoned(bio->bi_bdev))
-- 
2.10.2



Re: [v2.1,1/2] watchdog: loongson1: Add Loongson1 SoC watchdog driver

2016-12-04 Thread Yang Ling
On Thu, Nov 24, 2016 at 08:05:58AM -0800, Guenter Roeck wrote:
> On Fri, Oct 21, 2016 at 01:45:39PM +0800, Yang Ling wrote:
> > Add watchdog timer specific driver for Loongson1 SoC.
> > 
> > Signed-off-by: Yang Ling 
> 
> First of all, sorry for the late reply. I'll try to do better next time.
> 
> > ---
> > V2.1 from Kelvin Cheung:
> >   Use max_hw_heartbeat_ms instead of max_timeout.
> > V2:
> >   Increase the value of the default heartbeat.
> >   Modify the setup process for register.
> >   Order include files and Makefile alphabetically.
> > V1.1:
> >   Add a little debugging information.
> > ---
> >  drivers/watchdog/Kconfig |   7 ++
> >  drivers/watchdog/Makefile|   1 +
> >  drivers/watchdog/loongson1_wdt.c | 158 
> > +++
> >  3 files changed, 166 insertions(+)
> >  create mode 100644 drivers/watchdog/loongson1_wdt.c
> > 
> > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > index 50dbaa8..6707d43 100644
> > --- a/drivers/watchdog/Kconfig
> > +++ b/drivers/watchdog/Kconfig
> > @@ -1513,6 +1513,13 @@ config LANTIQ_WDT
> > help
> >   Hardware driver for the Lantiq SoC Watchdog Timer.
> >  
> > +config LOONGSON1_WDT
> > +   tristate "Loongson1 SoC hardware watchdog"
> > +   depends on MACH_LOONGSON32
> > +   select WATCHDOG_CORE
> > +   help
> > + Hardware driver for the Loongson1 SoC Watchdog Timer.
> > +
> >  config RALINK_WDT
> > tristate "Ralink SoC watchdog"
> > select WATCHDOG_CORE
> > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> > index cba0043..b6a8d70 100644
> > --- a/drivers/watchdog/Makefile
> > +++ b/drivers/watchdog/Makefile
> > @@ -157,6 +157,7 @@ obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
> >  obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
> >  octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
> >  obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
> > +obj-$(CONFIG_LOONGSON1_WDT) += loongson1_wdt.o
> >  obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
> >  obj-$(CONFIG_IMGPDC_WDT) += imgpdc_wdt.o
> >  obj-$(CONFIG_MT7621_WDT) += mt7621_wdt.o
> > diff --git a/drivers/watchdog/loongson1_wdt.c 
> > b/drivers/watchdog/loongson1_wdt.c
> > new file mode 100644
> > index 000..f885294
> > --- /dev/null
> > +++ b/drivers/watchdog/loongson1_wdt.c
> > @@ -0,0 +1,158 @@
> > +/*
> > + * Copyright (c) 2016 Yang Ling 
> > + *
> > + * 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.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define DEFAULT_HEARTBEAT  30
> > +
> > +static bool nowayout = WATCHDOG_NOWAYOUT;
> > +module_param(nowayout, bool, 0444);
> > +
> > +static unsigned int heartbeat = DEFAULT_HEARTBEAT;
> > +module_param(heartbeat, uint, 0444);
> > +
> > +struct ls1x_wdt_drvdata {
> > +   void __iomem *base;
> > +   struct clk *clk;
> > +   unsigned int counts_per_second;
> > +   struct watchdog_device wdt;
> > +};
> > +
> > +static int ls1x_wdt_ping(struct watchdog_device *wdt_dev)
> > +{
> > +   struct ls1x_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
> > +
> > +   writel(0x1, drvdata->base + WDT_SET);
> > +
> > +   return 0;
> > +}
> > +
> > +static int ls1x_wdt_set_timeout(struct watchdog_device *wdt_dev,
> > +   unsigned int timeout)
> > +{
> > +   struct ls1x_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
> > +   unsigned int counts;
> > +
> > +   wdt_dev->timeout = min(timeout, wdt_dev->max_hw_heartbeat_ms / 1000);
> 
> wdt_dev->timeout needs to be set to the 'soft' timeout. The hardware timeout,
> if needed, needs to be saved internally (in struct ls1x_wdt_drvdata).
> Not that it is needed here, though - the value is not used elsewhere in the
> driver. So you can do something like
> 
>   wdt->timeout = timeout;
>   timeout = min(timeout, wdt_dev->max_hw_heartbeat_ms / 1000);
>   counts = drvdata->counts_per_second * timeout;
> 
> > +   counts = drvdata->counts_per_second * wdt_dev->timeout;
> > +
> > +   writel(counts, drvdata->base + WDT_TIMER);
> > +
> > +   return 0;
> > +}
> > +
> > +static int ls1x_wdt_start(struct watchdog_device *wdt_dev)
> > +{
> > +   struct ls1x_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
> > +
> > +   writel(0x1, drvdata->base + WDT_EN);
> > +
> > +   return 0;
> > +}
> > +
> > +static int ls1x_wdt_stop(struct watchdog_device *wdt_dev)
> > +{
> > +   struct ls1x_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
> > +
> > +   writel(0x0, drvdata->base + WDT_EN);
> > +
> > +   return 0;
> > +}
> > +
> > +static const struct watchdog_info ls1x_wdt_info = {
> > +   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
> > +   .identity = "Loongson1 Watchdog",
> > +};
> > +
> > +static const struct watchdog_ops 

Re: [tip:efi/core] efi/libstub: Make efi_random_alloc() allocate below 4 GB on 32-bit

2016-12-04 Thread Matt Fleming
On Thu, 24 Nov, at 10:47:15PM, tip-bot for Ard Biesheuvel wrote:
> Commit-ID:  018edcfac4c3b140366ad51b0907f3becb5bb624
> Gitweb: http://git.kernel.org/tip/018edcfac4c3b140366ad51b0907f3becb5bb624
> Author: Ard Biesheuvel 
> AuthorDate: Thu, 24 Nov 2016 18:02:23 +
> Committer:  Ingo Molnar 
> CommitDate: Fri, 25 Nov 2016 07:15:23 +0100
> 
> efi/libstub: Make efi_random_alloc() allocate below 4 GB on 32-bit
> 
> The UEFI stub executes in the context of the firmware, which identity
> maps the available system RAM, which implies that only memory below
> 4 GB can be used for allocations on 32-bit architectures, even on [L]PAE
> capable hardware.
> 
> So ignore any reported memory above 4 GB in efi_random_alloc(). This
> also fixes a reported build problem on ARM under -Os, where the 64-bit
> logical shift relies on a software routine that the ARM decompressor does
> not provide.
> 
> A second [minor] issue is also fixed, where the '+ 1' is moved out of
> the shift, where it belongs: the reason for its presence is that a
> memory region where start == end should count as a single slot, given
> that 'end' takes the desired size and alignment of the allocation into
> account.
> 
> To clarify the code in this regard, rename start/end to 'first_slot' and
> 'last_slot', respectively, and introduce 'region_end' to describe the
> last usable address of the current region.
> 
> Reported-by: Arnd Bergmann 
> Signed-off-by: Ard Biesheuvel 
> Cc: Linus Torvalds 
> Cc: Matt Fleming 
> Cc: Peter Zijlstra 
> Cc: Thomas Gleixner 
> Cc: linux-...@vger.kernel.org
> Link: 
> http://lkml.kernel.org/r/1480010543-25709-2-git-send-email-ard.biesheu...@linaro.org
> Signed-off-by: Ingo Molnar 
> ---
>  drivers/firmware/efi/libstub/random.c | 13 +++--
>  1 file changed, 7 insertions(+), 6 deletions(-)

Ard, was this picked up for the correct tip branch? If it fixes a
build failure it should have gone into tip/efi/urgent, right?


Re: [tip:efi/core] efi/libstub: Make efi_random_alloc() allocate below 4 GB on 32-bit

2016-12-04 Thread Ard Biesheuvel
On 4 December 2016 at 14:17, Matt Fleming  wrote:
> On Thu, 24 Nov, at 10:47:15PM, tip-bot for Ard Biesheuvel wrote:
>> Commit-ID:  018edcfac4c3b140366ad51b0907f3becb5bb624
>> Gitweb: 
>> http://git.kernel.org/tip/018edcfac4c3b140366ad51b0907f3becb5bb624
>> Author: Ard Biesheuvel 
>> AuthorDate: Thu, 24 Nov 2016 18:02:23 +
>> Committer:  Ingo Molnar 
>> CommitDate: Fri, 25 Nov 2016 07:15:23 +0100
>>
>> efi/libstub: Make efi_random_alloc() allocate below 4 GB on 32-bit
>>
>> The UEFI stub executes in the context of the firmware, which identity
>> maps the available system RAM, which implies that only memory below
>> 4 GB can be used for allocations on 32-bit architectures, even on [L]PAE
>> capable hardware.
>>
>> So ignore any reported memory above 4 GB in efi_random_alloc(). This
>> also fixes a reported build problem on ARM under -Os, where the 64-bit
>> logical shift relies on a software routine that the ARM decompressor does
>> not provide.
>>
>> A second [minor] issue is also fixed, where the '+ 1' is moved out of
>> the shift, where it belongs: the reason for its presence is that a
>> memory region where start == end should count as a single slot, given
>> that 'end' takes the desired size and alignment of the allocation into
>> account.
>>
>> To clarify the code in this regard, rename start/end to 'first_slot' and
>> 'last_slot', respectively, and introduce 'region_end' to describe the
>> last usable address of the current region.
>>
>> Reported-by: Arnd Bergmann 
>> Signed-off-by: Ard Biesheuvel 
>> Cc: Linus Torvalds 
>> Cc: Matt Fleming 
>> Cc: Peter Zijlstra 
>> Cc: Thomas Gleixner 
>> Cc: linux-...@vger.kernel.org
>> Link: 
>> http://lkml.kernel.org/r/1480010543-25709-2-git-send-email-ard.biesheu...@linaro.org
>> Signed-off-by: Ingo Molnar 
>> ---
>>  drivers/firmware/efi/libstub/random.c | 13 +++--
>>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> Ard, was this picked up for the correct tip branch? If it fixes a
> build failure it should have gone into tip/efi/urgent, right?

The failure was in -next, with a patch queued up for v4.10, so that is
where the fix went as well.


[PATCH v2.3 1/3] MIPS: loongson1: Remove several redundant RTC-related macros

2016-12-04 Thread Yang Ling
Move the RTC-related macros to regs-rtc.h.

Signed-off-by: Yang Ling 

---
V2.3:
  Remove the wide character.
V2.1~2.2:
  No change.
V2.0:
  Add the header file regs-rtc.h in loongson1.h.
---
 arch/mips/include/asm/mach-loongson32/loongson1.h |  7 +++---
 arch/mips/include/asm/mach-loongson32/regs-rtc.h  | 23 +++
 arch/mips/loongson32/common/platform.c| 27 +--
 3 files changed, 38 insertions(+), 19 deletions(-)
 create mode 100644 arch/mips/include/asm/mach-loongson32/regs-rtc.h

diff --git a/arch/mips/include/asm/mach-loongson32/loongson1.h 
b/arch/mips/include/asm/mach-loongson32/loongson1.h
index 3584c40..30bffcd 100644
--- a/arch/mips/include/asm/mach-loongson32/loongson1.h
+++ b/arch/mips/include/asm/mach-loongson32/loongson1.h
@@ -3,9 +3,9 @@
  *
  * Register mappings for Loongson 1
  *
- * 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
+ * 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.
  */
 
@@ -52,6 +52,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #endif /* __ASM_MACH_LOONGSON32_LOONGSON1_H */
diff --git a/arch/mips/include/asm/mach-loongson32/regs-rtc.h 
b/arch/mips/include/asm/mach-loongson32/regs-rtc.h
new file mode 100644
index 000..e67fda2
--- /dev/null
+++ b/arch/mips/include/asm/mach-loongson32/regs-rtc.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2016 Yang Ling 
+ *
+ * Loongson 1 RTC timer Register Definitions.
+ *
+ * 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.
+ */
+
+#ifndef __ASM_MACH_LOONGSON32_REGS_RTC_H
+#define __ASM_MACH_LOONGSON32_REGS_RTC_H
+
+#define LS1X_RTC_REG(x) \
+   ((void __iomem *)KSEG1ADDR(LS1X_RTC_BASE + (x)))
+
+#define LS1X_RTC_CTRL  LS1X_RTC_REG(0x40)
+
+#define RTC_EXTCLK_OK  (BIT(5) | BIT(8))
+#define RTC_EXTCLK_EN  BIT(8)
+
+#endif /* __ASM_MACH_LOONGSON32_REGS_RTC_H */
diff --git a/arch/mips/loongson32/common/platform.c 
b/arch/mips/loongson32/common/platform.c
index beff085..18c2959 100644
--- a/arch/mips/loongson32/common/platform.c
+++ b/arch/mips/loongson32/common/platform.c
@@ -1,9 +1,9 @@
 /*
  * Copyright (c) 2011-2016 Zhang, Keguang 
  *
- * 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
+ * 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.
  */
 
@@ -23,10 +23,6 @@
 #include 
 #include 
 
-#define LS1X_RTC_CTRL  ((void __iomem *)KSEG1ADDR(LS1X_RTC_BASE + 0x40))
-#define RTC_EXTCLK_OK  (BIT(5) | BIT(8))
-#define RTC_EXTCLK_EN  BIT(8)
-
 /* 8250/16550 compatible UART */
 #define LS1X_UART(_id) \
{   \
@@ -70,15 +66,6 @@ void __init ls1x_serial_set_uartclk(struct platform_device 
*pdev)
p->uartclk = clk_get_rate(clk);
 }
 
-void __init ls1x_rtc_set_extclk(struct platform_device *pdev)
-{
-   u32 val;
-
-   val = __raw_readl(LS1X_RTC_CTRL);
-   if (!(val & RTC_EXTCLK_OK))
-   __raw_writel(val | RTC_EXTCLK_EN, LS1X_RTC_CTRL);
-}
-
 /* CPUFreq */
 static struct plat_ls1x_cpufreq ls1x_cpufreq_pdata = {
.clk_name   = "cpu_clk",
@@ -357,6 +344,14 @@ struct platform_device ls1x_ehci_pdev = {
 };
 
 /* Real Time Clock */
+void __init ls1x_rtc_set_extclk(struct platform_device *pdev)
+{
+   u32 val = __raw_readl(LS1X_RTC_CTRL);
+
+   if (!(val & RTC_EXTCLK_OK))
+   __raw_writel(val | RTC_EXTCLK_EN, LS1X_RTC_CTRL);
+}
+
 struct platform_device ls1x_rtc_pdev = {
.name   = "ls1x-rtc",
.id = -1,
-- 
1.9.1



[PATCH v2.3 3/3] MIPS: loongson1: Add watchdog support for Loongson1 board

2016-12-04 Thread Yang Ling
The patch adds watchdog support for Loongson1 board.

Signed-off-by: Yang Ling 

---
V2.3:
  No change.
V2.2:
  Remove the wide character.
V2.1:
  No change.
V2.0:
  Add watchdog support for loongson1b_defconfig.
V1.1:
  Add watchdog support for Loongson1B.
---
 arch/mips/configs/loongson1b_defconfig   |  4 
 arch/mips/configs/loongson1c_defconfig   |  4 
 arch/mips/include/asm/mach-loongson32/platform.h |  9 +
 arch/mips/loongson32/common/platform.c   | 16 
 arch/mips/loongson32/ls1b/board.c|  7 ---
 arch/mips/loongson32/ls1c/board.c|  7 ---
 6 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/arch/mips/configs/loongson1b_defconfig 
b/arch/mips/configs/loongson1b_defconfig
index c442f27..914c867 100644
--- a/arch/mips/configs/loongson1b_defconfig
+++ b/arch/mips/configs/loongson1b_defconfig
@@ -74,6 +74,10 @@ CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_GPIOLIB=y
 CONFIG_GPIO_LOONGSON1=y
 # CONFIG_HWMON is not set
+CONFIG_WATCHDOG=y
+CONFIG_WATCHDOG_NOWAYOUT=y
+CONFIG_WATCHDOG_SYSFS=y
+CONFIG_LOONGSON1_WDT=y
 # CONFIG_VGA_CONSOLE is not set
 CONFIG_HID_GENERIC=m
 CONFIG_USB_HID=m
diff --git a/arch/mips/configs/loongson1c_defconfig 
b/arch/mips/configs/loongson1c_defconfig
index 2304d41..68e42ef 100644
--- a/arch/mips/configs/loongson1c_defconfig
+++ b/arch/mips/configs/loongson1c_defconfig
@@ -75,6 +75,10 @@ CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_GPIOLIB=y
 CONFIG_GPIO_LOONGSON1=y
 # CONFIG_HWMON is not set
+CONFIG_WATCHDOG=y
+CONFIG_WATCHDOG_NOWAYOUT=y
+CONFIG_WATCHDOG_SYSFS=y
+CONFIG_LOONGSON1_WDT=y
 # CONFIG_VGA_CONSOLE is not set
 CONFIG_HID_GENERIC=m
 CONFIG_USB_HID=m
diff --git a/arch/mips/include/asm/mach-loongson32/platform.h 
b/arch/mips/include/asm/mach-loongson32/platform.h
index 7adc313..8f8fa43 100644
--- a/arch/mips/include/asm/mach-loongson32/platform.h
+++ b/arch/mips/include/asm/mach-loongson32/platform.h
@@ -1,9 +1,9 @@
 /*
  * Copyright (c) 2011 Zhang, Keguang 
  *
- * 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
+ * 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.
  */
 
@@ -25,11 +25,12 @@
 extern struct platform_device ls1x_gpio1_pdev;
 extern struct platform_device ls1x_nand_pdev;
 extern struct platform_device ls1x_rtc_pdev;
+extern struct platform_device ls1x_wdt_pdev;
 
 void __init ls1x_clk_init(void);
 void __init ls1x_dma_set_platdata(struct plat_ls1x_dma *pdata);
 void __init ls1x_nand_set_platdata(struct plat_ls1x_nand *pdata);
-void __init ls1x_serial_set_uartclk(struct platform_device *pdev);
 void __init ls1x_rtc_set_extclk(struct platform_device *pdev);
+void __init ls1x_serial_set_uartclk(struct platform_device *pdev);
 
 #endif /* __ASM_MACH_LOONGSON32_PLATFORM_H */
diff --git a/arch/mips/loongson32/common/platform.c 
b/arch/mips/loongson32/common/platform.c
index 18c2959..a3dabe9 100644
--- a/arch/mips/loongson32/common/platform.c
+++ b/arch/mips/loongson32/common/platform.c
@@ -356,3 +356,19 @@ struct platform_device ls1x_rtc_pdev = {
.name   = "ls1x-rtc",
.id = -1,
 };
+
+/* Watchdog */
+static struct resource ls1x_wdt_resources[] = {
+   {
+   .start  = LS1X_WDT_BASE,
+   .end= LS1X_WDT_BASE + SZ_16 - 1,
+   .flags  = IORESOURCE_MEM,
+   },
+};
+
+struct platform_device ls1x_wdt_pdev = {
+   .name   = "ls1x-wdt",
+   .id = -1,
+   .num_resources  = ARRAY_SIZE(ls1x_wdt_resources),
+   .resource   = ls1x_wdt_resources,
+};
diff --git a/arch/mips/loongson32/ls1b/board.c 
b/arch/mips/loongson32/ls1b/board.c
index 38a1d40..01aceaa 100644
--- a/arch/mips/loongson32/ls1b/board.c
+++ b/arch/mips/loongson32/ls1b/board.c
@@ -1,9 +1,9 @@
 /*
  * Copyright (c) 2011-2016 Zhang, Keguang 
  *
- * 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
+ * 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.
  */
 
@@ -72,6 +72,7 @@ struct plat_ls1x_nand ls1x_nand_pdata = {
&ls1x_gpio1_pdev,
&ls1x_nand_pdev,
&ls1x_rtc_pdev,
+   &ls1x_wdt_pdev,
 };
 
 static int __init ls1b_platform_init(void)
diff --git a/arch/mips/loongson32/ls1c/board.c 
b/arch/mips/loongson32/ls1c/board.c
index a96bed5..eb2d913 

[PATCH v2.3 2/3] watchdog: loongson1: Add Loongson1 SoC watchdog driver

2016-12-04 Thread Yang Ling
Add watchdog timer specific driver for Loongson1 SoC.

Signed-off-by: Yang Ling 

---
V2.3:
  Set DEFAULT_HEARTBEAT value to ls1x_wdt->timeout.
V2.2:
  Remove the wide character.
  Check the return value for clk_get_rate().
V2.1 from Kelvin Cheung:
  Use max_hw_heartbeat_ms instead of max_timeout.
V2.0:
  Increase the value of the default heartbeat.
  Modify the setup process for register.
  Order include files and Makefile alphabetically.
V1.1:
  Add a little debugging information.
---
 drivers/watchdog/Kconfig |   7 ++
 drivers/watchdog/Makefile|   1 +
 drivers/watchdog/loongson1_wdt.c | 170 +++
 3 files changed, 178 insertions(+)
 create mode 100644 drivers/watchdog/loongson1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index fdd3228..c5b9c6e 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1513,6 +1513,13 @@ config LANTIQ_WDT
help
  Hardware driver for the Lantiq SoC Watchdog Timer.
 
+config LOONGSON1_WDT
+   tristate "Loongson1 SoC hardware watchdog"
+   depends on MACH_LOONGSON32
+   select WATCHDOG_CORE
+   help
+ Hardware driver for the Loongson1 SoC Watchdog Timer.
+
 config RALINK_WDT
tristate "Ralink SoC watchdog"
select WATCHDOG_CORE
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index caa9f4a..0c3d35e 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -163,6 +163,7 @@ obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
 obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
 octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
 obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
+obj-$(CONFIG_LOONGSON1_WDT) += loongson1_wdt.o
 obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
 obj-$(CONFIG_IMGPDC_WDT) += imgpdc_wdt.o
 obj-$(CONFIG_MT7621_WDT) += mt7621_wdt.o
diff --git a/drivers/watchdog/loongson1_wdt.c b/drivers/watchdog/loongson1_wdt.c
new file mode 100644
index 000..c43ad38
--- /dev/null
+++ b/drivers/watchdog/loongson1_wdt.c
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2016 Yang Ling 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DEFAULT_HEARTBEAT  30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0444);
+
+static unsigned int heartbeat = DEFAULT_HEARTBEAT;
+module_param(heartbeat, uint, 0444);
+
+struct ls1x_wdt_drvdata {
+   void __iomem *base;
+   struct clk *clk;
+   unsigned long clk_rate;
+   struct watchdog_device wdt;
+};
+
+static int ls1x_wdt_ping(struct watchdog_device *wdt_dev)
+{
+   struct ls1x_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
+
+   writel(0x1, drvdata->base + WDT_SET);
+
+   return 0;
+}
+
+static int ls1x_wdt_set_timeout(struct watchdog_device *wdt_dev,
+   unsigned int timeout)
+{
+   struct ls1x_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
+   unsigned int max_hw_heartbeat = wdt_dev->max_hw_heartbeat_ms / 1000;
+   unsigned int counts;
+
+   wdt_dev->timeout = timeout;
+
+   counts = drvdata->clk_rate * min(timeout, max_hw_heartbeat);
+   writel(counts, drvdata->base + WDT_TIMER);
+
+   return 0;
+}
+
+static int ls1x_wdt_start(struct watchdog_device *wdt_dev)
+{
+   struct ls1x_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
+
+   writel(0x1, drvdata->base + WDT_EN);
+
+   return 0;
+}
+
+static int ls1x_wdt_stop(struct watchdog_device *wdt_dev)
+{
+   struct ls1x_wdt_drvdata *drvdata = watchdog_get_drvdata(wdt_dev);
+
+   writel(0x0, drvdata->base + WDT_EN);
+
+   return 0;
+}
+
+static const struct watchdog_info ls1x_wdt_info = {
+   .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "Loongson1 Watchdog",
+};
+
+static const struct watchdog_ops ls1x_wdt_ops = {
+   .owner = THIS_MODULE,
+   .start = ls1x_wdt_start,
+   .stop = ls1x_wdt_stop,
+   .ping = ls1x_wdt_ping,
+   .set_timeout = ls1x_wdt_set_timeout,
+};
+
+static int ls1x_wdt_probe(struct platform_device *pdev)
+{
+   struct ls1x_wdt_drvdata *drvdata;
+   struct watchdog_device *ls1x_wdt;
+   unsigned long clk_rate;
+   struct resource *res;
+   int err;
+
+   drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
+   if (!drvdata)
+   return -ENOMEM;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   drvdata->base = devm_ioremap_resource(&pdev->dev, res);
+   if (IS_ERR(drvdata->base))
+   return PTR_ERR(drvdata->base);
+
+   drvdata->clk = devm_clk_get(&pdev->dev, pdev->name);
+   if (IS_ERR(drvdata->clk))
+   return PTR_ERR(drvdata->clk);

[patch net] net: fec: fix compile with CONFIG_M5272

2016-12-04 Thread Nikita Yushchenko
Commit 4dfb80d18d05 ("net: fec: cache statistics while device is down")
introduced unconditional statistics-related actions.

However, when driver is compiled with CONFIG_M5272, staticsics-related
definitions do not exist, which results into build errors.

Fix that by adding needed #if !defined(CONFIG_M5272).

Fixes: 4dfb80d18d05 ("net: fec: cache statistics while device is down")
Signed-off-by: Nikita Yushchenko 
---
 drivers/net/ethernet/freescale/fec_main.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c 
b/drivers/net/ethernet/freescale/fec_main.c
index 6a20c24a2003..89e902767abb 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -2884,7 +2884,9 @@ fec_enet_close(struct net_device *ndev)
if (fep->quirks & FEC_QUIRK_ERR006687)
imx6q_cpuidle_fec_irqs_unused();
 
+#if !defined(CONFIG_M5272)
fec_enet_update_ethtool_stats(ndev);
+#endif
 
fec_enet_clk_enable(ndev, false);
pinctrl_pm_select_sleep_state(&fep->pdev->dev);
@@ -3192,7 +3194,9 @@ static int fec_enet_init(struct net_device *ndev)
 
fec_restart(ndev);
 
+#if !defined(CONFIG_M5272)
fec_enet_update_ethtool_stats(ndev);
+#endif
 
return 0;
 }
@@ -3292,9 +3296,11 @@ fec_probe(struct platform_device *pdev)
fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs);
 
/* Init network device */
-   ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private) +
- ARRAY_SIZE(fec_stats) * sizeof(u64),
- num_tx_qs, num_rx_qs);
+   ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private)
+#if !defined(CONFIG_M5272)
+ + ARRAY_SIZE(fec_stats) * sizeof(u64)
+#endif
+ , num_tx_qs, num_rx_qs);
if (!ndev)
return -ENOMEM;
 
-- 
2.1.4



Re: [PATCH] vfio/pci: Support error recovery

2016-12-04 Thread Alex Williamson
On Sun, 4 Dec 2016 20:16:42 +0800
Cao jin  wrote:

> On 12/01/2016 10:55 PM, Alex Williamson wrote:
> > On Thu, 1 Dec 2016 21:40:00 +0800  
> 
> >>> If an AER fault occurs and the user doesn't do a reset, what
> >>> happens when that device is released and a host driver tries to make
> >>> use of it?  The user makes no commitment to do a reset and there are
> >>> only limited configurations where we even allow the user to perform a
> >>> reset.
> >>> 
> >>
> >> Limited? Do you mean the things __pci_dev_reset() can do?  
> > 
> > I mean that there are significant device and guest configuration
> > restrictions in order to support AER.  For instance, all the functions
> > of the slot need to appear in a PCI-e topology in the guest with all
> > the functions in the right place such that a guest bus reset translates
> > into a host bus reset.  The physical functions cannot be split between
> > guests even if IOMMU isolation would otherwise allow it.  The user
> > needs to explicitly enable AER support for the devices.  A VM need to
> > be specifically configured for AER support in order to set any sort of
> > expectations of a guest directed bus reset, let alone a guarantee that
> > it will happen.  So all the existing VMs, where functions are split
> > between guests, or the topology isn't exactly right, or AER isn't
> > enabled see a regression from the above change as the device is no
> > longer reset.
> >   
> 
> I am not clear why set these restrictions in the current design. I take
> a glance at older versions of qemu's patchset, their thoughts is:
> translate a guest bus reset into a host bus reset(Which is
> unreasonable[*] to me). And I guess, that's the *cause* of these
> restrictions?  Is there any other stories behind these restrictions?
> 
> [*] In physical world, set bridge's secondary bus reset would send
> hot-reset TLP to all functions below, trigger every device's reset
> separately. Emulated device should behave the same, means just using
> each device's DeviceClass->reset method.

Are you trying to say that an FLR is equivalent to a link reset?
Please go read the previous discussions, especially if you're sending
patches you don't believe in.  Thanks,

Alex


Re: [PATCH 1/1] mtd: ubi: fix improper return value

2016-12-04 Thread Marek Vasut
On 12/04/2016 07:12 AM, Pan Bian wrote:
> From: Pan Bian 
> 
> When __vmalloc() returns a NULL pointer, the region is not checked, and
> we cannot make sure that only 0xFF bytes are present at offset. Thus,
> returning 0 seems improper.
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189081
> 
> Signed-off-by: Pan Bian 
> ---
>  drivers/mtd/ubi/io.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
> index b6fb8f9..b54fe05 100644
> --- a/drivers/mtd/ubi/io.c
> +++ b/drivers/mtd/ubi/io.c
> @@ -1413,7 +1413,7 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int 
> pnum, int offset, int len)
>   buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL);
>   if (!buf) {
>   ubi_err(ubi, "cannot allocate memory to check for 0xFFs");
> - return 0;
> + return -ENOMEM;

I wonder if you shouldn't also nuke the ubi_err() , because when you run
out of memory, printk() will likely also fail.

>   }
>  
>   err = mtd_read(ubi->mtd, addr, len, &read, buf);
> 


-- 
Best regards,
Marek Vasut


[PATCH v2] tty: serial: fsl_lpuart: fix del_timer_sync() vs timer routine deadlock

2016-12-04 Thread Nikita Yushchenko
Problem found via lockdep:

- lpuart_set_termios() calls del_timer_sync(&sport->lpuart_timer) while
  holding sport->port.lock

- sport->lpuart_timer routine is lpuart_timer_func() that calls
  lpuart_copy_rx_to_tty() that acquires same lock.

To fix, move Rx DMA stopping out of lock, as it already is in other places
in the same file.

While at it, also make Rx DMA start/stop code to look the same is in
other places in the same file.

Signed-off-by: Nikita Yushchenko 
---
Changes from v1:
- keep reallocation of Rx DMA buffer conditional on 'old'
- do not set sport->lpuart_dma_rx_use to true when it is already true

 drivers/tty/serial/fsl_lpuart.c | 35 +--
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index a1c6519837a4..f02934ffb329 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1407,6 +1407,18 @@ lpuart_set_termios(struct uart_port *port, struct 
ktermios *termios,
/* ask the core to calculate the divisor */
baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16);
 
+   /*
+* Need to update the Ring buffer length according to the selected
+* baud rate and restart Rx DMA path.
+*
+* Since timer function acqures sport->port.lock, need to stop before
+* acquring same lock because otherwise del_timer_sync() can deadlock.
+*/
+   if (old && sport->lpuart_dma_rx_use) {
+   del_timer_sync(&sport->lpuart_timer);
+   lpuart_dma_rx_free(&sport->port);
+   }
+
spin_lock_irqsave(&sport->port.lock, flags);
 
sport->port.read_status_mask = 0;
@@ -1456,22 +1468,11 @@ lpuart_set_termios(struct uart_port *port, struct 
ktermios *termios,
/* restore control register */
writeb(old_cr2, sport->port.membase + UARTCR2);
 
-   /*
-* If new baud rate is set, we will also need to update the Ring buffer
-* length according to the selected baud rate and restart Rx DMA path.
-*/
-   if (old) {
-   if (sport->lpuart_dma_rx_use) {
-   del_timer_sync(&sport->lpuart_timer);
-   lpuart_dma_rx_free(&sport->port);
-   }
-
-   if (sport->dma_rx_chan && !lpuart_start_rx_dma(sport)) {
-   sport->lpuart_dma_rx_use = true;
+   if (old && sport->lpuart_dma_rx_use) {
+   if (!lpuart_start_rx_dma(sport))
rx_dma_timer_init(sport);
-   } else {
+   else
sport->lpuart_dma_rx_use = false;
-   }
}
 
spin_unlock_irqrestore(&sport->port.lock, flags);
@@ -2131,12 +2132,10 @@ static int lpuart_resume(struct device *dev)
 
if (sport->lpuart_dma_rx_use) {
if (sport->port.irq_wake) {
-   if (!lpuart_start_rx_dma(sport)) {
-   sport->lpuart_dma_rx_use = true;
+   if (!lpuart_start_rx_dma(sport))
rx_dma_timer_init(sport);
-   } else {
+   else
sport->lpuart_dma_rx_use = false;
-   }
}
}
 
-- 
2.1.4



Re: [PATCH 1/4] statx: Add a system call to make enhanced file info available [ver #3]

2016-12-04 Thread Al Viro
On Sun, Dec 04, 2016 at 04:38:05AM +, Al Viro wrote:

> I understand wanting to avoid extra arguments, but you are asking for trouble
> with that sort of calling conventions.  Verifying that all call chains have
> these fields initialized is bloody unpleasant and it *is* going to break,
> especially since the rules are "you need to initialize it for vfs_xgetattr(),
> but not for vfs_getattr()" - the names are similar enough for confusion,
> and that's not the only such pair.

BTW, after some grepping: you seem to leave ecryptfs_getattr() as-is, which
means that flags it had been passed by caller in *stat are not seen by
underlying fs.  Looks fishy...


Hello Beautiful,

2016-12-04 Thread Jack
Good day dear, i hope this mail meets you well? my name is Jack, from the U.S. 
I know this may seem inappropriate so i ask for your forgiveness but i wish to 
get to know you better, if I may be so bold. I consider myself an easy-going 
man, adventurous, honest and fun loving person but I am currently looking for a 
relationship in which I will feel loved. I promise to answer any question that 
you may want to ask me...all i need is just your attention and the chance to 
know you more.

Please tell me more about yourself, if you do not mind. Hope to hear back from 
you soon.

Jack.


Re: Linux 4.9-rc6

2016-12-04 Thread Eric Dumazet
On Sun, 2016-12-04 at 03:10 -0800, Linus Torvalds wrote:
> 
> 
> On Dec 4, 2016 02:43, "Thorsten Leemhuis" 
> wrote:
> 
> 
> What the status of below patch? From the discussion it looks a
> lot like
> it was developed to fix a regression in 4.9, but the patch
> afaics has
> neither his mainline or linux-next yet. 
> 
> 
> It's not a regression as far as I can tell. It's a small optimization.
> Maybe.
> 
> 
> It's not going into 4.9, is not even clear it's worth it later either,
> unless somebody had numbers (which I haven't seen)
> 
Right, the patch was not in anyway ready for 4.9 ;)

I'll try to complete this for next cycle.

Thanks.





Re: [PATCH v2.3 2/3] watchdog: loongson1: Add Loongson1 SoC watchdog driver

2016-12-04 Thread Guenter Roeck

On 12/04/2016 07:02 AM, Yang Ling wrote:

Add watchdog timer specific driver for Loongson1 SoC.

Signed-off-by: Yang Ling 

---
V2.3:
  Set DEFAULT_HEARTBEAT value to ls1x_wdt->timeout.
V2.2:
  Remove the wide character.
  Check the return value for clk_get_rate().
V2.1 from Kelvin Cheung:
  Use max_hw_heartbeat_ms instead of max_timeout.
V2.0:
  Increase the value of the default heartbeat.
  Modify the setup process for register.
  Order include files and Makefile alphabetically.
V1.1:
  Add a little debugging information.
---
 drivers/watchdog/Kconfig |   7 ++
 drivers/watchdog/Makefile|   1 +
 drivers/watchdog/loongson1_wdt.c | 170 +++
 3 files changed, 178 insertions(+)
 create mode 100644 drivers/watchdog/loongson1_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index fdd3228..c5b9c6e 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1513,6 +1513,13 @@ config LANTIQ_WDT
help
  Hardware driver for the Lantiq SoC Watchdog Timer.

+config LOONGSON1_WDT
+   tristate "Loongson1 SoC hardware watchdog"
+   depends on MACH_LOONGSON32
+   select WATCHDOG_CORE
+   help
+ Hardware driver for the Loongson1 SoC Watchdog Timer.
+
 config RALINK_WDT
tristate "Ralink SoC watchdog"
select WATCHDOG_CORE
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index caa9f4a..0c3d35e 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -163,6 +163,7 @@ obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
 obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
 octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
 obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
+obj-$(CONFIG_LOONGSON1_WDT) += loongson1_wdt.o
 obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
 obj-$(CONFIG_IMGPDC_WDT) += imgpdc_wdt.o
 obj-$(CONFIG_MT7621_WDT) += mt7621_wdt.o
diff --git a/drivers/watchdog/loongson1_wdt.c b/drivers/watchdog/loongson1_wdt.c
new file mode 100644
index 000..c43ad38
--- /dev/null
+++ b/drivers/watchdog/loongson1_wdt.c
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2016 Yang Ling 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DEFAULT_HEARTBEAT  30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0444);
+
+static unsigned int heartbeat = DEFAULT_HEARTBEAT;


heartbeat should be 0.

Guenter



Re: [PATCH 1/4] statx: Add a system call to make enhanced file info available [ver #3]

2016-12-04 Thread Al Viro
On Sun, Dec 04, 2016 at 04:38:05AM +, Al Viro wrote:

> I understand wanting to avoid extra arguments, but you are asking for trouble
> with that sort of calling conventions.  Verifying that all call chains have
> these fields initialized is bloody unpleasant and it *is* going to break,
> especially since the rules are "you need to initialize it for vfs_xgetattr(),
> but not for vfs_getattr()" - the names are similar enough for confusion,
> and that's not the only such pair.

FWIW, there's a bit of abuse of struct kstat in overlayfs object
creation paths - for one thing, it ends up with a very small subset
of struct kstat (mode + rdev), for another it also needs link in
case of symlinks and ends up passing it separately.

IMO it would be better to introduce a separate object for that; does anybody
have objections to something like the patch below?  In principle, we might
even lift that thing into general API and switch ->mkdir()/->mknod()/->symlink()
to identical calling conventions.  Hell knows, perhaps ->create() as well...
Comments?

diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 36795ee..17ad2da 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -231,10 +231,15 @@ static int ovl_copy_up_locked(struct dentry *workdir, 
struct dentry *upperdir,
struct inode *udir = upperdir->d_inode;
struct dentry *newdentry = NULL;
struct dentry *upper = NULL;
-   umode_t mode = stat->mode;
int err;
const struct cred *old_creds = NULL;
struct cred *new_creds = NULL;
+   struct cattr cattr = {
+   /* Can't properly set mode on creation because of the umask */
+   .mode = stat->mode & S_IFMT,
+   .rdev = stat->rdev,
+   .link = link
+   };
 
newdentry = ovl_lookup_temp(workdir, dentry);
err = PTR_ERR(newdentry);
@@ -254,10 +259,7 @@ static int ovl_copy_up_locked(struct dentry *workdir, 
struct dentry *upperdir,
if (new_creds)
old_creds = override_creds(new_creds);
 
-   /* Can't properly set mode on creation because of the umask */
-   stat->mode &= S_IFMT;
-   err = ovl_create_real(wdir, newdentry, stat, link, NULL, true);
-   stat->mode = mode;
+   err = ovl_create_real(wdir, newdentry, &cattr, NULL, true);
 
if (new_creds) {
revert_creds(old_creds);
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 306b6c1..dc60a23 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -75,8 +75,8 @@ static struct dentry *ovl_whiteout(struct dentry *workdir,
 }
 
 int ovl_create_real(struct inode *dir, struct dentry *newdentry,
-   struct kstat *stat, const char *link,
-   struct dentry *hardlink, bool debug)
+   struct cattr *attr, struct dentry *hardlink,
+   bool debug)
 {
int err;
 
@@ -86,13 +86,13 @@ int ovl_create_real(struct inode *dir, struct dentry 
*newdentry,
if (hardlink) {
err = ovl_do_link(hardlink, dir, newdentry, debug);
} else {
-   switch (stat->mode & S_IFMT) {
+   switch (attr->mode & S_IFMT) {
case S_IFREG:
-   err = ovl_do_create(dir, newdentry, stat->mode, debug);
+   err = ovl_do_create(dir, newdentry, attr->mode, debug);
break;
 
case S_IFDIR:
-   err = ovl_do_mkdir(dir, newdentry, stat->mode, debug);
+   err = ovl_do_mkdir(dir, newdentry, attr->mode, debug);
break;
 
case S_IFCHR:
@@ -100,11 +100,11 @@ int ovl_create_real(struct inode *dir, struct dentry 
*newdentry,
case S_IFIFO:
case S_IFSOCK:
err = ovl_do_mknod(dir, newdentry,
-  stat->mode, stat->rdev, debug);
+  attr->mode, attr->rdev, debug);
break;
 
case S_IFLNK:
-   err = ovl_do_symlink(dir, newdentry, link, debug);
+   err = ovl_do_symlink(dir, newdentry, attr->link, debug);
break;
 
default:
@@ -183,8 +183,7 @@ static void ovl_instantiate(struct dentry *dentry, struct 
inode *inode,
 }
 
 static int ovl_create_upper(struct dentry *dentry, struct inode *inode,
-   struct kstat *stat, const char *link,
-   struct dentry *hardlink)
+   struct cattr *attr, struct dentry *hardlink)
 {
struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent);
struct inode *udir = upperdir->d_inode;
@@ -192,7 +191,7 @@ static int ovl_create_upper(struct dentry *dentry, struct 
inode *inode,
int err;
 
if (!hardlink && !IS_POSIXACL(udir))
-   stat->mode &= ~curren

Re: Cherryview wake up events

2016-12-04 Thread Johannes Stezenbach
Hi,

On Wed, Oct 05, 2016 at 04:05:11PM +0300, Mika Westerberg wrote:
> On Wed, Oct 05, 2016 at 02:46:48PM +0200, Johannes Stezenbach wrote:
> > On Fri, Sep 23, 2016 at 11:19:04AM +0300, Mika Westerberg wrote:
> > > David (CC'd) is working on getting the Dollar Cove PMIC driver
> > > upstreamed to the mainline kernel.
> > 
> > May I ask when to expect a patch?  I'm ready if you
> > have something to test, even if it's not in
> > shape for mainline yet.
> 
> It typically takes quite some time to get all the legal stuff done
> before the code can be published. And if people are busy with other
> things it takes even more time.
> 
> So please be patient, it will happen sooner or later ;-)

I don't want to nag, but just so it doesn't drop off
the TODO list due to "lack of interest":  What's the
status?  Will Santa bring the the TI Dollar Cove PMIC driver?

While I'm at it, I also have questions about S0ix support
in Linux which I didn't find answers to by web search.
Does S0ix depend on the PMIC driver?  And will it be
used during run time or only in "sleep" state
(which would mean "echo freeze >/sys/power/state"
since ACPI S3 isn't supported)?
Now all I know is it doesn't seem to be used so far (running 4.9.0-rc7+):

/sys/kernel/debug/pmc_atom/sleep_state:S0IR Residency:  0us
/sys/kernel/debug/pmc_atom/sleep_state:S0I1 Residency:  0us
/sys/kernel/debug/pmc_atom/sleep_state:S0I2 Residency:  0us
/sys/kernel/debug/pmc_atom/sleep_state:S0I3 Residency:  0us
/sys/kernel/debug/pmc_atom/sleep_state:S0   Residency: 160934496us


Thanks,
Johannes


Re: [PATCH] staging: dgnc: Fix lines longer than 80 characters

2016-12-04 Thread Fernando Apesteguia
On Sat, Dec 03, 2016 at 11:11:23AM +0100, Greg KH wrote:
> On Sat, Dec 03, 2016 at 10:56:54AM +0100, Fernando Apesteguia wrote:
> > On Sat, Dec 03, 2016 at 09:51:13AM +0100, Greg KH wrote:
> > > On Fri, Dec 02, 2016 at 08:13:49PM +0100, Fernando Apesteguia wrote:
> > > > For the first lines of the patch, I opted to create a small function
> > > > instead of breaking the the line in a weird way.
> > > > 
> > > > The other changes are simple ones.
> > > > 
> > > > Signed-off-by: Fernando Apesteguia 
> > > > ---
> > > >  drivers/staging/dgnc/dgnc_tty.c | 42 
> > > > +
> > > >  1 file changed, 26 insertions(+), 16 deletions(-)
> > > > 
> > > > diff --git a/drivers/staging/dgnc/dgnc_tty.c 
> > > > b/drivers/staging/dgnc/dgnc_tty.c
> > > > index af4bc86..835d448 100644
> > > > --- a/drivers/staging/dgnc/dgnc_tty.c
> > > > +++ b/drivers/staging/dgnc/dgnc_tty.c
> > > > @@ -102,6 +102,7 @@ static int dgnc_tty_write(struct tty_struct *tty, 
> > > > const unsigned char *buf,
> > > >  static void dgnc_tty_set_termios(struct tty_struct *tty,
> > > >  struct ktermios *old_termios);
> > > >  static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch);
> > > > +static void dgnc_keep_line_low(struct channel_t *ch, const unsigned 
> > > > char line);
> > > >  
> > > >  static const struct tty_operations dgnc_tty_ops = {
> > > > .open = dgnc_tty_open,
> > > > @@ -786,6 +787,12 @@ void dgnc_check_queue_flow_control(struct 
> > > > channel_t *ch)
> > > > }
> > > >  }
> > > >  
> > > > +static void dgnc_keep_line_low(struct channel_t *ch, const unsigned 
> > > > char line)
> > > > +{
> > > > +   ch->ch_mostat &= ~(line);
> > > > +   ch->ch_bd->bd_ops->assert_modem_signals(ch);
> > > > +}
> > > 
> > > Your name here is odd, it is named because of what it does to the coding
> > > style, not to the logic of what is happening in the function itself,
> > > making it very confusing.
> > 
> > It was a bad choice indeed :) but I didn't mean anything about the coding
> > style but about what the fuction does. It was meant to be read as:
> > "keep_signal_low" since the function puts (RTS/DTR) UART "line" to low.
> > 
> > Would "keep_signal_low" be clear and representative of what the function 
> > does?
> 
> It's not "keep", it is "change", right?  I don't remember the context
> now, sorry, you could be correct...

Yes, I think "change" or even "set" would be more appropriate. I'll rework the
patch and send it again.

Thanks.

> 
> 
> greg k-h


Re: [PATCH dt V2] ARM: BCM5301X: Enable UART by default for BCM4708(1), BCM4709(4) & BCM53012

2016-12-04 Thread Hauke Mehrtens
On 12/01/2016 06:40 PM, Rafał Miłecki wrote:
> From: Rafał Miłecki 
> 
> Every device tested so far got UART0 (at 0x18000300) working as serial
> console. It's most likely part of reference design and all vendors use
> it that way.

I think the last 4 boards are some of the reference boards. ;-)

> It seems to be easier to enable it by default and just disable it if we
> ever see a device with different hardware design.
> 
> Signed-off-by: Rafał Miłecki 

Acked-by: Hauke Mehrtens 

> ---
> V2: Update bcm94708.dts bcm94709.dts bcm953012er.dts & bcm953012k.dts
> ---
>  arch/arm/boot/dts/bcm4708-buffalo-wzr-1750dhp.dts  | 4 
>  arch/arm/boot/dts/bcm4708-luxul-xap-1510.dts   | 4 
>  arch/arm/boot/dts/bcm4708-luxul-xwc-1000.dts   | 4 
>  arch/arm/boot/dts/bcm4708-netgear-r6250.dts| 4 
>  arch/arm/boot/dts/bcm4708-smartrg-sr400ac.dts  | 4 
>  arch/arm/boot/dts/bcm4708.dtsi | 4 
>  arch/arm/boot/dts/bcm47081-buffalo-wzr-600dhp2.dts | 4 
>  arch/arm/boot/dts/bcm47081.dtsi| 4 
>  arch/arm/boot/dts/bcm4709-netgear-r7000.dts| 4 
>  arch/arm/boot/dts/bcm4709-netgear-r8000.dts| 4 
>  arch/arm/boot/dts/bcm4709-tplink-archer-c9-v1.dts  | 4 
>  arch/arm/boot/dts/bcm4709.dtsi | 1 +
>  arch/arm/boot/dts/bcm47094-dlink-dir-885l.dts  | 4 
>  arch/arm/boot/dts/bcm47094-luxul-xwr-3100.dts  | 4 
>  arch/arm/boot/dts/bcm47094-netgear-r8500.dts   | 4 
>  arch/arm/boot/dts/bcm47094.dtsi| 1 +
>  arch/arm/boot/dts/bcm94708.dts | 4 
>  arch/arm/boot/dts/bcm94709.dts | 4 
>  arch/arm/boot/dts/bcm953012er.dts  | 4 
>  arch/arm/boot/dts/bcm953012k.dts   | 1 -
>  20 files changed, 10 insertions(+), 61 deletions(-)
> 
> diff --git a/arch/arm/boot/dts/bcm4708-buffalo-wzr-1750dhp.dts 
> b/arch/arm/boot/dts/bcm4708-buffalo-wzr-1750dhp.dts
> index 9cb186e..d49afec0 100644
> --- a/arch/arm/boot/dts/bcm4708-buffalo-wzr-1750dhp.dts
> +++ b/arch/arm/boot/dts/bcm4708-buffalo-wzr-1750dhp.dts
> @@ -136,10 +136,6 @@
>   };
>  };
>  
> -&uart0 {
> - status = "okay";
> -};
> -
>  &usb2 {
>   vcc-gpio = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
>  };
> diff --git a/arch/arm/boot/dts/bcm4708-luxul-xap-1510.dts 
> b/arch/arm/boot/dts/bcm4708-luxul-xap-1510.dts
> index 35e6ed6..f591b0f 100644
> --- a/arch/arm/boot/dts/bcm4708-luxul-xap-1510.dts
> +++ b/arch/arm/boot/dts/bcm4708-luxul-xap-1510.dts
> @@ -55,10 +55,6 @@
>   };
>  };
>  
> -&uart0 {
> - status = "okay";
> -};
> -
>  &spi_nor {
>   status = "okay";
>  };
> diff --git a/arch/arm/boot/dts/bcm4708-luxul-xwc-1000.dts 
> b/arch/arm/boot/dts/bcm4708-luxul-xwc-1000.dts
> index 1c7e53d..50d65d8 100644
> --- a/arch/arm/boot/dts/bcm4708-luxul-xwc-1000.dts
> +++ b/arch/arm/boot/dts/bcm4708-luxul-xwc-1000.dts
> @@ -56,10 +56,6 @@
>   };
>  };
>  
> -&uart0 {
> - status = "okay";
> -};
> -
>  &spi_nor {
>   status = "okay";
>  };
> diff --git a/arch/arm/boot/dts/bcm4708-netgear-r6250.dts 
> b/arch/arm/boot/dts/bcm4708-netgear-r6250.dts
> index 8ce39d5..8519548 100644
> --- a/arch/arm/boot/dts/bcm4708-netgear-r6250.dts
> +++ b/arch/arm/boot/dts/bcm4708-netgear-r6250.dts
> @@ -83,10 +83,6 @@
>   };
>  };
>  
> -&uart0 {
> - status = "okay";
> -};
> -
>  &usb3 {
>   vcc-gpio = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
>  };
> diff --git a/arch/arm/boot/dts/bcm4708-smartrg-sr400ac.dts 
> b/arch/arm/boot/dts/bcm4708-smartrg-sr400ac.dts
> index 70f4bb9..74cfcd3 100644
> --- a/arch/arm/boot/dts/bcm4708-smartrg-sr400ac.dts
> +++ b/arch/arm/boot/dts/bcm4708-smartrg-sr400ac.dts
> @@ -119,10 +119,6 @@
>   };
>  };
>  
> -&uart0 {
> - status = "okay";
> -};
> -
>  &spi_nor {
>   status = "okay";
>  };
> diff --git a/arch/arm/boot/dts/bcm4708.dtsi b/arch/arm/boot/dts/bcm4708.dtsi
> index eed4dd1..d0eec09 100644
> --- a/arch/arm/boot/dts/bcm4708.dtsi
> +++ b/arch/arm/boot/dts/bcm4708.dtsi
> @@ -34,3 +34,7 @@
>   };
>  
>  };
> +
> +&uart0 {
> + status = "okay";
> +};
> diff --git a/arch/arm/boot/dts/bcm47081-buffalo-wzr-600dhp2.dts 
> b/arch/arm/boot/dts/bcm47081-buffalo-wzr-600dhp2.dts
> index a9c8def..2922536 100644
> --- a/arch/arm/boot/dts/bcm47081-buffalo-wzr-600dhp2.dts
> +++ b/arch/arm/boot/dts/bcm47081-buffalo-wzr-600dhp2.dts
> @@ -122,7 +122,3 @@
>   };
>   };
>  };
> -
> -&uart0 {
> - status = "okay";
> -};
> diff --git a/arch/arm/boot/dts/bcm47081.dtsi b/arch/arm/boot/dts/bcm47081.dtsi
> index f720012..c5f7619 100644
> --- a/arch/arm/boot/dts/bcm47081.dtsi
> +++ b/arch/arm/boot/dts/bcm47081.dtsi
> @@ -24,3 +24,7 @@
>   };
>   };
>  };
> +
> +&uart0 {
> + status = "okay";
> +};
> diff --git a/arch/arm/boot/dts/bcm4709-netgear-r7000.dts 
> b/arch/arm/boot/dts/bcm4709-netgear-r7000.dts
> index fd38d2a..0225d82 100644
> --- a/arch/arm/boot/dts/bcm4709-netgear-r7

Re: [PATCH V2 1/3 libnvdimm-pending] libnvdimm: remove else after return in nsio_rw_bytes()

2016-12-04 Thread Dan Williams
On Sat, Dec 3, 2016 at 10:53 AM, Fabian Frederick  wrote:
> else after return is not needed.
>
> Signed-off-by: Fabian Frederick 
> ---
> V2: -applied on top of libnvdimm-pending
>

Thanks. This one and the other 2 are applied and pushed out to
libnvdimm-pending.


[PATCH V2] staging: dgnc: Fix lines longer than 80 characters

2016-12-04 Thread Fernando Apesteguia
For the first lines of the patch, I opted to create a small function
instead of breaking the the line in a weird way.

This is v2 of the patch with the name of the function changed from
v1

The other changes are simple ones.

Signed-off-by: Fernando Apesteguia 
---
 drivers/staging/dgnc/dgnc_tty.c | 42 +
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index af4bc86..557b566 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -102,6 +102,7 @@ static int dgnc_tty_write(struct tty_struct *tty, const 
unsigned char *buf,
 static void dgnc_tty_set_termios(struct tty_struct *tty,
 struct ktermios *old_termios);
 static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch);
+static void dgnc_set_signal_low(struct channel_t *ch, const unsigned char 
line);
 
 static const struct tty_operations dgnc_tty_ops = {
.open = dgnc_tty_open,
@@ -786,6 +787,12 @@ void dgnc_check_queue_flow_control(struct channel_t *ch)
}
 }
 
+static void dgnc_set_signal_low(struct channel_t *ch, const unsigned char sig)
+{
+   ch->ch_mostat &= ~(sig);
+   ch->ch_bd->bd_ops->assert_modem_signals(ch);
+}
+
 void dgnc_wakeup_writes(struct channel_t *ch)
 {
int qlen = 0;
@@ -823,19 +830,15 @@ void dgnc_wakeup_writes(struct channel_t *ch)
 * If RTS Toggle mode is on, whenever
 * the queue and UART is empty, keep RTS low.
 */
-   if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
-   ch->ch_mostat &= ~(UART_MCR_RTS);
-   
ch->ch_bd->bd_ops->assert_modem_signals(ch);
-   }
+   if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
+   dgnc_set_signal_low(ch, UART_MCR_RTS);
 
/*
 * If DTR Toggle mode is on, whenever
 * the queue and UART is empty, keep DTR low.
 */
-   if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
-   ch->ch_mostat &= ~(UART_MCR_DTR);
-   
ch->ch_bd->bd_ops->assert_modem_signals(ch);
-   }
+   if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
+   dgnc_set_signal_low(ch, UART_MCR_DTR);
}
}
 
@@ -969,8 +972,9 @@ static int dgnc_tty_open(struct tty_struct *tty, struct 
file *file)
 * touched safely, the close routine will signal the
 * ch_flags_wait to wake us back up.
 */
-   rc = wait_event_interruptible(ch->ch_flags_wait, (((ch->ch_tun.un_flags 
|
- ch->ch_pun.un_flags) & UN_CLOSING) == 0));
+   rc = wait_event_interruptible(ch->ch_flags_wait,
+   (((ch->ch_tun.un_flags |
+  ch->ch_pun.un_flags) & UN_CLOSING) == 0));
 
/* If ret is non-zero, user ctrl-c'ed us */
if (rc)
@@ -1188,11 +1192,12 @@ static int dgnc_block_til_ready(struct tty_struct *tty,
 */
if (sleep_on_un_flags)
retval = wait_event_interruptible
-   (un->un_flags_wait, (old_flags != 
(ch->ch_tun.un_flags |
-  
ch->ch_pun.un_flags)));
+   (un->un_flags_wait,
+(old_flags != (ch->ch_tun.un_flags |
+   ch->ch_pun.un_flags)));
else
retval = wait_event_interruptible(ch->ch_flags_wait,
- (old_flags != 
ch->ch_flags));
+   (old_flags != ch->ch_flags));
 
/*
 * We got woken up for some reason.
@@ -2511,13 +2516,15 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, 
unsigned int cmd,
if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
ch->ch_tun.un_flags &=
~(UN_LOW | UN_EMPTY);
-   
wake_up_interruptible(&ch->ch_tun.un_flags_wait);
+   wake_up_interruptible(&ch->ch_tun
+   .un_flags_wait);
}
 
if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
ch->ch_pun.un_flags

Re: [PATCH 1/1] btrfs: fix improper return value

2016-12-04 Thread Omar Sandoval
On Sun, Dec 04, 2016 at 12:51:53PM +0800, Pan Bian wrote:
> In function btrfs_uuid_tree_iterate(), errno is assigned to variable ret
> on errors. However, it directly returns 0. It may be better to return
> ret. This patch also removes the warning, because the caller already
> prints a warning.
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=188731

Looks good.

Reviewed-by: Omar Sandoval 

> Signed-off-by: Pan Bian 
> ---
>  fs/btrfs/uuid-tree.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/uuid-tree.c b/fs/btrfs/uuid-tree.c
> index 7fc89e4..83bb2f2 100644
> --- a/fs/btrfs/uuid-tree.c
> +++ b/fs/btrfs/uuid-tree.c
> @@ -351,7 +351,5 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info,
>  
>  out:
>   btrfs_free_path(path);
> - if (ret)
> - btrfs_warn(fs_info, "btrfs_uuid_tree_iterate failed %d", ret);
> - return 0;
> + return ret;
>  }
> -- 
> 1.9.1
> 
> 


[PATCH] mlx4: Use kernel sizeof and alloc styles

2016-12-04 Thread Joe Perches
Convert sizeof foo to sizeof(foo) and allocations with multiplications
to the appropriate kcalloc/kmalloc_array styles.

Signed-off-by: Joe Perches 
---
 drivers/net/ethernet/mellanox/mlx4/alloc.c |  6 +++---
 drivers/net/ethernet/mellanox/mlx4/cmd.c   |  8 
 drivers/net/ethernet/mellanox/mlx4/en_resources.c  |  2 +-
 drivers/net/ethernet/mellanox/mlx4/en_rx.c |  2 +-
 drivers/net/ethernet/mellanox/mlx4/en_tx.c |  2 +-
 drivers/net/ethernet/mellanox/mlx4/eq.c| 20 +-
 drivers/net/ethernet/mellanox/mlx4/fw.c|  2 +-
 drivers/net/ethernet/mellanox/mlx4/icm.c   |  2 +-
 drivers/net/ethernet/mellanox/mlx4/icm.h   |  4 ++--
 drivers/net/ethernet/mellanox/mlx4/intf.c  |  2 +-
 drivers/net/ethernet/mellanox/mlx4/main.c  | 12 +--
 drivers/net/ethernet/mellanox/mlx4/mcg.c   | 12 +--
 drivers/net/ethernet/mellanox/mlx4/mr.c| 18 
 drivers/net/ethernet/mellanox/mlx4/qp.c| 12 +--
 .../net/ethernet/mellanox/mlx4/resource_tracker.c  | 24 +++---
 15 files changed, 63 insertions(+), 65 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c 
b/drivers/net/ethernet/mellanox/mlx4/alloc.c
index 249a4584401a..c25de2740c78 100644
--- a/drivers/net/ethernet/mellanox/mlx4/alloc.c
+++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c
@@ -185,8 +185,8 @@ int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, 
u32 mask,
bitmap->avail = num - reserved_top - reserved_bot;
bitmap->effective_len = bitmap->avail;
spin_lock_init(&bitmap->lock);
-   bitmap->table = kzalloc(BITS_TO_LONGS(bitmap->max) *
-   sizeof (long), GFP_KERNEL);
+   bitmap->table = kcalloc(BITS_TO_LONGS(bitmap->max), sizeof(long),
+   GFP_KERNEL);
if (!bitmap->table)
return -ENOMEM;
 
@@ -668,7 +668,7 @@ static struct mlx4_db_pgdir *mlx4_alloc_db_pgdir(struct 
device *dma_device,
 {
struct mlx4_db_pgdir *pgdir;
 
-   pgdir = kzalloc(sizeof *pgdir, gfp);
+   pgdir = kzalloc(sizeof(*pgdir), gfp);
if (!pgdir)
return NULL;
 
diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c 
b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index e36bebcab3f2..86e03e47ca47 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c
@@ -2616,9 +2616,9 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
int i;
int err = 0;
 
-   priv->cmd.context = kmalloc(priv->cmd.max_cmds *
-  sizeof (struct mlx4_cmd_context),
-  GFP_KERNEL);
+   priv->cmd.context = kmalloc_array(priv->cmd.max_cmds,
+ sizeof(struct mlx4_cmd_context),
+ GFP_KERNEL);
if (!priv->cmd.context)
return -ENOMEM;
 
@@ -2675,7 +2675,7 @@ struct mlx4_cmd_mailbox *mlx4_alloc_cmd_mailbox(struct 
mlx4_dev *dev)
 {
struct mlx4_cmd_mailbox *mailbox;
 
-   mailbox = kmalloc(sizeof *mailbox, GFP_KERNEL);
+   mailbox = kmalloc(sizeof(*mailbox), GFP_KERNEL);
if (!mailbox)
return ERR_PTR(-ENOMEM);
 
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_resources.c 
b/drivers/net/ethernet/mellanox/mlx4/en_resources.c
index a6b0db0e0383..10966dc5792c 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_resources.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_resources.c
@@ -44,7 +44,7 @@ void mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int 
size, int stride,
struct mlx4_en_dev *mdev = priv->mdev;
struct net_device *dev = priv->dev;
 
-   memset(context, 0, sizeof *context);
+   memset(context, 0, sizeof(*context));
context->flags = cpu_to_be32(7 << 16 | rss << MLX4_RSS_QPC_FLAG_OFFSET);
context->pd = cpu_to_be32(mdev->priv_pdn);
context->mtu_msgmax = 0xff;
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c 
b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 6562f78b07f4..616d3febe7ce 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -1235,7 +1235,7 @@ static int mlx4_en_config_rss_qp(struct mlx4_en_priv 
*priv, int qpn,
}
qp->event = mlx4_en_sqp_event;
 
-   memset(context, 0, sizeof *context);
+   memset(context, 0, sizeof(*context));
mlx4_en_fill_qp_context(priv, ring->actual_size, ring->stride, 0, 0,
qpn, ring->cqn, -1, context);
context->db_rec_addr = cpu_to_be64(ring->wqres.db.dma);
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c 
b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index 5de3cbe24f2b..233317e5fe72 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -660,7 +660,7 @@ stat

Re: [PATCH 1/1] mtd: ubi: fix improper return value

2016-12-04 Thread Joe Perches
On Sun, 2016-12-04 at 13:48 +0100, Marek Vasut wrote:
> On 12/04/2016 07:12 AM, Pan Bian wrote:
> > From: Pan Bian 
> > 
> > When __vmalloc() returns a NULL pointer, the region is not checked, and
> > we cannot make sure that only 0xFF bytes are present at offset. Thus,
> > returning 0 seems improper.
> > 
> > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=189081
> > 
> > Signed-off-by: Pan Bian 
> > ---
> >  drivers/mtd/ubi/io.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
[]
> > @@ -1413,7 +1413,7 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int 
> > pnum, int offset, int len)
> > buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL);
> > if (!buf) {
> > ubi_err(ubi, "cannot allocate memory to check for 0xFFs");
> > -   return 0;
> > +   return -ENOMEM;
> 
> I wonder if you shouldn't also nuke the ubi_err() , because when you run
> out of memory, printk() will likely also fail.

No, not really.  printk doesn't allocate memory.

But the ubi_err should be removed because all memory
allocations that fail without a specific GFP_NOWARN
flag already have a dump_stack() call.



[PATCH 3/7] perf tools: Move install-gtk target into rules area

2016-12-04 Thread Jiri Olsa
Following fixdep fix needs all targets at the same area,
so they'll fit under signal condition block.

Moving install-gtk target into rules section.

Link: http://lkml.kernel.org/n/tip-0xk7ca6fdvv6jg71lp40y...@git.kernel.org
Signed-off-by: Jiri Olsa 
---
 tools/perf/Makefile.perf | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 3cb1df43ad3e..2e95456108d7 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -325,11 +325,6 @@ endif
 ifndef NO_GTK2
   ALL_PROGRAMS += $(OUTPUT)libperf-gtk.so
   GTK_IN := $(OUTPUT)gtk-in.o
-
-install-gtk: $(OUTPUT)libperf-gtk.so
-   $(call QUIET_INSTALL, 'GTK UI') \
-   $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(libdir_SQ)'; \
-   $(INSTALL) $(OUTPUT)libperf-gtk.so '$(DESTDIR_SQ)$(libdir_SQ)'
 endif
 
 ifdef ASCIIDOC8
@@ -691,7 +686,14 @@ check: $(OUTPUT)common-cmds.h
 
 ### Installation rules
 
+ifndef NO_GTK2
+install-gtk: $(OUTPUT)libperf-gtk.so
+   $(call QUIET_INSTALL, 'GTK UI') \
+   $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(libdir_SQ)'; \
+   $(INSTALL) $(OUTPUT)libperf-gtk.so '$(DESTDIR_SQ)$(libdir_SQ)'
+else
 install-gtk:
+endif
 
 install-tools: all install-gtk
$(call QUIET_INSTALL, binaries) \
-- 
2.7.4



  1   2   3   >