Skip to content

Commit b19ee2f

Browse files
anadavrkrcmar
authored andcommitted
KVM: x86: avoid write-tearing of TDP
In theory, nothing prevents the compiler from write-tearing PTEs, or split PTE writes. These partially-modified PTEs can be fetched by other cores and cause mayhem. I have not really encountered such case in real-life, but it does seem possible. For example, the compiler may try to do something creative for kvm_set_pte_rmapp() and perform multiple writes to the PTE. Signed-off-by: Nadav Amit <[email protected]> Signed-off-by: Radim Krčmář <[email protected]>
1 parent 13e98fd commit b19ee2f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/x86/kvm/mmu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,12 @@ static gfn_t pse36_gfn_delta(u32 gpte)
336336
#ifdef CONFIG_X86_64
337337
static void __set_spte(u64 *sptep, u64 spte)
338338
{
339-
*sptep = spte;
339+
WRITE_ONCE(*sptep, spte);
340340
}
341341

342342
static void __update_clear_spte_fast(u64 *sptep, u64 spte)
343343
{
344-
*sptep = spte;
344+
WRITE_ONCE(*sptep, spte);
345345
}
346346

347347
static u64 __update_clear_spte_slow(u64 *sptep, u64 spte)
@@ -390,7 +390,7 @@ static void __set_spte(u64 *sptep, u64 spte)
390390
*/
391391
smp_wmb();
392392

393-
ssptep->spte_low = sspte.spte_low;
393+
WRITE_ONCE(ssptep->spte_low, sspte.spte_low);
394394
}
395395

396396
static void __update_clear_spte_fast(u64 *sptep, u64 spte)
@@ -400,7 +400,7 @@ static void __update_clear_spte_fast(u64 *sptep, u64 spte)
400400
ssptep = (union split_spte *)sptep;
401401
sspte = (union split_spte)spte;
402402

403-
ssptep->spte_low = sspte.spte_low;
403+
WRITE_ONCE(ssptep->spte_low, sspte.spte_low);
404404

405405
/*
406406
* If we map the spte from present to nonpresent, we should clear

0 commit comments

Comments
 (0)