From 2546678969eabc8610156e7ebc4bbac3af5c4647 Mon Sep 17 00:00:00 2001 From: Xianglai Li Date: Wed, 11 Jun 2025 11:33:58 +0800 Subject: [PATCH 1/4] LoongArch: KVM: Fix the extioi simulation error Upstream: no Conflict: none Checkpatch: pass Fixed the out-of-bounds issue of accessing the array in the enable field of the extioi register. Signed-off-by: Xianglai Li Signed-off-by: Ming Wang --- arch/loongarch/kvm/intc/extioi.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/loongarch/kvm/intc/extioi.c b/arch/loongarch/kvm/intc/extioi.c index 440bd8733dae..227348d5fe72 100644 --- a/arch/loongarch/kvm/intc/extioi.c +++ b/arch/loongarch/kvm/intc/extioi.c @@ -244,11 +244,10 @@ static int loongarch_extioi_writew(struct kvm_vcpu *vcpu, * update irq when isr is set. */ data = s->enable.reg_u32[index] & ~old_data & s->isr.reg_u32[index]; - index = index << 2; for (i = 0; i < sizeof(data); i++) { u8 mask = (data >> (i * 8)) & 0xff; - extioi_enable_irq(vcpu, s, index + i, mask, 1); + extioi_enable_irq(vcpu, s, index * 4 + i, mask, 1); } /* * 0: disable irq. @@ -258,7 +257,7 @@ static int loongarch_extioi_writew(struct kvm_vcpu *vcpu, for (i = 0; i < sizeof(data); i++) { u8 mask = (data >> (i * 8)) & 0xff; - extioi_enable_irq(vcpu, s, index, mask, 0); + extioi_enable_irq(vcpu, s, index * 4 + i, mask, 0); } break; case EXTIOI_BOUNCE_START ... EXTIOI_BOUNCE_END: @@ -331,11 +330,10 @@ static int loongarch_extioi_writel(struct kvm_vcpu *vcpu, * update irq when isr is set. */ data = s->enable.reg_u64[index] & ~old_data & s->isr.reg_u64[index]; - index = index << 3; for (i = 0; i < sizeof(data); i++) { u8 mask = (data >> (i * 8)) & 0xff; - extioi_enable_irq(vcpu, s, index + i, mask, 1); + extioi_enable_irq(vcpu, s, index * 8 + i, mask, 1); } /* * 0: disable irq. @@ -345,7 +343,7 @@ static int loongarch_extioi_writel(struct kvm_vcpu *vcpu, for (i = 0; i < sizeof(data); i++) { u8 mask = (data >> (i * 8)) & 0xff; - extioi_enable_irq(vcpu, s, index, mask, 0); + extioi_enable_irq(vcpu, s, index * 8 + i, mask, 0); } break; case EXTIOI_BOUNCE_START ... EXTIOI_BOUNCE_END: -- Gitee From 0a2c16bc36b6c33afdda5e6063b3f49beb5439f5 Mon Sep 17 00:00:00 2001 From: wanghongliang Date: Wed, 11 Jun 2025 16:31:03 +0800 Subject: [PATCH 2/4] LoongArch: fix access mode of 7A2000 acpi gpio. Upstream: no Conflict: none Checkpatch: pass 7A2000 acpi gpio only support bit access mode. Signed-off-by: wanghongliang Signed-off-by: Ming Wang --- drivers/gpio/gpio-loongson-64bit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-loongson-64bit.c b/drivers/gpio/gpio-loongson-64bit.c index f916a5ae0290..7363736830e1 100644 --- a/drivers/gpio/gpio-loongson-64bit.c +++ b/drivers/gpio/gpio-loongson-64bit.c @@ -334,10 +334,10 @@ static const struct loongson_gpio_chip_data loongson_gpio_ls7a2000_data0 = { static const struct loongson_gpio_chip_data loongson_gpio_ls7a2000_data1 = { .label = "ls7a2000_gpio", - .mode = BYTE_CTRL_MODE, - .conf_offset = 0x84, - .in_offset = 0x88, - .out_offset = 0x80, + .mode = BIT_CTRL_MODE, + .conf_offset = 0x4, + .in_offset = 0x8, + .out_offset = 0x0, }; static const struct loongson_gpio_chip_data loongson_gpio_ls3a6000_data = { -- Gitee From f1661df83d3e70d8fa73a595a7cccc90f6731b14 Mon Sep 17 00:00:00 2001 From: Xianglai Li Date: Tue, 24 Jun 2025 17:32:27 +0800 Subject: [PATCH 3/4] drivers/iommu: Fix the initialization failure issue of the iommu module Upstream: no Conflict: none Checkpatch: pass Add support for the def_domain_type callback function. Signed-off-by: Xianglai Li Signed-off-by: Ming Wang --- drivers/iommu/loongarch_iommu.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/loongarch_iommu.c b/drivers/iommu/loongarch_iommu.c index 63d0d2ce3c0e..6905f2d3ddb8 100644 --- a/drivers/iommu/loongarch_iommu.c +++ b/drivers/iommu/loongarch_iommu.c @@ -596,13 +596,14 @@ static struct iommu_domain *la_iommu_domain_alloc(unsigned int type) switch (type) { case IOMMU_DOMAIN_BLOCKED: + case IOMMU_DOMAIN_IDENTITY: case IOMMU_DOMAIN_UNMANAGED: info = alloc_dom_info(); if (info == NULL) - return NULL; + return ERR_PTR(-ENOMEM); break; default: - return NULL; + return ERR_PTR(-EINVAL); } return &info->domain; } @@ -756,7 +757,6 @@ static void la_iommu_remove_device(struct device *dev) { struct la_iommu_dev_data *dev_data; - iommu_group_remove_device(dev); dev_data = dev->archdata.iommu; dev->archdata.iommu = NULL; kfree(dev_data); @@ -846,11 +846,13 @@ static int la_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) struct iommu_info *info; unsigned short bdf; - if (domain != NULL && domain->type == IOMMU_DOMAIN_BLOCKED) - return 0; - la_iommu_detach_dev(dev); + if (domain != NULL && + (domain->type == IOMMU_DOMAIN_IDENTITY || + domain->type == IOMMU_DOMAIN_BLOCKED)) + return 0; + if (domain == NULL) return 0; @@ -1186,6 +1188,11 @@ static void la_domain_set_plaform_dma_ops(struct device *dev) */ } +static int la_iommu_def_domain_type(struct device *dev) +{ + return IOMMU_DOMAIN_IDENTITY; +} + const struct iommu_ops la_iommu_ops = { .capable = la_iommu_capable, .domain_alloc = la_iommu_domain_alloc, @@ -1193,6 +1200,7 @@ const struct iommu_ops la_iommu_ops = { .release_device = la_iommu_remove_device, .device_group = la_iommu_device_group, .pgsize_bitmap = LA_IOMMU_PGSIZE, + .def_domain_type = la_iommu_def_domain_type, .owner = THIS_MODULE, .set_platform_dma_ops = la_domain_set_plaform_dma_ops, .default_domain_ops = &(const struct iommu_domain_ops) { -- Gitee From bd8284112d4a28c7c0e8df1a6f748068799ccb2c Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Tue, 24 Jun 2025 10:41:41 +0800 Subject: [PATCH 4/4] LoongArch: Reserve the EFI memory map region commit 39503fc84b4ea94f2bedca481de5e225e0df729d upstream. The EFI memory map at 'boot_memmap' is crucial for kdump to understand the primary kernel's memory layout. This memory region, typically part of EFI Boot Services (BS) data, can be overwritten after ExitBootServices if not explicitly preserved by the kernel. This commit addresses this by: 1. Calling memblock_reserve() to reserve the entire physical region occupied by the EFI memory map (header + descriptors). This prevents the primary kernel from reallocating and corrupting this area. 2. Setting the EFI_PRESERVE_BS_REGIONS flag in efi.flags. This indicates that efforts have been made to preserve critical BS code/data regions which can be useful for other kernel subsystems or debugging. These changes ensure the original EFI memory map data remains intact, improving kdump reliability and potentially aiding other EFI-related functionalities that might rely on preserved BS code/data. Signed-off-by: Ming Wang Signed-off-by: Huacai Chen --- arch/loongarch/kernel/efi.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/loongarch/kernel/efi.c b/arch/loongarch/kernel/efi.c index 459583c985be..76845a225e97 100644 --- a/arch/loongarch/kernel/efi.c +++ b/arch/loongarch/kernel/efi.c @@ -328,6 +328,18 @@ void __init efi_init(void) if (efi_memmap_init_early(&data) < 0) panic("Unable to map EFI memory map.\n"); + /* + * Reserve the physical memory region occupied by the EFI + * memory map table (header + descriptors). This is crucial + * for kdump, as the kdump kernel relies on this original + * memmap passed by the bootloader. Without reservation, + * this region could be overwritten by the primary kernel. + * Also, set the EFI_PRESERVE_BS_REGIONS flag to indicate that + * critical boot services data regions like this are preserved. + */ + memblock_reserve((phys_addr_t)boot_memmap, sizeof(*tbl) + data.size); + set_bit(EFI_PRESERVE_BS_REGIONS, &efi.flags); + early_memunmap(tbl, sizeof(*tbl)); } } -- Gitee