* [PATCH v2] cxgb3i: fix ddp map overrun (v2)
@ 2009-04-18 4:45 kxie-ut6Up61K2wZBDgjK7y7TUQ
2009-04-21 20:19 ` Mike Christie
0 siblings, 1 reply; 2+ messages in thread
From: kxie-ut6Up61K2wZBDgjK7y7TUQ @ 2009-04-18 4:45 UTC (permalink / raw)
To: linux-scsi-u79uwXL29TY76Z2rM5mHXA,
open-iscsi-/JYPxA39Uh5TLH3MbocFFw
Cc: kxie-ut6Up61K2wZBDgjK7y7TUQ,
James.Bottomley-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk,
michaelc-hcNo3dDEHLuVc3sceRu5cw
[PATCH v2] cxgb3i: fix ddp map overrun (version 2)
From: Karen Xie <kxie-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
Fixed a bug in calculating ddp map range when search for free entries:
it was going beyond the end by one, thus corrupting gl_skb[0].
Signed-off-by: Karen Xie <kxie-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
---
drivers/scsi/cxgb3i/cxgb3i_ddp.c | 32 +++++++++++++++++++-------------
1 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/drivers/scsi/cxgb3i/cxgb3i_ddp.c b/drivers/scsi/cxgb3i/cxgb3i_ddp.c
index d06a661..99c9125 100644
--- a/drivers/scsi/cxgb3i/cxgb3i_ddp.c
+++ b/drivers/scsi/cxgb3i/cxgb3i_ddp.c
@@ -120,20 +120,26 @@ static void clear_ddp_map(struct cxgb3i_ddp_info *ddp, unsigned int tag,
}
static inline int ddp_find_unused_entries(struct cxgb3i_ddp_info *ddp,
- int start, int max, int count,
+ unsigned int start, unsigned int max,
+ unsigned int count,
struct cxgb3i_gather_list *gl)
{
- unsigned int i, j;
+ unsigned int i, j, k;
+ /* not enough entries */
+ if ((max - start) < count)
+ return -EBUSY;
+
+ max -= count;
spin_lock(&ddp->map_lock);
- for (i = start; i <= max;) {
- for (j = 0; j < count; j++) {
- if (ddp->gl_map[i + j])
+ for (i = start; i < max;) {
+ for (j = 0, k = i; j < count; j++, k++) {
+ if (ddp->gl_map[k])
break;
}
if (j == count) {
- for (j = 0; j < count; j++)
- ddp->gl_map[i + j] = gl;
+ for (j = 0, k = i; j < count; j++, k++)
+ ddp->gl_map[k] = gl;
spin_unlock(&ddp->map_lock);
return i;
}
@@ -354,7 +360,7 @@ int cxgb3i_ddp_tag_reserve(struct t3cdev *tdev, unsigned int tid,
struct cxgb3i_ddp_info *ddp = tdev->ulp_iscsi;
struct pagepod_hdr hdr;
unsigned int npods;
- int idx = -1, idx_max;
+ int idx = -1;
int err = -ENOMEM;
u32 sw_tag = *tagp;
u32 tag;
@@ -367,17 +373,17 @@ int cxgb3i_ddp_tag_reserve(struct t3cdev *tdev, unsigned int tid,
}
npods = (gl->nelem + PPOD_PAGES_MAX - 1) >> PPOD_PAGES_SHIFT;
- idx_max = ddp->nppods - npods + 1;
if (ddp->idx_last == ddp->nppods)
- idx = ddp_find_unused_entries(ddp, 0, idx_max, npods, gl);
+ idx = ddp_find_unused_entries(ddp, 0, ddp->nppods, npods, gl);
else {
idx = ddp_find_unused_entries(ddp, ddp->idx_last + 1,
- idx_max, npods, gl);
- if (idx < 0 && ddp->idx_last >= npods)
+ ddp->nppods, npods, gl);
+ if (idx < 0 && ddp->idx_last >= npods) {
idx = ddp_find_unused_entries(ddp, 0,
- ddp->idx_last - npods + 1,
+ min(ddp->idx_last + npods, ddp->nppods),
npods, gl);
+ }
}
if (idx < 0) {
ddp_log_debug("xferlen %u, gl %u, npods %u NO DDP.\n",
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] cxgb3i: fix ddp map overrun (v2)
2009-04-18 4:45 [PATCH v2] cxgb3i: fix ddp map overrun (v2) kxie-ut6Up61K2wZBDgjK7y7TUQ
@ 2009-04-21 20:19 ` Mike Christie
0 siblings, 0 replies; 2+ messages in thread
From: Mike Christie @ 2009-04-21 20:19 UTC (permalink / raw)
To: open-iscsi; +Cc: linux-scsi, kxie, James.Bottomley
kxie@chelsio.com wrote:
> [PATCH v2] cxgb3i: fix ddp map overrun (version 2)
>
> From: Karen Xie <kxie@chelsio.com>
>
> Fixed a bug in calculating ddp map range when search for free entries:
> it was going beyond the end by one, thus corrupting gl_skb[0].
>
This fixes the bug I was hitting. For the next feature release, we
probably want to look at using a more efficient map. I would have
thought there would be something general but I could not find anything
that handles what you are doing.
I will send this to James with the other queueing and xmit fixes I have
for cxgb3i.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-04-21 20:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-18 4:45 [PATCH v2] cxgb3i: fix ddp map overrun (v2) kxie-ut6Up61K2wZBDgjK7y7TUQ
2009-04-21 20:19 ` Mike Christie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).