From patchwork Fri Dec 13 19:37:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22363 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 A4EC6202E2 for ; Fri, 13 Dec 2013 19:38:27 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id o6sf8548048oag.3 for ; Fri, 13 Dec 2013 11:38: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=fnswXIREngvdmWnuLgDq9hkVpOUTNdgs0i/is4IYKqo=; b=ST58YGZIJbIpjRcdK8YCMjjYaxhF9giVKfNUnYCQJlf1Webr4fn/QdS0WzNd6zBmVf MX/Nd7RQTFpZ2WrdOkqanmFX9ewo+ur7k+O2EZ+fSc8TALL3v1Wdt82DM25zfV6NMLUo VaE1zxF/dsINAZUtMJrJyeJ5fW2jVSTB349uKJEbOMt2fXN/yxfYAatvy/bUoirhegK/ T8TcUCcKcKDGNK0no0+5j3v9BsF3toGmjmqJmqj1li4yzhxIJ6FNdGHVMrRySav/cDF+ i3ktY43QSfvLNtnTD8HJ6SIx4vfMOoUrJJ960iyXuWyPv7c6Pn6HdP/bYmvIRNbLzzaR 3tmQ== X-Gm-Message-State: ALoCoQmeb6XnroIP8GMmqzi307NOgcsW59erRWYWcce7xFsNZHDZGRN3lbxfv5h7w4t7Vy6mMoCz X-Received: by 10.43.44.136 with SMTP id ug8mr1468012icb.17.1386963507225; Fri, 13 Dec 2013 11:38:27 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.85.162 with SMTP id i2ls1116431qez.39.gmail; Fri, 13 Dec 2013 11:38:27 -0800 (PST) X-Received: by 10.221.60.134 with SMTP id ws6mr1977040vcb.44.1386963506978; Fri, 13 Dec 2013 11:38:26 -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 pv1si1076692veb.56.2013.12.13.11.38.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 11:38:26 -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 hq11so1620282vcb.36 for ; Fri, 13 Dec 2013 11:38:26 -0800 (PST) X-Received: by 10.220.74.69 with SMTP id t5mr1998606vcj.18.1386963506898; Fri, 13 Dec 2013 11:38: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 u4csp64212vcz; Fri, 13 Dec 2013 11:38:26 -0800 (PST) X-Received: by 10.14.119.136 with SMTP id n8mr4568030eeh.82.1386963505520; Fri, 13 Dec 2013 11:38:25 -0800 (PST) Received: from mail-ee0-f54.google.com (mail-ee0-f54.google.com [74.125.83.54]) by mx.google.com with ESMTPS id l44si3143696eem.145.2013.12.13.11.38.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 11:38:25 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.54 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.83.54; Received: by mail-ee0-f54.google.com with SMTP id e51so906769eek.13 for ; Fri, 13 Dec 2013 11:38:25 -0800 (PST) X-Received: by 10.14.205.201 with SMTP id j49mr4536431eeo.85.1386963505096; Fri, 13 Dec 2013 11:38:25 -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.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Dec 2013 11:38:23 -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 10/11] xen/arm: Set foreign page type to p2m_map_foreign Date: Fri, 13 Dec 2013 19:37:40 +0000 Message-Id: <1386963461-6520-11-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.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: , 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 --- 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 | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b1222be..0434296 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,29 @@ 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; od = rcu_lock_domain_by_any_id(foreign_domid); if ( od == NULL ) return -ESRCH; + if ( od == d ) + return -EINVAL; + rc = xsm_map_gmfn_foreign(XSM_TARGET, d, od); if ( rc ) { @@ -1032,15 +1040,18 @@ 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, NULL, P2M_ALLOC); + if ( !page ) { dump_p2m_lookup(od, pfn_to_paddr(idx)); rcu_unlock_domain(od); return -EINVAL; } - mfn = maddr >> PAGE_SHIFT; + mfn = page_to_mfn(page); + t = p2m_map_foreign; rcu_unlock_domain(od); break; @@ -1051,7 +1062,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; }