[PATCH] kernel: resourse: Add conditional handling for ACPI device

Szuying Chen posted 1 patch 3 months, 3 weeks ago
kernel/resource.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
[PATCH] kernel: resourse: Add conditional handling for ACPI device
Posted by Szuying Chen 3 months, 3 weeks ago
To avoid address conflicts and related errors, specific checks for
the ACPI device "AMDIF031" should be bypassed.

Signed-off-by: Szuying Chen <Chloe_Chen@asmedia.com.tw>
---
 kernel/resource.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/kernel/resource.c b/kernel/resource.c
index b9fa2a4ce089..9ffcd5bdb62e 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -177,6 +177,27 @@ static struct resource *alloc_resource(gfp_t flags)
 	return kzalloc(sizeof(struct resource), flags);
 }

+static int IgnoreResource(struct resource *tmp)
+{
+	char *pt, *name_sep;
+	char *name;
+
+	pt = kstrdup(tmp->name, GFP_KERNEL);
+	name_sep = pt;
+	if (!name_sep)
+		goto out;
+
+	name = strsep(&name_sep, ":");
+	if (strcmp(name, "AMDIF031") == 0) {
+		kfree(pt);
+		return 1;
+	}
+
+out:
+	kfree(pt);
+	return 0;
+}
+
 /* Return the conflict entry if you can't request it */
 static struct resource * __request_resource(struct resource *root, struct resource *new)
 {
@@ -202,6 +223,8 @@ static struct resource * __request_resource(struct resource *root, struct resour
 		p = &tmp->sibling;
 		if (tmp->end < start)
 			continue;
+		if (IgnoreResource(tmp))
+			continue;
 		return tmp;
 	}
 }
--
2.39.2
Re: [PATCH] kernel: resourse: Add conditional handling for ACPI device
Posted by kernel test robot 3 months, 3 weeks ago

Hello,

kernel test robot noticed "BUG:sleeping_function_called_from_invalid_context_at_include/linux/sched/mm.h" on:

commit: 871e73eea694be4705a5e3ebc9119e6c76c7b246 ("[PATCH] kernel: resourse: Add conditional handling for ACPI device")
url: https://github.com/intel-lab-lkp/linux/commits/Szuying-Chen/kernel-resourse-Add-conditional-handling-for-ACPI-device/20251017-103749
base: https://git.kernel.org/cgit/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/all/20251017023531.5616-1-Chloe_Chen@asmedia.com.tw/
patch subject: [PATCH] kernel: resourse: Add conditional handling for ACPI device

in testcase: boot

config: i386-randconfig-141-20251019
compiler: gcc-14
test machine: qemu-system-i386 -enable-kvm -cpu SandyBridge -smp 2 -m 4G

(please refer to attached dmesg/kmsg for entire log/backtrace)


+-------------------------------------------------------------------------------+------------+------------+
|                                                                               | 4d30e94233 | 871e73eea6 |
+-------------------------------------------------------------------------------+------------+------------+
| BUG:sleeping_function_called_from_invalid_context_at_include/linux/sched/mm.h | 0          | 12         |
+-------------------------------------------------------------------------------+------------+------------+


If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <oliver.sang@intel.com>
| Closes: https://lore.kernel.org/oe-lkp/202510201616.6e6b62a1-lkp@intel.com


[    0.605114][    T1] BUG: sleeping function called from invalid context at include/linux/sched/mm.h:323
[    0.606472][    T1] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1, name: swapper/0
[    0.607674][    T1] preempt_count: 1, expected: 0
[    0.608383][    T1] 2 locks held by swapper/0/1:
[    0.609070][    T1]  #0: 82a715b8 (acpi_scan_lock){+.+.}-{4:4}, at: acpi_scan_init (drivers/acpi/scan.c:2748)
[    0.609944][    T1]  #1: 82686c74 (resource_lock){++++}-{3:3}, at: insert_resource_conflict (kernel/resource.c:960)
[    0.611267][    T1] CPU: 1 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.18.0-rc1-00168-g871e73eea694 #1 NONE  6a82e794814861a45fb7fec961bde07e21f033c5
[    0.611273][    T1] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[    0.611275][    T1] Call Trace:
[    0.611277][    T1]  ? show_stack (arch/x86/kernel/dumpstack.c:319)
[    0.611285][    T1]  dump_stack_lvl (lib/dump_stack.c:122)
[    0.611290][    T1]  dump_stack (lib/dump_stack.c:130)
[    0.611293][    T1]  __might_resched.cold (kernel/sched/core.c:8926)
[    0.611297][    T1]  __might_sleep (kernel/sched/core.c:8855)
[    0.611303][    T1]  __kmalloc_node_track_caller_noprof (include/linux/sched/mm.h:323 (discriminator 1) mm/slub.c:4906 (discriminator 1) mm/slub.c:5241 (discriminator 1) mm/slub.c:5626 (discriminator 1) mm/slub.c:5736 (discriminator 1))
[    0.611310][    T1]  kstrdup (mm/util.c:64 (discriminator 2) mm/util.c:84 (discriminator 2))
[    0.611314][    T1]  ? __request_resource (kernel/resource.c:187 kernel/resource.c:226)
[    0.611319][    T1]  __request_resource (kernel/resource.c:187 kernel/resource.c:226)
[    0.611321][    T1]  ? insert_resource_conflict (kernel/resource.c:960)
[    0.611325][    T1]  __insert_resource (kernel/resource.c:896)
[    0.611330][    T1]  insert_resource_conflict (kernel/resource.c:960)
[    0.611333][    T1]  acpi_pci_root_create (drivers/acpi/pci_root.c:952 drivers/acpi/pci_root.c:1023)
[    0.611342][    T1]  pci_acpi_scan_root (arch/x86/pci/acpi.c:582)
[    0.611350][    T1]  acpi_pci_root_add.cold (drivers/acpi/pci_root.c:729)
[    0.611359][    T1]  acpi_bus_attach (drivers/acpi/scan.c:2261 drivers/acpi/scan.c:2309)
[    0.611365][    T1]  ? sb_notify_work (drivers/acpi/bus.c:1142)
[    0.611368][    T1]  acpi_dev_for_one_check (drivers/acpi/bus.c:1146)
[    0.611371][    T1]  device_for_each_child (drivers/base/core.c:4017)
[    0.611378][    T1]  acpi_dev_for_each_child (drivers/acpi/bus.c:1158)
[    0.611381][    T1]  ? get_acpi_device (drivers/acpi/scan.c:2274)
[    0.611384][    T1]  acpi_bus_attach (drivers/acpi/scan.c:2331)
[    0.611389][    T1]  ? klist_next (lib/klist.c:403)
[    0.611392][    T1]  ? sb_notify_work (drivers/acpi/bus.c:1142)
[    0.611396][    T1]  acpi_dev_for_one_check (drivers/acpi/bus.c:1146)
[    0.611398][    T1]  device_for_each_child (drivers/base/core.c:4017)
[    0.611404][    T1]  acpi_dev_for_each_child (drivers/acpi/bus.c:1158)
[    0.611406][    T1]  ? get_acpi_device (drivers/acpi/scan.c:2274)
[    0.611410][    T1]  acpi_bus_attach (drivers/acpi/scan.c:2331)
[    0.611416][    T1]  acpi_bus_scan (drivers/acpi/scan.c:2541 drivers/acpi/scan.c:2614)
[    0.611422][    T1]  acpi_scan_init (drivers/acpi/scan.c:2748 (discriminator 1))
[    0.611425][    T1]  ? acpi_viot_early_init (drivers/acpi/viot.c:263)
[    0.611429][    T1]  acpi_init (drivers/acpi/bus.c:1470)
[    0.611431][    T1]  ? acpi_arch_init+0x4/0x4
[    0.611433][    T1]  ? acpi_arch_init+0x4/0x4
[    0.611435][    T1]  do_one_initcall (init/main.c:1283)
[    0.611444][    T1]  ? do_initcalls (init/main.c:1343 init/main.c:1361)
[    0.611449][    T1]  do_initcalls (init/main.c:1344 (discriminator 3) init/main.c:1361 (discriminator 3))
[    0.611454][    T1]  kernel_init_freeable (init/main.c:1597)
[    0.611457][    T1]  ? rest_init (init/main.c:1475)
[    0.611461][    T1]  kernel_init (init/main.c:1485)
[    0.611464][    T1]  ret_from_fork (arch/x86/kernel/process.c:164)
[    0.611466][    T1]  ? rest_init (init/main.c:1475)
[    0.611470][    T1]  ret_from_fork_asm (arch/x86/entry/entry_32.S:737)
[    0.611473][    T1]  entry_INT80_32 (arch/x86/entry/entry_32.S:945)


The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20251020/202510201616.6e6b62a1-lkp@intel.com



-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] kernel: resourse: Add conditional handling for ACPI device
Posted by Andy Shevchenko 3 months, 3 weeks ago
On Mon, Oct 20, 2025 at 04:46:04PM +0800, kernel test robot wrote:
> 
> kernel test robot noticed "BUG:sleeping_function_called_from_invalid_context_at_include/linux/sched/mm.h" on:
> 
> commit: 871e73eea694be4705a5e3ebc9119e6c76c7b246 ("[PATCH] kernel: resourse: Add conditional handling for ACPI device")
> url: https://github.com/intel-lab-lkp/linux/commits/Szuying-Chen/kernel-resourse-Add-conditional-handling-for-ACPI-device/20251017-103749
> base: https://git.kernel.org/cgit/linux/kernel/git/akpm/mm.git mm-everything
> patch link: https://lore.kernel.org/all/20251017023531.5616-1-Chloe_Chen@asmedia.com.tw/
> patch subject: [PATCH] kernel: resourse: Add conditional handling for ACPI device
> 
> in testcase: boot
> 
> config: i386-randconfig-141-20251019
> compiler: gcc-14
> test machine: qemu-system-i386 -enable-kvm -cpu SandyBridge -smp 2 -m 4G

> +-------------------------------------------------------------------------------+------------+------------+
> |                                                                               | 4d30e94233 | 871e73eea6 |
> +-------------------------------------------------------------------------------+------------+------------+
> | BUG:sleeping_function_called_from_invalid_context_at_include/linux/sched/mm.h | 0          | 12         |
> +-------------------------------------------------------------------------------+------------+------------+

Thanks, absolutely NAK to the patch based on this report and my previous comment.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH] kernel: resourse: Add conditional handling for ACPI device
Posted by Andy Shevchenko 3 months, 3 weeks ago
On Fri, Oct 17, 2025 at 10:35:31AM +0800, Szuying Chen wrote:
> To avoid address conflicts and related errors, specific checks for
> the ACPI device "AMDIF031" should be bypassed.

TL;DR: NAK.

No, this is not how we should do the quirks (besides the use of CamelCase).
Also, please provide more info why firmware may not be fixed properly at
the same time, so we won't need this on an updated version?

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH] kernel: resourse: Add conditional handling for ACPI device
Posted by Szuying Chen 3 months, 2 weeks ago
On Sun, Oct 19, 2025 at 03:07AM, Andy Shevchenko wrote:
> On Fri, Oct 17, 2025 at 10:35:31AM +0800, Szuying Chen wrote:
> > To avoid address conflicts and related errors, specific checks for
> > the ACPI device "AMDIF031" should be bypassed.
> 
> TL;DR: NAK.
> 
> No, this is not how we should do the quirks (besides the use of CamelCase).
> Also, please provide more info why firmware may not be fixed properly at
> the same time, so we won't need this on an updated version?
> 
> -- 
> With Best Regards,
> Andy Shevchenko

The ACPI device AMDIF031 is a virtual (non-PCI) device located on the PCI
upstream port. Its memory resource is assigned by the BIOS within the bridge
windows of the PCI upstream port.

When the kernel creates ACPI/AMDIF031 and verifies memory resources, it may
detect an address conflict between AMDIF031 and the PCI upstream port. The
kernel then attempts to reassign resources for the PCI upstream port tree,
causing AMDIF031's memory resource to fall outside the bridge windows. This
makes the device inaccessible.

To prevent this and allow AMDIF031 to use the BIOS-assigned memory range,
skip resource reallocation when an address conflict is detected for this 
device.

Thanks
Chloe
Re: [PATCH] kernel: resourse: Add conditional handling for ACPI device
Posted by Andy Shevchenko 3 months, 2 weeks ago
On Thu, Oct 23, 2025 at 04:04:55PM +0800, Szuying Chen wrote:
> On Sun, Oct 19, 2025 at 03:07AM, Andy Shevchenko wrote:
> > On Fri, Oct 17, 2025 at 10:35:31AM +0800, Szuying Chen wrote:
> > > To avoid address conflicts and related errors, specific checks for
> > > the ACPI device "AMDIF031" should be bypassed.
> > 
> > TL;DR: NAK.
> > 
> > No, this is not how we should do the quirks (besides the use of CamelCase).
> > Also, please provide more info why firmware may not be fixed properly at
> > the same time, so we won't need this on an updated version?
> 
> The ACPI device AMDIF031 is a virtual (non-PCI) device located on the PCI
> upstream port. Its memory resource is assigned by the BIOS within the bridge
> windows of the PCI upstream port.
> 
> When the kernel creates ACPI/AMDIF031 and verifies memory resources, it may
> detect an address conflict between AMDIF031 and the PCI upstream port. The
> kernel then attempts to reassign resources for the PCI upstream port tree,
> causing AMDIF031's memory resource to fall outside the bridge windows. This
> makes the device inaccessible.
> 
> To prevent this and allow AMDIF031 to use the BIOS-assigned memory range,
> skip resource reallocation when an address conflict is detected for this 
> device.

We have such devices in many platforms, older ones use MFD framework with
specific flag set, you may check how it's done there. But for this change is
definitely NAK, take your time to find proper solution (see above for the
hint).

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH] kernel: resourse: Add conditional handling for ACPI device
Posted by Gregory Price 3 months, 3 weeks ago
On Fri, Oct 17, 2025 at 10:35:31AM +0800, Szuying Chen wrote:
> To avoid address conflicts and related errors, specific checks for
> the ACPI device "AMDIF031" should be bypassed.
> 
> Signed-off-by: Szuying Chen <Chloe_Chen@asmedia.com.tw>
> ---
>  kernel/resource.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/kernel/resource.c b/kernel/resource.c
> index b9fa2a4ce089..9ffcd5bdb62e 100644
> --- a/kernel/resource.c
> +++ b/kernel/resource.c
> @@ -177,6 +177,27 @@ static struct resource *alloc_resource(gfp_t flags)
>  	return kzalloc(sizeof(struct resource), flags);
>  }
> 
> +static int IgnoreResource(struct resource *tmp)
> +{
> +	char *pt, *name_sep;
> +	char *name;
> +
> +	pt = kstrdup(tmp->name, GFP_KERNEL);
> +	name_sep = pt;
> +	if (!name_sep)
> +		goto out;
> +
> +	name = strsep(&name_sep, ":");
> +	if (strcmp(name, "AMDIF031") == 0) {
> +		kfree(pt);
> +		return 1;
> +	}

Assuming we actually want this, i think we probably need to put this in
an arch/ extension, not hard-coded into kernel/.  There's no need for
non-x86 platforms to ever touch this.

> +
> +out:
> +	kfree(pt);
> +	return 0;
> +}
> +
>  /* Return the conflict entry if you can't request it */
>  static struct resource * __request_resource(struct resource *root, struct resource *new)
>  {
> @@ -202,6 +223,8 @@ static struct resource * __request_resource(struct resource *root, struct resour
>  		p = &tmp->sibling;
>  		if (tmp->end < start)
>  			continue;
> +		if (IgnoreResource(tmp))
> +			continue;
>  		return tmp;
>  	}
>  }
> --
> 2.39.2
>