* [PATCH 0/2] Drivers: hv: fix memory leak while establishing GPADL
@ 2016-05-30 9:57 Vitaly Kuznetsov
2016-05-30 9:57 ` [PATCH 1/2] Drivers: hv: get rid of redundant messagecount in create_gpadl_header() Vitaly Kuznetsov
2016-05-30 9:57 ` [PATCH 2/2] Drivers: hv: don't leak memory in vmbus_establish_gpadl() Vitaly Kuznetsov
0 siblings, 2 replies; 3+ messages in thread
From: Vitaly Kuznetsov @ 2016-05-30 9:57 UTC (permalink / raw)
To: devel; +Cc: linux-kernel, K. Y. Srinivasan, Haiyang Zhang
kmemleak helped me to identify a memory leak on GPADL establishment. Do
some minor refactoring and fix the issue.
Vitaly Kuznetsov (2):
Drivers: hv: get rid of redundant messagecount in
create_gpadl_header()
Drivers: hv: don't leak memory in vmbus_establish_gpadl()
drivers/hv/channel.c | 44 +++++++++++++++++++++-----------------------
1 file changed, 21 insertions(+), 23 deletions(-)
--
2.5.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] Drivers: hv: get rid of redundant messagecount in create_gpadl_header()
2016-05-30 9:57 [PATCH 0/2] Drivers: hv: fix memory leak while establishing GPADL Vitaly Kuznetsov
@ 2016-05-30 9:57 ` Vitaly Kuznetsov
2016-05-30 9:57 ` [PATCH 2/2] Drivers: hv: don't leak memory in vmbus_establish_gpadl() Vitaly Kuznetsov
1 sibling, 0 replies; 3+ messages in thread
From: Vitaly Kuznetsov @ 2016-05-30 9:57 UTC (permalink / raw)
To: devel; +Cc: linux-kernel, K. Y. Srinivasan, Haiyang Zhang
We use messagecount only once in vmbus_establish_gpadl() to check if
it is safe to iterate through the submsglist. We can just initialize
the list header in all cases in create_gpadl_header() instead.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
drivers/hv/channel.c | 38 ++++++++++++++++----------------------
1 file changed, 16 insertions(+), 22 deletions(-)
diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 56dd261..2b109e8 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -238,8 +238,7 @@ EXPORT_SYMBOL_GPL(vmbus_send_tl_connect_request);
* create_gpadl_header - Creates a gpadl for the specified buffer
*/
static int create_gpadl_header(void *kbuffer, u32 size,
- struct vmbus_channel_msginfo **msginfo,
- u32 *messagecount)
+ struct vmbus_channel_msginfo **msginfo)
{
int i;
int pagecount;
@@ -283,7 +282,6 @@ static int create_gpadl_header(void *kbuffer, u32 size,
gpadl_header->range[0].pfn_array[i] = slow_virt_to_phys(
kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT;
*msginfo = msgheader;
- *messagecount = 1;
pfnsum = pfncount;
pfnleft = pagecount - pfncount;
@@ -323,7 +321,6 @@ static int create_gpadl_header(void *kbuffer, u32 size,
}
msgbody->msgsize = msgsize;
- (*messagecount)++;
gpadl_body =
(struct vmbus_channel_gpadl_body *)msgbody->msg;
@@ -352,6 +349,8 @@ static int create_gpadl_header(void *kbuffer, u32 size,
msgheader = kzalloc(msgsize, GFP_KERNEL);
if (msgheader == NULL)
goto nomem;
+
+ INIT_LIST_HEAD(&msgheader->submsglist);
msgheader->msgsize = msgsize;
gpadl_header = (struct vmbus_channel_gpadl_header *)
@@ -366,7 +365,6 @@ static int create_gpadl_header(void *kbuffer, u32 size,
kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT;
*msginfo = msgheader;
- *messagecount = 1;
}
return 0;
@@ -391,7 +389,6 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
struct vmbus_channel_gpadl_body *gpadl_body;
struct vmbus_channel_msginfo *msginfo = NULL;
struct vmbus_channel_msginfo *submsginfo;
- u32 msgcount;
struct list_head *curr;
u32 next_gpadl_handle;
unsigned long flags;
@@ -400,7 +397,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
next_gpadl_handle =
(atomic_inc_return(&vmbus_connection.next_gpadl_handle) - 1);
- ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
+ ret = create_gpadl_header(kbuffer, size, &msginfo);
if (ret)
return ret;
@@ -423,24 +420,21 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
if (ret != 0)
goto cleanup;
- if (msgcount > 1) {
- list_for_each(curr, &msginfo->submsglist) {
+ list_for_each(curr, &msginfo->submsglist) {
+ submsginfo = (struct vmbus_channel_msginfo *)curr;
+ gpadl_body =
+ (struct vmbus_channel_gpadl_body *)submsginfo->msg;
- submsginfo = (struct vmbus_channel_msginfo *)curr;
- gpadl_body =
- (struct vmbus_channel_gpadl_body *)submsginfo->msg;
+ gpadl_body->header.msgtype =
+ CHANNELMSG_GPADL_BODY;
+ gpadl_body->gpadl = next_gpadl_handle;
- gpadl_body->header.msgtype =
- CHANNELMSG_GPADL_BODY;
- gpadl_body->gpadl = next_gpadl_handle;
+ ret = vmbus_post_msg(gpadl_body,
+ submsginfo->msgsize -
+ sizeof(*submsginfo));
+ if (ret != 0)
+ goto cleanup;
- ret = vmbus_post_msg(gpadl_body,
- submsginfo->msgsize -
- sizeof(*submsginfo));
- if (ret != 0)
- goto cleanup;
-
- }
}
wait_for_completion(&msginfo->waitevent);
--
2.5.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] Drivers: hv: don't leak memory in vmbus_establish_gpadl()
2016-05-30 9:57 [PATCH 0/2] Drivers: hv: fix memory leak while establishing GPADL Vitaly Kuznetsov
2016-05-30 9:57 ` [PATCH 1/2] Drivers: hv: get rid of redundant messagecount in create_gpadl_header() Vitaly Kuznetsov
@ 2016-05-30 9:57 ` Vitaly Kuznetsov
1 sibling, 0 replies; 3+ messages in thread
From: Vitaly Kuznetsov @ 2016-05-30 9:57 UTC (permalink / raw)
To: devel; +Cc: linux-kernel, K. Y. Srinivasan, Haiyang Zhang
In some cases create_gpadl_header() allocates submessages but we never
free them.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
drivers/hv/channel.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 2b109e8..a68830c 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -388,7 +388,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
struct vmbus_channel_gpadl_header *gpadlmsg;
struct vmbus_channel_gpadl_body *gpadl_body;
struct vmbus_channel_msginfo *msginfo = NULL;
- struct vmbus_channel_msginfo *submsginfo;
+ struct vmbus_channel_msginfo *submsginfo, *tmp;
struct list_head *curr;
u32 next_gpadl_handle;
unsigned long flags;
@@ -445,6 +445,10 @@ cleanup:
spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
list_del(&msginfo->msglistentry);
spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
+ list_for_each_entry_safe(submsginfo, tmp, &msginfo->submsglist,
+ msglistentry) {
+ kfree(submsginfo);
+ }
kfree(msginfo);
return ret;
--
2.5.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-30 9:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-30 9:57 [PATCH 0/2] Drivers: hv: fix memory leak while establishing GPADL Vitaly Kuznetsov
2016-05-30 9:57 ` [PATCH 1/2] Drivers: hv: get rid of redundant messagecount in create_gpadl_header() Vitaly Kuznetsov
2016-05-30 9:57 ` [PATCH 2/2] Drivers: hv: don't leak memory in vmbus_establish_gpadl() Vitaly Kuznetsov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.