Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp906057rwe; Fri, 14 Apr 2023 11:13:43 -0700 (PDT) X-Google-Smtp-Source: AKy350ZpNWh9kRQdK2cn+sg2ZinEe0RpgNzIcdcfOVRjNCx0tnZ3rvS53ViZddCPm6poGs65jItj X-Received: by 2002:a05:6a00:2da2:b0:628:87f:6b5d with SMTP id fb34-20020a056a002da200b00628087f6b5dmr9696911pfb.11.1681496023245; Fri, 14 Apr 2023 11:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681496023; cv=none; d=google.com; s=arc-20160816; b=bbNxOZArLhwjnnpHOY5IB68/Ur1oecBSXygJnqM+jxb36J4Ld8h72a1gz+VgcbhYdX gkt71DB30XtRV7exwoDItJ9jBprqL30CyGhbWIIBMqjA3HlWiqwg4Sc0Nar6UhT3pMvj 0hpAg14OLaB8WVGxJJJcPznrUpufqOc9i2gzavI15xvGFxWZiDawH3aoaKUohIHWPDR4 xo/72K2IJU4i/3W69trfj1uawPdBOF9HEhNed60oMUdnc8pMnIsUvkPBVXpMelRMBpYd ufJxSSlhvQciqZal1aW3Vr/hIZHIqUvVy71bZvS8DbHZ6LHkapZu7lEgr1Rp9cXnTVd2 LQEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-filter; bh=vrTl5Ep5devbVecjQ6jAI5gZaBXZaMXlbw5ZKByZUZ8=; b=TwTZxbDGMShZ6y2vwRmgwGyD8gsQzazyJXBVclAyCnkHPxuffzS2sEB8We1B0auW5F kJpmcQI3hwtEaIALe/W1XGMrc7UjrFUpWMKk8UEFW/0uOaGoeYtzfSHQfHR2WUME6Fe7 vq3xN5bfIqjss3QfRCgqdSCguEUjxXm5GHj+th3PPbxVA05xJn2tPolXu5jhfm24mlyz iF+kBugDHJW/bqpQP75HnZ65IIs4xXYcE4RCpL8z/qHEzgkIsO9hO3Lvke8xVHeOEHdL E74LumpV9hPYV8Td6mV68l5Q4HvDmSpGtdOnizU8CFNfYwhrADik/gnIpM/0xKUqxGDF 0gxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=OLR94xfw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x18-20020aa79412000000b0063b1d0f2b51si4879357pfo.163.2023.04.14.11.13.31; Fri, 14 Apr 2023 11:13:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=OLR94xfw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbjDNSHs (ORCPT + 99 others); Fri, 14 Apr 2023 14:07:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjDNSHp (ORCPT ); Fri, 14 Apr 2023 14:07:45 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 020DE83CB; Fri, 14 Apr 2023 11:07:43 -0700 (PDT) Received: from skinsburskii.localdomain (c-67-170-100-148.hsd1.wa.comcast.net [67.170.100.148]) by linux.microsoft.com (Postfix) with ESMTPSA id 202C42179263; Fri, 14 Apr 2023 11:07:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 202C42179263 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1681495663; bh=vrTl5Ep5devbVecjQ6jAI5gZaBXZaMXlbw5ZKByZUZ8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OLR94xfw4mfXwonzEA8XTEXGARFL/FomL1UtMFLtChA6mRBwBbI7M2wqo5Hn35QmD qgdYXzkWrT/+m9wWm/fA6EZoFvX6zxOuenxKDip0xvOzdZjW+D3T7KlQvRITLnZecY NHBohp/XeamzyyXQ/vSteUenpSDBNAWyudrT5nL4= Date: Wed, 12 Apr 2023 13:31:38 -0700 From: Stanislav Kinsburskii To: Thomas Gleixner Cc: Stanislav Kinsburskii , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] x86/hyperv: Expose an helper to map PCI interrupts Message-ID: <20230412203138.GA1782@skinsburskii.localdomain> References: <168079806973.14175.17999267023207421381.stgit@skinsburskii.localdomain> <168079870998.14175.16015623662679754647.stgit@skinsburskii.localdomain> <87o7nrzy9e.ffs@tglx> <20230412161951.GA894@skinsburskii.localdomain> <20230412163616.GA1535@skinsburskii.localdomain> <878reuzzuz.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878reuzzuz.ffs@tglx> X-Spam-Status: No, score=-18.5 required=5.0 tests=BAYES_00,DATE_IN_PAST_24_48, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 14, 2023 at 09:28:52AM +0200, Thomas Gleixner wrote: > Stanislav! > > On Wed, Apr 12 2023 at 09:36, Stanislav Kinsburskii wrote: > > On Wed, Apr 12, 2023 at 09:19:51AM -0700, Stanislav Kinsburskii wrote: > >> > > + affinity = irq_data_get_effective_affinity_mask(data); > >> > > + cpu = cpumask_first_and(affinity, cpu_online_mask); > >> > > >> > The effective affinity mask of MSI interrupts consists only of online > >> > CPUs, to be accurate: it has exactly one online CPU set. > >> > > >> > But even if it would have only offline CPUs then the result would be: > >> > > >> > cpu = nr_cpu_ids > >> > > >> > which is definitely invalid. While a disabled vector targeted to an > >> > offline CPU is not necessarily invalid. > > > > Although this patch only tosses the code and doens't make any functional > > changes, I guess if the fix for the used cpu id is required, it has to > > be in a separated patch. > > Correct, but if the interrupt _is_ masked at the MSI level then the > hypervisor must not deliver an interrupt at all. > > The point is that it is valid to target a masked MSI entry to an offline > CPU under the assumption that the hardware/emulation respects the > masking. Whether that's a good idea or not is a different question. > > The kernel as of today does not do that. It targets unused but > configured MSI[-x] entries towards MANAGED_IRQ_SHUTDOWN_VECTOR on CPU0 > for various reasons, one of them being paranoia. > > But in principle there is nothing wrong with that and it should either > succeed or being rejected at the software level and not expose a > completely invalid CPU number to the hypercall in the first place. > > So if you want to be defensive, then keep the _and(), but then check the > result for being valid and emit something useful like a pr_warn_once() > instead of blindly handing the invalid result to the hypercall and then > have that reject it with some undecipherable error code. > > Actually it would not necessarily reach the hypercall because before > that it dereferences cpumask_of(nr_cpu_ids) here: > > nr_bank = cpumask_to_vpset(&(intr_desc->target.vp_set), cpumask_of(cpu)); > > and explode with a kernel pagefault. If not it will read some random > adjacent data and try to create a vp_set from it. Neither of that is > anywhere close to correct. > Thank you Thomas. I sent a patch to address the problmes you highlighted: "x86/hyperv: Fix IRQ effective cpu discovery for the interrupts unmasking" I'll update this series after that patch is merged. Thanks, Stanislav > Thanks, > > tglx