From patchwork Fri Jan 24 09:43:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949161 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 A7795C0218C for ; Fri, 24 Jan 2025 09:45:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFG-0006I9-2I; Fri, 24 Jan 2025 04:44: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 1tbGFD-0006FN-UL for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:44:55 -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 1tbGF9-0003di-Kt for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:44:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711889; 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=I0AomW1l4KHfrFLmCQFbvJtiWPWMXEyRVqhKBkK9J0U=; b=IC6vZHsZgq8UniK/2/M3+MP1h+l0edorGAK8j+Y7tNxh+X1PvHQzLO68+3CMPUTzFd1gOH sOz9BWTYGq2NwZjq/mCOJzLcKlKBmdE/KghlYyFXjYP3Yq3/IV5LCWmKUeRedbqCGmArpv BmmOJWTsMiaFNfxUbj3abs+scbqD0is= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-249-Hkik6ykTPre9I7ak76WZxw-1; Fri, 24 Jan 2025 04:44:47 -0500 X-MC-Unique: Hkik6ykTPre9I7ak76WZxw-1 X-Mimecast-MFC-AGG-ID: Hkik6ykTPre9I7ak76WZxw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-436723bf7ffso13410885e9.3 for ; Fri, 24 Jan 2025 01:44:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711886; x=1738316686; 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=I0AomW1l4KHfrFLmCQFbvJtiWPWMXEyRVqhKBkK9J0U=; b=hgH437P3+3WIYzNLM834iAE1FxDASLbNemZ7hlFiiVVwjQqa3QhsG5/WZBWE7919Bs N8sZHZ98tjuQ1nQaqfG/EqT4SJPQTg+W5CuJHlP78YgBWKZNdPHIjkuBDp2SgMIz/C2C I6MShFc/cm6WW3fIlfyfYoknoCO0Rd6L3FxSbzVm9+Xv7fUpd9q34+VN2WKs9JvUgCZh j8b2jegX9LXqRB/NoEtaglvefWRlE3XTD5m31EiFlif8jxtZOTq4h3+ucea+5Bl2NojI xFhHlm61ynjP592QzQfgng6YhHW7ew42fI3CEODFyUUbKS1o7AmXYLOLstge4df9u0vb JcMA== X-Gm-Message-State: AOJu0Yy7tQXhN9zUB/hWrum2o32Hcd1Bq11JVMXrosn14vPZGUt08ZxI we9INf3vF4ozHFW0RS6BoYMiGZsrRmnfDcDzQdhPcCm5a6kPzZwcSMupDPX/AkeATGOTT2dTJcv Pr9E+8D1MtHBmZ1aB95PwTh8ji+E9OfwdeoKQ8Vjt5ym2CWtxpHPZggbPG/ZEt64rKUSgvreS3c mS5DUQ6JX4JUGZeO0yX3lQCl+3jvlCPXeVvCJX67Q= X-Gm-Gg: ASbGncvk4WXAU6w1EdiR9hSYrYvSE9KDTUt9VoyPeAa61JqbB1tgLLfM/udtnkC1FT/ /bwGMtWhrSmS5FBaqiENdmG7p0MccKNPRu1982ga4NR7dJHCEQ2V68oVGUoKo7+T+D6ij4SZLpE ze+vNP2Gha9O42tmYkJBb8PwIVYMcJT58uC0lq8WE9RkbcwWxjzULW9dIP3Tvux8kiml7/Zf+ol k7JfsbvbVKC1tznN9UcoqM0BZnUsgzLpP2ts1oDc8g0KC5iicAVa4BNKOE2EFOJH2PO+hDhpw== X-Received: by 2002:a05:600c:468d:b0:431:542d:2599 with SMTP id 5b1f17b1804b1-4389143b715mr263482075e9.22.1737711885877; Fri, 24 Jan 2025 01:44:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtYpfq86TqlsdTvONYYwiPM3ymHhxrk7p9ONPBPHO0lVsBIluOqPlON2PzaF5o6EBTQRaYLg== X-Received: by 2002:a05:600c:468d:b0:431:542d:2599 with SMTP id 5b1f17b1804b1-4389143b715mr263481875e9.22.1737711885464; Fri, 24 Jan 2025 01:44:45 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd54bfb0sm19669085e9.32.2025.01.24.01.44.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:44:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 01/48] rust: pl011: fix repr(C) for PL011Class Date: Fri, 24 Jan 2025 10:43:55 +0100 Message-ID: <20250124094442.13207-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 --- rust/hw/char/pl011/src/device.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 994c2fc0593..65a1234b9ff 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -123,6 +123,7 @@ pub struct PL011State { qom_isa!(PL011State : SysBusDevice, DeviceState, Object); +#[repr(C)] pub struct PL011Class { parent_class: ::Class, /// The byte string that identifies the device. From patchwork Fri Jan 24 09:43:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949164 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 BB39BC02181 for ; Fri, 24 Jan 2025 09:45:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFG-0006IA-2E; Fri, 24 Jan 2025 04:44: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 1tbGFE-0006G5-9j for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:44:56 -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 1tbGFC-0003dq-M6 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:44:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711892; 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=C+omDzyHoZTIzAUYMRxi5mDLkt7qKuTv7D0ZlYB6tvI=; b=YJazdJ1Qhr4WSAJt9HIcQ9WMWMQLawEHjCq4bGJR6DrpsGteDtmi/5ck7HpoRVnalTWD7n gWtyplwlIK+lWx2km62ATLvgQwPErDI7NmkyknZ0ifx2cbX+x6BbcuoFgyGGSuZVZXfTHF h9xWxI0/6mk605ClLRejds0RFtwjCOw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-7hifE_YkO8-P40tqEEvKSw-1; Fri, 24 Jan 2025 04:44:49 -0500 X-MC-Unique: 7hifE_YkO8-P40tqEEvKSw-1 X-Mimecast-MFC-AGG-ID: 7hifE_YkO8-P40tqEEvKSw Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-38bf4913669so1009534f8f.2 for ; Fri, 24 Jan 2025 01:44:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711888; x=1738316688; 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=C+omDzyHoZTIzAUYMRxi5mDLkt7qKuTv7D0ZlYB6tvI=; b=ltzQ2C8WZFFym/nFgY2cDlvN6LHH1Xywx03UViXOaL/cjyT17485BaYxbQ22kaa0tO 80AVnzvNBtTDOhaO1g7Cz1XzgB1HyXyuXgdYUaS/5w3zZ3VMyGwz5oeXqzUmsO/vok25 Gofh51TwdSHcxEZWpaDRM33EzQ+6+kOQTcT8ygdcDWNAOQCqqG2sb+XQLseQbsJ0q35D 5x5APF51yRMx5wV+l/zYbueNapzTeKpste2DUhhN6GStqyj2upPTI1tHJLajPN1c+MGs hPJuwLyejBHNG8X2yG+5Q5s6OBkmkniQfkcI/n04sok9FylpayhpZ5sIY0TuF0ozc87R 4WMQ== X-Gm-Message-State: AOJu0YwRNMDwm8T2AOekjIwb9GE39N6o6cp9x+6EmW2/D/sSABKKArYj k55evekpIvkCfs9f3pbHAcouvEahTwUph4kpL2ZSl9e+prmc6A8KGh3aK/OwDaNcha6fybj2Wqc eGXUR80I/a1bJjjcQWCOknXc++ffjqx5gvNUMzB82d6arakungDE+GVNmAkdGeBOsbqr6mVyAdy HZyrVZjuQQxfVkj4qDO7NeAvH0eoyF4USnPGI1fL8= X-Gm-Gg: ASbGncvxtxPdw0D+fmM57kxQUrP0QjXivW4s32CrJ4LB/R4OO0g8NAdZeKTEbtFtvMs exJiUl8UzyPzDCKcPSmieqUzDSuTK3ua+9PQFlUJdxZbqVz8iQJuTDU8cZXnt/3lfRdj+JgfiM3 ddo6NvMmldpYks0CU+/afUI4wASF3fBwfnNUJOQnkuegGjPBjDIcIPySppi43jEee9ELESv4OhX rd+ga5+Udljcoys77f0ac/5rvzszVDRssr6ErQOe+Tqhe02e7RJqXpnR9UNsw1/0p4STWOdtg== X-Received: by 2002:a5d:6650:0:b0:38b:ed0d:c1b0 with SMTP id ffacd0b85a97d-38bf57b41cemr24412400f8f.40.1737711887909; Fri, 24 Jan 2025 01:44:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRCY9OUKh8mTE8mS0BrKff1DNNelZch4BhAopUG1VNs5NS/ZuH7ObRdryjqz6groFJVsRxPw== X-Received: by 2002:a5d:6650:0:b0:38b:ed0d:c1b0 with SMTP id ffacd0b85a97d-38bf57b41cemr24412383f8f.40.1737711887448; Fri, 24 Jan 2025 01:44:47 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a17d6e2sm2159361f8f.23.2025.01.24.01.44.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:44:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 02/48] target/i386: inline gen_jcc into sole caller Date: Fri, 24 Jan 2025 10:43:56 +0100 Message-ID: <20250124094442.13207-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 code of gen_Jcc is very similar to gen_LOOP* and gen_JCXZ, but this is hidden by gen_jcc. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-2-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 8 -------- target/i386/tcg/emit.c.inc | 5 ++++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index dbc9d637c4b..3b68441a561 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1847,14 +1847,6 @@ static void gen_conditional_jump_labels(DisasContext *s, target_long diff, gen_jmp_rel(s, s->dflag, diff, 0); } -static void gen_jcc(DisasContext *s, int b, int diff) -{ - TCGLabel *l1 = gen_new_label(); - - gen_jcc1(s, b, l1); - gen_conditional_jump_labels(s, diff, NULL, l1); -} - static void gen_cmovcc1(DisasContext *s, int b, TCGv dest, TCGv src) { CCPrepare cc = gen_prepare_cc(s, b, NULL); diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index c4cc5f48d83..a193d32ca76 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -2297,8 +2297,11 @@ static void gen_IRET(DisasContext *s, X86DecodedInsn *decode) static void gen_Jcc(DisasContext *s, X86DecodedInsn *decode) { + TCGLabel *taken = gen_new_label(); + gen_bnd_jmp(s); - gen_jcc(s, decode->b & 0xf, decode->immediate); + gen_jcc1(s, decode->b & 0xf, taken); + gen_conditional_jump_labels(s, decode->immediate, NULL, taken); } static void gen_JCXZ(DisasContext *s, X86DecodedInsn *decode) From patchwork Fri Jan 24 09:43:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949163 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 6FC77C0218B for ; Fri, 24 Jan 2025 09:45:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFJ-0006RM-Ft; Fri, 24 Jan 2025 04:45:01 -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 1tbGFF-0006Hz-Ey for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:44:57 -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 1tbGFC-0003e0-Ms for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:44:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711894; 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=SWJ9yLcmbAXDT1ZuvmB0daQxa504eigEeoJOBFz9rfk=; b=VtFF8JyRj3W+0QlUtL0Zc5Dcz2aWKJII2pe+iQ3nThZqtuiAbEubMGGviFTd4Tc7+A1HcA W04m5AAUSJ07ZxrJoVOsh4JfMr4/lh4WfYgYL8dHmAACBbRtJod+IO9ImhtVm9xPyjtJ3N XJu8X9a6BaCNnMSQLJakBqB3qppyTEo= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-pKrj1jNrPLmWwzO96HP1OQ-1; Fri, 24 Jan 2025 04:44:51 -0500 X-MC-Unique: pKrj1jNrPLmWwzO96HP1OQ-1 X-Mimecast-MFC-AGG-ID: pKrj1jNrPLmWwzO96HP1OQ Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-386333ea577so722390f8f.1 for ; Fri, 24 Jan 2025 01:44:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711890; x=1738316690; 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=SWJ9yLcmbAXDT1ZuvmB0daQxa504eigEeoJOBFz9rfk=; b=hpUu2RwL4856J+F2JbWJHbMw44BjtVs03cFjPK3PTj/b8iSOZfhDAoOpB7Z0qwbiSM X6VwUIxwXi1sBOHiXbocoLZh9/Ms5ltLoaZLwxkaR5TATXe7kro7/2adM6K+24NUn3ce pSYvCNibtpEmjxgP1U3erVC7o4eh6gZy8DcPOJMcO4jeq+56VflDCXk9lzFqekaHhkcs RiYcv8n16BWlcBd7SGImpronOQza6j/XB7setIYobTU/hFtzBGY/vZ9Rh8+x6UpHzDRl fxM5jQGBelKAXQ4C0nbMCl5Hk6unuXls19B2i13I1aknhNbxoG3mFixBhkQUE3tJDK5V RFzg== X-Gm-Message-State: AOJu0Yzzav2YTzQGmEe7osUU9PUIiJpb2DTLzxNNzc8rU+kabbRWX7k3 SR1LRd3Jo6AEiKNFZz7D5Z9+LbGr/A2LNG4vG3oMGXftGXtaLd3PGZ1mOnzucozSaGmhEBJ4yp9 Fx9M+6D5XzKLk/WVLrsoB3OmczRFtD//BJyWRF9kUE8tocMt3AXTgqAw+Zx/0LZ1KGc1zo1PROx bXPi8TmcuIg4g5/LeUrnmB/SpfPnljvobZiXJKUOE= X-Gm-Gg: ASbGncupeUZV60T1UI6MrISuMtIatpSljnOc1uOJovFaBk5tbFtgD3iRraCiexCbTFk IfX985aICkOP+5DJxTHC2hbuGvktr+R7kA1KIqWR+6J1906Ab7xn5iaibbM7zSI0rLRcYRriEAF FDxfI64LTTgTloY4gENXsENmf4i1OpS2XJK5J4FwCyqnzo12ZUA1op12oxwx/wrvPaFpJSCeyPH 9VwoDvau1d767FVoArUFqagopflRWrlvM0VWg1xng2re3vjKedTs5kwnmjfXNP4KAVqxbFV7g== X-Received: by 2002:a05:6000:2ce:b0:38a:a117:3da1 with SMTP id ffacd0b85a97d-38bf566e683mr24833490f8f.5.1737711890282; Fri, 24 Jan 2025 01:44:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IH84xk42pimvTZVM6ee2tspeDvSBNHEYDaH+wi6dI33mYl2BG1cf15cQxl/wRb1Q+GKJLSXBg== X-Received: by 2002:a05:6000:2ce:b0:38a:a117:3da1 with SMTP id ffacd0b85a97d-38bf566e683mr24833456f8f.5.1737711889740; Fri, 24 Jan 2025 01:44:49 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd43cdbbsm21063845e9.0.2025.01.24.01.44.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:44:48 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 03/48] target/i386: remove trailing 1 from gen_{j, cmov, set}cc1 Date: Fri, 24 Jan 2025 10:43:57 +0100 Message-ID: <20250124094442.13207-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 is not needed anymore now that gen_jcc has been eliminated (merged into the similarly-named gen_Jcc, where the uppercase letter gives away that it is an emission function). Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-3-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 14 +++++++------- target/i386/tcg/emit.c.inc | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 3b68441a561..a2101b5615e 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1148,7 +1148,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int b, TCGv reg) return cc; } -static void gen_setcc1(DisasContext *s, int b, TCGv reg) +static void gen_setcc(DisasContext *s, int b, TCGv reg) { CCPrepare cc = gen_prepare_cc(s, b, reg); @@ -1170,12 +1170,12 @@ static void gen_setcc1(DisasContext *s, int b, TCGv reg) static inline void gen_compute_eflags_c(DisasContext *s, TCGv reg) { - gen_setcc1(s, JCC_B << 1, reg); + gen_setcc(s, JCC_B << 1, reg); } /* generate a conditional jump to label 'l1' according to jump opcode value 'b'. In the fast case, T0 is guaranteed not to be used. */ -static inline void gen_jcc1_noeob(DisasContext *s, int b, TCGLabel *l1) +static inline void gen_jcc_noeob(DisasContext *s, int b, TCGLabel *l1) { CCPrepare cc = gen_prepare_cc(s, b, NULL); @@ -1190,7 +1190,7 @@ static inline void gen_jcc1_noeob(DisasContext *s, int b, TCGLabel *l1) value 'b'. In the fast case, T0 is guaranteed not to be used. One or both of the branches will call gen_jmp_rel, so ensure cc_op is clean. */ -static inline void gen_jcc1(DisasContext *s, int b, TCGLabel *l1) +static inline void gen_jcc(DisasContext *s, int b, TCGLabel *l1) { CCPrepare cc = gen_prepare_cc(s, b, NULL); @@ -1337,7 +1337,7 @@ static void gen_repz_nz(DisasContext *s, MemOp ot, l2 = gen_jz_ecx_string(s); fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); - gen_jcc1(s, (JCC_Z << 1) | (nz ^ 1), l2); + gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2); if (s->repz_opt) { gen_op_jz_ecx(s, l2); } @@ -1847,7 +1847,7 @@ static void gen_conditional_jump_labels(DisasContext *s, target_long diff, gen_jmp_rel(s, s->dflag, diff, 0); } -static void gen_cmovcc1(DisasContext *s, int b, TCGv dest, TCGv src) +static void gen_cmovcc(DisasContext *s, int b, TCGv dest, TCGv src) { CCPrepare cc = gen_prepare_cc(s, b, NULL); @@ -2856,7 +2856,7 @@ static void gen_x87(DisasContext *s, X86DecodedInsn *decode) } op1 = fcmov_cc[op & 3] | (((op >> 3) & 1) ^ 1); l1 = gen_new_label(); - gen_jcc1_noeob(s, op1, l1); + gen_jcc_noeob(s, op1, l1); gen_helper_fmov_ST0_STN(tcg_env, tcg_constant_i32(opreg)); gen_set_label(l1); diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index a193d32ca76..861f0fb70f3 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1634,7 +1634,7 @@ static void gen_CMC(DisasContext *s, X86DecodedInsn *decode) static void gen_CMOVcc(DisasContext *s, X86DecodedInsn *decode) { - gen_cmovcc1(s, decode->b & 0xf, s->T0, s->T1); + gen_cmovcc(s, decode->b & 0xf, s->T0, s->T1); } static void gen_CMPccXADD(DisasContext *s, X86DecodedInsn *decode) @@ -2300,7 +2300,7 @@ static void gen_Jcc(DisasContext *s, X86DecodedInsn *decode) TCGLabel *taken = gen_new_label(); gen_bnd_jmp(s); - gen_jcc1(s, decode->b & 0xf, taken); + gen_jcc(s, decode->b & 0xf, taken); gen_conditional_jump_labels(s, decode->immediate, NULL, taken); } @@ -2451,7 +2451,7 @@ static void gen_LOOPE(DisasContext *s, X86DecodedInsn *decode) gen_update_cc_op(s); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); gen_op_jz_ecx(s, not_taken); - gen_jcc1(s, (JCC_Z << 1), taken); /* jz taken */ + gen_jcc(s, (JCC_Z << 1), taken); /* jz taken */ gen_conditional_jump_labels(s, decode->immediate, not_taken, taken); } @@ -2463,7 +2463,7 @@ static void gen_LOOPNE(DisasContext *s, X86DecodedInsn *decode) gen_update_cc_op(s); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); gen_op_jz_ecx(s, not_taken); - gen_jcc1(s, (JCC_Z << 1) | 1, taken); /* jnz taken */ + gen_jcc(s, (JCC_Z << 1) | 1, taken); /* jnz taken */ gen_conditional_jump_labels(s, decode->immediate, not_taken, taken); } @@ -3888,7 +3888,7 @@ static void gen_SCAS(DisasContext *s, X86DecodedInsn *decode) static void gen_SETcc(DisasContext *s, X86DecodedInsn *decode) { - gen_setcc1(s, decode->b & 0xf, s->T0); + gen_setcc(s, decode->b & 0xf, s->T0); } static void gen_SFENCE(DisasContext *s, X86DecodedInsn *decode) From patchwork Fri Jan 24 09:43:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949162 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 04F60C02181 for ; Fri, 24 Jan 2025 09:45:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFL-0006Ud-RG; Fri, 24 Jan 2025 04:45: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 1tbGFK-0006SQ-8n for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:02 -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 1tbGFF-0003eP-Hn for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711896; 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=dp8dzrQlvVxyn9uMuLYOc0nw+zdKZDXrocgw0Gg9Ryw=; b=Tvr4b8A2rOXxtbb22BqTVLBPkWlC+4HTd5GLsHOGzgbFKlu72ssxyvocKJnSPrJIq0QfT2 9Nv83fXaBdI2xmu6J0lecu7mBKJItTstCVzQ2b9GZjHrK9l82Hd96Fr7JDjc+qmeVw19Pk fV+uSjFpEbmAQSS9g/dUau01VJkXeok= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-fsS0SXd-OV2jkZt3HeVTjw-1; Fri, 24 Jan 2025 04:44:53 -0500 X-MC-Unique: fsS0SXd-OV2jkZt3HeVTjw-1 X-Mimecast-MFC-AGG-ID: fsS0SXd-OV2jkZt3HeVTjw Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385e3cbf308so742127f8f.2 for ; Fri, 24 Jan 2025 01:44:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711892; x=1738316692; 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=dp8dzrQlvVxyn9uMuLYOc0nw+zdKZDXrocgw0Gg9Ryw=; b=saqdWwxaROy1kOBLQBO08PiSZZYP9PFrFxRpu3CiMmRUMt/x4KjbydBGKT0is80iif JfjMcBObVrrnawGonOxgq/pF32oya3pfPynrCZBcU2Fex+GPOOGilWi1huzlC+rGEq1S 5bHrQbz6IUZ5WYh0Dv96cM4nKHJdt/u3OASwj+0sVkbl6wXjlgzaIW11NaHha4vFnJzk 8IOD50vLIcgqn4k5rs5hXeA7xAtZVuIGYbiFROLCXdAiFrSRUv1V/C1BdP1MzoYSYMCx OTEuBXSYwspghI4a7q3Tq9gi7Wvyk3o2zaiI8HhaMhPUehVZ0ajnXf6QVtMzm+gfbcok u9aQ== X-Gm-Message-State: AOJu0Yxf8NuHVk/Mt1p1gjbXoBxGVJtJpBJV/xxV1jcocooZUgX++X3/ 9oTMbaRM7b/PDNIvcC86avW1pHeW+AJbbMH3JffuN7DgeyeL6L68AoDJWZ10aVmJPrxQvizs7+Y +Aq/q2/75CThiUK4lPE/baWro/ibae54x8ADg3Q5ZwwnHYv+QJN0i3frp9Y21WhrncTQzegk7c0 XPsS9QvU3ooyyTIszULieBPa1PBLrKXtYWix/lHlI= X-Gm-Gg: ASbGncu2pj8AsR+kvXtG5gDlZLgeAXcjq4eDW1tQxd9jMo2/CnAHeS/x0y4dxp2lUWs ujwfxGjSFhHeKh0CV1MzRwa/Dhbglx5iAklGpVlcF7WtqyPSkdVbW2bk5fPUbgkUInGPXmjXBrd b4Kcf5nNXD2eDUn5Nkd+/9jC1oGEyUGyx/MwKC7PkMC6uBuTtw0DIW1Ornr6EtG1c3I/1Y6rmf3 0alhKB1DAgFRE/xBWX4aK05bkIPY+P/XNWRR197uFcCvaxl5ZhKcTZeJaMlZJfpH+BBP3rVNA== X-Received: by 2002:a05:6000:108d:b0:385:f677:8594 with SMTP id ffacd0b85a97d-38bf57a238bmr22440177f8f.43.1737711891871; Fri, 24 Jan 2025 01:44:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1ZAwRz96FyomgKkPJM8Qfs7hP9qYVJPjSCgqS49j9rpkidvHYASsM5yZG1MmFhaSnZCmqMQ== X-Received: by 2002:a05:6000:108d:b0:385:f677:8594 with SMTP id ffacd0b85a97d-38bf57a238bmr22440153f8f.43.1737711891431; Fri, 24 Jan 2025 01:44:51 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1ca723sm2135160f8f.101.2025.01.24.01.44.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:44:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 04/48] target/i386: unify REP and REPZ/REPNZ generation Date: Fri, 24 Jan 2025 10:43:58 +0100 Message-ID: <20250124094442.13207-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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, T_SPF_TEMPERROR=0.01 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 only differs in a single call to gen_jcc, so use a "bool" argument to distinguish the two cases; do not duplicate code. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-4-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 39 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index a2101b5615e..877b5846114 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1310,14 +1310,18 @@ static void gen_outs(DisasContext *s, MemOp ot) gen_bpt_io(s, s->tmp2_i32, ot); } -/* Generate jumps to current or next instruction */ -static void gen_repz(DisasContext *s, MemOp ot, - void (*fn)(DisasContext *s, MemOp ot)) +static void do_gen_rep(DisasContext *s, MemOp ot, + void (*fn)(DisasContext *s, MemOp ot), + bool is_repz_nz) { TCGLabel *l2; l2 = gen_jz_ecx_string(s); fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); + if (is_repz_nz) { + int nz = (s->prefix & PREFIX_REPNZ) ? 1 : 0; + gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2); + } /* * A loop would cause two single step exceptions if ECX = 1 * before rep string_insn @@ -1325,28 +1329,25 @@ static void gen_repz(DisasContext *s, MemOp ot, if (s->repz_opt) { gen_op_jz_ecx(s, l2); } + /* + * For CMPS/SCAS there is no need to set CC_OP_DYNAMIC: only one iteration + * is done at a time, so the translation block ends unconditionally after + * this instruction and there is no control flow junction. + */ gen_jmp_rel_csize(s, -cur_insn_len(s), 0); } +static void gen_repz(DisasContext *s, MemOp ot, + void (*fn)(DisasContext *s, MemOp ot)) + +{ + do_gen_rep(s, ot, fn, false); +} + static void gen_repz_nz(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot)) { - TCGLabel *l2; - int nz = (s->prefix & PREFIX_REPNZ) ? 1 : 0; - - l2 = gen_jz_ecx_string(s); - fn(s, ot); - gen_op_add_reg_im(s, s->aflag, R_ECX, -1); - gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2); - if (s->repz_opt) { - gen_op_jz_ecx(s, l2); - } - /* - * Only one iteration is done at a time, so the translation - * block ends unconditionally after this instruction and there - * is no control flow junction - no need to set CC_OP_DYNAMIC. - */ - gen_jmp_rel_csize(s, -cur_insn_len(s), 0); + do_gen_rep(s, ot, fn, true); } static void gen_helper_fp_arith_ST0_FT0(int op) From patchwork Fri Jan 24 09:43:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949170 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 384AAC0218B for ; Fri, 24 Jan 2025 09:47:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFK-0006St-Jo; Fri, 24 Jan 2025 04:45:02 -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 1tbGFI-0006Op-35 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:00 -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 1tbGFG-0003ea-BH for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:44:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711897; 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=yeuGoGuKTcvwqHXgxX9xaCBIJpyVFW8auKhsCDJr9O0=; b=Bp0M+uxTom5fqfqzfZ4DOkBr5T6az234bUU7Sr8ltdP/Tv91J2Tyqfq9Cu2ySrhbYh/Ogd diiQ4tYjs3aHMgfM/pYBByD5Blj8IlXR2UeJHB0zqzJCu1+KLIqUMA+9yfLekhG6hat9dg QPWUXGHdYzrHobqX5OalBNEoG8OVfRs= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-148-pwWiZI4HOYysMXAqEWjgjw-1; Fri, 24 Jan 2025 04:44:55 -0500 X-MC-Unique: pwWiZI4HOYysMXAqEWjgjw-1 X-Mimecast-MFC-AGG-ID: pwWiZI4HOYysMXAqEWjgjw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43673af80a6so13347885e9.1 for ; Fri, 24 Jan 2025 01:44:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711894; x=1738316694; 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=yeuGoGuKTcvwqHXgxX9xaCBIJpyVFW8auKhsCDJr9O0=; b=WVHOrjhGdc9VujpPDgytip/jAQvRsOlBjNa0Dbr2eIdQtACvY0G6iQ3KBd1M+24nIk DhVwYn224jaPnpAWBlqxmGVAHut1B0Nd3xVi8Ixd4JNE8FanR1WUS800PRnqwOT5NOJ2 7tEKYaBV6V9a4XXMD1HDmHgD+Ay9yL00N8Lhnflkm3SchYlNver6e3OoBouJhP6KA7fg gf+tBW8kLuLF0boITZAtbVAWXk+BX6vN2ZeqXrKIfcDQVcNZiSxqLeKJooxHkEX0DVM0 MMBPZVKxWPFF5tVQmwR8vGsX5H+jVYl47/jxWkerPZXOQMVdqodC4qgL8QBKRED8UxW0 tS1Q== X-Gm-Message-State: AOJu0Yxjet7Ky4RI43XM8zbDmchRkdT4fl2zFvqdtmeyk23n2UcNKtND OnwB5r2nKHIHtP416u3usb4dEqmgh3aICRrgrS3rmvUVf81Eyk4xl5kn5zehZDqYkVsWiC1IGim ji+kkabIagiRKZKYdeCV23ZA/m5Kgk4pz9B3+8cPaIuFyJ9l3IbgFMqq+LwxlLxz0NTZe+OBQi6 ZMCbqWgpOjMzGYopp/Q/JL8aZGgLauj7zKaJf8jfc= X-Gm-Gg: ASbGncucertvVi6UMJmtmkOkh41QeWIuLcOnNsqs1kwyJf2rMp0HAXz5MqAarZaiAVi IAgQfWO1USfEPKMJdhXSZo0g7TvV1dHDTmQG4cgfxwa+J9aXNwPKAzrNWiqZG3Im2QopDLgHWc7 dL1ZIyimiZKV6GWrsDX1+aEBB6wX+ApNr8hhqXdgKAqdl+ll9fPLxALWaqJ2CB3VVBxWouAI33M GVeBo2aKFWruXQqkGBt+vhgFD+0hesc8kXHXC/qkUUJ2wTQJgFeDKlLEe1kqKDe4aua/1EWiQ== X-Received: by 2002:a05:600c:1e18:b0:436:8a6f:b6db with SMTP id 5b1f17b1804b1-4389141c12emr237090245e9.22.1737711893392; Fri, 24 Jan 2025 01:44:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9134ho+c33aRXcw2WcMMOqRVvSNXc8G7fvS6ZJ7qrDk9hxSdq3axhWYGeDtEh2aObtmLWUw== X-Received: by 2002:a05:600c:1e18:b0:436:8a6f:b6db with SMTP id 5b1f17b1804b1-4389141c12emr237090005e9.22.1737711892948; Fri, 24 Jan 2025 01:44:52 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd57545dsm20122795e9.40.2025.01.24.01.44.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:44:52 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/48] target/i386: unify choice between single and repeated string instructions Date: Fri, 24 Jan 2025 10:43:59 +0100 Message-ID: <20250124094442.13207-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 same "if" is present in all generator functions for string instructions. Push it inside gen_repz() and gen_repz_nz() instead. Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241215090613.89588-5-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 12 +++++++++-- target/i386/tcg/emit.c.inc | 42 +++++++------------------------------ 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 877b5846114..3e46be8d78d 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1341,13 +1341,21 @@ static void gen_repz(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot)) { - do_gen_rep(s, ot, fn, false); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { + do_gen_rep(s, ot, fn, false); + } else { + fn(s, ot); + } } static void gen_repz_nz(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot)) { - do_gen_rep(s, ot, fn, true); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { + do_gen_rep(s, ot, fn, true); + } else { + fn(s, ot); + } } static void gen_helper_fp_arith_ST0_FT0(int op) diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 861f0fb70f3..3a28b0cb31b 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1743,11 +1743,7 @@ static void gen_CMPccXADD(DisasContext *s, X86DecodedInsn *decode) static void gen_CMPS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot = decode->op[2].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz_nz(s, ot, gen_cmps); - } else { - gen_cmps(s, ot); - } + gen_repz_nz(s, ot, gen_cmps); } static void gen_CMPXCHG(DisasContext *s, X86DecodedInsn *decode) @@ -2238,11 +2234,7 @@ static void gen_INS(DisasContext *s, X86DecodedInsn *decode) } translator_io_start(&s->base); - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_ins); - } else { - gen_ins(s, ot); - } + gen_repz(s, ot, gen_ins); } static void gen_INSERTQ_i(DisasContext *s, X86DecodedInsn *decode) @@ -2426,11 +2418,7 @@ static void gen_LGS(DisasContext *s, X86DecodedInsn *decode) static void gen_LODS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot = decode->op[1].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_lods); - } else { - gen_lods(s, ot); - } + gen_repz(s, ot, gen_lods); } static void gen_LOOP(DisasContext *s, X86DecodedInsn *decode) @@ -2628,11 +2616,7 @@ static void gen_MOVq_dq(DisasContext *s, X86DecodedInsn *decode) static void gen_MOVS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot = decode->op[2].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_movs); - } else { - gen_movs(s, ot); - } + gen_repz(s, ot, gen_movs); } static void gen_MUL(DisasContext *s, X86DecodedInsn *decode) @@ -2794,11 +2778,7 @@ static void gen_OUTS(DisasContext *s, X86DecodedInsn *decode) } translator_io_start(&s->base); - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_outs); - } else { - gen_outs(s, ot); - } + gen_repz(s, ot, gen_outs); } static void gen_PALIGNR(DisasContext *s, X86DecodedInsn *decode) @@ -3879,11 +3859,7 @@ static void gen_SBB(DisasContext *s, X86DecodedInsn *decode) static void gen_SCAS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot = decode->op[2].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz_nz(s, ot, gen_scas); - } else { - gen_scas(s, ot); - } + gen_repz_nz(s, ot, gen_scas); } static void gen_SETcc(DisasContext *s, X86DecodedInsn *decode) @@ -4089,11 +4065,7 @@ static void gen_STMXCSR(DisasContext *s, X86DecodedInsn *decode) static void gen_STOS(DisasContext *s, X86DecodedInsn *decode) { MemOp ot = decode->op[1].ot; - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - gen_repz(s, ot, gen_stos); - } else { - gen_stos(s, ot); - } + gen_repz(s, ot, gen_stos); } static void gen_SUB(DisasContext *s, X86DecodedInsn *decode) From patchwork Fri Jan 24 09:44:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949187 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 00FB5C0218C for ; Fri, 24 Jan 2025 09:49:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFO-0006Vc-4r; Fri, 24 Jan 2025 04:45:06 -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 1tbGFL-0006Ue-RK for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:03 -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 1tbGFJ-0003em-E6 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711900; 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=j2/9PlpXoOglUx6Dtwf/yi/v6/s//LvDY4FV96ReuTE=; b=dRpSfapTQ2z/uoovrWBP0ckNIPspWFB6GIQsxw+yZgq+i03Uit7n1GXNB1Bc6pjbfKrth5 NK9kojshkH2t9bcsMd1WjC3C5fdYw7mB5kAiyl2E7Ys7gvMUTa+6GHZo5/Fz9w0YMzdtAd /9xldqV+5s01qWz7b4A5I2vgfkc0TP8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-544-tf34eCvfO_qssvPXR-ZAxw-1; Fri, 24 Jan 2025 04:44:58 -0500 X-MC-Unique: tf34eCvfO_qssvPXR-ZAxw-1 X-Mimecast-MFC-AGG-ID: tf34eCvfO_qssvPXR-ZAxw Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4361c040ba8so10341515e9.1 for ; Fri, 24 Jan 2025 01:44:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711896; x=1738316696; 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=j2/9PlpXoOglUx6Dtwf/yi/v6/s//LvDY4FV96ReuTE=; b=Q049hsRyW+S1y0x+KSkq+dcuXDgSHY+0M9D/ij25lCLNMmWOsn7u6rirQS7s3tW/JG QNjRrIvc4/CQnP+tcoxpPf+IWwXuz+RG0SzXd7GgqZWsATW4WcvRCNUrBBs8HG7kv8B0 bUUFe4YRyn0VJ5PHviBzV4xkx8SHV0ucwPV6rVd3TuNFmTz7BrY/9Mz9ndXH1G/4kUZW nTV+MFrgKsO0Pz0m147KOuu7fx8ocU/4kADBfrGrauep2WAlpTxlJP6snuO1xblHi1JF QTa5wMwgvp/y9oeJyhejSa4Wav2a8h85gF2xvompGC3thxVGN1iV3ZLTU0GaBodd+Dc3 Ed5g== X-Gm-Message-State: AOJu0YymFXuMdOyQgA+oFJ8aid3ACNzIZb6B1OHCFiJ8KvRv2bPmkm5X d2oWw2/Pk2wgKVFnznr5pBe6Afp1Rb59sKylLPUzyEm0dIL5t3am+KMuHppTMgRgKMey0xcRxKj 2PIWbfizjE/53xTAuWmz8Vjs6SEyD9c0H7Y7D5xX3eTP/6rYdS4lqMbqK1KIqmIK8AzawfIeAfl 0NEE7ayQGObVMB+dMaSt19XtM44tHnhZBvT36NR/U= X-Gm-Gg: ASbGnctY5xjOhrX4uPZjepOckGwYAN3xYcG4A7tQUxZVvAx1tz577YujihxGLUUU9O9 sTcBEwcu+3xPO7E/vIk4MR05fBKLam0zrVM9exa9OixHbut34yndt92Np4xQnuSpaR5YAPWlOya 1VRCr542gPSRGB0F/TqfTNidYk+iY0Fsb+zM06BsU+2pUYkaflD6MUDfITm0ozA2IVLIPVrkyEN yHcYZItoiwHW/URRSCNtLG2K/uDt9GtUWCQzP7Dq4kTb4q0RLkfTIdYXhgpxIcVJ6g8vCDnSg== X-Received: by 2002:a05:600c:4ec8:b0:434:f219:6b28 with SMTP id 5b1f17b1804b1-43891435c37mr250640845e9.24.1737711896311; Fri, 24 Jan 2025 01:44:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRvUhnHMuyQTlvDEZ0+ojaSa7lft9wF4cm5O02j59lG6Eo7yPtrFx4cP7g5HO1SA13mpK7+g== X-Received: by 2002:a05:600c:4ec8:b0:434:f219:6b28 with SMTP id 5b1f17b1804b1-43891435c37mr250640335e9.24.1737711895658; Fri, 24 Jan 2025 01:44:55 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd54c098sm20178745e9.31.2025.01.24.01.44.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:44:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 06/48] target/i386: reorganize ops emitted by do_gen_rep, drop repz_opt Date: Fri, 24 Jan 2025 10:44:00 +0100 Message-ID: <20250124094442.13207-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 condition for optimizing repeat instruction is more or less the opposite of what you imagine: almost always the string instruction was _not_ optimized and optimizing the loop relied on goto_tb. This is obviously not great for performance, due to the cost of the exit-to-main-loop check, but also wrong. In fact, after expanding dc->jmp_opt and simplifying "!!x" to "x", the condition for looping used to be: ((cflags & CF_NO_GOTO_TB) || (flags & (HF_RF_MASK | HF_TF_MASK | HF_INHIBIT_IRQ_MASK))) && !(cflags & CF_USE_ICOUNT) In other words, setting aside RF (it requires special handling for REP instructions and it was completely missing), repeat instruction were being optimized if TF or inhibit IRQ flags were set. This is certainly wrong for TF, because string instructions trap after every execution, and probably for interrupt shadow too. Get rid of repz_opt completely. The next patches will reintroduce the optimization, applying it in the common case instead of the unlikely and wrong one. While at it, place the CX/ECX/RCX=0 case is at the end of the function, which saves a label and is clearer when reading the generated ops. For clarity, mark the cc_op explicitly as DYNAMIC even if at the end of the translation block; the cc_op can come from either the previous instruction or the string instruction, and currently we rely on a gen_update_cc_op() that is hidden in the bowels of gen_jcc() to spill cc_op and mark it clean. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-6-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 60 ++++++++----------------------------- 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 3e46be8d78d..ee536234398 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -113,7 +113,6 @@ typedef struct DisasContext { #endif bool vex_w; /* used by AVX even on 32-bit processors */ bool jmp_opt; /* use direct block chaining for direct jumps */ - bool repz_opt; /* optimize jumps within repz instructions */ bool cc_op_dirty; CCOp cc_op; /* current CC operation */ @@ -1206,23 +1205,6 @@ static inline void gen_jcc(DisasContext *s, int b, TCGLabel *l1) } } -/* XXX: does not work with gdbstub "ice" single step - not a - serious problem. The caller can jump to the returned label - to stop the REP but, if the flags have changed, it has to call - gen_update_cc_op before doing so. */ -static TCGLabel *gen_jz_ecx_string(DisasContext *s) -{ - TCGLabel *l1 = gen_new_label(); - TCGLabel *l2 = gen_new_label(); - - gen_update_cc_op(s); - gen_op_jnz_ecx(s, l1); - gen_set_label(l2); - gen_jmp_rel_csize(s, 0, 1); - gen_set_label(l1); - return l2; -} - static void gen_stos(DisasContext *s, MemOp ot) { gen_string_movl_A0_EDI(s); @@ -1314,27 +1296,25 @@ static void do_gen_rep(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot), bool is_repz_nz) { - TCGLabel *l2; - l2 = gen_jz_ecx_string(s); + TCGLabel *done = gen_new_label(); + + gen_update_cc_op(s); + gen_op_jz_ecx(s, done); + fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); if (is_repz_nz) { int nz = (s->prefix & PREFIX_REPNZ) ? 1 : 0; - gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2); + gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), done); } - /* - * A loop would cause two single step exceptions if ECX = 1 - * before rep string_insn - */ - if (s->repz_opt) { - gen_op_jz_ecx(s, l2); - } - /* - * For CMPS/SCAS there is no need to set CC_OP_DYNAMIC: only one iteration - * is done at a time, so the translation block ends unconditionally after - * this instruction and there is no control flow junction. - */ + + /* Go to the main loop but reenter the same instruction. */ gen_jmp_rel_csize(s, -cur_insn_len(s), 0); + + /* CX/ECX/RCX is zero, or REPZ/REPNZ broke the repetition. */ + gen_set_label(done); + set_cc_op(s, CC_OP_DYNAMIC); + gen_jmp_rel_csize(s, 0, 1); } static void gen_repz(DisasContext *s, MemOp ot, @@ -3665,20 +3645,6 @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) dc->cpuid_xsave_features = env->features[FEAT_XSAVE]; dc->jmp_opt = !((cflags & CF_NO_GOTO_TB) || (flags & (HF_RF_MASK | HF_TF_MASK | HF_INHIBIT_IRQ_MASK))); - /* - * If jmp_opt, we want to handle each string instruction individually. - * For icount also disable repz optimization so that each iteration - * is accounted separately. - * - * FIXME: this is messy; it makes REP string instructions a lot less - * efficient than they should be and it gets in the way of correct - * handling of RF (interrupts or traps arriving after any iteration - * of a repeated string instruction but the last should set RF to 1). - * Perhaps it would be more efficient if REP string instructions were - * always at the beginning of the TB, or even their own TB? That - * would even allow accounting up to 64k iterations at once for icount. - */ - dc->repz_opt = !dc->jmp_opt && !(cflags & CF_USE_ICOUNT); dc->T0 = tcg_temp_new(); dc->T1 = tcg_temp_new(); From patchwork Fri Jan 24 09:44:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949191 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 C1843C02181 for ; Fri, 24 Jan 2025 09:50:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFQ-0006Wi-Vf; Fri, 24 Jan 2025 04:45: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 1tbGFP-0006W2-7B for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:07 -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 1tbGFN-0003qe-A3 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711904; 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=JBevoGoFcg9Wd4iiTpRW0rHaDELMzFnRDJIXacwfsdU=; b=VJePcRwPgzwsmbBL//v/KrqodU55wgM1HgE0+ahWQPXJcIogXMe3zfQvvg9VYjbNuYu8FM FtTFHaf+RrCygBQ3l5xFw4fJCympq6BxP4FytPxrpITLM3qFPNbjlg1NppGCGIbNF69l81 2ARURjDOfOgvspn5uLCQJ4ALVLi3fZg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-cGnTO2R-MlyG0IEuuftqmg-1; Fri, 24 Jan 2025 04:45:01 -0500 X-MC-Unique: cGnTO2R-MlyG0IEuuftqmg-1 X-Mimecast-MFC-AGG-ID: cGnTO2R-MlyG0IEuuftqmg Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-38c24ac3415so1500725f8f.2 for ; Fri, 24 Jan 2025 01:45:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711900; x=1738316700; 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=JBevoGoFcg9Wd4iiTpRW0rHaDELMzFnRDJIXacwfsdU=; b=kj2DSyQQyaPQuW58LrY/UQwLPQ7kWumRdizBlfrvjq6154C0C1VyQI9gA+malwQ1+h XniMqxo8trBHxQRK/5rDQJUn7MGL4iCBaKsNIQXRNtUVJBtVb2BDKdh4Om8gbUDUJiLB RM9DGRiCHR+FHuyBls3KsSxVVIoyEm0/YnA4yt/MwUL8Pd2HEVzSHUt1p6M1uxQT+sL3 n+Qeji8fTAyiPl5DcMp8r+xj3xdseeNLz9cUH76fJXd149FWFvx/m8qPfmbbr2eBpWC6 dE4qQp2YcA8DuZ5BlpBsyPwDEeOW0dzwMZSXLGFkneg5UlsUW0/PrjCAt3my8S3jDEXm MQBg== X-Gm-Message-State: AOJu0YxHlvwcVOjb6gzTk7oF51LV3qHCY1ikpO1Nv53HmFOQZCJQMqrs sUYyjeVhMvsGfjlUUjZfO5djLruKYnnq7feKPzSCKMbSii0R8ppLkues53azgMk6dV9L9+JX421 VXC9R4+R4wzat3LF22f0N0gRL7VzLNnPvh9O2AfTk7RPj7KluGKPYSKm0YA+UW76G3ZOBhzUaZm nX1tE5yrABAvDFSnLzxtzBYgipWA8CCLRF/7MdS/Q= X-Gm-Gg: ASbGnctPzaj7szY4Qx06Jn19PrO/SSAbpyqiS/io5Q1x8/a6/c/1zVZHnT46kRk9Lhc 8VBbv2yvT1Q91DwWtRh55NMEIN7vlYAPy/vBMfosy4XCBorbjDFb4FHnUn1tqeQIxxCCoUD7dAt 404gJPJmdeeZowGGZ5Pzzt48naIm+0v4u8ej1hiZJUxMXkgWLS0RFaMo5Lp3we6NjxX3xV9pEC0 i/zwGQixX0dI1HLfuVjwomZRP+2yfKmOLBrbUDwSfTr/M4OT4xkDImuRQvHroIvICtrJUETXQ== X-Received: by 2002:a5d:59ab:0:b0:386:605:77e with SMTP id ffacd0b85a97d-38bf57beaebmr30842937f8f.49.1737711899645; Fri, 24 Jan 2025 01:44:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGupPXe6hHHo51ER4hJGbbh5egb8AnEQVVr6m9rE9XQTJUnUwc1W1oJgvSQM1+C7VmOYvL7Iw== X-Received: by 2002:a5d:59ab:0:b0:386:605:77e with SMTP id ffacd0b85a97d-38bf57beaebmr30842818f8f.49.1737711897663; Fri, 24 Jan 2025 01:44:57 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1761f4sm2171855f8f.20.2025.01.24.01.44.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:44:57 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 07/48] target/i386: tcg: move gen_set/reset_* earlier in the file Date: Fri, 24 Jan 2025 10:44:01 +0100 Message-ID: <20250124094442.13207-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 Allow using them in the code that translates REP/REPZ, without forward declarations. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-7-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 80 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index ee536234398..6347de446a4 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -725,6 +725,46 @@ static inline void gen_op_jnz_ecx(DisasContext *s, TCGLabel *label1) gen_op_j_ecx(s, TCG_COND_NE, label1); } +static void gen_set_hflag(DisasContext *s, uint32_t mask) +{ + if ((s->flags & mask) == 0) { + TCGv_i32 t = tcg_temp_new_i32(); + tcg_gen_ld_i32(t, tcg_env, offsetof(CPUX86State, hflags)); + tcg_gen_ori_i32(t, t, mask); + tcg_gen_st_i32(t, tcg_env, offsetof(CPUX86State, hflags)); + s->flags |= mask; + } +} + +static void gen_reset_hflag(DisasContext *s, uint32_t mask) +{ + if (s->flags & mask) { + TCGv_i32 t = tcg_temp_new_i32(); + tcg_gen_ld_i32(t, tcg_env, offsetof(CPUX86State, hflags)); + tcg_gen_andi_i32(t, t, ~mask); + tcg_gen_st_i32(t, tcg_env, offsetof(CPUX86State, hflags)); + s->flags &= ~mask; + } +} + +static void gen_set_eflags(DisasContext *s, target_ulong mask) +{ + TCGv t = tcg_temp_new(); + + tcg_gen_ld_tl(t, tcg_env, offsetof(CPUX86State, eflags)); + tcg_gen_ori_tl(t, t, mask); + tcg_gen_st_tl(t, tcg_env, offsetof(CPUX86State, eflags)); +} + +static void gen_reset_eflags(DisasContext *s, target_ulong mask) +{ + TCGv t = tcg_temp_new(); + + tcg_gen_ld_tl(t, tcg_env, offsetof(CPUX86State, eflags)); + tcg_gen_andi_tl(t, t, ~mask); + tcg_gen_st_tl(t, tcg_env, offsetof(CPUX86State, eflags)); +} + static void gen_helper_in_func(MemOp ot, TCGv v, TCGv_i32 n) { switch (ot) { @@ -2084,46 +2124,6 @@ static void gen_interrupt(DisasContext *s, uint8_t intno) s->base.is_jmp = DISAS_NORETURN; } -static void gen_set_hflag(DisasContext *s, uint32_t mask) -{ - if ((s->flags & mask) == 0) { - TCGv_i32 t = tcg_temp_new_i32(); - tcg_gen_ld_i32(t, tcg_env, offsetof(CPUX86State, hflags)); - tcg_gen_ori_i32(t, t, mask); - tcg_gen_st_i32(t, tcg_env, offsetof(CPUX86State, hflags)); - s->flags |= mask; - } -} - -static void gen_reset_hflag(DisasContext *s, uint32_t mask) -{ - if (s->flags & mask) { - TCGv_i32 t = tcg_temp_new_i32(); - tcg_gen_ld_i32(t, tcg_env, offsetof(CPUX86State, hflags)); - tcg_gen_andi_i32(t, t, ~mask); - tcg_gen_st_i32(t, tcg_env, offsetof(CPUX86State, hflags)); - s->flags &= ~mask; - } -} - -static void gen_set_eflags(DisasContext *s, target_ulong mask) -{ - TCGv t = tcg_temp_new(); - - tcg_gen_ld_tl(t, tcg_env, offsetof(CPUX86State, eflags)); - tcg_gen_ori_tl(t, t, mask); - tcg_gen_st_tl(t, tcg_env, offsetof(CPUX86State, eflags)); -} - -static void gen_reset_eflags(DisasContext *s, target_ulong mask) -{ - TCGv t = tcg_temp_new(); - - tcg_gen_ld_tl(t, tcg_env, offsetof(CPUX86State, eflags)); - tcg_gen_andi_tl(t, t, ~mask); - tcg_gen_st_tl(t, tcg_env, offsetof(CPUX86State, eflags)); -} - /* Clear BND registers during legacy branches. */ static void gen_bnd_jmp(DisasContext *s) { From patchwork Fri Jan 24 09:44:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949168 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 B9861C0218C for ; Fri, 24 Jan 2025 09:47:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFS-0006c3-QS; Fri, 24 Jan 2025 04:45: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 1tbGFP-0006W5-M9 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:07 -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 1tbGFN-0003qo-ST for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711905; 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=+SghbM/NNoU3iHbE0G8WtufvFOtxEQ/VfpTeyiNEP0U=; b=YCKCam1bOJTVJtd+V7uULcla1FWgqF4FxWYqcMoy1QKdKqNu1OJHbo3q7lrAsQnbbIkPWE EqYZdzVgmVmN2kHDgJv9GIcb0ZOo+mgwi9VauPuFIFFrf+TDnizqYT2W/jbbRM7u1oElKC Bp2tBmXa6ZqAwtr8/4aTs2wDYIrUfkE= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-I2KN4JB9P4SJNTP2ePNPRw-1; Fri, 24 Jan 2025 04:45:03 -0500 X-MC-Unique: I2KN4JB9P4SJNTP2ePNPRw-1 X-Mimecast-MFC-AGG-ID: I2KN4JB9P4SJNTP2ePNPRw Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-385fdff9db5so703000f8f.0 for ; Fri, 24 Jan 2025 01:45:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711901; x=1738316701; 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=+SghbM/NNoU3iHbE0G8WtufvFOtxEQ/VfpTeyiNEP0U=; b=JJCC+TAie0/kY9w6zloZb7JGzXJHxSAsY9TYoYBPpMCuGth5gMT4b2m62d3MXB3Sh5 FPA7RuEh9tMyI+LGLaaiG0w0hFXNlaSaDNG1XDygGQWzdhBU3feXrqtkBJqPI53tf1YJ BBEqcbT2+6A4IaXXG/S0ULoBWFAJXabJpNYArrvbg+rLq+0ktr9FlEmggsPQ+DDogosj YLaRz/Ngc0FggwAcJj7AUWaTCHxJgI+dwpk3WxDAzx2vrOc+3KNUq7ZKgF7LwdfOrpSn MZzNhujHNyqzFa/gvCHgIgRAEX3eaGLr0l43kWJXfMoLyMopjvzoeNyage/yNrSAzaAO R8Qg== X-Gm-Message-State: AOJu0Yw8MFNiyNVbxh/NMY6cnxwqGRMX7HzaemozDZ1yEIapbGS3o+nR J3UiBXiq27MtfeoxNZN/QUpUdnXChFzNI5dQRvA8XlqLfbRC/Q4ctJIsdQqfNYLonYYEZpSIN79 2YEoxTO/senh51TPQ4/iVOgYgU84A18N0vnUtu7kpJMlXFdtcgM8sswffGqyiXwNaSVBk+GtEK3 pgLeWEj1alOq847WSykfRkzRmif2fx77atuWc2Dl4= X-Gm-Gg: ASbGncthFJlRiklDTPMflh9dq6iS93SL3kmf3xKvRDfrGe9pAdnYd24zgM2OeUwI5NZ uyPIID975dACLt6PFzDWe7tVLsbiRpVxAbu2mkfjGX51JwZbl1Au6EbFRYX8ku1Hd++xpCt3vhp X3CVCM8eIUqlPJfDndAHUItVw9w1kZXygVR9ZopXCrG3fqrsruy8py699ofPC2/2Nc4hpC44DZq j/n8NK+JqT0TO6fb3TsY4LE21+BOmk6WatqUqSh4rQZFRhh63P5JfkFIqF2F96DNcJrREkS4w== X-Received: by 2002:a05:6000:4008:b0:38b:ed1c:a70d with SMTP id ffacd0b85a97d-38bf55c53c8mr25158537f8f.0.1737711901511; Fri, 24 Jan 2025 01:45:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGP6mTzQ9P75WlOcIRQYeRnExACSQStsulxTNCTTwCfHzLFazt6TftK2eCUAYqFBjkjpCLG8g== X-Received: by 2002:a05:6000:4008:b0:38b:ed1c:a70d with SMTP id ffacd0b85a97d-38bf55c53c8mr25158511f8f.0.1737711901074; Fri, 24 Jan 2025 01:45:01 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a188fd0sm2207866f8f.58.2025.01.24.01.44.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 08/48] target/i386: fix RF handling for string instructions Date: Fri, 24 Jan 2025 10:44:02 +0100 Message-ID: <20250124094442.13207-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 RF must be set on traps and interrupts from a string instruction, except if they occur after the last iteration. Ensure it is set before giving the main loop a chance to execute. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-8-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 6347de446a4..141295742ae 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1337,6 +1337,14 @@ static void do_gen_rep(DisasContext *s, MemOp ot, bool is_repz_nz) { TCGLabel *done = gen_new_label(); + bool had_rf = s->flags & HF_RF_MASK; + + /* + * Even if EFLAGS.RF was set on entry (such as if we're on the second or + * later iteration and an exception or interrupt happened), force gen_eob() + * not to clear the flag. We do that ourselves after the last iteration. + */ + s->flags &= ~HF_RF_MASK; gen_update_cc_op(s); gen_op_jz_ecx(s, done); @@ -1348,12 +1356,24 @@ static void do_gen_rep(DisasContext *s, MemOp ot, gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), done); } + /* + * Traps or interrupts set RF_MASK if they happen after any iteration + * but the last. Set it here before giving the main loop a chance to + * execute. (For faults, seg_helper.c sets the flag as usual). + */ + if (!had_rf) { + gen_set_eflags(s, RF_MASK); + } + /* Go to the main loop but reenter the same instruction. */ gen_jmp_rel_csize(s, -cur_insn_len(s), 0); /* CX/ECX/RCX is zero, or REPZ/REPNZ broke the repetition. */ gen_set_label(done); set_cc_op(s, CC_OP_DYNAMIC); + if (had_rf) { + gen_reset_eflags(s, RF_MASK); + } gen_jmp_rel_csize(s, 0, 1); } @@ -2158,7 +2178,7 @@ gen_eob(DisasContext *s, int mode) gen_set_hflag(s, HF_INHIBIT_IRQ_MASK); } - if (s->base.tb->flags & HF_RF_MASK) { + if (s->flags & HF_RF_MASK) { gen_reset_eflags(s, RF_MASK); } if (mode == DISAS_EOB_RECHECK_TF) { From patchwork Fri Jan 24 09:44:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949167 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 8AFDCC02181 for ; Fri, 24 Jan 2025 09:47:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFT-0006cR-3R; Fri, 24 Jan 2025 04:45: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 1tbGFR-0006aJ-Pt for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45: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 1tbGFQ-0003rL-4H for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711907; 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=2/THGezMiwi4jd00Cw/rtHI0MwkPkicDfVIV0NnRNVM=; b=cKrHQxTjOxS7l5IMq43RpzyXixoXbgOyarYyjQM4L/KMkJOpi7kmun/YFWo3E2hb9J0DdW S0QYed/N7d+iRFgc6CwMHSoU8/k3zFq3e87fjkLjwj+cyxYhIUzS3BpaovfK5aUVgmGB+2 LADI+Rw5ncZ5vGS7sUvtCT8RzdQlUOQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-0bgactGPOPG3-1s6oVbPTA-1; Fri, 24 Jan 2025 04:45:05 -0500 X-MC-Unique: 0bgactGPOPG3-1s6oVbPTA-1 X-Mimecast-MFC-AGG-ID: 0bgactGPOPG3-1s6oVbPTA Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38639b4f19cso1281641f8f.0 for ; Fri, 24 Jan 2025 01:45:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711903; x=1738316703; 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=2/THGezMiwi4jd00Cw/rtHI0MwkPkicDfVIV0NnRNVM=; b=wBmc834/Y4GkNcIKgt+bct6a+BZXDf8bRn+RIRjwtHKQ0RThVbCrhOgowcK805EUbJ KaRU1l55fDi1/vT12O67xzr6LYVhs33wpgfiTRF9wYmGGswXwwJM5gDGCCGGz6tyDY0Z VWFr7IWWBTjbBfmhrujIjbsZD0iT7uxUZJaCsHj04e0/SF2GMJZcAu1WegTzNuCH5Zq+ dCe4ay8zSxqsush055aTTbPK0B8qKUpUHeKvu2UqyT7hfG9IsDbVp8i+IdfuL9QHavSQ rKc/DT3ozUpdFMVZWzWKVaH47ALfnusL+kRkTc59+ey+9UNui52IdzmCx+SPsBtIDsK2 j+iA== X-Gm-Message-State: AOJu0YzjzMbcOkstouzE6vkQTRPizBMCc55Ld7ksuqsc22Pl2i2G4Y/J 8zoICwTAamyyFrCmDlVWMdBfQ1yckYjPYQVAw7fvTl89QEYxVBrErn7W9i+KOMN0DA2tFwVcfzT 20hZ840l5oM0QcC2NSmr3T/gnWUkSJ+TgIY3sJylZuyfAaiJxgIyozGTOGHuU0qr1ZHX/1EK+LI YAed08BAOuoAskyBgWeZ5Ryk7rqxaJ5v2itIZ4LVM= X-Gm-Gg: ASbGncsCGC9ke7vZyyxT/4hn/QTafmI6S6fGVL2MZBSkuSfEV5BmlGHiCrwoyJK1SY0 GMCukV5oj2nJgUKxL+DFyNDogrDxmEk+c8z6IwLd6Rm+9d/8wO97wOeMRUKd7hELQR3zlOpr62p 4jGLTGR/I1SXvUbVrE4AhNJGgQ6IViou0lHdE9/qAs5LuNABxzRBHwQSHSlolnwtYylJetjgT5q gSeZNqJEVg4kIlyl2FnLsO2Y4T9/RwsT6izRbMMIzywr0SPS2gZ6r1eCGbf7yKqfn4jn6ytWg== X-Received: by 2002:a05:6000:1786:b0:385:d7f9:f16c with SMTP id ffacd0b85a97d-38bf57be11bmr30979858f8f.46.1737711903508; Fri, 24 Jan 2025 01:45:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlSx1i36sHZuvyoOUw6cTHUCqalxbDDbcjrkFrQhixhiZ62bBgiLTe61yCM/3mfh/fzk0AbQ== X-Received: by 2002:a05:6000:1786:b0:385:d7f9:f16c with SMTP id ffacd0b85a97d-38bf57be11bmr30979819f8f.46.1737711903057; Fri, 24 Jan 2025 01:45:03 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a18867esm2130345f8f.43.2025.01.24.01.45.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 09/48] target/i386: make cc_op handling more explicit for repeated string instructions. Date: Fri, 24 Jan 2025 10:44:03 +0100 Message-ID: <20250124094442.13207-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Since the cost of gen_update_cc_op() must be paid anyway, it's easier to place them manually and not rely on spilling that is buried under multiple levels of function calls. While at it, clarify the circumstances in which the gen_update_cc_op() is needed, and why it is not for REPxx SCAS and REPxx CMPS. And since cc_op will have been spilled at the point of a fault, just make the whole insn CC_OP_DYNAMIC. Once repz_opt is reintroduced, a fault could happen either before or after the first execution of CMPS/SCAS, and CC_OP_DYNAMIC sidesteps the complicated matter of what x86_restore_state_to_opc would do. Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241215090613.89588-9-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 141295742ae..8bc91c3de31 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1234,8 +1234,9 @@ static inline void gen_jcc(DisasContext *s, int b, TCGLabel *l1) CCPrepare cc = gen_prepare_cc(s, b, NULL); /* - * Note that this must be _after_ gen_prepare_cc, because it - * can change the cc_op from CC_OP_DYNAMIC to CC_OP_EFLAGS! + * Note that this must be _after_ gen_prepare_cc, because it can change + * the cc_op to CC_OP_EFLAGS (because it's CC_OP_DYNAMIC or because + * it's cheaper to just compute the flags)! */ gen_update_cc_op(s); if (cc.use_reg2) { @@ -1346,14 +1347,31 @@ static void do_gen_rep(DisasContext *s, MemOp ot, */ s->flags &= ~HF_RF_MASK; + /* + * For CMPS/SCAS, the CC_OP after a memory fault could come from either + * the previous instruction or the string instruction; but because we + * arrange to keep CC_OP up to date all the time, just mark the whole + * insn as CC_OP_DYNAMIC. + * + * It's not a problem to do this even for instructions that do not + * modify the flags, so do it unconditionally. + */ gen_update_cc_op(s); + tcg_set_insn_start_param(s->base.insn_start, 1, CC_OP_DYNAMIC); + + /* Any iteration at all? */ gen_op_jz_ecx(s, done); fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); + gen_update_cc_op(s); + + /* Leave if REP condition fails. */ if (is_repz_nz) { int nz = (s->prefix & PREFIX_REPNZ) ? 1 : 0; - gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), done); + gen_jcc_noeob(s, (JCC_Z << 1) | (nz ^ 1), done); + /* gen_prepare_eflags_z never changes cc_op. */ + assert(!s->cc_op_dirty); } /* From patchwork Fri Jan 24 09:44:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949175 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 2622DC0218B for ; Fri, 24 Jan 2025 09:47:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFc-0006mR-H7; Fri, 24 Jan 2025 04:45:20 -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 1tbGFU-0006di-6A for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45: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 1tbGFS-0003rk-F6 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711909; 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=S+EjvWyBBLr0j+Oba7qUT580r4IhKj6r/hq6xSJZJ4U=; b=akA93CrsLdp/2T1UXBM4IpPrD+mIhFG1ycQ+eZoKWV3KUAGG8mSy30hlkhMsnHw2DxjSs5 LlOaDg0DOnGqdalPdB9n6NcWK2wEx6iG+FF6Z+F0OW8Pb4JkI+pafclATXEICNL2e79BjG ze6dcUWfkGCf0A7XN78L0YU9yWKcSDw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-nGhk_kT6PpWh_5hi8ennjw-1; Fri, 24 Jan 2025 04:45:07 -0500 X-MC-Unique: nGhk_kT6PpWh_5hi8ennjw-1 X-Mimecast-MFC-AGG-ID: nGhk_kT6PpWh_5hi8ennjw Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-38a35a65575so1231115f8f.1 for ; Fri, 24 Jan 2025 01:45:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711905; x=1738316705; 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=S+EjvWyBBLr0j+Oba7qUT580r4IhKj6r/hq6xSJZJ4U=; b=knRqqf6WpbaorqKkTAHsyf6jP3OqdIbeVe6jWT/JOQnpsFjQiUTobQl+g+4uzzsd3d tyrPdPli+hz3NQHP+XmmeaGu1+tXb7dnpzyaRxjHgDCkNMfVPpVqumdvGpjmvIE7n09q NZ/ntwWNv3jyAf1MNHJ1WX1zUdMcnWS3ibmMHyDYgqDWejtCbQYquQO2Gk9yUv/dForO uUbFNCobj0J9xymfHd54Q6CYWChhU/bBbkvXqOTcwAcwXYeGb5bAeSWjfyhJciV4XDjd wFBC0Z0SnlTMo2vAkeKWcrygdgmXQ4AQoe7aMCDFLFKrmq3mB5+W6kGIlv4t3HkaxpgF /fVQ== X-Gm-Message-State: AOJu0YwhEwRP8w5kR+crIa6SISnN/IIjCyQvNdRXBqrYNnpFKpKtBavG aBjIEDoSgBJVRdfEVpvMnt84PM+VI05f4znNvijerFQk9Tzq7tEaKPcMZsyC4OaFGrgiyiDygfs 4a37zt0tojDCpuWRi+soYFbWI08a8yhyA+dlA2erfB0vKIpI+yKhYAzXCZgs8R6dGIfg3ZFDl4r 7bUNrVUfNH4XlS62+7dwQc35H9P27QcFH77fW1aSo= X-Gm-Gg: ASbGncu+oxsXuUCPLwLkbo9/x9hCLS3zbbmVCpP8NAeaGMNzNxuH4P54rGPbN1sR4qw CPnc+QKe7IRpn284AjmBoOyte9MDabmnpiOK1jCOkbbYeZt9U3aQMVU+uzgXU13xZOlne7Tpyu2 +reJsY9JDe7LHJgZvkSP7VyKFrHwpwc17zrF5mA0IcgtIjO85XxFL8my1YzaH7c8JC/bSpAZuk/ jxsDckSZ1yNeOm3PNDmr/q8Rl3a1CoLp8Vv8TuycXIme0zNMdFMc9hZ4Ll27mgl0Rjf04FIoQ== X-Received: by 2002:a05:6000:18a7:b0:386:4312:53ec with SMTP id ffacd0b85a97d-38bf5663683mr28192927f8f.17.1737711905568; Fri, 24 Jan 2025 01:45:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFn2BYucTSAWxjnLcS3iUiS8XF8nq//l8IrLbf4kksWUcyoKXYKV0x+Rio1bYTuFrVvTK9TLQ== X-Received: by 2002:a05:6000:18a7:b0:386:4312:53ec with SMTP id ffacd0b85a97d-38bf5663683mr28192893f8f.17.1737711905037; Fri, 24 Jan 2025 01:45:05 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a188689sm2174083f8f.48.2025.01.24.01.45.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 10/48] target/i386: do not use gen_op_jz_ecx for repeated string operations Date: Fri, 24 Jan 2025 10:44:04 +0100 Message-ID: <20250124094442.13207-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 Explicitly generate a TSTEQ branch (which is optimized to NE x,0 if possible). This does not make much sense yet, but later we will add more checks and some will use a temporary to check on the decremented value of CX/ECX/RCX; it will be clearer for all checks to share the same logic using TSTEQ(reg, cx_mask). Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-10-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 8bc91c3de31..7a3caf8b996 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1338,6 +1338,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, bool is_repz_nz) { TCGLabel *done = gen_new_label(); + target_ulong cx_mask = MAKE_64BIT_MASK(0, 8 << s->aflag); bool had_rf = s->flags & HF_RF_MASK; /* @@ -1360,7 +1361,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, tcg_set_insn_start_param(s->base.insn_start, 1, CC_OP_DYNAMIC); /* Any iteration at all? */ - gen_op_jz_ecx(s, done); + tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cpu_regs[R_ECX], cx_mask, done); fn(s, ot); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); From patchwork Fri Jan 24 09:44:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949174 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 0A8E8C02181 for ; Fri, 24 Jan 2025 09:47:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFd-0006od-O7; Fri, 24 Jan 2025 04:45:21 -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 1tbGFV-0006ev-5G for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:18 -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 1tbGFT-0003ru-Ih for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711910; 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=D1rO3vXe0bS4eUZYDa0eLCYPsVdQibP8a4QBB0eAkTo=; b=b1pukGYe0CvGQCtIU+NcqJLS1ytzqOKb6jZB82J6VC4RZ/tt3WiiuMW8dybd4mQcdNlFel KVlxCfA4CO8TUiSE0V5S6Yx+dzILbG3gQEZ/3NqXkWgNtq2CWDyli8Vb55pB40mai0v+Se QRr+8gW/9ZqSa9yJs4JUoiKEK+HQ/Ug= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-8xXTxqu4OzmazvydXQCovg-1; Fri, 24 Jan 2025 04:45:08 -0500 X-MC-Unique: 8xXTxqu4OzmazvydXQCovg-1 X-Mimecast-MFC-AGG-ID: 8xXTxqu4OzmazvydXQCovg Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38bf4913659so1541120f8f.1 for ; Fri, 24 Jan 2025 01:45:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711906; x=1738316706; 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=D1rO3vXe0bS4eUZYDa0eLCYPsVdQibP8a4QBB0eAkTo=; b=LTI6+qnpUhgoyu5+ySC2gege4YSzEEkoxRE2Tnk3lLfWBErT2di0WEOCxIERwIwVmh 79RjrbkslllXBejF611ycaGVCoPs5hjKbnyKvEZnZ1qOJMs+QS4hhm2f5Dqy+BbboGvw u0yDMcnpmpI9sP0Zir1wuzlcFaVsK4nf/5cHtmhtdM4SDb2AfHAXdGpFOVtK2P1mwI8D 6ri/GBCyQN5YpiBw7evRp+ptlRQkHIyIktlx/N3bg57ScHDyAFdE3J5X3hHmnjz1fJV4 OPmqCHm6ggAQ7KAVJpWw52IYnjURq7TUU87WpjRlLSqVDxwYW9KzmJF8Td36cm729Wc0 2Viw== X-Gm-Message-State: AOJu0YzXAfxzGG/AmvnXh9RNfj+ZxCK44wdXkNOI9UGuD3Jo3qzvk5Bp WBjUtQ2X4TjXWKNXc705Z5cPso0ARmMS5VE8U/3GM6vZT+rFonZckpoUeXbSsZ5r2MklMtZaiAP l/Td5KwIgnL/+fFHDn/9tkHbu7SLDPEM0BT/+dZNYq8bPJib5gMqcZQ+di4+bMVfzlcD9vPuELw j85G/LQkurpZJWa6qD5GMWkY4G/QJKZCDvXOx83zY= X-Gm-Gg: ASbGncsKnEj/I8LORHXvTFWuJD1DAAELXGx+PDwcOrA5UgncB6fBHnnXQT+LlMBrinG FYxoVLplWFJo3QyNZUWBpA+NOIwVigRfknuEpIliwqTe4YB5AJPEEMAyRnhHRMnafpUt6jtBHYr LJwFQmKezp+43K/QHWAgpqbTbLx9OpbmJjaMiEEykZHh3yxWBlcft84gYc5D9GjFcgwrNvHtDvL 1llOJLLLeJsumaZ1kxB2RiO7uPaOlLeSPMr180RIKR87Mc6UaYgXaszaRN0gQB7VaL2WsnLVg== X-Received: by 2002:a5d:47c8:0:b0:385:df43:2179 with SMTP id ffacd0b85a97d-38bf577ffc2mr25581510f8f.17.1737711906663; Fri, 24 Jan 2025 01:45:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7a0Y9G3P4eXsb36h8Ct45GRthZwPYKYYHDoR768aACOAVxqfjHKBj7XqFeULXWD6rQ0KLqw== X-Received: by 2002:a5d:47c8:0:b0:385:df43:2179 with SMTP id ffacd0b85a97d-38bf577ffc2mr25581476f8f.17.1737711906215; Fri, 24 Jan 2025 01:45:06 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a17d74esm2218569f8f.37.2025.01.24.01.45.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:05 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 11/48] target/i386: optimize CX handling in repeated string operations Date: Fri, 24 Jan 2025 10:44:05 +0100 Message-ID: <20250124094442.13207-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 In a repeated string operation, CX/ECX will be decremented until it is 0 but never underflow. Use this observation to avoid a deposit or zero-extend operation if the address size of the operation is smaller than MO_TL. As in the previous patch, the patch is structured to include some preparatory work for subsequent changes. In particular, introducing cx_next prepares for when ECX will be decremented *before* calling fn(s, ot), and therefore cannot yet be written back to cpu_regs. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-11-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 7a3caf8b996..0a8f3c89514 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1339,6 +1339,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, { TCGLabel *done = gen_new_label(); target_ulong cx_mask = MAKE_64BIT_MASK(0, 8 << s->aflag); + TCGv cx_next = tcg_temp_new(); bool had_rf = s->flags & HF_RF_MASK; /* @@ -1364,7 +1365,19 @@ static void do_gen_rep(DisasContext *s, MemOp ot, tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cpu_regs[R_ECX], cx_mask, done); fn(s, ot); - gen_op_add_reg_im(s, s->aflag, R_ECX, -1); + + tcg_gen_subi_tl(cx_next, cpu_regs[R_ECX], 1); + + /* + * Write back cx_next to CX/ECX/RCX. There can be no carry, so zero + * extend if needed but do not do expensive deposit operations. + */ +#ifdef TARGET_X86_64 + if (s->aflag == MO_32) { + tcg_gen_ext32u_tl(cx_next, cx_next); + } +#endif + tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); gen_update_cc_op(s); /* Leave if REP condition fails. */ From patchwork Fri Jan 24 09:44:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949171 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 6572BC0218B for ; Fri, 24 Jan 2025 09:47:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFf-0006pf-GF; Fri, 24 Jan 2025 04:45: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 1tbGFa-0006iu-7r for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:18 -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 1tbGFV-0003sB-Gi for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711912; 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=Yk4DzKWKZjZoPnJ42L2/nSatLr8j0v2WzIzFpqrdX2Y=; b=D49+SAw3h0FLnyo0f8fgSDbIVVL5Fm7Iy+3/8A/dE6IPCFdMWshLQD6OSwym3ZR5WnZHqj Uii15PINFQZer5kwsW+uuPvG4Cy5Ti2aELusbIo4h7e6+OslfU/inIbt1q36VOwvV+SuQt 8CFnAQlv+9QBlUhlJCXq+W7OD5cHtEg= 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-201-WHxuJMA0MAGyIPtkmAZTbg-1; Fri, 24 Jan 2025 04:45:10 -0500 X-MC-Unique: WHxuJMA0MAGyIPtkmAZTbg-1 X-Mimecast-MFC-AGG-ID: WHxuJMA0MAGyIPtkmAZTbg Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385ded5e92aso813512f8f.3 for ; Fri, 24 Jan 2025 01:45:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711908; x=1738316708; 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=Yk4DzKWKZjZoPnJ42L2/nSatLr8j0v2WzIzFpqrdX2Y=; b=ir7AYU7PQGVCkb9x4PfIO7ZKIA77+q6zrSX1e3anGZjYFp6qXfLNiOpn6RJDUwBOew ytU6d+SG+4RKJvVkI+hjogGmvdoYRq1IPUwx0x3WVJR3vFGnBoNGxnMSe2FR3veH+d3x O8+i4yK/2cGckHz4+fnx6CAlD1NuFWs5hiRK+RMRkL5HflDYy648WGd0yO4xmIwZCGoP hHYeVIXt8LC8Ne/mYl5oVVwCUhqdIGxRReLCLjrQnqTdVD6tz6WF6ol5QVhi+lLZmebl lZ7ovmFzB4g5i5C7WYiQZjgEKu0+DaV5E2/3uLXqbZDmX25sJUlAgMnqJ+tX/AzmblQe I0Hg== X-Gm-Message-State: AOJu0YyV9YdxY1MtrSVY22s7PbiyPLJwT6tJRNfcaZAk9vR6MWiuDVOS 7hBKUsxrUAH2DMDYjqkp2cuMWShS0dAmP9kXq5e0+PN/EjiAZErLtPxID8CDyagpDY+t2nU3hHl sClM9sXDkPhIUzZ90fbRSCyYuLhQ/qVpnxXPuYztevFFLrFZYKZ1MFr3RpK+FmT6kK96UtSMw1v iPmV/PsZSw8jLgGyiRRCk1K/oyAkQZDBJartBJmfE= X-Gm-Gg: ASbGnctsNut5Cj+L0l8O88S13QYraIKTKl7pWAhJoQOHlSF9KqfgCTXE5I5sVoA6HpR bDWGJcugM0qmKYlrhG1ukSA2gUoNG/KDyzclImWE0CEVPjlm41XsLTwIvuBm2SmBd/S/7URl9fm pxFhs42hDqP+Wm0Znx/diH/5goaNPM9viLv3IuQ3cEp++0NMKrv++G2thxXbtnbljTyBW1UK4Ce pPPUKPF0fUy3E84Ubnp4jBGqVQXxNDKb3vG44U0bTHf5xrvfCvztfqMvn14xnMG/T89Eg0mQA== X-Received: by 2002:a5d:6d86:0:b0:385:e38f:8cc with SMTP id ffacd0b85a97d-38bf59e1e56mr35363882f8f.38.1737711908417; Fri, 24 Jan 2025 01:45:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnIfF1UxOmHuBFjiWF5YXRiyfqdrcpt11qlvrfCoPPUpbwqSgW4o/9DLAtFvT7S3RgsetV9g== X-Received: by 2002:a5d:6d86:0:b0:385:e38f:8cc with SMTP id ffacd0b85a97d-38bf59e1e56mr35363841f8f.38.1737711907893; Fri, 24 Jan 2025 01:45:07 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a17650esm2197739f8f.12.2025.01.24.01.45.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:07 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 12/48] target/i386: execute multiple REP/REPZ iterations without leaving TB Date: Fri, 24 Jan 2025 10:44:06 +0100 Message-ID: <20250124094442.13207-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 Use a TCG loop so that it is not necessary to go through the setup steps of REP and through the I/O check on every iteration. Interestingly, this is not a particularly effective optimization on its own, though it avoids the cost of correct RF emulation that was added in the previous patch. The main benefit lies in allowing the hoisting of loop invariants outside the loop, which will happen separately. The loop exits when the low 16 bits of CX/ECX/RCX are zero (so generally speaking the string operation runs in 65536 iteration batches) to give the main loop an opportunity to pick up interrupts. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-12-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 55 +++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 0a8f3c89514..991baf5d829 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -1333,13 +1333,28 @@ static void gen_outs(DisasContext *s, MemOp ot) gen_bpt_io(s, s->tmp2_i32, ot); } +#define REP_MAX 65535 + static void do_gen_rep(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot), bool is_repz_nz) { + TCGLabel *last = gen_new_label(); + TCGLabel *loop = gen_new_label(); TCGLabel *done = gen_new_label(); + target_ulong cx_mask = MAKE_64BIT_MASK(0, 8 << s->aflag); TCGv cx_next = tcg_temp_new(); + + /* + * Check if we must translate a single iteration only. Normally, HF_RF_MASK + * would also limit translation blocks to one instruction, so that gen_eob + * can reset the flag; here however RF is set throughout the repetition, so + * we can plow through until CX/ECX/RCX is zero. + */ + bool can_loop = + (!(tb_cflags(s->base.tb) & (CF_USE_ICOUNT | CF_SINGLE_STEP)) + && !(s->flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK))); bool had_rf = s->flags & HF_RF_MASK; /* @@ -1364,19 +1379,29 @@ static void do_gen_rep(DisasContext *s, MemOp ot, /* Any iteration at all? */ tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cpu_regs[R_ECX], cx_mask, done); - fn(s, ot); - - tcg_gen_subi_tl(cx_next, cpu_regs[R_ECX], 1); - /* - * Write back cx_next to CX/ECX/RCX. There can be no carry, so zero - * extend if needed but do not do expensive deposit operations. + * From now on we operate on the value of CX/ECX/RCX that will be written + * back, which is stored in cx_next. There can be no carry, so we can zero + * extend here if needed and not do any expensive deposit operations later. */ + tcg_gen_subi_tl(cx_next, cpu_regs[R_ECX], 1); #ifdef TARGET_X86_64 if (s->aflag == MO_32) { tcg_gen_ext32u_tl(cx_next, cx_next); + cx_mask = ~0; } #endif + + /* + * The last iteration is handled outside the loop, so that cx_next + * can never underflow. + */ + if (can_loop) { + tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cx_next, cx_mask, last); + } + + gen_set_label(loop); + fn(s, ot); tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); gen_update_cc_op(s); @@ -1388,6 +1413,12 @@ static void do_gen_rep(DisasContext *s, MemOp ot, assert(!s->cc_op_dirty); } + if (can_loop) { + tcg_gen_subi_tl(cx_next, cx_next, 1); + tcg_gen_brcondi_tl(TCG_COND_TSTNE, cx_next, REP_MAX, loop); + tcg_gen_brcondi_tl(TCG_COND_TSTEQ, cx_next, cx_mask, last); + } + /* * Traps or interrupts set RF_MASK if they happen after any iteration * but the last. Set it here before giving the main loop a chance to @@ -1400,6 +1431,18 @@ static void do_gen_rep(DisasContext *s, MemOp ot, /* Go to the main loop but reenter the same instruction. */ gen_jmp_rel_csize(s, -cur_insn_len(s), 0); + if (can_loop) { + /* + * The last iteration needs no conditional jump, even if is_repz_nz, + * because the repeats are ending anyway. + */ + gen_set_label(last); + set_cc_op(s, CC_OP_DYNAMIC); + fn(s, ot); + tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); + gen_update_cc_op(s); + } + /* CX/ECX/RCX is zero, or REPZ/REPNZ broke the repetition. */ gen_set_label(done); set_cc_op(s, CC_OP_DYNAMIC); From patchwork Fri Jan 24 09:44:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949194 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 27F85C02181 for ; Fri, 24 Jan 2025 09:50:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFg-0006sx-Q9; Fri, 24 Jan 2025 04:45:24 -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 1tbGFc-0006mQ-56 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:20 -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 1tbGFZ-0003sL-O3 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711913; 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=hPRuMrkGlDgncK8Zo+Qb0JgJSO2g2QdNllQujRRkgEk=; b=H4QsG8jmEvvPd4g+hcoH/6s6r1e92+0YC/SEDAbqea7JtP1Dyhs/Nr5ymhs7Pc8PiWaU+q VPOVh5+unGuXJdG+M2wiT6Nfe5IiORFgKn4FaG6/lY+oQP/nCLA3DFho1B83chU9X/+bcf cmwY5T2yH4HyS0CSkvG1P0wem3YBkDQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-61-0aUkPbSBMYmpXgIfXUVWYQ-1; Fri, 24 Jan 2025 04:45:11 -0500 X-MC-Unique: 0aUkPbSBMYmpXgIfXUVWYQ-1 X-Mimecast-MFC-AGG-ID: 0aUkPbSBMYmpXgIfXUVWYQ Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4361a8fc3bdso8761435e9.2 for ; Fri, 24 Jan 2025 01:45:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711910; x=1738316710; 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=hPRuMrkGlDgncK8Zo+Qb0JgJSO2g2QdNllQujRRkgEk=; b=ZrKc7xZF9C2wUUYCaFK9KsyA8GVXrNn3SbSphkg69v/K0hSiZZlWk+t5nmVAW7COfH GF6DZCCZFGM1qZ0xO+wZPfBZJ6wJFlMl3UIANS/PTzUm8Hc4gNAmb5qMyUNgOr40fIJ9 Emsg2ZUKzuFAXJEZ0zi5B69u4lprKsfk71aY3YpgNMQVASg8mfIefGqp/nrxnqRSHX48 tWatW07wgKufGCHo2MTQPAMjzNmURd1BNBudweJwb1VGn3hdlR9DyhhP+AEUipvwNGm9 MfYjZiOXZc4yfYcNFUUejVXrHqrsXsd4f4rsczgvL3UlaMzwiXkfxrsIxU0wPWe+oVO9 t0AQ== X-Gm-Message-State: AOJu0Yw4nUMr76ulkq9kD1erfIvnf001Yuk8X+DmslodpRAs9Ifo+nuw 2iscsV5mW/kWGF1Y6GNRGkSFLJpxrlqhB5dzBfFH3wf2sqwL6iB5vJ0EfuHhIJ8CHHA2iCi8F61 lQ2D4OoCO+hbHYAO3J6qc/555Brv7JDXRCznzDSh0ZM2vCyae55LeLqD7Wqwi6Grab8TxNWI2wW ZjjxlIQdxDiplH0pseNuo34Gcd9ePv9zg5plR2e68= X-Gm-Gg: ASbGncvFpeAMsIJqmq2N/I4r0zDyZaRnuzCP5yShjbFs8HTLbM32pJvgKU1XPwK6sf8 8/QP4mCWJ1R7rt+hTIopwhFrMDLHFgDlzG77Va/98OQKrpgGs3i8wVK4YOUmFRB9MszBpyK86Fp dDVRCLuOFtlfRs0/3ZWMbYncForJEO4Wtc9XcXScV77cTC4kR9S3Nw9j7wj9eFKknAp2Ow+NKpB GtryHrPV30I+Si2lfBKDZVL7ADkOr6eTrqhDfoxLSfRO9OmMIM7Xkwm1uPaGivQjSu68HXgBA== X-Received: by 2002:a05:600c:46ca:b0:434:a367:2bd9 with SMTP id 5b1f17b1804b1-438913dfd7fmr325619345e9.14.1737711909839; Fri, 24 Jan 2025 01:45:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFi9Cyr1qmaKtAihszP392he3yXXCQY7XJ93fRJh7fTl5lMWt48R04G6vatoXJ3oQQyNzz+xg== X-Received: by 2002:a05:600c:46ca:b0:434:a367:2bd9 with SMTP id 5b1f17b1804b1-438913dfd7fmr325619025e9.14.1737711909319; Fri, 24 Jan 2025 01:45:09 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4fa46esm20449995e9.1.2025.01.24.01.45.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:08 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 13/48] target/i386: pull computation of string update value out of loop Date: Fri, 24 Jan 2025 10:44:07 +0100 Message-ID: <20250124094442.13207-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 is a common operation that is executed many times in rep movs or rep stos loops. It can improve performance by several percentage points. Signed-off-by: Paolo Bonzini Link: https://lore.kernel.org/r/20241215090613.89588-13-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 54 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 991baf5d829..9f4d3ebbd95 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -832,16 +832,13 @@ static bool gen_check_io(DisasContext *s, MemOp ot, TCGv_i32 port, #endif } -static void gen_movs(DisasContext *s, MemOp ot) +static void gen_movs(DisasContext *s, MemOp ot, TCGv dshift) { - TCGv dshift; - gen_string_movl_A0_ESI(s); gen_op_ld_v(s, ot, s->T0, s->A0); gen_string_movl_A0_EDI(s); gen_op_st_v(s, ot, s->T0, s->A0); - dshift = gen_compute_Dshift(s, ot); gen_op_add_reg(s, s->aflag, R_ESI, dshift); gen_op_add_reg(s, s->aflag, R_EDI, dshift); } @@ -1246,22 +1243,22 @@ static inline void gen_jcc(DisasContext *s, int b, TCGLabel *l1) } } -static void gen_stos(DisasContext *s, MemOp ot) +static void gen_stos(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_EDI(s); gen_op_st_v(s, ot, s->T0, s->A0); - gen_op_add_reg(s, s->aflag, R_EDI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_EDI, dshift); } -static void gen_lods(DisasContext *s, MemOp ot) +static void gen_lods(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_ESI(s); gen_op_ld_v(s, ot, s->T0, s->A0); gen_op_mov_reg_v(s, ot, R_EAX, s->T0); - gen_op_add_reg(s, s->aflag, R_ESI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_ESI, dshift); } -static void gen_scas(DisasContext *s, MemOp ot) +static void gen_scas(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_EDI(s); gen_op_ld_v(s, ot, s->T1, s->A0); @@ -1270,13 +1267,11 @@ static void gen_scas(DisasContext *s, MemOp ot) tcg_gen_sub_tl(cpu_cc_dst, s->T0, s->T1); set_cc_op(s, CC_OP_SUBB + ot); - gen_op_add_reg(s, s->aflag, R_EDI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_EDI, dshift); } -static void gen_cmps(DisasContext *s, MemOp ot) +static void gen_cmps(DisasContext *s, MemOp ot, TCGv dshift) { - TCGv dshift; - gen_string_movl_A0_EDI(s); gen_op_ld_v(s, ot, s->T1, s->A0); gen_string_movl_A0_ESI(s); @@ -1286,7 +1281,6 @@ static void gen_cmps(DisasContext *s, MemOp ot) tcg_gen_sub_tl(cpu_cc_dst, s->T0, s->T1); set_cc_op(s, CC_OP_SUBB + ot); - dshift = gen_compute_Dshift(s, ot); gen_op_add_reg(s, s->aflag, R_ESI, dshift); gen_op_add_reg(s, s->aflag, R_EDI, dshift); } @@ -1305,7 +1299,7 @@ static void gen_bpt_io(DisasContext *s, TCGv_i32 t_port, int ot) } } -static void gen_ins(DisasContext *s, MemOp ot) +static void gen_ins(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_EDI(s); /* Note: we must do this dummy write first to be restartable in @@ -1316,11 +1310,11 @@ static void gen_ins(DisasContext *s, MemOp ot) tcg_gen_andi_i32(s->tmp2_i32, s->tmp2_i32, 0xffff); gen_helper_in_func(ot, s->T0, s->tmp2_i32); gen_op_st_v(s, ot, s->T0, s->A0); - gen_op_add_reg(s, s->aflag, R_EDI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_EDI, dshift); gen_bpt_io(s, s->tmp2_i32, ot); } -static void gen_outs(DisasContext *s, MemOp ot) +static void gen_outs(DisasContext *s, MemOp ot, TCGv dshift) { gen_string_movl_A0_ESI(s); gen_op_ld_v(s, ot, s->T0, s->A0); @@ -1329,14 +1323,14 @@ static void gen_outs(DisasContext *s, MemOp ot) tcg_gen_andi_i32(s->tmp2_i32, s->tmp2_i32, 0xffff); tcg_gen_trunc_tl_i32(s->tmp3_i32, s->T0); gen_helper_out_func(ot, s->tmp2_i32, s->tmp3_i32); - gen_op_add_reg(s, s->aflag, R_ESI, gen_compute_Dshift(s, ot)); + gen_op_add_reg(s, s->aflag, R_ESI, dshift); gen_bpt_io(s, s->tmp2_i32, ot); } #define REP_MAX 65535 -static void do_gen_rep(DisasContext *s, MemOp ot, - void (*fn)(DisasContext *s, MemOp ot), +static void do_gen_rep(DisasContext *s, MemOp ot, TCGv dshift, + void (*fn)(DisasContext *s, MemOp ot, TCGv dshift), bool is_repz_nz) { TCGLabel *last = gen_new_label(); @@ -1401,7 +1395,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, } gen_set_label(loop); - fn(s, ot); + fn(s, ot, dshift); tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); gen_update_cc_op(s); @@ -1438,7 +1432,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, */ gen_set_label(last); set_cc_op(s, CC_OP_DYNAMIC); - fn(s, ot); + fn(s, ot, dshift); tcg_gen_mov_tl(cpu_regs[R_ECX], cx_next); gen_update_cc_op(s); } @@ -1453,23 +1447,27 @@ static void do_gen_rep(DisasContext *s, MemOp ot, } static void gen_repz(DisasContext *s, MemOp ot, - void (*fn)(DisasContext *s, MemOp ot)) + void (*fn)(DisasContext *s, MemOp ot, TCGv dshift)) { + TCGv dshift = gen_compute_Dshift(s, ot); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - do_gen_rep(s, ot, fn, false); + do_gen_rep(s, ot, dshift, fn, false); } else { - fn(s, ot); + fn(s, ot, dshift); } } static void gen_repz_nz(DisasContext *s, MemOp ot, - void (*fn)(DisasContext *s, MemOp ot)) + void (*fn)(DisasContext *s, MemOp ot, TCGv dshift)) { + TCGv dshift = gen_compute_Dshift(s, ot); + if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - do_gen_rep(s, ot, fn, true); + do_gen_rep(s, ot, dshift, fn, true); } else { - fn(s, ot); + fn(s, ot, dshift); } } From patchwork Fri Jan 24 09:44:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949189 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 4C255C02181 for ; Fri, 24 Jan 2025 09:49:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFe-0006pV-V9; Fri, 24 Jan 2025 04:45: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 1tbGFb-0006l8-Hs for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45: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 1tbGFa-0003sT-0b for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711914; 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=xatIXaIYlV/CgS4ESCp0zEwFccHB44d7QBdN1/soCUc=; b=f375Fa+d+/j6pLnTQPJFjd1ljys2kTE221lhLdPpcVjjKCNQIjphF0FxqEoHWPvJz6/J36 6NY2nJcWZy+rr4VAZw1w7+JPDl6ozaJv21QMZv013Lgu69SW/OuRx0abuVC0/e3A2XRY73 +47q29FbqeEcVYdwQjmSyUu0Y0OoaXA= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-oDdY2WblPZeHzolOYJm5Iw-1; Fri, 24 Jan 2025 04:45:13 -0500 X-MC-Unique: oDdY2WblPZeHzolOYJm5Iw-1 X-Mimecast-MFC-AGG-ID: oDdY2WblPZeHzolOYJm5Iw Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-436723db6c4so12960295e9.3 for ; Fri, 24 Jan 2025 01:45:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711911; x=1738316711; 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=xatIXaIYlV/CgS4ESCp0zEwFccHB44d7QBdN1/soCUc=; b=RqGWxkyrZK0a9FE+8UjC4oOlC4FUvC+dfMRWEaxtHitMT3VQXUAm2tVrRtXx3jKiH5 ZAyz24lOp9lNsCNIWYeEJgifbVLVLvRfNoMYLq+MrmyV9quTCEG50H+VG/4fyXyUrNOT peVZjXxKh6VZ3NkpdGuil48/EGTzD1xHLwZgAIdtFDHgfoKXZ2AwWKqqKTfupU8uRlKs 6RGaDooxpIF/EhnT8ak5cB3a9vqjlhADD/ywkVUkO53QfKqzSDfuGT/2OBQvXtED9OzM e5Kr+mnuSvxY9zR8CD6NWHyLenVwfnN5iUVo+Hzh1+FUXdFEDD9+xX66zYZByQBeaDqR oV3w== X-Gm-Message-State: AOJu0YxBSJinTtR09Xwooys49E2mcmbaywikmndmczNiX/WPheNlj9zK pJ2dQb2wKfOFCCRNhS3PYPNLTKBPsihfKiBuhxmGL3BXh5iph85JHn5Eq9j/Kd42mJfJc+uOGGo S2130Z+j6D+N/X1DYDeiRoL94fL5xEz11t6kItHQbeU0KhEg8GbVP94iMWZ7xa0KIlxiTJmQcpc l4RALuLY2Kjixp0FTj1ecrxQXCwuPmWZgKzw3kybE= X-Gm-Gg: ASbGncuvcSbEvJ3Qg5JYfFkkHHdXWzVrIYJxNSZvq1TnsNaLwQvhCgpunqlixGFy0kJ GeucJMLjobCrTEpPCULolDzMo5D4uVypbsdDY2qsXbBtT/lk0qsQAAhFfePeKMO2T1Dqe9W1Mw0 IGAtb72QytbPMHMX/e8ChvNb7zgkF+osTsKapQaDLVFKdN1Hpfs47RhGEaGqM8wrmwvdgDkIDuc VHg1X2KmwaoH5jJVjNCnXSmj9W1nL3Ef3h5qEHsXXmqTtykHMiadNRfPZaL/ITWgV1PncSLKg== X-Received: by 2002:a05:600c:1c16:b0:435:192:63fb with SMTP id 5b1f17b1804b1-438913bed1bmr256504785e9.3.1737711911521; Fri, 24 Jan 2025 01:45:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsIm+Ym8NnzGGf6nf7UgSf5CGAEqY2xPvvmdHJFC1/4vDfx8svnz11aFZB96lXs2oWZYQkBw== X-Received: by 2002:a05:600c:1c16:b0:435:192:63fb with SMTP id 5b1f17b1804b1-438913bed1bmr256504435e9.3.1737711911044; Fri, 24 Jan 2025 01:45:11 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4fa479sm20684205e9.5.2025.01.24.01.45.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 14/48] target/i386: extract common bits of gen_repz/gen_repz_nz Date: Fri, 24 Jan 2025 10:44:08 +0100 Message-ID: <20250124094442.13207-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 Now that everything has been cleaned up, look at DF and prefixes in a single function, and call that one from gen_repz and gen_repz_nz. Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 9f4d3ebbd95..9b2fde5eb28 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -688,14 +688,6 @@ static inline void gen_string_movl_A0_EDI(DisasContext *s) gen_lea_v_seg(s, cpu_regs[R_EDI], R_ES, -1); } -static inline TCGv gen_compute_Dshift(DisasContext *s, MemOp ot) -{ - TCGv dshift = tcg_temp_new(); - tcg_gen_ld32s_tl(dshift, tcg_env, offsetof(CPUX86State, df)); - tcg_gen_shli_tl(dshift, dshift, ot); - return dshift; -}; - static TCGv gen_ext_tl(TCGv dst, TCGv src, MemOp size, bool sign) { if (size == MO_TL) { @@ -1446,29 +1438,31 @@ static void do_gen_rep(DisasContext *s, MemOp ot, TCGv dshift, gen_jmp_rel_csize(s, 0, 1); } -static void gen_repz(DisasContext *s, MemOp ot, - void (*fn)(DisasContext *s, MemOp ot, TCGv dshift)) - +static void do_gen_string(DisasContext *s, MemOp ot, + void (*fn)(DisasContext *s, MemOp ot, TCGv dshift), + bool is_repz_nz) { - TCGv dshift = gen_compute_Dshift(s, ot); + TCGv dshift = tcg_temp_new(); + tcg_gen_ld32s_tl(dshift, tcg_env, offsetof(CPUX86State, df)); + tcg_gen_shli_tl(dshift, dshift, ot); if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - do_gen_rep(s, ot, dshift, fn, false); + do_gen_rep(s, ot, dshift, fn, is_repz_nz); } else { fn(s, ot, dshift); } } +static void gen_repz(DisasContext *s, MemOp ot, + void (*fn)(DisasContext *s, MemOp ot, TCGv dshift)) +{ + do_gen_string(s, ot, fn, false); +} + static void gen_repz_nz(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot, TCGv dshift)) { - TCGv dshift = gen_compute_Dshift(s, ot); - - if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { - do_gen_rep(s, ot, dshift, fn, true); - } else { - fn(s, ot, dshift); - } + do_gen_string(s, ot, fn, true); } static void gen_helper_fp_arith_ST0_FT0(int op) From patchwork Fri Jan 24 09:44:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949197 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 49DF1C02181 for ; Fri, 24 Jan 2025 09:51:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGG0-0007C2-FF; Fri, 24 Jan 2025 04:45: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 1tbGFd-0006oI-DP for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:21 -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 1tbGFb-0003sb-Kb for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711916; 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=cQbZtmBk+g/IDUiWwXjwX0V2l1jb0mb1+mhwT99ZFxk=; b=U6N1v+Mva24wDgt5n7pJPN3m2gKNO7PWyN1AN+3oAFxoICJ2KzoTIMFidenkZsCGDMVNKI SnESFxLIRjceGzoYxDLcRD5An4gonD6+6gG9Nv5EyWQtdI/tWESII56p2ZD9eQ0m1HEQdA Ax3yb8YUHAi29FzZpLwo0V4DVdemaJc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-XmCPt4zCNN-UwiXuP5b6ZQ-1; Fri, 24 Jan 2025 04:45:14 -0500 X-MC-Unique: XmCPt4zCNN-UwiXuP5b6ZQ-1 X-Mimecast-MFC-AGG-ID: XmCPt4zCNN-UwiXuP5b6ZQ Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-38629a685fdso688610f8f.2 for ; Fri, 24 Jan 2025 01:45:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711913; x=1738316713; 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=cQbZtmBk+g/IDUiWwXjwX0V2l1jb0mb1+mhwT99ZFxk=; b=e+3lP+uptpnxn3c58c4A+xstm0477paxxUCzOi+RRNdsSdWgEUq6X907SUUDNOWDUU O9O/d8RtwvlgnSllAJ1baB9euzVSZhIArSKDBT3T7J85earrRVUMzzFU7nycQ1/c7KND KbIhkboksRmI0wZBoikZB4QYZ5xAWe+j8BclsWQvndQg4V52wW53GFhUnZSTknrVtxr7 IUC7o3afLXaEgn1JFKR5JR28O2l6DqqnfmrYQtp08lM6jjbiFO4Dnf47eEfFkiV+XxFL Qj72QCWZaaMo/lKvVXgrtTY1mxawD8LVU2r+Yw6wUoaFmPI0at1l4kBOs9aivhtn2gTN BoxA== X-Gm-Message-State: AOJu0YwRQiIX5m3kq+/hDjf8nuAh+ea9rjWzSPhOLmfmwdTBTKD4lFOD 0FtaYykS4JqeTrUnG4Zr8XlPNk+2Y1JIqM0sD+gb5ZN6NYdk4VGoPjZJYoiZHkgse+rdQle2M/N 0MCBaqpSvTlL0kguCrvQ/T/uY1ushB9CaxT+HgQBvJnJfKox++nLuKcBkPffFYXQDCryRxqbpxS Eg8CblgsspH5+M8cirqktNMGQHJTLW9AQaX6jEpRo= X-Gm-Gg: ASbGncuWSjvpVNJe9qY+RbYPFBsF+OKSHB8W24JKwowpPrGg9km0R3CSdUksN+Cd1qp w+RHQkzGvdDxHuokalWHAtkHpKfYS67XsA+R/axk+mX1hGo8/XlHdNpMpogmq95Q/Geq1qS2vEk R/dTYKU2i5Cx9PbiUDmttmpaQn9/yq5Zu6Oss6lGVoO0aR1tIXY0NAwo2KfT1AUvUlBc5Ld0Z4Z qTgjqNd6lrZ5s13t751UaCwEveQltv01YcwiFeAhRVoWg5oZiLF6Uenwzq44XczSBHcyosqcw== X-Received: by 2002:a05:6000:4026:b0:385:e8b0:df13 with SMTP id ffacd0b85a97d-38bf57a9569mr31670661f8f.40.1737711913175; Fri, 24 Jan 2025 01:45:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMzipNrHGdnQIs+B16qWtOmja0hWoou5S5KefICZC9WqQktUsHoPPNuNt7OLhGt4/YC43TOA== X-Received: by 2002:a05:6000:4026:b0:385:e8b0:df13 with SMTP id ffacd0b85a97d-38bf57a9569mr31670624f8f.40.1737711912754; Fri, 24 Jan 2025 01:45:12 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4fa599sm20988735e9.7.2025.01.24.01.45.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 15/48] target/i386: avoid using s->tmp0 for add to implicit registers Date: Fri, 24 Jan 2025 10:44:09 +0100 Message-ID: <20250124094442.13207-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 For updates to implicit registers (RCX in LOOP instructions, RSI or RDI in string instructions, or the stack pointer) do the add directly using the registers (with no temporary) if 32-bit or 64-bit, or use a temporary created for the occasion if 16-bit. This is more efficient and removes move instructions for the MO_TL case. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20241215090613.89588-14-pbonzini@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 9b2fde5eb28..a8935f487aa 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -505,17 +505,24 @@ static inline void gen_op_jmp_v(DisasContext *s, TCGv dest) s->pc_save = -1; } +static inline void gen_op_add_reg(DisasContext *s, MemOp size, int reg, TCGv val) +{ + /* Using cpu_regs[reg] does not work for xH registers. */ + assert(size >= MO_16); + if (size == MO_16) { + TCGv temp = tcg_temp_new(); + tcg_gen_add_tl(temp, cpu_regs[reg], val); + gen_op_mov_reg_v(s, size, reg, temp); + } else { + tcg_gen_add_tl(cpu_regs[reg], cpu_regs[reg], val); + tcg_gen_ext_tl(cpu_regs[reg], cpu_regs[reg], size); + } +} + static inline void gen_op_add_reg_im(DisasContext *s, MemOp size, int reg, int32_t val) { - tcg_gen_addi_tl(s->tmp0, cpu_regs[reg], val); - gen_op_mov_reg_v(s, size, reg, s->tmp0); -} - -static inline void gen_op_add_reg(DisasContext *s, MemOp size, int reg, TCGv val) -{ - tcg_gen_add_tl(s->tmp0, cpu_regs[reg], val); - gen_op_mov_reg_v(s, size, reg, s->tmp0); + gen_op_add_reg(s, size, reg, tcg_constant_tl(val)); } static inline void gen_op_ld_v(DisasContext *s, int idx, TCGv t0, TCGv a0) From patchwork Fri Jan 24 09:44:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949188 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 7B334C0218B for ; Fri, 24 Jan 2025 09:49:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFi-0006tK-72; Fri, 24 Jan 2025 04:45:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbGFc-0006nX-Ts for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:20 -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 1tbGFb-0003sl-0y for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711918; 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=uraIJgwBFUvUKFYLefg6yvOaMymHtIAJOis/mI8DgJQ=; b=Pjf0QlAfjLeY9UhU0/7/WRixQXzaRQnsuxbMm7ODqagAaNJRNfGheO8Ns0RdG6+55L58uX yw8W53p7sTF+1O8QIgL1+AsWuC4cHUt7+li8CXlVxXBiMpQP+WqQSnRMyrDilUGR4kBUUB 0lrapI6y5q5GagOEekDLsnMrtIngpxM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-56-_7Spe-3zNHSpwCd5V8VdrA-1; Fri, 24 Jan 2025 04:45:16 -0500 X-MC-Unique: _7Spe-3zNHSpwCd5V8VdrA-1 X-Mimecast-MFC-AGG-ID: _7Spe-3zNHSpwCd5V8VdrA Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361d4e8359so13275605e9.3 for ; Fri, 24 Jan 2025 01:45:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711915; x=1738316715; 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=uraIJgwBFUvUKFYLefg6yvOaMymHtIAJOis/mI8DgJQ=; b=J/gbxTcJKtBwXZNzcc01sDIlKUrewZIG16NMsMq2rKn98BvlQj+x5dUgaa6xdqEwyE vYYpg4oPcQZh59wMu9V78fmz4lA7IbcXf0N1mmFDk/ih54zD0E9oGx2G+xBEKvV/0Unb 4TSX3dfkzLZnd995N5PJ8ux5/IELHoq4fcA3zS/XjNnSEc1ajVxiodKRCU18QRimNeXQ U8xyT6ucCXIkDwG8rZWFGV5I81m6u5v0ORYaFk3i4M8TY++vANSjg77gbrQYHkzWoI13 Ib0YtlGkrpXfesmgs1Y5WjWq6TJir6OIXc6QhiXb4wCQgS6rrwPn9Qo47IINLcHBNxbh 4Nvw== X-Gm-Message-State: AOJu0Yx8Ihg9IVg9kn0KsMABMQ0LUFr+B3QTSrtVT+Hs4JD8BvtOVnVV hauu46bE/qmaEVUK80dpn78/nD0sXQibLhZlNRJYYmGQVhEdWxVxMEDijJTWZdGPVK1Q4wEJAY7 uUaVenObnMmXt+mW9AK5r/PEoQSoxYxvt0LvomPC7l1Uj0w6JKw8KogLnmJcPrudgCW1J6BKRPq 3c0JBVUz9BroiQcBbB96FagVewJ3hpU/MN89Z3n+0= X-Gm-Gg: ASbGncu4dH3e3CJkWL5cHZuIuq5SrUndDQpM1WjasOaZ6ppciocbQXptR3MDSYaUPTG LKAGABnqpe6i1/Si1uan5IOkoQgXfopPIGvPRqGw+5AbaCHTlvq5JZL6YYgU/C4abRnmazV33j5 a9+a6R9bleaNJvSmpZAMJxbq5rY8Uxe3wcNJ1QpA44r7rD6JwJgCnyAcFx6U2wA705iyWTw8vfM IE4PZn3s7eEwcr6VspiAZRSbWfMcdBB3JzcAxwXN/QV43ONUlaYGs4WqS9AUZPd4P88mXueVw== X-Received: by 2002:a05:600c:601a:b0:42c:bb10:7292 with SMTP id 5b1f17b1804b1-438a2114bc9mr173905545e9.1.1737711914875; Fri, 24 Jan 2025 01:45:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGku2OYAFByGb551sRZ8gr87JWPufRNulZJt45pE6CAwNbhWGtiZU8/NyrCAG+vCt3ywoc4Yw== X-Received: by 2002:a05:600c:601a:b0:42c:bb10:7292 with SMTP id 5b1f17b1804b1-438a2114bc9mr173905265e9.1.1737711914361; Fri, 24 Jan 2025 01:45:14 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd57517fsm19616805e9.38.2025.01.24.01.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:13 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Tao Su Subject: [PULL 16/48] target/i386: Introduce SierraForest-v2 model Date: Fri, 24 Jan 2025 10:44:10 +0100 Message-ID: <20250124094442.13207-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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: Tao Su Update SierraForest CPU model to add LAM, 4 bits indicating certain bits of IA32_SPEC_CTR are supported(intel-psfd, ipred-ctrl, rrsba-ctrl, bhi-ctrl) and the missing features(ss, tsc-adjust, cldemote, movdiri, movdir64b) Also add GDS-NO and RFDS-NO to indicate the related vulnerabilities are mitigated in stepping 3. Tested-by: Xuelian Guo Signed-off-by: Tao Su Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250121020650.1899618-2-tao1.su@linux.intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 1b9c11022c4..6db8d6c9bab 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4549,6 +4549,25 @@ static const X86CPUDefinition builtin_x86_defs[] = { .model_id = "Intel Xeon Processor (SierraForest)", .versions = (X86CPUVersionDefinition[]) { { .version = 1 }, + { + .version = 2, + .props = (PropValue[]) { + { "ss", "on" }, + { "tsc-adjust", "on" }, + { "cldemote", "on" }, + { "movdiri", "on" }, + { "movdir64b", "on" }, + { "gds-no", "on" }, + { "rfds-no", "on" }, + { "lam", "on" }, + { "intel-psfd", "on"}, + { "ipred-ctrl", "on"}, + { "rrsba-ctrl", "on"}, + { "bhi-ctrl", "on"}, + { "stepping", "3" }, + { /* end of list */ } + } + }, { /* end of list */ }, }, }, From patchwork Fri Jan 24 09:44:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949205 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 D7117C02181 for ; Fri, 24 Jan 2025 09:52:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGFi-0006tM-8J; Fri, 24 Jan 2025 04:45:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbGFe-0006pE-79 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:22 -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 1tbGFc-0003t6-MK for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711920; 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=RD+mEfAdDUkodwsyNQ6ua+15ZST6/FVUt+cz1H6YqK8=; b=I4pek+epbOPb/JPCQ19AYus3pBUs3Xw1HMVUDIkcplJBng5ZkSHl9OEJdzwy1XpeXaFH7N IHYNgfmnhgp6I4l3YMDpPNevUbqeCK/BwIvycdQxvvvk9TmFqolNHduU2j/+wiOY1PprgA zNWCBEmudygNRR9HlehuPTMJsdSu4QQ= 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-1-_23GfbwJN1eoTBd-JrSn5g-1; Fri, 24 Jan 2025 04:45:18 -0500 X-MC-Unique: _23GfbwJN1eoTBd-JrSn5g-1 X-Mimecast-MFC-AGG-ID: _23GfbwJN1eoTBd-JrSn5g Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385d80576abso1182532f8f.3 for ; Fri, 24 Jan 2025 01:45:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711916; x=1738316716; 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=RD+mEfAdDUkodwsyNQ6ua+15ZST6/FVUt+cz1H6YqK8=; b=ob09QV00Dx5kEcU81s4lfHduH7v5LTNWbPzqxzRMO4sNiAE/lStQFTRGDBNwB7i1Kl f5aqPLBQQ3rhN46CEnr1Ly9ozK72/hyR0s+dg0jU3xW2SeGrErX1PHUTuX6u656QP5Dz 6w6TslAh4KVuQRLIobCIfKYp0/uTRzvl1tA+ZVwY4AtdKWCGoD/ChAiBSln7oan0DtHD ZMrk3xWZfq1bjjsatvTzzv2K2kDYLRHYJlQOKf9Os0H8LeBZCxG0rnayRIH6aYaX0IaH xTyoTXMlt0M6KuYvnXLmpN3ChQ2g+xANoCgRlnULnJRfhnMtNZVpcLoKkZQ+WU5MPPYf U+Aw== X-Gm-Message-State: AOJu0YxrCKI0bVVkM5EM6v9zFovpamKe8EyFYDhzaxNT4e36Aq6E7bVh GflYS5viZbmHZTdLvOXjjbxa5zf5lKrvX4JwzzBlrgpiy8B0EdBXxU+88MKRUU1tnXrQzrzzMBX 4j1EZHCU/5bdyxClaBCX+J55gW8vbMVabI1FcWN2rw5hLfQz9xvQEDZT5wp1mrsr/xJL8N0RjUM kI/gZXSWfRcZaR1JpV+xEl06EY3twRTGGWVH4bPpg= X-Gm-Gg: ASbGncsurzybJ/Hrc9E7X6O3YkgwqAnmH5RxZWx6lf6fkbbnw309xL7P4Y7NyFZa1Fe meblVOwnfOsqxA0ezt7Cun0UNLHi3y7sVSl1MLxnwnV9PQMOD1SWXUOT+mCRzsI3AhYzZZ2iOHy YT2esD3lMFFoIlrIUXTYEfsKMyduWX7GQl+gNXZWQGXROcWSnirQG7AL64CshdQD2ivR450NYZ4 OTutFx0TGJW/ydJXZKeBML4cz0mivtT4clXb2B4vgXbindWtICQxv84KohNcdblbIMapqcVyQ== X-Received: by 2002:adf:f48c:0:b0:385:f996:1b8e with SMTP id ffacd0b85a97d-38bf5659a94mr23984758f8f.16.1737711916528; Fri, 24 Jan 2025 01:45:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdQpy974WgGHbEVD5uPHNT71/Z2lx0UkA0QVHLx9JQ7VIITD7kh44vZLFUj5DR0Zb4ZprZCQ== X-Received: by 2002:adf:f48c:0:b0:385:f996:1b8e with SMTP id ffacd0b85a97d-38bf5659a94mr23984729f8f.16.1737711916116; Fri, 24 Jan 2025 01:45:16 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1bb0d4sm2213554f8f.69.2025.01.24.01.45.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:15 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Tao Su Subject: [PULL 17/48] target/i386: Export BHI_NO bit to guests Date: Fri, 24 Jan 2025 10:44:11 +0100 Message-ID: <20250124094442.13207-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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: Tao Su Branch History Injection (BHI) is a CPU side-channel vulnerability, where an attacker may manipulate branch history before transitioning from user to supervisor mode or from VMX non-root/guest to root mode. CPUs that set BHI_NO bit in MSR IA32_ARCH_CAPABILITIES to indicate no additional mitigation is required to prevent BHI. Make BHI_NO bit available to guests. Tested-by: Xuelian Guo Signed-off-by: Tao Su Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250121020650.1899618-3-tao1.su@linux.intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6db8d6c9bab..33fb27a6119 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1364,7 +1364,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { "taa-no", NULL, NULL, NULL, NULL, "sbdr-ssdp-no", "fbsdp-no", "psdp-no", NULL, "fb-clear", NULL, NULL, - NULL, NULL, NULL, NULL, + "bhi-no", NULL, NULL, NULL, "pbrsb-no", NULL, "gds-no", "rfds-no", "rfds-clear", NULL, NULL, NULL, }, From patchwork Fri Jan 24 09:44:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949165 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 32488C0218B for ; Fri, 24 Jan 2025 09:46:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGG4-0007Jd-Gi; Fri, 24 Jan 2025 04:45:49 -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 1tbGFi-0006tg-Cb for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:26 -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 1tbGFg-0003tc-44 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711923; 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=dR2kSe8qSzBAA1k+EbyVgJaxWbRgwHrntpYjIEWk2M8=; b=hSBgcEr7NS2MROivZwopDLhjB+G6iexx7LxDUX/iwc9U06DwlVHl8utLtvWpmgaa5mUmC2 bKhN4BJ8djsP1EnRlQ37gT9CHrxVsiQS07VrvgEMEpL2G7GUHQFdMJ8z7yeGeQX2LUL0/t CWDUxE/LZtsRn6Oli9JsqyVUER1SrO0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-HwUsQbZDNqSWk3sSsq0nAQ-1; Fri, 24 Jan 2025 04:45:21 -0500 X-MC-Unique: HwUsQbZDNqSWk3sSsq0nAQ-1 X-Mimecast-MFC-AGG-ID: HwUsQbZDNqSWk3sSsq0nAQ Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361fc2b2d6so10299155e9.3 for ; Fri, 24 Jan 2025 01:45:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711920; x=1738316720; 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=dR2kSe8qSzBAA1k+EbyVgJaxWbRgwHrntpYjIEWk2M8=; b=bnrJmEAfBr0G9dJMWH5Hyu0kRFYe76kg18WuKEx/xKHoBC0RIyz21RsUiyrHH9/vTd b0zzwzVzrhhRHlyi4ao9UkdHgQExu9482u8qOceViH9ukhdDDCF1rMlqrr4DzgZeM7jo azdm7Ja2weJlL4zqCykNEplDqCXjEcsFsis96kBfpWJCNArJ9IT+mF+9XxrYl4c8VyNO cluxfgUtTVOQCTd+C1sL3yxJaqlsBTG7ocfCYK5JOc9g69yPOqnAZ+eZzY5B40U5Z3Xk r5XR0tu6V6vHM+2jj6A/rCWX4TjlNc/1vIUrQjzlzslfnIOwI9I0BIVUWnB/OTmU+BVU TgSA== X-Gm-Message-State: AOJu0YyCFmpH/COEtQ8D0cN3sDTq16IRI5hsZfdshh59QNcgldRk+GzL FFyJnZkck6079JljXRH+jNHpjsoWvbK82NVdrPeslelJaXIce503ibPGp9hVWD2PNHUQfHAwTVC 50dN0I7c/5fCI6YgiMH/dQJWXqfR48crxtyFH50UrbiFbtDcl+M+fE/ydxS4/KjwO6I9oXGsBKj lTD675wGHyxei5woLvLvopUJlcWXomba8qRlpcd7E= X-Gm-Gg: ASbGncvnBisJT/n0Eg18iOP2OW3jV5tAUueV49FkzHPJ2V0/IOMYUGY3Xv0psBqpPty qLzeY2Gj+TxtiKW3C3QTCPThpKXuhWhg2N/Exj3qZvqZgh0KeTbwLxQqa3TsWmNOJBncSnMaQzf Niw2tklDtVf2ZnJOsl/6FUEOq/uTQ5A6vXH5BRDQwqF9SXT5h++B3t6faCBiNNpuzCpE3+Nztr4 ZflKVeeLWVIo1sPICxILtXiPlwfOAlhXerxClGWAERbiKzwmabEyMQ3HOD2aQbtDutWMFxl8A== X-Received: by 2002:a05:600c:1d28:b0:434:9f81:76d5 with SMTP id 5b1f17b1804b1-43891434081mr255515105e9.22.1737711918569; Fri, 24 Jan 2025 01:45:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVUZtJTUAd28zMu2hoLbJm75jEGtRAUOLZwB1c5UmpT3xGeiCBZ659EwmCtBrzAqwgFrbQAw== X-Received: by 2002:a05:600c:1d28:b0:434:9f81:76d5 with SMTP id 5b1f17b1804b1-43891434081mr255514835e9.22.1737711917994; Fri, 24 Jan 2025 01:45:17 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4b9984sm20388465e9.28.2025.01.24.01.45.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:17 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Tao Su Subject: [PULL 18/48] target/i386: Add new CPU model ClearwaterForest Date: Fri, 24 Jan 2025 10:44:12 +0100 Message-ID: <20250124094442.13207-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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, UPPERCASE_50_75=0.008 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: Tao Su According to table 1-2 in Intel Architecture Instruction Set Extensions and Future Features (rev 056) [1], ClearwaterForest has the following new features which have already been virtualized: - AVX-VNNI-INT16 CPUID.(EAX=7,ECX=1):EDX[bit 10] - SHA512 CPUID.(EAX=7,ECX=1):EAX[bit 0] - SM3 CPUID.(EAX=7,ECX=1):EAX[bit 1] - SM4 CPUID.(EAX=7,ECX=1):EAX[bit 2] Add above features to new CPU model ClearwaterForest. Comparing with SierraForest, ClearwaterForest bare-metal contains all features of SierraForest-v2 CPU model and adds: - PREFETCHI CPUID.(EAX=7,ECX=1):EDX[bit 14] - DDPD_U CPUID.(EAX=7,ECX=2):EDX[bit 3] - BHI_NO IA32_ARCH_CAPABILITIES[bit 20] Add above and all features of SierraForest-v2 CPU model to new CPU model ClearwaterForest. [1] https://cdrdv2.intel.com/v1/dl/getContent/671368 Tested-by: Xuelian Guo Signed-off-by: Tao Su Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250121020650.1899618-4-tao1.su@linux.intel.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 33 +++++++++--- target/i386/cpu.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index b26e25ba15e..c67b42d34fc 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -951,6 +951,12 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); /* Speculative Store Bypass Disable */ #define CPUID_7_0_EDX_SPEC_CTRL_SSBD (1U << 31) +/* SHA512 Instruction */ +#define CPUID_7_1_EAX_SHA512 (1U << 0) +/* SM3 Instruction */ +#define CPUID_7_1_EAX_SM3 (1U << 1) +/* SM4 Instruction */ +#define CPUID_7_1_EAX_SM4 (1U << 2) /* AVX VNNI Instruction */ #define CPUID_7_1_EAX_AVX_VNNI (1U << 4) /* AVX512 BFloat16 Instruction */ @@ -963,6 +969,12 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); #define CPUID_7_1_EAX_FSRS (1U << 11) /* Fast Short REP CMPS/SCAS */ #define CPUID_7_1_EAX_FSRC (1U << 12) +/* Flexible return and event delivery (FRED) */ +#define CPUID_7_1_EAX_FRED (1U << 17) +/* Load into IA32_KERNEL_GS_BASE (LKGS) */ +#define CPUID_7_1_EAX_LKGS (1U << 18) +/* Non-Serializing Write to Model Specific Register (WRMSRNS) */ +#define CPUID_7_1_EAX_WRMSRNS (1U << 19) /* Support Tile Computational Operations on FP16 Numbers */ #define CPUID_7_1_EAX_AMX_FP16 (1U << 21) /* Support for VPMADD52[H,L]UQ */ @@ -976,17 +988,23 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); #define CPUID_7_1_EDX_AVX_NE_CONVERT (1U << 5) /* AMX COMPLEX Instructions */ #define CPUID_7_1_EDX_AMX_COMPLEX (1U << 8) +/* AVX-VNNI-INT16 Instructions */ +#define CPUID_7_1_EDX_AVX_VNNI_INT16 (1U << 10) /* PREFETCHIT0/1 Instructions */ #define CPUID_7_1_EDX_PREFETCHITI (1U << 14) /* Support for Advanced Vector Extensions 10 */ #define CPUID_7_1_EDX_AVX10 (1U << 19) -/* Flexible return and event delivery (FRED) */ -#define CPUID_7_1_EAX_FRED (1U << 17) -/* Load into IA32_KERNEL_GS_BASE (LKGS) */ -#define CPUID_7_1_EAX_LKGS (1U << 18) -/* Non-Serializing Write to Model Specific Register (WRMSRNS) */ -#define CPUID_7_1_EAX_WRMSRNS (1U << 19) +/* Indicate bit 7 of the IA32_SPEC_CTRL MSR is supported */ +#define CPUID_7_2_EDX_PSFD (1U << 0) +/* Indicate bits 3 and 4 of the IA32_SPEC_CTRL MSR are supported */ +#define CPUID_7_2_EDX_IPRED_CTRL (1U << 1) +/* Indicate bits 5 and 6 of the IA32_SPEC_CTRL MSR are supported */ +#define CPUID_7_2_EDX_RRSBA_CTRL (1U << 2) +/* Indicate bit 8 of the IA32_SPEC_CTRL MSR is supported */ +#define CPUID_7_2_EDX_DDPD_U (1U << 3) +/* Indicate bit 10 of the IA32_SPEC_CTRL MSR is supported */ +#define CPUID_7_2_EDX_BHI_CTRL (1U << 4) /* Do not exhibit MXCSR Configuration Dependent Timing (MCDT) behavior */ #define CPUID_7_2_EDX_MCDT_NO (1U << 5) @@ -1144,7 +1162,10 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); #define MSR_ARCH_CAP_FBSDP_NO (1U << 14) #define MSR_ARCH_CAP_PSDP_NO (1U << 15) #define MSR_ARCH_CAP_FB_CLEAR (1U << 17) +#define MSR_ARCH_CAP_BHI_NO (1U << 20) #define MSR_ARCH_CAP_PBRSB_NO (1U << 24) +#define MSR_ARCH_CAP_GDS_NO (1U << 26) +#define MSR_ARCH_CAP_RFDS_NO (1U << 27) #define MSR_CORE_CAP_SPLIT_LOCK_DETECT (1U << 5) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 33fb27a6119..b5dd60d2812 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4571,6 +4571,141 @@ static const X86CPUDefinition builtin_x86_defs[] = { { /* end of list */ }, }, }, + { + .name = "ClearwaterForest", + .level = 0x23, + .xlevel = 0x80000008, + .vendor = CPUID_VENDOR_INTEL, + .family = 6, + .model = 221, + .stepping = 0, + /* + * please keep the ascending order so that we can have a clear view of + * bit position of each feature. + */ + .features[FEAT_1_EDX] = + CPUID_FP87 | CPUID_VME | CPUID_DE | CPUID_PSE | CPUID_TSC | + CPUID_MSR | CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | + CPUID_SEP | CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | + CPUID_PAT | CPUID_PSE36 | CPUID_CLFLUSH | CPUID_MMX | CPUID_FXSR | + CPUID_SSE | CPUID_SSE2 | CPUID_SS, + .features[FEAT_1_ECX] = + CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | CPUID_EXT_SSSE3 | + CPUID_EXT_FMA | CPUID_EXT_CX16 | CPUID_EXT_PCID | CPUID_EXT_SSE41 | + CPUID_EXT_SSE42 | CPUID_EXT_X2APIC | CPUID_EXT_MOVBE | + CPUID_EXT_POPCNT | CPUID_EXT_TSC_DEADLINE_TIMER | CPUID_EXT_AES | + CPUID_EXT_XSAVE | CPUID_EXT_AVX | CPUID_EXT_F16C | CPUID_EXT_RDRAND, + .features[FEAT_8000_0001_EDX] = + CPUID_EXT2_SYSCALL | CPUID_EXT2_NX | CPUID_EXT2_PDPE1GB | + CPUID_EXT2_RDTSCP | CPUID_EXT2_LM, + .features[FEAT_8000_0001_ECX] = + CPUID_EXT3_LAHF_LM | CPUID_EXT3_ABM | CPUID_EXT3_3DNOWPREFETCH, + .features[FEAT_8000_0008_EBX] = + CPUID_8000_0008_EBX_WBNOINVD, + .features[FEAT_7_0_EBX] = + CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_TSC_ADJUST | + CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_SMEP | + CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_INVPCID | + CPUID_7_0_EBX_RDSEED | CPUID_7_0_EBX_ADX | CPUID_7_0_EBX_SMAP | + CPUID_7_0_EBX_CLFLUSHOPT | CPUID_7_0_EBX_CLWB | + CPUID_7_0_EBX_SHA_NI, + .features[FEAT_7_0_ECX] = + CPUID_7_0_ECX_UMIP | CPUID_7_0_ECX_PKU | CPUID_7_0_ECX_GFNI | + CPUID_7_0_ECX_VAES | CPUID_7_0_ECX_VPCLMULQDQ | + CPUID_7_0_ECX_RDPID | CPUID_7_0_ECX_BUS_LOCK_DETECT | + CPUID_7_0_ECX_CLDEMOTE | CPUID_7_0_ECX_MOVDIRI | + CPUID_7_0_ECX_MOVDIR64B, + .features[FEAT_7_0_EDX] = + CPUID_7_0_EDX_FSRM | CPUID_7_0_EDX_SERIALIZE | + CPUID_7_0_EDX_SPEC_CTRL | CPUID_7_0_EDX_ARCH_CAPABILITIES | + CPUID_7_0_EDX_SPEC_CTRL_SSBD, + .features[FEAT_ARCH_CAPABILITIES] = + MSR_ARCH_CAP_RDCL_NO | MSR_ARCH_CAP_IBRS_ALL | + MSR_ARCH_CAP_SKIP_L1DFL_VMENTRY | MSR_ARCH_CAP_MDS_NO | + MSR_ARCH_CAP_PSCHANGE_MC_NO | MSR_ARCH_CAP_SBDR_SSDP_NO | + MSR_ARCH_CAP_FBSDP_NO | MSR_ARCH_CAP_PSDP_NO | + MSR_ARCH_CAP_BHI_NO | MSR_ARCH_CAP_PBRSB_NO | + MSR_ARCH_CAP_GDS_NO | MSR_ARCH_CAP_RFDS_NO, + .features[FEAT_XSAVE] = + CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC | + CPUID_XSAVE_XGETBV1 | CPUID_XSAVE_XSAVES, + .features[FEAT_6_EAX] = + CPUID_6_EAX_ARAT, + .features[FEAT_7_1_EAX] = + CPUID_7_1_EAX_SHA512 | CPUID_7_1_EAX_SM3 | CPUID_7_1_EAX_SM4 | + CPUID_7_1_EAX_AVX_VNNI | CPUID_7_1_EAX_CMPCCXADD | + CPUID_7_1_EAX_FSRS | CPUID_7_1_EAX_AVX_IFMA | + CPUID_7_1_EAX_LAM, + .features[FEAT_7_1_EDX] = + CPUID_7_1_EDX_AVX_VNNI_INT8 | CPUID_7_1_EDX_AVX_NE_CONVERT | + CPUID_7_1_EDX_AVX_VNNI_INT16 | CPUID_7_1_EDX_PREFETCHITI, + .features[FEAT_7_2_EDX] = + CPUID_7_2_EDX_PSFD | CPUID_7_2_EDX_IPRED_CTRL | + CPUID_7_2_EDX_RRSBA_CTRL | CPUID_7_2_EDX_DDPD_U | + CPUID_7_2_EDX_BHI_CTRL | CPUID_7_2_EDX_MCDT_NO, + .features[FEAT_VMX_BASIC] = + MSR_VMX_BASIC_INS_OUTS | MSR_VMX_BASIC_TRUE_CTLS, + .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, + .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 | MSR_VMX_EPT_INVVPID_SINGLE_ADDR | + MSR_VMX_EPT_INVVPID_SINGLE_CONTEXT | + MSR_VMX_EPT_INVVPID_ALL_CONTEXT | + MSR_VMX_EPT_INVVPID_SINGLE_CONTEXT_NOGLOBALS, + .features[FEAT_VMX_EXIT_CTLS] = + VMX_VM_EXIT_SAVE_DEBUG_CONTROLS | + 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, + .features[FEAT_VMX_MISC] = + MSR_VMX_MISC_STORE_LMA | MSR_VMX_MISC_ACTIVITY_HLT | + MSR_VMX_MISC_VMWRITE_VMEXIT, + .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_PROCBASED_CTLS] = + VMX_CPU_BASED_VIRTUAL_INTR_PENDING | + VMX_CPU_BASED_USE_TSC_OFFSETING | VMX_CPU_BASED_HLT_EXITING | + 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, + .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_VIRTUALIZE_X2APIC_MODE | + VMX_SECONDARY_EXEC_ENABLE_VPID | 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_RDSEED_EXITING | VMX_SECONDARY_EXEC_ENABLE_PML | + VMX_SECONDARY_EXEC_XSAVES, + .features[FEAT_VMX_VMFUNC] = + MSR_VMX_VMFUNC_EPT_SWITCHING, + .model_id = "Intel Xeon Processor (ClearwaterForest)", + .versions = (X86CPUVersionDefinition[]) { + { .version = 1 }, + { /* end of list */ }, + }, + }, { .name = "Denverton", .level = 21, From patchwork Fri Jan 24 09:44:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949172 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 31591C0218B for ; Fri, 24 Jan 2025 09:47:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHk-0002OK-7V; Fri, 24 Jan 2025 04:47:32 -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 1tbGFk-0006ua-Bf for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:33 -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 1tbGFi-0003tg-66 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711924; 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=KP65DPAPt9KsJWuPUWuSo56FR59BUIL6HMXyZyeXonQ=; b=EFSzao2LRCccc1n+XtXsHx0pExowx8G0rV+gVjkOtCzCemhdp6i+j8Xd69qQ7MPVkZh0up GX0VQTHDKNj7YJR8r9nIaLY9aP7V5jvnJ/QcQN51eQuKbGaY165IzCl9RW3OXmMVEv4lM+ C5NbtMCRZeKveY/L1u1aWoWPnopvlfo= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-MDD2BVuBNHa8zul6NN7HBw-1; Fri, 24 Jan 2025 04:45:22 -0500 X-MC-Unique: MDD2BVuBNHa8zul6NN7HBw-1 X-Mimecast-MFC-AGG-ID: MDD2BVuBNHa8zul6NN7HBw Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38bf4913659so1541258f8f.1 for ; Fri, 24 Jan 2025 01:45:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711921; x=1738316721; 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=KP65DPAPt9KsJWuPUWuSo56FR59BUIL6HMXyZyeXonQ=; b=k/nmwxFG1ZR82tX6PhQ+TUSPng+82ufHZqHMjmu1p4QsZDu9brHh1Dm9Ky7NNhh6lT nSWiA9pFUV9TJlgn6m71zqwinSTlO0Wxh5eV/nuwRdMMDUm3/+Ocdsmgi5RJ3tV1xPF/ /JJXr9ex4fMdkfehYTAWweVM/pYVkouldc9NXGrLnZAR1XUUu7K0PEL47V4HGUjBSw6U IaK/coAXFMH/QljSqvx41QVKjpKe3UdYVn3SRlVkNDe8cYpO6EjVQFqYBBRPlU5oel7J XPoFfaknL5lQmfhVIWJzwPoCM9TDiu3C2IXdvqldsf96d7tzu3GdBqXjP1Si4Gq5zkTE 4KqQ== X-Gm-Message-State: AOJu0YwkTn8saT9Fbpdme81WH3ONbnoUioCHa0Y4A/ct0evmn5LUnhQl hh++o8fkDzXMDckJcVF2Q1sxA88bQxSwwfuWMZDzEDtK0Bcsmi9MuOsTJHjSxvz4EjTXzRLho0N lLPj/dkiJ2SSVVd0vGG7kpgTO9VqpCPpbfoEPh5pGRsi0HgxzV9S1HORk5oKT6u2d/4SlT1cEmo urskWO7h2pSdEu3IAuKcLl6CkZmC7vBuJkcdjQ5Ck= X-Gm-Gg: ASbGncs3HS+huN+/a/+6aKboqHhZLlBIt/cDHZyUyfph/Yr5aNLh50puvyvKY6hCvb9 JuMWCwpSis67DJWXXKJnpBVHdlHTvNEGnTaUSt0kwbiVWawWHBbqTp309xJiDb6XoUia5cwTVJL 2Na8/y5VrZx7AnH6SA2RiRA2r4z4QRcgIbsdQBeuemi9ffuc2rSoYx4Mcw/sT0q0dfvGvfonM7P mX7l5hVpWHqbm7g7gkBFjmoNHroMjOTb/RSd15oDThaJiy2qNoBoqfCgE5ZecyZ2VAUgVf1ag== X-Received: by 2002:adf:ab0f:0:b0:386:3711:ff8c with SMTP id ffacd0b85a97d-38bf579348dmr20110933f8f.23.1737711920744; Fri, 24 Jan 2025 01:45:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6F41fp90vF7+INj63ZJxGWMaZ97YzAIZIKNwemeiacajidaMxNqpfpoUP7WsPXlRK0tU+hA== X-Received: by 2002:adf:ab0f:0:b0:386:3711:ff8c with SMTP id ffacd0b85a97d-38bf579348dmr20110909f8f.23.1737711920207; Fri, 24 Jan 2025 01:45:20 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a188a77sm2209828f8f.51.2025.01.24.01.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Tao Su Subject: [PULL 19/48] docs: Add GNR, SRF and CWF CPU models Date: Fri, 24 Jan 2025 10:44:13 +0100 Message-ID: <20250124094442.13207-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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: Tao Su Update GraniteRapids, SierraForest and ClearwaterForest CPU models in section "Preferred CPU models for Intel x86 hosts". Also introduce bhi-no, gds-no and rfds-no in doc. Suggested-by: Zhao Liu Signed-off-by: Tao Su Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250121020650.1899618-5-tao1.su@linux.intel.com Signed-off-by: Paolo Bonzini --- docs/system/cpu-models-x86.rst.inc | 50 +++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/docs/system/cpu-models-x86.rst.inc b/docs/system/cpu-models-x86.rst.inc index ba27b5683fb..6a770ca8351 100644 --- a/docs/system/cpu-models-x86.rst.inc +++ b/docs/system/cpu-models-x86.rst.inc @@ -71,6 +71,16 @@ mixture of host CPU models between machines, if live migration compatibility is required, use the newest CPU model that is compatible across all desired hosts. +``ClearwaterForest`` + Intel Xeon Processor (ClearwaterForest, 2025) + +``SierraForest``, ``SierraForest-v2`` + Intel Xeon Processor (SierraForest, 2024), SierraForest-v2 mitigates + the GDS and RFDS vulnerabilities with stepping 3. + +``GraniteRapids``, ``GraniteRapids-v2`` + Intel Xeon Processor (GraniteRapids, 2024) + ``Cascadelake-Server``, ``Cascadelake-Server-noTSX`` Intel Xeon Processor (Cascade Lake, 2019), with "stepping" levels 6 or 7 only. (The Cascade Lake Xeon processor with *stepping 5 is @@ -181,7 +191,7 @@ features are included if using "Host passthrough" or "Host model". CVE-2018-12127, [MSBDS] CVE-2018-12126). This is an MSR (Model-Specific Register) feature rather than a CPUID feature, - so it will not appear in the Linux ``/proc/cpuinfo`` in the host or + therefore it will not appear in the Linux ``/proc/cpuinfo`` in the host or guest. Instead, the host kernel uses it to populate the MDS vulnerability file in ``sysfs``. @@ -189,10 +199,10 @@ features are included if using "Host passthrough" or "Host model". affected} in the ``/sys/devices/system/cpu/vulnerabilities/mds`` file. ``taa-no`` - Recommended to inform that the guest that the host is ``not`` + Recommended to inform the guest that the host is ``not`` vulnerable to CVE-2019-11135, TSX Asynchronous Abort (TAA). - This too is an MSR feature, so it does not show up in the Linux + This is also an MSR feature, therefore it does not show up in the Linux ``/proc/cpuinfo`` in the host or guest. It should only be enabled for VMs if the host reports ``Not affected`` @@ -214,7 +224,7 @@ features are included if using "Host passthrough" or "Host model". By disabling TSX, KVM-based guests can avoid paying the price of mitigating TSX-based attacks. - Note that ``tsx-ctrl`` too is an MSR feature, so it does not show + Note that ``tsx-ctrl`` is also an MSR feature, therefore it does not show up in the Linux ``/proc/cpuinfo`` in the host or guest. To validate that Intel TSX is indeed disabled for the guest, there are @@ -223,6 +233,38 @@ features are included if using "Host passthrough" or "Host model". ``/sys/devices/system/cpu/vulnerabilities/tsx_async_abort`` file in the guest should report ``Mitigation: TSX disabled``. +``bhi-no`` + Recommended to inform the guest that the host is ``not`` + vulnerable to CVE-2022-0001, Branch History Injection (BHI). + + This is also an MSR feature, therefore it does not show up in the Linux + ``/proc/cpuinfo`` in the host or guest. + + It should only be enabled for VMs if the host reports + ``BHI: Not affected`` in the + ``/sys/devices/system/cpu/vulnerabilities/spectre_v2`` file. + +``gds-no`` + Recommended to inform the guest that the host is ``not`` + vulnerable to CVE-2022-40982, Gather Data Sampling (GDS). + + This is also an MSR feature, therefore it does not show up in the Linux + ``/proc/cpuinfo`` in the host or guest. + + It should only be enabled for VMs if the host reports ``Not affected`` + in the ``/sys/devices/system/cpu/vulnerabilities/gather_data_sampling`` + file. + +``rfds-no`` + Recommended to inform the guest that the host is ``not`` + vulnerable to CVE-2023-28746, Register File Data Sampling (RFDS). + + This is also an MSR feature, therefore it does not show up in the Linux + ``/proc/cpuinfo`` in the host or guest. + + It should only be enabled for VMs if the host reports ``Not affected`` + in the ``/sys/devices/system/cpu/vulnerabilities/reg_file_data_sampling`` + file. Preferred CPU models for AMD x86 hosts ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From patchwork Fri Jan 24 09:44:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949199 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 EB0FEC0218B for ; Fri, 24 Jan 2025 09:51:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGH3-0008O2-Hr; Fri, 24 Jan 2025 04:46:51 -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 1tbGFp-00074D-FE for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:35 -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 1tbGFk-0003u3-3t for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711927; 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=2JnJ4uWdXLKH0BSsQ/cswZ3Sl3lzRSubbNSrDL/OSsc=; b=IJ0+zQyqP4nt7ZT/McAfOfU0+yDlRsijfdJ8TzQcUXN+uqW39DQ9dxeQoedzDGQbGpL29c +33FNM4ZLiUdx6wDtfBMUntx27OEpON4lhiZvLCcKhduIKhhrXaal9G7GtehTN8rgPIi8P Wy31fqZT+OjAuxy+DhaqADqZZBPnW9w= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-o3gp6_WuNdCDUSH75oRt1A-1; Fri, 24 Jan 2025 04:45:25 -0500 X-MC-Unique: o3gp6_WuNdCDUSH75oRt1A-1 X-Mimecast-MFC-AGG-ID: o3gp6_WuNdCDUSH75oRt1A Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385d7611ad3so1028618f8f.2 for ; Fri, 24 Jan 2025 01:45:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711923; x=1738316723; 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=2JnJ4uWdXLKH0BSsQ/cswZ3Sl3lzRSubbNSrDL/OSsc=; b=fI9WaGXarkiSarFvs9AE9ExkTjE8FbuGfDg2f73KVLcb0hztVM9c1v9jh3x3tIP9Lo RYXlt9VMHQRitGrDyTYuD0Ab848wwjOtIzJIkGGcQz5+qQtTDWfF1c3CXyjj+tk3f5nE WkWogN1TsPJ/JHfM/hdSHTBdpWckxDbD5PLJq05uyA2qU+3+hTHYlluYDpOF6A18H6kX wlzwhJYhdc8xFs4Us/Pzu9gH+vbiLMn16MhpMb5xtz2xQbksbd1/oEzoEo6G7xlxnTQ7 RWL+9ttsW0oHdNVx6jF9S1hG24dRvAYYWh/ZHWBr5bC0QfMcOkxDPsZN58H1z7tg1iWa by+w== X-Gm-Message-State: AOJu0Yy6PnuPa1bfCNqOoQFar2kZgULHoYwbqvGfw63t87trl3b+zBxr d66Um6swzJy8+ermiiiN4ktx/WgcnuZtPjTqpEZsVFb5Z8T0VaZcjwWIQryey/3MTep6qVc2Z0z psj+wJ0m9eahI0F6rHx6EKE390UheUMvhqBxUWXje9/VqvqvJ4HAIbiShha51ZoP1kVn3GT36RX 2RjTaVSdA9awY23ZJ1gY2G2stzlJ34tKrMekZtbmM= X-Gm-Gg: ASbGncs9Qb5tIa+Dvr7mw5cFQslpGuY2xxXJyzTyRPnVZGitGR/ymOLTwWvIMJGVHYX YmcTPeQDXEMfTNuHlwxhLhpeSobbc/9juODb/4TmyUSzp2ReqMklySsDgdsJIVYq47bQ69ZxTbf ZnifIftA0hG2qxv9e545Q/wMgb+uTj29UJq9U0fyQ84hOmIAahL/a4Pf4SW0n2Z1o4j64ysdZ/N 2CIaeo3VfdkJlZRygzlnTAk3u977Dz6jeVIxNFUWa4o8GqhrXRfbEuSXKnc94TmLyhQoX5g4g== X-Received: by 2002:a05:6000:1a8c:b0:38b:ed6f:f00f with SMTP id ffacd0b85a97d-38bf56635a1mr25565338f8f.17.1737711923231; Fri, 24 Jan 2025 01:45:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFvviF5m5Le9uIdKQug3cLYtChw3LC78akqAs4EDVOcfJv4Ook5jum8vK/EBgn/itTU+PobvA== X-Received: by 2002:a05:6000:1a8c:b0:38b:ed6f:f00f with SMTP id ffacd0b85a97d-38bf56635a1mr25565307f8f.17.1737711922794; Fri, 24 Jan 2025 01:45:22 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438b1da8d4asm47818215e9.3.2025.01.24.01.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:21 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , qemu-stable@nongnu.org Subject: [PULL 20/48] stub: Fix build failure with --enable-user --disable-system --enable-tools Date: Fri, 24 Jan 2025 10:44:14 +0100 Message-ID: <20250124094442.13207-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 From: Zhao Liu Configuring "--enable-user --disable-system --enable-tools" causes the build failure with the following information: /usr/bin/ld: libhwcore.a.p/hw_core_qdev.c.o: in function `device_finalize': /qemu/build/../hw/core/qdev.c:688: undefined reference to `qapi_event_send_device_deleted' collect2: error: ld returned 1 exit status To fix the above issue, add qdev.c stub when build with `have_tools`. With this fix, QEMU could be successfully built in the following cases: --enable-user --disable-system --enable-tools --enable-user --disable-system --disable-tools --enable-user --disable-system Cc: qemu-stable@nongnu.org Fixes: 388b849fb6c3 ("stubs: avoid duplicate symbols in libqemuutil.a") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2766 Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250121154318.214680-1-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- stubs/meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/meson.build b/stubs/meson.build index e91614a874d..a8b3aeb5645 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -57,8 +57,8 @@ if have_user stub_ss.add(files('cpu-synchronize-state.c')) # Stubs for QAPI events. Those can always be included in the build, but - # they are not built at all for --disable-system --disable-tools builds. - if not (have_system or have_tools) + # they are not built at all for --disable-system builds. + if not have_system stub_ss.add(files('qdev.c')) endif endif From patchwork Fri Jan 24 09:44:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949211 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 51F9BC02181 for ; Fri, 24 Jan 2025 09:52:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGI7-0004vX-DA; Fri, 24 Jan 2025 04:47:55 -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 1tbGFq-00077V-Vm for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:37 -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 1tbGFo-0003uV-3r for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711929; 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=Iz+0oRL8E0Alsm18eGzwPgcS9Df+LzoBBQHD3AQeNAQ=; b=ASczHboJXu+CgBtNq0LGYmT7We/reUwHzZLrBFtVl5YD1a8HQC3HgUaMGuSaxmqWgx9UW6 So80eW3lxJPuIJgjgs9BuAGw874A388cx4c+cF4D+k6uyOj0fsYUbzoZfQ+fP8U9kQRSxQ vOI+BdSOu9OwtUqgATHG7GStOQXEWXE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-ZszoNrUbMyK3FqjLb10pYQ-1; Fri, 24 Jan 2025 04:45:27 -0500 X-MC-Unique: ZszoNrUbMyK3FqjLb10pYQ-1 X-Mimecast-MFC-AGG-ID: ZszoNrUbMyK3FqjLb10pYQ Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-436248d1240so8883855e9.0 for ; Fri, 24 Jan 2025 01:45:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711926; x=1738316726; 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=Iz+0oRL8E0Alsm18eGzwPgcS9Df+LzoBBQHD3AQeNAQ=; b=K5EiCTLQox/BlZ01qK34+3T9XP99TkG9/PVnKtholS6+4qdlWDIOvgbbzYHfLFwbKm z90dT/BKcc3dSomkOzeR7DYJPNCebAttxApFaAl+EnykjPfmOX1I1cylEJBGuLspR+4A HYb2DSOxb0+oyiZ0e2SPrQ725CLsaD36oOYazIwuR06d+PY+KT/CejUM8P9y3eRNv+EA OBpsOPDknIX4DTs77MntTvbcYagpqUJSoYuzUbJ78lOwHvNHQCxOdRtH08nmSS9EHcn1 PDDxcf31VzrHu+0jq0GbEQHlvJ5NcxDTy1jMgxfMlLq6rYuw/joGMFTj56VnR9qj49VD zv7w== X-Gm-Message-State: AOJu0Ywqv3cN+I8p4wc3BeSwUdpQBiFp/eC4H/USFbqFuTsZz9cs3EVi G4W6JrCvUTzZQGkx1/ighSmTgp85+91caDNGOI1q7c4wsGzC2oGlJQceXDfRK6zmd48xdoLRd9t Aa0dUqhFPFDJKbZlDMVIitIT+mbu2l5ANtlypXkPK+EI0I6mvdUdaqS8CTzHGf25dbvQmdLTv2r g0oalJg1xkqUAhs+ElCgP1qnztEJzfwYVnL339QuU= X-Gm-Gg: ASbGncunFNpHuVicyIl6lHLpmIzq9U4hnGfzq3MgDEaJ0yoxdMjHCmmTYCzt2l4WQgi 8IfSw25QSp8IURko2gsrwyjjsPKoZPOgfzJaErSAQUuLF63M0j2+5XDcdOIU6Ixst15hRMihWwz RBGlIjczCJt2dkRL8S+WMx2htAsnF+Ftd3O+c8ydafHfhiR0M7dcrL9nD9PllsNMKGnqTxIdzVU mZoUM2bxEZYb9+ShMznXQGl8m//SbsjpriCS15b3Cd0AVu1XV+dZIB515tgb3/UbFY1o2ygkg== X-Received: by 2002:a05:600c:870a:b0:436:e8b4:3cde with SMTP id 5b1f17b1804b1-438913ded64mr303096405e9.14.1737711925891; Fri, 24 Jan 2025 01:45:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXSpC+4KZA/BzRCnAv813raC+gdiYw1Sf975YdvHjOWehdfDkA3Vx3ttAodIR60iz3neIHug== X-Received: by 2002:a05:600c:870a:b0:436:e8b4:3cde with SMTP id 5b1f17b1804b1-438913ded64mr303096165e9.14.1737711925520; Fri, 24 Jan 2025 01:45:25 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd47f120sm21133505e9.2.2025.01.24.01.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:24 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 21/48] rust/qdev: Make REALIZE safe Date: Fri, 24 Jan 2025 10:44:15 +0100 Message-ID: <20250124094442.13207-22-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 A safe REALIZE accepts immutable reference. Since current PL011's realize() only calls a char binding function ( qemu_chr_fe_set_handlers), it is possible to convert mutable reference (&mut self) to immutable reference (&self), which only needs to convert the pointers passed to C to mutable pointers. Thus, make REALIZE accept immutable reference. Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250121140457.84631-2-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 10 +++++----- rust/qemu-api/src/qdev.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 65a1234b9ff..a0e0fbdd9dd 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -2,7 +2,7 @@ // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -use core::ptr::{addr_of_mut, NonNull}; +use core::ptr::{addr_of, addr_of_mut, NonNull}; use std::{ ffi::CStr, os::raw::{c_int, c_uint, c_void}, @@ -156,7 +156,7 @@ fn properties() -> &'static [Property] { fn vmsd() -> Option<&'static VMStateDescription> { Some(&device_class::VMSTATE_PL011) } - const REALIZE: Option = Some(Self::realize); + const REALIZE: Option = Some(Self::realize); const RESET: Option = Some(Self::reset); } @@ -439,17 +439,17 @@ fn set_read_trigger(&mut self) { self.read_trigger = 1; } - pub fn realize(&mut self) { + pub fn realize(&self) { // SAFETY: self.char_backend has the correct size and alignment for a // CharBackend object, and its callbacks are of the correct types. unsafe { qemu_chr_fe_set_handlers( - addr_of_mut!(self.char_backend), + addr_of!(self.char_backend) as *mut CharBackend, Some(pl011_can_receive), Some(pl011_receive), Some(pl011_event), None, - addr_of_mut!(*self).cast::(), + addr_of!(*self).cast::() as *mut c_void, core::ptr::null_mut(), true, ); diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs index 686054e737a..a5121e31a37 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/qemu-api/src/qdev.rs @@ -23,7 +23,7 @@ pub trait DeviceImpl { /// /// If not `None`, the parent class's `realize` method is overridden /// with the function pointed to by `REALIZE`. - const REALIZE: Option = None; + const REALIZE: Option = None; /// If not `None`, the parent class's `reset` method is overridden /// with the function pointed to by `RESET`. From patchwork Fri Jan 24 09:44:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949166 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 6E107C02181 for ; Fri, 24 Jan 2025 09:46:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGGm-000811-9K; Fri, 24 Jan 2025 04:46:33 -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 1tbGFq-00077U-Tt for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:37 -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 1tbGFp-0003ub-8S for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711931; 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=byv7yqpioTnmhdGEjf7rdV0DYWcU89djOSCRL0A/xmg=; b=FcqrFQtBqMy9Mrbty5KFQeS8hT1ZooDw3l/6mIrFBdtH1L7QQSeFSdrCwVdRAwDxcX58iF MnnkomxevpNXFHf5/6k2PyP2t82xBLx44l0LtHr7MkIPZfx49jwMjjz8qXlbGUiWOD7cUQ +5yHm0Y/KSSZ2g6YQylUDJoZMfRBP6M= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-529-shqhB78XNDGRulA6wtJzjQ-1; Fri, 24 Jan 2025 04:45:29 -0500 X-MC-Unique: shqhB78XNDGRulA6wtJzjQ-1 X-Mimecast-MFC-AGG-ID: shqhB78XNDGRulA6wtJzjQ Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-38bf4913669so1009980f8f.2 for ; Fri, 24 Jan 2025 01:45:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711928; x=1738316728; 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=byv7yqpioTnmhdGEjf7rdV0DYWcU89djOSCRL0A/xmg=; b=G0fKARIazDxLmaNUjFC2Bo2hV/Xw2UyPgtOw0w6fi9/OUUfka37hJAqU/2fv3AZJVn lTye/L9eprtLTna73mfSgkSoaIbkmOtXE3bjbV/78kscpxGjNaNZIkaS+BYNEaRjROTC TI8b7BGHhDOzfQV6FPECzal6ppUPTBwJ8EykqDb987mVFO2e5f4IB14eNl8QTTAKfVm+ 5fnO5EQm2hTbgXPPUAEixMXfW8ncGkALLu2RkM2Qk5V0DgOTKvq25ksGNP2pCKFlZUT/ YwwXSmfgsrP7bYNUT9RZKKwbRWmj1qtkXjvnphQwtWvskjJUVqYVeiwTVUM3KjUW5tG3 sKzw== X-Gm-Message-State: AOJu0YwwpeqL7TQnGdC6FYYBh74BGf38unfg4g4we6279Yy5XvwF8Rws 5f7wMbCiBkgtTQm41gMo8dgCp2Uc6IDUsbGPxNuWjuPyHuicPxoBN1Qop60+PXq1TNfegiBWIKL OyGLhXAp1BTe7Ys2sR0Lcg+aLgyugyEOtKaY0QnJmOAeotYNRp4HRvZQZCcVAe82OAzV/hDQJA5 oIxEhzI8wPTFS5tXbvLlSbGdjaBFk7bBg8Mki8tOA= X-Gm-Gg: ASbGnct/tx+uaCBw/gIOpCOdGC+P/k2eBFXTBkvltUQOP6pfcjCCsbOsa3Jr8usVUEG p4RXVOadi2nPh4NwkMvWWL3f+xm9CDASRZ7Cq+cT6TTjoPauki4b6Z59MlGZJmxlptvwYsKm1jX OSKc/nqJ9N+C0qJz93jQBvfBVqB9TgAh+p684xYdfjP0fMTu+iH1rM4euGu8TxTLIwiGR1Cz5wf goZE5HjbPlUMJX1Lqng5WCsKQAULN7LiTvi5Z4vR7c1XCMMhQH8vMBhAwNkEUMe2QWyqMM4AA== X-Received: by 2002:a5d:4007:0:b0:38a:888c:7dec with SMTP id ffacd0b85a97d-38bf5675e61mr24559857f8f.28.1737711927975; Fri, 24 Jan 2025 01:45:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IF36MJ7Wpp4C/FN9fV3gHTkz7acfg7AbPrgVBQAHzyYek9PxgiL8sTcBAlcoWis9fG+Kci8kA== X-Received: by 2002:a5d:4007:0:b0:38a:888c:7dec with SMTP id ffacd0b85a97d-38bf5675e61mr24559825f8f.28.1737711927542; Fri, 24 Jan 2025 01:45:27 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1144f6sm2187016f8f.0.2025.01.24.01.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 22/48] rust/pl011: Avoid bindings::* Date: Fri, 24 Jan 2025 10:44:16 +0100 Message-ID: <20250124094442.13207-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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: Zhao Liu List all the necessary bindings to better identify gaps in rust/qapi. And include the bindings wrapped by rust/qapi instead mapping the raw bindings directly. Inspired-by: Paolo Bonzini Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250121140457.84631-3-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index a0e0fbdd9dd..4f1080ff19f 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -9,12 +9,19 @@ }; use qemu_api::{ - bindings::{self, *}, + bindings::{ + error_fatal, hwaddr, memory_region_init_io, qdev_init_clock_in, qdev_new, + qdev_prop_set_chr, qemu_chr_fe_ioctl, qemu_chr_fe_set_handlers, qemu_chr_fe_write_all, + qemu_irq, sysbus_connect_irq, sysbus_mmio_map, sysbus_realize_and_unref, CharBackend, + Chardev, Clock, ClockEvent, MemoryRegion, QEMUChrEvent, CHR_IOCTL_SERIAL_SET_BREAK, + }, c_str, irq::InterruptSource, prelude::*, - qdev::DeviceImpl, + qdev::{DeviceImpl, DeviceState, Property}, qom::{ClassInitImpl, ObjectImpl, ParentField}, + sysbus::{SysBusDevice, SysBusDeviceClass}, + vmstate::VMStateDescription, }; use crate::{ @@ -494,7 +501,7 @@ pub fn can_receive(&self) -> bool { } pub fn event(&mut self, event: QEMUChrEvent) { - if event == bindings::QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_enabled() { + if event == QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_enabled() { self.put_fifo(registers::Data::BREAK.into()); } } From patchwork Fri Jan 24 09:44:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949173 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 23080C0218C for ; Fri, 24 Jan 2025 09:47:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGGI-0007Y5-14; Fri, 24 Jan 2025 04:46: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 1tbGFt-0007Ai-8Z for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:38 -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 1tbGFq-0003us-4D for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711933; 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=6bbpMEor1R2bRwOjlbdZexCI/CHydxS93U9CuB4hmPI=; b=LFYfq029YPxZCP+6yX7TUBbT/V2LmYaw+yxt8xXcRuw9G350fn+D8THHWxyLczgxeGbvGs MaHx9yIGlyHG9kxsJP2h0LmpiTSsZ3MGMdzwW6VgxWeshqVwuaRIM5Uvm0TyYFnbMhVS7F fOA/PqcdHBjfcitPT6CzsonihKcY1Yw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-38-KCDAK3XlN7GOPnc4eH1kZA-1; Fri, 24 Jan 2025 04:45:31 -0500 X-MC-Unique: KCDAK3XlN7GOPnc4eH1kZA-1 X-Mimecast-MFC-AGG-ID: KCDAK3XlN7GOPnc4eH1kZA Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43624b08181so10185575e9.0 for ; Fri, 24 Jan 2025 01:45:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711930; x=1738316730; 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=6bbpMEor1R2bRwOjlbdZexCI/CHydxS93U9CuB4hmPI=; b=eW0BkaEQ18IazG3qLZrG9AbIFGpodbFnJAEj7T3L8Pum7H1I9gdcN1yHuq5Fzkr0e6 voGpGzYHBXLNI67gVskiuU91patlErEYGOq06X2fdGzrRowsIiQ5Kk8F6gIEVk8HKVC8 hwpUF9Nt1Bdr62BMc0gmaYt6raYzb2o/v6Y4/zhlNcqnT3zNfOJRj1c35Vvj+nt00pmD 8bW3Vl0cU0O49fLRHOEPzXCYApwUMrSRniKgivgiOuc+eBTE0OMffAwiX6Wiz5CPHvXh davVXRq21t1+o6MkOlkyedOvmPCMwCthzqHAE4uVAZ08+ZOzvnR2LQdgQaGuBqIHEFSe SsNQ== X-Gm-Message-State: AOJu0Yx66L5cfqZILQKvUgRvvHq5xBIp4HG1DsG57IYfCRlARvavDpWY gMIxPOZDDQ6WbGIMXhGggjuty/pn+Ml0gN0/NDljJDJhCKjzC3dWOwDGJjrPvnLDRLcBqO41HRr N2qA9ni45bH1kVhcEm+xvHm1E6u3NGdBReoBkjkIOsn5lTxdUusarCYOCrHAy8E5mRIc579ilF4 mWmgjSA8hqf4sarIJ/LunPISngyum17Kx/9OrhPi4= X-Gm-Gg: ASbGncv3cpvMzGxfepybIoGZpciJ1kJVSvQFUjV3LUGSQ+sLZIzkFjC570NdxbLGPOj bLhs83vihQN2Fyp1m52cl+ilZUcb/YiU3O+Pwa9M6V1LBFyiV7XhN/2UPb//0QnMj879ynEIjzu MBWSrGeMTA6+nw3sRWQ03eoOMgLu0OKMhcyN2HEsdasriPCrcPOvrE9lwJ0cU7hX7y4lccBJNgn xmwqTQuTYmBFz1Kpz//nLzJOK/c99MRupo8y/oxXq2jXitsDSBeRR6xibK7bJl7oey7/IZZaA== X-Received: by 2002:a05:600c:4fcf:b0:434:e892:1033 with SMTP id 5b1f17b1804b1-438bd052fedmr24335575e9.2.1737711929782; Fri, 24 Jan 2025 01:45:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMy8nR8jXlLgW7lQ+fq1Z8BGr/NbZMwdE3nztVlUkfmqPqIaKMctM4WuO5lytPuB72ohNnFw== X-Received: by 2002:a05:600c:4fcf:b0:434:e892:1033 with SMTP id 5b1f17b1804b1-438bd052fedmr24335225e9.2.1737711929329; Fri, 24 Jan 2025 01:45:29 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd507c59sm20071965e9.17.2025.01.24.01.45.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 23/48] memattrs: Convert unspecified member to bool Date: Fri, 24 Jan 2025 10:44:17 +0100 Message-ID: <20250124094442.13207-24-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Convert `unspecified` member of MemTxAttrs from bit field to bool, so that bindgen could generate more ergonomic Rust binding with bool type. As a result, MemTxAttrs needs to be expanded from 4 bytes to 8 bytes. Therefore, move `unspecified` to after the bit fields and add reserved members to ensure that the whole structure is packed into 8 bytes. Suggested-by: Richard Henderson Suggested-by: Paolo Bonzini Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250121151322.171832-2-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- include/exec/memattrs.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index e27c18f3dc3..4fde4eee843 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -23,12 +23,6 @@ * different semantics. */ typedef struct MemTxAttrs { - /* Bus masters which don't specify any attributes will get this - * (via the MEMTXATTRS_UNSPECIFIED constant), so that we can - * distinguish "all attributes deliberately clear" from - * "didn't specify" if necessary. - */ - unsigned int unspecified:1; /* * ARM/AMBA: TrustZone Secure access * x86: System Management Mode access @@ -57,6 +51,17 @@ typedef struct MemTxAttrs { * PID (PCI PASID) support: Limited to 8 bits process identifier. */ unsigned int pid:8; + + /* + * Bus masters which don't specify any attributes will get this + * (via the MEMTXATTRS_UNSPECIFIED constant), so that we can + * distinguish "all attributes deliberately clear" from + * "didn't specify" if necessary. + */ + bool unspecified; + + uint8_t _reserved1; + uint16_t _reserved2; } MemTxAttrs; /* Bus masters which don't specify any attributes will get this, @@ -64,7 +69,7 @@ typedef struct MemTxAttrs { * (so that we can distinguish "all attributes deliberately clear" * from "didn't specify" if necessary). */ -#define MEMTXATTRS_UNSPECIFIED ((MemTxAttrs) { .unspecified = 1 }) +#define MEMTXATTRS_UNSPECIFIED ((MemTxAttrs) { .unspecified = true }) /* New-style MMIO accessors can indicate that the transaction failed. * A zero (MEMTX_OK) response means success; anything else is a failure From patchwork Fri Jan 24 09:44:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949212 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 42A96C02181 for ; Fri, 24 Jan 2025 09:52:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGID-0005Pm-3A; Fri, 24 Jan 2025 04:48:01 -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 1tbGFu-0007By-M7 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:41 -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 1tbGFt-0003vD-1S for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711935; 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=yvbr/euLYmsi01MyC/bxJYSQaCK8iNl78JJ9FTSlmig=; b=aztr62+fVqIDyAjMGheHp5SRgo9ts1zNSXmKqjv5qezd+KfJvqJv2JmEk0SbX4NXTbSJjk Jt6lzIvDlmzuyzSzrnCvm59hO5/xKuXEGfMZmVIZW0gLL9VgmjPEdnmzCFpYaVP9CGC4Kg RLNfmIoDCshPlPCRa7COMyqs6UiYTK8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-110-kaD5ZBWrMeGlUNqvchK06g-1; Fri, 24 Jan 2025 04:45:33 -0500 X-MC-Unique: kaD5ZBWrMeGlUNqvchK06g-1 X-Mimecast-MFC-AGG-ID: kaD5ZBWrMeGlUNqvchK06g Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43673af80a6so13352135e9.1 for ; Fri, 24 Jan 2025 01:45:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711931; x=1738316731; 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=yvbr/euLYmsi01MyC/bxJYSQaCK8iNl78JJ9FTSlmig=; b=xJ5RymGhpLOW8c8t1uNiOk3j8BgkXo3VBBE2oPfrWhltBcr+Lwj6KgqP5WE1lyd79w w1yG4PVcXY4Fuwab90Ih/is1GYAUtH8ReHVvJgEXl3W5qWuQux6cHPcIcEyv6J+jmoo/ XhEQVO24DQ76AOYHb8/nT5BApIQudLcKBFjCtiX3FxjWj9759YyVwRZDIU0X0dfD/Ziv /fi07Mn1f2XVTTGOzZRegSIFQ0sUReVQcVraW9cj7LwZlYz0QVUseYaO8TM8ANTzMwAC WNFvbUvP3Agr31hkyHKf/wKm7eLzlMO9xXK2TsnlbBGlAEaR1BvbvuuNbKI/EmY4N//t ifmA== X-Gm-Message-State: AOJu0YyfSbfgspM6qI1hHNSTdObRDQLE7PP7UTQctvsx6atYj6ZeCWtR lYPsEAgUp/6bDGjs0B5YCWqjh4ipmXgt3qeqzdgKc2wvJBV5lsO3YaQ7MXVrhhhClMCiFbsuqBb MLQnAJG86MUdOee+FrYZwMcKw6UnpTQpSbqTWZmruci8y/n909nzgPgVtmG3c0zvGJXBZrC8roL nmgcS7718s+BCSYXiGrXPNcKqWWBz+AUSspufxIHs= X-Gm-Gg: ASbGnctpgQtJQvTpeTdlPzDQO9rcT7ZM1YWGNELRX4viHRI5+GFBH74xI5Ku4l9ElPe wmyMJyebGKgXe4fOZE99O1kp6wujV6oKtEAFzP+VFW5tZsr6DyMc5uz9aUwPkGjoCzZDNtFvf25 LYxeLqGn3Rp0ivJmnh31YT3FaF/vMfJRpFf75wyIExEH4QAhl1oOL4o3yERPwS8Gla3H9UYSAr+ +njimnAoshJhNa4+3aERPMXQFqEEejKOU1/PE0mnwcWEFRGFl4iYiHMJUROjDifTwgYvdPT/A== X-Received: by 2002:a05:600c:511b:b0:435:14d:f61a with SMTP id 5b1f17b1804b1-438914304a8mr213647055e9.25.1737711931674; Fri, 24 Jan 2025 01:45:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKkR6w5XYAxB63/i7et5JL3JLz14imn+MOMh1OUbq69Am4fQn2rUta9B+G2TNyg4bTxmuKrw== X-Received: by 2002:a05:600c:511b:b0:435:14d:f61a with SMTP id 5b1f17b1804b1-438914304a8mr213646855e9.25.1737711931269; Fri, 24 Jan 2025 01:45:31 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd48a906sm20805735e9.18.2025.01.24.01.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 24/48] memattrs: Check the size of MemTxAttrs Date: Fri, 24 Jan 2025 10:44:18 +0100 Message-ID: <20250124094442.13207-25-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Make sure MemTxAttrs is packed into 8 bytes and does not exceed 8 bytes. Suggested-by: Philippe Mathieu-Daudà Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250121151322.171832-3-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- include/exec/memattrs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index 4fde4eee843..060b7e71314 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -64,6 +64,8 @@ typedef struct MemTxAttrs { uint16_t _reserved2; } MemTxAttrs; +QEMU_BUILD_BUG_ON(sizeof(MemTxAttrs) > 8); + /* Bus masters which don't specify any attributes will get this, * which has all attribute bits clear except the topmost one * (so that we can distinguish "all attributes deliberately clear" From patchwork Fri Jan 24 09:44: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: 13949202 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 072C2C02181 for ; Fri, 24 Jan 2025 09:51:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHn-0002pB-I6; Fri, 24 Jan 2025 04:47: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 1tbGFw-0007Fs-TF for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45: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 1tbGFu-0003vc-TS for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711937; 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=x12cdz98fJEGCgnfpXNEyv2Wt4PmKvtkHskbUpC7miM=; b=LzWy5ElwWtMyc9Un1jIeeY3qSaEfwHjtmusQIv1gon2qFPbagQ0vqaOY3DJx+oKCiLLkZe jq7zznF1pdudRI3rFs1kKPuizpH+mUIbvB5+C1tB+p7NTqSPQGnSp4ESFMHDTrAWYCiwLN tdEZ1lIWaXUlu8bW0Xrax1PL0/MTDBs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-Edx-51ukNKWTwCpDy1eYaQ-1; Fri, 24 Jan 2025 04:45:36 -0500 X-MC-Unique: Edx-51ukNKWTwCpDy1eYaQ-1 X-Mimecast-MFC-AGG-ID: Edx-51ukNKWTwCpDy1eYaQ Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4362153dcd6so9082895e9.2 for ; Fri, 24 Jan 2025 01:45:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711935; x=1738316735; 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=x12cdz98fJEGCgnfpXNEyv2Wt4PmKvtkHskbUpC7miM=; b=R7BFs/sZyr7lyvtZaRJFd922YEOS2J1HdRdvVCE98+VqLCr2ZwcbR4iM2xcW5sHb8C GTxDkYpAZOmmM/hqmr9igpR6sTioi4Dt+FlDEJyQClJfjZw9jtTPHTN1BOBd2MObROM4 7+bbNV5rJf7NU/7FC7YoKZA4adPBez7TLCxKhHIgh3jYAmwe4uLE8T7nWjtXlcJqK0ve NwzRgVjTg0Iy/bVCy1TwyAeayJ9HCenjmAbbpaLQqzdherHeoT0URBFcuCmcYExN2Hjd 7QEoG9K0KSagRzf4Ee3zJT27sp8jiaPq4VB9czkaE+H+BKt5yKxdaKBzyR+ds6g7J/QA 8W0g== X-Gm-Message-State: AOJu0Yzvieob+GDo9peKAiM04orW2makWjnprrTLjC8qeALm+NLPYYw7 HO7z2yc8pBvtW9yyWyHfYIJW8vFPmjbdAshuxK26jXJuX7iUeO9f9BpFY88Ne+NoS0MmHqaIbS5 lpJjG4wqAZq1vBYm4sANKYqxbDmXsIR8yPytuG6BwnKmEW8tY/bEasNCdzdwK7HHAB0L8YR9XSW T6/ByF06k1eFPZmOXkVhblekiMVt09+iH7bPjAiec= X-Gm-Gg: ASbGnctRI7KU80MCDsBn+qE5clYbLhMRGaQPeSDTcmWA7YYeg5ZezKjOPMz4hmTnKp+ J1JMk0D0LGoPfXOOoomC5XGKSSDEShuYo0auHqesFMf3q4WG/P4V9lpNUBWVc6WiP7KIUHXCiZb JIzqa2ispwj4idC7mqt/pmmRgtzas0jHT9sj9Ud+elrXMIe8drSEbxwg8p/riG1slehVT1C8Dm/ KqLArJXbAQyqvVfjlzkS/dSJeiNWemqjPQX7S4tH0so++qCo1+EPPsyAt+yzc3711qqJnbLxA== X-Received: by 2002:a05:600c:3593:b0:434:a239:d2fe with SMTP id 5b1f17b1804b1-4389144d62cmr240608725e9.28.1737711934691; Fri, 24 Jan 2025 01:45:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfjtSQ0sPoKCbQMqJMKpfHplSWXi8EYMgNxscny1LIbjP4bwNNeXvEjySXtLBMxrZpkMh7Nw== X-Received: by 2002:a05:600c:3593:b0:434:a239:d2fe with SMTP id 5b1f17b1804b1-4389144d62cmr240608515e9.28.1737711934182; Fri, 24 Jan 2025 01:45:34 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd48574csm20782835e9.9.2025.01.24.01.45.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 25/48] rust: vmstate: add new type safe implementation Date: Fri, 24 Jan 2025 10:44:19 +0100 Message-ID: <20250124094442.13207-26-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 The existing translation of the C macros for vmstate does not make any attempt to type-check vmstate declarations against the struct, so introduce a new system that computes VMStateField based on the actual struct declaration. Macros do not have full access to the type system, therefore a full implementation of this scheme requires a helper trait to analyze the type and produce a VMStateField from it; a macro "vmstate_of!" accepts arguments similar to "offset_of!" and tricks the compiler into looking up the trait for the right type. The patch introduces not just vmstate_of!, but also the slightly too clever enabling macro call_func_with_field!. The particular trick used here was proposed on the users.rust-lang.org forum, so I take no merit and all the blame. Introduce the trait and some functions to access it; the actual implementation comes later. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/prelude.rs | 2 + rust/qemu-api/src/vmstate.rs | 113 +++++++++++++++++++++++++++++++++-- 2 files changed, 109 insertions(+), 6 deletions(-) diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs index 4ea70b9c823..2dc86e19b29 100644 --- a/rust/qemu-api/src/prelude.rs +++ b/rust/qemu-api/src/prelude.rs @@ -18,3 +18,5 @@ pub use crate::qom_isa; pub use crate::sysbus::SysBusDeviceMethods; + +pub use crate::vmstate::VMState; diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 63c897abcdf..b839a7d6b7f 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -4,13 +4,114 @@ //! Helper macros to declare migration state for device models. //! -//! Some macros are direct equivalents to the C macros declared in -//! `include/migration/vmstate.h` while -//! [`vmstate_subsections`](crate::vmstate_subsections) and -//! [`vmstate_fields`](crate::vmstate_fields) are meant to be used when -//! declaring a device model state struct. +//! This module includes three families of macros: +//! +//! * [`vmstate_unused!`](crate::vmstate_unused) and +//! [`vmstate_of!`](crate::vmstate_of), which are used to express the +//! migration format for a struct. This is based on the [`VMState`] trait, +//! which is defined by all migrateable types. +//! +//! * helper macros to declare a device model state struct, in particular +//! [`vmstate_subsections`](crate::vmstate_subsections) and +//! [`vmstate_fields`](crate::vmstate_fields). +//! +//! * direct equivalents to the C macros declared in +//! `include/migration/vmstate.h`. These are not type-safe and should not be +//! used if the equivalent functionality is available with `vmstate_of!`. -pub use crate::bindings::VMStateDescription; +use core::marker::PhantomData; + +pub use crate::bindings::{VMStateDescription, VMStateField}; + +/// This macro is used to call a function with a generic argument bound +/// to the type of a field. The function must take a +/// [`PhantomData`]`` argument; `T` is the type of +/// field `$field` in the `$typ` type. +/// +/// # Examples +/// +/// ``` +/// # use qemu_api::call_func_with_field; +/// # use core::marker::PhantomData; +/// const fn size_of_field(_: PhantomData) -> usize { +/// std::mem::size_of::() +/// } +/// +/// struct Foo { +/// x: u16, +/// }; +/// // calls size_of_field::() +/// assert_eq!(call_func_with_field!(size_of_field, Foo, x), 2); +/// ``` +#[macro_export] +macro_rules! call_func_with_field { + // Based on the answer by user steffahn (Frank Steffahn) at + // https://users.rust-lang.org/t/inferring-type-of-field/122857 + // and used under MIT license + ($func:expr, $typ:ty, $($field:tt).+) => { + $func(loop { + #![allow(unreachable_code)] + const fn phantom__(_: &T) -> ::core::marker::PhantomData { ::core::marker::PhantomData } + // Unreachable code is exempt from checks on uninitialized values. + // Use that trick to infer the type of this PhantomData. + break ::core::marker::PhantomData; + break phantom__(&{ let value__: $typ; value__.$($field).+ }); + }) + }; +} + +/// A trait for types that can be included in a device's migration stream. It +/// provides the base contents of a `VMStateField` (minus the name and offset). +/// +/// # Safety +/// +/// The contents of this trait go straight into structs that are parsed by C +/// code and used to introspect into other structs. Be careful. +pub unsafe trait VMState { + /// The base contents of a `VMStateField` (minus the name and offset) for + /// the type that is implementing the trait. + const BASE: VMStateField; +} + +/// Internal utility function to retrieve a type's `VMStateField`; +/// used by [`vmstate_of!`](crate::vmstate_of). +pub const fn vmstate_base(_: PhantomData) -> VMStateField { + T::BASE +} + +/// Return the `VMStateField` for a field of a struct. The field must be +/// visible in the current scope. +/// +/// In order to support other types, the trait `VMState` must be implemented +/// for them. +#[macro_export] +macro_rules! vmstate_of { + ($struct_name:ty, $field_name:ident $(,)?) => { + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), "\0") + .as_bytes() + .as_ptr() as *const ::std::os::raw::c_char, + offset: $crate::offset_of!($struct_name, $field_name), + // Compute most of the VMStateField from the type of the field. + ..$crate::call_func_with_field!( + $crate::vmstate::vmstate_base, + $struct_name, + $field_name + ) + } + }; +} + +// Add a couple builder-style methods to VMStateField, allowing +// easy derivation of VMStateField constants from other types. +impl VMStateField { + #[must_use] + pub const fn with_version_id(mut self, version_id: i32) -> Self { + assert!(version_id >= 0); + self.version_id = version_id; + self + } +} #[doc(alias = "VMSTATE_UNUSED_BUFFER")] #[macro_export] From patchwork Fri Jan 24 09:44: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: 13949169 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 48E15C0218B for ; Fri, 24 Jan 2025 09:47:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHS-0000n4-73; Fri, 24 Jan 2025 04:47: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 1tbGFz-0007Jf-Pp for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:44 -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 1tbGFx-0003w6-DP for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711940; 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=WuoN8SLEI/o39maAHg/7so9lLNQmaFy/97KoTszJKKQ=; b=XlztEyWJRYeNvB/tiRnUhuMNFRhVKtxp7bDqZSnGCpSEbz3aUPYxmTGtzNazVkvJd5r9MJ 5vsuySiUKwYPp22jyp6OGTzPCPkXzdKUtbObHVzQlL3mF1zlaGAGcsqNz1/GNO44oFHMVi 65mqbTzmikcLpg7/sjaRy9xZWdRNdV0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-UQNJI1oKO9yvAvo7ljR4Uw-1; Fri, 24 Jan 2025 04:45:38 -0500 X-MC-Unique: UQNJI1oKO9yvAvo7ljR4Uw-1 X-Mimecast-MFC-AGG-ID: UQNJI1oKO9yvAvo7ljR4Uw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361ac8b25fso10149085e9.2 for ; Fri, 24 Jan 2025 01:45:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711936; x=1738316736; 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=WuoN8SLEI/o39maAHg/7so9lLNQmaFy/97KoTszJKKQ=; b=ZLDddjG9xuqmS/cxRqsVM+5Ijck3mxVLuXS0LcIuoi7m+W7ZK0aEg/jeaAeGLCxcDp /2rcbkbqSjRMLZDBN2oz76Y3mtxmtEyuYneMad8SPUXqGb9YCLoWGhmm4YI6hi8ZO8dN F/GMQ1szmADVyILT1rXltxp+guP5KDWyq/3P43jW++fP5PIkVTWJ4hFZrb/vEXMPtRuE R0G8JWvLmehZICh5x8iSF+pqLlwe8cA4G66fzF2UI7+dh1Fxl27viFEsJMs5gqkqrv1Q U+xzgKYmLbn1zglu43/xV54SuBa51WHFSbjcN3qGcpBuXjExFQHBB9nHDBFWLA5t4VC1 jjBA== X-Gm-Message-State: AOJu0YzmM+B5gXhLTY3sk66iF//e3wjWRRUH6GYhuVT/7Kd7aydVrG18 5YN3vGOhfT1U+8VcDjOnOjStZxlsry7LKHzpfWpKqXvazeJhdNvczysndyn/kZy3bYTl8oKlVqo O88+BzttuRY/lH3zv37SdzMoac8Y3kVaNc4F0MskCs5BgQA11ahc/D6hWL4DgkZm4tvRy2LRZqS VJxIGE3Wxyxu1t9rnPFG3TrS4Ik6O2XQixp7W9+wY= X-Gm-Gg: ASbGncsFa4twHTCy3nKa49QM1rmbH3lMJwAie34EtBwvvWDHprD5I9ifRh0wBzzFoCH XYIwiyoiH8wOgUh1CYViZnxEWLyGOlocnzHXvcu7x1CeobOegSxuCG92PwgrGZthukpuegsL9ap 4B6QT3FxEV/x1DZuPIqPTo+o4HC0fTVVa3/jXw1EDcUc4V7jXMbuV453uBO2DrxElhsGgzUAouC F3+k+9NoXgQ/AiE5tbca6ZXTdF9AKwWdykscBeOasxCJ8k/agjp2AFyf0WUz5i2K5/miExXjg== X-Received: by 2002:a05:600c:5021:b0:436:1c0c:bfb6 with SMTP id 5b1f17b1804b1-438914514f2mr244848995e9.27.1737711936470; Fri, 24 Jan 2025 01:45:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+cxcSOIcrJqmFFnL92uu2ZGDmPzzYW4L4730MT2xj8Ea51jXn02blTc6ontKhcpM0Fkw7lA== X-Received: by 2002:a05:600c:5021:b0:436:1c0c:bfb6 with SMTP id 5b1f17b1804b1-438914514f2mr244848755e9.27.1737711935992; Fri, 24 Jan 2025 01:45:35 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd47f355sm20441285e9.4.2025.01.24.01.45.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:35 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 26/48] rust: vmstate: implement VMState for non-leaf types Date: Fri, 24 Jan 2025 10:44:20 +0100 Message-ID: <20250124094442.13207-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Arrays, pointers and cells use a VMStateField that is based on that for the inner type. The implementation therefore delegates to the VMState implementation of the inner type. Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/vmstate.rs | 79 +++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index b839a7d6b7f..211c3d096b7 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -19,8 +19,9 @@ //! `include/migration/vmstate.h`. These are not type-safe and should not be //! used if the equivalent functionality is available with `vmstate_of!`. -use core::marker::PhantomData; +use core::{marker::PhantomData, mem, ptr::NonNull}; +use crate::bindings::VMStateFlags; pub use crate::bindings::{VMStateDescription, VMStateField}; /// This macro is used to call a function with a generic argument bound @@ -102,6 +103,15 @@ macro_rules! vmstate_of { }; } +impl VMStateFlags { + const VMS_VARRAY_FLAGS: VMStateFlags = VMStateFlags( + VMStateFlags::VMS_VARRAY_INT32.0 + | VMStateFlags::VMS_VARRAY_UINT8.0 + | VMStateFlags::VMS_VARRAY_UINT16.0 + | VMStateFlags::VMS_VARRAY_UINT32.0, + ); +} + // Add a couple builder-style methods to VMStateField, allowing // easy derivation of VMStateField constants from other types. impl VMStateField { @@ -111,6 +121,73 @@ pub const fn with_version_id(mut self, version_id: i32) -> Self { self.version_id = version_id; self } + + #[must_use] + pub const fn with_array_flag(mut self, num: usize) -> Self { + assert!(num <= 0x7FFF_FFFFusize); + assert!((self.flags.0 & VMStateFlags::VMS_ARRAY.0) == 0); + assert!((self.flags.0 & VMStateFlags::VMS_VARRAY_FLAGS.0) == 0); + if (self.flags.0 & VMStateFlags::VMS_POINTER.0) != 0 { + self.flags = VMStateFlags(self.flags.0 & !VMStateFlags::VMS_POINTER.0); + self.flags = VMStateFlags(self.flags.0 | VMStateFlags::VMS_ARRAY_OF_POINTER.0); + } + self.flags = VMStateFlags(self.flags.0 & !VMStateFlags::VMS_SINGLE.0); + self.flags = VMStateFlags(self.flags.0 | VMStateFlags::VMS_ARRAY.0); + self.num = num as i32; + self + } + + #[must_use] + pub const fn with_pointer_flag(mut self) -> Self { + assert!((self.flags.0 & VMStateFlags::VMS_POINTER.0) == 0); + self.flags = VMStateFlags(self.flags.0 | VMStateFlags::VMS_POINTER.0); + self + } +} + +// Transparent wrappers: just use the internal type + +macro_rules! impl_vmstate_transparent { + ($type:ty where $base:tt: VMState $($where:tt)*) => { + unsafe impl<$base> VMState for $type where $base: VMState $($where)* { + const BASE: VMStateField = VMStateField { + size: mem::size_of::<$type>(), + ..<$base as VMState>::BASE + }; + } + }; +} + +impl_vmstate_transparent!(std::cell::Cell where T: VMState); +impl_vmstate_transparent!(std::cell::UnsafeCell where T: VMState); +impl_vmstate_transparent!(crate::cell::BqlCell where T: VMState); +impl_vmstate_transparent!(crate::cell::BqlRefCell where T: VMState); + +// Pointer types using the underlying type's VMState plus VMS_POINTER +// Note that references are not supported, though references to cells +// could be allowed. + +macro_rules! impl_vmstate_pointer { + ($type:ty where $base:tt: VMState $($where:tt)*) => { + unsafe impl<$base> VMState for $type where $base: VMState $($where)* { + const BASE: VMStateField = <$base as VMState>::BASE.with_pointer_flag(); + } + }; +} + +impl_vmstate_pointer!(*const T where T: VMState); +impl_vmstate_pointer!(*mut T where T: VMState); +impl_vmstate_pointer!(NonNull where T: VMState); + +// Unlike C pointers, Box is always non-null therefore there is no need +// to specify VMS_ALLOC. +impl_vmstate_pointer!(Box where T: VMState); + +// Arrays using the underlying type's VMState plus +// VMS_ARRAY/VMS_ARRAY_OF_POINTER + +unsafe impl VMState for [T; N] { + const BASE: VMStateField = ::BASE.with_array_flag(N); } #[doc(alias = "VMSTATE_UNUSED_BUFFER")] From patchwork Fri Jan 24 09:44: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: 13949207 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 8866BC02181 for ; Fri, 24 Jan 2025 09:52:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGIi-0007Qc-Mm; Fri, 24 Jan 2025 04:48:33 -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 1tbGG2-0007Nn-5T for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45: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 1tbGG0-0003wS-Je for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711943; 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=iUzMFIurVFZDuf9mlbfI79G6/XfuTB6fCKo65mN+6bA=; b=eGDi1ZDYPYDDOMXoVb+fK6Nchki1EBCla7YlV22dsN6+tU8ilgPen/A+4vFj6APLf24g5a jr5fMcIcf8Vn3K3MXOyONLuyJs6z4IwsOggqu7ApA9rKc8S0hEXQ5s5XarbLkJwE0CZExW ZGO5URvwqvY6l+pqZ7T0R+I52XNFcw8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-BKGuiY_jN3uqEcFp2Ab2-g-1; Fri, 24 Jan 2025 04:45:42 -0500 X-MC-Unique: BKGuiY_jN3uqEcFp2Ab2-g-1 X-Mimecast-MFC-AGG-ID: BKGuiY_jN3uqEcFp2Ab2-g Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-388d1f6f3b2so848841f8f.0 for ; Fri, 24 Jan 2025 01:45:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711940; x=1738316740; 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=iUzMFIurVFZDuf9mlbfI79G6/XfuTB6fCKo65mN+6bA=; b=cSPr9DO9cLObT00lhPKSqmvGEoQFKUhCp5U7y7EOQ4VprloUdlbTuOHxFcmsquv6Ov G1h5Dc8RazQDAooSEoybdlMbTQH1z5sWP+P9APUCyYLCOURIMQ/7sHbaSQfFxlRT1iTO H+G5ZcclvoheBQzHhHsqR9KDlo08hSn+or/NfBF1XbKUlFM01m7uRWScM2+825NCRS0F wFXedWSdYdNPVkuVmQUYQjmM5Oj1teOylJr27AqIqcxvhyVI6U3gXtopFhfFqVhdmIuI lU8oDEyLZM1nhdjXfDHqIlELzY9+I92BVHW7CXHVQl8sRS6ACElMHVWgHjMSxJKkMQAD VOUA== X-Gm-Message-State: AOJu0YwcLTgKdbcdq7BHcgCl2j8G4MF5FHquAFj+1GGhSJ8MWQhfo76l ynsNhv6euxyLb0+u/u4m/u2Y/nQxEHTAnuCEehybZst7A9hnbu3oEdVR6E0EfcS9lIuurr7ckj5 cSYGeTkgifZwfDVhRFRdizbywxvDfYSlO6HGcYZqUnrEO5IvEr85RDSnuwJJlUUoNWfOT6OkFoJ YsSYLe1folTKezvDPRuCPY4k7dNsSBN8SVLWBEmFQ= X-Gm-Gg: ASbGncteUkwdHy9pjrveU17bGc8H7pazjWHbtZxCtWWCcMSrO7pMGdYctFgOko483a7 ZeInhbRGW7JvwzlZG6ZQjvrk0cI2tS544ygGqJlxHzbNBD9KToa0QkbC4JTPuQi1P8J17YuYSk2 DR/DD6uVNhgCh+9t90SqZRnb4JzCWe38GGN35fIfhre8EeEbJQ6W4D14YdBY0SYShZEs5dfI3B0 NBNuyszSKFSeQ1Z26eMfrSbPvokoq8dDwUzZyRQeA07JjIntRwAqivuU4x7TYFdRdV+Ky9UHA== X-Received: by 2002:a5d:4207:0:b0:38b:ebcd:305c with SMTP id ffacd0b85a97d-38bf5675826mr21816588f8f.29.1737711939630; Fri, 24 Jan 2025 01:45:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVv96LqD7sfaqk8mv6sYQsgNUHWv3HMbkMyQOw0qVEXsAHBPEQQd5mihfPaWGDzMS1uIVEMw== X-Received: by 2002:a5d:4207:0:b0:38b:ebcd:305c with SMTP id ffacd0b85a97d-38bf5675826mr21816558f8f.29.1737711939057; Fri, 24 Jan 2025 01:45:39 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a18859asm2145107f8f.42.2025.01.24.01.45.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 27/48] rust: vmstate: add varray support to vmstate_of! Date: Fri, 24 Jan 2025 10:44:21 +0100 Message-ID: <20250124094442.13207-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/vmstate.rs | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 211c3d096b7..2b14d4839df 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -72,6 +72,15 @@ pub unsafe trait VMState { /// The base contents of a `VMStateField` (minus the name and offset) for /// the type that is implementing the trait. const BASE: VMStateField; + + /// A flag that is added to another field's `VMStateField` to specify the + /// length's type in a variable-sized array. If this is not a supported + /// type for the length (i.e. if it is not `u8`, `u16`, `u32`), using it + /// in a call to [`vmstate_of!`](crate::vmstate_of) will cause a + /// compile-time error. + const VARRAY_FLAG: VMStateFlags = { + panic!("invalid type for variable-sized array"); + }; } /// Internal utility function to retrieve a type's `VMStateField`; @@ -80,6 +89,13 @@ pub const fn vmstate_base(_: PhantomData) -> VMStateField { T::BASE } +/// Internal utility function to retrieve a type's `VMStateFlags` when it +/// is used as the element count of a `VMSTATE_VARRAY`; used by +/// [`vmstate_of!`](crate::vmstate_of). +pub const fn vmstate_varray_flag(_: PhantomData) -> VMStateFlags { + T::VARRAY_FLAG +} + /// Return the `VMStateField` for a field of a struct. The field must be /// visible in the current scope. /// @@ -87,18 +103,23 @@ pub const fn vmstate_base(_: PhantomData) -> VMStateField { /// for them. #[macro_export] macro_rules! vmstate_of { - ($struct_name:ty, $field_name:ident $(,)?) => { + ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:expr)?])? $(,)?) => { $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name), "\0") .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, offset: $crate::offset_of!($struct_name, $field_name), // Compute most of the VMStateField from the type of the field. + $(.num_offset: $crate::offset_of!($struct_name, $num),)? ..$crate::call_func_with_field!( $crate::vmstate::vmstate_base, $struct_name, $field_name - ) + )$(.with_varray_flag($crate::call_func_with_field!( + $crate::vmstate::vmstate_varray_flag, + $struct_name, + $num)) + $(.with_varray_multiply($factor))?)? } }; } @@ -143,6 +164,22 @@ pub const fn with_pointer_flag(mut self) -> Self { self.flags = VMStateFlags(self.flags.0 | VMStateFlags::VMS_POINTER.0); self } + + #[must_use] + pub const fn with_varray_flag(mut self, flag: VMStateFlags) -> VMStateField { + assert!((self.flags.0 & VMStateFlags::VMS_ARRAY.0) != 0); + self.flags = VMStateFlags(self.flags.0 & !VMStateFlags::VMS_ARRAY.0); + self.flags = VMStateFlags(self.flags.0 | flag.0); + self + } + + #[must_use] + pub const fn with_varray_multiply(mut self, num: u32) -> VMStateField { + assert!(num <= 0x7FFF_FFFFu32); + self.flags = VMStateFlags(self.flags.0 | VMStateFlags::VMS_MULTIPLY_ELEMENTS.0); + self.num = num as i32; + self + } } // Transparent wrappers: just use the internal type @@ -154,6 +191,7 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* { size: mem::size_of::<$type>(), ..<$base as VMState>::BASE }; + const VARRAY_FLAG: VMStateFlags = <$base as VMState>::VARRAY_FLAG; } }; } From patchwork Fri Jan 24 09:44: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: 13949209 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 CE628C0218C for ; Fri, 24 Jan 2025 09:52:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGIE-0005YV-0J; Fri, 24 Jan 2025 04:48:02 -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 1tbGG6-0007TO-0L for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:53 -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 1tbGG4-0003wl-FB for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711947; 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=AeUloYUS4GjmUT75E0JIueWDFUGBROQ8X7lta1NSKvg=; b=H6mx6LYIz2PWbXxl6qtrXOZj7nOHwN++2WqY4v2CaQwuDzT2m4W/UxmYm9ZKPTd7DGLB5U M/EEOVh0dUIqUIa+bF66bHtFCnOKuzj2+SK0DhDJhO3yUFFPEFH29khq9AJJ3nNPpslw3d +NnYf2lee5CWdL0f5NTMWJ+MGEAlCS8= 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-304-O-r8OH37ONSzzYnYzWEs5w-1; Fri, 24 Jan 2025 04:45:42 -0500 X-MC-Unique: O-r8OH37ONSzzYnYzWEs5w-1 X-Mimecast-MFC-AGG-ID: O-r8OH37ONSzzYnYzWEs5w Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38a35a65575so1231514f8f.1 for ; Fri, 24 Jan 2025 01:45:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711941; x=1738316741; 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=AeUloYUS4GjmUT75E0JIueWDFUGBROQ8X7lta1NSKvg=; b=FY1vzXjJM8PjcziIa1H3ttyEwXQlQ/+Y4uC2N+CijYMYn6LeIxb5BHMWvuGI0BP15u jf8utCS/mWvzWr2b406YmM7PJDTajgDu9pmG5oPvsFE2js9RmDMXRVIp4p/43+RR5rVI MWfxlS8JS9dlMEh15VEbCRSFnyJKm0Hr8aQY1OV2ZnIvG3tonph/MefYcueLzz/ZXsXW obqkgRkxPrm/bXEH4QGjYaDt/yaGbvMmkbns1PBPxcfhYfJhJgVZayzvwUqGHqXnX92S 3UVuXpvuLBmjxoCcaHLPjOeldzTkiS9yZBQzUcRMmEhqz9C0BBCkGRdLoOPwJNxmZYg4 F+KA== X-Gm-Message-State: AOJu0Yy67XqU50Cw+9pT3q8Xcni/Xq8bNWOhB+/5trkYIPyp83LzHVkD rsBBej/Ri4Ks/7RB3ahqtYkK7Bm4x70/w+6d2/JxtBCzMJNHs/bPWz3nlYSETuFZS2647egbnxB I95nb8acAf11xwk544O5NpWMoIguHurSbMjJuFNZzJzx/08BvT4yI1I+eUmgpwMOz9hWHtLwkqt LcQmafO6DBhkOxXR4pqr1rkRpVoYHK0ssFD0sABKw= X-Gm-Gg: ASbGncsPfrfqnVXHnzfF9TeXXBLX/Ixxc/vKOnrIC2Ng88Zs8Q7FnFN3VDhVxoemWFX q3fmdt72E5+90vrLQUbl0mlK+n73jdkA484OqM7XD+zYHZ3YBI+oFcdASqqgidyhZE/j/d+ErxQ ofg4YtOOT7BR6WXWO69uN/oqk/uvlXMW2CzEUIZ2nGa3Zym3NBeevogFdJ8pBVoiK23JcR59FFe hRHHn+aoXOKwYHzhi/2d+WpAIz3G+Hi7fbYdNP4Ez2ZTKnVfj74FjzXcW90Qox90oMyQk/gKQ== X-Received: by 2002:a5d:6da4:0:b0:38b:e32a:10a6 with SMTP id ffacd0b85a97d-38bf57a9932mr32061193f8f.41.1737711940747; Fri, 24 Jan 2025 01:45:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGM/78mz3VExiNnYWsnIIdxajIW+OeoDI4UWKlixbxasFGOS+obUI6TGoIT2uOGTwVIzVecIQ== X-Received: by 2002:a5d:6da4:0:b0:38b:e32a:10a6 with SMTP id ffacd0b85a97d-38bf57a9932mr32061145f8f.41.1737711940331; Fri, 24 Jan 2025 01:45:40 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1bad92sm2161951f8f.61.2025.01.24.01.45.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 28/48] rust: vmstate: implement Zeroable for VMStateField Date: Fri, 24 Jan 2025 10:44:22 +0100 Message-ID: <20250124094442.13207-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 shortens a bit the constants. Do not bother using it in the vmstate macros since most of them will go away soon. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/vmstate.rs | 18 +++--------------- rust/qemu-api/src/zeroable.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 2b14d4839df..7652930affc 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -21,8 +21,8 @@ use core::{marker::PhantomData, mem, ptr::NonNull}; -use crate::bindings::VMStateFlags; pub use crate::bindings::{VMStateDescription, VMStateField}; +use crate::bindings::VMStateFlags; /// This macro is used to call a function with a generic argument bound /// to the type of a field. The function must take a @@ -503,20 +503,8 @@ macro_rules! vmstate_fields { static _FIELDS: &[$crate::bindings::VMStateField] = &[ $($field),*, $crate::bindings::VMStateField { - name: ::core::ptr::null(), - err_hint: ::core::ptr::null(), - offset: 0, - size: 0, - start: 0, - num: 0, - num_offset: 0, - size_offset: 0, - info: ::core::ptr::null(), - flags: VMStateFlags::VMS_END, - vmsd: ::core::ptr::null(), - version_id: 0, - struct_version_id: 0, - field_exists: None, + flags: $crate::bindings::VMStateFlags::VMS_END, + ..$crate::zeroable::Zeroable::ZERO } ]; _FIELDS.as_ptr() diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs index 6125aeed8b4..57cac96de06 100644 --- a/rust/qemu-api/src/zeroable.rs +++ b/rust/qemu-api/src/zeroable.rs @@ -49,6 +49,37 @@ unsafe impl Zeroable for crate::bindings::Property { }; } +// bindgen does not derive Default here +#[allow(clippy::derivable_impls)] +impl Default for crate::bindings::VMStateFlags { + fn default() -> Self { + Self(0) + } +} + +unsafe impl Zeroable for crate::bindings::VMStateFlags { + const ZERO: Self = Self(0); +} + +unsafe impl Zeroable for crate::bindings::VMStateField { + const ZERO: Self = Self { + name: ptr::null(), + err_hint: ptr::null(), + offset: 0, + size: 0, + start: 0, + num: 0, + num_offset: 0, + size_offset: 0, + info: ptr::null(), + flags: Zeroable::ZERO, + vmsd: ptr::null(), + version_id: 0, + struct_version_id: 0, + field_exists: None, + }; +} + unsafe impl Zeroable for crate::bindings::VMStateDescription { const ZERO: Self = Self { name: ptr::null(), From patchwork Fri Jan 24 09:44: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: 13949192 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 A4232C02181 for ; Fri, 24 Jan 2025 09:50:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHW-0001Ak-S1; Fri, 24 Jan 2025 04:47: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 1tbGGD-0007ZH-Og for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:59 -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 1tbGG7-0003x6-9e for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711950; 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=ER3J/G2n/x1etciyFe+iGi4cTA2mYslp7tdM9gzwjf0=; b=NHZ9B5RxEg6XflIjr9cTODioqC89eBwJwKORi8mG8tnodQSRYw6uxGdx0H9RQXFaOGkHv1 /XyJwc3cAavCgoSE5f1Knq+schXvsKCSRBOJcVUrdOikXA4Ue431ojY307Y/rPKHqlC7cN SJbq0ZBMoFQ/AWySpTMELVYQ+W6qsZk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-eiuTbOL-MkibkINRJM4ilQ-1; Fri, 24 Jan 2025 04:45:45 -0500 X-MC-Unique: eiuTbOL-MkibkINRJM4ilQ-1 X-Mimecast-MFC-AGG-ID: eiuTbOL-MkibkINRJM4ilQ Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-436219070b4so8837505e9.1 for ; Fri, 24 Jan 2025 01:45:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711943; x=1738316743; 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=ER3J/G2n/x1etciyFe+iGi4cTA2mYslp7tdM9gzwjf0=; b=ucxTDxx4xj0hA3thZFYgB0kEup37c2A+NUCgkRSjWgQTER2M5MSa4ZQqMbulHP9qkC 9CICx/6RzEdaRTWhGRxVWpuzqWsaNWTQJwfhrXElEbgtlPhWSaHrIgeY6+8ypH4cAP4S yX6fsCSvAopK424hBrW8j/QmfQbsnV/n6WDTBdPNGtrTCQp4PrEKwy58yorRNNgGaHQ+ TJMAvE0oKtkMCz9H9SWUh02pueS6Ujc3kz78Zt0RCHjvAgUNeja6I9nkeTKhyBltucKz UzTCfEYPMSvDMw8WAik/uKac/LhmfbwqbHB6PWlhE9pWhKjFzHgZuAxDeC70STuGTxyD gr0Q== X-Gm-Message-State: AOJu0YxCG9N8QJT+km9fi1YG1JTAOy8Fb7a2tq6sAW+JegE3h8REOJvB Pbvd2+Dy8FVQfpNTP6ixgZgp6yBxYiP2tXvygtCkc4ZleaER6qiNtGwZ4kfC3XYATjZ3VC+z/mc dK7dU6JtUkQHwvnQ3j+Fm/qFQvs41eacVWIppvw3y0bNEj7BE/3YhovJd4YnCnXFVs8M3z7gTWe sdWRg4p6cwnLthyM7yvAHLXz0AzzHklcS3qc9s4oc= X-Gm-Gg: ASbGncsAli2JsRry+9AHdMPr8Yqjlb3nAOfJiAjphGYPqju3KyyTuXbNcZSJrfJTMFH TlJPMewIhfZfI38eYHUs3E0MGvH79CWidXq3rSYEGRUsT+5mgblg2YE/NG95sioSWfkfJ1XrFe4 UKY9DGC4OBbwejdDjFNlTNKHi69mHQshujURQjtSDGKacPo2IWl4PwZjE9JAhJVsxYJul/NMcQY 5IwC147ds86MJraAzR3Dn6By+lMFFqgKJiB6/T4B3NufNJ8xICY9exuaALzHNMCHDcIShvm3w== X-Received: by 2002:a05:600c:1c93:b0:431:5863:4240 with SMTP id 5b1f17b1804b1-43891429c77mr245338575e9.24.1737711943379; Fri, 24 Jan 2025 01:45:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8KhK1T73h7P9Wlshy05YecWHsNCQOIsEAZN6pbI8qVVau+yAgRle1VJCR9b7nn7euu8VQ3g== X-Received: by 2002:a05:600c:1c93:b0:431:5863:4240 with SMTP id 5b1f17b1804b1-43891429c77mr245338195e9.24.1737711942791; Fri, 24 Jan 2025 01:45:42 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4857cesm20392295e9.13.2025.01.24.01.45.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:41 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 29/48] rust: vmstate: implement VMState for scalar types Date: Fri, 24 Jan 2025 10:44:23 +0100 Message-ID: <20250124094442.13207-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Scalar types are those that have their own VMStateInfo. This poses a problem in that references to VMStateInfo can only be included in associated consts starting with Rust 1.83.0, when the const_refs_static was stabilized. Removing the requirement is done by placing a limited list of VMStateInfos in an enum, and going from enum to &VMStateInfo only when building the VMStateField. The same thing cannot be done with VMS_STRUCT because the set of VMStateDescriptions extends to structs defined by the devices. Therefore, structs and cells cannot yet use vmstate_of!. Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/vmstate.rs | 128 ++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 7652930affc..a262c315da1 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -22,7 +22,10 @@ use core::{marker::PhantomData, mem, ptr::NonNull}; pub use crate::bindings::{VMStateDescription, VMStateField}; -use crate::bindings::VMStateFlags; +use crate::{ + bindings::{self, VMStateFlags}, + zeroable::Zeroable, +}; /// This macro is used to call a function with a generic argument bound /// to the type of a field. The function must take a @@ -61,6 +64,70 @@ const fn phantom__(_: &T) -> ::core::marker::PhantomData { ::core::marker: }; } +/// Workaround for lack of `const_refs_static`: references to global variables +/// can be included in a `static`, but not in a `const`; unfortunately, this +/// is exactly what would go in the `VMStateField`'s `info` member. +/// +/// This enum contains the contents of the `VMStateField`'s `info` member, +/// but as an `enum` instead of a pointer. +#[allow(non_camel_case_types)] +pub enum VMStateFieldType { + null, + vmstate_info_bool, + vmstate_info_int8, + vmstate_info_int16, + vmstate_info_int32, + vmstate_info_int64, + vmstate_info_uint8, + vmstate_info_uint16, + vmstate_info_uint32, + vmstate_info_uint64, + vmstate_info_timer, +} + +/// Workaround for lack of `const_refs_static`. Converts a `VMStateFieldType` +/// to a `*const VMStateInfo`, for inclusion in a `VMStateField`. +#[macro_export] +macro_rules! info_enum_to_ref { + ($e:expr) => { + unsafe { + match $e { + $crate::vmstate::VMStateFieldType::null => ::core::ptr::null(), + $crate::vmstate::VMStateFieldType::vmstate_info_bool => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_bool) + } + $crate::vmstate::VMStateFieldType::vmstate_info_int8 => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_int8) + } + $crate::vmstate::VMStateFieldType::vmstate_info_int16 => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_int16) + } + $crate::vmstate::VMStateFieldType::vmstate_info_int32 => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_int32) + } + $crate::vmstate::VMStateFieldType::vmstate_info_int64 => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_int64) + } + $crate::vmstate::VMStateFieldType::vmstate_info_uint8 => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint8) + } + $crate::vmstate::VMStateFieldType::vmstate_info_uint16 => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint16) + } + $crate::vmstate::VMStateFieldType::vmstate_info_uint32 => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint32) + } + $crate::vmstate::VMStateFieldType::vmstate_info_uint64 => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint64) + } + $crate::vmstate::VMStateFieldType::vmstate_info_timer => { + ::core::ptr::addr_of!($crate::bindings::vmstate_info_timer) + } + } + } + }; +} + /// A trait for types that can be included in a device's migration stream. It /// provides the base contents of a `VMStateField` (minus the name and offset). /// @@ -69,6 +136,12 @@ const fn phantom__(_: &T) -> ::core::marker::PhantomData { ::core::marker: /// The contents of this trait go straight into structs that are parsed by C /// code and used to introspect into other structs. Be careful. pub unsafe trait VMState { + /// The `info` member of a `VMStateField` is a pointer and as such cannot + /// yet be included in the [`BASE`](VMState::BASE) associated constant; + /// this is only allowed by Rust 1.83.0 and newer. For now, include the + /// member as an enum which is stored in a separate constant. + const SCALAR_TYPE: VMStateFieldType = VMStateFieldType::null; + /// The base contents of a `VMStateField` (minus the name and offset) for /// the type that is implementing the trait. const BASE: VMStateField; @@ -83,6 +156,12 @@ pub unsafe trait VMState { }; } +/// Internal utility function to retrieve a type's `VMStateFieldType`; +/// used by [`vmstate_of!`](crate::vmstate_of). +pub const fn vmstate_scalar_type(_: PhantomData) -> VMStateFieldType { + T::SCALAR_TYPE +} + /// Internal utility function to retrieve a type's `VMStateField`; /// used by [`vmstate_of!`](crate::vmstate_of). pub const fn vmstate_base(_: PhantomData) -> VMStateField { @@ -99,6 +178,15 @@ pub const fn vmstate_varray_flag(_: PhantomData) -> VMStateFlags /// Return the `VMStateField` for a field of a struct. The field must be /// visible in the current scope. /// +/// Only a limited set of types is supported out of the box: +/// * scalar types (integer and `bool`) +/// * the C struct `QEMUTimer` +/// * a transparent wrapper for any of the above (`Cell`, `UnsafeCell`, +/// [`BqlCell`](crate::cell::BqlCell), [`BqlRefCell`](crate::cell::BqlRefCell) +/// * a raw pointer to any of the above +/// * a `NonNull` pointer or a `Box` for any of the above +/// * an array of any of the above +/// /// In order to support other types, the trait `VMState` must be implemented /// for them. #[macro_export] @@ -109,8 +197,14 @@ macro_rules! vmstate_of { .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, offset: $crate::offset_of!($struct_name, $field_name), - // Compute most of the VMStateField from the type of the field. $(.num_offset: $crate::offset_of!($struct_name, $num),)? + // The calls to `call_func_with_field!` are the magic that + // computes most of the VMStateField from the type of the field. + info: $crate::info_enum_to_ref!($crate::call_func_with_field!( + $crate::vmstate::vmstate_scalar_type, + $struct_name, + $field_name + )), ..$crate::call_func_with_field!( $crate::vmstate::vmstate_base, $struct_name, @@ -187,6 +281,7 @@ pub const fn with_varray_multiply(mut self, num: u32) -> VMStateField { macro_rules! impl_vmstate_transparent { ($type:ty where $base:tt: VMState $($where:tt)*) => { unsafe impl<$base> VMState for $type where $base: VMState $($where)* { + const SCALAR_TYPE: VMStateFieldType = <$base as VMState>::SCALAR_TYPE; const BASE: VMStateField = VMStateField { size: mem::size_of::<$type>(), ..<$base as VMState>::BASE @@ -201,6 +296,33 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* { impl_vmstate_transparent!(crate::cell::BqlCell where T: VMState); impl_vmstate_transparent!(crate::cell::BqlRefCell where T: VMState); +// Scalar types using predefined VMStateInfos + +macro_rules! impl_vmstate_scalar { + ($info:ident, $type:ty$(, $varray_flag:ident)?) => { + unsafe impl VMState for $type { + const SCALAR_TYPE: VMStateFieldType = VMStateFieldType::$info; + const BASE: VMStateField = VMStateField { + size: mem::size_of::<$type>(), + flags: VMStateFlags::VMS_SINGLE, + ..Zeroable::ZERO + }; + $(const VARRAY_FLAG: VMStateFlags = VMStateFlags::$varray_flag;)? + } + }; +} + +impl_vmstate_scalar!(vmstate_info_bool, bool); +impl_vmstate_scalar!(vmstate_info_int8, i8); +impl_vmstate_scalar!(vmstate_info_int16, i16); +impl_vmstate_scalar!(vmstate_info_int32, i32); +impl_vmstate_scalar!(vmstate_info_int64, i64); +impl_vmstate_scalar!(vmstate_info_uint8, u8, VMS_VARRAY_UINT8); +impl_vmstate_scalar!(vmstate_info_uint16, u16, VMS_VARRAY_UINT16); +impl_vmstate_scalar!(vmstate_info_uint32, u32, VMS_VARRAY_UINT32); +impl_vmstate_scalar!(vmstate_info_uint64, u64); +impl_vmstate_scalar!(vmstate_info_timer, bindings::QEMUTimer); + // Pointer types using the underlying type's VMState plus VMS_POINTER // Note that references are not supported, though references to cells // could be allowed. @@ -208,6 +330,7 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* { macro_rules! impl_vmstate_pointer { ($type:ty where $base:tt: VMState $($where:tt)*) => { unsafe impl<$base> VMState for $type where $base: VMState $($where)* { + const SCALAR_TYPE: VMStateFieldType = ::SCALAR_TYPE; const BASE: VMStateField = <$base as VMState>::BASE.with_pointer_flag(); } }; @@ -225,6 +348,7 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* { // VMS_ARRAY/VMS_ARRAY_OF_POINTER unsafe impl VMState for [T; N] { + const SCALAR_TYPE: VMStateFieldType = ::SCALAR_TYPE; const BASE: VMStateField = ::BASE.with_array_flag(N); } From patchwork Fri Jan 24 09:44: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: 13949190 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 DDD8BC0218B for ; Fri, 24 Jan 2025 09:50:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHg-0001qZ-FA; Fri, 24 Jan 2025 04:47: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 1tbGGD-0007Yt-DG for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:59 -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 1tbGG6-0003ww-Gw for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711949; 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=qfBGu2d09XoRzvMmTPlk/daGZbhlpGqkbhXjGEOkEVc=; b=ZTXY+tMJdaP/23nyNv96gq4bmIRE2FRlI9L52GxK+i1Gk5LivJys1sF587XnbwIrU81kKA pV1xtmT64bdUISRk65BYKM6m+G1FBpdMuR1DMWMfHZWL8DoQCew8/kSL5fR34WIhdprqTX f8uVHQ3Fz1/TRH+sUpwScX5Ho/xiS4I= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-0ntV0aI1OXKhwWsnGVJcyw-1; Fri, 24 Jan 2025 04:45:47 -0500 X-MC-Unique: 0ntV0aI1OXKhwWsnGVJcyw-1 X-Mimecast-MFC-AGG-ID: 0ntV0aI1OXKhwWsnGVJcyw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43628594d34so10310325e9.2 for ; Fri, 24 Jan 2025 01:45:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711946; x=1738316746; 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=qfBGu2d09XoRzvMmTPlk/daGZbhlpGqkbhXjGEOkEVc=; b=DTj/yGOy2PcKeBRGIPgGMG4nVpv8ajACJuCvydfHfiITZmUvhmiEAzz1LvOIx/4DEM AQkvqCQpMiE0nAuyjoFww9y64qK/YpL8UfdZZNPxLPIoQQLqz3otfY8y8sSiKt58yHhK 5ZFM2zSt8iHJY0cWibcYnFQpK5rUoT2EgLI6zh5X0N7wpPeOTnJTbdidvesM6a04z5de 78A7EDt9NDpzYI/9pKKO+vKirGy25ZWcomb3jbwSX9oVp52+rWAZ+Kcc67TpIuL4pK/9 p4bsMgcdVwn6/gIGb/DCqJnXKyvq7JTwqR+mdhIEw9s260SXPNiE3J/RYkz1YfnZjg1a MMcA== X-Gm-Message-State: AOJu0YxhDLEh43EZJZBPcADegmTp0PWqQ5vOVPvNJXUaS6gpTJGTJiGw J1uG88gnapN4UJbKnYGOtPTZsIMiZcg2dGefoPFAoFi9D2M6cmwD9fHc7yWzjLjL2p+WT9tcUJ+ +TAT6vEAQ+1c0k0cLLIY+gH2fGzqHG6xShTccjD5hZfe8Hop36vAt+drAVZUMTAbE3c3tsNPQI0 Jp/Jy/QQOQvwrDncV7WKBtl/Rl15FmHXO6PVcjxIE= X-Gm-Gg: ASbGncutw20y2hwQpfx0bBXe6iTjBvMZuWK+dlONdgYicv39KOr7uEYLUpw1Y+jZqgC GyRsjOTKVz4tDrEnMf2jyFpcsf241VNRR85/X+IPgk2XHhvteOoeEAxHGzKTiHLFd9KUBdEuSE3 LdsSJ52vVg79Tx21MD5tEAHxgRA84iSKqkvVZGRUKHwXniHl4g66V0sOfspMa2SmbLgqfYxYKzS VZFLy4Yp7Ul15QsMBlQQCQ1CTaE53kGn/ZFCx9rr9hYnvzDihaNdiPu+r+XXsUwDAEcbELGiQ== X-Received: by 2002:a05:600c:1d14:b0:436:46f9:4fc6 with SMTP id 5b1f17b1804b1-438913d63cfmr269424625e9.8.1737711946120; Fri, 24 Jan 2025 01:45:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMBiOIJTcrAxD3PfhXn++d3eB+X2m6jKfcqYMhRShtc6/pp+0QMNXb9L/fS+aThRiSoSY9Kw== X-Received: by 2002:a05:600c:1d14:b0:436:46f9:4fc6 with SMTP id 5b1f17b1804b1-438913d63cfmr269424355e9.8.1737711945645; Fri, 24 Jan 2025 01:45:45 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4c6fadsm20156545e9.32.2025.01.24.01.45.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 30/48] rust: vmstate: add public utility macros to implement VMState Date: Fri, 24 Jan 2025 10:44:24 +0100 Message-ID: <20250124094442.13207-31-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 --- rust/qemu-api/src/vmstate.rs | 61 ++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index a262c315da1..9ac699b73b7 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -4,13 +4,18 @@ //! Helper macros to declare migration state for device models. //! -//! This module includes three families of macros: +//! This module includes four families of macros: //! //! * [`vmstate_unused!`](crate::vmstate_unused) and //! [`vmstate_of!`](crate::vmstate_of), which are used to express the //! migration format for a struct. This is based on the [`VMState`] trait, //! which is defined by all migrateable types. //! +//! * [`impl_vmstate_forward`](crate::impl_vmstate_forward) and +//! [`impl_vmstate_bitsized`](crate::impl_vmstate_bitsized), which help with +//! the definition of the [`VMState`] trait (respectively for transparent +//! structs and for `bilge`-defined types) +//! //! * helper macros to declare a device model state struct, in particular //! [`vmstate_subsections`](crate::vmstate_subsections) and //! [`vmstate_fields`](crate::vmstate_fields). @@ -134,7 +139,9 @@ macro_rules! info_enum_to_ref { /// # Safety /// /// The contents of this trait go straight into structs that are parsed by C -/// code and used to introspect into other structs. Be careful. +/// code and used to introspect into other structs. Generally, you don't need +/// to implement it except via macros that do it for you, such as +/// `impl_vmstate_bitsized!`. pub unsafe trait VMState { /// The `info` member of a `VMStateField` is a pointer and as such cannot /// yet be included in the [`BASE`](VMState::BASE) associated constant; @@ -188,7 +195,9 @@ pub const fn vmstate_varray_flag(_: PhantomData) -> VMStateFlags /// * an array of any of the above /// /// In order to support other types, the trait `VMState` must be implemented -/// for them. +/// for them. The macros +/// [`impl_vmstate_bitsized!`](crate::impl_vmstate_bitsized) +/// and [`impl_vmstate_forward!`](crate::impl_vmstate_forward) help with this. #[macro_export] macro_rules! vmstate_of { ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:expr)?])? $(,)?) => { @@ -276,6 +285,32 @@ pub const fn with_varray_multiply(mut self, num: u32) -> VMStateField { } } +/// This macro can be used (by just passing it a type) to forward the `VMState` +/// trait to the first field of a tuple. This is a workaround for lack of +/// support of nested [`offset_of`](core::mem::offset_of) until Rust 1.82.0. +/// +/// # Examples +/// +/// ``` +/// # use qemu_api::vmstate::impl_vmstate_forward; +/// pub struct Fifo([u8; 16]); +/// impl_vmstate_forward!(Fifo); +/// ``` +#[macro_export] +macro_rules! impl_vmstate_forward { + // This is similar to impl_vmstate_transparent below, but it + // uses the same trick as vmstate_of! to obtain the type of + // the first field of the tuple + ($tuple:ty) => { + unsafe impl $crate::vmstate::VMState for $tuple { + const SCALAR_TYPE: $crate::vmstate::VMStateFieldType = + $crate::call_func_with_field!($crate::vmstate::vmstate_scalar_type, $tuple, 0); + const BASE: $crate::bindings::VMStateField = + $crate::call_func_with_field!($crate::vmstate::vmstate_base, $tuple, 0); + } + }; +} + // Transparent wrappers: just use the internal type macro_rules! impl_vmstate_transparent { @@ -296,6 +331,26 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* { impl_vmstate_transparent!(crate::cell::BqlCell where T: VMState); impl_vmstate_transparent!(crate::cell::BqlRefCell where T: VMState); +#[macro_export] +macro_rules! impl_vmstate_bitsized { + ($type:ty) => { + unsafe impl $crate::vmstate::VMState for $type { + const SCALAR_TYPE: $crate::vmstate::VMStateFieldType = + <<<$type as ::bilge::prelude::Bitsized>::ArbitraryInt + as ::bilge::prelude::Number>::UnderlyingType + as $crate::vmstate::VMState>::SCALAR_TYPE; + const BASE: $crate::bindings::VMStateField = + <<<$type as ::bilge::prelude::Bitsized>::ArbitraryInt + as ::bilge::prelude::Number>::UnderlyingType + as $crate::vmstate::VMState>::BASE; + const VARRAY_FLAG: $crate::bindings::VMStateFlags = + <<<$type as ::bilge::prelude::Bitsized>::ArbitraryInt + as ::bilge::prelude::Number>::UnderlyingType + as $crate::vmstate::VMState>::VARRAY_FLAG; + } + }; +} + // Scalar types using predefined VMStateInfos macro_rules! impl_vmstate_scalar { From patchwork Fri Jan 24 09:44: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: 13949179 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 881B7C0218B for ; Fri, 24 Jan 2025 09:48:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGI3-0004RO-Qb; Fri, 24 Jan 2025 04:47:51 -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 1tbGGH-0007c8-0z for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:01 -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 1tbGGD-0003xF-6S for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:45:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711952; 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=5OmDZaW5YgRWxpigliqJLZJIDncKLDQrlFlqEsLvUnw=; b=cwSvw0YMn7VPzkXSd4tJpMdrD1JBBwOOe0G+kPAIw3/tHQTcwFrAMClnSgHXD1YHw5kEoz feyLOGJaLxNUruQ1VLYG0+R4oBaHkRAYAFZBTAr+AxnY+oIqtclHaEVEbWYBryKq5HlZLH GzoVIsWWP/DeMvu+DVmSA4CWAgLl2E4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-qy4WhyNfOGGhcpfsZW7hyw-1; Fri, 24 Jan 2025 04:45:50 -0500 X-MC-Unique: qy4WhyNfOGGhcpfsZW7hyw-1 X-Mimecast-MFC-AGG-ID: qy4WhyNfOGGhcpfsZW7hyw Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361efc9dc6so10144355e9.3 for ; Fri, 24 Jan 2025 01:45:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711948; x=1738316748; 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=5OmDZaW5YgRWxpigliqJLZJIDncKLDQrlFlqEsLvUnw=; b=dlu60qgbjRlabcO7jYZUf3KdIE/hNUY2fs9YwSxxTIdjB3eQ5TWrQIAwxAjiIIcSi2 VdEuLz3Jo567JzlIDwm3dBdJukX3wkt3enKpQI5nzuigUpcsNL20SFLXFuESul5WzBJq JYFsv0ug+nBjBenM1SeFHZD60flo88ThvQnMezny3RSic89kdhC4FZkHi2QuvpPVks1L qGunzQ/BMsMW/Eggf8+wGYKiWQfcHcw1sWmN5Q2J4Gdpoqzp30mj8GGz1NQNg7vfWWco TmfiR6x6aHQPuRvwrom3tJRlO6J12EhEKF8IyGBQCgE4yqyXvFTBxHJ0bemrpXo8te0U cGiw== X-Gm-Message-State: AOJu0YybccIZk06Ru2qDy52jpCTzEVzJmu+h0GUmvAE4hMOQdKXfbUZ9 D05H0Mtf/aItLJ0UzItjk2auWt6LL7OvBGD7rY5laCzYm75el1zRvLHAfT8WzfA6HgfaN9SbDXs vhzDTyvASPJBSgk/EvRovATRJSJAjg7S8HK+gyquP+w1cQ3p0UeyBODguODoqb8SUU+RuAYvZ5L W6Ke54Wc/xX4e6jySoeU8QhoqGVJCChlhFAPblLTs= X-Gm-Gg: ASbGncvSlYvlOv4uI3AqJ4nprmTS4BFvwnHwIZfyfyiz/vTz5FYsad+Glkibv7c1Gca UvDVO168w/GPAO1BkVlF9wfifBwlazrBKacqDZEy1vXDjJOrwTZVsElq6XfE5xsxjSZ/9vBrqNj 3ggTwvQd5RwrmxRz0x7zzGBCsCOrG0kGP8I9kF9Of8Pi0gQkdXlSdOeZ4U+PdRpPu7wRGkDR+bP BHByK0yEfQTMsDiQnMndcxpyjDeXsnY/dWCfxyNIzjf2sVpYjnIcoDB4UwfNe9stpajYkMDKg== X-Received: by 2002:a05:600c:4f16:b0:434:fdf3:2c26 with SMTP id 5b1f17b1804b1-4389143a124mr244594815e9.19.1737711947954; Fri, 24 Jan 2025 01:45:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxP3PpEnHAngHO79A5JAb+fLAGpww1lRg5RRriQS1o6t36W4/M5vh8NOvJZvClg5doqAIyqA== X-Received: by 2002:a05:600c:4f16:b0:434:fdf3:2c26 with SMTP id 5b1f17b1804b1-4389143a124mr244594505e9.19.1737711947434; Fri, 24 Jan 2025 01:45:47 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd57545dsm20147905e9.40.2025.01.24.01.45.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 31/48] rust: qemu_api: add vmstate_struct Date: Fri, 24 Jan 2025 10:44:25 +0100 Message-ID: <20250124094442.13207-32-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 not type safe, but it's the best that can be done without const_refs_static. It can also be used with BqlCell and BqlRefCell. Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/vmstate.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 9ac699b73b7..d3a9cffdf3f 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -628,6 +628,39 @@ macro_rules! vmstate_array_of_pointer_to_struct { }}; } +// FIXME: including the `vmsd` field in a `const` is not possible without +// the const_refs_static feature (stabilized in Rust 1.83.0). Without it, +// it is not possible to use VMS_STRUCT in a transparent manner using +// `vmstate_of!`. While VMSTATE_CLOCK can at least try to be type-safe, +// VMSTATE_STRUCT includes $type only for documentation purposes; it +// is checked against $field_name and $struct_name, but not against $vmsd +// which is what really would matter. +#[doc(alias = "VMSTATE_STRUCT")] +#[macro_export] +macro_rules! vmstate_struct { + ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:expr)?])?, $vmsd:expr, $type:ty $(,)?) => { + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), "\0") + .as_bytes() + .as_ptr() as *const ::std::os::raw::c_char, + $(.num_offset: $crate::offset_of!($struct_name, $num),)? + offset: { + $crate::assert_field_type!($struct_name, $field_name, $type); + $crate::offset_of!($struct_name, $field_name) + }, + size: ::core::mem::size_of::<$type>(), + flags: $crate::bindings::VMStateFlags::VMS_STRUCT, + vmsd: unsafe { $vmsd }, + ..$crate::zeroable::Zeroable::ZERO $( + .with_varray_flag($crate::call_func_with_field!( + $crate::vmstate::vmstate_varray_flag, + $struct_name, + $num)) + $(.with_varray_multiply($factor))?)? + } + }; +} + #[doc(alias = "VMSTATE_CLOCK_V")] #[macro_export] macro_rules! vmstate_clock_v { From patchwork Fri Jan 24 09:44: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: 13949210 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 C5181C0218B for ; Fri, 24 Jan 2025 09:52:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGIH-0005qn-4b; Fri, 24 Jan 2025 04:48:06 -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 1tbGGH-0007c9-1F for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:01 -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 1tbGGD-0003xN-Hs for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711953; 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=N2oD6fS2wUWrP/tzWspSWPbZz4DpoC2JTpmignvtp7I=; b=VY/11RigmTD4vgzqK13ASpKwY38TMo7e8gBxSdEoeJwskVnNWCDWOFCLMxAZAAPqxzYUru ti+MfreU8xoKwifkzIX8VhFgRfTMU1p4wVEugmucc1COS/ABC+TOSGSEBbjgNx/rtKPwEC Bs84hLV/C+TJWA2cUSze6PH9SJhyhx8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-222-8NOYgB5BPsOYl8YNg2VaNw-1; Fri, 24 Jan 2025 04:45:51 -0500 X-MC-Unique: 8NOYgB5BPsOYl8YNg2VaNw-1 X-Mimecast-MFC-AGG-ID: 8NOYgB5BPsOYl8YNg2VaNw Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361efc9dc6so10144415e9.3 for ; Fri, 24 Jan 2025 01:45:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711949; x=1738316749; 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=N2oD6fS2wUWrP/tzWspSWPbZz4DpoC2JTpmignvtp7I=; b=oCa+aU+Uf3DbexRHdCzYOwlCx4ggSXGPbCdg1akZMsrCLMmSFuKQI/H6qaxiKrMU0q 8+fFqylHiyfvFCojH0qNQgyqWyh3ZcTCZ5Nb5ALhfxEtIuVBBFkl4fEFZXN6KObEHXvU 27QhUU/ab0MUs3dLr2U6/pMOcumhYTTB2hXCIlzBWwFFot55ZsuB101AI5xg6wCYEC14 6yLCArD6J8UMyHFdDMBrpqSJP+t2iuW/6KiNdOkhf4kR1qpDTs2om6YKsDmFBFsEl+ui hBUskjeQXiDQ5R3yxTIwnVzZBUBotK2698BzZMnrdhvBhz/TPmbosGGKM0OU5lEOkLar WI8Q== X-Gm-Message-State: AOJu0Yy3QF8gkOkQOH7BoAM7jWCCScp++DVhv/Hn1tCYxRhZdT9OotCw ZOl8ZmnkX3eGIdbfBI+6ODY1lWi6cHztMClLVRYThPvPRnmvEmOmROk0Y69JEIABoim6mmo6XKP RudJTm8khzTHRDGpOTPkRAJkgKAbngJjYY/JIPoe/ISjtJj4/1f/hOrBq9dXzRH4cVQosj4Jhld 1yQ48YxXj5G8KnyaLVk7/ODpE0vWIcf8PojfJGwMc= X-Gm-Gg: ASbGnct6B5iVGqfzbHRsyCdbdl0ftNq92NbwK7nYE3rFzKDIK8bVGlFD9J9+fO9P/N4 b3aHtplBIEXruYpnCBfXecQIcZK4wOEMbkDMVF6PaxzQt8dV1VLuxqKvfwNEaPfa02OoEaLeh3W auBPSh5QDU0M5kkBafnquwdRj/tQn/p9RAZvWizNnp5dMv1LUo4qhHHsgwFClaLTrfWtov2whFD 5eXvSHce30E/VEw05ZxRK7ZoLtV1bbtqA5tY2swN2dUDjuBB85+wmw0lz+JP7pgNG9mQQwYSg== X-Received: by 2002:a05:600c:1f86:b0:436:aaf:7eb9 with SMTP id 5b1f17b1804b1-43891439d5fmr243279845e9.20.1737711949312; Fri, 24 Jan 2025 01:45:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGV4vSi1Wy0Y7v32Q2fKMYDf1L3K8Ry4dXnvYP1JLOBHmN49SVX/mLbHiu4qbhqsFP8IPSxPA== X-Received: by 2002:a05:600c:1f86:b0:436:aaf:7eb9 with SMTP id 5b1f17b1804b1-43891439d5fmr243279655e9.20.1737711948874; Fri, 24 Jan 2025 01:45:48 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd57545dsm20148715e9.40.2025.01.24.01.45.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:48 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 32/48] rust: pl011: switch vmstate to new-style macros Date: Fri, 24 Jan 2025 10:44:26 +0100 Message-ID: <20250124094442.13207-33-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 --- rust/hw/char/pl011/src/device.rs | 3 ++- rust/hw/char/pl011/src/device_class.rs | 36 +++++++++++++------------- rust/hw/char/pl011/src/lib.rs | 6 +++++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 4f1080ff19f..a1a522fdcdb 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -15,7 +15,7 @@ qemu_irq, sysbus_connect_irq, sysbus_mmio_map, sysbus_realize_and_unref, CharBackend, Chardev, Clock, ClockEvent, MemoryRegion, QEMUChrEvent, CHR_IOCTL_SERIAL_SET_BREAK, }, - c_str, + c_str, impl_vmstate_forward, irq::InterruptSource, prelude::*, qdev::{DeviceImpl, DeviceState, Property}, @@ -61,6 +61,7 @@ impl DeviceId { #[repr(transparent)] #[derive(Debug, Default)] pub struct Fifo([registers::Data; PL011_FIFO_DEPTH as usize]); +impl_vmstate_forward!(Fifo); impl Fifo { const fn len(&self) -> u32 { diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index 7f3ca895071..e0d3532e956 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -6,11 +6,11 @@ use std::os::raw::{c_int, c_void}; use qemu_api::{ - bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_subsections, vmstate_uint32, - vmstate_uint32_array, vmstate_unused, zeroable::Zeroable, + bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_of, vmstate_subsections, + vmstate_unused, zeroable::Zeroable, }; -use crate::device::{PL011State, PL011_FIFO_DEPTH}; +use crate::device::PL011State; extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { unsafe { @@ -52,21 +52,21 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { post_load: Some(pl011_post_load), fields: vmstate_fields! { vmstate_unused!(core::mem::size_of::()), - vmstate_uint32!(flags, PL011State), - vmstate_uint32!(line_control, PL011State), - vmstate_uint32!(receive_status_error_clear, PL011State), - vmstate_uint32!(control, PL011State), - vmstate_uint32!(dmacr, PL011State), - vmstate_uint32!(int_enabled, PL011State), - vmstate_uint32!(int_level, PL011State), - vmstate_uint32_array!(read_fifo, PL011State, PL011_FIFO_DEPTH), - vmstate_uint32!(ilpr, PL011State), - vmstate_uint32!(ibrd, PL011State), - vmstate_uint32!(fbrd, PL011State), - vmstate_uint32!(ifl, PL011State), - vmstate_uint32!(read_pos, PL011State), - vmstate_uint32!(read_count, PL011State), - vmstate_uint32!(read_trigger, PL011State), + vmstate_of!(PL011State, flags), + vmstate_of!(PL011State, line_control), + vmstate_of!(PL011State, receive_status_error_clear), + vmstate_of!(PL011State, control), + vmstate_of!(PL011State, dmacr), + vmstate_of!(PL011State, int_enabled), + vmstate_of!(PL011State, int_level), + vmstate_of!(PL011State, read_fifo), + vmstate_of!(PL011State, ilpr), + vmstate_of!(PL011State, ibrd), + vmstate_of!(PL011State, fbrd), + vmstate_of!(PL011State, ifl), + vmstate_of!(PL011State, read_pos), + vmstate_of!(PL011State, read_count), + vmstate_of!(PL011State, read_trigger), }, subsections: vmstate_subsections! { VMSTATE_PL011_CLOCK diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index 0a89d393e0f..f30f9850ad4 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -106,6 +106,7 @@ pub mod registers { //! Device registers exposed as typed structs which are backed by arbitrary //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. use bilge::prelude::*; + use qemu_api::impl_vmstate_bitsized; /// Receive Status Register / Data Register common error bits /// @@ -172,6 +173,7 @@ pub struct Data { pub errors: Errors, _reserved: u16, } + impl_vmstate_bitsized!(Data); impl Data { // bilge is not very const-friendly, unfortunately @@ -208,6 +210,7 @@ pub struct ReceiveStatusErrorClear { pub errors: Errors, _reserved_unpredictable: u24, } + impl_vmstate_bitsized!(ReceiveStatusErrorClear); impl ReceiveStatusErrorClear { pub fn set_from_data(&mut self, data: Data) { @@ -280,6 +283,7 @@ pub struct Flags { pub ring_indicator: bool, _reserved_zero_no_modify: u23, } + impl_vmstate_bitsized!(Flags); impl Flags { pub fn reset(&mut self) { @@ -354,6 +358,7 @@ pub struct LineControl { /// 31:8 - Reserved, do not modify, read as zero. _reserved_zero_no_modify: u24, } + impl_vmstate_bitsized!(LineControl); impl LineControl { pub fn reset(&mut self) { @@ -498,6 +503,7 @@ pub struct Control { /// 31:16 - Reserved, do not modify, read as zero. _reserved_zero_no_modify2: u16, } + impl_vmstate_bitsized!(Control); impl Control { pub fn reset(&mut self) { From patchwork Fri Jan 24 09:44: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: 13949204 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 E09EDC02181 for ; Fri, 24 Jan 2025 09:52:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGIH-0005q3-4V; Fri, 24 Jan 2025 04:48:06 -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 1tbGGH-0007cP-ME for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46: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 1tbGGE-0003xU-Fs for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711956; 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=cNWd0azXgUd9sSMT4kGbMLXTGKtKYehwsaTDvX4Hyhc=; b=IyruKMr3g2g1OHc8Q/z/VK9iWbdJuZ0ijjB5yzfYqdSdw1XIDhvUh0DVuWKKC71BmWSl9j l1hIDwHYqUAYONgI/OybYhytSKPyUroDUCbEiq2kJfQ7flPu2kz1WJS6FjutODhCCqpEZu NH5lbVzjskag6Dz7K/oHN53dvQRuk4E= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-278-B_XD4nRSOWGQw8ScdCxHGQ-1; Fri, 24 Jan 2025 04:45:54 -0500 X-MC-Unique: B_XD4nRSOWGQw8ScdCxHGQ-1 X-Mimecast-MFC-AGG-ID: B_XD4nRSOWGQw8ScdCxHGQ Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38bf4913659so1541615f8f.1 for ; Fri, 24 Jan 2025 01:45:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711952; x=1738316752; 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=cNWd0azXgUd9sSMT4kGbMLXTGKtKYehwsaTDvX4Hyhc=; b=QZ9M4vin/s/wG+KixS3VEZDBe5IF7NzVFrayq0y0QO2daOsXdL/f0yLRImWwimY/NR kK8L0RrjW5uZmTPqj4RfR+LAxsA53qDbtNS408koo3QHo1zb7ha/zUN3auiZFvYi6l/W +b8W8VsRSXNc40lc991pqyUSVJcSqNub5dIzq7GA3vLoLwEUqOBWrdaNiEZxtRfqiqpY VqMSQNwl/CMqMCHqbIbqD7GQNLOJJtDsJWTbB29CY3u9+8Ik80BV8WhYeN300fD1gnyA h1bsPDDwO/LPgACqbXfHzeB0G53YoOJoCI9/BCxYPic3HXa3nKJIDGn+UWKdSOr5AffE 0f+Q== X-Gm-Message-State: AOJu0YyAA4acY/2iuaxHhY/Y5h4OD+zxG+2US3eDfk4M2wVF3z2Sytan mqJdWKJ72a04tNevdIJiv2XokrpbHwEGbL4TEi1lv4L4OoBnIjnNFnCqtr8z0KQfrRhUZ11hM+8 9E5sQJGlc54EBOUnq1x9YPYZC7LSzQj/lZ/tlftzFP8D84Gu641udG5U+R6mJNauu68iYNV4N07 NkKVXbPSKJpKrsVvcenpL9/PneBqLNifuSGkEh3aY= X-Gm-Gg: ASbGnctb2HiIa3PRmfGGNY27Srqji4qJS2o2d2zvu5PYI0epJ93DUTBGqKTcDrPSNla xiCZmKdYkcpKVYRI9j8uKpQqRU04ZraDpjYHP0kOS2VsIWXkt+GMp4x1yqj8aY+Dr0NgcaKzMNq +C7PHukyvW+ZY5VJIRDSAUsfhbd9bcBKu9DAACDQ6ftxzEvTPWKJducyWmfFFVpj9N9WyZew/qc HuJIgcSgCvIWZHNimJy6DZvLOWJjb4OPk20SwPH42Ue9p0WwIELfzIq0+puZ5OL4mfVqMQaFw== X-Received: by 2002:a5d:64eb:0:b0:385:df4e:3645 with SMTP id ffacd0b85a97d-38bf59ecb69mr29263172f8f.50.1737711952285; Fri, 24 Jan 2025 01:45:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHug1mOEp4gPWlIm6m1dTVjvGq2gbv8pGjETnDCeokDkOefOv1bCruhmO9I4PHzf4Hy1nyZCQ== X-Received: by 2002:a5d:64eb:0:b0:385:df4e:3645 with SMTP id ffacd0b85a97d-38bf59ecb69mr29263126f8f.50.1737711951656; Fri, 24 Jan 2025 01:45:51 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1885besm2138844f8f.49.2025.01.24.01.45.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 33/48] rust: vmstate: remove translation of C vmstate macros Date: Fri, 24 Jan 2025 10:44:27 +0100 Message-ID: <20250124094442.13207-34-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Keep vmstate_clock!; because it uses a field of type VMStateDescription, it cannot be converted to the VMState trait without access to the const_refs_static feature. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/vmstate.rs | 274 +++-------------------------------- 1 file changed, 23 insertions(+), 251 deletions(-) diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index d3a9cffdf3f..120933e60da 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -21,8 +21,8 @@ //! [`vmstate_fields`](crate::vmstate_fields). //! //! * direct equivalents to the C macros declared in -//! `include/migration/vmstate.h`. These are not type-safe and should not be -//! used if the equivalent functionality is available with `vmstate_of!`. +//! `include/migration/vmstate.h`. These are not type-safe and only provide +//! functionality that is missing from `vmstate_of!`. use core::{marker::PhantomData, mem, ptr::NonNull}; @@ -407,223 +407,16 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* { const BASE: VMStateField = ::BASE.with_array_flag(N); } -#[doc(alias = "VMSTATE_UNUSED_BUFFER")] -#[macro_export] -macro_rules! vmstate_unused_buffer { - ($field_exists_fn:expr, $version_id:expr, $size:expr) => {{ - $crate::bindings::VMStateField { - name: c_str!("unused").as_ptr(), - err_hint: ::core::ptr::null(), - offset: 0, - size: $size, - start: 0, - num: 0, - num_offset: 0, - size_offset: 0, - info: unsafe { ::core::ptr::addr_of!($crate::bindings::vmstate_info_unused_buffer) }, - flags: VMStateFlags::VMS_BUFFER, - vmsd: ::core::ptr::null(), - version_id: $version_id, - struct_version_id: 0, - field_exists: $field_exists_fn, - } - }}; -} - -#[doc(alias = "VMSTATE_UNUSED_V")] -#[macro_export] -macro_rules! vmstate_unused_v { - ($version_id:expr, $size:expr) => {{ - $crate::vmstate_unused_buffer!(None, $version_id, $size) - }}; -} - #[doc(alias = "VMSTATE_UNUSED")] #[macro_export] macro_rules! vmstate_unused { ($size:expr) => {{ - $crate::vmstate_unused_v!(0, $size) - }}; -} - -#[doc(alias = "VMSTATE_SINGLE_TEST")] -#[macro_export] -macro_rules! vmstate_single_test { - ($field_name:ident, $struct_name:ty, $field_exists_fn:expr, $version_id:expr, $info:expr, $size:expr) => {{ $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - err_hint: ::core::ptr::null(), - offset: $crate::offset_of!($struct_name, $field_name), + name: $crate::c_str!("unused").as_ptr(), size: $size, - start: 0, - num: 0, - num_offset: 0, - size_offset: 0, - info: unsafe { $info }, - flags: VMStateFlags::VMS_SINGLE, - vmsd: ::core::ptr::null(), - version_id: $version_id, - struct_version_id: 0, - field_exists: $field_exists_fn, - } - }}; -} - -#[doc(alias = "VMSTATE_SINGLE")] -#[macro_export] -macro_rules! vmstate_single { - ($field_name:ident, $struct_name:ty, $version_id:expr, $info:expr, $size:expr) => {{ - $crate::vmstate_single_test!($field_name, $struct_name, None, $version_id, $info, $size) - }}; -} - -#[doc(alias = "VMSTATE_UINT32_V")] -#[macro_export] -macro_rules! vmstate_uint32_v { - ($field_name:ident, $struct_name:ty, $version_id:expr) => {{ - $crate::vmstate_single!( - $field_name, - $struct_name, - $version_id, - ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint32), - ::core::mem::size_of::() - ) - }}; -} - -#[doc(alias = "VMSTATE_UINT32")] -#[macro_export] -macro_rules! vmstate_uint32 { - ($field_name:ident, $struct_name:ty) => {{ - $crate::vmstate_uint32_v!($field_name, $struct_name, 0) - }}; -} - -#[doc(alias = "VMSTATE_ARRAY")] -#[macro_export] -macro_rules! vmstate_array { - ($field_name:ident, $struct_name:ty, $length:expr, $version_id:expr, $info:expr, $size:expr) => {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - err_hint: ::core::ptr::null(), - offset: $crate::offset_of!($struct_name, $field_name), - size: $size, - start: 0, - num: $length as _, - num_offset: 0, - size_offset: 0, - info: unsafe { $info }, - flags: VMStateFlags::VMS_ARRAY, - vmsd: ::core::ptr::null(), - version_id: $version_id, - struct_version_id: 0, - field_exists: None, - } - }}; -} - -#[doc(alias = "VMSTATE_UINT32_ARRAY_V")] -#[macro_export] -macro_rules! vmstate_uint32_array_v { - ($field_name:ident, $struct_name:ty, $length:expr, $version_id:expr) => {{ - $crate::vmstate_array!( - $field_name, - $struct_name, - $length, - $version_id, - ::core::ptr::addr_of!($crate::bindings::vmstate_info_uint32), - ::core::mem::size_of::() - ) - }}; -} - -#[doc(alias = "VMSTATE_UINT32_ARRAY")] -#[macro_export] -macro_rules! vmstate_uint32_array { - ($field_name:ident, $struct_name:ty, $length:expr) => {{ - $crate::vmstate_uint32_array_v!($field_name, $struct_name, $length, 0) - }}; -} - -#[doc(alias = "VMSTATE_STRUCT_POINTER_V")] -#[macro_export] -macro_rules! vmstate_struct_pointer_v { - ($field_name:ident, $struct_name:ty, $version_id:expr, $vmsd:expr, $type:ty) => {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - err_hint: ::core::ptr::null(), - offset: $crate::offset_of!($struct_name, $field_name), - size: ::core::mem::size_of::<*const $type>(), - start: 0, - num: 0, - num_offset: 0, - size_offset: 0, - info: ::core::ptr::null(), - flags: VMStateFlags(VMStateFlags::VMS_STRUCT.0 | VMStateFlags::VMS_POINTER.0), - vmsd: unsafe { $vmsd }, - version_id: $version_id, - struct_version_id: 0, - field_exists: None, - } - }}; -} - -#[doc(alias = "VMSTATE_ARRAY_OF_POINTER")] -#[macro_export] -macro_rules! vmstate_array_of_pointer { - ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr, $info:expr, $type:ty) => {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - version_id: $version_id, - num: $num as _, - info: unsafe { $info }, - size: ::core::mem::size_of::<*const $type>(), - flags: VMStateFlags(VMStateFlags::VMS_ARRAY.0 | VMStateFlags::VMS_ARRAY_OF_POINTER.0), - offset: $crate::offset_of!($struct_name, $field_name), - err_hint: ::core::ptr::null(), - start: 0, - num_offset: 0, - size_offset: 0, - vmsd: ::core::ptr::null(), - struct_version_id: 0, - field_exists: None, - } - }}; -} - -#[doc(alias = "VMSTATE_ARRAY_OF_POINTER_TO_STRUCT")] -#[macro_export] -macro_rules! vmstate_array_of_pointer_to_struct { - ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr, $vmsd:expr, $type:ty) => {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), 0) - .as_bytes() - .as_ptr() as *const ::std::os::raw::c_char, - version_id: $version_id, - num: $num as _, - vmsd: unsafe { $vmsd }, - size: ::core::mem::size_of::<*const $type>(), - flags: VMStateFlags( - VMStateFlags::VMS_ARRAY.0 - | VMStateFlags::VMS_STRUCT.0 - | VMStateFlags::VMS_ARRAY_OF_POINTER.0, - ), - offset: $crate::offset_of!($struct_name, $field_name), - err_hint: ::core::ptr::null(), - start: 0, - num_offset: 0, - size_offset: 0, - vmsd: ::core::ptr::null(), - struct_version_id: 0, - field_exists: None, + info: unsafe { ::core::ptr::addr_of!($crate::bindings::vmstate_info_unused_buffer) }, + flags: $crate::bindings::VMStateFlags::VMS_BUFFER, + ..$crate::zeroable::Zeroable::ZERO } }}; } @@ -661,48 +454,27 @@ macro_rules! vmstate_struct { }; } -#[doc(alias = "VMSTATE_CLOCK_V")] -#[macro_export] -macro_rules! vmstate_clock_v { - ($field_name:ident, $struct_name:ty, $version_id:expr) => {{ - $crate::vmstate_struct_pointer_v!( - $field_name, - $struct_name, - $version_id, - ::core::ptr::addr_of!($crate::bindings::vmstate_clock), - $crate::bindings::Clock - ) - }}; -} - #[doc(alias = "VMSTATE_CLOCK")] #[macro_export] macro_rules! vmstate_clock { ($field_name:ident, $struct_name:ty) => {{ - $crate::vmstate_clock_v!($field_name, $struct_name, 0) - }}; -} - -#[doc(alias = "VMSTATE_ARRAY_CLOCK_V")] -#[macro_export] -macro_rules! vmstate_array_clock_v { - ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr) => {{ - $crate::vmstate_array_of_pointer_to_struct!( - $field_name, - $struct_name, - $num, - $version_id, - ::core::ptr::addr_of!($crate::bindings::vmstate_clock), - $crate::bindings::Clock - ) - }}; -} - -#[doc(alias = "VMSTATE_ARRAY_CLOCK")] -#[macro_export] -macro_rules! vmstate_array_clock { - ($field_name:ident, $struct_name:ty, $num:expr) => {{ - $crate::vmstate_array_clock_v!($field_name, $struct_name, $name, 0) + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name), "\0") + .as_bytes() + .as_ptr() as *const ::std::os::raw::c_char, + offset: { + $crate::assert_field_type!( + $struct_name, + $field_name, + core::ptr::NonNull<$crate::bindings::Clock> + ); + $crate::offset_of!($struct_name, $field_name) + }, + size: ::core::mem::size_of::<*const $crate::bindings::Clock>(), + flags: VMStateFlags(VMStateFlags::VMS_STRUCT.0 | VMStateFlags::VMS_POINTER.0), + vmsd: unsafe { ::core::ptr::addr_of!($crate::bindings::vmstate_clock) }, + ..$crate::zeroable::Zeroable::ZERO + } }}; } From patchwork Fri Jan 24 09:44: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: 13949203 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 7B3A0C02181 for ; Fri, 24 Jan 2025 09:52:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHo-0002se-4L; Fri, 24 Jan 2025 04:47: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 1tbGGH-0007cA-7Z for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46: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 1tbGGE-0003xd-OG for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711957; 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=5RWHadt6elK2BqfQZaH/RGR4cLbXUDpaxbkzpm020/U=; b=gCY5iro4CnPzkFZvOCfqPXbdsBlpisX6DqhpEGaelzXSfBUbyZGWsHwPLDLXEunxDR7ArZ savCTd2nOp4V5QDTGi5totRTL224hICo9kfmpq4I0zSxZki+ybr8MgJ7u8x00NZe22VO95 mtTpHLjTckCTfFFpJayfrMbQN6/9yGo= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-290-F0SLxbSbMweVcSuard8m4Q-1; Fri, 24 Jan 2025 04:45:55 -0500 X-MC-Unique: F0SLxbSbMweVcSuard8m4Q-1 X-Mimecast-MFC-AGG-ID: F0SLxbSbMweVcSuard8m4Q Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-436219070b4so8837975e9.1 for ; Fri, 24 Jan 2025 01:45:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711953; x=1738316753; 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=5RWHadt6elK2BqfQZaH/RGR4cLbXUDpaxbkzpm020/U=; b=h8cBPnVFPo1LT68ovBlg+hpHdRfMpyXUjp2SJHLge/D8DII0eDLh3Dgjzhg4mxMg16 /8RAk7ey3T1SocQKd0oynj6BU/s+d0iKEMW0tUZnSlpixssg+kBbcs2tPoaVc6f9WAlO Vv8bN2J5CUQtfaFGvUQN5hqiBX80UXf0mBWYrfhtL0x5TF8VvoJI1GHb7vCcmN8o+h52 WrWc/RsTIRJ/L0VxrTC8XVKSvnhTySdgL5UOSgpE1+1V3bgh0Ssa14poJssSEpUJa0C+ jwLcOIKOyLPvojuoeplAW118XAkTQrD8+bPCsACiIUy6wbbSYJJ9DlubtQsQj/vSWPL2 CAHw== X-Gm-Message-State: AOJu0YxHmtZc65/jsRWQti/Mp11RMymVq6Bc/DxK+MLu8LCga47ujkCU wIOs7LmT1uOi5kUTDzf/P3Z1tpp5L+UOQ2B81vPpf83rFOJ/i7cJU+Xlbtdoyo1/mtdU/AcZ99m Er4EukXCTWg0vK4rO2yzn7OtzccNe+BU3LzR+vNPGS7MHj4ktqv3AdplpHARy7d53AaVqHYuNTC NobeF2cU1vAymgSl+rUt7KxhROo5OPCxyb94sHF7M= X-Gm-Gg: ASbGnctcTu36xdNKLFmXi98OplZOEzk3pc6MIbwjCf5jXFVPbsLln/hg3qUMPgXLOe+ jZf2Zd0DgE2S6WAMKN0HFdynBcc8eiiFvHPRBh4bPiT8bP1CuFtWOK4JC+HvwA9S2kcuk9LYEnK 6kFSaVVgU9+1KtcRUy5nQP+ZZZ3aOXf8qoNJv0nu1w2RtCYCAPADNlOTGnK8WpZv9/JxjHim2j8 unDZ+LczJfISCBRKASRyTZfVPlQom3nxL6AJ8sWAoerY2RJLlhhPRbCz4lxlRWeMvM0SZx4pw== X-Received: by 2002:a05:600c:3b94:b0:434:e2ea:fc94 with SMTP id 5b1f17b1804b1-438913cb620mr316034275e9.11.1737711953611; Fri, 24 Jan 2025 01:45:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkCDUrEDHQWQECI2bLf/gLV64mRVOJ+56Qdp1dHDW79rtrrH4WPyk3e4X1YxW5XWh0LT+hhQ== X-Received: by 2002:a05:600c:3b94:b0:434:e2ea:fc94 with SMTP id 5b1f17b1804b1-438913cb620mr316033945e9.11.1737711953146; Fri, 24 Jan 2025 01:45:53 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd47f355sm20449095e9.4.2025.01.24.01.45.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:52 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 34/48] rust: vmstate: make order of parameters consistent in vmstate_clock Date: Fri, 24 Jan 2025 10:44:28 +0100 Message-ID: <20250124094442.13207-35-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Place struct_name before field_name, similar to offset_of. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device_class.rs | 2 +- rust/qemu-api/src/vmstate.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index e0d3532e956..b052d98803f 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -27,7 +27,7 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { minimum_version_id: 1, needed: Some(pl011_clock_needed), fields: vmstate_fields! { - vmstate_clock!(clock, PL011State), + vmstate_clock!(PL011State, clock), }, ..Zeroable::ZERO }; diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs index 120933e60da..6ac432cf52f 100644 --- a/rust/qemu-api/src/vmstate.rs +++ b/rust/qemu-api/src/vmstate.rs @@ -457,7 +457,7 @@ macro_rules! vmstate_struct { #[doc(alias = "VMSTATE_CLOCK")] #[macro_export] macro_rules! vmstate_clock { - ($field_name:ident, $struct_name:ty) => {{ + ($struct_name:ty, $field_name:ident) => {{ $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name), "\0") .as_bytes() From patchwork Fri Jan 24 09:44:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949180 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 D7880C02181 for ; Fri, 24 Jan 2025 09:48:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHX-0001IT-T7; Fri, 24 Jan 2025 04:47:20 -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 1tbGGI-0007dW-Nj for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:04 -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 1tbGGG-0003xu-LV for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711959; 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=GX5ZXSWUGkXS8f5Sw6QjzbC9hARnbnbxThpUdHGomPY=; b=HOf5tA2aWbrLnhzHrCTJR5b/EsUFHzT+JoOnVOTNSirTuhUivw7LB5asCPRTK1wRsYNWmh kS55pBKrQNL0OVljz9puRb+im1oMLyoAA4SBC9sLykqdN7y1b6U5v5P/StsIyr0sGbhPuK X5Xz8feG0gigDDdW1T3kjz8DDecWG8Q= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-68-RgrdhWqbOlagfosL1Ofv4g-1; Fri, 24 Jan 2025 04:45:57 -0500 X-MC-Unique: RgrdhWqbOlagfosL1Ofv4g-1 X-Mimecast-MFC-AGG-ID: RgrdhWqbOlagfosL1Ofv4g Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4359eb032c9so13289975e9.2 for ; Fri, 24 Jan 2025 01:45:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711955; x=1738316755; 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=GX5ZXSWUGkXS8f5Sw6QjzbC9hARnbnbxThpUdHGomPY=; b=EqwjQsZTMlQIBQYWg/jbwovx4l3/Et7MLIzFoD9IJOZI57k88EAko2i3amMaTrmpK/ fQSD/pEgDB49GaII7p3z5bSBYzRQWWpVB3uMTJSI3BI0rwgOfAsZRaVhJfK1bbcedj2M ouFAYUY5PIzOMrWGxRic93v+qZ+JQhuHIoWxfwKtFn/bJE/QCijL3JhidrUsbVeVgx84 AaRSOa/0J+zhN69ck857bpWVyiJ6XKJ5Qp9uwDbJmJ3khnOr/Wf9Me355DmeGSePY5K+ Z2vTgG2NMruXVEVETLkd8YPzLZOifSqQVSxFeu/zpg2hCs8hcuWwaxOVB5odVow8y8TX FjXg== X-Gm-Message-State: AOJu0YwYVsaswOxK+H+Bz360i7pRoy7HqIkvT3IDbsyILvPvyBQWTnlq +edM3DMwq76SCmipFhZIi1zm4OTJ5JjVlvj1v1PNtuOqv5PCaGAkxw20VlbusF11ifDMdkvVvRF ItXyTjJBvMv/dZb4Em1RNAeqH45CkoRN7UPy8HVuvlhqu400ig8YnJsA4GtZyTrmQWEaQ7i3vmw 6uNuPQBlpfhycyMg0gSU4et9oQKulgd1wrHVWikrU= X-Gm-Gg: ASbGncv2GhiIi8tBr6FwpBp2xTa4tWWZ1Rxo/9YZDCY6nTjRSoB6PIWbHDIJZH8Sd6+ sIoI+bKpx7AeC3OQiLOW/C7zlU6FsFWmJWdyjTA4V7BQOpIB0ozvR99PrJH7zxBlL4sLdpQ7vI2 LGj2Ed1SG1Elyvjik8lPmMVHAOekbEOAJtg8iaH8hhAnKNSY8FtoEaxgpKfKdgXopcZAaXxDije +4tzTbg3Ggtgo8oVocHU7b3kBTJ0767PTKQZ8opZpe8mlKqdKnT1NXH6MdteH8dLUllUWMz3Q== X-Received: by 2002:a7b:c3d8:0:b0:436:17e4:ad4c with SMTP id 5b1f17b1804b1-438a0d3c71fmr208517655e9.6.1737711955383; Fri, 24 Jan 2025 01:45:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFR9jW+ROCeL72qO2reeDCROKBMuAF3wWj+2qVaXLi7wNINfmAQHvdTWDrQXp4CNcpJCHUt3Q== X-Received: by 2002:a7b:c3d8:0:b0:436:17e4:ad4c with SMTP id 5b1f17b1804b1-438a0d3c71fmr208517355e9.6.1737711954807; Fri, 24 Jan 2025 01:45:54 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4fa46esm20470025e9.1.2025.01.24.01.45.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:53 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 35/48] rust: prefer NonNull::new to assertions Date: Fri, 24 Jan 2025 10:44:29 +0100 Message-ID: <20250124094442.13207-36-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Do not use new_unchecked; the effect is the same, but the code is easier to read and unsafe regions become smaller. Likewise, NonNull::new can be used instead of assertion and followed by as_ref() or as_mut() instead of dereferencing the pointer. Suggested-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 17 +++++------------ rust/hw/char/pl011/src/device_class.rs | 23 +++++++++-------------- rust/hw/char/pl011/src/memory_ops.rs | 9 +++------ rust/qemu-api/src/qdev.rs | 12 +++++------- rust/qemu-api/src/qom.rs | 21 +++++++++++++-------- 5 files changed, 35 insertions(+), 47 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index a1a522fdcdb..c0b53f2515c 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -593,11 +593,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. pub unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int { - unsafe { - debug_assert!(!opaque.is_null()); - let state = NonNull::new_unchecked(opaque.cast::()); - state.as_ref().can_receive().into() - } + let state = NonNull::new(opaque).unwrap().cast::(); + unsafe { state.as_ref().can_receive().into() } } /// # Safety @@ -608,9 +605,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { /// /// The buffer and size arguments must also be valid. pub unsafe extern "C" fn pl011_receive(opaque: *mut c_void, buf: *const u8, size: c_int) { + let mut state = NonNull::new(opaque).unwrap().cast::(); unsafe { - debug_assert!(!opaque.is_null()); - let mut state = NonNull::new_unchecked(opaque.cast::()); if state.as_ref().loopback_enabled() { return; } @@ -627,11 +623,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. pub unsafe extern "C" fn pl011_event(opaque: *mut c_void, event: QEMUChrEvent) { - unsafe { - debug_assert!(!opaque.is_null()); - let mut state = NonNull::new_unchecked(opaque.cast::()); - state.as_mut().event(event) - } + let mut state = NonNull::new(opaque).unwrap().cast::(); + unsafe { state.as_mut().event(event) } } /// # Safety diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index b052d98803f..6fa14ca0f9b 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -12,12 +12,10 @@ use crate::device::PL011State; +#[allow(clippy::missing_const_for_fn)] extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { - unsafe { - debug_assert!(!opaque.is_null()); - let state = NonNull::new_unchecked(opaque.cast::()); - state.as_ref().migrate_clock - } + let state = NonNull::new(opaque).unwrap().cast::(); + unsafe { state.as_ref().migrate_clock } } /// Migration subsection for [`PL011State`] clock. @@ -33,15 +31,12 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { }; extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { - unsafe { - debug_assert!(!opaque.is_null()); - let mut state = NonNull::new_unchecked(opaque.cast::()); - let result = state.as_mut().post_load(version_id as u32); - if result.is_err() { - -1 - } else { - 0 - } + let mut state = NonNull::new(opaque).unwrap().cast::(); + let result = unsafe { state.as_mut().post_load(version_id as u32) }; + if result.is_err() { + -1 + } else { + 0 } } diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index c4e8599ba43..a286003d136 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -25,7 +25,7 @@ unsafe extern "C" fn pl011_read(opaque: *mut c_void, addr: hwaddr, size: c_uint) -> u64 { assert!(!opaque.is_null()); - let mut state = unsafe { NonNull::new_unchecked(opaque.cast::()) }; + let mut state = NonNull::new(opaque).unwrap().cast::(); let val = unsafe { state.as_mut().read(addr, size) }; match val { std::ops::ControlFlow::Break(val) => val, @@ -43,9 +43,6 @@ } unsafe extern "C" fn pl011_write(opaque: *mut c_void, addr: hwaddr, data: u64, _size: c_uint) { - unsafe { - assert!(!opaque.is_null()); - let mut state = NonNull::new_unchecked(opaque.cast::()); - state.as_mut().write(addr, data) - } + let mut state = NonNull::new(opaque).unwrap().cast::(); + unsafe { state.as_mut().write(addr, data) } } diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs index a5121e31a37..42429903aae 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/qemu-api/src/qdev.rs @@ -4,7 +4,7 @@ //! Bindings to create devices and access device functionality from Rust. -use std::ffi::CStr; +use std::{ffi::CStr, ptr::NonNull}; pub use bindings::{DeviceClass, DeviceState, Property}; @@ -55,9 +55,8 @@ fn vmsd() -> Option<&'static VMStateDescription> { /// can be downcasted to type `T`. We also expect the device is /// readable/writeable from one thread at any time. unsafe extern "C" fn rust_realize_fn(dev: *mut DeviceState, _errp: *mut *mut Error) { - assert!(!dev.is_null()); - let state = dev.cast::(); - T::REALIZE.unwrap()(unsafe { &mut *state }); + let state = NonNull::new(dev).unwrap().cast::(); + T::REALIZE.unwrap()(unsafe { state.as_ref() }); } /// # Safety @@ -66,9 +65,8 @@ fn vmsd() -> Option<&'static VMStateDescription> { /// can be downcasted to type `T`. We also expect the device is /// readable/writeable from one thread at any time. unsafe extern "C" fn rust_reset_fn(dev: *mut DeviceState) { - assert!(!dev.is_null()); - let state = dev.cast::(); - T::RESET.unwrap()(unsafe { &mut *state }); + let mut state = NonNull::new(dev).unwrap().cast::(); + T::RESET.unwrap()(unsafe { state.as_mut() }); } impl ClassInitImpl for T diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs index 97901fb9084..f50ee371aac 100644 --- a/rust/qemu-api/src/qom.rs +++ b/rust/qemu-api/src/qom.rs @@ -58,6 +58,7 @@ fmt, ops::{Deref, DerefMut}, os::raw::c_void, + ptr::NonNull, }; pub use bindings::{Object, ObjectClass}; @@ -153,27 +154,34 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { } unsafe extern "C" fn rust_instance_init(obj: *mut Object) { + let mut state = NonNull::new(obj).unwrap().cast::(); // SAFETY: obj is an instance of T, since rust_instance_init // is called from QOM core as the instance_init function // for class T - unsafe { T::INSTANCE_INIT.unwrap()(&mut *obj.cast::()) } + unsafe { + T::INSTANCE_INIT.unwrap()(state.as_mut()); + } } unsafe extern "C" fn rust_instance_post_init(obj: *mut Object) { + let state = NonNull::new(obj).unwrap().cast::(); // SAFETY: obj is an instance of T, since rust_instance_post_init // is called from QOM core as the instance_post_init function // for class T - T::INSTANCE_POST_INIT.unwrap()(unsafe { &*obj.cast::() }) + T::INSTANCE_POST_INIT.unwrap()(unsafe { state.as_ref() }); } unsafe extern "C" fn rust_class_init>( klass: *mut ObjectClass, _data: *mut c_void, ) { + let mut klass = NonNull::new(klass) + .unwrap() + .cast::<::Class>(); // 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 { &mut *klass.cast::() }) + T::class_init(unsafe { klass.as_mut() }) } unsafe extern "C" fn drop_object(obj: *mut Object) { @@ -581,11 +589,8 @@ pub trait ClassInitImpl { /// can be downcasted to type `T`. We also expect the device is /// readable/writeable from one thread at any time. unsafe extern "C" fn rust_unparent_fn(dev: *mut Object) { - unsafe { - assert!(!dev.is_null()); - let state = core::ptr::NonNull::new_unchecked(dev.cast::()); - T::UNPARENT.unwrap()(state.as_ref()); - } + let state = NonNull::new(dev).unwrap().cast::(); + T::UNPARENT.unwrap()(unsafe { state.as_ref() }); } impl ClassInitImpl for T From patchwork Fri Jan 24 09:44: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: 13949193 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 02748C0218C for ; Fri, 24 Jan 2025 09:50:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHg-0001tu-Fg; Fri, 24 Jan 2025 04:47: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 1tbGGJ-0007do-9h for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:04 -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 1tbGGH-0003y5-FB for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711960; 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=v046WHBDzXsfnIdlJ2KYuzlpoyQwX0KFTxjaaOlycxU=; b=UKgBrsAazOrxtoNe3PKE4C/5wEDiUwN/nPQiZOR2JiL/emk80dA1z3muiO9Xv+EusV4qdm bUyC4CqJZtpH9INmQzCMDwr++JvsCwmKUXX+9hflaGAkX1ZbvudkdREYoSkNhcFh28ieuD CCIlmbs7DDhiRmwDcjOeo3sfkwL/8rw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-ar6S6ekEPU-rw_ZBgnXUAQ-1; Fri, 24 Jan 2025 04:45:58 -0500 X-MC-Unique: ar6S6ekEPU-rw_ZBgnXUAQ-1 X-Mimecast-MFC-AGG-ID: ar6S6ekEPU-rw_ZBgnXUAQ Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-38a873178f2so1041969f8f.1 for ; Fri, 24 Jan 2025 01:45:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711957; x=1738316757; 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=v046WHBDzXsfnIdlJ2KYuzlpoyQwX0KFTxjaaOlycxU=; b=J+4+SyHHOUFg49P6RnZycuTDIO1joOTbk9ArrZO6D6SbCMzRQteUwCtgctCR+/yD0+ x9HH7LcOqOkfWGwLBjaE5SUUr+aYAp6IwFTeaY2z8XrAltBQ2WACEIYmkdEuwcTxDdr7 /H6CK+5Sc2ewPS+iLBJ3pWFIqKF8ZHl58BKw1N20wGhqtzqflztbWeDout5IbaYClI/x tSttdP8/9B3+6TpyLLSqw0Jcq+1+9l6g4Jta5PFkQqyqdlxAy86dJ5YcKfh2XXQz0ZiN cH0aUTD17FuHB/9+RUPWqdG/cxN3SfebvsM8reQmjukyR1lrKag1/vlifV/CLw3DLG2p jJCA== X-Gm-Message-State: AOJu0YyQOM3oUemAxxPNMuerdmpF4f8OQGV7YdFzU+wiixlhH47Go6Xe D4r+R6YQ62QwdnPLbjHr68e7oxL0Kzd8dq7m7X9LQa330wJ92nyORft7wLMLt1SxmEwATo36FUa sCtNhnmsUAELW2YrxTDSU+FuX0auwvp6cuuXU9edQJvBj3SqLtGhmuM6q9IcseACfWbp8fzB18t mDxHPGg/a1uXIekDckj6Jze4UAyFajKwHu17ILaKc= X-Gm-Gg: ASbGncuOQm19XbGideBHFaHhGxL3wv259fQp0HKguQAzZ8A3VkIhqlgyTMsxD9FtEMv b2uYoTS3/uZAlGLqZ6jKaHmvqMj8TmbPquVCiQxGSYin4wmVx18awM32fBzpfmD15Bpm/pOI3de UXZvZFEV/Qgu1W6gPcVd5z2CfYOKeYoffs7mebZfcV2ZWR4oSxCcRxcVVFwGmoVByaqi+KwswL1 ZVg3bPeSVgOg1FnHqSeHDfKgs15rpM7KboN18VYmmuknNBsM0wJSWIcJAx8Ur3YIPRA+HO/Lw== X-Received: by 2002:adf:f682:0:b0:38b:e26d:ea0b with SMTP id ffacd0b85a97d-38bf566c314mr23371388f8f.25.1737711957189; Fri, 24 Jan 2025 01:45:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9aq052Xl/vYca/Bt3phpmiYj9f1dU6/LBU0CGe0yDhe+8K1AAYsDCMBwZXbuSUtf/GeDCMg== X-Received: by 2002:adf:f682:0:b0:38b:e26d:ea0b with SMTP id ffacd0b85a97d-38bf566c314mr23371365f8f.25.1737711956840; Fri, 24 Jan 2025 01:45:56 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4d2c0esm20268945e9.33.2025.01.24.01.45.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:56 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 36/48] rust: pl011: remove unnecessary "extern crate" Date: Fri, 24 Jan 2025 10:44:30 +0100 Message-ID: <20250124094442.13207-37-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 --- rust/hw/char/pl011/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index f30f9850ad4..d10f0805aac 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -25,10 +25,6 @@ #![allow(clippy::upper_case_acronyms)] #![allow(clippy::result_unit_err)] -extern crate bilge; -extern crate bilge_impl; -extern crate qemu_api; - use qemu_api::c_str; pub mod device; From patchwork Fri Jan 24 09:44: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: 13949186 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 E3373C02181 for ; Fri, 24 Jan 2025 09:49:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHr-0003El-Mb; Fri, 24 Jan 2025 04:47:39 -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 1tbGGN-0007op-SM for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:16 -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 1tbGGL-0003yu-Rw for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711964; 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=XbTiAxgh79DT2i5TJ+IcQefSJjUXpkJJ3v15Ommm2hM=; b=IAOEHrMpk7xO3d3NkH0ka0yGr6TiBL3gVkbekiZheMShhMng6+Fg04zo80Z0BHUD7NgDdl qb5K2IkVQrPgrC9yJ6wnBpQyx9hQQn3N+luGLfD1ffSPNXt5dRlhriVZOtdWcJsWuX3ukL Msq6/TwqETyJFb1xB/wfBjP+V4RGdv0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325-wWLBKtYFNjaoo4QwOGO7pQ-1; Fri, 24 Jan 2025 04:46:01 -0500 X-MC-Unique: wWLBKtYFNjaoo4QwOGO7pQ-1 X-Mimecast-MFC-AGG-ID: wWLBKtYFNjaoo4QwOGO7pQ Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4361c040ba8so10346295e9.1 for ; Fri, 24 Jan 2025 01:46:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711959; x=1738316759; 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=XbTiAxgh79DT2i5TJ+IcQefSJjUXpkJJ3v15Ommm2hM=; b=wKxqOLxYVy3lClIwaQhjJiNe6u6bUpeLid3vGQhbnvUDDvP71yClMzTRQWDH5Gw+S6 ngW0hxiU9OFmGqPyKVSevQBxDUrIbtpiDxIWCMxgCZ+eZKLqLBDVhyW+r85rRfNk5Xke j4HJwYwNw3MaHX0Vv3qg4HvHybg8JFIY7I7FHEleBX7LPTvY7tBm+I7B30kLGikiekCk aMYiszlYkjBepKo6/INatn1pqT0+H3Vb1j4wPHq67NZ/cVsSo8DeRyVGpJ2FCd4fjBN3 f9cXpO40AW6/W5GatiEI00drcn0sImkh20lQruYX1GNVRJ+8oSMOxhv+AGxv5+BsErE/ k/UQ== X-Gm-Message-State: AOJu0Yw0ZBhbgfz4Pj4xgKbcSTtp/KOOgcNBmWbGFvIhTeqo6xFTslZm QwQfkRY7ubKggL1DIko6oXJmOrFMw92SYEZSwJxbEkL0RarwpGw3J2Zj469C2FekULKEQT2/eVp 2vW+4SOVimEPFbZmaOA7/xFe12h6FPd8z8gu7+xN2LP99d2cqpbx0su46NRPubc5eOVl+ITrag2 mwISj0qLqEoyU7sOXb2ajUiSKGwMNtpUpvQQUkyw4= X-Gm-Gg: ASbGnctrTyA3+oYLpUPzmPjZVtSgLuiImOcSXS2WknQYJo5vVzJz8GJepuj9h0oThbu 1ZljbYLYG57xUYpX9aIuU3jWt//fAI1AjiDrLLE5Wkc/spMxaVDPaj/F+Xv8gApc0HH7vHWEyBK DuPUZ3+Wo4p24totqB4rhhMvul0BaSzdsFPSvsysFW0NfTwi041co67SP7xQ9Y2oOwpuO1TFgrX YwEogeUq4LMtvOipgx+7ME7R76sF6oIbucPN+bHWnrpi8j32W4rGHWHgDmUv2W2oK5bHQQWIQ== X-Received: by 2002:a05:600c:348c:b0:434:f1d5:1453 with SMTP id 5b1f17b1804b1-438912dbfedmr301689695e9.0.1737711958891; Fri, 24 Jan 2025 01:45:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcKxLRNPH6+Vb+/kuM5n2ydl7ljcmwAtFnlrV/Mkt0GOVQfsfWpizmqsmwqwNmCiEoJg7jKQ== X-Received: by 2002:a05:600c:348c:b0:434:f1d5:1453 with SMTP id 5b1f17b1804b1-438912dbfedmr301689345e9.0.1737711958388; Fri, 24 Jan 2025 01:45:58 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd47f0fdsm20856125e9.5.2025.01.24.01.45.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:57 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 37/48] rust: pl011: hide unnecessarily "pub" items from outside pl011::device Date: Fri, 24 Jan 2025 10:44:31 +0100 Message-ID: <20250124094442.13207-38-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 The only public interfaces for pl011 are TYPE_PL011 and pl011_create. Remove pub from everything else. Note: the "allow(dead_code)" is removed later. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 2 +- rust/hw/char/pl011/src/device_class.rs | 2 +- rust/hw/char/pl011/src/lib.rs | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index c0b53f2515c..c8496eeb1b6 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -573,7 +573,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { } /// Which bits in the interrupt status matter for each outbound IRQ line ? -pub const IRQMASK: [u32; 6] = [ +const IRQMASK: [u32; 6] = [ /* combined IRQ */ Interrupt::E | Interrupt::MS diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index 6fa14ca0f9b..2336a768729 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -19,7 +19,7 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { } /// Migration subsection for [`PL011State`] clock. -pub static VMSTATE_PL011_CLOCK: VMStateDescription = VMStateDescription { +static VMSTATE_PL011_CLOCK: VMStateDescription = VMStateDescription { name: c_str!("pl011/clock").as_ptr(), version_id: 1, minimum_version_id: 1, diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index d10f0805aac..2baacba2306 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -27,9 +27,11 @@ use qemu_api::c_str; -pub mod device; -pub mod device_class; -pub mod memory_ops; +mod device; +mod device_class; +mod memory_ops; + +pub use device::pl011_create; pub const TYPE_PL011: &::std::ffi::CStr = c_str!("pl011"); pub const TYPE_PL011_LUMINARY: &::std::ffi::CStr = c_str!("pl011_luminary"); @@ -42,7 +44,7 @@ #[allow(non_camel_case_types)] #[repr(u64)] #[derive(Debug, qemu_api_macros::TryInto)] -pub enum RegisterOffset { +enum RegisterOffset { /// Data Register /// /// A write to this register initiates the actual data transmission @@ -98,7 +100,8 @@ pub enum RegisterOffset { //Reserved = 0x04C, } -pub mod registers { +#[allow(dead_code)] +mod registers { //! Device registers exposed as typed structs which are backed by arbitrary //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. use bilge::prelude::*; From patchwork Fri Jan 24 09:44:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13949181 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 1F55AC02181 for ; Fri, 24 Jan 2025 09:48:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGI1-0004FZ-N7; Fri, 24 Jan 2025 04:47: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 1tbGGM-0007oY-LW for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:16 -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 1tbGGK-0003yq-R9 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711964; 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=JUZvvlaNtJrFbkkw9/p5GgCt5QVuzk/+d4qUzLuDLw4=; b=UzHJkwwELn4OGZc55oV39Nh4EmK7aT0dosPrqNSHYcLz/5+Zuz3hubaRmHtfEFXhLGyV3H XuS/LGlcm9YzrNPgIt5ABs9gJnBnyernjBlRnWW/2op3r+wkWdfRrK604yxd++aRHlTU1A 0XgRm9avu/cuRmyT51M55dBRaH4+bOc= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-130-_8Y9NHMiO4aNOYACdnAS1w-1; Fri, 24 Jan 2025 04:46:02 -0500 X-MC-Unique: _8Y9NHMiO4aNOYACdnAS1w-1 X-Mimecast-MFC-AGG-ID: _8Y9NHMiO4aNOYACdnAS1w Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43623bf2a83so15109445e9.0 for ; Fri, 24 Jan 2025 01:46:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711960; x=1738316760; 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=JUZvvlaNtJrFbkkw9/p5GgCt5QVuzk/+d4qUzLuDLw4=; b=oJSNNgRQ07x9/2UjWrFIVF+cNoCXz7RIlplkv7HBvoinmFwVbR0AluJ/vvFUnSWLzF iBuaVg7Mi+VNdudmMxgni4K53jUia/rw2Pedm5kXzYUZ5DoCrKjzSgBbo75huw9+fSmb oloBWeBHHarOOAOLjTs3uchnf6jhfjRbM27GrfBwaDsZpEzQrO+rnX4KchuwTr0HoM/l MtqwcD/nUA/oirvGt3fNnE5l7Hj/X63uz8IMfSNkzBtGFBtVjmZQDfMQznmeNDNZZibM 3K+ypMLo8HJHM8g8vVpjliPbzpl5Q4gsPpk2hp36EiF//HJQGe9wErw/zbdWpn/jJnmI RyKg== X-Gm-Message-State: AOJu0YwM5WpO2S+lVsLUAJePIeS6B9utRhBWSwblyLMgbMuKmYkbaOQe pwuZmefevP3C+xvhdjolVUDPn/Cln6xqVyCNnHLkP5M5VBu/oedQrVOfMVYwa1IdUULAaKmhY14 AMagUqR2QHXHClUCWOgYte2ck7TYY6obu2DsXNURLlDZULfIgi5Dp7CXKjfeH5v1BcwkY8GexzO O41EXdAu2JJ3XvanKpVaTNNrDCmnVd4ykhf1Mfm9Y= X-Gm-Gg: ASbGncsMKcOBLZG4KO75TmEUxriQNVLhAPI0mANjOJD6IyGP2pW376KzfA+YpdBuI7A If+uNzCblxUGjevhnT3ApAV5b8XGRkqYFmOB7o4U/Fw4tZ3G02sE/Gzi6rQoNbhB0AhzDy1Pa3Z MpHDK/waJQ4TOIGgl1gstMyQZSMcLdxH48/HLIaXzNJvrZu2o+29goqkZhH2pvTNYm5kQQPUirH /rtTzzga+1PFblZqSnFMfrBL/nfI2Lm/F9IcN0RGoKc0o2SJGIm0bZoMGWqnpRco1et5FEajQ== X-Received: by 2002:a05:600c:3149:b0:434:e9ee:c2d with SMTP id 5b1f17b1804b1-4389144eee4mr237345025e9.26.1737711960531; Fri, 24 Jan 2025 01:46:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZnPxOwuDAnNeXdA6db/f2nQUiOSJpjQN0GrFdk1loiEVEI5x4VUgQRg5UVkn2XGIQFiisRQ== X-Received: by 2002:a05:600c:3149:b0:434:e9ee:c2d with SMTP id 5b1f17b1804b1-4389144eee4mr237344715e9.26.1737711960051; Fri, 24 Jan 2025 01:46:00 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd48ae56sm20569435e9.21.2025.01.24.01.45.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:45:59 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 38/48] rust: pl011: extract conversion to RegisterOffset Date: Fri, 24 Jan 2025 10:44:32 +0100 Message-ID: <20250124094442.13207-39-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 an added bonus, this also makes the new function return u32 instead of u64, thus factoring some casts into a single place. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 113 +++++++++++++++++-------------- 1 file changed, 64 insertions(+), 49 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index c8496eeb1b6..58b54547336 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -5,6 +5,7 @@ use core::ptr::{addr_of, addr_of_mut, NonNull}; use std::{ ffi::CStr, + ops::ControlFlow, os::raw::{c_int, c_uint, c_void}, }; @@ -222,19 +223,11 @@ fn post_init(&self) { } } - pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::ControlFlow { + fn regs_read(&mut self, offset: RegisterOffset) -> ControlFlow { use RegisterOffset::*; - let value = match RegisterOffset::try_from(offset) { - Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => { - let device_id = self.get_class().device_id; - u32::from(device_id[(offset - 0xfe0) >> 2]) - } - Err(_) => { - // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); - 0 - } - Ok(DR) => { + ControlFlow::Break(match offset { + DR => { self.flags.set_receive_fifo_full(false); let c = self.read_fifo[self.read_pos]; if self.read_count > 0 { @@ -251,39 +244,33 @@ pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::ControlFlow u32::from(self.receive_status_error_clear), - Ok(FR) => u32::from(self.flags), - Ok(FBRD) => self.fbrd, - Ok(ILPR) => self.ilpr, - Ok(IBRD) => self.ibrd, - Ok(LCR_H) => u32::from(self.line_control), - Ok(CR) => u32::from(self.control), - Ok(FLS) => self.ifl, - Ok(IMSC) => self.int_enabled, - Ok(RIS) => self.int_level, - Ok(MIS) => self.int_level & self.int_enabled, - Ok(ICR) => { + RSR => u32::from(self.receive_status_error_clear), + FR => u32::from(self.flags), + FBRD => self.fbrd, + ILPR => self.ilpr, + IBRD => self.ibrd, + LCR_H => u32::from(self.line_control), + CR => u32::from(self.control), + FLS => self.ifl, + IMSC => self.int_enabled, + RIS => self.int_level, + MIS => self.int_level & self.int_enabled, + ICR => { // "The UARTICR Register is the interrupt clear register and is write-only" // Source: ARM DDI 0183G 3.3.13 Interrupt Clear Register, UARTICR 0 } - Ok(DMACR) => self.dmacr, - }; - std::ops::ControlFlow::Break(value.into()) + DMACR => self.dmacr, + }) } - pub fn write(&mut self, offset: hwaddr, value: u64) { + fn regs_write(&mut self, offset: RegisterOffset, value: u32) { // eprintln!("write offset {offset} value {value}"); use RegisterOffset::*; - let value: u32 = value as u32; - match RegisterOffset::try_from(offset) { - Err(_bad_offset) => { - eprintln!("write bad offset {offset} value {value}"); - } - Ok(DR) => { + match offset { + DR => { // ??? Check if transmitter is enabled. let ch: u8 = value as u8; // XXX this blocks entire thread. Rewrite to use @@ -298,22 +285,22 @@ pub fn write(&mut self, offset: hwaddr, value: u64) { self.int_level |= registers::INT_TX; self.update(); } - Ok(RSR) => { - self.receive_status_error_clear.reset(); + RSR => { + self.receive_status_error_clear = 0.into(); } - Ok(FR) => { + FR => { // flag writes are ignored } - Ok(ILPR) => { + ILPR => { self.ilpr = value; } - Ok(IBRD) => { + IBRD => { self.ibrd = value; } - Ok(FBRD) => { + FBRD => { self.fbrd = value; } - Ok(LCR_H) => { + LCR_H => { let new_val: registers::LineControl = value.into(); // Reset the FIFO state on FIFO enable or disable if self.line_control.fifos_enabled() != new_val.fifos_enabled() { @@ -336,26 +323,26 @@ pub fn write(&mut self, offset: hwaddr, value: u64) { self.line_control = new_val; self.set_read_trigger(); } - Ok(CR) => { + CR => { // ??? Need to implement the enable bit. self.control = value.into(); self.loopback_mdmctrl(); } - Ok(FLS) => { + FLS => { self.ifl = value; self.set_read_trigger(); } - Ok(IMSC) => { + IMSC => { self.int_enabled = value; self.update(); } - Ok(RIS) => {} - Ok(MIS) => {} - Ok(ICR) => { + RIS => {} + MIS => {} + ICR => { self.int_level &= !value; self.update(); } - Ok(DMACR) => { + DMACR => { self.dmacr = value; if value & 3 > 0 { // qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemented\n"); @@ -570,6 +557,34 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { Ok(()) } + + pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { + match RegisterOffset::try_from(offset) { + Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => { + let device_id = self.get_class().device_id; + ControlFlow::Break(u64::from(device_id[(offset - 0xfe0) >> 2])) + } + Err(_) => { + // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); + ControlFlow::Break(0) + } + Ok(field) => { + let result = self.regs_read(field); + match result { + ControlFlow::Break(value) => ControlFlow::Break(value.into()), + ControlFlow::Continue(value) => ControlFlow::Continue(value.into()), + } + } + } + } + + pub fn write(&mut self, offset: hwaddr, value: u64) { + if let Ok(field) = RegisterOffset::try_from(offset) { + self.regs_write(field, value as u32); + } else { + eprintln!("write bad offset {offset} value {value}"); + } + } } /// Which bits in the interrupt status matter for each outbound IRQ line ? From patchwork Fri Jan 24 09:44: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: 13949198 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 277ECC0218B for ; Fri, 24 Jan 2025 09:51:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGIO-0006Xp-LC; Fri, 24 Jan 2025 04:48: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 1tbGGQ-0007r6-PF for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:22 -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 1tbGGO-0003zJ-G6 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711967; 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=14M6y43j2+I/0HjJ1yw2OhzwD6m5Rm3rJ7c4Et0oVDw=; b=Wh0KrcQfYpbGSSB2dPsjKvSVUTd51fQGkdo2lKZZPmCY3J4XrZ1KNTZjdFfg2QOSvAfvZm gWnz186AkpShmof/e37XodOBeSF2+6MUuIcPhBFQPyu7xr4HKc99k1Mn15XcPxPo1TgISn FJ9nKOYNwh82/k1uIwcBvzj8ImB9+uM= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-231-Yd6b2oNGMiy0FdLMtXXyzg-1; Fri, 24 Jan 2025 04:46:05 -0500 X-MC-Unique: Yd6b2oNGMiy0FdLMtXXyzg-1 X-Mimecast-MFC-AGG-ID: Yd6b2oNGMiy0FdLMtXXyzg Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-436219070b4so8838835e9.1 for ; Fri, 24 Jan 2025 01:46:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711963; x=1738316763; 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=14M6y43j2+I/0HjJ1yw2OhzwD6m5Rm3rJ7c4Et0oVDw=; b=Au0WVXlXouJa3yfDSzfX1drUTybpi4iVhZMlUAc0tU1WDG6t3wmxwP5buKkSVUlbo2 8l9bl3mGxZJM3kQ+9QekwelfYnSKYRsHhnGyj0oBgl3LgNuGiuY78Ij3N042Y3uKIznG S04wCA2OdkZzPVitbvoPswgAUNbWrRTT41w+jYiiZQboFQVIQystsHnd5D44H/4vvKk2 +0Q2EcoEUFZol2l+PqCGEDolyFv3sieTe5uY/ZIlheQo3wdkxEUQuSgnWOFP2TwH6DLr N9Hw4+pjz+LA6tY4Le74qJNyQxJMreKaOWjNhsK5TmBZgNAxl0ns8MdeVtkkcMrU585L vnsg== X-Gm-Message-State: AOJu0YxA1WHJyryaLLTtqI3m8gi+R9XZ3ehVbfzELkcwsIO+NToVMO4Y 1hoQ/KSfLP4O1uuf5K+Vx4k4EBd1pgdF2c8hCMuEff1o2bqlXSf5qcxqWaz2Dxazn1a0qqPSrrs oR4KL9BrrTRJWcF+k/RctpqCgwQyErpLcrEM4cEz0Hwnz3Au4ipVrR+vnLeaXVAbu7pnrj93Qi3 r/gyXS9LGmpidEMOT0FD7pUU3Z2+wSD2T886nUOAA= X-Gm-Gg: ASbGncvWFOq9xDCnO3YabUrJ0bk0IGOTsUM+yTwi5bXLYN/TtlJJjavtGaU0XMvc/zl quTvYKlU5jVGxWLCNy91vyhgi7XtyOeXSVWIOWb01CIhJWceFS7ZV4O05TAIHPcPG38vNl/SHzK ykWmxKXSg8bah3lLcG3EDE76eZ1UEr3FgRbgKvNwArjg+DhOFRqs8RUDxShZ9NhbYLbikGbQfNx P2HVmmEqFxFEVB1/k0PgciC5oJNtFuWJOMep+qJlFhr5lKyh/y1Wkbun2eB8QtAyyY6Xreziw== X-Received: by 2002:a05:600c:3b94:b0:434:e2ea:fc94 with SMTP id 5b1f17b1804b1-438913cb620mr316040725e9.11.1737711962645; Fri, 24 Jan 2025 01:46:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3rQQxsZQyvpOIozx0hbjE0/adKr7dmqg8km34oHyV1LLaRGaqvnBlh/SqRHWK3U2nRQeKIg== X-Received: by 2002:a05:600c:3b94:b0:434:e2ea:fc94 with SMTP id 5b1f17b1804b1-438913cb620mr316040335e9.11.1737711962087; Fri, 24 Jan 2025 01:46:02 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4856d8sm20627535e9.11.2025.01.24.01.46.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 39/48] rust: pl011: extract CharBackend receive logic into a separate function Date: Fri, 24 Jan 2025 10:44:33 +0100 Message-ID: <20250124094442.13207-40-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 Prepare for moving all references to the registers and the FIFO into a separate struct. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 58b54547336..de5110038a5 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -6,7 +6,7 @@ use std::{ ffi::CStr, ops::ControlFlow, - os::raw::{c_int, c_uint, c_void}, + os::raw::{c_int, c_void}, }; use qemu_api::{ @@ -488,6 +488,12 @@ pub fn can_receive(&self) -> bool { self.read_count < self.fifo_depth() } + pub fn receive(&mut self, ch: u32) { + if !self.loopback_enabled() { + self.put_fifo(ch) + } + } + pub fn event(&mut self, event: QEMUChrEvent) { if event == QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_enabled() { self.put_fifo(registers::Data::BREAK.into()); @@ -513,7 +519,7 @@ pub fn fifo_depth(&self) -> u32 { 1 } - pub fn put_fifo(&mut self, value: c_uint) { + pub fn put_fifo(&mut self, value: u32) { let depth = self.fifo_depth(); assert!(depth > 0); let slot = (self.read_pos + self.read_count) & (depth - 1); @@ -622,12 +628,9 @@ pub fn write(&mut self, offset: hwaddr, value: u64) { pub unsafe extern "C" fn pl011_receive(opaque: *mut c_void, buf: *const u8, size: c_int) { let mut state = NonNull::new(opaque).unwrap().cast::(); unsafe { - if state.as_ref().loopback_enabled() { - return; - } if size > 0 { debug_assert!(!buf.is_null()); - state.as_mut().put_fifo(c_uint::from(buf.read_volatile())) + state.as_mut().receive(u32::from(buf.read_volatile())); } } } From patchwork Fri Jan 24 09:44: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: 13949178 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 469EAC0218B for ; Fri, 24 Jan 2025 09:48:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHz-000476-Qb; Fri, 24 Jan 2025 04:47: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 1tbGGT-0007rM-71 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:20 -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 1tbGGO-0003zM-UU for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711967; 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=Oie+UgyG+xo4wp2azixL6WeEjPRPNC/oLryPAGhcuZA=; b=FuON5gzawoCkYokvCGEO8nj9htrkxink5ev13xtzkZjbofUL9PpsVuscpJwRnK7zJF4Hdk geHhbRic0ZMzONj3YcOYxVsCqgoK3490ieCXHbjBLGw5OHjETeBXZlDl4HiPaTsiUBufki hKAuHGHL/nh9htTJweo7kKwZUnKp1fk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-xrsaROcOOp-VKvJlBmBg5w-1; Fri, 24 Jan 2025 04:46:05 -0500 X-MC-Unique: xrsaROcOOp-VKvJlBmBg5w-1 X-Mimecast-MFC-AGG-ID: xrsaROcOOp-VKvJlBmBg5w Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4362b9c15d8so8753975e9.3 for ; Fri, 24 Jan 2025 01:46:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711964; x=1738316764; 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=Oie+UgyG+xo4wp2azixL6WeEjPRPNC/oLryPAGhcuZA=; b=rmOyZcYEuZBXGa1MDGmEoV6Zff2KGHArlzOac4zuzDxj97s4OmqQQbIvc2khdlMuo3 N6vJ3fFtKL0DrIrV/BwIDZGPn9e7IXPkuu73xIqxiP4f+Y7fHCOOScufEDOWXcn7OD99 zATBmm3TF3B9pyCq8Consm/d9wbjkWY8N+Xycp8604rvsrwzHOVQyd8fDe8CXgemC06G dT2Upm7a0qn9Ji/9y93VGMSkMGEOkd6iClo/LLryj+sLUXKbmPgr5x0EuOJE3tmCjvRj TZqpeFZTEwj34I3/x1HgW1ZaPH9gt3tpsaZ6CBoNjSfmr95MGcC/AJvjQL7OrATYgC2A htvg== X-Gm-Message-State: AOJu0YzkVY28ShN8NjJVpwh/+nL6GGF5lXyK6HoLeXM7re+vjlluhZ2y rT2RVvrQ+Ci78qDC1cZ2/VbguuExuM3DaArLq6nt3QOvPqW8oNMkq7LPX27QM6GCPX2sjGVq2lh bPsUREzaq+e5/6jqSMfmakPJw1CZYr18pUHOnUXj86lwLEZA9Z4tCebHe3NXjOBqOuOf5qgTsrU G/XLwdGEbj9FFx7AAl8shHKcm8hJdsNshUaIwFZmM= X-Gm-Gg: ASbGncsRYaifxKz+6Z0EJb8CIwFdk/lDHDnvCXiLNIkIHg4s+NB3sDDruNyxT48Rxqp lsRtVfvYRVOUEAuS+/E9niIy3STfCevssxvh3ulFSWj9rbnMWRsyJvWMCirFkd0W87bl6iicesc zeN1KBsK4GgOJM/JZrNliS81rBfPitXEMTvviQW70C7UMSxJ0sT9zj1nSQ/CFw4YDxf2bD9tVnf QUNC8xNn9dLWfy4syyFwOcj12PnR/7Mup7oRG80VwPPGVxW3ZS+zJPxSoorrGgfe3NHtzjfqA== X-Received: by 2002:a05:600c:5486:b0:434:f1e9:afae with SMTP id 5b1f17b1804b1-438913bfa0fmr242509635e9.1.1737711963919; Fri, 24 Jan 2025 01:46:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUHi8PqY8wgEb9kJyjfU7CyySml8jiZHKdXoA4+DZ7ZbBcNysjR55/L/bjNVmCrfIQSaRfWQ== X-Received: by 2002:a05:600c:5486:b0:434:f1e9:afae with SMTP id 5b1f17b1804b1-438913bfa0fmr242509215e9.1.1737711963273; Fri, 24 Jan 2025 01:46:03 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4c75c0sm20280095e9.31.2025.01.24.01.46.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:02 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 40/48] rust: pl011: pull interrupt updates out of read/write ops Date: Fri, 24 Jan 2025 10:44:34 +0100 Message-ID: <20250124094442.13207-41-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 qemu_irqs are not part of the vmstate, therefore they will remain in PL011State. Update them if needed after regs_read()/regs_write(). Apply #[must_use] to functions that return whether the interrupt state could have changed, so that it's harder to forget the call to update(). Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 84 ++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index de5110038a5..9cac9d352a2 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -242,7 +242,6 @@ fn regs_read(&mut self, offset: RegisterOffset) -> ControlFlow { } // Update error bits. self.receive_status_error_clear.set_from_data(c); - self.update(); // Must call qemu_chr_fe_accept_input, so return Continue: return ControlFlow::Continue(u32::from(c)); } @@ -266,7 +265,7 @@ fn regs_read(&mut self, offset: RegisterOffset) -> ControlFlow { }) } - fn regs_write(&mut self, offset: RegisterOffset, value: u32) { + fn regs_write(&mut self, offset: RegisterOffset, value: u32) -> bool { // eprintln!("write offset {offset} value {value}"); use RegisterOffset::*; match offset { @@ -281,9 +280,10 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) { unsafe { qemu_chr_fe_write_all(addr_of_mut!(self.char_backend), &ch, 1); } - self.loopback_tx(value); + // interrupts always checked + let _ = self.loopback_tx(value); self.int_level |= registers::INT_TX; - self.update(); + return true; } RSR => { self.receive_status_error_clear = 0.into(); @@ -307,7 +307,7 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) { self.reset_rx_fifo(); self.reset_tx_fifo(); } - if self.line_control.send_break() ^ new_val.send_break() { + let update = (self.line_control.send_break() != new_val.send_break()) && { let mut break_enable: c_int = new_val.send_break().into(); // SAFETY: self.char_backend is a valid CharBackend instance after it's been // initialized in realize(). @@ -318,15 +318,16 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) { addr_of_mut!(break_enable).cast::(), ); } - self.loopback_break(break_enable > 0); - } + self.loopback_break(break_enable > 0) + }; self.line_control = new_val; self.set_read_trigger(); + return update; } CR => { // ??? Need to implement the enable bit. self.control = value.into(); - self.loopback_mdmctrl(); + return self.loopback_mdmctrl(); } FLS => { self.ifl = value; @@ -334,13 +335,13 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) { } IMSC => { self.int_enabled = value; - self.update(); + return true; } RIS => {} MIS => {} ICR => { self.int_level &= !value; - self.update(); + return true; } DMACR => { self.dmacr = value; @@ -350,14 +351,12 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) { } } } + false } #[inline] - fn loopback_tx(&mut self, value: u32) { - if !self.loopback_enabled() { - return; - } - + #[must_use] + fn loopback_tx(&mut self, value: u32) -> bool { // Caveat: // // In real hardware, TX loopback happens at the serial-bit level @@ -375,12 +374,13 @@ fn loopback_tx(&mut self, value: u32) { // hardware flow-control is enabled. // // For simplicity, the above described is not emulated. - self.put_fifo(value); + self.loopback_enabled() && self.put_fifo(value) } - fn loopback_mdmctrl(&mut self) { + #[must_use] + fn loopback_mdmctrl(&mut self) -> bool { if !self.loopback_enabled() { - return; + return false; } /* @@ -421,13 +421,11 @@ fn loopback_mdmctrl(&mut self) { il |= Interrupt::RI as u32; } self.int_level = il; - self.update(); + true } - fn loopback_break(&mut self, enable: bool) { - if enable { - self.loopback_tx(registers::Data::BREAK.into()); - } + fn loopback_break(&mut self, enable: bool) -> bool { + enable && self.loopback_tx(registers::Data::BREAK.into()) } fn set_read_trigger(&mut self) { @@ -489,14 +487,17 @@ pub fn can_receive(&self) -> bool { } pub fn receive(&mut self, ch: u32) { - if !self.loopback_enabled() { - self.put_fifo(ch) + if !self.loopback_enabled() && self.put_fifo(ch) { + self.update(); } } pub fn event(&mut self, event: QEMUChrEvent) { if event == QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_enabled() { - self.put_fifo(registers::Data::BREAK.into()); + let update = self.put_fifo(registers::Data::BREAK.into()); + if update { + self.update(); + } } } @@ -519,7 +520,8 @@ pub fn fifo_depth(&self) -> u32 { 1 } - pub fn put_fifo(&mut self, value: u32) { + #[must_use] + pub fn put_fifo(&mut self, value: u32) -> bool { let depth = self.fifo_depth(); assert!(depth > 0); let slot = (self.read_pos + self.read_count) & (depth - 1); @@ -532,8 +534,9 @@ pub fn put_fifo(&mut self, value: u32) { if self.read_count == self.read_trigger { self.int_level |= registers::INT_RX; - self.update(); + return true; } + false } pub fn update(&self) { @@ -565,7 +568,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { } pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { - match RegisterOffset::try_from(offset) { + let mut update_irq = false; + let result = match RegisterOffset::try_from(offset) { Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => { let device_id = self.get_class().device_id; ControlFlow::Break(u64::from(device_id[(offset - 0xfe0) >> 2])) @@ -574,22 +578,30 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); ControlFlow::Break(0) } - Ok(field) => { - let result = self.regs_read(field); - match result { - ControlFlow::Break(value) => ControlFlow::Break(value.into()), - ControlFlow::Continue(value) => ControlFlow::Continue(value.into()), + Ok(field) => match self.regs_read(field) { + ControlFlow::Break(value) => ControlFlow::Break(value.into()), + ControlFlow::Continue(value) => { + update_irq = true; + ControlFlow::Continue(value.into()) } - } + }, + }; + if update_irq { + self.update(); } + result } pub fn write(&mut self, offset: hwaddr, value: u64) { + let mut update_irq = false; if let Ok(field) = RegisterOffset::try_from(offset) { - self.regs_write(field, value as u32); + update_irq = self.regs_write(field, value as u32); } else { eprintln!("write bad offset {offset} value {value}"); } + if update_irq { + self.update(); + } } } From patchwork Fri Jan 24 09:44: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: 13949201 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 2AF55C02181 for ; Fri, 24 Jan 2025 09:51:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGIN-0006M0-1Q; Fri, 24 Jan 2025 04:48: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 1tbGGT-0007rN-Fg for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:22 -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 1tbGGQ-0003zU-FV for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711969; 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=pYotlgAkj0BTi86HRyNenC71lJ7jbC7FINWW+MntPOg=; b=C4mrhwk6jfnZjSlx0nmzKGL1hETa1j8MRQPBlmVCjvx6e2rSB4QuBlJ8PH8/UVyQ9RBe30 H/JA1eY3NQK7tMoHAFw2re0gaSq8VuPD7PwpzNe29WrSi5YDWYIVFf/uBan3huMR3yxpRV 6HbqiJO+c6KZ06M0vmQTg6CZNv1z9i8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-0z3mT4ZuMxWwYqLQ2p7Xzg-1; Fri, 24 Jan 2025 04:46:07 -0500 X-MC-Unique: 0z3mT4ZuMxWwYqLQ2p7Xzg-1 X-Mimecast-MFC-AGG-ID: 0z3mT4ZuMxWwYqLQ2p7Xzg Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43625ceae52so10232015e9.0 for ; Fri, 24 Jan 2025 01:46:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711965; x=1738316765; 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=pYotlgAkj0BTi86HRyNenC71lJ7jbC7FINWW+MntPOg=; b=E9fPCJWo+U6cdxGy1DCBi6BjTHJ1TdGB8y3sWdCpCoRhgnBxoPRznc0j9saAYbEwIL soatiFIsBOfTq9DIeKQInqKtJwHORrQVW1lyzKIC66Kcf1gNmAhxddKcIXM0EE6UEMnC iBfnw7dfv9/pmSY0rxCnvGtkjr1XrZsiVYrlrBpfOUH/YswPptMwRucFXNngdbvKkaP/ wDYUNIC5tNgP9Mgd0ldLbiWg78MSTxtq+doXc7O/hSYDasctUa6JgXM9NbiFBCqMDJey eNCAnk/lSRngBVrnv/HoV/fNWJEFe5r6WMK97UnrzQlCpbiK4DQA7Ei0a/fXkzSFBfax jbgg== X-Gm-Message-State: AOJu0YzLGTnxzxLOcYge0vtaEZ1lqlJARXU9xz5/GFF5Dq9JChginyRB oC8fRgCn3OeJm+6DHc55Diz7I03hAihYmxWiJlREP1nb6jig94PgtKcRVcaJukiSC9w1wnzTpbC 0sJyKHhM7XursJE9IgxJYI81pxwKyuX5yywV9cGRhK5h69YDBWIQVTG42xpe8TiqBwQ1LFNZInb pVZc1TOYptbT7HWHi+NX/D02jKoczr9qs9Wo/lbFA= X-Gm-Gg: ASbGncuaWiLXJzo3yG3XziIXdeFDY9xFKPqA1iL5aFty/ENxiB0eDc9SJ42YnusNiXa cD3iKTrLQCo8DKlCxX5B4aem/UGa599PBEjIm9mFpjNDgQL1dwOW9P8d7Pa7WQzsxWe7aKMR+Gl A4Yu9Jv3ZkPZn8TuVRKJyWxdogXDtXeVEpPZie2hGYDJ76h2mQfLDos7V+ktwxPrSwA0f1A14C8 hqDy4L/giHqvZHYf9zL4d9xBqtS92rMullGBfKnl4Fh7sHuof9/3rsZpFSitOgFCkStVh8Zzw== X-Received: by 2002:a5d:4845:0:b0:385:f573:1f78 with SMTP id ffacd0b85a97d-38bf566e2b2mr21737166f8f.24.1737711965160; Fri, 24 Jan 2025 01:46:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDG0GGTjZLED+Fv+D/Cn1YWr7dft/Kj99t5Lq1gN8swteMPsVQfTkrB1oXaes3Ox13k6Wz0g== X-Received: by 2002:a5d:4845:0:b0:385:f573:1f78 with SMTP id ffacd0b85a97d-38bf566e2b2mr21737126f8f.24.1737711964493; Fri, 24 Jan 2025 01:46:04 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1bbd93sm2151296f8f.76.2025.01.24.01.46.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 41/48] rust: pl011: extract PL011Registers Date: Fri, 24 Jan 2025 10:44:35 +0100 Message-ID: <20250124094442.13207-42-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 Pull all the mutable fields of PL011State into a separate struct. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 251 ++++++++++++++----------- rust/hw/char/pl011/src/device_class.rs | 46 +++-- 2 files changed, 168 insertions(+), 129 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 9cac9d352a2..f1319d1a8bd 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -85,11 +85,8 @@ fn index(&self, idx: u32) -> &Self::Output { } #[repr(C)] -#[derive(Debug, qemu_api_macros::Object, qemu_api_macros::offsets)] -/// PL011 Device Model in QEMU -pub struct PL011State { - pub parent_obj: ParentField, - pub iomem: MemoryRegion, +#[derive(Debug, Default, qemu_api_macros::offsets)] +pub struct PL011Registers { #[doc(alias = "fr")] pub flags: registers::Flags, #[doc(alias = "lcr")] @@ -109,8 +106,17 @@ pub struct PL011State { pub read_pos: u32, pub read_count: u32, pub read_trigger: u32, +} + +#[repr(C)] +#[derive(Debug, qemu_api_macros::Object, qemu_api_macros::offsets)] +/// PL011 Device Model in QEMU +pub struct PL011State { + pub parent_obj: ParentField, + pub iomem: MemoryRegion, #[doc(alias = "chr")] pub char_backend: CharBackend, + pub regs: PL011Registers, /// QEMU interrupts /// /// ```text @@ -169,61 +175,8 @@ fn vmsd() -> Option<&'static VMStateDescription> { const RESET: Option = Some(Self::reset); } -impl PL011State { - /// Initializes a pre-allocated, unitialized instance of `PL011State`. - /// - /// # Safety - /// - /// `self` must point to a correctly sized and aligned location for the - /// `PL011State` type. It must not be called more than once on the same - /// location/instance. All its fields are expected to hold unitialized - /// values with the sole exception of `parent_obj`. - unsafe fn init(&mut self) { - const CLK_NAME: &CStr = c_str!("clk"); - - // SAFETY: - // - // self and self.iomem are guaranteed to be valid at this point since callers - // must make sure the `self` reference is valid. - unsafe { - memory_region_init_io( - addr_of_mut!(self.iomem), - addr_of_mut!(*self).cast::(), - &PL011_OPS, - addr_of_mut!(*self).cast::(), - Self::TYPE_NAME.as_ptr(), - 0x1000, - ); - } - - // SAFETY: - // - // self.clock is not initialized at this point; but since `NonNull<_>` is Copy, - // we can overwrite the undefined value without side effects. This is - // safe since all PL011State instances are created by QOM code which - // calls this function to initialize the fields; therefore no code is - // able to access an invalid self.clock value. - unsafe { - let dev: &mut DeviceState = self.upcast_mut(); - self.clock = NonNull::new(qdev_init_clock_in( - dev, - CLK_NAME.as_ptr(), - None, /* pl011_clock_update */ - addr_of_mut!(*self).cast::(), - ClockEvent::ClockUpdate.0, - )) - .unwrap(); - } - } - - fn post_init(&self) { - self.init_mmio(&self.iomem); - for irq in self.interrupts.iter() { - self.init_irq(irq); - } - } - - fn regs_read(&mut self, offset: RegisterOffset) -> ControlFlow { +impl PL011Registers { + pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow { use RegisterOffset::*; ControlFlow::Break(match offset { @@ -265,7 +218,12 @@ fn regs_read(&mut self, offset: RegisterOffset) -> ControlFlow { }) } - fn regs_write(&mut self, offset: RegisterOffset, value: u32) -> bool { + pub(self) fn write( + &mut self, + offset: RegisterOffset, + value: u32, + char_backend: *mut CharBackend, + ) -> bool { // eprintln!("write offset {offset} value {value}"); use RegisterOffset::*; match offset { @@ -275,10 +233,10 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) -> bool { // XXX this blocks entire thread. Rewrite to use // qemu_chr_fe_write and background I/O callbacks - // SAFETY: self.char_backend is a valid CharBackend instance after it's been + // SAFETY: char_backend is a valid CharBackend instance after it's been // initialized in realize(). unsafe { - qemu_chr_fe_write_all(addr_of_mut!(self.char_backend), &ch, 1); + qemu_chr_fe_write_all(char_backend, &ch, 1); } // interrupts always checked let _ = self.loopback_tx(value); @@ -313,7 +271,7 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) -> bool { // initialized in realize(). unsafe { qemu_chr_fe_ioctl( - addr_of_mut!(self.char_backend), + char_backend, CHR_IOCTL_SERIAL_SET_BREAK as i32, addr_of_mut!(break_enable).cast::(), ); @@ -432,23 +390,6 @@ fn set_read_trigger(&mut self) { self.read_trigger = 1; } - pub fn realize(&self) { - // SAFETY: self.char_backend has the correct size and alignment for a - // CharBackend object, and its callbacks are of the correct types. - unsafe { - qemu_chr_fe_set_handlers( - addr_of!(self.char_backend) as *mut CharBackend, - Some(pl011_can_receive), - Some(pl011_receive), - Some(pl011_event), - None, - addr_of!(*self).cast::() as *mut c_void, - core::ptr::null_mut(), - true, - ); - } - } - pub fn reset(&mut self) { self.line_control.reset(); self.receive_status_error_clear.reset(); @@ -481,26 +422,6 @@ pub fn reset_tx_fifo(&mut self) { self.flags.set_transmit_fifo_empty(true); } - pub fn can_receive(&self) -> bool { - // trace_pl011_can_receive(s->lcr, s->read_count, r); - self.read_count < self.fifo_depth() - } - - pub fn receive(&mut self, ch: u32) { - if !self.loopback_enabled() && self.put_fifo(ch) { - self.update(); - } - } - - pub fn event(&mut self, event: QEMUChrEvent) { - if event == QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_enabled() { - let update = self.put_fifo(registers::Data::BREAK.into()); - if update { - self.update(); - } - } - } - #[inline] pub fn fifo_enabled(&self) -> bool { self.line_control.fifos_enabled() == registers::Mode::FIFO @@ -539,14 +460,7 @@ pub fn put_fifo(&mut self, value: u32) -> bool { false } - pub fn update(&self) { - let flags = self.int_level & self.int_enabled; - for (irq, i) in self.interrupts.iter().zip(IRQMASK) { - irq.set(flags & i != 0); - } - } - - pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { + pub fn post_load(&mut self) -> Result<(), ()> { /* Sanity-check input state */ if self.read_pos >= self.read_fifo.len() || self.read_count > self.read_fifo.len() { return Err(()); @@ -566,6 +480,63 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { Ok(()) } +} + +impl PL011State { + /// Initializes a pre-allocated, unitialized instance of `PL011State`. + /// + /// # Safety + /// + /// `self` must point to a correctly sized and aligned location for the + /// `PL011State` type. It must not be called more than once on the same + /// location/instance. All its fields are expected to hold unitialized + /// values with the sole exception of `parent_obj`. + unsafe fn init(&mut self) { + const CLK_NAME: &CStr = c_str!("clk"); + + // SAFETY: + // + // self and self.iomem are guaranteed to be valid at this point since callers + // must make sure the `self` reference is valid. + unsafe { + memory_region_init_io( + addr_of_mut!(self.iomem), + addr_of_mut!(*self).cast::(), + &PL011_OPS, + addr_of_mut!(*self).cast::(), + Self::TYPE_NAME.as_ptr(), + 0x1000, + ); + } + + self.regs = Default::default(); + + // SAFETY: + // + // self.clock is not initialized at this point; but since `NonNull<_>` is Copy, + // we can overwrite the undefined value without side effects. This is + // safe since all PL011State instances are created by QOM code which + // calls this function to initialize the fields; therefore no code is + // able to access an invalid self.clock value. + unsafe { + let dev: &mut DeviceState = self.upcast_mut(); + self.clock = NonNull::new(qdev_init_clock_in( + dev, + CLK_NAME.as_ptr(), + None, /* pl011_clock_update */ + addr_of_mut!(*self).cast::(), + ClockEvent::ClockUpdate.0, + )) + .unwrap(); + } + } + + fn post_init(&self) { + self.init_mmio(&self.iomem); + for irq in self.interrupts.iter() { + self.init_irq(irq); + } + } pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { let mut update_irq = false; @@ -578,7 +549,7 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); ControlFlow::Break(0) } - Ok(field) => match self.regs_read(field) { + Ok(field) => match self.regs.read(field) { ControlFlow::Break(value) => ControlFlow::Break(value.into()), ControlFlow::Continue(value) => { update_irq = true; @@ -595,7 +566,7 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { pub fn write(&mut self, offset: hwaddr, value: u64) { let mut update_irq = false; if let Ok(field) = RegisterOffset::try_from(offset) { - update_irq = self.regs_write(field, value as u32); + update_irq = self.regs.write(field, value as u32, &mut self.char_backend); } else { eprintln!("write bad offset {offset} value {value}"); } @@ -603,6 +574,64 @@ pub fn write(&mut self, offset: hwaddr, value: u64) { self.update(); } } + + pub fn can_receive(&self) -> bool { + // trace_pl011_can_receive(s->lcr, s->read_count, r); + let regs = &self.regs; + regs.read_count < regs.fifo_depth() + } + + pub fn receive(&mut self, ch: u32) { + let regs = &mut self.regs; + let update_irq = !regs.loopback_enabled() && regs.put_fifo(ch); + if update_irq { + self.update(); + } + } + + pub fn event(&mut self, event: QEMUChrEvent) { + let mut update_irq = false; + let regs = &mut self.regs; + if event == QEMUChrEvent::CHR_EVENT_BREAK && !regs.loopback_enabled() { + update_irq = regs.put_fifo(registers::Data::BREAK.into()); + } + if update_irq { + self.update() + } + } + + pub fn realize(&self) { + // SAFETY: self.char_backend has the correct size and alignment for a + // CharBackend object, and its callbacks are of the correct types. + unsafe { + qemu_chr_fe_set_handlers( + addr_of!(self.char_backend) as *mut CharBackend, + Some(pl011_can_receive), + Some(pl011_receive), + Some(pl011_event), + None, + addr_of!(*self).cast::() as *mut c_void, + core::ptr::null_mut(), + true, + ); + } + } + + pub fn reset(&mut self) { + self.regs.reset(); + } + + pub fn update(&self) { + let regs = &self.regs; + let flags = regs.int_level & regs.int_enabled; + for (irq, i) in self.interrupts.iter().zip(IRQMASK) { + irq.set(flags & i != 0); + } + } + + pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { + self.regs.post_load() + } } /// Which bits in the interrupt status matter for each outbound IRQ line ? diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index 2336a768729..d94b98de7bb 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -6,11 +6,11 @@ use std::os::raw::{c_int, c_void}; use qemu_api::{ - bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_of, vmstate_subsections, - vmstate_unused, zeroable::Zeroable, + bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_of, vmstate_struct, + vmstate_subsections, vmstate_unused, zeroable::Zeroable, }; -use crate::device::PL011State; +use crate::device::{PL011Registers, PL011State}; #[allow(clippy::missing_const_for_fn)] extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { @@ -40,6 +40,30 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { } } +static VMSTATE_PL011_REGS: VMStateDescription = VMStateDescription { + name: c_str!("pl011/regs").as_ptr(), + version_id: 2, + minimum_version_id: 2, + fields: vmstate_fields! { + vmstate_of!(PL011Registers, flags), + vmstate_of!(PL011Registers, line_control), + vmstate_of!(PL011Registers, receive_status_error_clear), + vmstate_of!(PL011Registers, control), + vmstate_of!(PL011Registers, dmacr), + vmstate_of!(PL011Registers, int_enabled), + vmstate_of!(PL011Registers, int_level), + vmstate_of!(PL011Registers, read_fifo), + vmstate_of!(PL011Registers, ilpr), + vmstate_of!(PL011Registers, ibrd), + vmstate_of!(PL011Registers, fbrd), + vmstate_of!(PL011Registers, ifl), + vmstate_of!(PL011Registers, read_pos), + vmstate_of!(PL011Registers, read_count), + vmstate_of!(PL011Registers, read_trigger), + }, + ..Zeroable::ZERO +}; + pub static VMSTATE_PL011: VMStateDescription = VMStateDescription { name: c_str!("pl011").as_ptr(), version_id: 2, @@ -47,21 +71,7 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { post_load: Some(pl011_post_load), fields: vmstate_fields! { vmstate_unused!(core::mem::size_of::()), - vmstate_of!(PL011State, flags), - vmstate_of!(PL011State, line_control), - vmstate_of!(PL011State, receive_status_error_clear), - vmstate_of!(PL011State, control), - vmstate_of!(PL011State, dmacr), - vmstate_of!(PL011State, int_enabled), - vmstate_of!(PL011State, int_level), - vmstate_of!(PL011State, read_fifo), - vmstate_of!(PL011State, ilpr), - vmstate_of!(PL011State, ibrd), - vmstate_of!(PL011State, fbrd), - vmstate_of!(PL011State, ifl), - vmstate_of!(PL011State, read_pos), - vmstate_of!(PL011State, read_count), - vmstate_of!(PL011State, read_trigger), + vmstate_struct!(PL011State, regs, &VMSTATE_PL011_REGS, PL011Registers), }, subsections: vmstate_subsections! { VMSTATE_PL011_CLOCK From patchwork Fri Jan 24 09:44: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: 13949206 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 4DBD0C0218C for ; Fri, 24 Jan 2025 09:52:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHv-0003ii-GS; Fri, 24 Jan 2025 04:47: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 1tbGGT-0007rL-6G for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:22 -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 1tbGGQ-0003zZ-Fs for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711969; 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=LnYPmmzbHtO9VYxLsF7WeRrLBt7TIDcweZucQbIAULs=; b=bcpQ9EBOhXBq7pT0Nn4/Di/gdwxx/QAZmUGOvDRxBpHL0QEUxTgoUVgDL0n1+17r8dIpik e84PubB7gxwxMQbWKIXjOkibVxnroFUNFlIiBum6z+iLxSo5JuvVyIlFeXZvBMMT+AU4z6 OcQZmPoypXIMY8z1WqzcR9779PMmhG4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-aQMRFyNBPOWxMDhjRNLCnA-1; Fri, 24 Jan 2025 04:46:08 -0500 X-MC-Unique: aQMRFyNBPOWxMDhjRNLCnA-1 X-Mimecast-MFC-AGG-ID: aQMRFyNBPOWxMDhjRNLCnA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-436225d4389so14625265e9.1 for ; Fri, 24 Jan 2025 01:46:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711966; x=1738316766; 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=LnYPmmzbHtO9VYxLsF7WeRrLBt7TIDcweZucQbIAULs=; b=Xy83KKrg2K+fvQh+swHWx6lyVtOMsBzFd4LgPE1dYvebFSoY8r23bjlxLnLeP5kPd9 RJM0xDcSAKyHoKwxMF/f9heumD2USeuXCoiz/gpd2XBl6rSoxNunhJX/HXnKL4x2Gwq2 X+CHrnqXGd8w4A/ze4LimJQ4hkq8z3c0DHCgCHQj3b5AMCQnnTkqbm8vcSOSzCPDG0UZ POgEscQIq1DyzmsRZHLmjxnmjpDOHKEsPJkGWElRXDl2SGDsGyQbtm6jj9w83RqFp5vR M2Ej1HpQch8fZC4ci+/evmBRjHYpJQZPFbMUjnvkfW0oj+pf8Bv0ZCqF3sMGHJvFUJFv qEpw== X-Gm-Message-State: AOJu0Yw7IYz1CyghzM0y2H+ZJeEy14bNOW9u7jy4DQ4WNUy4UZZlBInq jYP5GGMOwRNBcAiQjzpfxAPzYalLC4odMQ3FGHZr+aEZJUPk76LUtoiseH/bSgg59QX34IM79rs 70a/cB1g0uW03F7ZMWdiUo8VoJtD6BQ60fXtfeQNRJDkHvWHUSNYrIA8mFl8Rd1nIX/cmE2l9zB BqOkGEpYaLnWorzV5+k+y0nYBlkCZEgcMde+Wd4x4= X-Gm-Gg: ASbGncs8f9EoRWpil+uX4iVVsNq5IhWkklt0gjQA/V5oWMB/aWb4jeB+HEUwacf2Ugk YrXQI+kgIV47NaIxyClVsAfjNSpSSlu3d57vDXG/XEwx6E1O4Ns5t2GrE95EsV5RA2pH3RBOT+Q 6kDB7lPU6ZK2tEkXgpRm89/vACg36gluQgUq8nUtceg0WsnUZjPjFhu19V8rPGIlcNi9imeugLE XKS2ezqtrcGy9pwC9cao9MUa4rBW6TL0Uhm5au7hsn/7fw+MileL26m0FaD4Sy5uGOH8EOXyg== X-Received: by 2002:a05:600c:58c9:b0:436:e3ea:64dd with SMTP id 5b1f17b1804b1-438bd0a88dbmr22948015e9.11.1737711966482; Fri, 24 Jan 2025 01:46:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXene5jhJddv0rJmibbIevqjM3Q7qVX6fnc4nuI5ZR4uq6NX3kd8xFBwOws2RK1dhn7pKf5Q== X-Received: by 2002:a05:600c:58c9:b0:436:e3ea:64dd with SMTP id 5b1f17b1804b1-438bd0a88dbmr22947645e9.11.1737711965962; Fri, 24 Jan 2025 01:46:05 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4b9990sm20855065e9.29.2025.01.24.01.46.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:05 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 42/48] rust: pl011: wrap registers with BqlRefCell Date: Fri, 24 Jan 2025 10:44:36 +0100 Message-ID: <20250124094442.13207-43-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 is a step towards making memory ops use a shared reference to the device type; it's not yet possible due to the calls to character device functions. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 40 ++++++++++++++------------ rust/hw/char/pl011/src/device_class.rs | 8 +++--- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index f1319d1a8bd..4fd9bdc8584 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -109,14 +109,14 @@ pub struct PL011Registers { } #[repr(C)] -#[derive(Debug, qemu_api_macros::Object, qemu_api_macros::offsets)] +#[derive(qemu_api_macros::Object, qemu_api_macros::offsets)] /// PL011 Device Model in QEMU pub struct PL011State { pub parent_obj: ParentField, pub iomem: MemoryRegion, #[doc(alias = "chr")] pub char_backend: CharBackend, - pub regs: PL011Registers, + pub regs: BqlRefCell, /// QEMU interrupts /// /// ```text @@ -538,6 +538,7 @@ fn post_init(&self) { } } + #[allow(clippy::needless_pass_by_ref_mut)] pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { let mut update_irq = false; let result = match RegisterOffset::try_from(offset) { @@ -549,7 +550,7 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); ControlFlow::Break(0) } - Ok(field) => match self.regs.read(field) { + Ok(field) => match self.regs.borrow_mut().read(field) { ControlFlow::Break(value) => ControlFlow::Break(value.into()), ControlFlow::Continue(value) => { update_irq = true; @@ -566,7 +567,10 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { pub fn write(&mut self, offset: hwaddr, value: u64) { let mut update_irq = false; if let Ok(field) = RegisterOffset::try_from(offset) { - update_irq = self.regs.write(field, value as u32, &mut self.char_backend); + update_irq = self + .regs + .borrow_mut() + .write(field, value as u32, &mut self.char_backend); } else { eprintln!("write bad offset {offset} value {value}"); } @@ -577,21 +581,21 @@ pub fn write(&mut self, offset: hwaddr, value: u64) { pub fn can_receive(&self) -> bool { // trace_pl011_can_receive(s->lcr, s->read_count, r); - let regs = &self.regs; + let regs = self.regs.borrow(); regs.read_count < regs.fifo_depth() } - pub fn receive(&mut self, ch: u32) { - let regs = &mut self.regs; + pub fn receive(&self, ch: u32) { + let mut regs = self.regs.borrow_mut(); let update_irq = !regs.loopback_enabled() && regs.put_fifo(ch); if update_irq { self.update(); } } - pub fn event(&mut self, event: QEMUChrEvent) { + pub fn event(&self, event: QEMUChrEvent) { let mut update_irq = false; - let regs = &mut self.regs; + let mut regs = self.regs.borrow_mut(); if event == QEMUChrEvent::CHR_EVENT_BREAK && !regs.loopback_enabled() { update_irq = regs.put_fifo(registers::Data::BREAK.into()); } @@ -618,19 +622,19 @@ pub fn realize(&self) { } pub fn reset(&mut self) { - self.regs.reset(); + self.regs.borrow_mut().reset(); } pub fn update(&self) { - let regs = &self.regs; + let regs = self.regs.borrow(); let flags = regs.int_level & regs.int_enabled; for (irq, i) in self.interrupts.iter().zip(IRQMASK) { irq.set(flags & i != 0); } } - pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { - self.regs.post_load() + pub fn post_load(&self, _version_id: u32) -> Result<(), ()> { + self.regs.borrow_mut().post_load() } } @@ -667,11 +671,11 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { /// /// The buffer and size arguments must also be valid. pub unsafe extern "C" fn pl011_receive(opaque: *mut c_void, buf: *const u8, size: c_int) { - let mut state = NonNull::new(opaque).unwrap().cast::(); + let state = NonNull::new(opaque).unwrap().cast::(); unsafe { if size > 0 { debug_assert!(!buf.is_null()); - state.as_mut().receive(u32::from(buf.read_volatile())); + state.as_ref().receive(u32::from(buf.read_volatile())); } } } @@ -682,8 +686,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { /// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. pub unsafe extern "C" fn pl011_event(opaque: *mut c_void, event: QEMUChrEvent) { - let mut state = NonNull::new(opaque).unwrap().cast::(); - unsafe { state.as_mut().event(event) } + let state = NonNull::new(opaque).unwrap().cast::(); + unsafe { state.as_ref().event(event) } } /// # Safety @@ -708,7 +712,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { } #[repr(C)] -#[derive(Debug, qemu_api_macros::Object)] +#[derive(qemu_api_macros::Object)] /// PL011 Luminary device model. pub struct PL011Luminary { parent_obj: ParentField, diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index d94b98de7bb..8a157a663fb 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -6,7 +6,7 @@ use std::os::raw::{c_int, c_void}; use qemu_api::{ - bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_of, vmstate_struct, + bindings::*, c_str, prelude::*, vmstate_clock, vmstate_fields, vmstate_of, vmstate_struct, vmstate_subsections, vmstate_unused, zeroable::Zeroable, }; @@ -31,8 +31,8 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { }; extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { - let mut state = NonNull::new(opaque).unwrap().cast::(); - let result = unsafe { state.as_mut().post_load(version_id as u32) }; + let state = NonNull::new(opaque).unwrap().cast::(); + let result = unsafe { state.as_ref().post_load(version_id as u32) }; if result.is_err() { -1 } else { @@ -71,7 +71,7 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { post_load: Some(pl011_post_load), fields: vmstate_fields! { vmstate_unused!(core::mem::size_of::()), - vmstate_struct!(PL011State, regs, &VMSTATE_PL011_REGS, PL011Registers), + vmstate_struct!(PL011State, regs, &VMSTATE_PL011_REGS, BqlRefCell), }, subsections: vmstate_subsections! { VMSTATE_PL011_CLOCK From patchwork Fri Jan 24 09:44: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: 13949176 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 C0332C02181 for ; Fri, 24 Jan 2025 09:47:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHa-0001dh-NS; Fri, 24 Jan 2025 04:47: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 1tbGGU-0007rU-Vi for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46: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 1tbGGT-0003zv-8L for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711972; 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=RIbFHI36QG2C9ttEM2sSjSaRWtytsQRJX6tP+6nmQnM=; b=OrtzcITV2c+XtBMBo2AcdhbTOPEaxN4Mgn1zbW8eCbJeznh3YFzIFY6lNEjoo2lltRj02s /1mn/ybyANx+GP7UOJ3yxdwaSp4M8CPKczEYaySdR3muS8h+9+YHvr9csKgB4xp1Ux+CgC pHQHknO/LQWV6uYpL/ZaVjZizjMdgEI= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-436-XUrUIViRNma4rOu4XttNDQ-1; Fri, 24 Jan 2025 04:46:10 -0500 X-MC-Unique: XUrUIViRNma4rOu4XttNDQ-1 X-Mimecast-MFC-AGG-ID: XUrUIViRNma4rOu4XttNDQ Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385e49efd59so808608f8f.0 for ; Fri, 24 Jan 2025 01:46:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711968; x=1738316768; 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=RIbFHI36QG2C9ttEM2sSjSaRWtytsQRJX6tP+6nmQnM=; b=GmjHVNRzzAES5OT6mUHdHrBhUhODQFhP2IXuPQrbCFDeZED26ctdqJjaBrTappJU+X nqnSknaXyzYnGr6RpdRomI6vEORA8dpQhy2+x67RbnuGWc2qwxtsqI6ZFFkcjoLJHnf9 y7OGvA9qyEi1A8nm55Q0sYkYBHTPLikyKt0aoBaYTM+81HXrt9HkVRh3V85of2FowF4l hTJkt6tEyOD3/6lz3bQtZgCOD3pHzqi+A4lvtroisWohJsshTj/Kb3QT+pkFOU+axYdX 7E3K8H0vVUoGLocwiCfXaHftlPXK/vVOxWNqxvXRTQzKbp64WyNfysEBO/pCVg39ZEu0 gnxg== X-Gm-Message-State: AOJu0YwOC9zfGUb6w8WR5t+jCaOhzSGUk7URTz+jLi97PIJp6qTjkGpq 32fBbEnV9pR2uUq/Ml8vSqArnGenJQNeXxbhFEegjjO13NNgHXfdO1hJAFekCYliYGb495oxIgq PGg3t5trp4lL69O8taU923me2uo9rw+9UYHJY6ZTOZUSQvJP5hZ7sIBhmb8lPIHTTLFjzxhVcbH UgTX53kmwSa4F74q2ElKLm19Qaou+Nlh3uz9/ey/Q= X-Gm-Gg: ASbGncuHDO36S3Zt3b+YGZYt2OmeGUL+FGjUkUcY5GJuO1DfZzg/lFkMCxuVZ8rfXZm 8ud5cjlMhD6rSFAsnBsjxbbPHhTshU54kL4SyPzL2S0FJHXynSXxDm1EbHID+iXd3CZ8/ihu0OJ 0XwDXA4RUjgneomjctzns1m6ePBP8+/NYgIUkvqqnr7eRGkkYix9RT8HNwst9vVTTpFlPYzKn0j K+CLBj2O9Q8PO9wpKqSK6mE36Wx0fHhlFCcK60cEUfLCJdYWWTERK+iTjb2pMYrmymuOnUVKA== X-Received: by 2002:a5d:6c6f:0:b0:385:ee40:2d88 with SMTP id ffacd0b85a97d-38bf566e691mr27462728f8f.3.1737711968358; Fri, 24 Jan 2025 01:46:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPNxy+OyRzyAB3/p4Oq+OobI7lrZ1tlL1bYR8U0nTmz3643KHcYb0uKaQk3zX7iwXm2puZ2Q== X-Received: by 2002:a5d:6c6f:0:b0:385:ee40:2d88 with SMTP id ffacd0b85a97d-38bf566e691mr27462692f8f.3.1737711967869; Fri, 24 Jan 2025 01:46:07 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a17662bsm2173007f8f.4.2025.01.24.01.46.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 43/48] rust: pl011: remove duplicate definitions Date: Fri, 24 Jan 2025 10:44:37 +0100 Message-ID: <20250124094442.13207-44-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Unify the "Interrupt" enum and the "INT_*" constants with a struct that contains the bits. The "int_level" and "int_enabled" fields could use a crate such as "bitflags". Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 32 ++++++++++------------ rust/hw/char/pl011/src/lib.rs | 46 +++++++++++--------------------- 2 files changed, 29 insertions(+), 49 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 4fd9bdc8584..eab3cf96f4c 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -191,7 +191,7 @@ pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow { self.flags.set_receive_fifo_empty(true); } if self.read_count + 1 == self.read_trigger { - self.int_level &= !registers::INT_RX; + self.int_level &= !Interrupt::RX.0; } // Update error bits. self.receive_status_error_clear.set_from_data(c); @@ -240,7 +240,7 @@ pub(self) fn write( } // interrupts always checked let _ = self.loopback_tx(value); - self.int_level |= registers::INT_TX; + self.int_level |= Interrupt::TX.0; return true; } RSR => { @@ -364,19 +364,19 @@ fn loopback_mdmctrl(&mut self) -> bool { // Change interrupts based on updated FR let mut il = self.int_level; - il &= !Interrupt::MS; + il &= !Interrupt::MS.0; if self.flags.data_set_ready() { - il |= Interrupt::DSR as u32; + il |= Interrupt::DSR.0; } if self.flags.data_carrier_detect() { - il |= Interrupt::DCD as u32; + il |= Interrupt::DCD.0; } if self.flags.clear_to_send() { - il |= Interrupt::CTS as u32; + il |= Interrupt::CTS.0; } if self.flags.ring_indicator() { - il |= Interrupt::RI as u32; + il |= Interrupt::RI.0; } self.int_level = il; true @@ -454,7 +454,7 @@ pub fn put_fifo(&mut self, value: u32) -> bool { } if self.read_count == self.read_trigger { - self.int_level |= registers::INT_RX; + self.int_level |= Interrupt::RX.0; return true; } false @@ -641,16 +641,12 @@ pub fn post_load(&self, _version_id: u32) -> Result<(), ()> { /// Which bits in the interrupt status matter for each outbound IRQ line ? const IRQMASK: [u32; 6] = [ /* combined IRQ */ - Interrupt::E - | Interrupt::MS - | Interrupt::RT as u32 - | Interrupt::TX as u32 - | Interrupt::RX as u32, - Interrupt::RX as u32, - Interrupt::TX as u32, - Interrupt::RT as u32, - Interrupt::MS, - Interrupt::E, + Interrupt::E.0 | Interrupt::MS.0 | Interrupt::RT.0 | Interrupt::TX.0 | Interrupt::RX.0, + Interrupt::RX.0, + Interrupt::TX.0, + Interrupt::RT.0, + Interrupt::MS.0, + Interrupt::E.0, ]; /// # Safety diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index 2baacba2306..300c732ae1d 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -100,7 +100,6 @@ enum RegisterOffset { //Reserved = 0x04C, } -#[allow(dead_code)] mod registers { //! Device registers exposed as typed structs which are backed by arbitrary //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. @@ -521,38 +520,23 @@ fn default() -> Self { } /// Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC - pub const INT_OE: u32 = 1 << 10; - pub const INT_BE: u32 = 1 << 9; - pub const INT_PE: u32 = 1 << 8; - pub const INT_FE: u32 = 1 << 7; - pub const INT_RT: u32 = 1 << 6; - pub const INT_TX: u32 = 1 << 5; - pub const INT_RX: u32 = 1 << 4; - pub const INT_DSR: u32 = 1 << 3; - pub const INT_DCD: u32 = 1 << 2; - pub const INT_CTS: u32 = 1 << 1; - pub const INT_RI: u32 = 1 << 0; - pub const INT_E: u32 = INT_OE | INT_BE | INT_PE | INT_FE; - pub const INT_MS: u32 = INT_RI | INT_DSR | INT_DCD | INT_CTS; - - #[repr(u32)] - pub enum Interrupt { - OE = 1 << 10, - BE = 1 << 9, - PE = 1 << 8, - FE = 1 << 7, - RT = 1 << 6, - TX = 1 << 5, - RX = 1 << 4, - DSR = 1 << 3, - DCD = 1 << 2, - CTS = 1 << 1, - RI = 1 << 0, - } + pub struct Interrupt(pub u32); impl Interrupt { - pub const E: u32 = INT_OE | INT_BE | INT_PE | INT_FE; - pub const MS: u32 = INT_RI | INT_DSR | INT_DCD | INT_CTS; + pub const OE: Self = Self(1 << 10); + pub const BE: Self = Self(1 << 9); + pub const PE: Self = Self(1 << 8); + pub const FE: Self = Self(1 << 7); + pub const RT: Self = Self(1 << 6); + pub const TX: Self = Self(1 << 5); + pub const RX: Self = Self(1 << 4); + pub const DSR: Self = Self(1 << 3); + pub const DCD: Self = Self(1 << 2); + pub const CTS: Self = Self(1 << 1); + pub const RI: Self = Self(1 << 0); + + pub const E: Self = Self(Self::OE.0 | Self::BE.0 | Self::PE.0 | Self::FE.0); + pub const MS: Self = Self(Self::RI.0 | Self::DSR.0 | Self::DCD.0 | Self::CTS.0); } } From patchwork Fri Jan 24 09:44: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: 13949195 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 66E65C0218C for ; Fri, 24 Jan 2025 09:50:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGIw-0007rz-0d; Fri, 24 Jan 2025 04:48:46 -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 1tbGGV-0007rW-EI for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:20 -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 1tbGGT-000409-Qy for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711973; 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=QamUuDsh3u1zhv5UP9v4AP13NvSKrprRowPTkNfQPV0=; b=VlhFFw7m1uVm/fya4VVj60NamK94Ubt0J1RAPnfypbnDKnNNFNg7y0oscraMShUMb12F7Y ZPiuR3v5/QjvNPSQgl7+wPCV6U/OiG1q3uTWqaQcFTlsY3dToGZ6bdt16rLY3mluKrutbK iHSIpFVzZXXHHDu0z6jg8/1ztyOF0SY= 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-682-6s9kZ87_OneDVFzvECI24A-1; Fri, 24 Jan 2025 04:46:11 -0500 X-MC-Unique: 6s9kZ87_OneDVFzvECI24A-1 X-Mimecast-MFC-AGG-ID: 6s9kZ87_OneDVFzvECI24A Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385e3cbf308so742567f8f.2 for ; Fri, 24 Jan 2025 01:46:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711969; x=1738316769; 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=QamUuDsh3u1zhv5UP9v4AP13NvSKrprRowPTkNfQPV0=; b=wVgaAMUXgg+En/GP5CvbepSuy6Y+QXkcvLjaUeVDQFgenq3ryjfYZaxzn2WxC42uaK +FON4h2pr4gLt5lu+DgEaJ6TUVhmS+0TK5JP/NbnDWV5TTSrVRnGZDZD4TE7iabSHAcL 2jJ8AwPKHsuQBUuvwUaZ9Ooy1Fp4+ru/q0BJuHuGyIBMiMeavCF7tgrVVi4q49uEdpnq 3KKAoHbwXMcEtAlE00WQOKNep6r4wgCU9yhJ9sMw3mUs09XWeftrs8ig0/DfFDSeTGLI Q8PBZ8OdfAwzh+WN/wDP9hjhSso0H8f024eL32b3zU4EkY098wCkdeBHSNa6U7NjmkdI rC6g== X-Gm-Message-State: AOJu0YwGCHCYJjZRh5BPPCiaQIqXcaXdkXRbQ8uhGoYJGNCKGNwVuXGn 7sIOfh6+GBdyMB0MvJ7WnpZGj5BLfKn9v31/lrEz/+sBnR9LJCk4Pttq74xP5lxH9AGAps1jPcL wrjl01NkP9i2D8hC1LYMUMpq5dxOEMJ3hPv3mmwj/IRczhk94/K5PcSBushP1VrppXUE7WavJAX d5GLjiPCG5+kd3CJFWZiB9+qlxJN22gov7RJyLIN8= X-Gm-Gg: ASbGnctTReR2o3+BDPvL76d5cZ8kmDasGg+bcxlAU1oNPul1sRLXdOPwpFovK0mcs9n 2wnLorjjwfuTGIoGv+KCXGBsLcY/qHCV94OD9WNMojkq9IQL2XYdcHFRt2Dzo3RQnDiapTjZOvI l+KDXqLYVip+vDUUJ6X5mJ5U6DLrhk+gULLaynf82OYMgwvpm/skfIrgvP+eaA1AOFK+iRPZ4vX WHJb15Y67Xs8b2XWmSbTugOB1gTXrcgB50jYLZUjE8KCQEuGDMz+s/irT8FuygoYyJ/K7Ynlw== X-Received: by 2002:a5d:6481:0:b0:38c:246f:b0b3 with SMTP id ffacd0b85a97d-38c246fb2bcmr6845003f8f.51.1737711969545; Fri, 24 Jan 2025 01:46:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlslvanWOXciNRbMHt3LyBstsOQVcKdcoxXMR33PJ8oXh4eTK0zDAuRCx9LMuAbPsCnCR5nw== X-Received: by 2002:a5d:6481:0:b0:38c:246f:b0b3 with SMTP id ffacd0b85a97d-38c246fb2bcmr6844949f8f.51.1737711969017; Fri, 24 Jan 2025 01:46:09 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a188928sm2151701f8f.45.2025.01.24.01.46.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:08 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 44/48] rust: pl011: pull device-specific code out of MemoryRegionOps callbacks Date: Fri, 24 Jan 2025 10:44:38 +0100 Message-ID: <20250124094442.13207-45-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 read() can now return a simple u64. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 23 +++++++++++++---------- rust/hw/char/pl011/src/memory_ops.rs | 18 ++---------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index eab3cf96f4c..9a0ba87aa5b 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -12,9 +12,10 @@ use qemu_api::{ bindings::{ error_fatal, hwaddr, memory_region_init_io, qdev_init_clock_in, qdev_new, - qdev_prop_set_chr, qemu_chr_fe_ioctl, qemu_chr_fe_set_handlers, qemu_chr_fe_write_all, - qemu_irq, sysbus_connect_irq, sysbus_mmio_map, sysbus_realize_and_unref, CharBackend, - Chardev, Clock, ClockEvent, MemoryRegion, QEMUChrEvent, CHR_IOCTL_SERIAL_SET_BREAK, + qdev_prop_set_chr, qemu_chr_fe_accept_input, qemu_chr_fe_ioctl, qemu_chr_fe_set_handlers, + qemu_chr_fe_write_all, qemu_irq, sysbus_connect_irq, sysbus_mmio_map, + sysbus_realize_and_unref, CharBackend, Chardev, Clock, ClockEvent, MemoryRegion, + QEMUChrEvent, CHR_IOCTL_SERIAL_SET_BREAK, }, c_str, impl_vmstate_forward, irq::InterruptSource, @@ -538,30 +539,32 @@ fn post_init(&self) { } } - #[allow(clippy::needless_pass_by_ref_mut)] - pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { + pub fn read(&mut self, offset: hwaddr, _size: u32) -> u64 { let mut update_irq = false; let result = match RegisterOffset::try_from(offset) { Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => { let device_id = self.get_class().device_id; - ControlFlow::Break(u64::from(device_id[(offset - 0xfe0) >> 2])) + u32::from(device_id[(offset - 0xfe0) >> 2]) } Err(_) => { // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); - ControlFlow::Break(0) + 0 } Ok(field) => match self.regs.borrow_mut().read(field) { - ControlFlow::Break(value) => ControlFlow::Break(value.into()), + ControlFlow::Break(value) => value, ControlFlow::Continue(value) => { update_irq = true; - ControlFlow::Continue(value.into()) + value } }, }; if update_irq { self.update(); + unsafe { + qemu_chr_fe_accept_input(&mut self.char_backend); + } } - result + result.into() } pub fn write(&mut self, offset: hwaddr, value: u64) { diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index a286003d136..432d3263898 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -24,25 +24,11 @@ }; unsafe extern "C" fn pl011_read(opaque: *mut c_void, addr: hwaddr, size: c_uint) -> u64 { - assert!(!opaque.is_null()); let mut state = NonNull::new(opaque).unwrap().cast::(); - let val = unsafe { state.as_mut().read(addr, size) }; - match val { - std::ops::ControlFlow::Break(val) => val, - std::ops::ControlFlow::Continue(val) => { - // SAFETY: self.char_backend is a valid CharBackend instance after it's been - // initialized in realize(). - let cb_ptr = unsafe { core::ptr::addr_of_mut!(state.as_mut().char_backend) }; - unsafe { - qemu_chr_fe_accept_input(cb_ptr); - } - - val - } - } + unsafe { state.as_mut() }.read(addr, size) } unsafe extern "C" fn pl011_write(opaque: *mut c_void, addr: hwaddr, data: u64, _size: c_uint) { let mut state = NonNull::new(opaque).unwrap().cast::(); - unsafe { state.as_mut().write(addr, data) } + unsafe { state.as_mut() }.write(addr, data); } From patchwork Fri Jan 24 09:44: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: 13949196 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 14215C02181 for ; Fri, 24 Jan 2025 09:50:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHm-0002hs-He; Fri, 24 Jan 2025 04:47: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 1tbGGX-0007t1-JY for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:26 -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 1tbGGV-00040T-Rx for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711975; 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=HGlACdH/EqIXZ5fV9dpl3biokpD3XWX5J53CWbCvliw=; b=NCkE00l3R2WITQykv2GI6cpC4Pgq4JMHibAx1JpEwgNTEyupLjnwseD4kn0hvU3ihdTNed 6xspbYhA73Nxz7v2yxdItq/eCwQRgI8ev32dRRjeL7+ijByofpeNsCJR9386u6Cx78aanD CULudY+qHkyGZQSDCRy5CuoLUp3xk64= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-58-MbdS2my0On6j8WlUXLUTcQ-1; Fri, 24 Jan 2025 04:46:13 -0500 X-MC-Unique: MbdS2my0On6j8WlUXLUTcQ-1 X-Mimecast-MFC-AGG-ID: MbdS2my0On6j8WlUXLUTcQ Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-386333ea577so722964f8f.1 for ; Fri, 24 Jan 2025 01:46:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711971; x=1738316771; 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=HGlACdH/EqIXZ5fV9dpl3biokpD3XWX5J53CWbCvliw=; b=nkdfLgPU/P6VY0MEW2XvFbmmtluBjyvaPj50xXiW1kYdzC57S/3u5rmPeyKn6fT5Md 9JRvfTmEKAu4i/eJIgP4zDaX2VcG+jwE3bySKmsWG933JypOrRlrkY3FvfzDV9SlGyu8 CfOpRW8uQRWwWKSee3QaFE2+qskOr1deQgWGeAndXUeyJiON7AEwHXYQnZo9D2ICav5+ io2exoa0LAUjAEXhQZcQd2fDSBdEuhI3rxXLLTaiWw0DE5yeztM0AErEXKHYCQzOo3oT nlBurrUlvnayfvih/i6SI2Eb/fTSDIswQXfMl7M1ad7V/vrvpUguTLkCSBC4O+9h0pSt OW9w== X-Gm-Message-State: AOJu0YxB9uyx1jiZvYkp7Tx1dkXBdsMHig4/pGQhrGSkTf8AYKKsoWgm dhWSq6GyMO1YC7zaB2B7hB2pqezd+jAf2jNMlbywoKEoTh3zEzLHAbL04N0iUX9F50KIG/+eQuc KV4oWUduExE4VylVKKSOV8zCRk0HE/3kFFJRdrLNbe3i6RoBP7niT7yBV9ulwk+ar6PANtkJ99v VK/oDnd3E47T3qXHJREM1G752hDjHX2wEhysMTxgg= X-Gm-Gg: ASbGncuVQFy1sFJkRXx+Ht4R9iz3+bwEVg/NSJDCQKtzBNIwBc1o0+JM6UQvbJj4s1u Wr5GChAEcRVh6uW/7wchogl/h0BGfID5i6Nt6KE5bmwKN5F+iA6452H/bRWZx+fNF3ToxEggrji zP1RZG1bM4bVENmxHLdaxbwhBo55Vjb9kKWE9fLG9uuFv9M6tlltSO9KXwRaVWYPmgGRKNvArsx BzeC18DNnYmVVF55/UxeiORhXotM5gDqNY83nXBhR2+9cN46x24zTjYGs9gX/jRAdKMfoSI2w== X-Received: by 2002:a5d:6d86:0:b0:385:e38f:8cc with SMTP id ffacd0b85a97d-38bf59e1e56mr35368799f8f.38.1737711971514; Fri, 24 Jan 2025 01:46:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IESvIu5c2mJcLqK4Exh1VbSoR5Anib++QtMt0Ybw2FTzn3FrrYZlE4rGqbGbQujEvrzcRlJkQ== X-Received: by 2002:a5d:6d86:0:b0:385:e38f:8cc with SMTP id ffacd0b85a97d-38bf59e1e56mr35368768f8f.38.1737711971051; Fri, 24 Jan 2025 01:46:11 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1bb062sm2151664f8f.71.2025.01.24.01.46.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:09 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 45/48] rust: pl011: drop use of ControlFlow Date: Fri, 24 Jan 2025 10:44:39 +0100 Message-ID: <20250124094442.13207-46-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 poor match for what the code is doing, anyway. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 39 +++++++++++++++----------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 9a0ba87aa5b..e916ea11884 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -5,7 +5,6 @@ use core::ptr::{addr_of, addr_of_mut, NonNull}; use std::{ ffi::CStr, - ops::ControlFlow, os::raw::{c_int, c_void}, }; @@ -177,10 +176,11 @@ fn vmsd() -> Option<&'static VMStateDescription> { } impl PL011Registers { - pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow { + pub(self) fn read(&mut self, offset: RegisterOffset) -> (bool, u32) { use RegisterOffset::*; - ControlFlow::Break(match offset { + let mut update = false; + let result = match offset { DR => { self.flags.set_receive_fifo_full(false); let c = self.read_fifo[self.read_pos]; @@ -196,8 +196,9 @@ pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow { } // Update error bits. self.receive_status_error_clear.set_from_data(c); - // Must call qemu_chr_fe_accept_input, so return Continue: - return ControlFlow::Continue(u32::from(c)); + // Must call qemu_chr_fe_accept_input + update = true; + u32::from(c) } RSR => u32::from(self.receive_status_error_clear), FR => u32::from(self.flags), @@ -216,7 +217,8 @@ pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow { 0 } DMACR => self.dmacr, - }) + }; + (update, result) } pub(self) fn write( @@ -540,31 +542,26 @@ fn post_init(&self) { } pub fn read(&mut self, offset: hwaddr, _size: u32) -> u64 { - let mut update_irq = false; - let result = match RegisterOffset::try_from(offset) { + match RegisterOffset::try_from(offset) { Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => { let device_id = self.get_class().device_id; - u32::from(device_id[(offset - 0xfe0) >> 2]) + u64::from(device_id[(offset - 0xfe0) >> 2]) } Err(_) => { // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); 0 } - Ok(field) => match self.regs.borrow_mut().read(field) { - ControlFlow::Break(value) => value, - ControlFlow::Continue(value) => { - update_irq = true; - value + Ok(field) => { + let (update_irq, result) = self.regs.borrow_mut().read(field); + if update_irq { + self.update(); + unsafe { + qemu_chr_fe_accept_input(&mut self.char_backend); + } } - }, - }; - if update_irq { - self.update(); - unsafe { - qemu_chr_fe_accept_input(&mut self.char_backend); + result.into() } } - result.into() } pub fn write(&mut self, offset: hwaddr, value: u64) { From patchwork Fri Jan 24 09:44: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: 13949200 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 AB3C4C02181 for ; Fri, 24 Jan 2025 09:51:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGJ1-0008F6-Ge; Fri, 24 Jan 2025 04:48:52 -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 1tbGGa-0007tu-4c for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:26 -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 1tbGGX-00040f-6j for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711976; 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=jllJCe45+on6RBQLoaPv4sZe3uCPs/UzG77MtZEZeWI=; b=VBnlwWP4hri/atmw59ZS3v+OaKgoBJ8+pNrLVjVYRsW4BNo1G+UoHhcCpX5EWWPsdaqwpg Clh8KJ26KZLIY9iGV1KTGrsPJcWgTrB3IioPvTotYW5uO6nSPgcKM9oD0YYGzPo99jcpTY EFBZr4W/dnD6l8fzl2Bn7oC0YzDHfoE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-54-yGL0HQ7WNnab4xqo0HsLGg-1; Fri, 24 Jan 2025 04:46:14 -0500 X-MC-Unique: yGL0HQ7WNnab4xqo0HsLGg-1 X-Mimecast-MFC-AGG-ID: yGL0HQ7WNnab4xqo0HsLGg Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4362f893bfaso10182205e9.1 for ; Fri, 24 Jan 2025 01:46:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711973; x=1738316773; 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=jllJCe45+on6RBQLoaPv4sZe3uCPs/UzG77MtZEZeWI=; b=uuOgkFKSgQoC6exybUXY5c+SACe6ERp+94nnSAKuhpSUvJ5oCZBDNQc3eqkL1G4t6k Ib+rpCkXtThokBbdBlY65ZAsn27XBVIWxznZEQ8eA/AKHnqJT29lminlz5sPpiIiqQxa WIydm7VnXS0e4jNyIu+HHLAphCMi4wTN2Bq3uoXiKjkidnjgmIMTX8y7u3y0W3w9bl0u suM9SUBzeREDUh017fTrds5110/dEQJoNzq5pIsY8XXWBGk64sGiU23VJovxypGOMAAo Iryu6HYh5Wq9fTMpHrZHkXXXArIJmolLAmFaOy02gqtcKaTLWloR0qRh7JO6RATa4qUV wyug== X-Gm-Message-State: AOJu0YwUotcvn3TdSwdD98hjKvtKTHqfTvN05pXGrFbtqXz6T7zbX+mY RBYMCk4mqNkYrv6QMJSCJvrG+iAyGbJANAVtBtNjl5A0T0iTS8EdR1Sh7qrqMVW/tAhL9mhBMpV VbHyxLaaQQsM9/8Xo+fEM8sVlu1z/Cg9Nt8Ft9o24TOOE+axxlPE60I/B2Xq+a8XtgcPoQVgMGU EuqbBolxHoRasHRzBkHvsD+Z9WpPl19Inyj0Selms= X-Gm-Gg: ASbGnctF3Pwpd3AvlCSGEB5qmLpjTkNAMHgk4yeIfTAKR2RUSIV2AqpxGPIz40MvZ9N q35aUnINFQpy2K9U7wfm97+MrAq0xjEbhByUHD7qVQnKpslPlhKJLIrN5V2FmUoToiWsWuZBc7v I2wmqXaOuUnUNuWHWa+gQt9TUyBVkU9W5sjzDBAkHamcxXc/yZZwB+TY4aMkQVUCeZb12IlrvkG Qo7Kvw/ihN+hIJ6JCRSyMbWGFFjHWeMRhK5OP+T5hFf/XKr6Dl6KnoDyeMdvLdI6/xYNMVX4Q== X-Received: by 2002:a05:600c:1f86:b0:436:aaf:7eb9 with SMTP id 5b1f17b1804b1-43891439d5fmr243292135e9.20.1737711973212; Fri, 24 Jan 2025 01:46:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEn+6TE64XAJLPxZqRdqCYfhcGLvWfGj3Qbgx41WEvAuIx6sHzQULVETYsTgAD3O+Z9BSxNDg== X-Received: by 2002:a05:600c:1f86:b0:436:aaf:7eb9 with SMTP id 5b1f17b1804b1-43891439d5fmr243291955e9.20.1737711972713; Fri, 24 Jan 2025 01:46:12 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd48ae29sm20961865e9.22.2025.01.24.01.46.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 46/48] rust: qdev: make reset take a shared reference Date: Fri, 24 Jan 2025 10:44:40 +0100 Message-ID: <20250124094442.13207-47-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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 Because register reset is within a borrow_mut() call, reset does not need anymore a mut reference to the PL011State. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 4 ++-- rust/qemu-api/src/qdev.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index e916ea11884..fad190a9133 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -172,7 +172,7 @@ fn vmsd() -> Option<&'static VMStateDescription> { Some(&device_class::VMSTATE_PL011) } const REALIZE: Option = Some(Self::realize); - const RESET: Option = Some(Self::reset); + const RESET: Option = Some(Self::reset); } impl PL011Registers { @@ -621,7 +621,7 @@ pub fn realize(&self) { } } - pub fn reset(&mut self) { + pub fn reset(&self) { self.regs.borrow_mut().reset(); } diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs index 42429903aae..f4c75c752f1 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/qemu-api/src/qdev.rs @@ -30,7 +30,7 @@ pub trait DeviceImpl { /// /// Rust does not yet support the three-phase reset protocol; this is /// usually okay for leaf classes. - const RESET: Option = None; + const RESET: Option = None; /// An array providing the properties that the user can set on the /// device. Not a `const` because referencing statics in constants From patchwork Fri Jan 24 09:44: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: 13949177 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 A21F5C02181 for ; Fri, 24 Jan 2025 09:48:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGI8-00054K-2Z; Fri, 24 Jan 2025 04:47: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 1tbGGe-0007zG-P4 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46: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 1tbGGa-00040y-Rm for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711978; 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=ohg5OnpD+mvfyDVr/6jK+jcwElKVKW8I4Rdj5udNnOk=; b=APs502RdPcG17vG6RB2hBKrcWiTg925bT1/SBKQKoWnNS9Z/TwpkUQ7k8UQpGXKr4OT/jl Sdzeq7oaxp6ZFYe2K+kft+dF5ZsKCF0E1JHJikvR20QXE95iirt5EjieqE34/KZNWL7JMh wS8Rb38Pp/0yzS7YOAtryBLXpXaCDwE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-551-1TY6_MnGMGO3TiZCOz3-lQ-1; Fri, 24 Jan 2025 04:46:17 -0500 X-MC-Unique: 1TY6_MnGMGO3TiZCOz3-lQ-1 X-Mimecast-MFC-AGG-ID: 1TY6_MnGMGO3TiZCOz3-lQ Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4388eee7073so14701225e9.0 for ; Fri, 24 Jan 2025 01:46:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711975; x=1738316775; 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=ohg5OnpD+mvfyDVr/6jK+jcwElKVKW8I4Rdj5udNnOk=; b=duU227zRShnw0QtBqaXdn9hKo+l/OiKL+jDoHBwy6G0PQeQ2AVu9ETrmRgePpA1PI0 +chmddtb7+Xc9aDBajEuQuhgOckWVcn3ii1t3QK1FxPthgXs27brwf9nhpmY6Hl6Hfc3 Mc/9B3e1BpPwRRKSo1Lt1gW7wOPsNF1OjEp/FItsQXnh56Nt3uu1cWByf61Ut7MUXdgf 7FIsDzMKja+Lnu+N2Go4Go8DsyvbZHjAGDM4rrSi96S0bGuItb/EC6iI7Q0v8RQi4iYR L7m3/FGlpqXIdrECsRAJKftzvulYhPcM2JoNOH9aels8/Fb1A7fIuPsrnPZozWUACp6s plcQ== X-Gm-Message-State: AOJu0YwuBVTyfKp8BxNKXeDPdbki1U2D8WcENafDQObaG2adGZyT12C2 4SyC6XyJLMvyhDd5wdnoYcguGQqZi/J7yGpFABp3PIR1WkdKVCR27itZLb5A0WUKY1gQE7tQwS/ xLOuvq227z5zfQJL4IW9DCMLVWSbESDZGnRWFcTN1h3n9Ap7yMiXA1iLk4UUV9IvaV4AI86X381 lEH5vgJkRdOB39W7h4oLiArtx73sOQMnobXlmYyMc= X-Gm-Gg: ASbGnctqEdd6Yg2eMuJnvAY8ZXyqZGgjbJhz2biMa915pvb3WVgW/UAZaNuMP+blo6y 7MOfA1YdVBiwuFwQ+G5yDXhCx07PnaSeGT1sQY7nXb1qqHe/Qv1Z9YNdNH8ZOQkHSdvX6m0bbwb ps9t+zqngAVUAjVqMaebl73U2EuTwvT3XQ3sGBk/SmulGapzY2kzjYSs+V2FygHHnpN75NOt9t4 CUORS9kRMZokPuTFkzMzuJ3cD1+WflC8vXPyYu2VNdBfaIqF/j2CWZlZqHyD5YTsKXLEzl4mQ== X-Received: by 2002:a05:600c:21d8:b0:434:ea1a:e30c with SMTP id 5b1f17b1804b1-438bd0bca9amr24646095e9.13.1737711975457; Fri, 24 Jan 2025 01:46:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaQMD872HSJ7oNUvzxx8TYuhffIXBnNk59r9n2YzNcPiSCU2DDk5UQ9CQsTnsFL1XSLQIFAQ== X-Received: by 2002:a05:600c:21d8:b0:434:ea1a:e30c with SMTP id 5b1f17b1804b1-438bd0bca9amr24645785e9.13.1737711975028; Fri, 24 Jan 2025 01:46:15 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd501721sm19993645e9.9.2025.01.24.01.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:14 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 47/48] rust/zeroable: Implement Zeroable with const_zero macro Date: Fri, 24 Jan 2025 10:44:41 +0100 Message-ID: <20250124094442.13207-48-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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 The `const_zero` crate provides a nice macro to zero type-specific constants, which doesn't need to enumerates the fields one by one. Introduce the `const_zero` macro to QEMU (along with its documentation), and use it to simplify the implementation of `Zeroable` trait. Suggested-by: Paolo Bonzini Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250123163143.679841-1-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/zeroable.rs | 137 +++++++++++++++------------------- 1 file changed, 61 insertions(+), 76 deletions(-) diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs index 57cac96de06..7b04947cb6c 100644 --- a/rust/qemu-api/src/zeroable.rs +++ b/rust/qemu-api/src/zeroable.rs @@ -1,13 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later -use std::ptr; - /// Encapsulates the requirement that /// `MaybeUninit::::zeroed().assume_init()` does not cause undefined /// behavior. This trait in principle could be implemented as just: /// /// ``` -/// pub unsafe trait Zeroable: Default { +/// pub unsafe trait Zeroable { /// const ZERO: Self = unsafe { ::core::mem::MaybeUninit::::zeroed().assume_init() }; /// } /// ``` @@ -29,23 +27,61 @@ pub unsafe trait Zeroable: Default { const ZERO: Self; } -unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 { - const ZERO: Self = Self { i: 0 }; +/// A macro that acts similarly to [`core::mem::zeroed()`], only is const +/// +/// ## Safety +/// +/// Similar to `core::mem::zeroed()`, except this zeroes padding bits. Zeroed +/// padding usually isn't relevant to safety, but might be if a C union is used. +/// +/// Just like for `core::mem::zeroed()`, an all zero byte pattern might not +/// be a valid value for a type, as is the case for references `&T` and `&mut +/// T`. Reference types trigger a (denied by default) lint and cause immediate +/// undefined behavior if the lint is ignored +/// +/// ```rust compile_fail +/// use const_zero::const_zero; +/// // error: any use of this value will cause an error +/// // note: `#[deny(const_err)]` on by default +/// const STR: &str = unsafe{const_zero!(&'static str)}; +/// ``` +/// +/// `const_zero` does not work on unsized types: +/// +/// ```rust compile_fail +/// use const_zero::const_zero; +/// // error[E0277]: the size for values of type `[u8]` cannot be known at compilation time +/// const BYTES: [u8] = unsafe{const_zero!([u8])}; +/// ``` +/// ## Differences with `core::mem::zeroed` +/// +/// `const_zero` zeroes padding bits, while `core::mem::zeroed` doesn't +macro_rules! const_zero { + // This macro to produce a type-generic zero constant is taken from the + // const_zero crate (v0.1.1): + // + // https://docs.rs/const-zero/latest/src/const_zero/lib.rs.html + // + // and used under MIT license + ($type_:ty) => {{ + const TYPE_SIZE: ::core::primitive::usize = ::core::mem::size_of::<$type_>(); + union TypeAsBytes { + bytes: [::core::primitive::u8; TYPE_SIZE], + inner: ::core::mem::ManuallyDrop<$type_>, + } + const ZERO_BYTES: TypeAsBytes = TypeAsBytes { + bytes: [0; TYPE_SIZE], + }; + ::core::mem::ManuallyDrop::<$type_>::into_inner(ZERO_BYTES.inner) + }}; } -unsafe impl Zeroable for crate::bindings::Property { - const ZERO: Self = Self { - name: ptr::null(), - info: ptr::null(), - offset: 0, - bitnr: 0, - bitmask: 0, - set_default: false, - defval: Zeroable::ZERO, - arrayoffset: 0, - arrayinfo: ptr::null(), - arrayfieldsize: 0, - link_type: ptr::null(), +/// A wrapper to implement the `Zeroable` trait through the `const_zero` macro. +macro_rules! impl_zeroable { + ($type:ty) => { + unsafe impl Zeroable for $type { + const ZERO: Self = unsafe { const_zero!($type) }; + } }; } @@ -57,61 +93,10 @@ fn default() -> Self { } } -unsafe impl Zeroable for crate::bindings::VMStateFlags { - const ZERO: Self = Self(0); -} - -unsafe impl Zeroable for crate::bindings::VMStateField { - const ZERO: Self = Self { - name: ptr::null(), - err_hint: ptr::null(), - offset: 0, - size: 0, - start: 0, - num: 0, - num_offset: 0, - size_offset: 0, - info: ptr::null(), - flags: Zeroable::ZERO, - vmsd: ptr::null(), - version_id: 0, - struct_version_id: 0, - field_exists: None, - }; -} - -unsafe impl Zeroable for crate::bindings::VMStateDescription { - const ZERO: Self = Self { - name: ptr::null(), - unmigratable: false, - early_setup: false, - version_id: 0, - minimum_version_id: 0, - priority: crate::bindings::MigrationPriority::MIG_PRI_DEFAULT, - pre_load: None, - post_load: None, - pre_save: None, - post_save: None, - needed: None, - dev_unplug_pending: None, - fields: ptr::null(), - subsections: ptr::null(), - }; -} - -unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 { - const ZERO: Self = Self { - min_access_size: 0, - max_access_size: 0, - unaligned: false, - accepts: None, - }; -} - -unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 { - const ZERO: Self = Self { - min_access_size: 0, - max_access_size: 0, - unaligned: false, - }; -} +impl_zeroable!(crate::bindings::Property__bindgen_ty_1); +impl_zeroable!(crate::bindings::Property); +impl_zeroable!(crate::bindings::VMStateFlags); +impl_zeroable!(crate::bindings::VMStateField); +impl_zeroable!(crate::bindings::VMStateDescription); +impl_zeroable!(crate::bindings::MemoryRegionOps__bindgen_ty_1); +impl_zeroable!(crate::bindings::MemoryRegionOps__bindgen_ty_2); From patchwork Fri Jan 24 09:44: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: 13949182 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 B8C95C02181 for ; Fri, 24 Jan 2025 09:49:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGI1-0004CQ-Ld; Fri, 24 Jan 2025 04:47:49 -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 1tbGGg-0007zR-KE for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:29 -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 1tbGGd-00041C-Uo for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711982; 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=ESHgSiSE1123xBuo1J97jzh2hkYZ9bH4zzgarY8aj/g=; b=J0vp8NswnYE6y24YDk5e5tObur0uyv12oQxmKZ2mAduZVtonBO6QIUeSReeTnHnQ6o7qNA Mtc/1W1G9MsY9ZqdRCW5ohc2THQxN+ahwLhUHN4A2xu+clV4kwFA7QZJEi+dCol7me3XcL B+0ZMd2/q+ezUBCoKZgncnwucAHLXmI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-224-lNUoovw2PC66eTwTR1i3EQ-1; Fri, 24 Jan 2025 04:46:20 -0500 X-MC-Unique: lNUoovw2PC66eTwTR1i3EQ-1 X-Mimecast-MFC-AGG-ID: lNUoovw2PC66eTwTR1i3EQ Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4362153dcd6so9086415e9.2 for ; Fri, 24 Jan 2025 01:46:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711978; x=1738316778; 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=ESHgSiSE1123xBuo1J97jzh2hkYZ9bH4zzgarY8aj/g=; b=VQLAfnkZcYKOLS2dTvi2wjNi/T5S3V4OGN8pYfcA4zIgnN3BAoHCKWA9vFF0LzcCex elWmW7xpFiex15XoHtN8MKUAyrLZbkmPynE46jbtJ1/HczjnYkE5nuX6dd2sLE8w0AcX u2SzcCTMCZq57FxSX6LUoVHZCb6476Wrr9VpF2QNXzuU/CXx7b/Sm1IymC3mUWWskeWI 8VdV8KDd7PvdDLuWVNzxAHYI54xNCZs6AGOVp0GKF7rRDFrR9dtA7ZANb8BeRpqHam5n vRlsaQr7cwqaMhGMLzAiuZEDITXyMYBm0MP7PGhBH+hTt5JLeOO9oKIvqppshw+Ba5b3 F5YQ== X-Gm-Message-State: AOJu0YxEhm+2kpJNcl+t35rhO1wpjDvuUBv98xii/Gf/ixFE8HP49cL8 ZPpD4eeEZk5YVE4ldsB7mmtO6/N0JjA8qzSAgaoOHcDPmEKQ2HGwLIRZpYYmNsYpGfc+2SdIzhv Ox3yCzeP8Bxv6xvzfoa+7HDxfaqGOYhV1AZ3njZbGEgD8LytM4BE6GA2SC0Z5jrvR3NvUSH0MnB HQJeiSffktdzOIeI5/kDpwnWjCurxTzn4oZ0fTVb0= X-Gm-Gg: ASbGncubiWmxOLHWyHb2Il769zzzvJCpfYD91WPg8/SY76rn54HXXS3COqM48uuj3AQ cqVkVTs/IlOY7Gn2ejL8MEYUc95eyR3eFbJkzKm62gspKN9WC2dPWLRjFIauZsBW+SRv0JylGZx jO4jE+Ouj4q7pCUTWQLrDNq6MvWsxwuenfTCztVeo+UfYUC2u5luZE6M0qhbTNXYSMK3tezztFO PK6n/TVDHxoPHHXv+QbfLfAYQCFlCUXHEIt+Z4jxZ3uyL5+VB06qQG1zFgAqbIIGKdIAzO6Dw== X-Received: by 2002:a05:600c:4fd6:b0:434:feb1:adcf with SMTP id 5b1f17b1804b1-43891436690mr223595735e9.25.1737711978175; Fri, 24 Jan 2025 01:46:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQw0q78asJ8ydf09X5+4Zdt/evkPrjtWQgWQSAs/cTYcwd1Vk+lgSSYu44GFjnIyo4jbXmQw== X-Received: by 2002:a05:600c:4fd6:b0:434:feb1:adcf with SMTP id 5b1f17b1804b1-43891436690mr223595575e9.25.1737711977857; Fri, 24 Jan 2025 01:46:17 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4d2c0esm20278115e9.33.2025.01.24.01.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:16 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 48/48] rust: qemu-api: add sub-subclass to the integration tests Date: Fri, 24 Jan 2025 10:44:42 +0100 Message-ID: <20250124094442.13207-49-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-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: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, 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.043, 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: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/tests/tests.rs | 56 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 526c3f4f8ea..5c3e75ed3d5 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -14,8 +14,8 @@ cell::{self, BqlCell}, declare_properties, define_property, prelude::*, - qdev::{DeviceImpl, DeviceState, Property}, - qom::{ObjectImpl, ParentField}, + qdev::{DeviceClass, DeviceImpl, DeviceState, Property}, + qom::{ClassInitImpl, ObjectImpl, ParentField}, vmstate::VMStateDescription, zeroable::Zeroable, }; @@ -37,6 +37,10 @@ pub struct DummyState { qom_isa!(DummyState: Object, DeviceState); +pub struct DummyClass { + parent_class: ::Class, +} + declare_properties! { DUMMY_PROPERTIES, define_property!( @@ -49,7 +53,7 @@ pub struct DummyState { } unsafe impl ObjectType for DummyState { - type Class = ::Class; + type Class = DummyClass; const TYPE_NAME: &'static CStr = c_str!("dummy"); } @@ -67,6 +71,51 @@ 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)] +pub struct DummyChildState { + parent: ParentField, +} + +qom_isa!(DummyChildState: Object, DeviceState, DummyState); + +pub struct DummyChildClass { + parent_class: ::Class, +} + +unsafe impl ObjectType for DummyChildState { + type Class = DummyChildClass; + const TYPE_NAME: &'static CStr = c_str!("dummy_child"); +} + +impl ObjectImpl for DummyChildState { + type ParentType = DummyState; + const ABSTRACT: bool = false; +} + +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); + } +} + fn init_qom() { static ONCE: BqlCell = BqlCell::new(false); @@ -85,6 +134,7 @@ fn test_object_new() { init_qom(); unsafe { object_unref(object_new(DummyState::TYPE_NAME.as_ptr()).cast()); + object_unref(object_new(DummyChildState::TYPE_NAME.as_ptr()).cast()); } }