lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20181228051920.GA63763@google.com>
Date:   Fri, 28 Dec 2018 14:19:20 +0900
From:   Minchan Kim <minchan@...nel.org>
To:     Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        LKML <linux-kernel@...r.kernel.org>, joaodias@...gle.com,
        srnvs@...gle.com
Subject: Re: [PATCH] zram: idle writeback fixes and cleanup

Hi Sergey,

On Thu, Dec 27, 2018 at 11:26:24AM +0900, Sergey Senozhatsky wrote:
> On (12/24/18 12:35), Minchan Kim wrote:
> [..]
> > @@ -645,10 +680,13 @@ static ssize_t writeback_store(struct device *dev,
> >  		bvec.bv_len = PAGE_SIZE;
> >  		bvec.bv_offset = 0;
> >  
> > -		if (zram->stop_writeback) {
> > +		spin_lock(&zram->wb_limit_lock);
> > +		if (zram->wb_limit_enable && !zram->bd_wb_limit) {
> > +			spin_unlock(&zram->wb_limit_lock);
> >  			ret = -EIO;
> >  			break;
> >  		}
> > +		spin_unlock(&zram->wb_limit_lock);
> [..]
> > @@ -732,11 +771,10 @@ static ssize_t writeback_store(struct device *dev,
> >  		zram_set_element(zram, index, blk_idx);
> >  		blk_idx = 0;
> >  		atomic64_inc(&zram->stats.pages_stored);
> > -		if (atomic64_add_unless(&zram->stats.bd_wb_limit,
> > -					-1 << (PAGE_SHIFT - 12), 0)) {
> > -			if (atomic64_read(&zram->stats.bd_wb_limit) == 0)
> > -				zram->stop_writeback = true;
> > -		}
> > +		spin_lock(&zram->wb_limit_lock);
> > +		if (zram->wb_limit_enable && zram->bd_wb_limit > 0)
> > +			zram->bd_wb_limit -=  1UL << (PAGE_SHIFT - 12);
> > +		spin_unlock(&zram->wb_limit_lock);
> 
> Do we really need ->wb_limit_lock spinlock? We kinda punch it twice
> in this loop. If someone clears ->wb_limit_enable somewhere in between
> then the worst thing to happen is that we will just write extra page
> to the backing device; not a very big deal to me. Am I missing
> something?

Without the lock, bd_wb_limit store/read would be racy.

CPU A                                                           CPU B
if (zram->wb_limit_enable && zram->bd_wb_limit > 0)
                                                            zram->bd_wb_limit = 0
    zram->bd_wb_limit -= 1UL << (PAGE_SHIFT - 12) 

It makes limit feature void.

> 
> 	-ss

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ