From patchwork Wed Dec 15 12:23:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charan Teja Kalla X-Patchwork-Id: 12678225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD629C433EF for ; Wed, 15 Dec 2021 12:24:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61E596B0071; Wed, 15 Dec 2021 07:24:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CD946B0073; Wed, 15 Dec 2021 07:24:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4952A6B0074; Wed, 15 Dec 2021 07:24:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id 3A36B6B0071 for ; Wed, 15 Dec 2021 07:24:32 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 01B62180AF84E for ; Wed, 15 Dec 2021 12:24:22 +0000 (UTC) X-FDA: 78919946364.31.479B27A Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by imf27.hostedemail.com (Postfix) with ESMTP id D835040013 for ; Wed, 15 Dec 2021 12:24:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1639571061; x=1671107061; h=from:to:cc:subject:date:message-id:mime-version; bh=0T9EXSTFudFillhaxA4SCedNXGE4nE1HUul8/TIhE10=; b=grcPes6UGogSSkce13WVKDa6KUK7Kmh/aCUId3/K3PBILec6VGePlnMd lRHmQ5FkbrqsoesH06qUthF8QR29XmbiJirYpgerNNBSBPemiBtjhbyHh FL962SIfQ/uFFNPFnvA4Iohsdi07dJ5Z9593DQ7fGtu+6Y/pjFQLVT/4X 4=; Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 15 Dec 2021 04:24:20 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2021 04:24:19 -0800 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 15 Dec 2021 04:24:19 -0800 Received: from hu-charante-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 15 Dec 2021 04:24:16 -0800 From: Charan Teja Reddy To: , , , , CC: , , Charan Teja Reddy Subject: [PATCH] mm/madvise: elevate page refcount while isolating in process_madvise() Date: Wed, 15 Dec 2021 17:53:39 +0530 Message-ID: <1639571019-30043-1-git-send-email-quic_charante@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Rspamd-Queue-Id: D835040013 X-Stat-Signature: o1k8ui8i9i8j4swxymmx4wwhut34yacx Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcdkim header.b=grcPes6U; spf=pass (imf27.hostedemail.com: domain of quic_charante@quicinc.com designates 129.46.98.28 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com X-Rspamd-Server: rspam10 X-HE-Tag: 1639571060-180316 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: The documentation of isolate_lru_page() says that, "it must be called with an elevated refcount on the page", which is not followed while isolating pages in process_madvise() system call with advise MADV_PAGEOUT. Fix it. Signed-off-by: Charan Teja Reddy --- mm/madvise.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 0734db8..4c4a8e9 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -317,6 +317,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, pte_t *orig_pte, *pte, ptent; spinlock_t *ptl; struct page *page = NULL; + int ret; LIST_HEAD(page_list); if (fatal_signal_pending(current)) @@ -373,12 +374,15 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, ClearPageReferenced(page); test_and_clear_page_young(page); if (pageout) { - if (!isolate_lru_page(page)) { + get_page(page); + ret = isolate_lru_page(page); + if (!ret) { if (PageUnevictable(page)) putback_lru_page(page); else list_add(&page->lru, &page_list); } + put_page(page); } else deactivate_page(page); huge_unlock: @@ -459,12 +463,15 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, ClearPageReferenced(page); test_and_clear_page_young(page); if (pageout) { - if (!isolate_lru_page(page)) { + get_page(page); + ret = isolate_lru_page(page); + if (!ret) { if (PageUnevictable(page)) putback_lru_page(page); else list_add(&page->lru, &page_list); } + put_page(page); } else deactivate_page(page); }