From patchwork Wed May 4 21:44:34 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: 12838672 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 0A4CCC433F5 for ; Wed, 4 May 2022 21:45:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F5EE6B0082; Wed, 4 May 2022 17:45:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 752FC6B0087; Wed, 4 May 2022 17:45:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4146E6B0085; Wed, 4 May 2022 17:45:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 32B6C6B0081 for ; Wed, 4 May 2022 17:45:22 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0E533912 for ; Wed, 4 May 2022 21:45:22 +0000 (UTC) X-FDA: 79429392084.19.B408753 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf22.hostedemail.com (Postfix) with ESMTP id 3D690C008F for ; Wed, 4 May 2022 21:45:20 +0000 (UTC) Received: by mail-pg1-f201.google.com with SMTP id f7-20020a6547c7000000b003c600995546so723255pgs.5 for ; Wed, 04 May 2022 14:45:21 -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=ycD61MQgIhpcrtvxZMyg0KT3Zd0aTw6m/uwS7wZnXys=; b=IvKbG9ikAwG0nZEEUErkrwBY/rU7Ow8y53t9jRhda92fSkWwB3gUi0yAkabkP2iqOQ ICOzeDuRW4QNqVHT3WYt+6dLLRlqt+POHSyGyianNm/Nw0MbVPPjav4JHqbOnO/m3L0/ +EXcK01or03BkuQQ8kn8zFWG7cJcgVRqWQlzD9FTCF1HqrOCsh6pjbUWFZrfw7kpjaBo AfROYH5pfY5eKiXNp2PKH/K6UEyiBXyyo0Rolxwq6+ZJAcRSBKyHCCnh+JTm4bmFboQM 22YpAk5Sf/ZyCO9MrR7mWPTzm5a2Gb4mat2+HE6HzXhIzClV6Azq7uRtwAX5gIwGr2fi tjew== 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=ycD61MQgIhpcrtvxZMyg0KT3Zd0aTw6m/uwS7wZnXys=; b=6tAK7WbLPiHkv9oghAIkQI5gXvWjNFvxnEMJhUFB6xLaplOOdOSFpSsOHLBMBVr3cV YsO0hpmSWzFhIotjC6jha/7ZNnwqmq/8z8+PWL+4/vecRfOAhspEsqJCP4yY5DfkmWAB 1/ZXxRkYkSp38HQPnru18auF4JrIYfRzDTvYTByyJxDSs/EZX3OJYuiovSrDkUFOw0JK ySdkhnvzqwFNR160oYR47LYXBLjsMuTQ/wGH9EBTPkh3o78paLTZ7MPBHBv9YO1rdhmh Nu1ApL6/E4ezgalFHbHxxjgSr81UHygvBWZxAFe+sLS831xWFRC3Ex3o4CDyogtJxPbT PEqA== X-Gm-Message-State: AOAM531l3KYEZcufOqciuY/BsPlHlcmglpmDwLuS9qHCgA0AxSaBzcyn LKFSB4zQJZ2zUWTDhrATNcre+0VmlXBJ X-Google-Smtp-Source: ABdhPJzQ0vQlKaoP+2IFPabfM0cx9twO9vyeIb1dIsLRcx2PJepSXdPnKmebeL+nhq0shOImF8Tbq2wMvLQC X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:903:11c7:b0:154:b936:d1d4 with SMTP id q7-20020a17090311c700b00154b936d1d4mr23584337plh.78.1651700720526; Wed, 04 May 2022 14:45:20 -0700 (PDT) Date: Wed, 4 May 2022 14:44:34 -0700 In-Reply-To: <20220504214437.2850685-1-zokeefe@google.com> Message-Id: <20220504214437.2850685-11-zokeefe@google.com> Mime-Version: 1.0 References: <20220504214437.2850685-1-zokeefe@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v5 10/13] 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 , Peter Xu , 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 , Thomas Bogendoerfer , "Zach O'Keefe" X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 3D690C008F X-Stat-Signature: 7n64qsncc4b34jcysexrcwq6c31w9k3m Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=IvKbG9ik; spf=pass (imf22.hostedemail.com: domain of 38PNyYgcKCL02rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=38PNyYgcKCL02rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1651700720-986234 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 Acked-by: David Rientjes --- mm/madvise.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 638517952bd2..08c11217025a 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1168,13 +1168,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; } @@ -1452,7 +1454,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; }