Skip to contentSkip to conversation

rust: mm: warn once on invalid VMA range

PATCH Superseded Ivan Tverdokhleb 2 participants 2 messages Nov 24 – Nov 26 1 message not in the archive

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/1 rust: mm: warn once on invalid VMA range

In reply to a message not in the archive

Use debug_assert!() and pr_warn_once!() in
Vma::zap_vma_range() to report invalid ranges.

---
Changes in v2:
- Drop the warn_once!() macro and its KUnit test.
- Use debug_assert!() and pr_warn_once!() in Vma::zap_vma_range() as suggested by Miguel.

 rust/kernel/mm/virt.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
rust/kernel/mm/virt.rs +2 -1
index 63eb730b0..1a3a990c9 100644
@@ -115,8 +115,9 @@ pub fn end(&self) -> usize {
     #[inline]
     pub fn zap_vma_range(&self, address: usize, size: usize) {
         let (end, did_overflow) = address.overflowing_add(size);
+        debug_assert!(!did_overflow && address >= self.start() && self.end() >= end);
         if did_overflow || address < self.start() || self.end() < end {
-            // TODO: call WARN_ONCE once Rust version of it is added
+            crate::pr_warn_once!("Attempt to zap invalid VMA range\n");
             return;
         }
 
Signature · 1 line
2.56.1
#2 lore raw

Hello,

Quoted 17 lines · Ivan Tverdokhleb

Use debug_assert!() and pr_warn_once!() in
Vma::zap_vma_range() to report invalid ranges.

---
Changes in v2:
- Drop the warn_once!() macro and its KUnit test.
- Use debug_assert!() and pr_warn_once!() in Vma::zap_vma_range() as suggested by Miguel.

 rust/kernel/mm/virt.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
rust/kernel/mm/virt.rs +0 -0
index 63eb730b0..1a3a990c9 100644

rust/kernel/mm/virt.rs pub fn end(&self) -> usize { · line 120

Quoted 7 lines
rust/kernel/mm/virt.rs +2 -1
@@ -115,8 +115,9 @@ pub fn end(&self) -> usize {
     #[inline]
     pub fn zap_vma_range(&self, address: usize, size: usize) {
         let (end, did_overflow) = address.overflowing_add(size);
+        debug_assert!(!did_overflow && address >= self.start() && self.end() >= end);
         if did_overflow || address < self.start() || self.end() < end {
-            // TODO: call WARN_ONCE once Rust version of it is added
+            crate::pr_warn_once!("Attempt to zap invalid VMA range\n");

I believe by the comment of Fujita [1], the pr_warn_once! should be guarded by #[cfg(CONFIG_DEBUG_VM)].

Regards,
Nicolás

[1] https://lore.kernel.org/rust-for-linux/[email protected]/