From patchwork Mon Feb 10 10:22:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13967608 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 5160BC0219E for ; Mon, 10 Feb 2025 10:24:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thQxf-0003e2-SJ; Mon, 10 Feb 2025 05:24: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 1thQxd-0003WP-3s for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:24:17 -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 1thQxa-0000eR-Uv for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:24:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739183054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lf4c6h56xYCNge6XjLmVtzeXRglB5fuipR2Vwz8DQLs=; b=AE9LbxqAVMMKRvuOuXWU2YSR8rxoljDx1t1cG/a3xFbp362zk/iNAzlf5udfuUnuZk9id0 TPc+u9JqKQ3hG3P3uvZNiDow/6cMLjL+xQY5cVwojyfOX6dUpOG+59zKg5+JViUkwWGxd5 v7qaMA3iM3ixKIh1kvdkdO8tHU8E+Fc= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-205-HqWenfjxNEayASUbtnJhuw-1; Mon, 10 Feb 2025 05:23:02 -0500 X-MC-Unique: HqWenfjxNEayASUbtnJhuw-1 X-Mimecast-MFC-AGG-ID: HqWenfjxNEayASUbtnJhuw Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5de363763ddso2504501a12.2 for ; Mon, 10 Feb 2025 02:23:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739182980; x=1739787780; 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=Lf4c6h56xYCNge6XjLmVtzeXRglB5fuipR2Vwz8DQLs=; b=DL1YFZJ/J2y+2+wPY878wBH06/kJL5WU5DzV0q9P5FgDXSYfhA23cMh/grYz2ri2Pg JURX2RZKNXdgZ/NZ/0w1G9aJAl0EE6BKzFao/WDUTQ+Zs4umwfCfYSxW+92rAl1Ef4L2 c54N2T2FkF+1/zbNRTBegDujaOtpfXOWa+6A3/cCdoCVq5yoReH3TL49CoVcZR/QMFbX Mqww+yQNKE7ijEp+sRXAXAucFBfmf+K4LIWHsDTxCKTqOi3vOnVcS/pYf4DA1z7vJ9Mi TSbd/vv5yTul7agP+7jIxV9oe2Y4Hp9rlEVcqmTZk1RayONu8Pcaqa4HyuDJhuYevt+J ckkw== X-Gm-Message-State: AOJu0Ywb6LCMbQXs3/SVNF4HEo8+MqNitewOUQBePRwlkQ3abI2OPUjE mSv/qKuxlOf7C6aziZ/9hwB50xd2vZ1pgis/ZnICi8pC+A8OOXa1HrsSBEGT7MuvHihnPhViPlH zodfbdqKRtmYyhN/L66aG2o/w1oVY/EetNz/fFQkWdGcmfYfuA9ubP9qLH7BKaV1APh+jlAtNNn LT2Dy6nnTrg4gASbvTBOx2FVrrM3y2Qq/gg7VdJRs= X-Gm-Gg: ASbGncssxkllZvDHqHYv2RDR9PeVKV+KdTRUDPQvA6CK+VyOW+Tpf3E/L3BnSqUTYnt MQOiDwMqIIc//l6sQkXlsZmDp25maf8x8jwmC733zJh3Sv80v/qVVxWM4007Dvo4hTbz2Futcra TxHSgg9hln+AwVpuBQpHOBmkXF+eXjZ136w4b9bwODv9GWh/5ms3iGpTWfgfwn8NceHZL6aJzSC O1NRoo7Eg4F2qMjuBDZyC+fW+NSXDeVzby/fMHhNknMSnxGY2IiuFANGele8+UDN63gh79a+p6K KGwUZA== X-Received: by 2002:a05:6402:321d:b0:5dc:cfc5:9324 with SMTP id 4fb4d7f45d1cf-5de4508084amr40832484a12.30.1739182980180; Mon, 10 Feb 2025 02:23:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5zeQOjjAbeKNV++dYtQL0f8cINJzeWMgP5UImuqSnOVc43RuRy/2ph7ghH1CLKIaPgPjmrw== X-Received: by 2002:a05:6402:321d:b0:5dc:cfc5:9324 with SMTP id 4fb4d7f45d1cf-5de4508084amr40832421a12.30.1739182979520; Mon, 10 Feb 2025 02:22:59 -0800 (PST) Received: from [192.168.10.3] ([151.62.97.55]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab7ced6fe0dsm61951166b.179.2025.02.10.02.22.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 02:22:58 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 1/9] rust: remove unnecessary Cargo.toml metadata Date: Mon, 10 Feb 2025 11:22:46 +0100 Message-ID: <20250210102255.2555097-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250210102255.2555097-1-pbonzini@redhat.com> References: <20250210102255.2555097-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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.405, 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.01, 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 Some items of Cargo.toml (readme, homepage, repository) are only present because of clippy::cargo warnings being enabled in rust/hw/char/pl011/src/lib.rs. But these items are not particularly useful and would be all the same for all Cargo.toml files in the QEMU workspace. Clean them up. Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/hw/char/pl011/Cargo.toml | 3 --- rust/hw/char/pl011/README.md | 31 ------------------------------- rust/hw/char/pl011/src/lib.rs | 14 ++++++-------- rust/qemu-api-macros/Cargo.toml | 3 --- rust/qemu-api-macros/README.md | 1 - 5 files changed, 6 insertions(+), 46 deletions(-) delete mode 100644 rust/hw/char/pl011/README.md delete mode 100644 rust/qemu-api-macros/README.md diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml index 58f3e859f7e..2b4097864df 100644 --- a/rust/hw/char/pl011/Cargo.toml +++ b/rust/hw/char/pl011/Cargo.toml @@ -4,10 +4,7 @@ version = "0.1.0" edition = "2021" authors = ["Manos Pitsidianakis "] license = "GPL-2.0-or-later" -readme = "README.md" -homepage = "https://www.qemu.org" description = "pl011 device model for QEMU" -repository = "https://gitlab.com/epilys/rust-for-qemu" resolver = "2" publish = false keywords = [] diff --git a/rust/hw/char/pl011/README.md b/rust/hw/char/pl011/README.md deleted file mode 100644 index cd7dea31634..00000000000 --- a/rust/hw/char/pl011/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# PL011 QEMU Device Model - -This library implements a device model for the PrimeCell® UART (PL011) -device in QEMU. - -## Build static lib - -Host build target must be explicitly specified: - -```sh -cargo build --target x86_64-unknown-linux-gnu -``` - -Replace host target triplet if necessary. - -## Generate Rust documentation - -To generate docs for this crate, including private items: - -```sh -cargo doc --no-deps --document-private-items --target x86_64-unknown-linux-gnu -``` - -To include direct dependencies like `bilge` (bitmaps for register types): - -```sh -cargo tree --depth 1 -e normal --prefix none \ - | cut -d' ' -f1 \ - | xargs printf -- '-p %s\n' \ - | xargs cargo doc --no-deps --document-private-items --target x86_64-unknown-linux-gnu -``` diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index e2df4586bcc..e704daf6e3e 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -1,13 +1,12 @@ // Copyright 2024, Linaro Limited // Author(s): Manos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later -// -// PL011 QEMU Device Model -// -// This library implements a device model for the PrimeCell® UART (PL011) -// device in QEMU. -// -#![doc = include_str!("../README.md")] + +//! PL011 QEMU Device Model +//! +//! This library implements a device model for the PrimeCell® UART (PL011) +//! device in QEMU. +//! //! # Library crate //! //! See [`PL011State`](crate::device::PL011State) for the device model type and @@ -18,7 +17,6 @@ clippy::suspicious, clippy::complexity, clippy::perf, - clippy::cargo, clippy::nursery, clippy::style )] diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.toml index 5a27b52ee6e..b9b4baecddb 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -4,10 +4,7 @@ version = "0.1.0" edition = "2021" authors = ["Manos Pitsidianakis "] license = "GPL-2.0-or-later" -readme = "README.md" -homepage = "https://www.qemu.org" description = "Rust bindings for QEMU - Utility macros" -repository = "https://gitlab.com/qemu-project/qemu/" resolver = "2" publish = false keywords = [] diff --git a/rust/qemu-api-macros/README.md b/rust/qemu-api-macros/README.md deleted file mode 100644 index f60f54ac4be..00000000000 --- a/rust/qemu-api-macros/README.md +++ /dev/null @@ -1 +0,0 @@ -# `qemu-api-macros` - Utility macros for defining QEMU devices From patchwork Mon Feb 10 10:22:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13967604 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 D34D3C02198 for ; Mon, 10 Feb 2025 10:24:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thQwY-0002Kr-6q; Mon, 10 Feb 2025 05:23:10 -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 1thQwX-0002Kh-EP for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23: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 1thQwV-0000LI-Sy for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739182986; 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=3kI2fmnmJgUGnjqtQ5jhxKS9I/PiFpAzsz1KC537irc=; b=Phx5Een57gJ/MgMw8vgc4g5HnXgmE2CugK9IyX9z1TSjiC2BRj4D0KXAzGwle7dgLhCNrs 4YqTPNx+NK6Z5PrycRzr7icPoH3TAHxh2flR2Fu7vnuEuGzMC168FLgPO5zxMW63pNSV72 7HxSc5lsy+9144mMF+2Nb3VM4Jk+Acw= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-14-hwpK8irYOrqIgdBkQBCEaQ-1; Mon, 10 Feb 2025 05:23:03 -0500 X-MC-Unique: hwpK8irYOrqIgdBkQBCEaQ-1 X-Mimecast-MFC-AGG-ID: hwpK8irYOrqIgdBkQBCEaQ Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-ab7a3a033b4so129709366b.0 for ; Mon, 10 Feb 2025 02:23:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739182981; x=1739787781; 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=3kI2fmnmJgUGnjqtQ5jhxKS9I/PiFpAzsz1KC537irc=; b=Rxy8YNNyY/f6VG9qUpDXVPuJv/mzaxMdWW3Bf3OoFE1IDiB3tHbZJYYq1dsTEKVBHg x51hX2oTaMBmkWiAjqPB+aVWXR0x5BduSUH0hwGU1VaeriOTJv30iqZyyXUhDB3Qip2v RMkwyhN+fZmuHRBXCE8VW5WC90MCTDnQzxu5n7nk/mqXpD/COibaElGCXIB+o6hjJ2Rd iB/9j2Rgf+/4UDUpZWe6r1Z1cnbJEbhhLv4Z+0Gh68hifQdP7iWXCJAgYNapf8PM86CQ /Wc4gqHVXwNrH00bKOf3+G7Cvr9dh5YeOe4m4s93SU+coq4zYi/+EK83sZT2wRbB3bv7 euQQ== X-Gm-Message-State: AOJu0Yx4yVWoCOBT2muvFn7wgEsZ1nfRlEiY0Mb7eCFEvZRyPAu/SDbn 3gSETE08adbk3UTC0LXT0qNrWxUyp1ETQlQARuY1DQKLrpB1fcGDXAxkklzZyMQD24lZtAYz6p5 elO/vppu5jU6bpfj9aL9uMycYRzXdQ7J+5XLAL4xKdTv3vGDo2kIjfexSsdFne343cVndXLtRSw 3qCqcOCYKMLUBusEz1Hzx4SpmwxJmWVdGlLLXGXnA= X-Gm-Gg: ASbGnctcEURc6Wj+jFbRGPOBPrgBppwxlUlAJkF8jThXAAKp4XEaFhSuNRPlqzhX+EB xmtm4+yZksFbV3HHfUBOLrytOWzsUhSZz91NGp3x4mRjaQahnLi7dmiYW/vC6aBlYhbpCTV8AHl RtqewMYbbgnggsVoneFAlbes7skho68lUICaePELv3dihGTsXFcchyl+WmZIkk3K+kXrTSl/hqm d10A8pYNI6AHjtj4S3vSSNfiDo7QumxEA75F1wjFp4+VOi9d61MYPnl9EVOlGdKaDnXvDqXdQdL akGqkA== X-Received: by 2002:a17:907:1c95:b0:ab7:c94f:af87 with SMTP id a640c23a62f3a-ab7c94fb336mr217388566b.16.1739182981306; Mon, 10 Feb 2025 02:23:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWBADpk9Vdt5YkfFx+tF4N7pRZWyo3pMmuCDIbXW1+Lyg05wle11lZt0QrgGTsG1WB4gn6/A== X-Received: by 2002:a17:907:1c95:b0:ab7:c94f:af87 with SMTP id a640c23a62f3a-ab7c94fb336mr217386166b.16.1739182980771; Mon, 10 Feb 2025 02:23:00 -0800 (PST) Received: from [192.168.10.3] ([151.62.97.55]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab7809a2ec4sm770242466b.116.2025.02.10.02.23.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 02:23:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 2/9] rust: include rust_version in Cargo.toml Date: Mon, 10 Feb 2025 11:22:47 +0100 Message-ID: <20250210102255.2555097-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250210102255.2555097-1-pbonzini@redhat.com> References: <20250210102255.2555097-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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.405, 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.01, 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 Tell clippy the minimum supported Rust version for QEMU. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/Cargo.toml | 1 + rust/hw/char/pl011/src/device_class.rs | 1 - rust/qemu-api-macros/Cargo.toml | 1 + rust/qemu-api/Cargo.toml | 1 + 4 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml index 2b4097864df..f2296cad58b 100644 --- a/rust/hw/char/pl011/Cargo.toml +++ b/rust/hw/char/pl011/Cargo.toml @@ -9,6 +9,7 @@ resolver = "2" publish = false keywords = [] categories = [] +rust-version = "1.63.0" [lib] crate-type = ["staticlib"] diff --git a/rust/hw/char/pl011/src/device_class.rs b/rust/hw/char/pl011/src/device_class.rs index 8a157a663fb..dbef93f6cb3 100644 --- a/rust/hw/char/pl011/src/device_class.rs +++ b/rust/hw/char/pl011/src/device_class.rs @@ -12,7 +12,6 @@ use crate::device::{PL011Registers, PL011State}; -#[allow(clippy::missing_const_for_fn)] extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { let state = NonNull::new(opaque).unwrap().cast::(); unsafe { state.as_ref().migrate_clock } diff --git a/rust/qemu-api-macros/Cargo.toml b/rust/qemu-api-macros/Cargo.toml index b9b4baecddb..89dee1cfb39 100644 --- a/rust/qemu-api-macros/Cargo.toml +++ b/rust/qemu-api-macros/Cargo.toml @@ -9,6 +9,7 @@ resolver = "2" publish = false keywords = [] categories = [] +rust-version = "1.63.0" [lib] proc-macro = true diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index 4aa22f31986..a51dd142852 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -12,6 +12,7 @@ resolver = "2" publish = false keywords = [] categories = [] +rust-version = "1.63.0" [dependencies] qemu_api_macros = { path = "../qemu-api-macros" } From patchwork Mon Feb 10 10:22:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13967603 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 0D549C021A2 for ; Mon, 10 Feb 2025 10:23:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thQwc-0002Mo-Le; Mon, 10 Feb 2025 05:23:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1thQwb-0002MK-61 for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1thQwW-0000LN-VP for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739182988; 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=jzu5KqFPpVTmIeybSZHg/TQc1UM016G+0N2y7+uUJlY=; b=Bq0w8nrEs/dQ4t/uGR7ohUrYT054qtA7n3w1mtDykE3HDJ2u3KLvSiEVSih3sRLKFoDlBW DrpdCjvgBI8IGUgfEkp+a/Xxea4YNf42eYeKYhNdml0IlXyrIY9fH6W3WziIy8eUaUrkwj SXri9OMhBWTl0DzAkBO+GoJF4QMjaM4= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-357-Z-ZvtD4tNLCpjVCsdxiuCw-1; Mon, 10 Feb 2025 05:23:06 -0500 X-MC-Unique: Z-ZvtD4tNLCpjVCsdxiuCw-1 X-Mimecast-MFC-AGG-ID: Z-ZvtD4tNLCpjVCsdxiuCw Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ab78a6342d7so283182166b.2 for ; Mon, 10 Feb 2025 02:23:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739182984; x=1739787784; 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=jzu5KqFPpVTmIeybSZHg/TQc1UM016G+0N2y7+uUJlY=; b=epCK+JOtniiAMg5eislQbvbNYFwHoD9+AvQ4t0cr2p3+Y37gGaRPqz4mx3tc5Kpo2Z kwOIuiwltUaQ7A6Ovj0zCsPA/w9c0q9v1/BMXJ4qk7EHv9oUPnkbDmiIMspSEmQx2zSG qCS0lBIy0T6F15qDSVmT15ExXg5TheyZM/WFKNTWBo/TZCQ44kH4mCXTQ+PqcZdh9YgS 1I+CBEOUgh8rK+5XChU9UQxL6swf/DWlYmqTINnde6Xq6duZ7vRPgpP5fHvlJ6CaS1zX E+ucpziGjkVsUSRBAAVN+vvOAHgfvwCxe6qbvjh9iEIXbeigfhapH//aesSmPSAmx3WK 8kyQ== X-Gm-Message-State: AOJu0Yw/20/RRWD7WCphiqYW06g/SWkYecOIbc0kUaE2eZG3gzOcvo05 rb7ofw58pFR9F54FXX86PeOCZBob+nrAvevcmTFm8H+1UPdZCkB5FUU1QY70H+7QTWBCAUz5E0f rKl2VTyh9JqSg6Qdq4KuH2+vXhTNSMLRGWlToDCRvxIE/+cej4syZPqPyMsEBbtk3bmfOa3iOK5 36JQSoUSZVOcQNehjxDPTIpgCSvuhaKZ5/vLLQEHo= X-Gm-Gg: ASbGncv6SNVG19+11LHUYVQy32EKY0GQ5+UBxBtwNbiFa7pkbWc64lC2vjUPKPUAT7e cA+PqiITiC1W2gqNnXQQL3hlCpS1yP2FMiQToFRmTXgYpHHuOQG2tU+HkuU3/VW8xsmZ80AKMrV 94uLspTP89ahb6Og9CV1LMEFktP/uEsYsBKAg4PpZPmfd37adQfos+tLOwGo0PNUWQNrJBjlAgI 8aIBjGXoSxyWfrxDa5i6o5P7QD+uMuu47NwHU+pYuyBuWb2UUducBfBbsJfyz2BlQ9Z3a0+ooE7 DWXDRQ== X-Received: by 2002:a17:907:1b28:b0:aab:eefd:bfd8 with SMTP id a640c23a62f3a-ab789c4f7f6mr1683765366b.49.1739182983891; Mon, 10 Feb 2025 02:23:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdI9RqBhX2QgYfl9cRuDr+VZ11XxJGs/GLwqBRrxou1t/WRdTH03nMU1rTnsKVn+xwNmw45g== X-Received: by 2002:a17:907:1b28:b0:aab:eefd:bfd8 with SMTP id a640c23a62f3a-ab789c4f7f6mr1683759966b.49.1739182982959; Mon, 10 Feb 2025 02:23:02 -0800 (PST) Received: from [192.168.10.3] ([151.62.97.55]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab77bdb5b93sm800827066b.171.2025.02.10.02.23.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 02:23:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 3/9] rust: add docs Date: Mon, 10 Feb 2025 11:22:48 +0100 Message-ID: <20250210102255.2555097-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250210102255.2555097-1-pbonzini@redhat.com> References: <20250210102255.2555097-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: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.405, 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=-1, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_SBL_A=0.1 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Paolo Bonzini --- docs/devel/index-process.rst | 1 + docs/devel/rust.rst | 430 +++++++++++++++++++++++++++++++++++ 2 files changed, 431 insertions(+) create mode 100644 docs/devel/rust.rst diff --git a/docs/devel/index-process.rst b/docs/devel/index-process.rst index 362f97ee300..cb7c6640fd2 100644 --- a/docs/devel/index-process.rst +++ b/docs/devel/index-process.rst @@ -17,3 +17,4 @@ Notes about how to interact with the community and how and where to submit patch stable-process submitting-a-pull-request secure-coding-practices + rust diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst new file mode 100644 index 00000000000..390aae43866 --- /dev/null +++ b/docs/devel/rust.rst @@ -0,0 +1,430 @@ +.. |msrv| replace:: 1.63.0 + +Rust in QEMU +============ + +Rust in QEMU is a project to enable using the Rust programming language +to add new functionality to QEMU. + +Right now, the focus is on making it possible to write devices that inherit +from ``SysBusDevice`` in `*safe*`__ Rust. Later, it may become possible +to write other kinds of devices (e.g. PCI devices that can do DMA), +complete boards, or backends (e.g. block device formats). + +__ https://doc.rust-lang.org/nomicon/meet-safe-and-unsafe.html + +Building the Rust in QEMU code +------------------------------ + +The Rust in QEMU code is included in the emulators via Meson. Meson +invokes rustc directly, building static libraries that are then linked +together with the C code. This is completely automatic when you run +``make`` or ``ninja``. + +However, QEMU's build system also tries to be easy to use for people who +are accustomed to the more "normal" Cargo-based development workflow. +In particular: + +* the set of warnings and lints that are used to build QEMU always + comes from the ``rust/Cargo.toml`` workspace file + +* it is also possible to use ``cargo`` for common Rust-specific coding + tasks, in particular to invoke ``clippy``, ``rustfmt`` and ``rustdoc``. + +To this end, QEMU includes a ``build.rs`` build script that picks up +generated sources from QEMU's build directory and puts it in Cargo's +output directory (typically ``rust/target/``). A vanilla invocation +of Cargo will complain that it cannot find the generated sources, +which can be fixed in different ways: + +* by using special shorthand targets in the QEMU build directory:: + + make clippy + make rustfmt + make rustdoc + +* by invoking ``cargo`` through the Meson `development environment`__ + feature:: + + pyvenv/bin/meson devenv -w ../rust cargo clippy --tests + pyvenv/bin/meson devenv -w ../rust cargo fmt + + If you are going to use ``cargo`` repeatedly, ``pyvenv/bin/meson devenv`` + will enter a shell where commands like ``cargo clippy`` just work. + +__ https://mesonbuild.com/Commands.html#devenv + +* by pointing the ``MESON_BUILD_ROOT`` to the top of your QEMU build + tree. This third method is useful if you are using ``rust-analyzer``; + you can set the environment variable through the + ``rust-analyzer.cargo.extraEnv`` setting. + +As shown above, you can use the ``--tests`` option as usual to operate on test +code. Note however that you cannot *build* or run tests via ``cargo``, because +they need support C code from QEMU that Cargo does not know about. Tests can +be run via ``meson test`` or ``make``:: + + make check-rust + +Building Rust code with ``--enable-modules`` is not supported yet. + +Supported tools +''''''''''''''' + +QEMU supports rustc version 1.63.0 and newer. Notably, the following features +are missing: + +* ``core::ffi`` (1.64.0). Use ``std::os::raw`` and ``std::ffi`` instead. + +* ``cast_mut()``/``cast_const()`` (1.65.0). Use ``as`` instead. + +* "let ... else" (1.65.0). Use ``if let`` instead. This is currently patched + in QEMU's vendored copy of the bilge crate. + +* Generic Associated Types (1.65.0) + +* ``CStr::from_bytes_with_nul()`` as a ``const`` function (1.72.0). + +* "Return position ``impl Trait`` in Traits" (1.75.0, blocker for including + the pinned-init create). + +* ``MaybeUninit::zeroed()`` as a ``const`` function (1.75.0). QEMU's + ``Zeroable`` trait can be implemented without ``MaybeUninit::zeroed()``, + so this would be just a cleanup. + +* ``c"" literals`` (stable in 1.77.0). QEMU provides a ``c_str!()`` macro + to define ``CStr`` constants easily + +* ``offset_of!`` (stable in 1.77.0). QEMU uses ``offset_of!()`` heavily; it + provides a replacement in the ``qemu_api`` crate, but it does not support + lifetime parameters and therefore ``&'a Something`` fields in the struct + may have to be replaced by ``NonNull``. *Nested* ``offset_of!`` + was only stabilized in Rust 1.82.0, but it is not used. + +* inline const expression (stable in 1.79.0), currently worked around with + associated constants in the ``FnCall`` trait. + +* associated constants have to be explicitly marked ``'static`` (`changed in + 1.81.0`__) + +* ``&raw`` (stable in 1.82.0). Use ``addr_of!`` and ``addr_of_mut!`` instead, + though hopefully the need for raw pointers will go down over time. + +* ``new_uninit`` (stable in 1.82.0). This is used internally by the ``pinned_init`` + crate, which is planned for inclusion in QEMU, but it can be easily patched + out. + +* referencing statics in constants (stable in 1.83.0). For now use a const + function; this is an important limitation for QEMU's migration stream + architecture (VMState). Right now, VMState lacks type safety because + it is hard to place the ``VMStateField`` definitions in traits. + +* associated const equality would be nice to have for some users of + ``callbacks::FnCall``, but is still experimental. ``ASSERT_IS_SOME`` + replaces it. + +__ https://github.com/rust-lang/rust/pull/125258 + +It is expected that QEMU will advance its minimum supported version of +rustc to 1.77.0 as soon as possible; as of January 2025, blockers +for that right now are Debian bookworm and 32-bit MIPS processors. +This unfortunately means that references to statics in constants will +remain an issue. + +QEMU also supports version 0.60.x of bindgen, which is missing option +``--generate-cstr``. This option requires version 0.66.x and will +be adopted as soon as supporting these older versions is not necessary +anymore. + +Writing Rust code in QEMU +------------------------- + +Right now QEMU includes three crates: + +* ``qemu_api`` for bindings to C code and useful functionality + +* ``qemu_api_macros`` defines several procedural macros that are useful when + writing C code + +* ``pl011`` (under ``rust/hw/char/pl011``) is the sample device that is being + used to further develop ``qemu_api`` and ``qemu_api_macros``. It is a functional + replacement for the ``hw/char/pl011.c`` file. + +This section explains how to work with them. + +Status +'''''' + +Modules of ``qemu_api`` can be defined as: + +- *complete*: ready for use in new devices; if applicable, the API supports the + full functionality available in C + +- *stable*: ready for production use, the API is safe and should not undergo + major changes + +- *proof of concept*: the API is subject to change but allows working with safe + Rust + +- *initial*: the API is in its initial stages; it requires large amount of + unsafe code; it might have soundness or type-safety issues + +The status of the modules is as follows: + +================ ====================== +module status +================ ====================== +``assertions`` stable +``bitops`` complete +``callbacks`` complete +``cell`` stable +``c_str`` complete +``irq`` complete +``module`` complete +``offset_of`` stable +``qdev`` stable +``qom`` stable +``sysbus`` stable +``vmstate`` proof of concept +``zeroable`` stable +================ ====================== + +.. note:: + API stability is not a promise, if anything because the C APIs are not a stable + interface either. Also, ``unsafe`` interfaces may be replaced by safe interfaces + later. + +Common pitfalls +''''''''''''''' + +Rust has very strict rules with respect to how you get an exclusive (``&mut``) +reference; failure to respect those rules is a source of undefined behavior. +In particular, even if a value is loaded from a raw mutable pointer (``*mut``), +it *cannot* be casted to ``&mut`` unless the value was stored to the ``*mut`` +from a mutable reference. Furthermore, it is undefined behavior if any +shared reference was created between the store to the ``*mut`` and the load:: + + let mut p: u32 = 42; + let p_mut = &mut p; // 1 + let p_raw = p_mut as *mut u32; // 2 + + // p_raw keeps the mutable reference "alive" + + let p_shared = &p; // 3 + println!("access from &u32: {}", *p_shared); + + // Bring back the mutable reference, its lifetime overlaps + // with that of a shared reference. + let p_mut = unsafe { &mut *p_raw }; // 4 + println!("access from &mut 32: {}", *p_mut); + + println!("access from &u32: {}", *p_shared); // 5 + +These rules can be tested with `MIRI`__, for example. + +__ https://github.com/rust-lang/miri + +Almost all Rust code in QEMU will involve QOM objects, and pointers to these +objects are *shared*, for example because they are part of the QOM composition +tree. This creates exactly the above scenario: + +1. a QOM object is created + +2. a ``*mut`` is created, for example as the opaque value for a ``MemoryRegion`` + +3. the QOM object is placed in the composition tree + +4. a memory access dereferences the opaque value to a ``&mut`` + +5. but the shared reference is still present in the composition tree + +Because of this, QOM objects should almost always use ``&self`` instead +of ``&mut self``; access to internal fields must use *interior mutability* +to go from a shared reference to a ``&mut``. + +Whenever C code provides you with an opaque ``void *``, avoid converting it +to a Rust mutable reference, and use a shared reference instead. Rust code +will then have to use QEMU's ``BqlRefCell`` and ``BqlCell`` type, which +enforce that locking rules for the "Big QEMU Lock" are respected. These cell +types are also known to the ``vmstate`` crate, which is able to "look inside" +them when building an in-memory representation of a ``struct``s layout. +Note that the same is not true of a ``RefCell`` or ``Mutex``. + +In the future, similar cell types might also be provided for ``AioContext``-based +locking as well. + +Writing bindings to C code +'''''''''''''''''''''''''' + +Here are some things to keep in mind when working on the ``qemu_api`` crate. + +**Look at existing code** + Very often, similar idioms in C code correspond to similar tricks in + Rust bindings. If the C code uses ``offsetof``, look at qdev properties + or ``vmstate``. If the C code has a complex const struct, look at + ``MemoryRegion``. Reuse existing patterns for handling lifetimes; + for example use ``&T`` for QOM objects that do not need a reference + count (including those that can be embedded in other objects) and + ``Owned`` for those that need it. + +**Use the type system** + Bindings often will need access information that is specific to a type + (either a builtin one or a user-defined one) in order to pass it to C + functions. Put them in a trait and access it through generic parameters. + The ``vmstate`` module has examples of how to retrieve type information + for the fields of a Rust ``struct``. + +**Prefer unsafe traits to unsafe functions** + Unsafe traits are much easier to prove correct than unsafe functions. + They are an excellent place to store metadata that can later be accessed + by generic functions. C code usually places metadata in global variables; + in Rust, they can be stored in traits and then turned into ``static`` + variables. Often, unsafe traits can be generated by procedural macros. + +**Document limitations due to old Rust versions** + If you need to settle for an inferior solution because of the currently + supported set of Rust versions, document it in the source and in this + file. This ensures that it can be fixed when the minimum supported + version is bumped. + +**Keep locking in mind**. + When marking a type ``Sync``, be careful of whether it needs the big + QEMU lock. Use ``BqlCell`` and ``BqlRefCell`` for interior data, + or assert ``bql_locked()``. + +**Don't be afraid of complexity, but document and isolate it** + It's okay to be tricky; device code is written more often than bindings + code and it's important that it is idiomatic. However, you should strive + to isolate any tricks in a place (for example a ``struct``, a trait + or a macro) where it can be documented and tested. If needed, include + toy versions of the code in the documentation. + +Writing procedural macros +''''''''''''''''''''''''' + +By conventions, procedural macros are split in two functions, one +returning ``Result` with the body of +the procedural macro, and the second returning ``proc_macro::TokenStream`` +which is the actual procedural macro. The former's name is the same as +the latter with the ``_or_error`` suffix. The code for the latter is more +or less fixed; it follows the following template, which is fixed apart +from the type after ``as`` in the invocation of ``parse_macro_input!``:: + + #[proc_macro_derive(Object)] + pub fn derive_object(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let expanded = derive_object_or_error(input).unwrap_or_else(Into::into); + + TokenStream::from(expanded) + } + +The ``qemu_api_macros`` crate has utility functions to examine a +``DeriveInput`` and perform common checks (e.g. looking for a struct +with named fields). These functions return ``Result<..., MacroError>`` +and can be used easily in the procedural macro function:: + + fn derive_object_or_error(input: DeriveInput) -> + Result + { + is_c_repr(&input, "#[derive(Object)]")?; + + let name = &input.ident; + let parent = &get_fields(&input, "#[derive(Object)]")?[0].ident; + ... + } + +Use procedural macros with care. They are mostly useful for two purposes: + +* Performing consistency checks; for example ``#[derive(Object)]`` checks + that the structure has ``#[repr[C])`` and that the type of the first field + is consistent with the ``ObjectType`` declaration. + +* Extracting information from Rust source code into traits, typically based + on types and attributes. For example, ``#[derive(TryInto)]`` builds an + implementation of ``TryFrom``, and it uses the ``#[repr(...)]`` attribute + as the ``TryFrom`` source and error types. + +Procedural macros can be hard to debug and test; if the code generation +exceeds a few lines of code, it may be worthwhile to delegate work to +"regular" declarative (``macro_rules!``) macros and write unit tests for +those instead. + + +Coding style +'''''''''''' + +Code should pass clippy and be formatted with rustfmt. + +Right now, only the nightly version of ``rustfmt`` is supported. This +might change in the future. While CI checks for correct formatting via +``cargo fmt --check``, maintainers can fix this for you when applying patches. + +It is expected that ``qemu_api`` provides full ``rustdoc`` documentation for +bindings that are in their final shape or close. + +Adding dependencies +------------------- + +Generally, the set of dependent crates is kept small. Think twice before +adding a new external crate, especially if it comes with a large set of +dependencies itself. Sometimes QEMU only needs a small subset of the +functionality; see for example QEMU's ``assertions`` or ``c_str`` modules. + +On top of this recommendation, adding external crates to QEMU is a +slightly complicated process, mostly due to the need to teach Meson how +to build them. While Meson has initial support for parsing ``Cargo.lock`` +files, it is still highly experimental and is therefore not used. + +Therefore, external crates must be added as subprojects for Meson to +learn how to build them, as well as to the relevant ``Cargo.toml`` files. +The versions specified in ``rust/Cargo.lock`` must be the same as the +subprojects; note that the ``rust/`` directory forms a Cargo `workspace`__, +and therefore there is a single lock file for the whole build. + +__ https://doc.rust-lang.org/cargo/reference/workspaces.html#virtual-workspace + +Choose a version of the crate that works with QEMU's minimum supported +Rust version (|msrv|). + +Second, a new ``wrap`` file must be added to teach Meson how to download the +crate. The wrap file must be named ``NAME-SEMVER-rs.wrap``, where ``NAME`` +is the name of the crate and ``SEMVER`` is the version up to and including the +first non-zero number. For example, a crate with version ``0.2.3`` will use +``0.2`` for its ``SEMVER``, while a crate with version ``1.0.84`` will use ``1``. + +Third, the Meson rules to build the crate must be added at +``subprojects/NAME-SEMVER-rs/meson.build``. Generally this includes: + +* ``subproject`` and ``dependency`` lines for all dependent crates + +* a ``static_library`` or ``rust.proc_macro`` line to perform the actual build + +* ``declare_dependency`` and a ``meson.override_dependency`` lines to expose + the result to QEMU and to other subprojects + +Remember to add ``native: true`` to ``dependency``, ``static_library`` and +``meson.override_dependency`` for dependencies of procedural macros. +If a crate is needed in both procedural macros and QEMU binaries, everything +apart from ``subproject`` must be duplicated to build both native and +non-native versions of the crate. + +It's important to specify the right compiler options. These include: + +* the language edition (which can be found in the ``Cargo.toml`` file) + +* the ``--cfg`` (which have to be "reverse engineered" from the ``build.rs`` + file of the crate). + +* usually, a ``--cap-lints allow`` argument to hide warnings from rustc + or clippy. + +After every change to the ``meson.build`` file you have to update the patched +version with ``meson subprojects update --reset ``NAME-SEMVER-rs``. This might +be automated in the future. + +Also, after every change to the ``meson.build`` file it is strongly suggested to +do a dummy change to the ``.wrap`` file (for example adding a comment like +``# version 2``), which will help Meson notice that the subproject is out of date. + +As a last step, add the new subproject to ``scripts/archive-source.sh``, +``scripts/make-release`` and ``subprojects/.gitignore``. From patchwork Mon Feb 10 10:22:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13967609 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 52CC6C0219D for ; Mon, 10 Feb 2025 10:24:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thQwd-0002N1-0C; Mon, 10 Feb 2025 05:23: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 1thQwb-0002ML-9d for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1thQwZ-0000Lj-Sw for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739182990; 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=PTpZU6C+PVHvakVak4NM4kkJCm6RFTzLKXCDFFbmoAQ=; b=FZ2STHFh26ZTEvQ4t3CjDxWXVHgC6fjrEAfSANqmSYW6LI9OhmcOqRBI5mzFeZUvCLg8gS IBbKWueb6DgMrMe95nin7YskDkGDqsmCDyk8TYKR3W2PVCYlf/ilKSgY6ExhfU23nkn0sr NpF/Z42uzgYz15Pyv5PuLrHJ6fJMx4s= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-501-1PvkXmhaNvaD3FjZmaH_Kg-1; Mon, 10 Feb 2025 05:23:06 -0500 X-MC-Unique: 1PvkXmhaNvaD3FjZmaH_Kg-1 X-Mimecast-MFC-AGG-ID: 1PvkXmhaNvaD3FjZmaH_Kg Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ab7912ce928so273491866b.0 for ; Mon, 10 Feb 2025 02:23:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739182985; x=1739787785; 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=PTpZU6C+PVHvakVak4NM4kkJCm6RFTzLKXCDFFbmoAQ=; b=D2ab47iTpFkR4zYg5rzcHCDQHz1tDLe8QHVqkuUxhGSG7MbqkyO2SR0OcXPT2CsT3u yXII7RLMpkD6gW5sXjYsLfKpqaJwVmfY8nEx/0zAd+g2y293loQ23v0GXLtcom6yCA4z drQK6jcf08n7cebovZNVPG2pUT4BWZuArGsvQC7ScjdFUnRHRhL/emD42pUB0ifq/Sho U95r3sHkDNfBSiYyyqW6wovYD77gj1tS971KQIDjqHwysE4EFxo1VLEhbRgzPoloyFxP AtUT8HRBb4cofVpaYlNfrZ3ji1t58K4pDNqz5cA0rF4RdG45H6SvZhWZq6bsNlP8S4aE +DCQ== X-Gm-Message-State: AOJu0YwL8oz56ZB/kJjXwRKaKnBN0fOcOARpD+aILepoFBLzvop2ce2y ANx+q/G7DdHwJCJAx1CnL2AGW4Fl22GOQf/ebUvVA+6ExQoIL/mQWFKiMXauPEza0MQ9GAybN4h fs+I7oMRRIlxexgoT/W1P6CM7VH1z2H0p1VpgdBZbJqua2Bp1aWAhZzzLLjDX5ExuPGipUE32Jg xCEYNYnUzZxGeB6PRY4OgQZHN0Ic7iZjZu/p31V8I= X-Gm-Gg: ASbGncucLdMy9opsUnHBhYIpCyBI/XarjnU6wt0kXMB0razo21doq1D3QCwKNRtvBKh lGPzmGpzMmPnt28bW1/nxp9vo7yqrLKRetsm9AiXIhHRmsAFdKblfWxcopvpMJ+NhFfkHckmcnD YmbnONKLVaEPWRlege3LaLKmKwdgX3qimVJDiVgXnis27sF6Vd5b8YNsbffkwWUjo5y72IwQ/Ns GVNwpGKFKACYNgmwEFY1Lo9uuidVuSUWyIDx/9PTaGN8eRvPO+gLlReS2OyYoPpK2d/0JiL9GAP AWkbAQ== X-Received: by 2002:a17:907:7fa3:b0:ab6:e04e:b29 with SMTP id a640c23a62f3a-ab76e84c376mr1551797766b.3.1739182984721; Mon, 10 Feb 2025 02:23:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHf6fTBTf6Jag48tCbTAC1nJ/43O5xpujFkxLU5rYXDzbxpasSy6o54cM70TDxhlnwCLvhzcA== X-Received: by 2002:a17:907:7fa3:b0:ab6:e04e:b29 with SMTP id a640c23a62f3a-ab76e84c376mr1551795766b.3.1739182984259; Mon, 10 Feb 2025 02:23:04 -0800 (PST) Received: from [192.168.10.3] ([151.62.97.55]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab784d4aadbsm733939566b.113.2025.02.10.02.23.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 02:23:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 4/9] rust: add clippy configuration file Date: Mon, 10 Feb 2025 11:22:49 +0100 Message-ID: <20250210102255.2555097-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250210102255.2555097-1-pbonzini@redhat.com> References: <20250210102255.2555097-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: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.405, 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=-1, RCVD_IN_MSPIKE_WL=-0.01, 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 Configure the minimum supported Rust version (though strictly speaking that's redundant with Cargo.toml), and the list of CamelCase identifiers that are not Rust types. Signed-off-by: Paolo Bonzini --- rust/clippy.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 rust/clippy.toml diff --git a/rust/clippy.toml b/rust/clippy.toml new file mode 100644 index 00000000000..5d190f91dec --- /dev/null +++ b/rust/clippy.toml @@ -0,0 +1,2 @@ +doc-valid-idents = ["PrimeCell", ".."] +msrv = "1.63.0" From patchwork Mon Feb 10 10:22:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13967602 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 DD006C0219D for ; Mon, 10 Feb 2025 10:23:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thQwe-0002Nc-Qr; Mon, 10 Feb 2025 05:23:16 -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 1thQwc-0002Ms-Ll for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1thQwa-0000Lq-2X for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739182991; 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=33vv0LTRkoa8007dZV9o44ZqrRUf3Wofq/Zn2BVSNwk=; b=T3JMSs7y06pWc+B6D6ChFMDuSttz4QH25uOp5g8LIMIvoGgdv9HemvxA391959Q6zHPbSX dfFfijRAX3S4bddxCqGybs2Q8XR/KdV9zzOHtDyV3qcfc0r1unrB2xMpP1rML7pJYPRnre C78pdF5UU0K4zqojqW1IneTM3A5ywCc= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-230-XSqTcDfbPyK4gejA6Z9-bA-1; Mon, 10 Feb 2025 05:23:08 -0500 X-MC-Unique: XSqTcDfbPyK4gejA6Z9-bA-1 X-Mimecast-MFC-AGG-ID: XSqTcDfbPyK4gejA6Z9-bA Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5de4c781e00so2612824a12.1 for ; Mon, 10 Feb 2025 02:23:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739182987; x=1739787787; 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=33vv0LTRkoa8007dZV9o44ZqrRUf3Wofq/Zn2BVSNwk=; b=kCfYkPL8OY54rKS/mxs/5kq8/F20nwZR8UrolkeJyye861vgyEodxkkHREwBk8DqqI uG+c+orZC4CSW9cEzvvqc8QH3L9527HZH+pkCg17WwO0SMhoW1sJtOuzHA8sQnGbL7QZ Wn3xGIGFSqsRmyjv+xRzk+r1aExNOkXDdSo/crjG8KcSImLaZ9KzDK/HUOhXWZldxsaF LYLkIT3c6t4NZo9llfdjcG9oPj1buG6D+0VHoH4GveJX/B5EmFoE0ip6mYXuFdVhDj/a NlZ6pzprq+YDraJlp4xrV+3qmXoM8u37r/sXgnHaHUINCsuOmE5gLS+zxxbrVectHk2k 4JsA== X-Gm-Message-State: AOJu0YxOrAUxo5F/E0T5tNgYYMaPSDlEuIy7mEuxrLicB1AQnWsgWJlY 9l4SxC6pDjsF9TF1yDXNLjL8o1aR231k/OmJhY94xhVlxv0EN0zgmY17HBENXVkWDjB78JPxFOv rWPnwgnI7BJOFe7vf7wyU10wShH4p2iP2sgoPOiz1iLxXoN8GhVRKud6XiOW3gPrewfBn9yHoP0 m+2BHoYswGbvV0dKRW+eneUsVJ6ZWbMjxjIJxgdvI= X-Gm-Gg: ASbGnctwk0RGZ/7SSRkdbtWdw3bl7HbdjPccOv7fbqPxDNH6+W1TFjj3IcPETWo7+xI 3SV3n8TsaNHh1T+v4uXwNn/dh0w8QscdZQLv/DHn3BkQaEJ7V+EqihrF1NNixOrJyloDBrcCnlV HT2f+66WhR5/vOZVV96CAp/s8NfGyMAWW9gGAhPkzq7OyJfUoKyq0jDF7fnGORU2XB4SPTmjNI1 qoS/LZSGviKrsIAo4jcV312MDUhnNHGbmFYc67z18aB8FDLQcHDV3lxq7FcuulHW3bS/m3IaryH dSAaWw== X-Received: by 2002:a05:6402:26cf:b0:5de:3c29:e82e with SMTP id 4fb4d7f45d1cf-5de45070668mr15804250a12.18.1739182986603; Mon, 10 Feb 2025 02:23:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4hg57/FyN8f0hF2Xs9hC0ipRFwFCwAaB0O7kI6bUrycwPXM552SFj2ZdML/VSQgVkb3W1Lw== X-Received: by 2002:a05:6402:26cf:b0:5de:3c29:e82e with SMTP id 4fb4d7f45d1cf-5de45070668mr15804214a12.18.1739182986000; Mon, 10 Feb 2025 02:23:06 -0800 (PST) Received: from [192.168.10.3] ([151.62.97.55]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5de72da5ce6sm2531551a12.51.2025.02.10.02.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 02:23:05 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Peter Maydell , qemu-stable@nongnu.org, Richard Henderson Subject: [PULL 5/9] target/i386: Do not raise Invalid for 0 * Inf + QNaN Date: Mon, 10 Feb 2025 11:22:50 +0100 Message-ID: <20250210102255.2555097-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250210102255.2555097-1-pbonzini@redhat.com> References: <20250210102255.2555097-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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.405, 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.01, 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: Peter Maydell In commit 8adcff4ae7 ("fpu: handle raising Invalid for infzero in pick_nan_muladd") we changed the handling of 0 * Inf + QNaN to always raise the Invalid exception regardless of target architecture. (This was a change affecting hppa, i386, sh4 and tricore.) However, this was incorrect for i386, which documents in the SDM section 14.5.2 that for the 0 * Inf + NaN case that it will only raise the Invalid exception when the input is an SNaN. (This is permitted by the IEEE 754-2008 specification, which documents that whether we raise Invalid for 0 * Inf + QNaN is implementation defined.) Adjust the softfloat pick_nan_muladd code to allow the target to suppress the raising of Invalid for the inf * zero + NaN case (as an extra flag orthogonal to its choice for when to use the default NaN), and enable that for x86. We do not revert here the behaviour change for hppa, sh4 or tricore: * The sh4 manual is clear that it should signal Invalid * The tricore manual is a bit vague but doesn't say it shouldn't * The hppa manual doesn't talk about fused multiply-add corner cases at all Cc: qemu-stable@nongnu.org Fixes: 8adcff4ae7 (""fpu: handle raising Invalid for infzero in pick_nan_muladd") Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20250116112536.4117889-2-peter.maydell@linaro.org Signed-off-by: Paolo Bonzini --- include/fpu/softfloat-types.h | 16 +++++++++++++--- target/i386/tcg/fpu_helper.c | 5 ++++- fpu/softfloat-parts.c.inc | 5 +++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h index 616c290145f..2e43d1dd9e6 100644 --- a/include/fpu/softfloat-types.h +++ b/include/fpu/softfloat-types.h @@ -280,11 +280,21 @@ typedef enum __attribute__((__packed__)) { /* No propagation rule specified */ float_infzeronan_none = 0, /* Result is never the default NaN (so always the input NaN) */ - float_infzeronan_dnan_never, + float_infzeronan_dnan_never = 1, /* Result is always the default NaN */ - float_infzeronan_dnan_always, + float_infzeronan_dnan_always = 2, /* Result is the default NaN if the input NaN is quiet */ - float_infzeronan_dnan_if_qnan, + float_infzeronan_dnan_if_qnan = 3, + /* + * Don't raise Invalid for 0 * Inf + NaN. Default is to raise. + * IEEE 754-2008 section 7.2 makes it implementation defined whether + * 0 * Inf + QNaN raises Invalid or not. Note that 0 * Inf + SNaN will + * raise the Invalid flag for the SNaN anyway. + * + * This is a flag which can be ORed in with any of the above + * DNaN behaviour options. + */ + float_infzeronan_suppress_invalid = (1 << 7), } FloatInfZeroNaNRule; /* diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 3d764bc138d..de6d0b252ec 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -178,8 +178,11 @@ void cpu_init_fp_statuses(CPUX86State *env) * "Fused-Multiply-ADD (FMA) Numeric Behavior" the NaN handling is * specified -- for 0 * inf + NaN the input NaN is selected, and if * there are multiple input NaNs they are selected in the order a, b, c. + * We also do not raise Invalid for the 0 * inf + (Q)NaN case. */ - set_float_infzeronan_rule(float_infzeronan_dnan_never, &env->sse_status); + set_float_infzeronan_rule(float_infzeronan_dnan_never | + float_infzeronan_suppress_invalid, + &env->sse_status); set_float_3nan_prop_rule(float_3nan_prop_abc, &env->sse_status); /* Default NaN: sign bit set, most significant frac bit set */ set_float_default_nan_pattern(0b11000000, &env->fp_status); diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index fee05d0a863..73621f4a970 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -126,7 +126,8 @@ static FloatPartsN *partsN(pick_nan_muladd)(FloatPartsN *a, FloatPartsN *b, float_raise(float_flag_invalid | float_flag_invalid_snan, s); } - if (infzero) { + if (infzero && + !(s->float_infzeronan_rule & float_infzeronan_suppress_invalid)) { /* This is (0 * inf) + NaN or (inf * 0) + NaN */ float_raise(float_flag_invalid | float_flag_invalid_imz, s); } @@ -144,7 +145,7 @@ static FloatPartsN *partsN(pick_nan_muladd)(FloatPartsN *a, FloatPartsN *b, * Inf * 0 + NaN -- some implementations return the * default NaN here, and some return the input NaN. */ - switch (s->float_infzeronan_rule) { + switch (s->float_infzeronan_rule & ~float_infzeronan_suppress_invalid) { case float_infzeronan_dnan_never: break; case float_infzeronan_dnan_always: From patchwork Mon Feb 10 10:22:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13967606 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 AD041C0219D for ; Mon, 10 Feb 2025 10:24:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thQwg-0002Ol-O0; Mon, 10 Feb 2025 05:23:18 -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 1thQwe-0002NU-1T for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23: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 1thQwb-0000MN-TT for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739182993; 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=dGTMV/JVOhgwSD7zfFhjmY9o50J6ILSLJjCbihcs1Oc=; b=CLU+pHR5G8/IA2aIndM1i2IjbdSlB8xAaMmU8z83Qhq3aYxXNzLhzikVi5WsaWaFiODp/G udDjrPoB38gB9FOJLXfZn/jSzH7UvYWo3utyOcYDkteK1KkbOz3PMQYhNMCrAZSVWjm8KI rBGnNlD3mHTAnF++buLggggNMxeOwJA= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-333-IKXnFx1ONMSw8OeeRsWHng-1; Mon, 10 Feb 2025 05:23:11 -0500 X-MC-Unique: IKXnFx1ONMSw8OeeRsWHng-1 X-Mimecast-MFC-AGG-ID: IKXnFx1ONMSw8OeeRsWHng Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ab79858cd31so234989666b.2 for ; Mon, 10 Feb 2025 02:23:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739182989; x=1739787789; 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=dGTMV/JVOhgwSD7zfFhjmY9o50J6ILSLJjCbihcs1Oc=; b=tMeC/GUsM24zLFYt4uwGlAGYdMCI/a9YE2f3WPRlfW7+9SKEnyOuauYhvxJqDjMCA3 92Z7Xq+ssSIcjViYmy7WWwWwouCa56XdqGR77M1yfpcH93Nq8xE3XZ5W859REo8wqjMN S7WfO9wbo+/jukrUw4YDMfzfspeHU15b0Yl2leDaiWi/Ka85ReEkdJLGOsaIGLXCbjr0 FojVwL8+9xNUC5FsqYldMwPuGOsK9+JAYxXScKjGXDVkeOltA4RKv9MsxxD66sosxevt RpE0X6L63UcrG0WaO/i7ks16MSDZvKj5ZH8QqYu1xlyDWXZjUdVoKzqiw1ZsgLElX2yv 4Q2A== X-Gm-Message-State: AOJu0Yz+vP3d3644zrZOFScmA2thf1F8X8FnNgr2CXXfEjXPuPYYYelC +lpYhDDHe+HTVI2YYajzeSKxkCrismZfsyzy9vR/RbSX50mv/u04KvzcBDGDe7t1PYMTNk/U/yR ltepD0kqx38c9AS3DCjPy/nmD2ZrsQ1IL1I3+D0CWSzsHXR7DaloeiBH7OuJX7RRRazvi8ucwIT QucsQWyA6LGZ9vDJSErCJ+4ymbmijpsD9Ivqt00Ko= X-Gm-Gg: ASbGnctsLLgf6+NdYd4YEFP9j1V8xroL8GiDN3zyks7JPyFYKsxQgXJrm5woAbPh2ZW 0SSPi1jcb/glsZnb45dqFLrlB0jfwjZpwbWpNp+DTirqn7sgOlWyNbF2jjvSFJFoyB4V6n1vHuu B6k+6X2JroP5Fl+QFqvoW+dDe063f1IjPvhOFgkoIFhCjprRoCRho0/cfRrVJqlYhAnXH3eoxlV Sa5FvPDHYXcQ0NKd/B7fbdsAknaT/qVjDj51xx1SfaAzbkNfnHmxKOKXdn0y0/F4Da/isJQOPTA xjtpwg== X-Received: by 2002:a17:907:1b27:b0:aa6:8cbc:8d15 with SMTP id a640c23a62f3a-ab789ac0169mr1438222166b.14.1739182989010; Mon, 10 Feb 2025 02:23:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8EDm970Ti+/x53SCyJTQQFHqYprLsbtmqNW2lJA/pPggmIi42D9VTRl9rx6GKYllKCZbmDg== X-Received: by 2002:a17:907:1b27:b0:aa6:8cbc:8d15 with SMTP id a640c23a62f3a-ab789ac0169mr1438219166b.14.1739182988387; Mon, 10 Feb 2025 02:23:08 -0800 (PST) Received: from [192.168.10.3] ([151.62.97.55]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab79bf7ca1esm538707366b.30.2025.02.10.02.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 02:23:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson Subject: [PULL 6/9] tests/tcg/x86_64/fma: Test some x86 fused-multiply-add cases Date: Mon, 10 Feb 2025 11:22:51 +0100 Message-ID: <20250210102255.2555097-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250210102255.2555097-1-pbonzini@redhat.com> References: <20250210102255.2555097-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: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.405, 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=-1, RCVD_IN_MSPIKE_WL=-0.01, 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: Peter Maydell Add a test case which tests some corner case behaviour of fused-multiply-add on x86: * 0 * Inf + SNaN should raise Invalid * 0 * Inf + QNaN shouldh not raise Invalid * tininess should be detected after rounding There is also one currently-disabled test case: * flush-to-zero should be done after rounding This is disabled because QEMU's emulation currently does this incorrectly (and so would fail the test). The test case is kept in but disabled, as the justification for why the test running harness has support for testing both with and without FTZ set. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Link: https://lore.kernel.org/r/20250116112536.4117889-3-peter.maydell@linaro.org Signed-off-by: Paolo Bonzini --- tests/tcg/x86_64/fma.c | 109 +++++++++++++++++++++++++++++++ tests/tcg/x86_64/Makefile.target | 1 + 2 files changed, 110 insertions(+) create mode 100644 tests/tcg/x86_64/fma.c diff --git a/tests/tcg/x86_64/fma.c b/tests/tcg/x86_64/fma.c new file mode 100644 index 00000000000..09c622ebc00 --- /dev/null +++ b/tests/tcg/x86_64/fma.c @@ -0,0 +1,109 @@ +/* + * Test some fused multiply add corner cases. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include +#include + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +/* + * Perform one "n * m + a" operation using the vfmadd insn and return + * the result; on return *mxcsr_p is set to the bottom 6 bits of MXCSR + * (the Flag bits). If ftz is true then we set MXCSR.FTZ while doing + * the operation. + * We print the operation and its results to stdout. + */ +static uint64_t do_fmadd(uint64_t n, uint64_t m, uint64_t a, + bool ftz, uint32_t *mxcsr_p) +{ + uint64_t r; + uint32_t mxcsr = 0; + uint32_t ftz_bit = ftz ? (1 << 15) : 0; + uint32_t saved_mxcsr = 0; + + asm volatile("stmxcsr %[saved_mxcsr]\n" + "stmxcsr %[mxcsr]\n" + "andl $0xffff7fc0, %[mxcsr]\n" + "orl %[ftz_bit], %[mxcsr]\n" + "ldmxcsr %[mxcsr]\n" + "movq %[a], %%xmm0\n" + "movq %[m], %%xmm1\n" + "movq %[n], %%xmm2\n" + /* xmm0 = xmm0 + xmm2 * xmm1 */ + "vfmadd231sd %%xmm1, %%xmm2, %%xmm0\n" + "movq %%xmm0, %[r]\n" + "stmxcsr %[mxcsr]\n" + "ldmxcsr %[saved_mxcsr]\n" + : [r] "=r" (r), [mxcsr] "=m" (mxcsr), + [saved_mxcsr] "=m" (saved_mxcsr) + : [n] "r" (n), [m] "r" (m), [a] "r" (a), + [ftz_bit] "r" (ftz_bit) + : "xmm0", "xmm1", "xmm2"); + *mxcsr_p = mxcsr & 0x3f; + printf("vfmadd132sd 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 + " = 0x%" PRIx64 " MXCSR flags 0x%" PRIx32 "\n", + n, m, a, r, *mxcsr_p); + return r; +} + +typedef struct testdata { + /* Input n, m, a */ + uint64_t n; + uint64_t m; + uint64_t a; + bool ftz; + /* Expected result */ + uint64_t expected_r; + /* Expected low 6 bits of MXCSR (the Flag bits) */ + uint32_t expected_mxcsr; +} testdata; + +static testdata tests[] = { + { 0, 0x7ff0000000000000, 0x7ff000000000aaaa, false, /* 0 * Inf + SNaN */ + 0x7ff800000000aaaa, 1 }, /* Should be QNaN and does raise Invalid */ + { 0, 0x7ff0000000000000, 0x7ff800000000aaaa, false, /* 0 * Inf + QNaN */ + 0x7ff800000000aaaa, 0 }, /* Should be QNaN and does *not* raise Invalid */ + /* + * These inputs give a result which is tiny before rounding but which + * becomes non-tiny after rounding. x86 is a "detect tininess after + * rounding" architecture, so it should give a non-denormal result and + * not set the Underflow flag (only the Precision flag for an inexact + * result). + */ + { 0x3fdfffffffffffff, 0x001fffffffffffff, 0x801fffffffffffff, false, + 0x8010000000000000, 0x20 }, + /* + * Flushing of denormal outputs to zero should also happen after + * rounding, so setting FTZ should not affect the result or the flags. + * QEMU currently does not emulate this correctly because we do the + * flush-to-zero check before rounding, so we incorrectly produce a + * zero result and set Underflow as well as Precision. + */ +#ifdef ENABLE_FAILING_TESTS + { 0x3fdfffffffffffff, 0x001fffffffffffff, 0x801fffffffffffff, true, + 0x8010000000000000, 0x20 }, /* Enabling FTZ shouldn't change flags */ +#endif +}; + +int main(void) +{ + bool passed = true; + for (int i = 0; i < ARRAY_SIZE(tests); i++) { + uint32_t mxcsr; + uint64_t r = do_fmadd(tests[i].n, tests[i].m, tests[i].a, + tests[i].ftz, &mxcsr); + if (r != tests[i].expected_r) { + printf("expected result 0x%" PRIx64 "\n", tests[i].expected_r); + passed = false; + } + if (mxcsr != tests[i].expected_mxcsr) { + printf("expected MXCSR flags 0x%x\n", tests[i].expected_mxcsr); + passed = false; + } + } + return passed ? 0 : 1; +} diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.target index d6dff559c7d..be20fc64e88 100644 --- a/tests/tcg/x86_64/Makefile.target +++ b/tests/tcg/x86_64/Makefile.target @@ -18,6 +18,7 @@ X86_64_TESTS += adox X86_64_TESTS += test-1648 X86_64_TESTS += test-2175 X86_64_TESTS += cross-modifying-code +X86_64_TESTS += fma TESTS=$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64 else TESTS=$(MULTIARCH_TESTS) From patchwork Mon Feb 10 10:22:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13967607 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 D3403C021A2 for ; Mon, 10 Feb 2025 10:24:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thQwi-0002PB-7z; Mon, 10 Feb 2025 05:23: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 1thQwg-0002Ok-Jc for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23: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 1thQwf-0000N5-65 for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739182996; 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=79wQisxmrG4uGvWqFVzBGJF7Meflxb2NnqvI+vXjWx4=; b=RMRRAGNEJMVLwD3Oy/ruJbGYMsyZRo8AhI+bcDHK1MY4RTmBRCfXfqLnLK/rATH3fWew8A XMgxvdNSYwf9YzfRXab683gN9PW3OUwoBHoR2UKWz9sui2Zs4xAg1ElXbZhGqZl7b9aEGK bcwGGmLLdCBrvah4hBpqLkzjmWGPRuo= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-193-MPZhp_wmOFGnO9yN2j8ywg-1; Mon, 10 Feb 2025 05:23:12 -0500 X-MC-Unique: MPZhp_wmOFGnO9yN2j8ywg-1 X-Mimecast-MFC-AGG-ID: MPZhp_wmOFGnO9yN2j8ywg Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-ab77dd2c243so420376066b.0 for ; Mon, 10 Feb 2025 02:23:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739182991; x=1739787791; 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=79wQisxmrG4uGvWqFVzBGJF7Meflxb2NnqvI+vXjWx4=; b=WoAL0Y3GEJxH+iqrWi6lieeaT9rXORkzjUXCXpwTVurC33aRRSAM8FjgdSAgScMYEu BaPLdkeJXwJXiJz+mf3WiBQGSs+kSg4V1uF5NLS+ANBc/O0sElrWsD0C6xBwCge7DsJV oS8DVRALgR4IejwBhAoh9fLquskYR59w9DdSJ4eIESCKGT5Aa87l6FdqRxaEhT4rDFNC iHNElhOzwDTuFV/Mp0okroEamUMDFGMMt6wynaX2eLrX9bpUCVo5r9yCuZzFoiL3s2iJ n2sq53Ixgj9tPrRkuim+M7CDpgEFyKGrjiil1g3noHiGVuAqbWBDc5FJnQS1HQLd438N 51VQ== X-Gm-Message-State: AOJu0YxPhJ2PtHPgc4fsHjURxgmzRNTGr9MButzS6z6llP7ADS4dKdWC /jknziBYiW/wWRB1SQHiXCJT/0FCieYy+dchYcvkQGFYcsTWgkngcNMJSNNi7dy8ESUMSwKvayB sNuw/FItzEAxeAJJwi4cp6l2qj88qVULQmIbTimQK0LhcB7ajC3J47Twl0gGK6G8u/lIO7g6zdq dihf8ZLRYvCiwCDrOv3G74v/nf2Yubg0xB85TsHW8= X-Gm-Gg: ASbGnculdpSjAIL0AOy6wSH9zSCWN5cFuboDdTxUnju52cdX4RK5McEOmSY2uuSWSEm FtR5BLSVICHpmvpiNnnZK1tl2rcy/EXHLTTnB+OPVGZO/c5Fl7v4yq1Slwfkbz0bS8KgwYIx3l/ fuCBkdPPcugH4g6P/O5C+s7NMFNesebE/d1oIb5aAJl0ciH8f+i2ja7Tjck8ecV0mNVK3LDUicm dE1YetkAtIIR3TvKMM3tHlEBtSwRPV+II3u9MobImU23RRvsKts0QFmrpvXybbDn4E8mPVKM3Iu YcbZJA== X-Received: by 2002:a05:6402:3907:b0:5dc:8fb1:d43e with SMTP id 4fb4d7f45d1cf-5de4501882bmr13983998a12.12.1739182991224; Mon, 10 Feb 2025 02:23:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnXapblXN6zG9dxVW9fDKQHoLxx7wjPdumnzuYNDxDW8D4aEQCO2N+dPprArBnTw1RddiBAg== X-Received: by 2002:a05:6402:3907:b0:5dc:8fb1:d43e with SMTP id 4fb4d7f45d1cf-5de4501882bmr13983979a12.12.1739182990673; Mon, 10 Feb 2025 02:23:10 -0800 (PST) Received: from [192.168.10.3] ([151.62.97.55]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dcf9f6c1d6sm7520534a12.65.2025.02.10.02.23.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 02:23:09 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 7/9] tcg/optimize: optimize TSTNE using smask and zmask Date: Mon, 10 Feb 2025 11:22:52 +0100 Message-ID: <20250210102255.2555097-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250210102255.2555097-1-pbonzini@redhat.com> References: <20250210102255.2555097-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: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.405, 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=-1, RCVD_IN_MSPIKE_WL=-0.01, 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 Generalize the existing optimization of "TSTNE x,sign" and "TSTNE x,-1". This can be useful for example in the i386 frontend, which will generate tests of zero-extended registers against 0xffffffff. Ironically, on x86 hosts this is a very slight pessimization in the very case it's meant to optimize because brcond_i64 cc_dst,$0xffffffff,tsteq,$L1 (test %ebx, %ebx) is 1 byte smaller than brcond_i64 cc_dst,$0x0,eq,$L1 (test %rbx, %rbx). However, in general it is an improvement, especially if it avoids placing a large immediate in the constant pool. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- tcg/optimize.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 8c6303e3afa..bca11cc427b 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -766,6 +766,7 @@ static int do_constant_folding_cond1(OptContext *ctx, TCGOp *op, TCGArg dest, TCGArg *p1, TCGArg *p2, TCGArg *pcond) { TCGCond cond; + TempOptInfo *i1; bool swap; int r; @@ -783,19 +784,21 @@ static int do_constant_folding_cond1(OptContext *ctx, TCGOp *op, TCGArg dest, return -1; } + i1 = arg_info(*p1); + /* * TSTNE x,x -> NE x,0 - * TSTNE x,-1 -> NE x,0 + * TSTNE x,i -> NE x,0 if i includes all nonzero bits of x */ - if (args_are_copies(*p1, *p2) || arg_is_const_val(*p2, -1)) { + if (args_are_copies(*p1, *p2) || + (arg_is_const(*p2) && (i1->z_mask & ~arg_info(*p2)->val) == 0)) { *p2 = arg_new_constant(ctx, 0); *pcond = tcg_tst_eqne_cond(cond); return -1; } - /* TSTNE x,sign -> LT x,0 */ - if (arg_is_const_val(*p2, (ctx->type == TCG_TYPE_I32 - ? INT32_MIN : INT64_MIN))) { + /* TSTNE x,i -> LT x,0 if i only includes sign bit copies */ + if (arg_is_const(*p2) && (arg_info(*p2)->val & ~i1->s_mask) == 0) { *p2 = arg_new_constant(ctx, 0); *pcond = tcg_tst_ltge_cond(cond); return -1; From patchwork Mon Feb 10 10:22:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13967605 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 CEEF5C0219E for ; Mon, 10 Feb 2025 10:24:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thQwh-0002P9-Qz; Mon, 10 Feb 2025 05:23: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 1thQwg-0002Ow-SR for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23: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 1thQwf-0000N7-D0 for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739182996; 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=ZIZqG/E9D5i5Jo+tlmoRFu4ynuvOisUz6AS8Y0OYPXQ=; b=SNpxUiPYkyoZbynHnyflZdGEamUJpm4IeI0cNVV1azwuS+Ok/oKDUmCFQxc71T3AKLzx9l A+WASQaJkEhQ7UsMz2xD4e1ksLh8m/XsJ24q7e4HWss0C75xjq6VWxZIc4QiTC0bVb38bM LJJHoxHWSxGZJP1Uahv+g7gZwbLrfys= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-GFtZs3FAO8G7UiL31x_gxQ-1; Mon, 10 Feb 2025 05:23:15 -0500 X-MC-Unique: GFtZs3FAO8G7UiL31x_gxQ-1 X-Mimecast-MFC-AGG-ID: GFtZs3FAO8G7UiL31x_gxQ Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5de909cf05dso97995a12.2 for ; Mon, 10 Feb 2025 02:23:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739182993; x=1739787793; 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=ZIZqG/E9D5i5Jo+tlmoRFu4ynuvOisUz6AS8Y0OYPXQ=; b=w3AFp4lT3qEtULmGAH+nc26RIwzG6tp/k/nOAGTs/PNp9RGJvnbQwqvdJvPMCBvB+p yDevWLHTE1V+h5VfTtIi6400AVX6TOp+jyXa3h1OKi8kETMVC0fvCUH/71Y+/5OpnXMS w+q6kD+S80Umf4kkyLNXZ0qQI/bA9WVID9ItLbLkJjhHvaKhPguDvExkr8kLl7vIYp6O hS3HGiKi2GhAzI6c6KV6JAIm/Df4vmivHqxdsbE8KdQAOXLW7+P9XPBja58fxfJoErsd Mvrho02wV/PgdqdbVM+4IPyULzBqKgYfhy2FLcDEphYXrf/ntmzWfaenZBtm7aI3lOFU fezA== X-Gm-Message-State: AOJu0Yzzh36c/iHB2IBOTKkett3iVhREIUpbjNAfx2zFzPJ57tWaMbIl VKz9XhzdyI+B98pQovs4qXib3+jscjB+KtPVS90g5x1waxYulhlRd9rIK8j7T2VYdvSoyj0fgAj y/wnVxT5QnUwRg2VPgS7p3G0bwQwso+WsTddbVNboQ70xGWdX3Rv2n2YhdwuNrINqzLsQiFXmhS OLE3aDG7EFS2wHDppwZvqt1W3w3c0D+neaTR3AztI= X-Gm-Gg: ASbGncuThhX/FfZeDttMOKNr/R9i02/yuuvnzgQhZcVF9xH6T4SQhEF5oFBo74OAZUR hNARQfQBmWSRPPJSZNPRFy9rYj0ZskSys9N+ng3PAfBymGBK+ZvnON+yIAvULRd8X5JR1NIAYs6 Syl9uGO6tFekBoBiFjl5y9SssKgyvAPUylko5oWcA5vO3XlA+HS0wQs+jZE41IK7y5/wSuBzIuw PfmwE6M2guNZqKYhAxVdUyi3kUObUrBoCkrRj72Tk7KJJJfmakT+FWJofQoyqZPl10a0QsrLMgZ lTzSJg== X-Received: by 2002:a05:6402:4416:b0:5dc:c9ce:b022 with SMTP id 4fb4d7f45d1cf-5de45005a55mr14306442a12.9.1739182992868; Mon, 10 Feb 2025 02:23:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEy5fL0lT9GaNDmcNc/RBQwZNb5t6rRPxWWdmRPF8SPHBew+QLNoiuPT0PLbkOvDfBnI/N+Kw== X-Received: by 2002:a05:6402:4416:b0:5dc:c9ce:b022 with SMTP id 4fb4d7f45d1cf-5de45005a55mr14306425a12.9.1739182992438; Mon, 10 Feb 2025 02:23:12 -0800 (PST) Received: from [192.168.10.3] ([151.62.97.55]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5de4c9b890dsm6032657a12.56.2025.02.10.02.23.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 02:23:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi Subject: [PULL 8/9] rust: pl011: use default set of lints Date: Mon, 10 Feb 2025 11:22:53 +0100 Message-ID: <20250210102255.2555097-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250210102255.2555097-1-pbonzini@redhat.com> References: <20250210102255.2555097-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: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.405, 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=-1, RCVD_IN_MSPIKE_WL=-0.01, 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 Being the first crate added to QEMU, pl011 has a rather restrictive Clippy setup. This can be sometimes a bit too heavy on its suggestions, for example error: this could be a `const fn` --> hw/char/pl011/src/device.rs:382:5 | 382 | / fn set_read_trigger(&mut self) { 383 | | self.read_trigger = 1; 384 | | } | |_____^ Just use the standard set that is present in rust/Cargo.toml, with just a small adjustment to allow upper case acronyms which are used for register names. Reported-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/lib.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/rust/hw/char/pl011/src/lib.rs b/rust/hw/char/pl011/src/lib.rs index e704daf6e3e..3c72f1221ff 100644 --- a/rust/hw/char/pl011/src/lib.rs +++ b/rust/hw/char/pl011/src/lib.rs @@ -12,16 +12,7 @@ //! See [`PL011State`](crate::device::PL011State) for the device model type and //! the [`registers`] module for register types. -#![deny( - clippy::correctness, - clippy::suspicious, - clippy::complexity, - clippy::perf, - clippy::nursery, - clippy::style -)] #![allow(clippy::upper_case_acronyms)] -#![allow(clippy::result_unit_err)] use qemu_api::c_str; From patchwork Mon Feb 10 10:22:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13967601 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 BD815C02198 for ; Mon, 10 Feb 2025 10:23:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thQwk-0002QX-V2; Mon, 10 Feb 2025 05:23: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 1thQwj-0002Pi-2Y for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:21 -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 1thQwh-0000NW-Gs for qemu-devel@nongnu.org; Mon, 10 Feb 2025 05:23:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739182998; 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=H1s7l6TURQyL8eCO9/e3NPz0hlAdj5Twhr0tY7ty5ok=; b=KSy6fc4MX8bYfnLo+MIhvXBI0gNs+xA8G19AbmrsRAyfQg642ihUUU4DMpFNEuVEcBZ88S ElXA2kLGQCH6W8r47EEjVSFMZVSFK4uqlJb+eIhCgOr5RqadgRr0OWKdcWwqgdst9SOmLr ZClWjSWN1n7kMNihOZ2XZbzeNS2uGls= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-37GHqKcwO-iTkHSEd01aNQ-1; Mon, 10 Feb 2025 05:23:17 -0500 X-MC-Unique: 37GHqKcwO-iTkHSEd01aNQ-1 X-Mimecast-MFC-AGG-ID: 37GHqKcwO-iTkHSEd01aNQ Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ab7a7c8c70aso179698266b.2 for ; Mon, 10 Feb 2025 02:23:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739182996; x=1739787796; 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=H1s7l6TURQyL8eCO9/e3NPz0hlAdj5Twhr0tY7ty5ok=; b=Yi6vkbLBcGYqQKpTl+E0ZzhImampqmr+bf66KIlHaK9EQGoBGfktUyHKMnS4UY6wc2 ODo5PnTkn1GxFTFl6SZppt5rUaWlSq2h8fVAGVGUmgE34eN8HzfjQdxkCjgHpdXk+JqK dZeo4uOXEu07vCcWwn9MyCltIkGu+d/ubY1luFXWPcjrS9zhxGSu2wEItacWDvJz7iq4 E8Bj6T15IWO9dFCoNdFQUnPfY3pGQliA9NjaduK6btaCkRH2gTxnUU5vuQGDF3IjZkTH J2/IOotY8VYRLIUK3SPF/o7OcYS66UAM5aPF0zxjqVNpnq88o9DmHh98PRM+GuJ11PFc RiKg== X-Gm-Message-State: AOJu0Yzp03bmKG0WHqaF7IsZQHIC5mz/Q3vc8l2lRhqCEV9+yNrYmcRU sMJL7T3C4vOUdimiPgjkHB6q6Z8IcQmdXJqriz9ySenaF2PLl9j8fszIdcv9w1Ypc77M/bUwrgx hhOsNzhkymbj2n6pQ4vsu0uwchNvJJI0rShBxam0QqKdqr2rehJrIr2w8yefyAk6p0Cgj7RXtaB 650sQPMmUfog8FA+XqXL2Syzr8HHBQEendNPPbZU4= X-Gm-Gg: ASbGnctLaOt85VgqdCFm7uzoXFgeN0gdyLoYoPMFu2+9xQ7fjvIbxXVAp2TdLBpFu4u uib0XJfkrCcBo+7fHAUNFGnlEIHwMSomXhyCrEdRo88bAC8JNWSPzglaNQXUGtCacHa16hApydo xvy6Lem+TVDl7qoVucNtGb32q3p7VghInHvuXXRWqwEXMc0Ye65VQZMagK/71Hf2eOCrHfGj7NE ZFt7EAoOttn7VLdsBJtnEaCAAZ/dKof8ho4vtt+lngtimNNmQYDr7oH3p2JhVLSL4OJp7Gsjrxj kO+1Pw== X-Received: by 2002:a17:907:724e:b0:ab7:9648:17be with SMTP id a640c23a62f3a-ab796481894mr1046879566b.19.1739182995776; Mon, 10 Feb 2025 02:23:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8IkewaN9mhFyqOkM4ANoRkpKHLlQsYyCryzjrwZgoPgEXFTOlNU6yoxnnNq+tcEo4VrR+Gg== X-Received: by 2002:a17:907:724e:b0:ab7:9648:17be with SMTP id a640c23a62f3a-ab796481894mr1046876966b.19.1739182995184; Mon, 10 Feb 2025 02:23:15 -0800 (PST) Received: from [192.168.10.3] ([151.62.97.55]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab78ee9e208sm663264066b.50.2025.02.10.02.23.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 02:23:13 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 9/9] rust: restrict missing_const_for_fn to qemu_api crate Date: Mon, 10 Feb 2025 11:22:54 +0100 Message-ID: <20250210102255.2555097-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250210102255.2555097-1-pbonzini@redhat.com> References: <20250210102255.2555097-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: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.405, 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=-1, RCVD_IN_MSPIKE_WL=-0.01, 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 missing_const_for_fn is not necessarily useful or good. For example in a private API you can always add const later, and in a public API it can be unnecessarily restrictive to annotate everything with const (blocking further improvements to the API). Nevertheless, QEMU turns it on because qemu_api uses const quite aggressively and therefore it can be handy to have as much as possible annotated with const. Outside qemu_api though, not so much: devices are self contained consumers and if there is nothing that could use their functions in const contexts that were not anticipated. Since missing_const_for_fn can be a bit noisy and trigger on trivial functions that no one would ever call in const context, do not turn it on everywhere and only keep it in qemu_api as a special case. Signed-off-by: Paolo Bonzini --- rust/Cargo.toml | 1 - rust/qemu-api/src/lib.rs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 5b6b6ca4382..5b0cb559286 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -52,7 +52,6 @@ empty_structs_with_brackets = "deny" ignored_unit_patterns = "deny" implicit_clone = "deny" macro_use_imports = "deny" -missing_const_for_fn = "deny" missing_safety_doc = "deny" multiple_crate_versions = "deny" mut_mut = "deny" diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 83c6a987c05..3cf9371cff0 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #![cfg_attr(not(MESON), doc = include_str!("../README.md"))] +#![deny(clippy::missing_const_for_fn)] #[rustfmt::skip] pub mod bindings;