arch/x86/kvm/mmu/tdp_mmu.c:388:49: sparse: sparse: incorrect type in argument 2 (different address spaces)

From: kernel test robot
Date: Sat Feb 27 2021 - 16:40:07 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 5695e51619745d4fe3ec2506a2f0cd982c5e27a4
commit: 7cca2d0b7e7d9f3cd740d41afdc00051c9b508a0 KVM: x86/mmu: Protect TDP MMU page table memory with RCU
date: 3 weeks ago
config: x86_64-randconfig-s022-20210228 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.3-241-geaceeafa-dirty
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7cca2d0b7e7d9f3cd740d41afdc00051c9b508a0
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 7cca2d0b7e7d9f3cd740d41afdc00051c9b508a0
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64

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


"sparse warnings: (new ones prefixed by >>)"
>> arch/x86/kvm/mmu/tdp_mmu.c:388:49: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected unsigned long long [usertype] *pt @@ got unsigned long long [noderef] [usertype] __rcu * @@
arch/x86/kvm/mmu/tdp_mmu.c:388:49: sparse: expected unsigned long long [usertype] *pt
arch/x86/kvm/mmu/tdp_mmu.c:388:49: sparse: got unsigned long long [noderef] [usertype] __rcu *
>> arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected unsigned long long [usertype] *root_pt @@ got unsigned long long [noderef] [usertype] __rcu * @@
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: expected unsigned long long [usertype] *root_pt
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: got unsigned long long [noderef] [usertype] __rcu *
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected unsigned long long [usertype] *root_pt @@ got unsigned long long [noderef] [usertype] __rcu * @@
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: expected unsigned long long [usertype] *root_pt
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: got unsigned long long [noderef] [usertype] __rcu *
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected unsigned long long [usertype] *root_pt @@ got unsigned long long [noderef] [usertype] __rcu * @@
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: expected unsigned long long [usertype] *root_pt
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: got unsigned long long [noderef] [usertype] __rcu *
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected unsigned long long [usertype] *root_pt @@ got unsigned long long [noderef] [usertype] __rcu * @@
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: expected unsigned long long [usertype] *root_pt
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: got unsigned long long [noderef] [usertype] __rcu *
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected unsigned long long [usertype] *root_pt @@ got unsigned long long [noderef] [usertype] __rcu * @@
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: expected unsigned long long [usertype] *root_pt
arch/x86/kvm/mmu/tdp_mmu.c:506:51: sparse: got unsigned long long [noderef] [usertype] __rcu *
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt
>> arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected unsigned long long [usertype] *sptep @@ got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt @@
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: expected unsigned long long [usertype] *sptep
arch/x86/kvm/mmu/tdp_mmu.c:421:49: sparse: got unsigned long long [noderef] [usertype] __rcu *[usertype] root_pt

vim +388 arch/x86/kvm/mmu/tdp_mmu.c

a066e61f13cf4b Ben Gardon 2021年02月02日 302
2f2fad0897cbfd Ben Gardon 2020年10月14日 303 /**
2f2fad0897cbfd Ben Gardon 2020年10月14日 304 * handle_changed_spte - handle bookkeeping associated with an SPTE change
2f2fad0897cbfd Ben Gardon 2020年10月14日 305 * @kvm: kvm instance
2f2fad0897cbfd Ben Gardon 2020年10月14日 306 * @as_id: the address space of the paging structure the SPTE was a part of
2f2fad0897cbfd Ben Gardon 2020年10月14日 307 * @gfn: the base GFN that was mapped by the SPTE
2f2fad0897cbfd Ben Gardon 2020年10月14日 308 * @old_spte: The value of the SPTE before the change
2f2fad0897cbfd Ben Gardon 2020年10月14日 309 * @new_spte: The value of the SPTE after the change
2f2fad0897cbfd Ben Gardon 2020年10月14日 310 * @level: the level of the PT the SPTE is part of in the paging structure
2f2fad0897cbfd Ben Gardon 2020年10月14日 311 *
2f2fad0897cbfd Ben Gardon 2020年10月14日 312 * Handle bookkeeping that might result from the modification of a SPTE.
2f2fad0897cbfd Ben Gardon 2020年10月14日 313 * This function must be called for all TDP SPTE modifications.
2f2fad0897cbfd Ben Gardon 2020年10月14日 314 */
2f2fad0897cbfd Ben Gardon 2020年10月14日 315 static void __handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
2f2fad0897cbfd Ben Gardon 2020年10月14日 316 u64 old_spte, u64 new_spte, int level)
2f2fad0897cbfd Ben Gardon 2020年10月14日 317 {
2f2fad0897cbfd Ben Gardon 2020年10月14日 318 bool was_present = is_shadow_present_pte(old_spte);
2f2fad0897cbfd Ben Gardon 2020年10月14日 319 bool is_present = is_shadow_present_pte(new_spte);
2f2fad0897cbfd Ben Gardon 2020年10月14日 320 bool was_leaf = was_present && is_last_spte(old_spte, level);
2f2fad0897cbfd Ben Gardon 2020年10月14日 321 bool is_leaf = is_present && is_last_spte(new_spte, level);
2f2fad0897cbfd Ben Gardon 2020年10月14日 322 bool pfn_changed = spte_to_pfn(old_spte) != spte_to_pfn(new_spte);
2f2fad0897cbfd Ben Gardon 2020年10月14日 323
2f2fad0897cbfd Ben Gardon 2020年10月14日 324 WARN_ON(level > PT64_ROOT_MAX_LEVEL);
2f2fad0897cbfd Ben Gardon 2020年10月14日 325 WARN_ON(level < PG_LEVEL_4K);
764388ce598f0c Sean Christopherson 2020年10月23日 326 WARN_ON(gfn & (KVM_PAGES_PER_HPAGE(level) - 1));
2f2fad0897cbfd Ben Gardon 2020年10月14日 327
2f2fad0897cbfd Ben Gardon 2020年10月14日 328 /*
2f2fad0897cbfd Ben Gardon 2020年10月14日 329 * If this warning were to trigger it would indicate that there was a
2f2fad0897cbfd Ben Gardon 2020年10月14日 330 * missing MMU notifier or a race with some notifier handler.
2f2fad0897cbfd Ben Gardon 2020年10月14日 331 * A present, leaf SPTE should never be directly replaced with another
2f2fad0897cbfd Ben Gardon 2020年10月14日 332 * present leaf SPTE pointing to a differnt PFN. A notifier handler
2f2fad0897cbfd Ben Gardon 2020年10月14日 333 * should be zapping the SPTE before the main MM's page table is
2f2fad0897cbfd Ben Gardon 2020年10月14日 334 * changed, or the SPTE should be zeroed, and the TLBs flushed by the
2f2fad0897cbfd Ben Gardon 2020年10月14日 335 * thread before replacement.
2f2fad0897cbfd Ben Gardon 2020年10月14日 336 */
2f2fad0897cbfd Ben Gardon 2020年10月14日 337 if (was_leaf && is_leaf && pfn_changed) {
2f2fad0897cbfd Ben Gardon 2020年10月14日 338 pr_err("Invalid SPTE change: cannot replace a present leaf\n"
2f2fad0897cbfd Ben Gardon 2020年10月14日 339 "SPTE with another present leaf SPTE mapping a\n"
2f2fad0897cbfd Ben Gardon 2020年10月14日 340 "different PFN!\n"
2f2fad0897cbfd Ben Gardon 2020年10月14日 341 "as_id: %d gfn: %llx old_spte: %llx new_spte: %llx level: %d",
2f2fad0897cbfd Ben Gardon 2020年10月14日 342 as_id, gfn, old_spte, new_spte, level);
2f2fad0897cbfd Ben Gardon 2020年10月14日 343
2f2fad0897cbfd Ben Gardon 2020年10月14日 344 /*
2f2fad0897cbfd Ben Gardon 2020年10月14日 345 * Crash the host to prevent error propagation and guest data
2f2fad0897cbfd Ben Gardon 2020年10月14日 346 * courruption.
2f2fad0897cbfd Ben Gardon 2020年10月14日 347 */
2f2fad0897cbfd Ben Gardon 2020年10月14日 348 BUG();
2f2fad0897cbfd Ben Gardon 2020年10月14日 349 }
2f2fad0897cbfd Ben Gardon 2020年10月14日 350
2f2fad0897cbfd Ben Gardon 2020年10月14日 351 if (old_spte == new_spte)
2f2fad0897cbfd Ben Gardon 2020年10月14日 352 return;
2f2fad0897cbfd Ben Gardon 2020年10月14日 353
b9a98c3437e353 Ben Gardon 2020年10月27日 354 trace_kvm_tdp_mmu_spte_changed(as_id, gfn, level, old_spte, new_spte);
b9a98c3437e353 Ben Gardon 2020年10月27日 355
2f2fad0897cbfd Ben Gardon 2020年10月14日 356 /*
2f2fad0897cbfd Ben Gardon 2020年10月14日 357 * The only times a SPTE should be changed from a non-present to
2f2fad0897cbfd Ben Gardon 2020年10月14日 358 * non-present state is when an MMIO entry is installed/modified/
2f2fad0897cbfd Ben Gardon 2020年10月14日 359 * removed. In that case, there is nothing to do here.
2f2fad0897cbfd Ben Gardon 2020年10月14日 360 */
2f2fad0897cbfd Ben Gardon 2020年10月14日 361 if (!was_present && !is_present) {
2f2fad0897cbfd Ben Gardon 2020年10月14日 362 /*
2f2fad0897cbfd Ben Gardon 2020年10月14日 363 * If this change does not involve a MMIO SPTE, it is
2f2fad0897cbfd Ben Gardon 2020年10月14日 364 * unexpected. Log the change, though it should not impact the
2f2fad0897cbfd Ben Gardon 2020年10月14日 365 * guest since both the former and current SPTEs are nonpresent.
2f2fad0897cbfd Ben Gardon 2020年10月14日 366 */
2f2fad0897cbfd Ben Gardon 2020年10月14日 367 if (WARN_ON(!is_mmio_spte(old_spte) && !is_mmio_spte(new_spte)))
2f2fad0897cbfd Ben Gardon 2020年10月14日 368 pr_err("Unexpected SPTE change! Nonpresent SPTEs\n"
2f2fad0897cbfd Ben Gardon 2020年10月14日 369 "should not be replaced with another,\n"
2f2fad0897cbfd Ben Gardon 2020年10月14日 370 "different nonpresent SPTE, unless one or both\n"
2f2fad0897cbfd Ben Gardon 2020年10月14日 371 "are MMIO SPTEs.\n"
2f2fad0897cbfd Ben Gardon 2020年10月14日 372 "as_id: %d gfn: %llx old_spte: %llx new_spte: %llx level: %d",
2f2fad0897cbfd Ben Gardon 2020年10月14日 373 as_id, gfn, old_spte, new_spte, level);
2f2fad0897cbfd Ben Gardon 2020年10月14日 374 return;
2f2fad0897cbfd Ben Gardon 2020年10月14日 375 }
2f2fad0897cbfd Ben Gardon 2020年10月14日 376
2f2fad0897cbfd Ben Gardon 2020年10月14日 377
2f2fad0897cbfd Ben Gardon 2020年10月14日 378 if (was_leaf && is_dirty_spte(old_spte) &&
2f2fad0897cbfd Ben Gardon 2020年10月14日 379 (!is_dirty_spte(new_spte) || pfn_changed))
2f2fad0897cbfd Ben Gardon 2020年10月14日 380 kvm_set_pfn_dirty(spte_to_pfn(old_spte));
2f2fad0897cbfd Ben Gardon 2020年10月14日 381
2f2fad0897cbfd Ben Gardon 2020年10月14日 382 /*
2f2fad0897cbfd Ben Gardon 2020年10月14日 383 * Recursively handle child PTs if the change removed a subtree from
2f2fad0897cbfd Ben Gardon 2020年10月14日 384 * the paging structure.
2f2fad0897cbfd Ben Gardon 2020年10月14日 385 */
a066e61f13cf4b Ben Gardon 2021年02月02日 386 if (was_present && !was_leaf && (pfn_changed || !is_present))
a066e61f13cf4b Ben Gardon 2021年02月02日 387 handle_removed_tdp_mmu_page(kvm,
a066e61f13cf4b Ben Gardon 2021年02月02日 @388 spte_to_child_pt(old_spte, level));
2f2fad0897cbfd Ben Gardon 2020年10月14日 389 }
2f2fad0897cbfd Ben Gardon 2020年10月14日 390
2f2fad0897cbfd Ben Gardon 2020年10月14日 391 static void handle_changed_spte(struct kvm *kvm, int as_id, gfn_t gfn,
2f2fad0897cbfd Ben Gardon 2020年10月14日 392 u64 old_spte, u64 new_spte, int level)
2f2fad0897cbfd Ben Gardon 2020年10月14日 393 {
2f2fad0897cbfd Ben Gardon 2020年10月14日 394 __handle_changed_spte(kvm, as_id, gfn, old_spte, new_spte, level);
f8e144971c6834 Ben Gardon 2020年10月14日 395 handle_changed_spte_acc_track(old_spte, new_spte, level);
a6a0b05da9f37f Ben Gardon 2020年10月14日 396 handle_changed_spte_dirty_log(kvm, as_id, gfn, old_spte,
a6a0b05da9f37f Ben Gardon 2020年10月14日 397 new_spte, level);
2f2fad0897cbfd Ben Gardon 2020年10月14日 398 }
faaf05b00aecdb Ben Gardon 2020年10月14日 399
fe43fa2f407b9d Ben Gardon 2021年02月02日 400 /*
fe43fa2f407b9d Ben Gardon 2021年02月02日 401 * __tdp_mmu_set_spte - Set a TDP MMU SPTE and handle the associated bookkeeping
fe43fa2f407b9d Ben Gardon 2021年02月02日 402 * @kvm: kvm instance
fe43fa2f407b9d Ben Gardon 2021年02月02日 403 * @iter: a tdp_iter instance currently on the SPTE that should be set
fe43fa2f407b9d Ben Gardon 2021年02月02日 404 * @new_spte: The value the SPTE should be set to
fe43fa2f407b9d Ben Gardon 2021年02月02日 405 * @record_acc_track: Notify the MM subsystem of changes to the accessed state
fe43fa2f407b9d Ben Gardon 2021年02月02日 406 * of the page. Should be set unless handling an MMU
fe43fa2f407b9d Ben Gardon 2021年02月02日 407 * notifier for access tracking. Leaving record_acc_track
fe43fa2f407b9d Ben Gardon 2021年02月02日 408 * unset in that case prevents page accesses from being
fe43fa2f407b9d Ben Gardon 2021年02月02日 409 * double counted.
fe43fa2f407b9d Ben Gardon 2021年02月02日 410 * @record_dirty_log: Record the page as dirty in the dirty bitmap if
fe43fa2f407b9d Ben Gardon 2021年02月02日 411 * appropriate for the change being made. Should be set
fe43fa2f407b9d Ben Gardon 2021年02月02日 412 * unless performing certain dirty logging operations.
fe43fa2f407b9d Ben Gardon 2021年02月02日 413 * Leaving record_dirty_log unset in that case prevents page
fe43fa2f407b9d Ben Gardon 2021年02月02日 414 * writes from being double counted.
fe43fa2f407b9d Ben Gardon 2021年02月02日 415 */
f8e144971c6834 Ben Gardon 2020年10月14日 416 static inline void __tdp_mmu_set_spte(struct kvm *kvm, struct tdp_iter *iter,
a6a0b05da9f37f Ben Gardon 2020年10月14日 417 u64 new_spte, bool record_acc_track,
a6a0b05da9f37f Ben Gardon 2020年10月14日 418 bool record_dirty_log)
faaf05b00aecdb Ben Gardon 2020年10月14日 419 {
7cca2d0b7e7d9f Ben Gardon 2021年02月02日 420 tdp_ptep_t root_pt = tdp_iter_root_pt(iter);
faaf05b00aecdb Ben Gardon 2020年10月14日 @421 struct kvm_mmu_page *root = sptep_to_sp(root_pt);
faaf05b00aecdb Ben Gardon 2020年10月14日 422 int as_id = kvm_mmu_page_as_id(root);
faaf05b00aecdb Ben Gardon 2020年10月14日 423
3a9a4aa5657471 Ben Gardon 2021年02月02日 424 lockdep_assert_held(&kvm->mmu_lock);
3a9a4aa5657471 Ben Gardon 2021年02月02日 425
7cca2d0b7e7d9f Ben Gardon 2021年02月02日 426 WRITE_ONCE(*rcu_dereference(iter->sptep), new_spte);
faaf05b00aecdb Ben Gardon 2020年10月14日 427
f8e144971c6834 Ben Gardon 2020年10月14日 428 __handle_changed_spte(kvm, as_id, iter->gfn, iter->old_spte, new_spte,
faaf05b00aecdb Ben Gardon 2020年10月14日 429 iter->level);
f8e144971c6834 Ben Gardon 2020年10月14日 430 if (record_acc_track)
f8e144971c6834 Ben Gardon 2020年10月14日 431 handle_changed_spte_acc_track(iter->old_spte, new_spte,
f8e144971c6834 Ben Gardon 2020年10月14日 432 iter->level);
a6a0b05da9f37f Ben Gardon 2020年10月14日 433 if (record_dirty_log)
a6a0b05da9f37f Ben Gardon 2020年10月14日 434 handle_changed_spte_dirty_log(kvm, as_id, iter->gfn,
a6a0b05da9f37f Ben Gardon 2020年10月14日 435 iter->old_spte, new_spte,
a6a0b05da9f37f Ben Gardon 2020年10月14日 436 iter->level);
f8e144971c6834 Ben Gardon 2020年10月14日 437 }
f8e144971c6834 Ben Gardon 2020年10月14日 438
f8e144971c6834 Ben Gardon 2020年10月14日 439 static inline void tdp_mmu_set_spte(struct kvm *kvm, struct tdp_iter *iter,
f8e144971c6834 Ben Gardon 2020年10月14日 440 u64 new_spte)
f8e144971c6834 Ben Gardon 2020年10月14日 441 {
a6a0b05da9f37f Ben Gardon 2020年10月14日 442 __tdp_mmu_set_spte(kvm, iter, new_spte, true, true);
f8e144971c6834 Ben Gardon 2020年10月14日 443 }
f8e144971c6834 Ben Gardon 2020年10月14日 444
f8e144971c6834 Ben Gardon 2020年10月14日 445 static inline void tdp_mmu_set_spte_no_acc_track(struct kvm *kvm,
f8e144971c6834 Ben Gardon 2020年10月14日 446 struct tdp_iter *iter,
f8e144971c6834 Ben Gardon 2020年10月14日 447 u64 new_spte)
f8e144971c6834 Ben Gardon 2020年10月14日 448 {
a6a0b05da9f37f Ben Gardon 2020年10月14日 449 __tdp_mmu_set_spte(kvm, iter, new_spte, false, true);
a6a0b05da9f37f Ben Gardon 2020年10月14日 450 }
a6a0b05da9f37f Ben Gardon 2020年10月14日 451
a6a0b05da9f37f Ben Gardon 2020年10月14日 452 static inline void tdp_mmu_set_spte_no_dirty_log(struct kvm *kvm,
a6a0b05da9f37f Ben Gardon 2020年10月14日 453 struct tdp_iter *iter,
a6a0b05da9f37f Ben Gardon 2020年10月14日 454 u64 new_spte)
a6a0b05da9f37f Ben Gardon 2020年10月14日 455 {
a6a0b05da9f37f Ben Gardon 2020年10月14日 456 __tdp_mmu_set_spte(kvm, iter, new_spte, true, false);
faaf05b00aecdb Ben Gardon 2020年10月14日 457 }
faaf05b00aecdb Ben Gardon 2020年10月14日 458
faaf05b00aecdb Ben Gardon 2020年10月14日 459 #define tdp_root_for_each_pte(_iter, _root, _start, _end) \
faaf05b00aecdb Ben Gardon 2020年10月14日 460 for_each_tdp_pte(_iter, _root->spt, _root->role.level, _start, _end)
faaf05b00aecdb Ben Gardon 2020年10月14日 461
f8e144971c6834 Ben Gardon 2020年10月14日 462 #define tdp_root_for_each_leaf_pte(_iter, _root, _start, _end) \
f8e144971c6834 Ben Gardon 2020年10月14日 463 tdp_root_for_each_pte(_iter, _root, _start, _end) \
f8e144971c6834 Ben Gardon 2020年10月14日 464 if (!is_shadow_present_pte(_iter.old_spte) || \
f8e144971c6834 Ben Gardon 2020年10月14日 465 !is_last_spte(_iter.old_spte, _iter.level)) \
f8e144971c6834 Ben Gardon 2020年10月14日 466 continue; \
f8e144971c6834 Ben Gardon 2020年10月14日 467 else
f8e144971c6834 Ben Gardon 2020年10月14日 468
bb18842e21111a Ben Gardon 2020年10月14日 469 #define tdp_mmu_for_each_pte(_iter, _mmu, _start, _end) \
bb18842e21111a Ben Gardon 2020年10月14日 470 for_each_tdp_pte(_iter, __va(_mmu->root_hpa), \
bb18842e21111a Ben Gardon 2020年10月14日 471 _mmu->shadow_root_level, _start, _end)
bb18842e21111a Ben Gardon 2020年10月14日 472
e28a436ca4f653 Ben Gardon 2021年02月02日 473 /*
e28a436ca4f653 Ben Gardon 2021年02月02日 474 * Yield if the MMU lock is contended or this thread needs to return control
e28a436ca4f653 Ben Gardon 2021年02月02日 475 * to the scheduler.
e28a436ca4f653 Ben Gardon 2021年02月02日 476 *
e139a34ef9d562 Ben Gardon 2021年02月02日 477 * If this function should yield and flush is set, it will perform a remote
e139a34ef9d562 Ben Gardon 2021年02月02日 478 * TLB flush before yielding.
e139a34ef9d562 Ben Gardon 2021年02月02日 479 *
e28a436ca4f653 Ben Gardon 2021年02月02日 480 * If this function yields, it will also reset the tdp_iter's walk over the
ed5e484b79e8a9 Ben Gardon 2021年02月02日 481 * paging structure and the calling function should skip to the next
ed5e484b79e8a9 Ben Gardon 2021年02月02日 482 * iteration to allow the iterator to continue its traversal from the
ed5e484b79e8a9 Ben Gardon 2021年02月02日 483 * paging structure root.
e28a436ca4f653 Ben Gardon 2021年02月02日 484 *
e28a436ca4f653 Ben Gardon 2021年02月02日 485 * Return true if this function yielded and the iterator's traversal was reset.
e28a436ca4f653 Ben Gardon 2021年02月02日 486 * Return false if a yield was not needed.
e28a436ca4f653 Ben Gardon 2021年02月02日 487 */
e139a34ef9d562 Ben Gardon 2021年02月02日 488 static inline bool tdp_mmu_iter_cond_resched(struct kvm *kvm,
e139a34ef9d562 Ben Gardon 2021年02月02日 489 struct tdp_iter *iter, bool flush)
a6a0b05da9f37f Ben Gardon 2020年10月14日 490 {
ed5e484b79e8a9 Ben Gardon 2021年02月02日 491 /* Ensure forward progress has been made before yielding. */
ed5e484b79e8a9 Ben Gardon 2021年02月02日 492 if (iter->next_last_level_gfn == iter->yielded_gfn)
ed5e484b79e8a9 Ben Gardon 2021年02月02日 493 return false;
ed5e484b79e8a9 Ben Gardon 2021年02月02日 494
a6a0b05da9f37f Ben Gardon 2020年10月14日 495 if (need_resched() || spin_needbreak(&kvm->mmu_lock)) {
7cca2d0b7e7d9f Ben Gardon 2021年02月02日 496 rcu_read_unlock();
7cca2d0b7e7d9f Ben Gardon 2021年02月02日 497
e139a34ef9d562 Ben Gardon 2021年02月02日 498 if (flush)
e139a34ef9d562 Ben Gardon 2021年02月02日 499 kvm_flush_remote_tlbs(kvm);
e139a34ef9d562 Ben Gardon 2021年02月02日 500
a6a0b05da9f37f Ben Gardon 2020年10月14日 501 cond_resched_lock(&kvm->mmu_lock);
7cca2d0b7e7d9f Ben Gardon 2021年02月02日 502 rcu_read_lock();
ed5e484b79e8a9 Ben Gardon 2021年02月02日 503
ed5e484b79e8a9 Ben Gardon 2021年02月02日 504 WARN_ON(iter->gfn > iter->next_last_level_gfn);
ed5e484b79e8a9 Ben Gardon 2021年02月02日 505
ed5e484b79e8a9 Ben Gardon 2021年02月02日 @506 tdp_iter_start(iter, iter->pt_path[iter->root_level - 1],
ed5e484b79e8a9 Ben Gardon 2021年02月02日 507 iter->root_level, iter->min_level,
ed5e484b79e8a9 Ben Gardon 2021年02月02日 508 iter->next_last_level_gfn);
ed5e484b79e8a9 Ben Gardon 2021年02月02日 509
e28a436ca4f653 Ben Gardon 2021年02月02日 510 return true;
a6a0b05da9f37f Ben Gardon 2020年10月14日 511 }
e28a436ca4f653 Ben Gardon 2021年02月02日 512
e28a436ca4f653 Ben Gardon 2021年02月02日 513 return false;
a6a0b05da9f37f Ben Gardon 2020年10月14日 514 }
a6a0b05da9f37f Ben Gardon 2020年10月14日 515

:::::: The code at line 388 was first introduced by commit
:::::: a066e61f13cf4b17d043ad8bea0cdde2b1e5ee49 KVM: x86/mmu: Factor out handling of removed page tables

:::::: TO: Ben Gardon <bgardon@xxxxxxxxxx>
:::::: CC: Paolo Bonzini <pbonzini@xxxxxxxxxx>

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

Attachment: .config.gz
Description: application/gzip


AltStyle によって変換されたページ (->オリジナル) /