From patchwork Thu Apr 7 08:20: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: 65238 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp329590lbc; Thu, 7 Apr 2016 01:22:30 -0700 (PDT) X-Received: by 10.66.55.39 with SMTP id o7mr2936757pap.13.1460017350150; Thu, 07 Apr 2016 01:22:30 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yx1si10234653pab.52.2016.04.07.01.22.29; Thu, 07 Apr 2016 01:22:30 -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 S1755564AbcDGIWL (ORCPT + 29 others); Thu, 7 Apr 2016 04:22:11 -0400 Received: from mail-by2on0068.outbound.protection.outlook.com ([207.46.100.68]:40640 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751231AbcDGIWD (ORCPT ); Thu, 7 Apr 2016 04:22:03 -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=XuvSeYmeqKGU3jMOSOvs0LLguiNNzU1yxbwJuw31bmw=; b=K5p/rSUlHiR5EOv6Tun6qyOXyXdTATaqhvbrtvnlLMfgf5qt5DVW8xaB1y0UVjoU/Hrzz2f4semdADvFKNKhrcPvm8NmLGpflXybAvG7qwf07UsJ80g7TM/urbd1mM6AApL8YSzekWRdEppd+z3AwsBttI/gIAYkE5XIhUKzEsM= 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 SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) with Microsoft SMTP Server (TLS) id 15.1.447.15; Thu, 7 Apr 2016 08:21:50 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit , Suravee Suthikulpanit Subject: [PART1 RFC v4 07/11] svm: Add interrupt injection via AVIC Date: Thu, 7 Apr 2016 03:20:28 -0500 Message-ID: <1460017232-17429-8-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460017232-17429-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1460017232-17429-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: KL1PR02CA0009.apcprd02.prod.outlook.com (10.165.15.19) To SN1PR12MB0445.namprd12.prod.outlook.com (10.162.105.139) X-MS-Office365-Filtering-Correlation-Id: 1ef0d7bd-1ece-41b8-eb0b-08d35ebdb086 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 2:Wd8f1uu/lnQRxG88bDeX2oDg4WOSBL4JdVNsAStT8OfzbkZnxj4soMEz793ZgPxyzfb4+zdrEqbPv1IhvLDt8pX+Pn2nB3OkwS3lh9oI+6/qYPEPMvBtH+VIpsG3tGZVKgLDAKOm1TggFiHQhx3IlbjTjOJybb6/hxbrMX7aB7x8SO15EjesfGvIU385cX9G; 3:Px0qqBiNOE7vR45FybJS8e09WP3cUpJvnKGSA1dMcDprjIea1/N54WP4vca20D8pu4lLNEdZ4K3i/SYHDUjMnlKo96ESyI+r8KvOSR8nBVwWV6vhRtebU9WkFs/QFSjT; 25:NK3OyvKOpOACZbJdeZN6V2hjquXR6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/M6uUf4m0FJ6RCqB9kEh492cgVdoc7JcgxFyeX1UyAf3ZCQT9MoKQfFgXkefz0rWGMGdYQZ5ZVBjNGWO7rVdKx/gIvDbl8HqzmQ6AjR08uEFp8dPdawdTeo2T0ZqF+sk57sRcSqcMte8RPSuJglK0skvWaALi51FKg/k6QKBS+Xd7bM30VbkestJ1cj1ukovmsh/zWwlku9TBv39dQnuneFOaGS7C 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)(10201501046)(3002001); SRVR:SN1PR12MB0445; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0445; X-Forefront-PRVS: 0905A6B2C7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(5001770100001)(50466002)(2906002)(48376002)(50986999)(189998001)(77096005)(4326007)(2950100001)(36756003)(5003940100001)(92566002)(76176999)(47776003)(19580395003)(19580405001)(81166005)(2201001)(229853001)(50226001)(86362001)(42186005)(586003)(3846002)(5008740100001)(66066001)(1096002)(6116002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0445; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 23:GAjnUub2Jy+Xz6Amx446MZpQqaX5LITd2dzKQl17LbcEN7qLkJHIe68WeHlk2ts+tmf2amTi0DhxDqChG5oSXDlbJeI1rkL9rJ0+pofXcx03DkBVtVWL1lsFIXz9CutxVpdfvKIp5FC9vyWgeN1SwjO+mBFrfutb9ssxgu4ax+//KtP8o8jStdUuzjKkxgdi+g8sBqZmotTSKfFHKPSyxDeQTM3GMrZhsHCVoPX9ndMqYhljykAQWu4ViXnr/wG9U6/uza+Oh6VcXuEN+a2MrB9FIsMXiRqccPh59AinP8WXMqNvxjVX/SGw2t1NzT7ApmhmOch6ZhF31/3sqR6N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uxgjBHkApGvwZrOvYd/bDsgKp X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2016 08:21:50.6267 (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 This patch introduces a new mechanism to inject interrupt using AVIC. Since VINTR is not supported when enable AVIC, we need to inject interrupt via APIC backing page instead. This patch also adds support for AVIC doorbell, which is used by KVM to signal a running vcpu to check IRR for injected interrupts. Signed-off-by: Suravee Suthikulpanit --- arch/x86/kvm/svm.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 137cf18..f9547bc 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -71,6 +71,8 @@ MODULE_DEVICE_TABLE(x86cpu, svm_cpu_id); #define SVM_FEATURE_DECODE_ASSIST (1 << 7) #define SVM_FEATURE_PAUSE_FILTER (1 << 10) +#define SVM_AVIC_DOORBELL 0xc001011b + #define NESTED_EXIT_HOST 0 /* Exit handled on host level */ #define NESTED_EXIT_DONE 1 /* Exit caused nested vmexit */ #define NESTED_EXIT_CONTINUE 2 /* Further checks needed */ @@ -216,6 +218,8 @@ static bool npt_enabled = true; static bool npt_enabled; #endif +static struct kvm_x86_ops svm_x86_ops; + /* allow nested paging (virtualized MMU) for all guests */ static int npt = true; module_param(npt, int, S_IRUGO); @@ -290,6 +294,18 @@ static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu) return container_of(vcpu, struct vcpu_svm, vcpu); } +static inline bool avic_vcpu_is_running(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + u64 *entry; + + entry = svm->avic_physical_id_cache; + if (!entry) + return false; + + return (READ_ONCE(*entry) & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK); +} + static void recalc_intercepts(struct vcpu_svm *svm) { struct vmcb_control_area *c, *h; @@ -963,6 +979,8 @@ static __init int svm_hardware_setup(void) if (avic) { printk(KERN_INFO "kvm: AVIC enabled\n"); + } else { + svm_x86_ops.deliver_posted_interrupt = NULL; } return 0; @@ -2883,8 +2901,10 @@ static int clgi_interception(struct vcpu_svm *svm) disable_gif(svm); /* After a CLGI no interrupts should come */ - svm_clear_vintr(svm); - svm->vmcb->control.int_ctl &= ~V_IRQ_MASK; + if (!svm_vcpu_avic_enabled(svm)) { + svm_clear_vintr(svm); + svm->vmcb->control.int_ctl &= ~V_IRQ_MASK; + } mark_dirty(svm->vmcb, VMCB_INTR); @@ -3777,6 +3797,7 @@ static inline void svm_inject_irq(struct vcpu_svm *svm, int irq) { struct vmcb_control_area *control; + /* The following fields are ignored when AVIC is enabled */ control = &svm->vmcb->control; control->int_vector = irq; control->int_ctl &= ~V_INTR_PRIO_MASK; @@ -3854,6 +3875,20 @@ static void svm_sync_pir_to_irr(struct kvm_vcpu *vcpu) return; } +static void svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec) +{ + struct vcpu_svm *svm = to_svm(vcpu); + + kvm_lapic_set_irr(vec, svm->vcpu.arch.apic); + smp_mb__after_atomic(); + + if (avic_vcpu_is_running(vcpu)) + wrmsrl(SVM_AVIC_DOORBELL, + __default_cpu_present_to_apicid(vcpu->cpu)); + else + kvm_vcpu_wake_up(vcpu); +} + static int svm_nmi_allowed(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); @@ -3908,6 +3943,9 @@ static void enable_irq_window(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); + if (svm_vcpu_avic_enabled(svm)) + return; + /* * In case GIF=0 we can't rely on the CPU to tell us when GIF becomes * 1, because that's a separate STGI/VMRUN intercept. The next time we @@ -4651,6 +4689,7 @@ static struct kvm_x86_ops svm_x86_ops = { .sched_in = svm_sched_in, .pmu_ops = &amd_pmu_ops, + .deliver_posted_interrupt = svm_deliver_avic_intr, }; static int __init svm_init(void)