All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root
@ 2025-01-06 19:14 Alejandro Jimenez
  2025-01-07  8:50 ` Srivastava, Dheeraj Kumar
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Alejandro Jimenez @ 2025-01-06 19:14 UTC (permalink / raw)
  To: iommu, linux-kernel
  Cc: joro, suravee.suthikulpanit, vasant.hegde, will, jgg,
	joao.m.martins, boris.ostrovsky, alejandro.j.jimenez

When updating the page table root field on the DTE, avoid overwriting any
bits that are already set. The earlier call to make_clear_dte() writes
default values that all DTEs must have set (currently DTE[V]), and those
must be preserved.

Currently this doesn't cause problems since the page table root update is
the first field that is set after make_clear_dte() is called, and
DTE_FLAG_V is set again later along with the permission bits (IR/IW).
Remove this redundant assignment too.

Fixes: fd5dff9de4be ("iommu/amd: Modify set_dte_entry() to use 256-bit DTE helpers")
Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
---
 drivers/iommu/amd/iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 20177e18eb0d..a8c17b602c95 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2052,12 +2052,12 @@ static void set_dte_entry(struct amd_iommu *iommu,
 	make_clear_dte(dev_data, dte, &new);
 
 	if (domain->iop.mode != PAGE_MODE_NONE)
-		new.data[0] = iommu_virt_to_phys(domain->iop.root);
+		new.data[0] |= iommu_virt_to_phys(domain->iop.root);
 
 	new.data[0] |= (domain->iop.mode & DEV_ENTRY_MODE_MASK)
 		    << DEV_ENTRY_MODE_SHIFT;
 
-	new.data[0] |= DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V;
+	new.data[0] |= DTE_FLAG_IR | DTE_FLAG_IW;
 
 	/*
 	 * When SNP is enabled, we can only support TV=1 with non-zero domain ID.

base-commit: 1f37ef785d54b27e304c189038697a845259408a
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root
  2025-01-06 19:14 [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root Alejandro Jimenez
@ 2025-01-07  8:50 ` Srivastava, Dheeraj Kumar
  2025-01-07 12:15 ` Vasant Hegde
  2025-02-28 11:18 ` Joerg Roedel
  2 siblings, 0 replies; 9+ messages in thread
From: Srivastava, Dheeraj Kumar @ 2025-01-07  8:50 UTC (permalink / raw)
  To: Alejandro Jimenez, iommu, linux-kernel
  Cc: joro, suravee.suthikulpanit, vasant.hegde, will, jgg,
	joao.m.martins, boris.ostrovsky

Hi,

On 1/7/2025 12:44 AM, Alejandro Jimenez wrote:
> When updating the page table root field on the DTE, avoid overwriting any
> bits that are already set. The earlier call to make_clear_dte() writes
> default values that all DTEs must have set (currently DTE[V]), and those
> must be preserved.
> 
> Currently this doesn't cause problems since the page table root update is
> the first field that is set after make_clear_dte() is called, and
> DTE_FLAG_V is set again later along with the permission bits (IR/IW).
> Remove this redundant assignment too.
> 
> Fixes: fd5dff9de4be ("iommu/amd: Modify set_dte_entry() to use 256-bit DTE helpers")
> Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>

LGTM. Please feel free to add...

Reviewed-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>

Thanks
Dheeraj

> ---
>   drivers/iommu/amd/iommu.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 20177e18eb0d..a8c17b602c95 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2052,12 +2052,12 @@ static void set_dte_entry(struct amd_iommu *iommu,
>   	make_clear_dte(dev_data, dte, &new);
>   
>   	if (domain->iop.mode != PAGE_MODE_NONE)
> -		new.data[0] = iommu_virt_to_phys(domain->iop.root);
> +		new.data[0] |= iommu_virt_to_phys(domain->iop.root);
>   
>   	new.data[0] |= (domain->iop.mode & DEV_ENTRY_MODE_MASK)
>   		    << DEV_ENTRY_MODE_SHIFT;
>   
> -	new.data[0] |= DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_V;
> +	new.data[0] |= DTE_FLAG_IR | DTE_FLAG_IW;
>   
>   	/*
>   	 * When SNP is enabled, we can only support TV=1 with non-zero domain ID.
> 
> base-commit: 1f37ef785d54b27e304c189038697a845259408a


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root
  2025-01-06 19:14 [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root Alejandro Jimenez
  2025-01-07  8:50 ` Srivastava, Dheeraj Kumar
@ 2025-01-07 12:15 ` Vasant Hegde
  2025-01-07 13:36   ` Arun Kodilkar, Sairaj
  2025-01-07 18:01   ` Jason Gunthorpe
  2025-02-28 11:18 ` Joerg Roedel
  2 siblings, 2 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-01-07 12:15 UTC (permalink / raw)
  To: Alejandro Jimenez, iommu, linux-kernel
  Cc: joro, suravee.suthikulpanit, will, jgg, joao.m.martins,
	boris.ostrovsky

Hi Alejandro, Suravee,



On 1/7/2025 12:44 AM, Alejandro Jimenez wrote:
> When updating the page table root field on the DTE, avoid overwriting any
> bits that are already set. The earlier call to make_clear_dte() writes
> default values that all DTEs must have set (currently DTE[V]), and those
> must be preserved.
> 
> Currently this doesn't cause problems since the page table root update is
> the first field that is set after make_clear_dte() is called, and
> DTE_FLAG_V is set again later along with the permission bits (IR/IW).
> Remove this redundant assignment too.

Good catch!

> > Fixes: fd5dff9de4be ("iommu/amd: Modify set_dte_entry() to use 256-bit DTE
helpers")
> Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
> ---
>  drivers/iommu/amd/iommu.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 20177e18eb0d..a8c17b602c95 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2052,12 +2052,12 @@ static void set_dte_entry(struct amd_iommu *iommu,
>  	make_clear_dte(dev_data, dte, &new);

This fix is fine. But with all changes we have done in this code does, do we
really need make_clear_dte()?

How about removing `make_clear_dte()` and moving DTE_FLAG_V to
write_dte_lower128() ?

-Vasant




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root
  2025-01-07 12:15 ` Vasant Hegde
@ 2025-01-07 13:36   ` Arun Kodilkar, Sairaj
  2025-01-07 18:01   ` Jason Gunthorpe
  1 sibling, 0 replies; 9+ messages in thread
From: Arun Kodilkar, Sairaj @ 2025-01-07 13:36 UTC (permalink / raw)
  To: Vasant Hegde, Alejandro Jimenez, iommu, linux-kernel
  Cc: joro, suravee.suthikulpanit, will, jgg, joao.m.martins,
	boris.ostrovsky

On 1/7/2025 5:45 PM, Vasant Hegde wrote:
Hi vasant,
> 
> On 1/7/2025 12:44 AM, Alejandro Jimenez wrote:
>> When updating the page table root field on the DTE, avoid overwriting any
>> bits that are already set. The earlier call to make_clear_dte() writes
>> default values that all DTEs must have set (currently DTE[V]), and those
>> must be preserved.
>>
>> Currently this doesn't cause problems since the page table root update is
>> the first field that is set after make_clear_dte() is called, and
>> DTE_FLAG_V is set again later along with the permission bits (IR/IW).
>> Remove this redundant assignment too.
> 
> Good catch!
> 
>>> Fixes: fd5dff9de4be ("iommu/amd: Modify set_dte_entry() to use 256-bit DTE
> helpers")
>> Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
>> ---
>>   drivers/iommu/amd/iommu.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
>> index 20177e18eb0d..a8c17b602c95 100644
>> --- a/drivers/iommu/amd/iommu.c
>> +++ b/drivers/iommu/amd/iommu.c
>> @@ -2052,12 +2052,12 @@ static void set_dte_entry(struct amd_iommu *iommu,
>>   	make_clear_dte(dev_data, dte, &new);
> 
> This fix is fine. But with all changes we have done in this code does, do we
> really need make_clear_dte()?
> 
> How about removing `make_clear_dte()` and moving DTE_FLAG_V to
> write_dte_lower128() ?
> 

I dont think moving DTE_FLAG_V to write_dte_lower128() is a good
idea, because the order in which the function update_dte256()
assigns upper and lower 128 bits depends on this flag.

Regards
Sairaj Kodilkar

> -Vasant
> 
> 
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root
  2025-01-07 12:15 ` Vasant Hegde
  2025-01-07 13:36   ` Arun Kodilkar, Sairaj
@ 2025-01-07 18:01   ` Jason Gunthorpe
  2025-02-26 16:19     ` Alejandro Jimenez
  1 sibling, 1 reply; 9+ messages in thread
From: Jason Gunthorpe @ 2025-01-07 18:01 UTC (permalink / raw)
  To: Vasant Hegde
  Cc: Alejandro Jimenez, iommu, linux-kernel, joro,
	suravee.suthikulpanit, will, joao.m.martins, boris.ostrovsky

On Tue, Jan 07, 2025 at 05:45:38PM +0530, Vasant Hegde wrote:
> > @@ -2052,12 +2052,12 @@ static void set_dte_entry(struct amd_iommu *iommu,
> >  	make_clear_dte(dev_data, dte, &new);
> 
> This fix is fine. But with all changes we have done in this code does, do we
> really need make_clear_dte()?

> How about removing `make_clear_dte()` and moving DTE_FLAG_V to
> write_dte_lower128() ?

The V flag should just be set by the functions building the DTE,
write_dte_lower() should accept a fully formed dte as a matter of
layering.

I'm hopefull Suravee will come with something like this:

https://lore.kernel.org/linux-iommu/20241016142237.GP3559746@nvidia.com/

And then I'd expect to drop make_clear_dte() and sprinkle the V into
the individual settings that already have bitflags for entry 0.

The one place outside that call chain using make_clear_dte() is
clear_dte_entry() which should call a set_dte_blocked() with the above
break up.

Then the set_dte() functions are called by the attach functions and
you can get hitless replace.

Jason

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root
  2025-01-07 18:01   ` Jason Gunthorpe
@ 2025-02-26 16:19     ` Alejandro Jimenez
  2025-02-26 16:35       ` Jason Gunthorpe
  2025-02-28  9:54       ` Vasant Hegde
  0 siblings, 2 replies; 9+ messages in thread
From: Alejandro Jimenez @ 2025-02-26 16:19 UTC (permalink / raw)
  To: Jason Gunthorpe, Vasant Hegde, dheerajkumar.srivastava, sarunkod
  Cc: iommu, linux-kernel, joro, suravee.suthikulpanit, will,
	joao.m.martins, boris.ostrovsky



On 1/7/25 13:01, Jason Gunthorpe wrote:
> On Tue, Jan 07, 2025 at 05:45:38PM +0530, Vasant Hegde wrote:
>>> @@ -2052,12 +2052,12 @@ static void set_dte_entry(struct amd_iommu *iommu,
>>>   	make_clear_dte(dev_data, dte, &new);
>>
>> This fix is fine. But with all changes we have done in this code does, do we
>> really need make_clear_dte()?
> 
>> How about removing `make_clear_dte()` and moving DTE_FLAG_V to
>> write_dte_lower128() ?
> 
> The V flag should just be set by the functions building the DTE,
> write_dte_lower() should accept a fully formed dte as a matter of
> layering.
> 
> I'm hopefull Suravee will come with something like this:
> 
> https://lore.kernel.org/linux-iommu/20241016142237.GP3559746@nvidia.com/
> 

Suravee did say he would implement the suggestions above in the series for
nested translation support, but that might take a while considering where
we are in the cycle. Given that this fix is straightforward and has been
reviewed by Dheeraj, are there any concerns with merging it in its current
form?

Otherwise I can implement and test the more extensive changes that Jason
provided above, and hopefully Suravee's work on nested support can easily
merge with those once ready.

Alejandro


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root
  2025-02-26 16:19     ` Alejandro Jimenez
@ 2025-02-26 16:35       ` Jason Gunthorpe
  2025-02-28  9:54       ` Vasant Hegde
  1 sibling, 0 replies; 9+ messages in thread
From: Jason Gunthorpe @ 2025-02-26 16:35 UTC (permalink / raw)
  To: Alejandro Jimenez, joro
  Cc: Vasant Hegde, dheerajkumar.srivastava, sarunkod, iommu,
	linux-kernel, suravee.suthikulpanit, will, joao.m.martins,
	boris.ostrovsky

On Wed, Feb 26, 2025 at 11:19:46AM -0500, Alejandro Jimenez wrote:
> On 1/7/25 13:01, Jason Gunthorpe wrote:
> > On Tue, Jan 07, 2025 at 05:45:38PM +0530, Vasant Hegde wrote:
> > > > @@ -2052,12 +2052,12 @@ static void set_dte_entry(struct amd_iommu *iommu,
> > > >   	make_clear_dte(dev_data, dte, &new);
> > > 
> > > This fix is fine. But with all changes we have done in this code does, do we
> > > really need make_clear_dte()?
> > 
> > > How about removing `make_clear_dte()` and moving DTE_FLAG_V to
> > > write_dte_lower128() ?
> > 
> > The V flag should just be set by the functions building the DTE,
> > write_dte_lower() should accept a fully formed dte as a matter of
> > layering.
> > 
> > I'm hopefull Suravee will come with something like this:
> > 
> > https://lore.kernel.org/linux-iommu/20241016142237.GP3559746@nvidia.com/
> > 
> 
> Suravee did say he would implement the suggestions above in the series for
> nested translation support, but that might take a while considering where
> we are in the cycle. Given that this fix is straightforward and has been
> reviewed by Dheeraj, are there any concerns with merging it in its current
> form?

+1 to take the fix

Jason

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root
  2025-02-26 16:19     ` Alejandro Jimenez
  2025-02-26 16:35       ` Jason Gunthorpe
@ 2025-02-28  9:54       ` Vasant Hegde
  1 sibling, 0 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-02-28  9:54 UTC (permalink / raw)
  To: Alejandro Jimenez, Jason Gunthorpe, dheerajkumar.srivastava,
	sarunkod
  Cc: iommu, linux-kernel, joro, suravee.suthikulpanit, will,
	joao.m.martins, boris.ostrovsky



On 2/26/2025 9:49 PM, Alejandro Jimenez wrote:
> 
> 
> On 1/7/25 13:01, Jason Gunthorpe wrote:
>> On Tue, Jan 07, 2025 at 05:45:38PM +0530, Vasant Hegde wrote:
>>>> @@ -2052,12 +2052,12 @@ static void set_dte_entry(struct amd_iommu *iommu,
>>>>       make_clear_dte(dev_data, dte, &new);
>>>
>>> This fix is fine. But with all changes we have done in this code does, do we
>>> really need make_clear_dte()?
>>
>>> How about removing `make_clear_dte()` and moving DTE_FLAG_V to
>>> write_dte_lower128() ?
>>
>> The V flag should just be set by the functions building the DTE,
>> write_dte_lower() should accept a fully formed dte as a matter of
>> layering.
>>
>> I'm hopefull Suravee will come with something like this:
>>
>> https://lore.kernel.org/linux-iommu/20241016142237.GP3559746@nvidia.com/
>>
> 
> Suravee did say he would implement the suggestions above in the series for
> nested translation support, but that might take a while considering where
> we are in the cycle. Given that this fix is straightforward and has been
> reviewed by Dheeraj, are there any concerns with merging it in its current
> form?

Ack. I think its fine to pull current patch for now.

Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>

-Vasant


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root
  2025-01-06 19:14 [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root Alejandro Jimenez
  2025-01-07  8:50 ` Srivastava, Dheeraj Kumar
  2025-01-07 12:15 ` Vasant Hegde
@ 2025-02-28 11:18 ` Joerg Roedel
  2 siblings, 0 replies; 9+ messages in thread
From: Joerg Roedel @ 2025-02-28 11:18 UTC (permalink / raw)
  To: Alejandro Jimenez
  Cc: iommu, linux-kernel, suravee.suthikulpanit, vasant.hegde, will,
	jgg, joao.m.martins, boris.ostrovsky

On Mon, Jan 06, 2025 at 07:14:13PM +0000, Alejandro Jimenez wrote:
> When updating the page table root field on the DTE, avoid overwriting any
> bits that are already set. The earlier call to make_clear_dte() writes
> default values that all DTEs must have set (currently DTE[V]), and those
> must be preserved.
> 
> Currently this doesn't cause problems since the page table root update is
> the first field that is set after make_clear_dte() is called, and
> DTE_FLAG_V is set again later along with the permission bits (IR/IW).
> Remove this redundant assignment too.
> 
> Fixes: fd5dff9de4be ("iommu/amd: Modify set_dte_entry() to use 256-bit DTE helpers")
> Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
> ---
>  drivers/iommu/amd/iommu.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-02-28 11:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-06 19:14 [PATCH 1/1] iommu/amd: Preserve default DTE fields when updating Host Page Table Root Alejandro Jimenez
2025-01-07  8:50 ` Srivastava, Dheeraj Kumar
2025-01-07 12:15 ` Vasant Hegde
2025-01-07 13:36   ` Arun Kodilkar, Sairaj
2025-01-07 18:01   ` Jason Gunthorpe
2025-02-26 16:19     ` Alejandro Jimenez
2025-02-26 16:35       ` Jason Gunthorpe
2025-02-28  9:54       ` Vasant Hegde
2025-02-28 11:18 ` Joerg Roedel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.