* [PATCH v2 0/2] Initial logging support for Rust
@ 2025-06-10 20:21 Bernhard Beschow
2025-06-10 20:21 ` [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API Bernhard Beschow
2025-06-10 20:21 ` [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging Bernhard Beschow
0 siblings, 2 replies; 15+ messages in thread
From: Bernhard Beschow @ 2025-06-10 20:21 UTC (permalink / raw)
To: qemu-devel
Cc: Manos Pitsidianakis, Paolo Bonzini, qemu-rust, Bernhard Beschow
This series introduces a log_mask! macro which is inspired by the C version
and is just a thin wrapper around qemu_log(). It caters to Rust expectations by
accepting an enum for logging categories and working like the format! macro. The
macro then gets used in the pl011 device which either had its logging commented
out or relied on eprintln!() which can't be silenced by users.
Note that this is my first Rust contribution, so please check if the usage of
`unsafe` is sound.
v2:
* Drop the qemu_ prefix from the macro name (Paolo)
* Use an enum for the logging categories in PascalCase as suggested by Paolo
Bernhard Beschow (2):
rust/qemu-api: Add initial logging support based on C API
rust/hw/char/pl011/src/device: Implement logging
docs/devel/rust.rst | 1 +
rust/wrapper.h | 2 +
rust/hw/char/pl011/src/device.rs | 12 +++--
rust/qemu-api/meson.build | 1 +
rust/qemu-api/src/lib.rs | 1 +
rust/qemu-api/src/log.rs | 76 ++++++++++++++++++++++++++++++++
6 files changed, 89 insertions(+), 4 deletions(-)
create mode 100644 rust/qemu-api/src/log.rs
--
2.49.0
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-10 20:21 [PATCH v2 0/2] Initial logging support for Rust Bernhard Beschow
@ 2025-06-10 20:21 ` Bernhard Beschow
2025-06-11 7:56 ` Paolo Bonzini
2025-06-11 10:57 ` Manos Pitsidianakis
2025-06-10 20:21 ` [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging Bernhard Beschow
1 sibling, 2 replies; 15+ messages in thread
From: Bernhard Beschow @ 2025-06-10 20:21 UTC (permalink / raw)
To: qemu-devel
Cc: Manos Pitsidianakis, Paolo Bonzini, qemu-rust, Bernhard Beschow
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 <shentey@gmail.com>
---
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 */
#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 = 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 <shentey@gmail.com>
+// 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, corresponding
+/// 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 = crate::bindings::LOG_GUEST_ERROR,
+
+ /// Log guest access of unimplemented functionality.
+ /// Corresponds to `LOG_UNIMP` in the C implementation.
+ Unimp = 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 counterpart
+/// of the qemu_log_mask() macro in the C implementation.
+///
+/// # Parameters
+///
+/// - `$mask`: A log level mask. This should be a variant of the `Log` enum.
+/// - `$fmt`: A format string following the syntax and rules of the `format!`
+/// macro. It specifies the structure of the log message.
+/// - `$args`: Optional arguments to be interpolated into the format string.
+///
+/// # Example
+///
+/// ```
+/// use qemu_api::log::Log;
+/// use qemu_api::log_mask;
+///
+/// let error_address = 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 = 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)*) => {{
+ // Type assertion to enforce type `Log` for $mask
+ let _: Log = $mask;
+
+ if unsafe {
+ (::qemu_api::bindings::qemu_loglevel & ($mask as std::os::raw::c_int)) != 0
+ } {
+ let formatted_string = format!($fmt $($args)*);
+ let c_string = std::ffi::CString::new(formatted_string).unwrap();
+
+ unsafe {
+ ::qemu_api::bindings::qemu_log(c_string.as_ptr());
+ }
+ }
+ }};
+}
--
2.49.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging
2025-06-10 20:21 [PATCH v2 0/2] Initial logging support for Rust Bernhard Beschow
2025-06-10 20:21 ` [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API Bernhard Beschow
@ 2025-06-10 20:21 ` Bernhard Beschow
2025-06-11 7:55 ` Paolo Bonzini
2025-06-11 11:01 ` Manos Pitsidianakis
1 sibling, 2 replies; 15+ messages in thread
From: Bernhard Beschow @ 2025-06-10 20:21 UTC (permalink / raw)
To: qemu-devel
Cc: Manos Pitsidianakis, Paolo Bonzini, qemu-rust, Bernhard Beschow
Now that there is logging support in Rust for QEMU, use it in the pl011
device.
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
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/device.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 => {
self.dmacr = value;
if value & 3 > 0 {
- // qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemented\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(_) => {
- // 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) => {
@@ -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();
--
2.49.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging
2025-06-10 20:21 ` [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging Bernhard Beschow
@ 2025-06-11 7:55 ` Paolo Bonzini
2025-06-11 10:20 ` Bernhard Beschow
2025-06-11 11:01 ` Manos Pitsidianakis
1 sibling, 1 reply; 15+ messages in thread
From: Paolo Bonzini @ 2025-06-11 7:55 UTC (permalink / raw)
To: Bernhard Beschow, qemu-devel; +Cc: Manos Pitsidianakis, qemu-rust
On 6/10/25 22:21, Bernhard Beschow wrote:
> Now that there is logging support in Rust for QEMU, use it in the pl011
> device.
Adding also this to match the C code:
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 42dfa9509dc..e505abfae86 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -305,6 +305,12 @@ fn read_data_register(&mut self, update: &mut bool) -> u32 {
}
fn write_data_register(&mut self, value: u32) -> bool {
+ if !self.control.enable_uart() {
+ log_mask!(Log::GuestError, "PL011 data written to disabled UART\n");
+ }
+ if !self.control.enable_transmit() {
+ log_mask!(Log::GuestError, "PL011 data written to disabled TX UART\n");
+ }
// interrupts always checked
let _ = self.loopback_tx(value.into());
self.int_level |= Interrupt::TX;
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-10 20:21 ` [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API Bernhard Beschow
@ 2025-06-11 7:56 ` Paolo Bonzini
2025-06-11 10:19 ` Bernhard Beschow
2025-06-11 10:57 ` Manos Pitsidianakis
1 sibling, 1 reply; 15+ messages in thread
From: Paolo Bonzini @ 2025-06-11 7:56 UTC (permalink / raw)
To: Bernhard Beschow, qemu-devel; +Cc: Manos Pitsidianakis, qemu-rust
On 6/10/25 22:21, Bernhard Beschow wrote:
> +/// 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 counterpart
> +/// of the qemu_log_mask() macro in the C implementation.
Clippy complains that it wants `` around the function name.
Paolo
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-11 7:56 ` Paolo Bonzini
@ 2025-06-11 10:19 ` Bernhard Beschow
2025-06-11 10:44 ` Paolo Bonzini
0 siblings, 1 reply; 15+ messages in thread
From: Bernhard Beschow @ 2025-06-11 10:19 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: Manos Pitsidianakis, qemu-rust
Am 11. Juni 2025 07:56:23 UTC schrieb Paolo Bonzini <pbonzini@redhat.com>:
>On 6/10/25 22:21, Bernhard Beschow wrote:
>> +/// 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 counterpart
>> +/// of the qemu_log_mask() macro in the C implementation.
>
>Clippy complains that it wants `` around the function name.
Will fix in v3.
>
>Paolo
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging
2025-06-11 7:55 ` Paolo Bonzini
@ 2025-06-11 10:20 ` Bernhard Beschow
0 siblings, 0 replies; 15+ messages in thread
From: Bernhard Beschow @ 2025-06-11 10:20 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: Manos Pitsidianakis, qemu-rust
Am 11. Juni 2025 07:55:20 UTC schrieb Paolo Bonzini <pbonzini@redhat.com>:
>On 6/10/25 22:21, Bernhard Beschow wrote:
>> Now that there is logging support in Rust for QEMU, use it in the pl011
>> device.
>Adding also this to match the C code:
>
>diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
>index 42dfa9509dc..e505abfae86 100644
>--- a/rust/hw/char/pl011/src/device.rs
>+++ b/rust/hw/char/pl011/src/device.rs
>@@ -305,6 +305,12 @@ fn read_data_register(&mut self, update: &mut bool) -> u32 {
> }
> fn write_data_register(&mut self, value: u32) -> bool {
>+ if !self.control.enable_uart() {
>+ log_mask!(Log::GuestError, "PL011 data written to disabled UART\n");
>+ }
>+ if !self.control.enable_transmit() {
>+ log_mask!(Log::GuestError, "PL011 data written to disabled TX UART\n");
>+ }
> // interrupts always checked
> let _ = self.loopback_tx(value.into());
> self.int_level |= Interrupt::TX;
>
Will add as separate patch in v3.
Best regards,
Bernhard
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-11 10:19 ` Bernhard Beschow
@ 2025-06-11 10:44 ` Paolo Bonzini
0 siblings, 0 replies; 15+ messages in thread
From: Paolo Bonzini @ 2025-06-11 10:44 UTC (permalink / raw)
To: Bernhard Beschow; +Cc: qemu-devel, Manos Pitsidianakis, qemu-rust
[-- Attachment #1: Type: text/plain, Size: 514 bytes --]
Il mer 11 giu 2025, 12:21 Bernhard Beschow <shentey@gmail.com> ha scritto:
> Am 11. Juni 2025 07:56:23 UTC schrieb Paolo Bonzini <pbonzini@redhat.com>:
> >Clippy complains that it wants `` around the function name.
>
> Will fix in v3.
>
While at it, please run it through rustfmt and add a "//!" comment at the
top, such as "Bindings for QEMU's logging infrastructure".
You can build the documentation with "ninja rustdoc" so you can check the
result of the doc comments.
Thanks,
Paolo
> >
> >Paolo
> >
>
>
[-- Attachment #2: Type: text/html, Size: 1402 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-10 20:21 ` [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API Bernhard Beschow
2025-06-11 7:56 ` Paolo Bonzini
@ 2025-06-11 10:57 ` Manos Pitsidianakis
2025-06-11 11:05 ` Paolo Bonzini
1 sibling, 1 reply; 15+ messages in thread
From: Manos Pitsidianakis @ 2025-06-11 10:57 UTC (permalink / raw)
To: Bernhard Beschow; +Cc: qemu-devel, Paolo Bonzini, qemu-rust
On Tue, Jun 10, 2025 at 11:21 PM Bernhard Beschow <shentey@gmail.com> wrote:
>
> 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 <shentey@gmail.com>
> ---
> 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 */
>
> #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 = 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 <shentey@gmail.com>
> +// 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, corresponding
> +/// 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 = crate::bindings::LOG_GUEST_ERROR,
> +
> + /// Log guest access of unimplemented functionality.
> + /// Corresponds to `LOG_UNIMP` in the C implementation.
> + Unimp = 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 counterpart
> +/// of the qemu_log_mask() macro in the C implementation.
> +///
> +/// # Parameters
> +///
> +/// - `$mask`: A log level mask. This should be a variant of the `Log` enum.
> +/// - `$fmt`: A format string following the syntax and rules of the `format!`
> +/// macro. It specifies the structure of the log message.
> +/// - `$args`: Optional arguments to be interpolated into the format string.
> +///
> +/// # Example
> +///
> +/// ```
> +/// use qemu_api::log::Log;
> +/// use qemu_api::log_mask;
> +///
> +/// let error_address = 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 = 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)*) => {{
> + // Type assertion to enforce type `Log` for $mask
> + let _: Log = $mask;
> +
> + if unsafe {
> + (::qemu_api::bindings::qemu_loglevel & ($mask as std::os::raw::c_int)) != 0
> + } {
> + let formatted_string = format!($fmt $($args)*);
> + let c_string = std::ffi::CString::new(formatted_string).unwrap();
> +
> + unsafe {
> + ::qemu_api::bindings::qemu_log(c_string.as_ptr());
> + }
> + }
> + }};
> +}
> --
> 2.49.0
>
Maybe we could take this chance to remove the requirement for trailing
newline? Not urgent, and also something we could change afterwards
anyway. We could also introduce log_mask_ln! macro but now I'm just
bikeshedding.
Besides that, I think it'd be useful to have the macro re-exported in
rust/qemu-api/src/prelude.rs as well. Please add it for the next
version.
--
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging
2025-06-10 20:21 ` [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging Bernhard Beschow
2025-06-11 7:55 ` Paolo Bonzini
@ 2025-06-11 11:01 ` Manos Pitsidianakis
1 sibling, 0 replies; 15+ messages in thread
From: Manos Pitsidianakis @ 2025-06-11 11:01 UTC (permalink / raw)
To: Bernhard Beschow; +Cc: qemu-devel, Paolo Bonzini, qemu-rust
On Tue, Jun 10, 2025 at 11:21 PM Bernhard Beschow <shentey@gmail.com> wrote:
>
> Now that there is logging support in Rust for QEMU, use it in the pl011
> device.
>
> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
> ---
> 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/device.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 => {
> self.dmacr = value;
> if value & 3 > 0 {
> - // qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemented\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(_) => {
> - // 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");
Nit:
log_mask!(Log::GuestError, "pl011_read: Bad offset 0x{offset:x}\n");
Also, pl011_read is the C device function. You can put
`PL011State::read: ` instead.
> 0
> }
> Ok(field) => {
> @@ -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"
> + );
Ditto
--
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-11 10:57 ` Manos Pitsidianakis
@ 2025-06-11 11:05 ` Paolo Bonzini
2025-06-11 12:17 ` Manos Pitsidianakis
0 siblings, 1 reply; 15+ messages in thread
From: Paolo Bonzini @ 2025-06-11 11:05 UTC (permalink / raw)
To: Manos Pitsidianakis; +Cc: Bernhard Beschow, qemu-devel, qemu-rust
On Wed, Jun 11, 2025 at 12:57 PM Manos Pitsidianakis
<manos.pitsidianakis@linaro.org> wrote:
> Maybe we could take this chance to remove the requirement for trailing
> newline? Not urgent, and also something we could change afterwards
> anyway. We could also introduce log_mask_ln! macro but now I'm just
> bikeshedding.
Good idea; there is no "formatln!" but I think you could use concat instead.
If that doesn't work for whatever reason we can indeed add it later. I
had the idea of a struct that wraps the logging functions
qemu_log_trylock() and qemu_log_unlock() and implements io::Write; at
which point, implementing log_mask_ln! (or _nl! following the unstable
format_args_nl!) with writeln! would be trivial.
> Besides that, I think it'd be useful to have the macro re-exported in
> rust/qemu-api/src/prelude.rs as well. Please add it for the next
> version.
Yes, I agree.
Paolo
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-11 11:05 ` Paolo Bonzini
@ 2025-06-11 12:17 ` Manos Pitsidianakis
2025-06-12 7:29 ` Bernhard Beschow
2025-06-12 7:37 ` Bernhard Beschow
0 siblings, 2 replies; 15+ messages in thread
From: Manos Pitsidianakis @ 2025-06-11 12:17 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Bernhard Beschow, qemu-devel, qemu-rust
On Wed, Jun 11, 2025 at 2:05 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On Wed, Jun 11, 2025 at 12:57 PM Manos Pitsidianakis
> <manos.pitsidianakis@linaro.org> wrote:
>
> > Maybe we could take this chance to remove the requirement for trailing
> > newline? Not urgent, and also something we could change afterwards
> > anyway. We could also introduce log_mask_ln! macro but now I'm just
> > bikeshedding.
>
> Good idea; there is no "formatln!" but I think you could use concat instead.
I think `let formatted_string = format!("{}\n", format_args!($fmt
$($args)*));` might be sufficient, but I haven't checked it myself
--
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-11 12:17 ` Manos Pitsidianakis
@ 2025-06-12 7:29 ` Bernhard Beschow
2025-06-12 7:37 ` Bernhard Beschow
1 sibling, 0 replies; 15+ messages in thread
From: Bernhard Beschow @ 2025-06-12 7:29 UTC (permalink / raw)
To: Manos Pitsidianakis, Paolo Bonzini; +Cc: qemu-devel, qemu-rust
Am 11. Juni 2025 12:17:57 UTC schrieb Manos Pitsidianakis <manos.pitsidianakis@linaro.org>:
>On Wed, Jun 11, 2025 at 2:05 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> On Wed, Jun 11, 2025 at 12:57 PM Manos Pitsidianakis
>> <manos.pitsidianakis@linaro.org> wrote:
>>
>> > Maybe we could take this chance to remove the requirement for trailing
>> > newline? Not urgent, and also something we could change afterwards
>> > anyway. We could also introduce log_mask_ln! macro but now I'm just
>> > bikeshedding.
>>
>> Good idea; there is no "formatln!" but I think you could use concat instead.
>
>I think `let formatted_string = format!("{}\n", format_args!($fmt
>$($args)*));` might be sufficient, but I haven't checked it myself
>
So the idea is to have a log_mask_ln! macro instead, since there isn't really a point for a macro that doesn't add `\n` at the end. Correct?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-11 12:17 ` Manos Pitsidianakis
2025-06-12 7:29 ` Bernhard Beschow
@ 2025-06-12 7:37 ` Bernhard Beschow
2025-06-12 7:39 ` Paolo Bonzini
1 sibling, 1 reply; 15+ messages in thread
From: Bernhard Beschow @ 2025-06-12 7:37 UTC (permalink / raw)
To: Manos Pitsidianakis, Paolo Bonzini; +Cc: qemu-devel, qemu-rust
Am 11. Juni 2025 12:17:57 UTC schrieb Manos Pitsidianakis <manos.pitsidianakis@linaro.org>:
>On Wed, Jun 11, 2025 at 2:05 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> On Wed, Jun 11, 2025 at 12:57 PM Manos Pitsidianakis
>> <manos.pitsidianakis@linaro.org> wrote:
>>
>> > Maybe we could take this chance to remove the requirement for trailing
>> > newline? Not urgent, and also something we could change afterwards
>> > anyway. We could also introduce log_mask_ln! macro but now I'm just
>> > bikeshedding.
>>
>> Good idea; there is no "formatln!" but I think you could use concat instead.
>
>I think `let formatted_string = format!("{}\n", format_args!($fmt
>$($args)*));` might be sufficient, but I haven't checked it myself
>
So the idea is to have a log_mask_ln! macro instead, since there isn't really a point for a macro that doesn't add `\n` at the end. Correct?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API
2025-06-12 7:37 ` Bernhard Beschow
@ 2025-06-12 7:39 ` Paolo Bonzini
0 siblings, 0 replies; 15+ messages in thread
From: Paolo Bonzini @ 2025-06-12 7:39 UTC (permalink / raw)
To: Bernhard Beschow; +Cc: Manos Pitsidianakis, qemu-devel, qemu-rust
[-- Attachment #1: Type: text/plain, Size: 248 bytes --]
Il gio 12 giu 2025, 09:37 Bernhard Beschow <shentey@gmail.com> ha scritto:
> So the idea is to have a log_mask_ln! macro instead, since there isn't
> really a point for a macro that doesn't add `\n` at the end. Correct?
>
Yes, or both.
Paolo
>
[-- Attachment #2: Type: text/html, Size: 870 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-06-12 7:40 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-10 20:21 [PATCH v2 0/2] Initial logging support for Rust Bernhard Beschow
2025-06-10 20:21 ` [PATCH v2 1/2] rust/qemu-api: Add initial logging support based on C API Bernhard Beschow
2025-06-11 7:56 ` Paolo Bonzini
2025-06-11 10:19 ` Bernhard Beschow
2025-06-11 10:44 ` Paolo Bonzini
2025-06-11 10:57 ` Manos Pitsidianakis
2025-06-11 11:05 ` Paolo Bonzini
2025-06-11 12:17 ` Manos Pitsidianakis
2025-06-12 7:29 ` Bernhard Beschow
2025-06-12 7:37 ` Bernhard Beschow
2025-06-12 7:39 ` Paolo Bonzini
2025-06-10 20:21 ` [PATCH v2 2/2] rust/hw/char/pl011/src/device: Implement logging Bernhard Beschow
2025-06-11 7:55 ` Paolo Bonzini
2025-06-11 10:20 ` Bernhard Beschow
2025-06-11 11:01 ` Manos Pitsidianakis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).