From patchwork Thu Sep 26 15:42:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13813477 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 58003CDE015 for ; Thu, 26 Sep 2024 15:42:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B74AB6B0089; Thu, 26 Sep 2024 11:42:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B23506B0095; Thu, 26 Sep 2024 11:42:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C40C6B0096; Thu, 26 Sep 2024 11:42:45 -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 7864B6B0089 for ; Thu, 26 Sep 2024 11:42:45 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EDF381C71ED for ; Thu, 26 Sep 2024 15:42:44 +0000 (UTC) X-FDA: 82607307048.17.FD3489C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 6287DC0006 for ; Thu, 26 Sep 2024 15:42:43 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ByFDlo2p; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727365301; a=rsa-sha256; cv=none; b=U3xCpVVPtIBfie83mUpqcK7aOZIEJmQGXHBYQb98BvFM0rk+lq0QLkE02yZglcEUrXNgPl lzCla8WvsVuPHAbqOp8xXN20QDQ/Yu8+Crzx2kxGq+X+ogw8qvxyrZ2yXFdcIDFFeCcZKY NTqHZCzFXfufuqu087NEOIMC2Nr2Q7M= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ByFDlo2p; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727365301; 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=QzpXW0kqGG/nfjNuZXnte9cVrtF0I2kkpQcSvMv8nk8=; b=yT/F2aCxd9Vn3a0HZF/5h+n6VZcLJpq1V1VyMX3FYdolMbx45etM6gJ9UrCcu9CAt3/TuL okZNBU9eQHyje+bFPRZnXo6w6GR2uHJYHEnEjgjMnUS21+L/4KqD6145vqj2fl0xhziDr4 W4KM15Hn0qGUd1fBDwo7mWCw2JHH/Vs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727365362; 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=QzpXW0kqGG/nfjNuZXnte9cVrtF0I2kkpQcSvMv8nk8=; b=ByFDlo2p3c7R9la6kCHhUfpRcfPgzlcmn5xcN9+09mbaETJOqKg2+ncAnYCCznW3aU99SW quMKDQnDT30WltFRvH8RHCO6GZ8lcVhxdGZCVorRQeK/n7YKAvdjXOTmkVCizQ+yo9xlHE A0gq6e0lAoQiRtcHCXdzKyx0JAo9sZo= Received: from mx-prod-mc-04.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-272-P_ZYmrDuOzSD45jTD3BBiQ-1; Thu, 26 Sep 2024 11:42:39 -0400 X-MC-Unique: P_ZYmrDuOzSD45jTD3BBiQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9555F1903080; Thu, 26 Sep 2024 15:42:38 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.16.71]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 198AA3003DEC; Thu, 26 Sep 2024 15:42:35 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , syzbot+bf2c35fa302ebe3c7471@syzkaller.appspotmail.com, Peter Xu Subject: [PATCH v1] mm/huge_memory: check pmd_special() only after pmd_present() Date: Thu, 26 Sep 2024 17:42:34 +0200 Message-ID: <20240926154234.2247217-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Stat-Signature: f1uxkgk3yiux5x9gfnq9ksook9wuyi18 X-Rspamd-Queue-Id: 6287DC0006 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727365363-996558 X-HE-Meta: U2FsdGVkX1+hcrGsMh6ZLRVlMi6iTRhs7rg23HqyWxoj4ZlO9+dnkbMikdCVMNif+AWNVHJyWhD351/B90WdJ+WZamDwq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AZUl642rXLRRsJvR/p5ab4uiXX4u590EYLpRCH6sGkRTjR0zyesfqHB5YXvPOqLMQKPt6A4RGe+Afky0SIP7MFCyWW/e2HBqTqa0qvyEkw9jPK5JvsgZP/X0n6ahJyI4zC2bEVaM+60VTdQk264BUrwUyAPfL4NlVv9TSOkzqtqZ6pp86VSfrZ8nVJHx29+2qv0l1/uWvVBgtOr3mUN7tsubb9A1Bfml2D39A+v+DuXS54dNFmPCM/0m9K/3sn3MdHZvW3tNa4EYI45NvQiMSyGmh5X8ej/m+GKJuGOZBYpHYZxt4dyRK6bEBKaCo9TW0w1gCuCJ6r32PqAyY6rrUtvu2PQ0YRwwTO9M5SULLRSPGecrfbTHRr2yWf3qiHQVknzV5Ie/ 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: We should only check for pmd_special() after we made sure that we have a present PMD. For example, if we have a migration PMD, pmd_special() might indicate that we have a special PMD although we really don't. This fixes confusing migration entries as PFN mappings, and not doing what we are supposed to do in the "is_swap_pmd()" case further down in the function -- including messing up COW, page table handling and accounting. Reported-by: syzbot+bf2c35fa302ebe3c7471@syzkaller.appspotmail.com Closes: https://lore.kernel.org/lkml/66f15c8d.050a0220.c23dd.000f.GAE@google.com/ Fixes: bc02afbd4d73 ("mm/fork: accept huge pfnmap entries") Cc: Peter Xu Signed-off-by: David Hildenbrand Reviewed-by: Peter Xu --- I yet have to do more testing, but sending this out already. --- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 0580ac9e47b9..e55efcad1e6c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1586,7 +1586,7 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, int ret = -ENOMEM; pmd = pmdp_get_lockless(src_pmd); - if (unlikely(pmd_special(pmd))) { + if (unlikely(pmd_present(pmd) && pmd_special(pmd))) { dst_ptl = pmd_lock(dst_mm, dst_pmd); src_ptl = pmd_lockptr(src_mm, src_pmd); spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);