From patchwork Thu Feb 27 14:19:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994630 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73CEEC19F2E for ; Thu, 27 Feb 2025 14:25:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekC-0006nE-UT; Thu, 27 Feb 2025 09:20: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 ) id 1tnek9-0006h2-Ik for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnek5-0003TF-E4 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740665999; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=016GiMgPCDCxH4pGbauqv5pOlfa+t27Nzdjf4IvZ1wM=; b=NIEd3X8JA7vak89kixpWJSuSjCcUekhwR3jA17aDC8t7L/RW0Wip8hM9uyuxc5A6yueZ9p pX+Amg4PjwVNY9VfhsGJySrkn2UOa8wT2XA5DFMzoVwOFXGNvO3VKk2Y+gBiUyN+4KiNwI WptaVgshzKZah9s0OQxt6wY/ecMiJAc= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-66-jB1P_j1OPVWp6v7kCFiAGA-1; Thu, 27 Feb 2025 09:19:58 -0500 X-MC-Unique: jB1P_j1OPVWp6v7kCFiAGA-1 X-Mimecast-MFC-AGG-ID: jB1P_j1OPVWp6v7kCFiAGA_1740665997 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-abbae81829fso114065966b.3 for ; Thu, 27 Feb 2025 06:19:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740665996; x=1741270796; 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=016GiMgPCDCxH4pGbauqv5pOlfa+t27Nzdjf4IvZ1wM=; b=OF6QWIdqEEHYPHWFfhA0Ho/etaw+1r6VcD9cQ5fYx9oTXd9a+6JuU2e2ZobU5X7P1+ 69GzpS1aQeqEo8DBNPIhwNt3wjwAqJ4tCxofZq0c8KP+kXbuQRMGBtJBsK7rtpplGNA6 abch2DuTWV0GTLSynnppgkObYKowE+229YczKFNLvFj9zDE8O0RT4u4O18dN3KrhoTs7 8mZetO5hd6f+w/tcJsxhC7j6ZBNhW8Eoum9H5Oxn3gdmKUvfVGPatfBNGaqDTntHVwte pxBZFImpml1nqNHeMCcdL3wo2pEUwYcwAT3Zf0cTOfvK1Chsu1VQr3W+sHXXXbkxjns9 MfHg== X-Gm-Message-State: AOJu0YyB7UCoWhIpoektzvK/Obkl8vsjhpa7hVPupzQnxEXDjsGRkJ5p 2PGw/u0oa8u69mO62ntaoOADleJF/WXEsWb+UCvnqS8lcZpEBzGzlihTcfYW2Ck9plBKfjeHPx2 hy25viC6BMQ8IV/1POFLJKy2Uko5G8gF6FVlQdvVGYw2oVpjqiKHvBzTYILUvo4d9ZKJnqWV4he QU4XOJvnMZSSXTLOz77kW19an5noINqalqY7xcnzk= X-Gm-Gg: ASbGncsGHkMJjAiQq3mBD4fe69kyNRTI0aRPQMC4sOnC6LFw/qXFezDp7Op0UZIC27Y bEBz5rz+JdfvyaCUvVQ48s09+gYF0jR+uZjBCl9tYUA/Ww07EEiT4tIk1ANDpGvLa51dtmfRxCI /PC5g1Mq3h4m1hFtPd1VkYF+5QFqD+1sbKRWCIIskXWwCZ8iGlYx33degY+PXOJ/Z4dD/zWoxWg Sp67IMweMyLO1SFVGNhwLmDd9uVnsY9Arg7nPI75dCUNg+0ohTic8CotUboX+AdyRjnSrTLrR8N l99GmiKcKCOkFSRwSbHC X-Received: by 2002:a17:906:3109:b0:aa6:7091:1e91 with SMTP id a640c23a62f3a-abed0c66947mr1240880666b.11.1740665995727; Thu, 27 Feb 2025 06:19:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEP/XSbmvFTNNThmAOiFlW/7Pija0uKgDmKhE89+TZfCvGl0FL/GGGOnlXiMjRl0FuK80btxA== X-Received: by 2002:a17:906:3109:b0:aa6:7091:1e91 with SMTP id a640c23a62f3a-abed0c66947mr1240878666b.11.1740665995200; Thu, 27 Feb 2025 06:19:55 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dcb12sm129184566b.74.2025.02.27.06.19.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:19:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PULL 01/34] qom: Use command line syntax for default values in help Date: Thu, 27 Feb 2025 15:19:19 +0100 Message-ID: <20250227141952.811410-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Akihiko Odaki object_property_help() uses the conventional command line syntax instead of the JSON syntax. In particular, - Key-value pairs are written in the command line syntax. - bool description passed to the function says on/off instead of true/false. However, there is one exception: default values are formatted into JSON. While the command line and JSON syntaxes are consistent in many cases, there are two types where they disagree: string: The command line syntax omits quotes while JSON requires them. bool: JSON only accepts true/false for bool but the command line syntax accepts on/off too, and on/off are also more popular than true/false. For example, the docs directory has 2045 "on" occurances while it has only 194 "true" occurances. on/off are also accepted by OnOffAuto so users do not have to remember the type is bool or OnOffAuto to use the values. Omit quotes for strings and use on/off for bools when formatting default values for better consistency. Signed-off-by: Akihiko Odaki Link: https://lore.kernel.org/r/20250207-bool-v1-1-5749d5d6df24@daynix.com Signed-off-by: Paolo Bonzini --- qom/object_interfaces.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index f35d3313317..1ffea1a7288 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -4,9 +4,11 @@ #include "qapi/error.h" #include "qapi/qapi-visit-qom.h" #include "qobject/qobject.h" +#include "qobject/qbool.h" #include "qobject/qdict.h" #include "qapi/qmp/qerror.h" #include "qobject/qjson.h" +#include "qobject/qstring.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" #include "qom/object_interfaces.h" @@ -177,9 +179,25 @@ char *object_property_help(const char *name, const char *type, g_string_append(str, description); } if (defval) { - g_autofree char *def_json = g_string_free(qobject_to_json(defval), - false); - g_string_append_printf(str, " (default: %s)", def_json); + g_autofree char *def_json = NULL; + const char *def; + + switch (qobject_type(defval)) { + case QTYPE_QSTRING: + def = qstring_get_str(qobject_to(QString, defval)); + break; + + case QTYPE_QBOOL: + def = qbool_get_bool(qobject_to(QBool, defval)) ? "on" : "off"; + break; + + default: + def_json = g_string_free(qobject_to_json(defval), false); + def = def_json; + break; + } + + g_string_append_printf(str, " (default: %s)", def); } return g_string_free(str, false); From patchwork Thu Feb 27 14:19:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994620 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A612EC19F2E for ; Thu, 27 Feb 2025 14:20:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekJ-0006xA-DW; Thu, 27 Feb 2025 09:20:15 -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 ) id 1tnekE-0006py-1B for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnek9-0003Tp-8T for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yd96deOozQ4yFlkLSTWHMyluR4p3ujPsRgX3RMFDVT8=; b=PU1kJAiO+ZMdlT94zPxZbtkNQ/y5FPdp7VRUOUxHI2r6Lx7CaeLTYH0dF6VY+w7juWWx1D jpx2+0v2bRYUITJihcTWg3w6oFKV8zM194e5laF+zNd6oGmz/1NJLE0SpUvFljcV/wENRk YjO2EeMvThFY0Enxz5V/UHDXwCNpggI= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-ythVPMXcMr-U-Zs9c4Armw-1; Thu, 27 Feb 2025 09:20:00 -0500 X-MC-Unique: ythVPMXcMr-U-Zs9c4Armw-1 X-Mimecast-MFC-AGG-ID: ythVPMXcMr-U-Zs9c4Armw_1740665999 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-abb76bd0feeso127363366b.0 for ; Thu, 27 Feb 2025 06:19:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740665997; x=1741270797; 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=Yd96deOozQ4yFlkLSTWHMyluR4p3ujPsRgX3RMFDVT8=; b=hjJ/lyhjbUMDsLt+yF978CwnRohk2qoKcJlVzhU/w+tRGRdgTWGS61a5Qn7f/8ILqZ xjj/zdqa5kSQedW5UTtYEC357EjiMs4bvp8X5UeoUOhFBmAEetFOKPeRl2OxEZyBa505 +zWdp2/acWLxdYsO67q6+Sy3rGAqRZrOw37IZdsKGCF+grzQS0mg7qUhFWQLZGMSqbwa LmKIRnRFbBZpqVtSpMkCNqOpQCxNj63korcU3cIZ422uxYPMO9JaVagnB6hElCoNrobx Z+CcoTzgV+qsAvUdi8lkPBi2cfoJu1ac/ObIZvHK+cu3geL7tq4rjZff9XKJX/vhAKtd olCg== X-Gm-Message-State: AOJu0Yx7Ecr+/6h0pc6rhkOLAXDTVc2TJkYjAqDQpTOHxUP12/tSrjQL iyGtEU9UkC1qIDb+f1l9O5dtRssz5UiYzbRMvakr7E3mdcHjxmR3fOzppPUWHmtWftVABgFPTfF Jes2bXG16aRhU3gsaLHwPKy+qZ2A3Ea2pebbamuNQHoN+z2xNR2gSYv/19b4IeK5aWpJtsIFKt1 QDiF5OHZh8OFaulky4KN3VbxtzwEsFcksaKUEqcNg= X-Gm-Gg: ASbGnctfpClMmVQVnar6USw2AVaKvZ4d5I9lionbN1Ri4W90YceKMbpY17MktiUkYBd CkZ4RghxIt4H7g2T36u/kFjBsVi07va/8j9OfVAvNyc1SrxSMHgXNdXmvejjaE86H7YH8hQD21U 26Rlox3UoNUwcQuDPIJmVwEJnBQvsXeefhZHfLj3Wn4u7TTTTaaHD1ZAVLFC1Q/uAEdQOqMgQq/ NgYn7SRuwqfvLVcveR8jSJhDdDW0Kxstt0iTZvriFModMHPcSw5AXG/HnesFNC5lR5dyK/5e00v Jx1muz/98d5X/k2boIrw X-Received: by 2002:a17:907:96ac:b0:ab7:d34a:8f83 with SMTP id a640c23a62f3a-abf0609c4d0mr495143066b.17.1740665996809; Thu, 27 Feb 2025 06:19:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEue+gpbYy29G1dTgzJx7eaylJDIreWqwC32T3hk9MPX7vIKqxCgOl3nM57B6lknnK94DTc7g== X-Received: by 2002:a17:907:96ac:b0:ab7:d34a:8f83 with SMTP id a640c23a62f3a-abf0609c4d0mr495137066b.17.1740665996400; Thu, 27 Feb 2025 06:19:56 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc5d5sm131905966b.63.2025.02.27.06.19.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:19:55 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 02/34] hpet: do not overwrite properties on post_load Date: Thu, 27 Feb 2025 15:19:20 +0100 Message-ID: <20250227141952.811410-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Migration relies on having the same device configuration on the source and destination. Therefore, there is no need to modify flags, timer capabilities and the fw_cfg HPET block id on migration; it was set to exactly the same values by realize. Reviewed-by: Zhao Liu (hpet_post_load only) Signed-off-by: Paolo Bonzini --- hw/timer/hpet.c | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index dcff18a9871..ccb97b68066 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -77,6 +77,7 @@ struct HPETState { uint8_t rtc_irq_level; qemu_irq pit_enabled; uint8_t num_timers; + uint8_t num_timers_save; uint32_t intcap; HPETTimer timer[HPET_MAX_TIMERS]; @@ -237,15 +238,12 @@ static int hpet_pre_save(void *opaque) s->hpet_counter = hpet_get_ticks(s); } - return 0; -} - -static int hpet_pre_load(void *opaque) -{ - HPETState *s = opaque; - - /* version 1 only supports 3, later versions will load the actual value */ - s->num_timers = HPET_MIN_TIMERS; + /* + * The number of timers must match on source and destination, but it was + * also added to the migration stream. Check that it matches the value + * that was configured. + */ + s->num_timers_save = s->num_timers; return 0; } @@ -253,12 +251,7 @@ static bool hpet_validate_num_timers(void *opaque, int version_id) { HPETState *s = opaque; - if (s->num_timers < HPET_MIN_TIMERS) { - return false; - } else if (s->num_timers > HPET_MAX_TIMERS) { - return false; - } - return true; + return s->num_timers == s->num_timers_save; } static int hpet_post_load(void *opaque, int version_id) @@ -277,16 +270,6 @@ static int hpet_post_load(void *opaque, int version_id) - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); } - /* Push number of timers into capability returned via HPET_ID */ - s->capability &= ~HPET_ID_NUM_TIM_MASK; - s->capability |= (s->num_timers - 1) << HPET_ID_NUM_TIM_SHIFT; - hpet_fw_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability; - - /* Derive HPET_MSI_SUPPORT from the capability of the first timer. */ - s->flags &= ~(1 << HPET_MSI_SUPPORT); - if (s->timer[0].config & HPET_TN_FSB_CAP) { - s->flags |= 1 << HPET_MSI_SUPPORT; - } return 0; } @@ -347,14 +330,13 @@ static const VMStateDescription vmstate_hpet = { .version_id = 2, .minimum_version_id = 1, .pre_save = hpet_pre_save, - .pre_load = hpet_pre_load, .post_load = hpet_post_load, .fields = (const VMStateField[]) { VMSTATE_UINT64(config, HPETState), VMSTATE_UINT64(isr, HPETState), VMSTATE_UINT64(hpet_counter, HPETState), - VMSTATE_UINT8_V(num_timers, HPETState, 2), - VMSTATE_VALIDATE("num_timers in range", hpet_validate_num_timers), + VMSTATE_UINT8_V(num_timers_save, HPETState, 2), + VMSTATE_VALIDATE("num_timers must match", hpet_validate_num_timers), VMSTATE_STRUCT_VARRAY_UINT8(timer, HPETState, num_timers, 0, vmstate_hpet_timer, HPETTimer), VMSTATE_END_OF_LIST() From patchwork Thu Feb 27 14:19:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3A76C282C1 for ; Thu, 27 Feb 2025 14:20:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekH-0006pz-Fu; Thu, 27 Feb 2025 09:20:13 -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 ) id 1tnekC-0006n6-6k for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekA-0003gD-81 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666005; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LJB2c4bxzU4WmleXJ0VX4oOrax270tsJkQEdT3TL6CQ=; b=JPQ6IEo7b23SziV76iDSYLxHbr3sIKp4FMvoeI5aYXNT5+i7iMoc41o6hvSEcjCSlE6D6w EuSqRd25/v7KGmZeSyrdappTiRCj/cKJiXlts/W6zo/cM3pfMoG8nzQpdhUF7M883wpzWv SGWsexRgqGqLhxAprOMnTRgwJ39wZUQ= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-X_g0KlgzP4S43QBinx6ECA-1; Thu, 27 Feb 2025 09:20:03 -0500 X-MC-Unique: X_g0KlgzP4S43QBinx6ECA-1 X-Mimecast-MFC-AGG-ID: X_g0KlgzP4S43QBinx6ECA_1740666002 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-abba896add9so116633066b.1 for ; Thu, 27 Feb 2025 06:20:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666001; x=1741270801; 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=LJB2c4bxzU4WmleXJ0VX4oOrax270tsJkQEdT3TL6CQ=; b=t6/a1DcSzvc3t2rEZP7D+TWltUVmSNUC7HV1st8Z3s74w6MWyFQwBgyFjvriLKDXCo BeGd7L2s1aHWveXmNb1GIKxUv+ogJjqlDu0hFa0SKIZSbX6mjaV07+8eM/chVN3BbNQI yU5zlHOO36Z09XZ3Ovcuyqe6pjKfpAzRcfe4olfXfw6gVFeidP9ke3wOrsPej9WANGFQ kXcLOvlR2GNNRGZpkxlna6oPmeH9RSq59dyMWVi3D8fFAFcr7Fu4haruw1VARVdQMkLz Ihbio+1Ndgu7OknwyeRHhpVGtl4esxKHnjPIy4ItvvITL5Vjnpmt2aal0NYsppuLrE2Z cHwg== X-Gm-Message-State: AOJu0YxyXHV5YF0YpNFUF/+pqD150CmRWxp04kiVUJrBoh8LVJj1u+Yj Np0gwW8czTOKwp7ThYgFcqGMf3ol0jN8OGdqFMzN6kcmAAeETHoY3wE8T1Vas5sW7KNY8HFm5Fb ZUdxC3dMVHI27zLnUS02W2/ngAoX7snd5TX5MM8utbtyHnqxjVK54qvj6I1Vpcz2ufulNy2Z1tx XUiQebCA2HP8/jcjHbEO08tFoWKg5dD+/07C8qZao= X-Gm-Gg: ASbGncsC/qPwRsVtC2iWvku0QfN4NocJM+s0598wRk01dh2QRE5svEHUMW2Ssr77QPo zxtbPYosQj/nYEBeInvHQYMwGJE02SqBcAaC4t1V9m5Bk+i30lUM6ArnjnqX+1VhbpvU4niRz1R Bx97Y1d5yKtfkcAUb7u7kb+gT1SWAA5ypKAiq8edKFakKRzVsENeBgOuGwdCga6Pzwx6d9Ddum6 erqHKoesRc65APqpNpohkVR5Uj0qRgoH1nQczbadD1fDuG9hN0Ornw0RWK3m3TyUg6fZgskDwh9 Kj8yTnpvNEBvnXW3tura X-Received: by 2002:a17:906:6a19:b0:abb:6e95:b272 with SMTP id a640c23a62f3a-abc09a8091emr2753678766b.30.1740666001305; Thu, 27 Feb 2025 06:20:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFN5q1EWZ4vpbjOAN8dICG2xZjo5vyycBjiz7KXuTPHwe5I3CuqRzdgEaQV0KEYm6igPgQFNQ== X-Received: by 2002:a17:906:6a19:b0:abb:6e95:b272 with SMTP id a640c23a62f3a-abc09a8091emr2753675266b.30.1740666000845; Thu, 27 Feb 2025 06:20:00 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf19aca8a0sm76306266b.178.2025.02.27.06.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:19:57 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 03/34] i386: Fix the missing Rust HPET configuration option Date: Thu, 27 Feb 2025 15:19:21 +0100 Message-ID: <20250227141952.811410-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Zhao Liu The configuration option of Rust HPET is missing, so that PC machine can't boot with "hpet=on" when QEMU Rust support is enabled. Add the Rust HPET configuration option. Fixes: d128c341a744 ("i386: enable rust hpet for pc when rust is enabled") Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250217154416.3144571-1-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- rust/hw/timer/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/hw/timer/Kconfig b/rust/hw/timer/Kconfig index afd98033503..42e421317a5 100644 --- a/rust/hw/timer/Kconfig +++ b/rust/hw/timer/Kconfig @@ -1,2 +1,3 @@ config X_HPET_RUST bool + default y if PC && HAVE_RUST From patchwork Thu Feb 27 14:19:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994684 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D9DBC19F2E for ; Thu, 27 Feb 2025 14:33:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekL-0006yh-8K; Thu, 27 Feb 2025 09:20:17 -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 ) id 1tnekH-0006vG-NE for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekC-0003gY-41 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666007; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6S3+h0KILMZzEFjUXbmLqWGpqxuaheqFJv+xCK/jNY0=; b=ZAc5Ma+t7Y5kmVBcFi7AYeOjPkHmMtnv0dISxhjQYMWba7S+QxX2N6gkSjOyP+v24EFShS SkmSXfX76+Rx13aL6qC1zYjr8bQTylRM1bUXnlEVRVVjgl3+pViM/vpQA23OpQjWNCwDh7 snDxyTNRfton/q4njcNPaU09Ap8m1pY= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-15-eTkUseSzMl2VTEQWiQoP0Q-1; Thu, 27 Feb 2025 09:20:05 -0500 X-MC-Unique: eTkUseSzMl2VTEQWiQoP0Q-1 X-Mimecast-MFC-AGG-ID: eTkUseSzMl2VTEQWiQoP0Q_1740666004 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5de5172cc5bso918130a12.0 for ; Thu, 27 Feb 2025 06:20:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666004; x=1741270804; 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=6S3+h0KILMZzEFjUXbmLqWGpqxuaheqFJv+xCK/jNY0=; b=GkTQdWI+uhZNIf6BHBfRrW30fCY5XmvdbdeZvEEpF4I47v3dTV4o34ELZ03TUKSABZ oXb50jZI8aOUiH/POFAn+pT7Bz52dd6gj9l8xv+OkAmB7wF+MXTACG8/W5lQWydpqOGE XWJdtBSPmYGjHfWLfqd+Iq3e9N9MlXT+0nOZLHq6q4iEwSL88ueBKdEv2qh1y9haAtzo 5ELIMnx9D0eYjAS7vXDPNfaDCxdULoDFOA0KL59oofCKDn8guMgQGCzDvsE4t5fJNtuC V2JNM+uyN9aFSWwKpGh1YwaorAIfOCkOjQhRzChrvYdSuBWkfL3rWlc5zXrdXJfXXx+v 0o0A== X-Gm-Message-State: AOJu0YzBWsBqxic4oWUpWOO3agdraa7q3TPsej5me2JNKUffFgxOR3vr 3moNWxpg67WTVLWkMT2xbuy+/yJ4LonRMSmN3WHIIHt9nmhDDOxXxl8NFzp0FNe3Orw85+Jgrum 4ofJFlAx3bO8baSoWPC9pH1a3wP5gGuHJNQQPo6l+6W7aOV+YrkK+U1C0yGFz9ywPo9cR2jrAkQ 7QtumypnUMSI0xQk0JU8yxw1ZoHneBKIM1ec++/vc= X-Gm-Gg: ASbGncu6vRwUpvfqp8307xIAFQcM8Ik4/BODbOZ4Onbd0iDgP6oVpo6UoGq01iPfm82 /J71x9xjkhJ1zc6SxYJMYiYvLJwgPExdMIVom5aEYtOizFBysVQDJy3G8rfGNZPWKZV8WdwhJr0 7w03x/VJbdRpegYZr3h8gmbSEt/TpqIXdrBn8EWfNRQ7+ZyRwqdyuqkG68iBss8ypIeQJghsO9W 4QRc3u3ytk7NoEi/vGWUwoYce2J4HSyfS/sFoypJxClhRlYwYOh1htkmOQ04PQV/ywKHVZr4jrM Sh+K2hDH7BDDcMJ4HxKS X-Received: by 2002:a05:6402:35d3:b0:5dc:caab:9447 with SMTP id 4fb4d7f45d1cf-5e4469dd8eemr30508391a12.18.1740666003596; Thu, 27 Feb 2025 06:20:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqZlhQ7KbyYU/7FFHFZRg0Qb5nNfwuQTkzsuGR8q0ELLB/0jkLy8pDqW/yjIx7SX0BSD7zWA== X-Received: by 2002:a05:6402:35d3:b0:5dc:caab:9447 with SMTP id 4fb4d7f45d1cf-5e4469dd8eemr30508292a12.18.1740666002966; Thu, 27 Feb 2025 06:20:02 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c75d8ddsm127748866b.154.2025.02.27.06.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 04/34] rust: subprojects: add libc crate Date: Thu, 27 Feb 2025 15:19:22 +0100 Message-ID: <20250227141952.811410-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This allows access to errno values. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/Cargo.lock | 7 ++++ rust/qemu-api/Cargo.toml | 1 + scripts/archive-source.sh | 2 +- scripts/make-release | 2 +- subprojects/.gitignore | 1 + subprojects/libc-0.2-rs.wrap | 7 ++++ .../packagefiles/libc-0.2-rs/meson.build | 37 +++++++++++++++++++ 7 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 subprojects/libc-0.2-rs.wrap create mode 100644 subprojects/packagefiles/libc-0.2-rs/meson.build diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 79e142723b8..2ebf0a11ea4 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -54,6 +54,12 @@ dependencies = [ "either", ] +[[package]] +name = "libc" +version = "0.2.162" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" + [[package]] name = "pl011" version = "0.1.0" @@ -100,6 +106,7 @@ dependencies = [ name = "qemu_api" version = "0.1.0" dependencies = [ + "libc", "qemu_api_macros", "version_check", ] diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index a51dd142852..57747bc9341 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -16,6 +16,7 @@ rust-version = "1.63.0" [dependencies] qemu_api_macros = { path = "../qemu-api-macros" } +libc = "0.2.162" [build-dependencies] version_check = "~0.9" diff --git a/scripts/archive-source.sh b/scripts/archive-source.sh index 30677c3ec90..e461c1531ed 100755 --- a/scripts/archive-source.sh +++ b/scripts/archive-source.sh @@ -28,7 +28,7 @@ sub_file="${sub_tdir}/submodule.tar" # different to the host OS. subprojects="keycodemapdb libvfio-user berkeley-softfloat-3 berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs - bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs + bilge-impl-0.2-rs either-1-rs itertools-0.11-rs libc-0.2-rs proc-macro2-1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" sub_deinit="" diff --git a/scripts/make-release b/scripts/make-release index 1b89b3423a8..8c3594a1a47 100755 --- a/scripts/make-release +++ b/scripts/make-release @@ -41,7 +41,7 @@ fi # Only include wraps that are invoked with subproject() SUBPROJECTS="libvfio-user keycodemapdb berkeley-softfloat-3 berkeley-testfloat-3 arbitrary-int-1-rs bilge-0.2-rs - bilge-impl-0.2-rs either-1-rs itertools-0.11-rs proc-macro2-1-rs + bilge-impl-0.2-rs either-1-rs itertools-0.11-rs libc-0.2-rs proc-macro2-1-rs proc-macro-error-1-rs proc-macro-error-attr-1-rs quote-1-rs syn-2-rs unicode-ident-1-rs" diff --git a/subprojects/.gitignore b/subprojects/.gitignore index 50f173f90db..d12d34618cc 100644 --- a/subprojects/.gitignore +++ b/subprojects/.gitignore @@ -11,6 +11,7 @@ /bilge-impl-0.2.0 /either-1.12.0 /itertools-0.11.0 +/libc-0.2.162 /proc-macro-error-1.0.4 /proc-macro-error-attr-1.0.4 /proc-macro2-1.0.84 diff --git a/subprojects/libc-0.2-rs.wrap b/subprojects/libc-0.2-rs.wrap new file mode 100644 index 00000000000..bbe08f87883 --- /dev/null +++ b/subprojects/libc-0.2-rs.wrap @@ -0,0 +1,7 @@ +[wrap-file] +directory = libc-0.2.162 +source_url = https://crates.io/api/v1/crates/libc/0.2.162/download +source_filename = libc-0.2.162.tar.gz +source_hash = 18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398 +#method = cargo +patch_directory = libc-0.2-rs diff --git a/subprojects/packagefiles/libc-0.2-rs/meson.build b/subprojects/packagefiles/libc-0.2-rs/meson.build new file mode 100644 index 00000000000..ac4f80dba98 --- /dev/null +++ b/subprojects/packagefiles/libc-0.2-rs/meson.build @@ -0,0 +1,37 @@ +project('libc-0.2-rs', 'rust', + meson_version: '>=1.5.0', + version: '0.2.162', + license: 'MIT OR Apache-2.0', + default_options: []) + +_libc_rs = static_library( + 'libc', + files('src/lib.rs'), + gnu_symbol_visibility: 'hidden', + override_options: ['rust_std=2015', 'build.rust_std=2015'], + rust_abi: 'rust', + rust_args: [ + '--cap-lints', 'allow', + '--cfg', 'freebsd11', + '--cfg', 'libc_priv_mod_use', + '--cfg', 'libc_union', + '--cfg', 'libc_const_size_of', + '--cfg', 'libc_align', + '--cfg', 'libc_int128', + '--cfg', 'libc_core_cvoid', + '--cfg', 'libc_packedN', + '--cfg', 'libc_cfg_target_vendor', + '--cfg', 'libc_non_exhaustive', + '--cfg', 'libc_long_array', + '--cfg', 'libc_ptr_addr_of', + '--cfg', 'libc_underscore_const_names', + '--cfg', 'libc_const_extern_fn', + ], + dependencies: [], +) + +libc_dep = declare_dependency( + link_with: _libc_rs, +) + +meson.override_dependency('libc-0.2-rs', libc_dep) From patchwork Thu Feb 27 14:19:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D3D40C19F2E for ; Thu, 27 Feb 2025 14:23:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekN-00072U-LI; Thu, 27 Feb 2025 09:20:19 -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 ) id 1tnekL-0006zw-L8 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekH-0003hM-44 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666011; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IgSmPH6FgqvSH4TYQz2O4mHUPP3MFLvByAioX0qEPM8=; b=OC99gwsLNDikZvxAf+Me33erJefhrHUWdeJUmmWNlIGOUEzYOs6Amrtb7CxvA5Q/EraM3m BZE4gbIHbd4Erv0ca1GgSWGMcaSrybyH0IBSpqwPCrotb0V8ugrNGeerrc5GD9IjHJVsJU 4uySeDoKJ+HwF7s2TJ5xXSGAGObEHbA= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-KWst1sZCNHOAYWjZk4dOHA-1; Thu, 27 Feb 2025 09:20:09 -0500 X-MC-Unique: KWst1sZCNHOAYWjZk4dOHA-1 X-Mimecast-MFC-AGG-ID: KWst1sZCNHOAYWjZk4dOHA_1740666008 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-abec83a498cso114799766b.1 for ; Thu, 27 Feb 2025 06:20:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666008; x=1741270808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IgSmPH6FgqvSH4TYQz2O4mHUPP3MFLvByAioX0qEPM8=; b=nc8t9IXAi78/9HpuQePSKHnl1UrDhj4FzmZUcMjgRb9bYt7EJRAL/jYG+NLd/7pVY6 /Q2Hfq8Et59JtPB8mGsXpSUy32dYgKoCChtjwlwzVn83vQx0WhW8CxND9z76AmcBe9lb 6vTEV1MJq3BT+69RnA7clykHrPkGh3ad3UpNiN7wmROm2FezkxUmf56Rlz0zpfJHIu0t 8b84vgO+7KnKImNlT9hlkFVKbIIc2KsI2dO6fMXvkMbxx13GjQEZ+Na+yK/3OZtlB5eB bKGCiS7bf9qKOBQxfM/6i8RAtRTDkCdJx7KKNjeiygxq+gtFm9ZTTHUTeu2vUdPCfKr3 Ei+Q== X-Gm-Message-State: AOJu0Yy94u3IKalk8xg8TuhI27lYZZcQ61EdPP7gEaKEy3/W1dpuYIbK tfVmQtNUocFcUD2TuEan0gXnFzQQGNt7cOG571krny9Z77CqjPCJkcVd70kNME12+De1Y/pNAxo qE9fJuxNcZBA/BOZvghg1e6+dDQp7vQs6eeyN0IA7GOWq8IFpVErIAq8gJqUBpycyvHUmUH0xEg 5VmOlNFFAedn98o5xKcZ/vt1XZm/dIGx5fGd8DgdE= X-Gm-Gg: ASbGncvQJe7f40j4Ay3IL2v1WppBjf9ijMir1iFsc5d91LlBZ0KgOdkgDyINRLHbIA0 tXUjV+pqfW6ISTxAWLcPk0GWPqewJMY8uupEu97AZqUFYPBxFVXKgX6tQolIfR3gR3onysV10I+ NCXW5CmPqR5Q3s7EzMqXr9rb3yQlszBRlt2+7r4BtspcUUfz5xmNnQGMiP4SB7Wd72NN3y0S2Pb e7QImgU8taVYJIAc1MPaFhkxz2OKE6aCSO65XcFZb+eSy25DEH2SeApZC662Rmj6LVN1oXUH83z jvgeNhBaumT34yyrlXQW X-Received: by 2002:a17:906:30d4:b0:ab7:e3cb:ca81 with SMTP id a640c23a62f3a-abeeee9faefmr923226966b.30.1740666007725; Thu, 27 Feb 2025 06:20:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcCDr/N4Px4FtoGaEnyTtaRQBB/xMej5khIhJV7udVOcUnULpUvSw5kG9aAxlwxB/Y1I/VVQ== X-Received: by 2002:a17:906:30d4:b0:ab7:e3cb:ca81 with SMTP id a640c23a62f3a-abeeee9faefmr923222266b.30.1740666006991; Thu, 27 Feb 2025 06:20:06 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0b91dcsm129360166b.21.2025.02.27.06.20.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/34] rust: add module to convert between success/-errno and io::Result Date: Thu, 27 Feb 2025 15:19:23 +0100 Message-ID: <20250227141952.811410-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It is a common convention in QEMU to return a positive value in case of success, and a negated errno value in case of error. Unfortunately, using errno portably in Rust is a bit complicated; on Unix the errno values are supported natively by io::Error, but on Windows they are not; so, use the libc crate. This is a set of utility functions that are used by both chardev and block layer bindings. Signed-off-by: Paolo Bonzini --- docs/devel/rust.rst | 1 + rust/qemu-api/meson.build | 4 + rust/qemu-api/src/assertions.rs | 28 +++ rust/qemu-api/src/errno.rs | 345 ++++++++++++++++++++++++++++++++ rust/qemu-api/src/lib.rs | 1 + rust/qemu-api/src/prelude.rs | 2 + 6 files changed, 381 insertions(+) create mode 100644 rust/qemu-api/src/errno.rs diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index 90958e5a306..c75dccdbb7c 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -179,6 +179,7 @@ module status ``callbacks`` complete ``cell`` stable ``c_str`` complete +``errno`` complete ``irq`` complete ``memory`` stable ``module`` complete diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 2e9c1078b9b..bcf1cf780f3 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -2,6 +2,8 @@ _qemu_api_cfg = run_command(rustc_args, '--config-headers', config_host_h, '--features', files('Cargo.toml'), capture: true, check: true).stdout().strip().splitlines() +libc_dep = dependency('libc-0.2-rs') + # _qemu_api_cfg += ['--cfg', 'feature="allocator"'] if rustc.version().version_compare('>=1.77.0') _qemu_api_cfg += ['--cfg', 'has_offset_of'] @@ -22,6 +24,7 @@ _qemu_api_rs = static_library( 'src/cell.rs', 'src/chardev.rs', 'src/c_str.rs', + 'src/errno.rs', 'src/irq.rs', 'src/memory.rs', 'src/module.rs', @@ -39,6 +42,7 @@ _qemu_api_rs = static_library( override_options: ['rust_std=2021', 'build.rust_std=2021'], rust_abi: 'rust', rust_args: _qemu_api_cfg, + dependencies: libc_dep, ) rust.test('rust-qemu-api-tests', _qemu_api_rs, diff --git a/rust/qemu-api/src/assertions.rs b/rust/qemu-api/src/assertions.rs index fa1a18de6fe..104dec39774 100644 --- a/rust/qemu-api/src/assertions.rs +++ b/rust/qemu-api/src/assertions.rs @@ -92,3 +92,31 @@ fn types_must_be_equal(_: T) }; }; } + +/// Assert that an expression matches a pattern. This can also be +/// useful to compare enums that do not implement `Eq`. +/// +/// # Examples +/// +/// ``` +/// # use qemu_api::assert_match; +/// // JoinHandle does not implement `Eq`, therefore the result +/// // does not either. +/// let result: Result, u32> = Err(42); +/// assert_match!(result, Err(42)); +/// ``` +#[macro_export] +macro_rules! assert_match { + ($a:expr, $b:pat) => { + assert!( + match $a { + $b => true, + _ => false, + }, + "{} = {:?} does not match {}", + stringify!($a), + $a, + stringify!($b) + ); + }; +} diff --git a/rust/qemu-api/src/errno.rs b/rust/qemu-api/src/errno.rs new file mode 100644 index 00000000000..18d101448b9 --- /dev/null +++ b/rust/qemu-api/src/errno.rs @@ -0,0 +1,345 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +//! Utility functions to convert `errno` to and from +//! [`io::Error`]/[`io::Result`] +//! +//! QEMU C functions often have a "positive success/negative `errno`" calling +//! convention. This module provides functions to portably convert an integer +//! into an [`io::Result`] and back. + +use std::{convert::TryFrom, io, io::ErrorKind}; + +/// An `errno` value that can be converted into an [`io::Error`] +pub struct Errno(pub u16); + +// On Unix, from_raw_os_error takes an errno value and OS errors +// are printed using strerror. On Windows however it takes a +// GetLastError() value; therefore we need to convert errno values +// into io::Error by hand. This is the same mapping that the +// standard library uses to retrieve the kind of OS errors +// (`std::sys::pal::unix::decode_error_kind`). +impl From for ErrorKind { + fn from(value: Errno) -> ErrorKind { + use ErrorKind::*; + let Errno(errno) = value; + match i32::from(errno) { + libc::EPERM | libc::EACCES => PermissionDenied, + libc::ENOENT => NotFound, + libc::EINTR => Interrupted, + x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => WouldBlock, + libc::ENOMEM => OutOfMemory, + libc::EEXIST => AlreadyExists, + libc::EINVAL => InvalidInput, + libc::EPIPE => BrokenPipe, + libc::EADDRINUSE => AddrInUse, + libc::EADDRNOTAVAIL => AddrNotAvailable, + libc::ECONNABORTED => ConnectionAborted, + libc::ECONNREFUSED => ConnectionRefused, + libc::ECONNRESET => ConnectionReset, + libc::ENOTCONN => NotConnected, + libc::ENOTSUP => Unsupported, + libc::ETIMEDOUT => TimedOut, + _ => Other, + } + } +} + +// This is used on Windows for all io::Errors, but also on Unix if the +// io::Error does not have a raw OS error. This is the reversed +// mapping of the above; EIO is returned for unknown ErrorKinds. +impl From for Errno { + fn from(value: io::ErrorKind) -> Errno { + use ErrorKind::*; + let errno = match value { + // can be both EPERM or EACCES :( pick one + PermissionDenied => libc::EPERM, + NotFound => libc::ENOENT, + Interrupted => libc::EINTR, + WouldBlock => libc::EAGAIN, + OutOfMemory => libc::ENOMEM, + AlreadyExists => libc::EEXIST, + InvalidInput => libc::EINVAL, + BrokenPipe => libc::EPIPE, + AddrInUse => libc::EADDRINUSE, + AddrNotAvailable => libc::EADDRNOTAVAIL, + ConnectionAborted => libc::ECONNABORTED, + ConnectionRefused => libc::ECONNREFUSED, + ConnectionReset => libc::ECONNRESET, + NotConnected => libc::ENOTCONN, + Unsupported => libc::ENOTSUP, + TimedOut => libc::ETIMEDOUT, + _ => libc::EIO, + }; + Errno(errno as u16) + } +} + +impl From for io::Error { + #[cfg(unix)] + fn from(value: Errno) -> io::Error { + let Errno(errno) = value; + io::Error::from_raw_os_error(errno.into()) + } + + #[cfg(windows)] + fn from(value: Errno) -> io::Error { + let error_kind: ErrorKind = value.into(); + error_kind.into() + } +} + +impl From for Errno { + fn from(value: io::Error) -> Errno { + if cfg!(unix) { + if let Some(errno) = value.raw_os_error() { + return Errno(u16::try_from(errno).unwrap()); + } + } + value.kind().into() + } +} + +/// Internal traits; used to enable [`into_io_result`] and [`into_neg_errno`] +/// for the "right" set of types. +mod traits { + use super::Errno; + + /// A signed type that can be converted into an + /// [`io::Result`](std::io::Result) + pub trait GetErrno { + /// Unsigned variant of `Self`, used as the type for the `Ok` case. + type Out; + + /// Return `Ok(self)` if positive, `Err(Errno(-self))` if negative + fn into_errno_result(self) -> Result; + } + + /// A type that can be taken out of an [`io::Result`](std::io::Result) and + /// converted into "positive success/negative `errno`" convention. + pub trait MergeErrno { + /// Signed variant of `Self`, used as the return type of + /// [`into_neg_errno`](super::into_neg_errno). + type Out: From + std::ops::Neg; + + /// Return `self`, asserting that it is in range + fn map_ok(self) -> Self::Out; + } + + macro_rules! get_errno { + ($t:ty, $out:ty) => { + impl GetErrno for $t { + type Out = $out; + fn into_errno_result(self) -> Result { + match self { + 0.. => Ok(self as $out), + -65535..=-1 => Err(Errno(-self as u16)), + _ => panic!("{self} is not a negative errno"), + } + } + } + }; + } + + get_errno!(i32, u32); + get_errno!(i64, u64); + get_errno!(isize, usize); + + macro_rules! merge_errno { + ($t:ty, $out:ty) => { + impl MergeErrno for $t { + type Out = $out; + fn map_ok(self) -> Self::Out { + self.try_into().unwrap() + } + } + }; + } + + merge_errno!(u8, i32); + merge_errno!(u16, i32); + merge_errno!(u32, i32); + merge_errno!(u64, i64); + + impl MergeErrno for () { + type Out = i32; + fn map_ok(self) -> i32 { + 0 + } + } +} + +use traits::{GetErrno, MergeErrno}; + +/// Convert an integer value into a [`io::Result`]. +/// +/// Positive values are turned into an `Ok` result; negative values +/// are interpreted as negated `errno` and turned into an `Err`. +/// +/// ``` +/// # use qemu_api::errno::into_io_result; +/// # use std::io::ErrorKind; +/// let ok = into_io_result(1i32).unwrap(); +/// assert_eq!(ok, 1u32); +/// +/// let err = into_io_result(-1i32).unwrap_err(); // -EPERM +/// assert_eq!(err.kind(), ErrorKind::PermissionDenied); +/// ``` +/// +/// # Panics +/// +/// Since the result is an unsigned integer, negative values must +/// be close to 0; values that are too far away are considered +/// likely overflows and will panic: +/// +/// ```should_panic +/// # use qemu_api::errno::into_io_result; +/// # #[allow(dead_code)] +/// let err = into_io_result(-0x1234_5678i32); // panic +/// ``` +pub fn into_io_result(value: T) -> io::Result { + value.into_errno_result().map_err(Into::into) +} + +/// Convert a [`Result`] into an integer value, using negative `errno` +/// values to report errors. +/// +/// ``` +/// # use qemu_api::errno::into_neg_errno; +/// # use std::io::{self, ErrorKind}; +/// let ok: io::Result<()> = Ok(()); +/// assert_eq!(into_neg_errno(ok), 0); +/// +/// let err: io::Result<()> = Err(ErrorKind::InvalidInput.into()); +/// assert_eq!(into_neg_errno(err), -22); // -EINVAL +/// ``` +/// +/// Since this module also provides the ability to convert [`io::Error`] +/// to an `errno` value, [`io::Result`] is the most commonly used type +/// for the argument of this function: +/// +/// # Panics +/// +/// Since the result is a signed integer, integer `Ok` values must remain +/// positive: +/// +/// ```should_panic +/// # use qemu_api::errno::into_neg_errno; +/// # use std::io; +/// let err: io::Result = Ok(0x8899_AABB); +/// into_neg_errno(err) // panic +/// # ; +/// ``` +pub fn into_neg_errno>(value: Result) -> T::Out { + match value { + Ok(x) => x.map_ok(), + Err(err) => -T::Out::from(err.into().0), + } +} + +#[cfg(test)] +mod tests { + use std::io::ErrorKind; + + use super::*; + use crate::assert_match; + + #[test] + pub fn test_from_u8() { + let ok: io::Result<_> = Ok(42u8); + assert_eq!(into_neg_errno(ok), 42); + + let err: io::Result = Err(io::ErrorKind::PermissionDenied.into()); + assert_eq!(into_neg_errno(err), -1); + + if cfg!(unix) { + let os_err: io::Result = Err(io::Error::from_raw_os_error(10)); + assert_eq!(into_neg_errno(os_err), -10); + } + } + + #[test] + pub fn test_from_u16() { + let ok: io::Result<_> = Ok(1234u16); + assert_eq!(into_neg_errno(ok), 1234); + + let err: io::Result = Err(io::ErrorKind::PermissionDenied.into()); + assert_eq!(into_neg_errno(err), -1); + + if cfg!(unix) { + let os_err: io::Result = Err(io::Error::from_raw_os_error(10)); + assert_eq!(into_neg_errno(os_err), -10); + } + } + + #[test] + pub fn test_i32() { + assert_match!(into_io_result(1234i32), Ok(1234)); + + let err = into_io_result(-1i32).unwrap_err(); + #[cfg(unix)] + assert_match!(err.raw_os_error(), Some(1)); + assert_match!(err.kind(), ErrorKind::PermissionDenied); + } + + #[test] + pub fn test_from_u32() { + let ok: io::Result<_> = Ok(1234u32); + assert_eq!(into_neg_errno(ok), 1234); + + let err: io::Result = Err(io::ErrorKind::PermissionDenied.into()); + assert_eq!(into_neg_errno(err), -1); + + if cfg!(unix) { + let os_err: io::Result = Err(io::Error::from_raw_os_error(10)); + assert_eq!(into_neg_errno(os_err), -10); + } + } + + #[test] + pub fn test_i64() { + assert_match!(into_io_result(1234i64), Ok(1234)); + + let err = into_io_result(-22i64).unwrap_err(); + #[cfg(unix)] + assert_match!(err.raw_os_error(), Some(22)); + assert_match!(err.kind(), ErrorKind::InvalidInput); + } + + #[test] + pub fn test_from_u64() { + let ok: io::Result<_> = Ok(1234u64); + assert_eq!(into_neg_errno(ok), 1234); + + let err: io::Result = Err(io::ErrorKind::InvalidInput.into()); + assert_eq!(into_neg_errno(err), -22); + + if cfg!(unix) { + let os_err: io::Result = Err(io::Error::from_raw_os_error(6)); + assert_eq!(into_neg_errno(os_err), -6); + } + } + + #[test] + pub fn test_isize() { + assert_match!(into_io_result(1234isize), Ok(1234)); + + let err = into_io_result(-4isize).unwrap_err(); + #[cfg(unix)] + assert_match!(err.raw_os_error(), Some(4)); + assert_match!(err.kind(), ErrorKind::Interrupted); + } + + #[test] + pub fn test_from_unit() { + let ok: io::Result<_> = Ok(()); + assert_eq!(into_neg_errno(ok), 0); + + let err: io::Result<()> = Err(io::ErrorKind::OutOfMemory.into()); + assert_eq!(into_neg_errno(err), -12); + + if cfg!(unix) { + let os_err: io::Result<()> = Err(io::Error::from_raw_os_error(2)); + assert_eq!(into_neg_errno(os_err), -2); + } + } +} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index ed1a8f9a2b4..05f38b51d30 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -19,6 +19,7 @@ pub mod callbacks; pub mod cell; pub mod chardev; +pub mod errno; pub mod irq; pub mod memory; pub mod module; diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs index fbf0ee23e0b..634acf37a85 100644 --- a/rust/qemu-api/src/prelude.rs +++ b/rust/qemu-api/src/prelude.rs @@ -9,6 +9,8 @@ pub use crate::cell::BqlCell; pub use crate::cell::BqlRefCell; +pub use crate::errno; + pub use crate::qdev::DeviceMethods; pub use crate::qom::InterfaceType; From patchwork Thu Feb 27 14:19:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994618 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C0867C1B0FF for ; Thu, 27 Feb 2025 14:20:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekP-000735-Hc; Thu, 27 Feb 2025 09:20:22 -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 ) id 1tnekK-0006ya-UU for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekH-0003hW-SD for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jtNzr8uYuWTsnD/A8rhDCCpOJ/XgomM+/PA3Y3Q8jKo=; b=JgO3DgRpxNo5V0ebeXinozC/Z+J7Dx+mSdAuKT8TfdYBEiaXodXBgZhoULOdRr2ImgDrYd jHNPZGD4GLeX5R59jEKU4OMz2CK0/qWIc6EHUn/e3mLSr9w8aLTISI29h1BoBg1gORMrgI sbqYHgnikP6MyxC0kCKE6eGxKvtunac= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-425-wmXwe4eWMwq9AtxxpKWsdg-1; Thu, 27 Feb 2025 09:20:10 -0500 X-MC-Unique: wmXwe4eWMwq9AtxxpKWsdg-1 X-Mimecast-MFC-AGG-ID: wmXwe4eWMwq9AtxxpKWsdg_1740666009 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-ab68fbe53a4so151877666b.2 for ; Thu, 27 Feb 2025 06:20:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666008; x=1741270808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jtNzr8uYuWTsnD/A8rhDCCpOJ/XgomM+/PA3Y3Q8jKo=; b=SX1QOI/XBUiO39tofkVtVJaRZXbzDrWuzo65iMeaPbOXQBxm282WmjAp74yV1usCzK ro+DN4lIM2bW3YDxADyGzf1tk2XHFA9MkPZyOXOzFNzgbw2lJsIFjWprQEbCI4MYKWyD oIi2se4LmM5YWzNlH6AOLN6mknLo4HqN5XrSUG/zjaKUx+5ccWw1MDYLBTINDX4OqIL6 TUHpDY+NLgI5/2zfCEH7TvyoityuK5IUloD3ONHrk1i9LJr9LkKWloX+XiJfVyrJlWLI I1JLz7KEEeDsEmRhIl4tON+iHyNZ0lE01BfnBmZtmK4dOyEWsypUgZdORABE3ud0Cf5/ 4Jkw== X-Gm-Message-State: AOJu0YzRP/aQsbTGm6juE1e7TH31SdAhz2fnnSQ2yu6dx97gHzfvxUC+ ZlDybhyLQM8QsXMgll9G0gTjy9F26G6UjTAgCjLd0E4Vqa/h2p/Fi9KtPutNQsyyH0Vq64bqyIf bjm1Nh6/eHk0FBZSBlzVLbUF10dyizyusl2QKvdW2nCQTECooqtOvKnBAAWHD3Pry4fgF5GlsBt LMxJkhMgIKMJX/CIFHDKDvIbrGPglCg47Sq7XLzOI= X-Gm-Gg: ASbGncsk2lu3vLEUeE6lSTPd2sgH+AuYleSdsBdtrkFyvdcPJHh4ZmzraCBDhM4VQoJ 19wk0RSw/ZQ+dyxHKkgLqCf0Fo57z/YFP2OdKWyuLShGslQ5vwemVx3zmqc7djmvB/P2u6Hzqm1 d7idR9VQwu8hZoyEadMVfTp9frkW+4YjEC18kKLG934lC5101E9PfU8SY6JazjELjhDuYw6cnMw eGf0lSrT96PdH9bIVNHZDXn2obwDK5lSr788fikSywm8ykYs/uZkO4hWItyRmYDBO15xYIyiOt8 yDOecIRL+D9fKjffBFxo X-Received: by 2002:a17:907:96a1:b0:aa6:8d51:8fdb with SMTP id a640c23a62f3a-abed0ce9953mr1269801466b.19.1740666008604; Thu, 27 Feb 2025 06:20:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPEeMfrnDw4VgOT3FXH1Rjs0vLsCS7hIAjBNG2UWO4gshvoAkn/3UmynDGL+MSsArUqsIQZg== X-Received: by 2002:a17:907:96a1:b0:aa6:8d51:8fdb with SMTP id a640c23a62f3a-abed0ce9953mr1269799266b.19.1740666008132; Thu, 27 Feb 2025 06:20:08 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c7c18a3sm127464566b.185.2025.02.27.06.20.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 06/34] rust: tests: do not import bindings::* Date: Thu, 27 Feb 2025 15:19:24 +0100 Message-ID: <20250227141952.811410-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Similar to the devices, spell the exact set of C functions that are called directly. Signed-off-by: Paolo Bonzini --- rust/qemu-api/tests/tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 92dbfb8a0c8..03569e4a44c 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -8,13 +8,14 @@ }; use qemu_api::{ - bindings::*, + bindings::{module_call_init, module_init_type, object_new, object_unref, qdev_prop_bool}, c_str, cell::{self, BqlCell}, declare_properties, define_property, prelude::*, qdev::{DeviceClass, DeviceImpl, DeviceState, Property, ResettablePhasesImpl}, qom::{ClassInitImpl, ObjectImpl, ParentField}, + sysbus::SysBusDevice, vmstate::VMStateDescription, zeroable::Zeroable, }; From patchwork Thu Feb 27 14:19:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D3397C1B0FF for ; Thu, 27 Feb 2025 14:21:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekN-00072V-Ti; Thu, 27 Feb 2025 09:20:19 -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 ) id 1tnekM-00071V-CA for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekI-0003i2-T6 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PjtxIkwdleYjC4DCWP1LEl8y9JNwMGZvc6X0QJOda88=; b=OsfnlrOdWGJwmmAVZ2hACCm4tJ5ZYJi1aZ4yfvaOE2HCXl0Ag3xbiq0wZ218i0GLeXFnih H45UVTrBDviiXNurGhsTmYXDhVHBeeW2Li/yihJfbbqlXbdG8AWYlc95BEz5fUuXocP7rY 6i6Sl8N/PekM1YV4H/7VxVPcMy65Q58= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-224-OxMmEe7VOVuHqIUO00AoAA-1; Thu, 27 Feb 2025 09:20:12 -0500 X-MC-Unique: OxMmEe7VOVuHqIUO00AoAA-1 X-Mimecast-MFC-AGG-ID: OxMmEe7VOVuHqIUO00AoAA_1740666012 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5de5172cc5bso918251a12.0 for ; Thu, 27 Feb 2025 06:20:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666011; x=1741270811; 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=PjtxIkwdleYjC4DCWP1LEl8y9JNwMGZvc6X0QJOda88=; b=OtD1VMGwu1hW1CR5MdaGM3ULPPunq2Ze9l7c5xBirlQuu5ExpQt6v74JgcYbtbOtKt AR3zCoQL1PpbSSlEdPseHzNH4gkgZyqbjHV6m+CCOnFA05TdnvTzAYXJXgmM7SL47hpG vzSUB3HwsJmBZcbDclfiHnImd2/4+GnfOreRZKJE0VV/gejzqYQbCsjkuIWmc6vBk7JC LPx1YXNUTzmCIoonU1TSS9BUGZZ6AdN96TfH5xR78RnHDrNTg/WvdwGjaFkOuiI2IaYK f29C0xyEArlqAv0gX/h5UYYx4IFO6LJWdbQqLozf/moIE+SneQsftRTfJ2DnrEUpoUvY wPnQ== X-Gm-Message-State: AOJu0Yxk+evKC3Z5bwWyqTBhxKUNAhcsccqYpMleKW69BreAkP+slPnH QiJ1jfVceg2MMVEwfmcULEazBmvIkomBK72o+kuGfBh4Axa3swFQqiwlKAtkcUzotkmRpuXB3qU I+xloTJY/8378VFELqWOvhES+JAbQlWT3MnzB50j5mR80siIDaKelhTOMv0SJOtwNypz3dEX2En aqyGHEt7uArpCvg1Ka74sQZVG6+wdUwlFkSNuM5x0= X-Gm-Gg: ASbGncu9OS3LKZ0Y4H88BqviwGicoObCFJhAqnl7pkEaWuZdBby1Ud/zHY6TTw8wytA RuqqsuX6XC0zeUQEflLLBGgHVn1N6IEBJCbWLIKNgibSG+ZGEPyqGwkz8Fo1a96ulPrFmMRkfmu /kZcJTY03utV0K2FtJltMQXB8VxYaV49zrhh3CyEYj/ee+Jw4X8fJ+yBxeqw4PPHIyQuQd7HHVh 2u938DhI9mhSgLh+lQydQlx2VC0EmGwRPedwLuE17bxik4k02uXhfhuwuHK6EbLFfZk39UMsPGL 6rv7hmXg7VtFhiURBxzk X-Received: by 2002:a05:6402:550c:b0:5de:4a8b:4c9c with SMTP id 4fb4d7f45d1cf-5e44bb36bbcmr28548676a12.32.1740666010850; Thu, 27 Feb 2025 06:20:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWomp/c2XCxOHLPzV0g4wWqhMU7pq5Hz6kGeGHOZZ0M6++7mL0JarG9dPdFeUTR5roKKafcA== X-Received: by 2002:a05:6402:550c:b0:5de:4a8b:4c9c with SMTP id 4fb4d7f45d1cf-5e44bb36bbcmr28548589a12.32.1740666010217; Thu, 27 Feb 2025 06:20:10 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c3b6df84sm1143247a12.30.2025.02.27.06.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:08 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 07/34] rust: prefer importing std::ptr over core::ptr Date: Thu, 27 Feb 2025 15:19:25 +0100 Message-ID: <20250227141952.811410-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Zhao Liu The std::ptr is same as core::ptr, but std has already been used in many cases and there's no need to choose non-std library. So, use std::ptr directly to make the used ptr library as consistent as possible. Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250218080835.3341082-1-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 2 +- rust/hw/char/pl011/src/device_class.rs | 6 ++++-- rust/qemu-api/src/irq.rs | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index fe73771021e..59a689fdcd7 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -2,10 +2,10 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use core::ptr::{addr_of, addr_of_mut, NonNull}; use std::{ ffi::CStr, os::raw::{c_int, c_void}, + ptr::{addr_of, addr_of_mut, NonNull}, }; use qemu_api::{ diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index dbef93f6cb3..0b2076ddaa0 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -2,8 +2,10 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use core::ptr::NonNull; -use std::os::raw::{c_int, c_void}; +use std::{ + os::raw::{c_int, c_void}, + ptr::NonNull, +}; use qemu_api::{ bindings::*, c_str, prelude::*, vmstate_clock, vmstate_fields, vmstate_of, vmstate_struct, diff --git a/rust/qemu-api/src/irq.rs b/rust/qemu-api/src/irq.rs index d1c9dc96eff..34c19263c23 100644 --- a/rust/qemu-api/src/irq.rs +++ b/rust/qemu-api/src/irq.rs @@ -4,8 +4,7 @@ //! Bindings for interrupt sources -use core::ptr; -use std::{ffi::CStr, marker::PhantomData, os::raw::c_int}; +use std::{ffi::CStr, marker::PhantomData, os::raw::c_int, ptr}; use crate::{ bindings::{self, qemu_set_irq}, From patchwork Thu Feb 27 14:19:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994658 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63062C19F32 for ; Thu, 27 Feb 2025 14:27:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekR-00074E-CC; Thu, 27 Feb 2025 09:20:23 -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 ) id 1tnekN-00072h-P2 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekK-0003iN-AO for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666015; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rffOM0f5uVVtqcpBSP7+vcNn2V5K/QuALkN5DWmU1mM=; b=V3wvxd11JJynKhtd/RziZ4jlYjazhfWcigGc+hgiZUP3DSrwjLtoNP+a3Kpdc24I1D2zYH nl+7LFUejMJWOmVzlF6D4G0sZBKwaqm0astkTyhF2zj7JIK1k1x2cyN0A+2Nsk/96QHyNB BRElI58YcZwFrWZdUFm89EPldDUt2J4= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-bwRcAuttOv2TxXdHS50Sbw-1; Thu, 27 Feb 2025 09:20:14 -0500 X-MC-Unique: bwRcAuttOv2TxXdHS50Sbw-1 X-Mimecast-MFC-AGG-ID: bwRcAuttOv2TxXdHS50Sbw_1740666013 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5e082a05744so1106825a12.2 for ; Thu, 27 Feb 2025 06:20:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666012; x=1741270812; 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=rffOM0f5uVVtqcpBSP7+vcNn2V5K/QuALkN5DWmU1mM=; b=o9zuiFYwlcBvMRwLqKU4RUZOpysClXBKHcbE/0e0RftW65M7xBr7OptcgI28cbLhLS OVstDmYO8kl3XIGS409l/veFpTxP6qU2AVZ9oY3hVAzdnQ0SK0q1H99JrCixyVZVZOSz sO4LLwOb9nTeaAyfwogF7lBCFAkp1N759DvVCtkH7/nfzkd6zAtn1TkXCR5YkPof1OJw R85Amjf3gx7M8oNuZM3DohXABp4WhwztJhsbhioX7SXz0L9nh5ux7IeD+Fwg550mqR8D 5XGzA3729XT0jtIu9YoGKJzWyYiWDphu5epQlJcyyGIWmw1GdR/f9FEr2eHqbn2SxDWx RiRQ== X-Gm-Message-State: AOJu0Yyml/YhCV16AOb3bR/kalKW3SDb9RsZGWi8mCkMO+8oPG05A1cX Jem2GwEDBngyoUfqMyEg3IQlqCjxEIkyNo5nXFtjcGTgN1kYZJNCfyHe5JutQWmLwC2JfXqtPtY cQKGpogUo+gHmOLoq2ePQU/ItJPtKu2XOMbijcn9wN5zg1iS/vPgjjC9ChoWFWtJ4cKfY0g46Vm 2mBcXUySYk6r16U4s5EvmDQWcKZJz2UUhJWhuMR9g= X-Gm-Gg: ASbGncvaRutVM9L0awmoq67I7e4/Z/l83htNWEEEtWMrohJX/OpsCFl466LFFGkDMcG ffO1S/BXsHB98EDJ3WFOTsB3yom8eMRs+0UjNreKpvQHBvXwGESHPZ2wT8LrBSIJFo7KlZtLteu KZv+sH7ZJ7yqwVs+d3eWC2XQulLl4OSlPj6dcinR8JIjkkAVWrCfSQa+m8VrQlMrEV99jiiagoQ gtIAoL19OivkKoHiPAZmxAUBcHaXA1zn6IpY5CG7M3/7U4pk6j6EP60ZzGF8lm7KcLKO0ieHzzl MFPQP0tZx84SgcFhT/GA X-Received: by 2002:a05:6402:a001:b0:5e4:a0c4:1db7 with SMTP id 4fb4d7f45d1cf-5e4a0c41eadmr7442309a12.13.1740666011884; Thu, 27 Feb 2025 06:20:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8bZf1qckRKdvlgFMb0JPie2kjFkOllhql9a2DyL3Zbr2Cpwq9f7HU2qxJuzxbhtkv1UKFGQ== X-Received: by 2002:a05:6402:a001:b0:5e4:a0c4:1db7 with SMTP id 4fb4d7f45d1cf-5e4a0c41eadmr7442290a12.13.1740666011514; Thu, 27 Feb 2025 06:20:11 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c3b70112sm1145715a12.31.2025.02.27.06.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 08/34] docs: rust: fix typos Date: Thu, 27 Feb 2025 15:19:26 +0100 Message-ID: <20250227141952.811410-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- docs/devel/rust.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index c75dccdbb7c..d68701c9c87 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -294,7 +294,7 @@ to a Rust mutable reference, and use a shared reference instead. Rust code will then have to use QEMU's ``BqlRefCell`` and ``BqlCell`` type, which enforce that locking rules for the "Big QEMU Lock" are respected. These cell types are also known to the ``vmstate`` crate, which is able to "look inside" -them when building an in-memory representation of a ``struct``s layout. +them when building an in-memory representation of a ``struct``'s layout. Note that the same is not true of a ``RefCell`` or ``Mutex``. In the future, similar cell types might also be provided for ``AioContext``-based @@ -350,7 +350,7 @@ Writing procedural macros ''''''''''''''''''''''''' By conventions, procedural macros are split in two functions, one -returning ``Result` with the body of +returning ``Result`` with the body of the procedural macro, and the second returning ``proc_macro::TokenStream`` which is the actual procedural macro. The former's name is the same as the latter with the ``_or_error`` suffix. The code for the latter is more From patchwork Thu Feb 27 14:19:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994622 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4A7EC19F2E for ; Thu, 27 Feb 2025 14:21:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekU-00075j-1H; Thu, 27 Feb 2025 09:20: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 ) id 1tnekP-00073F-IS for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekN-0003jD-Ee for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TIrGFvl8XMnSDNAnwzqUPVz8YQqpnZQKu+akhrL+9gc=; b=g+57ciItA7Lf+3gucuPYLnUT95VaiV81NtrVO/5oXtMOKs2/vIJUj7cJZd1ZwKcXk7mkwv AVuSVpDt3+yv+tar3oguZLwbwhEmPrrCfCkLIjM9rGjdpJPlD92nlhICpsradDSmMu5n9T F+TJPlqBmyWvGS7Sw8VCenQcAv1fXhw= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-AI6gzLkaP8yPBGnA7efScg-1; Thu, 27 Feb 2025 09:20:16 -0500 X-MC-Unique: AI6gzLkaP8yPBGnA7efScg-1 X-Mimecast-MFC-AGG-ID: AI6gzLkaP8yPBGnA7efScg_1740666015 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-abbe5ac36a9so116393866b.2 for ; Thu, 27 Feb 2025 06:20:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666015; x=1741270815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TIrGFvl8XMnSDNAnwzqUPVz8YQqpnZQKu+akhrL+9gc=; b=PMOHcx6Hqz8/MRgmDmB56elnpMBjtxlehOk/NdB2E6ZwaQyb3O+327AlJ8DCwoWZ2n LTlP14h4c0QPY9Dm1a8ekTCH0+aANfQKJI3uFPgv+xOUIMB7LYXemo20G9S4pfdBdLSW a1zhY9+oAhbatMrvT43XYaAGk7g3PhMySWxeT0OzaKKTvkuBbuNgeBG8rHfYa1WPh3+P zQQsyg+8owOLAC21rHNuO9GL/9CmqkO62Utpn81Oyhju2g/kjHa4vJkilHxn5zb/6/yu 7ZOHPlBm14iroRO+TVU7dqlS/Fcgz1JrnNKsYIgnlDbck1BbbfbOPRgki56ZULo2cnf0 Hpwg== X-Gm-Message-State: AOJu0YwxdaMmJRaabDPl/v5CibjgnuD2dBnvihtJSqKS73z3Ly8oZe7v sWxKq1OTfy37OZzb8mAOZf5Jl0zqnu1Z7VVcplpS72NRjhmkoOAI+h7XZN0wf42udywEAILo1gf zTl/3SmsUOY+2eRtr4yJ/RISmARCNYSefFm0zwZM4kz83K2p8M+4JSDBYx4QA53admSG1uUWieJ CwkBF01Ura77d7P11sW4V/Fj0XkY0b+dT0pFP+doY= X-Gm-Gg: ASbGnctZq5cEmLWsghkYvdsRZ6iY/G7sZNBU4gYWjtme3lNy0+6heD4iziHlszQaDub MzXu3KtDC5wbETC1FXNB6M18eF3cFMtccIU4hYf/Amh1/whZikuwtiajoF6OT1WAIMl0IXiRJQf ZKNtQtmZ2A4lrpd3y5Y8reGwjD9zN1XYllK0VZShgsDCFgYsiE2WvNulWkdISVmQE1J5qLeOZkW JygN2rKbvbWGGHdejucyAQo1WBmeEDJ+POFZ371QQ5vO1iZI8z8aMjfbLUOGuO2YTdcEBJuoRqG b0OO2KzaNsVKLhpehat+ X-Received: by 2002:a17:906:309a:b0:ab7:4641:a72d with SMTP id a640c23a62f3a-abc0de4fb0cmr2488339266b.51.1740666014727; Thu, 27 Feb 2025 06:20:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGowif1EE8SoFEH8XN4ShMl+uizlle4Eeii03++zVweXfeDYmMob3hKp9e5Ee+vgo0OsUQAmg== X-Received: by 2002:a17:906:309a:b0:ab7:4641:a72d with SMTP id a640c23a62f3a-abc0de4fb0cmr2488334866b.51.1740666014241; Thu, 27 Feb 2025 06:20:14 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c759385sm128256566b.150.2025.02.27.06.20.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:12 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 09/34] docs: rust: update description of crates Date: Thu, 27 Feb 2025 15:19:27 +0100 Message-ID: <20250227141952.811410-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Paolo Bonzini --- docs/devel/rust.rst | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index d68701c9c87..5d8aa3a45bc 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -139,16 +139,22 @@ anymore. Writing Rust code in QEMU ------------------------- -Right now QEMU includes three crates: +QEMU includes four crates: * ``qemu_api`` for bindings to C code and useful functionality * ``qemu_api_macros`` defines several procedural macros that are useful when writing C code -* ``pl011`` (under ``rust/hw/char/pl011``) is the sample device that is being - used to further develop ``qemu_api`` and ``qemu_api_macros``. It is a functional - replacement for the ``hw/char/pl011.c`` file. +* ``pl011`` (under ``rust/hw/char/pl011``) and ``hpet`` (under ``rust/hw/timer/hpet``) + are sample devices that demonstrate ``qemu_api`` and ``qemu_api_macros``, and are + used to further develop them. These two crates are functional\ [#issues]_ replacements + for the ``hw/char/pl011.c`` and ``hw/timer/hpet.c`` files. + +.. [#issues] The ``pl011`` crate is synchronized with ``hw/char/pl011.c`` + as of commit 02b1f7f61928. The ``hpet`` crate is synchronized as of + commit f32352ff9e. Both are lacking tracing functionality; ``hpet`` + is also lacking support for migration. This section explains how to work with them. From patchwork Thu Feb 27 14:19:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CA9E2C19F2E for ; Thu, 27 Feb 2025 14:28:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekX-0007Bu-Ld; Thu, 27 Feb 2025 09:20: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 ) id 1tnekR-00074F-7C for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekO-0003jW-HP for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RntUDexksFwvMT7+4/zwxw40OZKETlpI3GYu/coQJlI=; b=DKPZupDbVCJVuo4t4ciXx8TIdgm2AYf+DOAqBxPHbmAsatkcabeEe12MJGf5h3eVqJPRVl eDXoom/B1za5Ty5A0GLQtdv8vYYQfLzmvCrLYXMLKzHnI5AQ5ezcEdl4LePyYgteYx2WGM MORdi5/nFE6KFJFcNcm/hThVom833s4= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-kwogPHaZNdSr2sPjRa_Qfg-1; Thu, 27 Feb 2025 09:20:18 -0500 X-MC-Unique: kwogPHaZNdSr2sPjRa_Qfg-1 X-Mimecast-MFC-AGG-ID: kwogPHaZNdSr2sPjRa_Qfg_1740666017 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5e0573b9f60so1028416a12.3 for ; Thu, 27 Feb 2025 06:20:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666016; x=1741270816; 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=RntUDexksFwvMT7+4/zwxw40OZKETlpI3GYu/coQJlI=; b=izjvTM0IEohcm2LbQDeDgyi5FHHFSxhUTYiCEdoTCBqjYm2I71H8qQpGfMyaDltekh jP0jn0VtZ+5pXQDThiNY+GYoDX9cOlI5USd8vrNtuJy103+7RiPpJ/R3MGLDEwYp9g3C 8m1hudRzyXl0HcEy9U0KcbPMupO+WegDgbaUhW93vJqlsG/DjufAuwPjmkZR/gKIJdpj HQ4U40uA+0cOh1rr8V65VsRygM/5vxphStDPTrla5n1EZRBL1bVCSOUfWDHKWKXRxGa4 o14a7CRDhGbXLUCUAIp2P6qz5VifMTrnktrd2gOkI6NxH3H21D0nLQ4mWCgBVtLlytxP ApgA== X-Gm-Message-State: AOJu0Yz5ExW5yByvzJzMBRWEkEF1lFRFqmeH2tzf9BxfmCaZITEOD+d/ GRB896lAYVSpP9gVmAPPXgVJIVy7CvawvGYKxsHZ1+QFX8YrMsYBgsSOUyjbnUwhAXBp3it0+hV X/HdqhslyflN9CV2qFxoZV8r54oDanTQmQZCXRax+J/kHNoH7uZuZIcRS2B7ThG+sXdl1qHd5B5 gi4whLqxR2lso8kkbFY6+2yIytuvT77fGjdNnCwsc= X-Gm-Gg: ASbGnct3UjmhmplRE5LY5vjENP5Hup39z53f6rorO1Tdq8mPA4wrxx29nuuhzyXXqG0 6qA/iKvGf+9oMErPqFDesPK1ThIsm0GIPl9Y1eFjUDVQ3yYQVweTXPhLm2IGTzIT/jak03j0fyN gr8iYLFsvkViZn+pnLAduFbaZf6yx5+xlD1X4YYP1cT3ykarIMREduH+98Kxey46+Xs0Zv7hP3X /yzKsAbXKV5Sewmo5EdOoC3sgk+Tw425EMrlBsUFj871Gg/kt1csbLAOYt/o6ak5TNwN3/7u22y dGx6FV56Iz4iU1i8KJIq X-Received: by 2002:a05:6402:3554:b0:5de:5263:ae79 with SMTP id 4fb4d7f45d1cf-5e0b70f0041mr27989570a12.12.1740666016422; Thu, 27 Feb 2025 06:20:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9rccv8llgNynnIpHT98jNn2N6bzeWxaCSLX8hJwSQfyyn3+TQFQRqPmMSQUvBtNwarAxGNg== X-Received: by 2002:a05:6402:3554:b0:5de:5263:ae79 with SMTP id 4fb4d7f45d1cf-5e0b70f0041mr27989534a12.12.1740666015948; Thu, 27 Feb 2025 06:20:15 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c3b6d252sm1173607a12.26.2025.02.27.06.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:14 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Zhao Liu Subject: [PULL 10/34] stub: Remove monitor-fd.c Date: Thu, 27 Feb 2025 15:19:28 +0100 Message-ID: <20250227141952.811410-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Ilya Leoshkevich Both monitor-fd.c and monitor-internal.c contain a stub for monitor_get_fd(), which causes a duplicate symbol linker error when linking rust-qemu-api-integration. Use monitor-internal.c instead of monitor-fd.c and remove the latter. Reported-by: Zhao Liu Suggested-by: Zhao Liu Fixes: fccb744f41c6 ("gdbstub: Try unlinking the unix socket before binding") Signed-off-by: Ilya Leoshkevich Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250217104900.230122-1-iii@linux.ibm.com Signed-off-by: Paolo Bonzini --- stubs/monitor-fd.c | 9 --------- stubs/meson.build | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 stubs/monitor-fd.c diff --git a/stubs/monitor-fd.c b/stubs/monitor-fd.c deleted file mode 100644 index 9bb67498850..00000000000 --- a/stubs/monitor-fd.c +++ /dev/null @@ -1,9 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "qemu/osdep.h" -#include "monitor/monitor.h" - -int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp) -{ - abort(); -} diff --git a/stubs/meson.build b/stubs/meson.build index b0fee37e059..63392f5e785 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -62,7 +62,7 @@ if have_user stub_ss.add(files('qdev.c')) endif - stub_ss.add(files('monitor-fd.c')) + stub_ss.add(files('monitor-internal.c')) endif if have_system From patchwork Thu Feb 27 14:19:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994654 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB5B4C19F2E for ; Thu, 27 Feb 2025 14:26:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekZ-0007E5-A2; Thu, 27 Feb 2025 09:20:31 -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 ) id 1tnekW-0007BV-BX for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekU-0003l0-Jx for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d3SHEfAckc7eqDUyGo9AWwA42EPB6Qrfn1g2oHUJdAU=; b=CsWg0BhZi5T+6H8wbTB40jcAEE7W0cQzhStkuvjMJFzcsbjybIYYPvBYhhUKkcJRca/aTj OEf2GJOnCmP/YR9Ya3gFlNfeH5n7yzbOV/GehOGzGAncN1GFuUWa0b2br3yNfzYUDaYfHP HjQVl2GLefQj+IkkB2yr8RiK7Idi7Pg= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-693-qS-PosQrNgCe_EzZkF2xFw-1; Thu, 27 Feb 2025 09:20:21 -0500 X-MC-Unique: qS-PosQrNgCe_EzZkF2xFw-1 X-Mimecast-MFC-AGG-ID: qS-PosQrNgCe_EzZkF2xFw_1740666020 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-abb7e837a7aso112748666b.3 for ; Thu, 27 Feb 2025 06:20:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666019; x=1741270819; 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=d3SHEfAckc7eqDUyGo9AWwA42EPB6Qrfn1g2oHUJdAU=; b=H4stA6ISuB44nWVu35SabXSygv7W9f6jAC5KxKq++syZXHDDUg+ve2ruqFWt+JGELm IVtVczkuB76O0sOOsWpWadlZWWhit2HjI3hBsi629EAolPXOcPKw4MCEJuzbney5AzsV skfA3+44AFRVfQPnGgmY2NqzNIuaBEy6avGL7Pkoowp8nnS2d/jS1BqKx2El8qeXRXOD n7MN2D84aWxtw+6DnTwR310/UrsazThB4JY3pqfGENy+0jMXLX/bv+bc1rBmZ950fukh yTxbn2O7uwt3UIa6/4WTfqFL6ReBY10wfatr/z7GP69WSDxruDCnk1C9jmnyQq/2PPSi 4nvA== X-Gm-Message-State: AOJu0YyuoYBnJnKYOY7HAC9a1AktDG4K2IGVYoZlVj7SRwT2dh7gx+Vg Z1SHPXSjcHToYYymnJex8kA7AdQ9P1icIzFAdkuDH23nfCY3g8MBy86jzzX54STXDWWiDWNACm2 XAp0Ia6NEDCvvSdg5yyQ4S7SrFvs1F7ZO3TJruxq908wCB42qTtnfV33ZfnPpbBp6KjD9JH8DXL /zZH17u1bGiItkV6DuqAftS2SyJP5P7osLaRrzXE0= X-Gm-Gg: ASbGnctBaZTdCpbZ9PpLs/yNgYOJwxvoS/35hpQk8T52NkcwYqqz/YyJYd4601avsVg /oZU+bOvd/Fl05ioFw+TLbQV4O/baBlDUGP5SPNJ+N6sBI3LcoGtPRJ+rBp+bo8Bje/pUiNlQLP mCtOo5YZ81aN53Bju256RGOHuS+HH+tTbkxGshRT2WZgOLSw8MetPRpBctaJveIPS5tfoCtUNui IPxEaIPdXUhqg6IRGbQbiZDmB5mLuWxuPbDzFj/cWdpkgpyoCTiFKJ5Cjv4AYwoBo5HO4vLvH3Z TLm/TFD4n/56qTG+hrit X-Received: by 2002:a17:907:7801:b0:aa6:7737:199c with SMTP id a640c23a62f3a-abc09a079d1mr2691813066b.15.1740666019119; Thu, 27 Feb 2025 06:20:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFparBIFnApYePY3cRqTgul9/BGUSE3ord1JQgKYxTV0MP1CgCcshqlW0JkCTbBtdyaVcZJuA== X-Received: by 2002:a17:907:7801:b0:aa6:7737:199c with SMTP id a640c23a62f3a-abc09a079d1mr2691809166b.15.1740666018617; Thu, 27 Feb 2025 06:20:18 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c6f60b2sm129205466b.102.2025.02.27.06.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:16 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li , qemu-stable@nongnu.org, =?utf-8?q?Dan?= =?utf-8?q?iel_P=2E_Berrang=C3=A9?= , David Hildenbrand , Pankaj Gupta Subject: [PULL 11/34] physmem: replace assertion with error Date: Thu, 27 Feb 2025 15:19:29 +0100 Message-ID: <20250227141952.811410-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It is possible to start QEMU with a confidential-guest-support object even in TCG mode. While there is already a check in qemu_machine_creation_done: if (machine->cgs && !machine->cgs->ready) { error_setg(errp, "accelerator does not support confidential guest %s", object_get_typename(OBJECT(machine->cgs))); exit(1); } the creation of RAMBlocks happens earlier, in qemu_init_board(), if the command line does not override the default memory backend with -M memdev. Then the RAMBlock will try to use guest_memfd (because machine_require_guest_memfd correctly returns true; at least correctly according to the current implementation) and trigger the assertion failure for kvm_enabled(). This happend with a command line as simple as the following: qemu-system-x86_64 -m 512 -nographic -object sev-snp-guest,reduced-phys-bits=48,id=sev0 \ -M q35,kernel-irqchip=split,confidential-guest-support=sev0 qemu-system-x86_64: ../system/physmem.c:1871: ram_block_add: Assertion `kvm_enabled()' failed. Cc: Xiaoyao Li Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini Reviewed-by: Daniel P. Berrangé Reviewed-by: David Hildenbrand Reviewed-by: Pankaj Gupta Reviewed-by: Xiaoyao Li Link: https://lore.kernel.org/r/20250217120812.396522-1-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- system/physmem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system/physmem.c b/system/physmem.c index 67bdf631e60..eff8b55c2dd 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -1882,7 +1882,11 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) if (new_block->flags & RAM_GUEST_MEMFD) { int ret; - assert(kvm_enabled()); + if (!kvm_enabled()) { + error_setg(errp, "cannot set up private guest memory for %s: KVM required", + object_get_typename(OBJECT(current_machine->cgs))); + goto out_free; + } assert(new_block->guest_memfd < 0); ret = ram_block_discard_require(true); From patchwork Thu Feb 27 14:19:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4D66C19F2E for ; Thu, 27 Feb 2025 14:21:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekb-0007EN-DN; Thu, 27 Feb 2025 09:20:34 -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 ) id 1tnekX-0007CD-KE for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekU-0003l2-UW for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3r5BzHwwGLE8w4wpYRt2uj1rsGj25j/C0CBMCevqqBU=; b=SsOBAILotg0oXhmTlLCkfGNAZ/STfrDKo/Cr3KzFT7r9EtvC/Kq0UUomesfFxk6xmOR0vj 54SHtYjhNiBY59e9hfafWiZOXeVBPLYBP5gh6zLel/Aw1IljMlamYonW9Q0ZfNSfohLdgh xHJ+2YqYhUI4/TdpweU4OEiA80UZiIA= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-UQYzrzFhMM27S47IaMrfOw-1; Thu, 27 Feb 2025 09:20:21 -0500 X-MC-Unique: UQYzrzFhMM27S47IaMrfOw-1 X-Mimecast-MFC-AGG-ID: UQYzrzFhMM27S47IaMrfOw_1740666021 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-abf16f47749so73097166b.0 for ; Thu, 27 Feb 2025 06:20:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666020; x=1741270820; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3r5BzHwwGLE8w4wpYRt2uj1rsGj25j/C0CBMCevqqBU=; b=lzJVYKJnoxia5wruVxHsR3hnSEk4VDuza4q527RHJqYn2c8IhkP2YHsGcXwmXfjp9L Zwt7Y+lZUlkrFF8E0Y/CBNCBTTclNYpVSR/Dp1M8K5X/3ZJ+zWyVZFo2F0lzmYjjvrPE kVnyRTylfvARDQgg7aHNffiFjCivS1dW2vOxbYwpJ01suULl/AwSO6vTSjqzNjjQtZeX sMw7GrbO5BCJRaC3RuuMvIZRjoTFd2EWAM14cmMGr5dcpkPcanLhJmVxFgplA13dZ9IF fC74yC3SamuYTIOebMF3QXbSeFZ5oUjWeiEvkXDipZ6l8RitCK93WhQXmxEQkQitCbZA 1CEA== X-Gm-Message-State: AOJu0YzqDn3eHR569McZ0o7mOE3cQFJ6Bspxpg3gb9LeQmsRkoEIJeyi Rey9L93LLzm/HzIoKJ2E0uIJnM8y8yRvsbrn33a0vb4eLiyZFh84jS5nL33JizGXExDTaNG5U8Y bpCumTGymQAFAt8FSqbefQdnH9YEvY1h6GvODGE8icDa94fuO50Y3u5Cxv/nauIXB1kWnJIqbNU 7Wx161npwYFUL/BZEvJQQNspcqkha12cQUVeG05Tc= X-Gm-Gg: ASbGncvTDRmP+At45l1i6h5I6IuHvKraXPPHtMKpt8eV0fhUZYAUPsDEI7lUypZhAzK Verd9SZGgHRHITIolc/8s9hO11pdkM8f1w9ZUEoMBCtC0MvKY1sJPzdEmIsgSLf7nJV487+pxrW v2rclMuGOWlv41ufmU35eKZPNyrnbfKzMWfG++ZPESh/VbFTJ86YsH9aaHlQYEEwpidH9FZo/0x ByhBg+tfQk/cbDo6aDE4Fv/ZFaMoLwZL9O866aNI/o3Ga4BVvb/8FTnvnX66WRDegf4kvH4PLpG NVnYpc+HJW0pxixm6usm X-Received: by 2002:a05:6402:4310:b0:5de:5939:6c34 with SMTP id 4fb4d7f45d1cf-5e4bfba9848mr4139849a12.15.1740666020232; Thu, 27 Feb 2025 06:20:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9emLnvHCCggBF1OEIDrmWorMy2I48000PcEQ7IZrLuP0QRKyPgEoe8g1cWCogbehQCz0Oeg== X-Received: by 2002:a05:6402:4310:b0:5de:5939:6c34 with SMTP id 4fb4d7f45d1cf-5e4bfba9848mr4139825a12.15.1740666019667; Thu, 27 Feb 2025 06:20:19 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c43a55e0sm1145604a12.79.2025.02.27.06.20.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 12/34] pvg: do not enable it on cross-architecture targets Date: Thu, 27 Feb 2025 15:19:30 +0100 Message-ID: <20250227141952.811410-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org PVG is not cross-architecture; the PVG guest drivers with x86-64 macOS do not give useful results with the aarch64 macOS host PVG framework, and vice versa. To express this repurpose CONFIG_MAC_PVG, making it true only if the target has the same architecture as the host. Furthermore, remove apple-gfx.m unless one of the devices is actually present. Signed-off-by: Paolo Bonzini --- meson.build | 6 ++++++ Kconfig.host | 3 +++ hw/display/Kconfig | 4 ---- hw/display/meson.build | 9 +++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index 0ee79c664d3..ad2c6b61930 100644 --- a/meson.build +++ b/meson.build @@ -3367,6 +3367,12 @@ foreach target : target_dirs target_kconfig += 'CONFIG_' + config_target['TARGET_ARCH'].to_upper() + '=y' target_kconfig += 'CONFIG_TARGET_BIG_ENDIAN=' + config_target['TARGET_BIG_ENDIAN'] + # PVG is not cross-architecture. Use accelerator_targets as a proxy to + # figure out which target can support PVG on this host + if pvg.found() and target in accelerator_targets.get('CONFIG_HVF', []) + target_kconfig += 'CONFIG_MAC_PVG=y' + endif + config_input = meson.get_external_property(target, 'default') config_devices_mak = target + '-config-devices.mak' config_devices_mak = configure_file( diff --git a/Kconfig.host b/Kconfig.host index 842cbe0d6c5..933425c74b4 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -61,3 +61,6 @@ config HV_BALLOON_POSSIBLE config HAVE_RUST bool + +config MAC_PVG + bool diff --git a/hw/display/Kconfig b/hw/display/Kconfig index 2b53dfd7d26..1e95ab28ef4 100644 --- a/hw/display/Kconfig +++ b/hw/display/Kconfig @@ -141,10 +141,6 @@ config XLNX_DISPLAYPORT config DM163 bool -config MAC_PVG - bool - default y - config MAC_PVG_MMIO bool depends on MAC_PVG && AARCH64 diff --git a/hw/display/meson.build b/hw/display/meson.build index 94f4f05d36f..b9bdf219103 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -61,12 +61,9 @@ system_ss.add(when: 'CONFIG_ARTIST', if_true: files('artist.c')) system_ss.add(when: 'CONFIG_ATI_VGA', if_true: [files('ati.c', 'ati_2d.c', 'ati_dbg.c'), pixman]) -if host_os == 'darwin' - system_ss.add(when: 'CONFIG_MAC_PVG', if_true: [files('apple-gfx.m'), pvg, metal]) - system_ss.add(when: 'CONFIG_MAC_PVG_PCI', if_true: [files('apple-gfx-pci.m'), pvg, metal]) - if cpu == 'aarch64' - system_ss.add(when: 'CONFIG_MAC_PVG_MMIO', if_true: [files('apple-gfx-mmio.m'), pvg, metal]) - endif +if pvg.found() + system_ss.add(when: 'CONFIG_MAC_PVG_PCI', if_true: [files('apple-gfx.m', 'apple-gfx-pci.m'), pvg, metal]) + system_ss.add(when: 'CONFIG_MAC_PVG_MMIO', if_true: [files('apple-gfx.m', 'apple-gfx-mmio.m'), pvg, metal]) endif if config_all_devices.has_key('CONFIG_VIRTIO_GPU') From patchwork Thu Feb 27 14:19:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D63F0C19F2E for ; Thu, 27 Feb 2025 14:24:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekj-0007Fk-AU; Thu, 27 Feb 2025 09:20:41 -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 ) id 1tnekb-0007Ei-KA for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekX-0003lK-3b for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qDS6Z8WrawwiiNNBQJGPMXXcS8yRfFQepxVzx5eREHg=; b=eaq6drC+JkXJffsUXMNYqSLw1o5J05htqPeu2KEdq2hnqriKVb+OCwfEt52wIiu8QzDtGV rUy6qG7rspHdESb5JkoRGcUBc0cHPYzYjPBjyVbdaSwugjLs8bJbMKINbQKLOgw7Rk53RA u0qPXcWap/0OtBnwu8NzPmXS9Afg+RM= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-_OkUomRKOi2xiANX7B9tZQ-1; Thu, 27 Feb 2025 09:20:25 -0500 X-MC-Unique: _OkUomRKOi2xiANX7B9tZQ-1 X-Mimecast-MFC-AGG-ID: _OkUomRKOi2xiANX7B9tZQ_1740666023 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-abec83a498cso114824066b.1 for ; Thu, 27 Feb 2025 06:20:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666022; x=1741270822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qDS6Z8WrawwiiNNBQJGPMXXcS8yRfFQepxVzx5eREHg=; b=IZ236ryrjJtWnhMCKb6iJEcRHKCRYmhbC3ECP8XzLfQJJdLPIProI/wci2TafXe5Ls hq18WS7ai657c5jut7JPFySwEYSr8ZGZ7JVCKUthCPNR6x+Y7v4HKHtv+SxyP/F/YYZm Ui6LxIDV5qkY5ZFzrgP7h1uWZribfZxkuVB+Pu10kcY21/312qc28HyX21Z/In8Ud5eJ O1IoFL1Gt3BpRUOrAV5DdfmHwF+L/PjxMGEWj4+IgWC46njgaHCERHkM2aTYRgi83IUw JhlsnEKlXFDUgsskKFbZQ0/dkYOmz2DGa42Om3L0xioe3Y/GxQF9wv4lDKb+h0fBr1a/ pZqQ== X-Gm-Message-State: AOJu0YzBMJ8nywVOdeCqENwpsF+q34/FsaQndW5xzZaNAJqTMCmpobyW vsvcr8XWOEmz0WbZsD87Gb1BPDNn5JbkFPZsAhlh7Mql4v1Eneoohy2IQsqpQZx0BQ5bbuEhccB qg5hs7UvI/yZ5hjy+ZnRSqCUv2MEwmVkEPkfE6uXNJsRbqa/Dh+VYyT65YihWN/SyX6y2PQbadt WFJTtu5zmWO/g0WyOPiflO7IHMeFSYBuuV4++iLc0= X-Gm-Gg: ASbGncvatZsXyRwd3dzO6TzFhUf48ZQ/yl9ejtgAksY3XAWrbbL8no8ZUuhebZmP5W0 pkurE0C1ZLVicvD0sz/EQCan6zAw/8dq5AileDCTf7VXErJSHP8aCdoKsY5ZSik4/u9um85yEs9 ihDPQqpE4U7gvtI2I/0aW6lsBqBSU1U+AbvC/57xCNbnYdMk9PWu1IdbkgrbDKJjd5YwCYNKZZ4 GPf7TgdXEWXA6gYT662FUmecGo94dGdxTv+xJqasXZE1i2mjWqw79T4rvBEckt3lXrZYuoz0iEi lflSJFIF5zHigJT/Kty9 X-Received: by 2002:a17:907:a42:b0:abe:cecc:727 with SMTP id a640c23a62f3a-abeeefc9108mr1115438766b.53.1740666022538; Thu, 27 Feb 2025 06:20:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGczmJdoKKAUlk0rHBNxZL5To0t5xZmTCbJAqQAD5Prh9RXIwM35vJs4lvLoUpGjyMkMyzqLQ== X-Received: by 2002:a17:907:a42:b0:abe:cecc:727 with SMTP id a640c23a62f3a-abeeefc9108mr1115434066b.53.1740666021995; Thu, 27 Feb 2025 06:20:21 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c7ba168sm126906266b.163.2025.02.27.06.20.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:20 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 13/34] pvg: add option to configure it out Date: Thu, 27 Feb 2025 15:19:31 +0100 Message-ID: <20250227141952.811410-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ... and also to require it (--enable-pvg). While at it, unify the dependency() call for pvg and metal, which simplifies the logic a bit. Note that all other Apple frameworks are either required or always-present, therefore do not add them to the summary in the same way as PVG. Signed-off-by: Paolo Bonzini --- meson.build | 8 +++++--- hw/display/meson.build | 6 ++---- meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 3 +++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index ad2c6b61930..0a2c61d2bfa 100644 --- a/meson.build +++ b/meson.build @@ -821,7 +821,6 @@ version_res = [] coref = [] iokit = [] pvg = not_found -metal = [] emulator_link_args = [] midl = not_found widl = not_found @@ -843,8 +842,8 @@ elif host_os == 'darwin' coref = dependency('appleframeworks', modules: 'CoreFoundation') iokit = dependency('appleframeworks', modules: 'IOKit', required: false) host_dsosuf = '.dylib' - pvg = dependency('appleframeworks', modules: 'ParavirtualizedGraphics') - metal = dependency('appleframeworks', modules: 'Metal') + pvg = dependency('appleframeworks', modules: ['ParavirtualizedGraphics', 'Metal'], + required: get_option('pvg')) elif host_os == 'sunos' socket = [cc.find_library('socket'), cc.find_library('nsl'), @@ -4846,6 +4845,9 @@ summary_info += {'libdw': libdw} if host_os == 'freebsd' summary_info += {'libinotify-kqueue': inotify} endif +if host_os == 'darwin' + summary_info += {'ParavirtualizedGraphics support': pvg} +endif summary(summary_info, bool_yn: true, section: 'Dependencies') if host_arch == 'unknown' diff --git a/hw/display/meson.build b/hw/display/meson.build index b9bdf219103..90e6c041bdb 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -61,10 +61,8 @@ system_ss.add(when: 'CONFIG_ARTIST', if_true: files('artist.c')) system_ss.add(when: 'CONFIG_ATI_VGA', if_true: [files('ati.c', 'ati_2d.c', 'ati_dbg.c'), pixman]) -if pvg.found() - system_ss.add(when: 'CONFIG_MAC_PVG_PCI', if_true: [files('apple-gfx.m', 'apple-gfx-pci.m'), pvg, metal]) - system_ss.add(when: 'CONFIG_MAC_PVG_MMIO', if_true: [files('apple-gfx.m', 'apple-gfx-mmio.m'), pvg, metal]) -endif +system_ss.add(when: [pvg, 'CONFIG_MAC_PVG_PCI'], if_true: [files('apple-gfx.m', 'apple-gfx-pci.m')]) +system_ss.add(when: [pvg, 'CONFIG_MAC_PVG_MMIO'], if_true: [files('apple-gfx.m', 'apple-gfx-mmio.m')]) if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss = ss.source_set() diff --git a/meson_options.txt b/meson_options.txt index 5eeaf3eee5c..59d973bca00 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -198,6 +198,8 @@ option('lzfse', type : 'feature', value : 'auto', description: 'lzfse support for DMG images') option('lzo', type : 'feature', value : 'auto', description: 'lzo compression support') +option('pvg', type: 'feature', value: 'auto', + description: 'macOS paravirtualized graphics support') option('rbd', type : 'feature', value : 'auto', description: 'Ceph block device driver') option('opengl', type : 'feature', value : 'auto', diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index a8066aab037..3e8e00852b2 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -168,6 +168,7 @@ meson_options_help() { printf "%s\n" ' pixman pixman support' printf "%s\n" ' plugins TCG plugins via shared library loading' printf "%s\n" ' png PNG support with libpng' + printf "%s\n" ' pvg macOS paravirtualized graphics support' printf "%s\n" ' qatzip QATzip compression support' printf "%s\n" ' qcow1 qcow1 image format support' printf "%s\n" ' qed qed image format support' @@ -436,6 +437,8 @@ _meson_option_parse() { --enable-png) printf "%s" -Dpng=enabled ;; --disable-png) printf "%s" -Dpng=disabled ;; --prefix=*) quote_sh "-Dprefix=$2" ;; + --enable-pvg) printf "%s" -Dpvg=enabled ;; + --disable-pvg) printf "%s" -Dpvg=disabled ;; --enable-qatzip) printf "%s" -Dqatzip=enabled ;; --disable-qatzip) printf "%s" -Dqatzip=disabled ;; --enable-qcow1) printf "%s" -Dqcow1=enabled ;; From patchwork Thu Feb 27 14:19:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B896EC19F2E for ; Thu, 27 Feb 2025 14:22:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekl-0007GF-GK; Thu, 27 Feb 2025 09:20:43 -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 ) id 1tnekb-0007Ej-Ka for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekZ-0003lz-43 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BzevOw2v7eV63sKXI0ynTRS0gFenKTHy7ijiSe2WtG8=; b=Rd1Vaf067brtPWNmwnUkppQEQpPWF/XwqUNtFhQqAnZsOJvhGcMXsqFaa3ZSgQhth+i1VR bYp1mABHfwuMVwVIXmVcCm9TwPfZGhdxvq2i6H+3W1GqEtlt16ShEuEzbkacmwUVT+ySBP zPSpqqh3Q1YAMtRf+JYW4aDUnpGPuDc= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-uccrlwbJOJ6LSCjSRvNpVQ-1; Thu, 27 Feb 2025 09:20:28 -0500 X-MC-Unique: uccrlwbJOJ6LSCjSRvNpVQ-1 X-Mimecast-MFC-AGG-ID: uccrlwbJOJ6LSCjSRvNpVQ_1740666027 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-abbc0572fc9so133284766b.0 for ; Thu, 27 Feb 2025 06:20:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666025; x=1741270825; 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=BzevOw2v7eV63sKXI0ynTRS0gFenKTHy7ijiSe2WtG8=; b=oZSagxcD3UGwns5tcHlJPEPxOiSLTCLH2ffy+z9imdTmn4aDHOu74yr8QJRXNexyvt H8t1f/bL1CsBywpc0ywUkNFU8aF0W14IzZHFyXuS6U6X2V8N9sRgHctrHWsgwXP1Un1r PGY1gGdx4lPzwrUhWN7a23ntEFVoZ+sp5cxl+ww+xGTGKuH5cSNzqagVVu13yceGBX6H TVf4tOhibsJSVmzV3EtbRAIJtlf/3ViuBDVKp43v3f9JYfN0L8OREicRT7iYY4JFhWbs z/AhpK99twpaigtj+m6vjeT4L2Z++TQMq5TLvejaUFzTKWX3gVqROD1Ergq/MbqWp28w XMSw== X-Gm-Message-State: AOJu0YzIhsUb6BjoOHAgGOcRDtV011NyZdlnvMVRaVnylfJeYe7XyMN8 e0LusJUzCofvR190Jf8T7WvlzAdIkUwynedZnGp9iKEXNIVTfmPnwKpgf41Fe2G8RQqGteEaf45 1z0ysefTBmo0D7dNU6kP9xPwMKNMZDfhENpLLLCHQNOv1zlW9DlbYkixQ5a5LfJPnqT4SDoBJ15 6kn4XeCjyzGNoNXdKJMx49D9JcZYR1zF7EUnSCnyc= X-Gm-Gg: ASbGncseswNcb2cRIzKaE7Jn5NhQlckWMHtff21CLm+llxSBvygH/qsxgXgULkay9p8 OmqXyGCUKU3M5TDwzO2MRLch9ehGNmyHRqijYQsntiAOUTbCeSaphmLiQfzN6EFXOftWwX3V6HO vEEy5KXHDXjZrj/B1AslViprSHz6elJSAh9amvCSBiYX2tmC9WyM4/vPHZaZh35qtL+HnVi7hH0 dcFZtOHmWQiGOMUPQ+3STnfcVOzIBPRl4TXuiVYZ/cAHZAp6ls4/uVYmcqUtAks4p5i/OWUnWM7 vw6xin3MK/VPFc76Qm4L X-Received: by 2002:a17:907:7704:b0:ab7:ef38:1277 with SMTP id a640c23a62f3a-abc09a74646mr2372138266b.26.1740666025173; Thu, 27 Feb 2025 06:20:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQMrpA+80/oIoceAbfVOiXOR2QDCzYmfvXCr/nYuVn95AM2fdhPGzTIoMHxUbswgTP5t2+CQ== X-Received: by 2002:a17:907:7704:b0:ab7:ef38:1277 with SMTP id a640c23a62f3a-abc09a74646mr2372133166b.26.1740666024311; Thu, 27 Feb 2025 06:20:24 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c74fba2sm128900366b.131.2025.02.27.06.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:22 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Wei Liu , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 14/34] target/i386/hvf: fix a typo in a type name Date: Thu, 27 Feb 2025 15:19:32 +0100 Message-ID: <20250227141952.811410-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Wei Liu The prefix x68 is wrong. Change it to x86. Signed-off-by: Wei Liu Reviewed-by: Philippe Mathieu-Daudé Link: https://lore.kernel.org/r/1740126987-8483-2-git-send-email-liuwe@linux.microsoft.com Signed-off-by: Paolo Bonzini --- target/i386/hvf/x86.h | 8 ++++---- target/i386/hvf/x86_descr.h | 6 +++--- target/i386/hvf/x86_task.h | 2 +- target/i386/hvf/hvf.c | 2 +- target/i386/hvf/x86.c | 4 ++-- target/i386/hvf/x86_descr.c | 8 ++++---- target/i386/hvf/x86_task.c | 22 +++++++++++----------- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/target/i386/hvf/x86.h b/target/i386/hvf/x86.h index 3570f29aa9d..063cd0b83ec 100644 --- a/target/i386/hvf/x86.h +++ b/target/i386/hvf/x86.h @@ -183,7 +183,7 @@ static inline uint32_t x86_call_gate_offset(x86_call_gate *gate) #define GDT_SEL 0 #define LDT_SEL 1 -typedef struct x68_segment_selector { +typedef struct x86_segment_selector { union { uint16_t sel; struct { @@ -192,7 +192,7 @@ typedef struct x68_segment_selector { uint16_t index:13; }; }; -} __attribute__ ((__packed__)) x68_segment_selector; +} __attribute__ ((__packed__)) x86_segment_selector; /* useful register access macros */ #define x86_reg(cpu, reg) ((x86_register *) &cpu->regs[reg]) @@ -250,10 +250,10 @@ typedef struct x68_segment_selector { /* deal with GDT/LDT descriptors in memory */ bool x86_read_segment_descriptor(CPUState *cpu, struct x86_segment_descriptor *desc, - x68_segment_selector sel); + x86_segment_selector sel); bool x86_write_segment_descriptor(CPUState *cpu, struct x86_segment_descriptor *desc, - x68_segment_selector sel); + x86_segment_selector sel); bool x86_read_call_gate(CPUState *cpu, struct x86_call_gate *idt_desc, int gate); diff --git a/target/i386/hvf/x86_descr.h b/target/i386/hvf/x86_descr.h index 9f06014b56a..ce5de983497 100644 --- a/target/i386/hvf/x86_descr.h +++ b/target/i386/hvf/x86_descr.h @@ -34,10 +34,10 @@ void vmx_read_segment_descriptor(CPUState *cpu, void vmx_write_segment_descriptor(CPUState *cpu, struct vmx_segment *desc, enum X86Seg seg); -x68_segment_selector vmx_read_segment_selector(CPUState *cpu, +x86_segment_selector vmx_read_segment_selector(CPUState *cpu, enum X86Seg seg); void vmx_write_segment_selector(CPUState *cpu, - x68_segment_selector selector, + x86_segment_selector selector, enum X86Seg seg); uint64_t vmx_read_segment_base(CPUState *cpu, enum X86Seg seg); @@ -45,7 +45,7 @@ void vmx_write_segment_base(CPUState *cpu, enum X86Seg seg, uint64_t base); void x86_segment_descriptor_to_vmx(CPUState *cpu, - x68_segment_selector selector, + x86_segment_selector selector, struct x86_segment_descriptor *desc, struct vmx_segment *vmx_desc); diff --git a/target/i386/hvf/x86_task.h b/target/i386/hvf/x86_task.h index 4eaa61a7dee..b9afac6a47b 100644 --- a/target/i386/hvf/x86_task.h +++ b/target/i386/hvf/x86_task.h @@ -15,6 +15,6 @@ #ifndef HVF_X86_TASK_H #define HVF_X86_TASK_H -void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, +void vmx_handle_task_switch(CPUState *cpu, x86_segment_selector tss_sel, int reason, bool gate_valid, uint8_t gate, uint64_t gate_type); #endif diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index ca08f0753f0..353549fa779 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -674,7 +674,7 @@ int hvf_vcpu_exec(CPUState *cpu) } case EXIT_REASON_TASK_SWITCH: { uint64_t vinfo = rvmcs(cpu->accel->fd, VMCS_IDT_VECTORING_INFO); - x68_segment_selector sel = {.sel = exit_qual & 0xffff}; + x86_segment_selector sel = {.sel = exit_qual & 0xffff}; vmx_handle_task_switch(cpu, sel, (exit_qual >> 30) & 0x3, vinfo & VMCS_INTR_VALID, vinfo & VECTORING_INFO_VECTOR_MASK, vinfo & VMCS_INTR_T_MASK); diff --git a/target/i386/hvf/x86.c b/target/i386/hvf/x86.c index 80e36136d04..a0ede138865 100644 --- a/target/i386/hvf/x86.c +++ b/target/i386/hvf/x86.c @@ -48,7 +48,7 @@ bool x86_read_segment_descriptor(CPUState *cpu, struct x86_segment_descriptor *desc, - x68_segment_selector sel) + x86_segment_selector sel) { target_ulong base; uint32_t limit; @@ -78,7 +78,7 @@ bool x86_read_segment_descriptor(CPUState *cpu, bool x86_write_segment_descriptor(CPUState *cpu, struct x86_segment_descriptor *desc, - x68_segment_selector sel) + x86_segment_selector sel) { target_ulong base; uint32_t limit; diff --git a/target/i386/hvf/x86_descr.c b/target/i386/hvf/x86_descr.c index f33836d6cba..7b599c90377 100644 --- a/target/i386/hvf/x86_descr.c +++ b/target/i386/hvf/x86_descr.c @@ -60,14 +60,14 @@ uint64_t vmx_read_segment_base(CPUState *cpu, X86Seg seg) return rvmcs(cpu->accel->fd, vmx_segment_fields[seg].base); } -x68_segment_selector vmx_read_segment_selector(CPUState *cpu, X86Seg seg) +x86_segment_selector vmx_read_segment_selector(CPUState *cpu, X86Seg seg) { - x68_segment_selector sel; + x86_segment_selector sel; sel.sel = rvmcs(cpu->accel->fd, vmx_segment_fields[seg].selector); return sel; } -void vmx_write_segment_selector(CPUState *cpu, x68_segment_selector selector, X86Seg seg) +void vmx_write_segment_selector(CPUState *cpu, x86_segment_selector selector, X86Seg seg) { wvmcs(cpu->accel->fd, vmx_segment_fields[seg].selector, selector.sel); } @@ -90,7 +90,7 @@ void vmx_write_segment_descriptor(CPUState *cpu, struct vmx_segment *desc, X86Se wvmcs(cpu->accel->fd, sf->ar_bytes, desc->ar); } -void x86_segment_descriptor_to_vmx(CPUState *cpu, x68_segment_selector selector, +void x86_segment_descriptor_to_vmx(CPUState *cpu, x86_segment_selector selector, struct x86_segment_descriptor *desc, struct vmx_segment *vmx_desc) { diff --git a/target/i386/hvf/x86_task.c b/target/i386/hvf/x86_task.c index bcd844cff60..287fe11cf70 100644 --- a/target/i386/hvf/x86_task.c +++ b/target/i386/hvf/x86_task.c @@ -76,16 +76,16 @@ static void load_state_from_tss32(CPUState *cpu, struct x86_tss_segment32 *tss) RSI(env) = tss->esi; RDI(env) = tss->edi; - vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ldt}}, R_LDTR); - vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->es}}, R_ES); - vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->cs}}, R_CS); - vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ss}}, R_SS); - vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->ds}}, R_DS); - vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->fs}}, R_FS); - vmx_write_segment_selector(cpu, (x68_segment_selector){{tss->gs}}, R_GS); + vmx_write_segment_selector(cpu, (x86_segment_selector){{tss->ldt}}, R_LDTR); + vmx_write_segment_selector(cpu, (x86_segment_selector){{tss->es}}, R_ES); + vmx_write_segment_selector(cpu, (x86_segment_selector){{tss->cs}}, R_CS); + vmx_write_segment_selector(cpu, (x86_segment_selector){{tss->ss}}, R_SS); + vmx_write_segment_selector(cpu, (x86_segment_selector){{tss->ds}}, R_DS); + vmx_write_segment_selector(cpu, (x86_segment_selector){{tss->fs}}, R_FS); + vmx_write_segment_selector(cpu, (x86_segment_selector){{tss->gs}}, R_GS); } -static int task_switch_32(CPUState *cpu, x68_segment_selector tss_sel, x68_segment_selector old_tss_sel, +static int task_switch_32(CPUState *cpu, x86_segment_selector tss_sel, x86_segment_selector old_tss_sel, uint64_t old_tss_base, struct x86_segment_descriptor *new_desc) { struct x86_tss_segment32 tss_seg; @@ -108,7 +108,7 @@ static int task_switch_32(CPUState *cpu, x68_segment_selector tss_sel, x68_segme return 0; } -void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int reason, bool gate_valid, uint8_t gate, uint64_t gate_type) +void vmx_handle_task_switch(CPUState *cpu, x86_segment_selector tss_sel, int reason, bool gate_valid, uint8_t gate, uint64_t gate_type) { uint64_t rip = rreg(cpu->accel->fd, HV_X86_RIP); if (!gate_valid || (gate_type != VMCS_INTR_T_HWEXCEPTION && @@ -122,7 +122,7 @@ void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int rea load_regs(cpu); struct x86_segment_descriptor curr_tss_desc, next_tss_desc; - x68_segment_selector old_tss_sel = vmx_read_segment_selector(cpu, R_TR); + x86_segment_selector old_tss_sel = vmx_read_segment_selector(cpu, R_TR); uint64_t old_tss_base = vmx_read_segment_base(cpu, R_TR); uint32_t desc_limit; struct x86_call_gate task_gate_desc; @@ -140,7 +140,7 @@ void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int rea x86_read_call_gate(cpu, &task_gate_desc, gate); dpl = task_gate_desc.dpl; - x68_segment_selector cs = vmx_read_segment_selector(cpu, R_CS); + x86_segment_selector cs = vmx_read_segment_selector(cpu, R_CS); if (tss_sel.rpl > dpl || cs.rpl > dpl) ;//DPRINTF("emulate_gp"); } From patchwork Thu Feb 27 14:19:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7AE37C19F2E for ; Thu, 27 Feb 2025 14:32:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnekn-0007M6-Ii; Thu, 27 Feb 2025 09:20:45 -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 ) id 1tnekb-0007Ek-KW for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekZ-0003mE-Ca for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OFjFdlkLFZq0ZT7FD3u03N89XHgvBXcDvp8KHJtTu6Q=; b=KV5U8NX2gKptn29fFi1sZnVxj88QogbfinaA9jntd2CsqolDQGDdxkz9hLUatTyE9Sn4wj qYmh5xBTm8UrPa3cL8vDuOMYBgsZhuSTSrB62TywCQIdMMM1fUKF7pwzKmWVd365LF95RL LL6BNKYQdLj6Jwe2+LfzoeP2hducngI= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-Rq_O9rL0O0yPkBKiYCtx4w-1; Thu, 27 Feb 2025 09:20:29 -0500 X-MC-Unique: Rq_O9rL0O0yPkBKiYCtx4w-1 X-Mimecast-MFC-AGG-ID: Rq_O9rL0O0yPkBKiYCtx4w_1740666028 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-abb9d1c8113so105451666b.0 for ; Thu, 27 Feb 2025 06:20:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666026; x=1741270826; 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=OFjFdlkLFZq0ZT7FD3u03N89XHgvBXcDvp8KHJtTu6Q=; b=wPA0ojgrBrk1Uz6x5pzKbhLLPRv5rC8SsdDNoJCRwz9ABjxufvuU57q3h16WirZzHB Rqsb3wm4t/99i44G5kfdItaq+ysRxvO8tiIfgC4rkfRB/hll85eLsErc/E1VtvB3m8n7 Mk/kMI1xuEtwzrY4vhhmrftSI8fwcXFat85gzSSJeMYIVfQhBNet5XcLrV1omxrf1oIV hLmz6h2xAXLh7JsfhFXFGbd4iHLKbGtnc4jEPm3yrYQtJs0WeLTClRiBPuoBWFMiJ7pB QgewPi8VTBNUOy7lpOktoTZPt/NXiVcqnA64YHp1kFtGdjsI3Qz6GQrbNmsX8Zaj/Rk4 e/BA== X-Gm-Message-State: AOJu0Ywk/xaLuwsCno6hY8JsWlRegBmaIjqkT7dYLTpxCijZzolnaJ9t LX9Ce7ldym4tdpPBVNXiYIyErkQhRybPBhuj6B7nllFh9J+MaoKyER/qOAjog6oFGTPdPdnOTf1 MH5xm67RKVVAcfcfv98xOiY/1jm9D4UoO/T0b9Ac3UghoEv8ZsU34+sp/MKzwtDGx6diJLeI5l8 6XoHTbCR8mMSaq34SsmHdKOjrGQJyGS5BrWZW5AiU= X-Gm-Gg: ASbGncu1H5yPJPWY3EOV5TgOWQ7AN7/jUP5S4pdbOOWUqM9qrCX4vuB2n1kpYsWZlqt MJvwybZKOJCTHtUkmW8XDmp0ks5V6MQrS+NJdrof1RdZ6ElmZGAl8WU8PGWqEgOmMLbTuetS+3I Wnqpb2Qm8J2Ai6axj6psTpcI3QBie3vTctW2llWRjz3Xmt7XfdmSUTE7CmKCSdd4wwqr9/5vazV wBcVT67/oP+1Rv2iK8L8aRKoFltoKU/jQ3jYAZP4Zqfnu2HuSlHtWIAXA8Gu+jRRWfbc1KQMjK3 fOkCH86uP2w0b+dYm0W/ X-Received: by 2002:a17:907:1c28:b0:abb:d9c6:ecb2 with SMTP id a640c23a62f3a-abeeed5f5c7mr778296266b.21.1740666026271; Thu, 27 Feb 2025 06:20:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHk3huHDJ0jd9iiFURktx9s849n+VJEZsX+VObrS4e+XichH8/IJ4AK9QwCEh0X3h6dMr0Og== X-Received: by 2002:a17:907:1c28:b0:abb:d9c6:ecb2 with SMTP id a640c23a62f3a-abeeed5f5c7mr778293566b.21.1740666025775; Thu, 27 Feb 2025 06:20:25 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0b9887sm129751966b.7.2025.02.27.06.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:25 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Wei Liu Subject: [PULL 15/34] target/i386/hvf: fix the declaration of hvf_handle_io Date: Thu, 27 Feb 2025 15:19:33 +0100 Message-ID: <20250227141952.811410-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Wei Liu There is a conflicting declaration for hvf_handle_io in x86_emu.c. The type of the first argument is wrong. There has never been a problem because the first argument is not used in hvf_handle_io. That being said, the code shouldn't contain such an error. Use the proper declaration from hvf-i386.h. Take the chance to change the first argument's type to be CPUState. Signed-off-by: Wei Liu Link: https://lore.kernel.org/r/1740126987-8483-3-git-send-email-liuwe@linux.microsoft.com Signed-off-by: Paolo Bonzini --- target/i386/hvf/hvf-i386.h | 2 +- target/i386/hvf/hvf.c | 6 +++--- target/i386/hvf/x86_emu.c | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/target/i386/hvf/hvf-i386.h b/target/i386/hvf/hvf-i386.h index e99c02cd4bf..046b681d134 100644 --- a/target/i386/hvf/hvf-i386.h +++ b/target/i386/hvf/hvf-i386.h @@ -18,7 +18,7 @@ uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx, int reg); -void hvf_handle_io(CPUArchState *, uint16_t, void *, int, int, int); +void hvf_handle_io(CPUState *, uint16_t, void *, int, int, int); /* Host specific functions */ int hvf_inject_interrupt(CPUArchState *env, int vector); diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 353549fa779..1ecb6993ba1 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -103,7 +103,7 @@ static void update_apic_tpr(CPUState *cpu) #define VECTORING_INFO_VECTOR_MASK 0xff -void hvf_handle_io(CPUArchState *env, uint16_t port, void *buffer, +void hvf_handle_io(CPUState *env, uint16_t port, void *buffer, int direction, int size, int count) { int i; @@ -536,7 +536,7 @@ int hvf_vcpu_exec(CPUState *cpu) if (!string && in) { uint64_t val = 0; load_regs(cpu); - hvf_handle_io(env, port, &val, 0, size, 1); + hvf_handle_io(env_cpu(env), port, &val, 0, size, 1); if (size == 1) { AL(env) = val; } else if (size == 2) { @@ -551,7 +551,7 @@ int hvf_vcpu_exec(CPUState *cpu) break; } else if (!string && !in) { RAX(env) = rreg(cpu->accel->fd, HV_X86_RAX); - hvf_handle_io(env, port, &RAX(env), 1, size, 1); + hvf_handle_io(env_cpu(env), port, &RAX(env), 1, size, 1); macvm_set_rip(cpu, rip + ins_len); break; } diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c index 69c61c9c073..2c7da10c1d2 100644 --- a/target/i386/hvf/x86_emu.c +++ b/target/i386/hvf/x86_emu.c @@ -44,9 +44,7 @@ #include "x86_flags.h" #include "vmcs.h" #include "vmx.h" - -void hvf_handle_io(CPUState *cs, uint16_t port, void *data, - int direction, int size, uint32_t count); +#include "hvf-i386.h" #define EXEC_2OP_FLAGS_CMD(env, decode, cmd, FLAGS_FUNC, save_res) \ { \ From patchwork Thu Feb 27 14:19:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994692 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8240C19F2E for ; Thu, 27 Feb 2025 14:34:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tneko-0007Nn-RS; Thu, 27 Feb 2025 09:20:47 -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 ) id 1tnekl-0007Jo-3R for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekd-0003ms-D9 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vnzc4UUkvTQN2ZMghuf8CBTQIaTWTUioqbHttISTjcc=; b=fPXa/11tCb6aB9/UNQRqyg2P+557rsAIseHGf54R5cfnNcRHJhFyWOuMhCd4F/0zg4NmvV X/K4WevtuEl1Ww/mTmPlJ1PXvX7BZp2bGIP/AGmo9kOn3hYCN7MAocfqrRXxTIVjjuzkWd a3TdgRd9Bc7bPLfIT/jUWMwwW1L+53U= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-349-tJlK4aAJOdOQF12i_rt2Wg-1; Thu, 27 Feb 2025 09:20:31 -0500 X-MC-Unique: tJlK4aAJOdOQF12i_rt2Wg-1 X-Mimecast-MFC-AGG-ID: tJlK4aAJOdOQF12i_rt2Wg_1740666031 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-abec83a498cso114845166b.1 for ; Thu, 27 Feb 2025 06:20:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666030; x=1741270830; 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=vnzc4UUkvTQN2ZMghuf8CBTQIaTWTUioqbHttISTjcc=; b=ZwYpFQJseMJ93Yl5HFsy3CE1v9rDx/9gG61Epvpgx3dDbysB0fscdjrqjJyqBmWRx5 0I5YSvG6rcMdfAXzeEvucBJImgdxIw+vZVUAAEQIoeT3NSGorXoOlgHqS/ePms9KKU7S Ik/jgFXyIMR4R6l9wtUTgJPXAliS4t/OBED0F1daOIkN+Cw4Jo3Ne70mQrIl6hAKKx5o PJSfjCAGqO4hDe8/hU9Wx37r/tgheqlJd4b4FmIbvzLxGTls4Xm/Ts+EiNeGjfirPsYy 8X/3Rvlj9xh0x11EElwiv8z43IO8VDiV2ubbbG/MU4QAW/xfn4FGeMA/7wcvEhkZcwyB bCbA== X-Gm-Message-State: AOJu0YztdznSbvOp7IVFNpIVeVoPIOq+07KgxwCGauaGw/PbEXeVm5Sz PwV1J7JitV4FJeg5Q0V6a49W0Isij1Qhf+r0kOrhAss709l2hiOyCvnfIft6wzcd9J88a0R4mzk a86VWXFmkWRDYh+aLdTdSiFWkJphf4myzrw/3q1n9mfTt11Imz9xxlnSO1f3q1la8676NzdPdgz 8IxFiVajD7/PCWLRh+tfx79HxZlS3QjDt20Ne/JfI= X-Gm-Gg: ASbGncsaEqDs2DpgAildqROZxNyaJIINKZacckZiS0MvNHawAHn9W/OjOcMh4VET+1/ vMc/Hn+8SARCHbzu1rjExMPMJ5QjJ+FO8emYxfSq89gm3kCBUikYUZyylT8bSta1dWoGPCbkwur Tq+cvrdaTDlmOA1XQAPDDiZCKlfFWedxq/e0pbmP9mhSutI+RcLYfQqnFSK9nzON+sAs09u9iFf JIE09tO9005nDaJWG6UnWG7wVd0ie93gPHyLPrgtukhYhS94scvhbfVILDOawiaBFfeVrzbe1rA knCTEVkZgMkIyfda2GXh X-Received: by 2002:a17:906:7952:b0:abb:cdca:1c08 with SMTP id a640c23a62f3a-abeeee04193mr935706366b.16.1740666029692; Thu, 27 Feb 2025 06:20:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZjEsyzbquHuhVPmRpyq7dOcfP6JQO5bBZtpIISEktuKe/oYs6IPGguM3FOyZrgD5r+CSkkQ== X-Received: by 2002:a17:906:7952:b0:abb:cdca:1c08 with SMTP id a640c23a62f3a-abeeee04193mr935703566b.16.1740666029223; Thu, 27 Feb 2025 06:20:29 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0b98e1sm129714966b.9.2025.02.27.06.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Wei Liu Subject: [PULL 16/34] target/i386/hvf: use x86_segment in x86_decode.c Date: Thu, 27 Feb 2025 15:19:34 +0100 Message-ID: <20250227141952.811410-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Wei Liu Make the code to rely on the segment definition for checking cs.db. This allows removing HVF specific VMX related definition from the decoder. Introduce a function for retrieving the CS descriptor. No functional change intended. Signed-off-by: Wei Liu Link: https://lore.kernel.org/r/1740126987-8483-4-git-send-email-liuwe@linux.microsoft.com Signed-off-by: Paolo Bonzini --- target/i386/hvf/x86_decode.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/target/i386/hvf/x86_decode.c b/target/i386/hvf/x86_decode.c index a4a28f113fd..d6d5894e54b 100644 --- a/target/i386/hvf/x86_decode.c +++ b/target/i386/hvf/x86_decode.c @@ -1893,6 +1893,16 @@ static void decode_prefix(CPUX86State *env, struct x86_decode *decode) } } +static struct x86_segment_descriptor get_cs_descriptor(CPUState *s) +{ + struct vmx_segment vmx_cs; + x86_segment_descriptor cs; + vmx_read_segment_descriptor(s, &vmx_cs, R_CS); + vmx_segment_to_x86_descriptor(s, &vmx_cs, &cs); + + return cs; +} + void set_addressing_size(CPUX86State *env, struct x86_decode *decode) { decode->addressing_size = -1; @@ -1904,10 +1914,9 @@ void set_addressing_size(CPUX86State *env, struct x86_decode *decode) } } else if (!x86_is_long_mode(env_cpu(env))) { /* protected */ - struct vmx_segment cs; - vmx_read_segment_descriptor(env_cpu(env), &cs, R_CS); + x86_segment_descriptor cs = get_cs_descriptor(env_cpu(env)); /* check db */ - if ((cs.ar >> 14) & 1) { + if (cs.db) { if (decode->addr_size_override) { decode->addressing_size = 2; } else { @@ -1941,10 +1950,9 @@ void set_operand_size(CPUX86State *env, struct x86_decode *decode) } } else if (!x86_is_long_mode(env_cpu(env))) { /* protected */ - struct vmx_segment cs; - vmx_read_segment_descriptor(env_cpu(env), &cs, R_CS); + x86_segment_descriptor cs = get_cs_descriptor(env_cpu(env)); /* check db */ - if ((cs.ar >> 14) & 1) { + if (cs.db) { if (decode->op_size_override) { decode->operand_size = 2; } else{ From patchwork Thu Feb 27 14:19:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1AA2EC19F32 for ; Thu, 27 Feb 2025 14:27:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelE-00085E-EX; Thu, 27 Feb 2025 09:21:14 -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 ) id 1tneko-0007Nm-AJ for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekk-0003ne-UB for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kREDGuRWTSnetD6IUegbVc8rafPOtZ5CPk3iVS4K+Rc=; b=X2O7nkuY0dRtzu9AyZGzW3siwUHgpLv+WO9n2lC0dSBw5MUFQmoK0PWP7Hq2cotWFbKbi2 G6czk1M+Q0zWpiNm+RVVf+xCpG188/vpGgv4mFicGDdBIDZTYZY+Mrwq4YNL4CSHD/oOQd JlU73/FQzIEVJiMBKVGT1KrAG0/Tm+g= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-323-bkBhKyI9PwuQw9XQT3k2gA-1; Thu, 27 Feb 2025 09:20:35 -0500 X-MC-Unique: bkBhKyI9PwuQw9XQT3k2gA-1 X-Mimecast-MFC-AGG-ID: bkBhKyI9PwuQw9XQT3k2gA_1740666034 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ab68fbe53a4so151935566b.2 for ; Thu, 27 Feb 2025 06:20:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666033; x=1741270833; 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=kREDGuRWTSnetD6IUegbVc8rafPOtZ5CPk3iVS4K+Rc=; b=pkuAE3D/DnctosFtRVAVVc5R8uBViDvAKVAqZinmaP504BGctPBD7cy7TDPXukwisV v9zv+du1zqZW1/+NoEX/r4T+gI+Wohu3obIONLje25vocdm/pyhY28HVMlxmwSrtJgCj paU5GfNnYPOkZzm9Gemj7MQchyTRRVxxxqPGjIt6xVefd7byMGuXQATTwLOKbu+Ra2v5 F9fSmzmsrpu2ryfn8zeMJN9By/6VhtA10eF8BjCJ2pTjYrLlBT74l2tsQuSG131PassF 9PhT6VlET667qyoaFp2xB3luRYZjLkUn8MSpLzefbJiu8hBD3h2Yga7errmDbORpFgZB lUig== X-Gm-Message-State: AOJu0YyHcRxhJWhi378YF061A8Y6BP0JdCRwqFoiuvYdhqS20byacHdq aeOle8/Yv3ffRb+oOqSanrWDx2fNPgS8HmmN/+KfuxSfhUHRx3/aILdmS2fOpSmXCOD9xRmZlLQ E6LH1whzieP2oOOR+3VnJN9K8ZjEIruds3wygOX7Yj4+ADu+huUzROd+CYzKDsNU3yx63lQr3HQ 2lvZf2hP+gnF3Aws0nZkheYzuHJWAkyp5ZY3+gaAY= X-Gm-Gg: ASbGncuub7qTyx3xZY8FmE7ysriMGWiXtbRMTCVbpnPMk9YzV4NmaydQH1FAj+Z9EzH wyqiD7+/9HEC4oA1wB4QcO3x5FhDK+1hrc8LuBjErC7xMUmmb6+F2j2RGrZNYfU8ROa6IbUFZtg FBIFEU1xwGqjfLB1yaBWEVWgjqrQfB+1gqzua3GpiMk5uEkkqJW8PHagymiku7LDz1OtGw8iGRe vfmSlEQuZxfVE4p7JLKT4mXl8iAwehtGMGnefsXK3CnBAqFneG/LXSrCWTjqSVVqa9Y82b53mY+ srEkHKh8yR0RATkgxXlb X-Received: by 2002:a17:907:2ce2:b0:ab7:d87:50f2 with SMTP id a640c23a62f3a-abed101dd89mr1442889066b.44.1740666032648; Thu, 27 Feb 2025 06:20:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFagW/zcje0zwDc9ll7PjYs3gpck6Hbc6M8vl/UAXFWCH5dqmF+rFyZNglzK7/QJE2o66H03w== X-Received: by 2002:a17:907:2ce2:b0:ab7:d87:50f2 with SMTP id a640c23a62f3a-abed101dd89mr1442883866b.44.1740666032034; Thu, 27 Feb 2025 06:20:32 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0db671sm129939766b.72.2025.02.27.06.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Wei Liu Subject: [PULL 17/34] target/i386/hvf: move and rename {load, store}_regs Date: Thu, 27 Feb 2025 15:19:35 +0100 Message-ID: <20250227141952.811410-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Wei Liu They contain HVF specific code. Move them to a better location and add "hvf_" prefix. Fix up all the call sites. No functional change. Signed-off-by: Wei Liu Link: https://lore.kernel.org/r/1740126987-8483-7-git-send-email-liuwe@linux.microsoft.com Signed-off-by: Paolo Bonzini --- target/i386/hvf/x86_emu.h | 3 -- target/i386/hvf/x86hvf.h | 3 ++ target/i386/hvf/hvf.c | 71 +++++++++++++++++++++++++++++++------- target/i386/hvf/x86_emu.c | 46 ------------------------ target/i386/hvf/x86_task.c | 4 +-- 5 files changed, 64 insertions(+), 63 deletions(-) diff --git a/target/i386/hvf/x86_emu.h b/target/i386/hvf/x86_emu.h index 8bd97608c42..cd953849c99 100644 --- a/target/i386/hvf/x86_emu.h +++ b/target/i386/hvf/x86_emu.h @@ -26,9 +26,6 @@ void init_emu(void); bool exec_instruction(CPUX86State *env, struct x86_decode *ins); -void load_regs(CPUState *cpu); -void store_regs(CPUState *cpu); - void simulate_rdmsr(CPUX86State *env); void simulate_wrmsr(CPUX86State *env); diff --git a/target/i386/hvf/x86hvf.h b/target/i386/hvf/x86hvf.h index 423a89b6ad3..8c46ce8ad02 100644 --- a/target/i386/hvf/x86hvf.h +++ b/target/i386/hvf/x86hvf.h @@ -31,4 +31,7 @@ void hvf_get_xsave(CPUState *cs); void hvf_get_msrs(CPUState *cs); void vmx_clear_int_window_exiting(CPUState *cs); void vmx_update_tpr(CPUState *cs); + +void hvf_load_regs(CPUState *cpu); +void hvf_store_regs(CPUState *cpu); #endif diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 1ecb6993ba1..3ab3c0043db 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -61,6 +61,7 @@ #include "vmx.h" #include "x86.h" #include "x86_descr.h" +#include "x86_flags.h" #include "x86_mmu.h" #include "x86_decode.h" #include "x86_emu.h" @@ -434,6 +435,52 @@ static void hvf_cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } } +void hvf_load_regs(CPUState *cs) +{ + X86CPU *cpu = X86_CPU(cs); + CPUX86State *env = &cpu->env; + + int i = 0; + RRX(env, R_EAX) = rreg(cs->accel->fd, HV_X86_RAX); + RRX(env, R_EBX) = rreg(cs->accel->fd, HV_X86_RBX); + RRX(env, R_ECX) = rreg(cs->accel->fd, HV_X86_RCX); + RRX(env, R_EDX) = rreg(cs->accel->fd, HV_X86_RDX); + RRX(env, R_ESI) = rreg(cs->accel->fd, HV_X86_RSI); + RRX(env, R_EDI) = rreg(cs->accel->fd, HV_X86_RDI); + RRX(env, R_ESP) = rreg(cs->accel->fd, HV_X86_RSP); + RRX(env, R_EBP) = rreg(cs->accel->fd, HV_X86_RBP); + for (i = 8; i < 16; i++) { + RRX(env, i) = rreg(cs->accel->fd, HV_X86_RAX + i); + } + + env->eflags = rreg(cs->accel->fd, HV_X86_RFLAGS); + rflags_to_lflags(env); + env->eip = rreg(cs->accel->fd, HV_X86_RIP); +} + +void hvf_store_regs(CPUState *cs) +{ + X86CPU *cpu = X86_CPU(cs); + CPUX86State *env = &cpu->env; + + int i = 0; + wreg(cs->accel->fd, HV_X86_RAX, RAX(env)); + wreg(cs->accel->fd, HV_X86_RBX, RBX(env)); + wreg(cs->accel->fd, HV_X86_RCX, RCX(env)); + wreg(cs->accel->fd, HV_X86_RDX, RDX(env)); + wreg(cs->accel->fd, HV_X86_RSI, RSI(env)); + wreg(cs->accel->fd, HV_X86_RDI, RDI(env)); + wreg(cs->accel->fd, HV_X86_RBP, RBP(env)); + wreg(cs->accel->fd, HV_X86_RSP, RSP(env)); + for (i = 8; i < 16; i++) { + wreg(cs->accel->fd, HV_X86_RAX + i, RRX(env, i)); + } + + lflags_to_rflags(env); + wreg(cs->accel->fd, HV_X86_RFLAGS, env->eflags); + macvm_set_rip(cs, env->eip); +} + int hvf_vcpu_exec(CPUState *cpu) { X86CPU *x86_cpu = X86_CPU(cpu); @@ -517,10 +564,10 @@ int hvf_vcpu_exec(CPUState *cpu) if (ept_emulation_fault(slot, gpa, exit_qual)) { struct x86_decode decode; - load_regs(cpu); + hvf_load_regs(cpu); decode_instruction(env, &decode); exec_instruction(env, &decode); - store_regs(cpu); + hvf_store_regs(cpu); break; } break; @@ -535,7 +582,7 @@ int hvf_vcpu_exec(CPUState *cpu) if (!string && in) { uint64_t val = 0; - load_regs(cpu); + hvf_load_regs(cpu); hvf_handle_io(env_cpu(env), port, &val, 0, size, 1); if (size == 1) { AL(env) = val; @@ -547,7 +594,7 @@ int hvf_vcpu_exec(CPUState *cpu) RAX(env) = (uint64_t)val; } env->eip += ins_len; - store_regs(cpu); + hvf_store_regs(cpu); break; } else if (!string && !in) { RAX(env) = rreg(cpu->accel->fd, HV_X86_RAX); @@ -557,11 +604,11 @@ int hvf_vcpu_exec(CPUState *cpu) } struct x86_decode decode; - load_regs(cpu); + hvf_load_regs(cpu); decode_instruction(env, &decode); assert(ins_len == decode.len); exec_instruction(env, &decode); - store_regs(cpu); + hvf_store_regs(cpu); break; } @@ -614,21 +661,21 @@ int hvf_vcpu_exec(CPUState *cpu) case EXIT_REASON_RDMSR: case EXIT_REASON_WRMSR: { - load_regs(cpu); + hvf_load_regs(cpu); if (exit_reason == EXIT_REASON_RDMSR) { simulate_rdmsr(env); } else { simulate_wrmsr(env); } env->eip += ins_len; - store_regs(cpu); + hvf_store_regs(cpu); break; } case EXIT_REASON_CR_ACCESS: { int cr; int reg; - load_regs(cpu); + hvf_load_regs(cpu); cr = exit_qual & 15; reg = (exit_qual >> 8) & 15; @@ -656,16 +703,16 @@ int hvf_vcpu_exec(CPUState *cpu) abort(); } env->eip += ins_len; - store_regs(cpu); + hvf_store_regs(cpu); break; } case EXIT_REASON_APIC_ACCESS: { /* TODO */ struct x86_decode decode; - load_regs(cpu); + hvf_load_regs(cpu); decode_instruction(env, &decode); exec_instruction(env, &decode); - store_regs(cpu); + hvf_store_regs(cpu); break; } case EXIT_REASON_TPR: { diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c index 2c7da10c1d2..8b0d54d69a0 100644 --- a/target/i386/hvf/x86_emu.c +++ b/target/i386/hvf/x86_emu.c @@ -1452,52 +1452,6 @@ static void init_cmd_handler(void) } } -void load_regs(CPUState *cs) -{ - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - - int i = 0; - RRX(env, R_EAX) = rreg(cs->accel->fd, HV_X86_RAX); - RRX(env, R_EBX) = rreg(cs->accel->fd, HV_X86_RBX); - RRX(env, R_ECX) = rreg(cs->accel->fd, HV_X86_RCX); - RRX(env, R_EDX) = rreg(cs->accel->fd, HV_X86_RDX); - RRX(env, R_ESI) = rreg(cs->accel->fd, HV_X86_RSI); - RRX(env, R_EDI) = rreg(cs->accel->fd, HV_X86_RDI); - RRX(env, R_ESP) = rreg(cs->accel->fd, HV_X86_RSP); - RRX(env, R_EBP) = rreg(cs->accel->fd, HV_X86_RBP); - for (i = 8; i < 16; i++) { - RRX(env, i) = rreg(cs->accel->fd, HV_X86_RAX + i); - } - - env->eflags = rreg(cs->accel->fd, HV_X86_RFLAGS); - rflags_to_lflags(env); - env->eip = rreg(cs->accel->fd, HV_X86_RIP); -} - -void store_regs(CPUState *cs) -{ - X86CPU *cpu = X86_CPU(cs); - CPUX86State *env = &cpu->env; - - int i = 0; - wreg(cs->accel->fd, HV_X86_RAX, RAX(env)); - wreg(cs->accel->fd, HV_X86_RBX, RBX(env)); - wreg(cs->accel->fd, HV_X86_RCX, RCX(env)); - wreg(cs->accel->fd, HV_X86_RDX, RDX(env)); - wreg(cs->accel->fd, HV_X86_RSI, RSI(env)); - wreg(cs->accel->fd, HV_X86_RDI, RDI(env)); - wreg(cs->accel->fd, HV_X86_RBP, RBP(env)); - wreg(cs->accel->fd, HV_X86_RSP, RSP(env)); - for (i = 8; i < 16; i++) { - wreg(cs->accel->fd, HV_X86_RAX + i, RRX(env, i)); - } - - lflags_to_rflags(env); - wreg(cs->accel->fd, HV_X86_RFLAGS, env->eflags); - macvm_set_rip(cs, env->eip); -} - bool exec_instruction(CPUX86State *env, struct x86_decode *ins) { /*if (hvf_vcpu_id(cs)) diff --git a/target/i386/hvf/x86_task.c b/target/i386/hvf/x86_task.c index 287fe11cf70..161217991fc 100644 --- a/target/i386/hvf/x86_task.c +++ b/target/i386/hvf/x86_task.c @@ -119,7 +119,7 @@ void vmx_handle_task_switch(CPUState *cpu, x86_segment_selector tss_sel, int rea return; } - load_regs(cpu); + hvf_load_regs(cpu); struct x86_segment_descriptor curr_tss_desc, next_tss_desc; x86_segment_selector old_tss_sel = vmx_read_segment_selector(cpu, R_TR); @@ -178,7 +178,7 @@ void vmx_handle_task_switch(CPUState *cpu, x86_segment_selector tss_sel, int rea x86_segment_descriptor_to_vmx(cpu, tss_sel, &next_tss_desc, &vmx_seg); vmx_write_segment_descriptor(cpu, &vmx_seg, R_TR); - store_regs(cpu); + hvf_store_regs(cpu); hv_vcpu_invalidate_tlb(cpu->accel->fd); } From patchwork Thu Feb 27 14:19:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DADD9C19F2E for ; Thu, 27 Feb 2025 14:28:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelq-0001JM-8O; Thu, 27 Feb 2025 09:21:50 -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 ) id 1tnekr-0007Or-QD for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekk-0003nn-Uo for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j9+wmdhWJh7eNAeDIFKf+aCQUmB7mSKSBUhZD4+88Vg=; b=bhhoFYT7bfimPMjuS1fjCfLMeDnP/z3PUS75/oVJKxwL+nMtxRO0b6r+quZIqKj/vcxAUg gCfxEZIUvRgWEy7SU5wTCruCreXUlXMT3HU9+PL5GTaovrU1O4WKbqS5Ieg5zt8zHH4GVA XsfRGBCSe5AQgwnwEfAxN96gwkUi4Do= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-198-AKn3mjsoNm-qvc_4wnQWEw-1; Thu, 27 Feb 2025 09:20:36 -0500 X-MC-Unique: AKn3mjsoNm-qvc_4wnQWEw-1 X-Mimecast-MFC-AGG-ID: AKn3mjsoNm-qvc_4wnQWEw_1740666036 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ab77e03f2c0so105740566b.3 for ; Thu, 27 Feb 2025 06:20:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666034; x=1741270834; 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=j9+wmdhWJh7eNAeDIFKf+aCQUmB7mSKSBUhZD4+88Vg=; b=dlxzjDnQbqILUHsP9Ihj1tAyP/Nbx1iuHMpjH/VLtlGl2PUyYO2P/AIysRrVKkHINJ BXzhoqGZBNWvIxlQMCUf4t4JNIEV2m0G5RIqd0aH3iwIUrp+N5VHEC/pazyzq2hjfbGQ WLIWKRmly2qg0tYs3zGad29x97RHFRrRi2YK17JYjaNXw2loB93IAM4NzUY4Rn/0HeD0 MyXkQRSNrfMj1MJP0tieVBHNNBG4cYMQkDBxbwgT/iqFqBvXv5o0eFhuoRXA+pm90fQR 1SXaMnzM6S1lG3EYcGX0JWmulOy6iTxS3D37d4dxJZxyg1aftngP4qph7v1dVSokGdRY jrAg== X-Gm-Message-State: AOJu0YyKbryxWGKNYFYbOFIHaK/qb49L3+ET/LfXiIyfu241vIquhWih LdjWtOisbn6oWs1UG+0w3toUBskjsmvpOSgWiCAstD1bLlla8TN447HTmY3hY814RZIPu7ejNM4 +/MTpjm+W+xAO9uDl3qTDf3nYYvpeF7Gi9fXU3dNNMheIqq4RnYjL4kmwmc4t0CZsprNGrPNHiE sYesH39rzM71EiB8/zG83FPKDOnYmdrRLrqK3llhg= X-Gm-Gg: ASbGnctt8+EbsII9XVOqiLnIAF0P9ECVo3s2nj0JZX+80KBZEmTs/Hb32AijunTDEJL jx9me45OZ3WBehOAZ9MfFHY5JVrl+hk6aUUBumD1afHcj2TxTGT85XRsJMZBf0E5OTwjNSMEwwq Udf2B+OreLvpIv6go8IVceSKnOQaK8zFp5NBnEVSY4WozZGlfq726nAv/g2BAdmLkIe1jGMSIwx 9yt4F7cpUI4Wt7DvGSXiX1jkUModeHwZ2MzOopDbpbOXrmXN5vyHgj2Rpvaamd5szJ6EEf+K9vI d8IyWdQeDCWtd1v5BJLS X-Received: by 2002:a17:907:6ea1:b0:ab7:f245:fbc1 with SMTP id a640c23a62f3a-abc0d97e4f9mr3167706366b.3.1740666033838; Thu, 27 Feb 2025 06:20:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3A3zPIwkuEo2Un+v8PsDyfW+6auWuI/J1AqTspj2xH0s8Og9eUOd4HvcdAdvWVV7AJ6o9Bw== X-Received: by 2002:a17:907:6ea1:b0:ab7:f245:fbc1 with SMTP id a640c23a62f3a-abc0d97e4f9mr3167700866b.3.1740666033267; Thu, 27 Feb 2025 06:20:33 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c6ee4b3sm126995466b.112.2025.02.27.06.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Wei Liu Subject: [PULL 18/34] target/i386/hvf: move and rename simulate_{rdmsr, wrmsr} Date: Thu, 27 Feb 2025 15:19:36 +0100 Message-ID: <20250227141952.811410-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Wei Liu This requires making raise_exception non-static. That function needs to be renamed to avoid clashing with a function in TCG. Mostly code movement. No functional change. Signed-off-by: Wei Liu Link: https://lore.kernel.org/r/1740126987-8483-12-git-send-email-liuwe@linux.microsoft.com Signed-off-by: Paolo Bonzini --- target/i386/hvf/hvf-i386.h | 2 + target/i386/hvf/x86_emu.h | 4 +- target/i386/hvf/hvf.c | 216 +++++++++++++++++++++++++++++++++++- target/i386/hvf/x86_emu.c | 219 +------------------------------------ 4 files changed, 220 insertions(+), 221 deletions(-) diff --git a/target/i386/hvf/hvf-i386.h b/target/i386/hvf/hvf-i386.h index 046b681d134..044ad236ae8 100644 --- a/target/i386/hvf/hvf-i386.h +++ b/target/i386/hvf/hvf-i386.h @@ -19,6 +19,8 @@ uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx, int reg); void hvf_handle_io(CPUState *, uint16_t, void *, int, int, int); +void hvf_simulate_rdmsr(CPUX86State *env); +void hvf_simulate_wrmsr(CPUX86State *env); /* Host specific functions */ int hvf_inject_interrupt(CPUArchState *env, int vector); diff --git a/target/i386/hvf/x86_emu.h b/target/i386/hvf/x86_emu.h index cd953849c99..bc0fc72c761 100644 --- a/target/i386/hvf/x86_emu.h +++ b/target/i386/hvf/x86_emu.h @@ -25,9 +25,7 @@ void init_emu(void); bool exec_instruction(CPUX86State *env, struct x86_decode *ins); - -void simulate_rdmsr(CPUX86State *env); -void simulate_wrmsr(CPUX86State *env); +void x86_emul_raise_exception(CPUX86State *env, int exception_index, int error_code); target_ulong read_reg(CPUX86State *env, int reg, int size); void write_reg(CPUX86State *env, int reg, target_ulong val, int size); diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 3ab3c0043db..9ba0e04ac75 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -481,6 +481,218 @@ void hvf_store_regs(CPUState *cs) macvm_set_rip(cs, env->eip); } +void hvf_simulate_rdmsr(CPUX86State *env) +{ + X86CPU *cpu = env_archcpu(env); + CPUState *cs = env_cpu(env); + uint32_t msr = ECX(env); + uint64_t val = 0; + + switch (msr) { + case MSR_IA32_TSC: + val = rdtscp() + rvmcs(cs->accel->fd, VMCS_TSC_OFFSET); + break; + case MSR_IA32_APICBASE: + val = cpu_get_apic_base(cpu->apic_state); + break; + case MSR_APIC_START ... MSR_APIC_END: { + int ret; + int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START; + + ret = apic_msr_read(index, &val); + if (ret < 0) { + x86_emul_raise_exception(env, EXCP0D_GPF, 0); + } + + break; + } + case MSR_IA32_UCODE_REV: + val = cpu->ucode_rev; + break; + case MSR_EFER: + val = rvmcs(cs->accel->fd, VMCS_GUEST_IA32_EFER); + break; + case MSR_FSBASE: + val = rvmcs(cs->accel->fd, VMCS_GUEST_FS_BASE); + break; + case MSR_GSBASE: + val = rvmcs(cs->accel->fd, VMCS_GUEST_GS_BASE); + break; + case MSR_KERNELGSBASE: + val = rvmcs(cs->accel->fd, VMCS_HOST_FS_BASE); + break; + case MSR_STAR: + abort(); + break; + case MSR_LSTAR: + abort(); + break; + case MSR_CSTAR: + abort(); + break; + case MSR_IA32_MISC_ENABLE: + val = env->msr_ia32_misc_enable; + break; + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + val = env->mtrr_var[(ECX(env) - MSR_MTRRphysBase(0)) / 2].base; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + val = env->mtrr_var[(ECX(env) - MSR_MTRRphysMask(0)) / 2].mask; + break; + case MSR_MTRRfix64K_00000: + val = env->mtrr_fixed[0]; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + val = env->mtrr_fixed[ECX(env) - MSR_MTRRfix16K_80000 + 1]; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + val = env->mtrr_fixed[ECX(env) - MSR_MTRRfix4K_C0000 + 3]; + break; + case MSR_MTRRdefType: + val = env->mtrr_deftype; + break; + case MSR_CORE_THREAD_COUNT: + val = cpu_x86_get_msr_core_thread_count(cpu); + break; + default: + /* fprintf(stderr, "%s: unknown msr 0x%x\n", __func__, msr); */ + val = 0; + break; + } + + RAX(env) = (uint32_t)val; + RDX(env) = (uint32_t)(val >> 32); +} + +void hvf_simulate_wrmsr(CPUX86State *env) +{ + X86CPU *cpu = env_archcpu(env); + CPUState *cs = env_cpu(env); + uint32_t msr = ECX(env); + uint64_t data = ((uint64_t)EDX(env) << 32) | EAX(env); + + switch (msr) { + case MSR_IA32_TSC: + break; + case MSR_IA32_APICBASE: { + int r; + + r = cpu_set_apic_base(cpu->apic_state, data); + if (r < 0) { + x86_emul_raise_exception(env, EXCP0D_GPF, 0); + } + + break; + } + case MSR_APIC_START ... MSR_APIC_END: { + int ret; + int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START; + + ret = apic_msr_write(index, data); + if (ret < 0) { + x86_emul_raise_exception(env, EXCP0D_GPF, 0); + } + + break; + } + case MSR_FSBASE: + wvmcs(cs->accel->fd, VMCS_GUEST_FS_BASE, data); + break; + case MSR_GSBASE: + wvmcs(cs->accel->fd, VMCS_GUEST_GS_BASE, data); + break; + case MSR_KERNELGSBASE: + wvmcs(cs->accel->fd, VMCS_HOST_FS_BASE, data); + break; + case MSR_STAR: + abort(); + break; + case MSR_LSTAR: + abort(); + break; + case MSR_CSTAR: + abort(); + break; + case MSR_EFER: + /*printf("new efer %llx\n", EFER(cs));*/ + wvmcs(cs->accel->fd, VMCS_GUEST_IA32_EFER, data); + if (data & MSR_EFER_NXE) { + hv_vcpu_invalidate_tlb(cs->accel->fd); + } + break; + case MSR_MTRRphysBase(0): + case MSR_MTRRphysBase(1): + case MSR_MTRRphysBase(2): + case MSR_MTRRphysBase(3): + case MSR_MTRRphysBase(4): + case MSR_MTRRphysBase(5): + case MSR_MTRRphysBase(6): + case MSR_MTRRphysBase(7): + env->mtrr_var[(ECX(env) - MSR_MTRRphysBase(0)) / 2].base = data; + break; + case MSR_MTRRphysMask(0): + case MSR_MTRRphysMask(1): + case MSR_MTRRphysMask(2): + case MSR_MTRRphysMask(3): + case MSR_MTRRphysMask(4): + case MSR_MTRRphysMask(5): + case MSR_MTRRphysMask(6): + case MSR_MTRRphysMask(7): + env->mtrr_var[(ECX(env) - MSR_MTRRphysMask(0)) / 2].mask = data; + break; + case MSR_MTRRfix64K_00000: + env->mtrr_fixed[ECX(env) - MSR_MTRRfix64K_00000] = data; + break; + case MSR_MTRRfix16K_80000: + case MSR_MTRRfix16K_A0000: + env->mtrr_fixed[ECX(env) - MSR_MTRRfix16K_80000 + 1] = data; + break; + case MSR_MTRRfix4K_C0000: + case MSR_MTRRfix4K_C8000: + case MSR_MTRRfix4K_D0000: + case MSR_MTRRfix4K_D8000: + case MSR_MTRRfix4K_E0000: + case MSR_MTRRfix4K_E8000: + case MSR_MTRRfix4K_F0000: + case MSR_MTRRfix4K_F8000: + env->mtrr_fixed[ECX(env) - MSR_MTRRfix4K_C0000 + 3] = data; + break; + case MSR_MTRRdefType: + env->mtrr_deftype = data; + break; + default: + break; + } + + /* Related to support known hypervisor interface */ + /* if (g_hypervisor_iface) + g_hypervisor_iface->wrmsr_handler(cs, msr, data); + + printf("write msr %llx\n", RCX(cs));*/ +} + int hvf_vcpu_exec(CPUState *cpu) { X86CPU *x86_cpu = X86_CPU(cpu); @@ -663,9 +875,9 @@ int hvf_vcpu_exec(CPUState *cpu) { hvf_load_regs(cpu); if (exit_reason == EXIT_REASON_RDMSR) { - simulate_rdmsr(env); + hvf_simulate_rdmsr(env); } else { - simulate_wrmsr(env); + hvf_simulate_wrmsr(env); } env->eip += ins_len; hvf_store_regs(cpu); diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c index 8b0d54d69a0..df815941156 100644 --- a/target/i386/hvf/x86_emu.c +++ b/target/i386/hvf/x86_emu.c @@ -661,8 +661,7 @@ static void exec_lods(CPUX86State *env, struct x86_decode *decode) env->eip += decode->len; } -static void raise_exception(CPUX86State *env, int exception_index, - int error_code) +void x86_emul_raise_exception(CPUX86State *env, int exception_index, int error_code) { env->exception_nr = exception_index; env->error_code = error_code; @@ -670,227 +669,15 @@ static void raise_exception(CPUX86State *env, int exception_index, env->exception_injected = 1; } -void simulate_rdmsr(CPUX86State *env) -{ - X86CPU *cpu = env_archcpu(env); - CPUState *cs = env_cpu(env); - uint32_t msr = ECX(env); - uint64_t val = 0; - - switch (msr) { - case MSR_IA32_TSC: - val = rdtscp() + rvmcs(cs->accel->fd, VMCS_TSC_OFFSET); - break; - case MSR_IA32_APICBASE: - val = cpu_get_apic_base(cpu->apic_state); - break; - case MSR_APIC_START ... MSR_APIC_END: { - int ret; - int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START; - - ret = apic_msr_read(index, &val); - if (ret < 0) { - raise_exception(env, EXCP0D_GPF, 0); - } - - break; - } - case MSR_IA32_UCODE_REV: - val = cpu->ucode_rev; - break; - case MSR_EFER: - val = rvmcs(cs->accel->fd, VMCS_GUEST_IA32_EFER); - break; - case MSR_FSBASE: - val = rvmcs(cs->accel->fd, VMCS_GUEST_FS_BASE); - break; - case MSR_GSBASE: - val = rvmcs(cs->accel->fd, VMCS_GUEST_GS_BASE); - break; - case MSR_KERNELGSBASE: - val = rvmcs(cs->accel->fd, VMCS_HOST_FS_BASE); - break; - case MSR_STAR: - abort(); - break; - case MSR_LSTAR: - abort(); - break; - case MSR_CSTAR: - abort(); - break; - case MSR_IA32_MISC_ENABLE: - val = env->msr_ia32_misc_enable; - break; - case MSR_MTRRphysBase(0): - case MSR_MTRRphysBase(1): - case MSR_MTRRphysBase(2): - case MSR_MTRRphysBase(3): - case MSR_MTRRphysBase(4): - case MSR_MTRRphysBase(5): - case MSR_MTRRphysBase(6): - case MSR_MTRRphysBase(7): - val = env->mtrr_var[(ECX(env) - MSR_MTRRphysBase(0)) / 2].base; - break; - case MSR_MTRRphysMask(0): - case MSR_MTRRphysMask(1): - case MSR_MTRRphysMask(2): - case MSR_MTRRphysMask(3): - case MSR_MTRRphysMask(4): - case MSR_MTRRphysMask(5): - case MSR_MTRRphysMask(6): - case MSR_MTRRphysMask(7): - val = env->mtrr_var[(ECX(env) - MSR_MTRRphysMask(0)) / 2].mask; - break; - case MSR_MTRRfix64K_00000: - val = env->mtrr_fixed[0]; - break; - case MSR_MTRRfix16K_80000: - case MSR_MTRRfix16K_A0000: - val = env->mtrr_fixed[ECX(env) - MSR_MTRRfix16K_80000 + 1]; - break; - case MSR_MTRRfix4K_C0000: - case MSR_MTRRfix4K_C8000: - case MSR_MTRRfix4K_D0000: - case MSR_MTRRfix4K_D8000: - case MSR_MTRRfix4K_E0000: - case MSR_MTRRfix4K_E8000: - case MSR_MTRRfix4K_F0000: - case MSR_MTRRfix4K_F8000: - val = env->mtrr_fixed[ECX(env) - MSR_MTRRfix4K_C0000 + 3]; - break; - case MSR_MTRRdefType: - val = env->mtrr_deftype; - break; - case MSR_CORE_THREAD_COUNT: - val = cpu_x86_get_msr_core_thread_count(cpu); - break; - default: - /* fprintf(stderr, "%s: unknown msr 0x%x\n", __func__, msr); */ - val = 0; - break; - } - - RAX(env) = (uint32_t)val; - RDX(env) = (uint32_t)(val >> 32); -} - static void exec_rdmsr(CPUX86State *env, struct x86_decode *decode) { - simulate_rdmsr(env); + hvf_simulate_rdmsr(env); env->eip += decode->len; } -void simulate_wrmsr(CPUX86State *env) -{ - X86CPU *cpu = env_archcpu(env); - CPUState *cs = env_cpu(env); - uint32_t msr = ECX(env); - uint64_t data = ((uint64_t)EDX(env) << 32) | EAX(env); - - switch (msr) { - case MSR_IA32_TSC: - break; - case MSR_IA32_APICBASE: { - int r; - - r = cpu_set_apic_base(cpu->apic_state, data); - if (r < 0) { - raise_exception(env, EXCP0D_GPF, 0); - } - - break; - } - case MSR_APIC_START ... MSR_APIC_END: { - int ret; - int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START; - - ret = apic_msr_write(index, data); - if (ret < 0) { - raise_exception(env, EXCP0D_GPF, 0); - } - - break; - } - case MSR_FSBASE: - wvmcs(cs->accel->fd, VMCS_GUEST_FS_BASE, data); - break; - case MSR_GSBASE: - wvmcs(cs->accel->fd, VMCS_GUEST_GS_BASE, data); - break; - case MSR_KERNELGSBASE: - wvmcs(cs->accel->fd, VMCS_HOST_FS_BASE, data); - break; - case MSR_STAR: - abort(); - break; - case MSR_LSTAR: - abort(); - break; - case MSR_CSTAR: - abort(); - break; - case MSR_EFER: - /*printf("new efer %llx\n", EFER(cs));*/ - wvmcs(cs->accel->fd, VMCS_GUEST_IA32_EFER, data); - if (data & MSR_EFER_NXE) { - hv_vcpu_invalidate_tlb(cs->accel->fd); - } - break; - case MSR_MTRRphysBase(0): - case MSR_MTRRphysBase(1): - case MSR_MTRRphysBase(2): - case MSR_MTRRphysBase(3): - case MSR_MTRRphysBase(4): - case MSR_MTRRphysBase(5): - case MSR_MTRRphysBase(6): - case MSR_MTRRphysBase(7): - env->mtrr_var[(ECX(env) - MSR_MTRRphysBase(0)) / 2].base = data; - break; - case MSR_MTRRphysMask(0): - case MSR_MTRRphysMask(1): - case MSR_MTRRphysMask(2): - case MSR_MTRRphysMask(3): - case MSR_MTRRphysMask(4): - case MSR_MTRRphysMask(5): - case MSR_MTRRphysMask(6): - case MSR_MTRRphysMask(7): - env->mtrr_var[(ECX(env) - MSR_MTRRphysMask(0)) / 2].mask = data; - break; - case MSR_MTRRfix64K_00000: - env->mtrr_fixed[ECX(env) - MSR_MTRRfix64K_00000] = data; - break; - case MSR_MTRRfix16K_80000: - case MSR_MTRRfix16K_A0000: - env->mtrr_fixed[ECX(env) - MSR_MTRRfix16K_80000 + 1] = data; - break; - case MSR_MTRRfix4K_C0000: - case MSR_MTRRfix4K_C8000: - case MSR_MTRRfix4K_D0000: - case MSR_MTRRfix4K_D8000: - case MSR_MTRRfix4K_E0000: - case MSR_MTRRfix4K_E8000: - case MSR_MTRRfix4K_F0000: - case MSR_MTRRfix4K_F8000: - env->mtrr_fixed[ECX(env) - MSR_MTRRfix4K_C0000 + 3] = data; - break; - case MSR_MTRRdefType: - env->mtrr_deftype = data; - break; - default: - break; - } - - /* Related to support known hypervisor interface */ - /* if (g_hypervisor_iface) - g_hypervisor_iface->wrmsr_handler(cs, msr, data); - - printf("write msr %llx\n", RCX(cs));*/ -} - static void exec_wrmsr(CPUX86State *env, struct x86_decode *decode) { - simulate_wrmsr(env); + hvf_simulate_wrmsr(env); env->eip += decode->len; } From patchwork Thu Feb 27 14:19:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994624 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB025C19F32 for ; Thu, 27 Feb 2025 14:21:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelB-0007l1-Ew; Thu, 27 Feb 2025 09:21: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 ) id 1tnekp-0007OK-1v for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekk-0003nx-Uo for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p1jc2WOXKFzU8PfCDoo9XS4Niue04Jb6wNaS0Mo76Zc=; b=K6TZW6jD8zVQSvi03zNhhps36qqS8RowlMXiLJvs9obwm1Hls0wAvpBCJdMl/ff8V0tQfL gAR0uEtq4D/CL2KCIBbiwsfvWsNl1RyYkdXAk6A/LLYkobP4isl3WaRQtVB+GuD/xeGZzX 4A6O0VOAKFET2+sPrPQQA8YjaBi/WFI= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-541-2JBPx0O5Ma6aDwmL2KHgyw-1; Thu, 27 Feb 2025 09:20:39 -0500 X-MC-Unique: 2JBPx0O5Ma6aDwmL2KHgyw-1 X-Mimecast-MFC-AGG-ID: 2JBPx0O5Ma6aDwmL2KHgyw_1740666038 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5dc5beb5eb0so760122a12.1 for ; Thu, 27 Feb 2025 06:20:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666037; x=1741270837; 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=p1jc2WOXKFzU8PfCDoo9XS4Niue04Jb6wNaS0Mo76Zc=; b=ZULiVD9PXu2T9OOvj5QtdDqnhjBfhli6ql9MToyAtGN/HGgMJ199adCf4qfF57IRK3 fll8h7jFZ+YyUkQluOH27QNAL8QuQIt3hCYCepf6hFRMgJYXBbB3Cw5us39h4BC6Yb3q plf2UxkrrDfDcus+FIb/GnesmHTjVcN4QYch7cTR+Dq0uV80V8fbUYSDY1FGVJVhHR1A /JmLWS0NCEBOoivvxDBdI7C3OybOQmokeh59dDpwYWuPbm29wPH31Bt24PYLT6gzjMj6 IRx5rU1td7w47VmQtMr+aPc0WYG7ObeDpUu3zWMYWQq2FN3C78ucErNppHaCKsIzVnIr XtSA== X-Gm-Message-State: AOJu0Yz7oJCKPO0zd4h+RjimZaH9VDaQ9HD5J+RWEHeHQ4TYnJlvg4gW ow4eVv6il9evZXQdivKiqYSfJbXxaEPVFaZApC5LwuGea0w6f0bCrUzuvyoEwfVEMqv8elN8oVM FAYyDXXSAbMkHl2jxxenkNdXnGciBAZoPAyYNUeAYiX2wrq60Fo/cnwkcsIamWja/ivNazmK+7P 6xHQ7hLYWPaE9p1mPvfHnrsfBxNwsmDz7mBBEFpG8= X-Gm-Gg: ASbGncvfLwlqRLVLryTsYC9TXvDIMKJRhqHhaU3pj1z1XZny7PeDT0eVDth25xF7JFZ +l2kJUl+HRCPVY/rVZN/9iaHz/YfEAOtpYP+/CEZg0mnkWLfu5i44P6sv0R4qfzVu0N8GCB6rcd Y55inJarGe7bAHAIL8J56EJKbDfof8vCJzfW78GgWKs0itmTTzLWvPK5IPfFpb1nX3PYhYUPNgc mdvyigepXdJp7cqENMo9yORkkRAN+MlCOsjU/aPVyxp+01xf8kOupE4p5jBbRgDEZU4yemaaV7O njjdIis2QCxzWdcihj94 X-Received: by 2002:a05:6402:1e8c:b0:5dc:a44e:7644 with SMTP id 4fb4d7f45d1cf-5e4448537c6mr27471029a12.2.1740666037387; Thu, 27 Feb 2025 06:20:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeekzDsDRoq56vyy5wcxRzuFXiLqthAQSLuboWUfkfWzEl5l81rxbtKBKgyuDpnZH456lHUg== X-Received: by 2002:a05:6402:1e8c:b0:5dc:a44e:7644 with SMTP id 4fb4d7f45d1cf-5e4448537c6mr27470942a12.2.1740666036823; Thu, 27 Feb 2025 06:20:36 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c74fbc2sm128752366b.137.2025.02.27.06.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:33 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Wei Liu Subject: [PULL 19/34] target/i386/hvf: drop some dead code Date: Thu, 27 Feb 2025 15:19:37 +0100 Message-ID: <20250227141952.811410-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Wei Liu Signed-off-by: Wei Liu Link: https://lore.kernel.org/r/1740126987-8483-16-git-send-email-liuwe@linux.microsoft.com Signed-off-by: Paolo Bonzini --- target/i386/hvf/x86_emu.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c index df815941156..ebba80a36b5 100644 --- a/target/i386/hvf/x86_emu.c +++ b/target/i386/hvf/x86_emu.c @@ -1241,10 +1241,6 @@ static void init_cmd_handler(void) bool exec_instruction(CPUX86State *env, struct x86_decode *ins) { - /*if (hvf_vcpu_id(cs)) - printf("%d, %llx: exec_instruction %s\n", hvf_vcpu_id(cs), env->eip, - decode_cmd_to_string(ins->cmd));*/ - if (!_cmd_handler[ins->cmd].handler) { printf("Unimplemented handler (%llx) for %d (%x %x) \n", env->eip, ins->cmd, ins->opcode[0], From patchwork Thu Feb 27 14:19:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4CDDC19F32 for ; Thu, 27 Feb 2025 14:21:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelj-0000io-Oh; Thu, 27 Feb 2025 09:21:44 -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 ) id 1tnekr-0007Ot-QU for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tneko-0003oQ-2M for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VMmBZwWfeUJ0S3v0Efj9vDO4/Kt8kiAMYCBrnhv0TtQ=; b=UdX+0w+WuRqtX5hQsMK9ynayCjkZIikr8auAco8tJ4ifchG+qsePEg38pBAlGw8ZJ363Pe 3Mv77cBlBiZOJxMx8f7g/cFtIA+pjxIRAHDdQ7Cz/5PuLySxwV4PSoR9VpdvijRNbVLRAX xwgaeGbQugww1FiLuTHOIza5+bjj5b4= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-26-mk5VR0o9NUyKfWUsrdcrDQ-1; Thu, 27 Feb 2025 09:20:40 -0500 X-MC-Unique: mk5VR0o9NUyKfWUsrdcrDQ-1 X-Mimecast-MFC-AGG-ID: mk5VR0o9NUyKfWUsrdcrDQ_1740666040 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5e4987b2107so1060025a12.0 for ; Thu, 27 Feb 2025 06:20:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666039; x=1741270839; 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=VMmBZwWfeUJ0S3v0Efj9vDO4/Kt8kiAMYCBrnhv0TtQ=; b=oVTkgvy9jokgOQFubeiEd3Ro80V9aMG4erF1w30RuAnuIF2x1AyrfloSB7Gn4IwLZr mptTnS2eFXTfZRlzunoILCmJJbOKrtPPrKXWmKmxKHWi9gbWiwmgr3bABnnTenPrCEdk Qbg7MkF1ZILe/UX1rrwPpXXyN3LAznJP7wrf2u4QSBCWslcV1pJ8aHmTdqtbUuxdH57Z V4OLkUkgdXNBt6EzdWEz3tQMHKNiBnnRYQ9YA37DJdTupF9hSpwpWY67jbKhFYQNDung LHa8EruT+Ken6ZxkIjOKUXTB0J5PFOSX8cPCG6InV9uYLXbu6a52EQ79YRxSk4fKbl7B Jrpw== X-Gm-Message-State: AOJu0YyYq99A1J/XlJxLl9bj8hkL9bktOMKArCxbjSYtzQ45J2w0LG0a kmSsH6P64wiq3MmHn4i/IsVQd/qP00Tx6gT5Nu6qbv/qt20LzBVmtBamQQsv6sg/R9UfTGOwMqV PHH5E37JZy0ySEEYloapMr+rouEhteQu/lNvP2zDnBfvNpX/6eI1FdBqns0B/X/Da68Sn6BHhLs UwdXKWLkka8O92cdr2kgxSRWAiEPj1jGMWj6IKFRo= X-Gm-Gg: ASbGncvJOdpb6F2NhNGVwgAG8YsBWovot2zWn2WEzmLzSqw+5J7J8oXrdvntiYkR3Bw c0zpHXa8oz7jdSYIuN4HT6qZDQhkgLrzq7ERptYlo3xFdk/MkosYtGb+4Dyh53XLGMxsOXu3AYz WMe8nyl+srQGQRhk0qJpdqhBor2wrILfRPxV7ikwg80e+LhQndHAdP/o24/O97zYxLesFEjattC qoqlB9kYRsC89NIH6LwGEbQNAnDaQiPx8sspv2A18tzY7o0EELTPh7BBgaYp6WqjefRQ2ijg7Mm yW13ITM2n59SU/ecbvG7 X-Received: by 2002:a05:6402:3483:b0:5e4:c522:51cd with SMTP id 4fb4d7f45d1cf-5e4c5225c72mr2888192a12.20.1740666038596; Thu, 27 Feb 2025 06:20:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdxIZkrf6vaXaGryO1U5cLNzE8R58b3C28wriZ9epCFj4Y53ya5Cbw65qd+d7rpqyN7rr1+g== X-Received: by 2002:a05:6402:3483:b0:5e4:c522:51cd with SMTP id 4fb4d7f45d1cf-5e4c5225c72mr2888153a12.20.1740666037999; Thu, 27 Feb 2025 06:20:37 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c3bb733asm1152112a12.38.2025.02.27.06.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 20/34] rust: add IsA bounds to QOM implementation traits Date: Thu, 27 Feb 2025 15:19:38 +0100 Message-ID: <20250227141952.811410-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Check that the right bounds are provided to the qom_isa! macro whenever the class is defined to implement a certain class. This removes the need to add IsA<> bounds together with the *Impl trait bounds. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/qdev.rs | 2 +- rust/qemu-api/src/qom.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs index 3a7aa4def62..c4dd26b582c 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/qemu-api/src/qdev.rs @@ -86,7 +86,7 @@ pub trait ResettablePhasesImpl { } /// Trait providing the contents of [`DeviceClass`]. -pub trait DeviceImpl: ObjectImpl + ResettablePhasesImpl { +pub trait DeviceImpl: ObjectImpl + ResettablePhasesImpl + IsA { /// _Realization_ is the second stage of device creation. It contains /// all operations that depend on device properties and can fail (note: /// this is not yet supported for Rust devices). diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs index 3d5ab2d9018..10ce359becb 100644 --- a/rust/qemu-api/src/qom.rs +++ b/rust/qemu-api/src/qom.rs @@ -37,6 +37,8 @@ //! * a trait for virtual method implementations, for example `DeviceImpl`. //! Child classes implement this trait to provide their own behavior for //! virtual methods. The trait's methods take `&self` to access instance data. +//! The traits have the appropriate specialization of `IsA<>` as a supertrait, +//! for example `IsA` for `DeviceImpl`. //! //! * an implementation of [`ClassInitImpl`], for example //! `ClassInitImpl`. This fills the vtable in the class struct; @@ -497,7 +499,7 @@ impl ObjectDeref for &mut T {} impl ObjectCastMut for &mut T {} /// Trait a type must implement to be registered with QEMU. -pub trait ObjectImpl: ObjectType + ClassInitImpl { +pub trait ObjectImpl: ObjectType + ClassInitImpl + IsA { /// The parent of the type. This should match the first field of the /// struct that implements `ObjectImpl`, minus the `ParentField<_>` wrapper. type ParentType: ObjectType; From patchwork Thu Feb 27 14:19:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B80FC1B0FF for ; Thu, 27 Feb 2025 14:29:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelU-0008CI-4Z; Thu, 27 Feb 2025 09:21:28 -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 ) id 1tnekr-0007Ou-SZ for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tneko-0003oU-1V for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w5tiPQV4FLbVxra6ghak4CioHmf6+RCo+QEbLhSZJd4=; b=Qn8DgNNz5+1x4meZOc4yGYyd65m62XN5caK+kufH0GxiftwRnMDeOhhZ2zfMVe6LZcHdsi 70UVJUyk0bDm2D/wGa/lQ+Ds1FK2f6ZhRzSCgFGB82j8rPpoxenbKn7pkOVnaqFwinGhOW /lj0sMX5OfiwPGbd76VZxSybMnHcHV8= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-Sw-MAk7nMGa61r4UEhPhyw-1; Thu, 27 Feb 2025 09:20:43 -0500 X-MC-Unique: Sw-MAk7nMGa61r4UEhPhyw-1 X-Mimecast-MFC-AGG-ID: Sw-MAk7nMGa61r4UEhPhyw_1740666041 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ab39f65dc10so106199166b.1 for ; Thu, 27 Feb 2025 06:20:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666040; x=1741270840; 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=w5tiPQV4FLbVxra6ghak4CioHmf6+RCo+QEbLhSZJd4=; b=w4u+ppRGAy+rZiqluE1UtS6nYYnWdckA+De9zzcSTqVSZrhG7fwZAuaH3MVy4mnnLr eVJsUs2Lpf3TkF4WYtaG9qEFvI92ERElDVPZbL32guHxkj327j7UfObZvPmTbpFe/NQt rz/QtJDcBN35LpBHOKlwm7pHQwaWScEY3jzBDXSmfCF4BEd+WIKAj/pxBiSxw7Fq14bR CFCyGzamMF1hRmIjLgAoR/NIEY2KhjPIxp4u0rYyghN3YIYdnKXjUVQ1R+uW+55R2khk 5/gOfg0dnQgPg7bOy88KSiWrZr0TAu+OqhNYfJuN3F80PEeGtCr9/wqGKcOQxAtONfDE TTEQ== X-Gm-Message-State: AOJu0YyVK+zs9u7ZrHMqpjPNxCEKCXBf/lzFMyC/O4Agzy9Q8YVfxDjx 5ZiS4ikbKU+HA6/AXraASKz9dJ1hn/QdzBix1z46Vk0hmKl4VMDBCLVoQWZBcYzgqpw1vL11zQW yVOi3YksYNzSCjqnz8ZSNrFj+0BZ4WG0k4eYKOeu4q2uQyGI+9JONgAqLlkZRuEcYeWxaSqcz8D 24lzypM06MthY6tkRlHtPPGPRkNlzteMYEBvhHLOI= X-Gm-Gg: ASbGncuQglgLUE3ddREDnjjaKXiyB7j3llS9LENRtA1FYRRVpn3gXzcHC7YHPSgyEw1 BjfQiUmW8AbnX6KBqkyMQpqB9M90bG4nhahNpqH8V1RUYlojpTk7Mh52Bg4YNjNk8lqsSBKq0aT 9nJzc0QKXor2c27s3U756XWxTY5BlUYpLiNQG/7xnntebz2r+ZTUOWZ8LNg5SWrVUfyaVHxuyyU 0BxNKoMFXNvugzEXKwtVR87fZ1FpbqAZTkijaLHcySy2jraK+KL3UhHhaP6sE+Ly43cZswpuDte hokVO/nO2pvuDCi45pM+ X-Received: by 2002:a17:907:7fa6:b0:abe:c8ff:32a7 with SMTP id a640c23a62f3a-abed0db724fmr1443989466b.31.1740666039622; Thu, 27 Feb 2025 06:20:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcMSb6n5Zcu3jgk9dUkGkCUYM7m5rg1FYPOE8oahP9/0LN8kLAOJrNfIXPTntJzwieBIUUow== X-Received: by 2002:a17:907:7fa6:b0:abe:c8ff:32a7 with SMTP id a640c23a62f3a-abed0db724fmr1443985766b.31.1740666039183; Thu, 27 Feb 2025 06:20:39 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc150sm131297766b.61.2025.02.27.06.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 21/34] rust: add SysBusDeviceImpl Date: Thu, 27 Feb 2025 15:19:39 +0100 Message-ID: <20250227141952.811410-22-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The only function, right now, is to ensure that anything with a SysBusDeviceClass class is a SysBusDevice. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 5 ++++- rust/hw/timer/hpet/src/hpet.rs | 4 +++- rust/qemu-api/src/sysbus.rs | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 59a689fdcd7..bea9723aed8 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -20,7 +20,7 @@ prelude::*, qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl}, qom::{ClassInitImpl, ObjectImpl, Owned, ParentField}, - sysbus::{SysBusDevice, SysBusDeviceClass}, + sysbus::{SysBusDevice, SysBusDeviceClass, SysBusDeviceImpl}, vmstate::VMStateDescription, }; @@ -176,6 +176,8 @@ impl ResettablePhasesImpl for PL011State { const HOLD: Option = Some(Self::reset_hold); } +impl SysBusDeviceImpl for PL011State {} + impl PL011Registers { pub(self) fn read(&mut self, offset: RegisterOffset) -> (bool, u32) { use RegisterOffset::*; @@ -746,3 +748,4 @@ impl ObjectImpl for PL011Luminary { impl DeviceImpl for PL011Luminary {} impl ResettablePhasesImpl for PL011Luminary {} +impl SysBusDeviceImpl for PL011Luminary {} diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index 75ff5b3e8d6..b4ffccf815f 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -23,7 +23,7 @@ qdev::{DeviceImpl, DeviceMethods, DeviceState, Property, ResetType, ResettablePhasesImpl}, qom::{ObjectImpl, ObjectType, ParentField}, qom_isa, - sysbus::SysBusDevice, + sysbus::{SysBusDevice, SysBusDeviceImpl}, timer::{Timer, CLOCK_VIRTUAL}, }; @@ -887,3 +887,5 @@ fn properties() -> &'static [Property] { impl ResettablePhasesImpl for HPETState { const HOLD: Option = Some(Self::reset_hold); } + +impl SysBusDeviceImpl for HPETState {} diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs index fa36e12178f..fee2e3d478f 100644 --- a/rust/qemu-api/src/sysbus.rs +++ b/rust/qemu-api/src/sysbus.rs @@ -14,7 +14,7 @@ irq::{IRQState, InterruptSource}, memory::MemoryRegion, prelude::*, - qdev::{DeviceClass, DeviceState}, + qdev::{DeviceClass, DeviceImpl, DeviceState}, qom::{ClassInitImpl, Owned}, }; @@ -25,10 +25,12 @@ unsafe impl ObjectType for SysBusDevice { } qom_isa!(SysBusDevice: DeviceState, Object); -// TODO: add SysBusDeviceImpl +// TODO: add virtual methods +pub trait SysBusDeviceImpl: DeviceImpl + IsA {} + impl ClassInitImpl for T where - T: ClassInitImpl, + T: SysBusDeviceImpl + ClassInitImpl, { fn class_init(sdc: &mut SysBusDeviceClass) { >::class_init(&mut sdc.parent_class); From patchwork Thu Feb 27 14:19:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994628 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D842C19F2E for ; Thu, 27 Feb 2025 14:23:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelD-000824-5s; Thu, 27 Feb 2025 09:21: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 ) id 1tnekr-0007Ov-SZ for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tneko-0003ot-Ry for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q60znN5LHGAuKN5cvbnnTxdVSjdEKcjfrdyADjSGY/8=; b=CuEdutb1711u8Kd3/FC70iq/I4Ta2RrUT6FTRRdQFbKpWwuBC6gr9P5Cd1xAio8vRcglli c8MWMGR/DA+NFA8DWtyIGuW5xuLQ6I5v94pZa4os+43hKma5MeM9StdKTwaBnh7QkVEls7 2Io2cvH9ErfHHNDWSePOiz8K8Iq4F0k= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-5RawHmHOPJeZUdNtRaqPPw-1; Thu, 27 Feb 2025 09:20:44 -0500 X-MC-Unique: 5RawHmHOPJeZUdNtRaqPPw-1 X-Mimecast-MFC-AGG-ID: 5RawHmHOPJeZUdNtRaqPPw_1740666044 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-abbb44abae6so103500366b.1 for ; Thu, 27 Feb 2025 06:20:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666043; x=1741270843; 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=q60znN5LHGAuKN5cvbnnTxdVSjdEKcjfrdyADjSGY/8=; b=nR8ysKzKX0whsC92Bxi1ZP6OEWes+Wbqdk1gJP4C03A9hwHtmIqtjJydVljVQ6MWre Qqb5BE0byw0TICAS8QRbb4BD/wD83sTE+DOLADC3lJVt+IbnZ2AWes66XJ2O354Mvmxn yYBy5HkkkqWEjwumTpeU/dQcTUWvsU47CEdQ96rdh4kV0+EtVZOw+boDqb45QRJF8XiY 2z7yMPZ6VfZi4F/jLKxXdBQXKgugU6cJZ0TfrMW9aYLKsuP76wFYszoz/CWFlHjI2En1 Ek6BcNhjoyU/qEJrxSvp1GOtmpt6ucTwFSfrKhHsfRGq7u6boyx974L4pbzCPxkER5Za XHAA== X-Gm-Message-State: AOJu0YxjDCWUq3nAuDvzy98zCHt2f2YQn7MfGGsDn+0TcA7Rvxgh93Fr DkbCmPqqlXvErSH1Rh+9pbFvmqJ/gQn/K/1kikUFMmE922A6TMSsUtq2KMhQIKlhoixZgdfn+ZB 1ecUfztS3zemJjdeU/brZFNJTyX/SG8acuXV6QMz6z6IEmz71aMF8OXP2cOgx1SrisgtGYFOfgG aWEbE2oqAYSCJ+qlLdKmS6xhRlvpscoKfyWxAn8vg= X-Gm-Gg: ASbGncv4ezNP8CQRMvRxu755IKx30AYuBd7KLA6oWB2voamd8VulKabAwZo3lsMOEt3 LO9nkeDj5/ZKU6M1hwRoZUaW45nhoAQ68q6Aait5pAsAlRg6vt06FtHN2u0/caNF4dyW6Mz5LVB 0+xKxaa2RaW0r3KMPmGOVIWnEzzaU5HiFGOso19sD302Sp6fJk6fDz20c418WwuvxPXWwwbdmc7 AC17zwnRT7ebG7WXbITsZ2z+oZmElKbyLNo2Q5Bj3D35VOvtdsnJ84KYjLVmrkMWImTMOyKEE/4 0dYSwPgTqFYiJTy8XqC4 X-Received: by 2002:a17:907:7d89:b0:ab7:6bb3:b14b with SMTP id a640c23a62f3a-abc0da33611mr3300699166b.30.1740666042779; Thu, 27 Feb 2025 06:20:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFb1bHwxk1EffUFOzZVieNJknGQA3xXnKmKjwXesUr64bD662hrJtfxu4y5jpFLM/XDlaNRww== X-Received: by 2002:a17:907:7d89:b0:ab7:6bb3:b14b with SMTP id a640c23a62f3a-abc0da33611mr3300695766b.30.1740666042282; Thu, 27 Feb 2025 06:20:42 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c75c333sm130592566b.145.2025.02.27.06.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 22/34] rust: qom: add ObjectImpl::CLASS_INIT Date: Thu, 27 Feb 2025 15:19:40 +0100 Message-ID: <20250227141952.811410-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org As shown in the PL011 device, the orphan rules required a manual implementation of ClassInitImpl for anything not in the qemu_api crate; this gets in the way of moving system emulation-specific code (including DeviceClass, which as a blanket ClassInitImpl implementation) into its own crate. Make ClassInitImpl optional, at the cost of having to specify the CLASS_INIT member by hand in every implementation of ObjectImpl. The next commits will get rid of it, replacing all the "impl ClassInitImpl for T" blocks with a generic class_init method on Class. Right now the definition is always the same, but do not provide a default as that will not be true once ClassInitImpl goes away. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 3 +++ rust/hw/timer/hpet/src/hpet.rs | 3 ++- rust/qemu-api/src/qom.rs | 14 +++++++++++--- rust/qemu-api/tests/tests.rs | 3 +++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index bea9723aed8..ead361b3f52 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -160,6 +160,7 @@ impl ObjectImpl for PL011State { const INSTANCE_INIT: Option = Some(Self::init); const INSTANCE_POST_INIT: Option = Some(Self::post_init); + const CLASS_INIT: fn(&mut Self::Class) = >::class_init; } impl DeviceImpl for PL011State { @@ -744,6 +745,8 @@ unsafe impl ObjectType for PL011Luminary { impl ObjectImpl for PL011Luminary { type ParentType = PL011State; + + const CLASS_INIT: fn(&mut Self::Class) = >::class_init; } impl DeviceImpl for PL011Luminary {} diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index b4ffccf815f..e01b4b67064 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -21,7 +21,7 @@ }, prelude::*, qdev::{DeviceImpl, DeviceMethods, DeviceState, Property, ResetType, ResettablePhasesImpl}, - qom::{ObjectImpl, ObjectType, ParentField}, + qom::{ClassInitImpl, ObjectImpl, ObjectType, ParentField}, qom_isa, sysbus::{SysBusDevice, SysBusDeviceImpl}, timer::{Timer, CLOCK_VIRTUAL}, @@ -836,6 +836,7 @@ impl ObjectImpl for HPETState { const INSTANCE_INIT: Option = Some(Self::init); const INSTANCE_POST_INIT: Option = Some(Self::post_init); + const CLASS_INIT: fn(&mut Self::Class) = >::class_init; } // TODO: Make these properties user-configurable! diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs index 10ce359becb..d821ac25acc 100644 --- a/rust/qemu-api/src/qom.rs +++ b/rust/qemu-api/src/qom.rs @@ -180,7 +180,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { T::INSTANCE_POST_INIT.unwrap()(unsafe { state.as_ref() }); } -unsafe extern "C" fn rust_class_init>( +unsafe extern "C" fn rust_class_init( klass: *mut ObjectClass, _data: *mut c_void, ) { @@ -190,7 +190,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { // SAFETY: klass is a T::Class, since rust_class_init // is called from QOM core as the class_init function // for class T - T::class_init(unsafe { klass.as_mut() }) + ::CLASS_INIT(unsafe { klass.as_mut() }) } unsafe extern "C" fn drop_object(obj: *mut Object) { @@ -499,7 +499,7 @@ impl ObjectDeref for &mut T {} impl ObjectCastMut for &mut T {} /// Trait a type must implement to be registered with QEMU. -pub trait ObjectImpl: ObjectType + ClassInitImpl + IsA { +pub trait ObjectImpl: ObjectType + IsA { /// The parent of the type. This should match the first field of the /// struct that implements `ObjectImpl`, minus the `ParentField<_>` wrapper. type ParentType: ObjectType; @@ -552,6 +552,14 @@ pub trait ObjectImpl: ObjectType + ClassInitImpl + IsA { // methods on ObjectClass const UNPARENT: Option = None; + + /// Store into the argument the virtual method implementations + /// for `Self`. On entry, the virtual method pointers are set to + /// the default values coming from the parent classes; the function + /// can change them to override virtual methods of a parent class. + /// + /// Usually defined as `::class_init`. + const CLASS_INIT: fn(&mut Self::Class); } /// Internal trait used to automatically fill in a class struct. diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 03569e4a44c..9546e9d7963 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -60,6 +60,7 @@ unsafe impl ObjectType for DummyState { impl ObjectImpl for DummyState { type ParentType = DeviceState; const ABSTRACT: bool = false; + const CLASS_INIT: fn(&mut DummyClass) = >::class_init; } impl ResettablePhasesImpl for DummyState {} @@ -102,6 +103,8 @@ unsafe impl ObjectType for DummyChildState { impl ObjectImpl for DummyChildState { type ParentType = DummyState; const ABSTRACT: bool = false; + const CLASS_INIT: fn(&mut DummyChildClass) = + >::class_init; } impl ResettablePhasesImpl for DummyChildState {} From patchwork Thu Feb 27 14:19:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6912C19F2E for ; Thu, 27 Feb 2025 14:31:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelV-00008E-VN; Thu, 27 Feb 2025 09:21:30 -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 ) id 1tnekt-0007Pr-9d for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekr-0003pE-GP for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L7GGVBmZG7ZF98LfqMdeaCfIRAIPw9igfsvGxUYuvdQ=; b=E3MA2cHlJzNyENALgjX+wwBDom++XQbN6TBNlFkkpK/+5JjWAX/wuLSPUOOa9MkeTb95Go W1t35g4zfvafDk3dZ+pIPNuNvzoZz0U+kFqo1jI6W0b/+nN6ABzZiJK04h2q9Ntr2n928T eaaLkmn5i78A0y9pPCKo2T/qy5e9Cus= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-388-ugWjiPUGMtuIjEnEo2Ox5A-1; Thu, 27 Feb 2025 09:20:46 -0500 X-MC-Unique: ugWjiPUGMtuIjEnEo2Ox5A-1 X-Mimecast-MFC-AGG-ID: ugWjiPUGMtuIjEnEo2Ox5A_1740666045 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-abbb6fa430fso70450366b.3 for ; Thu, 27 Feb 2025 06:20:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666044; x=1741270844; 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=L7GGVBmZG7ZF98LfqMdeaCfIRAIPw9igfsvGxUYuvdQ=; b=MsxlQOv03XwGJX4b90g/frDgyE5x6JCJcSLYUbE6AO8C9iTGIx/FyorkNBNT2F30hx Jhs5nUbcPvDcJpq6aK7eToHg6foRLPbDKYHznfX7mNOPC6Z1D77WN3AA5wFhGLboOX1t Q+DIcBzWdT04awMScMt4REg//36BXalGTKZujCfgsvUMcgFrQRh6EkQ9f0aONVppXBVr zkoKxgf6+4KeBgrvaC16Eb45Awl5vwN/qJQTT0aXbBFtKyY/BqvaEXYthSmsN+gQmr1x WE9laGtABGBh4i506s6AmkC7+w4xmSVne6TWp92cMVOaCGMJLEutVXKal6TqiWVtAT7c j3Ng== X-Gm-Message-State: AOJu0Yz9TKpqiC6ny6mPCKlPh2yIIXv9m1HkRqx4+M9Y9ZUIrpswuFoJ tsYr00bXOrK2kprbv2pT0z1EVjnYwu5SPyVeHMjNcU3c3KRwPwiVrkNXSG/UbXR1+hqarSkWnZy m1pxu3DoO2UU4F3OR4Qi3rd5/y4tZMQg3BOL5T5KtfUuxwXlqiwhDEoGkeHB7tITK4AT/X7sYA2 qIxthkWg7D9XJq7vAu9DfNPutFiPcELUlSRXmBQfc= X-Gm-Gg: ASbGncsH1qKZZdn+4Lppt6GwWqio9UAoz3M84dz4Nnl/nU3K8reL9wnEtyndD/lolvk Ap5MCxoOZf9B7ocGn6DcqbWwUEepAucccAdYEhs95/LjYvOhDYSaOLLzC+VSVLvQVLZ6e9PJWck 5hoVRm4hkrIbqHPprKyeK1izCVHxVaUHsBZZ0+/WobYOKlpzvIsGfZ1mefbDafzA7TLeZXbqmED VMQK6SIWIMaSSQzqXY/2YzV5ZiILK90Y2zv3DaQHpkW+Nv09xk5hos3Db22xk0T1FtU2qkkhD/i GrwNdo3o7EjEnbgeaCg8 X-Received: by 2002:a05:6402:42c3:b0:5de:dfde:c8b1 with SMTP id 4fb4d7f45d1cf-5e444853739mr30916757a12.4.1740666044079; Thu, 27 Feb 2025 06:20:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEwHF5s+2czzZF4i+g5uC8ZIvIPzvxMVtRvVmvQf1ifmOd2a2Ary/406iyFDTqANlGIppsrA== X-Received: by 2002:a05:6402:42c3:b0:5de:dfde:c8b1 with SMTP id 4fb4d7f45d1cf-5e444853739mr30916682a12.4.1740666043562; Thu, 27 Feb 2025 06:20:43 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0b9961sm132113566b.10.2025.02.27.06.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:43 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 23/34] rust: pl011, qemu_api tests: do not use ClassInitImpl Date: Thu, 27 Feb 2025 15:19:41 +0100 Message-ID: <20250227141952.811410-24-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Outside the qemu_api crate, orphan rules make the usage of ClassInitImpl unwieldy. Now that it is optional, do not use it. For PL011Class, this makes it easier to provide a PL011Impl trait similar to the ones in the qemu_api crate. The device id consts are moved there. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 38 ++++++++++++++++---------------- rust/qemu-api/tests/tests.rs | 33 ++++++++++----------------- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index ead361b3f52..094049cb9e6 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -50,11 +50,6 @@ fn index(&self, idx: hwaddr) -> &Self::Output { } } -impl DeviceId { - const ARM: Self = Self(&[0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1]); - const LUMINARY: Self = Self(&[0x11, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x05, 0xb1]); -} - // FIFOs use 32-bit indices instead of usize, for compatibility with // the migration stream produced by the C version of this device. #[repr(transparent)] @@ -143,16 +138,24 @@ pub struct PL011Class { device_id: DeviceId, } +trait PL011Impl: SysBusDeviceImpl + IsA { + const DEVICE_ID: DeviceId; +} + +impl PL011Class { + fn class_init(&mut self) { + self.device_id = T::DEVICE_ID; + >::class_init(&mut self.parent_class); + } +} + unsafe impl ObjectType for PL011State { type Class = PL011Class; const TYPE_NAME: &'static CStr = crate::TYPE_PL011; } -impl ClassInitImpl for PL011State { - fn class_init(klass: &mut PL011Class) { - klass.device_id = DeviceId::ARM; - >::class_init(&mut klass.parent_class); - } +impl PL011Impl for PL011State { + const DEVICE_ID: DeviceId = DeviceId(&[0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1]); } impl ObjectImpl for PL011State { @@ -160,7 +163,7 @@ impl ObjectImpl for PL011State { const INSTANCE_INIT: Option = Some(Self::init); const INSTANCE_POST_INIT: Option = Some(Self::post_init); - const CLASS_INIT: fn(&mut Self::Class) = >::class_init; + const CLASS_INIT: fn(&mut Self::Class) = Self::Class::class_init::; } impl DeviceImpl for PL011State { @@ -729,13 +732,6 @@ pub struct PL011Luminary { parent_obj: ParentField, } -impl ClassInitImpl for PL011Luminary { - fn class_init(klass: &mut PL011Class) { - klass.device_id = DeviceId::LUMINARY; - >::class_init(&mut klass.parent_class); - } -} - qom_isa!(PL011Luminary : PL011State, SysBusDevice, DeviceState, Object); unsafe impl ObjectType for PL011Luminary { @@ -746,7 +742,11 @@ unsafe impl ObjectType for PL011Luminary { impl ObjectImpl for PL011Luminary { type ParentType = PL011State; - const CLASS_INIT: fn(&mut Self::Class) = >::class_init; + const CLASS_INIT: fn(&mut Self::Class) = Self::Class::class_init::; +} + +impl PL011Impl for PL011Luminary { + const DEVICE_ID: DeviceId = DeviceId(&[0x11, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x05, 0xb1]); } impl DeviceImpl for PL011Luminary {} diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 9546e9d7963..93c5637bbc3 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -13,7 +13,7 @@ cell::{self, BqlCell}, declare_properties, define_property, prelude::*, - qdev::{DeviceClass, DeviceImpl, DeviceState, Property, ResettablePhasesImpl}, + qdev::{DeviceImpl, DeviceState, Property, ResettablePhasesImpl}, qom::{ClassInitImpl, ObjectImpl, ParentField}, sysbus::SysBusDevice, vmstate::VMStateDescription, @@ -41,6 +41,12 @@ pub struct DummyClass { parent_class: ::Class, } +impl DummyClass { + pub fn class_init(self: &mut DummyClass) { + >::class_init(&mut self.parent_class); + } +} + declare_properties! { DUMMY_PROPERTIES, define_property!( @@ -60,7 +66,7 @@ unsafe impl ObjectType for DummyState { impl ObjectImpl for DummyState { type ParentType = DeviceState; const ABSTRACT: bool = false; - const CLASS_INIT: fn(&mut DummyClass) = >::class_init; + const CLASS_INIT: fn(&mut DummyClass) = DummyClass::class_init::; } impl ResettablePhasesImpl for DummyState {} @@ -74,14 +80,6 @@ fn vmsd() -> Option<&'static VMStateDescription> { } } -// `impl ClassInitImpl for T` doesn't work since it violates -// orphan rule. -impl ClassInitImpl for DummyState { - fn class_init(klass: &mut DummyClass) { - >::class_init(&mut klass.parent_class); - } -} - #[derive(qemu_api_macros::offsets)] #[repr(C)] #[derive(qemu_api_macros::Object)] @@ -103,22 +101,15 @@ unsafe impl ObjectType for DummyChildState { impl ObjectImpl for DummyChildState { type ParentType = DummyState; const ABSTRACT: bool = false; - const CLASS_INIT: fn(&mut DummyChildClass) = - >::class_init; + const CLASS_INIT: fn(&mut DummyChildClass) = DummyChildClass::class_init::; } impl ResettablePhasesImpl for DummyChildState {} impl DeviceImpl for DummyChildState {} -impl ClassInitImpl for DummyChildState { - fn class_init(klass: &mut DummyClass) { - >::class_init(&mut klass.parent_class); - } -} - -impl ClassInitImpl for DummyChildState { - fn class_init(klass: &mut DummyChildClass) { - >::class_init(&mut klass.parent_class); +impl DummyChildClass { + pub fn class_init(self: &mut DummyChildClass) { + self.parent_class.class_init::(); } } From patchwork Thu Feb 27 14:19:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994680 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50BD7C19F2E for ; Thu, 27 Feb 2025 14:31:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelb-0000XB-Ub; Thu, 27 Feb 2025 09:21:37 -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 ) id 1tnekz-0007bs-1f for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekt-0003ps-Rg for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qmdmd+wL1XBTd0QsgGEcFsO/eGydgDAort0AQ7Nq3Cg=; b=bva3h58GyCs3joj2fQ0T5HVjK5BK4roJ5gM4tnYCF4kSX6tek0DYRlP+xHIxGp/oFOvTUW EN2Gq7zy4sb7X3qmFAI3GzyHL1W4iSDCPcjsEFL3wRuC66IK5ryZBrJY8EIlMZxjetZS8Z 5fJLL7n6WqUQoSHiTIQ8P+f2l+sc7g8= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-79-W8QcDvCFMS2AUMicQYZAcA-1; Thu, 27 Feb 2025 09:20:49 -0500 X-MC-Unique: W8QcDvCFMS2AUMicQYZAcA-1 X-Mimecast-MFC-AGG-ID: W8QcDvCFMS2AUMicQYZAcA_1740666049 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5de5172cc5bso918655a12.0 for ; Thu, 27 Feb 2025 06:20:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666048; x=1741270848; 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=Qmdmd+wL1XBTd0QsgGEcFsO/eGydgDAort0AQ7Nq3Cg=; b=QrSk9W1o3B/Bay7hym+9slAsDa04dVRwXO67sQYDAorVgGWWfomJSNx2ozAe76gonr kfmeLi7BvjqkiBVPfXeX7X4HOF9U2M5Fdi1Nh6kY97qGMLEyX1kT4iDb7aztUx60aElM 1DFJNbxSbjnGohJeFKJoW1n5nADxvAj2Aem+JqO4wsEpl2zSSFOu9Uq993Y/6uvPBawd dtNLhbPjiyRr4feRuowS1agXS/IHWemWkDL7wCq+yqBtwe855qbLjtDJDaADTNdtKhc7 DcoQfom3KYETb7qPbnzH0FQ8qtlBKevbPx5WAr40tCMSbInd42ZzhCEQBUATWRZWdkLz mwCg== X-Gm-Message-State: AOJu0YzZvdJdzYzcTZZYYSD3kJ+v89NJdc5SL8nWxQJL9RcHPxumjstZ MduZ54C8N7/fk073NX5ygCmoLze29cFXmcXWQT1GDlGui3yXD2T3aqnbDK4hlL5KtesEidknoMb sBfL6vPM5WZYM4/33XWFUGWCk+YLr4+SEV2c5UJ59Yta0eAc0BFU7J/bFkxG8hAsiPSgSm3Jwfl zPDQj7hoTcLGo4n1beHMMbjgS0BfO49iE+q5ePF0Y= X-Gm-Gg: ASbGncuzmVfwoxoPv0MZ2m8g7C7p3izjedn8Yu19T+NxrCti/YXKAXOOPvgjmF5L8qX vx7bMjZAY0k2ILulcSl/jXdI6Ul4fSbICpawhV3jZTG66XVrPwRRYvTStolzqU3Z8fO+0+jzd4M EJRF8bg7dhL7eL7AA9KWwc2fAYpXggRnPi8aAIFu1XvfXRX7ZW2FiQuuGvRtJWJvd6l1f4RpVVC Q9XQZkWZQoYosyMSvzoE4CxcddtQHIEILH2xhezz26Is53MjB8GiNh50OBQckT7kuWq1isbXFUT qRzhL9OcAhiRMLprCOv+ X-Received: by 2002:a05:6402:524f:b0:5dc:5ada:e0c7 with SMTP id 4fb4d7f45d1cf-5e44a256c98mr29401273a12.26.1740666047551; Thu, 27 Feb 2025 06:20:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgoBTCfCzjELF+/8A5x3OoVRzl075bsimUN6iERAAzPqkkWzLwS32RmGxHgy73WV86TD7qiA== X-Received: by 2002:a05:6402:524f:b0:5dc:5ada:e0c7 with SMTP id 4fb4d7f45d1cf-5e44a256c98mr29401184a12.26.1740666046820; Thu, 27 Feb 2025 06:20:46 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c7c083esm130186666b.175.2025.02.27.06.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:44 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 24/34] rust: qom: get rid of ClassInitImpl Date: Thu, 27 Feb 2025 15:19:42 +0100 Message-ID: <20250227141952.811410-25-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Complete the conversion from the ClassInitImpl trait to class_init() methods. This will provide more freedom to split the qemu_api crate in separate parts. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 6 +- rust/hw/timer/hpet/src/hpet.rs | 4 +- rust/qemu-api/src/qdev.rs | 38 ++++--- rust/qemu-api/src/qom.rs | 164 +++++++++++++------------------ rust/qemu-api/src/sysbus.rs | 15 ++- rust/qemu-api/tests/tests.rs | 4 +- 6 files changed, 101 insertions(+), 130 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 094049cb9e6..d0857b470c9 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -19,8 +19,8 @@ memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder}, prelude::*, qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl}, - qom::{ClassInitImpl, ObjectImpl, Owned, ParentField}, - sysbus::{SysBusDevice, SysBusDeviceClass, SysBusDeviceImpl}, + qom::{ObjectImpl, Owned, ParentField}, + sysbus::{SysBusDevice, SysBusDeviceImpl}, vmstate::VMStateDescription, }; @@ -145,7 +145,7 @@ trait PL011Impl: SysBusDeviceImpl + IsA { impl PL011Class { fn class_init(&mut self) { self.device_id = T::DEVICE_ID; - >::class_init(&mut self.parent_class); + self.parent_class.class_init::(); } } diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs index e01b4b67064..be27eb0eff4 100644 --- a/rust/hw/timer/hpet/src/hpet.rs +++ b/rust/hw/timer/hpet/src/hpet.rs @@ -21,7 +21,7 @@ }, prelude::*, qdev::{DeviceImpl, DeviceMethods, DeviceState, Property, ResetType, ResettablePhasesImpl}, - qom::{ClassInitImpl, ObjectImpl, ObjectType, ParentField}, + qom::{ObjectImpl, ObjectType, ParentField}, qom_isa, sysbus::{SysBusDevice, SysBusDeviceImpl}, timer::{Timer, CLOCK_VIRTUAL}, @@ -836,7 +836,7 @@ impl ObjectImpl for HPETState { const INSTANCE_INIT: Option = Some(Self::init); const INSTANCE_POST_INIT: Option = Some(Self::post_init); - const CLASS_INIT: fn(&mut Self::Class) = >::class_init; + const CLASS_INIT: fn(&mut Self::Class) = Self::Class::class_init::; } // TODO: Make these properties user-configurable! diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs index c4dd26b582c..c136457090c 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/qemu-api/src/qdev.rs @@ -19,7 +19,7 @@ chardev::Chardev, irq::InterruptSource, prelude::*, - qom::{ClassInitImpl, ObjectClass, ObjectImpl, Owned}, + qom::{ObjectClass, ObjectImpl, Owned}, vmstate::VMStateDescription, }; @@ -113,7 +113,7 @@ fn vmsd() -> Option<&'static VMStateDescription> { /// # Safety /// /// This function is only called through the QOM machinery and -/// used by the `ClassInitImpl` trait. +/// used by `DeviceClass::class_init`. /// We expect the FFI user of this function to pass a valid pointer that /// can be downcasted to type `T`. We also expect the device is /// readable/writeable from one thread at any time. @@ -127,43 +127,41 @@ unsafe impl InterfaceType for ResettableClass { unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_RESETTABLE_INTERFACE) }; } -impl ClassInitImpl for T -where - T: ResettablePhasesImpl, -{ - fn class_init(rc: &mut ResettableClass) { +impl ResettableClass { + /// Fill in the virtual methods of `ResettableClass` based on the + /// definitions in the `ResettablePhasesImpl` trait. + pub fn class_init(&mut self) { if ::ENTER.is_some() { - rc.phases.enter = Some(rust_resettable_enter_fn::); + self.phases.enter = Some(rust_resettable_enter_fn::); } if ::HOLD.is_some() { - rc.phases.hold = Some(rust_resettable_hold_fn::); + self.phases.hold = Some(rust_resettable_hold_fn::); } if ::EXIT.is_some() { - rc.phases.exit = Some(rust_resettable_exit_fn::); + self.phases.exit = Some(rust_resettable_exit_fn::); } } } -impl ClassInitImpl for T -where - T: ClassInitImpl + ClassInitImpl + DeviceImpl, -{ - fn class_init(dc: &mut DeviceClass) { +impl DeviceClass { + /// Fill in the virtual methods of `DeviceClass` based on the definitions in + /// the `DeviceImpl` trait. + pub fn class_init(&mut self) { if ::REALIZE.is_some() { - dc.realize = Some(rust_realize_fn::); + self.realize = Some(rust_realize_fn::); } if let Some(vmsd) = ::vmsd() { - dc.vmsd = vmsd; + self.vmsd = vmsd; } let prop = ::properties(); if !prop.is_empty() { unsafe { - bindings::device_class_set_props_n(dc, prop.as_ptr(), prop.len()); + bindings::device_class_set_props_n(self, prop.as_ptr(), prop.len()); } } - ResettableClass::interface_init::(dc); - >::class_init(&mut dc.parent_class); + ResettableClass::cast::(self).class_init::(); + self.parent_class.class_init::(); } } diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs index d821ac25acc..5488643a2fd 100644 --- a/rust/qemu-api/src/qom.rs +++ b/rust/qemu-api/src/qom.rs @@ -40,11 +40,6 @@ //! The traits have the appropriate specialization of `IsA<>` as a supertrait, //! for example `IsA` for `DeviceImpl`. //! -//! * an implementation of [`ClassInitImpl`], for example -//! `ClassInitImpl`. This fills the vtable in the class struct; -//! the source for this is the `*Impl` trait; the associated consts and -//! functions if needed are wrapped to map C types into Rust types. -//! //! * a trait for instance methods, for example `DeviceMethods`. This trait is //! automatically implemented for any reference or smart pointer to a device //! instance. It calls into the vtable provides access across all subclasses @@ -54,6 +49,48 @@ //! This provides access to class-wide functionality that doesn't depend on //! instance data. Like instance methods, these are automatically inherited by //! child classes. +//! +//! # Class structures +//! +//! Each QOM class that has virtual methods describes them in a +//! _class struct_. Class structs include a parent field corresponding +//! to the vtable of the parent class, all the way up to [`ObjectClass`]. +//! +//! As mentioned above, virtual methods are defined via traits such as +//! `DeviceImpl`. Class structs do not define any trait but, conventionally, +//! all of them have a `class_init` method to initialize the virtual methods +//! based on the trait and then call the same method on the superclass. +//! +//! ```ignore +//! impl YourSubclassClass +//! { +//! pub fn class_init(&mut self) { +//! ... +//! klass.parent_class::class_init(); +//! } +//! } +//! ``` +//! +//! If a class implements a QOM interface. In that case, the function must +//! contain, for each interface, an extra forwarding call as follows: +//! +//! ```ignore +//! ResettableClass::cast::(self).class_init::(); +//! ``` +//! +//! These `class_init` functions are methods on the class rather than a trait, +//! because the bound on `T` (`DeviceImpl` in this case), will change for every +//! class struct. The functions are pointed to by the +//! [`ObjectImpl::CLASS_INIT`] function pointer. While there is no default +//! implementation, in most cases it will be enough to write it as follows: +//! +//! ```ignore +//! const CLASS_INIT: fn(&mut Self::Class)> = Self::Class::class_init::; +//! ``` +//! +//! This design incurs a small amount of code duplication but, by not using +//! traits, it allows the flexibility of implementing bindings in any crate, +//! without incurring into violations of orphan rules for traits. use std::{ ffi::CStr, @@ -279,19 +316,25 @@ pub unsafe trait InterfaceType: Sized { /// for this interface. const TYPE_NAME: &'static CStr; - /// Initialize the vtable for the interface; the generic argument `T` is the - /// type being initialized, while the generic argument `U` is the type that + /// Return the vtable for the interface; `U` is the type that /// lists the interface in its `TypeInfo`. /// + /// # Examples + /// + /// This function is usually called by a `class_init` method in `U::Class`. + /// For example, `DeviceClass::class_init` initializes its `Resettable` + /// interface as follows: + /// + /// ```ignore + /// ResettableClass::cast::(self).class_init::(); + /// ``` + /// + /// where `T` is the concrete subclass that is being initialized. + /// /// # Panics /// /// Panic if the incoming argument if `T` does not implement the interface. - fn interface_init< - T: ObjectType + ClassInitImpl + ClassInitImpl, - U: ObjectType, - >( - klass: &mut U::Class, - ) { + fn cast(klass: &mut U::Class) -> &mut Self { unsafe { // SAFETY: upcasting to ObjectClass is always valid, and the // return type is either NULL or the argument itself @@ -300,8 +343,7 @@ fn interface_init< Self::TYPE_NAME.as_ptr(), ) .cast(); - - >::class_init(result.as_mut().unwrap()) + result.as_mut().unwrap() } } } @@ -558,87 +600,20 @@ pub trait ObjectImpl: ObjectType + IsA { /// the default values coming from the parent classes; the function /// can change them to override virtual methods of a parent class. /// - /// Usually defined as `::class_init`. - const CLASS_INIT: fn(&mut Self::Class); -} - -/// Internal trait used to automatically fill in a class struct. -/// -/// Each QOM class that has virtual methods describes them in a -/// _class struct_. Class structs include a parent field corresponding -/// to the vtable of the parent class, all the way up to [`ObjectClass`]. -/// Each QOM type has one such class struct; this trait takes care of -/// initializing the `T` part of the class struct, for the type that -/// implements the trait. -/// -/// Each struct will implement this trait with `T` equal to each -/// superclass. For example, a device should implement at least -/// `ClassInitImpl<`[`DeviceClass`](crate::qdev::DeviceClass)`>` and -/// `ClassInitImpl<`[`ObjectClass`]`>`. Such implementations are made -/// in one of two ways. -/// -/// For most superclasses, `ClassInitImpl` is provided by the `qemu-api` -/// crate itself. The Rust implementation of methods will come from a -/// trait like [`ObjectImpl`] or [`DeviceImpl`](crate::qdev::DeviceImpl), -/// and `ClassInitImpl` is provided by blanket implementations that -/// operate on all implementors of the `*Impl`* trait. For example: -/// -/// ```ignore -/// impl ClassInitImpl for T -/// where -/// T: ClassInitImpl + DeviceImpl, -/// ``` -/// -/// The bound on `ClassInitImpl` is needed so that, -/// after initializing the `DeviceClass` part of the class struct, -/// the parent [`ObjectClass`] is initialized as well. -/// -/// The other case is when manual implementation of the trait is needed. -/// This covers the following cases: -/// -/// * if a class implements a QOM interface, the Rust code _has_ to define its -/// own class struct `FooClass` and implement `ClassInitImpl`. -/// `ClassInitImpl`'s `class_init` method will then forward to -/// multiple other `class_init`s, for the interfaces as well as the -/// superclass. (Note that there is no Rust example yet for using interfaces). -/// -/// * for classes implemented outside the ``qemu-api`` crate, it's not possible -/// to add blanket implementations like the above one, due to orphan rules. In -/// that case, the easiest solution is to implement -/// `ClassInitImpl` for each subclass and not have a -/// `YourSuperclassImpl` trait at all. -/// -/// ```ignore -/// impl ClassInitImpl for YourSubclass { -/// fn class_init(klass: &mut YourSuperclass) { -/// klass.some_method = Some(Self::some_method); -/// >::class_init(&mut klass.parent_class); -/// } -/// } -/// ``` -/// -/// While this method incurs a small amount of code duplication, -/// it is generally limited to the recursive call on the last line. -/// This is because classes defined in Rust do not need the same -/// glue code that is needed when the classes are defined in C code. -/// You may consider using a macro if you have many subclasses. -pub trait ClassInitImpl { - /// Initialize `klass` to point to the virtual method implementations - /// for `Self`. On entry, the virtual method pointers are set to - /// the default values coming from the parent classes; the function - /// can change them to override virtual methods of a parent class. + /// Usually defined simply as `Self::Class::class_init::`; + /// however a default implementation cannot be included here, because the + /// bounds that the `Self::Class::class_init` method places on `Self` are + /// not known in advance. /// - /// The virtual method implementations usually come from another - /// trait, for example [`DeviceImpl`](crate::qdev::DeviceImpl) - /// when `T` is [`DeviceClass`](crate::qdev::DeviceClass). + /// # Safety /// - /// On entry, `klass`'s parent class is initialized, while the other fields + /// While `klass`'s parent class is initialized on entry, the other fields /// are all zero; it is therefore assumed that all fields in `T` can be /// zeroed, otherwise it would not be possible to provide the class as a /// `&mut T`. TODO: add a bound of [`Zeroable`](crate::zeroable::Zeroable) /// to T; this is more easily done once Zeroable does not require a manual /// implementation (Rust 1.75.0). - fn class_init(klass: &mut T); + const CLASS_INIT: fn(&mut Self::Class); } /// # Safety @@ -651,13 +626,12 @@ pub trait ClassInitImpl { T::UNPARENT.unwrap()(unsafe { state.as_ref() }); } -impl ClassInitImpl for T -where - T: ObjectImpl, -{ - fn class_init(oc: &mut ObjectClass) { +impl ObjectClass { + /// Fill in the virtual methods of `ObjectClass` based on the definitions in + /// the `ObjectImpl` trait. + pub fn class_init(&mut self) { if ::UNPARENT.is_some() { - oc.unparent = Some(rust_unparent_fn::); + self.unparent = Some(rust_unparent_fn::); } } } diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs index fee2e3d478f..04821a2b9b3 100644 --- a/rust/qemu-api/src/sysbus.rs +++ b/rust/qemu-api/src/sysbus.rs @@ -14,8 +14,8 @@ irq::{IRQState, InterruptSource}, memory::MemoryRegion, prelude::*, - qdev::{DeviceClass, DeviceImpl, DeviceState}, - qom::{ClassInitImpl, Owned}, + qdev::{DeviceImpl, DeviceState}, + qom::Owned, }; unsafe impl ObjectType for SysBusDevice { @@ -28,12 +28,11 @@ unsafe impl ObjectType for SysBusDevice { // TODO: add virtual methods pub trait SysBusDeviceImpl: DeviceImpl + IsA {} -impl ClassInitImpl for T -where - T: SysBusDeviceImpl + ClassInitImpl, -{ - fn class_init(sdc: &mut SysBusDeviceClass) { - >::class_init(&mut sdc.parent_class); +impl SysBusDeviceClass { + /// Fill in the virtual methods of `SysBusDeviceClass` based on the + /// definitions in the `SysBusDeviceImpl` trait. + pub fn class_init(self: &mut SysBusDeviceClass) { + self.parent_class.class_init::(); } } diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 93c5637bbc3..e3985782a38 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -14,7 +14,7 @@ declare_properties, define_property, prelude::*, qdev::{DeviceImpl, DeviceState, Property, ResettablePhasesImpl}, - qom::{ClassInitImpl, ObjectImpl, ParentField}, + qom::{ObjectImpl, ParentField}, sysbus::SysBusDevice, vmstate::VMStateDescription, zeroable::Zeroable, @@ -43,7 +43,7 @@ pub struct DummyClass { impl DummyClass { pub fn class_init(self: &mut DummyClass) { - >::class_init(&mut self.parent_class); + self.parent_class.class_init::(); } } From patchwork Thu Feb 27 14:19:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 512F2C19F2E for ; Thu, 27 Feb 2025 14:36:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelo-0001BV-DX; Thu, 27 Feb 2025 09:21:48 -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 ) id 1tnel0-0007f9-Ja for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tneky-0003q1-PS for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sU4JUhAK5XAEQyd9qSYhUnxLKsYgYIsyzAJD2IwPzIU=; b=UxN8L+pmpRAvWKPPy9JX5r5v2ixSu7kNKYzwa+/LvspKdu1XY1rEe7B66vm7kVOA283WDL A7mNpHNMPXtKz8ptGeG5XV1gMf+szdkg1VXuAeKhxJ4t6rqSl0hRhjhlPjonFqnov8k3yc gz1TdqJ0pL3Cb/IVixpavQe8kS4tnDE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-104-ApgzUnnTPYOD0V9g1-lFSQ-1; Thu, 27 Feb 2025 09:20:50 -0500 X-MC-Unique: ApgzUnnTPYOD0V9g1-lFSQ-1 X-Mimecast-MFC-AGG-ID: ApgzUnnTPYOD0V9g1-lFSQ_1740666050 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-390eb06d920so101572f8f.3 for ; Thu, 27 Feb 2025 06:20:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666048; x=1741270848; 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=sU4JUhAK5XAEQyd9qSYhUnxLKsYgYIsyzAJD2IwPzIU=; b=fDO7QNAsmA5ySGy8gYcu9QcvKGG85qFwoyxer8+V8s2zhJcVCO+n/cumgNHAtxRQNN mzVnMVT4yLZE44nP3l1JfafeMuMWGkryphCSsho3gU1H2h4YvGBwPdSR0UBTguaR4DnC bkBRTeXGmYO1K9ut6xNGTjQjKHZRfhMA6yeX/IZ1hNEmJlgRxNX1bxZaryPkuZm2Ayyh G3Rl09DG6gz5sOVtSIXQ4tjy6B/U5tbk5eJRHex0m/kny2Z9kZJiZhKZUmuGmOWU3PoI vrn1mAlDcIcRlHTlXM6uxtJcrFgx4jC4mbWySHDyv+SKyg/D68vlLhsFubSnaVDfmJ8w /VhA== X-Gm-Message-State: AOJu0Yw+u4j+yaPaiWrAj3m0jhrIGGJXmw3bBRmloQN06769RIWgKfeO H8oQWM+LNCVKuW2nf0NXIJbf5C0uDGMEXh+DbaKiqIazVqjVZwNfWYPzjhkuZTxKK58ceKcUiES oXgWUYseVK/ShxqXjBU8gFtLeZelEXIXQ4AXekxL8zTN6/L/TSbjcVmKOww4bhklnRR02h+9lA6 I37cilovV/3pT1sBKlmTK4gvi35jydzGQ5XXWNg/U= X-Gm-Gg: ASbGnct0dJNKr+sNYjrm/wXvBypQPWMCMYTfPj3kqFunTDRgS0JtfliZESMQV87dJGx DzsYEzxMQSXFj6wdt4vselNg1AtItxT7De9IpPbWpsPXeQXUJt00PlG90yTB8/YblMFnPMqvdu9 QRyHM0xH7WW5IBR/FNEy1KvmEQkCZv6dmx6QuEZpASTB5iFyQj5+Sj6Qjfox+aEl1Own9fWAiED FqUA7SgD3eDwUOzRyqdFNsEIE/2QizGMnzu0JhUCiRL5/BxKPNcuuSbrjyhL5sGAG/bGn49eKwm at/Zxv7kgz2/0p/o1ex2 X-Received: by 2002:a05:6000:18ad:b0:38f:32ab:d4f4 with SMTP id ffacd0b85a97d-390cc5f58admr11636049f8f.4.1740666048629; Thu, 27 Feb 2025 06:20:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdrJGfG1m9xhlSs8sYUhd0vadoDAk6nS4+smvPDgTgjagVwFjAhKtVfXfdtuQqpsk8rTQb/w== X-Received: by 2002:a05:6000:18ad:b0:38f:32ab:d4f4 with SMTP id ffacd0b85a97d-390cc5f58admr11636013f8f.4.1740666048152; Thu, 27 Feb 2025 06:20:48 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c1146b7sm129343066b.84.2025.02.27.06.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:47 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yongwei Ma , Jonathan Cameron , "Michael S. Tsirkin" Subject: [PULL 25/34] i386/cpu: Support module level cache topology Date: Thu, 27 Feb 2025 15:19:43 +0100 Message-ID: <20250227141952.811410-26-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Zhao Liu Allow cache to be defined at the module level. This increases flexibility for x86 users to customize their cache topology. Signed-off-by: Zhao Liu Tested-by: Yongwei Ma Reviewed-by: Jonathan Cameron Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/r/20250110145115.1574345-3-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 72ab147e851..8799e22ed45 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -247,6 +247,9 @@ static uint32_t max_thread_ids_for_cache(X86CPUTopoInfo *topo_info, case CPU_TOPOLOGY_LEVEL_CORE: num_ids = 1 << apicid_core_offset(topo_info); break; + case CPU_TOPOLOGY_LEVEL_MODULE: + num_ids = 1 << apicid_module_offset(topo_info); + break; case CPU_TOPOLOGY_LEVEL_DIE: num_ids = 1 << apicid_die_offset(topo_info); break; @@ -255,7 +258,7 @@ static uint32_t max_thread_ids_for_cache(X86CPUTopoInfo *topo_info, break; default: /* - * Currently there is no use case for THREAD and MODULE, so use + * Currently there is no use case for THREAD, so use * assert directly to facilitate debugging. */ g_assert_not_reached(); From patchwork Thu Feb 27 14:19:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E912FC1B0FF for ; Thu, 27 Feb 2025 14:31:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelZ-0000Wc-PX; Thu, 27 Feb 2025 09:21:35 -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 ) id 1tnel2-0007ib-Oj for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tneky-0003q9-Qz for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:20:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gh0j8ufLlOEegSjJktfQdEiBAdxSKXYPacngKO6YrfQ=; b=XLE5RkBjQNWh7rdqMZ6jMIE3k9ARe1yOR19G5aUc+YiA55BOUE9lEc2H1PYlEN+G+BGUI0 KCh020KCBQj1IdRLQisGr/FVXy+FfHHbEAtaz1dLb4iUMDLANwdgaZHBhBYyNPt7qpIK+T lyPP99zTVkLMTfrEiw3HcZKKC9nNEMc= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-578-IjFlgM1JODamjTXTiufiMw-1; Thu, 27 Feb 2025 09:20:53 -0500 X-MC-Unique: IjFlgM1JODamjTXTiufiMw-1 X-Mimecast-MFC-AGG-ID: IjFlgM1JODamjTXTiufiMw_1740666052 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-ab76f438dddso41007066b.2 for ; Thu, 27 Feb 2025 06:20:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666051; x=1741270851; 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=gh0j8ufLlOEegSjJktfQdEiBAdxSKXYPacngKO6YrfQ=; b=Y7S9Gz2G7AioDRa7+iSnL87r1cKGXkA8j09nUNpQR17E4iRCxvfqxa93Hhlbheq7ES h121yoVWl0pOi4bOhTpRDw7ULji/CnvHwleJAFBr0un6kzwRmI0+eKq+k0QLj+I9G48k D9jkMmEq84XeOtY3f8XXgclzeT08sBddQ01ddTdNc0bv05lIoB92cYTIirhdaiJtc9HS 0OrZy8GmpSPonD/DlJh9/4l4xEwBrJ5HhGtOerc4azoNQbYmyNmEDEhDpFMzj48Bt10w HxdbUmRWp8VcjUf7jhJQ4r3e712x1M+YsoCleyIB6z91T1V6nAkudVNdKyft1QzSm3l0 CfSg== X-Gm-Message-State: AOJu0YzSP1o/2PBFQJVkoSwhvynTUP0dHJmMafFDAmEt0+FgBdu6SD06 aZ88PU3p44mn+J2mzlPOEh4c8Rs3S9K9qaJsKsakuzNXwHtIUKiD85q4HCSSapGrC+rRSzwMJt1 oJ2pYyTrA2cTK1FjGyJdEK5NIjKhO2DI62oDjS4kj7SPxCwKowN/zBMhuaPPZkFyLLu7cHZoIP3 sjZrAE802JXwSwgr7a8iN0FEvTD/iSNdnC/t6M+BA= X-Gm-Gg: ASbGncvDXhP7klIk9rs1ylGUBkUsvpWVyiNlsVrSwyw2VHdRuafK7zGU8estQEU5o3Q IvvvucK5/0jYwItocV4hYBOGNU/5OgaSi8IZiiBs5hee27JrfYjUpg4HQd/pIoZww9epoWk6+an Y2djvQi3pvN8gRw23Gkq3T+ijxudh5fwG9P/qYvGI3cTMckFL1dYwGvcp8MsuA/MgJkvZuEyHy1 edf+xh0tHGQXQzJ1LWPYuqob6BAxsDxEf8ixkIyJZyRBTfDZX+NgciLo30TuWOFtfjHFSBiSgwz mJ1jNyO142V2wPZdkzoh X-Received: by 2002:a17:906:3155:b0:ab7:c6a2:7a43 with SMTP id a640c23a62f3a-abc0db35941mr2366717066b.31.1740666051264; Thu, 27 Feb 2025 06:20:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLlWQ6QD1ZDDBu4ot/1NZFk2nnvmD0s6fqyXTudnZBPEAQfDfIX2y8kxCKr/w45fxh1mKsMg== X-Received: by 2002:a17:906:3155:b0:ab7:c6a2:7a43 with SMTP id a640c23a62f3a-abc0db35941mr2366713966b.31.1740666050819; Thu, 27 Feb 2025 06:20:50 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c3b6dbbbsm1179991a12.22.2025.02.27.06.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:49 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yongwei Ma , Jonathan Cameron , "Michael S. Tsirkin" Subject: [PULL 26/34] i386/cpu: Update cache topology with machine's configuration Date: Thu, 27 Feb 2025 15:19:44 +0100 Message-ID: <20250227141952.811410-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Zhao Liu User will configure smp cache topology via -machine smp-cache. For this case, update the x86 CPUs' cache topology with user's configuration in MachineState. Signed-off-by: Zhao Liu Tested-by: Yongwei Ma Reviewed-by: Jonathan Cameron Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/r/20250110145115.1574345-4-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8799e22ed45..005ca4235df 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7906,6 +7906,64 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu) cpu->hyperv_limits[2] = 0; } +#ifndef CONFIG_USER_ONLY +static bool x86_cpu_update_smp_cache_topo(MachineState *ms, X86CPU *cpu, + Error **errp) +{ + CPUX86State *env = &cpu->env; + CpuTopologyLevel level; + + level = machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D); + if (level != CPU_TOPOLOGY_LEVEL_DEFAULT) { + env->cache_info_cpuid4.l1d_cache->share_level = level; + env->cache_info_amd.l1d_cache->share_level = level; + } else { + machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D, + env->cache_info_cpuid4.l1d_cache->share_level); + machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1D, + env->cache_info_amd.l1d_cache->share_level); + } + + level = machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I); + if (level != CPU_TOPOLOGY_LEVEL_DEFAULT) { + env->cache_info_cpuid4.l1i_cache->share_level = level; + env->cache_info_amd.l1i_cache->share_level = level; + } else { + machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I, + env->cache_info_cpuid4.l1i_cache->share_level); + machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L1I, + env->cache_info_amd.l1i_cache->share_level); + } + + level = machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2); + if (level != CPU_TOPOLOGY_LEVEL_DEFAULT) { + env->cache_info_cpuid4.l2_cache->share_level = level; + env->cache_info_amd.l2_cache->share_level = level; + } else { + machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2, + env->cache_info_cpuid4.l2_cache->share_level); + machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L2, + env->cache_info_amd.l2_cache->share_level); + } + + level = machine_get_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3); + if (level != CPU_TOPOLOGY_LEVEL_DEFAULT) { + env->cache_info_cpuid4.l3_cache->share_level = level; + env->cache_info_amd.l3_cache->share_level = level; + } else { + machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3, + env->cache_info_cpuid4.l3_cache->share_level); + machine_set_cache_topo_level(ms, CACHE_LEVEL_AND_TYPE_L3, + env->cache_info_amd.l3_cache->share_level); + } + + if (!machine_check_smp_cache(ms, errp)) { + return false; + } + return true; +} +#endif + static void x86_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); @@ -8145,6 +8203,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) #ifndef CONFIG_USER_ONLY MachineState *ms = MACHINE(qdev_get_machine()); + + /* + * TODO: Add a SMPCompatProps.has_caches flag to avoid useless updates + * if user didn't set smp_cache. + */ + if (!x86_cpu_update_smp_cache_topo(ms, cpu, errp)) { + return; + } + qemu_register_reset(x86_cpu_machine_reset_cb, cpu); if (cpu->env.features[FEAT_1_EDX] & CPUID_APIC || ms->smp.cpus > 1) { From patchwork Thu Feb 27 14:19:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 784B3C19F2E for ; Thu, 27 Feb 2025 14:37:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tneln-00015D-RH; Thu, 27 Feb 2025 09:21:48 -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 ) id 1tnel2-0007ia-OG for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnekz-0003qb-SA for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666057; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W2DTEL0GvEgD05Vg/aBlXWWfjE1Jq68V9IAsv0IIcfk=; b=TKzodS39GChu4vh3QJ7LvfEIpbaUg2OA3OZcQR2j14O2Zx9ddQWsBqVtjvHT+q/U6G37nY uX/6/hB2wOFPf5OAB/GfZoFeNwDVbq1+xjqtjvxhcCgMZnoAFI58v+y1waOgGRVF0C+nLN xtHtKckr/SgNK7buAF7lehpNj6TQIqs= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-336-yYxRgl66P8Kpnts6Wi53Yg-1; Thu, 27 Feb 2025 09:20:55 -0500 X-MC-Unique: yYxRgl66P8Kpnts6Wi53Yg-1 X-Mimecast-MFC-AGG-ID: yYxRgl66P8Kpnts6Wi53Yg_1740666055 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5e4aecbd88fso1149299a12.1 for ; Thu, 27 Feb 2025 06:20:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666054; x=1741270854; 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=W2DTEL0GvEgD05Vg/aBlXWWfjE1Jq68V9IAsv0IIcfk=; b=r480jGFftfMuh8kcRv+1hLWIEOtTFBoFyj+ntGtnEWboPBjU4Qex3qUV2ZiP6SphcE 0l0CjJMaOro/PtRZuUUgWLRu2JwwUUyIm8pc3ovn3eAQmZpnmrgqucLWlbcLrmwaF+Zy KiLMNuZcxptacOv/xQzddulWRE88tN2irh0fJwGVC34drmAxY6PElILg08c2JiFgZkZ/ HFAzVDJftNJA4THzUsv4A/pzHCJBE1uJbWkZ6DJJhdmkye6UwC1+vGtuaAGyH9jacjZ8 afEfUq76o9mrzgNUTgpxAHKrU/qi1cJ+AySyPRa5jqYBd0eHZ/SXZi+E0qUcHWg4MPlh WdFg== X-Gm-Message-State: AOJu0YwW0LvxL5zG8Bpx07fo/c+wUmM0F42ZvYDqRcDR8OMp3lS8F0iw dY59Ffl5i/FPL5mT2N/UOzrTRcvC01Ic6n8M8muX+wQNZmb60H5DLcN9w+I7ZFUBZ8in48dhEwh 6OFc0F7Pbddg0c7zDbWDa2sZ+VA7CFaqdKTz+zvTTIXFbpV3ucRBhhejF6Axjz5CvLdlW1370mk 7B4EqeDhEYvLm3bvw49EbC/XG1yzDoSkwrmW+W4Z0= X-Gm-Gg: ASbGncskRBFpLrGYbqVLDUdP++aG5bGJso79kRifxa2D02o1s9QJQFFes49fYVKj7Gg NII1Z2FVMq4bR/w+FHSMhmBtgAXlLnEAcyJxZh61XKULKVSvtM1fbLyPEDJ1UIgMj01wniZQYxj O4pGRM90TEeeCyCNjhMWzwxea9UnO0jMu6WBjN7NDRsY6u4pXMdgC7gcSrhi2SpyCU6vWtj2L4/ K3uzYs/EHqVWig4u/AgYr8ReO9pMQkLM2WBwOPsMY9gTw2U2OZE/uihJRT0cImyMtnl2Alz+DMI JVAALCuwC7YfujBEOs/L X-Received: by 2002:a05:6402:2548:b0:5db:e7eb:1b34 with SMTP id 4fb4d7f45d1cf-5e0b70f07d4mr29001794a12.13.1740666053775; Thu, 27 Feb 2025 06:20:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNsxeGbB+ZyF929QRj/hqGtIm2BMFKVfQd0zLRSDWQNLAUaW9RIj3K1h0b5ko8JQeCbTFUbA== X-Received: by 2002:a05:6402:2548:b0:5db:e7eb:1b34 with SMTP id 4fb4d7f45d1cf-5e0b70f07d4mr29001757a12.13.1740666053283; Thu, 27 Feb 2025 06:20:53 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c43a55besm1139424a12.72.2025.02.27.06.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yongwei Ma , Jonathan Cameron , "Michael S. Tsirkin" Subject: [PULL 27/34] i386/pc: Support cache topology in -machine for PC machine Date: Thu, 27 Feb 2025 15:19:45 +0100 Message-ID: <20250227141952.811410-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Zhao Liu Allow user to configure l1d, l1i, l2 and l3 cache topologies for PC machine. Additionally, add the document of "-machine smp-cache" in qemu-options.hx. Signed-off-by: Zhao Liu Tested-by: Yongwei Ma Reviewed-by: Jonathan Cameron Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/r/20250110145115.1574345-5-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 4 ++++ qemu-options.hx | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f199a8c7ad1..63a96cd23f8 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1798,6 +1798,10 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) mc->nvdimm_supported = true; mc->smp_props.dies_supported = true; mc->smp_props.modules_supported = true; + mc->smp_props.cache_supported[CACHE_LEVEL_AND_TYPE_L1D] = true; + mc->smp_props.cache_supported[CACHE_LEVEL_AND_TYPE_L1I] = true; + mc->smp_props.cache_supported[CACHE_LEVEL_AND_TYPE_L2] = true; + mc->smp_props.cache_supported[CACHE_LEVEL_AND_TYPE_L3] = true; mc->default_ram_id = "pc.ram"; pcmc->default_smbios_ep_type = SMBIOS_ENTRY_POINT_TYPE_AUTO; diff --git a/qemu-options.hx b/qemu-options.hx index 61270e32067..dc694a99a30 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -42,7 +42,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " aux-ram-share=on|off allocate auxiliary guest RAM as shared (default: off)\n" #endif " memory-backend='backend-id' specifies explicitly provided backend for main RAM (default=none)\n" - " cxl-fmw.0.targets.0=firsttarget,cxl-fmw.0.targets.1=secondtarget,cxl-fmw.0.size=size[,cxl-fmw.0.interleave-granularity=granularity]\n", + " cxl-fmw.0.targets.0=firsttarget,cxl-fmw.0.targets.1=secondtarget,cxl-fmw.0.size=size[,cxl-fmw.0.interleave-granularity=granularity]\n" + " smp-cache.0.cache=cachename,smp-cache.0.topology=topologylevel\n", QEMU_ARCH_ALL) SRST ``-machine [type=]name[,prop=value[,...]]`` @@ -172,6 +173,33 @@ SRST :: -machine cxl-fmw.0.targets.0=cxl.0,cxl-fmw.0.targets.1=cxl.1,cxl-fmw.0.size=128G,cxl-fmw.0.interleave-granularity=512 + + ``smp-cache.0.cache=cachename,smp-cache.0.topology=topologylevel`` + Define cache properties for SMP system. + + ``cache=cachename`` specifies the cache that the properties will be + applied on. This field is the combination of cache level and cache + type. It supports ``l1d`` (L1 data cache), ``l1i`` (L1 instruction + cache), ``l2`` (L2 unified cache) and ``l3`` (L3 unified cache). + + ``topology=topologylevel`` sets the cache topology level. It accepts + CPU topology levels including ``core``, ``module``, ``cluster``, ``die``, + ``socket``, ``book``, ``drawer`` and a special value ``default``. If + ``default`` is set, then the cache topology will follow the architecture's + default cache topology model. If another topology level is set, the cache + will be shared at corresponding CPU topology level. For example, + ``topology=core`` makes the cache shared by all threads within a core. + The omitting cache will default to using the ``default`` level. + + The default cache topology model for an i386 PC machine is as follows: + ``l1d``, ``l1i``, and ``l2`` caches are per ``core``, while the ``l3`` + cache is per ``die``. + + Example: + + :: + + -machine smp-cache.0.cache=l1d,smp-cache.0.topology=core,smp-cache.1.cache=l1i,smp-cache.1.topology=core ERST DEF("M", HAS_ARG, QEMU_OPTION_M, From patchwork Thu Feb 27 14:19:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6BADEC19F2E for ; Thu, 27 Feb 2025 14:25:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelV-00006S-Up; Thu, 27 Feb 2025 09:21:30 -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 ) id 1tnel6-0007sD-DA for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnel3-0003ra-Cg for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wxYYY1R7biz/YFz8OOn3xrn4YUgJT/5akSv9YjxqfqA=; b=J6/uHhb87Tv6c8wm0IR7tLWF0QpISWJpZsEhg3iwpr5Ri/GVQx8IY1nW2b42bgF4a2zffQ Ue6FERRqcKGvN83dwNpv/kF24F4TeTgp1t/P8NBnIuj9aIlhXe/h2AD6x0+Kvw85juAQZt bkPSZ8rgkwPdMw43WdHsT5hHeU7Xwjw= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-203-DIR0lcozOUKqRndGKx9XJg-1; Thu, 27 Feb 2025 09:20:59 -0500 X-MC-Unique: DIR0lcozOUKqRndGKx9XJg-1 X-Mimecast-MFC-AGG-ID: DIR0lcozOUKqRndGKx9XJg_1740666057 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-abb61c30566so93541766b.2 for ; Thu, 27 Feb 2025 06:20:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666056; x=1741270856; 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=wxYYY1R7biz/YFz8OOn3xrn4YUgJT/5akSv9YjxqfqA=; b=dv83nZ1TnZasMO81CvhKve9sVG6s227WpjeGe/HPgbb313KBPcpYLuIUyhQrsESTZX shWIavKXQYlZiZ3Mgy8x0u0F1p/CMhQTZ1c6OuvBTv4PuhB+6kKfcc+lClLoJlMfI9Av avRZHqeBLtVtmN0aIAf+49mwQfClW3swthRnniVtt5dXdmElUBcT1uxkC21CDrO7dCZQ Nqb+dK+q79KuwZQ9YXSvzc1iTH7poMceSdilYwAe/4Z2SfrPJYUReLTKIauFxJ8vqI7Q AjvusNNOjM02vm+h0NqLusnM0tFOqBAvKq+dgFsjbBEY+GH0Ks6ntKOqIHK7WUtuPf2B iqBQ== X-Gm-Message-State: AOJu0YyJbMUOyvTs+NO6rWbRVy447ILOi0Mswv2nMOZ6KEeuYebERbXG xKWhsG4IcBxY+/fQnP5jE3+R7gQESeNoA/gKDGUgujGVYQKDGPZ0ChqFhO6JtYdytBvJYC8Pm2n rcKAFp8l0XmMrl3fH2VILykTNApY0lxi0g0UkZOgma6Ki3gi7jfUDX4kDcWfoE3xZBuhApfPWq+ 7Y8G4q0JImalmr/RFvk3VW5AWPBz/NO0IsXV0xX8g= X-Gm-Gg: ASbGncuZyXZY5J3FPbcyx/Z5v1jBF4CmQqeHKlHPqcF8Cs4abynEWvcY1PBb14EVUNA ObVZeO/OHP5cSOqhcL5MtG2NX5wiaUg11mzeuqBg53Eyto4/vgVZbR3z/zv9y+9SNRIRN7WQfdz b2T3mkpn0INemVTOV/rLgwO2qkvRndYlX4Y2ecOhb6Lba+EzOOTUBbwhlY6iXOtD6L0X7F9Vtrp 9ZQTfCV1/wjelcz2XtjpMtZR1/jr+P/JZhUFmJ7ttJfsQcy34+w/Gxr7xphmGy3lP795aNyXi08 PXcpoy7JPB8XYRwDyr81 X-Received: by 2002:a17:907:c407:b0:abc:4b7:e3d3 with SMTP id a640c23a62f3a-abeeedcfecbmr1035342766b.27.1740666055907; Thu, 27 Feb 2025 06:20:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbnHBHIeA7vDAqGtZEUn8x3VOIc4qFSRAuXBDdTB6Angr8zSECngHltyIUGtquqaCepK9zNg== X-Received: by 2002:a17:907:c407:b0:abc:4b7:e3d3 with SMTP id a640c23a62f3a-abeeedcfecbmr1035339566b.27.1740666055459; Thu, 27 Feb 2025 06:20:55 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c6ee4b3sm127042766b.112.2025.02.27.06.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Alireza Sanaee , Zhao Liu , Jonathan Cameron , "Michael S. Tsirkin" Subject: [PULL 28/34] i386/cpu: add has_caches flag to check smp_cache configuration Date: Thu, 27 Feb 2025 15:19:46 +0100 Message-ID: <20250227141952.811410-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Alireza Sanaee Add has_caches flag to SMPCompatProps, which helps in avoiding extra checks for every single layer of caches in x86 (and ARM in future). Signed-off-by: Alireza Sanaee Signed-off-by: Zhao Liu Reviewed-by: Jonathan Cameron Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/r/20250110145115.1574345-6-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- include/hw/boards.h | 3 +++ hw/core/machine-smp.c | 2 ++ target/i386/cpu.c | 11 +++++------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index 9360d1ce394..f22b2e7fc75 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -156,6 +156,8 @@ typedef struct { * @modules_supported - whether modules are supported by the machine * @cache_supported - whether cache (l1d, l1i, l2 and l3) configuration are * supported by the machine + * @has_caches - whether cache properties are explicitly specified in the + * user provided smp-cache configuration */ typedef struct { bool prefer_sockets; @@ -166,6 +168,7 @@ typedef struct { bool drawers_supported; bool modules_supported; bool cache_supported[CACHE_LEVEL_AND_TYPE__MAX]; + bool has_caches; } SMPCompatProps; /** diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c index 4e020c358b6..0be0ac044c2 100644 --- a/hw/core/machine-smp.c +++ b/hw/core/machine-smp.c @@ -332,6 +332,8 @@ bool machine_parse_smp_cache(MachineState *ms, return false; } } + + mc->smp_props.has_caches = true; return true; } diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 005ca4235df..2f9c604552b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8203,13 +8203,12 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) #ifndef CONFIG_USER_ONLY MachineState *ms = MACHINE(qdev_get_machine()); + MachineClass *mc = MACHINE_GET_CLASS(ms); - /* - * TODO: Add a SMPCompatProps.has_caches flag to avoid useless updates - * if user didn't set smp_cache. - */ - if (!x86_cpu_update_smp_cache_topo(ms, cpu, errp)) { - return; + if (mc->smp_props.has_caches) { + if (!x86_cpu_update_smp_cache_topo(ms, cpu, errp)) { + return; + } } qemu_register_reset(x86_cpu_machine_reset_cb, cpu); From patchwork Thu Feb 27 14:19:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994632 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25F23C1B0FF for ; Thu, 27 Feb 2025 14:25:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelw-0001o1-IJ; Thu, 27 Feb 2025 09:21:56 -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 ) id 1tnel5-0007s3-Nd for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnel3-0003rc-Ar for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bMWORzOUwOCcEXcO5zGOU3VoKiAgJTGJeIEtqhhwSfc=; b=Hhr/92fgP/0QQX0lOdKMw3NYqJpLtuG7SPVsbUA5bXEXdUcE77V9xulr6oX10We0pgqaht WniEehLWR17beIl0OSoHVEjyR8F0gl0QX4l9rJC6tE/ua6rkwaoG6zuIqfNiMvQI26WSoC MLKpfVIeqR6I7OfacEvc47EMZsUg2D0= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-iGLgRnGsP3WBsmm63IOKbA-1; Thu, 27 Feb 2025 09:20:59 -0500 X-MC-Unique: iGLgRnGsP3WBsmm63IOKbA-1 X-Mimecast-MFC-AGG-ID: iGLgRnGsP3WBsmm63IOKbA_1740666058 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-aa6b904a886so89110066b.0 for ; Thu, 27 Feb 2025 06:20:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666057; x=1741270857; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bMWORzOUwOCcEXcO5zGOU3VoKiAgJTGJeIEtqhhwSfc=; b=v74MbPtpB9JucdE2fFhfXBSWQuONrk7ldwvlXV+faK929l2CsenXZ/e40qd/HC+hE1 +r3rlAaKLwYJQkjluq8v9+pVaMwC/k6O8reHrKGhv1fQwheb93VefunbrZ3C3AGpjJ2g JwfoC1LxbkhlR7arAsQIcR+zUuvXnPwSmv0umBlkMGxqWf0FE9FiH8tLRLahwNpH3P9l GGWlE+q/fLbMMi6W+H6EQXfHdcu8Jd3pfMQ+uk1LW0P5XWzk/mn6Xg4EkP2Ur3x4IPRN 04prdKcAto0M2RgxxFu4obe6vn1F9XzHhJGPUqIWvYcfCAdiufpIMCrShm4gN4O5TnWB /0xA== X-Gm-Message-State: AOJu0YybPwcZXP7H1RSPmm/9h5hoI/+KGJxrM/KWDdB3XwD+BtXP4s2S cpSzpqkDPbjf3AFevEvcT/JDADx8hjUV/0Ef4kT0JKX5xggh36zc7Krvwdh7EFY0O7QvqZe4Jo8 8fqFD2yuJt8Oy2HErHn14Mu+M7PSwAibAIOCiQ4bd1wHYIKpAjTh8EPSVhQ/54I9jZGIvOeYtVW Nrw/YH9hlvncdewSpBcmVG9iEvT5PtuI5Qoo68jt8= X-Gm-Gg: ASbGncvS0R9GIErihMfh2gS5eslA0iwQHBQ/aXxEIW251sLgPDYMgEQOD42OdQlflZP PgWwIRUn0S9DQ9bQVAvIL3po/YBDhMbhFee/qr0XkqsIdRvKgxeykBGe3k7DjnqFJhohzyVk70w QpmvMAe0LGWDF9aSsS3sVPB9SONfnyJehlO3ezaiGU+WO4eMSewmuFM9CHVUvM7qfFat+8/2OkW LAho3L2WjWYH+rIXVaNtEFpzl46S0MyIYNZbewVj2zlPjjX/irfDq7vgz0GSVTLBLW5tQaHdugv 8tGE7iG9k3eSwtgzbMP5 X-Received: by 2002:a17:907:724b:b0:abf:3df:3ea with SMTP id a640c23a62f3a-abf03df0cb4mr604542866b.44.1740666056974; Thu, 27 Feb 2025 06:20:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGq33zoWF8E7wTMdAUzbpWIGFna6zBFPUhdN42qs4Dg0LUSj3WNc+CNTjDZ5G7Q4mr1zGimWw== X-Received: by 2002:a17:907:724b:b0:abf:3df:3ea with SMTP id a640c23a62f3a-abf03df0cb4mr604540366b.44.1740666056580; Thu, 27 Feb 2025 06:20:56 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dd9f1sm131562766b.62.2025.02.27.06.20.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:56 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 29/34] target/riscv: remove unused macro DEFINE_CPU Date: Thu, 27 Feb 2025 15:19:47 +0100 Message-ID: <20250227141952.811410-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Paolo Bonzini --- target/riscv/cpu.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index cca24b9f1fc..0dcde546e47 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -3051,15 +3051,6 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename) } #endif -#define DEFINE_CPU(type_name, misa_mxl_max, initfn) \ - { \ - .name = (type_name), \ - .parent = TYPE_RISCV_CPU, \ - .instance_init = (initfn), \ - .class_init = riscv_cpu_class_init, \ - .class_data = (void *)(misa_mxl_max) \ - } - #define DEFINE_DYNAMIC_CPU(type_name, misa_mxl_max, initfn) \ { \ .name = (type_name), \ From patchwork Thu Feb 27 14:19:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65424C1B0FF for ; Thu, 27 Feb 2025 14:33:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnely-0001yG-EK; Thu, 27 Feb 2025 09:21:58 -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 ) id 1tnel7-0007td-Od for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnel6-0003sa-8Q for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DNRcGZG9VCey+RCXjFT/3nzg+eoPhsw8VV+4T8TIEPQ=; b=T97BhxVtfB13999Y3V3mF+81Jhy4jWQxwFMgeWSMD66CE+gzqsF0dDmZ7Aaw0Bhb7UeKe5 mtaRwYRCZR6ATA6UQD2IEHjRbLh4LSvqt3qA0EjgcvSv762Wctil0ITOM/VqbdFk0hEXwa afmtZsBivsq/IGWIQOlKWzzzaTDiQb4= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-HqeMUlXXNjCa1QNAXe7YHA-1; Thu, 27 Feb 2025 09:21:02 -0500 X-MC-Unique: HqeMUlXXNjCa1QNAXe7YHA-1 X-Mimecast-MFC-AGG-ID: HqeMUlXXNjCa1QNAXe7YHA_1740666061 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-abf16f47749so73159266b.0 for ; Thu, 27 Feb 2025 06:21:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666060; x=1741270860; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DNRcGZG9VCey+RCXjFT/3nzg+eoPhsw8VV+4T8TIEPQ=; b=Cxq34rnA5fZIXN/6ZHYBplt90slKQNRcUuGyWbnNV7ger9ryk0eCh+x33o1CJ3dcg+ aIl37LoWPommi5mY+IGAszrhMQnrbvvXNimr9Q/kABPulWnK05Prp0yepRaQ0RsL/vnP Is3Zde8DR9T45oZEPfDo2sLmdmAXK6cW2+3BvB3MeY9F2YvmIvSV+AxUTx0+XFSbshzC HKgTFnCSHztyL31uciFNWG4q0T/hmgz9GM6EiWJOIgeN9tuU6+hZaJcQmkF4wFMKLCyt eAxA0ZppQgasNdEcQeP3sq+rOyjISgtp5tirFo9lqJn47IpCstpBkmWvUWVOdhcDFR0i DJkQ== X-Gm-Message-State: AOJu0YziTFwJ5NxP5EBZiuO/vvIH7pVl3pCPX3ewWHX7wFJsR3TSV8Z9 ZcmpRUUDf9Fu+F9wK+oOCpCsfyuQKmadv/iG80MQQSPkysEo07j5MW/wF+TUysGYnYxH+t2kDfn ly44NqQrqLYxMkftz3zRIK4yMxuX9B7DBZ8hdIG0i38kTHSaPSi4p9toBL5iMJvaVPJaXLUy66s UOyiL+a9tatK2HG8tmOgdvgw2sw2nbeayRsPkcwwU= X-Gm-Gg: ASbGncu+yMYLQd9tKH9fPSNP++/o/Ehy/hV5ru0WxCWlb35dkGm67whnbk+9zaIEM1v kHrSPL/E+3F7dOdgZInuze/7nntCNgDIX1/bUnDoBSwwsUvSvaKfd+mBzDd5MDup6XBlolBUhYW 3ctJXausyXnjNmeTvkw/cbellWPEYyd6JlnxmJG8PR+6diBpFJU46S9oGDm4931NwG5/K3rsLWF DsoPQODow9fGUkapAoJtnp617UGtL1ujYyoVXubsxTHqoy6fKj5dmjRYDWqVpn8C5XZy/v+UAmM Q5Z731/X4fNrsOsjILKv X-Received: by 2002:a17:907:96ac:b0:ab7:d34a:8f83 with SMTP id a640c23a62f3a-abf0609c4d0mr495584566b.17.1740666060479; Thu, 27 Feb 2025 06:21:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTX43Of/Epghw8hmGmiD6O53NB4l4EKHhhOOXLQoiHx+uUS/N88FvCkGJmZEDfGpdAio5RTA== X-Received: by 2002:a17:907:96ac:b0:ab7:d34a:8f83 with SMTP id a640c23a62f3a-abf0609c4d0mr495580966b.17.1740666059998; Thu, 27 Feb 2025 06:20:59 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf1da15621sm48601066b.106.2025.02.27.06.20.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:20:57 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 30/34] target/riscv: move 128-bit check to TCG realize Date: Thu, 27 Feb 2025 15:19:48 +0100 Message-ID: <20250227141952.811410-31-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Besides removing non-declarative code in instance_init, this also fixes an issue with query-cpu-model-expansion. Just invoking it for the x-rv128 CPU model causes QEMU to exit immediately. With this patch it is possible to do {'execute': 'query-cpu-model-expansion', 'arguments':{'type': 'full', 'model': {'name': 'x-rv128'}}} Signed-off-by: Paolo Bonzini --- target/riscv/cpu.c | 7 ------- target/riscv/tcg/tcg-cpu.c | 9 +++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 0dcde546e47..d7ecf729d05 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -700,13 +700,6 @@ static void rv128_base_cpu_init(Object *obj) RISCVCPU *cpu = RISCV_CPU(obj); CPURISCVState *env = &cpu->env; - if (qemu_tcg_mttcg_enabled()) { - /* Missing 128-bit aligned atomics */ - error_report("128-bit RISC-V currently does not work with Multi " - "Threaded TCG. Please use: -accel tcg,thread=single"); - exit(EXIT_FAILURE); - } - cpu->cfg.mmu = true; cpu->cfg.pmp = true; diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 0a137281de1..d7e694fdb3d 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -1014,6 +1014,7 @@ static bool riscv_cpu_is_generic(Object *cpu_obj) static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp) { RISCVCPU *cpu = RISCV_CPU(cs); + RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu); if (!riscv_cpu_tcg_compatible(cpu)) { g_autofree char *name = riscv_cpu_get_name(cpu); @@ -1022,6 +1023,14 @@ static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp) return false; } + if (mcc->misa_mxl_max >= MXL_RV128 && qemu_tcg_mttcg_enabled()) { + /* Missing 128-bit aligned atomics */ + error_setg(errp, + "128-bit RISC-V currently does not work with Multi " + "Threaded TCG. Please use: -accel tcg,thread=single"); + return false; + } + #ifndef CONFIG_USER_ONLY CPURISCVState *env = &cpu->env; From patchwork Thu Feb 27 14:19:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B9F9C19F2E for ; Thu, 27 Feb 2025 14:33:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnem3-0002TA-81; Thu, 27 Feb 2025 09:22:03 -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 ) id 1tnelB-0007yX-8I for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnel8-0003sx-H2 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PQLxNgYdZM0KSbKDqppJfoYhlJo1A1+kCjsRcdbWf5w=; b=TGPc0Dh8XB0NcujX5PrtJB2CNrjNQJQWCM+nhuDA12dQqNrLSgU44E8prPV+1IsaKpPdi0 zKFrwIt+ehWPRYkbGY/zOZykJHjgJJLG6HRfauknCAtHeNwuAlxU8FDmqZK8QNIGVhDcte dNyIy7JNnQQaTyhGnHGCfvucV17oH1o= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-r8dWTlaUPMqaMfcGmY5pIg-1; Thu, 27 Feb 2025 09:21:04 -0500 X-MC-Unique: r8dWTlaUPMqaMfcGmY5pIg-1 X-Mimecast-MFC-AGG-ID: r8dWTlaUPMqaMfcGmY5pIg_1740666063 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5e4c2618332so1105360a12.2 for ; Thu, 27 Feb 2025 06:21:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666062; x=1741270862; 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=PQLxNgYdZM0KSbKDqppJfoYhlJo1A1+kCjsRcdbWf5w=; b=nnip8UO2AGKeyshov07r2CrDIBYYlEzdQD1u9vnF8mnv2rWmNW4+gC3CVQfNOu5tPD SdBrqzX8NxN6mEkaGeanqhNYniDZygT6I0BNpBohIyMC5VTAmuF2+9dBmlosueE9pAZs qgSQozUghOVK0EYzaJ7KBUIoihh1jU7foo8IvQVPkCJ6YORVY6DqoMNgzP61uJ1/Nobc NI9haKt+C61QjakU+VzPdb7ayy5MTYomiv+9w+j7LuzIsP1v1kDNk3hB+JlQahPWMD/P ZOs9bJcQB4OQmWvyHKsL35NJkDDlGHTQFQVliQV6usuvjYVK3oV1Ydkw8MHH2HxnbgSN uhyw== X-Gm-Message-State: AOJu0Yy8OS+tySohcXJ332Xg7foPhqoUyK1CjZ5ZWdobCXxbasLTV5bN muZUEix602Z5s5xvytzVaGYT2wHFI4QdLpg/4r2lR2YvY3/V5s3zE9oPY5geptJ/1SFGTklpf0O 07v1Ff5YSwMjPmCYMwJo3UObMQT2p0UyHlBXOpQ6UthotMo7igX4/uSB8h/fp41gwSjudo/qM7u 87/sItI0W4PSikEPIKeHgSKFiJkQalg92DMRmEu5g= X-Gm-Gg: ASbGncvSBxlysvgOc1pZIj/LOJtN/XURYrdyrjcpEeh7aELqjBHjI8IVQNJvwoHL5iU xWAWufAJhaQ/egHlo4aq3JAK1eAGJ4Wr1Ezxn8A9kaYPjBdqN9cr4eRRB/CLP2u/skSW68mhdw+ 67npcLX/kGopHIh1Q0ZGalKS2chXEK5nb6JuzhA08L3M1wcQq5anTum7HrxuezL6gTr7BxIE1m9 gHLx8NJMMmx9Xo41Br2IkXOIFQl3+NO7nVxlJS4fGLzxAVyBDBwImu8ZtKztTrVyvPEsqhiCtA3 o0HxhQ5MTqDix7uczUDF X-Received: by 2002:a05:6402:13d2:b0:5e0:2ce6:3d50 with SMTP id 4fb4d7f45d1cf-5e4a0dfc587mr8748723a12.23.1740666062366; Thu, 27 Feb 2025 06:21:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCxQV2zq3REPKF+9zeoHJgyF+JRF/UdepBUbu59xs1Yz8FPQaNnVqb30lOQv+FZCBkFCVC5Q== X-Received: by 2002:a05:6402:13d2:b0:5e0:2ce6:3d50 with SMTP id 4fb4d7f45d1cf-5e4a0dfc587mr8748697a12.23.1740666061853; Thu, 27 Feb 2025 06:21:01 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c3fb44dasm1162171a12.62.2025.02.27.06.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:21:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: EwanHai , Zhao Liu Subject: [PULL 31/34] target/i386: Add support for Zhaoxin CPU vendor identification Date: Thu, 27 Feb 2025 15:19:49 +0100 Message-ID: <20250227141952.811410-32-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: EwanHai Zhaoxin currently uses two vendors: "Shanghai" and "Centaurhauls". It is important to note that the latter now belongs to Zhaoxin. Therefore, this patch replaces CPUID_VENDOR_VIA with CPUID_VENDOR_ZHAOXIN1. The previous CPUID_VENDOR_VIA macro was only defined but never used in QEMU, making this change straightforward. Additionally, the IS_ZHAOXIN_CPU macro has been added to simplify the checks for Zhaoxin CPUs. Signed-off-by: EwanHai Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250113074413.297793-2-ewanhai-oc@zhaoxin.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index c67b42d34fc..4279cf5cdee 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1122,7 +1122,16 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); #define CPUID_VENDOR_AMD_3 0x444d4163 /* "cAMD" */ #define CPUID_VENDOR_AMD "AuthenticAMD" -#define CPUID_VENDOR_VIA "CentaurHauls" +#define CPUID_VENDOR_ZHAOXIN1_1 0x746E6543 /* "Cent" */ +#define CPUID_VENDOR_ZHAOXIN1_2 0x48727561 /* "aurH" */ +#define CPUID_VENDOR_ZHAOXIN1_3 0x736C7561 /* "auls" */ + +#define CPUID_VENDOR_ZHAOXIN2_1 0x68532020 /* " Sh" */ +#define CPUID_VENDOR_ZHAOXIN2_2 0x68676E61 /* "angh" */ +#define CPUID_VENDOR_ZHAOXIN2_3 0x20206961 /* "ai " */ + +#define CPUID_VENDOR_ZHAOXIN1 "CentaurHauls" +#define CPUID_VENDOR_ZHAOXIN2 " Shanghai " #define CPUID_VENDOR_HYGON "HygonGenuine" @@ -1132,6 +1141,15 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); #define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \ (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \ (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3) +#define IS_ZHAOXIN1_CPU(env) \ + ((env)->cpuid_vendor1 == CPUID_VENDOR_ZHAOXIN1_1 && \ + (env)->cpuid_vendor2 == CPUID_VENDOR_ZHAOXIN1_2 && \ + (env)->cpuid_vendor3 == CPUID_VENDOR_ZHAOXIN1_3) +#define IS_ZHAOXIN2_CPU(env) \ + ((env)->cpuid_vendor1 == CPUID_VENDOR_ZHAOXIN2_1 && \ + (env)->cpuid_vendor2 == CPUID_VENDOR_ZHAOXIN2_2 && \ + (env)->cpuid_vendor3 == CPUID_VENDOR_ZHAOXIN2_3) +#define IS_ZHAOXIN_CPU(env) (IS_ZHAOXIN1_CPU(env) || IS_ZHAOXIN2_CPU(env)) #define CPUID_MWAIT_IBE (1U << 1) /* Interrupts can exit capability */ #define CPUID_MWAIT_EMX (1U << 0) /* enumeration supported */ From patchwork Thu Feb 27 14:19:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54E0CC19F2E for ; Thu, 27 Feb 2025 14:28:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnelz-00023j-Vu; Thu, 27 Feb 2025 09:22:00 -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 ) id 1tnelC-00084L-Mn for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnelB-0003t9-0u for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+GiEaq4+igrWwP4fp+abzJc1rUXq1wsd/EYkNDp5ecs=; b=GCwsHdLoebe4X37KiLrWWMFum2gGutKHvocwa3uVtLk9JrOy1L4cPe2movJHRfTGts0FlU /Vv5htSy6LwxFHROf4r6olX5E2LNlqv6yNGB9P8b0zKbFxXnhTGkHI0Yla2PHzVbEeMLtR dgSPwGG3zKDatLLL1cm/fUjMLKhaEt8= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-ugK5z9jINDutf280NJIQVw-1; Thu, 27 Feb 2025 09:21:07 -0500 X-MC-Unique: ugK5z9jINDutf280NJIQVw-1 X-Mimecast-MFC-AGG-ID: ugK5z9jINDutf280NJIQVw_1740666066 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5e0573b9f60so1029310a12.3 for ; Thu, 27 Feb 2025 06:21:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666065; x=1741270865; 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=+GiEaq4+igrWwP4fp+abzJc1rUXq1wsd/EYkNDp5ecs=; b=kraINdXZPn4zoUg6TTcZBtPE3LPpBez9zJQNdiRotW3xayzFespWT63SB0DxI2R+sy mevGwoWiIVWyv1y/rCce9RAQpeGOTLLrihzGScbNDVT0Fd8t6dwOsoVl+GlnU3jrUi5t yGCsNZygOmzbsPRNsZ/cZhu+3CYi83kgi3i6/imAWhXh1o7vkjx2rCNaqNFLWdVVHaTq iLh1yGyeJWlKhp03DjuDSYQm32e81/APbjKP4oFQi5BiK7omm3QVyNudioegPzpmjoKk 4AmSnUEXQU+qCRBvYN/6SFPcAhfpdQJdCN6o145g1XpbOXDI5T52lVM2ubttRpoxxxWk nzSQ== X-Gm-Message-State: AOJu0YwLun2/rhx9f+4Xr0mlhZ+e8oPL4JQXkNqF/1LAQnjGn1JS4311 9KoWKfQ+YLpCNR4gubyVxLkZEMmjYTE8Dy83DVATOZxyrxqrHVUCqDlTagyEh447Kzj2wBKI8EK pLfypdtbHrjbOtklvpXCpLQBenQpNFj6MSmFijDtw/0UgZFaMxHG2s3A272stTo0mKBLdIMYN2d SOCOKAtxIoswj99k5Ykab1SHJdOwUpvqHt2276AZ4= X-Gm-Gg: ASbGncsfLTgO90X0V3ooGPPhwC438c1kIGQLO3YiHmVpuBajA5DvGan2hhfzvP/9Jtq 3WVwY+Jpi+t9bhjC6ZzOy/RV3lZCQXKdKuzEWzAX72G2nMDL1NTNRBayNnA7Zj8YnT9ouEElw0M JCxYJQL3kU4oUDXsj2/BizbTDIuOHqXQ24cs2hnXsRu09D9NEO3BVHsBa2DpDSuJozSQM7RDku1 RcQDbIPOq5NpxdnZ64rO3hKWMbWvxZOFd6j/80OCDU5dXWVLgTrw7ji6XXH7rkN9cMXfcDMBO5E +Fo4q907o8xBiga9US81 X-Received: by 2002:a05:6402:4008:b0:5e4:bf03:e907 with SMTP id 4fb4d7f45d1cf-5e4bf03eaafmr4860349a12.19.1740666065184; Thu, 27 Feb 2025 06:21:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAcqj9YSZaFkB+23AY/L7qncTTPWc3kca6m9MNiFg2ZmVIRlsguDOEk7M9XeRoVE8HbwzdBg== X-Received: by 2002:a05:6402:4008:b0:5e4:bf03:e907 with SMTP id 4fb4d7f45d1cf-5e4bf03eaafmr4860316a12.19.1740666064697; Thu, 27 Feb 2025 06:21:04 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c3fb6067sm1140683a12.50.2025.02.27.06.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:21:02 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: EwanHai , Zhao Liu Subject: [PULL 32/34] target/i386: Add CPUID leaf 0xC000_0001 EDX definitions Date: Thu, 27 Feb 2025 15:19:50 +0100 Message-ID: <20250227141952.811410-33-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: EwanHai Add new CPUID feature flags for various Zhaoxin PadLock extensions. These definitions will be used for Zhaoxin CPU models. Signed-off-by: EwanHai Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250113074413.297793-3-ewanhai-oc@zhaoxin.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 4279cf5cdee..10ce019e3f8 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1110,6 +1110,27 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); /* CPUID[0x80000007].EDX flags: */ #define CPUID_APM_INVTSC (1U << 8) +/* "rng" RNG present (xstore) */ +#define CPUID_C000_0001_EDX_XSTORE (1U << 2) +/* "rng_en" RNG enabled */ +#define CPUID_C000_0001_EDX_XSTORE_EN (1U << 3) +/* "ace" on-CPU crypto (xcrypt) */ +#define CPUID_C000_0001_EDX_XCRYPT (1U << 6) +/* "ace_en" on-CPU crypto enabled */ +#define CPUID_C000_0001_EDX_XCRYPT_EN (1U << 7) +/* Advanced Cryptography Engine v2 */ +#define CPUID_C000_0001_EDX_ACE2 (1U << 8) +/* ACE v2 enabled */ +#define CPUID_C000_0001_EDX_ACE2_EN (1U << 9) +/* PadLock Hash Engine */ +#define CPUID_C000_0001_EDX_PHE (1U << 10) +/* PHE enabled */ +#define CPUID_C000_0001_EDX_PHE_EN (1U << 11) +/* PadLock Montgomery Multiplier */ +#define CPUID_C000_0001_EDX_PMM (1U << 12) +/* PMM enabled */ +#define CPUID_C000_0001_EDX_PMM_EN (1U << 13) + #define CPUID_VENDOR_SZ 12 #define CPUID_VENDOR_INTEL_1 0x756e6547 /* "Genu" */ From patchwork Thu Feb 27 14:19:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD2F1C1B0FF for ; Thu, 27 Feb 2025 14:31:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnem4-0002d6-Kr; Thu, 27 Feb 2025 09:22:05 -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 ) id 1tnelF-00089U-PO for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnelD-0003tr-PH for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5VzTOknxE32oHEMhtjQjnFZQdG2DcQck0j4ELndUMhI=; b=M84gsF5lYMEdAN0h9PlsMCuOgNMe7Q+wP7wECmgM9O3FBxnOicPs+DHAYrt42/dHHO3NCc ZRJQ7o3F24QUzpYBbSa2CxDqRqNniKtidrr3e1BPJkjQP9FbzhMU07qsh+Wo/72lFwklUV Cl/RPqwN6MssfP71LPXiwNeX2mORUQ8= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-PSe-n2p7OmG_bcHjQ8CNww-1; Thu, 27 Feb 2025 09:21:10 -0500 X-MC-Unique: PSe-n2p7OmG_bcHjQ8CNww-1 X-Mimecast-MFC-AGG-ID: PSe-n2p7OmG_bcHjQ8CNww_1740666069 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-abba6d94ae4so127509366b.1 for ; Thu, 27 Feb 2025 06:21:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666067; x=1741270867; 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=5VzTOknxE32oHEMhtjQjnFZQdG2DcQck0j4ELndUMhI=; b=k9/c1D0TIvMI6r28zaGYNIvJZqWBFJuuuHtEBv5R3HriFP3+QRR6GIsAxD72VNp45O v5T9hUK9+JnWBA7kbWi4FMnhNnKV2XzLBLF5lhsPhaT9WSHq7C+lmKYVXcmYWqkC9/cf enPJ+ehJZY66RqYNd8bMh3y2PesIYcCGkwvIZhu5wCotUtQHjnwFfMC2AGbIJSWy4msT B+LpEWC5r9i0R2EudF+PFi1Bcji5tk5+QgL94NGCIiVf4t9Yizdg2hM12prUNeKJUsbN ysHX7adBpS8jkmzlkdpV6BhhyKFS92eNpyGKplLFbbtaeTYPy0v0+UJtPOSs3uGLgt9d emdQ== X-Gm-Message-State: AOJu0Yy6oXeLjm70codz9inTQ1wYebk1fp2MOmDbeSc371o+bWsVCltZ hXDy4Ez0+NvDhIN0ksiRTm/W+/Qb6RPerNh2U7Cuk1e1MIE0UXm4wECR3HUkImyU5Ol/4XLSKCj 3+rW9x/ZKdtWky24t9HRi4xjTl6+8IPlKSW9bO/pvT4h3QoYIKDSTLtYukbZUjcIeyS0VPBGhtx MFBVW4s6WkjvbG3u0DIMz6AhxAK9YtljYC94HxJj8= X-Gm-Gg: ASbGncvNVZQIlnUUMVwkvznaDSe5kB8kchW0jD6lDvKD9bB3VaVmytiAI+R/L/BqVfF n3ArlGl1o61J4r7ois/uACArfQLv3n0MBKLNXr2Q3zIn5SUoFFgDhvXeHhPbbJa+uXPcYlX+KVk MgGzj9DBUuC1yLqoqJT71M3loYlCOlfztgiO6N9vz534csxW/5LMJdkH/5kk5VUiLWTdI1mP/5Z xnesjTOjRO4jnC2cNzCseGBGXJRwYtez8eEgoNAtjhBLQbq44vCiYyr5RQkEe7yE1YPdR9w1Wsy GV4skt2KcBkALtZIno3J X-Received: by 2002:a17:906:b2c4:b0:abe:e2ac:62db with SMTP id a640c23a62f3a-abeeed11204mr818591366b.7.1740666067379; Thu, 27 Feb 2025 06:21:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4zDlUj+KSRuamWFMeKk5jI359XJn9cJ/SimUbTBFq53R8L8f5eXszAKxNcGNQbNRlVdrABw== X-Received: by 2002:a17:906:b2c4:b0:abe:e2ac:62db with SMTP id a640c23a62f3a-abeeed11204mr818589066b.7.1740666066980; Thu, 27 Feb 2025 06:21:06 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc150sm131359266b.61.2025.02.27.06.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:21:05 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: EwanHai , Zhao Liu Subject: [PULL 33/34] target/i386: Introduce Zhaoxin Yongfeng CPU model Date: Thu, 27 Feb 2025 15:19:51 +0100 Message-ID: <20250227141952.811410-34-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UPPERCASE_50_75=0.008 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: EwanHai Introduce support for the Zhaoxin Yongfeng CPU model. The Zhaoxin Yongfeng CPU is Zhaoxin's latest server CPU. This new cpu model ensure that QEMU can correctly emulate the Zhaoxin Yongfeng CPU, providing accurate functionality and performance characteristics. Signed-off-by: EwanHai Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250113074413.297793-4-ewanhai-oc@zhaoxin.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 2f9c604552b..bd407146136 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5498,6 +5498,130 @@ static const X86CPUDefinition builtin_x86_defs[] = { .model_id = "AMD EPYC-Genoa Processor", .cache_info = &epyc_genoa_cache_info, }, + { + .name = "YongFeng", + .level = 0x1F, + .vendor = CPUID_VENDOR_ZHAOXIN1, + .family = 7, + .model = 11, + .stepping = 3, + /* missing: CPUID_HT, CPUID_TM, CPUID_PBE */ + .features[FEAT_1_EDX] = + CPUID_SS | CPUID_SSE2 | CPUID_SSE | CPUID_FXSR | CPUID_MMX | + CPUID_ACPI | CPUID_CLFLUSH | CPUID_PSE36 | CPUID_PAT | CPUID_CMOV | + CPUID_MCA | CPUID_PGE | CPUID_MTRR | CPUID_SEP | CPUID_APIC | + CPUID_CX8 | CPUID_MCE | CPUID_PAE | CPUID_MSR | CPUID_TSC | + CPUID_PSE | CPUID_DE | CPUID_VME | CPUID_FP87, + /* + * missing: CPUID_EXT_OSXSAVE, CPUID_EXT_XTPR, CPUID_EXT_TM2, + * CPUID_EXT_EST, CPUID_EXT_SMX, CPUID_EXT_VMX + */ + .features[FEAT_1_ECX] = + CPUID_EXT_RDRAND | CPUID_EXT_F16C | CPUID_EXT_AVX | + CPUID_EXT_XSAVE | CPUID_EXT_AES | CPUID_EXT_TSC_DEADLINE_TIMER | + CPUID_EXT_POPCNT | CPUID_EXT_MOVBE | CPUID_EXT_X2APIC | + CPUID_EXT_SSE42 | CPUID_EXT_SSE41 | CPUID_EXT_PCID | + CPUID_EXT_CX16 | CPUID_EXT_FMA | CPUID_EXT_SSSE3 | + CPUID_EXT_MONITOR | CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSE3, + .features[FEAT_7_0_EBX] = + CPUID_7_0_EBX_SHA_NI | CPUID_7_0_EBX_SMAP | CPUID_7_0_EBX_ADX | + CPUID_7_0_EBX_RDSEED | CPUID_7_0_EBX_INVPCID | CPUID_7_0_EBX_BMI2 | + CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_BMI1 | + CPUID_7_0_EBX_FSGSBASE, + /* missing: CPUID_7_0_ECX_OSPKE */ + .features[FEAT_7_0_ECX] = + CPUID_7_0_ECX_RDPID | CPUID_7_0_ECX_PKU | CPUID_7_0_ECX_UMIP, + .features[FEAT_7_0_EDX] = + CPUID_7_0_EDX_ARCH_CAPABILITIES | CPUID_7_0_EDX_SPEC_CTRL, + .features[FEAT_8000_0001_EDX] = + CPUID_EXT2_LM | CPUID_EXT2_RDTSCP | CPUID_EXT2_PDPE1GB | + CPUID_EXT2_NX | CPUID_EXT2_SYSCALL, + .features[FEAT_8000_0001_ECX] = + CPUID_EXT3_3DNOWPREFETCH | CPUID_EXT3_ABM | CPUID_EXT3_LAHF_LM, + .features[FEAT_8000_0007_EDX] = CPUID_APM_INVTSC, + /* + * TODO: When the Linux kernel introduces other existing definitions + * for this leaf, remember to update the definitions here. + */ + .features[FEAT_C000_0001_EDX] = + CPUID_C000_0001_EDX_PMM_EN | CPUID_C000_0001_EDX_PMM | + CPUID_C000_0001_EDX_PHE_EN | CPUID_C000_0001_EDX_PHE | + CPUID_C000_0001_EDX_ACE2 | + CPUID_C000_0001_EDX_XCRYPT_EN | CPUID_C000_0001_EDX_XCRYPT | + CPUID_C000_0001_EDX_XSTORE_EN | CPUID_C000_0001_EDX_XSTORE, + .features[FEAT_XSAVE] = + CPUID_XSAVE_XSAVEOPT, + .features[FEAT_ARCH_CAPABILITIES] = + MSR_ARCH_CAP_RDCL_NO | MSR_ARCH_CAP_SKIP_L1DFL_VMENTRY | + MSR_ARCH_CAP_MDS_NO | MSR_ARCH_CAP_PSCHANGE_MC_NO | + MSR_ARCH_CAP_SSB_NO, + .features[FEAT_VMX_PROCBASED_CTLS] = + VMX_CPU_BASED_VIRTUAL_INTR_PENDING | VMX_CPU_BASED_HLT_EXITING | + VMX_CPU_BASED_USE_TSC_OFFSETING | VMX_CPU_BASED_INVLPG_EXITING | + VMX_CPU_BASED_MWAIT_EXITING | VMX_CPU_BASED_RDPMC_EXITING | + VMX_CPU_BASED_RDTSC_EXITING | VMX_CPU_BASED_CR3_LOAD_EXITING | + VMX_CPU_BASED_CR3_STORE_EXITING | VMX_CPU_BASED_CR8_LOAD_EXITING | + VMX_CPU_BASED_CR8_STORE_EXITING | VMX_CPU_BASED_TPR_SHADOW | + VMX_CPU_BASED_VIRTUAL_NMI_PENDING | VMX_CPU_BASED_MOV_DR_EXITING | + VMX_CPU_BASED_UNCOND_IO_EXITING | VMX_CPU_BASED_USE_IO_BITMAPS | + VMX_CPU_BASED_MONITOR_TRAP_FLAG | VMX_CPU_BASED_USE_MSR_BITMAPS | + VMX_CPU_BASED_MONITOR_EXITING | VMX_CPU_BASED_PAUSE_EXITING | + VMX_CPU_BASED_ACTIVATE_SECONDARY_CONTROLS, + /* + * missing: VMX_SECONDARY_EXEC_PAUSE_LOOP_EXITING, + * VMX_SECONDARY_EXEC_TSC_SCALING + */ + .features[FEAT_VMX_SECONDARY_CTLS] = + VMX_SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES | + VMX_SECONDARY_EXEC_ENABLE_EPT | VMX_SECONDARY_EXEC_DESC | + VMX_SECONDARY_EXEC_RDTSCP | VMX_SECONDARY_EXEC_ENABLE_VPID | + VMX_SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE | + VMX_SECONDARY_EXEC_WBINVD_EXITING | + VMX_SECONDARY_EXEC_UNRESTRICTED_GUEST | + VMX_SECONDARY_EXEC_APIC_REGISTER_VIRT | + VMX_SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY | + VMX_SECONDARY_EXEC_RDRAND_EXITING | + VMX_SECONDARY_EXEC_ENABLE_INVPCID | + VMX_SECONDARY_EXEC_ENABLE_VMFUNC | + VMX_SECONDARY_EXEC_SHADOW_VMCS | + VMX_SECONDARY_EXEC_ENABLE_PML, + .features[FEAT_VMX_PINBASED_CTLS] = + VMX_PIN_BASED_EXT_INTR_MASK | VMX_PIN_BASED_NMI_EXITING | + VMX_PIN_BASED_VIRTUAL_NMIS | VMX_PIN_BASED_VMX_PREEMPTION_TIMER | + VMX_PIN_BASED_POSTED_INTR, + .features[FEAT_VMX_EXIT_CTLS] = + VMX_VM_EXIT_SAVE_DEBUG_CONTROLS | VMX_VM_EXIT_HOST_ADDR_SPACE_SIZE | + VMX_VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | + VMX_VM_EXIT_ACK_INTR_ON_EXIT | VMX_VM_EXIT_SAVE_IA32_PAT | + VMX_VM_EXIT_LOAD_IA32_PAT | VMX_VM_EXIT_SAVE_IA32_EFER | + VMX_VM_EXIT_LOAD_IA32_EFER | VMX_VM_EXIT_SAVE_VMX_PREEMPTION_TIMER, + /* missing: VMX_VM_ENTRY_SMM, VMX_VM_ENTRY_DEACT_DUAL_MONITOR */ + .features[FEAT_VMX_ENTRY_CTLS] = + VMX_VM_ENTRY_LOAD_DEBUG_CONTROLS | VMX_VM_ENTRY_IA32E_MODE | + VMX_VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | + VMX_VM_ENTRY_LOAD_IA32_PAT | VMX_VM_ENTRY_LOAD_IA32_EFER, + /* + * missing: MSR_VMX_MISC_ACTIVITY_SHUTDOWN, + * MSR_VMX_MISC_ACTIVITY_WAIT_SIPI + */ + .features[FEAT_VMX_MISC] = + MSR_VMX_MISC_STORE_LMA | MSR_VMX_MISC_ACTIVITY_HLT | + MSR_VMX_MISC_VMWRITE_VMEXIT, + /* missing: MSR_VMX_EPT_UC */ + .features[FEAT_VMX_EPT_VPID_CAPS] = + MSR_VMX_EPT_EXECONLY | MSR_VMX_EPT_PAGE_WALK_LENGTH_4 | + MSR_VMX_EPT_WB | MSR_VMX_EPT_2MB | MSR_VMX_EPT_1GB | + MSR_VMX_EPT_INVEPT | MSR_VMX_EPT_AD_BITS | + MSR_VMX_EPT_INVEPT_SINGLE_CONTEXT | MSR_VMX_EPT_INVEPT_ALL_CONTEXT | + MSR_VMX_EPT_INVVPID_SINGLE_CONTEXT | MSR_VMX_EPT_INVVPID | + MSR_VMX_EPT_INVVPID_ALL_CONTEXT | MSR_VMX_EPT_INVVPID_SINGLE_ADDR | + MSR_VMX_EPT_INVVPID_SINGLE_CONTEXT_NOGLOBALS, + .features[FEAT_VMX_BASIC] = + MSR_VMX_BASIC_INS_OUTS | MSR_VMX_BASIC_TRUE_CTLS, + .features[FEAT_VMX_VMFUNC] = MSR_VMX_VMFUNC_EPT_SWITCHING, + .xlevel = 0x80000008, + .model_id = "Zhaoxin YongFeng Processor", + }, }; /* From patchwork Thu Feb 27 14:19:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13994662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3EE9C1B0FF for ; Thu, 27 Feb 2025 14:28:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnem7-0002t9-HW; Thu, 27 Feb 2025 09:22: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 ) id 1tnelL-0008N3-F5 for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnelI-0003uf-Fj for qemu-devel@nongnu.org; Thu, 27 Feb 2025 09:21:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740666075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cVvubKkZS2BJDfw7tQbs/X69Fi3+CKEkqZrpaVeftvc=; b=g9sTrzpxdfZELWJvCWLOPJg90D5ZVmYqFqzg+p0GDsKvpYE04XychCv07pyc7FPVs6qd1n VLREVuxuuuZr9oX8eY8SQE7Bt3/gmKud6V+Dn03YaHVMtI72+6ZumYxf0S6VrVtYuSUaXm Kx+JON5Bpwoz9nuCIlSWFLjI9AQTEZk= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-175--vbOxG-CMu-0UZz25Loznw-1; Thu, 27 Feb 2025 09:21:12 -0500 X-MC-Unique: -vbOxG-CMu-0UZz25Loznw-1 X-Mimecast-MFC-AGG-ID: -vbOxG-CMu-0UZz25Loznw_1740666072 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-abbc0572fc9so133364266b.0 for ; Thu, 27 Feb 2025 06:21:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740666071; x=1741270871; 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=cVvubKkZS2BJDfw7tQbs/X69Fi3+CKEkqZrpaVeftvc=; b=AxcnflNndxHESgcKDo1Cm52UbSOUKkIus5Ym+kPCrHeSt1Vy3CDKnWI0/IgR78kDbZ B5J9ykrMWS6tsAcNlx7Ale3jaL+pLnST4Ldm+SkaVkSoTEX9G6lqUBFNFqSCZUz21AUt OzVLXwEgvsX62QPOEgys28YT/hHdyOFIcpVSCSkNxoJNRWqrtCGLfYK9iDj3Bx+OgDLv gLapeFyijN08Hzdt06jYgEXr+8acnapr3KipYUw0Bm5eDvF77WB8/2ybKx2ytrMDnT1O u5iGLFlXCnFdpmyFZPT1gplgIE4KNFQo6SqyArGalJ3rkaNA+CmPrzMaoc60jLytxIXY 74Dg== X-Gm-Message-State: AOJu0YzJ7IbkTSzv5QpxS8tdhCvWhfLv26MAd2JrIyIbzcVJU2sb6d1L v7p+vOYFmjV2PB2fldxyEzbLJIr3GRCnkCnf/nV2TUe+2tYbO4tW7nSKNANyglVon4T1XkI/cT0 SkhEZ/0oAQGcboeKpovPI+brl8fmMhIz4+PCttXxGMnsl/PWtqZ+7BF0pWZk9kfzYCUYCZ960pW pKm6Gazmh13TBNOXDDJmXLtI/iRBhmEqSQepQcRCo= X-Gm-Gg: ASbGncvZJwenWgnO5EoeVA2Usyb8zWuEAXS0K5nAaAPL75hQpshPrAFYUeTV8l0lIX0 GXVlWrZGCMFrPHYVtfssFov67rye6B5z2oxznMvyKZcsmKe3s/ywc42AaLbCcrhc/sPPcYZYbrf Z6xP6fvOD67fBjuBm6Z9CfkqUEgjobQAohm9KzNb7eEDSFHEL2MGFjUNWS7Xpy6Kd1KvpxXnnYE c3ydmuimMNF+nB4Okqp4RTr8iyrou07nJegYTbOe16k7zc4GXurYeq/XPswqk0TCJLibPPGrrRD 2XBq2oTG42zJ6GK9xhiT X-Received: by 2002:a17:906:c00f:b0:ab7:b589:4f9e with SMTP id a640c23a62f3a-abc09c1a648mr2308367066b.39.1740666070913; Thu, 27 Feb 2025 06:21:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKgbYxuh+MB2gM/6flbYrUCoyOvV4GP3JqiNRJG+IufQ63cI4iQKOWSCRc0svq6y6TaSmeKw== X-Received: by 2002:a17:906:c00f:b0:ab7:b589:4f9e with SMTP id a640c23a62f3a-abc09c1a648mr2308363466b.39.1740666070450; Thu, 27 Feb 2025 06:21:10 -0800 (PST) Received: from [192.168.10.48] ([176.206.102.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf1f1d5b4csm39341366b.85.2025.02.27.06.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 06:21:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: EwanHai , Zhao Liu Subject: [PULL 34/34] target/i386: Mask CMPLegacy bit in CPUID[0x80000001].ECX for Zhaoxin CPUs Date: Thu, 27 Feb 2025 15:19:52 +0100 Message-ID: <20250227141952.811410-35-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250227141952.811410-1-pbonzini@redhat.com> References: <20250227141952.811410-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.438, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: EwanHai Zhaoxin CPUs (including vendors "Shanghai" and "Centaurhauls") handle the CMPLegacy bit similarly to Intel CPUs. Therefore, this commit masks the CMPLegacy bit in CPUID[0x80000001].ECX for Zhaoxin CPUs, just as it is done for Intel CPUs. AMD uses the CMPLegacy bit (CPUID[0x80000001].ECX.bit1) along with other CPUID information to enumerate platform topology (e.g., the number of logical processors per package). However, for Intel and other CPUs that follow Intel's behavior, CPUID[0x80000001].ECX.bit1 is reserved. - Impact on Intel and similar CPUs: This change has no effect on Intel and similar CPUs, as the goal is to accurately emulate CPU CPUID information. - Impact on Linux Guests running on Intel (and similar) vCPUs: During boot, Linux checks if the CPU supports Hyper-Threading. For the Linux kernel before v6.9, if it detects X86_FEATURE_CMP_LEGACY, it assumes Hyper-Threading is not supported. For Intel and similar vCPUs, if the CMPLegacy bit is not masked in CPUID[0x80000001].ECX, Linux will incorrectly assume that Hyper-Threading is not supported, even if the vCPU does support it. Signed-off-by: EwanHai Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250113074413.297793-5-ewanhai-oc@zhaoxin.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index bd407146136..0cd9b70938d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7804,9 +7804,10 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) /* * The Linux kernel checks for the CMPLegacy bit and * discards multiple thread information if it is set. - * So don't set it here for Intel to make Linux guests happy. + * So don't set it here for Intel (and other processors + * following Intel's behavior) to make Linux guests happy. */ - if (!IS_INTEL_CPU(env)) { + if (!IS_INTEL_CPU(env) && !IS_ZHAOXIN_CPU(env)) { env->features[FEAT_8000_0001_ECX] |= CPUID_EXT3_CMP_LEG; } }