History

dma-debug: Ensure mappings are created and released with matching attributes

The DMA API expects that callers use the same attributes when mapping and unmapping. Add tracking to verify this and catch mismatches.

Leon Romanovsky committed 6 months ago

Commit a34bd601 parent c8411b11 file · +23 −0Browse files

Unified · Split

kernel/dma/debug.c+23−0
@@ -1074,6 +1074,29 @@ static void check_unmap(struct dma_debug_entry *ref) · 1073 unmodified lines
10741074 type2name[entry->type]);
10751075 }
10761076
1077+ /*
1078+ * This may be no bug in reality - but DMA API still expects
1079+ * that entry is unmapped with same attributes as it was mapped.
1080+ *
1081+ * DMA_ATTR_UNMAP_VALID lists the attributes that must be identical
1082+ * between map and unmap. Any attribute outside this set (e.g.
1083+ * DMA_ATTR_NO_WARN, DMA_ATTR_SKIP_CPU_SYNC) is allowed to differ.
1084+ */
1085+#define DMA_ATTR_UNMAP_VALID \
1086+ (DMA_ATTR_NO_KERNEL_MAPPING | DMA_ATTR_FORCE_CONTIGUOUS | \
1087+ DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT | DMA_ATTR_PRIVILEGED | \
1088+ DMA_ATTR_CC_SHARED)
1089+ if ((ref->attrs & DMA_ATTR_UNMAP_VALID) !=
1090+ (entry->attrs & DMA_ATTR_UNMAP_VALID)) {
1091+ err_printk(ref->dev, entry,
1092+ "device driver frees "
1093+ "DMA memory with different attributes "
1094+ "[device address=0x%016llx] [size=%llu bytes] "
1095+ "[mapped with 0x%lx] [unmapped with 0x%lx]\n",
1096+ ref->dev_addr, ref->size, entry->attrs, ref->attrs);
1097+ }
1098+#undef DMA_ATTR_UNMAP_VALID
1099+
10771100 hash_bucket_del(entry);
10781101 put_hash_bucket(bucket, flags);
10791102

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t