]> www.infradead.org Git - users/hch/configfs.git/commitdiff
LoongArch: KVM: Add memory barrier before update pmd entry
authorBibo Mao <maobibo@loongson.cn>
Tue, 9 Jul 2024 08:25:51 +0000 (16:25 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Tue, 9 Jul 2024 08:25:51 +0000 (16:25 +0800)
When updating pmd entry such as allocating new pmd page or splitting
huge page into normal page, it is necessary to firstly update all pte
entries, and then update pmd entry.

It is weak order with LoongArch system, there will be problem if other
VCPUs see pmd update firstly while ptes are not updated. Here smp_wmb()
is added to assure this.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kvm/mmu.c

index 5fa8e3b36121606c3165ca70a787f4894d19b529..f1ed1c5296cf8305d8b9c0ad4105ccba28dd84a2 100644 (file)
@@ -163,6 +163,7 @@ static kvm_pte_t *kvm_populate_gpa(struct kvm *kvm,
 
                        child = kvm_mmu_memory_cache_alloc(cache);
                        _kvm_pte_init(child, ctx.invalid_ptes[ctx.level - 1]);
+                       smp_wmb(); /* Make pte visible before pmd */
                        kvm_set_pte(entry, __pa(child));
                } else if (kvm_pte_huge(*entry)) {
                        return entry;
@@ -746,6 +747,7 @@ static kvm_pte_t *kvm_split_huge(struct kvm_vcpu *vcpu, kvm_pte_t *ptep, gfn_t g
                val += PAGE_SIZE;
        }
 
+       smp_wmb(); /* Make pte visible before pmd */
        /* The later kvm_flush_tlb_gpa() will flush hugepage tlb */
        kvm_set_pte(ptep, __pa(child));