From patchwork Wed Apr 12 15:55:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 82552 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp444411vqo; Wed, 12 Apr 2023 09:12:52 -0700 (PDT) X-Google-Smtp-Source: AKy350adyqU/q+Ay1zyw2p1teMRp07x9h5HTltErWBN8ccnth3YnS+J8pmhbW6cSPTR5rYWZKRjq X-Received: by 2002:a17:906:6a0d:b0:94e:7f0d:2964 with SMTP id qw13-20020a1709066a0d00b0094e7f0d2964mr1212835ejc.64.1681315971951; Wed, 12 Apr 2023 09:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681315971; cv=none; d=google.com; s=arc-20160816; b=hnSDmFjOz8sfqtQz0l7pfW1oEHkMSAwPQNI/hFqXzqrFvPgaf/qEAyPIg6i5zxcrEH yP0elklCLQuut/beb7MJlb2nkSp9+im3O91rEi+ZWKKbizH1OABO+Ql7C0LwKZMqIAHo 2Asds8QPzlPCobdWS/z6nkh1SUsR+2OnfVl/d/RMQVg32FrExrIV+OYKFJrnhQcZitPd IAfmP25OV6/AEhs0a5SVz/LOQdDHXUYPw7KYSmqz+piaGDegSnaJVn9dM3O5adANLamo HIDwHQk7seQowpevS5S1UXU8QEP4XVgLFvRIgGDvasAxs4ohQv+k98JETTmdSQ67RiqH mTQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=gyJPOKJL8+7PQlCso7HQtQzxVvaJLCpeyOybz5yLnSM=; b=kT/efY3ZdSj4+HDnIzv1K/Ho6lBAUMgUboB6Sjt+PuYn8zmqgV4ojc3ByPie+wRF/E W9CUX4ivdpm3oqXltQKYo6sTkeC/BvrarL+yDqDqKEh3TRn+ZqxzLCBonU7SvGJWNA4k +BACglFBJQMtjlM85pytwG8fSgta1ddf+NVkFxuknfPYk3tHgSyrIkg23lCvsnELBz0V kRpGf0bzf1+6rLM8iztDq43sGdD8wfJQFn6b3yJOZ+IWHQzjFmp8ac/KMh9WfKn/YL9z OQWH5vzAzpRtbHB2eXsckxm1ZOSAvIA3/+9Mw9I/Vg/fiaDRVGljd4is3MRQKjzBqFjA PbfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lwj7Gv9H; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd7-20020a1709069b8700b009334f7bc132si1317812ejc.947.2023.04.12.09.12.26; Wed, 12 Apr 2023 09:12:51 -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=@linutronix.de header.s=2020 header.b=lwj7Gv9H; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbjDLPzy (ORCPT + 99 others); Wed, 12 Apr 2023 11:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbjDLPzw (ORCPT ); Wed, 12 Apr 2023 11:55:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A66FB40FB; Wed, 12 Apr 2023 08:55:51 -0700 (PDT) Date: Wed, 12 Apr 2023 15:55:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1681314950; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gyJPOKJL8+7PQlCso7HQtQzxVvaJLCpeyOybz5yLnSM=; b=lwj7Gv9H1KVkoBLmvX/XSgDZwo1kHBkjV9cqV8VFW8qDK0eAg0ZI+eeO1eHCegSO++XkQt DinfwyY60QU6zaYyJAdcjlEjTYF1n4vaijWll3nglLgPb+bsQZCfro61bK+Nd1nRmBKLX1 P5Vfab6H9db+4q8J+MfpzluVDEe5gt94e9yeqP+1x56Eg/+PEfaxBFA9dGZZyO1HrgN0F5 oVxLO4S/kbfN0/fV3dHv8CQbczFJG+aVZQgDD1M51g/LIfDO+2i9z2mgAUfomPD0RdUgpv hqtl3UTJHWsU6uszjJuskHFlQA5Vhjf7XPD8Zja4XlwIFZihQ8tlhDZdB1HC9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1681314950; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gyJPOKJL8+7PQlCso7HQtQzxVvaJLCpeyOybz5yLnSM=; b=xAgSbDNPxDPg3ceO3tXHmodpHf/GIqE5R/zPTpdyYe9Y/YasA5gUz8xAbleHa6+hOrfO42 r458FjoyPI8f2QCw== From: "tip-bot2 for Saurabh Sengar" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/apic] x86/ioapic: Don't return 0 from arch_dynirq_lower_bound() Cc: Saurabh Sengar , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <1679988604-20308-1-git-send-email-ssengar@linux.microsoft.com> References: <1679988604-20308-1-git-send-email-ssengar@linux.microsoft.com> MIME-Version: 1.0 Message-ID: <168131494872.404.16905626584604172948.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761597175226327041?= X-GMAIL-MSGID: =?utf-8?q?1762987576398457574?= The following commit has been merged into the x86/apic branch of tip: Commit-ID: 5af507bef93c09a94fb8f058213b489178f4cbe5 Gitweb: https://git.kernel.org/tip/5af507bef93c09a94fb8f058213b489178f4cbe5 Author: Saurabh Sengar AuthorDate: Tue, 28 Mar 2023 00:30:04 -07:00 Committer: Thomas Gleixner CommitterDate: Wed, 12 Apr 2023 17:45:50 +02:00 x86/ioapic: Don't return 0 from arch_dynirq_lower_bound() 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, as 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") Signed-off-by: Saurabh Sengar Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/1679988604-20308-1-git-send-email-ssengar@linux.microsoft.com --- 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 1f83b05..f980b38 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