qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Joelle van Dyne" <j@getutm.app>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PULL 23/55] util: Extract flush_icache_range to cacheflush.c
Date: Mon, 21 Dec 2020 15:44:15 +0100	[thread overview]
Message-ID: <20201221144447.26161-24-pbonzini@redhat.com> (raw)
In-Reply-To: <20201221144447.26161-1-pbonzini@redhat.com>

From: Richard Henderson <richard.henderson@linaro.org>

This has been a tcg-specific function, but is also in use
by hardware accelerators via physmem.c.  This can cause
link errors when tcg is disabled.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Joelle van Dyne <j@getutm.app>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20201214140314.18544-3-richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 MAINTAINERS               |  2 ++
 include/qemu/cacheflush.h | 24 +++++++++++++
 softmmu/physmem.c         |  1 +
 tcg/aarch64/tcg-target.h  |  5 ---
 tcg/arm/tcg-target.h      |  5 ---
 tcg/i386/tcg-target.h     |  4 ---
 tcg/mips/tcg-target.h     | 11 ------
 tcg/ppc/tcg-target.c.inc  | 22 ------------
 tcg/ppc/tcg-target.h      |  1 -
 tcg/riscv/tcg-target.h    |  5 ---
 tcg/s390/tcg-target.h     |  4 ---
 tcg/sparc/tcg-target.h    |  8 -----
 tcg/tcg.c                 |  1 +
 tcg/tci/tcg-target.h      |  4 ---
 util/cacheflush.c         | 71 +++++++++++++++++++++++++++++++++++++++
 util/meson.build          |  2 +-
 16 files changed, 100 insertions(+), 70 deletions(-)
 create mode 100644 include/qemu/cacheflush.h
 create mode 100644 util/cacheflush.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 1e7c8f0488..d7ff660c1e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -119,6 +119,8 @@ F: softmmu/cpus.c
 F: cpus-common.c
 F: accel/tcg/
 F: accel/stubs/tcg-stub.c
+F: util/cacheinfo.c
+F: util/cacheflush.c
 F: scripts/decodetree.py
 F: docs/devel/decodetree.rst
 F: include/exec/cpu*.h
diff --git a/include/qemu/cacheflush.h b/include/qemu/cacheflush.h
new file mode 100644
index 0000000000..58ae488491
--- /dev/null
+++ b/include/qemu/cacheflush.h
@@ -0,0 +1,24 @@
+/*
+ * Flush the host cpu caches.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_CACHEFLUSH_H
+#define QEMU_CACHEFLUSH_H
+
+#if defined(__i386__) || defined(__x86_64__) || defined(__s390__)
+
+static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
+{
+    /* icache is coherent and does not require flushing. */
+}
+
+#else
+
+void flush_icache_range(uintptr_t start, uintptr_t stop);
+
+#endif
+
+#endif /* QEMU_CACHEFLUSH_H */
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 67b53d39e4..8b9ffc41c2 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -22,6 +22,7 @@
 #include "qapi/error.h"
 
 #include "qemu/cutils.h"
+#include "qemu/cacheflush.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
 #include "exec/target_page.h"
diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h
index 663dd0b95e..8a6b97598e 100644
--- a/tcg/aarch64/tcg-target.h
+++ b/tcg/aarch64/tcg-target.h
@@ -148,11 +148,6 @@ typedef enum {
 #define TCG_TARGET_DEFAULT_MO (0)
 #define TCG_TARGET_HAS_MEMORY_BSWAP     1
 
-static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
-{
-    __builtin___clear_cache((char *)start, (char *)stop);
-}
-
 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
 
 #ifdef CONFIG_SOFTMMU
diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h
index 17e771374d..f1955ce4ac 100644
--- a/tcg/arm/tcg-target.h
+++ b/tcg/arm/tcg-target.h
@@ -134,11 +134,6 @@ enum {
 #define TCG_TARGET_DEFAULT_MO (0)
 #define TCG_TARGET_HAS_MEMORY_BSWAP     1
 
-static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
-{
-    __builtin___clear_cache((char *) start, (char *) stop);
-}
-
 /* not defined -- call should be eliminated at compile time */
 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
 
diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h
index abd4ac7fc0..cd067e0b30 100644
--- a/tcg/i386/tcg-target.h
+++ b/tcg/i386/tcg-target.h
@@ -206,10 +206,6 @@ extern bool have_avx2;
 #define TCG_TARGET_extract_i64_valid(ofs, len) \
     (((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32)
 
-static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
-{
-}
-
 static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
                                             uintptr_t jmp_addr, uintptr_t addr)
 {
diff --git a/tcg/mips/tcg-target.h b/tcg/mips/tcg-target.h
index c6b091d849..92c1d63da3 100644
--- a/tcg/mips/tcg-target.h
+++ b/tcg/mips/tcg-target.h
@@ -198,20 +198,9 @@ extern bool use_mips32r2_instructions;
 #define TCG_TARGET_HAS_ext16u_i64       0 /* andi rt, rs, 0xffff */
 #endif
 
-#ifdef __OpenBSD__
-#include <machine/sysarch.h>
-#else
-#include <sys/cachectl.h>
-#endif
-
 #define TCG_TARGET_DEFAULT_MO (0)
 #define TCG_TARGET_HAS_MEMORY_BSWAP     1
 
-static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
-{
-    cacheflush ((void *)start, stop-start, ICACHE);
-}
-
 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
 
 #ifdef CONFIG_SOFTMMU
diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc
index 18ee989f95..0d068ec8ab 100644
--- a/tcg/ppc/tcg-target.c.inc
+++ b/tcg/ppc/tcg-target.c.inc
@@ -3863,25 +3863,3 @@ void tcg_register_jit(void *buf, size_t buf_size)
     tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame));
 }
 #endif /* __ELF__ */
-
-void flush_icache_range(uintptr_t start, uintptr_t stop)
-{
-    uintptr_t p, start1, stop1;
-    size_t dsize = qemu_dcache_linesize;
-    size_t isize = qemu_icache_linesize;
-
-    start1 = start & ~(dsize - 1);
-    stop1 = (stop + dsize - 1) & ~(dsize - 1);
-    for (p = start1; p < stop1; p += dsize) {
-        asm volatile ("dcbst 0,%0" : : "r"(p) : "memory");
-    }
-    asm volatile ("sync" : : : "memory");
-
-    start &= start & ~(isize - 1);
-    stop1 = (stop + isize - 1) & ~(isize - 1);
-    for (p = start1; p < stop1; p += isize) {
-        asm volatile ("icbi 0,%0" : : "r"(p) : "memory");
-    }
-    asm volatile ("sync" : : : "memory");
-    asm volatile ("isync" : : : "memory");
-}
diff --git a/tcg/ppc/tcg-target.h b/tcg/ppc/tcg-target.h
index be10363956..a509a19628 100644
--- a/tcg/ppc/tcg-target.h
+++ b/tcg/ppc/tcg-target.h
@@ -175,7 +175,6 @@ extern bool have_vsx;
 #define TCG_TARGET_HAS_bitsel_vec       have_vsx
 #define TCG_TARGET_HAS_cmpsel_vec       0
 
-void flush_icache_range(uintptr_t start, uintptr_t stop);
 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
 
 #define TCG_TARGET_DEFAULT_MO (0)
diff --git a/tcg/riscv/tcg-target.h b/tcg/riscv/tcg-target.h
index 032439d806..c1bd52bb9a 100644
--- a/tcg/riscv/tcg-target.h
+++ b/tcg/riscv/tcg-target.h
@@ -159,11 +159,6 @@ typedef enum {
 #define TCG_TARGET_HAS_mulsh_i64        1
 #endif
 
-static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
-{
-    __builtin___clear_cache((char *)start, (char *)stop);
-}
-
 /* not defined -- call should be eliminated at compile time */
 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
 
diff --git a/tcg/s390/tcg-target.h b/tcg/s390/tcg-target.h
index 63c8797bd3..b4feb2f55a 100644
--- a/tcg/s390/tcg-target.h
+++ b/tcg/s390/tcg-target.h
@@ -145,10 +145,6 @@ enum {
     TCG_AREG0 = TCG_REG_R10,
 };
 
-static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
-{
-}
-
 static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
                                             uintptr_t jmp_addr, uintptr_t addr)
 {
diff --git a/tcg/sparc/tcg-target.h b/tcg/sparc/tcg-target.h
index 633841ebf2..d8b0e32e2e 100644
--- a/tcg/sparc/tcg-target.h
+++ b/tcg/sparc/tcg-target.h
@@ -168,14 +168,6 @@ extern bool use_vis3_instructions;
 #define TCG_TARGET_DEFAULT_MO (0)
 #define TCG_TARGET_HAS_MEMORY_BSWAP     1
 
-static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
-{
-    uintptr_t p;
-    for (p = start & -8; p < ((stop + 7) & -8); p += 8) {
-        __asm__ __volatile__("flush\t%0" : : "r" (p));
-    }
-}
-
 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
 
 #define TCG_TARGET_NEED_POOL_LABELS
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 43c6cf8f52..ebb9466ffc 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -35,6 +35,7 @@
 #include "qemu/host-utils.h"
 #include "qemu/qemu-print.h"
 #include "qemu/timer.h"
+#include "qemu/cacheflush.h"
 
 /* Note: the long term plan is to reduce the dependencies on the QEMU
    CPU definitions. Currently they are used for qemu_ld/st
diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h
index 8c1c1d265d..b84480f989 100644
--- a/tcg/tci/tcg-target.h
+++ b/tcg/tci/tcg-target.h
@@ -191,10 +191,6 @@ void tci_disas(uint8_t opc);
 
 #define HAVE_TCG_QEMU_TB_EXEC
 
-static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
-{
-}
-
 /* We could notice __i386__ or __s390x__ and reduce the barriers depending
    on the host.  But if you want performance, you use the normal backend.
    We prefer consistency across hosts on this.  */
diff --git a/util/cacheflush.c b/util/cacheflush.c
new file mode 100644
index 0000000000..2881832a38
--- /dev/null
+++ b/util/cacheflush.c
@@ -0,0 +1,71 @@
+/*
+ * Flush the host cpu caches.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/cacheflush.h"
+
+
+#if defined(__i386__) || defined(__x86_64__) || defined(__s390__)
+
+/* Caches are coherent and do not require flushing; symbol inline. */
+
+#elif defined(__mips__)
+
+#ifdef __OpenBSD__
+#include <machine/sysarch.h>
+#else
+#include <sys/cachectl.h>
+#endif
+
+void flush_icache_range(uintptr_t start, uintptr_t stop)
+{
+    cacheflush((void *)start, stop - start, ICACHE);
+}
+
+#elif defined(__powerpc__)
+
+void flush_icache_range(uintptr_t start, uintptr_t stop)
+{
+    uintptr_t p, start1, stop1;
+    size_t dsize = qemu_dcache_linesize;
+    size_t isize = qemu_icache_linesize;
+
+    start1 = start & ~(dsize - 1);
+    stop1 = (stop + dsize - 1) & ~(dsize - 1);
+    for (p = start1; p < stop1; p += dsize) {
+        asm volatile ("dcbst 0,%0" : : "r"(p) : "memory");
+    }
+    asm volatile ("sync" : : : "memory");
+
+    start &= start & ~(isize - 1);
+    stop1 = (stop + isize - 1) & ~(isize - 1);
+    for (p = start1; p < stop1; p += isize) {
+        asm volatile ("icbi 0,%0" : : "r"(p) : "memory");
+    }
+    asm volatile ("sync" : : : "memory");
+    asm volatile ("isync" : : : "memory");
+}
+
+#elif defined(__sparc__)
+
+void flush_icache_range(uintptr_t start, uintptr_t stop)
+{
+    uintptr_t p;
+
+    for (p = start & -8; p < ((stop + 7) & -8); p += 8) {
+        __asm__ __volatile__("flush\t%0" : : "r" (p));
+    }
+}
+
+#else
+
+void flush_icache_range(uintptr_t start, uintptr_t stop)
+{
+    __builtin___clear_cache((char *)start, (char *)stop);
+}
+
+#endif
diff --git a/util/meson.build b/util/meson.build
index f359af0d46..a3dfc0f966 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -21,7 +21,7 @@ util_ss.add(files('envlist.c', 'path.c', 'module.c'))
 util_ss.add(files('host-utils.c'))
 util_ss.add(files('bitmap.c', 'bitops.c'))
 util_ss.add(files('fifo8.c'))
-util_ss.add(files('cacheinfo.c'))
+util_ss.add(files('cacheinfo.c', 'cacheflush.c'))
 util_ss.add(files('error.c', 'qemu-error.c'))
 util_ss.add(files('qemu-print.c'))
 util_ss.add(files('id.c'))
-- 
2.29.2




  parent reply	other threads:[~2020-12-21 15:09 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-21 14:43 [PULL 00/55] Misc patches for 2020-12-21 Paolo Bonzini
2020-12-21 14:43 ` [PULL 01/55] gitlab: include aarch64-softmmu and ppc64-softmmu cross-system-build Paolo Bonzini
2020-12-21 14:43 ` [PULL 02/55] configure: move gettext detection to meson.build Paolo Bonzini
2020-12-21 14:43 ` [PULL 03/55] configure: add --without-default-features Paolo Bonzini
2020-12-21 14:43 ` [PULL 04/55] python: add __repr__ to ConsoleSocket to aid debugging Paolo Bonzini
2020-12-21 14:43 ` [PULL 05/55] gitlab: move --without-default-devices build from Travis Paolo Bonzini
2020-12-21 14:43 ` [PULL 06/55] gitlab: add --without-default-features build Paolo Bonzini
2020-12-21 14:43 ` [PULL 07/55] tests/tcg: build tests with -Werror Paolo Bonzini
2020-12-21 14:44 ` [PULL 08/55] gitlab-CI: Test 32-bit builds with the fedora-i386-cross container Paolo Bonzini
2020-12-21 14:44 ` [PULL 09/55] tests/docker: Remove the remainders of debian9 containers from the Makefile Paolo Bonzini
2020-12-21 14:44 ` [PULL 10/55] tests: update for rename of CentOS8 PowerTools repo Paolo Bonzini
2020-12-21 14:44 ` [PULL 11/55] configure: document --without-default-{features, devices} Paolo Bonzini
2020-12-21 14:44 ` [PULL 12/55] vl: initialize displays _after_ exiting preconfiguration Paolo Bonzini
2020-12-21 14:44 ` [PULL 13/55] test-char: Destroy chardev correctly at char_file_test_internal() Paolo Bonzini
2020-12-21 14:44 ` [PULL 14/55] qom: Assert that objects being destroyed have no parent Paolo Bonzini
2020-12-21 14:44 ` [PULL 15/55] target/i386: Check privilege level for protected mode 'int N' task gate Paolo Bonzini
2020-12-21 14:44 ` [PULL 16/55] configure,meson: add option to enable LTO Paolo Bonzini
2020-12-21 14:44 ` [PULL 17/55] cfi: Initial support for cfi-icall in QEMU Paolo Bonzini
2020-12-21 14:44 ` [PULL 18/55] check-block: enable iotests with cfi-icall Paolo Bonzini
2020-12-21 14:44 ` [PULL 19/55] configure,meson: support Control-Flow Integrity Paolo Bonzini
2020-12-21 14:44 ` [PULL 20/55] docs: Add CFI Documentation Paolo Bonzini
2020-12-21 14:44 ` [PULL 21/55] build-sys: fix -static linking of libvhost-user Paolo Bonzini
2020-12-21 14:44 ` [PULL 22/55] remove TCG includes from common code Paolo Bonzini
2020-12-21 14:44 ` Paolo Bonzini [this message]
2020-12-21 14:44 ` [PULL 24/55] trace: do not include TCG helper tracepoints in no-TCG builds Paolo Bonzini
2020-12-21 14:44 ` [PULL 25/55] Makefile: add dummy target for build.ninja dependencies Paolo Bonzini
2020-12-21 14:44 ` [PULL 26/55] meson: update submodule to 0.56.0 Paolo Bonzini
2020-12-21 14:44 ` [PULL 27/55] meson: switch minimum meson version " Paolo Bonzini
2020-12-21 14:44 ` [PULL 28/55] meson: fix detection of curses with pkgconfig Paolo Bonzini
2020-12-21 14:44 ` [PULL 29/55] meson: use pkg-config method for libudev Paolo Bonzini
2020-12-21 14:44 ` [PULL 30/55] meson: use dependency to gate block modules Paolo Bonzini
2020-12-21 14:44 ` [PULL 31/55] meson: cleanup Kconfig.host handling Paolo Bonzini
2020-12-21 14:44 ` [PULL 32/55] configure: remove useless code to check for Xen PCI passthrough Paolo Bonzini
2020-12-21 14:44 ` [PULL 33/55] configure: remove variable bogus_os Paolo Bonzini
2020-12-21 14:44 ` [PULL 34/55] configure: accept --enable-slirp Paolo Bonzini
2020-12-21 14:44 ` [PULL 35/55] configure: remove CONFIG_FILEVERSION and CONFIG_PRODUCTVERSION Paolo Bonzini
2020-12-21 14:44 ` [PULL 36/55] brlapi: convert to meson Paolo Bonzini
2020-12-21 14:44 ` [PULL 37/55] curl: remove compatibility code, require 7.29.0 Paolo Bonzini
2020-12-21 14:44 ` [PULL 38/55] curl: convert to meson Paolo Bonzini
2020-12-21 14:44 ` [PULL 39/55] glusterfs: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 40/55] bzip2: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 41/55] libiscsi: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 42/55] libnfs: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 43/55] libssh: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 44/55] rbd: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 45/55] lzo: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 46/55] snappy: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 47/55] lzfse: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 48/55] zstd: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 49/55] seccomp: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 50/55] virtfs: " Paolo Bonzini
2021-01-07 13:58   ` Bruce Rogers
2021-01-07 14:49     ` Paolo Bonzini
2021-01-07 15:31       ` Bruce Rogers
2020-12-21 14:44 ` [PULL 51/55] cap_ng: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 52/55] libattr: " Paolo Bonzini
2020-12-21 14:44 ` [PULL 53/55] meson.build: convert --with-default-devices " Paolo Bonzini
2020-12-21 14:44 ` [PULL 54/55] configure: move tests/qemu-iotests/common.env generation " Paolo Bonzini
2020-12-21 14:44 ` [PULL 55/55] win32: drop fd registration to the main-loop on setting non-block Paolo Bonzini
2021-01-01 17:05 ` [PULL 00/55] Misc patches for 2020-12-21 Peter Maydell
2021-01-01 19:59   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201221144447.26161-24-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=j@getutm.app \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).