From patchwork Tue Dec 17 16:27:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22606 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D26EC23FC6 for ; Tue, 17 Dec 2013 16:28:57 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id e9sf11525006qcy.1 for ; Tue, 17 Dec 2013 08:28:57 -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=BZADonGskPVFfFOGBKhzI5a/YDocA4JP9lxFLc1GBEM=; b=L6As9ZR+8nRANHq0cb6FAF+9chRDyou+jDCno6Aw4wKULK3f2/l8zAnUUdNJNEZbdy cD4oIbBaKQ3Ia8xGYPQbrBYbHrufh4BJE1U8dIiS7FLd4XUUHRcDK/aUodWpK8mxJK8f LSaDZXBcziySqHiU+K0SkIeqDv68+cQ9hTyMPG/BBf6o2gVdPN7+cZSw9JHInuDP3T6x C1DIWAbrx2zIY8EcroY0yk27ZfhfM3DSDrI1ukcMU8i+tP20ht7UD5rmGR7aBiIL4CBq QRTeknNuppB9d9mevyevkcb0trjXjXyHMD8IBXSEh4qe7XT99PNzsh2GT5RjutcznRU1 2+Kw== X-Gm-Message-State: ALoCoQnSQhx8emi7ighgnW+05HYBu28jh0Te708LUubaoBNhbI7dz8aHsKa2ruqJ6I+wthy7BRNV X-Received: by 10.236.125.79 with SMTP id y55mr797293yhh.53.1387297737632; Tue, 17 Dec 2013 08:28:57 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.17.163 with SMTP id p3ls2536036qed.41.gmail; Tue, 17 Dec 2013 08:28:57 -0800 (PST) X-Received: by 10.220.186.202 with SMTP id ct10mr11232881vcb.14.1387297737556; Tue, 17 Dec 2013 08:28:57 -0800 (PST) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id bj1si5038455ved.116.2013.12.17.08.28.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Dec 2013 08:28:57 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.174 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.174; Received: by mail-ve0-f174.google.com with SMTP id pa12so4396212veb.5 for ; Tue, 17 Dec 2013 08:28:57 -0800 (PST) X-Received: by 10.52.160.130 with SMTP id xk2mr9361079vdb.24.1387297737477; Tue, 17 Dec 2013 08:28:57 -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 u4csp79607vcz; Tue, 17 Dec 2013 08:28:56 -0800 (PST) X-Received: by 10.15.45.135 with SMTP id b7mr24275270eew.88.1387297736026; Tue, 17 Dec 2013 08:28:56 -0800 (PST) Received: from mail-ea0-f169.google.com (mail-ea0-f169.google.com [209.85.215.169]) by mx.google.com with ESMTPS id a9si5614975eew.201.2013.12.17.08.28.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Dec 2013 08:28:56 -0800 (PST) Received-SPF: neutral (google.com: 209.85.215.169 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.215.169; Received: by mail-ea0-f169.google.com with SMTP id l9so2586355eaj.28 for ; Tue, 17 Dec 2013 08:28:55 -0800 (PST) X-Received: by 10.15.45.135 with SMTP id b7mr24275232eew.88.1387297735598; Tue, 17 Dec 2013 08:28:55 -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.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2013 08:28:47 -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 09/10] xen/arm: Set foreign page type to p2m_map_foreign Date: Tue, 17 Dec 2013 16:27:57 +0000 Message-Id: <1387297678-17762-10-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.128.174 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: , Xen needs to know that the current page belongs to another domain. Also take a reference to this page. The current process to add a foreign page is: 1) get the page from the foreign p2m 2) take a reference on the page with the foreign domain in parameters 3) add the page to the current domain p2m If the foreign domain drops the page: - before 2), get_page will return NULL because the page doesn't belong anymore to the domain - after 2), the current domain already have a reference. Write will occur to an old page which is not yet released. It can corrupt the foreign domain. Signed-off-by: Julien Grall Acked-by: Ian Campbell --- Changes in v5: - Missing rcu_unlock_domain in one path - Check if the foreign page is RAM Changes in v4: - Typo s/release/released/ - Improve commit message Changes in v3: - Typoes - Check if the foreign domain is different from the current domain Changes in v2: - Even if gcc is buggy (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501) define p2m type per mapspace to let the compiler warns about unitialized values. --- xen/arch/arm/mm.c | 38 ++++++++++++++++++++++++++++++-------- xen/include/asm-arm/p2m.h | 1 + 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b1222be..6829822 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -977,6 +977,7 @@ static int xenmem_add_to_physmap_one( { unsigned long mfn = 0; int rc; + p2m_type_t t; switch ( space ) { @@ -1009,22 +1010,33 @@ static int xenmem_add_to_physmap_one( d->arch.grant_table_gpfn[idx] = gpfn; + t = p2m_ram_rw; + spin_unlock(&d->grant_table->lock); break; case XENMAPSPACE_shared_info: - if ( idx == 0 ) - mfn = virt_to_mfn(d->shared_info); - else + if ( idx != 0 ) return -EINVAL; + + mfn = virt_to_mfn(d->shared_info); + t = p2m_ram_rw; + break; case XENMAPSPACE_gmfn_foreign: { - paddr_t maddr; struct domain *od; + struct page_info *page; + p2m_type_t p2mt; od = rcu_lock_domain_by_any_id(foreign_domid); if ( od == NULL ) return -ESRCH; + if ( od == d ) + { + rcu_unlock_domain(od); + return -EINVAL; + } + rc = xsm_map_gmfn_foreign(XSM_TARGET, d, od); if ( rc ) { @@ -1032,15 +1044,25 @@ static int xenmem_add_to_physmap_one( return rc; } - maddr = p2m_lookup(od, pfn_to_paddr(idx), NULL); - if ( maddr == INVALID_PADDR ) + /* Take reference to the foreign domain page. + * Reference will be released in XENMEM_remove_from_physmap */ + page = get_page_from_gfn(od, idx, &p2mt, P2M_ALLOC); + if ( !page ) { dump_p2m_lookup(od, pfn_to_paddr(idx)); rcu_unlock_domain(od); return -EINVAL; } - mfn = maddr >> PAGE_SHIFT; + if ( !p2m_is_ram(p2mt) ) + { + put_page(page); + rcu_unlock_domain(od); + return -EINVAL; + } + + mfn = page_to_mfn(page); + t = p2m_map_foreign; rcu_unlock_domain(od); break; @@ -1051,7 +1073,7 @@ static int xenmem_add_to_physmap_one( } /* Map at new location. */ - rc = guest_physmap_add_page(d, gpfn, mfn, 0); + rc = guest_physmap_add_entry(d, gpfn, mfn, 0, t); return rc; } diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 8b7b6d0..53b3266 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -47,6 +47,7 @@ typedef enum { } p2m_type_t; #define p2m_is_foreign(_t) ((_t) == p2m_map_foreign) +#define p2m_is_ram(_t) ((_t) == p2m_ram_rw || (_t) == p2m_ram_ro) /* Initialise vmid allocator */ void p2m_vmid_allocator_init(void);