From patchwork Fri Jan 27 18:17:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamas Lengyel X-Patchwork-Id: 9542483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2AE33604A0 for ; Fri, 27 Jan 2017 18:20:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DB4828389 for ; Fri, 27 Jan 2017 18:20:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11E3A2832F; Fri, 27 Jan 2017 18:20:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D402128356 for ; Fri, 27 Jan 2017 18:20:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXB6B-00021V-87; Fri, 27 Jan 2017 18:18:11 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXB69-00021P-MB for xen-devel@lists.xenproject.org; Fri, 27 Jan 2017 18:18:09 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id E3/85-00888-0EE8B885; Fri, 27 Jan 2017 18:18:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupikeJIrShJLcpLzFFi42Lxqg121n3Q1x1 h8KWd3+L7lslMDowehz9cYQlgjGLNzEvKr0hgzVh27xVLwUW5iuUrljI2MM6T7GLk4hASmMoo 8eFkNxuIwyLwhkVi0qUJLCCOhMA7Fonm21MZuxg5gZwYiWe/v7JC2FUSa+78AosLCWhKHNxwh hli1EQmiTnrl4IVsQkYSVy92sMGYosIKEncWzWZCaSIWWAdo8SczzPBioQFwiQ+LjwPZrMIqE r8f98BZvMK2EtsujKVHWKbvMSutousExj5FjAyrGLUKE4tKkst0jUy0ksqykzPKMlNzMzRNTQ w1stNLS5OTE/NSUwq1kvOz93ECAyXegYGxh2MU0/4HWKU5GBSEuXltuiOEOJLyk+pzEgszogv Ks1JLT7EKMPBoSTBe6UXKCdYlJqeWpGWmQMMXJi0BAePkgjvZZA0b3FBYm5xZjpE6hSjLseuX ZdfMgmx5OXnpUqJ8y4GKRIAKcoozYMbAYuiS4yyUsK8jAwMDEI8BalFuZklqPKvGMU5GJWEed eDTOHJzCuB2/QK6AgmoCPEf3SBHFGSiJCSamDMMasMfFTyVSRs7vuzBmbeB35q+LDNm/nm/5o 191Yu1FYvm9u3vvdt+MIIBfOJDwVEpTnP8WpqGku2XfesaQ5dPLvr0wyeDfk6n65uS0meuX+9 K7N6zIbtiU4Mgvf/TeYREuru3efqekvjAI9XyrWnp9Yk1Gxc6awys9Brpvrj7ijD/1aH5/Aqs RRnJBpqMRcVJwIAx7nK9J0CAAA= X-Env-Sender: tamas.lengyel@zentific.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1485541086!75204702!1 X-Originating-IP: [74.125.83.67] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 35977 invoked from network); 27 Jan 2017 18:18:08 -0000 Received: from mail-pg0-f67.google.com (HELO mail-pg0-f67.google.com) (74.125.83.67) by server-7.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 27 Jan 2017 18:18:08 -0000 Received: by mail-pg0-f67.google.com with SMTP id 3so7807272pgj.1 for ; Fri, 27 Jan 2017 10:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zentific-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=PvAvGOkqX5w5F7pIhDSzSNRwbEX6jw5pGNyTdHU+FRQ=; b=u8Ck/jo3QNQXuh2DKT4ydqjlvOPWWir1q1Wr2jdKLKLw+iRAapYgIFVBRnNFoqjTi5 sLsHnK1MITfbzkLzgFOHPCA19i8aKKPE5nnr4HnBnf6sGs73FBg70SDDIqn+wTQ5XA9d QzPAf0TfOxGpxDDwHgrLevOtA13lzN6nZs7RJG5tG7nqusf0aiR0wlPoWIdw/OzODhyV 3XPVCj193HkNyFQ7qlKIuu9i8bmOdd5qF/GEtl4toySwiMuvGu4bpvnWRAj7QonCCD3j KepTAGtzv/2mg0j+99CGewLbrCDTHuRIJNJtffP/ciEF6AaLzvEmRbLjl0tywGIFR2Tz x1cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PvAvGOkqX5w5F7pIhDSzSNRwbEX6jw5pGNyTdHU+FRQ=; b=LRsEeY1Sfv9tIr0v3Y6CM6/eTpP8qfAYdtqts2psDzU1uIMjQKW3u8rzqV6+4UCLCc 6WiNHLy5NulRzF1XNJdaedYuZZ9Pv/lVqIShnDM8SMlCyjHKuJc3KGdXOK7eJ98r60R1 C2jBQaZj9qHC1/UjaGJ6t5+6uO6Osk7J+jX0bCA0Gmswip3ntfaUAt/nJZ7j8MqHwsy+ V6L98I8R21f0Cl8S6axgJr3h98jQT8XMcc8QV5YhTH+CZIYfK40lesF6NNI/Q/tmINrj 0Od19R0fmZFErMB6LmIiCqdw1SjAknkABTrwhVbsXEGj+Ar95p91Qt6XZcYoLkWi52N0 KC9Q== X-Gm-Message-State: AIkVDXI4veBVzKNk8IdIhKDpyZ57TsC0md0OJMzgCfKs6KKBp18+1YWZCk0SHxgGYsyEvw== X-Received: by 10.99.166.25 with SMTP id t25mr11141807pge.196.1485541086410; Fri, 27 Jan 2017 10:18:06 -0800 (PST) Received: from l1.lan (c-73-14-35-59.hsd1.co.comcast.net. [73.14.35.59]) by smtp.gmail.com with ESMTPSA id g28sm13059280pgn.3.2017.01.27.10.18.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Jan 2017 10:18:05 -0800 (PST) From: Tamas K Lengyel To: xen-devel@lists.xenproject.org Date: Fri, 27 Jan 2017 11:17:56 -0700 Message-Id: <20170127181756.16184-1-tamas.lengyel@zentific.com> X-Mailer: git-send-email 2.11.0 Cc: Tamas K Lengyel , Julien Grall , Stefano Stabellini , Ian Jackson Subject: [Xen-devel] [PATCH v3] xen/arm: flush icache as well when XEN_DOMCTL_cacheflush is issued X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP When the toolstack modifies memory of a running ARM VM it may happen that the underlying memory of a current vCPU PC is changed. Without flushing the icache the vCPU may continue executing stale instructions. In this patch we introduce VA-based icache flushing macros. Also expose the xc_domain_cacheflush through xenctrl.h. Signed-off-by: Tamas K Lengyel Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Stefano Stabellini Cc: Julien Grall Note: patch has been verified to solve stale icache issues on the HiKey platform. v3: Flush the entire icache instead of flush by VA v2: Return 0 on x86 and clarify comment in xenctrl.h --- tools/libxc/include/xenctrl.h | 8 ++++++++ tools/libxc/xc_domain.c | 6 +++--- tools/libxc/xc_private.h | 3 --- xen/arch/arm/mm.c | 10 ++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 63c616ff6a..a2f23fcd5a 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2720,6 +2720,14 @@ int xc_livepatch_revert(xc_interface *xch, char *name, uint32_t timeout); int xc_livepatch_unload(xc_interface *xch, char *name, uint32_t timeout); int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout); +/* + * Ensure cache coherency after memory modifications. A call to this function + * is only required on ARM as the x86 architecture provides cache coherency + * guarantees. Calling this function on x86 is allowed but has no effect. + */ +int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, + xen_pfn_t start_pfn, xen_pfn_t nr_pfns); + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 296b8523b5..98ab6ba3fd 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -74,10 +74,10 @@ int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, /* * The x86 architecture provides cache coherency guarantees which prevent * the need for this hypercall. Avoid the overhead of making a hypercall - * just for Xen to return -ENOSYS. + * just for Xen to return -ENOSYS. It is safe to ignore this call on x86 + * so we just return 0. */ - errno = ENOSYS; - return -1; + return 0; #else DECLARE_DOMCTL; domctl.cmd = XEN_DOMCTL_cacheflush; diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h index 97445ae1fe..fddebdc917 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -366,9 +366,6 @@ void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits); /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush); -int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, - xen_pfn_t start_pfn, xen_pfn_t nr_pfns); - #define MAX_MMU_UPDATES 1024 struct xc_mmu { mmu_update_t updates[MAX_MMU_UPDATES]; diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 99588a330d..596283fc99 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -390,6 +390,16 @@ void flush_page_to_ram(unsigned long mfn) clean_and_invalidate_dcache_va_range(v, PAGE_SIZE); unmap_domain_page(v); + + /* + * For some of the instruction cache (such as VIPT), the entire I-Cache + * needs to be flushed to guarantee that all the aliases of a given + * physical address will be removed from the cache. + * Invalidating the I-Cache by VA highly depends on the behavior of the + * I-Cache (See D4.9.2 in ARM DDI 0487A.k_iss10775). Instead of using flush + * by VA on select platforms, we just flush the entire cache here. + */ + invalidate_icache(); } void __init arch_init_memory(void)