diff mbox series

pstore/ram: Improve backward compatibility with older Chromebooks

Message ID 20190503174730.245762-1-dianders@chromium.org (mailing list archive)
State New, archived
Headers show
Series pstore/ram: Improve backward compatibility with older Chromebooks | expand

Commit Message

Douglas Anderson May 3, 2019, 5:47 p.m. UTC
When you try to run an upstream kernel on an old ARM-based Chromebook
you'll find that console-ramoops doesn't work.

Old ARM-based Chromebooks, before <https://crrev.com/c/439792>
("ramoops: support upstream {console,pmsg,ftrace}-size properties")
used to create a "ramoops" node at the top level that looked like:

/ {
  ramoops {
    compatible = "ramoops";
    reg = <...>;
    record-size = <...>;
    dump-oops;
  };
};

...and these Chromebooks assumed that the downstream kernel would make
console_size / pmsg_size match the record size.  The above ramoops
node was added by the firmware so it's not easy to make any changes.

Let's match the expected behavior, but only for those using the old
backward-compatible way of working where ramoops is right under the
root node.

NOTE: if there are some out-of-tree devices that had ramoops at the
top level, left everything but the record size as 0, and somehow
doesn't want this behavior, we can try to add more conditions here.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 fs/pstore/ram.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Guenter Roeck May 3, 2019, 7:06 p.m. UTC | #1
On Fri, May 3, 2019 at 10:48 AM Douglas Anderson <dianders@chromium.org> wrote:
>
> When you try to run an upstream kernel on an old ARM-based Chromebook
> you'll find that console-ramoops doesn't work.
>
> Old ARM-based Chromebooks, before <https://crrev.com/c/439792>
> ("ramoops: support upstream {console,pmsg,ftrace}-size properties")
> used to create a "ramoops" node at the top level that looked like:
>
> / {
>   ramoops {
>     compatible = "ramoops";
>     reg = <...>;
>     record-size = <...>;
>     dump-oops;
>   };
> };
>
> ...and these Chromebooks assumed that the downstream kernel would make
> console_size / pmsg_size match the record size.  The above ramoops
> node was added by the firmware so it's not easy to make any changes.
>
> Let's match the expected behavior, but only for those using the old
> backward-compatible way of working where ramoops is right under the
> root node.
>
> NOTE: if there are some out-of-tree devices that had ramoops at the
> top level, left everything but the record size as 0, and somehow
> doesn't want this behavior, we can try to add more conditions here.
>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

Reviewed-by: Guenter Roeck <groeck@chromium.org>

> ---
>
>  fs/pstore/ram.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index c5c685589e36..8df3bfa2837f 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -669,6 +669,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
>                             struct ramoops_platform_data *pdata)
>  {
>         struct device_node *of_node = pdev->dev.of_node;
> +       struct device_node *parent_node;
>         struct resource *res;
>         u32 value;
>         int ret;
> @@ -703,6 +704,23 @@ static int ramoops_parse_dt(struct platform_device *pdev,
>
>  #undef parse_size
>
> +       /*
> +        * Some old Chromebooks relied on the kernel setting the console_size
> +        * and pmsg_size to the record size since that's what the downstream
> +        * kernel did.  These same Chromebooks had "ramoops" straight under
> +        * the root node which isn't according to the upstream bindings.  Let's
> +        * make those old Chromebooks work by detecting this and mimicing the
> +        * expected behavior.
> +        */
> +       parent_node = of_get_parent(of_node);
> +       if (of_node_is_root(parent_node) &&
> +           !pdata->console_size && !pdata->ftrace_size &&
> +           !pdata->pmsg_size && !pdata->ecc_info.ecc_size) {
> +               pdata->console_size = pdata->record_size;
> +               pdata->pmsg_size = pdata->record_size;
> +       }
> +       of_node_put(parent_node);
> +
>         return 0;
>  }
>
> --
> 2.21.0.1020.gf2820cf01a-goog
>
Kees Cook May 6, 2019, 9:09 p.m. UTC | #2
From: Douglas Anderson <dianders@chromium.org>
Date: Fri, May 3, 2019 at 10:48 AM
To: Kees Cook, Anton Vorontsov
Cc: <linux-rockchip@lists.infradead.org>, <jwerner@chromium.org>,
<groeck@chromium.org>, <mka@chromium.org>, <briannorris@chromium.org>,
Douglas Anderson, Colin Cross, Tony Luck,
<linux-kernel@vger.kernel.org>

> When you try to run an upstream kernel on an old ARM-based Chromebook
> you'll find that console-ramoops doesn't work.
>
> Old ARM-based Chromebooks, before <https://crrev.com/c/439792>
> ("ramoops: support upstream {console,pmsg,ftrace}-size properties")
> used to create a "ramoops" node at the top level that looked like:
>
> / {
>   ramoops {
>     compatible = "ramoops";
>     reg = <...>;
>     record-size = <...>;
>     dump-oops;
>   };
> };
>
> ...and these Chromebooks assumed that the downstream kernel would make
> console_size / pmsg_size match the record size.  The above ramoops
> node was added by the firmware so it's not easy to make any changes.
>
> Let's match the expected behavior, but only for those using the old
> backward-compatible way of working where ramoops is right under the
> root node.
>
> NOTE: if there are some out-of-tree devices that had ramoops at the
> top level, left everything but the record size as 0, and somehow
> doesn't want this behavior, we can try to add more conditions here.
>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

I like this; thanks! Rob is this okay by you? I just want to
double-check since it's part of the DT parsing logic.

I'll pick it up and add a Cc: stable.

-Kees

> ---
>
>  fs/pstore/ram.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index c5c685589e36..8df3bfa2837f 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -669,6 +669,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
>                             struct ramoops_platform_data *pdata)
>  {
>         struct device_node *of_node = pdev->dev.of_node;
> +       struct device_node *parent_node;
>         struct resource *res;
>         u32 value;
>         int ret;
> @@ -703,6 +704,23 @@ static int ramoops_parse_dt(struct platform_device *pdev,
>
>  #undef parse_size
>
> +       /*
> +        * Some old Chromebooks relied on the kernel setting the console_size
> +        * and pmsg_size to the record size since that's what the downstream
> +        * kernel did.  These same Chromebooks had "ramoops" straight under
> +        * the root node which isn't according to the upstream bindings.  Let's
> +        * make those old Chromebooks work by detecting this and mimicing the
> +        * expected behavior.
> +        */
> +       parent_node = of_get_parent(of_node);
> +       if (of_node_is_root(parent_node) &&
> +           !pdata->console_size && !pdata->ftrace_size &&
> +           !pdata->pmsg_size && !pdata->ecc_info.ecc_size) {
> +               pdata->console_size = pdata->record_size;
> +               pdata->pmsg_size = pdata->record_size;
> +       }
> +       of_node_put(parent_node);
> +
>         return 0;
>  }
>
> --
> 2.21.0.1020.gf2820cf01a-goog
>
Rob Herring May 6, 2019, 9:33 p.m. UTC | #3
On Mon, May 6, 2019 at 4:10 PM Kees Cook <keescook@chromium.org> wrote:
>
> From: Douglas Anderson <dianders@chromium.org>
> Date: Fri, May 3, 2019 at 10:48 AM
> To: Kees Cook, Anton Vorontsov
> Cc: <linux-rockchip@lists.infradead.org>, <jwerner@chromium.org>,
> <groeck@chromium.org>, <mka@chromium.org>, <briannorris@chromium.org>,
> Douglas Anderson, Colin Cross, Tony Luck,
> <linux-kernel@vger.kernel.org>
>
> > When you try to run an upstream kernel on an old ARM-based Chromebook
> > you'll find that console-ramoops doesn't work.
> >
> > Old ARM-based Chromebooks, before <https://crrev.com/c/439792>
> > ("ramoops: support upstream {console,pmsg,ftrace}-size properties")
> > used to create a "ramoops" node at the top level that looked like:
> >
> > / {
> >   ramoops {
> >     compatible = "ramoops";
> >     reg = <...>;
> >     record-size = <...>;
> >     dump-oops;
> >   };
> > };
> >
> > ...and these Chromebooks assumed that the downstream kernel would make
> > console_size / pmsg_size match the record size.  The above ramoops
> > node was added by the firmware so it's not easy to make any changes.
> >
> > Let's match the expected behavior, but only for those using the old
> > backward-compatible way of working where ramoops is right under the
> > root node.
> >
> > NOTE: if there are some out-of-tree devices that had ramoops at the
> > top level, left everything but the record size as 0, and somehow
> > doesn't want this behavior, we can try to add more conditions here.
> >
> > Signed-off-by: Douglas Anderson <dianders@chromium.org>
>
> I like this; thanks! Rob is this okay by you? I just want to
> double-check since it's part of the DT parsing logic.

I'll leave it to you. It does fall into the case of supporting
downstream bindings that weren't reviewed (IIRC reviewed maybe, but
not accepted) which isn't great precedent. OTOH, it's a small change
for a largish number of devices.

Rob
Brian Norris May 6, 2019, 9:40 p.m. UTC | #4
On Fri, May 3, 2019 at 10:48 AM Douglas Anderson <dianders@chromium.org> wrote:
> When you try to run an upstream kernel on an old ARM-based Chromebook
> you'll find that console-ramoops doesn't work.

Ooh, nice! I still get annoyed by old depthcharge firmware. It's
almost as if we should have gotten an upstream binding approved before
baking it into firmware...

> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c

> @@ -703,6 +704,23 @@ static int ramoops_parse_dt(struct platform_device *pdev,
>
>  #undef parse_size
>
> +       /*
> +        * Some old Chromebooks relied on the kernel setting the console_size
> +        * and pmsg_size to the record size since that's what the downstream
> +        * kernel did.  These same Chromebooks had "ramoops" straight under
> +        * the root node which isn't according to the upstream bindings.

The last part of the sentence technically isn't true -- the original
bindings (notably, with no DT maintainer Reviewed-by) didn't specify
where such a node should be found:

35da60941e44 pstore/ram: add Device Tree bindings

so child-of-root used to be a valid location. But anyway, this code is
just part of a heuristic for "old DT" (where later bindings clarified
this), so it still seems valid.

>  Let's
> +        * make those old Chromebooks work by detecting this and mimicing the

s/mimicing/mimicking/

> +        * expected behavior.
> +        */
> +       parent_node = of_get_parent(of_node);
> +       if (of_node_is_root(parent_node) &&
> +           !pdata->console_size && !pdata->ftrace_size &&
> +           !pdata->pmsg_size && !pdata->ecc_info.ecc_size) {
> +               pdata->console_size = pdata->record_size;
> +               pdata->pmsg_size = pdata->record_size;
> +       }
> +       of_node_put(parent_node);
> +
>         return 0;
>  }
>

Otherwise, looks good to me:

Reviewed-by: Brian Norris <briannorris@chromium.org>
Douglas Anderson May 6, 2019, 11:58 p.m. UTC | #5
Hi,

On Mon, May 6, 2019 at 2:10 PM Kees Cook <keescook@chromium.org> wrote:
>
> From: Douglas Anderson <dianders@chromium.org>
> Date: Fri, May 3, 2019 at 10:48 AM
> To: Kees Cook, Anton Vorontsov
> Cc: <linux-rockchip@lists.infradead.org>, <jwerner@chromium.org>,
> <groeck@chromium.org>, <mka@chromium.org>, <briannorris@chromium.org>,
> Douglas Anderson, Colin Cross, Tony Luck,
> <linux-kernel@vger.kernel.org>
>
> > When you try to run an upstream kernel on an old ARM-based Chromebook
> > you'll find that console-ramoops doesn't work.
> >
> > Old ARM-based Chromebooks, before <https://crrev.com/c/439792>
> > ("ramoops: support upstream {console,pmsg,ftrace}-size properties")
> > used to create a "ramoops" node at the top level that looked like:
> >
> > / {
> >   ramoops {
> >     compatible = "ramoops";
> >     reg = <...>;
> >     record-size = <...>;
> >     dump-oops;
> >   };
> > };
> >
> > ...and these Chromebooks assumed that the downstream kernel would make
> > console_size / pmsg_size match the record size.  The above ramoops
> > node was added by the firmware so it's not easy to make any changes.
> >
> > Let's match the expected behavior, but only for those using the old
> > backward-compatible way of working where ramoops is right under the
> > root node.
> >
> > NOTE: if there are some out-of-tree devices that had ramoops at the
> > top level, left everything but the record size as 0, and somehow
> > doesn't want this behavior, we can try to add more conditions here.
> >
> > Signed-off-by: Douglas Anderson <dianders@chromium.org>
>
> I like this; thanks! Rob is this okay by you? I just want to
> double-check since it's part of the DT parsing logic.
>
> I'll pick it up and add a Cc: stable.

Hold off a second--I may need to send out a v2 but out of time for the
day.  I think I need a #include file to fix errors on x86:

> implicit declaration of function 'of_node_is_root' [-Werror,-Wimplicit-function-declaration

I'm unfortunately out of time for now, but I'll post a v2 within the next day.


-Doug
Douglas Anderson May 7, 2019, 4:51 a.m. UTC | #6
Hi,

On Mon, May 6, 2019 at 4:58 PM Doug Anderson <dianders@chromium.org> wrote:
>
> Hi,
>
> On Mon, May 6, 2019 at 2:10 PM Kees Cook <keescook@chromium.org> wrote:
> >
> > From: Douglas Anderson <dianders@chromium.org>
> > Date: Fri, May 3, 2019 at 10:48 AM
> > To: Kees Cook, Anton Vorontsov
> > Cc: <linux-rockchip@lists.infradead.org>, <jwerner@chromium.org>,
> > <groeck@chromium.org>, <mka@chromium.org>, <briannorris@chromium.org>,
> > Douglas Anderson, Colin Cross, Tony Luck,
> > <linux-kernel@vger.kernel.org>
> >
> > > When you try to run an upstream kernel on an old ARM-based Chromebook
> > > you'll find that console-ramoops doesn't work.
> > >
> > > Old ARM-based Chromebooks, before <https://crrev.com/c/439792>
> > > ("ramoops: support upstream {console,pmsg,ftrace}-size properties")
> > > used to create a "ramoops" node at the top level that looked like:
> > >
> > > / {
> > >   ramoops {
> > >     compatible = "ramoops";
> > >     reg = <...>;
> > >     record-size = <...>;
> > >     dump-oops;
> > >   };
> > > };
> > >
> > > ...and these Chromebooks assumed that the downstream kernel would make
> > > console_size / pmsg_size match the record size.  The above ramoops
> > > node was added by the firmware so it's not easy to make any changes.
> > >
> > > Let's match the expected behavior, but only for those using the old
> > > backward-compatible way of working where ramoops is right under the
> > > root node.
> > >
> > > NOTE: if there are some out-of-tree devices that had ramoops at the
> > > top level, left everything but the record size as 0, and somehow
> > > doesn't want this behavior, we can try to add more conditions here.
> > >
> > > Signed-off-by: Douglas Anderson <dianders@chromium.org>
> >
> > I like this; thanks! Rob is this okay by you? I just want to
> > double-check since it's part of the DT parsing logic.
> >
> > I'll pick it up and add a Cc: stable.
>
> Hold off a second--I may need to send out a v2 but out of time for the
> day.  I think I need a #include file to fix errors on x86:
>
> > implicit declaration of function 'of_node_is_root' [-Werror,-Wimplicit-function-declaration
>
> I'm unfortunately out of time for now, but I'll post a v2 within the next day.

OK, it needs this to land first:

https://lore.kernel.org/lkml/20190507044801.250396-1-dianders@chromium.org/T/#u

I thought it'd be OK to just send a separate patch.

-Doug
Douglas Anderson May 7, 2019, 4:25 p.m. UTC | #7
Hi,

On Mon, May 6, 2019 at 2:40 PM Brian Norris <briannorris@chromium.org> wrote:
>
> On Fri, May 3, 2019 at 10:48 AM Douglas Anderson <dianders@chromium.org> wrote:
> > When you try to run an upstream kernel on an old ARM-based Chromebook
> > you'll find that console-ramoops doesn't work.
>
> Ooh, nice! I still get annoyed by old depthcharge firmware. It's
> almost as if we should have gotten an upstream binding approved before
> baking it into firmware...
>
> > --- a/fs/pstore/ram.c
> > +++ b/fs/pstore/ram.c
>
> > @@ -703,6 +704,23 @@ static int ramoops_parse_dt(struct platform_device *pdev,
> >
> >  #undef parse_size
> >
> > +       /*
> > +        * Some old Chromebooks relied on the kernel setting the console_size
> > +        * and pmsg_size to the record size since that's what the downstream
> > +        * kernel did.  These same Chromebooks had "ramoops" straight under
> > +        * the root node which isn't according to the upstream bindings.
>
> The last part of the sentence technically isn't true -- the original
> bindings (notably, with no DT maintainer Reviewed-by) didn't specify
> where such a node should be found:
>
> 35da60941e44 pstore/ram: add Device Tree bindings
>
> so child-of-root used to be a valid location. But anyway, this code is
> just part of a heuristic for "old DT" (where later bindings clarified
> this), so it still seems valid.

I agree that it was unclear in the past, but it is true that being
under the root node is not according to the _current_ upstream
bindings, right?  ;-)


> >  Let's
> > +        * make those old Chromebooks work by detecting this and mimicing the
>
> s/mimicing/mimicking/

Kees: if you want me to spin with this typo fix then please let me
know.  Otherwise I'll assume it's less work for you to just fix it
yourself when applying.

-Doug
Brian Norris May 7, 2019, 4:48 p.m. UTC | #8
On Tue, May 7, 2019 at 9:25 AM Doug Anderson <dianders@chromium.org> wrote:
> On Mon, May 6, 2019 at 2:40 PM Brian Norris <briannorris@chromium.org> wrote:
> > The last part of the sentence technically isn't true -- the original
> > bindings (notably, with no DT maintainer Reviewed-by) didn't specify
> > where such a node should be found:
> >
> > 35da60941e44 pstore/ram: add Device Tree bindings
> >
> > so child-of-root used to be a valid location. But anyway, this code is
> > just part of a heuristic for "old DT" (where later bindings clarified
> > this), so it still seems valid.
>
> I agree that it was unclear in the past, but it is true that being
> under the root node is not according to the _current_ upstream
> bindings, right?  ;-)

Sure, I suppose. Although, given the general ABI policy around DT, it
seems to me that something that was "according to" an old binding
cannot really be made "no longer" according to the binding. It can be
discouraged, and removed from new DTs, but it doesn't really become
*wrong*.

But our DT was definitely *not* according to even the (un-reviewed)
merged binding. So I'm mostly mincing words here.

Brian
Frank Rowand May 7, 2019, 10:17 p.m. UTC | #9
On 5/6/19 4:58 PM, Doug Anderson wrote:
> Hi,
> 
> On Mon, May 6, 2019 at 2:10 PM Kees Cook <keescook@chromium.org> wrote:
>>
>> From: Douglas Anderson <dianders@chromium.org>
>> Date: Fri, May 3, 2019 at 10:48 AM
>> To: Kees Cook, Anton Vorontsov
>> Cc: <linux-rockchip@lists.infradead.org>, <jwerner@chromium.org>,
>> <groeck@chromium.org>, <mka@chromium.org>, <briannorris@chromium.org>,
>> Douglas Anderson, Colin Cross, Tony Luck,
>> <linux-kernel@vger.kernel.org>
>>
>>> When you try to run an upstream kernel on an old ARM-based Chromebook
>>> you'll find that console-ramoops doesn't work.
>>>
>>> Old ARM-based Chromebooks, before <https://crrev.com/c/439792>
>>> ("ramoops: support upstream {console,pmsg,ftrace}-size properties")
>>> used to create a "ramoops" node at the top level that looked like:
>>>
>>> / {
>>>   ramoops {
>>>     compatible = "ramoops";
>>>     reg = <...>;
>>>     record-size = <...>;
>>>     dump-oops;
>>>   };
>>> };
>>>
>>> ...and these Chromebooks assumed that the downstream kernel would make
>>> console_size / pmsg_size match the record size.  The above ramoops
>>> node was added by the firmware so it's not easy to make any changes.
>>>
>>> Let's match the expected behavior, but only for those using the old
>>> backward-compatible way of working where ramoops is right under the
>>> root node.
>>>
>>> NOTE: if there are some out-of-tree devices that had ramoops at the
>>> top level, left everything but the record size as 0, and somehow
>>> doesn't want this behavior, we can try to add more conditions here.
>>>
>>> Signed-off-by: Douglas Anderson <dianders@chromium.org>
>>
>> I like this; thanks! Rob is this okay by you? I just want to
>> double-check since it's part of the DT parsing logic.
>>
>> I'll pick it up and add a Cc: stable.
> 
> Hold off a second--I may need to send out a v2 but out of time for the
> day.  I think I need a #include file to fix errors on x86:
> 
>> implicit declaration of function 'of_node_is_root' [-Werror,-Wimplicit-function-declaration

Instead of checking "of_node_is_root(parent_node)" the patch could check
for parent_node not "/reserved-memory".  Then the x86 error would not
occur.

The check I am suggesting is not as precise, but it should be good enough
for this case, correct?

-Frank

> 
> I'm unfortunately out of time for now, but I'll post a v2 within the next day.
> 
> 
> -Doug
>
Douglas Anderson May 7, 2019, 10:19 p.m. UTC | #10
Hi,

On Tue, May 7, 2019 at 3:17 PM Frank Rowand <frowand.list@gmail.com> wrote:
>
> On 5/6/19 4:58 PM, Doug Anderson wrote:
> > Hi,
> >
> > On Mon, May 6, 2019 at 2:10 PM Kees Cook <keescook@chromium.org> wrote:
> >>
> >> From: Douglas Anderson <dianders@chromium.org>
> >> Date: Fri, May 3, 2019 at 10:48 AM
> >> To: Kees Cook, Anton Vorontsov
> >> Cc: <linux-rockchip@lists.infradead.org>, <jwerner@chromium.org>,
> >> <groeck@chromium.org>, <mka@chromium.org>, <briannorris@chromium.org>,
> >> Douglas Anderson, Colin Cross, Tony Luck,
> >> <linux-kernel@vger.kernel.org>
> >>
> >>> When you try to run an upstream kernel on an old ARM-based Chromebook
> >>> you'll find that console-ramoops doesn't work.
> >>>
> >>> Old ARM-based Chromebooks, before <https://crrev.com/c/439792>
> >>> ("ramoops: support upstream {console,pmsg,ftrace}-size properties")
> >>> used to create a "ramoops" node at the top level that looked like:
> >>>
> >>> / {
> >>>   ramoops {
> >>>     compatible = "ramoops";
> >>>     reg = <...>;
> >>>     record-size = <...>;
> >>>     dump-oops;
> >>>   };
> >>> };
> >>>
> >>> ...and these Chromebooks assumed that the downstream kernel would make
> >>> console_size / pmsg_size match the record size.  The above ramoops
> >>> node was added by the firmware so it's not easy to make any changes.
> >>>
> >>> Let's match the expected behavior, but only for those using the old
> >>> backward-compatible way of working where ramoops is right under the
> >>> root node.
> >>>
> >>> NOTE: if there are some out-of-tree devices that had ramoops at the
> >>> top level, left everything but the record size as 0, and somehow
> >>> doesn't want this behavior, we can try to add more conditions here.
> >>>
> >>> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> >>
> >> I like this; thanks! Rob is this okay by you? I just want to
> >> double-check since it's part of the DT parsing logic.
> >>
> >> I'll pick it up and add a Cc: stable.
> >
> > Hold off a second--I may need to send out a v2 but out of time for the
> > day.  I think I need a #include file to fix errors on x86:
> >
> >> implicit declaration of function 'of_node_is_root' [-Werror,-Wimplicit-function-declaration
>
> Instead of checking "of_node_is_root(parent_node)" the patch could check
> for parent_node not "/reserved-memory".  Then the x86 error would not
> occur.
>
> The check I am suggesting is not as precise, but it should be good enough
> for this case, correct?

Sure, there are a million different ways to slice it.  If you prefer
that instead of adding a dummy of_node_is_root() I'm happy to do that.

-Doug
Frank Rowand May 7, 2019, 10:23 p.m. UTC | #11
Hi Doug,

On 5/7/19 3:19 PM, Doug Anderson wrote:
> Hi,
> 
> On Tue, May 7, 2019 at 3:17 PM Frank Rowand <frowand.list@gmail.com> wrote:
>>
>> On 5/6/19 4:58 PM, Doug Anderson wrote:
>>> Hi,
>>>
>>> On Mon, May 6, 2019 at 2:10 PM Kees Cook <keescook@chromium.org> wrote:
>>>>
>>>> From: Douglas Anderson <dianders@chromium.org>
>>>> Date: Fri, May 3, 2019 at 10:48 AM
>>>> To: Kees Cook, Anton Vorontsov
>>>> Cc: <linux-rockchip@lists.infradead.org>, <jwerner@chromium.org>,
>>>> <groeck@chromium.org>, <mka@chromium.org>, <briannorris@chromium.org>,
>>>> Douglas Anderson, Colin Cross, Tony Luck,
>>>> <linux-kernel@vger.kernel.org>
>>>>
>>>>> When you try to run an upstream kernel on an old ARM-based Chromebook
>>>>> you'll find that console-ramoops doesn't work.
>>>>>
>>>>> Old ARM-based Chromebooks, before <https://crrev.com/c/439792>
>>>>> ("ramoops: support upstream {console,pmsg,ftrace}-size properties")
>>>>> used to create a "ramoops" node at the top level that looked like:
>>>>>
>>>>> / {
>>>>>   ramoops {
>>>>>     compatible = "ramoops";
>>>>>     reg = <...>;
>>>>>     record-size = <...>;
>>>>>     dump-oops;
>>>>>   };
>>>>> };
>>>>>
>>>>> ...and these Chromebooks assumed that the downstream kernel would make
>>>>> console_size / pmsg_size match the record size.  The above ramoops
>>>>> node was added by the firmware so it's not easy to make any changes.
>>>>>
>>>>> Let's match the expected behavior, but only for those using the old
>>>>> backward-compatible way of working where ramoops is right under the
>>>>> root node.
>>>>>
>>>>> NOTE: if there are some out-of-tree devices that had ramoops at the
>>>>> top level, left everything but the record size as 0, and somehow
>>>>> doesn't want this behavior, we can try to add more conditions here.
>>>>>
>>>>> Signed-off-by: Douglas Anderson <dianders@chromium.org>
>>>>
>>>> I like this; thanks! Rob is this okay by you? I just want to
>>>> double-check since it's part of the DT parsing logic.
>>>>
>>>> I'll pick it up and add a Cc: stable.
>>>
>>> Hold off a second--I may need to send out a v2 but out of time for the
>>> day.  I think I need a #include file to fix errors on x86:
>>>
>>>> implicit declaration of function 'of_node_is_root' [-Werror,-Wimplicit-function-declaration
>>
>> Instead of checking "of_node_is_root(parent_node)" the patch could check
>> for parent_node not "/reserved-memory".  Then the x86 error would not
>> occur.
>>
>> The check I am suggesting is not as precise, but it should be good enough
>> for this case, correct?
> 
> Sure, there are a million different ways to slice it.  If you prefer
> that instead of adding a dummy of_node_is_root() I'm happy to do that.

Yes, I would prefer to avoid adding a dummy of_node_is_root() if the
alternative is reasonable (and if I understand, you are saying the
alternative is reasonable).

Thanks,

Frank
diff mbox series

Patch

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index c5c685589e36..8df3bfa2837f 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -669,6 +669,7 @@  static int ramoops_parse_dt(struct platform_device *pdev,
 			    struct ramoops_platform_data *pdata)
 {
 	struct device_node *of_node = pdev->dev.of_node;
+	struct device_node *parent_node;
 	struct resource *res;
 	u32 value;
 	int ret;
@@ -703,6 +704,23 @@  static int ramoops_parse_dt(struct platform_device *pdev,
 
 #undef parse_size
 
+	/*
+	 * Some old Chromebooks relied on the kernel setting the console_size
+	 * and pmsg_size to the record size since that's what the downstream
+	 * kernel did.  These same Chromebooks had "ramoops" straight under
+	 * the root node which isn't according to the upstream bindings.  Let's
+	 * make those old Chromebooks work by detecting this and mimicing the
+	 * expected behavior.
+	 */
+	parent_node = of_get_parent(of_node);
+	if (of_node_is_root(parent_node) &&
+	    !pdata->console_size && !pdata->ftrace_size &&
+	    !pdata->pmsg_size && !pdata->ecc_info.ecc_size) {
+		pdata->console_size = pdata->record_size;
+		pdata->pmsg_size = pdata->record_size;
+	}
+	of_node_put(parent_node);
+
 	return 0;
 }