From patchwork Fri Mar 18 06:09:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 64016 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp869594lbc; Thu, 17 Mar 2016 23:11:32 -0700 (PDT) X-Received: by 10.98.87.216 with SMTP id i85mr6587103pfj.61.1458281492554; Thu, 17 Mar 2016 23:11:32 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ze7si6900663pac.34.2016.03.17.23.11.32; Thu, 17 Mar 2016 23:11:32 -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; dkim=pass header.i=@amdcloud.onmicrosoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752212AbcCRGLN (ORCPT + 30 others); Fri, 18 Mar 2016 02:11:13 -0400 Received: from mail-bn1on0058.outbound.protection.outlook.com ([157.56.110.58]:33350 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756837AbcCRGKq (ORCPT ); Fri, 18 Mar 2016 02:10:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=648Q3FLjCeuxIe+SS9lMU52QLJY7SwZL5EWFjvfHdrk=; b=eWXmFTHVjnPE6ApN+MLLeRTK0HYfEaDkYOGtHX5I17U5MsCj2pBj5wKTNN60rYeNuq8Rc3Dxs6zCJdz8vKC7FPgwA47ke7dIiaIheRrlJG7iM+a5kSq4uhxjT/LxGVhgV0oHnOhYJdTw61ryGGHGqwKbEbCr2oiZX9CSfDG2P5g= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=amd.com; Received: from localhost.localdomain (124.121.8.20) by BY1PR12MB0437.namprd12.prod.outlook.com (10.162.147.139) with Microsoft SMTP Server (TLS) id 15.1.443.12; Fri, 18 Mar 2016 06:10:33 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit , Suravee Suthikulpanit Subject: [PART1 RFC v3 02/12] KVM: x86: Introducing kvm_x86_ops VM init/uninit hooks Date: Fri, 18 Mar 2016 01:09:38 -0500 Message-ID: <1458281388-14452-3-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458281388-14452-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1458281388-14452-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: SG2PR04CA0047.apcprd04.prod.outlook.com (25.169.49.143) To BY1PR12MB0437.namprd12.prod.outlook.com (25.162.147.139) X-MS-Office365-Filtering-Correlation-Id: c70115d8-accc-4695-913b-08d34ef40917 X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0437; 2:Y8sHvvt+WuYgZNvMazuI9wneFlARSn9nEtoaJSxZjTcjFhrkde8cMtrQlQrNZErZxdtiCNXUkhc338bF3y7cmAEIij5EqgVKhrFPSSamusUzffk2BI3j2eY7hFhuD3hSgLdqRvNwKtLVr6mz8Y8uH6VldPBm5ZxgFsM6Gx6bjyfdcewaJCdktMxkpcaTKHj2; 3:QA3Riqi3M+EYn9og5ALNPZ8rz2MCP24B6cHnGUsBrO7aDqgQLsBexRMY/bSunhtxPpd1PGeMUeN0OtAy2KxV73Rif941PNWd4kXYx/Xmkje00ZXeZ5q4w726qsr0KO8P; 25:swBrBQG3rmK9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OE747zkI+i6bU5CuJm7qzxoqjjYTgyHmyZKdHIv1E0dL3iO83OFzt3p5luYmnD; 4:8kJO+cE4z0kYD62xV9eCzC5OIX2FI90kau+U51+4NM2hD4OuAU/wTl7FbUd8zF339KU3ZTX0PtEDrGniuR9u9lbOArijCLzi9dD5vDjUbhWoDV/2v1wzB7vJInljcNjp0Wg0BXGYHIh4+KgVrnKA8VK1z18jsj6OnSOHHL0VZGESZwvFuPHAC8/zVCbISBSXyejdmWZCxQCChdLSAtdjAqcmxTWCYbmfQwdqQoIkMZ1zLX0rdcBPvC2BikJDkiQT0WoxU46LWIMRS2McubtaymGZotZ4vOXCLyZD9PitDk5OGQ8gHtKcJ3dSYk1OPI3y8Q0x0LGS4tT8slVo4iVS4nUBIRRJdj5vBPQpjJh1Qjvi38zC7Lz3URCLsGrxcKXt X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:BY1PR12MB0437; BCL:0; PCL:0; RULEID:; SRVR:BY1PR12MB0437; X-Forefront-PRVS: 088552DE73 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(5890100001)(189998001)(66066001)(19580395003)(19580405001)(47776003)(42186005)(3846002)(5001770100001)(50226001)(6116002)(2201001)(86362001)(575784001)(586003)(229853001)(2950100001)(36756003)(5004730100002)(77096005)(81166005)(5003940100001)(4326007)(50466002)(92566002)(48376002)(5008740100001)(76176999)(50986999); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR12MB0437; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0437; 23:T1MBoir/vF0dhLS8FUdemk2FRB76PdqhyZaQFitd8d5Yn0bLK3AD1gArfTXw2vMijBdGgDVu5Oaa4rVxCgFgTDiPXSLBI387s8rfUfRxq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U+fuaz/eKMLulf8Ed75YtgfPMm00fKsgxag=; 20:3FXqO4tPfdow+YRlTGo94R6EIHyTmRkVbs/9sN6RwB5bohtPC5y12f8gF7xGOleL4beE6ByTYz9sJ682BURjIuCXxJUL5jGEJbuQzD/WmWwyL8QBEgdUtz1iTWqHCkxoEsanliRUyEhsDvYwA3ULPSDPI+oIaXmUxuD+YHXLAbE7cFtkDPqivnBA+ebaU+14JYvHHhn8MX0XzQebZtCBIwjFzBpIny5LqqqWu2z4gVwok7NSDSNk+Yp5DFdxfS8w X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2016 06:10:33.9177 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR12MB0437 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding function pointers in struct kvm_x86_ops for processor-specific layer to provide hooks for when KVM initialize and un-initialize VM. Signed-off-by: Suravee Suthikulpanit --- arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/kvm/x86.c | 10 +++++++++- virt/kvm/kvm_main.c | 8 ++++---- 3 files changed, 16 insertions(+), 5 deletions(-) -- 1.9.1 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 44adbb8..4b0dd0f 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -828,6 +828,9 @@ struct kvm_x86_ops { bool (*cpu_has_high_real_mode_segbase)(void); void (*cpuid_update)(struct kvm_vcpu *vcpu); + int (*vm_init)(struct kvm *kvm); + void (*vm_uninit)(struct kvm *kvm); + /* Create, but do not attach this VCPU */ struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id); void (*vcpu_free)(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 429c3f5..4d2961d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7700,6 +7700,8 @@ void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) { + int ret = 0; + if (type) return -EINVAL; @@ -7724,7 +7726,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) INIT_DELAYED_WORK(&kvm->arch.kvmclock_update_work, kvmclock_update_fn); INIT_DELAYED_WORK(&kvm->arch.kvmclock_sync_work, kvmclock_sync_fn); - return 0; + if (kvm_x86_ops->vm_init) + ret = kvm_x86_ops->vm_init(kvm); + + return ret; } static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu) @@ -7751,6 +7756,9 @@ static void kvm_free_vcpus(struct kvm *kvm) kvm_for_each_vcpu(i, vcpu, kvm) kvm_arch_vcpu_free(vcpu); + if (kvm_x86_ops->vm_uninit) + kvm_x86_ops->vm_uninit(kvm); + mutex_lock(&kvm->lock); for (i = 0; i < atomic_read(&kvm->online_vcpus); i++) kvm->vcpus[i] = NULL; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 1ca0258..5460325 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -536,10 +536,6 @@ static struct kvm *kvm_create_vm(unsigned long type) if (!kvm) return ERR_PTR(-ENOMEM); - r = kvm_arch_init_vm(kvm, type); - if (r) - goto out_err_no_disable; - r = hardware_enable_all(); if (r) goto out_err_no_disable; @@ -578,6 +574,10 @@ static struct kvm *kvm_create_vm(unsigned long type) atomic_set(&kvm->users_count, 1); INIT_LIST_HEAD(&kvm->devices); + r = kvm_arch_init_vm(kvm, type); + if (r) + goto out_err; + r = kvm_init_mmu_notifier(kvm); if (r) goto out_err;