Received: by 10.223.185.116 with SMTP id b49csp7481870wrg; Thu, 1 Mar 2018 06:17:51 -0800 (PST) X-Google-Smtp-Source: AG47ELuUB0dYyWk7Jq4b1I7Z/0D22JIs7rJaezIrZoqj0Bt+EWyshRclMfx9KT46RfhwR30wk0bw X-Received: by 2002:a17:902:4201:: with SMTP id g1-v6mr2093931pld.62.1519913870993; Thu, 01 Mar 2018 06:17:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519913870; cv=none; d=google.com; s=arc-20160816; b=kZihdfGoCywdmuuHGI/lCqP5vm4qTGWoJgrfPDvnOFR7Hd0X8cOyMUS1nkZZXcjeTD IsaqlEH/czDe1b81WyHeixxIOn7VQq3bYDlYJnJJj3I4C8IpeQHVBYItqj81cdxfYv3o uC39uYXE58KaGcMJGQF5F32gc49d5bjBGjwA+gmui0cb9ffdV/OgnKsSe1bsFkSGkQMg 80i+rTia7hAboRa+/aqDwZf+BpzyG0qjRWK4ENqhlQuyM0KqttJ7hof4xTLjvAg9e5QW Xj9/WleK3ri7urI5wp1CcA1SDF2PudY9Aj26grn2/H0vdK/gCOptZsstyXTDVz2ywn1X FsXQ== 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=UYCgiLQfgFH4eOtNcRAC9xX0DVoSbbetZkccfntVhdc=; b=kOvpXjFDbLaejib0KBwtqoEDdxOn0BJNbdrU52+s48xDPtrXWCWeOYDA9i72XmYUjR SJs5Q6fiC4LBRTc+Y+fP6lZKuZstLMl1sqR8cJcQUKh1931Nel1lYn2chzJyOy1qiSjV g/02pE26PrPnAg8Db7egdJWGGcF1cKXJxvmEyYBU6Bx9DsSNOjewNTAIa4w0zJpdon3o NT3uANPwtRgtw6llVEQuSBabKcmboQZH/B3dMtk3/eugGB/7B8MEAj+lqrLSZwSCHEU4 zIVTW3NODO2a3bgtEGhXoKaft8D5bra2oG+F5dy3n/rHa2CtjbSeeZXuCO9B6/hNMHzn 4ViQ== 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 v12-v6si3076176plk.256.2018.03.01.06.17.35; Thu, 01 Mar 2018 06:17:50 -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 S1031280AbeCAOP2 (ORCPT + 99 others); Thu, 1 Mar 2018 09:15:28 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38348 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1031211AbeCAOPW (ORCPT ); Thu, 1 Mar 2018 09:15:22 -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 10358402291E; Thu, 1 Mar 2018 14:15:22 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A7AF2024CA6; Thu, 1 Mar 2018 14:15:20 +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 2/3] x86/kvm/hyper-v: remove stale entries from vec_bitmap/auto_eoi_bitmap on vector change Date: Thu, 1 Mar 2018 15:15:13 +0100 Message-Id: <20180301141514.3482-3-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.6]); Thu, 01 Mar 2018 14:15:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 01 Mar 2018 14:15:22 +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 When a new vector is written to SINx we update vec_bitmap/auto_eoi_bitmap but we forget to remove old vector from these masks (in case it is not present in some other SINTx). Signed-off-by: Vitaly Kuznetsov Reviewed-by: Roman Kagan --- arch/x86/include/uapi/asm/hyperv.h | 2 ++ arch/x86/kvm/hyperv.c | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h index 197c2e6c7376..62c778a303a1 100644 --- a/arch/x86/include/uapi/asm/hyperv.h +++ b/arch/x86/include/uapi/asm/hyperv.h @@ -318,6 +318,8 @@ typedef struct _HV_REFERENCE_TSC_PAGE { #define HV_SYNIC_SINT_COUNT (16) /* Define the expected SynIC version. */ #define HV_SYNIC_VERSION_1 (0x1) +/* Valid SynIC vectors are 16-255. */ +#define HV_SYNIC_FIRST_VALID_VECTOR (16) #define HV_SYNIC_CONTROL_ENABLE (1ULL << 0) #define HV_SYNIC_SIMP_ENABLE (1ULL << 0) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 05f414525538..6d14f808145d 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -74,13 +74,30 @@ static bool synic_has_vector_auto_eoi(struct kvm_vcpu_hv_synic *synic, return false; } +static void synic_update_vector(struct kvm_vcpu_hv_synic *synic, + int vector) +{ + if (vector < HV_SYNIC_FIRST_VALID_VECTOR) + return; + + if (synic_has_vector_connected(synic, vector)) + __set_bit(vector, synic->vec_bitmap); + else + __clear_bit(vector, synic->vec_bitmap); + + if (synic_has_vector_auto_eoi(synic, vector)) + __set_bit(vector, synic->auto_eoi_bitmap); + else + __clear_bit(vector, synic->auto_eoi_bitmap); +} + static int synic_set_sint(struct kvm_vcpu_hv_synic *synic, int sint, u64 data, bool host) { - int vector; + int vector, old_vector; vector = data & HV_SYNIC_SINT_VECTOR_MASK; - if (vector < 16 && !host) + if (vector < HV_SYNIC_FIRST_VALID_VECTOR && !host) return 1; /* * Guest may configure multiple SINTs to use the same vector, so @@ -88,18 +105,13 @@ static int synic_set_sint(struct kvm_vcpu_hv_synic *synic, int sint, * bitmap of vectors with auto-eoi behavior. The bitmaps are * updated here, and atomically queried on fast paths. */ + old_vector = synic_read_sint(synic, sint) & HV_SYNIC_SINT_VECTOR_MASK; atomic64_set(&synic->sint[sint], data); - if (synic_has_vector_connected(synic, vector)) - __set_bit(vector, synic->vec_bitmap); - else - __clear_bit(vector, synic->vec_bitmap); + synic_update_vector(synic, old_vector); - if (synic_has_vector_auto_eoi(synic, vector)) - __set_bit(vector, synic->auto_eoi_bitmap); - else - __clear_bit(vector, synic->auto_eoi_bitmap); + synic_update_vector(synic, vector); /* Load SynIC vectors into EOI exit bitmap */ kvm_make_request(KVM_REQ_SCAN_IOAPIC, synic_to_vcpu(synic)); -- 2.14.3