[PATCH AUTOSEL 4.4 2/6] sparc: Throttle perf events properly.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit 455adb3174d2c8518cef1a61140c211f6ac224d2 ]

Like x86 and arm, call perf_sample_event_took() in perf event
NMI interrupt handler.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index a5d0c2f08110..dd02219bcc35 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1611,6 +1612,8 @@ static int __kprobes perf_event_nmi_handler(struct 
notifier_block *self,
struct perf_sample_data data;
struct cpu_hw_events *cpuc;
struct pt_regs *regs;
+   u64 finish_clock;
+   u64 start_clock;
int i;
 
if (!atomic_read(_events))
@@ -1624,6 +1627,8 @@ static int __kprobes perf_event_nmi_handler(struct 
notifier_block *self,
return NOTIFY_DONE;
}
 
+   start_clock = sched_clock();
+
regs = args->regs;
 
cpuc = this_cpu_ptr(_hw_events);
@@ -1662,6 +1667,10 @@ static int __kprobes perf_event_nmi_handler(struct 
notifier_block *self,
sparc_pmu_stop(event, 0);
}
 
+   finish_clock = sched_clock();
+
+   perf_sample_event_took(finish_clock - start_clock);
+
return NOTIFY_STOP;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.4 1/6] sparc: Fix single-pcr perf event counter management.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit cfdc3170d214046b9509183fe9b9544dc644d40b ]

It is important to clear the hw->state value for non-stopped events
when they are added into the PMU.  Otherwise when the event is
scheduled out, we won't read the counter because HES_UPTODATE is still
set.  This breaks 'perf stat' and similar use cases, causing all the
events to show zero.

This worked for multi-pcr because we make explicit sparc_pmu_start()
calls in calculate_multiple_pcrs().  calculate_single_pcr() doesn't do
this because the idea there is to accumulate all of the counter
settings into the single pcr value.  So we have to add explicit
hw->state handling there.

Like x86, we use the PERF_HES_ARCH bit to track truly stopped events
so that we don't accidently start them on a reload.

Related to all of this, sparc_pmu_start() is missing a userpage update
so add it.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index 6596f66ce112..a5d0c2f08110 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -926,6 +926,8 @@ static void read_in_all_counters(struct cpu_hw_events *cpuc)
sparc_perf_event_update(cp, >hw,
cpuc->current_idx[i]);
cpuc->current_idx[i] = PIC_NO_INDEX;
+   if (cp->hw.state & PERF_HES_STOPPED)
+   cp->hw.state |= PERF_HES_ARCH;
}
}
 }
@@ -958,10 +960,12 @@ static void calculate_single_pcr(struct cpu_hw_events 
*cpuc)
 
enc = perf_event_get_enc(cpuc->events[i]);
cpuc->pcr[0] &= ~mask_for_index(idx);
-   if (hwc->state & PERF_HES_STOPPED)
+   if (hwc->state & PERF_HES_ARCH) {
cpuc->pcr[0] |= nop_for_index(idx);
-   else
+   } else {
cpuc->pcr[0] |= event_encoding(enc, idx);
+   hwc->state = 0;
+   }
}
 out:
cpuc->pcr[0] |= cpuc->event[0]->hw.config_base;
@@ -987,6 +991,9 @@ static void calculate_multiple_pcrs(struct cpu_hw_events 
*cpuc)
 
cpuc->current_idx[i] = idx;
 
+   if (cp->hw.state & PERF_HES_ARCH)
+   continue;
+
sparc_pmu_start(cp, PERF_EF_RELOAD);
}
 out:
@@ -1078,6 +1085,8 @@ static void sparc_pmu_start(struct perf_event *event, int 
flags)
event->hw.state = 0;
 
sparc_pmu_enable_event(cpuc, >hw, idx);
+
+   perf_event_update_userpage(event);
 }
 
 static void sparc_pmu_stop(struct perf_event *event, int flags)
@@ -1370,9 +1379,9 @@ static int sparc_pmu_add(struct perf_event *event, int 
ef_flags)
cpuc->events[n0] = event->hw.event_base;
cpuc->current_idx[n0] = PIC_NO_INDEX;
 
-   event->hw.state = PERF_HES_UPTODATE;
+   event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
if (!(ef_flags & PERF_EF_START))
-   event->hw.state |= PERF_HES_STOPPED;
+   event->hw.state |= PERF_HES_ARCH;
 
/*
 * If group events scheduling transaction was started,
-- 
2.17.1



[PATCH AUTOSEL 4.9 13/13] i2c: rcar: cleanup DMA for all kinds of failure

2018-10-30 Thread Sasha Levin
From: Wolfram Sang 

[ Upstream commit 31d86033a0749a0463ea654130b2de5c163154f1 ]

DMA needs to be cleaned up not only on timeout, but on all errors where
it has been setup before.

Fixes: 73e8b0528346 ("i2c: rcar: add DMA support")
Signed-off-by: Wolfram Sang 
Signed-off-by: Wolfram Sang 
Signed-off-by: Sasha Levin 
---
 drivers/i2c/busses/i2c-rcar.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index c7592fe30e6e..93b8069041bb 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -723,8 +723,12 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
 
time_left = wait_event_timeout(priv->wait, priv->flags & ID_DONE,
 num * adap->timeout);
-   if (!time_left) {
+
+   /* cleanup DMA if it couldn't complete properly due to an error */
+   if (priv->dma_direction != DMA_NONE)
rcar_i2c_cleanup_dma(priv);
+
+   if (!time_left) {
rcar_i2c_init(priv);
ret = -ETIMEDOUT;
} else if (priv->flags & ID_NACK) {
-- 
2.17.1



[PATCH AUTOSEL 4.9 10/13] r8169: fix NAPI handling under high load

2018-10-30 Thread Sasha Levin
From: Heiner Kallweit 

[ Upstream commit 6b839b6cf9eada30b086effb51e5d6076bafc761 ]

rtl_rx() and rtl_tx() are called only if the respective bits are set
in the interrupt status register. Under high load NAPI may not be
able to process all data (work_done == budget) and it will schedule
subsequent calls to the poll callback.
rtl_ack_events() however resets the bits in the interrupt status
register, therefore subsequent calls to rtl8169_poll() won't call
rtl_rx() and rtl_tx() - chip interrupts are still disabled.

Fix this by calling rtl_rx() and rtl_tx() independent of the bits
set in the interrupt status register. Both functions will detect
if there's nothing to do for them.

Fixes: da78dbff2e05 ("r8169: remove work from irq handler.")
Signed-off-by: Heiner Kallweit 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/realtek/r8169.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index 20f5c0cabc89..24754d3fb0ac 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7559,17 +7559,15 @@ static int rtl8169_poll(struct napi_struct *napi, int 
budget)
struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, 
napi);
struct net_device *dev = tp->dev;
u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow;
-   int work_done= 0;
+   int work_done;
u16 status;
 
status = rtl_get_events(tp);
rtl_ack_events(tp, status & ~tp->event_slow);
 
-   if (status & RTL_EVENT_NAPI_RX)
-   work_done = rtl_rx(dev, tp, (u32) budget);
+   work_done = rtl_rx(dev, tp, (u32) budget);
 
-   if (status & RTL_EVENT_NAPI_TX)
-   rtl_tx(dev, tp);
+   rtl_tx(dev, tp);
 
if (status & tp->event_slow) {
enable_mask &= ~tp->event_slow;
-- 
2.17.1



[PATCH AUTOSEL 4.9 13/13] i2c: rcar: cleanup DMA for all kinds of failure

2018-10-30 Thread Sasha Levin
From: Wolfram Sang 

[ Upstream commit 31d86033a0749a0463ea654130b2de5c163154f1 ]

DMA needs to be cleaned up not only on timeout, but on all errors where
it has been setup before.

Fixes: 73e8b0528346 ("i2c: rcar: add DMA support")
Signed-off-by: Wolfram Sang 
Signed-off-by: Wolfram Sang 
Signed-off-by: Sasha Levin 
---
 drivers/i2c/busses/i2c-rcar.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index c7592fe30e6e..93b8069041bb 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -723,8 +723,12 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
 
time_left = wait_event_timeout(priv->wait, priv->flags & ID_DONE,
 num * adap->timeout);
-   if (!time_left) {
+
+   /* cleanup DMA if it couldn't complete properly due to an error */
+   if (priv->dma_direction != DMA_NONE)
rcar_i2c_cleanup_dma(priv);
+
+   if (!time_left) {
rcar_i2c_init(priv);
ret = -ETIMEDOUT;
} else if (priv->flags & ID_NACK) {
-- 
2.17.1



[PATCH AUTOSEL 4.9 10/13] r8169: fix NAPI handling under high load

2018-10-30 Thread Sasha Levin
From: Heiner Kallweit 

[ Upstream commit 6b839b6cf9eada30b086effb51e5d6076bafc761 ]

rtl_rx() and rtl_tx() are called only if the respective bits are set
in the interrupt status register. Under high load NAPI may not be
able to process all data (work_done == budget) and it will schedule
subsequent calls to the poll callback.
rtl_ack_events() however resets the bits in the interrupt status
register, therefore subsequent calls to rtl8169_poll() won't call
rtl_rx() and rtl_tx() - chip interrupts are still disabled.

Fix this by calling rtl_rx() and rtl_tx() independent of the bits
set in the interrupt status register. Both functions will detect
if there's nothing to do for them.

Fixes: da78dbff2e05 ("r8169: remove work from irq handler.")
Signed-off-by: Heiner Kallweit 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/realtek/r8169.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index 20f5c0cabc89..24754d3fb0ac 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7559,17 +7559,15 @@ static int rtl8169_poll(struct napi_struct *napi, int 
budget)
struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, 
napi);
struct net_device *dev = tp->dev;
u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow;
-   int work_done= 0;
+   int work_done;
u16 status;
 
status = rtl_get_events(tp);
rtl_ack_events(tp, status & ~tp->event_slow);
 
-   if (status & RTL_EVENT_NAPI_RX)
-   work_done = rtl_rx(dev, tp, (u32) budget);
+   work_done = rtl_rx(dev, tp, (u32) budget);
 
-   if (status & RTL_EVENT_NAPI_TX)
-   rtl_tx(dev, tp);
+   rtl_tx(dev, tp);
 
if (status & tp->event_slow) {
enable_mask &= ~tp->event_slow;
-- 
2.17.1



[PATCH AUTOSEL 4.9 04/13] sparc: Fix single-pcr perf event counter management.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit cfdc3170d214046b9509183fe9b9544dc644d40b ]

It is important to clear the hw->state value for non-stopped events
when they are added into the PMU.  Otherwise when the event is
scheduled out, we won't read the counter because HES_UPTODATE is still
set.  This breaks 'perf stat' and similar use cases, causing all the
events to show zero.

This worked for multi-pcr because we make explicit sparc_pmu_start()
calls in calculate_multiple_pcrs().  calculate_single_pcr() doesn't do
this because the idea there is to accumulate all of the counter
settings into the single pcr value.  So we have to add explicit
hw->state handling there.

Like x86, we use the PERF_HES_ARCH bit to track truly stopped events
so that we don't accidently start them on a reload.

Related to all of this, sparc_pmu_start() is missing a userpage update
so add it.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index 710f3278d448..71e7f77f6776 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -926,6 +926,8 @@ static void read_in_all_counters(struct cpu_hw_events *cpuc)
sparc_perf_event_update(cp, >hw,
cpuc->current_idx[i]);
cpuc->current_idx[i] = PIC_NO_INDEX;
+   if (cp->hw.state & PERF_HES_STOPPED)
+   cp->hw.state |= PERF_HES_ARCH;
}
}
 }
@@ -958,10 +960,12 @@ static void calculate_single_pcr(struct cpu_hw_events 
*cpuc)
 
enc = perf_event_get_enc(cpuc->events[i]);
cpuc->pcr[0] &= ~mask_for_index(idx);
-   if (hwc->state & PERF_HES_STOPPED)
+   if (hwc->state & PERF_HES_ARCH) {
cpuc->pcr[0] |= nop_for_index(idx);
-   else
+   } else {
cpuc->pcr[0] |= event_encoding(enc, idx);
+   hwc->state = 0;
+   }
}
 out:
cpuc->pcr[0] |= cpuc->event[0]->hw.config_base;
@@ -987,6 +991,9 @@ static void calculate_multiple_pcrs(struct cpu_hw_events 
*cpuc)
 
cpuc->current_idx[i] = idx;
 
+   if (cp->hw.state & PERF_HES_ARCH)
+   continue;
+
sparc_pmu_start(cp, PERF_EF_RELOAD);
}
 out:
@@ -1078,6 +1085,8 @@ static void sparc_pmu_start(struct perf_event *event, int 
flags)
event->hw.state = 0;
 
sparc_pmu_enable_event(cpuc, >hw, idx);
+
+   perf_event_update_userpage(event);
 }
 
 static void sparc_pmu_stop(struct perf_event *event, int flags)
@@ -1370,9 +1379,9 @@ static int sparc_pmu_add(struct perf_event *event, int 
ef_flags)
cpuc->events[n0] = event->hw.event_base;
cpuc->current_idx[n0] = PIC_NO_INDEX;
 
-   event->hw.state = PERF_HES_UPTODATE;
+   event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
if (!(ef_flags & PERF_EF_START))
-   event->hw.state |= PERF_HES_STOPPED;
+   event->hw.state |= PERF_HES_ARCH;
 
/*
 * If group events scheduling transaction was started,
-- 
2.17.1



[PATCH AUTOSEL 4.9 09/13] net: qla3xxx: Remove overflowing shift statement

2018-10-30 Thread Sasha Levin
From: Nathan Chancellor 

[ Upstream commit 8c3bf9b62b667456a57aefcf1689e826df146159 ]

Clang currently warns:

drivers/net/ethernet/qlogic/qla3xxx.c:384:24: warning: signed shift
result (0xF) requires 37 bits to represent, but 'int' only has
32 bits [-Wshift-overflow]
((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
  ~~ ^  ~~
1 warning generated.

The warning is certainly accurate since ISP_NVRAM_MASK is defined as
(0x000F << 16) which is then shifted by 16, resulting in 64424509440,
well above UINT_MAX.

Given that this is the only location in this driver where ISP_NVRAM_MASK
is shifted again, it seems likely that ISP_NVRAM_MASK was originally
defined without a shift and during the move of the shift to the
definition, this statement wasn't properly removed (since ISP_NVRAM_MASK
is used in the statenent right above this). Only the maintainers can
confirm this since this statment has been here since the driver was
first added to the kernel.

Link: https://github.com/ClangBuiltLinux/linux/issues/127
Signed-off-by: Nathan Chancellor 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/qlogic/qla3xxx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c 
b/drivers/net/ethernet/qlogic/qla3xxx.c
index b09a6b80d107..355c5fb802cd 100644
--- a/drivers/net/ethernet/qlogic/qla3xxx.c
+++ b/drivers/net/ethernet/qlogic/qla3xxx.c
@@ -380,8 +380,6 @@ static void fm93c56a_select(struct ql3_adapter *qdev)
 
qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_1;
ql_write_nvram_reg(qdev, spir, ISP_NVRAM_MASK | qdev->eeprom_cmd_data);
-   ql_write_nvram_reg(qdev, spir,
-  ((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.9 05/13] sparc64: Make proc_id signed.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit b3e1eb8e7ac9aaa283989496651d99267c4cad6c ]

So that when it is unset, ie. '-1', userspace can see it
properly.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/include/asm/cpudata_64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/include/asm/cpudata_64.h 
b/arch/sparc/include/asm/cpudata_64.h
index 5b0ed48e5b0c..aa2bf904b582 100644
--- a/arch/sparc/include/asm/cpudata_64.h
+++ b/arch/sparc/include/asm/cpudata_64.h
@@ -27,7 +27,7 @@ typedef struct {
unsigned short  sock_id;/* physical package */
unsigned short  core_id;
unsigned short  max_cache_id;   /* groupings of highest shared cache */
-   unsigned short  proc_id;/* strand (aka HW thread) id */
+   signed shortproc_id;/* strand (aka HW thread) id */
 } cpuinfo_sparc;
 
 DECLARE_PER_CPU(cpuinfo_sparc, __cpu_data);
-- 
2.17.1



[PATCH AUTOSEL 4.9 06/13] sched/fair: Fix the min_vruntime update logic in dequeue_entity()

2018-10-30 Thread Sasha Levin
From: Song Muchun 

[ Upstream commit 9845c49cc9bbb317a0bc9e9cf78d8e09d54c9af0 ]

The comment and the code around the update_min_vruntime() call in
dequeue_entity() are not in agreement.

>From commit:

  b60205c7c558 ("sched/fair: Fix min_vruntime tracking")

I think that we want to update min_vruntime when a task is sleeping/migrating.
So, the check is inverted there - fix it.

Signed-off-by: Song Muchun 
Cc: Linus Torvalds 
Cc: Mike Galbraith 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: b60205c7c558 ("sched/fair: Fix min_vruntime tracking")
Link: http://lkml.kernel.org/r/20181014112612.2614-1-smuc...@gmail.com
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index f81adb476c03..dfec7d4789fa 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3502,7 +3502,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity 
*se, int flags)
 * put back on, and if we advance min_vruntime, we'll be placed back
 * further than we started -- ie. we'll be penalized.
 */
-   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) == DEQUEUE_SAVE)
+   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) != DEQUEUE_SAVE)
update_min_vruntime(cfs_rq);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 09/13] net: qla3xxx: Remove overflowing shift statement

2018-10-30 Thread Sasha Levin
From: Nathan Chancellor 

[ Upstream commit 8c3bf9b62b667456a57aefcf1689e826df146159 ]

Clang currently warns:

drivers/net/ethernet/qlogic/qla3xxx.c:384:24: warning: signed shift
result (0xF) requires 37 bits to represent, but 'int' only has
32 bits [-Wshift-overflow]
((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
  ~~ ^  ~~
1 warning generated.

The warning is certainly accurate since ISP_NVRAM_MASK is defined as
(0x000F << 16) which is then shifted by 16, resulting in 64424509440,
well above UINT_MAX.

Given that this is the only location in this driver where ISP_NVRAM_MASK
is shifted again, it seems likely that ISP_NVRAM_MASK was originally
defined without a shift and during the move of the shift to the
definition, this statement wasn't properly removed (since ISP_NVRAM_MASK
is used in the statenent right above this). Only the maintainers can
confirm this since this statment has been here since the driver was
first added to the kernel.

Link: https://github.com/ClangBuiltLinux/linux/issues/127
Signed-off-by: Nathan Chancellor 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/qlogic/qla3xxx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c 
b/drivers/net/ethernet/qlogic/qla3xxx.c
index b09a6b80d107..355c5fb802cd 100644
--- a/drivers/net/ethernet/qlogic/qla3xxx.c
+++ b/drivers/net/ethernet/qlogic/qla3xxx.c
@@ -380,8 +380,6 @@ static void fm93c56a_select(struct ql3_adapter *qdev)
 
qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_1;
ql_write_nvram_reg(qdev, spir, ISP_NVRAM_MASK | qdev->eeprom_cmd_data);
-   ql_write_nvram_reg(qdev, spir,
-  ((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.9 05/13] sparc64: Make proc_id signed.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit b3e1eb8e7ac9aaa283989496651d99267c4cad6c ]

So that when it is unset, ie. '-1', userspace can see it
properly.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/include/asm/cpudata_64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/include/asm/cpudata_64.h 
b/arch/sparc/include/asm/cpudata_64.h
index 5b0ed48e5b0c..aa2bf904b582 100644
--- a/arch/sparc/include/asm/cpudata_64.h
+++ b/arch/sparc/include/asm/cpudata_64.h
@@ -27,7 +27,7 @@ typedef struct {
unsigned short  sock_id;/* physical package */
unsigned short  core_id;
unsigned short  max_cache_id;   /* groupings of highest shared cache */
-   unsigned short  proc_id;/* strand (aka HW thread) id */
+   signed shortproc_id;/* strand (aka HW thread) id */
 } cpuinfo_sparc;
 
 DECLARE_PER_CPU(cpuinfo_sparc, __cpu_data);
-- 
2.17.1



[PATCH AUTOSEL 4.9 06/13] sched/fair: Fix the min_vruntime update logic in dequeue_entity()

2018-10-30 Thread Sasha Levin
From: Song Muchun 

[ Upstream commit 9845c49cc9bbb317a0bc9e9cf78d8e09d54c9af0 ]

The comment and the code around the update_min_vruntime() call in
dequeue_entity() are not in agreement.

>From commit:

  b60205c7c558 ("sched/fair: Fix min_vruntime tracking")

I think that we want to update min_vruntime when a task is sleeping/migrating.
So, the check is inverted there - fix it.

Signed-off-by: Song Muchun 
Cc: Linus Torvalds 
Cc: Mike Galbraith 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: b60205c7c558 ("sched/fair: Fix min_vruntime tracking")
Link: http://lkml.kernel.org/r/20181014112612.2614-1-smuc...@gmail.com
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index f81adb476c03..dfec7d4789fa 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3502,7 +3502,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity 
*se, int flags)
 * put back on, and if we advance min_vruntime, we'll be placed back
 * further than we started -- ie. we'll be penalized.
 */
-   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) == DEQUEUE_SAVE)
+   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) != DEQUEUE_SAVE)
update_min_vruntime(cfs_rq);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 04/13] sparc: Fix single-pcr perf event counter management.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit cfdc3170d214046b9509183fe9b9544dc644d40b ]

It is important to clear the hw->state value for non-stopped events
when they are added into the PMU.  Otherwise when the event is
scheduled out, we won't read the counter because HES_UPTODATE is still
set.  This breaks 'perf stat' and similar use cases, causing all the
events to show zero.

This worked for multi-pcr because we make explicit sparc_pmu_start()
calls in calculate_multiple_pcrs().  calculate_single_pcr() doesn't do
this because the idea there is to accumulate all of the counter
settings into the single pcr value.  So we have to add explicit
hw->state handling there.

Like x86, we use the PERF_HES_ARCH bit to track truly stopped events
so that we don't accidently start them on a reload.

Related to all of this, sparc_pmu_start() is missing a userpage update
so add it.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index 710f3278d448..71e7f77f6776 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -926,6 +926,8 @@ static void read_in_all_counters(struct cpu_hw_events *cpuc)
sparc_perf_event_update(cp, >hw,
cpuc->current_idx[i]);
cpuc->current_idx[i] = PIC_NO_INDEX;
+   if (cp->hw.state & PERF_HES_STOPPED)
+   cp->hw.state |= PERF_HES_ARCH;
}
}
 }
@@ -958,10 +960,12 @@ static void calculate_single_pcr(struct cpu_hw_events 
*cpuc)
 
enc = perf_event_get_enc(cpuc->events[i]);
cpuc->pcr[0] &= ~mask_for_index(idx);
-   if (hwc->state & PERF_HES_STOPPED)
+   if (hwc->state & PERF_HES_ARCH) {
cpuc->pcr[0] |= nop_for_index(idx);
-   else
+   } else {
cpuc->pcr[0] |= event_encoding(enc, idx);
+   hwc->state = 0;
+   }
}
 out:
cpuc->pcr[0] |= cpuc->event[0]->hw.config_base;
@@ -987,6 +991,9 @@ static void calculate_multiple_pcrs(struct cpu_hw_events 
*cpuc)
 
cpuc->current_idx[i] = idx;
 
+   if (cp->hw.state & PERF_HES_ARCH)
+   continue;
+
sparc_pmu_start(cp, PERF_EF_RELOAD);
}
 out:
@@ -1078,6 +1085,8 @@ static void sparc_pmu_start(struct perf_event *event, int 
flags)
event->hw.state = 0;
 
sparc_pmu_enable_event(cpuc, >hw, idx);
+
+   perf_event_update_userpage(event);
 }
 
 static void sparc_pmu_stop(struct perf_event *event, int flags)
@@ -1370,9 +1379,9 @@ static int sparc_pmu_add(struct perf_event *event, int 
ef_flags)
cpuc->events[n0] = event->hw.event_base;
cpuc->current_idx[n0] = PIC_NO_INDEX;
 
-   event->hw.state = PERF_HES_UPTODATE;
+   event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
if (!(ef_flags & PERF_EF_START))
-   event->hw.state |= PERF_HES_STOPPED;
+   event->hw.state |= PERF_HES_ARCH;
 
/*
 * If group events scheduling transaction was started,
-- 
2.17.1



[PATCH AUTOSEL 4.9 03/13] xfrm: policy: use hlist rcu variants on insert

2018-10-30 Thread Sasha Levin
From: Florian Westphal 

[ Upstream commit 9d200fd178f11dd50eb1fd8ccd0650c9284e ]

bydst table/list lookups use rcu, so insertions must use rcu versions.

Fixes: a7c44247f704e ("xfrm: policy: make xfrm_policy_lookup_bytype lockless")
Signed-off-by: Florian Westphal 
Signed-off-by: Steffen Klassert 
Signed-off-by: Sasha Levin 
---
 net/xfrm/xfrm_policy.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index d0dcfc68c043..155b1591b17a 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -659,9 +659,9 @@ static void xfrm_hash_rebuild(struct work_struct *work)
break;
}
if (newpos)
-   hlist_add_behind(>bydst, newpos);
+   hlist_add_behind_rcu(>bydst, newpos);
else
-   hlist_add_head(>bydst, chain);
+   hlist_add_head_rcu(>bydst, chain);
}
 
spin_unlock_bh(>xfrm.xfrm_policy_lock);
@@ -800,9 +800,9 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, 
int excl)
break;
}
if (newpos)
-   hlist_add_behind(>bydst, newpos);
+   hlist_add_behind_rcu(>bydst, newpos);
else
-   hlist_add_head(>bydst, chain);
+   hlist_add_head_rcu(>bydst, chain);
__xfrm_policy_link(policy, dir);
atomic_inc(>xfrm.flow_cache_genid);
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 12/13] net: fix pskb_trim_rcsum_slow() with odd trim offset

2018-10-30 Thread Sasha Levin
From: Dimitris Michailidis 

[ Upstream commit d55bef5059dd057bd077155375c581b49d25be7e ]

We've been getting checksum errors involving small UDP packets, usually
59B packets with 1 extra non-zero padding byte. netdev_rx_csum_fault()
has been complaining that HW is providing bad checksums. Turns out the
problem is in pskb_trim_rcsum_slow(), introduced in commit 88078d98d1bb
("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends").

The source of the problem is that when the bytes we are trimming start
at an odd address, as in the case of the 1 padding byte above,
skb_checksum() returns a byte-swapped value. We cannot just combine this
with skb->csum using csum_sub(). We need to use csum_block_sub() here
that takes into account the parity of the start address and handles the
swapping.

Matches existing code in __skb_postpull_rcsum() and esp_remove_trailer().

Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends")
Signed-off-by: Dimitris Michailidis 
Reviewed-by: Eric Dumazet 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 net/core/skbuff.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 038ec74fa131..68ecb7d71c2b 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1585,8 +1585,9 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned 
int len)
if (skb->ip_summed == CHECKSUM_COMPLETE) {
int delta = skb->len - len;
 
-   skb->csum = csum_sub(skb->csum,
-skb_checksum(skb, len, delta, 0));
+   skb->csum = csum_block_sub(skb->csum,
+  skb_checksum(skb, len, delta, 0),
+  len);
}
return __pskb_trim(skb, len);
 }
-- 
2.17.1



[PATCH AUTOSEL 4.9 07/13] perf cpu_map: Align cpu map synthesized events properly.

2018-10-30 Thread Sasha Levin
From: David Miller 

[ Upstream commit 0ed149cf5239cc6e7e65bf00f769e8f1e91076c0 ]

The size of the resulting cpu map can be smaller than a multiple of
sizeof(u64), resulting in SIGBUS on cpus like Sparc as the next event
will not be aligned properly.

Signed-off-by: David S. Miller 
Cc: Jiri Olsa 
Cc: Kan Liang 
Fixes: 6c872901af07 ("perf cpu_map: Add cpu_map event synthesize function")
Link: 
http://lkml.kernel.org/r/20181011.224655.716771175766946817.da...@davemloft.net
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/event.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 663192395780..2d5744d986f0 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -839,6 +839,7 @@ void *cpu_map_data__alloc(struct cpu_map *map, size_t 
*size, u16 *type, int *max
}
 
*size += sizeof(struct cpu_map_data);
+   *size = PERF_ALIGN(*size, sizeof(u64));
return zalloc(*size);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 01/13] bpf: do not blindly change rlimit in reuseport net selftest

2018-10-30 Thread Sasha Levin
From: Eric Dumazet 

[ Upstream commit 262f9d811c7608f1e74258ceecfe1fa213bdf912 ]

If the current process has unlimited RLIMIT_MEMLOCK,
we should should leave it as is.

Fixes: 941ff6f11c02 ("bpf: fix rlimit in reuseport net selftest")
Signed-off-by: John Sperbeck 
Signed-off-by: Eric Dumazet 
Acked-by: Daniel Borkmann 
Signed-off-by: Daniel Borkmann 
Signed-off-by: Sasha Levin 
---
 tools/testing/selftests/net/reuseport_bpf.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/reuseport_bpf.c 
b/tools/testing/selftests/net/reuseport_bpf.c
index cad14cd0ea92..b5277106df1f 100644
--- a/tools/testing/selftests/net/reuseport_bpf.c
+++ b/tools/testing/selftests/net/reuseport_bpf.c
@@ -437,14 +437,19 @@ void enable_fastopen(void)
}
 }
 
-static struct rlimit rlim_old, rlim_new;
+static struct rlimit rlim_old;
 
 static  __attribute__((constructor)) void main_ctor(void)
 {
getrlimit(RLIMIT_MEMLOCK, _old);
-   rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
-   rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
-   setrlimit(RLIMIT_MEMLOCK, _new);
+
+   if (rlim_old.rlim_cur != RLIM_INFINITY) {
+   struct rlimit rlim_new;
+
+   rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
+   rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
+   setrlimit(RLIMIT_MEMLOCK, _new);
+   }
 }
 
 static __attribute__((destructor)) void main_dtor(void)
-- 
2.17.1



[PATCH AUTOSEL 4.9 08/13] x86/fpu: Remove second definition of fpu in __fpu__restore_sig()

2018-10-30 Thread Sasha Levin
From: Sebastian Andrzej Siewior 

[ Upstream commit 6aa676761d4c1acfa31320e55fa1f83f3fcbbc7a ]

Commit:

  c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")

introduced the 'fpu' variable at top of __restore_xstate_sig(),
which now shadows the other definition:

  arch/x86/kernel/fpu/signal.c:318:28: warning: symbol 'fpu' shadows an earlier 
one
  arch/x86/kernel/fpu/signal.c:271:20: originally declared here

Remove the shadowed definition of 'fpu', as the two definitions are the same.

Signed-off-by: Sebastian Andrzej Siewior 
Reviewed-by: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Dave Hansen 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")
Link: http://lkml.kernel.org/r/20181016202525.29437-3-bige...@linutronix.de
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 arch/x86/kernel/fpu/signal.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c
index 3a9318610c4d..ae52ef05d098 100644
--- a/arch/x86/kernel/fpu/signal.c
+++ b/arch/x86/kernel/fpu/signal.c
@@ -309,7 +309,6 @@ static int __fpu__restore_sig(void __user *buf, void __user 
*buf_fx, int size)
 * thread's fpu state, reconstruct fxstate from the fsave
 * header. Sanitize the copied state etc.
 */
-   struct fpu *fpu = >thread.fpu;
struct user_i387_ia32_struct env;
int err = 0;
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 02/13] Revert "perf tools: Fix PMU term format max value calculation"

2018-10-30 Thread Sasha Levin
From: Jiri Olsa 

[ Upstream commit 1b9caa10b31dda0866f4028e4bfb923fb6e4072f ]

This reverts commit ac0e2cd555373ae6f8f3a3ad3fbbf5b6d1e7.

Michael reported an issue with oversized terms values assignment
and I noticed there was actually a misunderstanding of the max
value check in the past.

The above commit's changelog says:

  If bit 21 is set, there is parsing issues as below.

$ perf stat -a -e uncore_qpi_0/event=0x22,umask=0x8/
event syntax error: '..pi_0/event=0x22,umask=0x8/'
  \___ value too big for format, maximum is 
511

But there's no issue there, because the event value is distributed
along the value defined by the format. Even if the format defines
separated bit, the value is treated as a continual number, which
should follow the format definition.

In above case it's 9-bit value with last bit separated:
  $ cat uncore_qpi_0/format/event
  config:0-7,21

Hence the value 0x22 is correctly reported as format violation,
because it exceeds 9 bits. It should have been 0x102 instead, which
sets the 9th bit - the bit 21 of the format.

  $ perf stat -vv -a -e uncore_qpi_0/event=0x102,umask=0x8/
  Using CPUID GenuineIntel-6-2D
  ...
  
  perf_event_attr:
type 10
size 112
config   0x200802
sample_type  IDENTIFIER
  ...

Reported-by: Michael Petlan 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Andi Kleen 
Cc: Kan Liang 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Fixes: ac0e2cd55537 ("perf tools: Fix PMU term format max value calculation")
Link: http://lkml.kernel.org/r/20181003072046.29276-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/pmu.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index b1474dcadfa2..0f84371d4d6b 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -685,13 +685,14 @@ static void pmu_format_value(unsigned long *format, __u64 
value, __u64 *v,
 
 static __u64 pmu_format_max_value(const unsigned long *format)
 {
-   __u64 w = 0;
-   int fbit;
-
-   for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
-   w |= (1ULL << fbit);
+   int w;
 
-   return w;
+   w = bitmap_weight(format, PERF_PMU_FORMAT_BITS);
+   if (!w)
+   return 0;
+   if (w < 64)
+   return (1ULL << w) - 1;
+   return -1;
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.14 03/19] net/mlx5: Take only bit 24-26 of wqe.pftype_wq for page fault type

2018-10-30 Thread Sasha Levin
From: Huy Nguyen 

[ Upstream commit a48bc513159d4767f9988f0d857b2b0c38a4d614 ]

The HW spec defines only bits 24-26 of pftype_wq as the page fault type,
use the required mask to ensure that.

Fixes: d9aaed838765 ("{net,IB}/mlx5: Refactor page fault handling")
Signed-off-by: Huy Nguyen 
Signed-off-by: Eli Cohen 
Signed-off-by: Saeed Mahameed 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/mellanox/mlx5/core/eq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c 
b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
index eb91de86202b..5da0b6e11530 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
@@ -262,7 +262,7 @@ static void eq_pf_process(struct mlx5_eq *eq)
case MLX5_PFAULT_SUBTYPE_WQE:
/* WQE based event */
pfault->type =
-   be32_to_cpu(pf_eqe->wqe.pftype_wq) >> 24;
+   (be32_to_cpu(pf_eqe->wqe.pftype_wq) >> 24) & 
0x7;
pfault->token =
be32_to_cpu(pf_eqe->wqe.token);
pfault->wqe.wq_num =
-- 
2.17.1



[PATCH AUTOSEL 4.9 11/13] selftests: ftrace: Add synthetic event syntax testcase

2018-10-30 Thread Sasha Levin
From: Masami Hiramatsu 

[ Upstream commit ba0e41ca81b935b958006c7120466e2217357827 ]

Add a testcase to check the syntax and field types for
synthetic_events interface.

Link: 
http://lkml.kernel.org/r/153986838264.18251.16627517536956299922.stgit@devbox

Acked-by: Shuah Khan 
Signed-off-by: Masami Hiramatsu 
Signed-off-by: Steven Rostedt (VMware) 
Signed-off-by: Sasha Levin 
---
 .../trigger-synthetic-event-syntax.tc | 80 +++
 1 file changed, 80 insertions(+)
 create mode 100644 
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc

diff --git 
a/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
new file mode 100644
index ..88e6c3f43006
--- /dev/null
+++ 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
@@ -0,0 +1,80 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: event trigger - test synthetic_events syntax parser
+
+do_reset() {
+reset_trigger
+echo > set_event
+clear_trace
+}
+
+fail() { #msg
+do_reset
+echo $1
+exit_fail
+}
+
+if [ ! -f set_event ]; then
+echo "event tracing is not supported"
+exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+echo "synthetic event is not supported"
+exit_unsupported
+fi
+
+reset_tracer
+do_reset
+
+echo "Test synthetic_events syntax parser"
+
+echo > synthetic_events
+
+# synthetic event must have a field
+! echo "myevent" >> synthetic_events
+echo "myevent u64 var1" >> synthetic_events
+
+# synthetic event must be found in synthetic_events
+grep "myevent[[:space:]]u64 var1" synthetic_events
+
+# it is not possible to add same name event
+! echo "myevent u64 var2" >> synthetic_events
+
+# Non-append open will cleanup all events and add new one
+echo "myevent u64 var2" > synthetic_events
+
+# multiple fields with different spaces
+echo "myevent u64 var1; u64 var2;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ; u64 var2 ;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ;u64 var2" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+
+# test field types
+echo "myevent u32 var" > synthetic_events
+echo "myevent u16 var" > synthetic_events
+echo "myevent u8 var" > synthetic_events
+echo "myevent s64 var" > synthetic_events
+echo "myevent s32 var" > synthetic_events
+echo "myevent s16 var" > synthetic_events
+echo "myevent s8 var" > synthetic_events
+
+echo "myevent char var" > synthetic_events
+echo "myevent int var" > synthetic_events
+echo "myevent long var" > synthetic_events
+echo "myevent pid_t var" > synthetic_events
+
+echo "myevent unsigned char var" > synthetic_events
+echo "myevent unsigned int var" > synthetic_events
+echo "myevent unsigned long var" > synthetic_events
+grep "myevent[[:space:]]unsigned long var" synthetic_events
+
+# test string type
+echo "myevent char var[10]" > synthetic_events
+grep "myevent[[:space:]]char\[10\] var" synthetic_events
+
+do_reset
+
+exit 0
-- 
2.17.1



[PATCH v2 1/2] kbuild: replace cc-name test with CONFIG_CC_IS_CLANG

2018-10-30 Thread Masahiro Yamada
Evaluating cc-name invokes the compiler every time even when you are
not compiling anything, like 'make help'. This is not efficient.

The compiler type has been already detected in the Kconfig stage.
Use CONFIG_CC_IS_CLANG, instead.

Signed-off-by: Masahiro Yamada 
Acked-by: Michael Ellerman  (powerpc)
---

Changes in v2:
 - Use ifdef/ifndef insteaed of ifeq/ifneq

 Makefile   | 2 +-
 arch/mips/Makefile | 2 +-
 arch/mips/vdso/Makefile| 2 +-
 arch/powerpc/Makefile  | 4 ++--
 scripts/Makefile.extrawarn | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 0a42d06..1c0696d 100644
--- a/Makefile
+++ b/Makefile
@@ -707,7 +707,7 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)  := 
-fstack-protector-strong
 
 KBUILD_CFLAGS += $(stackp-flags-y)
 
-ifeq ($(cc-name),clang)
+ifdef CONFIG_CC_IS_CLANG
 KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
 KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
 KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 15a84cf..6841049 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -128,7 +128,7 @@ cflags-y += -ffreestanding
 # clang's output will be based upon the build machine. So for clang we simply
 # unconditionally specify -EB or -EL as appropriate.
 #
-ifeq ($(cc-name),clang)
+ifdef CONFIG_CC_IS_CLANG
 cflags-$(CONFIG_CPU_BIG_ENDIAN)+= -EB
 cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -EL
 else
diff --git a/arch/mips/vdso/Makefile b/arch/mips/vdso/Makefile
index 34605ca..58a0315 100644
--- a/arch/mips/vdso/Makefile
+++ b/arch/mips/vdso/Makefile
@@ -10,7 +10,7 @@ ccflags-vdso := \
$(filter -march=%,$(KBUILD_CFLAGS)) \
-D__VDSO__
 
-ifeq ($(cc-name),clang)
+ifdef CONFIG_CC_IS_CLANG
 ccflags-vdso += $(filter --target=%,$(KBUILD_CFLAGS))
 endif
 
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 17be664..8a2ce14 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -96,7 +96,7 @@ aflags-$(CONFIG_CPU_BIG_ENDIAN)   += $(call 
cc-option,-mabi=elfv1)
 aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mabi=elfv2
 endif
 
-ifneq ($(cc-name),clang)
+ifndef CONFIG_CC_IS_CLANG
   cflags-$(CONFIG_CPU_LITTLE_ENDIAN)   += -mno-strict-align
 endif
 
@@ -175,7 +175,7 @@ endif
 # Work around gcc code-gen bugs with -pg / -fno-omit-frame-pointer in gcc <= 
4.8
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44199
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52828
-ifneq ($(cc-name),clang)
+ifndef CONFIG_CC_IS_CLANG
 CC_FLAGS_FTRACE+= $(call cc-ifversion, -lt, 0409, -mno-sched-epilog)
 endif
 endif
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 24b2fb1..800a10f 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -64,7 +64,7 @@ endif
 KBUILD_CFLAGS += $(warning)
 else
 
-ifeq ($(cc-name),clang)
+ifdef CONFIG_CC_IS_CLANG
 KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
 KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
 KBUILD_CFLAGS += $(call cc-disable-warning, format)
-- 
2.7.4



[PATCH AUTOSEL 4.9 03/13] xfrm: policy: use hlist rcu variants on insert

2018-10-30 Thread Sasha Levin
From: Florian Westphal 

[ Upstream commit 9d200fd178f11dd50eb1fd8ccd0650c9284e ]

bydst table/list lookups use rcu, so insertions must use rcu versions.

Fixes: a7c44247f704e ("xfrm: policy: make xfrm_policy_lookup_bytype lockless")
Signed-off-by: Florian Westphal 
Signed-off-by: Steffen Klassert 
Signed-off-by: Sasha Levin 
---
 net/xfrm/xfrm_policy.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index d0dcfc68c043..155b1591b17a 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -659,9 +659,9 @@ static void xfrm_hash_rebuild(struct work_struct *work)
break;
}
if (newpos)
-   hlist_add_behind(>bydst, newpos);
+   hlist_add_behind_rcu(>bydst, newpos);
else
-   hlist_add_head(>bydst, chain);
+   hlist_add_head_rcu(>bydst, chain);
}
 
spin_unlock_bh(>xfrm.xfrm_policy_lock);
@@ -800,9 +800,9 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, 
int excl)
break;
}
if (newpos)
-   hlist_add_behind(>bydst, newpos);
+   hlist_add_behind_rcu(>bydst, newpos);
else
-   hlist_add_head(>bydst, chain);
+   hlist_add_head_rcu(>bydst, chain);
__xfrm_policy_link(policy, dir);
atomic_inc(>xfrm.flow_cache_genid);
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 12/13] net: fix pskb_trim_rcsum_slow() with odd trim offset

2018-10-30 Thread Sasha Levin
From: Dimitris Michailidis 

[ Upstream commit d55bef5059dd057bd077155375c581b49d25be7e ]

We've been getting checksum errors involving small UDP packets, usually
59B packets with 1 extra non-zero padding byte. netdev_rx_csum_fault()
has been complaining that HW is providing bad checksums. Turns out the
problem is in pskb_trim_rcsum_slow(), introduced in commit 88078d98d1bb
("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends").

The source of the problem is that when the bytes we are trimming start
at an odd address, as in the case of the 1 padding byte above,
skb_checksum() returns a byte-swapped value. We cannot just combine this
with skb->csum using csum_sub(). We need to use csum_block_sub() here
that takes into account the parity of the start address and handles the
swapping.

Matches existing code in __skb_postpull_rcsum() and esp_remove_trailer().

Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends")
Signed-off-by: Dimitris Michailidis 
Reviewed-by: Eric Dumazet 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 net/core/skbuff.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 038ec74fa131..68ecb7d71c2b 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1585,8 +1585,9 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned 
int len)
if (skb->ip_summed == CHECKSUM_COMPLETE) {
int delta = skb->len - len;
 
-   skb->csum = csum_sub(skb->csum,
-skb_checksum(skb, len, delta, 0));
+   skb->csum = csum_block_sub(skb->csum,
+  skb_checksum(skb, len, delta, 0),
+  len);
}
return __pskb_trim(skb, len);
 }
-- 
2.17.1



[PATCH AUTOSEL 4.9 07/13] perf cpu_map: Align cpu map synthesized events properly.

2018-10-30 Thread Sasha Levin
From: David Miller 

[ Upstream commit 0ed149cf5239cc6e7e65bf00f769e8f1e91076c0 ]

The size of the resulting cpu map can be smaller than a multiple of
sizeof(u64), resulting in SIGBUS on cpus like Sparc as the next event
will not be aligned properly.

Signed-off-by: David S. Miller 
Cc: Jiri Olsa 
Cc: Kan Liang 
Fixes: 6c872901af07 ("perf cpu_map: Add cpu_map event synthesize function")
Link: 
http://lkml.kernel.org/r/20181011.224655.716771175766946817.da...@davemloft.net
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/event.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 663192395780..2d5744d986f0 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -839,6 +839,7 @@ void *cpu_map_data__alloc(struct cpu_map *map, size_t 
*size, u16 *type, int *max
}
 
*size += sizeof(struct cpu_map_data);
+   *size = PERF_ALIGN(*size, sizeof(u64));
return zalloc(*size);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 01/13] bpf: do not blindly change rlimit in reuseport net selftest

2018-10-30 Thread Sasha Levin
From: Eric Dumazet 

[ Upstream commit 262f9d811c7608f1e74258ceecfe1fa213bdf912 ]

If the current process has unlimited RLIMIT_MEMLOCK,
we should should leave it as is.

Fixes: 941ff6f11c02 ("bpf: fix rlimit in reuseport net selftest")
Signed-off-by: John Sperbeck 
Signed-off-by: Eric Dumazet 
Acked-by: Daniel Borkmann 
Signed-off-by: Daniel Borkmann 
Signed-off-by: Sasha Levin 
---
 tools/testing/selftests/net/reuseport_bpf.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/reuseport_bpf.c 
b/tools/testing/selftests/net/reuseport_bpf.c
index cad14cd0ea92..b5277106df1f 100644
--- a/tools/testing/selftests/net/reuseport_bpf.c
+++ b/tools/testing/selftests/net/reuseport_bpf.c
@@ -437,14 +437,19 @@ void enable_fastopen(void)
}
 }
 
-static struct rlimit rlim_old, rlim_new;
+static struct rlimit rlim_old;
 
 static  __attribute__((constructor)) void main_ctor(void)
 {
getrlimit(RLIMIT_MEMLOCK, _old);
-   rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
-   rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
-   setrlimit(RLIMIT_MEMLOCK, _new);
+
+   if (rlim_old.rlim_cur != RLIM_INFINITY) {
+   struct rlimit rlim_new;
+
+   rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
+   rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
+   setrlimit(RLIMIT_MEMLOCK, _new);
+   }
 }
 
 static __attribute__((destructor)) void main_dtor(void)
-- 
2.17.1



[PATCH AUTOSEL 4.9 08/13] x86/fpu: Remove second definition of fpu in __fpu__restore_sig()

2018-10-30 Thread Sasha Levin
From: Sebastian Andrzej Siewior 

[ Upstream commit 6aa676761d4c1acfa31320e55fa1f83f3fcbbc7a ]

Commit:

  c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")

introduced the 'fpu' variable at top of __restore_xstate_sig(),
which now shadows the other definition:

  arch/x86/kernel/fpu/signal.c:318:28: warning: symbol 'fpu' shadows an earlier 
one
  arch/x86/kernel/fpu/signal.c:271:20: originally declared here

Remove the shadowed definition of 'fpu', as the two definitions are the same.

Signed-off-by: Sebastian Andrzej Siewior 
Reviewed-by: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Dave Hansen 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")
Link: http://lkml.kernel.org/r/20181016202525.29437-3-bige...@linutronix.de
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 arch/x86/kernel/fpu/signal.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c
index 3a9318610c4d..ae52ef05d098 100644
--- a/arch/x86/kernel/fpu/signal.c
+++ b/arch/x86/kernel/fpu/signal.c
@@ -309,7 +309,6 @@ static int __fpu__restore_sig(void __user *buf, void __user 
*buf_fx, int size)
 * thread's fpu state, reconstruct fxstate from the fsave
 * header. Sanitize the copied state etc.
 */
-   struct fpu *fpu = >thread.fpu;
struct user_i387_ia32_struct env;
int err = 0;
 
-- 
2.17.1



[PATCH AUTOSEL 4.9 02/13] Revert "perf tools: Fix PMU term format max value calculation"

2018-10-30 Thread Sasha Levin
From: Jiri Olsa 

[ Upstream commit 1b9caa10b31dda0866f4028e4bfb923fb6e4072f ]

This reverts commit ac0e2cd555373ae6f8f3a3ad3fbbf5b6d1e7.

Michael reported an issue with oversized terms values assignment
and I noticed there was actually a misunderstanding of the max
value check in the past.

The above commit's changelog says:

  If bit 21 is set, there is parsing issues as below.

$ perf stat -a -e uncore_qpi_0/event=0x22,umask=0x8/
event syntax error: '..pi_0/event=0x22,umask=0x8/'
  \___ value too big for format, maximum is 
511

But there's no issue there, because the event value is distributed
along the value defined by the format. Even if the format defines
separated bit, the value is treated as a continual number, which
should follow the format definition.

In above case it's 9-bit value with last bit separated:
  $ cat uncore_qpi_0/format/event
  config:0-7,21

Hence the value 0x22 is correctly reported as format violation,
because it exceeds 9 bits. It should have been 0x102 instead, which
sets the 9th bit - the bit 21 of the format.

  $ perf stat -vv -a -e uncore_qpi_0/event=0x102,umask=0x8/
  Using CPUID GenuineIntel-6-2D
  ...
  
  perf_event_attr:
type 10
size 112
config   0x200802
sample_type  IDENTIFIER
  ...

Reported-by: Michael Petlan 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Andi Kleen 
Cc: Kan Liang 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Fixes: ac0e2cd55537 ("perf tools: Fix PMU term format max value calculation")
Link: http://lkml.kernel.org/r/20181003072046.29276-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/pmu.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index b1474dcadfa2..0f84371d4d6b 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -685,13 +685,14 @@ static void pmu_format_value(unsigned long *format, __u64 
value, __u64 *v,
 
 static __u64 pmu_format_max_value(const unsigned long *format)
 {
-   __u64 w = 0;
-   int fbit;
-
-   for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
-   w |= (1ULL << fbit);
+   int w;
 
-   return w;
+   w = bitmap_weight(format, PERF_PMU_FORMAT_BITS);
+   if (!w)
+   return 0;
+   if (w < 64)
+   return (1ULL << w) - 1;
+   return -1;
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.14 03/19] net/mlx5: Take only bit 24-26 of wqe.pftype_wq for page fault type

2018-10-30 Thread Sasha Levin
From: Huy Nguyen 

[ Upstream commit a48bc513159d4767f9988f0d857b2b0c38a4d614 ]

The HW spec defines only bits 24-26 of pftype_wq as the page fault type,
use the required mask to ensure that.

Fixes: d9aaed838765 ("{net,IB}/mlx5: Refactor page fault handling")
Signed-off-by: Huy Nguyen 
Signed-off-by: Eli Cohen 
Signed-off-by: Saeed Mahameed 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/mellanox/mlx5/core/eq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c 
b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
index eb91de86202b..5da0b6e11530 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
@@ -262,7 +262,7 @@ static void eq_pf_process(struct mlx5_eq *eq)
case MLX5_PFAULT_SUBTYPE_WQE:
/* WQE based event */
pfault->type =
-   be32_to_cpu(pf_eqe->wqe.pftype_wq) >> 24;
+   (be32_to_cpu(pf_eqe->wqe.pftype_wq) >> 24) & 
0x7;
pfault->token =
be32_to_cpu(pf_eqe->wqe.token);
pfault->wqe.wq_num =
-- 
2.17.1



[PATCH AUTOSEL 4.9 11/13] selftests: ftrace: Add synthetic event syntax testcase

2018-10-30 Thread Sasha Levin
From: Masami Hiramatsu 

[ Upstream commit ba0e41ca81b935b958006c7120466e2217357827 ]

Add a testcase to check the syntax and field types for
synthetic_events interface.

Link: 
http://lkml.kernel.org/r/153986838264.18251.16627517536956299922.stgit@devbox

Acked-by: Shuah Khan 
Signed-off-by: Masami Hiramatsu 
Signed-off-by: Steven Rostedt (VMware) 
Signed-off-by: Sasha Levin 
---
 .../trigger-synthetic-event-syntax.tc | 80 +++
 1 file changed, 80 insertions(+)
 create mode 100644 
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc

diff --git 
a/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
new file mode 100644
index ..88e6c3f43006
--- /dev/null
+++ 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
@@ -0,0 +1,80 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: event trigger - test synthetic_events syntax parser
+
+do_reset() {
+reset_trigger
+echo > set_event
+clear_trace
+}
+
+fail() { #msg
+do_reset
+echo $1
+exit_fail
+}
+
+if [ ! -f set_event ]; then
+echo "event tracing is not supported"
+exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+echo "synthetic event is not supported"
+exit_unsupported
+fi
+
+reset_tracer
+do_reset
+
+echo "Test synthetic_events syntax parser"
+
+echo > synthetic_events
+
+# synthetic event must have a field
+! echo "myevent" >> synthetic_events
+echo "myevent u64 var1" >> synthetic_events
+
+# synthetic event must be found in synthetic_events
+grep "myevent[[:space:]]u64 var1" synthetic_events
+
+# it is not possible to add same name event
+! echo "myevent u64 var2" >> synthetic_events
+
+# Non-append open will cleanup all events and add new one
+echo "myevent u64 var2" > synthetic_events
+
+# multiple fields with different spaces
+echo "myevent u64 var1; u64 var2;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ; u64 var2 ;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ;u64 var2" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+
+# test field types
+echo "myevent u32 var" > synthetic_events
+echo "myevent u16 var" > synthetic_events
+echo "myevent u8 var" > synthetic_events
+echo "myevent s64 var" > synthetic_events
+echo "myevent s32 var" > synthetic_events
+echo "myevent s16 var" > synthetic_events
+echo "myevent s8 var" > synthetic_events
+
+echo "myevent char var" > synthetic_events
+echo "myevent int var" > synthetic_events
+echo "myevent long var" > synthetic_events
+echo "myevent pid_t var" > synthetic_events
+
+echo "myevent unsigned char var" > synthetic_events
+echo "myevent unsigned int var" > synthetic_events
+echo "myevent unsigned long var" > synthetic_events
+grep "myevent[[:space:]]unsigned long var" synthetic_events
+
+# test string type
+echo "myevent char var[10]" > synthetic_events
+grep "myevent[[:space:]]char\[10\] var" synthetic_events
+
+do_reset
+
+exit 0
-- 
2.17.1



[PATCH v2 1/2] kbuild: replace cc-name test with CONFIG_CC_IS_CLANG

2018-10-30 Thread Masahiro Yamada
Evaluating cc-name invokes the compiler every time even when you are
not compiling anything, like 'make help'. This is not efficient.

The compiler type has been already detected in the Kconfig stage.
Use CONFIG_CC_IS_CLANG, instead.

Signed-off-by: Masahiro Yamada 
Acked-by: Michael Ellerman  (powerpc)
---

Changes in v2:
 - Use ifdef/ifndef insteaed of ifeq/ifneq

 Makefile   | 2 +-
 arch/mips/Makefile | 2 +-
 arch/mips/vdso/Makefile| 2 +-
 arch/powerpc/Makefile  | 4 ++--
 scripts/Makefile.extrawarn | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 0a42d06..1c0696d 100644
--- a/Makefile
+++ b/Makefile
@@ -707,7 +707,7 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)  := 
-fstack-protector-strong
 
 KBUILD_CFLAGS += $(stackp-flags-y)
 
-ifeq ($(cc-name),clang)
+ifdef CONFIG_CC_IS_CLANG
 KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
 KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
 KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 15a84cf..6841049 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -128,7 +128,7 @@ cflags-y += -ffreestanding
 # clang's output will be based upon the build machine. So for clang we simply
 # unconditionally specify -EB or -EL as appropriate.
 #
-ifeq ($(cc-name),clang)
+ifdef CONFIG_CC_IS_CLANG
 cflags-$(CONFIG_CPU_BIG_ENDIAN)+= -EB
 cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -EL
 else
diff --git a/arch/mips/vdso/Makefile b/arch/mips/vdso/Makefile
index 34605ca..58a0315 100644
--- a/arch/mips/vdso/Makefile
+++ b/arch/mips/vdso/Makefile
@@ -10,7 +10,7 @@ ccflags-vdso := \
$(filter -march=%,$(KBUILD_CFLAGS)) \
-D__VDSO__
 
-ifeq ($(cc-name),clang)
+ifdef CONFIG_CC_IS_CLANG
 ccflags-vdso += $(filter --target=%,$(KBUILD_CFLAGS))
 endif
 
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 17be664..8a2ce14 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -96,7 +96,7 @@ aflags-$(CONFIG_CPU_BIG_ENDIAN)   += $(call 
cc-option,-mabi=elfv1)
 aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mabi=elfv2
 endif
 
-ifneq ($(cc-name),clang)
+ifndef CONFIG_CC_IS_CLANG
   cflags-$(CONFIG_CPU_LITTLE_ENDIAN)   += -mno-strict-align
 endif
 
@@ -175,7 +175,7 @@ endif
 # Work around gcc code-gen bugs with -pg / -fno-omit-frame-pointer in gcc <= 
4.8
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44199
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52828
-ifneq ($(cc-name),clang)
+ifndef CONFIG_CC_IS_CLANG
 CC_FLAGS_FTRACE+= $(call cc-ifversion, -lt, 0409, -mno-sched-epilog)
 endif
 endif
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 24b2fb1..800a10f 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -64,7 +64,7 @@ endif
 KBUILD_CFLAGS += $(warning)
 else
 
-ifeq ($(cc-name),clang)
+ifdef CONFIG_CC_IS_CLANG
 KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
 KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
 KBUILD_CFLAGS += $(call cc-disable-warning, format)
-- 
2.7.4



[PATCH AUTOSEL 4.14 07/19] sparc: Throttle perf events properly.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit 455adb3174d2c8518cef1a61140c211f6ac224d2 ]

Like x86 and arm, call perf_sample_event_took() in perf event
NMI interrupt handler.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index 8a569b09d2c2..eceb0215bdee 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1612,6 +1613,8 @@ static int __kprobes perf_event_nmi_handler(struct 
notifier_block *self,
struct perf_sample_data data;
struct cpu_hw_events *cpuc;
struct pt_regs *regs;
+   u64 finish_clock;
+   u64 start_clock;
int i;
 
if (!atomic_read(_events))
@@ -1625,6 +1628,8 @@ static int __kprobes perf_event_nmi_handler(struct 
notifier_block *self,
return NOTIFY_DONE;
}
 
+   start_clock = sched_clock();
+
regs = args->regs;
 
cpuc = this_cpu_ptr(_hw_events);
@@ -1663,6 +1668,10 @@ static int __kprobes perf_event_nmi_handler(struct 
notifier_block *self,
sparc_pmu_stop(event, 0);
}
 
+   finish_clock = sched_clock();
+
+   perf_sample_event_took(finish_clock - start_clock);
+
return NOTIFY_STOP;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 07/19] sparc: Throttle perf events properly.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit 455adb3174d2c8518cef1a61140c211f6ac224d2 ]

Like x86 and arm, call perf_sample_event_took() in perf event
NMI interrupt handler.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index 8a569b09d2c2..eceb0215bdee 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1612,6 +1613,8 @@ static int __kprobes perf_event_nmi_handler(struct 
notifier_block *self,
struct perf_sample_data data;
struct cpu_hw_events *cpuc;
struct pt_regs *regs;
+   u64 finish_clock;
+   u64 start_clock;
int i;
 
if (!atomic_read(_events))
@@ -1625,6 +1628,8 @@ static int __kprobes perf_event_nmi_handler(struct 
notifier_block *self,
return NOTIFY_DONE;
}
 
+   start_clock = sched_clock();
+
regs = args->regs;
 
cpuc = this_cpu_ptr(_hw_events);
@@ -1663,6 +1668,10 @@ static int __kprobes perf_event_nmi_handler(struct 
notifier_block *self,
sparc_pmu_stop(event, 0);
}
 
+   finish_clock = sched_clock();
+
+   perf_sample_event_took(finish_clock - start_clock);
+
return NOTIFY_STOP;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 18/19] net: fix pskb_trim_rcsum_slow() with odd trim offset

2018-10-30 Thread Sasha Levin
From: Dimitris Michailidis 

[ Upstream commit d55bef5059dd057bd077155375c581b49d25be7e ]

We've been getting checksum errors involving small UDP packets, usually
59B packets with 1 extra non-zero padding byte. netdev_rx_csum_fault()
has been complaining that HW is providing bad checksums. Turns out the
problem is in pskb_trim_rcsum_slow(), introduced in commit 88078d98d1bb
("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends").

The source of the problem is that when the bytes we are trimming start
at an odd address, as in the case of the 1 padding byte above,
skb_checksum() returns a byte-swapped value. We cannot just combine this
with skb->csum using csum_sub(). We need to use csum_block_sub() here
that takes into account the parity of the start address and handles the
swapping.

Matches existing code in __skb_postpull_rcsum() and esp_remove_trailer().

Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends")
Signed-off-by: Dimitris Michailidis 
Reviewed-by: Eric Dumazet 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 net/core/skbuff.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 9f80b947f53b..c19a118f9f82 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1843,8 +1843,9 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned 
int len)
if (skb->ip_summed == CHECKSUM_COMPLETE) {
int delta = skb->len - len;
 
-   skb->csum = csum_sub(skb->csum,
-skb_checksum(skb, len, delta, 0));
+   skb->csum = csum_block_sub(skb->csum,
+  skb_checksum(skb, len, delta, 0),
+  len);
}
return __pskb_trim(skb, len);
 }
-- 
2.17.1



[PATCH AUTOSEL 4.14 17/19] selftests: ftrace: Add synthetic event syntax testcase

2018-10-30 Thread Sasha Levin
From: Masami Hiramatsu 

[ Upstream commit ba0e41ca81b935b958006c7120466e2217357827 ]

Add a testcase to check the syntax and field types for
synthetic_events interface.

Link: 
http://lkml.kernel.org/r/153986838264.18251.16627517536956299922.stgit@devbox

Acked-by: Shuah Khan 
Signed-off-by: Masami Hiramatsu 
Signed-off-by: Steven Rostedt (VMware) 
Signed-off-by: Sasha Levin 
---
 .../trigger-synthetic-event-syntax.tc | 80 +++
 1 file changed, 80 insertions(+)
 create mode 100644 
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc

diff --git 
a/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
new file mode 100644
index ..88e6c3f43006
--- /dev/null
+++ 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
@@ -0,0 +1,80 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: event trigger - test synthetic_events syntax parser
+
+do_reset() {
+reset_trigger
+echo > set_event
+clear_trace
+}
+
+fail() { #msg
+do_reset
+echo $1
+exit_fail
+}
+
+if [ ! -f set_event ]; then
+echo "event tracing is not supported"
+exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+echo "synthetic event is not supported"
+exit_unsupported
+fi
+
+reset_tracer
+do_reset
+
+echo "Test synthetic_events syntax parser"
+
+echo > synthetic_events
+
+# synthetic event must have a field
+! echo "myevent" >> synthetic_events
+echo "myevent u64 var1" >> synthetic_events
+
+# synthetic event must be found in synthetic_events
+grep "myevent[[:space:]]u64 var1" synthetic_events
+
+# it is not possible to add same name event
+! echo "myevent u64 var2" >> synthetic_events
+
+# Non-append open will cleanup all events and add new one
+echo "myevent u64 var2" > synthetic_events
+
+# multiple fields with different spaces
+echo "myevent u64 var1; u64 var2;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ; u64 var2 ;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ;u64 var2" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+
+# test field types
+echo "myevent u32 var" > synthetic_events
+echo "myevent u16 var" > synthetic_events
+echo "myevent u8 var" > synthetic_events
+echo "myevent s64 var" > synthetic_events
+echo "myevent s32 var" > synthetic_events
+echo "myevent s16 var" > synthetic_events
+echo "myevent s8 var" > synthetic_events
+
+echo "myevent char var" > synthetic_events
+echo "myevent int var" > synthetic_events
+echo "myevent long var" > synthetic_events
+echo "myevent pid_t var" > synthetic_events
+
+echo "myevent unsigned char var" > synthetic_events
+echo "myevent unsigned int var" > synthetic_events
+echo "myevent unsigned long var" > synthetic_events
+grep "myevent[[:space:]]unsigned long var" synthetic_events
+
+# test string type
+echo "myevent char var[10]" > synthetic_events
+grep "myevent[[:space:]]char\[10\] var" synthetic_events
+
+do_reset
+
+exit 0
-- 
2.17.1



[PATCH AUTOSEL 4.14 19/19] i2c: rcar: cleanup DMA for all kinds of failure

2018-10-30 Thread Sasha Levin
From: Wolfram Sang 

[ Upstream commit 31d86033a0749a0463ea654130b2de5c163154f1 ]

DMA needs to be cleaned up not only on timeout, but on all errors where
it has been setup before.

Fixes: 73e8b0528346 ("i2c: rcar: add DMA support")
Signed-off-by: Wolfram Sang 
Signed-off-by: Wolfram Sang 
Signed-off-by: Sasha Levin 
---
 drivers/i2c/busses/i2c-rcar.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 7f044df1ea07..3415733a9364 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -761,8 +761,12 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
 
time_left = wait_event_timeout(priv->wait, priv->flags & ID_DONE,
 num * adap->timeout);
-   if (!time_left) {
+
+   /* cleanup DMA if it couldn't complete properly due to an error */
+   if (priv->dma_direction != DMA_NONE)
rcar_i2c_cleanup_dma(priv);
+
+   if (!time_left) {
rcar_i2c_init(priv);
ret = -ETIMEDOUT;
} else if (priv->flags & ID_NACK) {
-- 
2.17.1



[PATCH AUTOSEL 4.14 18/19] net: fix pskb_trim_rcsum_slow() with odd trim offset

2018-10-30 Thread Sasha Levin
From: Dimitris Michailidis 

[ Upstream commit d55bef5059dd057bd077155375c581b49d25be7e ]

We've been getting checksum errors involving small UDP packets, usually
59B packets with 1 extra non-zero padding byte. netdev_rx_csum_fault()
has been complaining that HW is providing bad checksums. Turns out the
problem is in pskb_trim_rcsum_slow(), introduced in commit 88078d98d1bb
("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends").

The source of the problem is that when the bytes we are trimming start
at an odd address, as in the case of the 1 padding byte above,
skb_checksum() returns a byte-swapped value. We cannot just combine this
with skb->csum using csum_sub(). We need to use csum_block_sub() here
that takes into account the parity of the start address and handles the
swapping.

Matches existing code in __skb_postpull_rcsum() and esp_remove_trailer().

Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends")
Signed-off-by: Dimitris Michailidis 
Reviewed-by: Eric Dumazet 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 net/core/skbuff.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 9f80b947f53b..c19a118f9f82 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1843,8 +1843,9 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned 
int len)
if (skb->ip_summed == CHECKSUM_COMPLETE) {
int delta = skb->len - len;
 
-   skb->csum = csum_sub(skb->csum,
-skb_checksum(skb, len, delta, 0));
+   skb->csum = csum_block_sub(skb->csum,
+  skb_checksum(skb, len, delta, 0),
+  len);
}
return __pskb_trim(skb, len);
 }
-- 
2.17.1



[PATCH AUTOSEL 4.14 17/19] selftests: ftrace: Add synthetic event syntax testcase

2018-10-30 Thread Sasha Levin
From: Masami Hiramatsu 

[ Upstream commit ba0e41ca81b935b958006c7120466e2217357827 ]

Add a testcase to check the syntax and field types for
synthetic_events interface.

Link: 
http://lkml.kernel.org/r/153986838264.18251.16627517536956299922.stgit@devbox

Acked-by: Shuah Khan 
Signed-off-by: Masami Hiramatsu 
Signed-off-by: Steven Rostedt (VMware) 
Signed-off-by: Sasha Levin 
---
 .../trigger-synthetic-event-syntax.tc | 80 +++
 1 file changed, 80 insertions(+)
 create mode 100644 
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc

diff --git 
a/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
new file mode 100644
index ..88e6c3f43006
--- /dev/null
+++ 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
@@ -0,0 +1,80 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: event trigger - test synthetic_events syntax parser
+
+do_reset() {
+reset_trigger
+echo > set_event
+clear_trace
+}
+
+fail() { #msg
+do_reset
+echo $1
+exit_fail
+}
+
+if [ ! -f set_event ]; then
+echo "event tracing is not supported"
+exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+echo "synthetic event is not supported"
+exit_unsupported
+fi
+
+reset_tracer
+do_reset
+
+echo "Test synthetic_events syntax parser"
+
+echo > synthetic_events
+
+# synthetic event must have a field
+! echo "myevent" >> synthetic_events
+echo "myevent u64 var1" >> synthetic_events
+
+# synthetic event must be found in synthetic_events
+grep "myevent[[:space:]]u64 var1" synthetic_events
+
+# it is not possible to add same name event
+! echo "myevent u64 var2" >> synthetic_events
+
+# Non-append open will cleanup all events and add new one
+echo "myevent u64 var2" > synthetic_events
+
+# multiple fields with different spaces
+echo "myevent u64 var1; u64 var2;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ; u64 var2 ;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ;u64 var2" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+
+# test field types
+echo "myevent u32 var" > synthetic_events
+echo "myevent u16 var" > synthetic_events
+echo "myevent u8 var" > synthetic_events
+echo "myevent s64 var" > synthetic_events
+echo "myevent s32 var" > synthetic_events
+echo "myevent s16 var" > synthetic_events
+echo "myevent s8 var" > synthetic_events
+
+echo "myevent char var" > synthetic_events
+echo "myevent int var" > synthetic_events
+echo "myevent long var" > synthetic_events
+echo "myevent pid_t var" > synthetic_events
+
+echo "myevent unsigned char var" > synthetic_events
+echo "myevent unsigned int var" > synthetic_events
+echo "myevent unsigned long var" > synthetic_events
+grep "myevent[[:space:]]unsigned long var" synthetic_events
+
+# test string type
+echo "myevent char var[10]" > synthetic_events
+grep "myevent[[:space:]]char\[10\] var" synthetic_events
+
+do_reset
+
+exit 0
-- 
2.17.1



[PATCH AUTOSEL 4.14 19/19] i2c: rcar: cleanup DMA for all kinds of failure

2018-10-30 Thread Sasha Levin
From: Wolfram Sang 

[ Upstream commit 31d86033a0749a0463ea654130b2de5c163154f1 ]

DMA needs to be cleaned up not only on timeout, but on all errors where
it has been setup before.

Fixes: 73e8b0528346 ("i2c: rcar: add DMA support")
Signed-off-by: Wolfram Sang 
Signed-off-by: Wolfram Sang 
Signed-off-by: Sasha Levin 
---
 drivers/i2c/busses/i2c-rcar.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 7f044df1ea07..3415733a9364 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -761,8 +761,12 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
 
time_left = wait_event_timeout(priv->wait, priv->flags & ID_DONE,
 num * adap->timeout);
-   if (!time_left) {
+
+   /* cleanup DMA if it couldn't complete properly due to an error */
+   if (priv->dma_direction != DMA_NONE)
rcar_i2c_cleanup_dma(priv);
+
+   if (!time_left) {
rcar_i2c_init(priv);
ret = -ETIMEDOUT;
} else if (priv->flags & ID_NACK) {
-- 
2.17.1



[PATCH AUTOSEL 4.14 15/19] virtio_net: avoid using netif_tx_disable() for serializing tx routine

2018-10-30 Thread Sasha Levin
From: Ake Koomsin 

[ Upstream commit 05c998b738fdd3e5d6a257bcacc8f34b6284d795 ]

Commit 713a98d90c5e ("virtio-net: serialize tx routine during reset")
introduces netif_tx_disable() after netif_device_detach() in order to
avoid use-after-free of tx queues. However, there are two issues.

1) Its operation is redundant with netif_device_detach() in case the
   interface is running.
2) In case of the interface is not running before suspending and
   resuming, the tx does not get resumed by netif_device_attach().
   This results in losing network connectivity.

It is better to use netif_tx_lock_bh()/netif_tx_unlock_bh() instead for
serializing tx routine during reset. This also preserves the symmetry
of netif_device_detach() and netif_device_attach().

Fixes commit 713a98d90c5e ("virtio-net: serialize tx routine during reset")
Signed-off-by: Ake Koomsin 
Acked-by: Jason Wang 
Acked-by: Michael S. Tsirkin 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/virtio_net.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 910c46b47769..f528e9ac3413 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1872,8 +1872,9 @@ static void virtnet_freeze_down(struct virtio_device 
*vdev)
/* Make sure no work handler is accessing the device */
flush_work(>config_work);
 
+   netif_tx_lock_bh(vi->dev);
netif_device_detach(vi->dev);
-   netif_tx_disable(vi->dev);
+   netif_tx_unlock_bh(vi->dev);
cancel_delayed_work_sync(>refill);
 
if (netif_running(vi->dev)) {
@@ -1909,7 +1910,9 @@ static int virtnet_restore_up(struct virtio_device *vdev)
}
}
 
+   netif_tx_lock_bh(vi->dev);
netif_device_attach(vi->dev);
+   netif_tx_unlock_bh(vi->dev);
return err;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 16/19] r8169: fix NAPI handling under high load

2018-10-30 Thread Sasha Levin
From: Heiner Kallweit 

[ Upstream commit 6b839b6cf9eada30b086effb51e5d6076bafc761 ]

rtl_rx() and rtl_tx() are called only if the respective bits are set
in the interrupt status register. Under high load NAPI may not be
able to process all data (work_done == budget) and it will schedule
subsequent calls to the poll callback.
rtl_ack_events() however resets the bits in the interrupt status
register, therefore subsequent calls to rtl8169_poll() won't call
rtl_rx() and rtl_tx() - chip interrupts are still disabled.

Fix this by calling rtl_rx() and rtl_tx() independent of the bits
set in the interrupt status register. Both functions will detect
if there's nothing to do for them.

Fixes: da78dbff2e05 ("r8169: remove work from irq handler.")
Signed-off-by: Heiner Kallweit 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/realtek/r8169.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index f7e540eeb877..1b61ce310132 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7579,17 +7579,15 @@ static int rtl8169_poll(struct napi_struct *napi, int 
budget)
struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, 
napi);
struct net_device *dev = tp->dev;
u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow;
-   int work_done= 0;
+   int work_done;
u16 status;
 
status = rtl_get_events(tp);
rtl_ack_events(tp, status & ~tp->event_slow);
 
-   if (status & RTL_EVENT_NAPI_RX)
-   work_done = rtl_rx(dev, tp, (u32) budget);
+   work_done = rtl_rx(dev, tp, (u32) budget);
 
-   if (status & RTL_EVENT_NAPI_TX)
-   rtl_tx(dev, tp);
+   rtl_tx(dev, tp);
 
if (status & tp->event_slow) {
enable_mask &= ~tp->event_slow;
-- 
2.17.1



[PATCH AUTOSEL 4.14 15/19] virtio_net: avoid using netif_tx_disable() for serializing tx routine

2018-10-30 Thread Sasha Levin
From: Ake Koomsin 

[ Upstream commit 05c998b738fdd3e5d6a257bcacc8f34b6284d795 ]

Commit 713a98d90c5e ("virtio-net: serialize tx routine during reset")
introduces netif_tx_disable() after netif_device_detach() in order to
avoid use-after-free of tx queues. However, there are two issues.

1) Its operation is redundant with netif_device_detach() in case the
   interface is running.
2) In case of the interface is not running before suspending and
   resuming, the tx does not get resumed by netif_device_attach().
   This results in losing network connectivity.

It is better to use netif_tx_lock_bh()/netif_tx_unlock_bh() instead for
serializing tx routine during reset. This also preserves the symmetry
of netif_device_detach() and netif_device_attach().

Fixes commit 713a98d90c5e ("virtio-net: serialize tx routine during reset")
Signed-off-by: Ake Koomsin 
Acked-by: Jason Wang 
Acked-by: Michael S. Tsirkin 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/virtio_net.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 910c46b47769..f528e9ac3413 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1872,8 +1872,9 @@ static void virtnet_freeze_down(struct virtio_device 
*vdev)
/* Make sure no work handler is accessing the device */
flush_work(>config_work);
 
+   netif_tx_lock_bh(vi->dev);
netif_device_detach(vi->dev);
-   netif_tx_disable(vi->dev);
+   netif_tx_unlock_bh(vi->dev);
cancel_delayed_work_sync(>refill);
 
if (netif_running(vi->dev)) {
@@ -1909,7 +1910,9 @@ static int virtnet_restore_up(struct virtio_device *vdev)
}
}
 
+   netif_tx_lock_bh(vi->dev);
netif_device_attach(vi->dev);
+   netif_tx_unlock_bh(vi->dev);
return err;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 16/19] r8169: fix NAPI handling under high load

2018-10-30 Thread Sasha Levin
From: Heiner Kallweit 

[ Upstream commit 6b839b6cf9eada30b086effb51e5d6076bafc761 ]

rtl_rx() and rtl_tx() are called only if the respective bits are set
in the interrupt status register. Under high load NAPI may not be
able to process all data (work_done == budget) and it will schedule
subsequent calls to the poll callback.
rtl_ack_events() however resets the bits in the interrupt status
register, therefore subsequent calls to rtl8169_poll() won't call
rtl_rx() and rtl_tx() - chip interrupts are still disabled.

Fix this by calling rtl_rx() and rtl_tx() independent of the bits
set in the interrupt status register. Both functions will detect
if there's nothing to do for them.

Fixes: da78dbff2e05 ("r8169: remove work from irq handler.")
Signed-off-by: Heiner Kallweit 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/realtek/r8169.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index f7e540eeb877..1b61ce310132 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7579,17 +7579,15 @@ static int rtl8169_poll(struct napi_struct *napi, int 
budget)
struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, 
napi);
struct net_device *dev = tp->dev;
u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow;
-   int work_done= 0;
+   int work_done;
u16 status;
 
status = rtl_get_events(tp);
rtl_ack_events(tp, status & ~tp->event_slow);
 
-   if (status & RTL_EVENT_NAPI_RX)
-   work_done = rtl_rx(dev, tp, (u32) budget);
+   work_done = rtl_rx(dev, tp, (u32) budget);
 
-   if (status & RTL_EVENT_NAPI_TX)
-   rtl_tx(dev, tp);
+   rtl_tx(dev, tp);
 
if (status & tp->event_slow) {
enable_mask &= ~tp->event_slow;
-- 
2.17.1



[PATCH AUTOSEL 4.14 09/19] net: fec: don't dump RX FIFO register when not available

2018-10-30 Thread Sasha Levin
From: Fugang Duan 

[ Upstream commit ec20a63aa8b8ec3223fb25cdb2a49f9f9dfda88c ]

Commit db65f35f50e0 ("net: fec: add support of ethtool get_regs") introduce
ethool "--register-dump" interface to dump all FEC registers.

But not all silicon implementations of the Freescale FEC hardware module
have the FRBR (FIFO Receive Bound Register) and FRSR (FIFO Receive Start
Register) register, so we should not be trying to dump them on those that
don't.

To fix it we create a quirk flag, FEC_QUIRK_HAS_RFREG, and check it before
dump those RX FIFO registers.

Signed-off-by: Fugang Duan 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/freescale/fec.h  |  4 
 drivers/net/ethernet/freescale/fec_main.c | 16 
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec.h 
b/drivers/net/ethernet/freescale/fec.h
index 44720f83af27..4d4f16ad88c3 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -451,6 +451,10 @@ struct bufdesc_ex {
  * initialisation.
  */
 #define FEC_QUIRK_MIB_CLEAR(1 << 15)
+/* Only i.MX25/i.MX27/i.MX28 controller supports FRBR,FRSR registers,
+ * those FIFO receive registers are resolved in other platforms.
+ */
+#define FEC_QUIRK_HAS_FRREG(1 << 16)
 
 struct bufdesc_prop {
int qid;
diff --git a/drivers/net/ethernet/freescale/fec_main.c 
b/drivers/net/ethernet/freescale/fec_main.c
index eb2ea231c7ca..01fb35f66276 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -89,14 +89,16 @@ static struct platform_device_id fec_devtype[] = {
.driver_data = 0,
}, {
.name = "imx25-fec",
-   .driver_data = FEC_QUIRK_USE_GASKET | FEC_QUIRK_MIB_CLEAR,
+   .driver_data = FEC_QUIRK_USE_GASKET | FEC_QUIRK_MIB_CLEAR |
+  FEC_QUIRK_HAS_FRREG,
}, {
.name = "imx27-fec",
-   .driver_data = FEC_QUIRK_MIB_CLEAR,
+   .driver_data = FEC_QUIRK_MIB_CLEAR | FEC_QUIRK_HAS_FRREG,
}, {
.name = "imx28-fec",
.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME |
-   FEC_QUIRK_SINGLE_MDIO | FEC_QUIRK_HAS_RACC,
+   FEC_QUIRK_SINGLE_MDIO | FEC_QUIRK_HAS_RACC |
+   FEC_QUIRK_HAS_FRREG,
}, {
.name = "imx6q-fec",
.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
@@ -2166,7 +2168,13 @@ static void fec_enet_get_regs(struct net_device *ndev,
memset(buf, 0, regs->len);
 
for (i = 0; i < ARRAY_SIZE(fec_enet_register_offset); i++) {
-   off = fec_enet_register_offset[i] / 4;
+   off = fec_enet_register_offset[i];
+
+   if ((off == FEC_R_BOUND || off == FEC_R_FSTART) &&
+   !(fep->quirks & FEC_QUIRK_HAS_FRREG))
+   continue;
+
+   off >>= 2;
buf[off] = readl([off]);
}
 }
-- 
2.17.1



[PATCH AUTOSEL 4.14 13/19] x86/fpu: Remove second definition of fpu in __fpu__restore_sig()

2018-10-30 Thread Sasha Levin
From: Sebastian Andrzej Siewior 

[ Upstream commit 6aa676761d4c1acfa31320e55fa1f83f3fcbbc7a ]

Commit:

  c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")

introduced the 'fpu' variable at top of __restore_xstate_sig(),
which now shadows the other definition:

  arch/x86/kernel/fpu/signal.c:318:28: warning: symbol 'fpu' shadows an earlier 
one
  arch/x86/kernel/fpu/signal.c:271:20: originally declared here

Remove the shadowed definition of 'fpu', as the two definitions are the same.

Signed-off-by: Sebastian Andrzej Siewior 
Reviewed-by: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Dave Hansen 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")
Link: http://lkml.kernel.org/r/20181016202525.29437-3-bige...@linutronix.de
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 arch/x86/kernel/fpu/signal.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c
index 23f1691670b6..61a949d84dfa 100644
--- a/arch/x86/kernel/fpu/signal.c
+++ b/arch/x86/kernel/fpu/signal.c
@@ -314,7 +314,6 @@ static int __fpu__restore_sig(void __user *buf, void __user 
*buf_fx, int size)
 * thread's fpu state, reconstruct fxstate from the fsave
 * header. Validate and sanitize the copied state.
 */
-   struct fpu *fpu = >thread.fpu;
struct user_i387_ia32_struct env;
int err = 0;
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 10/19] sched/fair: Fix the min_vruntime update logic in dequeue_entity()

2018-10-30 Thread Sasha Levin
From: Song Muchun 

[ Upstream commit 9845c49cc9bbb317a0bc9e9cf78d8e09d54c9af0 ]

The comment and the code around the update_min_vruntime() call in
dequeue_entity() are not in agreement.

>From commit:

  b60205c7c558 ("sched/fair: Fix min_vruntime tracking")

I think that we want to update min_vruntime when a task is sleeping/migrating.
So, the check is inverted there - fix it.

Signed-off-by: Song Muchun 
Cc: Linus Torvalds 
Cc: Mike Galbraith 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: b60205c7c558 ("sched/fair: Fix min_vruntime tracking")
Link: http://lkml.kernel.org/r/20181014112612.2614-1-smuc...@gmail.com
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index b2d699f28304..a2949d4e9f1b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3825,7 +3825,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity 
*se, int flags)
 * put back on, and if we advance min_vruntime, we'll be placed back
 * further than we started -- ie. we'll be penalized.
 */
-   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) == DEQUEUE_SAVE)
+   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) != DEQUEUE_SAVE)
update_min_vruntime(cfs_rq);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 11/19] perf tools: Fix use of alternatives to find JDIR

2018-10-30 Thread Sasha Levin
From: Jarod Wilson 

[ Upstream commit 36b8d4628d3cc8f5a748e508cce8673bc00fc63c ]

When a build is run from something like a cron job, the user's $PATH is
rather minimal, of note, not including /usr/sbin in my own case. Because
of that, an automated rpm package build ultimately fails to find
libperf-jvmti.so, because somewhere within the build, this happens...

  /bin/sh: alternatives: command not found
  /bin/sh: alternatives: command not found
  Makefile.config:849: No openjdk development package found, please install
  JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel

...and while the build continues, libperf-jvmti.so isn't built, and
things fall down when rpm tries to find all the %files specified. Exact
same system builds everything just fine when the job is launched from a
login shell instead of a cron job, since alternatives is in $PATH, so
openjdk is actually found.

The test required to get into this section of code actually specifies
the full path, as does a block just above it, so let's do that here too.

Signed-off-by: Jarod Wilson 
Acked-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: William Cohen 
Fixes: d4dfdf00d43e ("perf jvmti: Plug compilation into perf build")
Link: http://lkml.kernel.org/r/20180906221812.11167-1-ja...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/Makefile.config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 63f534a0902f..f362ee46506a 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -795,7 +795,7 @@ ifndef NO_JVMTI
 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print 
$$3}')
   else
 ifneq (,$(wildcard /usr/sbin/alternatives))
-  JDIR=$(shell alternatives --display java | tail -1 | cut -d' ' -f 5 | 
sed 's%/jre/bin/java.%%g')
+  JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' 
-f 5 | sed 's%/jre/bin/java.%%g')
 endif
   endif
   ifndef JDIR
-- 
2.17.1



[PATCH AUTOSEL 4.14 14/19] net: qla3xxx: Remove overflowing shift statement

2018-10-30 Thread Sasha Levin
From: Nathan Chancellor 

[ Upstream commit 8c3bf9b62b667456a57aefcf1689e826df146159 ]

Clang currently warns:

drivers/net/ethernet/qlogic/qla3xxx.c:384:24: warning: signed shift
result (0xF) requires 37 bits to represent, but 'int' only has
32 bits [-Wshift-overflow]
((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
  ~~ ^  ~~
1 warning generated.

The warning is certainly accurate since ISP_NVRAM_MASK is defined as
(0x000F << 16) which is then shifted by 16, resulting in 64424509440,
well above UINT_MAX.

Given that this is the only location in this driver where ISP_NVRAM_MASK
is shifted again, it seems likely that ISP_NVRAM_MASK was originally
defined without a shift and during the move of the shift to the
definition, this statement wasn't properly removed (since ISP_NVRAM_MASK
is used in the statenent right above this). Only the maintainers can
confirm this since this statment has been here since the driver was
first added to the kernel.

Link: https://github.com/ClangBuiltLinux/linux/issues/127
Signed-off-by: Nathan Chancellor 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/qlogic/qla3xxx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c 
b/drivers/net/ethernet/qlogic/qla3xxx.c
index 2991179c2fd0..080d00520362 100644
--- a/drivers/net/ethernet/qlogic/qla3xxx.c
+++ b/drivers/net/ethernet/qlogic/qla3xxx.c
@@ -380,8 +380,6 @@ static void fm93c56a_select(struct ql3_adapter *qdev)
 
qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_1;
ql_write_nvram_reg(qdev, spir, ISP_NVRAM_MASK | qdev->eeprom_cmd_data);
-   ql_write_nvram_reg(qdev, spir,
-  ((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.14 08/19] sparc64: Make proc_id signed.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit b3e1eb8e7ac9aaa283989496651d99267c4cad6c ]

So that when it is unset, ie. '-1', userspace can see it
properly.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/include/asm/cpudata_64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/include/asm/cpudata_64.h 
b/arch/sparc/include/asm/cpudata_64.h
index 666d6b5c0440..9c3fc03abe9a 100644
--- a/arch/sparc/include/asm/cpudata_64.h
+++ b/arch/sparc/include/asm/cpudata_64.h
@@ -28,7 +28,7 @@ typedef struct {
unsigned short  sock_id;/* physical package */
unsigned short  core_id;
unsigned short  max_cache_id;   /* groupings of highest shared cache */
-   unsigned short  proc_id;/* strand (aka HW thread) id */
+   signed shortproc_id;/* strand (aka HW thread) id */
 } cpuinfo_sparc;
 
 DECLARE_PER_CPU(cpuinfo_sparc, __cpu_data);
-- 
2.17.1



[PATCH AUTOSEL 4.14 09/19] net: fec: don't dump RX FIFO register when not available

2018-10-30 Thread Sasha Levin
From: Fugang Duan 

[ Upstream commit ec20a63aa8b8ec3223fb25cdb2a49f9f9dfda88c ]

Commit db65f35f50e0 ("net: fec: add support of ethtool get_regs") introduce
ethool "--register-dump" interface to dump all FEC registers.

But not all silicon implementations of the Freescale FEC hardware module
have the FRBR (FIFO Receive Bound Register) and FRSR (FIFO Receive Start
Register) register, so we should not be trying to dump them on those that
don't.

To fix it we create a quirk flag, FEC_QUIRK_HAS_RFREG, and check it before
dump those RX FIFO registers.

Signed-off-by: Fugang Duan 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/freescale/fec.h  |  4 
 drivers/net/ethernet/freescale/fec_main.c | 16 
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec.h 
b/drivers/net/ethernet/freescale/fec.h
index 44720f83af27..4d4f16ad88c3 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -451,6 +451,10 @@ struct bufdesc_ex {
  * initialisation.
  */
 #define FEC_QUIRK_MIB_CLEAR(1 << 15)
+/* Only i.MX25/i.MX27/i.MX28 controller supports FRBR,FRSR registers,
+ * those FIFO receive registers are resolved in other platforms.
+ */
+#define FEC_QUIRK_HAS_FRREG(1 << 16)
 
 struct bufdesc_prop {
int qid;
diff --git a/drivers/net/ethernet/freescale/fec_main.c 
b/drivers/net/ethernet/freescale/fec_main.c
index eb2ea231c7ca..01fb35f66276 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -89,14 +89,16 @@ static struct platform_device_id fec_devtype[] = {
.driver_data = 0,
}, {
.name = "imx25-fec",
-   .driver_data = FEC_QUIRK_USE_GASKET | FEC_QUIRK_MIB_CLEAR,
+   .driver_data = FEC_QUIRK_USE_GASKET | FEC_QUIRK_MIB_CLEAR |
+  FEC_QUIRK_HAS_FRREG,
}, {
.name = "imx27-fec",
-   .driver_data = FEC_QUIRK_MIB_CLEAR,
+   .driver_data = FEC_QUIRK_MIB_CLEAR | FEC_QUIRK_HAS_FRREG,
}, {
.name = "imx28-fec",
.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_SWAP_FRAME |
-   FEC_QUIRK_SINGLE_MDIO | FEC_QUIRK_HAS_RACC,
+   FEC_QUIRK_SINGLE_MDIO | FEC_QUIRK_HAS_RACC |
+   FEC_QUIRK_HAS_FRREG,
}, {
.name = "imx6q-fec",
.driver_data = FEC_QUIRK_ENET_MAC | FEC_QUIRK_HAS_GBIT |
@@ -2166,7 +2168,13 @@ static void fec_enet_get_regs(struct net_device *ndev,
memset(buf, 0, regs->len);
 
for (i = 0; i < ARRAY_SIZE(fec_enet_register_offset); i++) {
-   off = fec_enet_register_offset[i] / 4;
+   off = fec_enet_register_offset[i];
+
+   if ((off == FEC_R_BOUND || off == FEC_R_FSTART) &&
+   !(fep->quirks & FEC_QUIRK_HAS_FRREG))
+   continue;
+
+   off >>= 2;
buf[off] = readl([off]);
}
 }
-- 
2.17.1



[PATCH AUTOSEL 4.14 13/19] x86/fpu: Remove second definition of fpu in __fpu__restore_sig()

2018-10-30 Thread Sasha Levin
From: Sebastian Andrzej Siewior 

[ Upstream commit 6aa676761d4c1acfa31320e55fa1f83f3fcbbc7a ]

Commit:

  c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")

introduced the 'fpu' variable at top of __restore_xstate_sig(),
which now shadows the other definition:

  arch/x86/kernel/fpu/signal.c:318:28: warning: symbol 'fpu' shadows an earlier 
one
  arch/x86/kernel/fpu/signal.c:271:20: originally declared here

Remove the shadowed definition of 'fpu', as the two definitions are the same.

Signed-off-by: Sebastian Andrzej Siewior 
Reviewed-by: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Dave Hansen 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")
Link: http://lkml.kernel.org/r/20181016202525.29437-3-bige...@linutronix.de
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 arch/x86/kernel/fpu/signal.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c
index 23f1691670b6..61a949d84dfa 100644
--- a/arch/x86/kernel/fpu/signal.c
+++ b/arch/x86/kernel/fpu/signal.c
@@ -314,7 +314,6 @@ static int __fpu__restore_sig(void __user *buf, void __user 
*buf_fx, int size)
 * thread's fpu state, reconstruct fxstate from the fsave
 * header. Validate and sanitize the copied state.
 */
-   struct fpu *fpu = >thread.fpu;
struct user_i387_ia32_struct env;
int err = 0;
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 10/19] sched/fair: Fix the min_vruntime update logic in dequeue_entity()

2018-10-30 Thread Sasha Levin
From: Song Muchun 

[ Upstream commit 9845c49cc9bbb317a0bc9e9cf78d8e09d54c9af0 ]

The comment and the code around the update_min_vruntime() call in
dequeue_entity() are not in agreement.

>From commit:

  b60205c7c558 ("sched/fair: Fix min_vruntime tracking")

I think that we want to update min_vruntime when a task is sleeping/migrating.
So, the check is inverted there - fix it.

Signed-off-by: Song Muchun 
Cc: Linus Torvalds 
Cc: Mike Galbraith 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: b60205c7c558 ("sched/fair: Fix min_vruntime tracking")
Link: http://lkml.kernel.org/r/20181014112612.2614-1-smuc...@gmail.com
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index b2d699f28304..a2949d4e9f1b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3825,7 +3825,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity 
*se, int flags)
 * put back on, and if we advance min_vruntime, we'll be placed back
 * further than we started -- ie. we'll be penalized.
 */
-   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) == DEQUEUE_SAVE)
+   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) != DEQUEUE_SAVE)
update_min_vruntime(cfs_rq);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.14 11/19] perf tools: Fix use of alternatives to find JDIR

2018-10-30 Thread Sasha Levin
From: Jarod Wilson 

[ Upstream commit 36b8d4628d3cc8f5a748e508cce8673bc00fc63c ]

When a build is run from something like a cron job, the user's $PATH is
rather minimal, of note, not including /usr/sbin in my own case. Because
of that, an automated rpm package build ultimately fails to find
libperf-jvmti.so, because somewhere within the build, this happens...

  /bin/sh: alternatives: command not found
  /bin/sh: alternatives: command not found
  Makefile.config:849: No openjdk development package found, please install
  JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel

...and while the build continues, libperf-jvmti.so isn't built, and
things fall down when rpm tries to find all the %files specified. Exact
same system builds everything just fine when the job is launched from a
login shell instead of a cron job, since alternatives is in $PATH, so
openjdk is actually found.

The test required to get into this section of code actually specifies
the full path, as does a block just above it, so let's do that here too.

Signed-off-by: Jarod Wilson 
Acked-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: William Cohen 
Fixes: d4dfdf00d43e ("perf jvmti: Plug compilation into perf build")
Link: http://lkml.kernel.org/r/20180906221812.11167-1-ja...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/Makefile.config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 63f534a0902f..f362ee46506a 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -795,7 +795,7 @@ ifndef NO_JVMTI
 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print 
$$3}')
   else
 ifneq (,$(wildcard /usr/sbin/alternatives))
-  JDIR=$(shell alternatives --display java | tail -1 | cut -d' ' -f 5 | 
sed 's%/jre/bin/java.%%g')
+  JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' 
-f 5 | sed 's%/jre/bin/java.%%g')
 endif
   endif
   ifndef JDIR
-- 
2.17.1



[PATCH AUTOSEL 4.14 14/19] net: qla3xxx: Remove overflowing shift statement

2018-10-30 Thread Sasha Levin
From: Nathan Chancellor 

[ Upstream commit 8c3bf9b62b667456a57aefcf1689e826df146159 ]

Clang currently warns:

drivers/net/ethernet/qlogic/qla3xxx.c:384:24: warning: signed shift
result (0xF) requires 37 bits to represent, but 'int' only has
32 bits [-Wshift-overflow]
((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
  ~~ ^  ~~
1 warning generated.

The warning is certainly accurate since ISP_NVRAM_MASK is defined as
(0x000F << 16) which is then shifted by 16, resulting in 64424509440,
well above UINT_MAX.

Given that this is the only location in this driver where ISP_NVRAM_MASK
is shifted again, it seems likely that ISP_NVRAM_MASK was originally
defined without a shift and during the move of the shift to the
definition, this statement wasn't properly removed (since ISP_NVRAM_MASK
is used in the statenent right above this). Only the maintainers can
confirm this since this statment has been here since the driver was
first added to the kernel.

Link: https://github.com/ClangBuiltLinux/linux/issues/127
Signed-off-by: Nathan Chancellor 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/qlogic/qla3xxx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c 
b/drivers/net/ethernet/qlogic/qla3xxx.c
index 2991179c2fd0..080d00520362 100644
--- a/drivers/net/ethernet/qlogic/qla3xxx.c
+++ b/drivers/net/ethernet/qlogic/qla3xxx.c
@@ -380,8 +380,6 @@ static void fm93c56a_select(struct ql3_adapter *qdev)
 
qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_1;
ql_write_nvram_reg(qdev, spir, ISP_NVRAM_MASK | qdev->eeprom_cmd_data);
-   ql_write_nvram_reg(qdev, spir,
-  ((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.14 08/19] sparc64: Make proc_id signed.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit b3e1eb8e7ac9aaa283989496651d99267c4cad6c ]

So that when it is unset, ie. '-1', userspace can see it
properly.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/include/asm/cpudata_64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/include/asm/cpudata_64.h 
b/arch/sparc/include/asm/cpudata_64.h
index 666d6b5c0440..9c3fc03abe9a 100644
--- a/arch/sparc/include/asm/cpudata_64.h
+++ b/arch/sparc/include/asm/cpudata_64.h
@@ -28,7 +28,7 @@ typedef struct {
unsigned short  sock_id;/* physical package */
unsigned short  core_id;
unsigned short  max_cache_id;   /* groupings of highest shared cache */
-   unsigned short  proc_id;/* strand (aka HW thread) id */
+   signed shortproc_id;/* strand (aka HW thread) id */
 } cpuinfo_sparc;
 
 DECLARE_PER_CPU(cpuinfo_sparc, __cpu_data);
-- 
2.17.1



[PATCH AUTOSEL 4.18 29/33] drm: Get ref on CRTC commit object when waiting for flip_done

2018-10-30 Thread Sasha Levin
From: Leo Li 

[ Upstream commit 4364bcb2cd21d042bde4776448417ddffbc54045 ]

This fixes a general protection fault, caused by accessing the contents
of a flip_done completion object that has already been freed. It occurs
due to the preemption of a non-blocking commit worker thread W by
another commit thread X. X continues to clear its atomic state at the
end, destroying the CRTC commit object that W still needs. Switching
back to W and accessing the commit objects then leads to bad results.

Worker W becomes preemptable when waiting for flip_done to complete. At
this point, a frequently occurring commit thread X can take over. Here's
an example where W is a worker thread that flips on both CRTCs, and X
does a legacy cursor update on both CRTCs:

...
 1. W does flip work
 2. W runs commit_hw_done()
 3. W waits for flip_done on CRTC 1
 4. > flip_done for CRTC 1 completes
 5. W finishes waiting for CRTC 1
 6. W waits for flip_done on CRTC 2

 7. > Preempted by X
 8. > flip_done for CRTC 2 completes
 9. X atomic_check: hw_done and flip_done are complete on all CRTCs
10. X updates cursor on both CRTCs
11. X destroys atomic state
12. X done

13. > Switch back to W
14. W waits for flip_done on CRTC 2
15. W raises general protection fault

The error looks like so:

general protection fault:  [#1] PREEMPT SMP PTI
**snip**
Call Trace:
 lock_acquire+0xa2/0x1b0
 _raw_spin_lock_irq+0x39/0x70
 wait_for_completion_timeout+0x31/0x130
 drm_atomic_helper_wait_for_flip_done+0x64/0x90 [drm_kms_helper]
 amdgpu_dm_atomic_commit_tail+0xcae/0xdd0 [amdgpu]
 commit_tail+0x3d/0x70 [drm_kms_helper]
 process_one_work+0x212/0x650
 worker_thread+0x49/0x420
 kthread+0xfb/0x130
 ret_from_fork+0x3a/0x50
Modules linked in: x86_pkg_temp_thermal amdgpu(O) chash(O)
gpu_sched(O) drm_kms_helper(O) syscopyarea sysfillrect sysimgblt
fb_sys_fops ttm(O) drm(O)

Note that i915 has this issue masked, since hw_done is signaled after
waiting for flip_done. Doing so will block the cursor update from
happening until hw_done is signaled, preventing the cursor commit from
destroying the state.

v2: The reference on the commit object needs to be obtained before
hw_done() is signaled, since that's the point where another commit
is allowed to modify the state. Assuming that the
new_crtc_state->commit object still exists within flip_done() is
incorrect.

Fix by getting a reference in setup_commit(), and releasing it
during default_clear().

Signed-off-by: Leo Li 
Reviewed-by: Daniel Vetter 
Signed-off-by: Harry Wentland 
Link: 
https://patchwork.freedesktop.org/patch/msgid/1539611200-6184-1-git-send-email-sunpeng...@amd.com
Signed-off-by: Sasha Levin 
---
 drivers/gpu/drm/drm_atomic.c|  5 +
 drivers/gpu/drm/drm_atomic_helper.c | 12 
 include/drm/drm_atomic.h| 11 +++
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 895741e9cd7d..52ccf1c31855 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -173,6 +173,11 @@ void drm_atomic_state_default_clear(struct 
drm_atomic_state *state)
state->crtcs[i].state = NULL;
state->crtcs[i].old_state = NULL;
state->crtcs[i].new_state = NULL;
+
+   if (state->crtcs[i].commit) {
+   drm_crtc_commit_put(state->crtcs[i].commit);
+   state->crtcs[i].commit = NULL;
+   }
}
 
for (i = 0; i < config->num_total_plane; i++) {
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 81e32199d3ef..abca95b970ea 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -1384,15 +1384,16 @@ EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
 void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
  struct drm_atomic_state *old_state)
 {
-   struct drm_crtc_state *new_crtc_state;
struct drm_crtc *crtc;
int i;
 
-   for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) {
-   struct drm_crtc_commit *commit = new_crtc_state->commit;
+   for (i = 0; i < dev->mode_config.num_crtc; i++) {
+   struct drm_crtc_commit *commit = old_state->crtcs[i].commit;
int ret;
 
-   if (!commit)
+   crtc = old_state->crtcs[i].ptr;
+
+   if (!crtc || !commit)
continue;
 
ret = wait_for_completion_timeout(>flip_done, 10 * HZ);
@@ -1906,6 +1907,9 @@ int drm_atomic_helper_setup_commit(struct 
drm_atomic_state *state,
drm_crtc_commit_get(commit);
 
commit->abort_completion = true;
+
+   state->crtcs[i].commit = commit;
+

[PATCH AUTOSEL 4.18 30/33] r8169: fix NAPI handling under high load

2018-10-30 Thread Sasha Levin
From: Heiner Kallweit 

[ Upstream commit 6b839b6cf9eada30b086effb51e5d6076bafc761 ]

rtl_rx() and rtl_tx() are called only if the respective bits are set
in the interrupt status register. Under high load NAPI may not be
able to process all data (work_done == budget) and it will schedule
subsequent calls to the poll callback.
rtl_ack_events() however resets the bits in the interrupt status
register, therefore subsequent calls to rtl8169_poll() won't call
rtl_rx() and rtl_tx() - chip interrupts are still disabled.

Fix this by calling rtl_rx() and rtl_tx() independent of the bits
set in the interrupt status register. Both functions will detect
if there's nothing to do for them.

Fixes: da78dbff2e05 ("r8169: remove work from irq handler.")
Signed-off-by: Heiner Kallweit 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/realtek/r8169.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index 2eea2b66d970..41bcbdd355f0 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7044,17 +7044,15 @@ static int rtl8169_poll(struct napi_struct *napi, int 
budget)
struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, 
napi);
struct net_device *dev = tp->dev;
u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow;
-   int work_done= 0;
+   int work_done;
u16 status;
 
status = rtl_get_events(tp);
rtl_ack_events(tp, status & ~tp->event_slow);
 
-   if (status & RTL_EVENT_NAPI_RX)
-   work_done = rtl_rx(dev, tp, (u32) budget);
+   work_done = rtl_rx(dev, tp, (u32) budget);
 
-   if (status & RTL_EVENT_NAPI_TX)
-   rtl_tx(dev, tp);
+   rtl_tx(dev, tp);
 
if (status & tp->event_slow) {
enable_mask &= ~tp->event_slow;
-- 
2.17.1



[PATCH AUTOSEL 4.14 05/19] perf vendor events intel: Fix wrong filter_band* values for uncore events

2018-10-30 Thread Sasha Levin
From: Jiri Olsa 

[ Upstream commit 94aafb74cee0002e2f2eb6dc5376f54d5951ab4d ]

Michael reported that he could not stat following event:

  $ perf stat -e unc_p_freq_ge_1200mhz_cycles -a -- ls
  event syntax error: '..e_1200mhz_cycles'
\___ value too big for format, maximum is 
255
  Run 'perf list' for a list of valid events

The event is unwrapped into:

  uncore_pcu/event=0xb,filter_band0=1200/

where filter_band0 format says it's one byte only:

  # cat uncore_pcu/format/filter_band0
  config1:0-7

while JSON files specifies bigger number:

  "Filter": "filter_band0=1200",

all the filter_band* formats show 1 byte width:

  # cat uncore_pcu/format/filter_band1
  config1:8-15
  # cat uncore_pcu/format/filter_band2
  config1:16-23
  # cat uncore_pcu/format/filter_band3
  config1:24-31

The reason of the issue is that filter_band* values are supposed to be
in 100Mhz units.. it's stated in the JSON help for the events, like:

  filter_band3=XXX, with XXX in 100Mhz units

This patch divides the filter_band* values by 100, plus there's couple
of changes that actually change the number completely, like:

  -"Filter": "edge=1,filter_band2=4000",
  +"Filter": "edge=1,filter_band2=30",

Reported-by: Michael Petlan 
Signed-off-by: Jiri Olsa 
Acked-by: Andi Kleen 
Cc: Alexander Shishkin 
Cc: Kan Liang 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20181010080339.GB15790@krava
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 .../arch/x86/ivytown/uncore-power.json   | 16 
 .../arch/x86/jaketown/uncore-power.json  | 16 
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json 
b/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
index d40498f2cb1e..635c09fda1d9 100644
--- a/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
+++ b/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
@@ -188,7 +188,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xb",
 "EventName": "UNC_P_FREQ_GE_1200MHZ_CYCLES",
-"Filter": "filter_band0=1200",
+"Filter": "filter_band0=12",
 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_1200mhz_cycles %",
 "PerPkg": "1",
@@ -199,7 +199,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xc",
 "EventName": "UNC_P_FREQ_GE_2000MHZ_CYCLES",
-"Filter": "filter_band1=2000",
+"Filter": "filter_band1=20",
 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_2000mhz_cycles %",
 "PerPkg": "1",
@@ -210,7 +210,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xd",
 "EventName": "UNC_P_FREQ_GE_3000MHZ_CYCLES",
-"Filter": "filter_band2=3000",
+"Filter": "filter_band2=30",
 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_3000mhz_cycles %",
 "PerPkg": "1",
@@ -221,7 +221,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xe",
 "EventName": "UNC_P_FREQ_GE_4000MHZ_CYCLES",
-"Filter": "filter_band3=4000",
+"Filter": "filter_band3=40",
 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_4000mhz_cycles %",
 "PerPkg": "1",
@@ -232,7 +232,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xb",
 "EventName": "UNC_P_FREQ_GE_1200MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band0=1200",
+"Filter": "edge=1,filter_band0=12",
 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_1200mhz_cycles %",
 "PerPkg": "1",
@@ -243,7 +243,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xc",
 "EventName": "UNC_P_FREQ_GE_2000MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band1=2000",
+"Filter": "edge=1,filter_band1=20",
 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_2000mhz_cycles %",
 "PerPkg": "1",
@@ -254,7 +254,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xd",
 "EventName": "UNC_P_FREQ_GE_3000MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band2=4000",
+"Filter": "edge=1,filter_band2=30",
 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_3000mhz_cycles %",
 "PerPkg": "1",
@@ -265,7 +265,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xe",
 "EventName": "UNC_P_FREQ_GE_4000MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band3=4000",
+"Filter": "edge=1,filter_band3=40",
 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 

[PATCH AUTOSEL 4.14 12/19] perf cpu_map: Align cpu map synthesized events properly.

2018-10-30 Thread Sasha Levin
From: David Miller 

[ Upstream commit 0ed149cf5239cc6e7e65bf00f769e8f1e91076c0 ]

The size of the resulting cpu map can be smaller than a multiple of
sizeof(u64), resulting in SIGBUS on cpus like Sparc as the next event
will not be aligned properly.

Signed-off-by: David S. Miller 
Cc: Jiri Olsa 
Cc: Kan Liang 
Fixes: 6c872901af07 ("perf cpu_map: Add cpu_map event synthesize function")
Link: 
http://lkml.kernel.org/r/20181011.224655.716771175766946817.da...@davemloft.net
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/event.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index fc690fecbfd6..a19e840db54a 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -951,6 +951,7 @@ void *cpu_map_data__alloc(struct cpu_map *map, size_t 
*size, u16 *type, int *max
}
 
*size += sizeof(struct cpu_map_data);
+   *size = PERF_ALIGN(*size, sizeof(u64));
return zalloc(*size);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.18 31/33] selftests: ftrace: Add synthetic event syntax testcase

2018-10-30 Thread Sasha Levin
From: Masami Hiramatsu 

[ Upstream commit ba0e41ca81b935b958006c7120466e2217357827 ]

Add a testcase to check the syntax and field types for
synthetic_events interface.

Link: 
http://lkml.kernel.org/r/153986838264.18251.16627517536956299922.stgit@devbox

Acked-by: Shuah Khan 
Signed-off-by: Masami Hiramatsu 
Signed-off-by: Steven Rostedt (VMware) 
Signed-off-by: Sasha Levin 
---
 .../trigger-synthetic-event-syntax.tc | 80 +++
 1 file changed, 80 insertions(+)
 create mode 100644 
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc

diff --git 
a/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
new file mode 100644
index ..88e6c3f43006
--- /dev/null
+++ 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
@@ -0,0 +1,80 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: event trigger - test synthetic_events syntax parser
+
+do_reset() {
+reset_trigger
+echo > set_event
+clear_trace
+}
+
+fail() { #msg
+do_reset
+echo $1
+exit_fail
+}
+
+if [ ! -f set_event ]; then
+echo "event tracing is not supported"
+exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+echo "synthetic event is not supported"
+exit_unsupported
+fi
+
+reset_tracer
+do_reset
+
+echo "Test synthetic_events syntax parser"
+
+echo > synthetic_events
+
+# synthetic event must have a field
+! echo "myevent" >> synthetic_events
+echo "myevent u64 var1" >> synthetic_events
+
+# synthetic event must be found in synthetic_events
+grep "myevent[[:space:]]u64 var1" synthetic_events
+
+# it is not possible to add same name event
+! echo "myevent u64 var2" >> synthetic_events
+
+# Non-append open will cleanup all events and add new one
+echo "myevent u64 var2" > synthetic_events
+
+# multiple fields with different spaces
+echo "myevent u64 var1; u64 var2;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ; u64 var2 ;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ;u64 var2" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+
+# test field types
+echo "myevent u32 var" > synthetic_events
+echo "myevent u16 var" > synthetic_events
+echo "myevent u8 var" > synthetic_events
+echo "myevent s64 var" > synthetic_events
+echo "myevent s32 var" > synthetic_events
+echo "myevent s16 var" > synthetic_events
+echo "myevent s8 var" > synthetic_events
+
+echo "myevent char var" > synthetic_events
+echo "myevent int var" > synthetic_events
+echo "myevent long var" > synthetic_events
+echo "myevent pid_t var" > synthetic_events
+
+echo "myevent unsigned char var" > synthetic_events
+echo "myevent unsigned int var" > synthetic_events
+echo "myevent unsigned long var" > synthetic_events
+grep "myevent[[:space:]]unsigned long var" synthetic_events
+
+# test string type
+echo "myevent char var[10]" > synthetic_events
+grep "myevent[[:space:]]char\[10\] var" synthetic_events
+
+do_reset
+
+exit 0
-- 
2.17.1



[PATCH AUTOSEL 4.14 06/19] sparc: Fix single-pcr perf event counter management.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit cfdc3170d214046b9509183fe9b9544dc644d40b ]

It is important to clear the hw->state value for non-stopped events
when they are added into the PMU.  Otherwise when the event is
scheduled out, we won't read the counter because HES_UPTODATE is still
set.  This breaks 'perf stat' and similar use cases, causing all the
events to show zero.

This worked for multi-pcr because we make explicit sparc_pmu_start()
calls in calculate_multiple_pcrs().  calculate_single_pcr() doesn't do
this because the idea there is to accumulate all of the counter
settings into the single pcr value.  So we have to add explicit
hw->state handling there.

Like x86, we use the PERF_HES_ARCH bit to track truly stopped events
so that we don't accidently start them on a reload.

Related to all of this, sparc_pmu_start() is missing a userpage update
so add it.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index 5c1f54758312..8a569b09d2c2 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -927,6 +927,8 @@ static void read_in_all_counters(struct cpu_hw_events *cpuc)
sparc_perf_event_update(cp, >hw,
cpuc->current_idx[i]);
cpuc->current_idx[i] = PIC_NO_INDEX;
+   if (cp->hw.state & PERF_HES_STOPPED)
+   cp->hw.state |= PERF_HES_ARCH;
}
}
 }
@@ -959,10 +961,12 @@ static void calculate_single_pcr(struct cpu_hw_events 
*cpuc)
 
enc = perf_event_get_enc(cpuc->events[i]);
cpuc->pcr[0] &= ~mask_for_index(idx);
-   if (hwc->state & PERF_HES_STOPPED)
+   if (hwc->state & PERF_HES_ARCH) {
cpuc->pcr[0] |= nop_for_index(idx);
-   else
+   } else {
cpuc->pcr[0] |= event_encoding(enc, idx);
+   hwc->state = 0;
+   }
}
 out:
cpuc->pcr[0] |= cpuc->event[0]->hw.config_base;
@@ -988,6 +992,9 @@ static void calculate_multiple_pcrs(struct cpu_hw_events 
*cpuc)
 
cpuc->current_idx[i] = idx;
 
+   if (cp->hw.state & PERF_HES_ARCH)
+   continue;
+
sparc_pmu_start(cp, PERF_EF_RELOAD);
}
 out:
@@ -1079,6 +1086,8 @@ static void sparc_pmu_start(struct perf_event *event, int 
flags)
event->hw.state = 0;
 
sparc_pmu_enable_event(cpuc, >hw, idx);
+
+   perf_event_update_userpage(event);
 }
 
 static void sparc_pmu_stop(struct perf_event *event, int flags)
@@ -1371,9 +1380,9 @@ static int sparc_pmu_add(struct perf_event *event, int 
ef_flags)
cpuc->events[n0] = event->hw.event_base;
cpuc->current_idx[n0] = PIC_NO_INDEX;
 
-   event->hw.state = PERF_HES_UPTODATE;
+   event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
if (!(ef_flags & PERF_EF_START))
-   event->hw.state |= PERF_HES_STOPPED;
+   event->hw.state |= PERF_HES_ARCH;
 
/*
 * If group events scheduling transaction was started,
-- 
2.17.1



[PATCH AUTOSEL 4.18 29/33] drm: Get ref on CRTC commit object when waiting for flip_done

2018-10-30 Thread Sasha Levin
From: Leo Li 

[ Upstream commit 4364bcb2cd21d042bde4776448417ddffbc54045 ]

This fixes a general protection fault, caused by accessing the contents
of a flip_done completion object that has already been freed. It occurs
due to the preemption of a non-blocking commit worker thread W by
another commit thread X. X continues to clear its atomic state at the
end, destroying the CRTC commit object that W still needs. Switching
back to W and accessing the commit objects then leads to bad results.

Worker W becomes preemptable when waiting for flip_done to complete. At
this point, a frequently occurring commit thread X can take over. Here's
an example where W is a worker thread that flips on both CRTCs, and X
does a legacy cursor update on both CRTCs:

...
 1. W does flip work
 2. W runs commit_hw_done()
 3. W waits for flip_done on CRTC 1
 4. > flip_done for CRTC 1 completes
 5. W finishes waiting for CRTC 1
 6. W waits for flip_done on CRTC 2

 7. > Preempted by X
 8. > flip_done for CRTC 2 completes
 9. X atomic_check: hw_done and flip_done are complete on all CRTCs
10. X updates cursor on both CRTCs
11. X destroys atomic state
12. X done

13. > Switch back to W
14. W waits for flip_done on CRTC 2
15. W raises general protection fault

The error looks like so:

general protection fault:  [#1] PREEMPT SMP PTI
**snip**
Call Trace:
 lock_acquire+0xa2/0x1b0
 _raw_spin_lock_irq+0x39/0x70
 wait_for_completion_timeout+0x31/0x130
 drm_atomic_helper_wait_for_flip_done+0x64/0x90 [drm_kms_helper]
 amdgpu_dm_atomic_commit_tail+0xcae/0xdd0 [amdgpu]
 commit_tail+0x3d/0x70 [drm_kms_helper]
 process_one_work+0x212/0x650
 worker_thread+0x49/0x420
 kthread+0xfb/0x130
 ret_from_fork+0x3a/0x50
Modules linked in: x86_pkg_temp_thermal amdgpu(O) chash(O)
gpu_sched(O) drm_kms_helper(O) syscopyarea sysfillrect sysimgblt
fb_sys_fops ttm(O) drm(O)

Note that i915 has this issue masked, since hw_done is signaled after
waiting for flip_done. Doing so will block the cursor update from
happening until hw_done is signaled, preventing the cursor commit from
destroying the state.

v2: The reference on the commit object needs to be obtained before
hw_done() is signaled, since that's the point where another commit
is allowed to modify the state. Assuming that the
new_crtc_state->commit object still exists within flip_done() is
incorrect.

Fix by getting a reference in setup_commit(), and releasing it
during default_clear().

Signed-off-by: Leo Li 
Reviewed-by: Daniel Vetter 
Signed-off-by: Harry Wentland 
Link: 
https://patchwork.freedesktop.org/patch/msgid/1539611200-6184-1-git-send-email-sunpeng...@amd.com
Signed-off-by: Sasha Levin 
---
 drivers/gpu/drm/drm_atomic.c|  5 +
 drivers/gpu/drm/drm_atomic_helper.c | 12 
 include/drm/drm_atomic.h| 11 +++
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 895741e9cd7d..52ccf1c31855 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -173,6 +173,11 @@ void drm_atomic_state_default_clear(struct 
drm_atomic_state *state)
state->crtcs[i].state = NULL;
state->crtcs[i].old_state = NULL;
state->crtcs[i].new_state = NULL;
+
+   if (state->crtcs[i].commit) {
+   drm_crtc_commit_put(state->crtcs[i].commit);
+   state->crtcs[i].commit = NULL;
+   }
}
 
for (i = 0; i < config->num_total_plane; i++) {
diff --git a/drivers/gpu/drm/drm_atomic_helper.c 
b/drivers/gpu/drm/drm_atomic_helper.c
index 81e32199d3ef..abca95b970ea 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -1384,15 +1384,16 @@ EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
 void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
  struct drm_atomic_state *old_state)
 {
-   struct drm_crtc_state *new_crtc_state;
struct drm_crtc *crtc;
int i;
 
-   for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) {
-   struct drm_crtc_commit *commit = new_crtc_state->commit;
+   for (i = 0; i < dev->mode_config.num_crtc; i++) {
+   struct drm_crtc_commit *commit = old_state->crtcs[i].commit;
int ret;
 
-   if (!commit)
+   crtc = old_state->crtcs[i].ptr;
+
+   if (!crtc || !commit)
continue;
 
ret = wait_for_completion_timeout(>flip_done, 10 * HZ);
@@ -1906,6 +1907,9 @@ int drm_atomic_helper_setup_commit(struct 
drm_atomic_state *state,
drm_crtc_commit_get(commit);
 
commit->abort_completion = true;
+
+   state->crtcs[i].commit = commit;
+

[PATCH AUTOSEL 4.18 30/33] r8169: fix NAPI handling under high load

2018-10-30 Thread Sasha Levin
From: Heiner Kallweit 

[ Upstream commit 6b839b6cf9eada30b086effb51e5d6076bafc761 ]

rtl_rx() and rtl_tx() are called only if the respective bits are set
in the interrupt status register. Under high load NAPI may not be
able to process all data (work_done == budget) and it will schedule
subsequent calls to the poll callback.
rtl_ack_events() however resets the bits in the interrupt status
register, therefore subsequent calls to rtl8169_poll() won't call
rtl_rx() and rtl_tx() - chip interrupts are still disabled.

Fix this by calling rtl_rx() and rtl_tx() independent of the bits
set in the interrupt status register. Both functions will detect
if there's nothing to do for them.

Fixes: da78dbff2e05 ("r8169: remove work from irq handler.")
Signed-off-by: Heiner Kallweit 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/realtek/r8169.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index 2eea2b66d970..41bcbdd355f0 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7044,17 +7044,15 @@ static int rtl8169_poll(struct napi_struct *napi, int 
budget)
struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, 
napi);
struct net_device *dev = tp->dev;
u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow;
-   int work_done= 0;
+   int work_done;
u16 status;
 
status = rtl_get_events(tp);
rtl_ack_events(tp, status & ~tp->event_slow);
 
-   if (status & RTL_EVENT_NAPI_RX)
-   work_done = rtl_rx(dev, tp, (u32) budget);
+   work_done = rtl_rx(dev, tp, (u32) budget);
 
-   if (status & RTL_EVENT_NAPI_TX)
-   rtl_tx(dev, tp);
+   rtl_tx(dev, tp);
 
if (status & tp->event_slow) {
enable_mask &= ~tp->event_slow;
-- 
2.17.1



[PATCH AUTOSEL 4.14 05/19] perf vendor events intel: Fix wrong filter_band* values for uncore events

2018-10-30 Thread Sasha Levin
From: Jiri Olsa 

[ Upstream commit 94aafb74cee0002e2f2eb6dc5376f54d5951ab4d ]

Michael reported that he could not stat following event:

  $ perf stat -e unc_p_freq_ge_1200mhz_cycles -a -- ls
  event syntax error: '..e_1200mhz_cycles'
\___ value too big for format, maximum is 
255
  Run 'perf list' for a list of valid events

The event is unwrapped into:

  uncore_pcu/event=0xb,filter_band0=1200/

where filter_band0 format says it's one byte only:

  # cat uncore_pcu/format/filter_band0
  config1:0-7

while JSON files specifies bigger number:

  "Filter": "filter_band0=1200",

all the filter_band* formats show 1 byte width:

  # cat uncore_pcu/format/filter_band1
  config1:8-15
  # cat uncore_pcu/format/filter_band2
  config1:16-23
  # cat uncore_pcu/format/filter_band3
  config1:24-31

The reason of the issue is that filter_band* values are supposed to be
in 100Mhz units.. it's stated in the JSON help for the events, like:

  filter_band3=XXX, with XXX in 100Mhz units

This patch divides the filter_band* values by 100, plus there's couple
of changes that actually change the number completely, like:

  -"Filter": "edge=1,filter_band2=4000",
  +"Filter": "edge=1,filter_band2=30",

Reported-by: Michael Petlan 
Signed-off-by: Jiri Olsa 
Acked-by: Andi Kleen 
Cc: Alexander Shishkin 
Cc: Kan Liang 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20181010080339.GB15790@krava
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 .../arch/x86/ivytown/uncore-power.json   | 16 
 .../arch/x86/jaketown/uncore-power.json  | 16 
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json 
b/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
index d40498f2cb1e..635c09fda1d9 100644
--- a/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
+++ b/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
@@ -188,7 +188,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xb",
 "EventName": "UNC_P_FREQ_GE_1200MHZ_CYCLES",
-"Filter": "filter_band0=1200",
+"Filter": "filter_band0=12",
 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_1200mhz_cycles %",
 "PerPkg": "1",
@@ -199,7 +199,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xc",
 "EventName": "UNC_P_FREQ_GE_2000MHZ_CYCLES",
-"Filter": "filter_band1=2000",
+"Filter": "filter_band1=20",
 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_2000mhz_cycles %",
 "PerPkg": "1",
@@ -210,7 +210,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xd",
 "EventName": "UNC_P_FREQ_GE_3000MHZ_CYCLES",
-"Filter": "filter_band2=3000",
+"Filter": "filter_band2=30",
 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_3000mhz_cycles %",
 "PerPkg": "1",
@@ -221,7 +221,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xe",
 "EventName": "UNC_P_FREQ_GE_4000MHZ_CYCLES",
-"Filter": "filter_band3=4000",
+"Filter": "filter_band3=40",
 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_4000mhz_cycles %",
 "PerPkg": "1",
@@ -232,7 +232,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xb",
 "EventName": "UNC_P_FREQ_GE_1200MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band0=1200",
+"Filter": "edge=1,filter_band0=12",
 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_1200mhz_cycles %",
 "PerPkg": "1",
@@ -243,7 +243,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xc",
 "EventName": "UNC_P_FREQ_GE_2000MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band1=2000",
+"Filter": "edge=1,filter_band1=20",
 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_2000mhz_cycles %",
 "PerPkg": "1",
@@ -254,7 +254,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xd",
 "EventName": "UNC_P_FREQ_GE_3000MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band2=4000",
+"Filter": "edge=1,filter_band2=30",
 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_3000mhz_cycles %",
 "PerPkg": "1",
@@ -265,7 +265,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xe",
 "EventName": "UNC_P_FREQ_GE_4000MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band3=4000",
+"Filter": "edge=1,filter_band3=40",
 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 

[PATCH AUTOSEL 4.14 12/19] perf cpu_map: Align cpu map synthesized events properly.

2018-10-30 Thread Sasha Levin
From: David Miller 

[ Upstream commit 0ed149cf5239cc6e7e65bf00f769e8f1e91076c0 ]

The size of the resulting cpu map can be smaller than a multiple of
sizeof(u64), resulting in SIGBUS on cpus like Sparc as the next event
will not be aligned properly.

Signed-off-by: David S. Miller 
Cc: Jiri Olsa 
Cc: Kan Liang 
Fixes: 6c872901af07 ("perf cpu_map: Add cpu_map event synthesize function")
Link: 
http://lkml.kernel.org/r/20181011.224655.716771175766946817.da...@davemloft.net
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/event.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index fc690fecbfd6..a19e840db54a 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -951,6 +951,7 @@ void *cpu_map_data__alloc(struct cpu_map *map, size_t 
*size, u16 *type, int *max
}
 
*size += sizeof(struct cpu_map_data);
+   *size = PERF_ALIGN(*size, sizeof(u64));
return zalloc(*size);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.18 31/33] selftests: ftrace: Add synthetic event syntax testcase

2018-10-30 Thread Sasha Levin
From: Masami Hiramatsu 

[ Upstream commit ba0e41ca81b935b958006c7120466e2217357827 ]

Add a testcase to check the syntax and field types for
synthetic_events interface.

Link: 
http://lkml.kernel.org/r/153986838264.18251.16627517536956299922.stgit@devbox

Acked-by: Shuah Khan 
Signed-off-by: Masami Hiramatsu 
Signed-off-by: Steven Rostedt (VMware) 
Signed-off-by: Sasha Levin 
---
 .../trigger-synthetic-event-syntax.tc | 80 +++
 1 file changed, 80 insertions(+)
 create mode 100644 
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc

diff --git 
a/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
new file mode 100644
index ..88e6c3f43006
--- /dev/null
+++ 
b/tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-synthetic-event-syntax.tc
@@ -0,0 +1,80 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: event trigger - test synthetic_events syntax parser
+
+do_reset() {
+reset_trigger
+echo > set_event
+clear_trace
+}
+
+fail() { #msg
+do_reset
+echo $1
+exit_fail
+}
+
+if [ ! -f set_event ]; then
+echo "event tracing is not supported"
+exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+echo "synthetic event is not supported"
+exit_unsupported
+fi
+
+reset_tracer
+do_reset
+
+echo "Test synthetic_events syntax parser"
+
+echo > synthetic_events
+
+# synthetic event must have a field
+! echo "myevent" >> synthetic_events
+echo "myevent u64 var1" >> synthetic_events
+
+# synthetic event must be found in synthetic_events
+grep "myevent[[:space:]]u64 var1" synthetic_events
+
+# it is not possible to add same name event
+! echo "myevent u64 var2" >> synthetic_events
+
+# Non-append open will cleanup all events and add new one
+echo "myevent u64 var2" > synthetic_events
+
+# multiple fields with different spaces
+echo "myevent u64 var1; u64 var2;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ; u64 var2 ;" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+echo "myevent u64 var1 ;u64 var2" > synthetic_events
+grep "myevent[[:space:]]u64 var1; u64 var2" synthetic_events
+
+# test field types
+echo "myevent u32 var" > synthetic_events
+echo "myevent u16 var" > synthetic_events
+echo "myevent u8 var" > synthetic_events
+echo "myevent s64 var" > synthetic_events
+echo "myevent s32 var" > synthetic_events
+echo "myevent s16 var" > synthetic_events
+echo "myevent s8 var" > synthetic_events
+
+echo "myevent char var" > synthetic_events
+echo "myevent int var" > synthetic_events
+echo "myevent long var" > synthetic_events
+echo "myevent pid_t var" > synthetic_events
+
+echo "myevent unsigned char var" > synthetic_events
+echo "myevent unsigned int var" > synthetic_events
+echo "myevent unsigned long var" > synthetic_events
+grep "myevent[[:space:]]unsigned long var" synthetic_events
+
+# test string type
+echo "myevent char var[10]" > synthetic_events
+grep "myevent[[:space:]]char\[10\] var" synthetic_events
+
+do_reset
+
+exit 0
-- 
2.17.1



[PATCH AUTOSEL 4.14 06/19] sparc: Fix single-pcr perf event counter management.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit cfdc3170d214046b9509183fe9b9544dc644d40b ]

It is important to clear the hw->state value for non-stopped events
when they are added into the PMU.  Otherwise when the event is
scheduled out, we won't read the counter because HES_UPTODATE is still
set.  This breaks 'perf stat' and similar use cases, causing all the
events to show zero.

This worked for multi-pcr because we make explicit sparc_pmu_start()
calls in calculate_multiple_pcrs().  calculate_single_pcr() doesn't do
this because the idea there is to accumulate all of the counter
settings into the single pcr value.  So we have to add explicit
hw->state handling there.

Like x86, we use the PERF_HES_ARCH bit to track truly stopped events
so that we don't accidently start them on a reload.

Related to all of this, sparc_pmu_start() is missing a userpage update
so add it.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index 5c1f54758312..8a569b09d2c2 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -927,6 +927,8 @@ static void read_in_all_counters(struct cpu_hw_events *cpuc)
sparc_perf_event_update(cp, >hw,
cpuc->current_idx[i]);
cpuc->current_idx[i] = PIC_NO_INDEX;
+   if (cp->hw.state & PERF_HES_STOPPED)
+   cp->hw.state |= PERF_HES_ARCH;
}
}
 }
@@ -959,10 +961,12 @@ static void calculate_single_pcr(struct cpu_hw_events 
*cpuc)
 
enc = perf_event_get_enc(cpuc->events[i]);
cpuc->pcr[0] &= ~mask_for_index(idx);
-   if (hwc->state & PERF_HES_STOPPED)
+   if (hwc->state & PERF_HES_ARCH) {
cpuc->pcr[0] |= nop_for_index(idx);
-   else
+   } else {
cpuc->pcr[0] |= event_encoding(enc, idx);
+   hwc->state = 0;
+   }
}
 out:
cpuc->pcr[0] |= cpuc->event[0]->hw.config_base;
@@ -988,6 +992,9 @@ static void calculate_multiple_pcrs(struct cpu_hw_events 
*cpuc)
 
cpuc->current_idx[i] = idx;
 
+   if (cp->hw.state & PERF_HES_ARCH)
+   continue;
+
sparc_pmu_start(cp, PERF_EF_RELOAD);
}
 out:
@@ -1079,6 +1086,8 @@ static void sparc_pmu_start(struct perf_event *event, int 
flags)
event->hw.state = 0;
 
sparc_pmu_enable_event(cpuc, >hw, idx);
+
+   perf_event_update_userpage(event);
 }
 
 static void sparc_pmu_stop(struct perf_event *event, int flags)
@@ -1371,9 +1380,9 @@ static int sparc_pmu_add(struct perf_event *event, int 
ef_flags)
cpuc->events[n0] = event->hw.event_base;
cpuc->current_idx[n0] = PIC_NO_INDEX;
 
-   event->hw.state = PERF_HES_UPTODATE;
+   event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
if (!(ef_flags & PERF_EF_START))
-   event->hw.state |= PERF_HES_STOPPED;
+   event->hw.state |= PERF_HES_ARCH;
 
/*
 * If group events scheduling transaction was started,
-- 
2.17.1



[PATCH AUTOSEL 4.18 33/33] i2c: rcar: cleanup DMA for all kinds of failure

2018-10-30 Thread Sasha Levin
From: Wolfram Sang 

[ Upstream commit 31d86033a0749a0463ea654130b2de5c163154f1 ]

DMA needs to be cleaned up not only on timeout, but on all errors where
it has been setup before.

Fixes: 73e8b0528346 ("i2c: rcar: add DMA support")
Signed-off-by: Wolfram Sang 
Signed-off-by: Wolfram Sang 
Signed-off-by: Sasha Levin 
---
 drivers/i2c/busses/i2c-rcar.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 3c1c817f6968..e152716bf07f 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -812,8 +812,12 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
 
time_left = wait_event_timeout(priv->wait, priv->flags & ID_DONE,
 num * adap->timeout);
-   if (!time_left) {
+
+   /* cleanup DMA if it couldn't complete properly due to an error */
+   if (priv->dma_direction != DMA_NONE)
rcar_i2c_cleanup_dma(priv);
+
+   if (!time_left) {
rcar_i2c_init(priv);
ret = -ETIMEDOUT;
} else if (priv->flags & ID_NACK) {
-- 
2.17.1



[PATCH AUTOSEL 4.18 32/33] net: fix pskb_trim_rcsum_slow() with odd trim offset

2018-10-30 Thread Sasha Levin
From: Dimitris Michailidis 

[ Upstream commit d55bef5059dd057bd077155375c581b49d25be7e ]

We've been getting checksum errors involving small UDP packets, usually
59B packets with 1 extra non-zero padding byte. netdev_rx_csum_fault()
has been complaining that HW is providing bad checksums. Turns out the
problem is in pskb_trim_rcsum_slow(), introduced in commit 88078d98d1bb
("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends").

The source of the problem is that when the bytes we are trimming start
at an odd address, as in the case of the 1 padding byte above,
skb_checksum() returns a byte-swapped value. We cannot just combine this
with skb->csum using csum_sub(). We need to use csum_block_sub() here
that takes into account the parity of the start address and handles the
swapping.

Matches existing code in __skb_postpull_rcsum() and esp_remove_trailer().

Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends")
Signed-off-by: Dimitris Michailidis 
Reviewed-by: Eric Dumazet 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 net/core/skbuff.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 3680912f056a..c45916b91a9c 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1845,8 +1845,9 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned 
int len)
if (skb->ip_summed == CHECKSUM_COMPLETE) {
int delta = skb->len - len;
 
-   skb->csum = csum_sub(skb->csum,
-skb_checksum(skb, len, delta, 0));
+   skb->csum = csum_block_sub(skb->csum,
+  skb_checksum(skb, len, delta, 0),
+  len);
}
return __pskb_trim(skb, len);
 }
-- 
2.17.1



[PATCH AUTOSEL 4.18 33/33] i2c: rcar: cleanup DMA for all kinds of failure

2018-10-30 Thread Sasha Levin
From: Wolfram Sang 

[ Upstream commit 31d86033a0749a0463ea654130b2de5c163154f1 ]

DMA needs to be cleaned up not only on timeout, but on all errors where
it has been setup before.

Fixes: 73e8b0528346 ("i2c: rcar: add DMA support")
Signed-off-by: Wolfram Sang 
Signed-off-by: Wolfram Sang 
Signed-off-by: Sasha Levin 
---
 drivers/i2c/busses/i2c-rcar.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 3c1c817f6968..e152716bf07f 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -812,8 +812,12 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
 
time_left = wait_event_timeout(priv->wait, priv->flags & ID_DONE,
 num * adap->timeout);
-   if (!time_left) {
+
+   /* cleanup DMA if it couldn't complete properly due to an error */
+   if (priv->dma_direction != DMA_NONE)
rcar_i2c_cleanup_dma(priv);
+
+   if (!time_left) {
rcar_i2c_init(priv);
ret = -ETIMEDOUT;
} else if (priv->flags & ID_NACK) {
-- 
2.17.1



[PATCH AUTOSEL 4.18 32/33] net: fix pskb_trim_rcsum_slow() with odd trim offset

2018-10-30 Thread Sasha Levin
From: Dimitris Michailidis 

[ Upstream commit d55bef5059dd057bd077155375c581b49d25be7e ]

We've been getting checksum errors involving small UDP packets, usually
59B packets with 1 extra non-zero padding byte. netdev_rx_csum_fault()
has been complaining that HW is providing bad checksums. Turns out the
problem is in pskb_trim_rcsum_slow(), introduced in commit 88078d98d1bb
("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends").

The source of the problem is that when the bytes we are trimming start
at an odd address, as in the case of the 1 padding byte above,
skb_checksum() returns a byte-swapped value. We cannot just combine this
with skb->csum using csum_sub(). We need to use csum_block_sub() here
that takes into account the parity of the start address and handles the
swapping.

Matches existing code in __skb_postpull_rcsum() and esp_remove_trailer().

Fixes: 88078d98d1bb ("net: pskb_trim_rcsum() and CHECKSUM_COMPLETE are friends")
Signed-off-by: Dimitris Michailidis 
Reviewed-by: Eric Dumazet 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 net/core/skbuff.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 3680912f056a..c45916b91a9c 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1845,8 +1845,9 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned 
int len)
if (skb->ip_summed == CHECKSUM_COMPLETE) {
int delta = skb->len - len;
 
-   skb->csum = csum_sub(skb->csum,
-skb_checksum(skb, len, delta, 0));
+   skb->csum = csum_block_sub(skb->csum,
+  skb_checksum(skb, len, delta, 0),
+  len);
}
return __pskb_trim(skb, len);
 }
-- 
2.17.1



[PATCH AUTOSEL 4.14 01/19] bpf: do not blindly change rlimit in reuseport net selftest

2018-10-30 Thread Sasha Levin
From: Eric Dumazet 

[ Upstream commit 262f9d811c7608f1e74258ceecfe1fa213bdf912 ]

If the current process has unlimited RLIMIT_MEMLOCK,
we should should leave it as is.

Fixes: 941ff6f11c02 ("bpf: fix rlimit in reuseport net selftest")
Signed-off-by: John Sperbeck 
Signed-off-by: Eric Dumazet 
Acked-by: Daniel Borkmann 
Signed-off-by: Daniel Borkmann 
Signed-off-by: Sasha Levin 
---
 tools/testing/selftests/net/reuseport_bpf.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/reuseport_bpf.c 
b/tools/testing/selftests/net/reuseport_bpf.c
index cad14cd0ea92..b5277106df1f 100644
--- a/tools/testing/selftests/net/reuseport_bpf.c
+++ b/tools/testing/selftests/net/reuseport_bpf.c
@@ -437,14 +437,19 @@ void enable_fastopen(void)
}
 }
 
-static struct rlimit rlim_old, rlim_new;
+static struct rlimit rlim_old;
 
 static  __attribute__((constructor)) void main_ctor(void)
 {
getrlimit(RLIMIT_MEMLOCK, _old);
-   rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
-   rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
-   setrlimit(RLIMIT_MEMLOCK, _new);
+
+   if (rlim_old.rlim_cur != RLIM_INFINITY) {
+   struct rlimit rlim_new;
+
+   rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
+   rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
+   setrlimit(RLIMIT_MEMLOCK, _new);
+   }
 }
 
 static __attribute__((destructor)) void main_dtor(void)
-- 
2.17.1



[PATCH AUTOSEL 4.14 02/19] Revert "perf tools: Fix PMU term format max value calculation"

2018-10-30 Thread Sasha Levin
From: Jiri Olsa 

[ Upstream commit 1b9caa10b31dda0866f4028e4bfb923fb6e4072f ]

This reverts commit ac0e2cd555373ae6f8f3a3ad3fbbf5b6d1e7.

Michael reported an issue with oversized terms values assignment
and I noticed there was actually a misunderstanding of the max
value check in the past.

The above commit's changelog says:

  If bit 21 is set, there is parsing issues as below.

$ perf stat -a -e uncore_qpi_0/event=0x22,umask=0x8/
event syntax error: '..pi_0/event=0x22,umask=0x8/'
  \___ value too big for format, maximum is 
511

But there's no issue there, because the event value is distributed
along the value defined by the format. Even if the format defines
separated bit, the value is treated as a continual number, which
should follow the format definition.

In above case it's 9-bit value with last bit separated:
  $ cat uncore_qpi_0/format/event
  config:0-7,21

Hence the value 0x22 is correctly reported as format violation,
because it exceeds 9 bits. It should have been 0x102 instead, which
sets the 9th bit - the bit 21 of the format.

  $ perf stat -vv -a -e uncore_qpi_0/event=0x102,umask=0x8/
  Using CPUID GenuineIntel-6-2D
  ...
  
  perf_event_attr:
type 10
size 112
config   0x200802
sample_type  IDENTIFIER
  ...

Reported-by: Michael Petlan 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Andi Kleen 
Cc: Kan Liang 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Fixes: ac0e2cd55537 ("perf tools: Fix PMU term format max value calculation")
Link: http://lkml.kernel.org/r/20181003072046.29276-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/pmu.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index d87d458996b7..dceef4725d33 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -754,13 +754,14 @@ static void pmu_format_value(unsigned long *format, __u64 
value, __u64 *v,
 
 static __u64 pmu_format_max_value(const unsigned long *format)
 {
-   __u64 w = 0;
-   int fbit;
-
-   for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
-   w |= (1ULL << fbit);
+   int w;
 
-   return w;
+   w = bitmap_weight(format, PERF_PMU_FORMAT_BITS);
+   if (!w)
+   return 0;
+   if (w < 64)
+   return (1ULL << w) - 1;
+   return -1;
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.14 04/19] xfrm: policy: use hlist rcu variants on insert

2018-10-30 Thread Sasha Levin
From: Florian Westphal 

[ Upstream commit 9d200fd178f11dd50eb1fd8ccd0650c9284e ]

bydst table/list lookups use rcu, so insertions must use rcu versions.

Fixes: a7c44247f704e ("xfrm: policy: make xfrm_policy_lookup_bytype lockless")
Signed-off-by: Florian Westphal 
Signed-off-by: Steffen Klassert 
Signed-off-by: Sasha Levin 
---
 net/xfrm/xfrm_policy.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 2fb7a78308e1..f60ff9b6a731 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -626,9 +626,9 @@ static void xfrm_hash_rebuild(struct work_struct *work)
break;
}
if (newpos)
-   hlist_add_behind(>bydst, newpos);
+   hlist_add_behind_rcu(>bydst, newpos);
else
-   hlist_add_head(>bydst, chain);
+   hlist_add_head_rcu(>bydst, chain);
}
 
spin_unlock_bh(>xfrm.xfrm_policy_lock);
@@ -767,9 +767,9 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, 
int excl)
break;
}
if (newpos)
-   hlist_add_behind(>bydst, newpos);
+   hlist_add_behind_rcu(>bydst, newpos);
else
-   hlist_add_head(>bydst, chain);
+   hlist_add_head_rcu(>bydst, chain);
__xfrm_policy_link(policy, dir);
 
/* After previous checking, family can either be AF_INET or AF_INET6 */
-- 
2.17.1



[PATCH AUTOSEL 4.14 01/19] bpf: do not blindly change rlimit in reuseport net selftest

2018-10-30 Thread Sasha Levin
From: Eric Dumazet 

[ Upstream commit 262f9d811c7608f1e74258ceecfe1fa213bdf912 ]

If the current process has unlimited RLIMIT_MEMLOCK,
we should should leave it as is.

Fixes: 941ff6f11c02 ("bpf: fix rlimit in reuseport net selftest")
Signed-off-by: John Sperbeck 
Signed-off-by: Eric Dumazet 
Acked-by: Daniel Borkmann 
Signed-off-by: Daniel Borkmann 
Signed-off-by: Sasha Levin 
---
 tools/testing/selftests/net/reuseport_bpf.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/reuseport_bpf.c 
b/tools/testing/selftests/net/reuseport_bpf.c
index cad14cd0ea92..b5277106df1f 100644
--- a/tools/testing/selftests/net/reuseport_bpf.c
+++ b/tools/testing/selftests/net/reuseport_bpf.c
@@ -437,14 +437,19 @@ void enable_fastopen(void)
}
 }
 
-static struct rlimit rlim_old, rlim_new;
+static struct rlimit rlim_old;
 
 static  __attribute__((constructor)) void main_ctor(void)
 {
getrlimit(RLIMIT_MEMLOCK, _old);
-   rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
-   rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
-   setrlimit(RLIMIT_MEMLOCK, _new);
+
+   if (rlim_old.rlim_cur != RLIM_INFINITY) {
+   struct rlimit rlim_new;
+
+   rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
+   rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
+   setrlimit(RLIMIT_MEMLOCK, _new);
+   }
 }
 
 static __attribute__((destructor)) void main_dtor(void)
-- 
2.17.1



[PATCH AUTOSEL 4.14 02/19] Revert "perf tools: Fix PMU term format max value calculation"

2018-10-30 Thread Sasha Levin
From: Jiri Olsa 

[ Upstream commit 1b9caa10b31dda0866f4028e4bfb923fb6e4072f ]

This reverts commit ac0e2cd555373ae6f8f3a3ad3fbbf5b6d1e7.

Michael reported an issue with oversized terms values assignment
and I noticed there was actually a misunderstanding of the max
value check in the past.

The above commit's changelog says:

  If bit 21 is set, there is parsing issues as below.

$ perf stat -a -e uncore_qpi_0/event=0x22,umask=0x8/
event syntax error: '..pi_0/event=0x22,umask=0x8/'
  \___ value too big for format, maximum is 
511

But there's no issue there, because the event value is distributed
along the value defined by the format. Even if the format defines
separated bit, the value is treated as a continual number, which
should follow the format definition.

In above case it's 9-bit value with last bit separated:
  $ cat uncore_qpi_0/format/event
  config:0-7,21

Hence the value 0x22 is correctly reported as format violation,
because it exceeds 9 bits. It should have been 0x102 instead, which
sets the 9th bit - the bit 21 of the format.

  $ perf stat -vv -a -e uncore_qpi_0/event=0x102,umask=0x8/
  Using CPUID GenuineIntel-6-2D
  ...
  
  perf_event_attr:
type 10
size 112
config   0x200802
sample_type  IDENTIFIER
  ...

Reported-by: Michael Petlan 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Andi Kleen 
Cc: Kan Liang 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Fixes: ac0e2cd55537 ("perf tools: Fix PMU term format max value calculation")
Link: http://lkml.kernel.org/r/20181003072046.29276-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/pmu.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index d87d458996b7..dceef4725d33 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -754,13 +754,14 @@ static void pmu_format_value(unsigned long *format, __u64 
value, __u64 *v,
 
 static __u64 pmu_format_max_value(const unsigned long *format)
 {
-   __u64 w = 0;
-   int fbit;
-
-   for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
-   w |= (1ULL << fbit);
+   int w;
 
-   return w;
+   w = bitmap_weight(format, PERF_PMU_FORMAT_BITS);
+   if (!w)
+   return 0;
+   if (w < 64)
+   return (1ULL << w) - 1;
+   return -1;
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.14 04/19] xfrm: policy: use hlist rcu variants on insert

2018-10-30 Thread Sasha Levin
From: Florian Westphal 

[ Upstream commit 9d200fd178f11dd50eb1fd8ccd0650c9284e ]

bydst table/list lookups use rcu, so insertions must use rcu versions.

Fixes: a7c44247f704e ("xfrm: policy: make xfrm_policy_lookup_bytype lockless")
Signed-off-by: Florian Westphal 
Signed-off-by: Steffen Klassert 
Signed-off-by: Sasha Levin 
---
 net/xfrm/xfrm_policy.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 2fb7a78308e1..f60ff9b6a731 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -626,9 +626,9 @@ static void xfrm_hash_rebuild(struct work_struct *work)
break;
}
if (newpos)
-   hlist_add_behind(>bydst, newpos);
+   hlist_add_behind_rcu(>bydst, newpos);
else
-   hlist_add_head(>bydst, chain);
+   hlist_add_head_rcu(>bydst, chain);
}
 
spin_unlock_bh(>xfrm.xfrm_policy_lock);
@@ -767,9 +767,9 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, 
int excl)
break;
}
if (newpos)
-   hlist_add_behind(>bydst, newpos);
+   hlist_add_behind_rcu(>bydst, newpos);
else
-   hlist_add_head(>bydst, chain);
+   hlist_add_head_rcu(>bydst, chain);
__xfrm_policy_link(policy, dir);
 
/* After previous checking, family can either be AF_INET or AF_INET6 */
-- 
2.17.1



[PATCH AUTOSEL 4.18 24/33] perf report: Don't crash on invalid inline debug information

2018-10-30 Thread Sasha Levin
From: Milian Wolff 

[ Upstream commit d4046e8e17b9f378cb861982ef71c63911b5dff3 ]

When the function name for an inline frame is invalid, we must not try
to demangle this symbol, otherwise we crash with:

  #0  0x55895c01 in bfd_demangle ()
  #1  0x55823262 in demangle_sym (dso=0x55d92b90, elf_name=0x0, 
kmodule=0) at util/symbol-elf.c:215
  #2  dso__demangle_sym (dso=dso@entry=0x55d92b90, kmodule=, 
kmodule@entry=0, elf_name=elf_name@entry=0x0) at util/symbol-elf.c:400
  #3  0x557fef4b in new_inline_sym (funcname=0x0, 
base_sym=0x55d92b90, dso=0x55d92b90) at util/srcline.c:89
  #4  inline_list__append_dso_a2l (dso=dso@entry=0x55c7bb00, 
node=node@entry=0x55e31810, sym=sym@entry=0x55d92b90) at 
util/srcline.c:264
  #5  0x557ff27f in addr2line (dso_name=dso_name@entry=0x55d92430 
"/home/milian/.debug/.build-id/f7/186d14bb94f3c6161c010926da66033d24fce5/elf", 
addr=addr@entry=2888, file=file@entry=0x0,
  line=line@entry=0x0, dso=dso@entry=0x55c7bb00, 
unwind_inlines=unwind_inlines@entry=true, node=0x55e31810, 
sym=0x55d92b90) at util/srcline.c:313
  #6  0x557ffe7c in addr2inlines (sym=0x55d92b90, 
dso=0x55c7bb00, addr=2888, dso_name=0x55d92430 
"/home/milian/.debug/.build-id/f7/186d14bb94f3c6161c010926da66033d24fce5/elf")
  at util/srcline.c:358

So instead handle the case where we get invalid function names for
inlined frames and use a fallback '??' function name instead.

While this crash was originally reported by Hadrien for rust code, I can
now also reproduce it with trivial C++ code. Indeed, it seems like
libbfd fails to interpret the debug information for the inline frame
symbol name:

  $ addr2line -e 
/home/milian/.debug/.build-id/f7/186d14bb94f3c6161c010926da66033d24fce5/elf -if 
b48
  main
  /usr/include/c++/8.2.1/complex:610
  ??
  /usr/include/c++/8.2.1/complex:618
  ??
  /usr/include/c++/8.2.1/complex:675
  ??
  /usr/include/c++/8.2.1/complex:685
  main
  
/home/milian/projects/kdab/rnd/hotspot/tests/test-clients/cpp-inlining/main.cpp:39

I've reported this bug upstream and also attached a patch there which
should fix this issue:

https://sourceware.org/bugzilla/show_bug.cgi?id=23715

Reported-by: Hadrien Grasland 
Signed-off-by: Milian Wolff 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Fixes: a64489c56c30 ("perf report: Find the inline stack for a given address")
[ The above 'Fixes:' cset is where originally the problem was
  introduced, i.e.  using a2l->funcname without checking if it is NULL,
  but this current patch fixes the current codebase, i.e. multiple csets
  were applied after a64489c56c30 before the problem was reported by Hadrien ]
Link: http://lkml.kernel.org/r/20180926135207.30263-3-milian.wo...@kdab.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/srcline.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 09d6746e6ec8..e767c4a9d4d2 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -85,6 +85,9 @@ static struct symbol *new_inline_sym(struct dso *dso,
struct symbol *inline_sym;
char *demangled = NULL;
 
+   if (!funcname)
+   funcname = "??";
+
if (dso) {
demangled = dso__demangle_sym(dso, 0, funcname);
if (demangled)
-- 
2.17.1



[PATCH AUTOSEL 4.18 25/33] x86/fpu: Remove second definition of fpu in __fpu__restore_sig()

2018-10-30 Thread Sasha Levin
From: Sebastian Andrzej Siewior 

[ Upstream commit 6aa676761d4c1acfa31320e55fa1f83f3fcbbc7a ]

Commit:

  c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")

introduced the 'fpu' variable at top of __restore_xstate_sig(),
which now shadows the other definition:

  arch/x86/kernel/fpu/signal.c:318:28: warning: symbol 'fpu' shadows an earlier 
one
  arch/x86/kernel/fpu/signal.c:271:20: originally declared here

Remove the shadowed definition of 'fpu', as the two definitions are the same.

Signed-off-by: Sebastian Andrzej Siewior 
Reviewed-by: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Dave Hansen 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")
Link: http://lkml.kernel.org/r/20181016202525.29437-3-bige...@linutronix.de
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 arch/x86/kernel/fpu/signal.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c
index 23f1691670b6..61a949d84dfa 100644
--- a/arch/x86/kernel/fpu/signal.c
+++ b/arch/x86/kernel/fpu/signal.c
@@ -314,7 +314,6 @@ static int __fpu__restore_sig(void __user *buf, void __user 
*buf_fx, int size)
 * thread's fpu state, reconstruct fxstate from the fsave
 * header. Validate and sanitize the copied state.
 */
-   struct fpu *fpu = >thread.fpu;
struct user_i387_ia32_struct env;
int err = 0;
 
-- 
2.17.1



[PATCH AUTOSEL 4.18 22/33] perf tools: Fix use of alternatives to find JDIR

2018-10-30 Thread Sasha Levin
From: Jarod Wilson 

[ Upstream commit 36b8d4628d3cc8f5a748e508cce8673bc00fc63c ]

When a build is run from something like a cron job, the user's $PATH is
rather minimal, of note, not including /usr/sbin in my own case. Because
of that, an automated rpm package build ultimately fails to find
libperf-jvmti.so, because somewhere within the build, this happens...

  /bin/sh: alternatives: command not found
  /bin/sh: alternatives: command not found
  Makefile.config:849: No openjdk development package found, please install
  JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel

...and while the build continues, libperf-jvmti.so isn't built, and
things fall down when rpm tries to find all the %files specified. Exact
same system builds everything just fine when the job is launched from a
login shell instead of a cron job, since alternatives is in $PATH, so
openjdk is actually found.

The test required to get into this section of code actually specifies
the full path, as does a block just above it, so let's do that here too.

Signed-off-by: Jarod Wilson 
Acked-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: William Cohen 
Fixes: d4dfdf00d43e ("perf jvmti: Plug compilation into perf build")
Link: http://lkml.kernel.org/r/20180906221812.11167-1-ja...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/Makefile.config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 67b042738ed7..986151732d68 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -831,7 +831,7 @@ ifndef NO_JVMTI
 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print 
$$3}')
   else
 ifneq (,$(wildcard /usr/sbin/alternatives))
-  JDIR=$(shell alternatives --display java | tail -1 | cut -d' ' -f 5 | 
sed 's%/jre/bin/java.%%g')
+  JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' 
-f 5 | sed 's%/jre/bin/java.%%g')
 endif
   endif
   ifndef JDIR
-- 
2.17.1



[PATCH AUTOSEL 4.18 21/33] perf evsel: Store ids for events with their own cpus perf_event__synthesize_event_update_cpus

2018-10-30 Thread Sasha Levin
From: Jiri Olsa 

[ Upstream commit 4ab8455f8bd83298bf7f67ab9357e3b1cc765c7d ]

John reported crash when recording on an event under PMU with cpumask defined:

  root@localhost:~# ./perf_debug_ record -e armv8_pmuv3_0/br_mis_pred/ sleep 1
  perf: Segmentation fault
  Obtained 9 stack frames.
  ./perf_debug_() [0x4c5ef8]
  [0x82ba267c]
  ./perf_debug_() [0x4bc5a8]
  ./perf_debug_() [0x419550]
  ./perf_debug_() [0x41a928]
  ./perf_debug_() [0x472f58]
  ./perf_debug_() [0x473210]
  ./perf_debug_() [0x4070f4]
  /lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe0) [0x8294c8a0]
  Segmentation fault (core dumped)

We synthesize an update event that needs to touch the evsel id array, which is
not defined at that time. Fixing this by forcing the id allocation for events
with their own cpus.

Reported-by: John Garry 
Signed-off-by: Jiri Olsa 
Tested-by: John Garry 
Cc: Alexander Shishkin 
Cc: Andi Kleen 
Cc: Mark Rutland 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Will Deacon 
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux...@huawei.com
Fixes: bfd8f72c2778 ("perf record: Synthesize unit/scale/... in event update")
Link: http://lkml.kernel.org/r/20181003212052.GA32371@krava
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/builtin-report.c | 1 +
 tools/perf/util/evsel.c | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index c04dc7b53797..82a3c8be19ee 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -981,6 +981,7 @@ int cmd_report(int argc, const char **argv)
.id_index= perf_event__process_id_index,
.auxtrace_info   = perf_event__process_auxtrace_info,
.auxtrace= perf_event__process_auxtrace,
+   .event_update= perf_event__process_event_update,
.feature = process_feature_event,
.ordered_events  = true,
.ordering_requires_timestamps = true,
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 6324afba8fdd..86ad1389ff5a 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1078,6 +1078,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct 
record_opts *opts,
attr->exclude_user   = 1;
}
 
+   if (evsel->own_cpus)
+   evsel->attr.read_format |= PERF_FORMAT_ID;
+
/*
 * Apply event specific term settings,
 * it overloads any global configuration.
-- 
2.17.1



[PATCH AUTOSEL 4.18 28/33] virtio_net: avoid using netif_tx_disable() for serializing tx routine

2018-10-30 Thread Sasha Levin
From: Ake Koomsin 

[ Upstream commit 05c998b738fdd3e5d6a257bcacc8f34b6284d795 ]

Commit 713a98d90c5e ("virtio-net: serialize tx routine during reset")
introduces netif_tx_disable() after netif_device_detach() in order to
avoid use-after-free of tx queues. However, there are two issues.

1) Its operation is redundant with netif_device_detach() in case the
   interface is running.
2) In case of the interface is not running before suspending and
   resuming, the tx does not get resumed by netif_device_attach().
   This results in losing network connectivity.

It is better to use netif_tx_lock_bh()/netif_tx_unlock_bh() instead for
serializing tx routine during reset. This also preserves the symmetry
of netif_device_detach() and netif_device_attach().

Fixes commit 713a98d90c5e ("virtio-net: serialize tx routine during reset")
Signed-off-by: Ake Koomsin 
Acked-by: Jason Wang 
Acked-by: Michael S. Tsirkin 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/virtio_net.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 2b6ec927809e..500e2d8f10bc 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2162,8 +2162,9 @@ static void virtnet_freeze_down(struct virtio_device 
*vdev)
/* Make sure no work handler is accessing the device */
flush_work(>config_work);
 
+   netif_tx_lock_bh(vi->dev);
netif_device_detach(vi->dev);
-   netif_tx_disable(vi->dev);
+   netif_tx_unlock_bh(vi->dev);
cancel_delayed_work_sync(>refill);
 
if (netif_running(vi->dev)) {
@@ -2199,7 +2200,9 @@ static int virtnet_restore_up(struct virtio_device *vdev)
}
}
 
+   netif_tx_lock_bh(vi->dev);
netif_device_attach(vi->dev);
+   netif_tx_unlock_bh(vi->dev);
return err;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.18 19/33] nfp: flower: use offsets provided by pedit instead of index for ipv6

2018-10-30 Thread Sasha Levin
From: Pieter Jansen van Vuuren 

[ Upstream commit 140b6abac26d799f75d772ab5e969b34ad8d68f1 ]

Previously when populating the set ipv6 address action, we incorrectly
made use of pedit's key index to determine which 32bit word should be
set. We now calculate which word has been selected based on the offset
provided by the pedit action.

Fixes: 354b82bb320e ("nfp: add set ipv6 source and destination address")
Signed-off-by: Pieter Jansen van Vuuren 
Reviewed-by: Jakub Kicinski 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 .../ethernet/netronome/nfp/flower/action.c| 26 +++
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/flower/action.c 
b/drivers/net/ethernet/netronome/nfp/flower/action.c
index 35f294bf0cd4..417fbcc64f00 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/action.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/action.c
@@ -335,12 +335,12 @@ nfp_fl_set_ip4(const struct tc_action *action, int idx, 
u32 off,
 }
 
 static void
-nfp_fl_set_ip6_helper(int opcode_tag, int idx, __be32 exact, __be32 mask,
+nfp_fl_set_ip6_helper(int opcode_tag, u8 word, __be32 exact, __be32 mask,
  struct nfp_fl_set_ipv6_addr *ip6)
 {
-   ip6->ipv6[idx % 4].mask |= mask;
-   ip6->ipv6[idx % 4].exact &= ~mask;
-   ip6->ipv6[idx % 4].exact |= exact & mask;
+   ip6->ipv6[word].mask |= mask;
+   ip6->ipv6[word].exact &= ~mask;
+   ip6->ipv6[word].exact |= exact & mask;
 
ip6->reserved = cpu_to_be16(0);
ip6->head.jump_id = opcode_tag;
@@ -353,6 +353,7 @@ nfp_fl_set_ip6(const struct tc_action *action, int idx, u32 
off,
   struct nfp_fl_set_ipv6_addr *ip_src)
 {
__be32 exact, mask;
+   u8 word;
 
/* We are expecting tcf_pedit to return a big endian value */
mask = (__force __be32)~tcf_pedit_mask(action, idx);
@@ -361,17 +362,20 @@ nfp_fl_set_ip6(const struct tc_action *action, int idx, 
u32 off,
if (exact & ~mask)
return -EOPNOTSUPP;
 
-   if (off < offsetof(struct ipv6hdr, saddr))
+   if (off < offsetof(struct ipv6hdr, saddr)) {
return -EOPNOTSUPP;
-   else if (off < offsetof(struct ipv6hdr, daddr))
-   nfp_fl_set_ip6_helper(NFP_FL_ACTION_OPCODE_SET_IPV6_SRC, idx,
+   } else if (off < offsetof(struct ipv6hdr, daddr)) {
+   word = (off - offsetof(struct ipv6hdr, saddr)) / sizeof(exact);
+   nfp_fl_set_ip6_helper(NFP_FL_ACTION_OPCODE_SET_IPV6_SRC, word,
  exact, mask, ip_src);
-   else if (off < offsetof(struct ipv6hdr, daddr) +
-  sizeof(struct in6_addr))
-   nfp_fl_set_ip6_helper(NFP_FL_ACTION_OPCODE_SET_IPV6_DST, idx,
+   } else if (off < offsetof(struct ipv6hdr, daddr) +
+  sizeof(struct in6_addr)) {
+   word = (off - offsetof(struct ipv6hdr, daddr)) / sizeof(exact);
+   nfp_fl_set_ip6_helper(NFP_FL_ACTION_OPCODE_SET_IPV6_DST, word,
  exact, mask, ip_dst);
-   else
+   } else {
return -EOPNOTSUPP;
+   }
 
return 0;
 }
-- 
2.17.1



[PATCH AUTOSEL 4.18 20/33] sched/fair: Fix the min_vruntime update logic in dequeue_entity()

2018-10-30 Thread Sasha Levin
From: Song Muchun 

[ Upstream commit 9845c49cc9bbb317a0bc9e9cf78d8e09d54c9af0 ]

The comment and the code around the update_min_vruntime() call in
dequeue_entity() are not in agreement.

>From commit:

  b60205c7c558 ("sched/fair: Fix min_vruntime tracking")

I think that we want to update min_vruntime when a task is sleeping/migrating.
So, the check is inverted there - fix it.

Signed-off-by: Song Muchun 
Cc: Linus Torvalds 
Cc: Mike Galbraith 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: b60205c7c558 ("sched/fair: Fix min_vruntime tracking")
Link: http://lkml.kernel.org/r/20181014112612.2614-1-smuc...@gmail.com
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 26526fc41f0d..1c17a4a49ee0 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4321,7 +4321,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity 
*se, int flags)
 * put back on, and if we advance min_vruntime, we'll be placed back
 * further than we started -- ie. we'll be penalized.
 */
-   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) == DEQUEUE_SAVE)
+   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) != DEQUEUE_SAVE)
update_min_vruntime(cfs_rq);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.18 27/33] r8169: re-enable MSI-X on RTL8168g

2018-10-30 Thread Sasha Levin
From: Heiner Kallweit 

[ Upstream commit 9675931e6b65d160d16bcc9472c1acef15524def ]

Similar to d49c88d7677b ("r8169: Enable MSI-X on RTL8106e") after
e9d0ba506ea8 ("PCI: Reprogram bridge prefetch registers on resume")
we can safely assume that this also fixes the root cause of
the issue worked around by 7c53a722459c ("r8169: don't use MSI-X on
RTL8168g"). So let's revert it.

Fixes: 7c53a722459c ("r8169: don't use MSI-X on RTL8168g")
Signed-off-by: Heiner Kallweit 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/realtek/r8169.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index 36422f783fe7..2eea2b66d970 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7546,11 +7546,6 @@ static int rtl_alloc_irq(struct rtl8169_private *tp)
RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable);
RTL_W8(tp, Cfg9346, Cfg9346_Lock);
flags = PCI_IRQ_LEGACY;
-   } else if (tp->mac_version == RTL_GIGA_MAC_VER_40) {
-   /* This version was reported to have issues with resume
-* from suspend when using MSI-X
-*/
-   flags = PCI_IRQ_LEGACY | PCI_IRQ_MSI;
} else {
flags = PCI_IRQ_ALL_TYPES;
}
-- 
2.17.1



[PATCH AUTOSEL 4.18 26/33] net: qla3xxx: Remove overflowing shift statement

2018-10-30 Thread Sasha Levin
From: Nathan Chancellor 

[ Upstream commit 8c3bf9b62b667456a57aefcf1689e826df146159 ]

Clang currently warns:

drivers/net/ethernet/qlogic/qla3xxx.c:384:24: warning: signed shift
result (0xF) requires 37 bits to represent, but 'int' only has
32 bits [-Wshift-overflow]
((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
  ~~ ^  ~~
1 warning generated.

The warning is certainly accurate since ISP_NVRAM_MASK is defined as
(0x000F << 16) which is then shifted by 16, resulting in 64424509440,
well above UINT_MAX.

Given that this is the only location in this driver where ISP_NVRAM_MASK
is shifted again, it seems likely that ISP_NVRAM_MASK was originally
defined without a shift and during the move of the shift to the
definition, this statement wasn't properly removed (since ISP_NVRAM_MASK
is used in the statenent right above this). Only the maintainers can
confirm this since this statment has been here since the driver was
first added to the kernel.

Link: https://github.com/ClangBuiltLinux/linux/issues/127
Signed-off-by: Nathan Chancellor 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/qlogic/qla3xxx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c 
b/drivers/net/ethernet/qlogic/qla3xxx.c
index b48f76182049..10b075bc5959 100644
--- a/drivers/net/ethernet/qlogic/qla3xxx.c
+++ b/drivers/net/ethernet/qlogic/qla3xxx.c
@@ -380,8 +380,6 @@ static void fm93c56a_select(struct ql3_adapter *qdev)
 
qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_1;
ql_write_nvram_reg(qdev, spir, ISP_NVRAM_MASK | qdev->eeprom_cmd_data);
-   ql_write_nvram_reg(qdev, spir,
-  ((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.18 28/33] virtio_net: avoid using netif_tx_disable() for serializing tx routine

2018-10-30 Thread Sasha Levin
From: Ake Koomsin 

[ Upstream commit 05c998b738fdd3e5d6a257bcacc8f34b6284d795 ]

Commit 713a98d90c5e ("virtio-net: serialize tx routine during reset")
introduces netif_tx_disable() after netif_device_detach() in order to
avoid use-after-free of tx queues. However, there are two issues.

1) Its operation is redundant with netif_device_detach() in case the
   interface is running.
2) In case of the interface is not running before suspending and
   resuming, the tx does not get resumed by netif_device_attach().
   This results in losing network connectivity.

It is better to use netif_tx_lock_bh()/netif_tx_unlock_bh() instead for
serializing tx routine during reset. This also preserves the symmetry
of netif_device_detach() and netif_device_attach().

Fixes commit 713a98d90c5e ("virtio-net: serialize tx routine during reset")
Signed-off-by: Ake Koomsin 
Acked-by: Jason Wang 
Acked-by: Michael S. Tsirkin 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/virtio_net.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 2b6ec927809e..500e2d8f10bc 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2162,8 +2162,9 @@ static void virtnet_freeze_down(struct virtio_device 
*vdev)
/* Make sure no work handler is accessing the device */
flush_work(>config_work);
 
+   netif_tx_lock_bh(vi->dev);
netif_device_detach(vi->dev);
-   netif_tx_disable(vi->dev);
+   netif_tx_unlock_bh(vi->dev);
cancel_delayed_work_sync(>refill);
 
if (netif_running(vi->dev)) {
@@ -2199,7 +2200,9 @@ static int virtnet_restore_up(struct virtio_device *vdev)
}
}
 
+   netif_tx_lock_bh(vi->dev);
netif_device_attach(vi->dev);
+   netif_tx_unlock_bh(vi->dev);
return err;
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.18 19/33] nfp: flower: use offsets provided by pedit instead of index for ipv6

2018-10-30 Thread Sasha Levin
From: Pieter Jansen van Vuuren 

[ Upstream commit 140b6abac26d799f75d772ab5e969b34ad8d68f1 ]

Previously when populating the set ipv6 address action, we incorrectly
made use of pedit's key index to determine which 32bit word should be
set. We now calculate which word has been selected based on the offset
provided by the pedit action.

Fixes: 354b82bb320e ("nfp: add set ipv6 source and destination address")
Signed-off-by: Pieter Jansen van Vuuren 
Reviewed-by: Jakub Kicinski 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 .../ethernet/netronome/nfp/flower/action.c| 26 +++
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/flower/action.c 
b/drivers/net/ethernet/netronome/nfp/flower/action.c
index 35f294bf0cd4..417fbcc64f00 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/action.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/action.c
@@ -335,12 +335,12 @@ nfp_fl_set_ip4(const struct tc_action *action, int idx, 
u32 off,
 }
 
 static void
-nfp_fl_set_ip6_helper(int opcode_tag, int idx, __be32 exact, __be32 mask,
+nfp_fl_set_ip6_helper(int opcode_tag, u8 word, __be32 exact, __be32 mask,
  struct nfp_fl_set_ipv6_addr *ip6)
 {
-   ip6->ipv6[idx % 4].mask |= mask;
-   ip6->ipv6[idx % 4].exact &= ~mask;
-   ip6->ipv6[idx % 4].exact |= exact & mask;
+   ip6->ipv6[word].mask |= mask;
+   ip6->ipv6[word].exact &= ~mask;
+   ip6->ipv6[word].exact |= exact & mask;
 
ip6->reserved = cpu_to_be16(0);
ip6->head.jump_id = opcode_tag;
@@ -353,6 +353,7 @@ nfp_fl_set_ip6(const struct tc_action *action, int idx, u32 
off,
   struct nfp_fl_set_ipv6_addr *ip_src)
 {
__be32 exact, mask;
+   u8 word;
 
/* We are expecting tcf_pedit to return a big endian value */
mask = (__force __be32)~tcf_pedit_mask(action, idx);
@@ -361,17 +362,20 @@ nfp_fl_set_ip6(const struct tc_action *action, int idx, 
u32 off,
if (exact & ~mask)
return -EOPNOTSUPP;
 
-   if (off < offsetof(struct ipv6hdr, saddr))
+   if (off < offsetof(struct ipv6hdr, saddr)) {
return -EOPNOTSUPP;
-   else if (off < offsetof(struct ipv6hdr, daddr))
-   nfp_fl_set_ip6_helper(NFP_FL_ACTION_OPCODE_SET_IPV6_SRC, idx,
+   } else if (off < offsetof(struct ipv6hdr, daddr)) {
+   word = (off - offsetof(struct ipv6hdr, saddr)) / sizeof(exact);
+   nfp_fl_set_ip6_helper(NFP_FL_ACTION_OPCODE_SET_IPV6_SRC, word,
  exact, mask, ip_src);
-   else if (off < offsetof(struct ipv6hdr, daddr) +
-  sizeof(struct in6_addr))
-   nfp_fl_set_ip6_helper(NFP_FL_ACTION_OPCODE_SET_IPV6_DST, idx,
+   } else if (off < offsetof(struct ipv6hdr, daddr) +
+  sizeof(struct in6_addr)) {
+   word = (off - offsetof(struct ipv6hdr, daddr)) / sizeof(exact);
+   nfp_fl_set_ip6_helper(NFP_FL_ACTION_OPCODE_SET_IPV6_DST, word,
  exact, mask, ip_dst);
-   else
+   } else {
return -EOPNOTSUPP;
+   }
 
return 0;
 }
-- 
2.17.1



[PATCH AUTOSEL 4.18 20/33] sched/fair: Fix the min_vruntime update logic in dequeue_entity()

2018-10-30 Thread Sasha Levin
From: Song Muchun 

[ Upstream commit 9845c49cc9bbb317a0bc9e9cf78d8e09d54c9af0 ]

The comment and the code around the update_min_vruntime() call in
dequeue_entity() are not in agreement.

>From commit:

  b60205c7c558 ("sched/fair: Fix min_vruntime tracking")

I think that we want to update min_vruntime when a task is sleeping/migrating.
So, the check is inverted there - fix it.

Signed-off-by: Song Muchun 
Cc: Linus Torvalds 
Cc: Mike Galbraith 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: b60205c7c558 ("sched/fair: Fix min_vruntime tracking")
Link: http://lkml.kernel.org/r/20181014112612.2614-1-smuc...@gmail.com
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 26526fc41f0d..1c17a4a49ee0 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4321,7 +4321,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity 
*se, int flags)
 * put back on, and if we advance min_vruntime, we'll be placed back
 * further than we started -- ie. we'll be penalized.
 */
-   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) == DEQUEUE_SAVE)
+   if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE)) != DEQUEUE_SAVE)
update_min_vruntime(cfs_rq);
 }
 
-- 
2.17.1



[PATCH AUTOSEL 4.18 24/33] perf report: Don't crash on invalid inline debug information

2018-10-30 Thread Sasha Levin
From: Milian Wolff 

[ Upstream commit d4046e8e17b9f378cb861982ef71c63911b5dff3 ]

When the function name for an inline frame is invalid, we must not try
to demangle this symbol, otherwise we crash with:

  #0  0x55895c01 in bfd_demangle ()
  #1  0x55823262 in demangle_sym (dso=0x55d92b90, elf_name=0x0, 
kmodule=0) at util/symbol-elf.c:215
  #2  dso__demangle_sym (dso=dso@entry=0x55d92b90, kmodule=, 
kmodule@entry=0, elf_name=elf_name@entry=0x0) at util/symbol-elf.c:400
  #3  0x557fef4b in new_inline_sym (funcname=0x0, 
base_sym=0x55d92b90, dso=0x55d92b90) at util/srcline.c:89
  #4  inline_list__append_dso_a2l (dso=dso@entry=0x55c7bb00, 
node=node@entry=0x55e31810, sym=sym@entry=0x55d92b90) at 
util/srcline.c:264
  #5  0x557ff27f in addr2line (dso_name=dso_name@entry=0x55d92430 
"/home/milian/.debug/.build-id/f7/186d14bb94f3c6161c010926da66033d24fce5/elf", 
addr=addr@entry=2888, file=file@entry=0x0,
  line=line@entry=0x0, dso=dso@entry=0x55c7bb00, 
unwind_inlines=unwind_inlines@entry=true, node=0x55e31810, 
sym=0x55d92b90) at util/srcline.c:313
  #6  0x557ffe7c in addr2inlines (sym=0x55d92b90, 
dso=0x55c7bb00, addr=2888, dso_name=0x55d92430 
"/home/milian/.debug/.build-id/f7/186d14bb94f3c6161c010926da66033d24fce5/elf")
  at util/srcline.c:358

So instead handle the case where we get invalid function names for
inlined frames and use a fallback '??' function name instead.

While this crash was originally reported by Hadrien for rust code, I can
now also reproduce it with trivial C++ code. Indeed, it seems like
libbfd fails to interpret the debug information for the inline frame
symbol name:

  $ addr2line -e 
/home/milian/.debug/.build-id/f7/186d14bb94f3c6161c010926da66033d24fce5/elf -if 
b48
  main
  /usr/include/c++/8.2.1/complex:610
  ??
  /usr/include/c++/8.2.1/complex:618
  ??
  /usr/include/c++/8.2.1/complex:675
  ??
  /usr/include/c++/8.2.1/complex:685
  main
  
/home/milian/projects/kdab/rnd/hotspot/tests/test-clients/cpp-inlining/main.cpp:39

I've reported this bug upstream and also attached a patch there which
should fix this issue:

https://sourceware.org/bugzilla/show_bug.cgi?id=23715

Reported-by: Hadrien Grasland 
Signed-off-by: Milian Wolff 
Cc: Jin Yao 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Fixes: a64489c56c30 ("perf report: Find the inline stack for a given address")
[ The above 'Fixes:' cset is where originally the problem was
  introduced, i.e.  using a2l->funcname without checking if it is NULL,
  but this current patch fixes the current codebase, i.e. multiple csets
  were applied after a64489c56c30 before the problem was reported by Hadrien ]
Link: http://lkml.kernel.org/r/20180926135207.30263-3-milian.wo...@kdab.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/util/srcline.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index 09d6746e6ec8..e767c4a9d4d2 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -85,6 +85,9 @@ static struct symbol *new_inline_sym(struct dso *dso,
struct symbol *inline_sym;
char *demangled = NULL;
 
+   if (!funcname)
+   funcname = "??";
+
if (dso) {
demangled = dso__demangle_sym(dso, 0, funcname);
if (demangled)
-- 
2.17.1



[PATCH AUTOSEL 4.18 25/33] x86/fpu: Remove second definition of fpu in __fpu__restore_sig()

2018-10-30 Thread Sasha Levin
From: Sebastian Andrzej Siewior 

[ Upstream commit 6aa676761d4c1acfa31320e55fa1f83f3fcbbc7a ]

Commit:

  c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")

introduced the 'fpu' variable at top of __restore_xstate_sig(),
which now shadows the other definition:

  arch/x86/kernel/fpu/signal.c:318:28: warning: symbol 'fpu' shadows an earlier 
one
  arch/x86/kernel/fpu/signal.c:271:20: originally declared here

Remove the shadowed definition of 'fpu', as the two definitions are the same.

Signed-off-by: Sebastian Andrzej Siewior 
Reviewed-by: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Dave Hansen 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: c5bedc6847c3b ("x86/fpu: Get rid of PF_USED_MATH usage, convert it to 
fpu->fpstate_active")
Link: http://lkml.kernel.org/r/20181016202525.29437-3-bige...@linutronix.de
Signed-off-by: Ingo Molnar 
Signed-off-by: Sasha Levin 
---
 arch/x86/kernel/fpu/signal.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c
index 23f1691670b6..61a949d84dfa 100644
--- a/arch/x86/kernel/fpu/signal.c
+++ b/arch/x86/kernel/fpu/signal.c
@@ -314,7 +314,6 @@ static int __fpu__restore_sig(void __user *buf, void __user 
*buf_fx, int size)
 * thread's fpu state, reconstruct fxstate from the fsave
 * header. Validate and sanitize the copied state.
 */
-   struct fpu *fpu = >thread.fpu;
struct user_i387_ia32_struct env;
int err = 0;
 
-- 
2.17.1



[PATCH AUTOSEL 4.18 22/33] perf tools: Fix use of alternatives to find JDIR

2018-10-30 Thread Sasha Levin
From: Jarod Wilson 

[ Upstream commit 36b8d4628d3cc8f5a748e508cce8673bc00fc63c ]

When a build is run from something like a cron job, the user's $PATH is
rather minimal, of note, not including /usr/sbin in my own case. Because
of that, an automated rpm package build ultimately fails to find
libperf-jvmti.so, because somewhere within the build, this happens...

  /bin/sh: alternatives: command not found
  /bin/sh: alternatives: command not found
  Makefile.config:849: No openjdk development package found, please install
  JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel

...and while the build continues, libperf-jvmti.so isn't built, and
things fall down when rpm tries to find all the %files specified. Exact
same system builds everything just fine when the job is launched from a
login shell instead of a cron job, since alternatives is in $PATH, so
openjdk is actually found.

The test required to get into this section of code actually specifies
the full path, as does a block just above it, so let's do that here too.

Signed-off-by: Jarod Wilson 
Acked-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: William Cohen 
Fixes: d4dfdf00d43e ("perf jvmti: Plug compilation into perf build")
Link: http://lkml.kernel.org/r/20180906221812.11167-1-ja...@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/Makefile.config | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 67b042738ed7..986151732d68 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -831,7 +831,7 @@ ifndef NO_JVMTI
 JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print 
$$3}')
   else
 ifneq (,$(wildcard /usr/sbin/alternatives))
-  JDIR=$(shell alternatives --display java | tail -1 | cut -d' ' -f 5 | 
sed 's%/jre/bin/java.%%g')
+  JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' 
-f 5 | sed 's%/jre/bin/java.%%g')
 endif
   endif
   ifndef JDIR
-- 
2.17.1



[PATCH AUTOSEL 4.18 21/33] perf evsel: Store ids for events with their own cpus perf_event__synthesize_event_update_cpus

2018-10-30 Thread Sasha Levin
From: Jiri Olsa 

[ Upstream commit 4ab8455f8bd83298bf7f67ab9357e3b1cc765c7d ]

John reported crash when recording on an event under PMU with cpumask defined:

  root@localhost:~# ./perf_debug_ record -e armv8_pmuv3_0/br_mis_pred/ sleep 1
  perf: Segmentation fault
  Obtained 9 stack frames.
  ./perf_debug_() [0x4c5ef8]
  [0x82ba267c]
  ./perf_debug_() [0x4bc5a8]
  ./perf_debug_() [0x419550]
  ./perf_debug_() [0x41a928]
  ./perf_debug_() [0x472f58]
  ./perf_debug_() [0x473210]
  ./perf_debug_() [0x4070f4]
  /lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe0) [0x8294c8a0]
  Segmentation fault (core dumped)

We synthesize an update event that needs to touch the evsel id array, which is
not defined at that time. Fixing this by forcing the id allocation for events
with their own cpus.

Reported-by: John Garry 
Signed-off-by: Jiri Olsa 
Tested-by: John Garry 
Cc: Alexander Shishkin 
Cc: Andi Kleen 
Cc: Mark Rutland 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Will Deacon 
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux...@huawei.com
Fixes: bfd8f72c2778 ("perf record: Synthesize unit/scale/... in event update")
Link: http://lkml.kernel.org/r/20181003212052.GA32371@krava
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 tools/perf/builtin-report.c | 1 +
 tools/perf/util/evsel.c | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index c04dc7b53797..82a3c8be19ee 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -981,6 +981,7 @@ int cmd_report(int argc, const char **argv)
.id_index= perf_event__process_id_index,
.auxtrace_info   = perf_event__process_auxtrace_info,
.auxtrace= perf_event__process_auxtrace,
+   .event_update= perf_event__process_event_update,
.feature = process_feature_event,
.ordered_events  = true,
.ordering_requires_timestamps = true,
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 6324afba8fdd..86ad1389ff5a 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1078,6 +1078,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct 
record_opts *opts,
attr->exclude_user   = 1;
}
 
+   if (evsel->own_cpus)
+   evsel->attr.read_format |= PERF_FORMAT_ID;
+
/*
 * Apply event specific term settings,
 * it overloads any global configuration.
-- 
2.17.1



[PATCH AUTOSEL 4.18 27/33] r8169: re-enable MSI-X on RTL8168g

2018-10-30 Thread Sasha Levin
From: Heiner Kallweit 

[ Upstream commit 9675931e6b65d160d16bcc9472c1acef15524def ]

Similar to d49c88d7677b ("r8169: Enable MSI-X on RTL8106e") after
e9d0ba506ea8 ("PCI: Reprogram bridge prefetch registers on resume")
we can safely assume that this also fixes the root cause of
the issue worked around by 7c53a722459c ("r8169: don't use MSI-X on
RTL8168g"). So let's revert it.

Fixes: 7c53a722459c ("r8169: don't use MSI-X on RTL8168g")
Signed-off-by: Heiner Kallweit 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/realtek/r8169.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c 
b/drivers/net/ethernet/realtek/r8169.c
index 36422f783fe7..2eea2b66d970 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7546,11 +7546,6 @@ static int rtl_alloc_irq(struct rtl8169_private *tp)
RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable);
RTL_W8(tp, Cfg9346, Cfg9346_Lock);
flags = PCI_IRQ_LEGACY;
-   } else if (tp->mac_version == RTL_GIGA_MAC_VER_40) {
-   /* This version was reported to have issues with resume
-* from suspend when using MSI-X
-*/
-   flags = PCI_IRQ_LEGACY | PCI_IRQ_MSI;
} else {
flags = PCI_IRQ_ALL_TYPES;
}
-- 
2.17.1



[PATCH AUTOSEL 4.18 26/33] net: qla3xxx: Remove overflowing shift statement

2018-10-30 Thread Sasha Levin
From: Nathan Chancellor 

[ Upstream commit 8c3bf9b62b667456a57aefcf1689e826df146159 ]

Clang currently warns:

drivers/net/ethernet/qlogic/qla3xxx.c:384:24: warning: signed shift
result (0xF) requires 37 bits to represent, but 'int' only has
32 bits [-Wshift-overflow]
((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
  ~~ ^  ~~
1 warning generated.

The warning is certainly accurate since ISP_NVRAM_MASK is defined as
(0x000F << 16) which is then shifted by 16, resulting in 64424509440,
well above UINT_MAX.

Given that this is the only location in this driver where ISP_NVRAM_MASK
is shifted again, it seems likely that ISP_NVRAM_MASK was originally
defined without a shift and during the move of the shift to the
definition, this statement wasn't properly removed (since ISP_NVRAM_MASK
is used in the statenent right above this). Only the maintainers can
confirm this since this statment has been here since the driver was
first added to the kernel.

Link: https://github.com/ClangBuiltLinux/linux/issues/127
Signed-off-by: Nathan Chancellor 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 drivers/net/ethernet/qlogic/qla3xxx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qla3xxx.c 
b/drivers/net/ethernet/qlogic/qla3xxx.c
index b48f76182049..10b075bc5959 100644
--- a/drivers/net/ethernet/qlogic/qla3xxx.c
+++ b/drivers/net/ethernet/qlogic/qla3xxx.c
@@ -380,8 +380,6 @@ static void fm93c56a_select(struct ql3_adapter *qdev)
 
qdev->eeprom_cmd_data = AUBURN_EEPROM_CS_1;
ql_write_nvram_reg(qdev, spir, ISP_NVRAM_MASK | qdev->eeprom_cmd_data);
-   ql_write_nvram_reg(qdev, spir,
-  ((ISP_NVRAM_MASK << 16) | qdev->eeprom_cmd_data));
 }
 
 /*
-- 
2.17.1



[PATCH AUTOSEL 4.18 12/33] sparc: Fix single-pcr perf event counter management.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit cfdc3170d214046b9509183fe9b9544dc644d40b ]

It is important to clear the hw->state value for non-stopped events
when they are added into the PMU.  Otherwise when the event is
scheduled out, we won't read the counter because HES_UPTODATE is still
set.  This breaks 'perf stat' and similar use cases, causing all the
events to show zero.

This worked for multi-pcr because we make explicit sparc_pmu_start()
calls in calculate_multiple_pcrs().  calculate_single_pcr() doesn't do
this because the idea there is to accumulate all of the counter
settings into the single pcr value.  So we have to add explicit
hw->state handling there.

Like x86, we use the PERF_HES_ARCH bit to track truly stopped events
so that we don't accidently start them on a reload.

Related to all of this, sparc_pmu_start() is missing a userpage update
so add it.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index d3149baaa33c..a4cc26bd89a2 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -927,6 +927,8 @@ static void read_in_all_counters(struct cpu_hw_events *cpuc)
sparc_perf_event_update(cp, >hw,
cpuc->current_idx[i]);
cpuc->current_idx[i] = PIC_NO_INDEX;
+   if (cp->hw.state & PERF_HES_STOPPED)
+   cp->hw.state |= PERF_HES_ARCH;
}
}
 }
@@ -959,10 +961,12 @@ static void calculate_single_pcr(struct cpu_hw_events 
*cpuc)
 
enc = perf_event_get_enc(cpuc->events[i]);
cpuc->pcr[0] &= ~mask_for_index(idx);
-   if (hwc->state & PERF_HES_STOPPED)
+   if (hwc->state & PERF_HES_ARCH) {
cpuc->pcr[0] |= nop_for_index(idx);
-   else
+   } else {
cpuc->pcr[0] |= event_encoding(enc, idx);
+   hwc->state = 0;
+   }
}
 out:
cpuc->pcr[0] |= cpuc->event[0]->hw.config_base;
@@ -988,6 +992,9 @@ static void calculate_multiple_pcrs(struct cpu_hw_events 
*cpuc)
 
cpuc->current_idx[i] = idx;
 
+   if (cp->hw.state & PERF_HES_ARCH)
+   continue;
+
sparc_pmu_start(cp, PERF_EF_RELOAD);
}
 out:
@@ -1079,6 +1086,8 @@ static void sparc_pmu_start(struct perf_event *event, int 
flags)
event->hw.state = 0;
 
sparc_pmu_enable_event(cpuc, >hw, idx);
+
+   perf_event_update_userpage(event);
 }
 
 static void sparc_pmu_stop(struct perf_event *event, int flags)
@@ -1371,9 +1380,9 @@ static int sparc_pmu_add(struct perf_event *event, int 
ef_flags)
cpuc->events[n0] = event->hw.event_base;
cpuc->current_idx[n0] = PIC_NO_INDEX;
 
-   event->hw.state = PERF_HES_UPTODATE;
+   event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
if (!(ef_flags & PERF_EF_START))
-   event->hw.state |= PERF_HES_STOPPED;
+   event->hw.state |= PERF_HES_ARCH;
 
/*
 * If group events scheduling transaction was started,
-- 
2.17.1



[PATCH AUTOSEL 4.18 11/33] perf vendor events intel: Fix wrong filter_band* values for uncore events

2018-10-30 Thread Sasha Levin
From: Jiri Olsa 

[ Upstream commit 94aafb74cee0002e2f2eb6dc5376f54d5951ab4d ]

Michael reported that he could not stat following event:

  $ perf stat -e unc_p_freq_ge_1200mhz_cycles -a -- ls
  event syntax error: '..e_1200mhz_cycles'
\___ value too big for format, maximum is 
255
  Run 'perf list' for a list of valid events

The event is unwrapped into:

  uncore_pcu/event=0xb,filter_band0=1200/

where filter_band0 format says it's one byte only:

  # cat uncore_pcu/format/filter_band0
  config1:0-7

while JSON files specifies bigger number:

  "Filter": "filter_band0=1200",

all the filter_band* formats show 1 byte width:

  # cat uncore_pcu/format/filter_band1
  config1:8-15
  # cat uncore_pcu/format/filter_band2
  config1:16-23
  # cat uncore_pcu/format/filter_band3
  config1:24-31

The reason of the issue is that filter_band* values are supposed to be
in 100Mhz units.. it's stated in the JSON help for the events, like:

  filter_band3=XXX, with XXX in 100Mhz units

This patch divides the filter_band* values by 100, plus there's couple
of changes that actually change the number completely, like:

  -"Filter": "edge=1,filter_band2=4000",
  +"Filter": "edge=1,filter_band2=30",

Reported-by: Michael Petlan 
Signed-off-by: Jiri Olsa 
Acked-by: Andi Kleen 
Cc: Alexander Shishkin 
Cc: Kan Liang 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20181010080339.GB15790@krava
Signed-off-by: Arnaldo Carvalho de Melo 
Signed-off-by: Sasha Levin 
---
 .../arch/x86/ivytown/uncore-power.json   | 16 
 .../arch/x86/jaketown/uncore-power.json  | 16 
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json 
b/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
index d40498f2cb1e..635c09fda1d9 100644
--- a/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
+++ b/tools/perf/pmu-events/arch/x86/ivytown/uncore-power.json
@@ -188,7 +188,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xb",
 "EventName": "UNC_P_FREQ_GE_1200MHZ_CYCLES",
-"Filter": "filter_band0=1200",
+"Filter": "filter_band0=12",
 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_1200mhz_cycles %",
 "PerPkg": "1",
@@ -199,7 +199,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xc",
 "EventName": "UNC_P_FREQ_GE_2000MHZ_CYCLES",
-"Filter": "filter_band1=2000",
+"Filter": "filter_band1=20",
 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_2000mhz_cycles %",
 "PerPkg": "1",
@@ -210,7 +210,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xd",
 "EventName": "UNC_P_FREQ_GE_3000MHZ_CYCLES",
-"Filter": "filter_band2=3000",
+"Filter": "filter_band2=30",
 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_3000mhz_cycles %",
 "PerPkg": "1",
@@ -221,7 +221,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xe",
 "EventName": "UNC_P_FREQ_GE_4000MHZ_CYCLES",
-"Filter": "filter_band3=4000",
+"Filter": "filter_band3=40",
 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_4000mhz_cycles %",
 "PerPkg": "1",
@@ -232,7 +232,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xb",
 "EventName": "UNC_P_FREQ_GE_1200MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band0=1200",
+"Filter": "edge=1,filter_band0=12",
 "MetricExpr": "(UNC_P_FREQ_GE_1200MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_1200mhz_cycles %",
 "PerPkg": "1",
@@ -243,7 +243,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xc",
 "EventName": "UNC_P_FREQ_GE_2000MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band1=2000",
+"Filter": "edge=1,filter_band1=20",
 "MetricExpr": "(UNC_P_FREQ_GE_2000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_2000mhz_cycles %",
 "PerPkg": "1",
@@ -254,7 +254,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xd",
 "EventName": "UNC_P_FREQ_GE_3000MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band2=4000",
+"Filter": "edge=1,filter_band2=30",
 "MetricExpr": "(UNC_P_FREQ_GE_3000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 
100.",
 "MetricName": "freq_ge_3000mhz_cycles %",
 "PerPkg": "1",
@@ -265,7 +265,7 @@
 "Counter": "0,1,2,3",
 "EventCode": "0xe",
 "EventName": "UNC_P_FREQ_GE_4000MHZ_TRANSITIONS",
-"Filter": "edge=1,filter_band3=4000",
+"Filter": "edge=1,filter_band3=40",
 "MetricExpr": "(UNC_P_FREQ_GE_4000MHZ_CYCLES / UNC_P_CLOCKTICKS) * 

[PATCH AUTOSEL 4.18 18/33] nfp: flower: fix pedit set actions for multiple partial masks

2018-10-30 Thread Sasha Levin
From: Pieter Jansen van Vuuren 

[ Upstream commit 8913806f166e47c6b3fe8253e9cfb9caabe64341 ]

Previously we did not correctly change headers when using multiple
pedit actions with partial masks. We now take this into account and
no longer just commit the last pedit action.

Fixes: c0b1bd9a8b8a ("nfp: add set ipv4 header action flower offload")
Signed-off-by: Pieter Jansen van Vuuren 
Reviewed-by: Jakub Kicinski 
Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 .../net/ethernet/netronome/nfp/flower/action.c| 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/flower/action.c 
b/drivers/net/ethernet/netronome/nfp/flower/action.c
index 4a6d2db75071..35f294bf0cd4 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/action.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/action.c
@@ -314,12 +314,14 @@ nfp_fl_set_ip4(const struct tc_action *action, int idx, 
u32 off,
 
switch (off) {
case offsetof(struct iphdr, daddr):
-   set_ip_addr->ipv4_dst_mask = mask;
-   set_ip_addr->ipv4_dst = exact;
+   set_ip_addr->ipv4_dst_mask |= mask;
+   set_ip_addr->ipv4_dst &= ~mask;
+   set_ip_addr->ipv4_dst |= exact & mask;
break;
case offsetof(struct iphdr, saddr):
-   set_ip_addr->ipv4_src_mask = mask;
-   set_ip_addr->ipv4_src = exact;
+   set_ip_addr->ipv4_src_mask |= mask;
+   set_ip_addr->ipv4_src &= ~mask;
+   set_ip_addr->ipv4_src |= exact & mask;
break;
default:
return -EOPNOTSUPP;
@@ -336,8 +338,9 @@ static void
 nfp_fl_set_ip6_helper(int opcode_tag, int idx, __be32 exact, __be32 mask,
  struct nfp_fl_set_ipv6_addr *ip6)
 {
-   ip6->ipv6[idx % 4].mask = mask;
-   ip6->ipv6[idx % 4].exact = exact;
+   ip6->ipv6[idx % 4].mask |= mask;
+   ip6->ipv6[idx % 4].exact &= ~mask;
+   ip6->ipv6[idx % 4].exact |= exact & mask;
 
ip6->reserved = cpu_to_be16(0);
ip6->head.jump_id = opcode_tag;
-- 
2.17.1



[PATCH AUTOSEL 4.18 12/33] sparc: Fix single-pcr perf event counter management.

2018-10-30 Thread Sasha Levin
From: "David S. Miller" 

[ Upstream commit cfdc3170d214046b9509183fe9b9544dc644d40b ]

It is important to clear the hw->state value for non-stopped events
when they are added into the PMU.  Otherwise when the event is
scheduled out, we won't read the counter because HES_UPTODATE is still
set.  This breaks 'perf stat' and similar use cases, causing all the
events to show zero.

This worked for multi-pcr because we make explicit sparc_pmu_start()
calls in calculate_multiple_pcrs().  calculate_single_pcr() doesn't do
this because the idea there is to accumulate all of the counter
settings into the single pcr value.  So we have to add explicit
hw->state handling there.

Like x86, we use the PERF_HES_ARCH bit to track truly stopped events
so that we don't accidently start them on a reload.

Related to all of this, sparc_pmu_start() is missing a userpage update
so add it.

Signed-off-by: David S. Miller 
Signed-off-by: Sasha Levin 
---
 arch/sparc/kernel/perf_event.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index d3149baaa33c..a4cc26bd89a2 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -927,6 +927,8 @@ static void read_in_all_counters(struct cpu_hw_events *cpuc)
sparc_perf_event_update(cp, >hw,
cpuc->current_idx[i]);
cpuc->current_idx[i] = PIC_NO_INDEX;
+   if (cp->hw.state & PERF_HES_STOPPED)
+   cp->hw.state |= PERF_HES_ARCH;
}
}
 }
@@ -959,10 +961,12 @@ static void calculate_single_pcr(struct cpu_hw_events 
*cpuc)
 
enc = perf_event_get_enc(cpuc->events[i]);
cpuc->pcr[0] &= ~mask_for_index(idx);
-   if (hwc->state & PERF_HES_STOPPED)
+   if (hwc->state & PERF_HES_ARCH) {
cpuc->pcr[0] |= nop_for_index(idx);
-   else
+   } else {
cpuc->pcr[0] |= event_encoding(enc, idx);
+   hwc->state = 0;
+   }
}
 out:
cpuc->pcr[0] |= cpuc->event[0]->hw.config_base;
@@ -988,6 +992,9 @@ static void calculate_multiple_pcrs(struct cpu_hw_events 
*cpuc)
 
cpuc->current_idx[i] = idx;
 
+   if (cp->hw.state & PERF_HES_ARCH)
+   continue;
+
sparc_pmu_start(cp, PERF_EF_RELOAD);
}
 out:
@@ -1079,6 +1086,8 @@ static void sparc_pmu_start(struct perf_event *event, int 
flags)
event->hw.state = 0;
 
sparc_pmu_enable_event(cpuc, >hw, idx);
+
+   perf_event_update_userpage(event);
 }
 
 static void sparc_pmu_stop(struct perf_event *event, int flags)
@@ -1371,9 +1380,9 @@ static int sparc_pmu_add(struct perf_event *event, int 
ef_flags)
cpuc->events[n0] = event->hw.event_base;
cpuc->current_idx[n0] = PIC_NO_INDEX;
 
-   event->hw.state = PERF_HES_UPTODATE;
+   event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
if (!(ef_flags & PERF_EF_START))
-   event->hw.state |= PERF_HES_STOPPED;
+   event->hw.state |= PERF_HES_ARCH;
 
/*
 * If group events scheduling transaction was started,
-- 
2.17.1



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