From patchwork Wed Jan 29 11:54:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13953684 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 B1C18C0218D for ; Wed, 29 Jan 2025 11:55:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80CA7280038; Wed, 29 Jan 2025 06:55:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7468B280025; Wed, 29 Jan 2025 06:55:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54D4D280038; Wed, 29 Jan 2025 06:55:05 -0500 (EST) 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 2B52E280025 for ; Wed, 29 Jan 2025 06:55:05 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 13279120E1D for ; Wed, 29 Jan 2025 11:54:54 +0000 (UTC) X-FDA: 83060332950.26.4C9F521 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id CBF4740003 for ; Wed, 29 Jan 2025 11:54:51 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hIpLnsqD; spf=pass (imf12.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@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=1738151691; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8FdUGdC2w/N5TeOcJ3tL/h1ogRWBFVvHy4t3b3m6isA=; b=HAN60+dKEZ4gSo5i/f8S97GjbGjR4+7FGw+re5s7W5oHFLFRc2Br7zfOIp76fa8OZ1cxdg 2pCSFaWszNRu3OnybZnwvbKyugQubWSDCpJOyZZ/rRIowPMD4x+7WNoAEa8KfLpUdJthKK 6bcyXOBwKypPSLV5yhXzBgbLbUeBwhA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738151691; a=rsa-sha256; cv=none; b=j5V4Z8O1jWlHsjjJzP8U/C/SP0LzPekwhduYeDnzXkqzilpB3Kagrzg28cKQcelHlDANTe H8B/Mtzrh0AELl+ih6kMkYF6gZAJeIb+J0qiRjQiA8XFPUbKme39ie1TIYNepVRvsAAIvS cNVk2vn0EAv6RZIrQ7+WvIUfHIJM5bI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hIpLnsqD; spf=pass (imf12.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738151691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8FdUGdC2w/N5TeOcJ3tL/h1ogRWBFVvHy4t3b3m6isA=; b=hIpLnsqD5RbDU8gw0WGmPPyfiIak/MxLjmueg0GlNudyinRIKdeyXdoeBzP8T/S5FY8jRP bsk7YaIEj60jfF+hUeWx/lHDtFZjuc030VsLFF4s3IzrLB28o660Wgey2nxtDQrMJEcZYN SbDZWpLXGxYPz/D491Io2+TH7dvuSfc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-Lfa4pMu7NtSFPqz3yHVJRQ-1; Wed, 29 Jan 2025 06:54:49 -0500 X-MC-Unique: Lfa4pMu7NtSFPqz3yHVJRQ-1 X-Mimecast-MFC-AGG-ID: Lfa4pMu7NtSFPqz3yHVJRQ Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-385e49efd59so2588086f8f.0 for ; Wed, 29 Jan 2025 03:54:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738151689; x=1738756489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8FdUGdC2w/N5TeOcJ3tL/h1ogRWBFVvHy4t3b3m6isA=; b=AlcLz6mnSfQUXwu2vwzZ/lobpFC8jnvr4cDFrSPVXYEQD5XWm35dMTLUa7LjkGfvJS A1cJFmDR2T8z6IIwkSvziK5MfXW4DJHMXVdE+rJBXWEdQIH4aEae3SfpEE8AfDLrGk5N tB0LmLK8wAEUxfVKEw5jvQHKkDQw0tOUlJpUPO9h5JlaidyXk2yHRz6OupD7E6mtxDBc ZjjKBeQ20rUU1g4b8xj1nPIIoWEMC4/n3YYn3N0cwSCfPSjwPl8s6UDlzT06S8YJb3O+ 51Q24WSq/ZQ665K3ine5Wt8YkAGajciet2LX7SalMco5HZVRnxvsysofnpQm/x0S5FzT IA6A== X-Forwarded-Encrypted: i=1; AJvYcCXKRGj3Cx5FCwBGUHYUCnrmfOly2iXE+IZYGh6QsKWh1lfzcbogAYmvEd6bA6M0mtOVupAdLaGJ6g==@kvack.org X-Gm-Message-State: AOJu0YwzHGfrRFb1aufyw5m0GEmc/AesyGhXhywkIRx1pdQQttfy7gzf 5jZP4Ty8XAYyrL62nzi2Mx2pkNDuCI8iSBkotprwraqzE18iXHao6iFKuAZvKlKKFWYT1bB0mwU FuD4kvSrLNG+IbvyaHMgLkfo8SYi0jWvOhxaIg4Q5GcbBvo5L X-Gm-Gg: ASbGncvLBgT4KcqTh9o6Wrbf0lBeWNNbb+FLTVyuy76Wlb9dBccaixSWE4afp70MYmp 2wYCfQYyKn4sN0LpxOqUBuNt+KDAawri4ietqkDpg7Kucm194VsStgfM2sJsa6m9mHtMOt+CLjy ElixsH0frRHfZzZhLbTPyTRPWEWQfTc1V7uhg8Df1NIN8a0UYIUdtLUuNn6OYWWXH99QFx3r7lu jDoZZWWgE3mWKINOX7lFYcuk9zWh3LwGwMeAqDceVeR2oFttdnWiXoTIcSQodiZ3Vk0KdiCZNI7 e83CxBbiOSoMOJZhzY1rFTxmKQjLKoUcV6qj8yimBKrpl4syPAqT7GrfcXVK/kywzA== X-Received: by 2002:a5d:5384:0:b0:38a:8ed1:c5c7 with SMTP id ffacd0b85a97d-38c520bdb45mr1846672f8f.46.1738151688842; Wed, 29 Jan 2025 03:54:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQObdLJ4S/sxdMO/dY9vI6fd5p4fQOJgmwgX26yitgXbCNTkIYH7aPDZgCkfY36quLJ2o2xA== X-Received: by 2002:a5d:5384:0:b0:38a:8ed1:c5c7 with SMTP id ffacd0b85a97d-38c520bdb45mr1846636f8f.46.1738151688502; Wed, 29 Jan 2025 03:54:48 -0800 (PST) Received: from localhost (p200300cbc7053b0064b867195794bf13.dip0.t-ipconnect.de. [2003:cb:c705:3b00:64b8:6719:5794:bf13]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38c2a1c4006sm17020800f8f.94.2025.01.29.03.54.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2025 03:54:47 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, David Hildenbrand , Andrew Morton , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Jonathan Corbet , Alex Shi , Yanteng Si , Karol Herbst , Lyude Paul , Danilo Krummrich , David Airlie , Simona Vetter , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pasha Tatashin , Peter Xu , Alistair Popple , Jason Gunthorpe Subject: [PATCH v1 12/12] mm/rmap: keep mapcount untouched for device-exclusive entries Date: Wed, 29 Jan 2025 12:54:10 +0100 Message-ID: <20250129115411.2077152-13-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129115411.2077152-1-david@redhat.com> References: <20250129115411.2077152-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: uxGnIROl4AK4DDe-vmAKVzRiRJgCiG4HSuJ4hRuYcns_1738151689 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: CBF4740003 X-Stat-Signature: wfkshtktkirh16zk8k98rma7r7afyu3s X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1738151691-874674 X-HE-Meta: U2FsdGVkX1/VucadSj5WqUfRHR/J225n9r3Hzw6bsiJwY9prKCMGCHoTY2xqpvETAgDAszrrnLLxy8PLjsgh3tJ2QXO7hBS+49dl9KfVfVe1TsvnZuHwZyo+dV1vpjxs/6kz+LT1cdTVsctTMGyvaJXHhHr2CFGo8iwiufxyl+oFYCekOPn2qMw+cZzGe0B22//y1aoNoLkerTcaQ6RhPHJNe3znfDeRhqDeK65QxG1O7DEYeREHtc4ZwHqbKC+U2aI4YktMIGHftjwymEzdyVNDmUYXqkoBBu3IqdACSQxd+rA3uwEq6V8Xmg2qiVvE4YUKTeHR9OtvbshY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Mkw3Qj17NrU41+oK5aBEe9NpEnodfbeaM2Qo/3QXRP0g X-Bogosity: Ham, tests=bogofilter, spamicity=0.000012, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Now that conversion to device-exclusive does no longer perform an rmap walk and the main page_vma_mapped_walk() users were taught to properly handle nonswap entries, let's treat device-exclusive entries just as if they would be present, similar to how we handle device-private entries already. This fixes swapout/migration of folios with device-exclusive entries. Likely there are still some page_vma_mapped_walk() callers that are not fully prepared for these entries, and where we simply want to refuse !pte_present() entries. They have to be fixed independently; the ones in mm/rmap.c are prepared. Fixes: b756a3b5e7ea ("mm: device exclusive memory access") Signed-off-by: David Hildenbrand --- mm/memory.c | 17 +---------------- mm/rmap.c | 7 ------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index db38d6ae4e74..cd689cd8a7c8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -743,20 +743,6 @@ static void restore_exclusive_pte(struct vm_area_struct *vma, VM_BUG_ON_FOLIO(pte_write(pte) && (!folio_test_anon(folio) && PageAnonExclusive(page)), folio); - - /* - * No need to take a page reference as one was already - * created when the swap entry was made. - */ - if (folio_test_anon(folio)) - folio_add_anon_rmap_pte(folio, page, vma, address, RMAP_NONE); - else - /* - * Currently device exclusive access only supports anonymous - * memory so the entry shouldn't point to a filebacked page. - */ - WARN_ON_ONCE(1); - set_pte_at(vma->vm_mm, address, ptep, pte); /* @@ -1628,8 +1614,7 @@ static inline int zap_nonpresent_ptes(struct mmu_gather *tlb, */ WARN_ON_ONCE(!vma_is_anonymous(vma)); rss[mm_counter(folio)]--; - if (is_device_private_entry(entry)) - folio_remove_rmap_pte(folio, page, vma); + folio_remove_rmap_pte(folio, page, vma); folio_put(folio); } else if (!non_swap_entry(entry)) { /* Genuine swap entries, hence a private anon pages */ diff --git a/mm/rmap.c b/mm/rmap.c index 9e2002d97d6f..4acc9f6d743a 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2495,13 +2495,6 @@ struct page *make_device_exclusive(struct mm_struct *mm, unsigned long addr, /* The pte is writable, uffd-wp does not apply. */ set_pte_at(mm, addr, fw.ptep, swp_pte); - /* - * TODO: The device-exclusive non-swap PTE holds a folio reference but - * does not count as a mapping (mapcount), which is wrong and must be - * fixed, otherwise RMAP walks don't behave as expected. - */ - folio_remove_rmap_pte(folio, page, vma); - folio_walk_end(&fw, vma); *foliop = folio; return page;