From patchwork Tue Apr 30 14:00:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 793321 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:54f:b0:34d:5089:5a9e with SMTP id b15csp275962wrf; Tue, 30 Apr 2024 07:02:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX/8nBidEcR1PdWPXy3qKH2jq0WF21/Ac3hzjQMdPC/wYF5q5GWozdVKfb64DH6fkJwrMFumwxMCK3oFueSuAFW X-Google-Smtp-Source: AGHT+IGUIPkXRjxuV+QLG4tXssKW8Jm2voqn8XC4yALfdu3uEP3I0PmNmEjMh0i4Z+ES5EbudhX7 X-Received: by 2002:a67:efc4:0:b0:47b:b817:f31f with SMTP id s4-20020a67efc4000000b0047bb817f31fmr12516600vsp.9.1714485728274; Tue, 30 Apr 2024 07:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714485728; cv=none; d=google.com; s=arc-20160816; b=KB1EA9eEY7Zpy7HOLtOYjcOP+JE5MD9QuDwnzgtdJoNTm1fQHNKcZYakFqiSp3ncKv vaa+1kr9/0IsylvmfkKi84FtjHkKWPoaxiJwOSiF+XP+22K0K1jcaNXe60h7wQura3Mc V8qaeH1CRr4ynzjr2/ol3E3yD1NS3to4UF2CsJ8C1rzc6cdaTH8LSDHqXypz7F35CJBt eFGZAxx3f3ebRbpmmnD/q9jqgRjiG9aOM10awz0EkbijTJtpvmxRxtfnG6zRp+WboMtT Wu/LeybMT5rA88PaWb2Ux6UpVg0pK+ZDAmG/COmnKgubQ92Q8etoEJrCDgasqFZP7Zqa m9QQ== 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:to:from :dkim-signature; bh=pdw4e1T+XOnjRYbe6abw8/6ufHXzK4jmHY6mtjifRb8=; fh=68wiIGPkWm/0azCHzpRXqXi5Lsy/uB/434VAMxZd7RM=; b=UeX2+G9ds4XEEBl9m2uKa+hJjdHef4AOD/JFZEgMWZ+tt3efCiVPhdmmEQPsfOJnpA uTHNP/QCufMg22xsx4WYgyU3ZeGsqkQSOcdZZCE5zDt1AnObjAUVcQzWuBGLKxfzsrsE vsj1G2sNZMCKVocR2A5+WQg5x9YAAB59lgTY6Q9yYfV3LlqakMSPxKmidf2LqlfX4WCr wtgcKvxG+4Qr+5UyS9k6sRUWd4klOREIB8uHCWg0oj52bdc5iq6/CfSY5SR18PBy8E3N xvXU2tvY44cO18fOQujdaVJ/geWq4EWSPa62EvhKiXtUQLQ46lP2/R0YiWyrDlK3jGnF WuOw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=COx0NkUK; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j6-20020a67ef06000000b0047270645a06si4526965vsr.511.2024.04.30.07.02.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Apr 2024 07:02:08 -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; dkim=pass header.i=@linaro.org header.s=google header.b=COx0NkUK; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1o2g-0002eW-W1; Tue, 30 Apr 2024 10:01:12 -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 1s1o2U-0002Yv-7u for qemu-devel@nongnu.org; Tue, 30 Apr 2024 10:01:05 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1o2O-0002uI-MS for qemu-devel@nongnu.org; Tue, 30 Apr 2024 10:00:54 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2d858501412so73687181fa.0 for ; Tue, 30 Apr 2024 07:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714485649; x=1715090449; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=pdw4e1T+XOnjRYbe6abw8/6ufHXzK4jmHY6mtjifRb8=; b=COx0NkUKj6lNJihspMIjN8j+xzj7zsugmcVCAO++jt7IcUNHfCUBJDIkQHBJ512o/B oIZRL33quWqdEwO6FQf+gp6yV9am0IwyucIedOefLzxzTZGKcc5iXQMDwGQoULYfN6OX OTWkvuBBQBzUYs/7w/ye/ytXk2fl2vN9hq5ts10qRcqUPqmHIVKSsH61vxNxWb3PM9hx cSS83+/t/H6RfheAaoHw+dfYinfJlxJtfAjnNI6AMVhyxm2NDErdYkYuILCfzOhuR5gq HREh2J8+BlOLTM48TS6r8m3BVXVJ/0VGgn2VwgzJnmjKMuRSzuzO+8Qeo/EwdicxGxdS YCkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714485649; x=1715090449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pdw4e1T+XOnjRYbe6abw8/6ufHXzK4jmHY6mtjifRb8=; b=cRTfF2pJWg+Qsm2DHA1LRfy7pBvBDr9ZnRIMeVNpsELkL32IFS1Q9zzZoDM7yz4d8J N3YjIUDP5wtJ7qn3tNCMwTvrEHIC1q/vCaTPEWSvB9JMXK1OBlurJb1Z3AML9xoiYrJN gvbmteO+1mo8T+ORCnrCrpvGdms3tNEZ7uHtJvRLxRXTZrpXSVHpmrFOyl5Jlbtfk7/R l9UxL97SOqsKfiSUi8sCQV5R71F2Ka7aX7SM9cSwKyLVNWMcVivadqfHDpkjxlRzGPtS hsZ+UATafShlGIhLtloqXdMVPlpKr2Vr1+ttVVwnmsqdgIvBa/07lbuOhn/qaM2ktChh h+Mg== X-Forwarded-Encrypted: i=1; AJvYcCXAZpl/uI26GybRENxmE/C1cw6Do2lpc+xcAc0W4BQO/n5nbI4LOocVnrdAf5jS6/CzsCQRRv8RG0Alc/s6etjrNIzdlsw= X-Gm-Message-State: AOJu0YwvCA2fxVARhSr+QN4DJpCW8x1IRhT/x8EGYg00HnRp0bH2CR5Y T5vUt/NXxaRO2Xjfr6ju/E0Jj06dQe+7isDkuz4fW/A7UdYnboiE9qNsRKWln2s= X-Received: by 2002:a2e:8750:0:b0:2de:25e2:6187 with SMTP id q16-20020a2e8750000000b002de25e26187mr1967189ljj.23.1714485639231; Tue, 30 Apr 2024 07:00:39 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id v10-20020a05600c470a00b0041bfa349cadsm11062705wmo.16.2024.04.30.07.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:00:37 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 1/2] accel/tcg: Make TCGCPUOps::cpu_exec_halt return bool for whether to halt Date: Tue, 30 Apr 2024 15:00:34 +0100 Message-Id: <20240430140035.3889879-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240430140035.3889879-1-peter.maydell@linaro.org> References: <20240430140035.3889879-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=peter.maydell@linaro.org; helo=mail-lj1-x22c.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=unavailable 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 The TCGCPUOps::cpu_exec_halt method is called from cpu_handle_halt() when the CPU is halted, so that a target CPU emulation can do anything target-specific it needs to do. (At the moment we only use this on i386.) The current specification of the method doesn't allow the target specific code to do something different if the CPU is about to come out of the halt state, because cpu_handle_halt() only determines this after the method has returned. (If the method called cpu_has_work() itself this would introduce a potential race if an interrupt arrived between the target's method implementation checking and cpu_handle_halt() repeating the check.) Change the definition of the method so that it returns a bool to tell cpu_handle_halt() whether to stay in halt or not. We will want this for the Arm target, where FEAT_WFxT wants to do some work only for the case where the CPU is in halt but about to leave it. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- include/hw/core/tcg-cpu-ops.h | 11 +++++++++-- target/i386/tcg/helper-tcg.h | 2 +- accel/tcg/cpu-exec.c | 7 +++++-- target/i386/tcg/sysemu/seg_helper.c | 3 ++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h index dc1f16a9777..f3ac76e6f6d 100644 --- a/include/hw/core/tcg-cpu-ops.h +++ b/include/hw/core/tcg-cpu-ops.h @@ -111,8 +111,15 @@ struct TCGCPUOps { void (*do_interrupt)(CPUState *cpu); /** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */ bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request); - /** @cpu_exec_halt: Callback for handling halt in cpu_exec */ - void (*cpu_exec_halt)(CPUState *cpu); + /** + * @cpu_exec_halt: Callback for handling halt in cpu_exec. + * + * Return true to indicate that the CPU should now leave halt, false + * if it should remain in the halted state. + * If this method is not provided, the default is to leave halt + * if cpu_has_work() returns true. + */ + bool (*cpu_exec_halt)(CPUState *cpu); /** * @tlb_fill: Handle a softmmu tlb miss * diff --git a/target/i386/tcg/helper-tcg.h b/target/i386/tcg/helper-tcg.h index effc2c1c984..85957943bf3 100644 --- a/target/i386/tcg/helper-tcg.h +++ b/target/i386/tcg/helper-tcg.h @@ -39,7 +39,7 @@ QEMU_BUILD_BUG_ON(TCG_PHYS_ADDR_BITS > TARGET_PHYS_ADDR_SPACE_BITS); */ void x86_cpu_do_interrupt(CPUState *cpu); #ifndef CONFIG_USER_ONLY -void x86_cpu_exec_halt(CPUState *cpu); +bool x86_cpu_exec_halt(CPUState *cpu); bool x86_need_replay_interrupt(int interrupt_request); bool x86_cpu_exec_interrupt(CPUState *cpu, int int_req); #endif diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 5c70748060a..550f93b19ce 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -669,11 +669,14 @@ static inline bool cpu_handle_halt(CPUState *cpu) #ifndef CONFIG_USER_ONLY if (cpu->halted) { const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; + bool leave_halt; if (tcg_ops->cpu_exec_halt) { - tcg_ops->cpu_exec_halt(cpu); + leave_halt = tcg_ops->cpu_exec_halt(cpu); + } else { + leave_halt = cpu_has_work(cpu); } - if (!cpu_has_work(cpu)) { + if (!leave_halt) { return true; } diff --git a/target/i386/tcg/sysemu/seg_helper.c b/target/i386/tcg/sysemu/seg_helper.c index 2db8083748e..9ba94deb3aa 100644 --- a/target/i386/tcg/sysemu/seg_helper.c +++ b/target/i386/tcg/sysemu/seg_helper.c @@ -128,7 +128,7 @@ void x86_cpu_do_interrupt(CPUState *cs) } } -void x86_cpu_exec_halt(CPUState *cpu) +bool x86_cpu_exec_halt(CPUState *cpu) { if (cpu->interrupt_request & CPU_INTERRUPT_POLL) { X86CPU *x86_cpu = X86_CPU(cpu); @@ -138,6 +138,7 @@ void x86_cpu_exec_halt(CPUState *cpu) cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL); bql_unlock(); } + return cpu_has_work(cpu); } bool x86_need_replay_interrupt(int interrupt_request)