arch/riscv/kernel/vdso.c

Source file repositories/reference/linux-study-clean/arch/riscv/kernel/vdso.c

File Facts

System
Linux kernel
Corpus path
arch/riscv/kernel/vdso.c
Extension
.c
Size
4344 bytes
Lines
188
Domain
Architecture Layer
Bucket
arch/riscv
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

struct __vdso_info {
	const char *name;
	const char *vdso_code_start;
	const char *vdso_code_end;
	unsigned long vdso_pages;
	/* Code Mapping */
	struct vm_special_mapping *cm;
};

static struct __vdso_info vdso_info;
#ifdef CONFIG_COMPAT
static struct __vdso_info compat_vdso_info;
#endif

static int vdso_mremap(const struct vm_special_mapping *sm,
		       struct vm_area_struct *new_vma)
{
	current->mm->context.vdso = (void *)new_vma->vm_start;

	return 0;
}

static void __init __vdso_init(struct __vdso_info *vdso_info)
{
	unsigned int i;
	struct page **vdso_pagelist;
	unsigned long pfn;

	if (memcmp(vdso_info->vdso_code_start, "\177ELF", 4))
		panic("vDSO is not a valid ELF object!\n");

	vdso_info->vdso_pages = (
		vdso_info->vdso_code_end -
		vdso_info->vdso_code_start) >>
		PAGE_SHIFT;

	vdso_pagelist = kzalloc_objs(struct page *, vdso_info->vdso_pages);
	if (vdso_pagelist == NULL)
		panic("vDSO kcalloc failed!\n");

	/* Grab the vDSO code pages. */
	pfn = sym_to_pfn(vdso_info->vdso_code_start);

	for (i = 0; i < vdso_info->vdso_pages; i++)
		vdso_pagelist[i] = pfn_to_page(pfn + i);

	vdso_info->cm->pages = vdso_pagelist;
}

static struct vm_special_mapping rv_vdso_map __ro_after_init = {
	.name   = "[vdso]",
	.mremap = vdso_mremap,
};

static struct __vdso_info vdso_info __ro_after_init = {
	.name = "vdso",
	.vdso_code_start = vdso_start,
	.vdso_code_end = vdso_end,
	.cm = &rv_vdso_map,
};

#ifdef CONFIG_COMPAT
static struct vm_special_mapping rv_compat_vdso_map __ro_after_init = {
	.name   = "[vdso]",
	.mremap = vdso_mremap,
};

static struct __vdso_info compat_vdso_info __ro_after_init = {
	.name = "compat_vdso",
	.vdso_code_start = compat_vdso_start,
	.vdso_code_end = compat_vdso_end,
	.cm = &rv_compat_vdso_map,
};
#endif

static int __init vdso_init(void)
{
	/* Hart implements zimop, expose cfi compiled vdso */
	if (IS_ENABLED(CONFIG_RISCV_USER_CFI) &&
	    riscv_has_extension_unlikely(RISCV_ISA_EXT_ZIMOP)) {
		vdso_info.vdso_code_start = vdso_cfi_start;
		vdso_info.vdso_code_end = vdso_cfi_end;
	}

	__vdso_init(&vdso_info);
#ifdef CONFIG_COMPAT
	__vdso_init(&compat_vdso_info);
#endif

	return 0;

Annotation

Implementation Notes