Skip to contentSkip to conversation

FAILED: patch "[PATCH] iommu/amd/pgtbl_v2: Fix domain max address" failed to apply to 6.3-stable tree

PATCH In review [email protected] 3 participants 7 messages Jun 5, 2023 – Jun 7, 2023

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.3-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.3.y
git checkout FETCH_HEAD
git cherry-pick -x 11c439a19466e7feaccdbce148a75372fddaf4e9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023060548-rake-strongman-fdbe@gregkh' --subject-prefix 'PATCH 6.3.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 11c439a19466e7feaccdbce148a75372fddaf4e9 Mon Sep 17 00:00:00 2001
From: Vasant Hegde <[email protected]>
Date: Thu, 18 May 2023 05:43:51 +0000
Subject: [PATCH] iommu/amd/pgtbl_v2: Fix domain max address

IOMMU v2 page table supports 4 level (47 bit) or 5 level (56 bit) virtual address space. Current code assumes it can support 64bit IOVA address space. If IOVA allocator allocates virtual address > 47/56 bit (depending on page table level) then it will do wrong mapping and cause invalid translation.

Hence adjust aperture size to use max address supported by the page table.

Fixes aaac38f61487 ("iommu/amd: Initial support for AMD IOMMU v2 page table")
Cc <[email protected]> # v6.0+
Cc Suravee Suthikulpanit <[email protected]>
drivers/iommu/amd/iommu.c +10 -1
index 0f3ac4b489d6..dc1ec6849775 100644
@@ -2129,6 +2129,15 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 	return NULL;
 }
 
+static inline u64 dma_max_address(void)
+{
+	if (amd_iommu_pgtable == AMD_IOMMU_V1)
+		return ~0ULL;
+
+	/* V2 with 4/5 level page table */
+	return ((1ULL << PM_LEVEL_SHIFT(amd_iommu_gpt_level)) - 1);
+}
+
 static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
 {
 	struct protection_domain *domain;
@@ -2145,7 +2154,7 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
 		return NULL;
 
 	domain->domain.geometry.aperture_start = 0;
-	domain->domain.geometry.aperture_end   = ~0ULL;
+	domain->domain.geometry.aperture_end   = dma_max_address();
 	domain->domain.geometry.force_aperture = true;
 
 	return &domain->domain;
#1 lore raw
Quoted 15 lines · On Mon, Jun 05, 2023 at 10:38:48PM +0200, [email protected] wrote:

The patch below does not apply to the 6.3-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.3.y
git checkout FETCH_HEAD
git cherry-pick -x 11c439a19466e7feaccdbce148a75372fddaf4e9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023060548-rake-strongman-fdbe@gregkh' --subject-prefix 'PATCH 6.3.y' HEAD^..

Quoted 8 lines

Possible dependencies:

thanks,

greg k-h

I'm not sure what happened, but it works for me:

# git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.3.y
From https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux
 * branch                      linux-6.3.y -> FETCH_HEAD
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
# git co FETCH_HEAD
Note: switching to 'FETCH_HEAD'.

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may do so (now or later) by using -c with the switch command. Example:

git switch -c <new-branch-name>

Or undo this operation with:

git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at abfd9cf1c3d4 Linux 6.3.6

# git cherry-pick -x 11c439a19466e7feaccdbce148a75372fddaf4e9
Auto-merging drivers/iommu/amd/iommu.c
[detached HEAD 20a7d8fdd693] iommu/amd/pgtbl_v2: Fix domain max address
 Author: Vasant Hegde <[email protected]>
 Date: Thu May 18 05:43:51 2023 +0000
 1 file changed, 10 insertions(+), 1 deletion(-)

It also worked with 6.1.y:

# git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
From https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux
 * branch                      linux-6.1.y -> FETCH_HEAD
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
# git co FETCH_HEAD                                                                      
Note: switching to 'FETCH_HEAD'.

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may do so (now or later) by using -c with the switch command. Example:

git switch -c <new-branch-name>

Or undo this operation with:

git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 76ba310227d2 Linux 6.1.32

# git cherry-pick -x 11c439a19466e7feaccdbce148a75372fddaf4e9                            
Auto-merging drivers/iommu/amd/iommu.c
[detached HEAD 75eead6b6b81] iommu/amd/pgtbl_v2: Fix domain max address
 Author: Vasant Hegde <[email protected]>
 Date: Thu May 18 05:43:51 2023 +0000
 1 file changed, 10 insertions(+), 1 deletion(-)

Regards,
Jerry

Quoted 54 lines

------------------ original commit in Linus's tree ------------------

From 11c439a19466e7feaccdbce148a75372fddaf4e9 Mon Sep 17 00:00:00 2001
From: Vasant Hegde <[email protected]>
Date: Thu, 18 May 2023 05:43:51 +0000
Subject: [PATCH] iommu/amd/pgtbl_v2: Fix domain max address

IOMMU v2 page table supports 4 level (47 bit) or 5 level (56 bit) virtual address space. Current code assumes it can support 64bit IOVA address space. If IOVA allocator allocates virtual address > 47/56 bit (depending on page table level) then it will do wrong mapping and cause invalid translation.

Hence adjust aperture size to use max address supported by the page table.

Fixes aaac38f61487 ("iommu/amd: Initial support for AMD IOMMU v2 page table")
Cc <[email protected]> # v6.0+
Cc Suravee Suthikulpanit <[email protected]>
drivers/iommu/amd/iommu.c +10 -1
index 0f3ac4b489d6..dc1ec6849775 100644
@@ -2129,6 +2129,15 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 	return NULL;
 }
 
+static inline u64 dma_max_address(void)
+{
+	if (amd_iommu_pgtable == AMD_IOMMU_V1)
+		return ~0ULL;
+
+	/* V2 with 4/5 level page table */
+	return ((1ULL << PM_LEVEL_SHIFT(amd_iommu_gpt_level)) - 1);
+}
+
 static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
 {
 	struct protection_domain *domain;
@@ -2145,7 +2154,7 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
 		return NULL;
 
 	domain->domain.geometry.aperture_start = 0;
-	domain->domain.geometry.aperture_end   = ~0ULL;
+	domain->domain.geometry.aperture_end   = dma_max_address();
 	domain->domain.geometry.force_aperture = true;
 
 	return &domain->domain;
maintainer
#2 lore raw

Hi,

Quoted 20 lines · Jerry Snitselaar
Quoted 19 lines · On Mon, Jun 05, 2023 at 10:38:48PM +0200, [email protected] wrote:

The patch below does not apply to the 6.3-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.3.y
git checkout FETCH_HEAD
git cherry-pick -x 11c439a19466e7feaccdbce148a75372fddaf4e9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023060548-rake-strongman-fdbe@gregkh' --subject-prefix 'PATCH 6.3.y' HEAD^..

Possible dependencies:

Quoted 6 lines
Quoted 4 lines

thanks,

greg k-h

I'm not sure what happened, but it works for me:

You are right. This applies cleanly on 6.3 stable branch. But it won't build. We have dependency on below commit:

f594496403fa ("iommu/amd: Add 5 level guest page table support")

-Vasant

Quoted 125 lines
# git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.3.y
From https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux
 * branch                      linux-6.3.y -> FETCH_HEAD
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
# git co FETCH_HEAD
Note: switching to 'FETCH_HEAD'.

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may do so (now or later) by using -c with the switch command. Example:

git switch -c <new-branch-name>

Or undo this operation with:

git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at abfd9cf1c3d4 Linux 6.3.6

# git cherry-pick -x 11c439a19466e7feaccdbce148a75372fddaf4e9
Auto-merging drivers/iommu/amd/iommu.c
[detached HEAD 20a7d8fdd693] iommu/amd/pgtbl_v2: Fix domain max address
 Author: Vasant Hegde <[email protected]>
 Date: Thu May 18 05:43:51 2023 +0000
 1 file changed, 10 insertions(+), 1 deletion(-)

It also worked with 6.1.y:

# git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
From https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux
 * branch                      linux-6.1.y -> FETCH_HEAD
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
# git co FETCH_HEAD                                                                      
Note: switching to 'FETCH_HEAD'.

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may do so (now or later) by using -c with the switch command. Example:

git switch -c <new-branch-name>

Or undo this operation with:

git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 76ba310227d2 Linux 6.1.32

# git cherry-pick -x 11c439a19466e7feaccdbce148a75372fddaf4e9                            
Auto-merging drivers/iommu/amd/iommu.c
[detached HEAD 75eead6b6b81] iommu/amd/pgtbl_v2: Fix domain max address
 Author: Vasant Hegde <[email protected]>
 Date: Thu May 18 05:43:51 2023 +0000
 1 file changed, 10 insertions(+), 1 deletion(-)

Regards,
Jerry

Quoted 54 lines

------------------ original commit in Linus's tree ------------------

From 11c439a19466e7feaccdbce148a75372fddaf4e9 Mon Sep 17 00:00:00 2001
From: Vasant Hegde <[email protected]>
Date: Thu, 18 May 2023 05:43:51 +0000
Subject: [PATCH] iommu/amd/pgtbl_v2: Fix domain max address

IOMMU v2 page table supports 4 level (47 bit) or 5 level (56 bit) virtual address space. Current code assumes it can support 64bit IOVA address space. If IOVA allocator allocates virtual address > 47/56 bit (depending on page table level) then it will do wrong mapping and cause invalid translation.

Hence adjust aperture size to use max address supported by the page table.

Fixes aaac38f61487 ("iommu/amd: Initial support for AMD IOMMU v2 page table")
Cc <[email protected]> # v6.0+
Cc Suravee Suthikulpanit <[email protected]>
drivers/iommu/amd/iommu.c +10 -1
index 0f3ac4b489d6..dc1ec6849775 100644
@@ -2129,6 +2129,15 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 	return NULL;
 }
 
+static inline u64 dma_max_address(void)
+{
+	if (amd_iommu_pgtable == AMD_IOMMU_V1)
+		return ~0ULL;
+
+	/* V2 with 4/5 level page table */
+	return ((1ULL << PM_LEVEL_SHIFT(amd_iommu_gpt_level)) - 1);
+}
+
 static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
 {
 	struct protection_domain *domain;
@@ -2145,7 +2154,7 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
 		return NULL;
 
 	domain->domain.geometry.aperture_start = 0;
-	domain->domain.geometry.aperture_end   = ~0ULL;
+	domain->domain.geometry.aperture_end   = dma_max_address();
 	domain->domain.geometry.force_aperture = true;
 
 	return &domain->domain;
author maintainer
#3 lore raw
In reply to Jerry Snitselaar
Quoted 26 lines · Jerry Snitselaar
Quoted 15 lines · On Mon, Jun 05, 2023 at 10:38:48PM +0200, [email protected] wrote:

The patch below does not apply to the 6.3-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.3.y
git checkout FETCH_HEAD
git cherry-pick -x 11c439a19466e7feaccdbce148a75372fddaf4e9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023060548-rake-strongman-fdbe@gregkh' --subject-prefix 'PATCH 6.3.y' HEAD^..

Quoted 8 lines

Possible dependencies:

thanks,

greg k-h

I'm not sure what happened, but it works for me:

Quoted 1 line · I think you skipped the line above that
Quoted 1 line

# <resolve conflicts, build, test, etc.>

Did you test-build this?

thanks,

greg k-h

#4 lore raw
Quoted 30 lines · Greg KH
Quoted 20 lines · Jerry Snitselaar
Quoted 19 lines · On Mon, Jun 05, 2023 at 10:38:48PM +0200, [email protected] wrote:

The patch below does not apply to the 6.3-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.3.y
git checkout FETCH_HEAD
git cherry-pick -x 11c439a19466e7feaccdbce148a75372fddaf4e9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023060548-rake-strongman-fdbe@gregkh' --subject-prefix 'PATCH 6.3.y' HEAD^..

Possible dependencies:

Quoted 6 lines
Quoted 4 lines

thanks,

greg k-h

I'm not sure what happened, but it works for me:

I think you skipped the line above that said:

Quoted 7 lines
Quoted 1 line
Quoted 1 line

# <resolve conflicts, build, test, etc.>

Did you test-build this?

thanks,

greg k-h

Sigh, nope skipped right over that. I even sent a reply when the original patch was sent saying it would need to be changed for stable:

For the stable releases, this will need to be PAGE_MODE_4_LEVEL instead of amd_iommu_gpt_level? The 6.4 merge window is when amd_iommu_gpt_level arrived with the 5 level page table changes.

Sorry for the noise.

maintainer
#5 lore raw

PATCH 1/1 iommu/amd/pgtbl_v2: Fix domain max address

In reply to [email protected]

[ Upstream commit 11c439a19466e7feaccdbce148a75372fddaf4e9 ]

IOMMU v2 page table supports 4 level (47 bit) or 5 level (56 bit) virtual address space. Current code assumes it can support 64bit IOVA address space. If IOVA allocator allocates virtual address > 47/56 bit (depending on page table level) then it will do wrong mapping and cause invalid translation.

Hence adjust aperture size to use max address supported by the page table.

Fixes aaac38f61487 ("iommu/amd: Initial support for AMD IOMMU v2 page table")
Cc <[email protected]> # v6.0+
Cc Suravee Suthikulpanit <[email protected]>
[ Modified to work with "V2 with 4 level page table" only - Vasant ]
---
 drivers/iommu/amd/iommu.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +10 -1
index 167da5b1a5e3..7fe62558d24f 100644
@@ -2107,6 +2107,15 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 	return NULL;
 }
 
+static inline u64 dma_max_address(void)
+{
+	if (amd_iommu_pgtable == AMD_IOMMU_V1)
+		return ~0ULL;
+
+	/* V2 with 4 level page table */
+	return ((1ULL << PM_LEVEL_SHIFT(PAGE_MODE_4_LEVEL)) - 1);
+}
+
 static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
 {
 	struct protection_domain *domain;
@@ -2123,7 +2132,7 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
 		return NULL;
 
 	domain->domain.geometry.aperture_start = 0;
-	domain->domain.geometry.aperture_end   = ~0ULL;
+	domain->domain.geometry.aperture_end   = dma_max_address();
 	domain->domain.geometry.force_aperture = true;
 
 	return &domain->domain;
Signature · 1 line
2.31.1
author maintainer
#6 lore raw

Re: [PATCH 6.3.y] iommu/amd/pgtbl_v2: Fix domain max address

Quoted 20 lines · Vasant Hegde

[ Upstream commit 11c439a19466e7feaccdbce148a75372fddaf4e9 ]

IOMMU v2 page table supports 4 level (47 bit) or 5 level (56 bit) virtual address space. Current code assumes it can support 64bit IOVA address space. If IOVA allocator allocates virtual address > 47/56 bit (depending on page table level) then it will do wrong mapping and cause invalid translation.

Hence adjust aperture size to use max address supported by the page table.

Fixes aaac38f61487 ("iommu/amd: Initial support for AMD IOMMU v2 page table")
Cc <[email protected]> # v6.0+
Cc Suravee Suthikulpanit <[email protected]>
[ Modified to work with "V2 with 4 level page table" only - Vasant ]
Quoted 4 lines
---
 drivers/iommu/amd/iommu.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Both now queued up, thanks.

greg k-h