From patchwork Tue Dec 17 14:28:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22576 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 610B123FC6 for ; Tue, 17 Dec 2013 14:28:28 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id hu19sf11420968vcb.11 for ; Tue, 17 Dec 2013 06: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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=j5c/dWURZZezuSrebDHYiVOSjvbvQG+VP3ugu/+nAtU=; b=Ge7R1p5gxxcVprnUDD72TgaCytuxTEwdK2DnmuVu0rXUtCCqfBcu2y/N+qwFfeFVYW sU/nyvRpm0G//nSjrYv9bZaB9I8AZ6PS4fFMP6596TlTHXP8FCBe5qb0BQOBqjG0XDa6 NBA3TUSITbc1UGmfkIvoCqZE/7qswdK8KzEUWJ+NhV4LSVCy+B/1Dcl5qFNspaGFeOTB ohiGz3f72f++BEQ7lqZs4LtH7eKWO5/nwjZq0AkuF+RuxLKK8HOv7VujDGPm48NmZwXv xvxkhFEcMbp2rpH/QoDCUwTSvx9QC5ueo8kr4mo4Q/eYqylHN0lryAwpdGH+Cri4HApL nk8g== X-Gm-Message-State: ALoCoQnUPil0NBXwfyekyqlh/Rf3R0v6B2/4Iw4sJcUnIEVeHomTu0f5lUpGVVgq+DpXgUk5/jrw X-Received: by 10.58.249.148 with SMTP id yu20mr6093295vec.11.1387290507430; Tue, 17 Dec 2013 06:28:27 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.49.70 with SMTP id s6ls2487436qen.34.gmail; Tue, 17 Dec 2013 06:28:27 -0800 (PST) X-Received: by 10.58.118.84 with SMTP id kk20mr6492957veb.26.1387290507133; Tue, 17 Dec 2013 06:28:27 -0800 (PST) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id ti3si4966328vdc.2.2013.12.17.06.28.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Dec 2013 06:28:27 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.176 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.176; Received: by mail-vc0-f176.google.com with SMTP id lf12so4138199vcb.21 for ; Tue, 17 Dec 2013 06:28:27 -0800 (PST) X-Received: by 10.58.246.136 with SMTP id xw8mr1421971vec.41.1387290507026; Tue, 17 Dec 2013 06:28:27 -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 u4csp72418vcz; Tue, 17 Dec 2013 06:28:26 -0800 (PST) X-Received: by 10.14.101.4 with SMTP id a4mr23228790eeg.28.1387290506019; Tue, 17 Dec 2013 06:28:26 -0800 (PST) Received: from mail-ee0-f50.google.com (mail-ee0-f50.google.com [74.125.83.50]) by mx.google.com with ESMTPS id m49si4869674eeg.178.2013.12.17.06.28.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Dec 2013 06:28:25 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.50 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.83.50; Received: by mail-ee0-f50.google.com with SMTP id c41so2976577eek.9 for ; Tue, 17 Dec 2013 06:28:25 -0800 (PST) X-Received: by 10.14.3.130 with SMTP id 2mr23095206eeh.36.1387290505059; Tue, 17 Dec 2013 06:28:25 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id b41sm53514400eef.16.2013.12.17.06.28.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2013 06:28:22 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, ian.campbell@citrix.com, ian.jackson@eu.citrix.com, stefano.stabellini@citrix.com, Julien Grall , Keir Fraser Subject: [PATCH v6] xen/arm: Allow balooning working with 1:1 memory mapping Date: Tue, 17 Dec 2013 14:28:19 +0000 Message-Id: <1387290499-3970-1-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 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.176 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: , With the lack of iommu, dom0 must have a 1:1 memory mapping for all these guest physical address. When the ballon decides to give back a page to the kernel, this page must have the same address as previously. Otherwise, we will loose the 1:1 mapping and will break DMA-capable devices. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich Cc: Keir Fraser Acked-by: Stefano Stabellini --- Release: This is a bug that prevents DMA-capable devices to work after a guest has started. Changes in v6: - Use # instead of 0x - Make sure that d is evaluated in is_domain_direct_mapped Changes in v5: - Export dom0_11_mapping and transform is_domain_direct_mapped in macro - Add ifndef in common code to define is_domain_direct_mapped Changes in v4: - Fix typoes - Update comment in the code Changes in v3: - Remove spurious page = NULL - Rename is_dom0_mapped_11 to is_domain_direct_mapped - Coding style Changes in v2: - Drop CONFIG_ARM and add is_dom0_mapped_11 --- xen/arch/arm/domain_build.c | 2 +- xen/common/memory.c | 35 ++++++++++++++++++++++++++++++++++- xen/include/asm-arm/domain.h | 3 +++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index faff88e..47b781b 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -22,7 +22,7 @@ static unsigned int __initdata opt_dom0_max_vcpus; integer_param("dom0_max_vcpus", opt_dom0_max_vcpus); -static int dom0_11_mapping = 1; +int dom0_11_mapping = 1; #define DOM0_MEM_DEFAULT 0x8000000 /* 128 MiB */ static u64 __initdata dom0_mem = DOM0_MEM_DEFAULT; diff --git a/xen/common/memory.c b/xen/common/memory.c index eb7b72b..51f11ff 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -29,6 +29,10 @@ #include #include +#ifndef is_domain_direct_mapped +# define is_domain_direct_mapped(d) ((void)(d), 0) +#endif + struct memop_args { /* INPUT */ struct domain *domain; /* Domain to be affected. */ @@ -122,7 +126,29 @@ static void populate_physmap(struct memop_args *a) } else { - page = alloc_domheap_pages(d, a->extent_order, a->memflags); + if ( is_domain_direct_mapped(d) ) + { + mfn = gpfn; + if ( !mfn_valid(mfn) ) + { + gdprintk(XENLOG_INFO, "Invalid mfn %#"PRI_xen_pfn"\n", + mfn); + goto out; + } + + page = mfn_to_page(mfn); + if ( !get_page(page, d) ) + { + gdprintk(XENLOG_INFO, + "mfn %#"PRI_xen_pfn" doesn't belong to the" + " domain\n", mfn); + goto out; + } + put_page(page); + } + else + page = alloc_domheap_pages(d, a->extent_order, a->memflags); + if ( unlikely(page == NULL) ) { if ( !opt_tmem || (a->extent_order != 0) ) @@ -270,6 +296,13 @@ static void decrease_reservation(struct memop_args *a) && p2m_pod_decrease_reservation(a->domain, gmfn, a->extent_order) ) continue; + /* With the lack for iommu on some ARM platform, domain with DMA-capable + * device must retrieve the same pfn when the hypercall + * populate_physmap is called. + */ + if ( is_domain_direct_mapped(a->domain) ) + continue; + for ( j = 0; j < (1 << a->extent_order); j++ ) if ( !guest_remove_page(a->domain, gmfn + j) ) goto out; diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 28d39a0..e2202a6 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -86,6 +86,9 @@ enum domain_type { #define is_pv64_domain(d) (0) #endif +extern int dom0_11_mapping; +#define is_domain_direct_mapped(d) ((d) == dom0 && dom0_11_mapping) + struct vtimer { struct vcpu *v; int irq;