Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp5148652pxb; Tue, 28 Sep 2021 11:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz58oYWWFxwFjcLe+dK//NobtSe3rcymZfm52Pm3v/LLboOzuLN0b1ZTkalxWXhxB1jq4o6 X-Received: by 2002:a17:90b:111:: with SMTP id p17mr1518905pjz.225.1632853966660; Tue, 28 Sep 2021 11:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632853966; cv=none; d=google.com; s=arc-20160816; b=zfayGmBCr2HnaBm1pC7A5EabefugyRkl58dtfuVwCRxbhfAP7dXKNdYQL2KxuX8RX6 y4ACrPQ7rMyAxkr6CZCK2MAReAdtNuIz86RATOB0k5kASidE/DSi4Dwk9ipqB77yXSxc +vtiwXCD5/Hfua1uynCZA2egbSn8v8DbH06tdlAZujD3XfKkxEhb7DRacS3AVgSOSeWX 7rrzq41kGAdRdvow+6GUYMJbAMY8vEHyyqz8KnmGbFQKLV0/qG9Lxmiz4F0OVs1n+ela 2Z2T613VpE+92zoDCJ7F/+xFoaYYMj2DIxunby3wJtpiwlxT3f80d4QEcMaM9xEmvjtB Lz0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=1oeJbjSXwAb0ssDXgaPPwIFVcrq/IYAl6vElWXKXlTI=; b=wtLMkr9GzBK7aw1vXx4J0cOnCyyvI/kzif0uT1uxYlV5wIfU99DMnGBDoMtXm3awIs h3zBemL6SaAwft6FMGxVrpbVX7QWWmh5wkhEVrlqcHUSJVRb4UShhHlS/FtmJHcQ3kR5 U8ski03oipzLMns1cq9lOsbLdp4JjMZ+rdpWNQYzGoWvcoeCXK5NyaSLKpMUBJYEcG58 Fxwc3gEhufuvClhrLBokU++a60i5WYgmG/xAEAnDfkyl8Zt+7IkXlmStnSMNg7AKXJ6j ypIGXHR3d0mfB6MH9OvVR20Hooo9OWRFt/QjuV/NiFByojiKQdHaVxfDCjx3y+unWc3N KRZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Si5p/uJf"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si26953118pfk.30.2021.09.28.11.32.34; Tue, 28 Sep 2021 11:32:46 -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=@linux.microsoft.com header.s=default header.b="Si5p/uJf"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242321AbhI1SdK (ORCPT + 99 others); Tue, 28 Sep 2021 14:33:10 -0400 Received: from linux.microsoft.com ([13.77.154.182]:50866 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242161AbhI1SdB (ORCPT ); Tue, 28 Sep 2021 14:33:01 -0400 Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 1BEEA20B8799; Tue, 28 Sep 2021 11:31:21 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1BEEA20B8799 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1632853881; bh=1oeJbjSXwAb0ssDXgaPPwIFVcrq/IYAl6vElWXKXlTI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Si5p/uJf3PkYjK9zQ7SdftCk4BxgCsSmOT6odiJMosDOKdYDXiU3LMTbY+m9Q0qph g/t69QvtIZxx8AE975Oi2nSTwfq4n6ddYDOnITqkgNPgxW7v3sFMDmapGd3ov9jMdc 02fQNhQpL7CUDGp6DToewyeaRgERb2PJmRJS2IfM= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Cc: virtualization@lists.linux-foundation.org, mikelley@microsoft.com, viremana@linux.microsoft.com, sunilmut@microsoft.com, wei.liu@kernel.org, vkuznets@redhat.com, ligrassi@microsoft.com, kys@microsoft.com, sthemmin@microsoft.com, anbelski@linux.microsoft.com Subject: [PATCH v3 04/19] drivers/hv: check extension ioctl Date: Tue, 28 Sep 2021 11:31:00 -0700 Message-Id: <1632853875-20261-5-git-send-email-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1632853875-20261-1-git-send-email-nunodasneves@linux.microsoft.com> References: <1632853875-20261-1-git-send-email-nunodasneves@linux.microsoft.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reserve ioctl number in userpsace-api/ioctl/ioctl-number.rst Introduce MSHV_CHECK_EXTENSION ioctl. Introduce documentation for /dev/mshv in Documentation/virt/mshv Signed-off-by: Nuno Das Neves --- .../userspace-api/ioctl/ioctl-number.rst | 2 + Documentation/virt/mshv/api.rst | 60 +++++++++++++++++++ drivers/hv/mshv_main.c | 23 +++++++ include/linux/mshv.h | 11 ++++ include/uapi/linux/mshv.h | 20 +++++++ 5 files changed, 116 insertions(+) create mode 100644 Documentation/virt/mshv/api.rst create mode 100644 include/linux/mshv.h create mode 100644 include/uapi/linux/mshv.h diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst index 9bfc2b510c64..585d9cc42a5a 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -350,6 +350,8 @@ Code Seq# Include File Comments 0xB6 all linux/fpga-dfl.h 0xB7 all uapi/linux/remoteproc_cdev.h 0xB7 all uapi/linux/nsfs.h > +0xB8 all uapi/linux/mshv.h Microsoft Hypervisor root partition APIs + 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h 0xCA 10-2F uapi/misc/ocxl.h diff --git a/Documentation/virt/mshv/api.rst b/Documentation/virt/mshv/api.rst new file mode 100644 index 000000000000..75c5e073ecc0 --- /dev/null +++ b/Documentation/virt/mshv/api.rst @@ -0,0 +1,60 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================================================== +Microsoft Hypervisor Root Partition API Documentation +===================================================== + +1. Overview +=========== + +This document describes APIs for creating and managing guest virtual machines +when running Linux as the root partition on the Microsoft Hypervisor. + +Note that this API is not yet stable! + +2. Glossary/Terms +================= + +hv +-- +Short for Hyper-V. This name is used in the kernel to describe interfaces to +the Microsoft Hypervisor. + +mshv +---- +Short for Microsoft Hypervisor. This is the name of the userland API module +described in this document. + +Partition +--------- +A virtual machine running on the Microsoft Hypervisor. + +Root Partition +-------------- +The partition that is created and assumes control when the machine boots. The +root partition can use mshv APIs to create guest partitions. + +3. API description +================== + +The module is named mshv and can be configured with CONFIG_HYPERV_ROOT_API. + +Mshv is file descriptor-based, following a similar pattern to KVM. + +To get a handle to the mshv driver, use open("/dev/mshv"). + +3.1 MSHV_CHECK_EXTENSION +------------------------ +:Type: /dev/mshv ioctl +:Parameters: pointer to a u32 +:Returns: 0 if extension unsupported, positive number if supported + +This ioctl takes a single argument corresponding to an API extension to check +support for. + +If the extension is supported, MSHV_CHECK_EXTENSION will return a positive +number. If not, it will return 0. + +The first extension that can be checked is MSHV_CAP_CORE_API_STABLE. This +will be supported when the core API is stable. + diff --git a/drivers/hv/mshv_main.c b/drivers/hv/mshv_main.c index e44adf91f660..d73b64ea1448 100644 --- a/drivers/hv/mshv_main.c +++ b/drivers/hv/mshv_main.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include MODULE_AUTHOR("Microsoft"); MODULE_LICENSE("GPL"); @@ -34,9 +36,30 @@ static struct miscdevice mshv_dev = { .mode = 0600, }; +static long +mshv_ioctl_check_extension(void __user *user_arg) +{ + u32 arg; + + if (copy_from_user(&arg, user_arg, sizeof(arg))) + return -EFAULT; + + switch (arg) { + case MSHV_CAP_CORE_API_STABLE: + return 0; + } + + return -EOPNOTSUPP; +} + static long mshv_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { + switch (ioctl) { + case MSHV_CHECK_EXTENSION: + return mshv_ioctl_check_extension((void __user *)arg); + } + return -ENOTTY; } diff --git a/include/linux/mshv.h b/include/linux/mshv.h new file mode 100644 index 000000000000..a0982fe2c0b8 --- /dev/null +++ b/include/linux/mshv.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _LINUX_MSHV_H +#define _LINUX_MSHV_H + +/* + * Microsoft Hypervisor root partition driver for /dev/mshv + */ + +#include + +#endif diff --git a/include/uapi/linux/mshv.h b/include/uapi/linux/mshv.h new file mode 100644 index 000000000000..3b84e3ea97be --- /dev/null +++ b/include/uapi/linux/mshv.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_MSHV_H +#define _UAPI_LINUX_MSHV_H + +/* + * Userspace interface for /dev/mshv + * Microsoft Hypervisor root partition APIs + * NOTE: This API is not yet stable! + */ + +#include + +#define MSHV_CAP_CORE_API_STABLE 0x0 + +#define MSHV_IOCTL 0xB8 + +/* mshv device */ +#define MSHV_CHECK_EXTENSION _IOW(MSHV_IOCTL, 0x00, __u32) + +#endif -- 2.23.4