From mboxrd@z Thu Jan 1 00:00:00 1970 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 C9D4BC0218F for ; Thu, 30 Jan 2025 13:43:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B97A280096; Thu, 30 Jan 2025 08:43:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5699E6B00AD; Thu, 30 Jan 2025 08:43:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E283280096; Thu, 30 Jan 2025 08:43:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 205686B00AC for ; Thu, 30 Jan 2025 08:43:57 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BAF67140D05 for ; Thu, 30 Jan 2025 13:43:56 +0000 (UTC) X-FDA: 83064236472.30.EE3B43F Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf12.hostedemail.com (Postfix) with ESMTP id 83D5D4000E for ; Thu, 30 Jan 2025 13:43:54 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=ffwll.ch header.s=google header.b=TGNNevSq; dmarc=none; spf=none (imf12.hostedemail.com: domain of simona.vetter@ffwll.ch has no SPF policy when checking 209.85.128.46) smtp.mailfrom=simona.vetter@ffwll.ch ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738244634; a=rsa-sha256; cv=none; b=rgy8jkTeSqtCihhPzjOzrirE7mH7iZU4DBUnWArXdF0llIluejaUumkEkhG0Wjr1eD+6JK Vme5wAKbF+NuimADCOVovb84JhJdU8YptTaHDoVvq3wsicbXjDRoyYAB/kPBxYS/UZPJJ+ MtMP1/9LgWi5JQhFhMkDzxqCg+PK/bI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=ffwll.ch header.s=google header.b=TGNNevSq; dmarc=none; spf=none (imf12.hostedemail.com: domain of simona.vetter@ffwll.ch has no SPF policy when checking 209.85.128.46) smtp.mailfrom=simona.vetter@ffwll.ch ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738244634; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ha66Iu6lse0aeaZq4IXkBsImhaaLmQUiLrfjz5cfLcs=; b=QNQFwWoTR/bKYdzgkw4VFHgotrujKPuxW0a+sc7g+69BPnLL0ghbtbVbVVfl+UQ41VUTUE aFokVxUXvJP374DGtFoUOpUymfl7z2DOeKntjUBwcRj/RFlWq3znuAp+CAyNwAGBRflnqF QL/loAb7vK9R6RQupxUETwHu+pV5zAo= Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4364a37a1d7so8101645e9.3 for ; Thu, 30 Jan 2025 05:43:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1738244633; x=1738849433; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=ha66Iu6lse0aeaZq4IXkBsImhaaLmQUiLrfjz5cfLcs=; b=TGNNevSqj5YzTz25MtFSZccoAXdumt3ErzY46P+OmFJWJybeziqr5BMcWEgUbHhcqV 3cVC6r8nIEzYhc7BECR3I6SqZHnX5OaVpLRwZshJJTR5mD3FVFO9yL2Q/1LeLOuV1UYj JVqBlwFMamgbv22tXZOngeAc+CfVfiHL5Xmpk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738244633; x=1738849433; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ha66Iu6lse0aeaZq4IXkBsImhaaLmQUiLrfjz5cfLcs=; b=aCFDgP1LJ3b5qmKyMdEn1XGIaUixNvmtWsNcaktsnUZMORobcAN5DSvz94meCk1yT8 fDbxiJwjQgzDX97UsJDXju6pJujOnJQP7sJZtsVNE9ihXo7v1rhEeRo7MSpEYVW27/pM X5OIrtyL7N0AVdH39QNjrm+T6SEj48Og/WsJn3HqEUV6SKei1M/wRLtjfwkgncNUrnd6 3F5H/7bJEBVLZufm5ndNslOzYSIV4TydBB9ht4GyrRxXD1V4CNw57818N7j0rqM3B2lJ taU6e9Cuq6uhRMN1hZfSltlmN/kkAve/IK4FvpyGvGmzQr3Jy4NaL98T05kjJGv2R+pX groA== X-Forwarded-Encrypted: i=1; AJvYcCVKZ2VCWNMd6bohL4JXRvH2c2kkPCiVc4p+yQiGt/RvGa5LHTf/nFO2zRC9ATkaCmi3PBH0j1CbbQ==@kvack.org X-Gm-Message-State: AOJu0YyboMP3vtfb/sEq4143jKaEPslFVb6VbrA+F+Es+m8evcnmjMpH T88OGATBjbgyp+Xi+SUpB6BmWLm5ZylBSAFyKwrhBCNHZeYMo2YkFXJ2zZaRpPU= X-Gm-Gg: ASbGncvADt6V2sfUDwlec+btrAegI0AMClJ4Hi8jEHVI0EB21XawrlPqGsdiS/o7LRq xXFxkswrQpAqMdYI3+9WhwGOxBs97LUff78GE+b+dSETxHy1BtDcblrevUv0CM5942nIfRedW0L g1EgOZpgdx4jn92IFejpx8crS2gxNU4zoTJJe3uXksBLYBSS8CgG1r8zKC6f5fSdl7+4gy9RQ0Q x8kjriJCt3jERM6e+YxrHGeLSQxoWOq+83torJNAVpa6qLrimlbAD+SxQvhWe/7m7vDx+kQ59aJ 9RONnlVkdHjgwb7ukiGnd/sjP/A= X-Google-Smtp-Source: AGHT+IGPwbF4Ytpnf417QGIV7aWx0XKtwsuKOqBPTmJvh2JEm7/wX2JzW1AoBcF90cds5JkZfLV8kw== X-Received: by 2002:a05:600c:4f83:b0:436:713b:cb31 with SMTP id 5b1f17b1804b1-438dc3a904cmr60626675e9.3.1738244632903; Thu, 30 Jan 2025 05:43:52 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:5485:d4b2:c087:b497]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438dcc2e384sm61161085e9.19.2025.01.30.05.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2025 05:43:52 -0800 (PST) Date: Thu, 30 Jan 2025 14:43:50 +0100 From: Simona Vetter To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, Andrew Morton , =?iso-8859-1?B?Suly9G1l?= Glisse , 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: Re: [PATCH v1 06/12] mm: use single SWP_DEVICE_EXCLUSIVE entry type Message-ID: Mail-Followup-To: David Hildenbrand , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, Andrew Morton , =?iso-8859-1?B?Suly9G1l?= Glisse , 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 References: <20250129115411.2077152-1-david@redhat.com> <20250129115411.2077152-7-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250129115411.2077152-7-david@redhat.com> X-Operating-System: Linux phenom 6.12.11-amd64 X-Rspam-User: X-Rspamd-Queue-Id: 83D5D4000E X-Rspamd-Server: rspam10 X-Stat-Signature: 8u6s6p9scb3gey9skrmi3eg67swpocwe X-HE-Tag: 1738244634-518553 X-HE-Meta: U2FsdGVkX19HHpyXeyAw8XNGmqVmsD+qaA9azaEmykRCHccnzH3QY3vSglxX8jMfxvH9s9KbFboXXvdbRRMFljP2250/NOzsMAO9zZEImy6auz3mo2JYiaSsuqcDCQCMCOifjZMF84fVXotK9qKCJMjqCE8hwz0/McIL2eqNapZ4Hi4TAP3z0uCgwAfrkdKVHl3mQqOxEj8PWhZQO8G6ETSiD3Qhz2cA9zww7LNnAtA5n1dj2PNKEh02zP9fnPiYz54XXPi6EOlCUKMuAV0SRkFMDFFUWItduwQ7Yg0vklpdKOSkuMxhuHIbX+8GJrmh7RD6udSP31Al7ZWE6G7aMbm0AURzLiE9QplkJs9C+xl/uVVeBeZl9tALAEoPmXCMBsknBqW8LySQhcw3EpfFjK4ZMaYDOH4ZRQdBdKT5SU3Yxm9yEViCO7aflBzZz+iTQ09rFPuXNUJLZ1DG8G9u7zuynur3v4MWsuoL/sPNXt6He7jLIbrHgH3Sva/Fx/NTBI5UxjRLTfVaQbK63nu7jXVfeR1sQA8/4rYLleXxpTJjdfhZzpfYttSFTCcYtWYp1ehtUZBoXWKsOuE24Wc+2PtEOoq7bmDF0RcolQqIgNm31zlHcMwofwbJwV3l7Fjxs1vTRR1AixrAwRqy5AuVExDUvqGgM/EIZWXjf8X/K5grJ+dOTf7sgpnelzblTbT98nqN4vVlKJCieFg0swqPL3ov/sGvIl8rLVRjWHYYAN1mX5vFUF64LuiwN3vx+Hs9BlB5bu7vexWXT880hxNzoPWAc7fMFVB/zubqTA+yed9pzq7k5exzPlZs+WbtdzMIXUmL5LYT37u2aveisx0ZPaSDwLFL9GUNztrzN3twik4/v0w7o/VFj/Z8SsafDG+T5ZHikc6+6tEix1tUyOnPdDrMv8+c9lR0nLDFKa7ifL+iDYsixLJC85/NAwh3hAMlzTLZUL+MgXyZPc0OLsa Ygdal8jp UKjtQULPXCGX5K02wuxfzUOlgBduiXRvuNvrZIOhqGH9VL2p3RvkK7VcJKY+kPUd2ZjROC37OeguBErndoWR/r/H5Z+IPp+JnjVnC24eTmSE9e/1TmSgEnBwBegQytarhTdFBWb5oy7U1ZYinG/EFV79qcQhQfRRX6sEbrO/yVn+KU3NcfmSZuP6ER2JTYmqPmwmvuB4fuiisPf8H4Cx6keZL/zBkuY50u/LQtpI1p0CR/D1nvp/BuZSCgXRwi+3MNnn4Jkuy5ynSRkj1jj7x7aQF7uRURAf4fEa1ujBTlugqSi/NJDldDO1Yf2E/i0/zSTylEVbMfSdrpm6n8epdRP0O30iv/LilR1RcB36mKez+RGGkWO2Xsf5gCg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Jan 29, 2025 at 12:54:04PM +0100, David Hildenbrand wrote: > 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 Yeah I really don't think there's a need to track that on the cpu ptes. Device should have write/dirty bits (which nouveau really should forward) or defensively assume the page is always dirtied when clearing a pte. Plus the entire point of device exclusive access is to support device atomics, so in practice it's always a write access that dirties anyway. Acked-by: Simona Vetter > --- > 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_MIGRATION_NUM+2) > -#define SWP_DEVICE_EXCLUSIVE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_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(swp_entry_t entry) > return unlikely(swp_type(entry) == SWP_DEVICE_WRITE); > } > > -static inline swp_entry_t make_readable_device_exclusive_entry(pgoff_t offset) > +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 offset) > -{ > - return swp_entry(SWP_DEVICE_EXCLUSIVE_WRITE, offset); > + return swp_entry(SWP_DEVICE_EXCLUSIVE, offset); > } > > static inline bool is_device_exclusive_entry(swp_entry_t entry) > { > - return swp_type(entry) == SWP_DEVICE_EXCLUSIVE_READ || > - swp_type(entry) == SWP_DEVICE_EXCLUSIVE_WRITE; > + return swp_type(entry) == SWP_DEVICE_EXCLUSIVE; > } > > -static inline bool is_writable_device_exclusive_entry(swp_entry_t entry) > -{ > - return unlikely(swp_type(entry) == SWP_DEVICE_EXCLUSIVE_WRITE); > -} > #else /* CONFIG_DEVICE_PRIVATE */ > static inline swp_entry_t make_readable_device_private_entry(pgoff_t offset) > { > @@ -227,12 +217,7 @@ static inline bool is_writable_device_private_entry(swp_entry_t entry) > return false; > } > > -static inline swp_entry_t make_readable_device_exclusive_entry(pgoff_t offset) > -{ > - return swp_entry(0, 0); > -} > - > -static inline swp_entry_t make_writable_device_exclusive_entry(pgoff_t offset) > +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; > } > > -static inline bool is_writable_device_exclusive_entry(swp_entry_t entry) > -{ > - return false; > -} > #endif /* CONFIG_DEVICE_PRIVATE */ > > #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 = swp_entry_to_pte(entry); > if (pte_swp_uffd_wp(oldpte)) > newpte = pte_swp_mkuffd_wp(newpte); > - } else if (is_writable_device_exclusive_entry(entry)) { > - entry = make_readable_device_exclusive_entry( > - swp_offset(entry)); > - newpte = swp_entry_to_pte(entry); > - if (pte_swp_soft_dirty(oldpte)) > - newpte = pte_swp_mksoft_dirty(newpte); > - if (pte_swp_uffd_wp(oldpte)) > - newpte = 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); > } > > 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 = make_writable_device_exclusive_entry(page_to_pfn(page)); > + entry = make_device_exclusive_entry(page_to_pfn(page)); > swp_pte = swp_entry_to_pte(entry); > if (pte_soft_dirty(fw.pte)) > swp_pte = pte_swp_mksoft_dirty(swp_pte); > -- > 2.48.1 > -- Simona Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch