Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp323070pxb; Wed, 6 Oct 2021 05:52:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW21eOau8ySrqkM88WKMyWk30ZuUpWeMZMuvRBC15zPEynaE+IoSgqtBWqL/4osgIUoG91 X-Received: by 2002:a17:902:e544:b0:13e:e863:6cd2 with SMTP id n4-20020a170902e54400b0013ee8636cd2mr7706552plf.41.1633524754755; Wed, 06 Oct 2021 05:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633524754; cv=none; d=google.com; s=arc-20160816; b=aj3mtOmUdRxZLzX42EvmImmdA9366hfevYQ6lPIQU+aKxSWhiiPyhucq8T8mGK30qs 02G0xJ7eoqizH8OXAWu9j5q8I9iQ9o4Tr62gaMVVRFQY8luvCDoMtyhffcYeIfU5HQsz epSOF5iHzPT96/fHvK3CenqpYbQdoCfiEWOfZUCZYMES27TSrtr4XUAOSS1EO6jfjRum +3e4d0f5Wgx7JeM3IgIr3FvXV5NAEucUhmzfvFL6CWEN+iGonsjALrXVFQknDxQxbEVW 96JM9PbGgHnsXfPtADyClJ4QFtNGR6AkcM8W54wZJY27kJNeeYZ031k9vq1VyXLwJOQ/ /Hkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=yEd1nl5sTg+RWty43ssaYveHIjPOLpFS5qrgx7WwBNw=; b=Aot1L8wX0KmrRZdORvmFgilBs069WiS818zMmc2Y2k+og+o1Xg0NR4F+vtQ2rvyn8c tlb0griwYnRAaJUY6t3EP6jvfNonoE3rq38H3GhIDp88JcU38MSyWGoWpjqSwcyQDjsT JRGE07cKL2FZeuUVvHwCyUTp3WS9R5Si0SD3pe5cUpvU54vHIi6uXBDzwRafezVxflHf RF0N7ePaJ6UyHyh53XbJMedJtnbU1wzh/YVk+GTuGJlt0sW2Q1o6Y+tpPmvoioXHwOJw bVV3UZnnnOv8wE209j9JEKYGsSm6ZB9haEsUybqnDwEaeayl4sftUMgnmghvuGYJXjpf JUFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cjKPn005; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si5295778pjd.99.2021.10.06.05.52.19; Wed, 06 Oct 2021 05:52:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cjKPn005; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238488AbhJFMwR (ORCPT + 99 others); Wed, 6 Oct 2021 08:52:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46946 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbhJFMwQ (ORCPT ); Wed, 6 Oct 2021 08:52:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633524624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yEd1nl5sTg+RWty43ssaYveHIjPOLpFS5qrgx7WwBNw=; b=cjKPn005VtOHy6Tskl/U9kjV0aUJQomLr2pKwq63Y1Hm7JePSkKAaCHVhB1MgQAEa6ul// xuUGJG1B7ustoAKbJ8kGROs+awDJsjlzhnyvpjz0zS9MF8JBHqYWDqpj8Q3niGFIkjDUjF ubvv+bXc/qn5UDgfimEz/3LQKofL6qE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-OEvNXBC1Od2Atfgtea_O8g-1; Wed, 06 Oct 2021 08:50:23 -0400 X-MC-Unique: OEvNXBC1Od2Atfgtea_O8g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F7701007908; Wed, 6 Oct 2021 12:50:21 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6AFE60657; Wed, 6 Oct 2021 12:50:17 +0000 (UTC) From: Vitaly Kuznetsov To: linux-hyperv@vger.kernel.org, Wei Liu Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Michael Kelley , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Dexuan Cui Subject: [PATCH] x86/hyperv: Avoid erroneously sending IPI to 'self' Date: Wed, 6 Oct 2021 14:50:16 +0200 Message-Id: <20211006125016.941616-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __send_ipi_mask_ex() uses an optimization: when the target CPU mask is equal to 'cpu_present_mask' it uses 'HV_GENERIC_SET_ALL' format to avoid converting the specified cpumask to VP_SET. This case was overlooked when 'exclude_self' parameter was added. As the result, a spurious IPI to 'self' can be send. Reported-by: Thomas Gleixner Fixes: dfb5c1e12c28 ("x86/hyperv: remove on-stack cpumask from hv_send_ipi_mask_allbutself") Signed-off-by: Vitaly Kuznetsov --- arch/x86/hyperv/hv_apic.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c index 32a1ad356c18..db2d92fb44da 100644 --- a/arch/x86/hyperv/hv_apic.c +++ b/arch/x86/hyperv/hv_apic.c @@ -122,17 +122,27 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector, ipi_arg->reserved = 0; ipi_arg->vp_set.valid_bank_mask = 0; - if (!cpumask_equal(mask, cpu_present_mask)) { + /* + * Use HV_GENERIC_SET_ALL and avoid converting cpumask to VP_SET + * when the IPI is sent to all currently present CPUs. + */ + if (!cpumask_equal(mask, cpu_present_mask) || exclude_self) { ipi_arg->vp_set.format = HV_GENERIC_SET_SPARSE_4K; if (exclude_self) nr_bank = cpumask_to_vpset_noself(&(ipi_arg->vp_set), mask); else nr_bank = cpumask_to_vpset(&(ipi_arg->vp_set), mask); - } - if (nr_bank < 0) - goto ipi_mask_ex_done; - if (!nr_bank) + + /* + * 'nr_bank <= 0' means some CPUs in cpumask can't be + * represented in VP_SET. Return an error and fall back to + * native (architectural) method of sending IPIs. + */ + if (nr_bank <= 0) + goto ipi_mask_ex_done; + } else { ipi_arg->vp_set.format = HV_GENERIC_SET_ALL; + } status = hv_do_rep_hypercall(HVCALL_SEND_IPI_EX, 0, nr_bank, ipi_arg, NULL); -- 2.31.1