Whamcloud - gitweb
LU-10026 ptlrpc: verify large allocations are aligned 44/57844/15
authorPatrick Farrell <pfarrell@whamcloud.com>
Thu, 28 Sep 2023 00:09:03 +0000 (20:09 -0400)
committerOleg Drokin <green@whamcloud.com>
Sat, 7 Jun 2025 23:00:09 +0000 (23:00 +0000)
If we were ever to do an allocation with kmalloc(), we could
get non-page-aligned memory.

We haven't seen any problem yet, but we are trying to be ready for
this in advance. The arguments from https://lwn.net/Articles/787740/
also look strong.

Let's add an assertion to illuminate this dangerous behaviour.

EX-bug-id: EX-8245
Signed-off-by: Patrick Farrell <pfarrell@whamcloud.com>
Signed-off-by: Artem Blagodarenko <ablagodarenko@ddn.com>
Change-Id: Id20898065b516d363d9dc280e71be1b5cfb6f4a7
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57844
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Sergey Cheremencev <scherementsev@ddn.com>
Tested-by: Maloo <maloo@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
lustre/obdclass/page_pools.c

index edc4b0b..34d8695 100644 (file)
@@ -569,6 +569,18 @@ static int pool_add_objects(int nobjects, struct obd_page_pool *page_pool)
                        else {
                                OBD_ALLOC_LARGE(ptr_pages[i][j],
                                        object_size(page_pool));
+                               /*
+                                * It is possible that at some moment kmalloc
+                                * will start to return non-page aligned memory,
+                                * so leave this assort for quicker problem
+                                * detection
+                                */
+                               LASSERTF(IS_ALIGNED((unsigned long)
+                                                   (ptr_pages[i][j]),
+                                                   PAGE_SIZE),
+                                   "Page %p (order %i) is not aligned to PAGE_SIZE",
+                                   ptr_pages[i][j], page_pool->opp_order);
+
                        }
                        if (ptr_pages[i][j] == NULL)
                                goto out_ptr_pages;