ept: Put locks around ept_get_entry
PATCH 1/1 ept: Put locks around ept_get_entry
There's a subtle race in ept_get_entry, such that if tries to read an entry that ept_set_entry is modifying, it gets neither the old entry nor the new entry, but empty. In the case of multi-cpu populate-on-demand guests, this manifests as a guest crash when one vcpu tries to read a page which another page is trying to populate, and ept_get_entry returns p2m_mmio_dm.
This bug can also be fixed by making both ept_set_entry and ept_next_level access-once (i.e., ept_next_level reads full ept_entry and then works with local value; ept_set_entry construct the entry locally and then sets it in one write). But there doesn't seem to be any major performance implications of just making ept_get_entry use locks; so the simpler, the better.
xen/arch/x86/mm/hap/p2m-ept.c +6 -0
@@ -431,6 +431,10 @@int i;int ret =0 ;mfn_t mfn =_mfn (INVALID_MFN ); +int do_locking = !p2m_locked_by_me (d->arch.p2m); + +if ( do_locking ) +p2m_lock (d->arch.p2m); *t = p2m_mmio_dm;
@@ -507,6 +511,8 @@ } out: +if ( do_locking ) +p2m_unlock (d->arch.p2m);unmap_domain_page (table);return mfn; }
Quoted 7 lines · On Friday 27 August 2010 13:23:57 George Dunlap wrote:
There's a subtle race in
ept_get_entry, such that if tries to read an entry thatept_set_entryis modifying, it gets neither the old entry nor the new entry, but empty. In the case of multi-cpu populate-on-demand guests, this manifests as a guest crash when one vcpu tries to read a page which another page is trying to populate, andept_get_entryreturnsp2m_mmio_dm.
Quoted 8 lines
This bug can also be fixed by making both
ept_set_entryandept_next_levelaccess-once (i.e.,ept_next_levelreads fullept_entryand then works with local value;ept_set_entryconstruct the entry locally and then sets it in one write). But there doesn't seem to be any major performance implications of just makingept_get_entryuse locks; so the simpler, the better.Signed-off-by George Dunlap <[email protected]>
Please use p2m_get_hostp2m(d) instead of d->arch.p2m.
Christoph
Quoted 28 lines
diff -r
3c4c3d48a835-re17c8f37a2c2xen/arch/x86/mm/hap/p2m-ept.cxen/arch/x86/mm/hap/p2m-ept.c +6
-0@@ -431,6 +431,10 @@int i;int ret =0 ;mfn_t mfn =_mfn (INVALID_MFN ); +int do_locking = !p2m_locked_by_me (d->arch.p2m); + +if ( do_locking ) +p2m_lock (d->arch.p2m); *t = p2m_mmio_dm;@@ -507,6 +511,8 @@ } out: +if ( do_locking ) +p2m_unlock (d->arch.p2m);unmap_domain_page (table);return mfn; }_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Signature · 6 lines
---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
Quoted 1 line · Christoph Egger
Please use
p2m_get_hostp2m(d)instead ofd->arch.p2m.
...or, just use the p2m variable which was passed as a parameter to the function. :-)
Sorry, I wrote this patch for XenServer (using 3.4), and didn't take a close look. New patch on the way...
-George
Quoted 49 lines
Christoph
Quoted 24 lines
diff -r
3c4c3d48a835-re17c8f37a2c2xen/arch/x86/mm/hap/p2m-ept.cxen/arch/x86/mm/hap/p2m-ept.c Fri Aug 27 12:23:27 2010 +0100 renamed from xen/arch/x86/mm/hap/p2m-ept.c Thu Aug 26 11:16:56 2010 +0100 +4
-0@@ -431,6 +431,10 @@ int i; int ret = 0; mfn_t mfn = _mfn(INVALID_MFN); + int do_locking = !p2m_locked_by_me(d->arch.p2m); + + if ( do_locking ) + p2m_lock(d->arch.p2m); *t = p2m_mmio_dm;@@ -507,6 +511,8 @@ }out:
+ if (do_locking)
+ p2m_unlock(d->arch.p2m);
unmap_domain_page(table);
return mfn;
}Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel--
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 7 lines · On Friday 27 August 2010 13:58:44 George Dunlap wrote:
On Fri, Aug 27, 2010 at 12:38 PM, Christoph Egger
Quoted 1 line · <[email protected]> wrote:
Please use
p2m_get_hostp2m(d)instead ofd->arch.p2m....or, just use the p2m variable which was passed as a parameter to the function. :-)
That's even better. The function defintion isn't visible in the hunk.
Christoph
Quoted 29 lines
Sorry, I wrote this patch for XenServer (using 3.4), and didn't take a close look. New patch on the way...
-GeorgeQuoted 25 lines
Christoph
Quoted 23 lines
diff -r
3c4c3d48a835-re17c8f37a2c2xen/arch/x86/mm/hap/p2m-ept.cxen/arch/x86/mm/hap/p2m-ept.c Fri Aug 27 12:23:27 2010 +0100 renamed from xen/arch/x86/mm/hap/p2m-ept.c Thu Aug 26 11:16:56 2010 +0100 +4
-0@@ -431,6 +431,10 @@ int i; int ret = 0; mfn_t mfn = _mfn(INVALID_MFN); + int do_locking = !p2m_locked_by_me(d->arch.p2m); + + if ( do_locking ) + p2m_lock(d->arch.p2m); *t = p2m_mmio_dm;@@ -507,6 +511,8 @@ }out:
+ if (do_locking)
+ p2m_unlock(d->arch.p2m);
unmap_domain_page(table);
return mfn;
}
Signature · 6 lines
---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632