Linux IOMMU Development
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Vasant Hegde <vasant.hegde@amd.com>
Cc: iommu@lists.linux.dev, joro@8bytes.org,
	suravee.suthikulpanit@amd.com, wei.huang2@amd.com,
	jsnitsel@redhat.com, Alex Deucher <alexander.deucher@amd.com>,
	Felix Kuehling <Felix.Kuehling@amd.com>
Subject: Re: [PATCH 1/4] iommu/amd: Remove iommu_v2 module
Date: Tue, 15 Aug 2023 11:43:50 -0300	[thread overview]
Message-ID: <ZNuPJmi9sdRPVVVL@ziepe.ca> (raw)
In-Reply-To: <20230815103255.565295-2-vasant.hegde@amd.com>

On Tue, Aug 15, 2023 at 10:32:52AM +0000, Vasant Hegde wrote:

> -int amd_iommu_init_device(struct pci_dev *pdev, int pasids)
> -{
> -	struct device_state *dev_state;
> -	struct iommu_group *group;
> -	unsigned long flags;
> -	int ret, tmp;
> -	u32 sbdf;
> -
> -	might_sleep();
> -
> -	/*
> -	 * When memory encryption is active the device is likely not in a
> -	 * direct-mapped domain. Forbid using IOMMUv2 functionality for now.
> -	 */
> -	if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
> -		return -ENODEV;
> -
> -	if (!amd_iommu_v2_supported())
> -		return -ENODEV;
> -
> -	if (pasids <= 0 || pasids > (PASID_MASK + 1))
> -		return -EINVAL;
> -
> -	sbdf = get_pci_sbdf_id(pdev);
> -
> -	dev_state = kzalloc(sizeof(*dev_state), GFP_KERNEL);
> -	if (dev_state == NULL)
> -		return -ENOMEM;
> -
> -	spin_lock_init(&dev_state->lock);
> -	init_waitqueue_head(&dev_state->wq);
> -	dev_state->pdev  = pdev;
> -	dev_state->sbdf = sbdf;
> -
> -	tmp = pasids;
> -	for (dev_state->pasid_levels = 0; (tmp - 1) & ~0x1ff; tmp >>= 9)
> -		dev_state->pasid_levels += 1;
> -
> -	atomic_set(&dev_state->count, 1);
> -	dev_state->max_pasids = pasids;
> -
> -	ret = -ENOMEM;
> -	dev_state->states = (void *)get_zeroed_page(GFP_KERNEL);
> -	if (dev_state->states == NULL)
> -		goto out_free_dev_state;
> -
> -	dev_state->domain = iommu_domain_alloc(&pci_bus_type);
> -	if (dev_state->domain == NULL)
> -		goto out_free_states;
> -
> -	/* See iommu_is_default_domain() */
> -	dev_state->domain->type = IOMMU_DOMAIN_IDENTITY;
> -	amd_iommu_domain_direct_map(dev_state->domain);

Since this code has been removed please also add a revert for the core
bodge that was supporting it:

commit 2380f1e8195ef612deea1dc7a3d611c5d2b9b56a
Author: Jason Gunthorpe <jgg@ziepe.ca>
Date:   Fri Sep 9 16:46:31 2022 -0300

    iommu: Fix false ownership failure on AMD systems with PASID activated
    
    The AMD IOMMU driver cannot activate PASID mode on a RID without the RID's
    translation being set to IDENTITY. Further it requires changing the RID's
    page table layout from the normal v1 IOMMU_DOMAIN_IDENTITY layout to a
    different v2 layout.
    
    It does this by creating a new iommu_domain, configuring that domain for
    v2 identity operation and then attaching it to the group, from within the
    driver. This logic assumes the group is already set to the IDENTITY domain
    and is being used by the DMA API.
    
    However, since the ownership logic is based on the group's domain pointer
    equaling the default domain to detect DMA API ownership, this causes it to
    look like the group is not attached to the DMA API any more. This blocks
    attaching drivers to any other devices in the group.
    
    In a real system this manifests itself as the HD-audio devices on some AMD
    platforms losing their device drivers.
    
    Work around this unique behavior of the AMD driver by checking for
    equality of IDENTITY domains based on their type, not their pointer
    value. This allows the AMD driver to have two IDENTITY domains for
    internal purposes without breaking the check.
    
    Have the AMD driver properly declare that the special domain it created is
    actually an IDENTITY domain.

Jason

  reply	other threads:[~2023-08-15 14:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 10:32 [PATCH 0/4] iommu/amd: SVA Support (part 2) - deprecate iommu_v2 module Vasant Hegde
2023-08-15 10:32 ` [PATCH 1/4] iommu/amd: Remove " Vasant Hegde
2023-08-15 14:43   ` Jason Gunthorpe [this message]
2023-08-16  9:52     ` Vasant Hegde
2023-08-15 10:32 ` [PATCH 2/4] iommu/amd: Remove PPR support Vasant Hegde
2023-08-15 10:32 ` [PATCH 3/4] iommu/amd: Remove amd_iommu_device_info() Vasant Hegde
2023-08-15 10:32 ` [PATCH 4/4] iommu/amd: Remove unused EXPORT_SYMBOLS Vasant Hegde
2023-08-15 14:41 ` [PATCH 0/4] iommu/amd: SVA Support (part 2) - deprecate iommu_v2 module Jason Gunthorpe
2023-08-16  7:31   ` Vasant Hegde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZNuPJmi9sdRPVVVL@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=Felix.Kuehling@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=jsnitsel@redhat.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=vasant.hegde@amd.com \
    --cc=wei.huang2@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox