staging: zsmalloc: Ensure handle is never 0 on success
Subsystems (2)
PATCH 1/1 staging: zsmalloc: Ensure handle is never 0 on success
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
--- drivers/staging/zsmalloc/zsmalloc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/zsmalloc/zsmalloc-main.c +2 -2
@@ -441,7 +441,7 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) } handle =page_to_pfn (page) <<OBJ_INDEX_BITS ; - handle |= (obj_idx &OBJ_INDEX_MASK ); + handle |= ((obj_idx +1 ) &OBJ_INDEX_MASK );return (void *)handle; }
@@ -451,7 +451,7 @@ static void obj_handle_to_location(unsigned long handle, struct page **page, unsigned long *obj_idx) { *page =pfn_to_page (handle >>OBJ_INDEX_BITS ); - *obj_idx = handle &OBJ_INDEX_MASK ; + *obj_idx = (handle &OBJ_INDEX_MASK ) -1 ; } static unsigned long obj_idx_to_offset(struct page *page,
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Hi Olav,
Quoted 19 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
Change-Id Ifff930dcf254915b497aec5cb36f152a5e5365d6Signed-off-by Olav Haugan <[email protected]>--- drivers/staging/zsmalloc/zsmalloc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/zsmalloc/zsmalloc-main.c +0
-0
drivers/staging/zsmalloc/zsmalloc-main.c static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) · line 444
Quoted 5 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -441,7 +441,7 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) } handle =page_to_pfn (page) <<OBJ_INDEX_BITS ; - handle |= (obj_idx &OBJ_INDEX_MASK ); + handle |= ((obj_idx +1 ) &OBJ_INDEX_MASK );
As suggestion you could use a macro instead of hardcoded 1.
I am not familiar with this code, but if it's a valid test to verify if the resulting address is page aligned, you might want to set this offset macro to a page aligned value as well.
drivers/staging/zsmalloc/zsmalloc-main.c static void obj_handle_to_location(unsigned long handle, struct page **page, · line 454
Quoted 9 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1
-1return (void *)handle; }@@ -451,7 +451,7 @@ static void obj_handle_to_location(unsigned long handle, struct page **page, unsigned long *obj_idx) { *page =pfn_to_page (handle >>OBJ_INDEX_BITS ); - *obj_idx = handle &OBJ_INDEX_MASK ; + *obj_idx = (handle &OBJ_INDEX_MASK ) -1 ;
Ditto.
Br, David Cohen
Quoted 35 lines · David Cohen
Hi Olav,
Quoted 21 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
Change-Id Ifff930dcf254915b497aec5cb36f152a5e5365d6Signed-off-by Olav Haugan <[email protected]>--- drivers/staging/zsmalloc/zsmalloc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/zsmalloc/zsmalloc-main.c +0
-0drivers/staging/zsmalloc/zsmalloc-main.c static void *obj_location_to_handle(struct page *page, · line 445
Quoted 6 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -441,7 +441,7 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) } handle =page_to_pfn (page) <<OBJ_INDEX_BITS ; - handle |= (obj_idx &OBJ_INDEX_MASK ); + handle |= ((obj_idx +1 ) &OBJ_INDEX_MASK );As suggestion you could use a macro instead of hardcoded 1.
Quoted 5 lines
I am not familiar with this code, but if it's a valid test to verify if the resulting address is page aligned, you might want to set this offset macro to a page aligned value as well.
Using a hardcoded 1 looks fine in this case. But the patch description should also be added as a comment for this function. Otherwise, the patch looks good to me.
Quoted 14 lines
drivers/staging/zsmalloc/zsmalloc-main.c static void obj_handle_to_location(unsigned long · line 455
Quoted 10 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1
-1return (void *)handle; }@@ -451,7 +451,7 @@ static void obj_handle_to_location(unsigned long handle, struct page **page, unsigned long *obj_idx) { *page =pfn_to_page (handle >>OBJ_INDEX_BITS ); - *obj_idx = handle &OBJ_INDEX_MASK ; + *obj_idx = (handle &OBJ_INDEX_MASK ) -1 ;Ditto.
Thanks,
Nitin
Quoted 43 lines · Nitin Gupta
Quoted 35 lines · David Cohen
Hi Olav,
Quoted 21 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
Change-Id Ifff930dcf254915b497aec5cb36f152a5e5365d6Signed-off-by Olav Haugan <[email protected]>--- drivers/staging/zsmalloc/zsmalloc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/zsmalloc/zsmalloc-main.c +0
-0drivers/staging/zsmalloc/zsmalloc-main.c static void *obj_location_to_handle(struct page *page, · line 445
Quoted 6 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -441,7 +441,7 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) } handle =page_to_pfn (page) <<OBJ_INDEX_BITS ; - handle |= (obj_idx &OBJ_INDEX_MASK ); + handle |= ((obj_idx +1 ) &OBJ_INDEX_MASK );As suggestion you could use a macro instead of hardcoded 1.
Quoted 5 lines
I am not familiar with this code, but if it's a valid test to verify if the resulting address is page aligned, you might want to set this offset macro to a page aligned value as well.
Quoted 4 lines
Using a hardcoded 1 looks fine in this case. But the patch description should also be added as a comment for this function. Otherwise, the patch looks good to me.
Sure, I can add a comment above obj_location_to_handle() and obj_handle_to_location().
Olav Haugan
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Greg KH
maintainerQuoted 4 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
What platforms specifically have this issue?
Quoted 5 lines
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
Change-Id: Ifff930dcf254915b497aec5cb36f152a5e5365d6
What is this? What can anyone do with it?
Quoted 19 lines
Signed-off-by Olav Haugan <[email protected]>--- drivers/staging/zsmalloc/zsmalloc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -441,7 +441,7 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) } handle =page_to_pfn (page) <<OBJ_INDEX_BITS ; - handle |= (obj_idx &OBJ_INDEX_MASK ); + handle |= ((obj_idx +1 ) &OBJ_INDEX_MASK );return (void *)handle; }
drivers/staging/zsmalloc/zsmalloc-main.c static void obj_handle_to_location(unsigned long handle, struct page **page, · line 455
Quoted 6 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -451,7 +451,7 @@ static void obj_handle_to_location(unsigned long handle, struct page **page, unsigned long *obj_idx) { *page =pfn_to_page (handle >>OBJ_INDEX_BITS ); - *obj_idx = handle &OBJ_INDEX_MASK ; + *obj_idx = (handle &OBJ_INDEX_MASK ) -1 ; }
I need someone who knows how to test this code to ack it before I can take it...
And I thought we were deleting zsmalloc anyway, why are you using this code? Isn't it no longer needed anymore?
greg k-h
Quoted 45 lines · Greg KH
Quoted 4 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
What platforms specifically have this issue?
Quoted 5 lines
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
Change-Id: Ifff930dcf254915b497aec5cb36f152a5e5365d6
What is this? What can anyone do with it?
Quoted 19 lines
Signed-off-by Olav Haugan <[email protected]>--- drivers/staging/zsmalloc/zsmalloc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -441,7 +441,7 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) } handle =page_to_pfn (page) <<OBJ_INDEX_BITS ; - handle |= (obj_idx &OBJ_INDEX_MASK ); + handle |= ((obj_idx +1 ) &OBJ_INDEX_MASK );return (void *)handle; }drivers/staging/zsmalloc/zsmalloc-main.c static void obj_handle_to_location(unsigned long handle, struct page **page, · line 455
Quoted 6 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -451,7 +451,7 @@ static void obj_handle_to_location(unsigned long handle, struct page **page, unsigned long *obj_idx) { *page =pfn_to_page (handle >>OBJ_INDEX_BITS ); - *obj_idx = handle &OBJ_INDEX_MASK ; + *obj_idx = (handle &OBJ_INDEX_MASK ) -1 ; }I need someone who knows how to test this code to ack it before I can take it...
Quoted 3 lines
And I thought we were deleting zsmalloc anyway, why are you using this code? Isn't it no longer needed anymore?
zsmalloc is used by zram. Other zstuff has switched to zbud since they need to do shrinking which is much easier to implement with simpler design of zbud. For zram, which is a block device, we don't do such active shrinking, so uses zsmalloc which provides much better density.
Nitin
Greg KH
maintainerQuoted 46 lines · Nitin Gupta
Quoted 45 lines · Greg KH
Quoted 4 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
What platforms specifically have this issue?
Quoted 5 lines
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
Change-Id: Ifff930dcf254915b497aec5cb36f152a5e5365d6
What is this? What can anyone do with it?
Quoted 19 lines
Signed-off-by Olav Haugan <[email protected]>--- drivers/staging/zsmalloc/zsmalloc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -441,7 +441,7 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) } handle =page_to_pfn (page) <<OBJ_INDEX_BITS ; - handle |= (obj_idx &OBJ_INDEX_MASK ); + handle |= ((obj_idx +1 ) &OBJ_INDEX_MASK );return (void *)handle; }drivers/staging/zsmalloc/zsmalloc-main.c static void obj_handle_to_location(unsigned long handle, struct page **page, · line 455
Quoted 6 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -451,7 +451,7 @@ static void obj_handle_to_location(unsigned long handle, struct page **page, unsigned long *obj_idx) { *page =pfn_to_page (handle >>OBJ_INDEX_BITS ); - *obj_idx = handle &OBJ_INDEX_MASK ; + *obj_idx = (handle &OBJ_INDEX_MASK ) -1 ; }I need someone who knows how to test this code to ack it before I can take it...
Quoted 8 lines
Quoted 3 lines
And I thought we were deleting zsmalloc anyway, why are you using this code? Isn't it no longer needed anymore?
zsmalloc is used by zram. Other zstuff has switched to zbud since they need to do shrinking which is much easier to implement with simpler design of zbud. For zram, which is a block device, we don't do such active shrinking, so uses zsmalloc which provides much better density.
Ok, so what's the plan of getting these other things out of staging? I'm getting really tired of them hanging around in here for many years now...
Should I just remove them if no one is working on getting them merged "properly"?
thanks,
greg k-h
Quoted 51 lines · Greg KH
Quoted 50 lines · Nitin Gupta
Quoted 48 lines · Greg KH
Quoted 4 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
What platforms specifically have this issue?
Quoted 5 lines
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
Change-Id: Ifff930dcf254915b497aec5cb36f152a5e5365d6
What is this? What can anyone do with it?
Quoted 19 lines
Signed-off-by Olav Haugan <[email protected]>--- drivers/staging/zsmalloc/zsmalloc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -441,7 +441,7 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) } handle =page_to_pfn (page) <<OBJ_INDEX_BITS ; - handle |= (obj_idx &OBJ_INDEX_MASK ); + handle |= ((obj_idx +1 ) &OBJ_INDEX_MASK );return (void *)handle; }drivers/staging/zsmalloc/zsmalloc-main.c static void obj_handle_to_location(unsigned long handle, struct page **page, · line 455
Quoted 6 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1
-1@@ -451,7 +451,7 @@ static void obj_handle_to_location(unsigned long handle, struct page **page, unsigned long *obj_idx) { *page =pfn_to_page (handle >>OBJ_INDEX_BITS ); - *obj_idx = handle &OBJ_INDEX_MASK ; + *obj_idx = (handle &OBJ_INDEX_MASK ) -1 ; }I need someone who knows how to test this code to ack it before I can take it...
And I thought we were deleting zsmalloc anyway, why are you using this code? Isn't it no longer needed anymore?
Quoted 6 lines
Quoted 4 lines
zsmalloc is used by zram. Other zstuff has switched to zbud since they need to do shrinking which is much easier to implement with simpler design of zbud. For zram, which is a block device, we don't do such active shrinking, so uses zsmalloc which provides much better density.
Ok, so what's the plan of getting these other things out of staging?
Other zstuff: zswap and zcache
1) zswap (along with zbud allocator, frontcache, cleancache) is already out of staging into mm/ (by Seth Jennings)
2) zcache seems to have been completely removed (not sure if Dan ever wants to reintroduce it)
Quoted 3 lines
I'm getting really tired of them hanging around in here for many years now...
Minchan has tried many times to promote zram out of staging. This was his most recent attempt:
https://lkml.org/lkml/2013/8/21/54
There he provided arguments for zram inclusion, how it can help in situations where zswap can't and why generalizing /dev/ramX would not be a great idea. So, cannot say why it wasn't picked up for inclusion at that time.
Quoted 3 lines
Should I just remove them if no one is working on getting them merged "properly"?
Please refer the mail thread (link above) and see Minchan's justifications for zram.
If they don't sound convincing enough then please remove zram+zsmalloc from staging.
Nitin
Greg KH
maintainerQuoted 14 lines · Nitin Gupta
I'm getting really tired of them hanging around in here for many years
Quoted 2 lines
now...
Minchan has tried many times to promote zram out of staging. This was his most recent attempt:
https://lkml.org/lkml/2013/8/21/54
There he provided arguments for zram inclusion, how it can help in situations where zswap can't and why generalizing
/dev/ramXwould not be a great idea. So, cannot say why it wasn't picked up for inclusion at that time.
Quoted 8 lines
Quoted 3 lines
Should I just remove them if no one is working on getting them merged "properly"?
Please refer the mail thread (link above) and see Minchan's justifications for zram.
If they don't sound convincing enough then please remove zram+zsmalloc from staging.
You don't need to be convincing me, you need to be convincing the maintainers of the area of the kernel you are working with.
And since the last time you all tried to get this merged was back in August, I'm feeling that you all have given up, so it needs to be deleted. I'll go do that for 3.14, and if someone wants to pick it up and merge it properly, they can easily revert it.
thanks,
greg k-h
Quoted 7 lines · Greg KH
Quoted 4 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
What platforms specifically have this issue?
Currently some of Qualcomm SoC's have physical memory that starts at address 0x0 which causes this problem. I believe this could be a problem on any platforms if memory is configured to be starting at physical address 0x0 for these platforms.
Quoted 7 lines
Quoted 5 lines
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
Change-Id: Ifff930dcf254915b497aec5cb36f152a5e5365d6
What is this? What can anyone do with it?
This is an identifier used by "Gerrit Code Review" to track changes to the same patch. I will remove it.
Olav Haugan
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Greg KH
maintainerQuoted 11 lines · Olav Haugan
Quoted 7 lines · Greg KH
Quoted 4 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
What platforms specifically have this issue?
Currently some of Qualcomm SoC's have physical memory that starts at address
0x0which causes this problem.
Then say this, and list the exact SoC's that can have this problem so people know how to evaluate the bugfix and see if it is relevant for their systems.
Quoted 3 lines
I believe this could be a problem
on any platforms if memory is configured to be starting at physical address0x0for these platforms.
Have you seen this be a problem? So it's just a theoretical issue at this point in time?
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds.
Change-Id: Ifff930dcf254915b497aec5cb36f152a5e5365d6
What is this? What can anyone do with it?
This is an identifier used by "Gerrit Code Review" to track changes to the same patch. I will remove it.
Please do so, it has no place in kernel patches submitted for acceptance.
Please fix up the changelog, and the rest based on the other comments and resend.
thanks,
greg k-h
Quoted 17 lines · Greg KH
Quoted 11 lines · Olav Haugan
Quoted 7 lines · Greg KH
Quoted 4 lines · Olav Haugan
zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure.
What platforms specifically have this issue?
Currently some of Qualcomm SoC's have physical memory that starts at address
0x0which causes this problem.Then say this, and list the exact SoC's that can have this problem so people know how to evaluate the bugfix and see if it is relevant for their systems.
Quoted 6 lines
Quoted 3 lines
I believe this could be a problem
on any platforms if memory is configured to be starting at physical address0x0for these platforms.Have you seen this be a problem? So it's just a theoretical issue at this point in time?
Yes, I can consistently reproduce it. It is not just theoretical.
Thanks,
Olav Haugan
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation