iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Joerg Roedel <joro@8bytes.org>
To: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Cc: iommu@lists.linux-foundation.org, Jon.Grimm@amd.com,
	linux-kernel@vger.kernel.org, Wei.Huang2@amd.com
Subject: Re: [RFC PATCH 4/7] iommu/amd: Initial support for AMD IOMMU v2 page table
Date: Thu, 18 Mar 2021 16:28:10 +0100	[thread overview]
Message-ID: <YFNxiiU9jc0+/oU9@8bytes.org> (raw)
In-Reply-To: <20210312090411.6030-5-suravee.suthikulpanit@amd.com>

Hi Suravee,

On Fri, Mar 12, 2021 at 03:04:08AM -0600, Suravee Suthikulpanit wrote:
> @@ -503,6 +504,7 @@ struct amd_io_pgtable {
>  	int			mode;
>  	u64			*root;
>  	atomic64_t		pt_root;    /* pgtable root and pgtable mode */
> +	struct mm_struct	v2_mm;
>  };

A whole mm_struct is a bit too much when all we really need is an 8-byte
page-table root pointer.


> +static pte_t *fetch_pte(struct amd_io_pgtable *pgtable,
> +		      unsigned long iova,
> +		      unsigned long *page_size)
> +{
> +	int level;
> +	pte_t *ptep;
> +
> +	ptep = lookup_address_in_mm(&pgtable->v2_mm, iova, &level);
> +	if (!ptep || pte_none(*ptep) || (level == PG_LEVEL_NONE))
> +		return NULL;

So you are re-using the in-kernel page-table building code. That safes
some lines of code, but has several problems:

	1) When you boot a kernel with this code on a machine with
	   5-level paging, the IOMMU code will build a 5-level
	   page-table too, breaking IOMMU mappings.

	2) You need a whole mm_struct per domain, which is big.

	3) The existing macros for CPU page-tables require locking. For
	   IOMMU page-tables this is not really necessary and might
	   cause scalability issues.

Overall I think you should write your own code to build a 4-level
page-table and use cmpxchg64 to avoid the need for locking. Then things
will not break when such a kernel is suddenly booted on a machine which
as 5-level paging enabled.

Regards,

	Joerg

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2021-03-18 15:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12  9:04 [RFC PATCH 0/7] iommu/amd: Add Generic IO Page Table Framework Support for v2 Page Table Suravee Suthikulpanit
2021-03-12  9:04 ` [RFC PATCH 1/7] iommu/amd: Refactor amd_iommu_domain_enable_v2 Suravee Suthikulpanit
2021-03-12  9:04 ` [RFC PATCH 2/7] iommu/amd: Update sanity check when enable PRI/ATS Suravee Suthikulpanit
2021-03-12  9:04 ` [RFC PATCH 3/7] iommu/amd: Decouple the logic to enable PPR and GT Suravee Suthikulpanit
2021-03-12  9:04 ` [RFC PATCH 4/7] iommu/amd: Initial support for AMD IOMMU v2 page table Suravee Suthikulpanit
2021-03-18 15:28   ` Joerg Roedel [this message]
2021-03-12  9:04 ` [RFC PATCH 5/7] iommu/amd: Add support for Guest IO protection Suravee Suthikulpanit
2021-03-18 15:31   ` Joerg Roedel
2021-03-25 13:06     ` Suravee Suthikulpanit
2021-03-12  9:04 ` [RFC PATCH 6/7] iommu/amd: Introduce amd_iommu_pgtable command-line option Suravee Suthikulpanit
2021-03-18 15:33   ` Joerg Roedel
2021-03-22  4:24     ` Suravee Suthikulpanit
2021-03-12  9:04 ` [RFC PATCH 7/7] iommu/amd: Add support for using AMD IOMMU v2 page table for DMA-API Suravee Suthikulpanit
2021-03-18 15:44   ` Joerg Roedel

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=YFNxiiU9jc0+/oU9@8bytes.org \
    --to=joro@8bytes.org \
    --cc=Jon.Grimm@amd.com \
    --cc=Wei.Huang2@amd.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=suravee.suthikulpanit@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;
as well as URLs for NNTP newsgroup(s).