linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/1] staging: zsmalloc: Ensure handle is never 0 on success
@ 2013-11-22 17:30 Olav Haugan
  2013-11-22 17:30 ` [PATCH v3 1/1] " Olav Haugan
  2013-11-25 20:41 ` [PATCH v3 0/1] " Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Olav Haugan @ 2013-11-22 17:30 UTC (permalink / raw)
  To: gregkh; +Cc: ngupta, sjenning, linux-kernel, minchan, linux-arm-msm,
	Olav Haugan

v3:
Updated commit text with info about affected SoCs.

v2:
Added comments to code.
Updated commit text.

Olav Haugan (1):
  staging: zsmalloc: Ensure handle is never 0 on success

 drivers/staging/zsmalloc/zsmalloc-main.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3 1/1] staging: zsmalloc: Ensure handle is never 0 on success
  2013-11-22 17:30 [PATCH v3 0/1] staging: zsmalloc: Ensure handle is never 0 on success Olav Haugan
@ 2013-11-22 17:30 ` Olav Haugan
  2013-11-25 20:41 ` [PATCH v3 0/1] " Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Olav Haugan @ 2013-11-22 17:30 UTC (permalink / raw)
  To: gregkh; +Cc: ngupta, sjenning, linux-kernel, minchan, linux-arm-msm,
	Olav Haugan

zsmalloc encodes a handle using the pfn and an object
index. On hardware platforms with physical memory starting
at 0x0 the pfn can be 0. This causes the encoded handle to be
0 and is incorrectly interpreted as an allocation failure.

This issue affects all current and future SoCs with physical
memory starting at 0x0. All MSM8974 SoCs which includes
Google Nexus 5 devices are affected.

To prevent this false error we ensure that the encoded handle
will not be 0 when allocation succeeds.

Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
---
 drivers/staging/zsmalloc/zsmalloc-main.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c
index 1a67537..3b950e5 100644
--- a/drivers/staging/zsmalloc/zsmalloc-main.c
+++ b/drivers/staging/zsmalloc/zsmalloc-main.c
@@ -430,7 +430,12 @@ static struct page *get_next_page(struct page *page)
 	return next;
 }
 
-/* Encode <page, obj_idx> as a single handle value */
+/*
+ * Encode <page, obj_idx> as a single handle value.
+ * On hardware platforms with physical memory starting at 0x0 the pfn
+ * could be 0 so we ensure that the handle will never be 0 by adjusting the
+ * encoded obj_idx value before encoding.
+ */
 static void *obj_location_to_handle(struct page *page, unsigned long obj_idx)
 {
 	unsigned long handle;
@@ -441,17 +446,21 @@ 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;
 }
 
-/* Decode <page, obj_idx> pair from the given object handle */
+/*
+ * Decode <page, obj_idx> pair from the given object handle. We adjust the
+ * decoded obj_idx back to its original value since it was adjusted in
+ * obj_location_to_handle().
+ */
 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,
-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3 0/1] staging: zsmalloc: Ensure handle is never 0 on success
  2013-11-22 17:30 [PATCH v3 0/1] staging: zsmalloc: Ensure handle is never 0 on success Olav Haugan
  2013-11-22 17:30 ` [PATCH v3 1/1] " Olav Haugan
@ 2013-11-25 20:41 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2013-11-25 20:41 UTC (permalink / raw)
  To: Olav Haugan; +Cc: ngupta, sjenning, linux-kernel, minchan, linux-arm-msm

On Fri, Nov 22, 2013 at 09:30:40AM -0800, Olav Haugan wrote:
> v3:
> Updated commit text with info about affected SoCs.

You forgot to add a Cc: stable tag :(

I'll go do it...

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-25 20:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-22 17:30 [PATCH v3 0/1] staging: zsmalloc: Ensure handle is never 0 on success Olav Haugan
2013-11-22 17:30 ` [PATCH v3 1/1] " Olav Haugan
2013-11-25 20:41 ` [PATCH v3 0/1] " Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).