Compliment of the day to you Dear Friend.

2018-07-28 Thread Mrs.Amina.Kadi
 Compliment of the day to you Dear Friend.

Dear Friend.
 
  I am Mrs. Amina Kadi. am sending this brief letter to solicit your
partnership to transfer $5.5 million US Dollars. I shall send you
more information and procedures when I receive positive response from
you.

Mrs. Amina Kadi









Compliment of the day to you Dear Friend.

2018-07-28 Thread Mrs.Amina.Kadi
 Compliment of the day to you Dear Friend.

Dear Friend.
 
  I am Mrs. Amina Kadi. am sending this brief letter to solicit your
partnership to transfer $5.5 million US Dollars. I shall send you
more information and procedures when I receive positive response from
you.

Mrs. Amina Kadi









[PATCH 2/2] staging: erofs: fix conditional uninitialized `pcn' in z_erofs_map_blocks_iter

2018-07-28 Thread Gao Xiang
This patch adds error handling code for
z_erofs_map_blocks_iter to fix the compiler blame.

Signed-off-by: Gao Xiang 
---

let's solve the compiler warning first, more error handling code
for other functions will be added in the future patch.

 drivers/staging/erofs/unzip_vle.c | 25 +
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/erofs/unzip_vle.c 
b/drivers/staging/erofs/unzip_vle.c
index 0e410a228cd4..bd2d7a8d5085 100644
--- a/drivers/staging/erofs/unzip_vle.c
+++ b/drivers/staging/erofs/unzip_vle.c
@@ -1532,13 +1532,14 @@ int z_erofs_map_blocks_iter(struct inode *inode,
unsigned long long ofs, end;
struct z_erofs_vle_decompressed_index *di;
erofs_blk_t e_blkaddr, pcn;
-   unsigned lcn, logical_cluster_ofs;
+   unsigned lcn, logical_cluster_ofs, cluster_type;
u32 ofs_rem;
struct page *mpage = *mpage_ret;
void *kaddr;
bool initial;
const unsigned int clusterbits = EROFS_SB(inode->i_sb)->clusterbits;
const unsigned int clustersize = 1 << clusterbits;
+   int err = 0;
 
/* if both m_(l,p)len are 0, regularize l_lblk, l_lofs, etc... */
initial = !map->m_llen;
@@ -1592,7 +1593,9 @@ int z_erofs_map_blocks_iter(struct inode *inode,
 
end = (u64)(lcn + 1) * clustersize;
 
-   switch (vle_cluster_type(di)) {
+   cluster_type = vle_cluster_type(di);
+
+   switch (cluster_type) {
case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
if (ofs_rem >= logical_cluster_ofs)
map->m_flags ^= EROFS_MAP_ZIPPED;
@@ -1608,13 +1611,24 @@ int z_erofs_map_blocks_iter(struct inode *inode,
break;
}
 
-   BUG_ON(!lcn);   /* logical cluster number >= 1 */
+   /* logical cluster number should be >= 1 */
+   if (unlikely(!lcn)) {
+   errln("invalid logical cluster 0 at nid %llu",
+   EROFS_V(inode)->nid);
+   err = -EIO;
+   goto unmap_out;
+   }
end = (lcn-- * clustersize) | logical_cluster_ofs;
case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
/* get the correspoinding first chunk */
ofs = vle_get_logical_extent_head(inode, mpage_ret,
, lcn, , >m_flags);
mpage = *mpage_ret;
+   default:
+   errln("unknown cluster type %u at offset %llu of nid %llu",
+   cluster_type, ofs, EROFS_V(inode)->nid);
+   err = -EIO;
+   goto unmap_out;
}
 
map->m_la = ofs;
@@ -1630,6 +1644,9 @@ int z_erofs_map_blocks_iter(struct inode *inode,
debugln("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o",
__func__, map->m_la, map->m_pa,
map->m_llen, map->m_plen, map->m_flags);
-   return 0;
+
+   /* aggressively BUG_ON iff CONFIG_EROFS_FS_DEBUG is on */
+   DBG_BUGON(err < 0);
+   return err;
 }
 
-- 
2.17.1



[PATCH 2/2] staging: erofs: fix conditional uninitialized `pcn' in z_erofs_map_blocks_iter

2018-07-28 Thread Gao Xiang
This patch adds error handling code for
z_erofs_map_blocks_iter to fix the compiler blame.

Signed-off-by: Gao Xiang 
---

let's solve the compiler warning first, more error handling code
for other functions will be added in the future patch.

 drivers/staging/erofs/unzip_vle.c | 25 +
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/erofs/unzip_vle.c 
b/drivers/staging/erofs/unzip_vle.c
index 0e410a228cd4..bd2d7a8d5085 100644
--- a/drivers/staging/erofs/unzip_vle.c
+++ b/drivers/staging/erofs/unzip_vle.c
@@ -1532,13 +1532,14 @@ int z_erofs_map_blocks_iter(struct inode *inode,
unsigned long long ofs, end;
struct z_erofs_vle_decompressed_index *di;
erofs_blk_t e_blkaddr, pcn;
-   unsigned lcn, logical_cluster_ofs;
+   unsigned lcn, logical_cluster_ofs, cluster_type;
u32 ofs_rem;
struct page *mpage = *mpage_ret;
void *kaddr;
bool initial;
const unsigned int clusterbits = EROFS_SB(inode->i_sb)->clusterbits;
const unsigned int clustersize = 1 << clusterbits;
+   int err = 0;
 
/* if both m_(l,p)len are 0, regularize l_lblk, l_lofs, etc... */
initial = !map->m_llen;
@@ -1592,7 +1593,9 @@ int z_erofs_map_blocks_iter(struct inode *inode,
 
end = (u64)(lcn + 1) * clustersize;
 
-   switch (vle_cluster_type(di)) {
+   cluster_type = vle_cluster_type(di);
+
+   switch (cluster_type) {
case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
if (ofs_rem >= logical_cluster_ofs)
map->m_flags ^= EROFS_MAP_ZIPPED;
@@ -1608,13 +1611,24 @@ int z_erofs_map_blocks_iter(struct inode *inode,
break;
}
 
-   BUG_ON(!lcn);   /* logical cluster number >= 1 */
+   /* logical cluster number should be >= 1 */
+   if (unlikely(!lcn)) {
+   errln("invalid logical cluster 0 at nid %llu",
+   EROFS_V(inode)->nid);
+   err = -EIO;
+   goto unmap_out;
+   }
end = (lcn-- * clustersize) | logical_cluster_ofs;
case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
/* get the correspoinding first chunk */
ofs = vle_get_logical_extent_head(inode, mpage_ret,
, lcn, , >m_flags);
mpage = *mpage_ret;
+   default:
+   errln("unknown cluster type %u at offset %llu of nid %llu",
+   cluster_type, ofs, EROFS_V(inode)->nid);
+   err = -EIO;
+   goto unmap_out;
}
 
map->m_la = ofs;
@@ -1630,6 +1644,9 @@ int z_erofs_map_blocks_iter(struct inode *inode,
debugln("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o",
__func__, map->m_la, map->m_pa,
map->m_llen, map->m_plen, map->m_flags);
-   return 0;
+
+   /* aggressively BUG_ON iff CONFIG_EROFS_FS_DEBUG is on */
+   DBG_BUGON(err < 0);
+   return err;
 }
 
-- 
2.17.1



[PATCH] cpufreq: intel_pstate: warn if HWP Native mode and OOB mode are both set

2018-07-28 Thread oceanhe
From: Ocean He 

Refer to Intel HWPM Compliance Guide (Document Number: 566474): Bit[6] or
bit[8] of MSR MISC_PWR_MGMT is set only when BIOS select either HWP Native
mode or HWP OOB mode. Bit[6] and bit[8] cannot be set both at the same
time.

Add a warning message if intel_pstate detects both HWP Native mode and
HWP OOB mode are set at the same time.

Signed-off-by: Ocean He 
---
 drivers/cpufreq/intel_pstate.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 3c39712..678d3f2 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -2455,8 +2455,12 @@ static bool __init 
intel_pstate_platform_pwr_mgmt_exists(void)
id = x86_match_cpu(intel_pstate_cpu_oob_ids);
if (id) {
rdmsrl(MSR_MISC_PWR_MGMT, misc_pwr);
-   if ( misc_pwr & (1 << 8))
+   if (misc_pwr & (1 << 8)) {
+   if (misc_pwr & (1 << 6))
+   pr_warn(FW_WARN
+   "HWP Native mode and OOB mode cannot be 
set both at the same time.\n");
return true;
+   }
}
 
idx = acpi_match_platform_list(plat_info);
-- 
1.8.3.1




[PATCH] cpufreq: intel_pstate: warn if HWP Native mode and OOB mode are both set

2018-07-28 Thread oceanhe
From: Ocean He 

Refer to Intel HWPM Compliance Guide (Document Number: 566474): Bit[6] or
bit[8] of MSR MISC_PWR_MGMT is set only when BIOS select either HWP Native
mode or HWP OOB mode. Bit[6] and bit[8] cannot be set both at the same
time.

Add a warning message if intel_pstate detects both HWP Native mode and
HWP OOB mode are set at the same time.

Signed-off-by: Ocean He 
---
 drivers/cpufreq/intel_pstate.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 3c39712..678d3f2 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -2455,8 +2455,12 @@ static bool __init 
intel_pstate_platform_pwr_mgmt_exists(void)
id = x86_match_cpu(intel_pstate_cpu_oob_ids);
if (id) {
rdmsrl(MSR_MISC_PWR_MGMT, misc_pwr);
-   if ( misc_pwr & (1 << 8))
+   if (misc_pwr & (1 << 8)) {
+   if (misc_pwr & (1 << 6))
+   pr_warn(FW_WARN
+   "HWP Native mode and OOB mode cannot be 
set both at the same time.\n");
return true;
+   }
}
 
idx = acpi_match_platform_list(plat_info);
-- 
1.8.3.1




Re: [PATCH 06/10] mm,x86: skip cr4 and ldt reload when mm stays the same

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> When switching back from lazy TLB mode to a thread of the same process
> that switched into lazy TLB mode, we still have the cr4 (and sometimes
> LDT) of that process loaded, and there is no need to reload it.
>
> When there was no TLB flush while the CPU was in lazy TLB mode, the
> current code in switch_mm_irqs_off already avoids the reload, by
> returning early.
>
> However, when the TLB contents on the CPU are out of date, and we
> flush the TLB for the task, we fall through to the regular context
> switching code. This patch teaches that code to skip the cr4 and LDT
> flushes when switching back to the same mm after a flush.

Acked-by: Andy Lutomirski 


Re: [PATCH 06/10] mm,x86: skip cr4 and ldt reload when mm stays the same

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> When switching back from lazy TLB mode to a thread of the same process
> that switched into lazy TLB mode, we still have the cr4 (and sometimes
> LDT) of that process loaded, and there is no need to reload it.
>
> When there was no TLB flush while the CPU was in lazy TLB mode, the
> current code in switch_mm_irqs_off already avoids the reload, by
> returning early.
>
> However, when the TLB contents on the CPU are out of date, and we
> flush the TLB for the task, we fall through to the regular context
> switching code. This patch teaches that code to skip the cr4 and LDT
> flushes when switching back to the same mm after a flush.

Acked-by: Andy Lutomirski 


Re: [PATCH 10/10] mm,sched: conditionally skip lazy TLB mm refcounting

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> Conditionally skip lazy TLB mm refcounting. When an architecture has
> CONFIG_ARCH_NO_ACTIVE_MM_REFCOUNTING enabled, an mm that is used in
> lazy TLB mode anywhere will get shot down from exit_mmap, and there
> in no need to incur the cache line bouncing overhead of refcounting
> a lazy TLB mm.

Unless I've misunderstood something, this patch results in idle tasks
whose active_mm has been freed still having active_mm pointing at
freed memory.  This isn't strictly speaking a bug, but it's extremely
confusing and risks all kinds of nasty errors.  That's why I prefer
the approach of actually removing the active_mm field on x86 rather
than merely removing the refcount.

I realize that this will add more ifdeffery and make the patch a bit
bigger, but I think it'll be much more robust.  Not to mention that it
will save a pointer an a refcount per mm_struct, but that barely
matters.


Re: [PATCH 10/10] mm,sched: conditionally skip lazy TLB mm refcounting

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> Conditionally skip lazy TLB mm refcounting. When an architecture has
> CONFIG_ARCH_NO_ACTIVE_MM_REFCOUNTING enabled, an mm that is used in
> lazy TLB mode anywhere will get shot down from exit_mmap, and there
> in no need to incur the cache line bouncing overhead of refcounting
> a lazy TLB mm.

Unless I've misunderstood something, this patch results in idle tasks
whose active_mm has been freed still having active_mm pointing at
freed memory.  This isn't strictly speaking a bug, but it's extremely
confusing and risks all kinds of nasty errors.  That's why I prefer
the approach of actually removing the active_mm field on x86 rather
than merely removing the refcount.

I realize that this will add more ifdeffery and make the patch a bit
bigger, but I think it'll be much more robust.  Not to mention that it
will save a pointer an a refcount per mm_struct, but that barely
matters.


Re: [PATCH v0 3/4] drivers: edac: Add cache erp driver for Last Level Cache Controller (LLCC)

2018-07-28 Thread Borislav Petkov
On Wed, Jul 25, 2018 at 10:44:56AM -0700, Venkata Narendra Kumar Gutta wrote:
> Add cache error reporting driver for single and double bit errors on
> Last Level Cache Controller (LLCC) cache. This driver takes care of
> dumping registers and add config options to enable and disable panic
> when these errors happen.
> 
> Signed-off-by: Channagoud Kadabi 
> Signed-off-by: Venkata Narendra Kumar Gutta 

This SOB chain doesn't make any sense - see
Documentation/process/submitting-patches.rst

> ---
>  drivers/edac/Kconfig  |  21 ++
>  drivers/edac/Makefile |   1 +
>  drivers/edac/qcom_llcc_edac.c | 520 
> ++
>  3 files changed, 542 insertions(+)
>  create mode 100644 drivers/edac/qcom_llcc_edac.c

Needs MAINTAINERS entry so that you get all the bug reports.

> diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
> index 57304b2..68518ad 100644
> --- a/drivers/edac/Kconfig
> +++ b/drivers/edac/Kconfig
> @@ -460,4 +460,25 @@ config EDAC_TI
> Support for error detection and correction on the
>TI SoCs.
>  
> +config EDAC_QCOM_LLCC
> +depends on QCOM_LLCC
> +tristate "QCOM EDAC Controller for LLCC Cache"

No edac driver per functional unit pls - see how altera_edac.c does it,
for example. IOW, this driver - if it cannot share/reuse any of the
existing edac drivers, it should be called qcom_edac and contain all the
Qualcomm-specific RAS features there.

> +help
> +  Support for error detection and correction on the
> +  QCOM LLCC cache. Report errors caught by LLCC ECC
> +  mechanism.
> +
> +  For debugging issues having to do with stability and overall system
> +  health, you should probably say 'Y' here.
> +
> +config EDAC_QCOM_LLCC_PANIC_ON_UE
> +depends on EDAC_QCOM_LLCC
> +bool "Panic on uncorrectable errors - qcom llcc"
> +help
> +  Forcibly cause a kernel panic if an uncorrectable error (UE) is
> +  detected. This can reduce debugging times on hardware which may be
> +  operating at voltages or frequencies outside normal specification.
> +
> +  For production builds, you should probably say 'N' here.
> +
>  endif # EDAC
> diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
> index 02b43a7..28aff28 100644
> --- a/drivers/edac/Makefile
> +++ b/drivers/edac/Makefile
> @@ -77,3 +77,4 @@ obj-$(CONFIG_EDAC_ALTERA)   += altera_edac.o
>  obj-$(CONFIG_EDAC_SYNOPSYS)  += synopsys_edac.o
>  obj-$(CONFIG_EDAC_XGENE) += xgene_edac.o
>  obj-$(CONFIG_EDAC_TI)+= ti_edac.o
> +obj-$(CONFIG_EDAC_QCOM_LLCC) += qcom_llcc_edac.o
> diff --git a/drivers/edac/qcom_llcc_edac.c b/drivers/edac/qcom_llcc_edac.c
> new file mode 100644
> index 000..7a678b5
> --- /dev/null
> +++ b/drivers/edac/qcom_llcc_edac.c
> @@ -0,0 +1,520 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "edac_mc.h"
> +#include "edac_device.h"
> +
> +#ifdef CONFIG_EDAC_QCOM_LLCC_PANIC_ON_UE
> +#define LLCC_ERP_PANIC_ON_UE 1
> +#else
> +#define LLCC_ERP_PANIC_ON_UE 0
> +#endif
> +
> +#define EDAC_LLCC"qcom_llcc"
> +
> +#define TRP_SYN_REG_CNT  6
> +
> +#define DRP_SYN_REG_CNT  8
> +
> +#define LLCC_COMMON_STATUS0  0x0003000C
> +#define LLCC_LB_CNT_MASK GENMASK(31, 28)
> +#define LLCC_LB_CNT_SHIFT28
> +
> +/* single & Double Bit syndrome register offsets */
> +#define TRP_ECC_SB_ERR_SYN0  0x0002304C
> +#define TRP_ECC_DB_ERR_SYN0  0x00020370
> +#define DRP_ECC_SB_ERR_SYN0  0x0004204C
> +#define DRP_ECC_DB_ERR_SYN0  0x00042070
> +
> +/* Error register offsets */
> +#define TRP_ECC_ERROR_STATUS10x00020348
> +#define TRP_ECC_ERROR_STATUS00x00020344
> +#define DRP_ECC_ERROR_STATUS10x00042048
> +#define DRP_ECC_ERROR_STATUS00x00042044
> +
> +/* TRP, DRP interrupt register offsets */
> +#define DRP_INTERRUPT_STATUS 0x00041000
> +#define TRP_INTERRUPT_0_STATUS   0x00020480
> +#define DRP_INTERRUPT_CLEAR  0x00041008
> +#define DRP_ECC_ERROR_CNTR_CLEAR 0x00040004
> +#define TRP_INTERRUPT_0_CLEAR0x00020484
> +#define TRP_ECC_ERROR_CNTR_CLEAR 0x00020440
> +
> +/* Mask and shift macros */
> +#define ECC_DB_ERR_COUNT_MASKGENMASK(4, 0)

Align all those to the same vertical column.

> +#define ECC_DB_ERR_WAYS_MASK GENMASK(31, 16)
> +#define ECC_DB_ERR_WAYS_SHIFTBIT(4)
> +
> +#define ECC_SB_ERR_COUNT_MASKGENMASK(23, 16)
> +#define ECC_SB_ERR_COUNT_SHIFT   BIT(4)
> +#define ECC_SB_ERR_WAYS_MASK GENMASK(15, 0)
> +
> +#define SB_ECC_ERROR BIT(0)
> +#define DB_ECC_ERROR BIT(1)
> +
> 

Re: [PATCH v0 3/4] drivers: edac: Add cache erp driver for Last Level Cache Controller (LLCC)

2018-07-28 Thread Borislav Petkov
On Wed, Jul 25, 2018 at 10:44:56AM -0700, Venkata Narendra Kumar Gutta wrote:
> Add cache error reporting driver for single and double bit errors on
> Last Level Cache Controller (LLCC) cache. This driver takes care of
> dumping registers and add config options to enable and disable panic
> when these errors happen.
> 
> Signed-off-by: Channagoud Kadabi 
> Signed-off-by: Venkata Narendra Kumar Gutta 

This SOB chain doesn't make any sense - see
Documentation/process/submitting-patches.rst

> ---
>  drivers/edac/Kconfig  |  21 ++
>  drivers/edac/Makefile |   1 +
>  drivers/edac/qcom_llcc_edac.c | 520 
> ++
>  3 files changed, 542 insertions(+)
>  create mode 100644 drivers/edac/qcom_llcc_edac.c

Needs MAINTAINERS entry so that you get all the bug reports.

> diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
> index 57304b2..68518ad 100644
> --- a/drivers/edac/Kconfig
> +++ b/drivers/edac/Kconfig
> @@ -460,4 +460,25 @@ config EDAC_TI
> Support for error detection and correction on the
>TI SoCs.
>  
> +config EDAC_QCOM_LLCC
> +depends on QCOM_LLCC
> +tristate "QCOM EDAC Controller for LLCC Cache"

No edac driver per functional unit pls - see how altera_edac.c does it,
for example. IOW, this driver - if it cannot share/reuse any of the
existing edac drivers, it should be called qcom_edac and contain all the
Qualcomm-specific RAS features there.

> +help
> +  Support for error detection and correction on the
> +  QCOM LLCC cache. Report errors caught by LLCC ECC
> +  mechanism.
> +
> +  For debugging issues having to do with stability and overall system
> +  health, you should probably say 'Y' here.
> +
> +config EDAC_QCOM_LLCC_PANIC_ON_UE
> +depends on EDAC_QCOM_LLCC
> +bool "Panic on uncorrectable errors - qcom llcc"
> +help
> +  Forcibly cause a kernel panic if an uncorrectable error (UE) is
> +  detected. This can reduce debugging times on hardware which may be
> +  operating at voltages or frequencies outside normal specification.
> +
> +  For production builds, you should probably say 'N' here.
> +
>  endif # EDAC
> diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
> index 02b43a7..28aff28 100644
> --- a/drivers/edac/Makefile
> +++ b/drivers/edac/Makefile
> @@ -77,3 +77,4 @@ obj-$(CONFIG_EDAC_ALTERA)   += altera_edac.o
>  obj-$(CONFIG_EDAC_SYNOPSYS)  += synopsys_edac.o
>  obj-$(CONFIG_EDAC_XGENE) += xgene_edac.o
>  obj-$(CONFIG_EDAC_TI)+= ti_edac.o
> +obj-$(CONFIG_EDAC_QCOM_LLCC) += qcom_llcc_edac.o
> diff --git a/drivers/edac/qcom_llcc_edac.c b/drivers/edac/qcom_llcc_edac.c
> new file mode 100644
> index 000..7a678b5
> --- /dev/null
> +++ b/drivers/edac/qcom_llcc_edac.c
> @@ -0,0 +1,520 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2018, The Linux Foundation. All rights reserved.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "edac_mc.h"
> +#include "edac_device.h"
> +
> +#ifdef CONFIG_EDAC_QCOM_LLCC_PANIC_ON_UE
> +#define LLCC_ERP_PANIC_ON_UE 1
> +#else
> +#define LLCC_ERP_PANIC_ON_UE 0
> +#endif
> +
> +#define EDAC_LLCC"qcom_llcc"
> +
> +#define TRP_SYN_REG_CNT  6
> +
> +#define DRP_SYN_REG_CNT  8
> +
> +#define LLCC_COMMON_STATUS0  0x0003000C
> +#define LLCC_LB_CNT_MASK GENMASK(31, 28)
> +#define LLCC_LB_CNT_SHIFT28
> +
> +/* single & Double Bit syndrome register offsets */
> +#define TRP_ECC_SB_ERR_SYN0  0x0002304C
> +#define TRP_ECC_DB_ERR_SYN0  0x00020370
> +#define DRP_ECC_SB_ERR_SYN0  0x0004204C
> +#define DRP_ECC_DB_ERR_SYN0  0x00042070
> +
> +/* Error register offsets */
> +#define TRP_ECC_ERROR_STATUS10x00020348
> +#define TRP_ECC_ERROR_STATUS00x00020344
> +#define DRP_ECC_ERROR_STATUS10x00042048
> +#define DRP_ECC_ERROR_STATUS00x00042044
> +
> +/* TRP, DRP interrupt register offsets */
> +#define DRP_INTERRUPT_STATUS 0x00041000
> +#define TRP_INTERRUPT_0_STATUS   0x00020480
> +#define DRP_INTERRUPT_CLEAR  0x00041008
> +#define DRP_ECC_ERROR_CNTR_CLEAR 0x00040004
> +#define TRP_INTERRUPT_0_CLEAR0x00020484
> +#define TRP_ECC_ERROR_CNTR_CLEAR 0x00020440
> +
> +/* Mask and shift macros */
> +#define ECC_DB_ERR_COUNT_MASKGENMASK(4, 0)

Align all those to the same vertical column.

> +#define ECC_DB_ERR_WAYS_MASK GENMASK(31, 16)
> +#define ECC_DB_ERR_WAYS_SHIFTBIT(4)
> +
> +#define ECC_SB_ERR_COUNT_MASKGENMASK(23, 16)
> +#define ECC_SB_ERR_COUNT_SHIFT   BIT(4)
> +#define ECC_SB_ERR_WAYS_MASK GENMASK(15, 0)
> +
> +#define SB_ECC_ERROR BIT(0)
> +#define DB_ECC_ERROR BIT(1)
> +
> 

Re: [PATCH 01/10] x86,tlb: clarify memory barrier in switch_mm_irqs_off

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> Clarify exactly what the memory barrier synchronizes with.

Reviewed-by: Andy Lutomirski 


Re: [PATCH 01/10] x86,tlb: clarify memory barrier in switch_mm_irqs_off

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> Clarify exactly what the memory barrier synchronizes with.

Reviewed-by: Andy Lutomirski 


Re: [PATCH 02/10] smp: use __cpumask_set_cpu in on_each_cpu_cond

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> The code in on_each_cpu_cond sets CPUs in a locally allocated bitmask,
> which should never be used by other CPUs simultaneously. There is no
> need to use locked memory accesses to set the bits in this bitmap.
>
> Switch to __cpumask_set_cpu.

Reviewed-by: Andy Lutomirski 


Re: [PATCH 02/10] smp: use __cpumask_set_cpu in on_each_cpu_cond

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> The code in on_each_cpu_cond sets CPUs in a locally allocated bitmask,
> which should never be used by other CPUs simultaneously. There is no
> need to use locked memory accesses to set the bits in this bitmap.
>
> Switch to __cpumask_set_cpu.

Reviewed-by: Andy Lutomirski 


Re: [PATCH 04/10] x86,mm: use on_each_cpu_cond for TLB flushes

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> Instead of open coding bitmap magic, use on_each_cpu_cond
> to determine which CPUs to send TLB flush IPIs to.
>
> This might be a little bit slower than examining the bitmaps,
> but it should be a lot easier to maintain in the long run.

Looks good.

i assume it's not easy to get the remove-tables case to do a single
on_each_cpu_cond() instead of two?  Currently it's doing the lazy ones
and the non-lazy ones separately.


Re: [PATCH 04/10] x86,mm: use on_each_cpu_cond for TLB flushes

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> Instead of open coding bitmap magic, use on_each_cpu_cond
> to determine which CPUs to send TLB flush IPIs to.
>
> This might be a little bit slower than examining the bitmaps,
> but it should be a lot easier to maintain in the long run.

Looks good.

i assume it's not easy to get the remove-tables case to do a single
on_each_cpu_cond() instead of two?  Currently it's doing the lazy ones
and the non-lazy ones separately.


Re: [PATCH 03/10] smp,cpumask: introduce on_each_cpu_cond_mask

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> Introduce a variant of on_each_cpu_cond that iterates only over the
> CPUs in a cpumask, in order to avoid making callbacks for every single
> CPU in the system when we only need to test a subset.

Nice.

Although, if you want to be really fancy, you could optimize this (or
add a variant) that does the callback on the local CPU in parallel
with the remote ones.  That would give a small boost to TLB flushes.


Re: [PATCH 03/10] smp,cpumask: introduce on_each_cpu_cond_mask

2018-07-28 Thread Andy Lutomirski
On Sat, Jul 28, 2018 at 2:53 PM, Rik van Riel  wrote:
> Introduce a variant of on_each_cpu_cond that iterates only over the
> CPUs in a cpumask, in order to avoid making callbacks for every single
> CPU in the system when we only need to test a subset.

Nice.

Although, if you want to be really fancy, you could optimize this (or
add a variant) that does the callback on the local CPU in parallel
with the remote ones.  That would give a small boost to TLB flushes.


linux-next: Signed-off-by missing for commit in the arc-current tree

2018-07-28 Thread Stephen Rothwell
Hi Vineet,

Commit

  fa52704e2816 ("ARC: add SMP_CACHE_BYTES value validate")

is missing a Signed-off-by from its committer.

-- 
Cheers,
Stephen Rothwell


pgpNj5UEArVOk.pgp
Description: OpenPGP digital signature


linux-next: Signed-off-by missing for commit in the arc-current tree

2018-07-28 Thread Stephen Rothwell
Hi Vineet,

Commit

  fa52704e2816 ("ARC: add SMP_CACHE_BYTES value validate")

is missing a Signed-off-by from its committer.

-- 
Cheers,
Stephen Rothwell


pgpNj5UEArVOk.pgp
Description: OpenPGP digital signature


Re: [PATCH v2] scripts: Add Python 3 support to tracing/draw_functrace.py

2018-07-28 Thread Masahiro Yamada
2018-07-28 23:48 GMT+09:00 Jeremy Cline :
> Use the print function. This maintains Python 2 support and should have
> no functional change.
>
> Signed-off-by: Jeremy Cline 
> ---

Applied to linux-kbuild. Thanks!


> Changes from v1:
>   - Drop "from __future__ import print_function" as Python 2 is not long
> for this world and in this case the statement and function behave
> the same way.
>
>  scripts/tracing/draw_functrace.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/tracing/draw_functrace.py 
> b/scripts/tracing/draw_functrace.py
> index db40fa04cd51..9b6dd4f36335 100755
> --- a/scripts/tracing/draw_functrace.py
> +++ b/scripts/tracing/draw_functrace.py
> @@ -123,7 +123,7 @@ def main():
> tree = tree.getParent(caller)
> tree = tree.calls(callee, calltime)
>
> -   print CallTree.ROOT
> +   print(CallTree.ROOT)
>
>  if __name__ == "__main__":
> main()
> --
> 2.17.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Best Regards
Masahiro Yamada


Re: [PATCH v2] scripts: Add Python 3 support to tracing/draw_functrace.py

2018-07-28 Thread Masahiro Yamada
2018-07-28 23:48 GMT+09:00 Jeremy Cline :
> Use the print function. This maintains Python 2 support and should have
> no functional change.
>
> Signed-off-by: Jeremy Cline 
> ---

Applied to linux-kbuild. Thanks!


> Changes from v1:
>   - Drop "from __future__ import print_function" as Python 2 is not long
> for this world and in this case the statement and function behave
> the same way.
>
>  scripts/tracing/draw_functrace.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/tracing/draw_functrace.py 
> b/scripts/tracing/draw_functrace.py
> index db40fa04cd51..9b6dd4f36335 100755
> --- a/scripts/tracing/draw_functrace.py
> +++ b/scripts/tracing/draw_functrace.py
> @@ -123,7 +123,7 @@ def main():
> tree = tree.getParent(caller)
> tree = tree.calls(callee, calltime)
>
> -   print CallTree.ROOT
> +   print(CallTree.ROOT)
>
>  if __name__ == "__main__":
> main()
> --
> 2.17.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Best Regards
Masahiro Yamada


(no subject)

2018-07-28 Thread Yue Eddie
-- 
I have a business proposal contact ( yue.eddi...@live.com ) for more
details

(no subject)

2018-07-28 Thread Yue Eddie
-- 
I have a business proposal contact ( yue.eddi...@live.com ) for more
details

[PATCH] microblaze: delete wrong comment about machine_early_init

2018-07-28 Thread Masahiro Yamada
machine_early_init is defined in arch/microblaze/kernel/setup.c
I do not see mach-* directory for MicroBlaze.

Signed-off-by: Masahiro Yamada 
---

 arch/microblaze/kernel/head.S | 5 -
 1 file changed, 5 deletions(-)

diff --git a/arch/microblaze/kernel/head.S b/arch/microblaze/kernel/head.S
index 4655ff3..f264fdc 100644
--- a/arch/microblaze/kernel/head.S
+++ b/arch/microblaze/kernel/head.S
@@ -341,11 +341,6 @@ start_here:
/* Initialize r31 with current task address */
addik   r31, r0, init_task
 
-   /*
-* Call platform dependent initialize function.
-* Please see $(ARCH)/mach-$(SUBARCH)/setup.c for
-* the function.
-*/
addik   r11, r0, machine_early_init
brald   r15, r11
nop
-- 
2.7.4



[PATCH] microblaze: delete wrong comment about machine_early_init

2018-07-28 Thread Masahiro Yamada
machine_early_init is defined in arch/microblaze/kernel/setup.c
I do not see mach-* directory for MicroBlaze.

Signed-off-by: Masahiro Yamada 
---

 arch/microblaze/kernel/head.S | 5 -
 1 file changed, 5 deletions(-)

diff --git a/arch/microblaze/kernel/head.S b/arch/microblaze/kernel/head.S
index 4655ff3..f264fdc 100644
--- a/arch/microblaze/kernel/head.S
+++ b/arch/microblaze/kernel/head.S
@@ -341,11 +341,6 @@ start_here:
/* Initialize r31 with current task address */
addik   r31, r0, init_task
 
-   /*
-* Call platform dependent initialize function.
-* Please see $(ARCH)/mach-$(SUBARCH)/setup.c for
-* the function.
-*/
addik   r11, r0, machine_early_init
brald   r15, r11
nop
-- 
2.7.4



[GIT PULL] random fixes for 4.18-rc7

2018-07-28 Thread Theodore Y. Ts'o
The following changes since commit 1e4b044d22517cae7047c99038abb23243ca:

  Linux 4.18-rc4 (2018-07-08 16:34:02 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random.git 
tags/random_for_linus_stable

for you to fetch changes up to 81e69df38e2911b642ec121dec319fad2a4782f3:

  random: mix rdrand with entropy sent in from userspace (2018-07-17 21:32:36 
-0400)


In reaction to the fixes to address CVE-2018-1108, some Linux
distributions that have certain systemd versions in some cases
combined with patches to libcrypt for FIPS/FEDRAMP compliance, have
led to boot-time stalls for some hardware.  The reaction by some
distros and Linux sysadmins has been to install packages that try to
do complicated things with the CPU and hope that leads to randomness.
To mitigate this, if RDRAND is available, mix it into entropy provided
by userspace.  It won't hurt. and it will probably help.


Theodore Ts'o (1):
  random: mix rdrand with entropy sent in from userspace

 drivers/char/random.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)


[GIT PULL] random fixes for 4.18-rc7

2018-07-28 Thread Theodore Y. Ts'o
The following changes since commit 1e4b044d22517cae7047c99038abb23243ca:

  Linux 4.18-rc4 (2018-07-08 16:34:02 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random.git 
tags/random_for_linus_stable

for you to fetch changes up to 81e69df38e2911b642ec121dec319fad2a4782f3:

  random: mix rdrand with entropy sent in from userspace (2018-07-17 21:32:36 
-0400)


In reaction to the fixes to address CVE-2018-1108, some Linux
distributions that have certain systemd versions in some cases
combined with patches to libcrypt for FIPS/FEDRAMP compliance, have
led to boot-time stalls for some hardware.  The reaction by some
distros and Linux sysadmins has been to install packages that try to
do complicated things with the CPU and hope that leads to randomness.
To mitigate this, if RDRAND is available, mix it into entropy provided
by userspace.  It won't hurt. and it will probably help.


Theodore Ts'o (1):
  random: mix rdrand with entropy sent in from userspace

 drivers/char/random.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)


Re: [PATCH v2] pci/aspm: Remove CONFIG_PCIEASPM_DEBUG

2018-07-28 Thread Sinan Kaya

On 7/27/2018 1:26 PM, Bjorn Helgaas wrote:

- A link can lead to a multi-function device, and the spec allows
 those functions to have different ASPM settings (see PCIe r4.0,
 sec 5.4.1).  With the sysfs files at the upstream end of the link,
 we have no way to configure those functions individually.


Even though we can set them individually, there is only one PCIe link
for single function as well as multi-function devices.

It would be a user mistake to allow individual PCIe functions with
different ASPM policies. (maybe, we should enforce it if we are not
doing it already).


Re: [PATCH v2] pci/aspm: Remove CONFIG_PCIEASPM_DEBUG

2018-07-28 Thread Sinan Kaya

On 7/27/2018 1:26 PM, Bjorn Helgaas wrote:

- A link can lead to a multi-function device, and the spec allows
 those functions to have different ASPM settings (see PCIe r4.0,
 sec 5.4.1).  With the sysfs files at the upstream end of the link,
 we have no way to configure those functions individually.


Even though we can set them individually, there is only one PCIe link
for single function as well as multi-function devices.

It would be a user mistake to allow individual PCIe functions with
different ASPM policies. (maybe, we should enforce it if we are not
doing it already).


Re: [PATCH v2 01/17] x86/cpu: create Dhyana init file and register new cpu_dev to system

2018-07-28 Thread Paolo Bonzini
On 28/07/2018 18:48, pu...@hygon.cn wrote:
> Hi Paolo,
> 
> Thanks for your feedback.
> 
> As we described in the patch description, current Hygon Family 18h share
> most architecture with AMD Family 17h. But Hygon Family 18h are not the
> same with AMD family 17h, as it removed some features such as SME/SEV in
> Dhyana.

If the maintainers are okay with X86_FEATURE_HYGON that's certainly
fine, however I think you can improve the consistency of the patches in
a few ways.

Lack of SME/SEV is not an issue, since there are AMD Zen chips without
SME/SEV too, but potential incompatibility with future AMD fam18h chips
is important.  Therefore, code like this one in amd_uncore_init


-   if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
+   if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
+   boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
return -ENODEV;

if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
return -ENODEV;

-   if (boot_cpu_data.x86 == 0x17) {
+   if (boot_cpu_data.x86 == 0x17 || boot_cpu_data.x86 == 0x18) {

should check explicitly for Hygon before checking for family 18h.  The
same applies to the edac patch that I've just sent an answer to.

On the other hand, in many cases the AMD code is testing something like
"AMD && family >= 0x0f".  In this case you have a mix of:

- duplicate code for HYGON, such as modern_apic or mce_is_correctable

- change the condition to (AMD || HYGON) && family >= 0x0f, such as
k8_check_syscfg_dram_mod_en and amd_special_default_mtrr

- change the condition to (AMD && family >= 0x0f) || (HYGON && family >=
0x18), such as smp_quirk_init_udelay

I couldn't find any case where you used (AMD && family >= 0x0f) ||
HYGON, but I think it would be clearer in most cases than all the above
three alternatives.

In general, I would duplicate code if and only if the AMD code is a maze
of if/elseif/elseif.  In particular, code like this

case X86_VENDOR_AMD:
if (msr >= MSR_F15H_PERF_CTL)
return (msr - MSR_F15H_PERF_CTL) >> 1;
return msr - MSR_K7_EVNTSEL0;
+   case X86_VENDOR_HYGON:
+   if (msr >= MSR_F15H_PERF_CTL)
+   return (msr - MSR_F15H_PERF_CTL) >> 1;
+   return msr - MSR_K7_EVNTSEL0;

or this

case X86_VENDOR_AMD:
rdmsr_on_cpu(cpu, MSR_K7_HWCR, , );
msr = lo | ((u64)hi << 32);
return !(msr & MSR_K7_HWCR_CPB_DIS);
+   case X86_VENDOR_HYGON:
+   rdmsr_on_cpu(cpu, MSR_K7_HWCR, , );
+   msr = lo | ((u64)hi << 32);
+   return !(msr & MSR_K7_HWCR_CPB_DIS);

looks a bit silly, and you already have several cases when you are not
introducing duplication (e.g. __mcheck_cpu_init_early).  On the other
hand, code like xen_pmu_arch_init can be very simple for Hygon and so it
may be useful to have a separate branch.

Thanks,

Paolo


Re: [PATCH v2 01/17] x86/cpu: create Dhyana init file and register new cpu_dev to system

2018-07-28 Thread Paolo Bonzini
On 28/07/2018 18:48, pu...@hygon.cn wrote:
> Hi Paolo,
> 
> Thanks for your feedback.
> 
> As we described in the patch description, current Hygon Family 18h share
> most architecture with AMD Family 17h. But Hygon Family 18h are not the
> same with AMD family 17h, as it removed some features such as SME/SEV in
> Dhyana.

If the maintainers are okay with X86_FEATURE_HYGON that's certainly
fine, however I think you can improve the consistency of the patches in
a few ways.

Lack of SME/SEV is not an issue, since there are AMD Zen chips without
SME/SEV too, but potential incompatibility with future AMD fam18h chips
is important.  Therefore, code like this one in amd_uncore_init


-   if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
+   if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
+   boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
return -ENODEV;

if (!boot_cpu_has(X86_FEATURE_TOPOEXT))
return -ENODEV;

-   if (boot_cpu_data.x86 == 0x17) {
+   if (boot_cpu_data.x86 == 0x17 || boot_cpu_data.x86 == 0x18) {

should check explicitly for Hygon before checking for family 18h.  The
same applies to the edac patch that I've just sent an answer to.

On the other hand, in many cases the AMD code is testing something like
"AMD && family >= 0x0f".  In this case you have a mix of:

- duplicate code for HYGON, such as modern_apic or mce_is_correctable

- change the condition to (AMD || HYGON) && family >= 0x0f, such as
k8_check_syscfg_dram_mod_en and amd_special_default_mtrr

- change the condition to (AMD && family >= 0x0f) || (HYGON && family >=
0x18), such as smp_quirk_init_udelay

I couldn't find any case where you used (AMD && family >= 0x0f) ||
HYGON, but I think it would be clearer in most cases than all the above
three alternatives.

In general, I would duplicate code if and only if the AMD code is a maze
of if/elseif/elseif.  In particular, code like this

case X86_VENDOR_AMD:
if (msr >= MSR_F15H_PERF_CTL)
return (msr - MSR_F15H_PERF_CTL) >> 1;
return msr - MSR_K7_EVNTSEL0;
+   case X86_VENDOR_HYGON:
+   if (msr >= MSR_F15H_PERF_CTL)
+   return (msr - MSR_F15H_PERF_CTL) >> 1;
+   return msr - MSR_K7_EVNTSEL0;

or this

case X86_VENDOR_AMD:
rdmsr_on_cpu(cpu, MSR_K7_HWCR, , );
msr = lo | ((u64)hi << 32);
return !(msr & MSR_K7_HWCR_CPB_DIS);
+   case X86_VENDOR_HYGON:
+   rdmsr_on_cpu(cpu, MSR_K7_HWCR, , );
+   msr = lo | ((u64)hi << 32);
+   return !(msr & MSR_K7_HWCR_CPB_DIS);

looks a bit silly, and you already have several cases when you are not
introducing duplication (e.g. __mcheck_cpu_init_early).  On the other
hand, code like xen_pmu_arch_init can be very simple for Hygon and so it
may be useful to have a separate branch.

Thanks,

Paolo


[PATCH v2 08/08] staging:rtl8192u: Remove unused constants - Style

2018-07-28 Thread John Whitmore
Remove defined constants from code, since they are never actually
used in code. This is a simple coding style change which should have
no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 17b676b0ed8b..810d81addcf6 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -2,13 +2,6 @@
 #ifndef __INC_QOS_TYPE_H
 #define __INC_QOS_TYPE_H
 
-#defineMAX_WMMELE_LENGTH   64
-
-#define AC_PARAM_SIZE  4
-#define WMM_PARAM_ELE_BODY_LEN 18
-
-#define WMM_PARAM_ELEMENT_SIZE (8 + (4 * AC_PARAM_SIZE))
-
 //
 // ACI/AIFSN Field.
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
-- 
2.18.0



[PATCH v2 07/08] staging:rtl8192u: Rename union QOS_TSINFO - Style

2018-07-28 Thread John Whitmore
The union QOS_TSINFO, as a type, should have a lowercase name. The
union has therefore been renamed to qos_tsinfo. Additionally the
'typedef' directive has been removed to clear the checkpatch issue
with defining new types.

These are coding style changes which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h| 6 +++---
 drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 428a8c4cebf1..17b676b0ed8b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -42,7 +42,7 @@ enum direction_value {
 // 1. WMM spec 2.2.11: WME TSPEC Element, p.18.
 // 2. 8185 QoS code: QOS_TSINFO [def. in QoS_mp.h]
 //
-typedef union _QOS_TSINFO {
+union qos_tsinfo {
u8  charData[3];
struct {
u8  ucTrafficType:1;//WMM 
is reserved
@@ -56,7 +56,7 @@ typedef union _QOS_TSINFO {
u8  ucSchedule:1;   //WMM is 
reserved
u8  ucReserved:7;
} field;
-} QOS_TSINFO, *PQOS_TSINFO;
+};
 
 //
 // WMM TSPEC Body.
@@ -66,7 +66,7 @@ typedef union _TSPEC_BODY {
u8  charData[55];
 
struct {
-   QOS_TSINFO  TSInfo; //u8TSInfo[3];
+   union qos_tsinfoTSInfo; //u8TSInfo[3];
u16 NominalMSDUsize;
u16 MaxMSDUsize;
u32 MinServiceItv;
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 79c96da41d8b..4d92b97a1521 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -355,7 +355,7 @@ bool GetTs(
// For HCCA or WMMSA, TS cannot be addmit without 
negotiation.
//
TSPEC_BODY  TSpec;
-   PQOS_TSINFO pTSInfo = 
+   union qos_tsinfo*pTSInfo = 
struct list_head*pUnusedList =
(TxRxSelect == 
TX_DIR)?

(>Tx_TS_Unused_List):
-- 
2.18.0



[PATCH v2 00/08] staging:rtl8192u: cleanup of rtl819x_Qos.h - Style

2018-07-28 Thread John Whitmore
These are a few coding style changes to the file
drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
I had more patches in the list but had to dump some of the later
patches as I made a mistake. Thought I'd send these 8.

John Whitmore (8):
  staging:rtl8192u: Add spaces around operators - Style
  staging:rtl8192u: Rename ACI_AIFSN - Style
  staging:rtl8192u: Rename member variables - Style
  staging:rtl8192u: Remove unused  union AC_PARAM - Style
  staging:rtl8192u: Remove unused union ECW -Style
  staging:rtl8192u: Rename enum DIRECTION_VALUE - Style
  staging:rtl8192u: Rename union QOS_TSINFO - Style
  staging:rtl8192u: Remove unused constants - Style



[PATCH v2 06/08] staging:rtl8192u: Rename enum DIRECTION_VALUE - Style

2018-07-28 Thread John Whitmore
The enumerated type DIRECTION_VALUE should be named in lowercase to
comply with coding standard so is renamed to direction_value. In
addition the 'typedef' directive has been removed to clear the
checkpatch issue with defining new types.

These changes are coding style changes which should have no impact on
runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h| 4 ++--
 drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 65d7c9f4d840..428a8c4cebf1 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -28,12 +28,12 @@ union aci_aifsn {
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
 //
-typedefenum _DIRECTION_VALUE {
+enum direction_value {
DIR_UP  = 0,// 0x00 // UpLink
DIR_DOWN= 1,// 0x01 // DownLink
DIR_DIRECT  = 2,// 0x10 // DirectLink
DIR_BI_DIR  = 3,// 0x11 // Bi-Direction
-} DIRECTION_VALUE, *PDIRECTION_VALUE;
+};
 
 
 //
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 4b2da7f31166..79c96da41d8b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -366,7 +366,7 @@ bool GetTs(

(>Tx_TS_Admit_List):

(>Rx_TS_Admit_List);
 
-   DIRECTION_VALUE Dir =   (ieee->iw_mode 
== IW_MODE_MASTER)?
+   enum direction_valueDir =   (ieee->iw_mode 
== IW_MODE_MASTER)?

((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):

((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
IEEE80211_DEBUG(IEEE80211_DL_TS, "to add Ts\n");
-- 
2.18.0



[PATCH v2 04/08] staging:rtl8192u: Remove unused union AC_PARAM - Style

2018-07-28 Thread John Whitmore
The union ACM_PARAM is never actually used in code so removed. This
is a coding style change which should have no impact on runtime code
execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 901b85139d3b..43edb830ad5d 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -36,21 +36,6 @@ typedef  union _ECW {
} f;// Field
 } ECW, *PECW;
 
-//
-// AC Parameters Record Format.
-// Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
-//
-typedefunion _AC_PARAM {
-   u32 longData;
-   u8  charData[4];
-
-   struct {
-   union aci_aifsn AciAifsn;
-   ECW Ecw;
-   u16 TXOPLimit;
-   } f;// Field
-} AC_PARAM, *PAC_PARAM;
-
 //
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
-- 
2.18.0



[PATCH v2 00/08] staging:rtl8192u: cleanup of rtl819x_Qos.h - Style

2018-07-28 Thread John Whitmore
These are a few coding style changes to the file
drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
I had more patches in the list but had to dump some of the later
patches as I made a mistake. Thought I'd send these 8.

John Whitmore (8):
  staging:rtl8192u: Add spaces around operators - Style
  staging:rtl8192u: Rename ACI_AIFSN - Style
  staging:rtl8192u: Rename member variables - Style
  staging:rtl8192u: Remove unused  union AC_PARAM - Style
  staging:rtl8192u: Remove unused union ECW -Style
  staging:rtl8192u: Rename enum DIRECTION_VALUE - Style
  staging:rtl8192u: Rename union QOS_TSINFO - Style
  staging:rtl8192u: Remove unused constants - Style



[PATCH v2 06/08] staging:rtl8192u: Rename enum DIRECTION_VALUE - Style

2018-07-28 Thread John Whitmore
The enumerated type DIRECTION_VALUE should be named in lowercase to
comply with coding standard so is renamed to direction_value. In
addition the 'typedef' directive has been removed to clear the
checkpatch issue with defining new types.

These changes are coding style changes which should have no impact on
runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h| 4 ++--
 drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 65d7c9f4d840..428a8c4cebf1 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -28,12 +28,12 @@ union aci_aifsn {
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
 //
-typedefenum _DIRECTION_VALUE {
+enum direction_value {
DIR_UP  = 0,// 0x00 // UpLink
DIR_DOWN= 1,// 0x01 // DownLink
DIR_DIRECT  = 2,// 0x10 // DirectLink
DIR_BI_DIR  = 3,// 0x11 // Bi-Direction
-} DIRECTION_VALUE, *PDIRECTION_VALUE;
+};
 
 
 //
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 4b2da7f31166..79c96da41d8b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -366,7 +366,7 @@ bool GetTs(

(>Tx_TS_Admit_List):

(>Rx_TS_Admit_List);
 
-   DIRECTION_VALUE Dir =   (ieee->iw_mode 
== IW_MODE_MASTER)?
+   enum direction_valueDir =   (ieee->iw_mode 
== IW_MODE_MASTER)?

((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):

((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
IEEE80211_DEBUG(IEEE80211_DL_TS, "to add Ts\n");
-- 
2.18.0



[PATCH v2 04/08] staging:rtl8192u: Remove unused union AC_PARAM - Style

2018-07-28 Thread John Whitmore
The union ACM_PARAM is never actually used in code so removed. This
is a coding style change which should have no impact on runtime code
execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 901b85139d3b..43edb830ad5d 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -36,21 +36,6 @@ typedef  union _ECW {
} f;// Field
 } ECW, *PECW;
 
-//
-// AC Parameters Record Format.
-// Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
-//
-typedefunion _AC_PARAM {
-   u32 longData;
-   u8  charData[4];
-
-   struct {
-   union aci_aifsn AciAifsn;
-   ECW Ecw;
-   u16 TXOPLimit;
-   } f;// Field
-} AC_PARAM, *PAC_PARAM;
-
 //
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
-- 
2.18.0



[PATCH v2 08/08] staging:rtl8192u: Remove unused constants - Style

2018-07-28 Thread John Whitmore
Remove defined constants from code, since they are never actually
used in code. This is a simple coding style change which should have
no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 17b676b0ed8b..810d81addcf6 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -2,13 +2,6 @@
 #ifndef __INC_QOS_TYPE_H
 #define __INC_QOS_TYPE_H
 
-#defineMAX_WMMELE_LENGTH   64
-
-#define AC_PARAM_SIZE  4
-#define WMM_PARAM_ELE_BODY_LEN 18
-
-#define WMM_PARAM_ELEMENT_SIZE (8 + (4 * AC_PARAM_SIZE))
-
 //
 // ACI/AIFSN Field.
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
-- 
2.18.0



[PATCH v2 07/08] staging:rtl8192u: Rename union QOS_TSINFO - Style

2018-07-28 Thread John Whitmore
The union QOS_TSINFO, as a type, should have a lowercase name. The
union has therefore been renamed to qos_tsinfo. Additionally the
'typedef' directive has been removed to clear the checkpatch issue
with defining new types.

These are coding style changes which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h| 6 +++---
 drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 428a8c4cebf1..17b676b0ed8b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -42,7 +42,7 @@ enum direction_value {
 // 1. WMM spec 2.2.11: WME TSPEC Element, p.18.
 // 2. 8185 QoS code: QOS_TSINFO [def. in QoS_mp.h]
 //
-typedef union _QOS_TSINFO {
+union qos_tsinfo {
u8  charData[3];
struct {
u8  ucTrafficType:1;//WMM 
is reserved
@@ -56,7 +56,7 @@ typedef union _QOS_TSINFO {
u8  ucSchedule:1;   //WMM is 
reserved
u8  ucReserved:7;
} field;
-} QOS_TSINFO, *PQOS_TSINFO;
+};
 
 //
 // WMM TSPEC Body.
@@ -66,7 +66,7 @@ typedef union _TSPEC_BODY {
u8  charData[55];
 
struct {
-   QOS_TSINFO  TSInfo; //u8TSInfo[3];
+   union qos_tsinfoTSInfo; //u8TSInfo[3];
u16 NominalMSDUsize;
u16 MaxMSDUsize;
u32 MinServiceItv;
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 79c96da41d8b..4d92b97a1521 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -355,7 +355,7 @@ bool GetTs(
// For HCCA or WMMSA, TS cannot be addmit without 
negotiation.
//
TSPEC_BODY  TSpec;
-   PQOS_TSINFO pTSInfo = 
+   union qos_tsinfo*pTSInfo = 
struct list_head*pUnusedList =
(TxRxSelect == 
TX_DIR)?

(>Tx_TS_Unused_List):
-- 
2.18.0



[PATCH v2 02/08] staging:rtl8192u: Rename ACI_AIFSN - Style

2018-07-28 Thread John Whitmore
Rename the union ACI_AIFSN to aci_aifsn and remove the typedef directive.

The removal of the typedef clears the checkpatch issue with defining
new types. The renaming is to adhere to the coding style where types
are name in lower case.

These changes are coding style changes which should have no impact on
runtime execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 6 +++---
 drivers/staging/rtl8192u/r8192U_dm.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 92afa9dc9663..5856bf87c5dc 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -13,7 +13,7 @@
 // ACI/AIFSN Field.
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
 //
-typedefunion _ACI_AIFSN {
+union aci_aifsn {
u8  charData;
 
struct {
@@ -22,7 +22,7 @@ typedef   union _ACI_AIFSN {
u8  ACI:2;
u8  Reserved:1;
} f;// Field
-} ACI_AIFSN, *PACI_AIFSN;
+};
 
 //
 // ECWmin/ECWmax field.
@@ -45,7 +45,7 @@ typedef   union _AC_PARAM {
u8  charData[4];
 
struct {
-   ACI_AIFSN   AciAifsn;
+   union aci_aifsn AciAifsn;
ECW Ecw;
u16 TXOPLimit;
} f;// Field
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c 
b/drivers/staging/rtl8192u/r8192U_dm.c
index c4e4e3ba394b..04c08ca8a0bb 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2333,7 +2333,7 @@ static void dm_check_edca_turbo(
{
/*  TODO:  Modified this part and try to set 
acm control in only 1 IO processing!! */
 
-   PACI_AIFSN  pAciAifsn = 
(PACI_AIFSN)&(qos_parameters->aifs[0]);
+   union aci_aifsn *pAciAifsn = (union aci_aifsn 
*)&(qos_parameters->aifs[0]);
u8  AcmCtrl;
 
read_nic_byte(dev, AcmHwCtrl, );
-- 
2.18.0



[PATCH v2 02/08] staging:rtl8192u: Rename ACI_AIFSN - Style

2018-07-28 Thread John Whitmore
Rename the union ACI_AIFSN to aci_aifsn and remove the typedef directive.

The removal of the typedef clears the checkpatch issue with defining
new types. The renaming is to adhere to the coding style where types
are name in lower case.

These changes are coding style changes which should have no impact on
runtime execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 6 +++---
 drivers/staging/rtl8192u/r8192U_dm.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 92afa9dc9663..5856bf87c5dc 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -13,7 +13,7 @@
 // ACI/AIFSN Field.
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
 //
-typedefunion _ACI_AIFSN {
+union aci_aifsn {
u8  charData;
 
struct {
@@ -22,7 +22,7 @@ typedef   union _ACI_AIFSN {
u8  ACI:2;
u8  Reserved:1;
} f;// Field
-} ACI_AIFSN, *PACI_AIFSN;
+};
 
 //
 // ECWmin/ECWmax field.
@@ -45,7 +45,7 @@ typedef   union _AC_PARAM {
u8  charData[4];
 
struct {
-   ACI_AIFSN   AciAifsn;
+   union aci_aifsn AciAifsn;
ECW Ecw;
u16 TXOPLimit;
} f;// Field
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c 
b/drivers/staging/rtl8192u/r8192U_dm.c
index c4e4e3ba394b..04c08ca8a0bb 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2333,7 +2333,7 @@ static void dm_check_edca_turbo(
{
/*  TODO:  Modified this part and try to set 
acm control in only 1 IO processing!! */
 
-   PACI_AIFSN  pAciAifsn = 
(PACI_AIFSN)&(qos_parameters->aifs[0]);
+   union aci_aifsn *pAciAifsn = (union aci_aifsn 
*)&(qos_parameters->aifs[0]);
u8  AcmCtrl;
 
read_nic_byte(dev, AcmHwCtrl, );
-- 
2.18.0



[PATCH v2 05/08] staging:rtl8192u: Remove unused union ECW -Style

2018-07-28 Thread John Whitmore
The union ECW is never used in code so has simply been removed.
This is a coding style change which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 12 
 1 file changed, 12 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 43edb830ad5d..65d7c9f4d840 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -24,18 +24,6 @@ union aci_aifsn {
} f;// Field
 };
 
-//
-// ECWmin/ECWmax field.
-// Ref: WMM spec 2.2.2: WME Parameter Element, p.13.
-//
-typedefunion _ECW {
-   u8  charData;
-   struct {
-   u8  ECWmin:4;
-   u8  ECWmax:4;
-   } f;// Field
-} ECW, *PECW;
-
 //
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
-- 
2.18.0



[PATCH v2 03/08] staging:rtl8192u: Rename member variables - Style

2018-07-28 Thread John Whitmore
Rename the member variables of union aci_aifsn, which should be named
in lowercase. The only member variable, of this union, which is
actually used is 'acm'.

This are coding style changes which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 10 +-
 drivers/staging/rtl8192u/r8192U_dm.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 5856bf87c5dc..901b85139d3b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -14,13 +14,13 @@
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
 //
 union aci_aifsn {
-   u8  charData;
+   u8  char_data;
 
struct {
-   u8  AIFSN:4;
-   u8  ACM:1;
-   u8  ACI:2;
-   u8  Reserved:1;
+   u8  aifsn:4;
+   u8  acm:1;
+   u8  aci:2;
+   u8  reserved:1;
} f;// Field
 };
 
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c 
b/drivers/staging/rtl8192u/r8192U_dm.c
index 04c08ca8a0bb..7dc912dd53af 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2338,7 +2338,7 @@ static void dm_check_edca_turbo(
 
read_nic_byte(dev, AcmHwCtrl, );
 
-   if (pAciAifsn->f.ACM) { /*  ACM bit is 1. */
+   if (pAciAifsn->f.acm) { /*  acm bit is 1. */
AcmCtrl |= AcmHw_BeqEn;
} else {/* ACM bit is 0. */
AcmCtrl &= (~AcmHw_BeqEn);
-- 
2.18.0



[PATCH v2 05/08] staging:rtl8192u: Remove unused union ECW -Style

2018-07-28 Thread John Whitmore
The union ECW is never used in code so has simply been removed.
This is a coding style change which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 12 
 1 file changed, 12 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 43edb830ad5d..65d7c9f4d840 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -24,18 +24,6 @@ union aci_aifsn {
} f;// Field
 };
 
-//
-// ECWmin/ECWmax field.
-// Ref: WMM spec 2.2.2: WME Parameter Element, p.13.
-//
-typedefunion _ECW {
-   u8  charData;
-   struct {
-   u8  ECWmin:4;
-   u8  ECWmax:4;
-   } f;// Field
-} ECW, *PECW;
-
 //
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
-- 
2.18.0



[PATCH v2 03/08] staging:rtl8192u: Rename member variables - Style

2018-07-28 Thread John Whitmore
Rename the member variables of union aci_aifsn, which should be named
in lowercase. The only member variable, of this union, which is
actually used is 'acm'.

This are coding style changes which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 10 +-
 drivers/staging/rtl8192u/r8192U_dm.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 5856bf87c5dc..901b85139d3b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -14,13 +14,13 @@
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
 //
 union aci_aifsn {
-   u8  charData;
+   u8  char_data;
 
struct {
-   u8  AIFSN:4;
-   u8  ACM:1;
-   u8  ACI:2;
-   u8  Reserved:1;
+   u8  aifsn:4;
+   u8  acm:1;
+   u8  aci:2;
+   u8  reserved:1;
} f;// Field
 };
 
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c 
b/drivers/staging/rtl8192u/r8192U_dm.c
index 04c08ca8a0bb..7dc912dd53af 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2338,7 +2338,7 @@ static void dm_check_edca_turbo(
 
read_nic_byte(dev, AcmHwCtrl, );
 
-   if (pAciAifsn->f.ACM) { /*  ACM bit is 1. */
+   if (pAciAifsn->f.acm) { /*  acm bit is 1. */
AcmCtrl |= AcmHw_BeqEn;
} else {/* ACM bit is 0. */
AcmCtrl &= (~AcmHw_BeqEn);
-- 
2.18.0



[PATCH v2 01/08] staging:rtl8192u: Add spaces around operators - Style

2018-07-28 Thread John Whitmore
Add the required spaces around '+' and '*' operators. This is a
coding style change to clear the checkpatch issue. There should be
no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 8ee9370520f3..92afa9dc9663 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -7,7 +7,7 @@
 #define AC_PARAM_SIZE  4
 #define WMM_PARAM_ELE_BODY_LEN 18
 
-#define WMM_PARAM_ELEMENT_SIZE (8+(4*AC_PARAM_SIZE))
+#define WMM_PARAM_ELEMENT_SIZE (8 + (4 * AC_PARAM_SIZE))
 
 //
 // ACI/AIFSN Field.
-- 
2.18.0



[PATCH v2 01/08] staging:rtl8192u: Add spaces around operators - Style

2018-07-28 Thread John Whitmore
Add the required spaces around '+' and '*' operators. This is a
coding style change to clear the checkpatch issue. There should be
no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 8ee9370520f3..92afa9dc9663 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -7,7 +7,7 @@
 #define AC_PARAM_SIZE  4
 #define WMM_PARAM_ELE_BODY_LEN 18
 
-#define WMM_PARAM_ELEMENT_SIZE (8+(4*AC_PARAM_SIZE))
+#define WMM_PARAM_ELEMENT_SIZE (8 + (4 * AC_PARAM_SIZE))
 
 //
 // ACI/AIFSN Field.
-- 
2.18.0



[PATCH 05/10] kvm: selftests: add basic test for state save and restore

2018-07-28 Thread Paolo Bonzini
The test calls KVM_RUN repeatedly, and creates an entirely new VM with the
old memory and vCPU state on every exit to userspace.  The kvm_util API is
expanded with two functions that manage the lifetime of a kvm_vm struct:
the first closes the file descriptors and leaves the memory allocated,
and the second opens the file descriptors and reuses the memory from
the previous incarnation of the kvm_vm struct.

For now the test is very basic, as it does not test for example XSAVE or
vCPU events.  However, it will test nested virtualization state starting
with the next patch.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/Makefile   |   1 +
 tools/testing/selftests/kvm/include/kvm_util.h |   2 +
 tools/testing/selftests/kvm/include/x86.h  |   4 +
 tools/testing/selftests/kvm/lib/kvm_util.c |  88 +++
 .../testing/selftests/kvm/lib/kvm_util_internal.h  |   2 +
 tools/testing/selftests/kvm/lib/x86.c  | 122 +
 tools/testing/selftests/kvm/state_test.c   | 119 
 7 files changed, 316 insertions(+), 22 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/state_test.c

diff --git a/tools/testing/selftests/kvm/Makefile 
b/tools/testing/selftests/kvm/Makefile
index 65bda4fb0ad6..dd0e5163f01f 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -10,6 +10,7 @@ TEST_GEN_PROGS_x86_64 = set_sregs_test
 TEST_GEN_PROGS_x86_64 += sync_regs_test
 TEST_GEN_PROGS_x86_64 += vmx_tsc_adjust_test
 TEST_GEN_PROGS_x86_64 += cr4_cpuid_sync_test
+TEST_GEN_PROGS_x86_64 += state_test
 
 TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M))
 LIBKVM += $(LIBKVM_$(UNAME_M))
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h 
b/tools/testing/selftests/kvm/include/kvm_util.h
index 87e05664c7f9..d32632f71ab8 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -53,6 +53,8 @@ enum vm_mem_backing_src_type {
 
 struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int 
perm);
 void kvm_vm_free(struct kvm_vm *vmp);
+void kvm_vm_restart(struct kvm_vm *vmp, int perm);
+void kvm_vm_release(struct kvm_vm *vmp);
 
 int kvm_memcmp_hva_gva(void *hva,
struct kvm_vm *vm, const vm_vaddr_t gva, size_t len);
diff --git a/tools/testing/selftests/kvm/include/x86.h 
b/tools/testing/selftests/kvm/include/x86.h
index d8788ddb0210..2559f6d2d683 100644
--- a/tools/testing/selftests/kvm/include/x86.h
+++ b/tools/testing/selftests/kvm/include/x86.h
@@ -310,6 +310,10 @@ static inline unsigned long get_xmm(int n)
return 0;
 }
 
+struct kvm_x86_state;
+struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, uint32_t vcpuid);
+void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state 
*state);
+
 /*
  * Basic CPU control in CR0
  */
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
b/tools/testing/selftests/kvm/lib/kvm_util.c
index 163482873363..643309d6de74 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -62,6 +62,18 @@ int kvm_check_cap(long cap)
return ret;
 }
 
+static void vm_open(struct kvm_vm *vm, int perm)
+{
+   vm->kvm_fd = open(KVM_DEV_PATH, perm);
+   if (vm->kvm_fd < 0)
+   exit(KSFT_SKIP);
+
+   /* Create VM. */
+   vm->fd = ioctl(vm->kvm_fd, KVM_CREATE_VM, NULL);
+   TEST_ASSERT(vm->fd >= 0, "KVM_CREATE_VM ioctl failed, "
+   "rc: %i errno: %i", vm->fd, errno);
+}
+
 /* VM Create
  *
  * Input Args:
@@ -90,16 +102,7 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t 
phy_pages, int perm)
TEST_ASSERT(vm != NULL, "Insufficent Memory");
 
vm->mode = mode;
-   kvm_fd = open(KVM_DEV_PATH, perm);
-   if (kvm_fd < 0)
-   exit(KSFT_SKIP);
-
-   /* Create VM. */
-   vm->fd = ioctl(kvm_fd, KVM_CREATE_VM, NULL);
-   TEST_ASSERT(vm->fd >= 0, "KVM_CREATE_VM ioctl failed, "
-   "rc: %i errno: %i", vm->fd, errno);
-
-   close(kvm_fd);
+   vm_open(vm, perm);
 
/* Setup mode specific traits. */
switch (vm->mode) {
@@ -132,6 +135,39 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t 
phy_pages, int perm)
return vm;
 }
 
+/* VM Restart
+ *
+ * Input Args:
+ *   vm - VM that has been released before
+ *   perm - permission
+ *
+ * Output Args: None
+ *
+ * Reopens the file descriptors associated to the VM and reinstates the
+ * global state, such as the irqchip and the memory regions that are mapped
+ * into the guest.
+ */
+void kvm_vm_restart(struct kvm_vm *vmp, int perm)
+{
+   struct userspace_mem_region *region;
+
+   vm_open(vmp, perm);
+   if (vmp->has_irqchip)
+   vm_create_irqchip(vmp);
+
+   for (region = vmp->userspace_mem_region_head; region;
+   region = region->next) {
+   int ret = ioctl(vmp->fd, 

[PATCH 05/10] kvm: selftests: add basic test for state save and restore

2018-07-28 Thread Paolo Bonzini
The test calls KVM_RUN repeatedly, and creates an entirely new VM with the
old memory and vCPU state on every exit to userspace.  The kvm_util API is
expanded with two functions that manage the lifetime of a kvm_vm struct:
the first closes the file descriptors and leaves the memory allocated,
and the second opens the file descriptors and reuses the memory from
the previous incarnation of the kvm_vm struct.

For now the test is very basic, as it does not test for example XSAVE or
vCPU events.  However, it will test nested virtualization state starting
with the next patch.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/Makefile   |   1 +
 tools/testing/selftests/kvm/include/kvm_util.h |   2 +
 tools/testing/selftests/kvm/include/x86.h  |   4 +
 tools/testing/selftests/kvm/lib/kvm_util.c |  88 +++
 .../testing/selftests/kvm/lib/kvm_util_internal.h  |   2 +
 tools/testing/selftests/kvm/lib/x86.c  | 122 +
 tools/testing/selftests/kvm/state_test.c   | 119 
 7 files changed, 316 insertions(+), 22 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/state_test.c

diff --git a/tools/testing/selftests/kvm/Makefile 
b/tools/testing/selftests/kvm/Makefile
index 65bda4fb0ad6..dd0e5163f01f 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -10,6 +10,7 @@ TEST_GEN_PROGS_x86_64 = set_sregs_test
 TEST_GEN_PROGS_x86_64 += sync_regs_test
 TEST_GEN_PROGS_x86_64 += vmx_tsc_adjust_test
 TEST_GEN_PROGS_x86_64 += cr4_cpuid_sync_test
+TEST_GEN_PROGS_x86_64 += state_test
 
 TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M))
 LIBKVM += $(LIBKVM_$(UNAME_M))
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h 
b/tools/testing/selftests/kvm/include/kvm_util.h
index 87e05664c7f9..d32632f71ab8 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -53,6 +53,8 @@ enum vm_mem_backing_src_type {
 
 struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int 
perm);
 void kvm_vm_free(struct kvm_vm *vmp);
+void kvm_vm_restart(struct kvm_vm *vmp, int perm);
+void kvm_vm_release(struct kvm_vm *vmp);
 
 int kvm_memcmp_hva_gva(void *hva,
struct kvm_vm *vm, const vm_vaddr_t gva, size_t len);
diff --git a/tools/testing/selftests/kvm/include/x86.h 
b/tools/testing/selftests/kvm/include/x86.h
index d8788ddb0210..2559f6d2d683 100644
--- a/tools/testing/selftests/kvm/include/x86.h
+++ b/tools/testing/selftests/kvm/include/x86.h
@@ -310,6 +310,10 @@ static inline unsigned long get_xmm(int n)
return 0;
 }
 
+struct kvm_x86_state;
+struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, uint32_t vcpuid);
+void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state 
*state);
+
 /*
  * Basic CPU control in CR0
  */
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
b/tools/testing/selftests/kvm/lib/kvm_util.c
index 163482873363..643309d6de74 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -62,6 +62,18 @@ int kvm_check_cap(long cap)
return ret;
 }
 
+static void vm_open(struct kvm_vm *vm, int perm)
+{
+   vm->kvm_fd = open(KVM_DEV_PATH, perm);
+   if (vm->kvm_fd < 0)
+   exit(KSFT_SKIP);
+
+   /* Create VM. */
+   vm->fd = ioctl(vm->kvm_fd, KVM_CREATE_VM, NULL);
+   TEST_ASSERT(vm->fd >= 0, "KVM_CREATE_VM ioctl failed, "
+   "rc: %i errno: %i", vm->fd, errno);
+}
+
 /* VM Create
  *
  * Input Args:
@@ -90,16 +102,7 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t 
phy_pages, int perm)
TEST_ASSERT(vm != NULL, "Insufficent Memory");
 
vm->mode = mode;
-   kvm_fd = open(KVM_DEV_PATH, perm);
-   if (kvm_fd < 0)
-   exit(KSFT_SKIP);
-
-   /* Create VM. */
-   vm->fd = ioctl(kvm_fd, KVM_CREATE_VM, NULL);
-   TEST_ASSERT(vm->fd >= 0, "KVM_CREATE_VM ioctl failed, "
-   "rc: %i errno: %i", vm->fd, errno);
-
-   close(kvm_fd);
+   vm_open(vm, perm);
 
/* Setup mode specific traits. */
switch (vm->mode) {
@@ -132,6 +135,39 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t 
phy_pages, int perm)
return vm;
 }
 
+/* VM Restart
+ *
+ * Input Args:
+ *   vm - VM that has been released before
+ *   perm - permission
+ *
+ * Output Args: None
+ *
+ * Reopens the file descriptors associated to the VM and reinstates the
+ * global state, such as the irqchip and the memory regions that are mapped
+ * into the guest.
+ */
+void kvm_vm_restart(struct kvm_vm *vmp, int perm)
+{
+   struct userspace_mem_region *region;
+
+   vm_open(vmp, perm);
+   if (vmp->has_irqchip)
+   vm_create_irqchip(vmp);
+
+   for (region = vmp->userspace_mem_region_head; region;
+   region = region->next) {
+   int ret = ioctl(vmp->fd, 

[PATCH 04/10] kvm: selftests: ensure vcpu file is released

2018-07-28 Thread Paolo Bonzini
The selftests were not munmap-ing the kvm_run area from the vcpu file 
descriptor.
The result was that kvm_vcpu_release was not called and a reference was left in 
the
parent "struct kvm".  Ultimately this was visible in the upcoming state 
save/restore
test as an error when KVM attempted to create a duplicate debugfs entry.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/lib/kvm_util.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
b/tools/testing/selftests/kvm/lib/kvm_util.c
index 610d1326f03d..163482873363 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -238,8 +238,12 @@ struct vcpu *vcpu_find(struct kvm_vm *vm,
 static void vm_vcpu_rm(struct kvm_vm *vm, uint32_t vcpuid)
 {
struct vcpu *vcpu = vcpu_find(vm, vcpuid);
+   int ret;
 
-   int ret = close(vcpu->fd);
+   ret = munmap(vcpu->state, sizeof(*vcpu->state));
+   TEST_ASSERT(ret == 0, "munmap of VCPU fd failed, rc: %i "
+   "errno: %i", ret, errno);
+   close(vcpu->fd);
TEST_ASSERT(ret == 0, "Close of VCPU fd failed, rc: %i "
"errno: %i", ret, errno);
 
@@ -295,6 +299,10 @@ void kvm_vm_free(struct kvm_vm *vmp)
TEST_ASSERT(ret == 0, "Close of vm fd failed,\n"
"  vmp->fd: %i rc: %i errno: %i", vmp->fd, ret, errno);
 
+   close(vmp->kvm_fd);
+   TEST_ASSERT(ret == 0, "Close of /dev/kvm fd failed,\n"
+   "  vmp->kvm_fd: %i rc: %i errno: %i", vmp->kvm_fd, ret, errno);
+
/* Free the structure describing the VM. */
free(vmp);
 }
-- 
1.8.3.1



[PATCH 03/10] kvm: selftests: actually use all of lib/vmx.c

2018-07-28 Thread Paolo Bonzini
The allocation of the VMXON and VMCS is currently done twice, in
lib/vmx.c and in vmx_tsc_adjust_test.c.  Reorganize the code to
provide a cleaner and easier to use API to the tests.  lib/vmx.c
now does the complete setup of the VMX data structures, but does not
create the VM or set CPUID.  This has to be done by the caller.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/cr4_cpuid_sync_test.c |  2 +-
 tools/testing/selftests/kvm/include/vmx.h | 21 +--
 tools/testing/selftests/kvm/lib/vmx.c | 71 ++-
 tools/testing/selftests/kvm/vmx_tsc_adjust_test.c | 69 +-
 4 files changed, 73 insertions(+), 90 deletions(-)

diff --git a/tools/testing/selftests/kvm/cr4_cpuid_sync_test.c 
b/tools/testing/selftests/kvm/cr4_cpuid_sync_test.c
index dbbaf3c3fbfe..8346b33c2073 100644
--- a/tools/testing/selftests/kvm/cr4_cpuid_sync_test.c
+++ b/tools/testing/selftests/kvm/cr4_cpuid_sync_test.c
@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
setbuf(stdout, NULL);
 
/* Create VM */
-   vm = vm_create_default_vmx(VCPU_ID, guest_code);
+   vm = vm_create_default(VCPU_ID, guest_code);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
run = vcpu_state(vm, VCPU_ID);
 
diff --git a/tools/testing/selftests/kvm/include/vmx.h 
b/tools/testing/selftests/kvm/include/vmx.h
index 6ed8499807fd..9caaf56696a4 100644
--- a/tools/testing/selftests/kvm/include/vmx.h
+++ b/tools/testing/selftests/kvm/include/vmx.h
@@ -486,9 +486,22 @@ static inline uint32_t vmcs_revision(void)
return rdmsr(MSR_IA32_VMX_BASIC);
 }
 
-void prepare_for_vmx_operation(void);
-void prepare_vmcs(void *guest_rip, void *guest_rsp);
-struct kvm_vm *vm_create_default_vmx(uint32_t vcpuid,
-vmx_guest_code_t guest_code);
+struct vmx_pages {
+   void *vmxon_hva;
+   uint64_t vmxon_gpa;
+   void *vmxon;
+
+   void *vmcs_hva;
+   uint64_t vmcs_gpa;
+   void *vmcs;
+
+   void *msr_hva;
+   uint64_t msr_gpa;
+   void *msr;
+};
+
+struct vmx_pages *vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva);
+bool prepare_for_vmx_operation(struct vmx_pages *vmx);
+void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp);
 
 #endif /* !SELFTEST_KVM_VMX_H */
diff --git a/tools/testing/selftests/kvm/lib/vmx.c 
b/tools/testing/selftests/kvm/lib/vmx.c
index 0231bc0aae7b..5701e52a33ed 100644
--- a/tools/testing/selftests/kvm/lib/vmx.c
+++ b/tools/testing/selftests/kvm/lib/vmx.c
@@ -13,47 +13,43 @@
 #include "x86.h"
 #include "vmx.h"
 
-/* Create a default VM for VMX tests.
+/* Allocate memory regions for nested VMX tests.
  *
  * Input Args:
- *   vcpuid - The id of the single VCPU to add to the VM.
- *   guest_code - The vCPU's entry point
+ *   vm - The VM to allocate guest-virtual addresses in.
  *
- * Output Args: None
+ * Output Args:
+ *   p_vmx_gva - The guest virtual address for the struct vmx_pages.
  *
  * Return:
- *   Pointer to opaque structure that describes the created VM.
+ *   Pointer to structure with the addresses of the VMX areas.
  */
-struct kvm_vm *
-vm_create_default_vmx(uint32_t vcpuid, vmx_guest_code_t guest_code)
+struct vmx_pages *
+vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva)
 {
-   struct kvm_cpuid2 *cpuid;
-   struct kvm_vm *vm;
-   vm_vaddr_t vmxon_vaddr;
-   vm_paddr_t vmxon_paddr;
-   vm_vaddr_t vmcs_vaddr;
-   vm_paddr_t vmcs_paddr;
-
-   vm = vm_create_default(vcpuid, (void *) guest_code);
-
-   /* Enable nesting in CPUID */
-   vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid());
+   vm_vaddr_t vmx_gva = vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   struct vmx_pages *vmx = addr_gva2hva(vm, vmx_gva);
 
/* Setup of a region of guest memory for the vmxon region. */
-   vmxon_vaddr = vm_vaddr_alloc(vm, getpagesize(), 0, 0, 0);
-   vmxon_paddr = addr_gva2gpa(vm, vmxon_vaddr);
+   vmx->vmxon = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->vmxon_hva = addr_gva2hva(vm, (uintptr_t)vmx->vmxon);
+   vmx->vmxon_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->vmxon);
 
/* Setup of a region of guest memory for a vmcs. */
-   vmcs_vaddr = vm_vaddr_alloc(vm, getpagesize(), 0, 0, 0);
-   vmcs_paddr = addr_gva2gpa(vm, vmcs_vaddr);
+   vmx->vmcs = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->vmcs_hva = addr_gva2hva(vm, (uintptr_t)vmx->vmcs);
+   vmx->vmcs_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->vmcs);
 
-   vcpu_args_set(vm, vcpuid, 4, vmxon_vaddr, vmxon_paddr, vmcs_vaddr,
- vmcs_paddr);
+   /* Setup of a region of guest memory for the MSR bitmap. */
+   vmx->msr = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->msr_hva = addr_gva2hva(vm, (uintptr_t)vmx->msr);
+   vmx->msr_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->msr);
 
-   return vm;
+ 

[PATCH 04/10] kvm: selftests: ensure vcpu file is released

2018-07-28 Thread Paolo Bonzini
The selftests were not munmap-ing the kvm_run area from the vcpu file 
descriptor.
The result was that kvm_vcpu_release was not called and a reference was left in 
the
parent "struct kvm".  Ultimately this was visible in the upcoming state 
save/restore
test as an error when KVM attempted to create a duplicate debugfs entry.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/lib/kvm_util.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
b/tools/testing/selftests/kvm/lib/kvm_util.c
index 610d1326f03d..163482873363 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -238,8 +238,12 @@ struct vcpu *vcpu_find(struct kvm_vm *vm,
 static void vm_vcpu_rm(struct kvm_vm *vm, uint32_t vcpuid)
 {
struct vcpu *vcpu = vcpu_find(vm, vcpuid);
+   int ret;
 
-   int ret = close(vcpu->fd);
+   ret = munmap(vcpu->state, sizeof(*vcpu->state));
+   TEST_ASSERT(ret == 0, "munmap of VCPU fd failed, rc: %i "
+   "errno: %i", ret, errno);
+   close(vcpu->fd);
TEST_ASSERT(ret == 0, "Close of VCPU fd failed, rc: %i "
"errno: %i", ret, errno);
 
@@ -295,6 +299,10 @@ void kvm_vm_free(struct kvm_vm *vmp)
TEST_ASSERT(ret == 0, "Close of vm fd failed,\n"
"  vmp->fd: %i rc: %i errno: %i", vmp->fd, ret, errno);
 
+   close(vmp->kvm_fd);
+   TEST_ASSERT(ret == 0, "Close of /dev/kvm fd failed,\n"
+   "  vmp->kvm_fd: %i rc: %i errno: %i", vmp->kvm_fd, ret, errno);
+
/* Free the structure describing the VM. */
free(vmp);
 }
-- 
1.8.3.1



[PATCH 03/10] kvm: selftests: actually use all of lib/vmx.c

2018-07-28 Thread Paolo Bonzini
The allocation of the VMXON and VMCS is currently done twice, in
lib/vmx.c and in vmx_tsc_adjust_test.c.  Reorganize the code to
provide a cleaner and easier to use API to the tests.  lib/vmx.c
now does the complete setup of the VMX data structures, but does not
create the VM or set CPUID.  This has to be done by the caller.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/cr4_cpuid_sync_test.c |  2 +-
 tools/testing/selftests/kvm/include/vmx.h | 21 +--
 tools/testing/selftests/kvm/lib/vmx.c | 71 ++-
 tools/testing/selftests/kvm/vmx_tsc_adjust_test.c | 69 +-
 4 files changed, 73 insertions(+), 90 deletions(-)

diff --git a/tools/testing/selftests/kvm/cr4_cpuid_sync_test.c 
b/tools/testing/selftests/kvm/cr4_cpuid_sync_test.c
index dbbaf3c3fbfe..8346b33c2073 100644
--- a/tools/testing/selftests/kvm/cr4_cpuid_sync_test.c
+++ b/tools/testing/selftests/kvm/cr4_cpuid_sync_test.c
@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
setbuf(stdout, NULL);
 
/* Create VM */
-   vm = vm_create_default_vmx(VCPU_ID, guest_code);
+   vm = vm_create_default(VCPU_ID, guest_code);
vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
run = vcpu_state(vm, VCPU_ID);
 
diff --git a/tools/testing/selftests/kvm/include/vmx.h 
b/tools/testing/selftests/kvm/include/vmx.h
index 6ed8499807fd..9caaf56696a4 100644
--- a/tools/testing/selftests/kvm/include/vmx.h
+++ b/tools/testing/selftests/kvm/include/vmx.h
@@ -486,9 +486,22 @@ static inline uint32_t vmcs_revision(void)
return rdmsr(MSR_IA32_VMX_BASIC);
 }
 
-void prepare_for_vmx_operation(void);
-void prepare_vmcs(void *guest_rip, void *guest_rsp);
-struct kvm_vm *vm_create_default_vmx(uint32_t vcpuid,
-vmx_guest_code_t guest_code);
+struct vmx_pages {
+   void *vmxon_hva;
+   uint64_t vmxon_gpa;
+   void *vmxon;
+
+   void *vmcs_hva;
+   uint64_t vmcs_gpa;
+   void *vmcs;
+
+   void *msr_hva;
+   uint64_t msr_gpa;
+   void *msr;
+};
+
+struct vmx_pages *vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva);
+bool prepare_for_vmx_operation(struct vmx_pages *vmx);
+void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp);
 
 #endif /* !SELFTEST_KVM_VMX_H */
diff --git a/tools/testing/selftests/kvm/lib/vmx.c 
b/tools/testing/selftests/kvm/lib/vmx.c
index 0231bc0aae7b..5701e52a33ed 100644
--- a/tools/testing/selftests/kvm/lib/vmx.c
+++ b/tools/testing/selftests/kvm/lib/vmx.c
@@ -13,47 +13,43 @@
 #include "x86.h"
 #include "vmx.h"
 
-/* Create a default VM for VMX tests.
+/* Allocate memory regions for nested VMX tests.
  *
  * Input Args:
- *   vcpuid - The id of the single VCPU to add to the VM.
- *   guest_code - The vCPU's entry point
+ *   vm - The VM to allocate guest-virtual addresses in.
  *
- * Output Args: None
+ * Output Args:
+ *   p_vmx_gva - The guest virtual address for the struct vmx_pages.
  *
  * Return:
- *   Pointer to opaque structure that describes the created VM.
+ *   Pointer to structure with the addresses of the VMX areas.
  */
-struct kvm_vm *
-vm_create_default_vmx(uint32_t vcpuid, vmx_guest_code_t guest_code)
+struct vmx_pages *
+vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva)
 {
-   struct kvm_cpuid2 *cpuid;
-   struct kvm_vm *vm;
-   vm_vaddr_t vmxon_vaddr;
-   vm_paddr_t vmxon_paddr;
-   vm_vaddr_t vmcs_vaddr;
-   vm_paddr_t vmcs_paddr;
-
-   vm = vm_create_default(vcpuid, (void *) guest_code);
-
-   /* Enable nesting in CPUID */
-   vcpu_set_cpuid(vm, vcpuid, kvm_get_supported_cpuid());
+   vm_vaddr_t vmx_gva = vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   struct vmx_pages *vmx = addr_gva2hva(vm, vmx_gva);
 
/* Setup of a region of guest memory for the vmxon region. */
-   vmxon_vaddr = vm_vaddr_alloc(vm, getpagesize(), 0, 0, 0);
-   vmxon_paddr = addr_gva2gpa(vm, vmxon_vaddr);
+   vmx->vmxon = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->vmxon_hva = addr_gva2hva(vm, (uintptr_t)vmx->vmxon);
+   vmx->vmxon_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->vmxon);
 
/* Setup of a region of guest memory for a vmcs. */
-   vmcs_vaddr = vm_vaddr_alloc(vm, getpagesize(), 0, 0, 0);
-   vmcs_paddr = addr_gva2gpa(vm, vmcs_vaddr);
+   vmx->vmcs = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->vmcs_hva = addr_gva2hva(vm, (uintptr_t)vmx->vmcs);
+   vmx->vmcs_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->vmcs);
 
-   vcpu_args_set(vm, vcpuid, 4, vmxon_vaddr, vmxon_paddr, vmcs_vaddr,
- vmcs_paddr);
+   /* Setup of a region of guest memory for the MSR bitmap. */
+   vmx->msr = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->msr_hva = addr_gva2hva(vm, (uintptr_t)vmx->msr);
+   vmx->msr_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->msr);
 
-   return vm;
+ 

[PATCH 06/10] KVM: x86: do not load vmcs12 pages while still in SMM

2018-07-28 Thread Paolo Bonzini
If the vCPU enters system management mode while running a nested guest,
RSM starts processing the vmentry while still in SMM.  In that case,
however, the pages pointed to by the vmcs12 might be incorrectly
loaded from SMRAM.  To avoid this, delay the handling of the pages
until just before the next vmentry.  This is done with a new request
and a new entry in kvm_x86_ops, which we will be able to reuse for
nested VMX state migration.

Extracted from a patch by Jim Mattson and KarimAllah Ahmed.

Signed-off-by: Paolo Bonzini 
---
 arch/x86/include/asm/kvm_host.h |  3 +++
 arch/x86/kvm/vmx.c  | 53 +++--
 arch/x86/kvm/x86.c  |  2 ++
 3 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index c13cd28d9d1b..da957725992d 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -75,6 +75,7 @@
 #define KVM_REQ_HV_EXITKVM_ARCH_REQ(21)
 #define KVM_REQ_HV_STIMER  KVM_ARCH_REQ(22)
 #define KVM_REQ_LOAD_EOI_EXITMAP   KVM_ARCH_REQ(23)
+#define KVM_REQ_GET_VMCS12_PAGES   KVM_ARCH_REQ(24)
 
 #define CR0_RESERVED_BITS   \
(~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \
@@ -1085,6 +1086,8 @@ struct kvm_x86_ops {
 
void (*setup_mce)(struct kvm_vcpu *vcpu);
 
+   void (*get_vmcs12_pages)(struct kvm_vcpu *vcpu);
+
int (*smi_allowed)(struct kvm_vcpu *vcpu);
int (*pre_enter_smm)(struct kvm_vcpu *vcpu, char *smstate);
int (*pre_leave_smm)(struct kvm_vcpu *vcpu, u64 smbase);
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 2630ab38d72c..17aede06ae0e 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -10636,9 +10636,9 @@ static void vmx_inject_page_fault_nested(struct 
kvm_vcpu *vcpu,
 static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
 struct vmcs12 *vmcs12);
 
-static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu,
-   struct vmcs12 *vmcs12)
+static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
 {
+   struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct page *page;
u64 hpa;
@@ -11750,13 +11750,18 @@ static int check_vmentry_postreqs(struct kvm_vcpu 
*vcpu, struct vmcs12 *vmcs12,
return 0;
 }
 
-static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu)
+/*
+ * If p_exit_qual is NULL, this is being called from state restore (either
+ * kvm_set_nested_state or RSM).  Otherwise it's called from vmlaunch/vmresume.
+ */
+static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, u32 *p_exit_qual)
 {
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
+   bool from_vmentry = !!p_exit_qual;
u32 msr_entry_idx;
-   u32 exit_qual;
-   int r;
+   u32 dummy_exit_qual;
+   int r = 0;
 
enter_guest_mode(vcpu);
 
@@ -11770,17 +11775,27 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu 
*vcpu)
vcpu->arch.tsc_offset += vmcs12->tsc_offset;
 
r = EXIT_REASON_INVALID_STATE;
-   if (prepare_vmcs02(vcpu, vmcs12, _qual))
+   if (prepare_vmcs02(vcpu, vmcs12, from_vmentry ? p_exit_qual : 
_exit_qual))
goto fail;
 
-   nested_get_vmcs12_pages(vcpu, vmcs12);
+   if (from_vmentry) {
+   nested_get_vmcs12_pages(vcpu);
 
-   r = EXIT_REASON_MSR_LOAD_FAIL;
-   msr_entry_idx = nested_vmx_load_msr(vcpu,
-   vmcs12->vm_entry_msr_load_addr,
-   vmcs12->vm_entry_msr_load_count);
-   if (msr_entry_idx)
-   goto fail;
+   r = EXIT_REASON_MSR_LOAD_FAIL;
+   msr_entry_idx = nested_vmx_load_msr(vcpu,
+   
vmcs12->vm_entry_msr_load_addr,
+   
vmcs12->vm_entry_msr_load_count);
+   if (msr_entry_idx)
+   goto fail;
+   } else {
+   /*
+* The MMU is not initialized to point at the right entities 
yet and
+* "get pages" would need to read data from the guest (i.e. we 
will
+* need to perform gpa to hpa translation). Request a call
+* to nested_get_vmcs12_pages before the next VM-entry.
+*/
+   kvm_make_request(KVM_REQ_GET_VMCS12_PAGES, vcpu);
+   }
 
/*
 * Note no nested_vmx_succeed or nested_vmx_fail here. At this point
@@ -11795,8 +11810,7 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu 
*vcpu)
vcpu->arch.tsc_offset -= vmcs12->tsc_offset;
leave_guest_mode(vcpu);
vmx_switch_vmcs(vcpu, >vmcs01);
- 

[PATCH 02/10] kvm: selftests: create a GDT and TSS

2018-07-28 Thread Paolo Bonzini
The GDT and the TSS base were left to zero, and this has interesting effects
when the TSS descriptor is later read to set up a VMCS's TR_BASE.  Basically
it worked by chance, and this patch fixes it by setting up all the protected
mode data structures properly.

Because the GDT and TSS addresses are virtual, the page tables now always
exist at the time of vcpu setup.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/include/kvm_util.h |   2 +-
 tools/testing/selftests/kvm/include/x86.h  |  11 +-
 tools/testing/selftests/kvm/lib/kvm_util.c |   4 +-
 .../testing/selftests/kvm/lib/kvm_util_internal.h  |   5 +-
 tools/testing/selftests/kvm/lib/x86.c  | 111 +
 5 files changed, 86 insertions(+), 47 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/kvm_util.h 
b/tools/testing/selftests/kvm/include/kvm_util.h
index 637b7017b6ee..87e05664c7f9 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -75,7 +75,7 @@ void vcpu_ioctl(struct kvm_vm *vm,
uint32_t vcpuid, unsigned long ioctl, void *arg);
 void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);
 void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags);
-void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid);
+void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot, int 
gdt_memslot);
 vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
uint32_t data_memslot, uint32_t pgd_memslot);
 void *addr_gpa2hva(struct kvm_vm *vm, vm_paddr_t gpa);
diff --git a/tools/testing/selftests/kvm/include/x86.h 
b/tools/testing/selftests/kvm/include/x86.h
index 4a5b2c4c1a0f..d8788ddb0210 100644
--- a/tools/testing/selftests/kvm/include/x86.h
+++ b/tools/testing/selftests/kvm/include/x86.h
@@ -56,8 +56,8 @@ enum x86_register {
 struct desc64 {
uint16_t limit0;
uint16_t base0;
-   unsigned base1:8, type:5, dpl:2, p:1;
-   unsigned limit1:4, zero0:3, g:1, base2:8;
+   unsigned base1:8, s:1, type:4, dpl:2, p:1;
+   unsigned limit1:4, avl:1, l:1, db:1, g:1, base2:8;
uint32_t base3;
uint32_t zero1;
 } __attribute__((packed));
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
b/tools/testing/selftests/kvm/lib/kvm_util.c
index 37e2a787d2fc..610d1326f03d 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -701,7 +701,7 @@ static int vcpu_mmap_sz(void)
  * Creates and adds to the VM specified by vm and virtual CPU with
  * the ID given by vcpuid.
  */
-void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid)
+void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot, int 
gdt_memslot)
 {
struct vcpu *vcpu;
 
@@ -736,7 +736,7 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid)
vcpu->next = vm->vcpu_head;
vm->vcpu_head = vcpu;
 
-   vcpu_setup(vm, vcpuid);
+   vcpu_setup(vm, vcpuid, pgd_memslot, gdt_memslot);
 }
 
 /* VM Virtual Address Unused Gap
diff --git a/tools/testing/selftests/kvm/lib/kvm_util_internal.h 
b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
index a0bd1980c81c..cbb40288890a 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util_internal.h
+++ b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
@@ -51,13 +51,16 @@ struct kvm_vm {
struct userspace_mem_region *userspace_mem_region_head;
struct sparsebit *vpages_valid;
struct sparsebit *vpages_mapped;
+
bool pgd_created;
vm_paddr_t pgd;
+   vm_vaddr_t gdt;
+   vm_vaddr_t tss;
 };
 
 struct vcpu *vcpu_find(struct kvm_vm *vm,
uint32_t vcpuid);
-void vcpu_setup(struct kvm_vm *vm, int vcpuid);
+void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int 
gdt_memslot);
 void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
 void regs_dump(FILE *stream, struct kvm_regs *regs,
uint8_t indent);
diff --git a/tools/testing/selftests/kvm/lib/x86.c 
b/tools/testing/selftests/kvm/lib/x86.c
index 2f17675f4275..024e95f1b470 100644
--- a/tools/testing/selftests/kvm/lib/x86.c
+++ b/tools/testing/selftests/kvm/lib/x86.c
@@ -239,25 +239,6 @@ void virt_pgd_alloc(struct kvm_vm *vm, uint32_t 
pgd_memslot)
vm_paddr_t paddr = vm_phy_page_alloc(vm,
KVM_GUEST_PAGE_TABLE_MIN_PADDR, pgd_memslot);
vm->pgd = paddr;
-
-   /* Set pointer to pgd tables in all the VCPUs that
-* have already been created.  Future VCPUs will have
-* the value set as each one is created.
-*/
-   for (struct vcpu *vcpu = vm->vcpu_head; vcpu;
-   vcpu = vcpu->next) {
-   struct kvm_sregs sregs;
-
-   /* Obtain the current system register settings */
-   vcpu_sregs_get(vm, vcpu->id, );
-
-   /* Set 

[PATCH 09/10] KVM: nVMX: include shadow vmcs12 in nested state

2018-07-28 Thread Paolo Bonzini
The shadow vmcs12 cannot be flushed on KVM_GET_NESTED_STATE,
because at that point guest memory is assumed by userspace to
be immutable.  Capture the cache in vmx_get_nested_state, adding
another page at the end if there is an active shadow vmcs12.

Signed-off-by: Paolo Bonzini 
---
 arch/x86/kvm/vmx.c | 31 ++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b5ee9e08bb48..ce8c0c759a19 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -13167,9 +13167,15 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu,
kvm_state.vmx.vmxon_pa = vmx->nested.vmxon_ptr;
kvm_state.vmx.vmcs_pa = vmx->nested.current_vmptr;
 
-   if (vmx->nested.current_vmptr != -1ull)
+   if (vmx->nested.current_vmptr != -1ull) {
kvm_state.size += VMCS12_SIZE;
 
+   if (is_guest_mode(vcpu) &&
+   nested_cpu_has_shadow_vmcs(vmcs12) &&
+   vmcs12->vmcs_link_pointer != -1ull)
+   kvm_state.size += VMCS12_SIZE;
+   }
+
if (vmx->nested.smm.vmxon)
kvm_state.vmx.smm.flags |= KVM_STATE_NESTED_SMM_VMXON;
 
@@ -13208,6 +13214,13 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu,
if (copy_to_user(user_kvm_nested_state->data, vmcs12, sizeof(*vmcs12)))
return -EFAULT;
 
+   if (nested_cpu_has_shadow_vmcs(vmcs12) &&
+   vmcs12->vmcs_link_pointer != -1ull) {
+   if (copy_to_user(user_kvm_nested_state->data + VMCS12_SIZE,
+get_shadow_vmcs12(vcpu), sizeof(*vmcs12)))
+   return -EFAULT;
+   }
+
 out:
return kvm_state.size;
 }
@@ -13288,6 +13301,22 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
vmx->nested.nested_run_pending =
!!(kvm_state->flags & KVM_STATE_NESTED_RUN_PENDING);
 
+   if (nested_cpu_has_shadow_vmcs(vmcs12) &&
+   vmcs12->vmcs_link_pointer != -1ull) {
+   struct vmcs12 *shadow_vmcs12 = get_shadow_vmcs12(vcpu);
+   if (kvm_state->size < sizeof(kvm_state) + 2 * sizeof(*vmcs12))
+   return -EINVAL;
+
+   if (copy_from_user(shadow_vmcs12,
+  user_kvm_nested_state->data + VMCS12_SIZE,
+  sizeof(*vmcs12)))
+   return -EFAULT;
+
+   if (shadow_vmcs12->hdr.revision_id != VMCS12_REVISION ||
+   !shadow_vmcs12->hdr.shadow_vmcs)
+   return -EINVAL;
+   }
+
if (check_vmentry_prereqs(vcpu, vmcs12) ||
check_vmentry_postreqs(vcpu, vmcs12, _qual))
return -EINVAL;
-- 
1.8.3.1



[PATCH 07/10] kvm: nVMX: Introduce KVM_CAP_NESTED_STATE

2018-07-28 Thread Paolo Bonzini
From: Jim Mattson 

For nested virtualization L0 KVM is managing a bit of state for L2 guests,
this state can not be captured through the currently available IOCTLs. In
fact the state captured through all of these IOCTLs is usually a mix of L1
and L2 state. It is also dependent on whether the L2 guest was running at
the moment when the process was interrupted to save its state.

With this capability, there are two new vcpu ioctls: KVM_GET_NESTED_STATE
and KVM_SET_NESTED_STATE. These can be used for saving and restoring a VM
that is in VMX operation.

Signed-off-by: Jim Mattson 
[karahmed@ - rename structs and functions and make them ready for AMD and
 address previous comments.
   - handle nested.smm state.
   - rebase & a bit of refactoring.
   - Merge 7/8 and 8/8 into one patch. ]
Signed-off-by: KarimAllah Ahmed 
Signed-off-by: Paolo Bonzini 
---
 Documentation/virtual/kvm/api.txt |  52 
 arch/x86/include/asm/kvm_host.h   |   6 ++
 arch/x86/include/uapi/asm/kvm.h   |  37 +
 arch/x86/kvm/vmx.c| 167 ++
 arch/x86/kvm/x86.c|  54 
 include/uapi/linux/kvm.h  |   4 +
 6 files changed, 320 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index d10944e619d3..84504566c4ff 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -3561,6 +3561,62 @@ Returns: 0 on success,
-ENOENT on deassign if the conn_id isn't registered
-EEXIST on assign if the conn_id is already registered
 
+4.114 KVM_GET_NESTED_STATE
+
+Capability: KVM_CAP_NESTED_STATE
+Architectures: x86
+Type: vcpu ioctl
+Parameters: struct kvm_nested_state (in/out)
+Returns: 0 on success, -1 on error
+Errors:
+  E2BIG: the total state size (including the fixed-size part of struct
+ kvm_nested_state) exceeds the value of 'size' specified by
+ the user; the size required will be written into size.
+
+struct kvm_nested_state {
+   __u16 flags;
+   __u16 format;
+   __u32 size;
+   union {
+   struct kvm_vmx_nested_state vmx;
+   struct kvm_svm_nested_state svm;
+   __u8 pad[120];
+   };
+   __u8 data[0];
+};
+
+#define KVM_STATE_NESTED_GUEST_MODE0x0001
+#define KVM_STATE_NESTED_RUN_PENDING   0x0002
+
+#define KVM_STATE_NESTED_SMM_GUEST_MODE0x0001
+#define KVM_STATE_NESTED_SMM_VMXON 0x0002
+
+struct kvm_vmx_nested_state {
+   __u64 vmxon_pa;
+   __u64 vmcs_pa;
+
+   struct {
+   __u16 flags;
+   } smm;
+};
+
+This ioctl copies the vcpu's nested virtualization state from the kernel to
+userspace.
+
+The maximum size of the state, including the fixed-size part of struct
+kvm_nested_state, can be retrieved by passing KVM_CAP_NESTED_STATE to
+the KVM_CHECK_EXTENSION ioctl().
+
+4.115 KVM_SET_NESTED_STATE
+
+Capability: KVM_CAP_NESTED_STATE
+Architectures: x86
+Type: vcpu ioctl
+Parameters: struct kvm_nested_state (in)
+Returns: 0 on success, -1 on error
+
+This copies the vcpu's kvm_nested_state struct from userspace to the kernel.  
For
+the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE.
 
 5. The kvm_run structure
 
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index da957725992d..bd287b348751 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1086,6 +1086,12 @@ struct kvm_x86_ops {
 
void (*setup_mce)(struct kvm_vcpu *vcpu);
 
+   int (*get_nested_state)(struct kvm_vcpu *vcpu,
+   struct kvm_nested_state __user 
*user_kvm_nested_state,
+   unsigned user_data_size);
+   int (*set_nested_state)(struct kvm_vcpu *vcpu,
+   struct kvm_nested_state __user 
*user_kvm_nested_state,
+   struct kvm_nested_state *kvm_state);
void (*get_vmcs12_pages)(struct kvm_vcpu *vcpu);
 
int (*smi_allowed)(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
index c535c2fdea13..86299efa804a 100644
--- a/arch/x86/include/uapi/asm/kvm.h
+++ b/arch/x86/include/uapi/asm/kvm.h
@@ -378,4 +378,41 @@ struct kvm_sync_regs {
 #define KVM_X86_QUIRK_LINT0_REENABLED  (1 << 0)
 #define KVM_X86_QUIRK_CD_NW_CLEARED(1 << 1)
 
+#define KVM_STATE_NESTED_GUEST_MODE0x0001
+#define KVM_STATE_NESTED_RUN_PENDING   0x0002
+
+#define KVM_STATE_NESTED_SMM_GUEST_MODE0x0001
+#define KVM_STATE_NESTED_SMM_VMXON 0x0002
+
+struct kvm_vmx_nested_state {
+   __u64 vmxon_pa;
+   __u64 vmcs_pa;
+
+   struct {
+   __u16 flags;
+   } smm;
+};
+
+/* for KVM_CAP_NESTED_STATE */
+struct kvm_nested_state {
+   /* KVM_STATE_* flags */
+   __u16 flags;
+
+   /* 0 for VMX, 

[PATCH 06/10] KVM: x86: do not load vmcs12 pages while still in SMM

2018-07-28 Thread Paolo Bonzini
If the vCPU enters system management mode while running a nested guest,
RSM starts processing the vmentry while still in SMM.  In that case,
however, the pages pointed to by the vmcs12 might be incorrectly
loaded from SMRAM.  To avoid this, delay the handling of the pages
until just before the next vmentry.  This is done with a new request
and a new entry in kvm_x86_ops, which we will be able to reuse for
nested VMX state migration.

Extracted from a patch by Jim Mattson and KarimAllah Ahmed.

Signed-off-by: Paolo Bonzini 
---
 arch/x86/include/asm/kvm_host.h |  3 +++
 arch/x86/kvm/vmx.c  | 53 +++--
 arch/x86/kvm/x86.c  |  2 ++
 3 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index c13cd28d9d1b..da957725992d 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -75,6 +75,7 @@
 #define KVM_REQ_HV_EXITKVM_ARCH_REQ(21)
 #define KVM_REQ_HV_STIMER  KVM_ARCH_REQ(22)
 #define KVM_REQ_LOAD_EOI_EXITMAP   KVM_ARCH_REQ(23)
+#define KVM_REQ_GET_VMCS12_PAGES   KVM_ARCH_REQ(24)
 
 #define CR0_RESERVED_BITS   \
(~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \
@@ -1085,6 +1086,8 @@ struct kvm_x86_ops {
 
void (*setup_mce)(struct kvm_vcpu *vcpu);
 
+   void (*get_vmcs12_pages)(struct kvm_vcpu *vcpu);
+
int (*smi_allowed)(struct kvm_vcpu *vcpu);
int (*pre_enter_smm)(struct kvm_vcpu *vcpu, char *smstate);
int (*pre_leave_smm)(struct kvm_vcpu *vcpu, u64 smbase);
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 2630ab38d72c..17aede06ae0e 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -10636,9 +10636,9 @@ static void vmx_inject_page_fault_nested(struct 
kvm_vcpu *vcpu,
 static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
 struct vmcs12 *vmcs12);
 
-static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu,
-   struct vmcs12 *vmcs12)
+static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
 {
+   struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct page *page;
u64 hpa;
@@ -11750,13 +11750,18 @@ static int check_vmentry_postreqs(struct kvm_vcpu 
*vcpu, struct vmcs12 *vmcs12,
return 0;
 }
 
-static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu)
+/*
+ * If p_exit_qual is NULL, this is being called from state restore (either
+ * kvm_set_nested_state or RSM).  Otherwise it's called from vmlaunch/vmresume.
+ */
+static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, u32 *p_exit_qual)
 {
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
+   bool from_vmentry = !!p_exit_qual;
u32 msr_entry_idx;
-   u32 exit_qual;
-   int r;
+   u32 dummy_exit_qual;
+   int r = 0;
 
enter_guest_mode(vcpu);
 
@@ -11770,17 +11775,27 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu 
*vcpu)
vcpu->arch.tsc_offset += vmcs12->tsc_offset;
 
r = EXIT_REASON_INVALID_STATE;
-   if (prepare_vmcs02(vcpu, vmcs12, _qual))
+   if (prepare_vmcs02(vcpu, vmcs12, from_vmentry ? p_exit_qual : 
_exit_qual))
goto fail;
 
-   nested_get_vmcs12_pages(vcpu, vmcs12);
+   if (from_vmentry) {
+   nested_get_vmcs12_pages(vcpu);
 
-   r = EXIT_REASON_MSR_LOAD_FAIL;
-   msr_entry_idx = nested_vmx_load_msr(vcpu,
-   vmcs12->vm_entry_msr_load_addr,
-   vmcs12->vm_entry_msr_load_count);
-   if (msr_entry_idx)
-   goto fail;
+   r = EXIT_REASON_MSR_LOAD_FAIL;
+   msr_entry_idx = nested_vmx_load_msr(vcpu,
+   
vmcs12->vm_entry_msr_load_addr,
+   
vmcs12->vm_entry_msr_load_count);
+   if (msr_entry_idx)
+   goto fail;
+   } else {
+   /*
+* The MMU is not initialized to point at the right entities 
yet and
+* "get pages" would need to read data from the guest (i.e. we 
will
+* need to perform gpa to hpa translation). Request a call
+* to nested_get_vmcs12_pages before the next VM-entry.
+*/
+   kvm_make_request(KVM_REQ_GET_VMCS12_PAGES, vcpu);
+   }
 
/*
 * Note no nested_vmx_succeed or nested_vmx_fail here. At this point
@@ -11795,8 +11810,7 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu 
*vcpu)
vcpu->arch.tsc_offset -= vmcs12->tsc_offset;
leave_guest_mode(vcpu);
vmx_switch_vmcs(vcpu, >vmcs01);
- 

[PATCH 02/10] kvm: selftests: create a GDT and TSS

2018-07-28 Thread Paolo Bonzini
The GDT and the TSS base were left to zero, and this has interesting effects
when the TSS descriptor is later read to set up a VMCS's TR_BASE.  Basically
it worked by chance, and this patch fixes it by setting up all the protected
mode data structures properly.

Because the GDT and TSS addresses are virtual, the page tables now always
exist at the time of vcpu setup.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/include/kvm_util.h |   2 +-
 tools/testing/selftests/kvm/include/x86.h  |  11 +-
 tools/testing/selftests/kvm/lib/kvm_util.c |   4 +-
 .../testing/selftests/kvm/lib/kvm_util_internal.h  |   5 +-
 tools/testing/selftests/kvm/lib/x86.c  | 111 +
 5 files changed, 86 insertions(+), 47 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/kvm_util.h 
b/tools/testing/selftests/kvm/include/kvm_util.h
index 637b7017b6ee..87e05664c7f9 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -75,7 +75,7 @@ void vcpu_ioctl(struct kvm_vm *vm,
uint32_t vcpuid, unsigned long ioctl, void *arg);
 void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg);
 void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags);
-void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid);
+void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot, int 
gdt_memslot);
 vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
uint32_t data_memslot, uint32_t pgd_memslot);
 void *addr_gpa2hva(struct kvm_vm *vm, vm_paddr_t gpa);
diff --git a/tools/testing/selftests/kvm/include/x86.h 
b/tools/testing/selftests/kvm/include/x86.h
index 4a5b2c4c1a0f..d8788ddb0210 100644
--- a/tools/testing/selftests/kvm/include/x86.h
+++ b/tools/testing/selftests/kvm/include/x86.h
@@ -56,8 +56,8 @@ enum x86_register {
 struct desc64 {
uint16_t limit0;
uint16_t base0;
-   unsigned base1:8, type:5, dpl:2, p:1;
-   unsigned limit1:4, zero0:3, g:1, base2:8;
+   unsigned base1:8, s:1, type:4, dpl:2, p:1;
+   unsigned limit1:4, avl:1, l:1, db:1, g:1, base2:8;
uint32_t base3;
uint32_t zero1;
 } __attribute__((packed));
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
b/tools/testing/selftests/kvm/lib/kvm_util.c
index 37e2a787d2fc..610d1326f03d 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -701,7 +701,7 @@ static int vcpu_mmap_sz(void)
  * Creates and adds to the VM specified by vm and virtual CPU with
  * the ID given by vcpuid.
  */
-void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid)
+void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid, int pgd_memslot, int 
gdt_memslot)
 {
struct vcpu *vcpu;
 
@@ -736,7 +736,7 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid)
vcpu->next = vm->vcpu_head;
vm->vcpu_head = vcpu;
 
-   vcpu_setup(vm, vcpuid);
+   vcpu_setup(vm, vcpuid, pgd_memslot, gdt_memslot);
 }
 
 /* VM Virtual Address Unused Gap
diff --git a/tools/testing/selftests/kvm/lib/kvm_util_internal.h 
b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
index a0bd1980c81c..cbb40288890a 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util_internal.h
+++ b/tools/testing/selftests/kvm/lib/kvm_util_internal.h
@@ -51,13 +51,16 @@ struct kvm_vm {
struct userspace_mem_region *userspace_mem_region_head;
struct sparsebit *vpages_valid;
struct sparsebit *vpages_mapped;
+
bool pgd_created;
vm_paddr_t pgd;
+   vm_vaddr_t gdt;
+   vm_vaddr_t tss;
 };
 
 struct vcpu *vcpu_find(struct kvm_vm *vm,
uint32_t vcpuid);
-void vcpu_setup(struct kvm_vm *vm, int vcpuid);
+void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int 
gdt_memslot);
 void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent);
 void regs_dump(FILE *stream, struct kvm_regs *regs,
uint8_t indent);
diff --git a/tools/testing/selftests/kvm/lib/x86.c 
b/tools/testing/selftests/kvm/lib/x86.c
index 2f17675f4275..024e95f1b470 100644
--- a/tools/testing/selftests/kvm/lib/x86.c
+++ b/tools/testing/selftests/kvm/lib/x86.c
@@ -239,25 +239,6 @@ void virt_pgd_alloc(struct kvm_vm *vm, uint32_t 
pgd_memslot)
vm_paddr_t paddr = vm_phy_page_alloc(vm,
KVM_GUEST_PAGE_TABLE_MIN_PADDR, pgd_memslot);
vm->pgd = paddr;
-
-   /* Set pointer to pgd tables in all the VCPUs that
-* have already been created.  Future VCPUs will have
-* the value set as each one is created.
-*/
-   for (struct vcpu *vcpu = vm->vcpu_head; vcpu;
-   vcpu = vcpu->next) {
-   struct kvm_sregs sregs;
-
-   /* Obtain the current system register settings */
-   vcpu_sregs_get(vm, vcpu->id, );
-
-   /* Set 

[PATCH 09/10] KVM: nVMX: include shadow vmcs12 in nested state

2018-07-28 Thread Paolo Bonzini
The shadow vmcs12 cannot be flushed on KVM_GET_NESTED_STATE,
because at that point guest memory is assumed by userspace to
be immutable.  Capture the cache in vmx_get_nested_state, adding
another page at the end if there is an active shadow vmcs12.

Signed-off-by: Paolo Bonzini 
---
 arch/x86/kvm/vmx.c | 31 ++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b5ee9e08bb48..ce8c0c759a19 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -13167,9 +13167,15 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu,
kvm_state.vmx.vmxon_pa = vmx->nested.vmxon_ptr;
kvm_state.vmx.vmcs_pa = vmx->nested.current_vmptr;
 
-   if (vmx->nested.current_vmptr != -1ull)
+   if (vmx->nested.current_vmptr != -1ull) {
kvm_state.size += VMCS12_SIZE;
 
+   if (is_guest_mode(vcpu) &&
+   nested_cpu_has_shadow_vmcs(vmcs12) &&
+   vmcs12->vmcs_link_pointer != -1ull)
+   kvm_state.size += VMCS12_SIZE;
+   }
+
if (vmx->nested.smm.vmxon)
kvm_state.vmx.smm.flags |= KVM_STATE_NESTED_SMM_VMXON;
 
@@ -13208,6 +13214,13 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu,
if (copy_to_user(user_kvm_nested_state->data, vmcs12, sizeof(*vmcs12)))
return -EFAULT;
 
+   if (nested_cpu_has_shadow_vmcs(vmcs12) &&
+   vmcs12->vmcs_link_pointer != -1ull) {
+   if (copy_to_user(user_kvm_nested_state->data + VMCS12_SIZE,
+get_shadow_vmcs12(vcpu), sizeof(*vmcs12)))
+   return -EFAULT;
+   }
+
 out:
return kvm_state.size;
 }
@@ -13288,6 +13301,22 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
vmx->nested.nested_run_pending =
!!(kvm_state->flags & KVM_STATE_NESTED_RUN_PENDING);
 
+   if (nested_cpu_has_shadow_vmcs(vmcs12) &&
+   vmcs12->vmcs_link_pointer != -1ull) {
+   struct vmcs12 *shadow_vmcs12 = get_shadow_vmcs12(vcpu);
+   if (kvm_state->size < sizeof(kvm_state) + 2 * sizeof(*vmcs12))
+   return -EINVAL;
+
+   if (copy_from_user(shadow_vmcs12,
+  user_kvm_nested_state->data + VMCS12_SIZE,
+  sizeof(*vmcs12)))
+   return -EFAULT;
+
+   if (shadow_vmcs12->hdr.revision_id != VMCS12_REVISION ||
+   !shadow_vmcs12->hdr.shadow_vmcs)
+   return -EINVAL;
+   }
+
if (check_vmentry_prereqs(vcpu, vmcs12) ||
check_vmentry_postreqs(vcpu, vmcs12, _qual))
return -EINVAL;
-- 
1.8.3.1



[PATCH 07/10] kvm: nVMX: Introduce KVM_CAP_NESTED_STATE

2018-07-28 Thread Paolo Bonzini
From: Jim Mattson 

For nested virtualization L0 KVM is managing a bit of state for L2 guests,
this state can not be captured through the currently available IOCTLs. In
fact the state captured through all of these IOCTLs is usually a mix of L1
and L2 state. It is also dependent on whether the L2 guest was running at
the moment when the process was interrupted to save its state.

With this capability, there are two new vcpu ioctls: KVM_GET_NESTED_STATE
and KVM_SET_NESTED_STATE. These can be used for saving and restoring a VM
that is in VMX operation.

Signed-off-by: Jim Mattson 
[karahmed@ - rename structs and functions and make them ready for AMD and
 address previous comments.
   - handle nested.smm state.
   - rebase & a bit of refactoring.
   - Merge 7/8 and 8/8 into one patch. ]
Signed-off-by: KarimAllah Ahmed 
Signed-off-by: Paolo Bonzini 
---
 Documentation/virtual/kvm/api.txt |  52 
 arch/x86/include/asm/kvm_host.h   |   6 ++
 arch/x86/include/uapi/asm/kvm.h   |  37 +
 arch/x86/kvm/vmx.c| 167 ++
 arch/x86/kvm/x86.c|  54 
 include/uapi/linux/kvm.h  |   4 +
 6 files changed, 320 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index d10944e619d3..84504566c4ff 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -3561,6 +3561,62 @@ Returns: 0 on success,
-ENOENT on deassign if the conn_id isn't registered
-EEXIST on assign if the conn_id is already registered
 
+4.114 KVM_GET_NESTED_STATE
+
+Capability: KVM_CAP_NESTED_STATE
+Architectures: x86
+Type: vcpu ioctl
+Parameters: struct kvm_nested_state (in/out)
+Returns: 0 on success, -1 on error
+Errors:
+  E2BIG: the total state size (including the fixed-size part of struct
+ kvm_nested_state) exceeds the value of 'size' specified by
+ the user; the size required will be written into size.
+
+struct kvm_nested_state {
+   __u16 flags;
+   __u16 format;
+   __u32 size;
+   union {
+   struct kvm_vmx_nested_state vmx;
+   struct kvm_svm_nested_state svm;
+   __u8 pad[120];
+   };
+   __u8 data[0];
+};
+
+#define KVM_STATE_NESTED_GUEST_MODE0x0001
+#define KVM_STATE_NESTED_RUN_PENDING   0x0002
+
+#define KVM_STATE_NESTED_SMM_GUEST_MODE0x0001
+#define KVM_STATE_NESTED_SMM_VMXON 0x0002
+
+struct kvm_vmx_nested_state {
+   __u64 vmxon_pa;
+   __u64 vmcs_pa;
+
+   struct {
+   __u16 flags;
+   } smm;
+};
+
+This ioctl copies the vcpu's nested virtualization state from the kernel to
+userspace.
+
+The maximum size of the state, including the fixed-size part of struct
+kvm_nested_state, can be retrieved by passing KVM_CAP_NESTED_STATE to
+the KVM_CHECK_EXTENSION ioctl().
+
+4.115 KVM_SET_NESTED_STATE
+
+Capability: KVM_CAP_NESTED_STATE
+Architectures: x86
+Type: vcpu ioctl
+Parameters: struct kvm_nested_state (in)
+Returns: 0 on success, -1 on error
+
+This copies the vcpu's kvm_nested_state struct from userspace to the kernel.  
For
+the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE.
 
 5. The kvm_run structure
 
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index da957725992d..bd287b348751 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1086,6 +1086,12 @@ struct kvm_x86_ops {
 
void (*setup_mce)(struct kvm_vcpu *vcpu);
 
+   int (*get_nested_state)(struct kvm_vcpu *vcpu,
+   struct kvm_nested_state __user 
*user_kvm_nested_state,
+   unsigned user_data_size);
+   int (*set_nested_state)(struct kvm_vcpu *vcpu,
+   struct kvm_nested_state __user 
*user_kvm_nested_state,
+   struct kvm_nested_state *kvm_state);
void (*get_vmcs12_pages)(struct kvm_vcpu *vcpu);
 
int (*smi_allowed)(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
index c535c2fdea13..86299efa804a 100644
--- a/arch/x86/include/uapi/asm/kvm.h
+++ b/arch/x86/include/uapi/asm/kvm.h
@@ -378,4 +378,41 @@ struct kvm_sync_regs {
 #define KVM_X86_QUIRK_LINT0_REENABLED  (1 << 0)
 #define KVM_X86_QUIRK_CD_NW_CLEARED(1 << 1)
 
+#define KVM_STATE_NESTED_GUEST_MODE0x0001
+#define KVM_STATE_NESTED_RUN_PENDING   0x0002
+
+#define KVM_STATE_NESTED_SMM_GUEST_MODE0x0001
+#define KVM_STATE_NESTED_SMM_VMXON 0x0002
+
+struct kvm_vmx_nested_state {
+   __u64 vmxon_pa;
+   __u64 vmcs_pa;
+
+   struct {
+   __u16 flags;
+   } smm;
+};
+
+/* for KVM_CAP_NESTED_STATE */
+struct kvm_nested_state {
+   /* KVM_STATE_* flags */
+   __u16 flags;
+
+   /* 0 for VMX, 

[PATCH 10/10] KVM: selftests: add tests for shadow VMCS save/restore

2018-07-28 Thread Paolo Bonzini
This includes setting up the shadow VMCS and the secondary execution
controls in lib/vmx.c.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/include/vmx.h | 12 +++
 tools/testing/selftests/kvm/lib/vmx.c | 33 +++---
 tools/testing/selftests/kvm/state_test.c  | 34 +--
 3 files changed, 74 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/vmx.h 
b/tools/testing/selftests/kvm/include/vmx.h
index 2b37f9b6f7df..02cdecf9560c 100644
--- a/tools/testing/selftests/kvm/include/vmx.h
+++ b/tools/testing/selftests/kvm/include/vmx.h
@@ -530,6 +530,18 @@ struct vmx_pages {
void *msr_hva;
uint64_t msr_gpa;
void *msr;
+
+   void *shadow_vmcs_hva;
+   uint64_t shadow_vmcs_gpa;
+   void *shadow_vmcs;
+
+   void *vmread_hva;
+   uint64_t vmread_gpa;
+   void *vmread;
+
+   void *vmwrite_hva;
+   uint64_t vmwrite_gpa;
+   void *vmwrite;
 };
 
 struct vmx_pages *vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva);
diff --git a/tools/testing/selftests/kvm/lib/vmx.c 
b/tools/testing/selftests/kvm/lib/vmx.c
index 5701e52a33ed..b987c3c970eb 100644
--- a/tools/testing/selftests/kvm/lib/vmx.c
+++ b/tools/testing/selftests/kvm/lib/vmx.c
@@ -44,6 +44,23 @@ struct vmx_pages *
vmx->msr = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
vmx->msr_hva = addr_gva2hva(vm, (uintptr_t)vmx->msr);
vmx->msr_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->msr);
+   memset(vmx->msr_hva, 0, getpagesize());
+
+   /* Setup of a region of guest memory for the shadow VMCS. */
+   vmx->shadow_vmcs = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 
0, 0);
+   vmx->shadow_vmcs_hva = addr_gva2hva(vm, (uintptr_t)vmx->shadow_vmcs);
+   vmx->shadow_vmcs_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->shadow_vmcs);
+
+   /* Setup of a region of guest memory for the VMREAD and VMWRITE 
bitmaps. */
+   vmx->vmread = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->vmread_hva = addr_gva2hva(vm, (uintptr_t)vmx->vmread);
+   vmx->vmread_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->vmread);
+   memset(vmx->vmread_hva, 0, getpagesize());
+
+   vmx->vmwrite = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->vmwrite_hva = addr_gva2hva(vm, (uintptr_t)vmx->vmwrite);
+   vmx->vmwrite_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->vmwrite);
+   memset(vmx->vmwrite_hva, 0, getpagesize());
 
*p_vmx_gva = vmx_gva;
return vmx;
@@ -98,6 +115,11 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx)
if (vmptrld(vmx->vmcs_gpa))
return false;
 
+   /* Setup shadow VMCS, do not load it yet. */
+   *(uint32_t *)(vmx->shadow_vmcs) = vmcs_revision() | 0x8000ul;
+   if (vmclear(vmx->shadow_vmcs_gpa))
+   return false;
+
return true;
 }
 
@@ -109,8 +131,12 @@ static inline void init_vmcs_control_fields(struct 
vmx_pages *vmx)
vmwrite(VIRTUAL_PROCESSOR_ID, 0);
vmwrite(POSTED_INTR_NV, 0);
 
-   vmwrite(PIN_BASED_VM_EXEC_CONTROL, rdmsr(MSR_IA32_VMX_PINBASED_CTLS));
-   vmwrite(CPU_BASED_VM_EXEC_CONTROL, rdmsr(MSR_IA32_VMX_PROCBASED_CTLS));
+   vmwrite(PIN_BASED_VM_EXEC_CONTROL, 
rdmsr(MSR_IA32_VMX_TRUE_PINBASED_CTLS));
+   if (!vmwrite(SECONDARY_VM_EXEC_CONTROL, 0))
+   vmwrite(CPU_BASED_VM_EXEC_CONTROL,
+   rdmsr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS) | 
CPU_BASED_ACTIVATE_SECONDARY_CONTROLS);
+   else
+   vmwrite(CPU_BASED_VM_EXEC_CONTROL, 
rdmsr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS));
vmwrite(EXCEPTION_BITMAP, 0);
vmwrite(PAGE_FAULT_ERROR_CODE_MASK, 0);
vmwrite(PAGE_FAULT_ERROR_CODE_MATCH, -1); /* Never match */
@@ -124,7 +150,6 @@ static inline void init_vmcs_control_fields(struct 
vmx_pages *vmx)
vmwrite(VM_ENTRY_MSR_LOAD_COUNT, 0);
vmwrite(VM_ENTRY_INTR_INFO_FIELD, 0);
vmwrite(TPR_THRESHOLD, 0);
-   vmwrite(SECONDARY_VM_EXEC_CONTROL, 0);
 
vmwrite(CR0_GUEST_HOST_MASK, 0);
vmwrite(CR4_GUEST_HOST_MASK, 0);
@@ -132,6 +157,8 @@ static inline void init_vmcs_control_fields(struct 
vmx_pages *vmx)
vmwrite(CR4_READ_SHADOW, get_cr4());
 
vmwrite(MSR_BITMAP, vmx->msr_gpa);
+   vmwrite(VMREAD_BITMAP, vmx->vmread_gpa);
+   vmwrite(VMWRITE_BITMAP, vmx->vmwrite_gpa);
 }
 
 /*
diff --git a/tools/testing/selftests/kvm/state_test.c 
b/tools/testing/selftests/kvm/state_test.c
index 447da4f76b56..833319b06577 100644
--- a/tools/testing/selftests/kvm/state_test.c
+++ b/tools/testing/selftests/kvm/state_test.c
@@ -55,7 +55,15 @@ void l2_guest_code(void)
 /* Exit to L1 */
vmcall();
 
-   GUEST_SYNC(7);
+   /* L1 has now set up a shadow VMCS for us.  */
+   GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffee);
+   GUEST_SYNC(9);
+   GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffee);

[PATCH 10/10] KVM: selftests: add tests for shadow VMCS save/restore

2018-07-28 Thread Paolo Bonzini
This includes setting up the shadow VMCS and the secondary execution
controls in lib/vmx.c.

Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/include/vmx.h | 12 +++
 tools/testing/selftests/kvm/lib/vmx.c | 33 +++---
 tools/testing/selftests/kvm/state_test.c  | 34 +--
 3 files changed, 74 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/vmx.h 
b/tools/testing/selftests/kvm/include/vmx.h
index 2b37f9b6f7df..02cdecf9560c 100644
--- a/tools/testing/selftests/kvm/include/vmx.h
+++ b/tools/testing/selftests/kvm/include/vmx.h
@@ -530,6 +530,18 @@ struct vmx_pages {
void *msr_hva;
uint64_t msr_gpa;
void *msr;
+
+   void *shadow_vmcs_hva;
+   uint64_t shadow_vmcs_gpa;
+   void *shadow_vmcs;
+
+   void *vmread_hva;
+   uint64_t vmread_gpa;
+   void *vmread;
+
+   void *vmwrite_hva;
+   uint64_t vmwrite_gpa;
+   void *vmwrite;
 };
 
 struct vmx_pages *vcpu_alloc_vmx(struct kvm_vm *vm, vm_vaddr_t *p_vmx_gva);
diff --git a/tools/testing/selftests/kvm/lib/vmx.c 
b/tools/testing/selftests/kvm/lib/vmx.c
index 5701e52a33ed..b987c3c970eb 100644
--- a/tools/testing/selftests/kvm/lib/vmx.c
+++ b/tools/testing/selftests/kvm/lib/vmx.c
@@ -44,6 +44,23 @@ struct vmx_pages *
vmx->msr = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
vmx->msr_hva = addr_gva2hva(vm, (uintptr_t)vmx->msr);
vmx->msr_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->msr);
+   memset(vmx->msr_hva, 0, getpagesize());
+
+   /* Setup of a region of guest memory for the shadow VMCS. */
+   vmx->shadow_vmcs = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 
0, 0);
+   vmx->shadow_vmcs_hva = addr_gva2hva(vm, (uintptr_t)vmx->shadow_vmcs);
+   vmx->shadow_vmcs_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->shadow_vmcs);
+
+   /* Setup of a region of guest memory for the VMREAD and VMWRITE 
bitmaps. */
+   vmx->vmread = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->vmread_hva = addr_gva2hva(vm, (uintptr_t)vmx->vmread);
+   vmx->vmread_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->vmread);
+   memset(vmx->vmread_hva, 0, getpagesize());
+
+   vmx->vmwrite = (void *)vm_vaddr_alloc(vm, getpagesize(), 0x1, 0, 0);
+   vmx->vmwrite_hva = addr_gva2hva(vm, (uintptr_t)vmx->vmwrite);
+   vmx->vmwrite_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->vmwrite);
+   memset(vmx->vmwrite_hva, 0, getpagesize());
 
*p_vmx_gva = vmx_gva;
return vmx;
@@ -98,6 +115,11 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx)
if (vmptrld(vmx->vmcs_gpa))
return false;
 
+   /* Setup shadow VMCS, do not load it yet. */
+   *(uint32_t *)(vmx->shadow_vmcs) = vmcs_revision() | 0x8000ul;
+   if (vmclear(vmx->shadow_vmcs_gpa))
+   return false;
+
return true;
 }
 
@@ -109,8 +131,12 @@ static inline void init_vmcs_control_fields(struct 
vmx_pages *vmx)
vmwrite(VIRTUAL_PROCESSOR_ID, 0);
vmwrite(POSTED_INTR_NV, 0);
 
-   vmwrite(PIN_BASED_VM_EXEC_CONTROL, rdmsr(MSR_IA32_VMX_PINBASED_CTLS));
-   vmwrite(CPU_BASED_VM_EXEC_CONTROL, rdmsr(MSR_IA32_VMX_PROCBASED_CTLS));
+   vmwrite(PIN_BASED_VM_EXEC_CONTROL, 
rdmsr(MSR_IA32_VMX_TRUE_PINBASED_CTLS));
+   if (!vmwrite(SECONDARY_VM_EXEC_CONTROL, 0))
+   vmwrite(CPU_BASED_VM_EXEC_CONTROL,
+   rdmsr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS) | 
CPU_BASED_ACTIVATE_SECONDARY_CONTROLS);
+   else
+   vmwrite(CPU_BASED_VM_EXEC_CONTROL, 
rdmsr(MSR_IA32_VMX_TRUE_PROCBASED_CTLS));
vmwrite(EXCEPTION_BITMAP, 0);
vmwrite(PAGE_FAULT_ERROR_CODE_MASK, 0);
vmwrite(PAGE_FAULT_ERROR_CODE_MATCH, -1); /* Never match */
@@ -124,7 +150,6 @@ static inline void init_vmcs_control_fields(struct 
vmx_pages *vmx)
vmwrite(VM_ENTRY_MSR_LOAD_COUNT, 0);
vmwrite(VM_ENTRY_INTR_INFO_FIELD, 0);
vmwrite(TPR_THRESHOLD, 0);
-   vmwrite(SECONDARY_VM_EXEC_CONTROL, 0);
 
vmwrite(CR0_GUEST_HOST_MASK, 0);
vmwrite(CR4_GUEST_HOST_MASK, 0);
@@ -132,6 +157,8 @@ static inline void init_vmcs_control_fields(struct 
vmx_pages *vmx)
vmwrite(CR4_READ_SHADOW, get_cr4());
 
vmwrite(MSR_BITMAP, vmx->msr_gpa);
+   vmwrite(VMREAD_BITMAP, vmx->vmread_gpa);
+   vmwrite(VMWRITE_BITMAP, vmx->vmwrite_gpa);
 }
 
 /*
diff --git a/tools/testing/selftests/kvm/state_test.c 
b/tools/testing/selftests/kvm/state_test.c
index 447da4f76b56..833319b06577 100644
--- a/tools/testing/selftests/kvm/state_test.c
+++ b/tools/testing/selftests/kvm/state_test.c
@@ -55,7 +55,15 @@ void l2_guest_code(void)
 /* Exit to L1 */
vmcall();
 
-   GUEST_SYNC(7);
+   /* L1 has now set up a shadow VMCS for us.  */
+   GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffee);
+   GUEST_SYNC(9);
+   GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffee);

[PATCH 08/10] kvm: selftests: add test for nested state save/restore

2018-07-28 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/include/vmx.h | 32 +
 tools/testing/selftests/kvm/lib/x86.c | 27 ++-
 tools/testing/selftests/kvm/state_test.c  | 75 ++-
 3 files changed, 131 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/vmx.h 
b/tools/testing/selftests/kvm/include/vmx.h
index 9caaf56696a4..2b37f9b6f7df 100644
--- a/tools/testing/selftests/kvm/include/vmx.h
+++ b/tools/testing/selftests/kvm/include/vmx.h
@@ -380,6 +380,30 @@ static inline int vmptrld(uint64_t vmcs_pa)
return ret;
 }
 
+static inline int vmptrst(uint64_t *value)
+{
+   uint64_t tmp;
+   uint8_t ret;
+
+   __asm__ __volatile__("vmptrst %[value]; setna %[ret]"
+   : [value]"=m"(tmp), [ret]"=rm"(ret)
+   : : "cc", "memory");
+
+   *value = tmp;
+   return ret;
+}
+
+/*
+ * A wrapper around vmptrst that ignores errors and returns zero if the
+ * vmptrst instruction fails.
+ */
+static inline uint64_t vmptrstz(void)
+{
+   uint64_t value = 0;
+   vmptrst();
+   return value;
+}
+
 /*
  * No guest state (e.g. GPRs) is established by this vmlaunch.
  */
@@ -444,6 +468,15 @@ static inline int vmresume(void)
return ret;
 }
 
+static inline void vmcall(void)
+{
+   /* Currently, L1 destroys our GPRs during vmexits.  */
+   __asm__ __volatile__("push %%rbp; vmcall; pop %%rbp" : : :
+"rax", "rbx", "rcx", "rdx",
+"rsi", "rdi", "r8", "r9", "r10", "r11", "r12",
+"r13", "r14", "r15");
+}
+
 static inline int vmread(uint64_t encoding, uint64_t *value)
 {
uint64_t tmp;
diff --git a/tools/testing/selftests/kvm/lib/x86.c 
b/tools/testing/selftests/kvm/lib/x86.c
index 78aabcb91de1..e38345252df5 100644
--- a/tools/testing/selftests/kvm/lib/x86.c
+++ b/tools/testing/selftests/kvm/lib/x86.c
@@ -736,6 +736,10 @@ struct kvm_x86_state {
struct kvm_xcrs xcrs;
struct kvm_sregs sregs;
struct kvm_debugregs debugregs;
+   union {
+   struct kvm_nested_state nested;
+   char nested_[16384];
+   };
struct kvm_msrs msrs;
 };
 
@@ -764,6 +762,14 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, 
uint32_t vcpuid)
struct kvm_msr_list *list;
struct kvm_x86_state *state;
int nmsrs, r, i;
+   static int nested_size = -1;
+
+   if (nested_size == -1) {
+   nested_size = kvm_check_cap(KVM_CAP_NESTED_STATE);
+   TEST_ASSERT(nested_size <= sizeof(state->nested_),
+   "Nested state size too big, %i > %zi",
+   nested_size, sizeof(state->nested_));
+   }
 
nmsrs = kvm_get_num_msrs(vm);
list = malloc(sizeof(*list) + nmsrs * sizeof(list->indices[0]));
@@ -797,6 +803,17 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, 
uint32_t vcpuid)
 TEST_ASSERT(r == 0, "Unexpected result from KVM_GET_SREGS, r: %i",
 r);
 
+   if (nested_size) {
+   state->nested.size = sizeof(state->nested_);
+   r = ioctl(vcpu->fd, KVM_GET_NESTED_STATE, >nested);
+   TEST_ASSERT(r == 0, "Unexpected result from 
KVM_GET_NESTED_STATE, r: %i",
+   r);
+   TEST_ASSERT(state->nested.size <= nested_size,
+   "Nested state size too big, %i (KVM_CHECK_CAP gave %i)",
+   state->nested.size, nested_size);
+   } else
+   state->nested.size = 0;
+
state->msrs.nmsrs = nmsrs;
for (i = 0; i < nmsrs; i++)
state->msrs.entries[i].index = list->indices[i];
@@ -817,6 +834,12 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, 
struct kvm_x86_state *s
struct vcpu *vcpu = vcpu_find(vm, vcpuid);
int r;
 
+   if (state->nested.size) {
+   r = ioctl(vcpu->fd, KVM_SET_NESTED_STATE, >nested);
+   TEST_ASSERT(r == 0, "Unexpected result from 
KVM_SET_NESTED_STATE, r: %i",
+   r);
+   }
+
r = ioctl(vcpu->fd, KVM_SET_XSAVE, >xsave);
 TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XSAVE, r: %i",
 r);
diff --git a/tools/testing/selftests/kvm/state_test.c 
b/tools/testing/selftests/kvm/state_test.c
index e47b27b5406e..447da4f76b56 100644
--- a/tools/testing/selftests/kvm/state_test.c
+++ b/tools/testing/selftests/kvm/state_test.c
@@ -18,6 +18,7 @@
 
 #include "kvm_util.h"
 #include "x86.h"
+#include "vmx.h"
 
 #define VCPU_ID5
 #define PORT_SYNC  0x1000
@@ -45,16 +46,75 @@ static inline void __exit_to_l0(uint16_t port, uint64_t 
arg0, uint64_t arg1)
 
 static bool have_nested_state;
 
-void guest_code(void)
+void l2_guest_code(void)
+{
+   GUEST_SYNC(5);
+
+/* Exit to L1 */
+   vmcall();
+
+   GUEST_SYNC(7);
+
+   /* Done, exit 

[PATCH v6 00/10] kvm: x86: migration of nested virtualization state

2018-07-28 Thread Paolo Bonzini
This is the next version of the nested virtualization migration series,
now with unit tests too.

Patches 6, 7, and 9 replace the (broken) WIP patches in the kvm/queue branch,
while the other seven are new and related to the tests.  In particular, patch 1
is an independent bugfix, which makes it much simpler to use 
KVM_GET_MSR/KVM_SET_MSR
in a simple userspace client such as the new test.  Patches 2-4 are also
improvements and bugfixes to the unit test infrastructure.

Please review (especially the non-test patches of course!).

Thanks,

Paolo

Jim Mattson (1):
kvm: nVMX: Introduce KVM_CAP_NESTED_STATE

Paolo Bonzini (9):
KVM: x86: ensure all MSRs can always be KVM_GET/SET_MSR'd
kvm: selftests: create a GDT and TSS
kvm: selftests: actually use all of lib/vmx.c
kvm: selftests: ensure vcpu file is released
kvm: selftests: add basic test for state save and restore
KVM: x86: do not load vmcs12 pages while still in SMM
kvm: selftests: add test for nested state save/restore
KVM: nVMX: include shadow vmcs12 in nested state
KVM: selftests: add tests for shadow VMCS save/restore

 Documentation/virtual/kvm/api.txt   |   56 
 arch/x86/include/asm/kvm_host.h |9 
 arch/x86/include/uapi/asm/kvm.h |   37 ++
 arch/x86/kvm/hyperv.c   |   27 +-
 arch/x86/kvm/hyperv.h   |2 
 arch/x86/kvm/vmx.c  |  255 ++-
 arch/x86/kvm/x86.c  |   71 +
 include/uapi/linux/kvm.h|4 
 tools/testing/selftests/kvm/Makefile|1 
 tools/testing/selftests/kvm/cr4_cpuid_sync_test.c   |2 
 tools/testing/selftests/kvm/include/kvm_util.h  |4 
 tools/testing/selftests/kvm/include/vmx.h   |   66 -
 tools/testing/selftests/kvm/include/x86.h   |8 
 tools/testing/selftests/kvm/lib/kvm_util.c  |  102 ++-
 tools/testing/selftests/kvm/lib/kvm_util_internal.h |7 
 tools/testing/selftests/kvm/lib/vmx.c   |  104 +---
 tools/testing/selftests/kvm/lib/x86.c   |  256 
 tools/testing/selftests/kvm/state_test.c|  224 +
 tools/testing/selftests/kvm/vmx_tsc_adjust_test.c   |   69 +
 19 files changed, 1105 insertions(+), 199 deletions(-)



[PATCH 01/10] KVM: x86: ensure all MSRs can always be KVM_GET/SET_MSR'd

2018-07-28 Thread Paolo Bonzini
Some of the MSRs returned by GET_MSR_INDEX_LIST currently cannot be sent back
to KVM_GET_MSR and/or KVM_SET_MSR; either they can never be sent back, or you
they are only accepted under special conditions.  This makes the API a pain to
use.

To avoid this pain, this patch makes it so that the result of the get-list
ioctl can always be used for host-initiated get and set.  Since we don't have
a separate way to check for read-only MSRs, this means some Hyper-V MSRs are
ignored when written.  Arguably they should not even be in the result of
GET_MSR_INDEX_LIST, but I am leaving there in case userspace is using the
outcome of GET_MSR_INDEX_LIST to derive the support for the corresponding
Hyper-V feature.

Cc: sta...@vger.kernel.org
Signed-off-by: Paolo Bonzini 
---
 arch/x86/kvm/hyperv.c | 27 ---
 arch/x86/kvm/hyperv.h |  2 +-
 arch/x86/kvm/x86.c| 15 +--
 3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index af8caf965baa..01d209ab5481 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -235,7 +235,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
struct kvm_vcpu *vcpu = synic_to_vcpu(synic);
int ret;
 
-   if (!synic->active)
+   if (!synic->active && !host)
return 1;
 
trace_kvm_hv_synic_set_msr(vcpu->vcpu_id, msr, data, host);
@@ -295,11 +295,12 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
return ret;
 }
 
-static int synic_get_msr(struct kvm_vcpu_hv_synic *synic, u32 msr, u64 *pdata)
+static int synic_get_msr(struct kvm_vcpu_hv_synic *synic, u32 msr, u64 *pdata,
+bool host)
 {
int ret;
 
-   if (!synic->active)
+   if (!synic->active && !host)
return 1;
 
ret = 0;
@@ -1014,6 +1015,11 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 data,
case HV_X64_MSR_TSC_EMULATION_STATUS:
hv->hv_tsc_emulation_status = data;
break;
+   case HV_X64_MSR_TIME_REF_COUNT:
+   /* read-only, but still ignore it if host-initiated */
+   if (!host)
+   return 1;
+   break;
default:
vcpu_unimpl(vcpu, "Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n",
msr, data);
@@ -1101,6 +1107,12 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 
msr, u64 data, bool host)
return stimer_set_count(vcpu_to_stimer(vcpu, timer_index),
data, host);
}
+   case HV_X64_MSR_TSC_FREQUENCY:
+   case HV_X64_MSR_APIC_FREQUENCY:
+   /* read-only, but still ignore it if host-initiated */
+   if (!host)
+   return 1;
+   break;
default:
vcpu_unimpl(vcpu, "Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n",
msr, data);
@@ -1156,7 +1168,8 @@ static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 *pdata)
return 0;
 }
 
-static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata,
+ bool host)
 {
u64 data = 0;
struct kvm_vcpu_hv *hv = >arch.hyperv;
@@ -1183,7 +1196,7 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, 
u64 *pdata)
case HV_X64_MSR_SIMP:
case HV_X64_MSR_EOM:
case HV_X64_MSR_SINT0 ... HV_X64_MSR_SINT15:
-   return synic_get_msr(vcpu_to_synic(vcpu), msr, pdata);
+   return synic_get_msr(vcpu_to_synic(vcpu), msr, pdata, host);
case HV_X64_MSR_STIMER0_CONFIG:
case HV_X64_MSR_STIMER1_CONFIG:
case HV_X64_MSR_STIMER2_CONFIG:
@@ -1229,7 +1242,7 @@ int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, 
u64 data, bool host)
return kvm_hv_set_msr(vcpu, msr, data, host);
 }
 
-int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool 
host)
 {
if (kvm_hv_msr_partition_wide(msr)) {
int r;
@@ -1239,7 +1252,7 @@ int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, 
u64 *pdata)
mutex_unlock(>kvm->arch.hyperv.hv_lock);
return r;
} else
-   return kvm_hv_get_msr(vcpu, msr, pdata);
+   return kvm_hv_get_msr(vcpu, msr, pdata, host);
 }
 
 static __always_inline int get_sparse_bank_no(u64 valid_bank_mask, int bank_no)
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
index 837465d69c6d..d6aa969e20f1 100644
--- a/arch/x86/kvm/hyperv.h
+++ b/arch/x86/kvm/hyperv.h
@@ -48,7 +48,7 @@ static inline struct kvm_vcpu *synic_to_vcpu(struct 
kvm_vcpu_hv_synic *synic)
 }
 
 int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host);
-int 

[PATCH 08/10] kvm: selftests: add test for nested state save/restore

2018-07-28 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini 
---
 tools/testing/selftests/kvm/include/vmx.h | 32 +
 tools/testing/selftests/kvm/lib/x86.c | 27 ++-
 tools/testing/selftests/kvm/state_test.c  | 75 ++-
 3 files changed, 131 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/vmx.h 
b/tools/testing/selftests/kvm/include/vmx.h
index 9caaf56696a4..2b37f9b6f7df 100644
--- a/tools/testing/selftests/kvm/include/vmx.h
+++ b/tools/testing/selftests/kvm/include/vmx.h
@@ -380,6 +380,30 @@ static inline int vmptrld(uint64_t vmcs_pa)
return ret;
 }
 
+static inline int vmptrst(uint64_t *value)
+{
+   uint64_t tmp;
+   uint8_t ret;
+
+   __asm__ __volatile__("vmptrst %[value]; setna %[ret]"
+   : [value]"=m"(tmp), [ret]"=rm"(ret)
+   : : "cc", "memory");
+
+   *value = tmp;
+   return ret;
+}
+
+/*
+ * A wrapper around vmptrst that ignores errors and returns zero if the
+ * vmptrst instruction fails.
+ */
+static inline uint64_t vmptrstz(void)
+{
+   uint64_t value = 0;
+   vmptrst();
+   return value;
+}
+
 /*
  * No guest state (e.g. GPRs) is established by this vmlaunch.
  */
@@ -444,6 +468,15 @@ static inline int vmresume(void)
return ret;
 }
 
+static inline void vmcall(void)
+{
+   /* Currently, L1 destroys our GPRs during vmexits.  */
+   __asm__ __volatile__("push %%rbp; vmcall; pop %%rbp" : : :
+"rax", "rbx", "rcx", "rdx",
+"rsi", "rdi", "r8", "r9", "r10", "r11", "r12",
+"r13", "r14", "r15");
+}
+
 static inline int vmread(uint64_t encoding, uint64_t *value)
 {
uint64_t tmp;
diff --git a/tools/testing/selftests/kvm/lib/x86.c 
b/tools/testing/selftests/kvm/lib/x86.c
index 78aabcb91de1..e38345252df5 100644
--- a/tools/testing/selftests/kvm/lib/x86.c
+++ b/tools/testing/selftests/kvm/lib/x86.c
@@ -736,6 +736,10 @@ struct kvm_x86_state {
struct kvm_xcrs xcrs;
struct kvm_sregs sregs;
struct kvm_debugregs debugregs;
+   union {
+   struct kvm_nested_state nested;
+   char nested_[16384];
+   };
struct kvm_msrs msrs;
 };
 
@@ -764,6 +762,14 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, 
uint32_t vcpuid)
struct kvm_msr_list *list;
struct kvm_x86_state *state;
int nmsrs, r, i;
+   static int nested_size = -1;
+
+   if (nested_size == -1) {
+   nested_size = kvm_check_cap(KVM_CAP_NESTED_STATE);
+   TEST_ASSERT(nested_size <= sizeof(state->nested_),
+   "Nested state size too big, %i > %zi",
+   nested_size, sizeof(state->nested_));
+   }
 
nmsrs = kvm_get_num_msrs(vm);
list = malloc(sizeof(*list) + nmsrs * sizeof(list->indices[0]));
@@ -797,6 +803,17 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, 
uint32_t vcpuid)
 TEST_ASSERT(r == 0, "Unexpected result from KVM_GET_SREGS, r: %i",
 r);
 
+   if (nested_size) {
+   state->nested.size = sizeof(state->nested_);
+   r = ioctl(vcpu->fd, KVM_GET_NESTED_STATE, >nested);
+   TEST_ASSERT(r == 0, "Unexpected result from 
KVM_GET_NESTED_STATE, r: %i",
+   r);
+   TEST_ASSERT(state->nested.size <= nested_size,
+   "Nested state size too big, %i (KVM_CHECK_CAP gave %i)",
+   state->nested.size, nested_size);
+   } else
+   state->nested.size = 0;
+
state->msrs.nmsrs = nmsrs;
for (i = 0; i < nmsrs; i++)
state->msrs.entries[i].index = list->indices[i];
@@ -817,6 +834,12 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, 
struct kvm_x86_state *s
struct vcpu *vcpu = vcpu_find(vm, vcpuid);
int r;
 
+   if (state->nested.size) {
+   r = ioctl(vcpu->fd, KVM_SET_NESTED_STATE, >nested);
+   TEST_ASSERT(r == 0, "Unexpected result from 
KVM_SET_NESTED_STATE, r: %i",
+   r);
+   }
+
r = ioctl(vcpu->fd, KVM_SET_XSAVE, >xsave);
 TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_XSAVE, r: %i",
 r);
diff --git a/tools/testing/selftests/kvm/state_test.c 
b/tools/testing/selftests/kvm/state_test.c
index e47b27b5406e..447da4f76b56 100644
--- a/tools/testing/selftests/kvm/state_test.c
+++ b/tools/testing/selftests/kvm/state_test.c
@@ -18,6 +18,7 @@
 
 #include "kvm_util.h"
 #include "x86.h"
+#include "vmx.h"
 
 #define VCPU_ID5
 #define PORT_SYNC  0x1000
@@ -45,16 +46,75 @@ static inline void __exit_to_l0(uint16_t port, uint64_t 
arg0, uint64_t arg1)
 
 static bool have_nested_state;
 
-void guest_code(void)
+void l2_guest_code(void)
+{
+   GUEST_SYNC(5);
+
+/* Exit to L1 */
+   vmcall();
+
+   GUEST_SYNC(7);
+
+   /* Done, exit 

[PATCH v6 00/10] kvm: x86: migration of nested virtualization state

2018-07-28 Thread Paolo Bonzini
This is the next version of the nested virtualization migration series,
now with unit tests too.

Patches 6, 7, and 9 replace the (broken) WIP patches in the kvm/queue branch,
while the other seven are new and related to the tests.  In particular, patch 1
is an independent bugfix, which makes it much simpler to use 
KVM_GET_MSR/KVM_SET_MSR
in a simple userspace client such as the new test.  Patches 2-4 are also
improvements and bugfixes to the unit test infrastructure.

Please review (especially the non-test patches of course!).

Thanks,

Paolo

Jim Mattson (1):
kvm: nVMX: Introduce KVM_CAP_NESTED_STATE

Paolo Bonzini (9):
KVM: x86: ensure all MSRs can always be KVM_GET/SET_MSR'd
kvm: selftests: create a GDT and TSS
kvm: selftests: actually use all of lib/vmx.c
kvm: selftests: ensure vcpu file is released
kvm: selftests: add basic test for state save and restore
KVM: x86: do not load vmcs12 pages while still in SMM
kvm: selftests: add test for nested state save/restore
KVM: nVMX: include shadow vmcs12 in nested state
KVM: selftests: add tests for shadow VMCS save/restore

 Documentation/virtual/kvm/api.txt   |   56 
 arch/x86/include/asm/kvm_host.h |9 
 arch/x86/include/uapi/asm/kvm.h |   37 ++
 arch/x86/kvm/hyperv.c   |   27 +-
 arch/x86/kvm/hyperv.h   |2 
 arch/x86/kvm/vmx.c  |  255 ++-
 arch/x86/kvm/x86.c  |   71 +
 include/uapi/linux/kvm.h|4 
 tools/testing/selftests/kvm/Makefile|1 
 tools/testing/selftests/kvm/cr4_cpuid_sync_test.c   |2 
 tools/testing/selftests/kvm/include/kvm_util.h  |4 
 tools/testing/selftests/kvm/include/vmx.h   |   66 -
 tools/testing/selftests/kvm/include/x86.h   |8 
 tools/testing/selftests/kvm/lib/kvm_util.c  |  102 ++-
 tools/testing/selftests/kvm/lib/kvm_util_internal.h |7 
 tools/testing/selftests/kvm/lib/vmx.c   |  104 +---
 tools/testing/selftests/kvm/lib/x86.c   |  256 
 tools/testing/selftests/kvm/state_test.c|  224 +
 tools/testing/selftests/kvm/vmx_tsc_adjust_test.c   |   69 +
 19 files changed, 1105 insertions(+), 199 deletions(-)



[PATCH 01/10] KVM: x86: ensure all MSRs can always be KVM_GET/SET_MSR'd

2018-07-28 Thread Paolo Bonzini
Some of the MSRs returned by GET_MSR_INDEX_LIST currently cannot be sent back
to KVM_GET_MSR and/or KVM_SET_MSR; either they can never be sent back, or you
they are only accepted under special conditions.  This makes the API a pain to
use.

To avoid this pain, this patch makes it so that the result of the get-list
ioctl can always be used for host-initiated get and set.  Since we don't have
a separate way to check for read-only MSRs, this means some Hyper-V MSRs are
ignored when written.  Arguably they should not even be in the result of
GET_MSR_INDEX_LIST, but I am leaving there in case userspace is using the
outcome of GET_MSR_INDEX_LIST to derive the support for the corresponding
Hyper-V feature.

Cc: sta...@vger.kernel.org
Signed-off-by: Paolo Bonzini 
---
 arch/x86/kvm/hyperv.c | 27 ---
 arch/x86/kvm/hyperv.h |  2 +-
 arch/x86/kvm/x86.c| 15 +--
 3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index af8caf965baa..01d209ab5481 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -235,7 +235,7 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
struct kvm_vcpu *vcpu = synic_to_vcpu(synic);
int ret;
 
-   if (!synic->active)
+   if (!synic->active && !host)
return 1;
 
trace_kvm_hv_synic_set_msr(vcpu->vcpu_id, msr, data, host);
@@ -295,11 +295,12 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
return ret;
 }
 
-static int synic_get_msr(struct kvm_vcpu_hv_synic *synic, u32 msr, u64 *pdata)
+static int synic_get_msr(struct kvm_vcpu_hv_synic *synic, u32 msr, u64 *pdata,
+bool host)
 {
int ret;
 
-   if (!synic->active)
+   if (!synic->active && !host)
return 1;
 
ret = 0;
@@ -1014,6 +1015,11 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 data,
case HV_X64_MSR_TSC_EMULATION_STATUS:
hv->hv_tsc_emulation_status = data;
break;
+   case HV_X64_MSR_TIME_REF_COUNT:
+   /* read-only, but still ignore it if host-initiated */
+   if (!host)
+   return 1;
+   break;
default:
vcpu_unimpl(vcpu, "Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n",
msr, data);
@@ -1101,6 +1107,12 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 
msr, u64 data, bool host)
return stimer_set_count(vcpu_to_stimer(vcpu, timer_index),
data, host);
}
+   case HV_X64_MSR_TSC_FREQUENCY:
+   case HV_X64_MSR_APIC_FREQUENCY:
+   /* read-only, but still ignore it if host-initiated */
+   if (!host)
+   return 1;
+   break;
default:
vcpu_unimpl(vcpu, "Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n",
msr, data);
@@ -1156,7 +1168,8 @@ static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 
msr, u64 *pdata)
return 0;
 }
 
-static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata,
+ bool host)
 {
u64 data = 0;
struct kvm_vcpu_hv *hv = >arch.hyperv;
@@ -1183,7 +1196,7 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, 
u64 *pdata)
case HV_X64_MSR_SIMP:
case HV_X64_MSR_EOM:
case HV_X64_MSR_SINT0 ... HV_X64_MSR_SINT15:
-   return synic_get_msr(vcpu_to_synic(vcpu), msr, pdata);
+   return synic_get_msr(vcpu_to_synic(vcpu), msr, pdata, host);
case HV_X64_MSR_STIMER0_CONFIG:
case HV_X64_MSR_STIMER1_CONFIG:
case HV_X64_MSR_STIMER2_CONFIG:
@@ -1229,7 +1242,7 @@ int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, 
u64 data, bool host)
return kvm_hv_set_msr(vcpu, msr, data, host);
 }
 
-int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
+int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool 
host)
 {
if (kvm_hv_msr_partition_wide(msr)) {
int r;
@@ -1239,7 +1252,7 @@ int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, 
u64 *pdata)
mutex_unlock(>kvm->arch.hyperv.hv_lock);
return r;
} else
-   return kvm_hv_get_msr(vcpu, msr, pdata);
+   return kvm_hv_get_msr(vcpu, msr, pdata, host);
 }
 
 static __always_inline int get_sparse_bank_no(u64 valid_bank_mask, int bank_no)
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
index 837465d69c6d..d6aa969e20f1 100644
--- a/arch/x86/kvm/hyperv.h
+++ b/arch/x86/kvm/hyperv.h
@@ -48,7 +48,7 @@ static inline struct kvm_vcpu *synic_to_vcpu(struct 
kvm_vcpu_hv_synic *synic)
 }
 
 int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host);
-int 

Re: [PATCH 00/08] staging:rtl8192u: cleanup of rtl819x_Qos.h - Style

2018-07-28 Thread John Whitmore
On Sun, Jul 29, 2018 at 12:02:52AM +0100, John Whitmore wrote:
> These are a few coding style changes to the file
> drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
> I had more patches in the list but had to dump some of the later
> patches as I made a mistake. Thought I'd send these 8.
> 
> John Whitmore (8):
>   staging:rtl8192u: Add spaces around operators - Style
>   staging:rtl8192u: Rename ACI_AIFSN - Style
>   staging:rtl8192u: Rename member variables - Style
>   staging:rtl8192u: Remove unused  union AC_PARAM - Style
>   staging:rtl8192u: Remove unused union ECW -Style
>   staging:rtl8192u: Rename enum DIRECTION_VALUE - Style
>   staging:rtl8192u: Rename union QOS_TSINFO - Style
>   staging:rtl8192u: Remove unused constants - Style
> 

Sorry I forgot to edit the subject of each of the patch emails to
truncate the patch series to just the 8 that were good. I'll edit and
resend.

jwhitmore


Re: [PATCH 00/08] staging:rtl8192u: cleanup of rtl819x_Qos.h - Style

2018-07-28 Thread John Whitmore
On Sun, Jul 29, 2018 at 12:02:52AM +0100, John Whitmore wrote:
> These are a few coding style changes to the file
> drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
> I had more patches in the list but had to dump some of the later
> patches as I made a mistake. Thought I'd send these 8.
> 
> John Whitmore (8):
>   staging:rtl8192u: Add spaces around operators - Style
>   staging:rtl8192u: Rename ACI_AIFSN - Style
>   staging:rtl8192u: Rename member variables - Style
>   staging:rtl8192u: Remove unused  union AC_PARAM - Style
>   staging:rtl8192u: Remove unused union ECW -Style
>   staging:rtl8192u: Rename enum DIRECTION_VALUE - Style
>   staging:rtl8192u: Rename union QOS_TSINFO - Style
>   staging:rtl8192u: Remove unused constants - Style
> 

Sorry I forgot to edit the subject of each of the patch emails to
truncate the patch series to just the 8 that were good. I'll edit and
resend.

jwhitmore


[PATCH 08/12] staging:rtl8192u: Remove unused constants - Style

2018-07-28 Thread John Whitmore
Remove defined constants from code, since they are never actually
used in code. This is a simple coding style change which should have
no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 17b676b0ed8b..810d81addcf6 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -2,13 +2,6 @@
 #ifndef __INC_QOS_TYPE_H
 #define __INC_QOS_TYPE_H
 
-#defineMAX_WMMELE_LENGTH   64
-
-#define AC_PARAM_SIZE  4
-#define WMM_PARAM_ELE_BODY_LEN 18
-
-#define WMM_PARAM_ELEMENT_SIZE (8 + (4 * AC_PARAM_SIZE))
-
 //
 // ACI/AIFSN Field.
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
-- 
2.18.0



[PATCH 06/12] staging:rtl8192u: Rename enum DIRECTION_VALUE - Style

2018-07-28 Thread John Whitmore
The enumerated type DIRECTION_VALUE should be named in lowercase to
comply with coding standard so is renamed to direction_value. In
addition the 'typedef' directive has been removed to clear the
checkpatch issue with defining new types.

These changes are coding style changes which should have no impact on
runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h| 4 ++--
 drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 65d7c9f4d840..428a8c4cebf1 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -28,12 +28,12 @@ union aci_aifsn {
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
 //
-typedefenum _DIRECTION_VALUE {
+enum direction_value {
DIR_UP  = 0,// 0x00 // UpLink
DIR_DOWN= 1,// 0x01 // DownLink
DIR_DIRECT  = 2,// 0x10 // DirectLink
DIR_BI_DIR  = 3,// 0x11 // Bi-Direction
-} DIRECTION_VALUE, *PDIRECTION_VALUE;
+};
 
 
 //
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 4b2da7f31166..79c96da41d8b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -366,7 +366,7 @@ bool GetTs(

(>Tx_TS_Admit_List):

(>Rx_TS_Admit_List);
 
-   DIRECTION_VALUE Dir =   (ieee->iw_mode 
== IW_MODE_MASTER)?
+   enum direction_valueDir =   (ieee->iw_mode 
== IW_MODE_MASTER)?

((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):

((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
IEEE80211_DEBUG(IEEE80211_DL_TS, "to add Ts\n");
-- 
2.18.0



[PATCH 07/12] staging:rtl8192u: Rename union QOS_TSINFO - Style

2018-07-28 Thread John Whitmore
The union QOS_TSINFO, as a type, should have a lowercase name. The
union has therefore been renamed to qos_tsinfo. Additionally the
'typedef' directive has been removed to clear the checkpatch issue
with defining new types.

These are coding style changes which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h| 6 +++---
 drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 428a8c4cebf1..17b676b0ed8b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -42,7 +42,7 @@ enum direction_value {
 // 1. WMM spec 2.2.11: WME TSPEC Element, p.18.
 // 2. 8185 QoS code: QOS_TSINFO [def. in QoS_mp.h]
 //
-typedef union _QOS_TSINFO {
+union qos_tsinfo {
u8  charData[3];
struct {
u8  ucTrafficType:1;//WMM 
is reserved
@@ -56,7 +56,7 @@ typedef union _QOS_TSINFO {
u8  ucSchedule:1;   //WMM is 
reserved
u8  ucReserved:7;
} field;
-} QOS_TSINFO, *PQOS_TSINFO;
+};
 
 //
 // WMM TSPEC Body.
@@ -66,7 +66,7 @@ typedef union _TSPEC_BODY {
u8  charData[55];
 
struct {
-   QOS_TSINFO  TSInfo; //u8TSInfo[3];
+   union qos_tsinfoTSInfo; //u8TSInfo[3];
u16 NominalMSDUsize;
u16 MaxMSDUsize;
u32 MinServiceItv;
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 79c96da41d8b..4d92b97a1521 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -355,7 +355,7 @@ bool GetTs(
// For HCCA or WMMSA, TS cannot be addmit without 
negotiation.
//
TSPEC_BODY  TSpec;
-   PQOS_TSINFO pTSInfo = 
+   union qos_tsinfo*pTSInfo = 
struct list_head*pUnusedList =
(TxRxSelect == 
TX_DIR)?

(>Tx_TS_Unused_List):
-- 
2.18.0



[PATCH 05/12] staging:rtl8192u: Remove unused union ECW -Style

2018-07-28 Thread John Whitmore
The union ECW is never used in code so has simply been removed.
This is a coding style change which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 12 
 1 file changed, 12 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 43edb830ad5d..65d7c9f4d840 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -24,18 +24,6 @@ union aci_aifsn {
} f;// Field
 };
 
-//
-// ECWmin/ECWmax field.
-// Ref: WMM spec 2.2.2: WME Parameter Element, p.13.
-//
-typedefunion _ECW {
-   u8  charData;
-   struct {
-   u8  ECWmin:4;
-   u8  ECWmax:4;
-   } f;// Field
-} ECW, *PECW;
-
 //
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
-- 
2.18.0



[PATCH 08/12] staging:rtl8192u: Remove unused constants - Style

2018-07-28 Thread John Whitmore
Remove defined constants from code, since they are never actually
used in code. This is a simple coding style change which should have
no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 17b676b0ed8b..810d81addcf6 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -2,13 +2,6 @@
 #ifndef __INC_QOS_TYPE_H
 #define __INC_QOS_TYPE_H
 
-#defineMAX_WMMELE_LENGTH   64
-
-#define AC_PARAM_SIZE  4
-#define WMM_PARAM_ELE_BODY_LEN 18
-
-#define WMM_PARAM_ELEMENT_SIZE (8 + (4 * AC_PARAM_SIZE))
-
 //
 // ACI/AIFSN Field.
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
-- 
2.18.0



[PATCH 06/12] staging:rtl8192u: Rename enum DIRECTION_VALUE - Style

2018-07-28 Thread John Whitmore
The enumerated type DIRECTION_VALUE should be named in lowercase to
comply with coding standard so is renamed to direction_value. In
addition the 'typedef' directive has been removed to clear the
checkpatch issue with defining new types.

These changes are coding style changes which should have no impact on
runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h| 4 ++--
 drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 65d7c9f4d840..428a8c4cebf1 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -28,12 +28,12 @@ union aci_aifsn {
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
 //
-typedefenum _DIRECTION_VALUE {
+enum direction_value {
DIR_UP  = 0,// 0x00 // UpLink
DIR_DOWN= 1,// 0x01 // DownLink
DIR_DIRECT  = 2,// 0x10 // DirectLink
DIR_BI_DIR  = 3,// 0x11 // Bi-Direction
-} DIRECTION_VALUE, *PDIRECTION_VALUE;
+};
 
 
 //
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 4b2da7f31166..79c96da41d8b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -366,7 +366,7 @@ bool GetTs(

(>Tx_TS_Admit_List):

(>Rx_TS_Admit_List);
 
-   DIRECTION_VALUE Dir =   (ieee->iw_mode 
== IW_MODE_MASTER)?
+   enum direction_valueDir =   (ieee->iw_mode 
== IW_MODE_MASTER)?

((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):

((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
IEEE80211_DEBUG(IEEE80211_DL_TS, "to add Ts\n");
-- 
2.18.0



[PATCH 07/12] staging:rtl8192u: Rename union QOS_TSINFO - Style

2018-07-28 Thread John Whitmore
The union QOS_TSINFO, as a type, should have a lowercase name. The
union has therefore been renamed to qos_tsinfo. Additionally the
'typedef' directive has been removed to clear the checkpatch issue
with defining new types.

These are coding style changes which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h| 6 +++---
 drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 428a8c4cebf1..17b676b0ed8b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -42,7 +42,7 @@ enum direction_value {
 // 1. WMM spec 2.2.11: WME TSPEC Element, p.18.
 // 2. 8185 QoS code: QOS_TSINFO [def. in QoS_mp.h]
 //
-typedef union _QOS_TSINFO {
+union qos_tsinfo {
u8  charData[3];
struct {
u8  ucTrafficType:1;//WMM 
is reserved
@@ -56,7 +56,7 @@ typedef union _QOS_TSINFO {
u8  ucSchedule:1;   //WMM is 
reserved
u8  ucReserved:7;
} field;
-} QOS_TSINFO, *PQOS_TSINFO;
+};
 
 //
 // WMM TSPEC Body.
@@ -66,7 +66,7 @@ typedef union _TSPEC_BODY {
u8  charData[55];
 
struct {
-   QOS_TSINFO  TSInfo; //u8TSInfo[3];
+   union qos_tsinfoTSInfo; //u8TSInfo[3];
u16 NominalMSDUsize;
u16 MaxMSDUsize;
u32 MinServiceItv;
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 79c96da41d8b..4d92b97a1521 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -355,7 +355,7 @@ bool GetTs(
// For HCCA or WMMSA, TS cannot be addmit without 
negotiation.
//
TSPEC_BODY  TSpec;
-   PQOS_TSINFO pTSInfo = 
+   union qos_tsinfo*pTSInfo = 
struct list_head*pUnusedList =
(TxRxSelect == 
TX_DIR)?

(>Tx_TS_Unused_List):
-- 
2.18.0



[PATCH 05/12] staging:rtl8192u: Remove unused union ECW -Style

2018-07-28 Thread John Whitmore
The union ECW is never used in code so has simply been removed.
This is a coding style change which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 12 
 1 file changed, 12 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 43edb830ad5d..65d7c9f4d840 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -24,18 +24,6 @@ union aci_aifsn {
} f;// Field
 };
 
-//
-// ECWmin/ECWmax field.
-// Ref: WMM spec 2.2.2: WME Parameter Element, p.13.
-//
-typedefunion _ECW {
-   u8  charData;
-   struct {
-   u8  ECWmin:4;
-   u8  ECWmax:4;
-   } f;// Field
-} ECW, *PECW;
-
 //
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
-- 
2.18.0



[PATCH 02/12] staging:rtl8192u: Rename ACI_AIFSN - Style

2018-07-28 Thread John Whitmore
Rename the union ACI_AIFSN to aci_aifsn and remove the typedef directive.

The removal of the typedef clears the checkpatch issue with defining
new types. The renaming is to adhere to the coding style where types
are name in lower case.

These changes are coding style changes which should have no impact on
runtime execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 6 +++---
 drivers/staging/rtl8192u/r8192U_dm.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 92afa9dc9663..5856bf87c5dc 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -13,7 +13,7 @@
 // ACI/AIFSN Field.
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
 //
-typedefunion _ACI_AIFSN {
+union aci_aifsn {
u8  charData;
 
struct {
@@ -22,7 +22,7 @@ typedef   union _ACI_AIFSN {
u8  ACI:2;
u8  Reserved:1;
} f;// Field
-} ACI_AIFSN, *PACI_AIFSN;
+};
 
 //
 // ECWmin/ECWmax field.
@@ -45,7 +45,7 @@ typedef   union _AC_PARAM {
u8  charData[4];
 
struct {
-   ACI_AIFSN   AciAifsn;
+   union aci_aifsn AciAifsn;
ECW Ecw;
u16 TXOPLimit;
} f;// Field
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c 
b/drivers/staging/rtl8192u/r8192U_dm.c
index c4e4e3ba394b..04c08ca8a0bb 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2333,7 +2333,7 @@ static void dm_check_edca_turbo(
{
/*  TODO:  Modified this part and try to set 
acm control in only 1 IO processing!! */
 
-   PACI_AIFSN  pAciAifsn = 
(PACI_AIFSN)&(qos_parameters->aifs[0]);
+   union aci_aifsn *pAciAifsn = (union aci_aifsn 
*)&(qos_parameters->aifs[0]);
u8  AcmCtrl;
 
read_nic_byte(dev, AcmHwCtrl, );
-- 
2.18.0



[PATCH 03/12] staging:rtl8192u: Rename member variables - Style

2018-07-28 Thread John Whitmore
Rename the member variables of union aci_aifsn, which should be named
in lowercase. The only member variable, of this union, which is
actually used is 'acm'.

This are coding style changes which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 10 +-
 drivers/staging/rtl8192u/r8192U_dm.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 5856bf87c5dc..901b85139d3b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -14,13 +14,13 @@
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
 //
 union aci_aifsn {
-   u8  charData;
+   u8  char_data;
 
struct {
-   u8  AIFSN:4;
-   u8  ACM:1;
-   u8  ACI:2;
-   u8  Reserved:1;
+   u8  aifsn:4;
+   u8  acm:1;
+   u8  aci:2;
+   u8  reserved:1;
} f;// Field
 };
 
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c 
b/drivers/staging/rtl8192u/r8192U_dm.c
index 04c08ca8a0bb..7dc912dd53af 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2338,7 +2338,7 @@ static void dm_check_edca_turbo(
 
read_nic_byte(dev, AcmHwCtrl, );
 
-   if (pAciAifsn->f.ACM) { /*  ACM bit is 1. */
+   if (pAciAifsn->f.acm) { /*  acm bit is 1. */
AcmCtrl |= AcmHw_BeqEn;
} else {/* ACM bit is 0. */
AcmCtrl &= (~AcmHw_BeqEn);
-- 
2.18.0



[PATCH 04/12] staging:rtl8192u: Remove unused union AC_PARAM - Style

2018-07-28 Thread John Whitmore
The union ACM_PARAM is never actually used in code so removed. This
is a coding style change which should have no impact on runtime code
execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 901b85139d3b..43edb830ad5d 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -36,21 +36,6 @@ typedef  union _ECW {
} f;// Field
 } ECW, *PECW;
 
-//
-// AC Parameters Record Format.
-// Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
-//
-typedefunion _AC_PARAM {
-   u32 longData;
-   u8  charData[4];
-
-   struct {
-   union aci_aifsn AciAifsn;
-   ECW Ecw;
-   u16 TXOPLimit;
-   } f;// Field
-} AC_PARAM, *PAC_PARAM;
-
 //
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
-- 
2.18.0



[PATCH 02/12] staging:rtl8192u: Rename ACI_AIFSN - Style

2018-07-28 Thread John Whitmore
Rename the union ACI_AIFSN to aci_aifsn and remove the typedef directive.

The removal of the typedef clears the checkpatch issue with defining
new types. The renaming is to adhere to the coding style where types
are name in lower case.

These changes are coding style changes which should have no impact on
runtime execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 6 +++---
 drivers/staging/rtl8192u/r8192U_dm.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 92afa9dc9663..5856bf87c5dc 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -13,7 +13,7 @@
 // ACI/AIFSN Field.
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
 //
-typedefunion _ACI_AIFSN {
+union aci_aifsn {
u8  charData;
 
struct {
@@ -22,7 +22,7 @@ typedef   union _ACI_AIFSN {
u8  ACI:2;
u8  Reserved:1;
} f;// Field
-} ACI_AIFSN, *PACI_AIFSN;
+};
 
 //
 // ECWmin/ECWmax field.
@@ -45,7 +45,7 @@ typedef   union _AC_PARAM {
u8  charData[4];
 
struct {
-   ACI_AIFSN   AciAifsn;
+   union aci_aifsn AciAifsn;
ECW Ecw;
u16 TXOPLimit;
} f;// Field
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c 
b/drivers/staging/rtl8192u/r8192U_dm.c
index c4e4e3ba394b..04c08ca8a0bb 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2333,7 +2333,7 @@ static void dm_check_edca_turbo(
{
/*  TODO:  Modified this part and try to set 
acm control in only 1 IO processing!! */
 
-   PACI_AIFSN  pAciAifsn = 
(PACI_AIFSN)&(qos_parameters->aifs[0]);
+   union aci_aifsn *pAciAifsn = (union aci_aifsn 
*)&(qos_parameters->aifs[0]);
u8  AcmCtrl;
 
read_nic_byte(dev, AcmHwCtrl, );
-- 
2.18.0



[PATCH 03/12] staging:rtl8192u: Rename member variables - Style

2018-07-28 Thread John Whitmore
Rename the member variables of union aci_aifsn, which should be named
in lowercase. The only member variable, of this union, which is
actually used is 'acm'.

This are coding style changes which should have no impact on runtime
code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 10 +-
 drivers/staging/rtl8192u/r8192U_dm.c |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 5856bf87c5dc..901b85139d3b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -14,13 +14,13 @@
 // Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
 //
 union aci_aifsn {
-   u8  charData;
+   u8  char_data;
 
struct {
-   u8  AIFSN:4;
-   u8  ACM:1;
-   u8  ACI:2;
-   u8  Reserved:1;
+   u8  aifsn:4;
+   u8  acm:1;
+   u8  aci:2;
+   u8  reserved:1;
} f;// Field
 };
 
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c 
b/drivers/staging/rtl8192u/r8192U_dm.c
index 04c08ca8a0bb..7dc912dd53af 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -2338,7 +2338,7 @@ static void dm_check_edca_turbo(
 
read_nic_byte(dev, AcmHwCtrl, );
 
-   if (pAciAifsn->f.ACM) { /*  ACM bit is 1. */
+   if (pAciAifsn->f.acm) { /*  acm bit is 1. */
AcmCtrl |= AcmHw_BeqEn;
} else {/* ACM bit is 0. */
AcmCtrl &= (~AcmHw_BeqEn);
-- 
2.18.0



[PATCH 04/12] staging:rtl8192u: Remove unused union AC_PARAM - Style

2018-07-28 Thread John Whitmore
The union ACM_PARAM is never actually used in code so removed. This
is a coding style change which should have no impact on runtime code
execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 901b85139d3b..43edb830ad5d 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -36,21 +36,6 @@ typedef  union _ECW {
} f;// Field
 } ECW, *PECW;
 
-//
-// AC Parameters Record Format.
-// Ref: WMM spec 2.2.2: WME Parameter Element, p.12.
-//
-typedefunion _AC_PARAM {
-   u32 longData;
-   u8  charData[4];
-
-   struct {
-   union aci_aifsn AciAifsn;
-   ECW Ecw;
-   u16 TXOPLimit;
-   } f;// Field
-} AC_PARAM, *PAC_PARAM;
-
 //
 // Direction Field Values.
 // Ref: WMM spec 2.2.11: WME TSPEC Element, p.18.
-- 
2.18.0



[PATCH 00/08] staging:rtl8192u: cleanup of rtl819x_Qos.h - Style

2018-07-28 Thread John Whitmore
These are a few coding style changes to the file
drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
I had more patches in the list but had to dump some of the later
patches as I made a mistake. Thought I'd send these 8.

John Whitmore (8):
  staging:rtl8192u: Add spaces around operators - Style
  staging:rtl8192u: Rename ACI_AIFSN - Style
  staging:rtl8192u: Rename member variables - Style
  staging:rtl8192u: Remove unused  union AC_PARAM - Style
  staging:rtl8192u: Remove unused union ECW -Style
  staging:rtl8192u: Rename enum DIRECTION_VALUE - Style
  staging:rtl8192u: Rename union QOS_TSINFO - Style
  staging:rtl8192u: Remove unused constants - Style



[PATCH 01/12] staging:rtl8192u: Add spaces around operators - Style

2018-07-28 Thread John Whitmore
Add the required spaces around '+' and '*' operators. This is a
coding style change to clear the checkpatch issue. There should be
no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 8ee9370520f3..92afa9dc9663 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -7,7 +7,7 @@
 #define AC_PARAM_SIZE  4
 #define WMM_PARAM_ELE_BODY_LEN 18
 
-#define WMM_PARAM_ELEMENT_SIZE (8+(4*AC_PARAM_SIZE))
+#define WMM_PARAM_ELEMENT_SIZE (8 + (4 * AC_PARAM_SIZE))
 
 //
 // ACI/AIFSN Field.
-- 
2.18.0



[PATCH 00/08] staging:rtl8192u: cleanup of rtl819x_Qos.h - Style

2018-07-28 Thread John Whitmore
These are a few coding style changes to the file
drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
I had more patches in the list but had to dump some of the later
patches as I made a mistake. Thought I'd send these 8.

John Whitmore (8):
  staging:rtl8192u: Add spaces around operators - Style
  staging:rtl8192u: Rename ACI_AIFSN - Style
  staging:rtl8192u: Rename member variables - Style
  staging:rtl8192u: Remove unused  union AC_PARAM - Style
  staging:rtl8192u: Remove unused union ECW -Style
  staging:rtl8192u: Rename enum DIRECTION_VALUE - Style
  staging:rtl8192u: Rename union QOS_TSINFO - Style
  staging:rtl8192u: Remove unused constants - Style



[PATCH 01/12] staging:rtl8192u: Add spaces around operators - Style

2018-07-28 Thread John Whitmore
Add the required spaces around '+' and '*' operators. This is a
coding style change to clear the checkpatch issue. There should be
no impact on runtime code execution.

Signed-off-by: John Whitmore 
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h 
b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 8ee9370520f3..92afa9dc9663 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -7,7 +7,7 @@
 #define AC_PARAM_SIZE  4
 #define WMM_PARAM_ELE_BODY_LEN 18
 
-#define WMM_PARAM_ELEMENT_SIZE (8+(4*AC_PARAM_SIZE))
+#define WMM_PARAM_ELEMENT_SIZE (8 + (4 * AC_PARAM_SIZE))
 
 //
 // ACI/AIFSN Field.
-- 
2.18.0



[PATCH] staging: gasket: use NULL instead of 0 for null pointer

2018-07-28 Thread Dmitriy Cherkasov
Fixes sparse warning: Using plain integer as NULL pointer

Signed-off-by: Dmitriy Cherkasov 
---
 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 9f81161..8fbfd58 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -1689,7 +1689,7 @@ int gasket_alloc_coherent_memory(struct gasket_dev 
*gasket_dev, u64 size,
 
if (gasket_dev->page_table[index]->coherent_pages) {
kfree(gasket_dev->page_table[index]->coherent_pages);
-   gasket_dev->page_table[index]->coherent_pages = 0;
+   gasket_dev->page_table[index]->coherent_pages = NULL;
}
gasket_dev->page_table[index]->num_coherent_pages = 0;
return -ENOMEM;
-- 
1.9.1



[PATCH] staging: gasket: use NULL instead of 0 for null pointer

2018-07-28 Thread Dmitriy Cherkasov
Fixes sparse warning: Using plain integer as NULL pointer

Signed-off-by: Dmitriy Cherkasov 
---
 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 9f81161..8fbfd58 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -1689,7 +1689,7 @@ int gasket_alloc_coherent_memory(struct gasket_dev 
*gasket_dev, u64 size,
 
if (gasket_dev->page_table[index]->coherent_pages) {
kfree(gasket_dev->page_table[index]->coherent_pages);
-   gasket_dev->page_table[index]->coherent_pages = 0;
+   gasket_dev->page_table[index]->coherent_pages = NULL;
}
gasket_dev->page_table[index]->num_coherent_pages = 0;
return -ENOMEM;
-- 
1.9.1



Re: [PATCH 3/4] ASoC: tegra: Allow 32-bit and 24-bit samples

2018-07-28 Thread kbuild test robot
Hi Edward,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tegra/for-next]
[also build test ERROR on v4.18-rc6 next-20180727]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Jorge-Sanjuan/ASoC-Tegra30-TDM-support/20180728-163720
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git for-next
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm 

Note: the linux-review/Jorge-Sanjuan/ASoC-Tegra30-TDM-support/20180728-163720 
HEAD 14bbc96df0fa027f7bc057eb2da8181baff4e22c builds fine.
  It only hurts bisectibility.

All errors (new ones prefixed by >>):

   sound/soc/tegra/tegra30_i2s.c: In function 'tegra30_i2s_hw_params':
>> sound/soc/tegra/tegra30_i2s.c:155:3: error: 'audio_bits' undeclared (first 
>> use in this function); did you mean 'audit_names'?
  audio_bits = TEGRA30_AUDIOCIF_BITS_24;
  ^~
  audit_names
   sound/soc/tegra/tegra30_i2s.c:155:3: note: each undeclared identifier is 
reported only once for each function it appears in

vim +155 sound/soc/tegra/tegra30_i2s.c

   133  
   134  static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
   135   struct snd_pcm_hw_params *params,
   136   struct snd_soc_dai *dai)
   137  {
   138  struct device *dev = dai->dev;
   139  struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
   140  unsigned int mask, val, reg;
   141  int ret, sample_size, srate, i2sclock, bitcnt;
   142  struct tegra30_ahub_cif_conf cif_conf;
   143  
   144  if (params_channels(params) != 2)
   145  return -EINVAL;
   146  
   147  mask = TEGRA30_I2S_CTRL_BIT_SIZE_MASK;
   148  switch (params_format(params)) {
   149  case SNDRV_PCM_FORMAT_S16_LE:
   150  val = TEGRA30_I2S_CTRL_BIT_SIZE_16;
   151  sample_size = 16;
   152  break;
   153  case SNDRV_PCM_FORMAT_S24_LE:
   154  val = TEGRA30_I2S_CTRL_BIT_SIZE_24;
 > 155  audio_bits = TEGRA30_AUDIOCIF_BITS_24;
   156  sample_size = 24;
   157  break;
   158  case SNDRV_PCM_FORMAT_S32_LE:
   159  val = TEGRA30_I2S_CTRL_BIT_SIZE_32;
   160  sample_size = 32;
   161  break;
   162  default:
   163  return -EINVAL;
   164  }
   165  
   166  regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, mask, val);
   167  
   168  srate = params_rate(params);
   169  
   170  /* Final "* 2" required by Tegra hardware */
   171  i2sclock = srate * params_channels(params) * sample_size * 2;
   172  
   173  bitcnt = (i2sclock / (2 * srate)) - 1;
   174  if (bitcnt < 0 || bitcnt > 
TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US)
   175  return -EINVAL;
   176  
   177  ret = clk_set_rate(i2s->clk_i2s, i2sclock);
   178  if (ret) {
   179  dev_err(dev, "Can't set I2S clock rate: %d\n", ret);
   180  return ret;
   181  }
   182  
   183  val = bitcnt << TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT;
   184  
   185  if (i2sclock % (2 * srate))
   186  val |= TEGRA30_I2S_TIMING_NON_SYM_ENABLE;
   187  
   188  regmap_write(i2s->regmap, TEGRA30_I2S_TIMING, val);
   189  
   190  cif_conf.threshold = 0;
   191  cif_conf.audio_channels = 2;
   192  cif_conf.client_channels = 2;
   193  cif_conf.audio_bits = TEGRA30_AUDIOCIF_BITS_16;
   194  cif_conf.client_bits = TEGRA30_AUDIOCIF_BITS_16;
   195  cif_conf.expand = 0;
   196  cif_conf.stereo_conv = 0;
   197  cif_conf.replicate = 0;
   198  cif_conf.truncate = 0;
   199  cif_conf.mono_conv = 0;
   200  
   201  if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
   202  cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_RX;
   203  reg = TEGRA30_I2S_CIF_RX_CTRL;
   204  } else {
   205  cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_TX;
   206  reg = TEGRA30_I2S_CIF_TX_CTRL;
   207  }
   208  
   209  i2s->soc_data->set_audio_cif(i2s->regmap, reg, _conf);
   210  
   211  val = (1 << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) |
   212 

Re: [PATCH 3/4] ASoC: tegra: Allow 32-bit and 24-bit samples

2018-07-28 Thread kbuild test robot
Hi Edward,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tegra/for-next]
[also build test ERROR on v4.18-rc6 next-20180727]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Jorge-Sanjuan/ASoC-Tegra30-TDM-support/20180728-163720
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git for-next
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm 

Note: the linux-review/Jorge-Sanjuan/ASoC-Tegra30-TDM-support/20180728-163720 
HEAD 14bbc96df0fa027f7bc057eb2da8181baff4e22c builds fine.
  It only hurts bisectibility.

All errors (new ones prefixed by >>):

   sound/soc/tegra/tegra30_i2s.c: In function 'tegra30_i2s_hw_params':
>> sound/soc/tegra/tegra30_i2s.c:155:3: error: 'audio_bits' undeclared (first 
>> use in this function); did you mean 'audit_names'?
  audio_bits = TEGRA30_AUDIOCIF_BITS_24;
  ^~
  audit_names
   sound/soc/tegra/tegra30_i2s.c:155:3: note: each undeclared identifier is 
reported only once for each function it appears in

vim +155 sound/soc/tegra/tegra30_i2s.c

   133  
   134  static int tegra30_i2s_hw_params(struct snd_pcm_substream *substream,
   135   struct snd_pcm_hw_params *params,
   136   struct snd_soc_dai *dai)
   137  {
   138  struct device *dev = dai->dev;
   139  struct tegra30_i2s *i2s = snd_soc_dai_get_drvdata(dai);
   140  unsigned int mask, val, reg;
   141  int ret, sample_size, srate, i2sclock, bitcnt;
   142  struct tegra30_ahub_cif_conf cif_conf;
   143  
   144  if (params_channels(params) != 2)
   145  return -EINVAL;
   146  
   147  mask = TEGRA30_I2S_CTRL_BIT_SIZE_MASK;
   148  switch (params_format(params)) {
   149  case SNDRV_PCM_FORMAT_S16_LE:
   150  val = TEGRA30_I2S_CTRL_BIT_SIZE_16;
   151  sample_size = 16;
   152  break;
   153  case SNDRV_PCM_FORMAT_S24_LE:
   154  val = TEGRA30_I2S_CTRL_BIT_SIZE_24;
 > 155  audio_bits = TEGRA30_AUDIOCIF_BITS_24;
   156  sample_size = 24;
   157  break;
   158  case SNDRV_PCM_FORMAT_S32_LE:
   159  val = TEGRA30_I2S_CTRL_BIT_SIZE_32;
   160  sample_size = 32;
   161  break;
   162  default:
   163  return -EINVAL;
   164  }
   165  
   166  regmap_update_bits(i2s->regmap, TEGRA30_I2S_CTRL, mask, val);
   167  
   168  srate = params_rate(params);
   169  
   170  /* Final "* 2" required by Tegra hardware */
   171  i2sclock = srate * params_channels(params) * sample_size * 2;
   172  
   173  bitcnt = (i2sclock / (2 * srate)) - 1;
   174  if (bitcnt < 0 || bitcnt > 
TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US)
   175  return -EINVAL;
   176  
   177  ret = clk_set_rate(i2s->clk_i2s, i2sclock);
   178  if (ret) {
   179  dev_err(dev, "Can't set I2S clock rate: %d\n", ret);
   180  return ret;
   181  }
   182  
   183  val = bitcnt << TEGRA30_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT;
   184  
   185  if (i2sclock % (2 * srate))
   186  val |= TEGRA30_I2S_TIMING_NON_SYM_ENABLE;
   187  
   188  regmap_write(i2s->regmap, TEGRA30_I2S_TIMING, val);
   189  
   190  cif_conf.threshold = 0;
   191  cif_conf.audio_channels = 2;
   192  cif_conf.client_channels = 2;
   193  cif_conf.audio_bits = TEGRA30_AUDIOCIF_BITS_16;
   194  cif_conf.client_bits = TEGRA30_AUDIOCIF_BITS_16;
   195  cif_conf.expand = 0;
   196  cif_conf.stereo_conv = 0;
   197  cif_conf.replicate = 0;
   198  cif_conf.truncate = 0;
   199  cif_conf.mono_conv = 0;
   200  
   201  if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
   202  cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_RX;
   203  reg = TEGRA30_I2S_CIF_RX_CTRL;
   204  } else {
   205  cif_conf.direction = TEGRA30_AUDIOCIF_DIRECTION_TX;
   206  reg = TEGRA30_I2S_CIF_TX_CTRL;
   207  }
   208  
   209  i2s->soc_data->set_audio_cif(i2s->regmap, reg, _conf);
   210  
   211  val = (1 << TEGRA30_I2S_OFFSET_RX_DATA_OFFSET_SHIFT) |
   212 

[TRIVIAL RFC PATCH] Kconfigs - reduce use of "depends on EXPERT"

2018-07-28 Thread Joe Perches
Most uses of EXPERT are in the form

bool "something" if EXPERT

but some are

depends on EXPERT

The difference is the the 'depends on' use makes it
easier to select the CONFIG_EXPERT option.

$ git grep "if EXPERT" -- "*/Kconfig*" | wc -l
155
$ git grep "depends on.*EXPERT" -- "*/Kconfig*" | wc -l
26

Some of the 'depends on' uses with EXPERT are more menus
or complex logic with || and can not easily be modified,
but it's perhaps reasonable to modify the simpler ones
to the "if EXPERT" form.
---
 arch/x86/Kconfig.debug |  3 +--
 drivers/char/Kconfig   |  4 ++--
 drivers/gpu/drm/i915/Kconfig.debug |  3 +--
 drivers/gpu/drm/msm/Kconfig|  4 ++--
 drivers/net/wireless/intel/iwlwifi/Kconfig |  4 ++--
 drivers/ssb/Kconfig|  4 ++--
 drivers/video/fbdev/Kconfig|  4 ++--
 init/Kconfig   | 10 --
 kernel/power/Kconfig   |  7 +++
 net/wireless/Kconfig   |  3 +--
 security/Kconfig   |  3 +--
 11 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index c6dd1d980081..f175c00c3786 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -393,8 +393,7 @@ config UNWINDER_FRAME_POINTER
  reliable stack trace (CONFIG_HAVE_RELIABLE_STACKTRACE).
 
 config UNWINDER_GUESS
-   bool "Guess unwinder"
-   depends on EXPERT
+   bool "Guess unwinder" if EXPERT
depends on !STACKDEPOT
---help---
  This option enables the "guess" unwinder for unwinding kernel stack
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index ce277ee0a28a..c1c231a32521 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -52,8 +52,8 @@ source "drivers/tty/serial/Kconfig"
 source "drivers/tty/serdev/Kconfig"
 
 config TTY_PRINTK
-   tristate "TTY driver to output user messages via printk"
-   depends on EXPERT && TTY
+   tristate "TTY driver to output user messages via printk" if EXPERT
+   depends on TTY
default n
---help---
  If you say Y here, the support for writing user messages (i.e.
diff --git a/drivers/gpu/drm/i915/Kconfig.debug 
b/drivers/gpu/drm/i915/Kconfig.debug
index 459f8f88a34c..cbf61c0d3917 100644
--- a/drivers/gpu/drm/i915/Kconfig.debug
+++ b/drivers/gpu/drm/i915/Kconfig.debug
@@ -1,8 +1,7 @@
 config DRM_I915_WERROR
-bool "Force GCC to throw an error instead of a warning when compiling"
+bool "Force GCC to throw an error instead of a warning when compiling" 
if EXPERT
 # As this may inadvertently break the build, only allow the user
 # to shoot oneself in the foot iff they aim really hard
-depends on EXPERT
 # We use the dependency on !COMPILE_TEST to not be enabled in
 # allmodconfig or allyesconfig configurations
 depends on !COMPILE_TEST
diff --git a/drivers/gpu/drm/msm/Kconfig b/drivers/gpu/drm/msm/Kconfig
index 843a9d40c05e..4fe57693005f 100644
--- a/drivers/gpu/drm/msm/Kconfig
+++ b/drivers/gpu/drm/msm/Kconfig
@@ -30,8 +30,8 @@ config DRM_MSM_REGISTER_LOGGING
  logging can be switched on via msm.reglog=y module param.
 
 config DRM_MSM_GPU_SUDO
-   bool "Enable SUDO flag on submits"
-   depends on DRM_MSM && EXPERT
+   bool "Enable SUDO flag on submits" if EXPERT
+   depends on DRM_MSM
default n
help
  Enable userspace that has CAP_SYS_RAWIO to submit GPU commands
diff --git a/drivers/net/wireless/intel/iwlwifi/Kconfig 
b/drivers/net/wireless/intel/iwlwifi/Kconfig
index e5a2fc738ac3..d82d0bdd837e 100644
--- a/drivers/net/wireless/intel/iwlwifi/Kconfig
+++ b/drivers/net/wireless/intel/iwlwifi/Kconfig
@@ -89,8 +89,8 @@ config IWLWIFI_BCAST_FILTERING
  expect incoming broadcasts for their normal operations.
 
 config IWLWIFI_PCIE_RTPM
-   bool "Enable runtime power management mode for PCIe devices"
-   depends on IWLMVM && PM && EXPERT
+   bool "Enable runtime power management mode for PCIe devices" if EXPERT
+   depends on IWLMVM && PM
help
  Say Y here to enable runtime power management for PCIe
  devices.  If enabled, the device will go into low power mode
diff --git a/drivers/ssb/Kconfig b/drivers/ssb/Kconfig
index c574dd210500..e6036784c260 100644
--- a/drivers/ssb/Kconfig
+++ b/drivers/ssb/Kconfig
@@ -90,8 +90,8 @@ config SSB_HOST_SOC
  If unsure, say N
 
 config SSB_SILENT
-   bool "No SSB kernel messages"
-   depends on SSB && EXPERT
+   bool "No SSB kernel messages" if EXPERT
+   depends on SSB
help
  This option turns off all Sonics Silicon Backplane printks.
  Note that you won't be able to identify problems, once
diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig
index 591a13a59787..371c6c6ac414 100644
--- 

[TRIVIAL RFC PATCH] Kconfigs - reduce use of "depends on EXPERT"

2018-07-28 Thread Joe Perches
Most uses of EXPERT are in the form

bool "something" if EXPERT

but some are

depends on EXPERT

The difference is the the 'depends on' use makes it
easier to select the CONFIG_EXPERT option.

$ git grep "if EXPERT" -- "*/Kconfig*" | wc -l
155
$ git grep "depends on.*EXPERT" -- "*/Kconfig*" | wc -l
26

Some of the 'depends on' uses with EXPERT are more menus
or complex logic with || and can not easily be modified,
but it's perhaps reasonable to modify the simpler ones
to the "if EXPERT" form.
---
 arch/x86/Kconfig.debug |  3 +--
 drivers/char/Kconfig   |  4 ++--
 drivers/gpu/drm/i915/Kconfig.debug |  3 +--
 drivers/gpu/drm/msm/Kconfig|  4 ++--
 drivers/net/wireless/intel/iwlwifi/Kconfig |  4 ++--
 drivers/ssb/Kconfig|  4 ++--
 drivers/video/fbdev/Kconfig|  4 ++--
 init/Kconfig   | 10 --
 kernel/power/Kconfig   |  7 +++
 net/wireless/Kconfig   |  3 +--
 security/Kconfig   |  3 +--
 11 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index c6dd1d980081..f175c00c3786 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -393,8 +393,7 @@ config UNWINDER_FRAME_POINTER
  reliable stack trace (CONFIG_HAVE_RELIABLE_STACKTRACE).
 
 config UNWINDER_GUESS
-   bool "Guess unwinder"
-   depends on EXPERT
+   bool "Guess unwinder" if EXPERT
depends on !STACKDEPOT
---help---
  This option enables the "guess" unwinder for unwinding kernel stack
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index ce277ee0a28a..c1c231a32521 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -52,8 +52,8 @@ source "drivers/tty/serial/Kconfig"
 source "drivers/tty/serdev/Kconfig"
 
 config TTY_PRINTK
-   tristate "TTY driver to output user messages via printk"
-   depends on EXPERT && TTY
+   tristate "TTY driver to output user messages via printk" if EXPERT
+   depends on TTY
default n
---help---
  If you say Y here, the support for writing user messages (i.e.
diff --git a/drivers/gpu/drm/i915/Kconfig.debug 
b/drivers/gpu/drm/i915/Kconfig.debug
index 459f8f88a34c..cbf61c0d3917 100644
--- a/drivers/gpu/drm/i915/Kconfig.debug
+++ b/drivers/gpu/drm/i915/Kconfig.debug
@@ -1,8 +1,7 @@
 config DRM_I915_WERROR
-bool "Force GCC to throw an error instead of a warning when compiling"
+bool "Force GCC to throw an error instead of a warning when compiling" 
if EXPERT
 # As this may inadvertently break the build, only allow the user
 # to shoot oneself in the foot iff they aim really hard
-depends on EXPERT
 # We use the dependency on !COMPILE_TEST to not be enabled in
 # allmodconfig or allyesconfig configurations
 depends on !COMPILE_TEST
diff --git a/drivers/gpu/drm/msm/Kconfig b/drivers/gpu/drm/msm/Kconfig
index 843a9d40c05e..4fe57693005f 100644
--- a/drivers/gpu/drm/msm/Kconfig
+++ b/drivers/gpu/drm/msm/Kconfig
@@ -30,8 +30,8 @@ config DRM_MSM_REGISTER_LOGGING
  logging can be switched on via msm.reglog=y module param.
 
 config DRM_MSM_GPU_SUDO
-   bool "Enable SUDO flag on submits"
-   depends on DRM_MSM && EXPERT
+   bool "Enable SUDO flag on submits" if EXPERT
+   depends on DRM_MSM
default n
help
  Enable userspace that has CAP_SYS_RAWIO to submit GPU commands
diff --git a/drivers/net/wireless/intel/iwlwifi/Kconfig 
b/drivers/net/wireless/intel/iwlwifi/Kconfig
index e5a2fc738ac3..d82d0bdd837e 100644
--- a/drivers/net/wireless/intel/iwlwifi/Kconfig
+++ b/drivers/net/wireless/intel/iwlwifi/Kconfig
@@ -89,8 +89,8 @@ config IWLWIFI_BCAST_FILTERING
  expect incoming broadcasts for their normal operations.
 
 config IWLWIFI_PCIE_RTPM
-   bool "Enable runtime power management mode for PCIe devices"
-   depends on IWLMVM && PM && EXPERT
+   bool "Enable runtime power management mode for PCIe devices" if EXPERT
+   depends on IWLMVM && PM
help
  Say Y here to enable runtime power management for PCIe
  devices.  If enabled, the device will go into low power mode
diff --git a/drivers/ssb/Kconfig b/drivers/ssb/Kconfig
index c574dd210500..e6036784c260 100644
--- a/drivers/ssb/Kconfig
+++ b/drivers/ssb/Kconfig
@@ -90,8 +90,8 @@ config SSB_HOST_SOC
  If unsure, say N
 
 config SSB_SILENT
-   bool "No SSB kernel messages"
-   depends on SSB && EXPERT
+   bool "No SSB kernel messages" if EXPERT
+   depends on SSB
help
  This option turns off all Sonics Silicon Backplane printks.
  Note that you won't be able to identify problems, once
diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig
index 591a13a59787..371c6c6ac414 100644
--- 

  1   2   3   4   >