From patchwork Fri Oct 3 14:50:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 38325 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C9D782057C for ; Fri, 3 Oct 2014 14:54:46 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id b57sf905520eek.8 for ; Fri, 03 Oct 2014 07:54:45 -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=/96ydgSWv3D+mrGXxnL0uuQt4yCThUPGO0IjpslL7sg=; b=Tb8iTcXoIiGhHTcwrzf5VAet0Nqd7oAbF5Cbdn7gOyqG+XHN7VdkjmcWRElPvr63/O 3TDhSwy0Z4wcbBpMdGsYmL/swgNF6xoRreUzATvY7Ex51rTpKZQCbtDgSS3WLLQdIwsU G/7o4yPEcUF7RYV/trk3UaCaMpAr1qUGFsxEfUHHTbZuzuNdcOlkC07Wa8onzI/MQjnX j9z2zkxdSokb+FQ/hHLgTRhjxQXF/tvnmHayelzVId7SdIl3S+j1VW421FBxNgPdhcGb VeF689PfBb4O4GjfjxQ2L7nyKw3IL6BujNn1dppr5wg+qGGgDjFUt7Px80DE1VWyhtzZ MAfg== X-Gm-Message-State: ALoCoQnW1cYM3+dMfEoH45votWXan0Ie+Xj+rosC/xmi+IN192KuO6Dzza5mSAMZl/1QyT0vvQFj X-Received: by 10.152.29.130 with SMTP id k2mr1069812lah.3.1412348085835; Fri, 03 Oct 2014 07:54:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.39 with SMTP id x7ls393146lax.31.gmail; Fri, 03 Oct 2014 07:54:45 -0700 (PDT) X-Received: by 10.152.202.135 with SMTP id ki7mr6650017lac.16.1412348085367; Fri, 03 Oct 2014 07:54:45 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by mx.google.com with ESMTPS id z8si11458751lbf.132.2014.10.03.07.54.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 03 Oct 2014 07:54:44 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id l4so1150943lbv.10 for ; Fri, 03 Oct 2014 07:54:44 -0700 (PDT) X-Received: by 10.153.7.73 with SMTP id da9mr5135424lad.56.1412348084591; Fri, 03 Oct 2014 07:54:44 -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 of9csp242212lbb; Fri, 3 Oct 2014 07:54:44 -0700 (PDT) X-Received: by 10.224.26.84 with SMTP id d20mr7976908qac.11.1412348083789; Fri, 03 Oct 2014 07:54:43 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id u109si12626549qge.81.2014.10.03.07.54.43 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 03 Oct 2014 07:54:43 -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 1Xa4EE-0002rr-AQ; Fri, 03 Oct 2014 14:53:06 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xa4ED-0002rM-74 for xen-devel@lists.xensource.com; Fri, 03 Oct 2014 14:53:05 +0000 Received: from [193.109.254.147:44712] by server-8.bemta-14.messagelabs.com id 51/85-01875-058BE245; Fri, 03 Oct 2014 14:53:04 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1412347981!13226146!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 31142 invoked from network); 3 Oct 2014 14:53:03 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 3 Oct 2014 14:53:03 -0000 X-IronPort-AV: E=Sophos;i="5.04,647,1406592000"; d="scan'208";a="178978987" 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; Fri, 3 Oct 2014 10:52:59 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1Xa4E2-0000Fl-As; Fri, 03 Oct 2014 15:52:54 +0100 From: Stefano Stabellini To: Date: Fri, 3 Oct 2014 15:50:44 +0100 Message-ID: <1412347845-27755-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 v2 3/4] xen/arm: introduce GNTTABOP_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.217.179 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 --- Changes in v2: - do not check for mfn_to_page errors; - take a reference to the page; - replace printk with gdprintk; - split long line; - remove out label; - move rcu_lock_current_domain down before the loop. - move the hypercall to GNTTABOP; - take a spin_lock before calling grant_map_exists. --- xen/common/grant_table.c | 73 ++++++++++++++++++++++++++++++++++++++ xen/include/public/grant_table.h | 19 ++++++++++ 2 files changed, 92 insertions(+) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 7a6399b..d5bb4f7 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -2641,6 +2641,79 @@ do_grant_table_op( } break; } + case GNTTABOP_cache_flush: + { + struct gnttab_cache_flush cflush; + struct domain *d, *owner; + struct page_info *page; + uint64_t mfn; + void *v; + + /* currently unimplemented */ + if ( count != 1 ) + return -ENOSYS; + + if ( copy_from_guest(&cflush, uop, 1) ) + return -EFAULT; + + if ( cflush.offset + cflush.size > PAGE_SIZE ) + return -EINVAL; + + if ( cflush.size == 0 || cflush.op == 0 ) + return 0; + + if ( cflush.op & ~(GNTTAB_CACHE_INVAL|GNTTAB_CACHE_CLEAN) ) + return -EINVAL; + + /* currently unimplemented */ + if ( cflush.a.ref != 0 ) + return -ENOSYS; + + d = rcu_lock_current_domain(); + if ( d == NULL ) + return -ESRCH; + + mfn = cflush.a.dev_bus_addr >> PAGE_SHIFT; + + if ( !mfn_valid(mfn) ) + { + gdprintk(XENLOG_G_ERR, "mfn=%llx is not valid\n", mfn); + rcu_unlock_domain(d); + return -EINVAL; + } + + page = mfn_to_page(mfn); + owner = page_get_owner_and_reference(page); + if ( !owner ) + { + rcu_unlock_domain(d); + return -EFAULT; + } + + spin_lock(&owner->grant_table->lock); + + if ( !grant_map_exists(d, owner->grant_table, mfn) ) + { + spin_unlock(&owner->grant_table->lock); + put_page(page); + rcu_unlock_domain(d); + gdprintk(XENLOG_G_ERR, "mfn %llx hasn't been granted by %d to %d\n", + mfn, owner->domain_id, d->domain_id); + return -EINVAL; + } + + v = map_domain_page(mfn); + v += cflush.offset; + + if ( cflush.op & GNTTAB_CACHE_INVAL ) + invalidate_xen_dcache_va_range(v, cflush.size); + if ( cflush.op & GNTTAB_CACHE_CLEAN ) + clean_xen_dcache_va_range(v, cflush.size); + + unmap_domain_page(v); + spin_unlock(&owner->grant_table->lock); + put_page(page); + } default: rc = -ENOSYS; break; diff --git a/xen/include/public/grant_table.h b/xen/include/public/grant_table.h index b8a3d6c..1833bba 100644 --- a/xen/include/public/grant_table.h +++ b/xen/include/public/grant_table.h @@ -309,6 +309,7 @@ typedef uint16_t grant_status_t; #define GNTTABOP_get_status_frames 9 #define GNTTABOP_get_version 10 #define GNTTABOP_swap_grant_ref 11 +#define GNTTABOP_cache_flush 12 #endif /* __XEN_INTERFACE_VERSION__ */ /* ` } */ @@ -574,6 +575,24 @@ struct gnttab_swap_grant_ref { typedef struct gnttab_swap_grant_ref gnttab_swap_grant_ref_t; DEFINE_XEN_GUEST_HANDLE(gnttab_swap_grant_ref_t); +/* + * Issue one or more cache maintenance operations on a portion of a + * page granted to the calling domain by a foreign domain. + */ +struct gnttab_cache_flush { + union { + uint64_t dev_bus_addr; + grant_ref_t ref; + } a; + uint32_t offset; /* offset from start of grant */ + uint32_t size; /* size within the grant */ +#define GNTTAB_CACHE_CLEAN (1<<0) +#define GNTTAB_CACHE_INVAL (1<<1) + uint32_t op; +}; +typedef struct gnttab_cache_flush gnttab_cache_flush_t; +DEFINE_XEN_GUEST_HANDLE(gnttab_cache_flush_t); + #endif /* __XEN_INTERFACE_VERSION__ */ /*