Re: [PATCH] dt-bindings: Add bindings for aliases node

2018-10-08 Thread Stephen Boyd
Quoting Matthias Kaehlcke (2018-09-25 14:02:55)
> Add a global binding for the 'aliases' node. This includes an initial list
> of standardized alias names for some hardware components that are commonly
> found in 'aliases'.
> 
> Signed-off-by: Matthias Kaehlcke 
> ---
>  Documentation/devicetree/bindings/aliases.txt | 47 +++

Any chance we can get a documentation update for the devicetree spec as
well?

>  1 file changed, 47 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/aliases.txt
> 
> diff --git a/Documentation/devicetree/bindings/aliases.txt 
> b/Documentation/devicetree/bindings/aliases.txt
> new file mode 100644
> index ..d64ed1c7eb34
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/aliases.txt
> @@ -0,0 +1,47 @@
> +The aliases node
> +
> +
> +The aliases node contains properties that represent aliases to device tree
> +nodes. The name of the property is the alias name, the value is the path of
> +a the device tree node that corresponds to the alias. The path may be

s/a //

> +specified as a string or a phandle.
> +
> +Alias names are often suffixed with a numeric ID, especially when there may
> +be multiple instances of the same type. The ID typically corresponds to the
> +hardware layout, it may also be used by drivers for a stable mapping of
> +device names and hardware entities.

Indicate the numeric ID is a u32 or something like that?

> +
> +Alias names
> +---
> +
> +The devicetree specification doesn't require the use of specific alias
> +names to refer to hardware entities of a given type, however the Linux
> +kernel aims for a certain level of consistency.
> +
> +The following standardized alias names shall be used for their
> +corresponding hardware components:
> +
> +  bluetoothN   Bluetooth controller

Can we use syntax like:

bluetooth

to indicate that  is an unsigned integer?

> +  ethernetNEthernet interface
> +  gpioNGPIO controller
> +  i2cN i2c bus
> +  mmcN MMC bus
> +  rtcN Real time clock
> +  serialN  UART port
> +  spiN SPI bus
> +  wifiNWireless network interface
> +
> +The above list is not exhaustive and will be extended over time. Please
> +send patches to devicet...@vger.kernel.org if you think a hardware
> +component and its alias name should be on the list.
> +


Re: [PATCH] dt-bindings: Add bindings for aliases node

2018-10-08 Thread Stephen Boyd
Quoting Matthias Kaehlcke (2018-09-25 14:02:55)
> Add a global binding for the 'aliases' node. This includes an initial list
> of standardized alias names for some hardware components that are commonly
> found in 'aliases'.
> 
> Signed-off-by: Matthias Kaehlcke 
> ---
>  Documentation/devicetree/bindings/aliases.txt | 47 +++

Any chance we can get a documentation update for the devicetree spec as
well?

>  1 file changed, 47 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/aliases.txt
> 
> diff --git a/Documentation/devicetree/bindings/aliases.txt 
> b/Documentation/devicetree/bindings/aliases.txt
> new file mode 100644
> index ..d64ed1c7eb34
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/aliases.txt
> @@ -0,0 +1,47 @@
> +The aliases node
> +
> +
> +The aliases node contains properties that represent aliases to device tree
> +nodes. The name of the property is the alias name, the value is the path of
> +a the device tree node that corresponds to the alias. The path may be

s/a //

> +specified as a string or a phandle.
> +
> +Alias names are often suffixed with a numeric ID, especially when there may
> +be multiple instances of the same type. The ID typically corresponds to the
> +hardware layout, it may also be used by drivers for a stable mapping of
> +device names and hardware entities.

Indicate the numeric ID is a u32 or something like that?

> +
> +Alias names
> +---
> +
> +The devicetree specification doesn't require the use of specific alias
> +names to refer to hardware entities of a given type, however the Linux
> +kernel aims for a certain level of consistency.
> +
> +The following standardized alias names shall be used for their
> +corresponding hardware components:
> +
> +  bluetoothN   Bluetooth controller

Can we use syntax like:

bluetooth

to indicate that  is an unsigned integer?

> +  ethernetNEthernet interface
> +  gpioNGPIO controller
> +  i2cN i2c bus
> +  mmcN MMC bus
> +  rtcN Real time clock
> +  serialN  UART port
> +  spiN SPI bus
> +  wifiNWireless network interface
> +
> +The above list is not exhaustive and will be extended over time. Please
> +send patches to devicet...@vger.kernel.org if you think a hardware
> +component and its alias name should be on the list.
> +


[tip:irq/core] genirq: Fix grammar s/an /a /

2018-10-08 Thread tip-bot for Geert Uytterhoeven
Commit-ID:  b8d62f33b7b225935649ab165d901fe8dd7f95e5
Gitweb: https://git.kernel.org/tip/b8d62f33b7b225935649ab165d901fe8dd7f95e5
Author: Geert Uytterhoeven 
AuthorDate: Mon, 8 Oct 2018 13:17:26 +0200
Committer:  Ingo Molnar 
CommitDate: Tue, 9 Oct 2018 07:50:41 +0200

genirq: Fix grammar s/an /a /

Fix a grammar mistake in .

[ mingo: While at it also fix another similar error in another comment as well. 
]

Signed-off-by: Geert Uytterhoeven 
Cc: Jiri Kosina 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: http://lkml.kernel.org/r/20181008111726.26286-1-geert%2brene...@glider.be
Signed-off-by: Ingo Molnar 
---
 include/linux/interrupt.h | 2 +-
 kernel/irq/irqdomain.c| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index eeceac3376fc..1d6711c28271 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -45,7 +45,7 @@
  * IRQF_PERCPU - Interrupt is per cpu
  * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
  * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is
- *registered first in an shared interrupt is considered for
+ *registered first in a shared interrupt is considered for
  *performance reasons)
  * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler 
finished.
  *Used by threaded interrupts which need to keep the
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 3b30a4aeb0db..3366d11c3e02 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -867,7 +867,7 @@ void irq_dispose_mapping(unsigned int virq)
 EXPORT_SYMBOL_GPL(irq_dispose_mapping);
 
 /**
- * irq_find_mapping() - Find a linux irq from an hw irq number.
+ * irq_find_mapping() - Find a linux irq from a hw irq number.
  * @domain: domain owning this hardware interrupt
  * @hwirq: hardware irq number in that domain space
  */


[tip:irq/core] genirq: Fix grammar s/an /a /

2018-10-08 Thread tip-bot for Geert Uytterhoeven
Commit-ID:  b8d62f33b7b225935649ab165d901fe8dd7f95e5
Gitweb: https://git.kernel.org/tip/b8d62f33b7b225935649ab165d901fe8dd7f95e5
Author: Geert Uytterhoeven 
AuthorDate: Mon, 8 Oct 2018 13:17:26 +0200
Committer:  Ingo Molnar 
CommitDate: Tue, 9 Oct 2018 07:50:41 +0200

genirq: Fix grammar s/an /a /

Fix a grammar mistake in .

[ mingo: While at it also fix another similar error in another comment as well. 
]

Signed-off-by: Geert Uytterhoeven 
Cc: Jiri Kosina 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: http://lkml.kernel.org/r/20181008111726.26286-1-geert%2brene...@glider.be
Signed-off-by: Ingo Molnar 
---
 include/linux/interrupt.h | 2 +-
 kernel/irq/irqdomain.c| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index eeceac3376fc..1d6711c28271 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -45,7 +45,7 @@
  * IRQF_PERCPU - Interrupt is per cpu
  * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
  * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is
- *registered first in an shared interrupt is considered for
+ *registered first in a shared interrupt is considered for
  *performance reasons)
  * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler 
finished.
  *Used by threaded interrupts which need to keep the
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 3b30a4aeb0db..3366d11c3e02 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -867,7 +867,7 @@ void irq_dispose_mapping(unsigned int virq)
 EXPORT_SYMBOL_GPL(irq_dispose_mapping);
 
 /**
- * irq_find_mapping() - Find a linux irq from an hw irq number.
+ * irq_find_mapping() - Find a linux irq from a hw irq number.
  * @domain: domain owning this hardware interrupt
  * @hwirq: hardware irq number in that domain space
  */


[PATCH 6/7] dmaengine: stm32-dma: fix max items per transfer

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

Having 0 in item counter register is valid and stands for a "No or Ended
transfer". Therefore valid transfer starts from @+0 to @+0xFFFE leading to
unaligned scatter gather at boundary. Thus it's safer to round down this
value on its FIFO size (16 Bytes).

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index b40486454a2c..05a2974cd2c0 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -38,10 +38,6 @@
 #define STM32_DMA_TEI  BIT(3) /* Transfer Error Interrupt */
 #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */
 #define STM32_DMA_FEI  BIT(0) /* FIFO Error Interrupt */
-#define STM32_DMA_MASKI(STM32_DMA_TCI \
-| STM32_DMA_TEI \
-| STM32_DMA_DMEI \
-| STM32_DMA_FEI)
 
 /* DMA Stream x Configuration Register */
 #define STM32_DMA_SCR(x)   (0x0010 + 0x18 * (x)) /* x = 0..7 */
@@ -118,6 +114,13 @@
 #define STM32_DMA_FIFO_THRESHOLD_FULL  0x03
 
 #define STM32_DMA_MAX_DATA_ITEMS   0x
+/*
+ * Valid transfer starts from @0 to @0xFFFE leading to unaligned scatter
+ * gather at boundary. Thus it's safer to round down this value on FIFO
+ * size (16 Bytes)
+ */
+#define STM32_DMA_ALIGNED_MAX_DATA_ITEMS   \
+   ALIGN_DOWN(STM32_DMA_MAX_DATA_ITEMS, 16)
 #define STM32_DMA_MAX_CHANNELS 0x08
 #define STM32_DMA_MAX_REQUEST_ID   0x08
 #define STM32_DMA_MAX_DATA_PARAM   0x03
@@ -869,7 +872,7 @@ static struct dma_async_tx_descriptor 
*stm32_dma_prep_slave_sg(
desc->sg_req[i].len = sg_dma_len(sg);
 
nb_data_items = desc->sg_req[i].len / buswidth;
-   if (nb_data_items > STM32_DMA_MAX_DATA_ITEMS) {
+   if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) {
dev_err(chan2dev(chan), "nb items not supported\n");
goto err;
}
@@ -935,7 +938,7 @@ static struct dma_async_tx_descriptor 
*stm32_dma_prep_dma_cyclic(
return NULL;
 
nb_data_items = period_len / buswidth;
-   if (nb_data_items > STM32_DMA_MAX_DATA_ITEMS) {
+   if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) {
dev_err(chan2dev(chan), "number of items not supported\n");
return NULL;
}
@@ -985,7 +988,7 @@ static struct dma_async_tx_descriptor 
*stm32_dma_prep_dma_memcpy(
u32 num_sgs, best_burst, dma_burst, threshold;
int i;
 
-   num_sgs = DIV_ROUND_UP(len, STM32_DMA_MAX_DATA_ITEMS);
+   num_sgs = DIV_ROUND_UP(len, STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
desc = stm32_dma_alloc_desc(num_sgs);
if (!desc)
return NULL;
@@ -994,7 +997,7 @@ static struct dma_async_tx_descriptor 
*stm32_dma_prep_dma_memcpy(
 
for (offset = 0, i = 0; offset < len; offset += xfer_count, i++) {
xfer_count = min_t(size_t, len - offset,
-  STM32_DMA_MAX_DATA_ITEMS);
+  STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
 
/* Compute best burst size */
max_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
-- 
2.19.0.605.g01d371f741-goog



[PATCH 6/7] dmaengine: stm32-dma: fix max items per transfer

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

Having 0 in item counter register is valid and stands for a "No or Ended
transfer". Therefore valid transfer starts from @+0 to @+0xFFFE leading to
unaligned scatter gather at boundary. Thus it's safer to round down this
value on its FIFO size (16 Bytes).

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index b40486454a2c..05a2974cd2c0 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -38,10 +38,6 @@
 #define STM32_DMA_TEI  BIT(3) /* Transfer Error Interrupt */
 #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */
 #define STM32_DMA_FEI  BIT(0) /* FIFO Error Interrupt */
-#define STM32_DMA_MASKI(STM32_DMA_TCI \
-| STM32_DMA_TEI \
-| STM32_DMA_DMEI \
-| STM32_DMA_FEI)
 
 /* DMA Stream x Configuration Register */
 #define STM32_DMA_SCR(x)   (0x0010 + 0x18 * (x)) /* x = 0..7 */
@@ -118,6 +114,13 @@
 #define STM32_DMA_FIFO_THRESHOLD_FULL  0x03
 
 #define STM32_DMA_MAX_DATA_ITEMS   0x
+/*
+ * Valid transfer starts from @0 to @0xFFFE leading to unaligned scatter
+ * gather at boundary. Thus it's safer to round down this value on FIFO
+ * size (16 Bytes)
+ */
+#define STM32_DMA_ALIGNED_MAX_DATA_ITEMS   \
+   ALIGN_DOWN(STM32_DMA_MAX_DATA_ITEMS, 16)
 #define STM32_DMA_MAX_CHANNELS 0x08
 #define STM32_DMA_MAX_REQUEST_ID   0x08
 #define STM32_DMA_MAX_DATA_PARAM   0x03
@@ -869,7 +872,7 @@ static struct dma_async_tx_descriptor 
*stm32_dma_prep_slave_sg(
desc->sg_req[i].len = sg_dma_len(sg);
 
nb_data_items = desc->sg_req[i].len / buswidth;
-   if (nb_data_items > STM32_DMA_MAX_DATA_ITEMS) {
+   if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) {
dev_err(chan2dev(chan), "nb items not supported\n");
goto err;
}
@@ -935,7 +938,7 @@ static struct dma_async_tx_descriptor 
*stm32_dma_prep_dma_cyclic(
return NULL;
 
nb_data_items = period_len / buswidth;
-   if (nb_data_items > STM32_DMA_MAX_DATA_ITEMS) {
+   if (nb_data_items > STM32_DMA_ALIGNED_MAX_DATA_ITEMS) {
dev_err(chan2dev(chan), "number of items not supported\n");
return NULL;
}
@@ -985,7 +988,7 @@ static struct dma_async_tx_descriptor 
*stm32_dma_prep_dma_memcpy(
u32 num_sgs, best_burst, dma_burst, threshold;
int i;
 
-   num_sgs = DIV_ROUND_UP(len, STM32_DMA_MAX_DATA_ITEMS);
+   num_sgs = DIV_ROUND_UP(len, STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
desc = stm32_dma_alloc_desc(num_sgs);
if (!desc)
return NULL;
@@ -994,7 +997,7 @@ static struct dma_async_tx_descriptor 
*stm32_dma_prep_dma_memcpy(
 
for (offset = 0, i = 0; offset < len; offset += xfer_count, i++) {
xfer_count = min_t(size_t, len - offset,
-  STM32_DMA_MAX_DATA_ITEMS);
+  STM32_DMA_ALIGNED_MAX_DATA_ITEMS);
 
/* Compute best burst size */
max_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
-- 
2.19.0.605.g01d371f741-goog



[PATCH 7/7] dmaengine: stm32-dma: properly mask irq bits

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

A single register of the controller holds the information for four dma
channels.
The functions stm32_dma_irq_status() don't mask the relevant bits after
the shift, thus adjacent channel's status is also reported in the returned
value.
Fixed by masking the value before returning it.

Similarly, the function stm32_dma_irq_clear() don't mask the input value
before shifting it, thus an incorrect input value could disable the
interrupts of adjacent channels.
Fixed by masking the input value before using it.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Antonio Borneo 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 05a2974cd2c0..8c5807362a25 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -38,6 +38,10 @@
 #define STM32_DMA_TEI  BIT(3) /* Transfer Error Interrupt */
 #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */
 #define STM32_DMA_FEI  BIT(0) /* FIFO Error Interrupt */
+#define STM32_DMA_MASKI(STM32_DMA_TCI \
+| STM32_DMA_TEI \
+| STM32_DMA_DMEI \
+| STM32_DMA_FEI)
 
 /* DMA Stream x Configuration Register */
 #define STM32_DMA_SCR(x)   (0x0010 + 0x18 * (x)) /* x = 0..7 */
@@ -405,7 +409,7 @@ static u32 stm32_dma_irq_status(struct stm32_dma_chan *chan)
 
flags = dma_isr >> (((chan->id & 2) << 3) | ((chan->id & 1) * 6));
 
-   return flags;
+   return flags & STM32_DMA_MASKI;
 }
 
 static void stm32_dma_irq_clear(struct stm32_dma_chan *chan, u32 flags)
@@ -420,6 +424,7 @@ static void stm32_dma_irq_clear(struct stm32_dma_chan 
*chan, u32 flags)
 * If (ch % 4) is 2 or 3, left shift the mask by 16 bits.
 * If (ch % 4) is 1 or 3, additionally left shift the mask by 6 bits.
 */
+   flags &= STM32_DMA_MASKI;
dma_ifcr = flags << (((chan->id & 2) << 3) | ((chan->id & 1) * 6));
 
if (chan->id & 4)
-- 
2.19.0.605.g01d371f741-goog



[PATCH 7/7] dmaengine: stm32-dma: properly mask irq bits

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

A single register of the controller holds the information for four dma
channels.
The functions stm32_dma_irq_status() don't mask the relevant bits after
the shift, thus adjacent channel's status is also reported in the returned
value.
Fixed by masking the value before returning it.

Similarly, the function stm32_dma_irq_clear() don't mask the input value
before shifting it, thus an incorrect input value could disable the
interrupts of adjacent channels.
Fixed by masking the input value before using it.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Antonio Borneo 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 05a2974cd2c0..8c5807362a25 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -38,6 +38,10 @@
 #define STM32_DMA_TEI  BIT(3) /* Transfer Error Interrupt */
 #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */
 #define STM32_DMA_FEI  BIT(0) /* FIFO Error Interrupt */
+#define STM32_DMA_MASKI(STM32_DMA_TCI \
+| STM32_DMA_TEI \
+| STM32_DMA_DMEI \
+| STM32_DMA_FEI)
 
 /* DMA Stream x Configuration Register */
 #define STM32_DMA_SCR(x)   (0x0010 + 0x18 * (x)) /* x = 0..7 */
@@ -405,7 +409,7 @@ static u32 stm32_dma_irq_status(struct stm32_dma_chan *chan)
 
flags = dma_isr >> (((chan->id & 2) << 3) | ((chan->id & 1) * 6));
 
-   return flags;
+   return flags & STM32_DMA_MASKI;
 }
 
 static void stm32_dma_irq_clear(struct stm32_dma_chan *chan, u32 flags)
@@ -420,6 +424,7 @@ static void stm32_dma_irq_clear(struct stm32_dma_chan 
*chan, u32 flags)
 * If (ch % 4) is 2 or 3, left shift the mask by 16 bits.
 * If (ch % 4) is 1 or 3, additionally left shift the mask by 6 bits.
 */
+   flags &= STM32_DMA_MASKI;
dma_ifcr = flags << (((chan->id & 2) << 3) | ((chan->id & 1) * 6));
 
if (chan->id & 4)
-- 
2.19.0.605.g01d371f741-goog



[PATCH 4/7] dmaengine: stm32-dma: Improve memory burst management

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

This patch improves memory burst capability using best burst size
according to transferred buffer size from/to memory.

>From now on, memory burst is not necessarily same as with peripheral
burst one and fifo threshold is directly managed by this driver in order
to fit with computed memory burst.

Signed-off-by: M'boumba Cedric Madianga 
Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 204 ++--
 1 file changed, 175 insertions(+), 29 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index b64e14a83dec..21ad359a5a59 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -5,6 +5,7 @@
  *
  * Copyright (C) M'boumba Cedric Madianga 2015
  * Author: M'boumba Cedric Madianga 
+ * Pierre-Yves Mordret 
  *
  * License terms:  GNU General Public License (GPL), version 2
  */
@@ -115,6 +116,8 @@
 #define STM32_DMA_MAX_CHANNELS 0x08
 #define STM32_DMA_MAX_REQUEST_ID   0x08
 #define STM32_DMA_MAX_DATA_PARAM   0x03
+#define STM32_DMA_FIFO_SIZE16  /* FIFO is 16 bytes */
+#define STM32_DMA_MIN_BURST4
 #define STM32_DMA_MAX_BURST16
 
 /* DMA Features */
@@ -184,6 +187,8 @@ struct stm32_dma_chan {
struct dma_slave_config dma_sconfig;
struct stm32_dma_chan_reg chan_reg;
u32 threshold;
+   u32 mem_burst;
+   u32 mem_width;
 };
 
 struct stm32_dma_device {
@@ -248,6 +253,85 @@ static int stm32_dma_get_width(struct stm32_dma_chan *chan,
}
 }
 
+static enum dma_slave_buswidth stm32_dma_get_max_width(u32 buf_len,
+  u32 threshold)
+{
+   enum dma_slave_buswidth max_width;
+
+   if (threshold == STM32_DMA_FIFO_THRESHOLD_FULL)
+   max_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+   else
+   max_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
+
+   while ((buf_len < max_width  || buf_len % max_width) &&
+  max_width > DMA_SLAVE_BUSWIDTH_1_BYTE)
+   max_width = max_width >> 1;
+
+   return max_width;
+}
+
+static bool stm32_dma_fifo_threshold_is_allowed(u32 burst, u32 threshold,
+   enum dma_slave_buswidth width)
+{
+   u32 remaining;
+
+   if (width != DMA_SLAVE_BUSWIDTH_UNDEFINED) {
+   if (burst != 0) {
+   /*
+* If number of beats fit in several whole bursts
+* this configuration is allowed.
+*/
+   remaining = ((STM32_DMA_FIFO_SIZE / width) *
+(threshold + 1) / 4) % burst;
+
+   if (remaining == 0)
+   return true;
+   } else {
+   return true;
+   }
+   }
+
+   return false;
+}
+
+static bool stm32_dma_is_burst_possible(u32 buf_len, u32 threshold)
+{
+   switch (threshold) {
+   case STM32_DMA_FIFO_THRESHOLD_FULL:
+   if (buf_len >= STM32_DMA_MAX_BURST)
+   return true;
+   else
+   return false;
+   case STM32_DMA_FIFO_THRESHOLD_HALFFULL:
+   if (buf_len >= STM32_DMA_MAX_BURST / 2)
+   return true;
+   else
+   return false;
+   default:
+   return false;
+   }
+}
+
+static u32 stm32_dma_get_best_burst(u32 buf_len, u32 max_burst, u32 threshold,
+   enum dma_slave_buswidth width)
+{
+   u32 best_burst = max_burst;
+
+   if (best_burst == 1 || !stm32_dma_is_burst_possible(buf_len, threshold))
+   return 0;
+
+   while ((buf_len < best_burst * width && best_burst > 1) ||
+  !stm32_dma_fifo_threshold_is_allowed(best_burst, threshold,
+   width)) {
+   if (best_burst > STM32_DMA_MIN_BURST)
+   best_burst = best_burst >> 1;
+   else
+   best_burst = 0;
+   }
+
+   return best_burst;
+}
+
 static int stm32_dma_get_burst(struct stm32_dma_chan *chan, u32 maxburst)
 {
switch (maxburst) {
@@ -267,12 +351,12 @@ static int stm32_dma_get_burst(struct stm32_dma_chan 
*chan, u32 maxburst)
 }
 
 static void stm32_dma_set_fifo_config(struct stm32_dma_chan *chan,
- u32 src_maxburst, u32 dst_maxburst)
+ u32 src_burst, u32 dst_burst)
 {
chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_MASK;
chan->chan_reg.dma_scr &= ~STM32_DMA_SCR_DMEIE;
 
-   if ((!src_maxburst) && (!dst_maxburst)) {
+   if (!src_burst && !dst_burst) {
/* Using direct mode */
chan->chan_reg.dma_scr |= STM32_DMA_SCR_DMEIE;
} else {
@@ -589,37 

[PATCH 4/7] dmaengine: stm32-dma: Improve memory burst management

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

This patch improves memory burst capability using best burst size
according to transferred buffer size from/to memory.

>From now on, memory burst is not necessarily same as with peripheral
burst one and fifo threshold is directly managed by this driver in order
to fit with computed memory burst.

Signed-off-by: M'boumba Cedric Madianga 
Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 204 ++--
 1 file changed, 175 insertions(+), 29 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index b64e14a83dec..21ad359a5a59 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -5,6 +5,7 @@
  *
  * Copyright (C) M'boumba Cedric Madianga 2015
  * Author: M'boumba Cedric Madianga 
+ * Pierre-Yves Mordret 
  *
  * License terms:  GNU General Public License (GPL), version 2
  */
@@ -115,6 +116,8 @@
 #define STM32_DMA_MAX_CHANNELS 0x08
 #define STM32_DMA_MAX_REQUEST_ID   0x08
 #define STM32_DMA_MAX_DATA_PARAM   0x03
+#define STM32_DMA_FIFO_SIZE16  /* FIFO is 16 bytes */
+#define STM32_DMA_MIN_BURST4
 #define STM32_DMA_MAX_BURST16
 
 /* DMA Features */
@@ -184,6 +187,8 @@ struct stm32_dma_chan {
struct dma_slave_config dma_sconfig;
struct stm32_dma_chan_reg chan_reg;
u32 threshold;
+   u32 mem_burst;
+   u32 mem_width;
 };
 
 struct stm32_dma_device {
@@ -248,6 +253,85 @@ static int stm32_dma_get_width(struct stm32_dma_chan *chan,
}
 }
 
+static enum dma_slave_buswidth stm32_dma_get_max_width(u32 buf_len,
+  u32 threshold)
+{
+   enum dma_slave_buswidth max_width;
+
+   if (threshold == STM32_DMA_FIFO_THRESHOLD_FULL)
+   max_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+   else
+   max_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
+
+   while ((buf_len < max_width  || buf_len % max_width) &&
+  max_width > DMA_SLAVE_BUSWIDTH_1_BYTE)
+   max_width = max_width >> 1;
+
+   return max_width;
+}
+
+static bool stm32_dma_fifo_threshold_is_allowed(u32 burst, u32 threshold,
+   enum dma_slave_buswidth width)
+{
+   u32 remaining;
+
+   if (width != DMA_SLAVE_BUSWIDTH_UNDEFINED) {
+   if (burst != 0) {
+   /*
+* If number of beats fit in several whole bursts
+* this configuration is allowed.
+*/
+   remaining = ((STM32_DMA_FIFO_SIZE / width) *
+(threshold + 1) / 4) % burst;
+
+   if (remaining == 0)
+   return true;
+   } else {
+   return true;
+   }
+   }
+
+   return false;
+}
+
+static bool stm32_dma_is_burst_possible(u32 buf_len, u32 threshold)
+{
+   switch (threshold) {
+   case STM32_DMA_FIFO_THRESHOLD_FULL:
+   if (buf_len >= STM32_DMA_MAX_BURST)
+   return true;
+   else
+   return false;
+   case STM32_DMA_FIFO_THRESHOLD_HALFFULL:
+   if (buf_len >= STM32_DMA_MAX_BURST / 2)
+   return true;
+   else
+   return false;
+   default:
+   return false;
+   }
+}
+
+static u32 stm32_dma_get_best_burst(u32 buf_len, u32 max_burst, u32 threshold,
+   enum dma_slave_buswidth width)
+{
+   u32 best_burst = max_burst;
+
+   if (best_burst == 1 || !stm32_dma_is_burst_possible(buf_len, threshold))
+   return 0;
+
+   while ((buf_len < best_burst * width && best_burst > 1) ||
+  !stm32_dma_fifo_threshold_is_allowed(best_burst, threshold,
+   width)) {
+   if (best_burst > STM32_DMA_MIN_BURST)
+   best_burst = best_burst >> 1;
+   else
+   best_burst = 0;
+   }
+
+   return best_burst;
+}
+
 static int stm32_dma_get_burst(struct stm32_dma_chan *chan, u32 maxburst)
 {
switch (maxburst) {
@@ -267,12 +351,12 @@ static int stm32_dma_get_burst(struct stm32_dma_chan 
*chan, u32 maxburst)
 }
 
 static void stm32_dma_set_fifo_config(struct stm32_dma_chan *chan,
- u32 src_maxburst, u32 dst_maxburst)
+ u32 src_burst, u32 dst_burst)
 {
chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_MASK;
chan->chan_reg.dma_scr &= ~STM32_DMA_SCR_DMEIE;
 
-   if ((!src_maxburst) && (!dst_maxburst)) {
+   if (!src_burst && !dst_burst) {
/* Using direct mode */
chan->chan_reg.dma_scr |= STM32_DMA_SCR_DMEIE;
} else {
@@ -589,37 

[PATCH 3/7] dmaengine: stm32-dma: fix typo and reported checkpatch warnings

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

Fix typo in a comment and solved reported checkpatch warnings.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index fae7de54f00a..b64e14a83dec 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -60,7 +60,8 @@
 #define STM32_DMA_SCR_PINC BIT(9) /* Peripheral increment mode */
 #define STM32_DMA_SCR_CIRC BIT(8) /* Circular mode */
 #define STM32_DMA_SCR_PFCTRL   BIT(5) /* Peripheral Flow Controller */
-#define STM32_DMA_SCR_TCIE BIT(4) /* Transfer Cplete Int Enable*/
+#define STM32_DMA_SCR_TCIE BIT(4) /* Transfer Complete Int Enable
+   */
 #define STM32_DMA_SCR_TEIE BIT(2) /* Transfer Error Int Enable */
 #define STM32_DMA_SCR_DMEIEBIT(1) /* Direct Mode Err Int Enable */
 #define STM32_DMA_SCR_EN   BIT(0) /* Stream Enable */
@@ -918,7 +919,7 @@ static enum dma_status stm32_dma_tx_status(struct dma_chan 
*c,
u32 residue = 0;
 
status = dma_cookie_status(c, cookie, state);
-   if ((status == DMA_COMPLETE) || (!state))
+   if (status == DMA_COMPLETE || !state)
return status;
 
spin_lock_irqsave(>vchan.lock, flags);
@@ -982,7 +983,7 @@ static void stm32_dma_desc_free(struct virt_dma_desc *vdesc)
 }
 
 static void stm32_dma_set_config(struct stm32_dma_chan *chan,
- struct stm32_dma_cfg *cfg)
+struct stm32_dma_cfg *cfg)
 {
stm32_dma_clear_reg(>chan_reg);
 
@@ -1015,8 +1016,8 @@ static struct dma_chan *stm32_dma_of_xlate(struct 
of_phandle_args *dma_spec,
cfg.stream_config = dma_spec->args[2];
cfg.features = dma_spec->args[3];
 
-   if ((cfg.channel_id >= STM32_DMA_MAX_CHANNELS) ||
-   (cfg.request_line >= STM32_DMA_MAX_REQUEST_ID)) {
+   if (cfg.channel_id >= STM32_DMA_MAX_CHANNELS ||
+   cfg.request_line >= STM32_DMA_MAX_REQUEST_ID) {
dev_err(dev, "Bad channel and/or request id\n");
return NULL;
}
-- 
2.19.0.605.g01d371f741-goog



[PATCH 5/7] dmaengine: stm32-dma: fix DMA IRQ status handling

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

Update the way Transfer Complete and Half Transfer Complete status are
acknowledge. Even if HTI is not enabled its status is shown when reading
registers, driver has to clear it gently and not raise an error.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 29 +
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 21ad359a5a59..b40486454a2c 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -34,9 +34,14 @@
 #define STM32_DMA_LIFCR0x0008 /* DMA Low Int Flag 
Clear Reg */
 #define STM32_DMA_HIFCR0x000c /* DMA High Int Flag 
Clear Reg */
 #define STM32_DMA_TCI  BIT(5) /* Transfer Complete Interrupt */
+#define STM32_DMA_HTI  BIT(4) /* Half Transfer Interrupt */
 #define STM32_DMA_TEI  BIT(3) /* Transfer Error Interrupt */
 #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */
 #define STM32_DMA_FEI  BIT(0) /* FIFO Error Interrupt */
+#define STM32_DMA_MASKI(STM32_DMA_TCI \
+| STM32_DMA_TEI \
+| STM32_DMA_DMEI \
+| STM32_DMA_FEI)
 
 /* DMA Stream x Configuration Register */
 #define STM32_DMA_SCR(x)   (0x0010 + 0x18 * (x)) /* x = 0..7 */
@@ -643,13 +648,29 @@ static irqreturn_t stm32_dma_chan_irq(int irq, void 
*devid)
status = stm32_dma_irq_status(chan);
scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id));
 
-   if ((status & STM32_DMA_TCI) && (scr & STM32_DMA_SCR_TCIE)) {
+   if (status & STM32_DMA_TCI) {
stm32_dma_irq_clear(chan, STM32_DMA_TCI);
-   stm32_dma_handle_chan_done(chan);
-
-   } else {
+   if (scr & STM32_DMA_SCR_TCIE)
+   stm32_dma_handle_chan_done(chan);
+   status &= ~STM32_DMA_TCI;
+   }
+   if (status & STM32_DMA_HTI) {
+   stm32_dma_irq_clear(chan, STM32_DMA_HTI);
+   status &= ~STM32_DMA_HTI;
+   }
+   if (status & STM32_DMA_FEI) {
+   stm32_dma_irq_clear(chan, STM32_DMA_FEI);
+   status &= ~STM32_DMA_FEI;
+   if (!(scr & STM32_DMA_SCR_EN))
+   dev_err(chan2dev(chan), "FIFO Error\n");
+   else
+   dev_dbg(chan2dev(chan), "FIFO over/underrun\n");
+   }
+   if (status) {
stm32_dma_irq_clear(chan, status);
dev_err(chan2dev(chan), "DMA error: status=0x%08x\n", status);
+   if (!(scr & STM32_DMA_SCR_EN))
+   dev_err(chan2dev(chan), "chan disabled by HW\n");
}
 
spin_unlock(>vchan.lock);
-- 
2.19.0.605.g01d371f741-goog



[PATCH 3/7] dmaengine: stm32-dma: fix typo and reported checkpatch warnings

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

Fix typo in a comment and solved reported checkpatch warnings.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index fae7de54f00a..b64e14a83dec 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -60,7 +60,8 @@
 #define STM32_DMA_SCR_PINC BIT(9) /* Peripheral increment mode */
 #define STM32_DMA_SCR_CIRC BIT(8) /* Circular mode */
 #define STM32_DMA_SCR_PFCTRL   BIT(5) /* Peripheral Flow Controller */
-#define STM32_DMA_SCR_TCIE BIT(4) /* Transfer Cplete Int Enable*/
+#define STM32_DMA_SCR_TCIE BIT(4) /* Transfer Complete Int Enable
+   */
 #define STM32_DMA_SCR_TEIE BIT(2) /* Transfer Error Int Enable */
 #define STM32_DMA_SCR_DMEIEBIT(1) /* Direct Mode Err Int Enable */
 #define STM32_DMA_SCR_EN   BIT(0) /* Stream Enable */
@@ -918,7 +919,7 @@ static enum dma_status stm32_dma_tx_status(struct dma_chan 
*c,
u32 residue = 0;
 
status = dma_cookie_status(c, cookie, state);
-   if ((status == DMA_COMPLETE) || (!state))
+   if (status == DMA_COMPLETE || !state)
return status;
 
spin_lock_irqsave(>vchan.lock, flags);
@@ -982,7 +983,7 @@ static void stm32_dma_desc_free(struct virt_dma_desc *vdesc)
 }
 
 static void stm32_dma_set_config(struct stm32_dma_chan *chan,
- struct stm32_dma_cfg *cfg)
+struct stm32_dma_cfg *cfg)
 {
stm32_dma_clear_reg(>chan_reg);
 
@@ -1015,8 +1016,8 @@ static struct dma_chan *stm32_dma_of_xlate(struct 
of_phandle_args *dma_spec,
cfg.stream_config = dma_spec->args[2];
cfg.features = dma_spec->args[3];
 
-   if ((cfg.channel_id >= STM32_DMA_MAX_CHANNELS) ||
-   (cfg.request_line >= STM32_DMA_MAX_REQUEST_ID)) {
+   if (cfg.channel_id >= STM32_DMA_MAX_CHANNELS ||
+   cfg.request_line >= STM32_DMA_MAX_REQUEST_ID) {
dev_err(dev, "Bad channel and/or request id\n");
return NULL;
}
-- 
2.19.0.605.g01d371f741-goog



[PATCH 5/7] dmaengine: stm32-dma: fix DMA IRQ status handling

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

Update the way Transfer Complete and Half Transfer Complete status are
acknowledge. Even if HTI is not enabled its status is shown when reading
registers, driver has to clear it gently and not raise an error.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 29 +
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 21ad359a5a59..b40486454a2c 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -34,9 +34,14 @@
 #define STM32_DMA_LIFCR0x0008 /* DMA Low Int Flag 
Clear Reg */
 #define STM32_DMA_HIFCR0x000c /* DMA High Int Flag 
Clear Reg */
 #define STM32_DMA_TCI  BIT(5) /* Transfer Complete Interrupt */
+#define STM32_DMA_HTI  BIT(4) /* Half Transfer Interrupt */
 #define STM32_DMA_TEI  BIT(3) /* Transfer Error Interrupt */
 #define STM32_DMA_DMEI BIT(2) /* Direct Mode Error Interrupt */
 #define STM32_DMA_FEI  BIT(0) /* FIFO Error Interrupt */
+#define STM32_DMA_MASKI(STM32_DMA_TCI \
+| STM32_DMA_TEI \
+| STM32_DMA_DMEI \
+| STM32_DMA_FEI)
 
 /* DMA Stream x Configuration Register */
 #define STM32_DMA_SCR(x)   (0x0010 + 0x18 * (x)) /* x = 0..7 */
@@ -643,13 +648,29 @@ static irqreturn_t stm32_dma_chan_irq(int irq, void 
*devid)
status = stm32_dma_irq_status(chan);
scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id));
 
-   if ((status & STM32_DMA_TCI) && (scr & STM32_DMA_SCR_TCIE)) {
+   if (status & STM32_DMA_TCI) {
stm32_dma_irq_clear(chan, STM32_DMA_TCI);
-   stm32_dma_handle_chan_done(chan);
-
-   } else {
+   if (scr & STM32_DMA_SCR_TCIE)
+   stm32_dma_handle_chan_done(chan);
+   status &= ~STM32_DMA_TCI;
+   }
+   if (status & STM32_DMA_HTI) {
+   stm32_dma_irq_clear(chan, STM32_DMA_HTI);
+   status &= ~STM32_DMA_HTI;
+   }
+   if (status & STM32_DMA_FEI) {
+   stm32_dma_irq_clear(chan, STM32_DMA_FEI);
+   status &= ~STM32_DMA_FEI;
+   if (!(scr & STM32_DMA_SCR_EN))
+   dev_err(chan2dev(chan), "FIFO Error\n");
+   else
+   dev_dbg(chan2dev(chan), "FIFO over/underrun\n");
+   }
+   if (status) {
stm32_dma_irq_clear(chan, status);
dev_err(chan2dev(chan), "DMA error: status=0x%08x\n", status);
+   if (!(scr & STM32_DMA_SCR_EN))
+   dev_err(chan2dev(chan), "chan disabled by HW\n");
}
 
spin_unlock(>vchan.lock);
-- 
2.19.0.605.g01d371f741-goog



[PATCH 2/7] dmaengine: stm32-dma: fix incomplete configuration in cyclic mode

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

When in cyclic mode, the configuration is updated after having started the
DMA hardware (STM32_DMA_SCR_EN) leading to incomplete configuration of
SMxAR registers.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Hugues Fruchet 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 4099948b6914..fae7de54f00a 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -441,6 +441,8 @@ static void stm32_dma_dump_reg(struct stm32_dma_chan *chan)
dev_dbg(chan2dev(chan), "SFCR:  0x%08x\n", sfcr);
 }
 
+static void stm32_dma_configure_next_sg(struct stm32_dma_chan *chan);
+
 static void stm32_dma_start_transfer(struct stm32_dma_chan *chan)
 {
struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
@@ -483,6 +485,9 @@ static void stm32_dma_start_transfer(struct stm32_dma_chan 
*chan)
if (status)
stm32_dma_irq_clear(chan, status);
 
+   if (chan->desc->cyclic)
+   stm32_dma_configure_next_sg(chan);
+
stm32_dma_dump_reg(chan);
 
/* Start DMA */
@@ -576,8 +581,7 @@ static void stm32_dma_issue_pending(struct dma_chan *c)
if (vchan_issue_pending(>vchan) && !chan->desc && !chan->busy) {
dev_dbg(chan2dev(chan), "vchan %p: issued\n", >vchan);
stm32_dma_start_transfer(chan);
-   if (chan->desc->cyclic)
-   stm32_dma_configure_next_sg(chan);
+
}
spin_unlock_irqrestore(>vchan.lock, flags);
 }
-- 
2.19.0.605.g01d371f741-goog



[PATCH 0/7] NULL pointer deref fix for stm32-dma

2018-10-08 Thread Joel Fernandes (Google)
Hi Greg,

While looking at android-4.14, I found a NULL pointer deref with
stm32-dma driver using Coccicheck errors. I found that upstream had a
bunch of patches on stm32-dma that have fixed this and other issues, I
applied these patches cleanly onto Android 4.14. I believe these should
goto stable and flow into Android 4.14 from there, but I haven't tested
this since I have no hardware to do so.

Atleast I can say that the coccicheck error below goes away when running:
make coccicheck MODE=report
./drivers/dma/stm32-dma.c:567:18-24: ERROR: chan -> desc is NULL but 
dereferenced.

Anyway, please consider this series for 4.14 stable, I have CC'd the
author and others, thanks.

Pierre Yves MORDRET (7):
  dmaengine: stm32-dma: threshold manages with bitfield feature
  dmaengine: stm32-dma: fix incomplete configuration in cyclic mode
  dmaengine: stm32-dma: fix typo and reported checkpatch warnings
  dmaengine: stm32-dma: Improve memory burst management
  dmaengine: stm32-dma: fix DMA IRQ status handling
  dmaengine: stm32-dma: fix max items per transfer
  dmaengine: stm32-dma: properly mask irq bits

 drivers/dma/stm32-dma.c | 287 +---
 1 file changed, 240 insertions(+), 47 deletions(-)

-- 
2.19.0.605.g01d371f741-goog


[PATCH 1/7] dmaengine: stm32-dma: threshold manages with bitfield feature

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

>From now on, DMA bitfield is to manage DMA FIFO Threshold.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 786fc8fcc38e..4099948b6914 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -116,6 +116,10 @@
 #define STM32_DMA_MAX_DATA_PARAM   0x03
 #define STM32_DMA_MAX_BURST16
 
+/* DMA Features */
+#define STM32_DMA_THRESHOLD_FTR_MASK   GENMASK(1, 0)
+#define STM32_DMA_THRESHOLD_FTR_GET(n) ((n) & STM32_DMA_THRESHOLD_FTR_MASK)
+
 enum stm32_dma_width {
STM32_DMA_BYTE,
STM32_DMA_HALF_WORD,
@@ -129,11 +133,18 @@ enum stm32_dma_burst_size {
STM32_DMA_BURST_INCR16,
 };
 
+/**
+ * struct stm32_dma_cfg - STM32 DMA custom configuration
+ * @channel_id: channel ID
+ * @request_line: DMA request
+ * @stream_config: 32bit mask specifying the DMA channel configuration
+ * @features: 32bit mask specifying the DMA Feature list
+ */
 struct stm32_dma_cfg {
u32 channel_id;
u32 request_line;
u32 stream_config;
-   u32 threshold;
+   u32 features;
 };
 
 struct stm32_dma_chan_reg {
@@ -171,6 +182,7 @@ struct stm32_dma_chan {
u32 next_sg;
struct dma_slave_config dma_sconfig;
struct stm32_dma_chan_reg chan_reg;
+   u32 threshold;
 };
 
 struct stm32_dma_device {
@@ -976,7 +988,8 @@ static void stm32_dma_set_config(struct stm32_dma_chan 
*chan,
/* Enable Interrupts  */
chan->chan_reg.dma_scr |= STM32_DMA_SCR_TEIE | STM32_DMA_SCR_TCIE;
 
-   chan->chan_reg.dma_sfcr = cfg->threshold & STM32_DMA_SFCR_FTH_MASK;
+   chan->threshold = STM32_DMA_THRESHOLD_FTR_GET(cfg->features);
+   chan->chan_reg.dma_sfcr = STM32_DMA_SFCR_FTH(chan->threshold);
 }
 
 static struct dma_chan *stm32_dma_of_xlate(struct of_phandle_args *dma_spec,
@@ -996,7 +1009,7 @@ static struct dma_chan *stm32_dma_of_xlate(struct 
of_phandle_args *dma_spec,
cfg.channel_id = dma_spec->args[0];
cfg.request_line = dma_spec->args[1];
cfg.stream_config = dma_spec->args[2];
-   cfg.threshold = dma_spec->args[3];
+   cfg.features = dma_spec->args[3];
 
if ((cfg.channel_id >= STM32_DMA_MAX_CHANNELS) ||
(cfg.request_line >= STM32_DMA_MAX_REQUEST_ID)) {
-- 
2.19.0.605.g01d371f741-goog



[PATCH 2/7] dmaengine: stm32-dma: fix incomplete configuration in cyclic mode

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

When in cyclic mode, the configuration is updated after having started the
DMA hardware (STM32_DMA_SCR_EN) leading to incomplete configuration of
SMxAR registers.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Hugues Fruchet 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 4099948b6914..fae7de54f00a 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -441,6 +441,8 @@ static void stm32_dma_dump_reg(struct stm32_dma_chan *chan)
dev_dbg(chan2dev(chan), "SFCR:  0x%08x\n", sfcr);
 }
 
+static void stm32_dma_configure_next_sg(struct stm32_dma_chan *chan);
+
 static void stm32_dma_start_transfer(struct stm32_dma_chan *chan)
 {
struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
@@ -483,6 +485,9 @@ static void stm32_dma_start_transfer(struct stm32_dma_chan 
*chan)
if (status)
stm32_dma_irq_clear(chan, status);
 
+   if (chan->desc->cyclic)
+   stm32_dma_configure_next_sg(chan);
+
stm32_dma_dump_reg(chan);
 
/* Start DMA */
@@ -576,8 +581,7 @@ static void stm32_dma_issue_pending(struct dma_chan *c)
if (vchan_issue_pending(>vchan) && !chan->desc && !chan->busy) {
dev_dbg(chan2dev(chan), "vchan %p: issued\n", >vchan);
stm32_dma_start_transfer(chan);
-   if (chan->desc->cyclic)
-   stm32_dma_configure_next_sg(chan);
+
}
spin_unlock_irqrestore(>vchan.lock, flags);
 }
-- 
2.19.0.605.g01d371f741-goog



[PATCH 0/7] NULL pointer deref fix for stm32-dma

2018-10-08 Thread Joel Fernandes (Google)
Hi Greg,

While looking at android-4.14, I found a NULL pointer deref with
stm32-dma driver using Coccicheck errors. I found that upstream had a
bunch of patches on stm32-dma that have fixed this and other issues, I
applied these patches cleanly onto Android 4.14. I believe these should
goto stable and flow into Android 4.14 from there, but I haven't tested
this since I have no hardware to do so.

Atleast I can say that the coccicheck error below goes away when running:
make coccicheck MODE=report
./drivers/dma/stm32-dma.c:567:18-24: ERROR: chan -> desc is NULL but 
dereferenced.

Anyway, please consider this series for 4.14 stable, I have CC'd the
author and others, thanks.

Pierre Yves MORDRET (7):
  dmaengine: stm32-dma: threshold manages with bitfield feature
  dmaengine: stm32-dma: fix incomplete configuration in cyclic mode
  dmaengine: stm32-dma: fix typo and reported checkpatch warnings
  dmaengine: stm32-dma: Improve memory burst management
  dmaengine: stm32-dma: fix DMA IRQ status handling
  dmaengine: stm32-dma: fix max items per transfer
  dmaengine: stm32-dma: properly mask irq bits

 drivers/dma/stm32-dma.c | 287 +---
 1 file changed, 240 insertions(+), 47 deletions(-)

-- 
2.19.0.605.g01d371f741-goog


[PATCH 1/7] dmaengine: stm32-dma: threshold manages with bitfield feature

2018-10-08 Thread Joel Fernandes (Google)
From: Pierre Yves MORDRET 

>From now on, DMA bitfield is to manage DMA FIFO Threshold.

Signed-off-by: Pierre-Yves MORDRET 
Signed-off-by: Vinod Koul 
---
 drivers/dma/stm32-dma.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 786fc8fcc38e..4099948b6914 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -116,6 +116,10 @@
 #define STM32_DMA_MAX_DATA_PARAM   0x03
 #define STM32_DMA_MAX_BURST16
 
+/* DMA Features */
+#define STM32_DMA_THRESHOLD_FTR_MASK   GENMASK(1, 0)
+#define STM32_DMA_THRESHOLD_FTR_GET(n) ((n) & STM32_DMA_THRESHOLD_FTR_MASK)
+
 enum stm32_dma_width {
STM32_DMA_BYTE,
STM32_DMA_HALF_WORD,
@@ -129,11 +133,18 @@ enum stm32_dma_burst_size {
STM32_DMA_BURST_INCR16,
 };
 
+/**
+ * struct stm32_dma_cfg - STM32 DMA custom configuration
+ * @channel_id: channel ID
+ * @request_line: DMA request
+ * @stream_config: 32bit mask specifying the DMA channel configuration
+ * @features: 32bit mask specifying the DMA Feature list
+ */
 struct stm32_dma_cfg {
u32 channel_id;
u32 request_line;
u32 stream_config;
-   u32 threshold;
+   u32 features;
 };
 
 struct stm32_dma_chan_reg {
@@ -171,6 +182,7 @@ struct stm32_dma_chan {
u32 next_sg;
struct dma_slave_config dma_sconfig;
struct stm32_dma_chan_reg chan_reg;
+   u32 threshold;
 };
 
 struct stm32_dma_device {
@@ -976,7 +988,8 @@ static void stm32_dma_set_config(struct stm32_dma_chan 
*chan,
/* Enable Interrupts  */
chan->chan_reg.dma_scr |= STM32_DMA_SCR_TEIE | STM32_DMA_SCR_TCIE;
 
-   chan->chan_reg.dma_sfcr = cfg->threshold & STM32_DMA_SFCR_FTH_MASK;
+   chan->threshold = STM32_DMA_THRESHOLD_FTR_GET(cfg->features);
+   chan->chan_reg.dma_sfcr = STM32_DMA_SFCR_FTH(chan->threshold);
 }
 
 static struct dma_chan *stm32_dma_of_xlate(struct of_phandle_args *dma_spec,
@@ -996,7 +1009,7 @@ static struct dma_chan *stm32_dma_of_xlate(struct 
of_phandle_args *dma_spec,
cfg.channel_id = dma_spec->args[0];
cfg.request_line = dma_spec->args[1];
cfg.stream_config = dma_spec->args[2];
-   cfg.threshold = dma_spec->args[3];
+   cfg.features = dma_spec->args[3];
 
if ((cfg.channel_id >= STM32_DMA_MAX_CHANNELS) ||
(cfg.request_line >= STM32_DMA_MAX_REQUEST_ID)) {
-- 
2.19.0.605.g01d371f741-goog



[tip:perf/core] tools lib traceevent: Separate out tep_strerror() for strerror_r() issues

2018-10-08 Thread tip-bot for Steven Rostedt (VMware)
Commit-ID:  bbbab191c2c474d183e93799d008b412e97f5936
Gitweb: https://git.kernel.org/tip/bbbab191c2c474d183e93799d008b412e97f5936
Author: Steven Rostedt (VMware) 
AuthorDate: Fri, 5 Oct 2018 12:18:16 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:30:45 -0300

tools lib traceevent: Separate out tep_strerror() for strerror_r() issues

While working on having PowerTop use libtracevent as a shared object
library, Tzvetomir hit "str_error_r not defined". This was added by commit
c3cec9e68f12d ("tools lib traceevent: Use str_error_r()") because
strerror_r() has two definitions, where one is GNU specific, and the other
is XSI complient. The strerror_r() is in a wrapper str_error_r() to keep the
code from having to worry about which compiler is being used.

The problem is that str_error_r() is external to libtraceevent, and not part
of the library. If it is used as a shared object then the tools using it
will need to define that function. I do not want that function defined in
libtraceevent itself, as it is out of scope for that library.

As there's only a single instance of this call, and its in the traceevent
library's own tep_strerror() function, we can copy what was done in perf,
and create yet another external file that undefs _GNU_SOURCE to use the more
portable version of the function. We don't need to worry about the errors
that strerror_r() returns. If the buffer isn't big enough, we simply
truncate it.

Reported-by: Tzvetomir Stoyanov 
Signed-off-by: Steven Rostedt (VMware) 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Tzvetomir Stoyanov (VMware) 
Cc: linux trace devel 
Link: http://lkml.kernel.org/r/20181005121816.484e6...@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/traceevent/Build |  1 +
 tools/lib/traceevent/event-parse.c | 30 
 .../{str_error_r.c => traceevent/tep_strerror.c}   | 40 ++
 3 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/tools/lib/traceevent/Build b/tools/lib/traceevent/Build
index c681d0575d16..0050c145d806 100644
--- a/tools/lib/traceevent/Build
+++ b/tools/lib/traceevent/Build
@@ -4,6 +4,7 @@ libtraceevent-y += trace-seq.o
 libtraceevent-y += parse-filter.o
 libtraceevent-y += parse-utils.o
 libtraceevent-y += kbuffer-parse.o
+libtraceevent-y += tep_strerror.o
 
 plugin_jbd2-y += plugin_jbd2.o
 plugin_hrtimer-y  += plugin_hrtimer.o
diff --git a/tools/lib/traceevent/event-parse.c 
b/tools/lib/traceevent/event-parse.c
index 7980fc6c3bac..233179a712d6 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -18,7 +18,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
@@ -6201,35 +6200,6 @@ enum tep_errno tep_parse_event(struct tep_handle 
*pevent, const char *buf,
return __parse_event(pevent, , buf, size, sys);
 }
 
-#undef _PE
-#define _PE(code, str) str
-static const char * const tep_error_str[] = {
-   TEP_ERRORS
-};
-#undef _PE
-
-int tep_strerror(struct tep_handle *pevent __maybe_unused,
-enum tep_errno errnum, char *buf, size_t buflen)
-{
-   int idx;
-   const char *msg;
-
-   if (errnum >= 0) {
-   str_error_r(errnum, buf, buflen);
-   return 0;
-   }
-
-   if (errnum <= __TEP_ERRNO__START ||
-   errnum >= __TEP_ERRNO__END)
-   return -1;
-
-   idx = errnum - __TEP_ERRNO__START - 1;
-   msg = tep_error_str[idx];
-   snprintf(buf, buflen, "%s", msg);
-
-   return 0;
-}
-
 int get_field_val(struct trace_seq *s, struct tep_format_field *field,
  const char *name, struct tep_record *record,
  unsigned long long *val, int err)
diff --git a/tools/lib/str_error_r.c b/tools/lib/traceevent/tep_strerror.c
similarity index 54%
copy from tools/lib/str_error_r.c
copy to tools/lib/traceevent/tep_strerror.c
index 6aad8308a0ac..4ac26445b2f6 100644
--- a/tools/lib/str_error_r.c
+++ b/tools/lib/traceevent/tep_strerror.c
@@ -1,8 +1,16 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: LGPL-2.1
 #undef _GNU_SOURCE
 #include 
 #include 
-#include 
+
+#include "event-parse.h"
+
+#undef _PE
+#define _PE(code, str) str
+static const char * const tep_error_str[] = {
+   TEP_ERRORS
+};
+#undef _PE
 
 /*
  * The tools so far have been using the strerror_r() GNU variant, that returns
@@ -18,10 +26,28 @@
  * interface, but uses the portable XSI variant of strerror_r(), so that users
  * rest asured that the provided buffer is used and it is what is returned.
  */
-char *str_error_r(int errnum, char *buf, size_t buflen)
+int tep_strerror(struct tep_handle *tep __maybe_unused,
+enum tep_errno errnum, char *buf, size_t buflen)
 {
-   int err = strerror_r(errnum, buf, buflen);
-   if (err)
-   snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, [buf], 
%zd)=%d", errnum, buflen, err);
-   return 

[tip:perf/core] tools lib traceevent: Separate out tep_strerror() for strerror_r() issues

2018-10-08 Thread tip-bot for Steven Rostedt (VMware)
Commit-ID:  bbbab191c2c474d183e93799d008b412e97f5936
Gitweb: https://git.kernel.org/tip/bbbab191c2c474d183e93799d008b412e97f5936
Author: Steven Rostedt (VMware) 
AuthorDate: Fri, 5 Oct 2018 12:18:16 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:30:45 -0300

tools lib traceevent: Separate out tep_strerror() for strerror_r() issues

While working on having PowerTop use libtracevent as a shared object
library, Tzvetomir hit "str_error_r not defined". This was added by commit
c3cec9e68f12d ("tools lib traceevent: Use str_error_r()") because
strerror_r() has two definitions, where one is GNU specific, and the other
is XSI complient. The strerror_r() is in a wrapper str_error_r() to keep the
code from having to worry about which compiler is being used.

The problem is that str_error_r() is external to libtraceevent, and not part
of the library. If it is used as a shared object then the tools using it
will need to define that function. I do not want that function defined in
libtraceevent itself, as it is out of scope for that library.

As there's only a single instance of this call, and its in the traceevent
library's own tep_strerror() function, we can copy what was done in perf,
and create yet another external file that undefs _GNU_SOURCE to use the more
portable version of the function. We don't need to worry about the errors
that strerror_r() returns. If the buffer isn't big enough, we simply
truncate it.

Reported-by: Tzvetomir Stoyanov 
Signed-off-by: Steven Rostedt (VMware) 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Tzvetomir Stoyanov (VMware) 
Cc: linux trace devel 
Link: http://lkml.kernel.org/r/20181005121816.484e6...@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/traceevent/Build |  1 +
 tools/lib/traceevent/event-parse.c | 30 
 .../{str_error_r.c => traceevent/tep_strerror.c}   | 40 ++
 3 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/tools/lib/traceevent/Build b/tools/lib/traceevent/Build
index c681d0575d16..0050c145d806 100644
--- a/tools/lib/traceevent/Build
+++ b/tools/lib/traceevent/Build
@@ -4,6 +4,7 @@ libtraceevent-y += trace-seq.o
 libtraceevent-y += parse-filter.o
 libtraceevent-y += parse-utils.o
 libtraceevent-y += kbuffer-parse.o
+libtraceevent-y += tep_strerror.o
 
 plugin_jbd2-y += plugin_jbd2.o
 plugin_hrtimer-y  += plugin_hrtimer.o
diff --git a/tools/lib/traceevent/event-parse.c 
b/tools/lib/traceevent/event-parse.c
index 7980fc6c3bac..233179a712d6 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -18,7 +18,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
@@ -6201,35 +6200,6 @@ enum tep_errno tep_parse_event(struct tep_handle 
*pevent, const char *buf,
return __parse_event(pevent, , buf, size, sys);
 }
 
-#undef _PE
-#define _PE(code, str) str
-static const char * const tep_error_str[] = {
-   TEP_ERRORS
-};
-#undef _PE
-
-int tep_strerror(struct tep_handle *pevent __maybe_unused,
-enum tep_errno errnum, char *buf, size_t buflen)
-{
-   int idx;
-   const char *msg;
-
-   if (errnum >= 0) {
-   str_error_r(errnum, buf, buflen);
-   return 0;
-   }
-
-   if (errnum <= __TEP_ERRNO__START ||
-   errnum >= __TEP_ERRNO__END)
-   return -1;
-
-   idx = errnum - __TEP_ERRNO__START - 1;
-   msg = tep_error_str[idx];
-   snprintf(buf, buflen, "%s", msg);
-
-   return 0;
-}
-
 int get_field_val(struct trace_seq *s, struct tep_format_field *field,
  const char *name, struct tep_record *record,
  unsigned long long *val, int err)
diff --git a/tools/lib/str_error_r.c b/tools/lib/traceevent/tep_strerror.c
similarity index 54%
copy from tools/lib/str_error_r.c
copy to tools/lib/traceevent/tep_strerror.c
index 6aad8308a0ac..4ac26445b2f6 100644
--- a/tools/lib/str_error_r.c
+++ b/tools/lib/traceevent/tep_strerror.c
@@ -1,8 +1,16 @@
-// SPDX-License-Identifier: GPL-2.0
+// SPDX-License-Identifier: LGPL-2.1
 #undef _GNU_SOURCE
 #include 
 #include 
-#include 
+
+#include "event-parse.h"
+
+#undef _PE
+#define _PE(code, str) str
+static const char * const tep_error_str[] = {
+   TEP_ERRORS
+};
+#undef _PE
 
 /*
  * The tools so far have been using the strerror_r() GNU variant, that returns
@@ -18,10 +26,28 @@
  * interface, but uses the portable XSI variant of strerror_r(), so that users
  * rest asured that the provided buffer is used and it is what is returned.
  */
-char *str_error_r(int errnum, char *buf, size_t buflen)
+int tep_strerror(struct tep_handle *tep __maybe_unused,
+enum tep_errno errnum, char *buf, size_t buflen)
 {
-   int err = strerror_r(errnum, buf, buflen);
-   if (err)
-   snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, [buf], 
%zd)=%d", errnum, buflen, err);
-   return 

[tip:perf/core] tools lib traceevent, perf tools: Move struct tep_handler definition in a local header file

2018-10-08 Thread tip-bot for Tzvetomir Stoyanov
Commit-ID:  bb3dd7e7c4d5e024d607c0ec06c2a2fb9408cc99
Gitweb: https://git.kernel.org/tip/bb3dd7e7c4d5e024d607c0ec06c2a2fb9408cc99
Author: Tzvetomir Stoyanov 
AuthorDate: Fri, 5 Oct 2018 12:22:25 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 15:05:37 -0300

tools lib traceevent, perf tools: Move struct tep_handler definition in a local 
header file

As traceevent is going to be transferred into a proper library,
its local data should be protected from the library users.
This patch encapsulates struct tep_handler into a local header,
not visible outside of the library. It implements also a bunch
of new APIs, which library users can use to access tep_handler members.

Signed-off-by: Tzvetomir Stoyanov 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: linux trace devel 
Cc: tzvetomir stoyanov 
Link: http://lkml.kernel.org/r/2018100515.52215...@gandalf.local.home
Signed-off-by: Steven Rostedt (VMware) 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/traceevent/Build   |   1 +
 tools/lib/traceevent/event-parse-api.c   | 275 +++
 tools/lib/traceevent/event-parse-local.h |  92 +++
 tools/lib/traceevent/event-parse.c   |   2 +
 tools/lib/traceevent/event-parse.h   | 228 -
 tools/lib/traceevent/event-plugin.c  |   1 +
 tools/lib/traceevent/parse-filter.c  |   1 +
 tools/perf/util/trace-event-parse.c  |  25 +--
 tools/perf/util/trace-event-read.c   |   2 +-
 9 files changed, 416 insertions(+), 211 deletions(-)

diff --git a/tools/lib/traceevent/Build b/tools/lib/traceevent/Build
index 0050c145d806..ba54bfce0b0b 100644
--- a/tools/lib/traceevent/Build
+++ b/tools/lib/traceevent/Build
@@ -5,6 +5,7 @@ libtraceevent-y += parse-filter.o
 libtraceevent-y += parse-utils.o
 libtraceevent-y += kbuffer-parse.o
 libtraceevent-y += tep_strerror.o
+libtraceevent-y += event-parse-api.o
 
 plugin_jbd2-y += plugin_jbd2.o
 plugin_hrtimer-y  += plugin_hrtimer.o
diff --git a/tools/lib/traceevent/event-parse-api.c 
b/tools/lib/traceevent/event-parse-api.c
new file mode 100644
index ..61f7149085ee
--- /dev/null
+++ b/tools/lib/traceevent/event-parse-api.c
@@ -0,0 +1,275 @@
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt 
+ *
+ */
+
+#include "event-parse.h"
+#include "event-parse-local.h"
+#include "event-utils.h"
+
+/**
+ * tep_get_first_event - returns the first event in the events array
+ * @tep: a handle to the tep_handle
+ *
+ * This returns pointer to the first element of the events array
+ * If @tep is NULL, NULL is returned.
+ */
+struct tep_event_format *tep_get_first_event(struct tep_handle *tep)
+{
+   if (tep && tep->events)
+   return tep->events[0];
+
+   return NULL;
+}
+
+/**
+ * tep_get_events_count - get the number of defined events
+ * @tep: a handle to the tep_handle
+ *
+ * This returns number of elements in event array
+ * If @tep is NULL, 0 is returned.
+ */
+int tep_get_events_count(struct tep_handle *tep)
+{
+   if(tep)
+   return tep->nr_events;
+   return 0;
+}
+
+/**
+ * tep_set_flag - set event parser flag
+ * @tep: a handle to the tep_handle
+ * @flag: flag, or combination of flags to be set
+ * can be any combination from enum tep_flag
+ *
+ * This sets a flag or mbination of flags  from enum tep_flag
+  */
+void tep_set_flag(struct tep_handle *tep, int flag)
+{
+   if(tep)
+   tep->flags |= flag;
+}
+
+unsigned short __tep_data2host2(struct tep_handle *pevent, unsigned short data)
+{
+   unsigned short swap;
+
+   if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
+   return data;
+
+   swap = ((data & 0xffULL) << 8) |
+   ((data & (0xffULL << 8)) >> 8);
+
+   return swap;
+}
+
+unsigned int __tep_data2host4(struct tep_handle *pevent, unsigned int data)
+{
+   unsigned int swap;
+
+   if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
+   return data;
+
+   swap = ((data & 0xffULL) << 24) |
+   ((data & (0xffULL << 8)) << 8) |
+   ((data & (0xffULL << 16)) >> 8) |
+   ((data & (0xffULL << 24)) >> 24);
+
+   return swap;
+}
+
+unsigned long long
+__tep_data2host8(struct tep_handle *pevent, unsigned long long data)
+{
+   unsigned long long swap;
+
+   if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
+   return data;
+
+   swap = ((data & 0xffULL) << 56) |
+   ((data & (0xffULL << 8)) << 40) |
+   ((data & (0xffULL << 16)) << 24) |
+   ((data & (0xffULL << 24)) << 8) |
+   ((data & (0xffULL << 32)) >> 8) |
+   ((data & (0xffULL << 40)) >> 24) |
+   ((data & (0xffULL << 48)) >> 40) |
+   ((data & (0xffULL << 56)) >> 56);
+
+   return swap;
+}
+
+/**
+ * tep_get_header_page_size - get size of the 

[tip:perf/core] tools lib traceevent, perf tools: Move struct tep_handler definition in a local header file

2018-10-08 Thread tip-bot for Tzvetomir Stoyanov
Commit-ID:  bb3dd7e7c4d5e024d607c0ec06c2a2fb9408cc99
Gitweb: https://git.kernel.org/tip/bb3dd7e7c4d5e024d607c0ec06c2a2fb9408cc99
Author: Tzvetomir Stoyanov 
AuthorDate: Fri, 5 Oct 2018 12:22:25 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 15:05:37 -0300

tools lib traceevent, perf tools: Move struct tep_handler definition in a local 
header file

As traceevent is going to be transferred into a proper library,
its local data should be protected from the library users.
This patch encapsulates struct tep_handler into a local header,
not visible outside of the library. It implements also a bunch
of new APIs, which library users can use to access tep_handler members.

Signed-off-by: Tzvetomir Stoyanov 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: linux trace devel 
Cc: tzvetomir stoyanov 
Link: http://lkml.kernel.org/r/2018100515.52215...@gandalf.local.home
Signed-off-by: Steven Rostedt (VMware) 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/traceevent/Build   |   1 +
 tools/lib/traceevent/event-parse-api.c   | 275 +++
 tools/lib/traceevent/event-parse-local.h |  92 +++
 tools/lib/traceevent/event-parse.c   |   2 +
 tools/lib/traceevent/event-parse.h   | 228 -
 tools/lib/traceevent/event-plugin.c  |   1 +
 tools/lib/traceevent/parse-filter.c  |   1 +
 tools/perf/util/trace-event-parse.c  |  25 +--
 tools/perf/util/trace-event-read.c   |   2 +-
 9 files changed, 416 insertions(+), 211 deletions(-)

diff --git a/tools/lib/traceevent/Build b/tools/lib/traceevent/Build
index 0050c145d806..ba54bfce0b0b 100644
--- a/tools/lib/traceevent/Build
+++ b/tools/lib/traceevent/Build
@@ -5,6 +5,7 @@ libtraceevent-y += parse-filter.o
 libtraceevent-y += parse-utils.o
 libtraceevent-y += kbuffer-parse.o
 libtraceevent-y += tep_strerror.o
+libtraceevent-y += event-parse-api.o
 
 plugin_jbd2-y += plugin_jbd2.o
 plugin_hrtimer-y  += plugin_hrtimer.o
diff --git a/tools/lib/traceevent/event-parse-api.c 
b/tools/lib/traceevent/event-parse-api.c
new file mode 100644
index ..61f7149085ee
--- /dev/null
+++ b/tools/lib/traceevent/event-parse-api.c
@@ -0,0 +1,275 @@
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt 
+ *
+ */
+
+#include "event-parse.h"
+#include "event-parse-local.h"
+#include "event-utils.h"
+
+/**
+ * tep_get_first_event - returns the first event in the events array
+ * @tep: a handle to the tep_handle
+ *
+ * This returns pointer to the first element of the events array
+ * If @tep is NULL, NULL is returned.
+ */
+struct tep_event_format *tep_get_first_event(struct tep_handle *tep)
+{
+   if (tep && tep->events)
+   return tep->events[0];
+
+   return NULL;
+}
+
+/**
+ * tep_get_events_count - get the number of defined events
+ * @tep: a handle to the tep_handle
+ *
+ * This returns number of elements in event array
+ * If @tep is NULL, 0 is returned.
+ */
+int tep_get_events_count(struct tep_handle *tep)
+{
+   if(tep)
+   return tep->nr_events;
+   return 0;
+}
+
+/**
+ * tep_set_flag - set event parser flag
+ * @tep: a handle to the tep_handle
+ * @flag: flag, or combination of flags to be set
+ * can be any combination from enum tep_flag
+ *
+ * This sets a flag or mbination of flags  from enum tep_flag
+  */
+void tep_set_flag(struct tep_handle *tep, int flag)
+{
+   if(tep)
+   tep->flags |= flag;
+}
+
+unsigned short __tep_data2host2(struct tep_handle *pevent, unsigned short data)
+{
+   unsigned short swap;
+
+   if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
+   return data;
+
+   swap = ((data & 0xffULL) << 8) |
+   ((data & (0xffULL << 8)) >> 8);
+
+   return swap;
+}
+
+unsigned int __tep_data2host4(struct tep_handle *pevent, unsigned int data)
+{
+   unsigned int swap;
+
+   if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
+   return data;
+
+   swap = ((data & 0xffULL) << 24) |
+   ((data & (0xffULL << 8)) << 8) |
+   ((data & (0xffULL << 16)) >> 8) |
+   ((data & (0xffULL << 24)) >> 24);
+
+   return swap;
+}
+
+unsigned long long
+__tep_data2host8(struct tep_handle *pevent, unsigned long long data)
+{
+   unsigned long long swap;
+
+   if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
+   return data;
+
+   swap = ((data & 0xffULL) << 56) |
+   ((data & (0xffULL << 8)) << 40) |
+   ((data & (0xffULL << 16)) << 24) |
+   ((data & (0xffULL << 24)) << 8) |
+   ((data & (0xffULL << 32)) >> 8) |
+   ((data & (0xffULL << 40)) >> 24) |
+   ((data & (0xffULL << 48)) >> 40) |
+   ((data & (0xffULL << 56)) >> 56);
+
+   return swap;
+}
+
+/**
+ * tep_get_header_page_size - get size of the 

[tip:perf/core] perf python: More portable way to make CFLAGS work with clang

2018-10-08 Thread tip-bot for Eduardo Habkost
Commit-ID:  8b2f245faa6238e28a1d801e8633515251d1acfc
Gitweb: https://git.kernel.org/tip/8b2f245faa6238e28a1d801e8633515251d1acfc
Author: Eduardo Habkost 
AuthorDate: Fri, 5 Oct 2018 17:40:58 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:30:45 -0300

perf python: More portable way to make CFLAGS work with clang

The existing code that tries to make CFLAGS compatible with clang
doesn't work with Python 3.

Instead of trying to touch _sysconfigdata.build_time_vars directly,
change the dictionary returned by disutils.sysconfig.get_config_vars().
This works on both Python 2 and Python 3.

Signed-off-by: Eduardo Habkost 
Reported-by: Arnaldo Carvalho de Melo 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: http://lkml.kernel.org/r/20181005204058.7966-3-ehabk...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/setup.py | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 261a55e7e1b2..63f758c655d5 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -9,12 +9,14 @@ def clang_has_option(option):
 
 cc = getenv("CC")
 if cc == "clang":
-from _sysconfigdata import build_time_vars
-build_time_vars["CFLAGS"] = sub("-specs=[^ ]+", "", 
build_time_vars["CFLAGS"])
-if not clang_has_option("-mcet"):
-build_time_vars["CFLAGS"] = sub("-mcet", "", build_time_vars["CFLAGS"])
-if not clang_has_option("-fcf-protection"):
-build_time_vars["CFLAGS"] = sub("-fcf-protection", "", 
build_time_vars["CFLAGS"])
+from distutils.sysconfig import get_config_vars
+vars = get_config_vars()
+for var in ('CFLAGS', 'OPT'):
+vars[var] = sub("-specs=[^ ]+", "", vars[var])
+if not clang_has_option("-mcet"):
+vars[var] = sub("-mcet", "", vars[var])
+if not clang_has_option("-fcf-protection"):
+vars[var] = sub("-fcf-protection", "", vars[var])
 
 from distutils.core import setup, Extension
 


[tip:perf/core] perf python: More portable way to make CFLAGS work with clang

2018-10-08 Thread tip-bot for Eduardo Habkost
Commit-ID:  8b2f245faa6238e28a1d801e8633515251d1acfc
Gitweb: https://git.kernel.org/tip/8b2f245faa6238e28a1d801e8633515251d1acfc
Author: Eduardo Habkost 
AuthorDate: Fri, 5 Oct 2018 17:40:58 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:30:45 -0300

perf python: More portable way to make CFLAGS work with clang

The existing code that tries to make CFLAGS compatible with clang
doesn't work with Python 3.

Instead of trying to touch _sysconfigdata.build_time_vars directly,
change the dictionary returned by disutils.sysconfig.get_config_vars().
This works on both Python 2 and Python 3.

Signed-off-by: Eduardo Habkost 
Reported-by: Arnaldo Carvalho de Melo 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: http://lkml.kernel.org/r/20181005204058.7966-3-ehabk...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/setup.py | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 261a55e7e1b2..63f758c655d5 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -9,12 +9,14 @@ def clang_has_option(option):
 
 cc = getenv("CC")
 if cc == "clang":
-from _sysconfigdata import build_time_vars
-build_time_vars["CFLAGS"] = sub("-specs=[^ ]+", "", 
build_time_vars["CFLAGS"])
-if not clang_has_option("-mcet"):
-build_time_vars["CFLAGS"] = sub("-mcet", "", build_time_vars["CFLAGS"])
-if not clang_has_option("-fcf-protection"):
-build_time_vars["CFLAGS"] = sub("-fcf-protection", "", 
build_time_vars["CFLAGS"])
+from distutils.sysconfig import get_config_vars
+vars = get_config_vars()
+for var in ('CFLAGS', 'OPT'):
+vars[var] = sub("-specs=[^ ]+", "", vars[var])
+if not clang_has_option("-mcet"):
+vars[var] = sub("-mcet", "", vars[var])
+if not clang_has_option("-fcf-protection"):
+vars[var] = sub("-fcf-protection", "", vars[var])
 
 from distutils.core import setup, Extension
 


[tip:perf/core] perf python: Make clang_has_option() work on Python 3

2018-10-08 Thread tip-bot for Eduardo Habkost
Commit-ID:  e13a5d69c31d35538e80176d54d95b6addf4dcbf
Gitweb: https://git.kernel.org/tip/e13a5d69c31d35538e80176d54d95b6addf4dcbf
Author: Eduardo Habkost 
AuthorDate: Fri, 5 Oct 2018 17:40:57 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:30:44 -0300

perf python: Make clang_has_option() work on Python 3

Use a bytes literal so it works with Python 3's version of Popen().
Note that the b"..." syntax requires Python 2.6+.

Signed-off-by: Eduardo Habkost 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: http://lkml.kernel.org/r/20181005204058.7966-2-ehabk...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 1942f6dd24f6..261a55e7e1b2 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -5,7 +5,7 @@ from subprocess import Popen, PIPE
 from re import sub
 
 def clang_has_option(option):
-return [o for o in Popen(['clang', option], 
stderr=PIPE).stderr.readlines() if "unknown argument" in o] == [ ]
+return [o for o in Popen(['clang', option], 
stderr=PIPE).stderr.readlines() if b"unknown argument" in o] == [ ]
 
 cc = getenv("CC")
 if cc == "clang":


[tip:perf/core] perf python: Make clang_has_option() work on Python 3

2018-10-08 Thread tip-bot for Eduardo Habkost
Commit-ID:  e13a5d69c31d35538e80176d54d95b6addf4dcbf
Gitweb: https://git.kernel.org/tip/e13a5d69c31d35538e80176d54d95b6addf4dcbf
Author: Eduardo Habkost 
AuthorDate: Fri, 5 Oct 2018 17:40:57 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:30:44 -0300

perf python: Make clang_has_option() work on Python 3

Use a bytes literal so it works with Python 3's version of Popen().
Note that the b"..." syntax requires Python 2.6+.

Signed-off-by: Eduardo Habkost 
Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: http://lkml.kernel.org/r/20181005204058.7966-2-ehabk...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 1942f6dd24f6..261a55e7e1b2 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -5,7 +5,7 @@ from subprocess import Popen, PIPE
 from re import sub
 
 def clang_has_option(option):
-return [o for o in Popen(['clang', option], 
stderr=PIPE).stderr.readlines() if "unknown argument" in o] == [ ]
+return [o for o in Popen(['clang', option], 
stderr=PIPE).stderr.readlines() if b"unknown argument" in o] == [ ]
 
 cc = getenv("CC")
 if cc == "clang":


[tip:perf/core] perf tools: Free temporary 'sys' string in read_event_files()

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  1e44224fb0528b4c0cc176bde2bb31e9127eb14b
Gitweb: https://git.kernel.org/tip/1e44224fb0528b4c0cc176bde2bb31e9127eb14b
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:14 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:46 -0300

perf tools: Free temporary 'sys' string in read_event_files()

For each system in a given pevent, read_event_files() reads in a
temporary 'sys' string.  Be sure to free this string before moving onto
to the next system and/or leaving read_event_files().

Fixes the following coverity complaints:

  Error: RESOURCE_LEAK (CWE-772):

  tools/perf/util/trace-event-read.c:343: overwrite_var: Overwriting
  "sys" in "sys = read_string()" leaks the storage that "sys" points to.

  tools/perf/util/trace-event-read.c:353: leaked_storage: Variable "sys"
  going out of scope leaks the storage it points to.

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-6-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/trace-event-read.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/trace-event-read.c 
b/tools/perf/util/trace-event-read.c
index a278e1eee5f5..add8441de579 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -347,9 +347,12 @@ static int read_event_files(struct tep_handle *pevent)
for (x=0; x < count; x++) {
size = read8(pevent);
ret = read_event_file(pevent, sys, size);
-   if (ret)
+   if (ret) {
+   free(sys);
return ret;
+   }
}
+   free(sys);
}
return 0;
 }


[tip:perf/core] perf tools: Free temporary 'sys' string in read_event_files()

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  1e44224fb0528b4c0cc176bde2bb31e9127eb14b
Gitweb: https://git.kernel.org/tip/1e44224fb0528b4c0cc176bde2bb31e9127eb14b
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:14 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:46 -0300

perf tools: Free temporary 'sys' string in read_event_files()

For each system in a given pevent, read_event_files() reads in a
temporary 'sys' string.  Be sure to free this string before moving onto
to the next system and/or leaving read_event_files().

Fixes the following coverity complaints:

  Error: RESOURCE_LEAK (CWE-772):

  tools/perf/util/trace-event-read.c:343: overwrite_var: Overwriting
  "sys" in "sys = read_string()" leaks the storage that "sys" points to.

  tools/perf/util/trace-event-read.c:353: leaked_storage: Variable "sys"
  going out of scope leaks the storage it points to.

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-6-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/trace-event-read.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/trace-event-read.c 
b/tools/perf/util/trace-event-read.c
index a278e1eee5f5..add8441de579 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -347,9 +347,12 @@ static int read_event_files(struct tep_handle *pevent)
for (x=0; x < count; x++) {
size = read8(pevent);
ret = read_event_file(pevent, sys, size);
-   if (ret)
+   if (ret) {
+   free(sys);
return ret;
+   }
}
+   free(sys);
}
return 0;
 }


[tip:perf/core] perf tools: Avoid double free in read_event_file()

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  470c8f7c88de013d266e1b61044efe8937728b7f
Gitweb: https://git.kernel.org/tip/470c8f7c88de013d266e1b61044efe8937728b7f
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:13 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:46 -0300

perf tools: Avoid double free in read_event_file()

The temporary 'buf' buffer allocated in read_event_file() may be freed
twice.  Move the free() call to the common function exit point.

Fixes the following coverity complaints:

  Error: USE_AFTER_FREE (CWE-825):
  tools/perf/util/trace-event-read.c:309: double_free: Calling "free"
  frees pointer "buf" which has already been freed.

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-5-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/trace-event-read.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/tools/perf/util/trace-event-read.c 
b/tools/perf/util/trace-event-read.c
index b98ee2a2eb44..a278e1eee5f5 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -297,10 +297,8 @@ static int read_event_file(struct tep_handle *pevent, char 
*sys,
}
 
ret = do_read(buf, size);
-   if (ret < 0) {
-   free(buf);
+   if (ret < 0)
goto out;
-   }
 
ret = parse_event_file(pevent, buf, size, sys);
if (ret < 0)


[tip:perf/core] perf tools: Avoid double free in read_event_file()

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  470c8f7c88de013d266e1b61044efe8937728b7f
Gitweb: https://git.kernel.org/tip/470c8f7c88de013d266e1b61044efe8937728b7f
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:13 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:46 -0300

perf tools: Avoid double free in read_event_file()

The temporary 'buf' buffer allocated in read_event_file() may be freed
twice.  Move the free() call to the common function exit point.

Fixes the following coverity complaints:

  Error: USE_AFTER_FREE (CWE-825):
  tools/perf/util/trace-event-read.c:309: double_free: Calling "free"
  frees pointer "buf" which has already been freed.

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-5-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/trace-event-read.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/tools/perf/util/trace-event-read.c 
b/tools/perf/util/trace-event-read.c
index b98ee2a2eb44..a278e1eee5f5 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -297,10 +297,8 @@ static int read_event_file(struct tep_handle *pevent, char 
*sys,
}
 
ret = do_read(buf, size);
-   if (ret < 0) {
-   free(buf);
+   if (ret < 0)
goto out;
-   }
 
ret = parse_event_file(pevent, buf, size, sys);
if (ret < 0)


[tip:perf/core] perf tools: Free 'printk' string in parse_ftrace_printk()

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  9c8a182e5a73e01afd11742a2ab887bf338fdafd
Gitweb: https://git.kernel.org/tip/9c8a182e5a73e01afd11742a2ab887bf338fdafd
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:12 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:45 -0300

perf tools: Free 'printk' string in parse_ftrace_printk()

parse_ftrace_printk() tokenizes and parses a line, calling strdup() each
iteration.  Add code to free this temporary format string duplicate.

Fixes the following coverity complaints:

  Error: RESOURCE_LEAK (CWE-772):
  tools/perf/util/trace-event-parse.c:158: overwrite_var: Overwriting
  "printk" in "printk = strdup(fmt + 1)" leaks the storage that "printk"
  points to.

  tools/perf/util/trace-event-parse.c:162: leaked_storage: Variable
  "printk" going out of scope leaks the storage it points to.

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-4-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/trace-event-parse.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/trace-event-parse.c 
b/tools/perf/util/trace-event-parse.c
index a4d7de1c96d1..02f97f5dd588 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -158,6 +158,7 @@ void parse_ftrace_printk(struct tep_handle *pevent,
printk = strdup(fmt+1);
line = strtok_r(NULL, "\n", );
tep_register_print_string(pevent, printk, addr);
+   free(printk);
}
 }
 


[tip:perf/core] perf tools: Free 'printk' string in parse_ftrace_printk()

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  9c8a182e5a73e01afd11742a2ab887bf338fdafd
Gitweb: https://git.kernel.org/tip/9c8a182e5a73e01afd11742a2ab887bf338fdafd
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:12 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:45 -0300

perf tools: Free 'printk' string in parse_ftrace_printk()

parse_ftrace_printk() tokenizes and parses a line, calling strdup() each
iteration.  Add code to free this temporary format string duplicate.

Fixes the following coverity complaints:

  Error: RESOURCE_LEAK (CWE-772):
  tools/perf/util/trace-event-parse.c:158: overwrite_var: Overwriting
  "printk" in "printk = strdup(fmt + 1)" leaks the storage that "printk"
  points to.

  tools/perf/util/trace-event-parse.c:162: leaked_storage: Variable
  "printk" going out of scope leaks the storage it points to.

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-4-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/trace-event-parse.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/trace-event-parse.c 
b/tools/perf/util/trace-event-parse.c
index a4d7de1c96d1..02f97f5dd588 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -158,6 +158,7 @@ void parse_ftrace_printk(struct tep_handle *pevent,
printk = strdup(fmt+1);
line = strtok_r(NULL, "\n", );
tep_register_print_string(pevent, printk, addr);
+   free(printk);
}
 }
 


[tip:perf/core] perf tools: Cleanup trace-event-info 'tdata' leak

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  faedbf3fd19f2511a39397f76359e4cc6ee93072
Gitweb: https://git.kernel.org/tip/faedbf3fd19f2511a39397f76359e4cc6ee93072
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:11 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:45 -0300

perf tools: Cleanup trace-event-info 'tdata' leak

Free tracing_data structure in tracing_data_get() error paths.

Fixes the following coverity complaint:

  Error: RESOURCE_LEAK (CWE-772):
  leaked_storage: Variable "tdata" going out of scope leaks the storage

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-3-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/trace-event-info.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/trace-event-info.c 
b/tools/perf/util/trace-event-info.c
index 7b0ca7cbb7de..8ad8e755127b 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -531,12 +531,14 @@ struct tracing_data *tracing_data_get(struct list_head 
*pattrs,
 "/tmp/perf-XX");
if (!mkstemp(tdata->temp_file)) {
pr_debug("Can't make temp file");
+   free(tdata);
return NULL;
}
 
temp_fd = open(tdata->temp_file, O_RDWR);
if (temp_fd < 0) {
pr_debug("Can't read '%s'", tdata->temp_file);
+   free(tdata);
return NULL;
}
 


[tip:perf/core] perf tools: Cleanup trace-event-info 'tdata' leak

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  faedbf3fd19f2511a39397f76359e4cc6ee93072
Gitweb: https://git.kernel.org/tip/faedbf3fd19f2511a39397f76359e4cc6ee93072
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:11 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:45 -0300

perf tools: Cleanup trace-event-info 'tdata' leak

Free tracing_data structure in tracing_data_get() error paths.

Fixes the following coverity complaint:

  Error: RESOURCE_LEAK (CWE-772):
  leaked_storage: Variable "tdata" going out of scope leaks the storage

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-3-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/trace-event-info.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/trace-event-info.c 
b/tools/perf/util/trace-event-info.c
index 7b0ca7cbb7de..8ad8e755127b 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -531,12 +531,14 @@ struct tracing_data *tracing_data_get(struct list_head 
*pattrs,
 "/tmp/perf-XX");
if (!mkstemp(tdata->temp_file)) {
pr_debug("Can't make temp file");
+   free(tdata);
return NULL;
}
 
temp_fd = open(tdata->temp_file, O_RDWR);
if (temp_fd < 0) {
pr_debug("Can't read '%s'", tdata->temp_file);
+   free(tdata);
return NULL;
}
 


[tip:perf/core] perf strbuf: Match va_{add,copy} with va_end

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  ce49d8436cffa9b7a6a5f110879d53e89dbc6746
Gitweb: https://git.kernel.org/tip/ce49d8436cffa9b7a6a5f110879d53e89dbc6746
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:10 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:44 -0300

perf strbuf: Match va_{add,copy} with va_end

Ensure that all code paths in strbuf_addv() call va_end() on the
ap_saved copy that was made.

Fixes the following coverity complaint:

  Error: VARARGS (CWE-237): [#def683]
  tools/perf/util/strbuf.c:106: missing_va_end: va_end was not called
  for "ap_saved".

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-2-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/strbuf.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index 3d1cf5bf7f18..9005fbe0780e 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -98,19 +98,25 @@ static int strbuf_addv(struct strbuf *sb, const char *fmt, 
va_list ap)
 
va_copy(ap_saved, ap);
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
-   if (len < 0)
+   if (len < 0) {
+   va_end(ap_saved);
return len;
+   }
if (len > strbuf_avail(sb)) {
ret = strbuf_grow(sb, len);
-   if (ret)
+   if (ret) {
+   va_end(ap_saved);
return ret;
+   }
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, 
ap_saved);
va_end(ap_saved);
if (len > strbuf_avail(sb)) {
pr_debug("this should not happen, your vsnprintf is 
broken");
+   va_end(ap_saved);
return -EINVAL;
}
}
+   va_end(ap_saved);
return strbuf_setlen(sb, sb->len + len);
 }
 


[tip:perf/core] perf strbuf: Match va_{add,copy} with va_end

2018-10-08 Thread tip-bot for Sanskriti Sharma
Commit-ID:  ce49d8436cffa9b7a6a5f110879d53e89dbc6746
Gitweb: https://git.kernel.org/tip/ce49d8436cffa9b7a6a5f110879d53e89dbc6746
Author: Sanskriti Sharma 
AuthorDate: Tue, 2 Oct 2018 10:29:10 -0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:44 -0300

perf strbuf: Match va_{add,copy} with va_end

Ensure that all code paths in strbuf_addv() call va_end() on the
ap_saved copy that was made.

Fixes the following coverity complaint:

  Error: VARARGS (CWE-237): [#def683]
  tools/perf/util/strbuf.c:106: missing_va_end: va_end was not called
  for "ap_saved".

Signed-off-by: Sanskriti Sharma 
Reviewed-by: Jiri Olsa 
Cc: Joe Lawrence 
Link: 
http://lkml.kernel.org/r/1538490554-8161-2-git-send-email-sansh...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/strbuf.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index 3d1cf5bf7f18..9005fbe0780e 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -98,19 +98,25 @@ static int strbuf_addv(struct strbuf *sb, const char *fmt, 
va_list ap)
 
va_copy(ap_saved, ap);
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
-   if (len < 0)
+   if (len < 0) {
+   va_end(ap_saved);
return len;
+   }
if (len > strbuf_avail(sb)) {
ret = strbuf_grow(sb, len);
-   if (ret)
+   if (ret) {
+   va_end(ap_saved);
return ret;
+   }
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, 
ap_saved);
va_end(ap_saved);
if (len > strbuf_avail(sb)) {
pr_debug("this should not happen, your vsnprintf is 
broken");
+   va_end(ap_saved);
return -EINVAL;
}
}
+   va_end(ap_saved);
return strbuf_setlen(sb, sb->len + len);
 }
 


[tip:perf/core] tools include: Adopt linux/bits.h

2018-10-08 Thread tip-bot for Arnaldo Carvalho de Melo
Commit-ID:  ba4aa02b417f08a0bee5e7b8ed70cac788a7c854
Gitweb: https://git.kernel.org/tip/ba4aa02b417f08a0bee5e7b8ed70cac788a7c854
Author: Arnaldo Carvalho de Melo 
AuthorDate: Tue, 25 Sep 2018 10:55:59 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:43 -0300

tools include: Adopt linux/bits.h

So that we reduce the difference of tools/include/linux/bitops.h to the
original kernel file, include/linux/bitops.h, trying to remove the need
to define BITS_PER_LONG, to avoid clashes with asm/bitsperlong.h.

And the things removed from tools/include/linux/bitops.h are really in
linux/bits.h, so that we can have a copy and then
tools/perf/check_headers.sh will tell us when new stuff gets added to
linux/bits.h so that we can check if it is useful and if any adjustment
needs to be done to the tools/{include,arch}/ copies.

Cc: Adrian Hunter 
Cc: Alexander Sverdlin 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-y1sqyydvfzo0bjjoj4zsl...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/linux/bitops.h| 7 ++-
 {include => tools/include}/linux/bits.h | 0
 tools/perf/check-headers.sh | 1 +
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index acc704bd3998..0b0ef3abc966 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -3,8 +3,6 @@
 #define _TOOLS_LINUX_BITOPS_H_
 
 #include 
-#include 
-
 #ifndef __WORDSIZE
 #define __WORDSIZE (__SIZEOF_LONG__ * 8)
 #endif
@@ -12,10 +10,9 @@
 #ifndef BITS_PER_LONG
 # define BITS_PER_LONG __WORDSIZE
 #endif
+#include 
+#include 
 
-#define BIT_MASK(nr)   (1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr)   ((nr) / BITS_PER_LONG)
-#define BITS_PER_BYTE  8
 #define BITS_TO_LONGS(nr)  DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 #define BITS_TO_U64(nr)DIV_ROUND_UP(nr, BITS_PER_BYTE * 
sizeof(u64))
 #define BITS_TO_U32(nr)DIV_ROUND_UP(nr, BITS_PER_BYTE * 
sizeof(u32))
diff --git a/include/linux/bits.h b/tools/include/linux/bits.h
similarity index 100%
copy from include/linux/bits.h
copy to tools/include/linux/bits.h
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index 466540ee8ea7..c72cc73a6b09 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -14,6 +14,7 @@ include/uapi/linux/sched.h
 include/uapi/linux/stat.h
 include/uapi/linux/vhost.h
 include/uapi/sound/asound.h
+include/linux/bits.h
 include/linux/hash.h
 include/uapi/linux/hw_breakpoint.h
 arch/x86/include/asm/disabled-features.h


[tip:perf/core] perf test: S390 does not support watchpoints in test 22

2018-10-08 Thread tip-bot for Thomas Richter
Commit-ID:  0e24147d69c9357b1ccb54a9bc028eb9a9f9ed1a
Gitweb: https://git.kernel.org/tip/0e24147d69c9357b1ccb54a9bc028eb9a9f9ed1a
Author: Thomas Richter 
AuthorDate: Fri, 28 Sep 2018 12:53:35 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:44 -0300

perf test: S390 does not support watchpoints in test 22

S390 does not support the perf_event_open system call for
attribute type PERF_TYPE_BREAKPOINT. This results in test
failure for test 22:

  [root@s8360046 perf]# ./perf test 22
  22: Watchpoint:
  22.1: Read Only Watchpoint: FAILED!
  22.2: Write Only Watchpoint   : FAILED!
  22.3: Read / Write Watchpoint : FAILED!
  22.4: Modify Watchpoint   : FAILED!
  [root@s8360046 perf]#

Add s390 support to avoid these tests being executed on
s390 platform:

  [root@s8360046 perf]# ./perf test 22
  [root@s8360046 perf]# ./perf test -v 22
  22: Watchpoint: Disabled
  [root@s8360046 perf]#

Signed-off-by: Thomas Richter 
Reviewed-by: Ravi Bangoria 
Cc: Heiko Carstens 
Cc: Hendrik Brueckner 
Cc: Martin Schwidefsky 
Link: http://lkml.kernel.org/r/20180928105335.67179-1-tmri...@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/builtin-test.c |  1 +
 tools/perf/tests/tests.h|  1 +
 tools/perf/tests/wp.c   | 12 
 3 files changed, 14 insertions(+)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 54ca7d87236f..12c09e0ece71 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -123,6 +123,7 @@ static struct test generic_tests[] = {
{
.desc = "Watchpoint",
.func = test__wp,
+   .is_supported = test__wp_is_supported,
.subtest = {
.skip_if_fail   = false,
.get_nr = test__wp_subtest_get_nr,
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 8e26a4148f30..b82f55fcc294 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -109,6 +109,7 @@ int test__unit_number__scnprint(struct test *test, int 
subtest);
 int test__mem2node(struct test *t, int subtest);
 
 bool test__bp_signal_is_supported(void);
+bool test__wp_is_supported(void);
 
 #if defined(__arm__) || defined(__aarch64__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/tests/wp.c b/tools/perf/tests/wp.c
index 017a99317f94..f89e6806557b 100644
--- a/tools/perf/tests/wp.c
+++ b/tools/perf/tests/wp.c
@@ -227,3 +227,15 @@ int test__wp(struct test *test __maybe_unused, int i)
 
return !wp_testcase_table[i].target_func() ? TEST_OK : TEST_FAIL;
 }
+
+/* The s390 so far does not have support for
+ * instruction breakpoint using the perf_event_open() system call.
+ */
+bool test__wp_is_supported(void)
+{
+#if defined(__s390x__)
+   return false;
+#else
+   return true;
+#endif
+}


[tip:perf/core] perf auxtrace: Include missing asm/bitsperlong.h to get BITS_PER_LONG

2018-10-08 Thread tip-bot for Arnaldo Carvalho de Melo
Commit-ID:  291ed51deee49ff35d0824fb7050538b449964d6
Gitweb: https://git.kernel.org/tip/291ed51deee49ff35d0824fb7050538b449964d6
Author: Arnaldo Carvalho de Melo 
AuthorDate: Tue, 25 Sep 2018 11:52:10 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:43 -0300

perf auxtrace: Include missing asm/bitsperlong.h to get BITS_PER_LONG

The auxtrace.h header references BITS_PER_LONG without including the
header where it is defined, getting it by luck from some other header,
fix it.

Cc: Adrian Hunter 
Cc: Alexander Sverdlin 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-v04ydmbh7tvpcctf3zld9...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/auxtrace.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 0a6ce9c4fc11..d88f6e9eb461 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "../perf.h"
 #include "event.h"


[tip:perf/core] perf test: S390 does not support watchpoints in test 22

2018-10-08 Thread tip-bot for Thomas Richter
Commit-ID:  0e24147d69c9357b1ccb54a9bc028eb9a9f9ed1a
Gitweb: https://git.kernel.org/tip/0e24147d69c9357b1ccb54a9bc028eb9a9f9ed1a
Author: Thomas Richter 
AuthorDate: Fri, 28 Sep 2018 12:53:35 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:44 -0300

perf test: S390 does not support watchpoints in test 22

S390 does not support the perf_event_open system call for
attribute type PERF_TYPE_BREAKPOINT. This results in test
failure for test 22:

  [root@s8360046 perf]# ./perf test 22
  22: Watchpoint:
  22.1: Read Only Watchpoint: FAILED!
  22.2: Write Only Watchpoint   : FAILED!
  22.3: Read / Write Watchpoint : FAILED!
  22.4: Modify Watchpoint   : FAILED!
  [root@s8360046 perf]#

Add s390 support to avoid these tests being executed on
s390 platform:

  [root@s8360046 perf]# ./perf test 22
  [root@s8360046 perf]# ./perf test -v 22
  22: Watchpoint: Disabled
  [root@s8360046 perf]#

Signed-off-by: Thomas Richter 
Reviewed-by: Ravi Bangoria 
Cc: Heiko Carstens 
Cc: Hendrik Brueckner 
Cc: Martin Schwidefsky 
Link: http://lkml.kernel.org/r/20180928105335.67179-1-tmri...@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/builtin-test.c |  1 +
 tools/perf/tests/tests.h|  1 +
 tools/perf/tests/wp.c   | 12 
 3 files changed, 14 insertions(+)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 54ca7d87236f..12c09e0ece71 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -123,6 +123,7 @@ static struct test generic_tests[] = {
{
.desc = "Watchpoint",
.func = test__wp,
+   .is_supported = test__wp_is_supported,
.subtest = {
.skip_if_fail   = false,
.get_nr = test__wp_subtest_get_nr,
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 8e26a4148f30..b82f55fcc294 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -109,6 +109,7 @@ int test__unit_number__scnprint(struct test *test, int 
subtest);
 int test__mem2node(struct test *t, int subtest);
 
 bool test__bp_signal_is_supported(void);
+bool test__wp_is_supported(void);
 
 #if defined(__arm__) || defined(__aarch64__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/tests/wp.c b/tools/perf/tests/wp.c
index 017a99317f94..f89e6806557b 100644
--- a/tools/perf/tests/wp.c
+++ b/tools/perf/tests/wp.c
@@ -227,3 +227,15 @@ int test__wp(struct test *test __maybe_unused, int i)
 
return !wp_testcase_table[i].target_func() ? TEST_OK : TEST_FAIL;
 }
+
+/* The s390 so far does not have support for
+ * instruction breakpoint using the perf_event_open() system call.
+ */
+bool test__wp_is_supported(void)
+{
+#if defined(__s390x__)
+   return false;
+#else
+   return true;
+#endif
+}


[tip:perf/core] perf auxtrace: Include missing asm/bitsperlong.h to get BITS_PER_LONG

2018-10-08 Thread tip-bot for Arnaldo Carvalho de Melo
Commit-ID:  291ed51deee49ff35d0824fb7050538b449964d6
Gitweb: https://git.kernel.org/tip/291ed51deee49ff35d0824fb7050538b449964d6
Author: Arnaldo Carvalho de Melo 
AuthorDate: Tue, 25 Sep 2018 11:52:10 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:43 -0300

perf auxtrace: Include missing asm/bitsperlong.h to get BITS_PER_LONG

The auxtrace.h header references BITS_PER_LONG without including the
header where it is defined, getting it by luck from some other header,
fix it.

Cc: Adrian Hunter 
Cc: Alexander Sverdlin 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-v04ydmbh7tvpcctf3zld9...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/auxtrace.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 0a6ce9c4fc11..d88f6e9eb461 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "../perf.h"
 #include "event.h"


[tip:perf/core] tools include: Adopt linux/bits.h

2018-10-08 Thread tip-bot for Arnaldo Carvalho de Melo
Commit-ID:  ba4aa02b417f08a0bee5e7b8ed70cac788a7c854
Gitweb: https://git.kernel.org/tip/ba4aa02b417f08a0bee5e7b8ed70cac788a7c854
Author: Arnaldo Carvalho de Melo 
AuthorDate: Tue, 25 Sep 2018 10:55:59 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 8 Oct 2018 14:23:43 -0300

tools include: Adopt linux/bits.h

So that we reduce the difference of tools/include/linux/bitops.h to the
original kernel file, include/linux/bitops.h, trying to remove the need
to define BITS_PER_LONG, to avoid clashes with asm/bitsperlong.h.

And the things removed from tools/include/linux/bitops.h are really in
linux/bits.h, so that we can have a copy and then
tools/perf/check_headers.sh will tell us when new stuff gets added to
linux/bits.h so that we can check if it is useful and if any adjustment
needs to be done to the tools/{include,arch}/ copies.

Cc: Adrian Hunter 
Cc: Alexander Sverdlin 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: https://lkml.kernel.org/n/tip-y1sqyydvfzo0bjjoj4zsl...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/linux/bitops.h| 7 ++-
 {include => tools/include}/linux/bits.h | 0
 tools/perf/check-headers.sh | 1 +
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index acc704bd3998..0b0ef3abc966 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -3,8 +3,6 @@
 #define _TOOLS_LINUX_BITOPS_H_
 
 #include 
-#include 
-
 #ifndef __WORDSIZE
 #define __WORDSIZE (__SIZEOF_LONG__ * 8)
 #endif
@@ -12,10 +10,9 @@
 #ifndef BITS_PER_LONG
 # define BITS_PER_LONG __WORDSIZE
 #endif
+#include 
+#include 
 
-#define BIT_MASK(nr)   (1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr)   ((nr) / BITS_PER_LONG)
-#define BITS_PER_BYTE  8
 #define BITS_TO_LONGS(nr)  DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 #define BITS_TO_U64(nr)DIV_ROUND_UP(nr, BITS_PER_BYTE * 
sizeof(u64))
 #define BITS_TO_U32(nr)DIV_ROUND_UP(nr, BITS_PER_BYTE * 
sizeof(u32))
diff --git a/include/linux/bits.h b/tools/include/linux/bits.h
similarity index 100%
copy from include/linux/bits.h
copy to tools/include/linux/bits.h
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index 466540ee8ea7..c72cc73a6b09 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -14,6 +14,7 @@ include/uapi/linux/sched.h
 include/uapi/linux/stat.h
 include/uapi/linux/vhost.h
 include/uapi/sound/asound.h
+include/linux/bits.h
 include/linux/hash.h
 include/uapi/linux/hw_breakpoint.h
 arch/x86/include/asm/disabled-features.h


Re: [GIT PULL 00/12] perf/core improvements and fixes

2018-10-08 Thread Ingo Molnar


* Arnaldo Carvalho de Melo  wrote:

> Hi Ingo,
> 
>   Please consider pulling,
> 
> - Arnaldo
> 
> Test results at the end of this message, as usual.
> 
> The following changes since commit 7c5314b88da6d5af98239786772a1c44cc5eb67d:
> 
>   perf/x86/intel: Add quirk for Goldmont Plus (2018-10-02 10:14:33 +0200)
> 
> are available in the Git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git 
> tags/perf-core-for-mingo-4.20-20181008
> 
> for you to fetch changes up to bb3dd7e7c4d5e024d607c0ec06c2a2fb9408cc99:
> 
>   tools lib traceevent, perf tools: Move struct tep_handler definition in a 
> local header file (2018-10-08 15:05:37 -0300)
> 
> 
> perf/core improvements and fixes:
> 
> . Fix building the python bindings with python3, which fixes some
>   problems with building with clang on Clear Linux (Eduardo Habkost)
> 
> . Fix coverity warnings, fixing up some error paths and plugging
>   some temporary small buffer leaks (Sanskriti Sharma)
> 
> . Adopt a wrapper for strerror_r() for the same reasons as recently
>   for libbpf (Steven Rostedt)
> 
> . S390 does not support watchpoints in 'perf test 22', check if
>   that test is supported by the arch. (Thomas Richter)
> 
> Signed-off-by: Arnaldo Carvalho de Melo 
> 
> 
> Arnaldo Carvalho de Melo (2):
>   tools include: Adopt linux/bits.h
>   perf auxtrace: Include missing asm/bitsperlong.h to get BITS_PER_LONG
> 
> Eduardo Habkost (2):
>   perf python: Make clang_has_option() work on Python 3
>   perf python: More portable way to make CFLAGS work with clang
> 
> Sanskriti Sharma (5):
>   perf strbuf: Match va_{add,copy} with va_end
>   perf tools: Cleanup trace-event-info 'tdata' leak
>   perf tools: Free 'printk' string in parse_ftrace_printk()
>   perf tools: Avoid double free in read_event_file()
>   perf tools: Free temporary 'sys' string in read_event_files()
> 
> Steven Rostedt (VMware) (1):
>   tools lib traceevent: Separate out tep_strerror() for strerror_r() 
> issues
> 
> Thomas Richter (1):
>   perf test: S390 does not support watchpoints in test 22
> 
> Tzvetomir Stoyanov (1):
>   tools lib traceevent, perf tools: Move struct tep_handler definition in 
> a local header file
> 
>  tools/include/linux/bitops.h |   7 +-
>  tools/include/linux/bits.h   |  26 +++
>  tools/lib/traceevent/Build   |   2 +
>  tools/lib/traceevent/event-parse-api.c   | 275 
> +++
>  tools/lib/traceevent/event-parse-local.h |  92 +++
>  tools/lib/traceevent/event-parse.c   |  32 +---
>  tools/lib/traceevent/event-parse.h   | 228 -
>  tools/lib/traceevent/event-plugin.c  |   1 +
>  tools/lib/traceevent/parse-filter.c  |   1 +
>  tools/lib/traceevent/tep_strerror.c  |  53 ++
>  tools/perf/check-headers.sh  |   1 +
>  tools/perf/tests/builtin-test.c  |   1 +
>  tools/perf/tests/tests.h |   1 +
>  tools/perf/tests/wp.c|  12 ++
>  tools/perf/util/auxtrace.h   |   1 +
>  tools/perf/util/setup.py |  16 +-
>  tools/perf/util/strbuf.c |  10 +-
>  tools/perf/util/trace-event-info.c   |   2 +
>  tools/perf/util/trace-event-parse.c  |  26 +--
>  tools/perf/util/trace-event-read.c   |  11 +-
>  20 files changed, 539 insertions(+), 259 deletions(-)
>  create mode 100644 tools/include/linux/bits.h
>  create mode 100644 tools/lib/traceevent/event-parse-api.c
>  create mode 100644 tools/lib/traceevent/event-parse-local.h
>  create mode 100644 tools/lib/traceevent/tep_strerror.c

Pulled, thanks a lot Arnaldo!

Ingo


Re: [GIT PULL 00/12] perf/core improvements and fixes

2018-10-08 Thread Ingo Molnar


* Arnaldo Carvalho de Melo  wrote:

> Hi Ingo,
> 
>   Please consider pulling,
> 
> - Arnaldo
> 
> Test results at the end of this message, as usual.
> 
> The following changes since commit 7c5314b88da6d5af98239786772a1c44cc5eb67d:
> 
>   perf/x86/intel: Add quirk for Goldmont Plus (2018-10-02 10:14:33 +0200)
> 
> are available in the Git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git 
> tags/perf-core-for-mingo-4.20-20181008
> 
> for you to fetch changes up to bb3dd7e7c4d5e024d607c0ec06c2a2fb9408cc99:
> 
>   tools lib traceevent, perf tools: Move struct tep_handler definition in a 
> local header file (2018-10-08 15:05:37 -0300)
> 
> 
> perf/core improvements and fixes:
> 
> . Fix building the python bindings with python3, which fixes some
>   problems with building with clang on Clear Linux (Eduardo Habkost)
> 
> . Fix coverity warnings, fixing up some error paths and plugging
>   some temporary small buffer leaks (Sanskriti Sharma)
> 
> . Adopt a wrapper for strerror_r() for the same reasons as recently
>   for libbpf (Steven Rostedt)
> 
> . S390 does not support watchpoints in 'perf test 22', check if
>   that test is supported by the arch. (Thomas Richter)
> 
> Signed-off-by: Arnaldo Carvalho de Melo 
> 
> 
> Arnaldo Carvalho de Melo (2):
>   tools include: Adopt linux/bits.h
>   perf auxtrace: Include missing asm/bitsperlong.h to get BITS_PER_LONG
> 
> Eduardo Habkost (2):
>   perf python: Make clang_has_option() work on Python 3
>   perf python: More portable way to make CFLAGS work with clang
> 
> Sanskriti Sharma (5):
>   perf strbuf: Match va_{add,copy} with va_end
>   perf tools: Cleanup trace-event-info 'tdata' leak
>   perf tools: Free 'printk' string in parse_ftrace_printk()
>   perf tools: Avoid double free in read_event_file()
>   perf tools: Free temporary 'sys' string in read_event_files()
> 
> Steven Rostedt (VMware) (1):
>   tools lib traceevent: Separate out tep_strerror() for strerror_r() 
> issues
> 
> Thomas Richter (1):
>   perf test: S390 does not support watchpoints in test 22
> 
> Tzvetomir Stoyanov (1):
>   tools lib traceevent, perf tools: Move struct tep_handler definition in 
> a local header file
> 
>  tools/include/linux/bitops.h |   7 +-
>  tools/include/linux/bits.h   |  26 +++
>  tools/lib/traceevent/Build   |   2 +
>  tools/lib/traceevent/event-parse-api.c   | 275 
> +++
>  tools/lib/traceevent/event-parse-local.h |  92 +++
>  tools/lib/traceevent/event-parse.c   |  32 +---
>  tools/lib/traceevent/event-parse.h   | 228 -
>  tools/lib/traceevent/event-plugin.c  |   1 +
>  tools/lib/traceevent/parse-filter.c  |   1 +
>  tools/lib/traceevent/tep_strerror.c  |  53 ++
>  tools/perf/check-headers.sh  |   1 +
>  tools/perf/tests/builtin-test.c  |   1 +
>  tools/perf/tests/tests.h |   1 +
>  tools/perf/tests/wp.c|  12 ++
>  tools/perf/util/auxtrace.h   |   1 +
>  tools/perf/util/setup.py |  16 +-
>  tools/perf/util/strbuf.c |  10 +-
>  tools/perf/util/trace-event-info.c   |   2 +
>  tools/perf/util/trace-event-parse.c  |  26 +--
>  tools/perf/util/trace-event-read.c   |  11 +-
>  20 files changed, 539 insertions(+), 259 deletions(-)
>  create mode 100644 tools/include/linux/bits.h
>  create mode 100644 tools/lib/traceevent/event-parse-api.c
>  create mode 100644 tools/lib/traceevent/event-parse-local.h
>  create mode 100644 tools/lib/traceevent/tep_strerror.c

Pulled, thanks a lot Arnaldo!

Ingo


Re: linux-next: build failure after merge of the ext4 tree

2018-10-08 Thread Theodore Y. Ts'o
On Tue, Oct 09, 2018 at 10:51:02AM +1100, Stephen Rothwell wrote:
> Hi Ted,
> 
> After merging the ext4 tree, today's linux-next build (arm
> multi_v7_defconfig) failed like this:

Oops, my bad.  Thanks for catching this.  I failed to a new helper
function inside #ifdef CONFIG_QUOTA .. #endif.

Should be fixed now.

- Ted


Re: linux-next: build failure after merge of the ext4 tree

2018-10-08 Thread Theodore Y. Ts'o
On Tue, Oct 09, 2018 at 10:51:02AM +1100, Stephen Rothwell wrote:
> Hi Ted,
> 
> After merging the ext4 tree, today's linux-next build (arm
> multi_v7_defconfig) failed like this:

Oops, my bad.  Thanks for catching this.  I failed to a new helper
function inside #ifdef CONFIG_QUOTA .. #endif.

Should be fixed now.

- Ted


Re: [PATCH 2/6] phy: am654-mmc-phy: Add Support for MMC PHY on AM654 Devices

2018-10-08 Thread Kishon Vijay Abraham I
Hi Uffe,

On Monday 08 October 2018 05:02 PM, Ulf Hansson wrote:
> On 4 October 2018 at 13:14, Faiz Abbas  wrote:
>> Add driver support for the MMC physical layer present
>> on TI's AM654 devices.
>>
>> Signed-off-by: Faiz Abbas 
>> Signed-off-by: Sekhar Nori 
> 
> I assume Kishon would like to pick up this through his tree? If not,
> please tell and I can do it, with his ack.

yes, I'll pick this in my tree.

> 
> Reviewed-by: Ulf Hansson 

Thanks
Kishon

> 
> Kind regards
> Uffe
> 
>> ---
>>  drivers/phy/ti/Kconfig |   7 +
>>  drivers/phy/ti/Makefile|   1 +
>>  drivers/phy/ti/phy-am654-mmc.c | 291 +
>>  3 files changed, 299 insertions(+)
>>  create mode 100644 drivers/phy/ti/phy-am654-mmc.c
>>
>> diff --git a/drivers/phy/ti/Kconfig b/drivers/phy/ti/Kconfig
>> index 20503562666c..ea5fe4db01c8 100644
>> --- a/drivers/phy/ti/Kconfig
>> +++ b/drivers/phy/ti/Kconfig
>> @@ -76,3 +76,10 @@ config TWL4030_USB
>>   family chips (including the TWL5030 and TPS659x0 devices).
>>   This transceiver supports high and full speed devices plus,
>>   in host mode, low speed.
>> +
>> +config PHY_AM654_MMC
>> +   bool "TI AM654 MMC PHY Support"
>> +   select GENERIC_PHY
>> +   help
>> + This option enables support for the Physical layer for MMC host
>> + controllers present on TI AM654 SOCs.
>> diff --git a/drivers/phy/ti/Makefile b/drivers/phy/ti/Makefile
>> index 9f361756eaf2..5b2db2d164a5 100644
>> --- a/drivers/phy/ti/Makefile
>> +++ b/drivers/phy/ti/Makefile
>> @@ -6,3 +6,4 @@ obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
>>  obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
>>  obj-$(CONFIG_PHY_TUSB1210) += phy-tusb1210.o
>>  obj-$(CONFIG_TWL4030_USB)  += phy-twl4030-usb.o
>> +obj-$(CONFIG_PHY_AM654_MMC)+= phy-am654-mmc.o
>> diff --git a/drivers/phy/ti/phy-am654-mmc.c b/drivers/phy/ti/phy-am654-mmc.c
>> new file mode 100644
>> index ..91255947fb67
>> --- /dev/null
>> +++ b/drivers/phy/ti/phy-am654-mmc.c
>> @@ -0,0 +1,291 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * phy-am654-mmc.c - MMC PHY driver for TI's AM654 SOCs
>> + *
>> + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +/* MMC PHY Registers */
>> +#define PHYCTRL_CTRL1_REG  0x00
>> +#define PHYCTRL_CTRL2_REG  0x04
>> +#define PHYCTRL_CTRL3_REG  0x08
>> +#define PHYCTRL_CTRL4_REG  0x0C
>> +#define PHYCTRL_CTRL5_REG  0x10
>> +#define PHYCTRL_CTRL6_REG  0x14
>> +#define PHYCTRL_STAT1_REG  0x30
>> +#define PHYCTRL_STAT2_REG  0x34
>> +
>> +#define IOMUX_ENABLE_SHIFT 31
>> +#define IOMUX_ENABLE_MASK  BIT(IOMUX_ENABLE_SHIFT)
>> +#define OTAPDLYENA_SHIFT   20
>> +#define OTAPDLYENA_MASKBIT(OTAPDLYENA_SHIFT)
>> +#define OTAPDLYSEL_SHIFT   12
>> +#define OTAPDLYSEL_MASKGENMASK(15, 12)
>> +#define STRBSEL_SHIFT  24
>> +#define STRBSEL_MASK   GENMASK(27, 24)
>> +#define SEL50_SHIFT8
>> +#define SEL50_MASK BIT(SEL50_SHIFT)
>> +#define SEL100_SHIFT   9
>> +#define SEL100_MASKBIT(SEL100_SHIFT)
>> +#define DLL_TRIM_ICP_SHIFT 4
>> +#define DLL_TRIM_ICP_MASK  GENMASK(7, 4)
>> +#define DR_TY_SHIFT20
>> +#define DR_TY_MASK GENMASK(22, 20)
>> +#define ENDLL_SHIFT1
>> +#define ENDLL_MASK BIT(ENDLL_SHIFT)
>> +#define DLLRDY_SHIFT   0
>> +#define DLLRDY_MASKBIT(DLLRDY_SHIFT)
>> +#define PDB_SHIFT  0
>> +#define PDB_MASK   BIT(PDB_SHIFT)
>> +#define CALDONE_SHIFT  1
>> +#define CALDONE_MASK   BIT(CALDONE_SHIFT)
>> +
>> +#define DRIVER_STRENGTH_50_OHM 0x0
>> +#define DRIVER_STRENGTH_33_OHM 0x1
>> +#define DRIVER_STRENGTH_66_OHM 0x2
>> +#define DRIVER_STRENGTH_100_OHM0x3
>> +#define DRIVER_STRENGTH_40_OHM 0x4
>> +
>> +static struct regmap_config am654_mmc_phy_regmap_config = {
>> +   .reg_bits = 32,
>> +   .val_bits = 32,
>> +   .reg_stride = 4,
>> +   .fast_io = true,
>> +};
>> +
>> +struct am654_mmc_phy {
>> +   struct regmap *reg_base;
>> +   struct clk *mmcclk;
>> +   int otap_del_sel;
>> +   int trm_icp;
>> +   int drv_strength;
>> +};
>> +
>> +static int am654_mmc_phy_init(struct phy *phy)
>> +{
>> +   struct am654_mmc_phy *mmc_phy = phy_get_drvdata(phy);
>> +   int ret;
>> +   u32 val;
>> +
>> +   /* Reset registers to default value */
>> +   regmap_write(mmc_phy->reg_base, PHYCTRL_CTRL1_REG, 0x1);
>> +   regmap_write(mmc_phy->reg_base, PHYCTRL_CTRL4_REG, 0x0);
>> +   regmap_write(mmc_phy->reg_base, PHYCTRL_CTRL5_REG, 0x0);
>> +
>> +   /* Calibrate IO lines */
>> +   regmap_update_bits(mmc_phy->reg_base, PHYCTRL_CTRL1_REG,
>> +

Re: [PATCH 2/6] phy: am654-mmc-phy: Add Support for MMC PHY on AM654 Devices

2018-10-08 Thread Kishon Vijay Abraham I
Hi Uffe,

On Monday 08 October 2018 05:02 PM, Ulf Hansson wrote:
> On 4 October 2018 at 13:14, Faiz Abbas  wrote:
>> Add driver support for the MMC physical layer present
>> on TI's AM654 devices.
>>
>> Signed-off-by: Faiz Abbas 
>> Signed-off-by: Sekhar Nori 
> 
> I assume Kishon would like to pick up this through his tree? If not,
> please tell and I can do it, with his ack.

yes, I'll pick this in my tree.

> 
> Reviewed-by: Ulf Hansson 

Thanks
Kishon

> 
> Kind regards
> Uffe
> 
>> ---
>>  drivers/phy/ti/Kconfig |   7 +
>>  drivers/phy/ti/Makefile|   1 +
>>  drivers/phy/ti/phy-am654-mmc.c | 291 +
>>  3 files changed, 299 insertions(+)
>>  create mode 100644 drivers/phy/ti/phy-am654-mmc.c
>>
>> diff --git a/drivers/phy/ti/Kconfig b/drivers/phy/ti/Kconfig
>> index 20503562666c..ea5fe4db01c8 100644
>> --- a/drivers/phy/ti/Kconfig
>> +++ b/drivers/phy/ti/Kconfig
>> @@ -76,3 +76,10 @@ config TWL4030_USB
>>   family chips (including the TWL5030 and TPS659x0 devices).
>>   This transceiver supports high and full speed devices plus,
>>   in host mode, low speed.
>> +
>> +config PHY_AM654_MMC
>> +   bool "TI AM654 MMC PHY Support"
>> +   select GENERIC_PHY
>> +   help
>> + This option enables support for the Physical layer for MMC host
>> + controllers present on TI AM654 SOCs.
>> diff --git a/drivers/phy/ti/Makefile b/drivers/phy/ti/Makefile
>> index 9f361756eaf2..5b2db2d164a5 100644
>> --- a/drivers/phy/ti/Makefile
>> +++ b/drivers/phy/ti/Makefile
>> @@ -6,3 +6,4 @@ obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
>>  obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
>>  obj-$(CONFIG_PHY_TUSB1210) += phy-tusb1210.o
>>  obj-$(CONFIG_TWL4030_USB)  += phy-twl4030-usb.o
>> +obj-$(CONFIG_PHY_AM654_MMC)+= phy-am654-mmc.o
>> diff --git a/drivers/phy/ti/phy-am654-mmc.c b/drivers/phy/ti/phy-am654-mmc.c
>> new file mode 100644
>> index ..91255947fb67
>> --- /dev/null
>> +++ b/drivers/phy/ti/phy-am654-mmc.c
>> @@ -0,0 +1,291 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * phy-am654-mmc.c - MMC PHY driver for TI's AM654 SOCs
>> + *
>> + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +/* MMC PHY Registers */
>> +#define PHYCTRL_CTRL1_REG  0x00
>> +#define PHYCTRL_CTRL2_REG  0x04
>> +#define PHYCTRL_CTRL3_REG  0x08
>> +#define PHYCTRL_CTRL4_REG  0x0C
>> +#define PHYCTRL_CTRL5_REG  0x10
>> +#define PHYCTRL_CTRL6_REG  0x14
>> +#define PHYCTRL_STAT1_REG  0x30
>> +#define PHYCTRL_STAT2_REG  0x34
>> +
>> +#define IOMUX_ENABLE_SHIFT 31
>> +#define IOMUX_ENABLE_MASK  BIT(IOMUX_ENABLE_SHIFT)
>> +#define OTAPDLYENA_SHIFT   20
>> +#define OTAPDLYENA_MASKBIT(OTAPDLYENA_SHIFT)
>> +#define OTAPDLYSEL_SHIFT   12
>> +#define OTAPDLYSEL_MASKGENMASK(15, 12)
>> +#define STRBSEL_SHIFT  24
>> +#define STRBSEL_MASK   GENMASK(27, 24)
>> +#define SEL50_SHIFT8
>> +#define SEL50_MASK BIT(SEL50_SHIFT)
>> +#define SEL100_SHIFT   9
>> +#define SEL100_MASKBIT(SEL100_SHIFT)
>> +#define DLL_TRIM_ICP_SHIFT 4
>> +#define DLL_TRIM_ICP_MASK  GENMASK(7, 4)
>> +#define DR_TY_SHIFT20
>> +#define DR_TY_MASK GENMASK(22, 20)
>> +#define ENDLL_SHIFT1
>> +#define ENDLL_MASK BIT(ENDLL_SHIFT)
>> +#define DLLRDY_SHIFT   0
>> +#define DLLRDY_MASKBIT(DLLRDY_SHIFT)
>> +#define PDB_SHIFT  0
>> +#define PDB_MASK   BIT(PDB_SHIFT)
>> +#define CALDONE_SHIFT  1
>> +#define CALDONE_MASK   BIT(CALDONE_SHIFT)
>> +
>> +#define DRIVER_STRENGTH_50_OHM 0x0
>> +#define DRIVER_STRENGTH_33_OHM 0x1
>> +#define DRIVER_STRENGTH_66_OHM 0x2
>> +#define DRIVER_STRENGTH_100_OHM0x3
>> +#define DRIVER_STRENGTH_40_OHM 0x4
>> +
>> +static struct regmap_config am654_mmc_phy_regmap_config = {
>> +   .reg_bits = 32,
>> +   .val_bits = 32,
>> +   .reg_stride = 4,
>> +   .fast_io = true,
>> +};
>> +
>> +struct am654_mmc_phy {
>> +   struct regmap *reg_base;
>> +   struct clk *mmcclk;
>> +   int otap_del_sel;
>> +   int trm_icp;
>> +   int drv_strength;
>> +};
>> +
>> +static int am654_mmc_phy_init(struct phy *phy)
>> +{
>> +   struct am654_mmc_phy *mmc_phy = phy_get_drvdata(phy);
>> +   int ret;
>> +   u32 val;
>> +
>> +   /* Reset registers to default value */
>> +   regmap_write(mmc_phy->reg_base, PHYCTRL_CTRL1_REG, 0x1);
>> +   regmap_write(mmc_phy->reg_base, PHYCTRL_CTRL4_REG, 0x0);
>> +   regmap_write(mmc_phy->reg_base, PHYCTRL_CTRL5_REG, 0x0);
>> +
>> +   /* Calibrate IO lines */
>> +   regmap_update_bits(mmc_phy->reg_base, PHYCTRL_CTRL1_REG,
>> +

linux-next: manual merge of the staging tree with the vfs tree

2018-10-08 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the staging tree got a conflict in:

  drivers/staging/dgnc/dgnc_tty.c

between commits:

  b68166ef8fd9 ("dgnc: leave TIOC[GS]SOFTCAR to ldisc")
  e002c6f1ccb9 ("dgnc: don't bother with (empty) stub for TCXONC")
  79273fc94ee9 ("dgnc: break-related ioctls won't reach ->ioctl()")
  246d394c9cc5 ("dgnc: TIOCM... won't reach ->ioctl()")

from the vfs tree and commit:

  3268357865d6 ("staging: dgnc: delete the driver")

from the staging tree.

I fixed it up (I just removed the file) and can carry the fix as
necessary. This is now fixed as far as linux-next is concerned, but any
non trivial conflicts should be mentioned to your upstream maintainer
when your tree is submitted for merging.  You may also want to consider
cooperating with the maintainer of the conflicting tree to minimise any
particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell


pgp4G2TROuGFd.pgp
Description: OpenPGP digital signature


linux-next: manual merge of the staging tree with the vfs tree

2018-10-08 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the staging tree got a conflict in:

  drivers/staging/dgnc/dgnc_tty.c

between commits:

  b68166ef8fd9 ("dgnc: leave TIOC[GS]SOFTCAR to ldisc")
  e002c6f1ccb9 ("dgnc: don't bother with (empty) stub for TCXONC")
  79273fc94ee9 ("dgnc: break-related ioctls won't reach ->ioctl()")
  246d394c9cc5 ("dgnc: TIOCM... won't reach ->ioctl()")

from the vfs tree and commit:

  3268357865d6 ("staging: dgnc: delete the driver")

from the staging tree.

I fixed it up (I just removed the file) and can carry the fix as
necessary. This is now fixed as far as linux-next is concerned, but any
non trivial conflicts should be mentioned to your upstream maintainer
when your tree is submitted for merging.  You may also want to consider
cooperating with the maintainer of the conflicting tree to minimise any
particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell


pgp4G2TROuGFd.pgp
Description: OpenPGP digital signature


Re: [PATCH 1/4] gpio: Assign gpio_irq_chip::parents to non-stack pointer

2018-10-08 Thread kbuild test robot
Hi Stephen,

I love your patch! Perhaps something to improve:

[auto build test WARNING on gpio/for-next]
[also build test WARNING on v4.19-rc7 next-20181008]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Stephen-Boyd/gpio-chip-cascade-fixes/20181009-041639
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git 
for-next
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: w

Re: [PATCH 1/4] gpio: Assign gpio_irq_chip::parents to non-stack pointer

2018-10-08 Thread kbuild test robot
Hi Stephen,

I love your patch! Perhaps something to improve:

[auto build test WARNING on gpio/for-next]
[also build test WARNING on v4.19-rc7 next-20181008]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Stephen-Boyd/gpio-chip-cascade-fixes/20181009-041639
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git 
for-next
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: warning: Excess function parameter 'ptr' 
description in 'reg_query_regdb_wmm'
   include/net/cfg80211.h:4869: w

kernel BUG at fs/block_dev.c:LINE!

2018-10-08 Thread syzbot

Hello,

syzbot found the following crash on:

HEAD commit:0854ba5ff5c9 Merge git://git.kernel.org/pub/scm/linux/kern..
git tree:   upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1554ec0640
kernel config:  https://syzkaller.appspot.com/x/.config?x=88e9a8a39dc0be2d
dashboard link: https://syzkaller.appspot.com/bug?extid=82909b30c4657137bf84
compiler:   gcc (GCC) 8.0.1 20180413 (experimental)
syz repro:  https://syzkaller.appspot.com/x/repro.syz?x=1033197640
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=165db54e40

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+82909b30c4657137b...@syzkaller.appspotmail.com

 loop1: p1
 loop4: p1
 loop3: p1
 loop5: p1
[ cut here ]
kernel BUG at fs/block_dev.c:1627!
invalid opcode:  [#1] PREEMPT SMP KASAN
CPU: 1 PID: 6913 Comm: syz-executor753 Not tainted 4.19.0-rc7+ #53
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011

RIP: 0010:blkdev_get+0x65f/0xb50 fs/block_dev.c:1627
Code: ff ff ff 0f 84 4d 03 00 00 48 89 85 f0 fe ff ff e8 f6 fa 9d ff 48 8b  
85 f0 fe ff ff 48 85 c0 0f 84 9b 00 00 00 e8 e1 fa 9d ff <0f> 0b e8 da fa  
9d ff 4c 89 e2 48 b8 00 00 00 00 00 fc ff df 48 c1

RSP: 0018:8801c0a8f578 EFLAGS: 00010293
RAX: 8801c083a700 RBX:  RCX: 81e0da52
RDX:  RSI: 81e0daaf RDI: 0005
RBP: 8801c0a8f6a8 R08: 8801c083a700 R09: fbfff12424f0
R10: fbfff12424f0 R11: 89212783 R12: 8801d3ac0318
R13: 8801d3bee2d8 R14: 8801d3bee2c0 R15: 8801d3ac0280
FS:  01359880() GS:8801daf0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 00606ed8 CR3: 0001c12d3000 CR4: 001406e0
DR0:  DR1:  DR2: 
DR3:  DR6: fffe0ff0 DR7: 0400
Call Trace:
 blkdev_open+0x1fb/0x280 fs/block_dev.c:1775
 do_dentry_open+0x499/0x1250 fs/open.c:771
 vfs_open+0xa0/0xd0 fs/open.c:880
 do_last fs/namei.c:3418 [inline]
 path_openat+0x12bf/0x5160 fs/namei.c:3534
 do_filp_open+0x255/0x380 fs/namei.c:3564
 do_sys_open+0x568/0x700 fs/open.c:1063
 __do_sys_openat fs/open.c:1090 [inline]
 __se_sys_openat fs/open.c:1084 [inline]
 __x64_sys_openat+0x9d/0x100 fs/open.c:1084
 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x445589
Code: fd cd fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7  
48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff  
ff 0f 83 cb cd fb ff c3 66 2e 0f 1f 84 00 00 00 00

RSP: 002b:7ffd31e04eb8 EFLAGS: 0286 ORIG_RAX: 0101
RAX: ffda RBX: 2080 RCX: 00445589
RDX: 008001a0 RSI: 2080 RDI: ff9c
RBP: 706e692f7665642f R08: 0001 R09: 0001
R10:  R11: 0286 R12: 00069554
R13: 00402870 R14:  R15: 
Modules linked in:
---[ end trace bcaf07e3e9ad4219 ]---
RIP: 0010:blkdev_get+0x65f/0xb50 fs/block_dev.c:1627
Code: ff ff ff 0f 84 4d 03 00 00 48 89 85 f0 fe ff ff e8 f6 fa 9d ff 48 8b  
85 f0 fe ff ff 48 85 c0 0f 84 9b 00 00 00 e8 e1 fa 9d ff <0f> 0b e8 da fa  
9d ff 4c 89 e2 48 b8 00 00 00 00 00 fc ff df 48 c1

RSP: 0018:8801c0a8f578 EFLAGS: 00010293
RAX: 8801c083a700 RBX:  RCX: 81e0da52
RDX:  RSI: 81e0daaf RDI: 0005
RBP: 8801c0a8f6a8 R08: 8801c083a700 R09: fbfff12424f0
R10: fbfff12424f0 R11: 89212783 R12: 8801d3ac0318
R13: 8801d3bee2d8 R14: 8801d3bee2c0 R15: 8801d3ac0280
FS:  01359880() GS:8801daf0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 00606ed8 CR3: 0001c12d3000 CR4: 001406e0
DR0:  DR1:  DR2: 
DR3:  DR6: fffe0ff0 DR7: 0400


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkal...@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#bug-status-tracking for how to communicate with  
syzbot.

syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches


kernel BUG at fs/block_dev.c:LINE!

2018-10-08 Thread syzbot

Hello,

syzbot found the following crash on:

HEAD commit:0854ba5ff5c9 Merge git://git.kernel.org/pub/scm/linux/kern..
git tree:   upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1554ec0640
kernel config:  https://syzkaller.appspot.com/x/.config?x=88e9a8a39dc0be2d
dashboard link: https://syzkaller.appspot.com/bug?extid=82909b30c4657137bf84
compiler:   gcc (GCC) 8.0.1 20180413 (experimental)
syz repro:  https://syzkaller.appspot.com/x/repro.syz?x=1033197640
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=165db54e40

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+82909b30c4657137b...@syzkaller.appspotmail.com

 loop1: p1
 loop4: p1
 loop3: p1
 loop5: p1
[ cut here ]
kernel BUG at fs/block_dev.c:1627!
invalid opcode:  [#1] PREEMPT SMP KASAN
CPU: 1 PID: 6913 Comm: syz-executor753 Not tainted 4.19.0-rc7+ #53
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011

RIP: 0010:blkdev_get+0x65f/0xb50 fs/block_dev.c:1627
Code: ff ff ff 0f 84 4d 03 00 00 48 89 85 f0 fe ff ff e8 f6 fa 9d ff 48 8b  
85 f0 fe ff ff 48 85 c0 0f 84 9b 00 00 00 e8 e1 fa 9d ff <0f> 0b e8 da fa  
9d ff 4c 89 e2 48 b8 00 00 00 00 00 fc ff df 48 c1

RSP: 0018:8801c0a8f578 EFLAGS: 00010293
RAX: 8801c083a700 RBX:  RCX: 81e0da52
RDX:  RSI: 81e0daaf RDI: 0005
RBP: 8801c0a8f6a8 R08: 8801c083a700 R09: fbfff12424f0
R10: fbfff12424f0 R11: 89212783 R12: 8801d3ac0318
R13: 8801d3bee2d8 R14: 8801d3bee2c0 R15: 8801d3ac0280
FS:  01359880() GS:8801daf0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 00606ed8 CR3: 0001c12d3000 CR4: 001406e0
DR0:  DR1:  DR2: 
DR3:  DR6: fffe0ff0 DR7: 0400
Call Trace:
 blkdev_open+0x1fb/0x280 fs/block_dev.c:1775
 do_dentry_open+0x499/0x1250 fs/open.c:771
 vfs_open+0xa0/0xd0 fs/open.c:880
 do_last fs/namei.c:3418 [inline]
 path_openat+0x12bf/0x5160 fs/namei.c:3534
 do_filp_open+0x255/0x380 fs/namei.c:3564
 do_sys_open+0x568/0x700 fs/open.c:1063
 __do_sys_openat fs/open.c:1090 [inline]
 __se_sys_openat fs/open.c:1084 [inline]
 __x64_sys_openat+0x9d/0x100 fs/open.c:1084
 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x445589
Code: fd cd fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7  
48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff  
ff 0f 83 cb cd fb ff c3 66 2e 0f 1f 84 00 00 00 00

RSP: 002b:7ffd31e04eb8 EFLAGS: 0286 ORIG_RAX: 0101
RAX: ffda RBX: 2080 RCX: 00445589
RDX: 008001a0 RSI: 2080 RDI: ff9c
RBP: 706e692f7665642f R08: 0001 R09: 0001
R10:  R11: 0286 R12: 00069554
R13: 00402870 R14:  R15: 
Modules linked in:
---[ end trace bcaf07e3e9ad4219 ]---
RIP: 0010:blkdev_get+0x65f/0xb50 fs/block_dev.c:1627
Code: ff ff ff 0f 84 4d 03 00 00 48 89 85 f0 fe ff ff e8 f6 fa 9d ff 48 8b  
85 f0 fe ff ff 48 85 c0 0f 84 9b 00 00 00 e8 e1 fa 9d ff <0f> 0b e8 da fa  
9d ff 4c 89 e2 48 b8 00 00 00 00 00 fc ff df 48 c1

RSP: 0018:8801c0a8f578 EFLAGS: 00010293
RAX: 8801c083a700 RBX:  RCX: 81e0da52
RDX:  RSI: 81e0daaf RDI: 0005
RBP: 8801c0a8f6a8 R08: 8801c083a700 R09: fbfff12424f0
R10: fbfff12424f0 R11: 89212783 R12: 8801d3ac0318
R13: 8801d3bee2d8 R14: 8801d3bee2c0 R15: 8801d3ac0280
FS:  01359880() GS:8801daf0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 00606ed8 CR3: 0001c12d3000 CR4: 001406e0
DR0:  DR1:  DR2: 
DR3:  DR6: fffe0ff0 DR7: 0400


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkal...@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#bug-status-tracking for how to communicate with  
syzbot.

syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches


Re: [PATCH] RCU: Adjust the comment of function rcu_is_watching

2018-10-08 Thread Paul E. McKenney
On Mon, Oct 08, 2018 at 06:50:41AM +, zhouzho...@gmail.com wrote:
> From: Zhouyi Zhou 
> 
> Because RCU avoids interrupting idle CPUs, rcu_is_watching is used to
> test whether or not it is currently legal to run RCU read-side 
> critical sections on this CPU. 
> 
> First sentence and last sentence of current comment for rcu_is_watching
> have opposite meaning of what is expected.  
> 
> Signed-off-by: Zhouyi Zhou 

Good eyes!  Applied and pushed, thank you!

Thanx, Paul

> ---
>  kernel/rcu/tree.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index 0b760c1..adb04ea 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -1010,12 +1010,12 @@ void rcu_irq_enter_irqson(void)
>  }
> 
>  /**
> - * rcu_is_watching - see if RCU thinks that the current CPU is idle
> + * rcu_is_watching - see if RCU thinks that the current CPU is not idle
>   *
>   * Return true if RCU is watching the running CPU, which means that this
>   * CPU can safely enter RCU read-side critical sections.  In other words,
> - * if the current CPU is in its idle loop and is neither in an interrupt
> - * or NMI handler, return true.
> + * if the current CPU is not in its idle loop or is in an interrupt or
> + * NMI handler, return true.
>   */
>  bool notrace rcu_is_watching(void)
>  {
> -- 
> 2.1.4
> 



Re: [PATCH] RCU: Adjust the comment of function rcu_is_watching

2018-10-08 Thread Paul E. McKenney
On Mon, Oct 08, 2018 at 06:50:41AM +, zhouzho...@gmail.com wrote:
> From: Zhouyi Zhou 
> 
> Because RCU avoids interrupting idle CPUs, rcu_is_watching is used to
> test whether or not it is currently legal to run RCU read-side 
> critical sections on this CPU. 
> 
> First sentence and last sentence of current comment for rcu_is_watching
> have opposite meaning of what is expected.  
> 
> Signed-off-by: Zhouyi Zhou 

Good eyes!  Applied and pushed, thank you!

Thanx, Paul

> ---
>  kernel/rcu/tree.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index 0b760c1..adb04ea 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -1010,12 +1010,12 @@ void rcu_irq_enter_irqson(void)
>  }
> 
>  /**
> - * rcu_is_watching - see if RCU thinks that the current CPU is idle
> + * rcu_is_watching - see if RCU thinks that the current CPU is not idle
>   *
>   * Return true if RCU is watching the running CPU, which means that this
>   * CPU can safely enter RCU read-side critical sections.  In other words,
> - * if the current CPU is in its idle loop and is neither in an interrupt
> - * or NMI handler, return true.
> + * if the current CPU is not in its idle loop or is in an interrupt or
> + * NMI handler, return true.
>   */
>  bool notrace rcu_is_watching(void)
>  {
> -- 
> 2.1.4
> 



Re: [RESEND PATCH 1/2] mtd: spi-nor: add macros related to MICRON flash

2018-10-08 Thread Tudor Ambarus



On 09/19/2018 07:50 AM, Yogesh Gaur wrote:
> Some MICRON related macros in spi-nor domain were ST.
> Rename entries related to STMicroelectronics under macro SNOR_MFR_ST.
> 
> Added entry of MFR Id for Micron flashes, 0x002C.
> 
> Signed-off-by: Yogesh Gaur 

Reviewed-by: Tudor Ambarus 

> ---
>  drivers/mtd/spi-nor/spi-nor.c | 9 ++---
>  include/linux/mtd/cfi.h   | 1 +
>  include/linux/mtd/spi-nor.h   | 3 ++-
>  3 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index f028277..33a55bc 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -271,6 +271,7 @@ static inline int set_4byte(struct spi_nor *nor, const 
> struct flash_info *info,
>   u8 cmd;
>  
>   switch (JEDEC_MFR(info)) {
> + case SNOR_MFR_ST:
>   case SNOR_MFR_MICRON:
>   /* Some Micron need WREN command; all will accept it */
>   need_wren = true;
> @@ -1096,7 +1097,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, 
> loff_t ofs, uint64_t len)
>   { "mx66l1g45g",  INFO(0xc2201b, 0, 64 * 1024, 2048, SECT_4K | 
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
>   { "mx66l1g55g",  INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) 
> },
>  
> - /* Micron */
> + /* Micron <--> ST Micro */
>   { "n25q016a",INFO(0x20bb15, 0, 64 * 1024,   32, SECT_4K | 
> SPI_NOR_QUAD_READ) },
>   { "n25q032", INFO(0x20ba16, 0, 64 * 1024,   64, SPI_NOR_QUAD_READ) 
> },
>   { "n25q032a",INFO(0x20bb16, 0, 64 * 1024,   64, SPI_NOR_QUAD_READ) 
> },
> @@ -2502,6 +2503,7 @@ static int spi_nor_init_params(struct spi_nor *nor,
>   params->quad_enable = macronix_quad_enable;
>   break;
>  
> + case SNOR_MFR_ST:
>   case SNOR_MFR_MICRON:
>   break;
>  
> @@ -2876,8 +2878,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>   mtd->_resume = spi_nor_resume;
>  
>   /* NOR protection support for STmicro/Micron chips and similar */
> - if (JEDEC_MFR(info) == SNOR_MFR_MICRON ||
> - info->flags & SPI_NOR_HAS_LOCK) {
> + if (JEDEC_MFR(info) == SNOR_MFR_ST ||
> + JEDEC_MFR(info) == SNOR_MFR_MICRON ||
> + info->flags & SPI_NOR_HAS_LOCK) {
>   nor->flash_lock = stm_lock;
>   nor->flash_unlock = stm_unlock;
>   nor->flash_is_locked = stm_is_locked;
> diff --git a/include/linux/mtd/cfi.h b/include/linux/mtd/cfi.h
> index 9b57a9b..cbf7716 100644
> --- a/include/linux/mtd/cfi.h
> +++ b/include/linux/mtd/cfi.h
> @@ -377,6 +377,7 @@ struct cfi_fixup {
>  #define CFI_MFR_SHARP0x00B0
>  #define CFI_MFR_SST  0x00BF
>  #define CFI_MFR_ST   0x0020 /* STMicroelectronics */
> +#define CFI_MFR_MICRON   0x002C /* Micron */
>  #define CFI_MFR_TOSHIBA  0x0098
>  #define CFI_MFR_WINBOND  0x00DA
>  
> diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
> index c922e97..f43bfc5 100644
> --- a/include/linux/mtd/spi-nor.h
> +++ b/include/linux/mtd/spi-nor.h
> @@ -23,7 +23,8 @@
>  #define SNOR_MFR_ATMEL   CFI_MFR_ATMEL
>  #define SNOR_MFR_GIGADEVICE  0xc8
>  #define SNOR_MFR_INTEL   CFI_MFR_INTEL
> -#define SNOR_MFR_MICRON  CFI_MFR_ST /* ST Micro <--> Micron */
> +#define SNOR_MFR_ST  CFI_MFR_ST  /* ST Micro */
> +#define SNOR_MFR_MICRON  CFI_MFR_MICRON  /* Micron */
>  #define SNOR_MFR_MACRONIXCFI_MFR_MACRONIX
>  #define SNOR_MFR_SPANSIONCFI_MFR_AMD
>  #define SNOR_MFR_SST CFI_MFR_SST
> 


Re: [RESEND PATCH 1/2] mtd: spi-nor: add macros related to MICRON flash

2018-10-08 Thread Tudor Ambarus



On 09/19/2018 07:50 AM, Yogesh Gaur wrote:
> Some MICRON related macros in spi-nor domain were ST.
> Rename entries related to STMicroelectronics under macro SNOR_MFR_ST.
> 
> Added entry of MFR Id for Micron flashes, 0x002C.
> 
> Signed-off-by: Yogesh Gaur 

Reviewed-by: Tudor Ambarus 

> ---
>  drivers/mtd/spi-nor/spi-nor.c | 9 ++---
>  include/linux/mtd/cfi.h   | 1 +
>  include/linux/mtd/spi-nor.h   | 3 ++-
>  3 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index f028277..33a55bc 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -271,6 +271,7 @@ static inline int set_4byte(struct spi_nor *nor, const 
> struct flash_info *info,
>   u8 cmd;
>  
>   switch (JEDEC_MFR(info)) {
> + case SNOR_MFR_ST:
>   case SNOR_MFR_MICRON:
>   /* Some Micron need WREN command; all will accept it */
>   need_wren = true;
> @@ -1096,7 +1097,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, 
> loff_t ofs, uint64_t len)
>   { "mx66l1g45g",  INFO(0xc2201b, 0, 64 * 1024, 2048, SECT_4K | 
> SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
>   { "mx66l1g55g",  INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) 
> },
>  
> - /* Micron */
> + /* Micron <--> ST Micro */
>   { "n25q016a",INFO(0x20bb15, 0, 64 * 1024,   32, SECT_4K | 
> SPI_NOR_QUAD_READ) },
>   { "n25q032", INFO(0x20ba16, 0, 64 * 1024,   64, SPI_NOR_QUAD_READ) 
> },
>   { "n25q032a",INFO(0x20bb16, 0, 64 * 1024,   64, SPI_NOR_QUAD_READ) 
> },
> @@ -2502,6 +2503,7 @@ static int spi_nor_init_params(struct spi_nor *nor,
>   params->quad_enable = macronix_quad_enable;
>   break;
>  
> + case SNOR_MFR_ST:
>   case SNOR_MFR_MICRON:
>   break;
>  
> @@ -2876,8 +2878,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>   mtd->_resume = spi_nor_resume;
>  
>   /* NOR protection support for STmicro/Micron chips and similar */
> - if (JEDEC_MFR(info) == SNOR_MFR_MICRON ||
> - info->flags & SPI_NOR_HAS_LOCK) {
> + if (JEDEC_MFR(info) == SNOR_MFR_ST ||
> + JEDEC_MFR(info) == SNOR_MFR_MICRON ||
> + info->flags & SPI_NOR_HAS_LOCK) {
>   nor->flash_lock = stm_lock;
>   nor->flash_unlock = stm_unlock;
>   nor->flash_is_locked = stm_is_locked;
> diff --git a/include/linux/mtd/cfi.h b/include/linux/mtd/cfi.h
> index 9b57a9b..cbf7716 100644
> --- a/include/linux/mtd/cfi.h
> +++ b/include/linux/mtd/cfi.h
> @@ -377,6 +377,7 @@ struct cfi_fixup {
>  #define CFI_MFR_SHARP0x00B0
>  #define CFI_MFR_SST  0x00BF
>  #define CFI_MFR_ST   0x0020 /* STMicroelectronics */
> +#define CFI_MFR_MICRON   0x002C /* Micron */
>  #define CFI_MFR_TOSHIBA  0x0098
>  #define CFI_MFR_WINBOND  0x00DA
>  
> diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
> index c922e97..f43bfc5 100644
> --- a/include/linux/mtd/spi-nor.h
> +++ b/include/linux/mtd/spi-nor.h
> @@ -23,7 +23,8 @@
>  #define SNOR_MFR_ATMEL   CFI_MFR_ATMEL
>  #define SNOR_MFR_GIGADEVICE  0xc8
>  #define SNOR_MFR_INTEL   CFI_MFR_INTEL
> -#define SNOR_MFR_MICRON  CFI_MFR_ST /* ST Micro <--> Micron */
> +#define SNOR_MFR_ST  CFI_MFR_ST  /* ST Micro */
> +#define SNOR_MFR_MICRON  CFI_MFR_MICRON  /* Micron */
>  #define SNOR_MFR_MACRONIXCFI_MFR_MACRONIX
>  #define SNOR_MFR_SPANSIONCFI_MFR_AMD
>  #define SNOR_MFR_SST CFI_MFR_SST
> 


[PATCH] mm/thp: Correctly differentiate between mapped THP and PMD migration entry

2018-10-08 Thread Anshuman Khandual
A normal mapped THP page at PMD level should be correctly differentiated
from a PMD migration entry while walking the page table. A mapped THP would
additionally check positive for pmd_present() along with pmd_trans_huge()
as compared to a PMD migration entry. This just adds a new conditional test
differentiating the two while walking the page table.

Fixes: 616b8371539a6 ("mm: thp: enable thp migration in generic path")
Signed-off-by: Anshuman Khandual 
---
On X86, pmd_trans_huge() and is_pmd_migration_entry() are always mutually
exclusive which makes the current conditional block work for both mapped
and migration entries. This is not same with arm64 where pmd_trans_huge()
returns positive for both mapped and migration entries. Could some one
please explain why pmd_trans_huge() has to return false for migration
entries which just install swap bits and its still a PMD ? Nonetheless
pmd_present() seems to be a better check to distinguish between mapped
and (non-mapped non-present) migration entries without any ambiguity.

 mm/page_vma_mapped.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
index ae3c2a3..b384396 100644
--- a/mm/page_vma_mapped.c
+++ b/mm/page_vma_mapped.c
@@ -161,7 +161,8 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
pmde = READ_ONCE(*pvmw->pmd);
if (pmd_trans_huge(pmde) || is_pmd_migration_entry(pmde)) {
pvmw->ptl = pmd_lock(mm, pvmw->pmd);
-   if (likely(pmd_trans_huge(*pvmw->pmd))) {
+   if (likely(pmd_trans_huge(*pvmw->pmd) &&
+   pmd_present(*pvmw->pmd))) {
if (pvmw->flags & PVMW_MIGRATION)
return not_found(pvmw);
if (pmd_page(*pvmw->pmd) != page)
-- 
2.7.4



[RFC PATCH 1/2] net/ncsi: Don't enable all channels when HWA available

2018-10-08 Thread Samuel Mendoza-Jonas
NCSI hardware arbitration allows multiple packages to be enabled at once
and share the same wiring. If the NCSI driver recognises that HWA is
available it unconditionally enables all packages and channels; but that
is a configuration decision rather than something required by HWA.
Additionally the current implementation will not failover on link events
which can cause connectivity to be lost unless the interface is manually
bounced.

Retain basic HWA support but remove the separate configuration path to
enable all channels, leaving this to be handled by a later
implementation.

Signed-off-by: Samuel Mendoza-Jonas 
---
 net/ncsi/ncsi-aen.c|  3 +--
 net/ncsi/ncsi-manage.c | 51 +++---
 2 files changed, 9 insertions(+), 45 deletions(-)

diff --git a/net/ncsi/ncsi-aen.c b/net/ncsi/ncsi-aen.c
index 25e483e8278b..65f47a648be3 100644
--- a/net/ncsi/ncsi-aen.c
+++ b/net/ncsi/ncsi-aen.c
@@ -86,8 +86,7 @@ static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
!(state == NCSI_CHANNEL_ACTIVE && !(data & 0x1)))
return 0;
 
-   if (!(ndp->flags & NCSI_DEV_HWA) &&
-   state == NCSI_CHANNEL_ACTIVE)
+   if (state == NCSI_CHANNEL_ACTIVE)
ndp->flags |= NCSI_DEV_RESHUFFLE;
 
ncsi_stop_channel_monitor(nc);
diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index 091284760d21..665bee25ec44 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -112,10 +112,8 @@ static void ncsi_channel_monitor(struct timer_list *t)
default:
netdev_err(ndp->ndev.dev, "NCSI Channel %d timed out!\n",
   nc->id);
-   if (!(ndp->flags & NCSI_DEV_HWA)) {
-   ncsi_report_link(ndp, true);
-   ndp->flags |= NCSI_DEV_RESHUFFLE;
-   }
+   ncsi_report_link(ndp, true);
+   ndp->flags |= NCSI_DEV_RESHUFFLE;
 
ncsi_stop_channel_monitor(nc);
 
@@ -952,35 +950,6 @@ static bool ncsi_check_hwa(struct ncsi_dev_priv *ndp)
return false;
 }
 
-static int ncsi_enable_hwa(struct ncsi_dev_priv *ndp)
-{
-   struct ncsi_package *np;
-   struct ncsi_channel *nc;
-   unsigned long flags;
-
-   /* Move all available channels to processing queue */
-   spin_lock_irqsave(>lock, flags);
-   NCSI_FOR_EACH_PACKAGE(ndp, np) {
-   NCSI_FOR_EACH_CHANNEL(np, nc) {
-   WARN_ON_ONCE(nc->state != NCSI_CHANNEL_INACTIVE ||
-!list_empty(>link));
-   ncsi_stop_channel_monitor(nc);
-   list_add_tail_rcu(>link, >channel_queue);
-   }
-   }
-   spin_unlock_irqrestore(>lock, flags);
-
-   /* We can have no channels in extremely case */
-   if (list_empty(>channel_queue)) {
-   netdev_err(ndp->ndev.dev,
-  "NCSI: No available channels for HWA\n");
-   ncsi_report_link(ndp, false);
-   return -ENOENT;
-   }
-
-   return ncsi_process_next_channel(ndp);
-}
-
 static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
 {
struct ncsi_dev *nd = >ndev;
@@ -1047,6 +1016,10 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
ndp->active_package = list_next_entry(
ndp->active_package, node);
 
+   /* Check for HWA support */
+   if (ncsi_check_hwa(ndp))
+   netdev_info(ndp->ndev.dev, "NCSI: HWA available\n");
+
/* All available packages and channels are enumerated. The
 * enumeration happens for once when the NCSI interface is
 * started. So we need continue to start the interface after
@@ -1058,10 +1031,7 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
 */
if (!ndp->active_package) {
ndp->flags |= NCSI_DEV_PROBED;
-   if (ncsi_check_hwa(ndp))
-   ncsi_enable_hwa(ndp);
-   else
-   ncsi_choose_active_channel(ndp);
+   ncsi_choose_active_channel(ndp);
return;
}
 
@@ -1506,12 +1476,7 @@ int ncsi_start_dev(struct ncsi_dev *nd)
return 0;
}
 
-   if (ndp->flags & NCSI_DEV_HWA) {
-   netdev_info(ndp->ndev.dev, "NCSI: Enabling HWA mode\n");
-   ret = ncsi_enable_hwa(ndp);
-   } else {
-   ret = ncsi_choose_active_channel(ndp);
-   }
+   ret = ncsi_choose_active_channel(ndp);
 
return ret;
 }
-- 
2.19.0



[RFC PATCH 2/2] net/ncsi: Configure multi-package, multi-channel modes with failover

2018-10-08 Thread Samuel Mendoza-Jonas
This patch extends the ncsi-netlink interface with two new commands and
three new attributes to configure multiple packages and/or channels at
once, and configure specific failover modes.

NCSI_CMD_SET_PACKAGE mask and NCSI_CMD_SET_CHANNEL_MASK set a whitelist
of packages or channels allowed to be configured with the
NCSI_ATTR_PACKAGE_MASK and NCSI_ATTR_CHANNEL_MASK attributes
respectively. If one of these whitelists is set only packages or
channels matching the whitelist are considered for the channel queue in
ncsi_choose_active_channel().

These commands may also use the NCSI_ATTR_MULTI_FLAG to signal that
multiple packages or channels may be configured simultaneously. NCSI
hardware arbitration (HWA) must be available in order to enable
multi-package mode. Multi-channel mode is always available.

If the NCSI_ATTR_CHANNEL_ID attribute is present in the
NCSI_CMD_SET_CHANNEL_MASK command the it sets the preferred channel as
with the NCSI_CMD_SET_INTERFACE command. The combination of preferred
channel and channel whitelist defines a primary channel and the allowed
failover channels.
If the NCSI_ATTR_MULTI_FLAG attribute is also present then the preferred
channel is configured for Tx/Rx and the other channels are enabled only
for Rx.

Signed-off-by: Samuel Mendoza-Jonas 
---
 include/uapi/linux/ncsi.h |  16 +++
 net/ncsi/internal.h   |  11 +-
 net/ncsi/ncsi-aen.c   |   2 +-
 net/ncsi/ncsi-manage.c| 138 
 net/ncsi/ncsi-netlink.c   | 217 +-
 net/ncsi/ncsi-rsp.c   |   2 +-
 6 files changed, 312 insertions(+), 74 deletions(-)

diff --git a/include/uapi/linux/ncsi.h b/include/uapi/linux/ncsi.h
index 4c292ecbb748..035fba1693f9 100644
--- a/include/uapi/linux/ncsi.h
+++ b/include/uapi/linux/ncsi.h
@@ -23,6 +23,13 @@
  * optionally the preferred NCSI_ATTR_CHANNEL_ID.
  * @NCSI_CMD_CLEAR_INTERFACE: clear any preferred package/channel combination.
  * Requires NCSI_ATTR_IFINDEX.
+ * @NCSI_CMD_SET_PACKAGE_MASK: set a whitelist of allowed packages.
+ * @NCSI_CMD_SET_PACKAGE_MASK: set a whitelist of allowed channels.
+ * Requires NCSI_ATTR_IFINDEX and NCSI_ATTR_PACKAGE_MASK.
+ * @NCSI_CMD_SET_PACKAGE_MASK: set a whitelist of allowed channels.
+ * Requires NCSI_ATTR_IFINDEX, NCSI_ATTR_PACKAGE_ID, and
+ * NCSI_ATTR_CHANNEL_MASK. If NCSI_ATTR_CHANNEL_ID is present it sets
+ * the primary channel.
  * @NCSI_CMD_MAX: highest command number
  */
 enum ncsi_nl_commands {
@@ -30,6 +37,8 @@ enum ncsi_nl_commands {
NCSI_CMD_PKG_INFO,
NCSI_CMD_SET_INTERFACE,
NCSI_CMD_CLEAR_INTERFACE,
+   NCSI_CMD_SET_PACKAGE_MASK,
+   NCSI_CMD_SET_CHANNEL_MASK,
 
__NCSI_CMD_AFTER_LAST,
NCSI_CMD_MAX = __NCSI_CMD_AFTER_LAST - 1
@@ -43,6 +52,10 @@ enum ncsi_nl_commands {
  * @NCSI_ATTR_PACKAGE_LIST: nested array of NCSI_PKG_ATTR attributes
  * @NCSI_ATTR_PACKAGE_ID: package ID
  * @NCSI_ATTR_CHANNEL_ID: channel ID
+ * @NCSI_ATTR_MULTI_FLAG: flag to signal that multi-mode should be enabled with
+ * NCSI_CMD_SET_PACKAGE_MASK or NCSI_CMD_SET_CHANNEL_MASK.
+ * @NCSI_ATTR_PACKAGE_MASK: 32-bit mask of allowed packages.
+ * @NCSI_ATTR_CHANNEL_MASK: 32-bit mask of allowed channels.
  * @NCSI_ATTR_MAX: highest attribute number
  */
 enum ncsi_nl_attrs {
@@ -51,6 +64,9 @@ enum ncsi_nl_attrs {
NCSI_ATTR_PACKAGE_LIST,
NCSI_ATTR_PACKAGE_ID,
NCSI_ATTR_CHANNEL_ID,
+   NCSI_ATTR_MULTI_FLAG,
+   NCSI_ATTR_PACKAGE_MASK,
+   NCSI_ATTR_CHANNEL_MASK,
 
__NCSI_ATTR_AFTER_LAST,
NCSI_ATTR_MAX = __NCSI_ATTR_AFTER_LAST - 1
diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
index 3d0a33b874f5..8437474d0a78 100644
--- a/net/ncsi/internal.h
+++ b/net/ncsi/internal.h
@@ -213,6 +213,10 @@ struct ncsi_package {
unsigned int channel_num; /* Number of channels */
struct list_head channels;/* List of chanels*/
struct list_head node;/* Form list of packages  */
+
+   bool multi_channel; /* Enable multiple channels  */
+   u32  channel_whitelist; /* Channels to configure */
+   struct ncsi_channel  *preferred_channel; /* Primary channel  */
 };
 
 struct ncsi_request {
@@ -280,8 +284,6 @@ struct ncsi_dev_priv {
unsigned intpackage_num; /* Number of packages */
struct list_headpackages;/* List of packages   */
struct ncsi_channel *hot_channel;/* Channel was ever active*/
-   struct ncsi_package *force_package;  /* Force a specific package   */
-   struct ncsi_channel *force_channel;  /* Force a specific channel   */
struct ncsi_request requests[256];   /* Request table  */
unsigned intrequest_id;  /* Last used request ID   */
 #define NCSI_REQ_START_IDX 1
@@ -294,6 +296,9 @@ struct ncsi_dev_priv {
struct list_headnode;/* Form 

[PATCH] mm/thp: Correctly differentiate between mapped THP and PMD migration entry

2018-10-08 Thread Anshuman Khandual
A normal mapped THP page at PMD level should be correctly differentiated
from a PMD migration entry while walking the page table. A mapped THP would
additionally check positive for pmd_present() along with pmd_trans_huge()
as compared to a PMD migration entry. This just adds a new conditional test
differentiating the two while walking the page table.

Fixes: 616b8371539a6 ("mm: thp: enable thp migration in generic path")
Signed-off-by: Anshuman Khandual 
---
On X86, pmd_trans_huge() and is_pmd_migration_entry() are always mutually
exclusive which makes the current conditional block work for both mapped
and migration entries. This is not same with arm64 where pmd_trans_huge()
returns positive for both mapped and migration entries. Could some one
please explain why pmd_trans_huge() has to return false for migration
entries which just install swap bits and its still a PMD ? Nonetheless
pmd_present() seems to be a better check to distinguish between mapped
and (non-mapped non-present) migration entries without any ambiguity.

 mm/page_vma_mapped.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
index ae3c2a3..b384396 100644
--- a/mm/page_vma_mapped.c
+++ b/mm/page_vma_mapped.c
@@ -161,7 +161,8 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
pmde = READ_ONCE(*pvmw->pmd);
if (pmd_trans_huge(pmde) || is_pmd_migration_entry(pmde)) {
pvmw->ptl = pmd_lock(mm, pvmw->pmd);
-   if (likely(pmd_trans_huge(*pvmw->pmd))) {
+   if (likely(pmd_trans_huge(*pvmw->pmd) &&
+   pmd_present(*pvmw->pmd))) {
if (pvmw->flags & PVMW_MIGRATION)
return not_found(pvmw);
if (pmd_page(*pvmw->pmd) != page)
-- 
2.7.4



[RFC PATCH 1/2] net/ncsi: Don't enable all channels when HWA available

2018-10-08 Thread Samuel Mendoza-Jonas
NCSI hardware arbitration allows multiple packages to be enabled at once
and share the same wiring. If the NCSI driver recognises that HWA is
available it unconditionally enables all packages and channels; but that
is a configuration decision rather than something required by HWA.
Additionally the current implementation will not failover on link events
which can cause connectivity to be lost unless the interface is manually
bounced.

Retain basic HWA support but remove the separate configuration path to
enable all channels, leaving this to be handled by a later
implementation.

Signed-off-by: Samuel Mendoza-Jonas 
---
 net/ncsi/ncsi-aen.c|  3 +--
 net/ncsi/ncsi-manage.c | 51 +++---
 2 files changed, 9 insertions(+), 45 deletions(-)

diff --git a/net/ncsi/ncsi-aen.c b/net/ncsi/ncsi-aen.c
index 25e483e8278b..65f47a648be3 100644
--- a/net/ncsi/ncsi-aen.c
+++ b/net/ncsi/ncsi-aen.c
@@ -86,8 +86,7 @@ static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
!(state == NCSI_CHANNEL_ACTIVE && !(data & 0x1)))
return 0;
 
-   if (!(ndp->flags & NCSI_DEV_HWA) &&
-   state == NCSI_CHANNEL_ACTIVE)
+   if (state == NCSI_CHANNEL_ACTIVE)
ndp->flags |= NCSI_DEV_RESHUFFLE;
 
ncsi_stop_channel_monitor(nc);
diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index 091284760d21..665bee25ec44 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -112,10 +112,8 @@ static void ncsi_channel_monitor(struct timer_list *t)
default:
netdev_err(ndp->ndev.dev, "NCSI Channel %d timed out!\n",
   nc->id);
-   if (!(ndp->flags & NCSI_DEV_HWA)) {
-   ncsi_report_link(ndp, true);
-   ndp->flags |= NCSI_DEV_RESHUFFLE;
-   }
+   ncsi_report_link(ndp, true);
+   ndp->flags |= NCSI_DEV_RESHUFFLE;
 
ncsi_stop_channel_monitor(nc);
 
@@ -952,35 +950,6 @@ static bool ncsi_check_hwa(struct ncsi_dev_priv *ndp)
return false;
 }
 
-static int ncsi_enable_hwa(struct ncsi_dev_priv *ndp)
-{
-   struct ncsi_package *np;
-   struct ncsi_channel *nc;
-   unsigned long flags;
-
-   /* Move all available channels to processing queue */
-   spin_lock_irqsave(>lock, flags);
-   NCSI_FOR_EACH_PACKAGE(ndp, np) {
-   NCSI_FOR_EACH_CHANNEL(np, nc) {
-   WARN_ON_ONCE(nc->state != NCSI_CHANNEL_INACTIVE ||
-!list_empty(>link));
-   ncsi_stop_channel_monitor(nc);
-   list_add_tail_rcu(>link, >channel_queue);
-   }
-   }
-   spin_unlock_irqrestore(>lock, flags);
-
-   /* We can have no channels in extremely case */
-   if (list_empty(>channel_queue)) {
-   netdev_err(ndp->ndev.dev,
-  "NCSI: No available channels for HWA\n");
-   ncsi_report_link(ndp, false);
-   return -ENOENT;
-   }
-
-   return ncsi_process_next_channel(ndp);
-}
-
 static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
 {
struct ncsi_dev *nd = >ndev;
@@ -1047,6 +1016,10 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
ndp->active_package = list_next_entry(
ndp->active_package, node);
 
+   /* Check for HWA support */
+   if (ncsi_check_hwa(ndp))
+   netdev_info(ndp->ndev.dev, "NCSI: HWA available\n");
+
/* All available packages and channels are enumerated. The
 * enumeration happens for once when the NCSI interface is
 * started. So we need continue to start the interface after
@@ -1058,10 +1031,7 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
 */
if (!ndp->active_package) {
ndp->flags |= NCSI_DEV_PROBED;
-   if (ncsi_check_hwa(ndp))
-   ncsi_enable_hwa(ndp);
-   else
-   ncsi_choose_active_channel(ndp);
+   ncsi_choose_active_channel(ndp);
return;
}
 
@@ -1506,12 +1476,7 @@ int ncsi_start_dev(struct ncsi_dev *nd)
return 0;
}
 
-   if (ndp->flags & NCSI_DEV_HWA) {
-   netdev_info(ndp->ndev.dev, "NCSI: Enabling HWA mode\n");
-   ret = ncsi_enable_hwa(ndp);
-   } else {
-   ret = ncsi_choose_active_channel(ndp);
-   }
+   ret = ncsi_choose_active_channel(ndp);
 
return ret;
 }
-- 
2.19.0



[RFC PATCH 2/2] net/ncsi: Configure multi-package, multi-channel modes with failover

2018-10-08 Thread Samuel Mendoza-Jonas
This patch extends the ncsi-netlink interface with two new commands and
three new attributes to configure multiple packages and/or channels at
once, and configure specific failover modes.

NCSI_CMD_SET_PACKAGE mask and NCSI_CMD_SET_CHANNEL_MASK set a whitelist
of packages or channels allowed to be configured with the
NCSI_ATTR_PACKAGE_MASK and NCSI_ATTR_CHANNEL_MASK attributes
respectively. If one of these whitelists is set only packages or
channels matching the whitelist are considered for the channel queue in
ncsi_choose_active_channel().

These commands may also use the NCSI_ATTR_MULTI_FLAG to signal that
multiple packages or channels may be configured simultaneously. NCSI
hardware arbitration (HWA) must be available in order to enable
multi-package mode. Multi-channel mode is always available.

If the NCSI_ATTR_CHANNEL_ID attribute is present in the
NCSI_CMD_SET_CHANNEL_MASK command the it sets the preferred channel as
with the NCSI_CMD_SET_INTERFACE command. The combination of preferred
channel and channel whitelist defines a primary channel and the allowed
failover channels.
If the NCSI_ATTR_MULTI_FLAG attribute is also present then the preferred
channel is configured for Tx/Rx and the other channels are enabled only
for Rx.

Signed-off-by: Samuel Mendoza-Jonas 
---
 include/uapi/linux/ncsi.h |  16 +++
 net/ncsi/internal.h   |  11 +-
 net/ncsi/ncsi-aen.c   |   2 +-
 net/ncsi/ncsi-manage.c| 138 
 net/ncsi/ncsi-netlink.c   | 217 +-
 net/ncsi/ncsi-rsp.c   |   2 +-
 6 files changed, 312 insertions(+), 74 deletions(-)

diff --git a/include/uapi/linux/ncsi.h b/include/uapi/linux/ncsi.h
index 4c292ecbb748..035fba1693f9 100644
--- a/include/uapi/linux/ncsi.h
+++ b/include/uapi/linux/ncsi.h
@@ -23,6 +23,13 @@
  * optionally the preferred NCSI_ATTR_CHANNEL_ID.
  * @NCSI_CMD_CLEAR_INTERFACE: clear any preferred package/channel combination.
  * Requires NCSI_ATTR_IFINDEX.
+ * @NCSI_CMD_SET_PACKAGE_MASK: set a whitelist of allowed packages.
+ * @NCSI_CMD_SET_PACKAGE_MASK: set a whitelist of allowed channels.
+ * Requires NCSI_ATTR_IFINDEX and NCSI_ATTR_PACKAGE_MASK.
+ * @NCSI_CMD_SET_PACKAGE_MASK: set a whitelist of allowed channels.
+ * Requires NCSI_ATTR_IFINDEX, NCSI_ATTR_PACKAGE_ID, and
+ * NCSI_ATTR_CHANNEL_MASK. If NCSI_ATTR_CHANNEL_ID is present it sets
+ * the primary channel.
  * @NCSI_CMD_MAX: highest command number
  */
 enum ncsi_nl_commands {
@@ -30,6 +37,8 @@ enum ncsi_nl_commands {
NCSI_CMD_PKG_INFO,
NCSI_CMD_SET_INTERFACE,
NCSI_CMD_CLEAR_INTERFACE,
+   NCSI_CMD_SET_PACKAGE_MASK,
+   NCSI_CMD_SET_CHANNEL_MASK,
 
__NCSI_CMD_AFTER_LAST,
NCSI_CMD_MAX = __NCSI_CMD_AFTER_LAST - 1
@@ -43,6 +52,10 @@ enum ncsi_nl_commands {
  * @NCSI_ATTR_PACKAGE_LIST: nested array of NCSI_PKG_ATTR attributes
  * @NCSI_ATTR_PACKAGE_ID: package ID
  * @NCSI_ATTR_CHANNEL_ID: channel ID
+ * @NCSI_ATTR_MULTI_FLAG: flag to signal that multi-mode should be enabled with
+ * NCSI_CMD_SET_PACKAGE_MASK or NCSI_CMD_SET_CHANNEL_MASK.
+ * @NCSI_ATTR_PACKAGE_MASK: 32-bit mask of allowed packages.
+ * @NCSI_ATTR_CHANNEL_MASK: 32-bit mask of allowed channels.
  * @NCSI_ATTR_MAX: highest attribute number
  */
 enum ncsi_nl_attrs {
@@ -51,6 +64,9 @@ enum ncsi_nl_attrs {
NCSI_ATTR_PACKAGE_LIST,
NCSI_ATTR_PACKAGE_ID,
NCSI_ATTR_CHANNEL_ID,
+   NCSI_ATTR_MULTI_FLAG,
+   NCSI_ATTR_PACKAGE_MASK,
+   NCSI_ATTR_CHANNEL_MASK,
 
__NCSI_ATTR_AFTER_LAST,
NCSI_ATTR_MAX = __NCSI_ATTR_AFTER_LAST - 1
diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
index 3d0a33b874f5..8437474d0a78 100644
--- a/net/ncsi/internal.h
+++ b/net/ncsi/internal.h
@@ -213,6 +213,10 @@ struct ncsi_package {
unsigned int channel_num; /* Number of channels */
struct list_head channels;/* List of chanels*/
struct list_head node;/* Form list of packages  */
+
+   bool multi_channel; /* Enable multiple channels  */
+   u32  channel_whitelist; /* Channels to configure */
+   struct ncsi_channel  *preferred_channel; /* Primary channel  */
 };
 
 struct ncsi_request {
@@ -280,8 +284,6 @@ struct ncsi_dev_priv {
unsigned intpackage_num; /* Number of packages */
struct list_headpackages;/* List of packages   */
struct ncsi_channel *hot_channel;/* Channel was ever active*/
-   struct ncsi_package *force_package;  /* Force a specific package   */
-   struct ncsi_channel *force_channel;  /* Force a specific channel   */
struct ncsi_request requests[256];   /* Request table  */
unsigned intrequest_id;  /* Last used request ID   */
 #define NCSI_REQ_START_IDX 1
@@ -294,6 +296,9 @@ struct ncsi_dev_priv {
struct list_headnode;/* Form 

Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function"

2018-10-08 Thread Steven Rostedt
On Mon, 8 Oct 2018 21:17:10 -0500
Josh Poimboeuf  wrote:

> I'm not really convinced we need objtool for this, maybe I'll try
> whipping up a POC.

Awesome!

I wasn't thinking of actually having objtool itself perform this task,
but instead breaking the internals of objtool up into more of a generic
infrastructure, that recordmcount.c, objtool, and whatever this does
can use.

-- Steve


Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function"

2018-10-08 Thread Steven Rostedt
On Mon, 8 Oct 2018 21:17:10 -0500
Josh Poimboeuf  wrote:

> I'm not really convinced we need objtool for this, maybe I'll try
> whipping up a POC.

Awesome!

I wasn't thinking of actually having objtool itself perform this task,
but instead breaking the internals of objtool up into more of a generic
infrastructure, that recordmcount.c, objtool, and whatever this does
can use.

-- Steve


Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function"

2018-10-08 Thread Steven Rostedt
On Tue, 9 Oct 2018 12:44:01 +0900
Masami Hiramatsu  wrote:

> On Fri, 05 Oct 2018 21:51:11 -0400
> Steven Rostedt  wrote:
> 
> > +typedef long dynfunc_t;
> > +
> > +struct dynfunc_struct;
> > +
> > +#define arch_dynfunc_trampoline(name, def) \
> > +   asm volatile (  \
> > +   ".globl dynfunc_" #name "; \n\t"\
> > +   "dynfunc_" #name ": \n\t"   \
> > +   "jmp " #def " \n\t" \
> > +   ".balign 8 \n \t"   \
> > +   : : : "memory" )
> > +  
> 
> I have just a question, what is this different from livepatch? :)

I actually thought about this a bit, but decided against it.

I didn't want to hook another infrastructure into the fentry nop. It's
already complex enough with kprobes, live patching and ftrace.

The ideal solution is what Peter suggested, and that's to patch the
call sites, and I think that is attainable with objtool modifications.

> 
> I think we can replace the first 5 bytes of the default function
> to jmp instruction (to alternative function) instead of making
> this trampoline.
> 
> IOW, as far as I can see, this is changing
> 
> 
> call %reg (or retpoline_reg)
> 
> 
> to 
> 
> 
> call dynfunc_A
> 
> dynfunc_A:
> jmp func_A or altered_func_A
> 
> 
> If so, why don't we put the jmp on default func_A directly?
> 
> call func_A
> 
> func_A:
> "jmp altered_func" or "original sequence"
> 
> (this is idealy same as jprobes did)
> 
> Of course we have to arbitrate it with ftrace (fentry) but it may
> not so hard (simplest way is just adding "notrace" on the default
> function)

Then we lose the 5 byte nop.

> 
> BTW, I think "dynamic_function" may not correct name, it may be
> "alternative_function" or something like that, because this
> function must be replaced system-wide and this means we can
> not use this for generic function pointer usage which depends
> on thread context (like file_operations). But good for something
> pluggable code (LSM?).

I don't like the name alternative, as that's usually a one shot deal
(SMP vs UP).

It is dynamic, as it's a function that changes dynamically. Yes its
global, but that's not mutually exclusive to dynamic.

The use case I want this for is for tracing. But it can be useful for
KVM and power management governors. Basically anything that has a
global function pointer (hmm, even the idle call can use this).

-- Steve


Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function"

2018-10-08 Thread Steven Rostedt
On Tue, 9 Oct 2018 12:44:01 +0900
Masami Hiramatsu  wrote:

> On Fri, 05 Oct 2018 21:51:11 -0400
> Steven Rostedt  wrote:
> 
> > +typedef long dynfunc_t;
> > +
> > +struct dynfunc_struct;
> > +
> > +#define arch_dynfunc_trampoline(name, def) \
> > +   asm volatile (  \
> > +   ".globl dynfunc_" #name "; \n\t"\
> > +   "dynfunc_" #name ": \n\t"   \
> > +   "jmp " #def " \n\t" \
> > +   ".balign 8 \n \t"   \
> > +   : : : "memory" )
> > +  
> 
> I have just a question, what is this different from livepatch? :)

I actually thought about this a bit, but decided against it.

I didn't want to hook another infrastructure into the fentry nop. It's
already complex enough with kprobes, live patching and ftrace.

The ideal solution is what Peter suggested, and that's to patch the
call sites, and I think that is attainable with objtool modifications.

> 
> I think we can replace the first 5 bytes of the default function
> to jmp instruction (to alternative function) instead of making
> this trampoline.
> 
> IOW, as far as I can see, this is changing
> 
> 
> call %reg (or retpoline_reg)
> 
> 
> to 
> 
> 
> call dynfunc_A
> 
> dynfunc_A:
> jmp func_A or altered_func_A
> 
> 
> If so, why don't we put the jmp on default func_A directly?
> 
> call func_A
> 
> func_A:
> "jmp altered_func" or "original sequence"
> 
> (this is idealy same as jprobes did)
> 
> Of course we have to arbitrate it with ftrace (fentry) but it may
> not so hard (simplest way is just adding "notrace" on the default
> function)

Then we lose the 5 byte nop.

> 
> BTW, I think "dynamic_function" may not correct name, it may be
> "alternative_function" or something like that, because this
> function must be replaced system-wide and this means we can
> not use this for generic function pointer usage which depends
> on thread context (like file_operations). But good for something
> pluggable code (LSM?).

I don't like the name alternative, as that's usually a one shot deal
(SMP vs UP).

It is dynamic, as it's a function that changes dynamically. Yes its
global, but that's not mutually exclusive to dynamic.

The use case I want this for is for tracing. But it can be useful for
KVM and power management governors. Basically anything that has a
global function pointer (hmm, even the idle call can use this).

-- Steve


Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function"

2018-10-08 Thread Masami Hiramatsu
On Fri, 05 Oct 2018 21:51:11 -0400
Steven Rostedt  wrote:

> +typedef long dynfunc_t;
> +
> +struct dynfunc_struct;
> +
> +#define arch_dynfunc_trampoline(name, def)   \
> + asm volatile (  \
> + ".globl dynfunc_" #name "; \n\t"\
> + "dynfunc_" #name ": \n\t"   \
> + "jmp " #def " \n\t" \
> + ".balign 8 \n \t"   \
> + : : : "memory" )
> +

I have just a question, what is this different from livepatch? :)

I think we can replace the first 5 bytes of the default function
to jmp instruction (to alternative function) instead of making
this trampoline.

IOW, as far as I can see, this is changing


call %reg (or retpoline_reg)


to 


call dynfunc_A

dynfunc_A:
jmp func_A or altered_func_A


If so, why don't we put the jmp on default func_A directly?

call func_A

func_A:
"jmp altered_func" or "original sequence"

(this is idealy same as jprobes did)

Of course we have to arbitrate it with ftrace (fentry) but it may
not so hard (simplest way is just adding "notrace" on the default
function)

BTW, I think "dynamic_function" may not correct name, it may be
"alternative_function" or something like that, because this
function must be replaced system-wide and this means we can
not use this for generic function pointer usage which depends
on thread context (like file_operations). But good for something
pluggable code (LSM?).


Thank you,


-- 
Masami Hiramatsu 


Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function"

2018-10-08 Thread Masami Hiramatsu
On Fri, 05 Oct 2018 21:51:11 -0400
Steven Rostedt  wrote:

> +typedef long dynfunc_t;
> +
> +struct dynfunc_struct;
> +
> +#define arch_dynfunc_trampoline(name, def)   \
> + asm volatile (  \
> + ".globl dynfunc_" #name "; \n\t"\
> + "dynfunc_" #name ": \n\t"   \
> + "jmp " #def " \n\t" \
> + ".balign 8 \n \t"   \
> + : : : "memory" )
> +

I have just a question, what is this different from livepatch? :)

I think we can replace the first 5 bytes of the default function
to jmp instruction (to alternative function) instead of making
this trampoline.

IOW, as far as I can see, this is changing


call %reg (or retpoline_reg)


to 


call dynfunc_A

dynfunc_A:
jmp func_A or altered_func_A


If so, why don't we put the jmp on default func_A directly?

call func_A

func_A:
"jmp altered_func" or "original sequence"

(this is idealy same as jprobes did)

Of course we have to arbitrate it with ftrace (fentry) but it may
not so hard (simplest way is just adding "notrace" on the default
function)

BTW, I think "dynamic_function" may not correct name, it may be
"alternative_function" or something like that, because this
function must be replaced system-wide and this means we can
not use this for generic function pointer usage which depends
on thread context (like file_operations). But good for something
pluggable code (LSM?).


Thank you,


-- 
Masami Hiramatsu 


Re: [LKP] [rcutorture] 5aa56a54ce: WARNING:at_kernel/rcu/rcutorture.c:#rcu_torture_fwd_prog

2018-10-08 Thread Paul E. McKenney
On Tue, Oct 09, 2018 at 09:52:05AM +0800, Rong Chen wrote:
> 
> 
> On 10/01/2018 07:00 AM, Paul E. McKenney wrote:
> >On Sun, Sep 30, 2018 at 11:16:14AM +0800, kernel test robot wrote:
> >>FYI, we noticed the following commit (built with gcc-7):
> >>
> >>commit: 5aa56a54ce92761e974f93592f69b75b8c2398a8 ("rcutorture: Add 
> >>call_rcu() flooding forward-progress tests")
> >>https://git.kernel.org/cgit/linux/kernel/git/paulmck/linux-rcu.git dev
> >>
> >>in testcase: trinity
> >>with following parameters:
> >>
> >>runtime: 300s
> >>
> >>test-description: Trinity is a linux system call fuzz tester.
> >>test-url: http://codemonkey.org.uk/projects/trinity/
> >>
> >>
> >>on test machine: qemu-system-x86_64 -enable-kvm -cpu Haswell,+smep,+smap 
> >>-smp 2 -m 512M
> >>
> >>caused below changes (please refer to attached dmesg/kmsg for entire 
> >>log/backtrace):
> >Ah, this is another complaint from my recent forward-progress additions
> >to rcutorture.  You can prevent rcutorture from doing this by adding
> >the rcutorture.fwd_progress=0 kernel boot parameter.
> Thanks, we will ignore the error.
> 
> >
> >But that aside, does it really make sense to run rcutorture and trinity
> >simultaneously?
> We use random kconfigs to test kernel, it's a coincidence to run
> them simultaneously.

I cannot argue with that!  Either way, the rcutorture.fwd_progress=0 kernel
boot parameter will prevent this error.

Thanx, Paul

> Best Regards,
> Rong Chen
> 
> >
> > Thanx, Paul
> >
> >>+--+++
> >>|  | 
> >>0b1aba265b | 5aa56a54ce |
> >>+--+++
> >>| boot_successes   | 0  
> >>| 0  |
> >>| boot_failures| 10 
> >>| 14 |
> >>| invoked_oom-killer:gfp_mask=0x   | 2  
> >>| 4  |
> >>| Mem-Info | 10 
> >>| 14 |
> >>| Kernel_panic-not_syncing:Out_of_memory_and_no_killable_processes | 2  
> >>| 4  |
> >>| INFO:trying_to_register_non-static_key   | 8  
> >>| 10 |
> >>| WARNING:at_mm/page_alloc.c:#__alloc_pages_slowpath   | 8  
> >>| 10 |
> >>| RIP:__alloc_pages_slowpath   | 8  
> >>| 10 |
> >>| IP-Config:Auto-configuration_of_network_failed   | 1  
> >>| 1  |
> >>| BUG:soft_lockup-CPU##stuck_for#s | 7  
> >>| 7  |
> >>| RIP:drm_mm_insert_node_in_range  | 2  
> >>| 1  |
> >>| Kernel_panic-not_syncing:softlockup:hung_tasks   | 7  
> >>| 7  |
> >>| RIP:rb_prev  | 3  
> >>| 1  |
> >>| RIP:separate_adjacent_colors | 1  
> >>| 4  |
> >>| RIP:__orc_find   | 1  
> >>||
> >>| WARNING:at_kernel/rcu/rcutorture.c:#rcu_torture_fwd_prog | 0  
> >>| 8  |
> >>| RIP:rcu_torture_fwd_prog | 0  
> >>| 8  |
> >>| RIP:add_hole | 0  
> >>| 1  |
> >>+--+++
> >>
> >>
> >>
> >>[  807.497867] WARNING: CPU: 0 PID: 74 at kernel/rcu/rcutorture.c:1840 
> >>rcu_torture_fwd_prog+0x7b6/0x967
> >>[  807.497867] CPU: 0 PID: 74 Comm: rcu_torture_fwd Tainted: GW 
> >>4.19.0-rc1-00150-g5aa56a5 #1
> >>[  807.497867] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
> >>1.10.2-1 04/01/2014
> >>[  807.497867] RIP: 0010:rcu_torture_fwd_prog+0x7b6/0x967
> >>[  807.497867] Code: e3 13 00 eb bb 48 c7 05 22 08 4f 02 a0 08 08 85 c6 05 
> >>db b2 eb 03 00 e8 44 bd 0a 00 84 c0 0f 85 1a 01 00 00 49 83 fe 63 7f 02 
> >><0f> 0b 48 8b 85 60 ff ff ff 4c 8b 85 58 ff ff ff 4c 03 85 50 ff ff
> >>[  807.497867] RSP: :88000dadfe00 EFLAGS: 00010287
> >>[  807.497867] RAX:  RBX: dc00 RCX: 
> >>88000a838488
> >>[  807.497867] RDX: 110002175401 RSI: 88000fc0c5c0 RDI: 
> >>88000f1789a0
> >>[  807.497867] RBP: 88000dadfef0 R08: 0006 R09: 
> >>88000d35dc28
> >>[  807.497867] R10: 828001bf R11: 0040 R12: 
> >>000100079309
> >>[  807.497867] R13: 0009 R14: 0003 R15: 

Re: [LKP] [rcutorture] 5aa56a54ce: WARNING:at_kernel/rcu/rcutorture.c:#rcu_torture_fwd_prog

2018-10-08 Thread Paul E. McKenney
On Tue, Oct 09, 2018 at 09:52:05AM +0800, Rong Chen wrote:
> 
> 
> On 10/01/2018 07:00 AM, Paul E. McKenney wrote:
> >On Sun, Sep 30, 2018 at 11:16:14AM +0800, kernel test robot wrote:
> >>FYI, we noticed the following commit (built with gcc-7):
> >>
> >>commit: 5aa56a54ce92761e974f93592f69b75b8c2398a8 ("rcutorture: Add 
> >>call_rcu() flooding forward-progress tests")
> >>https://git.kernel.org/cgit/linux/kernel/git/paulmck/linux-rcu.git dev
> >>
> >>in testcase: trinity
> >>with following parameters:
> >>
> >>runtime: 300s
> >>
> >>test-description: Trinity is a linux system call fuzz tester.
> >>test-url: http://codemonkey.org.uk/projects/trinity/
> >>
> >>
> >>on test machine: qemu-system-x86_64 -enable-kvm -cpu Haswell,+smep,+smap 
> >>-smp 2 -m 512M
> >>
> >>caused below changes (please refer to attached dmesg/kmsg for entire 
> >>log/backtrace):
> >Ah, this is another complaint from my recent forward-progress additions
> >to rcutorture.  You can prevent rcutorture from doing this by adding
> >the rcutorture.fwd_progress=0 kernel boot parameter.
> Thanks, we will ignore the error.
> 
> >
> >But that aside, does it really make sense to run rcutorture and trinity
> >simultaneously?
> We use random kconfigs to test kernel, it's a coincidence to run
> them simultaneously.

I cannot argue with that!  Either way, the rcutorture.fwd_progress=0 kernel
boot parameter will prevent this error.

Thanx, Paul

> Best Regards,
> Rong Chen
> 
> >
> > Thanx, Paul
> >
> >>+--+++
> >>|  | 
> >>0b1aba265b | 5aa56a54ce |
> >>+--+++
> >>| boot_successes   | 0  
> >>| 0  |
> >>| boot_failures| 10 
> >>| 14 |
> >>| invoked_oom-killer:gfp_mask=0x   | 2  
> >>| 4  |
> >>| Mem-Info | 10 
> >>| 14 |
> >>| Kernel_panic-not_syncing:Out_of_memory_and_no_killable_processes | 2  
> >>| 4  |
> >>| INFO:trying_to_register_non-static_key   | 8  
> >>| 10 |
> >>| WARNING:at_mm/page_alloc.c:#__alloc_pages_slowpath   | 8  
> >>| 10 |
> >>| RIP:__alloc_pages_slowpath   | 8  
> >>| 10 |
> >>| IP-Config:Auto-configuration_of_network_failed   | 1  
> >>| 1  |
> >>| BUG:soft_lockup-CPU##stuck_for#s | 7  
> >>| 7  |
> >>| RIP:drm_mm_insert_node_in_range  | 2  
> >>| 1  |
> >>| Kernel_panic-not_syncing:softlockup:hung_tasks   | 7  
> >>| 7  |
> >>| RIP:rb_prev  | 3  
> >>| 1  |
> >>| RIP:separate_adjacent_colors | 1  
> >>| 4  |
> >>| RIP:__orc_find   | 1  
> >>||
> >>| WARNING:at_kernel/rcu/rcutorture.c:#rcu_torture_fwd_prog | 0  
> >>| 8  |
> >>| RIP:rcu_torture_fwd_prog | 0  
> >>| 8  |
> >>| RIP:add_hole | 0  
> >>| 1  |
> >>+--+++
> >>
> >>
> >>
> >>[  807.497867] WARNING: CPU: 0 PID: 74 at kernel/rcu/rcutorture.c:1840 
> >>rcu_torture_fwd_prog+0x7b6/0x967
> >>[  807.497867] CPU: 0 PID: 74 Comm: rcu_torture_fwd Tainted: GW 
> >>4.19.0-rc1-00150-g5aa56a5 #1
> >>[  807.497867] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
> >>1.10.2-1 04/01/2014
> >>[  807.497867] RIP: 0010:rcu_torture_fwd_prog+0x7b6/0x967
> >>[  807.497867] Code: e3 13 00 eb bb 48 c7 05 22 08 4f 02 a0 08 08 85 c6 05 
> >>db b2 eb 03 00 e8 44 bd 0a 00 84 c0 0f 85 1a 01 00 00 49 83 fe 63 7f 02 
> >><0f> 0b 48 8b 85 60 ff ff ff 4c 8b 85 58 ff ff ff 4c 03 85 50 ff ff
> >>[  807.497867] RSP: :88000dadfe00 EFLAGS: 00010287
> >>[  807.497867] RAX:  RBX: dc00 RCX: 
> >>88000a838488
> >>[  807.497867] RDX: 110002175401 RSI: 88000fc0c5c0 RDI: 
> >>88000f1789a0
> >>[  807.497867] RBP: 88000dadfef0 R08: 0006 R09: 
> >>88000d35dc28
> >>[  807.497867] R10: 828001bf R11: 0040 R12: 
> >>000100079309
> >>[  807.497867] R13: 0009 R14: 0003 R15: 

linux-next: manual merge of the tip tree with the s290 tree

2018-10-08 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the tip tree got a conflict in:

  arch/s390/Kconfig

between commit:

  819eafaa7b58 ("s390/kasan: add initialization code and enable it")

from the s290 tree and commit:

  13ddb52c165b ("s390/jump_label: Switch to relative references")

from the tip tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc arch/s390/Kconfig
index a45583f731f0,12dc4c1af96c..
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@@ -126,7 -120,7 +126,8 @@@ config S39
select HAVE_ALIGNED_STRUCT_PAGE if SLUB
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_JUMP_LABEL
+   select HAVE_ARCH_JUMP_LABEL_RELATIVE
 +  select HAVE_ARCH_KASAN
select CPU_NO_EFFICIENT_FFS if !HAVE_MARCH_Z9_109_FEATURES
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_SOFT_DIRTY


pgplqwhgy867O.pgp
Description: OpenPGP digital signature


linux-next: manual merge of the tip tree with the s290 tree

2018-10-08 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the tip tree got a conflict in:

  arch/s390/Kconfig

between commit:

  819eafaa7b58 ("s390/kasan: add initialization code and enable it")

from the s290 tree and commit:

  13ddb52c165b ("s390/jump_label: Switch to relative references")

from the tip tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc arch/s390/Kconfig
index a45583f731f0,12dc4c1af96c..
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@@ -126,7 -120,7 +126,8 @@@ config S39
select HAVE_ALIGNED_STRUCT_PAGE if SLUB
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_JUMP_LABEL
+   select HAVE_ARCH_JUMP_LABEL_RELATIVE
 +  select HAVE_ARCH_KASAN
select CPU_NO_EFFICIENT_FFS if !HAVE_MARCH_Z9_109_FEATURES
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_SOFT_DIRTY


pgplqwhgy867O.pgp
Description: OpenPGP digital signature


Re: [PATCH 4.18 000/168] 4.18.13-stable review

2018-10-08 Thread Andre Tomt

On 08. okt. 2018 20:29, Greg Kroah-Hartman wrote:

This is the start of the stable review cycle for the 4.18.13 release.
There are 168 patches in this series, all will be posted as a response
to this one.  If anyone has any issues with these being applied, please
let me know.


  CC [M]  net/ipv4/netfilter/nf_conntrack_proto_icmp.o
net/ipv4/netfilter/nf_conntrack_proto_icmp.c:373:3: error: ‘const struct 
nf_conntrack_l4proto’ has no member named ‘ctnl_timeout’; did you mean 
‘get_timeouts’?

  .ctnl_timeout  = {
   ^~~~
   get_timeouts

The problematic patch is:> 
netfilter-conntrack-timeout-interface-depend-on-config_nf_conntrack_timeout.patch


The stuff the commit message talks about seems like it was added in 
4.19-rc1, so this should not go into stable.


Kernel builds fine with this one patch reverted.


Re: [PATCH 4.18 000/168] 4.18.13-stable review

2018-10-08 Thread Andre Tomt

On 08. okt. 2018 20:29, Greg Kroah-Hartman wrote:

This is the start of the stable review cycle for the 4.18.13 release.
There are 168 patches in this series, all will be posted as a response
to this one.  If anyone has any issues with these being applied, please
let me know.


  CC [M]  net/ipv4/netfilter/nf_conntrack_proto_icmp.o
net/ipv4/netfilter/nf_conntrack_proto_icmp.c:373:3: error: ‘const struct 
nf_conntrack_l4proto’ has no member named ‘ctnl_timeout’; did you mean 
‘get_timeouts’?

  .ctnl_timeout  = {
   ^~~~
   get_timeouts

The problematic patch is:> 
netfilter-conntrack-timeout-interface-depend-on-config_nf_conntrack_timeout.patch


The stuff the commit message talks about seems like it was added in 
4.19-rc1, so this should not go into stable.


Kernel builds fine with this one patch reverted.


Re: [PATCH v2 2/2] treewide: use bus_find_device_by_fwnode

2018-10-08 Thread Silesh C V
Hello Rob,

Thanks for the review.

On Mon, Oct 8, 2018 at 9:15 PM Rob Herring  wrote:
>
> In the future, please use get_maintainers.pl and send to the right
> lists and people. Perhaps the coresight, i2c, network, nvmem and spi
> maintainers would like to see and be aware of this change.
>

Sure. Will send v3 with all the right people copied.

Regards,
Silesh


Re: [PATCH v2 2/2] treewide: use bus_find_device_by_fwnode

2018-10-08 Thread Silesh C V
Hello Rob,

Thanks for the review.

On Mon, Oct 8, 2018 at 9:15 PM Rob Herring  wrote:
>
> In the future, please use get_maintainers.pl and send to the right
> lists and people. Perhaps the coresight, i2c, network, nvmem and spi
> maintainers would like to see and be aware of this change.
>

Sure. Will send v3 with all the right people copied.

Regards,
Silesh


Re: [PATCH v2 1/2] Driver core: add bus_find_device_by_fwnode

2018-10-08 Thread Silesh C V
Hello Rafael,

On Mon, Oct 8, 2018 at 1:43 PM Rafael J. Wysocki  wrote:
>
> On Tue, Sep 25, 2018 at 7:29 AM Silesh C V  wrote:
> >
> > Some drivers need to find the device on a bus having a specific firmware
> > node. Currently, such drivers have their own implementations to do this.
> > Provide a helper similar to bus_find_device_by_name so that each driver
> > does not have to reinvent this.
> >
> > Signed-off-by: Silesh C V 
> >
> > ---
> >  drivers/base/bus.c | 26 ++
> >  include/linux/device.h |  3 +++
> >  2 files changed, 29 insertions(+)
> >
> > diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> > index 8bfd27e..148b198 100644
> > --- a/drivers/base/bus.c
> > +++ b/drivers/base/bus.c
> > @@ -17,6 +17,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include "base.h"
> >  #include "power/power.h"
> >
> > @@ -373,6 +374,31 @@ struct device *bus_find_device_by_name(struct bus_type 
> > *bus,
> >  }
> >  EXPORT_SYMBOL_GPL(bus_find_device_by_name);
> >
> > +static int match_fwnode(struct device *dev, void *data)
> > +{
> > +   struct fwnode_handle *fwnode = data;
> > +   struct device_node *of_node = to_of_node(fwnode);
> > +
> > +   if (of_node)
> > +   return dev->of_node == of_node;
> > +   else
> > +   return dev->fwnode == fwnode;
>
> Why don't you use dev_fwnode() here?
>

OK. Will send an updated patch.

Thanks,
Silesh.


Re: [PATCH v2 1/2] Driver core: add bus_find_device_by_fwnode

2018-10-08 Thread Silesh C V
Hello Rafael,

On Mon, Oct 8, 2018 at 1:43 PM Rafael J. Wysocki  wrote:
>
> On Tue, Sep 25, 2018 at 7:29 AM Silesh C V  wrote:
> >
> > Some drivers need to find the device on a bus having a specific firmware
> > node. Currently, such drivers have their own implementations to do this.
> > Provide a helper similar to bus_find_device_by_name so that each driver
> > does not have to reinvent this.
> >
> > Signed-off-by: Silesh C V 
> >
> > ---
> >  drivers/base/bus.c | 26 ++
> >  include/linux/device.h |  3 +++
> >  2 files changed, 29 insertions(+)
> >
> > diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> > index 8bfd27e..148b198 100644
> > --- a/drivers/base/bus.c
> > +++ b/drivers/base/bus.c
> > @@ -17,6 +17,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include "base.h"
> >  #include "power/power.h"
> >
> > @@ -373,6 +374,31 @@ struct device *bus_find_device_by_name(struct bus_type 
> > *bus,
> >  }
> >  EXPORT_SYMBOL_GPL(bus_find_device_by_name);
> >
> > +static int match_fwnode(struct device *dev, void *data)
> > +{
> > +   struct fwnode_handle *fwnode = data;
> > +   struct device_node *of_node = to_of_node(fwnode);
> > +
> > +   if (of_node)
> > +   return dev->of_node == of_node;
> > +   else
> > +   return dev->fwnode == fwnode;
>
> Why don't you use dev_fwnode() here?
>

OK. Will send an updated patch.

Thanks,
Silesh.


Re: [PATCH v6 2/9] PCI: mediatek: Fixup class ID for MT7622 as PCI_CLASS_BRIDGE_PCI

2018-10-08 Thread Honghui Zhang
On Mon, 2018-10-08 at 18:23 +0100, Lorenzo Pieralisi wrote:
> On Mon, Oct 08, 2018 at 11:24:41AM +0800, honghui.zh...@mediatek.com wrote:
> > From: Honghui Zhang 
> > 
> > The PCIe controller of MT7622 has TYPE 1 configuration space type, but
> > the HW default class type values is invalid.
> > 
> > The commit 101c92dc80c8 ("PCI: mediatek: Set up vendor ID and class
> > type for MT7622") have set the class ID for MT7622 as
> > PCI_CLASS_BRIDGE_HOST, but it's not workable for MT7622:
> > 
> > In __pci_bus_assign_resources, the framework only setup bridge's
> > resource window only if class type is PCI_CLASS_BRIDGE_PCI. Or it
> > will leave the subordinary PCIe device's MMIO window un-touched.
> > 
> > Fixup the class type to PCI_CLASS_BRIDGE_PCI as most of the controller
> > driver do.
> 
> I think that this patch is correct but the commit log fails to pin point
> the problem. The IP you are programming is a root port, that's why you
> have to have the proper class code, the patch looks fine but I would
> like to peek Bjorn's brain on this since it is a fundamental concept.
> 

I'm a bit confused with the concepts of PCI_CLASS_BRIDGE_HOST and
PCI_CLASS_BRIDGE_PCI, from PCI express spec,
4.0r1.0(PCI_Express_Base_4.0r1.0_September-27-2017-c), Host Bridge is
"part of a Root Complex that connects a host CPU or CPUs to a
Hierarchy". While Root Complex defines as "A defined System Element that
includes at least one Host Bridge, Root port, or Root complex Integrated
Endpoint".

But according to my understanding, most of the root port IPs integrated
with a "PCI_CLASS_BRIDGE_PCI", which has type 1 configuration space and
could be saw as a pci device when using lspci.

And for MT7622, it integrated with block of internal control registers,
type 1 configuration space, and is considered as a root complex.

I'm not sure which CLASS type it should have:
>From PCI_Code-ID_r_1_10__v8-Nov_2017, class type of
0x0604(PCI_CLASS_BRIDGE_PCI) is defined as a PCI-to-PCI bridge, not
literally suitable for MT7622(which is a root complex)(In my personal
opinion). But it is the only workable CLASS type for MT7622 in current
kernel.

> If the kernel does not assign resources unless it detects a
> PCI_CLASS_BRIDGE_PCI this means that for components that are
> actually PCI_CLASS_BRIDGE_HOST their register set must come
> preprogrammed unless I am missing something.
> 

In the function pci_request_resource_alignment, it will by pass the
resource assignment for PCI_CLASS_BRIDGE_HOST, though I'm not figured
out why.

> I would like to get to the bottom of this since it is a fundamental
> enumeration concept.
> 

Do you like me to re-write the commit message for this patch and put the
above information in? Or just not mention the PCI_CLASS_BRIDGE_HOST
assign resource routine?

Thanks

> Thanks,
> Lorenzo
> 
> > 
> > Signed-off-by: Honghui Zhang 
> > Acked-by: Ryder Lee 
> > ---
> >  drivers/pci/controller/pcie-mediatek.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/pci/controller/pcie-mediatek.c 
> > b/drivers/pci/controller/pcie-mediatek.c
> > index 288b8e2..bcdac9b 100644
> > --- a/drivers/pci/controller/pcie-mediatek.c
> > +++ b/drivers/pci/controller/pcie-mediatek.c
> > @@ -432,7 +432,7 @@ static int mtk_pcie_startup_port_v2(struct 
> > mtk_pcie_port *port)
> > val = PCI_VENDOR_ID_MEDIATEK;
> > writew(val, port->base + PCIE_CONF_VEND_ID);
> >  
> > -   val = PCI_CLASS_BRIDGE_HOST;
> > +   val = PCI_CLASS_BRIDGE_PCI;
> > writew(val, port->base + PCIE_CONF_CLASS_ID);
> > }
> >  
> > -- 
> > 2.6.4
> > 




Re: [PATCH v6 2/9] PCI: mediatek: Fixup class ID for MT7622 as PCI_CLASS_BRIDGE_PCI

2018-10-08 Thread Honghui Zhang
On Mon, 2018-10-08 at 18:23 +0100, Lorenzo Pieralisi wrote:
> On Mon, Oct 08, 2018 at 11:24:41AM +0800, honghui.zh...@mediatek.com wrote:
> > From: Honghui Zhang 
> > 
> > The PCIe controller of MT7622 has TYPE 1 configuration space type, but
> > the HW default class type values is invalid.
> > 
> > The commit 101c92dc80c8 ("PCI: mediatek: Set up vendor ID and class
> > type for MT7622") have set the class ID for MT7622 as
> > PCI_CLASS_BRIDGE_HOST, but it's not workable for MT7622:
> > 
> > In __pci_bus_assign_resources, the framework only setup bridge's
> > resource window only if class type is PCI_CLASS_BRIDGE_PCI. Or it
> > will leave the subordinary PCIe device's MMIO window un-touched.
> > 
> > Fixup the class type to PCI_CLASS_BRIDGE_PCI as most of the controller
> > driver do.
> 
> I think that this patch is correct but the commit log fails to pin point
> the problem. The IP you are programming is a root port, that's why you
> have to have the proper class code, the patch looks fine but I would
> like to peek Bjorn's brain on this since it is a fundamental concept.
> 

I'm a bit confused with the concepts of PCI_CLASS_BRIDGE_HOST and
PCI_CLASS_BRIDGE_PCI, from PCI express spec,
4.0r1.0(PCI_Express_Base_4.0r1.0_September-27-2017-c), Host Bridge is
"part of a Root Complex that connects a host CPU or CPUs to a
Hierarchy". While Root Complex defines as "A defined System Element that
includes at least one Host Bridge, Root port, or Root complex Integrated
Endpoint".

But according to my understanding, most of the root port IPs integrated
with a "PCI_CLASS_BRIDGE_PCI", which has type 1 configuration space and
could be saw as a pci device when using lspci.

And for MT7622, it integrated with block of internal control registers,
type 1 configuration space, and is considered as a root complex.

I'm not sure which CLASS type it should have:
>From PCI_Code-ID_r_1_10__v8-Nov_2017, class type of
0x0604(PCI_CLASS_BRIDGE_PCI) is defined as a PCI-to-PCI bridge, not
literally suitable for MT7622(which is a root complex)(In my personal
opinion). But it is the only workable CLASS type for MT7622 in current
kernel.

> If the kernel does not assign resources unless it detects a
> PCI_CLASS_BRIDGE_PCI this means that for components that are
> actually PCI_CLASS_BRIDGE_HOST their register set must come
> preprogrammed unless I am missing something.
> 

In the function pci_request_resource_alignment, it will by pass the
resource assignment for PCI_CLASS_BRIDGE_HOST, though I'm not figured
out why.

> I would like to get to the bottom of this since it is a fundamental
> enumeration concept.
> 

Do you like me to re-write the commit message for this patch and put the
above information in? Or just not mention the PCI_CLASS_BRIDGE_HOST
assign resource routine?

Thanks

> Thanks,
> Lorenzo
> 
> > 
> > Signed-off-by: Honghui Zhang 
> > Acked-by: Ryder Lee 
> > ---
> >  drivers/pci/controller/pcie-mediatek.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/pci/controller/pcie-mediatek.c 
> > b/drivers/pci/controller/pcie-mediatek.c
> > index 288b8e2..bcdac9b 100644
> > --- a/drivers/pci/controller/pcie-mediatek.c
> > +++ b/drivers/pci/controller/pcie-mediatek.c
> > @@ -432,7 +432,7 @@ static int mtk_pcie_startup_port_v2(struct 
> > mtk_pcie_port *port)
> > val = PCI_VENDOR_ID_MEDIATEK;
> > writew(val, port->base + PCIE_CONF_VEND_ID);
> >  
> > -   val = PCI_CLASS_BRIDGE_HOST;
> > +   val = PCI_CLASS_BRIDGE_PCI;
> > writew(val, port->base + PCIE_CONF_CLASS_ID);
> > }
> >  
> > -- 
> > 2.6.4
> > 




Re: [tip:x86/mm] kdump, proc/vmcore: Enable kdumping encrypted memory with SME enabled

2018-10-08 Thread lijiang
在 2018年10月08日 21:43, Borislav Petkov 写道:
> On Mon, Oct 08, 2018 at 10:59:09AM +0200, Borislav Petkov wrote:
>> On Mon, Oct 08, 2018 at 04:47:34PM +0800, lijiang wrote:
>>> It looks like a good way to avoid the 'ifdefined', and it's also good 
>>> enough for i386.
>>>
>>> But for other architectures, such as POWERPC/ARM..., we will also have to 
>>> add the same 
>>> function for every architecture. Otherwise, i guess that they also have a 
>>> same compile
>>> error on other architectures.
>>
>> Yap, just realized that and looking at the rest of fs/proc/vmcore.c -
>> such functions are defined with the __weak attribute. Lemme see if that
>> works better.
> 
> Seems so. I'll hammer on it more today:
> 
Great! Thank you, Borislav.

Regards,
Lianbo
> ---
>  fs/proc/vmcore.c | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
> index 42c32d06f7da..91ae16fbd7d5 100644
> --- a/fs/proc/vmcore.c
> +++ b/fs/proc/vmcore.c
> @@ -187,6 +187,16 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct 
> *vma,
>   return remap_pfn_range(vma, from, pfn, size, prot);
>  }
>  
> +/*
> + * Architectures which support memory encryption override this.
> + */
> +ssize_t __weak
> +copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize,
> +unsigned long offset, int userbuf)
> +{
> + return copy_oldmem_page(pfn, buf, csize, offset, userbuf);
> +}
> +
>  /*
>   * Copy to either kernel or user space
>   */
> 


Re: [tip:x86/mm] kdump, proc/vmcore: Enable kdumping encrypted memory with SME enabled

2018-10-08 Thread lijiang
在 2018年10月08日 21:43, Borislav Petkov 写道:
> On Mon, Oct 08, 2018 at 10:59:09AM +0200, Borislav Petkov wrote:
>> On Mon, Oct 08, 2018 at 04:47:34PM +0800, lijiang wrote:
>>> It looks like a good way to avoid the 'ifdefined', and it's also good 
>>> enough for i386.
>>>
>>> But for other architectures, such as POWERPC/ARM..., we will also have to 
>>> add the same 
>>> function for every architecture. Otherwise, i guess that they also have a 
>>> same compile
>>> error on other architectures.
>>
>> Yap, just realized that and looking at the rest of fs/proc/vmcore.c -
>> such functions are defined with the __weak attribute. Lemme see if that
>> works better.
> 
> Seems so. I'll hammer on it more today:
> 
Great! Thank you, Borislav.

Regards,
Lianbo
> ---
>  fs/proc/vmcore.c | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
> index 42c32d06f7da..91ae16fbd7d5 100644
> --- a/fs/proc/vmcore.c
> +++ b/fs/proc/vmcore.c
> @@ -187,6 +187,16 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct 
> *vma,
>   return remap_pfn_range(vma, from, pfn, size, prot);
>  }
>  
> +/*
> + * Architectures which support memory encryption override this.
> + */
> +ssize_t __weak
> +copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize,
> +unsigned long offset, int userbuf)
> +{
> + return copy_oldmem_page(pfn, buf, csize, offset, userbuf);
> +}
> +
>  /*
>   * Copy to either kernel or user space
>   */
> 


Re: [PATCH V10 1/8] irqchip: add C-SKY SMP interrupt controller

2018-10-08 Thread Guo Ren
Hi Marc,

On Mon, Oct 08, 2018 at 05:35:19PM +0100, Marc Zyngier wrote:
> Hi Guo,
> 
> On 04/10/18 18:22, Guo Ren wrote:
> >  - Irq-csky-mpintc is C-SKY smp system interrupt controller and it
> >could support 16 soft irqs, 16 private irqs, and 992 max common
> >irqs.
> >
> >Changelog:
> >  - pass checkpatch.pl
> >  - Move IPI_IRQ into the driver
> >  - Remove irq_set_default_host() and use set_ipi_irq_mapping()

 [...]

> >+#ifdef CONFIG_SMP
> >+static void csky_mpintc_send_ipi(const unsigned long *mask)
> >+{
> 
> Why isn't this a cpumask? It should be this driver's job to convert the
> cpumask to an interrupt-controller specific representation, and not the SMP
> code's.
Ok, use cpumask. 

 [...]

> >+#ifdef CONFIG_SMP
> >+set_send_ipi(_mpintc_send_ipi);
> >+
> >+set_ipi_irq_mapping(_mpintc_ipi_irq_mapping);
> 
> Since you seem to be inventing a new set_send_ipi callback, why don't you
> define it as:
> 
> void set_send_ipi(void (*func)(const struct cpumask *),
> unsigned int ipi_irq);
> after having created the mapping for the IPI interrupt? It would avoid this
> rather pointless mapping callback.

I'll define it to:

void set_send_ipi(void (*func)(const struct cpumask *));

IPI_IRQ only use software-irq-15 in mpintc driver, so arch needn't care
about irq-num.

/*
 * INTCL_SIGR[3:0] INTID
 * INTCL_SIGR[8:15] CPUMASK
 */
writel_relaxed((*mask) << 8 | IPI_IRQ, reg_base + INTCL_SIGR);

We direct put IPI_IRQ to the hw-reg for the target core.

Best Regards
 Guo Ren


Re: [PATCH V10 1/8] irqchip: add C-SKY SMP interrupt controller

2018-10-08 Thread Guo Ren
Hi Marc,

On Mon, Oct 08, 2018 at 05:35:19PM +0100, Marc Zyngier wrote:
> Hi Guo,
> 
> On 04/10/18 18:22, Guo Ren wrote:
> >  - Irq-csky-mpintc is C-SKY smp system interrupt controller and it
> >could support 16 soft irqs, 16 private irqs, and 992 max common
> >irqs.
> >
> >Changelog:
> >  - pass checkpatch.pl
> >  - Move IPI_IRQ into the driver
> >  - Remove irq_set_default_host() and use set_ipi_irq_mapping()

 [...]

> >+#ifdef CONFIG_SMP
> >+static void csky_mpintc_send_ipi(const unsigned long *mask)
> >+{
> 
> Why isn't this a cpumask? It should be this driver's job to convert the
> cpumask to an interrupt-controller specific representation, and not the SMP
> code's.
Ok, use cpumask. 

 [...]

> >+#ifdef CONFIG_SMP
> >+set_send_ipi(_mpintc_send_ipi);
> >+
> >+set_ipi_irq_mapping(_mpintc_ipi_irq_mapping);
> 
> Since you seem to be inventing a new set_send_ipi callback, why don't you
> define it as:
> 
> void set_send_ipi(void (*func)(const struct cpumask *),
> unsigned int ipi_irq);
> after having created the mapping for the IPI interrupt? It would avoid this
> rather pointless mapping callback.

I'll define it to:

void set_send_ipi(void (*func)(const struct cpumask *));

IPI_IRQ only use software-irq-15 in mpintc driver, so arch needn't care
about irq-num.

/*
 * INTCL_SIGR[3:0] INTID
 * INTCL_SIGR[8:15] CPUMASK
 */
writel_relaxed((*mask) << 8 | IPI_IRQ, reg_base + INTCL_SIGR);

We direct put IPI_IRQ to the hw-reg for the target core.

Best Regards
 Guo Ren


[PATCH v8 1/5] Extract FPU context operations from entry.S

2018-10-08 Thread Alan Kao
We move __fstate_save and __fstate_restore to a new source
file, fpu.S.

Signed-off-by: Alan Kao 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Zong Li 
Cc: Nick Hu 
Reviewed-by: Christoph Hellwig 
---
 arch/riscv/kernel/Makefile |   1 +
 arch/riscv/kernel/entry.S  |  87 -
 arch/riscv/kernel/fpu.S| 106 +
 3 files changed, 107 insertions(+), 87 deletions(-)
 create mode 100644 arch/riscv/kernel/fpu.S

diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index e1274fc..bd433efd 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -13,6 +13,7 @@ extra-y += vmlinux.lds
 obj-y  += cpu.o
 obj-y  += cpufeature.o
 obj-y  += entry.o
+obj-y  += fpu.o
 obj-y  += irq.o
 obj-y  += process.o
 obj-y  += ptrace.o
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index fa2c08e..59c02e2 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -357,93 +357,6 @@ ENTRY(__switch_to)
ret
 ENDPROC(__switch_to)
 
-ENTRY(__fstate_save)
-   li  a2,  TASK_THREAD_F0
-   add a0, a0, a2
-   li t1, SR_FS
-   csrs sstatus, t1
-   frcsr t0
-   fsd f0,  TASK_THREAD_F0_F0(a0)
-   fsd f1,  TASK_THREAD_F1_F0(a0)
-   fsd f2,  TASK_THREAD_F2_F0(a0)
-   fsd f3,  TASK_THREAD_F3_F0(a0)
-   fsd f4,  TASK_THREAD_F4_F0(a0)
-   fsd f5,  TASK_THREAD_F5_F0(a0)
-   fsd f6,  TASK_THREAD_F6_F0(a0)
-   fsd f7,  TASK_THREAD_F7_F0(a0)
-   fsd f8,  TASK_THREAD_F8_F0(a0)
-   fsd f9,  TASK_THREAD_F9_F0(a0)
-   fsd f10, TASK_THREAD_F10_F0(a0)
-   fsd f11, TASK_THREAD_F11_F0(a0)
-   fsd f12, TASK_THREAD_F12_F0(a0)
-   fsd f13, TASK_THREAD_F13_F0(a0)
-   fsd f14, TASK_THREAD_F14_F0(a0)
-   fsd f15, TASK_THREAD_F15_F0(a0)
-   fsd f16, TASK_THREAD_F16_F0(a0)
-   fsd f17, TASK_THREAD_F17_F0(a0)
-   fsd f18, TASK_THREAD_F18_F0(a0)
-   fsd f19, TASK_THREAD_F19_F0(a0)
-   fsd f20, TASK_THREAD_F20_F0(a0)
-   fsd f21, TASK_THREAD_F21_F0(a0)
-   fsd f22, TASK_THREAD_F22_F0(a0)
-   fsd f23, TASK_THREAD_F23_F0(a0)
-   fsd f24, TASK_THREAD_F24_F0(a0)
-   fsd f25, TASK_THREAD_F25_F0(a0)
-   fsd f26, TASK_THREAD_F26_F0(a0)
-   fsd f27, TASK_THREAD_F27_F0(a0)
-   fsd f28, TASK_THREAD_F28_F0(a0)
-   fsd f29, TASK_THREAD_F29_F0(a0)
-   fsd f30, TASK_THREAD_F30_F0(a0)
-   fsd f31, TASK_THREAD_F31_F0(a0)
-   sw t0, TASK_THREAD_FCSR_F0(a0)
-   csrc sstatus, t1
-   ret
-ENDPROC(__fstate_save)
-
-ENTRY(__fstate_restore)
-   li  a2,  TASK_THREAD_F0
-   add a0, a0, a2
-   li t1, SR_FS
-   lw t0, TASK_THREAD_FCSR_F0(a0)
-   csrs sstatus, t1
-   fld f0,  TASK_THREAD_F0_F0(a0)
-   fld f1,  TASK_THREAD_F1_F0(a0)
-   fld f2,  TASK_THREAD_F2_F0(a0)
-   fld f3,  TASK_THREAD_F3_F0(a0)
-   fld f4,  TASK_THREAD_F4_F0(a0)
-   fld f5,  TASK_THREAD_F5_F0(a0)
-   fld f6,  TASK_THREAD_F6_F0(a0)
-   fld f7,  TASK_THREAD_F7_F0(a0)
-   fld f8,  TASK_THREAD_F8_F0(a0)
-   fld f9,  TASK_THREAD_F9_F0(a0)
-   fld f10, TASK_THREAD_F10_F0(a0)
-   fld f11, TASK_THREAD_F11_F0(a0)
-   fld f12, TASK_THREAD_F12_F0(a0)
-   fld f13, TASK_THREAD_F13_F0(a0)
-   fld f14, TASK_THREAD_F14_F0(a0)
-   fld f15, TASK_THREAD_F15_F0(a0)
-   fld f16, TASK_THREAD_F16_F0(a0)
-   fld f17, TASK_THREAD_F17_F0(a0)
-   fld f18, TASK_THREAD_F18_F0(a0)
-   fld f19, TASK_THREAD_F19_F0(a0)
-   fld f20, TASK_THREAD_F20_F0(a0)
-   fld f21, TASK_THREAD_F21_F0(a0)
-   fld f22, TASK_THREAD_F22_F0(a0)
-   fld f23, TASK_THREAD_F23_F0(a0)
-   fld f24, TASK_THREAD_F24_F0(a0)
-   fld f25, TASK_THREAD_F25_F0(a0)
-   fld f26, TASK_THREAD_F26_F0(a0)
-   fld f27, TASK_THREAD_F27_F0(a0)
-   fld f28, TASK_THREAD_F28_F0(a0)
-   fld f29, TASK_THREAD_F29_F0(a0)
-   fld f30, TASK_THREAD_F30_F0(a0)
-   fld f31, TASK_THREAD_F31_F0(a0)
-   fscsr t0
-   csrc sstatus, t1
-   ret
-ENDPROC(__fstate_restore)
-
-
.section ".rodata"
/* Exception vector table */
 ENTRY(excp_vect_table)
diff --git a/arch/riscv/kernel/fpu.S b/arch/riscv/kernel/fpu.S
new file mode 100644
index 000..1defb06
--- /dev/null
+++ b/arch/riscv/kernel/fpu.S
@@ -0,0 +1,106 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   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, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include 
+
+#include 
+#include 

[PATCH v8 3/5] Cleanup ISA string setting

2018-10-08 Thread Alan Kao
This patch cleanup the MARCH string passing to both compiler and
assembler.  Note that the CFLAGS should not contain "fd" before we
have mechnisms like kernel_fpu_begin/end in other architectures.

Signed-off-by: Alan Kao 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Zong Li 
Cc: Nick Hu 
---
 arch/riscv/Makefile | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 61ec424..01393e1 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -28,7 +28,6 @@ ifeq ($(CONFIG_ARCH_RV64I),y)

KBUILD_CFLAGS   += $(call cc-ifversion, -ge, 0500, 
-DCONFIG_ARCH_SUPPORTS_INT128)
 
-   KBUILD_MARCH = rv64im
KBUILD_LDFLAGS += -melf64lriscv
 else
BITS := 32
@@ -36,22 +35,20 @@ else
 
KBUILD_CFLAGS += -mabi=ilp32
KBUILD_AFLAGS += -mabi=ilp32
-   KBUILD_MARCH = rv32im
KBUILD_LDFLAGS += -melf32lriscv
 endif
 
 KBUILD_CFLAGS += -Wall
 
-ifeq ($(CONFIG_RISCV_ISA_A),y)
-   KBUILD_ARCH_A = a
-endif
-ifeq ($(CONFIG_RISCV_ISA_C),y)
-   KBUILD_ARCH_C = c
-endif
-
-KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_ARCH_A)fd$(KBUILD_ARCH_C)
+# ISA string setting
+riscv-march-$(CONFIG_ARCH_RV32I)   := rv32im
+riscv-march-$(CONFIG_ARCH_RV64I)   := rv64im
+riscv-march-$(CONFIG_RISCV_ISA_A)  := $(riscv-march-y)a
+riscv-march-y  := $(riscv-march-y)fd
+riscv-march-$(CONFIG_RISCV_ISA_C)  := $(riscv-march-y)c
+KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
+KBUILD_AFLAGS += -march=$(riscv-march-y)
 
-KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_ARCH_A)$(KBUILD_ARCH_C)
 KBUILD_CFLAGS += -mno-save-restore
 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
 
-- 
2.7.4



[PATCH v8 1/5] Extract FPU context operations from entry.S

2018-10-08 Thread Alan Kao
We move __fstate_save and __fstate_restore to a new source
file, fpu.S.

Signed-off-by: Alan Kao 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Zong Li 
Cc: Nick Hu 
Reviewed-by: Christoph Hellwig 
---
 arch/riscv/kernel/Makefile |   1 +
 arch/riscv/kernel/entry.S  |  87 -
 arch/riscv/kernel/fpu.S| 106 +
 3 files changed, 107 insertions(+), 87 deletions(-)
 create mode 100644 arch/riscv/kernel/fpu.S

diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index e1274fc..bd433efd 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -13,6 +13,7 @@ extra-y += vmlinux.lds
 obj-y  += cpu.o
 obj-y  += cpufeature.o
 obj-y  += entry.o
+obj-y  += fpu.o
 obj-y  += irq.o
 obj-y  += process.o
 obj-y  += ptrace.o
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index fa2c08e..59c02e2 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -357,93 +357,6 @@ ENTRY(__switch_to)
ret
 ENDPROC(__switch_to)
 
-ENTRY(__fstate_save)
-   li  a2,  TASK_THREAD_F0
-   add a0, a0, a2
-   li t1, SR_FS
-   csrs sstatus, t1
-   frcsr t0
-   fsd f0,  TASK_THREAD_F0_F0(a0)
-   fsd f1,  TASK_THREAD_F1_F0(a0)
-   fsd f2,  TASK_THREAD_F2_F0(a0)
-   fsd f3,  TASK_THREAD_F3_F0(a0)
-   fsd f4,  TASK_THREAD_F4_F0(a0)
-   fsd f5,  TASK_THREAD_F5_F0(a0)
-   fsd f6,  TASK_THREAD_F6_F0(a0)
-   fsd f7,  TASK_THREAD_F7_F0(a0)
-   fsd f8,  TASK_THREAD_F8_F0(a0)
-   fsd f9,  TASK_THREAD_F9_F0(a0)
-   fsd f10, TASK_THREAD_F10_F0(a0)
-   fsd f11, TASK_THREAD_F11_F0(a0)
-   fsd f12, TASK_THREAD_F12_F0(a0)
-   fsd f13, TASK_THREAD_F13_F0(a0)
-   fsd f14, TASK_THREAD_F14_F0(a0)
-   fsd f15, TASK_THREAD_F15_F0(a0)
-   fsd f16, TASK_THREAD_F16_F0(a0)
-   fsd f17, TASK_THREAD_F17_F0(a0)
-   fsd f18, TASK_THREAD_F18_F0(a0)
-   fsd f19, TASK_THREAD_F19_F0(a0)
-   fsd f20, TASK_THREAD_F20_F0(a0)
-   fsd f21, TASK_THREAD_F21_F0(a0)
-   fsd f22, TASK_THREAD_F22_F0(a0)
-   fsd f23, TASK_THREAD_F23_F0(a0)
-   fsd f24, TASK_THREAD_F24_F0(a0)
-   fsd f25, TASK_THREAD_F25_F0(a0)
-   fsd f26, TASK_THREAD_F26_F0(a0)
-   fsd f27, TASK_THREAD_F27_F0(a0)
-   fsd f28, TASK_THREAD_F28_F0(a0)
-   fsd f29, TASK_THREAD_F29_F0(a0)
-   fsd f30, TASK_THREAD_F30_F0(a0)
-   fsd f31, TASK_THREAD_F31_F0(a0)
-   sw t0, TASK_THREAD_FCSR_F0(a0)
-   csrc sstatus, t1
-   ret
-ENDPROC(__fstate_save)
-
-ENTRY(__fstate_restore)
-   li  a2,  TASK_THREAD_F0
-   add a0, a0, a2
-   li t1, SR_FS
-   lw t0, TASK_THREAD_FCSR_F0(a0)
-   csrs sstatus, t1
-   fld f0,  TASK_THREAD_F0_F0(a0)
-   fld f1,  TASK_THREAD_F1_F0(a0)
-   fld f2,  TASK_THREAD_F2_F0(a0)
-   fld f3,  TASK_THREAD_F3_F0(a0)
-   fld f4,  TASK_THREAD_F4_F0(a0)
-   fld f5,  TASK_THREAD_F5_F0(a0)
-   fld f6,  TASK_THREAD_F6_F0(a0)
-   fld f7,  TASK_THREAD_F7_F0(a0)
-   fld f8,  TASK_THREAD_F8_F0(a0)
-   fld f9,  TASK_THREAD_F9_F0(a0)
-   fld f10, TASK_THREAD_F10_F0(a0)
-   fld f11, TASK_THREAD_F11_F0(a0)
-   fld f12, TASK_THREAD_F12_F0(a0)
-   fld f13, TASK_THREAD_F13_F0(a0)
-   fld f14, TASK_THREAD_F14_F0(a0)
-   fld f15, TASK_THREAD_F15_F0(a0)
-   fld f16, TASK_THREAD_F16_F0(a0)
-   fld f17, TASK_THREAD_F17_F0(a0)
-   fld f18, TASK_THREAD_F18_F0(a0)
-   fld f19, TASK_THREAD_F19_F0(a0)
-   fld f20, TASK_THREAD_F20_F0(a0)
-   fld f21, TASK_THREAD_F21_F0(a0)
-   fld f22, TASK_THREAD_F22_F0(a0)
-   fld f23, TASK_THREAD_F23_F0(a0)
-   fld f24, TASK_THREAD_F24_F0(a0)
-   fld f25, TASK_THREAD_F25_F0(a0)
-   fld f26, TASK_THREAD_F26_F0(a0)
-   fld f27, TASK_THREAD_F27_F0(a0)
-   fld f28, TASK_THREAD_F28_F0(a0)
-   fld f29, TASK_THREAD_F29_F0(a0)
-   fld f30, TASK_THREAD_F30_F0(a0)
-   fld f31, TASK_THREAD_F31_F0(a0)
-   fscsr t0
-   csrc sstatus, t1
-   ret
-ENDPROC(__fstate_restore)
-
-
.section ".rodata"
/* Exception vector table */
 ENTRY(excp_vect_table)
diff --git a/arch/riscv/kernel/fpu.S b/arch/riscv/kernel/fpu.S
new file mode 100644
index 000..1defb06
--- /dev/null
+++ b/arch/riscv/kernel/fpu.S
@@ -0,0 +1,106 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2012 Regents of the University of California
+ * Copyright (C) 2017 SiFive
+ *
+ *   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, version 2.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include 
+
+#include 
+#include 

[PATCH v8 3/5] Cleanup ISA string setting

2018-10-08 Thread Alan Kao
This patch cleanup the MARCH string passing to both compiler and
assembler.  Note that the CFLAGS should not contain "fd" before we
have mechnisms like kernel_fpu_begin/end in other architectures.

Signed-off-by: Alan Kao 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Zong Li 
Cc: Nick Hu 
---
 arch/riscv/Makefile | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 61ec424..01393e1 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -28,7 +28,6 @@ ifeq ($(CONFIG_ARCH_RV64I),y)

KBUILD_CFLAGS   += $(call cc-ifversion, -ge, 0500, 
-DCONFIG_ARCH_SUPPORTS_INT128)
 
-   KBUILD_MARCH = rv64im
KBUILD_LDFLAGS += -melf64lriscv
 else
BITS := 32
@@ -36,22 +35,20 @@ else
 
KBUILD_CFLAGS += -mabi=ilp32
KBUILD_AFLAGS += -mabi=ilp32
-   KBUILD_MARCH = rv32im
KBUILD_LDFLAGS += -melf32lriscv
 endif
 
 KBUILD_CFLAGS += -Wall
 
-ifeq ($(CONFIG_RISCV_ISA_A),y)
-   KBUILD_ARCH_A = a
-endif
-ifeq ($(CONFIG_RISCV_ISA_C),y)
-   KBUILD_ARCH_C = c
-endif
-
-KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_ARCH_A)fd$(KBUILD_ARCH_C)
+# ISA string setting
+riscv-march-$(CONFIG_ARCH_RV32I)   := rv32im
+riscv-march-$(CONFIG_ARCH_RV64I)   := rv64im
+riscv-march-$(CONFIG_RISCV_ISA_A)  := $(riscv-march-y)a
+riscv-march-y  := $(riscv-march-y)fd
+riscv-march-$(CONFIG_RISCV_ISA_C)  := $(riscv-march-y)c
+KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
+KBUILD_AFLAGS += -march=$(riscv-march-y)
 
-KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_ARCH_A)$(KBUILD_ARCH_C)
 KBUILD_CFLAGS += -mno-save-restore
 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
 
-- 
2.7.4



[PATCH v8 5/5] Auto-detect whether a FPU exists

2018-10-08 Thread Alan Kao
We expect that a kernel with CONFIG_FPU=y can still support no-FPU
machines. To do so, the kernel should first examine the existence of a
FPU, then do nothing if a FPU does exist; otherwise, it should
disable/bypass all FPU-related functions.

In this patch, a new global variable, has_fpu, is created and determined
when parsing the hardware capability from device tree during booting.
This variable is used in those FPU-related functions.

Signed-off-by: Alan Kao 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Zong Li 
Cc: Nick Hu 
---
 arch/riscv/include/asm/switch_to.h | 8 
 arch/riscv/kernel/cpufeature.c | 8 
 arch/riscv/kernel/process.c| 4 +++-
 arch/riscv/kernel/signal.c | 6 --
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/arch/riscv/include/asm/switch_to.h 
b/arch/riscv/include/asm/switch_to.h
index 093050b..7335590 100644
--- a/arch/riscv/include/asm/switch_to.h
+++ b/arch/riscv/include/asm/switch_to.h
@@ -56,13 +56,12 @@ static inline void __switch_to_aux(struct task_struct *prev,
fstate_restore(next, task_pt_regs(next));
 }
 
-#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_INITIAL)
-
+extern bool has_fpu;
 #else
+#define has_fpu false
 #define fstate_save(task, regs) do { } while (0)
 #define fstate_restore(task, regs) do { } while (0)
 #define __switch_to_aux(__prev, __next) do { } while (0)
-#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_OFF)
 #endif
 
 extern struct task_struct *__switch_to(struct task_struct *,
@@ -72,7 +71,8 @@ extern struct task_struct *__switch_to(struct task_struct *,
 do {   \
struct task_struct *__prev = (prev);\
struct task_struct *__next = (next);\
-   __switch_to_aux(__prev, __next);\
+   if (has_fpu)\
+   __switch_to_aux(__prev, __next);\
((last) = __switch_to(__prev, __next)); \
 } while (0)
 
diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
index 17011a8..46942e6 100644
--- a/arch/riscv/kernel/cpufeature.c
+++ b/arch/riscv/kernel/cpufeature.c
@@ -22,6 +22,9 @@
 #include 
 
 unsigned long elf_hwcap __read_mostly;
+#ifdef CONFIG_FPU
+bool has_fpu __read_mostly;
+#endif
 
 void riscv_fill_hwcap(void)
 {
@@ -58,4 +61,9 @@ void riscv_fill_hwcap(void)
elf_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
 
pr_info("elf_hwcap is 0x%lx", elf_hwcap);
+
+#ifdef CONFIG_FPU
+   if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D))
+   has_fpu = true;
+#endif
 }
diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index 07d5156..bef1999 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -76,7 +76,9 @@ void show_regs(struct pt_regs *regs)
 void start_thread(struct pt_regs *regs, unsigned long pc,
unsigned long sp)
 {
-   regs->sstatus = DEFAULT_SSTATUS;
+   regs->sstatus = SR_SPIE;
+   if (has_fpu)
+   regs->sstatus |= SR_FS_INITIAL;
regs->sepc = pc;
regs->sp = sp;
set_fs(USER_DS);
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 2450b82..f9b5e7e 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -98,7 +98,8 @@ static long restore_sigcontext(struct pt_regs *regs,
/* sc_regs is structured the same as the start of pt_regs */
err = __copy_from_user(regs, >sc_regs, sizeof(sc->sc_regs));
/* Restore the floating-point state. */
-   err |= restore_fp_state(regs, >sc_fpregs);
+   if (has_fpu)
+   err |= restore_fp_state(regs, >sc_fpregs);
return err;
 }
 
@@ -150,7 +151,8 @@ static long setup_sigcontext(struct rt_sigframe __user 
*frame,
/* sc_regs is structured the same as the start of pt_regs */
err = __copy_to_user(>sc_regs, regs, sizeof(sc->sc_regs));
/* Save the floating-point state. */
-   err |= save_fp_state(regs, >sc_fpregs);
+   if (has_fpu)
+   err |= save_fp_state(regs, >sc_fpregs);
return err;
 }
 
-- 
2.7.4



[PATCH v8 5/5] Auto-detect whether a FPU exists

2018-10-08 Thread Alan Kao
We expect that a kernel with CONFIG_FPU=y can still support no-FPU
machines. To do so, the kernel should first examine the existence of a
FPU, then do nothing if a FPU does exist; otherwise, it should
disable/bypass all FPU-related functions.

In this patch, a new global variable, has_fpu, is created and determined
when parsing the hardware capability from device tree during booting.
This variable is used in those FPU-related functions.

Signed-off-by: Alan Kao 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Zong Li 
Cc: Nick Hu 
---
 arch/riscv/include/asm/switch_to.h | 8 
 arch/riscv/kernel/cpufeature.c | 8 
 arch/riscv/kernel/process.c| 4 +++-
 arch/riscv/kernel/signal.c | 6 --
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/arch/riscv/include/asm/switch_to.h 
b/arch/riscv/include/asm/switch_to.h
index 093050b..7335590 100644
--- a/arch/riscv/include/asm/switch_to.h
+++ b/arch/riscv/include/asm/switch_to.h
@@ -56,13 +56,12 @@ static inline void __switch_to_aux(struct task_struct *prev,
fstate_restore(next, task_pt_regs(next));
 }
 
-#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_INITIAL)
-
+extern bool has_fpu;
 #else
+#define has_fpu false
 #define fstate_save(task, regs) do { } while (0)
 #define fstate_restore(task, regs) do { } while (0)
 #define __switch_to_aux(__prev, __next) do { } while (0)
-#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_OFF)
 #endif
 
 extern struct task_struct *__switch_to(struct task_struct *,
@@ -72,7 +71,8 @@ extern struct task_struct *__switch_to(struct task_struct *,
 do {   \
struct task_struct *__prev = (prev);\
struct task_struct *__next = (next);\
-   __switch_to_aux(__prev, __next);\
+   if (has_fpu)\
+   __switch_to_aux(__prev, __next);\
((last) = __switch_to(__prev, __next)); \
 } while (0)
 
diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
index 17011a8..46942e6 100644
--- a/arch/riscv/kernel/cpufeature.c
+++ b/arch/riscv/kernel/cpufeature.c
@@ -22,6 +22,9 @@
 #include 
 
 unsigned long elf_hwcap __read_mostly;
+#ifdef CONFIG_FPU
+bool has_fpu __read_mostly;
+#endif
 
 void riscv_fill_hwcap(void)
 {
@@ -58,4 +61,9 @@ void riscv_fill_hwcap(void)
elf_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
 
pr_info("elf_hwcap is 0x%lx", elf_hwcap);
+
+#ifdef CONFIG_FPU
+   if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D))
+   has_fpu = true;
+#endif
 }
diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index 07d5156..bef1999 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -76,7 +76,9 @@ void show_regs(struct pt_regs *regs)
 void start_thread(struct pt_regs *regs, unsigned long pc,
unsigned long sp)
 {
-   regs->sstatus = DEFAULT_SSTATUS;
+   regs->sstatus = SR_SPIE;
+   if (has_fpu)
+   regs->sstatus |= SR_FS_INITIAL;
regs->sepc = pc;
regs->sp = sp;
set_fs(USER_DS);
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 2450b82..f9b5e7e 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -98,7 +98,8 @@ static long restore_sigcontext(struct pt_regs *regs,
/* sc_regs is structured the same as the start of pt_regs */
err = __copy_from_user(regs, >sc_regs, sizeof(sc->sc_regs));
/* Restore the floating-point state. */
-   err |= restore_fp_state(regs, >sc_fpregs);
+   if (has_fpu)
+   err |= restore_fp_state(regs, >sc_fpregs);
return err;
 }
 
@@ -150,7 +151,8 @@ static long setup_sigcontext(struct rt_sigframe __user 
*frame,
/* sc_regs is structured the same as the start of pt_regs */
err = __copy_to_user(>sc_regs, regs, sizeof(sc->sc_regs));
/* Save the floating-point state. */
-   err |= save_fp_state(regs, >sc_fpregs);
+   if (has_fpu)
+   err |= save_fp_state(regs, >sc_fpregs);
return err;
 }
 
-- 
2.7.4



Re: [RESEND PATCH] ARM: prevent tracing IPI_CPU_BACKTRACE

2018-10-08 Thread Chunyan Zhang
Hi All,

If there's no comments, should I submit this patch on RMK's Patch system?

Thanks,
Chunyan

On 27 September 2018 at 11:41, Chunyan Zhang  wrote:
> From: Arnd Bergmann 
>
> When function tracing for IPIs is enabled, we get a warning for an
> overflow of the ipi_types array with the IPI_CPU_BACKTRACE type
> as triggered by raise_nmi():
>
> arch/arm/kernel/smp.c: In function 'raise_nmi':
> arch/arm/kernel/smp.c:489:2: error: array subscript is above array bounds 
> [-Werror=array-bounds]
> trace_ipi_raise(target, ipi_types[ipinr]);
>
> This is a correct warning as we actually overflow the array here.
>
> This patch raise_nmi() to call __smp_cross_call() instead of
> smp_cross_call(), to avoid calling into ftrace. For clarification,
> I'm also adding a two new code comments describing how this one
> is special.
>
> The warning appears to have shown up after patch e7273ff49acf
> ("ARM: 8488/1: Make IPI_CPU_BACKTRACE a "non-secure" SGI"), which
> changed the number assignment from '15' to '8', but as far as I can
> tell has existed since the IPI tracepoints were first introduced.
> If we decide to backport this patch to stable kernels, we probably
> need to backport e7273ff49acf as well.
>
> Resubmiting this patch is because that I found coverity is complaining
> the issue this patch fixed, and also I got the traces like below:
> "ipi_raise: target_mask=0001 (machine_suspend)" which actually was
> the TPS of suspend_resume[1] rather than ipi_raise.
>
> [1]
> https://elixir.bootlin.com/linux/latest/source/kernel/power/suspend.c#L80
>
> Signed-off-by: Arnd Bergmann 
> Fixes: e7273ff49acf ("ARM: 8488/1: Make IPI_CPU_BACKTRACE a "non-secure" SGI")
> Fixes: 365ec7b17327 ("ARM: add IPI tracepoints") # v3.17
> Signed-off-by: Chunyan Zhang 
> ---
>  arch/arm/include/asm/hardirq.h | 1 +
>  arch/arm/kernel/smp.c  | 6 +-
>  2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/include/asm/hardirq.h b/arch/arm/include/asm/hardirq.h
> index cba23ea..7a88f16 100644
> --- a/arch/arm/include/asm/hardirq.h
> +++ b/arch/arm/include/asm/hardirq.h
> @@ -6,6 +6,7 @@
>  #include 
>  #include 
>
> +/* number of IPIS _not_ including IPI_CPU_BACKTRACE */
>  #define NR_IPI 7
>
>  typedef struct {
> diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
> index 0978282..123be77 100644
> --- a/arch/arm/kernel/smp.c
> +++ b/arch/arm/kernel/smp.c
> @@ -75,6 +75,10 @@ enum ipi_msg_type {
> IPI_CPU_STOP,
> IPI_IRQ_WORK,
> IPI_COMPLETION,
> +   /*
> +* CPU_BACKTRACE is special and not included in NR_IPI
> +* or tracable with trace_ipi_*
> +*/
> IPI_CPU_BACKTRACE,
> /*
>  * SGI8-15 can be reserved by secure firmware, and thus may
> @@ -755,7 +759,7 @@ core_initcall(register_cpufreq_notifier);
>
>  static void raise_nmi(cpumask_t *mask)
>  {
> -   smp_cross_call(mask, IPI_CPU_BACKTRACE);
> +   _smp_cross_call(mask, IPI_CPU_BACKTRACE);
>  }
>
>  void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)
> --
> 2.7.4
>


Re: [RESEND PATCH] ARM: prevent tracing IPI_CPU_BACKTRACE

2018-10-08 Thread Chunyan Zhang
Hi All,

If there's no comments, should I submit this patch on RMK's Patch system?

Thanks,
Chunyan

On 27 September 2018 at 11:41, Chunyan Zhang  wrote:
> From: Arnd Bergmann 
>
> When function tracing for IPIs is enabled, we get a warning for an
> overflow of the ipi_types array with the IPI_CPU_BACKTRACE type
> as triggered by raise_nmi():
>
> arch/arm/kernel/smp.c: In function 'raise_nmi':
> arch/arm/kernel/smp.c:489:2: error: array subscript is above array bounds 
> [-Werror=array-bounds]
> trace_ipi_raise(target, ipi_types[ipinr]);
>
> This is a correct warning as we actually overflow the array here.
>
> This patch raise_nmi() to call __smp_cross_call() instead of
> smp_cross_call(), to avoid calling into ftrace. For clarification,
> I'm also adding a two new code comments describing how this one
> is special.
>
> The warning appears to have shown up after patch e7273ff49acf
> ("ARM: 8488/1: Make IPI_CPU_BACKTRACE a "non-secure" SGI"), which
> changed the number assignment from '15' to '8', but as far as I can
> tell has existed since the IPI tracepoints were first introduced.
> If we decide to backport this patch to stable kernels, we probably
> need to backport e7273ff49acf as well.
>
> Resubmiting this patch is because that I found coverity is complaining
> the issue this patch fixed, and also I got the traces like below:
> "ipi_raise: target_mask=0001 (machine_suspend)" which actually was
> the TPS of suspend_resume[1] rather than ipi_raise.
>
> [1]
> https://elixir.bootlin.com/linux/latest/source/kernel/power/suspend.c#L80
>
> Signed-off-by: Arnd Bergmann 
> Fixes: e7273ff49acf ("ARM: 8488/1: Make IPI_CPU_BACKTRACE a "non-secure" SGI")
> Fixes: 365ec7b17327 ("ARM: add IPI tracepoints") # v3.17
> Signed-off-by: Chunyan Zhang 
> ---
>  arch/arm/include/asm/hardirq.h | 1 +
>  arch/arm/kernel/smp.c  | 6 +-
>  2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/include/asm/hardirq.h b/arch/arm/include/asm/hardirq.h
> index cba23ea..7a88f16 100644
> --- a/arch/arm/include/asm/hardirq.h
> +++ b/arch/arm/include/asm/hardirq.h
> @@ -6,6 +6,7 @@
>  #include 
>  #include 
>
> +/* number of IPIS _not_ including IPI_CPU_BACKTRACE */
>  #define NR_IPI 7
>
>  typedef struct {
> diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
> index 0978282..123be77 100644
> --- a/arch/arm/kernel/smp.c
> +++ b/arch/arm/kernel/smp.c
> @@ -75,6 +75,10 @@ enum ipi_msg_type {
> IPI_CPU_STOP,
> IPI_IRQ_WORK,
> IPI_COMPLETION,
> +   /*
> +* CPU_BACKTRACE is special and not included in NR_IPI
> +* or tracable with trace_ipi_*
> +*/
> IPI_CPU_BACKTRACE,
> /*
>  * SGI8-15 can be reserved by secure firmware, and thus may
> @@ -755,7 +759,7 @@ core_initcall(register_cpufreq_notifier);
>
>  static void raise_nmi(cpumask_t *mask)
>  {
> -   smp_cross_call(mask, IPI_CPU_BACKTRACE);
> +   _smp_cross_call(mask, IPI_CPU_BACKTRACE);
>  }
>
>  void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)
> --
> 2.7.4
>


[PATCH v8 2/5] Refactor FPU code in signal setup/return procedures

2018-10-08 Thread Alan Kao
FPU-related logic is separated from normal signal handling path in
this patch.  Kernel can easily be configured to exclude those procedures
for no-FPU systems.

Signed-off-by: Alan Kao 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Zong Li 
Cc: Nick Hu 
Reviewed-by: Christoph Hellwig 
---
 arch/riscv/kernel/signal.c | 68 --
 1 file changed, 41 insertions(+), 27 deletions(-)

diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 718d0c9..6a18b98 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -37,45 +37,63 @@ struct rt_sigframe {
struct ucontext uc;
 };
 
-static long restore_d_state(struct pt_regs *regs,
-   struct __riscv_d_ext_state __user *state)
+static long restore_fp_state(struct pt_regs *regs,
+union __riscv_fp_state *sc_fpregs)
 {
long err;
+   struct __riscv_d_ext_state __user *state = _fpregs->d;
+   size_t i;
+
err = __copy_from_user(>thread.fstate, state, sizeof(*state));
-   if (likely(!err))
-   fstate_restore(current, regs);
+   if (unlikely(err))
+   return err;
+
+   fstate_restore(current, regs);
+
+   /* We support no other extension state at this time. */
+   for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
+   u32 value;
+
+   err = __get_user(value, _fpregs->q.reserved[i]);
+   if (unlikely(err))
+   break;
+   if (value != 0)
+   return -EINVAL;
+   }
+
return err;
 }
 
-static long save_d_state(struct pt_regs *regs,
-   struct __riscv_d_ext_state __user *state)
+static long save_fp_state(struct pt_regs *regs,
+ union __riscv_fp_state *sc_fpregs)
 {
+   long err;
+   struct __riscv_d_ext_state __user *state = _fpregs->d;
+   size_t i;
+
fstate_save(current, regs);
-   return __copy_to_user(state, >thread.fstate, sizeof(*state));
+   err = __copy_to_user(state, >thread.fstate, sizeof(*state));
+   if (unlikely(err))
+   return err;
+
+   /* We support no other extension state at this time. */
+   for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
+   err = __put_user(0, _fpregs->q.reserved[i]);
+   if (unlikely(err))
+   break;
+   }
+
+   return err;
 }
 
 static long restore_sigcontext(struct pt_regs *regs,
struct sigcontext __user *sc)
 {
long err;
-   size_t i;
/* sc_regs is structured the same as the start of pt_regs */
err = __copy_from_user(regs, >sc_regs, sizeof(sc->sc_regs));
-   if (unlikely(err))
-   return err;
/* Restore the floating-point state. */
-   err = restore_d_state(regs, >sc_fpregs.d);
-   if (unlikely(err))
-   return err;
-   /* We support no other extension state at this time. */
-   for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++) {
-   u32 value;
-   err = __get_user(value, >sc_fpregs.q.reserved[i]);
-   if (unlikely(err))
-   break;
-   if (value != 0)
-   return -EINVAL;
-   }
+   err |= restore_fp_state(regs, >sc_fpregs);
return err;
 }
 
@@ -124,14 +142,10 @@ static long setup_sigcontext(struct rt_sigframe __user 
*frame,
 {
struct sigcontext __user *sc = >uc.uc_mcontext;
long err;
-   size_t i;
/* sc_regs is structured the same as the start of pt_regs */
err = __copy_to_user(>sc_regs, regs, sizeof(sc->sc_regs));
/* Save the floating-point state. */
-   err |= save_d_state(regs, >sc_fpregs.d);
-   /* We support no other extension state at this time. */
-   for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++)
-   err |= __put_user(0, >sc_fpregs.q.reserved[i]);
+   err |= save_fp_state(regs, >sc_fpregs);
return err;
 }
 
-- 
2.7.4



[PATCH v8 2/5] Refactor FPU code in signal setup/return procedures

2018-10-08 Thread Alan Kao
FPU-related logic is separated from normal signal handling path in
this patch.  Kernel can easily be configured to exclude those procedures
for no-FPU systems.

Signed-off-by: Alan Kao 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Zong Li 
Cc: Nick Hu 
Reviewed-by: Christoph Hellwig 
---
 arch/riscv/kernel/signal.c | 68 --
 1 file changed, 41 insertions(+), 27 deletions(-)

diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 718d0c9..6a18b98 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -37,45 +37,63 @@ struct rt_sigframe {
struct ucontext uc;
 };
 
-static long restore_d_state(struct pt_regs *regs,
-   struct __riscv_d_ext_state __user *state)
+static long restore_fp_state(struct pt_regs *regs,
+union __riscv_fp_state *sc_fpregs)
 {
long err;
+   struct __riscv_d_ext_state __user *state = _fpregs->d;
+   size_t i;
+
err = __copy_from_user(>thread.fstate, state, sizeof(*state));
-   if (likely(!err))
-   fstate_restore(current, regs);
+   if (unlikely(err))
+   return err;
+
+   fstate_restore(current, regs);
+
+   /* We support no other extension state at this time. */
+   for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
+   u32 value;
+
+   err = __get_user(value, _fpregs->q.reserved[i]);
+   if (unlikely(err))
+   break;
+   if (value != 0)
+   return -EINVAL;
+   }
+
return err;
 }
 
-static long save_d_state(struct pt_regs *regs,
-   struct __riscv_d_ext_state __user *state)
+static long save_fp_state(struct pt_regs *regs,
+ union __riscv_fp_state *sc_fpregs)
 {
+   long err;
+   struct __riscv_d_ext_state __user *state = _fpregs->d;
+   size_t i;
+
fstate_save(current, regs);
-   return __copy_to_user(state, >thread.fstate, sizeof(*state));
+   err = __copy_to_user(state, >thread.fstate, sizeof(*state));
+   if (unlikely(err))
+   return err;
+
+   /* We support no other extension state at this time. */
+   for (i = 0; i < ARRAY_SIZE(sc_fpregs->q.reserved); i++) {
+   err = __put_user(0, _fpregs->q.reserved[i]);
+   if (unlikely(err))
+   break;
+   }
+
+   return err;
 }
 
 static long restore_sigcontext(struct pt_regs *regs,
struct sigcontext __user *sc)
 {
long err;
-   size_t i;
/* sc_regs is structured the same as the start of pt_regs */
err = __copy_from_user(regs, >sc_regs, sizeof(sc->sc_regs));
-   if (unlikely(err))
-   return err;
/* Restore the floating-point state. */
-   err = restore_d_state(regs, >sc_fpregs.d);
-   if (unlikely(err))
-   return err;
-   /* We support no other extension state at this time. */
-   for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++) {
-   u32 value;
-   err = __get_user(value, >sc_fpregs.q.reserved[i]);
-   if (unlikely(err))
-   break;
-   if (value != 0)
-   return -EINVAL;
-   }
+   err |= restore_fp_state(regs, >sc_fpregs);
return err;
 }
 
@@ -124,14 +142,10 @@ static long setup_sigcontext(struct rt_sigframe __user 
*frame,
 {
struct sigcontext __user *sc = >uc.uc_mcontext;
long err;
-   size_t i;
/* sc_regs is structured the same as the start of pt_regs */
err = __copy_to_user(>sc_regs, regs, sizeof(sc->sc_regs));
/* Save the floating-point state. */
-   err |= save_d_state(regs, >sc_fpregs.d);
-   /* We support no other extension state at this time. */
-   for (i = 0; i < ARRAY_SIZE(sc->sc_fpregs.q.reserved); i++)
-   err |= __put_user(0, >sc_fpregs.q.reserved[i]);
+   err |= save_fp_state(regs, >sc_fpregs);
return err;
 }
 
-- 
2.7.4



[PATCH v8 0/5] riscv: Add support to no-FPU systems

2018-10-08 Thread Alan Kao
This patchset adds an option, CONFIG_FPU, to enable/disable floating-
point procedures.

Kernel's new behavior will be as follows:

* with CONFIG_FPU=y
  All FPU codes are reserved.  If no FPU is found during booting, a
  global flag will be set, and those functions will be bypassed with
  condition check to that flag.

* with CONFIG_FPU=n
  No floating-point instructions in kernel and all related settings
  are excluded.

Changes in v8:
 - Fix a build fail introduced in v7.

Changes in v7:
 - Remove "fd" attribute from KBUILD_CFLAGS.

Changes in v6 (PATCH 0005 only):
 - Make the flag checking neater.

Changes in v5:
 - Invert the polarity of checking flag from no_fpu to has_fpu.

Changes in v4:
 - Append a new patch to detect existence of FPU and followups.
 - Add SPDX header to newly created fpu.S.
 - Fix a build error, sorry for that.
 - Fix wording, style, etc.

Changes in v3:
 - Refactor the whole patch into independent ones.

Changes in v2:
 - Various code cleanups and style fixes.

Alan Kao (5):
  Extract FPU context operations from entry.S
  Refactor FPU code in signal setup/return procedures
  Cleanup ISA string setting
  Allow to disable FPU support
  Auto-detect whether a FPU exists

 arch/riscv/Kconfig |   9 
 arch/riscv/Makefile|  19 +++
 arch/riscv/include/asm/switch_to.h |  12 -
 arch/riscv/kernel/Makefile |   1 +
 arch/riscv/kernel/cpufeature.c |   8 +++
 arch/riscv/kernel/entry.S  |  87 --
 arch/riscv/kernel/fpu.S| 106 +
 arch/riscv/kernel/process.c|   6 ++-
 arch/riscv/kernel/signal.c |  75 --
 9 files changed, 196 insertions(+), 127 deletions(-)
 create mode 100644 arch/riscv/kernel/fpu.S

-- 
2.7.4



[PATCH v8 4/5] Allow to disable FPU support

2018-10-08 Thread Alan Kao
FPU codes have been separated from common part in previous patches.
This patch add the CONFIG_FPU option and some stubs, so that a no-FPU
configuration is allowed.

Signed-off-by: Alan Kao 
Cc: Greentime Hu 
Cc: Vincent Chen 
Cc: Zong Li 
Cc: Nick Hu 
Reviewed-by: Christoph Hellwig 
---
 arch/riscv/Kconfig |  9 +
 arch/riscv/Makefile|  2 +-
 arch/riscv/include/asm/switch_to.h | 10 ++
 arch/riscv/kernel/Makefile |  2 +-
 arch/riscv/kernel/process.c|  4 +++-
 arch/riscv/kernel/signal.c |  5 +
 6 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index a344980..a63f9db 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -208,6 +208,15 @@ config RISCV_BASE_PMU
 
 endmenu
 
+config FPU
+   bool "FPU support"
+   default y
+   help
+ Say N here if you want to disable all floating-point related procedure
+ in the kernel.
+
+ If you don't know what to do here, say Y.
+
 endmenu
 
 menu "Kernel type"
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 01393e1..901770f 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -44,7 +44,7 @@ KBUILD_CFLAGS += -Wall
 riscv-march-$(CONFIG_ARCH_RV32I)   := rv32im
 riscv-march-$(CONFIG_ARCH_RV64I)   := rv64im
 riscv-march-$(CONFIG_RISCV_ISA_A)  := $(riscv-march-y)a
-riscv-march-y  := $(riscv-march-y)fd
+riscv-march-$(CONFIG_FPU)  := $(riscv-march-y)fd
 riscv-march-$(CONFIG_RISCV_ISA_C)  := $(riscv-march-y)c
 KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
 KBUILD_AFLAGS += -march=$(riscv-march-y)
diff --git a/arch/riscv/include/asm/switch_to.h 
b/arch/riscv/include/asm/switch_to.h
index dd6b05b..093050b 100644
--- a/arch/riscv/include/asm/switch_to.h
+++ b/arch/riscv/include/asm/switch_to.h
@@ -18,6 +18,7 @@
 #include 
 #include 
 
+#ifdef CONFIG_FPU
 extern void __fstate_save(struct task_struct *save_to);
 extern void __fstate_restore(struct task_struct *restore_from);
 
@@ -55,6 +56,15 @@ static inline void __switch_to_aux(struct task_struct *prev,
fstate_restore(next, task_pt_regs(next));
 }
 
+#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_INITIAL)
+
+#else
+#define fstate_save(task, regs) do { } while (0)
+#define fstate_restore(task, regs) do { } while (0)
+#define __switch_to_aux(__prev, __next) do { } while (0)
+#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_OFF)
+#endif
+
 extern struct task_struct *__switch_to(struct task_struct *,
   struct task_struct *);
 
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index bd433efd..f13f7f2 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -13,7 +13,6 @@ extra-y += vmlinux.lds
 obj-y  += cpu.o
 obj-y  += cpufeature.o
 obj-y  += entry.o
-obj-y  += fpu.o
 obj-y  += irq.o
 obj-y  += process.o
 obj-y  += ptrace.o
@@ -32,6 +31,7 @@ obj-y += vdso/
 
 CFLAGS_setup.o := -mcmodel=medany
 
+obj-$(CONFIG_FPU)  += fpu.o
 obj-$(CONFIG_SMP)  += smpboot.o
 obj-$(CONFIG_SMP)  += smp.o
 obj-$(CONFIG_MODULES)  += module.o
diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index d7c6ca7..07d5156 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -76,7 +76,7 @@ void show_regs(struct pt_regs *regs)
 void start_thread(struct pt_regs *regs, unsigned long pc,
unsigned long sp)
 {
-   regs->sstatus = SR_SPIE /* User mode, irqs on */ | SR_FS_INITIAL;
+   regs->sstatus = DEFAULT_SSTATUS;
regs->sepc = pc;
regs->sp = sp;
set_fs(USER_DS);
@@ -84,12 +84,14 @@ void start_thread(struct pt_regs *regs, unsigned long pc,
 
 void flush_thread(void)
 {
+#ifdef CONFIG_FPU
/*
 * Reset FPU context
 *  frm: round to nearest, ties to even (IEEE default)
 *  fflags: accrued exceptions cleared
 */
memset(>thread.fstate, 0, sizeof(current->thread.fstate));
+#endif
 }
 
 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 6a18b98..2450b82 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -37,6 +37,7 @@ struct rt_sigframe {
struct ucontext uc;
 };
 
+#ifdef CONFIG_FPU
 static long restore_fp_state(struct pt_regs *regs,
 union __riscv_fp_state *sc_fpregs)
 {
@@ -85,6 +86,10 @@ static long save_fp_state(struct pt_regs *regs,
 
return err;
 }
+#else
+#define save_fp_state(task, regs) (0)
+#define restore_fp_state(task, regs) (0)
+#endif
 
 static long restore_sigcontext(struct pt_regs *regs,
struct sigcontext __user *sc)
-- 
2.7.4



  1   2   3   4   5   6   7   8   9   10   >