From patchwork Thu Jul 25 18:39:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13742089 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 17C20C3DA49 for ; Thu, 25 Jul 2024 18:40:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D0B96B007B; Thu, 25 Jul 2024 14:40:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 880846B0082; Thu, 25 Jul 2024 14:40:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76EDF6B0083; Thu, 25 Jul 2024 14:40:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5E2B06B007B for ; Thu, 25 Jul 2024 14:40:11 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CC76216131E for ; Thu, 25 Jul 2024 18:40:10 +0000 (UTC) X-FDA: 82379139780.06.CE3A358 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 37D0440005 for ; Thu, 25 Jul 2024 18:40:09 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ivXp23jH; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721932769; a=rsa-sha256; cv=none; b=E1rkosz74gVQwWU0zdsTsqUhS6ppPQmAVed+RWcA5Mc5K0K3N6DFdv2wbeEVx3gLGkDsmb GQG6+8mj7Y/4z6DtiC5p6mLYwyb6xq+stgZw9+6TbDk73sAeweSgy291F65p1vV240MY3J 9h/xCiMe/2fA5NYD2RdjjUTj4b+axHY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ivXp23jH; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721932769; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=6pZb0N/kLDE9N4DI8onERCvts5vm83WGgR5AndUh35M=; b=XuUAVdQCJBROZl2ozTGiig8a70gMC9NsyK3ZrdRSFhZIXFK7zqZT5BJf4pbiGdEb1fesbe FsGRgErYPfjoaIILw8JRRRTimy+s9q3duL0ooCiPvXm7nS3+C/JuTZqxx9u/xqd+WDUBkl j5e6il5/ecx3r8ATI1W/Q8jX3J/XlVo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721932808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6pZb0N/kLDE9N4DI8onERCvts5vm83WGgR5AndUh35M=; b=ivXp23jHax67WnDCdhCt+43A9TmnFC17k1fDKcO1w1QSOmy6+5YJ+DbhcEQ2vrYRMgDGkc oIhg5YKRS9IWBgXPOIbYe+dcQ2WzQF01Df2V9FxdlGgoK/i4yNnBxG8vexeSu9Ao22NdBa KZoqIzlDbxOdsuseVvMQrEJ6WWOcxJA= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-UZaOshO6MOaEgq3uezcFDQ-1; Thu, 25 Jul 2024 14:40:01 -0400 X-MC-Unique: UZaOshO6MOaEgq3uezcFDQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D4D5B1955D48; Thu, 25 Jul 2024 18:39:59 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C906F1955D48; Thu, 25 Jul 2024 18:39:56 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Muchun Song , Peter Xu , Oscar Salvador Subject: [PATCH v1 0/2] mm/hugetlb: fix hugetlb vs. core-mm PT locking Date: Thu, 25 Jul 2024 20:39:53 +0200 Message-ID: <20240725183955.2268884-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 37D0440005 X-Stat-Signature: ibhwanp1y3u57roqh7azc1uk41hhexs7 X-Rspam-User: X-HE-Tag: 1721932809-311206 X-HE-Meta: U2FsdGVkX1+QallfOHP/XWoCvCjywWATf8E0nAa0wFcoKollYXHzNo1KvB/PdJxLt5Y65mW0//7Ln/WZ8uxIHlIFSqQ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p8jvERPfI7Ha1//KdkDmNUBf8ZkLHiaz1H8n2wkzX1ExEMydDpE3SFwzwCEWV/kGDV7Jd5//wHvE5FKv4uSN9biZ/BmKAUhxXrxzBIpQWeRg0eUzA5WpTa/Ewi0zNjGT24BbymG0WmgVsV0tMlpDU7bWMknw3h4SwrlfAJeSZ2 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: List-Subscribe: List-Unsubscribe: Working on another generic page table walker that tries to avoid special-casing hugetlb, I found a page table locking issue with hugetlb folios that are not mapped using a single PMD/PUD. For some hugetlb folio sizes, GUP will take different page table locks when walking the page tables than hugetlb when modifying the page tables. I did not actually try reproducing an issue, but looking at follow_pmd_mask() where we might be rereading a PMD value multiple times it's rather clear that concurrent modifications are rather unpleasant. In follow_page_pte() we might be better in that regard -- ptep_get() does a READ_ONCE() -- but who knows what else could happen concurrently in some weird corner cases (e.g., hugetlb folio getting unmapped and freed). Did some basic sanity testing with various hugetlb sizes on x86-64 and arm64. Maybe I'll find some time to actually write a simple reproducer in the common weeks, so this wouldn't have to be all-theoretical for now. Only v6.10 is affected, so the #1 can be simply backported as a prereq patch along with the real fix. Cc: Andrew Morton Cc: Muchun Song Cc: Peter Xu Cc: Oscar Salvador David Hildenbrand (2): mm: let pte_lockptr() consume a pte_t pointer mm/hugetlb: fix hugetlb vs. core-mm PT locking include/linux/hugetlb.h | 25 ++++++++++++++++++++++--- include/linux/mm.h | 7 ++++--- mm/khugepaged.c | 21 +++++++++++++++------ mm/pgtable-generic.c | 4 ++-- 4 files changed, 43 insertions(+), 14 deletions(-) base-commit: cca1345bd26a67fc61a92ff0c6d81766c259e522