Received: by 2002:a19:651b:0:0:0:0:0 with SMTP id z27csp3751774lfb; Mon, 9 May 2022 03:21:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym0eY0ULV3l/jG96SD6uziCrdrwiT2KBR5EBnXd0CZfO3Mmrc7hCfu/Y3mfWgwrMkyZBLO X-Received: by 2002:a65:6451:0:b0:3c1:cb83:8e4 with SMTP id s17-20020a656451000000b003c1cb8308e4mr12634563pgv.339.1652091688378; Mon, 09 May 2022 03:21:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652091688; cv=none; d=google.com; s=arc-20160816; b=eHcKtsAdXVC+WUdYmjBGni/+Gpfofc8c4EBF9boWdGSLqlqE7mI4F0+GkrrglSa/qb 6bOodH6Oz567CbfocvJXtg2O7CdMe9hqV5V0ZEQ3Fd7PKB9WKgieF8jAkie//sHjCnX2 X4luOlcV8qK2CcYfnFQmqV5zEggnASRl/TlgM8F+mXXTvZZEZOGQobVC4WrUCI6dRg/7 VF48FgczKmoiDoK6b+jOQZdLuz2+41qcw/PZjORMcunkY1di+Zpz6YXgp8Oap6V2Dkdf xe+IJt0qwjbYYeaIPPd/CElHCIzCpfn583MVmHTk/6qXHxU0aau65kU3AWGexFIsBIdm +uEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KwBbyH87QLuFybJCJK1L3o2HCzGQtzlhndyFtKBo1+M=; b=peVL5Kv14j21p+vrtDz1LKBc/XKtfRlirGAEoXyXERlmG+C7cBVF0NXw7HmOn5namJ Xko9/zKkKYD1S1g1UHv14vl44ydRLRMftzGmtOP7UPga5J7kWvgHh9JlI0tI19o28jBn /fm7u8lsJkS8jZvwF4YGyjE8sHZ1E4YnnS8mXOr/HcWKAJS1/1E+oUWDYZW9d5YYKncq oB1wbbtCA1/DH6xPec7B+RBTOgkC2PVgaeQyHMmW8a8ZuNwiPMklAZA2fZuJm0+GIRnb QaDsNvC+/2qErtbaqfEvokqKjhVhuT8UGHgMrSDMxPhb4nFjjQ0ybgMRSCu6nky2A+MD QHsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=YUWb9VnH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i1-20020a17090332c100b00153b2d16513si12873471plr.283.2022.05.09.03.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 03:21:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=YUWb9VnH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7C4CD9D4D0; Mon, 9 May 2022 02:56:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235111AbiEIGtz (ORCPT + 99 others); Mon, 9 May 2022 02:49:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236089AbiEIGqQ (ORCPT ); Mon, 9 May 2022 02:46:16 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7EBB122B73 for ; Sun, 8 May 2022 23:42:22 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id bo5so11442288pfb.4 for ; Sun, 08 May 2022 23:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=KwBbyH87QLuFybJCJK1L3o2HCzGQtzlhndyFtKBo1+M=; b=YUWb9VnH9CLdCOFSCg0EgRuHaol/guxgUnIE24J/u98QZ3I3dvqShcw6bHn8PbLn33 De91e3fLiUGBZs3puXjUkFqnGkfsceO/2eweNFJzxUeEtvloQSE+QJUqsSR4B/n5rCXn fOwQjXfTmiY/r6o87bGR+3OcaUM524WjnTrpTYj/0PlXxJLh/+Gh7NH9mmwLwHUNU7RV 798mKiROjo4EcdLxdwMlUkdsZDYVb3TJer8JHISDq/bQz+F1seNMMayMZJHD4rOjmga0 GVFw2YGdi2fk3IJL1R+yM+i5a8XRpkgqS57S/UyObr/jP4lzVJidIkm4bfeiGNsDsFN7 rlTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=KwBbyH87QLuFybJCJK1L3o2HCzGQtzlhndyFtKBo1+M=; b=KiBl2dnFL/1GoYqabYHZTzv3Zoty4nUBItpM0Bfe8FRyUFZO7g0fFEfflyzCB4BtI+ ynMKuKxwyk9miZW6NgwPTrJNnSGMlzHzed3wsEXbedWlHySHgFdxvvAZqFB2waRPQU8j ygmsgcD2NC6n3vEM4MmBweOfIUpNB55h5nXlPnjP5ojdvc8LjGANSVRm1lc65uVSlc59 O2yCodqR18ET48a2gnu+c/D6SHZ3rB/cbNCObghktrmcqZUs9SRxzKh0k9ZPr97ahVN3 jdTYcQgXvPhR9NgCJa6izIaXZ/nJhhOMhGa5QWcy565xKB6dPmfWmLKVO3LeU348KgdE 3hfA== X-Gm-Message-State: AOAM530DnuwUbovvDhZGCxdvhiXbSwf4CXqlbgqPvW3ip5m2tIGF6bDV MehPQg34pV83mpvbbuVcsxedPQ== X-Received: by 2002:a63:6987:0:b0:3c6:c3ce:5097 with SMTP id e129-20020a636987000000b003c6c3ce5097mr2699720pgc.293.1652078540543; Sun, 08 May 2022 23:42:20 -0700 (PDT) Received: from localhost ([139.177.225.250]) by smtp.gmail.com with ESMTPSA id r10-20020a170903020a00b0015e8d4eb21bsm6178989plh.101.2022.05.08.23.42.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:42:20 -0700 (PDT) Date: Mon, 9 May 2022 14:42:17 +0800 From: Muchun Song To: Baolin Wang Cc: akpm@linux-foundation.org, mike.kravetz@oracle.com, catalin.marinas@arm.com, will@kernel.org, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, deller@gmx.de, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, ysato@users.sourceforge.jp, dalias@libc.org, davem@davemloft.net, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 3/3] mm: rmap: Fix CONT-PTE/PMD size hugetlb issue when unmapping Message-ID: References: <43b11b69e9f0d9d7e7960b86661db27cc404d0c7.1652002221.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43b11b69e9f0d9d7e7960b86661db27cc404d0c7.1652002221.git.baolin.wang@linux.alibaba.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 08, 2022 at 05:36:41PM +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. > > When unmapping a hugetlb page, we will get the relevant page table > entry by huge_pte_offset() only once to nuke it. This is correct > for PMD or PUD size hugetlb, since they always contain only one > pmd entry or pud entry in the page table. > > However this is incorrect for CONT-PTE and CONT-PMD size hugetlb, > since they can contain several continuous pte or pmd entry with > same page table attributes, so we will nuke only one pte or pmd > entry for this CONT-PTE/PMD size hugetlb page. > > And now try_to_unmap() is only passed a hugetlb page in the case > where the hugetlb page is poisoned. Which means now we will unmap > only one pte entry for a CONT-PTE or CONT-PMD size poisoned hugetlb > page, and we can still access other subpages of a CONT-PTE or CONT-PMD > size poisoned hugetlb page, which will cause serious issues possibly. > > So we should change to use huge_ptep_clear_flush() to nuke the > hugetlb page table to fix this issue, which already considered > CONT-PTE and CONT-PMD size hugetlb. > > We've already used set_huge_swap_pte_at() to set a poisoned > swap entry for a poisoned hugetlb page. Meanwhile adding a VM_BUG_ON() > to make sure the passed hugetlb page is poisoned in try_to_unmap(). > > Signed-off-by: Baolin Wang Reviewed-by: Muchun Song Thanks.