Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp998343lqt; Fri, 7 Jun 2024 05:25:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXf8OwG2yUbEjQN9ciFy21KC8ilCrcCDHhXOY4+gTXyyABNCu3xO5iU/zswkjblI+R2i6TaBlwE++OsvsXA/ZGKnl/ON/rl2eWBHAPjkA== X-Google-Smtp-Source: AGHT+IGtsBfpVri2uWUsNJx2gJIjlDt0NVN/tOAmQ1FEvHUbX6THRBatWfIJG+Io9AtXAYML79nf X-Received: by 2002:a05:6e02:1d8b:b0:373:871d:5df6 with SMTP id e9e14a558f8ab-375803ad58dmr25766245ab.23.1717763113591; Fri, 07 Jun 2024 05:25:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717763113; cv=pass; d=google.com; s=arc-20160816; b=hRf7KyR3qUDQWzzYrPGEaCGMRQ/Orwgh83UWuH9enEbeeEkfkj1ntHop2yWiD6lPBE /uX+vZzLZ4ITvyGWjE5C3MibF6fKY9GVLyIDpLWQNjYwR2zAG+aGlEFmpfdUUp43QUJT IHgKBZ0F8k5iWQD2HXkX8r6XHvSJelz0NBJeHzO26EypalFdyKV+CqkkDWiKYlLArZyX Q2E8+P5JKCYmnurkwEMvqUbsHlCKkYTU6VM7z++BKotXYTH9jrUFKXD/53d6RNH4/QzM I11EXHtpnlUKpPuCxclw6jYnXArlK3GHD0brgE7T7zPuMlBdhBTkcMfSfTR0q7GZZDL3 yyyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ovOsFhoeBcVzjRXyHZJ60IBLz8Imu+IZUpS2p2waMJI=; fh=CIaeNsHvdnbvngJjnzLDSb2UCdCi60rbbZWKayXDh6A=; b=htzTxBQz6ZNNuGq9elRopx9j+GhfuzQPXbh4Ufy2iqKQNai9QDJdQ5FgcCJz+5h3Sd ITyrbJkYGe+tElT2h2es7KFZp1zaAYYpPkw/TtJLG30dvtoMtgJcf45xkSBQEF485c/L xiA1IbpUYz4cJEuhgT32go86f9iDTAJz9qejMeN88yQIkAwhh2yTk4X4B7Z4QMtjeq0E jtHkUDWDvzIyfQNJiXcY27Ul7t7LqHu28/cUixp7o6+t6XjXn2dqThM+h5G1+PNYEgOM u9IKlY6T55rD4KQv7qo8X5vB49umYBiTKDD3nDzzpWlxwWQWUSm3MH/1p9wAR4vJFv1P m/ag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KSh4ymjJ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-206019-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de261c9a2dsi3060557a12.334.2024.06.07.05.25.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 05:25:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206019-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KSh4ymjJ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-206019-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 28A5628A290 for ; Fri, 7 Jun 2024 12:25:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7A50194A49; Fri, 7 Jun 2024 12:24:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KSh4ymjJ" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4928F193063 for ; Fri, 7 Jun 2024 12:24:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717763052; cv=none; b=ge6F7UsIMP+8wERnxN++vxkVIBr4tmxSaUAB/h4G0ribuIh79NBI35ryg3JII39PbgcaLQ3Wk6qQdbK/pL++fzMonNDEfDBqoOcSvXlky4V4BvN4Qpc5oMOBtnT8SOyME8lFIItC493MqLP62q/9CJuAdIllbq50ZrX+Ex1FLJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717763052; c=relaxed/simple; bh=Ec4k3e66hg4z9z133SHENd5EvlVIm84PgrgP6E8dHmA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jJcm/JThIB/Qm8bIcXQ3OenAWw0XsPSLSMcQZKwdDU4nXpnt+nZ9SNa8DezClN0cyNKNr/C9FgxxlchwJCBVQHxWKMVivDEDihqXq7apzEN4IKbShq83tQu7FrxskYk1U3lZDYD0JwwGtKspe/AabdxIDa4fgVd/c9qTXxr7lfY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KSh4ymjJ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717763050; 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: in-reply-to:in-reply-to:references:references; bh=ovOsFhoeBcVzjRXyHZJ60IBLz8Imu+IZUpS2p2waMJI=; b=KSh4ymjJGsudsUhoOQ3F54dEdvcCae2F1s/qf8mUlZyh4dZIbrnISpfb+6mkSm8y+5O2BZ xmHC8erw4yUCkXoSWiYfir4LxEWTjlUGKWWrBNJyrL0LvtEglwEGN8jIAd1Y2mR2z56/xB LAfGLJOlM9ZZUBs4Lx8nlmVgUHZr2yU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-Fs9Zz3hfOzmviTqkwaPypg-1; Fri, 07 Jun 2024 08:24:05 -0400 X-MC-Unique: Fs9Zz3hfOzmviTqkwaPypg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id B888A1C05129; Fri, 7 Jun 2024 12:24:04 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A76D492BCD; Fri, 7 Jun 2024 12:24:03 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Jonathan Corbet Subject: [PATCH v1 2/6] fs/proc/task_mmu: don't indicate PM_MMAP_EXCLUSIVE without PM_PRESENT Date: Fri, 7 Jun 2024 14:23:53 +0200 Message-ID: <20240607122357.115423-3-david@redhat.com> In-Reply-To: <20240607122357.115423-1-david@redhat.com> References: <20240607122357.115423-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 Relying on the mapcount for non-present PTEs that reference pages doesn't make any sense: they are not accounted in the mapcount, so page_mapcount() == 1 won't return the result we actually want to know. While we don't check the mapcount for migration entries already, we could end up checking it for swap, hwpoison, device exclusive, ... entries, which we really shouldn't. There is one exception: device private entries, which we consider fake-present (e.g., incremented the mapcount). But we won't care about that for now for PM_MMAP_EXCLUSIVE, because indicating PM_SWAP for them although they are fake-present already sounds suspiciously wrong. Let's never indicate PM_MMAP_EXCLUSIVE without PM_PRESENT. Signed-off-by: David Hildenbrand --- fs/proc/task_mmu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 08465b904ced5..40e38bc33a9d2 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1415,7 +1415,6 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, { u64 frame = 0, flags = 0; struct page *page = NULL; - bool migration = false; if (pte_present(pte)) { if (pm->show_pfn) @@ -1447,7 +1446,6 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, (offset << MAX_SWAPFILES_SHIFT); } flags |= PM_SWAP; - migration = is_migration_entry(entry); if (is_pfn_swap_entry(entry)) page = pfn_swap_entry_to_page(entry); if (pte_marker_entry_uffd_wp(entry)) @@ -1456,7 +1454,7 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, if (page && !PageAnon(page)) flags |= PM_FILE; - if (page && !migration && page_mapcount(page) == 1) + if (page && (flags & PM_PRESENT) && page_mapcount(page) == 1) flags |= PM_MMAP_EXCLUSIVE; if (vma->vm_flags & VM_SOFTDIRTY) flags |= PM_SOFT_DIRTY; @@ -1473,7 +1471,6 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, pte_t *pte, *orig_pte; int err = 0; #ifdef CONFIG_TRANSPARENT_HUGEPAGE - bool migration = false; ptl = pmd_trans_huge_lock(pmdp, vma); if (ptl) { @@ -1517,14 +1514,13 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, if (pmd_swp_uffd_wp(pmd)) flags |= PM_UFFD_WP; VM_BUG_ON(!is_pmd_migration_entry(pmd)); - migration = is_migration_entry(entry); page = pfn_swap_entry_to_page(entry); } #endif if (page && !PageAnon(page)) flags |= PM_FILE; - if (page && !migration && page_mapcount(page) == 1) + if (page && (flags & PM_PRESENT) && page_mapcount(page) == 1) flags |= PM_MMAP_EXCLUSIVE; for (; addr != end; addr += PAGE_SIZE) { -- 2.45.2