-
Notifications
You must be signed in to change notification settings - Fork 4
lib/pem: fix SDP queue mapping #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dao-devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,29 +17,35 @@ | |||||||||||||||||||||||
| #define SDP0_PCIE_DEV_NAME "0002:18:00.0" | ||||||||||||||||||||||||
| #define SDP1_PCIE_DEV_NAME "0002:19:00.0" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| static inline int sdp_offset_valid(struct dao_vfio_device *sdp_pdev, uint64_t offset) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| return offset < sdp_pdev->mem[DAO_VFIO_DEV_BAR2].len; | ||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Offset validation doesn't account for full 8-byte access width Validate that |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| int | ||||||||||||||||||||||||
| sdp_reg_write(struct dao_vfio_device *sdp_pdev, uint64_t offset, uint64_t val) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| if (offset > sdp_pdev->mem[DAO_VFIO_DEV_BAR2].len) | ||||||||||||||||||||||||
| if (!sdp_offset_valid(sdp_pdev, offset)) | ||||||||||||||||||||||||
| return -ENOMEM; | ||||||||||||||||||||||||
|
Comment on lines
+28
to
29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Use a more appropriate error code than -ENOMEM for invalid offsets Consider returning
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| *((volatile uint64_t *)(sdp_pdev->mem[DAO_VFIO_DEV_BAR2].addr + offset)) = val; | ||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| uint64_t | ||||||||||||||||||||||||
| sdp_reg_read(struct dao_vfio_device *sdp_pdev, uint64_t offset) | ||||||||||||||||||||||||
| int | ||||||||||||||||||||||||
| sdp_reg_read(struct dao_vfio_device *sdp_pdev, uint64_t offset, uint64_t *val) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| if (offset > sdp_pdev->mem[DAO_VFIO_DEV_BAR2].len) | ||||||||||||||||||||||||
| if (!sdp_pdev || !val || !sdp_offset_valid(sdp_pdev, offset)) | ||||||||||||||||||||||||
| return -ENOMEM; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return *(volatile uint64_t *)(sdp_pdev->mem[DAO_VFIO_DEV_BAR2].addr + offset); | ||||||||||||||||||||||||
| *val = *(volatile uint64_t *)(sdp_pdev->mem[DAO_VFIO_DEV_BAR2].addr + offset); | ||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| uint64_t * | ||||||||||||||||||||||||
| sdp_reg_addr(struct dao_vfio_device *sdp_pdev, uint64_t offset) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| if (offset > sdp_pdev->mem[DAO_VFIO_DEV_BAR2].len) | ||||||||||||||||||||||||
| if (!sdp_offset_valid(sdp_pdev, offset)) | ||||||||||||||||||||||||
| return NULL; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return (uint64_t *)(sdp_pdev->mem[DAO_VFIO_DEV_BAR2].addr + offset); | ||||||||||||||||||||||||
|
Comment on lines
+48
to
51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Potential unaligned pointer cast for register address Enforce alignment by checking that offset is a multiple of sizeof(uint64_t), or use memcpy for unaligned access.
Suggested change
|
||||||||||||||||||||||||
|
|
@@ -66,14 +72,14 @@ sdp_init(struct dao_vfio_device *sdp_pdev) | |||||||||||||||||||||||
| sdp_pdev->mbar = DAO_VFIO_DEV_BAR4; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (sdp_pdev->prime) { | ||||||||||||||||||||||||
| reg_val = sdp_reg_read(sdp_pdev, SDP_EPFX_RINFO(0)); | ||||||||||||||||||||||||
| sdp_reg_read(sdp_pdev, SDP_EPFX_RINFO(0), ®_val); | ||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Return code of sdp_reg_read is ignored in initialization Please check the return value of |
||||||||||||||||||||||||
| reg_val &= ~SDP_EPFX_RINFO_SRN_MASK; | ||||||||||||||||||||||||
| sdp_reg_write(sdp_pdev, SDP_EPFX_RINFO(0), reg_val); | ||||||||||||||||||||||||
| reg_val = sdp_reg_read(sdp_pdev, SDP_EPFX_RINFO(0)); | ||||||||||||||||||||||||
| sdp_reg_read(sdp_pdev, SDP_EPFX_RINFO(0), ®_val); | ||||||||||||||||||||||||
| rpvf = (reg_val >> SDP_EPFX_RINFO_RPVF_SHIFT) & 0xf; | ||||||||||||||||||||||||
| num_vfs = (reg_val >> SDP_EPFX_RINFO_RPVF_SHIFT) & 0x7f; | ||||||||||||||||||||||||
| num_vfs = (reg_val >> SDP_EPFX_RINFO_NVVF_SHIFT) & 0x7f; | ||||||||||||||||||||||||
| /* Disable PF Ring */ | ||||||||||||||||||||||||
| reg_val = sdp_reg_read(sdp_pdev, SDP_MAC0_PF_RING_CTL); | ||||||||||||||||||||||||
| sdp_reg_read(sdp_pdev, SDP_MAC0_PF_RING_CTL, ®_val); | ||||||||||||||||||||||||
| reg_val &= ~SDP_MAC0_PF_RING_CTL_RPPF_MASK; | ||||||||||||||||||||||||
| sdp_reg_write(sdp_pdev, SDP_MAC0_PF_RING_CTL, reg_val); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -90,9 +96,11 @@ sdp_init(struct dao_vfio_device *sdp_pdev) | |||||||||||||||||||||||
| info <<= 32; | ||||||||||||||||||||||||
| sdp_reg_write(sdp_pdev, SDP_PF_MBOX_DATA(0), info); | ||||||||||||||||||||||||
| vfid = num_vfs >> 1; | ||||||||||||||||||||||||
| info = rpvf | ((uint64_t)vfid << 8) | ((uint64_t)num_vfs << 16); | ||||||||||||||||||||||||
| info <<= 32; | ||||||||||||||||||||||||
| sdp_reg_write(sdp_pdev, SDP_PF_MBOX_DATA(32), info); | ||||||||||||||||||||||||
| if (vfid) { | ||||||||||||||||||||||||
| info = rpvf | ((uint64_t)vfid << 8) | ((uint64_t)num_vfs << 16); | ||||||||||||||||||||||||
| info <<= 32; | ||||||||||||||||||||||||
| sdp_reg_write(sdp_pdev, SDP_PF_MBOX_DATA(vfid * rpvf), info); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): sdp_offset_valid dereferences sdp_pdev without verifying it's non-null
Please add a null check for
sdp_pdevor document that it must not be null.