* [PATCH] ubifs: tnc: use monotonic znode timestamp
@ 2018-06-20 8:29 Arnd Bergmann
2018-07-02 14:24 ` Richard Weinberger
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2018-06-20 8:29 UTC (permalink / raw)
To: Richard Weinberger, Artem Bityutskiy, Adrian Hunter
Cc: y2038, Arnd Bergmann, Deepa Dinamani, linux-mtd, linux-kernel
The tnc uses get_seconds() based timestamps to check the age of a znode,
which has two problems: on 32-bit architectures this may overflow in
2038 or 2106, and it gives incorrect information when the system time
is updated using settimeofday().
Using montonic timestamps with ktime_get_seconds() solves both thes
problems.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
fs/ubifs/shrinker.c | 2 +-
fs/ubifs/tnc.c | 4 ++--
fs/ubifs/tnc_misc.c | 2 +-
fs/ubifs/ubifs.h | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/fs/ubifs/shrinker.c b/fs/ubifs/shrinker.c
index 9a9fb94a41c6..9d10cbdec2cc 100644
--- a/fs/ubifs/shrinker.c
+++ b/fs/ubifs/shrinker.c
@@ -71,7 +71,7 @@ static int shrink_tnc(struct ubifs_info *c, int nr, int age, int *contention)
{
int total_freed = 0;
struct ubifs_znode *znode, *zprev;
- int time = get_seconds();
+ time64_t time = ktime_get_seconds();
ubifs_assert(mutex_is_locked(&c->umount_mutex));
ubifs_assert(mutex_is_locked(&c->tnc_mutex));
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c
index 4a21e7f75e7a..6c497fb48b98 100644
--- a/fs/ubifs/tnc.c
+++ b/fs/ubifs/tnc.c
@@ -1179,7 +1179,7 @@ int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key,
{
int err, exact;
struct ubifs_znode *znode;
- unsigned long time = get_seconds();
+ time64_t time = ktime_get_seconds();
dbg_tnck(key, "search key ");
ubifs_assert(key_type(c, key) < UBIFS_INVALID_KEY);
@@ -1315,7 +1315,7 @@ static int lookup_level0_dirty(struct ubifs_info *c, const union ubifs_key *key,
{
int err, exact;
struct ubifs_znode *znode;
- unsigned long time = get_seconds();
+ time64_t time = ktime_get_seconds();
dbg_tnck(key, "search and dirty key ");
diff --git a/fs/ubifs/tnc_misc.c b/fs/ubifs/tnc_misc.c
index 93f5b7859e6f..49f647bc88f0 100644
--- a/fs/ubifs/tnc_misc.c
+++ b/fs/ubifs/tnc_misc.c
@@ -435,7 +435,7 @@ struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c,
zbr->znode = znode;
znode->parent = parent;
- znode->time = get_seconds();
+ znode->time = ktime_get_seconds();
znode->iip = iip;
return znode;
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 04bf84d71e7b..54fb6b1cd042 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -758,7 +758,7 @@ struct ubifs_znode {
struct ubifs_znode *parent;
struct ubifs_znode *cnext;
unsigned long flags;
- unsigned long time;
+ time64_t time;
int level;
int child_cnt;
int iip;
--
2.9.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ubifs: tnc: use monotonic znode timestamp
2018-06-20 8:29 [PATCH] ubifs: tnc: use monotonic znode timestamp Arnd Bergmann
@ 2018-07-02 14:24 ` Richard Weinberger
2018-07-03 7:28 ` Richard Weinberger
0 siblings, 1 reply; 3+ messages in thread
From: Richard Weinberger @ 2018-07-02 14:24 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Artem Bityutskiy, Adrian Hunter, y2038, Deepa Dinamani,
linux-mtd, linux-kernel
Arnd,
Am Mittwoch, 20. Juni 2018, 10:29:11 CEST schrieb Arnd Bergmann:
> The tnc uses get_seconds() based timestamps to check the age of a znode,
> which has two problems: on 32-bit architectures this may overflow in
> 2038 or 2106, and it gives incorrect information when the system time
> is updated using settimeofday().
>
> Using montonic timestamps with ktime_get_seconds() solves both thes
> problems.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> fs/ubifs/shrinker.c | 2 +-
> fs/ubifs/tnc.c | 4 ++--
> fs/ubifs/tnc_misc.c | 2 +-
> fs/ubifs/ubifs.h | 2 +-
> 4 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/fs/ubifs/shrinker.c b/fs/ubifs/shrinker.c
> index 9a9fb94a41c6..9d10cbdec2cc 100644
> --- a/fs/ubifs/shrinker.c
> +++ b/fs/ubifs/shrinker.c
> @@ -71,7 +71,7 @@ static int shrink_tnc(struct ubifs_info *c, int nr, int age, int *contention)
> {
> int total_freed = 0;
> struct ubifs_znode *znode, *zprev;
> - int time = get_seconds();
> + time64_t time = ktime_get_seconds();
ubifs does
abs(time - znode->time) >= age) {
Is this still legit with time64_t?
Thanks,
//richard
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ubifs: tnc: use monotonic znode timestamp
2018-07-02 14:24 ` Richard Weinberger
@ 2018-07-03 7:28 ` Richard Weinberger
0 siblings, 0 replies; 3+ messages in thread
From: Richard Weinberger @ 2018-07-03 7:28 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Artem Bityutskiy, Adrian Hunter, y2038, Deepa Dinamani,
linux-mtd, linux-kernel
Am Montag, 2. Juli 2018, 16:24:15 CEST schrieb Richard Weinberger:
> Arnd,
>
> Am Mittwoch, 20. Juni 2018, 10:29:11 CEST schrieb Arnd Bergmann:
> > The tnc uses get_seconds() based timestamps to check the age of a znode,
> > which has two problems: on 32-bit architectures this may overflow in
> > 2038 or 2106, and it gives incorrect information when the system time
> > is updated using settimeofday().
> >
> > Using montonic timestamps with ktime_get_seconds() solves both thes
> > problems.
> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> > fs/ubifs/shrinker.c | 2 +-
> > fs/ubifs/tnc.c | 4 ++--
> > fs/ubifs/tnc_misc.c | 2 +-
> > fs/ubifs/ubifs.h | 2 +-
> > 4 files changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/fs/ubifs/shrinker.c b/fs/ubifs/shrinker.c
> > index 9a9fb94a41c6..9d10cbdec2cc 100644
> > --- a/fs/ubifs/shrinker.c
> > +++ b/fs/ubifs/shrinker.c
> > @@ -71,7 +71,7 @@ static int shrink_tnc(struct ubifs_info *c, int nr, int age, int *contention)
> > {
> > int total_freed = 0;
> > struct ubifs_znode *znode, *zprev;
> > - int time = get_seconds();
> > + time64_t time = ktime_get_seconds();
>
> ubifs does
> abs(time - znode->time) >= age) {
>
> Is this still legit with time64_t?
Answering my own question, yes.
abs() seems to be able to deal with 64bit numbers and time64_t is just a number.
Thanks,
//richard
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-07-03 7:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-20 8:29 [PATCH] ubifs: tnc: use monotonic znode timestamp Arnd Bergmann
2018-07-02 14:24 ` Richard Weinberger
2018-07-03 7:28 ` Richard Weinberger
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.