ACPI/IORT: rework num_ids off-by-one quirk
Subsystems (2)
v2 cover ACPI/IORT: rework num_ids off-by-one quirk
Replace the ACPI OEM ID matching based IORT quirk for the ID region size ambiguity with runtime handling of this condition.
This is based on the observation that we only care about this when it causes ambiguity regarding the output reference, which means that we will have more than one match for the input ID. In this case, we can just disregard the one at the end of a multi-ID region: if we hit it first, we record it tentatively but allow a subsequent match to supersede it. If we hit the correct match first, there is nothing we need to do.
Changes since v1:
- print FW_BUG error to the kernel log when a duplicate match is found
- ignore duplicate matches unless they occur at the start of a region (for compatibility with broken systems that might exist that happen to work today because the first match is always chosen)
Ard Biesheuvel (2):
Revert "ACPI/IORT: Fix 'Number of IDs' handling in iort_id_map()" ACPI/IORT: work around num_ids ambiguity
drivers/acpi/arm64/iort.c | 95 ++++++++------------ 1 file changed, 35 insertions(+), 60 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/2 Revert "ACPI/IORT: Fix 'Number of IDs' handling in iort_id_map()"
This reverts commit 3c23b83a88d00383e1d498cfa515249aa2fe0238.
--- drivers/acpi/arm64/iort.c | 57 +------------------- 1 file changed, 2 insertions(+), 55 deletions(-)
drivers/acpi/arm64/iort.c +2 -55
@@ -299,59 +299,6 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node,return status; } -struct iort_workaround_oem_info { -char oem_id[ACPI_OEM_ID_SIZE +1 ]; -char oem_table_id[ACPI_OEM_TABLE_ID_SIZE +1 ]; -u32 oem_revision; -}; - -static bool apply_id_count_workaround; - -static struct iort_workaround_oem_info wa_info[]__initdata = { - { - .oem_id ="HISI " , - .oem_table_id ="HIP07 " , - .oem_revision =0 , - }, { - .oem_id ="HISI " , - .oem_table_id ="HIP08 " , - .oem_revision =0 , - } -}; - -static void __init -iort_check_id_count_workaround (struct acpi_table_header *tbl) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (wa_info); i++) { -if (!memcmp (wa_info[i].oem_id, tbl->oem_id,ACPI_OEM_ID_SIZE ) && - !memcmp (wa_info[i].oem_table_id, tbl->oem_table_id,ACPI_OEM_TABLE_ID_SIZE ) && - wa_info[i].oem_revision == tbl->oem_revision) { - apply_id_count_workaround = true; -pr_warn (FW_BUG "ID count for ID mapping entry is wrong, applying workaround\n" ); -break ; - } - } -} - -static inline u32 iort_get_map_max (struct acpi_iort_id_mapping *map) -{ -u32 map_max = map->input_base + map->id_count; - -/* -* The IORT specification revision D (Section 3, table 4, page 9) says -* Number of IDs = The number of IDs in the range minus one, but the -* IORT code ignored the "minus one", and some firmware did that too, -* so apply a workaround here to keep compatible with both the spec -* compliant and non-spec compliant firmwares. -*/ -if (apply_id_count_workaround) - map_max--; - -return map_max; -} -static int iort_id_map (struct acpi_iort_id_mapping *map,u8 type,u32 rid_in,u32 *rid_out) {
@@ -368,7 +315,8 @@ static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in,return -ENXIO ; } -if (rid_in < map->input_base || rid_in >iort_get_map_max (map)) +if (rid_in < map->input_base || + (rid_in >= map->input_base + map->id_count))return -ENXIO ; *rid_out = map->output_base + (rid_in - map->input_base);
@@ -1703,6 +1651,5 @@ void __init acpi_iort_init(void)return ; } -iort_check_id_count_workaround (iort_table);iort_init_platform_devices (); }
Signature · 1 line
2.17.1
PATCH v2 2/2 ACPI/IORT: work around num_ids ambiguity
In reply to Ard BiesheuvelThe ID mapping table structure of the IORT table describes the size of a range using a num_ids field carrying the number of IDs in the region minus one. This has been misinterpreted in the past in the parsing code, and firmware is known to have shipped where this results in an ambiguity, where regions that should be adjacent have an overlap of one value.
So let's work around this by detecting this case specifically: when resolving an ID translation, allow one that matches right at the end of a multi-ID region to be superseded by a subsequent one.
To prevent potential regressions on broken firmware that happened to work before, only take the subsequent match into account if it occurs at the start of a mapping region.
--- drivers/acpi/arm64/iort.c | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-)
drivers/acpi/arm64/iort.c +34 -6
@@ -300,7 +300,7 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, }static int iort_id_map (struct acpi_iort_id_mapping *map,u8 type,u32 rid_in, -u32 *rid_out) +u32 *rid_out,bool check_overlap) {/* Single mapping does not care for input id */ if (map->flags &ACPI_IORT_ID_SINGLE_MAPPING ) {
@@ -316,10 +316,34 @@ static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, }if (rid_in < map->input_base || - (rid_in >= map->input_base + map->id_count)) + (rid_in > map->input_base + map->id_count))return -ENXIO ; +if (check_overlap) { +/* +* We already found a mapping for this input ID at the end of +* another region. If it coincides with the start of this +* region, we assume the prior match was due to the off-by-1 +* issue mentioned below, and allow it to be superseded. +* Otherwise, things are *really* broken, and we just disregard +* duplicate matches entirely to retain compatibility. +*/ +pr_err (FW_BUG "[map %p] conflicting mapping for input ID 0x%x\n" , + map, rid_in); +if (rid_in != map->input_base) +return -ENXIO ; + } + *rid_out = map->output_base + (rid_in - map->input_base); + +/* +* Due to confusion regarding the meaning of the id_count field (which +* carries the number of IDs *minus 1*), we may have to disregard this +* match if it is at the end of the range, and overlaps with the start +* of another one. +*/ +if (map->id_count >0 && rid_in == map->input_base + map->id_count) +return -EAGAIN ;return 0 ; }
@@ -404,7 +428,8 @@ static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node,/* Parse the ID mapping tree to find specified node type */ while (node) {struct acpi_iort_id_mapping *map; -int i, index; +int i, index, rc =0 ; +u32 out_ref =0 , map_id = id;if (IORT_TYPE_MASK (node->type) & type_mask) {if (id_out)
@@ -438,15 +463,18 @@ static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node,if (i == index)continue ; -if (!iort_id_map (map, node->type, id, &id)) + rc =iort_id_map (map, node->type, map_id, &id, out_ref); +if (!rc)break ; +if (rc == -EAGAIN ) + out_ref = map->output_reference; } -if (i == node->mapping_count) +if (i == node->mapping_count && !out_ref) goto fail_map; node = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, - map->output_reference); + rc ? out_ref : map->output_reference); } fail_map:
Signature · 1 line
2.17.1
Hanjun Guo
maintainerRe: [PATCH v2 2/2] ACPI/IORT: work around num_ids ambiguity
Quoted 41 lines · Ard Biesheuvel
The ID mapping table structure of the IORT table describes the size of a range using a
num_idsfield carrying the number of IDs in the region minus one. This has been misinterpreted in the past in the parsing code, and firmware is known to have shipped where this results in an ambiguity, where regions that should be adjacent have an overlap of one value.So let's work around this by detecting this case specifically: when resolving an ID translation, allow one that matches right at the end of a multi-ID region to be superseded by a subsequent one.
To prevent potential regressions on broken firmware that happened to work before, only take the subsequent match into account if it occurs at the start of a mapping region.
Signed-off-by Ard Biesheuvel <[email protected]>--- drivers/acpi/arm64/iort.c | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-)drivers/acpi/arm64/iort.c +3
-2@@ -300,7 +300,7 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, }static int iort_id_map (struct acpi_iort_id_mapping *map,u8 type,u32 rid_in, -u32 *rid_out) +u32 *rid_out,bool check_overlap) {/* Single mapping does not care for input id */ if (map->flags &ACPI_IORT_ID_SINGLE_MAPPING ) {@@ -316,10 +316,34 @@ static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, }if (rid_in < map->input_base || - (rid_in >= map->input_base + map->id_count)) + (rid_in > map->input_base + map->id_count))return -ENXIO ; +if (check_overlap) {
drivers/acpi/arm64/iort.c static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, · line 332
Quoted 10 lines
drivers/acpi/arm64/iort.c +10
-0+/* +* We already found a mapping for this input ID at the end of +* another region. If it coincides with the start of this +* region, we assume the prior match was due to the off-by-1 +* issue mentioned below, and allow it to be superseded. +* Otherwise, things are *really* broken, and we just disregard +* duplicate matches entirely to retain compatibility. +*/ +pr_err (FW_BUG "[map %p] conflicting mapping for input ID 0x%x\n" , + map, rid_in);
As we already applied a workaround here, can we add "applying workaround" in the error message? This will make the customers less uneasy to see such message in the boot log. Once the product was deliveried to customers, it's not that easy to update all the firmwares entirely.
I'm out of reach for D05/D06 hardware as it's holidays in China, please allow me to test this patch set in Wednesday this week.
Thanks
Hanjun
Re: [PATCH v2 2/2] ACPI/IORT: work around num_ids ambiguity
Quoted 51 lines · Hanjun Guo
Quoted 49 lines · Ard Biesheuvel
The ID mapping table structure of the IORT table describes the size of a range using a
num_idsfield carrying the number of IDs in the region minus one. This has been misinterpreted in the past in the parsing code, and firmware is known to have shipped where this results in an ambiguity, where regions that should be adjacent have an overlap of one value.So let's work around this by detecting this case specifically: when resolving an ID translation, allow one that matches right at the end of a multi-ID region to be superseded by a subsequent one.
To prevent potential regressions on broken firmware that happened to work before, only take the subsequent match into account if it occurs at the start of a mapping region.
Signed-off-by Ard Biesheuvel <[email protected]>--- drivers/acpi/arm64/iort.c | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-)drivers/acpi/arm64/iort.c +11
-2@@ -300,7 +300,7 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, }static int iort_id_map (struct acpi_iort_id_mapping *map,u8 type,u32 rid_in, -u32 *rid_out) +u32 *rid_out,bool check_overlap) {/* Single mapping does not care for input id */ if (map->flags &ACPI_IORT_ID_SINGLE_MAPPING ) {@@ -316,10 +316,34 @@ static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, }if (rid_in < map->input_base || - (rid_in >= map->input_base + map->id_count)) + (rid_in > map->input_base + map->id_count))return -ENXIO ; +if (check_overlap) { +/* +* We already found a mapping for this input ID at the end of +* another region. If it coincides with the start of this +* region, we assume the prior match was due to the off-by-1 +* issue mentioned below, and allow it to be superseded. +* Otherwise, things are *really* broken, and we just disregard +* duplicate matches entirely to retain compatibility. +*/
Quoted 9 lines
drivers/acpi/arm64/iort.c static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, · line 332
Quoted 2 lines
drivers/acpi/arm64/iort.c +2
-0+pr_err (FW_BUG "[map %p] conflicting mapping for input ID 0x%x\n" , + map, rid_in);As we already applied a workaround here, can we add "applying workaround" in the error message? This will make the customers less uneasy to see such message in the boot log. Once the product was deliveried to customers, it's not that easy to update all the firmwares entirely.
Sure.
Quoted 3 lines
I'm out of reach for D05/D06 hardware as it's holidays in China, please allow me to test this patch set in Wednesday this week.
Yes please
Hanjun Guo
maintainerRe: [PATCH v2 2/2] ACPI/IORT: work around num_ids ambiguity
Quoted 62 lines · Ard Biesheuvel
Quoted 51 lines · Hanjun Guo
Quoted 49 lines · Ard Biesheuvel
The ID mapping table structure of the IORT table describes the size of a range using a
num_idsfield carrying the number of IDs in the region minus one. This has been misinterpreted in the past in the parsing code, and firmware is known to have shipped where this results in an ambiguity, where regions that should be adjacent have an overlap of one value.So let's work around this by detecting this case specifically: when resolving an ID translation, allow one that matches right at the end of a multi-ID region to be superseded by a subsequent one.
To prevent potential regressions on broken firmware that happened to work before, only take the subsequent match into account if it occurs at the start of a mapping region.
Signed-off-by Ard Biesheuvel <[email protected]>--- drivers/acpi/arm64/iort.c | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-)drivers/acpi/arm64/iort.c +11
-2@@ -300,7 +300,7 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, }static int iort_id_map (struct acpi_iort_id_mapping *map,u8 type,u32 rid_in, -u32 *rid_out) +u32 *rid_out,bool check_overlap) {/* Single mapping does not care for input id */ if (map->flags &ACPI_IORT_ID_SINGLE_MAPPING ) {@@ -316,10 +316,34 @@ static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, }if (rid_in < map->input_base || - (rid_in >= map->input_base + map->id_count)) + (rid_in > map->input_base + map->id_count))return -ENXIO ; +if (check_overlap) { +/* +* We already found a mapping for this input ID at the end of +* another region. If it coincides with the start of this +* region, we assume the prior match was due to the off-by-1 +* issue mentioned below, and allow it to be superseded. +* Otherwise, things are *really* broken, and we just disregard +* duplicate matches entirely to retain compatibility. +*/ Quoted 9 lines
drivers/acpi/arm64/iort.c static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, · line 332
Quoted 2 lines
drivers/acpi/arm64/iort.c +2
-0+pr_err (FW_BUG "[map %p] conflicting mapping for input ID 0x%x\n" , + map, rid_in);As we already applied a workaround here, can we add "applying workaround" in the error message? This will make the customers less uneasy to see such message in the boot log. Once the product was deliveried to customers, it's not that easy to update all the firmwares entirely.
Quoted 1 line
Sure.
Since Will already merged this patchset, I would like to send a patch on top of it, what do you think?
Thanks
Hanjun
Will Deacon
maintainerRe: [PATCH v2 2/2] ACPI/IORT: work around num_ids ambiguity
Quoted 43 lines · Hanjun Guo
Quoted 42 lines · Ard Biesheuvel
Quoted 40 lines · Hanjun Guo
Quoted 22 lines · Ard Biesheuvel
drivers/acpi/arm64/iort.c +3
-2@@ -300,7 +300,7 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, }static int iort_id_map (struct acpi_iort_id_mapping *map,u8 type,u32 rid_in, -u32 *rid_out) +u32 *rid_out,bool check_overlap) {/* Single mapping does not care for input id */ if (map->flags &ACPI_IORT_ID_SINGLE_MAPPING ) {@@ -316,10 +316,34 @@ static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, }if (rid_in < map->input_base || - (rid_in >= map->input_base + map->id_count)) + (rid_in > map->input_base + map->id_count))return -ENXIO ; +if (check_overlap) {drivers/acpi/arm64/iort.c static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, · line 332
Quoted 10 lines
drivers/acpi/arm64/iort.c +10
-0+/* +* We already found a mapping for this input ID at the end of +* another region. If it coincides with the start of this +* region, we assume the prior match was due to the off-by-1 +* issue mentioned below, and allow it to be superseded. +* Otherwise, things are *really* broken, and we just disregard +* duplicate matches entirely to retain compatibility. +*/ +pr_err (FW_BUG "[map %p] conflicting mapping for input ID 0x%x\n" , + map, rid_in);As we already applied a workaround here, can we add "applying workaround" in the error message? This will make the customers less uneasy to see such message in the boot log. Once the product was deliveried to customers, it's not that easy to update all the firmwares entirely.
Quoted 4 lines
Quoted 1 line
Sure.
Since Will already merged this patchset, I would like to send a patch on top of it, what do you think?
Yes, please! I figured I'd queue it, as I could always revert it if your testing came back negative but extra stuff on top is always fine.
Will
Hanjun Guo
maintainerRe: [PATCH v2 2/2] ACPI/IORT: work around num_ids ambiguity
Quoted 44 lines · Will Deacon
Quoted 43 lines · Hanjun Guo
Quoted 42 lines · Ard Biesheuvel
Quoted 40 lines · Hanjun Guo
Quoted 22 lines · Ard Biesheuvel
drivers/acpi/arm64/iort.c +3
-2@@ -300,7 +300,7 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, }static int iort_id_map (struct acpi_iort_id_mapping *map,u8 type,u32 rid_in, -u32 *rid_out) +u32 *rid_out,bool check_overlap) {/* Single mapping does not care for input id */ if (map->flags &ACPI_IORT_ID_SINGLE_MAPPING ) {@@ -316,10 +316,34 @@ static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, }if (rid_in < map->input_base || - (rid_in >= map->input_base + map->id_count)) + (rid_in > map->input_base + map->id_count))return -ENXIO ; +if (check_overlap) {drivers/acpi/arm64/iort.c static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, · line 332
Quoted 10 lines
drivers/acpi/arm64/iort.c +10
-0+/* +* We already found a mapping for this input ID at the end of +* another region. If it coincides with the start of this +* region, we assume the prior match was due to the off-by-1 +* issue mentioned below, and allow it to be superseded. +* Otherwise, things are *really* broken, and we just disregard +* duplicate matches entirely to retain compatibility. +*/ +pr_err (FW_BUG "[map %p] conflicting mapping for input ID 0x%x\n" , + map, rid_in);As we already applied a workaround here, can we add "applying workaround" in the error message? This will make the customers less uneasy to see such message in the boot log. Once the product was deliveried to customers, it's not that easy to update all the firmwares entirely.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Sure.
Since Will already merged this patchset, I would like to send a patch on top of it, what do you think?
Yes, please! I figured I'd queue it, as I could always revert it if your testing came back negative but extra stuff on top is always fine.
OK, I will prepare a patch and send out for review.
Thanks
Hanjun
Re: [PATCH v2 2/2] ACPI/IORT: work around num_ids ambiguity
In reply to Hanjun GuoQuoted 59 lines · Hanjun Guo
Quoted 43 lines · Ard Biesheuvel
The ID mapping table structure of the IORT table describes the size of a range using a
num_idsfield carrying the number of IDs in the region minus one. This has been misinterpreted in the past in the parsing code, and firmware is known to have shipped where this results in an ambiguity, where regions that should be adjacent have an overlap of one value.So let's work around this by detecting this case specifically: when resolving an ID translation, allow one that matches right at the end of a multi-ID region to be superseded by a subsequent one.
To prevent potential regressions on broken firmware that happened to work before, only take the subsequent match into account if it occurs at the start of a mapping region.
Signed-off-by Ard Biesheuvel <[email protected]>---
drivers/acpi/arm64/iort.c| 40 +++++++++++++++++---1 file changed, 34 insertions(+), 6 deletions(-)drivers/acpi/arm64/iort.c +1
-1@@ -300,7 +300,7 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, } static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, - u32 *rid_out) + u32 *rid_out, bool check_overlap) { /* Single mapping does not care for input id */ if (map->flags & ACPI_IORT_ID_SINGLE_MAPPING) {@@ -316,10 +316,34 @@ static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, }if (
rid_in<map->input_base||
- (rid_in>=map->input_base+map->id_count))
+ (rid_in>map->input_base+map->id_count))
return-ENXIO;
+ if (check_overlap) {
+ /*
+ * We already found a mapping for this input ID at the end of + * another region. If it coincides with the start of thisQuoted 8 lines
+ * region, we assume the prior match was due to the off-by-1 + * issue mentioned below, and allow it to be superseded. + * Otherwise, things are *really* broken, and we just disregard + * duplicate matches entirely to retain compatibility. + */
+ pr_err(FW_BUG "[map %p] conflicting mapping for input ID 0x%x\n",
+ map,rid_in);As we already applied a workaround here, can we add "applying workaround" in the error message? This will make the customers less uneasy to see such message in the boot log. Once the product was deliveried to customers, it's not that easy to update all the firmwares entirely.
Quoted 2 lines
I'm out of reach for D05/D06 hardware as it's holidays in China, please allow me to test this patch set in Wednesday this week.
Tested this patchset on D06 and I comapared each sucessful mapped ID, no regressions, and also no function regressions as well,
Thanks
Hanjun
Re: [PATCH v2 2/2] ACPI/IORT: work around num_ids ambiguity
In reply to Ard BiesheuvelQuoted 10 lines · Ard Biesheuvel
The ID mapping table structure of the IORT table describes the size of a range using a
num_idsfield carrying the number of IDs in the region minus one. This has been misinterpreted in the past in the parsing code, and firmware is known to have shipped where this results in an ambiguity, where regions that should be adjacent have an overlap of one value.So let's work around this by detecting this case specifically: when resolving an ID translation, allow one that matches right at the end of a multi-ID region to be superseded by a subsequent one.
Quoted 8 lines
To prevent potential regressions on broken firmware that happened to work before, only take the subsequent match into account if it occurs at the start of a mapping region.
Signed-off-by Ard Biesheuvel <[email protected]>--- drivers/acpi/arm64/iort.c | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-)
The patch logic is sound - I still think that the resulting code can benefit from a one-off boot time mapping data initialisation but we can address that later as a clean-up, first thing is to remove the quirk mechanism.
Goes without saying, this needs extensive testing on existing platforms before sending it to stable kernels.
Quoted 84 lines
drivers/acpi/arm64/iort.c +34
-6@@ -300,7 +300,7 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, }static int iort_id_map (struct acpi_iort_id_mapping *map,u8 type,u32 rid_in, -u32 *rid_out) +u32 *rid_out,bool check_overlap) {/* Single mapping does not care for input id */ if (map->flags &ACPI_IORT_ID_SINGLE_MAPPING ) {@@ -316,10 +316,34 @@ static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, }if (rid_in < map->input_base || - (rid_in >= map->input_base + map->id_count)) + (rid_in > map->input_base + map->id_count))return -ENXIO ; +if (check_overlap) { +/* +* We already found a mapping for this input ID at the end of +* another region. If it coincides with the start of this +* region, we assume the prior match was due to the off-by-1 +* issue mentioned below, and allow it to be superseded. +* Otherwise, things are *really* broken, and we just disregard +* duplicate matches entirely to retain compatibility. +*/ +pr_err (FW_BUG "[map %p] conflicting mapping for input ID 0x%x\n" , + map, rid_in); +if (rid_in != map->input_base) +return -ENXIO ; + } + *rid_out = map->output_base + (rid_in - map->input_base); + +/* +* Due to confusion regarding the meaning of the id_count field (which +* carries the number of IDs *minus 1*), we may have to disregard this +* match if it is at the end of the range, and overlaps with the start +* of another one. +*/ +if (map->id_count >0 && rid_in == map->input_base + map->id_count) +return -EAGAIN ;return 0 ; }@@ -404,7 +428,8 @@ static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node,/* Parse the ID mapping tree to find specified node type */ while (node) {struct acpi_iort_id_mapping *map; -int i, index; +int i, index, rc =0 ; +u32 out_ref =0 , map_id = id;if (IORT_TYPE_MASK (node->type) & type_mask) {if (id_out)@@ -438,15 +463,18 @@ static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node,if (i == index)continue ; -if (!iort_id_map (map, node->type, id, &id)) + rc =iort_id_map (map, node->type, map_id, &id, out_ref); +if (!rc)break ; +if (rc == -EAGAIN ) + out_ref = map->output_reference; } -if (i == node->mapping_count) +if (i == node->mapping_count && !out_ref) goto fail_map; node = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, - map->output_reference); + rc ? out_ref : map->output_reference); } fail_map:Signature · 1 line
2.17.1
Quoted 11 lines · Ard Biesheuvel
Replace the ACPI OEM ID matching based IORT quirk for the ID region size ambiguity with runtime handling of this condition.
This is based on the observation that we only care about this when it causes ambiguity regarding the output reference, which means that we will have more than one match for the input ID. In this case, we can just disregard the one at the end of a multi-ID region: if we hit it first, we record it tentatively but allow a subsequent match to supersede it. If we hit the correct match first, there is nothing we need to do.
Quoted 1 line
[...]
Applied to arm64 (for-next/acpi), thanks!
[1/2] Revert "ACPI/IORT: Fix 'Number of IDs' handling in iort_id_map()"
https://git.kernel.org/arm64/c/6d3b29d07c3c [2/2] ACPI/IORT: work around num_ids ambiguity https://git.kernel.org/arm64/c/539979b6ec62
Cheers,
Signature · 4 lines
Will https://fixes.arm64.dev https://next.arm64.dev