Skip to contentSkip to conversation

Fix most ImgU driver compiler / checker warnings

PATCH In review Sakari Ailus 3 participants 9 messages Mar 1, 2019 – Apr 16, 2020

Subsystems (3)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

v2 cover Fix most ImgU driver compiler / checker warnings

Hi Mauro, Hans,

This set addresses most of the compiler / checker warnings from the ImgU driver. There are a few about stack usage from the compiler left but those were not trivial to address so I postponed that. There are also a few about memset but Hans suggested addressing that by increasing the maximum size. I guess it wouldn't benefit anyone to split those memsets into two...

since v2:

- Drop __attribute__((aligned())) -> __aligned() change for now

- Align awb_fr field in struct ipu3_uapi_acc_param

- Add Raj's Tested-by: tag

Sakari Ailus (4):
staging: imgu: Address a compiler warning on alignment
staging: imgu: Remove redundant checks
staging: imgu: Address compiler / checker warnings in MMU code Revert "media: ipu3: shut up warnings produced with W=1"

 drivers/staging/media/ipu3/Makefile             |  6 ----
 drivers/staging/media/ipu3/TODO                 |  2 --
 drivers/staging/media/ipu3/include/intel-ipu3.h |  2 +-
 drivers/staging/media/ipu3/ipu3-css-fw.c        |  6 ++--
 drivers/staging/media/ipu3/ipu3-mmu.c           | 39 ++++++++++++++++++++++---
 5 files changed, 38 insertions(+), 17 deletions(-)
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH v2 1/4 staging: imgu: Address a compiler warning on alignment

Address a compiler warnings on alignment of struct ipu3_uapi_awb_fr_config_s by adding __attribute__((aligned(32))) to a struct member of that type as well.

---
 drivers/staging/media/ipu3/include/intel-ipu3.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/ipu3/include/intel-ipu3.h +1 -1
index eb6f52aca9929..4a0e97b0cfd2b 100644
@@ -2472,7 +2472,7 @@ struct ipu3_uapi_acc_param {
 	struct ipu3_uapi_yuvp1_yds_config yds2 __attribute__((aligned(32)));
 	struct ipu3_uapi_yuvp2_tcc_static_config tcc __attribute__((aligned(32)));
 	struct ipu3_uapi_anr_config anr;
-	struct ipu3_uapi_awb_fr_config_s awb_fr;
+	struct ipu3_uapi_awb_fr_config_s awb_fr __attribute__((aligned(32)));
 	struct ipu3_uapi_ae_config ae;
 	struct ipu3_uapi_af_config_s af;
 	struct ipu3_uapi_awb_config awb;
Signature · 1 line
2.11.0
#2 lore raw

Re: [PATCH v2 1/4] staging: imgu: Address a compiler warning on alignment

Hi Sakari,

Quoted 4 lines · Sakari Ailus

Address a compiler warnings on alignment of struct ipu3_uapi_awb_fr_config_s by adding __attribute__((aligned(32))) to a struct member of that type as well.

Sorry, just noticed there was a v2.

This is how we momentary worked it around in libcamera, so my tag on v1 also applies here too :)

Could I know why this is preferred compared to v1? Has the field to be actually 32 bytes aligned?

Thanks
j

Quoted 22 lines
---
 drivers/staging/media/ipu3/include/intel-ipu3.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/ipu3/include/intel-ipu3.h +1 -2
index eb6f52aca9929..4a0e97b0cfd2b 100644
@@ -2472,7 +2472,7 @@ struct ipu3_uapi_acc_param {
 	struct ipu3_uapi_yuvp1_yds_config yds2 __attribute__((aligned(32)));
 	struct ipu3_uapi_yuvp2_tcc_static_config tcc __attribute__((aligned(32)));
 	struct ipu3_uapi_anr_config anr;
-	struct ipu3_uapi_awb_fr_config_s awb_fr;
+	struct ipu3_uapi_awb_fr_config_s awb_fr __attribute__((aligned(32)));
 	struct ipu3_uapi_ae_config ae;
 	struct ipu3_uapi_af_config_s af;
 	struct ipu3_uapi_awb_config awb;
--

2.11.0

author maintainer
#3 lore raw

Re: [PATCH v2 1/4] staging: imgu: Address a compiler warning on alignment

Hi Jacopo,

Quoted 8 lines · Jacopo Mondi

Hi Sakari,

Quoted 4 lines · Sakari Ailus

Address a compiler warnings on alignment of struct ipu3_uapi_awb_fr_config_s by adding __attribute__((aligned(32))) to a struct member of that type as well.

Quoted 7 lines

Sorry, just noticed there was a v2.

This is how we momentary worked it around in libcamera, so my tag on v1 also applies here too :)

Could I know why this is preferred compared to v1? Has the field to be actually 32 bytes aligned?

Not because of IPU3 DMA, but to maintain ABI compatibility. Technically there's no strict need to do that as this is a staging driver. This patch simply fixes the warning. Later on it'd be good to remove the alignment where they are unnecessary.

Signature · 4 lines
Regards,

Sakari Ailus
[email protected]
#4 lore raw

Re: [PATCH v2 1/4] staging: imgu: Address a compiler warning on alignment

In reply to Sakari Ailus

Hi Sakari,

Quoted 25 lines · Sakari Ailus

Address a compiler warnings on alignment of struct ipu3_uapi_awb_fr_config_s by adding __attribute__((aligned(32))) to a struct member of that type as well.

---
 drivers/staging/media/ipu3/include/intel-ipu3.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/ipu3/include/intel-ipu3.h +1 -2
index eb6f52aca9929..4a0e97b0cfd2b 100644
@@ -2472,7 +2472,7 @@ struct ipu3_uapi_acc_param {
        struct ipu3_uapi_yuvp1_yds_config yds2 __attribute__((aligned(32)));
        struct ipu3_uapi_yuvp2_tcc_static_config tcc __attribute__((aligned(32)));
        struct ipu3_uapi_anr_config anr;
-       struct ipu3_uapi_awb_fr_config_s awb_fr;
+       struct ipu3_uapi_awb_fr_config_s awb_fr __attribute__((aligned(32)));
        struct ipu3_uapi_ae_config ae;
        struct ipu3_uapi_af_config_s af;
        struct ipu3_uapi_awb_config awb;
--
Quoted 2 lines

2.11.0

I don't know how this patch was tested, but for me it breaks the layout of the ipu3_uapi_acc_param struct. The result is that awb_fr is moved from offset 37656 to 36768 and so everything else is shifted too. The end result is "set parameters failed" when the userspace tries to queue a parameter buffer.

To be honest, I don't like how alignments are used to define the ABI layout. Since these are definitions specified by the IMGU firmware, I'd suggest removing any compiler alignments, making all the structs packed and adding explicit padding in terms of u8 arrays, which is the proper way to enforce a specific binary layout.

Following is the relevant snippet from a diff of pahole output before and after this patch:

pahole.bad 2020-04-11 16:29:48.513110117 +0000 renamed from pahole.good 2020-04-11 16:40:18.706133867 +0000 +1 -2
@@ -7353,29 +7349,27 @@ // struct ipu3_uapi_acc_param {
        struct ipu3_uapi_anr_config anr;                 /* 36020   736 */
 
        /* XXX last struct has 24 bytes of padding */
+       /* XXX 12 bytes hole, try to pack */
 
-       /* --- cacheline 574 boundary (36736 bytes) was 20 bytes ago --- */
-       struct ipu3_uapi_awb_fr_config_s awb_fr

__attribute__((__aligned__(32))); /* 36756 32 */

-       struct ipu3_uapi_ae_config ae;                   /* 36788   480 */
+       /* --- cacheline 574 boundary (36736 bytes) was 32 bytes ago --- */
+       struct ipu3_uapi_awb_fr_config_s awb_fr

__attribute__((__aligned__(32))); /* 36768 32 */
+ /* --- cacheline 575 boundary (36800 bytes) --- */
+ struct ipu3_uapi_ae_config ae; /* 36800 480 */

        /* XXX last struct has 24 bytes of padding */
-       /* --- cacheline 582 boundary (37248 bytes) was 20 bytes ago --- */
-       struct ipu3_uapi_af_config_s af;                 /* 37268    96 */
+       /* --- cacheline 582 boundary (37248 bytes) was 32 bytes ago --- */
+       struct ipu3_uapi_af_config_s af;                 /* 37280    96 */
        /* XXX last struct has 20 bytes of padding */

- /* --- cacheline 583 boundary (37312 bytes) was 52 bytes ago --- */
- struct ipu3_uapi_awb_config awb; /* 37364 32 */
-

-       /* Force padding: */
-       struct ipu3_uapi_awb_config :256;
+       /* --- cacheline 584 boundary (37376 bytes) --- */
+       struct ipu3_uapi_awb_config awb;                 /* 37376    32 */
        /* size: 37408, cachelines: 585, members: 21 */
-       /* sum members: 37152, holes: 13, sum holes: 244 */
-       /* padding: 12 */
+       /* sum members: 37152, holes: 14, sum holes: 256 */
        /* paddings: 3, sum paddings: 68 */
-       /* forced alignments: 16, forced holes: 13, sum forced holes: 244 */
+       /* forced alignments: 16, forced holes: 14, sum forced holes: 256 */
        /* last cacheline: 32 bytes */

};

Best regards,
Tomasz

author maintainer
#5 lore raw

Re: [PATCH v2 1/4] staging: imgu: Address a compiler warning on alignment

Hi Tomasz,

Quoted 29 lines · Tomasz Figa

Hi Sakari,

Quoted 25 lines · Sakari Ailus

Address a compiler warnings on alignment of struct ipu3_uapi_awb_fr_config_s by adding __attribute__((aligned(32))) to a struct member of that type as well.

---
 drivers/staging/media/ipu3/include/intel-ipu3.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/ipu3/include/intel-ipu3.h +1 -2
index eb6f52aca9929..4a0e97b0cfd2b 100644
@@ -2472,7 +2472,7 @@ struct ipu3_uapi_acc_param {
        struct ipu3_uapi_yuvp1_yds_config yds2 __attribute__((aligned(32)));
        struct ipu3_uapi_yuvp2_tcc_static_config tcc __attribute__((aligned(32)));
        struct ipu3_uapi_anr_config anr;
-       struct ipu3_uapi_awb_fr_config_s awb_fr;
+       struct ipu3_uapi_awb_fr_config_s awb_fr __attribute__((aligned(32)));
        struct ipu3_uapi_ae_config ae;
        struct ipu3_uapi_af_config_s af;
        struct ipu3_uapi_awb_config awb;
--
Quoted 8 lines
Quoted 2 lines

2.11.0

I don't know how this patch was tested, but for me it breaks the layout of the ipu3_uapi_acc_param struct. The result is that awb_fr is moved from offset 37656 to 36768 and so everything else is shifted too. The end result is "set parameters failed" when the userspace tries to queue a parameter buffer.

Thanks for reporting this.

Unlike recent patches touching the struct, I didn't test (obviously) this one with pahole.

Quoted 6 lines

To be honest, I don't like how alignments are used to define the ABI layout. Since these are definitions specified by the IMGU firmware, I'd suggest removing any compiler alignments, making all the structs packed and adding explicit padding in terms of u8 arrays, which is the proper way to enforce a specific binary layout.

The current use of __aligned(32) with __packed especially makes this cumbersome and risky. __packed alone is necessary.

I'll send patches to address the alignment issue; converting to use reserved fields would be quite a bit more work.

Similar changes should be done to ipu3-abi.h as well, but it appears to have been less problematic so far.

Quoted 49 lines

Following is the relevant snippet from a diff of pahole output before and after this patch:

pahole.bad 2020-04-11 16:29:48.513110117 +0000 renamed from pahole.good 2020-04-11 16:40:18.706133867 +0000 +1 -2
@@ -7353,29 +7349,27 @@ // struct ipu3_uapi_acc_param {
        struct ipu3_uapi_anr_config anr;                 /* 36020   736 */
 
        /* XXX last struct has 24 bytes of padding */
+       /* XXX 12 bytes hole, try to pack */
 
-       /* --- cacheline 574 boundary (36736 bytes) was 20 bytes ago --- */
-       struct ipu3_uapi_awb_fr_config_s awb_fr

__attribute__((__aligned__(32))); /* 36756 32 */

pahole.bad 2020-04-11 16:29:48.513110117 +0000 renamed from pahole.good 2020-04-11 16:40:18.706133867 +0000 +2 -1
-       struct ipu3_uapi_ae_config ae;                   /* 36788   480 */
+       /* --- cacheline 574 boundary (36736 bytes) was 32 bytes ago --- */
+       struct ipu3_uapi_awb_fr_config_s awb_fr

__attribute__((__aligned__(32))); /* 36768 32 */

pahole.bad 2020-04-11 16:29:48.513110117 +0000 renamed from pahole.good 2020-04-11 16:40:18.706133867 +0000 +8 -10
+       /* --- cacheline 575 boundary (36800 bytes) --- */
+       struct ipu3_uapi_ae_config ae;                   /* 36800   480 */
 
        /* XXX last struct has 24 bytes of padding */
 
-       /* --- cacheline 582 boundary (37248 bytes) was 20 bytes ago --- */
-       struct ipu3_uapi_af_config_s af;                 /* 37268    96 */
+       /* --- cacheline 582 boundary (37248 bytes) was 32 bytes ago --- */
+       struct ipu3_uapi_af_config_s af;                 /* 37280    96 */
 
        /* XXX last struct has 20 bytes of padding */
 
-       /* --- cacheline 583 boundary (37312 bytes) was 52 bytes ago --- */
-       struct ipu3_uapi_awb_config awb;                 /* 37364    32 */
-
-       /* Force padding: */
-       struct ipu3_uapi_awb_config :256;
+       /* --- cacheline 584 boundary (37376 bytes) --- */
+       struct ipu3_uapi_awb_config awb;                 /* 37376    32 */
 
        /* size: 37408, cachelines: 585, members: 21 */
-       /* sum members: 37152, holes: 13, sum holes: 244 */
-       /* padding: 12 */
+       /* sum members: 37152, holes: 14, sum holes: 256 */
        /* paddings: 3, sum paddings: 68 */
-       /* forced alignments: 16, forced holes: 13, sum forced holes: 244 */
+       /* forced alignments: 16, forced holes: 14, sum forced holes: 256 */
        /* last cacheline: 32 bytes */
 };
Signature · 3 lines
Regards,

Sakari Ailus
author maintainer
#6 lore raw

PATCH v2 2/4 staging: imgu: Remove redundant checks

In reply to Sakari Ailus

Remove redundant checks for less than zero on unsigned variables.

---
 drivers/staging/media/ipu3/ipu3-css-fw.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/media/ipu3/ipu3-css-fw.c +2 -4
index 4122d4e42db6c..45aff76198e2c 100644
@@ -200,13 +200,11 @@ int imgu_css_fw_init(struct imgu_css *css)
 			goto bad_fw;
 
 		for (j = 0; j < bi->info.isp.num_output_formats; j++)
-			if (bi->info.isp.output_formats[j] < 0 ||
-			    bi->info.isp.output_formats[j] >=
+			if (bi->info.isp.output_formats[j] >=
 			    IMGU_ABI_FRAME_FORMAT_NUM)
 				goto bad_fw;
 		for (j = 0; j < bi->info.isp.num_vf_formats; j++)
-			if (bi->info.isp.vf_formats[j] < 0 ||
-			    bi->info.isp.vf_formats[j] >=
+			if (bi->info.isp.vf_formats[j] >=
 			    IMGU_ABI_FRAME_FORMAT_NUM)
 				goto bad_fw;
 
Signature · 1 line
2.11.0
author maintainer
#7 lore raw

PATCH v2 3/4 staging: imgu: Address compiler / checker warnings in MMU code

In reply to Sakari Ailus

Address C compiler, sparse and smatch warnings and little style issues in the IMGU MMU code.

---
 drivers/staging/media/ipu3/ipu3-mmu.c | 39 +++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)
drivers/staging/media/ipu3/ipu3-mmu.c +35 -4
index cfc2bdfb14b33..a55ff39be1882 100644
@@ -275,7 +275,17 @@ static size_t imgu_mmu_pgsize(unsigned long pgsize_bitmap,
 	return pgsize;
 }
 
-/* drivers/iommu/iommu.c/iommu_map() */
+/**
+ * imgu_mmu_map - map a buffer to a physical address
+ *
+ * @info: MMU mappable range
+ * @iova: the virtual address
+ * @paddr: the physical address
+ * @size: length of the mappable area
+ *
+ * The function has been adapted from iommu_map() in
+ * drivers/iommu/iommu.c .
+ */
 int imgu_mmu_map(struct imgu_mmu_info *info, unsigned long iova,
 		 phys_addr_t paddr, size_t size)
 {
@@ -321,7 +331,17 @@ int imgu_mmu_map(struct imgu_mmu_info *info, unsigned long iova,
 	return ret;
 }
 
-/* drivers/iommu/iommu.c/default_iommu_map_sg() */
+/**
+ * imgu_mmu_map_sg - Map a scatterlist
+ *
+ * @info: MMU mappable range
+ * @iova: the virtual address
+ * @sg: the scatterlist to map
+ * @nents: number of entries in the scatterlist
+ *
+ * The function has been adapted from default_iommu_map_sg() in
+ * drivers/iommu/iommu.c .
+ */
 size_t imgu_mmu_map_sg(struct imgu_mmu_info *info, unsigned long iova,
 		       struct scatterlist *sg, unsigned int nents)
 {
@@ -394,7 +414,16 @@ static size_t __imgu_mmu_unmap(struct imgu_mmu *mmu,
 	return unmap;
 }
 
-/* drivers/iommu/iommu.c/iommu_unmap() */
+/**
+ * imgu_mmu_unmap - Unmap a buffer
+ *
+ * @info: MMU mappable range
+ * @iova: the virtual address
+ * @size: the length of the buffer
+ *
+ * The function has been adapted from iommu_unmap() in
+ * drivers/iommu/iommu.c .
+ */
 size_t imgu_mmu_unmap(struct imgu_mmu_info *info, unsigned long iova,
 		      size_t size)
 {
@@ -444,6 +473,7 @@ size_t imgu_mmu_unmap(struct imgu_mmu_info *info, unsigned long iova,
 
 /**
  * imgu_mmu_init() - initialize IPU3 MMU block
+ *
  * @parent:	struct device parent
  * @base:	IOMEM base of hardware registers.
  *
@@ -523,7 +553,8 @@ struct imgu_mmu_info *imgu_mmu_init(struct device *parent, void __iomem *base)
 
 /**
  * imgu_mmu_exit() - clean up IPU3 MMU block
- * @info: IPU3 MMU private data
+ *
+ * @info: MMU mappable range
  */
 void imgu_mmu_exit(struct imgu_mmu_info *info)
 {
Signature · 1 line
2.11.0
author maintainer
#8 lore raw

PATCH v2 4/4 Revert "media: ipu3: shut up warnings produced with W=1"

In reply to Sakari Ailus

This reverts commit 0bdfc56c13c0ffe003f28395fcde2cd9b5ea0622.

The original patch suppressed compiler and checker warnings and those warnings have been addressed. Do not attempt to suppress these warnings anymore.

---
 drivers/staging/media/ipu3/Makefile | 6 ------
 drivers/staging/media/ipu3/TODO     | 2 --
 2 files changed, 8 deletions(-)
drivers/staging/media/ipu3/Makefile +0 -6
index fa7fa3372bcbe..fb146d178bd4b 100644
@@ -9,9 +9,3 @@ ipu3-imgu-objs += \
 		ipu3-css.o ipu3-v4l2.o ipu3.o
 
 obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3-imgu.o
-
-# HACK! While this driver is in bad shape, don't enable several warnings
-#       that would be otherwise enabled with W=1
-ccflags-y += $(call cc-disable-warning, packed-not-aligned)
-ccflags-y += $(call cc-disable-warning, type-limits)
-ccflags-y += $(call cc-disable-warning, unused-const-variable)
drivers/staging/media/ipu3/TODO +0 -2
index 5e55baeaea1a3..8b95e74e43a0f 100644
@@ -27,5 +27,3 @@ staging directory.
 - Document different operation modes, and which buffer queues are relevant
   in each mode. To process an image, which queues require a buffer an in
   which ones is it optional?
-
-- Make sure it builds fine with no warnings with W=1
Signature · 1 line
2.11.0