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 9E859CA9ECB for ; Thu, 31 Oct 2019 14:46:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F94A2086D for ; Thu, 31 Oct 2019 14:46:14 +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="SDowLBhS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F94A2086D 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 EDB3D6B0270; Thu, 31 Oct 2019 10:46:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8BF96B0272; Thu, 31 Oct 2019 10:46:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA2AE6B0273; Thu, 31 Oct 2019 10:46:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id B808D6B0270 for ; Thu, 31 Oct 2019 10:46:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 3F8B5181AEF30 for ; Thu, 31 Oct 2019 14:46:13 +0000 (UTC) X-FDA: 76104355026.21.truck34_1928653a0bf18 X-HE-Tag: truck34_1928653a0bf18 X-Filterd-Recvd-Size: 5172 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Thu, 31 Oct 2019 14:46:12 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id l3so4196715pgr.8 for ; Thu, 31 Oct 2019 07:46:12 -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=VWgXlmxE3fBiZT8aIhs/DS4aNmvkGR68uaaLKL0l8d4=; b=SDowLBhSZ+y9/Dg4WmBCaQ6EMNFle31DLfPhIIZPtF313BwZ4zHX7+ABBVjlHhdNqP VuWnylLtZF5nzOmifcNXdDcour36GOMWkojYCTxp+aB7EEZzbzDJh4mSlQXOEeiAvMzP dJTljtrkqFuUOHmhulp9r29e3JMrg2zAekgxJGz71WsxTt9CwofmX9b0t1n5nFf14hpW udP4JuARMDK5672YElFr/FfuplmKtNikbK0j0rD1RpnXPy5G31ouielAFWzRvs+f4G1s at81Y2/rODoZVnRMo/iRGqD+xkPjCi7IetoHUSn0U/zkWEAkxXvl9Pz3+DMgJDJyFrHZ VupA== 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=VWgXlmxE3fBiZT8aIhs/DS4aNmvkGR68uaaLKL0l8d4=; b=gMI95oiSx8el05xPLlDJHraGXYiRIXrqM4BnaeFO0p+L0NQDK/MxWdif1ViPhOePN0 dGMU3KTVEwoKEzqSw4mprOuiSDsgVkRbYH1g8pB+y8YuWCDPM4DNGGw2IcA4QrxrzTM2 UtE/C+G3KoKzfPUENM28rL5VgsNckFKBpvjtc1pRqJBfeJgC060PwRcyhFSt8NySzGqb DBd+RjEpr1eFjdd6WzpLuSzrP2zCLd19WPLqtZAOJOIbBMKtz+ZVtuBSFknhvj6PKUuU 1yzaeiLz5VXh2JqCisPT9rXZYvur95EWbIy6vDyfcU5/cg1kGcQ+rE2c0ZUNOGztMXPW 3f+w== X-Gm-Message-State: APjAAAWuK7VcDvzkhRQANCS6GTgJdjW5aKmw2RSWavGAXILZQcXZUmbj kgBMQ/dgi959W++gMqY9+uc= X-Google-Smtp-Source: APXvYqwLsBNKDO7aQROJB7W2RF1s4nBpQ9nA5q0uUCqZKmwzdaGZ05NIS7s4fTXnCLoHAT+rrw8Ghw== X-Received: by 2002:a63:b644:: with SMTP id v4mr7023502pgt.249.1572533171097; Thu, 31 Oct 2019 07:46:11 -0700 (PDT) Received: from google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id y126sm4559965pfg.74.2019.10.31.07.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 07:46:09 -0700 (PDT) Date: Thu, 31 Oct 2019 07:46:08 -0700 From: Minchan Kim To: Michal Hocko Cc: Vinayak Menon , linux-mm@kvack.org, kernel-team@android.com Subject: Re: [PATCH] mm: do not free shared swap slots Message-ID: <20191031144608.GA128849@google.com> References: <1571743294-14285-1-git-send-email-vinmenon@codeaurora.org> <20191030002447.GB175126@google.com> <20191030102409.GZ31513@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191030102409.GZ31513@dhcp22.suse.cz> 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 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) > > -- > Michal Hocko > SUSE Labs