Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5059838rwl; Mon, 10 Apr 2023 23:10:31 -0700 (PDT) X-Google-Smtp-Source: AKy350bei9bplKreHbADdW0XEMkYItQhC/YXraOGn1vKfuv7AW+Bpy8pnywKu5BI44LTwrpvrfJt X-Received: by 2002:a17:90b:3ec2:b0:246:82f9:9b0a with SMTP id rm2-20020a17090b3ec200b0024682f99b0amr2487125pjb.3.1681193431090; Mon, 10 Apr 2023 23:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681193431; cv=none; d=google.com; s=arc-20160816; b=nPhcP5+zfKgNaWrU1NSwz06Ws6RVevRZeT7EWaiCdunNJTEfmTkZnXUj4bczsNUcJL 13vQQc3EKKkrZkgE+nEhYL/oXREEFRzosVe2cT+5IUY0TKoMUcttt04Oc8YvzzCDDkRX 9i3lb963AGKbmJtU3SkBWYA33agR5rYFfBpgCwv21r7FVcm4EXOJPhNqReP+ZjMnk9Px HMOo+WfdEdqo0OryTOcHEkbuOGbv3jiuWTxYFQZs8X8+sr7gB3G6Z6lP3vziEKv4vYz8 aqThCiUrNs2WWNLAJEoz1J9DcvdoKtUu4P9RsWtKLi++motrnxbJtryx/oixKcjOpNcM Sl9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:to:from:date :dkim-signature:dkim-filter; bh=0vqxaTyHjkm2ePh3n+RG3jF8MQwkysGYAZtESJuLKW0=; b=iBB3Yr1gJysCCaMuq143E9JOUZU0UxZv09CdH0Oo41fWQ/555NKDUcK3VgIiYGw+fW IWE7I0nzEaYEMcdd2CnrZJ2uY7/vNqsMi3X6sSXkizuWmH7V/5CvnOAwQBuz9FoX/lz9 DAfXGK3dYdvjUiPs0C0zrR8U0X7pwwgt3tFtxwp0BLTzHt7EQ5p7Tl2EknpovX01uBE4 VsX1+A2v4YqxrQRj+9UFQplJIFH3WTYmQgkOJ1fqQDe37Z32EuWCrNqHcWmdYJuWaDTH pkKIC9ihlAdKFaETGx5VcoJEXQFEKes301or46mPUPJWCPhzIP4t29E018Y4dM5IC6Ms qAWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=IYcIbOqO; 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 il6-20020a17090b164600b00233e301c780si16553432pjb.31.2023.04.10.23.10.19; Mon, 10 Apr 2023 23:10:31 -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=IYcIbOqO; 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 S230137AbjDKGJ5 (ORCPT + 99 others); Tue, 11 Apr 2023 02:09:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230132AbjDKGJx (ORCPT ); Tue, 11 Apr 2023 02:09:53 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8FDB01704 for ; Mon, 10 Apr 2023 23:09:46 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1127) id 1A4912174E4C; Mon, 10 Apr 2023 23:09:46 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1A4912174E4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1681193386; bh=0vqxaTyHjkm2ePh3n+RG3jF8MQwkysGYAZtESJuLKW0=; h=Date:From:To:Subject:References:In-Reply-To:From; b=IYcIbOqOFJ3n70KmQHreJKEVQjeBtnDRM+Ut8PHLIDfEfK/JBBgATGZf1gIlngrf9 LfTjWnEDEbQTmTJUlZD295SHeYlmo6rSg9WtzHOcukIhiRgd1iTxn6Vw37QDojcvAW j7yRS9WLoHpBcp8ZUed9ogdZYXe+LMAfMwtlRhLM= Date: Mon, 10 Apr 2023 23:09:46 -0700 From: Saurabh Singh Sengar To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, johan+linaro@kernel.org, isaku.yamahata@intel.com, mikelley@microsoft.com, linux-kernel@vger.kernel.org, andriy.shevchenko@intel.com Subject: Re: [PATCH v2] x86/ioapic: Don't return 0 from arch_dynirq_lower_bound() Message-ID: <20230411060946.GA17134@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1679988604-20308-1-git-send-email-ssengar@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1679988604-20308-1-git-send-email-ssengar@linux.microsoft.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-17.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Tue, Mar 28, 2023 at 12:30:04AM -0700, Saurabh Sengar wrote: > arch_dynirq_lower_bound() is invoked by the core interrupt code to > retrieve the lowest possible Linux interrupt number for dynamically > allocated interrupts like MSI. > > The x86 implementation uses this to exclude the IO/APIC GSI space. > This works correctly as long as there is an IO/APIC registered, but > returns 0 if not. This has been observed in VMs where the BIOS does > not advertise an IO/APIC. > > 0 is an invalid interrupt number except for the legacy timer interrupt > on x86. The return value is unchecked in the core code, so it ends up > to allocate interrupt number 0 which is subsequently considered to be > invalid by the caller, e.g. the MSI allocation code. > > The function has already a check for 0 in the case that an IO/APIC is > registered, but ioapic_dynirq_base is 0 in case of device tree setups. > > Consolidate this and zero check for both ioapic_dynirq_base and gsi_top, > which is used in the case that no IO/APIC is registered. > > Fixes: 3e5bedc2c258 ("x86/apic: Fix arch_dynirq_lower_bound() bug for DT enabled machines") > Co-developed-by: Thomas Gleixner > Signed-off-by: Thomas Gleixner > Signed-off-by: Saurabh Sengar > Cc: Andy Shevchenko > Cc: Thomas Gleixner > --- > [V2] > - Edit commit message > - Consolidated the 0 check for ioapic_dynirq_base as well > > arch/x86/kernel/apic/io_apic.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c > index 1f83b052bb74..f980b38b0227 100644 > --- a/arch/x86/kernel/apic/io_apic.c > +++ b/arch/x86/kernel/apic/io_apic.c > @@ -2477,17 +2477,21 @@ static int io_apic_get_redir_entries(int ioapic) > > unsigned int arch_dynirq_lower_bound(unsigned int from) > { > + unsigned int ret; > + > /* > * dmar_alloc_hwirq() may be called before setup_IO_APIC(), so use > * gsi_top if ioapic_dynirq_base hasn't been initialized yet. > */ > - if (!ioapic_initialized) > - return gsi_top; > + ret = ioapic_dynirq_base ? : gsi_top; > + > /* > - * For DT enabled machines ioapic_dynirq_base is irrelevant and not > - * updated. So simply return @from if ioapic_dynirq_base == 0. > + * For DT enabled machines ioapic_dynirq_base is irrelevant and > + * always 0. gsi_top can be 0 if there is no IO/APIC registered. > + * 0 is an invalid interrupt number for dynamic allocations. Return > + * @from instead. > */ > - return ioapic_dynirq_base ? : from; > + return ret ? : from; > } > > #ifdef CONFIG_X86_32 Is this good to get accepted ? Please let me know if anything pending from my end on this. - Saurabh > -- > 2.34.1