From 7b2c7b92befda002f51e7cc4d02bd0853be88d9e Mon Sep 17 00:00:00 2001 From: Breno Leitao Date: Thu, 7 Jun 2018 13:57:34 +0000 Subject: [PATCH] md: use prestaged mfs_root On PowerNV systems, the rootfs is passed through kexec, which loads the rootfs into memory and set two fdt entries to describe where the file is located in the memory; I need to pass this memory region to the md device as a mfs_root, but, current md driver does not support two things: * Just getting a pointer from an external (bootloader) memory. If I need to workaround it, I would need to declare a static array and memcopy from this external memory to this static variable. * The size of the image. The usage of mfs_root_end, which is not a pointer, seems to be not possible for this prestaged scenario. This patch simply adds a new way to load mfs_root from memory. Differential Revision: https://reviews.freebsd.org/D15625 Approved by: kib, jhibbits (mentor) --- sys/conf/NOTES | 3 +++ sys/conf/options | 1 + sys/dev/md/md.c | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/sys/conf/NOTES b/sys/conf/NOTES index 06b05437f4bf..2f358d1a0f84 100644 --- a/sys/conf/NOTES +++ b/sys/conf/NOTES @@ -1111,6 +1111,9 @@ options MD_ROOT # Write-protect the md root device so that it may not be mounted writeable. options MD_ROOT_READONLY +# Allow to read MD image from external memory regions +options MD_ROOT_MEM + # Disk quotas are supported when this option is enabled. options QUOTA #enable disk quotas diff --git a/sys/conf/options b/sys/conf/options index dcfdf495e6cc..01639fa72e5d 100644 --- a/sys/conf/options +++ b/sys/conf/options @@ -168,6 +168,7 @@ MD_ROOT opt_md.h MD_ROOT_FSTYPE opt_md.h MD_ROOT_READONLY opt_md.h MD_ROOT_SIZE opt_md.h +MD_ROOT_MEM opt_md.h MFI_DEBUG opt_mfi.h MFI_DECODE_LOG opt_mfi.h MPROF_BUFFERS opt_mprof.h diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c index be661b2703c7..2209c6680be5 100644 --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -180,6 +180,10 @@ SYSCTL_INT(_vm, OID_AUTO, md_malloc_wait, CTLFLAG_RW, &md_malloc_wait, 0, */ u_char mfs_root[MD_ROOT_SIZE*1024] __attribute__ ((section ("oldmfs"))); const int mfs_root_size = sizeof(mfs_root); +#elif defined(MD_ROOT_MEM) +/* MD region already mapped in the memory */ +u_char *mfs_root; +int mfs_root_size; #else extern volatile u_char __weak_symbol mfs_root; extern volatile u_char __weak_symbol mfs_root_end; @@ -2074,8 +2078,12 @@ g_md_init(struct g_class *mp __unused) #ifdef MD_ROOT if (mfs_root_size != 0) { sx_xlock(&md_sx); +#ifdef MD_ROOT_MEM + md_preloaded(mfs_root, mfs_root_size, NULL); +#else md_preloaded(__DEVOLATILE(u_char *, &mfs_root), mfs_root_size, NULL); +#endif sx_xunlock(&md_sx); } #endif