Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1694498rda; Mon, 23 Oct 2023 23:39:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3XZhfyZPaxX2aJdB1BSKn8tOUIW/7/TEMjx9PQrYp0E5hsT1ai8gUxtuTgn2+wqYWfOaw X-Received: by 2002:aca:1004:0:b0:3a9:e8e2:57a7 with SMTP id 4-20020aca1004000000b003a9e8e257a7mr10315537oiq.53.1698129546380; Mon, 23 Oct 2023 23:39:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698129546; cv=none; d=google.com; s=arc-20160816; b=0+qroe01wJuDDPZoLWrfBh9v6Cl4uZ1yrBGLkrGW/TUn4SQBfhiwHyt0HFaKGYoq2h nZnQZyWiz1YOXWNpyoptEf8oD5fLv7qsU1QmXzh6Ykq1TGnvc+FluNDdHCYydlPFA6Pj /aBB2I0/PzskU/CdpMGukpGQ7idSkfm9zcKVlty3waT4TbkK/GfQp8VNxyEXhuLv/LR+ vH5uqLvwyambHL8j5mYf4SYgUKbqzgqvDUDZtD9vpb41buP/DZbToKXVzhjhlGcNXCTq F46FBs+OAqDUy0ygeUuPTCo+mL5SGXqIXl/5rmsfa4/QQv+5vKwGGcPg5M4c8ZpK9EDS mY5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=UXi6v2LbKa86tbarZSXs3eTomoCCL5BUs5KfudH0fXM=; fh=/G2/Gfam8ROXh09zjifx9+mWjPEMbpY4MQEcoHKAlHY=; b=Clu74/3z7TW6QbyjECgthWBwff5+B+QfmPYmQUExxG9MY0L5VMNZwGpGvnLqYNPeYt mJgusVz2/tAOBBk6XUDFmyKbPJonzbOTnV4No0gXgEJaV5BauG7RmY822kcs2X5jAxpR thMYuMVnxwpqX1tbt0yW4pPUU0XsHBLZWL+0i21UbUUOseGBFs/3resiROO4yARMiNkU F554gpghma4KWkypnTBmf8d9E4RR3bT1CyHL1GFSaV9RhjX465uFEhA6AAEkfOx5LvG2 t98L/47AK10M3hETiPlI8SlwcifS/kLP1JGWOa8XGxFGgDR5/XhJScYh0w4bHx1fY2Pd 7sog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="pplaE/v1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id b19-20020a656693000000b00584a4a5be67si7722310pgw.520.2023.10.23.23.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 23:39:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="pplaE/v1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 093DE80ADECC; Mon, 23 Oct 2023 23:39:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232621AbjJXGir (ORCPT + 99 others); Tue, 24 Oct 2023 02:38:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232335AbjJXGiq (ORCPT ); Tue, 24 Oct 2023 02:38:46 -0400 Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 291BCF9 for ; Mon, 23 Oct 2023 23:38:44 -0700 (PDT) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-5a7b91faf40so41280417b3.1 for ; Mon, 23 Oct 2023 23:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698129523; x=1698734323; darn=vger.kernel.org; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=UXi6v2LbKa86tbarZSXs3eTomoCCL5BUs5KfudH0fXM=; b=pplaE/v1KzadrnvkymvI/c+Jj3XiCYAkY8KiIDf7y3Ik/Jn/plJ8LE4Ie/BGdpYLXJ yHeWyzITGtHIwK9IzfI/sBTzaSoSie5x0Cwk9zc7BeGQwpOeB0TWs+4D7vJ0mWsoWjCS DyoucrHLt+Nbz9nsYv+gZkO+ne6c4cKeIsUaLjnUegQhEh2aTLMT7Ti5tSqUDo+d/Ouy RYwBKLTD3yKOl9nNwrYMrVSqiGVPI/oiDqaft0hu84rmxCgkXXhZg76Q3BdBYLtUvcPr I2AQwB6B++uidbSwlMObz7A1/jV98KQBHFsKfFiJPkQHGBNpmX7U2O3+Nom4mLmO44em pGRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698129523; x=1698734323; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UXi6v2LbKa86tbarZSXs3eTomoCCL5BUs5KfudH0fXM=; b=VH5esBdz7fTrqWtwctA/pmkd7Gr5pN+Z/KHrTTBb4dDg472MBCp549e/OXCAuaUQ8G Iy79eWe2UfAVysT3g8VOn0bE/D9a+7Y+qxsks+gfAcAjAjW0yU2jn5pFtBR8EZdiaKXN YcEbRrGuyBUrrbXiic3Kyzcqk2WsUvp1md0k7bRKLm5kls+m6549MiCvJlty+6MrUbAH VCTExDfzw7oafBuSbdmPIlr9l+s8+ZDSgi/5FEqimwEOlwOFkqip2N9IoQK2z8HUkVU9 2qd0W3px4IE1jvzz/W+dOjkVap7XgAl93nEA3Z6jy+RNeaDmm/MIQsYe/C1a2g5vVyqQ mw6Q== X-Gm-Message-State: AOJu0YwN6mNjBBcjtYkeUoWD74itHI5wZpLcCc1LwKLleQTO7njvQjFM aoBAjz8Jo3y+2LwpbDKQKsaddYnYM9RrFIE3v3SEXA== X-Received: by 2002:a0d:d48a:0:b0:5a7:b682:7929 with SMTP id w132-20020a0dd48a000000b005a7b6827929mr10904861ywd.17.1698129523237; Mon, 23 Oct 2023 23:38:43 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id w74-20020a81494d000000b005a206896d62sm3792514ywa.111.2023.10.23.23.38.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 23:38:42 -0700 (PDT) Date: Mon, 23 Oct 2023 23:38:41 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Yin Fengwei , Matthew Wilcox , Lorenzo Stoakes , Stefan Roesch , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm: mlock: avoid folio_within_range() on KSM pages Message-ID: <23852f6a-5bfa-1ffd-30db-30c5560ad426@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 23 Oct 2023 23:39:04 -0700 (PDT) Since mm-hotfixes-stable commit dc68badcede4 ("mm: mlock: update mlock_pte_range to handle large folio") I've just occasionally seen VM_WARN_ON_FOLIO(folio_test_ksm) warnings from folio_within_range(), in a splurge after testing with KSM hyperactive. folio_referenced_one()'s use of folio_within_vma() is safe because it checks folio_test_large() first; but allow_mlock_munlock() needs to do the same to avoid those warnings (or check !folio_test_ksm() itself? or move either check into folio_within_range()? hard to tell without more examples of its use). Fixes: dc68badcede4 ("mm: mlock: update mlock_pte_range to handle large folio") Signed-off-by: Hugh Dickins --- mm/mlock.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/mlock.c b/mm/mlock.c index aa44456200e3..086546ac5766 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -346,6 +346,10 @@ static inline bool allow_mlock_munlock(struct folio *folio, if (!(vma->vm_flags & VM_LOCKED)) return true; + /* folio_within_range() cannot take KSM, but any small folio is OK */ + if (!folio_test_large(folio)) + return true; + /* folio not in range [start, end), skip mlock */ if (!folio_within_range(folio, vma, start, end)) return false; -- 2.35.3