From patchwork Sun Apr 10 13:54:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 12808153 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 4F9D7C433EF for ; Sun, 10 Apr 2022 13:55:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 794B68D0005; Sun, 10 Apr 2022 09:55:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71CA68D0001; Sun, 10 Apr 2022 09:55:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 596A18D0005; Sun, 10 Apr 2022 09:55:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 3B8D88D0001 for ; Sun, 10 Apr 2022 09:55:17 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 0DF4360BB3 for ; Sun, 10 Apr 2022 13:55:17 +0000 (UTC) X-FDA: 79341116274.01.DA9D40B Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf04.hostedemail.com (Postfix) with ESMTP id 8712040005 for ; Sun, 10 Apr 2022 13:55:16 +0000 (UTC) Received: by mail-pg1-f201.google.com with SMTP id t3-20020a656083000000b0039cf337edd6so4114414pgu.18 for ; Sun, 10 Apr 2022 06:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=nq/xQcXjJdglMeLB91FD7YYLmBCvBfcr3XMv5Gt3XKQ=; b=rR8VEjDNZe1Lq8K0HN+KZaEFxGOw1k4/zI8bdQClwOSAIsJtXhF37fvSBGqwJVkHEb 6JS4nqV5inxX+WAlSugafU3p7TVOU5OuHKco84b5y9TcTh6vlnS5fiqipZbb/TyqDKh0 9Sqv7KJIB5PQQaArcvXATNPz3LQCZz73d0k2A6ulbnzUZUpsKwtzAQvXNtf43XkP/yfE dpBB+Kl1Yj6vUNBm84FhlSAYeLQ+Gw/rzyacWsCH56JCydNloqhUcpZ6ZTmqmdY8NcrL EfWGRma5HKPyRRw/BsxnK+Ha1RvqkNR6N3dvQ0LRJZoWwpHhTaaQVfvTQ7i0X/TqsWA4 Dhqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=nq/xQcXjJdglMeLB91FD7YYLmBCvBfcr3XMv5Gt3XKQ=; b=Pk4iriU/jdCZCdh1HUbBimTxM+axBzllSwYgp3VrKDJx9/4XxirgRjvhD70A5pHHlZ ucG+J5KN3uxNyJuliUp4TyitiyUz6qtGKQm3aasG7EqHD7KJj9HR12HtcpNwSSQimBwA V5ddzAjp7MrneG+wQbAf01UAEO9pQM+BblcY2UnM3ORzqMcGxdhuacLCaRWucVspv806 INTuJmCMvOpvGumX/fTFcdxQk/A0Xz/+9/l1BYFtzQ3EGkK2Ye8EMtM2SYI8GEgO9LOe bgQ84IFvM53w4MvvDLV8QZl65ZGNc3/m6x+WWnzhVe7W1QbCQkAj81Lq9dBDYUmwHYp0 +Xeg== X-Gm-Message-State: AOAM532I43Qd48yu0cc5k+wyUNu8qbhDngdzEYUntTfu+jLF7VitdI28 kZ42yzwOnQr3A2kARUQxuIBTZDb+nbDD X-Google-Smtp-Source: ABdhPJwXPcmP3mctsbyaCVDAgt+4qnBdcjuFNqbo1MA+nwhusXZmTjIdz8kw0AOGrO2ngfIFTKYMrrLZsoNN X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:6901:b0:156:4aad:fad7 with SMTP id j1-20020a170902690100b001564aadfad7mr28367254plk.33.1649598915487; Sun, 10 Apr 2022 06:55:15 -0700 (PDT) Date: Sun, 10 Apr 2022 06:54:42 -0700 In-Reply-To: <20220410135445.3897054-1-zokeefe@google.com> Message-Id: <20220410135445.3897054-10-zokeefe@google.com> Mime-Version: 1.0 References: <20220410135445.3897054-1-zokeefe@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH 09/12] mm/madvise: add MADV_COLLAPSE to process_madvise() From: "Zach O'Keefe" To: Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Michal Hocko , Pasha Tatashin , SeongJae Park , Song Liu , Vlastimil Babka , Yang Shi , Zi Yan , linux-mm@kvack.org Cc: Andrea Arcangeli , Andrew Morton , Arnd Bergmann , Axel Rasmussen , Chris Kennelly , Chris Zankel , Helge Deller , Hugh Dickins , Ivan Kokshaysky , "James E.J. Bottomley" , Jens Axboe , "Kirill A. Shutemov" , Matt Turner , Max Filippov , Miaohe Lin , Minchan Kim , Patrick Xia , Pavel Begunkov , Peter Xu , Thomas Bogendoerfer , "Zach O'Keefe" X-Rspam-User: X-Stat-Signature: 1z7pd7zz5tr6ouq7b79xh8czjczfd85h Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rR8VEjDN; spf=pass (imf04.hostedemail.com: domain of 3w-FSYgcKCOolaWQQRQSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3w-FSYgcKCOolaWQQRQSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8712040005 X-HE-Tag: 1649598916-691252 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: Allow MADV_COLLAPSE behavior for process_madvise(2) if caller has CAP_SYS_ADMIN or is requesting collapse of it's own memory. Signed-off-by: Zach O'Keefe --- mm/madvise.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 7ad53e5311cf..a5c82fa7972b 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1165,13 +1165,15 @@ madvise_behavior_valid(int behavior) } static bool -process_madvise_behavior_valid(int behavior) +process_madvise_behavior_valid(int behavior, struct task_struct *task) { switch (behavior) { case MADV_COLD: case MADV_PAGEOUT: case MADV_WILLNEED: return true; + case MADV_COLLAPSE: + return task == current || capable(CAP_SYS_ADMIN); default: return false; } @@ -1449,7 +1451,7 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, goto free_iov; } - if (!process_madvise_behavior_valid(behavior)) { + if (!process_madvise_behavior_valid(behavior, task)) { ret = -EINVAL; goto release_task; }