Skip to content

Commit c4f2ae5

Browse files
committed
Merge tag 'drm-rust-fixes-2025-12-29' of https://gitlab.freedesktop.org/drm/rust/kernel into drm-fixes
DRM Rust fixes for v6.19-rc4 MAINTAINERS: - Fix Nova GPU driver git links. - Fix typo in TYR driver entry preventing correct behavior of scripts/get_maintainer.pl. - Exclude TYR driver from DRM MISC. Nova Core: - Correctly select RUST_FW_LOADER_ABSTRACTIONS to prevent build errors. - Regenerate nova-core bindgen bindings with '--explicit-padding' to avoid uninitialized bytes. - Fix length of received GSP messages, due to miscalculated message payload size. - Regenerate bindings to derive MaybeZeroable. - Use a bindings alias to derive the firmware version. Signed-off-by: Dave Airlie <airlied@redhat.com> From: "Danilo Krummrich" <dakr@kernel.org> Link: https://patch.msgid.link/DFATYVSQRQ4W.1R030NZ34XUZK@kernel.org
2 parents 9ace475 + 97872fa commit c4f2ae5

6 files changed

Lines changed: 117 additions & 100 deletions

File tree

MAINTAINERS

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@ M: Alice Ryhl <aliceryhl@google.com>
21582158
L: dri-devel@lists.freedesktop.org
21592159
S: Supported
21602160
W: https://rust-for-linux.com/tyr-gpu-driver
2161-
W https://drm.pages.freedesktop.org/maintainer-tools/drm-rust.html
2161+
W: https://drm.pages.freedesktop.org/maintainer-tools/drm-rust.html
21622162
B: https://gitlab.freedesktop.org/panfrost/linux/-/issues
21632163
T: git https://gitlab.freedesktop.org/drm/rust/kernel.git
21642164
F: Documentation/devicetree/bindings/gpu/arm,mali-valhall-csf.yaml
@@ -8067,7 +8067,7 @@ W: https://rust-for-linux.com/nova-gpu-driver
80678067
Q: https://patchwork.freedesktop.org/project/nouveau/
80688068
B: https://gitlab.freedesktop.org/drm/nova/-/issues
80698069
C: irc://irc.oftc.net/nouveau
8070-
T: git https://gitlab.freedesktop.org/drm/nova.git nova-next
8070+
T: git https://gitlab.freedesktop.org/drm/rust/kernel.git drm-rust-next
80718071
F: Documentation/gpu/nova/
80728072
F: drivers/gpu/nova-core/
80738073

@@ -8079,7 +8079,7 @@ W: https://rust-for-linux.com/nova-gpu-driver
80798079
Q: https://patchwork.freedesktop.org/project/nouveau/
80808080
B: https://gitlab.freedesktop.org/drm/nova/-/issues
80818081
C: irc://irc.oftc.net/nouveau
8082-
T: git https://gitlab.freedesktop.org/drm/nova.git nova-next
8082+
T: git https://gitlab.freedesktop.org/drm/rust/kernel.git drm-rust-next
80838083
F: Documentation/gpu/nova/
80848084
F: drivers/gpu/drm/nova/
80858085
F: include/uapi/drm/nova_drm.h
@@ -8357,6 +8357,7 @@ X: drivers/gpu/drm/msm/
83578357
X: drivers/gpu/drm/nova/
83588358
X: drivers/gpu/drm/radeon/
83598359
X: drivers/gpu/drm/tegra/
8360+
X: drivers/gpu/drm/tyr/
83608361
X: drivers/gpu/drm/xe/
83618362

83628363
DRM DRIVERS AND COMMON INFRASTRUCTURE [RUST]

drivers/gpu/nova-core/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ config NOVA_CORE
33
depends on 64BIT
44
depends on PCI
55
depends on RUST
6-
depends on RUST_FW_LOADER_ABSTRACTIONS
6+
select RUST_FW_LOADER_ABSTRACTIONS
77
select AUXILIARY_BUS
88
default n
99
help

drivers/gpu/nova-core/gsp/cmdq.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,21 +588,23 @@ impl Cmdq {
588588
header.length(),
589589
);
590590

591+
let payload_length = header.payload_length();
592+
591593
// Check that the driver read area is large enough for the message.
592-
if slice_1.len() + slice_2.len() < header.length() {
594+
if slice_1.len() + slice_2.len() < payload_length {
593595
return Err(EIO);
594596
}
595597

596598
// Cut the message slices down to the actual length of the message.
597-
let (slice_1, slice_2) = if slice_1.len() > header.length() {
598-
// PANIC: we checked above that `slice_1` is at least as long as `msg_header.length()`.
599-
(slice_1.split_at(header.length()).0, &slice_2[0..0])
599+
let (slice_1, slice_2) = if slice_1.len() > payload_length {
600+
// PANIC: we checked above that `slice_1` is at least as long as `payload_length`.
601+
(slice_1.split_at(payload_length).0, &slice_2[0..0])
600602
} else {
601603
(
602604
slice_1,
603605
// PANIC: we checked above that `slice_1.len() + slice_2.len()` is at least as
604-
// large as `msg_header.length()`.
605-
slice_2.split_at(header.length() - slice_1.len()).0,
606+
// large as `payload_length`.
607+
slice_2.split_at(payload_length - slice_1.len()).0,
606608
)
607609
};
608610

drivers/gpu/nova-core/gsp/fw.rs

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ unsafe impl AsBytes for GspFwWprMeta {}
141141
// are valid.
142142
unsafe impl FromBytes for GspFwWprMeta {}
143143

144-
type GspFwWprMetaBootResumeInfo = r570_144::GspFwWprMeta__bindgen_ty_1;
145-
type GspFwWprMetaBootInfo = r570_144::GspFwWprMeta__bindgen_ty_1__bindgen_ty_1;
144+
type GspFwWprMetaBootResumeInfo = bindings::GspFwWprMeta__bindgen_ty_1;
145+
type GspFwWprMetaBootInfo = bindings::GspFwWprMeta__bindgen_ty_1__bindgen_ty_1;
146146

147147
impl GspFwWprMeta {
148148
/// Fill in and return a `GspFwWprMeta` suitable for booting `gsp_firmware` using the
149149
/// `fb_layout` layout.
150150
pub(crate) fn new(gsp_firmware: &GspFirmware, fb_layout: &FbLayout) -> Self {
151151
Self(bindings::GspFwWprMeta {
152152
// CAST: we want to store the bits of `GSP_FW_WPR_META_MAGIC` unmodified.
153-
magic: r570_144::GSP_FW_WPR_META_MAGIC as u64,
154-
revision: u64::from(r570_144::GSP_FW_WPR_META_REVISION),
153+
magic: bindings::GSP_FW_WPR_META_MAGIC as u64,
154+
revision: u64::from(bindings::GSP_FW_WPR_META_REVISION),
155155
sysmemAddrOfRadix3Elf: gsp_firmware.radix3_dma_handle(),
156156
sizeOfRadix3Elf: u64::from_safe_cast(gsp_firmware.size),
157157
sysmemAddrOfBootloader: gsp_firmware.bootloader.ucode.dma_handle(),
@@ -315,19 +315,19 @@ impl From<MsgFunction> for u32 {
315315
#[repr(u32)]
316316
pub(crate) enum SeqBufOpcode {
317317
// Core operation opcodes
318-
CoreReset = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESET,
319-
CoreResume = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESUME,
320-
CoreStart = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_START,
321-
CoreWaitForHalt = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_WAIT_FOR_HALT,
318+
CoreReset = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESET,
319+
CoreResume = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESUME,
320+
CoreStart = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_START,
321+
CoreWaitForHalt = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_WAIT_FOR_HALT,
322322

323323
// Delay opcode
324-
DelayUs = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_DELAY_US,
324+
DelayUs = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_DELAY_US,
325325

326326
// Register operation opcodes
327-
RegModify = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_MODIFY,
328-
RegPoll = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_POLL,
329-
RegStore = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_STORE,
330-
RegWrite = r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_WRITE,
327+
RegModify = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_MODIFY,
328+
RegPoll = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_POLL,
329+
RegStore = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_STORE,
330+
RegWrite = bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_WRITE,
331331
}
332332

333333
impl fmt::Display for SeqBufOpcode {
@@ -351,25 +351,25 @@ impl TryFrom<u32> for SeqBufOpcode {
351351

352352
fn try_from(value: u32) -> Result<SeqBufOpcode> {
353353
match value {
354-
r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESET => {
354+
bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESET => {
355355
Ok(SeqBufOpcode::CoreReset)
356356
}
357-
r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESUME => {
357+
bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_RESUME => {
358358
Ok(SeqBufOpcode::CoreResume)
359359
}
360-
r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_START => {
360+
bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_START => {
361361
Ok(SeqBufOpcode::CoreStart)
362362
}
363-
r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_WAIT_FOR_HALT => {
363+
bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_CORE_WAIT_FOR_HALT => {
364364
Ok(SeqBufOpcode::CoreWaitForHalt)
365365
}
366-
r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_DELAY_US => Ok(SeqBufOpcode::DelayUs),
367-
r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_MODIFY => {
366+
bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_DELAY_US => Ok(SeqBufOpcode::DelayUs),
367+
bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_MODIFY => {
368368
Ok(SeqBufOpcode::RegModify)
369369
}
370-
r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_POLL => Ok(SeqBufOpcode::RegPoll),
371-
r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_STORE => Ok(SeqBufOpcode::RegStore),
372-
r570_144::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_WRITE => Ok(SeqBufOpcode::RegWrite),
370+
bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_POLL => Ok(SeqBufOpcode::RegPoll),
371+
bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_STORE => Ok(SeqBufOpcode::RegStore),
372+
bindings::GSP_SEQ_BUF_OPCODE_GSP_SEQ_BUF_OPCODE_REG_WRITE => Ok(SeqBufOpcode::RegWrite),
373373
_ => Err(EINVAL),
374374
}
375375
}
@@ -385,7 +385,7 @@ impl From<SeqBufOpcode> for u32 {
385385
/// Wrapper for GSP sequencer register write payload.
386386
#[repr(transparent)]
387387
#[derive(Copy, Clone)]
388-
pub(crate) struct RegWritePayload(r570_144::GSP_SEQ_BUF_PAYLOAD_REG_WRITE);
388+
pub(crate) struct RegWritePayload(bindings::GSP_SEQ_BUF_PAYLOAD_REG_WRITE);
389389

390390
impl RegWritePayload {
391391
/// Returns the register address.
@@ -408,7 +408,7 @@ unsafe impl AsBytes for RegWritePayload {}
408408
/// Wrapper for GSP sequencer register modify payload.
409409
#[repr(transparent)]
410410
#[derive(Copy, Clone)]
411-
pub(crate) struct RegModifyPayload(r570_144::GSP_SEQ_BUF_PAYLOAD_REG_MODIFY);
411+
pub(crate) struct RegModifyPayload(bindings::GSP_SEQ_BUF_PAYLOAD_REG_MODIFY);
412412

413413
impl RegModifyPayload {
414414
/// Returns the register address.
@@ -436,7 +436,7 @@ unsafe impl AsBytes for RegModifyPayload {}
436436
/// Wrapper for GSP sequencer register poll payload.
437437
#[repr(transparent)]
438438
#[derive(Copy, Clone)]
439-
pub(crate) struct RegPollPayload(r570_144::GSP_SEQ_BUF_PAYLOAD_REG_POLL);
439+
pub(crate) struct RegPollPayload(bindings::GSP_SEQ_BUF_PAYLOAD_REG_POLL);
440440

441441
impl RegPollPayload {
442442
/// Returns the register address.
@@ -469,7 +469,7 @@ unsafe impl AsBytes for RegPollPayload {}
469469
/// Wrapper for GSP sequencer delay payload.
470470
#[repr(transparent)]
471471
#[derive(Copy, Clone)]
472-
pub(crate) struct DelayUsPayload(r570_144::GSP_SEQ_BUF_PAYLOAD_DELAY_US);
472+
pub(crate) struct DelayUsPayload(bindings::GSP_SEQ_BUF_PAYLOAD_DELAY_US);
473473

474474
impl DelayUsPayload {
475475
/// Returns the delay value in microseconds.
@@ -487,7 +487,7 @@ unsafe impl AsBytes for DelayUsPayload {}
487487
/// Wrapper for GSP sequencer register store payload.
488488
#[repr(transparent)]
489489
#[derive(Copy, Clone)]
490-
pub(crate) struct RegStorePayload(r570_144::GSP_SEQ_BUF_PAYLOAD_REG_STORE);
490+
pub(crate) struct RegStorePayload(bindings::GSP_SEQ_BUF_PAYLOAD_REG_STORE);
491491

492492
impl RegStorePayload {
493493
/// Returns the register address.
@@ -510,7 +510,7 @@ unsafe impl AsBytes for RegStorePayload {}
510510

511511
/// Wrapper for GSP sequencer buffer command.
512512
#[repr(transparent)]
513-
pub(crate) struct SequencerBufferCmd(r570_144::GSP_SEQUENCER_BUFFER_CMD);
513+
pub(crate) struct SequencerBufferCmd(bindings::GSP_SEQUENCER_BUFFER_CMD);
514514

515515
impl SequencerBufferCmd {
516516
/// Returns the opcode as a `SeqBufOpcode` enum, or error if invalid.
@@ -612,7 +612,7 @@ unsafe impl AsBytes for SequencerBufferCmd {}
612612

613613
/// Wrapper for GSP run CPU sequencer RPC.
614614
#[repr(transparent)]
615-
pub(crate) struct RunCpuSequencer(r570_144::rpc_run_cpu_sequencer_v17_00);
615+
pub(crate) struct RunCpuSequencer(bindings::rpc_run_cpu_sequencer_v17_00);
616616

617617
impl RunCpuSequencer {
618618
/// Returns the command index.
@@ -797,13 +797,6 @@ impl bindings::rpc_message_header_v {
797797
}
798798
}
799799

800-
// SAFETY: We can't derive the Zeroable trait for this binding because the
801-
// procedural macro doesn't support the syntax used by bindgen to create the
802-
// __IncompleteArrayField types. So instead we implement it here, which is safe
803-
// because these are explicitly padded structures only containing types for
804-
// which any bit pattern, including all zeros, is valid.
805-
unsafe impl Zeroable for bindings::rpc_message_header_v {}
806-
807800
/// GSP Message Element.
808801
///
809802
/// This is essentially a message header expected to be followed by the message data.
@@ -853,11 +846,16 @@ impl GspMsgElement {
853846
self.inner.checkSum = checksum;
854847
}
855848

856-
/// Returns the total length of the message.
849+
/// Returns the length of the message's payload.
850+
pub(crate) fn payload_length(&self) -> usize {
851+
// `rpc.length` includes the length of the RPC message header.
852+
num::u32_as_usize(self.inner.rpc.length)
853+
.saturating_sub(size_of::<bindings::rpc_message_header_v>())
854+
}
855+
856+
/// Returns the total length of the message, message and RPC headers included.
857857
pub(crate) fn length(&self) -> usize {
858-
// `rpc.length` includes the length of the GspRpcHeader but not the message header.
859-
size_of::<Self>() - size_of::<bindings::rpc_message_header_v>()
860-
+ num::u32_as_usize(self.inner.rpc.length)
858+
size_of::<Self>() + self.payload_length()
861859
}
862860

863861
// Returns the sequence number of the message.

drivers/gpu/nova-core/gsp/fw/r570_144.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
unreachable_pub,
2525
unsafe_op_in_unsafe_fn
2626
)]
27-
use kernel::{
28-
ffi,
29-
prelude::Zeroable, //
30-
};
27+
use kernel::ffi;
28+
use pin_init::MaybeZeroable;
29+
3130
include!("r570_144/bindings.rs");
31+
32+
// SAFETY: This type has a size of zero, so its inclusion into another type should not affect their
33+
// ability to implement `Zeroable`.
34+
unsafe impl<T> kernel::prelude::Zeroable for __IncompleteArrayField<T> {}

0 commit comments

Comments
 (0)