From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BFB3CA9ECB for ; Thu, 31 Oct 2019 17:15:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD8472086D for ; Thu, 31 Oct 2019 17:15:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD8472086D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4FA366B0006; Thu, 31 Oct 2019 13:15:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AB8E6B0008; Thu, 31 Oct 2019 13:15:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39B396B000A; Thu, 31 Oct 2019 13:15:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0033.hostedemail.com [216.40.44.33]) by kanga.kvack.org (Postfix) with ESMTP id 17DE66B0006 for ; Thu, 31 Oct 2019 13:15:08 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 6B433824999B for ; Thu, 31 Oct 2019 17:15:07 +0000 (UTC) X-FDA: 76104730254.07.art07_f91c0a19a10e X-HE-Tag: art07_f91c0a19a10e X-Filterd-Recvd-Size: 3281 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Thu, 31 Oct 2019 17:15:06 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 74C6AB813; Thu, 31 Oct 2019 17:15:05 +0000 (UTC) Date: Thu, 31 Oct 2019 18:15:04 +0100 From: Michal Hocko To: Minchan Kim Cc: Vinayak Menon , linux-mm@kvack.org, kernel-team@android.com Subject: Re: [PATCH] mm: do not free shared swap slots Message-ID: <20191031171504.GJ13102@dhcp22.suse.cz> References: <1571743294-14285-1-git-send-email-vinmenon@codeaurora.org> <20191030002447.GB175126@google.com> <20191030102409.GZ31513@dhcp22.suse.cz> <20191031144608.GA128849@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191031144608.GA128849@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu 31-10-19 07:46:08, Minchan Kim wrote: > On Wed, Oct 30, 2019 at 11:24:09AM +0100, Michal Hocko wrote: > > On Tue 29-10-19 17:24:47, Minchan Kim wrote: > > > On Tue, Oct 22, 2019 at 04:51:34PM +0530, Vinayak Menon wrote: > > > > The following race is observed due to which a processes faulting > > > > on a swap entry, finds the page neither in swapcache nor swap. This > > > > causes zram to give a zero filled page that gets mapped to the > > > > process, resulting in a user space crash later. > > > > > > > > Consider parent and child processes Pa and Pb sharing the same swap > > > > slot with swap_count 2. Swap is on zram with SWP_SYNCHRONOUS_IO set. > > > > Virtual address 'VA' of Pa and Pb points to the shared swap entry. > > > > > > > > Pa Pb > > > > > > > > fault on VA fault on VA > > > > do_swap_page do_swap_page > > > > lookup_swap_cache fails lookup_swap_cache fails > > > > Pb scheduled out > > > > swapin_readahead (deletes zram entry) > > > > swap_free (makes swap_count 1) > > > > Pb scheduled in > > > > swap_readpage (swap_count == 1) > > > > Takes SWP_SYNCHRONOUS_IO path > > > > zram enrty absent > > > > zram gives a zero filled page > > > > > > > > Fix this by making sure that swap slot is freed only when swap count > > > > drops down to one. > > > > > > > > Signed-off-by: Vinayak Menon > > > > Suggested-by: Minchan Kim > > > > Cc: Michal Hocko > > > Acked-by: Minchan Kim > > > > > > -stable material from v4.15. > > > > Which commit does this fix? Fixes: tag would be highly appreciated. > > Oops, I missed to mention it. > Fixes: aa8d22a11da9 (mm: swap: SWP_SYNCHRONOUS_IO: skip swapcache only if swapped page has no other reference) Thanks! -- Michal Hocko SUSE Labs