The DMA API expects that callers use the same attributes when mapping and unmapping. Add tracking to verify this and catch mismatches.
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -1074,6 +1074,29 @@ static void check_unmap(struct dma_debug_entry *ref) · 1073 unmodified lines | ||
| 1074 | 1074 | type2name[entry->type]); |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 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 | + | |
| 1077 | 1100 | hash_bucket_del(entry); |
| 1078 | 1101 | put_hash_bucket(bucket, flags); |
| 1079 | 1102 | |