Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2592365pxa; Mon, 24 Aug 2020 19:56:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGhlWwDah+3EMAlAx+D9sV8vjkc7GLhyPuvNHxoKU26ULi4GO71Zu7cI6ZvHphbHEH2nIU X-Received: by 2002:a17:906:37d3:: with SMTP id o19mr8002986ejc.62.1598324170679; Mon, 24 Aug 2020 19:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598324170; cv=none; d=google.com; s=arc-20160816; b=bPTmPUxK1IOZuenZhk5UYDbRnaEgMnDiRZnLQuBp3NPYx2t2MWv9dId8ld/m7ICyS7 gGe+7RCeMdUv7wA+NHxIAhfCjLmkRN98EE2Aw8C7+vSv+n4RjC+WmQo4R6gY/SmEs5zS NE9EeB2A9Xduz92cCtU5Mz2qze59aFT3+HvLSSgCiReEMbKyhVk/qs2fvBkea7KyoEez OgZ2Nq3bpNBj5W+VGVW+CisHRjaCnXzHjeVOCtvhumgbzQoYMLip3F0YqjxKiyvOPcrc 6Aev9hFOyCrtFahses3MoLOxcfEntvnx7dhe1JfiLZwgpDX0bPd3/u0SJz3bpXPwzIIt aNeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=ctmcDnJa2Ewg2eqDrDFWUPZOIduGlaueJqgUDVrAlts=; b=saYJITWw9x2KoczRBKX9dVkmX13Wyd3iZDq4/HhgvZkmQqre6f+7Cya2m/yo9L3ZZM Rd3PlRLegbQtvPCui093nalz22WzY7fONkwnNSxsUd3cEpzXrYEyG0hK3rZT+NCkqCfQ U7jzQyzNB22Gst/ToAC4fmrEMVPld8V/9QlgKbVasxWQNYPMdK/XX+D2hdnE+yU07ZXB 67xW606/i+hX/JzEknazB9mYwLwpdCOfSuRCmYq5fId4ZZiOUIErF4UMeyEcDI+1xRZV PkKhO0ZB8L3KctCCBP366QOrI1tGVMUfdKMA9rCIbLpre2fW3u7EH5EMYX6PlPrcfsuM 8zQA== ARC-Authentication-Results: i=1; mx.google.com; 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h24si3715401edq.394.2020.08.24.19.55.47; Mon, 24 Aug 2020 19:56:10 -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; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728528AbgHYCvi (ORCPT + 99 others); Mon, 24 Aug 2020 22:51:38 -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