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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF65BECAAD2 for ; Thu, 1 Sep 2022 19:49:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F60C80049; Thu, 1 Sep 2022 15:49:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A5338000D; Thu, 1 Sep 2022 15:49:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36CF780049; Thu, 1 Sep 2022 15:49:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 24D4A8000D for ; Thu, 1 Sep 2022 15:49:39 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D1ABA14061E for ; Thu, 1 Sep 2022 19:49:38 +0000 (UTC) X-FDA: 79864556436.08.4D99973 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf29.hostedemail.com (Postfix) with ESMTP id C4F1B120089 for ; Thu, 1 Sep 2022 19:49:37 +0000 (UTC) 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 AD2FCB82933; Thu, 1 Sep 2022 19:49:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26B39C433D6; Thu, 1 Sep 2022 19:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1662061774; bh=dg+ppRmkii5agmo19wFs2/RQZz+ZaDfIvg57CDdj8ok=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GLJWpoiIXh0uhBMuWBX6kmylUDxLAOU3NwISOFteCLQqVRHeChODXilCN9pJ9w5al t/EY5KiXLLvkuClEHs1FsGmXKt+EpIbeJadCwnV1i+bMgc0gwhapul4qNu3ADoeQEB xjmfN3OQG/n74smWZociDjoWUOUJJRAFsfbIwRHI= Date: Thu, 1 Sep 2022 12:49:33 -0700 From: Andrew Morton To: Baolin Wang Cc: mike.kravetz@oracle.com, songmuchun@bytedance.com, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] mm/hugetlb: fix races when looking up a CONT-PTE/PMD size hugetlb page Message-Id: <20220901124933.57ccd5f7c8dd8611ab667c3c@linux-foundation.org> In-Reply-To: <635f43bdd85ac2615a58405da82b4d33c6e5eb05.1662017562.git.baolin.wang@linux.alibaba.com> References: <635f43bdd85ac2615a58405da82b4d33c6e5eb05.1662017562.git.baolin.wang@linux.alibaba.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662061777; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ziLk3ZaFdT1qP08CF6WTOtfxpg/I0NOJUa+MQPPQUT0=; b=Frv2yabsFPmkWA2l1GV4+E8DAey+Nw82i+vqcGWpTyZbWVp8l+ChDdne2NJSTQR+IFdIS6 NInGp7RK2UONCjx8I2cXbnor0Q3noLYS2NYyb5mOFy3mmE/hwU7LifwSrlS1XMVKW4DqU3 uqtBGuywteA/XhyMz4wNh7bfEg/xAx8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=GLJWpoiI; spf=pass (imf29.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662061777; a=rsa-sha256; cv=none; b=3RuApyVJDnkLnePM4c4sdn1BQj+LewHbqWWucsLujINIX4aTBWte1ISIjOqQh3S9Py6T77 Brgj6BvBKDudFZQRIh1+cVAejZRS8WhPtKbvnR2+4tqSJF9rsPAkTLFMQYpmuZyGShvB1Q KvH9dbjNixw4n9rVEXye7A1fUoXL55w= Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=GLJWpoiI; spf=pass (imf29.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-Stat-Signature: onduoheirpddozcbkx3opg5eb1auisch X-Rspamd-Queue-Id: C4F1B120089 X-Rspamd-Server: rspam05 X-HE-Tag: 1662061777-559822 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: On Thu, 1 Sep 2022 18:41:31 +0800 Baolin Wang wrote: > On some architectures (like ARM64), it can support CONT-PTE/PMD size > hugetlb, which means it can support not only PMD/PUD size hugetlb > (2M and 1G), but also CONT-PTE/PMD size(64K and 32M) if a 4K page size > specified. > > So when looking up a CONT-PTE size hugetlb page by follow_page(), it > will use pte_offset_map_lock() to get the pte entry lock for the CONT-PTE > size hugetlb in follow_page_pte(). However this pte entry lock is incorrect > for the CONT-PTE size hugetlb, since we should use huge_pte_lock() to > get the correct lock, which is mm->page_table_lock. > > That means the pte entry of the CONT-PTE size hugetlb under current > pte lock is unstable in follow_page_pte(), we can continue to migrate > or poison the pte entry of the CONT-PTE size hugetlb, which can cause > some potential race issues, even though they are under the 'pte lock'. > > For example, suppose thread A is trying to look up a CONT-PTE size > hugetlb page by move_pages() syscall under the lock, however antoher > thread B can migrate the CONT-PTE hugetlb page at the same time, which > will cause thread A to get an incorrect page, if thread A also wants to > do page migration, then data inconsistency error occurs. > > Moreover we have the same issue for CONT-PMD size hugetlb in > follow_huge_pmd(). > > To fix above issues, rename the follow_huge_pmd() as follow_huge_pmd_pte() > to handle PMD and PTE level size hugetlb, which uses huge_pte_lock() to > get the correct pte entry lock to make the pte entry stable. > > Cc: Are we able to think of a Fixes: for this? > Mike, please fold this patch into your series. Thanks. As this is cc:stable I'll be looking to get this into mainline during this -rc cycle, so it shouldn't be part of a for-next-rc patch series.