From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4131C636D4 for ; Mon, 13 Feb 2023 15:03:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbjBMPDI (ORCPT ); Mon, 13 Feb 2023 10:03:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231335AbjBMPDE (ORCPT ); Mon, 13 Feb 2023 10:03:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6D6C1E1E6 for ; Mon, 13 Feb 2023 07:02:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 34572B81258 for ; Mon, 13 Feb 2023 14:57:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C488C433D2; Mon, 13 Feb 2023 14:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1676300259; bh=QdJbVDLORVGTqvqBjIdlpc60dR5Ps1+GqguQjDvgweA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QaMs0LsTgWmDIfvtYUo6jslOlnAyaS2mRzVhAP4AKtFZ86QWSvmnssDazJki3U7+3 WkYaIPaICSEPDwo6VnjvH824odKiQytwxGQrDzW3Ex4WYrSEN7Vr3z299WW0CdDu/S xPaABr6c5kWCLkkRd8/3jWXxaJJx2yyR9+JWIv1A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mike Kravetz , Peter Xu , David Hildenbrand , James Houghton , Matthew Wilcox , Michal Hocko , Muchun Song , Naoya Horiguchi , "Vishal Moola (Oracle)" , Yang Shi , Andrew Morton , Sasha Levin Subject: [PATCH 5.15 05/67] migrate: hugetlb: check for hugetlb shared PMD in node migration Date: Mon, 13 Feb 2023 15:48:46 +0100 Message-Id: <20230213144732.575198575@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213144732.336342050@linuxfoundation.org> References: <20230213144732.336342050@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mike Kravetz [ Upstream commit 73bdf65ea74857d7fb2ec3067a3cec0e261b1462 ] migrate_pages/mempolicy semantics state that CAP_SYS_NICE is required to move pages shared with another process to a different node. page_mapcount > 1 is being used to determine if a hugetlb page is shared. However, a hugetlb page will have a mapcount of 1 if mapped by multiple processes via a shared PMD. As a result, hugetlb pages shared by multiple processes and mapped with a shared PMD can be moved by a process without CAP_SYS_NICE. To fix, check for a shared PMD if mapcount is 1. If a shared PMD is found consider the page shared. Link: https://lkml.kernel.org/r/20230126222721.222195-3-mike.kravetz@oracle.com Fixes: e2d8cf405525 ("migrate: add hugepage migration code to migrate_pages()") Signed-off-by: Mike Kravetz Acked-by: Peter Xu Acked-by: David Hildenbrand Cc: James Houghton Cc: Matthew Wilcox Cc: Michal Hocko Cc: Muchun Song Cc: Naoya Horiguchi Cc: Vishal Moola (Oracle) Cc: Yang Shi Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/mempolicy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 8687781b41c96..818753635e427 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -603,7 +603,8 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned long hmask, /* With MPOL_MF_MOVE, we migrate only unshared hugepage. */ if (flags & (MPOL_MF_MOVE_ALL) || - (flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) { + (flags & MPOL_MF_MOVE && page_mapcount(page) == 1 && + !hugetlb_pmd_shared(pte))) { if (isolate_hugetlb(page, qp->pagelist) && (flags & MPOL_MF_STRICT)) /* -- 2.39.0