Received: by 10.223.185.116 with SMTP id b49csp6205636wrg; Wed, 28 Feb 2018 05:46:58 -0800 (PST) X-Google-Smtp-Source: AH8x225sD8nSepAaNH16daK2Y3Wyv26DxW+tgHOQvhm4sPGzUpohszf95Jpcvu3crtWhbwzzIxm3 X-Received: by 2002:a17:902:6c4d:: with SMTP id h13-v6mr18308074pln.273.1519825618195; Wed, 28 Feb 2018 05:46:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519825618; cv=none; d=google.com; s=arc-20160816; b=E1zUsiBzMiU5e5E0+9bU6bqIdsRfhJD0UWprpZFrMGVtxtt9HagMWiC6UQjzZbaTQk DBq0fKmAa+q9MrzYommkz15/agYhYKSMR4pGfLb3o4bEDsyyZe+0ZjUr9o+VDajpYKfi thNLesstTbJP5JnvK0Ek+1byUxMj1HNNutGcZU+80T3MHD8116Wpp0aGhq09i/gcVGg7 MB8xRwm+070EKfnsMAhN8mUcXAJyO1MrlPEdP5LLx/2bGJvRuzlDmYbE6jhsVlPjau6J fEc5N9nM22XqWtq8xVzH4+KAS3yl31QKGpOPyCZ8HgReNEf7ZKNxFgcpZWAXIFcMQmTA QYSQ== 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=Bt3fN7ywvLOoxWOmeX7O4mXpcFPXi80NTO+JvK/CAJA=; b=D53WQHxtxx/VXHNfGfxrXIkDgXLzFrwfJ3MhMWAubdVbUro5mLc1UmRA6V64w27iJc cpnxUvtArD/Cn64WuNGR6vawIu5RUzrZJcnW2f6X+szEwjTpTHAg3etZq6kD2kFc1t3A E2MnROTWCJeiV1qB+eq7CowOsiK1xYmuSlPeqtLo5bE0DW1JCc2f2XyFlxKbBpxsAIgW 6ZdK5wJKHag5BwHI0OWaC4ZR2043Mp3DAQIfft5pArYJmWD/2NT/7/vVXm5xqCdsOC4+ 3DQxMWSUw1buXetY28ocxqL5zYxC5eneL03CIkhUs8MlRo1+oxt4Ng7WC+dQQ+mw1PDA DjiQ== 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 g7si1244474pfm.0.2018.02.28.05.46.42; Wed, 28 Feb 2018 05:46:58 -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 S1752712AbeB1NpC (ORCPT + 99 others); Wed, 28 Feb 2018 08:45:02 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35916 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752636AbeB1NoK (ORCPT ); Wed, 28 Feb 2018 08:44:10 -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 2D5E94040859; Wed, 28 Feb 2018 13:44:09 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BDF2946B5; Wed, 28 Feb 2018 13:44:07 +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 2/3] x86/kvm/hyper-v: remove stale entries from vec_bitmap/auto_eoi_bitmap on vector change Date: Wed, 28 Feb 2018 14:44:00 +0100 Message-Id: <20180228134401.6544-3-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.5]); Wed, 28 Feb 2018 13:44:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 28 Feb 2018 13:44:09 +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 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 --- 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