From: "Jan Beulich" Subject: Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m Date: Tue, 20 May 2014 08:46:17 +0100 Message-ID: <537B24690200007800013EF0@mail.emea.novell.com> References: <1400516640-7175-1-git-send-email-julien.grall@linaro.org> <1400516640-7175-5-git-send-email-julien.grall@linaro.org> 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 1Wmekf-0002gf-Ac for xen-devel@lists.xenproject.org; Tue, 20 May 2014 07:46:21 +0000 In-Reply-To: <1400516640-7175-5-git-send-email-julien.grall@linaro.org> 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: Julien Grall Cc: xen-devel@lists.xenproject.org, stefano.stabellini@citrix.com, ian.campbell@citrix.com, tim@xen.org List-Id: xen-devel@lists.xenproject.org >>> On 19.05.14 at 18:24, wrote: > Grant mapping can be used for DMA request. The dev_bus_addr returned by the > hypercall is the MFN (not the IPA). Currently Linux is using this address (via > swiotlb) to program the DMA. > When the device is protected by IOMMU the request will fail. We have to > add 1:1 mapping in the domain p2m to allow DMA request working. > > This is valid because DOM0 has its memory mapped 1:1 and therefore we know > that RAM and devices cannot clash. Wasn't this 1:1 mapping meant as a temporary workaround? If so, does it really make sense to base further code on it? > --- a/xen/common/grant_table.c > +++ b/xen/common/grant_table.c > @@ -727,7 +727,7 @@ __gnttab_map_grant_ref( > > double_gt_lock(lgt, rgt); > > - if ( !paging_mode_translate(ld) && need_iommu(ld) ) > + if ( gnttab_need_iommu_mapping(ld) && need_iommu(ld) ) I suppose that you want to keep the common bits of this condition common, but the two "need_iommu" in here look sort of redundant: With the name chosen, I think it would make more sense for the second condition to be moved into gnttab_need_iommu_mapping(). > --- a/xen/include/asm-arm/grant_table.h > +++ b/xen/include/asm-arm/grant_table.h > @@ -33,6 +33,8 @@ static inline int replace_grant_supported(void) > ( ((i >= nr_grant_frames(d->grant_table)) && \ > (i < max_nr_grant_frames)) ? 0 : (d->arch.grant_table_gpfn[i])) > > +#define gnttab_need_iommu_mapping(d) is_domain_direct_mapped(d) While this one indeed doesn't need extra parentheses, ... > --- a/xen/include/asm-x86/grant_table.h > +++ b/xen/include/asm-x86/grant_table.h > @@ -65,6 +65,8 @@ static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st) > /* Done implicitly when page tables are destroyed. */ > #define gnttab_release_host_mappings(domain) ( paging_mode_external(domain) ) > > +#define gnttab_need_iommu_mapping(d) !paging_mode_translate(d) ... this one does. Also, with all of this I don't see how other than Dom0 is being (or going to be) handled in this regard. Jan