From patchwork Tue Dec 17 16:27:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22601 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7699E23FC6 for ; Tue, 17 Dec 2013 16:28:27 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wo20sf22791096obc.5 for ; Tue, 17 Dec 2013 08:28:27 -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=mbwFAVQidW25T8T7epu7Tyb6bdOd7/YhPlLZX9DPy0E=; b=O9HpSPNHh9sHyTh7AyxvxBVm6RhkJs3I4IB0eJnxx8VC0bSAhugKgzokpV1xLrwdR4 D1fKiVsK6EfnyxMaCFH1IfWr5a1uYsrLpcfJQ9BT7lMLiFHTOjy/VBzrXLTCXI0PJDAG Levz1ynnHCiWdDNC6/yKttZKNVezafGVCK4VJqT5R7WsZbkWr/SGNkdUUuh5r1tbb7XO 9iKgImvF3yt5LBoNz4XZOZXsEFyLUeIiZuYoCRGXfntsDs/wsHcZWUvWwOPmICROw4CC LqO1CfKDojvBWry+X6eNLbmj3vpvGHjLvDidW2Mxe704S//H7nE6EMtOYczJs/MRbwb9 Jd1A== X-Gm-Message-State: ALoCoQmnbK2BwwkNEXuqjMydQjcJjWbz8x8DKDdaU60Pxj66Z8NhM+0A4Hec0f+wMFpPBIRp8t8L X-Received: by 10.42.128.82 with SMTP id l18mr7334738ics.21.1387297706982; Tue, 17 Dec 2013 08:28:26 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.36.229 with SMTP id t5ls2530962qej.61.gmail; Tue, 17 Dec 2013 08:28:26 -0800 (PST) X-Received: by 10.220.64.69 with SMTP id d5mr11144443vci.11.1387297706777; Tue, 17 Dec 2013 08:28:26 -0800 (PST) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by mx.google.com with ESMTPS id xn8si5030858vdc.74.2013.12.17.08.28.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Dec 2013 08:28:26 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.50; Received: by mail-vb0-f50.google.com with SMTP id w18so4203999vbj.23 for ; Tue, 17 Dec 2013 08:28:26 -0800 (PST) X-Received: by 10.220.84.65 with SMTP id i1mr1674015vcl.51.1387297706673; Tue, 17 Dec 2013 08:28:26 -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 u4csp79571vcz; Tue, 17 Dec 2013 08:28:25 -0800 (PST) X-Received: by 10.15.73.134 with SMTP id h6mr23840631eey.90.1387297703908; Tue, 17 Dec 2013 08:28:23 -0800 (PST) Received: from mail-ee0-f42.google.com (mail-ee0-f42.google.com [74.125.83.42]) by mx.google.com with ESMTPS id m44si4870326eeo.58.2013.12.17.08.28.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Dec 2013 08:28:23 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.42 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.83.42; Received: by mail-ee0-f42.google.com with SMTP id e53so2964313eek.15 for ; Tue, 17 Dec 2013 08:28:23 -0800 (PST) X-Received: by 10.15.54.72 with SMTP id s48mr23661483eew.3.1387297703475; Tue, 17 Dec 2013 08:28:23 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id e3sm54411471eeg.11.2013.12.17.08.28.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2013 08:28:21 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, ian.campbell@citrix.com, ian.jackson@eu.citrix.com, Julien Grall Subject: [PATCH v6 04/10] xen/arm: Store p2m type in each page of the guest Date: Tue, 17 Dec 2013 16:27:52 +0000 Message-Id: <1387297678-17762-5-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1387297678-17762-1-git-send-email-julien.grall@linaro.org> References: <1387297678-17762-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.212.50 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 Acked-by: Ian Campbell --- Changes in v6: - Refactor switch - Invalid mapping and MMIO mapping doesn't need to have execution right - Remove default case in the switch 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 | 68 +++++++++++++++++++++++++++++++++----------- xen/include/asm-arm/p2m.h | 18 +++++++++--- xen/include/asm-arm/page.h | 2 +- 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 691cdfa..3dda5c2 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -128,22 +128,53 @@ 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; + /* xn and write bit will be defined in the switch */ lpae_t e = (lpae_t) { - .p2m.xn = 0, .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_ram_rw: + e.p2m.xn = 0; + e.p2m.write = 1; + break; + + case p2m_ram_ro: + e.p2m.xn = 0; + e.p2m.write = 0; + break; + + case p2m_map_foreign: + case p2m_grant_map_rw: + case p2m_mmio_direct: + e.p2m.xn = 1; + e.p2m.write = 1; + break; + + case p2m_grant_map_ro: + case p2m_invalid: + e.p2m.xn = 1; + e.p2m.write = 0; + break; + + case p2m_max_real_type: + BUG(); + break; + } + ASSERT(!(pa & ~PAGE_MASK)); ASSERT(!(pa & ~PADDR_MASK)); @@ -173,7 +204,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 +222,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 +303,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 +346,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 +355,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<