From patchwork Fri Nov 11 13:56:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 18805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp756809wru; Fri, 11 Nov 2022 06:03:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Rfn2xLLLBsE3+7ADLc3zxohr4w72A2/1HEtMgY999y/5fbkqYP2HFiUffhh7KrEzi+AAO X-Received: by 2002:a63:5465:0:b0:46f:f2f6:b06 with SMTP id e37-20020a635465000000b0046ff2f60b06mr1797443pgm.376.1668175425879; Fri, 11 Nov 2022 06:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668175425; cv=none; d=google.com; s=arc-20160816; b=MEuC+DMeG0LU9wDa6mikDMZoWQ5t/5UuPaUwI6NLUhXPLr3RsV8QldsgacCeW4hde/ iIC0ewwa3LIn3JEG5BKItEPTDLYP06TNA8FA/SfD7WcJYYaFI9RkY20u7MdM3CocTqvP 5Wk4PnjQAAKi8SMl96ggfgyqEHUzfOXRdRQ2IYWZnDC6fl9TYs2i7pXHVGJic8wk5tCx Zm8wgqDsAyNNp/hrH762QkfSYzLNFlloerjIy/rouoxTSYkxZc+Wxbo/zTSMOSSK4eRx HJfB6KpH5L72concKW7/UhRRQhHD0UN/07T5NlczXkNbrGX+IlON380IWJWmN+sFRDoF M2XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=+dAWZkN6cGNqJWgbyj9Oq+MbyBZuRhS/MrnxspMqy9E=; b=YV7Rr1fk1mTEmKpuNhEids2yfkFfsxQ4sM+OdZC3GdLAaEw9mV/r4yVpQlAs9wvfoB vW2t8Z+7N0ztpnXXJs9IPNJrZT57QBF75gnnrTj/qxhTg5JXcO+FQWcBvJLk0VJhJ6Hx pTvkH8rLcfADiTUMy3mw7roqmXjdg9hLdt6913/qHRI0KUs5ZAcGW1P92VpJihbc4XlZ 0D1xC/j+wb0ElgIKrcqvAPVImC86XrkvbQ97hyLKqdYZ+oDv19V98Ybe5N+PEYCWXNmj Ripu50zXhkbaFU09Wa2p7Vtz7qVw5VNQGOJicrk/ZjgcxUniZy7l5oyDk1Gf9BmBhzVM WpdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=v1PtI44g; dkim=neutral (no key) header.i=@linutronix.de; 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 t203-20020a635fd4000000b0044601bb2f96si2483118pgb.221.2022.11.11.06.02.59; Fri, 11 Nov 2022 06:03:45 -0800 (PST) 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=v1PtI44g; dkim=neutral (no key) header.i=@linutronix.de; 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 S234050AbiKKOBP (ORCPT + 99 others); Fri, 11 Nov 2022 09:01:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234049AbiKKOAf (ORCPT ); Fri, 11 Nov 2022 09:00:35 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC2F8D7ED; Fri, 11 Nov 2022 05:56:48 -0800 (PST) Message-ID: <20221111132706.388892782@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668175007; 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: references:references; bh=+dAWZkN6cGNqJWgbyj9Oq+MbyBZuRhS/MrnxspMqy9E=; b=v1PtI44g/Am1qxyq/3b/TdkupIjQY/gl40s7ApESbrvv3cabUzkAHZp05hF9W8FAV9F5hi TV6cYF44shMIAfq2CjPKvZ9+Pjwp0Io/AXIalqCz+iXrqAbTNpzskxa2Q9O69cy3dSn+oe NWWwWqHUeSKNwojTyq8r0/fGYUtWJfNIjmIzMZ5lw+N4IA/iqTZ9h5RbMVpDc9D7wgjQV2 mf43Xq8KvSl3iC+x89XCKH9pf5GoxjLEQ7KXwM0xoOEtTCyCIQNUG1Wp4Ctc4/5Z6KMCcx zQuLN3Mi72N5o/tU7l0Nh1H4ED+cNSw3WAnyexd6nDQDj+1hPM3rc13e12+2Ng== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668175007; 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: references:references; bh=+dAWZkN6cGNqJWgbyj9Oq+MbyBZuRhS/MrnxspMqy9E=; b=Y/gXDXsYJF6Sa5UVN981gmV3cjImDqIc0W/tEeW5iVObyX3LNvGJBgS91vBPGFLMIwAEXH 5JI1s/z7pzJ2nfDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Joerg Roedel , Will Deacon , linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Marc Zyngier , Greg Kroah-Hartman , Jason Gunthorpe , Dave Jiang , Alex Williamson , Kevin Tian , Dan Williams , Logan Gunthorpe , Ashok Raj , Jon Mason , Allen Hubbe , "Ahmed S. Darwish" , Reinette Chatre Subject: [patch 06/20] genirq/msi: Check for invalid MSI parent domain usage References: <20221111131813.914374272@linutronix.de> MIME-Version: 1.0 Date: Fri, 11 Nov 2022 14:56:46 +0100 (CET) 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 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?1749208715255940915?= X-GMAIL-MSGID: =?utf-8?q?1749208715255940915?= In the upcoming per device MSI domain concept the MSI parent domains are not allowed to be used as regular MSI domains where the MSI allocation/free operations are applicable. Add appropriate checks. Signed-off-by: Thomas Gleixner --- kernel/irq/msi.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -937,13 +937,21 @@ int msi_domain_alloc_irqs_descs_locked(s lockdep_assert_held(&dev->msi.data->mutex); + if (WARN_ON_ONCE(irq_domain_is_msi_parent(domain))) { + ret = -EINVAL; + goto free; + } + + /* Frees allocated descriptors in case of failure. */ ret = msi_domain_add_simple_msi_descs(info, dev, nvec); if (ret) return ret; ret = ops->domain_alloc_irqs(domain, dev, nvec); - if (ret) - msi_domain_free_irqs_descs_locked(domain, dev); + if (!ret) + return 0; +free: + msi_domain_free_irqs_descs_locked(domain, dev); return ret; } @@ -1013,6 +1021,9 @@ void msi_domain_free_irqs_descs_locked(s lockdep_assert_held(&dev->msi.data->mutex); + if (WARN_ON_ONCE(irq_domain_is_msi_parent(domain))) + return; + ops->domain_free_irqs(domain, dev); if (ops->msi_post_free) ops->msi_post_free(domain, dev);