From nobody Fri Dec 19 18:53:03 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 789FE1DE892 for ; Wed, 29 Jan 2025 11:58:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738151903; cv=none; b=YWWY4T61CDqYAy5xoy+w1cYlPWtjOiz8uCWE7k92x9Mryjw5KgjKd88jKxSq15ql0U0dPGDfYYGspIWzywizRXpX8Epk5ih4FEHFJL1QtgR8zw1hln4qyXTgbl4lpiQb2BPfaylBs4JzJehsczvQH7/umreo/Y5is77yenaKzsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738151903; c=relaxed/simple; bh=9PHBiuSbQfK/gtAQxmhDt+JDCvJOGqXhhiGP82nYoCo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bzuNFdK1eVuH/4srIWbbKdVFBSkU9PI6Ct6zDEbmXrdccYSv78yCvPfxRjbSB5GLe75/EiyRyVLWx3DPjzC2YQsHc2WSHxNv/xuVUXB9XdTpYrEGGc7oEGHL58D4bHBDkdQ4L0HPaZfc7vBx6G2iQOpHQ6YLXJKpE66tYIVkcmg= 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=gMr8HFVc; arc=none smtp.client-ip=170.10.133.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="gMr8HFVc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738151900; 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=FOqcQk5sbfQYMqiwFwVZu0o4Vgt4WnJhwl3OPDX2fpI=; b=gMr8HFVcJxKmjbJtkRH5yYQNFiu+zGbYkXCvDU2GOw937a/JXRypnyGGXSHVHpAmECcrN/ UBmA4626jYNkkxJT2MSCdjeRdkTefZXAfVlNbj/215MglLlGDTr6df95Zpz+SM48N73Hm6 GpQM4Px0kTr/PTHcqVgNbCoXgrgGqOk= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-fUi_F_FjOrGn_a2qoRG_aw-1; Wed, 29 Jan 2025 06:58:19 -0500 X-MC-Unique: fUi_F_FjOrGn_a2qoRG_aw-1 X-Mimecast-MFC-AGG-ID: fUi_F_FjOrGn_a2qoRG_aw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43631d8d9c7so3373895e9.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=KU2KdwlJz7da9ZnyVicenOaPLZd0OCihabfKBMUD2cpM6jyx5KPTxkX8z3hJG5rJKi yX02Z7yPZ4C0Y5ztjkx3KWrEwVkouYglxoy0/DBGI7TR7hv9JoFcNcxvkethLaNtYNV3 SzzwskjLufsPZeZvVEZoMa2QuTzwYpqClzcpLI3lMixyEy3xidehNH/GD89jAeK7CMWI oSoqUu+0fXmfzZ6LAvPJquiwZ/D+RpDR+u4q2Jjc/Tbm6CVemr+3dnuhlYVcx0vtYdRS 8c5CAVU2QuaI0G3TWkLAF/WsYAohphfrHXVX91l9HpTxQ1H9Ca1xZQdLXctWnE32v7cl tUjg== X-Gm-Message-State: AOJu0Yy1vpAcrRgaAPxe5qPp+L5C0CJsDpjdWHPN4LobzkqH05Z7USJL 7dmPib3zleczcmutfbI9MBfOM7VDHFr+2OEvWP5QcpcIkutF0jeugbuNbFWdRzkBMs9wpR3p7c/ ZjAwhTv4N6cAzJW7e4Ovft/ts8PxYlJXLOT0gu7w0UboFqSFFCC0jtCIktODV/bwstCZdzJrBFr cl8RDe2Mg+LF6+89gBU/PSgQu0nQ1xGj0+enBSu2uMUM3G X-Gm-Gg: ASbGncts1OXweSYzpqRP0FCU4vwtDEaVrZ+1xLFLEHu5x2YuPQUhoEemnpuQc08VxZz deZSQUINca4cKwI24Pmk4zWNRYC4ZRYqALqwwtlJ/xheYOOoZEXooSQy/wUyW5x/Qf9QXJ1SKTj n/a2WYTwrBp0TAM0FyHkj0ZNECeAYFgM1f3vtetpl5KuL/tLkRBBOFDE/RVJPwlbqKDvJbSGeoo NQ0M2JjwpW7+CS/28kxQtWLJhUlK233tMTQ2tsqqeiy6PRfjNrpr47gXmyBPDsv8U2CNc2w8KTn I/s4SJt524MI81V16zoGJafQ/tl7LCTFhV0FbThO/ed5WVRLAwMVR3aQn0Lv6ZUDpw== X-Received: by 2002:a05:600c:3d87:b0:436:1b0b:2633 with SMTP id 5b1f17b1804b1-438dbe9a124mr27335905e9.9.1738151898366; 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?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 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> 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" 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_struc= t *vma, } #endif =20 +/** + * 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 dri= vers + * 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) --=20 2.48.1