From patchwork Wed Jul 13 13:20:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 71958 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1148600qga; Wed, 13 Jul 2016 11:44:16 -0700 (PDT) X-Received: by 10.98.14.208 with SMTP id 77mr5955858pfo.23.1468435456422; Wed, 13 Jul 2016 11:44:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hm6si1360709pac.254.2016.07.13.11.44.15; Wed, 13 Jul 2016 11:44:16 -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 S1752023AbcGMR74 (ORCPT + 30 others); Wed, 13 Jul 2016 13:59:56 -0400 Received: from mail-co1nam03on0070.outbound.protection.outlook.com ([104.47.40.70]:56538 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751462AbcGMR7r (ORCPT ); Wed, 13 Jul 2016 13:59:47 -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=OdpJtDnRO5W9Z4GVzN0nBJrMs4a0WRFg4+v1I0SJLSg=; b=A3ewuGnl7tHxcSigflLcZiNhWfq22BX8zTZu+gcCTmtdiwEsSFDrDDUuWkSEixRyEcQPFBIwBk4NexiaiA5R/M2bi4EoUucoVvya2AjEDhSEDg0LyJqe61usymJZcYxX4Ek6UUTqSmwv5vapoIghDZ+HbQLD/IliJ3s/ynrifeU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (114.109.128.54) by SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) with Microsoft SMTP Server (TLS) id 15.1.534.14; Wed, 13 Jul 2016 13:21:44 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit , Suravee Suthikulpanit Subject: [PART2 PATCH v4 10/11] svm: Introduce AMD IOMMU avic_ga_log_notifier Date: Wed, 13 Jul 2016 08:20:31 -0500 Message-ID: <1468416032-7692-11-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468416032-7692-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1468416032-7692-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [114.109.128.54] X-ClientProxiedBy: SIXPR04CA0024.apcprd04.prod.outlook.com (10.162.171.14) To SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) X-MS-Office365-Filtering-Correlation-Id: dc28d8da-4d3b-46d3-cccc-08d3ab20a72f X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 2:eKmukfuri2tJtPOkcPRwV8gm20G4060l2U2O3V5ZDYDv+S/a3wk6eFK+yaeyAPvptoK7geBpZe1l7xUWKBUJkKKxkTFMP2upTiWMinBmH6CpHQ7/nnxNU7ejWzWgGyOdjp2Zd95xHIdxNewH5SOtOcBpT8y/WGmYVcfbpZvvJF9RcLjv9XJI3DHXgbke/Ebl; 3:5QOStK/gCYqQZsNpzxLzOrKKCNcrEoq+qkLDhgy2UlFJzmHCAdf4HxcuiOIQEEUXLL3iiIJEuiEbCf5+Yx7TcgFp5/G47SIULzerndqzsEmMYra6PdpHjtc6lnecjXGW X-Microsoft-Antispam: UriScan:;BCL:0;PCL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yfkOHvYIUJBV2GrpdNvuD14DulZ0OGawnqxDsE5baA==; 20:wKsWL/YEcJPoKl0/C6AIpmG9k573eKl4aJEBVN2Crm+SRqp8z355Q3Ji8dRQeqTjku9N6h/FfGwTXXJyEXL62Jh5eFtBxpY8OOQqAjHkx4i15WzTkWGNdssoxHK7st0CwWCd7HZKbflVgPQ9/ruPkRK59nTfnroGca7pojKIGjFmn9h1YPPSH4EIFB+sf+2WgWl7Vgcs+X0e/+MEbisQl0ztvTLrQdTPJVWm3qZm2xpR8vMhYA8IR6YnCM7ZjaUKhaFfQFNfM1r5+kTe5NPDSpEXaKbIA4skNnMbZnhIFN46OBQ9gR07iaUVEzx+cSIJURe4NjtFlaLAZ1dOsen9xv5CEOQ/hMx/2ONkUKSMxEXrh1W9PLNBS1c9MY9iecHpXpe5HEVBS0G62L8T7Zzkv56dpYvvRWP+O9XPWVZDdFfTEBThnmCw0G69uuobutqpZJ7rn40VoMRi+V4aNqcLhsGUvRcptkdIcGFWr908+0h+C1/wU7lfL5mxX0O/NTH8 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)(10201501046)(3002001)(6055026); SRVR:SN1PR12MB0445; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0445; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 4:jHwjn3QkMdQkHyFv+vNgTeaUnv4iUlteASelqR4BWvlpwklzSScUDN3ZKleuKzhii6/ANRPulbbYjLTM8GoP7cSkxPaCCgn+HUzKn+6c03bIJj7zBs79LWPH+msglXF+OkA17AL9rQuY66chgtgGA6s68/H1iAkBEViNKvY0BQlf4MF/1dwdlhdL6W7WiD4iGt0xpib7BkTtP8QpD2ooJQCeW4LC0s82vPnmCU60nVVgXaNpDETtMXGNL4T8eY2amvtBdjmJWTKUe4ii/3T5AZgHrHng/ICVm09HZKKMVJpJk1oONjjIR37JYoceBZX8o+WR2E0HGKlNV1hxt73fqVnyQxezdlu4UTHkdOIwdBg9+/tRniE6UJkqAH/npVq9KYM2SMwn94doWhfpjmCbBocNZm6c2BxypNaIC0lEQ8c= X-Forefront-PRVS: 000227DA0C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(979002)(6069001)(6009001)(7916002)(189002)(199003)(229853001)(101416001)(77096005)(8676002)(6116002)(2950100001)(42186005)(586003)(81156014)(81166006)(2201001)(3846002)(50986999)(4326007)(76176999)(50466002)(36756003)(5003940100001)(68736007)(105586002)(305945005)(47776003)(66066001)(86362001)(7846002)(50226002)(2906002)(48376002)(92566002)(106356001)(19580405001)(7736002)(33646002)(97736004)(189998001)(5001770100001)(19580395003)(217873001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0445; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0445; 23:6BSx+NsM2QdTMxZzkq91yDO5oLZv8ygAvk5RkSfjw?= =?us-ascii?Q?voFW2GId0PAoiITLzJmK5nJWj7FSmRgmw8oivazovlLwFJjS0ChzfgEP4WUS?= =?us-ascii?Q?Ewg83xk55ZyhFc8fqKn6TJIb6E8SkMhI4xb27VINogTf1YX1tvOPNHYBLZY9?= =?us-ascii?Q?9dNKVejrphGi9WjdHWawOtUq3TdbQ+FHmziUjoyknXGHJ7wZQCL5ZWwTSuM1?= =?us-ascii?Q?1hhb26Lvnlo4B39hFAoqGneRNR4OvsEYdCmxHqewAgwed8pjMhg991xSjdFI?= =?us-ascii?Q?E1000oS24ErGT7TVt7tB9pPlnunpyA6U2QugCEpuDEk1N/us9vSR3hSjnocA?= =?us-ascii?Q?XbwEqlOl7EpBH1hPtS+iyH3GJ2iMQumlP09vFRDoCI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zKuSSz4hC4+aXesLM0Nbbi+sFbHO/zgtczWOAp6DZXnvWatQsXpXuYmx5y+lckCbFVQv6NKSY2RymHmtPW4Lnv7ozc99TRnTX2+XH4JBTF/n X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2016 13:21:44.4172 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0445 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit 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 | 68 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 69e62862..a9466ad 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -776,9 +776,11 @@ struct kvm_arch { bool disabled_lapic_found; /* Struct members for AVIC */ + u32 avic_vm_id; 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 16ef31b..1d9f2f6 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include @@ -928,6 +930,53 @@ static void svm_disable_lbrv(struct vcpu_svm *svm) set_msr_interception(msrpm, MSR_IA32_LASTINTTOIP, 0, 0); } +/* Note: + * This hash table is used to map VM_ID to a struct kvm_arch, + * when handling AMD IOMMU GALOG notification to schedule in + * a particular vCPU. + */ +#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; + +/* Note: + * This function is called from IOMMU driver to notify + * SVM to schedule in a particular vCPU of a particular VM. + */ +static int avic_ga_log_notifier(int vm_id, int vcpu_id) +{ + unsigned long flags; + struct kvm_arch *ka = NULL; + struct kvm_vcpu *vcpu = NULL; + struct vcpu_svm *svm = NULL; + + pr_debug("SVM: %s: vm_id=%#x, vcpu_id=%#x\n", __func__, vm_id, vcpu_id); + + spin_lock_irqsave(&svm_vm_data_hash_lock, flags); + hash_for_each_possible(svm_vm_data_hash, ka, hnode, vm_id) { + 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; @@ -986,10 +1035,15 @@ static __init int svm_hardware_setup(void) if (avic) { if (!npt_enabled || !boot_cpu_has(X86_FEATURE_AVIC) || - !IS_ENABLED(CONFIG_X86_LOCAL_APIC)) + !IS_ENABLED(CONFIG_X86_LOCAL_APIC)) { avic = false; - else + } else { 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; @@ -1282,16 +1336,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; @@ -1316,6 +1376,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_vm_id); + spin_unlock_irqrestore(&svm_vm_data_hash_lock, flags); + return 0; free_avic: