From: "Jan Beulich" Subject: Re: [V9 PATCH 6/8] pvh dom0: Add and remove foreign pages Date: Thu, 24 Apr 2014 07:44:31 +0100 Message-ID: <5358CEEF020000780000BCD8@nat28.tlf.novell.com> References: <1397607172-32065-1-git-send-email-mukesh.rathor@oracle.com> <1397607172-32065-7-git-send-email-mukesh.rathor@oracle.com> <534EC5430200007800009ADD@nat28.tlf.novell.com> <20140416183742.50a98472@mantra.us.oracle.com> <534F95E00200007800009D40@nat28.tlf.novell.com> <20140417123653.GA25395@deinos.phlegethon.org> <534FFA32020000780000A077@nat28.tlf.novell.com> <20140423192151.0b05a91b@mantra.us.oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WdDOd-0004ah-3p for xen-devel@lists.xenproject.org; Thu, 24 Apr 2014 06:44:35 +0000 In-Reply-To: <20140423192151.0b05a91b@mantra.us.oracle.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Mukesh Rathor Cc: George.Dunlap@eu.citrix.com, Tim Deegan , eddie.dong@intel.com, keir.xen@gmail.com, jun.nakajima@intel.com, xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> On 24.04.14 at 04:21, wrote: > On Thu, 17 Apr 2014 14:58:42 +0100 > "Jan Beulich" wrote: >> Right - keeping the macro as is and introducing a derived function to >> handle the extra requirements on leaf entries would seem quite okay, >> so long as error propagation can be done properly. > > Ok, how about something like the following? Looks reasonable, especially if this is indeed the only place where leaf entries get modified. I suppose there's no path allowing 2M or 1G pages to be created with foreign type? > In case of get_page failure, > not sure EINVAL is the best one to return, EBUSY? Indeed, -EBUSY seems like the more applicable one here. > @@ -545,8 +569,14 @@ ept_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, > ept_p2m_type_to_flags(&new_entry, p2mt, p2ma); > } > > + if ( unlikely(p2m_is_foreign(ept_entry->sa_p2mt)) ) > + prev_foreign_mfn = ept_entry->mfn; > + > atomic_write_ept_entry(ept_entry, new_entry); > > + if ( unlikely(prev_foreign_mfn != INVALID_MFN) ) > + put_page(mfn_to_page(prev_foreign_mfn)); > + > /* Track the highest gfn for which we have ever had a valid mapping */ > if ( p2mt != p2m_invalid && > (gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) ) > @@ -576,6 +606,10 @@ out: > } > } > > + /* do cleanup for foreign types in case of error */ > + if ( unlikely(rc && ept_entry && p2m_is_foreign(p2mt)) ) > + put_page(mfn_to_page(mfn_x(mfn))); Comparing this with the above suggests that type safety rules would want prev_foreign_mfn to be mfn_t, and this as well as the code in ept_get_foreign_refcnt() suggest that you may want/ need to add *_to_* overrides similar to the ones near the top of p2m-pt.c. Jan