From patchwork Wed Jan 29 12:11:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 23833 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BD994202FA for ; Wed, 29 Jan 2014 12:13:52 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id gq1sf5678016obb.4 for ; Wed, 29 Jan 2014 04:13:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=AqgHXdXxWeGfHnNNryl8UPnc/OcZspxoSPtNmPX5BYM=; b=LsvBuxmmixrRBkvyHdaLgBytHZPels9Vsdoxo1kNJvoDUqWT1yniN8YYD8L7txvC2m nzdI92j2LzJx6nCZumHprA2FLpl3alZ7Z2dxHfmtNm27JXAEz+GPCE96BaU5aE6G0DV2 3bia3IqDSeZZpi0LH+Zr31V7zFn098kv9E5GMW3iaDdbhSdOn0y7kKtx16DYj/rr/XoS t8Kfgw/DYGK2CDJIZk5mvWFeIOKuZpN/+ibJNH+Qh8uZNc7tXIvyhDRY3u5VZAYP2r71 /cPDwjWK9AY1oiL79tV85EiRSHjiG8uDkXRW5uW6RXkfAPjDNLVqg+8xG+TkkrY6oysY oq/g== X-Gm-Message-State: ALoCoQmBLBOFB3HsHjDs5gVz7X/oNLotE9KfopedV7TRLZiJFBfA6GQzRsM1+Jan2th7QgfintLS X-Received: by 10.42.44.200 with SMTP id c8mr2336764icf.21.1390997631925; Wed, 29 Jan 2014 04:13:51 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.138 with SMTP id k10ls73218qge.66.gmail; Wed, 29 Jan 2014 04:13:51 -0800 (PST) X-Received: by 10.58.186.132 with SMTP id fk4mr6244856vec.9.1390997631777; Wed, 29 Jan 2014 04:13:51 -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 tt2si726096vdc.100.2014.01.29.04.13.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 Jan 2014 04:13:51 -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 la4so1063809vcb.21 for ; Wed, 29 Jan 2014 04:13:51 -0800 (PST) X-Received: by 10.52.171.39 with SMTP id ar7mr1516389vdc.5.1390997631609; Wed, 29 Jan 2014 04:13:51 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp107834vcz; Wed, 29 Jan 2014 04:13:51 -0800 (PST) X-Received: by 10.52.163.132 with SMTP id yi4mr802388vdb.30.1390997631169; Wed, 29 Jan 2014 04:13:51 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id uc1si734268vcb.53.2014.01.29.04.13.50 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 29 Jan 2014 04:13:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1W8Tzl-0005nu-Oi; Wed, 29 Jan 2014 12:11:53 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1W8Tzi-0005mJ-Ac for xen-devel@lists.xen.org; Wed, 29 Jan 2014 12:11:51 +0000 Received: from [85.158.139.211:61614] by server-7.bemta-5.messagelabs.com id 8D/B3-14867-500F8E25; Wed, 29 Jan 2014 12:11:49 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1390997506!355886!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.9.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18343 invoked from network); 29 Jan 2014 12:11:48 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 29 Jan 2014 12:11:48 -0000 X-IronPort-AV: E=Sophos;i="4.95,741,1384300800"; d="scan'208";a="95660775" Received: from accessns.citrite.net (HELO FTLPEX01CL03.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 29 Jan 2014 12:11:28 +0000 Received: from norwich.cam.xci-test.com (10.80.248.129) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.2.342.4; Wed, 29 Jan 2014 07:11:28 -0500 Received: from drall.uk.xensource.com ([10.80.16.71] helo=drall.uk.xensource.com.) by norwich.cam.xci-test.com with esmtp (Exim 4.72) (envelope-from ) id 1W8TzK-0000ow-Kw; Wed, 29 Jan 2014 12:11:26 +0000 From: Ian Campbell To: Date: Wed, 29 Jan 2014 12:11:26 +0000 Message-ID: <1390997486-3986-4-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1390997452.31814.90.camel@kazak.uk.xensource.com> References: <1390997452.31814.90.camel@kazak.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: keir@xen.org, Ian Campbell , stefano.stabellini@eu.citrix.com, ian.jackson@eu.citrix.com, julien.grall@linaro.org, tim@xen.org, george.dunlap@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH 4/4] xen/arm: clean and invalidate all guest caches by VMID after domain build. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ian.campbell@citrix.com 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: Guests are initially started with caches disabled and so we need to make sure they see consistent data in RAM (requiring a cache clean) but also that they do not have old stale data suddenly appear in the caches when they enable their caches (requiring the invalidate). We need to clean all caches in order to catch both pages dirtied by the domain builder and those which have been scrubbed but not yet flushed. Separating the two and flushing scrubbed pages at scrub time and only builder-dirtied pages here would require tracking the dirtiness state in the guest's p2m, perhaps via a new p2m type. Signed-off-by: Ian Campbell Cc: jbeulich@suse.com Cc: keir@xen.org Cc: ian.jackson@eu.citrix.com --- tools/libxc/xc_domain.c | 8 ++++++ tools/libxc/xenctrl.h | 1 + tools/libxl/libxl_create.c | 3 ++ xen/arch/arm/domctl.c | 12 ++++++++ xen/arch/arm/p2m.c | 64 +++++++++++++++++++++++++++++++++++++------ xen/include/public/domctl.h | 9 ++++++ 6 files changed, 89 insertions(+), 8 deletions(-) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index c2fdd74..e6fa4ff 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -48,6 +48,14 @@ int xc_domain_create(xc_interface *xch, return 0; } +int xc_domain_cacheflush(xc_interface *xch, uint32_t domid) +{ + DECLARE_DOMCTL; + domctl.cmd = XEN_DOMCTL_cacheflush; + domctl.domain = (domid_t)domid; + domctl.u.cacheflush.start_mfn = 0; + return do_domctl(xch, &domctl); +} int xc_domain_pause(xc_interface *xch, uint32_t domid) diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 13f816b..43dae5c 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -453,6 +453,7 @@ int xc_domain_create(xc_interface *xch, xen_domain_handle_t handle, uint32_t flags, uint32_t *pdomid); +int xc_domain_cacheflush(xc_interface *xch, uint32_t domid); /* Functions to produce a dump of a given domain diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index a604cd8..55c86f0 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -1364,7 +1364,10 @@ static void domain_create_cb(libxl__egc *egc, STATE_AO_GC(cdcs->dcs.ao); if (!rc) + { *cdcs->domid_out = domid; + xc_domain_cacheflush(CTX->xch, domid); + } libxl__ao_complete(egc, ao, rc); } diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index 546e86b..9e3b37d 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -11,12 +11,24 @@ #include #include #include +#include + +extern long p2m_cache_flush(struct domain *d, xen_pfn_t *start_mfn); long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) { switch ( domctl->cmd ) { + case XEN_DOMCTL_cacheflush: + { + long rc = p2m_cache_flush(d, &domctl->u.cacheflush.start_mfn); + if ( __copy_to_guest(u_domctl, domctl, 1) ) + rc = -EFAULT; + + return rc; + } + default: return subarch_do_domctl(domctl, d, u_domctl); } diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index a61edeb..18bd500 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -228,15 +228,26 @@ enum p2m_operation { ALLOCATE, REMOVE, RELINQUISH, + CACHEFLUSH, }; +static void do_one_cacheflush(paddr_t mfn) +{ + void *v = map_domain_page(mfn); + + flush_xen_dcache_va_range(v, PAGE_SIZE); + + unmap_domain_page(v); +} + static int apply_p2m_changes(struct domain *d, enum p2m_operation op, paddr_t start_gpaddr, paddr_t end_gpaddr, paddr_t maddr, int mattr, - p2m_type_t t) + p2m_type_t t, + xen_pfn_t *last_mfn) { int rc; struct p2m_domain *p2m = &d->arch.p2m; @@ -381,18 +392,42 @@ static int apply_p2m_changes(struct domain *d, count++; } break; + case CACHEFLUSH: + { + if ( !pte.p2m.valid || !p2m_is_ram(pte.p2m.type) ) + { + count++; + break; + } + + count += 0x10; + + do_one_cacheflush(pte.p2m.base); + } + break; } + if ( last_mfn ) + *last_mfn = addr >> PAGE_SHIFT; + /* Preempt every 2MiB (mapped) or 32 MiB (unmapped) - arbitrary */ - if ( op == RELINQUISH && count >= 0x2000 ) + switch ( op ) { - if ( hypercall_preempt_check() ) + case RELINQUISH: + case CACHEFLUSH: + if (count >= 0x2000 && hypercall_preempt_check() ) { p2m->lowest_mapped_gfn = addr >> PAGE_SHIFT; rc = -EAGAIN; goto out; } count = 0; + break; + case INSERT: + case ALLOCATE: + case REMOVE: + /* No preemption */ + break; } /* Got the next page */ @@ -438,7 +473,7 @@ int p2m_populate_ram(struct domain *d, paddr_t end) { return apply_p2m_changes(d, ALLOCATE, start, end, - 0, MATTR_MEM, p2m_ram_rw); + 0, MATTR_MEM, p2m_ram_rw, NULL); } int map_mmio_regions(struct domain *d, @@ -447,7 +482,7 @@ int map_mmio_regions(struct domain *d, paddr_t maddr) { return apply_p2m_changes(d, INSERT, start_gaddr, end_gaddr, - maddr, MATTR_DEV, p2m_mmio_direct); + maddr, MATTR_DEV, p2m_mmio_direct, NULL); } int guest_physmap_add_entry(struct domain *d, @@ -459,7 +494,7 @@ int guest_physmap_add_entry(struct domain *d, return apply_p2m_changes(d, INSERT, pfn_to_paddr(gpfn), pfn_to_paddr(gpfn + (1 << page_order)), - pfn_to_paddr(mfn), MATTR_MEM, t); + pfn_to_paddr(mfn), MATTR_MEM, t, NULL); } void guest_physmap_remove_page(struct domain *d, @@ -469,7 +504,7 @@ void guest_physmap_remove_page(struct domain *d, apply_p2m_changes(d, REMOVE, pfn_to_paddr(gpfn), pfn_to_paddr(gpfn + (1<lowest_mapped_gfn), pfn_to_paddr(p2m->max_mapped_gfn), pfn_to_paddr(INVALID_MFN), - MATTR_MEM, p2m_invalid); + MATTR_MEM, p2m_invalid, NULL); +} + +long p2m_cache_flush(struct domain *d, xen_pfn_t *start_mfn) +{ + struct p2m_domain *p2m = &d->arch.p2m; + + *start_mfn = MAX(*start_mfn, p2m->next_gfn_to_relinquish); + + return apply_p2m_changes(d, CACHEFLUSH, + pfn_to_paddr(*start_mfn), + pfn_to_paddr(p2m->max_mapped_gfn), + pfn_to_paddr(INVALID_MFN), + MATTR_MEM, p2m_invalid, start_mfn); } unsigned long gmfn_to_mfn(struct domain *d, unsigned long gpfn) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 91f01fa..d7b22c3 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -885,6 +885,13 @@ struct xen_domctl_set_max_evtchn { typedef struct xen_domctl_set_max_evtchn xen_domctl_set_max_evtchn_t; DEFINE_XEN_GUEST_HANDLE(xen_domctl_set_max_evtchn_t); +struct xen_domctl_cacheflush { + /* Updated for progress */ + xen_pfn_t start_mfn; +}; +typedef struct xen_domctl_cacheflush xen_domctl_cacheflush_t; +DEFINE_XEN_GUEST_HANDLE(xen_domctl_cacheflush_t); + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -954,6 +961,7 @@ struct xen_domctl { #define XEN_DOMCTL_setnodeaffinity 68 #define XEN_DOMCTL_getnodeaffinity 69 #define XEN_DOMCTL_set_max_evtchn 70 +#define XEN_DOMCTL_cacheflush 71 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1012,6 +1020,7 @@ struct xen_domctl { struct xen_domctl_set_max_evtchn set_max_evtchn; struct xen_domctl_gdbsx_memio gdbsx_guest_memio; struct xen_domctl_set_broken_page_p2m set_broken_page_p2m; + struct xen_domctl_cacheflush cacheflush; struct xen_domctl_gdbsx_pauseunp_vcpu gdbsx_pauseunp_vcpu; struct xen_domctl_gdbsx_domstatus gdbsx_domstatus; uint8_t pad[128];