diff mbox series

dmaengine: dw-edma: Check MSI descriptor before copying

Message ID 1587406568-26592-1-git-send-email-alan.mikhak@sifive.com (mailing list archive)
State Superseded, archived
Headers show
Series dmaengine: dw-edma: Check MSI descriptor before copying | expand

Commit Message

Alan Mikhak April 20, 2020, 6:16 p.m. UTC
From: Alan Mikhak <alan.mikhak@sifive.com>

Modify dw_edma_irq_request() to check if a struct msi_desc entry exists
before copying the contents of its struct msi_msg pointer.

Without this sanity check, __get_cached_msi_msg() crashes when invoked by
dw_edma_irq_request() running on a Linux-based PCIe endpoint device. MSI
interrupt are not received by PCIe endpoint devices. If irq_get_msi_desc()
returns null, then there is no cached struct msi_msg to be copied.

This patch depends on the following patch:
[PATCH v2] dmaengine: dw-edma: Decouple dw-edma-core.c from struct pci_dev
https://patchwork.kernel.org/patch/11491757/

Signed-off-by: Alan Mikhak <alan.mikhak@sifive.com>
---
 drivers/dma/dw-edma/dw-edma-core.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Comments

kernel test robot April 22, 2020, 9:01 p.m. UTC | #1
Hi Alan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on slave-dma/next]
[also build test WARNING on next-20200421]
[cannot apply to linus/master linux/master v5.7-rc2]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Alan-Mikhak/dmaengine-dw-edma-Check-MSI-descriptor-before-copying/20200422-131121
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/slave-dma.git next
config: x86_64-randconfig-f003-20200422 (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from include/linux/export.h:43:0,
                    from include/linux/linkage.h:7,
                    from include/linux/kernel.h:8,
                    from include/linux/list.h:9,
                    from include/linux/module.h:12,
                    from drivers/dma/dw-edma/dw-edma-core.c:9:
   drivers/dma/dw-edma/dw-edma-core.c: In function 'dw_edma_irq_request':
   drivers/dma/dw-edma/dw-edma-core.c:793:7: error: implicit declaration of function 'irq_get_msi_desc'; did you mean 'irq_to_desc'? [-Werror=implicit-function-declaration]
      if (irq_get_msi_desc(irq))
          ^
   include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
    #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                       ^~~~
>> drivers/dma/dw-edma/dw-edma-core.c:793:3: note: in expansion of macro 'if'
      if (irq_get_msi_desc(irq))
      ^~
   cc1: some warnings being treated as errors

vim +/if +793 drivers/dma/dw-edma/dw-edma-core.c

   766	
   767	static int dw_edma_irq_request(struct dw_edma_chip *chip,
   768				       u32 *wr_alloc, u32 *rd_alloc)
   769	{
   770		struct device *dev = chip->dev;
   771		struct dw_edma *dw = chip->dw;
   772		u32 wr_mask = 1;
   773		u32 rd_mask = 1;
   774		int i, err = 0;
   775		u32 ch_cnt;
   776		int irq;
   777	
   778		ch_cnt = dw->wr_ch_cnt + dw->rd_ch_cnt;
   779	
   780		if (dw->nr_irqs < 1)
   781			return -EINVAL;
   782	
   783		if (dw->nr_irqs == 1) {
   784			/* Common IRQ shared among all channels */
   785			irq = dw->ops->irq_vector(dev, 0);
   786			err = request_irq(irq, dw_edma_interrupt_common,
   787					  IRQF_SHARED, dw->name, &dw->irq[0]);
   788			if (err) {
   789				dw->nr_irqs = 0;
   790				return err;
   791			}
   792	
 > 793			if (irq_get_msi_desc(irq))
   794				get_cached_msi_msg(irq, &dw->irq[0].msi);
   795		} else {
   796			/* Distribute IRQs equally among all channels */
   797			int tmp = dw->nr_irqs;
   798	
   799			while (tmp && (*wr_alloc + *rd_alloc) < ch_cnt) {
   800				dw_edma_dec_irq_alloc(&tmp, wr_alloc, dw->wr_ch_cnt);
   801				dw_edma_dec_irq_alloc(&tmp, rd_alloc, dw->rd_ch_cnt);
   802			}
   803	
   804			dw_edma_add_irq_mask(&wr_mask, *wr_alloc, dw->wr_ch_cnt);
   805			dw_edma_add_irq_mask(&rd_mask, *rd_alloc, dw->rd_ch_cnt);
   806	
   807			for (i = 0; i < (*wr_alloc + *rd_alloc); i++) {
   808				irq = dw->ops->irq_vector(dev, i);
   809				err = request_irq(irq,
   810						  i < *wr_alloc ?
   811							dw_edma_interrupt_write :
   812							dw_edma_interrupt_read,
   813						  IRQF_SHARED, dw->name,
   814						  &dw->irq[i]);
   815				if (err) {
   816					dw->nr_irqs = i;
   817					return err;
   818				}
   819	
   820				if (irq_get_msi_desc(irq))
   821					get_cached_msi_msg(irq, &dw->irq[i].msi);
   822			}
   823	
   824			dw->nr_irqs = i;
   825		}
   826	
   827		return err;
   828	}
   829	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot April 22, 2020, 10:38 p.m. UTC | #2
Hi Alan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on slave-dma/next]
[also build test ERROR on next-20200421]
[cannot apply to linus/master linux/master v5.7-rc2]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Alan-Mikhak/dmaengine-dw-edma-Check-MSI-descriptor-before-copying/20200422-131121
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/slave-dma.git next
config: s390-allmodconfig (attached as .config)
compiler: s390-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=s390 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/dma/dw-edma/dw-edma-core.c: In function 'dw_edma_irq_request':
>> drivers/dma/dw-edma/dw-edma-core.c:793:7: error: implicit declaration of function 'irq_get_msi_desc'; did you mean 'irq_to_desc'? [-Werror=implicit-function-declaration]
     793 |   if (irq_get_msi_desc(irq))
         |       ^~~~~~~~~~~~~~~~
         |       irq_to_desc
   cc1: some warnings being treated as errors

vim +793 drivers/dma/dw-edma/dw-edma-core.c

   766	
   767	static int dw_edma_irq_request(struct dw_edma_chip *chip,
   768				       u32 *wr_alloc, u32 *rd_alloc)
   769	{
   770		struct device *dev = chip->dev;
   771		struct dw_edma *dw = chip->dw;
   772		u32 wr_mask = 1;
   773		u32 rd_mask = 1;
   774		int i, err = 0;
   775		u32 ch_cnt;
   776		int irq;
   777	
   778		ch_cnt = dw->wr_ch_cnt + dw->rd_ch_cnt;
   779	
   780		if (dw->nr_irqs < 1)
   781			return -EINVAL;
   782	
   783		if (dw->nr_irqs == 1) {
   784			/* Common IRQ shared among all channels */
   785			irq = dw->ops->irq_vector(dev, 0);
   786			err = request_irq(irq, dw_edma_interrupt_common,
   787					  IRQF_SHARED, dw->name, &dw->irq[0]);
   788			if (err) {
   789				dw->nr_irqs = 0;
   790				return err;
   791			}
   792	
 > 793			if (irq_get_msi_desc(irq))
   794				get_cached_msi_msg(irq, &dw->irq[0].msi);
   795		} else {
   796			/* Distribute IRQs equally among all channels */
   797			int tmp = dw->nr_irqs;
   798	
   799			while (tmp && (*wr_alloc + *rd_alloc) < ch_cnt) {
   800				dw_edma_dec_irq_alloc(&tmp, wr_alloc, dw->wr_ch_cnt);
   801				dw_edma_dec_irq_alloc(&tmp, rd_alloc, dw->rd_ch_cnt);
   802			}
   803	
   804			dw_edma_add_irq_mask(&wr_mask, *wr_alloc, dw->wr_ch_cnt);
   805			dw_edma_add_irq_mask(&rd_mask, *rd_alloc, dw->rd_ch_cnt);
   806	
   807			for (i = 0; i < (*wr_alloc + *rd_alloc); i++) {
   808				irq = dw->ops->irq_vector(dev, i);
   809				err = request_irq(irq,
   810						  i < *wr_alloc ?
   811							dw_edma_interrupt_write :
   812							dw_edma_interrupt_read,
   813						  IRQF_SHARED, dw->name,
   814						  &dw->irq[i]);
   815				if (err) {
   816					dw->nr_irqs = i;
   817					return err;
   818				}
   819	
   820				if (irq_get_msi_desc(irq))
   821					get_cached_msi_msg(irq, &dw->irq[i].msi);
   822			}
   823	
   824			dw->nr_irqs = i;
   825		}
   826	
   827		return err;
   828	}
   829	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c
index db401eb11322..a5d15f6ed5eb 100644
--- a/drivers/dma/dw-edma/dw-edma-core.c
+++ b/drivers/dma/dw-edma/dw-edma-core.c
@@ -773,6 +773,7 @@  static int dw_edma_irq_request(struct dw_edma_chip *chip,
 	u32 rd_mask = 1;
 	int i, err = 0;
 	u32 ch_cnt;
+	int irq;
 
 	ch_cnt = dw->wr_ch_cnt + dw->rd_ch_cnt;
 
@@ -781,16 +782,16 @@  static int dw_edma_irq_request(struct dw_edma_chip *chip,
 
 	if (dw->nr_irqs == 1) {
 		/* Common IRQ shared among all channels */
-		err = request_irq(dw->ops->irq_vector(dev, 0),
-				  dw_edma_interrupt_common,
+		irq = dw->ops->irq_vector(dev, 0);
+		err = request_irq(irq, dw_edma_interrupt_common,
 				  IRQF_SHARED, dw->name, &dw->irq[0]);
 		if (err) {
 			dw->nr_irqs = 0;
 			return err;
 		}
 
-		get_cached_msi_msg(dw->ops->irq_vector(dev, 0),
-				   &dw->irq[0].msi);
+		if (irq_get_msi_desc(irq))
+			get_cached_msi_msg(irq, &dw->irq[0].msi);
 	} else {
 		/* Distribute IRQs equally among all channels */
 		int tmp = dw->nr_irqs;
@@ -804,7 +805,8 @@  static int dw_edma_irq_request(struct dw_edma_chip *chip,
 		dw_edma_add_irq_mask(&rd_mask, *rd_alloc, dw->rd_ch_cnt);
 
 		for (i = 0; i < (*wr_alloc + *rd_alloc); i++) {
-			err = request_irq(dw->ops->irq_vector(dev, i),
+			irq = dw->ops->irq_vector(dev, i);
+			err = request_irq(irq,
 					  i < *wr_alloc ?
 						dw_edma_interrupt_write :
 						dw_edma_interrupt_read,
@@ -815,8 +817,8 @@  static int dw_edma_irq_request(struct dw_edma_chip *chip,
 				return err;
 			}
 
-			get_cached_msi_msg(dw->ops->irq_vector(dev, i),
-					   &dw->irq[i].msi);
+			if (irq_get_msi_desc(irq))
+				get_cached_msi_msg(irq, &dw->irq[i].msi);
 		}
 
 		dw->nr_irqs = i;