From patchwork Wed Jan 29 11:54:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13953678 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 C8A24C02190 for ; Wed, 29 Jan 2025 11:54:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26BE7280015; Wed, 29 Jan 2025 06:54:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F439280016; Wed, 29 Jan 2025 06:54:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0EB5280015; Wed, 29 Jan 2025 06:54:45 -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 CB1AE280011 for ; Wed, 29 Jan 2025 06:54:45 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F22161A0C6C for ; Wed, 29 Jan 2025 11:54:36 +0000 (UTC) X-FDA: 83060332152.20.968791F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id C27B220004 for ; Wed, 29 Jan 2025 11:54:34 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LKUWO0PY; spf=pass (imf13.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=1738151674; 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=bwRdkJe7S5eVWCBWfyg7xh/8u+L2oGZrd41rkCVbduE=; b=K/SQFngVNcaFZFdpie/zDU8uFDLgBky8JwDkh0PfSml70U2/lyrBv6zZjI37/Rx4aKHeBA Tk0U4dWME4lIBk705KDvLPtS1xYU4vBO7cw3qoRT113bZ/4whOrbQ9al1cuiBQq/UkXRQs 67k3e7KkuVtsYt1vJCwX0LYrV7NU0Vc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LKUWO0PY; spf=pass (imf13.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738151674; a=rsa-sha256; cv=none; b=XJsi7VvUyUUA4HuQKzIfWlgaiKFMT2N67eHqYQ5tYsXUGWh/jTrnwSkOTa+GUgG3A/v5GD r8Ezu+WWbgJtaKgbmPmq4BENq9bdKUdgRBpphdJdeIR8b+2unanM/6SmZRE35wGnMzjnZP mvuEW43IegW60Unjcsw1q6nTovVtLeI= 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bwRdkJe7S5eVWCBWfyg7xh/8u+L2oGZrd41rkCVbduE=; b=LKUWO0PYGzc9dUy1UErMnP8OYzjxyiNMxuix/cKwbPyIYHzTWSCZCK/Ib22baSZ9WegrhN ldpZLa/hVFB859ju/s4ficWmRE3y6m/T5i8guJeslw1W7X2ECh7t6EfQIgmSCK2Y2tpH3O MtgNE6Qmg5ZnLmmDXl36+UQx08cRwOI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-501-3XGaISYtNHOiwu_mg_4GPA-1; Wed, 29 Jan 2025 06:54:32 -0500 X-MC-Unique: 3XGaISYtNHOiwu_mg_4GPA-1 X-Mimecast-MFC-AGG-ID: 3XGaISYtNHOiwu_mg_4GPA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43651b1ba8aso46674425e9.1 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=vKItgidUhEzil73THPnLCmXNbg4G4GecLIF3D37P33xT+FwPgfLmtdHrmv9qAVYs2y A45EVuXMAiUFEeFvjxsTN1EAEf6j3a2vff6xhHvFG3/rGUA7+CX0A2suffc9l81a1OxH vdvVQQn4V1KDdGvnB0zonjjxQAFNPIYLmmA3DwvcgtEgYSULz42jQk7IJQScNsgTjqz6 yYFN/7j51wPzNWxQMqYH4W1bVQlLYaiiGYT3T47Zk2bqdMznVEqp3yhaMy9QSC8KHbuk IFAOtsd+dIt7wjfwAcJai8LHLrCMx+MMf+bCG4CdLTHDJtwbBg4Hr10oHyAPSHk06XtB GQqg== X-Forwarded-Encrypted: i=1; AJvYcCXjr2s8tz2Bonky+W/DLK66WYbJU7vHP/AF7a2Hxw5mxDZ8obpaMNjCMVP6vXKi7eBYZPpci9I1qQ==@kvack.org X-Gm-Message-State: AOJu0Yy+4pkrAy7F4nNuNCnZCU64jQz4jtnky+q4CjjDmE6pBxICU6ql fHxj0ca9e2RfyT5RvFA1x7xVV3HQxZ/x6kJMUQ2+8GJ0vZ9txFEWU6MY4T3UkXYKcXhVSmKJaEU ZytNJyfvLIOZO+oZdEGyyx94KCLmU4cFIoiTU6ZdsZY7VA04G X-Gm-Gg: ASbGncsEn2Aj1Xtr9SENGsoIlTdmaNZhh1Pn28t2ufY+3c/yq7d/btb22kJXlbM2a61 e13n9DfaLx2jeem5KAfOLjTAuROW3rl6zUdUJ52p49hXrp1//w28UlE6sDxKbAP6rVoaStOF3lE 0yNdUbWEV0QRWYLLAWbdFfQHVJQVlsgA4rvV2iE8e6QaN5geHao74yiy9Piscm7o2xUJt1JDgDA 3cdzaq+TlBB0eMYMKcwFfxh6N2upC+aH1OZiwlMRgt3o0kpBmbPQuwU7Sq5rTHUkzxa9++557AV UiicUe21NYcpd8PI0bZws51tswibjO7yTOeMZT3nf8aRuJG0vfMGN5yobY17vNME0w== X-Received: by 2002:a05:600c:1c1a:b0:434:f9c4:a850 with SMTP id 5b1f17b1804b1-438dc3c4623mr25664845e9.10.1738151671649; 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?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 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> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: HFEw9AJyuhojI5F5QYZl-dixnryWrDMPAiFZfUGD2ms_1738151672 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C27B220004 X-Stat-Signature: wo59ksm79mnxhwei59y8kxkeaquep3yh X-HE-Tag: 1738151674-76876 X-HE-Meta: U2FsdGVkX198GFHpjackiEiF4CLXh/UkvRftPslTj3KbOSXACseDKPg6YuyaNRtZ5IDplq5VdFP9nnYBrH9x/kfimmqd5PuJspFISrnLsSSN6EN1pqfsM+RYu6HZfQxYF9gTvm3wcZWIEbZixMMIwi4YVrdWhL+e5DOYiI2g3tzNxNA4IYDMHtHu1lCw3FSXO5xRoU0Ma657m+bbDrLD+V4ghTYNRaVRS5DgppehcEzuRXLN/V0bZT8L4kHxR7XatJEHPOicHbQzfxgXNh5ZQdtU6kN/lAxHQrXEPFP6/vkpVe6P1M77vSmbqr7VAIpAkfO1u5q4cnW2Ex/VqQKCCh5vuX9DN4zXbp20vXMHepu2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qR0lE02BUKn4E+S9UyxOG6rFWo3TdQ0+4+PFeAi115Vm47q6kfHWT/yk08WNh68wjRpAdQLDADA== 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: 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_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);