[PATCH v2 1/3] clocksource/drivers/atcpit100: Add andestech atcpit100 timer

2017-10-29 Thread Rick Chen
ATCPIT100 is often used on the Andes architecture,
This timer provide 4 PIT channels. Each PIT channel is a
multi-function timer, can be configured as 32,16,8 bit timers
or PWM as well.

For system timer it will set 32-bit timer0 as clock source
and count downwards until underflow and restart again.

It also set 32-bit timer1 as clock event and count downwards
until condition match. It will generate an interrupt for
handling periodically.

Signed-off-by: Greentime Hu 
Signed-off-by: Rick Chen 
---
 drivers/clocksource/timer-atcpit100.c | 199 ++
 1 file changed, 199 insertions(+)
 create mode 100644 drivers/clocksource/timer-atcpit100.c

diff --git a/drivers/clocksource/timer-atcpit100.c 
b/drivers/clocksource/timer-atcpit100.c
new file mode 100644
index 000..6b224c4
--- /dev/null
+++ b/drivers/clocksource/timer-atcpit100.c
@@ -0,0 +1,199 @@
+/*
+ *  Andestech ATCPIT100 Timer Device Driver Implementation
+ *
+ *  Copyright (C) 2016 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+void __iomem *base;
+static u32 freq;
+
+/*
+ * Definition of register offsets
+ */
+
+/* ID and Revision Register */
+#define ID_REV 0x0
+
+/* Configuration Register */
+#define CFG0x10
+
+/* Interrupt Enable Register */
+#define INT_EN 0x14
+#define CH_INT_EN(c, i)((1<

[PATCH v2 1/3] clocksource/drivers/atcpit100: Add andestech atcpit100 timer

2017-10-29 Thread Rick Chen
ATCPIT100 is often used on the Andes architecture,
This timer provide 4 PIT channels. Each PIT channel is a
multi-function timer, can be configured as 32,16,8 bit timers
or PWM as well.

For system timer it will set 32-bit timer0 as clock source
and count downwards until underflow and restart again.

It also set 32-bit timer1 as clock event and count downwards
until condition match. It will generate an interrupt for
handling periodically.

Signed-off-by: Greentime Hu 
Signed-off-by: Rick Chen 
---
 drivers/clocksource/timer-atcpit100.c | 199 ++
 1 file changed, 199 insertions(+)
 create mode 100644 drivers/clocksource/timer-atcpit100.c

diff --git a/drivers/clocksource/timer-atcpit100.c 
b/drivers/clocksource/timer-atcpit100.c
new file mode 100644
index 000..6b224c4
--- /dev/null
+++ b/drivers/clocksource/timer-atcpit100.c
@@ -0,0 +1,199 @@
+/*
+ *  Andestech ATCPIT100 Timer Device Driver Implementation
+ *
+ *  Copyright (C) 2016 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+void __iomem *base;
+static u32 freq;
+
+/*
+ * Definition of register offsets
+ */
+
+/* ID and Revision Register */
+#define ID_REV 0x0
+
+/* Configuration Register */
+#define CFG0x10
+
+/* Interrupt Enable Register */
+#define INT_EN 0x14
+#define CH_INT_EN(c, i)((1mult = div_sc(freq, NSEC_PER_SEC, evt->shift);
+   evt->max_delta_ns = clockevent_delta2ns(0x, evt);
+   evt->min_delta_ns = clockevent_delta2ns(3, evt);
+   clockevents_register_device(evt);
+   setup_irq(irq, _irq);
+}
+
+static int __init atcpit100_init(struct device_node *dev)
+{
+   int irq;
+
+   base = of_iomap(dev, 0);
+   if (!base) {
+   pr_warn("Can't remap registers");
+   return -ENXIO;
+   }
+
+   if (of_property_read_u32(dev, "clock-frequency", )) {
+   pr_warn("Can't read clock-frequency");
+   return -EINVAL;
+   }
+   irq = irq_of_parse_and_map(dev, 0);
+
+   if (irq <= 0) {
+   pr_warn("Failed to map timer IRQ\n");
+   return -EINVAL;
+   }
+   pr_info("ATCPIT100 timer 1 installed on IRQ %d, with clock %d at %d HZ. 
in 0x%08x\r\n",
+   irq, freq, HZ, (u32)base);
+   writel(APB_CLK|TMR_32, base + CH_CTL(0));
+   writel(readl(base + INT_EN) | CH_INT_EN(0, 0), base + INT_EN);
+   writel(readl(base + CH_EN) | CH_TMR_EN(0, 0), base + CH_EN);
+   atcpit100_clocksource_init();
+   atcpit100_clockevent_init(irq);
+
+   return 0;
+}
+
+TIMER_OF_DECLARE(atcpit100, "andestech,atcpit100", atcpit100_init);
-- 
2.7.4



[PATCH v2 3/3] dt-bindings: timer: Add andestech atcpit100 timer binding doc

2017-10-29 Thread Rick Chen
Add a document to describe Andestech atcpit100 timer and
binding information.

Signed-off-by: Greentime Hu 
Signed-off-by: Rick Chen 
---
 .../bindings/timer/andestech,atcpit100-timer.txt   | 31 ++
 1 file changed, 31 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt

diff --git 
a/Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt 
b/Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt
new file mode 100644
index 000..a87278a
--- /dev/null
+++ b/Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt
@@ -0,0 +1,31 @@
+Andestech ATCPIT100 timer
+--
+ATCPIT100 is a generic IP block from Andes Technology, embedded in
+Andestech AE3XX platforms and other designs.
+
+This timer is a set of compact multi-function timers, which can be
+used as pulse width modulators (PWM) as well as simple timers.
+
+It supports up to 4 PIT channels. Each PIT channel is a
+multi-function timer and provide the following usage scenarios:
+One 32-bit timer
+Two 16-bit timers
+Four 8-bit timers
+One 16-bit PWM
+One 16-bit timer and one 8-bit PWM
+Two 8-bit timer and one 8-bit PWM
+
+Required properties:
+- compatible   : Should be "andestech,atcpit100"
+- reg  : Address and length of the register set
+- interrupts   : Reference to the timer interrupt
+- clock-frequency : The rate in HZ in input of the Andestech ATCPIT100 timer
+
+Examples:
+
+timer0: timer@f040 {
+   compatible = "andestech,atcpit100";
+   reg = <0xf040 0x1000>;
+   interrupts = <2 4>;
+   clock-frequency = <3000>;
+};
-- 
2.7.4



[PATCH v2 2/3] clocksource/drivers/Kconfig: Support andestech atcpit100 timer

2017-10-29 Thread Rick Chen
Add CLKSRC_ATCPIT100 for Andestech atcpit100 timer selection.
It often be used in Andestech AE3XX platform.

Signed-off-by: Greentime Hu 
Signed-off-by: Rick Chen 
---
 drivers/clocksource/Kconfig  | 6 ++
 drivers/clocksource/Makefile | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index cc60620..e950066 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -615,4 +615,10 @@ config CLKSRC_ST_LPC
  Enable this option to use the Low Power controller timer
  as clocksource.
 
+config CLKSRC_ATCPIT100
+   bool "Clocksource for AE3XX platform" if COMPILE_TEST
+  depends on GENERIC_CLOCKEVENTS && HAS_IOMEM
+   help
+ This option enables support for the Andestech AE3XX platform timers.
+
 endmenu
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index dbc1ad1..24d15bd 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -74,3 +74,4 @@ obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o
 obj-$(CONFIG_H8300_TPU)+= h8300_tpu.o
 obj-$(CONFIG_CLKSRC_ST_LPC)+= clksrc_st_lpc.o
 obj-$(CONFIG_X86_NUMACHIP) += numachip.o
+obj-$(CONFIG_CLKSRC_ATCPIT100) += timer-atcpit100.o
-- 
2.7.4



[PATCH v2 3/3] dt-bindings: timer: Add andestech atcpit100 timer binding doc

2017-10-29 Thread Rick Chen
Add a document to describe Andestech atcpit100 timer and
binding information.

Signed-off-by: Greentime Hu 
Signed-off-by: Rick Chen 
---
 .../bindings/timer/andestech,atcpit100-timer.txt   | 31 ++
 1 file changed, 31 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt

diff --git 
a/Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt 
b/Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt
new file mode 100644
index 000..a87278a
--- /dev/null
+++ b/Documentation/devicetree/bindings/timer/andestech,atcpit100-timer.txt
@@ -0,0 +1,31 @@
+Andestech ATCPIT100 timer
+--
+ATCPIT100 is a generic IP block from Andes Technology, embedded in
+Andestech AE3XX platforms and other designs.
+
+This timer is a set of compact multi-function timers, which can be
+used as pulse width modulators (PWM) as well as simple timers.
+
+It supports up to 4 PIT channels. Each PIT channel is a
+multi-function timer and provide the following usage scenarios:
+One 32-bit timer
+Two 16-bit timers
+Four 8-bit timers
+One 16-bit PWM
+One 16-bit timer and one 8-bit PWM
+Two 8-bit timer and one 8-bit PWM
+
+Required properties:
+- compatible   : Should be "andestech,atcpit100"
+- reg  : Address and length of the register set
+- interrupts   : Reference to the timer interrupt
+- clock-frequency : The rate in HZ in input of the Andestech ATCPIT100 timer
+
+Examples:
+
+timer0: timer@f040 {
+   compatible = "andestech,atcpit100";
+   reg = <0xf040 0x1000>;
+   interrupts = <2 4>;
+   clock-frequency = <3000>;
+};
-- 
2.7.4



[PATCH v2 2/3] clocksource/drivers/Kconfig: Support andestech atcpit100 timer

2017-10-29 Thread Rick Chen
Add CLKSRC_ATCPIT100 for Andestech atcpit100 timer selection.
It often be used in Andestech AE3XX platform.

Signed-off-by: Greentime Hu 
Signed-off-by: Rick Chen 
---
 drivers/clocksource/Kconfig  | 6 ++
 drivers/clocksource/Makefile | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index cc60620..e950066 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -615,4 +615,10 @@ config CLKSRC_ST_LPC
  Enable this option to use the Low Power controller timer
  as clocksource.
 
+config CLKSRC_ATCPIT100
+   bool "Clocksource for AE3XX platform" if COMPILE_TEST
+  depends on GENERIC_CLOCKEVENTS && HAS_IOMEM
+   help
+ This option enables support for the Andestech AE3XX platform timers.
+
 endmenu
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index dbc1ad1..24d15bd 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -74,3 +74,4 @@ obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o
 obj-$(CONFIG_H8300_TPU)+= h8300_tpu.o
 obj-$(CONFIG_CLKSRC_ST_LPC)+= clksrc_st_lpc.o
 obj-$(CONFIG_X86_NUMACHIP) += numachip.o
+obj-$(CONFIG_CLKSRC_ATCPIT100) += timer-atcpit100.o
-- 
2.7.4



[PATCH V1] rpmsg: glink: Initialize the "intent_req_comp" completion variable

2017-10-29 Thread Arun Kumar Neelakantam
The "intent_req_comp" variable is used without initialization which
results in NULL pointer dereference in qcom_glink_request_intent().

we need to initialize the completion variable before using it.

Fixes: 27b9c5b66b23 ("rpmsg: glink: Request for intents when unavailable")
Signed-off-by: Arun Kumar Neelakantam 
---
 drivers/rpmsg/qcom_glink_native.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/rpmsg/qcom_glink_native.c 
b/drivers/rpmsg/qcom_glink_native.c
index 5dcc9bf..fcd46ab 100644
--- a/drivers/rpmsg/qcom_glink_native.c
+++ b/drivers/rpmsg/qcom_glink_native.c
@@ -227,6 +227,7 @@ static struct glink_channel 
*qcom_glink_alloc_channel(struct qcom_glink *glink,
 
init_completion(>open_req);
init_completion(>open_ack);
+   init_completion(>intent_req_comp);
 
INIT_LIST_HEAD(>done_intents);
INIT_WORK(>intent_work, qcom_glink_rx_done_work);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH V1] rpmsg: glink: Initialize the "intent_req_comp" completion variable

2017-10-29 Thread Arun Kumar Neelakantam
The "intent_req_comp" variable is used without initialization which
results in NULL pointer dereference in qcom_glink_request_intent().

we need to initialize the completion variable before using it.

Fixes: 27b9c5b66b23 ("rpmsg: glink: Request for intents when unavailable")
Signed-off-by: Arun Kumar Neelakantam 
---
 drivers/rpmsg/qcom_glink_native.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/rpmsg/qcom_glink_native.c 
b/drivers/rpmsg/qcom_glink_native.c
index 5dcc9bf..fcd46ab 100644
--- a/drivers/rpmsg/qcom_glink_native.c
+++ b/drivers/rpmsg/qcom_glink_native.c
@@ -227,6 +227,7 @@ static struct glink_channel 
*qcom_glink_alloc_channel(struct qcom_glink *glink,
 
init_completion(>open_req);
init_completion(>open_ack);
+   init_completion(>intent_req_comp);
 
INIT_LIST_HEAD(>done_intents);
INIT_WORK(>intent_work, qcom_glink_rx_done_work);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v4] KVM: arm/arm64: fix the incompatible matching for external abort

2017-10-29 Thread Dongjiu Geng
kvm_vcpu_dabt_isextabt() tries to match a full fault syndrome, but
calls kvm_vcpu_trap_get_fault_type() that only returns the fault class,
thus reducing the scope of the check. This doesn't cause any observable
bug yet as we end-up matching a closely related syndrome for which we
return the same value.

Using kvm_vcpu_trap_get_fault() instead fixes it for good.

Signed-off-by: Dongjiu Geng 
Acked-by: Marc Zyngier 
---
 arch/arm/include/asm/kvm_emulate.h   | 2 +-
 arch/arm64/include/asm/kvm_emulate.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/kvm_emulate.h 
b/arch/arm/include/asm/kvm_emulate.h
index 98089ff..7571b4e 100644
--- a/arch/arm/include/asm/kvm_emulate.h
+++ b/arch/arm/include/asm/kvm_emulate.h
@@ -203,7 +203,7 @@ static inline u8 kvm_vcpu_trap_get_fault_type(struct 
kvm_vcpu *vcpu)
 
 static inline bool kvm_vcpu_dabt_isextabt(struct kvm_vcpu *vcpu)
 {
-   switch (kvm_vcpu_trap_get_fault_type(vcpu)) {
+   switch (kvm_vcpu_trap_get_fault(vcpu)) {
case FSC_SEA:
case FSC_SEA_TTW0:
case FSC_SEA_TTW1:
diff --git a/arch/arm64/include/asm/kvm_emulate.h 
b/arch/arm64/include/asm/kvm_emulate.h
index e5df3fc..8c918c5 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -237,7 +237,7 @@ static inline u8 kvm_vcpu_trap_get_fault_type(const struct 
kvm_vcpu *vcpu)
 
 static inline bool kvm_vcpu_dabt_isextabt(const struct kvm_vcpu *vcpu)
 {
-   switch (kvm_vcpu_trap_get_fault_type(vcpu)) {
+   switch (kvm_vcpu_trap_get_fault(vcpu)) {
case FSC_SEA:
case FSC_SEA_TTW0:
case FSC_SEA_TTW1:
-- 
1.9.1



[PATCH v4] KVM: arm/arm64: fix the incompatible matching for external abort

2017-10-29 Thread Dongjiu Geng
kvm_vcpu_dabt_isextabt() tries to match a full fault syndrome, but
calls kvm_vcpu_trap_get_fault_type() that only returns the fault class,
thus reducing the scope of the check. This doesn't cause any observable
bug yet as we end-up matching a closely related syndrome for which we
return the same value.

Using kvm_vcpu_trap_get_fault() instead fixes it for good.

Signed-off-by: Dongjiu Geng 
Acked-by: Marc Zyngier 
---
 arch/arm/include/asm/kvm_emulate.h   | 2 +-
 arch/arm64/include/asm/kvm_emulate.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/kvm_emulate.h 
b/arch/arm/include/asm/kvm_emulate.h
index 98089ff..7571b4e 100644
--- a/arch/arm/include/asm/kvm_emulate.h
+++ b/arch/arm/include/asm/kvm_emulate.h
@@ -203,7 +203,7 @@ static inline u8 kvm_vcpu_trap_get_fault_type(struct 
kvm_vcpu *vcpu)
 
 static inline bool kvm_vcpu_dabt_isextabt(struct kvm_vcpu *vcpu)
 {
-   switch (kvm_vcpu_trap_get_fault_type(vcpu)) {
+   switch (kvm_vcpu_trap_get_fault(vcpu)) {
case FSC_SEA:
case FSC_SEA_TTW0:
case FSC_SEA_TTW1:
diff --git a/arch/arm64/include/asm/kvm_emulate.h 
b/arch/arm64/include/asm/kvm_emulate.h
index e5df3fc..8c918c5 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -237,7 +237,7 @@ static inline u8 kvm_vcpu_trap_get_fault_type(const struct 
kvm_vcpu *vcpu)
 
 static inline bool kvm_vcpu_dabt_isextabt(const struct kvm_vcpu *vcpu)
 {
-   switch (kvm_vcpu_trap_get_fault_type(vcpu)) {
+   switch (kvm_vcpu_trap_get_fault(vcpu)) {
case FSC_SEA:
case FSC_SEA_TTW0:
case FSC_SEA_TTW1:
-- 
1.9.1



[PATCH v4 1/1] xen/time: do not decrease steal time after live migration on xen

2017-10-29 Thread Dongli Zhang
After guest live migration on xen, steal time in /proc/stat
(cpustat[CPUTIME_STEAL]) might decrease because steal returned by
xen_steal_lock() might be less than this_rq()->prev_steal_time which is
derived from previous return value of xen_steal_clock().

For instance, steal time of each vcpu is 335 before live migration.

cpu  198 0 368 200064 1962 0 0 1340 0 0
cpu0 38 0 81 50063 492 0 0 335 0 0
cpu1 65 0 97 49763 634 0 0 335 0 0
cpu2 38 0 81 50098 462 0 0 335 0 0
cpu3 56 0 107 50138 374 0 0 335 0 0

After live migration, steal time is reduced to 312.

cpu  200 0 370 200330 1971 0 0 1248 0 0
cpu0 38 0 82 50123 500 0 0 312 0 0
cpu1 65 0 97 49832 634 0 0 312 0 0
cpu2 39 0 82 50167 462 0 0 312 0 0
cpu3 56 0 107 50207 374 0 0 312 0 0

Since runstate times are cumulative and cleared during xen live migration
by xen hypervisor, the idea of this patch is to accumulate runstate times
to global percpu variables before live migration suspend. Once guest VM is
resumed, xen_get_runstate_snapshot_cpu() would always return the sum of new
runstate times and previously accumulated times stored in global percpu
variables.

Similar and more severe issue would impact prior linux 4.8-4.10 as
discussed by Michael Las at
https://0xstubs.org/debugging-a-flaky-cpu-steal-time-counter-on-a-paravirtualized-xen-guest,
which would overflow steal time and lead to 100% st usage in top command
for linux 4.8-4.10. A backport of this patch would fix that issue.

References: 
https://0xstubs.org/debugging-a-flaky-cpu-steal-time-counter-on-a-paravirtualized-xen-guest
Signed-off-by: Dongli Zhang 

---
Changed since v1:
  * relocate modification to xen_get_runstate_snapshot_cpu

Changed since v2:
  * accumulate runstate times before live migration

Changed since v3:
  * do not accumulate times in the case of guest checkpointing

---
 drivers/xen/manage.c |  2 ++
 drivers/xen/time.c   | 83 ++--
 include/xen/interface/vcpu.h |  2 ++
 include/xen/xen-ops.h|  1 +
 4 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index c425d03..3dc085d 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -72,6 +72,7 @@ static int xen_suspend(void *data)
}
 
gnttab_suspend();
+   xen_accumulate_runstate_time(-1);
xen_arch_pre_suspend();
 
/*
@@ -84,6 +85,7 @@ static int xen_suspend(void *data)
: 0);
 
xen_arch_post_suspend(si->cancelled);
+   xen_accumulate_runstate_time(si->cancelled);
gnttab_resume();
 
if (!si->cancelled) {
diff --git a/drivers/xen/time.c b/drivers/xen/time.c
index ac5f23f..18e2b76 100644
--- a/drivers/xen/time.c
+++ b/drivers/xen/time.c
@@ -19,6 +19,9 @@
 /* runstate info updated by Xen */
 static DEFINE_PER_CPU(struct vcpu_runstate_info, xen_runstate);
 
+static DEFINE_PER_CPU(u64[RUNSTATE_max], old_runstate_time);
+static u64 **runstate_time_delta;
+
 /* return an consistent snapshot of 64-bit time/counter value */
 static u64 get64(const u64 *p)
 {
@@ -47,8 +50,8 @@ static u64 get64(const u64 *p)
return ret;
 }
 
-static void xen_get_runstate_snapshot_cpu(struct vcpu_runstate_info *res,
- unsigned int cpu)
+static void xen_get_runstate_snapshot_cpu_delta(
+   struct vcpu_runstate_info *res, unsigned int cpu)
 {
u64 state_time;
struct vcpu_runstate_info *state;
@@ -66,6 +69,82 @@ static void xen_get_runstate_snapshot_cpu(struct 
vcpu_runstate_info *res,
 (state_time & XEN_RUNSTATE_UPDATE));
 }
 
+static void xen_get_runstate_snapshot_cpu(struct vcpu_runstate_info *res,
+ unsigned int cpu)
+{
+   int i;
+
+   xen_get_runstate_snapshot_cpu_delta(res, cpu);
+
+   for (i = 0; i < RUNSTATE_max; i++)
+   res->time[i] += per_cpu(old_runstate_time, cpu)[i];
+}
+
+void xen_accumulate_runstate_time(int action)
+{
+   struct vcpu_runstate_info state;
+   int cpu, i;
+
+   switch (action) {
+   case -1: /* backup runstate time before suspend */
+   WARN_ON_ONCE(unlikely(runstate_time_delta));
+
+   runstate_time_delta = kcalloc(num_possible_cpus(),
+ sizeof(*runstate_time_delta),
+ GFP_KERNEL);
+   if (unlikely(!runstate_time_delta)) {
+   pr_alert("%s: failed to allocate runstate_time_delta\n",
+   __func__);
+   return;
+   }
+
+   for_each_possible_cpu(cpu) {
+   runstate_time_delta[cpu] = kmalloc_array(RUNSTATE_max,
+ sizeof(**runstate_time_delta),
+ GFP_KERNEL);
+  

[PATCH v4 1/1] xen/time: do not decrease steal time after live migration on xen

2017-10-29 Thread Dongli Zhang
After guest live migration on xen, steal time in /proc/stat
(cpustat[CPUTIME_STEAL]) might decrease because steal returned by
xen_steal_lock() might be less than this_rq()->prev_steal_time which is
derived from previous return value of xen_steal_clock().

For instance, steal time of each vcpu is 335 before live migration.

cpu  198 0 368 200064 1962 0 0 1340 0 0
cpu0 38 0 81 50063 492 0 0 335 0 0
cpu1 65 0 97 49763 634 0 0 335 0 0
cpu2 38 0 81 50098 462 0 0 335 0 0
cpu3 56 0 107 50138 374 0 0 335 0 0

After live migration, steal time is reduced to 312.

cpu  200 0 370 200330 1971 0 0 1248 0 0
cpu0 38 0 82 50123 500 0 0 312 0 0
cpu1 65 0 97 49832 634 0 0 312 0 0
cpu2 39 0 82 50167 462 0 0 312 0 0
cpu3 56 0 107 50207 374 0 0 312 0 0

Since runstate times are cumulative and cleared during xen live migration
by xen hypervisor, the idea of this patch is to accumulate runstate times
to global percpu variables before live migration suspend. Once guest VM is
resumed, xen_get_runstate_snapshot_cpu() would always return the sum of new
runstate times and previously accumulated times stored in global percpu
variables.

Similar and more severe issue would impact prior linux 4.8-4.10 as
discussed by Michael Las at
https://0xstubs.org/debugging-a-flaky-cpu-steal-time-counter-on-a-paravirtualized-xen-guest,
which would overflow steal time and lead to 100% st usage in top command
for linux 4.8-4.10. A backport of this patch would fix that issue.

References: 
https://0xstubs.org/debugging-a-flaky-cpu-steal-time-counter-on-a-paravirtualized-xen-guest
Signed-off-by: Dongli Zhang 

---
Changed since v1:
  * relocate modification to xen_get_runstate_snapshot_cpu

Changed since v2:
  * accumulate runstate times before live migration

Changed since v3:
  * do not accumulate times in the case of guest checkpointing

---
 drivers/xen/manage.c |  2 ++
 drivers/xen/time.c   | 83 ++--
 include/xen/interface/vcpu.h |  2 ++
 include/xen/xen-ops.h|  1 +
 4 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index c425d03..3dc085d 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -72,6 +72,7 @@ static int xen_suspend(void *data)
}
 
gnttab_suspend();
+   xen_accumulate_runstate_time(-1);
xen_arch_pre_suspend();
 
/*
@@ -84,6 +85,7 @@ static int xen_suspend(void *data)
: 0);
 
xen_arch_post_suspend(si->cancelled);
+   xen_accumulate_runstate_time(si->cancelled);
gnttab_resume();
 
if (!si->cancelled) {
diff --git a/drivers/xen/time.c b/drivers/xen/time.c
index ac5f23f..18e2b76 100644
--- a/drivers/xen/time.c
+++ b/drivers/xen/time.c
@@ -19,6 +19,9 @@
 /* runstate info updated by Xen */
 static DEFINE_PER_CPU(struct vcpu_runstate_info, xen_runstate);
 
+static DEFINE_PER_CPU(u64[RUNSTATE_max], old_runstate_time);
+static u64 **runstate_time_delta;
+
 /* return an consistent snapshot of 64-bit time/counter value */
 static u64 get64(const u64 *p)
 {
@@ -47,8 +50,8 @@ static u64 get64(const u64 *p)
return ret;
 }
 
-static void xen_get_runstate_snapshot_cpu(struct vcpu_runstate_info *res,
- unsigned int cpu)
+static void xen_get_runstate_snapshot_cpu_delta(
+   struct vcpu_runstate_info *res, unsigned int cpu)
 {
u64 state_time;
struct vcpu_runstate_info *state;
@@ -66,6 +69,82 @@ static void xen_get_runstate_snapshot_cpu(struct 
vcpu_runstate_info *res,
 (state_time & XEN_RUNSTATE_UPDATE));
 }
 
+static void xen_get_runstate_snapshot_cpu(struct vcpu_runstate_info *res,
+ unsigned int cpu)
+{
+   int i;
+
+   xen_get_runstate_snapshot_cpu_delta(res, cpu);
+
+   for (i = 0; i < RUNSTATE_max; i++)
+   res->time[i] += per_cpu(old_runstate_time, cpu)[i];
+}
+
+void xen_accumulate_runstate_time(int action)
+{
+   struct vcpu_runstate_info state;
+   int cpu, i;
+
+   switch (action) {
+   case -1: /* backup runstate time before suspend */
+   WARN_ON_ONCE(unlikely(runstate_time_delta));
+
+   runstate_time_delta = kcalloc(num_possible_cpus(),
+ sizeof(*runstate_time_delta),
+ GFP_KERNEL);
+   if (unlikely(!runstate_time_delta)) {
+   pr_alert("%s: failed to allocate runstate_time_delta\n",
+   __func__);
+   return;
+   }
+
+   for_each_possible_cpu(cpu) {
+   runstate_time_delta[cpu] = kmalloc_array(RUNSTATE_max,
+ sizeof(**runstate_time_delta),
+ GFP_KERNEL);
+   if 

Re: [PATCH 2/3] drivers: phy: broadcom: Add driver for Cygnus USB phy controller

2017-10-29 Thread Raveendra Padasalagi
Hi Chanwoo,

On Mon, Oct 30, 2017 at 5:32 AM, Chanwoo Choi  wrote:
> Hi,
>
> On 2017년 10월 27일 17:35, Kishon Vijay Abraham I wrote:
>> +Chanwoo, for reviewing extcon
>>
>> Hi.
>>
>> On Tuesday 24 October 2017 10:07 AM, Raveendra Padasalagi wrote:
>>> Add driver for Broadcom's USB phy controller's used in Cygnus
>>> familyof SoC. Cygnus has three USB phy controller's, port 0,
>>> port 1 provides USB host functionality and port 2 can be configured
>>> for host/device role.
>>>
>>> Configuration of host/device role for port 2 is achieved based on
>>> the extcon events, the driver registers to extcon framework to get
>>> appropriate connect events for Host/Device cables connect/disconnect
>>> states based on VBUS and ID interrupts.
>>>
>>> Signed-off-by: Raveendra Padasalagi 
>>> ---
>>>  drivers/phy/broadcom/Kconfig  |  14 +
>>>  drivers/phy/broadcom/Makefile |   1 +
>>>  drivers/phy/broadcom/phy-bcm-cygnus-usb.c | 672 
>>> ++
>>>  3 files changed, 687 insertions(+)
>>>  create mode 100644 drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>>>
>>> diff --git a/drivers/phy/broadcom/Kconfig b/drivers/phy/broadcom/Kconfig
>>> index 64fc59c..3179daf 100644
>>> --- a/drivers/phy/broadcom/Kconfig
>>> +++ b/drivers/phy/broadcom/Kconfig
>>> @@ -1,6 +1,20 @@
>>>  #
>>>  # Phy drivers for Broadcom platforms
>>>  #
>>> +config PHY_BCM_CYGNUS_USB
>>> +tristate "Broadcom Cygnus USB PHY support"
>>> +depends on OF
>>> +depends on ARCH_BCM_CYGNUS || COMPILE_TEST
>>> +select GENERIC_PHY
>>> +select EXTCON_USB_GPIO
>
> IMO, it is not good to add the dependency to the specific device driver.
> Instead, you better to depend on the EXTCON framework (select EXTCON)
> such as 'select GENERIC_PHY'.

GENERIC_PHY dependency is anyway needed and it's added as dependency.
Let me add "depends on EXTCON" instead of "select EXTCON"

>>
>> Didn't this throw up a warning for selecting config without caring for the
>> dependency?
>>
>>> +default ARCH_BCM_CYGNUS
>>> +help
>>> +  Enable this to support three USB PHY's present in Broadcom's
>>> +  Cygnus chip.
>>> +
>>> +  The phys are capable of supporting host mode on all ports and
>>> +  device mode for port 2.
>>> +
>>>  config PHY_CYGNUS_PCIE
>>>  tristate "Broadcom Cygnus PCIe PHY driver"
>>>  depends on OF && (ARCH_BCM_CYGNUS || COMPILE_TEST)
>>> diff --git a/drivers/phy/broadcom/Makefile b/drivers/phy/broadcom/Makefile
>>> index 4eb82ec..3dec23c 100644
>>> --- a/drivers/phy/broadcom/Makefile
>>> +++ b/drivers/phy/broadcom/Makefile
>>> @@ -1,4 +1,5 @@
>>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)   += phy-bcm-cygnus-pcie.o
>>> +obj-$(CONFIG_PHY_BCM_CYGNUS_USB)+= phy-bcm-cygnus-usb.o
>>>  obj-$(CONFIG_BCM_KONA_USB2_PHY) += phy-bcm-kona-usb2.o
>>>  obj-$(CONFIG_PHY_BCM_NS_USB2)   += phy-bcm-ns-usb2.o
>>>  obj-$(CONFIG_PHY_BCM_NS_USB3)   += phy-bcm-ns-usb3.o
>>> diff --git a/drivers/phy/broadcom/phy-bcm-cygnus-usb.c 
>>> b/drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>>> new file mode 100644
>>> index 000..ef2a94c
>>> --- /dev/null
>>> +++ b/drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>>> @@ -0,0 +1,672 @@
>>> +/*
>>> + * Copyright 2017 Broadcom
>>> + *
>>> + * This program is free software; you can redistribute it and/or modify
>>> + * it under the terms of the GNU General Public License, version 2, as
>>> + * published by the Free Software Foundation (the "GPL").
>>> + *
>>> + * This program is distributed in the hope that it will be useful, but
>>> + * WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> + * General Public License version 2 (GPLv2) for more details.
>>> + *
>>> + * You should have received a copy of the GNU General Public License
>>> + * version 2 (GPLv2) along with this source code.
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#define CDRU_USBPHY_CLK_RST_SEL_OFFSET  0x0
>>> +#define CDRU_USBPHY2_HOST_DEV_SEL_OFFSET0x4
>>> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET 0x5C
>>> +#define CDRU_USBPHY_P0_STATUS_OFFSET0x1C
>>> +#define CDRU_USBPHY_P1_STATUS_OFFSET0x34
>>> +#define CDRU_USBPHY_P2_STATUS_OFFSET0x4C
>>
>> Looks like it has 2 different blocks; CDRU and CMRU. Having a comment for 
>> each
>> of the block will help.
>>> +#define CRMU_USB_PHY_AON_CTRL_OFFSET0x0
>>> +
>>> +#define CDRU_USBPHY_USBPHY_ILDO_ON_FLAG BIT(1)
>>> +#define CDRU_USBPHY_USBPHY_PLL_LOCK BIT(0)
>>> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_DISABLEBIT(0)
>>> +
>>> +#define 

Re: [PATCH 2/3] drivers: phy: broadcom: Add driver for Cygnus USB phy controller

2017-10-29 Thread Raveendra Padasalagi
Hi Chanwoo,

On Mon, Oct 30, 2017 at 5:32 AM, Chanwoo Choi  wrote:
> Hi,
>
> On 2017년 10월 27일 17:35, Kishon Vijay Abraham I wrote:
>> +Chanwoo, for reviewing extcon
>>
>> Hi.
>>
>> On Tuesday 24 October 2017 10:07 AM, Raveendra Padasalagi wrote:
>>> Add driver for Broadcom's USB phy controller's used in Cygnus
>>> familyof SoC. Cygnus has three USB phy controller's, port 0,
>>> port 1 provides USB host functionality and port 2 can be configured
>>> for host/device role.
>>>
>>> Configuration of host/device role for port 2 is achieved based on
>>> the extcon events, the driver registers to extcon framework to get
>>> appropriate connect events for Host/Device cables connect/disconnect
>>> states based on VBUS and ID interrupts.
>>>
>>> Signed-off-by: Raveendra Padasalagi 
>>> ---
>>>  drivers/phy/broadcom/Kconfig  |  14 +
>>>  drivers/phy/broadcom/Makefile |   1 +
>>>  drivers/phy/broadcom/phy-bcm-cygnus-usb.c | 672 
>>> ++
>>>  3 files changed, 687 insertions(+)
>>>  create mode 100644 drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>>>
>>> diff --git a/drivers/phy/broadcom/Kconfig b/drivers/phy/broadcom/Kconfig
>>> index 64fc59c..3179daf 100644
>>> --- a/drivers/phy/broadcom/Kconfig
>>> +++ b/drivers/phy/broadcom/Kconfig
>>> @@ -1,6 +1,20 @@
>>>  #
>>>  # Phy drivers for Broadcom platforms
>>>  #
>>> +config PHY_BCM_CYGNUS_USB
>>> +tristate "Broadcom Cygnus USB PHY support"
>>> +depends on OF
>>> +depends on ARCH_BCM_CYGNUS || COMPILE_TEST
>>> +select GENERIC_PHY
>>> +select EXTCON_USB_GPIO
>
> IMO, it is not good to add the dependency to the specific device driver.
> Instead, you better to depend on the EXTCON framework (select EXTCON)
> such as 'select GENERIC_PHY'.

GENERIC_PHY dependency is anyway needed and it's added as dependency.
Let me add "depends on EXTCON" instead of "select EXTCON"

>>
>> Didn't this throw up a warning for selecting config without caring for the
>> dependency?
>>
>>> +default ARCH_BCM_CYGNUS
>>> +help
>>> +  Enable this to support three USB PHY's present in Broadcom's
>>> +  Cygnus chip.
>>> +
>>> +  The phys are capable of supporting host mode on all ports and
>>> +  device mode for port 2.
>>> +
>>>  config PHY_CYGNUS_PCIE
>>>  tristate "Broadcom Cygnus PCIe PHY driver"
>>>  depends on OF && (ARCH_BCM_CYGNUS || COMPILE_TEST)
>>> diff --git a/drivers/phy/broadcom/Makefile b/drivers/phy/broadcom/Makefile
>>> index 4eb82ec..3dec23c 100644
>>> --- a/drivers/phy/broadcom/Makefile
>>> +++ b/drivers/phy/broadcom/Makefile
>>> @@ -1,4 +1,5 @@
>>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)   += phy-bcm-cygnus-pcie.o
>>> +obj-$(CONFIG_PHY_BCM_CYGNUS_USB)+= phy-bcm-cygnus-usb.o
>>>  obj-$(CONFIG_BCM_KONA_USB2_PHY) += phy-bcm-kona-usb2.o
>>>  obj-$(CONFIG_PHY_BCM_NS_USB2)   += phy-bcm-ns-usb2.o
>>>  obj-$(CONFIG_PHY_BCM_NS_USB3)   += phy-bcm-ns-usb3.o
>>> diff --git a/drivers/phy/broadcom/phy-bcm-cygnus-usb.c 
>>> b/drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>>> new file mode 100644
>>> index 000..ef2a94c
>>> --- /dev/null
>>> +++ b/drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>>> @@ -0,0 +1,672 @@
>>> +/*
>>> + * Copyright 2017 Broadcom
>>> + *
>>> + * This program is free software; you can redistribute it and/or modify
>>> + * it under the terms of the GNU General Public License, version 2, as
>>> + * published by the Free Software Foundation (the "GPL").
>>> + *
>>> + * This program is distributed in the hope that it will be useful, but
>>> + * WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> + * General Public License version 2 (GPLv2) for more details.
>>> + *
>>> + * You should have received a copy of the GNU General Public License
>>> + * version 2 (GPLv2) along with this source code.
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#define CDRU_USBPHY_CLK_RST_SEL_OFFSET  0x0
>>> +#define CDRU_USBPHY2_HOST_DEV_SEL_OFFSET0x4
>>> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET 0x5C
>>> +#define CDRU_USBPHY_P0_STATUS_OFFSET0x1C
>>> +#define CDRU_USBPHY_P1_STATUS_OFFSET0x34
>>> +#define CDRU_USBPHY_P2_STATUS_OFFSET0x4C
>>
>> Looks like it has 2 different blocks; CDRU and CMRU. Having a comment for 
>> each
>> of the block will help.
>>> +#define CRMU_USB_PHY_AON_CTRL_OFFSET0x0
>>> +
>>> +#define CDRU_USBPHY_USBPHY_ILDO_ON_FLAG BIT(1)
>>> +#define CDRU_USBPHY_USBPHY_PLL_LOCK BIT(0)
>>> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_DISABLEBIT(0)
>>> +
>>> +#define PHY2_DEV_HOST_CTRL_SEL_DEVICE   0
>>> +#define 

Re: [lkp-robot] [perf/x86] a5df70c354: perf-sanity-tests.Parse_event_definition_strings.fail

2017-10-29 Thread Li Zhijian

attached to full output:


root@lkp-hsw-ep5 
/usr/src/linux-perf-x86_64-rhel-7.2-bb176f67090ca54869fc1262c913aa69d2ede070/tools/perf#
 ./perf test -F 6 -v
 6: Parse event definition strings:
--- start ---
running test 0 'syscalls:sys_enter_openat'
Using CPUID GenuineIntel-6-3F
running test 1 'syscalls:*'
running test 2 'r1a'
running test 3 '1:1'
running test 4 'instructions'
running test 5 'cycles/period=10,config2/'
running test 6 'faults'
running test 7 'L1-dcache-load-miss'
running test 8 'mem:0'
running test 9 'mem:0:x'
running test 10 'mem:0:r'
running test 11 'mem:0:w'
running test 12 'syscalls:sys_enter_openat:k'
running test 13 'syscalls:*:u'
running test 14 'r1a:kp'
running test 15 '1:1:hp'
running test 16 'instructions:h'
running test 17 'faults:u'
running test 18 'L1-dcache-load-miss:kp'
running test 19 'mem:0:u'
running test 20 'mem:0:x:k'
running test 21 'mem:0:r:hp'
running test 22 'mem:0:w:up'
running test 23 'r1,syscalls:sys_enter_openat:k,1:1:hp'
running test 24 'instructions:G'
running test 25 'instructions:H'
running test 26 'mem:0:rw'
running test 27 'mem:0:rw:kp'
running test 28 '{instructions:k,cycles:upp}'
running test 29 '{faults:k,cache-references}:u,cycles:k'
running test 30 
'group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u'
running test 31 '{cycles:u,instructions:kp}:p'
running test 32 '{cycles,instructions}:G,{cycles:G,instructions:G},cycles'
running test 33 '*:*'
  [kvmmmu:kvm_mmu_get_page] bad op token {
  [kvmmmu:kvm_mmu_sync_page] bad op token {
  [kvmmmu:kvm_mmu_unsync_page] bad op token {
  [kvmmmu:kvm_mmu_prepare_zap_page] bad op token {
  [kvmmmu:fast_page_fault] function is_writable_pte not defined
  [libata:ata_qc_issue] function libata_trace_parse_subcmd not defined
  [libata:ata_qc_complete_internal] function libata_trace_parse_qc_flags not 
defined
  [libata:ata_qc_complete_failed] function libata_trace_parse_qc_flags not 
defined
  [libata:ata_qc_complete_done] function libata_trace_parse_qc_flags not defined
  [libata:ata_eh_link_autopsy] function libata_trace_parse_eh_action not defined
  [libata:ata_eh_link_autopsy_qc] function libata_trace_parse_qc_flags not 
defined
  [sunrpc:xprt_lookup_rqst] function __builtin_bswap32 not defined
  [sunrpc:xprt_transmit] function __builtin_bswap32 not defined
  [sunrpc:xprt_complete_rqst] function __builtin_bswap32 not defined
  [sunrpc:xs_tcp_data_recv] function __builtin_bswap32 not defined
  [sunrpc:svc_recv] function __builtin_bswap32 not defined
  [sunrpc:svc_defer] function __builtin_bswap32 not defined
  [sunrpc:svc_drop] function __builtin_bswap32 not defined
  [sunrpc:svc_process] function __builtin_bswap32 not defined
  [sunrpc:svc_send] function __builtin_bswap32 not defined
  [sunrpc:svc_drop_deferred] function __builtin_bswap32 not defined
  [sunrpc:svc_revisit_deferred] function __builtin_bswap32 not defined
  [ras:extlog_mem_event] function cper_severity_str not defined
  [ras:mc_event] function mc_event_error_type not defined
  [xhci-hcd:xhci_handle_event] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_handle_command] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_handle_transfer] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_queue_trb] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_urb_enqueue] bad op token {
  [xhci-hcd:xhci_urb_giveback] bad op token {
  [xhci-hcd:xhci_urb_dequeue] bad op token {
  [xhci-hcd:xhci_handle_cmd_stop_ep] function xhci_decode_ep_context not defined
  [xhci-hcd:xhci_handle_cmd_set_deq_ep] function xhci_decode_ep_context not 
defined
  [xhci-hcd:xhci_handle_cmd_reset_ep] function xhci_decode_ep_context not 
defined
  [xhci-hcd:xhci_handle_cmd_config_ep] function xhci_decode_ep_context not 
defined
  [xhci-hcd:xhci_alloc_dev] function xhci_decode_slot_context not defined
  [xhci-hcd:xhci_free_dev] function xhci_decode_slot_context not defined
  [xhci-hcd:xhci_handle_cmd_disable_slot] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_discover_or_reset_device] function xhci_decode_slot_context 
not defined
  [xhci-hcd:xhci_setup_device_slot] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_handle_cmd_addr_dev] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_handle_cmd_reset_dev] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_handle_cmd_set_deq] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_ring_alloc] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_ring_free] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_ring_expansion] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_inc_enq] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_inc_deq] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_handle_port_status] function xhci_decode_portsc not defined
  [dwc3:dwc3_event] function dwc3_decode_event not defined
  [dwc3:dwc3_ctrl_req] function 

Re: [lkp-robot] [perf/x86] a5df70c354: perf-sanity-tests.Parse_event_definition_strings.fail

2017-10-29 Thread Li Zhijian

attached to full output:


root@lkp-hsw-ep5 
/usr/src/linux-perf-x86_64-rhel-7.2-bb176f67090ca54869fc1262c913aa69d2ede070/tools/perf#
 ./perf test -F 6 -v
 6: Parse event definition strings:
--- start ---
running test 0 'syscalls:sys_enter_openat'
Using CPUID GenuineIntel-6-3F
running test 1 'syscalls:*'
running test 2 'r1a'
running test 3 '1:1'
running test 4 'instructions'
running test 5 'cycles/period=10,config2/'
running test 6 'faults'
running test 7 'L1-dcache-load-miss'
running test 8 'mem:0'
running test 9 'mem:0:x'
running test 10 'mem:0:r'
running test 11 'mem:0:w'
running test 12 'syscalls:sys_enter_openat:k'
running test 13 'syscalls:*:u'
running test 14 'r1a:kp'
running test 15 '1:1:hp'
running test 16 'instructions:h'
running test 17 'faults:u'
running test 18 'L1-dcache-load-miss:kp'
running test 19 'mem:0:u'
running test 20 'mem:0:x:k'
running test 21 'mem:0:r:hp'
running test 22 'mem:0:w:up'
running test 23 'r1,syscalls:sys_enter_openat:k,1:1:hp'
running test 24 'instructions:G'
running test 25 'instructions:H'
running test 26 'mem:0:rw'
running test 27 'mem:0:rw:kp'
running test 28 '{instructions:k,cycles:upp}'
running test 29 '{faults:k,cache-references}:u,cycles:k'
running test 30 
'group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u'
running test 31 '{cycles:u,instructions:kp}:p'
running test 32 '{cycles,instructions}:G,{cycles:G,instructions:G},cycles'
running test 33 '*:*'
  [kvmmmu:kvm_mmu_get_page] bad op token {
  [kvmmmu:kvm_mmu_sync_page] bad op token {
  [kvmmmu:kvm_mmu_unsync_page] bad op token {
  [kvmmmu:kvm_mmu_prepare_zap_page] bad op token {
  [kvmmmu:fast_page_fault] function is_writable_pte not defined
  [libata:ata_qc_issue] function libata_trace_parse_subcmd not defined
  [libata:ata_qc_complete_internal] function libata_trace_parse_qc_flags not 
defined
  [libata:ata_qc_complete_failed] function libata_trace_parse_qc_flags not 
defined
  [libata:ata_qc_complete_done] function libata_trace_parse_qc_flags not defined
  [libata:ata_eh_link_autopsy] function libata_trace_parse_eh_action not defined
  [libata:ata_eh_link_autopsy_qc] function libata_trace_parse_qc_flags not 
defined
  [sunrpc:xprt_lookup_rqst] function __builtin_bswap32 not defined
  [sunrpc:xprt_transmit] function __builtin_bswap32 not defined
  [sunrpc:xprt_complete_rqst] function __builtin_bswap32 not defined
  [sunrpc:xs_tcp_data_recv] function __builtin_bswap32 not defined
  [sunrpc:svc_recv] function __builtin_bswap32 not defined
  [sunrpc:svc_defer] function __builtin_bswap32 not defined
  [sunrpc:svc_drop] function __builtin_bswap32 not defined
  [sunrpc:svc_process] function __builtin_bswap32 not defined
  [sunrpc:svc_send] function __builtin_bswap32 not defined
  [sunrpc:svc_drop_deferred] function __builtin_bswap32 not defined
  [sunrpc:svc_revisit_deferred] function __builtin_bswap32 not defined
  [ras:extlog_mem_event] function cper_severity_str not defined
  [ras:mc_event] function mc_event_error_type not defined
  [xhci-hcd:xhci_handle_event] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_handle_command] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_handle_transfer] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_queue_trb] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_urb_enqueue] bad op token {
  [xhci-hcd:xhci_urb_giveback] bad op token {
  [xhci-hcd:xhci_urb_dequeue] bad op token {
  [xhci-hcd:xhci_handle_cmd_stop_ep] function xhci_decode_ep_context not defined
  [xhci-hcd:xhci_handle_cmd_set_deq_ep] function xhci_decode_ep_context not 
defined
  [xhci-hcd:xhci_handle_cmd_reset_ep] function xhci_decode_ep_context not 
defined
  [xhci-hcd:xhci_handle_cmd_config_ep] function xhci_decode_ep_context not 
defined
  [xhci-hcd:xhci_alloc_dev] function xhci_decode_slot_context not defined
  [xhci-hcd:xhci_free_dev] function xhci_decode_slot_context not defined
  [xhci-hcd:xhci_handle_cmd_disable_slot] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_discover_or_reset_device] function xhci_decode_slot_context 
not defined
  [xhci-hcd:xhci_setup_device_slot] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_handle_cmd_addr_dev] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_handle_cmd_reset_dev] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_handle_cmd_set_deq] function xhci_decode_slot_context not 
defined
  [xhci-hcd:xhci_ring_alloc] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_ring_free] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_ring_expansion] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_inc_enq] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_inc_deq] function xhci_ring_type_string not defined
  [xhci-hcd:xhci_handle_port_status] function xhci_decode_portsc not defined
  [dwc3:dwc3_event] function dwc3_decode_event not defined
  [dwc3:dwc3_ctrl_req] function 

[PATCH 08/10] staging: lustre: lov: use list_for_each_entry in lov_obd.c

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/lov/lov_obd.c |6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c 
b/drivers/staging/lustre/lustre/lov/lov_obd.c
index fefd3c588681..7e013229d7b5 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -827,11 +827,9 @@ int lov_setup(struct obd_device *obd, struct lustre_cfg 
*lcfg)
 static int lov_cleanup(struct obd_device *obd)
 {
struct lov_obd *lov = >u.lov;
-   struct list_head *pos, *tmp;
-   struct pool_desc *pool;
+   struct pool_desc *pool, *tmp;
 
-   list_for_each_safe(pos, tmp, >lov_pool_list) {
-   pool = list_entry(pos, struct pool_desc, pool_list);
+   list_for_each_entry_safe(pool, tmp, >lov_pool_list, pool_list) {
/* free pool structs */
CDEBUG(D_INFO, "delete pool %p\n", pool);
/* In the function below, .hs_keycmp resolves to




[PATCH 10/10] staging: lustre: obdclass: simplify cl_lock_fini()

2017-10-29 Thread NeilBrown
Using list_first_entry_or_null() makes this (slightly)
simpler.

Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/obdclass/cl_lock.c |9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/cl_lock.c 
b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
index 20e64051d2d6..fa97f4b39bd1 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_lock.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
@@ -78,13 +78,12 @@ EXPORT_SYMBOL(cl_lock_slice_add);
 
 void cl_lock_fini(const struct lu_env *env, struct cl_lock *lock)
 {
+   struct cl_lock_slice *slice;
cl_lock_trace(D_DLMTRACE, env, "destroy lock", lock);
 
-   while (!list_empty(>cll_layers)) {
-   struct cl_lock_slice *slice;
-
-   slice = list_entry(lock->cll_layers.next,
-  struct cl_lock_slice, cls_linkage);
+   while ((slice = list_first_entry_or_null(>cll_layers,
+struct cl_lock_slice,
+cls_linkage)) != NULL) {
list_del_init(lock->cll_layers.next);
slice->cls_ops->clo_fini(env, slice);
}




[PATCH 08/10] staging: lustre: lov: use list_for_each_entry in lov_obd.c

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/lov/lov_obd.c |6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c 
b/drivers/staging/lustre/lustre/lov/lov_obd.c
index fefd3c588681..7e013229d7b5 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -827,11 +827,9 @@ int lov_setup(struct obd_device *obd, struct lustre_cfg 
*lcfg)
 static int lov_cleanup(struct obd_device *obd)
 {
struct lov_obd *lov = >u.lov;
-   struct list_head *pos, *tmp;
-   struct pool_desc *pool;
+   struct pool_desc *pool, *tmp;
 
-   list_for_each_safe(pos, tmp, >lov_pool_list) {
-   pool = list_entry(pos, struct pool_desc, pool_list);
+   list_for_each_entry_safe(pool, tmp, >lov_pool_list, pool_list) {
/* free pool structs */
CDEBUG(D_INFO, "delete pool %p\n", pool);
/* In the function below, .hs_keycmp resolves to




[PATCH 10/10] staging: lustre: obdclass: simplify cl_lock_fini()

2017-10-29 Thread NeilBrown
Using list_first_entry_or_null() makes this (slightly)
simpler.

Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/obdclass/cl_lock.c |9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/cl_lock.c 
b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
index 20e64051d2d6..fa97f4b39bd1 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_lock.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
@@ -78,13 +78,12 @@ EXPORT_SYMBOL(cl_lock_slice_add);
 
 void cl_lock_fini(const struct lu_env *env, struct cl_lock *lock)
 {
+   struct cl_lock_slice *slice;
cl_lock_trace(D_DLMTRACE, env, "destroy lock", lock);
 
-   while (!list_empty(>cll_layers)) {
-   struct cl_lock_slice *slice;
-
-   slice = list_entry(lock->cll_layers.next,
-  struct cl_lock_slice, cls_linkage);
+   while ((slice = list_first_entry_or_null(>cll_layers,
+struct cl_lock_slice,
+cls_linkage)) != NULL) {
list_del_init(lock->cll_layers.next);
slice->cls_ops->clo_fini(env, slice);
}




[PATCH 09/10] staging: lustre: simplfy lov_finish_set()

2017-10-29 Thread NeilBrown
When deleting everything from a list, a while loop
is cleaner than list_for_each_safe().

Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/lov/lov_request.c |   10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c 
b/drivers/staging/lustre/lustre/lov/lov_request.c
index 9d3b3f3e9f10..54f883e359ce 100644
--- a/drivers/staging/lustre/lustre/lov/lov_request.c
+++ b/drivers/staging/lustre/lustre/lov/lov_request.c
@@ -48,15 +48,13 @@ static void lov_init_set(struct lov_request_set *set)
 
 static void lov_finish_set(struct lov_request_set *set)
 {
-   struct list_head *pos, *n;
+   struct lov_request *req;
 
LASSERT(set);
-   list_for_each_safe(pos, n, >set_list) {
-   struct lov_request *req = list_entry(pos,
-struct lov_request,
-rq_link);
+   while ((req = list_first_entry_or_null(>set_list,
+  struct lov_request,
+  rq_link)) != NULL) {
list_del_init(>rq_link);
-
kfree(req->rq_oi.oi_osfs);
kfree(req);
}




[PATCH 09/10] staging: lustre: simplfy lov_finish_set()

2017-10-29 Thread NeilBrown
When deleting everything from a list, a while loop
is cleaner than list_for_each_safe().

Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/lov/lov_request.c |   10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c 
b/drivers/staging/lustre/lustre/lov/lov_request.c
index 9d3b3f3e9f10..54f883e359ce 100644
--- a/drivers/staging/lustre/lustre/lov/lov_request.c
+++ b/drivers/staging/lustre/lustre/lov/lov_request.c
@@ -48,15 +48,13 @@ static void lov_init_set(struct lov_request_set *set)
 
 static void lov_finish_set(struct lov_request_set *set)
 {
-   struct list_head *pos, *n;
+   struct lov_request *req;
 
LASSERT(set);
-   list_for_each_safe(pos, n, >set_list) {
-   struct lov_request *req = list_entry(pos,
-struct lov_request,
-rq_link);
+   while ((req = list_first_entry_or_null(>set_list,
+  struct lov_request,
+  rq_link)) != NULL) {
list_del_init(>rq_link);
-
kfree(req->rq_oi.oi_osfs);
kfree(req);
}




[PATCH 05/10] staging: lustre: ldlm: use list_first_entry in ldlm_lockd.c

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c |   10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
index e2707336586c..2aaa5e91c66c 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
@@ -693,13 +693,13 @@ static int ldlm_bl_get_work(struct ldlm_bl_pool *blp,
/* process a request from the blp_list at least every blp_num_threads */
if (!list_empty(>blp_list) &&
(list_empty(>blp_prio_list) || num_bl == 0))
-   blwi = list_entry(blp->blp_list.next,
- struct ldlm_bl_work_item, blwi_entry);
+   blwi = list_first_entry(>blp_list,
+   struct ldlm_bl_work_item, blwi_entry);
else
if (!list_empty(>blp_prio_list))
-   blwi = list_entry(blp->blp_prio_list.next,
- struct ldlm_bl_work_item,
- blwi_entry);
+   blwi = list_first_entry(>blp_prio_list,
+   struct ldlm_bl_work_item,
+   blwi_entry);
 
if (blwi) {
if (++num_bl >= num_th)




[PATCH 06/10] staging: lustre: ldlm: minor list_entry improvements in ldlm_request.c

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_request.c |   12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
index f5e791a92f62..1e7b8fc4dd00 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
@@ -1642,7 +1642,7 @@ int ldlm_cli_cancel_list(struct list_head *cancels, int 
count,
 */
while (count > 0) {
LASSERT(!list_empty(cancels));
-   lock = list_entry(cancels->next, struct ldlm_lock, l_bl_ast);
+   lock = list_first_entry(cancels, struct ldlm_lock, l_bl_ast);
LASSERT(lock->l_conn_export);
 
if (exp_connect_cancelset(lock->l_conn_export)) {
@@ -1766,7 +1766,7 @@ EXPORT_SYMBOL(ldlm_cli_cancel_unused);
 static int ldlm_resource_foreach(struct ldlm_resource *res,
 ldlm_iterator_t iter, void *closure)
 {
-   struct list_head *tmp, *next;
+   struct ldlm_lock *tmp;
struct ldlm_lock *lock;
int rc = LDLM_ITER_CONTINUE;
 
@@ -1774,18 +1774,14 @@ static int ldlm_resource_foreach(struct ldlm_resource 
*res,
return LDLM_ITER_CONTINUE;
 
lock_res(res);
-   list_for_each_safe(tmp, next, >lr_granted) {
-   lock = list_entry(tmp, struct ldlm_lock, l_res_link);
-
+   list_for_each_entry_safe(lock, tmp, >lr_granted, l_res_link) {
if (iter(lock, closure) == LDLM_ITER_STOP) {
rc = LDLM_ITER_STOP;
goto out;
}
}
 
-   list_for_each_safe(tmp, next, >lr_waiting) {
-   lock = list_entry(tmp, struct ldlm_lock, l_res_link);
-
+   list_for_each_entry_safe(lock, tmp, >lr_waiting, l_res_link) {
if (iter(lock, closure) == LDLM_ITER_STOP) {
rc = LDLM_ITER_STOP;
goto out;




[PATCH 07/10] staging: lustre: ldlm: use list_for_each_entry in ldlm_resource.c

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_resource.c |   20 +++-
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
index c2ddf7312571..980d970174d8 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -751,24 +751,22 @@ extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock 
*lock);
 static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
 __u64 flags)
 {
-   struct list_head *tmp;
int rc = 0;
bool local_only = !!(flags & LDLM_FL_LOCAL_ONLY);
 
do {
-   struct ldlm_lock *lock = NULL;
+   struct ldlm_lock *lock = NULL, *tmp;
struct lustre_handle lockh;
 
/* First, we look for non-cleaned-yet lock
 * all cleaned locks are marked by CLEANED flag.
 */
lock_res(res);
-   list_for_each(tmp, q) {
-   lock = list_entry(tmp, struct ldlm_lock, l_res_link);
-   if (ldlm_is_cleaned(lock)) {
-   lock = NULL;
+   list_for_each_entry(tmp, q, l_res_link) {
+   if (ldlm_is_cleaned(tmp))
continue;
-   }
+
+   lock = tmp;
LDLM_LOCK_GET(lock);
ldlm_set_cleaned(lock);
break;
@@ -1282,19 +1280,15 @@ void ldlm_res2desc(struct ldlm_resource *res, struct 
ldlm_resource_desc *desc)
  */
 void ldlm_dump_all_namespaces(enum ldlm_side client, int level)
 {
-   struct list_head *tmp;
+   struct ldlm_namespace *ns;
 
if (!((libcfs_debug | D_ERROR) & level))
return;
 
mutex_lock(ldlm_namespace_lock(client));
 
-   list_for_each(tmp, ldlm_namespace_list(client)) {
-   struct ldlm_namespace *ns;
-
-   ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
+   list_for_each_entry(ns, ldlm_namespace_list(client), ns_list_chain)
ldlm_namespace_dump(level, ns);
-   }
 
mutex_unlock(ldlm_namespace_lock(client));
 }




[PATCH 04/10] staging: lustre: ldlm: use list_for_each_entry in ldlm_lock.c

2017-10-29 Thread NeilBrown
This makes some slightly-confusing code a bit clearer, and
avoids the need for 'tmp'.

Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_lock.c |   10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index ed061cc46986..036a509eb515 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -885,17 +885,15 @@ static void search_granted_lock(struct list_head *queue,
struct ldlm_lock *req,
struct sl_insert_point *prev)
 {
-   struct list_head *tmp;
struct ldlm_lock *lock, *mode_end, *policy_end;
 
-   list_for_each(tmp, queue) {
-   lock = list_entry(tmp, struct ldlm_lock, l_res_link);
+   list_for_each_entry(lock, queue, l_res_link) {
 
mode_end = list_prev_entry(lock, l_sl_mode);
 
if (lock->l_req_mode != req->l_req_mode) {
/* jump to last lock of mode group */
-   tmp = _end->l_res_link;
+   lock = mode_end;
continue;
}
 
@@ -932,9 +930,7 @@ static void search_granted_lock(struct list_head *queue,
break;
 
/* go to next policy group within mode group */
-   tmp = policy_end->l_res_link.next;
-   lock = list_entry(tmp, struct ldlm_lock,
- l_res_link);
+   lock = list_next_entry(policy_end, l_res_link);
}  /* loop over policy groups within the mode group */
 
/* insert point is last lock of the mode group,




[PATCH 05/10] staging: lustre: ldlm: use list_first_entry in ldlm_lockd.c

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c |   10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
index e2707336586c..2aaa5e91c66c 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
@@ -693,13 +693,13 @@ static int ldlm_bl_get_work(struct ldlm_bl_pool *blp,
/* process a request from the blp_list at least every blp_num_threads */
if (!list_empty(>blp_list) &&
(list_empty(>blp_prio_list) || num_bl == 0))
-   blwi = list_entry(blp->blp_list.next,
- struct ldlm_bl_work_item, blwi_entry);
+   blwi = list_first_entry(>blp_list,
+   struct ldlm_bl_work_item, blwi_entry);
else
if (!list_empty(>blp_prio_list))
-   blwi = list_entry(blp->blp_prio_list.next,
- struct ldlm_bl_work_item,
- blwi_entry);
+   blwi = list_first_entry(>blp_prio_list,
+   struct ldlm_bl_work_item,
+   blwi_entry);
 
if (blwi) {
if (++num_bl >= num_th)




[PATCH 06/10] staging: lustre: ldlm: minor list_entry improvements in ldlm_request.c

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_request.c |   12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
index f5e791a92f62..1e7b8fc4dd00 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
@@ -1642,7 +1642,7 @@ int ldlm_cli_cancel_list(struct list_head *cancels, int 
count,
 */
while (count > 0) {
LASSERT(!list_empty(cancels));
-   lock = list_entry(cancels->next, struct ldlm_lock, l_bl_ast);
+   lock = list_first_entry(cancels, struct ldlm_lock, l_bl_ast);
LASSERT(lock->l_conn_export);
 
if (exp_connect_cancelset(lock->l_conn_export)) {
@@ -1766,7 +1766,7 @@ EXPORT_SYMBOL(ldlm_cli_cancel_unused);
 static int ldlm_resource_foreach(struct ldlm_resource *res,
 ldlm_iterator_t iter, void *closure)
 {
-   struct list_head *tmp, *next;
+   struct ldlm_lock *tmp;
struct ldlm_lock *lock;
int rc = LDLM_ITER_CONTINUE;
 
@@ -1774,18 +1774,14 @@ static int ldlm_resource_foreach(struct ldlm_resource 
*res,
return LDLM_ITER_CONTINUE;
 
lock_res(res);
-   list_for_each_safe(tmp, next, >lr_granted) {
-   lock = list_entry(tmp, struct ldlm_lock, l_res_link);
-
+   list_for_each_entry_safe(lock, tmp, >lr_granted, l_res_link) {
if (iter(lock, closure) == LDLM_ITER_STOP) {
rc = LDLM_ITER_STOP;
goto out;
}
}
 
-   list_for_each_safe(tmp, next, >lr_waiting) {
-   lock = list_entry(tmp, struct ldlm_lock, l_res_link);
-
+   list_for_each_entry_safe(lock, tmp, >lr_waiting, l_res_link) {
if (iter(lock, closure) == LDLM_ITER_STOP) {
rc = LDLM_ITER_STOP;
goto out;




[PATCH 07/10] staging: lustre: ldlm: use list_for_each_entry in ldlm_resource.c

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_resource.c |   20 +++-
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
index c2ddf7312571..980d970174d8 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -751,24 +751,22 @@ extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock 
*lock);
 static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
 __u64 flags)
 {
-   struct list_head *tmp;
int rc = 0;
bool local_only = !!(flags & LDLM_FL_LOCAL_ONLY);
 
do {
-   struct ldlm_lock *lock = NULL;
+   struct ldlm_lock *lock = NULL, *tmp;
struct lustre_handle lockh;
 
/* First, we look for non-cleaned-yet lock
 * all cleaned locks are marked by CLEANED flag.
 */
lock_res(res);
-   list_for_each(tmp, q) {
-   lock = list_entry(tmp, struct ldlm_lock, l_res_link);
-   if (ldlm_is_cleaned(lock)) {
-   lock = NULL;
+   list_for_each_entry(tmp, q, l_res_link) {
+   if (ldlm_is_cleaned(tmp))
continue;
-   }
+
+   lock = tmp;
LDLM_LOCK_GET(lock);
ldlm_set_cleaned(lock);
break;
@@ -1282,19 +1280,15 @@ void ldlm_res2desc(struct ldlm_resource *res, struct 
ldlm_resource_desc *desc)
  */
 void ldlm_dump_all_namespaces(enum ldlm_side client, int level)
 {
-   struct list_head *tmp;
+   struct ldlm_namespace *ns;
 
if (!((libcfs_debug | D_ERROR) & level))
return;
 
mutex_lock(ldlm_namespace_lock(client));
 
-   list_for_each(tmp, ldlm_namespace_list(client)) {
-   struct ldlm_namespace *ns;
-
-   ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
+   list_for_each_entry(ns, ldlm_namespace_list(client), ns_list_chain)
ldlm_namespace_dump(level, ns);
-   }
 
mutex_unlock(ldlm_namespace_lock(client));
 }




[PATCH 04/10] staging: lustre: ldlm: use list_for_each_entry in ldlm_lock.c

2017-10-29 Thread NeilBrown
This makes some slightly-confusing code a bit clearer, and
avoids the need for 'tmp'.

Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_lock.c |   10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index ed061cc46986..036a509eb515 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -885,17 +885,15 @@ static void search_granted_lock(struct list_head *queue,
struct ldlm_lock *req,
struct sl_insert_point *prev)
 {
-   struct list_head *tmp;
struct ldlm_lock *lock, *mode_end, *policy_end;
 
-   list_for_each(tmp, queue) {
-   lock = list_entry(tmp, struct ldlm_lock, l_res_link);
+   list_for_each_entry(lock, queue, l_res_link) {
 
mode_end = list_prev_entry(lock, l_sl_mode);
 
if (lock->l_req_mode != req->l_req_mode) {
/* jump to last lock of mode group */
-   tmp = _end->l_res_link;
+   lock = mode_end;
continue;
}
 
@@ -932,9 +930,7 @@ static void search_granted_lock(struct list_head *queue,
break;
 
/* go to next policy group within mode group */
-   tmp = policy_end->l_res_link.next;
-   lock = list_entry(tmp, struct ldlm_lock,
- l_res_link);
+   lock = list_next_entry(policy_end, l_res_link);
}  /* loop over policy groups within the mode group */
 
/* insert point is last lock of the mode group,




[PATCH 03/10] staging: lustre: ldlm: use list_first_entry in ldlm_lock

2017-10-29 Thread NeilBrown
This make the code (slightly) more readable.

Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_lock.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index b5d84f3f6071..ed061cc46986 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -1685,7 +1685,7 @@ ldlm_work_bl_ast_lock(struct ptlrpc_request_set *rqset, 
void *opaq)
if (list_empty(arg->list))
return -ENOENT;
 
-   lock = list_entry(arg->list->next, struct ldlm_lock, l_bl_ast);
+   lock = list_first_entry(arg->list, struct ldlm_lock, l_bl_ast);
 
/* nobody should touch l_bl_ast */
lock_res_and_lock(lock);
@@ -1721,7 +1721,7 @@ ldlm_work_cp_ast_lock(struct ptlrpc_request_set *rqset, 
void *opaq)
if (list_empty(arg->list))
return -ENOENT;
 
-   lock = list_entry(arg->list->next, struct ldlm_lock, l_cp_ast);
+   lock = list_first_entry(arg->list, struct ldlm_lock, l_cp_ast);
 
/* It's possible to receive a completion AST before we've set
 * the l_completion_ast pointer: either because the AST arrived
@@ -1767,7 +1767,7 @@ ldlm_work_revoke_ast_lock(struct ptlrpc_request_set 
*rqset, void *opaq)
if (list_empty(arg->list))
return -ENOENT;
 
-   lock = list_entry(arg->list->next, struct ldlm_lock, l_rk_ast);
+   lock = list_first_entry(arg->list, struct ldlm_lock, l_rk_ast);
list_del_init(>l_rk_ast);
 
/* the desc just pretend to exclusive */
@@ -1794,7 +1794,7 @@ static int ldlm_work_gl_ast_lock(struct 
ptlrpc_request_set *rqset, void *opaq)
if (list_empty(arg->list))
return -ENOENT;
 
-   gl_work = list_entry(arg->list->next, struct ldlm_glimpse_work,
+   gl_work = list_first_entry(arg->list, struct ldlm_glimpse_work,
 gl_list);
list_del_init(_work->gl_list);
 




[PATCH 03/10] staging: lustre: ldlm: use list_first_entry in ldlm_lock

2017-10-29 Thread NeilBrown
This make the code (slightly) more readable.

Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_lock.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index b5d84f3f6071..ed061cc46986 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -1685,7 +1685,7 @@ ldlm_work_bl_ast_lock(struct ptlrpc_request_set *rqset, 
void *opaq)
if (list_empty(arg->list))
return -ENOENT;
 
-   lock = list_entry(arg->list->next, struct ldlm_lock, l_bl_ast);
+   lock = list_first_entry(arg->list, struct ldlm_lock, l_bl_ast);
 
/* nobody should touch l_bl_ast */
lock_res_and_lock(lock);
@@ -1721,7 +1721,7 @@ ldlm_work_cp_ast_lock(struct ptlrpc_request_set *rqset, 
void *opaq)
if (list_empty(arg->list))
return -ENOENT;
 
-   lock = list_entry(arg->list->next, struct ldlm_lock, l_cp_ast);
+   lock = list_first_entry(arg->list, struct ldlm_lock, l_cp_ast);
 
/* It's possible to receive a completion AST before we've set
 * the l_completion_ast pointer: either because the AST arrived
@@ -1767,7 +1767,7 @@ ldlm_work_revoke_ast_lock(struct ptlrpc_request_set 
*rqset, void *opaq)
if (list_empty(arg->list))
return -ENOENT;
 
-   lock = list_entry(arg->list->next, struct ldlm_lock, l_rk_ast);
+   lock = list_first_entry(arg->list, struct ldlm_lock, l_rk_ast);
list_del_init(>l_rk_ast);
 
/* the desc just pretend to exclusive */
@@ -1794,7 +1794,7 @@ static int ldlm_work_gl_ast_lock(struct 
ptlrpc_request_set *rqset, void *opaq)
if (list_empty(arg->list))
return -ENOENT;
 
-   gl_work = list_entry(arg->list->next, struct ldlm_glimpse_work,
+   gl_work = list_first_entry(arg->list, struct ldlm_glimpse_work,
 gl_list);
list_del_init(_work->gl_list);
 




[PATCH 00/10] staging: lustre: assorted code improvements for list manipulations.

2017-10-29 Thread NeilBrown
There are mostly conversions of list_for_each() to
list_for_each_entry() and similar.  list_first_entry()
also makes a few appearances.

Thanks,
NeilBrown


---

NeilBrown (10):
  staging: lustre: use list_last_entry to simplify fld_cache_shrink
  staging: lustre: ldlm: use list_for_each_entry in ldlm_extent_shift_kms()
  staging: lustre: ldlm: use list_first_entry in ldlm_lock
  staging: lustre: ldlm: use list_for_each_entry in ldlm_lock.c
  staging: lustre: ldlm: use list_first_entry in ldlm_lockd.c
  staging: lustre: ldlm: minor list_entry improvements in ldlm_request.c
  staging: lustre: ldlm: use list_for_each_entry in ldlm_resource.c
  staging: lustre: lov: use list_for_each_entry in lov_obd.c
  staging: lustre: simplfy lov_finish_set()
  staging: lustre: obdclass: simplify cl_lock_fini()


 drivers/staging/lustre/lustre/fld/fld_cache.c  |   13 ++---
 drivers/staging/lustre/lustre/ldlm/ldlm_extent.c   |4 +---
 drivers/staging/lustre/lustre/ldlm/ldlm_lock.c |   18 +++---
 drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c|   10 +-
 drivers/staging/lustre/lustre/ldlm/ldlm_request.c  |   12 
 drivers/staging/lustre/lustre/ldlm/ldlm_resource.c |   20 +++-
 drivers/staging/lustre/lustre/lov/lov_obd.c|6 ++
 drivers/staging/lustre/lustre/lov/lov_request.c|   10 --
 drivers/staging/lustre/lustre/obdclass/cl_lock.c   |9 -
 9 files changed, 40 insertions(+), 62 deletions(-)

--
Signature



[PATCH 02/10] staging: lustre: ldlm: use list_for_each_entry in ldlm_extent_shift_kms()

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_extent.c |4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
index 2cc6dc2b281f..c9bf9ae40f7d 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
@@ -63,7 +63,6 @@
 __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms)
 {
struct ldlm_resource *res = lock->l_resource;
-   struct list_head *tmp;
struct ldlm_lock *lck;
__u64 kms = 0;
 
@@ -73,8 +72,7 @@ __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 
old_kms)
 */
ldlm_set_kms_ignore(lock);
 
-   list_for_each(tmp, >lr_granted) {
-   lck = list_entry(tmp, struct ldlm_lock, l_res_link);
+   list_for_each_entry(lck, >lr_granted, l_res_link) {
 
if (ldlm_is_kms_ignore(lck))
continue;




[PATCH 01/10] staging: lustre: use list_last_entry to simplify fld_cache_shrink

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/fld/fld_cache.c |   13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/lustre/lustre/fld/fld_cache.c 
b/drivers/staging/lustre/lustre/fld/fld_cache.c
index b723ece02eff..c01709cd22a1 100644
--- a/drivers/staging/lustre/lustre/fld/fld_cache.c
+++ b/drivers/staging/lustre/lustre/fld/fld_cache.c
@@ -212,19 +212,18 @@ static inline void fld_cache_entry_add(struct fld_cache 
*cache,
  */
 static int fld_cache_shrink(struct fld_cache *cache)
 {
-   struct fld_cache_entry *flde;
-   struct list_head *curr;
int num = 0;
 
if (cache->fci_cache_count < cache->fci_cache_size)
return 0;
 
-   curr = cache->fci_lru.prev;
-
while (cache->fci_cache_count + cache->fci_threshold >
-  cache->fci_cache_size && curr != >fci_lru) {
-   flde = list_entry(curr, struct fld_cache_entry, fce_lru);
-   curr = curr->prev;
+  cache->fci_cache_size &&
+  !list_empty(>fci_lru)) {
+   struct fld_cache_entry *flde =
+   list_last_entry(>fci_lru,
+   struct fld_cache_entry, fce_lru);
+
fld_cache_entry_delete(cache, flde);
num++;
}




[PATCH 00/10] staging: lustre: assorted code improvements for list manipulations.

2017-10-29 Thread NeilBrown
There are mostly conversions of list_for_each() to
list_for_each_entry() and similar.  list_first_entry()
also makes a few appearances.

Thanks,
NeilBrown


---

NeilBrown (10):
  staging: lustre: use list_last_entry to simplify fld_cache_shrink
  staging: lustre: ldlm: use list_for_each_entry in ldlm_extent_shift_kms()
  staging: lustre: ldlm: use list_first_entry in ldlm_lock
  staging: lustre: ldlm: use list_for_each_entry in ldlm_lock.c
  staging: lustre: ldlm: use list_first_entry in ldlm_lockd.c
  staging: lustre: ldlm: minor list_entry improvements in ldlm_request.c
  staging: lustre: ldlm: use list_for_each_entry in ldlm_resource.c
  staging: lustre: lov: use list_for_each_entry in lov_obd.c
  staging: lustre: simplfy lov_finish_set()
  staging: lustre: obdclass: simplify cl_lock_fini()


 drivers/staging/lustre/lustre/fld/fld_cache.c  |   13 ++---
 drivers/staging/lustre/lustre/ldlm/ldlm_extent.c   |4 +---
 drivers/staging/lustre/lustre/ldlm/ldlm_lock.c |   18 +++---
 drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c|   10 +-
 drivers/staging/lustre/lustre/ldlm/ldlm_request.c  |   12 
 drivers/staging/lustre/lustre/ldlm/ldlm_resource.c |   20 +++-
 drivers/staging/lustre/lustre/lov/lov_obd.c|6 ++
 drivers/staging/lustre/lustre/lov/lov_request.c|   10 --
 drivers/staging/lustre/lustre/obdclass/cl_lock.c   |9 -
 9 files changed, 40 insertions(+), 62 deletions(-)

--
Signature



[PATCH 02/10] staging: lustre: ldlm: use list_for_each_entry in ldlm_extent_shift_kms()

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/ldlm/ldlm_extent.c |4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c 
b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
index 2cc6dc2b281f..c9bf9ae40f7d 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
@@ -63,7 +63,6 @@
 __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms)
 {
struct ldlm_resource *res = lock->l_resource;
-   struct list_head *tmp;
struct ldlm_lock *lck;
__u64 kms = 0;
 
@@ -73,8 +72,7 @@ __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 
old_kms)
 */
ldlm_set_kms_ignore(lock);
 
-   list_for_each(tmp, >lr_granted) {
-   lck = list_entry(tmp, struct ldlm_lock, l_res_link);
+   list_for_each_entry(lck, >lr_granted, l_res_link) {
 
if (ldlm_is_kms_ignore(lck))
continue;




[PATCH 01/10] staging: lustre: use list_last_entry to simplify fld_cache_shrink

2017-10-29 Thread NeilBrown
Signed-off-by: NeilBrown 
---
 drivers/staging/lustre/lustre/fld/fld_cache.c |   13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/lustre/lustre/fld/fld_cache.c 
b/drivers/staging/lustre/lustre/fld/fld_cache.c
index b723ece02eff..c01709cd22a1 100644
--- a/drivers/staging/lustre/lustre/fld/fld_cache.c
+++ b/drivers/staging/lustre/lustre/fld/fld_cache.c
@@ -212,19 +212,18 @@ static inline void fld_cache_entry_add(struct fld_cache 
*cache,
  */
 static int fld_cache_shrink(struct fld_cache *cache)
 {
-   struct fld_cache_entry *flde;
-   struct list_head *curr;
int num = 0;
 
if (cache->fci_cache_count < cache->fci_cache_size)
return 0;
 
-   curr = cache->fci_lru.prev;
-
while (cache->fci_cache_count + cache->fci_threshold >
-  cache->fci_cache_size && curr != >fci_lru) {
-   flde = list_entry(curr, struct fld_cache_entry, fce_lru);
-   curr = curr->prev;
+  cache->fci_cache_size &&
+  !list_empty(>fci_lru)) {
+   struct fld_cache_entry *flde =
+   list_last_entry(>fci_lru,
+   struct fld_cache_entry, fce_lru);
+
fld_cache_entry_delete(cache, flde);
num++;
}




Re: [PATCH v2 2/3] mailbox: Add support for Hi3660 mailbox

2017-10-29 Thread Leo Yan
Hi Mark,

On Fri, Oct 27, 2017 at 11:46:00AM +0100, Mark Rutland wrote:
> On Fri, Oct 27, 2017 at 02:15:03PM +0800, Kaihua Zhong wrote:
> > Hi3660 mailbox controller is used to send message within multiple
> > processors, MCU, HIFI, etc.  It supports 32 mailbox channels and every
> > channel can only be used for single transferring direction.  Once the
> > channel is enabled, it needs to specify the destination interrupt and
> > acknowledge interrupt, these two interrupt vectors are used to create
> > the connection between the mailbox and interrupt controllers.
> > 
> > The application processor (or from point of view of kernel) is not the
> > only one master which can launch the data transferring, other
> > processors or MCU/DSP also can kick off the data transferring.  So this
> > driver implements a locking mechanism to support exclusive accessing.
> 
> ... and that locking mechanism is what precisely?
> 
> Where is the protocol defined?
> 
> > +static int hi3660_mbox_check_state(struct mbox_chan *chan)
> > +{
> > +   unsigned long ch = (unsigned long)chan->con_priv;
> > +   struct hi3660_mbox *mbox = to_hi3660_mbox(chan);
> > +   struct hi3660_mbox_dev *mdev = >mdev[ch];
> > +   void __iomem *base = MBOX_BASE(mbox, ch);
> > +   unsigned long val;
> > +   unsigned int state, ret;
> > +
> > +   /* Mailbox is idle so directly bail out */
> > +   state = readl_relaxed(base + MBOX_MODE_REG);
> > +   if (state & MBOX_STATE_IDLE)
> > +   return 0;
> > +
> > +   /* Wait for acknowledge from remote */
> > +   ret = readx_poll_timeout_atomic(readl_relaxed, base + MBOX_MODE_REG,
> > +   val, (val & MBOX_STATE_ACK), 1000, 30);
> > +   if (ret) {
> > +   dev_err(mbox->dev, "%s: timeout for receiving ack\n", __func__);
> > +   return ret;
> > +   }
> > +
> > +   /* Ensure channel is released */
> > +   writel_relaxed(0x, base + MBOX_IMASK_REG);
> > +   writel_relaxed(BIT(mdev->ack_irq), base + MBOX_SRC_REG);
> > +   __asm__ volatile ("sev");
> > +   return 0;
> > +}
> 
> Drivers really shouldn't be using SEV directly (even if via the sev() 
> macro)...
> 
> This SEV isn't ordered w.r.t. anything, and it's unclear what ordering you
> need, so this simply does not work.

I will leave your questions for Hisilicon colleagues, essentially
your questions are related with mailbox mechanism.

But I'd like to firstly get clear your question for "This SEV isn't
ordered w.r.t. anything". From my understanding, ARMv8 architecture
natually adds DMB before SEV so all previous register writing
opreations should be ensured to endpoint before SEV?

[...]

Thanks,
Leo Yan


Re: [PATCH v2 2/3] mailbox: Add support for Hi3660 mailbox

2017-10-29 Thread Leo Yan
Hi Mark,

On Fri, Oct 27, 2017 at 11:46:00AM +0100, Mark Rutland wrote:
> On Fri, Oct 27, 2017 at 02:15:03PM +0800, Kaihua Zhong wrote:
> > Hi3660 mailbox controller is used to send message within multiple
> > processors, MCU, HIFI, etc.  It supports 32 mailbox channels and every
> > channel can only be used for single transferring direction.  Once the
> > channel is enabled, it needs to specify the destination interrupt and
> > acknowledge interrupt, these two interrupt vectors are used to create
> > the connection between the mailbox and interrupt controllers.
> > 
> > The application processor (or from point of view of kernel) is not the
> > only one master which can launch the data transferring, other
> > processors or MCU/DSP also can kick off the data transferring.  So this
> > driver implements a locking mechanism to support exclusive accessing.
> 
> ... and that locking mechanism is what precisely?
> 
> Where is the protocol defined?
> 
> > +static int hi3660_mbox_check_state(struct mbox_chan *chan)
> > +{
> > +   unsigned long ch = (unsigned long)chan->con_priv;
> > +   struct hi3660_mbox *mbox = to_hi3660_mbox(chan);
> > +   struct hi3660_mbox_dev *mdev = >mdev[ch];
> > +   void __iomem *base = MBOX_BASE(mbox, ch);
> > +   unsigned long val;
> > +   unsigned int state, ret;
> > +
> > +   /* Mailbox is idle so directly bail out */
> > +   state = readl_relaxed(base + MBOX_MODE_REG);
> > +   if (state & MBOX_STATE_IDLE)
> > +   return 0;
> > +
> > +   /* Wait for acknowledge from remote */
> > +   ret = readx_poll_timeout_atomic(readl_relaxed, base + MBOX_MODE_REG,
> > +   val, (val & MBOX_STATE_ACK), 1000, 30);
> > +   if (ret) {
> > +   dev_err(mbox->dev, "%s: timeout for receiving ack\n", __func__);
> > +   return ret;
> > +   }
> > +
> > +   /* Ensure channel is released */
> > +   writel_relaxed(0x, base + MBOX_IMASK_REG);
> > +   writel_relaxed(BIT(mdev->ack_irq), base + MBOX_SRC_REG);
> > +   __asm__ volatile ("sev");
> > +   return 0;
> > +}
> 
> Drivers really shouldn't be using SEV directly (even if via the sev() 
> macro)...
> 
> This SEV isn't ordered w.r.t. anything, and it's unclear what ordering you
> need, so this simply does not work.

I will leave your questions for Hisilicon colleagues, essentially
your questions are related with mailbox mechanism.

But I'd like to firstly get clear your question for "This SEV isn't
ordered w.r.t. anything". From my understanding, ARMv8 architecture
natually adds DMB before SEV so all previous register writing
opreations should be ensured to endpoint before SEV?

[...]

Thanks,
Leo Yan


Re: [PATCH] kernel/kprobes: add check to avoid memory leaks

2017-10-29 Thread Masami Hiramatsu
On Mon, 30 Oct 2017 09:10:57 +0800
Bixuan Cui  wrote:

> On 2017/10/25 20:29, Bixuan Cui wrote:
> And test again with this patch:
> 
> insmod testRegKretprobes_004.ko
> [  163.853281] register_kretprobe failed, returned -22
> insmod: can't insert 'testRegKretprobes_004.ko': Operation not permitted
> 
> Thanks,
> Bixuan Cui
> > The register_kretprobe(struct kretprobe *rp) creates and initializes
> > a hash list for rp->free_instances when register kretprobe every time.
> > Then malloc memory for it.
> > 
> > The test case:
> > static struct kretprobe rp;
> > struct  kretprobe *rps[2]={, };
> > static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
> > {
> > printk(KERN_DEBUG "ret_handler\n");
> > return 0;
> > }
> > static int entry_handler(struct kretprobe_instance *ri, struct pt_regs 
> > *regs)
> > {
> > printk(KERN_DEBUG "entry_handler\n");
> > return 0;
> > }
> > static int __init kretprobe_init(void)
> > {
> > int ret;
> > rp.kp.addr = (kprobe_opcode_t *)kallsyms_lookup_name("do_fork");
> > rp.handler=ret_handler;
> > rp.entry_handler=entry_handler;
> > rp.maxactive = 3;
> > 
> > ret = register_kretprobes(rps,2);
> > 
> > Result:
> > unreferenced object 0x8010b12ad980 (size 64):
> > comm "insmod", pid 17352, jiffies 4298977824 (age 63065.756s)
> > hex dump (first 32 bytes):
> > 00 00 00 00 00 00 00 00 d8 84 12 fc ff 7f ff ff 
> > 74 65 73 74 52 65 67 4b 72 65 74 70 72 6f 62 65 testRegKretprobe
> > backtrace:
> > [] create_object+0x1e0/0x3f0
> > [] kmemleak_alloc+0x6c/0xf0
> > [] __kmalloc+0x23c/0x2e0
> > [] register_kretprobe+0x12c/0x350
> > 
> > When call register_kretprobes(struct kretprobe **rps, int num) with the
> > same rps(num>=2).
> > The first time,call INIT_HLIST_HEAD() and kmalloc() to malloc memory for the
> > hash list,then save into rp->free_instances.
> > The second time,call INIT_HLIST_HEAD() and kmalloc() then create a new
> > hash list into rp->free_instances and lost the first rp->free_instances.
> > So add check to avoid it.
> > 

I don't like this kind of check, since this is obviously caller's bug.
Why doesn't each caller check this?

Thank you,

> > Reported-and-tested-by: kangwen 
> > Signed-off-by: Bixuan Cui 
> > ---
> >  kernel/kprobes.c | 8 +++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > index 6301dae..f19f191 100644
> > --- a/kernel/kprobes.c
> > +++ b/kernel/kprobes.c
> > @@ -1890,10 +1890,16 @@ EXPORT_SYMBOL_GPL(register_kretprobe);
> > 
> >  int register_kretprobes(struct kretprobe **rps, int num)
> >  {
> > -   int ret = 0, i;
> > +   int ret = 0, i, j;
> > 
> > if (num <= 0)
> > return -EINVAL;
> > +
> > +   for (i = 0; i < num-1; i++)
> > +   for (j = i+1; j < num; j++)
> > +   if (rps[i] == rps[j])
> > +   return -EINVAL;
> > +
> > for (i = 0; i < num; i++) {
> > ret = register_kretprobe(rps[i]);
> > if (ret < 0) {
> > --
> > 2.6.2
> > 
> > 
> > 
> > 
> > .
> > 
> 
> 


-- 
Masami Hiramatsu 


Re: [PATCH] kernel/kprobes: add check to avoid memory leaks

2017-10-29 Thread Masami Hiramatsu
On Mon, 30 Oct 2017 09:10:57 +0800
Bixuan Cui  wrote:

> On 2017/10/25 20:29, Bixuan Cui wrote:
> And test again with this patch:
> 
> insmod testRegKretprobes_004.ko
> [  163.853281] register_kretprobe failed, returned -22
> insmod: can't insert 'testRegKretprobes_004.ko': Operation not permitted
> 
> Thanks,
> Bixuan Cui
> > The register_kretprobe(struct kretprobe *rp) creates and initializes
> > a hash list for rp->free_instances when register kretprobe every time.
> > Then malloc memory for it.
> > 
> > The test case:
> > static struct kretprobe rp;
> > struct  kretprobe *rps[2]={, };
> > static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
> > {
> > printk(KERN_DEBUG "ret_handler\n");
> > return 0;
> > }
> > static int entry_handler(struct kretprobe_instance *ri, struct pt_regs 
> > *regs)
> > {
> > printk(KERN_DEBUG "entry_handler\n");
> > return 0;
> > }
> > static int __init kretprobe_init(void)
> > {
> > int ret;
> > rp.kp.addr = (kprobe_opcode_t *)kallsyms_lookup_name("do_fork");
> > rp.handler=ret_handler;
> > rp.entry_handler=entry_handler;
> > rp.maxactive = 3;
> > 
> > ret = register_kretprobes(rps,2);
> > 
> > Result:
> > unreferenced object 0x8010b12ad980 (size 64):
> > comm "insmod", pid 17352, jiffies 4298977824 (age 63065.756s)
> > hex dump (first 32 bytes):
> > 00 00 00 00 00 00 00 00 d8 84 12 fc ff 7f ff ff 
> > 74 65 73 74 52 65 67 4b 72 65 74 70 72 6f 62 65 testRegKretprobe
> > backtrace:
> > [] create_object+0x1e0/0x3f0
> > [] kmemleak_alloc+0x6c/0xf0
> > [] __kmalloc+0x23c/0x2e0
> > [] register_kretprobe+0x12c/0x350
> > 
> > When call register_kretprobes(struct kretprobe **rps, int num) with the
> > same rps(num>=2).
> > The first time,call INIT_HLIST_HEAD() and kmalloc() to malloc memory for the
> > hash list,then save into rp->free_instances.
> > The second time,call INIT_HLIST_HEAD() and kmalloc() then create a new
> > hash list into rp->free_instances and lost the first rp->free_instances.
> > So add check to avoid it.
> > 

I don't like this kind of check, since this is obviously caller's bug.
Why doesn't each caller check this?

Thank you,

> > Reported-and-tested-by: kangwen 
> > Signed-off-by: Bixuan Cui 
> > ---
> >  kernel/kprobes.c | 8 +++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > index 6301dae..f19f191 100644
> > --- a/kernel/kprobes.c
> > +++ b/kernel/kprobes.c
> > @@ -1890,10 +1890,16 @@ EXPORT_SYMBOL_GPL(register_kretprobe);
> > 
> >  int register_kretprobes(struct kretprobe **rps, int num)
> >  {
> > -   int ret = 0, i;
> > +   int ret = 0, i, j;
> > 
> > if (num <= 0)
> > return -EINVAL;
> > +
> > +   for (i = 0; i < num-1; i++)
> > +   for (j = i+1; j < num; j++)
> > +   if (rps[i] == rps[j])
> > +   return -EINVAL;
> > +
> > for (i = 0; i < num; i++) {
> > ret = register_kretprobe(rps[i]);
> > if (ret < 0) {
> > --
> > 2.6.2
> > 
> > 
> > 
> > 
> > .
> > 
> 
> 


-- 
Masami Hiramatsu 


Re: [PATCH 2/3] drivers: phy: broadcom: Add driver for Cygnus USB phy controller

2017-10-29 Thread Raveendra Padasalagi
Hi Kishon,

On Fri, Oct 27, 2017 at 2:05 PM, Kishon Vijay Abraham I  wrote:
> +Chanwoo, for reviewing extcon
>
> Hi.
>
> On Tuesday 24 October 2017 10:07 AM, Raveendra Padasalagi wrote:
>> Add driver for Broadcom's USB phy controller's used in Cygnus
>> familyof SoC. Cygnus has three USB phy controller's, port 0,
>> port 1 provides USB host functionality and port 2 can be configured
>> for host/device role.
>>
>> Configuration of host/device role for port 2 is achieved based on
>> the extcon events, the driver registers to extcon framework to get
>> appropriate connect events for Host/Device cables connect/disconnect
>> states based on VBUS and ID interrupts.
>>
>> Signed-off-by: Raveendra Padasalagi 
>> ---
>>  drivers/phy/broadcom/Kconfig  |  14 +
>>  drivers/phy/broadcom/Makefile |   1 +
>>  drivers/phy/broadcom/phy-bcm-cygnus-usb.c | 672 
>> ++
>>  3 files changed, 687 insertions(+)
>>  create mode 100644 drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>>
>> diff --git a/drivers/phy/broadcom/Kconfig b/drivers/phy/broadcom/Kconfig
>> index 64fc59c..3179daf 100644
>> --- a/drivers/phy/broadcom/Kconfig
>> +++ b/drivers/phy/broadcom/Kconfig
>> @@ -1,6 +1,20 @@
>>  #
>>  # Phy drivers for Broadcom platforms
>>  #
>> +config PHY_BCM_CYGNUS_USB
>> + tristate "Broadcom Cygnus USB PHY support"
>> + depends on OF
>> + depends on ARCH_BCM_CYGNUS || COMPILE_TEST
>> + select GENERIC_PHY
>> + select EXTCON_USB_GPIO
>
> Didn't this throw up a warning for selecting config without caring for the
> dependency?

No, it didn't throw any warning. Let me remove select and place it as
dependency.

>> + default ARCH_BCM_CYGNUS
>> + help
>> +   Enable this to support three USB PHY's present in Broadcom's
>> +   Cygnus chip.
>> +
>> +   The phys are capable of supporting host mode on all ports and
>> +   device mode for port 2.
>> +
>>  config PHY_CYGNUS_PCIE
>>   tristate "Broadcom Cygnus PCIe PHY driver"
>>   depends on OF && (ARCH_BCM_CYGNUS || COMPILE_TEST)
>> diff --git a/drivers/phy/broadcom/Makefile b/drivers/phy/broadcom/Makefile
>> index 4eb82ec..3dec23c 100644
>> --- a/drivers/phy/broadcom/Makefile
>> +++ b/drivers/phy/broadcom/Makefile
>> @@ -1,4 +1,5 @@
>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)+= phy-bcm-cygnus-pcie.o
>> +obj-$(CONFIG_PHY_BCM_CYGNUS_USB) += phy-bcm-cygnus-usb.o
>>  obj-$(CONFIG_BCM_KONA_USB2_PHY)  += phy-bcm-kona-usb2.o
>>  obj-$(CONFIG_PHY_BCM_NS_USB2)+= phy-bcm-ns-usb2.o
>>  obj-$(CONFIG_PHY_BCM_NS_USB3)+= phy-bcm-ns-usb3.o
>> diff --git a/drivers/phy/broadcom/phy-bcm-cygnus-usb.c 
>> b/drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>> new file mode 100644
>> index 000..ef2a94c
>> --- /dev/null
>> +++ b/drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>> @@ -0,0 +1,672 @@
>> +/*
>> + * Copyright 2017 Broadcom
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License, version 2, as
>> + * published by the Free Software Foundation (the "GPL").
>> + *
>> + * This program is distributed in the hope that it will be useful, but
>> + * WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * General Public License version 2 (GPLv2) for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * version 2 (GPLv2) along with this source code.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define CDRU_USBPHY_CLK_RST_SEL_OFFSET   0x0
>> +#define CDRU_USBPHY2_HOST_DEV_SEL_OFFSET 0x4
>> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET  0x5C
>> +#define CDRU_USBPHY_P0_STATUS_OFFSET 0x1C
>> +#define CDRU_USBPHY_P1_STATUS_OFFSET 0x34
>> +#define CDRU_USBPHY_P2_STATUS_OFFSET 0x4C
>
> Looks like it has 2 different blocks; CDRU and CMRU. Having a comment for each
> of the block will help.

Ok, I will fix it in the next version of the patch.

>> +#define CRMU_USB_PHY_AON_CTRL_OFFSET 0x0
>> +
>> +#define CDRU_USBPHY_USBPHY_ILDO_ON_FLAG  BIT(1)
>> +#define CDRU_USBPHY_USBPHY_PLL_LOCK  BIT(0)
>> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_DISABLE BIT(0)
>> +
>> +#define PHY2_DEV_HOST_CTRL_SEL_DEVICE0
>> +#define PHY2_DEV_HOST_CTRL_SEL_HOST  1
>> +#define PHY2_DEV_HOST_CTRL_SEL_IDLE  2
>> +#define CRMU_USBPHY_P0_AFE_CORERDY_VDDC  BIT(1)
>> +#define CRMU_USBPHY_P0_RESETBBIT(2)
>> +#define CRMU_USBPHY_P1_AFE_CORERDY_VDDC

Re: [PATCH 2/3] drivers: phy: broadcom: Add driver for Cygnus USB phy controller

2017-10-29 Thread Raveendra Padasalagi
Hi Kishon,

On Fri, Oct 27, 2017 at 2:05 PM, Kishon Vijay Abraham I  wrote:
> +Chanwoo, for reviewing extcon
>
> Hi.
>
> On Tuesday 24 October 2017 10:07 AM, Raveendra Padasalagi wrote:
>> Add driver for Broadcom's USB phy controller's used in Cygnus
>> familyof SoC. Cygnus has three USB phy controller's, port 0,
>> port 1 provides USB host functionality and port 2 can be configured
>> for host/device role.
>>
>> Configuration of host/device role for port 2 is achieved based on
>> the extcon events, the driver registers to extcon framework to get
>> appropriate connect events for Host/Device cables connect/disconnect
>> states based on VBUS and ID interrupts.
>>
>> Signed-off-by: Raveendra Padasalagi 
>> ---
>>  drivers/phy/broadcom/Kconfig  |  14 +
>>  drivers/phy/broadcom/Makefile |   1 +
>>  drivers/phy/broadcom/phy-bcm-cygnus-usb.c | 672 
>> ++
>>  3 files changed, 687 insertions(+)
>>  create mode 100644 drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>>
>> diff --git a/drivers/phy/broadcom/Kconfig b/drivers/phy/broadcom/Kconfig
>> index 64fc59c..3179daf 100644
>> --- a/drivers/phy/broadcom/Kconfig
>> +++ b/drivers/phy/broadcom/Kconfig
>> @@ -1,6 +1,20 @@
>>  #
>>  # Phy drivers for Broadcom platforms
>>  #
>> +config PHY_BCM_CYGNUS_USB
>> + tristate "Broadcom Cygnus USB PHY support"
>> + depends on OF
>> + depends on ARCH_BCM_CYGNUS || COMPILE_TEST
>> + select GENERIC_PHY
>> + select EXTCON_USB_GPIO
>
> Didn't this throw up a warning for selecting config without caring for the
> dependency?

No, it didn't throw any warning. Let me remove select and place it as
dependency.

>> + default ARCH_BCM_CYGNUS
>> + help
>> +   Enable this to support three USB PHY's present in Broadcom's
>> +   Cygnus chip.
>> +
>> +   The phys are capable of supporting host mode on all ports and
>> +   device mode for port 2.
>> +
>>  config PHY_CYGNUS_PCIE
>>   tristate "Broadcom Cygnus PCIe PHY driver"
>>   depends on OF && (ARCH_BCM_CYGNUS || COMPILE_TEST)
>> diff --git a/drivers/phy/broadcom/Makefile b/drivers/phy/broadcom/Makefile
>> index 4eb82ec..3dec23c 100644
>> --- a/drivers/phy/broadcom/Makefile
>> +++ b/drivers/phy/broadcom/Makefile
>> @@ -1,4 +1,5 @@
>>  obj-$(CONFIG_PHY_CYGNUS_PCIE)+= phy-bcm-cygnus-pcie.o
>> +obj-$(CONFIG_PHY_BCM_CYGNUS_USB) += phy-bcm-cygnus-usb.o
>>  obj-$(CONFIG_BCM_KONA_USB2_PHY)  += phy-bcm-kona-usb2.o
>>  obj-$(CONFIG_PHY_BCM_NS_USB2)+= phy-bcm-ns-usb2.o
>>  obj-$(CONFIG_PHY_BCM_NS_USB3)+= phy-bcm-ns-usb3.o
>> diff --git a/drivers/phy/broadcom/phy-bcm-cygnus-usb.c 
>> b/drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>> new file mode 100644
>> index 000..ef2a94c
>> --- /dev/null
>> +++ b/drivers/phy/broadcom/phy-bcm-cygnus-usb.c
>> @@ -0,0 +1,672 @@
>> +/*
>> + * Copyright 2017 Broadcom
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License, version 2, as
>> + * published by the Free Software Foundation (the "GPL").
>> + *
>> + * This program is distributed in the hope that it will be useful, but
>> + * WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * General Public License version 2 (GPLv2) for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * version 2 (GPLv2) along with this source code.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define CDRU_USBPHY_CLK_RST_SEL_OFFSET   0x0
>> +#define CDRU_USBPHY2_HOST_DEV_SEL_OFFSET 0x4
>> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET  0x5C
>> +#define CDRU_USBPHY_P0_STATUS_OFFSET 0x1C
>> +#define CDRU_USBPHY_P1_STATUS_OFFSET 0x34
>> +#define CDRU_USBPHY_P2_STATUS_OFFSET 0x4C
>
> Looks like it has 2 different blocks; CDRU and CMRU. Having a comment for each
> of the block will help.

Ok, I will fix it in the next version of the patch.

>> +#define CRMU_USB_PHY_AON_CTRL_OFFSET 0x0
>> +
>> +#define CDRU_USBPHY_USBPHY_ILDO_ON_FLAG  BIT(1)
>> +#define CDRU_USBPHY_USBPHY_PLL_LOCK  BIT(0)
>> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_DISABLE BIT(0)
>> +
>> +#define PHY2_DEV_HOST_CTRL_SEL_DEVICE0
>> +#define PHY2_DEV_HOST_CTRL_SEL_HOST  1
>> +#define PHY2_DEV_HOST_CTRL_SEL_IDLE  2
>> +#define CRMU_USBPHY_P0_AFE_CORERDY_VDDC  BIT(1)
>> +#define CRMU_USBPHY_P0_RESETBBIT(2)
>> +#define CRMU_USBPHY_P1_AFE_CORERDY_VDDC  BIT(9)
>> +#define CRMU_USBPHY_P1_RESETB

[PATCH] Fix writing mtdoops to nand flash.

2017-10-29 Thread motobud
From: Brent Taylor 

When mtdoops calls mtd_panic_write, it eventually calls
panic_nand_write in nand_base.c.  In order to properly
wait for the nand chip to be ready in panic_nand_wait,
the chip must first be selected.

When using the atmel nand flash controller, a panic
would occur due to a NULL pointer exception.

Signed-off-by: Brent Taylor 
---
 drivers/mtd/nand/nand_base.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 12edaae17d81..0a8058a66d93 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2802,9 +2802,14 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t 
to, size_t len,
struct mtd_oob_ops ops;
int ret;
 
+   int chipnr = (int)(to >> chip->chip_shift);
+   chip->select_chip(mtd, chipnr);
+
/* Wait for the device to get ready */
panic_nand_wait(mtd, chip, 400);
 
+   chip->select_chip(mtd, -1);
+
/* Grab the device */
panic_nand_get_device(chip, mtd, FL_WRITING);
 
-- 
2.14.2



[PATCH] Fix writing mtdoops to nand flash.

2017-10-29 Thread motobud
From: Brent Taylor 

When mtdoops calls mtd_panic_write, it eventually calls
panic_nand_write in nand_base.c.  In order to properly
wait for the nand chip to be ready in panic_nand_wait,
the chip must first be selected.

When using the atmel nand flash controller, a panic
would occur due to a NULL pointer exception.

Signed-off-by: Brent Taylor 
---
 drivers/mtd/nand/nand_base.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 12edaae17d81..0a8058a66d93 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2802,9 +2802,14 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t 
to, size_t len,
struct mtd_oob_ops ops;
int ret;
 
+   int chipnr = (int)(to >> chip->chip_shift);
+   chip->select_chip(mtd, chipnr);
+
/* Wait for the device to get ready */
panic_nand_wait(mtd, chip, 400);
 
+   chip->select_chip(mtd, -1);
+
/* Grab the device */
panic_nand_get_device(chip, mtd, FL_WRITING);
 
-- 
2.14.2



Re: [PATCH v4 05/13] irqchip: add initial support for ompic

2017-10-29 Thread Stafford Horne
On Mon, Oct 30, 2017 at 02:29:18AM +, Marc Zyngier wrote:
> On Mon, Oct 30 2017 at  8:11:15 am GMT, Stafford Horne  
> wrote:
> > From: Stefan Kristiansson 
> >
> > IPI driver for the Open Multi-Processor Interrupt Controller (ompic) as
> > described in the Multi-core support section of the OpenRISC 1.2
> > architecture specification:
> >
> >   https://github.com/openrisc/doc/raw/master/openrisc-arch-1.2-rev0.pdf
> >
> > Each OpenRISC core contains a full interrupt controller which is used in
> > the SMP architecture for interrupt balancing.  This IPI device, the
> > ompic, is the only external device required for enabling SMP on
> > OpenRISC.
> >
> > Pending ops are stored in a memory bit mask which can allow multiple
> > pending operations to be set and serviced at a time. This is mostly
> > borrowed from the alpha IPI implementation.
> >
> > Cc: Marc Zyngier 
> > Acked-by: Rob Herring 
> > Signed-off-by: Stefan Kristiansson 
> > [sho...@gmail.com: converted ops to bitmask, wrote commit message]
> > Signed-off-by: Stafford Horne 
> 
> Reviewed-by: Marc Zyngier 

Thanks

> Side question: what is your merge strategy for this? I can take it
> through the irqchip tree as it is standalone, but I'm open to other
> suggestions.

For me its easier if I just take it through the openrisc tree, as
there are dependencies between this series and the irqchip driver.
If you are ok with that I can make a note to Linus indicating so in
the pull request.

My plan is to send this series during the 4.15 merge window.

-Stafford


Re: [PATCH v4 05/13] irqchip: add initial support for ompic

2017-10-29 Thread Stafford Horne
On Mon, Oct 30, 2017 at 02:29:18AM +, Marc Zyngier wrote:
> On Mon, Oct 30 2017 at  8:11:15 am GMT, Stafford Horne  
> wrote:
> > From: Stefan Kristiansson 
> >
> > IPI driver for the Open Multi-Processor Interrupt Controller (ompic) as
> > described in the Multi-core support section of the OpenRISC 1.2
> > architecture specification:
> >
> >   https://github.com/openrisc/doc/raw/master/openrisc-arch-1.2-rev0.pdf
> >
> > Each OpenRISC core contains a full interrupt controller which is used in
> > the SMP architecture for interrupt balancing.  This IPI device, the
> > ompic, is the only external device required for enabling SMP on
> > OpenRISC.
> >
> > Pending ops are stored in a memory bit mask which can allow multiple
> > pending operations to be set and serviced at a time. This is mostly
> > borrowed from the alpha IPI implementation.
> >
> > Cc: Marc Zyngier 
> > Acked-by: Rob Herring 
> > Signed-off-by: Stefan Kristiansson 
> > [sho...@gmail.com: converted ops to bitmask, wrote commit message]
> > Signed-off-by: Stafford Horne 
> 
> Reviewed-by: Marc Zyngier 

Thanks

> Side question: what is your merge strategy for this? I can take it
> through the irqchip tree as it is standalone, but I'm open to other
> suggestions.

For me its easier if I just take it through the openrisc tree, as
there are dependencies between this series and the irqchip driver.
If you are ok with that I can make a note to Linus indicating so in
the pull request.

My plan is to send this series during the 4.15 merge window.

-Stafford


[PATCH] st-hva: hva-h264: use swap macro in hva_h264_encode

2017-10-29 Thread Gustavo A. R. Silva
Make use of the swap macro and remove unnecessary variable tmp_frame.
This makes the code easier to read and maintain.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva 
---
 drivers/media/platform/sti/hva/hva-h264.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/platform/sti/hva/hva-h264.c 
b/drivers/media/platform/sti/hva/hva-h264.c
index e6f247a..a7e5eed 100644
--- a/drivers/media/platform/sti/hva/hva-h264.c
+++ b/drivers/media/platform/sti/hva/hva-h264.c
@@ -999,7 +999,6 @@ static int hva_h264_encode(struct hva_ctx *pctx, struct 
hva_frame *frame,
 {
struct hva_h264_ctx *ctx = (struct hva_h264_ctx *)pctx->priv;
struct hva_h264_task *task = (struct hva_h264_task *)ctx->task->vaddr;
-   struct hva_buffer *tmp_frame;
u32 stuffing_bytes = 0;
int ret = 0;
 
@@ -1023,9 +1022,7 @@ static int hva_h264_encode(struct hva_ctx *pctx, struct 
hva_frame *frame,
   >bytesused);
 
/* switch reference & reconstructed frame */
-   tmp_frame = ctx->ref_frame;
-   ctx->ref_frame = ctx->rec_frame;
-   ctx->rec_frame = tmp_frame;
+   swap(ctx->ref_frame, ctx->rec_frame);
 
return 0;
 err:
-- 
2.7.4



[PATCH] st-hva: hva-h264: use swap macro in hva_h264_encode

2017-10-29 Thread Gustavo A. R. Silva
Make use of the swap macro and remove unnecessary variable tmp_frame.
This makes the code easier to read and maintain.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva 
---
 drivers/media/platform/sti/hva/hva-h264.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/platform/sti/hva/hva-h264.c 
b/drivers/media/platform/sti/hva/hva-h264.c
index e6f247a..a7e5eed 100644
--- a/drivers/media/platform/sti/hva/hva-h264.c
+++ b/drivers/media/platform/sti/hva/hva-h264.c
@@ -999,7 +999,6 @@ static int hva_h264_encode(struct hva_ctx *pctx, struct 
hva_frame *frame,
 {
struct hva_h264_ctx *ctx = (struct hva_h264_ctx *)pctx->priv;
struct hva_h264_task *task = (struct hva_h264_task *)ctx->task->vaddr;
-   struct hva_buffer *tmp_frame;
u32 stuffing_bytes = 0;
int ret = 0;
 
@@ -1023,9 +1022,7 @@ static int hva_h264_encode(struct hva_ctx *pctx, struct 
hva_frame *frame,
   >bytesused);
 
/* switch reference & reconstructed frame */
-   tmp_frame = ctx->ref_frame;
-   ctx->ref_frame = ctx->rec_frame;
-   ctx->rec_frame = tmp_frame;
+   swap(ctx->ref_frame, ctx->rec_frame);
 
return 0;
 err:
-- 
2.7.4



Re: [PATCH] Coccinelle: use false positive annotation

2017-10-29 Thread Julia Lawall


On Mon, 30 Oct 2017, Masahiro Yamada wrote:

> Hi Julia,
>
>
> 2017-10-29 8:43 GMT+09:00 Julia Lawall :
> > /// is to describe the semantic patch, while //# indicates reasons
> > for false positives.
> >
> > Signed-off-by: Julia Lawall 
> >
> > ---
> >  scripts/coccinelle/misc/ifcol.cocci |6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/scripts/coccinelle/misc/ifcol.cocci 
> > b/scripts/coccinelle/misc/ifcol.cocci
> > index d0d00ef..30b248b 100644
> > --- a/scripts/coccinelle/misc/ifcol.cocci
> > +++ b/scripts/coccinelle/misc/ifcol.cocci
> > @@ -3,9 +3,9 @@
> >  /// Sometimes, code after an if that is indented is actually intended to be
> >  /// part of the if branch.
> >  ///
> > -/// This has a high rate of false positives, because Coccinelle's column
> > -/// calculation does not distinguish between spaces and tabs, so code that
> > -/// is not visually aligned may be considered to be in the same column.
> > +//# This has a high rate of false positives, because Coccinelle's column
> > +//# calculation does not distinguish between spaces and tabs, so code that
> > +//# is not visually aligned may be considered to be in the same column.
> >  ///
>
> Just a nit.
>
> The last /// should be turned into //
> if you want to avoid two blank lines in a series
> after the semantic patch information.
>
> (I can fix it locally if you agree with it and I am supposed to pick up this.)

Thanks for detecting the problem.  It would be great if you could pick it
up, since I haven't heard confirmation from Michal that he will start this
again.  The change seems fine.  Thanks for your help.

julia

>
>
>
> >  // Confidence: Low
> >  // Copyright: (C) 2010 Nicolas Palix, DIKU.  GPLv2.
> >
>
>
>
> --
> Best Regards
> Masahiro Yamada
>


Re: [PATCH] Coccinelle: use false positive annotation

2017-10-29 Thread Julia Lawall


On Mon, 30 Oct 2017, Masahiro Yamada wrote:

> Hi Julia,
>
>
> 2017-10-29 8:43 GMT+09:00 Julia Lawall :
> > /// is to describe the semantic patch, while //# indicates reasons
> > for false positives.
> >
> > Signed-off-by: Julia Lawall 
> >
> > ---
> >  scripts/coccinelle/misc/ifcol.cocci |6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/scripts/coccinelle/misc/ifcol.cocci 
> > b/scripts/coccinelle/misc/ifcol.cocci
> > index d0d00ef..30b248b 100644
> > --- a/scripts/coccinelle/misc/ifcol.cocci
> > +++ b/scripts/coccinelle/misc/ifcol.cocci
> > @@ -3,9 +3,9 @@
> >  /// Sometimes, code after an if that is indented is actually intended to be
> >  /// part of the if branch.
> >  ///
> > -/// This has a high rate of false positives, because Coccinelle's column
> > -/// calculation does not distinguish between spaces and tabs, so code that
> > -/// is not visually aligned may be considered to be in the same column.
> > +//# This has a high rate of false positives, because Coccinelle's column
> > +//# calculation does not distinguish between spaces and tabs, so code that
> > +//# is not visually aligned may be considered to be in the same column.
> >  ///
>
> Just a nit.
>
> The last /// should be turned into //
> if you want to avoid two blank lines in a series
> after the semantic patch information.
>
> (I can fix it locally if you agree with it and I am supposed to pick up this.)

Thanks for detecting the problem.  It would be great if you could pick it
up, since I haven't heard confirmation from Michal that he will start this
again.  The change seems fine.  Thanks for your help.

julia

>
>
>
> >  // Confidence: Low
> >  // Copyright: (C) 2010 Nicolas Palix, DIKU.  GPLv2.
> >
>
>
>
> --
> Best Regards
> Masahiro Yamada
>


Re: [PATCH] Coccinelle: use false positive annotation

2017-10-29 Thread Masahiro Yamada
Hi Julia,


2017-10-29 8:43 GMT+09:00 Julia Lawall :
> /// is to describe the semantic patch, while //# indicates reasons
> for false positives.
>
> Signed-off-by: Julia Lawall 
>
> ---
>  scripts/coccinelle/misc/ifcol.cocci |6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/coccinelle/misc/ifcol.cocci 
> b/scripts/coccinelle/misc/ifcol.cocci
> index d0d00ef..30b248b 100644
> --- a/scripts/coccinelle/misc/ifcol.cocci
> +++ b/scripts/coccinelle/misc/ifcol.cocci
> @@ -3,9 +3,9 @@
>  /// Sometimes, code after an if that is indented is actually intended to be
>  /// part of the if branch.
>  ///
> -/// This has a high rate of false positives, because Coccinelle's column
> -/// calculation does not distinguish between spaces and tabs, so code that
> -/// is not visually aligned may be considered to be in the same column.
> +//# This has a high rate of false positives, because Coccinelle's column
> +//# calculation does not distinguish between spaces and tabs, so code that
> +//# is not visually aligned may be considered to be in the same column.
>  ///

Just a nit.

The last /// should be turned into //
if you want to avoid two blank lines in a series
after the semantic patch information.

(I can fix it locally if you agree with it and I am supposed to pick up this.)



>  // Confidence: Low
>  // Copyright: (C) 2010 Nicolas Palix, DIKU.  GPLv2.
>



-- 
Best Regards
Masahiro Yamada


Re: [PATCH] Coccinelle: use false positive annotation

2017-10-29 Thread Masahiro Yamada
Hi Julia,


2017-10-29 8:43 GMT+09:00 Julia Lawall :
> /// is to describe the semantic patch, while //# indicates reasons
> for false positives.
>
> Signed-off-by: Julia Lawall 
>
> ---
>  scripts/coccinelle/misc/ifcol.cocci |6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/coccinelle/misc/ifcol.cocci 
> b/scripts/coccinelle/misc/ifcol.cocci
> index d0d00ef..30b248b 100644
> --- a/scripts/coccinelle/misc/ifcol.cocci
> +++ b/scripts/coccinelle/misc/ifcol.cocci
> @@ -3,9 +3,9 @@
>  /// Sometimes, code after an if that is indented is actually intended to be
>  /// part of the if branch.
>  ///
> -/// This has a high rate of false positives, because Coccinelle's column
> -/// calculation does not distinguish between spaces and tabs, so code that
> -/// is not visually aligned may be considered to be in the same column.
> +//# This has a high rate of false positives, because Coccinelle's column
> +//# calculation does not distinguish between spaces and tabs, so code that
> +//# is not visually aligned may be considered to be in the same column.
>  ///

Just a nit.

The last /// should be turned into //
if you want to avoid two blank lines in a series
after the semantic patch information.

(I can fix it locally if you agree with it and I am supposed to pick up this.)



>  // Confidence: Low
>  // Copyright: (C) 2010 Nicolas Palix, DIKU.  GPLv2.
>



-- 
Best Regards
Masahiro Yamada


[PATCH v3] i2c: aspeed: Deassert reset in probe

2017-10-29 Thread Joel Stanley
In order to use i2c from a cold boot, the i2c peripheral must be taken
out of reset. We request a shared reset controller each time a bus
driver is loaded, as the reset is shared between the 14 i2c buses.

On remove the reset is asserted, which only touches the hardware once
the last i2c bus is removed.

The request is optional, so if a device tree does not specify a reset
controller (or the driver is not built in), the driver continues to
probe.

Reviewed-by: Brendan Higgins 
Reviewed-by: Philipp Zabel 
Signed-off-by: Joel Stanley 
---
v3: Check for bad reset controller probe (caused by eg. bad device tree)
and set ->rst to NULL so assert/desassert does not cause a warning to
be printed
v2: Sort the headers
---
 drivers/i2c/busses/i2c-aspeed.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index 284f8670dbeb..5dec00d663eb 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -12,6 +12,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -27,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /* I2C Register */
@@ -132,6 +134,7 @@ struct aspeed_i2c_bus {
struct i2c_adapter  adap;
struct device   *dev;
void __iomem*base;
+   struct reset_control*rst;
/* Synchronizes I/O mem access to base. */
spinlock_t  lock;
struct completion   cmd_complete;
@@ -847,6 +850,13 @@ static int aspeed_i2c_probe_bus(struct platform_device 
*pdev)
/* We just need the clock rate, we don't actually use the clk object. */
devm_clk_put(>dev, parent_clk);
 
+   bus->rst = devm_reset_control_get_optional_shared(>dev, NULL);
+   if (IS_ERR(bus->rst)) {
+   dev_err(>dev, "invalid reset controller in device tree");
+   bus->rst = NULL;
+   } else
+   reset_control_deassert(bus->rst);
+
ret = of_property_read_u32(pdev->dev.of_node,
   "bus-frequency", >bus_frequency);
if (ret < 0) {
@@ -919,6 +929,8 @@ static int aspeed_i2c_remove_bus(struct platform_device 
*pdev)
 
i2c_del_adapter(>adap);
 
+   reset_control_assert(bus->rst);
+
return 0;
 }
 
-- 
2.14.1



[PATCH v3] i2c: aspeed: Deassert reset in probe

2017-10-29 Thread Joel Stanley
In order to use i2c from a cold boot, the i2c peripheral must be taken
out of reset. We request a shared reset controller each time a bus
driver is loaded, as the reset is shared between the 14 i2c buses.

On remove the reset is asserted, which only touches the hardware once
the last i2c bus is removed.

The request is optional, so if a device tree does not specify a reset
controller (or the driver is not built in), the driver continues to
probe.

Reviewed-by: Brendan Higgins 
Reviewed-by: Philipp Zabel 
Signed-off-by: Joel Stanley 
---
v3: Check for bad reset controller probe (caused by eg. bad device tree)
and set ->rst to NULL so assert/desassert does not cause a warning to
be printed
v2: Sort the headers
---
 drivers/i2c/busses/i2c-aspeed.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index 284f8670dbeb..5dec00d663eb 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -12,6 +12,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -27,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /* I2C Register */
@@ -132,6 +134,7 @@ struct aspeed_i2c_bus {
struct i2c_adapter  adap;
struct device   *dev;
void __iomem*base;
+   struct reset_control*rst;
/* Synchronizes I/O mem access to base. */
spinlock_t  lock;
struct completion   cmd_complete;
@@ -847,6 +850,13 @@ static int aspeed_i2c_probe_bus(struct platform_device 
*pdev)
/* We just need the clock rate, we don't actually use the clk object. */
devm_clk_put(>dev, parent_clk);
 
+   bus->rst = devm_reset_control_get_optional_shared(>dev, NULL);
+   if (IS_ERR(bus->rst)) {
+   dev_err(>dev, "invalid reset controller in device tree");
+   bus->rst = NULL;
+   } else
+   reset_control_deassert(bus->rst);
+
ret = of_property_read_u32(pdev->dev.of_node,
   "bus-frequency", >bus_frequency);
if (ret < 0) {
@@ -919,6 +929,8 @@ static int aspeed_i2c_remove_bus(struct platform_device 
*pdev)
 
i2c_del_adapter(>adap);
 
+   reset_control_assert(bus->rst);
+
return 0;
 }
 
-- 
2.14.1



Re: [PATCH V4 07/12] boot_constraint: Add debugfs support

2017-10-29 Thread Randy Dunlap
On 10/29/17 20:37, Viresh Kumar wrote:
> On 29-10-17, 08:09, Randy Dunlap wrote:
>> On 10/29/17 06:48, Viresh Kumar wrote:
>>> This patch adds debugfs support for boot constraints. This is how it
>>> looks for a "vmmc-supply" constraint for the MMC device.
>>>
>>> Tested-by: Rajendra Nayak 
>>> Signed-off-by: Viresh Kumar 
>>> ---
>>>  drivers/boot_constraints/clk.c|  3 ++
>>>  drivers/boot_constraints/core.c   | 60 
>>> +++
>>>  drivers/boot_constraints/core.h   |  6 
>>>  drivers/boot_constraints/pm.c | 11 +--
>>>  drivers/boot_constraints/supply.c |  9 ++
>>>  5 files changed, 87 insertions(+), 2 deletions(-)
>>
>> Hi,
>> Does this build OK when CONFIG_DEBUG_FS is not enabled?
>>
>> I didn't see any depends on or select DEBUG_FS or any use of
>> CONFIG_DEBUG_FS in any Makefile.
> 
> As soon as I saw your reply, it looked like I have seen this email
> earlier. :)
> 
> https://marc.info/?l=linux-kernel=149866480929111=2
> 
> And yes, it builds just fine as all the dummy helpers are in place.
> 

Thanks.

-- 
~Randy


Re: [PATCH V4 07/12] boot_constraint: Add debugfs support

2017-10-29 Thread Randy Dunlap
On 10/29/17 20:37, Viresh Kumar wrote:
> On 29-10-17, 08:09, Randy Dunlap wrote:
>> On 10/29/17 06:48, Viresh Kumar wrote:
>>> This patch adds debugfs support for boot constraints. This is how it
>>> looks for a "vmmc-supply" constraint for the MMC device.
>>>
>>> Tested-by: Rajendra Nayak 
>>> Signed-off-by: Viresh Kumar 
>>> ---
>>>  drivers/boot_constraints/clk.c|  3 ++
>>>  drivers/boot_constraints/core.c   | 60 
>>> +++
>>>  drivers/boot_constraints/core.h   |  6 
>>>  drivers/boot_constraints/pm.c | 11 +--
>>>  drivers/boot_constraints/supply.c |  9 ++
>>>  5 files changed, 87 insertions(+), 2 deletions(-)
>>
>> Hi,
>> Does this build OK when CONFIG_DEBUG_FS is not enabled?
>>
>> I didn't see any depends on or select DEBUG_FS or any use of
>> CONFIG_DEBUG_FS in any Makefile.
> 
> As soon as I saw your reply, it looked like I have seen this email
> earlier. :)
> 
> https://marc.info/?l=linux-kernel=149866480929111=2
> 
> And yes, it builds just fine as all the dummy helpers are in place.
> 

Thanks.

-- 
~Randy


Re: [PATCH] Check all .c files for bad kernel-doc comments

2017-10-29 Thread Masahiro Yamada
Hi Matthew,


2017-10-28 4:41 GMT+09:00 Matthew Wilcox :
> From: Matthew Wilcox 
>
> Implement a '-none' output mode for kernel-doc which will only output
> warning messages, and suppresses the warning message about there being
> no kernel-doc in the file.  Add it to the rule to build .o files from .c
> files, so it will check all .c files that have been modified.
>
> Adds about 1300 warnings to my build, but will hopefully discourage
> people from introducing more kerneldoc mistakes.


Basically, I think this is good,
but it is controversial to sprinkle warnings by default.

Maybe,

ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< ;
endif


so that this is checked only when W=... is given?




> Signed-off-by: Matthew Wilcox 
>
>  scripts/Makefile.build |  3 +++
>  scripts/kernel-doc | 25 -
>  2 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 061d0c3a420a..f0f907af53c7 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -108,6 +108,8 @@ ifneq ($(KBUILD_CHECKSRC),0)
>endif
>  endif
>
> +cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< ;
> +
>  # Do section mismatch analysis for each module/built-in.o
>  ifdef CONFIG_DEBUG_SECTION_MISMATCH
>cmd_secanalysis = ; scripts/mod/modpost $@
> @@ -291,6 +293,7 @@ define rule_cc_o_c
> $(call echo-cmd,checksrc) $(cmd_checksrc) \
> $(call cmd_and_fixdep,cc_o_c) \
> $(cmd_modversions_c)  \
> +   $(cmd_checkdoc)   \
> $(call echo-cmd,objtool) $(cmd_objtool)   \
> $(call echo-cmd,record_mcount) $(cmd_record_mcount)
>  endef
> diff --git a/scripts/kernel-doc b/scripts/kernel-doc
> index 9d3eafea58f0..c69583440a44 100755
> --- a/scripts/kernel-doc
> +++ b/scripts/kernel-doc
> @@ -58,6 +58,7 @@ Output format selection (mutually exclusive):
>-man Output troff manual page format. This is the default.
>-rst Output reStructuredText format.
>-textOutput plain text format.
> +  -noneDo not output documentation, only warnings.
>
>  Output selection (mutually exclusive):
>-export  Only output documentation for symbols that have been
> @@ -532,6 +533,8 @@ while ($ARGV[0] =~ m/^-(.*)/) {
> $output_mode = "gnome";
> @highlights = @highlights_gnome;
> $blankline = $blankline_gnome;
> +} elsif ($cmd eq "-none") {
> +   $output_mode = "none";
>  } elsif ($cmd eq "-module") { # not needed for XML, inherits from 
> calling document
> $modulename = shift @ARGV;
>  } elsif ($cmd eq "-function") { # to only output specific functions
> @@ -2117,6 +2120,24 @@ sub output_blockhead_list(%) {
>  }
>  }
>
> +
> +## none mode output functions
> +
> +sub output_function_none(%) {
> +}
> +
> +sub output_enum_none(%) {
> +}
> +
> +sub output_typedef_none(%) {
> +}
> +
> +sub output_struct_none(%) {
> +}
> +
> +sub output_blockhead_none(%) {
> +}
> +
>  ##
>  # generic output function for all types (function, struct/union, typedef, 
> enum);
>  # calls the generated, variable output_ function name based on
> @@ -3136,7 +3157,9 @@ sub process_file($) {
> }
>  }
>  if ($initial_section_counter == $section_counter) {
> -   print STDERR "${file}:1: warning: no structured comments found\n";
> +   if ($output_mode ne "none") {
> +   print STDERR "${file}:1: warning: no structured comments found\n";
> +   }
> if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
> print STDERR "Was looking for '$_'.\n" for keys 
> %function_table;
> }
> --
> 2.11.0.301.g722e3be85.dirty
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Best Regards
Masahiro Yamada


Re: [PATCH] Check all .c files for bad kernel-doc comments

2017-10-29 Thread Masahiro Yamada
Hi Matthew,


2017-10-28 4:41 GMT+09:00 Matthew Wilcox :
> From: Matthew Wilcox 
>
> Implement a '-none' output mode for kernel-doc which will only output
> warning messages, and suppresses the warning message about there being
> no kernel-doc in the file.  Add it to the rule to build .o files from .c
> files, so it will check all .c files that have been modified.
>
> Adds about 1300 warnings to my build, but will hopefully discourage
> people from introducing more kerneldoc mistakes.


Basically, I think this is good,
but it is controversial to sprinkle warnings by default.

Maybe,

ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< ;
endif


so that this is checked only when W=... is given?




> Signed-off-by: Matthew Wilcox 
>
>  scripts/Makefile.build |  3 +++
>  scripts/kernel-doc | 25 -
>  2 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 061d0c3a420a..f0f907af53c7 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -108,6 +108,8 @@ ifneq ($(KBUILD_CHECKSRC),0)
>endif
>  endif
>
> +cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< ;
> +
>  # Do section mismatch analysis for each module/built-in.o
>  ifdef CONFIG_DEBUG_SECTION_MISMATCH
>cmd_secanalysis = ; scripts/mod/modpost $@
> @@ -291,6 +293,7 @@ define rule_cc_o_c
> $(call echo-cmd,checksrc) $(cmd_checksrc) \
> $(call cmd_and_fixdep,cc_o_c) \
> $(cmd_modversions_c)  \
> +   $(cmd_checkdoc)   \
> $(call echo-cmd,objtool) $(cmd_objtool)   \
> $(call echo-cmd,record_mcount) $(cmd_record_mcount)
>  endef
> diff --git a/scripts/kernel-doc b/scripts/kernel-doc
> index 9d3eafea58f0..c69583440a44 100755
> --- a/scripts/kernel-doc
> +++ b/scripts/kernel-doc
> @@ -58,6 +58,7 @@ Output format selection (mutually exclusive):
>-man Output troff manual page format. This is the default.
>-rst Output reStructuredText format.
>-textOutput plain text format.
> +  -noneDo not output documentation, only warnings.
>
>  Output selection (mutually exclusive):
>-export  Only output documentation for symbols that have been
> @@ -532,6 +533,8 @@ while ($ARGV[0] =~ m/^-(.*)/) {
> $output_mode = "gnome";
> @highlights = @highlights_gnome;
> $blankline = $blankline_gnome;
> +} elsif ($cmd eq "-none") {
> +   $output_mode = "none";
>  } elsif ($cmd eq "-module") { # not needed for XML, inherits from 
> calling document
> $modulename = shift @ARGV;
>  } elsif ($cmd eq "-function") { # to only output specific functions
> @@ -2117,6 +2120,24 @@ sub output_blockhead_list(%) {
>  }
>  }
>
> +
> +## none mode output functions
> +
> +sub output_function_none(%) {
> +}
> +
> +sub output_enum_none(%) {
> +}
> +
> +sub output_typedef_none(%) {
> +}
> +
> +sub output_struct_none(%) {
> +}
> +
> +sub output_blockhead_none(%) {
> +}
> +
>  ##
>  # generic output function for all types (function, struct/union, typedef, 
> enum);
>  # calls the generated, variable output_ function name based on
> @@ -3136,7 +3157,9 @@ sub process_file($) {
> }
>  }
>  if ($initial_section_counter == $section_counter) {
> -   print STDERR "${file}:1: warning: no structured comments found\n";
> +   if ($output_mode ne "none") {
> +   print STDERR "${file}:1: warning: no structured comments found\n";
> +   }
> if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
> print STDERR "Was looking for '$_'.\n" for keys 
> %function_table;
> }
> --
> 2.11.0.301.g722e3be85.dirty
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Best Regards
Masahiro Yamada


Re: [PATCH v2 RESEND] Revert "f2fs: handle dirty segments inside refresh_sit_entry"

2017-10-29 Thread Chao Yu
On 2017/10/30 9:33, Yunlong Song wrote:
> This reverts commit 5e443818fa0b2a2845561ee25bec181424fb2889
> 
> The commit should be reverted because call sequence of below two parts
> of code must be kept:
> a. update sit information, it needs to be updated before segment
> allocation since latter allocation may trigger SSR, and SSR allocation
> needs latest valid block information of all segments.
> b. update segment status, it needs to be updated after segment allocation
> since we can skip updating current opened segment status.
> 
> Fixes: 5e443818fa0b ("f2fs: handle dirty segments inside refresh_sit_entry")
> Suggested-by: Chao Yu 
> Signed-off-by: Yunlong Song 

Reviewed-by: Chao Yu 

Thanks,

> ---
>  fs/f2fs/f2fs.h|  1 -
>  fs/f2fs/segment.c | 20 +---
>  2 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 13a96b8..f166112 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -2567,7 +2567,6 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
>  bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
>  void init_discard_policy(struct discard_policy *dpolicy, int discard_type,
>   unsigned int granularity);
> -void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new);
>  void stop_discard_thread(struct f2fs_sb_info *sbi);
>  bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi);
>  void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control 
> *cpc);
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 46dfbca..a3509e9 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -1884,14 +1884,11 @@ static void update_sit_entry(struct f2fs_sb_info 
> *sbi, block_t blkaddr, int del)
>   get_sec_entry(sbi, segno)->valid_blocks += del;
>  }
>  
> -void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new)
> +static void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t 
> new)
>  {
>   update_sit_entry(sbi, new, 1);
>   if (GET_SEGNO(sbi, old) != NULL_SEGNO)
>   update_sit_entry(sbi, old, -1);
> -
> - locate_dirty_segment(sbi, GET_SEGNO(sbi, old));
> - locate_dirty_segment(sbi, GET_SEGNO(sbi, new));
>  }
>  
>  void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr)
> @@ -2529,13 +2526,22 @@ void allocate_data_block(struct f2fs_sb_info *sbi, 
> struct page *page,
>  
>   stat_inc_block_count(sbi, curseg);
>  
> + /*
> +  * SIT information should be updated before segment allocation,
> +  * since SSR needs latest valid block information.
> +  */
> + refresh_sit_entry(sbi, old_blkaddr, *new_blkaddr);
> +
>   if (!__has_curseg_space(sbi, type))
>   sit_i->s_ops->allocate_segment(sbi, type, false);
> +
>   /*
> -  * SIT information should be updated after segment allocation,
> -  * since we need to keep dirty segments precisely under SSR.
> +  * segment dirty status should be updated after segment allocation,
> +  * so we just need to update status only one time after previous
> +  * segment being closed.
>*/
> - refresh_sit_entry(sbi, old_blkaddr, *new_blkaddr);
> + locate_dirty_segment(sbi, GET_SEGNO(sbi, old_blkaddr));
> + locate_dirty_segment(sbi, GET_SEGNO(sbi, *new_blkaddr));
>  
>   mutex_unlock(_i->sentry_lock);
>  
> 



Re: [PATCH v2 RESEND] Revert "f2fs: handle dirty segments inside refresh_sit_entry"

2017-10-29 Thread Chao Yu
On 2017/10/30 9:33, Yunlong Song wrote:
> This reverts commit 5e443818fa0b2a2845561ee25bec181424fb2889
> 
> The commit should be reverted because call sequence of below two parts
> of code must be kept:
> a. update sit information, it needs to be updated before segment
> allocation since latter allocation may trigger SSR, and SSR allocation
> needs latest valid block information of all segments.
> b. update segment status, it needs to be updated after segment allocation
> since we can skip updating current opened segment status.
> 
> Fixes: 5e443818fa0b ("f2fs: handle dirty segments inside refresh_sit_entry")
> Suggested-by: Chao Yu 
> Signed-off-by: Yunlong Song 

Reviewed-by: Chao Yu 

Thanks,

> ---
>  fs/f2fs/f2fs.h|  1 -
>  fs/f2fs/segment.c | 20 +---
>  2 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 13a96b8..f166112 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -2567,7 +2567,6 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
>  bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
>  void init_discard_policy(struct discard_policy *dpolicy, int discard_type,
>   unsigned int granularity);
> -void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new);
>  void stop_discard_thread(struct f2fs_sb_info *sbi);
>  bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi);
>  void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control 
> *cpc);
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 46dfbca..a3509e9 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -1884,14 +1884,11 @@ static void update_sit_entry(struct f2fs_sb_info 
> *sbi, block_t blkaddr, int del)
>   get_sec_entry(sbi, segno)->valid_blocks += del;
>  }
>  
> -void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new)
> +static void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t 
> new)
>  {
>   update_sit_entry(sbi, new, 1);
>   if (GET_SEGNO(sbi, old) != NULL_SEGNO)
>   update_sit_entry(sbi, old, -1);
> -
> - locate_dirty_segment(sbi, GET_SEGNO(sbi, old));
> - locate_dirty_segment(sbi, GET_SEGNO(sbi, new));
>  }
>  
>  void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr)
> @@ -2529,13 +2526,22 @@ void allocate_data_block(struct f2fs_sb_info *sbi, 
> struct page *page,
>  
>   stat_inc_block_count(sbi, curseg);
>  
> + /*
> +  * SIT information should be updated before segment allocation,
> +  * since SSR needs latest valid block information.
> +  */
> + refresh_sit_entry(sbi, old_blkaddr, *new_blkaddr);
> +
>   if (!__has_curseg_space(sbi, type))
>   sit_i->s_ops->allocate_segment(sbi, type, false);
> +
>   /*
> -  * SIT information should be updated after segment allocation,
> -  * since we need to keep dirty segments precisely under SSR.
> +  * segment dirty status should be updated after segment allocation,
> +  * so we just need to update status only one time after previous
> +  * segment being closed.
>*/
> - refresh_sit_entry(sbi, old_blkaddr, *new_blkaddr);
> + locate_dirty_segment(sbi, GET_SEGNO(sbi, old_blkaddr));
> + locate_dirty_segment(sbi, GET_SEGNO(sbi, *new_blkaddr));
>  
>   mutex_unlock(_i->sentry_lock);
>  
> 



Re: [PATCH V4 07/12] boot_constraint: Add debugfs support

2017-10-29 Thread Viresh Kumar
On 29-10-17, 08:09, Randy Dunlap wrote:
> On 10/29/17 06:48, Viresh Kumar wrote:
> > This patch adds debugfs support for boot constraints. This is how it
> > looks for a "vmmc-supply" constraint for the MMC device.
> > 
> > Tested-by: Rajendra Nayak 
> > Signed-off-by: Viresh Kumar 
> > ---
> >  drivers/boot_constraints/clk.c|  3 ++
> >  drivers/boot_constraints/core.c   | 60 
> > +++
> >  drivers/boot_constraints/core.h   |  6 
> >  drivers/boot_constraints/pm.c | 11 +--
> >  drivers/boot_constraints/supply.c |  9 ++
> >  5 files changed, 87 insertions(+), 2 deletions(-)
> 
> Hi,
> Does this build OK when CONFIG_DEBUG_FS is not enabled?
> 
> I didn't see any depends on or select DEBUG_FS or any use of
> CONFIG_DEBUG_FS in any Makefile.

As soon as I saw your reply, it looked like I have seen this email
earlier. :)

https://marc.info/?l=linux-kernel=149866480929111=2

And yes, it builds just fine as all the dummy helpers are in place.

-- 
viresh


Re: [PATCH V4 07/12] boot_constraint: Add debugfs support

2017-10-29 Thread Viresh Kumar
On 29-10-17, 08:09, Randy Dunlap wrote:
> On 10/29/17 06:48, Viresh Kumar wrote:
> > This patch adds debugfs support for boot constraints. This is how it
> > looks for a "vmmc-supply" constraint for the MMC device.
> > 
> > Tested-by: Rajendra Nayak 
> > Signed-off-by: Viresh Kumar 
> > ---
> >  drivers/boot_constraints/clk.c|  3 ++
> >  drivers/boot_constraints/core.c   | 60 
> > +++
> >  drivers/boot_constraints/core.h   |  6 
> >  drivers/boot_constraints/pm.c | 11 +--
> >  drivers/boot_constraints/supply.c |  9 ++
> >  5 files changed, 87 insertions(+), 2 deletions(-)
> 
> Hi,
> Does this build OK when CONFIG_DEBUG_FS is not enabled?
> 
> I didn't see any depends on or select DEBUG_FS or any use of
> CONFIG_DEBUG_FS in any Makefile.

As soon as I saw your reply, it looked like I have seen this email
earlier. :)

https://marc.info/?l=linux-kernel=149866480929111=2

And yes, it builds just fine as all the dummy helpers are in place.

-- 
viresh


[Part2 PATCH v6.2 18/38] crypto: ccp: Implement SEV_PEK_CSR ioctl command

2017-10-29 Thread Brijesh Singh
The SEV_PEK_CSR command can be used to generate a PEK certificate
signing request. The command is defined in SEV spec section 5.7.

Cc: Paolo Bonzini 
Cc: "Radim Krčmář" 
Cc: Borislav Petkov 
Cc: Herbert Xu 
Cc: Gary Hook 
Cc: Tom Lendacky 
Cc: linux-cry...@vger.kernel.org
Cc: k...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Improvements-by: Borislav Petkov 
Signed-off-by: Brijesh Singh 
Acked-by: Gary R Hook 
---

Changes since v6.1:
 * use psp->sev_state to check the state before transition to INIT

 drivers/crypto/ccp/psp-dev.c | 68 
 1 file changed, 68 insertions(+)

diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index 0d4d95bc35ab..e69ac6f6173c 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -253,6 +253,71 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct 
sev_issue_cmd *argp)
return sev_do_cmd_locked(cmd, 0, >error);
 }
 
+static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp)
+{
+   struct sev_user_data_pek_csr input;
+   struct sev_data_pek_csr *data;
+   void *blob = NULL;
+   int ret;
+
+   if (copy_from_user(, (void __user *)argp->data, sizeof(input)))
+   return -EFAULT;
+
+   data = kzalloc(sizeof(*data), GFP_KERNEL);
+   if (!data)
+   return -ENOMEM;
+
+   /* userspace wants to query CSR length */
+   if (!input.address || !input.length)
+   goto cmd;
+
+   /* allocate a physically contiguous buffer to store the CSR blob */
+   if (!access_ok(VERIFY_WRITE, input.address, input.length) ||
+   input.length > SEV_FW_BLOB_MAX_SIZE) {
+   ret = -EFAULT;
+   goto e_free;
+   }
+
+   blob = kmalloc(input.length, GFP_KERNEL);
+   if (!blob) {
+   ret = -ENOMEM;
+   goto e_free;
+   }
+
+   data->address = __psp_pa(blob);
+   data->len = input.length;
+
+cmd:
+   if (psp_master->sev_state == SEV_STATE_UNINIT) {
+   ret = sev_platform_init_locked(NULL, >error);
+   if (ret)
+   goto e_free_blob;
+   }
+
+   ret = sev_do_cmd_locked(SEV_CMD_PEK_CSR, data, >error);
+
+   /*
+* If we query the CSR length, FW responded with expected data
+*/
+   input.length = data->len;
+
+   if (copy_to_user((void __user *)argp->data, , sizeof(input))) {
+   ret = -EFAULT;
+   goto e_free_blob;
+   }
+
+   if (blob) {
+   if (copy_to_user((void __user *)input.address, blob, 
input.length))
+   ret = -EFAULT;
+   }
+
+e_free_blob:
+   kfree(blob);
+e_free:
+   kfree(data);
+   return ret;
+}
+
 static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
 {
void __user *argp = (void __user *)arg;
@@ -287,6 +352,9 @@ static long sev_ioctl(struct file *file, unsigned int 
ioctl, unsigned long arg)
case SEV_PDH_GEN:
ret = sev_ioctl_do_pek_pdh_gen(SEV_CMD_PDH_GEN, );
break;
+   case SEV_PEK_CSR:
+   ret = sev_ioctl_do_pek_csr();
+   break;
default:
ret = -EINVAL;
goto out;
-- 
2.9.5



[Part2 PATCH v6.2 18/38] crypto: ccp: Implement SEV_PEK_CSR ioctl command

2017-10-29 Thread Brijesh Singh
The SEV_PEK_CSR command can be used to generate a PEK certificate
signing request. The command is defined in SEV spec section 5.7.

Cc: Paolo Bonzini 
Cc: "Radim Krčmář" 
Cc: Borislav Petkov 
Cc: Herbert Xu 
Cc: Gary Hook 
Cc: Tom Lendacky 
Cc: linux-cry...@vger.kernel.org
Cc: k...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Improvements-by: Borislav Petkov 
Signed-off-by: Brijesh Singh 
Acked-by: Gary R Hook 
---

Changes since v6.1:
 * use psp->sev_state to check the state before transition to INIT

 drivers/crypto/ccp/psp-dev.c | 68 
 1 file changed, 68 insertions(+)

diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index 0d4d95bc35ab..e69ac6f6173c 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -253,6 +253,71 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct 
sev_issue_cmd *argp)
return sev_do_cmd_locked(cmd, 0, >error);
 }
 
+static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp)
+{
+   struct sev_user_data_pek_csr input;
+   struct sev_data_pek_csr *data;
+   void *blob = NULL;
+   int ret;
+
+   if (copy_from_user(, (void __user *)argp->data, sizeof(input)))
+   return -EFAULT;
+
+   data = kzalloc(sizeof(*data), GFP_KERNEL);
+   if (!data)
+   return -ENOMEM;
+
+   /* userspace wants to query CSR length */
+   if (!input.address || !input.length)
+   goto cmd;
+
+   /* allocate a physically contiguous buffer to store the CSR blob */
+   if (!access_ok(VERIFY_WRITE, input.address, input.length) ||
+   input.length > SEV_FW_BLOB_MAX_SIZE) {
+   ret = -EFAULT;
+   goto e_free;
+   }
+
+   blob = kmalloc(input.length, GFP_KERNEL);
+   if (!blob) {
+   ret = -ENOMEM;
+   goto e_free;
+   }
+
+   data->address = __psp_pa(blob);
+   data->len = input.length;
+
+cmd:
+   if (psp_master->sev_state == SEV_STATE_UNINIT) {
+   ret = sev_platform_init_locked(NULL, >error);
+   if (ret)
+   goto e_free_blob;
+   }
+
+   ret = sev_do_cmd_locked(SEV_CMD_PEK_CSR, data, >error);
+
+   /*
+* If we query the CSR length, FW responded with expected data
+*/
+   input.length = data->len;
+
+   if (copy_to_user((void __user *)argp->data, , sizeof(input))) {
+   ret = -EFAULT;
+   goto e_free_blob;
+   }
+
+   if (blob) {
+   if (copy_to_user((void __user *)input.address, blob, 
input.length))
+   ret = -EFAULT;
+   }
+
+e_free_blob:
+   kfree(blob);
+e_free:
+   kfree(data);
+   return ret;
+}
+
 static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
 {
void __user *argp = (void __user *)arg;
@@ -287,6 +352,9 @@ static long sev_ioctl(struct file *file, unsigned int 
ioctl, unsigned long arg)
case SEV_PDH_GEN:
ret = sev_ioctl_do_pek_pdh_gen(SEV_CMD_PDH_GEN, );
break;
+   case SEV_PEK_CSR:
+   ret = sev_ioctl_do_pek_csr();
+   break;
default:
ret = -EINVAL;
goto out;
-- 
2.9.5



Re: [PATCH v6 9/9] KVM: arm/arm64: vgic-its: Implement KVM_DEV_ARM_ITS_CTRL_RESET

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:11 pm BST, Eric Auger  
wrote:
> On reset we clear the valid bits of GITS_CBASER and GITS_BASER.
> We also clear command queue registers and free the cache (device,
> collection, and lpi lists).
>
> As we need to take the same locks as save/restore functions, we
> create a vgic_its_ctrl() wrapper that handles KVM_DEV_ARM_VGIC_GRP_CTRL
> group functions.
>
> Signed-off-by: Eric Auger 

Reviewed-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny.


Re: [PATCH v6 9/9] KVM: arm/arm64: vgic-its: Implement KVM_DEV_ARM_ITS_CTRL_RESET

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:11 pm BST, Eric Auger  
wrote:
> On reset we clear the valid bits of GITS_CBASER and GITS_BASER.
> We also clear command queue registers and free the cache (device,
> collection, and lpi lists).
>
> As we need to take the same locks as save/restore functions, we
> create a vgic_its_ctrl() wrapper that handles KVM_DEV_ARM_VGIC_GRP_CTRL
> group functions.
>
> Signed-off-by: Eric Auger 

Reviewed-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny.


Re: [PATCH v6 8/9] KVM: arm/arm64: Document KVM_DEV_ARM_ITS_CTRL_RESET

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:10 pm BST, Eric Auger  
wrote:
> At the moment, the in-kernel emulated ITS is not properly reset.
> On guest restart/reset some registers keep their old values and
> internal structures like device, ITE, and collection lists are not
> freed.
>
> This may lead to various bugs. Among them, we can have incorrect state
> backup or failure when saving the ITS state at early guest boot stage.
>
> This patch documents a new attribute, KVM_DEV_ARM_ITS_CTRL_RESET in
> the KVM_DEV_ARM_VGIC_GRP_CTRL group.
>
> Upon this action, we can reset registers and especially those
> pointing to tables previously allocated by the guest and free
> the internal data structures storing the list of devices, collections
> and lpis.
>
> The usual approach for device reset of having userspace write
> the reset values of the registers to the kernel via the register
> read/write APIs doesn't work for the ITS because it has some
> internal state (caches) which is not exposed as registers,
> and there is no register interface for "drop cached data without
> writing it back to RAM". So we need a KVM API which mimics the
> hardware's reset line, to provide the equivalent behaviour to
> a "pull the power cord out of the back of the machine" reset.
>
> Signed-off-by: Eric Auger 
> Reported-by: wanghaibin 

Reviewed-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny.


Re: [PATCH v6 8/9] KVM: arm/arm64: Document KVM_DEV_ARM_ITS_CTRL_RESET

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:10 pm BST, Eric Auger  
wrote:
> At the moment, the in-kernel emulated ITS is not properly reset.
> On guest restart/reset some registers keep their old values and
> internal structures like device, ITE, and collection lists are not
> freed.
>
> This may lead to various bugs. Among them, we can have incorrect state
> backup or failure when saving the ITS state at early guest boot stage.
>
> This patch documents a new attribute, KVM_DEV_ARM_ITS_CTRL_RESET in
> the KVM_DEV_ARM_VGIC_GRP_CTRL group.
>
> Upon this action, we can reset registers and especially those
> pointing to tables previously allocated by the guest and free
> the internal data structures storing the list of devices, collections
> and lpis.
>
> The usual approach for device reset of having userspace write
> the reset values of the registers to the kernel via the register
> read/write APIs doesn't work for the ITS because it has some
> internal state (caches) which is not exposed as registers,
> and there is no register interface for "drop cached data without
> writing it back to RAM". So we need a KVM API which mimics the
> hardware's reset line, to provide the equivalent behaviour to
> a "pull the power cord out of the back of the machine" reset.
>
> Signed-off-by: Eric Auger 
> Reported-by: wanghaibin 

Reviewed-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny.


Re: [PATCH v6 6/9] KVM: arm/arm64: vgic-its: New helper functions to free the caches

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:08 pm BST, Eric Auger  
wrote:
> From: wanghaibin 
>
> We create two new functions that free the device and
> collection lists. They are currently called by vgic_its_destroy()
> and other callers will be added in subsequent patches.
>
> We also remove the check on its->device_list.next.
> Lists are initialized in vgic_create_its() and the device
> is added to the device list only if this latter succeeds.
>
> vgic_its_destroy is the device destroy ops. This latter is called
> by kvm_destroy_devices() which loops on all created devices. So
> at this point the list is initialized.
>
> Signed-off-by: wanghaibin 
> Signed-off-by: Eric Auger 

Acked-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny.


Re: [PATCH v6 6/9] KVM: arm/arm64: vgic-its: New helper functions to free the caches

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:08 pm BST, Eric Auger  
wrote:
> From: wanghaibin 
>
> We create two new functions that free the device and
> collection lists. They are currently called by vgic_its_destroy()
> and other callers will be added in subsequent patches.
>
> We also remove the check on its->device_list.next.
> Lists are initialized in vgic_create_its() and the device
> is added to the device list only if this latter succeeds.
>
> vgic_its_destroy is the device destroy ops. This latter is called
> by kvm_destroy_devices() which loops on all created devices. So
> at this point the list is initialized.
>
> Signed-off-by: wanghaibin 
> Signed-off-by: Eric Auger 

Acked-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny.


Re: [PATCH v6 7/9] KVM: arm/arm64: vgic-its: Free caches when GITS_BASER Valid bit is cleared

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:09 pm BST, Eric Auger  
wrote:
> When the GITS_BASER.Valid gets cleared, the data structures in
> guest RAM are not valid anymore. The device, collection
> and LPI lists stored in the in-kernel ITS represent the same
> information in some form of cache. So let's void the cache.
>
> Signed-off-by: Eric Auger 
>
> ---
> v5 -> v6:
> - rename type into device_type and revert tthe u64 -> int change
> - remove the default clause
> - take the its mutex lock around vgic_its_free_device/collection_list
>
> v4 -> v5:
> - add comment about locking
>
> v2 -> v3:
> - add a comment and clear cache in if block
> ---
>  virt/kvm/arm/vgic/vgic-its.c | 26 ++
>  1 file changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
> index 5b7be85..2a92d4d 100644
> --- a/virt/kvm/arm/vgic/vgic-its.c
> +++ b/virt/kvm/arm/vgic/vgic-its.c
> @@ -1428,7 +1428,7 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
> unsigned long val)
>  {
>   const struct vgic_its_abi *abi = vgic_its_get_abi(its);
> - u64 entry_size, device_type;
> + u64 entry_size, table_type;
>   u64 reg, *regptr, clearbits = 0;
>  
>   /* When GITS_CTLR.Enable is 1, we ignore write accesses. */
> @@ -1439,12 +1439,12 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
>   case 0:
>   regptr = >baser_device_table;
>   entry_size = abi->dte_esz;
> - device_type = GITS_BASER_TYPE_DEVICE;
> + table_type = GITS_BASER_TYPE_DEVICE;
>   break;
>   case 1:
>   regptr = >baser_coll_table;
>   entry_size = abi->cte_esz;
> - device_type = GITS_BASER_TYPE_COLLECTION;
> + table_type = GITS_BASER_TYPE_COLLECTION;
>   clearbits = GITS_BASER_INDIRECT;
>   break;
>   default:
> @@ -1456,10 +1456,28 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
>   reg &= ~clearbits;
>  
>   reg |= (entry_size - 1) << GITS_BASER_ENTRY_SIZE_SHIFT;
> - reg |= device_type << GITS_BASER_TYPE_SHIFT;
> + reg |= table_type << GITS_BASER_TYPE_SHIFT;
>   reg = vgic_sanitise_its_baser(reg);
>  
>   *regptr = reg;
> +
> + /*
> +  * If the table is no longer valid, we clear the associated cached data.
> +  * Note: there cannot be any race with save/restore code which locks
> +  * all vcpus.
> +  */

nit: I found this comment to be pretty confusing, as it talks about
locks that we don't try to take here. The actual mutual exclusion is
done by taking the its_lock, which is also taken on the save/restore
path.

Christoffer: can you fix that when applying this patch? I don't think
there is a need for a respin of the series just for this.

> + if (!(reg & GITS_BASER_VALID)) {
> + mutex_lock(>its_lock);
> + switch (table_type) {
> + case GITS_BASER_TYPE_DEVICE:
> + vgic_its_free_device_list(kvm, its);
> + break;
> + case GITS_BASER_TYPE_COLLECTION:
> + vgic_its_free_collection_list(kvm, its);
> + break;
> + }
> + mutex_unlock(>its_lock);
> + }
>  }
>  
>  static unsigned long vgic_mmio_read_its_ctlr(struct kvm *vcpu,

Otherwise:

Reviewed-by: Marc Zyngier 

Thanks,

M.
-- 
Jazz is not dead. It just smells funny.


Re: [PATCH v6 7/9] KVM: arm/arm64: vgic-its: Free caches when GITS_BASER Valid bit is cleared

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:09 pm BST, Eric Auger  
wrote:
> When the GITS_BASER.Valid gets cleared, the data structures in
> guest RAM are not valid anymore. The device, collection
> and LPI lists stored in the in-kernel ITS represent the same
> information in some form of cache. So let's void the cache.
>
> Signed-off-by: Eric Auger 
>
> ---
> v5 -> v6:
> - rename type into device_type and revert tthe u64 -> int change
> - remove the default clause
> - take the its mutex lock around vgic_its_free_device/collection_list
>
> v4 -> v5:
> - add comment about locking
>
> v2 -> v3:
> - add a comment and clear cache in if block
> ---
>  virt/kvm/arm/vgic/vgic-its.c | 26 ++
>  1 file changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
> index 5b7be85..2a92d4d 100644
> --- a/virt/kvm/arm/vgic/vgic-its.c
> +++ b/virt/kvm/arm/vgic/vgic-its.c
> @@ -1428,7 +1428,7 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
> unsigned long val)
>  {
>   const struct vgic_its_abi *abi = vgic_its_get_abi(its);
> - u64 entry_size, device_type;
> + u64 entry_size, table_type;
>   u64 reg, *regptr, clearbits = 0;
>  
>   /* When GITS_CTLR.Enable is 1, we ignore write accesses. */
> @@ -1439,12 +1439,12 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
>   case 0:
>   regptr = >baser_device_table;
>   entry_size = abi->dte_esz;
> - device_type = GITS_BASER_TYPE_DEVICE;
> + table_type = GITS_BASER_TYPE_DEVICE;
>   break;
>   case 1:
>   regptr = >baser_coll_table;
>   entry_size = abi->cte_esz;
> - device_type = GITS_BASER_TYPE_COLLECTION;
> + table_type = GITS_BASER_TYPE_COLLECTION;
>   clearbits = GITS_BASER_INDIRECT;
>   break;
>   default:
> @@ -1456,10 +1456,28 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
>   reg &= ~clearbits;
>  
>   reg |= (entry_size - 1) << GITS_BASER_ENTRY_SIZE_SHIFT;
> - reg |= device_type << GITS_BASER_TYPE_SHIFT;
> + reg |= table_type << GITS_BASER_TYPE_SHIFT;
>   reg = vgic_sanitise_its_baser(reg);
>  
>   *regptr = reg;
> +
> + /*
> +  * If the table is no longer valid, we clear the associated cached data.
> +  * Note: there cannot be any race with save/restore code which locks
> +  * all vcpus.
> +  */

nit: I found this comment to be pretty confusing, as it talks about
locks that we don't try to take here. The actual mutual exclusion is
done by taking the its_lock, which is also taken on the save/restore
path.

Christoffer: can you fix that when applying this patch? I don't think
there is a need for a respin of the series just for this.

> + if (!(reg & GITS_BASER_VALID)) {
> + mutex_lock(>its_lock);
> + switch (table_type) {
> + case GITS_BASER_TYPE_DEVICE:
> + vgic_its_free_device_list(kvm, its);
> + break;
> + case GITS_BASER_TYPE_COLLECTION:
> + vgic_its_free_collection_list(kvm, its);
> + break;
> + }
> + mutex_unlock(>its_lock);
> + }
>  }
>  
>  static unsigned long vgic_mmio_read_its_ctlr(struct kvm *vcpu,

Otherwise:

Reviewed-by: Marc Zyngier 

Thanks,

M.
-- 
Jazz is not dead. It just smells funny.


[PATCH] selftests/vm: Add tests validating mremap mirror functionality

2017-10-29 Thread Anshuman Khandual
This adds two tests to validate mirror functionality with mremap()
system call on shared and private anon mappings. After the commit
dba58d3b8c5 ("mm/mremap: fail map duplication attempts for private
mappings"), any attempt to mirror private anon mapping will fail.

Suggested-by: Mike Kravetz 
Signed-off-by: Anshuman Khandual 
Reviewed-by: Mike Kravetz 
---
Changes in V4:

- Folded these two test files into just one as per Mike
- Did some renaming of functions, cleans ups etc

Changes in V3: (https://patchwork.kernel.org/patch/10013469/)

- Fail any attempts to mirror an existing anon private mapping
- Updated run_vmtests to include these new mremap tests
- Updated the commit message

Changes in V2: (https://patchwork.kernel.org/patch/9861259/)

- Added a test for private anon mappings
- Used sysconf(_SC_PAGESIZE) instead of hard coding page size
- Used MREMAP_MAYMOVE instead of hard coding the flag value 1

Original V1: (https://patchwork.kernel.org/patch/9854415/)

 tools/testing/selftests/vm/Makefile|  1 +
 tools/testing/selftests/vm/mremap_mirror.c | 96 ++
 tools/testing/selftests/vm/run_vmtests | 10 
 3 files changed, 107 insertions(+)
 create mode 100644 tools/testing/selftests/vm/mremap_mirror.c

diff --git a/tools/testing/selftests/vm/Makefile 
b/tools/testing/selftests/vm/Makefile
index cbb29e4..27f1967 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -17,6 +17,7 @@ TEST_GEN_FILES += transhuge-stress
 TEST_GEN_FILES += userfaultfd
 TEST_GEN_FILES += mlock-random-test
 TEST_GEN_FILES += virtual_address_range
+TEST_GEN_FILES += mremap_mirror
 
 TEST_PROGS := run_vmtests
 
diff --git a/tools/testing/selftests/vm/mremap_mirror.c 
b/tools/testing/selftests/vm/mremap_mirror.c
new file mode 100644
index 000..41cdba5
--- /dev/null
+++ b/tools/testing/selftests/vm/mremap_mirror.c
@@ -0,0 +1,96 @@
+/*
+ * Test to verify mirror functionality with mremap() system
+ * call for shared and private anon mappings. In shared anon
+ * mapping case, the 'mirrored' buffer will match element to
+ * element with that of the original one. But any attempts
+ * to create a mirror buffer for an anon private one should
+ * just fail.
+ *
+ * Copyright (C) 2017 Anshuman Khandual, IBM Corporation
+ *
+ * Licensed under GPL V2
+ */
+#define _GNU_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PATTERN0xbe
+#define NR_PAGES   10
+
+int test_mirror_shared(char *old, char *new, unsigned long size)
+{
+   unsigned long i;
+
+   for (i = 0; i < size; i++) {
+   if (new[i] != old[i]) {
+   printf("Mismatch at new[%lu] expected \
+   %d received %d\n", i, old[i], new[i]);
+   return 1;
+   }
+   }
+   return 0;
+}
+
+int mirror_anon_shared(unsigned long alloc_size)
+{
+   char *ptr, *mirror_ptr;
+
+   ptr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
+   MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+   if (ptr == MAP_FAILED) {
+   perror("map() failed");
+   return -1;
+   }
+   memset(ptr, PATTERN, alloc_size);
+
+   mirror_ptr =  (char *) mremap(ptr, 0, alloc_size, MREMAP_MAYMOVE);
+   if (mirror_ptr == MAP_FAILED) {
+   perror("mremap() failed");
+   return -1;
+   }
+
+   if (test_mirror_shared(ptr, mirror_ptr, alloc_size))
+   return 1;
+
+   return 0;
+}
+
+int  mirror_anon_private(unsigned long alloc_size)
+{
+   char *ptr, *mirror_ptr;
+
+   ptr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
+   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+   if (ptr == MAP_FAILED) {
+   perror("map() failed");
+   return -1;
+   }
+   memset(ptr, PATTERN, alloc_size);
+
+   mirror_ptr =  (char *) mremap(ptr, 0, alloc_size, MREMAP_MAYMOVE);
+   if (mirror_ptr == MAP_FAILED)
+   return 0;
+
+   printf("Mirror attempt on private anon mapping should have failed\n");
+   return 1;
+}
+
+int main(int argc, char *argv[])
+{
+   unsigned long alloc_size;
+   int ret;
+
+   alloc_size = sysconf(_SC_PAGESIZE) * NR_PAGES;
+   ret = mirror_anon_private(alloc_size);
+   if (ret)
+   return ret;
+
+   ret = mirror_anon_shared(alloc_size);
+   if (ret)
+   return ret;
+   return 0;
+}
diff --git a/tools/testing/selftests/vm/run_vmtests 
b/tools/testing/selftests/vm/run_vmtests
index 07548a1..7214aa2 100755
--- a/tools/testing/selftests/vm/run_vmtests
+++ b/tools/testing/selftests/vm/run_vmtests
@@ -176,4 +176,14 @@ else
echo "[PASS]"
 fi
 
+echo "-"
+echo "mremap_mirror"
+echo "-"
+./mremap_mirror
+if [ $? -ne 0 

[PATCH] selftests/vm: Add tests validating mremap mirror functionality

2017-10-29 Thread Anshuman Khandual
This adds two tests to validate mirror functionality with mremap()
system call on shared and private anon mappings. After the commit
dba58d3b8c5 ("mm/mremap: fail map duplication attempts for private
mappings"), any attempt to mirror private anon mapping will fail.

Suggested-by: Mike Kravetz 
Signed-off-by: Anshuman Khandual 
Reviewed-by: Mike Kravetz 
---
Changes in V4:

- Folded these two test files into just one as per Mike
- Did some renaming of functions, cleans ups etc

Changes in V3: (https://patchwork.kernel.org/patch/10013469/)

- Fail any attempts to mirror an existing anon private mapping
- Updated run_vmtests to include these new mremap tests
- Updated the commit message

Changes in V2: (https://patchwork.kernel.org/patch/9861259/)

- Added a test for private anon mappings
- Used sysconf(_SC_PAGESIZE) instead of hard coding page size
- Used MREMAP_MAYMOVE instead of hard coding the flag value 1

Original V1: (https://patchwork.kernel.org/patch/9854415/)

 tools/testing/selftests/vm/Makefile|  1 +
 tools/testing/selftests/vm/mremap_mirror.c | 96 ++
 tools/testing/selftests/vm/run_vmtests | 10 
 3 files changed, 107 insertions(+)
 create mode 100644 tools/testing/selftests/vm/mremap_mirror.c

diff --git a/tools/testing/selftests/vm/Makefile 
b/tools/testing/selftests/vm/Makefile
index cbb29e4..27f1967 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -17,6 +17,7 @@ TEST_GEN_FILES += transhuge-stress
 TEST_GEN_FILES += userfaultfd
 TEST_GEN_FILES += mlock-random-test
 TEST_GEN_FILES += virtual_address_range
+TEST_GEN_FILES += mremap_mirror
 
 TEST_PROGS := run_vmtests
 
diff --git a/tools/testing/selftests/vm/mremap_mirror.c 
b/tools/testing/selftests/vm/mremap_mirror.c
new file mode 100644
index 000..41cdba5
--- /dev/null
+++ b/tools/testing/selftests/vm/mremap_mirror.c
@@ -0,0 +1,96 @@
+/*
+ * Test to verify mirror functionality with mremap() system
+ * call for shared and private anon mappings. In shared anon
+ * mapping case, the 'mirrored' buffer will match element to
+ * element with that of the original one. But any attempts
+ * to create a mirror buffer for an anon private one should
+ * just fail.
+ *
+ * Copyright (C) 2017 Anshuman Khandual, IBM Corporation
+ *
+ * Licensed under GPL V2
+ */
+#define _GNU_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PATTERN0xbe
+#define NR_PAGES   10
+
+int test_mirror_shared(char *old, char *new, unsigned long size)
+{
+   unsigned long i;
+
+   for (i = 0; i < size; i++) {
+   if (new[i] != old[i]) {
+   printf("Mismatch at new[%lu] expected \
+   %d received %d\n", i, old[i], new[i]);
+   return 1;
+   }
+   }
+   return 0;
+}
+
+int mirror_anon_shared(unsigned long alloc_size)
+{
+   char *ptr, *mirror_ptr;
+
+   ptr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
+   MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+   if (ptr == MAP_FAILED) {
+   perror("map() failed");
+   return -1;
+   }
+   memset(ptr, PATTERN, alloc_size);
+
+   mirror_ptr =  (char *) mremap(ptr, 0, alloc_size, MREMAP_MAYMOVE);
+   if (mirror_ptr == MAP_FAILED) {
+   perror("mremap() failed");
+   return -1;
+   }
+
+   if (test_mirror_shared(ptr, mirror_ptr, alloc_size))
+   return 1;
+
+   return 0;
+}
+
+int  mirror_anon_private(unsigned long alloc_size)
+{
+   char *ptr, *mirror_ptr;
+
+   ptr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
+   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+   if (ptr == MAP_FAILED) {
+   perror("map() failed");
+   return -1;
+   }
+   memset(ptr, PATTERN, alloc_size);
+
+   mirror_ptr =  (char *) mremap(ptr, 0, alloc_size, MREMAP_MAYMOVE);
+   if (mirror_ptr == MAP_FAILED)
+   return 0;
+
+   printf("Mirror attempt on private anon mapping should have failed\n");
+   return 1;
+}
+
+int main(int argc, char *argv[])
+{
+   unsigned long alloc_size;
+   int ret;
+
+   alloc_size = sysconf(_SC_PAGESIZE) * NR_PAGES;
+   ret = mirror_anon_private(alloc_size);
+   if (ret)
+   return ret;
+
+   ret = mirror_anon_shared(alloc_size);
+   if (ret)
+   return ret;
+   return 0;
+}
diff --git a/tools/testing/selftests/vm/run_vmtests 
b/tools/testing/selftests/vm/run_vmtests
index 07548a1..7214aa2 100755
--- a/tools/testing/selftests/vm/run_vmtests
+++ b/tools/testing/selftests/vm/run_vmtests
@@ -176,4 +176,14 @@ else
echo "[PASS]"
 fi
 
+echo "-"
+echo "mremap_mirror"
+echo "-"
+./mremap_mirror
+if [ $? -ne 0 ]; then
+   echo "[FAIL]"
+   exitcode=1
+else
+   echo "[PASS]"

Re: [PATCH v2] i2c: aspeed: Deassert reset in probe

2017-10-29 Thread Joel Stanley
On Fri, Oct 27, 2017 at 7:23 AM, Wolfram Sang  wrote:
>> > +   bus->rst = devm_reset_control_get_optional_shared(>dev, 
>> > NULL);
>>
>> This could return error values in case of broken device trees, so you
>> may want to check IS_ERR(bus->rst) and handle the error here.

>From my understanding the optional variant of the API will set
silently fail. That was my intention - an outdated device tree would
result in the same behaviour as the old driver.

>>
>> > +   reset_control_deassert(bus->rst);
>>
>> Otherwise this will dump a warning.
>>
>> > +
>> > ret = of_property_read_u32(pdev->dev.of_node,
>> >"bus-frequency", >bus_frequency);
>> > if (ret < 0) {
>> > @@ -919,6 +925,8 @@ static int aspeed_i2c_remove_bus(struct 
>> > platform_device *pdev)
>> >
>> > i2c_del_adapter(>adap);
>> >
>> > +   reset_control_assert(bus->rst);
>>
>> As will this.
>>
>> Reviewed-by: Philipp Zabel 
>
> Joel, do you want to fix it? I'd think it makes sense...

Sorry, I've been on vacation. I thought the _optional variant of the
API would do the right thing for my use case (silently fail on old
device trees), but I'll add a check.

v3 incoming.

Cheers,

Joel


Re: [PATCH v2] i2c: aspeed: Deassert reset in probe

2017-10-29 Thread Joel Stanley
On Fri, Oct 27, 2017 at 7:23 AM, Wolfram Sang  wrote:
>> > +   bus->rst = devm_reset_control_get_optional_shared(>dev, 
>> > NULL);
>>
>> This could return error values in case of broken device trees, so you
>> may want to check IS_ERR(bus->rst) and handle the error here.

>From my understanding the optional variant of the API will set
silently fail. That was my intention - an outdated device tree would
result in the same behaviour as the old driver.

>>
>> > +   reset_control_deassert(bus->rst);
>>
>> Otherwise this will dump a warning.
>>
>> > +
>> > ret = of_property_read_u32(pdev->dev.of_node,
>> >"bus-frequency", >bus_frequency);
>> > if (ret < 0) {
>> > @@ -919,6 +925,8 @@ static int aspeed_i2c_remove_bus(struct 
>> > platform_device *pdev)
>> >
>> > i2c_del_adapter(>adap);
>> >
>> > +   reset_control_assert(bus->rst);
>>
>> As will this.
>>
>> Reviewed-by: Philipp Zabel 
>
> Joel, do you want to fix it? I'd think it makes sense...

Sorry, I've been on vacation. I thought the _optional variant of the
API would do the right thing for my use case (silently fail on old
device trees), but I'll add a check.

v3 incoming.

Cheers,

Joel


[Part2 PATCH v6.1 15/38] crypto: ccp: Implement SEV_PEK_GEN ioctl command

2017-10-29 Thread Brijesh Singh
The SEV_PEK_GEN command is used to generate a new Platform Endorsement
Key (PEK). The command is defined in SEV spec section 5.6.

Cc: Paolo Bonzini 
Cc: "Radim Krčmář" 
Cc: Borislav Petkov 
Cc: Herbert Xu 
Cc: Gary Hook 
Cc: Tom Lendacky 
Cc: linux-cry...@vger.kernel.org
Cc: k...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: Borislav Petkov 
Improvements-by: Borislav Petkov 
Signed-off-by: Brijesh Singh 
Acked-by: Gary R Hook 
---

Boris,

I had your R-b in v6 and have kept it. The changes in this patch are
very minor. Let me know if you are okay with it - thanks

Changes since v6:
 * use psp->sev_state to check if FW is in correct state before
   doing the INIT transition

 drivers/crypto/ccp/psp-dev.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index 24a970809ded..53fbbc41b521 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -240,6 +240,19 @@ static int sev_ioctl_do_platform_status(struct 
sev_issue_cmd *argp)
return ret;
 }
 
+static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp)
+{
+   int rc;
+
+   if (psp_master->sev_state == SEV_STATE_UNINIT) {
+   rc = sev_platform_init_locked(NULL, >error);
+   if (rc)
+   return rc;
+   }
+
+   return sev_do_cmd_locked(cmd, 0, >error);
+}
+
 static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
 {
void __user *argp = (void __user *)arg;
@@ -268,6 +281,9 @@ static long sev_ioctl(struct file *file, unsigned int 
ioctl, unsigned long arg)
case SEV_PLATFORM_STATUS:
ret = sev_ioctl_do_platform_status();
break;
+   case SEV_PEK_GEN:
+   ret = sev_ioctl_do_pek_pdh_gen(SEV_CMD_PEK_GEN, );
+   break;
default:
ret = -EINVAL;
goto out;
-- 
2.9.5



[Part2 PATCH v6.1 15/38] crypto: ccp: Implement SEV_PEK_GEN ioctl command

2017-10-29 Thread Brijesh Singh
The SEV_PEK_GEN command is used to generate a new Platform Endorsement
Key (PEK). The command is defined in SEV spec section 5.6.

Cc: Paolo Bonzini 
Cc: "Radim Krčmář" 
Cc: Borislav Petkov 
Cc: Herbert Xu 
Cc: Gary Hook 
Cc: Tom Lendacky 
Cc: linux-cry...@vger.kernel.org
Cc: k...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: Borislav Petkov 
Improvements-by: Borislav Petkov 
Signed-off-by: Brijesh Singh 
Acked-by: Gary R Hook 
---

Boris,

I had your R-b in v6 and have kept it. The changes in this patch are
very minor. Let me know if you are okay with it - thanks

Changes since v6:
 * use psp->sev_state to check if FW is in correct state before
   doing the INIT transition

 drivers/crypto/ccp/psp-dev.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index 24a970809ded..53fbbc41b521 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -240,6 +240,19 @@ static int sev_ioctl_do_platform_status(struct 
sev_issue_cmd *argp)
return ret;
 }
 
+static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp)
+{
+   int rc;
+
+   if (psp_master->sev_state == SEV_STATE_UNINIT) {
+   rc = sev_platform_init_locked(NULL, >error);
+   if (rc)
+   return rc;
+   }
+
+   return sev_do_cmd_locked(cmd, 0, >error);
+}
+
 static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
 {
void __user *argp = (void __user *)arg;
@@ -268,6 +281,9 @@ static long sev_ioctl(struct file *file, unsigned int 
ioctl, unsigned long arg)
case SEV_PLATFORM_STATUS:
ret = sev_ioctl_do_platform_status();
break;
+   case SEV_PEK_GEN:
+   ret = sev_ioctl_do_pek_pdh_gen(SEV_CMD_PEK_GEN, );
+   break;
default:
ret = -EINVAL;
goto out;
-- 
2.9.5



Re: [PATCH stable-4.1.y] tools include: Add a __fallthrough statement

2017-10-29 Thread Levin, Alexander (Sasha Levin)
On Fri, Oct 27, 2017 at 12:05:58PM -0700, Florian Fainelli wrote:
>From: Arnaldo Carvalho de Melo 
>
>commit b5bf1733d6a391c4e90ea8f8468d83023be74a2a upstream.
>
>For cases where implicit fall through case labels are intended,
>to let us inform that to gcc >= 7:
>
>CC   /tmp/build/perf/util/string.o
>  util/string.c: In function 'perf_atoll':
>  util/string.c:22:7: error: this statement may fall through 
> [-Werror=implicit-fallthrough=]
>  if (*p)
> ^
>  util/string.c:24:3: note: here
> case '\0':
> ^~~~
>
>So we introduce:
>
>  #define __fallthrough __attribute__ ((fallthrough))
>
>And use it in such cases.

Queued up, thanks!

-- 

Thanks,
Sasha

Re: [PATCH stable-4.1.y] tools include: Add a __fallthrough statement

2017-10-29 Thread Levin, Alexander (Sasha Levin)
On Fri, Oct 27, 2017 at 12:05:58PM -0700, Florian Fainelli wrote:
>From: Arnaldo Carvalho de Melo 
>
>commit b5bf1733d6a391c4e90ea8f8468d83023be74a2a upstream.
>
>For cases where implicit fall through case labels are intended,
>to let us inform that to gcc >= 7:
>
>CC   /tmp/build/perf/util/string.o
>  util/string.c: In function 'perf_atoll':
>  util/string.c:22:7: error: this statement may fall through 
> [-Werror=implicit-fallthrough=]
>  if (*p)
> ^
>  util/string.c:24:3: note: here
> case '\0':
> ^~~~
>
>So we introduce:
>
>  #define __fallthrough __attribute__ ((fallthrough))
>
>And use it in such cases.

Queued up, thanks!

-- 

Thanks,
Sasha

[PATCH] HID: i2c-hid: add reset gpio property

2017-10-29 Thread Lin Huang
some i2c hid devices have reset gpio, need to control
it in the driver.

Change-Id: I87bca954bffc7eb7b35711406f522cb3d0fc2ded
Signed-off-by: Lin Huang 
---
 drivers/hid/i2c-hid/i2c-hid.c | 63 +++
 include/linux/platform_data/i2c-hid.h |  4 +++
 2 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 9145c21..a0e3a8e 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -793,6 +794,34 @@ struct hid_ll_driver i2c_hid_ll_driver = {
 };
 EXPORT_SYMBOL_GPL(i2c_hid_ll_driver);
 
+static int i2c_hid_hw_power_on(struct i2c_hid *ihid)
+{
+   int ret;
+
+   ret = regulator_enable(ihid->pdata.supply);
+   if (ret < 0)
+   return ret;
+
+   if (ihid->pdata.post_power_delay_ms)
+   msleep(ihid->pdata.post_power_delay_ms);
+
+   gpiod_set_value_cansleep(ihid->pdata.reset_gpio, 1);
+   usleep_range(ihid->pdata.assert_reset_us,
+ihid->pdata.assert_reset_us);
+   gpiod_set_value_cansleep(ihid->pdata.reset_gpio, 0);
+   usleep_range(ihid->pdata.deassert_reset_us,
+ihid->pdata.deassert_reset_us);
+
+   return ret;
+}
+
+static int i2c_hid_hw_power_off(struct i2c_hid *ihid)
+{
+   gpiod_set_value_cansleep(ihid->pdata.reset_gpio, 1);
+
+   return regulator_disable(ihid->pdata.supply);
+}
+
 static int i2c_hid_init_irq(struct i2c_client *client)
 {
struct i2c_hid *ihid = i2c_get_clientdata(client);
@@ -934,6 +963,12 @@ static int i2c_hid_of_probe(struct i2c_client *client,
if (!ret)
pdata->post_power_delay_ms = val;
 
+   ret = of_property_read_u32(dev->of_node, "assert-reset-us",
+  >assert_reset_us);
+
+   ret = of_property_read_u32(dev->of_node, "deassert-reset-us",
+  >deassert_reset_us);
+
return 0;
 }
 
@@ -1002,14 +1037,16 @@ static int i2c_hid_probe(struct i2c_client *client,
goto err;
}
 
-   ret = regulator_enable(ihid->pdata.supply);
+   ihid->pdata.reset_gpio = devm_gpiod_get_optional(>dev, "reset",
+GPIOD_OUT_HIGH);
+   if (IS_ERR(ihid->pdata.reset_gpio))
+   goto err;
+
+   ret = i2c_hid_hw_power_on(ihid);
if (ret < 0) {
-   dev_err(>dev, "Failed to enable regulator: %d\n",
-   ret);
+   dev_err(>dev, "Failed to power on: %d\n", ret);
goto err;
}
-   if (ihid->pdata.post_power_delay_ms)
-   msleep(ihid->pdata.post_power_delay_ms);
 
i2c_set_clientdata(client, ihid);
 
@@ -1086,7 +1123,7 @@ static int i2c_hid_probe(struct i2c_client *client,
pm_runtime_disable(>dev);
 
 err_regulator:
-   regulator_disable(ihid->pdata.supply);
+   i2c_hid_hw_power_off(ihid);
 
 err:
i2c_hid_free_buffers(ihid);
@@ -1112,8 +1149,7 @@ static int i2c_hid_remove(struct i2c_client *client)
if (ihid->bufsize)
i2c_hid_free_buffers(ihid);
 
-   regulator_disable(ihid->pdata.supply);
-
+   i2c_hid_hw_power_off(ihid);
kfree(ihid);
 
return 0;
@@ -1165,9 +1201,10 @@ static int i2c_hid_suspend(struct device *dev)
hid_warn(hid, "Failed to enable irq wake: %d\n",
wake_status);
} else {
-   ret = regulator_disable(ihid->pdata.supply);
+   ret = i2c_hid_hw_power_off(ihid);
if (ret < 0)
-   hid_warn(hid, "Failed to disable supply: %d\n", ret);
+   hid_warn(hid, "Failed to disable hw power: %d\n",
+ret);
}
 
return 0;
@@ -1182,11 +1219,9 @@ static int i2c_hid_resume(struct device *dev)
int wake_status;
 
if (!device_may_wakeup(>dev)) {
-   ret = regulator_enable(ihid->pdata.supply);
+   ret = i2c_hid_hw_power_on(ihid);
if (ret < 0)
-   hid_warn(hid, "Failed to enable supply: %d\n", ret);
-   if (ihid->pdata.post_power_delay_ms)
-   msleep(ihid->pdata.post_power_delay_ms);
+   hid_warn(hid, "Failed to enable hw power: %d\n", ret);
} else if (ihid->irq_wake_enabled) {
wake_status = disable_irq_wake(client->irq);
if (!wake_status)
diff --git a/include/linux/platform_data/i2c-hid.h 
b/include/linux/platform_data/i2c-hid.h
index 1fb0882..3afc781 100644
--- a/include/linux/platform_data/i2c-hid.h
+++ b/include/linux/platform_data/i2c-hid.h
@@ -14,6 +14,7 @@
 
 #include 
 
+struct gpio_desc;
 struct regulator;
 
 /**
@@ -37,6 +38,9 @@ struct i2c_hid_platform_data {
 

[PATCH] HID: i2c-hid: add reset gpio property

2017-10-29 Thread Lin Huang
some i2c hid devices have reset gpio, need to control
it in the driver.

Change-Id: I87bca954bffc7eb7b35711406f522cb3d0fc2ded
Signed-off-by: Lin Huang 
---
 drivers/hid/i2c-hid/i2c-hid.c | 63 +++
 include/linux/platform_data/i2c-hid.h |  4 +++
 2 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 9145c21..a0e3a8e 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -793,6 +794,34 @@ struct hid_ll_driver i2c_hid_ll_driver = {
 };
 EXPORT_SYMBOL_GPL(i2c_hid_ll_driver);
 
+static int i2c_hid_hw_power_on(struct i2c_hid *ihid)
+{
+   int ret;
+
+   ret = regulator_enable(ihid->pdata.supply);
+   if (ret < 0)
+   return ret;
+
+   if (ihid->pdata.post_power_delay_ms)
+   msleep(ihid->pdata.post_power_delay_ms);
+
+   gpiod_set_value_cansleep(ihid->pdata.reset_gpio, 1);
+   usleep_range(ihid->pdata.assert_reset_us,
+ihid->pdata.assert_reset_us);
+   gpiod_set_value_cansleep(ihid->pdata.reset_gpio, 0);
+   usleep_range(ihid->pdata.deassert_reset_us,
+ihid->pdata.deassert_reset_us);
+
+   return ret;
+}
+
+static int i2c_hid_hw_power_off(struct i2c_hid *ihid)
+{
+   gpiod_set_value_cansleep(ihid->pdata.reset_gpio, 1);
+
+   return regulator_disable(ihid->pdata.supply);
+}
+
 static int i2c_hid_init_irq(struct i2c_client *client)
 {
struct i2c_hid *ihid = i2c_get_clientdata(client);
@@ -934,6 +963,12 @@ static int i2c_hid_of_probe(struct i2c_client *client,
if (!ret)
pdata->post_power_delay_ms = val;
 
+   ret = of_property_read_u32(dev->of_node, "assert-reset-us",
+  >assert_reset_us);
+
+   ret = of_property_read_u32(dev->of_node, "deassert-reset-us",
+  >deassert_reset_us);
+
return 0;
 }
 
@@ -1002,14 +1037,16 @@ static int i2c_hid_probe(struct i2c_client *client,
goto err;
}
 
-   ret = regulator_enable(ihid->pdata.supply);
+   ihid->pdata.reset_gpio = devm_gpiod_get_optional(>dev, "reset",
+GPIOD_OUT_HIGH);
+   if (IS_ERR(ihid->pdata.reset_gpio))
+   goto err;
+
+   ret = i2c_hid_hw_power_on(ihid);
if (ret < 0) {
-   dev_err(>dev, "Failed to enable regulator: %d\n",
-   ret);
+   dev_err(>dev, "Failed to power on: %d\n", ret);
goto err;
}
-   if (ihid->pdata.post_power_delay_ms)
-   msleep(ihid->pdata.post_power_delay_ms);
 
i2c_set_clientdata(client, ihid);
 
@@ -1086,7 +1123,7 @@ static int i2c_hid_probe(struct i2c_client *client,
pm_runtime_disable(>dev);
 
 err_regulator:
-   regulator_disable(ihid->pdata.supply);
+   i2c_hid_hw_power_off(ihid);
 
 err:
i2c_hid_free_buffers(ihid);
@@ -1112,8 +1149,7 @@ static int i2c_hid_remove(struct i2c_client *client)
if (ihid->bufsize)
i2c_hid_free_buffers(ihid);
 
-   regulator_disable(ihid->pdata.supply);
-
+   i2c_hid_hw_power_off(ihid);
kfree(ihid);
 
return 0;
@@ -1165,9 +1201,10 @@ static int i2c_hid_suspend(struct device *dev)
hid_warn(hid, "Failed to enable irq wake: %d\n",
wake_status);
} else {
-   ret = regulator_disable(ihid->pdata.supply);
+   ret = i2c_hid_hw_power_off(ihid);
if (ret < 0)
-   hid_warn(hid, "Failed to disable supply: %d\n", ret);
+   hid_warn(hid, "Failed to disable hw power: %d\n",
+ret);
}
 
return 0;
@@ -1182,11 +1219,9 @@ static int i2c_hid_resume(struct device *dev)
int wake_status;
 
if (!device_may_wakeup(>dev)) {
-   ret = regulator_enable(ihid->pdata.supply);
+   ret = i2c_hid_hw_power_on(ihid);
if (ret < 0)
-   hid_warn(hid, "Failed to enable supply: %d\n", ret);
-   if (ihid->pdata.post_power_delay_ms)
-   msleep(ihid->pdata.post_power_delay_ms);
+   hid_warn(hid, "Failed to enable hw power: %d\n", ret);
} else if (ihid->irq_wake_enabled) {
wake_status = disable_irq_wake(client->irq);
if (!wake_status)
diff --git a/include/linux/platform_data/i2c-hid.h 
b/include/linux/platform_data/i2c-hid.h
index 1fb0882..3afc781 100644
--- a/include/linux/platform_data/i2c-hid.h
+++ b/include/linux/platform_data/i2c-hid.h
@@ -14,6 +14,7 @@
 
 #include 
 
+struct gpio_desc;
 struct regulator;
 
 /**
@@ -37,6 +38,9 @@ struct i2c_hid_platform_data {
u16 

Re: [PATCH v6 5/9] KVM: arm/arm64: vgic-its: Remove kvm_its_unmap_device

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:07 pm BST, Eric Auger  
wrote:
> Let's remove kvm_its_unmap_device and use kvm_its_free_device
> as both functions are identical.
>
> Signed-off-by: Eric Auger 
> Acked-by: Christoffer Dall 

Acked-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny.


Re: [PATCH v6 5/9] KVM: arm/arm64: vgic-its: Remove kvm_its_unmap_device

2017-10-29 Thread Marc Zyngier
On Thu, Oct 26 2017 at  6:23:07 pm BST, Eric Auger  
wrote:
> Let's remove kvm_its_unmap_device and use kvm_its_free_device
> as both functions are identical.
>
> Signed-off-by: Eric Auger 
> Acked-by: Christoffer Dall 

Acked-by: Marc Zyngier 

M.
-- 
Jazz is not dead. It just smells funny.


[PATCH V1] regulator: da9211: update for supporting da9223/4/5

2017-10-29 Thread James Bans

From: James Ban 

This is update for supporting additional devices da9223/4/5.
Only device strings is added because only package type is different.

Signed-off-by: James Ban 

---
This patch applies against linux-next and next-20171018 


 .../devicetree/bindings/regulator/da9211.txt   |   82 ++--
 drivers/regulator/Kconfig  |2 +-
 drivers/regulator/da9211-regulator.c   |   14 +++-
 drivers/regulator/da9211-regulator.h   |2 +-
 include/linux/regulator/da9211.h   |5 +-
 5 files changed, 91 insertions(+), 14 deletions(-)

diff --git a/Documentation/devicetree/bindings/regulator/da9211.txt 
b/Documentation/devicetree/bindings/regulator/da9211.txt
index 0f2a6f8..27717e8 100644
--- a/Documentation/devicetree/bindings/regulator/da9211.txt
+++ b/Documentation/devicetree/bindings/regulator/da9211.txt
@@ -1,8 +1,9 @@
-* Dialog Semiconductor DA9211/DA9212/DA9213/DA9214/DA9215 Voltage Regulator
+* Dialog Semiconductor DA9211/DA9212/DA9213/DA9223/DA9214/DA9224/DA9215/DA9225
+ Voltage Regulator
 
 Required properties:
-- compatible: "dlg,da9211" or "dlg,da9212" or "dlg,da9213"
-  or "dlg,da9214" or "dlg,da9215"
+- compatible: "dlg,da9211" or "dlg,da9212" or "dlg,da9213" or "dlg,da9223"
+  or "dlg,da9214" or "dlg,da9224" or "dlg,da9215" or "dlg,da9225"
 - reg: I2C slave address, usually 0x68.
 - interrupts: the interrupt outputs of the controller
 - regulators: A node that houses a sub-node for each regulator within the
@@ -16,7 +17,6 @@ Optional properties:
 - Any optional property defined in regulator.txt
 
 Example 1) DA9211
-
pmic: da9211@68 {
compatible = "dlg,da9211";
reg = <0x68>;
@@ -35,7 +35,6 @@ Example 1) DA9211
};
 
 Example 2) DA9212
-
pmic: da9212@68 {
compatible = "dlg,da9212";
reg = <0x68>;
@@ -79,7 +78,25 @@ Example 3) DA9213
};
};
 
-Example 4) DA9214
+Example 4) DA9223
+   pmic: da9223@68 {
+   compatible = "dlg,da9223";
+   reg = <0x68>;
+   interrupts = <3 27>;
+
+   regulators {
+   BUCKA {
+   regulator-name = "VBUCKA";
+   regulator-min-microvolt = < 30>;
+   regulator-max-microvolt = <157>;
+   regulator-min-microamp  = <300>;
+   regulator-max-microamp  = <600>;
+   enable-gpios = < 27 0>;
+   };
+   };
+   };
+
+Example 5) DA9214
pmic: da9214@68 {
compatible = "dlg,da9214";
reg = <0x68>;
@@ -105,7 +122,33 @@ Example 4) DA9214
};
};
 
-Example 5) DA9215
+Example 6) DA9224
+   pmic: da9224@68 {
+   compatible = "dlg,da9224";
+   reg = <0x68>;
+   interrupts = <3 27>;
+
+   regulators {
+   BUCKA {
+   regulator-name = "VBUCKA";
+   regulator-min-microvolt = < 30>;
+   regulator-max-microvolt = <157>;
+   regulator-min-microamp  = <300>;
+   regulator-max-microamp  = <600>;
+   enable-gpios = < 27 0>;
+   };
+   BUCKB {
+   regulator-name = "VBUCKB";
+   regulator-min-microvolt = < 30>;
+   regulator-max-microvolt = <157>;
+   regulator-min-microamp  = <300>;
+   regulator-max-microamp  = <600>;
+   enable-gpios = < 17 0>;
+   };
+   };
+   };
+
+Example 7) DA9215
pmic: da9215@68 {
compatible = "dlg,da9215";
reg = <0x68>;
@@ -131,3 +174,28 @@ Example 5) DA9215
};
};
 
+Example 8) DA9225
+   pmic: da9225@68 {
+   compatible = "dlg,da9225";
+   reg = <0x68>;
+   interrupts = <3 27>;
+
+   regulators {
+   BUCKA {
+   regulator-name = "VBUCKA";
+   regulator-min-microvolt = < 30>;
+   regulator-max-microvolt = <157>;
+   regulator-min-microamp  = <400>;
+   regulator-max-microamp  = <700>;
+   enable-gpios = < 27 0>;
+   };
+   BUCKB {
+   regulator-name = "VBUCKB";
+

[PATCH V1] regulator: da9211: update for supporting da9223/4/5

2017-10-29 Thread James Bans

From: James Ban 

This is update for supporting additional devices da9223/4/5.
Only device strings is added because only package type is different.

Signed-off-by: James Ban 

---
This patch applies against linux-next and next-20171018 


 .../devicetree/bindings/regulator/da9211.txt   |   82 ++--
 drivers/regulator/Kconfig  |2 +-
 drivers/regulator/da9211-regulator.c   |   14 +++-
 drivers/regulator/da9211-regulator.h   |2 +-
 include/linux/regulator/da9211.h   |5 +-
 5 files changed, 91 insertions(+), 14 deletions(-)

diff --git a/Documentation/devicetree/bindings/regulator/da9211.txt 
b/Documentation/devicetree/bindings/regulator/da9211.txt
index 0f2a6f8..27717e8 100644
--- a/Documentation/devicetree/bindings/regulator/da9211.txt
+++ b/Documentation/devicetree/bindings/regulator/da9211.txt
@@ -1,8 +1,9 @@
-* Dialog Semiconductor DA9211/DA9212/DA9213/DA9214/DA9215 Voltage Regulator
+* Dialog Semiconductor DA9211/DA9212/DA9213/DA9223/DA9214/DA9224/DA9215/DA9225
+ Voltage Regulator
 
 Required properties:
-- compatible: "dlg,da9211" or "dlg,da9212" or "dlg,da9213"
-  or "dlg,da9214" or "dlg,da9215"
+- compatible: "dlg,da9211" or "dlg,da9212" or "dlg,da9213" or "dlg,da9223"
+  or "dlg,da9214" or "dlg,da9224" or "dlg,da9215" or "dlg,da9225"
 - reg: I2C slave address, usually 0x68.
 - interrupts: the interrupt outputs of the controller
 - regulators: A node that houses a sub-node for each regulator within the
@@ -16,7 +17,6 @@ Optional properties:
 - Any optional property defined in regulator.txt
 
 Example 1) DA9211
-
pmic: da9211@68 {
compatible = "dlg,da9211";
reg = <0x68>;
@@ -35,7 +35,6 @@ Example 1) DA9211
};
 
 Example 2) DA9212
-
pmic: da9212@68 {
compatible = "dlg,da9212";
reg = <0x68>;
@@ -79,7 +78,25 @@ Example 3) DA9213
};
};
 
-Example 4) DA9214
+Example 4) DA9223
+   pmic: da9223@68 {
+   compatible = "dlg,da9223";
+   reg = <0x68>;
+   interrupts = <3 27>;
+
+   regulators {
+   BUCKA {
+   regulator-name = "VBUCKA";
+   regulator-min-microvolt = < 30>;
+   regulator-max-microvolt = <157>;
+   regulator-min-microamp  = <300>;
+   regulator-max-microamp  = <600>;
+   enable-gpios = < 27 0>;
+   };
+   };
+   };
+
+Example 5) DA9214
pmic: da9214@68 {
compatible = "dlg,da9214";
reg = <0x68>;
@@ -105,7 +122,33 @@ Example 4) DA9214
};
};
 
-Example 5) DA9215
+Example 6) DA9224
+   pmic: da9224@68 {
+   compatible = "dlg,da9224";
+   reg = <0x68>;
+   interrupts = <3 27>;
+
+   regulators {
+   BUCKA {
+   regulator-name = "VBUCKA";
+   regulator-min-microvolt = < 30>;
+   regulator-max-microvolt = <157>;
+   regulator-min-microamp  = <300>;
+   regulator-max-microamp  = <600>;
+   enable-gpios = < 27 0>;
+   };
+   BUCKB {
+   regulator-name = "VBUCKB";
+   regulator-min-microvolt = < 30>;
+   regulator-max-microvolt = <157>;
+   regulator-min-microamp  = <300>;
+   regulator-max-microamp  = <600>;
+   enable-gpios = < 17 0>;
+   };
+   };
+   };
+
+Example 7) DA9215
pmic: da9215@68 {
compatible = "dlg,da9215";
reg = <0x68>;
@@ -131,3 +174,28 @@ Example 5) DA9215
};
};
 
+Example 8) DA9225
+   pmic: da9225@68 {
+   compatible = "dlg,da9225";
+   reg = <0x68>;
+   interrupts = <3 27>;
+
+   regulators {
+   BUCKA {
+   regulator-name = "VBUCKA";
+   regulator-min-microvolt = < 30>;
+   regulator-max-microvolt = <157>;
+   regulator-min-microamp  = <400>;
+   regulator-max-microamp  = <700>;
+   enable-gpios = < 27 0>;
+   };
+   BUCKB {
+   regulator-name = "VBUCKB";
+   regulator-min-microvolt = < 30>;
+

Re: [PATCH v4 05/13] irqchip: add initial support for ompic

2017-10-29 Thread Marc Zyngier
On Mon, Oct 30 2017 at  8:11:15 am GMT, Stafford Horne  wrote:
> From: Stefan Kristiansson 
>
> IPI driver for the Open Multi-Processor Interrupt Controller (ompic) as
> described in the Multi-core support section of the OpenRISC 1.2
> architecture specification:
>
>   https://github.com/openrisc/doc/raw/master/openrisc-arch-1.2-rev0.pdf
>
> Each OpenRISC core contains a full interrupt controller which is used in
> the SMP architecture for interrupt balancing.  This IPI device, the
> ompic, is the only external device required for enabling SMP on
> OpenRISC.
>
> Pending ops are stored in a memory bit mask which can allow multiple
> pending operations to be set and serviced at a time. This is mostly
> borrowed from the alpha IPI implementation.
>
> Cc: Marc Zyngier 
> Acked-by: Rob Herring 
> Signed-off-by: Stefan Kristiansson 
> [sho...@gmail.com: converted ops to bitmask, wrote commit message]
> Signed-off-by: Stafford Horne 

Reviewed-by: Marc Zyngier 

Side question: what is your merge strategy for this? I can take it
through the irqchip tree as it is standalone, but I'm open to other
suggestions.

Thanks,

M.
-- 
Jazz is not dead. It just smells funny.


Re: [PATCH v4 05/13] irqchip: add initial support for ompic

2017-10-29 Thread Marc Zyngier
On Mon, Oct 30 2017 at  8:11:15 am GMT, Stafford Horne  wrote:
> From: Stefan Kristiansson 
>
> IPI driver for the Open Multi-Processor Interrupt Controller (ompic) as
> described in the Multi-core support section of the OpenRISC 1.2
> architecture specification:
>
>   https://github.com/openrisc/doc/raw/master/openrisc-arch-1.2-rev0.pdf
>
> Each OpenRISC core contains a full interrupt controller which is used in
> the SMP architecture for interrupt balancing.  This IPI device, the
> ompic, is the only external device required for enabling SMP on
> OpenRISC.
>
> Pending ops are stored in a memory bit mask which can allow multiple
> pending operations to be set and serviced at a time. This is mostly
> borrowed from the alpha IPI implementation.
>
> Cc: Marc Zyngier 
> Acked-by: Rob Herring 
> Signed-off-by: Stefan Kristiansson 
> [sho...@gmail.com: converted ops to bitmask, wrote commit message]
> Signed-off-by: Stafford Horne 

Reviewed-by: Marc Zyngier 

Side question: what is your merge strategy for this? I can take it
through the irqchip tree as it is standalone, but I'm open to other
suggestions.

Thanks,

M.
-- 
Jazz is not dead. It just smells funny.


Re: [RFC PATCH v10 0/7] PCI: rockchip: Move PCIe WAKE# handling into pci core

2017-10-29 Thread jeffy

Hi Rafael,

thanks for your reply.

On 10/28/2017 05:07 PM, Rafael J. Wysocki wrote:

Overall, I don't quite like the direction this is going into, but I need to
have a deeper look.  Which may take some time, so please bear with me.


ok, i'll wait for your comments, thanks :)


Thanks,
Rafael





Re: [RFC PATCH v10 0/7] PCI: rockchip: Move PCIe WAKE# handling into pci core

2017-10-29 Thread jeffy

Hi Rafael,

thanks for your reply.

On 10/28/2017 05:07 PM, Rafael J. Wysocki wrote:

Overall, I don't quite like the direction this is going into, but I need to
have a deeper look.  Which may take some time, so please bear with me.


ok, i'll wait for your comments, thanks :)


Thanks,
Rafael





[PATCH] irqdomain: Update the comments of fwnode field of irq_domain structure

2017-10-29 Thread Dou Liyang
Commit:

f110711a6053 ("irqdomain: Convert irqdomain-%3Eof_node to fwnode")

converted of_node field to fwnode, but didn't update its comments.

Update it.

Signed-off-by: Dou Liyang 
---
 include/linux/irqdomain.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index df162f7..ce48a23 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -138,8 +138,8 @@ struct irq_domain_chip_generic;
  * @mapcount: The number of mapped interrupts
  *
  * Optional elements
- * @of_node: Pointer to device tree nodes associated with the irq_domain. Used
- *   when decoding device tree interrupt specifiers.
+ * @fwnode: Pointer to firmware node associated with the irq_domain. Pretty 
easy
+ *  to swap it for the of_node via the irq_domain_get_of_node accessor
  * @gc: Pointer to a list of generic chips. There is a helper function for
  *  setting up one or more generic chips for interrupt controllers
  *  drivers using the generic chip library which uses this pointer.
-- 
2.5.5





[PATCH] irqdomain: Update the comments of fwnode field of irq_domain structure

2017-10-29 Thread Dou Liyang
Commit:

f110711a6053 ("irqdomain: Convert irqdomain-%3Eof_node to fwnode")

converted of_node field to fwnode, but didn't update its comments.

Update it.

Signed-off-by: Dou Liyang 
---
 include/linux/irqdomain.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index df162f7..ce48a23 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -138,8 +138,8 @@ struct irq_domain_chip_generic;
  * @mapcount: The number of mapped interrupts
  *
  * Optional elements
- * @of_node: Pointer to device tree nodes associated with the irq_domain. Used
- *   when decoding device tree interrupt specifiers.
+ * @fwnode: Pointer to firmware node associated with the irq_domain. Pretty 
easy
+ *  to swap it for the of_node via the irq_domain_get_of_node accessor
  * @gc: Pointer to a list of generic chips. There is a helper function for
  *  setting up one or more generic chips for interrupt controllers
  *  drivers using the generic chip library which uses this pointer.
-- 
2.5.5





Re: [RFC PATCH v8 4/7] of/irq: Adjust of pci irq parsing for multiple interrupts

2017-10-29 Thread jeffy

Hi Rob,

On 10/27/2017 10:38 PM, Rob Herring wrote:

+   prop = of_find_property(dn, "interrupt-names", NULL);
>+   for (name = of_prop_next_string(prop, NULL); name;
>+name = of_prop_next_string(prop, name), index++) {
>+   if (!strcmp(name, "pci"))
>+   break;

Use of_property_match_string

i'm trying to find the first unnamed or "pci" named irq in the string 
array, so cannot use that API:)


but will change to of_property_for_each_string as Brian suggested.



Re: [RFC PATCH v8 4/7] of/irq: Adjust of pci irq parsing for multiple interrupts

2017-10-29 Thread jeffy

Hi Rob,

On 10/27/2017 10:38 PM, Rob Herring wrote:

+   prop = of_find_property(dn, "interrupt-names", NULL);
>+   for (name = of_prop_next_string(prop, NULL); name;
>+name = of_prop_next_string(prop, name), index++) {
>+   if (!strcmp(name, "pci"))
>+   break;

Use of_property_match_string

i'm trying to find the first unnamed or "pci" named irq in the string 
array, so cannot use that API:)


but will change to of_property_for_each_string as Brian suggested.



Re: [PATCH v3 00/13] dax: fix dma vs truncate and remove 'page-less' support

2017-10-29 Thread Dave Chinner
On Sun, Oct 29, 2017 at 04:46:44PM -0700, Dan Williams wrote:
> On Thu, Oct 26, 2017 at 3:58 AM, Jan Kara  wrote:
> > On Fri 20-10-17 11:31:48, Christoph Hellwig wrote:
> >> On Fri, Oct 20, 2017 at 09:47:50AM +0200, Christoph Hellwig wrote:
> >> > I'd like to brainstorm how we can do something better.
> >> >
> >> > How about:
> >> >
> >> > If we hit a page with an elevated refcount in truncate / hole puch
> >> > etc for a DAX file system we do not free the blocks in the file system,
> >> > but add it to the extent busy list.  We mark the page as delayed
> >> > free (e.g. page flag?) so that when it finally hits refcount zero we
> >> > call back into the file system to remove it from the busy list.
> >>
> >> Brainstorming some more:
> >>
> >> Given that on a DAX file there shouldn't be any long-term page
> >> references after we unmap it from the page table and don't allow
> >> get_user_pages calls why not wait for the references for all
> >> DAX pages to go away first?  E.g. if we find a DAX page in
> >> truncate_inode_pages_range that has an elevated refcount we set
> >> a new flag to prevent new references from showing up, and then
> >> simply wait for it to go away.  Instead of a busy way we can
> >> do this through a few hashed waitqueued in dev_pagemap.  And in
> >> fact put_zone_device_page already gets called when putting the
> >> last page so we can handle the wakeup from there.
> >>
> >> In fact if we can't find a page flag for the stop new callers
> >> things we could probably come up with a way to do that through
> >> dev_pagemap somehow, but I'm not sure how efficient that would
> >> be.
> >
> > We were talking about this yesterday with Dan so some more brainstorming
> > from us. We can implement the solution with extent busy list in ext4
> > relatively easily - we already have such list currently similarly to XFS.
> > There would be some modifications needed but nothing too complex. The
> > biggest downside of this solution I see is that it requires per-filesystem
> > solution for busy extents - ext4 and XFS are reasonably fine, however btrfs
> > may have problems and ext2 definitely will need some modifications.
> > Invisible used blocks may be surprising to users at times although given
> > page refs should be relatively short term, that should not be a big issue.
> > But are we guaranteed page refs are short term? E.g. if someone creates
> > v4l2 videobuf in MAP_SHARED mapping of a file on DAX filesystem, page refs
> > can be rather long-term similarly as in RDMA case. Also freeing of blocks
> > on page reference drop is another async entry point into the filesystem
> > which could unpleasantly surprise us but I guess workqueues would solve
> > that reasonably fine.
> >
> > WRT waiting for page refs to be dropped before proceeding with truncate (or
> > punch hole for that matter - that case is even nastier since we don't have
> > i_size to guard us). What I like about this solution is that it is very
> > visible there's something unusual going on with the file being truncated /
> > punched and so problems are easier to diagnose / fix from the admin side.
> > So far we have guarded hole punching from concurrent faults (and
> > get_user_pages() does fault once you do unmap_mapping_range()) with
> > I_MMAP_LOCK (or its equivalent in ext4). We cannot easily wait for page
> > refs to be dropped under I_MMAP_LOCK as that could deadlock - the most
> > obvious case Dan came up with is when GUP obtains ref to page A, then hole
> > punch comes grabbing I_MMAP_LOCK and waiting for page ref on A to be
> > dropped, and then GUP blocks on trying to fault in another page.
> >
> > I think we cannot easily prevent new page references to be grabbed as you
> > write above since nobody expects stuff like get_page() to fail. But I
> > think that unmapping relevant pages and then preventing them to be faulted
> > in again is workable and stops GUP as well. The problem with that is though
> > what to do with page faults to such pages - you cannot just fail them for
> > hole punch, and you cannot easily allocate new blocks either. So we are
> > back at a situation where we need to detach blocks from the inode and then
> > wait for page refs to be dropped - so some form of busy extents. Am I
> > missing something?
> 
> Coming back to this since Dave has made clear that new locking to
> coordinate get_user_pages() is a no-go.
> 
> We can unmap to force new get_user_pages() attempts to block on the
> per-fs mmap lock, but if punch-hole finds any elevated pages it needs
> to drop the mmap lock and wait. We need this lock dropped to get
> around the problem that the driver will not start to drop page
> references until it has elevated the page references on all the pages
> in the I/O. If we need to drop the mmap lock that makes it impossible
> to coordinate this unlock/retry loop within truncate_inode_pages_range
> which would otherwise be the natural place to land this code.
> 
> Would it be palatable 

Re: [PATCH v3 00/13] dax: fix dma vs truncate and remove 'page-less' support

2017-10-29 Thread Dave Chinner
On Sun, Oct 29, 2017 at 04:46:44PM -0700, Dan Williams wrote:
> On Thu, Oct 26, 2017 at 3:58 AM, Jan Kara  wrote:
> > On Fri 20-10-17 11:31:48, Christoph Hellwig wrote:
> >> On Fri, Oct 20, 2017 at 09:47:50AM +0200, Christoph Hellwig wrote:
> >> > I'd like to brainstorm how we can do something better.
> >> >
> >> > How about:
> >> >
> >> > If we hit a page with an elevated refcount in truncate / hole puch
> >> > etc for a DAX file system we do not free the blocks in the file system,
> >> > but add it to the extent busy list.  We mark the page as delayed
> >> > free (e.g. page flag?) so that when it finally hits refcount zero we
> >> > call back into the file system to remove it from the busy list.
> >>
> >> Brainstorming some more:
> >>
> >> Given that on a DAX file there shouldn't be any long-term page
> >> references after we unmap it from the page table and don't allow
> >> get_user_pages calls why not wait for the references for all
> >> DAX pages to go away first?  E.g. if we find a DAX page in
> >> truncate_inode_pages_range that has an elevated refcount we set
> >> a new flag to prevent new references from showing up, and then
> >> simply wait for it to go away.  Instead of a busy way we can
> >> do this through a few hashed waitqueued in dev_pagemap.  And in
> >> fact put_zone_device_page already gets called when putting the
> >> last page so we can handle the wakeup from there.
> >>
> >> In fact if we can't find a page flag for the stop new callers
> >> things we could probably come up with a way to do that through
> >> dev_pagemap somehow, but I'm not sure how efficient that would
> >> be.
> >
> > We were talking about this yesterday with Dan so some more brainstorming
> > from us. We can implement the solution with extent busy list in ext4
> > relatively easily - we already have such list currently similarly to XFS.
> > There would be some modifications needed but nothing too complex. The
> > biggest downside of this solution I see is that it requires per-filesystem
> > solution for busy extents - ext4 and XFS are reasonably fine, however btrfs
> > may have problems and ext2 definitely will need some modifications.
> > Invisible used blocks may be surprising to users at times although given
> > page refs should be relatively short term, that should not be a big issue.
> > But are we guaranteed page refs are short term? E.g. if someone creates
> > v4l2 videobuf in MAP_SHARED mapping of a file on DAX filesystem, page refs
> > can be rather long-term similarly as in RDMA case. Also freeing of blocks
> > on page reference drop is another async entry point into the filesystem
> > which could unpleasantly surprise us but I guess workqueues would solve
> > that reasonably fine.
> >
> > WRT waiting for page refs to be dropped before proceeding with truncate (or
> > punch hole for that matter - that case is even nastier since we don't have
> > i_size to guard us). What I like about this solution is that it is very
> > visible there's something unusual going on with the file being truncated /
> > punched and so problems are easier to diagnose / fix from the admin side.
> > So far we have guarded hole punching from concurrent faults (and
> > get_user_pages() does fault once you do unmap_mapping_range()) with
> > I_MMAP_LOCK (or its equivalent in ext4). We cannot easily wait for page
> > refs to be dropped under I_MMAP_LOCK as that could deadlock - the most
> > obvious case Dan came up with is when GUP obtains ref to page A, then hole
> > punch comes grabbing I_MMAP_LOCK and waiting for page ref on A to be
> > dropped, and then GUP blocks on trying to fault in another page.
> >
> > I think we cannot easily prevent new page references to be grabbed as you
> > write above since nobody expects stuff like get_page() to fail. But I
> > think that unmapping relevant pages and then preventing them to be faulted
> > in again is workable and stops GUP as well. The problem with that is though
> > what to do with page faults to such pages - you cannot just fail them for
> > hole punch, and you cannot easily allocate new blocks either. So we are
> > back at a situation where we need to detach blocks from the inode and then
> > wait for page refs to be dropped - so some form of busy extents. Am I
> > missing something?
> 
> Coming back to this since Dave has made clear that new locking to
> coordinate get_user_pages() is a no-go.
> 
> We can unmap to force new get_user_pages() attempts to block on the
> per-fs mmap lock, but if punch-hole finds any elevated pages it needs
> to drop the mmap lock and wait. We need this lock dropped to get
> around the problem that the driver will not start to drop page
> references until it has elevated the page references on all the pages
> in the I/O. If we need to drop the mmap lock that makes it impossible
> to coordinate this unlock/retry loop within truncate_inode_pages_range
> which would otherwise be the natural place to land this code.
> 
> Would it be palatable to unmap and 

[PATCH v3 3/3] MAINTAINERS: Add a new entry of the ov7740 driver

2017-10-29 Thread Wenyou Yang
Add a new entry of the ov7740 sensor driver to the MAINTAINERS file.

Signed-off-by: Wenyou Yang 
---

Changes in v3:
 - Put the MAINTAINERS change to a separate patch.

Changes in v2:
 - Split off the bindings into a separate patch.
 - Add a new entry to the MAINTAINERS file.

 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index adbf69306e9e..42b93599a0af 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9973,6 +9973,14 @@ S:   Maintained
 F: drivers/media/i2c/ov7670.c
 F: Documentation/devicetree/bindings/media/i2c/ov7670.txt
 
+OMNIVISION OV7740 SENSOR DRIVER
+M: Wenyou Yang 
+L: linux-me...@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ov7740.c
+F: Documentation/devicetree/bindings/media/i2c/ov7740.txt
+
 ONENAND FLASH DRIVER
 M: Kyungmin Park 
 L: linux-...@lists.infradead.org
-- 
2.13.0



[PATCH v3 3/3] MAINTAINERS: Add a new entry of the ov7740 driver

2017-10-29 Thread Wenyou Yang
Add a new entry of the ov7740 sensor driver to the MAINTAINERS file.

Signed-off-by: Wenyou Yang 
---

Changes in v3:
 - Put the MAINTAINERS change to a separate patch.

Changes in v2:
 - Split off the bindings into a separate patch.
 - Add a new entry to the MAINTAINERS file.

 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index adbf69306e9e..42b93599a0af 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9973,6 +9973,14 @@ S:   Maintained
 F: drivers/media/i2c/ov7670.c
 F: Documentation/devicetree/bindings/media/i2c/ov7670.txt
 
+OMNIVISION OV7740 SENSOR DRIVER
+M: Wenyou Yang 
+L: linux-me...@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ov7740.c
+F: Documentation/devicetree/bindings/media/i2c/ov7740.txt
+
 ONENAND FLASH DRIVER
 M: Kyungmin Park 
 L: linux-...@lists.infradead.org
-- 
2.13.0



  1   2   3   4   5   6   >