[PATCH v2 2/2] platform/x86: dell_rbu: Allocate large monolithic images contiguously

From: Rosen Penev

Date: Fri Nov 13 2026 - 21:08:51 EST


Monolithic RBU images must live in a single physically contiguous block
below 4GB. img_update_realloc() gets that block from __get_free_pages(),
which cannot return more than MAX_PAGE_ORDER (4MB on x86). Current Dell
BIOS packages are larger than that: the Precision M4800 A26 image
(the PFS container extracted from the update executable) is about 16MB,
and SMBIOS structure 0xDE on that system reports no packet-mode support,
so the image cannot be loaded at all.

When the required order exceeds MAX_PAGE_ORDER, fall back to
alloc_contig_pages() with __GFP_DMA32 so the range is still below 4GB,
and free it with free_contig_range(). Smaller images keep using the
buddy allocator as before.

Tested on a Precision M4800 by uploading the 16MB A26 image through
/sys/class/firmware/dell_rbu and reading it back byte-for-byte from
/sys/devices/platform/dell_rbu/data; a 300KB image still uses the
buddy allocator path.

Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
---
drivers/platform/x86/dell/dell_rbu.c | 54 +++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/dell/dell_rbu.c b/drivers/platform/x86/dell/dell_rbu.c
index a121f59a215d..d71fa9584831 100644
--- a/drivers/platform/x86/dell/dell_rbu.c
+++ b/drivers/platform/x86/dell/dell_rbu.c
@@ -41,6 +41,8 @@
#include <linux/moduleparam.h>
#include <linux/firmware.h>
#include <linux/dma-mapping.h>
+#include <linux/gfp.h>
+#include <linux/mm.h>
#include <asm/set_memory.h>

MODULE_AUTHOR("Abhay Salunke <abhay_salunke@xxxxxxxx>");
@@ -55,6 +57,7 @@ static struct _rbu_data {
unsigned long image_update_buffer_size;
unsigned long bios_image_size;
int image_update_ordernum;
+ unsigned long image_update_contig_pages;
spinlock_t lock;
unsigned long packet_read_count;
unsigned long num_packets;
@@ -335,6 +338,37 @@ static void packet_empty_list(void)
rbu_data.imagesize = 0;
}

+/*
+ * Monolithic images must sit in one physically contiguous block below 4GB.
+ * Current BIOS images (16MB on some systems) exceed what the buddy allocator
+ * can hand out (MAX_PAGE_ORDER), so fall back to the contiguous range
+ * allocator for those when it is available.
+ */
+#ifdef CONFIG_CONTIG_ALLOC
+static void *img_alloc_contig(unsigned long nr_pages)
+{
+ struct page *page;
+
+ page = alloc_contig_pages(nr_pages, GFP_KERNEL | __GFP_DMA32 | __GFP_NOWARN,
+ first_online_node, NULL);
+ return page ? page_address(page) : NULL;
+}
+
+static void img_free_contig(void *buf, unsigned long nr_pages)
+{
+ free_contig_range(PHYS_PFN(virt_to_phys(buf)), nr_pages);
+}
+#else
+static void *img_alloc_contig(unsigned long nr_pages)
+{
+ return NULL;
+}
+
+static void img_free_contig(void *buf, unsigned long nr_pages)
+{
+}
+#endif
+
/*
* img_update_free: Frees the buffer allocated for storing BIOS image
* Always called with lock held and returned with lock held
@@ -349,13 +383,18 @@ static void img_update_free(void)
*/
memset(rbu_data.image_update_buffer, 0,
rbu_data.image_update_buffer_size);
- free_pages((unsigned long) rbu_data.image_update_buffer,
- rbu_data.image_update_ordernum);
+ if (rbu_data.image_update_contig_pages)
+ img_free_contig(rbu_data.image_update_buffer,
+ rbu_data.image_update_contig_pages);
+ else
+ free_pages((unsigned long) rbu_data.image_update_buffer,
+ rbu_data.image_update_ordernum);

/*
* Re-initialize the rbu_data variables after a free
*/
rbu_data.image_update_ordernum = -1;
+ rbu_data.image_update_contig_pages = 0;
rbu_data.image_update_buffer = NULL;
rbu_data.image_update_buffer_size = 0;
rbu_data.bios_image_size = 0;
@@ -375,6 +414,7 @@ static int img_update_realloc(unsigned long size)
{
unsigned char *image_update_buffer = NULL;
unsigned long img_buf_phys_addr;
+ unsigned long contig_pages = 0;
int ordernum;

/*
@@ -404,8 +444,13 @@ static int img_update_realloc(unsigned long size)
spin_unlock(&rbu_data.lock);

ordernum = get_order(size);
- image_update_buffer =
- (unsigned char *)__get_free_pages(GFP_DMA32, ordernum);
+ if (ordernum <= MAX_PAGE_ORDER) {
+ image_update_buffer =
+ (unsigned char *)__get_free_pages(GFP_DMA32, ordernum);
+ } else {
+ contig_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
+ image_update_buffer = img_alloc_contig(contig_pages);
+ }
spin_lock(&rbu_data.lock);
if (!image_update_buffer) {
pr_debug("Not enough memory for image update: size = %ld\n", size);
@@ -420,6 +465,7 @@ static int img_update_realloc(unsigned long size)
rbu_data.image_update_buffer_size = size;
rbu_data.bios_image_size = rbu_data.image_update_buffer_size;
rbu_data.image_update_ordernum = ordernum;
+ rbu_data.image_update_contig_pages = contig_pages;
return 0;
}

--
2.56.1