raw/ioat: fix queue index calculation

Message ID 20201103144858.1317742-1-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series raw/ioat: fix queue index calculation |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/Intel-compilation fail Compilation issues

Commit Message

Bruce Richardson Nov. 3, 2020, 2:48 p.m. UTC
  Coverity flags a possible problem where the 8-bit wq_idx value may have
errors when shifted and sign-extended to 64-bits. Since this can only occur
if the shift index is larger than any expected value from hardware, it's
unlikely to cause any real problems, but we can eliminate any
possible errors, and the coverity issue, by explicitly typecasting
the uint8_t value to 64-bits before any shift operations occur.

Coverity issue: 363695
Fixes: a33969462135 ("raw/ioat: fix work-queue config size")

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/raw/ioat/idxd_pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Thomas Monjalon Nov. 3, 2020, 8:21 p.m. UTC | #1
03/11/2020 15:48, Bruce Richardson:
> Coverity flags a possible problem where the 8-bit wq_idx value may have
> errors when shifted and sign-extended to 64-bits. Since this can only occur
> if the shift index is larger than any expected value from hardware, it's
> unlikely to cause any real problems, but we can eliminate any
> possible errors, and the coverity issue, by explicitly typecasting
> the uint8_t value to 64-bits before any shift operations occur.
> 
> Coverity issue: 363695
> Fixes: a33969462135 ("raw/ioat: fix work-queue config size")
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks
  
Thomas Monjalon Nov. 3, 2020, 9:51 p.m. UTC | #2
03/11/2020 21:21, Thomas Monjalon:
> 03/11/2020 15:48, Bruce Richardson:
> > Coverity flags a possible problem where the 8-bit wq_idx value may have
> > errors when shifted and sign-extended to 64-bits. Since this can only occur
> > if the shift index is larger than any expected value from hardware, it's
> > unlikely to cause any real problems, but we can eliminate any
> > possible errors, and the coverity issue, by explicitly typecasting
> > the uint8_t value to 64-bits before any shift operations occur.
> > 
> > Coverity issue: 363695
> > Fixes: a33969462135 ("raw/ioat: fix work-queue config size")
> > 
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> 
> Applied, thanks

Actually no, sorry for the confusion, there is a build issue
with 32-bit compiler:
	error: cast to pointer from integer of different size

(thanks David for the heads up)
  
Bruce Richardson Nov. 4, 2020, 9:43 a.m. UTC | #3
On Tue, Nov 03, 2020 at 10:51:17PM +0100, Thomas Monjalon wrote:
> 03/11/2020 21:21, Thomas Monjalon:
> > 03/11/2020 15:48, Bruce Richardson:
> > > Coverity flags a possible problem where the 8-bit wq_idx value may have
> > > errors when shifted and sign-extended to 64-bits. Since this can only occur
> > > if the shift index is larger than any expected value from hardware, it's
> > > unlikely to cause any real problems, but we can eliminate any
> > > possible errors, and the coverity issue, by explicitly typecasting
> > > the uint8_t value to 64-bits before any shift operations occur.
> > > 
> > > Coverity issue: 363695
> > > Fixes: a33969462135 ("raw/ioat: fix work-queue config size")
> > > 
> > > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> > 
> > Applied, thanks
> 
> Actually no, sorry for the confusion, there is a build issue
> with 32-bit compiler:
> 	error: cast to pointer from integer of different size
> 
> (thanks David for the heads up)
> 
Ok, thanks for heads-up, I'll see about a v2.
  

Patch

diff --git a/drivers/raw/ioat/idxd_pci.c b/drivers/raw/ioat/idxd_pci.c
index 99ecfbbb4..7bc125014 100644
--- a/drivers/raw/ioat/idxd_pci.c
+++ b/drivers/raw/ioat/idxd_pci.c
@@ -47,7 +47,8 @@  idxd_pci_dev_command(struct idxd_rawdev *idxd, enum rte_idxd_cmds command)
 static uint32_t *
 idxd_get_wq_cfg(struct idxd_pci_common *pci, uint8_t wq_idx)
 {
-	return RTE_PTR_ADD(pci->wq_regs_base, wq_idx << (5 + pci->wq_cfg_sz));
+	return RTE_PTR_ADD(pci->wq_regs_base,
+			(uint64_t)wq_idx << (5 + pci->wq_cfg_sz));
 }
 
 static int