Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp224340pxb; Wed, 8 Sep 2021 22:42:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweBY9Mr62ROH4+6G4DBqjLU7lCayx9oWeCz5zomrFJdpjWiRjUUZQl+/6RcaNi0QHmlx5c X-Received: by 2002:a05:6402:14d6:: with SMTP id f22mr1377897edx.274.1631166123555; Wed, 08 Sep 2021 22:42:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631166123; cv=none; d=google.com; s=arc-20160816; b=HQWyIj4Lt0Y1KU7fg8tKonemuxnDf7oh3X+yEeRzjLuvYTcdQEu6y0aT2TptFdhEoJ FaX/FxILZMDxGISeH/pxSkA07F0mOnZbFpp0Bi5UeetTQCB+iIICIgPb4i343vwkDpia 0MR8vOgXf7zrTRVLyQNNb58HeS0p6OSk+d/Etk13LV7UWfdYfzDgdtki/8+tjXA8smhm LhieLqYe2de5xfhxluxnTaedvmBwwiOv/5iglsfY4RjPyevCsOxyJYCM0JSBE9ffQteV jvAw0pREp34dtXRQeYzGSfNNvbMcg37mrX7gc3AzBDevZvOVXhzneyEIbPQHwn4bIp7V 6kFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=BfCn6Kdj9U6+wyRq6rGqDZVU0uEjDmVJjKfyDttwqj4=; b=ju3BL0SVPNqrKdhD8IW4Tk5W7mf9G1K8G6EWVnlH9n/MHoW8vxfiJfV0jlBzXpUJOY BdldF5xN08NbHpEW9/dM7W3WlWw3ijE4aGAB+j1Zmp0fB+3I/4C1Y4BoYORHmwOlDmmo qKJR8bJh5HX73oq6eOArbEBT1wOwaabbR58/fkZXoMFA9sSa9bRu8XEI4TGvy0/RR5pF 7r9c6lro3efClbtIrfifalBKQJrR5JGlFMgMmLfBdyVgsvKcyfCtipsO+iwMNc51H2fd 0AE172OTlf/31pwbuB2ejem/o3ppTG2pAn1mK7tNieNVTYCbkpoRG1/K4RrA0ILQ41N/ sflA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VmTMOcDn; 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 h14si795581ejj.54.2021.09.08.22.41.14; Wed, 08 Sep 2021 22:42:03 -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=VmTMOcDn; 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 S1350785AbhIIFjs (ORCPT + 99 others); Thu, 9 Sep 2021 01:39:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30503 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348026AbhIIFjr (ORCPT ); Thu, 9 Sep 2021 01:39:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631165918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BfCn6Kdj9U6+wyRq6rGqDZVU0uEjDmVJjKfyDttwqj4=; b=VmTMOcDnTb7EW0iAI6E5i+0DLaA5qrr/M1gBc+zIpHxt19SCB6PsWUBolj/vVy5GQfMPfr dhdU0pcSZx34o7N8Tr9yElBssgcZjtpKF9rDZYQsnH1wEzf5vMutz0c2WKmPNeyzpWuq5m UbTuQ38rihJJjP6bOtjoEYOxrucOvwg= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-554-mqB8ukgFMvSSNBUt2gqKCg-1; Thu, 09 Sep 2021 01:38:37 -0400 X-MC-Unique: mqB8ukgFMvSSNBUt2gqKCg-1 Received: by mail-wm1-f72.google.com with SMTP id u1-20020a05600c210100b002e74fc5af71so326882wml.1 for ; Wed, 08 Sep 2021 22:38:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=BfCn6Kdj9U6+wyRq6rGqDZVU0uEjDmVJjKfyDttwqj4=; b=yflP6AS2MfgdNZzvPLcrrKYzTjm7AHMGfEUtrz4csXIOvIFEbUvdaSfeuDY39ASZF2 Hxh3VoUbF4oC8L9gJl74j0xIRLIE8pZgnReD+oPzVhWqNfCKTqhlOaBeBJIVyzS1m1b5 tbC/LnAkfEjgBs9tnxsC3iaQQhm+mrXoeroTq4w2NoTtzyFioXbOjbz3cX8xkACcvixp SqMT13TfP5ApJ4FbbUU9idrY0a7iz2e3XId0op8Z/zHfo5YdUer9eOJopU5DcetlpTQk c9lZgzIVrL+vM9pn9PMuX3emOiTWhfLozhI9xVOybvB74ZOf0uuIgDEJUzUfYc62NiCz +ReA== X-Gm-Message-State: AOAM533nO5pzBsefQnsEqLVb17ECVl0ngLN5unOzd2hhkJ32VT+eGtsx I8jHkzIWvexa0MEvkFER1BQsBrm6G6CIPK6GVeehyG/vzEeHfqiDeiMM2nM9jRO2wczi6UJoGRd eFnaJQdFA34a7fodQg536M3ZyFNNNYecy3vAfd6i6llRgN5vCyc3Rsd+nTa6p7vl9yeEW6SSxKk 5h X-Received: by 2002:a05:600c:4ece:: with SMTP id g14mr949965wmq.6.1631165915902; Wed, 08 Sep 2021 22:38:35 -0700 (PDT) X-Received: by 2002:a05:600c:4ece:: with SMTP id g14mr949943wmq.6.1631165915665; Wed, 08 Sep 2021 22:38:35 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id t14sm650634wrw.59.2021.09.08.22.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 22:38:35 -0700 (PDT) From: Vitaly Kuznetsov To: Wei Liu , Linux on Hyper-V List Cc: Michael Kelley , kys@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com, sthemmin@microsoft.com, Wei Liu , Arnd Bergmann , "open list:GENERIC INCLUDE/ASM HEADER FILES" , open list Subject: Re: [PATCH 1/2] asm-generic/hyperv: provide cpumask_to_vpset_noself In-Reply-To: <20210908194243.238523-2-wei.liu@kernel.org> References: <20210908194243.238523-1-wei.liu@kernel.org> <20210908194243.238523-2-wei.liu@kernel.org> Date: Thu, 09 Sep 2021 07:38:28 +0200 Message-ID: <871r5y48bv.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wei Liu writes: > This is a new variant which removes `self' cpu from the vpset. It will > be used in Hyper-V enlightened IPI code. > > Signed-off-by: Wei Liu > --- > Provide a new variant instead of adding a new parameter because it makes > it easier to backport -- we don't need to fix the users of > cpumask_to_vpset. > --- > include/asm-generic/mshyperv.h | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h > index 9a000ba2bb75..d89690ee95aa 100644 > --- a/include/asm-generic/mshyperv.h > +++ b/include/asm-generic/mshyperv.h > @@ -184,10 +184,12 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number) > return hv_vp_index[cpu_number]; > } > > -static inline int cpumask_to_vpset(struct hv_vpset *vpset, > - const struct cpumask *cpus) > +static inline int cpumask_to_vpset_ex(struct hv_vpset *vpset, I'd suggest to avoid '_ex' suffix as we use it for 'extended hypercalls' (e.g. __send_ipi_mask_ex). Assuming nobody needs to call cpumask_to_vpset_ex() directly, should we just go with __cpumask_to_vpset() instead? > + const struct cpumask *cpus, > + bool exclude_self) > { > int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank = 1; > + int this_cpu = smp_processor_id(); > > /* valid_bank_mask can represent up to 64 banks */ > if (hv_max_vp_index / 64 >= 64) > @@ -205,6 +207,8 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset, > * Some banks may end up being empty but this is acceptable. > */ > for_each_cpu(cpu, cpus) { > + if (exclude_self && cpu == this_cpu) > + continue; > vcpu = hv_cpu_number_to_vp_number(cpu); > if (vcpu == VP_INVAL) > return -1; > @@ -219,6 +223,18 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset, > return nr_bank; > } > > +static inline int cpumask_to_vpset(struct hv_vpset *vpset, > + const struct cpumask *cpus) > +{ > + return cpumask_to_vpset_ex(vpset, cpus, false); > +} > + > +static inline int cpumask_to_vpset_noself(struct hv_vpset *vpset, > + const struct cpumask *cpus) > +{ > + return cpumask_to_vpset_ex(vpset, cpus, true); We need to make sure this is called with preemption disabled. We could've just swapped smp_processor_id() for get_cpu() in cpumask_to_vpset_ex() but this is hardly a solution: we can get preempted right after put_cpu() so it's really the caller of this function which needs to be protected. TL;DR: I suggest we add 'WARN_ON_ONCE(preemptible());' or something like this here to catch wrong usage. > +} > + > void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die); > bool hv_is_hyperv_initialized(void); > bool hv_is_hibernation_supported(void); -- Vitaly