Skip to content

Commit f95d07d

Browse files
binbinwu1wenlingz
authored andcommitted
hv: vtd: use EPT as translation table for PTDev in SOS
In current code, the address translation type for passthrough devices in SOS is passthrough type, which means the device in SOS can access the whole physcial memory. This patch uses SOS EPT to translate address for passthrough devices. So that the memory of VMM or trusty can be protected from SOS PTDev. Signed-off-by: Binbin Wu <binbin.wu@intel.com> Reviewed-by: Li, Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 4579e57 commit f95d07d

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

hypervisor/arch/x86/guest/vm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <hypervisor.h>
88
#include <bsp_extern.h>
99
#include <multiboot.h>
10+
#include <vtd.h>
1011

1112
/* Local variables */
1213

@@ -163,6 +164,7 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
163164
goto err;
164165
}
165166
#endif
167+
init_iommu_vm0_domain(vm);
166168
} else {
167169
/* populate UOS vm fields according to vm_desc */
168170
vm->sworld_control.flag.supported =

hypervisor/arch/x86/vtd.c

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ static uint32_t dmar_hdrh_unit_count;
168168
static uint32_t max_domain_id = 63U;
169169
static uint64_t domain_bitmap;
170170
static spinlock_t domain_lock;
171-
static struct iommu_domain *host_domain;
171+
172+
static struct iommu_domain *vm0_domain;
172173
static struct list_head iommu_domains;
173174

174175
static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint);
@@ -516,20 +517,6 @@ static void free_domain_id(uint16_t dom_id)
516517
spinlock_release(&domain_lock);
517518
}
518519

519-
static struct iommu_domain *create_host_domain(void)
520-
{
521-
struct iommu_domain *domain = calloc(1U, sizeof(struct iommu_domain));
522-
523-
ASSERT(domain != NULL, "");
524-
domain->is_host = true;
525-
domain->dom_id = alloc_domain_id();
526-
/* dmar uint need to support translation passthrough */
527-
domain->trans_table_ptr = 0UL;
528-
domain->addr_width = 48U;
529-
530-
return domain;
531-
}
532-
533520
static void dmar_write_buffer_flush(struct dmar_drhd_rt *dmar_uint)
534521
{
535522
uint32_t status;
@@ -1148,7 +1135,7 @@ int assign_iommu_device(struct iommu_domain *domain, uint8_t bus,
11481135

11491136
/* TODO: check if the device assigned */
11501137

1151-
remove_iommu_device(host_domain, 0U, bus, devfun);
1138+
remove_iommu_device(vm0_domain, 0U, bus, devfun);
11521139
add_iommu_device(domain, 0U, bus, devfun);
11531140
return 0;
11541141
}
@@ -1163,7 +1150,7 @@ int unassign_iommu_device(struct iommu_domain *domain, uint8_t bus,
11631150
/* TODO: check if the device assigned */
11641151

11651152
remove_iommu_device(domain, 0U, bus, devfun);
1166-
add_iommu_device(host_domain, 0U, bus, devfun);
1153+
add_iommu_device(vm0_domain, 0U, bus, devfun);
11671154
return 0;
11681155
}
11691156

@@ -1282,24 +1269,30 @@ void resume_iommu(void)
12821269

12831270
void init_iommu(void)
12841271
{
1285-
uint16_t bus;
1286-
uint16_t devfun;
1287-
12881272
INIT_LIST_HEAD(&dmar_drhd_units);
12891273
INIT_LIST_HEAD(&iommu_domains);
12901274

12911275
spinlock_init(&domain_lock);
12921276

12931277
register_hrhd_units();
1278+
}
12941279

1295-
host_domain = create_host_domain();
1280+
void init_iommu_vm0_domain(struct vm *vm0)
1281+
{
1282+
uint16_t bus;
1283+
uint16_t devfun;
1284+
1285+
vm0->iommu = create_iommu_domain(vm0->vm_id,
1286+
HVA2HPA(vm0->arch_vm.nworld_eptp), 48U);
1287+
1288+
vm0_domain = (struct iommu_domain *) vm0->iommu;
12961289

12971290
for (bus = 0U; bus <= IOMMU_INIT_BUS_LIMIT; bus++) {
12981291
for (devfun = 0U; devfun <= 255U; devfun++) {
1299-
add_iommu_device(host_domain, 0U,
1300-
(uint8_t)bus, (uint8_t)devfun);
1292+
add_iommu_device(vm0_domain, 0U,
1293+
(uint8_t)bus, (uint8_t)devfun);
13011294
}
13021295
}
1303-
1296+
CACHE_FLUSH_INVALIDATE_ALL();
13041297
enable_iommu();
13051298
}

hypervisor/include/arch/x86/vtd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,6 @@ void resume_iommu(void);
496496

497497
/* iommu initialization */
498498
void init_iommu(void);
499+
void init_iommu_vm0_domain(struct vm *vm0);
500+
499501
#endif

0 commit comments

Comments
 (0)