Skip to content

Commit 5dba49e

Browse files
committed
[aarch64][riscv64][ppc64] Improving DT integration to detect VM
1 parent 260d8af commit 5dba49e

File tree

6 files changed

+87
-11
lines changed

6 files changed

+87
-11
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ ifneq ($(HWM_CHIPSET),)
9696
ccflags-y += -D HWM_CHIPSET=$(HWM_CHIPSET)
9797
endif
9898

99+
ccflags-y += -D DT_VIRTUAL_BOARD='{ \
100+
"linux,dummy-virt", \
101+
"riscv-virtio", \
102+
"qemu,pseries", \
103+
NULL \
104+
}'
105+
99106
ifneq ($(NO_HEADER),)
100107
LAYOUT += -D NO_HEADER=$(NO_HEADER)
101108
endif

aarch64/corefreqk.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@
44
* Licenses: GPL2
55
*/
66

7-
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
7+
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
8+
#define of_cpu_device_node_get(cpu) \
9+
({ \
10+
struct device_node *cpu_node; \
11+
struct device *cpu_dev; \
12+
cpu_dev = get_cpu_device(cpu); \
13+
if (!cpu_dev) { \
14+
cpu_node = of_get_cpu_node(cpu, NULL); \
15+
} else { \
16+
cpu_node = of_node_get(cpu_dev->of_node); \
17+
} \
18+
cpu_node; \
19+
})
20+
#endif
21+
22+
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
823
#define of_device_compatible_match(_device_, _compat_) \
924
({ \
1025
const struct device_node *device = _device_; \
@@ -164,12 +179,6 @@ ASM_COUNTERx3(x11, x12, x13, x14, ASM_RDTSC, mem_tsc, __VA_ARGS__)
164179
#define VENDOR_VMWARE "VMwawarereVM"
165180
#define VENDOR_HYPERV "Micrt Hvosof"
166181

167-
#define DT_VIRTUAL_BOARD { \
168-
"linux,dummy-virt", \
169-
"qemu,pseries", \
170-
NULL \
171-
}
172-
173182
#define LATCH_NONE 0b000000000000
174183
#define LATCH_TGT_RATIO_UNLOCK 0b000000000001 /* <T> TgtRatioUnlocked */
175184
#define LATCH_CLK_RATIO_UNLOCK 0b000000000010 /* <X> ClkRatioUnlocked */

ppc64le/corefreqk.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4667,7 +4667,19 @@ static int CoreFreqK_Ignition_Level_Up(INIT_ARG *pArg)
46674667
StrCopy(PUBLIC(RO(Proc))->Features.Info.Vendor.ID,
46684668
PUBLIC(RO(Proc))->Architecture,
46694669
12 + 4);
4670-
4670+
/* Attempt to detect virtualization from Device Tree */
4671+
#ifdef CONFIG_OF
4672+
{
4673+
const char *virtualBoard[] = DT_VIRTUAL_BOARD;
4674+
if (of_device_compatible_match(of_root, virtualBoard) > 0)
4675+
{
4676+
PUBLIC(RO(Proc))->HypervisorID = HYPERV_KVM;
4677+
PUBLIC(RO(Proc))->Features.Info.Hypervisor.CRC = CRC_KVM;
4678+
StrCopy(PUBLIC(RO(Proc))->Features.Info.Hypervisor.ID,
4679+
VENDOR_KVM, 12 + 4);
4680+
}
4681+
}
4682+
#endif /* CONFIG_OF */
46714683
/* Check if the Processor is actually virtualized ? */
46724684
#ifdef CONFIG_XEN
46734685
if (xen_pv_domain() || xen_hvm_domain())

ppc64le/corefreqk.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Licenses: GPL2
55
*/
66

7-
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
7+
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
88
#define of_cpu_device_node_get(cpu) \
99
({ \
1010
struct device_node *cpu_node; \
@@ -19,6 +19,24 @@
1919
})
2020
#endif
2121

22+
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
23+
#define of_device_compatible_match(_device_, _compat_) \
24+
({ \
25+
const struct device_node *device = _device_; \
26+
const char *const *compat = _compat_; \
27+
unsigned int tmp, score = 0; \
28+
\
29+
if (compat != NULL) \
30+
while (*compat) { \
31+
tmp = of_device_is_compatible(device, *compat); \
32+
if (tmp > score) \
33+
score = tmp; \
34+
compat++; \
35+
} \
36+
score; \
37+
})
38+
#endif
39+
2240
#define Atomic_Read_VPMC(_lock, _dest, _src) \
2341
{ \
2442
/* __asm__ volatile \

riscv64/corefreqk.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4661,7 +4661,19 @@ static int CoreFreqK_Ignition_Level_Up(INIT_ARG *pArg)
46614661
StrCopy(PUBLIC(RO(Proc))->Features.Info.Vendor.ID,
46624662
PUBLIC(RO(Proc))->Architecture,
46634663
12 + 4);
4664-
4664+
/* Attempt to detect virtualization from Device Tree */
4665+
#ifdef CONFIG_OF
4666+
{
4667+
const char *virtualBoard[] = DT_VIRTUAL_BOARD;
4668+
if (of_device_compatible_match(of_root, virtualBoard) > 0)
4669+
{
4670+
PUBLIC(RO(Proc))->HypervisorID = HYPERV_KVM;
4671+
PUBLIC(RO(Proc))->Features.Info.Hypervisor.CRC = CRC_KVM;
4672+
StrCopy(PUBLIC(RO(Proc))->Features.Info.Hypervisor.ID,
4673+
VENDOR_KVM, 12 + 4);
4674+
}
4675+
}
4676+
#endif /* CONFIG_OF */
46654677
/* Check if the Processor is actually virtualized ? */
46664678
#ifdef CONFIG_XEN
46674679
if (xen_pv_domain() || xen_hvm_domain())

riscv64/corefreqk.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Licenses: GPL2
55
*/
66

7-
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
7+
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
88
#define of_cpu_device_node_get(cpu) \
99
({ \
1010
struct device_node *cpu_node; \
@@ -19,6 +19,24 @@
1919
})
2020
#endif
2121

22+
#if defined(CONFIG_OF) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
23+
#define of_device_compatible_match(_device_, _compat_) \
24+
({ \
25+
const struct device_node *device = _device_; \
26+
const char *const *compat = _compat_; \
27+
unsigned int tmp, score = 0; \
28+
\
29+
if (compat != NULL) \
30+
while (*compat) { \
31+
tmp = of_device_is_compatible(device, *compat); \
32+
if (tmp > score) \
33+
score = tmp; \
34+
compat++; \
35+
} \
36+
score; \
37+
})
38+
#endif
39+
2240
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
2341
#define sys_reg(op0, op1, crn, crm, op2) ({ \
2442
UNUSED(op0); \

0 commit comments

Comments
 (0)