From patchwork Mon Dec 16 17:37:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22533 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CFB2523FC6 for ; Mon, 16 Dec 2013 17:37:45 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id o6sf19359461oag.11 for ; Mon, 16 Dec 2013 09:37:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=WnLlk+djVw+mVgh+iI5vy0f6JU/+WfZiAqwW5jA8g30=; b=aVOlhBUBeZ4UqwiBt92bZ5PLnc4QVw3lREu5jtpOh/+qDaoFR/o4RlxLgNvKzxqRrN 2jMBAF+0+8mAxPbgQDdg2Rnlv8dw4WbUqRhvczWYBsWBlT6MhG9/9+xmtWSb1Oci9caj tqDB/RApQ05h1N30IzurpYf08S08z+crTr5JWjt7Leci4XK83VzfCU+dZ4n43ZCE2Hfl 0qHcwKpV7bb+CuV3q9AIyAW8ZiytwDKNa9mxmNCB7dKv1zAVA4X65qHWx+fd9mC0PZkM TJYnxwzvw7v2nFMLm/pjANfDeEIs2bBRCrzKXaMG3OjH/PJYfg2ic1tqX8yCJmEmPnw1 3lLA== X-Gm-Message-State: ALoCoQljK4SIJN4cjI+Q4WefZgq5cUnAriY4DoiL7PvVsfJLcUD/EEvJavShQhBsj/n3iSa4qSdF X-Received: by 10.43.78.135 with SMTP id zm7mr1048764icb.27.1387215465401; Mon, 16 Dec 2013 09:37:45 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.120.5 with SMTP id ky5ls2214067qeb.26.gmail; Mon, 16 Dec 2013 09:37:45 -0800 (PST) X-Received: by 10.52.171.227 with SMTP id ax3mr3694896vdc.34.1387215465276; Mon, 16 Dec 2013 09:37:45 -0800 (PST) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id kp12si1627566vcb.91.2013.12.16.09.37.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 09:37:45 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hq11so3335156vcb.8 for ; Mon, 16 Dec 2013 09:37:45 -0800 (PST) X-Received: by 10.58.255.233 with SMTP id at9mr9031315ved.20.1387215465155; Mon, 16 Dec 2013 09:37:45 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp6116vcz; Mon, 16 Dec 2013 09:37:44 -0800 (PST) X-Received: by 10.14.172.130 with SMTP id t2mr17946711eel.68.1387215463659; Mon, 16 Dec 2013 09:37:43 -0800 (PST) Received: from mail-ee0-f45.google.com (mail-ee0-f45.google.com [74.125.83.45]) by mx.google.com with ESMTPS id v6si1258928eel.133.2013.12.16.09.37.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 09:37:43 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.45 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.83.45; Received: by mail-ee0-f45.google.com with SMTP id d49so2379221eek.32 for ; Mon, 16 Dec 2013 09:37:43 -0800 (PST) X-Received: by 10.14.182.199 with SMTP id o47mr18082444eem.7.1387215463060; Mon, 16 Dec 2013 09:37:43 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id e3sm44674680eeg.11.2013.12.16.09.37.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2013 09:37:42 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, ian.campbell@citrix.com, tim@xen.org, stefano.stabellini@citrix.com, Julien Grall Subject: [PATCH v5 04/10] xen/arm: Store p2m type in each page of the guest Date: Mon, 16 Dec 2013 17:37:26 +0000 Message-Id: <1387215452-10951-5-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1387215452-10951-1-git-send-email-julien.grall@linaro.org> References: <1387215452-10951-1-git-send-email-julien.grall@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Use the field 'avail' to store the type of the page. Rename it to 'type' for convenience. The information stored in this field will be retrieved in a future patch to change the behaviour when the page is removed. Also introduce guest_physmap_add_entry to map and set a specific p2m type for a page. Signed-off-by: Julien Grall --- Changes in v5: - Foreign mapping doesn't need to have execution right Changes in v3: - Typo in the commit message - Rename 'p2mt' field to 'type' - Remove default in switch to let the compiler warns - Move BUILD_BUG_ON to patch #3 Changes in v2: - Rename 'avail' field to 'p2mt' in the p2m structure - Add BUILD_BUG_ON to check if the enum value will fit in the field - Implement grant mapping type --- xen/arch/arm/p2m.c | 56 ++++++++++++++++++++++++++++++++------------ xen/include/asm-arm/p2m.h | 18 ++++++++++---- xen/include/asm-arm/page.h | 2 +- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 691cdfa..17d6620 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -128,7 +128,8 @@ int p2m_pod_decrease_reservation(struct domain *d, return -ENOSYS; } -static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr) +static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr, + p2m_type_t t) { paddr_t pa = ((paddr_t) mfn) << PAGE_SHIFT; lpae_t e = (lpae_t) { @@ -136,14 +137,34 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr) .p2m.af = 1, .p2m.sh = LPAE_SH_OUTER, .p2m.read = 1, - .p2m.write = 1, .p2m.mattr = mattr, .p2m.table = 1, .p2m.valid = 1, + .p2m.type = t, }; BUILD_BUG_ON(p2m_max_real_type > (1 << 4)); + switch (t) + { + case p2m_map_foreign: + case p2m_grant_map_rw: + e.p2m.xn = 1; + /* Fallthrough */ + case p2m_ram_rw: + case p2m_mmio_direct: + e.p2m.write = 1; + break; + + case p2m_grant_map_ro: + e.p2m.xn = 1; + /* Fallthrough */ + case p2m_invalid: + case p2m_ram_ro: + default: + e.p2m.write = 0; + } + ASSERT(!(pa & ~PAGE_MASK)); ASSERT(!(pa & ~PADDR_MASK)); @@ -173,7 +194,7 @@ static int p2m_create_table(struct domain *d, clear_page(p); unmap_domain_page(p); - pte = mfn_to_p2m_entry(page_to_mfn(page), MATTR_MEM); + pte = mfn_to_p2m_entry(page_to_mfn(page), MATTR_MEM, p2m_invalid); write_pte(entry, pte); @@ -191,7 +212,8 @@ static int create_p2m_entries(struct domain *d, paddr_t start_gpaddr, paddr_t end_gpaddr, paddr_t maddr, - int mattr) + int mattr, + p2m_type_t t) { int rc, flush; struct p2m_domain *p2m = &d->arch.p2m; @@ -271,14 +293,15 @@ static int create_p2m_entries(struct domain *d, goto out; } - pte = mfn_to_p2m_entry(page_to_mfn(page), mattr); + pte = mfn_to_p2m_entry(page_to_mfn(page), mattr, t); write_pte(&third[third_table_offset(addr)], pte); } break; case INSERT: { - lpae_t pte = mfn_to_p2m_entry(maddr >> PAGE_SHIFT, mattr); + lpae_t pte = mfn_to_p2m_entry(maddr >> PAGE_SHIFT, + mattr, t); write_pte(&third[third_table_offset(addr)], pte); maddr += PAGE_SIZE; } @@ -313,7 +336,8 @@ int p2m_populate_ram(struct domain *d, paddr_t start, paddr_t end) { - return create_p2m_entries(d, ALLOCATE, start, end, 0, MATTR_MEM); + return create_p2m_entries(d, ALLOCATE, start, end, + 0, MATTR_MEM, p2m_ram_rw); } int map_mmio_regions(struct domain *d, @@ -321,18 +345,20 @@ int map_mmio_regions(struct domain *d, paddr_t end_gaddr, paddr_t maddr) { - return create_p2m_entries(d, INSERT, start_gaddr, end_gaddr, maddr, MATTR_DEV); + return create_p2m_entries(d, INSERT, start_gaddr, end_gaddr, + maddr, MATTR_DEV, p2m_mmio_direct); } -int guest_physmap_add_page(struct domain *d, - unsigned long gpfn, - unsigned long mfn, - unsigned int page_order) +int guest_physmap_add_entry(struct domain *d, + unsigned long gpfn, + unsigned long mfn, + unsigned long page_order, + p2m_type_t t) { return create_p2m_entries(d, INSERT, pfn_to_paddr(gpfn), - pfn_to_paddr(gpfn + (1<