diff mbox series

[v4,07/21] soc: qcom: minidump: Add update region support

Message ID 1687955688-20809-8-git-send-email-quic_mojha@quicinc.com
State New
Headers show
Series [v4,01/21] docs: qcom: Add qualcomm minidump guide | expand

Commit Message

Mukesh Ojha June 28, 2023, 12:34 p.m. UTC
Add support to update client's region physical/virtual addresses,
which is useful for dynamic loadable modules, dynamic address
changing clients like if we want to collect current stack
information for each core and the current stack is changing on
each sched_switch event, So here virtual/physical address of
the current stack is changing. So, to cover such use cases
add the update region support in minidump driver and the
corresponding smem backend support.

Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
---
 drivers/soc/qcom/qcom_minidump.c          | 55 +++++++++++++++++++++++++++++++
 drivers/soc/qcom/qcom_minidump_internal.h |  3 ++
 drivers/soc/qcom/qcom_minidump_smem.c     | 21 ++++++++++++
 include/soc/qcom/qcom_minidump.h          |  5 +++
 4 files changed, 84 insertions(+)

Comments

Pavan Kondeti June 29, 2023, 2:49 a.m. UTC | #1
On Wed, Jun 28, 2023 at 06:04:34PM +0530, Mukesh Ojha wrote:
> Add support to update client's region physical/virtual addresses,
> which is useful for dynamic loadable modules, dynamic address
> changing clients like if we want to collect current stack
> information for each core and the current stack is changing on
> each sched_switch event, So here virtual/physical address of
> the current stack is changing. So, to cover such use cases
> add the update region support in minidump driver and the
> corresponding smem backend support.
> 
> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
> ---
>  drivers/soc/qcom/qcom_minidump.c          | 55 +++++++++++++++++++++++++++++++
>  drivers/soc/qcom/qcom_minidump_internal.h |  3 ++
>  drivers/soc/qcom/qcom_minidump_smem.c     | 21 ++++++++++++
>  include/soc/qcom/qcom_minidump.h          |  5 +++
>  4 files changed, 84 insertions(+)
> 
> diff --git a/drivers/soc/qcom/qcom_minidump.c b/drivers/soc/qcom/qcom_minidump.c
> index cfdb63cc29d6..37d6ceb4d85c 100644
> --- a/drivers/soc/qcom/qcom_minidump.c
> +++ b/drivers/soc/qcom/qcom_minidump.c
> @@ -318,6 +318,61 @@ int qcom_minidump_region_unregister(const struct qcom_minidump_region *region)
>  }
>  EXPORT_SYMBOL_GPL(qcom_minidump_region_unregister);
>  
> +/**
> + * qcom_minidump_update_region() - Update region information with new physical
> + * address and virtual address for already registered region e.g, current task
> + * stack for a core keeps on changing on each context switch, there it needs to
> + * change registered region with new updated addresses.
> + *
> + * @region: Should be already registered minidump region.
> + *
> + * Return: On success, it returns 0 and negative error value on failure.
> + */
> +int qcom_minidump_update_region(const struct qcom_minidump_region *region)
> +{
> +	struct minidump_pregion *md_pregion;
> +	struct qcom_minidump_region *tmp;
> +	struct elfhdr *ehdr;
> +	struct elf_shdr *shdr;
> +	struct elf_phdr *phdr;
> +	int idx;
> +	int ret = 0;
> +
> +	if (!qcom_minidump_valid_region(region))
> +		return -EINVAL;
> +
> +	mutex_lock(&md_lock);
> +	if (!md) {
> +		md_pregion = check_if_pending_region_exist(region);
> +		if (!md_pregion) {
> +			ret = -ENOENT;
> +			goto unlock;
> +		}
> +		tmp = &md_pregion->region;
> +		tmp->phys_addr = region->phys_addr;
> +		tmp->virt_addr = region->virt_addr;
> +		goto unlock;
> +	}
> +
> +	ret = md->ops->md_update_region(md, &idx, region);
> +	if (ret)
> +		goto unlock;
> +
> +	/* Skip predefined shdr/phdr header entry at the start */
> +	ehdr = md->elf.ehdr;
> +	shdr = elf_shdr_entry_addr(ehdr, idx + 4);
> +	phdr = elf_phdr_entry_addr(ehdr, idx + 1);
> +
> +	shdr->sh_addr = (elf_addr_t)region->virt_addr;
> +	phdr->p_vaddr = (elf_addr_t)region->virt_addr;
> +	phdr->p_paddr = region->phys_addr;
> +
> +unlock:
> +	mutex_unlock(&md_lock);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(qcom_minidump_update_region);
> +

I don't see any use of this API in the series. Do you plan to add one in
the next version?

Thanks,
Pavan
diff mbox series

Patch

diff --git a/drivers/soc/qcom/qcom_minidump.c b/drivers/soc/qcom/qcom_minidump.c
index cfdb63cc29d6..37d6ceb4d85c 100644
--- a/drivers/soc/qcom/qcom_minidump.c
+++ b/drivers/soc/qcom/qcom_minidump.c
@@ -318,6 +318,61 @@  int qcom_minidump_region_unregister(const struct qcom_minidump_region *region)
 }
 EXPORT_SYMBOL_GPL(qcom_minidump_region_unregister);
 
+/**
+ * qcom_minidump_update_region() - Update region information with new physical
+ * address and virtual address for already registered region e.g, current task
+ * stack for a core keeps on changing on each context switch, there it needs to
+ * change registered region with new updated addresses.
+ *
+ * @region: Should be already registered minidump region.
+ *
+ * Return: On success, it returns 0 and negative error value on failure.
+ */
+int qcom_minidump_update_region(const struct qcom_minidump_region *region)
+{
+	struct minidump_pregion *md_pregion;
+	struct qcom_minidump_region *tmp;
+	struct elfhdr *ehdr;
+	struct elf_shdr *shdr;
+	struct elf_phdr *phdr;
+	int idx;
+	int ret = 0;
+
+	if (!qcom_minidump_valid_region(region))
+		return -EINVAL;
+
+	mutex_lock(&md_lock);
+	if (!md) {
+		md_pregion = check_if_pending_region_exist(region);
+		if (!md_pregion) {
+			ret = -ENOENT;
+			goto unlock;
+		}
+		tmp = &md_pregion->region;
+		tmp->phys_addr = region->phys_addr;
+		tmp->virt_addr = region->virt_addr;
+		goto unlock;
+	}
+
+	ret = md->ops->md_update_region(md, &idx, region);
+	if (ret)
+		goto unlock;
+
+	/* Skip predefined shdr/phdr header entry at the start */
+	ehdr = md->elf.ehdr;
+	shdr = elf_shdr_entry_addr(ehdr, idx + 4);
+	phdr = elf_phdr_entry_addr(ehdr, idx + 1);
+
+	shdr->sh_addr = (elf_addr_t)region->virt_addr;
+	phdr->p_vaddr = (elf_addr_t)region->virt_addr;
+	phdr->p_paddr = region->phys_addr;
+
+unlock:
+	mutex_unlock(&md_lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(qcom_minidump_update_region);
+
 static int qcom_minidump_add_elf_header(struct minidump *md_data)
 {
 	struct qcom_minidump_region elfregion;
diff --git a/drivers/soc/qcom/qcom_minidump_internal.h b/drivers/soc/qcom/qcom_minidump_internal.h
index 6993e3be10c2..dc1e76c1f063 100644
--- a/drivers/soc/qcom/qcom_minidump_internal.h
+++ b/drivers/soc/qcom/qcom_minidump_internal.h
@@ -21,6 +21,7 @@  struct minidump;
  * @md_table_exit:	  Clean up the stuff populated while md_table_init()
  * @md_region_register:	  Callback to register the region at the backend.
  * @md_region_unregister: Callback to unregister the region at the backend.
+ * @md_update_region:	  Callback to update address of already registered regions.
  */
 struct minidump_ops {
 	int (*md_table_init)(struct minidump *md);
@@ -29,6 +30,8 @@  struct minidump_ops {
 				 const struct qcom_minidump_region *region);
 	int (*md_region_unregister)(struct minidump *md,
 				 const struct qcom_minidump_region *region);
+	int (*md_update_region)(struct minidump *md, int *idx,
+                                 const struct qcom_minidump_region *region);
 };
 
 /**
diff --git a/drivers/soc/qcom/qcom_minidump_smem.c b/drivers/soc/qcom/qcom_minidump_smem.c
index bdc75aa2f518..9d4021a5e4c8 100644
--- a/drivers/soc/qcom/qcom_minidump_smem.c
+++ b/drivers/soc/qcom/qcom_minidump_smem.c
@@ -263,6 +263,26 @@  static int smem_md_region_unregister(struct minidump *md,
 	return 0;
 }
 
+static int smem_md_update_region(struct minidump *md, int *idx,
+				 const struct qcom_minidump_region *region)
+{
+	struct minidump_ss_data *mdss_data = md->apss_data;
+	struct minidump_region *mdr;
+	int ret;
+
+	ret = smem_md_get_region_index(mdss_data, region);
+	if (ret < 0) {
+		dev_err(md->dev, "%s region is not present\n", region->name);
+		return ret;
+	}
+
+	*idx = ret;
+	mdr = &mdss_data->md_regions[*idx];
+	mdr->address = cpu_to_le64(region->phys_addr);
+
+	return 0;
+}
+
 static int smem_md_table_init(struct minidump *md)
 {
 	struct minidump_global_toc *mdgtoc;
@@ -324,6 +344,7 @@  static struct minidump_ops smem_md_ops = {
 	.md_table_exit		= smem_md_table_exit,
 	.md_region_register	= smem_md_region_register,
 	.md_region_unregister	= smem_md_region_unregister,
+	.md_update_region	= smem_md_update_region,
 };
 
 static int qcom_minidump_smem_probe(struct platform_device *pdev)
diff --git a/include/soc/qcom/qcom_minidump.h b/include/soc/qcom/qcom_minidump.h
index d0bebc3daac5..a86b0313698f 100644
--- a/include/soc/qcom/qcom_minidump.h
+++ b/include/soc/qcom/qcom_minidump.h
@@ -29,6 +29,7 @@  struct qcom_minidump_region {
 #if IS_ENABLED(CONFIG_QCOM_MINIDUMP)
 int qcom_minidump_region_register(const struct qcom_minidump_region *region);
 int qcom_minidump_region_unregister(const struct qcom_minidump_region *region);
+int qcom_minidump_update_region(const struct qcom_minidump_region *region);
 #else
 static inline int qcom_minidump_region_register(const struct qcom_minidump_region *region)
 {
@@ -39,6 +40,10 @@  static inline int qcom_minidump_region_unregister(const struct qcom_minidump_reg
 {
 	return 0;
 }
+static inline int qcom_minidump_update_region(const struct qcom_minidump_region *region)
+{
+	return 0;
+}
 #endif /* CONFIG_QCOM_MINIDUMP */
 
 #if IS_ENABLED(CONFIG_QCOM_MINIDUMP_SMEM)