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=-3.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, FSL_HELO_FAKE,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no 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 57581CA9EAE for ; Wed, 30 Oct 2019 00:24:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1754F20856 for ; Wed, 30 Oct 2019 00:24:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hfk/nsnH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1754F20856 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 A4E1B6B0003; Tue, 29 Oct 2019 20:24:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FF566B0006; Tue, 29 Oct 2019 20:24:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89F386B0007; Tue, 29 Oct 2019 20:24:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 6D1FC6B0003 for ; Tue, 29 Oct 2019 20:24:52 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id C087E181AF5C7 for ; Wed, 30 Oct 2019 00:24:51 +0000 (UTC) X-FDA: 76098555582.24.route83_d4bb46deef58 X-HE-Tag: route83_d4bb46deef58 X-Filterd-Recvd-Size: 4616 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 30 Oct 2019 00:24:51 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id l24so218702pgh.10 for ; Tue, 29 Oct 2019 17:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lrXNWp31V7uIolYXnEozp9XaDzH6ZoIh5HZxILFhT/Y=; b=hfk/nsnHQQa/txxHQ534knLgiP07k1x7Pd3Ua+emO6KQVVYJmdo/tj77PjF96nxF/I NEIFatLJf+/wRAcQZwE823p2PDZizEZq0aNDVbrAU4Re4X9q2Rdxt3QOqWKy2YGjJxbQ +Du4h+9nY32aWKR5yD9O4FzLBo/qdxeuv7sqtg1h9ocbTaZbnt/ZmodLbGPFi5AtdfRy 5+3ngoZzGNEILdVkGSP0eL/4PeGi6vdDdTwLwmYl8kFTb4chmgk+j8pvsYGaap6ftaJN QuCUHvOaUENEqoESm26WzYlZn40aFomUOsuI5UxVRjnbb1Z7ZxzibQnSvyyvk7htwMAz Rp4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=lrXNWp31V7uIolYXnEozp9XaDzH6ZoIh5HZxILFhT/Y=; b=ll+QhKsOQhXUm8JsKAYz/Jvyddu1scrDw0Qt1qGcSDqJI1IKsTDD/bDDj//o7Ad2X0 5lWIui9iXFIGzRfFIgC1pxox6+/RZ4A2ZiBGN0Ojxp/MW5s7n1tnK5laarWQIkJF486F wmxLNAiza59GOY/1O20lji0s+HhrUMCMylgYfhEKjVEmvLvkb70Av/4o7MuV3ydF4hFd XvwTuOpO9Nl6EhPqyrd2yhTNOfCS5cibXMfXL9grlOzKUP2oEnAIczuPVJ0Wjnhu61oU SO6eV9aRiEdphVHtcn7tpJWIJ7DR0tjeQZiyxUj+0gp1fvCCSXLmFU/PaWwgzFfuIyaO oo8Q== X-Gm-Message-State: APjAAAWhCgF+kDMC48Ie45c9weBfvMBqZUqF1X36/jSWr0/iT8tycuiG sWfDW1MZ/LzK2X4oJ1uhG2M= X-Google-Smtp-Source: APXvYqxDyOynztR9PnMhv118w3hcianjuXaRNwSlYDe/Z+JAPM64FhxudgNW6NUzw54Q/QD5mNpwWg== X-Received: by 2002:a63:ff65:: with SMTP id s37mr16702175pgk.331.1572395090094; Tue, 29 Oct 2019 17:24:50 -0700 (PDT) Received: from google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id c19sm286473pfn.44.2019.10.29.17.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2019 17:24:48 -0700 (PDT) Date: Tue, 29 Oct 2019 17:24:47 -0700 From: Minchan Kim To: Vinayak Menon Cc: linux-mm@kvack.org, kernel-team@android.com, Michal Hocko Subject: Re: [PATCH] mm: do not free shared swap slots Message-ID: <20191030002447.GB175126@google.com> References: <1571743294-14285-1-git-send-email-vinmenon@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1571743294-14285-1-git-send-email-vinmenon@codeaurora.org> 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 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. Thanks.