Received: by 10.223.185.116 with SMTP id b49csp6204109wrg; Wed, 28 Feb 2018 05:45:21 -0800 (PST) X-Google-Smtp-Source: AH8x226mJhY65XBtuy6ZhqOxnNit61nmKLuj427G6y2d1PAD4eALAGak2hcqp/U6EIqGutX/nigl X-Received: by 2002:a17:902:ab84:: with SMTP id f4-v6mr18368577plr.239.1519825521232; Wed, 28 Feb 2018 05:45:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519825521; cv=none; d=google.com; s=arc-20160816; b=jiyEdKHiDbg8Poo416P3rfaV8qTLsiEEPbs9GmI3RVqqkBwaoEQvQmbIkQLva1btIA WVLtRgLyzEnIK5HidgPLKZws35Rcj8C8SJEsZEIuNfKjZgw9dtXgikwFnBFmi3EmkW9t aBEZI3S3I0fL74DjLJlh0ySmgOV384xm6QslGSPvV4Xm2rlURgF5dd1GI3MySLplnfT+ s1+VIadbBe4sKlZDzvGfPz1NoXHNoWfMDATjc8BCjQA/PLwHHKq6xcQpREs+2fWiPzO3 mX59Z7tlWGl9YSgkIn3fa36UNMxi7hLRPUpoJYbaIrkjBk+xsp2AsdW+mktik5m+mDDf B80g== 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=dKt16q4+FAuSFae4PwsSYeSZS2o3TjiK/QaYD7WOJeg=; b=p/5MV823tLQgMoIUWNVzwiVv0jnSwbYzHXUoZhHIM5KscAeTgghDimXKw5/hGLr2l/ OlaFAUMuDCMUBwlX61uf/dhs7zrxM9Ty/RA7HiCui1n5vhkvUPJcBcBmcvGal+YEg3nX B1PX8fLBBFqesb+HlAVgnSqWwwUvOQz7GKaXCvVD7R4WS+ginxxEqLWAPre4L+1F8HbZ 877aSb2mVCXYyOGSokShwv1kOwP5Ih7bzCUy2jUzooA74RMuoCph8hzilYCb3+rPofAT 3KtWVlWEE0/wIUmoagJ47xGzVB62iFXEx7dV1XNWHAjxixyn9g0a9NiY7I38U17gY52H kgUw== 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 u19-v6si1298568plq.120.2018.02.28.05.45.04; Wed, 28 Feb 2018 05:45:21 -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 S932204AbeB1NoP (ORCPT + 99 others); Wed, 28 Feb 2018 08:44:15 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41360 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932167AbeB1NoL (ORCPT ); Wed, 28 Feb 2018 08:44:11 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E95CC4075166; Wed, 28 Feb 2018 13:44:10 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62801946B5; Wed, 28 Feb 2018 13:44:09 +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)" , Andrey Smetanin , Roman Kagan , "Denis V . Lunev" Subject: [PATCH 3/3] x86/kvm/hyper-v: inject #GP only when invalid SINTx vector is unmasked Date: Wed, 28 Feb 2018 14:44:01 +0100 Message-Id: <20180228134401.6544-4-vkuznets@redhat.com> In-Reply-To: <20180228134401.6544-1-vkuznets@redhat.com> References: <20180228134401.6544-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 28 Feb 2018 13:44:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 28 Feb 2018 13:44:11 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 --- arch/x86/include/uapi/asm/hyperv.h | 1 + arch/x86/kvm/hyperv.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h index 62c778a303a1..a492dc357bd7 100644 --- a/arch/x86/include/uapi/asm/hyperv.h +++ b/arch/x86/include/uapi/asm/hyperv.h @@ -326,6 +326,7 @@ typedef struct _HV_REFERENCE_TSC_PAGE { #define HV_SYNIC_SIEFP_ENABLE (1ULL << 0) #define HV_SYNIC_SINT_MASKED (1ULL << 16) #define HV_SYNIC_SINT_AUTO_EOI (1ULL << 17) +#define HV_SYNIC_SINT_POLLING (1ULL << 18) #define HV_SYNIC_SINT_VECTOR_MASK (0xFF) #define HV_SYNIC_STIMER_COUNT (4) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 6d14f808145d..d3d866c32976 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -95,9 +95,14 @@ static int synic_set_sint(struct kvm_vcpu_hv_synic *synic, int sint, u64 data, bool host) { int vector, old_vector; + bool masked, polling; vector = data & HV_SYNIC_SINT_VECTOR_MASK; - if (vector < HV_SYNIC_FIRST_VALID_VECTOR && !host) + masked = data & HV_SYNIC_SINT_MASKED; + polling = data & HV_SYNIC_SINT_POLLING; + + if (vector < HV_SYNIC_FIRST_VALID_VECTOR && + !host && !masked && !polling) return 1; /* * Guest may configure multiple SINTs to use the same vector, so -- 2.14.3