Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1653372rwj; Sat, 24 Dec 2022 00:53:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXt05bVYIyKddJtKV15LlFO/knp9nD4cPgoc5eaSXuISRgQzu1LYmTYukEibw2bZ8McI9wGm X-Received: by 2002:a17:902:b7cc:b0:191:a19:aa80 with SMTP id v12-20020a170902b7cc00b001910a19aa80mr14458804plz.52.1671872015020; Sat, 24 Dec 2022 00:53:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671872015; cv=none; d=google.com; s=arc-20160816; b=LVkjTw5hiUroGZsva7iy9/VhieUl0N7W2lG9uy6Znw7qd3/RdhYPIH1NRV6h5dqaZn ot1Lf/L6Y9b5L1DrGDRYfsasVfnbzzHkQeyF8vw5QVPQXrTyUQVb8ptkd/Ps2ynDg0x5 /OR0G0FQXWdsQVSD3dHNvh6THiBjX2zSXI1BKOxcIJtqsafP5uaIO74jIGimeZ1V4snK w0uJxZraTJet19nHsaj0CnsreGmf9iuQish82zEAN/K58cXTnxsFH5UviXGRYpnY3A5o QM0NyW98cJh5Cg6V6/ArTmRvE+R0mProgCR90siSsDzBkkF5at/Z6G8B5kKeQ3/e/63n hQCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=qHBgmM5FyY8tFESb+UZtZ7YHBNCfgMkVXvmSjVkn95c=; b=VyeVHWr9AZHTpTX4sczG8PbPa2nw6jVDD3scw0hTNigt79nq1q9spmH+pCTt2cbbBQ UJkmcR5N6cEbO0a2Q6QFCFFEGpckqPNCBOQJDxi2VMPLEMI+A5tNo9f9/51WfmT3HFse Ee8uxVP5fBTnJXfHwlfd4MGtfxIjAx/Q5bR3kcef/b0brkJoIf+iqBqqqn3Jc7paTyJZ kW6HqIT0jDyQtgfEEVpS0FVWHOtTTNxQNTIrsXIRRpK+ptfHMMKSKw20eNhFAZcaTYeE RYKnbENBEMzJHVEv6Eo81u49NMT89pzauUs9UIFqi5B1pxn5UoqSJrfdZ4Br04XbWVEd aThw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YIdgdTDl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q2-20020a170902edc200b0018c166e2304si5460179plk.299.2022.12.24.00.53.26; Sat, 24 Dec 2022 00:53:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YIdgdTDl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230423AbiLXIUp (ORCPT + 64 others); Sat, 24 Dec 2022 03:20:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbiLXIUl (ORCPT ); Sat, 24 Dec 2022 03:20:41 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13A32BC31 for ; Sat, 24 Dec 2022 00:20:40 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id x33-20020a056a0018a100b00577808a75c9so3616285pfh.13 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=LgLOrDcLkSppSqOdr7+pgeuWSwjJxcnu7PBWud5qU0aUS4J3A7Gd+FV6OeFEb4O/Fu Zio//6Ud97Jn0KFSx7VIdSHysBNwaNftdknwf1QipwLlRBd6Lc6SH1/VquhblFJWJcWS qicP8apOaZO1M9Aey4g+Dbg3dEhD/vdLrAbINhEb8oFOjMTp0aFan4IchKciaGpki+wY AGkbDWXqHWNDRKHbwncOq7JHGBWB9+a1wgVlkmLP4AJ4xK8lxE2zXpyGmb95yKlbjUjv hbd/+3rIKI9d6NNARefKm3d1pw6TPA+GvRHTalIGix63jK3Zf8UBOXEIZ6sQvezmSbMI RpPg== X-Gm-Message-State: AFqh2koJfN5coKfsq4P6YZJszl6KgJ6MD56AtDwa9d/8o8oTbgKOhYf4 98YrsDiltAWHWLj6cvZlbyZxQWcszZ51 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" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: -- 2.39.0.314.g84b9a713c41-goog