Skip to content

Commit 8f6b846

Browse files
drchristensendavem330
authored andcommitted
ionic: fix 16bit math issue when PAGE_SIZE >= 64KB
The ionic device supports a maximum buffer length of 16 bits (see ionic_rxq_desc or ionic_rxq_sg_elem). When adding new buffers to the receive rings, the function ionic_rx_fill() uses 16bit math when calculating the number of pages to allocate for an RX descriptor, given the interface's MTU setting. If the system PAGE_SIZE >= 64KB, and the buf_info->page_offset is 0, the remain_len value will never decrement from the original MTU value and the frag_len value will always be 0, causing additional pages to be allocated as scatter- gather elements unnecessarily. A similar math issue exists in ionic_rx_frags(), but no failures have been observed here since a 64KB page should not normally require any scatter-gather elements at any legal Ethernet MTU size. Fixes: 4b0a753 ("ionic: implement Rx page reuse") Signed-off-by: David Christensen <[email protected]> Reviewed-by: Shannon Nelson <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1612cc4 commit 8f6b846

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

drivers/net/ethernet/pensando/ionic/ionic_dev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ typedef void (*ionic_desc_cb)(struct ionic_queue *q,
187187
struct ionic_desc_info *desc_info,
188188
struct ionic_cq_info *cq_info, void *cb_arg);
189189

190+
#define IONIC_MAX_BUF_LEN ((u16)-1)
190191
#define IONIC_PAGE_SIZE PAGE_SIZE
191192
#define IONIC_PAGE_SPLIT_SZ (PAGE_SIZE / 2)
192193
#define IONIC_PAGE_GFP_MASK (GFP_ATOMIC | __GFP_NOWARN |\

drivers/net/ethernet/pensando/ionic/ionic_txrx.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ static struct sk_buff *ionic_rx_frags(struct ionic_queue *q,
207207
return NULL;
208208
}
209209

210-
frag_len = min_t(u16, len, IONIC_PAGE_SIZE - buf_info->page_offset);
210+
frag_len = min_t(u16, len, min_t(u32, IONIC_MAX_BUF_LEN,
211+
IONIC_PAGE_SIZE - buf_info->page_offset));
211212
len -= frag_len;
212213

213214
dma_sync_single_for_cpu(dev,
@@ -452,7 +453,8 @@ void ionic_rx_fill(struct ionic_queue *q)
452453

453454
/* fill main descriptor - buf[0] */
454455
desc->addr = cpu_to_le64(buf_info->dma_addr + buf_info->page_offset);
455-
frag_len = min_t(u16, len, IONIC_PAGE_SIZE - buf_info->page_offset);
456+
frag_len = min_t(u16, len, min_t(u32, IONIC_MAX_BUF_LEN,
457+
IONIC_PAGE_SIZE - buf_info->page_offset));
456458
desc->len = cpu_to_le16(frag_len);
457459
remain_len -= frag_len;
458460
buf_info++;
@@ -471,7 +473,9 @@ void ionic_rx_fill(struct ionic_queue *q)
471473
}
472474

473475
sg_elem->addr = cpu_to_le64(buf_info->dma_addr + buf_info->page_offset);
474-
frag_len = min_t(u16, remain_len, IONIC_PAGE_SIZE - buf_info->page_offset);
476+
frag_len = min_t(u16, remain_len, min_t(u32, IONIC_MAX_BUF_LEN,
477+
IONIC_PAGE_SIZE -
478+
buf_info->page_offset));
475479
sg_elem->len = cpu_to_le16(frag_len);
476480
remain_len -= frag_len;
477481
buf_info++;

0 commit comments

Comments
 (0)