Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2067181ybe; Tue, 3 Sep 2019 07:32:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqziUvsYMoVoULZGHE8NbqY6ByQsj/3/ZFpR7QwfOq/klphDQhjFuzYDUp9dNmcJ0M8YkZa+ X-Received: by 2002:aa7:8a13:: with SMTP id m19mr17581505pfa.228.1567521159424; Tue, 03 Sep 2019 07:32:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567521159; cv=none; d=google.com; s=arc-20160816; b=W54zeQKFXAV4fpdi0YANaoZXnhPKTxtFEpmIvM/LfhltUoJx3Nqg6c0Bk2kpE/ZYqe W4Sc491ymYlqSVDacuqy9Xc3IZ8xkDMd3NrLdYWBbhZXGjpKaeHyVqu2s3U7e6rYRX0k qaxOL7dm32PHejFnpulAQOFtLj/McIteS4f1xGKL1cqEoesfTKiF671mb4Qk2SFVfgjl Gcs4NvTpL9l9jtppadVVhsMbU9aZDIBf6cocyN55BPlyeFoZ7lwj/aM5r4itPpBytUTo 7F6Y1nB/sWHp50eZWdGCCXbrnj2TdDwt3yMTU9G9kBw7EUejTSRdUVNIjMa8X9tIMjUH rqog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=TsVQ4YmQUOxpHUFBpHr6G7zfIEU+Q8EKLJiiqblwGRM=; b=tXlyYlVuWpE2FDY9v4rI0UAziIHAh/kBmptKxAuFSQcqzcmszNXdOelNLoWj4vpW38 rs2T6NuAtAIWp1txudqrxWBSTC/lHDIbfYQk8HGkmeH2quXHr29BfwA9qvcaI/9nbfAO olg7u2JYLWND1gSSQX4Qxu0cff3zKtk3nMr6rxTKR6RI5VLG/Y6VH9SC0SPexuUBNxxk g8DqHgU1j9Y8CfcNGeuk6KM52KsmS/2H2MmIRJ+yLDBsQd6PyffxXDShqojj/QEV0A9C K/N+s5gWhij5EYaMBtYhOfD7Q5dWc3MAZsG80poMQt9EdeH3w2A8PHuBf/q+2EBA1R4i kj+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=vfmCkPa9; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d17si17472102pfr.235.2019.09.03.07.32.23; Tue, 03 Sep 2019 07:32:39 -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=@amazon.com header.s=amazon201209 header.b=vfmCkPa9; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729818AbfICOaj (ORCPT + 99 others); Tue, 3 Sep 2019 10:30:39 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:30282 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727667AbfICOai (ORCPT ); Tue, 3 Sep 2019 10:30:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1567521037; x=1599057037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=TsVQ4YmQUOxpHUFBpHr6G7zfIEU+Q8EKLJiiqblwGRM=; b=vfmCkPa9b2A9Jz4PsTGp2yQ+T2ucJ4f6CmAb7GiZkUhXOI8Zqv6YTXne RFUQIXq/ToQiRX/KcQHY31bPy8QLBIGsGWGfQOjmZ8Yafg2NGltqn1vbk 3GPpnhYiVsUx2sQDKpQYUAPF0bCg0Q5UXMhk+VEyR8hOJgK6H0IP6ogNu o=; X-IronPort-AV: E=Sophos;i="5.64,463,1559520000"; d="scan'208";a="748773588" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 03 Sep 2019 14:30:35 +0000 Received: from EX13MTAUWC001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-538b0bfb.us-west-2.amazon.com (Postfix) with ESMTPS id 3294EA2DEE; Tue, 3 Sep 2019 14:30:34 +0000 (UTC) Received: from EX13D20UWC001.ant.amazon.com (10.43.162.244) by EX13MTAUWC001.ant.amazon.com (10.43.162.135) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 3 Sep 2019 14:30:11 +0000 Received: from u79c5a0a55de558.ant.amazon.com (10.43.162.242) by EX13D20UWC001.ant.amazon.com (10.43.162.244) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 3 Sep 2019 14:30:08 +0000 From: Alexander Graf To: CC: , , "H. Peter Anvin" , Borislav Petkov , Ingo Molnar , Thomas Gleixner , Joerg Roedel , Jim Mattson , Wanpeng Li , Vitaly Kuznetsov , "Sean Christopherson" , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Paolo Bonzini Subject: [PATCH 2/2] KVM: SVM: Disable posted interrupts for odd IRQs Date: Tue, 3 Sep 2019 16:29:54 +0200 Message-ID: <20190903142954.3429-3-graf@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190903142954.3429-1-graf@amazon.com> References: <20190903142954.3429-1-graf@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.242] X-ClientProxiedBy: EX13D27UWA002.ant.amazon.com (10.43.160.30) To EX13D20UWC001.ant.amazon.com (10.43.162.244) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We can easily route hardware interrupts directly into VM context when they target the "Fixed" or "LowPriority" delivery modes. However, on modes such as "SMI" or "Init", we need to go via KVM code to actually put the vCPU into a different mode of operation, so we can not post the interrupt Add code in the SVM PI logic to explicitly refuse to establish posted mappings for advanced IRQ deliver modes. This fixes a bug I have with code which configures real hardware to inject virtual SMIs into my guest. Signed-off-by: Alexander Graf --- arch/x86/kvm/svm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 1f220a85514f..9a6ea78c3239 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5266,6 +5266,21 @@ get_pi_vcpu_info(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, return -1; } + switch (irq.delivery_mode) { + case dest_Fixed: + case dest_LowestPrio: + break; + default: + /* + * For non-trivial interrupt events, we need to go + * through the full KVM IRQ code, so refuse to take + * any direct PI assignments here. + */ + pr_debug("SVM: %s: use legacy intr remap mode for irq %u\n", + __func__, irq.vector); + return -1; + } + pr_debug("SVM: %s: use GA mode for irq %u\n", __func__, irq.vector); *svm = to_svm(vcpu); @@ -5314,6 +5329,7 @@ static int svm_update_pi_irte(struct kvm *kvm, unsigned int host_irq, * 1. When cannot target interrupt to a specific vcpu. * 2. Unsetting posted interrupt. * 3. APIC virtialization is disabled for the vcpu. + * 4. IRQ has extended delivery mode (SMI, INIT, etc) */ if (!get_pi_vcpu_info(kvm, e, &vcpu_info, &svm) && set && kvm_vcpu_apicv_active(&svm->vcpu)) { -- 2.17.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879