Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp376902ybl; Thu, 15 Aug 2019 19:35:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMKM9mpmsJiKkleVfy84xnMRrCQ1GnVRSWcl+0qTOOz/IItIyIWuW4jq207D7IFxpy4vEt X-Received: by 2002:aa7:925a:: with SMTP id 26mr8541355pfp.198.1565922910346; Thu, 15 Aug 2019 19:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565922910; cv=none; d=google.com; s=arc-20160816; b=DxxJqCSq5WzFGbzF+aHId/92tRhzJ0N6lMPOHLfjt25cP4TwF0bh/Qqbpl2Ubw0lbT bYKSOCqz+mSdUoaEl4istHzGaVMq8TfnJi3i1AUehXJ1bqFO9WNt1mvFZaSSBEArc8DQ 7nS3SnOSGao7NOlPOwF2UY1AnD7USHQ8vlJ8/eqnDJO/pyFiwxwWJITuP9dU9u173N3Z T2e5OwW/7YE53T4MEt3YIwTPYQoKenXLqnDtcLy0/aBN1kXqJhPzXY5FMEXfZmaY9R/z Gpw21ceyqP02Pgkg1il/tAxpum16bEJ6i6Uc0caByp16C6F2vyqRVLynLdOkySlEpDOi XnUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Z5WQoS1D/Lu+eTe1KbT7gOFPJUqKRdwnmFDwn9h/uQU=; b=WFFQrK/zZFSXtYOAUeetglVlPnV98zkVG3FD6vgWXFgPpJ/XUwHCCvWxjVs+rcyGWI lm6ho8hWD9calFCP1P4bbZC6SUbMbEQK4BGY9Tubo3lq1JZdS1SE7oW7o2k+t3UCx4MM w4XWlH7NXxIZO7mnsFDVSSaYSmhiFoSoP9DY0RRRbkwjEQVJHogBXMDh71BcpNyxVC0R gH1hTd/I4SMhAMsfFzg7qkl7eGB94dnwJA8/2ml4Yi/Jwz/s7/rUoMcw7ivh5PerCqyf aKHPYzxWaRcQax7EyfyMASXiDzaiPnydddtJ1X1jja+DjKhRiZopQZhXBs/5VuRKA8a+ PzRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb21si2091615pjb.37.2019.08.15.19.34.55; Thu, 15 Aug 2019 19:35:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726825AbfHPCdw (ORCPT + 99 others); Thu, 15 Aug 2019 22:33:52 -0400 Received: from mga09.intel.com ([134.134.136.24]:24671 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726595AbfHPCdJ (ORCPT ); Thu, 15 Aug 2019 22:33:09 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Aug 2019 19:33:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,391,1559545200"; d="scan'208";a="194894506" Received: from genxtest-ykzhao.sh.intel.com ([10.239.143.71]) by fmsmga001.fm.intel.com with ESMTP; 15 Aug 2019 19:33:07 -0700 From: Zhao Yakui To: x86@kernel.org, linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org Cc: Zhao Yakui , Jason Chen CJ , Liu Shuo Subject: [RFC PATCH 06/15] drivers/acrn: add the support of querying ACRN api version Date: Fri, 16 Aug 2019 10:25:47 +0800 Message-Id: <1565922356-4488-7-git-send-email-yakui.zhao@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1565922356-4488-1-git-send-email-yakui.zhao@intel.com> References: <1565922356-4488-1-git-send-email-yakui.zhao@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to assure that the ACRN module can work with the required ACRN hypervisor, it needs to check whether the required version is consistent with the queried version from ACRN ypervisor. If it is inconsistent, it won't coninue the initialization of ACRN_HSM module. Similarly the user-space module also needs to check the driver version. Co-developed-by: Jason Chen CJ Signed-off-by: Jason Chen CJ Co-developed-by: Liu Shuo Signed-off-by: Liu Shuo Signed-off-by: Zhao Yakui --- drivers/staging/acrn/acrn_dev.c | 47 +++++++++++++++++++++++++++++++ include/uapi/linux/acrn/acrn_ioctl_defs.h | 32 +++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 include/uapi/linux/acrn/acrn_ioctl_defs.h diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c index 55a7612..57cd2bb 100644 --- a/drivers/staging/acrn/acrn_dev.c +++ b/drivers/staging/acrn/acrn_dev.c @@ -18,13 +18,22 @@ #include #include #include +#include #include +#include +#include #include #include +#include + +#include "acrn_hypercall.h" #define DEVICE_NAME "acrn_hsm" #define CLASS_NAME "acrn" +#define ACRN_API_VERSION_MAJOR 1 +#define ACRN_API_VERSION_MINOR 0 + static int acrn_hsm_inited; static int major; static struct class *acrn_class; @@ -44,6 +53,19 @@ long acrn_dev_ioctl(struct file *filep, { long ret = 0; + if (ioctl_num == IC_GET_API_VERSION) { + struct api_version api_version; + + api_version.major_version = ACRN_API_VERSION_MAJOR; + api_version.minor_version = ACRN_API_VERSION_MINOR; + + if (copy_to_user((void *)ioctl_param, &api_version, + sizeof(api_version))) + return -EFAULT; + + return 0; + } + return ret; } @@ -59,9 +81,12 @@ static const struct file_operations fops = { }; #define EAX_PRIVILEGE_VM BIT(0) +#define SUPPORT_HV_API_VERSION_MAJOR 1 +#define SUPPORT_HV_API_VERSION_MINOR 0 static int __init acrn_init(void) { + struct api_version *api_version; acrn_hsm_inited = 0; if (x86_hyper_type != X86_HYPER_ACRN) return -ENODEV; @@ -69,6 +94,28 @@ static int __init acrn_init(void) if (!(cpuid_eax(0x40000001) & EAX_PRIVILEGE_VM)) return -EPERM; + api_version = kmalloc(sizeof(*api_version), GFP_KERNEL); + if (!api_version) + return -ENOMEM; + + if (hcall_get_api_version(virt_to_phys(api_version)) < 0) { + pr_err("acrn: failed to get api version from Hypervisor !\n"); + kfree(api_version); + return -EINVAL; + } + + if (api_version->major_version >= SUPPORT_HV_API_VERSION_MAJOR && + api_version->minor_version >= SUPPORT_HV_API_VERSION_MINOR) { + pr_info("acrn: hv api version %d.%d\n", + api_version->major_version, api_version->minor_version); + kfree(api_version); + } else { + pr_err("acrn: not support hv api version %d.%d!\n", + api_version->major_version, api_version->minor_version); + kfree(api_version); + return -EINVAL; + } + /* Try to dynamically allocate a major number for the device */ major = register_chrdev(0, DEVICE_NAME, &fops); if (major < 0) { diff --git a/include/uapi/linux/acrn/acrn_ioctl_defs.h b/include/uapi/linux/acrn/acrn_ioctl_defs.h new file mode 100644 index 0000000..8dbf69a --- /dev/null +++ b/include/uapi/linux/acrn/acrn_ioctl_defs.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */ +/** + * @file acrn_ioctl_defs.h + * + * ACRN definition for ioctl to user space + */ + +#ifndef __ACRN_IOCTL_DEFS_H__ +#define __ACRN_IOCTL_DEFS_H__ + +/** + * struct api_version - data structure to track ACRN_SRV API version + * + * @major_version: major version of ACRN_SRV API + * @minor_version: minor version of ACRN_SRV API + */ +struct api_version { + uint32_t major_version; + uint32_t minor_version; +}; + +/* + * Common IOCTL ID definition for DM + */ +#define _IC_ID(x, y) (((x) << 24) | (y)) +#define IC_ID 0x43UL + +/* General */ +#define IC_ID_GEN_BASE 0x0UL +#define IC_GET_API_VERSION _IC_ID(IC_ID, IC_ID_GEN_BASE + 0x00) + +#endif /* __ACRN_IOCTL_DEFS_H__ */ -- 2.7.4