From patchwork Fri Dec 21 16:26:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 154409 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1117811ljp; Fri, 21 Dec 2018 08:29:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/UpKT6LYmUgqRMXYeNXpeKTIybKjtVN22Yo8U0OdaEKxc6wkfyOM8wM+y0Dx/agBGJnFwBW X-Received: by 2002:a81:9ad8:: with SMTP id r207mr3166591ywg.72.1545409743348; Fri, 21 Dec 2018 08:29:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545409743; cv=none; d=google.com; s=arc-20160816; b=XuWwZLgqZBvN36fr3s+AqJAftn7rR6GR1LPoi/8feqqQeb8e3AEM8P2D+menWN8Co0 jxyCS8mTClWAwhK3z3MthpvljhEXgb75Mmxej2YeQv9t1DlMOz0uLq6YbZXrPgzR2rGa sV23m/Z+HHXKr2tXyhdifJCR9CjUo3LvDDz/hY140evnyce1i0UTUQacrpE5kmiP7NXD yM2QNtA+GqwCRhqv8ll/AKnAB9RBqfPjn1ik1JYIQz7Inpe/zIp9RP86RNBGtFE0YVtT FPXTjCuq1hG7dyynMBQQqriGf0Os8j1fKSI6Y3KlR8z5ARyk1OB1VCY/5ZW0W6ePwA4N fo2A== 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=eKTQazmZgBYbnOMXWN4g4k3Pu5fsm19lFtLQvVdmaCI=; b=ThpXsAj5en5aknHjjlc6RbdAxXbSQfuXAI5X7YNyLjoN9nprIniPeHITgW+W75eYNk 3NqEKQP3G3MV47KQEgH/b83Ou5KFQZSeYQdhh3M5jOAcIQzLZGohutf37osnfVGkGHTo Bo8tH3b3rJW0IFN82+h8/I3Gav31iGSBZXaML9NPCq/xMTLavgDhos0wv3J2jJZogryp PqoAGg/xwTAfugtVFENAxD57HG9Y4SMQ4osDHcd8o+C27wGENp6Z/x3eZRf0awN7s+E5 XleVBGBfsWQxJfeNAZElo8GF5F2u2sjah72iTfkUidln5k9nenR8Fgt1jFyXQ44P+rTg bDPg== 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 a123si15117869ywg.39.2018.12.21.08.29.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Dec 2018 08:29:03 -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 1gaNdi-00068L-Jo; Fri, 21 Dec 2018 16:27:06 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gaNdh-00067n-Bk for xen-devel@lists.xenproject.org; Fri, 21 Dec 2018 16:27:05 +0000 X-Inumbo-ID: 3fffc36e-053d-11e9-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 3fffc36e-053d-11e9-8e1d-bc764e045a96; Fri, 21 Dec 2018 16:27:03 +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 83DF415AD; Fri, 21 Dec 2018 08:27:03 -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 9522C3F5C0; Fri, 21 Dec 2018 08:27:02 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 21 Dec 2018 16:26:45 +0000 Message-Id: <20181221162650.11515-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181221162650.11515-1-julien.grall@arm.com> References: <20181221162650.11515-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v3 3/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" Currently, 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 --- Cc: Andrii Anisov Changes in v3: - Remove Andrii's reviewed-by - Move out the XEN_DOMID code in a separate patch - Make the new addition future-proof Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 5 +++-- xen/arch/arm/p2m.c | 1 + xen/include/asm-arm/p2m.h | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7193d83b44..3bf11eec4f 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1259,7 +1259,9 @@ int xenmem_add_to_physmap_one( return -EINVAL; } - if ( !p2m_is_ram(p2mt) ) + if ( p2m_is_ram(p2mt) ) + t = (p2mt == p2m_ram_rw) ? p2m_map_foreign_rw : p2m_map_foreign_ro; + else { put_page(page); rcu_unlock_domain(od); @@ -1267,7 +1269,6 @@ int xenmem_add_to_physmap_one( } mfn = page_to_mfn(page); - t = p2m_map_foreign_rw; rcu_unlock_domain(od); break; diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 89279fb590..1e7c91e39a 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -478,6 +478,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..a03a033a05 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