Skip to content

Commit 34f9a6f

Browse files
committed
add ioctl
1 parent 47325a6 commit 34f9a6f

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

drivers/hv/mshv_vtl_main.c

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -663,25 +663,23 @@ static int mshv_vtl_alloc_context(unsigned int cpu)
663663
return ret;
664664

665665
if (cc_platform_has(CC_ATTR_SNP_SECURE_AVIC)) {
666-
struct page *page = alloc_page(GFP_KERNEL | __GFP_ZERO);
667-
void *secure_avic_page;
666+
struct page *secure_avic_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
668667

669-
if (!page)
668+
if (!secure_avic_page)
670669
return -ENOMEM;
671-
secure_avic_page = page_address(page);
672670

673671
/* VMPL 2 for the VTL0 */
674-
ret = rmpadjust((unsigned long)secure_avic_page,
672+
ret = rmpadjust((unsigned long)page_address(secure_avic_page),
675673
RMP_PG_SIZE_4K, 2 | RMPADJUST_ENABLE_READ | RMPADJUST_ENABLE_WRITE);
676674
if (ret) {
677675
pr_err("failed to adjust RMP for the secure AVIC page: %d\n", ret);
678-
free_page((u64)page);
676+
free_page((u64)secure_avic_page);
679677
return -EINVAL;
680678
}
681679
pr_debug("VTL0 secure AVIC page allocated, CPU %d\n", cpu);
682680

683681
/* is the environment quiet enough to capture a consistent state? */
684-
x2apic_savic_init_backing_page(secure_avic_page);
682+
x2apic_savic_init_backing_page(page_address(secure_avic_page));
685683
per_cpu->secure_avic_page = secure_avic_page;
686684
}
687685
#endif
@@ -1889,6 +1887,41 @@ static long mshv_vtl_ioctl_guest_vsm_vmsa_pfn(void __user *user_arg)
18891887

18901888
return ret;
18911889
}
1890+
1891+
static void secure_avic_vtl0_this_cpu(void *arg)
1892+
{
1893+
int cpu;
1894+
struct page *secure_avic_page;
1895+
u64 *pfn = arg;
1896+
1897+
cpu = get_cpu();
1898+
secure_avic_page = *this_cpu_ptr(&mshv_vtl_per_cpu.secure_avic_page);
1899+
put_cpu();
1900+
1901+
*pfn = secure_avic_page ? page_to_pfn(secure_avic_page) : -ENOMEM;
1902+
}
1903+
1904+
static long mshv_vtl_ioctl_secure_avic_vtl0_pfn(void __user *user_arg)
1905+
{
1906+
u64 pfn;
1907+
u32 cpu_id;
1908+
long ret;
1909+
1910+
ret = copy_from_user(&cpu_id, user_arg, sizeof(cpu_id)) ? -EFAULT : 0;
1911+
if (ret)
1912+
return ret;
1913+
1914+
ret = smp_call_function_single(cpu_id, secure_avic_vtl0_this_cpu, &pfn, true);
1915+
if (ret)
1916+
return ret;
1917+
ret = (long)pfn;
1918+
if (ret < 0)
1919+
return ret;
1920+
1921+
ret = copy_to_user(user_arg, &pfn, sizeof(pfn)) ? -EFAULT : 0;
1922+
1923+
return ret;
1924+
}
18921925
#endif
18931926

18941927
static long
@@ -1942,6 +1975,9 @@ mshv_vtl_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
19421975
case MSHV_VTL_GUEST_VSM_VMSA_PFN:
19431976
ret = mshv_vtl_ioctl_guest_vsm_vmsa_pfn((void __user *)arg);
19441977
break;
1978+
case MSHV_VTL_SECURE_AVIC_VTL0_PFN:
1979+
ret = mshv_vtl_ioctl_secure_avic_vtl0_pfn((void __user *)arg);
1980+
break;
19451981
#endif
19461982

19471983
default:

include/uapi/linux/mshv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ struct mshv_invlpgb {
351351
#define MSHV_VTL_RMPQUERY _IOW(MSHV_IOCTL, 0x35, struct mshv_rmpquery)
352352
#define MSHV_VTL_INVLPGB _IOW(MSHV_IOCTL, 0x36, struct mshv_invlpgb)
353353
#define MSHV_VTL_TLBSYNC _IO(MSHV_IOCTL, 0x37)
354+
#define MSHV_VTL_SECURE_AVIC_VTL0_PFN _IO(MSHV_IOCTL, 0x38)
354355

355356
/* VMBus device IOCTLs */
356357
#define MSHV_SINT_SIGNAL_EVENT _IOW(MSHV_IOCTL, 0x22, struct mshv_vtl_signal_event)

0 commit comments

Comments
 (0)