From patchwork Fri Mar 4 20:46:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 63610 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp281530lbc; Fri, 4 Mar 2016 12:49:33 -0800 (PST) X-Received: by 10.98.31.21 with SMTP id f21mr14751146pff.134.1457124573814; Fri, 04 Mar 2016 12:49:33 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 66si7940989pfm.92.2016.03.04.12.49.33; Fri, 04 Mar 2016 12:49:33 -0800 (PST) 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; 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 S1760225AbcCDUtP (ORCPT + 30 others); Fri, 4 Mar 2016 15:49:15 -0500 Received: from mail-by2on0067.outbound.protection.outlook.com ([207.46.100.67]:58554 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759903AbcCDUtK (ORCPT ); Fri, 4 Mar 2016 15:49:10 -0500 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.415.20; Fri, 4 Mar 2016 20:48:57 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit , Suravee Suthikulpanit Subject: [PART1 RFC v2 06/10] svm: Add interrupt injection via AVIC Date: Fri, 4 Mar 2016 14:46:04 -0600 Message-ID: <1457124368-2025-7-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457124368-2025-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1457124368-2025-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: SINPR01CA0045.apcprd01.prod.exchangelabs.com (10.141.109.45) To SN1PR12MB0445.namprd12.prod.outlook.com (25.162.105.139) X-MS-Office365-Filtering-Correlation-Id: 0014368c-7a3c-496e-96e8-08d3446e6d84 X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 2:6L09oX7MCI7jC84eOM0nEgmh8Qw3/R/xGXKeEZg29jUHSs0DhZ95bHL7VYpGFOgCONkaKRP4Q2GFEzncZf7kQyDZzvmAnaa3bHm8K2bZKD4jYIC7gR8X06W88Xz8lvg4C2cS2fgex1zfNjluWXicCTi9VRUreUROX1R1OoJiHtQabQFvmAHrd2WX/LgV/9ss; 3:qbTTEVVM3TnqfWKqZaVyi2BQftDuS6Z5WE6eAR0uMHFQIdodMYegJNcboy9D0Bo1uVtapyQmLbEP/TUMxrlsHhXLvSQYkhUTEhUfoo21gw1nafXfx194T8HizE6qp7ti; 25:nSnNn0ufEbayoRxH0z2pORKssQidryc+qyy/vo0pXZBBY+ZGf3MHITWbw1V8eM5fx0EQcPIY9BfGe69S7cP4VNZD8bkJrzx9NV05PdYnASdy47kl0htpGOu7ZWJfpFxPewXAyGePsPnSel67PNvfwu3rBSvg6IJHqy5OAVwXPMFlE9+sclAbO4mdy0rjSbq6erA3Z4FWnz78zLBBPQ11bpkzo2Oh9ZJIAV7HCEk7mrun6Xeoo2+3dlCBCzD2khiWG5hrehq8MFZBDyclqk/9DN2TCZP33cSKT5b6TP0v94HLQ8u0mIXD+kZCUiyc8JXIBu3F4yRA4LVnaXcRYm1Kgw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR12MB0445; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0445; 20:3VoN/c2txhyz6/YXYrPomd/8LpXc1WborLeuq3WqWDDGoZH04rqf0WuRrl4sjm31T3Bs2kiLoLIcP6lgP5eDqsTED30iKbDDko39VrNQJRQu33okht3xjlCYVLfgIqeNhDx6KZVvVWwyv9DOKcnmsf0WwL2d/UsHap9IHgH2e/nvIB8vC6jmCmPenJ9n6fqds2E6Yfso+kBiPPzeySwLnTgAxYpCIkZHJ38zxrhv+T4UGlPFpjn8sfRm3I4NF2Nv21dMRVOfBuc0JIUF5jS8vaA3SNW2tZIvfP07lETPEpMmyerqvPEzPC3BaLprZ9MRtqEjgM06zOcF5GHHSw0CQniHa3akKq5BF+2+WxbVLccMSdJnNXAuzyjDR8mQXjSd7M/9xaOL9y+fQ9MGTS2zCS8/fu0poTSALaLIZWysA7ITSwSIEbBOgf4XqelfVdRuTz7YeX7upfFg6O0Ucm+TiNLRIG8enpwsvpOLKDd8zIz+eA7XiWtjAUDd/rwVqR0V; 4:bwloOFUdvlP/FuSGOIoYTCyZa+TQRLY6uF4aC3gVvk7sGPFZuF7+tDnE52AE/vLuS0ZhkjVZW7S/PAP/U9VwN0k4NoZOUIKLaMVb489HtsKu7qhUJHXeDv5xxXSK5A6A+sIPwi11ILPnrvYvwuFDjDshng2Rj/YRTOb3kUa2bFbjKepdRSAGIRUTLecpi0i9sqdwo4taD+cjHSjrcD2vwR1Pnk/Z6czm5gvZ9tk0h1Z4Ip7WV3eDp+ESqeY8MUF0218R0WqY3nQa3Sm5lP6pF15ADQmlfxGswsmyzMxQF61JH/x3A3FAFEd3UeCnVpLufMrqiHhveAXxCfgVRBFIetoYYOsRESb7nacQ2CVQOczgRGSIsXKPsFYuqHftqu/J 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:SN1PR12MB0445; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0445; X-Forefront-PRVS: 0871917CDA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(77096005)(5001770100001)(87976001)(48376002)(47776003)(229853001)(36756003)(2201001)(66066001)(81166005)(50466002)(2950100001)(5004730100002)(189998001)(40100003)(50226001)(5003940100001)(122386002)(5008740100001)(19580405001)(2906002)(19580395003)(86362001)(4326007)(42186005)(50986999)(6116002)(3846002)(1096002)(92566002)(586003)(76176999); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0445; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0445; 23:QAXNajAma5rFPiRKQy1jx/VUOaT981jPfhkHFn+nE?= =?us-ascii?Q?pWq6+13q9LliqKmTxkOdloWZZGj95wCv6YrW+VeYIi8IXBNZ5tHlFDi4uZlv?= =?us-ascii?Q?KirotnUaahGl0ooN1zKlgosfwZYmRg360rXc2Oq6iweO9e5Nf+oFpSYwlaWE?= =?us-ascii?Q?UvVUC9Ynoliu6YnOxeABlpFv9dX5Vx74/ZBXYo7FcBWCe8fXdF615IDBvrqZ?= =?us-ascii?Q?qbYKxg0hypDM0sAK89SaWiinE/aJM0YzxgnycbUZQqerTxqkJK5Rh5Xac8hn?= =?us-ascii?Q?EDGt+hjhlt2LvMKbgki3e3RxskF6aCSqWyysnzr4Vr9LpWbhltNl8v1rdniI?= =?us-ascii?Q?qitGpH3SI+2Xvf24hlDjR5LXpP7R1nTdJylDyra+8kZeXUSNEFpxlS80849p?= =?us-ascii?Q?579+aDAmnu9bijVjtrdvMoqvDFBmz/Ab7vqf3ZbMiDHKSndmgJy8VwsvCW2g?= =?us-ascii?Q?bV5ZEWIwqgT0THIL2jKt/XFEoln9XGIHDnaDnFfPS3jX2M6kqKq3kIPyI99+?= =?us-ascii?Q?gZq8JshuyUZ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41pRpC6MAFkOh8l85c6JamwdWVy8f74n X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2016 20:48:57.9490 (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 | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index c703149..8f11200 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 */ @@ -236,6 +238,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); @@ -978,6 +982,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; @@ -3071,8 +3077,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.v_irq = 0; + if (!avic) { + svm_clear_vintr(svm); + svm->vmcb->control.v_irq = 0; + } mark_dirty(svm->vmcb, VMCB_INTR); @@ -3647,6 +3655,9 @@ static int msr_interception(struct vcpu_svm *svm) static int interrupt_window_interception(struct vcpu_svm *svm) { + if (avic) + BUG(); + kvm_make_request(KVM_REQ_EVENT, &svm->vcpu); svm_clear_vintr(svm); svm->vmcb->control.v_irq = 0; @@ -3961,7 +3972,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->v_intr_prio = 0xf; @@ -4042,6 +4053,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_vector(vec, avic_get_bk_page_entry(svm, APIC_IRR)); + + if (vcpu->mode == IN_GUEST_MODE) { + wrmsrl(SVM_AVIC_DOORBELL, + __default_cpu_present_to_apicid(vcpu->cpu)); + } else { + kvm_vcpu_kick(vcpu); + } +} + static int svm_nmi_allowed(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); @@ -4102,6 +4127,9 @@ static void enable_irq_window(struct kvm_vcpu *vcpu) * get that intercept, this function will be called again though and * we'll get the vintr intercept. */ + if (avic) + return; + if (gif_set(svm) && nested_svm_intr(svm)) { svm_set_vintr(svm); svm_inject_irq(svm, 0x0); @@ -4834,6 +4862,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)