From patchwork Wed Oct 4 08:01:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 729252 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp221436wrs; Wed, 4 Oct 2023 01:11:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzXqT331NA9KKq/dgHc4wm12CT0j1dr+R6AAZ75A/eOwNWQyJ8D4e8Q2bYbZ7Jw6CC+3pu X-Received: by 2002:a05:6214:5585:b0:64d:254a:63dc with SMTP id mi5-20020a056214558500b0064d254a63dcmr1649741qvb.19.1696407119571; Wed, 04 Oct 2023 01:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696407119; cv=none; d=google.com; s=arc-20160816; b=H43hvV3gf7La0snmVEDALup381zD4/GXWZOchnY8kYHVbi72wvt/tKumpHUoNFmAwT /FvZj/JUEHjb37hhlYDYQwsTR1TYMfIsxP1yltTsp4j09ai0EAZDJvrFoz2It4DFkVTw tvSX3cy0Ky3AIkc90LAMOdXQXHTRMYbVw2u0QWek5NF4neaLOuAv9MVuTvcPAMLXME5n Anq6aw6V9f1mKc6+EN4+N2RvlIeWS1AD3JJO0aHCclp/d9f73HmdGzhB5KxQG56EJbLx 04JghurerWb1jYJvqaIDaH+IdCBmeOdNWZI+mYg5p+XKCNQcbC+1WVBtjLr8ySjHzRpN 9XwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=EWxsWOPYzdCN0md1pHqryXn+JJWcftwdi44zVlQ5nUY=; fh=xJ1URYKcMN3TM0/XAv5v+aCN+5tIbzAdcfBx5UNgoLw=; b=BQS8qVbw5LPUyz/2fz9KmHvrjHf+IJNUNjHt1uuc9z126j1br7ip1ZAH7ZOt3H9WPe G4oX/tR1+blFTQ+fjo+GDR24z8/W7oCS6uqfTSVLiamwdyC3PYAdBj+1MSqnYvVhb5EX A4Zd9LXDEFN5eq5rSomAXIP8sOeoueQgO2x8Ax5gGpHtIq/7pYLXmO1OPmUNyZoihP7f xWKpGjIlN6WtWiH1QUMlncuYf9S2Vr8Z/q1Q+fUVisl3HLev8X6c4bbsp/IcjC3kqnS0 5WRGc7NJb83B8ELNqqWP9P27QaQKj1zKAutU69ohgs+1JfOZZWHQvxC99h4mcmVE0MPs +R0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n12-20020a0ce48c000000b00655dd255108si1223077qvl.375.2023.10.04.01.11.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 01:11:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnwsy-00054e-7Y; Wed, 04 Oct 2023 04:05:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwrI-00075f-Ov; Wed, 04 Oct 2023 04:03:53 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwrG-00005l-4v; Wed, 04 Oct 2023 04:03:51 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 6707E2759E; Wed, 4 Oct 2023 11:02:26 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id B80F72CBDA; Wed, 4 Oct 2023 11:02:25 +0300 (MSK) Received: (nullmailer pid 2702810 invoked by uid 1000); Wed, 04 Oct 2023 08:02:21 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Peter Maydell , Richard Henderson , Michael Tokarev Subject: [Stable-8.1.2 20/45] target/arm: Don't skip MTE checks for LDRT/STRT at EL0 Date: Wed, 4 Oct 2023 11:01:41 +0300 Message-Id: <20231004080221.2702636-20-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Peter Maydell The LDRT/STRT "unprivileged load/store" instructions behave like normal ones if executed at EL0. We handle this correctly for the load/store semantics, but get the MTE checking wrong. We always look at s->mte_active[is_unpriv] to see whether we should be doing MTE checks, but in hflags.c when we set the TB flags that will be used to fill the mte_active[] array we only set the MTE0_ACTIVE bit if UNPRIV is true (i.e. we are not at EL0). This means that a LDRT at EL0 will see s->mte_active[1] as 0, and will not do MTE checks even when MTE is enabled. To avoid the translate-time code having to do an explicit check on s->unpriv to see if it is OK to index into the mte_active[] array, duplicate MTE_ACTIVE into MTE0_ACTIVE when UNPRIV is false. (This isn't a very serious bug because generally nobody executes LDRT/STRT at EL0, because they have no use there.) Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20230912140434.1333369-2-peter.maydell@linaro.org (cherry picked from commit 903dbefc2b6918c10d12d9aafa0168cee8d287c7) Signed-off-by: Michael Tokarev diff --git a/target/arm/tcg/hflags.c b/target/arm/tcg/hflags.c index 616c5fa723..ea642384f5 100644 --- a/target/arm/tcg/hflags.c +++ b/target/arm/tcg/hflags.c @@ -306,6 +306,15 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, && !(env->pstate & PSTATE_TCO) && (sctlr & (el == 0 ? SCTLR_TCF0 : SCTLR_TCF))) { DP_TBFLAG_A64(flags, MTE_ACTIVE, 1); + if (!EX_TBFLAG_A64(flags, UNPRIV)) { + /* + * In non-unpriv contexts (eg EL0), unpriv load/stores + * act like normal ones; duplicate the MTE info to + * avoid translate-a64.c having to check UNPRIV to see + * whether it is OK to index into MTE_ACTIVE[]. + */ + DP_TBFLAG_A64(flags, MTE0_ACTIVE, 1); + } } } /* And again for unprivileged accesses, if required. */ From patchwork Wed Oct 4 08:01:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 729251 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp220966wrs; Wed, 4 Oct 2023 01:10:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQnOfVGHiKl5FUQwKyV2Xm5wtyxcako0ROmor81uG8ZfptAtUCI/mrpkWkz74JgpatSlI1 X-Received: by 2002:a05:620a:2aea:b0:775:ce5f:95c8 with SMTP id bn42-20020a05620a2aea00b00775ce5f95c8mr527885qkb.25.1696407041306; Wed, 04 Oct 2023 01:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696407041; cv=none; d=google.com; s=arc-20160816; b=AR8pio2y/ys2VQYAA8uzYy530OquoY4ANiWAan9lMraqZIcxzgX23WTV/GlzSymLek myc6IeZivNIYXCZBIikGBNi/fYDJTUzxnxcSJWrzLZtc/kQr0njkUovfjwAqg6tDA96R ZqNrHzbICnNCYGAaiHaOS4dd4qcSpTO2KzZn/Dt41Z0bv6KkOmzMdsKQ99hIa6d3g7x8 b1oTXBu54B0jjSImA4IXscLrGu1H2G1CNEh8Z9zCggYGTZEpRu993k8KHXbySquJUKyb HiKtq19zyx/p6QuCJf94Xn/ghB7jIJja39eMBbQ/LchuWbqp+R4I5vOuchsygb+PdFUY orHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=0R8jeSBiOzixKARFXBI2sNvpbCleAKe6tLdmNbsL/AE=; fh=fA8wXgZkOijV3QzeJqIqYxlGqKQb9nNVVJRQwjQ6hao=; b=O9fHaJU+V6G95wZ0BkEBgEGkdLigHsCwx6l6/FGOJMut7gyvToz4OzWbwjP5sMHASv 8iM888h0fkHDdAZmv4zs+Z+UdwQN9RhNXYpH9IpfzTUos1rQcJcz62o7BAXFge/831RU h3yfUc6qdef+JUHlZj58kySXMaojFunDB7ih2wGrhKEpFdOnuYunogSfS7zhs5+ESvpf n+am754+ymKtsA8IBhGESmT6yVdXRsUYUu4gtmykR8rzjqsf6VFljDQ8qs4Id1G4FfZQ qvH2f9sl525iL569NVaqOxIAi6peg/0MiI2+H0e+Gr2/nCT40sWleppxJtlDKu2TPxGm oviA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m1-20020a05620a24c100b0076ca9dc9770si1264629qkn.661.2023.10.04.01.10.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 01:10:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnwsx-00054t-SY; Wed, 04 Oct 2023 04:05:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwsk-0003hp-Ho; Wed, 04 Oct 2023 04:05:22 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwsg-0002bj-Uh; Wed, 04 Oct 2023 04:05:22 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id D429A275AE; Wed, 4 Oct 2023 11:02:29 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 2EEDE2CBE8; Wed, 4 Oct 2023 11:02:29 +0300 (MSK) Received: (nullmailer pid 2702853 invoked by uid 1000); Wed, 04 Oct 2023 08:02:21 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , Michael Tokarev Subject: [Stable-8.1.2 34/45] softmmu: Use async_run_on_cpu in tcg_commit Date: Wed, 4 Oct 2023 11:01:55 +0300 Message-Id: <20231004080221.2702636-34-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson After system startup, run the update to memory_dispatch and the tlb_flush on the cpu. This eliminates a race, wherein a running cpu sees the memory_dispatch change but has not yet seen the tlb_flush. Since the update now happens on the cpu, we need not use qatomic_rcu_read to protect the read of memory_dispatch. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1826 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1834 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1846 Tested-by: Alex Bennée Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson (cherry picked from commit 0d58c660689f6da1e3feff8a997014003d928b3b) Signed-off-by: Michael Tokarev diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c index 9a5fabf625..7e35d7f4b5 100644 --- a/accel/tcg/cpu-exec-common.c +++ b/accel/tcg/cpu-exec-common.c @@ -33,36 +33,6 @@ void cpu_loop_exit_noexc(CPUState *cpu) cpu_loop_exit(cpu); } -#if defined(CONFIG_SOFTMMU) -void cpu_reloading_memory_map(void) -{ - if (qemu_in_vcpu_thread() && current_cpu->running) { - /* The guest can in theory prolong the RCU critical section as long - * as it feels like. The major problem with this is that because it - * can do multiple reconfigurations of the memory map within the - * critical section, we could potentially accumulate an unbounded - * collection of memory data structures awaiting reclamation. - * - * Because the only thing we're currently protecting with RCU is the - * memory data structures, it's sufficient to break the critical section - * in this callback, which we know will get called every time the - * memory map is rearranged. - * - * (If we add anything else in the system that uses RCU to protect - * its data structures, we will need to implement some other mechanism - * to force TCG CPUs to exit the critical section, at which point this - * part of this callback might become unnecessary.) - * - * This pair matches cpu_exec's rcu_read_lock()/rcu_read_unlock(), which - * only protects cpu->as->dispatch. Since we know our caller is about - * to reload it, it's safe to split the critical section. - */ - rcu_read_unlock(); - rcu_read_lock(); - } -} -#endif - void cpu_loop_exit(CPUState *cpu) { /* Undo the setting in cpu_tb_exec. */ diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 87dc9a752c..41788c0bdd 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -133,7 +133,6 @@ static inline void cpu_physical_memory_write(hwaddr addr, { cpu_physical_memory_rw(addr, (void *)buf, len, true); } -void cpu_reloading_memory_map(void); void *cpu_physical_memory_map(hwaddr addr, hwaddr *plen, bool is_write); diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 7597dc1c39..18277ddd67 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -680,8 +680,7 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr orig_addr, IOMMUTLBEntry iotlb; int iommu_idx; hwaddr addr = orig_addr; - AddressSpaceDispatch *d = - qatomic_rcu_read(&cpu->cpu_ases[asidx].memory_dispatch); + AddressSpaceDispatch *d = cpu->cpu_ases[asidx].memory_dispatch; for (;;) { section = address_space_translate_internal(d, addr, &addr, plen, false); @@ -2412,7 +2411,7 @@ MemoryRegionSection *iotlb_to_section(CPUState *cpu, { int asidx = cpu_asidx_from_attrs(cpu, attrs); CPUAddressSpace *cpuas = &cpu->cpu_ases[asidx]; - AddressSpaceDispatch *d = qatomic_rcu_read(&cpuas->memory_dispatch); + AddressSpaceDispatch *d = cpuas->memory_dispatch; int section_index = index & ~TARGET_PAGE_MASK; MemoryRegionSection *ret; @@ -2487,23 +2486,42 @@ static void tcg_log_global_after_sync(MemoryListener *listener) } } +static void tcg_commit_cpu(CPUState *cpu, run_on_cpu_data data) +{ + CPUAddressSpace *cpuas = data.host_ptr; + + cpuas->memory_dispatch = address_space_to_dispatch(cpuas->as); + tlb_flush(cpu); +} + static void tcg_commit(MemoryListener *listener) { CPUAddressSpace *cpuas; - AddressSpaceDispatch *d; + CPUState *cpu; assert(tcg_enabled()); /* since each CPU stores ram addresses in its TLB cache, we must reset the modified entries */ cpuas = container_of(listener, CPUAddressSpace, tcg_as_listener); - cpu_reloading_memory_map(); - /* The CPU and TLB are protected by the iothread lock. - * We reload the dispatch pointer now because cpu_reloading_memory_map() - * may have split the RCU critical section. + cpu = cpuas->cpu; + + /* + * Defer changes to as->memory_dispatch until the cpu is quiescent. + * Otherwise we race between (1) other cpu threads and (2) ongoing + * i/o for the current cpu thread, with data cached by mmu_lookup(). + * + * In addition, queueing the work function will kick the cpu back to + * the main loop, which will end the RCU critical section and reclaim + * the memory data structures. + * + * That said, the listener is also called during realize, before + * all of the tcg machinery for run-on is initialized: thus halt_cond. */ - d = address_space_to_dispatch(cpuas->as); - qatomic_rcu_set(&cpuas->memory_dispatch, d); - tlb_flush(cpuas->cpu); + if (cpu->halt_cond) { + async_run_on_cpu(cpu, tcg_commit_cpu, RUN_ON_CPU_HOST_PTR(cpuas)); + } else { + tcg_commit_cpu(cpu, RUN_ON_CPU_HOST_PTR(cpuas)); + } } static void memory_map_init(void) From patchwork Wed Oct 4 08:01:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 729248 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp220257wrs; Wed, 4 Oct 2023 01:08:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF62or3nMIMvqfwUFhvtt93OAmb0XvyiIzKZ5jd2DBuFFF/ued4i2QiXyF7jTkwDXj99Sr7 X-Received: by 2002:ac8:5b8e:0:b0:418:1edd:d2ed with SMTP id a14-20020ac85b8e000000b004181eddd2edmr1810151qta.4.1696406919266; Wed, 04 Oct 2023 01:08:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696406919; cv=none; d=google.com; s=arc-20160816; b=x++xy5Az9A0p+kDGDbiQYIUJG9Hk0WCRPFzsCdp/LtI+F8x73mXu4W8iKDvR9V3+Py 7EgQqSq7wPZjx8dPcfzxwqH70MY2bWWBaBxm80WBaTr64cFkNPutqzHORrFJ1Ue3L+2Q NyC3MD89s/2mU5rMLpKORaw+OtBUU2N57moX5P+Bq00+vyG1PlJ0S+OeBCIrpORW5nCe 8H0BpnjaCyL9+wfiwySwQOWJfG0iBU7eeu84PKKw3yos9sbVsVrbzzthOXljhj+eI7Hh PRiTk9qAhUqQwGMOQ0E5t1ghGMGPEQPH9Y4ErpCMmDNud1Aa6vguynbssC2Xnziv/av8 0+tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=812MlhQtSCw+1HpS4f9x/O30yjwMPNetUL0YHONIgl8=; fh=K4abbxCgZAPvqzOXA+PZ7RIZh+KufMVJze7rXLOwES0=; b=CfbPFecSccVyQn1Y7IrqxrqBFK0sCW5onCpSf+4Nh6rOxeZKJBSMNUtd3gUsdAtG+h qLR/JnQNe599WuSFupoNTRrUR1IAN3CjBJmFxFlmdFUIB5A7gFlAa7NmOXRepeV49AxZ ab6rt7awJuTqv4H81gt2Sy52OKXRKAQpTv5/oFySZiOj/AnXutKyKXIFWdARYg3wPeOX L1vON5MhZXYy2JDfwndA6uEoJ30eMNcdCUtNko0+N9yXy40Ju9efFXLTbRemDA4lP9oT TyMXF6EN+OiUsGa56go8EjUnVE0XHa4VZznHCikQtF79jf1hC6EawQ7vGj0QC5UA1B3y Fnhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o19-20020a05622a045300b00417afb934casi1301687qtx.683.2023.10.04.01.08.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 01:08:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnwu0-00067d-Mc; Wed, 04 Oct 2023 04:06:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwt7-0005iU-I9; Wed, 04 Oct 2023 04:05:48 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwt3-0002le-38; Wed, 04 Oct 2023 04:05:43 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 01B05275AF; Wed, 4 Oct 2023 11:02:30 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 5CC972CBE9; Wed, 4 Oct 2023 11:02:29 +0300 (MSK) Received: (nullmailer pid 2702856 invoked by uid 1000); Wed, 04 Oct 2023 08:02:21 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev Subject: [Stable-8.1.2 35/45] accel/tcg: Avoid load of icount_decr if unused Date: Wed, 4 Oct 2023 11:01:56 +0300 Message-Id: <20231004080221.2702636-35-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson With CF_NOIRQ and without !CF_USE_ICOUNT, the load isn't used. Avoid emitting it. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson (cherry picked from commit f47a90dacca8f74210a2675bdde7ab3856872b94) Signed-off-by: Michael Tokarev diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 1a6a5448c8..a3983019a5 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -49,12 +49,15 @@ bool translator_io_start(DisasContextBase *db) static TCGOp *gen_tb_start(uint32_t cflags) { - TCGv_i32 count = tcg_temp_new_i32(); + TCGv_i32 count = NULL; TCGOp *icount_start_insn = NULL; - tcg_gen_ld_i32(count, cpu_env, - offsetof(ArchCPU, neg.icount_decr.u32) - - offsetof(ArchCPU, env)); + if ((cflags & CF_USE_ICOUNT) || !(cflags & CF_NOIRQ)) { + count = tcg_temp_new_i32(); + tcg_gen_ld_i32(count, cpu_env, + offsetof(ArchCPU, neg.icount_decr.u32) - + offsetof(ArchCPU, env)); + } if (cflags & CF_USE_ICOUNT) { /* From patchwork Wed Oct 4 08:01:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 729253 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp221598wrs; Wed, 4 Oct 2023 01:12:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFp4t2AgsCYnpBhtMp50SrcT9PQvJPa/YfJEHad8WPxSuCPHfhy8veZ/LNgPovwGjDiB5DE X-Received: by 2002:ac8:5f13:0:b0:418:554:fa25 with SMTP id x19-20020ac85f13000000b004180554fa25mr1957925qta.47.1696407148022; Wed, 04 Oct 2023 01:12:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696407148; cv=none; d=google.com; s=arc-20160816; b=g26JLKetgiwiDtc2Ekf3xM/lZxZVp05op8jkAzwQzluBvRRNfdKsr2ygoC/myaJqkT Bgz9PYZbX/KReP+X1uqjBPo7LVo5BaCHnPRx1rypNP4tG9WRX+nBiOVHJMQndT+on9JF oZxY/Sx2gTwRS21LOrg7FWxE6BSHBo7EQAtVLU2mvP9yLtSEhLwGXrqjzW7mkNp3VeIC pxTHvw8AjgzTFV4HKAFcRuODDdjxuJNawL15hFiTP4lIvFV1eBUyoDu2SWCYwwTXtq5Z bQwV8BnHjf9wo+moHAtmvs1IWCncRNBKxlS75UWG5G3reBKZ2SFtht+mPXIn69E6WntZ T9NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=iVDiyQeFKkvdM4ftUiZqGTgtlgLGmvbYpxe2JgWdGzw=; fh=K4abbxCgZAPvqzOXA+PZ7RIZh+KufMVJze7rXLOwES0=; b=LMwH6+q0Fc+Xs+0dRdykbeg5M1wLZDiZCXB6lQSoh6Y82+Gwa3dgxtCWZG6F+HVDzt OcOfimuDFkhXbUg+k4Ia61TQIMO0Q4C6uy4lKQpUEr4uOwYZ3msGf+iBEVJGaZZxXarx Kjj3KIR1UM6s2CnEZSkqBpfkxh0Av4Lhm/DhDRkxp91mzLWKZyAO66Q2edAzDjfgmOAA T1hOAycNxLRoZdPx2Q5nHInw2ohSeX9lxydbrl21zVtW2tsQ4yCS8mu8dWqZJi9ehmkw j/lFVcW1JsUJ8VUK43v/AgVG1KoUqVvdwA72Klo9P2U6JXTHieD6i69uMGzZe4va73yn 8few== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z16-20020a05622a029000b0041812c64682si1284495qtw.112.2023.10.04.01.12.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 01:12:28 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnwvt-0002eJ-7Z; Wed, 04 Oct 2023 04:08:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwtM-0005tj-KJ; Wed, 04 Oct 2023 04:06:07 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwt6-0002tm-0g; Wed, 04 Oct 2023 04:05:48 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 45A2B275B0; Wed, 4 Oct 2023 11:02:30 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 7D1742CBEA; Wed, 4 Oct 2023 11:02:29 +0300 (MSK) Received: (nullmailer pid 2702859 invoked by uid 1000); Wed, 04 Oct 2023 08:02:21 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev Subject: [Stable-8.1.2 36/45] accel/tcg: Hoist CF_MEMI_ONLY check outside translation loop Date: Wed, 4 Oct 2023 11:01:57 +0300 Message-Id: <20231004080221.2702636-36-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson The condition checked is loop invariant; check it only once. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson (cherry picked from commit 5d97e94638100fd3e5b8d76ab30e1066cd4b1823) Signed-off-by: Michael Tokarev diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index a3983019a5..b6ab9f3d33 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -158,7 +158,13 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ - plugin_enabled = plugin_gen_tb_start(cpu, db, cflags & CF_MEMI_ONLY); + if (cflags & CF_MEMI_ONLY) { + /* We should only see CF_MEMI_ONLY for io_recompile. */ + assert(cflags & CF_LAST_IO); + plugin_enabled = plugin_gen_tb_start(cpu, db, true); + } else { + plugin_enabled = plugin_gen_tb_start(cpu, db, false); + } while (true) { *max_insns = ++db->num_insns; @@ -176,12 +182,8 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) { /* Accept I/O on the last instruction. */ gen_io_start(); - ops->translate_insn(db, cpu); - } else { - /* we should only see CF_MEMI_ONLY for io_recompile */ - tcg_debug_assert(!(cflags & CF_MEMI_ONLY)); - ops->translate_insn(db, cpu); } + ops->translate_insn(db, cpu); /* * We can't instrument after instructions that change control From patchwork Wed Oct 4 08:01:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 729249 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp220604wrs; Wed, 4 Oct 2023 01:09:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVI+9MEKSz8k0D2lpctSJ/jk2oPR/N5Y+Jf/IwpTWPjyVVT4IhFMyeijF7oPCqzaIGs+Gl X-Received: by 2002:a05:620a:4001:b0:775:6b2a:d749 with SMTP id h1-20020a05620a400100b007756b2ad749mr1982709qko.6.1696406978473; Wed, 04 Oct 2023 01:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696406978; cv=none; d=google.com; s=arc-20160816; b=C8dLlYUIPX72ZRIx/9peGJk7O68QH5neMF4tvtxIZKr6nvEmqGmnB9eeh7WSfJqwZz NZv2Cbv1hbM2A9k8p7hMq5Uj8IPWgyCnQRO+Tsf6iQs+d7xHPPeqPz+WjqjiHluxkn6p gNKQGLXrkYO2Yq8neiGjMPQMzc/HM6MUKt/vrPdUvDQ35yZUiVs6b/9WW5zewtI4bKKu 19Hh9Olg72Bexw3xcHAgZjwoB1+tG15QN6Bi3zzGZ0c2jo/JGL+6p7QLFiSSXm+QqbIj 8264zSu4vOjKurKhy5ntXMfFTE8tdkdj+rgQdNJo6CHKCrueHh1kgUyYODNm87nfha+m cIUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=y4oQ5cmm+Nr/LvGcx2MrIeiRRzHAPGWsyYuz1pixwJQ=; fh=K4abbxCgZAPvqzOXA+PZ7RIZh+KufMVJze7rXLOwES0=; b=nEkAbRAyNUOKzZlRVYeIA+ms5GJfJT7BB1A/AhwyAg8kHDeIttS5mtwK2lunkdlDYv vRDALAWxJOAVyqLkQwdO+hIKDcX5dzgsrzhs5oTKU6l1apo0z4E2TqjkTNjSNuK6wfRC XiD4SJy3bkZoVKl7kKGFiR0BwDNSrx6yrn7/S0PrqBJ8qcDs3vcv0kWmCOArOx0T/aSb 3kupNTbEguWUAsYCBRJXT5yHeZuLbsaUNKY2GIujtL0Q7j1pYXdBWgwx7aNnh0l/Din/ yTm+R52hNvlzG7PWCxDc1c+wBlSccWHP4ws2Ih6qjWXmjhbYQ0Oq0OylzCRHjcqxsVU5 YJ0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id dw10-20020a05620a600a00b0076ceb5934f6si1275315qkb.64.2023.10.04.01.09.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 01:09:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnwvw-00035q-8T; Wed, 04 Oct 2023 04:08:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwtM-0005tk-KF; Wed, 04 Oct 2023 04:06:07 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwtA-0003gI-3z; Wed, 04 Oct 2023 04:05:50 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 877E2275B2; Wed, 4 Oct 2023 11:02:30 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id C06AF2CBEB; Wed, 4 Oct 2023 11:02:29 +0300 (MSK) Received: (nullmailer pid 2702862 invoked by uid 1000); Wed, 04 Oct 2023 08:02:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev Subject: [Stable-8.1.2 37/45] accel/tcg: Track current value of can_do_io in the TB Date: Wed, 4 Oct 2023 11:01:58 +0300 Message-Id: <20231004080221.2702636-37-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Simplify translator_io_start by recording the current known value of can_do_io within DisasContextBase. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson (cherry picked from commit 0ca41ccf1c555f97873b8e02a47390fd6af4b18f) Signed-off-by: Michael Tokarev diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index b6ab9f3d33..850d82e26f 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -16,11 +16,14 @@ #include "tcg/tcg-op-common.h" #include "internal.h" -static void gen_io_start(void) +static void set_can_do_io(DisasContextBase *db, bool val) { - tcg_gen_st_i32(tcg_constant_i32(1), cpu_env, - offsetof(ArchCPU, parent_obj.can_do_io) - - offsetof(ArchCPU, env)); + if (db->saved_can_do_io != val) { + db->saved_can_do_io = val; + tcg_gen_st_i32(tcg_constant_i32(val), cpu_env, + offsetof(ArchCPU, parent_obj.can_do_io) - + offsetof(ArchCPU, env)); + } } bool translator_io_start(DisasContextBase *db) @@ -30,12 +33,8 @@ bool translator_io_start(DisasContextBase *db) if (!(cflags & CF_USE_ICOUNT)) { return false; } - if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) { - /* Already started in translator_loop. */ - return true; - } - gen_io_start(); + set_can_do_io(db, true); /* * Ensure that this instruction will be the last in the TB. @@ -47,7 +46,7 @@ bool translator_io_start(DisasContextBase *db) return true; } -static TCGOp *gen_tb_start(uint32_t cflags) +static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags) { TCGv_i32 count = NULL; TCGOp *icount_start_insn = NULL; @@ -91,12 +90,9 @@ static TCGOp *gen_tb_start(uint32_t cflags) * cpu->can_do_io is cleared automatically here at the beginning of * each translation block. The cost is minimal and only paid for * -icount, plus it would be very easy to forget doing it in the - * translator. Doing it here means we don't need a gen_io_end() to - * go with gen_io_start(). + * translator. */ - tcg_gen_st_i32(tcg_constant_i32(0), cpu_env, - offsetof(ArchCPU, parent_obj.can_do_io) - - offsetof(ArchCPU, env)); + set_can_do_io(db, false); } return icount_start_insn; @@ -147,6 +143,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, db->num_insns = 0; db->max_insns = *max_insns; db->singlestep_enabled = cflags & CF_SINGLE_STEP; + db->saved_can_do_io = -1; db->host_addr[0] = host_pc; db->host_addr[1] = NULL; @@ -154,7 +151,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ /* Start translating. */ - icount_start_insn = gen_tb_start(cflags); + icount_start_insn = gen_tb_start(db, cflags); ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ @@ -181,7 +178,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, the next instruction. */ if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) { /* Accept I/O on the last instruction. */ - gen_io_start(); + set_can_do_io(db, true); } ops->translate_insn(db, cpu); diff --git a/include/exec/translator.h b/include/exec/translator.h index a53d3243d4..0f4ecad7a2 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -72,6 +72,7 @@ typedef enum DisasJumpType { * @num_insns: Number of translated instructions (including current). * @max_insns: Maximum number of instructions to be translated in this TB. * @singlestep_enabled: "Hardware" single stepping enabled. + * @saved_can_do_io: Known value of cpu->neg.can_do_io, or -1 for unknown. * * Architecture-agnostic disassembly context. */ @@ -83,6 +84,7 @@ typedef struct DisasContextBase { int num_insns; int max_insns; bool singlestep_enabled; + int8_t saved_can_do_io; void *host_addr[2]; } DisasContextBase; From patchwork Wed Oct 4 08:01:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 729247 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp220255wrs; Wed, 4 Oct 2023 01:08:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFle6CP0nhlBtbz/YR562VzpoX//cLYiAbaEFn/8rZuKbWHJkJw/gNrhCiI3z6dmwQOODeg X-Received: by 2002:a05:620a:458c:b0:767:e994:ff03 with SMTP id bp12-20020a05620a458c00b00767e994ff03mr1988932qkb.15.1696406919266; Wed, 04 Oct 2023 01:08:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696406919; cv=none; d=google.com; s=arc-20160816; b=kFJjhGV0kQVKS3RcKQDizzGjF3EMaNWrXlUi2lIK8dMNJWi9SxxDKZWhLH1a68A6mV QBowlDaem9lxkrDzLQhyJO/yX6G8JsYyDzYZLXfdoofZwV1ikvoRI0hW49hSpNTQfRBr TzPUXFIcs+LiXRdiZXAEaMNXr0XAPULVCn2RiRmfnDFLj1kDfNbXH40KubU44R5dTRbJ X5VfvDx2Iw7yottpYbeaMGjDNN+YKboLtEz75hWP384psZpZ1gPf0APkqE2trpPSA9il k7X4ryTIq3vO+LaFrE1aR5TFWapsWpsFuI9IdvptMsanMm9veawPfmGw/Tygf9DuQa/W LobA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=QwhHa8Ug15W8ajsmY//u47SCtwdZ0TL0IqTw0GnxUBg=; fh=K4abbxCgZAPvqzOXA+PZ7RIZh+KufMVJze7rXLOwES0=; b=knz3iN2/8uuhiHaY2+KYy1KxlMkrgut/dr+FDTa/tawAstQfY8rOebYZ0QRukv6obv Mo4uUUhQhmlzec5j7jsnNEquyK3LCPbwrZZEf6kNvvL2E3zwJtZLigxfzt3p1+/o9L+y 01eysYxBp9qyvO4ShUkIW9Cw4xJ8b/wempYeS4y9KLMWAnBJ7/doczDGEzRIAC6KUkyB LGhhx7XRNcidVbrZqab+X4R0MoStZf4ooJ7QwTqYj/7DTzaE4hXwuj9WCWWlCF3TUKsP BPZl/C5lsML2OTPpXpizHqUeAQpI7UiitdMXNCJ2BbwFpJm+qRzgQflbDopTPtHj0JBq knoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v13-20020a05620a0f0d00b00773db595cccsi1278183qkl.672.2023.10.04.01.08.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 01:08:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnwu5-0006J1-FX; Wed, 04 Oct 2023 04:06:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwtW-00060L-Vf; Wed, 04 Oct 2023 04:06:16 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwtR-0003hU-6H; Wed, 04 Oct 2023 04:06:08 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id BA426275B3; Wed, 4 Oct 2023 11:02:30 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 0E32F2CBEC; Wed, 4 Oct 2023 11:02:30 +0300 (MSK) Received: (nullmailer pid 2702865 invoked by uid 1000); Wed, 04 Oct 2023 08:02:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev Subject: [Stable-8.1.2 38/45] accel/tcg: Improve setting of can_do_io at start of TB Date: Wed, 4 Oct 2023 11:01:59 +0300 Message-Id: <20231004080221.2702636-38-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Initialize can_do_io to true if this the TB has CF_LAST_IO and will consist of a single instruction. This avoids a set to 0 followed immediately by a set to 1. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson (cherry picked from commit a2f99d484c54adda13e62bf75ba512618a3fe470) Signed-off-by: Michael Tokarev diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 850d82e26f..dd507cd471 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -87,12 +87,12 @@ static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags) offsetof(ArchCPU, neg.icount_decr.u16.low) - offsetof(ArchCPU, env)); /* - * cpu->can_do_io is cleared automatically here at the beginning of + * cpu->can_do_io is set automatically here at the beginning of * each translation block. The cost is minimal and only paid for * -icount, plus it would be very easy to forget doing it in the * translator. */ - set_can_do_io(db, false); + set_can_do_io(db, db->max_insns == 1 && (cflags & CF_LAST_IO)); } return icount_start_insn; From patchwork Wed Oct 4 08:02:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 729250 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp220967wrs; Wed, 4 Oct 2023 01:10:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdLcbE1sRHupa8Ck9pKnWnOA2bGFr+CfB059n8kg5FWCHxf1XFQnDjhQf+Ni1iPeUwuFHg X-Received: by 2002:a0c:e04b:0:b0:65b:896:1cb1 with SMTP id y11-20020a0ce04b000000b0065b08961cb1mr1907208qvk.17.1696407041301; Wed, 04 Oct 2023 01:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696407041; cv=none; d=google.com; s=arc-20160816; b=i5SvxXvmSqpdwRmTJeE5XUX+vLahUjV+xPsVWXjdMmd6uatPjLzX2rixU/cBfO3ByB nk7DGHlDbrnKRNZ1Ars956Z6fWjude1e5A0en7awf8NHAIiNvfPp0UasbOvhVO1XBpZn ETlenjULnvDydi3gmOP9qpaUB6ey+dRQr0Z/4KP8im2wYDE3MTOOPkQI5gnKpViMGuFV buSqhCionEFClu+LXDtlJAAp2eDJ3FyvWvWgb5hpHRCgZsdh8GWmXB3nWTLZCC0ksn/y jTGrcZMP8jxq1ZsaWYGg5SJYjlnj+9CkDyOjDmfgaqUZcWU+cvFZMbJFjQoBmotgoKB/ 5MeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=wihOXMd1nKS+Pxco9iBgoCgCAPpjbg4ugLtxwJLBR/4=; fh=K4abbxCgZAPvqzOXA+PZ7RIZh+KufMVJze7rXLOwES0=; b=Udtn2WKvufbOo3V/vGizq6FlEuDeJGb/vgipSMmsx54kkmkNUdkf6TSSlnMk1fB2Ym zlRmO6pGK/8MRN0I/ltTQi7G3ixM5iL/z1DurYQLnU5QZcykmG1elYoLkUI+72Jzfaaz /atoFSTnMGVSzrSK+8G349d0krXXwpA8juAnZbjVyfpwHT40Mma1k4mYkkoDju7AtRoe kHuUjoHyii2Mr4MENZhAAq+wI5rdETnfBO0ZKg3+yT8jlV6dtHXTQgjC36sX3BjPhKAk xQBUx0SQMI+NuhAT6TI+/p/JKnlCbxQhR/8rA/2y19p9kiaygFqdAHObqpqrAnzHj0uO kydQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n9-20020a0c8c09000000b0065d0353baa0si1252554qvb.51.2023.10.04.01.10.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 01:10:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnwvz-0003WA-RV; Wed, 04 Oct 2023 04:08:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwtW-00060K-VI; Wed, 04 Oct 2023 04:06:16 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwtR-0003hV-7L; Wed, 04 Oct 2023 04:06:09 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id E84B5275B4; Wed, 4 Oct 2023 11:02:30 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 40DBC2CBED; Wed, 4 Oct 2023 11:02:30 +0300 (MSK) Received: (nullmailer pid 2702868 invoked by uid 1000); Wed, 04 Oct 2023 08:02:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev Subject: [Stable-8.1.2 39/45] accel/tcg: Always set CF_LAST_IO with CF_NOIRQ Date: Wed, 4 Oct 2023 11:02:00 +0300 Message-Id: <20231004080221.2702636-39-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Without this we can get see loops through cpu_io_recompile, in which the cpu makes no progress. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson (cherry picked from commit 200c1f904f46c209cb022e711a48b89e46512902) Signed-off-by: Michael Tokarev diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index e2c494e75e..c724e8b6f1 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -720,7 +720,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret) && cpu_neg(cpu)->icount_decr.u16.low + cpu->icount_extra == 0) { /* Execute just one insn to trigger exception pending in the log */ cpu->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT) - | CF_NOIRQ | 1; + | CF_LAST_IO | CF_NOIRQ | 1; } #endif return false; diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index c406b2f7b7..85684f2b3d 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -1083,7 +1083,8 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc) if (current_tb_modified) { /* Force execution of one insn next time. */ CPUState *cpu = current_cpu; - cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu); + cpu->cflags_next_tb = + 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu); return true; } return false; @@ -1153,7 +1154,8 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages, if (current_tb_modified) { page_collection_unlock(pages); /* Force execution of one insn next time. */ - current_cpu->cflags_next_tb = 1 | CF_NOIRQ | curr_cflags(current_cpu); + current_cpu->cflags_next_tb = + 1 | CF_LAST_IO | CF_NOIRQ | curr_cflags(current_cpu); mmap_unlock(); cpu_loop_exit_noexc(current_cpu); } From patchwork Wed Oct 4 08:02:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 729246 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp219830wrs; Wed, 4 Oct 2023 01:07:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRMDq5B3bA7YPzXtYcd7IX7Go58zL03iPskMf+Qx1QiaHNlTey+livk2onUCFvusFw/4H6 X-Received: by 2002:a05:622a:1ba8:b0:418:1194:42f7 with SMTP id bp40-20020a05622a1ba800b00418119442f7mr1793527qtb.51.1696406841279; Wed, 04 Oct 2023 01:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696406841; cv=none; d=google.com; s=arc-20160816; b=uT1wGvklcrdsUL4CU5bjN9HzdGYiqn286nYU+5j2fXa4lwbnbaPMZY0BAy+B3g4w10 G/ZRjVPWWgZPt9PX76+cX4bU8RjU0i1njXXZ60L6AsYyivgTuSaZdKipovHi3QDT5Bv0 LZkwWn1OaS4msSNk7iPPKIrc5eG5MHkua/xcwVPvKqAkE0QbRBtW5ZSCgz1nsjZtOp3N l/skivYWYDhS9E38Lb3jsk0FgS1smNPMjcw7o7e9SxqTqgVuDNxCC/+xSiRGf/gmfBS9 1NhTTx26ntv778JrhOu6ciPPiQSRhG75G5s98B2pATg2YvIsMFQd+Y1pbbiVs+xuWbxX KmHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=3+vA/vYER/L8sNSnxpocL0U+uLvdD3mtNL7B4pJAGgE=; fh=K4abbxCgZAPvqzOXA+PZ7RIZh+KufMVJze7rXLOwES0=; b=uavginIzsM1U978Rzxcegi8lvjDqYjk2wnt4ZVpld2h9YQ3Jgz+Kw/PJDGxzGt8z9w 8BLTC99qEnZR/jTZ/KdmRXCJ755ro0UtWnLnC0W5ZKh6LlE7lEmcC0h4my+dt8+n0dlZ oJTJks4nHZ61pgwOAMnmav7mRh/90hzTEPOWkbkT7leyypaSpIIEjcE2olD47oAVEuz6 oQs/JoRw/+ArUiFbCF45XgrAPQEIBpDMElT7SFSWHN9JTZqAiQPIR1TJPmlN//6ZETd1 YO5TmPJbi6N1Q3KiQ8nuhYNIYpRYqk/957VGr0cmHukeeIbJHIA7iYVfLuiEztlyK/2C FPOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h14-20020ac87d4e000000b004180cd5acadsi1285242qtb.454.2023.10.04.01.07.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 01:07:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnwuE-0006gA-Gw; Wed, 04 Oct 2023 04:06:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwte-00062A-3i; Wed, 04 Oct 2023 04:06:27 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnwtZ-0003iQ-K4; Wed, 04 Oct 2023 04:06:16 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 29AD8275B5; Wed, 4 Oct 2023 11:02:31 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 6EF6B2CBEE; Wed, 4 Oct 2023 11:02:30 +0300 (MSK) Received: (nullmailer pid 2702871 invoked by uid 1000); Wed, 04 Oct 2023 08:02:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Michael Tokarev Subject: [Stable-8.1.2 40/45] accel/tcg: Always require can_do_io Date: Wed, 4 Oct 2023 11:02:01 +0300 Message-Id: <20231004080221.2702636-40-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Require i/o as the last insn of a TranslationBlock always, not only with icount. This is required for i/o that alters the address space, such as a pci config space write. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1866 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson (cherry picked from commit 18a536f1f8d6222e562f59179e837fdfd8b92718) Signed-off-by: Michael Tokarev diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index dd507cd471..358214d526 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -28,12 +28,6 @@ static void set_can_do_io(DisasContextBase *db, bool val) bool translator_io_start(DisasContextBase *db) { - uint32_t cflags = tb_cflags(db->tb); - - if (!(cflags & CF_USE_ICOUNT)) { - return false; - } - set_can_do_io(db, true); /* @@ -86,15 +80,15 @@ static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags) tcg_gen_st16_i32(count, cpu_env, offsetof(ArchCPU, neg.icount_decr.u16.low) - offsetof(ArchCPU, env)); - /* - * cpu->can_do_io is set automatically here at the beginning of - * each translation block. The cost is minimal and only paid for - * -icount, plus it would be very easy to forget doing it in the - * translator. - */ - set_can_do_io(db, db->max_insns == 1 && (cflags & CF_LAST_IO)); } + /* + * cpu->can_do_io is set automatically here at the beginning of + * each translation block. The cost is minimal, plus it would be + * very easy to forget doing it in the translator. + */ + set_can_do_io(db, db->max_insns == 1 && (cflags & CF_LAST_IO)); + return icount_start_insn; } diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c index 9bb40f1849..593fc80458 100644 --- a/target/mips/tcg/translate.c +++ b/target/mips/tcg/translate.c @@ -11212,7 +11212,6 @@ static void gen_branch(DisasContext *ctx, int insn_bytes) /* Branches completion */ clear_branch_hflags(ctx); ctx->base.is_jmp = DISAS_NORETURN; - /* FIXME: Need to clear can_do_io. */ switch (proc_hflags & MIPS_HFLAG_BMASK_BASE) { case MIPS_HFLAG_FBNSLOT: gen_goto_tb(ctx, 0, ctx->base.pc_next + insn_bytes);