tree: https://github.com/intel/tdx.git kvm-upstream-workaround head: 699e64cb199ffac8cf4c8eff2e96fed94fcf5a0b commit: 60ecd050492a8dc393e7e2be3a2e8ad8b7856f99 [122/350] KVM: Add functions to set GFN to private or shared config: x86_64-rhel-8.3 compiler: gcc-11 (Debian 11.3.0-5) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel/tdx/commit/60ecd050492a8dc393e7e2be3a2e8ad8b7856f99 git remote add intel-tdx https://github.com/intel/tdx.git git fetch --no-tags intel-tdx kvm-upstream-workaround git checkout 60ecd050492a8dc393e7e2be3a2e8ad8b7856f99 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash arch/x86/kvm/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot All error/warnings (new ones prefixed by >>): In file included from include/linux/list_lru.h:14, from include/linux/fs.h:13, from include/linux/huge_mm.h:8, from include/linux/mm.h:703, from include/linux/kvm_host.h:16, from arch/x86/kvm/irq.h:15, from arch/x86/kvm/mmu/mmu.c:18: arch/x86/kvm/mmu/mmu.c: In function '__mem_attr_is_mixed': >> arch/x86/kvm/mmu/mmu.c:7098:27: error: 'struct kvm' has no member named 'mem_attr_array' 7098 | XA_STATE(xas, &kvm->mem_attr_array, start); | ^~ include/linux/xarray.h:1348:15: note: in definition of macro '__XA_STATE' 1348 | .xa = array, \ | ^~~~~ arch/x86/kvm/mmu/mmu.c:7098:9: note: in expansion of macro 'XA_STATE' 7098 | XA_STATE(xas, &kvm->mem_attr_array, start); | ^~~~~~~~ arch/x86/kvm/mmu/mmu.c: In function 'mem_attr_is_mixed': arch/x86/kvm/mmu/mmu.c:7143:29: error: 'struct kvm' has no member named 'mem_attr_array' 7143 | entry = xa_load(&kvm->mem_attr_array, start); | ^~ arch/x86/kvm/mmu/mmu.c:7150:33: error: 'struct kvm' has no member named 'mem_attr_array' 7150 | if (xa_load(&kvm->mem_attr_array, gfn) != entry) { | ^~ arch/x86/kvm/mmu/mmu.c: At top level: >> arch/x86/kvm/mmu/mmu.c:7194:6: warning: no previous prototype for 'kvm_arch_update_mem_attr' [-Wmissing-prototypes] 7194 | void kvm_arch_update_mem_attr(struct kvm *kvm, unsigned int attr, | ^~~~~~~~~~~~~~~~~~~~~~~~ In file included from include/linux/printk.h:10, from include/linux/kernel.h:29, 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/mmu/mmu.c: In function 'kvm_arch_update_mem_attr': >> arch/x86/kvm/mmu/mmu.c:7203:29: error: 'KVM_MEM_ATTR_PRIVATE' undeclared (first use in this function); did you mean 'KVM_MEM_PRIVATE'? 7203 | WARN_ONCE(!(attr & (KVM_MEM_ATTR_PRIVATE | KVM_MEM_ATTR_SHARED)), | ^~~~~~~~~~~~~~~~~~~~ include/linux/once_lite.h:28:41: note: in definition of macro 'DO_ONCE_LITE_IF' 28 | bool __ret_do_once = !!(condition); \ | ^~~~~~~~~ arch/x86/kvm/mmu/mmu.c:7203:9: note: in expansion of macro 'WARN_ONCE' 7203 | WARN_ONCE(!(attr & (KVM_MEM_ATTR_PRIVATE | KVM_MEM_ATTR_SHARED)), | ^~~~~~~~~ arch/x86/kvm/mmu/mmu.c:7203:29: note: each undeclared identifier is reported only once for each function it appears in 7203 | WARN_ONCE(!(attr & (KVM_MEM_ATTR_PRIVATE | KVM_MEM_ATTR_SHARED)), | ^~~~~~~~~~~~~~~~~~~~ include/linux/once_lite.h:28:41: note: in definition of macro 'DO_ONCE_LITE_IF' 28 | bool __ret_do_once = !!(condition); \ | ^~~~~~~~~ arch/x86/kvm/mmu/mmu.c:7203:9: note: in expansion of macro 'WARN_ONCE' 7203 | WARN_ONCE(!(attr & (KVM_MEM_ATTR_PRIVATE | KVM_MEM_ATTR_SHARED)), | ^~~~~~~~~ >> arch/x86/kvm/mmu/mmu.c:7203:52: error: 'KVM_MEM_ATTR_SHARED' undeclared (first use in this function) 7203 | WARN_ONCE(!(attr & (KVM_MEM_ATTR_PRIVATE | KVM_MEM_ATTR_SHARED)), | ^~~~~~~~~~~~~~~~~~~ include/linux/once_lite.h:28:41: note: in definition of macro 'DO_ONCE_LITE_IF' 28 | bool __ret_do_once = !!(condition); \ | ^~~~~~~~~ arch/x86/kvm/mmu/mmu.c:7203:9: note: in expansion of macro 'WARN_ONCE' 7203 | WARN_ONCE(!(attr & (KVM_MEM_ATTR_PRIVATE | KVM_MEM_ATTR_SHARED)), | ^~~~~~~~~ vim +7098 arch/x86/kvm/mmu/mmu.c d80e3cfb012774 Isaku Yamahata 2022-09-29 7095 d80e3cfb012774 Isaku Yamahata 2022-09-29 7096 static bool __mem_attr_is_mixed(struct kvm *kvm, gfn_t start, gfn_t end) fab0f69e33de02 Chao Peng 2022-09-15 7097 { fab0f69e33de02 Chao Peng 2022-09-15 @7098 XA_STATE(xas, &kvm->mem_attr_array, start); d80e3cfb012774 Isaku Yamahata 2022-09-29 7099 bool mixed = false; fab0f69e33de02 Chao Peng 2022-09-15 7100 gfn_t gfn = start; d80e3cfb012774 Isaku Yamahata 2022-09-29 7101 void *s_entry; fab0f69e33de02 Chao Peng 2022-09-15 7102 void *entry; fab0f69e33de02 Chao Peng 2022-09-15 7103 fab0f69e33de02 Chao Peng 2022-09-15 7104 rcu_read_lock(); d80e3cfb012774 Isaku Yamahata 2022-09-29 7105 s_entry = xas_load(&xas); d80e3cfb012774 Isaku Yamahata 2022-09-29 7106 entry = s_entry; fab0f69e33de02 Chao Peng 2022-09-15 7107 while (gfn < end) { fab0f69e33de02 Chao Peng 2022-09-15 7108 if (xas_retry(&xas, entry)) fab0f69e33de02 Chao Peng 2022-09-15 7109 continue; fab0f69e33de02 Chao Peng 2022-09-15 7110 fab0f69e33de02 Chao Peng 2022-09-15 7111 KVM_BUG_ON(gfn != xas.xa_index, kvm); fab0f69e33de02 Chao Peng 2022-09-15 7112 d80e3cfb012774 Isaku Yamahata 2022-09-29 7113 entry = xas_next(&xas); d80e3cfb012774 Isaku Yamahata 2022-09-29 7114 if (entry != s_entry) { fab0f69e33de02 Chao Peng 2022-09-15 7115 mixed = true; d80e3cfb012774 Isaku Yamahata 2022-09-29 7116 break; fab0f69e33de02 Chao Peng 2022-09-15 7117 } fab0f69e33de02 Chao Peng 2022-09-15 7118 gfn++; fab0f69e33de02 Chao Peng 2022-09-15 7119 } fab0f69e33de02 Chao Peng 2022-09-15 7120 rcu_read_unlock(); fab0f69e33de02 Chao Peng 2022-09-15 7121 return mixed; fab0f69e33de02 Chao Peng 2022-09-15 7122 } fab0f69e33de02 Chao Peng 2022-09-15 7123 d80e3cfb012774 Isaku Yamahata 2022-09-29 7124 static bool mem_attr_is_mixed(struct kvm *kvm, d80e3cfb012774 Isaku Yamahata 2022-09-29 7125 struct kvm_memory_slot *slot, int level, d80e3cfb012774 Isaku Yamahata 2022-09-29 7126 gfn_t start, gfn_t end) fab0f69e33de02 Chao Peng 2022-09-15 7127 { d80e3cfb012774 Isaku Yamahata 2022-09-29 7128 struct kvm_lpage_info *child_linfo; d80e3cfb012774 Isaku Yamahata 2022-09-29 7129 unsigned long child_pages; d80e3cfb012774 Isaku Yamahata 2022-09-29 7130 bool mixed = false; d80e3cfb012774 Isaku Yamahata 2022-09-29 7131 unsigned long gfn; d80e3cfb012774 Isaku Yamahata 2022-09-29 7132 void *entry; d80e3cfb012774 Isaku Yamahata 2022-09-29 7133 d80e3cfb012774 Isaku Yamahata 2022-09-29 7134 if (WARN_ON_ONCE(level == PG_LEVEL_4K)) d80e3cfb012774 Isaku Yamahata 2022-09-29 7135 return false; d80e3cfb012774 Isaku Yamahata 2022-09-29 7136 d80e3cfb012774 Isaku Yamahata 2022-09-29 7137 if (level == PG_LEVEL_2M) d80e3cfb012774 Isaku Yamahata 2022-09-29 7138 return __mem_attr_is_mixed(kvm, start, end); d80e3cfb012774 Isaku Yamahata 2022-09-29 7139 d80e3cfb012774 Isaku Yamahata 2022-09-29 7140 /* This assumes that level - 1 is already updated. */ d80e3cfb012774 Isaku Yamahata 2022-09-29 7141 rcu_read_lock(); d80e3cfb012774 Isaku Yamahata 2022-09-29 7142 child_pages = KVM_PAGES_PER_HPAGE(level - 1); d80e3cfb012774 Isaku Yamahata 2022-09-29 7143 entry = xa_load(&kvm->mem_attr_array, start); d80e3cfb012774 Isaku Yamahata 2022-09-29 7144 for (gfn = start; gfn < end; gfn += child_pages) { d80e3cfb012774 Isaku Yamahata 2022-09-29 7145 child_linfo = lpage_info_slot(gfn, slot, level - 1); d80e3cfb012774 Isaku Yamahata 2022-09-29 7146 if (child_linfo->disallow_lpage & KVM_LPAGE_PRIVATE_SHARED_MIXED) { d80e3cfb012774 Isaku Yamahata 2022-09-29 7147 mixed = true; d80e3cfb012774 Isaku Yamahata 2022-09-29 7148 break; d80e3cfb012774 Isaku Yamahata 2022-09-29 7149 } d80e3cfb012774 Isaku Yamahata 2022-09-29 7150 if (xa_load(&kvm->mem_attr_array, gfn) != entry) { d80e3cfb012774 Isaku Yamahata 2022-09-29 7151 mixed = true; d80e3cfb012774 Isaku Yamahata 2022-09-29 7152 break; d80e3cfb012774 Isaku Yamahata 2022-09-29 7153 } d80e3cfb012774 Isaku Yamahata 2022-09-29 7154 } d80e3cfb012774 Isaku Yamahata 2022-09-29 7155 rcu_read_unlock(); d80e3cfb012774 Isaku Yamahata 2022-09-29 7156 return mixed; fab0f69e33de02 Chao Peng 2022-09-15 7157 } fab0f69e33de02 Chao Peng 2022-09-15 7158 fab0f69e33de02 Chao Peng 2022-09-15 7159 static void update_mem_lpage_info(struct kvm *kvm, fab0f69e33de02 Chao Peng 2022-09-15 7160 struct kvm_memory_slot *slot, fab0f69e33de02 Chao Peng 2022-09-15 7161 unsigned int attr, fab0f69e33de02 Chao Peng 2022-09-15 7162 gfn_t start, gfn_t end) fab0f69e33de02 Chao Peng 2022-09-15 7163 { fab0f69e33de02 Chao Peng 2022-09-15 7164 unsigned long lpage_start, lpage_end; fab0f69e33de02 Chao Peng 2022-09-15 7165 unsigned long gfn, pages, mask; fab0f69e33de02 Chao Peng 2022-09-15 7166 int level; fab0f69e33de02 Chao Peng 2022-09-15 7167 fab0f69e33de02 Chao Peng 2022-09-15 7168 for (level = PG_LEVEL_2M; level <= KVM_MAX_HUGEPAGE_LEVEL; level++) { fab0f69e33de02 Chao Peng 2022-09-15 7169 pages = KVM_PAGES_PER_HPAGE(level); fab0f69e33de02 Chao Peng 2022-09-15 7170 mask = ~(pages - 1); fab0f69e33de02 Chao Peng 2022-09-15 7171 lpage_start = start & mask; fab0f69e33de02 Chao Peng 2022-09-15 7172 lpage_end = (end - 1) & mask; fab0f69e33de02 Chao Peng 2022-09-15 7173 fab0f69e33de02 Chao Peng 2022-09-15 7174 /* fab0f69e33de02 Chao Peng 2022-09-15 7175 * We only need to scan the head and tail page, for middle pages fab0f69e33de02 Chao Peng 2022-09-15 7176 * we know they are not mixed. fab0f69e33de02 Chao Peng 2022-09-15 7177 */ fab0f69e33de02 Chao Peng 2022-09-15 7178 update_mixed(lpage_info_slot(lpage_start, slot, level), d80e3cfb012774 Isaku Yamahata 2022-09-29 7179 mem_attr_is_mixed(kvm, slot, level, d80e3cfb012774 Isaku Yamahata 2022-09-29 7180 lpage_start, lpage_start + pages)); fab0f69e33de02 Chao Peng 2022-09-15 7181 fab0f69e33de02 Chao Peng 2022-09-15 7182 if (lpage_start == lpage_end) fab0f69e33de02 Chao Peng 2022-09-15 7183 return; fab0f69e33de02 Chao Peng 2022-09-15 7184 fab0f69e33de02 Chao Peng 2022-09-15 7185 for (gfn = lpage_start + pages; gfn < lpage_end; gfn += pages) fab0f69e33de02 Chao Peng 2022-09-15 7186 update_mixed(lpage_info_slot(gfn, slot, level), false); fab0f69e33de02 Chao Peng 2022-09-15 7187 fab0f69e33de02 Chao Peng 2022-09-15 7188 update_mixed(lpage_info_slot(lpage_end, slot, level), d80e3cfb012774 Isaku Yamahata 2022-09-29 7189 mem_attr_is_mixed(kvm, slot, level, d80e3cfb012774 Isaku Yamahata 2022-09-29 7190 lpage_end, lpage_end + pages)); fab0f69e33de02 Chao Peng 2022-09-15 7191 } fab0f69e33de02 Chao Peng 2022-09-15 7192 } fab0f69e33de02 Chao Peng 2022-09-15 7193 fab0f69e33de02 Chao Peng 2022-09-15 @7194 void kvm_arch_update_mem_attr(struct kvm *kvm, unsigned int attr, fab0f69e33de02 Chao Peng 2022-09-15 7195 gfn_t start, gfn_t end) fab0f69e33de02 Chao Peng 2022-09-15 7196 { fab0f69e33de02 Chao Peng 2022-09-15 7197 struct kvm_memory_slot *slot; fab0f69e33de02 Chao Peng 2022-09-15 7198 struct kvm_memslots *slots; fab0f69e33de02 Chao Peng 2022-09-15 7199 struct kvm_memslot_iter iter; d80e3cfb012774 Isaku Yamahata 2022-09-29 7200 int idx; fab0f69e33de02 Chao Peng 2022-09-15 7201 int i; fab0f69e33de02 Chao Peng 2022-09-15 7202 fab0f69e33de02 Chao Peng 2022-09-15 @7203 WARN_ONCE(!(attr & (KVM_MEM_ATTR_PRIVATE | KVM_MEM_ATTR_SHARED)), :::::: The code at line 7098 was first introduced by commit :::::: fab0f69e33de02a86f43e8ed45f22163db4ec4a0 KVM: Update lpage info when private/shared memory are mixed :::::: TO: Chao Peng :::::: CC: Isaku Yamahata -- 0-DAY CI Kernel Test Service https://01.org/lkp