Skip to content

Commit c1a2f4b

Browse files
yhluIngo Molnar
authored and
Ingo Molnar
committed
x86: change early_ioremap to use slots instead of nesting
so we could remove the requirement that one needs to call early_iounmap() in exactly reverse order of early_ioremap(). Signed-off-by: Yinghai Lu <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 79aa10d commit c1a2f4b

File tree

3 files changed

+61
-24
lines changed

3 files changed

+61
-24
lines changed

arch/x86/mm/ioremap.c

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -616,16 +616,22 @@ static inline void __init early_clear_fixmap(enum fixed_addresses idx)
616616
__early_set_fixmap(idx, 0, __pgprot(0));
617617
}
618618

619-
620-
static int __initdata early_ioremap_nested;
621-
619+
static void *prev_map[FIX_BTMAPS_SLOTS] __initdata;
620+
static unsigned long prev_size[FIX_BTMAPS_SLOTS] __initdata;
622621
static int __init check_early_ioremap_leak(void)
623622
{
624-
if (!early_ioremap_nested)
623+
int count = 0;
624+
int i;
625+
626+
for (i = 0; i < FIX_BTMAPS_SLOTS; i++)
627+
if (prev_map[i])
628+
count++;
629+
630+
if (!count)
625631
return 0;
626632
WARN(1, KERN_WARNING
627633
"Debug warning: early ioremap leak of %d areas detected.\n",
628-
early_ioremap_nested);
634+
count);
629635
printk(KERN_WARNING
630636
"please boot with early_ioremap_debug and report the dmesg.\n");
631637

@@ -636,15 +642,30 @@ late_initcall(check_early_ioremap_leak);
636642
static void __init *__early_ioremap(unsigned long phys_addr, unsigned long size, pgprot_t prot)
637643
{
638644
unsigned long offset, last_addr;
639-
unsigned int nrpages, nesting;
645+
unsigned int nrpages;
640646
enum fixed_addresses idx0, idx;
647+
int i, slot;
641648

642649
WARN_ON(system_state != SYSTEM_BOOTING);
643650

644-
nesting = early_ioremap_nested;
651+
slot = -1;
652+
for (i = 0; i < FIX_BTMAPS_SLOTS; i++) {
653+
if (!prev_map[i]) {
654+
slot = i;
655+
break;
656+
}
657+
}
658+
659+
if (slot < 0) {
660+
printk(KERN_INFO "early_iomap(%08lx, %08lx) not found slot\n",
661+
phys_addr, size);
662+
WARN_ON(1);
663+
return NULL;
664+
}
665+
645666
if (early_ioremap_debug) {
646667
printk(KERN_INFO "early_ioremap(%08lx, %08lx) [%d] => ",
647-
phys_addr, size, nesting);
668+
phys_addr, size, slot);
648669
dump_stack();
649670
}
650671

@@ -655,11 +676,7 @@ static void __init *__early_ioremap(unsigned long phys_addr, unsigned long size,
655676
return NULL;
656677
}
657678

658-
if (nesting >= FIX_BTMAPS_NESTING) {
659-
WARN_ON(1);
660-
return NULL;
661-
}
662-
early_ioremap_nested++;
679+
prev_size[slot] = size;
663680
/*
664681
* Mappings have to be page-aligned
665682
*/
@@ -679,7 +696,7 @@ static void __init *__early_ioremap(unsigned long phys_addr, unsigned long size,
679696
/*
680697
* Ok, go for it..
681698
*/
682-
idx0 = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*nesting;
699+
idx0 = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*slot;
683700
idx = idx0;
684701
while (nrpages > 0) {
685702
early_set_fixmap(idx, phys_addr, prot);
@@ -690,7 +707,8 @@ static void __init *__early_ioremap(unsigned long phys_addr, unsigned long size,
690707
if (early_ioremap_debug)
691708
printk(KERN_CONT "%08lx + %08lx\n", offset, fix_to_virt(idx0));
692709

693-
return (void *) (offset + fix_to_virt(idx0));
710+
prev_map[slot] = (void *) (offset + fix_to_virt(idx0));
711+
return prev_map[slot];
694712
}
695713

696714
/* Remap an IO device */
@@ -711,15 +729,33 @@ void __init early_iounmap(void *addr, unsigned long size)
711729
unsigned long offset;
712730
unsigned int nrpages;
713731
enum fixed_addresses idx;
714-
int nesting;
732+
int i, slot;
733+
734+
slot = -1;
735+
for (i = 0; i < FIX_BTMAPS_SLOTS; i++) {
736+
if (prev_map[i] == addr) {
737+
slot = i;
738+
break;
739+
}
740+
}
715741

716-
nesting = --early_ioremap_nested;
717-
if (WARN_ON(nesting < 0))
742+
if (slot < 0) {
743+
printk(KERN_INFO "early_iounmap(%p, %08lx) not found slot\n",
744+
addr, size);
745+
WARN_ON(1);
746+
return;
747+
}
748+
749+
if (prev_size[slot] != size) {
750+
printk(KERN_INFO "early_iounmap(%p, %08lx) [%d] size not consistent %08lx\n",
751+
addr, size, slot, prev_size[slot]);
752+
WARN_ON(1);
718753
return;
754+
}
719755

720756
if (early_ioremap_debug) {
721757
printk(KERN_INFO "early_iounmap(%p, %08lx) [%d]\n", addr,
722-
size, nesting);
758+
size, slot);
723759
dump_stack();
724760
}
725761

@@ -731,12 +767,13 @@ void __init early_iounmap(void *addr, unsigned long size)
731767
offset = virt_addr & ~PAGE_MASK;
732768
nrpages = PAGE_ALIGN(offset + size - 1) >> PAGE_SHIFT;
733769

734-
idx = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*nesting;
770+
idx = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*slot;
735771
while (nrpages > 0) {
736772
early_clear_fixmap(idx);
737773
--idx;
738774
--nrpages;
739775
}
776+
prev_map[slot] = 0;
740777
}
741778

742779
void __this_fixmap_does_not_exist(void)

include/asm-x86/fixmap_32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ enum fixed_addresses {
9494
* can have a single pgd entry and a single pte table:
9595
*/
9696
#define NR_FIX_BTMAPS 64
97-
#define FIX_BTMAPS_NESTING 4
97+
#define FIX_BTMAPS_SLOTS 4
9898
FIX_BTMAP_END = __end_of_permanent_fixed_addresses + 256 -
9999
(__end_of_permanent_fixed_addresses & 255),
100-
FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS*FIX_BTMAPS_NESTING - 1,
100+
FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS*FIX_BTMAPS_SLOTS - 1,
101101
FIX_WP_TEST,
102102
#ifdef CONFIG_ACPI
103103
FIX_ACPI_BEGIN,

include/asm-x86/fixmap_64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ enum fixed_addresses {
6565
* can have a single pgd entry and a single pte table:
6666
*/
6767
#define NR_FIX_BTMAPS 64
68-
#define FIX_BTMAPS_NESTING 4
68+
#define FIX_BTMAPS_SLOTS 4
6969
FIX_BTMAP_END = __end_of_permanent_fixed_addresses + 256 -
7070
(__end_of_permanent_fixed_addresses & 255),
71-
FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS*FIX_BTMAPS_NESTING - 1,
71+
FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS*FIX_BTMAPS_SLOTS - 1,
7272
__end_of_fixed_addresses
7373
};
7474

0 commit comments

Comments
 (0)