dm: Use new MMIO device passthrough management ioctls

IC_ASSIGN_MMIODEV	->	ACRN_IOCTL_ASSIGN_MMIODEV
IC_DEASSIGN_MMIODEV	->	ACRN_IOCTL_DEASSIGN_MMIODEV

struct acrn_mmiodev has slight change. Move struct acrn_mmiodev into
acrn_common.h because it is used by both DM and HV.

Tracked-On: #6282
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
This commit is contained in:
Shuo A Liu 2021-07-07 16:54:26 +08:00 committed by wenlingz
parent 3625eb7a99
commit 9e7abbb38c
13 changed files with 61 additions and 80 deletions

View File

@ -554,13 +554,13 @@ vm_deassign_pcidev(struct vmctx *ctx, struct acrn_pcidev *pcidev)
int
vm_assign_mmiodev(struct vmctx *ctx, struct acrn_mmiodev *mmiodev)
{
return ioctl(ctx->fd, IC_ASSIGN_MMIODEV, mmiodev);
return ioctl(ctx->fd, ACRN_IOCTL_ASSIGN_MMIODEV, mmiodev);
}
int
vm_deassign_mmiodev(struct vmctx *ctx, struct acrn_mmiodev *mmiodev)
{
return ioctl(ctx->fd, IC_DEASSIGN_MMIODEV, mmiodev);
return ioctl(ctx->fd, ACRN_IOCTL_DEASSIGN_MMIODEV, mmiodev);
}
int

View File

@ -74,11 +74,11 @@ int parse_pt_acpidev(char *opt)
if (strncmp(opt, "MSFT0101", 8) == 0) {
strncpy(mmio_devs[mmio_dev_idx].name, "MSFT0101", 8);
/* TODO: We would parse the /proc/iomem to get the corresponding resources */
mmio_devs[mmio_dev_idx].dev.base_hpa = 0xFED40000UL;
mmio_devs[mmio_dev_idx].dev.service_vm_pa = 0xFED40000UL;
/* FIXME: The 0xFED40000 doesn't conflict with other mmio or system memory so far.
* This need to be fixed by redesign the mmio_dev_alloc_gpa_resource32().
*/
mmio_devs[mmio_dev_idx].dev.base_gpa = 0xFED40000UL;
mmio_devs[mmio_dev_idx].dev.user_vm_pa = 0xFED40000UL;
mmio_devs[mmio_dev_idx].dev.size = 0x00005000UL;
mmio_dev_idx++;
pt_tpm2 = true;
@ -103,7 +103,7 @@ int parse_pt_mmiodev(char *opt)
(!dm_strtoul(cp + 1, &cp, 16, &size))) {
pr_dbg("%s pt mmiodev base: 0x%lx, size: 0x%lx\n", __func__, base_hpa, size);
strncpy(mmio_devs[mmio_dev_idx].name, pt_mmiodev.name, 8);
mmio_devs[mmio_dev_idx].dev.base_hpa = base_hpa;
mmio_devs[mmio_dev_idx].dev.service_vm_pa = base_hpa;
mmio_devs[mmio_dev_idx].dev.size = size;
mmio_dev_idx++;
} else {
@ -131,14 +131,14 @@ int init_mmio_dev(struct vmctx *ctx, struct mmio_dev_ops *ops, struct acrn_mmiod
int ret;
uint32_t base;
if (mmiodev->base_gpa == 0UL) {
if (mmiodev->user_vm_pa == 0UL) {
/* FIXME: The mmio_dev_alloc_gpa_resource32 needs to add one new parameter to indicate
* if the caller needs one specific GPA instead of dynamic allocation.
*/
ret = mmio_dev_alloc_gpa_resource32(&base, mmiodev->size);
if (ret < 0)
return ret;
mmiodev->base_gpa = base;
mmiodev->user_vm_pa = base;
}
return ops->init(ctx, mmiodev);
@ -158,7 +158,9 @@ int init_mmio_devs(struct vmctx *ctx)
ops = mmio_dev_finddev(mmio_devs[i].name);
if (ops != NULL) {
err = init_mmio_dev(ctx, ops, &mmio_devs[i].dev);
pr_notice("mmiodev[%d] hpa:0x%x gpa:0x%x size:0x%x err:%d\n", i, mmio_devs[i].dev.base_hpa, mmio_devs[i].dev.base_gpa, mmio_devs[i].dev.size, err);
pr_notice("mmiodev[%d] hpa:0x%x gpa:0x%x size:0x%x err:%d\n", i,
mmio_devs[i].dev.service_vm_pa, mmio_devs[i].dev.user_vm_pa,
mmio_devs[i].dev.size, err);
}
if (err != 0)
@ -218,7 +220,7 @@ uint64_t get_mmio_dev_tpm2_base_gpa(void)
for (i = 0; i < mmio_dev_idx; i++) {
if (!strcmp(mmio_devs[i].name, "MSFT0101")) {
base_gpa = mmio_devs[i].dev.base_gpa;
base_gpa = mmio_devs[i].dev.user_vm_pa;
break;
}
}

View File

@ -121,8 +121,10 @@
_IOW(ACRN_IOCTL_TYPE, 0x55, struct acrn_pcidev)
#define ACRN_IOCTL_DEASSIGN_PCIDEV \
_IOW(ACRN_IOCTL_TYPE, 0x56, struct acrn_pcidev)
#define IC_ASSIGN_MMIODEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x07)
#define IC_DEASSIGN_MMIODEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x08)
#define ACRN_IOCTL_ASSIGN_MMIODEV \
_IOW(ACRN_IOCTL_TYPE, 0x57, struct acrn_mmiodev)
#define ACRN_IOCTL_DEASSIGN_MMIODEV \
_IOW(ACRN_IOCTL_TYPE, 0x58, struct acrn_mmiodev)
#define IC_ADD_HV_VDEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x09)
#define IC_REMOVE_HV_VDEV _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x0A)
@ -180,24 +182,6 @@ struct acrn_vm_memmap {
__u64 len;
};
/**
* @brief Info to assign or deassign a MMIO device for a VM
*/
struct acrn_mmiodev {
/** the gpa of the MMIO region for the MMIO device */
uint64_t base_gpa;
/** the hpa of the MMIO region for the MMIO device */
uint64_t base_hpa;
/** the size of the MMIO region for the MMIO device */
uint64_t size;
/** reserved for extension */
uint64_t reserved[13];
} __attribute__((aligned(8)));
/**
* @brief Info to create or destroy a virtual PCI or legacy device for a VM
*

View File

@ -925,7 +925,7 @@ int32_t hcall_assign_mmiodev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm,
/* We should only assign a device to a post-launched VM at creating time for safety, not runtime or other cases*/
if (is_created_vm(target_vm)) {
if (copy_from_gpa(vm, &mmiodev, param2, sizeof(mmiodev)) == 0) {
if (ept_is_valid_mr(vm, mmiodev.base_hpa, mmiodev.size)) {
if (ept_is_valid_mr(vm, mmiodev.service_vm_pa, mmiodev.size)) {
ret = deassign_mmio_dev(vm, &mmiodev);
if (ret == 0) {
ret = assign_mmio_dev(target_vm, &mmiodev);
@ -960,7 +960,7 @@ int32_t hcall_deassign_mmiodev(struct acrn_vcpu *vcpu, struct acrn_vm *target_vm
/* We should only de-assign a device from a post-launched VM at creating/shutdown/reset time */
if ((is_paused_vm(target_vm) || is_created_vm(target_vm))) {
if (copy_from_gpa(vm, &mmiodev, param2, sizeof(mmiodev)) == 0) {
if (ept_is_valid_mr(target_vm, mmiodev.base_gpa, mmiodev.size)) {
if (ept_is_valid_mr(target_vm, mmiodev.user_vm_pa, mmiodev.size)) {
ret = deassign_mmio_dev(target_vm, &mmiodev);
if (ret == 0) {
ret = assign_mmio_dev(vm, &mmiodev);

View File

@ -15,11 +15,11 @@ int32_t assign_mmio_dev(struct acrn_vm *vm, const struct acrn_mmiodev *mmiodev)
{
int32_t ret = -EINVAL;
if (mem_aligned_check(mmiodev->base_gpa, PAGE_SIZE) &&
mem_aligned_check(mmiodev->base_hpa, PAGE_SIZE) &&
if (mem_aligned_check(mmiodev->user_vm_pa, PAGE_SIZE) &&
mem_aligned_check(mmiodev->service_vm_pa, PAGE_SIZE) &&
mem_aligned_check(mmiodev->size, PAGE_SIZE)) {
ept_add_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp, mmiodev->base_hpa,
is_sos_vm(vm) ? mmiodev->base_hpa : mmiodev->base_gpa,
ept_add_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp, mmiodev->service_vm_pa,
is_sos_vm(vm) ? mmiodev->service_vm_pa: mmiodev->user_vm_pa,
mmiodev->size, EPT_RWX | EPT_UNCACHED);
ret = 0;
}
@ -31,11 +31,11 @@ int32_t deassign_mmio_dev(struct acrn_vm *vm, const struct acrn_mmiodev *mmiodev
{
int32_t ret = -EINVAL;
if (mem_aligned_check(mmiodev->base_gpa, PAGE_SIZE) &&
mem_aligned_check(mmiodev->base_hpa, PAGE_SIZE) &&
if (mem_aligned_check(mmiodev->user_vm_pa, PAGE_SIZE) &&
mem_aligned_check(mmiodev->service_vm_pa, PAGE_SIZE) &&
mem_aligned_check(mmiodev->size, PAGE_SIZE)) {
ept_del_mr(vm, (uint64_t *)vm->arch_vm.nworld_eptp,
is_sos_vm(vm) ? mmiodev->base_hpa : mmiodev->base_gpa, mmiodev->size);
is_sos_vm(vm) ? mmiodev->service_vm_pa: mmiodev->user_vm_pa, mmiodev->size);
ret = 0;
}

View File

@ -136,10 +136,10 @@ void register_vgpio_handler(struct acrn_vm *vm, const struct acrn_mmiodev *mmiod
uint64_t gpa_start, gpa_end, gpio_pcr_sz;
uint64_t base_hpa;
gpa_start = mmiodev->base_gpa + (P2SB_BASE_GPIO_PORT_ID << P2SB_PORTID_SHIFT);
gpa_start = mmiodev->user_vm_pa + (P2SB_BASE_GPIO_PORT_ID << P2SB_PORTID_SHIFT);
gpio_pcr_sz = P2SB_PCR_SPACE_SIZE_PER_AGENT * P2SB_MAX_GPIO_COMMUNITIES;
gpa_end = gpa_start + gpio_pcr_sz;
base_hpa = mmiodev->base_hpa + (P2SB_BASE_GPIO_PORT_ID << P2SB_PORTID_SHIFT);
base_hpa = mmiodev->service_vm_pa + (P2SB_BASE_GPIO_PORT_ID << P2SB_PORTID_SHIFT);
/* emulate MMIO access to the GPIO private configuration space registers */
set_paging_supervisor((uint64_t)hpa2hva(base_hpa), gpio_pcr_sz);

View File

@ -735,6 +735,21 @@ struct acrn_pcidev {
uint32_t bar[ACRN_PCI_NUM_BARS];
} __attribute__((aligned(8)));
/**
* @brief Info to assign or deassign a MMIO device for a VM
*/
struct acrn_mmiodev {
/** the gpa of the MMIO region for the MMIO device */
uint64_t user_vm_pa;
/** the hpa of the MMIO region for the MMIO device */
uint64_t service_vm_pa;
/** the size of the MMIO region for the MMIO device */
uint64_t size;
} __attribute__((aligned(8)));
/**
* @}
*/

View File

@ -271,26 +271,6 @@ struct hc_ptdev_irq {
} __aligned(8);
/**
* @brief Info to assign or deassign a MMIO device for a VM
*
* the parameter for HC_ASSIGN_MMIODEV or HC_DEASSIGN_MMIODEV hypercall
*/
struct acrn_mmiodev {
/** the gpa of the MMIO region for the MMIO device */
uint64_t base_gpa;
/** the hpa of the MMIO region for the MMIO device */
uint64_t base_hpa;
/** the size of the MMIO region for the MMIO device */
uint64_t size;
/** reserved for extension */
uint64_t reserved[13];
} __attribute__((aligned(8)));
/**
* @brief Info to create or destroy a virtual PCI or legacy device for a VM
*

View File

@ -56,8 +56,8 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
.pt_tpm2 = true,
.mmiodevs[0] =
{
.base_gpa = VM0_TPM_BUFFER_BASE_ADDR_GPA,
.base_hpa = VM0_TPM_BUFFER_BASE_ADDR,
.user_vm_pa = VM0_TPM_BUFFER_BASE_ADDR_GPA,
.service_vm_pa = VM0_TPM_BUFFER_BASE_ADDR,
.size = VM0_TPM_BUFFER_SIZE,
},
#endif
@ -65,8 +65,8 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
.pt_p2sb_bar = true,
.mmiodevs[0] =
{
.base_gpa = P2SB_BAR_ADDR_GPA,
.base_hpa = P2SB_BAR_ADDR,
.user_vm_pa = P2SB_BAR_ADDR_GPA,
.service_vm_pa = P2SB_BAR_ADDR,
.size = P2SB_BAR_SIZE,
},
#endif

View File

@ -59,8 +59,8 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
.pt_tpm2 = true,
.mmiodevs[0] =
{
.base_gpa = VM0_TPM_BUFFER_BASE_ADDR_GPA,
.base_hpa = VM0_TPM_BUFFER_BASE_ADDR,
.user_vm_pa = VM0_TPM_BUFFER_BASE_ADDR_GPA,
.service_vm_pa = VM0_TPM_BUFFER_BASE_ADDR,
.size = VM0_TPM_BUFFER_SIZE,
},
#endif
@ -68,8 +68,8 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
.pt_p2sb_bar = true,
.mmiodevs[0] =
{
.base_gpa = P2SB_BAR_ADDR_GPA,
.base_hpa = P2SB_BAR_ADDR,
.user_vm_pa = P2SB_BAR_ADDR_GPA,
.service_vm_pa = P2SB_BAR_ADDR,
.size = P2SB_BAR_SIZE,
},
#endif

View File

@ -54,8 +54,8 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
.pt_tpm2 = true,
.mmiodevs[0] =
{
.base_gpa = VM0_TPM_BUFFER_BASE_ADDR_GPA,
.base_hpa = VM0_TPM_BUFFER_BASE_ADDR,
.user_vm_pa = VM0_TPM_BUFFER_BASE_ADDR_GPA,
.service_vm_pa = VM0_TPM_BUFFER_BASE_ADDR,
.size = VM0_TPM_BUFFER_SIZE,
},
#endif
@ -63,8 +63,8 @@ struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {
.pt_p2sb_bar = true,
.mmiodevs[0] =
{
.base_gpa = P2SB_BAR_ADDR_GPA,
.base_hpa = P2SB_BAR_ADDR,
.user_vm_pa = P2SB_BAR_ADDR_GPA,
.service_vm_pa = P2SB_BAR_ADDR,
.size = P2SB_BAR_SIZE,
},
#endif

View File

@ -340,8 +340,8 @@ def gen_pre_launch_vm(vm_type, vm_i, scenario_items, config):
print("#ifdef VM0_PASSTHROUGH_TPM", file=config)
print("\t\t.pt_tpm2 = true,", file=config)
print("\t\t.mmiodevs[0] = {", file=config)
print("\t\t\t.base_gpa = VM0_TPM_BUFFER_BASE_ADDR_GPA,", file=config)
print("\t\t\t.base_hpa = VM0_TPM_BUFFER_BASE_ADDR,", file=config)
print("\t\t\t.user_vm_pa = VM0_TPM_BUFFER_BASE_ADDR_GPA,", file=config)
print("\t\t\t.service_vm_pa = VM0_TPM_BUFFER_BASE_ADDR,", file=config)
print("\t\t\t.size = VM0_TPM_BUFFER_SIZE,", file=config)
print("\t\t},", file=config)
print("#endif", file=config)
@ -350,8 +350,8 @@ def gen_pre_launch_vm(vm_type, vm_i, scenario_items, config):
print("#ifdef P2SB_BAR_ADDR", file=config)
print("\t\t.pt_p2sb_bar = true,", file=config)
print("\t\t.mmiodevs[0] = {", file=config)
print("\t\t\t.base_gpa = P2SB_BAR_ADDR_GPA,", file=config)
print("\t\t\t.base_hpa = P2SB_BAR_ADDR,", file=config)
print("\t\t\t.user_vm_pa = P2SB_BAR_ADDR_GPA,", file=config)
print("\t\t\t.service_vm_pa = P2SB_BAR_ADDR,", file=config)
print("\t\t\t.size = P2SB_BAR_SIZE,", file=config)
print("\t\t},", file=config)
print("#endif", file=config)

View File

@ -238,8 +238,8 @@
<xsl:value-of select="acrn:ifdef('VM0_PASSTHROUGH_TPM')" />
<xsl:value-of select="acrn:initializer('pt_tpm2', 'true')" />
<xsl:value-of select="acrn:initializer('mmiodevs[0]', '{', true())" />
<xsl:value-of select="acrn:initializer('base_gpa', 'VM0_TPM_BUFFER_BASE_ADDR_GPA')" />
<xsl:value-of select="acrn:initializer('base_hpa', 'VM0_TPM_BUFFER_BASE_ADDR')" />
<xsl:value-of select="acrn:initializer('user_vm_pa', 'VM0_TPM_BUFFER_BASE_ADDR_GPA')" />
<xsl:value-of select="acrn:initializer('service_vm_pa', 'VM0_TPM_BUFFER_BASE_ADDR')" />
<xsl:value-of select="acrn:initializer('size', 'VM0_TPM_BUFFER_SIZE')" />
<xsl:text>},</xsl:text>
<xsl:value-of select="$newline" />
@ -247,8 +247,8 @@
<xsl:value-of select="acrn:ifdef('P2SB_BAR_ADDR')" />
<xsl:value-of select="acrn:initializer('pt_p2sb_bar', 'true')" />
<xsl:value-of select="acrn:initializer('mmiodevs[0]', '{', true())" />
<xsl:value-of select="acrn:initializer('base_gpa', 'P2SB_BAR_ADDR_GPA')" />
<xsl:value-of select="acrn:initializer('base_hpa', 'P2SB_BAR_ADDR')" />
<xsl:value-of select="acrn:initializer('user_vm_pa', 'P2SB_BAR_ADDR_GPA')" />
<xsl:value-of select="acrn:initializer('service_vm_pa', 'P2SB_BAR_ADDR')" />
<xsl:value-of select="acrn:initializer('size', 'P2SB_BAR_SIZE')" />
<xsl:text>},</xsl:text>
<xsl:value-of select="$newline" />