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 C13FEC38145 for ; Fri, 2 Sep 2022 01:29:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E10B80093; Thu, 1 Sep 2022 21:29:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 090798008D; Thu, 1 Sep 2022 21:29:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9B4A80093; Thu, 1 Sep 2022 21:29:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DB8218008D for ; Thu, 1 Sep 2022 21:29:37 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BC08740CBB for ; Fri, 2 Sep 2022 01:29:37 +0000 (UTC) X-FDA: 79865413194.28.4BA5321 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by imf07.hostedemail.com (Postfix) with ESMTP id 1061540045 for ; Fri, 2 Sep 2022 01:29:35 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VO3hyue_1662082171; Received: from 30.97.48.41(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VO3hyue_1662082171) by smtp.aliyun-inc.com; Fri, 02 Sep 2022 09:29:32 +0800 Message-ID: <46ab4086-8a7f-7c20-c326-72a863b77fbb@linux.alibaba.com> Date: Fri, 2 Sep 2022 09:29:44 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH v3] mm/hugetlb: fix races when looking up a CONT-PTE/PMD size hugetlb page To: Mike Kravetz , akpm@linux-foundation.org Cc: songmuchun@bytedance.com, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <635f43bdd85ac2615a58405da82b4d33c6e5eb05.1662017562.git.baolin.wang@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662082177; a=rsa-sha256; cv=none; b=IccXiTHy40hezFZGjnzr5V2W7uGH27EjxYc6g7fPkFVhf8fhtx/53fiHwxunfxYXfkXPf5 RSw30E0RPOs3YXl5CxdeIqDvxcqq2OYDu7TxPGI5qK94vT77jyOjSULwVOop7nihyyE1O7 /7j7OtxS+Z7kaSXUx8D+uUmYTEc9+is= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.44 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662082177; 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; bh=an2Vy3VuXKzVKR25TTPGKC/tzJhpVW0zxqttXaH9GMk=; b=vLL1wrbJ/1YznHoCYp5mTRCcObyijOnzEMes4PABfqbNqueHltWNwPTzL3kj2geI5y8Cq8 ZipdIYH+TFwV94cP5XQlERk6Oo7rJ1zzSYhWW3h3tulK7ymB0D4i23/9Uy6U4KiVu0zbSz SnoHX7r3d4aYIgPne8r3Lc3BUhK3Ac4= Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.44 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-Stat-Signature: nt7k4q9w1au18ukbwz4ea5qqz71qoskw X-Rspamd-Queue-Id: 1061540045 X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1662082175-515769 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 9/2/2022 5:06 AM, Mike Kravetz wrote: > On 09/01/22 18:41, 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: >> Suggested-by: Mike Kravetz >> Signed-off-by: Baolin Wang >> --- >> Changes from v2: >> - Combine PMD and PTE level hugetlb handling into one function. >> - Drop unnecessary patches. >> - Update the commit message. > > Baolin, were you able to at least exercise the new code paths? Especially the > path for CONT_PTE. Code looks fine to me. Yes, I've tested CONT-PTE, CONT-PMD and PMD size hugetlb with move_pages() syscall, all works well and the lock is expected. > > Reviewed-by: Mike Kravetz > > It is a little hackish, but this is only for backports. So, I think it is OK. > We may want to point out that code cleanup and simplification is going upstream > that will address these issues in a more elegant manner. > >> >> Mike, please fold this patch into your series. Thanks. > > If I understand Andrew, this can go in as a separate patch for backport to > address potential bugs. I will provide a cleanup/simplification that will > remove this going forward. > > Andrew also asked for a Fixes tag. > Support for CONT_PMD/_PTE was added with bb9dd3df8ee9 "arm64: hugetlb: refactor > find_num_contig()". Patch series "Support for contiguous pte hugepages", v4. > However, I do not believe these code paths were executed until migration > support was added with 5480280d3f2d "arm64/mm: enable HugeTLB migration for > contiguous bit HugeTLB pages" > I would go with 5480280d3f2d. Make sense. And I saw Andrew has helped to add a Fixes tag with your suggestion. Thanks Mike and Andrew.