From nobody Mon Feb 9 12:07:46 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 1EB121DE4F9 for ; Wed, 29 Jan 2025 11:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738151676; cv=none; b=k/8Eg7e4+LuWmDt2wWyOMEJwOK/nOtixPzN7wp2ezKd7AfCZ77j0A0fOdTA2KGtYpM22TpbximYdqFtVMWKKuzdu4PILH5yiNTvc+w4qKUKFsJkfAAdJCKD2Olh7W3vxgg+RWlg+6r5gTg0DwwTfMkW7UNQxcWEZ2c2UxelEqak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738151676; c=relaxed/simple; bh=TUOIefDWX1orCSp/1pnVE1CfdjwXLwRBvFvFbOJdqfw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oyKFprjFL+l/LRFqV+OZZo673DAHMOW1GFsDnf72PzyWWqyK/WNqiFuk8+fim5FsE2dOW5iBeI/wQc2zLXYQcCUqy5IvJpYsbrqa7mFdcUOEDTf1k8zEPTWy82www7IWkaJqLqCh6FjKxi9DGLBCv/CcpXX0+7BlyQ/Di8K6iz8= 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=Yfshc1Ul; arc=none smtp.client-ip=170.10.129.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Yfshc1Ul" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738151674; 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=bwRdkJe7S5eVWCBWfyg7xh/8u+L2oGZrd41rkCVbduE=; b=Yfshc1UlVTAyHf+Wof3r2B5z3qQW2X5LU/m/5Dp2EvrDPQXR9BtboH5bdQtZmLz4LkDKCE 16Gc+ge92jdzr+U5S9gLxl9WmMKX2ED5JSXaUKs7FpZYIlbp1cN8Sg7Q0ymX2X9LX+9Dw9 jrMi2QV+6poq6Yulk0QKw86wFm31xLk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-vBc7NWiLNV2UYSBOyMfD-Q-1; Wed, 29 Jan 2025 06:54:32 -0500 X-MC-Unique: vBc7NWiLNV2UYSBOyMfD-Q-1 X-Mimecast-MFC-AGG-ID: vBc7NWiLNV2UYSBOyMfD-Q Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-436723db6c4so46630085e9.3 for ; Wed, 29 Jan 2025 03:54:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738151672; x=1738756472; 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=bwRdkJe7S5eVWCBWfyg7xh/8u+L2oGZrd41rkCVbduE=; b=GGjxgC5QY2R4W3qbrQZcBCwpvBPx6OY6TOnNeNsGaXJQdeh2sdOyr5o6sGbPrHw/gm TwqTB8sqh+t4+P0HGvgLA60bKy8p0y/DaLdoJu1rjC+CyEkD567gwHwubjuX3nn9FMiD 6ynChAX/LZTUZk3khWhK07gIWWQza+oOTx739dg1Edo79WI46ybNcedtoLyh7rmVEbuD UlXXbISoe+Hg4qdvEAIQ1yTQ9U8zA+IgdemKX8+oW8WiZl7z06d16DVYIZ4UtbS1rsw3 3WulpEp5dvQdThLn12P52+105QBFA+bREWwujoN2I1PGflWk/LzZnapS/7f3WSRmuaMM KyvA== X-Gm-Message-State: AOJu0YyWFJ/rWMaFRj0LJmMffA4jp+FeJq32lXwIaDcHGsvL15HliojQ VmdBcKcyL1gBgPz/dgFdNJ+QRItdsgRIB/WT1RYBlktru2NS2nh2+Dfu7kWcPJ7qijDjTMrVV3v rw7FsTKho0v0eqZI72d0CIJoJHdQ/kOcb7T2i40dkKO7pnEIVE7+ln7rSiSlSUBU6STzPuM6t3N 0Kk+CUOuK6rWOtb4OtnMVFxAovjDVS4yJ14ycG2YvK1tEs X-Gm-Gg: ASbGncvuXyTWWvOokmWxdhKS0e0QZYsl2EuY5duiv+bQtcFCWZitwigIgFgro0Cf3Zz /4oE/fNoqRo9lcW1bARgZCkKNib11VNr1okXEHdf4XAhPYFGlCFWDQE8oUcLPtdWwJE/LEd2Dam e4cWDLo9bh0fWr29IfudndqS9Mb/2HsICOP5Q9C329BZ6XxwSrCjsvxWFS2uV82Q3o/QjEWMTuz f+YkLE1LDKawK1iHAQAvNP/MmRAJ3A4I4mc4Kzncako+6Txx2XhGeIUWdgNkFtF1wiNebNFBYeV y9eP/uTLfHgxFUePO5G2Xocqh4b+BM9dBJHl7f6wZSr+nVpxFq+djPZU9gG8mDCj+A== X-Received: by 2002:a05:600c:1c1a:b0:434:f9c4:a850 with SMTP id 5b1f17b1804b1-438dc3c4623mr25664965e9.10.1738151671710; Wed, 29 Jan 2025 03:54:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhuPkSFqdGYqW92VDVvy4lKssWj+By02GdvgYFn3sg13RZ9e45UT5b96yUwTD+A2GCuT4qDg== X-Received: by 2002:a05:600c:1c1a:b0:434:f9c4:a850 with SMTP id 5b1f17b1804b1-438dc3c4623mr25664525e9.10.1738151671268; Wed, 29 Jan 2025 03:54:31 -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 5b1f17b1804b1-438dcc24e73sm20192895e9.16.2025.01.29.03.54.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2025 03:54:30 -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?q?J=C3=A9r=C3=B4me=20Glisse?= , 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 06/12] mm: use single SWP_DEVICE_EXCLUSIVE entry type Date: Wed, 29 Jan 2025 12:54:04 +0100 Message-ID: <20250129115411.2077152-7-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is no need for the distinction anymore; let's merge the readable and writable device-exclusive entries into a single device-exclusive entry type. Signed-off-by: David Hildenbrand Acked-by: Simona Vetter Reviewed-by: Alistair Popple --- include/linux/swap.h | 7 +++---- include/linux/swapops.h | 27 ++++----------------------- mm/mprotect.c | 8 -------- mm/page_table_check.c | 5 ++--- mm/rmap.c | 2 +- 5 files changed, 10 insertions(+), 39 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 91b30701274e..9a48e79a0a52 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -74,14 +74,13 @@ static inline int current_is_kswapd(void) * to a special SWP_DEVICE_{READ|WRITE} entry. * * When a page is mapped by the device for exclusive access we set the CPU= page - * table entries to special SWP_DEVICE_EXCLUSIVE_* entries. + * table entries to a special SWP_DEVICE_EXCLUSIVE entry. */ #ifdef CONFIG_DEVICE_PRIVATE -#define SWP_DEVICE_NUM 4 +#define SWP_DEVICE_NUM 3 #define SWP_DEVICE_WRITE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM) #define SWP_DEVICE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+= 1) -#define SWP_DEVICE_EXCLUSIVE_WRITE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIG= RATION_NUM+2) -#define SWP_DEVICE_EXCLUSIVE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGR= ATION_NUM+3) +#define SWP_DEVICE_EXCLUSIVE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION= _NUM+2) #else #define SWP_DEVICE_NUM 0 #endif diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 96f26e29fefe..64ea151a7ae3 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -186,26 +186,16 @@ static inline bool is_writable_device_private_entry(s= wp_entry_t entry) return unlikely(swp_type(entry) =3D=3D SWP_DEVICE_WRITE); } =20 -static inline swp_entry_t make_readable_device_exclusive_entry(pgoff_t off= set) +static inline swp_entry_t make_device_exclusive_entry(pgoff_t offset) { - return swp_entry(SWP_DEVICE_EXCLUSIVE_READ, offset); -} - -static inline swp_entry_t make_writable_device_exclusive_entry(pgoff_t off= set) -{ - return swp_entry(SWP_DEVICE_EXCLUSIVE_WRITE, offset); + return swp_entry(SWP_DEVICE_EXCLUSIVE, offset); } =20 static inline bool is_device_exclusive_entry(swp_entry_t entry) { - return swp_type(entry) =3D=3D SWP_DEVICE_EXCLUSIVE_READ || - swp_type(entry) =3D=3D SWP_DEVICE_EXCLUSIVE_WRITE; + return swp_type(entry) =3D=3D SWP_DEVICE_EXCLUSIVE; } =20 -static inline bool is_writable_device_exclusive_entry(swp_entry_t entry) -{ - return unlikely(swp_type(entry) =3D=3D SWP_DEVICE_EXCLUSIVE_WRITE); -} #else /* CONFIG_DEVICE_PRIVATE */ static inline swp_entry_t make_readable_device_private_entry(pgoff_t offse= t) { @@ -227,12 +217,7 @@ static inline bool is_writable_device_private_entry(sw= p_entry_t entry) return false; } =20 -static inline swp_entry_t make_readable_device_exclusive_entry(pgoff_t off= set) -{ - return swp_entry(0, 0); -} - -static inline swp_entry_t make_writable_device_exclusive_entry(pgoff_t off= set) +static inline swp_entry_t make_device_exclusive_entry(pgoff_t offset) { return swp_entry(0, 0); } @@ -242,10 +227,6 @@ static inline bool is_device_exclusive_entry(swp_entry= _t entry) return false; } =20 -static inline bool is_writable_device_exclusive_entry(swp_entry_t entry) -{ - return false; -} #endif /* CONFIG_DEVICE_PRIVATE */ =20 #ifdef CONFIG_MIGRATION diff --git a/mm/mprotect.c b/mm/mprotect.c index 516b1d847e2c..9cb6ab7c4048 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -225,14 +225,6 @@ static long change_pte_range(struct mmu_gather *tlb, newpte =3D swp_entry_to_pte(entry); if (pte_swp_uffd_wp(oldpte)) newpte =3D pte_swp_mkuffd_wp(newpte); - } else if (is_writable_device_exclusive_entry(entry)) { - entry =3D make_readable_device_exclusive_entry( - swp_offset(entry)); - newpte =3D swp_entry_to_pte(entry); - if (pte_swp_soft_dirty(oldpte)) - newpte =3D pte_swp_mksoft_dirty(newpte); - if (pte_swp_uffd_wp(oldpte)) - newpte =3D pte_swp_mkuffd_wp(newpte); } else if (is_pte_marker_entry(entry)) { /* * Ignore error swap entries unconditionally, diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 509c6ef8de40..c2b3600429a0 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -196,9 +196,8 @@ EXPORT_SYMBOL(__page_table_check_pud_clear); /* Whether the swap entry cached writable information */ static inline bool swap_cached_writable(swp_entry_t entry) { - return is_writable_device_exclusive_entry(entry) || - is_writable_device_private_entry(entry) || - is_writable_migration_entry(entry); + return is_writable_device_private_entry(entry) || + is_writable_migration_entry(entry); } =20 static inline void page_table_check_pte_flags(pte_t pte) diff --git a/mm/rmap.c b/mm/rmap.c index 49ffac6d27f8..65d9bbea16d0 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2470,7 +2470,7 @@ struct page *make_device_exclusive(struct mm_struct *= mm, unsigned long addr, * do_swap_page() will trigger the conversion back while holding the * folio lock. */ - entry =3D make_writable_device_exclusive_entry(page_to_pfn(page)); + entry =3D make_device_exclusive_entry(page_to_pfn(page)); swp_pte =3D swp_entry_to_pte(entry); if (pte_soft_dirty(fw.pte)) swp_pte =3D pte_swp_mksoft_dirty(swp_pte); --=20 2.48.1