summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBibo Mao <maobibo@loongson.cn>2026-11-10 17:20:15 +0800
committerHuacai Chen <chenhuacai@loongson.cn>2026-11-10 17:20:15 +0800
commit2ccdfa6c93021ee3fca2e55d3757769ac2b69b30 (patch)
tree5a135975bbd63b3ac7f4fa877d23c556facf9d1c
parent67517aa0a0b30a8c2ddc2c34cdf2433a9c3152f0 (diff)
ACPI: LoongArch: Add checksum validation for ACPI IOVT table
Checksum information is put in acpi_table_header, here add checksum validation support with IOVT table. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
-rw-r--r--drivers/acpi/loongarch/iovt.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/acpi/loongarch/iovt.c b/drivers/acpi/loongarch/iovt.c
index 6c5bcb4df7d8..c972805c8e53 100644
--- a/drivers/acpi/loongarch/iovt.c
+++ b/drivers/acpi/loongarch/iovt.c
@@ -18,9 +18,20 @@ struct iovt_fwnode {
struct list_head ep_list;
};
+static bool checksum_valid;
static LIST_HEAD(iovt_fwnode_list);
static DEFINE_SPINLOCK(iovt_fwnode_lock);
+static u8 acpi_iovt_checksum(u8 *buffer, u32 len)
+{
+ u8 sum = 0, *end = buffer + len;
+
+ while (buffer < end)
+ sum += *buffer++;
+
+ return sum;
+}
+
#ifdef CONFIG_PCI
static void __init iovt_enable_acs(struct acpi_iovt_iommu *iommu)
{
@@ -184,6 +195,13 @@ void __init acpi_iovt_init(void)
return;
}
+ if (acpi_iovt_checksum((unsigned char *)hdr, hdr->length)) {
+ pr_err("IOVT invalid checksum\n");
+ acpi_put_table(hdr);
+ return;
+ }
+
+ checksum_valid = true;
iovt = (struct acpi_table_iovt *)hdr;
iommu = ACPI_ADD_PTR(struct acpi_iovt_iommu, iovt, iovt->iommu_offset);
for (i = 0; i < iovt->iommu_count; i++) {
@@ -199,6 +217,9 @@ void __init acpi_iovt_late_init(void)
acpi_status status;
struct acpi_table_header *hdr;
+ if (!checksum_valid)
+ return;
+
status = acpi_get_table(ACPI_SIG_IOVT, 0, &hdr);
if (ACPI_FAILURE(status)) {
if (status != AE_NOT_FOUND)