Message ID | 20221118023535.1903459-1-marmarek@invisiblethingslab.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp742526wrr; Thu, 17 Nov 2022 18:44:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf5YcVP5EnrGMNB1N+TIsWMWm3tcCgTD3Ayq6nIj+xk51GSuw60joXkC25aCIpB4kLseGmEB X-Received: by 2002:a17:906:edb0:b0:7a0:948d:80ae with SMTP id sa16-20020a170906edb000b007a0948d80aemr4308345ejb.658.1668739452412; Thu, 17 Nov 2022 18:44:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668739452; cv=none; d=google.com; s=arc-20160816; b=nVkN9vj6Hk+ch1QHShBAzlEbVOpzt6XciTrt4IjU+xeIEwUjCryZgpiA4tvTN37ouW V85Doejf6b6hXlCWHwJNFeRseqQKbDrBg1mQGwqesHvmNkuuMkfLciRK7yLR53+F2LnJ o2ztTljbHjsT4btl31vhXDmXGPwDuh1yAF39kLpBXbuAwJohppOqhBuZgeGDArOEJ3Cw CE1/lD5PibmKt0iRQnbOJ5CafSn08ccTR4AEoJwB3dDR7GXPwFlbzyDySjLO+bpr2ofG dYXe5Dh2mtovNjr5E4/DCT+hk/0KCeC9x0IiqKCauAN9qATmaHZje/Z1OyKwUaBvVdNt Pa5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=iXS5rnNN6KGyRE2PJSOSu9Q5tR9SxGRz/NBoxnHnE3o=; b=ROaEnTKxlRxM99RejzSV9W0JEpOLBQ2XKuF9L96iVUjUvSMhRaNlVZHRcFVX1x0NtO BpIZGSSrU/ltIihtMss07y5ezcA7EiiqB+ZNefV5FeXOFtp+JRAuelTyO+rkz+UpNmUb AUtUrWgqJkcyMmAqD6353/SFEPkFmQpaBC9sXa94KBHocVyu0mb6XUowQ2qCLefiKluG Gl6gudA5nUdCulU5w1taXMBUfD155OpsKKNgYqA4k1Ussr0eUx/uUzlbLYwES0aoOLdQ chQ7MCDxynv3hNJ8xO2Q72Vg4p7mRR12hX7SS2MdRMdybSbvnM04WHs5OFhBjJKiHuaS vZKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm1 header.b=L3k1ECDb; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="l/wqCKL7"; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb28-20020a170907961c00b007a7d37e467csi1982311ejc.763.2022.11.17.18.43.48; Thu, 17 Nov 2022 18:44:12 -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=@invisiblethingslab.com header.s=fm1 header.b=L3k1ECDb; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="l/wqCKL7"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231814AbiKRCfy (ORCPT <rfc822;a1648639935@gmail.com> + 99 others); Thu, 17 Nov 2022 21:35:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbiKRCfx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 17 Nov 2022 21:35:53 -0500 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A672E8D49F for <linux-kernel@vger.kernel.org>; Thu, 17 Nov 2022 18:35:52 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 321B6320005D; Thu, 17 Nov 2022 21:35:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 17 Nov 2022 21:35:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to; s=fm1; t= 1668738949; x=1668825349; bh=iXS5rnNN6KGyRE2PJSOSu9Q5tR9SxGRz/NB oxnHnE3o=; b=L3k1ECDbPMHp6Av60+4MBAOrax9uhhonBcOHlRj9ixsjSLE+vUY P46kjBipf/utAb0pXW3HKd4JUCaKZf0EDQRC4wVZxtHN1CUX8TuCWjzQCq1moxqy wMBb+rhTbTyFTXWGxUtwtry0wUHqh/PlWfnOIKT4NQll1PH4lRQz1OOLNO6HwBUM T1OEqBPtsPxMeZpNmLNst4uThX8b3wr29YhBw9Tw90Mx3HoCCVPb0ZEgdZYsJOXx 4jYvvMxRCSB6HBBQVe2y+Hl9gIi5l0aCOzMQvBzJgmuGnHUNZr9xBLFYGISjLtjT o/k6B5f+QBRBd8kv5uw2IbuQVY8pES6IMig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1668738949; x=1668825349; bh=iXS5rnNN6KGyR E2PJSOSu9Q5tR9SxGRz/NBoxnHnE3o=; b=l/wqCKL7HkibTjVT9rTeM96zNNg9i bUrp7eu4RoKTTWCmBp6GJKX+tMoKdvUsCkr80t0Y1u4hX2jNTfzxSd8SKf8ENDuc He9kmBbOEC8cyl2ZVZoD9Hfk4nk8E09RYr87FLtVl7OHq8RbSR97EcptVTI7Pu7U YMGPf34RwoM5R+vqgOonA5mtVv4pf/2VB9Rt/83rmYEk2yRgTpDqWN9J7tP9ewoM Npm97cs1YjrVquZZqMDshBmKI2m1mTUQUCzPIyMmqsznC9E0qU7VvEHMhN0/2U2G qiKTzte/ZcrNAkCP5mumX/od61/+wJDaNTd/J49MLnXZWcRfiVJZPL+mg== X-ME-Sender: <xms:he92Y95jrwYIhB3Zybp1Qlq4-n3Jwrq33GYXQv216TOaFRuax2BkSQ> <xme:he92Y64VBUldd00Ndf4dDXsIXt4Vwrm2Bi3xDr6Tf17CtutwNLKjY6GGk9ve_ReTm r_eE-nmLJavgA> X-ME-Received: <xmr:he92Y0fnbIA3fs_I0CiVKUWbBTmhypUYnI8zIl6a9m1OXDRTxb6dVAsu1j_esVvQNcVdVd7rWzgLiACZzHSnSSI_WyV5jAHoCuttaJTXX0VqZBdusds> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrgeelgdegjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffogggtgfesthekredtredtjeenucfhrhhomhepofgrrhgvkhcu ofgrrhgtiiihkhhofihskhhiqdfikphrvggtkhhiuceomhgrrhhmrghrvghksehinhhvih hsihgslhgvthhhihhnghhslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepleekhfdu leetleelleetteevfeefteffkeetteejheelgfegkeelgeehhfdthedvnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgrrhhmrghrvghksehi nhhvihhsihgslhgvthhhihhnghhslhgrsgdrtghomh X-ME-Proxy: <xmx:he92Y2Kvf5Lf9IO-eTS0KJiSeXvgriWrmxZxfVnTSE-6FBZnFhWQlA> <xmx:he92YxJ9i_6KgAUFtNRWLnx25MlRREMallN2nUMEoA05GNG9UxT9cw> <xmx:he92Y_wIQR2cciuNwFWnFh05XV0mx6Tg5xK_ZM5WzOH4Q8OxZUnKSg> <xmx:he92Y-FjTAi4ImC2SKQkwBLgrPZM1BpFt5qn2wFdGbZ8HJQUzk1dAg> Feedback-ID: i1568416f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 17 Nov 2022 21:35:48 -0500 (EST) From: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= <marmarek@invisiblethingslab.com> To: linux-kernel@vger.kernel.org Cc: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= <marmarek@invisiblethingslab.com>, Juergen Gross <jgross@suse.com>, Stefano Stabellini <sstabellini@kernel.org>, Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>, Jan Beulich <jbeulich@suse.com>, xen-devel@lists.xenproject.org (moderated list:XEN HYPERVISOR INTERFACE) Subject: [PATCH v2] xen-pciback: Consider INTx disabled when MSI/MSI-X is enabled Date: Fri, 18 Nov 2022 03:35:30 +0100 Message-Id: <20221118023535.1903459-1-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749800139738893213?= X-GMAIL-MSGID: =?utf-8?q?1749800139738893213?= |
Series |
[v2] xen-pciback: Consider INTx disabled when MSI/MSI-X is enabled
|
|
Commit Message
Marek Marczykowski-Górecki
Nov. 18, 2022, 2:35 a.m. UTC
Linux enables MSI-X before disabling INTx, but keeps MSI-X masked until
the table is filled. Then it disables INTx just before clearing MASKALL
bit. Currently this approach is rejected by xen-pciback.
According to the PCIe spec, device cannot use INTx when MSI/MSI-X is
enabled. Change the logic to consider INTx disabled if MSI/MSI-X is
enabled. This applies to two places: checking currently enabled
interrupts type, and transition to MSI/MSI-X - where INTx would be
implicitly disabled.
Fixes: 5e29500eba2a ("xen-pciback: Allow setting PCI_MSIX_FLAGS_MASKALL too")
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
drivers/xen/xen-pciback/conf_space.c | 19 +++++++++++++------
.../xen/xen-pciback/conf_space_capability.c | 3 ++-
2 files changed, 15 insertions(+), 7 deletions(-)
Comments
On 18.11.2022 03:35, Marek Marczykowski-Górecki wrote: > Linux enables MSI-X before disabling INTx, but keeps MSI-X masked until > the table is filled. Then it disables INTx just before clearing MASKALL > bit. Currently this approach is rejected by xen-pciback. > According to the PCIe spec, device cannot use INTx when MSI/MSI-X is > enabled. Similarly the spec doesn't allow using MSI and MSI-X at the same time. Before your change xen_pcibk_get_interrupt_type() is consistent for all three forms of interrupt delivery; imo it also wants to be consistent after your change. This effectively would mean setting only one bit at a time (or using an enum right away), but then the question is what order you do the checks in. IOW I think the change to the function is wrong. Furthermore it looks to me as if you're making msi_msix_flags_write() inconsistent with command_write() - you'd now want to also permit clearing "INTx disable" when MSI or MSI-X are enabled. Which, I think, would simply mean allowing the domain unconditional control of the bit (as long as allow_interrupt_control is set of course). Especially with these further changes I'm afraid at least for now I view this as moving in the wrong direction. My view might change in particular if the description made more clear what was wrong with the original change (476878e4b2be ["xen-pciback: optionally allow interrupt enable flag writes"]), or perhaps the discussion having led to the form which was committed in the end. Jan
On Fri, Nov 18, 2022 at 08:36:14AM +0100, Jan Beulich wrote: > On 18.11.2022 03:35, Marek Marczykowski-Górecki wrote: > > Linux enables MSI-X before disabling INTx, but keeps MSI-X masked until > > the table is filled. Then it disables INTx just before clearing MASKALL > > bit. Currently this approach is rejected by xen-pciback. > > According to the PCIe spec, device cannot use INTx when MSI/MSI-X is > > enabled. > > Similarly the spec doesn't allow using MSI and MSI-X at the same time. > Before your change xen_pcibk_get_interrupt_type() is consistent for all > three forms of interrupt delivery; imo it also wants to be consistent > after your change. This effectively would mean setting only one bit at > a time (or using an enum right away), but then the question is what > order you do the checks in. IOW I think the change to the function is > wrong. IIUC the difference is that enabling MSI or MSI-X implicitly disables INTx, while enabling both MSI and MSI-X is UB. This means that MSI active and PCI_COMMAND_INTX_DISABLE bit not set means "only MSI is active" - which the function now properly reports. Both MSI and MSI-X active at the same time means a bug somewhere else and the current code allows only to disable one of them in such case. I could replace this with BUG_ON, or simply assume such bug doesn't exist and ignore this case, if you prefer. > Furthermore it looks to me as if you're making msi_msix_flags_write() > inconsistent with command_write() - you'd now want to also permit > clearing "INTx disable" when MSI or MSI-X are enabled. Which, I think, > would simply mean allowing the domain unconditional control of the bit > (as long as allow_interrupt_control is set of course). I think your are correct. > Especially with these further changes I'm afraid at least for now I > view this as moving in the wrong direction. My view might change in > particular if the description made more clear what was wrong with the > original change (476878e4b2be ["xen-pciback: optionally allow interrupt > enable flag writes"]), or perhaps the discussion having led to the form > which was committed in the end. I'm afraid I don't understand why you think it's the wrong direction. Can you clarify?
On 18.11.2022 13:06, Marek Marczykowski-Górecki wrote: > On Fri, Nov 18, 2022 at 08:36:14AM +0100, Jan Beulich wrote: >> On 18.11.2022 03:35, Marek Marczykowski-Górecki wrote: >>> Linux enables MSI-X before disabling INTx, but keeps MSI-X masked until >>> the table is filled. Then it disables INTx just before clearing MASKALL >>> bit. Currently this approach is rejected by xen-pciback. >>> According to the PCIe spec, device cannot use INTx when MSI/MSI-X is >>> enabled. >> >> Similarly the spec doesn't allow using MSI and MSI-X at the same time. >> Before your change xen_pcibk_get_interrupt_type() is consistent for all >> three forms of interrupt delivery; imo it also wants to be consistent >> after your change. This effectively would mean setting only one bit at >> a time (or using an enum right away), but then the question is what >> order you do the checks in. IOW I think the change to the function is >> wrong. > > IIUC the difference is that enabling MSI or MSI-X implicitly disables > INTx, while enabling both MSI and MSI-X is UB. This means that MSI > active and PCI_COMMAND_INTX_DISABLE bit not set means "only MSI is > active" - which the function now properly reports. Hmm, yes, this is perhaps a good way to look at it. > Both MSI and MSI-X active at the same time means a bug somewhere else > and the current code allows only to disable one of them in such case. I > could replace this with BUG_ON, or simply assume such bug doesn't exist > and ignore this case, if you prefer. BUG_ON() would imply this state cannot be reached no matter what is requested from outside of the kernel. I'm not sure that's true here, so keeping that aspect unchanged is probably fine (and with the above I then take back my "wrong" from the earlier reply. Jan
diff --git a/drivers/xen/xen-pciback/conf_space.c b/drivers/xen/xen-pciback/conf_space.c index 059de92aea7d..d47eee6c5143 100644 --- a/drivers/xen/xen-pciback/conf_space.c +++ b/drivers/xen/xen-pciback/conf_space.c @@ -288,12 +288,6 @@ int xen_pcibk_get_interrupt_type(struct pci_dev *dev) u16 val; int ret = 0; - err = pci_read_config_word(dev, PCI_COMMAND, &val); - if (err) - return err; - if (!(val & PCI_COMMAND_INTX_DISABLE)) - ret |= INTERRUPT_TYPE_INTX; - /* * Do not trust dev->msi(x)_enabled here, as enabling could be done * bypassing the pci_*msi* functions, by the qemu. @@ -316,6 +310,19 @@ int xen_pcibk_get_interrupt_type(struct pci_dev *dev) if (val & PCI_MSIX_FLAGS_ENABLE) ret |= INTERRUPT_TYPE_MSIX; } + + /* + * PCIe spec says device cannot use INTx if MSI/MSI-X is enabled, + * so check for INTx only when both are disabled. + */ + if (!ret) { + err = pci_read_config_word(dev, PCI_COMMAND, &val); + if (err) + return err; + if (!(val & PCI_COMMAND_INTX_DISABLE)) + ret |= INTERRUPT_TYPE_INTX; + } + return ret ?: INTERRUPT_TYPE_NONE; } diff --git a/drivers/xen/xen-pciback/conf_space_capability.c b/drivers/xen/xen-pciback/conf_space_capability.c index 097316a74126..eb4c1af44f5c 100644 --- a/drivers/xen/xen-pciback/conf_space_capability.c +++ b/drivers/xen/xen-pciback/conf_space_capability.c @@ -236,10 +236,11 @@ static int msi_msix_flags_write(struct pci_dev *dev, int offset, u16 new_value, return PCIBIOS_SET_FAILED; if (new_value & field_config->enable_bit) { - /* don't allow enabling together with other interrupt types */ + /* don't allow enabling together with other interrupt type */ int int_type = xen_pcibk_get_interrupt_type(dev); if (int_type == INTERRUPT_TYPE_NONE || + int_type == INTERRUPT_TYPE_INTX || int_type == field_config->int_type) goto write; return PCIBIOS_SET_FAILED;