From patchwork Mon Jun 13 22:06:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 69949 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1759181qgf; Mon, 13 Jun 2016 15:22:45 -0700 (PDT) X-Received: by 10.36.19.16 with SMTP id 16mr22382555itz.76.1465856562965; Mon, 13 Jun 2016 15:22:42 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v76si34436908pfa.20.2016.06.13.15.22.42; Mon, 13 Jun 2016 15:22:42 -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; dkim=pass header.i=@amdcloud.onmicrosoft.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 S1423512AbcFMWWb (ORCPT + 30 others); Mon, 13 Jun 2016 18:22:31 -0400 Received: from mail-bn1on0061.outbound.protection.outlook.com ([157.56.110.61]:14821 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1422977AbcFMWW0 (ORCPT ); Mon, 13 Jun 2016 18:22:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=PvlvbwqEd7MIzfdzVGC7JYruy11fa5I1nGU/tdEavlQ=; b=aEkDBWuCQ3xpnB/eArMNmd/3iH6TwSf90fuMlaiH2ECWVECAyRD1dNSR6T2fhzP3vneKvGb57vea+FPmnpngEAReRtGAVbX9IHgzyrqneR2LNnTzG8oFAgHVwHIPQ9zjUr0BAXitCf0z2toPBF/CUWUl9oNy1yQ/o6cEXx2YE6U= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from ssuthiku-cz-dev.amd.com (165.204.77.1) by BLUPR12MB0434.namprd12.prod.outlook.com (10.162.92.14) with Microsoft SMTP Server (TLS) id 15.1.517.8; Mon, 13 Jun 2016 22:07:07 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit Subject: [PART2 RFC v2 08/10] svm: Introduce AMD IOMMU avic_ga_log_notifier Date: Mon, 13 Jun 2016 17:06:48 -0500 Message-ID: <1465855611-10092-9-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465855611-10092-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1465855611-10092-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR0701CA0005.namprd07.prod.outlook.com (10.162.96.15) To BLUPR12MB0434.namprd12.prod.outlook.com (10.162.92.14) X-MS-Office365-Filtering-Correlation-Id: 14d358a0-3983-4df8-bc1a-08d393d70f79 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 2:08YrVbLHqq2BDTVCYJPOxYd/sNmbE0nWVe9Ph74/xVVmTvA7q4KpOar4YZhVt7wzKJ1yKIth7mUn8dsTbYaOxPXz0JMEX2OLtt72/AbJWdp7XZfhR9chA9QuCvDP44QOC0rfzJi/yiajCP0JXQShZp2V/SajYNLMB0iXbeXC8a4862ga+2hkSUwiKoPpcygi; 3:GPUv2Ql7nF+n+OSUWDPbK2httZ4HRs1N32TPhvV/nFBxcPf/h2KrrGM0OeDk3OCQZEAoLQwi3UjBfE/1UIi2udsVUPcwv+eZCiQPnqzFBlBvAisJIDnJYwXtyARXGNgE X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0434; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 25:idaK/UEsFXvQ6IasmDFHGJR8riq+eUCDSDuNKdamdexr3cXPq/mX9mPVvApnYHRLcSxyHuAXVCdkYfQfch8Mfi51iTIK/jfnalSJtoFYFy2IBkAqriUt1HMauB29UqaSQ4GzqO/Eronri1HVMWsctRw+pBr8c9lkpgnGNloFMn5Hqu3dv+Dq+afuX85U/XrmwhWw5CoIYWVhoyNFqLh5qYtVc3rPv1yQEQ4v98WyyEFrHpwB4yYrurUR4gfCtqVL2KQiBS1zJ4mTYWHT268UhMB+HvStgFBjuiHkeasJ7nqZPO/xcvBZH4X5EDmPJamIHRM4Q2+LX8NWm17ubot2qyqDT6EbiscCQyaBlHeJNGKM2DpFEQG/5HoczYJaCqpkAO+oIHfcyXoiwJiqT7mul31rsm6PPaJMLtg8a3HJRXjQrscfmiNi5hh6o9k2OV0z2ztUMdixPDXQzuba9pNsB2t7Hsu45udFWw8KfBbpOsvzVhLi8I62MtpJxOgnAQsoBAtX3lty1WM1+Zqr2XwTBhVL6392pxG1l239mIfd1X98rubVFV58D/O9w8UB2ezQ1PJJlPIn2oz36EXcgt8zwTQkuTswsUl/R8BODIHx3J9I3VFAav8EtKA9fZwkdQHnV9+WsOtW6plnsyppWVqt+IZsGUfjdq76pD16p5INV31JqYr4sPwFV2KXjBvEnXDF8SvSst37e3FO5wAei5Eg+jtJkUyk5FhC9UDeOwEXoc5SJas4w3aUJ/ceSJhBggBG X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 20:O3T+5Ybf/CD/tpGhcM0gdpUp91RKB9obxv6HxiNhNB0m/6P8C1zwpKThQ6QgKvscVjYqylcHkgCrdW3usrrtZIymmvrl66Fk4eRnt7TeB+J+neVKewRqL5KRxeJrwHzub705NQW0HC/N3sWzzCf8LC1flDDt3kH17a3guWIadIczDlpZWEn51xSc1k8nr5xZcsdvnbNq+JFdUM+QfjsUX+BT8xsohp6FGCy76GVEiE3I9pEF1mSWl3jlZ3mXJvIyVZ4dD3w5xKKMbHHdYgLNlVGdaykKU4ntdJRZtrzHVV4FZ0J77Pj0+VKFqWj2Kxdc/6ttCwsuo0eL4wjm9A56XcmGUTsxGYVcFi7QTkP49i+5pGfYePXvukJ5Oy2W+dUAmTcj/QIvhLA16LqenmCgwvvO8JPakZpPsO67uvs4nlWi79YwSxMQkO29R+hUUbebaRzKfVmN5Wc0HttBI9XHGkNU3aCh3ZlttqtpwFvSp1c/n1ZaMNjqvq0L2sXe4pC4; 4:Rpiq6gklHnYKRPCK0pHpzI0W3WVtcPqAODGqPG5xzS1wzRsztQL6nXsIibBRHBbttdd7ctLPAn1YKgjPkfEJAgosSmHHiygQDfCVQLpgu8bEctJPC0oyjbXByXXV6tCXFRZm39dG8rLD+Fostyqr4ABscQNg8Qn3FiIixbRv7LBXIzYoW09lh43mzIUCZSWQ7RxxmmutKr4YmkcMIu6Bdt8eCbtwS9gLvPQeBWHyV450KbtdRZwgSU2TH58Tjnz1VjbOyddyRzl6++W2N9oDPypAywLzyvCBk0fabNaG97G0E1WAnV2zYX53B8ZHJa5iDuFao6nXRKJnci2SAlRXXDLL5YAiVcOHIuEPKSobLMXWSmfU4VTPbFBTHq+vsuYC5viP+sfxoZ/W6hqSNghxiDTTZ0cgh1XOgJH/ca2Xv8dVfvroYCcQq29zF1AmSzAa X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:BLUPR12MB0434; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0434; X-Forefront-PRVS: 0972DEC1D9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(53416004)(50226002)(5008740100001)(50466002)(36756003)(19580405001)(19580395003)(106356001)(189998001)(68736007)(105586002)(42186005)(2906002)(586003)(5001770100001)(101416001)(50986999)(4326007)(8676002)(81156014)(2950100001)(3846002)(6116002)(76176999)(77096005)(81166006)(97736004)(5003940100001)(5004730100002)(47776003)(86362001)(575784001)(48376002)(92566002)(229853001)(33646002)(2201001)(66066001)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0434; H:ssuthiku-cz-dev.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; CAT:NONE; LANG:en; CAT:NONE; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR12MB0434; 23:Tjjnq8lSTbGFw8Q5nWlfwJkeXIQ/DRVIIdCDTkxjR?= =?us-ascii?Q?sogKegzu9XpqwccvbE8HxcLjbUEbio8gvG08/P6m68QJJsFgUDnUz7+vV8dO?= =?us-ascii?Q?fK+Eb8MHpFWZPBEUEiyRk/wxJGV6GXmcO71xsvFY1schNaKKDGIkYekQAJm7?= =?us-ascii?Q?Y66QHT73d1gDhL878kgCFH2V46XJe6KM9oyTWMWSwlddKxRxpp6xAg5hWUH8?= =?us-ascii?Q?AI8KNEr/AKiv7ULt/xcDmidVAil+bpqkcLmRrTS79I8qYDMSMnh7rCDJ6neM?= =?us-ascii?Q?f9yd7onIR7h6vPoAePK8hiEYO3cyCzLMhJdx0hxatjSgv/oN35QD6STycURP?= =?us-ascii?Q?125MgOny3tPllo/6I9xAfUvUNCvUBeree+AMnhw1ammcTEILEdbVT/qBQ44D?= =?us-ascii?Q?zzd/sfILqBWXXdk1OxHvV7fLX57p4TLjKN/gPL803UMtiJxlnnOjlboxWY2y?= =?us-ascii?Q?eaPfbWWMkI+2VIpFJWYNJHrGQk1wy/eAWX2C8+CFgkinStSjE71+3c+5kKFf?= =?us-ascii?Q?BMvCU7CoZSbb7TjxIu74YJI9ONeLpqLznXT+C0+4HTNiOUHrCzWI3JEA5sT3?= =?us-ascii?Q?zJXUgS011KKfTjSBJsFx73LcM2kidlWqlvXN9bGA81BLFx6pkaYbLp74v3WT?= =?us-ascii?Q?uIYmwHe6ubFc6gustibLJCBAAcGnheT2u0o018NZbGUUd01iE039DyXfV60K?= =?us-ascii?Q?ZeaQLh9r320SX1J2j7lem+wYWmpkNacJEu0zwNGorDsfD7qDzorcJOfFPxZi?= =?us-ascii?Q?PhT+akUKdam4+E0flP/3VFKYdsTtqtWUXwaB8lrzhCRcZ5ivWbjDYr6OQPyY?= =?us-ascii?Q?XFK5bW0kcfuz27uFC4e1gNTGvnxlM7v27SBEx95JnKOk4l6K21B9UNcATHiX?= =?us-ascii?Q?s97mgdWevEQe4o2cah3aD2jFaXfop67F4o53vOVauuVNLS3+qGl/s4DjRnAS?= =?us-ascii?Q?2u/V8nECgO6wim9YFGmkSDlIVC9exim91XvDtDlV3skAFGXbml/qb2k32Mlu?= =?us-ascii?Q?sOuyS+VNRdgnatBKuABOBioj23g79VVb1o94chhXdTmjTUsUGdpZHRMDrDLD?= =?us-ascii?Q?OFu9Wze/qP7WhVfsNPhF3Fcm2iK3+Lnf9YTaq2kMOSAJxbXHFcaxhehP9yig?= =?us-ascii?Q?Vf7oA8ELRERx7kvUUaYAnhZP/Ksv3dD?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 6:ankFNU1gzeb2sfRoPeouIqvb626lH/NpKlsS+e9PxWibcu6arD26hsLwDUSaDCVCU3cugq0lYWvqEADYIP/KDamudcXYj2G4eepiiWlE0sD+MeVfLO+659dFX+DbCfJLkoAv4hQKlDbL63wYSi3H8x80cGh275rVf2qWf8B1PqjlKQiwuCRWoTgDTWINl+DNKjmzcADZLfwKscwWMUAOSWyKqbG2AYUpcNsuTu9UTTaZmhOvrYS6PY3tOlbXNH3H/JgKERQ16RobEX+raufodYn9xcJayhr3xgBczwX92zDoUyVLsmcwcA6WQqoei+H/; 5:07wHSqZYsB9MpG6taXS9b8e0lDF67oHtrWhebcgeb+6H/4G9+4c943G2MR277ViTsR3LYa9MM9gEEUJ5ysYXLaHhjSRJc2WZRwRnuQ4u9+gUyavY8c3xIHHf/E7s9N5DVK9R8I4hVWiK+yNuWTo8kw==; 24:vliPbFkva//YRi72R2xM9ZVqUYKn65Bdz6UWe8yNmjIRzNIhRSiZGQg7kurflxN9U8S7jeBXyjvmaWtBxX90C2OZCbTHJgHHjcpuUjtD4Kg=; 7:rJ2JFaho4xXGFQpnhvDvPN0y5tski6u/C6fqq4x6djLIQdxX39n9PonAHy4rJi2SyuOw/E1kjdppEtym6xUXNLS8GpxjpH3MR+BAMxe7rIzHPl8oZe2/89dChsA6LVw9x+GCWwnwJzgBw6EMrSHZEZU5bliC60i7uxEPNh2NwiV7NdvW6f0lYQ+WgzsaifqYWenI0kdHIspzyWfwvYtFCg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 20:xWeS1lYpVlG1ZG8OCVRcxp6FAcdXGBYPTwMZxjeeW6VBjf99h7W01+f7qE8YmohLnQXwaAZPfMpWZHD9M9jPnWdcSG5SBvHDzBDQVM5UyqkaiJiNMCHrFrPAJ9BYu/JOs61IMQ2KBLZ+73nNSXurA9Z1Mp1hOedBD0mF4DB/M2fbQ+RX28CZMAmcnJawveluy90voEefcQX84dj6wOpoKvg+dsnLwcS3NH3XWwoiJywxKb8jNcma3QVCku2Y5sGc X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2016 22:07:07.1103 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0434 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces avic_ga_log_notifier, which will be called by IOMMU driver whenever it handles the Guest vAPIC (GA) log entry. Signed-off-by: Suravee Suthikulpanit --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/svm.c | 58 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index e0fbe7e..a714cc2 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -775,9 +775,11 @@ struct kvm_arch { bool disabled_lapic_found; /* Struct members for AVIC */ + u32 avic_tag; u32 ldr_mode; struct page *avic_logical_id_table_page; struct page *avic_physical_id_table_page; + struct hlist_node hnode; }; struct kvm_vm_stat { diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 04707b7..a0aaaa6 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include @@ -926,6 +928,45 @@ static void svm_disable_lbrv(struct vcpu_svm *svm) set_msr_interception(msrpm, MSR_IA32_LASTINTTOIP, 0, 0); } +#define SVM_VM_DATA_HASH_BITS 8 +DECLARE_HASHTABLE(svm_vm_data_hash, SVM_VM_DATA_HASH_BITS); +static spinlock_t svm_vm_data_hash_lock; + +static int avic_ga_log_notifier(int avic_tag, int vcpu_id, int vec) +{ + unsigned long flags; + struct kvm_arch *ka = NULL; + struct kvm_vcpu *vcpu = NULL; + struct vcpu_svm *svm = NULL; + + pr_debug("SVM: %s: avic_tag=%#x, vcpu_id=%#x, vec=%#x\n", + __func__, avic_tag, vcpu_id, vec); + + spin_lock_irqsave(&svm_vm_data_hash_lock, flags); + hash_for_each_possible(svm_vm_data_hash, ka, hnode, avic_tag) { + struct kvm *kvm = container_of(ka, struct kvm, arch); + + vcpu = kvm_get_vcpu_by_id(kvm, vcpu_id); + break; + } + spin_unlock_irqrestore(&svm_vm_data_hash_lock, flags); + + if (!vcpu) + return 0; + + svm = to_svm(vcpu); + + /* Note: + * At this point, the IOMMU should have already set the pending + * bit in the vAPIC backing page. So, we just need to schedule + * in the vcpu. + */ + if (vcpu->mode == OUTSIDE_GUEST_MODE) + kvm_vcpu_wake_up(vcpu); + + return 0; +} + static __init int svm_hardware_setup(void) { int cpu; @@ -984,9 +1025,14 @@ static __init int svm_hardware_setup(void) if (avic && (!npt_enabled || !boot_cpu_has(X86_FEATURE_AVIC))) avic = false; - if (avic) + if (avic) { pr_info("AVIC enabled\n"); + hash_init(svm_vm_data_hash); + spin_lock_init(&svm_vm_data_hash_lock); + amd_iommu_register_ga_log_notifier(&avic_ga_log_notifier); + } + return 0; err: @@ -1277,16 +1323,22 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu) static void avic_vm_destroy(struct kvm *kvm) { + unsigned long flags; struct kvm_arch *vm_data = &kvm->arch; if (vm_data->avic_logical_id_table_page) __free_page(vm_data->avic_logical_id_table_page); if (vm_data->avic_physical_id_table_page) __free_page(vm_data->avic_physical_id_table_page); + + spin_lock_irqsave(&svm_vm_data_hash_lock, flags); + hash_del(&vm_data->hnode); + spin_unlock_irqrestore(&svm_vm_data_hash_lock, flags); } static int avic_vm_init(struct kvm *kvm) { + unsigned long flags; int err = -ENOMEM; struct kvm_arch *vm_data = &kvm->arch; struct page *p_page; @@ -1311,6 +1363,10 @@ static int avic_vm_init(struct kvm *kvm) vm_data->avic_logical_id_table_page = l_page; clear_page(page_address(l_page)); + spin_lock_irqsave(&svm_vm_data_hash_lock, flags); + hash_add(svm_vm_data_hash, &vm_data->hnode, vm_data->avic_tag); + spin_unlock_irqrestore(&svm_vm_data_hash_lock, flags); + return 0; free_avic: