From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776719; cv=none;
	d=zohomail.com; s=zohoarc;
	b=HX/S8CL4BVfqKyhTWisOTc2P5oJafS97PyhfWaR6/BNbb36/CvZS6tEcU8VMeRgW2tn/Cd/T9HuttT6Ab3Z3kl3FPoyAOQKdFxevHAE3LR0rB8idGMMzY7F3puYy1NGi85BM1eJcrTabi5Vh7dNS/EVH+jnlJF6sFP8Cdcg2BDc=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776719;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=Bli328WsnAA7e6BAnLZlQPV2xXXE4Q5muDDz6zeVzNM=;
	b=RmURU7cHgT1ImtJaf/PaP4l3W4D0sOFA9WGRaor07au1gT1c7qdYUNYYFm2DTgm3pigITElqwblPqW18uwHyecPOXFuXXoEpxMOo5I2FDBNtISqp7Lrb1LPqh5qmRIRpJI7NvknGx7Iyrz5a8/Kcj27K0hWAVbYKkCZr2ms0eic=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776719284416.40437909164234;
 Mon, 9 Dec 2024 12:38:39 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkV8-0006Dl-Vj; Mon, 09 Dec 2024 15:37:07 -0500
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 <phil@philjordan.eu>)
 id 1tKkV4-0006CQ-WD
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:03 -0500
Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkV2-0003Cb-Up
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:02 -0500
Received: by mail-ej1-x62a.google.com with SMTP id
 a640c23a62f3a-aa69251292dso222900666b.2
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:36:59 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.36.57
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:36:58 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776619;
 x=1734381419;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=Bli328WsnAA7e6BAnLZlQPV2xXXE4Q5muDDz6zeVzNM=;
 b=e6oeiZpu0b+UIZK1QOuPmuI2msBB1BuTwvXFfHhiw8CVH7Tnbc2211XO7RkVhIw6ik
 OXRai7b4PdnVJ6c/1cKKc8wSqkSZL+YDPu83cybp/qbn+4DQBc8tEkGnYcm6HjkyNh4k
 VF4CesNILgEVk63FIW3SDj9ef6LIdchq/WdJZRn7VNemDmmhtX5RuCFaNq0TRKyge7nM
 XqVdPobYKbUR4i+xdZcTF7zJbgSfaKFFOckagEX7PMbKMDZQcdSTA8ngcMSRl2DJFV7l
 gNLPspyDpm6Dj7G2XI4tFXGxbwGeE3b1vrlKp657TcM/Cg7PkU/2m0LrfA9lX3ImfgBY
 AfpQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776619; x=1734381419;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=Bli328WsnAA7e6BAnLZlQPV2xXXE4Q5muDDz6zeVzNM=;
 b=v78k9F8CRSZukGVKRjA2yG4HP5vsQVsQEJRLBtwGdBGUywhSpz+XhqrDGYomg+ZlC8
 SKKsXLrsClS2/oJUzVd0KRfuIHaiHYEyuCT5HHSg1F12d20+mDbffbpei5Q+MbSFS76D
 TsAQyE9xI8QtIqYSRfH8NEmTetYjDKXZDGNickEXzvRvxny4hBtU3KTmJmvp5MMseY1V
 zFkXLYAaiGknqUN5/RVBv2vfhe1hgHC5P+b3KGbvjylK/AHVsBIXm/Ugp75XOUFvsSvB
 9mKSysUobNBiQqMgk045FqeYPekI/2+Zpv4jY8Nr3ZyxqxKhksecuhmuzGMraP4WBiyb
 S4Kw==
X-Gm-Message-State: AOJu0Yw0YY2DVuPER/EupqVuktiIu2phdamAf+2HOytHbu4538P8zrfj
 ahefzSGmIlltPyY19hXYNx9BpV+1vEfT7CNxxtDMW8QUn9h5DjjA7Pr/PT0drHwow1TfiL/Ri+Z
 jPw==
X-Gm-Gg: ASbGnctrsUP9TBPStg54GOzF2PZBMmL9rEoiJ/vUkFbzmJIFAA0bfzrmEkCmnus0Xq4
 3MftocTNxsozeexScRIVpsYBo1NJO+uoL+M4aWrlXusitp19fXjy88y7IIgTLMW5KT82a/Aglvk
 Neg1wHqzsqyb3xMUKjwwZkFAkGyF0b4siqDwiHYHqMG/dIfkAwce89gZDrwYUIUOvfy5bywc482
 Iv1MgB2Hckj/lIc5eicj8yY9EKTG50sojHNjpT16b7TMcnlw8BbuRWvd8Uc0BnSDEoirmZJjp9k
 KEw/9DSDMWANI5ylOUWTweOWSuVllw==
X-Google-Smtp-Source: 
 AGHT+IHAgIfV0CH2ESB7U0RihyDwcsE4KwhWx9RoRlyJl0MzLDwtmoS5iSRTNbAC864Z/Y6LGGs1Cg==
X-Received: by 2002:a17:906:18aa:b0:aa6:80ed:e9af with SMTP id
 a640c23a62f3a-aa680edeb9cmr609832566b.25.1733776618468;
 Mon, 09 Dec 2024 12:36:58 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 01/11] hvf: Add facility for initialisation code prior to
 first vCPU run
Date: Mon,  9 Dec 2024 21:36:19 +0100
Message-Id: <20241209203629.74436-2-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::62a;
 envelope-from=phil@philjordan.eu; helo=mail-ej1-x62a.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776722251116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

Some VM state required for fully configuring vCPUs is only available
after all devices have been through their init phase. This extra
function, called just before each vCPU makes its first VM entry,
allows us to perform such architecture-specific initialisation.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
Reviewed-by: Alexander Graf <agraf@csgraf.de>
---
 accel/hvf/hvf-accel-ops.c | 5 +++++
 include/sysemu/hvf_int.h  | 1 +
 target/arm/hvf/hvf.c      | 4 ++++
 target/i386/hvf/hvf.c     | 4 ++++
 4 files changed, 14 insertions(+)

diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index d60874d3e6..c17a9a10de 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -442,6 +442,11 @@ static void *hvf_cpu_thread_fn(void *arg)
     cpu_thread_signal_created(cpu);
     qemu_guest_random_seed_thread_part2(cpu->random_seed);
=20
+    if (!cpu_can_run(cpu)) {
+        qemu_wait_io_event(cpu);
+    }
+    hvf_vcpu_before_first_run(cpu);
+
     do {
         if (cpu_can_run(cpu)) {
             r =3D hvf_vcpu_exec(cpu);
diff --git a/include/sysemu/hvf_int.h b/include/sysemu/hvf_int.h
index 42ae18433f..2775bd82d7 100644
--- a/include/sysemu/hvf_int.h
+++ b/include/sysemu/hvf_int.h
@@ -67,6 +67,7 @@ const char *hvf_return_string(hv_return_t ret);
 int hvf_arch_init(void);
 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range);
 int hvf_arch_init_vcpu(CPUState *cpu);
+void hvf_vcpu_before_first_run(CPUState *cpu);
 void hvf_arch_vcpu_destroy(CPUState *cpu);
 int hvf_vcpu_exec(CPUState *);
 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index ca7ea92774..0b334c268e 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1061,6 +1061,10 @@ int hvf_arch_init_vcpu(CPUState *cpu)
     return 0;
 }
=20
+void hvf_vcpu_before_first_run(CPUState *cpu)
+{
+}
+
 void hvf_kick_vcpu_thread(CPUState *cpu)
 {
     cpus_kick_thread(cpu);
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index c5d025d557..3b6ee79fb2 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -338,6 +338,10 @@ int hvf_arch_init_vcpu(CPUState *cpu)
     return 0;
 }
=20
+void hvf_vcpu_before_first_run(CPUState *cpu)
+{
+}
+
 static void hvf_store_events(CPUState *cpu, uint32_t ins_len, uint64_t idt=
vec_info)
 {
     X86CPU *x86_cpu =3D X86_CPU(cpu);
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776723; cv=none;
	d=zohomail.com; s=zohoarc;
	b=lZCTcrEyCz9aKqxcOttXvA7TtfXc7hytclMIiNr34WdcjBScxUZ5BR3MZLacagC7g310vG1ajSwIXemPEF8etGkQBrLRpGMsPIuWcHcQbZZ6hvwdd15ynKVEupvdO8M3n1aiBI8SKPcfLWCtREi3bUflX9y4pZm1Z+fjiDrY8Yo=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776723;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=z36PaPssdPX4LUQilDfpdanawwu1/7BMip/Q5SIiz60=;
	b=gkGAnWUBc+BR1PcSumtREMG7i6/Uid5r1wqEV9YRHLWXu7cA/4N08ILdIRxSE+Yr7hgXIaByOSx0oGIkpDmf2xVfMYgVc7vaeeMtbI8tMad+r8utuIARRVEJvsTMDbMUi95LDv+bYyICD+ePqwGFFXWRRcugwTZcg6+s2Y3syk0=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776722993158.83122655131467;
 Mon, 9 Dec 2024 12:38:42 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkV9-0006Ez-RH; Mon, 09 Dec 2024 15:37:07 -0500
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 <phil@philjordan.eu>)
 id 1tKkV6-0006Cz-Ds
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:04 -0500
Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkV3-0003Cn-Cl
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:04 -0500
Received: by mail-ej1-x629.google.com with SMTP id
 a640c23a62f3a-aa69077b93fso166505766b.0
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:01 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.36.58
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:36:59 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776620;
 x=1734381420;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=z36PaPssdPX4LUQilDfpdanawwu1/7BMip/Q5SIiz60=;
 b=lp4X1goYUlXI2n4VhWK70QV6t0dLthgN4zl/5Z2T3OeWc2dUT/YJAYK6Ot+3PzjmA4
 cee/qaRLf+fQ+EPOl/opnSsEmjqouLUPk8PwmUdXAUH5QMefr29RvkUxEKIXVOtj11Ks
 pmh6ILqlPJWE1c1MV3QuCI6NV8ZRB/0ZRu3a843vWlusR/nYJpRJoy+c9NpzlI9s1DpE
 GwKzX/DG0TZuJPa0mW5pe6AGnUcXxQe+iWuqt7HyMINcP8cttEhKDicW3ijhjThra1hy
 vkDixevRKYrq3Nqf8R4Wrn+5gPg6qkoxHWx58FaU7wjxzSVVs1lN9vurlgz3VoaK/Pch
 BV/g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776620; x=1734381420;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=z36PaPssdPX4LUQilDfpdanawwu1/7BMip/Q5SIiz60=;
 b=luDrKFI0KdKHqKBNUXY8zo8YuMuroLknB9aGF6Op5ZJMClz9wzq8wUgNKMtXKzXPEG
 VOEwH5f0w3caY2MbSfvKY3wRLXJmVV5dt50X+uStge7lZuvEhIK9cs/7bVCzCvRMNVjb
 VqYcpKeM7hv3ATuS9zcdUnwPy3yXwTWsrx5WtJN9CZUbN6DDGZtvTR3jVAExiHrB8n3U
 8QQZDSh0Kv6iZSiF/atlESfkyj2ThokY0r6x/UwqRg2ivhCKnuHgYWPBsSFb/DnJFB9Y
 YRH6ym+B3Vb8mqzotiKfdq/ycmgp3rD+5OE39VwyRj42EGg7T+AcxKeOsdyEQwBDOsAw
 Ll9A==
X-Gm-Message-State: AOJu0Yz0Bf1ag/C6XUmqliCmoGdBzBJugZyzYdr2IpQuZY3C/43QLxPb
 jiincLNn58kxzYMz0tRI9+YZ2QXK5R2iWFjBDEU1QR6Q1FRPaneIuKFye9/53wykf4zVB2lQyVU
 p9A==
X-Gm-Gg: ASbGnctMdr+dlb7UwKnB4A6DNh9HiNkEF6mWbRUVn3/P8C387QrG4WYALLrv3aXU9UN
 JjIIkLmdDjWh34mSeS9kaFJuSvyFYSEhCsIaEjW5PaynOJDtMkmj2qf32o5Ec19B52RCsQlDddc
 1z/0VfxiOF/0Oqrn4rEL+rhJULrunC3Odathr7mhQ4nNDqLQ6eanXU7BFprBjRaE/Y45tHtEk04
 pM6itLOJIl1caHAU80AB2ytqmdD0YeuNghB/pUw+6KUDSqqL0+geXwJjlUHOUSteEQQHiISEKvL
 5HisTFWUtWgLuM3dfRCZlAYjOlGsMw==
X-Google-Smtp-Source: 
 AGHT+IFCHGWvN4eBD40P7KsA69Hh/NiSP7Yqnb4S4X4ce8RQIDfvzoGa/pie8HPVbmfSwC9QhBz4dA==
X-Received: by 2002:a17:906:4ca:b0:aa6:2d86:bd2c with SMTP id
 a640c23a62f3a-aa63a0ed36cmr1178098066b.21.1733776619685;
 Mon, 09 Dec 2024 12:36:59 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 02/11] arm/hvf: Initialise GICv3 state just before first vCPU
 run
Date: Mon,  9 Dec 2024 21:36:20 +0100
Message-Id: <20241209203629.74436-3-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::629;
 envelope-from=phil@philjordan.eu; helo=mail-ej1-x629.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776723801116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

Initialising the vCPU PFR0_EL1 system register with the GIC flag in
hvf_arch_init_vcpu() does not actually work because the GIC state is
not yet available at that time.

If we set this flag just before running each vCPU for the first time,
the GIC will definitely be fully initialised at that point.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
Reviewed-by: Alexander Graf <agraf@csgraf.de>
Tested-by: Zenghui Yu <zenghui.yu@linux.dev>
---
 target/arm/hvf/hvf.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 0b334c268e..bc431f25cc 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -993,7 +993,6 @@ int hvf_arch_init_vcpu(CPUState *cpu)
     CPUARMState *env =3D &arm_cpu->env;
     uint32_t sregs_match_len =3D ARRAY_SIZE(hvf_sreg_match);
     uint32_t sregs_cnt =3D 0;
-    uint64_t pfr;
     hv_return_t ret;
     int i;
=20
@@ -1042,12 +1041,6 @@ int hvf_arch_init_vcpu(CPUState *cpu)
                               arm_cpu->mp_affinity);
     assert_hvf_ok(ret);
=20
-    ret =3D hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64PFR0_EL1=
, &pfr);
-    assert_hvf_ok(ret);
-    pfr |=3D env->gicv3state ? (1 << 24) : 0;
-    ret =3D hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64PFR0_EL1=
, pfr);
-    assert_hvf_ok(ret);
-
     /* We're limited to underlying hardware caps, override internal versio=
ns */
     ret =3D hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64MMFR0_EL=
1,
                               &arm_cpu->isar.id_aa64mmfr0);
@@ -1063,6 +1056,16 @@ int hvf_arch_init_vcpu(CPUState *cpu)
=20
 void hvf_vcpu_before_first_run(CPUState *cpu)
 {
+    uint64_t pfr;
+    hv_return_t ret;
+    ARMCPU *arm_cpu =3D ARM_CPU(cpu);
+    CPUARMState *env =3D &arm_cpu->env;
+
+    ret =3D hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64PFR0_EL1=
, &pfr);
+    assert_hvf_ok(ret);
+    pfr |=3D env->gicv3state ? (1 << 24) : 0;
+    ret =3D hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64PFR0_EL1=
, pfr);
+    assert_hvf_ok(ret);
 }
=20
 void hvf_kick_vcpu_thread(CPUState *cpu)
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776762; cv=none;
	d=zohomail.com; s=zohoarc;
	b=cV7JKhZQjRfjVEl6nEcDs8GeCcKzr4Aplo1FHWJzgP31rRrQzIyltQgWbe+hLt4lKF69m2VwZJSq1k5kw2R2BmPMV+Qguvy4aKkTS6UpY3LgOUWgdwN9VgYf6hS7yJqGqalNSfaKev7448bH9/L58Pl5TUTnjlz0yi2o9iSNUSs=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776762;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=qYKrY4D89CQtOtQV4UE1A1McnS4pHYxVCom2HH+qHOk=;
	b=ern1WN6fXLVODE840NeDnl76TQfp9R2N3mk4qslaehTrf4qd6h/OYXgUsGp23/lNSIjOXBatmpyXwGcM7KM5bAP9AwaFIeaw+oe8Ml2xDNshVTd0PosZOF9d2pUr9iFnkIyi8NSsFCw5puL735FImZ72kUMlIf9g0QgPfvefe+U=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776762604781.093804604668;
 Mon, 9 Dec 2024 12:39:22 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkVA-0006Fp-MY; Mon, 09 Dec 2024 15:37:08 -0500
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 <phil@philjordan.eu>)
 id 1tKkV7-0006DT-FJ
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:05 -0500
Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkV4-0003D1-Ce
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:05 -0500
Received: by mail-ej1-x636.google.com with SMTP id
 a640c23a62f3a-aa68b513abcso229204566b.0
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:02 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.36.59
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:37:00 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776621;
 x=1734381421;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=qYKrY4D89CQtOtQV4UE1A1McnS4pHYxVCom2HH+qHOk=;
 b=bawufz62s0+B4u9giuELv0ftic9R5QPCb2vQLlmQbYw7xLIo3VVyVSYOKkjLGmZlS8
 fl7RtGD+uyTBRnFBfcbqnOhysXl8rSAob6I/vFRMn+XwI4Ts9xt/TM0GLeZ6eREpceu0
 LufjcdwYGp79Kk1AcwVeTWKY705uodypdQVYL7m69IIJaBaBErgqj8Bhmlz6i+Kka87P
 hnovsxj7AM2kw3RxX6V/a0IJGmOrxlwPgwg9TWT5LLgQYmLQbr6lx4AZPtEQhG3tIB+D
 CHAcAMyIUnSpBW5tVbA183tDKK74AZM0Flhh+elqSbMXGPsuROg4VwoNai1tyz6GTOPw
 8JMQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776621; x=1734381421;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=qYKrY4D89CQtOtQV4UE1A1McnS4pHYxVCom2HH+qHOk=;
 b=uCgQ3SkXFItaLOSg88BZi5ORInxIIDU9SPM8au+PaCwg1VMbrYzwISFU1egclajtm2
 i/Wqvtu/nar1yJr1qDNQkjG2Yc8UWG8b8vpu0MIKZRiRe3kSjhKvabcW8mHtSCCMfzOJ
 6a1fhAlWxQm/NnFUloh+ScZBU0Y6X2uKfPTmY6Ala2t0uS/KIPpXV96NMF1blCKP3FuE
 zO4GVVNGHCtcPLhIUtLdzk1zaDRLxdk1TXtIxO0gCzwKvH6tG2tD/TpjZDHeEdpnLRGR
 hVvUtUbpec6pUZG0seNPTTq4VAaXSMQ4uTyQDlt/7+Fno+DjLn/tUptTe8r8eWPSYp2W
 qQwQ==
X-Gm-Message-State: AOJu0YwgTu9RsT9Rne9M2f4Zjs09RubENTOq8aUPS81+OvSFaLwTM8JX
 z3CsRqFBQUdGhceYTMOx3xm0UIHLSSw0Awzr5u2WQk72yI55aipKuMTebJmSV/9nfE5EpAoJI6b
 JQg==
X-Gm-Gg: ASbGncuzPkA8s7Bw9A4I0an/feaE45/35kocbMKINpxkW4rRos+vzztRUAdu8Hpr0kd
 gaOGA+kfpqVA252zQWFf6PLu2cRhV3UUVJPD+KO64B7O36YglQG5jyLKyfbEchcjKec3LjAg1D2
 jBJ785JFQ5Yl2Yu+GpASNEb8dDFDgWLXzpfflTmGn/mz01SdtxmPueVFOtF4GbsbYZwH40kNTRV
 nwO8aaa/yukuYAg+eT79TVEqAkp7M67xfDlTduzoKva3u8EqR88COGBjUjznyqiDYk4U4JOYevN
 slE8YxPRBfQTnQF2C1ZKx5CjPy1+FA==
X-Google-Smtp-Source: 
 AGHT+IGpQVRF/pbWeU4ghCdI1WiusaGqYHZNlg9MVL7VNjeigJCwKaKS24noJW27M/XzGw7NgFye7g==
X-Received: by 2002:a17:906:8455:b0:aa6:96c4:ad58 with SMTP id
 a640c23a62f3a-aa696c4ae47mr307131966b.61.1733776620739;
 Mon, 09 Dec 2024 12:37:00 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 03/11] i386/hvf: Don't send signal to thread when kicking
Date: Mon,  9 Dec 2024 21:36:21 +0100
Message-Id: <20241209203629.74436-4-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::636;
 envelope-from=phil@philjordan.eu; helo=mail-ej1-x636.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776763863116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

This seems to be entirely superfluous and is costly enough to show up in
profiling. hv_vcpu_interrupt() has been demonstrated to very reliably
cause VM exits - even if the target vCPU isn't even running, it will
immediately exit on entry.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 target/i386/hvf/hvf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 3b6ee79fb2..936c31dbdd 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -214,7 +214,7 @@ static inline bool apic_bus_freq_is_known(CPUX86State *=
env)
=20
 void hvf_kick_vcpu_thread(CPUState *cpu)
 {
-    cpus_kick_thread(cpu);
+    cpu->thread_kicked =3D true;
     hv_vcpu_interrupt(&cpu->accel->fd, 1);
 }
=20
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776674; cv=none;
	d=zohomail.com; s=zohoarc;
	b=e1HznuK95VkGIHff8Cu8lSs5DfsVvKt74kZU0jzAzeQuoLzyBFFy/Np5z/2osA/DOzeCEmArgYf8urc7wsn8ykJ9/I0mzdcVdiwZwUupD/WglYwCvxXACUgoHA2E+1OKnmUuHBuwIuCvLyU/T+oszJzElrCdEbuVPJOyRZwgkUk=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776674;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=Hi0SZTNhz11ho3vCY2FYS+EKuGIwlKWvrSV2lPVozDU=;
	b=j2dlJeDZcWTwvLlqCE0xm5p9mQCMsCVH7mJIh624CN+SEKYIB5VVo/FVrTkfJrK3y1CJyRl2OUf/hPLlaFuQKISAhD2Zp4628rb0jkuN12tqWpjCZnb7FvO93tMLe8po7jYv6c+Lw0QvIrqO1jhifeddSOJPag1MulihuWbDLpo=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776674558611.2480681106811;
 Mon, 9 Dec 2024 12:37:54 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkVB-0006Gl-Md; Mon, 09 Dec 2024 15:37:09 -0500
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 <phil@philjordan.eu>)
 id 1tKkV7-0006De-W5
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:06 -0500
Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkV5-0003DC-IA
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:05 -0500
Received: by mail-ej1-x634.google.com with SMTP id
 a640c23a62f3a-aa560a65fd6so870330866b.0
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:02 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.37.00
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:37:01 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776622;
 x=1734381422;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=Hi0SZTNhz11ho3vCY2FYS+EKuGIwlKWvrSV2lPVozDU=;
 b=LytLI0b4iJMT6mfRLDoHGMDH0C/XjYWsXujFYX1U/r/nifkvCkEQrUpeSjpEynhl5w
 Rsw8EIEnoTSjoODXWu0r7B538DG+pUEYzUib68JvFku+aO/NBQnU/iJ5jyljwwyTHsbj
 XsBmgSilDfCx+17WxR9GPNvMpkm7Syd/MURkGTjk2Z1qhTdslzolfu9R1kmtCSI0fpTs
 H4Oz4WyrA8YSghBAC3P2LFwzEvXlltk9dqGTLGuVEwx+OU8weo1fjLIvznbYML+vc/mn
 sP8e98AtqT/FQlTOtiXzDvODgmWtGKfxMv7ZZPgibqvwJHxsR6INqVTx2806Qgx9vojs
 N9MA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776622; x=1734381422;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=Hi0SZTNhz11ho3vCY2FYS+EKuGIwlKWvrSV2lPVozDU=;
 b=mklPMLx4q8YKAPKYF+9UIcee5uzOIOOpyr6cigUKsZKJI9USR8Q0VWaMLUkvkA/iY1
 WpKhgCzwBBZ0feGcHXl8/tab6QlwndPd45v8GSa2CH8YjWPySVka4CbqkGXjM1lI4vvk
 ilYSXDsc/BpnH2x8MZ6i/oow9D1vmr6SEriVyl23shlp61DoKZ3tf3P30+5l6o0prqfA
 eh41uYocxnQiw4ml2yLT2DnlE5adi1DOsbNLfxWE1w2pgk02hPfLhML8TO4uCSNmSpNg
 5KqeddzYOoNVc8hAx6VxmzcSbeGzB1qeFY5soSxjyUnXqsz7fcYp6v2dm6RoaEFuip6l
 8r3A==
X-Gm-Message-State: AOJu0YxWUTyGCbtgGtb6X7f30vZuT0TivWAVAYvhFpOvzK/anPPvvOjs
 N1xGo5ZRq8kTPzA3uFcbL7AcFUSenGZdaK03lRrIagWld02V8DQjsoLq6+hfOb58h42CqFGk7ft
 OZw==
X-Gm-Gg: ASbGncsAxUhc1YAvOd1NzHjsvrDCp+mWmtCAH7oZYFzzSKSoive3+3+G9yP/5WxczmZ
 vgtba7CRxET9ZN0kXClTkoT/BRpXzrgo6JxIE78i/UKubuTJtH98sJck1bsCkU0Se0sZXHveoBK
 p6AjnjNM4HlzamF5p6m/rMWRypXuKgoRxAaADOUJGpcaUlWtgBld83v1/57gr0FUMlBKB1bWgUj
 CCVUOyUjEyLH2ZxzI+Yh4vS5wT08deAtAi3/XST6gH3VhEu4shpvQAcd4ok74e4fbe5CFhWdmr+
 s4+rHI9vLh4AVTEXFKA6QHsaAHN0+w==
X-Google-Smtp-Source: 
 AGHT+IF97ZP4nL6Caxhy2PrICmPoNEio8MDbDpQr48YBwj0h6+Tmb9xVPRXPbfzgKVgW2Kg/0c4fyg==
X-Received: by 2002:a17:907:3f11:b0:aa6:42d8:afac with SMTP id
 a640c23a62f3a-aa6a01bea0bmr85134066b.15.1733776621756;
 Mon, 09 Dec 2024 12:37:01 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 04/11] i386/hvf: Pre-fetch emulated instructions
Date: Mon,  9 Dec 2024 21:36:22 +0100
Message-Id: <20241209203629.74436-5-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::634;
 envelope-from=phil@philjordan.eu; helo=mail-ej1-x634.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776676194116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

The HVF x86 instruction decoder has previously read each instruction
component a few bytes at a time. The HVF vCPU VM exit reports the length
of the faulted instruction, so we can just pre-fetch the memory for the
whole thing in one go, saving extra round-trips for most instructions.

The old code path is retained in case there is a race between VM exit
and another thread overwriting the faulted instruction. In this case,
the instruction length could be wrong, so we allow fetching additional
instruction bytes the traditional way if the prefetched bytes are
overrun.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 target/i386/hvf/hvf.c        |  6 +++---
 target/i386/hvf/x86_decode.c | 18 +++++++++++++++---
 target/i386/hvf/x86_decode.h |  5 ++++-
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 936c31dbdd..095f934923 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -522,7 +522,7 @@ int hvf_vcpu_exec(CPUState *cpu)
                 struct x86_decode decode;
=20
                 load_regs(cpu);
-                decode_instruction(env, &decode);
+                decode_instruction(env, &decode, ins_len);
                 exec_instruction(env, &decode);
                 store_regs(cpu);
                 break;
@@ -562,7 +562,7 @@ int hvf_vcpu_exec(CPUState *cpu)
             struct x86_decode decode;
=20
             load_regs(cpu);
-            decode_instruction(env, &decode);
+            decode_instruction(env, &decode, ins_len);
             assert(ins_len =3D=3D decode.len);
             exec_instruction(env, &decode);
             store_regs(cpu);
@@ -667,7 +667,7 @@ int hvf_vcpu_exec(CPUState *cpu)
             struct x86_decode decode;
=20
             load_regs(cpu);
-            decode_instruction(env, &decode);
+            decode_instruction(env, &decode, ins_len);
             exec_instruction(env, &decode);
             store_regs(cpu);
             break;
diff --git a/target/i386/hvf/x86_decode.c b/target/i386/hvf/x86_decode.c
index a4a28f113f..79dfc30408 100644
--- a/target/i386/hvf/x86_decode.c
+++ b/target/i386/hvf/x86_decode.c
@@ -73,8 +73,13 @@ static inline uint64_t decode_bytes(CPUX86State *env, st=
ruct x86_decode *decode,
         VM_PANIC_EX("%s invalid size %d\n", __func__, size);
         break;
     }
-    target_ulong va  =3D linear_rip(env_cpu(env), env->eip) + decode->len;
-    vmx_read_mem(env_cpu(env), &val, va, size);
+
+    if (decode->len + size < decode->prefetch_len) {
+        memcpy(&val, decode->prefetch_buf + decode->len, size);
+    } else {
+        target_ulong va  =3D linear_rip(env_cpu(env), env->eip) + decode->=
len;
+        vmx_read_mem(env_cpu(env), &val, va, size);
+    }
     decode->len +=3D size;
    =20
     return val;
@@ -2099,9 +2104,16 @@ static void decode_opcodes(CPUX86State *env, struct =
x86_decode *decode)
     }
 }
=20
-uint32_t decode_instruction(CPUX86State *env, struct x86_decode *decode)
+uint32_t decode_instruction(CPUX86State *env, x86_decode *decode,
+                            uint32_t ins_len)
 {
     memset(decode, 0, sizeof(*decode));
+
+    target_ulong va =3D linear_rip(env_cpu(env), env->eip);
+    uint32_t prefetch_len =3D MIN(ins_len, sizeof(sizeof(decode->prefetch_=
buf)));
+    vmx_read_mem(env_cpu(env), decode->prefetch_buf, va, prefetch_len);
+    decode->prefetch_len =3D prefetch_len;
+
     decode_prefix(env, decode);
     set_addressing_size(env, decode);
     set_operand_size(env, decode);
diff --git a/target/i386/hvf/x86_decode.h b/target/i386/hvf/x86_decode.h
index a2d7a2a27b..0ff368210b 100644
--- a/target/i386/hvf/x86_decode.h
+++ b/target/i386/hvf/x86_decode.h
@@ -297,11 +297,14 @@ typedef struct x86_decode {
     bool is_fpu;
     uint32_t flags_mask;
=20
+    uint8_t prefetch_buf[16];
+    uint16_t prefetch_len;
 } x86_decode;
=20
 uint64_t sign(uint64_t val, int size);
=20
-uint32_t decode_instruction(CPUX86State *env, struct x86_decode *decode);
+uint32_t decode_instruction(CPUX86State *env, x86_decode *decode,
+                            uint32_t ins_len);
=20
 target_ulong get_reg_ref(CPUX86State *env, int reg, int rex_present,
                          int is_extended, int size);
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776727; cv=none;
	d=zohomail.com; s=zohoarc;
	b=CpjLHiUn0F/SPzHsjiCF0POS/RnH6LsvvKfX5EfjoZsr4qbtTBuOaJb+ibAtItDRjhBfKs+melMYk1GULccvXpx/HVa8BRQHfD3j4SnlVC1tIE4vxZdQK1T5wegslEvsnmb8CZlczGcGKcA+QRV0U8dMLScR8nEwINqDBTaCBNc=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776727;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=80w6MVYCpseGDOCn7UKs1ZHKVvdaX2IHhBei9UGetlE=;
	b=inm8sPhUXz62dE8AqPWAHAcMvoSeSjTr20ryMMSvAEntvDqndbvBD3hGUy+B5CfuQcHoyBZkhA5Yo1hYa4PXq8oChXRexrJulu/Y/H3MlhbdkpRIznAaBecAp57+ZPGqYNuRgQ2+NAHJ/Y/1sJ6/I7V7TJrMjkaxBLBBZJprT3I=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 173377672684145.90049007565369;
 Mon, 9 Dec 2024 12:38:46 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkVD-0006I5-Is; Mon, 09 Dec 2024 15:37:11 -0500
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 <phil@philjordan.eu>)
 id 1tKkV8-0006EC-Te
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:06 -0500
Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkV6-0003De-Sp
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:06 -0500
Received: by mail-ej1-x631.google.com with SMTP id
 a640c23a62f3a-a9e8522445dso966119666b.1
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:04 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.37.01
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:37:02 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776623;
 x=1734381423;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=80w6MVYCpseGDOCn7UKs1ZHKVvdaX2IHhBei9UGetlE=;
 b=rfuVEk5WfTeJ3xysFPn1GjsVsvOqMg33iFMtgDaa0Nbhs6EflHvGkWrHAQ5mO/sdN8
 p5fzjMM4JUWjHGUNyiSbkr71Qmq9kC4TPshkr7tDu/ywm8FqQk+6qkTpp9UXDHbsqxe3
 7wmZY1oGFouc/xWdWtQW62FHZ9mjkk+R47AzAX86qpg2AT4I0aD7P8dYmul6phKDlvWb
 lhYbZAiQf6fXHm+AlnaRqhldOSy9oEhBkZM44Z2Vjqccn3bv/+BhiWxmSmFD9+qOHtDT
 mC0K9uduRaiq4JNndGfSI7zgkQLwRx+5f/Z4M2eGsTulQUe6qBGhQjzFrx6IH0WyxMXk
 RGDg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776623; x=1734381423;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=80w6MVYCpseGDOCn7UKs1ZHKVvdaX2IHhBei9UGetlE=;
 b=eVdiRcBxT0cIgZp5fepC4BW/edj1tYLnhAp5BT3yYKPJ0IdFCjEdruMJLGdaMkyMb0
 GT51sfr7ZFy9BkPJ/7lOMWhEVIU+mKYZpCniHidK1WCUxewIv7pdOYQ0J5oTwg88W+gT
 EzDgRosAJDQJlSewMx8yU4iS0FWClR+LUOhXCl7T14JUUMut0HQpm6OUDnl6qssmsage
 otwyDJ8H8phYM9gRAVz/iz9YFU84eVk3gi5w2GJvCNEOBA5Aen9dYtkIhnF0kDqjkIUP
 HaeKhSWolj12DDtH0nksTEufqD5BJGnbNbknHNLVrXCpnGQQ8XFSF+kkM2B+SGtvRvBD
 06pA==
X-Gm-Message-State: AOJu0YyK323DY7NPIQHtueSjPtd6zA+09ELL4uDJBr76MMvQVih2vURO
 TzWQjf0nIG4DerjNwqoEzrmyi/69HYBM08ZcLvNOGusD9sUfnenEQCHnhmcdRyV2Y/OFuTPOyO0
 +TA==
X-Gm-Gg: ASbGncv15YGbtCZyb2BKkearM/6jcIqbMLN+y6xtyplAPwTNe7CDXBs2U24kfaIj29f
 fViwyW8mgxaeyVOAVXHAQ9pc69ate8vOdUUV+/8XLwwiawprSB2dWib2ylSlr3Bi2df0bY2A4rH
 1Z663M/0zQYIf/I6yM1x9Dv1PGqTklzxXWXydOHd8DnCkZ50GPwiNHrkjh29lA3zuMNJgIyRdsA
 MXA5e3QcrrI5E1bbGZauUbpEXW/fyByhYM6A/fw9W32W219R9QAhyRD8oc9e3u08YP8qYl+FOsh
 nA+eF8FRZ3GiZTAWwcWzGpL35WULJw==
X-Google-Smtp-Source: 
 AGHT+IHOA10+IOWGH1xs673rmZxDJL/OiFnvd5GyWVUohsMAsTmIkOG70k/3jPi/czq8ZesF7SOLlA==
X-Received: by 2002:a17:906:9ca:b0:aa6:8430:cb02 with SMTP id
 a640c23a62f3a-aa69ce64479mr187055566b.61.1733776622848;
 Mon, 09 Dec 2024 12:37:02 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 05/11] i386/hvf: Decode APIC access x86 instruction outside
 BQL
Date: Mon,  9 Dec 2024 21:36:23 +0100
Message-Id: <20241209203629.74436-6-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::631;
 envelope-from=phil@philjordan.eu; helo=mail-ej1-x631.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776727823116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

The HVF accelerator suffers from severe BQL contention under common
practical workloads. x86 instruction decoding for software-emulating
faulted instructions is a somewhat expensive operation, and there
is no need to hold the BQL while performing it. Except in very
unusual edge cases, only an RCU read lock is acquired during the
instruction fetch from memory.

This change therefore moves instruction decoding for APIC access
VM exits to before the BQL is acquired. This improves performance
on APIC-heavy workloads.

It would be nice to eventually move instruction decoding outside
the BQL for MMIO EPT faults as well, but that case is more
complicated as not every EPT fault exit needs decoding/executing.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 target/i386/hvf/hvf.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 095f934923..3f1ff0f013 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -444,6 +444,7 @@ int hvf_vcpu_exec(CPUState *cpu)
     CPUX86State *env =3D &x86_cpu->env;
     int ret =3D 0;
     uint64_t rip =3D 0;
+    struct x86_decode decode;
=20
     if (hvf_process_events(cpu)) {
         return EXCP_HLT;
@@ -481,6 +482,11 @@ int hvf_vcpu_exec(CPUState *cpu)
         rip =3D rreg(cpu->accel->fd, HV_X86_RIP);
         env->eflags =3D rreg(cpu->accel->fd, HV_X86_RFLAGS);
=20
+        if (exit_reason =3D=3D EXIT_REASON_APIC_ACCESS) {
+            load_regs(cpu);
+            decode_instruction(env, &decode, ins_len);
+        }
+
         bql_lock();
=20
         update_apic_tpr(cpu);
@@ -519,8 +525,6 @@ int hvf_vcpu_exec(CPUState *cpu)
             slot =3D hvf_find_overlap_slot(gpa, 1);
             /* mmio */
             if (ept_emulation_fault(slot, gpa, exit_qual)) {
-                struct x86_decode decode;
-
                 load_regs(cpu);
                 decode_instruction(env, &decode, ins_len);
                 exec_instruction(env, &decode);
@@ -559,7 +563,6 @@ int hvf_vcpu_exec(CPUState *cpu)
                 macvm_set_rip(cpu, rip + ins_len);
                 break;
             }
-            struct x86_decode decode;
=20
             load_regs(cpu);
             decode_instruction(env, &decode, ins_len);
@@ -664,10 +667,6 @@ int hvf_vcpu_exec(CPUState *cpu)
             break;
         }
         case EXIT_REASON_APIC_ACCESS: { /* TODO */
-            struct x86_decode decode;
-
-            load_regs(cpu);
-            decode_instruction(env, &decode, ins_len);
             exec_instruction(env, &decode);
             store_regs(cpu);
             break;
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776740; cv=none;
	d=zohomail.com; s=zohoarc;
	b=kDC/M0MSt42I2Og2CeG6bzBwjm6w+kq08rFja1Iap28K6MN72Y8M0PH/iIL9TUkSeDHqyu+A1/S9TKNdPL4pHFU7lDrMfr8Lbdu7OKjTdtwmi3I/TqfGKTQ1JDAul+7q6/5wVAyf5zHjb2xvafkmkBS8Ivg0tyPREyeb94biBi8=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776740;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=o+++OhUvZkOaxfpw+rWVgz3w1Q+zW3e1baRIfvJZtEo=;
	b=UmONcOnG5ISmDI3t8VQoZIGRNi3H5hWGzt9D6AD27mcbsIhmGG8Zg5bGk5R92HifZ7BblZeaYDn9dNe3chDXbEjCYoGzHykEpeBDh/0W+A/V/OvwSH7v2dG38bP3CsGhe4M/I9/c/PO5shoP0YdbXiYp8hSuaLb8RBNfEBytrYg=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776740803145.14034886809316;
 Mon, 9 Dec 2024 12:39:00 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkVT-0006Pf-6z; Mon, 09 Dec 2024 15:37:27 -0500
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 <phil@philjordan.eu>)
 id 1tKkVB-0006GL-6O
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:09 -0500
Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkV8-0003E2-Kk
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:08 -0500
Received: by mail-ej1-x62e.google.com with SMTP id
 a640c23a62f3a-aa629402b53so669894766b.3
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:05 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.37.03
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:37:03 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776624;
 x=1734381424;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=o+++OhUvZkOaxfpw+rWVgz3w1Q+zW3e1baRIfvJZtEo=;
 b=ms/8y+uyLFnYoqR8L9fXwGnwmzK29Nz8m7ptjM4I67vxgzbErvf3ffDtAzrNnGWoZw
 YK3dmV9lXpjFLdl5cC1CEojASAMbvqJ/C47USS6e+T3I28TAnxm/XIC3sZzBD2ZJxHLd
 ne3rduxCTEQ3FJWnMJYue4t0oxGJGkveK2QAxIqDFmdZvEsLh8wTh4L/kK9bSmevQ2WL
 cHiq+7rE9YePk4mLfwTLnYFzct4ZiZHTOkY5ETge7ofLg7S6EyQBHURuAQDZql1bjX+7
 AP6SyHaD8YU+dE9SMuBs2YbFPQMEgS6K21z8XSxZ3oBqqdd4Zn1PA2g3urQgJaPTjQL5
 Wy4w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776624; x=1734381424;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=o+++OhUvZkOaxfpw+rWVgz3w1Q+zW3e1baRIfvJZtEo=;
 b=wHooHuV8Funbp+1b4I+AzqBbZ8fIMD1dIFtYMn8HKY6N03Y7y/Nj1KTM6o+aA3IRog
 mh8msE1Wuv1bGFDuUvbYy31jjeMt187WFbhVQK2TvqhEfqasaGvzlQn0JgDB1qMKh1Hw
 Ew9fYjaDIEkeTQuFXxc8xPe0c5mXnlF358suiLjXW1BSRWis/Tex/CU4M+qA7thHIP5I
 X1v0GyUocZQMwSnOSXIswE9v59VnUDXjlOv/qqViBalHBVDYWJSLM6HNlTH/5rPH65Rf
 T+64ay9HFaa/1/c5UjvZEGts4vebLBzEHwCS3vagbQ/hZ72cyKFBds9/7NV3WcWwcau+
 x5PA==
X-Gm-Message-State: AOJu0YzCdFFPdxyvUOHxD6qEPNP1tM+gmWW7min0U9co99bgbSTn3/xD
 NQtrN2jGfpQba+oG+df74FknKLO0wd7UitMIhHz3zGxHqkBzbO+sFPmTbvHSqD53HpjkcKGBMZs
 Y/w==
X-Gm-Gg: ASbGncthHUDVKWMaVUmVEknwz+0yLhPzHBRKfN7STYSFdAbF1bzZn14dbGpWhX3idZS
 9Sb6oNiwn48E3NYLz39fb35jXvTyvbTwcj2KrVEr01RnjfwJUQ6wKM9KAmNXDFo4p+0LofAVrr/
 vHbzx0PKGfTUNBV5ZyeurSzS6ym8Gou8+XJo7Vovyhc51Omt4azRtdHhaAsmRaRBefeyvb/kN2G
 jYKQA1WrQtB78rcQo4gl876dBNLX83xAlLhW9uTwabtzO07jMdQmVXE70uxalz5h6+VTAU9iYBB
 cgTZDH4AANOSqj6msMvUQpgDOhaZXg==
X-Google-Smtp-Source: 
 AGHT+IHv8BT2W08XVUJFbJlufdVJBUD/yYahMz4RRJKZpaFOo3Lq0o9noBsWAWneNSDHwtn6K7ejqA==
X-Received: by 2002:a17:906:3cb2:b0:aa6:59ee:1a19 with SMTP id
 a640c23a62f3a-aa659ee1a91mr847399366b.60.1733776623883;
 Mon, 09 Dec 2024 12:37:03 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 06/11] i386/hvf: APIC access exit with fast-path for common
 mov cases
Date: Mon,  9 Dec 2024 21:36:24 +0100
Message-Id: <20241209203629.74436-7-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::62e;
 envelope-from=phil@philjordan.eu; helo=mail-ej1-x62e.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776744081116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

The implementation of the EXIT_REASON_APIC_ACCESS vm exit handler has so far
been essentially the same as a regular EPT fault handler, performing a full
simulation of the faulted instruction. The code path has also not been used=
 at
all because the APIC base address setter in Hypervisor.framework was never
called. This change improves the former.

In particular, the APIC_ACCESS exit provides us some additional metadata wh=
ich
in many cases allows us to avoid a full instruction emulation.

There is no need to walk the memory hierarchy, because exit_qual contains t=
he
APIC MMIO offset. It also tells us whether it's an MMIO read or write. So
we can detect common mov instructions and directly call the relevant APIC
accessor functions.

For more complex instructions, we can fall back to the usual instruction
emulation.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 hw/intc/apic.c               |  4 +-
 include/hw/i386/apic.h       |  2 +
 meson.build                  |  1 +
 target/i386/hvf/hvf.c        | 18 +++++++-
 target/i386/hvf/trace-events |  9 ++++
 target/i386/hvf/trace.h      |  1 +
 target/i386/hvf/x86_emu.c    | 84 ++++++++++++++++++++++++++++++++++++
 target/i386/hvf/x86_emu.h    |  2 +
 8 files changed, 117 insertions(+), 4 deletions(-)
 create mode 100644 target/i386/hvf/trace-events
 create mode 100644 target/i386/hvf/trace.h

diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index 4186c57b34..add99f01e5 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -788,7 +788,7 @@ static void apic_timer(void *opaque)
     apic_timer_update(s, s->next_time);
 }
=20
-static int apic_register_read(int index, uint64_t *value)
+int apic_register_read(int index, uint64_t *value)
 {
     DeviceState *dev;
     APICCommonState *s;
@@ -936,7 +936,7 @@ static void apic_send_msi(MSIMessage *msi)
     apic_deliver_irq(dest, dest_mode, delivery, vector, trigger_mode);
 }
=20
-static int apic_register_write(int index, uint64_t val)
+int apic_register_write(int index, uint64_t val)
 {
     DeviceState *dev;
     APICCommonState *s;
diff --git a/include/hw/i386/apic.h b/include/hw/i386/apic.h
index eb606d6076..47946e5581 100644
--- a/include/hw/i386/apic.h
+++ b/include/hw/i386/apic.h
@@ -20,6 +20,8 @@ void apic_designate_bsp(DeviceState *d, bool bsp);
 int apic_get_highest_priority_irr(DeviceState *dev);
 int apic_msr_read(int index, uint64_t *val);
 int apic_msr_write(int index, uint64_t val);
+int apic_register_read(int index, uint64_t *value);
+int apic_register_write(int index, uint64_t val);
 bool is_x2apic_mode(DeviceState *d);
=20
 /* pc.c */
diff --git a/meson.build b/meson.build
index 147097c652..0846c09bdb 100644
--- a/meson.build
+++ b/meson.build
@@ -3606,6 +3606,7 @@ if have_system or have_user
     'target/arm/hvf',
     'target/hppa',
     'target/i386',
+    'target/i386/hvf',
     'target/i386/kvm',
     'target/loongarch',
     'target/mips/tcg',
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 3f1ff0f013..2a13a9e49b 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -75,6 +75,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/accel.h"
 #include "target/i386/cpu.h"
+#include "trace.h"
=20
 static Error *invtsc_mig_blocker;
=20
@@ -666,8 +667,21 @@ int hvf_vcpu_exec(CPUState *cpu)
             store_regs(cpu);
             break;
         }
-        case EXIT_REASON_APIC_ACCESS: { /* TODO */
-            exec_instruction(env, &decode);
+        case EXIT_REASON_APIC_ACCESS: {
+            bool is_load =3D (exit_qual & 0x1000) =3D=3D 0;
+            uint32_t apic_register_idx =3D (exit_qual & 0xff0) >> 4;
+
+            if (simulate_fast_path_apic_mmio(is_load, apic_register_idx,
+                                             env, &decode)) {
+                env->eip +=3D ins_len;
+            } else {
+                trace_hvf_x86_vcpu_exec_apic_access_slowpath(
+                    is_load ? "load from" : "store to", apic_register_idx,
+                    ins_len, decode.prefetch_buf[0], decode.prefetch_buf[1=
],
+                    decode.prefetch_buf[2], decode.prefetch_buf[3],
+                    decode.prefetch_buf[4], decode.prefetch_buf[5]);
+                exec_instruction(env, &decode);
+            }
             store_regs(cpu);
             break;
         }
diff --git a/target/i386/hvf/trace-events b/target/i386/hvf/trace-events
new file mode 100644
index 0000000000..7d0230fb37
--- /dev/null
+++ b/target/i386/hvf/trace-events
@@ -0,0 +1,9 @@
+# See docs/devel/tracing.rst for syntax documentation.
+
+# hvf.c
+hvf_x86_vcpu_exec_apic_access_slowpath(const char *access_type, uint32_t a=
pic_register_idx, uint32_t ins_len, uint8_t ins_byte_0, uint8_t ins_byte_1,=
 uint8_t ins_byte_2, uint8_t ins_byte_3, uint8_t ins_byte_4, uint8_t ins_by=
te_5) "xAPIC %s register 0x%" PRIx32" taking slow path; instruction length:=
 %" PRIu32 ", bytes: %02x %02x %02x %02x  %02x %02x ..."
+
+# x86_emu.c
+hvf_x86_emu_mmio_load_instruction_fastpath(int cmd, int operand_size, int =
opcode_len, uint8_t opcode_byte_0, uint8_t opcode_byte_1, uint8_t opcode_by=
te_2) "slow path apic load: cmd =3D %d, operand_size =3D %u, opcode_len =3D=
 %u, opcode =3D [ %02x %02x %02x ... ]"
+hvf_x86_emu_mmio_store_instruction_fastpath(int cmd, int operand_size, int=
 opcode_len, uint8_t opcode_byte_0, uint8_t opcode_byte_1, uint8_t opcode_b=
yte_2) "slow path apic store: cmd =3D %d, operand_size =3D %u, opcode_len =
=3D %u, opcode =3D [ %02x %02x %02x ... ]"
+hvf_x86_fast_path_apic_mmio_failed(const char *access_type, uint32_t apic_=
register_idx, uint64_t value, int result) "xAPIC %s register 0x%"PRIx32", v=
alue 0x%"PRIx64" returned error %d from APIC"
diff --git a/target/i386/hvf/trace.h b/target/i386/hvf/trace.h
new file mode 100644
index 0000000000..14f15a752a
--- /dev/null
+++ b/target/i386/hvf/trace.h
@@ -0,0 +1 @@
+#include "trace/trace-target_i386_hvf.h"
diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c
index 015f760acb..197fa155a0 100644
--- a/target/i386/hvf/x86_emu.c
+++ b/target/i386/hvf/x86_emu.c
@@ -44,6 +44,7 @@
 #include "x86_flags.h"
 #include "vmcs.h"
 #include "vmx.h"
+#include "trace.h"
=20
 void hvf_handle_io(CPUState *cs, uint16_t port, void *data,
                    int direction, int size, uint32_t count);
@@ -897,6 +898,89 @@ static void exec_wrmsr(CPUX86State *env, struct x86_de=
code *decode)
     env->eip +=3D decode->len;
 }
=20
+static bool mmio_load_instruction_fastpath(x86_decode *decode, CPUX86State=
 *env,
+                                           int *load_dest_reg)
+{
+    if (decode->cmd =3D=3D X86_DECODE_CMD_MOV && decode->operand_size =3D=
=3D 4
+        && decode->opcode_len =3D=3D 1) {
+        if (decode->opcode[0] =3D=3D 0x8b) {
+            g_assert(decode->op[0].type =3D=3D X86_VAR_REG);
+            g_assert(decode->op[1].type =3D=3D X86_VAR_RM);
+
+            *load_dest_reg =3D decode->op[0].reg | (decode->rex.r ? R_R8 :=
 0);
+            return true;
+        } else if (decode->opcode[0] =3D=3D 0xa1) {
+            *load_dest_reg =3D R_EAX;
+            return true;
+        }
+    }
+
+    trace_hvf_x86_emu_mmio_load_instruction_fastpath(
+        decode->cmd, decode->operand_size, decode->opcode_len,
+        decode->opcode[0], decode->opcode[1], decode->opcode[2]);
+
+    return false;
+}
+
+static bool mmio_store_instruction_fastpath(x86_decode *decode, CPUX86Stat=
e *env,
+                                            uint64_t *store_val)
+{
+    if (decode->cmd =3D=3D X86_DECODE_CMD_MOV && decode->operand_size =3D=
=3D 4 &&
+        decode->opcode_len =3D=3D 1) {
+        if (decode->opcode[0] =3D=3D 0x89) { /* mov DWORD PTR [reg0+off],r=
eg1 */
+            g_assert(decode->op[1].type =3D=3D X86_VAR_REG);
+            g_assert(decode->op[0].type =3D=3D X86_VAR_RM);
+
+            *store_val =3D RRX(env, decode->op[1].reg | (decode->rex.r ? R=
_R8 : 0));
+            return true;
+        } else if (decode->opcode[0] =3D=3D 0xc7) { /* mov DWORD PTR [reg0=
+off],imm*/
+            g_assert(decode->op[0].type =3D=3D X86_VAR_RM);
+            g_assert(decode->op[1].type =3D=3D X86_VAR_IMMEDIATE);
+            *store_val =3D decode->op[1].val;
+            return true;
+        } else if (decode->opcode[0] =3D=3D 0xa3) { /* movabs ds:immaddr,e=
ax */
+            *store_val =3D RRX(env, R_EAX);
+            return true;
+        }
+    }
+
+    trace_hvf_x86_emu_mmio_store_instruction_fastpath(
+        decode->cmd, decode->operand_size, decode->opcode_len,
+        decode->opcode[0], decode->opcode[1], decode->opcode[2]);
+    return false;
+}
+
+
+bool simulate_fast_path_apic_mmio(bool is_load, uint32_t apic_register_idx,
+                                  CPUX86State *env, x86_decode* decode)
+{
+    uint64_t value;
+    int load_dest_reg;
+    int res;
+
+    if (is_load) {
+        if (!mmio_load_instruction_fastpath(decode, env, &load_dest_reg)) {
+            return false;
+        }
+        res =3D apic_register_read(apic_register_idx, &value);
+        if (res =3D=3D 0) {
+            RRX(env, load_dest_reg) =3D value;
+        }
+    } else {
+        if (!mmio_store_instruction_fastpath(decode, env, &value)) {
+            return false;
+        }
+        res =3D apic_register_write(apic_register_idx, value);
+    }
+
+    if (res !=3D 0) {
+        trace_hvf_x86_fast_path_apic_mmio_failed(
+            is_load ? "load from" : "store to", apic_register_idx, value, =
res);
+        raise_exception(env, EXCP0D_GPF, 0);
+    }
+    return true;
+}
+
 /*
  * flag:
  * 0 - bt, 1 - btc, 2 - bts, 3 - btr
diff --git a/target/i386/hvf/x86_emu.h b/target/i386/hvf/x86_emu.h
index 8bd97608c4..6726ca2240 100644
--- a/target/i386/hvf/x86_emu.h
+++ b/target/i386/hvf/x86_emu.h
@@ -31,6 +31,8 @@ void store_regs(CPUState *cpu);
=20
 void simulate_rdmsr(CPUX86State *env);
 void simulate_wrmsr(CPUX86State *env);
+bool simulate_fast_path_apic_mmio(bool is_load, uint32_t apic_register_idx,
+                                  CPUX86State *env, x86_decode* decode);
=20
 target_ulong read_reg(CPUX86State *env, int reg, int size);
 void write_reg(CPUX86State *env, int reg, target_ulong val, int size);
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776760; cv=none;
	d=zohomail.com; s=zohoarc;
	b=nzC5fHKeF1JJzBpryVkBPvKcCIgPHWEzhsDCFii94yHK0lxx+8uvQda9Jqs/3STmhDGDH661E9bTaXPy6PV756cNNQqI81bjfslaTWNuoSqvwYaQninaKM4+HZp4KkjevsFwCCc0/937WWSIywJEl7wXulcMs9w8e0B+enBYnUg=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776760;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=xw6Nq/8rslxJnUqkSeXiT5oto8WsRm37mAQv6Zrh7Zo=;
	b=bUs7EjguJRaheHgXHTh9GQzlIi0KVE5fR0RfvtCVoCWC/vrIEqqtVVJi/t+WeFuMXSTdsWTlZqlkAAtVMOXCw6wPI+VjJZXib4i4O57tGWYQz1PDr4furHI/ortVn2TWEdFYkG5nbTEbm7HXik2N/1pXKYJSX5qNGfSmVsYDv7c=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776759916338.4355771396059;
 Mon, 9 Dec 2024 12:39:19 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkVE-0006J8-NA; Mon, 09 Dec 2024 15:37:12 -0500
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 <phil@philjordan.eu>)
 id 1tKkVA-0006FH-9U
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:08 -0500
Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkV8-0003ES-Ks
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:08 -0500
Received: by mail-ej1-x62f.google.com with SMTP id
 a640c23a62f3a-a9f1c590ecdso885673266b.1
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:05 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.37.04
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:37:04 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776625;
 x=1734381425;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=xw6Nq/8rslxJnUqkSeXiT5oto8WsRm37mAQv6Zrh7Zo=;
 b=10BtnBuKV4kcVgE0DHwEefoen9gFWctr/d3uBG9O7EByyHzpVxQzesF7Pg5mFXMOPf
 FEhsP8kG99qJNyTx0aPJpsFSLSKFEcPwkKfOFE2s5nxFcux16gmU0xV3UMjP/Ki8Tca5
 Zu5I/VNbG5F14JZCPGujjnXW3aMSYIG4XVXob9rycbkG9Ec2ivok9bhQLRb/fECDEqxy
 lSXhT8k/uzJzDBzx6euLGnWV92XpdT/40REo/zpwQcgXKvfO3GMl1XvMqC5nA0TVSJQy
 J+Z2+XnGt0iLYiNeemp/qIluX4ArIh1cSqjk4Ia6AbYFyK2Nj62PRG60eeUvYYnHXKoL
 xjdQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776625; x=1734381425;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=xw6Nq/8rslxJnUqkSeXiT5oto8WsRm37mAQv6Zrh7Zo=;
 b=kIJl6RbyJ76mA2elpCECbGMWn1I7fUMQJ4RYlllYEyWpWLWIJE1MdRp6PvtNbyUr6W
 /wiDr5H951vJEkLtXoMETa5kizu9qyoiS8JM4QZ0zcNWH9/KQjV9XmBEerQWN3oDowBJ
 JBBfBrzP17TcSBIlf9aJ6cpPVtSJWMV4EvfFo5mtExb+VrMNlWkj4AOZssDnBNMbyNYV
 1iUkF/vfId/8QtyxJVdlZgkdnfwK3y2Xi8mwbgNNpY9Jn8GygPS/i6YLRV7l23LAy+Sl
 EhkVkeo/PsJVBjr66cr5ArWwcguwcJ6H8mDVd0EmmVh93YWYi4jEsWoZz1PO5rsTy+fL
 V/+Q==
X-Gm-Message-State: AOJu0YwI74v73fzWDoZaQZGy/GtqwZWiP25iwFX8BU/wftZ4VocyZLUm
 3M5RKnn+xwr6UngY+3sPRLkTxxxSX+aXRbUlhvx9PNTq5WC3al+ljppPvu/9L77mk/Rj+t3T8HM
 e1g==
X-Gm-Gg: ASbGncsaDy1vs5DUi4qyncum+fPxrGCVYoM/CcUZ0+Bn6vnHPM6lKokF46mrhEPOYSP
 r1P2R4G0Sz1Ic0iK8igpUsa8pDAjfjMtLKeyEXsDXAY+GorPVdmmTJRA7o3KcFrdZc+f9QvAhbV
 9S4oEjkEBEXW7p+dNwifX5y45gAo6ktLDhwUXJ4iiCgAyjaTxLzIbOxNW29sf6+jIbxWOL7Zvzh
 VgeTmh1D0K4j5OFDFz7yNgXMtBLeJeA26fNadrMO9wjJVOTfwa2NeGWjrq4OlQLu/b0gCYjQQ/i
 e1z74pn1dRlms7CfhYz1PP6aT4WdLQ==
X-Google-Smtp-Source: 
 AGHT+IHMg8u6xatM3JB2nocPT1UsXkGcZR+sI4zYs81yAcFM4A0d7QHtdMwFv1r1VAuu+oR+0IFR5A==
X-Received: by 2002:a17:907:1dc4:b0:aa6:6c08:dc71 with SMTP id
 a640c23a62f3a-aa69cd8131emr196188866b.23.1733776624887;
 Mon, 09 Dec 2024 12:37:04 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 07/11] i386/hvf: Enables APIC_ACCESS VM exits by setting
 APICBASE
Date: Mon,  9 Dec 2024 21:36:25 +0100
Message-Id: <20241209203629.74436-8-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::62f;
 envelope-from=phil@philjordan.eu; helo=mail-ej1-x62f.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776761942116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

This change activates virtualised APIC access VM exits so the new
fast-pathed implementation will be taken.

Two parts are required for enabling APIC_ACCESS exits rather than
falling back to "regular" MMIO EPT faults: Hypervisor.framework
needs to know the current APIC base address, and the APIC access
virtualisation ctl, VMCS_PRI_PROC_BASED2_CTLS_APIC_ACCESSES,
must be set in the VMCS. The latter has already been set in QEMU's
HVF accel, but setting the APIC base address has been missing.

This change calls hv_vmx_vcpu_set_apic_address() before a vCPU
runs for the first time, and whenever the APICBASE MSR is modified
and the xAPIC is enabled. Additionally, the APIC access ctl is
toggled when the APIC is enabled or disabled, or changes mode.

In addition to making APIC access VM exits occur at all, it also
makes APIC relocation work, at least on the fast path. (QEMU does
not currently support different address spaces per vCPU, which
is why the purely EPT fault based software APIC - and thus the slow
path - does not properly support relocation.)

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 target/i386/hvf/hvf.c     | 11 +++++++++++
 target/i386/hvf/x86_emu.c | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 2a13a9e49b..a7b8d124bb 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -341,6 +341,17 @@ int hvf_arch_init_vcpu(CPUState *cpu)
=20
 void hvf_vcpu_before_first_run(CPUState *cpu)
 {
+    X86CPU *x86_cpu =3D X86_CPU(cpu);
+    hv_vcpuid_t vcpu =3D cpu->accel->fd;
+    uint64_t apic_base;
+    hv_return_t apicbase_result;
+
+    if (cpu_is_apic_enabled(x86_cpu->apic_state)
+        && !is_x2apic_mode(x86_cpu->apic_state)) {
+        apic_base =3D MSR_IA32_APICBASE_BASE & cpu_get_apic_base(x86_cpu->=
apic_state);
+        apicbase_result =3D hv_vmx_vcpu_set_apic_address(vcpu, apic_base);
+        assert_hvf_ok(apicbase_result);
+    }
 }
=20
 static void hvf_store_events(CPUState *cpu, uint32_t ins_len, uint64_t idt=
vec_info)
diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c
index 197fa155a0..88a946cb0f 100644
--- a/target/i386/hvf/x86_emu.c
+++ b/target/i386/hvf/x86_emu.c
@@ -797,10 +797,28 @@ void simulate_wrmsr(CPUX86State *env)
         break;
     case MSR_IA32_APICBASE: {
         int r;
+        hv_return_t res;
=20
         r =3D cpu_set_apic_base(cpu->apic_state, data);
         if (r < 0) {
             raise_exception(env, EXCP0D_GPF, 0);
+        } else {
+            uint64_t pbc =3D rvmcs(cs->accel->fd, VMCS_SEC_PROC_BASED_CTLS=
);
+            uint64_t new_pbc;
+            if (cpu_is_apic_enabled(cpu->apic_state)
+                && !is_x2apic_mode(cpu->apic_state)) {
+                res =3D hv_vmx_vcpu_set_apic_address(cs->accel->fd,
+                                                   data & MSR_IA32_APICBAS=
E_BASE);
+                assert_hvf_ok(res);
+
+                new_pbc =3D pbc | VMCS_PRI_PROC_BASED2_CTLS_APIC_ACCESSES;
+            } else {
+                new_pbc =3D pbc & ~VMCS_PRI_PROC_BASED2_CTLS_APIC_ACCESSES;
+            }
+            if (new_pbc !=3D pbc) {
+                wvmcs(cs->accel->fd, VMCS_SEC_PROC_BASED_CTLS,
+                    cap2ctrl(hvf_state->hvf_caps->vmx_cap_procbased2, new_=
pbc));
+            }
         }
=20
         break;
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776713; cv=none;
	d=zohomail.com; s=zohoarc;
	b=PbHYMqF2/NZvNmo/V2VC3cr4CzOFch6ESdfzzo3Psmn+y8g1F1OZRempQLwh3az2LQeJPYXA4twQwx56p/rTH5Qnz8/ZMc2jxHg92XoZpgWL1Vzad4+pLAlOTM8C04Fdc5bVWd+O2/mX0IEHWDQL746HjAJxBeNIJPXdPuWsygI=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776713;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=krA8fyL06OMuWhugQwkTM4Lyyjdxb/hlEgT8wYfNtek=;
	b=PoxJTeGNCXkf9kjZQZzMrIsHCVL5ix8Z2lFLITAoYLmjNrFyc/8KQrm/I1XFC82K7rENG0iE85to/veSQIPyyk4FGiSKPda2u4BGXJGSej0++XP6ixdGXkNhi8T9Afu+MK/2T+fCV7kht+VB4XCWVI/Rtd6B3RO3/0jvGhRfMVk=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776713670330.5502430687193;
 Mon, 9 Dec 2024 12:38:33 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkVS-0006Oe-TI; Mon, 09 Dec 2024 15:37:26 -0500
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 <phil@philjordan.eu>)
 id 1tKkVB-0006Gz-It
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:09 -0500
Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkVA-0003F6-9N
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:09 -0500
Received: by mail-ej1-x636.google.com with SMTP id
 a640c23a62f3a-aa67af4dc60so282399566b.2
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:07 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.37.05
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:37:05 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776627;
 x=1734381427;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=krA8fyL06OMuWhugQwkTM4Lyyjdxb/hlEgT8wYfNtek=;
 b=DkUsGM+KIIwkBxED9MqBqpJHwgDBcD6lkysQ8SbbbwolQElrnW3/7Zzyhz+CfULahK
 n3RHaFywC/Cl+OAlKteWSRlmkiQaXWa7rxOVJ2YqNAPVQVXhZYayBNa64QnaKWx6EKMC
 /qHShBzTzcBmpICw1sm3RU2iP+0aDyMFouSEacD+Bl3a2Ra5HPXrjtsn5ilXfPr4cT8Y
 Jz9hvjZNXKb9DhSxKnCr3pHsQIdIB5EyrJiGDVEdHcGxVPoKjXqzF6OXz1H1Bl/34ODG
 HHk4cGidKyf/lv6K6IUXe1C1wOnPDjm5RmBNU2DBsECZW2FbsH1COgWQgGLoE0VlSw65
 6r+g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776627; x=1734381427;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=krA8fyL06OMuWhugQwkTM4Lyyjdxb/hlEgT8wYfNtek=;
 b=wU1yLiNiON3UYvtVlAJBopSDWDCJJTSq45iSAAgSnR8FhqDDYlmBiNwXfa7obqU5wB
 ii7Vg+9BW5qQ9bGArIJ86naKf0+BSUp9fmLdXfTcWsWLbdvP64ip+mkC9/BFdhhoHFfN
 G78jPRbJTJozRZo4EnDCVdjWKreODV5AnS9NsrFqh30VbqSYbGR1UQE7R3oYZIk5VhEe
 nKIfZIsRGlqIGsl99CuwWZEF5gugE1qHUWggojcOp1wvXvjtTjno60LI/49wsJqNWvzV
 mzL34LKJAmTYokxFwHo36OgalTfr+1jJOWO0PVyaXuTh/KVeqFAsx2dg0s5FoCbiprEM
 QXAw==
X-Gm-Message-State: AOJu0YykmxOcYlpKytd2GPzC/B6IZrAUToYC5GrHhb2c1YFL/ZVBBHRV
 S+q076x6BEoccg6BYrmOrI8iV3AX9/A7GsBKXAomVThAa9VjP+1DPLYoBmClBMf2+k/olwyFkrs
 RmA==
X-Gm-Gg: ASbGncsrZHdztH+8vB9h9/FtoP62kOat7IM4tl7vtltEdLN6MChllmsAxZ3dxD7g9iy
 i6HGKgB25g70KsqPorfdAJNFwefGn28LLQy2il6MlPaXhqAA3ZQDJ6EBItlkcbM98F1toNwpypa
 dV5wToGnEzWCCylTG+iqm51QJhoAi2er2omAoe7HGA87BUI1TK+t9FRY2FqiFSY2r/KDFU9A4UR
 jWuVw6ustC/oXPqsvwMpkBiFlcU+KXQ/oA/uS4HiD0ErwPlPJg/ZHXLad4zfOoS8ho5H9aC/x5E
 7JEMOz+fSauBFtII5G3sq5qNofwvkQ==
X-Google-Smtp-Source: 
 AGHT+IGgYAERzRBwAhCxDsdhEYv5W+Jsd6e8CC7QdEOBvUYGE+tR8QXY7+Jt1+n08n5gXMqgtFr/ig==
X-Received: by 2002:a17:907:9554:b0:aa6:7d82:5414 with SMTP id
 a640c23a62f3a-aa67d825937mr591543966b.30.1733776626628;
 Mon, 09 Dec 2024 12:37:06 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 08/11] i386/hvf: Variable type fixup in decoder
Date: Mon,  9 Dec 2024 21:36:26 +0100
Message-Id: <20241209203629.74436-9-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::636;
 envelope-from=phil@philjordan.eu; helo=mail-ej1-x636.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776715804116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

decode_bytes reads 1, 2, 4, or 8 bytes at a time. The destination
variable should therefore be a uint64_t, not a target_ulong.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
Reviewed-by: Philippe Mathieu-Daud=C3=A9 <philmd@linaro.org>
---
 target/i386/hvf/x86_decode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/i386/hvf/x86_decode.c b/target/i386/hvf/x86_decode.c
index 79dfc30408..6c7cfc820f 100644
--- a/target/i386/hvf/x86_decode.c
+++ b/target/i386/hvf/x86_decode.c
@@ -61,8 +61,8 @@ uint64_t sign(uint64_t val, int size)
 static inline uint64_t decode_bytes(CPUX86State *env, struct x86_decode *d=
ecode,
                                     int size)
 {
-    target_ulong val =3D 0;
-   =20
+    uint64_t val =3D 0;
+
     switch (size) {
     case 1:
     case 2:
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776751; cv=none;
	d=zohomail.com; s=zohoarc;
	b=H5rxmnM4/xVJsaThktPH71SmLez/zC367zPlR0OBMsSBtP0qYN42ZpvcfXIBRlrRHYRZyf0uJ+PyzdWMKRgs7VPvoGXSdq0iny9rPe4eoKPSKsV2PgQ1Rj2u93ZTaVWTEpNzqboa7sv0w7CpEuEGw8xYb9HwRywg2RFKVcjT/YE=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776751;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=NYJPKkgcbTXxdsXMNMCRcjhKt+ms1PoytQbmmSrV3F4=;
	b=m2nQ6riUEGR44GU5cxh9DWUiW+m5NzhQsDjbIKpEAN0Y8fctw8ti+Y9cZCVIdfsDQ9zlrFrkT7iG+TcUBo28W0cHwvSlVj0RZfsI4V0jnx+8NLi5ipvu1yk13A/g73icQwDTmIueSLcATc3lKwencoBt9nGWJhSAiUUXKfe54L8=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776751633343.86812822920024;
 Mon, 9 Dec 2024 12:39:11 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkVT-0006QJ-Lk; Mon, 09 Dec 2024 15:37:29 -0500
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 <phil@philjordan.eu>)
 id 1tKkVC-0006Hw-J9
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:10 -0500
Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkVB-0003FT-8E
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:10 -0500
Received: by mail-ed1-x52d.google.com with SMTP id
 4fb4d7f45d1cf-5d3e829ff44so3836739a12.0
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:08 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.37.06
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:37:07 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776628;
 x=1734381428;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=NYJPKkgcbTXxdsXMNMCRcjhKt+ms1PoytQbmmSrV3F4=;
 b=MSSrHX2CDFbQUas3w06xQuH9T1mlo9XqCRYGf4YhlI1fXwwiv9acm1GZ4Wr+Ps/Ts/
 7UwT4PvtlGC8H08sFOdXDPJ7jO9kiFHh9i8ahFNbfE8kMqaCBMMj1PjWAGm0aY27AKug
 C0+0ez6sNused4lLL0uAsW5i29pKMRky9Tpzd6Eec6QuesCtNKFXSTYXuDBdmirtUUIl
 eXeIcDcfkkz4U1yhOOMphXtAu3B9c5i06/s5rKi8q8rFFcZe6UwRwSD6F/qJTVWyexFf
 kmrsTW/RWyLd+teiK2Cpq638Eiulztr7anmi4+fuKjAMnpvlKbh+lnxiV8d/l5banm/9
 vcNA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776628; x=1734381428;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=NYJPKkgcbTXxdsXMNMCRcjhKt+ms1PoytQbmmSrV3F4=;
 b=TVWPp6D3aSnBmLL7pv8NMylfTqipg6jZo70dQOtTgwUQ/h7AqfeHthQqRFWVMSBNU4
 9LFPakorZDZrHAdJudD0nz1yjBvOxJ+i8lW5TrwkYDAfiVCZjjMTWExThxtk+t0XNSip
 tjRrM48eQOm6RFp5+vVNlOOLLfoHpkKyiIo0ty1UKWkPJNvngBED/YrGfzHlMcRs548Y
 6QQ004jqzGkAf9g1M/0xEuPh+jCFTOE8usIwZXxeSH9/vke/PY9z9nWr3pjMqiPRCbnL
 6aKrmjEQ/6n6UKlM6rj259fuC4qlWjYEwxKhU4yzPy5U6R13HTSvv6etV6xPnlQS4kSx
 VcSA==
X-Gm-Message-State: AOJu0YyDmHRfLhNcOPabkQU/PLtxmXHb6u41UmrkElaza1ov4v6KKC7S
 8ZAZ3WTrKMMh1cZwhuTaOLSzFSWuxpDftfwSPxGMdqJXKJpC08yEgLqSFvje3AowDeGu6HmHJRA
 TYA==
X-Gm-Gg: ASbGncvJUeEGK6Qsds5A9JEtXSGadfLX+eE2+3S2jR/N0ajxep/VMgc45+w+WScN1bd
 WbhkFNS/nh9cizaWE6cK39auWcF8M73iRiMWAm8Qro2tfY+nUKEVSToQCvUHiOkHcJ/vft0UPhI
 MAcmieZABf7CbPVYvV8R/cYO0Zn9v7xk01lxad3RDczIINmkojXjmRYFp1RLmilRpoJeOLmQohb
 XJjQiTFjuUMOPKsIrLMJ6odRhxYn9cZlnC0xXihCClfzEHrAmBBRvIiyCntg7KoNDFNAiyQ6OtV
 oXtKVITUP2q9qaCrD0vHQE3m8B/EAg==
X-Google-Smtp-Source: 
 AGHT+IHB8k/H2RYEWOrL0OQQ9Gp9k12FNItyZBOVZ8YhOP0e7vqWuWpx893ffQORrlO+5JsHVKcYdA==
X-Received: by 2002:a17:907:1c85:b0:aa6:7ff9:d248 with SMTP id
 a640c23a62f3a-aa6a006e645mr65933966b.8.1733776627709;
 Mon, 09 Dec 2024 12:37:07 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 09/11] i386/hvf: Print hex pairs for each opcode byte in
 decode error
Date: Mon,  9 Dec 2024 21:36:27 +0100
Message-Id: <20241209203629.74436-10-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::52d;
 envelope-from=phil@philjordan.eu; helo=mail-ed1-x52d.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776753959116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

Printing a sequence of bytes as hex with leading zeroes omitted just looks =
odd.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
Reviewed-by: Philippe Mathieu-Daud=C3=A9 <philmd@linaro.org>
---
 target/i386/hvf/x86_decode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/i386/hvf/x86_decode.c b/target/i386/hvf/x86_decode.c
index 6c7cfc820f..f8d37f2d53 100644
--- a/target/i386/hvf/x86_decode.c
+++ b/target/i386/hvf/x86_decode.c
@@ -30,7 +30,7 @@ static void decode_invalid(CPUX86State *env, struct x86_d=
ecode *decode)
 {
     printf("%llx: failed to decode instruction ", env->eip);
     for (int i =3D 0; i < decode->opcode_len; i++) {
-        printf("%x ", decode->opcode[i]);
+        printf("%02x ", decode->opcode[i]);
     }
     printf("\n");
     VM_PANIC("decoder failed\n");
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776736; cv=none;
	d=zohomail.com; s=zohoarc;
	b=jMYqQlnIbXTS3duN2uF42sFEP0bg+1vRCWbW400ZuthVmgXxUNX5XDQBJ69/Mxc1r2lnBmeCYvNDgIyEp99hRV6WMLDS6jp6PfGEWhwFTbxEccaaitAUr+c+wRSnly+OtJ4lu0Zs6Ruvgyca5p9lSXgNLLBpRue61tXH4pXaOTA=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776736;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=IDfEUP5t3qEfB5+/2Qs/ja/PBzmRbPZf8EVWTjWrIGc=;
	b=nqVvJekQ3sZ+yzH1Mv9xVidcDElGTu5J7YLahKh/denPD4EppmB6Ejlr100I9nrwpoW7+7L6m6HnjQbdiviNb34dCpoc66TTjG6H/T5j1sX8w4rdYtLDJlfyrV8UAcMWBUnYHmfqevs3Wu6yxxPnXbROWkND/BV/YAKJKzBacMQ=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776736601573.5744647498349;
 Mon, 9 Dec 2024 12:38:56 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkVe-0006Vi-9R; Mon, 09 Dec 2024 15:37:38 -0500
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 <phil@philjordan.eu>)
 id 1tKkVE-0006Iu-DS
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:12 -0500
Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkVC-0003G3-V0
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:12 -0500
Received: by mail-ed1-x532.google.com with SMTP id
 4fb4d7f45d1cf-5d3f28881d6so2271940a12.1
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:10 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.37.07
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:37:09 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776629;
 x=1734381429;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=IDfEUP5t3qEfB5+/2Qs/ja/PBzmRbPZf8EVWTjWrIGc=;
 b=J+4JuwqyJBLIFpUlJf+k1RJFDlmTO2jp2tnxbO6P2rE4Cumv1nMMq/EaF0jzwJP1Fh
 Bw57UNf/M8cOishB4aSvIgRoAK7FGI5SOyCObsaSCXolqOTxWC2HRHxF0j61ADmyySCB
 bI9EKk/Weqlr4PNiVcDO2TyTmJuwTdzb9SVe9Stgfz9T8fw9Qu2D7JYM2c439nOO0bCL
 thsaxMtPNkvILwY5z11cG4PzcQw3PYjEfWpQvlpWegq2tR/G5a8XXvFSWLRXgWNzsdJr
 Zmdn+vK6gGHG4pm1NYdOrQq1R0STw+OBPDZyaDhfbLyimVDwrLarGPqlCqPV9LDzI7EX
 xTTA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776629; x=1734381429;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=IDfEUP5t3qEfB5+/2Qs/ja/PBzmRbPZf8EVWTjWrIGc=;
 b=IF651jSxuXVTa6PIH0JxpVVPf5AIUapt5vVrX5p/nxIF8uWC7rTfVr4eADp/HC5Jjh
 e/eDoaywfF6tUbcnsv5FJ2oydykJnIjmTSyv9ehgebjR0GWDvw/s/FXUfBgXWakQfs7F
 1BLkdx2YyVQjvUYIlxXL8Q7u4PAMS7Qp3pUcTKJnMm9CzMuL9SCoAV6SvTWqM/BOa6XC
 DxRxd9mWXaW+X1C1xlh6+yiOozWap/TdnO7eGvRcRAADLf/WIjz9090m72mO/BJfuxbd
 kUxGTzgMRJPFXK10Eq8bZ5pXMxYj5J2ZVrBKs9YbtoVE6t99BA/m7vIiBP353SAs7bII
 U5Zg==
X-Gm-Message-State: AOJu0YwaRfYB5xLY64JtBSl9fGnz9VwUeKYqPjLC4CWDa0AlcYzJj2xF
 NfDIGoMGueIJM3AiawlfDj3jcjHk8kK8IxQb0NfE1C4PytREkNtNvEGzYLW1Yl6G7FvLJMvBHoW
 3Zg==
X-Gm-Gg: ASbGncvccQVy1G6aWLzKO3+jBAobqw9JUrfubR6KqXsotNxyvo132KBWR43EyfORSPn
 lCVJNHR790jr2wpL68hd4burJJc5m4g0tu4Ae6R+Lfd8czub3dRpjs+oJg/1+Mk0qf9Xyu+FE3y
 tXsW91qoxjBZEKeHUQ1xVM43HtUyUQAa0YAEZC61eZq7yUcJGDC8f7b7pLkz62cFHOz19jnV9hS
 RHGV0eEzwBC2d7CmpQyk19sNiY9Yj43dSs3t7sUQpyy5JPiLqU+BfDJK/jUFQyXrS702uUBEv9G
 HpLRU13Pd2zYHYOabeiqrQcAgYfExQ==
X-Google-Smtp-Source: 
 AGHT+IGezn1JeAQQGfTDfs4KzWxtxZbySAwO0G3EdUJAYJ3BKTlm3vY5tOvZ4e3J/Irwk4yXruunsA==
X-Received: by 2002:a05:6402:3490:b0:5d0:d2ed:ebb with SMTP id
 4fb4d7f45d1cf-5d4184dd0e0mr5226880a12.3.1733776629471;
 Mon, 09 Dec 2024 12:37:09 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 10/11] hw/intc/apic: Fixes magic number use,
 removes outdated comment
Date: Mon,  9 Dec 2024 21:36:28 +0100
Message-Id: <20241209203629.74436-11-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::532;
 envelope-from=phil@philjordan.eu; helo=mail-ed1-x532.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776737721116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

This changes replaces the use of an explicit literal constant for
the APIC base address mask with the existing symbolic constant
intended for this purpose.

Additionally, we remove the comment about not being able to
re-enable the APIC after disabling it. This is no longer
the case after the APIC implementation's state machine was
modified in 9.0.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
Reviewed-by: Philippe Mathieu-Daud=C3=A9 <philmd@linaro.org>
---
 hw/intc/apic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index add99f01e5..d72cbb2a8f 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -350,9 +350,8 @@ static int apic_set_base(APICCommonState *s, uint64_t v=
al)
         return -1;
     }
=20
-    s->apicbase =3D (val & 0xfffff000) |
+    s->apicbase =3D (val & MSR_IA32_APICBASE_BASE) |
         (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE));
-    /* if disabled, cannot be enabled again */
     if (!(val & MSR_IA32_APICBASE_ENABLE)) {
         s->apicbase &=3D ~MSR_IA32_APICBASE_ENABLE;
         cpu_clear_apic_feature(&s->cpu->env);
--=20
2.39.3 (Apple Git-146)
From nobody Mon May 12 23:36:02 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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
ARC-Seal: i=1; a=rsa-sha256; t=1733776722; cv=none;
	d=zohomail.com; s=zohoarc;
	b=XZ2P0XoflTmmtEUGce7HaRlRuTDG+rikYQNH+s/uRxNg58AnSn3AVDeQgv03HUki/IoudvslB29tDZr9EsH6sGZcLwqALPsXTEaViBIm/qP9tiWsJ8qqsECftsew3o4yN81krKJvnAvgqbaVwyUygOYUrTLrdowfdWRJ3ZeRzuA=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733776722;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=IE9WDOVCTTfWbFzrWk3+NYB4k57W0Vt5GpleV+hnMAc=;
	b=LtUTFFjW0zHKsSAr7MrA82hloFInR8heDQwiMNrHEEJa3WQXkHN7kkcRcaFDhCg3K0Wsfpb2qotEwYxBBt6zYKFdbLJFzEDNKXf5kvhdY9N29tGwGaDviGeP+Pw8UOO+NkONpBLYskB/ksAypmGm63kYTdpFi8QGQBLgonUAk60=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733776718433196.4381299319998;
 Mon, 9 Dec 2024 12:38:38 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tKkVg-0006Wx-F2; Mon, 09 Dec 2024 15:37:40 -0500
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 <phil@philjordan.eu>)
 id 1tKkVG-0006Jh-W7
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:24 -0500
Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <phil@philjordan.eu>)
 id 1tKkVD-0003GQ-R8
 for qemu-devel@nongnu.org; Mon, 09 Dec 2024 15:37:13 -0500
Received: by mail-ej1-x629.google.com with SMTP id
 a640c23a62f3a-aa69077b93fso166530166b.0
 for <qemu-devel@nongnu.org>; Mon, 09 Dec 2024 12:37:11 -0800 (PST)
Received: from localhost.localdomain (h082218084190.host.wavenet.at.
 [82.218.84.190]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-aa692e4e9d5sm141783566b.129.2024.12.09.12.37.09
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 09 Dec 2024 12:37:10 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1733776630;
 x=1734381430;
 darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=IE9WDOVCTTfWbFzrWk3+NYB4k57W0Vt5GpleV+hnMAc=;
 b=R0ihLEGWWAL5uHJvgsajQpWguyLaiG7k/vnXDE1D66vUfYtYmX2WhfqEWwBuwtdZN+
 zYi1+M34YX6/FFVCLWSmEmLdaNfIHyiwRRjtfXeojFx3PZ3yQX2h5ihvTTUHIpw1Ham9
 1bWtivv4fbXOE2lqugSSpOwbzO6ZaTcDZterXSm9RhaqWSPIVNHAqq7FGKJOz85F4GM3
 H66ZBf7RLI75jrMOwGHki2oEwRvcS0K+20WQJ4quCxp+qigrAbQ4chQKuLI5cTTFS1+D
 ZzK4PiuatXqwg0NNOKdj3HZpWn8xi9PL2Kjb2eAxWRq1RodnWrligqJk/thePaYYMLXj
 YR3A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733776630; x=1734381430;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=IE9WDOVCTTfWbFzrWk3+NYB4k57W0Vt5GpleV+hnMAc=;
 b=awMVC/lNhELI5yhw0lm8kkTtiiSiV392jis3+wdsRym9Mxa31kruxlYo/qynYAL3yx
 yXYinOsCkl+5L2T4ffTgewlc5/tmkC3UdJCl4ZCxE6Heqdork/G1VoW8EmTRvkT3JWgf
 vgtSEdcUNkZw+xestwBd23NdTkPyIZKDp7EGytW8euryjua8+ln2z5nv8FNih1NhbDaE
 DTrBnCkCbeC0a7MvVjMkSwLe4TtU9NZKw//wyhsnQYv1QlwdtAMQ2cF0XIM6hMsOoIpD
 CM51FCCtCQo4REXcC5DStNNt5av0wUvWCevs4bAtvFeeM4hm4RTquU1Q63hT0rzKMRz+
 qLnA==
X-Gm-Message-State: AOJu0YwWMyHHBZexDbmWFT6gNUZXvyxfK8aam2aRs4adXkw8DNnD+d7g
 gucgUw2fXRZsNsMT3Bst4+/T1U80PoBlw8nKHpOWQC5xK3Bwyq0XS+s/zOGWstqaCBU9bLMj6Wr
 4eQ==
X-Gm-Gg: ASbGncv5q1dqU4jh3UmlYKDpodIEoZFmV9A+Hc9L6jQAUSEaBNW/yFz6dT2lv+ukY5Z
 BtsTHYVxjshKQVdRqxwvb5js3qVbWiB0NiTnFihJjaLVRSAKn7Gs7UDOM2XtiBRLGSW1lIjKQXo
 0wA+s+EI81KymkXED9P5wpn6SJdifPXdKPirx5h8fEBzjDnGvuJjYLX9HdHVlSuFzL+eDJwOFT6
 Wy/5B6H8gnH5JRJ8spo6OLTkRpg7d01oWer/S80WZhORuqvYbIKpE4yrfoa2e1kQn1E+8bYsjs4
 gottLzOdf6hlPgrPy6r/r8OnsmveTQ==
X-Google-Smtp-Source: 
 AGHT+IGswOYxVOkMA+XvzQnaKOD/7lVr+xcvNSKvz9rdbJJ/otbRBczcyzE8RbzHYCp8ocDjO+jPEg==
X-Received: by 2002:a17:906:4ca:b0:aa6:2d86:bd2c with SMTP id
 a640c23a62f3a-aa63a0ed36cmr1178144466b.21.1733776630516;
 Mon, 09 Dec 2024 12:37:10 -0800 (PST)
From: phil@philjordan.eu
To: qemu-devel@nongnu.org
Cc: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>,
 "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
 Alexander Graf <agraf@csgraf.de>, Peter Maydell <peter.maydell@linaro.org>,
 qemu-arm@nongnu.org, Phil Dennis-Jordan <phil@philjordan.eu>
Subject: [PATCH 11/11] hw/intc/apic: Raise exception when setting reserved
 APICBASE bits
Date: Mon,  9 Dec 2024 21:36:29 +0100
Message-Id: <20241209203629.74436-12-phil@philjordan.eu>
X-Mailer: git-send-email 2.39.3 (Apple Git-146)
In-Reply-To: <20241209203629.74436-1-phil@philjordan.eu>
References: <20241209203629.74436-1-phil@philjordan.eu>
MIME-Version: 1.0
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: neutral client-ip=2a00:1450:4864:20::629;
 envelope-from=phil@philjordan.eu; helo=mail-ej1-x629.google.com
X-Spam_score_int: -10
X-Spam_score: -1.1
X-Spam_bar: -
X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com)
X-ZM-MESSAGEID: 1733776727726116600
Content-Type: text/plain; charset="utf-8"

From: Phil Dennis-Jordan <phil@philjordan.eu>

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 hw/intc/apic.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index d72cbb2a8f..83e626a45e 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -309,6 +309,11 @@ bool is_x2apic_mode(DeviceState *dev)
=20
 static int apic_set_base_check(APICCommonState *s, uint64_t val)
 {
+    /* Refuse to set reserved bits */
+    if (val & MSR_IA32_APICBASE_RESERVED) {
+        return -1;
+    }
+
     /* Enable x2apic when x2apic is not supported by CPU */
     if (!cpu_has_x2apic_feature(&s->cpu->env) &&
         val & MSR_IA32_APICBASE_EXTD) {
--=20
2.39.3 (Apple Git-146)