From patchwork Fri Dec 13 19:37:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22361 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 36ABF202E2 for ; Fri, 13 Dec 2013 19:38:23 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id x13sf4040472qcv.7 for ; Fri, 13 Dec 2013 11:38:23 -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=ugR78jeUXH4wbfHpxbgiKOgkxpzRl5schOlfzk5TC80=; b=csKMHXweZU8OKbOwC6xG5Vbo/HDYkQOX0sbCSHPZI32atGIgpp+mmGsl1m9L/e0bzl aUFoYefGIv7GN34LVTTKYBiYjM1EOWkLUstNYvdaAQtmdTveVcAU8ggoIjeoGjduazgC sOz6jpcb4pzq69hfIMB8u2eBK5g1hZPrj4i3Cux1q7EoxPMjk0TR0Q7UmhWcZ61hQnKZ 4VjGeZ3wAzDc6xlt0pB72S9GfSlLAWu7JPPF+UKwt86f+jhYDgNUjCjdTlK8WOs2OC+U bsIH/IQfynTHUQugU7Hsu/7Aea3q2pyyAGDE3fY0ePgg5/pjDpQm8qYeK6ZWBvMyE7nX cXYQ== X-Gm-Message-State: ALoCoQlMmvH19sbJovn97/jmzSqinOSNwXd/wvIXGhCqVKNLD3ZUr8Tk4A1SdRNZxE+9oYeMRrhR X-Received: by 10.224.122.210 with SMTP id m18mr1586427qar.2.1386963503038; Fri, 13 Dec 2013 11:38:23 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.3.165 with SMTP id d5ls1180125qed.77.gmail; Fri, 13 Dec 2013 11:38:22 -0800 (PST) X-Received: by 10.58.96.15 with SMTP id do15mr1944498veb.56.1386963502944; Fri, 13 Dec 2013 11:38:22 -0800 (PST) Received: from mail-vb0-f41.google.com (mail-vb0-f41.google.com [209.85.212.41]) by mx.google.com with ESMTPS id wv16si1078023vcb.47.2013.12.13.11.38.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 11:38:22 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.41 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.41; Received: by mail-vb0-f41.google.com with SMTP id m10so1606835vbh.14 for ; Fri, 13 Dec 2013 11:38:22 -0800 (PST) X-Received: by 10.58.216.133 with SMTP id oq5mr82650vec.80.1386963502837; Fri, 13 Dec 2013 11:38:22 -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 u4csp64206vcz; Fri, 13 Dec 2013 11:38:22 -0800 (PST) X-Received: by 10.15.86.75 with SMTP id h51mr4600023eez.44.1386963501923; Fri, 13 Dec 2013 11:38:21 -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 e48si3126151eeh.218.2013.12.13.11.38.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 11:38:21 -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 e53so1078923eek.1 for ; Fri, 13 Dec 2013 11:38:21 -0800 (PST) X-Received: by 10.14.108.134 with SMTP id q6mr4639234eeg.96.1386963501365; Fri, 13 Dec 2013 11:38:21 -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.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Dec 2013 11:38:19 -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 , Jan Beulich , Keir Fraser Subject: [PATCH v4 08/11] xen/arm: Handle remove foreign mapping Date: Fri, 13 Dec 2013 19:37:38 +0000 Message-Id: <1386963461-6520-9-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.212.41 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: , Introduce p2m_remove_foreign to remove foreign mapping. This function will will release the reference taken when the mapping is added in the p2m. As the function is not yet implemented on x86, add stubs. Signed-off-by: Mukesh Rathor [common/memory.c] Signed-off-by: Julien Grall Cc: Jan Beulich Cc: Keir Fraser --- Changes in v4: - Split patch #6 from dom0 pvh series v6.2 to retrieve only common code. - Rework commit title - Rename xen_rem_foreign_from_p2m in p2m_remove_foreign - Get the mfn from the pte. We are not sure that maddr given in parameters is valid Changes in v3: - Move put_page in create_p2m_entries - Move xenmem_rem_foreign_from_p2m in arch/arm/p2m.c Changes in v2: - Introduce the patch --- xen/arch/arm/p2m.c | 25 +++++++++++++++++++++++-- xen/common/memory.c | 12 +++++++++++- xen/include/asm-arm/p2m.h | 2 ++ xen/include/asm-x86/p2m.h | 6 ++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 39d8a03..cfdc19c 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -317,10 +317,21 @@ static int create_p2m_entries(struct domain *d, break; case REMOVE: { - lpae_t pte; + lpae_t pte = third[third_table_offset(addr)]; + unsigned long mfn; + + maddr = (pte.bits & PADDR_MASK & PAGE_MASK); + mfn = paddr_to_pfn(maddr); + + /* TODO: Handle other p2m type */ + if ( pte.p2m.valid && p2m_is_foreign(pte.p2m.type) ) + { + ASSERT(mfn_valid(mfn)); + put_page(mfn_to_page(mfn)); + } + memset(&pte, 0x00, sizeof(pte)); write_pte(&third[third_table_offset(addr)], pte); - maddr += PAGE_SIZE; } break; } @@ -380,6 +391,16 @@ void guest_physmap_remove_page(struct domain *d, pfn_to_paddr(mfn), MATTR_MEM, p2m_invalid); } +int p2m_remove_foreign(struct domain *d, unsigned long gpfn) +{ + unsigned long mfn = gmfn_to_mfn(d, gpfn); + + ASSERT(mfn_valid(mfn)); + guest_physmap_remove_page(d, gpfn, mfn, 0); + + return 0; +} + int p2m_alloc_table(struct domain *d) { struct p2m_domain *p2m = &d->arch.p2m; diff --git a/xen/common/memory.c b/xen/common/memory.c index eb7b72b..61791a4 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -678,6 +678,7 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) struct xen_remove_from_physmap xrfp; struct page_info *page; struct domain *d; + p2m_type_t p2mt; if ( copy_from_guest(&xrfp, arg, 1) ) return -EFAULT; @@ -693,12 +694,21 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) return rc; } - page = get_page_from_gfn(d, xrfp.gpfn, NULL, P2M_ALLOC); + /* + * If autotranslate guest, (eg pvh), the gfn could be mapped to a mfn + * from foreign domain by the user space tool during domain creation. + * We need to check for that, free it up from the p2m, and release + * refcnt on it. In such a case, page would be NULL and the following + * call would not have refcnt'd the page. + */ + page = get_page_from_gfn(d, xrfp.gpfn, &p2mt, P2M_ALLOC); if ( page ) { guest_physmap_remove_page(d, xrfp.gpfn, page_to_mfn(page), 0); put_page(page); } + else if ( p2m_is_foreign(p2mt) ) + rc = p2m_remove_foreign(d, xrfp.gpfn); else rc = -ENOENT; diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 0eb07a8..844ef9d 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -144,6 +144,8 @@ static inline int get_page_and_type(struct page_info *page, return rc; } +int p2m_remove_foreign(struct domain *d, unsigned long gpfn); + #endif /* _XEN_P2M_H */ /* diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index d5d6391..9288043 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -515,6 +515,12 @@ int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn); /* Set foreign mfn in the current guest's p2m table. */ int set_foreign_p2m_entry(struct domain *domp, unsigned long gfn, mfn_t mfn); +/* Remove foreign mapping from the guest's p2m table. */ +static inline int p2m_remove_foreign(struct domain *d, unsigned long gpfn) +{ + return -ENOSYS; +} + /* * Populate-on-demand */