From patchwork Thu Dec 20 19:23:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 154363 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp50613ljp; Thu, 20 Dec 2018 11:26:06 -0800 (PST) X-Google-Smtp-Source: AFSGD/VB2ST4Q4mWFhE6e6RABWcr5zI12e2ioUBr0p964iEPf6fc+zFxdYCNjobSgn0aaAEUddQK X-Received: by 2002:a25:c286:: with SMTP id s128-v6mr27815467ybf.399.1545333966102; Thu, 20 Dec 2018 11:26:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545333966; cv=none; d=google.com; s=arc-20160816; b=bSnDIRv+sjpIt0whGUDEoMyYqAm91nYmFDgVzU+y/Na4VM/MiOvhb3wzImNZtPJCQD iv912Skgq5snR84g+HlmKVVkeJFcq1ZF8yDaUzLOKLU/bmgxylDaH42c0/izulu43f+0 0yttC6b/CNoJs1T1YAcC2j5uVOojsVW2PlYY/pWUEKS53/LlixtrcfsJMvrn44NxPO2t 8e8gMVHjqG8RRnDBgFW19lRPb09Dct/y70DSPk7dIObCbDg/tVwGGMqaGrHAx/AG613i aPVUDv+zGvO9v5B7RzrsWc+wcUho5aDz+W9KDRjHo5btVg+xnDS1egln+H/+VMj+F2ex 9aag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=2FymYDcatBfOKCmiMPew/rqhYCxeYL0weHdvjiod2SI=; b=sR0ty4EbD9740OL6Rc2ziquTCF2qOBYTYiPGEiDCZBNanAADgFx4CuwUtVlQl5wNaR 6d7lQ0POEJKwCf+mz23AgrWJ3SvNL96wyonVVhiLAPSv7F/cv8n5yyv5gbYiY+ARQmuO kBve+jO+ZyHe53kgS56SkMh7FeBCQ1RI5FgujW0ImCjgip7CzsveSCrd2obITW2RKoFv xz3uVJ1NBk/7Hzahtr4obyuQkwx6uhOpTrPnLiRDxKuTF3uQObU2ZsZMf4l9tdu0X6SX 2TxwRXLWj6tRFmmFjZ2VMTGYHS5x2d6XXEhQfpBvZURew9urOa/4ASWJRyPGAdzlADZI Mh8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id w37si12800720ybi.43.2018.12.20.11.26.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Dec 2018 11:26:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ga3vH-0001xn-3k; Thu, 20 Dec 2018 19:23:55 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ga3vG-0001xS-93 for xen-devel@lists.xenproject.org; Thu, 20 Dec 2018 19:23:54 +0000 X-Inumbo-ID: c93db8ce-048c-11e9-b535-5bd9d5a26786 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id c93db8ce-048c-11e9-b535-5bd9d5a26786; Thu, 20 Dec 2018 19:23:53 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AFAFF1596; Thu, 20 Dec 2018 11:23:52 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C161A3F575; Thu, 20 Dec 2018 11:23:51 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 20 Dec 2018 19:23:34 +0000 Message-Id: <20181220192338.17526-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181220192338.17526-1-julien.grall@arm.com> References: <20181220192338.17526-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 4/8] xen/arm: Add support for read-only foreign mappings X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , sstabellini@kernel.org, Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Current, foreign mappings can only be read-write. A follow-up patch will extend foreign mapping for Xen backend memory (via XEN_DOMID), some of that memory should only be read accessible for the mapping domain. Introduce a new p2m_type to cater read-only foreign mappings. For now, the decision between the two foreign mapping type is based on the type of the guest page mapped. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 2 +- xen/arch/arm/p2m.c | 1 + xen/include/asm-arm/p2m.h | 42 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7193d83b44..58f7e54640 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1267,7 +1267,7 @@ int xenmem_add_to_physmap_one( } mfn = page_to_mfn(page); - t = p2m_map_foreign_rw; + t = (p2mt == p2m_ram_rw) ? p2m_map_foreign_rw : p2m_map_foreign_ro; rcu_unlock_domain(od); break; diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index e0b84a9db5..dea04ef66f 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -477,6 +477,7 @@ static void p2m_set_permission(lpae_t *e, p2m_type_t t, p2m_access_t a) break; case p2m_iommu_map_ro: + case p2m_map_foreign_ro: case p2m_grant_map_ro: case p2m_invalid: e->p2m.xn = 1; diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index a1aef7b793..6f2728e2bb 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -116,6 +116,7 @@ typedef enum { p2m_mmio_direct_nc, /* Read/write mapping of genuine MMIO area non-cacheable */ p2m_mmio_direct_c, /* Read/write mapping of genuine MMIO area cacheable */ p2m_map_foreign_rw, /* Read/write RAM pages from foreign domain */ + p2m_map_foreign_ro, /* Read-only RAM pages from foreign domain */ p2m_grant_map_rw, /* Read/write grant mapping */ p2m_grant_map_ro, /* Read-only grant mapping */ /* The types below are only used to decide the page attribute in the P2M */ @@ -135,12 +136,16 @@ typedef enum { #define P2M_GRANT_TYPES (p2m_to_mask(p2m_grant_map_rw) | \ p2m_to_mask(p2m_grant_map_ro)) +/* Foreign mappings types */ +#define P2M_FOREIGN_TYPES (p2m_to_mask(p2m_map_foreign_rw) | \ + p2m_to_mask(p2m_map_foreign_ro)) + /* Useful predicates */ #define p2m_is_ram(_t) (p2m_to_mask(_t) & P2M_RAM_TYPES) -#define p2m_is_foreign(_t) (p2m_to_mask(_t) & p2m_to_mask(p2m_map_foreign_rw)) +#define p2m_is_foreign(_t) (p2m_to_mask(_t) & P2M_FOREIGN_TYPES) #define p2m_is_any_ram(_t) (p2m_to_mask(_t) & \ (P2M_RAM_TYPES | P2M_GRANT_TYPES | \ - p2m_to_mask(p2m_map_foreign_rw))) + P2M_FOREIGN_TYPES)) /* All common type definitions should live ahead of this inclusion. */ #ifdef _XEN_P2M_COMMON_H @@ -295,7 +300,38 @@ struct page_info *p2m_get_page_from_gfn(struct domain *d, gfn_t gfn, static inline struct page_info *get_page_from_gfn( struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) { - return p2m_get_page_from_gfn(d, _gfn(gfn), t); + mfn_t mfn; + p2m_type_t _t; + struct page_info *page; + + /* + * Special case for DOMID_XEN as it is the only domain so far that is + * not auto-translated. + */ + if ( unlikely(d != dom_xen) ) + return p2m_get_page_from_gfn(d, _gfn(gfn), t); + + if ( !t ) + t = &_t; + + *t = p2m_invalid; + + /* + * DOMID_XEN see 1-1 RAM. The p2m_type is based on the type of the + * page. + */ + mfn = _mfn(gfn); + page = mfn_to_page(mfn); + + if ( !mfn_valid(mfn) || !get_page(page, d) ) + return NULL; + + if ( page->u.inuse.type_info & PGT_writable_page ) + *t = p2m_ram_rw; + else + *t = p2m_ram_ro; + + return page; } int get_page_type(struct page_info *page, unsigned long type);