From nobody Sat Nov 15 15:29:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1749586929; cv=none; d=zohomail.com; s=zohoarc; b=Koinor6UJkZClgIm3dbiSkYjpdfNx+YTTsXl9tsm7pu8RU7UegEOhibW23SXeS6sEWVPu8G3guX89PvWhRkGNGOqhSpkiuN9odAKBvn1JXgZFXWIex392rgMKhj6V3/ROlvVRUro/j6qnbd+0o+aT4sBDfsi/juilQ5uHf+UZsk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749586929; 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=Hcp9cg9W7f8WjQhRw5f9FpDz7zN4s9hAjNEuNZIHKbA=; b=RrVZ+Z8Tc8prGBG9M3sksAeQyNGP9zqIZ/iUjZQCKiSka9XtdyZREvfCqtw+kgCMhEkhBySlFDyenGDfanZvvb5nbjbhdSc7OFBnSDHggxjZ0h8O4kiSiCYbXbfICZzdd7ij4D3k6WJN2XYNvmJLHWC7/v+mHDdtB8xaM0EJAvY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; 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 1749586929051480.17346233769797; Tue, 10 Jun 2025 13:22:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uP5TW-0008WU-2F; Tue, 10 Jun 2025 16:21:38 -0400 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 1uP5TL-0008VP-J1; Tue, 10 Jun 2025 16:21:28 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uP5TJ-0001JA-NL; Tue, 10 Jun 2025 16:21:27 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-adb2bd27c7bso950015266b.2; Tue, 10 Jun 2025 13:21:23 -0700 (PDT) Received: from Provence.localdomain (dynamic-2a02-3100-2cbf-5d00-0219-99ff-feb2-2458.310.pool.telefonica.de. [2a02:3100:2cbf:5d00:219:99ff:feb2:2458]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ade1dc7c786sm793135166b.172.2025.06.10.13.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 13:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749586882; x=1750191682; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Hcp9cg9W7f8WjQhRw5f9FpDz7zN4s9hAjNEuNZIHKbA=; b=ngXVYZo6UMOo3DTO+aqi7eaEQo8wav/K09j8yz9wQrOUBZZFcOj8lYIjt4n/PlHm3Q Upt/WnDvIOqVlWThvRsqvnBFnuFWDb+xVAgemS0sc55FGE+nFumOYAuuwo4wJi9GdBlm +gpQZ9bNRWb0OoYysbn1jj+5pjIqfZHZCtvk7A2Fg6YCk7uyP5qMx+VLCmnEpFU5fJjt OvL0jTia2eC/fUGCVyW4zSc1ueEkH76kVHYDjqPYJqzOWKwV6LNhGWBw8MxycogVX1XO ieapPWd87KQTVSd7qOIWGDMo6/Cz6wqNjUSL9I99Cywp3ztnPDYRJFH8hGGHKDnGqUhi wGYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749586882; x=1750191682; 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=Hcp9cg9W7f8WjQhRw5f9FpDz7zN4s9hAjNEuNZIHKbA=; b=UMFZsnFv0s0L1jJa7nQDoOG/plhSFaeNxckXeJ+ofwoQRYEI5r2EERh7CVPQBZEWuW IXLTjr/BEgVFGoQV67KRW7hk6JCdVOe16JD4MtkLy047iFgcJSpL5N/FEviZVXK6qLge XGWE4a97Tp2JOerrjhZSP+my1E6KB9KLBpFl6DqQwGtKQVtYfCdm9UPVqyOEyvgCjGR/ eCf4lPYJRQOmcuoIRojMmbJ8AApNMkSOsABmtawZ3e2hmOxdtCvpOjtMtNHPdupYnlTy kgqSVq301kN2FvfPNQywlkqwrryo166yA+dlopxp8rtbVUjUF7w8OPszGWvgfp7sB9HQ oN/Q== X-Forwarded-Encrypted: i=1; AJvYcCV3UqzLRf9m8wfZyAbOcTs4VY27aNyUxxAFtL1uMPKC6Fx+WZuo7G+9qYs5Wl1YXbWARsadKRpc/GQ=@nongnu.org X-Gm-Message-State: AOJu0YzDVzgvVKXj/XFkffKNcrC8kqTRoDLqvF5TYiChaX89GKqVr/Y3 JJB5ktBL/ivnR7IQvlNy9Wsrw7fotfuAGPmHsTxqEnV3RiTpDtf10OgCtEkQvA== X-Gm-Gg: ASbGnctCIo+H2BDMojLEszKb4LiGPQpOk8VhFhzgWT+clZY/DsKXpXR4VT4Lx8xwfNv T2eP2t0xnhRLq7qhCqjkMZhOFW91NPpvpdEYMxTUCMipZiP3tHGME993ARiyMrXL2KGfM5q8OqE AHHzSAP/qzwq/Zz53b6GTzbFCYe7Z/vK2QVh7deinsvynWWrsmliO+hv8pxOMdnIuPrTHtNCFKn kj7Vi0E/ezMonW34SeiY7Z6CAdwtUsdew81F4i3XDuARfVPwS9/Q7QwWDW/LihCeZxI7ONsRUP6 I+Zr2TV1bUeo4++NOAMM9mAh28x6DDvb+PlULgetDTzh+OTVnkcvBVebAEbiKa0fC6UttnuHfRO WcHtXc1Cp0EbOMlRuIZJ1gzqcXT60G0qYKl2RAUCuGJyhV1R1b8zWyX4R+LOgPjZCjP19QDgqfv 2avTYAYw== X-Google-Smtp-Source: AGHT+IFGP+aU1otc8K0JHPdFB34HabH20kTObIz9MH652uLsMHfleAVen3u2h7urlc10VxvO7YkOIA== X-Received: by 2002:a17:907:9414:b0:ad8:a329:b4a0 with SMTP id a640c23a62f3a-ade8955eeffmr77501766b.24.1749586881373; Tue, 10 Jun 2025 13:21:21 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Paolo Bonzini , qemu-rust@nongnu.org, Bernhard Beschow Subject: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API Date: Tue, 10 Jun 2025 22:21:09 +0200 Message-ID: <20250610202110.2243-2-shentey@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610202110.2243-1-shentey@gmail.com> References: <20250610202110.2243-1-shentey@gmail.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=2a00:1450:4864:20::635; envelope-from=shentey@gmail.com; helo=mail-ej1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1749586930536116600 Content-Type: text/plain; charset="utf-8" A log_mask!() macro is provided which expects similar arguments as the C version. However, the formatting works as one would expect from Rust. To maximize code reuse the macro is just a thin wrapper around qemu_log(). Also, just the bare minimum of logging masks is provided which should suffice for the current use case of Rust in QEMU. Signed-off-by: Bernhard Beschow --- docs/devel/rust.rst | 1 + rust/wrapper.h | 2 ++ rust/qemu-api/meson.build | 1 + rust/qemu-api/src/lib.rs | 1 + rust/qemu-api/src/log.rs | 76 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 rust/qemu-api/src/log.rs diff --git a/docs/devel/rust.rst b/docs/devel/rust.rst index 47e9677fcb..dc8c44109e 100644 --- a/docs/devel/rust.rst +++ b/docs/devel/rust.rst @@ -162,6 +162,7 @@ module status ``errno`` complete ``error`` stable ``irq`` complete +``log`` proof of concept ``memory`` stable ``module`` complete ``qdev`` stable diff --git a/rust/wrapper.h b/rust/wrapper.h index 6060d3ba1a..15a1b19847 100644 --- a/rust/wrapper.h +++ b/rust/wrapper.h @@ -48,6 +48,8 @@ typedef enum memory_order { #endif /* __CLANG_STDATOMIC_H */ =20 #include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/log-for-trace.h" #include "qemu/module.h" #include "qemu-io.h" #include "system/system.h" diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index cac8595a14..33caee3c4f 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -21,6 +21,7 @@ _qemu_api_rs =3D static_library( 'src/errno.rs', 'src/error.rs', 'src/irq.rs', + 'src/log.rs', 'src/memory.rs', 'src/module.rs', 'src/prelude.rs', diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 93902fc94b..e20be35460 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -21,6 +21,7 @@ pub mod errno; pub mod error; pub mod irq; +pub mod log; pub mod memory; pub mod module; pub mod qdev; diff --git a/rust/qemu-api/src/log.rs b/rust/qemu-api/src/log.rs new file mode 100644 index 0000000000..9e3c61b8b7 --- /dev/null +++ b/rust/qemu-api/src/log.rs @@ -0,0 +1,76 @@ +// Copyright 2025 Bernhard Beschow +// SPDX-License-Identifier: GPL-2.0-or-later + +#[repr(u32)] +/// Represents specific error categories within QEMU's logging system. +/// +/// The `Log` enum provides a Rust abstraction for logging errors, corresp= onding +/// to a subset of the error categories defined in the C implementation. +pub enum Log { + /// Log an invalid access caused by the guest. + /// Corresponds to `LOG_GUEST_ERROR` in the C implementation. + GuestError =3D crate::bindings::LOG_GUEST_ERROR, + + /// Log guest access of unimplemented functionality. + /// Corresponds to `LOG_UNIMP` in the C implementation. + Unimp =3D crate::bindings::LOG_UNIMP, +} + +/// A macro to log messages conditionally based on a provided mask. +/// +/// The `log_mask` macro checks whether the given mask matches the current= log +/// level and, if so, formats and logs the message. It is the Rust counter= part +/// of the qemu_log_mask() macro in the C implementation. +/// +/// # Parameters +/// +/// - `$mask`: A log level mask. This should be a variant of the `Log` enu= m. +/// - `$fmt`: A format string following the syntax and rules of the `forma= t!` +/// macro. It specifies the structure of the log message. +/// - `$args`: Optional arguments to be interpolated into the format strin= g. +/// +/// # Example +/// +/// ``` +/// use qemu_api::log::Log; +/// use qemu_api::log_mask; +/// +/// let error_address =3D 0xbad; +/// log_mask!( +/// Log::GuestError, +/// "Address 0x{error_address:x} out of range\n" +/// ); +/// ``` +/// +/// It is also possible to use printf-style formatting, as well as having a +/// trailing `,`: +/// +/// ``` +/// use qemu_api::log::Log; +/// use qemu_api::log_mask; +/// +/// let error_address =3D 0xbad; +/// log_mask!( +/// Log::GuestError, +/// "Address 0x{:x} out of range\n", +/// error_address, +/// ); +/// ``` +#[macro_export] +macro_rules! log_mask { + ($mask:expr, $fmt:tt $($args:tt)*) =3D> {{ + // Type assertion to enforce type `Log` for $mask + let _: Log =3D $mask; + + if unsafe { + (::qemu_api::bindings::qemu_loglevel & ($mask as std::os::raw:= :c_int)) !=3D 0 + } { + let formatted_string =3D format!($fmt $($args)*); + let c_string =3D std::ffi::CString::new(formatted_string).unwr= ap(); + + unsafe { + ::qemu_api::bindings::qemu_log(c_string.as_ptr()); + } + } + }}; +} --=20 2.49.0 From nobody Sat Nov 15 15:29:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1749586967; cv=none; d=zohomail.com; s=zohoarc; b=R4wyJjQhlKY0C1rE4dqSIyAkCY497n7Nr5lWbYsaweH5rXTc+3ny944iAMnrHBokaLeFn7FzNV5/R/YH1rcBYxF4ScOGt4E0/5106TitkBf/fksVkHiTm6DfbQWP2pzfx2+kBK3I9YDkDzSWwb2XmrxBekA21nFVqP3F/gZk5oc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749586967; 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=7mwAkV2ZVpCuhcQmhWwgDu1m1Z/Imf1J6IuSoGrizlU=; b=kdANAPQol/TGsJOB9lZ6Rtlzi9OoQImrXl32HRNJnKRL00kSdIdlb0j9iJtpY7U1MB2m8v5z2j8/vm2QusF4yjA4bTWjdfaKBrIXG8ydbRX9G3JvRGzk2mgGWU5//OdPjYqcIdPLf0X3o3adeJUGNPvN7G1WZUePrvBOACz0Qjc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; 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 1749586967615399.1365907831465; Tue, 10 Jun 2025 13:22:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uP5Ta-000069-Aq; Tue, 10 Jun 2025 16:21:42 -0400 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 1uP5TM-0008VV-Am; Tue, 10 Jun 2025 16:21:28 -0400 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uP5TJ-0001JE-NV; Tue, 10 Jun 2025 16:21:28 -0400 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-605b9488c28so9435648a12.2; Tue, 10 Jun 2025 13:21:24 -0700 (PDT) Received: from Provence.localdomain (dynamic-2a02-3100-2cbf-5d00-0219-99ff-feb2-2458.310.pool.telefonica.de. [2a02:3100:2cbf:5d00:219:99ff:feb2:2458]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ade1dc7c786sm793135166b.172.2025.06.10.13.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 13:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749586882; x=1750191682; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7mwAkV2ZVpCuhcQmhWwgDu1m1Z/Imf1J6IuSoGrizlU=; b=I16UH0Ch32G3s/85rdXh4yvF9r3Qvuk22tbhx11t6vQ1/gcFiFqbT0IwshoezIDRe+ vIn7Qj33mBcld0FmFj1yTk+Mm5dJeYxXOV4Ln1zmWVxcB+eCuzfgzcm8fhi0H2C/OIgc GVBZ5lTCPrjD/ILzOzfBEO1EVSuCiLxgG4aRuETxkGhtdVLghGp0S7Y+10CZ+h12Y1IP FShae+82jo/qUnQuTks3z3VsurpYjX5cVkf8dROWduUUhPjO+7od4Ntxkh9Wc6tnG8wx TACtWSfq01/35yu9XS/ss+/1RCe39amdhsqulP6jl0yO5cKpoqFC6Oug8X+JASLx2EvP OwWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749586882; x=1750191682; 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=7mwAkV2ZVpCuhcQmhWwgDu1m1Z/Imf1J6IuSoGrizlU=; b=w1xHOPY2eZKzBddhuWBBjqxgiixSRsfzjoPk5XIS+yJR2KCqzF5LHYTZGFgIu3qLjy 32kGZW99blrNIU/IVql/+btpUgllSs4+6OsSt4bd9UAQMthRz0tO4iCZWLF06KMpZjn4 Uy6+oP7S+6R+8AmmlTb8ug2FyMx3uCiarPTek39qyu6UWPj8vGDIBQ6aJloTaGc7HaJU NHLAvUcziHKC06FvNA5eW0UyF/aOKxmB3/wqtFI10dYtrXW9foNF1/Tr+ojHJJp44JgO pkboyeqzqK+WNNd/ESGn39f5VzuBPcCZ86K9t7ehGHqA3yxRfqrzxbQmJbJxk81W+84r TnPg== X-Forwarded-Encrypted: i=1; AJvYcCUFJyeNcHFnu9pAB0d6al1oDi//UmfFDbphKn4/6DruBTHwxG5rZRisP9C0oKURwOzomT+JlGCIyw8=@nongnu.org X-Gm-Message-State: AOJu0Yx5HefZkHXmYycX89/29pMqxf9fLpMIfB8g9e+u6uE5sy3Kcyhb dl517Hd2Qwb024GX86M0cDRF86QarpDa1hW1pkYgJ4mHtO8r71dFS6h0oJKN3A== X-Gm-Gg: ASbGncvK9FDWfD4jtjRrPvN+/03GoH0HJvWGy49XcHALN7gQpC5qeRK8VkHoM1Vc1BJ lKekCybnctqopo+kxwi1a2o1qrf6m7iD99n+zII8K6ThbcNiMuN+nXob0hlGL8I7RBR7XpMY1uR VyStTnuBMyx5DlbxkxmAISrrUM5wq73v5FCzWdQgF7aeEggRVcCKWb7FNeCgCmtpbC1Y4+kcAbC BBbsqL3InK1wYZHpQ3xzWlErmcLBlO93L+47Tn5ZsYuvCDxxxIzcEJDCPRA5phczjwx5V54fVFH QeHsXYycizj2/W9BfC5lJXB5y/TnJfrCqsB0EvzWrpvcVcO/M/rl6l5op4oz4mOsc0KHA1gPKDK oV8Pn0KVIn0jyD/ixQEC/Y/TqyIHL5VYc8sOmCHZZk43aNRKKDw+Qii7cfiU480e80mnrwA4H8L Usx/hTAA== X-Google-Smtp-Source: AGHT+IHiq3rlRmGcm6c+92AV20ASDAvlReFEmP6CyyYhP84jS9T8i2qP1KPimywoB6Yp/zhldmu1iw== X-Received: by 2002:a17:907:868b:b0:ad8:8efe:3205 with SMTP id a640c23a62f3a-ade8c996df0mr17918766b.55.1749586882134; Tue, 10 Jun 2025 13:21:22 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Manos Pitsidianakis , Paolo Bonzini , qemu-rust@nongnu.org, Bernhard Beschow Subject: [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging Date: Tue, 10 Jun 2025 22:21:10 +0200 Message-ID: <20250610202110.2243-3-shentey@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610202110.2243-1-shentey@gmail.com> References: <20250610202110.2243-1-shentey@gmail.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=2a00:1450:4864:20::533; envelope-from=shentey@gmail.com; helo=mail-ed1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1749586968381116600 Content-Type: text/plain; charset="utf-8" Now that there is logging support in Rust for QEMU, use it in the pl011 device. Signed-off-by: Bernhard Beschow --- rust/hw/char/pl011/src/device.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index be8387f6f2..17a4e9269c 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -8,6 +8,8 @@ chardev::{CharBackend, Chardev, Event}, impl_vmstate_forward, irq::{IRQState, InterruptSource}, + log::Log, + log_mask, memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder= }, prelude::*, qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, Property, ResetType= , ResettablePhasesImpl}, @@ -275,8 +277,7 @@ pub(self) fn write( DMACR =3D> { self.dmacr =3D value; if value & 3 > 0 { - // qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemente= d\n"); - eprintln!("pl011: DMA not implemented"); + log_mask!(Log::Unimp, "pl011: DMA not implemented\n"); } } } @@ -538,7 +539,7 @@ fn read(&self, offset: hwaddr, _size: u32) -> u64 { u64::from(device_id[(offset - 0xfe0) >> 2]) } Err(_) =3D> { - // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset = 0x%x\n", (int)offset); + log_mask!(Log::GuestError, "pl011_read: Bad offset {offset= }\n"); 0 } Ok(field) =3D> { @@ -570,7 +571,10 @@ fn write(&self, offset: hwaddr, value: u64, _size: u32= ) { .borrow_mut() .write(field, value as u32, &self.char_backend); } else { - eprintln!("write bad offset {offset} value {value}"); + log_mask!( + Log::GuestError, + "pl011_write: Bad offset {offset} value {value}\n" + ); } if update_irq { self.update(); --=20 2.49.0