summaryrefslogtreecommitdiff
path: root/arch/arm64/include/asm/hyp_image.h
blob: 737ded6b6d0db2d582ea7872847fd36070a5f899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2020 Google LLC.
 * Written by David Brazdil <dbrazdil@google.com>
 */

#ifndef __ARM64_HYP_IMAGE_H__
#define __ARM64_HYP_IMAGE_H__

#define __HYP_CONCAT(a, b)	a ## b
#define HYP_CONCAT(a, b)	__HYP_CONCAT(a, b)

/*
 * KVM nVHE code has its own symbol namespace prefixed with __kvm_nvhe_,
 * to separate it from the kernel proper.
 */
#define kvm_nvhe_sym(sym)	__kvm_nvhe_##sym

#ifdef LINKER_SCRIPT

/*
 * KVM nVHE ELF section names are prefixed with .hyp, to separate them
 * from the kernel proper.
 */
#define HYP_SECTION_NAME(NAME)	.hyp##NAME

/* Symbol defined at the beginning of each hyp section. */
#define HYP_SECTION_SYMBOL_NAME(NAME) \
	HYP_CONCAT(__hyp_section_, HYP_SECTION_NAME(NAME))

/*
 * Helper to generate linker script statements starting a hyp section.
 *
 * A symbol with a well-known name is defined at the first byte. This
 * is used as a base for hyp relocations (see gen-hyprel.c). It must
 * be defined inside the section so the linker of `vmlinux` cannot
 * separate it from the section data.
 */
#define BEGIN_HYP_SECTION(NAME)				\
	HYP_SECTION_NAME(NAME) : {			\
		HYP_SECTION_SYMBOL_NAME(NAME) = .;

/* Helper to generate linker script statements ending a hyp section. */
#define END_HYP_SECTION					\
	}

/* Defines an ELF hyp section from input section @NAME and its subsections. */
#define HYP_SECTION(NAME)			\
	BEGIN_HYP_SECTION(NAME)			\
		*(NAME NAME##.*)		\
	END_HYP_SECTION

/*
 * Defines a linker script alias of a kernel-proper symbol referenced by
 * KVM nVHE hyp code.
 */
#define KVM_NVHE_ALIAS(sym)	kvm_nvhe_sym(sym) = sym;

#endif /* LINKER_SCRIPT */

#endif /* __ARM64_HYP_IMAGE_H__ */