Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini  wrote:
>
> On 19/07/2018 18:28, Radim Krčmář wrote:
> >> +
> >> +kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, 
> >> vector);
> > and
> >
> >   kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vector);
> >
> > Still, the main problem is that we can only address 128 APICs.
> >
> > A simple improvement would reuse the vector field (as we need only 8
> > bits) and put a 'offset' in the rest.  The offset would say which
> > cluster of 128 are we addressing.  24 bits of offset results in 2^31
> > total addressable CPUs (we probably should even use that many bits).
> > The downside of this is that we can only address 128 at a time.
> >
> > It's basically the same as x2apic cluster mode, only with 128 cluster
> > size instead of 16, so the code should be a straightforward port.
> > And because x2apic code doesn't seem to use any division by the cluster
> > size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and
> > make the cluster size 192. :)
>
> I did suggest an offset earlier in the discussion.
>
> The main problem is that consecutive CPU ids do not map to consecutive
> APIC ids.  But still, we could do an hypercall whenever the total range
> exceeds 64.  Something like
>
> u64 ipi_bitmap = 0;
> for_each_cpu(cpu, mask)
> if (!ipi_bitmap) {
> min = max = cpu;
> } else if (cpu < min && max - cpu < 64) {
> ipi_bitmap <<= min - cpu;
> min = cpu;
> } else if (id < min + 64) {
> max = cpu < max ? max : cpu;
> } else {
> /* ... send hypercall... */
> min = max = cpu;
> ipi_bitmap = 0;
> }
> __set_bit(ipi_bitmap, cpu - min);
> }
> if (ipi_bitmap) {
> /* ... send hypercall... */
> }
>
> We could keep the cluster size of 128, but it would be more complicated
> to do the left shift in the first "else if".  If the limit is 64, you
> can keep the two arguments in the hypercall, and just pass 0 as the
> "high" bitmap on 64-bit kernels.

As David pointed out, we need to scale to higher APIC IDs. I will add
the cpu id to apic id transfer in the for loop. How about:
kvm_hypercall2(KVM_HC_SEND_IPI, ipi_bitmap, vector); directly. In
addition, why need to pass the 0 as the "high" bitmap even if for 128
vCPUs case?

Regards,
Wanpeng Li


Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini  wrote:
>
> On 19/07/2018 18:28, Radim Krčmář wrote:
> >> +
> >> +kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, 
> >> vector);
> > and
> >
> >   kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vector);
> >
> > Still, the main problem is that we can only address 128 APICs.
> >
> > A simple improvement would reuse the vector field (as we need only 8
> > bits) and put a 'offset' in the rest.  The offset would say which
> > cluster of 128 are we addressing.  24 bits of offset results in 2^31
> > total addressable CPUs (we probably should even use that many bits).
> > The downside of this is that we can only address 128 at a time.
> >
> > It's basically the same as x2apic cluster mode, only with 128 cluster
> > size instead of 16, so the code should be a straightforward port.
> > And because x2apic code doesn't seem to use any division by the cluster
> > size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and
> > make the cluster size 192. :)
>
> I did suggest an offset earlier in the discussion.
>
> The main problem is that consecutive CPU ids do not map to consecutive
> APIC ids.  But still, we could do an hypercall whenever the total range
> exceeds 64.  Something like
>
> u64 ipi_bitmap = 0;
> for_each_cpu(cpu, mask)
> if (!ipi_bitmap) {
> min = max = cpu;
> } else if (cpu < min && max - cpu < 64) {
> ipi_bitmap <<= min - cpu;
> min = cpu;
> } else if (id < min + 64) {
> max = cpu < max ? max : cpu;
> } else {
> /* ... send hypercall... */
> min = max = cpu;
> ipi_bitmap = 0;
> }
> __set_bit(ipi_bitmap, cpu - min);
> }
> if (ipi_bitmap) {
> /* ... send hypercall... */
> }
>
> We could keep the cluster size of 128, but it would be more complicated
> to do the left shift in the first "else if".  If the limit is 64, you
> can keep the two arguments in the hypercall, and just pass 0 as the
> "high" bitmap on 64-bit kernels.

As David pointed out, we need to scale to higher APIC IDs. I will add
the cpu id to apic id transfer in the for loop. How about:
kvm_hypercall2(KVM_HC_SEND_IPI, ipi_bitmap, vector); directly. In
addition, why need to pass the 0 as the "high" bitmap even if for 128
vCPUs case?

Regards,
Wanpeng Li


Re: m68k allmodconfig build errors

2018-07-19 Thread Finn Thain
On Thu, 19 Jul 2018, Randy Dunlap wrote:

> Hi Geert,
> 
> I am seeing a few errors when cross-building m68k on x86_64, using the 
> toolchain at https://mirrors.edge.kernel.org/pub/tools/crosstool/ 
> (thanks, Arnd). (so this is gcc 8.1.0)
> 
> block/partitions/ldm.o: In function `ldm_partition':
> ldm.c:(.text+0x1900): undefined reference to `strcmp'
> ldm.c:(.text+0x1964): undefined reference to `strcmp'
> drivers/rtc/rtc-proc.o: In function `is_rtc_hctosys':
> rtc-proc.c:(.text+0x290): undefined reference to `strcmp'
> drivers/watchdog/watchdog_pretimeout.o: In function 
> `watchdog_register_governor':
> (.text+0x142): undefined reference to `strcmp'
> 
> 
> Adding #include  does not help.
> 
> Is this a toolchain problem or drivers or something else?
> 

This gcc build was apparently configured like so:

/home/arnd/git/gcc/configure --target=m68k-linux --enable-targets=all 
--prefix=/home/arnd/cross/x86_64/gcc-8.1.0-nolibc/m68k-linux 
--enable-languages=c --without-headers --disable-bootstrap --disable-nls 
--disable-threads --disable-shared --disable-libmudflap --disable-libssp 
--disable-libgomp --disable-decimal-float --disable-libquadmath 
--disable-libatomic --disable-libcc1 --disable-libmpx 
--enable-checking=release

In my own cross toolchain builds strcmp comes from glibc but this 
toolchain has no libc at all.

> help?
> 

Linux will use the strcmp in lib/string.c unless __HAVE_ARCH_STRCMP is 
defined in the arch headers. Grep suggests that m68k, mips, x86, xtensa, 
arc, sh, arm64, s390 all define that macro. But maybe you could just patch 
out that definition for build testing.

-- 

> thanks,
> 


Re: m68k allmodconfig build errors

2018-07-19 Thread Finn Thain
On Thu, 19 Jul 2018, Randy Dunlap wrote:

> Hi Geert,
> 
> I am seeing a few errors when cross-building m68k on x86_64, using the 
> toolchain at https://mirrors.edge.kernel.org/pub/tools/crosstool/ 
> (thanks, Arnd). (so this is gcc 8.1.0)
> 
> block/partitions/ldm.o: In function `ldm_partition':
> ldm.c:(.text+0x1900): undefined reference to `strcmp'
> ldm.c:(.text+0x1964): undefined reference to `strcmp'
> drivers/rtc/rtc-proc.o: In function `is_rtc_hctosys':
> rtc-proc.c:(.text+0x290): undefined reference to `strcmp'
> drivers/watchdog/watchdog_pretimeout.o: In function 
> `watchdog_register_governor':
> (.text+0x142): undefined reference to `strcmp'
> 
> 
> Adding #include  does not help.
> 
> Is this a toolchain problem or drivers or something else?
> 

This gcc build was apparently configured like so:

/home/arnd/git/gcc/configure --target=m68k-linux --enable-targets=all 
--prefix=/home/arnd/cross/x86_64/gcc-8.1.0-nolibc/m68k-linux 
--enable-languages=c --without-headers --disable-bootstrap --disable-nls 
--disable-threads --disable-shared --disable-libmudflap --disable-libssp 
--disable-libgomp --disable-decimal-float --disable-libquadmath 
--disable-libatomic --disable-libcc1 --disable-libmpx 
--enable-checking=release

In my own cross toolchain builds strcmp comes from glibc but this 
toolchain has no libc at all.

> help?
> 

Linux will use the strcmp in lib/string.c unless __HAVE_ARCH_STRCMP is 
defined in the arch headers. Grep suggests that m68k, mips, x86, xtensa, 
arc, sh, arm64, s390 all define that macro. But maybe you could just patch 
out that definition for build testing.

-- 

> thanks,
> 


[PATCH v6 4/4] MAINTAINERS: add an entry for MediaTek Bluetooth driver

2018-07-19 Thread sean.wang
From: Sean Wang 

Add an entry for the MediaTek Bluetooth driver.

Signed-off-by: Sean Wang 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 20de9a5..5d81cc1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8780,6 +8780,14 @@ F:   include/uapi/linux/meye.h
 F: include/uapi/linux/ivtv*
 F: include/uapi/linux/uvcvideo.h
 
+MEDIATEK BLUETOOTH DRIVER
+M: Sean Wang 
+L: linux-blueto...@vger.kernel.org
+L: linux-media...@lists.infradead.org (moderated for non-subscribers)
+S: Maintained
+F: Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
+F: drivers/bluetooth/btmtkuart.c
+
 MEDIATEK CIR DRIVER
 M: Sean Wang 
 S: Maintained
-- 
2.7.4



[PATCH v6 1/4] dt-bindings: net: bluetooth: Add mediatek-bluetooth

2018-07-19 Thread sean.wang
From: Sean Wang 

Add binding document for a SoC built-in device using MediaTek protocol.
Which could be found on MT7622 SoC or other similar MediaTek SoCs.

Signed-off-by: Sean Wang 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/net/mediatek-bluetooth.txt | 35 ++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/mediatek-bluetooth.txt

diff --git a/Documentation/devicetree/bindings/net/mediatek-bluetooth.txt 
b/Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
new file mode 100644
index 000..14ceb2a
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
@@ -0,0 +1,35 @@
+MediaTek SoC built-in Bluetooth Devices
+==
+
+This device is a serial attached device to BTIF device and thus it must be a
+child node of the serial node with BTIF. The dt-bindings details for BTIF
+device can be known via Documentation/devicetree/bindings/serial/8250.txt.
+
+Required properties:
+
+- compatible:  Must be
+ "mediatek,mt7622-bluetooth": for MT7622 SoC
+- clocks:  Should be the clock specifiers corresponding to the entry in
+   clock-names property.
+- clock-names: Should contain "ref" entries.
+- power-domains: Phandle to the power domain that the device is part of
+
+Example:
+
+   btif: serial@1100c000 {
+   compatible = "mediatek,mt7622-btif",
+"mediatek,mtk-btif";
+   reg = <0 0x1100c000 0 0x1000>;
+   interrupts = ;
+   clocks = < CLK_PERI_BTIF_PD>;
+   clock-names = "main";
+   reg-shift = <2>;
+   reg-io-width = <4>;
+
+   bluetooth {
+   compatible = "mediatek,mt7622-bluetooth";
+   power-domains = < MT7622_POWER_DOMAIN_WB>;
+   clocks = <>;
+   clock-names = "ref";
+   };
+   };
-- 
2.7.4



Re: potential deadlock in cpufreq-dt

2018-07-19 Thread Viresh Kumar
+ linux-pm list.

On 19-07-18, 16:44, Jiada Wang wrote:
> Hello all
> 
> After enable lockdep, by poking /sys/kernel/debug/sched_features,
> I triggered the following lockdep report:
> 
> [   34.410559] ==
> [   34.416766] WARNING: possible circular locking dependency detected
> [   34.422987] 4.14.50-03493-g65adcd3b74c9-dirty #203 Tainted: G C
> [   34.450785] --
> [   34.457001] systemd-udevd/1490 is trying to acquire lock:
> [   34.462432]  (
> [   34.464102] opp_table_lock
> [   34.466814] ){+.+.}
> [   34.468932] , at: []
> dev_pm_opp_get_opp_table+0x2c/0x140
> [   34.475819]
>but task is already holding lock:
> [   34.481689]  (
> [   34.483359] subsys mutex
> [   34.485914] #6
> [   34.487587] ){+.+.}
> [   34.489701] , at: []
> subsys_interface_register+0x68/0x118
> [   34.496677]
>which lock already depends on the new lock.
> 
> [   34.504890]
>the existing dependency chain (in reverse order) is:
> [   34.512406]
>-> #3
> [   34.515836]  (
> [   34.517505] subsys mutex
> [   34.520045] #6
> [   34.521715] ){+.+.}linux-kernel@vger.kernel.org
> [   34.523819] :
> [   34.525412]__mutex_lock+0x94/0x840
> [   34.529543]mutex_lock_nested+0x1c/0x24
> [   34.534022]subsys_interface_register+0x68/0x118
> [   34.539284]cpufreq_register_driver+0x10c/0x1d8
> [   34.544464]dt_cpufreq_probe+0xcc/0x108 [cpufreq_dt]
> [   34.550074]platform_drv_probe+0x58/0xa8
> [   34.554637]driver_probe_device+0x200/0x2b4
> [   34.559463]__driver_attach+0x7c/0xac
> [   34.563768]bus_for_each_dev+0xa0/0xb8
> [   34.568169]driver_attach+0x20/0x28
> [   34.568173]bus_add_driver+0x19c/0x1d8
> [   34.568177]driver_register+0x98/0xd0
> [   34.568187]__platform_driver_register+0x48/0x50
> [   34.568198]dt_cpufreq_platdrv_init+0x18/0x1000 [cpufreq_dt]
> [   34.568205]do_one_initcall+0x120/0x13c
> [   34.568212]do_init_module+0x5c/0x1c8
> [   34.568215]load_module+0x20f0/0x2150
> [   34.568218]SyS_finit_module+0xd4/0xe8
> [   34.568220]el0_svc_naked+0x34/0x38
> [   34.568224]
>-> #2
> [   34.568225]  (
> [   34.568228] cpu_hotplug_lock.rw_sem
> [   34.568229] ){}
> [   34.568230] :
> [   34.568236]cpus_read_lock+0x54/0xcc
> [   34.568241]static_key_enable+0x14/0x2c
> [   34.568247]sched_feat_write+0xd0/0x1c4
> [   34.568252]full_proxy_write+0x6c/0xac
> [   34.568257]__vfs_write+0x34/0x138
> [   34.568260]vfs_write+0xc0/0x17c
> [   34.568262]SyS_write+0x60/0xb8
> [   34.568265]el0_svc_naked+0x34/0x38
> [   34.568266]
>-> #1
> [   34.568267]  (
> [   34.568269] >s_type->i_mutex_key
> [   34.568271] #3
> [   34.568272] ){+.+.}
> [   34.568273] :
> [   34.568279]down_write+0x48/0x84
> [   34.568282]start_creating+0x7c/0xd0
> [   34.568284]debugfs_create_dir+0x14/0xbc
> [   34.568289]opp_debug_register+0x68/0xa8
> [   34.568293]_add_opp_dev+0x78/0xb4
> [   34.568296]dev_pm_opp_get_opp_table+0x7c/0x140
> [   34.568300]dev_pm_opp_of_add_table+0x1e0/0x4a4
> [   34.568306]InitDVFS+0x7c/0x37c
> [   34.568314]PVRSRVDeviceCreate+0x324/0x610
> [   34.568317]pvr_drm_load+0x64/0x128
> [   34.568322]pvr_probe+0x70/0xa0
> [   34.568325]platform_drv_probe+0x58/0xa8
> [   34.568328]driver_probe_device+0x200/0x2b4
> [   34.568331]__driver_attach+0x7c/0xac
> [   34.568334]bus_for_each_dev+0xa0/0xb8
> [   34.568337]driver_attach+0x20/0x28
> [   34.568340]bus_add_driver+0x19c/0x1d8
> [   34.568343]driver_register+0x98/0xd0
> [   34.568346]__platform_driver_register+0x48/0x50
> [   34.568352]pvr_init+0x50/0x58
> [   34.568355]do_one_initcall+0x120/0x13c
> [   34.568360]kernel_init_freeable+0x26c/0x270
> [   34.568366]kernel_init+0x10/0xfc
> [   34.568369]ret_from_fork+0x10/0x18
> [   34.568370]
>-> #0
> [   34.568372]  (
> [   34.568373] opp_table_lock
> [   34.568375] ){+.+.}
> [   34.568376] :
> [   34.568381]lock_acquire+0x224/0x250
> [   34.568384]__mutex_lock+0x94/0x840
> [   34.568387]mutex_lock_nested+0x1c/0x24
> [   34.568391]dev_pm_opp_get_opp_table+0x2c/0x140
> [   34.568394]dev_pm_opp_set_regulators+0x30/0x190
> [   34.568400]cpufreq_init+0xe4/0x304 [cpufreq_dt]
> [   34.568405]cpufreq_online+0x174/0x5d8
> [   34.568408]cpufreq_add_dev+0x60/0x78linux-ker...@vger.kernel.org
> [   34.568411]subsys_interface_register+0x100/0x118
> [   34.568414]cpufreq_register_driver+0x10c/0x1d8
> [   34.568419]dt_cpufreq_probe+0xcc/0x108 [cpufreq_dt]
> [   

[PATCH v6 4/4] MAINTAINERS: add an entry for MediaTek Bluetooth driver

2018-07-19 Thread sean.wang
From: Sean Wang 

Add an entry for the MediaTek Bluetooth driver.

Signed-off-by: Sean Wang 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 20de9a5..5d81cc1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8780,6 +8780,14 @@ F:   include/uapi/linux/meye.h
 F: include/uapi/linux/ivtv*
 F: include/uapi/linux/uvcvideo.h
 
+MEDIATEK BLUETOOTH DRIVER
+M: Sean Wang 
+L: linux-blueto...@vger.kernel.org
+L: linux-media...@lists.infradead.org (moderated for non-subscribers)
+S: Maintained
+F: Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
+F: drivers/bluetooth/btmtkuart.c
+
 MEDIATEK CIR DRIVER
 M: Sean Wang 
 S: Maintained
-- 
2.7.4



[PATCH v6 1/4] dt-bindings: net: bluetooth: Add mediatek-bluetooth

2018-07-19 Thread sean.wang
From: Sean Wang 

Add binding document for a SoC built-in device using MediaTek protocol.
Which could be found on MT7622 SoC or other similar MediaTek SoCs.

Signed-off-by: Sean Wang 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/net/mediatek-bluetooth.txt | 35 ++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/mediatek-bluetooth.txt

diff --git a/Documentation/devicetree/bindings/net/mediatek-bluetooth.txt 
b/Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
new file mode 100644
index 000..14ceb2a
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
@@ -0,0 +1,35 @@
+MediaTek SoC built-in Bluetooth Devices
+==
+
+This device is a serial attached device to BTIF device and thus it must be a
+child node of the serial node with BTIF. The dt-bindings details for BTIF
+device can be known via Documentation/devicetree/bindings/serial/8250.txt.
+
+Required properties:
+
+- compatible:  Must be
+ "mediatek,mt7622-bluetooth": for MT7622 SoC
+- clocks:  Should be the clock specifiers corresponding to the entry in
+   clock-names property.
+- clock-names: Should contain "ref" entries.
+- power-domains: Phandle to the power domain that the device is part of
+
+Example:
+
+   btif: serial@1100c000 {
+   compatible = "mediatek,mt7622-btif",
+"mediatek,mtk-btif";
+   reg = <0 0x1100c000 0 0x1000>;
+   interrupts = ;
+   clocks = < CLK_PERI_BTIF_PD>;
+   clock-names = "main";
+   reg-shift = <2>;
+   reg-io-width = <4>;
+
+   bluetooth {
+   compatible = "mediatek,mt7622-bluetooth";
+   power-domains = < MT7622_POWER_DOMAIN_WB>;
+   clocks = <>;
+   clock-names = "ref";
+   };
+   };
-- 
2.7.4



Re: potential deadlock in cpufreq-dt

2018-07-19 Thread Viresh Kumar
+ linux-pm list.

On 19-07-18, 16:44, Jiada Wang wrote:
> Hello all
> 
> After enable lockdep, by poking /sys/kernel/debug/sched_features,
> I triggered the following lockdep report:
> 
> [   34.410559] ==
> [   34.416766] WARNING: possible circular locking dependency detected
> [   34.422987] 4.14.50-03493-g65adcd3b74c9-dirty #203 Tainted: G C
> [   34.450785] --
> [   34.457001] systemd-udevd/1490 is trying to acquire lock:
> [   34.462432]  (
> [   34.464102] opp_table_lock
> [   34.466814] ){+.+.}
> [   34.468932] , at: []
> dev_pm_opp_get_opp_table+0x2c/0x140
> [   34.475819]
>but task is already holding lock:
> [   34.481689]  (
> [   34.483359] subsys mutex
> [   34.485914] #6
> [   34.487587] ){+.+.}
> [   34.489701] , at: []
> subsys_interface_register+0x68/0x118
> [   34.496677]
>which lock already depends on the new lock.
> 
> [   34.504890]
>the existing dependency chain (in reverse order) is:
> [   34.512406]
>-> #3
> [   34.515836]  (
> [   34.517505] subsys mutex
> [   34.520045] #6
> [   34.521715] ){+.+.}linux-kernel@vger.kernel.org
> [   34.523819] :
> [   34.525412]__mutex_lock+0x94/0x840
> [   34.529543]mutex_lock_nested+0x1c/0x24
> [   34.534022]subsys_interface_register+0x68/0x118
> [   34.539284]cpufreq_register_driver+0x10c/0x1d8
> [   34.544464]dt_cpufreq_probe+0xcc/0x108 [cpufreq_dt]
> [   34.550074]platform_drv_probe+0x58/0xa8
> [   34.554637]driver_probe_device+0x200/0x2b4
> [   34.559463]__driver_attach+0x7c/0xac
> [   34.563768]bus_for_each_dev+0xa0/0xb8
> [   34.568169]driver_attach+0x20/0x28
> [   34.568173]bus_add_driver+0x19c/0x1d8
> [   34.568177]driver_register+0x98/0xd0
> [   34.568187]__platform_driver_register+0x48/0x50
> [   34.568198]dt_cpufreq_platdrv_init+0x18/0x1000 [cpufreq_dt]
> [   34.568205]do_one_initcall+0x120/0x13c
> [   34.568212]do_init_module+0x5c/0x1c8
> [   34.568215]load_module+0x20f0/0x2150
> [   34.568218]SyS_finit_module+0xd4/0xe8
> [   34.568220]el0_svc_naked+0x34/0x38
> [   34.568224]
>-> #2
> [   34.568225]  (
> [   34.568228] cpu_hotplug_lock.rw_sem
> [   34.568229] ){}
> [   34.568230] :
> [   34.568236]cpus_read_lock+0x54/0xcc
> [   34.568241]static_key_enable+0x14/0x2c
> [   34.568247]sched_feat_write+0xd0/0x1c4
> [   34.568252]full_proxy_write+0x6c/0xac
> [   34.568257]__vfs_write+0x34/0x138
> [   34.568260]vfs_write+0xc0/0x17c
> [   34.568262]SyS_write+0x60/0xb8
> [   34.568265]el0_svc_naked+0x34/0x38
> [   34.568266]
>-> #1
> [   34.568267]  (
> [   34.568269] >s_type->i_mutex_key
> [   34.568271] #3
> [   34.568272] ){+.+.}
> [   34.568273] :
> [   34.568279]down_write+0x48/0x84
> [   34.568282]start_creating+0x7c/0xd0
> [   34.568284]debugfs_create_dir+0x14/0xbc
> [   34.568289]opp_debug_register+0x68/0xa8
> [   34.568293]_add_opp_dev+0x78/0xb4
> [   34.568296]dev_pm_opp_get_opp_table+0x7c/0x140
> [   34.568300]dev_pm_opp_of_add_table+0x1e0/0x4a4
> [   34.568306]InitDVFS+0x7c/0x37c
> [   34.568314]PVRSRVDeviceCreate+0x324/0x610
> [   34.568317]pvr_drm_load+0x64/0x128
> [   34.568322]pvr_probe+0x70/0xa0
> [   34.568325]platform_drv_probe+0x58/0xa8
> [   34.568328]driver_probe_device+0x200/0x2b4
> [   34.568331]__driver_attach+0x7c/0xac
> [   34.568334]bus_for_each_dev+0xa0/0xb8
> [   34.568337]driver_attach+0x20/0x28
> [   34.568340]bus_add_driver+0x19c/0x1d8
> [   34.568343]driver_register+0x98/0xd0
> [   34.568346]__platform_driver_register+0x48/0x50
> [   34.568352]pvr_init+0x50/0x58
> [   34.568355]do_one_initcall+0x120/0x13c
> [   34.568360]kernel_init_freeable+0x26c/0x270
> [   34.568366]kernel_init+0x10/0xfc
> [   34.568369]ret_from_fork+0x10/0x18
> [   34.568370]
>-> #0
> [   34.568372]  (
> [   34.568373] opp_table_lock
> [   34.568375] ){+.+.}
> [   34.568376] :
> [   34.568381]lock_acquire+0x224/0x250
> [   34.568384]__mutex_lock+0x94/0x840
> [   34.568387]mutex_lock_nested+0x1c/0x24
> [   34.568391]dev_pm_opp_get_opp_table+0x2c/0x140
> [   34.568394]dev_pm_opp_set_regulators+0x30/0x190
> [   34.568400]cpufreq_init+0xe4/0x304 [cpufreq_dt]
> [   34.568405]cpufreq_online+0x174/0x5d8
> [   34.568408]cpufreq_add_dev+0x60/0x78linux-ker...@vger.kernel.org
> [   34.568411]subsys_interface_register+0x100/0x118
> [   34.568414]cpufreq_register_driver+0x10c/0x1d8
> [   34.568419]dt_cpufreq_probe+0xcc/0x108 [cpufreq_dt]
> [   

[PATCH v6 3/4] Bluetooth: mediatek: Add protocol support for MediaTek serial devices

2018-07-19 Thread sean.wang
From: Sean Wang 

This adds a driver to run on the top of btuart driver for the MediaTek
serial protocol based on running H:4, which can enable the built-in
Bluetooth device inside MT7622 SoC.

Signed-off-by: Sean Wang 
---
 drivers/bluetooth/Kconfig |  11 +
 drivers/bluetooth/Makefile|   2 +
 drivers/bluetooth/btmtkuart.c | 552 ++
 drivers/bluetooth/btmtkuart.h |  83 +++
 4 files changed, 648 insertions(+)
 create mode 100644 drivers/bluetooth/btmtkuart.c
 create mode 100644 drivers/bluetooth/btmtkuart.h

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index a164ac4..074737c 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -74,6 +74,17 @@ config BT_HCIBTSDIO
  Say Y here to compile support for Bluetooth SDIO devices into the
  kernel or say M to compile it as module (btsdio).
 
+config BT_HCIBTUART_MTK
+   tristate "MediaTek HCI UART driver"
+   depends on SERIAL_DEV_BUS
+   help
+ MediaTek Bluetooth HCI UART driver.
+ This driver is required if you want to use MediaTek Bluetooth
+ with serial interface.
+
+ Say Y here to compile support for MediaTek Bluetooth UART devices
+ into the kernel or say M to compile it as module (btmtkuart).
+
 config BT_HCIUART
tristate "HCI UART driver"
depends on SERIAL_DEV_BUS || !SERIAL_DEV_BUS
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 2fb6268..2aea62e 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -25,6 +25,8 @@ obj-$(CONFIG_BT_BCM)  += btbcm.o
 obj-$(CONFIG_BT_RTL)   += btrtl.o
 obj-$(CONFIG_BT_QCA)   += btqca.o
 
+obj-$(CONFIG_BT_HCIBTUART_MTK) += btmtkuart.o
+
 obj-$(CONFIG_BT_HCIUART_NOKIA) += hci_nokia.o
 
 btmrvl-y   := btmrvl_main.o
diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c
new file mode 100644
index 000..dd800ac
--- /dev/null
+++ b/drivers/bluetooth/btmtkuart.c
@@ -0,0 +1,552 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018 MediaTek Inc.
+
+/*
+ * Bluetooth support for MediaTek serial devices
+ *
+ * Author: Sean Wang 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "btmtkuart.h"
+#include "h4_recv.h"
+
+static void mtk_stp_reset(struct mtk_stp_splitter *sp)
+{
+   sp->cursor = 2;
+   sp->dlen = 0;
+}
+
+static const unsigned char *
+mtk_stp_split(struct mtk_btuart_dev *bdev, struct mtk_stp_splitter *sp,
+ const unsigned char *data, int count, int *sz_h4)
+{
+   struct mtk_stp_hdr *shdr;
+
+   /* The cursor is reset when all the data of STP is consumed out. */
+   if (!sp->dlen && sp->cursor >= 6)
+   sp->cursor = 0;
+
+   /* Filling pad until all STP info is obtained. */
+   while (sp->cursor < 6 && count > 0) {
+   sp->pad[sp->cursor] = *data;
+   sp->cursor++;
+   data++;
+   count--;
+   }
+
+   /* Retrieve STP info and have a sanity check. */
+   if (!sp->dlen && sp->cursor >= 6) {
+   shdr = (struct mtk_stp_hdr *)>pad[2];
+   sp->dlen = shdr->dlen1 << 8 | shdr->dlen2;
+
+   /* Resync STP when unexpected data is being read. */
+   if (shdr->prefix != 0x80 || sp->dlen > 2048) {
+   bt_dev_err(bdev->hdev, "stp format unexpect (%d, %d)",
+  shdr->prefix, sp->dlen);
+   mtk_stp_reset(sp);
+   }
+   }
+
+   /* Directly quit when there's no data found for H4 can process. */
+   if (count <= 0)
+   return NULL;
+
+   /* Tranlate to how much the size of data H4 can handle so far. */
+   *sz_h4 = min_t(int, count, sp->dlen);
+
+   /* Update the remaining size of STP packet. */
+   sp->dlen -= *sz_h4;
+
+   /* Data points to STP payload which can be handled by H4. */
+   return data;
+}
+
+static int mtk_stp_send(struct mtk_btuart_dev *bdev, struct sk_buff *skb)
+{
+   struct mtk_stp_hdr *shdr;
+   struct sk_buff *new_skb;
+   int dlen;
+
+   memcpy(skb_push(skb, 1), _skb_pkt_type(skb), 1);
+   dlen = skb->len;
+
+   /* Make sure of STP header at least has 4-bytes free space to fill. */
+   if (unlikely(skb_headroom(skb) < sizeof(*shdr))) {
+   new_skb = skb_realloc_headroom(skb, sizeof(*shdr));
+   kfree_skb(skb);
+   skb = new_skb;
+   }
+
+   /* Build for STP packet format. */
+   shdr = skb_push(skb, sizeof(*shdr));
+   mtk_make_stp_hdr(shdr, 0, dlen);
+   skb_put_zero(skb, MTK_STP_TLR_SIZE);
+
+   skb_queue_tail(>txq, skb);
+
+   return 0;
+}
+
+static int mtk_hci_wmt_sync(struct hci_dev *hdev, u8 opcode, u8 flag,
+   u16 

[PATCH v6 2/4] Bluetooth: Add new quirk for non-persistent setup settings

2018-07-19 Thread sean.wang
From: Sean Wang 

Add a new quirk HCI_QUIRK_NON_PERSISTENT_SETUP allowing that a quirk that
runs setup() after every open() and not just after the first open().

Signed-off-by: Sean Wang 
---
 include/net/bluetooth/hci.h | 9 +
 net/bluetooth/hci_core.c| 3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 1668211..b37d973 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -183,6 +183,15 @@ enum {
 * during the hdev->setup vendor callback.
 */
HCI_QUIRK_NON_PERSISTENT_DIAG,
+
+   /* When this quirk is set, setup() would be run after every
+* open() and not just after the first open().
+*
+* This quirk can be set before hci_register_dev is called or
+* during the hdev->setup vendor callback.
+*
+*/
+   HCI_QUIRK_NON_PERSISTENT_SETUP,
 };
 
 /* HCI device flags */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 40d260f..7de712e2 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1377,7 +1377,8 @@ static int hci_dev_do_open(struct hci_dev *hdev)
atomic_set(>cmd_cnt, 1);
set_bit(HCI_INIT, >flags);
 
-   if (hci_dev_test_flag(hdev, HCI_SETUP)) {
+   if (hci_dev_test_flag(hdev, HCI_SETUP) ||
+   test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, >quirks)) {
hci_sock_dev_event(hdev, HCI_DEV_SETUP);
 
if (hdev->setup)
-- 
2.7.4



[PATCH v6 3/4] Bluetooth: mediatek: Add protocol support for MediaTek serial devices

2018-07-19 Thread sean.wang
From: Sean Wang 

This adds a driver to run on the top of btuart driver for the MediaTek
serial protocol based on running H:4, which can enable the built-in
Bluetooth device inside MT7622 SoC.

Signed-off-by: Sean Wang 
---
 drivers/bluetooth/Kconfig |  11 +
 drivers/bluetooth/Makefile|   2 +
 drivers/bluetooth/btmtkuart.c | 552 ++
 drivers/bluetooth/btmtkuart.h |  83 +++
 4 files changed, 648 insertions(+)
 create mode 100644 drivers/bluetooth/btmtkuart.c
 create mode 100644 drivers/bluetooth/btmtkuart.h

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index a164ac4..074737c 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -74,6 +74,17 @@ config BT_HCIBTSDIO
  Say Y here to compile support for Bluetooth SDIO devices into the
  kernel or say M to compile it as module (btsdio).
 
+config BT_HCIBTUART_MTK
+   tristate "MediaTek HCI UART driver"
+   depends on SERIAL_DEV_BUS
+   help
+ MediaTek Bluetooth HCI UART driver.
+ This driver is required if you want to use MediaTek Bluetooth
+ with serial interface.
+
+ Say Y here to compile support for MediaTek Bluetooth UART devices
+ into the kernel or say M to compile it as module (btmtkuart).
+
 config BT_HCIUART
tristate "HCI UART driver"
depends on SERIAL_DEV_BUS || !SERIAL_DEV_BUS
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 2fb6268..2aea62e 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -25,6 +25,8 @@ obj-$(CONFIG_BT_BCM)  += btbcm.o
 obj-$(CONFIG_BT_RTL)   += btrtl.o
 obj-$(CONFIG_BT_QCA)   += btqca.o
 
+obj-$(CONFIG_BT_HCIBTUART_MTK) += btmtkuart.o
+
 obj-$(CONFIG_BT_HCIUART_NOKIA) += hci_nokia.o
 
 btmrvl-y   := btmrvl_main.o
diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c
new file mode 100644
index 000..dd800ac
--- /dev/null
+++ b/drivers/bluetooth/btmtkuart.c
@@ -0,0 +1,552 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018 MediaTek Inc.
+
+/*
+ * Bluetooth support for MediaTek serial devices
+ *
+ * Author: Sean Wang 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "btmtkuart.h"
+#include "h4_recv.h"
+
+static void mtk_stp_reset(struct mtk_stp_splitter *sp)
+{
+   sp->cursor = 2;
+   sp->dlen = 0;
+}
+
+static const unsigned char *
+mtk_stp_split(struct mtk_btuart_dev *bdev, struct mtk_stp_splitter *sp,
+ const unsigned char *data, int count, int *sz_h4)
+{
+   struct mtk_stp_hdr *shdr;
+
+   /* The cursor is reset when all the data of STP is consumed out. */
+   if (!sp->dlen && sp->cursor >= 6)
+   sp->cursor = 0;
+
+   /* Filling pad until all STP info is obtained. */
+   while (sp->cursor < 6 && count > 0) {
+   sp->pad[sp->cursor] = *data;
+   sp->cursor++;
+   data++;
+   count--;
+   }
+
+   /* Retrieve STP info and have a sanity check. */
+   if (!sp->dlen && sp->cursor >= 6) {
+   shdr = (struct mtk_stp_hdr *)>pad[2];
+   sp->dlen = shdr->dlen1 << 8 | shdr->dlen2;
+
+   /* Resync STP when unexpected data is being read. */
+   if (shdr->prefix != 0x80 || sp->dlen > 2048) {
+   bt_dev_err(bdev->hdev, "stp format unexpect (%d, %d)",
+  shdr->prefix, sp->dlen);
+   mtk_stp_reset(sp);
+   }
+   }
+
+   /* Directly quit when there's no data found for H4 can process. */
+   if (count <= 0)
+   return NULL;
+
+   /* Tranlate to how much the size of data H4 can handle so far. */
+   *sz_h4 = min_t(int, count, sp->dlen);
+
+   /* Update the remaining size of STP packet. */
+   sp->dlen -= *sz_h4;
+
+   /* Data points to STP payload which can be handled by H4. */
+   return data;
+}
+
+static int mtk_stp_send(struct mtk_btuart_dev *bdev, struct sk_buff *skb)
+{
+   struct mtk_stp_hdr *shdr;
+   struct sk_buff *new_skb;
+   int dlen;
+
+   memcpy(skb_push(skb, 1), _skb_pkt_type(skb), 1);
+   dlen = skb->len;
+
+   /* Make sure of STP header at least has 4-bytes free space to fill. */
+   if (unlikely(skb_headroom(skb) < sizeof(*shdr))) {
+   new_skb = skb_realloc_headroom(skb, sizeof(*shdr));
+   kfree_skb(skb);
+   skb = new_skb;
+   }
+
+   /* Build for STP packet format. */
+   shdr = skb_push(skb, sizeof(*shdr));
+   mtk_make_stp_hdr(shdr, 0, dlen);
+   skb_put_zero(skb, MTK_STP_TLR_SIZE);
+
+   skb_queue_tail(>txq, skb);
+
+   return 0;
+}
+
+static int mtk_hci_wmt_sync(struct hci_dev *hdev, u8 opcode, u8 flag,
+   u16 

[PATCH v6 2/4] Bluetooth: Add new quirk for non-persistent setup settings

2018-07-19 Thread sean.wang
From: Sean Wang 

Add a new quirk HCI_QUIRK_NON_PERSISTENT_SETUP allowing that a quirk that
runs setup() after every open() and not just after the first open().

Signed-off-by: Sean Wang 
---
 include/net/bluetooth/hci.h | 9 +
 net/bluetooth/hci_core.c| 3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 1668211..b37d973 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -183,6 +183,15 @@ enum {
 * during the hdev->setup vendor callback.
 */
HCI_QUIRK_NON_PERSISTENT_DIAG,
+
+   /* When this quirk is set, setup() would be run after every
+* open() and not just after the first open().
+*
+* This quirk can be set before hci_register_dev is called or
+* during the hdev->setup vendor callback.
+*
+*/
+   HCI_QUIRK_NON_PERSISTENT_SETUP,
 };
 
 /* HCI device flags */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 40d260f..7de712e2 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1377,7 +1377,8 @@ static int hci_dev_do_open(struct hci_dev *hdev)
atomic_set(>cmd_cnt, 1);
set_bit(HCI_INIT, >flags);
 
-   if (hci_dev_test_flag(hdev, HCI_SETUP)) {
+   if (hci_dev_test_flag(hdev, HCI_SETUP) ||
+   test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, >quirks)) {
hci_sock_dev_event(hdev, HCI_DEV_SETUP);
 
if (hdev->setup)
-- 
2.7.4



[PATCH v6 0/4] add support for Bluetooth on MT7622 SoC

2018-07-19 Thread sean.wang
From: Sean Wang 

v6 and changes since v5:
 - make btmtkuart become a separate driver.
 - drop already applied patches and the patch for btuart driver
 - refine comments in driver allowing people know that mtk extra header
   + length doesn't indicate a full H:4 frame, things can fragment.
 - enhance dt-binding document with removing mistaken added " and improve
   English sentence.
 - remove unnecessary '\n' with bt_dev_err.
 - refine code style.
 - set hdev->manufacturer as mtk id.

v5 and changes since v4:
 - add Reviewed-by Tag from Ulf Hansson for patch 2
 - remove default y in Kconfig for btmtkuart selection to avoid overkill for
   users which would like to have less an amount on stuff in kernel.
 - list header declarations in alphabetical order and add a proper blank line
   within.
 - remove unused macro.
 - use sizeof to calculate structure size instead of an aextra macro to 
hardcode.
 - use struct hci_dev * as input paraments for mtk_hci_wmt_sync and mtk_setup_fw
   for that can be reused in mtk bluetooth with other interfaces.
 - remove unused local variabled in mtk_btuart_recv.
 - remove superfluous :8 for dlen2 in struct mtk_stp_hdr definition.
 - give a reasonable naming for these labels and add a pm_runtime_put_noidle()
   in the path undoing failing pm_runtime_get_sync().
 - Turn __u8 into u8 in struct mtk_stp_hdr.

 Really thanks for these reviews by Johan Hovold and Andy Shevchenko

v4 and changes since v3:
 - refine patch 2 based on commit 919b7308fcc4 to allow that
   dev_pm_domain_attach() will return better error codes. 

v3 and changes since v2
* all changes happen on patch 6
 - fix up SPDX license style for btmtkuart.h.
 - change firmware download from in ACL data to in HCI commands
   and then remove unused mtk_acl_wmt_sync and related code.
 - add a workaround replacing bad vendor event id 0xe4 with 0xff every
   vendor should use.
 - add a sanity check for mtk_hci_wmt_sync to verifying if
   input parameters are valid.
 - add an atomic_inc(>hdev->cmd_cnt) for __hci_cmd_sync_ev.
 - be changed to use firmware with a header called mt7622pr2h.bin.

v2 and changes since v1
 - Dropped patches already being applied
 - Rewirte the whole driver using btuart [1], and add slight extension
   of btuart to fit into btmtkuart driver. Beware that [1] is also pulled
   into one part of the series for avoiding any breakage when the patchset
   is being compiled.

[1] btuart 
https://www.spinics.net/lists/linux-bluetooth/msg74918.html

v1:

Hi,

This patchset introduces built-in Bluetooth support on MT7622 SoC.
And, it should be simple to make an extension to support other
MediaTek SoCs with adjusting a few of changes on the initialization
sequence of the device.

Before the main driver is being introduced, a few of things about
power-domain management should be re-worked for serdev core and MediaTek
SCPSYS to allow the Bluetooth to properly power up.

Patch 2: add a generic way attaching power domain to serdev
Patch 3 and 4: add cleanups with reuse APIs from Linux core
Patch 5: fix a limitation about power enablement Bluetooth depends on
Patch 1, 6 and 7: the major part of adding Bluetooth support to MT7622

Sean

Sean Wang (4):
  dt-bindings: net: bluetooth: Add mediatek-bluetooth
  Bluetooth: Add new quirk for non-persistent setup settings
  Bluetooth: mediatek: Add protocol support for MediaTek serial devices
  MAINTAINERS: add an entry for MediaTek Bluetooth driver

 .../devicetree/bindings/net/mediatek-bluetooth.txt |  35 ++
 MAINTAINERS|   8 +
 drivers/bluetooth/Kconfig  |  11 +
 drivers/bluetooth/Makefile |   2 +
 drivers/bluetooth/btmtkuart.c  | 552 +
 drivers/bluetooth/btmtkuart.h  |  83 
 include/net/bluetooth/hci.h|   9 +
 net/bluetooth/hci_core.c   |   3 +-
 8 files changed, 702 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
 create mode 100644 drivers/bluetooth/btmtkuart.c
 create mode 100644 drivers/bluetooth/btmtkuart.h

-- 
2.7.4



[PATCH v6 0/4] add support for Bluetooth on MT7622 SoC

2018-07-19 Thread sean.wang
From: Sean Wang 

v6 and changes since v5:
 - make btmtkuart become a separate driver.
 - drop already applied patches and the patch for btuart driver
 - refine comments in driver allowing people know that mtk extra header
   + length doesn't indicate a full H:4 frame, things can fragment.
 - enhance dt-binding document with removing mistaken added " and improve
   English sentence.
 - remove unnecessary '\n' with bt_dev_err.
 - refine code style.
 - set hdev->manufacturer as mtk id.

v5 and changes since v4:
 - add Reviewed-by Tag from Ulf Hansson for patch 2
 - remove default y in Kconfig for btmtkuart selection to avoid overkill for
   users which would like to have less an amount on stuff in kernel.
 - list header declarations in alphabetical order and add a proper blank line
   within.
 - remove unused macro.
 - use sizeof to calculate structure size instead of an aextra macro to 
hardcode.
 - use struct hci_dev * as input paraments for mtk_hci_wmt_sync and mtk_setup_fw
   for that can be reused in mtk bluetooth with other interfaces.
 - remove unused local variabled in mtk_btuart_recv.
 - remove superfluous :8 for dlen2 in struct mtk_stp_hdr definition.
 - give a reasonable naming for these labels and add a pm_runtime_put_noidle()
   in the path undoing failing pm_runtime_get_sync().
 - Turn __u8 into u8 in struct mtk_stp_hdr.

 Really thanks for these reviews by Johan Hovold and Andy Shevchenko

v4 and changes since v3:
 - refine patch 2 based on commit 919b7308fcc4 to allow that
   dev_pm_domain_attach() will return better error codes. 

v3 and changes since v2
* all changes happen on patch 6
 - fix up SPDX license style for btmtkuart.h.
 - change firmware download from in ACL data to in HCI commands
   and then remove unused mtk_acl_wmt_sync and related code.
 - add a workaround replacing bad vendor event id 0xe4 with 0xff every
   vendor should use.
 - add a sanity check for mtk_hci_wmt_sync to verifying if
   input parameters are valid.
 - add an atomic_inc(>hdev->cmd_cnt) for __hci_cmd_sync_ev.
 - be changed to use firmware with a header called mt7622pr2h.bin.

v2 and changes since v1
 - Dropped patches already being applied
 - Rewirte the whole driver using btuart [1], and add slight extension
   of btuart to fit into btmtkuart driver. Beware that [1] is also pulled
   into one part of the series for avoiding any breakage when the patchset
   is being compiled.

[1] btuart 
https://www.spinics.net/lists/linux-bluetooth/msg74918.html

v1:

Hi,

This patchset introduces built-in Bluetooth support on MT7622 SoC.
And, it should be simple to make an extension to support other
MediaTek SoCs with adjusting a few of changes on the initialization
sequence of the device.

Before the main driver is being introduced, a few of things about
power-domain management should be re-worked for serdev core and MediaTek
SCPSYS to allow the Bluetooth to properly power up.

Patch 2: add a generic way attaching power domain to serdev
Patch 3 and 4: add cleanups with reuse APIs from Linux core
Patch 5: fix a limitation about power enablement Bluetooth depends on
Patch 1, 6 and 7: the major part of adding Bluetooth support to MT7622

Sean

Sean Wang (4):
  dt-bindings: net: bluetooth: Add mediatek-bluetooth
  Bluetooth: Add new quirk for non-persistent setup settings
  Bluetooth: mediatek: Add protocol support for MediaTek serial devices
  MAINTAINERS: add an entry for MediaTek Bluetooth driver

 .../devicetree/bindings/net/mediatek-bluetooth.txt |  35 ++
 MAINTAINERS|   8 +
 drivers/bluetooth/Kconfig  |  11 +
 drivers/bluetooth/Makefile |   2 +
 drivers/bluetooth/btmtkuart.c  | 552 +
 drivers/bluetooth/btmtkuart.h  |  83 
 include/net/bluetooth/hci.h|   9 +
 net/bluetooth/hci_core.c   |   3 +-
 8 files changed, 702 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
 create mode 100644 drivers/bluetooth/btmtkuart.c
 create mode 100644 drivers/bluetooth/btmtkuart.h

-- 
2.7.4



[tip:x86/pti] x86/pti: Check the return value of pti_user_pagetable_walk_pmd()

2018-07-19 Thread tip-bot for Jiang Biao
Commit-ID:  8c934e01a7ce685d98e970880f5941d79272c654
Gitweb: https://git.kernel.org/tip/8c934e01a7ce685d98e970880f5941d79272c654
Author: Jiang Biao 
AuthorDate: Fri, 20 Jul 2018 08:06:32 +0800
Committer:  Thomas Gleixner 
CommitDate: Fri, 20 Jul 2018 07:07:39 +0200

x86/pti: Check the return value of pti_user_pagetable_walk_pmd()

pti_user_pagetable_walk_pmd() can return NULL, so the return value should
be checked to prevent a NULL pointer dereference.

Add the check and a warning when the PMD allocation fails.

Signed-off-by: Jiang Biao 
Signed-off-by: Thomas Gleixner 
Cc: dave.han...@linux.intel.com
Cc: l...@kernel.org
Cc: h...@zytor.com
Cc: albca...@gmail.com
Cc: zhong.weid...@zte.com.cn
Link: 
https://lkml.kernel.org/r/1532045192-49622-2-git-send-email-jiang.bi...@zte.com.cn

---
 arch/x86/mm/pti.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 001ee6b0619e..bcf35dac1920 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -205,7 +205,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
BUILD_BUG_ON(p4d_large(*p4d) != 0);
if (p4d_none(*p4d)) {
unsigned long new_pud_page = __get_free_page(gfp);
-   if (!new_pud_page)
+   if (WARN_ON_ONCE(!new_pud_page))
return NULL;
 
set_p4d(p4d, __p4d(_KERNPG_TABLE | __pa(new_pud_page)));
@@ -219,7 +219,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
}
if (pud_none(*pud)) {
unsigned long new_pmd_page = __get_free_page(gfp);
-   if (!new_pmd_page)
+   if (WARN_ON_ONCE(!new_pmd_page))
return NULL;
 
set_pud(pud, __pud(_KERNPG_TABLE | __pa(new_pmd_page)));
@@ -241,9 +241,13 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
 static __init pte_t *pti_user_pagetable_walk_pte(unsigned long address)
 {
gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
-   pmd_t *pmd = pti_user_pagetable_walk_pmd(address);
+   pmd_t *pmd;
pte_t *pte;
 
+   pmd = pti_user_pagetable_walk_pmd(address);
+   if (!pmd)
+   return NULL;
+
/* We can't do anything sensible if we hit a large mapping. */
if (pmd_large(*pmd)) {
WARN_ON(1);


[tip:x86/pti] x86/pti: Check the return value of pti_user_pagetable_walk_pmd()

2018-07-19 Thread tip-bot for Jiang Biao
Commit-ID:  8c934e01a7ce685d98e970880f5941d79272c654
Gitweb: https://git.kernel.org/tip/8c934e01a7ce685d98e970880f5941d79272c654
Author: Jiang Biao 
AuthorDate: Fri, 20 Jul 2018 08:06:32 +0800
Committer:  Thomas Gleixner 
CommitDate: Fri, 20 Jul 2018 07:07:39 +0200

x86/pti: Check the return value of pti_user_pagetable_walk_pmd()

pti_user_pagetable_walk_pmd() can return NULL, so the return value should
be checked to prevent a NULL pointer dereference.

Add the check and a warning when the PMD allocation fails.

Signed-off-by: Jiang Biao 
Signed-off-by: Thomas Gleixner 
Cc: dave.han...@linux.intel.com
Cc: l...@kernel.org
Cc: h...@zytor.com
Cc: albca...@gmail.com
Cc: zhong.weid...@zte.com.cn
Link: 
https://lkml.kernel.org/r/1532045192-49622-2-git-send-email-jiang.bi...@zte.com.cn

---
 arch/x86/mm/pti.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 001ee6b0619e..bcf35dac1920 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -205,7 +205,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
BUILD_BUG_ON(p4d_large(*p4d) != 0);
if (p4d_none(*p4d)) {
unsigned long new_pud_page = __get_free_page(gfp);
-   if (!new_pud_page)
+   if (WARN_ON_ONCE(!new_pud_page))
return NULL;
 
set_p4d(p4d, __p4d(_KERNPG_TABLE | __pa(new_pud_page)));
@@ -219,7 +219,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
}
if (pud_none(*pud)) {
unsigned long new_pmd_page = __get_free_page(gfp);
-   if (!new_pmd_page)
+   if (WARN_ON_ONCE(!new_pmd_page))
return NULL;
 
set_pud(pud, __pud(_KERNPG_TABLE | __pa(new_pmd_page)));
@@ -241,9 +241,13 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long 
address)
 static __init pte_t *pti_user_pagetable_walk_pte(unsigned long address)
 {
gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
-   pmd_t *pmd = pti_user_pagetable_walk_pmd(address);
+   pmd_t *pmd;
pte_t *pte;
 
+   pmd = pti_user_pagetable_walk_pmd(address);
+   if (!pmd)
+   return NULL;
+
/* We can't do anything sensible if we hit a large mapping. */
if (pmd_large(*pmd)) {
WARN_ON(1);


[tip:x86/pti] x86/pti: Check the return value of pti_user_pagetable_walk_p4d()

2018-07-19 Thread tip-bot for Jiang Biao
Commit-ID:  b2b7d986a89b6c94b1331a909de1217214fb08c1
Gitweb: https://git.kernel.org/tip/b2b7d986a89b6c94b1331a909de1217214fb08c1
Author: Jiang Biao 
AuthorDate: Fri, 20 Jul 2018 08:06:31 +0800
Committer:  Thomas Gleixner 
CommitDate: Fri, 20 Jul 2018 07:07:39 +0200

x86/pti: Check the return value of pti_user_pagetable_walk_p4d()

pti_user_pagetable_walk_p4d() can return NULL, so the return value should
be checked to prevent a NULL pointer dereference.

Add the check and a warning when the P4D allocation fails.

Signed-off-by: Jiang Biao 
Signed-off-by: Thomas Gleixner 
Cc: dave.han...@linux.intel.com
Cc: l...@kernel.org
Cc: h...@zytor.com
Cc: albca...@gmail.com
Cc: zhong.weid...@zte.com.cn
Link: 
https://lkml.kernel.org/r/1532045192-49622-1-git-send-email-jiang.bi...@zte.com.cn

---
 arch/x86/mm/pti.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 7b1c85759005..001ee6b0619e 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -176,7 +176,7 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long 
address)
 
if (pgd_none(*pgd)) {
unsigned long new_p4d_page = __get_free_page(gfp);
-   if (!new_p4d_page)
+   if (WARN_ON_ONCE(!new_p4d_page))
return NULL;
 
set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(new_p4d_page)));
@@ -195,9 +195,13 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long 
address)
 static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)
 {
gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
-   p4d_t *p4d = pti_user_pagetable_walk_p4d(address);
+   p4d_t *p4d;
pud_t *pud;
 
+   p4d = pti_user_pagetable_walk_p4d(address);
+   if (!p4d)
+   return NULL;
+
BUILD_BUG_ON(p4d_large(*p4d) != 0);
if (p4d_none(*p4d)) {
unsigned long new_pud_page = __get_free_page(gfp);
@@ -359,6 +363,9 @@ static void __init pti_clone_p4d(unsigned long addr)
pgd_t *kernel_pgd;
 
user_p4d = pti_user_pagetable_walk_p4d(addr);
+   if (!user_p4d)
+   return;
+
kernel_pgd = pgd_offset_k(addr);
kernel_p4d = p4d_offset(kernel_pgd, addr);
*user_p4d = *kernel_p4d;


[tip:x86/pti] x86/pti: Check the return value of pti_user_pagetable_walk_p4d()

2018-07-19 Thread tip-bot for Jiang Biao
Commit-ID:  b2b7d986a89b6c94b1331a909de1217214fb08c1
Gitweb: https://git.kernel.org/tip/b2b7d986a89b6c94b1331a909de1217214fb08c1
Author: Jiang Biao 
AuthorDate: Fri, 20 Jul 2018 08:06:31 +0800
Committer:  Thomas Gleixner 
CommitDate: Fri, 20 Jul 2018 07:07:39 +0200

x86/pti: Check the return value of pti_user_pagetable_walk_p4d()

pti_user_pagetable_walk_p4d() can return NULL, so the return value should
be checked to prevent a NULL pointer dereference.

Add the check and a warning when the P4D allocation fails.

Signed-off-by: Jiang Biao 
Signed-off-by: Thomas Gleixner 
Cc: dave.han...@linux.intel.com
Cc: l...@kernel.org
Cc: h...@zytor.com
Cc: albca...@gmail.com
Cc: zhong.weid...@zte.com.cn
Link: 
https://lkml.kernel.org/r/1532045192-49622-1-git-send-email-jiang.bi...@zte.com.cn

---
 arch/x86/mm/pti.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 7b1c85759005..001ee6b0619e 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -176,7 +176,7 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long 
address)
 
if (pgd_none(*pgd)) {
unsigned long new_p4d_page = __get_free_page(gfp);
-   if (!new_p4d_page)
+   if (WARN_ON_ONCE(!new_p4d_page))
return NULL;
 
set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(new_p4d_page)));
@@ -195,9 +195,13 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long 
address)
 static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)
 {
gfp_t gfp = (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO);
-   p4d_t *p4d = pti_user_pagetable_walk_p4d(address);
+   p4d_t *p4d;
pud_t *pud;
 
+   p4d = pti_user_pagetable_walk_p4d(address);
+   if (!p4d)
+   return NULL;
+
BUILD_BUG_ON(p4d_large(*p4d) != 0);
if (p4d_none(*p4d)) {
unsigned long new_pud_page = __get_free_page(gfp);
@@ -359,6 +363,9 @@ static void __init pti_clone_p4d(unsigned long addr)
pgd_t *kernel_pgd;
 
user_p4d = pti_user_pagetable_walk_p4d(addr);
+   if (!user_p4d)
+   return;
+
kernel_pgd = pgd_offset_k(addr);
kernel_p4d = p4d_offset(kernel_pgd, addr);
*user_p4d = *kernel_p4d;


Re: linux-next: manual merge of the mfd tree with the sound tree

2018-07-19 Thread Takashi Iwai
On Fri, 20 Jul 2018 05:42:19 +0200,
Stephen Rothwell wrote:
> 
> Hi all,
> 
> Today's linux-next merge of the mfd tree got a conflict in:
> 
>   drivers/gpu/drm/i915/Kconfig
> 
> between commit:
> 
>   a57942bfdd61 ("ALSA: hda: Make audio component support more generic")
> 
> from the sound tree and commit:
> 
>   9c229127aee2 ("drm/i915: hdmi: add CEC notifier to intel_hdmi")
> 
> from the mfd tree.
> 
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging.  You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.
> 
> -- 
> Cheers,
> Stephen Rothwell
> 
> diff --cc drivers/gpu/drm/i915/Kconfig
> index 5c607f2c707b,2d65d567d5d1..
> --- a/drivers/gpu/drm/i915/Kconfig
> +++ b/drivers/gpu/drm/i915/Kconfig
> @@@ -23,7 -23,7 +23,8 @@@ config DRM_I91
>   select SYNC_FILE
>   select IOSF_MBI
>   select CRC32
>  +select SND_HDA_I915 if SND_HDA_CORE
> + select CEC_CORE if CEC_NOTIFIER
>   help
> Choose this option if you have a system that has "Intel Graphics
> Media Accelerator" or "HD Graphics" integrated graphics,

Looks good, thanks!


Takashi


Re: linux-next: manual merge of the mfd tree with the sound tree

2018-07-19 Thread Takashi Iwai
On Fri, 20 Jul 2018 05:42:19 +0200,
Stephen Rothwell wrote:
> 
> Hi all,
> 
> Today's linux-next merge of the mfd tree got a conflict in:
> 
>   drivers/gpu/drm/i915/Kconfig
> 
> between commit:
> 
>   a57942bfdd61 ("ALSA: hda: Make audio component support more generic")
> 
> from the sound tree and commit:
> 
>   9c229127aee2 ("drm/i915: hdmi: add CEC notifier to intel_hdmi")
> 
> from the mfd tree.
> 
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging.  You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.
> 
> -- 
> Cheers,
> Stephen Rothwell
> 
> diff --cc drivers/gpu/drm/i915/Kconfig
> index 5c607f2c707b,2d65d567d5d1..
> --- a/drivers/gpu/drm/i915/Kconfig
> +++ b/drivers/gpu/drm/i915/Kconfig
> @@@ -23,7 -23,7 +23,8 @@@ config DRM_I91
>   select SYNC_FILE
>   select IOSF_MBI
>   select CRC32
>  +select SND_HDA_I915 if SND_HDA_CORE
> + select CEC_CORE if CEC_NOTIFIER
>   help
> Choose this option if you have a system that has "Intel Graphics
> Media Accelerator" or "HD Graphics" integrated graphics,

Looks good, thanks!


Takashi


Re: [PATCH] fs: iomap: Change return type to vm_fault_t

2018-07-19 Thread Souptick Joarder
On Wed, Jul 4, 2018 at 3:22 AM, Andreas Gruenbacher  wrote:
> On 3 July 2018 at 23:39, Darrick J. Wong  wrote:
>> On Mon, Jul 02, 2018 at 07:52:41PM +0200, Andreas Gruenbacher wrote:
>>> On 2 July 2018 at 17:43, Souptick Joarder  wrote:
>>> > Return type has been changed to vm_fault_t type for
>>> > iomap_page_mkwrite().
>>> >
>>> > see commit 1c8f422059ae ("mm: change return type to
>>> > vm_fault_t") for reference.
>>> >
>>> > Signed-off-by: Souptick Joarder 
>>> > Reviewed-by: Matthew Wilcox 
>>
>> I don't recall Christoph [now cc'd] rescinding his NAK of the previous
>> version of this patch[1].  Has he changed his mind since May?
>
> Oops, a reply gone wrong -- I was meaning to reply to Souptick
> Joarder's gfs2 change which I've added to the gfs2 for-next branch.
> Not the iomap change. Sorry for the confusion.
>
>> [1] https://spinics.net/lists/linux-fsdevel/msg126032.html
>>
>> Now granted I didn't have a problem with the code (and applied the xfs
>> version to 4.18 after monitoring to satisfy myself that nothing
>> particularly weird happened during 4.17) but seeing as most of the iomap
>> changes have gone through hch's review and landed via the xfs tree...

Darrick, is this patch going to 4.19 through xfs tree ?


Re: [PATCH] fs: iomap: Change return type to vm_fault_t

2018-07-19 Thread Souptick Joarder
On Wed, Jul 4, 2018 at 3:22 AM, Andreas Gruenbacher  wrote:
> On 3 July 2018 at 23:39, Darrick J. Wong  wrote:
>> On Mon, Jul 02, 2018 at 07:52:41PM +0200, Andreas Gruenbacher wrote:
>>> On 2 July 2018 at 17:43, Souptick Joarder  wrote:
>>> > Return type has been changed to vm_fault_t type for
>>> > iomap_page_mkwrite().
>>> >
>>> > see commit 1c8f422059ae ("mm: change return type to
>>> > vm_fault_t") for reference.
>>> >
>>> > Signed-off-by: Souptick Joarder 
>>> > Reviewed-by: Matthew Wilcox 
>>
>> I don't recall Christoph [now cc'd] rescinding his NAK of the previous
>> version of this patch[1].  Has he changed his mind since May?
>
> Oops, a reply gone wrong -- I was meaning to reply to Souptick
> Joarder's gfs2 change which I've added to the gfs2 for-next branch.
> Not the iomap change. Sorry for the confusion.
>
>> [1] https://spinics.net/lists/linux-fsdevel/msg126032.html
>>
>> Now granted I didn't have a problem with the code (and applied the xfs
>> version to 4.18 after monitoring to satisfy myself that nothing
>> particularly weird happened during 4.17) but seeing as most of the iomap
>> changes have gone through hch's review and landed via the xfs tree...

Darrick, is this patch going to 4.19 through xfs tree ?


[tip:x86/hyperv] x86/hyper-v: Fix wrong merge conflict resolution

2018-07-19 Thread tip-bot for K. Y. Srinivasan
Commit-ID:  be0e16ce7c3bf9855f1ef5ae46cf889e1784ddea
Gitweb: https://git.kernel.org/tip/be0e16ce7c3bf9855f1ef5ae46cf889e1784ddea
Author: K. Y. Srinivasan 
AuthorDate: Fri, 20 Jul 2018 03:50:09 +
Committer:  Thomas Gleixner 
CommitDate: Fri, 20 Jul 2018 06:56:23 +0200

x86/hyper-v: Fix wrong merge conflict resolution

When the mapping betwween the Linux notion of CPU ID to the hypervisor's
notion of CPU ID is not initialized, IPI must fall back to the
non-enlightened path.

The recent merge of upstream changes into the hyperv branch resolved a
merge conflict wronly by returning success in that case, which results in
the IPI not being sent at all. Fix it up.

Fixes: 8f63e9230dec ("Merge branch 'x86/urgent' into x86/hyperv")
Reported-by: Michael Kelley 
Signed-off-by: K. Y. Srinivasan 
Signed-off-by: Thomas Gleixner 
Cc: gre...@linuxfoundation.org
Cc: de...@linuxdriverproject.org
Cc: o...@aepfle.de
Cc: a...@canonical.com
Cc: jasow...@redhat.com
Cc: h...@zytor.com
Cc: sthem...@microsoft.com
Cc: michael.h.kel...@microsoft.com
Cc: vkuzn...@redhat.com
Link: https://lkml.kernel.org/r/20180720035009.3995-1-...@linuxonhyperv.com
---
 arch/x86/hyperv/hv_apic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
index 0c3c9f8fee77..5b0f613428c2 100644
--- a/arch/x86/hyperv/hv_apic.c
+++ b/arch/x86/hyperv/hv_apic.c
@@ -168,7 +168,7 @@ static bool __send_ipi_mask(const struct cpumask *mask, int 
vector)
for_each_cpu(cur_cpu, mask) {
vcpu = hv_cpu_number_to_vp_number(cur_cpu);
if (vcpu == VP_INVAL)
-   return true;
+   return false;
 
/*
 * This particular version of the IPI hypercall can


[tip:x86/hyperv] x86/hyper-v: Fix wrong merge conflict resolution

2018-07-19 Thread tip-bot for K. Y. Srinivasan
Commit-ID:  be0e16ce7c3bf9855f1ef5ae46cf889e1784ddea
Gitweb: https://git.kernel.org/tip/be0e16ce7c3bf9855f1ef5ae46cf889e1784ddea
Author: K. Y. Srinivasan 
AuthorDate: Fri, 20 Jul 2018 03:50:09 +
Committer:  Thomas Gleixner 
CommitDate: Fri, 20 Jul 2018 06:56:23 +0200

x86/hyper-v: Fix wrong merge conflict resolution

When the mapping betwween the Linux notion of CPU ID to the hypervisor's
notion of CPU ID is not initialized, IPI must fall back to the
non-enlightened path.

The recent merge of upstream changes into the hyperv branch resolved a
merge conflict wronly by returning success in that case, which results in
the IPI not being sent at all. Fix it up.

Fixes: 8f63e9230dec ("Merge branch 'x86/urgent' into x86/hyperv")
Reported-by: Michael Kelley 
Signed-off-by: K. Y. Srinivasan 
Signed-off-by: Thomas Gleixner 
Cc: gre...@linuxfoundation.org
Cc: de...@linuxdriverproject.org
Cc: o...@aepfle.de
Cc: a...@canonical.com
Cc: jasow...@redhat.com
Cc: h...@zytor.com
Cc: sthem...@microsoft.com
Cc: michael.h.kel...@microsoft.com
Cc: vkuzn...@redhat.com
Link: https://lkml.kernel.org/r/20180720035009.3995-1-...@linuxonhyperv.com
---
 arch/x86/hyperv/hv_apic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
index 0c3c9f8fee77..5b0f613428c2 100644
--- a/arch/x86/hyperv/hv_apic.c
+++ b/arch/x86/hyperv/hv_apic.c
@@ -168,7 +168,7 @@ static bool __send_ipi_mask(const struct cpumask *mask, int 
vector)
for_each_cpu(cur_cpu, mask) {
vcpu = hv_cpu_number_to_vp_number(cur_cpu);
if (vcpu == VP_INVAL)
-   return true;
+   return false;
 
/*
 * This particular version of the IPI hypercall can


Re: [RFC PATCH v2 1/4] dt-bindings: misc: Add bindings for misc. BMC control fields

2018-07-19 Thread Benjamin Herrenschmidt
On Fri, 2018-07-20 at 09:37 +0930, Andrew Jeffery wrote:
> > 
> > Andrew, can you start with a list that shows what you expect us to need
> > on our systems ?
> > 
> 
> Okay, our Witherspoon and Romulus platforms containing the ASPEED AST2500 
> currently need the following tuneables exposed:
> 
> > From the SCU:
> 
> - Debug UART enable
> - VGA DAC mux
> - VGA scratch registers 0-7
> - LPC SuperIO decode enable
> - VGA MMIO decode enable
> 
> > From the LPC controller:
> 
> - iLPC2AHB enable
> - SuperIO scratch registers 0x20-0x2f
> 
> (The LPC controller is just as much of a collection of random bits as the SCU)
> 
> Lastly, our Palmetto platform uses an AST2400 which has fewer features 
> compared to the AST2500. Its tuneable list is the same as the above with the 
> exception of "Debug UART enable".
> 
> Tuneables that we may need to expose in the future include:
> 
> > From the SCU:
> 
> - PCI VID/DID for the BMC PCIe device
> - VGA device enable (may need to be disabled if the platform contains a 
> discrete graphics processor)

Additionally there's a bunch of resigters controlling the mapping of
various MMIO regions of the BMC PCIe device to portions of the BMC
address space. I'm not sure what's the best way to handle that.

This specific set might require a dedicated device as a subnode of
the SCU in the DT that contains all the mappings as properties... 

That or we consider them static enough and just whack it in u-boot.

> > From the LPC controller:
> 
> - UART mux
> 
> Alexander, Eugene, can you chime in with your platforms' needs?
> 
> Cheers,
> 
> Andrew


Re: [RFC PATCH v2 1/4] dt-bindings: misc: Add bindings for misc. BMC control fields

2018-07-19 Thread Benjamin Herrenschmidt
On Fri, 2018-07-20 at 09:37 +0930, Andrew Jeffery wrote:
> > 
> > Andrew, can you start with a list that shows what you expect us to need
> > on our systems ?
> > 
> 
> Okay, our Witherspoon and Romulus platforms containing the ASPEED AST2500 
> currently need the following tuneables exposed:
> 
> > From the SCU:
> 
> - Debug UART enable
> - VGA DAC mux
> - VGA scratch registers 0-7
> - LPC SuperIO decode enable
> - VGA MMIO decode enable
> 
> > From the LPC controller:
> 
> - iLPC2AHB enable
> - SuperIO scratch registers 0x20-0x2f
> 
> (The LPC controller is just as much of a collection of random bits as the SCU)
> 
> Lastly, our Palmetto platform uses an AST2400 which has fewer features 
> compared to the AST2500. Its tuneable list is the same as the above with the 
> exception of "Debug UART enable".
> 
> Tuneables that we may need to expose in the future include:
> 
> > From the SCU:
> 
> - PCI VID/DID for the BMC PCIe device
> - VGA device enable (may need to be disabled if the platform contains a 
> discrete graphics processor)

Additionally there's a bunch of resigters controlling the mapping of
various MMIO regions of the BMC PCIe device to portions of the BMC
address space. I'm not sure what's the best way to handle that.

This specific set might require a dedicated device as a subnode of
the SCU in the DT that contains all the mappings as properties... 

That or we consider them static enough and just whack it in u-boot.

> > From the LPC controller:
> 
> - UART mux
> 
> Alexander, Eugene, can you chime in with your platforms' needs?
> 
> Cheers,
> 
> Andrew


Re: [PATCH] sched/fair: remove #ifdefs from scale_rt_capacity

2018-07-19 Thread Viresh Kumar
On 19-07-18, 14:00, Vincent Guittot wrote:
> Reuse cpu_util_irq() that has been defined for schedutil and set irq util
> to 0 when !CONFIG_IRQ_TIME_ACCOUNTING
> 
> But the compiler is not able to optimize the sequence (at least with
> aarch64 GCC 7.2.1)
>   free *= (max - irq);
>   free /= max;
> when irq is fixed to 0
> 
> Add a new inline function scale_irq_capacity() that will scale utilization
> when irq is accounted. Reuse this funciton in schedutil which applies
> similar formula.
> 
> Suggested-by: Ingo Molnar 
> Signed-off-by: Vincent Guittot 
> ---
>  kernel/sched/cpufreq_schedutil.c |  3 +--
>  kernel/sched/fair.c  | 13 +++--
>  kernel/sched/sched.h | 20 ++--
>  3 files changed, 22 insertions(+), 14 deletions(-)
> 
> diff --git a/kernel/sched/cpufreq_schedutil.c 
> b/kernel/sched/cpufreq_schedutil.c
> index 97dcd44..3fffad3 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -247,8 +247,7 @@ static unsigned long sugov_get_util(struct sugov_cpu 
> *sg_cpu)
>*   U' = irq + --- * U
>*max
>*/
> - util *= (max - irq);
> - util /= max;
> + util = scale_irq_capacity(util, irq, max);
>   util += irq;
>  
>   /*
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index d5f7d52..14c3fdd 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -7551,16 +7551,12 @@ static unsigned long scale_rt_capacity(int cpu)
>   struct rq *rq = cpu_rq(cpu);
>   unsigned long max = arch_scale_cpu_capacity(NULL, cpu);
>   unsigned long used, free;
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
>   unsigned long irq;
> -#endif
>  
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> - irq = READ_ONCE(rq->avg_irq.util_avg);
> + irq = cpu_util_irq(rq);
>  
>   if (unlikely(irq >= max))
>   return 1;
> -#endif
>  
>   used = READ_ONCE(rq->avg_rt.util_avg);
>   used += READ_ONCE(rq->avg_dl.util_avg);
> @@ -7569,11 +7565,8 @@ static unsigned long scale_rt_capacity(int cpu)
>   return 1;
>  
>   free = max - used;
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> - free *= (max - irq);
> - free /= max;
> -#endif
> - return free;
> +
> + return scale_irq_capacity(free, irq, max);
>  }
>  
>  static void update_cpu_capacity(struct sched_domain *sd, int cpu)
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index ebb4b3c..b80c3fd 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -2210,17 +2210,33 @@ static inline unsigned long cpu_util_rt(struct rq *rq)
>  {
>   return READ_ONCE(rq->avg_rt.util_avg);
>  }
> +#endif
>  
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> +#if defined(SMP) \
> + && (defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING))
>  static inline unsigned long cpu_util_irq(struct rq *rq)
>  {
>   return rq->avg_irq.util_avg;
>  }
> +
> +static inline
> +unsigned long scale_irq_capacity(unsigned long util, unsigned long irq, 
> unsigned long max)
> +{
> + util *= (max - irq);

() can be dropped here. 

Other than that: 

Acked-by: Viresh Kumar 

-- 
viresh


Re: [PATCH] sched/fair: remove #ifdefs from scale_rt_capacity

2018-07-19 Thread Viresh Kumar
On 19-07-18, 14:00, Vincent Guittot wrote:
> Reuse cpu_util_irq() that has been defined for schedutil and set irq util
> to 0 when !CONFIG_IRQ_TIME_ACCOUNTING
> 
> But the compiler is not able to optimize the sequence (at least with
> aarch64 GCC 7.2.1)
>   free *= (max - irq);
>   free /= max;
> when irq is fixed to 0
> 
> Add a new inline function scale_irq_capacity() that will scale utilization
> when irq is accounted. Reuse this funciton in schedutil which applies
> similar formula.
> 
> Suggested-by: Ingo Molnar 
> Signed-off-by: Vincent Guittot 
> ---
>  kernel/sched/cpufreq_schedutil.c |  3 +--
>  kernel/sched/fair.c  | 13 +++--
>  kernel/sched/sched.h | 20 ++--
>  3 files changed, 22 insertions(+), 14 deletions(-)
> 
> diff --git a/kernel/sched/cpufreq_schedutil.c 
> b/kernel/sched/cpufreq_schedutil.c
> index 97dcd44..3fffad3 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -247,8 +247,7 @@ static unsigned long sugov_get_util(struct sugov_cpu 
> *sg_cpu)
>*   U' = irq + --- * U
>*max
>*/
> - util *= (max - irq);
> - util /= max;
> + util = scale_irq_capacity(util, irq, max);
>   util += irq;
>  
>   /*
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index d5f7d52..14c3fdd 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -7551,16 +7551,12 @@ static unsigned long scale_rt_capacity(int cpu)
>   struct rq *rq = cpu_rq(cpu);
>   unsigned long max = arch_scale_cpu_capacity(NULL, cpu);
>   unsigned long used, free;
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
>   unsigned long irq;
> -#endif
>  
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> - irq = READ_ONCE(rq->avg_irq.util_avg);
> + irq = cpu_util_irq(rq);
>  
>   if (unlikely(irq >= max))
>   return 1;
> -#endif
>  
>   used = READ_ONCE(rq->avg_rt.util_avg);
>   used += READ_ONCE(rq->avg_dl.util_avg);
> @@ -7569,11 +7565,8 @@ static unsigned long scale_rt_capacity(int cpu)
>   return 1;
>  
>   free = max - used;
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> - free *= (max - irq);
> - free /= max;
> -#endif
> - return free;
> +
> + return scale_irq_capacity(free, irq, max);
>  }
>  
>  static void update_cpu_capacity(struct sched_domain *sd, int cpu)
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index ebb4b3c..b80c3fd 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -2210,17 +2210,33 @@ static inline unsigned long cpu_util_rt(struct rq *rq)
>  {
>   return READ_ONCE(rq->avg_rt.util_avg);
>  }
> +#endif
>  
> -#if defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> +#if defined(SMP) \
> + && (defined(CONFIG_IRQ_TIME_ACCOUNTING) || 
> defined(CONFIG_PARAVIRT_TIME_ACCOUNTING))
>  static inline unsigned long cpu_util_irq(struct rq *rq)
>  {
>   return rq->avg_irq.util_avg;
>  }
> +
> +static inline
> +unsigned long scale_irq_capacity(unsigned long util, unsigned long irq, 
> unsigned long max)
> +{
> + util *= (max - irq);

() can be dropped here. 

Other than that: 

Acked-by: Viresh Kumar 

-- 
viresh


Re: [PATCH v2] pinctrl: uniphier: add spi pin-mux settings

2018-07-19 Thread Masahiro Yamada
2018-07-19 18:05 GMT+09:00 Keiji Hayashibara :
> From: Kunihiko Hayashi 
>
> Add pin-mux settings for spi controller.
>
> Signed-off-by: Kunihiko Hayashi 
> Signed-off-by: Keiji Hayashibara 
> ---


Acked-by: Masahiro Yamada 



>  Changes since v1:
>  - Fix build error of "pinctrl-uniphier-sld8.c".
>
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c | 20 
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld4.c  |  5 +
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld6b.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pro4.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pro5.c | 15 +++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pxs2.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pxs3.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-sld8.c |  5 +
>  9 files changed, 95 insertions(+)
>
> diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c 
> b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c
> index 58825f6..bce533f 100644
> --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c
> +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c
> @@ -517,6 +517,10 @@ static const int i2c4_muxvals[] = {1, 1};
>  static const unsigned nand_pins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
>  15, 16, 17};
>  static const int nand_muxvals[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
> 0};
> +static const unsigned spi0_pins[] = {56, 57, 58, 59};
> +static const int spi0_muxvals[] = {0, 0, 0, 0};
> +static const unsigned spi1_pins[] = {169, 170, 171, 172};
> +static const int spi1_muxvals[] = {1, 1, 1, 1};
>  static const unsigned system_bus_pins[] = {1, 2, 6, 7, 8, 9, 10, 11, 12, 13,
>14, 15, 16, 17};
>  static const int system_bus_muxvals[] = {0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
> 2,
> @@ -596,6 +600,8 @@ static const struct uniphier_pinctrl_group 
> uniphier_ld11_groups[] = {
> UNIPHIER_PINCTRL_GROUP(i2c3),
> UNIPHIER_PINCTRL_GROUP(i2c4),
> UNIPHIER_PINCTRL_GROUP(nand),
> +   UNIPHIER_PINCTRL_GROUP(spi0),
> +   UNIPHIER_PINCTRL_GROUP(spi1),
> UNIPHIER_PINCTRL_GROUP(system_bus),
> UNIPHIER_PINCTRL_GROUP(system_bus_cs1),
> UNIPHIER_PINCTRL_GROUP(uart0),
> @@ -632,6 +638,8 @@ static const char * const i2c1_groups[] = {"i2c1"};
>  static const char * const i2c3_groups[] = {"i2c3"};
>  static const char * const i2c4_groups[] = {"i2c4"};
>  static const char * const nand_groups[] = {"nand"};
> +static const char * const spi0_groups[] = {"spi0"};
> +static const char * const spi1_groups[] = {"spi1"};
>  static const char * const system_bus_groups[] = {"system_bus",
>  "system_bus_cs1"};
>  static const char * const uart0_groups[] = {"uart0"};
> @@ -657,6 +665,8 @@ static const struct uniphier_pinmux_function 
> uniphier_ld11_functions[] = {
> UNIPHIER_PINMUX_FUNCTION(i2c3),
> UNIPHIER_PINMUX_FUNCTION(i2c4),
> UNIPHIER_PINMUX_FUNCTION(nand),
> +   UNIPHIER_PINMUX_FUNCTION(spi0),
> +   UNIPHIER_PINMUX_FUNCTION(spi1),
> UNIPHIER_PINMUX_FUNCTION(system_bus),
> UNIPHIER_PINMUX_FUNCTION(uart0),
> UNIPHIER_PINMUX_FUNCTION(uart1),
> diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c 
> b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c
> index 9f449b3..99f06fe 100644
> --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c
> +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c
> @@ -606,6 +606,14 @@ static const unsigned nand_pins[] = {3, 4, 5, 6, 7, 8, 
> 9, 10, 11, 12, 13, 14,
>  static const int nand_muxvals[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
> 0};
>  static const unsigned sd_pins[] = {10, 11, 12, 13, 14, 15, 16, 17};
>  static const int sd_muxvals[] = {3, 3, 3, 3, 3, 3, 3, 3};  /* No SDVOLC */
> +static const unsigned spi0_pins[] = {56, 57, 58, 59};
> +static const int spi0_muxvals[] = {0, 0, 0, 0};
> +static const unsigned spi1_pins[] = {169, 170, 171, 172};
> +static const int spi1_muxvals[] = {1, 1, 1, 1};
> +static const unsigned spi2_pins[] = {86, 87, 88, 89};
> +static const int spi2_muxvals[] = {1, 1, 1, 1};
> +static const unsigned spi3_pins[] = {74, 75, 76, 77};
> +static const int spi3_muxvals[] = {1, 1, 1, 1};
>  static const unsigned system_bus_pins[] = {1, 2, 6, 7, 8, 9, 10, 11, 12, 13,
>14, 15, 16, 17};
>  static const int system_bus_muxvals[] = {0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
> 2,
> @@ -685,6 +693,10 @@ static const struct uniphier_pinctrl_group 
> uniphier_ld20_groups[] = {
> UNIPHIER_PINCTRL_GROUP(i2c4),
> UNIPHIER_PINCTRL_GROUP(nand),
> UNIPHIER_PINCTRL_GROUP(sd),
> +   UNIPHIER_PINCTRL_GROUP(spi0),
> +   UNIPHIER_PINCTRL_GROUP(spi1),
> +   UNIPHIER_PINCTRL_GROUP(spi2),
> +   

Re: [PATCH v2] pinctrl: uniphier: add spi pin-mux settings

2018-07-19 Thread Masahiro Yamada
2018-07-19 18:05 GMT+09:00 Keiji Hayashibara :
> From: Kunihiko Hayashi 
>
> Add pin-mux settings for spi controller.
>
> Signed-off-by: Kunihiko Hayashi 
> Signed-off-by: Keiji Hayashibara 
> ---


Acked-by: Masahiro Yamada 



>  Changes since v1:
>  - Fix build error of "pinctrl-uniphier-sld8.c".
>
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c | 20 
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld4.c  |  5 +
>  drivers/pinctrl/uniphier/pinctrl-uniphier-ld6b.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pro4.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pro5.c | 15 +++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pxs2.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-pxs3.c | 10 ++
>  drivers/pinctrl/uniphier/pinctrl-uniphier-sld8.c |  5 +
>  9 files changed, 95 insertions(+)
>
> diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c 
> b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c
> index 58825f6..bce533f 100644
> --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c
> +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld11.c
> @@ -517,6 +517,10 @@ static const int i2c4_muxvals[] = {1, 1};
>  static const unsigned nand_pins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
>  15, 16, 17};
>  static const int nand_muxvals[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
> 0};
> +static const unsigned spi0_pins[] = {56, 57, 58, 59};
> +static const int spi0_muxvals[] = {0, 0, 0, 0};
> +static const unsigned spi1_pins[] = {169, 170, 171, 172};
> +static const int spi1_muxvals[] = {1, 1, 1, 1};
>  static const unsigned system_bus_pins[] = {1, 2, 6, 7, 8, 9, 10, 11, 12, 13,
>14, 15, 16, 17};
>  static const int system_bus_muxvals[] = {0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
> 2,
> @@ -596,6 +600,8 @@ static const struct uniphier_pinctrl_group 
> uniphier_ld11_groups[] = {
> UNIPHIER_PINCTRL_GROUP(i2c3),
> UNIPHIER_PINCTRL_GROUP(i2c4),
> UNIPHIER_PINCTRL_GROUP(nand),
> +   UNIPHIER_PINCTRL_GROUP(spi0),
> +   UNIPHIER_PINCTRL_GROUP(spi1),
> UNIPHIER_PINCTRL_GROUP(system_bus),
> UNIPHIER_PINCTRL_GROUP(system_bus_cs1),
> UNIPHIER_PINCTRL_GROUP(uart0),
> @@ -632,6 +638,8 @@ static const char * const i2c1_groups[] = {"i2c1"};
>  static const char * const i2c3_groups[] = {"i2c3"};
>  static const char * const i2c4_groups[] = {"i2c4"};
>  static const char * const nand_groups[] = {"nand"};
> +static const char * const spi0_groups[] = {"spi0"};
> +static const char * const spi1_groups[] = {"spi1"};
>  static const char * const system_bus_groups[] = {"system_bus",
>  "system_bus_cs1"};
>  static const char * const uart0_groups[] = {"uart0"};
> @@ -657,6 +665,8 @@ static const struct uniphier_pinmux_function 
> uniphier_ld11_functions[] = {
> UNIPHIER_PINMUX_FUNCTION(i2c3),
> UNIPHIER_PINMUX_FUNCTION(i2c4),
> UNIPHIER_PINMUX_FUNCTION(nand),
> +   UNIPHIER_PINMUX_FUNCTION(spi0),
> +   UNIPHIER_PINMUX_FUNCTION(spi1),
> UNIPHIER_PINMUX_FUNCTION(system_bus),
> UNIPHIER_PINMUX_FUNCTION(uart0),
> UNIPHIER_PINMUX_FUNCTION(uart1),
> diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c 
> b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c
> index 9f449b3..99f06fe 100644
> --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c
> +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-ld20.c
> @@ -606,6 +606,14 @@ static const unsigned nand_pins[] = {3, 4, 5, 6, 7, 8, 
> 9, 10, 11, 12, 13, 14,
>  static const int nand_muxvals[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
> 0};
>  static const unsigned sd_pins[] = {10, 11, 12, 13, 14, 15, 16, 17};
>  static const int sd_muxvals[] = {3, 3, 3, 3, 3, 3, 3, 3};  /* No SDVOLC */
> +static const unsigned spi0_pins[] = {56, 57, 58, 59};
> +static const int spi0_muxvals[] = {0, 0, 0, 0};
> +static const unsigned spi1_pins[] = {169, 170, 171, 172};
> +static const int spi1_muxvals[] = {1, 1, 1, 1};
> +static const unsigned spi2_pins[] = {86, 87, 88, 89};
> +static const int spi2_muxvals[] = {1, 1, 1, 1};
> +static const unsigned spi3_pins[] = {74, 75, 76, 77};
> +static const int spi3_muxvals[] = {1, 1, 1, 1};
>  static const unsigned system_bus_pins[] = {1, 2, 6, 7, 8, 9, 10, 11, 12, 13,
>14, 15, 16, 17};
>  static const int system_bus_muxvals[] = {0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
> 2,
> @@ -685,6 +693,10 @@ static const struct uniphier_pinctrl_group 
> uniphier_ld20_groups[] = {
> UNIPHIER_PINCTRL_GROUP(i2c4),
> UNIPHIER_PINCTRL_GROUP(nand),
> UNIPHIER_PINCTRL_GROUP(sd),
> +   UNIPHIER_PINCTRL_GROUP(spi0),
> +   UNIPHIER_PINCTRL_GROUP(spi1),
> +   UNIPHIER_PINCTRL_GROUP(spi2),
> +   

Re: [PATCHv2 2/2] arm64: Clear the stack

2018-07-19 Thread Kees Cook
On Thu, Jul 19, 2018 at 4:28 PM, Laura Abbott  wrote:
>
> Implementation of stackleak based heavily on the x86 version
>
> Signed-off-by: Laura Abbott 

This is the commit message I wrote when I was using an earlier
version, which I think is more descriptive:

arm64: Add support for STACKLEAK gcc plugin

This adds support for the STACKLEAK gcc plugin to arm64 by implementing
stackleak_check_alloca(), based heavily on the x86 version, and adding the
two helpers used by the stackleak common code: current_top_of_stack() and
on_thread_stack(). The stack erasure calls are made at syscall returns.
Additionally, this disables the plugin in hypervisor and EFI stub code,
which are out of scope for the protection.

Either way:

Reviewed-by: Kees Cook 

Thanks for getting this hammered out!

> ---
> v2: Convert to adjusted on_acessible_stack APIs. Fixed alloca check to
> just panic. Dropped the extra include per Kees. I also didn't add the
> Reviewed-by since the APIs did change and I wanted another pass.

Maybe the panic() should get a comment above it to describe why it's
there (i.e. summarize the thread where that change was discussed?) Or
maybe mention it in the commit log (instead of being only below the
--- line?)

-Kees

> ---
>  arch/arm64/Kconfig|  1 +
>  arch/arm64/include/asm/processor.h| 15 +++
>  arch/arm64/kernel/entry.S |  7 +++
>  arch/arm64/kernel/process.c   | 17 +
>  arch/arm64/kvm/hyp/Makefile   |  3 ++-
>  drivers/firmware/efi/libstub/Makefile |  3 ++-
>  6 files changed, 44 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 42c090cf0292..216d36a49ab5 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -96,6 +96,7 @@ config ARM64
> select HAVE_ARCH_MMAP_RND_BITS
> select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
> select HAVE_ARCH_SECCOMP_FILTER
> +   select HAVE_ARCH_STACKLEAK
> select HAVE_ARCH_THREAD_STRUCT_WHITELIST
> select HAVE_ARCH_TRACEHOOK
> select HAVE_ARCH_TRANSPARENT_HUGEPAGE
> diff --git a/arch/arm64/include/asm/processor.h 
> b/arch/arm64/include/asm/processor.h
> index a73ae1e49200..0061450a793b 100644
> --- a/arch/arm64/include/asm/processor.h
> +++ b/arch/arm64/include/asm/processor.h
> @@ -266,5 +266,20 @@ extern void __init minsigstksz_setup(void);
>  #define SVE_SET_VL(arg)sve_set_current_vl(arg)
>  #define SVE_GET_VL()   sve_get_current_vl()
>
> +/*
> + * For CONFIG_GCC_PLUGIN_STACKLEAK
> + *
> + * These need to be macros because otherwise we get stuck in a nightmare
> + * of header definitions for the use of task_stack_page.
> + */
> +
> +#define current_top_of_stack()   
>   \
> +({   
>   \
> +   struct stack_info _info;  
>   \
> +   BUG_ON(!on_accessible_stack(current, current_stack_pointer, &_info)); 
>   \
> +   _info.high;   
>   \
> +})
> +#define on_thread_stack()  (on_task_stack(current, 
> current_stack_pointer, NULL))
> +
>  #endif /* __ASSEMBLY__ */
>  #endif /* __ASM_PROCESSOR_H */
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 28ad8799406f..67d12016063d 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -431,6 +431,11 @@ tsk.reqx28 // current thread_info
>
> .text
>
> +   .macro  stackleak_erase
> +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
> +   bl  stackleak_erase
> +#endif
> +   .endm
>  /*
>   * Exception vectors.
>   */
> @@ -910,6 +915,7 @@ ret_fast_syscall:
> and x2, x1, #_TIF_WORK_MASK
> cbnzx2, work_pending
> enable_step_tsk x1, x2
> +   stackleak_erase
> kernel_exit 0
>  ret_fast_syscall_trace:
> enable_daif
> @@ -936,6 +942,7 @@ ret_to_user:
> cbnzx2, work_pending
>  finish_ret_to_user:
> enable_step_tsk x1, x2
> +   stackleak_erase
> kernel_exit 0
>  ENDPROC(ret_to_user)
>
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index e10bc363f533..2724e4d31b16 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -493,3 +493,20 @@ void arch_setup_new_exec(void)
>  {
> current->mm->context.flags = is_compat_task() ? MMCF_AARCH32 : 0;
>  }
> +
> +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
> +void __used stackleak_check_alloca(unsigned long size)
> +{
> +   unsigned long stack_left;
> +   unsigned long current_sp = current_stack_pointer;
> +   struct stack_info info;
> +
> +   BUG_ON(!on_accessible_stack(current, current_sp, ));
> +
> +   stack_left = current_sp - info.low;
> +
> +   if (size >= stack_left)
> +   panic("alloca() over 

Re: [PATCHv2 2/2] arm64: Clear the stack

2018-07-19 Thread Kees Cook
On Thu, Jul 19, 2018 at 4:28 PM, Laura Abbott  wrote:
>
> Implementation of stackleak based heavily on the x86 version
>
> Signed-off-by: Laura Abbott 

This is the commit message I wrote when I was using an earlier
version, which I think is more descriptive:

arm64: Add support for STACKLEAK gcc plugin

This adds support for the STACKLEAK gcc plugin to arm64 by implementing
stackleak_check_alloca(), based heavily on the x86 version, and adding the
two helpers used by the stackleak common code: current_top_of_stack() and
on_thread_stack(). The stack erasure calls are made at syscall returns.
Additionally, this disables the plugin in hypervisor and EFI stub code,
which are out of scope for the protection.

Either way:

Reviewed-by: Kees Cook 

Thanks for getting this hammered out!

> ---
> v2: Convert to adjusted on_acessible_stack APIs. Fixed alloca check to
> just panic. Dropped the extra include per Kees. I also didn't add the
> Reviewed-by since the APIs did change and I wanted another pass.

Maybe the panic() should get a comment above it to describe why it's
there (i.e. summarize the thread where that change was discussed?) Or
maybe mention it in the commit log (instead of being only below the
--- line?)

-Kees

> ---
>  arch/arm64/Kconfig|  1 +
>  arch/arm64/include/asm/processor.h| 15 +++
>  arch/arm64/kernel/entry.S |  7 +++
>  arch/arm64/kernel/process.c   | 17 +
>  arch/arm64/kvm/hyp/Makefile   |  3 ++-
>  drivers/firmware/efi/libstub/Makefile |  3 ++-
>  6 files changed, 44 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 42c090cf0292..216d36a49ab5 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -96,6 +96,7 @@ config ARM64
> select HAVE_ARCH_MMAP_RND_BITS
> select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
> select HAVE_ARCH_SECCOMP_FILTER
> +   select HAVE_ARCH_STACKLEAK
> select HAVE_ARCH_THREAD_STRUCT_WHITELIST
> select HAVE_ARCH_TRACEHOOK
> select HAVE_ARCH_TRANSPARENT_HUGEPAGE
> diff --git a/arch/arm64/include/asm/processor.h 
> b/arch/arm64/include/asm/processor.h
> index a73ae1e49200..0061450a793b 100644
> --- a/arch/arm64/include/asm/processor.h
> +++ b/arch/arm64/include/asm/processor.h
> @@ -266,5 +266,20 @@ extern void __init minsigstksz_setup(void);
>  #define SVE_SET_VL(arg)sve_set_current_vl(arg)
>  #define SVE_GET_VL()   sve_get_current_vl()
>
> +/*
> + * For CONFIG_GCC_PLUGIN_STACKLEAK
> + *
> + * These need to be macros because otherwise we get stuck in a nightmare
> + * of header definitions for the use of task_stack_page.
> + */
> +
> +#define current_top_of_stack()   
>   \
> +({   
>   \
> +   struct stack_info _info;  
>   \
> +   BUG_ON(!on_accessible_stack(current, current_stack_pointer, &_info)); 
>   \
> +   _info.high;   
>   \
> +})
> +#define on_thread_stack()  (on_task_stack(current, 
> current_stack_pointer, NULL))
> +
>  #endif /* __ASSEMBLY__ */
>  #endif /* __ASM_PROCESSOR_H */
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 28ad8799406f..67d12016063d 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -431,6 +431,11 @@ tsk.reqx28 // current thread_info
>
> .text
>
> +   .macro  stackleak_erase
> +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
> +   bl  stackleak_erase
> +#endif
> +   .endm
>  /*
>   * Exception vectors.
>   */
> @@ -910,6 +915,7 @@ ret_fast_syscall:
> and x2, x1, #_TIF_WORK_MASK
> cbnzx2, work_pending
> enable_step_tsk x1, x2
> +   stackleak_erase
> kernel_exit 0
>  ret_fast_syscall_trace:
> enable_daif
> @@ -936,6 +942,7 @@ ret_to_user:
> cbnzx2, work_pending
>  finish_ret_to_user:
> enable_step_tsk x1, x2
> +   stackleak_erase
> kernel_exit 0
>  ENDPROC(ret_to_user)
>
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index e10bc363f533..2724e4d31b16 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -493,3 +493,20 @@ void arch_setup_new_exec(void)
>  {
> current->mm->context.flags = is_compat_task() ? MMCF_AARCH32 : 0;
>  }
> +
> +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
> +void __used stackleak_check_alloca(unsigned long size)
> +{
> +   unsigned long stack_left;
> +   unsigned long current_sp = current_stack_pointer;
> +   struct stack_info info;
> +
> +   BUG_ON(!on_accessible_stack(current, current_sp, ));
> +
> +   stack_left = current_sp - info.low;
> +
> +   if (size >= stack_left)
> +   panic("alloca() over 

Re: [RFC PATCH] EDAC, ghes: Enable per-layer error reporting for ARM

2018-07-19 Thread Borislav Petkov
On Thu, Jul 19, 2018 at 02:36:21PM -0400, Tyler Baicar wrote:
> With the current ghes_edac setup, it seems the only way this could
> work would be to have the firmware always report the module value to

My experience with firmware so far is that it is a lost cause,
considering all the bugs, snafus and incompleteness it demonstrates...

> The other obvious but more messy way would be to have notifiers
> register to be called by ghes_edac and have a custom EDAC driver for
> each CPU to properly populate their layer information.

... which is what we do on x86 and whitelist only known-good platforms
in ghes_edac, which claim that their fw info is correct.

-- 
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.
--


Re: [RFC PATCH] EDAC, ghes: Enable per-layer error reporting for ARM

2018-07-19 Thread Borislav Petkov
On Thu, Jul 19, 2018 at 02:36:21PM -0400, Tyler Baicar wrote:
> With the current ghes_edac setup, it seems the only way this could
> work would be to have the firmware always report the module value to

My experience with firmware so far is that it is a lost cause,
considering all the bugs, snafus and incompleteness it demonstrates...

> The other obvious but more messy way would be to have notifiers
> register to be called by ghes_edac and have a custom EDAC driver for
> each CPU to properly populate their layer information.

... which is what we do on x86 and whitelist only known-good platforms
in ghes_edac, which claim that their fw info is correct.

-- 
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.
--


[PATCH] Drivers: staging: rts5208: xd.c fixed a brace coding style issue

2018-07-19 Thread Ali Aminian
Fixing a coding style issue

Signed-off-by: Ali Aminian 
---
 drivers/staging/rts5208/xd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/rts5208/xd.c b/drivers/staging/rts5208/xd.c
index 667dfe1..261d868 100644
--- a/drivers/staging/rts5208/xd.c
+++ b/drivers/staging/rts5208/xd.c
@@ -787,9 +787,8 @@ static int reset_xd(struct rtsx_chip *chip)
}
 
dev_dbg(rtsx_dev(chip), "CIS block: 0x%x\n", xd_card->cis_block);
-   if (xd_card->cis_block == 0x) {
+   if (xd_card->cis_block == 0x)
return STATUS_FAIL;
-   }
 
chip->capacity[chip->card2lun[XD_CARD]] = xd_card->capacity;
 
-- 
2.7.4



[PATCH 1/1] x86/hyper-v: Fix a merge error

2018-07-19 Thread kys
From: "K. Y. Srinivasan" 

When the mapping betwween the Linux notion of CPU ID
to the hypervisor's notion of CPU ID is not initialized,
we should fall back on the non-enligghtened path for IPI.
A merge error introduced this bug; fix it.

Fixes: 1268ed0c474a ("Merge branch 'x86/urgent' into x86/hyperv")

Reported-by: Michael Kelley 
Signed-off-by: K. Y. Srinivasan 
---
 arch/x86/hyperv/hv_apic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
index 0c3c9f8fee77..5b0f613428c2 100644
--- a/arch/x86/hyperv/hv_apic.c
+++ b/arch/x86/hyperv/hv_apic.c
@@ -168,7 +168,7 @@ static bool __send_ipi_mask(const struct cpumask *mask, int 
vector)
for_each_cpu(cur_cpu, mask) {
vcpu = hv_cpu_number_to_vp_number(cur_cpu);
if (vcpu == VP_INVAL)
-   return true;
+   return false;
 
/*
 * This particular version of the IPI hypercall can
-- 
2.17.1



[PATCH 1/1] x86/hyper-v: Fix a merge error

2018-07-19 Thread kys
From: "K. Y. Srinivasan" 

When the mapping betwween the Linux notion of CPU ID
to the hypervisor's notion of CPU ID is not initialized,
we should fall back on the non-enligghtened path for IPI.
A merge error introduced this bug; fix it.

Fixes: 1268ed0c474a ("Merge branch 'x86/urgent' into x86/hyperv")

Reported-by: Michael Kelley 
Signed-off-by: K. Y. Srinivasan 
---
 arch/x86/hyperv/hv_apic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c
index 0c3c9f8fee77..5b0f613428c2 100644
--- a/arch/x86/hyperv/hv_apic.c
+++ b/arch/x86/hyperv/hv_apic.c
@@ -168,7 +168,7 @@ static bool __send_ipi_mask(const struct cpumask *mask, int 
vector)
for_each_cpu(cur_cpu, mask) {
vcpu = hv_cpu_number_to_vp_number(cur_cpu);
if (vcpu == VP_INVAL)
-   return true;
+   return false;
 
/*
 * This particular version of the IPI hypercall can
-- 
2.17.1



[PATCH] Drivers: staging: rts5208: xd.c fixed a brace coding style issue

2018-07-19 Thread Ali Aminian
Fixing a coding style issue

Signed-off-by: Ali Aminian 
---
 drivers/staging/rts5208/xd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/rts5208/xd.c b/drivers/staging/rts5208/xd.c
index 667dfe1..261d868 100644
--- a/drivers/staging/rts5208/xd.c
+++ b/drivers/staging/rts5208/xd.c
@@ -787,9 +787,8 @@ static int reset_xd(struct rtsx_chip *chip)
}
 
dev_dbg(rtsx_dev(chip), "CIS block: 0x%x\n", xd_card->cis_block);
-   if (xd_card->cis_block == 0x) {
+   if (xd_card->cis_block == 0x)
return STATUS_FAIL;
-   }
 
chip->capacity[chip->card2lun[XD_CARD]] = xd_card->capacity;
 
-- 
2.7.4



RE: [PATCH V3 0/4] KVM/x86/hyper-V: Introduce PV guest address space mapping flush support

2018-07-19 Thread KY Srinivasan



> -Original Message-
> From: Tianyu Lan
> Sent: Thursday, July 19, 2018 1:40 AM
> Cc: Tianyu Lan ; de...@linuxdriverproject.org;
> Haiyang Zhang ; h...@zytor.com;
> k...@vger.kernel.org; KY Srinivasan ; linux-
> ker...@vger.kernel.org; mi...@redhat.com; pbonz...@redhat.com;
> rkrc...@redhat.com; Stephen Hemminger ;
> t...@linutronix.de; x...@kernel.org; Michael Kelley (EOSG)
> ; vkuzn...@redhat.com
> Subject: [PATCH V3 0/4] KVM/x86/hyper-V: Introduce PV guest address
> space mapping flush support
> 
> Hyper-V provides a para-virtualization hypercall
> HvFlushGuestPhysicalAddressSpace
> to flush nested VM address space mapping in l1 hypervisor and it's to reduce
> overhead
> of flushing ept tlb among vcpus. The tradition way is to send IPIs to all
> affected
> vcpus and executes INVEPT on each vcpus. It will trigger several vmexits for
> IPI and
> INVEPT emulation. The pv hypercall can help to flush specified ept table on 
> all
> vcpus
> via one single hypercall.
> 
> Change since v2:
>- Make ept_pointers_match as tristate "check", "match" and "mismatch".
>Set "check" in vmx_set_cr3(), check all ept table pointers in
> hv_remote_flush_tlb()
>and call hypercall when all ept pointers are same.
>- Rename kvm_arch_hv_flush_remote_tlb with
> kvm_arch_flush_remote_tlb and
>Rename kvm_x86_ops->hv_tlb_remote_flush with kvm_x86_ops-
> >tlb_remote_flush
>- Fix issue that ignore updating tlbs_dirty during calling
> kvm_arch_flush_remote_tlbs()
>- Merge patch "KVM/VMX: Add identical ept table pointer check" and
>patch "KVM/x86: Add tlb_remote_flush callback support for vmx"
> 
> Change since v1:
>- Fix compilation error for non-x86 platform.
>- Use ept_pointers_match to check condition of identical ept
> table pointer and get ept pointer from struct 
> vcpu_vmx->ept_pointer.
>- Add hyperv_nested_flush_guest_mapping ftrace support
> 
> 
> 
> Lan Tianyu (4):
>   X86/Hyper-V: Add flush HvFlushGuestPhysicalAddressSpace hypercall
> support
>   X86/Hyper-V: Add hyperv_nested_flush_guest_mapping ftrace support
>   KVM: Add tlb remote flush callback in kvm_x86_ops.
>   KVM/x86: Add tlb_remote_flush callback support for vmx
> 
>  arch/x86/hyperv/Makefile|  2 +-
>  arch/x86/hyperv/nested.c| 67
> ++
>  arch/x86/include/asm/hyperv-tlfs.h  |  8 +
>  arch/x86/include/asm/kvm_host.h | 11 ++
>  arch/x86/include/asm/mshyperv.h |  2 ++
>  arch/x86/include/asm/trace/hyperv.h | 14 
>  arch/x86/kvm/vmx.c  | 72
> -
>  include/linux/kvm_host.h|  7 
>  virt/kvm/kvm_main.c |  3 +-
>  9 files changed, 183 insertions(+), 3 deletions(-)
>  create mode 100644 arch/x86/hyperv/nested.c

Acked-by: K. Y. Srinivasan 

> 
> --
> 2.14.3


RE: [PATCH V3 0/4] KVM/x86/hyper-V: Introduce PV guest address space mapping flush support

2018-07-19 Thread KY Srinivasan



> -Original Message-
> From: Tianyu Lan
> Sent: Thursday, July 19, 2018 1:40 AM
> Cc: Tianyu Lan ; de...@linuxdriverproject.org;
> Haiyang Zhang ; h...@zytor.com;
> k...@vger.kernel.org; KY Srinivasan ; linux-
> ker...@vger.kernel.org; mi...@redhat.com; pbonz...@redhat.com;
> rkrc...@redhat.com; Stephen Hemminger ;
> t...@linutronix.de; x...@kernel.org; Michael Kelley (EOSG)
> ; vkuzn...@redhat.com
> Subject: [PATCH V3 0/4] KVM/x86/hyper-V: Introduce PV guest address
> space mapping flush support
> 
> Hyper-V provides a para-virtualization hypercall
> HvFlushGuestPhysicalAddressSpace
> to flush nested VM address space mapping in l1 hypervisor and it's to reduce
> overhead
> of flushing ept tlb among vcpus. The tradition way is to send IPIs to all
> affected
> vcpus and executes INVEPT on each vcpus. It will trigger several vmexits for
> IPI and
> INVEPT emulation. The pv hypercall can help to flush specified ept table on 
> all
> vcpus
> via one single hypercall.
> 
> Change since v2:
>- Make ept_pointers_match as tristate "check", "match" and "mismatch".
>Set "check" in vmx_set_cr3(), check all ept table pointers in
> hv_remote_flush_tlb()
>and call hypercall when all ept pointers are same.
>- Rename kvm_arch_hv_flush_remote_tlb with
> kvm_arch_flush_remote_tlb and
>Rename kvm_x86_ops->hv_tlb_remote_flush with kvm_x86_ops-
> >tlb_remote_flush
>- Fix issue that ignore updating tlbs_dirty during calling
> kvm_arch_flush_remote_tlbs()
>- Merge patch "KVM/VMX: Add identical ept table pointer check" and
>patch "KVM/x86: Add tlb_remote_flush callback support for vmx"
> 
> Change since v1:
>- Fix compilation error for non-x86 platform.
>- Use ept_pointers_match to check condition of identical ept
> table pointer and get ept pointer from struct 
> vcpu_vmx->ept_pointer.
>- Add hyperv_nested_flush_guest_mapping ftrace support
> 
> 
> 
> Lan Tianyu (4):
>   X86/Hyper-V: Add flush HvFlushGuestPhysicalAddressSpace hypercall
> support
>   X86/Hyper-V: Add hyperv_nested_flush_guest_mapping ftrace support
>   KVM: Add tlb remote flush callback in kvm_x86_ops.
>   KVM/x86: Add tlb_remote_flush callback support for vmx
> 
>  arch/x86/hyperv/Makefile|  2 +-
>  arch/x86/hyperv/nested.c| 67
> ++
>  arch/x86/include/asm/hyperv-tlfs.h  |  8 +
>  arch/x86/include/asm/kvm_host.h | 11 ++
>  arch/x86/include/asm/mshyperv.h |  2 ++
>  arch/x86/include/asm/trace/hyperv.h | 14 
>  arch/x86/kvm/vmx.c  | 72
> -
>  include/linux/kvm_host.h|  7 
>  virt/kvm/kvm_main.c |  3 +-
>  9 files changed, 183 insertions(+), 3 deletions(-)
>  create mode 100644 arch/x86/hyperv/nested.c

Acked-by: K. Y. Srinivasan 

> 
> --
> 2.14.3


Re: [PATCH v3 5/6] KVM: X86: Add NMI support to PV IPIs

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:31, Radim Krčmář  wrote:
>
> 2018-07-03 14:21+0800, Wanpeng Li:
> > From: Wanpeng Li 
> >
> > The NMI delivery mode of ICR is used to deliver an NMI to the processor,
> > and the vector information is ignored.
> >
> > Cc: Paolo Bonzini 
> > Cc: Radim Krčmář 
> > Cc: Vitaly Kuznetsov 
> > Signed-off-by: Wanpeng Li 
> > ---
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > @@ -479,7 +479,16 @@ static int __send_ipi_mask(const struct cpumask *mask, 
> > int vector)
> >   }
> >   }
> >
> > - ret = kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, 
> > ipi_bitmap_high, vector);
> > + switch (vector) {
> > + default:
> > + icr = APIC_DM_FIXED | vector;
> > + break;
> > + case NMI_VECTOR:
> > + icr = APIC_DM_NMI;
>
> I think it would be better to say that KVM interprets NMI_VECTOR and
> sends the interrupt as APIC_DM_NMI.

Yeah, in addition, SDM 10.6.1 also mentioned that:
Delivery mode:
100 (NMI) Delivers an NMI interrupt to the target processor or
processors. The vector information is ignored.

Regards,
Wanpeng Li


Re: [PATCH v3 5/6] KVM: X86: Add NMI support to PV IPIs

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:31, Radim Krčmář  wrote:
>
> 2018-07-03 14:21+0800, Wanpeng Li:
> > From: Wanpeng Li 
> >
> > The NMI delivery mode of ICR is used to deliver an NMI to the processor,
> > and the vector information is ignored.
> >
> > Cc: Paolo Bonzini 
> > Cc: Radim Krčmář 
> > Cc: Vitaly Kuznetsov 
> > Signed-off-by: Wanpeng Li 
> > ---
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > @@ -479,7 +479,16 @@ static int __send_ipi_mask(const struct cpumask *mask, 
> > int vector)
> >   }
> >   }
> >
> > - ret = kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, 
> > ipi_bitmap_high, vector);
> > + switch (vector) {
> > + default:
> > + icr = APIC_DM_FIXED | vector;
> > + break;
> > + case NMI_VECTOR:
> > + icr = APIC_DM_NMI;
>
> I think it would be better to say that KVM interprets NMI_VECTOR and
> sends the interrupt as APIC_DM_NMI.

Yeah, in addition, SDM 10.6.1 also mentioned that:
Delivery mode:
100 (NMI) Delivers an NMI interrupt to the target processor or
processors. The vector information is ignored.

Regards,
Wanpeng Li


[PATCH 01/20] staging: gasket: allow compile for ARM64 in Kconfig

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

The gasket and apex drivers are also to be used on ARM64 architectures.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/Kconfig b/drivers/staging/gasket/Kconfig
index c836389c1402d..970e299046c37 100644
--- a/drivers/staging/gasket/Kconfig
+++ b/drivers/staging/gasket/Kconfig
@@ -2,7 +2,7 @@ menu "Gasket devices"
 
 config STAGING_GASKET_FRAMEWORK
tristate "Gasket framework"
-   depends on PCI && X86_64
+   depends on PCI && (X86_64 || ARM64)
help
  This framework supports Gasket-compatible devices, such as Apex.
  It is required for any of the following module(s).
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 01/20] staging: gasket: allow compile for ARM64 in Kconfig

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

The gasket and apex drivers are also to be used on ARM64 architectures.

Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/Kconfig b/drivers/staging/gasket/Kconfig
index c836389c1402d..970e299046c37 100644
--- a/drivers/staging/gasket/Kconfig
+++ b/drivers/staging/gasket/Kconfig
@@ -2,7 +2,7 @@ menu "Gasket devices"
 
 config STAGING_GASKET_FRAMEWORK
tristate "Gasket framework"
-   depends on PCI && X86_64
+   depends on PCI && (X86_64 || ARM64)
help
  This framework supports Gasket-compatible devices, such as Apex.
  It is required for any of the following module(s).
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 09/20] staging: gasket: gasket page table functions use bool return type

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Convert from int to bool return type for gasket page table functions
that return values used as booleans.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 58 +++---
 drivers/staging/gasket/gasket_page_table.h |  8 +--
 2 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 36a560c87af36..2a27db658a4e4 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -262,16 +262,16 @@ static void gasket_perform_unmapping(
 static void gasket_free_extended_subtable(
struct gasket_page_table *pg_tbl, struct gasket_page_table_entry *pte,
u64 __iomem *att_reg);
-static int gasket_release_page(struct page *page);
+static bool gasket_release_page(struct page *page);
 
 /* Other/utility declarations */
-static inline int gasket_addr_is_simple(
+static inline bool gasket_addr_is_simple(
struct gasket_page_table *pg_tbl, ulong addr);
-static int gasket_is_simple_dev_addr_bad(
+static bool gasket_is_simple_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, uint num_pages);
-static int gasket_is_extended_dev_addr_bad(
+static bool gasket_is_extended_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, uint num_pages);
-static int gasket_is_pte_range_free(
+static bool gasket_is_pte_range_free(
struct gasket_page_table_entry *pte, uint num_entries);
 static void gasket_page_table_garbage_collect_nolock(
struct gasket_page_table *pg_tbl);
@@ -558,7 +558,7 @@ int gasket_page_table_lookup_page(
 }
 
 /* See gasket_page_table.h for description. */
-int gasket_page_table_are_addrs_bad(
+bool gasket_page_table_are_addrs_bad(
struct gasket_page_table *pg_tbl, ulong host_addr, ulong dev_addr,
ulong bytes)
 {
@@ -567,7 +567,7 @@ int gasket_page_table_are_addrs_bad(
pg_tbl,
"host mapping address 0x%lx must be page aligned",
host_addr);
-   return 1;
+   return true;
}
 
return gasket_page_table_is_dev_addr_bad(pg_tbl, dev_addr, bytes);
@@ -575,7 +575,7 @@ int gasket_page_table_are_addrs_bad(
 EXPORT_SYMBOL(gasket_page_table_are_addrs_bad);
 
 /* See gasket_page_table.h for description. */
-int gasket_page_table_is_dev_addr_bad(
+bool gasket_page_table_is_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, ulong bytes)
 {
uint num_pages = bytes / PAGE_SIZE;
@@ -584,7 +584,7 @@ int gasket_page_table_is_dev_addr_bad(
gasket_pg_tbl_error(
pg_tbl,
"mapping size 0x%lX must be page aligned", bytes);
-   return 1;
+   return true;
}
 
if (num_pages == 0) {
@@ -592,7 +592,7 @@ int gasket_page_table_is_dev_addr_bad(
pg_tbl,
"requested mapping is less than one page: %lu / %lu",
bytes, PAGE_SIZE);
-   return 1;
+   return true;
}
 
if (gasket_addr_is_simple(pg_tbl, dev_addr))
@@ -1285,23 +1285,23 @@ static void gasket_free_extended_subtable(
 /*
  * Safely return a page to the OS.
  * @page: The page to return to the OS.
- * Returns 1 if the page was released, 0 if it was
+ * Returns true if the page was released, false if it was
  * ignored.
  */
-static int gasket_release_page(struct page *page)
+static bool gasket_release_page(struct page *page)
 {
if (!page)
-   return 0;
+   return false;
 
if (!PageReserved(page))
SetPageDirty(page);
put_page(page);
 
-   return 1;
+   return true;
 }
 
 /* Evaluates to nonzero if the specified virtual address is simple. */
-static inline int gasket_addr_is_simple(
+static inline bool gasket_addr_is_simple(
struct gasket_page_table *pg_tbl, ulong addr)
 {
return !((addr) & (pg_tbl)->extended_flag);
@@ -1317,7 +1317,7 @@ static inline int gasket_addr_is_simple(
  * address to/from page + offset) and that the requested page range starts and
  * ends within the set of currently-partitioned simple pages.
  */
-static int gasket_is_simple_dev_addr_bad(
+static bool gasket_is_simple_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, uint num_pages)
 {
ulong page_offset = dev_addr & (PAGE_SIZE - 1);
@@ -1328,7 +1328,7 @@ static int gasket_is_simple_dev_addr_bad(
pg_tbl, 1, page_index, page_offset) != dev_addr) {
gasket_pg_tbl_error(
pg_tbl, "address is invalid, 0x%lX", dev_addr);
-   return 1;
+   return true;
}
 
if (page_index >= pg_tbl->num_simple_entries) {
@@ -1336,7 +1336,7 @@ static 

[PATCH 03/20] staging: gasket: remove code for no physical device

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

gasket_enable_dev code for enabling a gasket device with no physical PCI
device registered shouldn't be necessary.

Reported-by: Greg Kroah-Hartman 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index f327c9d7f90a3..18cc8e3283b39 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -898,7 +898,6 @@ static int gasket_enable_dev(
 {
int tbl_idx;
int ret;
-   struct device *ddev;
const struct gasket_driver_desc *driver_desc =
internal_desc->driver_desc;
 
@@ -919,21 +918,12 @@ static int gasket_enable_dev(
for (tbl_idx = 0; tbl_idx < driver_desc->num_page_tables; tbl_idx++) {
gasket_log_debug(
gasket_dev, "Initializing page table %d.", tbl_idx);
-   if (gasket_dev->pci_dev) {
-   ddev = _dev->pci_dev->dev;
-   } else {
-   gasket_log_error(
-   gasket_dev,
-   "%s with no physical device!!", __func__);
-   WARN_ON(1);
-   ddev = NULL;
-   }
ret = gasket_page_table_init(
_dev->page_table[tbl_idx],
_dev->bar_data[
driver_desc->page_table_bar_index],
_desc->page_table_configs[tbl_idx],
-   ddev, gasket_dev->pci_dev, true);
+   _dev->pci_dev->dev, gasket_dev->pci_dev, true);
if (ret) {
gasket_log_error(
gasket_dev,
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 03/20] staging: gasket: remove code for no physical device

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

gasket_enable_dev code for enabling a gasket device with no physical PCI
device registered shouldn't be necessary.

Reported-by: Greg Kroah-Hartman 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index f327c9d7f90a3..18cc8e3283b39 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -898,7 +898,6 @@ static int gasket_enable_dev(
 {
int tbl_idx;
int ret;
-   struct device *ddev;
const struct gasket_driver_desc *driver_desc =
internal_desc->driver_desc;
 
@@ -919,21 +918,12 @@ static int gasket_enable_dev(
for (tbl_idx = 0; tbl_idx < driver_desc->num_page_tables; tbl_idx++) {
gasket_log_debug(
gasket_dev, "Initializing page table %d.", tbl_idx);
-   if (gasket_dev->pci_dev) {
-   ddev = _dev->pci_dev->dev;
-   } else {
-   gasket_log_error(
-   gasket_dev,
-   "%s with no physical device!!", __func__);
-   WARN_ON(1);
-   ddev = NULL;
-   }
ret = gasket_page_table_init(
_dev->page_table[tbl_idx],
_dev->bar_data[
driver_desc->page_table_bar_index],
_desc->page_table_configs[tbl_idx],
-   ddev, gasket_dev->pci_dev, true);
+   _dev->pci_dev->dev, gasket_dev->pci_dev, true);
if (ret) {
gasket_log_error(
gasket_dev,
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 09/20] staging: gasket: gasket page table functions use bool return type

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Convert from int to bool return type for gasket page table functions
that return values used as booleans.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 58 +++---
 drivers/staging/gasket/gasket_page_table.h |  8 +--
 2 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 36a560c87af36..2a27db658a4e4 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -262,16 +262,16 @@ static void gasket_perform_unmapping(
 static void gasket_free_extended_subtable(
struct gasket_page_table *pg_tbl, struct gasket_page_table_entry *pte,
u64 __iomem *att_reg);
-static int gasket_release_page(struct page *page);
+static bool gasket_release_page(struct page *page);
 
 /* Other/utility declarations */
-static inline int gasket_addr_is_simple(
+static inline bool gasket_addr_is_simple(
struct gasket_page_table *pg_tbl, ulong addr);
-static int gasket_is_simple_dev_addr_bad(
+static bool gasket_is_simple_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, uint num_pages);
-static int gasket_is_extended_dev_addr_bad(
+static bool gasket_is_extended_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, uint num_pages);
-static int gasket_is_pte_range_free(
+static bool gasket_is_pte_range_free(
struct gasket_page_table_entry *pte, uint num_entries);
 static void gasket_page_table_garbage_collect_nolock(
struct gasket_page_table *pg_tbl);
@@ -558,7 +558,7 @@ int gasket_page_table_lookup_page(
 }
 
 /* See gasket_page_table.h for description. */
-int gasket_page_table_are_addrs_bad(
+bool gasket_page_table_are_addrs_bad(
struct gasket_page_table *pg_tbl, ulong host_addr, ulong dev_addr,
ulong bytes)
 {
@@ -567,7 +567,7 @@ int gasket_page_table_are_addrs_bad(
pg_tbl,
"host mapping address 0x%lx must be page aligned",
host_addr);
-   return 1;
+   return true;
}
 
return gasket_page_table_is_dev_addr_bad(pg_tbl, dev_addr, bytes);
@@ -575,7 +575,7 @@ int gasket_page_table_are_addrs_bad(
 EXPORT_SYMBOL(gasket_page_table_are_addrs_bad);
 
 /* See gasket_page_table.h for description. */
-int gasket_page_table_is_dev_addr_bad(
+bool gasket_page_table_is_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, ulong bytes)
 {
uint num_pages = bytes / PAGE_SIZE;
@@ -584,7 +584,7 @@ int gasket_page_table_is_dev_addr_bad(
gasket_pg_tbl_error(
pg_tbl,
"mapping size 0x%lX must be page aligned", bytes);
-   return 1;
+   return true;
}
 
if (num_pages == 0) {
@@ -592,7 +592,7 @@ int gasket_page_table_is_dev_addr_bad(
pg_tbl,
"requested mapping is less than one page: %lu / %lu",
bytes, PAGE_SIZE);
-   return 1;
+   return true;
}
 
if (gasket_addr_is_simple(pg_tbl, dev_addr))
@@ -1285,23 +1285,23 @@ static void gasket_free_extended_subtable(
 /*
  * Safely return a page to the OS.
  * @page: The page to return to the OS.
- * Returns 1 if the page was released, 0 if it was
+ * Returns true if the page was released, false if it was
  * ignored.
  */
-static int gasket_release_page(struct page *page)
+static bool gasket_release_page(struct page *page)
 {
if (!page)
-   return 0;
+   return false;
 
if (!PageReserved(page))
SetPageDirty(page);
put_page(page);
 
-   return 1;
+   return true;
 }
 
 /* Evaluates to nonzero if the specified virtual address is simple. */
-static inline int gasket_addr_is_simple(
+static inline bool gasket_addr_is_simple(
struct gasket_page_table *pg_tbl, ulong addr)
 {
return !((addr) & (pg_tbl)->extended_flag);
@@ -1317,7 +1317,7 @@ static inline int gasket_addr_is_simple(
  * address to/from page + offset) and that the requested page range starts and
  * ends within the set of currently-partitioned simple pages.
  */
-static int gasket_is_simple_dev_addr_bad(
+static bool gasket_is_simple_dev_addr_bad(
struct gasket_page_table *pg_tbl, ulong dev_addr, uint num_pages)
 {
ulong page_offset = dev_addr & (PAGE_SIZE - 1);
@@ -1328,7 +1328,7 @@ static int gasket_is_simple_dev_addr_bad(
pg_tbl, 1, page_index, page_offset) != dev_addr) {
gasket_pg_tbl_error(
pg_tbl, "address is invalid, 0x%lX", dev_addr);
-   return 1;
+   return true;
}
 
if (page_index >= pg_tbl->num_simple_entries) {
@@ -1336,7 +1336,7 @@ static 

[PATCH 08/20] staging: gasket: apex_clock_gating simplify logic, reduce indentation

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Collapse together two checks and return immediately, avoid conditional
indentation for most of function code.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c | 43 +---
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index 3a83c3d4d5561..a01b1f2b827ea 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -666,33 +666,30 @@ static long apex_clock_gating(struct gasket_dev 
*gasket_dev, ulong arg)
 {
struct apex_gate_clock_ioctl ibuf;
 
-   if (bypass_top_level)
+   if (bypass_top_level || !allow_sw_clock_gating)
return 0;
 
-   if (allow_sw_clock_gating) {
-   if (copy_from_user(, (void __user *)arg, sizeof(ibuf)))
-   return -EFAULT;
+   if (copy_from_user(, (void __user *)arg, sizeof(ibuf)))
+   return -EFAULT;
 
-   gasket_log_error(
-   gasket_dev, "%s %llu", __func__, ibuf.enable);
+   gasket_log_error(gasket_dev, "%s %llu", __func__, ibuf.enable);
 
-   if (ibuf.enable) {
-   /* Quiesce AXI, gate GCB clock. */
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_AXI_QUIESCE, 0x1, 1, 16);
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x1, 2, 18);
-   } else {
-   /* Un-gate GCB clock, un-quiesce AXI. */
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x0, 2, 18);
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_AXI_QUIESCE, 0x0, 1, 16);
-   }
+   if (ibuf.enable) {
+   /* Quiesce AXI, gate GCB clock. */
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_AXI_QUIESCE, 0x1, 1, 16);
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x1, 2, 18);
+   } else {
+   /* Un-gate GCB clock, un-quiesce AXI. */
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x0, 2, 18);
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_AXI_QUIESCE, 0x0, 1, 16);
}
return 0;
 }
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 06/20] staging: gasket: don't treat no device reset callback as an error

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

It is not an error for a device to not have a reset callback registered.

Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 53236e1ba4e48..eb5ad161ccda2 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1836,11 +1836,8 @@ int gasket_reset_nolock(struct gasket_dev *gasket_dev, 
uint reset_type)
const struct gasket_driver_desc *driver_desc;
 
driver_desc = gasket_dev->internal_desc->driver_desc;
-   if (!driver_desc->device_reset_cb) {
-   gasket_log_error(
-   gasket_dev, "No device reset callback was registered.");
-   return -EINVAL;
-   }
+   if (!driver_desc->device_reset_cb)
+   return 0;
 
/* Perform a device reset of the requested type. */
ret = driver_desc->device_reset_cb(gasket_dev, reset_type);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 05/20] staging: gasket: remove unnecessary code in coherent allocator

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Remove extraneous statement in gasket_config_coherent_allocator()

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 0c2f85cf54480..d0142ed048a65 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -420,10 +420,8 @@ static int gasket_config_coherent_allocator(
if (ibuf.page_table_index >= gasket_dev->num_page_tables)
return -EFAULT;
 
-   if (ibuf.size > PAGE_SIZE * MAX_NUM_COHERENT_PAGES) {
-   ibuf.size = PAGE_SIZE * MAX_NUM_COHERENT_PAGES;
+   if (ibuf.size > PAGE_SIZE * MAX_NUM_COHERENT_PAGES)
return -ENOMEM;
-   }
 
if (ibuf.enable == 0) {
ret = gasket_free_coherent_memory(
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 08/20] staging: gasket: apex_clock_gating simplify logic, reduce indentation

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Collapse together two checks and return immediately, avoid conditional
indentation for most of function code.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c | 43 +---
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index 3a83c3d4d5561..a01b1f2b827ea 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -666,33 +666,30 @@ static long apex_clock_gating(struct gasket_dev 
*gasket_dev, ulong arg)
 {
struct apex_gate_clock_ioctl ibuf;
 
-   if (bypass_top_level)
+   if (bypass_top_level || !allow_sw_clock_gating)
return 0;
 
-   if (allow_sw_clock_gating) {
-   if (copy_from_user(, (void __user *)arg, sizeof(ibuf)))
-   return -EFAULT;
+   if (copy_from_user(, (void __user *)arg, sizeof(ibuf)))
+   return -EFAULT;
 
-   gasket_log_error(
-   gasket_dev, "%s %llu", __func__, ibuf.enable);
+   gasket_log_error(gasket_dev, "%s %llu", __func__, ibuf.enable);
 
-   if (ibuf.enable) {
-   /* Quiesce AXI, gate GCB clock. */
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_AXI_QUIESCE, 0x1, 1, 16);
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x1, 2, 18);
-   } else {
-   /* Un-gate GCB clock, un-quiesce AXI. */
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x0, 2, 18);
-   gasket_read_modify_write_32(
-   gasket_dev, APEX_BAR_INDEX,
-   APEX_BAR2_REG_AXI_QUIESCE, 0x0, 1, 16);
-   }
+   if (ibuf.enable) {
+   /* Quiesce AXI, gate GCB clock. */
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_AXI_QUIESCE, 0x1, 1, 16);
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x1, 2, 18);
+   } else {
+   /* Un-gate GCB clock, un-quiesce AXI. */
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_GCB_CLOCK_GATE, 0x0, 2, 18);
+   gasket_read_modify_write_32(
+   gasket_dev, APEX_BAR_INDEX,
+   APEX_BAR2_REG_AXI_QUIESCE, 0x0, 1, 16);
}
return 0;
 }
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 06/20] staging: gasket: don't treat no device reset callback as an error

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

It is not an error for a device to not have a reset callback registered.

Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 53236e1ba4e48..eb5ad161ccda2 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1836,11 +1836,8 @@ int gasket_reset_nolock(struct gasket_dev *gasket_dev, 
uint reset_type)
const struct gasket_driver_desc *driver_desc;
 
driver_desc = gasket_dev->internal_desc->driver_desc;
-   if (!driver_desc->device_reset_cb) {
-   gasket_log_error(
-   gasket_dev, "No device reset callback was registered.");
-   return -EINVAL;
-   }
+   if (!driver_desc->device_reset_cb)
+   return 0;
 
/* Perform a device reset of the requested type. */
ret = driver_desc->device_reset_cb(gasket_dev, reset_type);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 05/20] staging: gasket: remove unnecessary code in coherent allocator

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Remove extraneous statement in gasket_config_coherent_allocator()

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 0c2f85cf54480..d0142ed048a65 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -420,10 +420,8 @@ static int gasket_config_coherent_allocator(
if (ibuf.page_table_index >= gasket_dev->num_page_tables)
return -EFAULT;
 
-   if (ibuf.size > PAGE_SIZE * MAX_NUM_COHERENT_PAGES) {
-   ibuf.size = PAGE_SIZE * MAX_NUM_COHERENT_PAGES;
+   if (ibuf.size > PAGE_SIZE * MAX_NUM_COHERENT_PAGES)
return -ENOMEM;
-   }
 
if (ibuf.enable == 0) {
ret = gasket_free_coherent_memory(
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 17/20] staging: gasket: top ioctl handler add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to gasket_core top-level ioctl handling pointer
arguments, for sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 6 --
 drivers/staging/gasket/gasket_core.h | 7 +--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 254fb392c05c1..40e46ca5228c8 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -14,6 +14,7 @@
 #include "gasket_page_table.h"
 #include "gasket_sysfs.h"
 
+#include 
 #include 
 #include 
 #include 
@@ -1781,6 +1782,7 @@ static long gasket_ioctl(struct file *filp, uint cmd, 
ulong arg)
 {
struct gasket_dev *gasket_dev;
const struct gasket_driver_desc *driver_desc;
+   void __user *argp = (void __user *)arg;
char path[256];
 
if (!filp)
@@ -1810,14 +1812,14 @@ static long gasket_ioctl(struct file *filp, uint cmd, 
ulong arg)
 * check_and_invoke_callback.
 */
if (driver_desc->ioctl_handler_cb)
-   return driver_desc->ioctl_handler_cb(filp, cmd, arg);
+   return driver_desc->ioctl_handler_cb(filp, cmd, argp);
 
gasket_log_error(
gasket_dev, "Received unknown ioctl 0x%x", cmd);
return -EINVAL;
}
 
-   return gasket_handle_ioctl(filp, cmd, arg);
+   return gasket_handle_ioctl(filp, cmd, argp);
 }
 
 int gasket_reset(struct gasket_dev *gasket_dev, uint reset_type)
diff --git a/drivers/staging/gasket/gasket_core.h 
b/drivers/staging/gasket/gasket_core.h
index 7ea1df123ba5d..bf4ed3769efb2 100644
--- a/drivers/staging/gasket/gasket_core.h
+++ b/drivers/staging/gasket/gasket_core.h
@@ -314,9 +314,12 @@ struct gasket_dev {
struct hlist_node legacy_hlist_node;
 };
 
+/* Type of the ioctl handler callback. */
+typedef long (*gasket_ioctl_handler_cb_t)
+   (struct file *file, uint cmd, void __user *argp);
 /* Type of the ioctl permissions check callback. See below. */
 typedef int (*gasket_ioctl_permissions_cb_t)(
-   struct file *filp, uint cmd, ulong arg);
+   struct file *filp, uint cmd, void __user *argp);
 
 /*
  * Device type descriptor.
@@ -550,7 +553,7 @@ struct gasket_driver_desc {
 * return -EINVAL. Should return an error status (either -EINVAL or
 * the error result of the ioctl being handled).
 */
-   long (*ioctl_handler_cb)(struct file *filp, uint cmd, ulong arg);
+   gasket_ioctl_handler_cb_t ioctl_handler_cb;
 
/*
 * device_status_cb: Callback to determine device health.
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 15/20] staging: gasket: fix multi-line comment syntax in gasket_core.h

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Use consistent kernel-style multi-line comment syntax.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.h 
b/drivers/staging/gasket/gasket_core.h
index 50ad0c8853183..7ea1df123ba5d 100644
--- a/drivers/staging/gasket/gasket_core.h
+++ b/drivers/staging/gasket/gasket_core.h
@@ -54,7 +54,8 @@ enum gasket_interrupt_type {
PLATFORM_WIRE = 2,
 };
 
-/* Used to describe a Gasket interrupt. Contains an interrupt index, a 
register,
+/*
+ * Used to describe a Gasket interrupt. Contains an interrupt index, a 
register,
  * and packing data for that interrupt. The register and packing data
  * fields are relevant only for PCI_MSIX interrupt type and can be
  * set to 0 for everything else.
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 14/20] staging: gasket: remove extra parens in gasket_write_mappable_regions

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Remove unneeded parentheses around subexpressions.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index ae5febec8844c..ba48a379b0ada 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1889,7 +1889,7 @@ static ssize_t gasket_write_mappable_regions(
if (bar_desc.permissions == GASKET_NOMAP)
return 0;
for (i = 0;
-(i < bar_desc.num_mappable_regions) && (total_written < PAGE_SIZE);
+i < bar_desc.num_mappable_regions && total_written < PAGE_SIZE;
 i++) {
min_addr = bar_desc.mappable_regions[i].start -
   driver_desc->legacy_mmap_address_offset;
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 17/20] staging: gasket: top ioctl handler add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to gasket_core top-level ioctl handling pointer
arguments, for sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 6 --
 drivers/staging/gasket/gasket_core.h | 7 +--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 254fb392c05c1..40e46ca5228c8 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -14,6 +14,7 @@
 #include "gasket_page_table.h"
 #include "gasket_sysfs.h"
 
+#include 
 #include 
 #include 
 #include 
@@ -1781,6 +1782,7 @@ static long gasket_ioctl(struct file *filp, uint cmd, 
ulong arg)
 {
struct gasket_dev *gasket_dev;
const struct gasket_driver_desc *driver_desc;
+   void __user *argp = (void __user *)arg;
char path[256];
 
if (!filp)
@@ -1810,14 +1812,14 @@ static long gasket_ioctl(struct file *filp, uint cmd, 
ulong arg)
 * check_and_invoke_callback.
 */
if (driver_desc->ioctl_handler_cb)
-   return driver_desc->ioctl_handler_cb(filp, cmd, arg);
+   return driver_desc->ioctl_handler_cb(filp, cmd, argp);
 
gasket_log_error(
gasket_dev, "Received unknown ioctl 0x%x", cmd);
return -EINVAL;
}
 
-   return gasket_handle_ioctl(filp, cmd, arg);
+   return gasket_handle_ioctl(filp, cmd, argp);
 }
 
 int gasket_reset(struct gasket_dev *gasket_dev, uint reset_type)
diff --git a/drivers/staging/gasket/gasket_core.h 
b/drivers/staging/gasket/gasket_core.h
index 7ea1df123ba5d..bf4ed3769efb2 100644
--- a/drivers/staging/gasket/gasket_core.h
+++ b/drivers/staging/gasket/gasket_core.h
@@ -314,9 +314,12 @@ struct gasket_dev {
struct hlist_node legacy_hlist_node;
 };
 
+/* Type of the ioctl handler callback. */
+typedef long (*gasket_ioctl_handler_cb_t)
+   (struct file *file, uint cmd, void __user *argp);
 /* Type of the ioctl permissions check callback. See below. */
 typedef int (*gasket_ioctl_permissions_cb_t)(
-   struct file *filp, uint cmd, ulong arg);
+   struct file *filp, uint cmd, void __user *argp);
 
 /*
  * Device type descriptor.
@@ -550,7 +553,7 @@ struct gasket_driver_desc {
 * return -EINVAL. Should return an error status (either -EINVAL or
 * the error result of the ioctl being handled).
 */
-   long (*ioctl_handler_cb)(struct file *filp, uint cmd, ulong arg);
+   gasket_ioctl_handler_cb_t ioctl_handler_cb;
 
/*
 * device_status_cb: Callback to determine device health.
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 15/20] staging: gasket: fix multi-line comment syntax in gasket_core.h

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Use consistent kernel-style multi-line comment syntax.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.h 
b/drivers/staging/gasket/gasket_core.h
index 50ad0c8853183..7ea1df123ba5d 100644
--- a/drivers/staging/gasket/gasket_core.h
+++ b/drivers/staging/gasket/gasket_core.h
@@ -54,7 +54,8 @@ enum gasket_interrupt_type {
PLATFORM_WIRE = 2,
 };
 
-/* Used to describe a Gasket interrupt. Contains an interrupt index, a 
register,
+/*
+ * Used to describe a Gasket interrupt. Contains an interrupt index, a 
register,
  * and packing data for that interrupt. The register and packing data
  * fields are relevant only for PCI_MSIX interrupt type and can be
  * set to 0 for everything else.
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 14/20] staging: gasket: remove extra parens in gasket_write_mappable_regions

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Remove unneeded parentheses around subexpressions.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index ae5febec8844c..ba48a379b0ada 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1889,7 +1889,7 @@ static ssize_t gasket_write_mappable_regions(
if (bar_desc.permissions == GASKET_NOMAP)
return 0;
for (i = 0;
-(i < bar_desc.num_mappable_regions) && (total_written < PAGE_SIZE);
+i < bar_desc.num_mappable_regions && total_written < PAGE_SIZE;
 i++) {
min_addr = bar_desc.mappable_regions[i].start -
   driver_desc->legacy_mmap_address_offset;
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 12/20] staging: gasket: remove unnecessary parens in page table code

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

gasket_alloc_coherent_memory() extra parentheses in statement.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 617d602b8b447..9f8116112e0ac 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -1639,7 +1639,7 @@ int gasket_alloc_coherent_memory(struct gasket_dev 
*gasket_dev, u64 size,
dma_addr_t handle;
void *mem;
int j;
-   unsigned int num_pages = (size + PAGE_SIZE - 1) / (PAGE_SIZE);
+   unsigned int num_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
const struct gasket_driver_desc *driver_desc =
gasket_get_driver_desc(gasket_dev);
 
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 13/20] staging: gasket: gasket_mmap use PAGE_MASK

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

gasket_mmap use PAGE_MASK, instead of performing math on PAGE_SIZE, for
simplicity and clarity.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 3cf918f9d2604..ae5febec8844c 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1591,7 +1591,7 @@ static int gasket_mmap(struct file *filp, struct 
vm_area_struct *vma)
}
driver_desc = gasket_dev->internal_desc->driver_desc;
 
-   if (vma->vm_start & (PAGE_SIZE - 1)) {
+   if (vma->vm_start & ~PAGE_MASK) {
gasket_log_error(
gasket_dev, "Base address not page-aligned: 0x%p\n",
(void *)vma->vm_start);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 16/20] staging: gasket: always allow root open for write

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Always allow root to open device for writing.

Drop special-casing of ioctl permissions for root vs. owner.

Convert to bool types as appropriate.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c  | 15 --
 drivers/staging/gasket/gasket_core.c  |  8 ---
 drivers/staging/gasket/gasket_ioctl.c | 30 +--
 3 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index a01b1f2b827ea..4c00f3609f081 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -140,7 +140,7 @@ static int apex_reset(struct gasket_dev *gasket_dev, uint 
type);
 
 static int apex_get_status(struct gasket_dev *gasket_dev);
 
-static uint apex_ioctl_check_permissions(struct file *file, uint cmd);
+static bool apex_ioctl_check_permissions(struct file *file, uint cmd);
 
 static long apex_ioctl(struct file *file, uint cmd, ulong arg);
 
@@ -625,18 +625,11 @@ static bool is_gcb_in_reset(struct gasket_dev *gasket_dev)
  * @file: File pointer from ioctl.
  * @cmd: ioctl command.
  *
- * Returns 1 if the current user may execute this ioctl, and 0 otherwise.
+ * Returns true if the current user may execute this ioctl, and false 
otherwise.
  */
-static uint apex_ioctl_check_permissions(struct file *filp, uint cmd)
+static bool apex_ioctl_check_permissions(struct file *filp, uint cmd)
 {
-   struct gasket_dev *gasket_dev = filp->private_data;
-   int root = capable(CAP_SYS_ADMIN);
-   int is_owner = gasket_dev->dev_info.ownership.is_owned &&
-  current->tgid == gasket_dev->dev_info.ownership.owner;
-
-   if (root || is_owner)
-   return 1;
-   return 0;
+   return !!(filp->f_mode & FMODE_WRITE);
 }
 
 /*
diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index ba48a379b0ada..254fb392c05c1 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1072,6 +1072,7 @@ static int gasket_open(struct inode *inode, struct file 
*filp)
char task_name[TASK_COMM_LEN];
struct gasket_cdev_info *dev_info =
container_of(inode->i_cdev, struct gasket_cdev_info, cdev);
+   int is_root = capable(CAP_SYS_ADMIN);
 
gasket_dev = dev_info->gasket_dev_ptr;
driver_desc = gasket_dev->internal_desc->driver_desc;
@@ -1085,7 +1086,7 @@ static int gasket_open(struct inode *inode, struct file 
*filp)
"Attempting to open with tgid %u (%s) (f_mode: 0%03o, "
"fmode_write: %d is_root: %u)",
current->tgid, task_name, filp->f_mode,
-   (filp->f_mode & FMODE_WRITE), capable(CAP_SYS_ADMIN));
+   (filp->f_mode & FMODE_WRITE), is_root);
 
/* Always allow non-writing accesses. */
if (!(filp->f_mode & FMODE_WRITE)) {
@@ -1099,8 +1100,9 @@ static int gasket_open(struct inode *inode, struct file 
*filp)
gasket_dev, "Current owner open count (owning tgid %u): %d.",
ownership->owner, ownership->write_open_count);
 
-   /* Opening a node owned by another TGID is an error (even root.) */
-   if (ownership->is_owned && ownership->owner != current->tgid) {
+   /* Opening a node owned by another TGID is an error (unless root) */
+   if (ownership->is_owned && ownership->owner != current->tgid &&
+   !is_root) {
gasket_log_error(
gasket_dev,
"Process %u is opening a node held by %u.",
diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index d0142ed048a65..8fd44979fe713 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -22,7 +22,7 @@
 #define trace_gasket_ioctl_config_coherent_allocator(x, ...)
 #endif
 
-static uint gasket_ioctl_check_permissions(struct file *filp, uint cmd);
+static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd);
 static int gasket_set_event_fd(struct gasket_dev *dev, ulong arg);
 static int gasket_read_page_table_size(
struct gasket_dev *gasket_dev, ulong arg);
@@ -167,12 +167,13 @@ long gasket_is_supported_ioctl(uint cmd)
  * @filp: File structure pointer describing this node usage session.
  * @cmd: ioctl number to handle.
  *
- * Standard permissions checker.
+ * Check permissions for Gasket ioctls.
+ * Returns true if the file opener may execute this ioctl, or false otherwise.
  */
-static uint gasket_ioctl_check_permissions(struct file *filp, uint cmd)
+static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd)
 {
-   uint alive, root, device_owner;
-   fmode_t read, write;
+   bool alive;
+   bool read, write;
struct gasket_dev *gasket_dev = (struct gasket_dev *)filp->private_data;
 

[PATCH 12/20] staging: gasket: remove unnecessary parens in page table code

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

gasket_alloc_coherent_memory() extra parentheses in statement.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 617d602b8b447..9f8116112e0ac 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -1639,7 +1639,7 @@ int gasket_alloc_coherent_memory(struct gasket_dev 
*gasket_dev, u64 size,
dma_addr_t handle;
void *mem;
int j;
-   unsigned int num_pages = (size + PAGE_SIZE - 1) / (PAGE_SIZE);
+   unsigned int num_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
const struct gasket_driver_desc *driver_desc =
gasket_get_driver_desc(gasket_dev);
 
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 13/20] staging: gasket: gasket_mmap use PAGE_MASK

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

gasket_mmap use PAGE_MASK, instead of performing math on PAGE_SIZE, for
simplicity and clarity.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 3cf918f9d2604..ae5febec8844c 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1591,7 +1591,7 @@ static int gasket_mmap(struct file *filp, struct 
vm_area_struct *vma)
}
driver_desc = gasket_dev->internal_desc->driver_desc;
 
-   if (vma->vm_start & (PAGE_SIZE - 1)) {
+   if (vma->vm_start & ~PAGE_MASK) {
gasket_log_error(
gasket_dev, "Base address not page-aligned: 0x%p\n",
(void *)vma->vm_start);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 16/20] staging: gasket: always allow root open for write

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Always allow root to open device for writing.

Drop special-casing of ioctl permissions for root vs. owner.

Convert to bool types as appropriate.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c  | 15 --
 drivers/staging/gasket/gasket_core.c  |  8 ---
 drivers/staging/gasket/gasket_ioctl.c | 30 +--
 3 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index a01b1f2b827ea..4c00f3609f081 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -140,7 +140,7 @@ static int apex_reset(struct gasket_dev *gasket_dev, uint 
type);
 
 static int apex_get_status(struct gasket_dev *gasket_dev);
 
-static uint apex_ioctl_check_permissions(struct file *file, uint cmd);
+static bool apex_ioctl_check_permissions(struct file *file, uint cmd);
 
 static long apex_ioctl(struct file *file, uint cmd, ulong arg);
 
@@ -625,18 +625,11 @@ static bool is_gcb_in_reset(struct gasket_dev *gasket_dev)
  * @file: File pointer from ioctl.
  * @cmd: ioctl command.
  *
- * Returns 1 if the current user may execute this ioctl, and 0 otherwise.
+ * Returns true if the current user may execute this ioctl, and false 
otherwise.
  */
-static uint apex_ioctl_check_permissions(struct file *filp, uint cmd)
+static bool apex_ioctl_check_permissions(struct file *filp, uint cmd)
 {
-   struct gasket_dev *gasket_dev = filp->private_data;
-   int root = capable(CAP_SYS_ADMIN);
-   int is_owner = gasket_dev->dev_info.ownership.is_owned &&
-  current->tgid == gasket_dev->dev_info.ownership.owner;
-
-   if (root || is_owner)
-   return 1;
-   return 0;
+   return !!(filp->f_mode & FMODE_WRITE);
 }
 
 /*
diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index ba48a379b0ada..254fb392c05c1 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1072,6 +1072,7 @@ static int gasket_open(struct inode *inode, struct file 
*filp)
char task_name[TASK_COMM_LEN];
struct gasket_cdev_info *dev_info =
container_of(inode->i_cdev, struct gasket_cdev_info, cdev);
+   int is_root = capable(CAP_SYS_ADMIN);
 
gasket_dev = dev_info->gasket_dev_ptr;
driver_desc = gasket_dev->internal_desc->driver_desc;
@@ -1085,7 +1086,7 @@ static int gasket_open(struct inode *inode, struct file 
*filp)
"Attempting to open with tgid %u (%s) (f_mode: 0%03o, "
"fmode_write: %d is_root: %u)",
current->tgid, task_name, filp->f_mode,
-   (filp->f_mode & FMODE_WRITE), capable(CAP_SYS_ADMIN));
+   (filp->f_mode & FMODE_WRITE), is_root);
 
/* Always allow non-writing accesses. */
if (!(filp->f_mode & FMODE_WRITE)) {
@@ -1099,8 +1100,9 @@ static int gasket_open(struct inode *inode, struct file 
*filp)
gasket_dev, "Current owner open count (owning tgid %u): %d.",
ownership->owner, ownership->write_open_count);
 
-   /* Opening a node owned by another TGID is an error (even root.) */
-   if (ownership->is_owned && ownership->owner != current->tgid) {
+   /* Opening a node owned by another TGID is an error (unless root) */
+   if (ownership->is_owned && ownership->owner != current->tgid &&
+   !is_root) {
gasket_log_error(
gasket_dev,
"Process %u is opening a node held by %u.",
diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index d0142ed048a65..8fd44979fe713 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -22,7 +22,7 @@
 #define trace_gasket_ioctl_config_coherent_allocator(x, ...)
 #endif
 
-static uint gasket_ioctl_check_permissions(struct file *filp, uint cmd);
+static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd);
 static int gasket_set_event_fd(struct gasket_dev *dev, ulong arg);
 static int gasket_read_page_table_size(
struct gasket_dev *gasket_dev, ulong arg);
@@ -167,12 +167,13 @@ long gasket_is_supported_ioctl(uint cmd)
  * @filp: File structure pointer describing this node usage session.
  * @cmd: ioctl number to handle.
  *
- * Standard permissions checker.
+ * Check permissions for Gasket ioctls.
+ * Returns true if the file opener may execute this ioctl, or false otherwise.
  */
-static uint gasket_ioctl_check_permissions(struct file *filp, uint cmd)
+static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd)
 {
-   uint alive, root, device_owner;
-   fmode_t read, write;
+   bool alive;
+   bool read, write;
struct gasket_dev *gasket_dev = (struct gasket_dev *)filp->private_data;
 

[PATCH 20/20] staging: gasket: common ioctls add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to gasket common ioctl pointer arguments for
sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 102 ++
 1 file changed, 55 insertions(+), 47 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 998d0e215523c..2e2c9b997093b 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -24,17 +24,24 @@
 #endif
 
 static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd);
-static int gasket_set_event_fd(struct gasket_dev *dev, ulong arg);
+static int gasket_set_event_fd(struct gasket_dev *dev,
+  struct gasket_interrupt_eventfd __user *argp);
 static int gasket_read_page_table_size(
-   struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
 static int gasket_read_simple_page_table_size(
-   struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
 static int gasket_partition_page_table(
-   struct gasket_dev *gasket_dev, ulong arg);
-static int gasket_map_buffers(struct gasket_dev *gasket_dev, ulong arg);
-static int gasket_unmap_buffers(struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
+static int gasket_map_buffers(struct gasket_dev *gasket_dev,
+ struct gasket_page_table_ioctl __user *argp);
+static int gasket_unmap_buffers(struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
 static int gasket_config_coherent_allocator(
-   struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_coherent_alloc_config_ioctl __user *argp);
 
 /*
  * standard ioctl dispatch function.
@@ -80,7 +87,7 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, void 
__user *argp)
retval = gasket_reset(gasket_dev, arg);
break;
case GASKET_IOCTL_SET_EVENTFD:
-   retval = gasket_set_event_fd(gasket_dev, arg);
+   retval = gasket_set_event_fd(gasket_dev, argp);
break;
case GASKET_IOCTL_CLEAR_EVENTFD:
trace_gasket_ioctl_integer_data(arg);
@@ -89,31 +96,30 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, void 
__user *argp)
break;
case GASKET_IOCTL_PARTITION_PAGE_TABLE:
trace_gasket_ioctl_integer_data(arg);
-   retval = gasket_partition_page_table(gasket_dev, arg);
+   retval = gasket_partition_page_table(gasket_dev, argp);
break;
case GASKET_IOCTL_NUMBER_PAGE_TABLES:
trace_gasket_ioctl_integer_data(gasket_dev->num_page_tables);
-   if (copy_to_user((void __user *)arg,
-_dev->num_page_tables,
+   if (copy_to_user(argp, _dev->num_page_tables,
 sizeof(uint64_t)))
retval = -EFAULT;
else
retval = 0;
break;
case GASKET_IOCTL_PAGE_TABLE_SIZE:
-   retval = gasket_read_page_table_size(gasket_dev, arg);
+   retval = gasket_read_page_table_size(gasket_dev, argp);
break;
case GASKET_IOCTL_SIMPLE_PAGE_TABLE_SIZE:
-   retval = gasket_read_simple_page_table_size(gasket_dev, arg);
+   retval = gasket_read_simple_page_table_size(gasket_dev, argp);
break;
case GASKET_IOCTL_MAP_BUFFER:
-   retval = gasket_map_buffers(gasket_dev, arg);
+   retval = gasket_map_buffers(gasket_dev, argp);
break;
case GASKET_IOCTL_CONFIG_COHERENT_ALLOCATOR:
-   retval = gasket_config_coherent_allocator(gasket_dev, arg);
+   retval = gasket_config_coherent_allocator(gasket_dev, argp);
break;
case GASKET_IOCTL_UNMAP_BUFFER:
-   retval = gasket_unmap_buffers(gasket_dev, arg);
+   retval = gasket_unmap_buffers(gasket_dev, argp);
break;
case GASKET_IOCTL_CLEAR_INTERRUPT_COUNTS:
/* Clear interrupt counts doesn't take an arg, so use 0. */
@@ -218,16 +224,15 @@ static bool gasket_ioctl_check_permissions(struct file 
*filp, uint cmd)
 /*
  * Associate an eventfd with an interrupt.
  * @gasket_dev: Pointer to the current gasket_dev we're using.
- * @arg: Pointer to gasket_interrupt_eventfd struct in userspace.
+ * @argp: Pointer to gasket_interrupt_eventfd struct in userspace.
  */
-static int gasket_set_event_fd(struct gasket_dev *gasket_dev, ulong arg)
+static int 

Re: [PATCH v3 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini  wrote:
>
> On 03/07/2018 08:21, Wanpeng Li wrote:
> > +
> > + rcu_read_lock();
> > + map = rcu_dereference(kvm->arch.apic_map);
> > +
> > + for_each_set_bit(i, _bitmap_low, BITS_PER_LONG) {
> > + vcpu = map->phys_map[i]->vcpu;
> > + if (!kvm_apic_set_irq(vcpu, , NULL))
> > + return 1;
> > + }
> > +
> > + for_each_set_bit(i, _bitmap_high, BITS_PER_LONG) {
> > + vcpu = map->phys_map[i + BITS_PER_LONG]->vcpu;
> > + if (!kvm_apic_set_irq(vcpu, , NULL))
> > + return 1;
> > + }
> > +
>
> This should be the guest's BITS_PER_LONG, not the host's (i.e. you need
> to pass op_64_bit from kvm_emulate_hypercall).

Will do in next version.

Regards,
Wanpeng Li


[PATCH 07/20] staging: gasket: gasket_mmap return error instead of valid BAR index

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

When offset to be mapped matches both a BAR region and a coherent mapped
region return an error as intended, not the BAR index.

Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index eb5ad161ccda2..3cf918f9d2604 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1627,7 +1627,7 @@ static int gasket_mmap(struct file *filp, struct 
vm_area_struct *vma)
"0x%lx",
raw_offset);
trace_gasket_mmap_exit(bar_index);
-   return bar_index;
+   return -EINVAL;
}
 
vma->vm_private_data = gasket_dev;
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 20/20] staging: gasket: common ioctls add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to gasket common ioctl pointer arguments for
sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 102 ++
 1 file changed, 55 insertions(+), 47 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 998d0e215523c..2e2c9b997093b 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -24,17 +24,24 @@
 #endif
 
 static bool gasket_ioctl_check_permissions(struct file *filp, uint cmd);
-static int gasket_set_event_fd(struct gasket_dev *dev, ulong arg);
+static int gasket_set_event_fd(struct gasket_dev *dev,
+  struct gasket_interrupt_eventfd __user *argp);
 static int gasket_read_page_table_size(
-   struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
 static int gasket_read_simple_page_table_size(
-   struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
 static int gasket_partition_page_table(
-   struct gasket_dev *gasket_dev, ulong arg);
-static int gasket_map_buffers(struct gasket_dev *gasket_dev, ulong arg);
-static int gasket_unmap_buffers(struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
+static int gasket_map_buffers(struct gasket_dev *gasket_dev,
+ struct gasket_page_table_ioctl __user *argp);
+static int gasket_unmap_buffers(struct gasket_dev *gasket_dev,
+   struct gasket_page_table_ioctl __user *argp);
 static int gasket_config_coherent_allocator(
-   struct gasket_dev *gasket_dev, ulong arg);
+   struct gasket_dev *gasket_dev,
+   struct gasket_coherent_alloc_config_ioctl __user *argp);
 
 /*
  * standard ioctl dispatch function.
@@ -80,7 +87,7 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, void 
__user *argp)
retval = gasket_reset(gasket_dev, arg);
break;
case GASKET_IOCTL_SET_EVENTFD:
-   retval = gasket_set_event_fd(gasket_dev, arg);
+   retval = gasket_set_event_fd(gasket_dev, argp);
break;
case GASKET_IOCTL_CLEAR_EVENTFD:
trace_gasket_ioctl_integer_data(arg);
@@ -89,31 +96,30 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, void 
__user *argp)
break;
case GASKET_IOCTL_PARTITION_PAGE_TABLE:
trace_gasket_ioctl_integer_data(arg);
-   retval = gasket_partition_page_table(gasket_dev, arg);
+   retval = gasket_partition_page_table(gasket_dev, argp);
break;
case GASKET_IOCTL_NUMBER_PAGE_TABLES:
trace_gasket_ioctl_integer_data(gasket_dev->num_page_tables);
-   if (copy_to_user((void __user *)arg,
-_dev->num_page_tables,
+   if (copy_to_user(argp, _dev->num_page_tables,
 sizeof(uint64_t)))
retval = -EFAULT;
else
retval = 0;
break;
case GASKET_IOCTL_PAGE_TABLE_SIZE:
-   retval = gasket_read_page_table_size(gasket_dev, arg);
+   retval = gasket_read_page_table_size(gasket_dev, argp);
break;
case GASKET_IOCTL_SIMPLE_PAGE_TABLE_SIZE:
-   retval = gasket_read_simple_page_table_size(gasket_dev, arg);
+   retval = gasket_read_simple_page_table_size(gasket_dev, argp);
break;
case GASKET_IOCTL_MAP_BUFFER:
-   retval = gasket_map_buffers(gasket_dev, arg);
+   retval = gasket_map_buffers(gasket_dev, argp);
break;
case GASKET_IOCTL_CONFIG_COHERENT_ALLOCATOR:
-   retval = gasket_config_coherent_allocator(gasket_dev, arg);
+   retval = gasket_config_coherent_allocator(gasket_dev, argp);
break;
case GASKET_IOCTL_UNMAP_BUFFER:
-   retval = gasket_unmap_buffers(gasket_dev, arg);
+   retval = gasket_unmap_buffers(gasket_dev, argp);
break;
case GASKET_IOCTL_CLEAR_INTERRUPT_COUNTS:
/* Clear interrupt counts doesn't take an arg, so use 0. */
@@ -218,16 +224,15 @@ static bool gasket_ioctl_check_permissions(struct file 
*filp, uint cmd)
 /*
  * Associate an eventfd with an interrupt.
  * @gasket_dev: Pointer to the current gasket_dev we're using.
- * @arg: Pointer to gasket_interrupt_eventfd struct in userspace.
+ * @argp: Pointer to gasket_interrupt_eventfd struct in userspace.
  */
-static int gasket_set_event_fd(struct gasket_dev *gasket_dev, ulong arg)
+static int 

Re: [PATCH v3 4/6] KVM: X86: Implement PV IPIs send hypercall

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini  wrote:
>
> On 03/07/2018 08:21, Wanpeng Li wrote:
> > +
> > + rcu_read_lock();
> > + map = rcu_dereference(kvm->arch.apic_map);
> > +
> > + for_each_set_bit(i, _bitmap_low, BITS_PER_LONG) {
> > + vcpu = map->phys_map[i]->vcpu;
> > + if (!kvm_apic_set_irq(vcpu, , NULL))
> > + return 1;
> > + }
> > +
> > + for_each_set_bit(i, _bitmap_high, BITS_PER_LONG) {
> > + vcpu = map->phys_map[i + BITS_PER_LONG]->vcpu;
> > + if (!kvm_apic_set_irq(vcpu, , NULL))
> > + return 1;
> > + }
> > +
>
> This should be the guest's BITS_PER_LONG, not the host's (i.e. you need
> to pass op_64_bit from kvm_emulate_hypercall).

Will do in next version.

Regards,
Wanpeng Li


[PATCH 07/20] staging: gasket: gasket_mmap return error instead of valid BAR index

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

When offset to be mapped matches both a BAR region and a coherent mapped
region return an error as intended, not the BAR index.

Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index eb5ad161ccda2..3cf918f9d2604 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -1627,7 +1627,7 @@ static int gasket_mmap(struct file *filp, struct 
vm_area_struct *vma)
"0x%lx",
raw_offset);
trace_gasket_mmap_exit(bar_index);
-   return bar_index;
+   return -EINVAL;
}
 
vma->vm_private_data = gasket_dev;
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 19/20] staging: gasket: common ioctl dispatcher add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to gasket core common ioctl pointer arguments for
sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 8 +---
 drivers/staging/gasket/gasket_ioctl.h | 4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 8fd44979fe713..998d0e215523c 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -7,6 +7,7 @@
 #include "gasket_interrupt.h"
 #include "gasket_logging.h"
 #include "gasket_page_table.h"
+#include 
 #include 
 #include 
 
@@ -39,13 +40,14 @@ static int gasket_config_coherent_allocator(
  * standard ioctl dispatch function.
  * @filp: File structure pointer describing this node usage session.
  * @cmd: ioctl number to handle.
- * @arg: ioctl-specific data pointer.
+ * @argp: ioctl-specific data pointer.
  *
  * Standard ioctl dispatcher; forwards operations to individual handlers.
  */
-long gasket_handle_ioctl(struct file *filp, uint cmd, ulong arg)
+long gasket_handle_ioctl(struct file *filp, uint cmd, void __user *argp)
 {
struct gasket_dev *gasket_dev;
+   unsigned long arg = (unsigned long)argp;
int retval;
 
gasket_dev = (struct gasket_dev *)filp->private_data;
@@ -53,7 +55,7 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, ulong 
arg)
 
if (gasket_get_ioctl_permissions_cb(gasket_dev)) {
retval = gasket_get_ioctl_permissions_cb(gasket_dev)(
-   filp, cmd, arg);
+   filp, cmd, argp);
if (retval < 0) {
trace_gasket_ioctl_exit(-EPERM);
return retval;
diff --git a/drivers/staging/gasket/gasket_ioctl.h 
b/drivers/staging/gasket/gasket_ioctl.h
index 461fab27a3e52..51f468c77f041 100644
--- a/drivers/staging/gasket/gasket_ioctl.h
+++ b/drivers/staging/gasket/gasket_ioctl.h
@@ -5,6 +5,8 @@
 
 #include "gasket_core.h"
 
+#include 
+
 /*
  * Handle Gasket common ioctls.
  * @filp: Pointer to the ioctl's file.
@@ -13,7 +15,7 @@
  *
  * Returns 0 on success and nonzero on failure.
  */
-long gasket_handle_ioctl(struct file *filp, uint cmd, ulong arg);
+long gasket_handle_ioctl(struct file *filp, uint cmd, void __user *argp);
 
 /*
  * Determines if an ioctl is part of the standard Gasket framework.
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 02/20] staging: gasket: gasket_enable_dev remove unnecessary variable

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Remove unnecessary variable, pass constant param instead.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 0d5ba7359af73..f327c9d7f90a3 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -898,7 +898,6 @@ static int gasket_enable_dev(
 {
int tbl_idx;
int ret;
-   bool has_dma_ops;
struct device *ddev;
const struct gasket_driver_desc *driver_desc =
internal_desc->driver_desc;
@@ -917,8 +916,6 @@ static int gasket_enable_dev(
return ret;
}
 
-   has_dma_ops = true;
-
for (tbl_idx = 0; tbl_idx < driver_desc->num_page_tables; tbl_idx++) {
gasket_log_debug(
gasket_dev, "Initializing page table %d.", tbl_idx);
@@ -936,7 +933,7 @@ static int gasket_enable_dev(
_dev->bar_data[
driver_desc->page_table_bar_index],
_desc->page_table_configs[tbl_idx],
-   ddev, gasket_dev->pci_dev, has_dma_ops);
+   ddev, gasket_dev->pci_dev, true);
if (ret) {
gasket_log_error(
gasket_dev,
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 18/20] staging: gasket: apex ioctl add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to ioctl pointer argument, for sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index 4c00f3609f081..3e76c4db5db2e 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2018 Google, Inc.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -142,9 +143,10 @@ static int apex_get_status(struct gasket_dev *gasket_dev);
 
 static bool apex_ioctl_check_permissions(struct file *file, uint cmd);
 
-static long apex_ioctl(struct file *file, uint cmd, ulong arg);
+static long apex_ioctl(struct file *file, uint cmd, void __user *argp);
 
-static long apex_clock_gating(struct gasket_dev *gasket_dev, ulong arg);
+static long apex_clock_gating(struct gasket_dev *gasket_dev,
+ struct apex_gate_clock_ioctl __user *argp);
 
 static int apex_enter_reset(struct gasket_dev *gasket_dev, uint type);
 
@@ -635,7 +637,7 @@ static bool apex_ioctl_check_permissions(struct file *filp, 
uint cmd)
 /*
  * Apex-specific ioctl handler.
  */
-static long apex_ioctl(struct file *filp, uint cmd, ulong arg)
+static long apex_ioctl(struct file *filp, uint cmd, void __user *argp)
 {
struct gasket_dev *gasket_dev = filp->private_data;
 
@@ -644,7 +646,7 @@ static long apex_ioctl(struct file *filp, uint cmd, ulong 
arg)
 
switch (cmd) {
case APEX_IOCTL_GATE_CLOCK:
-   return apex_clock_gating(gasket_dev, arg);
+   return apex_clock_gating(gasket_dev, argp);
default:
return -ENOTTY; /* unknown command */
}
@@ -653,16 +655,17 @@ static long apex_ioctl(struct file *filp, uint cmd, ulong 
arg)
 /*
  * Gates or un-gates Apex clock.
  * @gasket_dev: Gasket device pointer.
- * @arg: User ioctl arg, in this case to a apex_gate_clock_ioctl struct.
+ * @argp: User ioctl arg, pointer to a apex_gate_clock_ioctl struct.
  */
-static long apex_clock_gating(struct gasket_dev *gasket_dev, ulong arg)
+static long apex_clock_gating(struct gasket_dev *gasket_dev,
+ struct apex_gate_clock_ioctl __user *argp)
 {
struct apex_gate_clock_ioctl ibuf;
 
if (bypass_top_level || !allow_sw_clock_gating)
return 0;
 
-   if (copy_from_user(, (void __user *)arg, sizeof(ibuf)))
+   if (copy_from_user(, argp, sizeof(ibuf)))
return -EFAULT;
 
gasket_log_error(gasket_dev, "%s %llu", __func__, ibuf.enable);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 19/20] staging: gasket: common ioctl dispatcher add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to gasket core common ioctl pointer arguments for
sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_ioctl.c | 8 +---
 drivers/staging/gasket/gasket_ioctl.h | 4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_ioctl.c 
b/drivers/staging/gasket/gasket_ioctl.c
index 8fd44979fe713..998d0e215523c 100644
--- a/drivers/staging/gasket/gasket_ioctl.c
+++ b/drivers/staging/gasket/gasket_ioctl.c
@@ -7,6 +7,7 @@
 #include "gasket_interrupt.h"
 #include "gasket_logging.h"
 #include "gasket_page_table.h"
+#include 
 #include 
 #include 
 
@@ -39,13 +40,14 @@ static int gasket_config_coherent_allocator(
  * standard ioctl dispatch function.
  * @filp: File structure pointer describing this node usage session.
  * @cmd: ioctl number to handle.
- * @arg: ioctl-specific data pointer.
+ * @argp: ioctl-specific data pointer.
  *
  * Standard ioctl dispatcher; forwards operations to individual handlers.
  */
-long gasket_handle_ioctl(struct file *filp, uint cmd, ulong arg)
+long gasket_handle_ioctl(struct file *filp, uint cmd, void __user *argp)
 {
struct gasket_dev *gasket_dev;
+   unsigned long arg = (unsigned long)argp;
int retval;
 
gasket_dev = (struct gasket_dev *)filp->private_data;
@@ -53,7 +55,7 @@ long gasket_handle_ioctl(struct file *filp, uint cmd, ulong 
arg)
 
if (gasket_get_ioctl_permissions_cb(gasket_dev)) {
retval = gasket_get_ioctl_permissions_cb(gasket_dev)(
-   filp, cmd, arg);
+   filp, cmd, argp);
if (retval < 0) {
trace_gasket_ioctl_exit(-EPERM);
return retval;
diff --git a/drivers/staging/gasket/gasket_ioctl.h 
b/drivers/staging/gasket/gasket_ioctl.h
index 461fab27a3e52..51f468c77f041 100644
--- a/drivers/staging/gasket/gasket_ioctl.h
+++ b/drivers/staging/gasket/gasket_ioctl.h
@@ -5,6 +5,8 @@
 
 #include "gasket_core.h"
 
+#include 
+
 /*
  * Handle Gasket common ioctls.
  * @filp: Pointer to the ioctl's file.
@@ -13,7 +15,7 @@
  *
  * Returns 0 on success and nonzero on failure.
  */
-long gasket_handle_ioctl(struct file *filp, uint cmd, ulong arg);
+long gasket_handle_ioctl(struct file *filp, uint cmd, void __user *argp);
 
 /*
  * Determines if an ioctl is part of the standard Gasket framework.
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 02/20] staging: gasket: gasket_enable_dev remove unnecessary variable

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Remove unnecessary variable, pass constant param instead.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_core.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 0d5ba7359af73..f327c9d7f90a3 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -898,7 +898,6 @@ static int gasket_enable_dev(
 {
int tbl_idx;
int ret;
-   bool has_dma_ops;
struct device *ddev;
const struct gasket_driver_desc *driver_desc =
internal_desc->driver_desc;
@@ -917,8 +916,6 @@ static int gasket_enable_dev(
return ret;
}
 
-   has_dma_ops = true;
-
for (tbl_idx = 0; tbl_idx < driver_desc->num_page_tables; tbl_idx++) {
gasket_log_debug(
gasket_dev, "Initializing page table %d.", tbl_idx);
@@ -936,7 +933,7 @@ static int gasket_enable_dev(
_dev->bar_data[
driver_desc->page_table_bar_index],
_desc->page_table_configs[tbl_idx],
-   ddev, gasket_dev->pci_dev, has_dma_ops);
+   ddev, gasket_dev->pci_dev, true);
if (ret) {
gasket_log_error(
gasket_dev,
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 18/20] staging: gasket: apex ioctl add __user annotations

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Add __user annotation to ioctl pointer argument, for sparse checking.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex_driver.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/gasket/apex_driver.c 
b/drivers/staging/gasket/apex_driver.c
index 4c00f3609f081..3e76c4db5db2e 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2018 Google, Inc.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -142,9 +143,10 @@ static int apex_get_status(struct gasket_dev *gasket_dev);
 
 static bool apex_ioctl_check_permissions(struct file *file, uint cmd);
 
-static long apex_ioctl(struct file *file, uint cmd, ulong arg);
+static long apex_ioctl(struct file *file, uint cmd, void __user *argp);
 
-static long apex_clock_gating(struct gasket_dev *gasket_dev, ulong arg);
+static long apex_clock_gating(struct gasket_dev *gasket_dev,
+ struct apex_gate_clock_ioctl __user *argp);
 
 static int apex_enter_reset(struct gasket_dev *gasket_dev, uint type);
 
@@ -635,7 +637,7 @@ static bool apex_ioctl_check_permissions(struct file *filp, 
uint cmd)
 /*
  * Apex-specific ioctl handler.
  */
-static long apex_ioctl(struct file *filp, uint cmd, ulong arg)
+static long apex_ioctl(struct file *filp, uint cmd, void __user *argp)
 {
struct gasket_dev *gasket_dev = filp->private_data;
 
@@ -644,7 +646,7 @@ static long apex_ioctl(struct file *filp, uint cmd, ulong 
arg)
 
switch (cmd) {
case APEX_IOCTL_GATE_CLOCK:
-   return apex_clock_gating(gasket_dev, arg);
+   return apex_clock_gating(gasket_dev, argp);
default:
return -ENOTTY; /* unknown command */
}
@@ -653,16 +655,17 @@ static long apex_ioctl(struct file *filp, uint cmd, ulong 
arg)
 /*
  * Gates or un-gates Apex clock.
  * @gasket_dev: Gasket device pointer.
- * @arg: User ioctl arg, in this case to a apex_gate_clock_ioctl struct.
+ * @argp: User ioctl arg, pointer to a apex_gate_clock_ioctl struct.
  */
-static long apex_clock_gating(struct gasket_dev *gasket_dev, ulong arg)
+static long apex_clock_gating(struct gasket_dev *gasket_dev,
+ struct apex_gate_clock_ioctl __user *argp)
 {
struct apex_gate_clock_ioctl ibuf;
 
if (bypass_top_level || !allow_sw_clock_gating)
return 0;
 
-   if (copy_from_user(, (void __user *)arg, sizeof(ibuf)))
+   if (copy_from_user(, argp, sizeof(ibuf)))
return -EFAULT;
 
gasket_log_error(gasket_dev, "%s %llu", __func__, ibuf.enable);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 11/20] staging: gasket: fix comment syntax in apex.h

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Use kernel-style multi-line comment syntax.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/gasket/apex.h b/drivers/staging/gasket/apex.h
index 4ef264106f503..d89cc2387b7d4 100644
--- a/drivers/staging/gasket/apex.h
+++ b/drivers/staging/gasket/apex.h
@@ -22,9 +22,10 @@
 
 #define APEX_EXTENDED_SHIFT 63 /* Extended address bit position. */
 
-/* Addresses are 2^3=8 bytes each. */
-/* page in second level page table */
-/* holds APEX_PAGE_SIZE/8 addresses  */
+/*
+ * Addresses are 2^3=8 bytes each. Page in second level page table holds
+ * APEX_PAGE_SIZE/8 addresses.
+ */
 #define APEX_ADDR_SHIFT 3
 #define APEX_LEVEL_SHIFT (APEX_PAGE_SHIFT - APEX_ADDR_SHIFT)
 #define APEX_LEVEL_SIZE BIT(APEX_LEVEL_SHIFT)
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 10/20] staging: gasket: remove else clause after return in if clause

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Else after return is unnecessary and may cause static code checkers to
complain.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 2a27db658a4e4..617d602b8b447 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -598,9 +598,7 @@ bool gasket_page_table_is_dev_addr_bad(
if (gasket_addr_is_simple(pg_tbl, dev_addr))
return gasket_is_simple_dev_addr_bad(
pg_tbl, dev_addr, num_pages);
-   else
-   return gasket_is_extended_dev_addr_bad(
-   pg_tbl, dev_addr, num_pages);
+   return gasket_is_extended_dev_addr_bad(pg_tbl, dev_addr, num_pages);
 }
 EXPORT_SYMBOL(gasket_page_table_is_dev_addr_bad);
 
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 04/20] staging: gasket: fix class create bug handling

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

class_create() never returns NULL, and this driver should never return
PTR_ERR(NULL) anyway.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
Reviewed-by: Dmitry Torokhov 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 18cc8e3283b39..53236e1ba4e48 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -321,7 +321,7 @@ int gasket_register_device(const struct gasket_driver_desc 
*driver_desc)
internal->class =
class_create(driver_desc->module, driver_desc->name);
 
-   if (IS_ERR_OR_NULL(internal->class)) {
+   if (IS_ERR(internal->class)) {
gasket_nodev_error("Cannot register %s class [ret=%ld]",
   driver_desc->name, PTR_ERR(internal->class));
ret = PTR_ERR(internal->class);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 00/20 v4] staging: gasket: sundry fixes and fixups

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Various fixes mainly from the chromium review of the gasket and apex
drivers.  More to come.

Todd Poynor (20):
  staging: gasket: allow compile for ARM64 in Kconfig
  staging: gasket: gasket_enable_dev remove unnecessary variable
  staging: gasket: remove code for no physical device
  staging: gasket: fix class create bug handling
  staging: gasket: remove unnecessary code in coherent allocator
  staging: gasket: don't treat no device reset callback as an error
  staging: gasket: gasket_mmap return error instead of valid BAR index
  staging: gasket: apex_clock_gating simplify logic, reduce indentation
  staging: gasket: gasket page table functions use bool return type
  staging: gasket: remove else clause after return in if clause
  staging: gasket: fix comment syntax in apex.h
  staging: gasket: remove unnecessary parens in page table code
  staging: gasket: gasket_mmap use PAGE_MASK
  staging: gasket: remove extra parens in gasket_write_mappable_regions
  staging: gasket: fix multi-line comment syntax in gasket_core.h
  staging: gasket: always allow root open for write
  staging: gasket: top ioctl handler add __user annotations
  staging: gasket: apex ioctl add __user annotations
  staging: gasket: common ioctl dispatcher add __user annotations
  staging: gasket: common ioctls add __user annotations

Patches changed from v3 in v4:
  staging: gasket: remove X86 Kconfig restriction
 Rename: staging: gasket: allow compile for ARM64 in Kconfig
 Restore existing "depends on" for X86_64, add ARM64.  Only compile for
 64-bit architectures known to work with this driver.
  staging: gasket: always allow root open for write
 Fold in patch to convert apex_ioctl_check_permissions to return bool
 Convert gasket_ioctl_check_permissions to use bool types.
  staging: gasket: apex_ioctl_check_permissions use bool return type
 Folded into above patch.
  staging: gasket: annotate ioctl arg with __user
 Split up into new patches:
staging: gasket: top ioctl handler add __user annotations
staging: gasket: apex ioctl add __user annotations
staging: gasket: common ioctl dispatcher add __user annotations
staging: gasket: common ioctls add __user annotations
 Convert various uses of void * to actual type.
 Minor formatting and naming changes.
 Drop Reviewed-By: Dmitry Torokhov due to changes since review.

Patches unchanged from v3 in v4:
  staging: gasket: gasket_enable_dev remove unnecessary variable
  staging: gasket: remove code for no physical device
  staging: gasket: fix class create bug handling
  staging: gasket: remove unnecessary code in coherent allocator
  staging: gasket: don't treat no device reset callback as an error
  staging: gasket: gasket_mmap return error instead of valid BAR index
  staging: gasket: apex_clock_gating simplify logic, reduce indentation
  staging: gasket: gasket page table functions use bool return type
  staging: gasket: remove else clause after return in if clause
  staging: gasket: fix comment syntax in apex.h
  staging: gasket: remove unnecessary parens in page table code
  staging: gasket: gasket_mmap use PAGE_MASK
  staging: gasket: remove extra parens in gasket_write_mappable_regions
  staging: gasket: fix multi-line comment syntax in gasket_core.h

Patches removed from v3 in v4 (already merged to staging-next):
  staging: gasket: fix typo in apex_enter_reset
  staging: gasket: fix typo in gasket_core.h comments
  staging: gasket: whitespace fix in gasket_page_table_init
  staging: gasket: remove driver registration on class creation failure
  staging: gasket: hold mutex on gasket driver unregistration
  staging: gasket: Return EBUSY on mapping create when already in use
  staging: gasket: Remove stale pointers on error allocating attr array
  staging: gasket: convert gasket_mmap_has_permissions to bool return
  staging: gasket: fix gasket_wait_with_reschedule timeout return code
  staging: gasket: gasket_wait_with_reschedule use msleep
  staging: gasket: gasket_wait_with_reschedule simplify logic
  staging: gasket: gasket_wait_with_reschedule use 32 bits of retry
  staging: gasket: bail out of reset sequence on device callback error
  staging: gasket: drop gasket_cdev_get_info, use container_of

 drivers/staging/gasket/Kconfig |   2 +-
 drivers/staging/gasket/apex.h  |   7 +-
 drivers/staging/gasket/apex_driver.c   |  73 +--
 drivers/staging/gasket/gasket_core.c   |  44 +++
 drivers/staging/gasket/gasket_core.h   |  10 +-
 drivers/staging/gasket/gasket_ioctl.c  | 144 +++--
 drivers/staging/gasket/gasket_ioctl.h  |   4 +-
 drivers/staging/gasket/gasket_page_table.c |  64 +
 drivers/staging/gasket/gasket_page_table.h |   8 +-
 9 files changed, 174 insertions(+), 182 deletions(-)

-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 11/20] staging: gasket: fix comment syntax in apex.h

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Use kernel-style multi-line comment syntax.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/apex.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/gasket/apex.h b/drivers/staging/gasket/apex.h
index 4ef264106f503..d89cc2387b7d4 100644
--- a/drivers/staging/gasket/apex.h
+++ b/drivers/staging/gasket/apex.h
@@ -22,9 +22,10 @@
 
 #define APEX_EXTENDED_SHIFT 63 /* Extended address bit position. */
 
-/* Addresses are 2^3=8 bytes each. */
-/* page in second level page table */
-/* holds APEX_PAGE_SIZE/8 addresses  */
+/*
+ * Addresses are 2^3=8 bytes each. Page in second level page table holds
+ * APEX_PAGE_SIZE/8 addresses.
+ */
 #define APEX_ADDR_SHIFT 3
 #define APEX_LEVEL_SHIFT (APEX_PAGE_SHIFT - APEX_ADDR_SHIFT)
 #define APEX_LEVEL_SIZE BIT(APEX_LEVEL_SHIFT)
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 10/20] staging: gasket: remove else clause after return in if clause

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Else after return is unnecessary and may cause static code checkers to
complain.

Reported-by: Guenter Roeck 
Signed-off-by: Simon Que 
Signed-off-by: Todd Poynor 
---
 drivers/staging/gasket/gasket_page_table.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/gasket/gasket_page_table.c 
b/drivers/staging/gasket/gasket_page_table.c
index 2a27db658a4e4..617d602b8b447 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -598,9 +598,7 @@ bool gasket_page_table_is_dev_addr_bad(
if (gasket_addr_is_simple(pg_tbl, dev_addr))
return gasket_is_simple_dev_addr_bad(
pg_tbl, dev_addr, num_pages);
-   else
-   return gasket_is_extended_dev_addr_bad(
-   pg_tbl, dev_addr, num_pages);
+   return gasket_is_extended_dev_addr_bad(pg_tbl, dev_addr, num_pages);
 }
 EXPORT_SYMBOL(gasket_page_table_is_dev_addr_bad);
 
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 04/20] staging: gasket: fix class create bug handling

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

class_create() never returns NULL, and this driver should never return
PTR_ERR(NULL) anyway.

Reported-by: Dmitry Torokhov 
Signed-off-by: Zhongze Hu 
Signed-off-by: Todd Poynor 
Reviewed-by: Dmitry Torokhov 
---
 drivers/staging/gasket/gasket_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/gasket/gasket_core.c 
b/drivers/staging/gasket/gasket_core.c
index 18cc8e3283b39..53236e1ba4e48 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -321,7 +321,7 @@ int gasket_register_device(const struct gasket_driver_desc 
*driver_desc)
internal->class =
class_create(driver_desc->module, driver_desc->name);
 
-   if (IS_ERR_OR_NULL(internal->class)) {
+   if (IS_ERR(internal->class)) {
gasket_nodev_error("Cannot register %s class [ret=%ld]",
   driver_desc->name, PTR_ERR(internal->class));
ret = PTR_ERR(internal->class);
-- 
2.18.0.233.g985f88cf7e-goog



[PATCH 00/20 v4] staging: gasket: sundry fixes and fixups

2018-07-19 Thread Todd Poynor
From: Todd Poynor 

Various fixes mainly from the chromium review of the gasket and apex
drivers.  More to come.

Todd Poynor (20):
  staging: gasket: allow compile for ARM64 in Kconfig
  staging: gasket: gasket_enable_dev remove unnecessary variable
  staging: gasket: remove code for no physical device
  staging: gasket: fix class create bug handling
  staging: gasket: remove unnecessary code in coherent allocator
  staging: gasket: don't treat no device reset callback as an error
  staging: gasket: gasket_mmap return error instead of valid BAR index
  staging: gasket: apex_clock_gating simplify logic, reduce indentation
  staging: gasket: gasket page table functions use bool return type
  staging: gasket: remove else clause after return in if clause
  staging: gasket: fix comment syntax in apex.h
  staging: gasket: remove unnecessary parens in page table code
  staging: gasket: gasket_mmap use PAGE_MASK
  staging: gasket: remove extra parens in gasket_write_mappable_regions
  staging: gasket: fix multi-line comment syntax in gasket_core.h
  staging: gasket: always allow root open for write
  staging: gasket: top ioctl handler add __user annotations
  staging: gasket: apex ioctl add __user annotations
  staging: gasket: common ioctl dispatcher add __user annotations
  staging: gasket: common ioctls add __user annotations

Patches changed from v3 in v4:
  staging: gasket: remove X86 Kconfig restriction
 Rename: staging: gasket: allow compile for ARM64 in Kconfig
 Restore existing "depends on" for X86_64, add ARM64.  Only compile for
 64-bit architectures known to work with this driver.
  staging: gasket: always allow root open for write
 Fold in patch to convert apex_ioctl_check_permissions to return bool
 Convert gasket_ioctl_check_permissions to use bool types.
  staging: gasket: apex_ioctl_check_permissions use bool return type
 Folded into above patch.
  staging: gasket: annotate ioctl arg with __user
 Split up into new patches:
staging: gasket: top ioctl handler add __user annotations
staging: gasket: apex ioctl add __user annotations
staging: gasket: common ioctl dispatcher add __user annotations
staging: gasket: common ioctls add __user annotations
 Convert various uses of void * to actual type.
 Minor formatting and naming changes.
 Drop Reviewed-By: Dmitry Torokhov due to changes since review.

Patches unchanged from v3 in v4:
  staging: gasket: gasket_enable_dev remove unnecessary variable
  staging: gasket: remove code for no physical device
  staging: gasket: fix class create bug handling
  staging: gasket: remove unnecessary code in coherent allocator
  staging: gasket: don't treat no device reset callback as an error
  staging: gasket: gasket_mmap return error instead of valid BAR index
  staging: gasket: apex_clock_gating simplify logic, reduce indentation
  staging: gasket: gasket page table functions use bool return type
  staging: gasket: remove else clause after return in if clause
  staging: gasket: fix comment syntax in apex.h
  staging: gasket: remove unnecessary parens in page table code
  staging: gasket: gasket_mmap use PAGE_MASK
  staging: gasket: remove extra parens in gasket_write_mappable_regions
  staging: gasket: fix multi-line comment syntax in gasket_core.h

Patches removed from v3 in v4 (already merged to staging-next):
  staging: gasket: fix typo in apex_enter_reset
  staging: gasket: fix typo in gasket_core.h comments
  staging: gasket: whitespace fix in gasket_page_table_init
  staging: gasket: remove driver registration on class creation failure
  staging: gasket: hold mutex on gasket driver unregistration
  staging: gasket: Return EBUSY on mapping create when already in use
  staging: gasket: Remove stale pointers on error allocating attr array
  staging: gasket: convert gasket_mmap_has_permissions to bool return
  staging: gasket: fix gasket_wait_with_reschedule timeout return code
  staging: gasket: gasket_wait_with_reschedule use msleep
  staging: gasket: gasket_wait_with_reschedule simplify logic
  staging: gasket: gasket_wait_with_reschedule use 32 bits of retry
  staging: gasket: bail out of reset sequence on device callback error
  staging: gasket: drop gasket_cdev_get_info, use container_of

 drivers/staging/gasket/Kconfig |   2 +-
 drivers/staging/gasket/apex.h  |   7 +-
 drivers/staging/gasket/apex_driver.c   |  73 +--
 drivers/staging/gasket/gasket_core.c   |  44 +++
 drivers/staging/gasket/gasket_core.h   |  10 +-
 drivers/staging/gasket/gasket_ioctl.c  | 144 +++--
 drivers/staging/gasket/gasket_ioctl.h  |   4 +-
 drivers/staging/gasket/gasket_page_table.c |  64 +
 drivers/staging/gasket/gasket_page_table.h |   8 +-
 9 files changed, 174 insertions(+), 182 deletions(-)

-- 
2.18.0.233.g985f88cf7e-goog



Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 07:05, David Matlack  wrote:
>
> On Mon, Jul 2, 2018 at 11:23 PM Wanpeng Li  wrote:
> >
> > From: Wanpeng Li 
> >
> > Implement paravirtual apic hooks to enable PV IPIs.
>
> Very cool. Thanks for working on this!

Thanks David!

>
> >
> > apic->send_IPI_mask
> > apic->send_IPI_mask_allbutself
> > apic->send_IPI_allbutself
> > apic->send_IPI_all
> >
> > The PV IPIs supports maximal 128 vCPUs VM, it is big enough for cloud
> > environment currently,
>
> From the Cloud perspective, 128 vCPUs is already obsolete. GCE's
> n1-utlramem-160 VMs have 160 vCPUs where the maximum APIC ID is 231.
> I'd definitely prefer an approach that scales to higher APIC IDs, like
> Paolo's offset idea.

Ok, I will try the offset method in next version.

>
> To Radim's point of real world performance testing, do you know what
> is the primary source of multi-target IPIs? If it's TLB shootdowns we
> might get a bigger bang for our buck with a PV TLB Shootdown.

The "Function Call interrupts", there is a lot of callers for
smp_call_function_many() except TLB Shootdowns in linux kernel which
try to run a function on a set of other CPUs. TLB Shootdown still can
get benefit from PV IPIs even if PV TLB Shootdown is enabled since
IPIs should be sent to the vCPUs which are active and will incur
vmexits. PV IPIs will benefit both vCPUs overcommit and
non-overcommit(which PV TLB Shootdown can't help) scenarios. Btw,
hyperv also implements PV IPIs even if PV TLB Shootdown is present.
https://lkml.org/lkml/2018/7/3/537

Regards,
Wanpeng Li


Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 07:05, David Matlack  wrote:
>
> On Mon, Jul 2, 2018 at 11:23 PM Wanpeng Li  wrote:
> >
> > From: Wanpeng Li 
> >
> > Implement paravirtual apic hooks to enable PV IPIs.
>
> Very cool. Thanks for working on this!

Thanks David!

>
> >
> > apic->send_IPI_mask
> > apic->send_IPI_mask_allbutself
> > apic->send_IPI_allbutself
> > apic->send_IPI_all
> >
> > The PV IPIs supports maximal 128 vCPUs VM, it is big enough for cloud
> > environment currently,
>
> From the Cloud perspective, 128 vCPUs is already obsolete. GCE's
> n1-utlramem-160 VMs have 160 vCPUs where the maximum APIC ID is 231.
> I'd definitely prefer an approach that scales to higher APIC IDs, like
> Paolo's offset idea.

Ok, I will try the offset method in next version.

>
> To Radim's point of real world performance testing, do you know what
> is the primary source of multi-target IPIs? If it's TLB shootdowns we
> might get a bigger bang for our buck with a PV TLB Shootdown.

The "Function Call interrupts", there is a lot of callers for
smp_call_function_many() except TLB Shootdowns in linux kernel which
try to run a function on a set of other CPUs. TLB Shootdown still can
get benefit from PV IPIs even if PV TLB Shootdown is enabled since
IPIs should be sent to the vCPUs which are active and will incur
vmexits. PV IPIs will benefit both vCPUs overcommit and
non-overcommit(which PV TLB Shootdown can't help) scenarios. Btw,
hyperv also implements PV IPIs even if PV TLB Shootdown is present.
https://lkml.org/lkml/2018/7/3/537

Regards,
Wanpeng Li


linux-next: manual merge of the mfd tree with the sound tree

2018-07-19 Thread Stephen Rothwell
Hi all,

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

  drivers/gpu/drm/i915/Kconfig

between commit:

  a57942bfdd61 ("ALSA: hda: Make audio component support more generic")

from the sound tree and commit:

  9c229127aee2 ("drm/i915: hdmi: add CEC notifier to intel_hdmi")

from the mfd tree.

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

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/i915/Kconfig
index 5c607f2c707b,2d65d567d5d1..
--- a/drivers/gpu/drm/i915/Kconfig
+++ b/drivers/gpu/drm/i915/Kconfig
@@@ -23,7 -23,7 +23,8 @@@ config DRM_I91
select SYNC_FILE
select IOSF_MBI
select CRC32
 +  select SND_HDA_I915 if SND_HDA_CORE
+   select CEC_CORE if CEC_NOTIFIER
help
  Choose this option if you have a system that has "Intel Graphics
  Media Accelerator" or "HD Graphics" integrated graphics,


pgpu8LR9tqAnJ.pgp
Description: OpenPGP digital signature


linux-next: manual merge of the mfd tree with the sound tree

2018-07-19 Thread Stephen Rothwell
Hi all,

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

  drivers/gpu/drm/i915/Kconfig

between commit:

  a57942bfdd61 ("ALSA: hda: Make audio component support more generic")

from the sound tree and commit:

  9c229127aee2 ("drm/i915: hdmi: add CEC notifier to intel_hdmi")

from the mfd tree.

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

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/i915/Kconfig
index 5c607f2c707b,2d65d567d5d1..
--- a/drivers/gpu/drm/i915/Kconfig
+++ b/drivers/gpu/drm/i915/Kconfig
@@@ -23,7 -23,7 +23,8 @@@ config DRM_I91
select SYNC_FILE
select IOSF_MBI
select CRC32
 +  select SND_HDA_I915 if SND_HDA_CORE
+   select CEC_CORE if CEC_NOTIFIER
help
  Choose this option if you have a system that has "Intel Graphics
  Media Accelerator" or "HD Graphics" integrated graphics,


pgpu8LR9tqAnJ.pgp
Description: OpenPGP digital signature


Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini  wrote:
>
> On 19/07/2018 18:28, Radim Krčmář wrote:
> >> +
> >> +kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, 
> >> vector);
> > and
> >
> >   kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vector);
> >
> > Still, the main problem is that we can only address 128 APICs.
> >
> > A simple improvement would reuse the vector field (as we need only 8
> > bits) and put a 'offset' in the rest.  The offset would say which
> > cluster of 128 are we addressing.  24 bits of offset results in 2^31
> > total addressable CPUs (we probably should even use that many bits).
> > The downside of this is that we can only address 128 at a time.
> >
> > It's basically the same as x2apic cluster mode, only with 128 cluster
> > size instead of 16, so the code should be a straightforward port.
> > And because x2apic code doesn't seem to use any division by the cluster
> > size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and
> > make the cluster size 192. :)
>
> I did suggest an offset earlier in the discussion.
>
> The main problem is that consecutive CPU ids do not map to consecutive
> APIC ids.  But still, we could do an hypercall whenever the total range
> exceeds 64.  Something like
>
> u64 ipi_bitmap = 0;
> for_each_cpu(cpu, mask)
> if (!ipi_bitmap) {
> min = max = cpu;
> } else if (cpu < min && max - cpu < 64) {
> ipi_bitmap <<= min - cpu;
> min = cpu;
> } else if (id < min + 64) {
> max = cpu < max ? max : cpu;
> } else {
> /* ... send hypercall... */
> min = max = cpu;
> ipi_bitmap = 0;
> }
> __set_bit(ipi_bitmap, cpu - min);
> }
> if (ipi_bitmap) {
> /* ... send hypercall... */
> }
>
> We could keep the cluster size of 128, but it would be more complicated
> to do the left shift in the first "else if".  If the limit is 64, you
> can keep the two arguments in the hypercall, and just pass 0 as the
> "high" bitmap on 64-bit kernels.

Cool, i will try the offset method in next version. Thanks for your
review, Paolo! :)

Regards,
Wanpeng Li


Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:47, Paolo Bonzini  wrote:
>
> On 19/07/2018 18:28, Radim Krčmář wrote:
> >> +
> >> +kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, 
> >> vector);
> > and
> >
> >   kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vector);
> >
> > Still, the main problem is that we can only address 128 APICs.
> >
> > A simple improvement would reuse the vector field (as we need only 8
> > bits) and put a 'offset' in the rest.  The offset would say which
> > cluster of 128 are we addressing.  24 bits of offset results in 2^31
> > total addressable CPUs (we probably should even use that many bits).
> > The downside of this is that we can only address 128 at a time.
> >
> > It's basically the same as x2apic cluster mode, only with 128 cluster
> > size instead of 16, so the code should be a straightforward port.
> > And because x2apic code doesn't seem to use any division by the cluster
> > size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and
> > make the cluster size 192. :)
>
> I did suggest an offset earlier in the discussion.
>
> The main problem is that consecutive CPU ids do not map to consecutive
> APIC ids.  But still, we could do an hypercall whenever the total range
> exceeds 64.  Something like
>
> u64 ipi_bitmap = 0;
> for_each_cpu(cpu, mask)
> if (!ipi_bitmap) {
> min = max = cpu;
> } else if (cpu < min && max - cpu < 64) {
> ipi_bitmap <<= min - cpu;
> min = cpu;
> } else if (id < min + 64) {
> max = cpu < max ? max : cpu;
> } else {
> /* ... send hypercall... */
> min = max = cpu;
> ipi_bitmap = 0;
> }
> __set_bit(ipi_bitmap, cpu - min);
> }
> if (ipi_bitmap) {
> /* ... send hypercall... */
> }
>
> We could keep the cluster size of 128, but it would be more complicated
> to do the left shift in the first "else if".  If the limit is 64, you
> can keep the two arguments in the hypercall, and just pass 0 as the
> "high" bitmap on 64-bit kernels.

Cool, i will try the offset method in next version. Thanks for your
review, Paolo! :)

Regards,
Wanpeng Li


Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:28, Radim Krčmář  wrote:
>
> 2018-07-03 14:21+0800, Wanpeng Li:
> > From: Wanpeng Li 
> >
> > Implement paravirtual apic hooks to enable PV IPIs.
> >
> > apic->send_IPI_mask
> > apic->send_IPI_mask_allbutself
> > apic->send_IPI_allbutself
> > apic->send_IPI_all
> >
> > The PV IPIs supports maximal 128 vCPUs VM, it is big enough for cloud
> > environment currently, supporting more vCPUs needs to introduce more
> > complex logic, in the future this might be extended if needed.
> >
> > Cc: Paolo Bonzini 
> > Cc: Radim Krčmář 
> > Cc: Vitaly Kuznetsov 
> > Signed-off-by: Wanpeng Li 
> > ---
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > @@ -454,6 +454,71 @@ static void __init sev_map_percpu_data(void)
> >  }
> >
> >  #ifdef CONFIG_SMP
> > +
> > +#ifdef CONFIG_X86_64
> > +static void __send_ipi_mask(const struct cpumask *mask, int vector)
> > +{
> > + unsigned long flags, ipi_bitmap_low = 0, ipi_bitmap_high = 0;
> > + int cpu, apic_id;
> > +
> > + if (cpumask_empty(mask))
> > + return;
> > +
> > + local_irq_save(flags);
> > +
> > + for_each_cpu(cpu, mask) {
> > + apic_id = per_cpu(x86_cpu_to_apicid, cpu);
> > + if (apic_id < BITS_PER_LONG)
> > + __set_bit(apic_id, _bitmap_low);
> > + else if (apic_id < 2 * BITS_PER_LONG)
> > + __set_bit(apic_id - BITS_PER_LONG, _bitmap_high);
>
> It'd be nicer with 'unsigned long ipi_bitmap[2]' and a single
>
> __set_bit(apic_id, ipi_bitmap);
>
> > + }
> > +
> > + kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, 
> > vector);
>
> and
>
> kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vector);
>
> Still, the main problem is that we can only address 128 APICs.
>
> A simple improvement would reuse the vector field (as we need only 8
> bits) and put a 'offset' in the rest.  The offset would say which
> cluster of 128 are we addressing.  24 bits of offset results in 2^31
> total addressable CPUs (we probably should even use that many bits).
> The downside of this is that we can only address 128 at a time.
>
> It's basically the same as x2apic cluster mode, only with 128 cluster
> size instead of 16, so the code should be a straightforward port.
> And because x2apic code doesn't seem to use any division by the cluster
> size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and
> make the cluster size 192. :)
>
> But because it is very similar to x2apic, I'd really need some real
> performance data to see if this benefits a real workload.

Thanks for your review, Radim! :) I will find another real benchmark
instead of the micro one to evaluate the performance.

> Hardware could further optimize LAPIC (apicv, vapic) in the future,
> which we'd lose by using paravirt.
>
> e.g. AMD's acceleration should be superior to this when using < 8 VCPUs
> as they can use logical xAPIC and send without VM exits (when all VCPUs
> are running).
>
> > +
> > + local_irq_restore(flags);
> > +}
> > +
> > +static void kvm_send_ipi_mask(const struct cpumask *mask, int vector)
> > +{
> > + __send_ipi_mask(mask, vector);
> > +}
> > +
> > +static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int 
> > vector)
> > +{
> > + unsigned int this_cpu = smp_processor_id();
> > + struct cpumask new_mask;
> > + const struct cpumask *local_mask;
> > +
> > + cpumask_copy(_mask, mask);
> > + cpumask_clear_cpu(this_cpu, _mask);
> > + local_mask = _mask;
> > + __send_ipi_mask(local_mask, vector);
> > +}
> > +
> > +static void kvm_send_ipi_allbutself(int vector)
> > +{
> > + kvm_send_ipi_mask_allbutself(cpu_online_mask, vector);
> > +}
> > +
> > +static void kvm_send_ipi_all(int vector)
> > +{
> > + __send_ipi_mask(cpu_online_mask, vector);
>
> These should be faster when using the native APIC shorthand -- is this
> the "Broadcast" in your tests?

Not true, .send_IPI_all almost no callers though linux apic drivers
implement this hook, in addition, shortcut is not used for x2apic
mode(__x2apic_send_IPI_dest()), and very limited using in other
scenarios according to linux apic drivers.

>
> > +}
> > +
> > +/*
> > + * Set the IPI entry points
> > + */
> > +static void kvm_setup_pv_ipi(void)
> > +{
> > + apic->send_IPI_mask = kvm_send_ipi_mask;
> > + apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself;
> > + apic->send_IPI_allbutself = kvm_send_ipi_allbutself;
> > + apic->send_IPI_all = kvm_send_ipi_all;
> > + pr_info("KVM setup pv IPIs\n");
> > +}
> > +#endif
> > +
> >  static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
> >  {
> >   native_smp_prepare_cpus(max_cpus);
> > @@ -626,6 +691,11 @@ static uint32_t __init kvm_detect(void)
> >
> >  static void __init kvm_apic_init(void)
> >  {
> > +#if defined(CONFIG_SMP) && defined(CONFIG_X86_64)
> > + if (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI) &&
> > +  

Re: [PATCH v3 2/6] KVM: X86: Implement PV IPIs in linux guest

2018-07-19 Thread Wanpeng Li
On Fri, 20 Jul 2018 at 00:28, Radim Krčmář  wrote:
>
> 2018-07-03 14:21+0800, Wanpeng Li:
> > From: Wanpeng Li 
> >
> > Implement paravirtual apic hooks to enable PV IPIs.
> >
> > apic->send_IPI_mask
> > apic->send_IPI_mask_allbutself
> > apic->send_IPI_allbutself
> > apic->send_IPI_all
> >
> > The PV IPIs supports maximal 128 vCPUs VM, it is big enough for cloud
> > environment currently, supporting more vCPUs needs to introduce more
> > complex logic, in the future this might be extended if needed.
> >
> > Cc: Paolo Bonzini 
> > Cc: Radim Krčmář 
> > Cc: Vitaly Kuznetsov 
> > Signed-off-by: Wanpeng Li 
> > ---
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > @@ -454,6 +454,71 @@ static void __init sev_map_percpu_data(void)
> >  }
> >
> >  #ifdef CONFIG_SMP
> > +
> > +#ifdef CONFIG_X86_64
> > +static void __send_ipi_mask(const struct cpumask *mask, int vector)
> > +{
> > + unsigned long flags, ipi_bitmap_low = 0, ipi_bitmap_high = 0;
> > + int cpu, apic_id;
> > +
> > + if (cpumask_empty(mask))
> > + return;
> > +
> > + local_irq_save(flags);
> > +
> > + for_each_cpu(cpu, mask) {
> > + apic_id = per_cpu(x86_cpu_to_apicid, cpu);
> > + if (apic_id < BITS_PER_LONG)
> > + __set_bit(apic_id, _bitmap_low);
> > + else if (apic_id < 2 * BITS_PER_LONG)
> > + __set_bit(apic_id - BITS_PER_LONG, _bitmap_high);
>
> It'd be nicer with 'unsigned long ipi_bitmap[2]' and a single
>
> __set_bit(apic_id, ipi_bitmap);
>
> > + }
> > +
> > + kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap_low, ipi_bitmap_high, 
> > vector);
>
> and
>
> kvm_hypercall3(KVM_HC_SEND_IPI, ipi_bitmap[0], ipi_bitmap[1], vector);
>
> Still, the main problem is that we can only address 128 APICs.
>
> A simple improvement would reuse the vector field (as we need only 8
> bits) and put a 'offset' in the rest.  The offset would say which
> cluster of 128 are we addressing.  24 bits of offset results in 2^31
> total addressable CPUs (we probably should even use that many bits).
> The downside of this is that we can only address 128 at a time.
>
> It's basically the same as x2apic cluster mode, only with 128 cluster
> size instead of 16, so the code should be a straightforward port.
> And because x2apic code doesn't seem to use any division by the cluster
> size, we could even try to use kvm_hypercall4, add ipi_bitmap[2], and
> make the cluster size 192. :)
>
> But because it is very similar to x2apic, I'd really need some real
> performance data to see if this benefits a real workload.

Thanks for your review, Radim! :) I will find another real benchmark
instead of the micro one to evaluate the performance.

> Hardware could further optimize LAPIC (apicv, vapic) in the future,
> which we'd lose by using paravirt.
>
> e.g. AMD's acceleration should be superior to this when using < 8 VCPUs
> as they can use logical xAPIC and send without VM exits (when all VCPUs
> are running).
>
> > +
> > + local_irq_restore(flags);
> > +}
> > +
> > +static void kvm_send_ipi_mask(const struct cpumask *mask, int vector)
> > +{
> > + __send_ipi_mask(mask, vector);
> > +}
> > +
> > +static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int 
> > vector)
> > +{
> > + unsigned int this_cpu = smp_processor_id();
> > + struct cpumask new_mask;
> > + const struct cpumask *local_mask;
> > +
> > + cpumask_copy(_mask, mask);
> > + cpumask_clear_cpu(this_cpu, _mask);
> > + local_mask = _mask;
> > + __send_ipi_mask(local_mask, vector);
> > +}
> > +
> > +static void kvm_send_ipi_allbutself(int vector)
> > +{
> > + kvm_send_ipi_mask_allbutself(cpu_online_mask, vector);
> > +}
> > +
> > +static void kvm_send_ipi_all(int vector)
> > +{
> > + __send_ipi_mask(cpu_online_mask, vector);
>
> These should be faster when using the native APIC shorthand -- is this
> the "Broadcast" in your tests?

Not true, .send_IPI_all almost no callers though linux apic drivers
implement this hook, in addition, shortcut is not used for x2apic
mode(__x2apic_send_IPI_dest()), and very limited using in other
scenarios according to linux apic drivers.

>
> > +}
> > +
> > +/*
> > + * Set the IPI entry points
> > + */
> > +static void kvm_setup_pv_ipi(void)
> > +{
> > + apic->send_IPI_mask = kvm_send_ipi_mask;
> > + apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself;
> > + apic->send_IPI_allbutself = kvm_send_ipi_allbutself;
> > + apic->send_IPI_all = kvm_send_ipi_all;
> > + pr_info("KVM setup pv IPIs\n");
> > +}
> > +#endif
> > +
> >  static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
> >  {
> >   native_smp_prepare_cpus(max_cpus);
> > @@ -626,6 +691,11 @@ static uint32_t __init kvm_detect(void)
> >
> >  static void __init kvm_apic_init(void)
> >  {
> > +#if defined(CONFIG_SMP) && defined(CONFIG_X86_64)
> > + if (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI) &&
> > +  

Re: [PATCH] ARM: dts: imx7d: remove "operating-points" property for cpu1

2018-07-19 Thread Shawn Guo
On Thu, Jul 19, 2018 at 04:24:19PM +0800, Anson Huang wrote:
> Commit b97872d4eb22 ("ARM: dts: imx: Add missing OPP properties for CPUs")
> added "operating-points" property for all CPUs, but i.MX7D already has
> "operating-points-v2" property on both CPUs, so no need to add
> "operating-points" property again, this patch removes it.
> 
> Fixes: b97872d4eb22 ("ARM: dts: imx: Add missing OPP properties for CPUs")
> Signed-off-by: Anson Huang 

Applied, thanks.


Re: [PATCH] ARM: dts: imx7d: remove "operating-points" property for cpu1

2018-07-19 Thread Shawn Guo
On Thu, Jul 19, 2018 at 04:24:19PM +0800, Anson Huang wrote:
> Commit b97872d4eb22 ("ARM: dts: imx: Add missing OPP properties for CPUs")
> added "operating-points" property for all CPUs, but i.MX7D already has
> "operating-points-v2" property on both CPUs, so no need to add
> "operating-points" property again, this patch removes it.
> 
> Fixes: b97872d4eb22 ("ARM: dts: imx: Add missing OPP properties for CPUs")
> Signed-off-by: Anson Huang 

Applied, thanks.


Re: [PATCH v2] ARM: dts: vf610: Add ZII CFU1 board

2018-07-19 Thread Shawn Guo
On Thu, Jul 19, 2018 at 12:57:24PM -0700, Andrey Smirnov wrote:
> Add support for the Zodiac Inflight Innovations CFU1
> board (VF610-based).
> 
> Cc: Shawn Guo 
> Cc: Fabio Estevam 
> Cc: cphe...@gmail.com
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: devicet...@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Reviewed-by: Fabio Estevam 
> Signed-off-by: Andrew Lunn 
> Signed-off-by: Andrey Smirnov 

Applied, thanks.


Re: [PATCH v2] ARM: dts: vf610: Add ZII CFU1 board

2018-07-19 Thread Shawn Guo
On Thu, Jul 19, 2018 at 12:57:24PM -0700, Andrey Smirnov wrote:
> Add support for the Zodiac Inflight Innovations CFU1
> board (VF610-based).
> 
> Cc: Shawn Guo 
> Cc: Fabio Estevam 
> Cc: cphe...@gmail.com
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: devicet...@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Reviewed-by: Fabio Estevam 
> Signed-off-by: Andrew Lunn 
> Signed-off-by: Andrey Smirnov 

Applied, thanks.


  1   2   3   4   5   6   7   8   9   10   >