Skip to content

Commit 095ac6f

Browse files
Baoquan Hebp3tk0v
authored andcommitted
x86/ioremap: Simplify setup_data mapping variants
memremap_is_setup_data() and early_memremap_is_setup_data() share completely the same process and handling, except for the differing memremap/unmap invocations. Add a helper __memremap_is_setup_data() extracting the common part and simplify a lot of code while at it. Mark __memremap_is_setup_data() as __ref to suppress this section mismatch warning: WARNING: modpost: vmlinux: section mismatch in reference: __memremap_is_setup_data+0x5f (section: .text) -> early_memunmap (section: .init.text) [ bp: Massage a bit. ] Signed-off-by: Baoquan He <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5daecec commit 095ac6f

File tree

1 file changed

+35
-71
lines changed

1 file changed

+35
-71
lines changed

arch/x86/mm/ioremap.c

Lines changed: 35 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -632,42 +632,54 @@ static bool memremap_is_efi_data(resource_size_t phys_addr,
632632
* Examine the physical address to determine if it is boot data by checking
633633
* it against the boot params setup_data chain.
634634
*/
635-
static bool memremap_is_setup_data(resource_size_t phys_addr,
636-
unsigned long size)
635+
static bool __ref __memremap_is_setup_data(resource_size_t phys_addr, bool early)
637636
{
637+
unsigned int setup_data_sz = sizeof(struct setup_data);
638638
struct setup_indirect *indirect;
639639
struct setup_data *data;
640640
u64 paddr, paddr_next;
641641

642642
paddr = boot_params.hdr.setup_data;
643643
while (paddr) {
644-
unsigned int len;
644+
unsigned int len, size;
645645

646646
if (phys_addr == paddr)
647647
return true;
648648

649-
data = memremap(paddr, sizeof(*data),
650-
MEMREMAP_WB | MEMREMAP_DEC);
649+
if (early)
650+
data = early_memremap_decrypted(paddr, setup_data_sz);
651+
else
652+
data = memremap(paddr, setup_data_sz, MEMREMAP_WB | MEMREMAP_DEC);
651653
if (!data) {
652-
pr_warn("failed to memremap setup_data entry\n");
654+
pr_warn("failed to remap setup_data entry\n");
653655
return false;
654656
}
655657

658+
size = setup_data_sz;
659+
656660
paddr_next = data->next;
657661
len = data->len;
658662

659663
if ((phys_addr > paddr) &&
660-
(phys_addr < (paddr + sizeof(struct setup_data) + len))) {
661-
memunmap(data);
664+
(phys_addr < (paddr + setup_data_sz + len))) {
665+
if (early)
666+
early_memunmap(data, setup_data_sz);
667+
else
668+
memunmap(data);
662669
return true;
663670
}
664671

665672
if (data->type == SETUP_INDIRECT) {
666-
memunmap(data);
667-
data = memremap(paddr, sizeof(*data) + len,
668-
MEMREMAP_WB | MEMREMAP_DEC);
673+
size += len;
674+
if (early) {
675+
early_memunmap(data, setup_data_sz);
676+
data = early_memremap_decrypted(paddr, size);
677+
} else {
678+
memunmap(data);
679+
data = memremap(paddr, size, MEMREMAP_WB | MEMREMAP_DEC);
680+
}
669681
if (!data) {
670-
pr_warn("failed to memremap indirect setup_data\n");
682+
pr_warn("failed to remap indirect setup_data\n");
671683
return false;
672684
}
673685

@@ -679,7 +691,10 @@ static bool memremap_is_setup_data(resource_size_t phys_addr,
679691
}
680692
}
681693

682-
memunmap(data);
694+
if (early)
695+
early_memunmap(data, size);
696+
else
697+
memunmap(data);
683698

684699
if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
685700
return true;
@@ -690,67 +705,16 @@ static bool memremap_is_setup_data(resource_size_t phys_addr,
690705
return false;
691706
}
692707

693-
/*
694-
* Examine the physical address to determine if it is boot data by checking
695-
* it against the boot params setup_data chain (early boot version).
696-
*/
708+
static bool memremap_is_setup_data(resource_size_t phys_addr,
709+
unsigned long size)
710+
{
711+
return __memremap_is_setup_data(phys_addr, false);
712+
}
713+
697714
static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
698715
unsigned long size)
699716
{
700-
struct setup_indirect *indirect;
701-
struct setup_data *data;
702-
u64 paddr, paddr_next;
703-
704-
paddr = boot_params.hdr.setup_data;
705-
while (paddr) {
706-
unsigned int len, size;
707-
708-
if (phys_addr == paddr)
709-
return true;
710-
711-
data = early_memremap_decrypted(paddr, sizeof(*data));
712-
if (!data) {
713-
pr_warn("failed to early memremap setup_data entry\n");
714-
return false;
715-
}
716-
717-
size = sizeof(*data);
718-
719-
paddr_next = data->next;
720-
len = data->len;
721-
722-
if ((phys_addr > paddr) &&
723-
(phys_addr < (paddr + sizeof(struct setup_data) + len))) {
724-
early_memunmap(data, sizeof(*data));
725-
return true;
726-
}
727-
728-
if (data->type == SETUP_INDIRECT) {
729-
size += len;
730-
early_memunmap(data, sizeof(*data));
731-
data = early_memremap_decrypted(paddr, size);
732-
if (!data) {
733-
pr_warn("failed to early memremap indirect setup_data\n");
734-
return false;
735-
}
736-
737-
indirect = (struct setup_indirect *)data->data;
738-
739-
if (indirect->type != SETUP_INDIRECT) {
740-
paddr = indirect->addr;
741-
len = indirect->len;
742-
}
743-
}
744-
745-
early_memunmap(data, size);
746-
747-
if ((phys_addr > paddr) && (phys_addr < (paddr + len)))
748-
return true;
749-
750-
paddr = paddr_next;
751-
}
752-
753-
return false;
717+
return __memremap_is_setup_data(phys_addr, true);
754718
}
755719

756720
/*

0 commit comments

Comments
 (0)