LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] remoteproc: qcom_q6v5_mss: Replace ioremap with memremap
@ 2020-11-04  7:03 Sibi Sankar
  2020-11-04  7:03 ` [PATCH 2/2] remoteproc: qcom_q6v5_mss: map/unmap MBA region before/after use Sibi Sankar
  2020-11-18 17:58 ` [PATCH 1/2] remoteproc: qcom_q6v5_mss: Replace ioremap with memremap Bjorn Andersson
  0 siblings, 2 replies; 4+ messages in thread
From: Sibi Sankar @ 2020-11-04  7:03 UTC (permalink / raw)
  To: bjorn.andersson
  Cc: ohad, linux-arm-msm, linux-remoteproc, linux-kernel, agross,
	evgreen, Sibi Sankar

Fix the sparse warnings reported by the kernel test bot by replacing
ioremap calls with memremap.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sibi Sankar <sibis@codeaurora.org>
---

I'll send out the patches to convert ioremap to memremap on other
qc remoteproc drivers once I get a chance to test them.

 drivers/remoteproc/qcom_q6v5_mss.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
index 9a473cfef758..2c866b6da23c 100644
--- a/drivers/remoteproc/qcom_q6v5_mss.c
+++ b/drivers/remoteproc/qcom_q6v5_mss.c
@@ -1194,7 +1194,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
 			goto release_firmware;
 		}
 
-		ptr = ioremap_wc(qproc->mpss_phys + offset, phdr->p_memsz);
+		ptr = memremap(qproc->mpss_phys + offset, phdr->p_memsz, MEMREMAP_WC);
 		if (!ptr) {
 			dev_err(qproc->dev,
 				"unable to map memory region: %pa+%zx-%x\n",
@@ -1209,7 +1209,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
 					"failed to load segment %d from truncated file %s\n",
 					i, fw_name);
 				ret = -EINVAL;
-				iounmap(ptr);
+				memunmap(ptr);
 				goto release_firmware;
 			}
 
@@ -1221,7 +1221,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
 							ptr, phdr->p_filesz);
 			if (ret) {
 				dev_err(qproc->dev, "failed to load %s\n", fw_name);
-				iounmap(ptr);
+				memunmap(ptr);
 				goto release_firmware;
 			}
 
@@ -1232,7 +1232,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
 			memset(ptr + phdr->p_filesz, 0,
 			       phdr->p_memsz - phdr->p_filesz);
 		}
-		iounmap(ptr);
+		memunmap(ptr);
 		size += phdr->p_memsz;
 
 		code_length = readl(qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG);
@@ -1299,11 +1299,11 @@ static void qcom_q6v5_dump_segment(struct rproc *rproc,
 	}
 
 	if (!ret)
-		ptr = ioremap_wc(qproc->mpss_phys + offset + cp_offset, size);
+		ptr = memremap(qproc->mpss_phys + offset + cp_offset, size, MEMREMAP_WC);
 
 	if (ptr) {
 		memcpy(dest, ptr, size);
-		iounmap(ptr);
+		memunmap(ptr);
 	} else {
 		memset(dest, 0xff, size);
 	}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


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

* [PATCH 2/2] remoteproc: qcom_q6v5_mss: map/unmap MBA region before/after use
  2020-11-04  7:03 [PATCH 1/2] remoteproc: qcom_q6v5_mss: Replace ioremap with memremap Sibi Sankar
@ 2020-11-04  7:03 ` Sibi Sankar
  2020-11-24 16:22   ` Bjorn Andersson
  2020-11-18 17:58 ` [PATCH 1/2] remoteproc: qcom_q6v5_mss: Replace ioremap with memremap Bjorn Andersson
  1 sibling, 1 reply; 4+ messages in thread
From: Sibi Sankar @ 2020-11-04  7:03 UTC (permalink / raw)
  To: bjorn.andersson
  Cc: ohad, linux-arm-msm, linux-remoteproc, linux-kernel, agross,
	evgreen, Sibi Sankar

The application processor accessing the MBA region after assigning it to
the remote Q6 would lead to an XPU violation. Fix this by un-mapping the
MBA region post firmware copy and MBA text log dumps.

Signed-off-by: Sibi Sankar <sibis@codeaurora.org>
---
 drivers/remoteproc/qcom_q6v5_mss.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
index 2c866b6da23c..1b4a34325788 100644
--- a/drivers/remoteproc/qcom_q6v5_mss.c
+++ b/drivers/remoteproc/qcom_q6v5_mss.c
@@ -189,7 +189,6 @@ struct q6v5 {
 	size_t total_dump_size;
 
 	phys_addr_t mba_phys;
-	void *mba_region;
 	size_t mba_size;
 	size_t dp_size;
 
@@ -408,7 +407,7 @@ static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm,
 				   current_perm, next, perms);
 }
 
-static void q6v5_debug_policy_load(struct q6v5 *qproc)
+static void q6v5_debug_policy_load(struct q6v5 *qproc, void *ptr)
 {
 	const struct firmware *dp_fw;
 
@@ -416,7 +415,7 @@ static void q6v5_debug_policy_load(struct q6v5 *qproc)
 		return;
 
 	if (SZ_1M + dp_fw->size <= qproc->mba_size) {
-		memcpy(qproc->mba_region + SZ_1M, dp_fw->data, dp_fw->size);
+		memcpy(ptr + SZ_1M, dp_fw->data, dp_fw->size);
 		qproc->dp_size = dp_fw->size;
 	}
 
@@ -426,6 +425,7 @@ static void q6v5_debug_policy_load(struct q6v5 *qproc)
 static int q6v5_load(struct rproc *rproc, const struct firmware *fw)
 {
 	struct q6v5 *qproc = rproc->priv;
+	void *ptr;
 
 	/* MBA is restricted to a maximum size of 1M */
 	if (fw->size > qproc->mba_size || fw->size > SZ_1M) {
@@ -433,8 +433,16 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw)
 		return -EINVAL;
 	}
 
-	memcpy(qproc->mba_region, fw->data, fw->size);
-	q6v5_debug_policy_load(qproc);
+	ptr = memremap(qproc->mba_phys, qproc->mba_size, MEMREMAP_WC);
+	if (!ptr) {
+		dev_err(qproc->dev, "unable to map memory region: %pa+%zx\n",
+			&qproc->mba_phys, qproc->mba_size);
+		return -EBUSY;
+	}
+
+	memcpy(ptr, fw->data, fw->size);
+	q6v5_debug_policy_load(qproc, ptr);
+	memunmap(ptr);
 
 	return 0;
 }
@@ -541,6 +549,7 @@ static void q6v5_dump_mba_logs(struct q6v5 *qproc)
 {
 	struct rproc *rproc = qproc->rproc;
 	void *data;
+	void *ptr;
 
 	if (!qproc->has_mba_logs)
 		return;
@@ -549,12 +558,16 @@ static void q6v5_dump_mba_logs(struct q6v5 *qproc)
 				    qproc->mba_size))
 		return;
 
-	data = vmalloc(MBA_LOG_SIZE);
-	if (!data)
+	ptr = memremap(qproc->mba_phys, qproc->mba_size, MEMREMAP_WC);
+	if (!ptr)
 		return;
 
-	memcpy(data, qproc->mba_region, MBA_LOG_SIZE);
-	dev_coredumpv(&rproc->dev, data, MBA_LOG_SIZE, GFP_KERNEL);
+	data = vmalloc(MBA_LOG_SIZE);
+	if (data) {
+		memcpy(data, ptr, MBA_LOG_SIZE);
+		dev_coredumpv(&rproc->dev, data, MBA_LOG_SIZE, GFP_KERNEL);
+	}
+	memunmap(ptr);
 }
 
 static int q6v5proc_reset(struct q6v5 *qproc)
@@ -1605,12 +1618,6 @@ static int q6v5_alloc_memory_region(struct q6v5 *qproc)
 
 	qproc->mba_phys = r.start;
 	qproc->mba_size = resource_size(&r);
-	qproc->mba_region = devm_ioremap_wc(qproc->dev, qproc->mba_phys, qproc->mba_size);
-	if (!qproc->mba_region) {
-		dev_err(qproc->dev, "unable to map memory region: %pa+%zx\n",
-			&r.start, qproc->mba_size);
-		return -EBUSY;
-	}
 
 	if (!child) {
 		node = of_parse_phandle(qproc->dev->of_node,
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


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

* Re: [PATCH 1/2] remoteproc: qcom_q6v5_mss: Replace ioremap with memremap
  2020-11-04  7:03 [PATCH 1/2] remoteproc: qcom_q6v5_mss: Replace ioremap with memremap Sibi Sankar
  2020-11-04  7:03 ` [PATCH 2/2] remoteproc: qcom_q6v5_mss: map/unmap MBA region before/after use Sibi Sankar
@ 2020-11-18 17:58 ` Bjorn Andersson
  1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Andersson @ 2020-11-18 17:58 UTC (permalink / raw)
  To: Sibi Sankar
  Cc: ohad, linux-arm-msm, linux-remoteproc, linux-kernel, agross, evgreen

On Wed 04 Nov 01:03 CST 2020, Sibi Sankar wrote:

> Fix the sparse warnings reported by the kernel test bot by replacing
> ioremap calls with memremap.
> 
> Reported-by: kernel test robot <lkp@intel.com>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> Signed-off-by: Sibi Sankar <sibis@codeaurora.org>
> ---
> 
> I'll send out the patches to convert ioremap to memremap on other
> qc remoteproc drivers once I get a chance to test them.
> 
>  drivers/remoteproc/qcom_q6v5_mss.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
> index 9a473cfef758..2c866b6da23c 100644
> --- a/drivers/remoteproc/qcom_q6v5_mss.c
> +++ b/drivers/remoteproc/qcom_q6v5_mss.c
> @@ -1194,7 +1194,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
>  			goto release_firmware;
>  		}
>  
> -		ptr = ioremap_wc(qproc->mpss_phys + offset, phdr->p_memsz);
> +		ptr = memremap(qproc->mpss_phys + offset, phdr->p_memsz, MEMREMAP_WC);
>  		if (!ptr) {
>  			dev_err(qproc->dev,
>  				"unable to map memory region: %pa+%zx-%x\n",
> @@ -1209,7 +1209,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
>  					"failed to load segment %d from truncated file %s\n",
>  					i, fw_name);
>  				ret = -EINVAL;
> -				iounmap(ptr);
> +				memunmap(ptr);
>  				goto release_firmware;
>  			}
>  
> @@ -1221,7 +1221,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
>  							ptr, phdr->p_filesz);
>  			if (ret) {
>  				dev_err(qproc->dev, "failed to load %s\n", fw_name);
> -				iounmap(ptr);
> +				memunmap(ptr);
>  				goto release_firmware;
>  			}
>  
> @@ -1232,7 +1232,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)
>  			memset(ptr + phdr->p_filesz, 0,
>  			       phdr->p_memsz - phdr->p_filesz);
>  		}
> -		iounmap(ptr);
> +		memunmap(ptr);
>  		size += phdr->p_memsz;
>  
>  		code_length = readl(qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG);
> @@ -1299,11 +1299,11 @@ static void qcom_q6v5_dump_segment(struct rproc *rproc,
>  	}
>  
>  	if (!ret)
> -		ptr = ioremap_wc(qproc->mpss_phys + offset + cp_offset, size);
> +		ptr = memremap(qproc->mpss_phys + offset + cp_offset, size, MEMREMAP_WC);
>  
>  	if (ptr) {
>  		memcpy(dest, ptr, size);
> -		iounmap(ptr);
> +		memunmap(ptr);
>  	} else {
>  		memset(dest, 0xff, size);
>  	}
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

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

* Re: [PATCH 2/2] remoteproc: qcom_q6v5_mss: map/unmap MBA region before/after use
  2020-11-04  7:03 ` [PATCH 2/2] remoteproc: qcom_q6v5_mss: map/unmap MBA region before/after use Sibi Sankar
@ 2020-11-24 16:22   ` Bjorn Andersson
  0 siblings, 0 replies; 4+ messages in thread
From: Bjorn Andersson @ 2020-11-24 16:22 UTC (permalink / raw)
  To: Sibi Sankar
  Cc: ohad, linux-arm-msm, linux-remoteproc, linux-kernel, agross, evgreen

On Wed 04 Nov 01:03 CST 2020, Sibi Sankar wrote:

> The application processor accessing the MBA region after assigning it to
> the remote Q6 would lead to an XPU violation. Fix this by un-mapping the
> MBA region post firmware copy and MBA text log dumps.
> 
> Signed-off-by: Sibi Sankar <sibis@codeaurora.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

I renamed "ptr" to "mba_region" throughout the patch and applied the
pair.

Thanks,
Bjorn

> ---
>  drivers/remoteproc/qcom_q6v5_mss.c | 37 ++++++++++++++++++++++---------------
>  1 file changed, 22 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
> index 2c866b6da23c..1b4a34325788 100644
> --- a/drivers/remoteproc/qcom_q6v5_mss.c
> +++ b/drivers/remoteproc/qcom_q6v5_mss.c
> @@ -189,7 +189,6 @@ struct q6v5 {
>  	size_t total_dump_size;
>  
>  	phys_addr_t mba_phys;
> -	void *mba_region;
>  	size_t mba_size;
>  	size_t dp_size;
>  
> @@ -408,7 +407,7 @@ static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm,
>  				   current_perm, next, perms);
>  }
>  
> -static void q6v5_debug_policy_load(struct q6v5 *qproc)
> +static void q6v5_debug_policy_load(struct q6v5 *qproc, void *ptr)
>  {
>  	const struct firmware *dp_fw;
>  
> @@ -416,7 +415,7 @@ static void q6v5_debug_policy_load(struct q6v5 *qproc)
>  		return;
>  
>  	if (SZ_1M + dp_fw->size <= qproc->mba_size) {
> -		memcpy(qproc->mba_region + SZ_1M, dp_fw->data, dp_fw->size);
> +		memcpy(ptr + SZ_1M, dp_fw->data, dp_fw->size);
>  		qproc->dp_size = dp_fw->size;
>  	}
>  
> @@ -426,6 +425,7 @@ static void q6v5_debug_policy_load(struct q6v5 *qproc)
>  static int q6v5_load(struct rproc *rproc, const struct firmware *fw)
>  {
>  	struct q6v5 *qproc = rproc->priv;
> +	void *ptr;
>  
>  	/* MBA is restricted to a maximum size of 1M */
>  	if (fw->size > qproc->mba_size || fw->size > SZ_1M) {
> @@ -433,8 +433,16 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw)
>  		return -EINVAL;
>  	}
>  
> -	memcpy(qproc->mba_region, fw->data, fw->size);
> -	q6v5_debug_policy_load(qproc);
> +	ptr = memremap(qproc->mba_phys, qproc->mba_size, MEMREMAP_WC);
> +	if (!ptr) {
> +		dev_err(qproc->dev, "unable to map memory region: %pa+%zx\n",
> +			&qproc->mba_phys, qproc->mba_size);
> +		return -EBUSY;
> +	}
> +
> +	memcpy(ptr, fw->data, fw->size);
> +	q6v5_debug_policy_load(qproc, ptr);
> +	memunmap(ptr);
>  
>  	return 0;
>  }
> @@ -541,6 +549,7 @@ static void q6v5_dump_mba_logs(struct q6v5 *qproc)
>  {
>  	struct rproc *rproc = qproc->rproc;
>  	void *data;
> +	void *ptr;
>  
>  	if (!qproc->has_mba_logs)
>  		return;
> @@ -549,12 +558,16 @@ static void q6v5_dump_mba_logs(struct q6v5 *qproc)
>  				    qproc->mba_size))
>  		return;
>  
> -	data = vmalloc(MBA_LOG_SIZE);
> -	if (!data)
> +	ptr = memremap(qproc->mba_phys, qproc->mba_size, MEMREMAP_WC);
> +	if (!ptr)
>  		return;
>  
> -	memcpy(data, qproc->mba_region, MBA_LOG_SIZE);
> -	dev_coredumpv(&rproc->dev, data, MBA_LOG_SIZE, GFP_KERNEL);
> +	data = vmalloc(MBA_LOG_SIZE);
> +	if (data) {
> +		memcpy(data, ptr, MBA_LOG_SIZE);
> +		dev_coredumpv(&rproc->dev, data, MBA_LOG_SIZE, GFP_KERNEL);
> +	}
> +	memunmap(ptr);
>  }
>  
>  static int q6v5proc_reset(struct q6v5 *qproc)
> @@ -1605,12 +1618,6 @@ static int q6v5_alloc_memory_region(struct q6v5 *qproc)
>  
>  	qproc->mba_phys = r.start;
>  	qproc->mba_size = resource_size(&r);
> -	qproc->mba_region = devm_ioremap_wc(qproc->dev, qproc->mba_phys, qproc->mba_size);
> -	if (!qproc->mba_region) {
> -		dev_err(qproc->dev, "unable to map memory region: %pa+%zx\n",
> -			&r.start, qproc->mba_size);
> -		return -EBUSY;
> -	}
>  
>  	if (!child) {
>  		node = of_parse_phandle(qproc->dev->of_node,
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-04  7:03 [PATCH 1/2] remoteproc: qcom_q6v5_mss: Replace ioremap with memremap Sibi Sankar
2020-11-04  7:03 ` [PATCH 2/2] remoteproc: qcom_q6v5_mss: map/unmap MBA region before/after use Sibi Sankar
2020-11-24 16:22   ` Bjorn Andersson
2020-11-18 17:58 ` [PATCH 1/2] remoteproc: qcom_q6v5_mss: Replace ioremap with memremap Bjorn Andersson

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git
	git clone --mirror https://lore.kernel.org/lkml/10 lkml/git/10.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git