Skip to contentSkip to conversation

ACPICA: ACPICA 20260930 with follow-up fixes

PATCH New Maciej Wieczor-Retman 1 participant 43 messages Nov 20

Subsystems (4)
lore
Share & tools
lore

Maciej Wieczor-Retman

author maintainer
#0 lore raw

v2 cover ACPICA: ACPICA 20260930 with follow-up fixes

The following patches are ported from upstream ACPICA and contain the 20260930 release and some follow up fixes (so generally everything after the 20260408 release). Only source files relevant to the Linux kernel are being ported.

Changes since v1:
v1 [1] contained only commits between the 20260408 and 20260930 releases. However sashiko.dev [2] raised some issues that needed to be either applied or rejected. Most issues were valid and were resolved in patches that follow the 20260930 release. Things that were rejected were the whole patch [3] due to not being a full solution to a very unlikely, debug only problem. Also the sashiko comment related to ACPI_GPE_AUTO_ENABLED in patch [4] wasn't applied due to not being realistically possible to happen and consequences were only an odd looking log entry.

There are non-ACPICA changes related to constants/variable name changes in these patches:
- ACPICA: actbl2: MPAM: adapt to MPAM ACPI spec v3.1
- ACPICA: acpica: Fix typo in the IOVT_IOMMU table definitions

The base for this patches is upstream kernel v7.4-rc3 and it consists of the following material:

Andre Przywara (1):
ACPICA: actbl2: MPAM: adapt to MPAM ACPI spec v3.1

Colin Ian King (2):

      ACPICA: components: Fix typo "Supress" -> "Suppress"
      ACPICA: components: Fix typo: "numer" -> "number"

Dave Jiang (2):
ACPICA: CEDT: RDPAS: Add missing reserved field in RDPAS structure
ACPICA: CEDT: RDPAS: Fix incorrect field positions for RDPAS

Hanjun Guo (1):
ACPICA: add UBRT (UnifiedBus Root Table) definitions

Himanshu Chauhan (1):
ACPICA: Introduce a new HEST notification type for RISC-V SSE events

Iurii Trukhin (1):
ACPICA: parser: Fix parse tree memory leak on AML execution error unwind

Leonard Lausen (1):
ACPICA: Executer: Resolve package index references used as integer operands

Maciej Strozek (1):
ACPICA: Utilities: Fix for AcpiUtVerifyChecksum warning display

Maciej Wieczor-Retman (17):
ACPICA: executer: Fix NULL pointer dereference in AcpiExStoreObjectToIndex()
ACPICA: compiler: Add _Ixx GPE object
ACPICA: namespace: Fix possible underflow and NULL pointer dereference
ACPICA: iASL: Fix the truncated count of external control methods
ACPICA: release: Update version to 20260930
ACPICA: events: Add missing event mutex to AcpiEvClearGpeDispatchByOwner()
ACPICA: events: Remove redundant code
ACPICA: events: Fix AcpiEvClearGpeDispatchByOwner handler type processing
ACPICA: events: Fix GPE cleanup return after changing program state
ACPICA: events: Handle GPEs' Notify dispatch type
ACPICA: tables: Fix wrong table unload and notify call order
ACPICA: tables: Fix global table read missing mutex
ACPICA: executer: Fix copying PCC source buffer data
ACPICA: dispatcher: Fix zero size non-NULL PCC buffer pointer
ACPICA: utilities: Clear NextObject so the outer loop doesn't read it
ACPICA: namespace: Fix memory leak around compiler alias flag
ACPICA: acpica: Fix typo in the IOVT_IOMMU table definitions

Mario Limonciello (AMD) (1):
ACPICA: Add ACPI_MSG_DEBUG to set KERN_DEBUG for debug output

Pawel Chmielewski (3):
ACPICA: ACPI 6.5 Add support for the MISC table
ACPICA: iASL: Complete KEYP support
ACPICA: tables: Fix table buffer leak when Load fails verification

Rong Zhang (1):
ACPICA: parser: Set AML length for bytelist

Vidya Sagar (1):
ACPICA: IORT: Add Root Complex PASID Flags field

ikaros (8):
ACPICA: Events: Clear GPE dispatch by owner during table unload
ACPICA: executer: Add bounds checking for PCC field read access
ACPICA: Validate 4-char field names before namespace lookup
ACPICA: Improve error handling in table loading process
ACPICA: executer: Add bounds checking for PCC field write access
ACPICA: tables: Fix heap-buffer-overflow in AcpiTbFindTable
ACPICA: Fix object reference update to skip non-local notify types
ACPICA: namespace: Recognize alias node types in detach

purofle (1):
ACPICA: fix: build error with gcc 16: unused-but-set-variable

[1] https://lore.kernel.org/all/[email protected]/
[2] https://sashiko.dev/#/patchset/20261020141051.2194123-1-pawel.chmielewski%40intel.com
[3] https://sashiko.dev/#/message/20261020141051.2194123-9-pawel.chmielewski%40intel.com
[4] https://sashiko.dev/#/patchset/20261020141051.2194123-1-pawel.chmielewski%40intel.com?part=7

Andre Przywara (1):
ACPICA: actbl2: MPAM: adapt to MPAM ACPI spec v3.1

Colin Ian King (2):
ACPICA: components: Fix typo "Supress" -> "Suppress"
ACPICA: components: Fix typo: "numer" -> "number"

Dave Jiang (2):
ACPICA: CEDT: RDPAS: Add missing reserved field in RDPAS structure
ACPICA: CEDT: RDPAS: Fix incorrect field positions for RDPAS

Hanjun Guo (1):
ACPICA: add UBRT (UnifiedBus Root Table) definitions

Himanshu Chauhan (1):
ACPICA: Introduce a new HEST notification type for RISC-V SSE events

Iurii Trukhin (1):
ACPICA: parser: Fix parse tree memory leak on AML execution error
unwind

Leonard Lausen (1):
ACPICA: Executer: Resolve package index references used as integer
operands

Maciej Strozek (1):
ACPICA: Utilities: Fix for AcpiUtVerifyChecksum warning display

Maciej Wieczor-Retman (17):
ACPICA: executer: Fix NULL pointer dereference in
AcpiExStoreObjectToIndex()
ACPICA: compiler: Add _Ixx GPE object
ACPICA: namespace: Fix possible underflow and NULL pointer dereference
ACPICA: iASL: Fix the truncated count of external control methods
ACPICA: release: Update version to 20260930
ACPICA: events: Add missing event mutex to
AcpiEvClearGpeDispatchByOwner()
ACPICA: events: Remove redundant code
ACPICA: events: Fix AcpiEvClearGpeDispatchByOwner handler type
processing
ACPICA: events: Fix GPE cleanup return after changing program state
ACPICA: events: Handle GPEs' Notify dispatch type
ACPICA: tables: Fix wrong table unload and notify call order
ACPICA: tables: Fix global table read missing mutex
ACPICA: executer: Fix copying PCC source buffer data
ACPICA: dispatcher: Fix zero size non-NULL PCC buffer pointer
ACPICA: utilities: Clear NextObject so the outer loop doesn't read it
ACPICA: namespace: Fix memory leak around compiler alias flag
ACPICA: acpica: Fix typo in the IOVT_IOMMU table definitions

Mario Limonciello (AMD) (1):
ACPICA: Add ACPI_MSG_DEBUG to set KERN_DEBUG for debug output

Pawel Chmielewski (3):
ACPICA: ACPI 6.5 Add support for the MISC table
ACPICA: iASL: Complete KEYP support
ACPICA: tables: Fix table buffer leak when Load fails verification

Rong Zhang (1):
ACPICA: parser: Set AML length for bytelist

Vidya Sagar (1):
ACPICA: IORT: Add Root Complex PASID Flags field

ikaros (8):
ACPICA: Events: Clear GPE dispatch by owner during table unload
ACPICA: executer: Add bounds checking for PCC field read access
ACPICA: Validate 4-char field names before namespace lookup
ACPICA: Improve error handling in table loading process
ACPICA: executer: Add bounds checking for PCC field write access
ACPICA: tables: Fix heap-buffer-overflow in AcpiTbFindTable
ACPICA: Fix object reference update to skip non-local notify types
ACPICA: namespace: Recognize alias node types in detach

purofle (1):
ACPICA: fix: build error with gcc 16: unused-but-set-variable

 drivers/acpi/acpica/acevents.h  |   4 +
 drivers/acpi/acpica/acglobal.h  |   2 +-
 drivers/acpi/acpica/acpredef.h  |   1 +
 drivers/acpi/acpica/acutils.h   |   3 +
 drivers/acpi/acpica/dsfield.c   |  24 +++
 drivers/acpi/acpica/evgpe.c     | 355 ++++++++++++++++++++++++++++++++
 drivers/acpi/acpica/exconfig.c  |   3 +-
 drivers/acpi/acpica/exconvrt.c  |   4 +-
 drivers/acpi/acpica/exfield.c   | 105 +++++++---
 drivers/acpi/acpica/exresop.c   |  26 +++
 drivers/acpi/acpica/exstore.c   |  20 +-
 drivers/acpi/acpica/extrace.c   |   2 +-
 drivers/acpi/acpica/nsaccess.c  |   2 +-
 drivers/acpi/acpica/nsobject.c  |   7 +-
 drivers/acpi/acpica/nsxfname.c  |   8 +
 drivers/acpi/acpica/psargs.c    |   8 +-
 drivers/acpi/acpica/psloop.c    |   5 +-
 drivers/acpi/acpica/psobject.c  |   1 -
 drivers/acpi/acpica/psparse.c   |  16 +-
 drivers/acpi/acpica/tbdata.c    |  32 ++-
 drivers/acpi/acpica/tbfind.c    |  16 +-
 drivers/acpi/acpica/utcksum.c   |   3 +-
 drivers/acpi/acpica/utdebug.c   |   9 +-
 drivers/acpi/acpica/utdelete.c  |   5 +
 drivers/acpi/arm64/mpam.c       |   6 +-
 drivers/acpi/loongarch/iovt.c   |   6 +-
 include/acpi/acpixf.h           |   2 +-
 include/acpi/actbl1.h           |   6 +-
 include/acpi/actbl2.h           | 200 +++++++++++++++++-
 include/acpi/platform/aclinux.h |   1 +
 30 files changed, 811 insertions(+), 71 deletions(-)
Signature · 1 line
2.56.0
author maintainer
#1 lore raw

PATCH v2 1/42 ACPICA: components: Fix typo "Supress" -> "Suppress"

From: Colin Ian King <[email protected]>

There are typos in comments. Fix them.

---
 drivers/acpi/acpica/exconvrt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/acpica/exconvrt.c +2 -2
index b51f20d0978e..ce5bdf519886 100644
@@ -334,7 +334,7 @@ acpi_ex_convert_to_ascii(u64 integer,
 			hex_char = (u8)
 			    acpi_ut_hex_to_ascii_char(integer, ACPI_MUL_4(j));
 
-			/* Supress leading zeros until the first non-zero character */
+			/* Suppress leading zeros until the first non-zero character */
 
 			if (hex_char == ACPI_ASCII_ZERO && supress_zeros) {
 				continue;
@@ -421,7 +421,7 @@ acpi_ex_convert_to_string(union acpi_operand_object * obj_desc,
 			/*
 			 * From to_hex_string.
 			 *
-			 * Supress leading zeros and append "0x"
+			 * Suppress leading zeros and append "0x"
 			 */
 			string_length =
 			    ACPI_MUL_2(acpi_gbl_integer_byte_width) + 2;
Signature · 1 line
2.56.0
author maintainer
#2 lore raw

PATCH v2 2/42 ACPICA: components: Fix typo: "numer" -> "number"

In reply to Maciej Wieczor-Retman

From: Colin Ian King <[email protected]>

There is a typo in a comment. Fix it.

---
 drivers/acpi/acpica/extrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpica/extrace.c +1 -1
index 4a6c7fb147d7..27a8e81e4157 100644
@@ -152,7 +152,7 @@ acpi_ex_trace_point(acpi_trace_event_type type,
  * FUNCTION:    acpi_ex_trace_args
  *
  * PARAMETERS:  params            - AML method arguments
- *              count             - numer of method arguments
+ *              count             - number of method arguments
  *
  * RETURN:      None
  *
Signature · 1 line
2.56.0
author maintainer
#3 lore raw

PATCH v2 3/42 ACPICA: Introduce a new HEST notification type for RISC-V SSE events

In reply to Maciej Wieczor-Retman

From: Himanshu Chauhan <[email protected]>

The GHES entry's notification structure contains the notification to be used for a given error source. For error sources delivering events over SSE, it should contain the new SSE notification type.

---
 include/acpi/actbl1.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/acpi/actbl1.h +2 -1
index d824838cb7af..73ebc089e96d 100644
@@ -1798,7 +1798,8 @@ enum acpi_hest_notify_types {
 	ACPI_HEST_NOTIFY_SEI = 9,	/* ACPI 6.1 */
 	ACPI_HEST_NOTIFY_GSIV = 10,	/* ACPI 6.1 */
 	ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED = 11,	/* ACPI 6.2 */
-	ACPI_HEST_NOTIFY_RESERVED = 12	/* 12 and greater are reserved */
+	ACPI_HEST_NOTIFY_SSE = 12, /* RISC-V SSE */
+	ACPI_HEST_NOTIFY_RESERVED = 13 /* 13 and greater are reserved */
 };
 
 /* Values for config_write_enable bitfield above */
Signature · 1 line
2.56.0
author maintainer
#4 lore raw

PATCH v2 4/42 ACPICA: Utilities: Fix for AcpiUtVerifyChecksum warning display

In reply to Maciej Wieczor-Retman

From: Maciej Strozek <[email protected]>

Remove redundant subtraction which is done already in AcpiUtGenerateChecksum.
Looks like it is a leftover from a refactor [1] where AcpiTbVerifyChecksum used to call AcpiTbChecksum which does not do the substraction (like the Acpi(Dm\Ut)GenerateChecksum does). Found by using iasl to generate checksum for SWFT tables.

[1]:
https://github.com/acpica/acpica/commit/8ac4e5116f59d6f9ba2fbeb9ce22ab58237a278f

---
 drivers/acpi/acpica/utcksum.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/acpi/acpica/utcksum.c +1 -2
index 040e34569ac7..1be8b5da055b 100644
@@ -58,8 +58,7 @@ acpi_status acpi_ut_verify_checksum(struct acpi_table_header *table, u32 length)
 		ACPI_BIOS_WARNING((AE_INFO,
 				   "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
 				   "should be 0x%2.2X",
-				   table->signature, table->checksum,
-				   table->checksum - checksum));
+				   table->signature, table->checksum, checksum));
 
 #if (ACPI_CHECKSUM_ABORT)
 		return (AE_BAD_CHECKSUM);
Signature · 1 line
2.56.0
author maintainer
#5 lore raw

PATCH v2 5/42 ACPICA: CEDT: RDPAS: Add missing reserved field in RDPAS structure

In reply to Maciej Wieczor-Retman

From: Dave Jiang <[email protected]>

Add the missing 3 reserved bytes at the end of the RDPAS structure.

---
 include/acpi/actbl1.h | 1 +
 1 file changed, 1 insertion(+)
include/acpi/actbl1.h +1 -0
index 73ebc089e96d..5b4207af046a 100644
@@ -590,6 +590,7 @@ struct acpi_cedt_rdpas {
 	u16 bdf;
 	u8 protocol;
 	u64 address;
+	u8 reserved[3];
 };
 
 /* Masks for bdf field above */
Signature · 1 line
2.56.0
author maintainer
#6 lore raw

PATCH v2 6/42 ACPICA: CEDT: RDPAS: Fix incorrect field positions for RDPAS

In reply to Maciej Wieczor-Retman

From: Dave Jiang <[email protected]>

The 'Address' and 'Protocol' fields for RDPAS are reversed. Correct them by swapping the positions.

---
 include/acpi/actbl1.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/acpi/actbl1.h +1 -1
index 5b4207af046a..3fa9cd46271f 100644
@@ -588,8 +588,8 @@ struct acpi_cedt_rdpas {
 	struct acpi_cedt_header header;
 	u16 segment;
 	u16 bdf;
-	u8 protocol;
 	u64 address;
+	u8 protocol;
 	u8 reserved[3];
 };
 
Signature · 1 line
2.56.0
author maintainer
#7 lore raw

PATCH v2 7/42 ACPICA: Events: Clear GPE dispatch by owner during table unload

In reply to Maciej Wieczor-Retman

From: ikaros <[email protected]>

When a table is unloaded, its GPE method handlers must be cleared to prevent use-after-free. Add AcpiEvClearGpeDispatchByOwner() which walks all GPE blocks and clears dispatch info for methods owned by the unloading table. If a matching GPE is currently dispatching, AE_ABORT_METHOD is returned and the unload is aborted.

Also add a dispatch-type re-check in AcpiEvAsynchExecuteGpeMethod to handle the case where dispatch was cleared between scheduling and execution.

---
 drivers/acpi/acpica/acevents.h |  4 ++
 drivers/acpi/acpica/evgpe.c    | 97 ++++++++++++++++++++++++++++++++++
 drivers/acpi/acpica/tbdata.c   | 13 +++++
 3 files changed, 114 insertions(+)
drivers/acpi/acpica/acevents.h +4 -0
index ccdc3725c773..4fe26c190c57 100644
@@ -122,6 +122,10 @@ acpi_status acpi_ev_gpe_initialize(void);
 ACPI_HW_DEPENDENT_RETURN_VOID(void
 			      acpi_ev_update_gpes(acpi_owner_id table_owner_id))
 
+ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
+				acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id
+								    owner_id))
+
 acpi_status
 acpi_ev_match_gpe_method(acpi_handle obj_handle,
 			 u32 level, void *context, void **return_value);
drivers/acpi/acpica/evgpe.c +97 -0

109 lines not on this page · raw message

drivers/acpi/acpica/tbdata.c +13 -0
index 07af035aa4de..144f15011eff 100644
@@ -1059,6 +1059,19 @@ acpi_status acpi_tb_unload_table(u32 table_index)
 		acpi_tb_notify_table(ACPI_TABLE_EVENT_UNLOAD, table);
 	}
 
+#if (!ACPI_REDUCED_HARDWARE)
+	/*
+	 * Clear GPE dispatch for methods owned by the table being unloaded.
+	 * If any matching GPE is currently dispatching, AE_ABORT_METHOD is
+	 * returned and the unload cannot proceed.
+	 */
+	status = acpi_ev_clear_gpe_dispatch_by_owner(
+		acpi_gbl_root_table_list.tables[table_index].owner_id);
+	if (ACPI_FAILURE(status)) {
+		return_ACPI_STATUS(status);
+	}
+#endif /* !ACPI_REDUCED_HARDWARE */
+
 	/* Delete the portion of the namespace owned by this table */
 
 	status = acpi_tb_delete_namespace_by_owner(table_index);
Signature · 1 line
2.56.0
author maintainer
#8 lore raw

PATCH v2 8/42 ACPICA: executer: Add bounds checking for PCC field read access

In reply to Maciej Wieczor-Retman

From: ikaros <[email protected]>

Add validation in AcpiExReadDataFromField to ensure that PCC field reads do not exceed the bounds of the InternalPccBuffer. Check for a NULL buffer pointer and verify that BaseByteOffset + field byte length does not exceed Region.Length.

---
 drivers/acpi/acpica/exfield.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/acpi/acpica/exfield.c +22 -2
index 50317fe0cbd5..6e86759162df 100644
@@ -209,12 +209,32 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
 		ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
 				  "PCC FieldRead bits %u\n",
 				  obj_desc->field.bit_length));
+		/*
+		 * Ensure the field access does not exceed the bounds of the
+		 * internal_pcc_buffer. The buffer is allocated with the region length,
+		 * so verify that base_byte_offset + field byte length <= Region.Length.
+		 */
+		if (!obj_desc->field.region_obj->field.internal_pcc_buffer) {
+			status = AE_AML_NO_OPERAND;
+			goto exit;
+		}
 
+		buffer_length = (acpi_size)ACPI_ROUND_BITS_UP_TO_BYTES(
+			obj_desc->field.bit_length);
+		if (obj_desc->field.base_byte_offset + buffer_length >
+		    obj_desc->field.region_obj->region.length) {
+			ACPI_ERROR((
+				AE_INFO,
+				"PCC field at offset %u length %u exceeds region size %u",
+				obj_desc->field.base_byte_offset, buffer_length,
+				obj_desc->field.region_obj->region.length));
+			status = AE_AML_BUFFER_LIMIT;
+			goto exit;
+		}
 		memcpy(buffer,
 		       obj_desc->field.region_obj->field.internal_pcc_buffer +
 		       obj_desc->field.base_byte_offset,
-		       (acpi_size)ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->field.
-							      bit_length));
+		       buffer_length);
 
 		*ret_buffer_desc = buffer_desc;
 		return AE_OK;
Signature · 1 line
2.56.0
author maintainer
#9 lore raw

PATCH v2 9/42 ACPICA: Validate 4-char field names before namespace lookup

In reply to Maciej Wieczor-Retman

From: ikaros <[email protected]>

acpi_ds_get_field_names() and acpi_ds_init_field_objects() pass the 4-byte name of a named field (arg->named.name) to acpi_ns_lookup() without checking it first. acpi_ns_lookup() treats its argument as an AML name string. If malformed AML makes the first byte of the field name AML_DUAL_NAME_PREFIX (0x2E) or AML_MULTI_NAME_PREFIX (0x2F), acpi_ns_lookup() reads more name segments past the 4-byte name. That is past the end of the parse object, which is a heap out-of-bounds read.

Before calling acpi_ns_lookup(), check that the field name is a valid ACPI name segment. Return AE_BAD_CHARACTER if it is not.

---
 drivers/acpi/acpica/dsfield.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/acpi/acpica/dsfield.c +12 -0
index f7e503bf57c8..5d0dfe4ff8e8 100644
@@ -374,6 +374,12 @@ acpi_ds_get_field_names(struct acpi_create_field_info *info,
 
 		case AML_INT_NAMEDFIELD_OP:
 
+			/* Validate the 4-char name to prevent OOB read in acpi_ns_lookup */
+
+			if (!acpi_ut_valid_nameseg((char *)&arg->named.name)) {
+				return_ACPI_STATUS(AE_BAD_CHARACTER);
+			}
+
 			/* Lookup the name, it should already exist */
 
 			status = acpi_ns_lookup(walk_state->scope_info,
@@ -630,6 +636,12 @@ acpi_ds_init_field_objects(union acpi_parse_object *op,
 		 * in the field names in order to enter them into the namespace.
 		 */
 		if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
+			/* Validate the 4-char name to prevent OOB read in acpi_ns_lookup */
+
+			if (!acpi_ut_valid_nameseg((char *)&arg->named.name)) {
+				return_ACPI_STATUS(AE_BAD_CHARACTER);
+			}
+
 			status = acpi_ns_lookup(walk_state->scope_info,
 						(char *)&arg->named.name, type,
 						ACPI_IMODE_LOAD_PASS1, flags,
Signature · 1 line
2.56.0
author maintainer
#10 lore raw

PATCH v2 10/42 ACPICA: Improve error handling in table loading process

In reply to Maciej Wieczor-Retman

From: ikaros <[email protected]>

The AML Load operator can install a table that acpi_tb_load_table() then fails to load. In that case acpi_tb_install_and_load_table() returns an error but leaves the table descriptor in acpi_gbl_root_table_list. acpi_ex_load_op() then frees the table buffer, so the descriptor still points to freed memory. Later users of the table list access the freed table. For example, acpi_tb_terminate() does when it uninstalls all tables.

When loading fails, uninstall the table in acpi_tb_install_and_load_table(). For internally allocated tables this also frees the table buffer, so acpi_ex_load_op() must stop freeing it.

---
 drivers/acpi/acpica/exconfig.c | 9 ++++++---
 drivers/acpi/acpica/tbdata.c   | 6 ++++++
 2 files changed, 12 insertions(+), 3 deletions(-)
drivers/acpi/acpica/exconfig.c +6 -3
index da39d578595b..cb2eed531c67 100644
@@ -461,9 +461,12 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
 	acpi_ex_enter_interpreter();
 	if (ACPI_FAILURE(status)) {
 
-		/* Delete allocated table buffer */
-
-		ACPI_FREE(table);
+		/*
+		 * Table buffer is already freed by acpi_tb_uninstall_table
+		 * in acpi_tb_install_and_load_table if installation succeeded,
+		 * or by acpi_tb_uninstall_table in acpi_tb_install_standard_table
+		 * if verification failed after partial setup.
+		 */
 		return_ACPI_STATUS(status);
 	}
 
drivers/acpi/acpica/tbdata.c +6 -0
index 144f15011eff..8185c6f7ce23 100644
@@ -1019,6 +1019,12 @@ acpi_tb_install_and_load_table(acpi_physical_address address,
 	}
 
 	status = acpi_tb_load_table(i, acpi_gbl_root_node);
+	if (ACPI_FAILURE(status)) {
+		/* Table was installed but not loaded, uninstall to clean up */
+
+		acpi_tb_uninstall_table(&acpi_gbl_root_table_list.tables[i]);
+		goto exit;
+	}
 
 exit:
 	*table_index = i;
Signature · 1 line
2.56.0
author maintainer
#11 lore raw

PATCH v2 11/42 ACPICA: executer: Add bounds checking for PCC field write access

In reply to Maciej Wieczor-Retman

From: ikaros <[email protected]>

Add validation in AcpiExWriteDataToField to ensure that PCC field writes do not exceed the bounds of the InternalPccBuffer. Check for a NULL buffer pointer and verify that BaseByteOffset + field byte length does not exceed Region.Length.

---
 drivers/acpi/acpica/exfield.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/acpi/acpica/exfield.c +18 -0
index 6e86759162df..632fc8693f23 100644
@@ -347,10 +347,28 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
 		 * implementation will use the offsets specified rather than the name
 		 * of the field. This is considered safer because some firmware tools
 		 * are known to obfiscate named objects.
+		 *
+		 * Ensure the field access does not exceed the bounds of the
+		 * internal_pcc_buffer.
 		 */
 		data_length =
 		    (acpi_size)ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->field.
 							   bit_length);
+
+		if (!obj_desc->field.region_obj->field.internal_pcc_buffer) {
+			return_ACPI_STATUS(AE_AML_NO_OPERAND);
+		}
+
+		if (obj_desc->field.base_byte_offset + data_length >
+		    obj_desc->field.region_obj->region.length) {
+			ACPI_ERROR((
+				AE_INFO,
+				"PCC field at offset %u length %u exceeds region size %u",
+				obj_desc->field.base_byte_offset, data_length,
+				obj_desc->field.region_obj->region.length));
+			return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
+		}
+
 		memcpy(obj_desc->field.region_obj->field.internal_pcc_buffer +
 		       obj_desc->field.base_byte_offset,
 		       source_desc->buffer.pointer, data_length);
Signature · 1 line
2.56.0
author maintainer
#12 lore raw

PATCH v2 12/42 ACPICA: tables: Fix heap-buffer-overflow in AcpiTbFindTable

In reply to Maciej Wieczor-Retman

From: ikaros <[email protected]>

The OEM ID and OEM Table ID string operands passed to AcpiTbFindTable can be shorter than ACPI_OEM_ID_SIZE (6) and ACPI_OEM_TABLE_ID_SIZE (8). The unconditional memcpy reads past the string allocation when the input is too short. Validate string length before memcpy and copy only what is available, relying on the prior memset to zero-pad the remainder.

---
 drivers/acpi/acpica/tbfind.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/acpi/acpica/tbfind.c +14 -2
index 60a772c87f42..f36a9b34058f 100644
@@ -57,8 +57,20 @@ acpi_tb_find_table(char *signature,
 
 	memset(&header, 0, sizeof(struct acpi_table_header));
 	ACPI_COPY_NAMESEG(header.signature, signature);
-	memcpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
-	memcpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
+	if (strlen(oem_id) >= ACPI_OEM_ID_SIZE) {
+		memcpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
+	} else {
+		memcpy(header.oem_id, oem_id, strlen(oem_id));
+		/* Remainder is already zeroed by memset above */
+	}
+
+	if (strlen(oem_table_id) >= ACPI_OEM_TABLE_ID_SIZE) {
+		memcpy(header.oem_table_id, oem_table_id,
+		       ACPI_OEM_TABLE_ID_SIZE);
+	} else {
+		memcpy(header.oem_table_id, oem_table_id, strlen(oem_table_id));
+		/* Remainder is already zeroed by memset above */
+	}
 
 	/* Search for the table */
 
Signature · 1 line
2.56.0
author maintainer
#13 lore raw

PATCH v2 13/42 ACPICA: Fix object reference update to skip non-local notify types

In reply to Maciej Wieczor-Retman

From: ikaros <[email protected]>

---
 drivers/acpi/acpica/utdelete.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/acpi/acpica/utdelete.c +4 -0
index e8180099d01f..57a0de6a49d6 100644
@@ -517,6 +517,10 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
 				prev_object =
 				    object->common_notify.notify_list[i];
 				while (prev_object) {
+					if (prev_object->common.type !=
+					    ACPI_TYPE_LOCAL_NOTIFY) {
+						break;
+					}
 					next_object =
 					    prev_object->notify.next[i];
 					acpi_ut_update_ref_count(prev_object,
Signature · 1 line
2.56.0
author maintainer
#14 lore raw

PATCH v2 14/42 ACPICA: namespace: Recognize alias node types in detach

In reply to Maciej Wieczor-Retman

From: ikaros <[email protected]>

---
 drivers/acpi/acpica/nsobject.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/acpica/nsobject.c +3 -1
index a4ccacecca53..49d9d917fa73 100644
@@ -174,7 +174,9 @@ void acpi_ns_detach_object(struct acpi_namespace_node *node)
 	obj_desc = node->object;
 
 	/* Alias nodes point directly to other namespace nodes; skip teardown */
-	if (node->flags & ANOBJ_IS_ALIAS) {
+	if ((node->type == ACPI_TYPE_LOCAL_ALIAS) ||
+	    (node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS) ||
+	    (node->flags & ANOBJ_IS_ALIAS)) {
 		node->object = NULL;
 		return_VOID;
 	}
Signature · 1 line
2.56.0
author maintainer
#15 lore raw

PATCH v2 15/42 ACPICA: fix: build error with gcc 16: unused-but-set-variable

In reply to Maciej Wieczor-Retman

From: purofle <[email protected]>

Since GCC 16, -Wunused-but-set-* warning options have been extended to have multiple levels controlling what kinds of uses disable the warnings for variables which are otherwise unused. Older versions of GCC only implemented what has become -Wunused-but-set-variable=1 or -Wunused-but-set-parameter=1, while the new default for -Wunused-but-set-variable or -Wunused-but-set-parameter is =3 (the new defaults are also used when these warnings are enabled by -Wall or -Wextra, respectively). =2 ignores pre/post inc/decrements on the variable, =3 also ignores compound assignments if the LHS variable is not also used on the RHS.

Use ACPI_UNUSED_VAR on the NumCarats variable. This variable causes the unused warning because its use is only compiled if ACPI_DEBUG_OUTPUT is defined.

---
 drivers/acpi/acpica/nsaccess.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpica/nsaccess.c +1 -1
index a0c1a665dfc1..1e7945ccff84 100644
@@ -292,7 +292,7 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
 	struct acpi_namespace_node *current_node = NULL;
 	struct acpi_namespace_node *this_node = NULL;
 	u32 num_segments;
-	u32 num_carats;
+	u32 ACPI_UNUSED_VAR num_carats;
 	acpi_name simple_name;
 	acpi_object_type type_to_check_for;
 	acpi_object_type this_search_type;
Signature · 1 line
2.56.0
author maintainer
#16 lore raw

PATCH v2 16/42 ACPICA: parser: Set AML length for bytelist

In reply to Maciej Wieczor-Retman

From: Rong Zhang <[email protected]>

The sanity check introduced in [1] leads to failures for resource templates. AcpiDmIsResourceTemplate compares the Length variable to BufferLength - the problem being that Length was never set. This causes the decompiler to decompile valid resource templates as plain buffers.

Fix it by setting the AML length properly.

[1] https://github.com/open-acpica/acpica/commit/3ce09021b677

---
 drivers/acpi/acpica/psargs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/acpi/acpica/psargs.c +5 -3
index 4643c839df7f..b0f5a11f9696 100644
@@ -760,6 +760,8 @@ static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
 
 				ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
 				arg->named.value.size = buffer_length;
+				arg->named.length = (u32)ACPI_PTR_DIFF(
+					pkg_end, parser_state->aml);
 				arg->named.data = parser_state->aml;
 			}
 
@@ -933,9 +935,9 @@ acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
 
 			/* Fill in bytelist data */
 
-			arg->common.value.size = (u32)
-			    ACPI_PTR_DIFF(parser_state->pkg_end,
-					  parser_state->aml);
+			arg->common.value.size = arg->named.length =
+				(u32)ACPI_PTR_DIFF(parser_state->pkg_end,
+						   parser_state->aml);
 			arg->named.data = parser_state->aml;
 
 			/* Skip to End of byte data */
Signature · 1 line
2.56.0
author maintainer
#17 lore raw

PATCH v2 17/42 ACPICA: executer: Fix NULL pointer dereference in AcpiExStoreObjectToIndex()

In reply to Maciej Wieczor-Retman

Fix a possible NULL pointer dereference when trying to store an empty buffer into an indexed string or buffer. Source-buffers are only allocated if the Length is non-zero.

Similarly to AcpiExConvertToInteger() reject empty buffers with an error.

---
 drivers/acpi/acpica/exstore.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/acpi/acpica/exstore.c +18 -2
index 86be6bce1648..cd60fc366b08 100644
@@ -295,13 +295,29 @@ acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
 			break;
 
 		case ACPI_TYPE_BUFFER:
-		case ACPI_TYPE_STRING:
 
-			/* Note: Takes advantage of common string/buffer fields */
+			/*
+			 * A zero-length buffer has no first element and a NULL
+			 * Pointer (see acpi_ut_create_buffer_object). Reject it, as is
+			 * done for the buffer-to-integer conversion.
+			 */
+			if (!source_desc->buffer.length) {
+				ACPI_BIOS_EXCEPTION((
+					AE_INFO, AE_AML_BUFFER_LIMIT,
+					"Source is a zero-length buffer, no data to store"));
+				return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
+			}
 
 			value = source_desc->buffer.pointer[0];
 			break;
 
+		case ACPI_TYPE_STRING:
+
+			/* A String always has a pointer; a null string stores a zero */
+
+			value = (u8)source_desc->string.pointer[0];
+			break;
+
 		default:
 
 			/* All other types are invalid */
Signature · 1 line
2.56.0
author maintainer
#18 lore raw

PATCH v2 18/42 ACPICA: compiler: Add _Ixx GPE object

In reply to Maciej Wieczor-Retman

ACPI 6.6 specification, chapter 5.6.4.3 mentions an _Ixx object (where xx is a two-digit hexadecimal number) which presence indicates that the corresponding GPE is enabled in the low power S0 idle state.

Add a new reserved name type to symbolize an object. Since the specification mentions that just the presence of the object is required, any one of Name(), Method(), Device(), etc. with the _Ixx name should be a valid indication.

Update comments and the disassembler path.

---
 drivers/acpi/acpica/acpredef.h | 1 +
 1 file changed, 1 insertion(+)
drivers/acpi/acpica/acpredef.h +1 -0
index 2208dc7aff8d..be44194b0426 100644
@@ -152,6 +152,7 @@ enum acpi_return_package_types {
  *              _Qxx EC methods
  *              _T_x compiler temporary variables
  *              _Wxx wake events
+ *              _Ixx indicator for GPEs in low power S0 idle state
  *
  *      2) Predefined names that never actually exist within the AML code:
  *              Predefined resource descriptor field names
Signature · 1 line
2.56.0
author maintainer
#19 lore raw

PATCH v2 19/42 ACPICA: namespace: Fix possible underflow and NULL pointer dereference

In reply to Maciej Wieczor-Retman

AcpiPsGetNextNamestring modifies ParserState.Aml. Since it can take on the AmlEnd value, further instruction that do Aml++ can cause underflows on pointer arithmetic that's done to calculate AmlLength. Also the return value can be NULL which is not checked currently.

Verify that return value is not NULL and check if ParserState.Aml can be incremented safely.

---
 drivers/acpi/acpica/nsxfname.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/acpi/acpica/nsxfname.c +8 -0
index fcd94947fedb..c0466139fd96 100644
@@ -519,6 +519,14 @@ acpi_status acpi_install_method(u8 *buffer)
 	}
 	path = acpi_ps_get_next_namestring(&parser_state);
 
+	/*
+	 * Path can be NULL, and Aml can be pkg_end which combined with the Aml++
+	 * a few lines below will cause aml_length to underflow.
+	 */
+	if (!path || (parser_state.aml >= parser_state.pkg_end)) {
+		return (AE_AML_PACKAGE_LIMIT);
+	}
+
 	method_flags = *parser_state.aml++;
 	aml_start = parser_state.aml;
 	aml_length = (u32)ACPI_PTR_DIFF(parser_state.pkg_end, aml_start);
Signature · 1 line
2.56.0
author maintainer
#20 lore raw

PATCH v2 20/42 ACPICA: add UBRT (UnifiedBus Root Table) definitions

In reply to Maciej Wieczor-Retman

From: Hanjun Guo <[email protected]>

Add UBRT table structure definitions as specified in "UnifiedBus Root Table (UBRT) Specification Revision 1.0" [1].

UBRT table signature was reserved and published in links to ACPI-related
documents: https://uefi.org/acpi.

The UBRT provides the OS with fundamental configuration and architectural information necessary to initialize and manage the UB device.

This includes:
- UBRT main table structure (ACPI_TABLE_UBRT)
- UBC (UnifiedBus Bus Controller) information sub-table
- UMMU (UnifiedBus Memory Management Unit) information sub-table
- UB Reserved Memory information sub-table

[1]: https://www.unifiedbus.com/en/docs/UB-Root-Table-Spec-1.0-en

---
 include/acpi/actbl2.h | 153 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 153 insertions(+)
include/acpi/actbl2.h +153 -0
index 76e4a5bc79b4..dbfea7c8bc00 100644
@@ -61,6 +61,7 @@
 #define ACPI_SIG_SVKL           "SVKL"	/* Storage Volume Key Location Table */
 #define ACPI_SIG_SWFT           "SWFT"	/* SoundWire File Table */
 #define ACPI_SIG_TDEL           "TDEL"	/* TD Event Log Table */
+#define ACPI_SIG_UBRT           "UBRT"	/* UnifiedBus Root Table */
 
 /*
  * All tables must be byte-packed to match the ACPI specification, since
@@ -3708,6 +3709,158 @@ struct acpi_table_tdel {
 	u64 log_area_start_address;
 };
 
+/*******************************************************************************
+ *
+ * UBRT - UnifiedBus Root Table
+ *        Revision 1
+ *
+ * Conforms to "UnifiedBus Root Table (UBRT) Specification"
+ * Revision 1.0, Release Date 2026-03-05
+ *
+ ******************************************************************************/
+
+struct acpi_table_ubrt {
+	struct acpi_table_header header; /* Common ACPI table header */
+	u32 count; /* Number of sub-tables */
+};
+
+/* UBRT sub-table entry (16 bytes) */
+
+struct acpi_ubrt_subtable {
+	u8 type; /* Sub-table type (0=UBC, 1=UMMU, 2=reserved_mem) */
+	u8 reserved[7]; /* Reserved, must be zero */
+	u64 pointer; /* Physical address of the sub-table */
+};
+
+/* Values for Type field above */
+
+#define ACPI_UBRT_TYPE_UBC 0 /* UBC information sub-table */
+#define ACPI_UBRT_TYPE_UMMU 1 /* UMMU information sub-table */
+#define ACPI_UBRT_TYPE_RESERVED_MEM \
+	2 /* UB reserved memory information sub-table */
+
+/*
+ * UBRT Sub-tables, correspond to Type in struct acpi_ubrt_subtable.
+ * These are accessed via the physical Pointer field - not contiguous with UBRT.
+ */
+
+/* Common header for all UBRT sub-tables */
+
+struct acpi_ubrt_header {
+	char name[16]; /* Table name, null-terminated */
+	u32 total_size; /* Total size including header */
+	u8 version; /* Version number */
+	u8 reserved[3]; /* Reserved, must be zero */
+	u32 remaining_size; /* Remaining size of the sub-table */
+	u32 checksum; /* Entire table must sum to zero */
+};
+
+/* Type 0: UBC Information Table */
+
+struct acpi_ubrt_ubc {
+	struct acpi_ubrt_header header; /* Common sub-table header */
+	u32 local_cna_start; /* Start CNA available for local UBPU */
+	u32 local_cna_end; /* End CNA available for local UBPU (included) */
+	u32 local_eid_start; /* Start EID available for local UBPU */
+	u32 local_eid_end; /* End EID available for local UBPU (included) */
+	u8 feature_sets; /* Features enabled for the UBC */
+	u8 reserved[3]; /* Reserved, must be zero */
+	u16 cluster_mode; /* System operating mode */
+	u16 ubc_count; /* Number of UBC structures */
+};
+
+/* Values for feature_sets field above */
+
+#define ACPI_UBRT_UBC_FEAT_MMIO_TOKEN (1 << 0) /* Bit 0: MMIO token value */
+#define ACPI_UBRT_UBC_FEAT_MCTP_UB (1 << 1) /* Bit 1: MCTP over UB */
+
+/* Values for cluster_mode field above */
+
+#define ACPI_UBRT_CLUSTER_MODE_STANDALONE 0
+#define ACPI_UBRT_CLUSTER_MODE_SUPERPOD 1
+
+/* UBC Structure entry (one per ubc_count) */
+
+struct acpi_ubrt_ubc_entry {
+	u32 interrupt_id_start; /* Start interrupt ID */
+	u32 interrupt_id_end; /* End interrupt ID (included) */
+	u64 hpa_base; /* Base address of available HPA */
+	u64 hpa_size; /* Size of available HPA */
+	u8 memory_size_limit; /* Maximum address bit width */
+	u8 dma_cca; /* DMA and cache coherent attribute */
+	u16 ummu_mapping; /* Mapping between UBC and UMMU */
+	u16 proximity_domain; /* NUMA domain sequence number */
+	u16 reserved; /* Reserved, must be zero */
+	u64 msg_queue_base; /* MSG queue register base address */
+	u64 msg_queue_size; /* MSG queue register size */
+	u16 msg_queue_depth; /* MSG queue depth */
+	u16 msg_queue_interrupt; /* MSG queue interrupt ID */
+	u8 msg_queue_interrupt_attr; /* MSG queue interrupt attribute */
+	u8 reserved1[59]; /* Reserved, must be zero */
+	u8 guid[16]; /* UBC GUID */
+	u8 vendor_info[256]; /* Vendor-defined information */
+};
+
+/* Values for dma_cca field above */
+
+#define ACPI_UBRT_UBC_DMA_ONLY 0
+#define ACPI_UBRT_UBC_DMA_CCA 1
+
+/* Values for msg_queue_interrupt_attr field above */
+
+#define ACPI_UBRT_UBC_MSG_INT_LEVEL (0 << 0) /* Bit 0: level-triggered */
+#define ACPI_UBRT_UBC_MSG_INT_EDGE (1 << 0) /* Bit 0: edge-triggered */
+#define ACPI_UBRT_UBC_MSG_INT_HIGH \
+	(0 << 1) /* Bit 1: high level (rising edge) */
+#define ACPI_UBRT_UBC_MSG_INT_LOW (1 << 1) /* Bit 1: low level (falling edge) */
+
+/* Type 1: UMMU Information Table */
+
+struct acpi_ubrt_ummu {
+	struct acpi_ubrt_header header; /* Common sub-table header */
+	u16 ummu_count; /* Number of UMMU structures */
+	u8 reserved[6]; /* Reserved, must be zero */
+};
+
+/* UMMU Structure entry (one per ummu_count) */
+
+struct acpi_ubrt_ummu_entry {
+	u64 base_address; /* Base address of UMMU register */
+	u64 size; /* Size of UMMU register */
+	u32 reserved; /* Reserved, must be zero */
+	u16 proximity_domain; /* NUMA domain sequence number */
+	u16 reserved1; /* Reserved, must be zero */
+	u64 pmu_base_address; /* PMU register base address */
+	u64 pmu_size; /* PMU register size */
+	u32 reserved2; /* Reserved, must be zero */
+	u32 min_token_id; /* Minimum token_ID */
+	u32 max_token_id; /* Maximum token_ID */
+	u8 reserved3[26]; /* Reserved, must be zero */
+	u16 vendor_id; /* Vendor ID */
+	u8 vendor_info[80]; /* Vendor-defined information */
+};
+
+/* Type 2: UB Reserved Memory Information Table */
+
+struct acpi_ubrt_reserved_mem {
+	struct acpi_ubrt_header header; /* Common sub-table header */
+	u16 memory_ranges_count; /* Number of memory ranges */
+	u8 reserved[6]; /* Reserved, must be zero */
+};
+
+/* Memory Range entry (one per memory_ranges_count) */
+
+struct acpi_ubrt_mem_range {
+	u8 flags; /* Memory segment flags */
+	u8 reserved[7]; /* Reserved, must be zero */
+	u64 memory_base; /* Base address of allocated UB memory (64KB aligned) */
+	u64 memory_size; /* Size of allocated UB memory (64KB aligned) */
+};
+
+/* Values for Flags field above */
+
+#define ACPI_UBRT_MEM_FLAG_1_1_MAPPING (1 << 0) /* Bit 0: 1:1 mapped mode */
+
 /* Reset to default packing */
 
 #pragma pack()
Signature · 1 line
2.56.0
author maintainer
#21 lore raw

PATCH v2 21/42 ACPICA: Add ACPI_MSG_DEBUG to set KERN_DEBUG for debug output

In reply to Maciej Wieczor-Retman

From: Mario Limonciello (AMD) <[email protected]>

acpi_debug_print() emits ACPI debug output using multi-part acpi_os_printf() and acpi_os_vprintf() calls without any loglevel prefix.

When acpi_os_vprintf() processes a chunk without a loglevel prefix (printk_get_level() returns 0), it prepends KERN_CONT. Because the initial header chunk lacks a loglevel prefix, it either attaches to a preceding unfinalized log message (inheriting its level) or, when split across printk buffer records, falls back to the default message loglevel rather than KERN_DEBUG. This can cause dmesg to misinterpret and colorize debug messages as errors.

Define ACPI_MSG_DEBUG as KERN_DEBUG in aclinux.h (with an empty fallback in acutils.h for ACPICA OS-independence) and prefix debug message headers and context switch output in acpi_debug_print() with ACPI_MSG_DEBUG so that printk records are properly tagged with KERN_DEBUG.

---
 drivers/acpi/acpica/acutils.h   | 3 +++
 drivers/acpi/acpica/utdebug.c   | 9 +++++----
 include/acpi/platform/aclinux.h | 1 +
 3 files changed, 9 insertions(+), 4 deletions(-)
drivers/acpi/acpica/acutils.h +3 -0
index 9049bfee409c..6b06f126c653 100644
@@ -100,6 +100,9 @@ extern const char *acpi_gbl_clock_input_scale[];
 #ifndef ACPI_MSG_BIOS_WARNING
 #define ACPI_MSG_BIOS_WARNING   "Firmware Warning (ACPI): "
 #endif
+#ifndef ACPI_MSG_DEBUG
+#define ACPI_MSG_DEBUG ""
+#endif
 
 /*
  * Common message suffix
drivers/acpi/acpica/utdebug.c +5 -4
index a31e07400c34..d031c5ab63bc 100644
@@ -155,9 +155,10 @@ acpi_debug_print(u32 requested_debug_level,
 	thread_id = acpi_os_get_thread_id();
 	if (thread_id != acpi_gbl_previous_thread_id) {
 		if (ACPI_LV_THREADS & acpi_dbg_level) {
-			acpi_os_printf
-			    ("\n**** Context Switch from TID %u to TID %u ****\n\n",
-			     (u32)acpi_gbl_previous_thread_id, (u32)thread_id);
+			acpi_os_printf(ACPI_MSG_DEBUG
+				       "\n**** Context Switch from TID %u to TID %u ****\n\n",
+				       (u32)acpi_gbl_previous_thread_id,
+				       (u32)thread_id);
 		}
 
 		acpi_gbl_previous_thread_id = thread_id;
@@ -168,7 +169,7 @@ acpi_debug_print(u32 requested_debug_level,
 	 * Display the module name, current line number, thread ID (if requested),
 	 * current procedure nesting level, and the current procedure name
 	 */
-	acpi_os_printf("%9s-%04d ", module_name, line_number);
+	acpi_os_printf(ACPI_MSG_DEBUG "%9s-%04d ", module_name, line_number);
 
 #ifdef ACPI_APPLICATION
 	/*
include/acpi/platform/aclinux.h +1 -0
index 9b30bb9ed711..5e2ed5e79d3b 100644
@@ -169,6 +169,7 @@
 
 #define ACPI_MSG_BIOS_ERROR     KERN_ERR "ACPI BIOS Error (bug): "
 #define ACPI_MSG_BIOS_WARNING   KERN_WARNING "ACPI BIOS Warning (bug): "
+#define ACPI_MSG_DEBUG          KERN_DEBUG
 
 /*
  * Linux wants to use designated initializers for function pointer structs.
Signature · 1 line
2.56.0
author maintainer
#22 lore raw

PATCH v2 22/42 ACPICA: ACPI 6.5 Add support for the MISC table

In reply to Maciej Wieczor-Retman

From: Pawel Chmielewski <[email protected]>

ACPI 6.5 Introduces MISC table and the definition for Miscellaneous GUIDed Table Entries. This commit adds support for this table, specifically in compiler, disassembler and template generator.
Refer to section 5.2.33. "Miscellaneous GUIDed Table Entries" of ACPI 6.5 specification for further information.

---
 include/acpi/actbl2.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
include/acpi/actbl2.h +30 -0
index dbfea7c8bc00..3f6e093133c7 100644
@@ -38,6 +38,7 @@
 #define ACPI_SIG_MADT           "APIC"	/* Multiple APIC Description Table */
 #define ACPI_SIG_MCFG           "MCFG"	/* PCI Memory Mapped Configuration table */
 #define ACPI_SIG_MCHI           "MCHI"	/* Management Controller Host Interface table */
+#define ACPI_SIG_MISC           "MISC"	/* Miscellaneous GUIDed Table */
 #define ACPI_SIG_MPAM           "MPAM"	/* Memory System Resource Partitioning and Monitoring Table */
 #define ACPI_SIG_MPST           "MPST"	/* Memory Power State Table */
 #define ACPI_SIG_MRRM           "MRRM"	/* Memory Range and Region Mapping table */
@@ -1876,6 +1877,35 @@ struct acpi_table_mchi {
 	u8 pci_function;
 };
 
+/*******************************************************************************
+ *
+ * MISC - Miscellaneous GUIDed Table
+ *
+ * Conforms to section "Miscellaneous GUIDed Table Entries" of ACPI
+ * Specification v6.5
+ *
+ ******************************************************************************/
+
+struct acpi_misc_guid_entry {
+	u8 entry_guid[16];
+	u32 entry_length;
+	u32 revision;
+	char producer_id[ACPI_NAMESEG_SIZE] ACPI_NONSTRING; /* ACPI Vendor ID */
+	u8 data[];
+};
+
+/* Minimum length of a MISC entry (the header fields, without any Data) */
+
+#define ACPI_MISC_MIN_ENTRY_LENGTH 28
+
+struct acpi_table_misc {
+	struct acpi_table_header header; /* Common ACPI table header */
+	/*
+	 * Immediately followed by one or more variable-length entries:
+	 * struct acpi_misc_guid_entry Entries[];
+	 */
+};
+
 /*******************************************************************************
  *
  * MPAM - Memory System Resource Partitioning and Monitoring
Signature · 1 line
2.56.0
author maintainer
#23 lore raw

PATCH v2 23/42 ACPICA: iASL: Complete KEYP support

In reply to Maciej Wieczor-Retman

From: Pawel Chmielewski <[email protected]>

Add the iASL disassembler, table compiler, and template support for the KEYP (Key Programming Interface for Root Complex Integrity and Data Encryption) table.

Add the KEYP entry to the supported-tables list and introduce an ACPI_DMT_KEYP opcode so the subtable Type field decodes to a name.

---
 include/acpi/actbl2.h | 5 +++++
 1 file changed, 5 insertions(+)
include/acpi/actbl2.h +5 -0
index 3f6e093133c7..9af7c51d1297 100644
@@ -1177,6 +1177,7 @@ struct acpi_keyp_common_header {
 
 enum acpi_keyp_type {
 	ACPI_KEYP_TYPE_CONFIG_UNIT = 0,
+	ACPI_KEYP_TYPE_RESERVED = 1,
 };
 
 /* Root Port Information Structure */
@@ -1206,6 +1207,10 @@ enum acpi_keyp_protocol_type {
 	ACPI_KEYP_PROTO_TYPE_RESERVED
 };
 
+/* Only version 1 of the KCU Structure is currently defined in the spec */
+
+#define ACPI_KEYP_CONFIG_UNIT_VERSION 1
+
 #define ACPI_KEYP_F_TVM_USABLE      (1)
 
 /*******************************************************************************
Signature · 1 line
2.56.0
author maintainer
#24 lore raw

PATCH v2 24/42 ACPICA: iASL: Fix the truncated count of external control methods

In reply to Maciej Wieczor-Retman

AcpiGbl_NumExternalMethods counts the external control methods that the disassembler finds in a table. Its type is BOOLEAN, which is an unsigned char, so the counter wraps at 256. A table with more than 255 external control methods gets a wrong count.

The wrong count makes the disassembler print a bogus warning. AcpiGbl_ResolvedExternalMethods is a UINT32 and keeps the correct value. The two counts then differ, even when the disassembler resolves every method. AcpiDmUnresolvedWarning() subtracts the counts to get the number of unresolved methods. That unsigned subtraction wraps and gives a very large number. A table with 300 externals, all of them resolved, reports "There were 44 external control methods found during disassembly, but only 300 were resolved (4294967040 unresolved)".

A count that is an exact multiple of 256 truncates to zero. In that case AcpiDmUnresolvedWarning() returns early and prints no warning at all, even when methods stay unresolved.

Change the type of AcpiGbl_NumExternalMethods to UINT32, which is the type of AcpiGbl_ResolvedExternalMethods.

---
 drivers/acpi/acpica/acglobal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpica/acglobal.h +1 -1
index b6e31517650e..9a2798896d48 100644
@@ -287,7 +287,7 @@ ACPI_INIT_GLOBAL(ACPI_PARSE_OBJECT_LIST, *acpi_gbl_temp_list_head, NULL);
 
 ACPI_GLOBAL(u8, acpi_gbl_dm_opt_disasm);
 ACPI_GLOBAL(u8, acpi_gbl_dm_opt_listing);
-ACPI_GLOBAL(u8, acpi_gbl_num_external_methods);
+ACPI_GLOBAL(u32, acpi_gbl_num_external_methods);
 ACPI_GLOBAL(u32, acpi_gbl_resolved_external_methods);
 ACPI_GLOBAL(struct acpi_external_list *, acpi_gbl_external_list);
 ACPI_GLOBAL(struct acpi_external_file *, acpi_gbl_external_file_list);
Signature · 1 line
2.56.0
author maintainer
#25 lore raw

PATCH v2 25/42 ACPICA: release: Update version to 20260930

In reply to Maciej Wieczor-Retman

Write most relevant changes that happened since the last release. Move the release notes to a markdown file for nice formatting compared to the currently used txt file. Finally update the release number.

---
 include/acpi/acpixf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/acpi/acpixf.h +1 -1
index 9557462e0be8..051ea76b7f5d 100644
@@ -12,7 +12,7 @@
 
 /* Current ACPICA subsystem version in YYYYMMDD format */
 
-#define ACPI_CA_VERSION                 0x20260408
+#define ACPI_CA_VERSION                 0x20260930
 
 #include <acpi/acconfig.h>
 #include <acpi/actypes.h>
Signature · 1 line
2.56.0
author maintainer
#26 lore raw

PATCH v2 26/42 ACPICA: actbl2: MPAM: adapt to MPAM ACPI spec v3.1

In reply to Maciej Wieczor-Retman

From: Andre Przywara <[email protected]>

The latest edition of the "ACPI for MPAM Platform Design Document" (ARM DEN0065C [1]) re-purposes the current Reserved2 field in the MPAM ACPI table to hold an offset value for the MPAM Firmware backed interface. Also the MSC structure gets abstracted a bit, which renames the Reserved field to type, although it stays at 0, for the time being.

Rename and describe the new fields in the table struct definition.

[1] https://support.arm.com/documentation/den0065/latest

---
 drivers/acpi/arm64/mpam.c | 6 +++---
 include/acpi/actbl2.h     | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/acpi/arm64/mpam.c +3 -3
index c57bd367922b..671ba501379a 100644
@@ -331,14 +331,14 @@ static int __init acpi_mpam_parse(void)
 		table_offset += tbl_msc->length;
 
 		/*
-		 * If any of the reserved fields are set, make no attempt to
-		 * parse the MSC structure. This MSC will still be counted by
+		 * If the reserved1 field is set, make no attempt to parse the
+		 * MSC structure. This MSC will still be counted by
 		 * acpi_mpam_count_msc(), meaning the MPAM driver can't probe
 		 * against all MSC, and will never be enabled. There is no way
 		 * to enable it safely, because we cannot determine safe
 		 * system-wide partid and pmg ranges in this situation.
 		 */
-		if (tbl_msc->reserved || tbl_msc->reserved1 || tbl_msc->reserved2) {
+		if (tbl_msc->reserved1) {
 			pr_err_once("Unrecognised MSC, MPAM not usable\n");
 			pr_debug("MSC.%u: reserved field set\n", tbl_msc->identifier);
 			continue;
include/acpi/actbl2.h +2 -2
index 9af7c51d1297..8e0d5156e6d6 100644
@@ -2004,7 +2004,7 @@ struct acpi_mpam_resource_node {
 struct acpi_mpam_msc_node {
 	u16 length;
 	u8 interface_type;
-	u8 reserved;
+	u8 type;
 	u32 identifier;
 	u64 base_address;
 	u32 mmio_size;
@@ -2014,7 +2014,7 @@ struct acpi_mpam_msc_node {
 	u32 overflow_interrupt_affinity;
 	u32 error_interrupt;
 	u32 error_interrupt_flags;
-	u32 reserved2;
+	u32 mpam_fb_offset;
 	u32 error_interrupt_affinity;
 	u32 max_nrdy_usec;
 	u64 hardware_id_linked_device;
Signature · 1 line
2.56.0
author maintainer
#27 lore raw

PATCH v2 27/42 ACPICA: Executer: Resolve package index references used as integer operands

In reply to Maciej Wieczor-Retman

From: Leonard Lausen <[email protected]>

Resolving a Local or Arg retrieves its stored object but does not resolve an Index reference stored there to the referenced package element. When that reference is used as an integer operand, implicit conversion rejects it with AE_AML_OPERAND_TYPE.

This prevents FAN0._FST on the Samsung Galaxy Book 930XDB from returning status whenever the fan is running. The method stores an Index reference into its fan-speed table in Local1 and then uses Add (Local1, 10, Local1).

Resolve a remaining package Index reference before integer conversion. Release the replaced reference inside AcpiExResolveObjectToValue() - it seems to be missing there with even a comment mentioning the non-existant reference removal. Limit this to integer operands so Store, CopyObject and method calls continue to preserve references. Leave Increment and Decrement's synthetic operand resolution unchanged; their reference-target handling requires a separate fix.

Add a standalone ASL regression covering local and argument inputs, integer conversion, reference preservation, target replacement and invalid operands. The extracted fan method also returns the expected status for all defined fan states with this change.

---
 drivers/acpi/acpica/exresop.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/acpi/acpica/exresop.c +26 -0
index 8127d4046d0b..87d04b74e13e 100644
@@ -375,6 +375,32 @@ acpi_ex_resolve_operands(u16 opcode,
 			 */
 		case ARGI_INTEGER:
 
+			/*
+			 * Resolving an Arg or Local can leave an Index reference to a
+			 * package element. Resolve that element before integer conversion,
+			 * without changing reference-preserving operands such as Store.
+			 * Leave the synthetic operand resolution used by Increment and
+			 * Decrement unchanged; those operators also need reference-target
+			 * handling when writing their result.
+			 */
+			if ((walk_state->opcode != AML_INCREMENT_OP) &&
+			    (walk_state->opcode != AML_DECREMENT_OP) &&
+			    (obj_desc->common.type ==
+			     ACPI_TYPE_LOCAL_REFERENCE) &&
+			    (obj_desc->reference.class ==
+			     ACPI_REFCLASS_INDEX) &&
+			    (obj_desc->reference.target_type ==
+			     ACPI_TYPE_PACKAGE)) {
+				status = acpi_ex_resolve_to_value(stack_ptr,
+								  walk_state);
+				if (ACPI_FAILURE(status)) {
+					return_ACPI_STATUS(status);
+				}
+
+				acpi_ut_remove_reference(obj_desc);
+				obj_desc = *stack_ptr;
+			}
+
 			/*
 			 * Need an operand of type ACPI_TYPE_INTEGER, but we can
 			 * implicitly convert from a STRING or BUFFER.
Signature · 1 line
2.56.0
author maintainer
#28 lore raw

PATCH v2 28/42 ACPICA: tables: Fix table buffer leak when Load fails verification

In reply to Maciej Wieczor-Retman

From: Pawel Chmielewski <[email protected]>

Commit "Improve error handling in table loading process to ensure proper cleanup on failure" removed the ACPI_FREE of the table buffer from the error path of AcpiExLoadOp, assuming lower layers always release it. That holds only when the table was installed and AcpiTbLoadTable failed.

If AcpiTbVerifyTempTable fails in AcpiTbInstallStandardTable (e.g. AE_ALREADY_EXISTS when the table is already loaded), the error path calls AcpiTbReleaseTempTable, which is a no-op for ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL. The buffer allocated by the Load operator leaks on every failed Load.

Make AcpiTbInstallAndLoadTable always consume an INTERNAL_VIRTUAL table and free it when AcpiTbInstallStandardTable fails. Document this in the function header and fix the comment in AcpiExLoadOp. Verified with acpiexec by executing Load twice on the same SSDT buffer.

---
 drivers/acpi/acpica/exconfig.c |  8 ++------
 drivers/acpi/acpica/tbdata.c   | 12 +++++++++++-
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/acpi/acpica/exconfig.c +2 -6
index cb2eed531c67..2354755ce8b3 100644
@@ -461,12 +461,8 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
 	acpi_ex_enter_interpreter();
 	if (ACPI_FAILURE(status)) {
 
-		/*
-		 * Table buffer is already freed by acpi_tb_uninstall_table
-		 * in acpi_tb_install_and_load_table if installation succeeded,
-		 * or by acpi_tb_uninstall_table in acpi_tb_install_standard_table
-		 * if verification failed after partial setup.
-		 */
+		/* Table buffer is already freed by acpi_tb_install_and_load_table */
+
 		return_ACPI_STATUS(status);
 	}
 
drivers/acpi/acpica/tbdata.c +11 -1
index 8185c6f7ce23..c756d34eeb44 100644
@@ -995,7 +995,9 @@ acpi_tb_load_table(u32 table_index, struct acpi_namespace_node *parent_node)
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Install and load an ACPI table
+ * DESCRIPTION: Install and load an ACPI table. An internally allocated
+ *              table (ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) is always consumed,
+ *              on failure it is freed here.
  *
  ******************************************************************************/
 
@@ -1015,6 +1017,14 @@ acpi_tb_install_and_load_table(acpi_physical_address address,
 	status = acpi_tb_install_standard_table(address, flags, table, TRUE,
 						override, &i);
 	if (ACPI_FAILURE(status)) {
+		/*
+		 * Table was not installed (e.g. it is a duplicate or failed
+		 * verification), so nobody else will free an internal buffer
+		 */
+		if ((flags & ACPI_TABLE_ORIGIN_MASK) ==
+		    ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
+			ACPI_FREE(table);
+		}
 		goto exit;
 	}
 
Signature · 1 line
2.56.0
author maintainer
#29 lore raw

PATCH v2 29/42 ACPICA: parser: Fix parse tree memory leak on AML execution error unwind

In reply to Maciej Wieczor-Retman

From: Iurii Trukhin <[email protected]>

AcpiPsCompleteThisOp() checks WalkState->OpInfo->Class when deciding whether to defer deletion of an AML_CLASS_ARGUMENT parse object to its parent. During error unwind, however, WalkState->OpInfo can still refer to the child that failed while Op refers to an enclosing scope.

If that child is an AML_INT_NAMEPATH_OP, the enclosing parse subtrees are skipped as well. A nested control method has RootOp = NULL, so an unattached top-level If subtree can leak on every failed evaluation.

Look up the opcode class of Op directly and only defer argument-object deletion when Op has a parent. Preserve WalkState->Opcode, which the parser still uses when skipping failed module-level scopes. Remove the extra region-error AcpiPsDeleteParseTree() call now that completion owns that deletion, and return discarded control states through AcpiUtDeleteGenericState() instead of freeing cached objects directly.

Tested with native iASL and acpiexec using a nested _GPE._L6F method whose If predicate calls a missing external _STA method. The unpatched interpreter leaves 64 parse objects after 32 evaluations; the patched interpreter leaves none. Both retain the expected AE_NOT_FOUND result. Normal If/Return evaluations continue to return 0 and 42.

---
 drivers/acpi/acpica/psloop.c   |  5 +++--
 drivers/acpi/acpica/psobject.c |  1 -
 drivers/acpi/acpica/psparse.c  | 16 ++++++++++++----
 3 files changed, 15 insertions(+), 7 deletions(-)
drivers/acpi/acpica/psloop.c +3 -2
index 24a57f971c96..f67bc2f3dc42 100644
@@ -464,8 +464,9 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
 						walk_state->aml =
 						    parser_state->aml;
 					}
-					ACPI_FREE(acpi_ut_pop_generic_state
-						  (&walk_state->control_state));
+					acpi_ut_delete_generic_state(
+						acpi_ut_pop_generic_state(
+							&walk_state->control_state));
 				}
 				op = NULL;
 				continue;
drivers/acpi/acpica/psobject.c +0 -1
index 629cafab1930..f1425b98087b 100644
@@ -559,7 +559,6 @@ acpi_ps_complete_op(struct acpi_walk_state *walk_state,
 								node);
 					acpi_ns_remove_node((*op)->common.node);
 					(*op)->common.node = NULL;
-					acpi_ps_delete_parse_tree(*op);
 				}
 
 				status2 =
drivers/acpi/acpica/psparse.c +12 -4
index 42ec8abef626..aa89bad57647 100644
@@ -108,6 +108,7 @@ acpi_ps_complete_this_op(struct acpi_walk_state *walk_state,
 {
 	union acpi_parse_object *prev;
 	union acpi_parse_object *next;
+	const struct acpi_opcode_info *op_info;
 	const struct acpi_opcode_info *parent_info;
 	union acpi_parse_object *replacement_op = NULL;
 	acpi_status status = AE_OK;
@@ -122,11 +123,18 @@ acpi_ps_complete_this_op(struct acpi_walk_state *walk_state,
 
 	acpi_ex_stop_trace_opcode(op, walk_state);
 
-	/* Delete this op and the subtree below it if asked to */
-
+	/*
+	 * Delete this op and the subtree below it if asked to
+	 *
+	 * Derive op_info from Op instead of using walk_state->op_info. While they are
+	 * often synonymous it is different during error unwind (in acpi_ps_complete_op).
+	 * Then the latter can describe a failed child object instead of the enclosing
+	 * operation that we want to handle here.
+	 */
+	op_info = acpi_ps_get_opcode_info(op->common.aml_opcode);
 	if (((walk_state->parse_flags & ACPI_PARSE_TREE_MASK) !=
-	     ACPI_PARSE_DELETE_TREE)
-	    || (walk_state->op_info->class == AML_CLASS_ARGUMENT)) {
+	     ACPI_PARSE_DELETE_TREE) ||
+	    ((op_info->class == AML_CLASS_ARGUMENT) && op->common.parent)) {
 		return_ACPI_STATUS(AE_OK);
 	}
 
Signature · 1 line
2.56.0
author maintainer
#30 lore raw

PATCH v2 30/42 ACPICA: IORT: Add Root Complex PASID Flags field

In reply to Maciej Wieczor-Retman

From: Vidya Sagar <[email protected]>

The IORT spec, Issue E.c (ARM DEN 0049E.c, January 2022), bumps the Root Complex Node to revision 4 and adds two PASID descriptors:

- PASID Capabilities at byte offset 33 (2 bytes), bits[4:0] of which report the Max PASID Width supported by the Root Complex.
- Flags at byte offset 36 (4 bytes), bit 0 of which reports whether the Root Complex itself supports PASID. This is distinct from the existing ATS Attribute bit 2 (at offset 24) that only reports whether the RC forwards PASID information on translated transactions.

ACPI_IORT_ROOT_COMPLEX in source/include/actbl2.h was updated for the E.c PASID Capabilities descriptor (offset 33) but stops short with a trailing 'UINT8 Reserved[]' flexible array, so the new Flags field at offset 36 is unreachable and the existing ACPI_IORT_PASID_* definitions have no consumer.

Replace the trailing flexible array with a fixed 'UINT8 Reserved[1]' followed by 'UINT32 Flags' so the struct fully covers RC node revision 4, and add the ACPI_IORT_RC_PASID_SUPPORTED mask for bit 0 of the new field. With #pragma pack(1) in effect for actbl2.h, this lands the new field at the spec-mandated absolute offset 36.

---
 include/acpi/actbl2.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/acpi/actbl2.h +5 -1
index 8e0d5156e6d6..1dafb2a71368 100644
@@ -750,7 +750,8 @@ struct acpi_iort_root_complex {
 	u32 pci_segment_number;
 	u8 memory_address_limit;	/* Memory address size limit */
 	u16 pasid_capabilities;	/* PASID Capabilities */
-	u8 reserved[];		/* Reserved, must be zero */
+	u8 reserved[1]; /* Reserved, must be zero */
+	u32 flags; /* Flags (IORT E.c, RC node revision >= 4) */
 };
 
 /* Masks for ats_attribute field above */
@@ -762,6 +763,9 @@ struct acpi_iort_root_complex {
 /* Masks for pasid_capabilities field above */
 #define ACPI_IORT_PASID_MAX_WIDTH       (0x1F)	/* Bits 0-4 */
 
+/* Masks for Flags field above */
+#define ACPI_IORT_RC_PASID_SUPPORTED (1) /* The root complex PASID support */
+
 struct acpi_iort_smmu {
 	u64 base_address;	/* SMMU base address */
 	u64 span;		/* Length of memory range */
Signature · 1 line
2.56.0
author maintainer
#31 lore raw

PATCH v2 31/42 ACPICA: events: Add missing event mutex to AcpiEvClearGpeDispatchByOwner()

In reply to Maciej Wieczor-Retman

While AcpiEvClearGpeDispatchByOwner() holds the global spinlock there are other GPE related functions that work on GPE blocks and they acquire the ACPI_MTX_EVENTS mutex.

Acquire the same mutex around handling GPE blocks to avoid any races between the different functions.

---
 drivers/acpi/acpica/evgpe.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/acpi/acpica/evgpe.c +6 -0
index 93e205c0709e..f74805507529 100644
@@ -576,6 +576,11 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 		return_ACPI_STATUS(AE_OK);
 	}
 
+	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
+	if (ACPI_FAILURE(status)) {
+		return_ACPI_STATUS(status);
+	}
+
 	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 
 	/* Walk all GPE interrupt blocks */
@@ -629,6 +634,7 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 	}
 
 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
+	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
 	return_ACPI_STATUS(status);
 }
 
Signature · 1 line
2.56.0
author maintainer
#32 lore raw

PATCH v2 32/42 ACPICA: events: Remove redundant code

In reply to Maciej Wieczor-Retman

This snippet happens inside the case part of a switch/case statement. It only checks whether the switch and case value match which makes no sense since they will always match. Remove the check.

---
 drivers/acpi/acpica/evgpe.c | 12 ------------
 1 file changed, 12 deletions(-)
drivers/acpi/acpica/evgpe.c +0 -12
index f74805507529..578651cde6f3 100644
@@ -489,18 +489,6 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
 
 	case ACPI_GPE_DISPATCH_METHOD:
 
-		/*
-		 * Re-check dispatch type. The table may have been unloaded
-		 * and its GPE dispatch cleared while we were waiting.
-		 */
-		if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
-		    ACPI_GPE_DISPATCH_METHOD) {
-			ACPI_DEBUG_PRINT(
-				(ACPI_DB_EVENTS,
-				 "GPE method dispatch cleared during wait\n"));
-			goto error_exit;
-		}
-
 		/* Allocate the evaluation information block */
 
 		info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
Signature · 1 line
2.56.0
author maintainer
#33 lore raw

PATCH v2 33/42 ACPICA: events: Fix AcpiEvClearGpeDispatchByOwner handler type processing

In reply to Maciej Wieczor-Retman

GPEs can have different callbacks tied to them - methods, notifies and handlers. Handlers, usually being functions called from C drivers, override methods, but they save the pointer to them and restore them later when handlers are unloaded.

Check and clear the methods hidden under the handler.

---
 drivers/acpi/acpica/evgpe.c | 103 +++++++++++++++++++++++++++++++++---
 1 file changed, 96 insertions(+), 7 deletions(-)
drivers/acpi/acpica/evgpe.c +96 -7
index 578651cde6f3..d45926ad3261 100644
@@ -535,6 +535,67 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
 }
 
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_dispatch_type_hidden_handler
+ *
+ * PARAMETERS:  gpe_event_info  - Struct where GPE dispatch type is stored
+ *              owner_id        - Table owner_id being unloaded that should match
+ *                                the gpe_event_info
+ *
+ * RETURN:      Return the dispatch type if it is either explicitly present or
+ *              hidden behind the handler saved method_node. The GPE has to also
+ *              match the table ID passed through owner_id to this function.
+ *              Return 0 if the above criteria aren't matched.
+ *
+ * DESCRIPTION: Check whether a passed GPE event info is of either DISPATCH,
+ *              NOTIFY or HANDLER type. Then verify it belongs to the table
+ *              ID passed as an argument and that it has a Method Node. Helper
+ *              is used for example with cleaning up after table unloading.
+ *
+ ******************************************************************************/
+static u8
+acpi_ev_dispatch_type_hidden_handler(struct acpi_gpe_event_info *gpe_event_info,
+				     acpi_owner_id owner_id)
+{
+	u8 gpe_dispatch_type = ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags);
+	struct acpi_gpe_handler_info *handler;
+
+	switch (gpe_dispatch_type) {
+	case ACPI_GPE_DISPATCH_METHOD:
+		if (!(gpe_event_info->dispatch.method_node) ||
+		    (gpe_event_info->dispatch.method_node->owner_id !=
+		     owner_id)) {
+			return 0;
+		}
+		break;
+
+	/* Method or Notify can be saved if the handler is present */
+	case ACPI_GPE_DISPATCH_HANDLER:
+	case ACPI_GPE_DISPATCH_RAW_HANDLER:
+		handler = gpe_event_info->dispatch.handler;
+		if (!(handler->method_node)) {
+			return 0;
+		}
+
+		switch (ACPI_GPE_DISPATCH_TYPE(handler->original_flags)) {
+		case ACPI_GPE_DISPATCH_METHOD:
+			if (handler->method_node->owner_id != owner_id) {
+				return 0;
+			}
+			break;
+		default:
+			return 0;
+		}
+
+		break;
+
+	default:
+		return 0;
+	}
+	return gpe_dispatch_type;
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_clear_gpe_dispatch_by_owner
@@ -557,6 +618,8 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 	u32 gpe_number;
 	acpi_cpu_flags flags;
 	acpi_status status = AE_OK;
+	u32 gpe_dispatch_type;
+	struct acpi_gpe_handler_info *handler;
 
 	ACPI_FUNCTION_TRACE_U32(ev_clear_gpe_dispatch_by_owner, owner_id);
 
@@ -584,13 +647,15 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 				gpe_event_info =
 					&gpe_block->event_info[gpe_number];
 
-				if ((ACPI_GPE_DISPATCH_TYPE(
-					     gpe_event_info->flags) ==
-				     ACPI_GPE_DISPATCH_METHOD) &&
-				    (gpe_event_info->dispatch.method_node) &&
-				    (gpe_event_info->dispatch.method_node
-					     ->owner_id == owner_id)) {
-					/* GPE method belongs to table being unloaded */
+				gpe_dispatch_type =
+					acpi_ev_dispatch_type_hidden_handler(
+						gpe_event_info, owner_id);
+				switch (gpe_dispatch_type) {
+				case ACPI_GPE_DISPATCH_METHOD:
+					/*
+					 * GPE method belongs to table being unloaded. Clear
+					 * only the dispatch type, preserve other flags.
+					 */
 
 					if (gpe_event_info
 						    ->disable_for_dispatch) {
@@ -612,6 +677,30 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 							gpe_event_info,
 							ACPI_GPE_DISABLE);
 					}
+					break;
+
+				case ACPI_GPE_DISPATCH_HANDLER:
+				case ACPI_GPE_DISPATCH_RAW_HANDLER:
+
+					handler =
+						gpe_event_info->dispatch.handler;
+					gpe_dispatch_type =
+						ACPI_GPE_DISPATCH_TYPE(
+							handler->original_flags);
+
+					/* Forget the hidden method so handler removal can't restore it */
+					if (gpe_dispatch_type ==
+					    ACPI_GPE_DISPATCH_METHOD) {
+						handler->method_node = NULL;
+						handler->original_flags &=
+							~ACPI_GPE_DISPATCH_MASK; /* -> NONE */
+						handler->originally_enabled =
+							FALSE;
+					}
+					break;
+
+				default:
+					break;
 				}
 			}
 
Signature · 1 line
2.56.0
author maintainer
#34 lore raw

PATCH v2 34/42 ACPICA: events: Fix GPE cleanup return after changing program state

In reply to Maciej Wieczor-Retman

If a GPE dispatch method or notify is currently getting executed or is set to polling etc. its table can't be freed. However the original commit ("ACPICA: Events: Clear GPE dispatch by owner during table unload") that tried to fix this problem would check this condition while some GPE methods already got disabled.

First parse all the GPE blocks and look if at least one element is blocked from being freed. If so abort the cleanup operation.

---
 drivers/acpi/acpica/evgpe.c | 49 +++++++++++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 10 deletions(-)
drivers/acpi/acpica/evgpe.c +39 -10
index d45926ad3261..5c283a2faaf0 100644
@@ -636,6 +636,43 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 
 	/* Walk all GPE interrupt blocks */
 
+	gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
+	while (gpe_xrupt_info) {
+		gpe_block = gpe_xrupt_info->gpe_block_list_head;
+		while (gpe_block) {
+			/*
+			 * Walk all GPEs in this block to make sure none are blocked from
+			 * getting cleared with disable_for_dispatch
+			 */
+
+			for (gpe_number = 0; gpe_number < gpe_block->gpe_count;
+			     gpe_number++) {
+				gpe_event_info =
+					&gpe_block->event_info[gpe_number];
+				gpe_dispatch_type =
+					acpi_ev_dispatch_type_hidden_handler(
+						gpe_event_info, owner_id);
+				if ((gpe_dispatch_type ==
+					     ACPI_GPE_DISPATCH_METHOD ||
+				     gpe_dispatch_type ==
+					     ACPI_GPE_DISPATCH_NOTIFY) &&
+				    gpe_event_info->disable_for_dispatch) {
+					/* At least one handler is polling or executing, cannot clear */
+					status = AE_ABORT_METHOD;
+					acpi_os_release_lock(acpi_gbl_gpe_lock,
+							     flags);
+					(void)acpi_ut_release_mutex(
+						ACPI_MTX_EVENTS);
+					return_ACPI_STATUS(status);
+				}
+			}
+
+			gpe_block = gpe_block->next;
+		}
+
+		gpe_xrupt_info = gpe_xrupt_info->next;
+	}
+
 	gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
 	while (gpe_xrupt_info) {
 		gpe_block = gpe_xrupt_info->gpe_block_list_head;
@@ -656,17 +693,10 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 					 * GPE method belongs to table being unloaded. Clear
 					 * only the dispatch type, preserve other flags.
 					 */
-
-					if (gpe_event_info
-						    ->disable_for_dispatch) {
-						/* Handler is executing, cannot clear */
-						status = AE_ABORT_METHOD;
-					} else {
-						/* Clear only the dispatch type, preserve other flags */
 						gpe_event_info->flags &=
 							~ACPI_GPE_DISPATCH_MASK;
-						gpe_event_info->dispatch
-							.method_node = NULL;
+					gpe_event_info->dispatch.method_node =
+						NULL;
 
 						/*
 						 * Hardware-disable the GPE so a late interrupt
@@ -676,7 +706,6 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 						(void)acpi_hw_low_set_gpe(
 							gpe_event_info,
 							ACPI_GPE_DISABLE);
-					}
 					break;
 
 				case ACPI_GPE_DISPATCH_HANDLER:
Signature · 1 line
2.56.0
author maintainer
#35 lore raw

PATCH v2 35/42 ACPICA: events: Handle GPEs' Notify dispatch type

In reply to Maciej Wieczor-Retman

The NotifyList is a list of devices that are tied to a single GPE. All devices on the list shall be notified if the GPE fires. Devices can have different parent tables - for example a DSDT can own some devices while a separate SSDT can own a couple of different ones.

GPE dispatch can be of the Notify type. When it is, the cleanup consists of removing devices from the GPE's device NotifyList - but only the ones that match the ID of the table that is getting unloaded. One also has to check the option of the NotifyList being stored away in the handler MethodNode pointer, similar to how the Method type is treated.

Freeing the GPE notify info entries tied to device nodes taken off the NotifyList should happen after the spinlock is released as some platforms can't handle freeing/allocating when holding spinlocks.

---
 drivers/acpi/acpica/evgpe.c | 146 ++++++++++++++++++++++++++++++++++++
 1 file changed, 146 insertions(+)
drivers/acpi/acpica/evgpe.c +146 -0
index 5c283a2faaf0..be48b8d1837f 100644
@@ -535,6 +535,96 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
 }
 
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_notify_list_has_owner
+ *
+ * PARAMETERS:  notify          - List of notify dispatch events
+ *              owner_id        - Table owner_id being unloaded that should match
+ *                                one of the notify device nodes on the list
+ *
+ * RETURN:      Return TRUE if at least one of the device nodes matches the
+ *              passed owner_id. Return FALSE if all notify list objects don't
+ *              match the passed owner_id.
+ *
+ * DESCRIPTION: Check whether at least on object on the notify list matches its
+ *              owner_id to the one passed as a function parameter. That means
+ *              that at least one device has ownership over an object on this
+ *              notify list.
+ *
+ ******************************************************************************/
+static u8 acpi_ev_notify_list_has_owner(struct acpi_gpe_notify_info *notify,
+					acpi_owner_id owner_id)
+{
+	while (notify) {
+		if (notify->device_node->owner_id == owner_id) {
+			return (TRUE);
+		}
+		notify = notify->next;
+	}
+	return (FALSE);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_unlink_notify_list_dev_id
+ *
+ * PARAMETERS:  owner_id        - Table owner_id being unloaded that should match
+ *                                the devices on the notify_list.
+ *              notify_list     - Address of the notify_list from the GPE
+ *              to_free_list    - Address of a struct acpi_gpe_notify_info pointer that
+ *                                will later be used to free the device objects
+ *                                from the list that match the owner_id
+ *
+ * RETURN:      Return TRUE if the original notify_list was emptied after the
+ *              unlinking is done. Return FALSE otherwise.
+ *
+ * DESCRIPTION: Helper in processing the notify_list during table unloading.
+ *              notify_list can contain devices from other tables. Only devices
+ *              from the table currently getting unloaded should be cleared from
+ *              this list. This helper parses the list and moves nodes that
+ *              match the unloaded table's ID to a separate single linked list.
+ *              That list shall be later freed node by node. It shouldn't be
+ *              freed immediately as freeing/allocating should be avoided on
+ *              some system when the global spinlock is held.
+ *
+ ******************************************************************************/
+static u8
+acpi_ev_unlink_notify_list_dev_id(acpi_owner_id owner_id,
+				  struct acpi_gpe_notify_info **notify_list,
+				  struct acpi_gpe_notify_info **to_free_list)
+{
+	/* Cursor pointer that will move through all notify_list nodes addresses */
+	struct acpi_gpe_notify_info **notify_pointer = notify_list;
+	/* Currently looked at structure in the loop iteration */
+	struct acpi_gpe_notify_info *node = *notify_pointer;
+
+	/*
+	 * Go through all Notify structures to find devices matching the owner_id
+	 * that is getting unloaded
+	 */
+	while (node) {
+		if (node->device_node->owner_id == owner_id) {
+			/* Modify original list by unlinking Node */
+			*notify_pointer = node->next;
+			/* Link the unlinked node to the to-be-freed list */
+			node->next = *to_free_list;
+			*to_free_list = node;
+		} else {
+			/* Move the cursor one node further */
+			notify_pointer = &node->next;
+		}
+		/* Grab the next node or NULL if there is no more */
+		node = *notify_pointer;
+	}
+
+	/*
+	 * If the original list was emptied return TRUE so that the caller knows to
+	 * move the dispatch type from Notify to None
+	 */
+	return (*notify_list == NULL);
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_dispatch_type_hidden_handler
@@ -560,6 +650,7 @@ acpi_ev_dispatch_type_hidden_handler(struct acpi_gpe_event_info *gpe_event_info,
 {
 	u8 gpe_dispatch_type = ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags);
 	struct acpi_gpe_handler_info *handler;
+	struct acpi_gpe_notify_info *notify;
 
 	switch (gpe_dispatch_type) {
 	case ACPI_GPE_DISPATCH_METHOD:
@@ -570,6 +661,13 @@ acpi_ev_dispatch_type_hidden_handler(struct acpi_gpe_event_info *gpe_event_info,
 		}
 		break;
 
+	case ACPI_GPE_DISPATCH_NOTIFY:
+		notify = gpe_event_info->dispatch.notify_list;
+		if (!acpi_ev_notify_list_has_owner(notify, owner_id)) {
+			return 0;
+		}
+		break;
+
 	/* Method or Notify can be saved if the handler is present */
 	case ACPI_GPE_DISPATCH_HANDLER:
 	case ACPI_GPE_DISPATCH_RAW_HANDLER:
@@ -584,6 +682,14 @@ acpi_ev_dispatch_type_hidden_handler(struct acpi_gpe_event_info *gpe_event_info,
 				return 0;
 			}
 			break;
+		case ACPI_GPE_DISPATCH_NOTIFY:
+			if (!acpi_ev_notify_list_has_owner(
+				    ACPI_CAST_PTR(struct acpi_gpe_notify_info,
+						  handler->method_node),
+				    owner_id)) {
+				return 0;
+			}
+			break;
 		default:
 			return 0;
 		}
@@ -620,6 +726,8 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 	acpi_status status = AE_OK;
 	u32 gpe_dispatch_type;
 	struct acpi_gpe_handler_info *handler;
+	struct acpi_gpe_notify_info *list;
+	struct acpi_gpe_notify_info *free_list = NULL;
 
 	ACPI_FUNCTION_TRACE_U32(ev_clear_gpe_dispatch_by_owner, owner_id);
 
@@ -708,6 +816,20 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 							ACPI_GPE_DISABLE);
 					break;
 
+				case ACPI_GPE_DISPATCH_NOTIFY:
+					if (acpi_ev_unlink_notify_list_dev_id(
+						    owner_id,
+						    &gpe_event_info->dispatch
+							     .notify_list,
+						    &free_list)) {
+						gpe_event_info->flags &=
+							~ACPI_GPE_DISPATCH_MASK;
+						(void)acpi_hw_low_set_gpe(
+							gpe_event_info,
+							ACPI_GPE_DISABLE);
+					}
+					break;
+
 				case ACPI_GPE_DISPATCH_HANDLER:
 				case ACPI_GPE_DISPATCH_RAW_HANDLER:
 
@@ -725,6 +847,22 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 							~ACPI_GPE_DISPATCH_MASK; /* -> NONE */
 						handler->originally_enabled =
 							FALSE;
+					} else if (gpe_dispatch_type ==
+						   ACPI_GPE_DISPATCH_NOTIFY) {
+						list = ACPI_CAST_PTR(
+							struct acpi_gpe_notify_info,
+							handler->method_node);
+						if (acpi_ev_unlink_notify_list_dev_id(
+							    owner_id, &list,
+							    &free_list)) {
+							handler->original_flags &=
+								~ACPI_GPE_DISPATCH_MASK;
+							handler->originally_enabled =
+								FALSE;
+						}
+						handler->method_node = ACPI_CAST_PTR(
+							struct acpi_namespace_node,
+							list);
 					}
 					break;
 
@@ -740,6 +878,14 @@ acpi_status acpi_ev_clear_gpe_dispatch_by_owner(acpi_owner_id owner_id)
 	}
 
 	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
+
+	/* Free the free_list elements from the Notify path */
+	while (free_list) {
+		list = free_list->next;
+		ACPI_FREE(free_list);
+		free_list = list;
+	}
+
 	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
 	return_ACPI_STATUS(status);
 }
Signature · 1 line
2.56.0
author maintainer
#36 lore raw

PATCH v2 36/42 ACPICA: tables: Fix wrong table unload and notify call order

In reply to Maciej Wieczor-Retman

Newly added cleanup - AcpiEvClearGpeDispatchByOwner() - was ordered in such a manner that if the clear gpe dispatch call failed it would leave GPEs still enabled but the host would get notified that the table is unloaded already.

Simply reorder the code blocks so that notifying the host happens last, after the GPE dispatch cleanup.

---
 drivers/acpi/acpica/tbdata.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/acpi/acpica/tbdata.c +7 -7
index c756d34eeb44..1cf0a46b3539 100644
@@ -1068,13 +1068,6 @@ acpi_status acpi_tb_unload_table(u32 table_index)
 		return_ACPI_STATUS(AE_NOT_EXIST);
 	}
 
-	/* Invoke table handler */
-
-	status = acpi_get_table_by_index(table_index, &table);
-	if (ACPI_SUCCESS(status)) {
-		acpi_tb_notify_table(ACPI_TABLE_EVENT_UNLOAD, table);
-	}
-
 #if (!ACPI_REDUCED_HARDWARE)
 	/*
 	 * Clear GPE dispatch for methods owned by the table being unloaded.
@@ -1088,6 +1081,13 @@ acpi_status acpi_tb_unload_table(u32 table_index)
 	}
 #endif /* !ACPI_REDUCED_HARDWARE */
 
+	/* Invoke table handler */
+
+	status = acpi_get_table_by_index(table_index, &table);
+	if (ACPI_SUCCESS(status)) {
+		acpi_tb_notify_table(ACPI_TABLE_EVENT_UNLOAD, table);
+	}
+
 	/* Delete the portion of the namespace owned by this table */
 
 	status = acpi_tb_delete_namespace_by_owner(table_index);
Signature · 1 line
2.56.0
author maintainer
#37 lore raw

PATCH v2 37/42 ACPICA: tables: Fix global table read missing mutex

In reply to Maciej Wieczor-Retman

Reading AcpiGbl_RootTableList.Tables[].OwnerId without holding an appropriate mutex can lead to races if anything modified the table after the read.

Use a helper specifically dedicated to reading the OwnerId.

---
 drivers/acpi/acpica/tbdata.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/acpi/acpica/tbdata.c +3 -2
index 1cf0a46b3539..94ac355daae7 100644
@@ -1059,6 +1059,7 @@ acpi_status acpi_tb_unload_table(u32 table_index)
 {
 	acpi_status status = AE_OK;
 	struct acpi_table_header *table;
+	acpi_owner_id ACPI_UNUSED_VAR owner_id;
 
 	ACPI_FUNCTION_TRACE(tb_unload_table);
 
@@ -1074,8 +1075,8 @@ acpi_status acpi_tb_unload_table(u32 table_index)
 	 * If any matching GPE is currently dispatching, AE_ABORT_METHOD is
 	 * returned and the unload cannot proceed.
 	 */
-	status = acpi_ev_clear_gpe_dispatch_by_owner(
-		acpi_gbl_root_table_list.tables[table_index].owner_id);
+	acpi_tb_get_owner_id(table_index, &owner_id);
+	status = acpi_ev_clear_gpe_dispatch_by_owner(owner_id);
 	if (ACPI_FAILURE(status)) {
 		return_ACPI_STATUS(status);
 	}
Signature · 1 line
2.56.0
author maintainer
#38 lore raw

PATCH v2 38/42 ACPICA: executer: Fix copying PCC source buffer data

In reply to Maciej Wieczor-Retman

Paths leading up to AcpiExWriteDataToField() group Integer, Buffer and String together when handling the operand type. In the operand type union, the integer's value and buffer's pointer share the same space.

One issue can be that the number stored in integer.value is interpreted as buffer.pointer - which can happen if ACPI_TYPE_INTEGER is the source operand type. The following code should result in a memory fault as it will read the value as the address, and won't use the address of the variable as it should:

    COMD = 0x01

Other problem is if SourceDesc->Buffer.Length is smaller than DataLength
- then more data will be read from the source operand than planned. For example the following ASL code would result in extra data getting read from BUF0 to COSP:

Name (BUF0, Buffer (2) {0x01, 0x02})
COSP = BUF0

Fix the first problem by moving the Buffer and BufferLength assignment before the PCC buffer code path.

Fix the second problem by copying only as much space as the source operand has. If it has less than the destination just zero-extend the extra space as similar Field operations do (AcpiExInsertIntoField() for example).

Fixes aa6ec56b574d ("ACPICA: ACPI 6.3: add PCC operation region support for AML interpreter")
---
 drivers/acpi/acpica/exfield.c | 63 ++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 27 deletions(-)
drivers/acpi/acpica/exfield.c +36 -27
index 632fc8693f23..2199d054ed58 100644
@@ -291,6 +291,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
 	acpi_status status;
 	u32 buffer_length;
 	u32 data_length;
+	u32 copy_length;
 	void *buffer;
 
 	ACPI_FUNCTION_TRACE_PTR(ex_write_data_to_field, obj_desc);
@@ -338,7 +339,34 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
 		    acpi_ex_write_serial_bus(source_desc, obj_desc,
 					     result_desc);
 		return_ACPI_STATUS(status);
-	} else if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
+	}
+
+	/* Get a pointer to the data to be written */
+
+	switch (source_desc->common.type) {
+	case ACPI_TYPE_INTEGER:
+
+		buffer = &source_desc->integer.value;
+		buffer_length = sizeof(source_desc->integer.value);
+		break;
+
+	case ACPI_TYPE_BUFFER:
+
+		buffer = source_desc->buffer.pointer;
+		buffer_length = source_desc->buffer.length;
+		break;
+
+	case ACPI_TYPE_STRING:
+
+		buffer = source_desc->string.pointer;
+		buffer_length = source_desc->string.length;
+		break;
+
+	default:
+		return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
+	}
+
+	if ((obj_desc->common.type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
 		   (obj_desc->field.region_obj->region.space_id ==
 		    ACPI_ADR_SPACE_PLATFORM_COMM)) {
 		/*
@@ -369,9 +397,15 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
 			return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
 		}
 
+		copy_length = ACPI_MIN(data_length, buffer_length);
+
+		memset(obj_desc->field.region_obj->field.internal_pcc_buffer +
+			       obj_desc->field.base_byte_offset,
+		       0, data_length);
+
 		memcpy(obj_desc->field.region_obj->field.internal_pcc_buffer +
 		       obj_desc->field.base_byte_offset,
-		       source_desc->buffer.pointer, data_length);
+		       buffer, copy_length);
 
 		if (MASTER_SUBSPACE_COMMAND(obj_desc->field.base_byte_offset)) {
 
@@ -391,31 +425,6 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
 		return (AE_OK);
 	}
 
-	/* Get a pointer to the data to be written */
-
-	switch (source_desc->common.type) {
-	case ACPI_TYPE_INTEGER:
-
-		buffer = &source_desc->integer.value;
-		buffer_length = sizeof(source_desc->integer.value);
-		break;
-
-	case ACPI_TYPE_BUFFER:
-
-		buffer = source_desc->buffer.pointer;
-		buffer_length = source_desc->buffer.length;
-		break;
-
-	case ACPI_TYPE_STRING:
-
-		buffer = source_desc->string.pointer;
-		buffer_length = source_desc->string.length;
-		break;
-
-	default:
-		return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
-	}
-
 	ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
 			  "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
 			  source_desc,
Signature · 1 line
2.56.0
author maintainer
#39 lore raw

PATCH v2 39/42 ACPICA: dispatcher: Fix zero size non-NULL PCC buffer pointer

In reply to Maciej Wieczor-Retman

Zero sized PCC buffers still get allocated, so they pass the null checks and can cause writes to unallocated memory.

Skip the allocation if the region length is zero or the AOPOBJ_DATA_VALID flag is not set as otherwise the disassembler will emit warnings on every PCC Field().

Fixes aa6ec56b574d ("ACPICA: ACPI 6.3: add PCC operation region support for AML interpreter")
---
 drivers/acpi/acpica/dsfield.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/acpi/acpica/dsfield.c +12 -0
index 5d0dfe4ff8e8..d091453eea93 100644
@@ -530,6 +530,18 @@ acpi_ds_create_field(union acpi_parse_object *op,
 	if (info.region_node->object->region.space_id ==
 	    ACPI_ADR_SPACE_PLATFORM_COMM &&
 	    !region_node->object->field.internal_pcc_buffer) {
+		/*
+	   * If AOPOBJ_DATA_VALID flag is not set the region operands is not
+	   * evaluated (e.g. disassembler), nothing to allocate.
+	   * Also avoid a zero-size allocation which may yield a non-NULL pointer
+	   */
+
+		if (!(info.region_node->object->common.flags &
+		      AOPOBJ_DATA_VALID) ||
+		    (!info.region_node->object->region.length)) {
+			return_ACPI_STATUS(AE_OK);
+		}
+
 		region_node->object->field.internal_pcc_buffer =
 		    ACPI_ALLOCATE_ZEROED(info.region_node->object->region.
 					 length);
Signature · 1 line
2.56.0
author maintainer
#40 lore raw

PATCH v2 40/42 ACPICA: utilities: Clear NextObject so the outer loop doesn't read it

In reply to Maciej Wieczor-Retman

If the inner 'while (PrevObject)' loop exits after NextObject was already set to the PrevObject->Notify.Next[i], then at the end of the outer loop, 'if (NextObject)' check will save that discarded object.

Set the unwanted NextObject to NULL before breaking the inner loop so it doesn't get saved for the next iteration of the outer loop.

---
 drivers/acpi/acpica/utdelete.c | 1 +
 1 file changed, 1 insertion(+)
drivers/acpi/acpica/utdelete.c +1 -0
index 57a0de6a49d6..7645c14aac68 100644
@@ -519,6 +519,7 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
 				while (prev_object) {
 					if (prev_object->common.type !=
 					    ACPI_TYPE_LOCAL_NOTIFY) {
+						next_object = NULL;
 						break;
 					}
 					next_object =
Signature · 1 line
2.56.0
author maintainer
#41 lore raw

PATCH v2 41/42 ACPICA: namespace: Fix memory leak around compiler alias flag

In reply to Maciej Wieczor-Retman

ANOBJ_IS_ALIAS is an iASL only flag that shares the bit position with ANOBJ_ALLOCATED_BUFFER, which is a flag used for runtime installing methods. Due to the bits matching a memory leak happens everytime a method is loaded in acpiexec (using AcpiInstallMethod()).

Check the compiler related flag only when the code is ran by the compiler.

Fixes 8d7987340301 ("ACPICA: Add alias node support in namespace handling")
---
 drivers/acpi/acpica/nsobject.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/acpi/acpica/nsobject.c +5 -2
index 49d9d917fa73..6eb278b9d714 100644
@@ -175,8 +175,11 @@ void acpi_ns_detach_object(struct acpi_namespace_node *node)
 
 	/* Alias nodes point directly to other namespace nodes; skip teardown */
 	if ((node->type == ACPI_TYPE_LOCAL_ALIAS) ||
-	    (node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS) ||
-	    (node->flags & ANOBJ_IS_ALIAS)) {
+	    (node->type == ACPI_TYPE_LOCAL_METHOD_ALIAS)
+#if defined ACPI_ASL_COMPILER
+	    || (node->flags & ANOBJ_IS_ALIAS)
+#endif
+	) {
 		node->object = NULL;
 		return_VOID;
 	}
Signature · 1 line
2.56.0
author maintainer
#42 lore raw

PATCH v2 42/42 ACPICA: acpica: Fix typo in the IOVT_IOMMU table definitions

In reply to Maciej Wieczor-Retman

Change MAGAGE to MANAGE in ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT.

---
 drivers/acpi/loongarch/iovt.c | 6 +++---
 include/acpi/actbl2.h         | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/acpi/loongarch/iovt.c +3 -3
index 1e97669eaeea..e891170d9b8b 100644
@@ -42,7 +42,7 @@ static void __init iovt_enable_acs(struct acpi_iovt_iommu *iommu)
 
 	/* IOMMU V1 only supports PCI device management */
 	if ((iommu->header.type == ACPI_IOVT_IOMMU_V1) ||
-	    (iommu->flags & (ACPI_IOVT_IOMMU_PCI_DEVICE | ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT))) {
+	    (iommu->flags & (ACPI_IOVT_IOMMU_PCI_DEVICE | ACPI_IOVT_IOMMU_MANAGE_BY_SEGMENT))) {
 		pci_request_acs();
 		acs_enabled = true;
 	}
@@ -151,7 +151,7 @@ static int __init iovt_add_iommu(struct acpi_iovt_iommu *iommu)
 	}
 
 	/* All devices in the segment are managed by this IOMMU */
-	if (np->flag & ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT)
+	if (np->flag & ACPI_IOVT_IOMMU_MANAGE_BY_SEGMENT)
 		goto skip;
 
 	if (iovt_validate_entries(iommu) < 0) {
@@ -280,7 +280,7 @@ static int iovt_pci_iommu_init(struct pci_dev *pdev, u16 dev_id, void *data)
 		if (dev_id == np->devid)
 			return -EINVAL;
 
-		if (np->flag & ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT)
+		if (np->flag & ACPI_IOVT_IOMMU_MANAGE_BY_SEGMENT)
 			goto found;
 
 		list_for_each_entry(entry, &np->ep_list, list) {
include/acpi/actbl2.h +1 -1
index 1dafb2a71368..fe767fcf5726 100644
@@ -928,7 +928,7 @@ struct acpi_iovt_iommu {
 /* Masks for Flags field above */
 #define ACPI_IOVT_IOMMU_PCI_DEVICE		(1<<0)
 #define ACPI_IOVT_IOMMU_PXM_VALID		(1<<1)
-#define ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT	(1<<2)
+#define ACPI_IOVT_IOMMU_MANAGE_BY_SEGMENT	(1<<2)
 #define ACPI_IOVT_IOMMU_HW_CAP_SUPPORT		(1<<3)
 #define ACPI_IOVT_IOMMU_MSI_INT_BYPASS		(1<<4)
 
Signature · 1 line
2.56.0