From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DD64C433E1 for ; Tue, 25 Aug 2020 02:51:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 132782072D for ; Tue, 25 Aug 2020 02:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728532AbgHYCvj (ORCPT ); Mon, 24 Aug 2020 22:51:39 -0400 Received: from mga18.intel.com ([134.134.136.126]:37761 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728523AbgHYCvg (ORCPT ); Mon, 24 Aug 2020 22:51:36 -0400 IronPort-SDR: CtBn19lOj+n++kyumNlnMmXpAUmQ+SpBrwjD4DdUd954+S6uVWGFEss/jqpUmnN/0qLvBpLcZW 5UHKdgN2zUng== X-IronPort-AV: E=McAfee;i="6000,8403,9723"; a="143690861" X-IronPort-AV: E=Sophos;i="5.76,350,1592895600"; d="scan'208";a="143690861" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2020 19:51:35 -0700 IronPort-SDR: ciVVabXF0bQq7erfIZjbfFM8lY1Ct+AQ1llv7yRbzKRd7btxkNERBQHB6mFSg4aF9hU2l+6G/E ECCW/rkgnyDQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,350,1592895600"; d="scan'208";a="312409898" Received: from shsi6026.sh.intel.com ([10.239.147.135]) by orsmga002.jf.intel.com with ESMTP; 24 Aug 2020 19:51:32 -0700 From: shuo.a.liu@intel.com To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Sean Christopherson , Yu Wang , Reinette Chatre , x86@kernel.org, Shuo Liu , Zhi Wang , Zhenyu Wang Subject: [PATCH 17/17] virt: acrn: Introduce an interface for Service VM to control vCPU Date: Tue, 25 Aug 2020 10:45:17 +0800 Message-Id: <20200825024516.16766-18-shuo.a.liu@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200825024516.16766-1-shuo.a.liu@intel.com> References: <20200825024516.16766-1-shuo.a.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shuo Liu ACRN supports partition mode to achieve real-time requirements. In partition mode, a CPU core can be dedicated to a vCPU of User VM. The local APIC of the dedicated CPU core can be passthrough to the User VM. The Service VM controls the assignment of the CPU cores. Introduce an interface for the Service VM to remove the control of CPU core from hypervisor perspective so that the CPU core can be a dedicated CPU core of User VM. 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 --- drivers/virt/acrn/hsm.c | 49 +++++++++++++++++++++++++++++++++++ drivers/virt/acrn/hypercall.h | 12 +++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c index 81300ea19dc9..b1e87684701c 100644 --- a/drivers/virt/acrn/hsm.c +++ b/drivers/virt/acrn/hsm.c @@ -11,6 +11,7 @@ #define pr_fmt(fmt) "acrn: " fmt +#include #include #include #include @@ -348,6 +349,47 @@ static struct miscdevice acrn_dev = { .fops = &acrn_fops, }; +static ssize_t remove_cpu_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u64 cpu, lapicid; + int ret; + + if (kstrtoull(buf, 0, &cpu) < 0) + return -EINVAL; + + if (cpu >= num_possible_cpus() || cpu == 0 || !cpu_is_hotpluggable(cpu)) + return -EINVAL; + + if (cpu_online(cpu)) + remove_cpu(cpu); + + lapicid = cpu_data(cpu).apicid; + pr_debug("Try to remove cpu %lld with lapicid %lld\n", cpu, lapicid); + ret = hcall_sos_remove_cpu(lapicid); + if (ret < 0) { + pr_err("Failed to remove cpu %lld!\n", cpu); + goto fail_remove; + } + + return count; + +fail_remove: + add_cpu(cpu); + return ret; +} +static DEVICE_ATTR_WO(remove_cpu); + +static struct attribute *acrn_attrs[] = { + &dev_attr_remove_cpu.attr, + NULL +}; + +static struct attribute_group acrn_attr_group = { + .attrs = acrn_attrs, +}; + static int __init hsm_init(void) { int ret; @@ -373,13 +415,20 @@ static int __init hsm_init(void) return ret; } + if (sysfs_create_group(&acrn_dev.this_device->kobj, &acrn_attr_group)) { + pr_warn("sysfs create failed\n"); + misc_deregister(&acrn_dev); + return -EINVAL; + } acrn_ioreq_intr_setup(); + return 0; } static void __exit hsm_exit(void) { acrn_ioreq_intr_remove(); + sysfs_remove_group(&acrn_dev.this_device->kobj, &acrn_attr_group); misc_deregister(&acrn_dev); } module_init(hsm_init); diff --git a/drivers/virt/acrn/hypercall.h b/drivers/virt/acrn/hypercall.h index ce8fdca76394..04121223ff8d 100644 --- a/drivers/virt/acrn/hypercall.h +++ b/drivers/virt/acrn/hypercall.h @@ -15,6 +15,7 @@ #define HC_ID_GEN_BASE 0x0UL #define HC_GET_API_VERSION _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x00) +#define HC_SOS_REMOVE_CPU _HC_ID(HC_ID, HC_ID_GEN_BASE + 0x01) #define HC_ID_VM_BASE 0x10UL #define HC_CREATE_VM _HC_ID(HC_ID, HC_ID_VM_BASE + 0x00) @@ -56,6 +57,17 @@ static inline long hcall_get_api_version(u64 api_version) return acrn_hypercall1(HC_GET_API_VERSION, api_version); } +/** + * hcall_sos_remove_cpu() - Remove a vCPU of Service VM + * @cpu: The vCPU to be removed + * + * Return: 0 on success, <0 on failure + */ +static inline long hcall_sos_remove_cpu(u64 cpu) +{ + return acrn_hypercall1(HC_SOS_REMOVE_CPU, cpu); +} + /** * hcall_create_vm() - Create a User VM * @vminfo: Service VM GPA of info of User VM creation -- 2.28.0