hv: multi-arch: move {arch_}get_random_value to random.c

Tracked-On: #8834
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
Jian Jun Chen
2025-10-23 13:55:22 +08:00
committed by acrnsi-robot
parent 0e0f673458
commit 0222bb0fc1
6 changed files with 40 additions and 14 deletions

View File

@@ -52,6 +52,7 @@ ASFLAGS += -m64 -nostdinc -nostdlib
# library componment # library componment
LIB_C_SRCS += arch/x86/lib/memory.c LIB_C_SRCS += arch/x86/lib/memory.c
LIB_C_SRCS += arch/x86/lib/random.c
# retpoline support # retpoline support
ifeq (true, $(shell [ $(GCC_MAJOR) -eq 7 ] && [ $(GCC_MINOR) -ge 3 ] && echo true)) ifeq (true, $(shell [ $(GCC_MAJOR) -eq 7 ] && [ $(GCC_MINOR) -ge 3 ] && echo true))

View File

@@ -14,6 +14,7 @@
#include <asm/cpufeatures.h> #include <asm/cpufeatures.h>
#include <asm/cpu_caps.h> #include <asm/cpu_caps.h>
#include <per_cpu.h> #include <per_cpu.h>
#include <random.h>
#include <asm/init.h> #include <asm/init.h>
#include <asm/guest/vm.h> #include <asm/guest/vm.h>
#include <asm/guest/vmcs.h> #include <asm/guest/vmcs.h>

View File

@@ -0,0 +1,20 @@
/*
* Copyright (C) 2025 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <types.h>
uint64_t arch_get_random_value(void)
{
uint64_t random;
asm volatile ("1: rdrand %%rax\n"
"jnc 1b\n"
"mov %%rax, %0\n"
: "=r"(random)
:
:"%rax");
return random;
}

View File

@@ -12,6 +12,7 @@
#include <asm/cpu_caps.h> #include <asm/cpu_caps.h>
#include <asm/security.h> #include <asm/security.h>
#include <logmsg.h> #include <logmsg.h>
#include <random.h>
static bool skip_l1dfl_vmentry; static bool skip_l1dfl_vmentry;
static bool cpu_md_clear; static bool cpu_md_clear;
@@ -198,19 +199,6 @@ void cpu_internal_buffers_clear(void)
} }
} }
uint64_t get_random_value(void)
{
uint64_t random;
asm volatile ("1: rdrand %%rax\n"
"jnc 1b\n"
"mov %%rax, %0\n"
: "=r"(random)
:
:"%rax");
return random;
}
#ifdef STACK_PROTECTOR #ifdef STACK_PROTECTOR
void set_fs_base(void) void set_fs_base(void)
{ {

View File

@@ -22,7 +22,6 @@ void cpu_l1d_flush(void);
bool check_cpu_security_cap(void); bool check_cpu_security_cap(void);
void cpu_internal_buffers_clear(void); void cpu_internal_buffers_clear(void);
bool is_ept_force_4k_ipage(void); bool is_ept_force_4k_ipage(void);
uint64_t get_random_value(void);
void disable_rrsba(void); void disable_rrsba(void);
#ifdef STACK_PROTECTOR #ifdef STACK_PROTECTOR

View File

@@ -0,0 +1,17 @@
/*
* Copyright (C) 2025 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef COMMON_RANDOM_H
#define COMMON_RANDOM_H
uint64_t arch_get_random_value(void);
static inline uint64_t get_random_value(void)
{
return arch_get_random_value();
}
#endif /* COMMON_RANDOM_H */