From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F7C23B8D65 for ; Mon, 8 Dec 2025 02:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765161168; cv=none; b=scKjBDGy44FIqe/L2S0H9SkDQ/xkPyRcWDI+L+UcZbIMffLEaNuyrYOgY42kpDU1Emg0jlVbj8Sn1g9/9wPcXslcu1hlwt6KLOwtVCJOOxkuF2pdDkWcI2+dnUo20ZELG7koYbpfKJq5Dx/XkSd1Vii83ZGzKBjUM9plMfp6p2M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765161168; c=relaxed/simple; bh=LDZzKnxa+uTKJQ1W2cNOvHeQO1Wju4V+jZZPxkOpJmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VLC8n32EUqZY2C5/DtkvodXYwiX3YMJVrAbT1l+Ws8FwctmJ1m6DOLD4gWOq7/MFkVfXzQVyoVDKVz6Q1fCgiroQNW9zDkhae/O58H8sTftg+jJ/Mn29auwTSHBYstBPpx3tf2YWo9eZYDrzG5ZFTdOYAECVVhbUO7YIRBncNlw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dYna8Eyq; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dYna8Eyq" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7bb710d1d1dso6358050b3a.1 for ; Sun, 07 Dec 2025 18:32:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765161162; x=1765765962; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OYtF8RDRQ6VRaXKUfw5cvR+LupuhtEwbZq6O0/1AaHc=; b=dYna8EyqTaE7QpaK8kc+K/8MmSwSYUmFCLZ8F3FhTTXjghsCyoDqwsXhi/rl5uZ6Z2 mOjZdThoZ7xMK1PmSG4EpHETu3CGf10zmxcLdrNEFkgpmHUv6fLOigdwTxdEZdIGylUh cLIzade44fbl2/Q06xH5JoYa37+hJ+RLX3sVb1z3STZGgGzVFiX+pMA4a45zXF5HWmM8 il3T4+IeKPZAVaoJmKdxMZNqzcmWpKdsADvWax4PUFdtR5WCCNqcIjrPLU6AisrVdWdu 5pgrCM6RV6HECAB4YpJXIwTf5lac3b5xqPozIAaZqPAxYvpIUL+WfPtzfNpnBqOFxTCT Tbtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765161162; x=1765765962; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OYtF8RDRQ6VRaXKUfw5cvR+LupuhtEwbZq6O0/1AaHc=; b=RQLYlFUD9PbFIZEay2HLmmhyV6KrdUpCi+BAkmF6BIi7ZOrrbd1NC2LMW+WPJ/AsE8 +xgEA44YkQoUNlYVf0fTTU663uh7bphUezoWglre1qtQTpybWdYQHEuoL+njAYW8THOs YqZWofIui0bZJYPiRGjrpQ0KBMNbb1UvLwBIg+OodC4oEyKUShM4jOAXPLPrhIJ8nKPE +SMOw+Qe8/780dDniw6xMN5nG+/NUPasTO2gGjCK6Y6mQ0lurLoB6wnIlI3+CsQfDghu IFkFiQiMAupkSvYxnXTfPXfQeiJpO3TMkL0z5lcZSU8azzVt+8VyQ4viGQUXXvlwT9lY MWCw== X-Forwarded-Encrypted: i=1; AJvYcCUZgnqk/iCwo+YjqIeRd7VTgmVcD2Ps8puYcMf0ltW021jUKWoTU/cZzhDbaYiWqVo3RsL5yb0mV2L9bOc=@vger.kernel.org X-Gm-Message-State: AOJu0YwCgCLRvHv18ABFHjJ3XutI+Rho7luOf/vLceGDwdIGZpMI9ZzI /OzhL746o748x1wrbo88vZlxiZhMFo7PtQJqpZbqjNSIBuzffQEg5Nt1 X-Gm-Gg: ASbGncvxV8i2ULfxxQ7SiXqTE1sTJI9jTee4Se5OEwwMuQloNBMFY/z1JC9ChDTIMwj HSsOWban/Z50GOL6s1q0w3wgqO4RdXbECKlIkXBBGJISmGrrfv1CJAe0kKntV5hh6vfwSOuv9aQ y9KmaD6qNBuxHQF5TyI6kFiWzt9YjRK5RmPSZ8OSAXdRvrsE1Yeq0qItv+X0N5IAV8gXv+57DOx NA3OgZuBaLVajg+I8f5SwhWm7aqvGYW7t6P7e287ocgPN4nO2kPshw1riu6ay7gDgrYO+3GqCyR pdOn3J4TOeBIKhnmW4PM+ybIuU3C744Ukpi32plkBuEUedMgw2FqZ13nZA/BF5f6w29+KRsrSQC iBYCvVch27aGogcDJCDXirEXkE1uA7hobp3oue7EgXt4ZCuULsPqViZF9FJG5f4W656zMH6c= X-Google-Smtp-Source: AGHT+IFD9CuAvyh/LldTgp7Zr7VitBVZghYnCn8DknhWR1P71K3h0yhqlnfFLuZIhyuQUfCBStR0eg== X-Received: by 2002:a05:6a00:1883:b0:7ab:f72e:8f9b with SMTP id d2e1a72fcca58-7e8c3a0ce46mr6066644b3a.25.1765161161990; Sun, 07 Dec 2025 18:32:41 -0800 (PST) Received: from EBJ9932692.tcent.cn ([2403:2c80:6::3075]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7e2af658d84sm11155165b3a.60.2025.12.07.18.32.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 07 Dec 2025 18:32:41 -0800 (PST) From: Lance Yang To: david@kernel.org Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, arnd@arndb.de, harry.yoo@oracle.com, jannh@google.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, liushixin2@huawei.com, loberman@redhat.com, lorenzo.stoakes@oracle.com, muchun.song@linux.dev, nadav.amit@gmail.com, npiggin@gmail.com, osalvador@suse.de, peterz@infradead.org, pfalcato@suse.de, prakash.sangappa@oracle.com, riel@surriel.com, stable@vger.kernel.org, vbabka@suse.cz, will@kernel.org, Lance Yang Subject: Re: [PATCH v1 1/4] mm/hugetlb: fix hugetlb_pmd_shared() Date: Mon, 8 Dec 2025 10:32:31 +0800 Message-ID: <20251208023231.1257-1-ioworker0@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251205213558.2980480-2-david@kernel.org> References: <20251205213558.2980480-2-david@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Lance Yang On Fri, 5 Dec 2025 22:35:55 +0100, David Hildenbrand (Red Hat) wrote: > We switched from (wrongly) using the page count to an independent > shared count. Now, shared page tables have a refcount of 1 (excluding > speculative references) and instead use ptdesc->pt_share_count to > identify sharing. > > We didn't convert hugetlb_pmd_shared(), so right now, we would never > detect a shared PMD table as such, because sharing/unsharing no longer > touches the refcount of a PMD table. > > Page migration, like mbind() or migrate_pages() would allow for migrating > folios mapped into such shared PMD tables, even though the folios are > not exclusive. In smaps we would account them as "private" although they > are "shared", and we would be wrongly setting the PM_MMAP_EXCLUSIVE in the > pagemap interface. > > Fix it by properly using ptdesc_pmd_is_shared() in hugetlb_pmd_shared(). > > Fixes: 59d9094df3d7 ("mm: hugetlb: independent PMD page table shared count") > Cc: > Cc: Liu Shixin > Signed-off-by: David Hildenbrand (Red Hat) > --- Tested on x86 with two independent processes sharing a 1GiB hugetlbfs file (aligned a 1GiB boundary). Before the fix, even though PMD sharing worked (pt_share_count=1), hugetlb_pmd_shared() returned false because page_count() was still 1, causing smaps to report it as "Private" and pagemap to set it PM_MMAP_EXCLUSIVE incorrectly :( After the fix, hugetlb_pmd_shared() correctly detects the sharing, smaps reports it as "Shared", and PM_MMAP_EXCLUSIVE is cleared ;) Tested-by: Lance Yang Cheers! > include/linux/hugetlb.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index 019a1c5281e4e..03c8725efa289 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -1326,7 +1326,7 @@ static inline __init void hugetlb_cma_reserve(int order) > #ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING > static inline bool hugetlb_pmd_shared(pte_t *pte) > { > - return page_count(virt_to_page(pte)) > 1; > + return ptdesc_pmd_is_shared(virt_to_ptdesc(pte)); > } > #else > static inline bool hugetlb_pmd_shared(pte_t *pte)