RISC-V: Copy kernel memory mappings to userspace addrenv

Copy the kernel mappings to the new (user) address environment. The
copyuing is done exactly once. This relies on the fact that the kernel
L1/L2 mappings will never change, as all of the kernel memory is mapped
upon boot.
This commit is contained in:
Ville Juven 2022-01-17 11:31:19 +02:00 committed by Xiang Xiao
parent 57127b9429
commit 1322f82802

View File

@ -88,6 +88,12 @@
#define ADDRENV_VBASE (CONFIG_ARCH_DATA_VBASE)
/****************************************************************************
* Public Data
****************************************************************************/
extern uintptr_t g_kernel_mappings;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -187,6 +193,38 @@ static int create_spgtables(group_addrenv_t *addrenv)
return i;
}
/****************************************************************************
* Name: copy_kernel_mappings
*
* Description:
* Copy kernel mappings to address environment. Expects that the user page
* table does not contain any mappings yet (as they will be wiped).
*
* Input Parameters:
* addrenv - Describes the address environment. The page tables must exist
* at this point.
*
* Returned value:
* OK on success, ERROR on failure
*
****************************************************************************/
static int copy_kernel_mappings(group_addrenv_t *addrenv)
{
uintptr_t user_mappings = addrenv->spgtables[0];
/* Copy the L1 references */
if (user_mappings == 0)
{
return -EINVAL;
}
memcpy((void *)user_mappings, (void *)g_kernel_mappings, RV_MMU_PAGE_SIZE);
return OK;
}
/****************************************************************************
* Name: create_region
*
@ -343,6 +381,16 @@ int up_addrenv_create(size_t textsize, size_t datasize, size_t heapsize,
goto errout;
}
/* Map the kernel memory for the user */
ret = copy_kernel_mappings(addrenv);
if (ret < 0)
{
serr("ERROR: Failed to copy kernel mappings to new environment");
goto errout;
}
/* Calculate the base addresses for convenience */
resvbase = ADDRENV_VBASE;