[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] Do not access /dev/mem in MSI-X PCI passthrough on Xen


  • To: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 17 Nov 2022 09:04:40 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RmJ7NlLjFIgEz8MPJs2nNMlsimgFsnOr/vd2T0Lnkng=; b=WqC4RySg0cRJcTovDWNp9J1GqPKopB7J8qYo8SIyEn2cXo8Amn89l+VcVpZY04bqqhE80+X2tvnIpGkmu+lMil56IdDLpp4cjeMTFE/FWpNY3RarmORBrRvBzWR3kFjgWG5OQXpZ6AAJfiu3T+b+ulplgnfLO5tHuyhqHltM686ZIdqv+RPs4EWSmQEy9kKGeBQw/xUwDoC7vi9Zst5q0dWf4bZ6DxhVCHgFi1gvY5vXDKTY77Lwt0UR3v1nsvMmYySPkY93tFwV6iU+WtYHrANI+gDnU31JCjGUSHYK5bRYlV8gdpMKaelt1tSN9m/QWaRTwz04bGLLuv/RRwG/uw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UVtSU9oyzIg5xWOx+Ixg+YJlx0Pl2y+zuo1Ag6iyFDXxPCchr3L1Dqt+TPPD8tyqYUv63HPYtmRPvCHcbAXuBA3DpmN5eHBq400jRP68TDELBFdfYl/gwTWo6FehgZHLdebN/pg5RhBIyTmZktRklAGdE7Vf7H5olsjEMezJQaiGW481cQZ/zRB8/SJ6d2VPh5lozJsn7sQvz+3a7BT3VVRzZ/5iH4YPS0AEwgmhAfuXtPpXhlMIT62MRESdzS8ZPdQdkGUWEow0ZBhnyQ7OcKF9sFl0h05ds2Axb5sXSUDFQlK+OgZBczUnC8+wzZuAFT/z9HCwCzndtdI4Ec+Qnw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: qemu-devel@xxxxxxxxxx, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, "open list:X86 Xen CPUs" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Jason Andryuk <jandryuk@xxxxxxxxx>
  • Delivery-date: Thu, 17 Nov 2022 08:05:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 17.11.2022 04:34, Marek Marczykowski-Górecki wrote:
> Ok, I found what is wrong. Enabling MSI-X is refused, because INTx isn't
> disabled at this point yet. And apparently I was testing this with
> permissive=1...
> 
> Linux does this:
> https://github.com/torvalds/linux/blob/master/drivers/pci/msi/msi.c#L611
> In short:
> 1. Enable MSI-X with MASKALL=1
> 2. Setup MSI-X table
> 3. Disable INTx
> 4. Set MASKALL=0
> 
> This patch on top should fix this:
> ----8<----
> diff --git a/drivers/xen/xen-pciback/conf_space_capability.c 
> b/drivers/xen/xen-pciback/conf_space_capability.c
> index 097316a74126..f4c4381de76e 100644
> --- a/drivers/xen/xen-pciback/conf_space_capability.c
> +++ b/drivers/xen/xen-pciback/conf_space_capability.c
> @@ -235,7 +235,7 @@ static int msi_msix_flags_write(struct pci_dev *dev, int 
> offset, u16 new_value,
>           (new_value ^ old_value) & ~field_config->allowed_bits)
>               return PCIBIOS_SET_FAILED;
>  
> -     if (new_value & field_config->enable_bit) {
> +     if ((new_value & field_config->allowed_bits) == 
> field_config->enable_bit) {
>               /* don't allow enabling together with other interrupt types */
>               int int_type = xen_pcibk_get_interrupt_type(dev);
>  
> ----8<----
> 
> Jan, is the above safe? It should prevent clearing MASKALL if INTx isn't
> disabled, unless I missed something? But also, it will allow enabling
> MSI-X with MASKALL=1 together with MSI, which I'm not sure if should be
> allowed.

While it would probably be okay with what we have now (after your earlier
patch introducing allowed_bits), it's likely not going to be correct once
further bits would be added to allowed_bits (which clearly is going to be
wanted sooner or later, e.g. for multi-vector MSI). Hence I think ...

> Alternatively to the above patch, I could allow specifically setting
> MSIX_FLAGS_ENABLE + MSIX_FLAGS_MASKALL while INTx isn't disabled as a
> single exception,

... this is the way to go, and ...

> but at this point I'm not sure if some other driver or
> OS wouldn't approach this in yet another way.

... I guess we need to further add exceptions as needed - the one further
approach I could see is to keep all entry's mask bits set until setting
"INTx disable", without using MASKALL.

I'd like to note though that the PCI spec has no such exception. It,
however, also doesn't mandate setting "INTx disable" - that's merely a
workaround for flawed hardware afaik. (In Xen we also only cross check
MSI and MSI-X. IOW we rely on Dom0 anyway when it comes to driving
"INTx disable".) Therefore in the end pciback looks to be going too far
in enforcing such dependencies.

Thinking of this - what about making the change in
xen_pcibk_get_interrupt_type() instead, setting INTERRUPT_TYPE_MSIX only
when MASKALL is clear (alongside ENABLE being set)? This would then also
cover command_write().

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.