From patchwork Thu Apr 14 18:06:09 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: 12813850 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 502EDC433FE for ; Thu, 14 Apr 2022 18:06:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5939C6B0080; Thu, 14 Apr 2022 14:06:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5417D6B0083; Thu, 14 Apr 2022 14:06:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 236C86B0080; Thu, 14 Apr 2022 14:06:51 -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 0348C6B0080 for ; Thu, 14 Apr 2022 14:06:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CDA1E2358C for ; Thu, 14 Apr 2022 18:06:50 +0000 (UTC) X-FDA: 79356265380.25.5246BA9 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf24.hostedemail.com (Postfix) with ESMTP id 49522180002 for ; Thu, 14 Apr 2022 18:06:50 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id d15-20020a17090a3b0f00b001cd5528627eso2281781pjc.1 for ; Thu, 14 Apr 2022 11:06:50 -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=qt7LAMoWwJRlSLWPA4drMIMlweaGvvHJUEKLpTNLGFs=; b=K1pmTkZ7xMyHq/WaSOdT2PLMHoeGIaNe+XBrANKHrYp+GD6iuKvTItnoZIPJqTNtjk IN2MykryqWRYxEQQubHLB+zdi279s3Lhp5U/S59DLyST75j7pqjf0x/F9CIoQDPeWeT6 fKbkTm1T30AiirtMf/m8qvgoD6sfYq7Re4qoNzA20C26GLwn5ZUSsf/c7hgDQyaFjabL vfe5jGePTliDMqj/fNN0WMQcRIuFV2lmQmkkTW9GZyqYAhV151QyWVNlnbUPhEKFGgT9 02nuy2xkrmYLNoz3ZfXlrpYBB8fc8Ere3f2jqNPWq87VkdeEpVGVQaXvmAuLnDRpZt5B 0oFw== 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=qt7LAMoWwJRlSLWPA4drMIMlweaGvvHJUEKLpTNLGFs=; b=YvSJ9lXnszzfT2Dd01kkCu1o2MVdxNE7pH65w6mTeN4GFn6u1xkjazbWP5o8POQxDc 9GWrFtw3yiu/Sfd77IvpaGPf4/9k+jyVk+Cp4d6oRGnT+2q3EJD0NPlm99rpbHQPWggR L80LR/hiCPkXl92ItUxsTLssle6Xh3RQhePRXUovF1kFNhWRz131hX2Tu9DS+4SGc6r0 sn+tPf9BLPNamybvU8TYfBZfMvqR54YFrIup/Zl2OtyAExgp/mnXYjUXYVcaMFJJj5cd V9St2rTtkWGivWqEGD6mF9znYeVpJYHWRjIiJJ+9UmTemH8I8EPpzC3EXdQLUqLEXrch o4Gw== X-Gm-Message-State: AOAM530s1QiJLVUFx7v7pmq+x2gSYSl31eH+AiBk+u3gEIEiFDjeooxi x8BCaE3uvsN5FYpHtzraPdsyxhZRz14p X-Google-Smtp-Source: ABdhPJxJAS5XPOE3eYXnTEWLcfkTBvyytCQdcnqYmFp2ueTRwd7MLrLX7mzR5AG7HIn03bCKnI6EeAj+W/vf X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:ab04:b0:156:1517:411a with SMTP id ik4-20020a170902ab0400b001561517411amr47503720plb.128.1649959609273; Thu, 14 Apr 2022 11:06:49 -0700 (PDT) Date: Thu, 14 Apr 2022 11:06:09 -0700 In-Reply-To: <20220414180612.3844426-1-zokeefe@google.com> Message-Id: <20220414180612.3844426-10-zokeefe@google.com> Mime-Version: 1.0 References: <20220414180612.3844426-1-zokeefe@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v2 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" Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=K1pmTkZ7; spf=pass (imf24.hostedemail.com: domain of 3uWJYYgcKCPg4tpjjkjlttlqj.htrqnsz2-rrp0fhp.twl@flex--zokeefe.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3uWJYYgcKCPg4tpjjkjlttlqj.htrqnsz2-rrp0fhp.twl@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: oadoz1p5ttrgfyuzkurskzp545nae8pw X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 49522180002 X-HE-Tag: 1649959610-246864 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; }