All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: update depracated jump label API
@ 2021-01-11 15:24 Cun Li
  2021-01-11 17:15 ` Vitaly Kuznetsov
  2021-01-13  8:43 ` kernel test robot
  0 siblings, 2 replies; 8+ messages in thread
From: Cun Li @ 2021-01-11 15:24 UTC (permalink / raw)
  To: pbonzini
  Cc: seanjc, vkuznets, wanpengli, jmattson, joro, tglx, mingo, bp,
	x86, hpa, kvm, linux-kernel, Cun Li

The use of 'struct static_key' and 'static_key_false' is
deprecated. Use the new API.

Signed-off-by: Cun Li <cun.jia.li@gmail.com>
---
 arch/x86/kvm/lapic.h         | 6 +++---
 arch/x86/kvm/mmu/mmu_audit.c | 4 ++--
 arch/x86/kvm/x86.c           | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 4fb86e3a9dd3..b7aa76e2678e 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -176,7 +176,7 @@ extern struct static_key kvm_no_apic_vcpu;
 
 static inline bool lapic_in_kernel(struct kvm_vcpu *vcpu)
 {
-	if (static_key_false(&kvm_no_apic_vcpu))
+	if (static_branch_unlikely(&kvm_no_apic_vcpu))
 		return vcpu->arch.apic;
 	return true;
 }
@@ -185,7 +185,7 @@ extern struct static_key_deferred apic_hw_disabled;
 
 static inline int kvm_apic_hw_enabled(struct kvm_lapic *apic)
 {
-	if (static_key_false(&apic_hw_disabled.key))
+	if (static_branch_unlikely(&apic_hw_disabled.key))
 		return apic->vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE;
 	return MSR_IA32_APICBASE_ENABLE;
 }
@@ -194,7 +194,7 @@ extern struct static_key_deferred apic_sw_disabled;
 
 static inline bool kvm_apic_sw_enabled(struct kvm_lapic *apic)
 {
-	if (static_key_false(&apic_sw_disabled.key))
+	if (static_branch_unlikely(&apic_sw_disabled.key))
 		return apic->sw_enabled;
 	return true;
 }
diff --git a/arch/x86/kvm/mmu/mmu_audit.c b/arch/x86/kvm/mmu/mmu_audit.c
index c8d51a37e2ce..8a4b3510151a 100644
--- a/arch/x86/kvm/mmu/mmu_audit.c
+++ b/arch/x86/kvm/mmu/mmu_audit.c
@@ -234,7 +234,7 @@ static void audit_vcpu_spte(struct kvm_vcpu *vcpu)
 }
 
 static bool mmu_audit;
-static struct static_key mmu_audit_key;
+static DEFINE_STATIC_KEY_FALSE(mmu_audit_key);
 
 static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
 {
@@ -250,7 +250,7 @@ static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
 
 static inline void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
 {
-	if (static_key_false((&mmu_audit_key)))
+	if (static_branch_unlikely((&mmu_audit_key)))
 		__kvm_mmu_audit(vcpu, point);
 }
 
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 9a8969a6dd06..b8c05ef26942 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10339,7 +10339,7 @@ bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
 	return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0;
 }
 
-struct static_key kvm_no_apic_vcpu __read_mostly;
+__read_mostly DEFINE_STATIC_KEY_FALSE(kvm_no_apic_vcpu);
 EXPORT_SYMBOL_GPL(kvm_no_apic_vcpu);
 
 void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] KVM: update depracated jump label API
  2021-01-11 15:24 [PATCH] KVM: update depracated jump label API Cun Li
@ 2021-01-11 17:15 ` Vitaly Kuznetsov
  2021-01-16  5:41   ` Cun Li
                     ` (2 more replies)
  2021-01-13  8:43 ` kernel test robot
  1 sibling, 3 replies; 8+ messages in thread
From: Vitaly Kuznetsov @ 2021-01-11 17:15 UTC (permalink / raw)
  To: Cun Li
  Cc: seanjc, wanpengli, jmattson, joro, tglx, mingo, bp, x86, hpa,
	kvm, linux-kernel, Cun Li, pbonzini

Cun Li <cun.jia.li@gmail.com> writes:

> The use of 'struct static_key' and 'static_key_false' is
> deprecated. Use the new API.
>
> Signed-off-by: Cun Li <cun.jia.li@gmail.com>
> ---
>  arch/x86/kvm/lapic.h         | 6 +++---
>  arch/x86/kvm/mmu/mmu_audit.c | 4 ++--
>  arch/x86/kvm/x86.c           | 2 +-
>  3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
> index 4fb86e3a9dd3..b7aa76e2678e 100644
> --- a/arch/x86/kvm/lapic.h
> +++ b/arch/x86/kvm/lapic.h
> @@ -176,7 +176,7 @@ extern struct static_key kvm_no_apic_vcpu;
>  
>  static inline bool lapic_in_kernel(struct kvm_vcpu *vcpu)
>  {
> -	if (static_key_false(&kvm_no_apic_vcpu))
> +	if (static_branch_unlikely(&kvm_no_apic_vcpu))
>  		return vcpu->arch.apic;
>  	return true;
>  }
> @@ -185,7 +185,7 @@ extern struct static_key_deferred apic_hw_disabled;
>  
>  static inline int kvm_apic_hw_enabled(struct kvm_lapic *apic)
>  {
> -	if (static_key_false(&apic_hw_disabled.key))
> +	if (static_branch_unlikely(&apic_hw_disabled.key))
>  		return apic->vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE;
>  	return MSR_IA32_APICBASE_ENABLE;
>  }
> @@ -194,7 +194,7 @@ extern struct static_key_deferred apic_sw_disabled;
>  
>  static inline bool kvm_apic_sw_enabled(struct kvm_lapic *apic)
>  {
> -	if (static_key_false(&apic_sw_disabled.key))
> +	if (static_branch_unlikely(&apic_sw_disabled.key))
>  		return apic->sw_enabled;
>  	return true;
>  }
> diff --git a/arch/x86/kvm/mmu/mmu_audit.c b/arch/x86/kvm/mmu/mmu_audit.c
> index c8d51a37e2ce..8a4b3510151a 100644
> --- a/arch/x86/kvm/mmu/mmu_audit.c
> +++ b/arch/x86/kvm/mmu/mmu_audit.c
> @@ -234,7 +234,7 @@ static void audit_vcpu_spte(struct kvm_vcpu *vcpu)
>  }
>  
>  static bool mmu_audit;
> -static struct static_key mmu_audit_key;
> +static DEFINE_STATIC_KEY_FALSE(mmu_audit_key);
>  
>  static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
>  {
> @@ -250,7 +250,7 @@ static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
>  
>  static inline void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
>  {
> -	if (static_key_false((&mmu_audit_key)))
> +	if (static_branch_unlikely((&mmu_audit_key)))
>  		__kvm_mmu_audit(vcpu, point);
>  }
>  
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 9a8969a6dd06..b8c05ef26942 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -10339,7 +10339,7 @@ bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
>  	return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0;
>  }
>  
> -struct static_key kvm_no_apic_vcpu __read_mostly;
> +__read_mostly DEFINE_STATIC_KEY_FALSE(kvm_no_apic_vcpu);
>  EXPORT_SYMBOL_GPL(kvm_no_apic_vcpu);
>  
>  void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu)

mmu_audit_key can only be true or false so it would also be nice to use 
static_branch_enable()/static_branch_disable() for it and not
static_key_slow_inc()/static_key_slow_dec() we currently use (as it
sounds weird to increment 'false').

kvm_no_apic_vcpu is different, we actually need to increase it with
every vCPU which doesn't have LAPIC but maybe we can at least switch to
static_branch_inc()/static_branch_dec(). It is still weird we initialize
it to 'false' but it seems to be a documented behavior. From
include/linux/jump_label.h:

"... Thus, static_branch_inc() can be thought of as a 'make more true'
 and static_branch_dec() as a 'make more false'"

so .. oh well.

-- 
Vitaly


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] KVM: update depracated jump label API
  2021-01-11 15:24 [PATCH] KVM: update depracated jump label API Cun Li
  2021-01-11 17:15 ` Vitaly Kuznetsov
@ 2021-01-13  8:43 ` kernel test robot
  1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2021-01-13  8:43 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 17666 bytes --]

Hi Cun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on kvm/linux-next]
[also build test ERROR on v5.11-rc3 next-20210113]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Cun-Li/KVM-update-depracated-jump-label-API/20210111-232923
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next
config: x86_64-rhel (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/a7e1eb7a34170e250266db48c133fe37ef1855aa
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Cun-Li/KVM-update-depracated-jump-label-API/20210111-232923
        git checkout a7e1eb7a34170e250266db48c133fe37ef1855aa
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from include/linux/dynamic_debug.h:6,
                    from include/linux/printk.h:409,
                    from include/linux/kernel.h:16,
                    from include/asm-generic/bug.h:20,
                    from arch/x86/include/asm/bug.h:93,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/percpu.h:5,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/x86/kvm/../../../virt/kvm/irqchip.c:15:
   arch/x86/kvm/lapic.h: In function 'lapic_in_kernel':
>> include/linux/jump_label.h:470:40: error: 'struct static_key' has no member named 'key'
     470 |   branch = arch_static_branch_jump(&(x)->key, false);  \
         |                                        ^~
   arch/x86/kvm/lapic.h:179:6: note: in expansion of macro 'static_branch_unlikely'
     179 |  if (static_branch_unlikely(&kvm_no_apic_vcpu))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:472:35: error: 'struct static_key' has no member named 'key'
     472 |   branch = arch_static_branch(&(x)->key, false);   \
         |                                   ^~
   arch/x86/kvm/lapic.h:179:6: note: in expansion of macro 'static_branch_unlikely'
     179 |  if (static_branch_unlikely(&kvm_no_apic_vcpu))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   arch/x86/kvm/lapic.h: In function 'kvm_apic_hw_enabled':
>> include/linux/jump_label.h:470:40: error: 'struct static_key' has no member named 'key'
     470 |   branch = arch_static_branch_jump(&(x)->key, false);  \
         |                                        ^~
   arch/x86/kvm/lapic.h:188:6: note: in expansion of macro 'static_branch_unlikely'
     188 |  if (static_branch_unlikely(&apic_hw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:472:35: error: 'struct static_key' has no member named 'key'
     472 |   branch = arch_static_branch(&(x)->key, false);   \
         |                                   ^~
   arch/x86/kvm/lapic.h:188:6: note: in expansion of macro 'static_branch_unlikely'
     188 |  if (static_branch_unlikely(&apic_hw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   arch/x86/kvm/lapic.h: In function 'kvm_apic_sw_enabled':
>> include/linux/jump_label.h:470:40: error: 'struct static_key' has no member named 'key'
     470 |   branch = arch_static_branch_jump(&(x)->key, false);  \
         |                                        ^~
   arch/x86/kvm/lapic.h:197:6: note: in expansion of macro 'static_branch_unlikely'
     197 |  if (static_branch_unlikely(&apic_sw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:472:35: error: 'struct static_key' has no member named 'key'
     472 |   branch = arch_static_branch(&(x)->key, false);   \
         |                                   ^~
   arch/x86/kvm/lapic.h:197:6: note: in expansion of macro 'static_branch_unlikely'
     197 |  if (static_branch_unlikely(&apic_sw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
--
   In file included from include/linux/dynamic_debug.h:6,
                    from include/linux/printk.h:409,
                    from include/linux/kernel.h:16,
                    from include/asm-generic/bug.h:20,
                    from arch/x86/include/asm/bug.h:93,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/percpu.h:5,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/x86/kvm/x86.c:19:
   arch/x86/kvm/lapic.h: In function 'lapic_in_kernel':
>> include/linux/jump_label.h:470:40: error: 'struct static_key' has no member named 'key'
     470 |   branch = arch_static_branch_jump(&(x)->key, false);  \
         |                                        ^~
   arch/x86/kvm/lapic.h:179:6: note: in expansion of macro 'static_branch_unlikely'
     179 |  if (static_branch_unlikely(&kvm_no_apic_vcpu))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:472:35: error: 'struct static_key' has no member named 'key'
     472 |   branch = arch_static_branch(&(x)->key, false);   \
         |                                   ^~
   arch/x86/kvm/lapic.h:179:6: note: in expansion of macro 'static_branch_unlikely'
     179 |  if (static_branch_unlikely(&kvm_no_apic_vcpu))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   arch/x86/kvm/lapic.h: In function 'kvm_apic_hw_enabled':
>> include/linux/jump_label.h:470:40: error: 'struct static_key' has no member named 'key'
     470 |   branch = arch_static_branch_jump(&(x)->key, false);  \
         |                                        ^~
   arch/x86/kvm/lapic.h:188:6: note: in expansion of macro 'static_branch_unlikely'
     188 |  if (static_branch_unlikely(&apic_hw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:472:35: error: 'struct static_key' has no member named 'key'
     472 |   branch = arch_static_branch(&(x)->key, false);   \
         |                                   ^~
   arch/x86/kvm/lapic.h:188:6: note: in expansion of macro 'static_branch_unlikely'
     188 |  if (static_branch_unlikely(&apic_hw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   arch/x86/kvm/lapic.h: In function 'kvm_apic_sw_enabled':
>> include/linux/jump_label.h:470:40: error: 'struct static_key' has no member named 'key'
     470 |   branch = arch_static_branch_jump(&(x)->key, false);  \
         |                                        ^~
   arch/x86/kvm/lapic.h:197:6: note: in expansion of macro 'static_branch_unlikely'
     197 |  if (static_branch_unlikely(&apic_sw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:472:35: error: 'struct static_key' has no member named 'key'
     472 |   branch = arch_static_branch(&(x)->key, false);   \
         |                                   ^~
   arch/x86/kvm/lapic.h:197:6: note: in expansion of macro 'static_branch_unlikely'
     197 |  if (static_branch_unlikely(&apic_sw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/dynamic_debug.h:6,
                    from include/linux/printk.h:409,
                    from include/linux/kernel.h:16,
                    from include/asm-generic/bug.h:20,
                    from arch/x86/include/asm/bug.h:93,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/percpu.h:5,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/x86/kvm/x86.c:19:
   arch/x86/kvm/x86.c: At top level:
>> arch/x86/kvm/x86.c:10322:39: error: conflicting types for 'kvm_no_apic_vcpu'
   10322 | __read_mostly DEFINE_STATIC_KEY_FALSE(kvm_no_apic_vcpu);
         |                                       ^~~~~~~~~~~~~~~~
   include/linux/jump_label.h:367:26: note: in definition of macro 'DEFINE_STATIC_KEY_FALSE'
     367 |  struct static_key_false name = STATIC_KEY_FALSE_INIT
         |                          ^~~~
   In file included from arch/x86/kvm/cpuid.h:5,
                    from arch/x86/kvm/mmu.h:7,
                    from arch/x86/kvm/x86.c:22:
   arch/x86/kvm/x86.h:297:26: note: previous declaration of 'kvm_no_apic_vcpu' was here
     297 | extern struct static_key kvm_no_apic_vcpu;
         |                          ^~~~~~~~~~~~~~~~
   In file included from include/linux/linkage.h:7,
                    from include/linux/kernel.h:8,
                    from include/asm-generic/bug.h:20,
                    from arch/x86/include/asm/bug.h:93,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/percpu.h:5,
                    from include/linux/context_tracking_state.h:5,
                    from include/linux/hardirq.h:5,
                    from include/linux/kvm_host.h:7,
                    from arch/x86/kvm/x86.c:19:
   arch/x86/kvm/x86.c:10323:19: error: conflicting types for 'kvm_no_apic_vcpu'
   10323 | EXPORT_SYMBOL_GPL(kvm_no_apic_vcpu);
         |                   ^~~~~~~~~~~~~~~~
   include/linux/export.h:98:21: note: in definition of macro '___EXPORT_SYMBOL'
      98 |  extern typeof(sym) sym;       \
         |                     ^~~
   include/linux/export.h:155:34: note: in expansion of macro '__EXPORT_SYMBOL'
     155 | #define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")
         |                                  ^~~~~~~~~~~~~~~
   include/linux/export.h:159:33: note: in expansion of macro '_EXPORT_SYMBOL'
     159 | #define EXPORT_SYMBOL_GPL(sym)  _EXPORT_SYMBOL(sym, "_gpl")
         |                                 ^~~~~~~~~~~~~~
   arch/x86/kvm/x86.c:10323:1: note: in expansion of macro 'EXPORT_SYMBOL_GPL'
   10323 | EXPORT_SYMBOL_GPL(kvm_no_apic_vcpu);
         | ^~~~~~~~~~~~~~~~~
   In file included from arch/x86/kvm/cpuid.h:5,
                    from arch/x86/kvm/mmu.h:7,
                    from arch/x86/kvm/x86.c:22:
   arch/x86/kvm/x86.h:297:26: note: previous declaration of 'kvm_no_apic_vcpu' was here
     297 | extern struct static_key kvm_no_apic_vcpu;
         |                          ^~~~~~~~~~~~~~~~
--
   In file included from include/linux/dynamic_debug.h:6,
                    from include/linux/printk.h:409,
                    from include/linux/kernel.h:16,
                    from include/linux/cpumask.h:10,
                    from include/linux/mm_types_task.h:14,
                    from include/linux/mm_types.h:5,
                    from arch/x86/kvm/irq.h:13,
                    from arch/x86/kvm/mmu/mmu.c:18:
   arch/x86/kvm/lapic.h: In function 'lapic_in_kernel':
>> include/linux/jump_label.h:470:40: error: 'struct static_key' has no member named 'key'
     470 |   branch = arch_static_branch_jump(&(x)->key, false);  \
         |                                        ^~
   arch/x86/kvm/lapic.h:179:6: note: in expansion of macro 'static_branch_unlikely'
     179 |  if (static_branch_unlikely(&kvm_no_apic_vcpu))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:472:35: error: 'struct static_key' has no member named 'key'
     472 |   branch = arch_static_branch(&(x)->key, false);   \
         |                                   ^~
   arch/x86/kvm/lapic.h:179:6: note: in expansion of macro 'static_branch_unlikely'
     179 |  if (static_branch_unlikely(&kvm_no_apic_vcpu))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   arch/x86/kvm/lapic.h: In function 'kvm_apic_hw_enabled':
>> include/linux/jump_label.h:470:40: error: 'struct static_key' has no member named 'key'
     470 |   branch = arch_static_branch_jump(&(x)->key, false);  \
         |                                        ^~
   arch/x86/kvm/lapic.h:188:6: note: in expansion of macro 'static_branch_unlikely'
     188 |  if (static_branch_unlikely(&apic_hw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:472:35: error: 'struct static_key' has no member named 'key'
     472 |   branch = arch_static_branch(&(x)->key, false);   \
         |                                   ^~
   arch/x86/kvm/lapic.h:188:6: note: in expansion of macro 'static_branch_unlikely'
     188 |  if (static_branch_unlikely(&apic_hw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   arch/x86/kvm/lapic.h: In function 'kvm_apic_sw_enabled':
>> include/linux/jump_label.h:470:40: error: 'struct static_key' has no member named 'key'
     470 |   branch = arch_static_branch_jump(&(x)->key, false);  \
         |                                        ^~
   arch/x86/kvm/lapic.h:197:6: note: in expansion of macro 'static_branch_unlikely'
     197 |  if (static_branch_unlikely(&apic_sw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/jump_label.h:472:35: error: 'struct static_key' has no member named 'key'
     472 |   branch = arch_static_branch(&(x)->key, false);   \
         |                                   ^~
   arch/x86/kvm/lapic.h:197:6: note: in expansion of macro 'static_branch_unlikely'
     197 |  if (static_branch_unlikely(&apic_sw_disabled.key))
         |      ^~~~~~~~~~~~~~~~~~~~~~
   In file included from arch/x86/kvm/mmu/mmu.c:1885:
   arch/x86/kvm/mmu/mmu_audit.c: In function 'mmu_audit_enable':
>> arch/x86/kvm/mmu/mmu_audit.c:262:22: error: passing argument 1 of 'static_key_slow_inc' from incompatible pointer type [-Werror=incompatible-pointer-types]
     262 |  static_key_slow_inc(&mmu_audit_key);
         |                      ^~~~~~~~~~~~~~
         |                      |
         |                      struct static_key_false *
   In file included from include/linux/dynamic_debug.h:6,
                    from include/linux/printk.h:409,
                    from include/linux/kernel.h:16,
                    from include/linux/cpumask.h:10,
                    from include/linux/mm_types_task.h:14,
                    from include/linux/mm_types.h:5,
                    from arch/x86/kvm/irq.h:13,
                    from arch/x86/kvm/mmu/mmu.c:18:
   include/linux/jump_label.h:222:52: note: expected 'struct static_key *' but argument is of type 'struct static_key_false *'
     222 | extern void static_key_slow_inc(struct static_key *key);
         |                                 ~~~~~~~~~~~~~~~~~~~^~~
   In file included from arch/x86/kvm/mmu/mmu.c:1885:
   arch/x86/kvm/mmu/mmu_audit.c: In function 'mmu_audit_disable':
>> arch/x86/kvm/mmu/mmu_audit.c:271:22: error: passing argument 1 of 'static_key_slow_dec' from incompatible pointer type [-Werror=incompatible-pointer-types]
     271 |  static_key_slow_dec(&mmu_audit_key);
         |                      ^~~~~~~~~~~~~~
         |                      |
         |                      struct static_key_false *
   In file included from include/linux/dynamic_debug.h:6,
                    from include/linux/printk.h:409,
                    from include/linux/kernel.h:16,
                    from include/linux/cpumask.h:10,
                    from include/linux/mm_types_task.h:14,
                    from include/linux/mm_types.h:5,
                    from arch/x86/kvm/irq.h:13,
                    from arch/x86/kvm/mmu/mmu.c:18:
   include/linux/jump_label.h:223:52: note: expected 'struct static_key *' but argument is of type 'struct static_key_false *'
     223 | extern void static_key_slow_dec(struct static_key *key);
         |                                 ~~~~~~~~~~~~~~~~~~~^~~
   cc1: some warnings being treated as errors


vim +470 include/linux/jump_label.h

11276d5306b8e5b4 Peter Zijlstra 2015-07-24  465  
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  466  #define static_branch_unlikely(x)						\
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  467  ({										\
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  468  	bool branch;								\
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  469  	if (__builtin_types_compatible_p(typeof(*x), struct static_key_true))	\
11276d5306b8e5b4 Peter Zijlstra 2015-07-24 @470  		branch = arch_static_branch_jump(&(x)->key, false);		\
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  471  	else if (__builtin_types_compatible_p(typeof(*x), struct static_key_false)) \
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  472  		branch = arch_static_branch(&(x)->key, false);			\
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  473  	else									\
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  474  		branch = ____wrong_branch_error();				\
81dcf89f03204d7e Peter Zijlstra 2018-01-18  475  	unlikely(branch);							\
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  476  })
11276d5306b8e5b4 Peter Zijlstra 2015-07-24  477  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 45671 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] KVM: update depracated jump label API
  2021-01-11 17:15 ` Vitaly Kuznetsov
@ 2021-01-16  5:41   ` Cun Li
  2021-01-16  5:50   ` [PATCH] KVM: update depracated and inappropriate " Cun Li
  2021-01-26 17:57   ` [PATCH] KVM: update depracated " Paolo Bonzini
  2 siblings, 0 replies; 8+ messages in thread
From: Cun Li @ 2021-01-16  5:41 UTC (permalink / raw)
  To: vkuznets
  Cc: pbonzini, seanjc, wanpengli, jmattson, joro, tglx, mingo, bp,
	x86, hpa, kvm, linux-kernel, Cun Li

Sorry for my late reply. Several final exams have delayed me these days.

Thank you for your detailed advice!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] KVM: update depracated and inappropriate jump label API
  2021-01-11 17:15 ` Vitaly Kuznetsov
  2021-01-16  5:41   ` Cun Li
@ 2021-01-16  5:50   ` Cun Li
  2021-01-19 20:46     ` Sean Christopherson
  2021-01-26 17:57   ` [PATCH] KVM: update depracated " Paolo Bonzini
  2 siblings, 1 reply; 8+ messages in thread
From: Cun Li @ 2021-01-16  5:50 UTC (permalink / raw)
  To: vkuznets
  Cc: pbonzini, seanjc, wanpengli, jmattson, joro, tglx, mingo, bp,
	x86, hpa, kvm, linux-kernel, Cun Li

The use of 'struct static_key' and 'static_key_false' is
deprecated. Use the new API.

mmu_audit_key can only be true or false so it would be nice to use
static_branch_enable()/static_branch_disable() for it and not
static_key_slow_inc()/static_key_slow_dec().

Signed-off-by: Cun Li <cun.jia.li@gmail.com>
---
 arch/x86/kvm/lapic.h         | 6 +++---
 arch/x86/kvm/mmu/mmu_audit.c | 8 ++++----
 arch/x86/kvm/x86.c           | 6 +++---
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 4fb86e3a9dd3..b7aa76e2678e 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -176,7 +176,7 @@ extern struct static_key kvm_no_apic_vcpu;
 
 static inline bool lapic_in_kernel(struct kvm_vcpu *vcpu)
 {
-	if (static_key_false(&kvm_no_apic_vcpu))
+	if (static_branch_unlikely(&kvm_no_apic_vcpu))
 		return vcpu->arch.apic;
 	return true;
 }
@@ -185,7 +185,7 @@ extern struct static_key_deferred apic_hw_disabled;
 
 static inline int kvm_apic_hw_enabled(struct kvm_lapic *apic)
 {
-	if (static_key_false(&apic_hw_disabled.key))
+	if (static_branch_unlikely(&apic_hw_disabled.key))
 		return apic->vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE;
 	return MSR_IA32_APICBASE_ENABLE;
 }
@@ -194,7 +194,7 @@ extern struct static_key_deferred apic_sw_disabled;
 
 static inline bool kvm_apic_sw_enabled(struct kvm_lapic *apic)
 {
-	if (static_key_false(&apic_sw_disabled.key))
+	if (static_branch_unlikely(&apic_sw_disabled.key))
 		return apic->sw_enabled;
 	return true;
 }
diff --git a/arch/x86/kvm/mmu/mmu_audit.c b/arch/x86/kvm/mmu/mmu_audit.c
index c8d51a37e2ce..df3482784aa5 100644
--- a/arch/x86/kvm/mmu/mmu_audit.c
+++ b/arch/x86/kvm/mmu/mmu_audit.c
@@ -234,7 +234,7 @@ static void audit_vcpu_spte(struct kvm_vcpu *vcpu)
 }
 
 static bool mmu_audit;
-static struct static_key mmu_audit_key;
+static DEFINE_STATIC_KEY_FALSE(mmu_audit_key);
 
 static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
 {
@@ -250,7 +250,7 @@ static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
 
 static inline void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
 {
-	if (static_key_false((&mmu_audit_key)))
+	if (static_branch_unlikely((&mmu_audit_key)))
 		__kvm_mmu_audit(vcpu, point);
 }
 
@@ -259,7 +259,7 @@ static void mmu_audit_enable(void)
 	if (mmu_audit)
 		return;
 
-	static_key_slow_inc(&mmu_audit_key);
+	static_branch_enable(&mmu_audit_key);
 	mmu_audit = true;
 }
 
@@ -268,7 +268,7 @@ static void mmu_audit_disable(void)
 	if (!mmu_audit)
 		return;
 
-	static_key_slow_dec(&mmu_audit_key);
+	static_branch_disable(&mmu_audit_key);
 	mmu_audit = false;
 }
 
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 9a8969a6dd06..6f460c3b8fb8 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9955,7 +9955,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 		if (kvm_apicv_activated(vcpu->kvm))
 			vcpu->arch.apicv_active = true;
 	} else
-		static_key_slow_inc(&kvm_no_apic_vcpu);
+		static_branch_inc(&kvm_no_apic_vcpu);
 
 	r = -ENOMEM;
 
@@ -10084,7 +10084,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
 	free_page((unsigned long)vcpu->arch.pio_data);
 	kvfree(vcpu->arch.cpuid_entries);
 	if (!lapic_in_kernel(vcpu))
-		static_key_slow_dec(&kvm_no_apic_vcpu);
+		static_branch_dec(&kvm_no_apic_vcpu);
 }
 
 void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
@@ -10339,7 +10339,7 @@ bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
 	return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0;
 }
 
-struct static_key kvm_no_apic_vcpu __read_mostly;
+__read_mostly DEFINE_STATIC_KEY_FALSE(kvm_no_apic_vcpu);
 EXPORT_SYMBOL_GPL(kvm_no_apic_vcpu);
 
 void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] KVM: update depracated and inappropriate jump label API
  2021-01-16  5:50   ` [PATCH] KVM: update depracated and inappropriate " Cun Li
@ 2021-01-19 20:46     ` Sean Christopherson
  0 siblings, 0 replies; 8+ messages in thread
From: Sean Christopherson @ 2021-01-19 20:46 UTC (permalink / raw)
  To: Cun Li
  Cc: vkuznets, pbonzini, wanpengli, jmattson, joro, tglx, mingo, bp,
	x86, hpa, kvm, linux-kernel

s/depracated/deprecated

And maybe reword the shortlog to be more explicit?  E.g.

  KVM: Stop using deprecated jump label APIs

On Sat, Jan 16, 2021, Cun Li wrote:
> The use of 'struct static_key' and 'static_key_false' is
> deprecated. Use the new API.
> 
> mmu_audit_key can only be true or false so it would be nice to use
> static_branch_enable()/static_branch_disable() for it and not
> static_key_slow_inc()/static_key_slow_dec().

Does anyone even build with CONFIG_KVM_MMU_AUDIT=y, let alone actually use the
auditing capabilities?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] KVM: update depracated jump label API
  2021-01-11 17:15 ` Vitaly Kuznetsov
  2021-01-16  5:41   ` Cun Li
  2021-01-16  5:50   ` [PATCH] KVM: update depracated and inappropriate " Cun Li
@ 2021-01-26 17:57   ` Paolo Bonzini
  2021-01-26 18:51     ` Sean Christopherson
  2 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2021-01-26 17:57 UTC (permalink / raw)
  To: Vitaly Kuznetsov, Cun Li
  Cc: seanjc, wanpengli, jmattson, joro, tglx, mingo, bp, x86, hpa,
	kvm, linux-kernel

On 11/01/21 18:15, Vitaly Kuznetsov wrote:
> kvm_no_apic_vcpu is different, we actually need to increase it with
> every vCPU which doesn't have LAPIC but maybe we can at least switch to
> static_branch_inc()/static_branch_dec(). It is still weird we initialize
> it to 'false'

"kvm_no_apic_vcpu" is badly named.  It reads as "true if no vCPU has 
APIC" but it means "true if some vCPU has no APIC".  The latter is 
obviously false in the beginning, because there is no vCPUs at all.

Perhaps a better name would be "kvm_has_noapic_vcpu" (for once, 
smashingwordstogether is more readable than the alternative).

Paolo

  but it seems to be a documented behavior. From
> include/linux/jump_label.h:
> 
> "... Thus, static_branch_inc() can be thought of as a 'make more true'
>   and static_branch_dec() as a 'make more false'"


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] KVM: update depracated jump label API
  2021-01-26 17:57   ` [PATCH] KVM: update depracated " Paolo Bonzini
@ 2021-01-26 18:51     ` Sean Christopherson
  0 siblings, 0 replies; 8+ messages in thread
From: Sean Christopherson @ 2021-01-26 18:51 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Vitaly Kuznetsov, Cun Li, wanpengli, jmattson, joro, tglx, mingo,
	bp, x86, hpa, kvm, linux-kernel

On Tue, Jan 26, 2021, Paolo Bonzini wrote:
> On 11/01/21 18:15, Vitaly Kuznetsov wrote:
> > kvm_no_apic_vcpu is different, we actually need to increase it with
> > every vCPU which doesn't have LAPIC but maybe we can at least switch to
> > static_branch_inc()/static_branch_dec(). It is still weird we initialize
> > it to 'false'
> 
> "kvm_no_apic_vcpu" is badly named.  It reads as "true if no vCPU has APIC"
> but it means "true if some vCPU has no APIC".  The latter is obviously false
> in the beginning, because there is no vCPUs at all.
> 
> Perhaps a better name would be "kvm_has_noapic_vcpu" (for once,
> smashingwordstogether is more readable than the alternative).

+1

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-01-27  1:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 15:24 [PATCH] KVM: update depracated jump label API Cun Li
2021-01-11 17:15 ` Vitaly Kuznetsov
2021-01-16  5:41   ` Cun Li
2021-01-16  5:50   ` [PATCH] KVM: update depracated and inappropriate " Cun Li
2021-01-19 20:46     ` Sean Christopherson
2021-01-26 17:57   ` [PATCH] KVM: update depracated " Paolo Bonzini
2021-01-26 18:51     ` Sean Christopherson
2021-01-13  8:43 ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.