From nobody Thu Jan 23 03:29:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1737467172; cv=none; d=zohomail.com; s=zohoarc; b=IPXJ5Q8ReRHSIUakisywuJ1NTnop/XeNVHc0FIG1D+ZWP26wyQcfrJxksw3wXgB7l5eskRWW2EUhbDE5Fpf6QDoLh33UtpCHXHuP4GxZLOgPMK1gdpeDFoOomOPmnAlxbJi/+/pKLhOLZMWVMrCaOIZKNorAf5xp1jZu2SY9Q2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737467172; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/I0MsgAvmKl8Xv4sLkumk7aato+HUm5+NfUPFEJaqqc=; b=ZOCnrwiXEqzpvhqKwSkoHAzBd6ASDbmlQ5ur4TGUHNKMRnNeS1peH3sBy1q+wjLfWz3TnqsPEoJzGZ9LXRZkryO6D5MjAT012Cew3UbngkcmoIrV1+EShTjVf1l+LT/yHSjzDdTGXqBmpn5tMDLi5ZvPnstunYR2ydfN8IffJJ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737467172244951.47058106267; Tue, 21 Jan 2025 05:46:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1taEZs-0000S0-UW; Tue, 21 Jan 2025 08:46: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 1taEZc-0000QY-SK; Tue, 21 Jan 2025 08:45:44 -0500 Received: from mgamail.intel.com ([192.198.163.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1taEZb-0005st-85; Tue, 21 Jan 2025 08:45:44 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2025 05:45:40 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa006.jf.intel.com with ESMTP; 21 Jan 2025 05:45:39 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1737467143; x=1769003143; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rxFIH1V2S/qGBuJ+RX3At6R9o8UedyIffIiZqAZTIuA=; b=b8i/veLYoBFNLZ/zPdBKmGRwjpENOt937PxByVb7M9p5g89wXBbHesdw YVcfyqVItMXzm8Su0SFVTa2iShfBDulBGbv3bOpcH4/HCiiG+WiCwaTvO iQBGZcDyg/paLTboLNTZHvpT9e9VRb1B2KKQbNm/OoLcPZHCuPm41D3tm jiVfLVhMVKPSxYLt9HBmWXTs0cIhWt+/Wephf75lA+kwXxnyvYWrpcVUP iCvi4kUYleMnbA+7cQX6jTUOQxnEUJ3y3ZOUO9WQcZhLQ6mqm3mdDH8Mu xpH8nNOCOCSUa5kKsWFCxIyNpgA40uEcvcj5hSpMIafJaqL7XsjL2U1+k A==; X-CSE-ConnectionGUID: dsXMQPEqRsGI9DTpT++g+g== X-CSE-MsgGUID: cHwz4T2gTq639t7xuKf/+w== X-IronPort-AV: E=McAfee;i="6700,10204,11322"; a="38123104" X-IronPort-AV: E=Sophos;i="6.13,222,1732608000"; d="scan'208";a="38123104" X-CSE-ConnectionGUID: 9YozACHrSDGMLWJ5IMzMLA== X-CSE-MsgGUID: 0T50GAtRRs6qFq18ZHUK8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,222,1732608000"; d="scan'208";a="106822605" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=83?= Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH RESEND 1/2] rust/qdev: Make REALIZE safe Date: Tue, 21 Jan 2025 22:04:56 +0800 Message-Id: <20250121140457.84631-2-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250121140457.84631-1-zhao1.liu@intel.com> References: <20250121140457.84631-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.14; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -73 X-Spam_score: -7.4 X-Spam_bar: ------- X-Spam_report: (-7.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1737467173332019000 Content-Type: text/plain; charset="utf-8" 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 --- 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/devi= ce.rs index 994c2fc0593c..c64af2684b7d 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 =20 -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}, @@ -155,7 +155,7 @@ fn properties() -> &'static [Property] { fn vmsd() -> Option<&'static VMStateDescription> { Some(&device_class::VMSTATE_PL011) } - const REALIZE: Option =3D Some(Self::realize); + const REALIZE: Option =3D Some(Self::realize); const RESET: Option =3D Some(Self::reset); } =20 @@ -438,17 +438,17 @@ fn set_read_trigger(&mut self) { self.read_trigger =3D 1; } =20 - pub fn realize(&mut self) { + pub fn realize(&self) { // SAFETY: self.char_backend has the correct size and alignment fo= r 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 686054e737ac..a5121e31a37a 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 =3D None; + const REALIZE: Option =3D None; =20 /// If not `None`, the parent class's `reset` method is overridden /// with the function pointed to by `RESET`. --=20 2.34.1 From nobody Thu Jan 23 03:29:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1737467211; cv=none; d=zohomail.com; s=zohoarc; b=g/Nv+3ABSAtWjN0018rC2E8A5CiaqE4L5o31ZvWhRc5K1cyOsmUkdT5xuqT76yRVoPpi9ksexqWxT3jXB9TRDKrzhgt/YA2tZsxhtZxFYh+5stneKGIpmuZHsYL+1xCQf46M4aHcEHFg9wLpERPRv6krQ444RYGgtmPzjI0kRlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737467211; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Y/BybO20pURAXX2UHMPMF82HoR7h+B/iwdXLg0rGwuQ=; b=F6lCDKHbxsfaWxLnD1YuhP4trc/0emQGTXSxfDzKi+Tlz+w6mCT+lxx+i7Q4O1zy3SyfvCsRDa5v0Hw8RIJcy9EM/BJl52EAFM74Uy/Xk4J2QhQKPY8pD66YgcRDyXdKpUOEhIYUy36CeT39HnTicKHQRE5UCF0sNnV8JFjjSeM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737467211492702.8190580843979; Tue, 21 Jan 2025 05:46:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1taEZv-0000TZ-O8; Tue, 21 Jan 2025 08:46:04 -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 1taEZe-0000RK-1d; Tue, 21 Jan 2025 08:45:46 -0500 Received: from mgamail.intel.com ([192.198.163.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1taEZb-0005tB-S1; Tue, 21 Jan 2025 08:45:45 -0500 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2025 05:45:42 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa006.jf.intel.com with ESMTP; 21 Jan 2025 05:45:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1737467144; x=1769003144; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OsIWBqlrGVm71pj8dI8rY/GCT36H3RyHgbAeCp1q76o=; b=hD8g8EVbb0ZuGThAm0qkqF6NERKQNEtqcyiZ3x7Hf1ouSn8YSgZTnm9F Xgd/JZbgcCeTKXvO+vmejWi2zbhBxZgoPnvvHH6o3C4ZEbU7U08Vpt1NY Tw0VSiRKOwGprh15IdMIhG2igk55owwpXt8ZrbUMIzgakgcK5e1LG0dcc wlp3SpwJcyb9N9jNugQA75oSOpsTheCmrR15pnPzKytRx6DeIQgyyf+ER QOHEubkhv0y8QMUFLiU8e0bTCFiun/4IcZwXqwXOXbp4OfOPiNWXO4+1w twT587Sx677mKD13gXPd2Yq51Eenz3sGaYDagyZyi2z5aBFs8b+XDVjIz Q==; X-CSE-ConnectionGUID: LMexH0opSHO0rJT8v/tC0A== X-CSE-MsgGUID: TuBaYDdDQweKfMcxwkzagg== X-IronPort-AV: E=McAfee;i="6700,10204,11322"; a="38123112" X-IronPort-AV: E=Sophos;i="6.13,222,1732608000"; d="scan'208";a="38123112" X-CSE-ConnectionGUID: i0quFSvGQGq7jtnfXHqbDw== X-CSE-MsgGUID: ComJf3WDQkaqxVh6jfuklg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,222,1732608000"; d="scan'208";a="106822617" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=83?= Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, Zhao Liu Subject: [PATCH RESEND 2/2] rust/pl011: Avoid bindings::* Date: Tue, 21 Jan 2025 22:04:57 +0800 Message-Id: <20250121140457.84631-3-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250121140457.84631-1-zhao1.liu@intel.com> References: <20250121140457.84631-1-zhao1.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.14; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -73 X-Spam_score: -7.4 X-Spam_bar: ------- X-Spam_report: (-7.4 / 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_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1737467213516019000 Content-Type: text/plain; charset="utf-8" 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 --- 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/devi= ce.rs index c64af2684b7d..c95ab49fd62e 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -9,12 +9,19 @@ }; =20 use qemu_api::{ - bindings::{self, *}, + bindings::{ + error_fatal, hwaddr, memory_region_init_io, qdev_init_clock_in, qd= ev_new, + qdev_prop_set_chr, qemu_chr_fe_ioctl, qemu_chr_fe_set_handlers, qe= mu_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, }; =20 use crate::{ @@ -493,7 +500,7 @@ pub fn can_receive(&self) -> bool { } =20 pub fn event(&mut self, event: QEMUChrEvent) { - if event =3D=3D bindings::QEMUChrEvent::CHR_EVENT_BREAK && !self.l= oopback_enabled() { + if event =3D=3D QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_en= abled() { self.put_fifo(registers::Data::BREAK.into()); } } --=20 2.34.1