Skip to content

Commit 94fb175

Browse files
committed
Merge tag 'dmaengine-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/dmaengine
Pull dmaengine fixes from Dan Williams: 1/ regression fix for Xen as it now trips over a broken assumption about the dma address size on 32-bit builds 2/ new quirk for netdma to ignore dma channels that cannot meet netdma alignment requirements 3/ fixes for two long standing issues in ioatdma (ring size overflow) and iop-adma (potential stack corruption) * tag 'dmaengine-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/dmaengine: netdma: adding alignment check for NETDMA ops ioatdma: DMA copy alignment needed to address IOAT DMA silicon errata ioat: ring size variables need to be 32bit to avoid overflow iop-adma: Corrected array overflow in RAID6 Xscale(R) test. ioat: fix size of 'completion' for Xen
2 parents a9e1e53 + a2bd114 commit 94fb175

File tree

12 files changed

+86
-30
lines changed

12 files changed

+86
-30
lines changed

drivers/dma/dmaengine.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,20 @@ struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type)
332332
}
333333
EXPORT_SYMBOL(dma_find_channel);
334334

335+
/*
336+
* net_dma_find_channel - find a channel for net_dma
337+
* net_dma has alignment requirements
338+
*/
339+
struct dma_chan *net_dma_find_channel(void)
340+
{
341+
struct dma_chan *chan = dma_find_channel(DMA_MEMCPY);
342+
if (chan && !is_dma_copy_aligned(chan->device, 1, 1, 1))
343+
return NULL;
344+
345+
return chan;
346+
}
347+
EXPORT_SYMBOL(net_dma_find_channel);
348+
335349
/**
336350
* dma_issue_pending_all - flush all pending operations across all channels
337351
*/

drivers/dma/ioat/dma.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
546546
PCI_DMA_TODEVICE, flags, 0);
547547
}
548548

549-
unsigned long ioat_get_current_completion(struct ioat_chan_common *chan)
549+
dma_addr_t ioat_get_current_completion(struct ioat_chan_common *chan)
550550
{
551-
unsigned long phys_complete;
551+
dma_addr_t phys_complete;
552552
u64 completion;
553553

554554
completion = *chan->completion;
@@ -569,7 +569,7 @@ unsigned long ioat_get_current_completion(struct ioat_chan_common *chan)
569569
}
570570

571571
bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
572-
unsigned long *phys_complete)
572+
dma_addr_t *phys_complete)
573573
{
574574
*phys_complete = ioat_get_current_completion(chan);
575575
if (*phys_complete == chan->last_completion)
@@ -580,14 +580,14 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
580580
return true;
581581
}
582582

583-
static void __cleanup(struct ioat_dma_chan *ioat, unsigned long phys_complete)
583+
static void __cleanup(struct ioat_dma_chan *ioat, dma_addr_t phys_complete)
584584
{
585585
struct ioat_chan_common *chan = &ioat->base;
586586
struct list_head *_desc, *n;
587587
struct dma_async_tx_descriptor *tx;
588588

589-
dev_dbg(to_dev(chan), "%s: phys_complete: %lx\n",
590-
__func__, phys_complete);
589+
dev_dbg(to_dev(chan), "%s: phys_complete: %llx\n",
590+
__func__, (unsigned long long) phys_complete);
591591
list_for_each_safe(_desc, n, &ioat->used_desc) {
592592
struct ioat_desc_sw *desc;
593593

@@ -652,7 +652,7 @@ static void __cleanup(struct ioat_dma_chan *ioat, unsigned long phys_complete)
652652
static void ioat1_cleanup(struct ioat_dma_chan *ioat)
653653
{
654654
struct ioat_chan_common *chan = &ioat->base;
655-
unsigned long phys_complete;
655+
dma_addr_t phys_complete;
656656

657657
prefetch(chan->completion);
658658

@@ -698,7 +698,7 @@ static void ioat1_timer_event(unsigned long data)
698698
mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
699699
spin_unlock_bh(&ioat->desc_lock);
700700
} else if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
701-
unsigned long phys_complete;
701+
dma_addr_t phys_complete;
702702

703703
spin_lock_bh(&ioat->desc_lock);
704704
/* if we haven't made progress and we have already

drivers/dma/ioat/dma.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct ioatdma_device {
8888
struct ioat_chan_common {
8989
struct dma_chan common;
9090
void __iomem *reg_base;
91-
unsigned long last_completion;
91+
dma_addr_t last_completion;
9292
spinlock_t cleanup_lock;
9393
unsigned long state;
9494
#define IOAT_COMPLETION_PENDING 0
@@ -310,15 +310,15 @@ int __devinit ioat_dma_self_test(struct ioatdma_device *device);
310310
void __devexit ioat_dma_remove(struct ioatdma_device *device);
311311
struct dca_provider * __devinit ioat_dca_init(struct pci_dev *pdev,
312312
void __iomem *iobase);
313-
unsigned long ioat_get_current_completion(struct ioat_chan_common *chan);
313+
dma_addr_t ioat_get_current_completion(struct ioat_chan_common *chan);
314314
void ioat_init_channel(struct ioatdma_device *device,
315315
struct ioat_chan_common *chan, int idx);
316316
enum dma_status ioat_dma_tx_status(struct dma_chan *c, dma_cookie_t cookie,
317317
struct dma_tx_state *txstate);
318318
void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
319319
size_t len, struct ioat_dma_descriptor *hw);
320320
bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
321-
unsigned long *phys_complete);
321+
dma_addr_t *phys_complete);
322322
void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
323323
void ioat_kobject_del(struct ioatdma_device *device);
324324
extern const struct sysfs_ops ioat_sysfs_ops;

drivers/dma/ioat/dma_v2.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void ioat2_start_null_desc(struct ioat2_dma_chan *ioat)
128128
spin_unlock_bh(&ioat->prep_lock);
129129
}
130130

131-
static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
131+
static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
132132
{
133133
struct ioat_chan_common *chan = &ioat->base;
134134
struct dma_async_tx_descriptor *tx;
@@ -179,7 +179,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
179179
static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
180180
{
181181
struct ioat_chan_common *chan = &ioat->base;
182-
unsigned long phys_complete;
182+
dma_addr_t phys_complete;
183183

184184
spin_lock_bh(&chan->cleanup_lock);
185185
if (ioat_cleanup_preamble(chan, &phys_complete))
@@ -260,7 +260,7 @@ int ioat2_reset_sync(struct ioat_chan_common *chan, unsigned long tmo)
260260
static void ioat2_restart_channel(struct ioat2_dma_chan *ioat)
261261
{
262262
struct ioat_chan_common *chan = &ioat->base;
263-
unsigned long phys_complete;
263+
dma_addr_t phys_complete;
264264

265265
ioat2_quiesce(chan, 0);
266266
if (ioat_cleanup_preamble(chan, &phys_complete))
@@ -275,7 +275,7 @@ void ioat2_timer_event(unsigned long data)
275275
struct ioat_chan_common *chan = &ioat->base;
276276

277277
if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
278-
unsigned long phys_complete;
278+
dma_addr_t phys_complete;
279279
u64 status;
280280

281281
status = ioat_chansts(chan);
@@ -572,9 +572,9 @@ bool reshape_ring(struct ioat2_dma_chan *ioat, int order)
572572
*/
573573
struct ioat_chan_common *chan = &ioat->base;
574574
struct dma_chan *c = &chan->common;
575-
const u16 curr_size = ioat2_ring_size(ioat);
575+
const u32 curr_size = ioat2_ring_size(ioat);
576576
const u16 active = ioat2_ring_active(ioat);
577-
const u16 new_size = 1 << order;
577+
const u32 new_size = 1 << order;
578578
struct ioat_ring_ent **ring;
579579
u16 i;
580580

drivers/dma/ioat/dma_v2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static inline struct ioat2_dma_chan *to_ioat2_chan(struct dma_chan *c)
7474
return container_of(chan, struct ioat2_dma_chan, base);
7575
}
7676

77-
static inline u16 ioat2_ring_size(struct ioat2_dma_chan *ioat)
77+
static inline u32 ioat2_ring_size(struct ioat2_dma_chan *ioat)
7878
{
7979
return 1 << ioat->alloc_order;
8080
}
@@ -91,7 +91,7 @@ static inline u16 ioat2_ring_pending(struct ioat2_dma_chan *ioat)
9191
return CIRC_CNT(ioat->head, ioat->issued, ioat2_ring_size(ioat));
9292
}
9393

94-
static inline u16 ioat2_ring_space(struct ioat2_dma_chan *ioat)
94+
static inline u32 ioat2_ring_space(struct ioat2_dma_chan *ioat)
9595
{
9696
return ioat2_ring_size(ioat) - ioat2_ring_active(ioat);
9797
}

drivers/dma/ioat/dma_v3.c

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static bool desc_has_ext(struct ioat_ring_ent *desc)
257257
* The difference from the dma_v2.c __cleanup() is that this routine
258258
* handles extended descriptors and dma-unmapping raid operations.
259259
*/
260-
static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
260+
static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
261261
{
262262
struct ioat_chan_common *chan = &ioat->base;
263263
struct ioat_ring_ent *desc;
@@ -314,7 +314,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
314314
static void ioat3_cleanup(struct ioat2_dma_chan *ioat)
315315
{
316316
struct ioat_chan_common *chan = &ioat->base;
317-
unsigned long phys_complete;
317+
dma_addr_t phys_complete;
318318

319319
spin_lock_bh(&chan->cleanup_lock);
320320
if (ioat_cleanup_preamble(chan, &phys_complete))
@@ -333,7 +333,7 @@ static void ioat3_cleanup_event(unsigned long data)
333333
static void ioat3_restart_channel(struct ioat2_dma_chan *ioat)
334334
{
335335
struct ioat_chan_common *chan = &ioat->base;
336-
unsigned long phys_complete;
336+
dma_addr_t phys_complete;
337337

338338
ioat2_quiesce(chan, 0);
339339
if (ioat_cleanup_preamble(chan, &phys_complete))
@@ -348,7 +348,7 @@ static void ioat3_timer_event(unsigned long data)
348348
struct ioat_chan_common *chan = &ioat->base;
349349

350350
if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
351-
unsigned long phys_complete;
351+
dma_addr_t phys_complete;
352352
u64 status;
353353

354354
status = ioat_chansts(chan);
@@ -1149,6 +1149,44 @@ static int ioat3_reset_hw(struct ioat_chan_common *chan)
11491149
return ioat2_reset_sync(chan, msecs_to_jiffies(200));
11501150
}
11511151

1152+
static bool is_jf_ioat(struct pci_dev *pdev)
1153+
{
1154+
switch (pdev->device) {
1155+
case PCI_DEVICE_ID_INTEL_IOAT_JSF0:
1156+
case PCI_DEVICE_ID_INTEL_IOAT_JSF1:
1157+
case PCI_DEVICE_ID_INTEL_IOAT_JSF2:
1158+
case PCI_DEVICE_ID_INTEL_IOAT_JSF3:
1159+
case PCI_DEVICE_ID_INTEL_IOAT_JSF4:
1160+
case PCI_DEVICE_ID_INTEL_IOAT_JSF5:
1161+
case PCI_DEVICE_ID_INTEL_IOAT_JSF6:
1162+
case PCI_DEVICE_ID_INTEL_IOAT_JSF7:
1163+
case PCI_DEVICE_ID_INTEL_IOAT_JSF8:
1164+
case PCI_DEVICE_ID_INTEL_IOAT_JSF9:
1165+
return true;
1166+
default:
1167+
return false;
1168+
}
1169+
}
1170+
1171+
static bool is_snb_ioat(struct pci_dev *pdev)
1172+
{
1173+
switch (pdev->device) {
1174+
case PCI_DEVICE_ID_INTEL_IOAT_SNB0:
1175+
case PCI_DEVICE_ID_INTEL_IOAT_SNB1:
1176+
case PCI_DEVICE_ID_INTEL_IOAT_SNB2:
1177+
case PCI_DEVICE_ID_INTEL_IOAT_SNB3:
1178+
case PCI_DEVICE_ID_INTEL_IOAT_SNB4:
1179+
case PCI_DEVICE_ID_INTEL_IOAT_SNB5:
1180+
case PCI_DEVICE_ID_INTEL_IOAT_SNB6:
1181+
case PCI_DEVICE_ID_INTEL_IOAT_SNB7:
1182+
case PCI_DEVICE_ID_INTEL_IOAT_SNB8:
1183+
case PCI_DEVICE_ID_INTEL_IOAT_SNB9:
1184+
return true;
1185+
default:
1186+
return false;
1187+
}
1188+
}
1189+
11521190
int __devinit ioat3_dma_probe(struct ioatdma_device *device, int dca)
11531191
{
11541192
struct pci_dev *pdev = device->pdev;
@@ -1169,6 +1207,9 @@ int __devinit ioat3_dma_probe(struct ioatdma_device *device, int dca)
11691207
dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
11701208
dma->device_free_chan_resources = ioat2_free_chan_resources;
11711209

1210+
if (is_jf_ioat(pdev) || is_snb_ioat(pdev))
1211+
dma->copy_align = 6;
1212+
11721213
dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
11731214
dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;
11741215

drivers/dma/iop-adma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,8 +1252,8 @@ iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device)
12521252
struct page **pq_hw = &pq[IOP_ADMA_NUM_SRC_TEST+2];
12531253
/* address conversion buffers (dma_map / page_address) */
12541254
void *pq_sw[IOP_ADMA_NUM_SRC_TEST+2];
1255-
dma_addr_t pq_src[IOP_ADMA_NUM_SRC_TEST];
1256-
dma_addr_t pq_dest[2];
1255+
dma_addr_t pq_src[IOP_ADMA_NUM_SRC_TEST+2];
1256+
dma_addr_t *pq_dest = &pq_src[IOP_ADMA_NUM_SRC_TEST];
12571257

12581258
int i;
12591259
struct dma_async_tx_descriptor *tx;

include/linux/dmaengine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ int dma_async_device_register(struct dma_device *device);
974974
void dma_async_device_unregister(struct dma_device *device);
975975
void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
976976
struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type);
977+
struct dma_chan *net_dma_find_channel(void);
977978
#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y)
978979

979980
/* --- Helper iov-locking functions --- */

net/ipv4/tcp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
14521452
if ((available < target) &&
14531453
(len > sysctl_tcp_dma_copybreak) && !(flags & MSG_PEEK) &&
14541454
!sysctl_tcp_low_latency &&
1455-
dma_find_channel(DMA_MEMCPY)) {
1455+
net_dma_find_channel()) {
14561456
preempt_enable_no_resched();
14571457
tp->ucopy.pinned_list =
14581458
dma_pin_iovec_pages(msg->msg_iov, len);
@@ -1667,7 +1667,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
16671667
if (!(flags & MSG_TRUNC)) {
16681668
#ifdef CONFIG_NET_DMA
16691669
if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list)
1670-
tp->ucopy.dma_chan = dma_find_channel(DMA_MEMCPY);
1670+
tp->ucopy.dma_chan = net_dma_find_channel();
16711671

16721672
if (tp->ucopy.dma_chan) {
16731673
tp->ucopy.dma_cookie = dma_skb_copy_datagram_iovec(

net/ipv4/tcp_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5225,7 +5225,7 @@ static int tcp_dma_try_early_copy(struct sock *sk, struct sk_buff *skb,
52255225
return 0;
52265226

52275227
if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list)
5228-
tp->ucopy.dma_chan = dma_find_channel(DMA_MEMCPY);
5228+
tp->ucopy.dma_chan = net_dma_find_channel();
52295229

52305230
if (tp->ucopy.dma_chan && skb_csum_unnecessary(skb)) {
52315231

0 commit comments

Comments
 (0)