mbox series

[REBASE,v5,00/17] Add Qualcomm Minidump kernel driver related support

Message ID 1694429639-21484-1-git-send-email-quic_mojha@quicinc.com
Headers show
Series Add Qualcomm Minidump kernel driver related support | expand

Message

Mukesh Ojha Sept. 11, 2023, 10:53 a.m. UTC
Hi All,

I apologise that the last v5 was on sent on older tag and it was reported
that it does not apply to linux-next tag cleanly, thanks to Kathiravan and
Bagas.S for giving me early notice.

I would like continue the conversation happened at v4

https://lore.kernel.org/lkml/632c5b97-4a91-c3e8-1e6c-33d6c4f6454f@quicinc.com/

https://lore.kernel.org/lkml/695133e6-105f-de2a-5559-555cea0a0462@quicinc.com/

We have put abstract on LPC on this topic as well as initiated a mail thread
with other SoC vendors but did not get much traction on it.

https://lore.kernel.org/lkml/0199db00-1b1d-0c63-58ff-03efae02cb21@quicinc.com/

We explored most of possiblity present in kernel to address this issue[1] but
solution like kdump/fadump does not seems safe/secure/performant from our
perspective.

Hence, with this series we tried to make the minidump kernel driver, simple
and tied with pstore frontends, so that it collects the present available
frontends data like dmesg, ftrace, pmsg, ftrace., Also, we will be working
towards enhancing generic pstore to capture more debug data which will be
helpful for first hand of debugging that can benefit both other pstore users
as well as us as minidump users.

One of the proposal made here,
https://lore.kernel.org/lkml/1683561060-2197-1-git-send-email-quic_mojha@quicinc.com/

Looking forward for your comments.

Thanks,
Mukesh

[1]
Minidump is a best effort mechanism to collect useful and predefined data
for first level of debugging on end user devices running on Qualcomm SoCs.
It is built on the premise that System on Chip (SoC) or subsystem part of
SoC crashes, due to a range of hardware and software bugs. Hence, the
ability to collect accurate data is only a best-effort. The data collected
could be invalid or corrupted, data collection itself could fail, and so on.

Qualcomm devices in engineering mode provides a mechanism for generating
full system ramdumps for post mortem debugging. But in some cases it's
however not feasible to capture the entire content of RAM. The minidump
mechanism provides the means for selecting which snippets should be
included in the ramdump.

The core of SMEM based minidump feature is part of Qualcomm's boot
firmware code. It initializes shared memory (SMEM), which is a part of
DDR and allocates a small section of SMEM to minidump table i.e also
called global table of content (G-ToC). Each subsystem (APSS, ADSP, ...)
has their own table of segments to be included in the minidump and all
get their reference from G-ToC. Each segment/region has some details
like name, physical address and it's size etc. and it could be anywhere
scattered in the DDR.

Existing upstream Qualcomm remoteproc driver[1] already supports SMEM
based minidump feature for remoteproc instances like ADSP, MODEM, ...
where predefined selective segments of subsystem region can be dumped
as part of coredump collection which generates smaller size artifacts
compared to complete coredump of subsystem on crash.

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/remoteproc/qcom_common.c#n142

In addition to managing and querying the APSS minidump description,
the Linux driver maintains a ELF header in a segment. This segment
gets updated with section/program header whenever a new entry gets
registered.

Change in rebase v5:
 - Rebased it on latest tag available on linux-next
 - Added missed Poovendhan sign-off on 15/17 and tested-by tag from
   Kathiravan. Thanks to him for testing and reminding me of missing sign-off.

Changes in v5: https://lore.kernel.org/lkml/1694290578-17733-1-git-send-email-quic_mojha@quicinc.com/
 - On suggestion from Pavan.k, to have single function call for minidump collection
   from remoteproc driver, separated the logic to have separate minidump file called
   qcom_rproc_minidump.c and also renamed the function from qcom_minidump() to 
   qcom_rproc_minidump(); however, dropped his suggestion about rework on lazy deletion
   during region unregister in this series, will pursue it in next series.

 - To simplify the minidump driver, removed the complication for frontend and different
   backend from Greg suggestion, will pursue this once main driver gets mainlined.

 - Move the dynamic ramoops region allocation from Device tree approach to command line
   approch with the introduction command line parsing and memblock reservation during
   early boot up; Not added documentation about it yet, will add if it gets positive
   response.

 - Exporting linux banner from kernel to make minidump build also as module, however,
   minidump is a debug module and should be kernel built to get most debug information
   from kernel.

 - Tried to address comments given on dload patch series. 

Changes in v4: https://lore.kernel.org/lkml/1687955688-20809-1-git-send-email-quic_mojha@quicinc.com/
 - Redesigned the driver and divided the driver into front end and backend (smem) so
   that any new backend can be attached easily to avoid code duplication.
 - Patch reordering as per the driver and subsystem to easier review of the code.
 - Removed minidump specific code from remoteproc to minidump smem based driver.
 - Enabled the all the driver as modules.
 - Address comments made on documentation and yaml and Device tree file [Krzysztof/Konrad]
 - Address comments made qcom_pstore_minidump driver and given its Device tree
   same set of properties as ramoops. [Luca/Kees]
 - Added patch for MAINTAINER file.
 - Include defconfig change as one patch as per [Krzysztof] suggestion.
 - Tried to remove the redundant file scope variables from the module as per [Krzysztof] suggestion.
 - Addressed comments made on dload mode patch v6 version
   https://lore.kernel.org/lkml/1680076012-10785-1-git-send-email-quic_mojha@quicinc.com/

Changes in v3: https://lore.kernel.org/lkml/1683133352-10046-1-git-send-email-quic_mojha@quicinc.com/
 - Addressed most of the comments by Srini on v2 and refactored the minidump driver.
    - Added platform device support
    - Unregister region support.
 - Added update region for clients.
 - Added pending region support.
 - Modified the documentation guide accordingly.
 - Added qcom_pstore_ramdump client driver which happen to add ramoops platform
   device and also registers ramoops region with minidump.
 - Added download mode patch series with this minidump series.
    https://lore.kernel.org/lkml/1680076012-10785-1-git-send-email-quic_mojha@quicinc.com/

Changes in v2: https://lore.kernel.org/lkml/1679491817-2498-1-git-send-email-quic_mojha@quicinc.com/
 - Addressed review comment made by [quic_tsoni/bmasney] to add documentation.
 - Addressed comments made by [srinivas.kandagatla]
 - Dropped pstore 6/6 from the last series, till i get conclusion to get pstore
   region in minidump.
 - Fixed issue reported by kernel test robot.

Changes in v1: https://lore.kernel.org/lkml/1676978713-7394-1-git-send-email-quic_mojha@quicinc.com/

Testing of the patches has been done on sm8450 target after enabling config like
CONFIG_PSTORE_RAM and CONFIG_PSTORE_CONSOLE and once the device boots up.

 echo mini > /sys/module/qcom_scm/parameters/download_mode

Try crashing it via devmem2 0xf11c000(this is known to create xpu violation and
and put the device in download mode) on command prompt.

Default storage type is set to via USB, so minidump would be downloaded with the
help of x86_64 machine (running PCAT tool) attached to Qualcomm device which has
backed minidump boot firmware support.

This will make the device go to download mode and collect the minidump on to the
attached x86 machine running the Qualcomm PCAT tool(This comes as part Qualcomm
package manager kit).

After that we will see a bunch of predefined registered region as binary blobs files
starts with md_* downloaded on the x86 machine on given location in PCAT tool from
the target device, more about this can be found in qualcomm minidump guide patch.


Mukesh Ojha (17):
  docs: qcom: Add qualcomm minidump guide
  soc: qcom: Add qcom_rproc_minidump module
  remoteproc: qcom_q6v5_pas: Use qcom_rproc_minidump()
  remoteproc: qcom: Remove minidump related data from qcom_common.c
  init: export linux_banner data variable
  soc: qcom: Add Qualcomm APSS minidump kernel driver
  soc: qcom: minidump: Add pending region registration
  arm64: mm: Add dynamic ramoops region support through command line
  pstore/ram: Use dynamic ramoops reserve resource
  pstore: Add pstore_region_defined() helper and export it
  qcom_minidump: Register ramoops region with minidump
  MAINTAINERS: Add entry for minidump related files
  firmware: qcom_scm: provide a read-modify-write function
  pinctrl: qcom: Use qcom_scm_io_update_field()
  firmware: scm: Modify only the download bits in TCSR register
  firmware: qcom_scm: Refactor code to support multiple download mode
  firmware: qcom_scm: Add multiple download mode support

 Documentation/admin-guide/index.rst         |   1 +
 Documentation/admin-guide/qcom_minidump.rst | 272 +++++++++++
 MAINTAINERS                                 |  10 +
 arch/arm64/mm/init.c                        |  94 ++++
 drivers/firmware/Kconfig                    |  11 -
 drivers/firmware/qcom_scm.c                 |  94 +++-
 drivers/pinctrl/qcom/pinctrl-msm.c          |  10 +-
 drivers/remoteproc/Kconfig                  |   1 +
 drivers/remoteproc/qcom_common.c            | 160 ------
 drivers/remoteproc/qcom_q6v5_pas.c          |   3 +-
 drivers/soc/qcom/Kconfig                    |  24 +
 drivers/soc/qcom/Makefile                   |   3 +
 drivers/soc/qcom/qcom_minidump.c            | 727 ++++++++++++++++++++++++++++
 drivers/soc/qcom/qcom_minidump_internal.h   |  74 +++
 drivers/soc/qcom/qcom_ramoops_minidump.c    |  88 ++++
 drivers/soc/qcom/qcom_ramoops_minidump.h    |  10 +
 drivers/soc/qcom/qcom_rproc_minidump.c      | 111 +++++
 drivers/soc/qcom/smem.c                     |  18 +
 fs/pstore/platform.c                        |  15 +
 fs/pstore/ram.c                             |  52 +-
 include/linux/firmware/qcom/qcom_scm.h      |   2 +
 include/linux/init.h                        |   3 +
 include/linux/pstore.h                      |   6 +
 include/linux/pstore_ram.h                  |   2 +
 include/linux/soc/qcom/smem.h               |   2 +
 include/soc/qcom/qcom_minidump.h            |  56 +++
 init/version-timestamp.c                    |   3 +
 27 files changed, 1663 insertions(+), 189 deletions(-)
 create mode 100644 Documentation/admin-guide/qcom_minidump.rst
 create mode 100644 drivers/soc/qcom/qcom_minidump.c
 create mode 100644 drivers/soc/qcom/qcom_minidump_internal.h
 create mode 100644 drivers/soc/qcom/qcom_ramoops_minidump.c
 create mode 100644 drivers/soc/qcom/qcom_ramoops_minidump.h
 create mode 100644 drivers/soc/qcom/qcom_rproc_minidump.c
 create mode 100644 include/soc/qcom/qcom_minidump.h

Comments

Krzysztof Kozlowski Sept. 11, 2023, 11:03 a.m. UTC | #1
On 11/09/2023 12:53, Mukesh Ojha wrote:

...

> +module_platform_driver(qcom_minidump_driver);
> +
> +MODULE_DESCRIPTION("Qualcomm APSS minidump driver");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:qcom-minidump-smem");

Nothing improved here and in other places. To avoid review being spread
all over, I will just NAK this one.

NAK

Best regards,
Krzysztof
Linus Walleij Sept. 12, 2023, 8:23 a.m. UTC | #2
On Mon, Sep 11, 2023 at 12:56 PM Mukesh Ojha <quic_mojha@quicinc.com> wrote:

> Use qcom_scm_io_update_field() exported function in
> pinctrl-msm driver.
>
> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>

As long as the qcom maintainers agree on the rest of the patches:
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
Will Deacon Sept. 12, 2023, 10:18 a.m. UTC | #3
On Mon, Sep 11, 2023 at 04:23:50PM +0530, Mukesh Ojha wrote:
> The reserved memory region for ramoops is assumed to be at a fixed
> and known location when read from the devicetree. This may not be
> required for something like Qualcomm's minidump which is interested
> in knowing addresses of ramoops region but it does not put hard
> requirement of address being fixed as most of it's SoC does not
> support warm reset and does not use pstorefs at all instead it has
> firmware way of collecting ramoops region if it gets to know the
> address and register it with apss minidump table which is sitting
> in shared memory region in DDR and firmware will have access to
> these table during reset and collects it on crash of SoC.
> 
> So, add the support of reserving ramoops region to be dynamically
> allocated early during boot if it is request through command line
> via 'dyn_ramoops_size=' and fill up reserved resource structure and
> export the structure, so that it can be read by ramoops driver.
> 
> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
> ---
>  arch/arm64/mm/init.c       | 94 ++++++++++++++++++++++++++++++++++++++++++++++

Why does this need to be in the arch code? There's absolutely nothing
arm64-specific here.

Will
Mukesh Ojha Sept. 13, 2023, 7:02 a.m. UTC | #4
Thanks for the response.

On 9/12/2023 3:48 PM, Will Deacon wrote:
> On Mon, Sep 11, 2023 at 04:23:50PM +0530, Mukesh Ojha wrote:
>> The reserved memory region for ramoops is assumed to be at a fixed
>> and known location when read from the devicetree. This may not be
>> required for something like Qualcomm's minidump which is interested
>> in knowing addresses of ramoops region but it does not put hard
>> requirement of address being fixed as most of it's SoC does not
>> support warm reset and does not use pstorefs at all instead it has
>> firmware way of collecting ramoops region if it gets to know the
>> address and register it with apss minidump table which is sitting
>> in shared memory region in DDR and firmware will have access to
>> these table during reset and collects it on crash of SoC.
>>
>> So, add the support of reserving ramoops region to be dynamically
>> allocated early during boot if it is request through command line
>> via 'dyn_ramoops_size=' and fill up reserved resource structure and
>> export the structure, so that it can be read by ramoops driver.
>>
>> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
>> ---
>>   arch/arm64/mm/init.c       | 94 ++++++++++++++++++++++++++++++++++++++++++++++
> 
> Why does this need to be in the arch code? There's absolutely nothing
> arm64-specific here.

Current clients of this cmdline would be only arm64, and that is the
reason of putting this here.

I was checking the places where memblock_phys_alloc_range() gets called
and found either it is arch/*/ and drivers/of/of_reserved_mem.c .

Since, this is not related to device tree, did not find a proper place
than this, i took the reference of this place from
reserve_crashkernel(). Also, not sure how could it be of help to other
non-arch64 users at this point.

-Mukesh
> 
> Will
Will Deacon Sept. 13, 2023, 10:25 a.m. UTC | #5
On Wed, Sep 13, 2023 at 12:32:54PM +0530, Mukesh Ojha wrote:
> Thanks for the response.
> 
> On 9/12/2023 3:48 PM, Will Deacon wrote:
> > On Mon, Sep 11, 2023 at 04:23:50PM +0530, Mukesh Ojha wrote:
> > > The reserved memory region for ramoops is assumed to be at a fixed
> > > and known location when read from the devicetree. This may not be
> > > required for something like Qualcomm's minidump which is interested
> > > in knowing addresses of ramoops region but it does not put hard
> > > requirement of address being fixed as most of it's SoC does not
> > > support warm reset and does not use pstorefs at all instead it has
> > > firmware way of collecting ramoops region if it gets to know the
> > > address and register it with apss minidump table which is sitting
> > > in shared memory region in DDR and firmware will have access to
> > > these table during reset and collects it on crash of SoC.
> > > 
> > > So, add the support of reserving ramoops region to be dynamically
> > > allocated early during boot if it is request through command line
> > > via 'dyn_ramoops_size=' and fill up reserved resource structure and
> > > export the structure, so that it can be read by ramoops driver.
> > > 
> > > Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
> > > ---
> > >   arch/arm64/mm/init.c       | 94 ++++++++++++++++++++++++++++++++++++++++++++++
> > 
> > Why does this need to be in the arch code? There's absolutely nothing
> > arm64-specific here.
> 
> Current clients of this cmdline would be only arm64, and that is the
> reason of putting this here.

I don't think that's a strong enough justification, tbh. We should at
least be able to compile this for other architectures using TEST_COMPILE
and so somewhere under drivers/ makes more sense to me.

Will
Kees Cook Sept. 13, 2023, 11:17 p.m. UTC | #6
On Tue, Sep 12, 2023 at 11:18:20AM +0100, Will Deacon wrote:
> On Mon, Sep 11, 2023 at 04:23:50PM +0530, Mukesh Ojha wrote:
> > The reserved memory region for ramoops is assumed to be at a fixed
> > and known location when read from the devicetree. This may not be
> > required for something like Qualcomm's minidump which is interested
> > in knowing addresses of ramoops region but it does not put hard
> > requirement of address being fixed as most of it's SoC does not
> > support warm reset and does not use pstorefs at all instead it has
> > firmware way of collecting ramoops region if it gets to know the
> > address and register it with apss minidump table which is sitting
> > in shared memory region in DDR and firmware will have access to
> > these table during reset and collects it on crash of SoC.
> > 
> > So, add the support of reserving ramoops region to be dynamically
> > allocated early during boot if it is request through command line
> > via 'dyn_ramoops_size=' and fill up reserved resource structure and
> > export the structure, so that it can be read by ramoops driver.
> > 
> > Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
> > ---
> >  arch/arm64/mm/init.c       | 94 ++++++++++++++++++++++++++++++++++++++++++++++
> 
> Why does this need to be in the arch code? There's absolutely nothing
> arm64-specific here.

I would agree: this needs to be in ramoops itself, IMO. It should be a
ramoops module argument, too.

It being unhelpful for systems that don't have an external consumer is
certainly true, but I think it would still make more sense for this
change to live entirely within ramoops. Specifically: you're
implementing a pstore backend behavioral change. In the same way that
patch 10 is putting the "output" side of this into pstore/, I'd expect
the "input" side also in pstore/

More comments there, though.
Mukesh Ojha Oct. 5, 2023, 11:22 a.m. UTC | #7
Sorry for the late reply, was on a long vacation.

On 9/14/2023 4:47 AM, Kees Cook wrote:
> On Tue, Sep 12, 2023 at 11:18:20AM +0100, Will Deacon wrote:
>> On Mon, Sep 11, 2023 at 04:23:50PM +0530, Mukesh Ojha wrote:
>>> The reserved memory region for ramoops is assumed to be at a fixed
>>> and known location when read from the devicetree. This may not be
>>> required for something like Qualcomm's minidump which is interested
>>> in knowing addresses of ramoops region but it does not put hard
>>> requirement of address being fixed as most of it's SoC does not
>>> support warm reset and does not use pstorefs at all instead it has
>>> firmware way of collecting ramoops region if it gets to know the
>>> address and register it with apss minidump table which is sitting
>>> in shared memory region in DDR and firmware will have access to
>>> these table during reset and collects it on crash of SoC.
>>>
>>> So, add the support of reserving ramoops region to be dynamically
>>> allocated early during boot if it is request through command line
>>> via 'dyn_ramoops_size=' and fill up reserved resource structure and
>>> export the structure, so that it can be read by ramoops driver.
>>>
>>> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
>>> ---
>>>   arch/arm64/mm/init.c       | 94 ++++++++++++++++++++++++++++++++++++++++++++++
>>
>> Why does this need to be in the arch code? There's absolutely nothing
>> arm64-specific here.
> 
> I would agree: this needs to be in ramoops itself, IMO. It should be a
> ramoops module argument, too.
> 
> It being unhelpful for systems that don't have an external consumer is
> certainly true, but I think it would still make more sense for this
> change to live entirely within ramoops. Specifically: you're
> implementing a pstore backend behavioral change. In the same way that
> patch 10 is putting the "output" side of this into pstore/, I'd expect
> the "input" side also in pstore/

How do we reserve memory? are you suggesting to use dma api's for
dynamic ramoops ?

-Mukesh
> 
> More comments there, though.
>
Pavan Kondeti Oct. 5, 2023, 11:44 a.m. UTC | #8
On Thu, Oct 05, 2023 at 04:52:20PM +0530, Mukesh Ojha wrote:
> Sorry for the late reply, was on a long vacation.
> 
> On 9/14/2023 4:47 AM, Kees Cook wrote:
> > On Tue, Sep 12, 2023 at 11:18:20AM +0100, Will Deacon wrote:
> > > On Mon, Sep 11, 2023 at 04:23:50PM +0530, Mukesh Ojha wrote:
> > > > The reserved memory region for ramoops is assumed to be at a fixed
> > > > and known location when read from the devicetree. This may not be
> > > > required for something like Qualcomm's minidump which is interested
> > > > in knowing addresses of ramoops region but it does not put hard
> > > > requirement of address being fixed as most of it's SoC does not
> > > > support warm reset and does not use pstorefs at all instead it has
> > > > firmware way of collecting ramoops region if it gets to know the
> > > > address and register it with apss minidump table which is sitting
> > > > in shared memory region in DDR and firmware will have access to
> > > > these table during reset and collects it on crash of SoC.
> > > > 
> > > > So, add the support of reserving ramoops region to be dynamically
> > > > allocated early during boot if it is request through command line
> > > > via 'dyn_ramoops_size=' and fill up reserved resource structure and
> > > > export the structure, so that it can be read by ramoops driver.
> > > > 
> > > > Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
> > > > ---
> > > >   arch/arm64/mm/init.c       | 94 ++++++++++++++++++++++++++++++++++++++++++++++
> > > 
> > > Why does this need to be in the arch code? There's absolutely nothing
> > > arm64-specific here.
> > 
> > I would agree: this needs to be in ramoops itself, IMO. It should be a
> > ramoops module argument, too.
> > 
> > It being unhelpful for systems that don't have an external consumer is
> > certainly true, but I think it would still make more sense for this
> > change to live entirely within ramoops. Specifically: you're
> > implementing a pstore backend behavioral change. In the same way that
> > patch 10 is putting the "output" side of this into pstore/, I'd expect
> > the "input" side also in pstore/
> 
> How do we reserve memory? are you suggesting to use dma api's for
> dynamic ramoops ?
> 
Sharing my thoughts:

Your patch is inspired from how kexec allocate memory for crash kernel
right? There is a series [1] which moved arch code (ARM64/x86) to
generic kexec core. Something we should also do as the feedback
received here.

Coming to how part, we still have to use memblock API to increase the chance
of allocating contiguous memory. Since PSTORE_RAM can also be
compiled as a module, we probably need another pstore layer that needs to
be built statically in kernel to allocate memory using memblock API.
once slab is available, all memblock API will re-direct to slab
allocations. This layer can be enabled via ARCH_WANTS_PSTORE_xxx or 
another config that only supports 'y'. PSTORE_RAM can still be a module but 
when this layer is available, it supports dynamic ramoops. Another option 
would be just including this layer in PSTORE RAM module but take away module 
option  when this layer is enabled.


[1]
https://lore.kernel.org/all/20211020020317.1220-6-thunder.leizhen@huawei.com/
Mukesh Ojha Oct. 5, 2023, 3:42 p.m. UTC | #9
On 10/5/2023 5:14 PM, Pavan Kondeti wrote:
> On Thu, Oct 05, 2023 at 04:52:20PM +0530, Mukesh Ojha wrote:
>> Sorry for the late reply, was on a long vacation.
>>
>> On 9/14/2023 4:47 AM, Kees Cook wrote:
>>> On Tue, Sep 12, 2023 at 11:18:20AM +0100, Will Deacon wrote:
>>>> On Mon, Sep 11, 2023 at 04:23:50PM +0530, Mukesh Ojha wrote:
>>>>> The reserved memory region for ramoops is assumed to be at a fixed
>>>>> and known location when read from the devicetree. This may not be
>>>>> required for something like Qualcomm's minidump which is interested
>>>>> in knowing addresses of ramoops region but it does not put hard
>>>>> requirement of address being fixed as most of it's SoC does not
>>>>> support warm reset and does not use pstorefs at all instead it has
>>>>> firmware way of collecting ramoops region if it gets to know the
>>>>> address and register it with apss minidump table which is sitting
>>>>> in shared memory region in DDR and firmware will have access to
>>>>> these table during reset and collects it on crash of SoC.
>>>>>
>>>>> So, add the support of reserving ramoops region to be dynamically
>>>>> allocated early during boot if it is request through command line
>>>>> via 'dyn_ramoops_size=' and fill up reserved resource structure and
>>>>> export the structure, so that it can be read by ramoops driver.
>>>>>
>>>>> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
>>>>> ---
>>>>>    arch/arm64/mm/init.c       | 94 ++++++++++++++++++++++++++++++++++++++++++++++
>>>>
>>>> Why does this need to be in the arch code? There's absolutely nothing
>>>> arm64-specific here.
>>>
>>> I would agree: this needs to be in ramoops itself, IMO. It should be a
>>> ramoops module argument, too.
>>>
>>> It being unhelpful for systems that don't have an external consumer is
>>> certainly true, but I think it would still make more sense for this
>>> change to live entirely within ramoops. Specifically: you're
>>> implementing a pstore backend behavioral change. In the same way that
>>> patch 10 is putting the "output" side of this into pstore/, I'd expect
>>> the "input" side also in pstore/
>>
>> How do we reserve memory? are you suggesting to use dma api's for
>> dynamic ramoops ?
>>
> Sharing my thoughts:
> 
> Your patch is inspired from how kexec allocate memory for crash kernel
> right?

Yes.

> There is a series [1] which moved arch code (ARM64/x86) to
> generic kexec core. Something we should also do as the feedback
> received here.
> 
> Coming to how part, we still have to use memblock API to increase the chance
> of allocating contiguous memory. Since PSTORE_RAM can also be
> compiled as a module, we probably need another pstore layer that needs to
> be built statically in kernel to allocate memory using memblock API.
> once slab is available, all memblock API will re-direct to slab
> allocations. This layer can be enabled via ARCH_WANTS_PSTORE_xxx or
> another config that only supports 'y'. PSTORE_RAM can still be a module but
> when this layer is available, it supports dynamic ramoops. Another option
> would be just including this layer in PSTORE RAM module but take away module
> option  when this layer is enabled.

I thought about this but still the caller will be in Arch code,
right ? would that be fine with others ?

-Mukesh
> 
> 
> [1]
> https://lore.kernel.org/all/20211020020317.1220-6-thunder.leizhen@huawei.com/
Pavan Kondeti Oct. 5, 2023, 3:51 p.m. UTC | #10
On Thu, Oct 05, 2023 at 09:12:25PM +0530, Mukesh Ojha wrote:
> 
> 
> On 10/5/2023 5:14 PM, Pavan Kondeti wrote:
> > On Thu, Oct 05, 2023 at 04:52:20PM +0530, Mukesh Ojha wrote:
> > > Sorry for the late reply, was on a long vacation.
> > > 
> > > On 9/14/2023 4:47 AM, Kees Cook wrote:
> > > > On Tue, Sep 12, 2023 at 11:18:20AM +0100, Will Deacon wrote:
> > > > > On Mon, Sep 11, 2023 at 04:23:50PM +0530, Mukesh Ojha wrote:
> > > > > > The reserved memory region for ramoops is assumed to be at a fixed
> > > > > > and known location when read from the devicetree. This may not be
> > > > > > required for something like Qualcomm's minidump which is interested
> > > > > > in knowing addresses of ramoops region but it does not put hard
> > > > > > requirement of address being fixed as most of it's SoC does not
> > > > > > support warm reset and does not use pstorefs at all instead it has
> > > > > > firmware way of collecting ramoops region if it gets to know the
> > > > > > address and register it with apss minidump table which is sitting
> > > > > > in shared memory region in DDR and firmware will have access to
> > > > > > these table during reset and collects it on crash of SoC.
> > > > > > 
> > > > > > So, add the support of reserving ramoops region to be dynamically
> > > > > > allocated early during boot if it is request through command line
> > > > > > via 'dyn_ramoops_size=' and fill up reserved resource structure and
> > > > > > export the structure, so that it can be read by ramoops driver.
> > > > > > 
> > > > > > Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
> > > > > > ---
> > > > > >    arch/arm64/mm/init.c       | 94 ++++++++++++++++++++++++++++++++++++++++++++++
> > > > > 
> > > > > Why does this need to be in the arch code? There's absolutely nothing
> > > > > arm64-specific here.
> > > > 
> > > > I would agree: this needs to be in ramoops itself, IMO. It should be a
> > > > ramoops module argument, too.
> > > > 
> > > > It being unhelpful for systems that don't have an external consumer is
> > > > certainly true, but I think it would still make more sense for this
> > > > change to live entirely within ramoops. Specifically: you're
> > > > implementing a pstore backend behavioral change. In the same way that
> > > > patch 10 is putting the "output" side of this into pstore/, I'd expect
> > > > the "input" side also in pstore/
> > > 
> > > How do we reserve memory? are you suggesting to use dma api's for
> > > dynamic ramoops ?
> > > 
> > Sharing my thoughts:
> > 
> > Your patch is inspired from how kexec allocate memory for crash kernel
> > right?
> 
> Yes.
> 
> > There is a series [1] which moved arch code (ARM64/x86) to
> > generic kexec core. Something we should also do as the feedback
> > received here.
> > 
> > Coming to how part, we still have to use memblock API to increase the chance
> > of allocating contiguous memory. Since PSTORE_RAM can also be
> > compiled as a module, we probably need another pstore layer that needs to
> > be built statically in kernel to allocate memory using memblock API.
> > once slab is available, all memblock API will re-direct to slab
> > allocations. This layer can be enabled via ARCH_WANTS_PSTORE_xxx or
> > another config that only supports 'y'. PSTORE_RAM can still be a module but
> > when this layer is available, it supports dynamic ramoops. Another option
> > would be just including this layer in PSTORE RAM module but take away module
> > option  when this layer is enabled.
> 
> I thought about this but still the caller will be in Arch code,
> right ? would that be fine with others ?
> 

The caller is not necessarily to be in the arch code. For ex:
mm_core_init()->kfence_alloc_pool_and_metadata()

> > 
> > 
> > [1]
> > https://lore.kernel.org/all/20211020020317.1220-6-thunder.leizhen@huawei.com/