From patchwork Thu Oct 2 10:02:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 38285 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A694420549 for ; Thu, 2 Oct 2014 10:06:37 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id d1sf960463wiv.10 for ; Thu, 02 Oct 2014 03:06:36 -0700 (PDT) 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=aEZ0ZuvaRkWHqUNF16BjPQHbeqGGFO2/yKeGEzxBV9I=; b=i0DZVpQbJZQWphsbO4FmnYS863DVpmc5DRxDwkimOC+uvQut43Qe2B0a82zR0MU3mz 5kOde8CzSgCpxPPM21iHNb07+wjK5qmLR1uhjTBmvAemdH3Mk1x8ERdyIvoUiPu4xxhB i3s5ZlrjmNfacXr5pnqsO8KxErA/NbGKJAX5HZChXnKAEE/oA+l6i0KzR72FaedmD2ol EODePz7E4GTMocamoI7bQ9gwpvGvzcqhcqzW4v5eMr561sSmI6ZPD5chpQnoOV7HaV21 pOa9acYhXzqEynkcs2DzuNVcjLasuKJNF2os+b2eaW1GaB1FooZqXze9AMXw6xAQAi5j ZvlQ== X-Gm-Message-State: ALoCoQm9l+BFhkmkMULVEFI+OD6FWIXj+ocWb6UldaqPvNHUtYbRzt8MNmnGy78XeR1CnlpTDI3S X-Received: by 10.112.137.230 with SMTP id ql6mr434364lbb.13.1412244396814; Thu, 02 Oct 2014 03:06:36 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.72 with SMTP id i8ls140045lai.25.gmail; Thu, 02 Oct 2014 03:06:36 -0700 (PDT) X-Received: by 10.112.173.134 with SMTP id bk6mr56381444lbc.36.1412244396539; Thu, 02 Oct 2014 03:06:36 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com [209.85.215.41]) by mx.google.com with ESMTPS id i3si5885260lbd.16.2014.10.02.03.06.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 02 Oct 2014 03:06:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id pn19so2055989lab.14 for ; Thu, 02 Oct 2014 03:06:36 -0700 (PDT) X-Received: by 10.112.75.233 with SMTP id f9mr24021735lbw.102.1412244396385; Thu, 02 Oct 2014 03:06:36 -0700 (PDT) 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.112.130.169 with SMTP id of9csp25663lbb; Thu, 2 Oct 2014 03:06:35 -0700 (PDT) X-Received: by 10.224.136.72 with SMTP id q8mr84582483qat.31.1412244395176; Thu, 02 Oct 2014 03:06:35 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id k7si6540890qge.58.2014.10.02.03.06.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 02 Oct 2014 03:06:35 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) 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 1XZdFs-0001CN-K5; Thu, 02 Oct 2014 10:05:00 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XZdFo-00019l-48 for xen-devel@lists.xensource.com; Thu, 02 Oct 2014 10:04:56 +0000 Received: from [193.109.254.147:20575] by server-1.bemta-14.messagelabs.com id 3C/D0-24760-7432D245; Thu, 02 Oct 2014 10:04:55 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-5.tower-27.messagelabs.com!1412244292!8300535!2 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.12.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 754 invoked from network); 2 Oct 2014 10:04:54 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-5.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 2 Oct 2014 10:04:54 -0000 X-IronPort-AV: E=Sophos;i="5.04,638,1406592000"; d="scan'208";a="178470625" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.3.181.6; Thu, 2 Oct 2014 06:04:51 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XZdFe-0001pd-Mx; Thu, 02 Oct 2014 11:04:46 +0100 From: Stefano Stabellini To: Date: Thu, 2 Oct 2014 11:02:37 +0100 Message-ID: <1412244158-12124-3-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA2 Cc: julien.grall@citrix.com, Ian.Campbell@citrix.com, Stefano Stabellini Subject: [Xen-devel] [PATCH 3/4] xen/arm: introduce XENMEM_cache_flush 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: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) 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: Introduce a new hypercall to perform cache maintenance operation on behalf of the guest. The argument is a machine address and a size. The implementation checks that the memory range is owned by the guest or the guest has been granted access to it by another domain. Signed-off-by: Stefano Stabellini --- xen/arch/arm/mm.c | 92 +++++++++++++++++++++++++++++++++++++++++++ xen/include/public/memory.h | 17 ++++++++ 2 files changed, 109 insertions(+) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index c5b48ef..f6139bd 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1134,6 +1134,98 @@ long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg) case XENMEM_get_sharing_shared_pages: case XENMEM_get_sharing_freed_pages: return 0; + case XENMEM_cache_flush: + { + struct xen_cache_flush cflush; + struct domain *d, *owner; + struct page_info *page; + uint64_t mfn, end; + uint64_t offset, size; + void *v; + int ret = 0; + + if ( copy_from_guest(&cflush, arg, 1) ) + return -EFAULT; + + d = rcu_lock_current_domain(); + if ( d == NULL ) + return -ESRCH; + + if ( (cflush.size >> PAGE_SHIFT) > (1U<> PAGE_SHIFT; + offset = cflush.addr & ~PAGE_MASK; + + if ( !mfn_valid(mfn) ) + { + printk(XENLOG_G_ERR "mfn=%llx is not valid\n", mfn); + ret = -EINVAL; + goto out; + } + + page = mfn_to_page(mfn); + if ( !page ) + { + printk(XENLOG_G_ERR "couldn't get page for mfn %llx\n", mfn); + ret = -EFAULT; + goto out; + } + + owner = page_get_owner(page); + if ( !owner ) + { + printk(XENLOG_G_ERR "couldn't get owner for mfn %llx\n", mfn); + ret = -EFAULT; + goto out; + } + + if ( owner != d && !grant_map_exists(d, owner->grant_table, mfn) ) + { + printk(XENLOG_G_ERR "mfn %llx hasn't been granted by %d to %d\n", mfn, owner->domain_id, d->domain_id); + ret = -EINVAL; + goto out; + } + + v = map_domain_page(mfn); + v += offset; + size = cflush.size - cflush.addr; + if ( size > PAGE_SIZE - offset ) + size = PAGE_SIZE - offset; + + if ( cflush.op & XENMEM_CACHE_INVAL ) + invalidate_xen_dcache_va_range(v, size); + if ( cflush.op & XENMEM_CACHE_CLEAN ) + clean_xen_dcache_va_range(v, size); + unmap_domain_page(v); + + cflush.addr += PAGE_SIZE - offset; + } + +out: + rcu_unlock_domain(d); + return ret; + } default: return -ENOSYS; diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index db961ec..4a6641d 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -571,6 +571,23 @@ DEFINE_XEN_GUEST_HANDLE(vnuma_topology_info_t); */ #define XENMEM_get_vnumainfo 26 +/* + * Issue one or more cache maintenance operations on a memory range + * owned by the calling domain or granted to the calling domain by a + * foreign domain. + */ +#define XENMEM_cache_flush 27 +struct xen_cache_flush { + /* addr is the machine address at the start of the memory range */ + uint64_t addr; + uint64_t size; +#define XENMEM_CACHE_CLEAN (1<<0) +#define XENMEM_CACHE_INVAL (1<<1) + uint32_t op; +}; +typedef struct xen_cache_flush xen_cache_flush_t; +DEFINE_XEN_GUEST_HANDLE(xen_cache_flush_t); + #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ /* Next available subop number is 27 */