Skip to contentSkip to conversation

KVM: x86: Complain about an attempt to change the APIC base address

PATCH Superseded Jim Mattson 2 participants 3 messages Jun 21, 2024 – Jun 25, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86: Complain about an attempt to change the APIC base address

KVM does not support changing the APIC's base address. Prior to commit 3743c2f02517 ("KVM: x86: inhibit APICv/AVIC on changes to APIC ID or APIC base"), it emitted a rate-limited warning about this. Now, it's just silently broken.

Use vcpu_unimpl() to complain about this unsupported operation. Even a rate-limited error message is better than complete silence.

Fixes 3743c2f02517 ("KVM: x86: inhibit APICv/AVIC on changes to APIC ID or APIC base")
---
 arch/x86/kvm/lapic.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/lapic.c +2 -0
index acd7d48100a1..5284dddab337 100644
@@ -2583,6 +2583,8 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value)
 
 	if ((value & MSR_IA32_APICBASE_ENABLE) &&
 	     apic->base_address != APIC_DEFAULT_PHYS_BASE) {
+		vcpu_unimpl(vcpu, "APIC base %#llx is not %#llx",
+			    apic->base_address, APIC_DEFAULT_PHYS_BASE);
 		kvm_set_apicv_inhibit(apic->vcpu->kvm,
 				      APICV_INHIBIT_REASON_APIC_BASE_MODIFIED);
 	}
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Jim,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kvm/queue]
[also build test WARNING on linus/master v6.10-rc5 next-20240625] [cannot apply to kvm/linux-next]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jim-Mattson/KVM-x86-Complain-about-an-attempt-to-change-the-APIC-base-address/20240625-181629
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
patch link:    https://lore.kernel.org/r/20240621224946.4083742-1-jmattson%40google.com
patch subject: [PATCH] KVM: x86: Complain about an attempt to change the APIC base address
config: i386-randconfig-141-20240626 (https://download.01.org/0day-ci/archive/20240626/[email protected]/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240626/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/asm-generic/bug.h:22,

                    from arch/x86/include/asm/bug.h:87,
                    from include/linux/bug.h:5,
                    from include/linux/alloc_tag.h:8,
                    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/lapic.c:20:
   arch/x86/kvm/lapic.c: In function 'kvm_lapic_set_base':
   include/linux/kern_levels.h:5:25: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 5 has type 'long unsigned int' [-Wformat=]
       5 | #define KERN_SOH        "\001"          /* ASCII Start Of Header */
         |                         ^~~~~~
   include/linux/printk.h:436:25: note: in definition of macro 'printk_index_wrap'
     436 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                         ^~~~
   include/linux/printk.h:658:17: note: in expansion of macro 'printk'
     658 |                 printk(fmt, ##__VA_ARGS__);                             \
         |                 ^~~~~~
   include/linux/printk.h:672:9: note: in expansion of macro 'printk_ratelimited'
     672 |         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/kern_levels.h:11:25: note: in expansion of macro 'KERN_SOH'
      11 | #define KERN_ERR        KERN_SOH "3"    /* error conditions */
         |                         ^~~~~~~~
   include/linux/printk.h:672:28: note: in expansion of macro 'KERN_ERR'
     672 |         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
         |                            ^~~~~~~~
   include/linux/kvm_host.h:855:9: note: in expansion of macro 'pr_err_ratelimited'
     855 |         pr_err_ratelimited("kvm [%i]: " fmt, \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/kvm_host.h:860:9: note: in expansion of macro 'kvm_pr_unimpl'
     860 |         kvm_pr_unimpl("vcpu%i, guest rIP: 0x%lx " fmt,                  \
         |         ^~~~~~~~~~~~~
   arch/x86/kvm/lapic.c:2586:17: note: in expansion of macro 'vcpu_unimpl'
    2586 |                 vcpu_unimpl(vcpu, "APIC base %#llx is not %#llx",
         |                 ^~~~~~~~~~~
>> include/linux/kern_levels.h:5:25: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 6 has type 'unsigned int' [-Wformat=]
       5 | #define KERN_SOH        "\001"          /* ASCII Start Of Header */
         |                         ^~~~~~
   include/linux/printk.h:436:25: note: in definition of macro 'printk_index_wrap'
     436 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                         ^~~~
   include/linux/printk.h:658:17: note: in expansion of macro 'printk'
     658 |                 printk(fmt, ##__VA_ARGS__);                             \
         |                 ^~~~~~
   include/linux/printk.h:672:9: note: in expansion of macro 'printk_ratelimited'
     672 |         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/kern_levels.h:11:25: note: in expansion of macro 'KERN_SOH'
      11 | #define KERN_ERR        KERN_SOH "3"    /* error conditions */
         |                         ^~~~~~~~
   include/linux/printk.h:672:28: note: in expansion of macro 'KERN_ERR'
     672 |         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
         |                            ^~~~~~~~
   include/linux/kvm_host.h:855:9: note: in expansion of macro 'pr_err_ratelimited'
     855 |         pr_err_ratelimited("kvm [%i]: " fmt, \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/kvm_host.h:860:9: note: in expansion of macro 'kvm_pr_unimpl'
     860 |         kvm_pr_unimpl("vcpu%i, guest rIP: 0x%lx " fmt,                  \
         |         ^~~~~~~~~~~~~
   arch/x86/kvm/lapic.c:2586:17: note: in expansion of macro 'vcpu_unimpl'
    2586 |                 vcpu_unimpl(vcpu, "APIC base %#llx is not %#llx",
         |                 ^~~~~~~~~~~

vim +5 include/linux/kern_levels.h

314ba3520e513a Joe Perches 2012-07-30 4
04d2c8c83d0e3a Joe Perches 2012-07-30 @5 #define KERN_SOH "\001" /* ASCII Start Of Header */
04d2c8c83d0e3a Joe Perches 2012-07-30 6 #define KERN_SOH_ASCII '\001'
04d2c8c83d0e3a Joe Perches 2012-07-30 7

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Jim Mattson
kernel test robot noticed the following build warnings:

Hi Jim,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kvm/queue]
[also build test WARNING on linus/master v6.10-rc5 next-20240625] [cannot apply to kvm/linux-next]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jim-Mattson/KVM-x86-Complain-about-an-attempt-to-change-the-APIC-base-address/20240625-181629
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
patch link:    https://lore.kernel.org/r/20240621224946.4083742-1-jmattson%40google.com
patch subject: [PATCH] KVM: x86: Complain about an attempt to change the APIC base address
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20240626/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240626/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> arch/x86/kvm/lapic.c:2587:8: warning: format specifies type 'unsigned long long' but the argument has type 'unsigned long' [-Wformat]
    2586 |                 vcpu_unimpl(vcpu, "APIC base %#llx is not %#llx",
         |                                              ~~~~~
         |                                              %#lx
    2587 |                             apic->base_address, APIC_DEFAULT_PHYS_BASE);
         |                             ^~~~~~~~~~~~~~~~~~
   include/linux/kvm_host.h:861:44: note: expanded from macro 'vcpu_unimpl'
     860 |         kvm_pr_unimpl("vcpu%i, guest rIP: 0x%lx " fmt,                  \
         |                                                   ~~~
     861 |                         (vcpu)->vcpu_id, kvm_rip_read(vcpu), ## __VA_ARGS__)
         |                                                                 ^~~~~~~~~~~
   include/linux/kvm_host.h:856:33: note: expanded from macro 'kvm_pr_unimpl'
     855 |         pr_err_ratelimited("kvm [%i]: " fmt, \
         |                                         ~~~
     856 |                            task_tgid_nr(current), ## __VA_ARGS__)
         |                                                      ^~~~~~~~~~~
   include/linux/printk.h:672:45: note: expanded from macro 'pr_err_ratelimited'
     672 |         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
         |                                            ~~~     ^~~~~~~~~~~
   include/linux/printk.h:658:17: note: expanded from macro 'printk_ratelimited'
     658 |                 printk(fmt, ##__VA_ARGS__);                             \
         |                        ~~~    ^~~~~~~~~~~
   include/linux/printk.h:464:60: note: expanded from macro 'printk'
     464 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
         |                                                     ~~~    ^~~~~~~~~~~
   include/linux/printk.h:436:19: note: expanded from macro 'printk_index_wrap'
     436 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                         ~~~~    ^~~~~~~~~~~
>> arch/x86/kvm/lapic.c:2587:28: warning: format specifies type 'unsigned long long' but the argument has type 'unsigned int' [-Wformat]
    2586 |                 vcpu_unimpl(vcpu, "APIC base %#llx is not %#llx",
         |                                                           ~~~~~
         |                                                           %#x
    2587 |                             apic->base_address, APIC_DEFAULT_PHYS_BASE);
         |                                                 ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/kvm_host.h:861:44: note: expanded from macro 'vcpu_unimpl'
     860 |         kvm_pr_unimpl("vcpu%i, guest rIP: 0x%lx " fmt,                  \
         |                                                   ~~~
     861 |                         (vcpu)->vcpu_id, kvm_rip_read(vcpu), ## __VA_ARGS__)
         |                                                                 ^~~~~~~~~~~
   include/linux/kvm_host.h:856:33: note: expanded from macro 'kvm_pr_unimpl'
     855 |         pr_err_ratelimited("kvm [%i]: " fmt, \
         |                                         ~~~
     856 |                            task_tgid_nr(current), ## __VA_ARGS__)
         |                                                      ^~~~~~~~~~~
   include/linux/printk.h:672:45: note: expanded from macro 'pr_err_ratelimited'
     672 |         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
         |                                            ~~~     ^~~~~~~~~~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/printk.h:464:60: note: expanded from macro 'printk'
     464 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
         |                                                     ~~~    ^~~~~~~~~~~
   include/linux/printk.h:436:19: note: expanded from macro 'printk_index_wrap'
     436 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                         ~~~~    ^~~~~~~~~~~
   arch/x86/include/asm/apicdef.h:15:33: note: expanded from macro 'APIC_DEFAULT_PHYS_BASE'
      15 | #define APIC_DEFAULT_PHYS_BASE          0xfee00000
         |                                         ^~~~~~~~~~

2 warnings generated.

vim +2587 arch/x86/kvm/lapic.c

2542
2543 void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value)
2544 {
2545 u64 old_value = vcpu->arch.apic_base;
2546 struct kvm_lapic *apic = vcpu->arch.apic;
2547
2548 vcpu->arch.apic_base = value;
2549
2550 if ((old_value ^ value) & MSR_IA32_APICBASE_ENABLE)
2551 kvm_update_cpuid_runtime(vcpu);
2552
2553 if (!apic)
2554 return;
2555
2556 /* update jump label if enable bit changes */
2557 if ((old_value ^ value) & MSR_IA32_APICBASE_ENABLE) {
2558 if (value & MSR_IA32_APICBASE_ENABLE) {
2559 kvm_apic_set_xapic_id(apic, vcpu->vcpu_id);
2560 static_branch_slow_dec_deferred(&apic_hw_disabled);
2561 /* Check if there are APF page ready requests pending */
2562 kvm_make_request(KVM_REQ_APF_READY, vcpu);
2563 } else {
2564 static_branch_inc(&apic_hw_disabled.key);
2565 atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
2566 }
2567 }
2568
2569 if ((old_value ^ value) & X2APIC_ENABLE) {
2570 if (value & X2APIC_ENABLE)
2571 kvm_apic_set_x2apic_id(apic, vcpu->vcpu_id);
2572 else if (value & MSR_IA32_APICBASE_ENABLE)
2573 kvm_apic_set_xapic_id(apic, vcpu->vcpu_id);
2574 }
2575
2576 if ((old_value ^ value) & (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE)) {
2577 kvm_make_request(KVM_REQ_APICV_UPDATE, vcpu);
2578 static_call_cond(kvm_x86_set_virtual_apic_mode)(vcpu);
2579 }
2580
2581 apic->base_address = apic->vcpu->arch.apic_base &
2582 MSR_IA32_APICBASE_BASE;
2583
2584 if ((value & MSR_IA32_APICBASE_ENABLE) &&
2585 apic->base_address != APIC_DEFAULT_PHYS_BASE) {
2586 vcpu_unimpl(vcpu, "APIC base %#llx is not %#llx",

> 2587				    apic->base_address, APIC_DEFAULT_PHYS_BASE);

2588 kvm_set_apicv_inhibit(apic->vcpu->kvm,
2589 APICV_INHIBIT_REASON_APIC_BASE_MODIFIED);
2590 }
2591 }
2592

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki