From: "Jan Beulich" Subject: Re: [PATCH RFC 1/2] gnttab: add IOMMU entries for grant mappings on auto-translated guests Date: Fri, 04 Apr 2014 16:35:30 +0100 Message-ID: <533EED620200007800005C88@nat28.tlf.novell.com> References: <1396622254-13069-1-git-send-email-roger.pau@citrix.com> <1396622254-13069-2-git-send-email-roger.pau@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WW69W-0002ys-8d for xen-devel@lists.xenproject.org; Fri, 04 Apr 2014 15:35:34 +0000 In-Reply-To: <1396622254-13069-2-git-send-email-roger.pau@citrix.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: Roger Pau Monne Cc: xen-devel@lists.xenproject.org, Keir Fraser List-Id: xen-devel@lists.xenproject.org >>> On 04.04.14 at 16:37, wrote: > --- a/xen/common/grant_table.c > +++ b/xen/common/grant_table.c > @@ -749,6 +749,22 @@ __gnttab_map_grant_ref( > goto undo_out; > } > } > + else if ( need_iommu(ld) ) > + { > + int err; > + > + BUG_ON(!paging_mode_translate(ld)); > + err = iommu_map_page(ld, op->host_addr >> PAGE_SHIFT, frame, > + op->flags & GNTMAP_readonly ? > + IOMMUF_readable : > + IOMMUF_readable|IOMMUF_writable); > + if ( err ) > + { > + double_gt_unlock(lgt, rgt); > + rc = GNTST_general_error; > + goto undo_out; > + } > + } As much of this as possible should be folded with the if() branch. And looking at the PV code, I think it makes no sense for the conditions whether to map the page r/o or r/w to be different between PV and non-PV. Plus - wouldn't it be better to have this taken care of via create_grant_host_mapping(), by not blindly calling iommu_unmap_page() on anything other than p2m_ram_rw in ept_set_entry() and p2m_set_entry(), the more that this should already be taken care of in the iommu_hap_pt_share case. > @@ -947,6 +963,18 @@ __gnttab_unmap_common( > goto unmap_out; > } > } > + else if ( need_iommu(ld) ) > + { > + int err; > + > + BUG_ON(!paging_mode_translate(ld)); > + err = iommu_unmap_page(ld, op->host_addr >> PAGE_SHIFT); > + if ( err ) > + { > + rc = GNTST_general_error; > + goto unmap_out; > + } > + } Same thing here obviously. Jan