Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2330672pxk; Sun, 27 Sep 2020 03:47:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRnTwx+0Fj04VhOcDkwTNC53uLC913cJY0y6KXtp+C2Jg93SrfU88rGuQZmy46fR5kh0nS X-Received: by 2002:a05:6402:64b:: with SMTP id u11mr10004591edx.147.1601203651389; Sun, 27 Sep 2020 03:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601203651; cv=none; d=google.com; s=arc-20160816; b=fZanDbIRVsURTKM+S0rJGlynk85hb8DZ7RSh+JXfN3ptp/9OlK/xXP8EEGqiY4jm3K wgVw8Hjny9lnFvkMKcfK99iN4CdFnload3F5roCUlAR/rqxbmxrkvADhAZQJqTDpbe3J RYlb3ObJ1YUnkZUsiK/jTTelhh8HPaXEN375Ogel5eeyuXa7e9GDam6sEKtNvdUjumjD kUs4ouDwE4YZID64NgXdvhgQSjA7f+DySy5pNRP4FIQxI0LQl0NN/4t+XN+xkMl+iOxf SC6gfzOjoOjtI+9J+WdeZlPf2CuSLm8rRNTeGZIwsHKU30yvGXFYTT60fYyQd7CGDm5/ D/ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WI8fzBnyBJhmfuI3hzncHzBNkGjyAQ0nyzmgq6H9Cc0=; b=nA9/7L1/xTzk3+MCYESU1ctfo4lUERb0keMyDtUVIQTuhCyhNEDKnJ7qesvC3XJrId Tt1TmM8VIhiLiAFINZaIDyhzH0AEOYNbI2Ex+seMTMvWtH1rZ2TPHGuuXBow078WLm+Z dcAXlKQpxb6L8L+5Iqwz5672UfodpUXo+iFvlFDZp15ZQjCUm41DWGXo26MuE2vxazmG qvppCjJAj2aXqVc/wcxPt2DYh3iOhQ1acccQGaSMkHB7q3nV1Be+4YDX0o5AJYwpTwbv EnBggXsIYygCPJHuwUfdD2ZBFVxsRMcLJLXlCh2nYrGAqGajLZbSA0jeG7UnrOiqPD4Z mr4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rCj3Vdp0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oq13si5413442ejb.308.2020.09.27.03.47.00; Sun, 27 Sep 2020 03:47:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rCj3Vdp0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726327AbgI0Kpd (ORCPT + 99 others); Sun, 27 Sep 2020 06:45:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:59602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbgI0Kp3 (ORCPT ); Sun, 27 Sep 2020 06:45:29 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3647C22207; Sun, 27 Sep 2020 10:45:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601203529; bh=vpId3SV8tixpmayxENUVAYIDaSBnpI8+QNsHHGhHM6A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rCj3Vdp0o15iVhZL+r+A/21IILdz1FmIfT06EYTtuYd1jHM4JQZFT0f3I+fY2jqVs W0MC8dgi4eB0rZZ9U8VobjfI/16+9Grjy1WHsllBM+VGipsxOuKqyUhLxjXk0queQp C6ZMgdDZog7gwNBlSWTS3kIvxzLYxCPE7/fACMaI= Date: Sun, 27 Sep 2020 12:45:38 +0200 From: Greg Kroah-Hartman To: shuo.a.liu@intel.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Sean Christopherson , Yu Wang , Reinette Chatre , Zhi Wang , Zhenyu Wang Subject: Re: [PATCH v4 06/17] virt: acrn: Introduce VM management interfaces Message-ID: <20200927104538.GD88650@kroah.com> References: <20200922114311.38804-1-shuo.a.liu@intel.com> <20200922114311.38804-7-shuo.a.liu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922114311.38804-7-shuo.a.liu@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 22, 2020 at 07:43:00PM +0800, shuo.a.liu@intel.com wrote: > From: Shuo Liu > > The VM management interfaces expose several VM operations to ACRN > userspace via ioctls. For example, creating VM, starting VM, destroying > VM and so on. > > The ACRN Hypervisor needs to exchange data with the ACRN userspace > during the VM operations. HSM provides VM operation ioctls to the ACRN > userspace and communicates with the ACRN Hypervisor for VM operations > via hypercalls. > > HSM maintains a list of User VM. Each User VM will be bound to an > existing file descriptor of /dev/acrn_hsm. The User VM will be > destroyed when the file descriptor is closed. > > Signed-off-by: Shuo Liu > Reviewed-by: Zhi Wang > Reviewed-by: Reinette Chatre > Cc: Zhi Wang > Cc: Zhenyu Wang > Cc: Yu Wang > Cc: Reinette Chatre > Cc: Greg Kroah-Hartman > --- > .../userspace-api/ioctl/ioctl-number.rst | 1 + > MAINTAINERS | 1 + > drivers/virt/acrn/Makefile | 2 +- > drivers/virt/acrn/acrn_drv.h | 23 +++++- > drivers/virt/acrn/hsm.c | 73 ++++++++++++++++- > drivers/virt/acrn/hypercall.h | 78 +++++++++++++++++++ > drivers/virt/acrn/vm.c | 71 +++++++++++++++++ > include/uapi/linux/acrn.h | 56 +++++++++++++ > 8 files changed, 301 insertions(+), 4 deletions(-) > create mode 100644 drivers/virt/acrn/hypercall.h > create mode 100644 drivers/virt/acrn/vm.c > create mode 100644 include/uapi/linux/acrn.h > > diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst > index 2a198838fca9..ac60efedb104 100644 > --- a/Documentation/userspace-api/ioctl/ioctl-number.rst > +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst > @@ -319,6 +319,7 @@ Code Seq# Include File Comments > 0xA0 all linux/sdp/sdp.h Industrial Device Project > > 0xA1 0 linux/vtpm_proxy.h TPM Emulator Proxy Driver > +0xA2 all uapi/linux/acrn.h ACRN hypervisor > 0xA3 80-8F Port ACL in development: > > 0xA3 90-9F linux/dtlk.h > diff --git a/MAINTAINERS b/MAINTAINERS > index 3030d0e93d02..d4c1ef303c2d 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -443,6 +443,7 @@ S: Supported > W: https://projectacrn.org > F: Documentation/virt/acrn/ > F: drivers/virt/acrn/ > +F: include/uapi/linux/acrn.h > > AD1889 ALSA SOUND DRIVER > L: linux-parisc@vger.kernel.org > diff --git a/drivers/virt/acrn/Makefile b/drivers/virt/acrn/Makefile > index 6920ed798aaf..cf8b4ed5e74e 100644 > --- a/drivers/virt/acrn/Makefile > +++ b/drivers/virt/acrn/Makefile > @@ -1,3 +1,3 @@ > # SPDX-License-Identifier: GPL-2.0 > obj-$(CONFIG_ACRN_HSM) := acrn.o > -acrn-y := hsm.o > +acrn-y := hsm.o vm.o > diff --git a/drivers/virt/acrn/acrn_drv.h b/drivers/virt/acrn/acrn_drv.h > index 29eedd696327..72d92b60d944 100644 > --- a/drivers/virt/acrn/acrn_drv.h > +++ b/drivers/virt/acrn/acrn_drv.h > @@ -3,16 +3,37 @@ > #ifndef __ACRN_HSM_DRV_H > #define __ACRN_HSM_DRV_H > > +#include > +#include > +#include > #include > > +#include "hypercall.h" > + > +extern struct miscdevice acrn_dev; Who else needs to get to this structure in your driver? > + > #define ACRN_INVALID_VMID (0xffffU) > > +#define ACRN_VM_FLAG_DESTROYED 0U > +extern struct list_head acrn_vm_list; > +extern rwlock_t acrn_vm_list_lock; > /** > * struct acrn_vm - Properties of ACRN User VM. > + * @list: Entry within global list of all VMs > * @vmid: User VM ID > + * @vcpu_num: Number of virtual CPUs in the VM > + * @flags: Flags (ACRN_VM_FLAG_*) of the VM. This is VM flag management > + * in HSM which is different from the &acrn_vm_creation.vm_flag. > */ > struct acrn_vm { > - u16 vmid; > + struct list_head list; > + u16 vmid; > + int vcpu_num; > + unsigned long flags; > }; > > +struct acrn_vm *acrn_vm_create(struct acrn_vm *vm, > + struct acrn_vm_creation *vm_param); > +int acrn_vm_destroy(struct acrn_vm *vm); > + > #endif /* __ACRN_HSM_DRV_H */ > diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c > index 28a3052ffa55..f3e6467b8723 100644 > --- a/drivers/virt/acrn/hsm.c > +++ b/drivers/virt/acrn/hsm.c > @@ -9,7 +9,6 @@ > * Yakui Zhao > */ > > -#include > #include > #include > #include > @@ -38,10 +37,79 @@ static int acrn_dev_open(struct inode *inode, struct file *filp) > return 0; > } > > +/* > + * HSM relies on hypercall layer of the ACRN hypervisor to do the > + * sanity check against the input parameters. > + */ > +static long acrn_dev_ioctl(struct file *filp, unsigned int cmd, > + unsigned long ioctl_param) > +{ > + struct acrn_vm *vm = filp->private_data; > + struct acrn_vm_creation *vm_param; > + int ret = 0; > + > + if (vm->vmid == ACRN_INVALID_VMID && cmd != ACRN_IOCTL_CREATE_VM) { > + dev_dbg(acrn_dev.this_device, > + "ioctl 0x%x: Invalid VM state!\n", cmd); > + return -EINVAL; > + } > + > + switch (cmd) { > + case ACRN_IOCTL_CREATE_VM: > + vm_param = memdup_user((void __user *)ioctl_param, > + sizeof(struct acrn_vm_creation)); > + if (IS_ERR(vm_param)) > + return PTR_ERR(vm_param); > + > + vm = acrn_vm_create(vm, vm_param); > + if (!vm) { > + ret = -EINVAL; > + kfree(vm_param); > + break; > + } > + > + if (copy_to_user((void __user *)ioctl_param, vm_param, > + sizeof(struct acrn_vm_creation))) { > + acrn_vm_destroy(vm); > + ret = -EFAULT; > + } > + > + kfree(vm_param); > + break; > + case ACRN_IOCTL_START_VM: > + ret = hcall_start_vm(vm->vmid); > + if (ret < 0) > + dev_err(acrn_dev.this_device, > + "Failed to start VM %u!\n", vm->vmid); > + break; > + case ACRN_IOCTL_PAUSE_VM: > + ret = hcall_pause_vm(vm->vmid); > + if (ret < 0) > + dev_err(acrn_dev.this_device, > + "Failed to pause VM %u!\n", vm->vmid); > + break; > + case ACRN_IOCTL_RESET_VM: > + ret = hcall_reset_vm(vm->vmid); > + if (ret < 0) > + dev_err(acrn_dev.this_device, > + "Failed to restart VM %u!\n", vm->vmid); > + break; > + case ACRN_IOCTL_DESTROY_VM: > + ret = acrn_vm_destroy(vm); > + break; > + default: > + dev_warn(acrn_dev.this_device, "Unknown IOCTL 0x%x!\n", cmd); Do not let userspace spam kernel logs with invalid stuff, that's a sure way to cause a DoS. thanks, greg k-h