From nobody Sat Sep 28 22:17:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1610051022; cv=none; d=zohomail.com; s=zohoarc; b=HzkfKPxipk2ViPaFiFttYCnkduTXGSW1OuaNfBtJuI/6EUNauivh9XMTp4PuOyz6u9J8je1vZWwkNzsbtDsGmVEx3nLHEtI/3g3NLKnuNtXFhmnyaxpxKgrbjQ7k2XvICyDPe1Brm7w08yihW3D+lXkXXnw4hQbsPYbkQFCFHWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610051022; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=48z+GqlaobtZlttO/+L7peMtbYaAP6yESc8MWoNMMuc=; b=M1cyB90JoNUcdT76FHXKClgq3+b2U5aEBq1TQR4xLPDvpvCQ+uqrbXd+ImEdkSOM7md/MLlSA3CNJ5hppKAcODDZB/TEwXBzPmddH4kD8lybGpqypXdwAp9oJhkuHiUNc2BW5BHvdNfHPjFje4JIClQ01HvgUQQpfPov8JFH0Dw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161005102199543.32131915666935; Thu, 7 Jan 2021 12:23:41 -0800 (PST) Received: from localhost ([::1]:39412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxbop-0001NT-FT for importer@patchew.org; Thu, 07 Jan 2021 15:23:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxbga-0000sQ-Te for qemu-devel@nongnu.org; Thu, 07 Jan 2021 15:15:08 -0500 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:35169) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kxbgY-0001Rp-QZ for qemu-devel@nongnu.org; Thu, 07 Jan 2021 15:15:08 -0500 Received: by mail-pg1-x533.google.com with SMTP id n7so5756993pgg.2 for ; Thu, 07 Jan 2021 12:15:06 -0800 (PST) Received: from localhost.localdomain (rrcs-173-197-107-21.west.biz.rr.com. [173.197.107.21]) by smtp.gmail.com with ESMTPSA id v6sm6516265pfi.31.2021.01.07.12.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 12:15:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=48z+GqlaobtZlttO/+L7peMtbYaAP6yESc8MWoNMMuc=; b=I78dbytRXYvJ6Njh94mxv/VfHQmkQCHMvNYIyFsDzi4Kt0BSwX67O7xavuiKVuC5ho vhG2bAQ+BaLr33xb9cHw3iv+C1O4nc9N1UEH/QC+7Cw1JLQlyaGNUuROTM9/sIx164mB 1A6cynxmq8p6hE+0CD/LCZjZm102tCSjAmW5wV/Jiw+C0KbBlr1EQM18ciz8NAP4AoHb jEKnYgnFK871JAj4UhbWXVX7dbCCMcwl9LHZ11YMQEPb5tcjdP7Sqcn3iaDZUX4Ddkpr n3CV/MA380r9R9v/dokah+dNwcW1VTZEojXRjkxN48yAvq0pgBSL2zRHbaIp9pEKtkbQ YHoA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=48z+GqlaobtZlttO/+L7peMtbYaAP6yESc8MWoNMMuc=; b=fbJGnIowKKMJgdrq3hiWUIcs+RuSC7PTRPi3kQthIyYxQUBUelakWRknJXQCm65hUI WdkUx6jmMJaUze3kfQHAiKysF/VtvLcoJhLaEReQ3VjR+wYIGXYh0uFINciWNQ9sQ8sl NjIYB+ZqSAXb5qZlgo+uz4OeK3sTuTfVpACURy4UdG9O222ydl/o/ZIXF/365vnS3t7i A3L0luEH3HKZu+BT699w0pkLc9ckybunGPc/NeZYG+SEtlhGhbL4PRgdJp/4khLJf6Xj QScUJ8Ex4StyYwNc5crMV2mJuyZRfWxS73taBYenPUF4FonZhlTjZp7ZP38m3EECpipL K/HQ== X-Gm-Message-State: AOAM5334t837hTaOLdG6xQ0V9beaycHZKdBvstUeCFbCahVtU+SNATrq y2mLBOsApTimUhCCVaxZkddrTnwqVCDF9A== X-Google-Smtp-Source: ABdhPJwi3LT4IUzZoiC6DUGUS4uv198M6Q38jazqKbPcjvIMMzFm+PzhHMkexu0hdal0vGo5mzm9Gw== X-Received: by 2002:aa7:8104:0:b029:1ae:684f:d140 with SMTP id b4-20020aa781040000b02901ae684fd140mr337939pfi.62.1610050505129; Thu, 07 Jan 2021 12:15:05 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 07/47] util: Enhance flush_icache_range with separate data pointer Date: Thu, 7 Jan 2021 10:14:08 -1000 Message-Id: <20210107201448.1152301-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210107201448.1152301-1-richard.henderson@linaro.org> References: <20210107201448.1152301-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Joelle van Dyne Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We are shortly going to have a split rw/rx jit buffer. Depending on the host, we need to flush the dcache at the rw data pointer and flush the icache at the rx code pointer. For now, the two passed pointers are identical, so there is no effective change in behaviour. Reviewed-by: Joelle van Dyne Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- include/qemu/cacheflush.h | 15 ++++++++++++-- softmmu/physmem.c | 2 +- tcg/tcg.c | 6 ++++-- util/cacheflush.c | 38 +++++++++++++++++++++--------------- util/cacheinfo.c | 8 +++++--- tcg/aarch64/tcg-target.c.inc | 2 +- tcg/mips/tcg-target.c.inc | 2 +- tcg/ppc/tcg-target.c.inc | 4 ++-- tcg/sparc/tcg-target.c.inc | 4 ++-- 9 files changed, 51 insertions(+), 30 deletions(-) diff --git a/include/qemu/cacheflush.h b/include/qemu/cacheflush.h index 58ae488491..ae20bcda73 100644 --- a/include/qemu/cacheflush.h +++ b/include/qemu/cacheflush.h @@ -8,16 +8,27 @@ #ifndef QEMU_CACHEFLUSH_H #define QEMU_CACHEFLUSH_H =20 +/** + * flush_idcache_range: + * @rx: instruction address + * @rw: data address + * @len: length to flush + * + * Flush @len bytes of the data cache at @rw and the icache at @rx + * to bring them in sync. The two addresses may be different virtual + * mappings of the same physical page(s). + */ + #if defined(__i386__) || defined(__x86_64__) || defined(__s390__) =20 -static inline void flush_icache_range(uintptr_t start, uintptr_t stop) +static inline void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t = len) { /* icache is coherent and does not require flushing. */ } =20 #else =20 -void flush_icache_range(uintptr_t start, uintptr_t stop); +void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len); =20 #endif =20 diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 8b9ffc41c2..6301f4f0a5 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2946,7 +2946,7 @@ static inline MemTxResult address_space_write_rom_int= ernal(AddressSpace *as, invalidate_and_set_dirty(mr, addr1, l); break; case FLUSH_CACHE: - flush_icache_range((uintptr_t)ram_ptr, (uintptr_t)ram_ptr = + l); + flush_idcache_range((uintptr_t)ram_ptr, (uintptr_t)ram_ptr= , l); break; } } diff --git a/tcg/tcg.c b/tcg/tcg.c index 9bdc450196..759a41d848 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1079,7 +1079,8 @@ void tcg_prologue_init(TCGContext *s) =20 buf1 =3D s->code_ptr; #ifndef CONFIG_TCG_INTERPRETER - flush_icache_range((uintptr_t)buf0, (uintptr_t)buf1); + flush_idcache_range((uintptr_t)buf0, (uintptr_t)buf0, + tcg_ptr_byte_diff(buf1, buf0)); #endif =20 /* Deduct the prologue from the buffer. */ @@ -4328,7 +4329,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) =20 #ifndef CONFIG_TCG_INTERPRETER /* flush instruction cache */ - flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr); + flush_idcache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_buf, + tcg_ptr_byte_diff(s->code_ptr, s->code_buf)); #endif =20 return tcg_current_code_size(s); diff --git a/util/cacheflush.c b/util/cacheflush.c index 2881832a38..92805efe49 100644 --- a/util/cacheflush.c +++ b/util/cacheflush.c @@ -21,29 +21,32 @@ #include #endif =20 -void flush_icache_range(uintptr_t start, uintptr_t stop) +void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len) { - cacheflush((void *)start, stop - start, ICACHE); + if (rx !=3D rw) { + cacheflush((void *)rw, len, DCACHE); + } + cacheflush((void *)rx, len, ICACHE); } =20 #elif defined(__powerpc__) =20 -void flush_icache_range(uintptr_t start, uintptr_t stop) +void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len) { - uintptr_t p, start1, stop1; + uintptr_t p, b, e; size_t dsize =3D qemu_dcache_linesize; size_t isize =3D qemu_icache_linesize; =20 - start1 =3D start & ~(dsize - 1); - stop1 =3D (stop + dsize - 1) & ~(dsize - 1); - for (p =3D start1; p < stop1; p +=3D dsize) { + b =3D rw & ~(dsize - 1); + e =3D (rw + len + dsize - 1) & ~(dsize - 1); + for (p =3D b; p < e; p +=3D dsize) { asm volatile ("dcbst 0,%0" : : "r"(p) : "memory"); } asm volatile ("sync" : : : "memory"); =20 - start &=3D start & ~(isize - 1); - stop1 =3D (stop + isize - 1) & ~(isize - 1); - for (p =3D start1; p < stop1; p +=3D isize) { + b =3D rx & ~(isize - 1); + e =3D (rx + len + isize - 1) & ~(isize - 1); + for (p =3D b; p < e; p +=3D isize) { asm volatile ("icbi 0,%0" : : "r"(p) : "memory"); } asm volatile ("sync" : : : "memory"); @@ -52,20 +55,23 @@ void flush_icache_range(uintptr_t start, uintptr_t stop) =20 #elif defined(__sparc__) =20 -void flush_icache_range(uintptr_t start, uintptr_t stop) +void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len) { - uintptr_t p; - - for (p =3D start & -8; p < ((stop + 7) & -8); p +=3D 8) { + /* No additional data flush to the RW virtual address required. */ + uintptr_t p, end =3D (rx + len + 7) & -8; + for (p =3D rx & -8; p < end; p +=3D 8) { __asm__ __volatile__("flush\t%0" : : "r" (p)); } } =20 #else =20 -void flush_icache_range(uintptr_t start, uintptr_t stop) +void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len) { - __builtin___clear_cache((char *)start, (char *)stop); + if (rw !=3D rx) { + __builtin___clear_cache((char *)rw, (char *)rw + len); + } + __builtin___clear_cache((char *)rx, (char *)rx + len); } =20 #endif diff --git a/util/cacheinfo.c b/util/cacheinfo.c index 7804c186b6..b182f0b693 100644 --- a/util/cacheinfo.c +++ b/util/cacheinfo.c @@ -166,9 +166,11 @@ static void fallback_cache_info(int *isize, int *dsize) *isize =3D *dsize; } else { #if defined(_ARCH_PPC) - /* For PPC, we're going to use the icache size computed for - flush_icache_range. Which means that we must use the - architecture minimum. */ + /* + * For PPC, we're going to use the cache sizes computed for + * flush_idcache_range. Which means that we must use the + * architecture minimum. + */ *isize =3D *dsize =3D 16; #else /* Otherwise, 64 bytes is not uncommon. */ diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc index 26f71cb599..83af3108a4 100644 --- a/tcg/aarch64/tcg-target.c.inc +++ b/tcg/aarch64/tcg-target.c.inc @@ -1363,7 +1363,7 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintp= tr_t jmp_addr, } pair =3D (uint64_t)i2 << 32 | i1; qatomic_set((uint64_t *)jmp_addr, pair); - flush_icache_range(jmp_addr, jmp_addr + 8); + flush_idcache_range(jmp_addr, jmp_addr, 8); } =20 static inline void tcg_out_goto_label(TCGContext *s, TCGLabel *l) diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc index 41be574e89..c255ecb444 100644 --- a/tcg/mips/tcg-target.c.inc +++ b/tcg/mips/tcg-target.c.inc @@ -2660,7 +2660,7 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintp= tr_t jmp_addr, uintptr_t addr) { qatomic_set((uint32_t *)jmp_addr, deposit32(OPC_J, 0, 26, addr >> 2)); - flush_icache_range(jmp_addr, jmp_addr + 4); + flush_idcache_range(jmp_addr, jmp_addr, 4); } =20 typedef struct { diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc index 0d068ec8ab..b756281042 100644 --- a/tcg/ppc/tcg-target.c.inc +++ b/tcg/ppc/tcg-target.c.inc @@ -1753,12 +1753,12 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uin= tptr_t jmp_addr, /* As per the enclosing if, this is ppc64. Avoid the _Static_asse= rt within qatomic_set that would fail to build a ppc32 host. */ qatomic_set__nocheck((uint64_t *)jmp_addr, pair); - flush_icache_range(jmp_addr, jmp_addr + 8); + flush_idcache_range(jmp_addr, jmp_addr, 8); } else { intptr_t diff =3D addr - jmp_addr; tcg_debug_assert(in_range_b(diff)); qatomic_set((uint32_t *)jmp_addr, B | (diff & 0x3fffffc)); - flush_icache_range(jmp_addr, jmp_addr + 4); + flush_idcache_range(jmp_addr, jmp_addr, 4); } } =20 diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc index 6775bd30fc..6e2d755f6a 100644 --- a/tcg/sparc/tcg-target.c.inc +++ b/tcg/sparc/tcg-target.c.inc @@ -1836,7 +1836,7 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintp= tr_t jmp_addr, if (!USE_REG_TB) { qatomic_set((uint32_t *)jmp_addr, deposit32(CALL, 0, 30, br_disp >> 2)); - flush_icache_range(jmp_addr, jmp_addr + 4); + flush_idcache_range(jmp_addr, jmp_addr, 4); return; } =20 @@ -1860,5 +1860,5 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintp= tr_t jmp_addr, } =20 qatomic_set((uint64_t *)jmp_addr, deposit64(i2, 32, 32, i1)); - flush_icache_range(jmp_addr, jmp_addr + 8); + flush_idcache_range(jmp_addr, jmp_addr, 8); } --=20 2.25.1