From patchwork Sat Dec 24 08:20:35 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: 13081312 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 6E60CC4167B for ; Sat, 24 Dec 2022 08:20:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDE4A94000C; Sat, 24 Dec 2022 03:20:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B8E6494000A; Sat, 24 Dec 2022 03:20:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5FFF94000C; Sat, 24 Dec 2022 03:20:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9797694000A for ; Sat, 24 Dec 2022 03:20:42 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6403B160996 for ; Sat, 24 Dec 2022 08:20:42 +0000 (UTC) X-FDA: 80276503524.13.F0772C6 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf02.hostedemail.com (Postfix) with ESMTP id B886580008 for ; Sat, 24 Dec 2022 08:20:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YIdgdTDl; spf=pass (imf02.hostedemail.com: domain of 3V7amYwcKCII5uqkklkmuumrk.iusrot03-ssq1giq.uxm@flex--zokeefe.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3V7amYwcKCII5uqkklkmuumrk.iusrot03-ssq1giq.uxm@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671870040; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qHBgmM5FyY8tFESb+UZtZ7YHBNCfgMkVXvmSjVkn95c=; b=4iQUblXAzuX9l+6sSWzUckGD+3nEnnLLCez2PZ7XVx+7LvqxbfPXzurtvSrZzjSiDwNFCP 4ke/zdU74SdVb8fTebwiwNl9HChQx4d/ocSoR88GxlO6M4DFPRSuwz3PIK+yVYqcuBlcmC mic7FBgEYGzNURYoAVmoGcIdUr54p/w= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YIdgdTDl; spf=pass (imf02.hostedemail.com: domain of 3V7amYwcKCII5uqkklkmuumrk.iusrot03-ssq1giq.uxm@flex--zokeefe.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3V7amYwcKCII5uqkklkmuumrk.iusrot03-ssq1giq.uxm@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671870040; a=rsa-sha256; cv=none; b=v5ZB1oXWwqIsaDRJmqy4JmrZjfGOCYYuCnvGgJmmI+joQQSAJ+08xaIe6RccCEeLY4S5We L5JKHLTJlsSNNEbiC5UMmJIxQs1XQBTxbZ5NokgyQxP/He8++7vECNLOtFveE9+fDR6ufO vQ/SD7RhntH3f7A9pbQ5uBdwppvWHdU= Received: by mail-pl1-f201.google.com with SMTP id l14-20020a170902f68e00b001926bc70048so316727plg.2 for ; Sat, 24 Dec 2022 00:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qHBgmM5FyY8tFESb+UZtZ7YHBNCfgMkVXvmSjVkn95c=; b=YIdgdTDlm/0rnNXmV/Ouxem7vSavubkjE/mlXtu3l2VNJp+VcHRwcxAqLRlRCht33T RjLRwnMH+83r29SKKJIBeQCmhsdRiiPnHm5RybHePQWkJtrnUBA8wvZoTReit57ZSQgj rb79t5GaIQFUYM+TelnB/YDfk3efw2LoXwE83oTT7NsNN0yVZUilRddaPER0eHid1zOn rFXxu33AQ1X9TIKISEarvlDOHXaIVzVHkuQDAvEdPao9/mUtIRnGOziez9pbYJtslSrk 9oofFPc8G704Z1XNJl+3ESz0Xb773tj4avam3C858QsEl+9wi5oCzl9RAxGV4CrpOS/U Na7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qHBgmM5FyY8tFESb+UZtZ7YHBNCfgMkVXvmSjVkn95c=; b=epxtoVmfFDS5JyuDyg9PB4zEo+AGOiClTmajMgqVZbs/S0oue/zXZjUXBZeLwSJRJi PANRMVnboa0vZjgr2P6qh/ymW+aLiIPZG9CXpv1B1hpwbBgv5O+A4MNm07oGA6dhXPr6 Mh3z69y2p5Dpb5i32uXr+9ccBlOEZCL/2xR5euyFubxwFM54J4R0aNDsDiUkkrUMgAI+ tjXWQ4UR0SMlAWrcBK/wjGc5xw/d4dFzixjTKTXfG4ZZIgTCEOodgMJHB5jEVVWfDQAI Vij9Fbnj8lzAjJGYUB2dIsi//UzZsjFNxfz/9Jx4Zr2MhvZAWFnzwUPOGv/eLp2ddlxE yJIg== X-Gm-Message-State: AFqh2koycrae1PO8TlMgxh8w/Ai+RajwEZ0hGQGmS9yiqyO+4TpBZJ56 Bi5se6I8hEBMRI+FAzpp9UlH1SL5h637hyDBR9EKS6F1j02l5KVEkCr//pk0PfdqLp5oPV4zqLV PaAtaRoQLOpCsuiBrskj65yLajKChvplaSO3QtJC/FJIsW03l0XSFfR7us0I= X-Google-Smtp-Source: AMrXdXtpnA9oa+kcg8UCtzsH2+zbPi8cE8h5FFqA3g8bAXygXEp5KA+R6LlQvnatJIrsuUCVCjwgqNmjUsVJ X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:90a:f018:b0:21a:150d:fe63 with SMTP id bt24-20020a17090af01800b0021a150dfe63mr1313517pjb.73.1671870039401; Sat, 24 Dec 2022 00:20:39 -0800 (PST) Date: Sat, 24 Dec 2022 00:20:35 -0800 In-Reply-To: <20221224082035.3197140-1-zokeefe@google.com> Mime-Version: 1.0 References: <20221224082035.3197140-1-zokeefe@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221224082035.3197140-2-zokeefe@google.com> Subject: [PATCH v3 2/2] mm/shmem: restore SHMEM_HUGE_DENY precedence over MADV_COLLAPSE From: "Zach O'Keefe" To: linux-mm@kvack.org Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , Yang Shi , "Zach O'Keefe" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B886580008 X-Stat-Signature: hhmehhn8tts9xwizjqgwgud1botctd5a X-Rspam-User: X-HE-Tag: 1671870040-516118 X-HE-Meta: U2FsdGVkX18fy4FJOYE9Wv+C8jn0ozZLXPwr2RN0fAX9CoLuEG5DquVu4MbHMN+eAa8w5QRDl61Sw752gGADSHaC+364otLjwnFPE39G1T5VNC1lSn95pOb8RYjrXryFG4bmi59L/jfmPz9D/EpYFcAe7/wQrfeffNJtjx58dbyfI/0SnsiFdsaG8PIkh0dkj9rhbqyDHEvgBLE8JBZjkoTvK433QtJ7AKancLY9im+yMgsFlFuQjBAxYyT5SYJQOvBdMYwVEqerMowxhL9fHAgmDmQRje//EUfML5wGawLmwt1uR5q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oCDoC0PSYr+2b+86B 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: SHMEM_HUGE_DENY is for emergency use by the admin, to disable allocation of shmem huge pages if, for example, a dangerous bug is found in their usage: see "deny" in Documentation/mm/transhuge.rst. An app using madvise(,,MADV_COLLAPSE) should not be allowed to override it: restore its precedence over shmem_huge_force. Restore SHMEM_HUGE_DENY precedence over MADV_COLLAPSE. Fixes: 7c6c6cc4d3a2 ("mm/shmem: add flag to enforce shmem THP in hugepage_vma_check()") Suggested-by: Hugh Dickins Signed-off-by: Zach O'Keefe Cc: Yang Shi Cc: stable@vger.kernel.org --- v2->v3: Add 'Cc: stable@vger.kernel.org' as per stable-kernel-rules. v1->v2: Update changelog, and add note explaining rationale for backporting (Andrew Morton). Request to backport this to 6.1.X stable. We'd like SHMEM_HUGE_DENY to take precedence over MADV_COLLAPSE. If we make this change later, it will be a userspace API change. As such, 6.1 cannot be allowed to continue as-is, and we should fix up the code there. --- mm/shmem.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index c301487be5fb..0005ab2c29af 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -478,12 +478,10 @@ bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode, if (vma && ((vma->vm_flags & VM_NOHUGEPAGE) || test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))) return false; - if (shmem_huge_force) - return true; - if (shmem_huge == SHMEM_HUGE_FORCE) - return true; if (shmem_huge == SHMEM_HUGE_DENY) return false; + if (shmem_huge_force || shmem_huge == SHMEM_HUGE_FORCE) + return true; switch (SHMEM_SB(inode->i_sb)->huge) { case SHMEM_HUGE_ALWAYS: