From patchwork Fri Apr 8 12:49:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 65401 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp49767lbl; Fri, 8 Apr 2016 05:51:17 -0700 (PDT) X-Received: by 10.67.30.163 with SMTP id kf3mr12524977pad.45.1460119876100; Fri, 08 Apr 2016 05:51:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ah8si782613pad.148.2016.04.08.05.51.15; Fri, 08 Apr 2016 05:51: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 S932898AbcDHMun (ORCPT + 29 others); Fri, 8 Apr 2016 08:50:43 -0400 Received: from mail-by2on0090.outbound.protection.outlook.com ([207.46.100.90]:56008 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932775AbcDHMuf (ORCPT ); Fri, 8 Apr 2016 08:50:35 -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=C5pp67VwurCWIkxKdmsm+FlXOJpSoalq8xK4uDdnF5Q=; b=L8HpGLxrOQ/VcP1f7kYYvL+WZ4IeeKdhL6v+Qe3Hl5k09E2OUFoyYm3NuespivoPvWd7y1XYiw4PIVYgXzp/Zg7+FM7x2GrEb7KIKP7hpubsV9GTfGTJmiXs+q7ssBnHs/u3GMtL872EFBy8U4vfSvRNTcRz5zpkL9Gwo4jehc0= 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 SN1PR12MB0446.namprd12.prod.outlook.com (10.162.105.14) with Microsoft SMTP Server (TLS) id 15.1.453.26; Fri, 8 Apr 2016 12:50:19 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit Subject: [PART2 RFC v1 7/9] svm: Introduce AMD IOMMU avic_ga_log_notifier Date: Fri, 8 Apr 2016 07:49:28 -0500 Message-ID: <1460119770-2896-8-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460119770-2896-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1460119770-2896-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: HKNPR06CA0022.apcprd06.prod.outlook.com (10.141.16.12) To SN1PR12MB0446.namprd12.prod.outlook.com (10.162.105.14) X-MS-Office365-Filtering-Correlation-Id: 9acf3cad-78c5-42b5-cc6b-08d35fac5950 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 2:a6MVHI8wuMGjOPp9/rIVX0DUFNbfEvZiOwqgFpRC9ddpZS6sJco5NIlhkACwvWAb0MvC1Qi/JMDpj5DQyaKI6+ULpHt7/UQ1DSNbrUYZNDhhm4R0WEtROEzWlu5GjZQUP01iGzZr0Fke7vtCkT3OI+IP5fOnEGp0CA1933h7GkU0oIp5j1Og8QuvxLwD2eXB; 3:FRFyaL4uVF0m7NEB8WAJ6WY+zgEgcDhGPV8ioP/EiiXCjCdFkmQ60JbQzfJma4QU3wgcRiZdB/BK6lU/9K3rXHL3vBA3uLoq0iC1YPSFC2a5UMuuB/g/r7b8MJvJX7Ie; 25:5lEJPSVwm9UTAw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7v2JmzRcxDIT46LvAKulKfmxJuBPa7XutR9H+YxI+PVPQ6YcndTm209rf82LqngPou8KQ2ByM/EWRMwcLUpJrUmEtnM9nj53dfl44WJ9gv/0McKzv+Q0MdNocpfdExdaIjzEUyVf4nm+pmfKcKcY+Mz4r3uZ/bydvJqT9FVgc8/rs7w5uZtJ8akjave9ptz1BjKIifr8L/GUM2LoVwZ9VeY3wqgr2pPXkgPjSuv9q1LADoZgfoFd/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:SN1PR12MB0446; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0446; X-Forefront-PRVS: 0906E83A25 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(50466002)(48376002)(77096005)(47776003)(66066001)(229853001)(36756003)(86362001)(1096002)(42186005)(19580405001)(19580395003)(92566002)(6116002)(3846002)(586003)(5004730100002)(50986999)(76176999)(4326007)(189998001)(5003940100001)(2950100001)(2201001)(2906002)(5008740100001)(5001770100001)(81166005)(50226001)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0446; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 23:d2sWok0dX0BOO/99Mlr76TwS2ySYPKhSSRLMMj+kp6vqaY/O8pSiCc7et/vbEX/HxMnJF7swehAJq0xoJ2Yx3OhfjfSlm1RPlw0HSJrr1AtPC+0sBn7CWTxv6sXDRtAoTVdVG5m6Vy6iFB779eR07FF0qefw/VnT5v5b03XskDnurZeB+VWX4bLKzqGC5zNR6YWm1gdRdV09Yn5H3UynhlIpk++YBhLGSVZiib9HESLwP+qMu/NhTQzYRa1qDQQC1ZPiZFzsn8UT/Q3Ks5B+HeDmSX2NJw7+5IgcAQtbyDP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vZ0SOIN3dEta1k//spzPEywwizWzjyWX2A+N1eg61H+DrfXpZ/e7ObQZ0l/5uYCehfC0BMCSaZr99IJ1XzcGW6KBZkrPQxLEEF8oePxU84FRSG X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2016 12:50:19.2632 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0446 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 | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) -- 1.9.1 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 5ee3eb7..b56ba9f 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 a037ceb..6b5ce27 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include @@ -921,6 +923,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; @@ -981,6 +1022,10 @@ static __init int svm_hardware_setup(void) if (avic) { printk(KERN_INFO "kvm: 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); } else { svm_x86_ops.deliver_posted_interrupt = NULL; } @@ -1280,12 +1325,17 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu) static void avic_vm_uninit(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 void avic_vcpu_uninit(struct kvm_vcpu *vcpu) @@ -1301,6 +1351,7 @@ static void avic_vcpu_uninit(struct kvm_vcpu *vcpu) 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; @@ -1325,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_tag); + spin_unlock_irqrestore(&svm_vm_data_hash_lock, flags); + return 0; free_avic: