From: Guenter Roeck <linux@roeck-us.net>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: "Alice Guo (OSS)" <alice.guo@oss.nxp.com>,
"wim@linux-watchdog.org" <wim@linux-watchdog.org>,
"shawnguo@kernel.org" <shawnguo@kernel.org>,
"s.hauer@pengutronix.de" <s.hauer@pengutronix.de>,
"festevam@gmail.com" <festevam@gmail.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
dl-linux-imx <linux-imx@nxp.com>,
"kernel@pengutronix.de" <kernel@pengutronix.de>,
"linux-watchdog@vger.kernel.org" <linux-watchdog@vger.kernel.org>
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence
Date: Tue, 23 Aug 2022 05:02:19 -0700 [thread overview]
Message-ID: <20220823120219.GA203169@roeck-us.net> (raw)
In-Reply-To: <20220823091027.ezyxkn64asajvjom@pengutronix.de>
On Tue, Aug 23, 2022 at 11:10:27AM +0200, Marco Felsch wrote:
> On 22-08-23, Alice Guo (OSS) wrote:
> >
> >
> > > -----Original Message-----
> > > From: Guenter Roeck <groeck7@gmail.com> On Behalf Of Guenter Roeck
> > > Sent: Monday, August 22, 2022 10:04 PM
> > > To: Marco Felsch <m.felsch@pengutronix.de>
> > > Cc: Alice Guo (OSS) <alice.guo@oss.nxp.com>; wim@linux-watchdog.org;
> > > shawnguo@kernel.org; s.hauer@pengutronix.de; festevam@gmail.com;
> > > linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org;
> > > dl-linux-imx <linux-imx@nxp.com>; kernel@pengutronix.de;
> > > linux-watchdog@vger.kernel.org
> > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> > > unlock sequence
> > >
> > > On Mon, Aug 22, 2022 at 10:00:10AM +0200, Marco Felsch wrote:
> > > > On 22-08-22, Alice Guo (OSS) wrote:
> > > > > > -----Original Message-----
> > > > > > From: Marco Felsch <m.felsch@pengutronix.de>
> > > > > > Sent: Tuesday, August 16, 2022 2:24 PM
> > > > > > To: Alice Guo (OSS) <alice.guo@oss.nxp.com>
> > > > > > Cc: wim@linux-watchdog.org; linux@roeck-us.net;
> > > > > > shawnguo@kernel.org; s.hauer@pengutronix.de; festevam@gmail.com;
> > > > > > linux-arm-kernel@lists.infradead.org;
> > > > > > linux-kernel@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > > > > kernel@pengutronix.de; linux-watchdog@vger.kernel.org
> > > > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > > > barrier for unlock sequence
> > > > > >
> > > > > > On 22-08-16, Alice Guo (OSS) wrote:
> > > > > > > From: Jacky Bai <ping.bai@nxp.com>
> > > > > > >
> > > > > > > Add explict memory barrier for the wdog unlock sequence.
> > > > > >
> > > > > > Did you inspected any failures? It's not enough to say what you
> > > > > > did, you need to specify the why as well.
> > > > > >
> > > > > > Regards,
> > > > > > Marco
> > > > >
> > > > > Hi,
> > > > >
> > > > > Two 16-bit writes of unlocking the Watchdog should be completed within a
> > > certain time. The first mb() is used to ensure that previous instructions are
> > > completed.
> > > > > The second mb() is used to ensure that the unlock sequence cannot be
> > > affected by subsequent instructions. The reason will be added in the commit
> > > log of v2.
> > > >
> > > > Hi,
> > > >
> > > > I know what memory barriers are. My question was, did you see any
> > > > issues? Since the driver is used mainline and no one reported issues.
> > > >
> > > > Also just don't use the *_relaxed() versions is more common, than
> > > > adding
> > > > mb() calls around *_relaxed() versions.
> > > >
> > >
> > > Agreed with both. The series is a bit short in explaining _why_ the changes are
> > > made.
> > >
> > > Guenter
> > >
> > > > Regards,
> > > > Marco
> > > >
> > > > >
> >
> > Hi Guenter and Marco,
> >
> > 1. did you see any issues?
> > This WDOG Timer first appeared in i.MX7ULP, no one report issues
> > probably because few people use i.MX7ULP. This issue was found when we
> > did a stress test on it. When we reconfigure the WDOG Timer, there is
> > a certain probability that it reset. The reason for the error is that
> > when WDOG_CS[CMD32EN] is 0, the unlock sequence is two 16-bit writes
> > (0xC520, 0xD928) to the CNT register within 16 bus clocks, and
> > improper unlock sequence causes the WDOG to reset. Adding mb() is to
> > guarantee that two 16-bit writes are finished within 16 bus clocks.
>
> After this explanation the whole imx7ulp_wdt_init() seems a bit buggy
> because writel_relaxed() as well as writel() are 32bit access functions.
> So the very first thing to do is to enable the 32-bit mode.
>
Agreed. This is much better than having extra code to deal with
both 16-bit and 32-bit access.
> Also this is a explanation worth to be added to the commit message ;)
>
Definitely. Also, the use of mb(), if it should indeed be needed,
would have to be explained in a code comment.
Thanks,
Guenter
> > 2. Also just don't use the *_relaxed() versions is more common, than
> > adding mb() calls around *_relaxed() versions. Memory barriers cannot
> > be added between two 16-bit writes. I do not know the reason.
>
> As written above, writel() as well as writel_relaxed() are not 16-bit
> access functions.
>
> So to me it looks as you need first to ensure that 32-bit access mode is
> enabled. After that you can write drop the to writel_relaxed() functions
> and instead just write:
>
> writel(UNLOCK, wdt->base + WDOG_CNT);
>
> Also why do we need to unlock the watchdog during imx7ulp_wdt_init()?
> This is handled just fine during imx7ulp_wdt_enable() and during
> imx7ulp_wdt_set_timeout(). So just drop those relaxed writes and
> everything should be fine.
>
> Regards,
> Marco
WARNING: multiple messages have this Message-ID (diff)
From: Guenter Roeck <linux@roeck-us.net>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: "Alice Guo (OSS)" <alice.guo@oss.nxp.com>,
"wim@linux-watchdog.org" <wim@linux-watchdog.org>,
"shawnguo@kernel.org" <shawnguo@kernel.org>,
"s.hauer@pengutronix.de" <s.hauer@pengutronix.de>,
"festevam@gmail.com" <festevam@gmail.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
dl-linux-imx <linux-imx@nxp.com>,
"kernel@pengutronix.de" <kernel@pengutronix.de>,
"linux-watchdog@vger.kernel.org" <linux-watchdog@vger.kernel.org>
Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence
Date: Tue, 23 Aug 2022 05:02:19 -0700 [thread overview]
Message-ID: <20220823120219.GA203169@roeck-us.net> (raw)
In-Reply-To: <20220823091027.ezyxkn64asajvjom@pengutronix.de>
On Tue, Aug 23, 2022 at 11:10:27AM +0200, Marco Felsch wrote:
> On 22-08-23, Alice Guo (OSS) wrote:
> >
> >
> > > -----Original Message-----
> > > From: Guenter Roeck <groeck7@gmail.com> On Behalf Of Guenter Roeck
> > > Sent: Monday, August 22, 2022 10:04 PM
> > > To: Marco Felsch <m.felsch@pengutronix.de>
> > > Cc: Alice Guo (OSS) <alice.guo@oss.nxp.com>; wim@linux-watchdog.org;
> > > shawnguo@kernel.org; s.hauer@pengutronix.de; festevam@gmail.com;
> > > linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org;
> > > dl-linux-imx <linux-imx@nxp.com>; kernel@pengutronix.de;
> > > linux-watchdog@vger.kernel.org
> > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for
> > > unlock sequence
> > >
> > > On Mon, Aug 22, 2022 at 10:00:10AM +0200, Marco Felsch wrote:
> > > > On 22-08-22, Alice Guo (OSS) wrote:
> > > > > > -----Original Message-----
> > > > > > From: Marco Felsch <m.felsch@pengutronix.de>
> > > > > > Sent: Tuesday, August 16, 2022 2:24 PM
> > > > > > To: Alice Guo (OSS) <alice.guo@oss.nxp.com>
> > > > > > Cc: wim@linux-watchdog.org; linux@roeck-us.net;
> > > > > > shawnguo@kernel.org; s.hauer@pengutronix.de; festevam@gmail.com;
> > > > > > linux-arm-kernel@lists.infradead.org;
> > > > > > linux-kernel@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>;
> > > > > > kernel@pengutronix.de; linux-watchdog@vger.kernel.org
> > > > > > Subject: Re: [PATCH 2/7] watchdog: imx7ulp: Add explict memory
> > > > > > barrier for unlock sequence
> > > > > >
> > > > > > On 22-08-16, Alice Guo (OSS) wrote:
> > > > > > > From: Jacky Bai <ping.bai@nxp.com>
> > > > > > >
> > > > > > > Add explict memory barrier for the wdog unlock sequence.
> > > > > >
> > > > > > Did you inspected any failures? It's not enough to say what you
> > > > > > did, you need to specify the why as well.
> > > > > >
> > > > > > Regards,
> > > > > > Marco
> > > > >
> > > > > Hi,
> > > > >
> > > > > Two 16-bit writes of unlocking the Watchdog should be completed within a
> > > certain time. The first mb() is used to ensure that previous instructions are
> > > completed.
> > > > > The second mb() is used to ensure that the unlock sequence cannot be
> > > affected by subsequent instructions. The reason will be added in the commit
> > > log of v2.
> > > >
> > > > Hi,
> > > >
> > > > I know what memory barriers are. My question was, did you see any
> > > > issues? Since the driver is used mainline and no one reported issues.
> > > >
> > > > Also just don't use the *_relaxed() versions is more common, than
> > > > adding
> > > > mb() calls around *_relaxed() versions.
> > > >
> > >
> > > Agreed with both. The series is a bit short in explaining _why_ the changes are
> > > made.
> > >
> > > Guenter
> > >
> > > > Regards,
> > > > Marco
> > > >
> > > > >
> >
> > Hi Guenter and Marco,
> >
> > 1. did you see any issues?
> > This WDOG Timer first appeared in i.MX7ULP, no one report issues
> > probably because few people use i.MX7ULP. This issue was found when we
> > did a stress test on it. When we reconfigure the WDOG Timer, there is
> > a certain probability that it reset. The reason for the error is that
> > when WDOG_CS[CMD32EN] is 0, the unlock sequence is two 16-bit writes
> > (0xC520, 0xD928) to the CNT register within 16 bus clocks, and
> > improper unlock sequence causes the WDOG to reset. Adding mb() is to
> > guarantee that two 16-bit writes are finished within 16 bus clocks.
>
> After this explanation the whole imx7ulp_wdt_init() seems a bit buggy
> because writel_relaxed() as well as writel() are 32bit access functions.
> So the very first thing to do is to enable the 32-bit mode.
>
Agreed. This is much better than having extra code to deal with
both 16-bit and 32-bit access.
> Also this is a explanation worth to be added to the commit message ;)
>
Definitely. Also, the use of mb(), if it should indeed be needed,
would have to be explained in a code comment.
Thanks,
Guenter
> > 2. Also just don't use the *_relaxed() versions is more common, than
> > adding mb() calls around *_relaxed() versions. Memory barriers cannot
> > be added between two 16-bit writes. I do not know the reason.
>
> As written above, writel() as well as writel_relaxed() are not 16-bit
> access functions.
>
> So to me it looks as you need first to ensure that 32-bit access mode is
> enabled. After that you can write drop the to writel_relaxed() functions
> and instead just write:
>
> writel(UNLOCK, wdt->base + WDOG_CNT);
>
> Also why do we need to unlock the watchdog during imx7ulp_wdt_init()?
> This is handled just fine during imx7ulp_wdt_enable() and during
> imx7ulp_wdt_set_timeout(). So just drop those relaxed writes and
> everything should be fine.
>
> Regards,
> Marco
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-08-23 15:55 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 4:36 [PATCH 0/7] watchdog: imx7ulp_wdt: update i.MX7ULP WDOG timer driver Alice Guo (OSS)
2022-08-16 4:36 ` Alice Guo (OSS)
2022-08-16 4:36 ` [PATCH 1/7] watchdog: imx7ulp: Move suspend/resume to noirq phase Alice Guo (OSS)
2022-08-16 4:36 ` Alice Guo (OSS)
2022-08-16 4:36 ` [PATCH 2/7] watchdog: imx7ulp: Add explict memory barrier for unlock sequence Alice Guo (OSS)
2022-08-16 4:36 ` Alice Guo (OSS)
2022-08-16 6:23 ` Marco Felsch
2022-08-16 6:23 ` Marco Felsch
2022-08-22 7:49 ` Alice Guo (OSS)
2022-08-22 7:49 ` Alice Guo (OSS)
2022-08-22 8:00 ` Marco Felsch
2022-08-22 8:00 ` Marco Felsch
2022-08-22 14:03 ` Guenter Roeck
2022-08-22 14:03 ` Guenter Roeck
2022-08-23 5:38 ` Alice Guo (OSS)
2022-08-23 5:38 ` Alice Guo (OSS)
2022-08-23 9:10 ` Marco Felsch
2022-08-23 9:10 ` Marco Felsch
2022-08-23 12:02 ` Guenter Roeck [this message]
2022-08-23 12:02 ` Guenter Roeck
2022-08-24 6:24 ` Alice Guo (OSS)
2022-08-24 6:24 ` Alice Guo (OSS)
2022-08-24 8:03 ` Marco Felsch
2022-08-24 8:03 ` Marco Felsch
2022-08-24 8:40 ` Alice Guo (OSS)
2022-08-24 8:40 ` Alice Guo (OSS)
2022-08-24 9:06 ` Marco Felsch
2022-08-24 9:06 ` Marco Felsch
2022-08-24 10:05 ` Alice Guo (OSS)
2022-08-24 10:05 ` Alice Guo (OSS)
2022-08-25 7:50 ` Marco Felsch
2022-08-25 7:50 ` Marco Felsch
2022-08-25 8:08 ` Alice Guo (OSS)
2022-08-25 8:08 ` Alice Guo (OSS)
2022-08-25 9:01 ` Marco Felsch
2022-08-25 9:01 ` Marco Felsch
2022-08-25 10:11 ` Alice Guo (OSS)
2022-08-25 10:11 ` Alice Guo (OSS)
2022-08-16 4:36 ` [PATCH 3/7] watchdog: imx7ulp_wdt: Check CMD32EN in wdog init Alice Guo (OSS)
2022-08-16 4:36 ` Alice Guo (OSS)
2022-08-22 14:05 ` Guenter Roeck
2022-08-22 14:05 ` Guenter Roeck
2022-08-23 5:46 ` Alice Guo (OSS)
2022-08-23 5:46 ` Alice Guo (OSS)
2022-08-23 12:05 ` Guenter Roeck
2022-08-23 12:05 ` Guenter Roeck
2022-08-16 4:36 ` [PATCH 4/7] watchdog: imx7ulp_wdt: Fix RCS timeout issue Alice Guo (OSS)
2022-08-16 4:36 ` Alice Guo (OSS)
2022-08-22 14:09 ` Guenter Roeck
2022-08-22 14:09 ` Guenter Roeck
2022-08-23 5:59 ` Alice Guo (OSS)
2022-08-23 5:59 ` Alice Guo (OSS)
2022-08-23 12:06 ` Guenter Roeck
2022-08-23 12:06 ` Guenter Roeck
2022-08-24 6:44 ` Alice Guo (OSS)
2022-08-24 6:44 ` Alice Guo (OSS)
2022-08-16 4:36 ` [PATCH 5/7] watchdog: imx7ulp_wdt: Handle wdog reconfigure failure Alice Guo (OSS)
2022-08-16 4:36 ` Alice Guo (OSS)
2022-08-16 4:36 ` [PATCH 6/7] watchdog: imx7ulp_wdt: init wdog when it was active Alice Guo (OSS)
2022-08-16 4:36 ` Alice Guo (OSS)
2022-08-16 4:36 ` [PATCH 7/7] watchdog: imx93: add watchdog timer on imx93 Alice Guo (OSS)
2022-08-16 4:36 ` Alice Guo (OSS)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220823120219.GA203169@roeck-us.net \
--to=linux@roeck-us.net \
--cc=alice.guo@oss.nxp.com \
--cc=festevam@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=m.felsch@pengutronix.de \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=wim@linux-watchdog.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.