From patchwork Mon Dec 16 17:00:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22528 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B86AE23FC7 for ; Mon, 16 Dec 2013 17:00:43 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id c14sf10103502vea.2 for ; Mon, 16 Dec 2013 09:00:42 -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=FZN11EWsJwEpajRRuqLQUnkx697McyVW8J9OAbP+s1A=; b=lvpOip835//PIncMdzf2QxcSoD3tdPXMd6eKQekX9+qNz36YcRK3jT6Vb3yTrkZduw FzJ8N3D6XyToztZmOe0bNp8e2E36W0B84rO7sL6UvfOSXoNTObcujeaY3LxarZb0dv3k sGyVX4vsH/yHyY+AFFoWglbeY7YlIq/xxjTRAj2LemnPMlXj3MqbnGX6nEceMLIX/TwB lUTmGGQdG9192APakma3KP/fRjEJNKNTfkJno2uz8jjffXUzk/03BuYC1mWoNDdRzeFv kVVL486xrrJkFcBHqsWOtUPjDVduk5E97Gpd6CBPfl2nxeK6nVMzj2yN4Z3ikzcs66UJ qkEQ== X-Gm-Message-State: ALoCoQlFbN1cwvMgWzvmfR2NNY3eAmv9//q86VUtCEnvJsReCzeRJ+ilMruiQX+d4vrencYgV6pr X-Received: by 10.236.13.36 with SMTP id a24mr919840yha.50.1387213242844; Mon, 16 Dec 2013 09:00:42 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.84.234 with SMTP id c10ls2165789qez.50.gmail; Mon, 16 Dec 2013 09:00:42 -0800 (PST) X-Received: by 10.52.36.80 with SMTP id o16mr1896156vdj.48.1387213242574; Mon, 16 Dec 2013 09:00:42 -0800 (PST) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id er6si4130617vdc.23.2013.12.16.09.00.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 09:00:42 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.169 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.169; Received: by mail-ve0-f169.google.com with SMTP id c14so3507759vea.14 for ; Mon, 16 Dec 2013 09:00:42 -0800 (PST) X-Received: by 10.52.78.193 with SMTP id d1mr812933vdx.57.1387213242444; Mon, 16 Dec 2013 09:00:42 -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 u4csp3446vcz; Mon, 16 Dec 2013 09:00:41 -0800 (PST) X-Received: by 10.14.203.6 with SMTP id e6mr18114089eeo.33.1387213241288; Mon, 16 Dec 2013 09:00:41 -0800 (PST) Received: from mail-ee0-f51.google.com (mail-ee0-f51.google.com [74.125.83.51]) by mx.google.com with ESMTPS id l2si1547886een.104.2013.12.16.09.00.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 09:00:41 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.51 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=74.125.83.51; Received: by mail-ee0-f51.google.com with SMTP id b15so2372370eek.38 for ; Mon, 16 Dec 2013 09:00:40 -0800 (PST) X-Received: by 10.15.82.8 with SMTP id z8mr18145504eey.25.1387213240727; Mon, 16 Dec 2013 09:00:40 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id e43sm44324349eep.7.2013.12.16.09.00.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2013 09:00:39 -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 , Keir Fraser , Jan Beulich Subject: [PATCH v5] xen/arm: Allow balooning working with 1:1 memory mapping Date: Mon, 16 Dec 2013 17:00:37 +0000 Message-Id: <1387213237-1216-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.128.169 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 Cc: Keir Fraser Cc: Jan Beulich Reviewed-by: Jan Beulich --- Release: This is a bug that prevents DMA-capable devices to work after a guest has started. 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..1a93196 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 0x%"PRI_xen_pfn"\n", + mfn); + goto out; + } + + page = mfn_to_page(mfn); + if ( !get_page(page, d) ) + { + gdprintk(XENLOG_INFO, + "mfn 0x%"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..3419c31 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) (dom0_11_mapping && (d) == dom0) + struct vtimer { struct vcpu *v; int irq;