2008-12-16 18:43:58 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2008 IBM Corporation.
|
|
|
|
* Authors: Hollis Blanchard <hollisb@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the GNU GPL license version 2 or later.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-06-29 19:47:03 +08:00
|
|
|
#ifndef KVM_PPC_H
|
|
|
|
#define KVM_PPC_H
|
2008-12-16 18:43:58 +08:00
|
|
|
|
2017-08-30 21:24:29 +08:00
|
|
|
#define TYPE_HOST_POWERPC_CPU POWERPC_CPU_TYPE_NAME("host")
|
2013-01-06 16:31:30 +08:00
|
|
|
|
2011-07-21 08:54:51 +08:00
|
|
|
#ifdef CONFIG_KVM
|
|
|
|
|
2010-02-10 00:37:05 +08:00
|
|
|
uint32_t kvmppc_get_tbfreq(void);
|
2011-07-21 08:29:15 +08:00
|
|
|
uint64_t kvmppc_get_clockfreq(void);
|
2014-07-09 18:38:37 +08:00
|
|
|
bool kvmppc_get_host_model(char **buf);
|
|
|
|
bool kvmppc_get_host_serial(char **buf);
|
2013-01-03 20:37:02 +08:00
|
|
|
int kvmppc_get_hasidle(CPUPPCState *env);
|
2012-03-14 08:38:22 +08:00
|
|
|
int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_len);
|
2012-10-31 13:06:49 +08:00
|
|
|
int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level);
|
2015-05-07 13:33:59 +08:00
|
|
|
void kvmppc_enable_logical_ci_hcalls(void);
|
2015-09-08 09:25:13 +08:00
|
|
|
void kvmppc_enable_set_mode_hcall(void);
|
2016-08-30 09:02:47 +08:00
|
|
|
void kvmppc_enable_clear_ref_mod_hcalls(void);
|
2019-03-06 14:06:08 +08:00
|
|
|
void kvmppc_enable_h_page_init(void);
|
2012-10-31 13:06:49 +08:00
|
|
|
void kvmppc_set_papr(PowerPCCPU *cpu);
|
2016-10-28 19:09:37 +08:00
|
|
|
int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
|
2013-01-17 18:54:38 +08:00
|
|
|
void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
|
2011-09-30 05:39:10 +08:00
|
|
|
int kvmppc_smt_threads(void);
|
2017-08-18 13:50:22 +08:00
|
|
|
void kvmppc_hint_smt_possible(Error **errp);
|
|
|
|
int kvmppc_set_smt_threads(int smt);
|
2013-02-25 02:16:21 +08:00
|
|
|
int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
|
|
|
|
int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
|
|
|
|
int kvmppc_set_tcr(PowerPCCPU *cpu);
|
|
|
|
int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu);
|
2017-03-20 07:46:46 +08:00
|
|
|
target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
|
|
|
|
bool radix, bool gtse,
|
|
|
|
uint64_t proc_tbl);
|
2011-10-24 01:25:04 +08:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2014-05-27 13:36:30 +08:00
|
|
|
bool kvmppc_spapr_use_multitce(void);
|
2017-03-27 13:22:19 +08:00
|
|
|
int kvmppc_spapr_enable_inkernel_multitce(void);
|
2017-03-10 09:41:13 +08:00
|
|
|
void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
|
|
|
|
uint64_t bus_offset, uint32_t nb_table,
|
|
|
|
int *pfd, bool need_vfio);
|
2011-09-30 05:39:12 +08:00
|
|
|
int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size);
|
2012-09-13 00:57:12 +08:00
|
|
|
int kvmppc_reset_htab(int shift_hint);
|
|
|
|
uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift);
|
2018-02-07 02:08:24 +08:00
|
|
|
bool kvmppc_has_cap_spapr_vfio(void);
|
2011-10-24 01:25:04 +08:00
|
|
|
#endif /* !CONFIG_USER_ONLY */
|
2013-03-30 14:40:49 +08:00
|
|
|
bool kvmppc_has_cap_epr(void);
|
2013-09-26 14:18:35 +08:00
|
|
|
int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function);
|
2017-09-15 21:16:20 +08:00
|
|
|
int kvmppc_get_htab_fd(bool write, uint64_t index, Error **errp);
|
2013-07-19 03:33:03 +08:00
|
|
|
int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns);
|
|
|
|
int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
|
|
|
|
uint16_t n_valid, uint16_t n_invalid);
|
target/ppc: Fix KVM-HV HPTE accessors
When a 'pseries' guest is running with KVM-HV, the guest's hashed page
table (HPT) is stored within the host kernel, so it is not directly
accessible to qemu. Most of the time, qemu doesn't need to access it:
we're using the hardware MMU, and KVM itself implements the guest
hypercalls for manipulating the HPT.
However, qemu does need access to the in-KVM HPT to implement
get_phys_page_debug() for the benefit of the gdbstub, and maybe for
other debug operations.
To allow this, 7c43bca "target-ppc: Fix page table lookup with kvm
enabled" added kvmppc_hash64_read_pteg() to target/ppc/kvm.c to read
in a batch of HPTEs from the KVM table. Unfortunately, there are a
couple of problems with this:
First, the name of the function implies it always reads a whole PTEG
from the HPT, but in fact in some cases it's used to grab individual
HPTEs (which ends up pulling 8 HPTEs, not aligned to a PTEG from the
kernel).
Second, and more importantly, the code to read the HPTEs from KVM is
simply wrong, in general. The data from the fd that KVM provides is
designed mostly for compact migration rather than this sort of one-off
access, and so needs some decoding for this purpose. The current code
will work in some cases, but if there are invalid HPTEs then it will
not get sane results.
This patch rewrite the HPTE reading function to have a simpler
interface (just read n HPTEs into a caller provided buffer), and to
correctly decode the stream from the kernel.
For consistency we also clean up the similar function for altering
HPTEs within KVM (introduced in c138593 "target-ppc: Update
ppc_hash64_store_hpte to support updating in-kernel htab").
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-27 12:34:19 +08:00
|
|
|
void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n);
|
|
|
|
void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1);
|
2014-06-04 18:14:08 +08:00
|
|
|
bool kvmppc_has_cap_fixup_hcalls(void);
|
2016-09-28 19:16:30 +08:00
|
|
|
bool kvmppc_has_cap_htm(void);
|
2017-03-20 07:46:44 +08:00
|
|
|
bool kvmppc_has_cap_mmu_radix(void);
|
|
|
|
bool kvmppc_has_cap_mmu_hash_v3(void);
|
2018-01-19 12:59:59 +08:00
|
|
|
int kvmppc_get_cap_safe_cache(void);
|
|
|
|
int kvmppc_get_cap_safe_bounds_check(void);
|
|
|
|
int kvmppc_get_cap_safe_indirect_branch(void);
|
2019-03-01 11:19:12 +08:00
|
|
|
int kvmppc_get_cap_count_cache_flush_assist(void);
|
2018-10-08 11:25:39 +08:00
|
|
|
bool kvmppc_has_cap_nested_kvm_hv(void);
|
|
|
|
int kvmppc_set_cap_nested_kvm_hv(int enable);
|
2019-03-01 10:43:16 +08:00
|
|
|
int kvmppc_get_cap_large_decr(void);
|
|
|
|
int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable);
|
ppc/spapr: Implement H_RANDOM hypercall in QEMU
The PAPR interface defines a hypercall to pass high-quality
hardware generated random numbers to guests. Recent kernels can
already provide this hypercall to the guest if the right hardware
random number generator is available. But in case the user wants
to use another source like EGD, or QEMU is running with an older
kernel, we should also have this call in QEMU, so that guests that
do not support virtio-rng yet can get good random numbers, too.
This patch now adds a new pseudo-device to QEMU that either
directly provides this hypercall to the guest or is able to
enable the in-kernel hypercall if available. The in-kernel
hypercall can be enabled with the use-kvm property, e.g.:
qemu-system-ppc64 -device spapr-rng,use-kvm=true
For handling the hypercall in QEMU instead, a "RngBackend" is
required since the hypercall should provide "good" random data
instead of pseudo-random (like from a "simple" library function
like rand() or g_random_int()). Since there are multiple RngBackends
available, the user must select an appropriate back-end via the
"rng" property of the device, e.g.:
qemu-system-ppc64 -object rng-random,filename=/dev/hwrng,id=gid0 \
-device spapr-rng,rng=gid0 ...
See http://wiki.qemu-project.org/Features-Done/VirtIORNG for
other example of specifying RngBackends.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-09-17 16:49:41 +08:00
|
|
|
int kvmppc_enable_hwrng(void);
|
2016-03-08 08:33:46 +08:00
|
|
|
int kvmppc_put_books_sregs(PowerPCCPU *cpu);
|
2016-06-07 23:39:38 +08:00
|
|
|
PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
|
2017-05-12 13:46:11 +08:00
|
|
|
void kvmppc_check_papr_resize_hpt(Error **errp);
|
2017-07-12 15:56:55 +08:00
|
|
|
int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu, target_ulong flags, int shift);
|
|
|
|
int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, target_ulong flags, int shift);
|
2017-08-10 04:43:46 +08:00
|
|
|
bool kvmppc_pvr_workaround_required(PowerPCCPU *cpu);
|
2014-02-21 01:52:38 +08:00
|
|
|
|
2018-06-14 10:11:08 +08:00
|
|
|
bool kvmppc_hpt_needs_host_contiguous_pages(void);
|
2018-04-16 14:19:52 +08:00
|
|
|
void kvm_check_mmu(PowerPCCPU *cpu, Error **errp);
|
2018-09-04 17:24:18 +08:00
|
|
|
void kvmppc_set_reg_ppc_online(PowerPCCPU *cpu, unsigned int online);
|
2017-02-15 17:21:44 +08:00
|
|
|
|
2011-07-21 08:54:51 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline uint32_t kvmppc_get_tbfreq(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-09 18:38:37 +08:00
|
|
|
static inline bool kvmppc_get_host_model(char **buf)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool kvmppc_get_host_serial(char **buf)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-21 08:54:51 +08:00
|
|
|
static inline uint64_t kvmppc_get_clockfreq(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
pseries: Add device tree properties for VMX/VSX and DFP under kvm
Sufficiently recent PAPR specifications define properties "ibm,vmx"
and "ibm,dfp" on the CPU node which advertise whether the VMX vector
extensions (or the later VSX version) and/or the Decimal Floating
Point operations from IBM's recent POWER CPUs are available.
Currently we do not put these in the guest device tree and the guest
kernel will consequently assume they are not available. This is good,
because they are not supported under TCG. VMX is similar enough to
Altivec that it might be trivial to support, but VSX and DFP would
both require significant work to support in TCG.
However, when running under kvm on a host which supports these
instructions, there's no reason not to let the guest use them. This
patch, therefore, checks for the relevant support on the host CPU
and, if present, advertises them to the guest as well.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alexander Graf <agraf@suse.de>
2011-10-11 02:31:01 +08:00
|
|
|
static inline uint32_t kvmppc_get_vmx(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t kvmppc_get_dfp(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-03 20:37:02 +08:00
|
|
|
static inline int kvmppc_get_hasidle(CPUPPCState *env)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-21 18:47:25 +08:00
|
|
|
static inline int kvmppc_get_hypercall(CPUPPCState *env,
|
|
|
|
uint8_t *buf, int buf_len)
|
2011-07-21 08:54:51 +08:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-31 13:06:49 +08:00
|
|
|
static inline int kvmppc_set_interrupt(PowerPCCPU *cpu, int irq, int level)
|
2011-07-21 08:54:51 +08:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-05-07 13:33:59 +08:00
|
|
|
static inline void kvmppc_enable_logical_ci_hcalls(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-08 09:25:13 +08:00
|
|
|
static inline void kvmppc_enable_set_mode_hcall(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-30 09:02:47 +08:00
|
|
|
static inline void kvmppc_enable_clear_ref_mod_hcalls(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-06 14:06:08 +08:00
|
|
|
static inline void kvmppc_enable_h_page_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-31 13:06:49 +08:00
|
|
|
static inline void kvmppc_set_papr(PowerPCCPU *cpu)
|
2011-08-09 23:57:37 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-28 19:09:37 +08:00
|
|
|
static inline int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr)
|
2014-05-23 10:26:58 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-17 18:54:38 +08:00
|
|
|
static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-30 05:39:10 +08:00
|
|
|
static inline int kvmppc_smt_threads(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-08-18 13:50:22 +08:00
|
|
|
static inline void kvmppc_hint_smt_possible(Error **errp)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_set_smt_threads(int smt)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-25 02:16:21 +08:00
|
|
|
static inline int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_set_tcr(PowerPCCPU *cpu)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-03-20 07:46:46 +08:00
|
|
|
static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
|
|
|
|
bool radix, bool gtse,
|
|
|
|
uint64_t proc_tbl)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-04 17:24:18 +08:00
|
|
|
static inline void kvmppc_set_reg_ppc_online(PowerPCCPU *cpu,
|
|
|
|
unsigned int online)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-24 01:25:04 +08:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2014-05-27 13:36:30 +08:00
|
|
|
static inline bool kvmppc_spapr_use_multitce(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-27 13:22:19 +08:00
|
|
|
static inline int kvmppc_spapr_enable_inkernel_multitce(void)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-03-10 09:41:13 +08:00
|
|
|
static inline void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
|
|
|
|
uint64_t bus_offset,
|
|
|
|
uint32_t nb_table,
|
|
|
|
int *pfd, bool need_vfio)
|
2011-09-30 05:39:12 +08:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_remove_spapr_tce(void *table, int pfd,
|
2014-05-27 13:36:35 +08:00
|
|
|
uint32_t nb_table)
|
2011-09-30 05:39:12 +08:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2012-09-13 00:57:12 +08:00
|
|
|
|
|
|
|
static inline int kvmppc_reset_htab(int shift_hint)
|
|
|
|
{
|
2015-11-10 13:24:53 +08:00
|
|
|
return 0;
|
2012-09-13 00:57:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t kvmppc_rma_size(uint64_t current_size,
|
|
|
|
unsigned int hash_shift)
|
|
|
|
{
|
|
|
|
return ram_size;
|
|
|
|
}
|
|
|
|
|
2018-06-14 10:11:08 +08:00
|
|
|
static inline bool kvmppc_hpt_needs_host_contiguous_pages(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-16 14:19:52 +08:00
|
|
|
static inline void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-07 02:08:24 +08:00
|
|
|
static inline bool kvmppc_has_cap_spapr_vfio(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-24 01:25:04 +08:00
|
|
|
#endif /* !CONFIG_USER_ONLY */
|
2011-09-30 05:39:12 +08:00
|
|
|
|
2013-03-30 14:40:49 +08:00
|
|
|
static inline bool kvmppc_has_cap_epr(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-19 03:33:03 +08:00
|
|
|
|
2013-09-26 14:18:35 +08:00
|
|
|
static inline int kvmppc_define_rtas_kernel_token(uint32_t token,
|
|
|
|
const char *function)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-09-15 21:16:20 +08:00
|
|
|
static inline int kvmppc_get_htab_fd(bool write, uint64_t index, Error **errp)
|
2013-07-19 03:33:03 +08:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize,
|
|
|
|
int64_t max_ns)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
|
|
|
|
uint16_t n_valid, uint16_t n_invalid)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
target/ppc: Fix KVM-HV HPTE accessors
When a 'pseries' guest is running with KVM-HV, the guest's hashed page
table (HPT) is stored within the host kernel, so it is not directly
accessible to qemu. Most of the time, qemu doesn't need to access it:
we're using the hardware MMU, and KVM itself implements the guest
hypercalls for manipulating the HPT.
However, qemu does need access to the in-KVM HPT to implement
get_phys_page_debug() for the benefit of the gdbstub, and maybe for
other debug operations.
To allow this, 7c43bca "target-ppc: Fix page table lookup with kvm
enabled" added kvmppc_hash64_read_pteg() to target/ppc/kvm.c to read
in a batch of HPTEs from the KVM table. Unfortunately, there are a
couple of problems with this:
First, the name of the function implies it always reads a whole PTEG
from the HPT, but in fact in some cases it's used to grab individual
HPTEs (which ends up pulling 8 HPTEs, not aligned to a PTEG from the
kernel).
Second, and more importantly, the code to read the HPTEs from KVM is
simply wrong, in general. The data from the fd that KVM provides is
designed mostly for compact migration rather than this sort of one-off
access, and so needs some decoding for this purpose. The current code
will work in some cases, but if there are invalid HPTEs then it will
not get sane results.
This patch rewrite the HPTE reading function to have a simpler
interface (just read n HPTEs into a caller provided buffer), and to
correctly decode the stream from the kernel.
For consistency we also clean up the similar function for altering
HPTEs within KVM (introduced in c138593 "target-ppc: Update
ppc_hash64_store_hpte to support updating in-kernel htab").
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-27 12:34:19 +08:00
|
|
|
static inline void kvmppc_read_hptes(ppc_hash_pte64_t *hptes,
|
|
|
|
hwaddr ptex, int n)
|
2014-02-21 01:52:24 +08:00
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
target/ppc: Fix KVM-HV HPTE accessors
When a 'pseries' guest is running with KVM-HV, the guest's hashed page
table (HPT) is stored within the host kernel, so it is not directly
accessible to qemu. Most of the time, qemu doesn't need to access it:
we're using the hardware MMU, and KVM itself implements the guest
hypercalls for manipulating the HPT.
However, qemu does need access to the in-KVM HPT to implement
get_phys_page_debug() for the benefit of the gdbstub, and maybe for
other debug operations.
To allow this, 7c43bca "target-ppc: Fix page table lookup with kvm
enabled" added kvmppc_hash64_read_pteg() to target/ppc/kvm.c to read
in a batch of HPTEs from the KVM table. Unfortunately, there are a
couple of problems with this:
First, the name of the function implies it always reads a whole PTEG
from the HPT, but in fact in some cases it's used to grab individual
HPTEs (which ends up pulling 8 HPTEs, not aligned to a PTEG from the
kernel).
Second, and more importantly, the code to read the HPTEs from KVM is
simply wrong, in general. The data from the fd that KVM provides is
designed mostly for compact migration rather than this sort of one-off
access, and so needs some decoding for this purpose. The current code
will work in some cases, but if there are invalid HPTEs then it will
not get sane results.
This patch rewrite the HPTE reading function to have a simpler
interface (just read n HPTEs into a caller provided buffer), and to
correctly decode the stream from the kernel.
For consistency we also clean up the similar function for altering
HPTEs within KVM (introduced in c138593 "target-ppc: Update
ppc_hash64_store_hpte to support updating in-kernel htab").
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-27 12:34:19 +08:00
|
|
|
static inline void kvmppc_write_hpte(hwaddr ptex, uint64_t pte0, uint64_t pte1)
|
2014-02-21 01:52:38 +08:00
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2014-06-04 18:14:08 +08:00
|
|
|
static inline bool kvmppc_has_cap_fixup_hcalls(void)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2016-09-28 19:16:30 +08:00
|
|
|
static inline bool kvmppc_has_cap_htm(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-20 07:46:44 +08:00
|
|
|
static inline bool kvmppc_has_cap_mmu_radix(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool kvmppc_has_cap_mmu_hash_v3(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-19 12:59:59 +08:00
|
|
|
static inline int kvmppc_get_cap_safe_cache(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_get_cap_safe_bounds_check(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_get_cap_safe_indirect_branch(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-01 11:19:12 +08:00
|
|
|
static inline int kvmppc_get_cap_count_cache_flush_assist(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-08 11:25:39 +08:00
|
|
|
static inline bool kvmppc_has_cap_nested_kvm_hv(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_set_cap_nested_kvm_hv(int enable)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-03-01 10:43:16 +08:00
|
|
|
static inline int kvmppc_get_cap_large_decr(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
ppc/spapr: Implement H_RANDOM hypercall in QEMU
The PAPR interface defines a hypercall to pass high-quality
hardware generated random numbers to guests. Recent kernels can
already provide this hypercall to the guest if the right hardware
random number generator is available. But in case the user wants
to use another source like EGD, or QEMU is running with an older
kernel, we should also have this call in QEMU, so that guests that
do not support virtio-rng yet can get good random numbers, too.
This patch now adds a new pseudo-device to QEMU that either
directly provides this hypercall to the guest or is able to
enable the in-kernel hypercall if available. The in-kernel
hypercall can be enabled with the use-kvm property, e.g.:
qemu-system-ppc64 -device spapr-rng,use-kvm=true
For handling the hypercall in QEMU instead, a "RngBackend" is
required since the hypercall should provide "good" random data
instead of pseudo-random (like from a "simple" library function
like rand() or g_random_int()). Since there are multiple RngBackends
available, the user must select an appropriate back-end via the
"rng" property of the device, e.g.:
qemu-system-ppc64 -object rng-random,filename=/dev/hwrng,id=gid0 \
-device spapr-rng,rng=gid0 ...
See http://wiki.qemu-project.org/Features-Done/VirtIORNG for
other example of specifying RngBackends.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-09-17 16:49:41 +08:00
|
|
|
static inline int kvmppc_enable_hwrng(void)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-08 08:33:46 +08:00
|
|
|
|
|
|
|
static inline int kvmppc_put_books_sregs(PowerPCCPU *cpu)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
2016-06-07 23:39:38 +08:00
|
|
|
|
|
|
|
static inline PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-05-12 13:46:11 +08:00
|
|
|
static inline void kvmppc_check_papr_resize_hpt(Error **errp)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-07-12 15:56:55 +08:00
|
|
|
|
|
|
|
static inline int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu,
|
|
|
|
target_ulong flags, int shift)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvmppc_resize_hpt_commit(PowerPCCPU *cpu,
|
|
|
|
target_ulong flags, int shift)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2011-07-21 08:54:51 +08:00
|
|
|
#endif
|
|
|
|
|
2011-04-01 12:15:30 +08:00
|
|
|
#ifndef CONFIG_KVM
|
2016-02-18 17:15:54 +08:00
|
|
|
|
2011-04-01 12:15:30 +08:00
|
|
|
#define kvmppc_eieio() do { } while (0)
|
2016-02-18 17:15:54 +08:00
|
|
|
|
|
|
|
static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_KVM */
|
|
|
|
|
2011-04-01 12:15:30 +08:00
|
|
|
#define kvmppc_eieio() \
|
|
|
|
do { \
|
|
|
|
if (kvm_enabled()) { \
|
|
|
|
asm volatile("eieio" : : : "memory"); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2016-02-18 17:15:54 +08:00
|
|
|
|
|
|
|
/* Store data cache blocks back to memory */
|
|
|
|
static inline void kvmppc_dcbst_range(PowerPCCPU *cpu, uint8_t *addr, int len)
|
|
|
|
{
|
|
|
|
uint8_t *p;
|
|
|
|
|
|
|
|
for (p = addr; p < addr + len; p += cpu->env.dcache_line_size) {
|
|
|
|
asm volatile("dcbst 0,%0" : : "r"(p) : "memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invalidate instruction cache blocks */
|
|
|
|
static inline void kvmppc_icbi_range(PowerPCCPU *cpu, uint8_t *addr, int len)
|
|
|
|
{
|
|
|
|
uint8_t *p;
|
|
|
|
|
|
|
|
for (p = addr; p < addr + len; p += cpu->env.icache_line_size) {
|
|
|
|
asm volatile("icbi 0,%0" : : "r"(p));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_KVM */
|
2011-04-01 12:15:30 +08:00
|
|
|
|
2016-06-29 19:47:03 +08:00
|
|
|
#endif /* KVM_PPC_H */
|