From patchwork Fri Dec 13 19:37:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22358 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4F40C202E2 for ; Fri, 13 Dec 2013 19:38:15 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id z6sf4389041yhz.11 for ; Fri, 13 Dec 2013 11:38:15 -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=AxBByEFB1vJ1OOk5o5YEnwesZH9CsailXjs9D4kgOAg=; b=XlGmRjqyul9oco9EK/41a+5/VbAYLzlOZolS+Rex9YtpztsBz4sql12hmkA5s6YNma safGYFkJFp/17wVVxNxQCPcRBIOZG48l6mwVP+t+9/2U1AN2ubfqaI6aeXeX0T4cap7U zrG9qUX4mkF4lhkNLy1q/OXr8+y1HKnkirQFtNqC9kULhg8xRHWMn+nhNOnO4sBp8Unv xtVb/jyHNprN7bJACqTtkVBm/+Q6lasMn9phw128qbHHKH8+2E9ODHFBSoNtEDLxFV9A GFhaap+leWPvRLzZt2nDUVEAbF+fHeMbcsyQ8tckwh0/uNZfTURtNoOlWqmrE0+UM2dR o36w== X-Gm-Message-State: ALoCoQnzuPWlmLByuGMpMztxFWH3hIwk6sXkeZ4HoiRb70U9amGIo8G8MQfrhqRSebeWEPA9mi9E X-Received: by 10.58.128.33 with SMTP id nl1mr1698365veb.28.1386963495125; Fri, 13 Dec 2013 11:38:15 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.37.195 with SMTP id a3ls1113618qek.88.gmail; Fri, 13 Dec 2013 11:38:15 -0800 (PST) X-Received: by 10.220.145.75 with SMTP id c11mr1986762vcv.30.1386963495022; Fri, 13 Dec 2013 11:38:15 -0800 (PST) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id bj1si1079291ved.40.2013.12.13.11.38.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 11:38:15 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.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.128.177; Received: by mail-ve0-f177.google.com with SMTP id db12so1705180veb.36 for ; Fri, 13 Dec 2013 11:38:14 -0800 (PST) X-Received: by 10.220.97.69 with SMTP id k5mr1940980vcn.45.1386963494919; Fri, 13 Dec 2013 11:38:14 -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 u4csp64190vcz; Fri, 13 Dec 2013 11:38:14 -0800 (PST) X-Received: by 10.14.178.197 with SMTP id f45mr4494306eem.47.1386963493853; Fri, 13 Dec 2013 11:38:13 -0800 (PST) Received: from mail-ea0-f179.google.com (mail-ea0-f179.google.com [209.85.215.179]) by mx.google.com with ESMTPS id p9si3168964eew.34.2013.12.13.11.38.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 11:38:13 -0800 (PST) Received-SPF: neutral (google.com: 209.85.215.179 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.215.179; Received: by mail-ea0-f179.google.com with SMTP id r15so1078934ead.24 for ; Fri, 13 Dec 2013 11:38:13 -0800 (PST) X-Received: by 10.14.32.132 with SMTP id o4mr4697545eea.14.1386963493446; Fri, 13 Dec 2013 11:38:13 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id m1sm10199792eeg.0.2013.12.13.11.38.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Dec 2013 11:38:12 -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 v4 05/11] xen/arm: Store p2m type in each page of the guest Date: Fri, 13 Dec 2013 19:37:35 +0000 Message-Id: <1386963461-6520-6-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1386963461-6520-1-git-send-email-julien.grall@linaro.org> References: <1386963461-6520-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.128.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 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..3a79927 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_grant_map_rw: + e.p2m.xn = 1; + /* Fallthrough */ + case p2m_ram_rw: + case p2m_mmio_direct: + case p2m_map_foreign: + 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<