From nobody Wed Nov 5 20:13:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537203177007106.50306068496025; Mon, 17 Sep 2018 09:52:57 -0700 (PDT) Received: from localhost ([::1]:36554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1wlb-0007N2-OE for importer@patchew.org; Mon, 17 Sep 2018 12:52:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1wQo-0006Qt-SQ for qemu-devel@nongnu.org; Mon, 17 Sep 2018 12:31:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1wQk-00028f-PX for qemu-devel@nongnu.org; Mon, 17 Sep 2018 12:31:26 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:55055) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g1wQk-0001oR-FE for qemu-devel@nongnu.org; Mon, 17 Sep 2018 12:31:22 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 83AFB53A; Mon, 17 Sep 2018 12:31:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 17 Sep 2018 12:31:08 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id B1C4FE49EC; Mon, 17 Sep 2018 12:31:07 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=aKGZlFokhmgqY6 5WFTOZA7QCDKI0QucVVq+XAIyQaMw=; b=XAMvm/10XcjK0lyJprO8zkwoh89epW G6DHN01BJ3tiEbUuOTzhqjkuEdT6Xm5prLzK6QUg7g8YklYoZfJ7ydBAZ30qQPb4 63Lv6zIJq5xv4YxOl9YG9fvZQDwnGxmINd2fMX/1kdbvzVLTJ/fM5mpkDiwzRMD4 wp2d56ZAljKac= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=aKGZlFokhmgqY65WFTOZA7QCDKI0QucVVq+XAIyQaMw=; b=GPfoCyC5 fFLPDTgd7upMo/NaQ3KdTjkLjMNU4VBatVOzE3kBVxpcD0+sT3uqynFtqo9H3D7Q jfNnq2/fBZJZgRl3lAxfBhDqI1qOEUDPtjitwVcdcFgj1gSc35VXy0FI3d9iER4E f6UIHvXFmk5k9KWEab3yjJs4jyJAPm7ag6vTJzIeMg+T6Oqj3yz9ma3cs8wrPOae Ps7U/DZc4nydeqN04q6aESh0lONf4pFpQPGu8SvdMOPGfeDztKn4cneUN2j6+wcf ew14WeYDKrqQVjqNI8C4WVdaDOTrvi5gZG8RWKMS67Z6m7lhLotXqVr9xEN3B9ev hEvWi1OhaKGT1w== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 17 Sep 2018 12:30:42 -0400 Message-Id: <20180917163103.6113-15-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180917163103.6113-1-cota@braap.org> References: <20180917163103.6113-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.147.123.25 Subject: [Qemu-devel] [PATCH 14/35] whpx: access cpu->interrupt_request with atomics X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Eduardo Habkost , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" I am not familiar with whpx, so I opted for the safe (and slow) route of performing probably many unnecessary atomic_reads. Cc: Richard Henderson Cc: Eduardo Habkost Signed-off-by: Emilio G. Cota --- target/i386/whpx-all.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c index d9428dc987..e0af3f5760 100644 --- a/target/i386/whpx-all.c +++ b/target/i386/whpx-all.c @@ -690,12 +690,15 @@ static int whpx_handle_portio(CPUState *cpu, static int whpx_handle_halt(CPUState *cpu) { struct CPUX86State *env =3D (CPUArchState *)(cpu->env_ptr); + int interrupt_request; int ret =3D 0; =20 qemu_mutex_lock_iothread(); - if (!((cpu->interrupt_request & CPU_INTERRUPT_HARD) && + interrupt_request =3D atomic_read(&cpu->interrupt_request); + + if (!((interrupt_request & CPU_INTERRUPT_HARD) && (env->eflags & IF_MASK)) && - !(cpu->interrupt_request & CPU_INTERRUPT_NMI)) { + !(interrupt_request & CPU_INTERRUPT_NMI)) { cpu->exception_index =3D EXCP_HLT; cpu->halted =3D true; ret =3D 1; @@ -718,6 +721,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) UINT32 reg_count =3D 0; WHV_REGISTER_VALUE reg_values[3]; WHV_REGISTER_NAME reg_names[3]; + int interrupt_request; =20 memset(&new_int, 0, sizeof(new_int)); memset(reg_values, 0, sizeof(reg_values)); @@ -725,16 +729,17 @@ static void whpx_vcpu_pre_run(CPUState *cpu) qemu_mutex_lock_iothread(); =20 /* Inject NMI */ + interrupt_request =3D atomic_read(&cpu->interrupt_request); if (!vcpu->interruption_pending && - cpu->interrupt_request & (CPU_INTERRUPT_NMI | CPU_INTERRUPT_SMI)) { - if (cpu->interrupt_request & CPU_INTERRUPT_NMI) { + interrupt_request & (CPU_INTERRUPT_NMI | CPU_INTERRUPT_SMI)) { + if (interrupt_request & CPU_INTERRUPT_NMI) { cpu_reset_interrupt(cpu, CPU_INTERRUPT_NMI); vcpu->interruptable =3D false; new_int.InterruptionType =3D WHvX64PendingNmi; new_int.InterruptionPending =3D 1; new_int.InterruptionVector =3D 2; } - if (cpu->interrupt_request & CPU_INTERRUPT_SMI) { + if (interrupt_request & CPU_INTERRUPT_SMI) { cpu_reset_interrupt(cpu, CPU_INTERRUPT_SMI); } } @@ -743,12 +748,13 @@ static void whpx_vcpu_pre_run(CPUState *cpu) * Force the VCPU out of its inner loop to process any INIT requests or * commit pending TPR access. */ - if (cpu->interrupt_request & (CPU_INTERRUPT_INIT | CPU_INTERRUPT_TPR))= { - if ((cpu->interrupt_request & CPU_INTERRUPT_INIT) && + interrupt_request =3D atomic_read(&cpu->interrupt_request); + if (interrupt_request & (CPU_INTERRUPT_INIT | CPU_INTERRUPT_TPR)) { + if ((interrupt_request & CPU_INTERRUPT_INIT) && !(env->hflags & HF_SMM_MASK)) { cpu->exit_request =3D 1; } - if (cpu->interrupt_request & CPU_INTERRUPT_TPR) { + if (interrupt_request & CPU_INTERRUPT_TPR) { cpu->exit_request =3D 1; } } @@ -757,7 +763,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) if (!vcpu->interruption_pending && vcpu->interruptable && (env->eflags & IF_MASK)) { assert(!new_int.InterruptionPending); - if (cpu->interrupt_request & CPU_INTERRUPT_HARD) { + if (interrupt_request & CPU_INTERRUPT_HARD) { cpu_reset_interrupt(cpu, CPU_INTERRUPT_HARD); irq =3D cpu_get_pic_interrupt(env); if (irq >=3D 0) { @@ -787,7 +793,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) =20 /* Update the state of the interrupt delivery notification */ if (!vcpu->window_registered && - cpu->interrupt_request & CPU_INTERRUPT_HARD) { + atomic_read(&cpu->interrupt_request) & CPU_INTERRUPT_HARD) { reg_values[reg_count].DeliverabilityNotifications.InterruptNotific= ation =3D 1; vcpu->window_registered =3D 1; @@ -840,8 +846,9 @@ static void whpx_vcpu_process_async_events(CPUState *cp= u) struct CPUX86State *env =3D (CPUArchState *)(cpu->env_ptr); X86CPU *x86_cpu =3D X86_CPU(cpu); struct whpx_vcpu *vcpu =3D get_whpx_vcpu(cpu); + int interrupt_request; =20 - if ((cpu->interrupt_request & CPU_INTERRUPT_INIT) && + if ((atomic_read(&cpu->interrupt_request) & CPU_INTERRUPT_INIT) && !(env->hflags & HF_SMM_MASK)) { =20 do_cpu_init(x86_cpu); @@ -849,25 +856,26 @@ static void whpx_vcpu_process_async_events(CPUState *= cpu) vcpu->interruptable =3D true; } =20 - if (cpu->interrupt_request & CPU_INTERRUPT_POLL) { + if (atomic_read(&cpu->interrupt_request) & CPU_INTERRUPT_POLL) { cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL); apic_poll_irq(x86_cpu->apic_state); } =20 - if (((cpu->interrupt_request & CPU_INTERRUPT_HARD) && + interrupt_request =3D atomic_read(&cpu->interrupt_request); + if (((interrupt_request & CPU_INTERRUPT_HARD) && (env->eflags & IF_MASK)) || - (cpu->interrupt_request & CPU_INTERRUPT_NMI)) { + (interrupt_request & CPU_INTERRUPT_NMI)) { cpu->halted =3D false; } =20 - if (cpu->interrupt_request & CPU_INTERRUPT_SIPI) { + if (interrupt_request & CPU_INTERRUPT_SIPI) { if (!cpu->vcpu_dirty) { whpx_get_registers(cpu); } do_cpu_sipi(x86_cpu); } =20 - if (cpu->interrupt_request & CPU_INTERRUPT_TPR) { + if (atomic_read(&cpu->interrupt_request) & CPU_INTERRUPT_TPR) { cpu_reset_interrupt(cpu, CPU_INTERRUPT_TPR); if (!cpu->vcpu_dirty) { whpx_get_registers(cpu); @@ -1350,7 +1358,7 @@ static void whpx_memory_init(void) =20 static void whpx_handle_interrupt(CPUState *cpu, int mask) { - cpu->interrupt_request |=3D mask; + atomic_or(&cpu->interrupt_request, mask); =20 if (!qemu_cpu_is_self(cpu)) { qemu_cpu_kick(cpu); --=20 2.17.1