All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
@ 2021-01-25 21:52 ` Isaac J. Manjarres
  0 siblings, 0 replies; 8+ messages in thread
From: Isaac J. Manjarres @ 2021-01-25 21:52 UTC (permalink / raw)
  To: will, robin.murphy, joro, bjorn.andersson
  Cc: Isaac J. Manjarres, linux-arm-kernel, iommu, linux-kernel, stable

When extracting the mask for a SMR that was programmed by the
bootloader, the SMR's valid bit is also extracted and is treated
as part of the mask, which is not correct. Consider the scenario
where an SMMU master whose context is determined by a bootloader
programmed SMR is removed (omitting parts of device/driver core):

->iommu_release_device()
 -> arm_smmu_release_device()
  -> arm_smmu_master_free_smes()
   -> arm_smmu_free_sme() /* Assume that the SME is now free */
   -> arm_smmu_write_sme()
    -> arm_smmu_write_smr() /* Construct SMR value using mask and SID */

Since the valid bit was considered as part of the mask, the SMR will
be programmed as valid.

Fix the SMR mask extraction step for bootloader programmed SMRs
by masking out the valid bit when we know that we're already
working with a valid SMR.

Fixes: 07a7f2caaa5a ("iommu/arm-smmu-qcom: Read back stream mappings")
Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
Cc: stable@vger.kernel.org
---
 drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
index bcda170..abb1d2f 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
@@ -206,6 +206,8 @@ static int qcom_smmu_cfg_probe(struct arm_smmu_device *smmu)
 		smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i));
 
 		if (FIELD_GET(ARM_SMMU_SMR_VALID, smr)) {
+			/* Ignore valid bit for SMR mask extraction. */
+			smr &= ~ARM_SMMU_SMR_VALID;
 			smmu->smrs[i].id = FIELD_GET(ARM_SMMU_SMR_ID, smr);
 			smmu->smrs[i].mask = FIELD_GET(ARM_SMMU_SMR_MASK, smr);
 			smmu->smrs[i].valid = true;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


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

* [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
@ 2021-01-25 21:52 ` Isaac J. Manjarres
  0 siblings, 0 replies; 8+ messages in thread
From: Isaac J. Manjarres @ 2021-01-25 21:52 UTC (permalink / raw)
  To: will, robin.murphy, joro, bjorn.andersson
  Cc: Isaac J. Manjarres, stable, iommu, linux-kernel, linux-arm-kernel

When extracting the mask for a SMR that was programmed by the
bootloader, the SMR's valid bit is also extracted and is treated
as part of the mask, which is not correct. Consider the scenario
where an SMMU master whose context is determined by a bootloader
programmed SMR is removed (omitting parts of device/driver core):

->iommu_release_device()
 -> arm_smmu_release_device()
  -> arm_smmu_master_free_smes()
   -> arm_smmu_free_sme() /* Assume that the SME is now free */
   -> arm_smmu_write_sme()
    -> arm_smmu_write_smr() /* Construct SMR value using mask and SID */

Since the valid bit was considered as part of the mask, the SMR will
be programmed as valid.

Fix the SMR mask extraction step for bootloader programmed SMRs
by masking out the valid bit when we know that we're already
working with a valid SMR.

Fixes: 07a7f2caaa5a ("iommu/arm-smmu-qcom: Read back stream mappings")
Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
Cc: stable@vger.kernel.org
---
 drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
index bcda170..abb1d2f 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
@@ -206,6 +206,8 @@ static int qcom_smmu_cfg_probe(struct arm_smmu_device *smmu)
 		smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i));
 
 		if (FIELD_GET(ARM_SMMU_SMR_VALID, smr)) {
+			/* Ignore valid bit for SMR mask extraction. */
+			smr &= ~ARM_SMMU_SMR_VALID;
 			smmu->smrs[i].id = FIELD_GET(ARM_SMMU_SMR_ID, smr);
 			smmu->smrs[i].mask = FIELD_GET(ARM_SMMU_SMR_MASK, smr);
 			smmu->smrs[i].valid = true;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

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

* Re: [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
  2021-01-25 21:52 ` Isaac J. Manjarres
  (?)
@ 2021-01-26 10:34   ` Robin Murphy
  -1 siblings, 0 replies; 8+ messages in thread
From: Robin Murphy @ 2021-01-26 10:34 UTC (permalink / raw)
  To: Isaac J. Manjarres, will, joro, bjorn.andersson
  Cc: stable, iommu, linux-kernel, linux-arm-kernel

On 2021-01-25 21:52, Isaac J. Manjarres wrote:
> When extracting the mask for a SMR that was programmed by the
> bootloader, the SMR's valid bit is also extracted and is treated
> as part of the mask, which is not correct. Consider the scenario
> where an SMMU master whose context is determined by a bootloader
> programmed SMR is removed (omitting parts of device/driver core):
> 
> ->iommu_release_device()
>   -> arm_smmu_release_device()
>    -> arm_smmu_master_free_smes()
>     -> arm_smmu_free_sme() /* Assume that the SME is now free */
>     -> arm_smmu_write_sme()
>      -> arm_smmu_write_smr() /* Construct SMR value using mask and SID */
> 
> Since the valid bit was considered as part of the mask, the SMR will
> be programmed as valid.

Ah, right, because ARM_SMMU_SMR_{ID,MASK} are 16-bit fields to 
accommodate EXIDS, which doesn't matter normally when the IDs are 
strictly validated in arm_smmu_probe_device()...

> Fix the SMR mask extraction step for bootloader programmed SMRs
> by masking out the valid bit when we know that we're already
> working with a valid SMR.

This seems like the neatest approach to me.

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> Fixes: 07a7f2caaa5a ("iommu/arm-smmu-qcom: Read back stream mappings")
> Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
> Cc: stable@vger.kernel.org
> ---
>   drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> index bcda170..abb1d2f 100644
> --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> @@ -206,6 +206,8 @@ static int qcom_smmu_cfg_probe(struct arm_smmu_device *smmu)
>   		smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i));
>   
>   		if (FIELD_GET(ARM_SMMU_SMR_VALID, smr)) {
> +			/* Ignore valid bit for SMR mask extraction. */
> +			smr &= ~ARM_SMMU_SMR_VALID;
>   			smmu->smrs[i].id = FIELD_GET(ARM_SMMU_SMR_ID, smr);
>   			smmu->smrs[i].mask = FIELD_GET(ARM_SMMU_SMR_MASK, smr);
>   			smmu->smrs[i].valid = true;
> 

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

* Re: [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
@ 2021-01-26 10:34   ` Robin Murphy
  0 siblings, 0 replies; 8+ messages in thread
From: Robin Murphy @ 2021-01-26 10:34 UTC (permalink / raw)
  To: Isaac J. Manjarres, will, joro, bjorn.andersson
  Cc: linux-arm-kernel, iommu, linux-kernel, stable

On 2021-01-25 21:52, Isaac J. Manjarres wrote:
> When extracting the mask for a SMR that was programmed by the
> bootloader, the SMR's valid bit is also extracted and is treated
> as part of the mask, which is not correct. Consider the scenario
> where an SMMU master whose context is determined by a bootloader
> programmed SMR is removed (omitting parts of device/driver core):
> 
> ->iommu_release_device()
>   -> arm_smmu_release_device()
>    -> arm_smmu_master_free_smes()
>     -> arm_smmu_free_sme() /* Assume that the SME is now free */
>     -> arm_smmu_write_sme()
>      -> arm_smmu_write_smr() /* Construct SMR value using mask and SID */
> 
> Since the valid bit was considered as part of the mask, the SMR will
> be programmed as valid.

Ah, right, because ARM_SMMU_SMR_{ID,MASK} are 16-bit fields to 
accommodate EXIDS, which doesn't matter normally when the IDs are 
strictly validated in arm_smmu_probe_device()...

> Fix the SMR mask extraction step for bootloader programmed SMRs
> by masking out the valid bit when we know that we're already
> working with a valid SMR.

This seems like the neatest approach to me.

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> Fixes: 07a7f2caaa5a ("iommu/arm-smmu-qcom: Read back stream mappings")
> Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
> Cc: stable@vger.kernel.org
> ---
>   drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> index bcda170..abb1d2f 100644
> --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> @@ -206,6 +206,8 @@ static int qcom_smmu_cfg_probe(struct arm_smmu_device *smmu)
>   		smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i));
>   
>   		if (FIELD_GET(ARM_SMMU_SMR_VALID, smr)) {
> +			/* Ignore valid bit for SMR mask extraction. */
> +			smr &= ~ARM_SMMU_SMR_VALID;
>   			smmu->smrs[i].id = FIELD_GET(ARM_SMMU_SMR_ID, smr);
>   			smmu->smrs[i].mask = FIELD_GET(ARM_SMMU_SMR_MASK, smr);
>   			smmu->smrs[i].valid = true;
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
@ 2021-01-26 10:34   ` Robin Murphy
  0 siblings, 0 replies; 8+ messages in thread
From: Robin Murphy @ 2021-01-26 10:34 UTC (permalink / raw)
  To: Isaac J. Manjarres, will, joro, bjorn.andersson
  Cc: linux-arm-kernel, iommu, linux-kernel, stable

On 2021-01-25 21:52, Isaac J. Manjarres wrote:
> When extracting the mask for a SMR that was programmed by the
> bootloader, the SMR's valid bit is also extracted and is treated
> as part of the mask, which is not correct. Consider the scenario
> where an SMMU master whose context is determined by a bootloader
> programmed SMR is removed (omitting parts of device/driver core):
> 
> ->iommu_release_device()
>   -> arm_smmu_release_device()
>    -> arm_smmu_master_free_smes()
>     -> arm_smmu_free_sme() /* Assume that the SME is now free */
>     -> arm_smmu_write_sme()
>      -> arm_smmu_write_smr() /* Construct SMR value using mask and SID */
> 
> Since the valid bit was considered as part of the mask, the SMR will
> be programmed as valid.

Ah, right, because ARM_SMMU_SMR_{ID,MASK} are 16-bit fields to 
accommodate EXIDS, which doesn't matter normally when the IDs are 
strictly validated in arm_smmu_probe_device()...

> Fix the SMR mask extraction step for bootloader programmed SMRs
> by masking out the valid bit when we know that we're already
> working with a valid SMR.

This seems like the neatest approach to me.

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> Fixes: 07a7f2caaa5a ("iommu/arm-smmu-qcom: Read back stream mappings")
> Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
> Cc: stable@vger.kernel.org
> ---
>   drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> index bcda170..abb1d2f 100644
> --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
> @@ -206,6 +206,8 @@ static int qcom_smmu_cfg_probe(struct arm_smmu_device *smmu)
>   		smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i));
>   
>   		if (FIELD_GET(ARM_SMMU_SMR_VALID, smr)) {
> +			/* Ignore valid bit for SMR mask extraction. */
> +			smr &= ~ARM_SMMU_SMR_VALID;
>   			smmu->smrs[i].id = FIELD_GET(ARM_SMMU_SMR_ID, smr);
>   			smmu->smrs[i].mask = FIELD_GET(ARM_SMMU_SMR_MASK, smr);
>   			smmu->smrs[i].valid = true;
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
  2021-01-25 21:52 ` Isaac J. Manjarres
  (?)
@ 2021-01-26 22:35   ` Will Deacon
  -1 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2021-01-26 22:35 UTC (permalink / raw)
  To: robin.murphy, bjorn.andersson, Isaac J. Manjarres, joro
  Cc: catalin.marinas, kernel-team, Will Deacon, linux-kernel, iommu,
	linux-arm-kernel, stable

On Mon, 25 Jan 2021 13:52:25 -0800, Isaac J. Manjarres wrote:
> When extracting the mask for a SMR that was programmed by the
> bootloader, the SMR's valid bit is also extracted and is treated
> as part of the mask, which is not correct. Consider the scenario
> where an SMMU master whose context is determined by a bootloader
> programmed SMR is removed (omitting parts of device/driver core):
> 
> ->iommu_release_device()
>  -> arm_smmu_release_device()
>   -> arm_smmu_master_free_smes()
>    -> arm_smmu_free_sme() /* Assume that the SME is now free */
>    -> arm_smmu_write_sme()
>     -> arm_smmu_write_smr() /* Construct SMR value using mask and SID */
> 
> [...]

Applied to will (for-joerg/arm-smmu/updates), thanks!

[1/1] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
      https://git.kernel.org/will/c/dead723e6f04

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

* Re: [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
@ 2021-01-26 22:35   ` Will Deacon
  0 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2021-01-26 22:35 UTC (permalink / raw)
  To: robin.murphy, bjorn.andersson, Isaac J. Manjarres, joro
  Cc: Will Deacon, catalin.marinas, linux-kernel, stable, iommu,
	kernel-team, linux-arm-kernel

On Mon, 25 Jan 2021 13:52:25 -0800, Isaac J. Manjarres wrote:
> When extracting the mask for a SMR that was programmed by the
> bootloader, the SMR's valid bit is also extracted and is treated
> as part of the mask, which is not correct. Consider the scenario
> where an SMMU master whose context is determined by a bootloader
> programmed SMR is removed (omitting parts of device/driver core):
> 
> ->iommu_release_device()
>  -> arm_smmu_release_device()
>   -> arm_smmu_master_free_smes()
>    -> arm_smmu_free_sme() /* Assume that the SME is now free */
>    -> arm_smmu_write_sme()
>     -> arm_smmu_write_smr() /* Construct SMR value using mask and SID */
> 
> [...]

Applied to will (for-joerg/arm-smmu/updates), thanks!

[1/1] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
      https://git.kernel.org/will/c/dead723e6f04

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
@ 2021-01-26 22:35   ` Will Deacon
  0 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2021-01-26 22:35 UTC (permalink / raw)
  To: robin.murphy, bjorn.andersson, Isaac J. Manjarres, joro
  Cc: Will Deacon, catalin.marinas, linux-kernel, stable, iommu,
	kernel-team, linux-arm-kernel

On Mon, 25 Jan 2021 13:52:25 -0800, Isaac J. Manjarres wrote:
> When extracting the mask for a SMR that was programmed by the
> bootloader, the SMR's valid bit is also extracted and is treated
> as part of the mask, which is not correct. Consider the scenario
> where an SMMU master whose context is determined by a bootloader
> programmed SMR is removed (omitting parts of device/driver core):
> 
> ->iommu_release_device()
>  -> arm_smmu_release_device()
>   -> arm_smmu_master_free_smes()
>    -> arm_smmu_free_sme() /* Assume that the SME is now free */
>    -> arm_smmu_write_sme()
>     -> arm_smmu_write_smr() /* Construct SMR value using mask and SID */
> 
> [...]

Applied to will (for-joerg/arm-smmu/updates), thanks!

[1/1] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs
      https://git.kernel.org/will/c/dead723e6f04

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-01-27 13:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25 21:52 [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs Isaac J. Manjarres
2021-01-25 21:52 ` Isaac J. Manjarres
2021-01-26 10:34 ` Robin Murphy
2021-01-26 10:34   ` Robin Murphy
2021-01-26 10:34   ` Robin Murphy
2021-01-26 22:35 ` Will Deacon
2021-01-26 22:35   ` Will Deacon
2021-01-26 22:35   ` Will Deacon

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.