From patchwork Fri Apr 8 12:49:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 65400 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp49751lbl; Fri, 8 Apr 2016 05:51:15 -0700 (PDT) X-Received: by 10.66.79.162 with SMTP id k2mr11209273pax.121.1460119875449; Fri, 08 Apr 2016 05:51:15 -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:15 -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 S932880AbcDHMuk (ORCPT + 29 others); Fri, 8 Apr 2016 08:50:40 -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 S932854AbcDHMug (ORCPT ); Fri, 8 Apr 2016 08:50:36 -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=fI4WrTdhN62Ybrl8sEdbe0Rd6t8/gWvpPtJR+u3LLps=; b=dfI3k/GUESwJZeZ+qSFbnyObWtlHGvXOZ6UY1cI1aokhl1XHX2v8q5z7IgSA/W4PF0Wjquv5jDBMYfkP5uO71pKZITc+MiCiRx4c9Zn8tJkAJXXJn1qiqafucx1PZFZzxTZcxhcbAxNHJzigsx8TtRtDZOn6ybbtTT1683qiDOY= 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:23 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit Subject: [PART2 RFC v1 8/9] svm: Implements update_pi_irte hook to setup posted interrupt Date: Fri, 8 Apr 2016 07:49:29 -0500 Message-ID: <1460119770-2896-9-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: 8d7dba1d-76e3-4372-f145-08d35fac5bb7 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 2:HyiuSjMwUc9ykqSub/i0+3zl7SZuhcPDihLayLIk2sIiUrMqU/zfEVItpfEWrsdnvGFJ+qedWHCBW8fKroML+NjQPj0MB+lGfDPoccXXf6CpBmU94SurIwomo0fkf+DyWE4EAz16443zGhGgPQ0BYUg5pkBNzVoOqFO0aXs6IHO27aIVfk884Z20aTuw+8T+; 3:NXPSjXdMNexEjbzgmTYu02r8n3mR5VjEsAsJxQg8Q8UvNvRh1O1m48oj4p7cfInmLTE2Nam2u4iAWqHVXzfoQjgo7Y1lG6E0K3sI7sO4Wgqhhkm++MwHx9Q9vqMCCj2S; 25:wXoONdbg6pwIlnxx6UCwkLXJ8IdMvQ3R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elrOc2jqjsE3DIHa7cIRZLT4p55W8lmRwQalsSHQqq0ZV/6q95YTJulVNfd7lZb4SkxQv/v+qK6zgo0ht5y1I5Pgjakyn62rHBYfewwwYEHzw3r0SEL7IMd8HrTgdbwrb7e8ndvonTxj4MJwtFXQeyDM6IY19QS5wQl5j69pKaE3ToDVQAV8d/AUhq+P8XWVp8oKe2+q3FzkUjjKDhy8d5yupcb 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)(15650500001)(50986999)(76176999)(4326007)(189998001)(5003940100001)(2950100001)(2201001)(2906002)(5008740100001)(5001770100001)(81166005)(50226001); 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:jSypgWaP1tZymWNsZoUJDNgyTCw2gV/Pe3nZYI8Vl/q/k6Mj/gEjc41hJm+lsStLPvrP7LZpswjYAjHUKNJqLOgXimUAhODlTyXrriOofUk242DioXMQbBem/qd2fq1ETMeKhIWGjF++mZs6KNDdHDTO96VlSaYek8Xi2rYieMGiqEyE2eQk7BbGzTHpPi031aTar9dqhMQ09f4ecotWHooJ7z75RPhzYPDw335GESq+Li6yni6GNc3JhFqaNFHRJDj9CveqbXJYGzg2ySlKLbHt1epWug4DGR6J8a4ZmgvSNtw+XtO0kRyMlEey2jJa1IuI5pW5Uwo65EPBmn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zhezO+FdUJR6/iGpCxkIqLp54lWfLxTggGtrxkmVtkobPepJLJRgaFRxOH8FDmQp9LP+RT+tPMHL4tTFKnq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2016 12:50:23.2790 (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 implements update_pi_irte function hook to allow SVM communicate to IOMMU driver regarding how to set up IRTE for handling posted interrupt. Signed-off-by: Suravee Suthikulpanit --- arch/x86/kvm/svm.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) -- 1.9.1 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 6b5ce27..38fd7a3 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include "trace.h" @@ -1349,6 +1350,13 @@ static void avic_vcpu_uninit(struct kvm_vcpu *vcpu) svm->avic_physical_id_cache = NULL; } +static atomic_t avic_tag_gen = ATOMIC_INIT(0); + +static inline u32 avic_get_next_tag(void) +{ + return atomic_inc_return(&avic_tag_gen); +} + static int avic_vm_init(struct kvm *kvm) { unsigned long flags; @@ -1373,6 +1381,8 @@ static int avic_vm_init(struct kvm *kvm) if (!l_page) goto free_avic; + vm_data->avic_tag = avic_get_next_tag(); + vm_data->avic_logical_id_table_page = l_page; clear_page(page_address(l_page)); @@ -4278,6 +4288,102 @@ static void svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec) kvm_vcpu_wake_up(vcpu); } +/* + * svm_update_pi_irte - set IRTE for Posted-Interrupts + * + * @kvm: kvm + * @host_irq: host irq of the interrupt + * @guest_irq: gsi of the interrupt + * @set: set or unset PI + * returns 0 on success, < 0 on failure + */ +static int svm_update_pi_irte(struct kvm *kvm, unsigned int host_irq, + uint32_t guest_irq, bool set) +{ + struct kvm_kernel_irq_routing_entry *e; + struct kvm_irq_routing_table *irq_rt; + struct kvm_lapic_irq irq; + struct kvm_vcpu *vcpu = NULL; + struct vcpu_data vcpu_info; + int idx, ret = -EINVAL; + struct vcpu_svm *svm; + struct amd_iommu_pi_data pi_data; + + if (!kvm_arch_has_assigned_device(kvm) || + !irq_remapping_cap(IRQ_POSTING_CAP)) + return 0; + + pr_debug("SVM: %s: host_irq=%#x, guest_irq=%#x, set=%#x\n", + __func__, host_irq, guest_irq, set); + + idx = srcu_read_lock(&kvm->irq_srcu); + irq_rt = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu); + WARN_ON(guest_irq >= irq_rt->nr_rt_entries); + + hlist_for_each_entry(e, &irq_rt->map[guest_irq], link) { + if (e->type != KVM_IRQ_ROUTING_MSI) + continue; + + /** + * Note: + * The HW cannot support posting multicast/broadcast + * interrupts to a vCPU. So, we still use interrupt + * remapping for these kind of interrupts. + * + * For lowest-priority interrupts, we only support + * those with single CPU as the destination, e.g. user + * configures the interrupts via /proc/irq or uses + * irqbalance to make the interrupts single-CPU. + */ + kvm_set_msi_irq(e, &irq); + if (kvm_intr_is_single_vcpu(kvm, &irq, &vcpu)) { + svm = to_svm(vcpu); + vcpu_info.pi_desc_addr = page_to_phys(svm->avic_backing_page); + vcpu_info.vector = irq.vector; + + trace_kvm_pi_irte_update(vcpu->vcpu_id, host_irq, e->gsi, + vcpu_info.vector, + vcpu_info.pi_desc_addr, set); + + pi_data.vcpu_id = vcpu->vcpu_id; + + pr_debug("SVM: %s: use GA mode for irq %u\n", __func__, + irq.vector); + } else { + set = false; + + pr_debug("SVM: %s: use legacy intr remap mode for irq %u\n", + __func__, irq.vector); + } + + /** + * Note: + * When AVIC is disabled, we fall-back to setup + * IRTE w/ legacy mode + */ + if (set && svm_vcpu_avic_enabled(svm)) { + /* Enable GA mode in IRTE */ + pi_data.avic_tag = kvm->arch.avic_tag; + pi_data.vcpu_data = &vcpu_info; + ret = irq_set_vcpu_affinity(host_irq, &pi_data); + } else { + /* Use legacy mode in IRTE */ + pi_data.vcpu_data = NULL; + ret = irq_set_vcpu_affinity(host_irq, &pi_data); + } + + if (ret < 0) { + pr_err("%s: failed to update PI IRTE\n", __func__); + goto out; + } + } + + ret = 0; +out: + srcu_read_unlock(&kvm->irq_srcu, idx); + return ret; +} + static int svm_nmi_allowed(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); @@ -5094,6 +5200,7 @@ static struct kvm_x86_ops svm_x86_ops = { .pmu_ops = &amd_pmu_ops, .deliver_posted_interrupt = svm_deliver_avic_intr, + .update_pi_irte = svm_update_pi_irte, }; static int __init svm_init(void)