Skip to content

Commit 1522ac3

Browse files
Russell KingRussell King
authored andcommitted
[ARM] Fix virtual to physical translation macro corner cases
The current use of these macros works well when the conversion is entirely linear. In this case, we can be assured that the following holds true: __va(p + s) - s = __va(p) However, this is not always the case, especially when there is a non-linear conversion (eg, when there is a 3.5GB hole in memory.) In this case, if 's' is the size of the region (eg, PAGE_SIZE) and 'p' is the final page, the above is most definitely not true. So, we must ensure that __va() and __pa() are only used with valid kernel direct mapped RAM addresses. This patch tweaks the code to achieve this. Tested-by: Charles Moschel <fred99@carolina.rr.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 305b076 commit 1522ac3

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

‎arch/arm/mm/dma-mapping.c‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,26 +490,30 @@ core_initcall(consistent_init);
490490
*/
491491
void dma_cache_maint(const void *start, size_t size, int direction)
492492
{
493-
const void *end = start + size;
493+
void (*inner_op)(const void *, const void *);
494+
void (*outer_op)(unsigned long, unsigned long);
494495

495-
BUG_ON(!virt_addr_valid(start) || !virt_addr_valid(end - 1));
496+
BUG_ON(!virt_addr_valid(start) || !virt_addr_valid(start + size - 1));
496497

497498
switch (direction) {
498499
case DMA_FROM_DEVICE: /* invalidate only */
499-
dmac_inv_range(start, end);
500-
outer_inv_range(__pa(start), __pa(end));
500+
inner_op = dmac_inv_range;
501+
outer_op = outer_inv_range;
501502
break;
502503
case DMA_TO_DEVICE: /* writeback only */
503-
dmac_clean_range(start, end);
504-
outer_clean_range(__pa(start), __pa(end));
504+
inner_op = dmac_clean_range;
505+
outer_op = outer_clean_range;
505506
break;
506507
case DMA_BIDIRECTIONAL: /* writeback and invalidate */
507-
dmac_flush_range(start, end);
508-
outer_flush_range(__pa(start), __pa(end));
508+
inner_op = dmac_flush_range;
509+
outer_op = outer_flush_range;
509510
break;
510511
default:
511512
BUG();
512513
}
514+
515+
inner_op(start, start + size);
516+
outer_op(__pa(start), __pa(start) + size);
513517
}
514518
EXPORT_SYMBOL(dma_cache_maint);
515519

‎arch/arm/mm/init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ void __init bootmem_init(void)
382382
for_each_node(node)
383383
bootmem_free_node(node, mi);
384384

385-
high_memory = __va(memend_pfn << PAGE_SHIFT);
385+
high_memory = __va((memend_pfn << PAGE_SHIFT) - 1) + 1;
386386

387387
/*
388388
* This doesn't seem to be used by the Linux memory manager any

‎arch/arm/mm/mmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int valid_phys_addr_range(unsigned long addr, size_t size)
124124
{
125125
if (addr < PHYS_OFFSET)
126126
return 0;
127-
if (addr + size > __pa(high_memory))
127+
if (addr + size >= __pa(high_memory - 1))
128128
return 0;
129129

130130
return 1;

0 commit comments

Comments
 (0)