Re: [PATCH v2] iommu/vt-d: Make DMAR_UNITS_SUPPORTED a config setting

From: Steve Wahl
Date: Thu May 12 2022 - 19:12:54 EST


On Thu, May 12, 2022 at 10:13:09AM -0500, Steve Wahl wrote:
> To support up to 64 sockets with 10 DMAR units each (640), make the
> value of DMAR_UNITS_SUPPORTED adjustable by a config variable,
> CONFIG_DMAR_UNITS_SUPPORTED, and make it's default 1024 when MAXSMP is
> set.
>
> If the available hardware exceeds DMAR_UNITS_SUPPORTED (previously set
> to MAX_IO_APICS, or 128), it causes these messages: "DMAR: Failed to
> allocate seq_id", "DMAR: Parse DMAR table failure.", and "x2apic: IRQ
> remapping doesn't support X2APIC mode x2apic disabled"; and the system
> fails to boot properly.
>
> Signed-off-by: Steve Wahl <steve.wahl@xxxxxxx>

I've received a report from the kernel test robot <lkp@xxxxxxxxx>,
that this patch causes an error (shown below) when
CONFIG_IOMMU_SUPPORT is not set.

In my opinion, this is because include/linux/dmar.h and
include/linux/intel-iommu are being #included when they are not really
being used.

I've tried placing the contents of intel-iommu.h within an #ifdef
CONFIG_INTEL_IOMMU, and that fixes the problem.

Two questions:

A) Is this the desired approach to to the fix?

B) Should it be a separate patch, or added onto this patch as a v3?

Error message: ------------------------------

In file included from include/linux/intel-iommu.h:21,
from arch/x86/kvm/x86.c:44:
>> include/linux/dmar.h:21:33: error: 'CONFIG_DMAR_UNITS_SUPPORTED' undeclared here (not in a function); did you mean 'DMAR_UNITS_SUPPORTED'?
21 | #define DMAR_UNITS_SUPPORTED CONFIG_DMAR_UNITS_SUPPORTED
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/intel-iommu.h:531:35: note: in expansion of macro 'DMAR_UNITS_SUPPORTED'
531 | unsigned int iommu_refcnt[DMAR_UNITS_SUPPORTED];
| ^~~~~~~~~~~~~~~~~~~~


vim +21 include/linux/dmar.h

20
> 21 #define DMAR_UNITS_SUPPORTED CONFIG_DMAR_UNITS_SUPPORTED
22

Initial stab at fixing it: ------------------------------

diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index 2f9891cb3d00..916fd7b5bcb5 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -10,6 +10,8 @@
#ifndef _INTEL_IOMMU_H_
#define _INTEL_IOMMU_H_

+#ifdef CONFIG_INTEL_IOMMU
+
#include <linux/types.h>
#include <linux/iova.h>
#include <linux/io.h>
@@ -831,4 +833,6 @@ static inline const char *decode_prq_descriptor(char *str, size_t size,
return str;
}

+#endif /* CONFIG_IOMMU_SUPPORT */
+
#endif


Thanks.

--> Steve Wahl


--
Steve Wahl, Hewlett Packard Enterprise