Skip to contentSkip to conversation

pvcalls-front: fixes incorrect error handling

PATCH Applied Pan Bian 4 participants 17 messages Nov 22, 2018 – Nov 29, 2018 Xen hypervisor interface

lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH 1/1 pvcalls-front: fixes incorrect error handling

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/pvcalls-front.c +2 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);
+	free_page((unsigned long)map->active.ring);
 	return ret;
 }
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 14 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/pvcalls-front.c +0 -0
index 2f11ca7..77224d8 100644

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 6 lines
drivers/xen/pvcalls-front.c +1 -2
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

-boris

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 392

Quoted 4 lines
drivers/xen/pvcalls-front.c +1 -0
+	free_page((unsigned long)map->active.ring);
 	return ret;
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
In reply to Pan Bian
Quoted 14 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/pvcalls-front.c +0 -0
index 2f11ca7..77224d8 100644

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 6 lines
drivers/xen/pvcalls-front.c +1 -2
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

-boris

Quoted 4 lines
drivers/xen/pvcalls-front.c +1 -0
+	free_page((unsigned long)map->active.ring);
 	return ret;
 }
 
author
#3 lore raw
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Thanks,
Pan

Quoted 8 lines

-boris

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 392

Quoted 4 lines
drivers/xen/pvcalls-front.c +1 -0
+	free_page((unsigned long)map->active.ring);
 	return ret;
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#4 lore raw
In reply to Boris Ostrovsky
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Thanks,
Pan

Quoted 8 lines

-boris

Quoted 4 lines
drivers/xen/pvcalls-front.c +1 -0
+	free_page((unsigned long)map->active.ring);
 	return ret;
 }
 
#5 lore raw
Quoted 25 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

Quoted 6 lines

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

Quoted 8 lines
Quoted 7 lines

-boris

Quoted 4 lines
drivers/xen/pvcalls-front.c +1 -0
+	free_page((unsigned long)map->active.ring);
 	return ret;
 }
 
#6 lore raw
Quoted 27 lines · Stefano Stabellini
Quoted 26 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

Quoted 8 lines
Quoted 3 lines

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

If map->active.data.in can be non-NULL on entry to this routine then I think this has been a problem all along. Pan's suggestion to use bytes for freeing is going to solve this (assuming bytes will be initialized to NULL).

-boris

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

-boris

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 392

Quoted 4 lines
drivers/xen/pvcalls-front.c +1 -0
+	free_page((unsigned long)map->active.ring);
 	return ret;
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw
In reply to Stefano Stabellini
Quoted 27 lines · Stefano Stabellini
Quoted 26 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

Quoted 8 lines
Quoted 3 lines

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

If map->active.data.in can be non-NULL on entry to this routine then I think this has been a problem all along. Pan's suggestion to use bytes for freeing is going to solve this (assuming bytes will be initialized to NULL).

-boris

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

-boris

Quoted 4 lines
drivers/xen/pvcalls-front.c +1 -0
+	free_page((unsigned long)map->active.ring);
 	return ret;
 }
 
#8 lore raw
Quoted 37 lines · Boris Ostrovsky
Quoted 27 lines · Stefano Stabellini
Quoted 26 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

Quoted 8 lines
Quoted 3 lines

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

Quoted 4 lines

If map->active.data.in can be non-NULL on entry to this routine then I think this has been a problem all along. Pan's suggestion to use bytes for freeing is going to solve this (assuming bytes will be initialized to NULL).

Why is it a problem? map->active.data.in and map->active.ring are only != NULL if they need to be freed. Otherwise, they are NULL. All structs are always initialized to zero. I don't think there are any issues.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw
In reply to Boris Ostrovsky
Quoted 37 lines · Boris Ostrovsky
Quoted 27 lines · Stefano Stabellini
Quoted 26 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

Quoted 8 lines
Quoted 3 lines

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

Quoted 4 lines

If map->active.data.in can be non-NULL on entry to this routine then I think this has been a problem all along. Pan's suggestion to use bytes for freeing is going to solve this (assuming bytes will be initialized to NULL).

Why is it a problem? map->active.data.in and map->active.ring are only != NULL if they need to be freed. Otherwise, they are NULL. All structs are always initialized to zero. I don't think there are any issues.

#10 lore raw
Quoted 37 lines · Stefano Stabellini
Quoted 36 lines · Boris Ostrovsky
Quoted 35 lines · Stefano Stabellini
Quoted 23 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

Quoted 6 lines

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

Quoted 6 lines
Quoted 4 lines

If map->active.data.in can be non-NULL on entry to this routine then I think this has been a problem all along. Pan's suggestion to use bytes for freeing is going to solve this (assuming bytes will be initialized to NULL).

Why is it a problem? map->active.data.in and map->active.ring are only != NULL if they need to be freed. Otherwise, they are NULL.

That was my question --- I wasn't sure about it, and I read your previous message as if it was possible to be calling create_active() with map->active.data.in pointing somewhere non-NULL.

If it is NULL *upon entry* to calling_create() then Pan's original patch is fine.

-boris

Quoted 2 lines

All structs
are always initialized to zero. I don't think there are any issues.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#11 lore raw
In reply to Stefano Stabellini
Quoted 37 lines · Stefano Stabellini
Quoted 36 lines · Boris Ostrovsky
Quoted 35 lines · Stefano Stabellini
Quoted 23 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

Quoted 6 lines

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

Quoted 6 lines
Quoted 4 lines

If map->active.data.in can be non-NULL on entry to this routine then I think this has been a problem all along. Pan's suggestion to use bytes for freeing is going to solve this (assuming bytes will be initialized to NULL).

Why is it a problem? map->active.data.in and map->active.ring are only != NULL if they need to be freed. Otherwise, they are NULL.

That was my question --- I wasn't sure about it, and I read your previous message as if it was possible to be calling create_active() with map->active.data.in pointing somewhere non-NULL.

If it is NULL *upon entry* to calling_create() then Pan's original patch is fine.

-boris

Quoted 2 lines

All structs
are always initialized to zero. I don't think there are any issues.

maintainer Reviewed-by
#12 lore raw
Quoted 45 lines · Boris Ostrovsky
Quoted 37 lines · Stefano Stabellini
Quoted 36 lines · Boris Ostrovsky
Quoted 35 lines · Stefano Stabellini
Quoted 23 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

Quoted 6 lines

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

Quoted 6 lines
Quoted 4 lines

If map->active.data.in can be non-NULL on entry to this routine then I think this has been a problem all along. Pan's suggestion to use bytes for freeing is going to solve this (assuming bytes will be initialized to NULL).

Why is it a problem? map->active.data.in and map->active.ring are only != NULL if they need to be freed. Otherwise, they are NULL.

Quoted 6 lines

That was my question --- I wasn't sure about it, and I read your previous message as if it was possible to be calling create_active() with map->active.data.in pointing somewhere non-NULL.

If it is NULL *upon entry* to calling_create() then Pan's original patch is fine.

Right, I think it is fine too.

Quoted 3 lines
Quoted 2 lines

All structs
are always initialized to zero. I don't think there are any issues.

maintainer Reviewed-by
#13 lore raw
In reply to Boris Ostrovsky
Quoted 45 lines · Boris Ostrovsky
Quoted 37 lines · Stefano Stabellini
Quoted 36 lines · Boris Ostrovsky
Quoted 35 lines · Stefano Stabellini
Quoted 23 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

Quoted 6 lines

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

Quoted 6 lines
Quoted 4 lines

If map->active.data.in can be non-NULL on entry to this routine then I think this has been a problem all along. Pan's suggestion to use bytes for freeing is going to solve this (assuming bytes will be initialized to NULL).

Why is it a problem? map->active.data.in and map->active.ring are only != NULL if they need to be freed. Otherwise, they are NULL.

Quoted 6 lines

That was my question --- I wasn't sure about it, and I read your previous message as if it was possible to be calling create_active() with map->active.data.in pointing somewhere non-NULL.

If it is NULL *upon entry* to calling_create() then Pan's original patch is fine.

Right, I think it is fine too.

Quoted 3 lines
Quoted 2 lines

All structs
are always initialized to zero. I don't think there are any issues.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw
In reply to PanBian
Quoted 25 lines · PanBian
Quoted 10 lines · Boris Ostrovsky
Quoted 9 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

---
 drivers/xen/pvcalls-front.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 388

Quoted 11 lines
drivers/xen/pvcalls-front.c +1 -2
index 2f11ca7..77224d8 100644
@@ -385,8 +385,8 @@ static int create_active(struct sock_mapping *map, int *evtchn)
 out_error:
 	if (*evtchn >= 0)
 		xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
-	kfree(map->active.data.in);
-	kfree(map->active.ring);
+	free_pages((unsigned long)map->active.data.in, PVCALLS_RING_ORDER);

Is map->active.data.in guaranteed to be NULL when entering this routine?

Quoted 6 lines

I am not sure yet. Sorry for that. I observed the mismatches between __get_free_page and kfree, and submitted the patch.

But I think your consideration is reasonable. A better solution is to directly free bytes, a local variable that holds __get_free_pages return value. If you agree, I will rewrite the patch.

Like Boris said, map->active.ring and map->active.data.in are not guaranteed to be NULL or != NULL here. For instance,map->active.ring can be != NULL and map->active.data.in can be NULL. However, free_pages and free_page should be able to cope with it, the same way that kfree is able to cope with it?

Quoted 8 lines
Quoted 7 lines

-boris

drivers/xen/pvcalls-front.c static int create_active(struct sock_mapping *map, int *evtchn) · line 392

Quoted 4 lines
drivers/xen/pvcalls-front.c +1 -0
+	free_page((unsigned long)map->active.ring);
 	return ret;
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

maintainer Applied
#15 lore raw
In reply to Pan Bian
Quoted 5 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

Pushed to xen/tip.git for-linus-4.20a

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

maintainer Applied
#16 lore raw
In reply to Pan Bian
Quoted 5 lines · Pan Bian

kfree() is incorrectly used to release the pages allocated by __get_free_page() and __get_free_pages(). Use the matching deallocators i.e., free_page() and free_pages(), respectively.

Pushed to xen/tip.git for-linus-4.20a

Juergen