From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6C3AC4361B for ; Fri, 18 Dec 2020 17:39:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA2A523B54 for ; Fri, 18 Dec 2020 17:39:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732760AbgLRRjf (ORCPT ); Fri, 18 Dec 2020 12:39:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:40818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726242AbgLRRje (ORCPT ); Fri, 18 Dec 2020 12:39:34 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43D7B239EE; Fri, 18 Dec 2020 17:38:53 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kqJiN-002LOd-7s; Fri, 18 Dec 2020 17:38:51 +0000 Date: Fri, 18 Dec 2020 17:38:50 +0000 Message-ID: <87v9czqaj9.wl-maz@kernel.org> From: Marc Zyngier To: Zenghui Yu Cc: , , , , Subject: Re: [PATCH] genirq/msi: Initialize msi_alloc_info to zero for msi_prepare API In-Reply-To: <20201218060039.1770-1-yuzenghui@huawei.com> References: <20201218060039.1770-1-yuzenghui@huawei.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: yuzenghui@huawei.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tglx@linutronix.de, kvm@vger.kernel.org, wanghaibin.wang@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Zenghui, On Fri, 18 Dec 2020 06:00:39 +0000, Zenghui Yu wrote: > > Since commit 5fe71d271df8 ("irqchip/gic-v3-its: Tag ITS device as shared if > allocating for a proxy device"), some of the devices are wrongly marked as > "shared" by the ITS driver on systems equipped with the ITS(es). The > problem is that the @info->flags may not be initialized anywhere and we end > up looking at random bits on the stack. That's obviously not good. > > The straightforward fix is to properly initialize msi_alloc_info inside the > .prepare callback of affected MSI domains (its-pci-msi, its-platform-msi, > etc). We can also perform the initialization in IRQ core layer for > msi_domain_prepare_irqs() API and it looks much neater to me. > > Signed-off-by: Zenghui Yu > --- > > This was noticed when I was playing with the assigned devices on arm64 and > VFIO failed to enable MSI-X vectors for almost all VFs (CCed kvm list in > case others will hit the same issue). It turned out that these VFs are > marked as "shared" by mistake and have trouble with the following sequence: > > pci_alloc_irq_vectors(pdev, 1, 1, flag); > pci_free_irq_vectors(pdev); > pci_alloc_irq_vectors(pdev, 1, 2, flag); --> we can only get > *one* vector > > But besides VFIO, I guess there are already some devices get into trouble > at probe time and can't work properly. > > kernel/irq/msi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c > index 2c0c4d6d0f83..dc0e2d7fbdfd 100644 > --- a/kernel/irq/msi.c > +++ b/kernel/irq/msi.c > @@ -402,7 +402,7 @@ int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, > struct msi_domain_ops *ops = info->ops; > struct irq_data *irq_data; > struct msi_desc *desc; > - msi_alloc_info_t arg; > + msi_alloc_info_t arg = { }; > int i, ret, virq; > bool can_reserve; Thanks for having investigated this. I guess my only worry with this is that msi_alloc_info_t is a pretty large structure on x86, and zeroing it isn't totally free. But this definitely looks nicer than some of the alternatives (.prepare isn't a good option, as we do rely on the flag being set in __platform_msi_create_device_domain(), which calls itself .prepare). I'll queue it, and we can always revisit this later if Thomas (or anyone else) has a better idea. Thanks, M. -- Without deviation from the norm, progress is not possible. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42FC4C4361B for ; Fri, 18 Dec 2020 18:05:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C785123B6C for ; Fri, 18 Dec 2020 18:05:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C785123B6C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Subject:To:From: Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RElCWq0hPFJUGpBOCIWnX/92hvNB+4rlpkKb1LLSiOU=; b=EVtcde/OkmXhkcs7Jd3+qmo42 K3Vv2vEjmokdiO/zNFvSSQWafiqGQh26z3BfWH1bwoV7a5gUdSu6AjZFrEYkiIpv+v9f1f37aAbqY YCsqt4Y+J0UIHZRUWo3NECLVxxENUxgqJYOHE34Nn1qkBrkD6RHtyKXZMhF/bqfuRae/SglEmZt6u LnXpoaoNMGM+eAwPPAQ+K8hvH4BFal57lh9g/uKmbKeXWNpDISVdshuD13V6di12NBz0ltqrFQ+7I /fHNeliIBF2RtBKxf5DXN84ECW1hEZntXie3oIB5kAjX/lbMbjqTkeEhAKJhBGe9xhhVMdZX86gea 88fZR6ALg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kqK6d-00022B-US; Fri, 18 Dec 2020 18:03:56 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kqJib-0006V4-9b for linux-arm-kernel@lists.infradead.org; Fri, 18 Dec 2020 17:39:16 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43D7B239EE; Fri, 18 Dec 2020 17:38:53 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kqJiN-002LOd-7s; Fri, 18 Dec 2020 17:38:51 +0000 Date: Fri, 18 Dec 2020 17:38:50 +0000 Message-ID: <87v9czqaj9.wl-maz@kernel.org> From: Marc Zyngier To: Zenghui Yu Subject: Re: [PATCH] genirq/msi: Initialize msi_alloc_info to zero for msi_prepare API In-Reply-To: <20201218060039.1770-1-yuzenghui@huawei.com> References: <20201218060039.1770-1-yuzenghui@huawei.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: yuzenghui@huawei.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tglx@linutronix.de, kvm@vger.kernel.org, wanghaibin.wang@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201218_123915_295582_D1B21328 X-CRM114-Status: GOOD ( 27.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wanghaibin.wang@huawei.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Zenghui, On Fri, 18 Dec 2020 06:00:39 +0000, Zenghui Yu wrote: > > Since commit 5fe71d271df8 ("irqchip/gic-v3-its: Tag ITS device as shared if > allocating for a proxy device"), some of the devices are wrongly marked as > "shared" by the ITS driver on systems equipped with the ITS(es). The > problem is that the @info->flags may not be initialized anywhere and we end > up looking at random bits on the stack. That's obviously not good. > > The straightforward fix is to properly initialize msi_alloc_info inside the > .prepare callback of affected MSI domains (its-pci-msi, its-platform-msi, > etc). We can also perform the initialization in IRQ core layer for > msi_domain_prepare_irqs() API and it looks much neater to me. > > Signed-off-by: Zenghui Yu > --- > > This was noticed when I was playing with the assigned devices on arm64 and > VFIO failed to enable MSI-X vectors for almost all VFs (CCed kvm list in > case others will hit the same issue). It turned out that these VFs are > marked as "shared" by mistake and have trouble with the following sequence: > > pci_alloc_irq_vectors(pdev, 1, 1, flag); > pci_free_irq_vectors(pdev); > pci_alloc_irq_vectors(pdev, 1, 2, flag); --> we can only get > *one* vector > > But besides VFIO, I guess there are already some devices get into trouble > at probe time and can't work properly. > > kernel/irq/msi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c > index 2c0c4d6d0f83..dc0e2d7fbdfd 100644 > --- a/kernel/irq/msi.c > +++ b/kernel/irq/msi.c > @@ -402,7 +402,7 @@ int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, > struct msi_domain_ops *ops = info->ops; > struct irq_data *irq_data; > struct msi_desc *desc; > - msi_alloc_info_t arg; > + msi_alloc_info_t arg = { }; > int i, ret, virq; > bool can_reserve; Thanks for having investigated this. I guess my only worry with this is that msi_alloc_info_t is a pretty large structure on x86, and zeroing it isn't totally free. But this definitely looks nicer than some of the alternatives (.prepare isn't a good option, as we do rely on the flag being set in __platform_msi_create_device_domain(), which calls itself .prepare). I'll queue it, and we can always revisit this later if Thomas (or anyone else) has a better idea. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel