From patchwork Mon Dec 16 16:36:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22523 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5C12223FC7 for ; Mon, 16 Dec 2013 16:36:50 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id m1sf19119465oag.5 for ; Mon, 16 Dec 2013 08:36:49 -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=+dSEXuThUcVAETrKiO2O/Bg3tJsnQK0JRzdBE01C84g=; b=TKTvx0tJk+vNjAdjKKobjzEVs9zRkfdD0zFijJ9LSvKGd6NG926tLp0lKRK6Pva5Rt 38w4zANHTjv0Zm3cInu38U9NauU/m5SfoZl5fbSZYmM5BozJpCKKhP2HlvEft0+CMVJk g5wyuZDkZSDSNw32P1gqSSNw49RKD8dlLVShuVZzqKqr/QZMXwpHkjio2y4ZGUr81Mq5 +JadQobleky54LpLqnB9dxwPjHTir1sxzibJmlq/PRkdhNanot1vtr5kx4dxRb+lhuLW nzENJxH81gDjwxsMIBzrw4VGqi6ImN1Ndwm13AslwK7vleP9XUts7bP+0v07r6l4auQ1 klhA== X-Gm-Message-State: ALoCoQnWo2I716SzHoJA5WVvvg8rU4uqGmk2KCAawb2ldTEJLmT5U2D8sI+9PWVmNw0LHrKyL/Iz X-Received: by 10.182.251.230 with SMTP id zn6mr6314896obc.14.1387211809391; Mon, 16 Dec 2013 08:36:49 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.83.2 with SMTP id m2ls2215659qey.37.gmail; Mon, 16 Dec 2013 08:36:49 -0800 (PST) X-Received: by 10.52.188.202 with SMTP id gc10mr596643vdc.84.1387211809304; Mon, 16 Dec 2013 08:36:49 -0800 (PST) Received: from mail-vb0-f52.google.com (mail-vb0-f52.google.com [209.85.212.52]) by mx.google.com with ESMTPS id sj10si4127292vcb.15.2013.12.16.08.36.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 08:36:49 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.52 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.52; Received: by mail-vb0-f52.google.com with SMTP id p5so3335933vbn.11 for ; Mon, 16 Dec 2013 08:36:49 -0800 (PST) X-Received: by 10.220.159.4 with SMTP id h4mr8862159vcx.1.1387211809186; Mon, 16 Dec 2013 08:36:49 -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 u4csp1952vcz; Mon, 16 Dec 2013 08:36:48 -0800 (PST) X-Received: by 10.14.223.198 with SMTP id v46mr17747766eep.20.1387211807900; Mon, 16 Dec 2013 08:36:47 -0800 (PST) Received: from mail-ea0-f179.google.com (mail-ea0-f179.google.com [209.85.215.179]) by mx.google.com with ESMTPS id f8si1430971eep.162.2013.12.16.08.36.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 08:36:47 -0800 (PST) Received-SPF: neutral (google.com: 209.85.215.179 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.215.179; Received: by mail-ea0-f179.google.com with SMTP id r15so2365453ead.10 for ; Mon, 16 Dec 2013 08:36:47 -0800 (PST) X-Received: by 10.14.204.135 with SMTP id h7mr9861611eeo.104.1387211806991; Mon, 16 Dec 2013 08:36:46 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id o47sm44090360eem.21.2013.12.16.08.36.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2013 08:36:46 -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 v4] xen/arm: Allow balooning working with 1:1 memory mapping Date: Mon, 16 Dec 2013 16:36:43 +0000 Message-Id: <1387211803-24933-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.212.52 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 --- Release: This is a bug that prevents DMA-capable devices to work after a guest has started. 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 | 5 +++++ xen/common/memory.c | 31 ++++++++++++++++++++++++++++++- xen/include/asm-arm/domain.h | 2 ++ xen/include/asm-x86/domain.h | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index faff88e..2bbee36 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -65,6 +65,11 @@ struct vcpu *__init alloc_dom0_vcpu0(void) return alloc_vcpu(dom0, 0, 0); } +int is_domain_direct_mapped(struct domain *d) +{ + return (dom0_11_mapping && d == dom0); +} + static void allocate_memory_11(struct domain *d, struct kernel_info *kinfo) { paddr_t start; diff --git a/xen/common/memory.c b/xen/common/memory.c index eb7b72b..edbbdc4 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -122,7 +122,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 +292,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..dbc1389 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -86,6 +86,8 @@ enum domain_type { #define is_pv64_domain(d) (0) #endif +int is_domain_direct_mapped(struct domain *d); + struct vtimer { struct vcpu *v; int irq; diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index 9d39061..2c7f809 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -16,6 +16,8 @@ #define is_pv_32on64_domain(d) (is_pv_32bit_domain(d)) #define is_pv_32on64_vcpu(v) (is_pv_32on64_domain((v)->domain)) +#define is_domain_direct_mapped(d) (0) + #define is_hvm_pv_evtchn_domain(d) (has_hvm_container_domain(d) && \ d->arch.hvm_domain.irq.callback_via_type == HVMIRQ_callback_vector) #define is_hvm_pv_evtchn_vcpu(v) (is_hvm_pv_evtchn_domain(v->domain))