Received: by 10.223.185.116 with SMTP id b49csp7481321wrg; Thu, 1 Mar 2018 06:17:25 -0800 (PST) X-Google-Smtp-Source: AG47ELsR30SCdbzpHzw5i6tVlNhRFfWkYMp9XndSz7ByDvf2xwoqQma0SNP1pWpeQgJmxA6C0nBz X-Received: by 10.98.56.131 with SMTP id f125mr2119580pfa.190.1519913845695; Thu, 01 Mar 2018 06:17:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519913845; cv=none; d=google.com; s=arc-20160816; b=AWHMLNigE+PSRAdqhRP9UQqzoJNmirNED5xfqt21l4lQDVqyG0Wg7xayLnxrkFOkaO 88AmTZNiycDxRGkqntG/RfquAb+0gLWisRy1fCW9GAsjEVCZCvDidUgU+cuPOjx2IIzj c9dJIArI8d0xh+odmOF1KjDDcBpk8gjo6GPfPFk1inKXM+2xqWQ3kn1P/b+68aBjm495 BZQXazJw/OMkZQiwrLUBdvxSPcnprJaK1anm2S7r90WyxCH8neeEt5qs5L+a+C5zk77p GmcjxoFTu21SJG8jtYZozUGLbFyACu37nsk3h7G+WHC94f4BoYM/rTYUn1AuN3KLpspM eTHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=//DM58S6f+u6xvVmxrzygZeSbfGtja/Rn0ArB+YD6kc=; b=VwB50WCws70mmBmH3dzT0JHiZO/vJW3oUmvJ5CIEZE6w+aNvrNysHlxPpgPf+KRGku 7zJ/atmrrMURSSb4yHZYLDmejsx+tSsirAGh/cL5WG8lbkUrE97ad72XxlnyWWUjDwne CjbRCipp3SHLkl6xTf28S1hsaBnquGqwH/N5rvrH5hRCY/H2JPPrez9Ibosm9Y1Fujv3 iSBdtxukf2acfho/guWkWvxYS/+Lki+uNG6ncj+DRvTS3pRepRdNLK1/gtsQPYGNjAcp 2yFADf3VTVzlrF79PPDjCOmJqwq+aaQqxpctqkld/nedUOlMXcG62W8i2q29jEXpdKga Q2KQ== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si2538660pgo.42.2018.03.01.06.17.10; Thu, 01 Mar 2018 06:17:25 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031308AbeCAOP7 (ORCPT + 99 others); Thu, 1 Mar 2018 09:15:59 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33838 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1031264AbeCAOPY (ORCPT ); Thu, 1 Mar 2018 09:15:24 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE07B818AB1A; Thu, 1 Mar 2018 14:15:23 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44D702026E04; Thu, 1 Mar 2018 14:15:22 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , "K. Y. Srinivasan" , "Michael Kelley (EOSG)" , Roman Kagan , "Denis V . Lunev" Subject: [PATCH v2 3/3] x86/kvm/hyper-v: inject #GP only when invalid SINTx vector is unmasked Date: Thu, 1 Mar 2018 15:15:14 +0100 Message-Id: <20180301141514.3482-4-vkuznets@redhat.com> In-Reply-To: <20180301141514.3482-1-vkuznets@redhat.com> References: <20180301141514.3482-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 01 Mar 2018 14:15:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 01 Mar 2018 14:15:23 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkuznets@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hyper-V 2016 on KVM with SynIC enabled doesn't boot with the following trace: kvm_entry: vcpu 0 kvm_exit: reason MSR_WRITE rip 0xfffff8000131c1e5 info 0 0 kvm_hv_synic_set_msr: vcpu_id 0 msr 0x40000090 data 0x10000 host 0 kvm_msr: msr_write 40000090 = 0x10000 (#GP) kvm_inj_exception: #GP (0x0) KVM acts according to the following statement from TLFS: " 11.8.4 SINTx Registers ... Valid values for vector are 16-255 inclusive. Specifying an invalid vector number results in #GP. " However, I checked and genuine Hyper-V doesn't #GP when we write 0x10000 to SINTx. I checked with Microsoft and they confirmed that if either the Masked bit (bit 16) or the Polling bit (bit 18) is set to 1, then they ignore the value of Vector. Make KVM act accordingly. Signed-off-by: Vitaly Kuznetsov --- Changes since v1: - Drop 'polling' bit check for now as we don't support this mode. We'll need to bring some form of this check back when polling mode is implemented [Roman Kagan]. - Add a comment explaining "!host && !masked" in synic_set_sint() --- arch/x86/kvm/hyperv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 6d14f808145d..b390a4d9ea14 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -95,9 +95,17 @@ static int synic_set_sint(struct kvm_vcpu_hv_synic *synic, int sint, u64 data, bool host) { int vector, old_vector; + bool masked; vector = data & HV_SYNIC_SINT_VECTOR_MASK; - if (vector < HV_SYNIC_FIRST_VALID_VECTOR && !host) + masked = data & HV_SYNIC_SINT_MASKED; + + /* + * Valid vectors are 16-255, however, nested Hyper-V attempts to write + * default '0x10000' value on boot and this should not #GP. We need to + * allow zero-initing the register from host as well. + */ + if (vector < HV_SYNIC_FIRST_VALID_VECTOR && !host && !masked) return 1; /* * Guest may configure multiple SINTs to use the same vector, so -- 2.14.3