From patchwork Mon Jan 20 01:30:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Yang X-Patchwork-Id: 13944652 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 2A265C02187 for ; Mon, 20 Jan 2025 01:31:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC4F16B007B; Sun, 19 Jan 2025 20:31:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A72786B0083; Sun, 19 Jan 2025 20:31:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 912DB6B0085; Sun, 19 Jan 2025 20:31:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7201F6B007B for ; Sun, 19 Jan 2025 20:31:07 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D3AFEB24E1 for ; Mon, 20 Jan 2025 01:31:06 +0000 (UTC) X-FDA: 83026101732.10.FA64E9E Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf04.hostedemail.com (Postfix) with ESMTP id 1041140005 for ; Mon, 20 Jan 2025 01:31:04 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GKNjPhzR; spf=pass (imf04.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=ioworker0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737336665; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=4xi6uzkmpe7CPatzY/KWNu8uk0vUaxhh6hw94Ux2ps0=; b=3A04Kj3jJlzlOQEpJx3g/gRJA14BVCgWqjrf5m3Bxl1kr6sKsMtRcFARMRYUifI8fhwFZ/ eR9vYuxKxTvhFsoPVHtCfobEldE0XwmietG1cMPlpwLMUd0oPloAfE2b88VBNNRN7a8IcS hdyKGK/EGdKEy8ZrSagsBrPSL0ZPfSw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GKNjPhzR; spf=pass (imf04.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=ioworker0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737336665; a=rsa-sha256; cv=none; b=YX2HyyHEp7zQArC6ALE1WB9aodd/pOSI4/KPatLmcimoY2t5Yp3vK391eesEhesjIaAgBR BtqKwnFtJq9eoulXJ2NwNrdmMS/0IFT+gRCXLXlW6exGFbpIUtXsyLBqqgSsxENqnXQXFN B9FJZ39R5uc5h1mraHq7kQIFEE9a3d4= Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-216728b1836so66596645ad.0 for ; Sun, 19 Jan 2025 17:31:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737336664; x=1737941464; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4xi6uzkmpe7CPatzY/KWNu8uk0vUaxhh6hw94Ux2ps0=; b=GKNjPhzRo+v0WufeEDdO2x8ItXOqKq+5i9+ZBrcalXgiZduhnTMTIEWC2KIBwg/owU DTzwTdQUNxmdDI207clGtyrO3uudtUTmH1gHOrz166CYX3w7IpGjAFSk9K/jtSEdP5Qk fcnc8yWCv948XAqwW5/6UOXlzLLYbG8nD3Xyhz9HpPJPmJ2LCURfnCIrh5fRIfyuad31 2cmOc+xMYSBdqXk2F+n0Jx+iS+dzV2EqOMx1TH4RgebVhFnFF6YrfmVz5U7EQxVFVJuV y0mwyqJp2DLv5vDcl981hvpghHy7fq89mVQ9a1q/1WdT5WQJhKy3tz/aRF0JPadngE1x /zIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737336664; x=1737941464; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4xi6uzkmpe7CPatzY/KWNu8uk0vUaxhh6hw94Ux2ps0=; b=QMI+nhVypxHhHLeYw+Y+tOd3l9xvN/A5qdQKgvdR2+AFOP23aYvhQgfRLgJotPpgDx A/0znAeES4CljReETLokbJGeTLy+rFHZZZ78rmUo/BslTORd7vwMHJiVXiVL2pTJtqkr q+vO3SuplddeGW2TjzvnkAw/r0EjNen0rwfvU6gYZs1d5X2uSJ/7vg9LK+lR6Aj7Ngr4 TJJIUowqv8h5lHKaSzfq6PPKmis28ExtsdlmOFkpLTg62Y3XLO5HyjUHxzG1gXVno3mX g07SmYaWmZw1sv1rDz7gsKMQZ9UD93RVC+nGrg87v9D+JfZId52YPikzmOFnkc2KJdeG By2A== X-Forwarded-Encrypted: i=1; AJvYcCXBk+REfvhyxE4dLsLVIqRzZ70EkAdrnWBe1lDasDK1RdHBziAd8GRvCNKOJD68+x+HFEpM9fpFoA==@kvack.org X-Gm-Message-State: AOJu0YykJBJkqFbKosDWRAIPHsGsLB/noGWC+Numln0nluIz3BCvuBQz f4mL4ZSljbpS6/jdK547A1Az+T26hnSqOq5N+4+ETQEjiNZdPwqY X-Gm-Gg: ASbGncuIXurUoj0WgzrRZ0h6vUeB6/S6UWxGebg+mEtTN7N9DRuPxjfajRnG/HzSYU1 LGuctjMHOOsbd4V+emy1E0CfnwULiQod2NPFpSYthBWhO+u62FaXDgg9GOs3W9rIe8EuVgFu2PM D/NldnrOOvuFyRVVakh0tstsSwaD3fy+hxp4dWB62L0NmplfmvNACq61Pj9mJSpXRkRGS33Gltc kyUlEBWuXsSUrwXiA+LCp3Ftjsq8NIapZuJt7qEdPYYIvJriSWOrHfZ22MvItsN/UdVpQXn6bLa bA== X-Google-Smtp-Source: AGHT+IH0kE3U5thGrd738UZ/5l7CyUWuiUCu0xb+oH2Kg60QXA/0TbPRh1L7d+VBNd4P/cmRK6QZzg== X-Received: by 2002:a17:903:1c6:b0:215:65f3:27f2 with SMTP id d9443c01a7336-21c352c7915mr142390025ad.8.1737336662931; Sun, 19 Jan 2025 17:31:02 -0800 (PST) Received: from EBJ9932692.tcent.cn ([43.134.20.116]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2ceb7476sm50716265ad.56.2025.01.19.17.30.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Jan 2025 17:31:02 -0800 (PST) From: Lance Yang To: akpm@linux-foundation.org Cc: 21cnbao@gmail.com, ryan.roberts@arm.com, dev.jain@arm.com, david@redhat.com, shy828301@gmail.com, ziy@nvidia.com, libang.li@antgroup.com, baolin.wang@linux.alibaba.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, Jason@zx2c4.com, Lance Yang , Mingzhe Yang Subject: [RFC 1/1] mm/madvise: fail MADV_PAGEOUT on VM_DROPPABLE VMA Date: Mon, 20 Jan 2025 09:30:38 +0800 Message-ID: <20250120013038.6657-1-ioworker0@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1041140005 X-Stat-Signature: sae9qbmdmeukii5mcjcuf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oVOOBqETVhWw6wp2inIFNDXCQQbk4sFpDNGSqKjc5YiHqeOcyiLHzJLY0QXOPnzAMDxzeyLWtDM4WxIcolyTP77lNNYzPR0BqeeAWlbxu/hGJLT3K6mjzenZqvgMNuxhbjQ1WQ36wACGh81RZMYM9KWj8zArGjuB+o52Xwm+MNlq6qv0+OVzsD1PbxmerX29sdqSaqiQ9MenEsSJ47LJ6wkau7+cW+xD7gjv+3eIRcyJyzS/TA/zbw0i5G9AJADF+Qc4O/KrInexoxRMep+LX9k4VK/9HVP0wpZUIbdKQ90U4rbu9jxzLrpU5Gf6hIpgl5REsWaE5SNooaKIGFgouEub54rke0vGTGCGXYXx2uml1zRgIcNSKG9R2e5wJHevH9wA1QnvCRrBHmee3to5 X-Bogosity: Ham, tests=bogofilter, spamicity=0.010458, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: MADV_PAGEOUT should fail on VMAs with the VM_DROPPABLE flag. While MADV_PAGEOUT is intended to move anonymous pages to swap, VM_DROPPABLE should not be swapped out. There is an issue where using MADV_PAGEOUT on a VMA with the VM_DROPPABLE flag behaves like MADV_DONTNEED, causing the pages to be dropped. This could break the semantics of MADV_PAGEOUT, IMO. So, let's add a check to detect the VM_DROPPABLE flag before doing MADV_PAGEOUT and returns -EINVAL. Fixes: 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings") Signed-off-by: Mingzhe Yang Signed-off-by: Lance Yang --- mm/madvise.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index 49f3a75046f6..29d0234da8a1 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1263,6 +1263,8 @@ static int madvise_vma_behavior(struct vm_area_struct *vma, case MADV_COLD: return madvise_cold(vma, prev, start, end); case MADV_PAGEOUT: + if (vma->vm_flags & VM_DROPPABLE) + return -EINVAL; return madvise_pageout(vma, prev, start, end); case MADV_FREE: case MADV_DONTNEED: