Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2774191rdb; Mon, 5 Feb 2024 18:24:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6un2ZeUAB0/6vLzJjtdC8+OMINuCQ14oA6eINIZVi1NggWgLDR8zswxyyvS6WxmXrK+Tk X-Received: by 2002:a05:620a:4acf:b0:785:53cc:ba81 with SMTP id sq15-20020a05620a4acf00b0078553ccba81mr1154635qkn.42.1707186266309; Mon, 05 Feb 2024 18:24:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707186266; cv=pass; d=google.com; s=arc-20160816; b=jpu7lVfonBU3L9JOqYLbsUuaGaK6sy+ty/iRvGYSbKmlENEMkpyxEuqPxzcBD+ZXxo 2155pGHbzP9/b6VDBQLZDYZ4VTWWTyYkCYeQoFgL1v0knyyAibUlzFenFtO7ymyNKQp7 lZh3YIdgtFyIve9m/hZTf7LRfHCOCqp2yEuPQ+4zjZNMojT5J1DKRFEX0okM7hsITJfY HqBO0gNeYG6cRZTz26WZ1ZAJ2GWKBYpG7UFL4SqIthwj4vrDounglnOk4B4KGvw39tsO uardJsxPNOHZx5UQrAmJYbYo6WqEguxDmhnXLE7L7m7M4u9r72z0GgDsqD5QIJvf5Ajz OFLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1qHSymltue5KrgCPgqetkQh5GExE2vnP3lWXH+/bErQ=; fh=oBwWdG3+1tbtzyOVul8wUmFaqL0gztytq5HiRW6mR/Y=; b=s1Leh/ruDMwY+vXp+QzWsynVJt94zyGNdtjgRY1NPvNnlJtvUnJz6dS3xLYw7umidb ZvezYXjN+GNtIkXxGR9oRlinIs38wu14uW448O2p1Nx6+Wi7FpeYXhPVEpTVfU1ljl4w qtGADLLNzLmc4yxKLWQP5pa/SBuGW1h2/U5vgFb/LBqEsBXDmZhULoxjMt/7UsHzIoOQ 4S7c+0wPeNrL74EzxgwJxO/jxoDoJF6u1pRZe43hQtYJh183YfYAuT+jOQcyguP3SwL3 /kvPIOCbbIxI8AO41WBDElvo75u5PlPO3MozU7Ny7BOt9GcNWNT2+EgFkzX2zh/P+eZD 8wRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RnJetQo5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54202-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54202-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCV3l6WT6p5pV+6EUGSQ+sOU51DsS3P0VegFfHt8nH2REh1FLKIlydrjsK2i9WqWpEHP0efgyWtZs03aHw6ZVQIkXn2swNoN1bE9Mso0aQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id de37-20020a05620a372500b007840425e501si1408195qkb.279.2024.02.05.18.24.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 18:24:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54202-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RnJetQo5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54202-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54202-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CC0141C23706 for ; Tue, 6 Feb 2024 02:24:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40D9B56B95; Tue, 6 Feb 2024 02:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RnJetQo5" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67E4256B68 for ; Tue, 6 Feb 2024 02:24:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707186253; cv=none; b=lq37GRmbzppSnemJDcy+zVKSejn2fpGClroBSceKsw9DtdmSXzzuQTfeR+ZnTlkLdJ0SAkLHLbOKiYmFzhAWAf2XHvZ35/QulTGMAjwizWx6V6gaNCI66thhBoAWEsl+DiRAjidTSsuEdwIQ5uvOV3w4vswiPxVHEEx1cTEHdQk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707186253; c=relaxed/simple; bh=gP1SNSrFBlGtxxoCJK90VW8nMVu/mXcAmT+PUBPwbnY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iZK+jyCt7aeX2UEuDz2dEVEAb67cunz/up/pF6OjOyJ3jh7KUYeFOtGeOrsFglH/ezCo3Axw5UuBnrwAuIH0sZJ6wWAikZey3U9Qa+CvbELcNwGW0UB9xWw6wJH5lAxbQchbPRQxfgNYP4ZAzGBpjkJ7tKTJ5cQfZCptYWFmeok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RnJetQo5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B806CC4166D; Tue, 6 Feb 2024 02:24:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707186252; bh=gP1SNSrFBlGtxxoCJK90VW8nMVu/mXcAmT+PUBPwbnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RnJetQo5yXZtVIzdqT7I2bsQ2Q0rf/2IJ5s0/Hb4g88pYbpEhXK7vxpcNaUuXoAuc Tah5pthrBmltjyo2WhboHUg05bJ/kxhO8MjQ6zRpVuodxGkyevLleK9PtY4DDtRaP0 MGo15cv/8l/yM3wfJaiOv42xDzscEGvtKAvPt/l15lRqu2sRakJT7Taf6FNtiD3ijB I5GGiYRK16Z36NY3nPCfaMHD0yFovIei8pC3Bf2dmOOmCPHU3A4wwyvi2aQ3mj/mKp TZDaFIAGn1USMl61w7761TV9JG4lzLbwDEkOUo7j0kItsGL6oH1YweLO+x8TNdkjLn o+NGYn5w8sqOA== From: SeongJae Park To: Kairui Song Cc: linux-mm@kvack.org, Andrew Morton , "Huang, Ying" , Chris Li , Minchan Kim , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Yosry Ahmed , David Hildenbrand , Yu Zhao , linux-kernel@vger.kernel.org, Kairui Song Subject: Re: [PATCH] mm/swap: fix race condition in direct swapin path Date: Mon, 5 Feb 2024 18:24:09 -0800 Message-Id: <20240206022409.202536-1-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240205110959.4021-1-ryncsn@gmail.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Kairui, On Mon, 5 Feb 2024 19:09:59 +0800 Kairui Song wrote: [...] > mm/memory.c | 19 +++++++++++++++++++ > mm/swap.h | 5 +++++ > mm/swapfile.c | 16 ++++++++++++++++ > 3 files changed, 40 insertions(+) > > diff --git a/mm/memory.c b/mm/memory.c > index 7e1f4849463a..fd7c55a292f1 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3867,6 +3867,20 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > if (!folio) { > if (data_race(si->flags & SWP_SYNCHRONOUS_IO) && > __swap_count(entry) == 1) { > + /* > + * With swap count == 1, after we read the entry, > + * other threads could finish swapin first, free > + * the entry, then swapout the modified page using > + * the same entry. Now the content we just read is > + * stalled, and it's undetectable as pte_same() > + * returns true due to entry reuse. > + * > + * So pin the swap entry using the cache flag even > + * cache is not used. > + */ > + if (swapcache_prepare(entry)) > + goto out; > + I'm getting below build error after this patch. I guess maybe the code need to take care of CONFIG_SWAP unset case? .../mm/memory.c: In function 'do_swap_page': .../mm/memory.c:4004:8: error: implicit declaration of function 'swapcache_prepare'; did you mean 'swapcache_clear'? [-Werror=implicit-function-declaration] 4004 | if (swapcache_prepare(entry)) | ^~~~~~~~~~~~~~~~~ | swapcache_clear Thanks, SJ [...]