From patchwork Tue Oct 24 06:38:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13433962 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 13483C07545 for ; Tue, 24 Oct 2023 06:38:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F6576B017B; Tue, 24 Oct 2023 02:38:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A6AE6B017C; Tue, 24 Oct 2023 02:38:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36DDB6B017D; Tue, 24 Oct 2023 02:38:46 -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 246846B017B for ; Tue, 24 Oct 2023 02:38:46 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E3678140DFE for ; Tue, 24 Oct 2023 06:38:45 +0000 (UTC) X-FDA: 81379401810.13.45B1CA0 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) by imf02.hostedemail.com (Postfix) with ESMTP id 4502980003 for ; Tue, 24 Oct 2023 06:38:44 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Af3Tot62; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.128.169 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698129524; a=rsa-sha256; cv=none; b=Vy+Tf1oRCmFWuk5CYJun5D1G/GH6DZ38dvOxp8slSJXpYKw+EckY/3FmRPH88bEuqlIr9F /qzKWfo/UWhflgfyYknLkj9DS4aCbltl6Eb1jdRQkeSvudu8zie9Fmr7ZYk4axv64B9thO QCR9b8ZAU0m0OUZQ7OwnYLiuShlYa1M= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Af3Tot62; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of hughd@google.com designates 209.85.128.169 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698129524; 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: references:dkim-signature; bh=UXi6v2LbKa86tbarZSXs3eTomoCCL5BUs5KfudH0fXM=; b=pCypYXjSvSe2RglqqgaBmjfl6fW22I8MaaJ7A7v9nQQSvKoGTXOywThHZTfHbKTwsnRF4U HWtvTVluXemhQkOl44FtryQz822zuESTcnnlg8uDJIlE4BGzcPcXgkGE+TFa+SC7TxIFlg T/axRi5lAIcpELpUdZ5LcPT3pOQfRA4= Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-5a7b91faf40so41280427b3.1 for ; Mon, 23 Oct 2023 23:38:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698129523; x=1698734323; darn=kvack.org; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=UXi6v2LbKa86tbarZSXs3eTomoCCL5BUs5KfudH0fXM=; b=Af3Tot62nw7Bu59kekxM7lL4iCU83utA1FaynoYR0AcnmPQ46LRRQ9kzDP9tEcAbSb a6Nc/e2EFWHg5DwII2vhbt6ZvmvWlmyWnWv08eOmaIbYbZBGM80LPu+8NphiT3eC8VRv wRV1vW9r6j/ynVc+BiFqN9ct28+XW0JF1M+l+iaXDvIB3R2lItdyAxadRzUqGdGl5kpe OfksRj2NH5e82eCUcVTQHeV2Vei22HPVOhOlizg1iCe8e6TqkftcWq7D6GVBr9JPSEtL 7seWylZm/YYgT6cGeJS3CRQski8LAj9uRsizYhYQshQvvy0JLtXIUF4q7ot0T9mXerZO dWYA== 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=jWzLso8xvUHyNUKnx79UaZzXrXTqgJifrXOO0Gl510sTSOfgzX+ytBm1l6s60tCjED gmwfgn8/vjy9+0xAQhaUohDnqqxqnPXjkcDoXLUZQnVCR5OOhSQQZm96Wm6ZyPvHJkgC 5z9B4FtewGYLSTUq5nVO1hVR2eHC1ukp74NsPOD/BykobRTPEIAAfushYU9Sp3bcWL7r 3dPHTjiHg8bZCAiafPh+/DQKjQ/P0q0ofRJ8Vj6PwR5W22kuk2me8y5G/QQ8R1N+m79D Cc9Mx1lH6Ziqgu/WX20er5s+3Ez0jiP5Qu/6V77CyzNoJZIpLXbQWfVCEIv4zxEh3ZZU eoqw== X-Gm-Message-State: AOJu0Yxk6qrqYYiDU39YbM3gl7EJwOXQWeRUQTVOx0p/R78BP1F9QAlm AQbADAi5H6Arx80EupcTe5U0Rw== X-Google-Smtp-Source: AGHT+IG0IW6r6OKt3t8wA3MRK4sQptJZdOLg5QTv5pLEidJzquHDgYh4NXUKWmkVGawKWVlb8hrCfQ== 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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4502980003 X-Stat-Signature: 6xhmjk386tfogp6e7bi6iwtprhn9bzqz X-HE-Tag: 1698129524-622539 X-HE-Meta: U2FsdGVkX1/g2XRr6JcOfxMuIDkxNEq6sYTKWOlhvgr8LElaZhyV1PQ1FuX9Ew3kB5ZtfyttdS30bAbQghDpzkusVMGm7BNZLfVsU3BmvrfM6VdhQ7VC53Q1Eqkojj2Rwr5au9kNdYXNGn73TDXOTKPhQAsHXDF/RS45i/L7hzpbS2q2nA7de7xuKE4bdrbs6I7u6WnmceKV0dz6K61S/maiWpnvv8RDU73csTXIsQLlkE0mleQc8NZYivPRZBjD4qxfsIWiWjcm2ULzQV6CU8j6D3N261OLX+5s1BCY1SbhTKMrYn6s02S2rRFs3UChGcNfdPn2CghleojvE5oOt85OO7gLxLXJZULhY4Uh1rhEI+McEVIZCiojQeSROg+6iG216C5iu9c9VRUwJAD74ZHKt9ej5FNZK2UCVlEZ1/WM9hwnE3tCQVcmF9YB7Wm2QpfLid5JAD14SW0lQNNW2U0a0OxQ3dMGVsW4Z4ed5iqFDe4CSy2k0WFyE0ig/srUqGhAGlOJ5n2OoIQcc4LuHt4yo4N+heLzD7ve/3zP3M0vxw2pp92Nh0h6PxW5Bh6OG4P9WGKF7x0XHsLIE/iRrsv6TL+AznA3AzjdNjxKw186j+HB6d2u9VLpi7p5zg6rLPCsAJY9FasrVPeX3gYvLVATY3h+deG/IhggK1edhedcKqUiot5JNyZS9FvlviaPZUkW6oLbHmkGwXH+vORN2Z1R3GwProwtKbKc74xLLEzZ2JVvdGY/wicAVMZaJvUqBzpAfd1wHJK8amfyOP5Ta7D7kGzCqgTd7UUWz05pBSEF4vXbqjgaqQt+JLBSSDn57RbyoEAkYf1HCsWnG4wW8d/oji72n+Ept2e/zIIHHLno6Uu0R3J8m3y0/ZsgwKLe8UnSXg7PDjxuFC90PvBAtlaKgQqZbU6AgI5J6KMOIJ7neIalXalrFU53aUKXufLhuCXEc0l5f+D5hX6H1I6 R5R2i+YL nR9T9gXYUOHqMdCZ2SbPYweJns5ETgK38mpzZt3QdW7AUzIkP51voRBXPLv14A2F9HieB1vTJ6ZfttY476Ik0x2yy5J/cu15jpyEejdo+gJRh6yG5OMvPJGodptd0Ac8r0Dq5s3sGJIPh7X4NwAmzq5oocCstvcNlLteXquzqfUhUBkVtDuqfPb3nQGwIGDrWQUbn/qO/vy4IY6ae/FZBCDBHw4+dJTkE8EIP2+csOKzmxOMJ/Dd0DHI7iwRENwION07sCr3iXFPs48wzX9EZcdDEnrfMFdHZ/EKr3PBlL57vLQ3fwB5PGM1VT0xW1ldDF2uikF2wXy2FKpAcohHCj9Cxy8TRvfLKPVb7vFEk7HjGQADf/NnKehrP3Lxn3tABcvijP5IiVua3I4TmkJ9r6GoW2sQ89TqKEBFbVmp6X1p9QlvSz8foVpMeag== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000016, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Reviewed-by: Yin Fengwei --- 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;