linux/arch/x86/kvm/svm/avic.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Kernel-based Virtual Machine driver for Linux
 *
 * AMD SVM support
 *
 * Copyright (C) 2006 Qumranet, Inc.
 * Copyright 2010 Red Hat, Inc. and/or its affiliates.
 *
 * Authors:
 *   Yaniv Kamay  <[email protected]>
 *   Avi Kivity   <[email protected]>
 */

#define pr_fmt(fmt)

#include <linux/kvm_types.h>
#include <linux/hashtable.h>
#include <linux/amd-iommu.h>
#include <linux/kvm_host.h>

#include <asm/irq_remapping.h>

#include "trace.h"
#include "lapic.h"
#include "x86.h"
#include "irq.h"
#include "svm.h"

/*
 * Encode the arbitrary VM ID and the vCPU's default APIC ID, i.e the vCPU ID,
 * into the GATag so that KVM can retrieve the correct vCPU from a GALog entry
 * if an interrupt can't be delivered, e.g. because the vCPU isn't running.
 *
 * For the vCPU ID, use however many bits are currently allowed for the max
 * guest physical APIC ID (limited by the size of the physical ID table), and
 * use whatever bits remain to assign arbitrary AVIC IDs to VMs.  Note, the
 * size of the GATag is defined by hardware (32 bits), but is an opaque value
 * as far as hardware is concerned.
 */
#define AVIC_VCPU_ID_MASK

#define AVIC_VM_ID_SHIFT
#define AVIC_VM_ID_MASK

#define AVIC_GATAG_TO_VMID(x)
#define AVIC_GATAG_TO_VCPUID(x)

#define __AVIC_GATAG(vm_id, vcpu_id)
#define AVIC_GATAG(vm_id, vcpu_id)

static_assert();

static bool force_avic;
module_param_unsafe(force_avic, bool, 0444);

/* Note:
 * This hash table is used to map VM_ID to a struct kvm_svm,
 * when handling AMD IOMMU GALOG notification to schedule in
 * a particular vCPU.
 */
#define SVM_VM_DATA_HASH_BITS
static DEFINE_HASHTABLE(svm_vm_data_hash, SVM_VM_DATA_HASH_BITS);
static u32 next_vm_id =;
static bool next_vm_id_wrapped =;
static DEFINE_SPINLOCK(svm_vm_data_hash_lock);
bool x2avic_enabled;

/*
 * This is a wrapper of struct amd_iommu_ir_data.
 */
struct amd_svm_iommu_ir {};

static void avic_activate_vmcb(struct vcpu_svm *svm)
{}

static void avic_deactivate_vmcb(struct vcpu_svm *svm)
{}

/* Note:
 * This function is called from IOMMU driver to notify
 * SVM to schedule in a particular vCPU of a particular VM.
 */
int avic_ga_log_notifier(u32 ga_tag)
{}

void avic_vm_destroy(struct kvm *kvm)
{}

int avic_vm_init(struct kvm *kvm)
{}

void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *vmcb)
{}

static u64 *avic_get_physical_id_entry(struct kvm_vcpu *vcpu,
				       unsigned int index)
{}

static int avic_init_backing_page(struct kvm_vcpu *vcpu)
{}

void avic_ring_doorbell(struct kvm_vcpu *vcpu)
{}


static void avic_kick_vcpu(struct kvm_vcpu *vcpu, u32 icrl)
{}

static void avic_kick_vcpu_by_physical_id(struct kvm *kvm, u32 physical_id,
					  u32 icrl)
{}

static void avic_kick_vcpu_by_logical_id(struct kvm *kvm, u32 *avic_logical_id_table,
					 u32 logid_index, u32 icrl)
{}

/*
 * A fast-path version of avic_kick_target_vcpus(), which attempts to match
 * destination APIC ID to vCPU without looping through all vCPUs.
 */
static int avic_kick_target_vcpus_fast(struct kvm *kvm, struct kvm_lapic *source,
				       u32 icrl, u32 icrh, u32 index)
{}

static void avic_kick_target_vcpus(struct kvm *kvm, struct kvm_lapic *source,
				   u32 icrl, u32 icrh, u32 index)
{}

int avic_incomplete_ipi_interception(struct kvm_vcpu *vcpu)
{}

unsigned long avic_vcpu_get_apicv_inhibit_reasons(struct kvm_vcpu *vcpu)
{}

static u32 *avic_get_logical_id_entry(struct kvm_vcpu *vcpu, u32 ldr, bool flat)
{}

static void avic_ldr_write(struct kvm_vcpu *vcpu, u8 g_physical_id, u32 ldr)
{}

static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu)
{}

static void avic_handle_ldr_update(struct kvm_vcpu *vcpu)
{}

static void avic_handle_dfr_update(struct kvm_vcpu *vcpu)
{}

static int avic_unaccel_trap_write(struct kvm_vcpu *vcpu)
{}

static bool is_avic_unaccelerated_access_trap(u32 offset)
{}

int avic_unaccelerated_access_interception(struct kvm_vcpu *vcpu)
{}

int avic_init_vcpu(struct vcpu_svm *svm)
{}

void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu)
{}

static int avic_set_pi_irte_mode(struct kvm_vcpu *vcpu, bool activate)
{}

static void svm_ir_list_del(struct vcpu_svm *svm, struct amd_iommu_pi_data *pi)
{}

static int svm_ir_list_add(struct vcpu_svm *svm, struct amd_iommu_pi_data *pi)
{}

/*
 * Note:
 * The HW cannot support posting multicast/broadcast
 * interrupts to a vCPU. So, we still use legacy interrupt
 * remapping for these kind of interrupts.
 *
 * For lowest-priority interrupts, we only support
 * those with single CPU as the destination, e.g. user
 * configures the interrupts via /proc/irq or uses
 * irqbalance to make the interrupts single-CPU.
 */
static int
get_pi_vcpu_info(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e,
		 struct vcpu_data *vcpu_info, struct vcpu_svm **svm)
{}

/*
 * avic_pi_update_irte - set IRTE for Posted-Interrupts
 *
 * @kvm: kvm
 * @host_irq: host irq of the interrupt
 * @guest_irq: gsi of the interrupt
 * @set: set or unset PI
 * returns 0 on success, < 0 on failure
 */
int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
			uint32_t guest_irq, bool set)
{}

static inline int
avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int cpu, bool r)
{}

void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
{}

void avic_vcpu_put(struct kvm_vcpu *vcpu)
{}

void avic_refresh_virtual_apic_mode(struct kvm_vcpu *vcpu)
{}

void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu)
{}

void avic_vcpu_blocking(struct kvm_vcpu *vcpu)
{}

void avic_vcpu_unblocking(struct kvm_vcpu *vcpu)
{}

/*
 * Note:
 * - The module param avic enable both xAPIC and x2APIC mode.
 * - Hypervisor can support both xAVIC and x2AVIC in the same guest.
 * - The mode can be switched at run-time.
 */
bool avic_hardware_setup(void)
{}