lkml.org 
[lkml]   [2023]   [Mar]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] migrate_pages: silence gcc notes for mis-casting
Date
The following GCC notes was reported for commit 64c8902ed441
("migrate_pages: split unmap_and_move() to _unmap() and _move()").

mm/migrate.c: In function ‘__migrate_folio_extract’:
mm/migrate.c:1050:20: note: randstruct: casting between randomized
structure pointer types (ssa): ‘struct anon_vma’ and ‘struct
address_space’

1050 | *anon_vmap = (void *)dst->mapping;
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

The casting itself is safe. Because we only use dst->mapping to store
the pointer itself temporarily and dst is a newly allocated folio and
not used by anyone else during that. But the notes should be silenced
and some comments are deserved. So, we do that in this patch.

Fixes: 64c8902ed441 ("migrate_pages: split unmap_and_move() to _unmap() and _move()")
Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Xin Hao <xhao@linux.alibaba.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Bharata B Rao <bharata@amd.com>
Cc: Alistair Popple <apopple@nvidia.com>
---
mm/migrate.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index c17ce5ee8d92..53fcc23025c7 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1047,7 +1047,16 @@ static void __migrate_folio_extract(struct folio *dst,
int *page_was_mappedp,
struct anon_vma **anon_vmap)
{
- *anon_vmap = (void *)dst->mapping;
+ struct anon_vma *anon_vma;
+
+ /*
+ * 2 steps assignment to silence gcc notes for mis-casting. The
+ * casting is safe. Because we only use dst->mapping to store
+ * the pointer itself temporarily and dst is a newly allocated
+ * folio and not used by anyone else during that.
+ */
+ anon_vma = (void *)dst->mapping;
+ *anon_vmap = anon_vma;
*page_was_mappedp = (unsigned long)dst->private;
dst->mapping = NULL;
dst->private = NULL;
--
2.39.2
\
 
 \ /
  Last update: 2023-03-27 00:41    [W:0.026 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site