Skip to content

Commit 5fa1da9

Browse files
Naman Jainliuw
authored andcommitted
uio_hv_generic: Add a check for HV_NIC for send, receive buffers setup
Receive and send buffer allocation was originally introduced to support DPDK's networking use case. These buffer sizes were further increased to meet DPDK performance requirements. However, these large buffers are unnecessary for any other UIO use cases. Restrict the allocation of receive and send buffers only for HV_NIC device type, saving 47 MB of memory per device. While at it, fix some of the syntax related issues in the touched code which are reported by "--strict" option of checkpatch. Signed-off-by: Naman Jain <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]> Message-ID: <[email protected]>
1 parent 4f6b64f commit 5fa1da9

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

drivers/uio/uio_hv_generic.c

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -296,51 +296,51 @@ hv_uio_probe(struct hv_device *dev,
296296
pdata->info.mem[MON_PAGE_MAP].size = PAGE_SIZE;
297297
pdata->info.mem[MON_PAGE_MAP].memtype = UIO_MEM_LOGICAL;
298298

299-
pdata->recv_buf = vzalloc(RECV_BUFFER_SIZE);
300-
if (pdata->recv_buf == NULL) {
301-
ret = -ENOMEM;
302-
goto fail_free_ring;
299+
if (channel->device_id == HV_NIC) {
300+
pdata->recv_buf = vzalloc(RECV_BUFFER_SIZE);
301+
if (!pdata->recv_buf) {
302+
ret = -ENOMEM;
303+
goto fail_free_ring;
304+
}
305+
306+
ret = vmbus_establish_gpadl(channel, pdata->recv_buf,
307+
RECV_BUFFER_SIZE, &pdata->recv_gpadl);
308+
if (ret) {
309+
if (!pdata->recv_gpadl.decrypted)
310+
vfree(pdata->recv_buf);
311+
goto fail_close;
312+
}
313+
314+
/* put Global Physical Address Label in name */
315+
snprintf(pdata->recv_name, sizeof(pdata->recv_name),
316+
"recv:%u", pdata->recv_gpadl.gpadl_handle);
317+
pdata->info.mem[RECV_BUF_MAP].name = pdata->recv_name;
318+
pdata->info.mem[RECV_BUF_MAP].addr = (uintptr_t)pdata->recv_buf;
319+
pdata->info.mem[RECV_BUF_MAP].size = RECV_BUFFER_SIZE;
320+
pdata->info.mem[RECV_BUF_MAP].memtype = UIO_MEM_VIRTUAL;
321+
322+
pdata->send_buf = vzalloc(SEND_BUFFER_SIZE);
323+
if (!pdata->send_buf) {
324+
ret = -ENOMEM;
325+
goto fail_close;
326+
}
327+
328+
ret = vmbus_establish_gpadl(channel, pdata->send_buf,
329+
SEND_BUFFER_SIZE, &pdata->send_gpadl);
330+
if (ret) {
331+
if (!pdata->send_gpadl.decrypted)
332+
vfree(pdata->send_buf);
333+
goto fail_close;
334+
}
335+
336+
snprintf(pdata->send_name, sizeof(pdata->send_name),
337+
"send:%u", pdata->send_gpadl.gpadl_handle);
338+
pdata->info.mem[SEND_BUF_MAP].name = pdata->send_name;
339+
pdata->info.mem[SEND_BUF_MAP].addr = (uintptr_t)pdata->send_buf;
340+
pdata->info.mem[SEND_BUF_MAP].size = SEND_BUFFER_SIZE;
341+
pdata->info.mem[SEND_BUF_MAP].memtype = UIO_MEM_VIRTUAL;
303342
}
304343

305-
ret = vmbus_establish_gpadl(channel, pdata->recv_buf,
306-
RECV_BUFFER_SIZE, &pdata->recv_gpadl);
307-
if (ret) {
308-
if (!pdata->recv_gpadl.decrypted)
309-
vfree(pdata->recv_buf);
310-
goto fail_close;
311-
}
312-
313-
/* put Global Physical Address Label in name */
314-
snprintf(pdata->recv_name, sizeof(pdata->recv_name),
315-
"recv:%u", pdata->recv_gpadl.gpadl_handle);
316-
pdata->info.mem[RECV_BUF_MAP].name = pdata->recv_name;
317-
pdata->info.mem[RECV_BUF_MAP].addr
318-
= (uintptr_t)pdata->recv_buf;
319-
pdata->info.mem[RECV_BUF_MAP].size = RECV_BUFFER_SIZE;
320-
pdata->info.mem[RECV_BUF_MAP].memtype = UIO_MEM_VIRTUAL;
321-
322-
pdata->send_buf = vzalloc(SEND_BUFFER_SIZE);
323-
if (pdata->send_buf == NULL) {
324-
ret = -ENOMEM;
325-
goto fail_close;
326-
}
327-
328-
ret = vmbus_establish_gpadl(channel, pdata->send_buf,
329-
SEND_BUFFER_SIZE, &pdata->send_gpadl);
330-
if (ret) {
331-
if (!pdata->send_gpadl.decrypted)
332-
vfree(pdata->send_buf);
333-
goto fail_close;
334-
}
335-
336-
snprintf(pdata->send_name, sizeof(pdata->send_name),
337-
"send:%u", pdata->send_gpadl.gpadl_handle);
338-
pdata->info.mem[SEND_BUF_MAP].name = pdata->send_name;
339-
pdata->info.mem[SEND_BUF_MAP].addr
340-
= (uintptr_t)pdata->send_buf;
341-
pdata->info.mem[SEND_BUF_MAP].size = SEND_BUFFER_SIZE;
342-
pdata->info.mem[SEND_BUF_MAP].memtype = UIO_MEM_VIRTUAL;
343-
344344
pdata->info.priv = pdata;
345345
pdata->device = dev;
346346

0 commit comments

Comments
 (0)