ANDROID: virt: geniezone: Refactor code comments from mainline v6 accordingly
Sync changes to align with upstream-v6 [Detail] - Response to reviewers and fix bugs accordingly Change-Id: I4ba05da2875542f067b8b275ce68a4869dcf9ca0 Signed-off-by: Yingshiuan Pan <yingshiuan.pan@mediatek.com> Signed-off-by: Liju-Clr Chen <liju-clr.chen@mediatek.com> Signed-off-by: Yi-De Wu <yi-de.wu@mediatek.com> Bug: 301179926 Link: https://lore.kernel.org/all/20230919111210.19615-1-yi-de.wu@mediatek.com/
This commit is contained in:
parent
544b128747
commit
9f64b18da1
5 changed files with 40 additions and 29 deletions
|
|
@ -3,7 +3,6 @@
|
||||||
* Copyright (c) 2023 MediaTek Inc.
|
* Copyright (c) 2023 MediaTek Inc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <asm/sysreg.h>
|
|
||||||
#include <linux/arm-smccc.h>
|
#include <linux/arm-smccc.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
|
|
@ -30,10 +29,10 @@ int gzvm_arch_probe(void)
|
||||||
struct arm_smccc_res res;
|
struct arm_smccc_res res;
|
||||||
|
|
||||||
arm_smccc_hvc(MT_HVC_GZVM_PROBE, 0, 0, 0, 0, 0, 0, 0, &res);
|
arm_smccc_hvc(MT_HVC_GZVM_PROBE, 0, 0, 0, 0, 0, 0, 0, &res);
|
||||||
if (res.a0 == 0)
|
if (res.a0)
|
||||||
return 0;
|
return -ENXIO;
|
||||||
|
|
||||||
return -ENXIO;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gzvm_arch_set_memregion(u16 vm_id, size_t buf_size,
|
int gzvm_arch_set_memregion(u16 vm_id, size_t buf_size,
|
||||||
|
|
@ -94,11 +93,7 @@ int gzvm_arch_create_vm(unsigned long vm_type)
|
||||||
|
|
||||||
ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_CREATE_VM, vm_type, 0, 0, 0, 0,
|
ret = gzvm_hypcall_wrapper(MT_HVC_GZVM_CREATE_VM, vm_type, 0, 0, 0, 0,
|
||||||
0, 0, &res);
|
0, 0, &res);
|
||||||
|
return ret ? ret : res.a1;
|
||||||
if (ret == 0)
|
|
||||||
return res.a1;
|
|
||||||
else
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gzvm_arch_destroy_vm(u16 vm_id)
|
int gzvm_arch_destroy_vm(u16 vm_id)
|
||||||
|
|
@ -221,12 +216,12 @@ int gzvm_vm_ioctl_arch_enable_cap(struct gzvm *gzvm,
|
||||||
* gzvm_hva_to_pa_arch() - converts hva to pa with arch-specific way
|
* gzvm_hva_to_pa_arch() - converts hva to pa with arch-specific way
|
||||||
* @hva: Host virtual address.
|
* @hva: Host virtual address.
|
||||||
*
|
*
|
||||||
* Return: 0 if translation error
|
* Return: GZVM_PA_ERR_BAD for translation error
|
||||||
*/
|
*/
|
||||||
u64 gzvm_hva_to_pa_arch(u64 hva)
|
u64 gzvm_hva_to_pa_arch(u64 hva)
|
||||||
{
|
{
|
||||||
u64 par;
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
u64 par;
|
||||||
|
|
||||||
local_irq_save(flags);
|
local_irq_save(flags);
|
||||||
asm volatile("at s1e1r, %0" :: "r" (hva));
|
asm volatile("at s1e1r, %0" :: "r" (hva));
|
||||||
|
|
@ -235,7 +230,9 @@ u64 gzvm_hva_to_pa_arch(u64 hva)
|
||||||
local_irq_restore(flags);
|
local_irq_restore(flags);
|
||||||
|
|
||||||
if (par & SYS_PAR_EL1_F)
|
if (par & SYS_PAR_EL1_F)
|
||||||
return 0;
|
return GZVM_PA_ERR_BAD;
|
||||||
|
par = par & PAR_PA47_MASK;
|
||||||
return par & PAR_PA47_MASK;
|
if (!par)
|
||||||
|
return GZVM_PA_ERR_BAD;
|
||||||
|
return par;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,13 +35,16 @@ static bool ioeventfd_check_collision(struct gzvm *gzvm, struct gzvm_ioevent *p)
|
||||||
{
|
{
|
||||||
struct gzvm_ioevent *_p;
|
struct gzvm_ioevent *_p;
|
||||||
|
|
||||||
list_for_each_entry(_p, &gzvm->ioevents, list)
|
list_for_each_entry(_p, &gzvm->ioevents, list) {
|
||||||
if (_p->addr == p->addr &&
|
if (_p->addr == p->addr &&
|
||||||
(!_p->len || !p->len ||
|
(!_p->len || !p->len ||
|
||||||
(_p->len == p->len &&
|
(_p->len == p->len &&
|
||||||
(_p->wildcard || p->wildcard ||
|
(_p->wildcard || p->wildcard ||
|
||||||
_p->datamatch == p->datamatch))))
|
_p->datamatch == p->datamatch))))
|
||||||
return true;
|
return true;
|
||||||
|
if (p->addr >= _p->addr && p->addr < _p->addr + _p->len)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,13 @@
|
||||||
* Copyright (c) 2023 MediaTek Inc.
|
* Copyright (c) 2023 MediaTek Inc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/anon_inodes.h>
|
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/file.h>
|
#include <linux/file.h>
|
||||||
#include <linux/kdev_t.h>
|
#include <linux/kdev_t.h>
|
||||||
|
#include <linux/miscdevice.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/slab.h>
|
|
||||||
#include <linux/gzvm_drv.h>
|
#include <linux/gzvm_drv.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -121,7 +120,7 @@ static int gzvm_drv_remove(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct of_device_id gzvm_of_match[] = {
|
static const struct of_device_id gzvm_of_match[] = {
|
||||||
{ .compatible = "mediatek,geniezone-hyp", },
|
{ .compatible = "mediatek,geniezone-hyp" },
|
||||||
{/* sentinel */},
|
{/* sentinel */},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -171,16 +171,21 @@ static int fill_constituents(struct mem_region_addr_range *consti,
|
||||||
return nr_pages;
|
return nr_pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* register_memslot_addr_range() - Register memory region to GZ */
|
/**
|
||||||
|
* register_memslot_addr_range() - Register memory region to GenieZone
|
||||||
|
* @gzvm: Pointer to struct gzvm
|
||||||
|
* @memslot: Pointer to struct gzvm_memslot
|
||||||
|
*
|
||||||
|
* Return: 0 for success, negative number for error
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
register_memslot_addr_range(struct gzvm *gzvm, struct gzvm_memslot *memslot)
|
register_memslot_addr_range(struct gzvm *gzvm, struct gzvm_memslot *memslot)
|
||||||
{
|
{
|
||||||
struct gzvm_memory_region_ranges *region;
|
struct gzvm_memory_region_ranges *region;
|
||||||
u32 buf_size;
|
u32 buf_size = PAGE_SIZE * 2;
|
||||||
int max_nr_consti, remain_pages;
|
int max_nr_consti, remain_pages;
|
||||||
u64 gfn, gfn_end;
|
u64 gfn, gfn_end;
|
||||||
|
|
||||||
buf_size = PAGE_SIZE * 2;
|
|
||||||
region = alloc_pages_exact(buf_size, GFP_KERNEL);
|
region = alloc_pages_exact(buf_size, GFP_KERNEL);
|
||||||
if (!region)
|
if (!region)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
@ -225,10 +230,11 @@ register_memslot_addr_range(struct gzvm *gzvm, struct gzvm_memslot *memslot)
|
||||||
* @gzvm: Pointer to struct gzvm.
|
* @gzvm: Pointer to struct gzvm.
|
||||||
* @mem: Input memory region from user.
|
* @mem: Input memory region from user.
|
||||||
*
|
*
|
||||||
* Return:
|
* Return: 0 for success, negative number for error
|
||||||
* * -EXIO - memslot is out-of-range
|
*
|
||||||
* * -EFAULT - Cannot find corresponding vma
|
* -EXIO - The memslot is out-of-range
|
||||||
* * -EINVAL - region size and vma size does not match
|
* -EFAULT - Cannot find corresponding vma
|
||||||
|
* -EINVAL - Region size and VMA size mismatch
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm,
|
gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm,
|
||||||
|
|
@ -345,7 +351,7 @@ static int gzvm_vm_ioctl_enable_cap(struct gzvm *gzvm,
|
||||||
static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl,
|
static long gzvm_vm_ioctl(struct file *filp, unsigned int ioctl,
|
||||||
unsigned long arg)
|
unsigned long arg)
|
||||||
{
|
{
|
||||||
long ret = -ENOTTY;
|
long ret;
|
||||||
void __user *argp = (void __user *)arg;
|
void __user *argp = (void __user *)arg;
|
||||||
struct gzvm *gzvm = filp->private_data;
|
struct gzvm *gzvm = filp->private_data;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,23 @@
|
||||||
|
|
||||||
#include <linux/eventfd.h>
|
#include <linux/eventfd.h>
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
|
#include <linux/mm.h>
|
||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
#include <linux/miscdevice.h>
|
|
||||||
#include <linux/gzvm.h>
|
#include <linux/gzvm.h>
|
||||||
#include <linux/srcu.h>
|
#include <linux/srcu.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For the normal physical address, the highest 12 bits should be zero, so we
|
||||||
|
* can mask bit 62 ~ bit 52 to indicate the error physical address
|
||||||
|
*/
|
||||||
|
#define GZVM_PA_ERR_BAD (0x7ffULL << 52)
|
||||||
|
|
||||||
#define GZVM_VCPU_MMAP_SIZE PAGE_SIZE
|
#define GZVM_VCPU_MMAP_SIZE PAGE_SIZE
|
||||||
#define INVALID_VM_ID 0xffff
|
#define INVALID_VM_ID 0xffff
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These are the efinitions of APIs between GenieZone hypervisor and driver,
|
* These are the definitions of APIs between GenieZone hypervisor and driver,
|
||||||
* there's no need to be visible to uapi. Furthermore, We need GenieZone
|
* there's no need to be visible to uapi. Furthermore, we need GenieZone
|
||||||
* specific error code in order to map to Linux errno
|
* specific error code in order to map to Linux errno
|
||||||
*/
|
*/
|
||||||
#define NO_ERROR (0)
|
#define NO_ERROR (0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue