Skip to content

Commit 42f2611

Browse files
Christoph Hellwigjgunthorpe
authored andcommitted
rds: stop using dmapool
RDMA ULPs should only perform DMA through the ib_dma_* API instead of using the hidden dma_device directly. In addition using the dma coherent API family that dmapool is a part of can be very ineffcient on plaforms that are not DMA coherent. Switch to use slab allocations and the ib_dma_* APIs instead. Link: https://lore.kernel.org/r/20201106181941.1878556-6-hch@lst.de Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent bf3b7b7 commit 42f2611

5 files changed

Lines changed: 101 additions & 69 deletions

File tree

‎net/rds/ib.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
* SOFTWARE.
3131
*
3232
*/
33-
#include <linux/dmapool.h>
3433
#include <linux/kernel.h>
3534
#include <linux/in.h>
3635
#include <linux/if.h>
@@ -108,7 +107,6 @@ static void rds_ib_dev_free(struct work_struct *work)
108107
rds_ib_destroy_mr_pool(rds_ibdev->mr_1m_pool);
109108
if (rds_ibdev->pd)
110109
ib_dealloc_pd(rds_ibdev->pd);
111-
dma_pool_destroy(rds_ibdev->rid_hdrs_pool);
112110

113111
list_for_each_entry_safe(i_ipaddr, i_next, &rds_ibdev->ipaddr_list, list) {
114112
list_del(&i_ipaddr->list);
@@ -191,14 +189,6 @@ static int rds_ib_add_one(struct ib_device *device)
191189
rds_ibdev->pd = NULL;
192190
goto put_dev;
193191
}
194-
rds_ibdev->rid_hdrs_pool = dma_pool_create(device->name,
195-
device->dma_device,
196-
sizeof(struct rds_header),
197-
L1_CACHE_BYTES, 0);
198-
if (!rds_ibdev->rid_hdrs_pool) {
199-
ret = -ENOMEM;
200-
goto put_dev;
201-
}
202192

203193
rds_ibdev->mr_1m_pool =
204194
rds_ib_create_mr_pool(rds_ibdev, RDS_IB_MR_1M_POOL);

‎net/rds/ib.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ struct rds_ib_device {
246246
struct list_head conn_list;
247247
struct ib_device *dev;
248248
struct ib_pd *pd;
249-
struct dma_pool *rid_hdrs_pool; /* RDS headers DMA pool */
250249
u8 odp_capable:1;
251250

252251
unsigned int max_mrs;
@@ -380,11 +379,6 @@ int rds_ib_cm_handle_connect(struct rdma_cm_id *cm_id,
380379
int rds_ib_cm_initiate_connect(struct rdma_cm_id *cm_id, bool isv6);
381380
void rds_ib_cm_connect_complete(struct rds_connection *conn,
382381
struct rdma_cm_event *event);
383-
struct rds_header **rds_dma_hdrs_alloc(struct ib_device *ibdev,
384-
struct dma_pool *pool,
385-
dma_addr_t **dma_addrs, u32 num_hdrs);
386-
void rds_dma_hdrs_free(struct dma_pool *pool, struct rds_header **hdrs,
387-
dma_addr_t *dma_addrs, u32 num_hdrs);
388382

389383
#define rds_ib_conn_error(conn, fmt...) \
390384
__rds_ib_conn_error(conn, KERN_WARNING "RDS/IB: " fmt)

‎net/rds/ib_cm.c‎

Lines changed: 78 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
* SOFTWARE.
3131
*
3232
*/
33-
#include <linux/dmapool.h>
3433
#include <linux/kernel.h>
3534
#include <linux/in.h>
3635
#include <linux/slab.h>
@@ -441,42 +440,87 @@ static inline void ibdev_put_vector(struct rds_ib_device *rds_ibdev, int index)
441440
rds_ibdev->vector_load[index]--;
442441
}
443442

443+
static void rds_dma_hdr_free(struct ib_device *dev, struct rds_header *hdr,
444+
dma_addr_t dma_addr, enum dma_data_direction dir)
445+
{
446+
ib_dma_unmap_single(dev, dma_addr, sizeof(*hdr), dir);
447+
kfree(hdr);
448+
}
449+
450+
static struct rds_header *rds_dma_hdr_alloc(struct ib_device *dev,
451+
dma_addr_t *dma_addr, enum dma_data_direction dir)
452+
{
453+
struct rds_header *hdr;
454+
455+
hdr = kzalloc_node(sizeof(*hdr), GFP_KERNEL, ibdev_to_node(dev));
456+
if (!hdr)
457+
return NULL;
458+
459+
*dma_addr = ib_dma_map_single(dev, hdr, sizeof(*hdr),
460+
DMA_BIDIRECTIONAL);
461+
if (ib_dma_mapping_error(dev, *dma_addr)) {
462+
kfree(hdr);
463+
return NULL;
464+
}
465+
466+
return hdr;
467+
}
468+
469+
/* Free the DMA memory used to store struct rds_header.
470+
*
471+
* @dev: the RDS IB device
472+
* @hdrs: pointer to the array storing DMA memory pointers
473+
* @dma_addrs: pointer to the array storing DMA addresses
474+
* @num_hdars: number of headers to free.
475+
*/
476+
static void rds_dma_hdrs_free(struct rds_ib_device *dev,
477+
struct rds_header **hdrs, dma_addr_t *dma_addrs, u32 num_hdrs,
478+
enum dma_data_direction dir)
479+
{
480+
u32 i;
481+
482+
for (i = 0; i < num_hdrs; i++)
483+
rds_dma_hdr_free(dev->dev, hdrs[i], dma_addrs[i], dir);
484+
kvfree(hdrs);
485+
kvfree(dma_addrs);
486+
}
487+
488+
444489
/* Allocate DMA coherent memory to be used to store struct rds_header for
445490
* sending/receiving packets. The pointers to the DMA memory and the
446491
* associated DMA addresses are stored in two arrays.
447492
*
448-
* @ibdev: the IB device
449-
* @pool: the DMA memory pool
493+
* @dev: the RDS IB device
450494
* @dma_addrs: pointer to the array for storing DMA addresses
451495
* @num_hdrs: number of headers to allocate
452496
*
453497
* It returns the pointer to the array storing the DMA memory pointers. On
454498
* error, NULL pointer is returned.
455499
*/
456-
struct rds_header **rds_dma_hdrs_alloc(struct ib_device *ibdev,
457-
struct dma_pool *pool,
458-
dma_addr_t **dma_addrs, u32 num_hdrs)
500+
static struct rds_header **rds_dma_hdrs_alloc(struct rds_ib_device *dev,
501+
dma_addr_t **dma_addrs, u32 num_hdrs,
502+
enum dma_data_direction dir)
459503
{
460504
struct rds_header **hdrs;
461505
dma_addr_t *hdr_daddrs;
462506
u32 i;
463507

464508
hdrs = kvmalloc_node(sizeof(*hdrs) * num_hdrs, GFP_KERNEL,
465-
ibdev_to_node(ibdev));
509+
ibdev_to_node(dev->dev));
466510
if (!hdrs)
467511
return NULL;
468512

469513
hdr_daddrs = kvmalloc_node(sizeof(*hdr_daddrs) * num_hdrs, GFP_KERNEL,
470-
ibdev_to_node(ibdev));
514+
ibdev_to_node(dev->dev));
471515
if (!hdr_daddrs) {
472516
kvfree(hdrs);
473517
return NULL;
474518
}
475519

476520
for (i = 0; i < num_hdrs; i++) {
477-
hdrs[i] = dma_pool_zalloc(pool, GFP_KERNEL, &hdr_daddrs[i]);
521+
hdrs[i] = rds_dma_hdr_alloc(dev->dev, &hdr_daddrs[i], dir);
478522
if (!hdrs[i]) {
479-
rds_dma_hdrs_free(pool, hdrs, hdr_daddrs, i);
523+
rds_dma_hdrs_free(dev, hdrs, hdr_daddrs, i, dir);
480524
return NULL;
481525
}
482526
}
@@ -485,24 +529,6 @@ struct rds_header **rds_dma_hdrs_alloc(struct ib_device *ibdev,
485529
return hdrs;
486530
}
487531

488-
/* Free the DMA memory used to store struct rds_header.
489-
*
490-
* @pool: the DMA memory pool
491-
* @hdrs: pointer to the array storing DMA memory pointers
492-
* @dma_addrs: pointer to the array storing DMA addresses
493-
* @num_hdars: number of headers to free.
494-
*/
495-
void rds_dma_hdrs_free(struct dma_pool *pool, struct rds_header **hdrs,
496-
dma_addr_t *dma_addrs, u32 num_hdrs)
497-
{
498-
u32 i;
499-
500-
for (i = 0; i < num_hdrs; i++)
501-
dma_pool_free(pool, hdrs[i], dma_addrs[i]);
502-
kvfree(hdrs);
503-
kvfree(dma_addrs);
504-
}
505-
506532
/*
507533
* This needs to be very careful to not leave IS_ERR pointers around for
508534
* cleanup to trip over.
@@ -516,7 +542,6 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
516542
struct rds_ib_device *rds_ibdev;
517543
unsigned long max_wrs;
518544
int ret, fr_queue_space;
519-
struct dma_pool *pool;
520545

521546
/*
522547
* It's normal to see a null device if an incoming connection races
@@ -612,25 +637,26 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
612637
goto recv_cq_out;
613638
}
614639

615-
pool = rds_ibdev->rid_hdrs_pool;
616-
ic->i_send_hdrs = rds_dma_hdrs_alloc(dev, pool, &ic->i_send_hdrs_dma,
617-
ic->i_send_ring.w_nr);
640+
ic->i_send_hdrs = rds_dma_hdrs_alloc(rds_ibdev, &ic->i_send_hdrs_dma,
641+
ic->i_send_ring.w_nr,
642+
DMA_TO_DEVICE);
618643
if (!ic->i_send_hdrs) {
619644
ret = -ENOMEM;
620645
rdsdebug("DMA send hdrs alloc failed\n");
621646
goto qp_out;
622647
}
623648

624-
ic->i_recv_hdrs = rds_dma_hdrs_alloc(dev, pool, &ic->i_recv_hdrs_dma,
625-
ic->i_recv_ring.w_nr);
649+
ic->i_recv_hdrs = rds_dma_hdrs_alloc(rds_ibdev, &ic->i_recv_hdrs_dma,
650+
ic->i_recv_ring.w_nr,
651+
DMA_FROM_DEVICE);
626652
if (!ic->i_recv_hdrs) {
627653
ret = -ENOMEM;
628654
rdsdebug("DMA recv hdrs alloc failed\n");
629655
goto send_hdrs_dma_out;
630656
}
631657

632-
ic->i_ack = dma_pool_zalloc(pool, GFP_KERNEL,
633-
&ic->i_ack_dma);
658+
ic->i_ack = rds_dma_hdr_alloc(rds_ibdev->dev, &ic->i_ack_dma,
659+
DMA_TO_DEVICE);
634660
if (!ic->i_ack) {
635661
ret = -ENOMEM;
636662
rdsdebug("DMA ack header alloc failed\n");
@@ -666,18 +692,19 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
666692
vfree(ic->i_sends);
667693

668694
ack_dma_out:
669-
dma_pool_free(pool, ic->i_ack, ic->i_ack_dma);
695+
rds_dma_hdr_free(rds_ibdev->dev, ic->i_ack, ic->i_ack_dma,
696+
DMA_TO_DEVICE);
670697
ic->i_ack = NULL;
671698

672699
recv_hdrs_dma_out:
673-
rds_dma_hdrs_free(pool, ic->i_recv_hdrs, ic->i_recv_hdrs_dma,
674-
ic->i_recv_ring.w_nr);
700+
rds_dma_hdrs_free(rds_ibdev, ic->i_recv_hdrs, ic->i_recv_hdrs_dma,
701+
ic->i_recv_ring.w_nr, DMA_FROM_DEVICE);
675702
ic->i_recv_hdrs = NULL;
676703
ic->i_recv_hdrs_dma = NULL;
677704

678705
send_hdrs_dma_out:
679-
rds_dma_hdrs_free(pool, ic->i_send_hdrs, ic->i_send_hdrs_dma,
680-
ic->i_send_ring.w_nr);
706+
rds_dma_hdrs_free(rds_ibdev, ic->i_send_hdrs, ic->i_send_hdrs_dma,
707+
ic->i_send_ring.w_nr, DMA_TO_DEVICE);
681708
ic->i_send_hdrs = NULL;
682709
ic->i_send_hdrs_dma = NULL;
683710

@@ -1110,29 +1137,30 @@ void rds_ib_conn_path_shutdown(struct rds_conn_path *cp)
11101137
}
11111138

11121139
if (ic->rds_ibdev) {
1113-
struct dma_pool *pool;
1114-
1115-
pool = ic->rds_ibdev->rid_hdrs_pool;
1116-
11171140
/* then free the resources that ib callbacks use */
11181141
if (ic->i_send_hdrs) {
1119-
rds_dma_hdrs_free(pool, ic->i_send_hdrs,
1142+
rds_dma_hdrs_free(ic->rds_ibdev,
1143+
ic->i_send_hdrs,
11201144
ic->i_send_hdrs_dma,
1121-
ic->i_send_ring.w_nr);
1145+
ic->i_send_ring.w_nr,
1146+
DMA_TO_DEVICE);
11221147
ic->i_send_hdrs = NULL;
11231148
ic->i_send_hdrs_dma = NULL;
11241149
}
11251150

11261151
if (ic->i_recv_hdrs) {
1127-
rds_dma_hdrs_free(pool, ic->i_recv_hdrs,
1152+
rds_dma_hdrs_free(ic->rds_ibdev,
1153+
ic->i_recv_hdrs,
11281154
ic->i_recv_hdrs_dma,
1129-
ic->i_recv_ring.w_nr);
1155+
ic->i_recv_ring.w_nr,
1156+
DMA_FROM_DEVICE);
11301157
ic->i_recv_hdrs = NULL;
11311158
ic->i_recv_hdrs_dma = NULL;
11321159
}
11331160

11341161
if (ic->i_ack) {
1135-
dma_pool_free(pool, ic->i_ack, ic->i_ack_dma);
1162+
rds_dma_hdr_free(ic->rds_ibdev->dev, ic->i_ack,
1163+
ic->i_ack_dma, DMA_TO_DEVICE);
11361164
ic->i_ack = NULL;
11371165
}
11381166
} else {

‎net/rds/ib_recv.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,16 @@ static void rds_ib_send_ack(struct rds_ib_connection *ic, unsigned int adv_credi
662662
seq = rds_ib_get_ack(ic);
663663

664664
rdsdebug("send_ack: ic %p ack %llu\n", ic, (unsigned long long) seq);
665+
666+
ib_dma_sync_single_for_cpu(ic->rds_ibdev->dev, ic->i_ack_dma,
667+
sizeof(*hdr), DMA_TO_DEVICE);
665668
rds_message_populate_header(hdr, 0, 0, 0);
666669
hdr->h_ack = cpu_to_be64(seq);
667670
hdr->h_credit = adv_credits;
668671
rds_message_make_checksum(hdr);
672+
ib_dma_sync_single_for_device(ic->rds_ibdev->dev, ic->i_ack_dma,
673+
sizeof(*hdr), DMA_TO_DEVICE);
674+
669675
ic->i_ack_queued = jiffies;
670676

671677
ret = ib_post_send(ic->i_cm_id->qp, &ic->i_ack_wr, NULL);
@@ -845,6 +851,7 @@ static void rds_ib_process_recv(struct rds_connection *conn,
845851
struct rds_ib_connection *ic = conn->c_transport_data;
846852
struct rds_ib_incoming *ibinc = ic->i_ibinc;
847853
struct rds_header *ihdr, *hdr;
854+
dma_addr_t dma_addr = ic->i_recv_hdrs_dma[recv - ic->i_recvs];
848855

849856
/* XXX shut down the connection if port 0,0 are seen? */
850857

@@ -863,14 +870,16 @@ static void rds_ib_process_recv(struct rds_connection *conn,
863870

864871
ihdr = ic->i_recv_hdrs[recv - ic->i_recvs];
865872

873+
ib_dma_sync_single_for_cpu(ic->rds_ibdev->dev, dma_addr,
874+
sizeof(*ihdr), DMA_FROM_DEVICE);
866875
/* Validate the checksum. */
867876
if (!rds_message_verify_checksum(ihdr)) {
868877
rds_ib_conn_error(conn, "incoming message "
869878
"from %pI6c has corrupted header - "
870879
"forcing a reconnect\n",
871880
&conn->c_faddr);
872881
rds_stats_inc(s_recv_drop_bad_checksum);
873-
return;
882+
goto done;
874883
}
875884

876885
/* Process the ACK sequence which comes with every packet */
@@ -899,7 +908,7 @@ static void rds_ib_process_recv(struct rds_connection *conn,
899908
*/
900909
rds_ib_frag_free(ic, recv->r_frag);
901910
recv->r_frag = NULL;
902-
return;
911+
goto done;
903912
}
904913

905914
/*
@@ -933,7 +942,7 @@ static void rds_ib_process_recv(struct rds_connection *conn,
933942
hdr->h_dport != ihdr->h_dport) {
934943
rds_ib_conn_error(conn,
935944
"fragment header mismatch; forcing reconnect\n");
936-
return;
945+
goto done;
937946
}
938947
}
939948

@@ -965,6 +974,9 @@ static void rds_ib_process_recv(struct rds_connection *conn,
965974

966975
rds_inc_put(&ibinc->ii_inc);
967976
}
977+
done:
978+
ib_dma_sync_single_for_device(ic->rds_ibdev->dev, dma_addr,
979+
sizeof(*ihdr), DMA_FROM_DEVICE);
968980
}
969981

970982
void rds_ib_recv_cqe_handler(struct rds_ib_connection *ic,

‎net/rds/ib_send.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,10 @@ int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm,
638638
send->s_sge[0].length = sizeof(struct rds_header);
639639
send->s_sge[0].lkey = ic->i_pd->local_dma_lkey;
640640

641+
ib_dma_sync_single_for_cpu(ic->rds_ibdev->dev,
642+
ic->i_send_hdrs_dma[pos],
643+
sizeof(struct rds_header),
644+
DMA_TO_DEVICE);
641645
memcpy(ic->i_send_hdrs[pos], &rm->m_inc.i_hdr,
642646
sizeof(struct rds_header));
643647

@@ -688,6 +692,10 @@ int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm,
688692
adv_credits = 0;
689693
rds_ib_stats_inc(s_ib_tx_credit_updates);
690694
}
695+
ib_dma_sync_single_for_device(ic->rds_ibdev->dev,
696+
ic->i_send_hdrs_dma[pos],
697+
sizeof(struct rds_header),
698+
DMA_TO_DEVICE);
691699

692700
if (prev)
693701
prev->s_wr.next = &send->s_wr;

0 commit comments

Comments
 (0)