All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Ganesh Mahendran <opensource.ganesh@gmail.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Minchan Kim <minchan@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Linux-MM <linux-mm@kvack.org>, Nitin Gupta <ngupta@vflare.org>,
	Jerome Marchand <jmarchan@redhat.com>
Subject: Re: [PATCH 2/2] zram: protect zram->stat race with init_lock
Date: Sun, 25 Jan 2015 23:38:34 +0900	[thread overview]
Message-ID: <20150125143834.GA951@swordfish> (raw)
In-Reply-To: <CADAEsF_pd_n9G4jft1dnXYM6N7SZ+YMQSKCAAszuLrpygaTQvQ@mail.gmail.com>

Hello,

On (01/24/15 21:17), Ganesh Mahendran wrote:
> Hello Sergey
> 
> 2015-01-23 22:38 GMT+08:00 Sergey Senozhatsky <sergey.senozhatsky@gmail.com>:
> > On (01/23/15 14:58), Minchan Kim wrote:
> >> The zram->stat handling should be procted by init_lock.
> >> Otherwise, user could see stale value from the stat.
> >>
> >> Signed-off-by: Minchan Kim <minchan@kernel.org>
> >> ---
> >>
> >> I don't think it's stable material. The race is rare in real practice
> >> and this stale stat value read is not a critical.
> >>
> >>  drivers/block/zram/zram_drv.c | 37 ++++++++++++++++++++++++++++---------
> >>  1 file changed, 28 insertions(+), 9 deletions(-)
> >>
> >> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> >> index 0299d82275e7..53f176f590b0 100644
> >> --- a/drivers/block/zram/zram_drv.c
> >> +++ b/drivers/block/zram/zram_drv.c
> >> @@ -48,8 +48,13 @@ static ssize_t name##_show(struct device *d,               \
> >>                               struct device_attribute *attr, char *b) \
> >>  {                                                                    \
> >
> > a side note: I wasn't Cc'd in that patchset and found out it only when it's
> > been merged. I'm not sure I understand, why it has been renamed from specific
> > zram_X_show to X_show. what gives?
> 
> I changed from zram_attr_##name##_show to name##_show in commit:
> fcf1bce zram: use DEVICE_ATTR_[RW|RO|WO] to define zram sys device attribute
> 
> I just want to keep the name consistent with others, like
> disksize_show(), initstate_show().

aha, I see.

	-ss

> Thanks.
> 
> >
> >
> > can't help, catches my eye every time, that rename has broken the original
> > formatting:
> >
> >
> > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> > index 9250b3f..c567af5 100644
> > --- a/drivers/block/zram/zram_drv.c
> > +++ b/drivers/block/zram/zram_drv.c
> > @@ -44,7 +44,7 @@ static const char *default_compressor = "lzo";
> >  static unsigned int num_devices = 1;
> >
> >  #define ZRAM_ATTR_RO(name)                                             \
> > -static ssize_t name##_show(struct device *d,           \
> > +static ssize_t name##_show(struct device *d,                           \
> >                                 struct device_attribute *attr, char *b) \
> >  {                                                                      \
> >         struct zram *zram = dev_to_zram(d);                             \
> >
> >
> >
> > I don't have any objections. but do we really want to wrap atomic ops in
> > semaphore? it is really such serious race?
> >
> >
> >         -ss
> >
> >>       struct zram *zram = dev_to_zram(d);                             \
> >> -     return scnprintf(b, PAGE_SIZE, "%llu\n",                        \
> >> -             (u64)atomic64_read(&zram->stats.name));                 \
> >> +     u64 val = 0;                                                    \
> >> +                                                                     \
> >> +     down_read(&zram->init_lock);                                    \
> >> +     if (init_done(zram))                                            \
> >> +             val = atomic64_read(&zram->stats.name);                 \
> >> +     up_read(&zram->init_lock);                                      \
> >> +     return scnprintf(b, PAGE_SIZE, "%llu\n", val);                  \
> >>  }                                                                    \
> >>  static DEVICE_ATTR_RO(name);
> >>
> >> @@ -67,8 +72,14 @@ static ssize_t disksize_show(struct device *dev,
> >>               struct device_attribute *attr, char *buf)
> >>  {
> >>       struct zram *zram = dev_to_zram(dev);
> >> +     u64 val = 0;
> >> +
> >> +     down_read(&zram->init_lock);
> >> +     if (init_done(zram))
> >> +             val = zram->disksize;
> >> +     up_read(&zram->init_lock);
> >>
> >> -     return scnprintf(buf, PAGE_SIZE, "%llu\n", zram->disksize);
> >> +     return scnprintf(buf, PAGE_SIZE, "%llu\n", val);
> >>  }
> >>
> >>  static ssize_t initstate_show(struct device *dev,
> >> @@ -88,9 +99,14 @@ static ssize_t orig_data_size_show(struct device *dev,
> >>               struct device_attribute *attr, char *buf)
> >>  {
> >>       struct zram *zram = dev_to_zram(dev);
> >> +     u64 val = 0;
> >> +
> >> +     down_read(&zram->init_lock);
> >> +     if (init_done(zram))
> >> +             val = atomic64_read(&zram->stats.pages_stored) << PAGE_SHIFT;
> >> +     up_read(&zram->init_lock);
> >>
> >> -     return scnprintf(buf, PAGE_SIZE, "%llu\n",
> >> -             (u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
> >> +     return scnprintf(buf, PAGE_SIZE, "%llu\n", val);
> >>  }
> >>
> >>  static ssize_t mem_used_total_show(struct device *dev,
> >> @@ -957,10 +973,6 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
> >>       struct bio_vec bv;
> >>
> >>       zram = bdev->bd_disk->private_data;
> >> -     if (!valid_io_request(zram, sector, PAGE_SIZE)) {
> >> -             atomic64_inc(&zram->stats.invalid_io);
> >> -             return -EINVAL;
> >> -     }
> >>
> >>       down_read(&zram->init_lock);
> >>       if (unlikely(!init_done(zram))) {
> >> @@ -968,6 +980,13 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
> >>               goto out_unlock;
> >>       }
> >>
> >> +     if (!valid_io_request(zram, sector, PAGE_SIZE)) {
> >> +             atomic64_inc(&zram->stats.invalid_io);
> >> +             err = -EINVAL;
> >> +             goto out_unlock;
> >> +     }
> >> +
> >> +
> >>       index = sector >> SECTORS_PER_PAGE_SHIFT;
> >>       offset = sector & (SECTORS_PER_PAGE - 1) << SECTOR_SHIFT;
> >>
> >> --
> >> 1.9.1
> >>
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Ganesh Mahendran <opensource.ganesh@gmail.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Minchan Kim <minchan@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Linux-MM <linux-mm@kvack.org>, Nitin Gupta <ngupta@vflare.org>,
	Jerome Marchand <jmarchan@redhat.com>
Subject: Re: [PATCH 2/2] zram: protect zram->stat race with init_lock
Date: Sun, 25 Jan 2015 23:38:34 +0900	[thread overview]
Message-ID: <20150125143834.GA951@swordfish> (raw)
In-Reply-To: <CADAEsF_pd_n9G4jft1dnXYM6N7SZ+YMQSKCAAszuLrpygaTQvQ@mail.gmail.com>

Hello,

On (01/24/15 21:17), Ganesh Mahendran wrote:
> Hello Sergey
> 
> 2015-01-23 22:38 GMT+08:00 Sergey Senozhatsky <sergey.senozhatsky@gmail.com>:
> > On (01/23/15 14:58), Minchan Kim wrote:
> >> The zram->stat handling should be procted by init_lock.
> >> Otherwise, user could see stale value from the stat.
> >>
> >> Signed-off-by: Minchan Kim <minchan@kernel.org>
> >> ---
> >>
> >> I don't think it's stable material. The race is rare in real practice
> >> and this stale stat value read is not a critical.
> >>
> >>  drivers/block/zram/zram_drv.c | 37 ++++++++++++++++++++++++++++---------
> >>  1 file changed, 28 insertions(+), 9 deletions(-)
> >>
> >> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> >> index 0299d82275e7..53f176f590b0 100644
> >> --- a/drivers/block/zram/zram_drv.c
> >> +++ b/drivers/block/zram/zram_drv.c
> >> @@ -48,8 +48,13 @@ static ssize_t name##_show(struct device *d,               \
> >>                               struct device_attribute *attr, char *b) \
> >>  {                                                                    \
> >
> > a side note: I wasn't Cc'd in that patchset and found out it only when it's
> > been merged. I'm not sure I understand, why it has been renamed from specific
> > zram_X_show to X_show. what gives?
> 
> I changed from zram_attr_##name##_show to name##_show in commit:
> fcf1bce zram: use DEVICE_ATTR_[RW|RO|WO] to define zram sys device attribute
> 
> I just want to keep the name consistent with others, like
> disksize_show(), initstate_show().

aha, I see.

	-ss

> Thanks.
> 
> >
> >
> > can't help, catches my eye every time, that rename has broken the original
> > formatting:
> >
> >
> > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> > index 9250b3f..c567af5 100644
> > --- a/drivers/block/zram/zram_drv.c
> > +++ b/drivers/block/zram/zram_drv.c
> > @@ -44,7 +44,7 @@ static const char *default_compressor = "lzo";
> >  static unsigned int num_devices = 1;
> >
> >  #define ZRAM_ATTR_RO(name)                                             \
> > -static ssize_t name##_show(struct device *d,           \
> > +static ssize_t name##_show(struct device *d,                           \
> >                                 struct device_attribute *attr, char *b) \
> >  {                                                                      \
> >         struct zram *zram = dev_to_zram(d);                             \
> >
> >
> >
> > I don't have any objections. but do we really want to wrap atomic ops in
> > semaphore? it is really such serious race?
> >
> >
> >         -ss
> >
> >>       struct zram *zram = dev_to_zram(d);                             \
> >> -     return scnprintf(b, PAGE_SIZE, "%llu\n",                        \
> >> -             (u64)atomic64_read(&zram->stats.name));                 \
> >> +     u64 val = 0;                                                    \
> >> +                                                                     \
> >> +     down_read(&zram->init_lock);                                    \
> >> +     if (init_done(zram))                                            \
> >> +             val = atomic64_read(&zram->stats.name);                 \
> >> +     up_read(&zram->init_lock);                                      \
> >> +     return scnprintf(b, PAGE_SIZE, "%llu\n", val);                  \
> >>  }                                                                    \
> >>  static DEVICE_ATTR_RO(name);
> >>
> >> @@ -67,8 +72,14 @@ static ssize_t disksize_show(struct device *dev,
> >>               struct device_attribute *attr, char *buf)
> >>  {
> >>       struct zram *zram = dev_to_zram(dev);
> >> +     u64 val = 0;
> >> +
> >> +     down_read(&zram->init_lock);
> >> +     if (init_done(zram))
> >> +             val = zram->disksize;
> >> +     up_read(&zram->init_lock);
> >>
> >> -     return scnprintf(buf, PAGE_SIZE, "%llu\n", zram->disksize);
> >> +     return scnprintf(buf, PAGE_SIZE, "%llu\n", val);
> >>  }
> >>
> >>  static ssize_t initstate_show(struct device *dev,
> >> @@ -88,9 +99,14 @@ static ssize_t orig_data_size_show(struct device *dev,
> >>               struct device_attribute *attr, char *buf)
> >>  {
> >>       struct zram *zram = dev_to_zram(dev);
> >> +     u64 val = 0;
> >> +
> >> +     down_read(&zram->init_lock);
> >> +     if (init_done(zram))
> >> +             val = atomic64_read(&zram->stats.pages_stored) << PAGE_SHIFT;
> >> +     up_read(&zram->init_lock);
> >>
> >> -     return scnprintf(buf, PAGE_SIZE, "%llu\n",
> >> -             (u64)(atomic64_read(&zram->stats.pages_stored)) << PAGE_SHIFT);
> >> +     return scnprintf(buf, PAGE_SIZE, "%llu\n", val);
> >>  }
> >>
> >>  static ssize_t mem_used_total_show(struct device *dev,
> >> @@ -957,10 +973,6 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
> >>       struct bio_vec bv;
> >>
> >>       zram = bdev->bd_disk->private_data;
> >> -     if (!valid_io_request(zram, sector, PAGE_SIZE)) {
> >> -             atomic64_inc(&zram->stats.invalid_io);
> >> -             return -EINVAL;
> >> -     }
> >>
> >>       down_read(&zram->init_lock);
> >>       if (unlikely(!init_done(zram))) {
> >> @@ -968,6 +980,13 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
> >>               goto out_unlock;
> >>       }
> >>
> >> +     if (!valid_io_request(zram, sector, PAGE_SIZE)) {
> >> +             atomic64_inc(&zram->stats.invalid_io);
> >> +             err = -EINVAL;
> >> +             goto out_unlock;
> >> +     }
> >> +
> >> +
> >>       index = sector >> SECTORS_PER_PAGE_SHIFT;
> >>       offset = sector & (SECTORS_PER_PAGE - 1) << SECTOR_SHIFT;
> >>
> >> --
> >> 1.9.1
> >>
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> 

  reply	other threads:[~2015-01-25 14:38 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23  5:58 [PATCH 1/2] zram: free meta out of init_lock Minchan Kim
2015-01-23  5:58 ` Minchan Kim
2015-01-23  5:58 ` [PATCH 2/2] zram: protect zram->stat race with init_lock Minchan Kim
2015-01-23  5:58   ` Minchan Kim
2015-01-23 13:45   ` Jerome Marchand
2015-01-23 14:38   ` Sergey Senozhatsky
2015-01-23 14:38     ` Sergey Senozhatsky
2015-01-24 13:17     ` Ganesh Mahendran
2015-01-24 13:17       ` Ganesh Mahendran
2015-01-25 14:38       ` Sergey Senozhatsky [this message]
2015-01-25 14:38         ` Sergey Senozhatsky
2015-01-23 13:07 ` [PATCH 1/2] zram: free meta out of init_lock Jerome Marchand
2015-01-23 14:24 ` Sergey Senozhatsky
2015-01-23 14:24   ` Sergey Senozhatsky
2015-01-23 14:48   ` Jerome Marchand
2015-01-23 15:47     ` Sergey Senozhatsky
2015-01-23 15:47       ` Sergey Senozhatsky
2015-01-26  1:33       ` Minchan Kim
2015-01-26  1:33         ` Minchan Kim
2015-01-26 14:17         ` Sergey Senozhatsky
2015-01-26 14:17           ` Sergey Senozhatsky
2015-01-26 16:00           ` Minchan Kim
2015-01-26 16:00             ` Minchan Kim
2015-01-27  2:17             ` Sergey Senozhatsky
2015-01-27  2:17               ` Sergey Senozhatsky
2015-01-27  3:18               ` Minchan Kim
2015-01-27  3:18                 ` Minchan Kim
2015-01-27  4:03                 ` Sergey Senozhatsky
2015-01-27  4:03                   ` Sergey Senozhatsky
2015-01-28  0:15                   ` Minchan Kim
2015-01-28  0:15                     ` Minchan Kim
2015-01-28  0:22                     ` Minchan Kim
2015-01-28  0:22                       ` Minchan Kim
2015-01-28  2:07                       ` Sergey Senozhatsky
2015-01-28  2:07                         ` Sergey Senozhatsky
2015-01-28  2:57                         ` Minchan Kim
2015-01-28  2:57                           ` Minchan Kim
2015-01-28  3:53                           ` Sergey Senozhatsky
2015-01-28  3:53                             ` Sergey Senozhatsky
2015-01-28  4:07                             ` Sergey Senozhatsky
2015-01-28  4:07                               ` Sergey Senozhatsky
2015-01-28  4:50                               ` Sergey Senozhatsky
2015-01-28  4:50                                 ` Sergey Senozhatsky
2015-01-28  4:58                                 ` Minchan Kim
2015-01-28  4:58                                   ` Minchan Kim
2015-01-28  5:35                                   ` Minchan Kim
2015-01-28  5:35                                     ` Minchan Kim
2015-01-28  6:08                                     ` Sergey Senozhatsky
2015-01-28  6:08                                       ` Sergey Senozhatsky
2015-01-28  6:10                                       ` Sergey Senozhatsky
2015-01-28  6:10                                         ` Sergey Senozhatsky
2015-01-28  4:55                             ` Minchan Kim
2015-01-28  4:55                               ` Minchan Kim
2015-01-28  0:24                     ` Sergey Senozhatsky
2015-01-28  0:24                       ` Sergey Senozhatsky
2015-01-28  0:59                       ` Minchan Kim
2015-01-28  0:59                         ` Minchan Kim
2015-01-26 14:34         ` Jerome Marchand
2015-01-26 15:52           ` Minchan Kim
2015-01-26 15:52             ` Minchan Kim

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=20150125143834.GA951@swordfish \
    --to=sergey.senozhatsky@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jmarchan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=opensource.ganesh@gmail.com \
    /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.