From patchwork Mon Jul 28 10:16:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 34349 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0D6BA20AE8 for ; Mon, 28 Jul 2014 10:20:25 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id v1sf26085162yhn.4 for ; Mon, 28 Jul 2014 03:20:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=9V9VaNKTy7zAPY7AY6mePmQ2Q9JBjoiZ7JuxtCtWNXU=; b=fTg/h1+NAin3bwdKfiEVSLuyBEezCrIhBCVRGXfwSIJpQRR/TrkNa/YFBAiTwaJM9m qeYGKr/0nVnkDhs++iP92+564hW1GVDWYmqDF7NwE8f0MM1iljkIZC/y5h3qaKPG861d XrhTewSrYT+CYvvngOLu0k/9jfFFJXW0xJhzz5/ZJIs0vSy3R7nI0czqJgngaaImosv1 LCl80CpRvW86AZ6Pop+Zhd+ca/YM9NQA4y2chChIBb2v47XVv+Cfv4MCQZCRLYd65lkq PBrrxplGpW17CJfXD/pFPoii+JeOcKpIFeOqqc61w92w4sW7PJeROXlz13qmg8yOEHWL 5afA== X-Gm-Message-State: ALoCoQmG9aNQvfXoLg9LaUstaEcdzxdzRMlGHqGTqg9Ma4MZDg/nKYrS5OOzUryQ9UX2UPCRnD/X X-Received: by 10.236.131.144 with SMTP id m16mr12968656yhi.25.1406542824867; Mon, 28 Jul 2014 03:20:24 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.35.232 with SMTP id n95ls2042613qgn.23.gmail; Mon, 28 Jul 2014 03:20:24 -0700 (PDT) X-Received: by 10.52.185.72 with SMTP id fa8mr36605917vdc.4.1406542824727; Mon, 28 Jul 2014 03:20:24 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id wd16si12132806vdc.15.2014.07.28.03.20.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Jul 2014 03:20:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hy4so10511337vcb.22 for ; Mon, 28 Jul 2014 03:20:24 -0700 (PDT) X-Received: by 10.52.244.138 with SMTP id xg10mr36564848vdc.40.1406542824640; Mon, 28 Jul 2014 03:20:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp154899vcb; Mon, 28 Jul 2014 03:20:24 -0700 (PDT) X-Received: by 10.50.80.76 with SMTP id p12mr31128913igx.34.1406542823096; Mon, 28 Jul 2014 03:20:23 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id m3si15535709igx.17.2014.07.28.03.20.22 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 28 Jul 2014 03:20:23 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XBi0i-0001a3-U0; Mon, 28 Jul 2014 10:18:28 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XBi0h-0001Zh-7z for xen-devel@lists.xensource.com; Mon, 28 Jul 2014 10:18:27 +0000 Received: from [193.109.254.147:36607] by server-11.bemta-14.messagelabs.com id 72/A1-14213-27326D35; Mon, 28 Jul 2014 10:18:26 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1406542704!12097195!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30370 invoked from network); 28 Jul 2014 10:18:25 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-3.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 28 Jul 2014 10:18:25 -0000 X-IronPort-AV: E=Sophos;i="5.01,748,1400025600"; d="scan'208";a="156845675" Received: from accessns.citrite.net (HELO FTLPEX01CL01.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 28 Jul 2014 10:18:00 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Mon, 28 Jul 2014 06:17:59 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XBi0A-0005Bg-DR; Mon, 28 Jul 2014 11:17:54 +0100 From: Stefano Stabellini To: Date: Mon, 28 Jul 2014 11:16:49 +0100 Message-ID: <1406542610-18724-2-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA2 Cc: julien.grall@citrix.com, Ian.Campbell@citrix.com, Stefano Stabellini Subject: [Xen-devel] [PATCH v4 2/3] xen: introduce arch_grant_(un)map_page_identity X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: Introduce two arch specific functions to create a new p2m mapping of granted pages at pfn == mfn. The x86 implementation just returns ENOSYS. Base the implementation of arm_smmu_(un)map_page on arch_grant_(un)map_page_identity. Signed-off-by: Stefano Stabellini Acked-by: Julien Grall --- Changes in v4: - declare the x86 implementations as extern; - add ASSERTs to ARM implementations. Changes in v3: - fix commit title; - use p2m_iommu types; - call arch_grant_(un)map_page_identity functions from arm_smmu_(un)map_page. --- xen/arch/arm/p2m.c | 26 ++++++++++++++++++++++++++ xen/arch/x86/mm/p2m.c | 13 +++++++++++++ xen/drivers/passthrough/arm/smmu.c | 13 ++----------- xen/include/asm-arm/p2m.h | 4 ++++ xen/include/asm-x86/p2m.h | 4 ++++ 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 9960e17..c2634fc 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -555,6 +555,32 @@ void guest_physmap_remove_page(struct domain *d, pfn_to_paddr(mfn), MATTR_MEM, p2m_invalid); } +int arch_grant_map_page_identity(struct domain *d, unsigned long frame, + bool_t writeable) +{ + p2m_type_t t; + + ASSERT(is_domain_direct_mapped(d)); + + /* This is not an IOMMU mapping but it is not a regular RAM p2m type + * either. We are using IOMMU p2m types here to prevent the pages + * from being used as grants. */ + if ( writeable ) + t = p2m_iommu_map_rw; + else + t = p2m_iommu_map_ro; + + return guest_physmap_add_entry(d, frame, frame, 0, t); +} + +int arch_grant_unmap_page_identity(struct domain *d, unsigned long frame) +{ + ASSERT(is_domain_direct_mapped(d)); + + guest_physmap_remove_page(d, frame, frame, 0); + return 0; +} + int p2m_alloc_table(struct domain *d) { struct p2m_domain *p2m = &d->arch.p2m; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 642ec28..c117d8d 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1905,6 +1905,19 @@ out: rcu_unlock_domain(fdom); return rc; } + + +int arch_grant_map_page_identity(struct domain *d, unsigned long frame, + bool_t writeable) +{ + return -ENOSYS; +} + +int arch_grant_unmap_page_identity(struct domain *d, unsigned long frame) +{ + return -ENOSYS; +} + /* * Local variables: * mode: C diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index f4eb2a2..fb0c694 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -1539,8 +1539,6 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d) static int arm_smmu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, unsigned int flags) { - p2m_type_t t; - /* Grant mappings can be used for DMA requests. The dev_bus_addr returned by * the hypercall is the MFN (not the IPA). For device protected by * an IOMMU, Xen needs to add a 1:1 mapping in the domain p2m to @@ -1555,12 +1553,7 @@ static int arm_smmu_map_page(struct domain *d, unsigned long gfn, if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) ) return -EINVAL; - t = (flags & IOMMUF_writable) ? p2m_iommu_map_rw : p2m_iommu_map_ro; - - /* The function guest_physmap_add_entry replaces the current mapping - * if there is already one... - */ - return guest_physmap_add_entry(d, gfn, mfn, 0, t); + return arch_grant_map_page_identity(d, mfn, flags & IOMMUF_writable); } static int arm_smmu_unmap_page(struct domain *d, unsigned long gfn) @@ -1571,9 +1564,7 @@ static int arm_smmu_unmap_page(struct domain *d, unsigned long gfn) if ( !is_domain_direct_mapped(d) ) return -EINVAL; - guest_physmap_remove_page(d, gfn, gfn, 0); - - return 0; + return arch_grant_unmap_page_identity(d, gfn); } static const struct iommu_ops arm_smmu_iommu_ops = { diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 911d32d..b682f51 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -181,6 +181,10 @@ static inline int get_page_and_type(struct page_info *page, return rc; } +int arch_grant_map_page_identity(struct domain *d, unsigned long frame, + bool_t writeable); +int arch_grant_unmap_page_identity(struct domain *d, unsigned long frame); + #endif /* _XEN_P2M_H */ /* diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 0ddbadb..0cf03da 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -717,6 +717,10 @@ static inline unsigned int p2m_get_iommu_flags(p2m_type_t p2mt) return flags; } + +int arch_grant_map_page_identity(struct domain *d, unsigned long frame, + bool_t writeable); +int arch_grant_unmap_page_identity(struct domain *d, unsigned long frame); #endif /* _XEN_P2M_H */