From patchwork Wed Jan 29 11:58:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13953689 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 D62DBC02190 for ; Wed, 29 Jan 2025 11:58:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D967280061; Wed, 29 Jan 2025 06:58:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 686D428005A; Wed, 29 Jan 2025 06:58:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 529D7280061; Wed, 29 Jan 2025 06:58:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 33FCD28005A for ; Wed, 29 Jan 2025 06:58:32 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5EBBCC0CC6 for ; Wed, 29 Jan 2025 11:58:25 +0000 (UTC) X-FDA: 83060341770.01.7285572 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 32E3F140004 for ; Wed, 29 Jan 2025 11:58:23 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IX9lNX0i; spf=pass (imf23.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=1738151903; 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=FOqcQk5sbfQYMqiwFwVZu0o4Vgt4WnJhwl3OPDX2fpI=; b=4+NYaz611GrxAhQBl4tWYF/Rkovo3T8ep9wuyvmepAsEylIv1vC210GgpJe9AM7s4eAK2U Hy79jcgsGeQOomIJthGsJK31JqU4AgFighmDwFtxzp7qDYWx2d/hcoQmBxHbGlIXXrQ5m6 PiKM09+U2DqmvQV+ni4fGgBd5IA8DS4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IX9lNX0i; spf=pass (imf23.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=1738151903; a=rsa-sha256; cv=none; b=RFhljrjzfUhnbBahAPZD6spYa8uflYPl+ZiwgeUm3mxraFLUGm0dsjS/YwzwRNS/yfSdF/ lCzs8dhbAPI5HZOramKLguviQ3/KoBZ2VilEZm3zhqV8xvTOIkg9QYLfIyLE0O35zt+DYt w5nyJUwDUGbKeEgn1Tlleqme7jE1ChU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738151902; 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=FOqcQk5sbfQYMqiwFwVZu0o4Vgt4WnJhwl3OPDX2fpI=; b=IX9lNX0iCgdQ58c+TGfq4L1owxkb+zKErVXudQ8awVwla1aP5lKEBcjWXcAOUFXRVlQTBE QZeaJMH8c/CzWMG+3PnXvS2HkxAm2Q64uWpwqaEU8nWRzNZnTV2Txn4FwQz/FmEm2J7r1V AldxwSVUrWzBIHcYtQyzVJbd4tivNv0= 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-193-kV4BleaOMTqOmJzW319f4Q-1; Wed, 29 Jan 2025 06:58:19 -0500 X-MC-Unique: kV4BleaOMTqOmJzW319f4Q-1 X-Mimecast-MFC-AGG-ID: kV4BleaOMTqOmJzW319f4Q Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43631d8d9c7so3373875e9.1 for ; Wed, 29 Jan 2025 03:58:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738151898; x=1738756698; 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=FOqcQk5sbfQYMqiwFwVZu0o4Vgt4WnJhwl3OPDX2fpI=; b=AvDxnvaIXf0M5ZyZNItryPZquXRcv4DsL+jOgQN94HTL5kb+Z7S9lHSeBk/gChYsLI f8YgLSxmqlVmuA1roiKqjkH1UqMb9/j9ns2W/aFhGXu1/rWEDnDEJYS+dCxsGmqf+Ry7 G4or7VolIB6TC6ujqwPcVVBThbcWVQtp4FQTbq4LYuVNDuWsZc3ovKXjcgbrNlSSBUEB gsr0d1BFbtMkru/wnW/PWh3iIlQqs6SS1sKQi3k06zYNRdVvZgqkoXlHd4AGLFufppXV d8q0bUeccFsfDkGv5cU/Fv+rSMrtvjLMNrr2QImuHFFXasYJroOc+nq/RZKvPqFSfnQr zosg== X-Forwarded-Encrypted: i=1; AJvYcCXCaOWnh1aECqCWQtUBwQNkYuQJCquSMLqGk+DC+YHZiav/9u0G/yJf17mumVqDECPSVu5mU0f+nw==@kvack.org X-Gm-Message-State: AOJu0YwpDR8AX+6/0VuLvucUBiaQ0LJcJFCkgGwElw9BGzg9DRpQig6e 6FEUa4aWS/rE6yjPk6bPkLEtBpPEObItH5fGjAbpv2YzWEsc2K1l8cqewbpdDTUV9B2AUBX616S oY3ZVwBwuRnqWXqh/R4AcsHQbSt5LxI5wJy+onRDw+VfruEDi X-Gm-Gg: ASbGncstbh11mfCp1jDRbWBwpFTc+/4e1aKvxH4ub9jTMFEQuzrKfu6oggl0WT9tlvU 5oH4GWv7wrkYt5Y5YlvPgmXI/oboHJw478vaQle5V25qpG4Xv2nka5MeQ2rwIciGgwRxf1sFCY2 11iULuC4JxAw0f8ciPzvqPTVJVf51eM8do5hhqN1WzHMGDMUwqYp56E/XdXFH8RacYAiRzKvkiD 2nXLK3SPcEtNK9kQgMrx2d6oO/vcmxcaYnuGFEzm5/UvfvutWnmz+6Krtk6rfuIP97uNecvOyZB prn4mpUXTNp5olUR5w865pPeUqskfgRrDA6rq0IZ0LyOItQuMKrvApSwTof5EzAoVQ== X-Received: by 2002:a05:600c:3d87:b0:436:1b0b:2633 with SMTP id 5b1f17b1804b1-438dbe9a124mr27335695e9.9.1738151898326; Wed, 29 Jan 2025 03:58:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUOJXNPPQ6xLco9EGZUl9hRUezUN+y2Deyf0uuUDDMY6E4w4fKpt4O5zyjSgxt4LyQtnHPOg== X-Received: by 2002:a05:600c:3d87:b0:436:1b0b:2633 with SMTP id 5b1f17b1804b1-438dbe9a124mr27335535e9.9.1738151897999; Wed, 29 Jan 2025 03:58:17 -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-438dcc33e04sm20207605e9.29.2025.01.29.03.58.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2025 03:58:17 -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 4/4] mm/memory: document restore_exclusive_pte() Date: Wed, 29 Jan 2025 12:58:02 +0100 Message-ID: <20250129115803.2084769-5-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250129115803.2084769-1-david@redhat.com> References: <20250129115803.2084769-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: BGSBP6ocL7HuA2noY0aJTHr1dnFKuacMJuJ7o7IIFHI_1738151898 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 32E3F140004 X-Stat-Signature: 3icegn15qn5eg5w6mda37mbjoxt5dzsg X-Rspam-User: X-HE-Tag: 1738151903-729878 X-HE-Meta: U2FsdGVkX18xwfWmiQAKhfd7s223McT6GzBiX/S5tvzL866R7oRFS28oHGwKgQJzL0eGWZi5vF4zVcUqjwhn828R+pgdbWoeXyxtFK2l5ufB1CXvTcmWQLMK2DPfWJyIgFcJ0RchnzMhK8dV8AYHxGwdB8PJ4PuGlRekwyu/OfLARADrTLbzk9Kwo9er2c1orMo2S9eAt7IXYLYVTdb8dH9fHHaX6BjbRxlY6CVwYJaXr3MWCt2RYdID3R8tVaHV6x2FLDsDrXKeNJED904JaZZ0MnQOpp+tb2vuOfkHWNLb7MD5F/XM8BZbAnQesRn4ZSmAK3DP5Ju4C2swaT0MW5FSfUUinspbrhKTb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1C5ERf+iVpXPlaRlQGf9kjUGA3IQbea4qCtm1K88sBlQjzOD0czRugS88xxsNIuAnwko+KNfro/U34ZmlcyWPnP/WW1W0exHXqlffzI7ig== 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: Let's document how this function is to be used, and why the requirement for the folio lock might maybe be dropped in the future. Signed-off-by: David Hildenbrand --- mm/memory.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 46956994aaff..caaae8df11a9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -718,6 +718,31 @@ struct folio *vm_normal_folio_pmd(struct vm_area_struct *vma, } #endif +/** + * restore_exclusive_pte - Restore a device-exclusive entry + * @vma: VMA covering @address + * @folio: the mapped folio + * @page: the mapped folio page + * @address: the virtual address + * @ptep: PTE pointer into the locked page table mapping the folio page + * @orig_pte: PTE value at @ptep + * + * Restore a device-exclusive non-swap entry to an ordinary present PTE. + * + * The folio and the page table must be locked, and MMU notifiers must have + * been called to invalidate any (exclusive) device mappings. In case of + * fork(), MMU_NOTIFY_PROTECTION_PAGE is triggered, and in case of a page + * fault MMU_NOTIFY_EXCLUSIVE is triggered. + * + * Locking the folio makes sure that anybody who just converted the PTE to + * a device-private entry can map it into the device, before unlocking it; so + * the folio lock prevents concurrent conversion to device-exclusive. + * + * TODO: the folio lock does not protect against all cases of concurrent + * page table modifications (e.g., MADV_DONTNEED, mprotect), so device drivers + * must already use MMU notifiers to sync against any concurrent changes + * Maybe the requirement for the folio lock can be dropped in the future. + */ static void restore_exclusive_pte(struct vm_area_struct *vma, struct folio *folio, struct page *page, unsigned long address, pte_t *ptep, pte_t orig_pte)