From: Dan Magenheimer Subject: RE: Re: xen crash in tmem: checking a xen pfn for domain ownership Date: Mon, 20 Sep 2010 16:03:52 -0700 (PDT) Message-ID: <12d0043a-2042-4939-9489-8ec8a50ea785@default> References: <4C9726890200007800017A42@vpn.id2.novell.com C8BCCFFD.23806%keir.fraser@eu.citrix.com 5c35f0dd-2f25-4843-8b8b-f6c596e7d2c3@default> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="__128502389314526335abhmt004" Return-path: In-Reply-To: <5c35f0dd-2f25-4843-8b8b-f6c596e7d2c3@default> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser , Jan Beulich Cc: Xen-devel List-Id: xen-devel@lists.xenproject.org --__128502389314526335abhmt004 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Wow, gfn_to_mfn() really is a no-op for the pv case. I thought you meant that it didn't do any translation, but it appears it also doesn't even set the return value to INVALID_MFN, so for pv I have to add a separate check for mfn_valid() to see if it is even a valid Xen mfn! THAT was what was causing the crash. Also, it appears that gfn_to_mfn_unshare is not suitable for tmem... it appears the existing code checks for "must_succeed" but gives no indication of success if must_succeed is NOT set but mem_sharing_unshare_page fails, correct? If I do plan to write to the page but I am willing to accept failure if the page is shared (since tmem is resilient to this scenario), it appears I will have to add a new variation of gfn_to_mfn_unshare. Or maybe I should just overload must_succeed, and if must_succeed is 2 and unsharing fails, return INVALID_MFN? P.S. Here's what the relevant tmem code looks like now (below and attached). Quick review appreciated. static inline void *cli_get_page(tmem_cli_mfn_t cmfn, unsigned long *pcli_m= fn, pfp_t **pcli_pfp, bool_t cli_write) { unsigned long xmfn; p2m_type_t t; struct page_info *page; int ret; if ( is_hvm_domain(current->domain) ) { xmfn =3D mfn_x(gfn_to_mfn_unshare(current->domain, cmfn, &t, 2)); if (t !=3D p2m_ram_rw || xmfn =3D=3D INVALID_MFN) return NULL; } else { xmfn =3D cmfn; if (!mfn_valid(xmfn)) return NULL; } page =3D mfn_to_page(xmfn); if ( cli_write ) ret =3D get_page_and_type(page, current->domain, PGT_writable_page)= ; else ret =3D get_page(page, current->domain); if ( ret <=3D 0 ) return NULL; *pcli_mfn =3D xmfn; *pcli_pfp =3D (pfp_t *)page; return map_domain_page(xmfn); } static inline void cli_put_page(void *cli_va, pfp_t *cli_pfp, unsigned long cli_mfn, bool_t mark_dirty) { if ( mark_dirty ) paging_mark_dirty(current->domain,cli_mfn); put_page((struct page_info *)cli_pfp); unmap_domain_page(cli_va); } > -----Original Message----- > From: Dan Magenheimer > Sent: Monday, September 20, 2010 8:13 AM > To: Keir Fraser; Jan Beulich > Cc: Xen-devel > Subject: RE: [Xen-devel] Re: xen crash in tmem: checking a xen pfn for > domain ownership >=20 > > On 20/09/2010 08:16, "Jan Beulich" wrote: > > > > >>>> On 17.09.10 at 21:32, Keir Fraser > > wrote: > > >> Oh, depending on what you want to do with the page you may well > want > > to > > >> get_page(current->domain, page). You don't hold a lock on the > > domain's p2m, > > >> so page ownerships can change under your feet, and hence getting a > > reference > > >> to the page, and checking the page's ownership at the same time, > > might be > > >> wise. And if you want to modify the page you should probably use > > >> get_page_and_type(..., PGT_writable_page). > > > > > > That's particularly important for the pv case, where gfn_to_mfn() > is > > > a no-op. >=20 > Thanks, Jan and Keir, I'll take a look at it. >=20 > > Yes, I actually forgot about the PV case, and I think that's the only > > case > > that matters for tmem. :-) >=20 > Tmem works for HVM guests now too (on top of Stefano's PV-on-HVM > Linux kernel patches), though I haven't tested it in awhile. --__128502389314526335abhmt004 Content-Type: application/octet-stream; name="tmem_xen.c" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="tmem_xen.c" c3RhdGljIGlubGluZSB2b2lkICpjbGlfZ2V0X3BhZ2UodG1lbV9jbGlfbWZuX3QgY21mbiwgdW5z aWduZWQgbG9uZyAqcGNsaV9tZm4sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBm cF90ICoqcGNsaV9wZnAsIGJvb2xfdCBjbGlfd3JpdGUpCnsKICAgIHVuc2lnbmVkIGxvbmcgeG1m bjsKICAgIHAybV90eXBlX3QgdDsKICAgIHN0cnVjdCBwYWdlX2luZm8gKnBhZ2U7CiAgICBpbnQg cmV0OwoKICAgIGlmICggaXNfaHZtX2RvbWFpbihjdXJyZW50LT5kb21haW4pICkKICAgIHsKICAg ICAgICB4bWZuID0gbWZuX3goZ2ZuX3RvX21mbl91bnNoYXJlKGN1cnJlbnQtPmRvbWFpbiwgY21m biwgJnQsIDIpKTsKICAgICAgICBpZiAodCAhPSBwMm1fcmFtX3J3IHx8IHhtZm4gPT0gSU5WQUxJ RF9NRk4pCiAgICAgICAgICAgIHJldHVybiBOVUxMOwogICAgfQogICAgZWxzZQogICAgewogICAg ICAgIHhtZm4gPSBjbWZuOwogICAgICAgIGlmICghbWZuX3ZhbGlkKHhtZm4pKQogICAgICAgICAg ICByZXR1cm4gTlVMTDsKICAgIH0KICAgIHBhZ2UgPSBtZm5fdG9fcGFnZSh4bWZuKTsKICAgIGlm ICggY2xpX3dyaXRlICkKICAgICAgICByZXQgPSBnZXRfcGFnZV9hbmRfdHlwZShwYWdlLCBjdXJy ZW50LT5kb21haW4sIFBHVF93cml0YWJsZV9wYWdlKTsKICAgIGVsc2UKICAgICAgICByZXQgPSBn ZXRfcGFnZShwYWdlLCBjdXJyZW50LT5kb21haW4pOwogICAgaWYgKCByZXQgPD0gMCApCiAgICAg ICAgcmV0dXJuIE5VTEw7CiAgICAqcGNsaV9tZm4gPSB4bWZuOwogICAgKnBjbGlfcGZwID0gKHBm cF90ICopcGFnZTsKICAgIHJldHVybiBtYXBfZG9tYWluX3BhZ2UoeG1mbik7Cn0KCnN0YXRpYyBp bmxpbmUgdm9pZCBjbGlfcHV0X3BhZ2Uodm9pZCAqY2xpX3ZhLCBwZnBfdCAqY2xpX3BmcCwKICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1bnNpZ25lZCBsb25nIGNsaV9tZm4sIGJvb2xf dCBtYXJrX2RpcnR5KQp7CiAgICBpZiAoIG1hcmtfZGlydHkgKQogICAgICAgIHBhZ2luZ19tYXJr X2RpcnR5KGN1cnJlbnQtPmRvbWFpbixjbGlfbWZuKTsKICAgIHB1dF9wYWdlKChzdHJ1Y3QgcGFn ZV9pbmZvICopY2xpX3BmcCk7CiAgICB1bm1hcF9kb21haW5fcGFnZShjbGlfdmEpOwp9Cg== --__128502389314526335abhmt004 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --__128502389314526335abhmt004--