From patchwork Mon Jul 11 10:11: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: 71720 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp528093qga; Mon, 11 Jul 2016 03:13:34 -0700 (PDT) X-Received: by 10.66.43.234 with SMTP id z10mr23660635pal.137.1468232014422; Mon, 11 Jul 2016 03:13:34 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a25si1105321pfg.33.2016.07.11.03.13.33; Mon, 11 Jul 2016 03:13:34 -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 S1030351AbcGKKNS (ORCPT + 30 others); Mon, 11 Jul 2016 06:13:18 -0400 Received: from mail-dm3nam03on0078.outbound.protection.outlook.com ([104.47.41.78]:3016 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753461AbcGKKNN (ORCPT ); Mon, 11 Jul 2016 06:13:13 -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=XuWIru9pUbLBz8n6QLJQ6oSohJQvt7Lew4+LZ8Gc7TE=; b=0X82vjK0N8SnGH97kAGgLgWMJ/+qpg6gsaEkqTzLy8MR1EEgiF6UN14nfNRduwnBFQxzROK1y1ixEMnxeRwmJ+ILSKvh+FVb6/qYFEq1jRjIURIhe8KZn/akJlYR3Vjl/AIlyLrKJfoUngLoBZ4MDSeyhNQoc/W0BgGr5AxrkRA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from localhost.localdomain (124.121.8.20) by CY1PR12MB0444.namprd12.prod.outlook.com (10.163.91.22) with Microsoft SMTP Server (TLS) id 15.1.534.14; Mon, 11 Jul 2016 10:12:57 +0000 From: Suravee Suthikulpanit To: , , , CC: , , , Suravee Suthikulpanit , Suravee Suthikulpanit Subject: [PART2 PATCH v3 10/11] svm: Introduce AMD IOMMU avic_ga_log_notifier Date: Mon, 11 Jul 2016 05:11:38 -0500 Message-ID: <1468231899-6987-11-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468231899-6987-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1468231899-6987-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: SG2PR03CA0026.apcprd03.prod.outlook.com (10.160.233.36) To CY1PR12MB0444.namprd12.prod.outlook.com (10.163.91.22) X-MS-Office365-Filtering-Correlation-Id: 0e50c19c-0897-4720-dfe5-08d3a973f319 X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 2:R04DdeKcgRczlP/e73RH56Ase282VSwQggZEPOBeLR+orOZ73vKWxgh3C/IYjWPGl6IQv4iR4LqaTDazrv7FdYf2SaFRpGm7TBMKap1RdQUW/lc1etNz3RN7P+mdSDMKAxasZgcWPDoAyPN4gT+Jb8YcDDiGmmcxGfw8GArEVKjudgJGwdfU5IDzVX+UA0K+; 3:RfnJjFSURQ73DaJnvqFtaapnJQXOhKyJC4h10XhQ/LbZ9GjbT+85854R7b1urnWjNz4xOZd2XXSq5q8zXgSZthI5cWmdThNPq00IpJzLCTYPVjY1gCUiU6MC9QPpYk6O X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;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Sud8vS09JC80xqk1T+1GIbomxzBvckI1yxcmpEOAeOCV/0+uwbUMUkQ==; 20:M8YeTQqUKwPBO4zXIKQFAurxLNZWMCOCzMKtp/U7AXQns2rOk09YK+iJN0SSvy7q93LMuDZi/QilrNo5YDizZlsrG6Caz52PwqfpAUyQE2R0qhkd+VLM88sLRlYHOYncKcroRyqWZxpbU1QX/y0O9YHxI7y/tZwgt69hDYbCyshAdhoNb16GgKWvgL0R3OvlK26WsGTHzdZHAxK2dEVKN9DIyymm/hS29sAvUPCQnmivuEKgE+emPT4VT5boxqFgNgFHA7PTyEdwBqvGxbldQlZkZZXi8I/HvKB/fIIWoW56hDCeAnqqwm5Phgeid3zjSqxEfCjHfh0WrwktmMe5NIHSl0pC576nqBHR9GITNv+XMplOUHXFV/wk6NoNdflQYMYfCjo4BQATPsmXmLryIBVnwFhOsj/GclE/DeyVo4BP5cMiaKlAhr6v0YY+zVu/V/qaY/Likdwhh53RE8BDmFzK6dfF5cjnbgi3pNKfOJ8RvUsmo9dTcUD32RsyrDAs 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:CY1PR12MB0444; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0444; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0444; 4:MQ1YBX+LZnHjvjzJHfjpi9IhA2M49QPPs9MfN4RCq9mLxO+Dc/ozG1cU1ujddX1umPwRLD8xg7SYsFiNxpN8w4vdfflFoGkL7O15Ta9eloiqSKyTjWhehPyriBnatfkKfrk5xVyORuC7fX4PCOLItB1fK2Xsl1ifL7KNAkB/YoQMdn9da1oDisAW9ruASAeYhP3ab2lSAXyDQnUisKGN2Y3/TzCu+a+l2cmRoV1L2gJ8nMiylQveVRygzj4c47gUbgdFjucdV0JHQN1z2nTgNJiJtL6WdYfIls0VjEs00kH8OyciD8BUKUi8abVTjf8ssr+u70DyevNpYg5bbAep5XpJeC9O5G1NSNF0KslmSj1zImxvKiZwVSTlGDto0CDHQjkfIJDpOv2kWTdgFIfdfGkFrwilkqDaXfVd6sXeyzk= X-Forefront-PRVS: 00003DBFE7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(189002)(199003)(3846002)(6116002)(2201001)(101416001)(81166006)(86362001)(5003940100001)(47776003)(586003)(189998001)(106356001)(66066001)(7736002)(77096005)(5001770100001)(36756003)(97736004)(50466002)(33646002)(50986999)(19580405001)(81156014)(305945005)(68736007)(4326007)(50226002)(19580395003)(48376002)(8676002)(105586002)(76176999)(7846002)(92566002)(42186005)(2906002)(2950100001)(229853001)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0444; 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; CY1PR12MB0444; 23:3/NqdPxY+wMK6V65tmxY9uGJyjBPlY18KMJ/iVlaZ?= =?us-ascii?Q?ZrJiAHjncRK6UQPCt13oJvup3cf9sBogLxTt4UXdvqpeLkkKMGnaDV0PBF6C?= =?us-ascii?Q?Ap2/dyEma9VZY2FR21OlGRJaq7mWcWa2qzvvCs38F6tsuxJr6waioImJDwJE?= =?us-ascii?Q?ZEtcZR3ZAgvJ98R4eG+eQIEOfx9GjNnlCQZWzBkQ7w4cH7OSmf0kGbupgegA?= =?us-ascii?Q?vR6E6MOtLKpsNMbCBx7ngh7lCh7HvrUy72sHi6en66H/htaC0LlUXKcL0nzO?= =?us-ascii?Q?QKrleuZehG/92aaddCBXauxx7nXGkIvPxU5nSqvHJKC8phk0k5v5O94/xgSo?= =?us-ascii?Q?grHlX+zv9N4QPBQP7tB0y66frMrkgXAhm8K7mTyXOet4Fmr6QKNroBG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nhLL7OQJTQMCzpboMXL6x0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jul 2016 10:12:57.5903 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0444 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 | 60 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 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..fe1c5c3 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_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 16ef31b..968047e 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,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; @@ -986,10 +1027,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 +1328,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 +1368,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: