From patchwork Fri Feb 12 13:59:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 61850 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp840478lbl; Fri, 12 Feb 2016 06:01:31 -0800 (PST) X-Received: by 10.98.34.209 with SMTP id p78mr2364392pfj.154.1455285691773; Fri, 12 Feb 2016 06:01:31 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si20211935pfn.180.2016.02.12.06.01.31; Fri, 12 Feb 2016 06:01:31 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752975AbcBLOB3 (ORCPT + 30 others); Fri, 12 Feb 2016 09:01:29 -0500 Received: from mail-bn1bon0085.outbound.protection.outlook.com ([157.56.111.85]:4256 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752834AbcBLOBY (ORCPT ); Fri, 12 Feb 2016 09:01:24 -0500 Authentication-Results: 8bytes.org; dkim=none (message not signed) header.d=none; 8bytes.org; dmarc=none action=none header.from=amd.com; Received: from localhost.localdomain (124.121.8.20) by BY1PR12MB0440.namprd12.prod.outlook.com (10.162.147.141) with Microsoft SMTP Server (TLS) id 15.1.403.16; Fri, 12 Feb 2016 14:01:13 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , , Suravee Suthikulpanit , Suravee Suthikulpanit Subject: [PART1 RFC 9/9] svm: Manage vcpu load/unload when enable AVIC Date: Fri, 12 Feb 2016 20:59:34 +0700 Message-ID: <1455285574-27892-10-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455285574-27892-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1455285574-27892-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: SG2PR03CA0036.apcprd03.prod.outlook.com (25.160.233.46) To BY1PR12MB0440.namprd12.prod.outlook.com (25.162.147.141) X-MS-Office365-Filtering-Correlation-Id: b321ec9a-b9c0-47fe-3163-08d333b4fc8d X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0440; 2:dyq0WEs/KXOkhQkJeeVs3nuZV3wg5oAATAQ0CZ2zPi7vsrMaPIUIkOg6Ed7Z+jR3MHUpJislFEb6U2rM5UTprR6773IPh9yZ03IPuYfA4zyZErT7vKni+BrPfjgCEShHSd7dRZsbtkL2NMiBGCENaA3Gav88mZiNr1umoRVmgG/x9kDPstVBU0EEe9gt8rk2; 3:/i7qaCtjQ5P+rtwMlXZJjugX6bY7FH9i7hHZB5kBzcPHx3GY1eDcLl41gvXv/NK2nHvdC/W7tTdCN7UNQ26nMD+Vgx3CFIUU5uxc7NZsuwsiyx10gK04aYYyv5CIpjlR; 25:NOqUI0y2RIWoVdIdN9zshMx2/t6H3sVysbh2hyGkregqM8HKWzDUJpA1/v5ViqT1WCvSGXM9hg9Utee++zkHjr6w2yW1l8gB8rzHSCtNwJ+eCAzhGH7bgiXza+Q420W3OA2/AMHjrpWEYqh8NEA2Yp7ugmT6wpE6avUsjUF91i9EFaQPcq4Baaa5zBJ5lqn+FR/hKrxht0uBociczDI9um5N4GOncA0ZStfKEnZxNqPMRJTGwyn51xxagMi+gl5afNzIoqzC7uFf+JqbYVeIgvUMwiMb0HAyFnz6cRIxLYlKNarUJGXPcTrqSnvQrv/U X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR12MB0440; X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0440; 20:lofp/Mg/EOSpfFXo2fyDLtWNF1SLRAeT3STaCkr3by2zIejmzD1ecFQdP9zm7nu9AfLoMriYxbKOxlFDfnzqW8ZQu3P62PXg+mLnM54QOyr/7KmiHSDAcIzh6fTjXPyS0AtsyoYcwbM9ZoJ8PtDtnQI8qBPjuLYtzzIzNaPOI/3u9QJAXI1oTeNavGa+A3I71JzrefmzU7eo9GKH02rHCcmyDZBWp/sCgsZYNsl4IbkamIqyBqyd95lqmHNwwYdIsxtPbrqM2ossXa1dvonWK7yMjNF0vyqWY6d3XdiZfd0WH3W4CiefH9N5eWNdkzTpcQ0oSPejYx2J/dCriS3/5bVizMV5IuTQVfmhpelCibDqvDat5jL8RN1tJ/9Pan0CjZY+E+4BTEcBjY1JxaNFz8ar1erJlbnT61yAEnWxZSH459jcz2xUErznNKU3gxaRvHtM/inwTXo8+5IiB4RkMDCDrhSV3d62iqDDVVkyKrr53Z3qh84FIZ5aTIjO1PMX; 4:bnncMoXmn/MUUQHj9NRTeD2aVbsT3wvYXxAmAsjCukwlDL4KOgYYc6ueLLEz80P47NiS/vnzVnTypscl3ZRvvHqn1kSudyFNiuPyqWpRrv1Ppl4XfDqkhjMHRlLfL97IMUrktOmTBABBUYk7EILt0fqopVZfj8OoCi5lw3H19oagNeSZyRjxyP1l4B4bj94l95fLhD2fm37C1AeSTQsPciszqQP28WjoQj0PvRcfGicIwmD8A7LFNJD3VI21pSzK+vi5acaH5vZ+2cArduhodXZhsQZa5gbYgB1ewdg+4aj8AzD8S1W1B7lJFeP8/5aIEdXnLe8Y9UD/i1GRcYP99XEjP84ek6chXl2HX4EstaKMN+DNyX1WsZblRwkYiROUJQ1QgeOa/tYrJEf0semYXg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BY1PR12MB0440; BCL:0; PCL:0; RULEID:; SRVR:BY1PR12MB0440; X-Forefront-PRVS: 0850800A29 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(6069001)(2201001)(36756003)(48376002)(586003)(40100003)(92566002)(3846002)(5003940100001)(77096005)(229853001)(2950100001)(19580395003)(19580405001)(6116002)(5004730100002)(189998001)(4326007)(42186005)(66066001)(50226001)(87976001)(5008740100001)(5001770100001)(122386002)(33646002)(50466002)(76176999)(50986999)(86362001)(5001960100002)(47776003)(1096002)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR12MB0440; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR12MB0440; 23:/Bjif2r+L+LEu+hZmw4oETv7FnH4NXUFi/1bHO02M?= =?us-ascii?Q?4zvucm/cWooSJBVSw+752vQOfYKdY6WCgPF3lHFca8cadmBRn1OdebBlTMhE?= =?us-ascii?Q?mkjVnv2uPuy55NUPz+qVwfJzmAyQOiRDmRT+asXOEezbyNpPiw+T5sOCwHep?= =?us-ascii?Q?kVBBj9kuSKm8ecVjPrPUQUGsl5sh7hCniKMg1u3wqBd3qbKZYgf1YeXFlJ19?= =?us-ascii?Q?mu3lGW8rqPtigkdwEX1RURSFl+6rvyE7E4BI+kR2rtPPOe1n9o/uSV57bvzO?= =?us-ascii?Q?gmIizSYYe3Dag0YMx9izNkJLhoDzrkYzzeITyWup02AD4z/JjoMkmhLFa38c?= =?us-ascii?Q?SJ/0NTQY7UA2iu8PmImUkbP6xLJGEuVVk+NWhsLHnqjK0/ESQ8hEt+bR1p3X?= =?us-ascii?Q?VXafYe7JLlGw8XLt5quoB/A1gYudU8wFG7fVR+zj/B8E2r4F1oFAelelDi7r?= =?us-ascii?Q?1r+EbLW/jEQ0K8lomUxIuPiyi7u28I4QHkCILsB+St1Dc/tabn2wI+15NHyr?= =?us-ascii?Q?0N3lA1tiX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9Qvz2hYxLmAUShc2dc0ejsrztYZYh2mMrP00cJuWEYhUE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2016 14:01:13.4079 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR12MB0440 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a vcpu is loaded/unloaded to a physical core, we need to update information in the Physical APIC-ID table accordingly. Signed-off-by: Suravee Suthikulpanit --- arch/x86/kvm/svm.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) -- 1.9.1 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 32da657..41e68d2 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -1508,6 +1509,61 @@ static int avic_vcpu_init(struct kvm *kvm, struct vcpu_svm *svm, int id) return 0; } +static inline int avic_update_iommu(struct kvm_vcpu *vcpu, int cpu, + phys_addr_t pa, bool is_running) +{ + if (!kvm_arch_has_assigned_device(vcpu->kvm)) + return 0; + + /* TODO: We will hook up with IOMMU API at later time */ + return 0; +} + +static int avic_set_running(struct kvm_vcpu *vcpu, int cpu, bool is_running) +{ + int g_phy_apic_id, h_phy_apic_id; + struct svm_avic_phy_ait_entry *entry; + struct vcpu_svm *svm = to_svm(vcpu); + int ret; + + if (!avic) + return 0; + + if (!svm) + return -EINVAL; + + /* Note: APIC ID = 0xff is used for broadcast. + * APIC ID > 0xff is reserved. + */ + g_phy_apic_id = vcpu->vcpu_id; + h_phy_apic_id = __default_cpu_present_to_apicid(cpu); + + if ((g_phy_apic_id >= AVIC_PHY_APIC_ID_MAX) || + (h_phy_apic_id >= AVIC_PHY_APIC_ID_MAX)) + return -EINVAL; + + entry = avic_get_phy_ait_entry(vcpu, g_phy_apic_id); + if (!entry) + return -EINVAL; + + if (is_running) { + phys_addr_t pa = PFN_PHYS(page_to_pfn(svm->avic_bk_page)); + + entry->bk_pg_ptr = (pa >> 12) & 0xffffffffff; + entry->valid = 1; + entry->host_phy_apic_id = h_phy_apic_id; + barrier(); + entry->is_running = is_running; + ret = avic_update_iommu(vcpu, h_phy_apic_id, pa, is_running); + } else { + ret = avic_update_iommu(vcpu, 0, 0, is_running); + barrier(); + entry->is_running = is_running; + } + + return ret; +} + static void svm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) { struct vcpu_svm *svm = to_svm(vcpu); @@ -1628,6 +1684,8 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu) mark_all_dirty(svm->vmcb); } + avic_set_running(vcpu, cpu, true); + #ifdef CONFIG_X86_64 rdmsrl(MSR_GS_BASE, to_svm(vcpu)->host.gs_base); #endif @@ -1668,6 +1726,9 @@ static void svm_vcpu_put(struct kvm_vcpu *vcpu) #endif for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++) wrmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]); + + avic_set_running(vcpu, 0, false); + } static unsigned long svm_get_rflags(struct kvm_vcpu *vcpu)