From nobody Fri Dec 19 02:50:38 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 AB75521B9D5 for ; Wed, 26 Feb 2025 13:23:04 +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=1740576186; cv=none; b=HZrvtpEnxIXmxBEO9/KblXBUraiA5HYSrNSizd7TIONU/NGuCrBMCT688l4ORydFWZ36CQzTzoxRniK1pZjwYnOtBiRuf30Vg4s+m0yB501Npl6eRFFcpxK++2MHSqn7l+ricWEm4TIrjreHS2NH/Jt7r6K50LkvvxUdNXjV+io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740576186; c=relaxed/simple; bh=pEh/GEr2ugLHRSDwWQQUGis0JRuTDl3y04fgg4bL7eU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nE5MjZIjwp97mzQ1466wiC8IzjHfQwjOjP6tiRskt/17S3OJeYtTJEPrSMErprPu+YOimPoy2/xUs1cinmWoYFypWznsSAlekT3UWnRKOVhW7AyV5ebU1KNpyJ0Poh9AKaI/oB27t13R3kVVLkjJ2zHElAOsZq0yoQLpCAp7nT8= 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=JguCOjuJ; 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="JguCOjuJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740576183; 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=B6orXFeJGAvu/Rrohb/dX/LYlUkQorCUoMUzPFZb2AU=; b=JguCOjuJWlTBkTWIaOu9sYLBEAE9tBFBVBbv5YmAf+RvbjmqXQ/qQVoZxaXWfYZ1xx0VB7 m54bT1beQeX4Avc48+FP0BSax+hnlKCmb7lXgA7JVMQ1vxL8MoB4hKRpftKRQ5A4uqIpoq zVaS5kUWk4dZDP+fqVUCb/XOr6al3Bw= 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-656-RO3QIkfTPz2kyZ4YaHzAmA-1; Wed, 26 Feb 2025 08:23:02 -0500 X-MC-Unique: RO3QIkfTPz2kyZ4YaHzAmA-1 X-Mimecast-MFC-AGG-ID: RO3QIkfTPz2kyZ4YaHzAmA_1740576181 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4399a5afcb3so62318385e9.3 for ; Wed, 26 Feb 2025 05:23:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740576181; x=1741180981; 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=B6orXFeJGAvu/Rrohb/dX/LYlUkQorCUoMUzPFZb2AU=; b=VMLZS5OHbtOMqAxFQiOrTiHAk7ZxxdBBG9NYC2pY0KXGZIG3SKypD/UhvZIipPeFwp 0w8mGa04H4ZSqXZD4rukojsVkohg3ao/toLa2YmFatise3sI6xdypF+ajuFR1/qyc0Wh J5znomGPqbH3HD9M0cemWUFMKhzDfwI3eXbQJeqslSqIqcMTEiSJ515oLgR0dLV1JGKR FZGT04yhrt+sZzW/2Z4SmYudyB2mX5zqhWWPv9oVgWyrXGuwlHpzZW10s4cc0SbCMtZX gMlauIDGkCX4vmof0EOHGMr6KBuyCT1Upg6mROEwLdZMNS1/LKFbM7dYHi6SSf+ueuoO 78Ow== X-Gm-Message-State: AOJu0YyTRE+fsAoYixHLX7wWM6g2athsWK40eiNKiwtaV8fFdVmMeX7s YE09M7Xrip/9FIknzgiwbMAUDP6GJ8aCqsJB/mBIIUeEzESkPSnbxuU3hLyFl5d/7zShvCIrIqI F/xSyKKRM5v1/zM29daYKrkNhKrFxHS5aNr54gjbR+/eCIepPTRLK1wUeDH1X1dw1yro2LiqAO3 OxsxjzX3UvNZQI1hcGS9Lbco1q1xcIAoJxK5IjP7gAmNtU X-Gm-Gg: ASbGnctU+4jfciu8yJfOw0EKFyoRe7L0On1SkrHv+G6D7hnJotq6EvLRfhpA/MUaKc+ JIwdGa6ADKFtnQdyKeB7m6LFRoAHGWYhofaXk7T7faayVf3y/JEBHfgLpmFA/PyKFH5fB1SryfQ Y94LZzsFGDjA9lt94PtrI67ZdbJspXRxUOtDprSbyvZUEYvQwx26o7yXOAW3bM1wrcRpJquv/JP KevotuUK2VFD+HxKo9bAB79KcHBMPq2rsXh0zWbWLX0LoeFk64Fe9aolPVWlJ0M9mINbz9In3zC oSFm9UIO7xe6YRj51c3S44i53h//4wFKdh1D/8//KYrlo5NpYBk3KFzQr57i3bsm8oqPejPjgG1 7 X-Received: by 2002:a05:600c:468b:b0:439:9eba:93bb with SMTP id 5b1f17b1804b1-43ab0f42a24mr78452235e9.18.1740576181095; Wed, 26 Feb 2025 05:23:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTKTUVpjblmKPNOofPuJhCfQ+I0IhzFCw2t/VamjME4II9+wlbxcBhKnNzq4bwr4GFZqWn4g== X-Received: by 2002:a05:600c:468b:b0:439:9eba:93bb with SMTP id 5b1f17b1804b1-43ab0f42a24mr78451845e9.18.1740576180695; Wed, 26 Feb 2025 05:23:00 -0800 (PST) Received: from localhost (p200300cbc747ff009d854afba7df6c45.dip0.t-ipconnect.de. [2003:cb:c747:ff00:9d85:4afb:a7df:6c45]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43aba543fdfsm21554525e9.31.2025.02.26.05.22.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Feb 2025 05:23:00 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Simona Vetter , Alistair Popple , Jason Gunthorpe Subject: [PATCH v2 1/5] lib/test_hmm: make dmirror_atomic_map() consume a single page Date: Wed, 26 Feb 2025 14:22:53 +0100 Message-ID: <20250226132257.2826043-2-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250226132257.2826043-1-david@redhat.com> References: <20250226132257.2826043-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" The caller now always passes a single page; let's simplify, and return "0" on success. Reviewed-by: Alistair Popple Signed-off-by: David Hildenbrand --- lib/test_hmm.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 155b18cd9f2af..5b144bc5c4ec7 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -707,34 +707,23 @@ static int dmirror_check_atomic(struct dmirror *dmirr= or, unsigned long start, return 0; } =20 -static int dmirror_atomic_map(unsigned long start, unsigned long end, - struct page **pages, struct dmirror *dmirror) +static int dmirror_atomic_map(unsigned long addr, struct page *page, + struct dmirror *dmirror) { - unsigned long pfn, mapped =3D 0; - int i; + void *entry; =20 /* Map the migrated pages into the device's page tables. */ mutex_lock(&dmirror->mutex); =20 - for (i =3D 0, pfn =3D start >> PAGE_SHIFT; pfn < (end >> PAGE_SHIFT); pfn= ++, i++) { - void *entry; - - if (!pages[i]) - continue; - - entry =3D pages[i]; - entry =3D xa_tag_pointer(entry, DPT_XA_TAG_ATOMIC); - entry =3D xa_store(&dmirror->pt, pfn, entry, GFP_ATOMIC); - if (xa_is_err(entry)) { - mutex_unlock(&dmirror->mutex); - return xa_err(entry); - } - - mapped++; + entry =3D xa_tag_pointer(page, DPT_XA_TAG_ATOMIC); + entry =3D xa_store(&dmirror->pt, addr >> PAGE_SHIFT, entry, GFP_ATOMIC); + if (xa_is_err(entry)) { + mutex_unlock(&dmirror->mutex); + return xa_err(entry); } =20 mutex_unlock(&dmirror->mutex); - return mapped; + return 0; } =20 static int dmirror_migrate_finalize_and_map(struct migrate_vma *args, @@ -804,8 +793,7 @@ static int dmirror_exclusive(struct dmirror *dmirror, break; } =20 - ret =3D dmirror_atomic_map(addr, addr + PAGE_SIZE, &page, dmirror); - ret =3D ret =3D=3D 1 ? 0 : -EBUSY; + ret =3D dmirror_atomic_map(addr, page, dmirror); folio_unlock(folio); folio_put(folio); } --=20 2.48.1 From nobody Fri Dec 19 02:50:38 2025 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 542BC21CC40 for ; Wed, 26 Feb 2025 13:23:05 +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=1740576188; cv=none; b=POcdSeHqgIpz3YmcfQaotyxt79txwViZSqZfNN7rLkCBS1rK8REsTZAPQ/JQ3V7ycMwIFw3n8NuOZ4EorNid2HB+z4Ienr2Ftk/Yn4Kw4Z4PXRn5C19rmeovI5wpQBNOWAz8QNfT+u4t9hGCemQOS2dAmzBLwzMFbmnR5nc9bOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740576188; c=relaxed/simple; bh=4OiIV5QxsFJTk6e24Gas31Y5wOcO3/LK71vDpcBsZvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=its5/3R34bFYKiqRbUOUDRsNc468dzm7krs3VRvj/0J6zknml7CdVYJNgOZLKs6/SWnhnPJuHg62C3J8RuhyzRv6uh4cMhb3wZAB+3DuUJyMOTm9obZL1kPz3iN4fDsdlo0/6xZsj55B30g2h6OG89dnmV47391mkCK9iJiMArM= 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=czH4shhU; 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="czH4shhU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740576185; 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=5HdgkEm0fuuu6fB71h9i6WnSRavi+zx73Ldo39ZrlKw=; b=czH4shhUkxVPZj3XPzriVIylgqMbsPPCWVv+hUhdIPwJ/XOmZ2ZXzf9pQ5DNqbi6PMYdet b9FDpSK05oB4+/ZBtBZiGnIDbHOzoMPIzs3xrj2VCeVzcHzioTM3cwoz8UiZfrodluZyoX dZ0f2prWIJa0v3eVt5nOMfYMdlrjBRU= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-73-vZQIL6F4MyuiI7yRwaMF6w-1; Wed, 26 Feb 2025 08:23:03 -0500 X-MC-Unique: vZQIL6F4MyuiI7yRwaMF6w-1 X-Mimecast-MFC-AGG-ID: vZQIL6F4MyuiI7yRwaMF6w_1740576183 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38f37b4a72fso393458f8f.1 for ; Wed, 26 Feb 2025 05:23:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740576182; x=1741180982; 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=5HdgkEm0fuuu6fB71h9i6WnSRavi+zx73Ldo39ZrlKw=; b=JlHSLMGYLwUDa2lY3Pjsphkf99Qx0XIPRk8rWP4ezW4YSZ9AH4NulR+YeSPbdEAPiP hz2E29H54aq83pzl7+vpmiz/EmS5mopgj3uNgf4FtCLYhcblT+dOlEcy6PYB5jXd8CEA ZaIrRVoyw24EQ13x6YLEpYLVVgx9DT54mfmmuGPelvFqO2QoF0CVQjuBil6Q9KuMbtgS n+DTTkzGc5R0eADoEmdoQzhoA08rwXB6pOK2lJdaisgfucigxF6DHHwA3/8Jg17Jmnut PPVKjEALxygDzZaiwhBdHFZgURfuKi+lPQ2QDFn22ZN8+1N1nu15IRl4NJrTIyJ1BqoR zgdA== X-Gm-Message-State: AOJu0Yy3FAxFlmxgSjtZiTRYyvJYLGf/r9P8Hz/QvacYhGI6iY8hEJRx talFglZ12BfWfDXl7c9j3SrHVSDGklK8rrif1D3Ef1hO1tMCw/GO4InzpMmq/S2M/McrQZdL27+ /wK5lH71mWxMffsSAgMf5eRgsAa2v0CCieenoRpQ2JtWO967M2ugpuCFiKaOZH977+vraEDx19E Ns4TTPaP7yrNeHwhqjxI7nfcQojAxR2WmLNmoUKwdGPDrZ X-Gm-Gg: ASbGncvAcX0TXg6SdvuOti8AWOmaHbdJWaQq9kAwCvSVu2M2dt0gMCUuQDZyuwjLARF 9SUfKbqU1DV+wC1L5Hjg2WQX2o/s6fG+BXNxUMU5UCitf0fr/pFGGJesdna97u7Af9kjIgi13zk N9kWsjFrPEKJBaIEjMGjxdb+zYJXUw4XQqtoXdvvdAmBIlyiWkWffY6UdfNjylshG1zoej2PNXo fJCwBMRqrZKA8OwQxD/aTp0qQSX7FqU4mkmtrXjMZq8mN0G76W57eVpfIn3SKU41F29s80sGVFO suqomYc5K4fFBn6X72FuGPqjPllXbftt/JHDaOrmmMG3K6MqM98lru9YqPaJJbpFSiPWacDov43 N X-Received: by 2002:a05:6000:1f87:b0:38d:ae4e:2267 with SMTP id ffacd0b85a97d-38f6f3cd3cbmr16504304f8f.11.1740576182668; Wed, 26 Feb 2025 05:23:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGt1VK8Qha+1uMsU2pDIjFygOFfguhh8q3wgw54Ai6Omd0rtqWpAarTyKRjr67o5nrATFNkDw== X-Received: by 2002:a05:6000:1f87:b0:38d:ae4e:2267 with SMTP id ffacd0b85a97d-38f6f3cd3cbmr16504283f8f.11.1740576182313; Wed, 26 Feb 2025 05:23:02 -0800 (PST) Received: from localhost (p200300cbc747ff009d854afba7df6c45.dip0.t-ipconnect.de. [2003:cb:c747:ff00:9d85:4afb:a7df:6c45]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-390d6a32299sm2059535f8f.55.2025.02.26.05.23.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Feb 2025 05:23:01 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Simona Vetter , Alistair Popple , Jason Gunthorpe Subject: [PATCH v2 2/5] mm/memory: remove PageAnonExclusive sanity-check in restore_exclusive_pte() Date: Wed, 26 Feb 2025 14:22:54 +0100 Message-ID: <20250226132257.2826043-3-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250226132257.2826043-1-david@redhat.com> References: <20250226132257.2826043-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" In commit b832a354d787 ("mm/memory: page_add_anon_rmap() -> folio_add_anon_rmap_pte()") we accidentally changed the sanity check to essentially ignore anonymous folio by mis-placing the "!" ... but we really always only get anonymous folios in restore_exclusive_pte(). However, in the meantime we removed the separate "writable device-exclusive entries" and always detect if the PTE can be writable using can_change_pte_writable() -- which also consults PageAnonExclusive. So let's just get rid of this sanity check completely. Signed-off-by: David Hildenbrand --- mm/memory.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 567b45e5d149e..507045fa719cc 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -740,9 +740,6 @@ static void restore_exclusive_pte(struct vm_area_struct= *vma, pte =3D pte_mkdirty(pte); pte =3D pte_mkwrite(pte, vma); } - - VM_BUG_ON_FOLIO(pte_write(pte) && (!folio_test_anon(folio) && - PageAnonExclusive(page)), folio); set_pte_at(vma->vm_mm, address, ptep, pte); =20 /* --=20 2.48.1 From nobody Fri Dec 19 02:50:38 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 0392921D3E8 for ; Wed, 26 Feb 2025 13:23:07 +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=1740576189; cv=none; b=U1YPQGSiluMaTghDkFSYsQqcaHSToutOmk6qYDABWYksTKzr97Zka8AoiEXEC9u8Uh/cK5KuT0ixzAXszOFGQgBVJqsLVWMyHtSuMNT/gG5N7YYPWqaV1K9vo78DBcCMM0ptKhshw2Q7S6iy4YLPRYtpopaVS9eTBt7hC+MHEZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740576189; c=relaxed/simple; bh=hv5cF+FmSUQB66FkGgLYhQwLyFrYJdO5vHdxITDFaBs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=baGaMDwsdTCMMHSQw7RVZhaqK2nJh74ZTm6DDQIyhNjrA3FeJHJNngn3OV6tR6jB26ZBNAcBtRP69qYWwgTaUTYilg/i0cGzuveV5tUGAJgselPUq5ir0+Oq/+pts7TOwoyvqn0n6UqaLBGkaS9LMojS+33yKOW42aopoEoJeQo= 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=XGvwjXfF; 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="XGvwjXfF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740576186; 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=BAb0fo+MBCG8218JfZux3TlZkyXUvKJVFQvJ8mnhkhM=; b=XGvwjXfFzKIPTi6p5SZxIUXyTYbnkrJyGvzKnI4lkUCYKE4fkdNWR3HgLalh2/labApSEm kGhs389EMuWf8xKyNxtSfdesy2aNKKrfMixpQWMDRqDr/ui/jSDeB71pC9BzzSHC5XUtfb nJd89FIcLCsozHa4MM5ZckgSX1XuntE= 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-648-ofYFlhFiMTKirA2obOBxYQ-1; Wed, 26 Feb 2025 08:23:05 -0500 X-MC-Unique: ofYFlhFiMTKirA2obOBxYQ-1 X-Mimecast-MFC-AGG-ID: ofYFlhFiMTKirA2obOBxYQ_1740576184 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43995bff469so52006995e9.2 for ; Wed, 26 Feb 2025 05:23:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740576184; x=1741180984; 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=BAb0fo+MBCG8218JfZux3TlZkyXUvKJVFQvJ8mnhkhM=; b=kzNwwie4y7Aw0N5O+ecv729ZYOXGpnTTBusp7HaVMmWnUHmJ73hbffnwmlIjbLs3ko V2BOyrsXEXxYYnYa2tfZCbWbyVNZ7kmczBva1qPgx30Wgevq0ZjqHo36ndXK3fq9V+Kr VzAID2VSawKRSxwD1uO/KJMQe8hpjzlWKE4ejDGg9qtZ1X8PYjxZqUPM+c7AZua0JBus Fo5ohkHykDDifjnMvSGX2wm3sMHDNaZGS+tSMJoXytsCYIn0ferydEi9GX5em3A5xR5a Co/F+yddvQ+V9FJaT08jKd73tOXQcxP9ZDkDyeFF4aIn8On8F+fSnDCwSxNOKO7arUrG Hx3w== X-Gm-Message-State: AOJu0YzhLozib9aGEO6AgzNDsvHo68/eB/iTSd9WxDr5pF6C4PU8kvjq e9haaRE5IpxTftU+d5Tw8XDS6Ode5eyF2gEvlVTf0nJVmPO38wV1bt61LDZkvR9VAAAinau6oS2 SvQ4oYG8SrMLTkEbcKKXn206WvKyKvn/OflC+ST0jkHjObyrW4YD3N5+EyAVa5W9v8PrXl4A/kE a95CPRYZ3PjMk38aeS5PDdJO5OAo7KgRVoJItHNg5alqr+ X-Gm-Gg: ASbGncufZAfuiKIHc39ZmuCEQqPDhUe0Pvi0eQvEFxVp0gEVWxYXPtNKI4wJg09X471 r3tO2jNBVteuJJrc8jBye4BbArXo6W9nGHkMl6jsld3UJZtK+CNyzjH8xLb9l9kiR9K1OgkpaZ4 g0K/pg7/m3Q37q6nnBoXyiVwIW++7OquXdTP+aemO1Vj5ozOdqzKSnK1sPbmkPJDitzaf0a6pw6 7zZomYIzs0MRRaQL5uW92+DKwhfnEP96T0j9JiBgfKYTmi+sHmIGVoCX8B8QpeCldvbZt/+BXtY 5k5+gJCdt7ADdSVEELcyXFbRFwdcBqRfWNahDlxLKP9oKUurLwMGHdq6nFBBisPudLhsn3f8aOl w X-Received: by 2002:a05:600c:4592:b0:439:94ef:3780 with SMTP id 5b1f17b1804b1-439aebe4a26mr212630805e9.30.1740576184323; Wed, 26 Feb 2025 05:23:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoD5SxjMPjT8fOACKzMgPJ46QVfUBCrCDwzS4nahkgUmdQJJ3IdcsNuACc+12Ckl886xGDnw== X-Received: by 2002:a05:600c:4592:b0:439:94ef:3780 with SMTP id 5b1f17b1804b1-439aebe4a26mr212630455e9.30.1740576183915; Wed, 26 Feb 2025 05:23:03 -0800 (PST) Received: from localhost (p200300cbc747ff009d854afba7df6c45.dip0.t-ipconnect.de. [2003:cb:c747:ff00:9d85:4afb:a7df:6c45]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43aba549eb9sm21310625e9.37.2025.02.26.05.23.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Feb 2025 05:23:03 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Simona Vetter , Alistair Popple , Jason Gunthorpe Subject: [PATCH v2 3/5] mm/memory: pass folio and pte to restore_exclusive_pte() Date: Wed, 26 Feb 2025 14:22:55 +0100 Message-ID: <20250226132257.2826043-4-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250226132257.2826043-1-david@redhat.com> References: <20250226132257.2826043-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 pass the folio and the pte to restore_exclusive_pte(), so we can avoid repeated page_folio() and ptep_get(). To do that, pass the pte to try_restore_exclusive_pte() and use a folio in there already. While at it, just avoid the "swp_entry_t entry" variable in try_restore_exclusive_pte() and add a folio-locked check to restore_exclusive_pte(). Reviewed-by: Alistair Popple Signed-off-by: David Hildenbrand --- mm/memory.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 507045fa719cc..2a0b4dd858769 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -719,14 +719,13 @@ struct folio *vm_normal_folio_pmd(struct vm_area_stru= ct *vma, #endif =20 static void restore_exclusive_pte(struct vm_area_struct *vma, - struct page *page, unsigned long address, - pte_t *ptep) + struct folio *folio, struct page *page, unsigned long address, + pte_t *ptep, pte_t orig_pte) { - struct folio *folio =3D page_folio(page); - pte_t orig_pte; pte_t pte; =20 - orig_pte =3D ptep_get(ptep); + VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio); + pte =3D pte_mkold(mk_pte(page, READ_ONCE(vma->vm_page_prot))); if (pte_swp_soft_dirty(orig_pte)) pte =3D pte_mksoft_dirty(pte); @@ -753,16 +752,15 @@ static void restore_exclusive_pte(struct vm_area_stru= ct *vma, * Tries to restore an exclusive pte if the page lock can be acquired with= out * sleeping. */ -static int -try_restore_exclusive_pte(pte_t *src_pte, struct vm_area_struct *vma, - unsigned long addr) +static int try_restore_exclusive_pte(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, pte_t orig_pte) { - swp_entry_t entry =3D pte_to_swp_entry(ptep_get(src_pte)); - struct page *page =3D pfn_swap_entry_to_page(entry); + struct page *page =3D pfn_swap_entry_to_page(pte_to_swp_entry(orig_pte)); + struct folio *folio =3D page_folio(page); =20 - if (trylock_page(page)) { - restore_exclusive_pte(vma, page, addr, src_pte); - unlock_page(page); + if (folio_trylock(folio)) { + restore_exclusive_pte(vma, folio, page, addr, ptep, orig_pte); + folio_unlock(folio); return 0; } =20 @@ -868,7 +866,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm= _struct *src_mm, * (ie. COW) mappings. */ VM_BUG_ON(!is_cow_mapping(src_vma->vm_flags)); - if (try_restore_exclusive_pte(src_pte, src_vma, addr)) + if (try_restore_exclusive_pte(src_vma, addr, src_pte, orig_pte)) return -EBUSY; return -ENOENT; } else if (is_pte_marker_entry(entry)) { @@ -4030,7 +4028,8 @@ static vm_fault_t remove_device_exclusive_entry(struc= t vm_fault *vmf) vmf->pte =3D pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); if (likely(vmf->pte && pte_same(ptep_get(vmf->pte), vmf->orig_pte))) - restore_exclusive_pte(vma, vmf->page, vmf->address, vmf->pte); + restore_exclusive_pte(vma, folio, vmf->page, vmf->address, + vmf->pte, vmf->orig_pte); =20 if (vmf->pte) pte_unmap_unlock(vmf->pte, vmf->ptl); --=20 2.48.1 From nobody Fri Dec 19 02:50:38 2025 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 6614F21E0B2 for ; Wed, 26 Feb 2025 13:23:09 +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=1740576191; cv=none; b=hc3IpwxcjRKEIpywFkcygDxmgBvEviGbsXoqb6mko4V4MbwyBJAs7MCqKw6+jah+ThNJ0ZH+3E5DGneGVR2p0xysYz48ZAgQsSNBmOVAiHT5w3fpyrR4rVSfqqxTfC/qNf6l43kOLlRXphrO+075JwfCsQSRSe+8xC4EDYBfQeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740576191; c=relaxed/simple; bh=J7bX3ng3MBFI3uixjZ9NZmXg9rqbq82/FkUeeG0DYh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W9onGWA6HoGhwSXmhPHvDZm7CTbyc0q7NSC5FsK0YKweGoKdT4UULu/ftrNiI90LR/O7AAsbBcUUwYW9VGRL8c5NBangid7iP6DFcXDS9xAHQhG/9nzIlVML0kK7kkaVNK+eWigYpBsOoz0yQ3Qiln9FPNrGPPPKftiHqji1qVk= 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=jT5GxHxe; 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="jT5GxHxe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740576188; 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=AjPK0xAhUMwvoTDKlkbg0/+uhvWrRoFGreGRAQOCejI=; b=jT5GxHxe7Xo+5EPhWnXXxOWNk6fFwZqk9SpxJ3P7iquuKTmuyZ3QLneG/Y1LT+vi5WLCh3 RReGKFhyVarg6htlkXlXVuKU0i2uChDpkcfAfhjLI4FN4OZBl95IqNNk7Cnv/S9UtCnWEe HY/1JvO7TcQCPQD7Dq3K+P/+g2oZTM0= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-KBIb2DqZM9K--xSYWvA79A-1; Wed, 26 Feb 2025 08:23:06 -0500 X-MC-Unique: KBIb2DqZM9K--xSYWvA79A-1 X-Mimecast-MFC-AGG-ID: KBIb2DqZM9K--xSYWvA79A_1740576186 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-38f20b530dfso6806534f8f.3 for ; Wed, 26 Feb 2025 05:23:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740576186; x=1741180986; 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=AjPK0xAhUMwvoTDKlkbg0/+uhvWrRoFGreGRAQOCejI=; b=IP70+nX79A60RpTyKtmxMW8FvFSkQMSbGXSAVYAerzX/e1h1jeyGNKhP6dnOsn4f6A dXqtsSKtxqbVy9prnHxPxJ0nItATou9q9bV8m7/m2r2rhQxZTPCfdDmHhTt2O5kU2w0m dUtA9Emw/uTruoEEWgsSdmHd/eKW4oUhr/FaEQ20Khgd+zcngA2QQNIiYVONx/Jddjbq jDyyPLCmYFwe+1Ztud/nYapmNyPPnQjyK+IyBFi0CyUGUtRMOlRuUCL3rcb/XTKPFeq/ DqtRGh5pmAYhetJ/psqP+nxeahYmlPZc8xaRSth1aP84oDQPAVwaVTtC5g7o8VPQuT0i Opxw== X-Gm-Message-State: AOJu0Yya1irhYXGxFEoAUhUW1jEj0r8CWSB+zQgSYu9wU7E+7tBY+dbo ql/hWB6ayEj7PppPDNc2FnATm031jqVZBacAzwYi3zcTrYv4PqLFtwhAVHfgrg2kKyn6AXw3QY4 rfWi4qBFSmaxOF5+qx/jnr+8+tejO0H5m5LUHzv93MFFDrkCD71RyMfEMDPzfpSITZPU+nA66dh buJEIPnnMbDSgJEygwcBzIaXGuTcpmFzWorbwcIVG4n2YS X-Gm-Gg: ASbGnctOW02NDOzzNVi4w+YBZI3DYGQ0e519hPkBDGHwh3B3PKS33SJPc66JT5y7BZg B5m5lh3WmT2qthHgkaxICFwh6pwgeTCmGO3olZdyDZ27suwmrPz4Ut+vgKeeFkcGufXvlnrKyy3 VbafuiOmT0x6Q6kbtZU5vWQua0UyHk7CnzCG/OWLW5kCS4yAJD8vYNWVhgunBbwI4U/RhIVrjjR bLhMNgATEjpmm+0qw7aGNWWW5d7q78VZsnmMHoSxVqKzQNQvhN+uKH6h3VOzdW4BGQp6P3OgRAG WceeUBoza8tE7htzW4nNRsG1FzpaxOK/6N/1oTe2hB2iI65QNySvSj49LvM+VkJ6g8NToEZhcOW B X-Received: by 2002:a5d:47c2:0:b0:38f:394f:d81 with SMTP id ffacd0b85a97d-38f7078453cmr15164342f8f.2.1740576185758; Wed, 26 Feb 2025 05:23:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5DqfQSz6+Y9W8USCBIUl1fQ02BbqBnpIn4TOEMuvpkG3OWGVNVeF9XVULbWYdy7YAqZOUzw== X-Received: by 2002:a5d:47c2:0:b0:38f:394f:d81 with SMTP id ffacd0b85a97d-38f7078453cmr15164317f8f.2.1740576185369; Wed, 26 Feb 2025 05:23:05 -0800 (PST) Received: from localhost (p200300cbc747ff009d854afba7df6c45.dip0.t-ipconnect.de. [2003:cb:c747:ff00:9d85:4afb:a7df:6c45]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-390cd86cc3csm5704848f8f.33.2025.02.26.05.23.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Feb 2025 05:23:04 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Simona Vetter , Alistair Popple , Jason Gunthorpe Subject: [PATCH v2 4/5] mm/memory: document restore_exclusive_pte() Date: Wed, 26 Feb 2025 14:22:56 +0100 Message-ID: <20250226132257.2826043-5-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250226132257.2826043-1-david@redhat.com> References: <20250226132257.2826043-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 folio lock is involved. Signed-off-by: David Hildenbrand --- mm/memory.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 2a0b4dd858769..50a305d7efcb9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -718,6 +718,32 @@ 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. + * + * Locking the folio makes sure that anybody who just converted the pte to + * a device-exclusive entry can map it into the device to make forward + * progress without others converting it back until the folio was unlocked. + * + * If the folio lock ever becomes an issue, we can stop relying on the fol= io + * lock; it might make some scenarios with heavy thrashing less likely to + * make forward progress, but these scenarios might not be valid use cases. + * + * Note that the folio lock does not protect against all cases of concurre= nt + * page table modifications (e.g., MADV_DONTNEED, mprotect), so device dri= vers + * must use MMU notifiers to sync against any concurrent changes. + */ 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 From nobody Fri Dec 19 02:50:38 2025 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 C79E92206B3 for ; Wed, 26 Feb 2025 13:23:10 +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=1740576192; cv=none; b=ouF1jjtgK84Yd42OLu8fhcmIK9kVOK3TXYU0sN9XNwImVjdneqgt1P4LpDIQXCpcI7gF9Z3HYgUtn28RWlCErDVyCZET7UXy9IGU4UDsZbT4rNDxUaTSwmNh+yI3UK+EQzhf0dj1cdeEAffP5zGTbNKicL1VJZRENYCLmW7Z+tA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740576192; c=relaxed/simple; bh=zb/ywQkAU/VZTJpUdxuoaD5DmJ0FlMmVf/JFfsbEDjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JNplgUEFlTuJQVD7vX0RwOpaFL/gwMSpWOM8x304OBgwx7PkEYAEjq7Rapw38zCvpjWbd31pzof3ii2DKqT0QRBBXkWahU4fR+FsiHNqhHSuplWchF9tR5emJEGaisCvWSNqkejHebgQkl1GNQF1nyeH3OrPxSUazU22R8074TE= 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=dNSHaRpU; 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="dNSHaRpU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740576190; 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=3ayxqWdfZtpuuFLEW5/IWnRh3wjbr3t43oqj3ksvw18=; b=dNSHaRpUYDX3N7mvoITAObQIOsFm9HcKge/SuO7l+GtI2h6vNdwZ0GyW1EP9BPlsfjIAGr lvTEBIUz6O1riBKTiZcvgciLRSiKRYBz09/Q4ta4X+PKBUVJDqyq2QeFRrcam3hQHVMtt4 J+lWuKRzEZRB3Vawv9PPUcg5VhC41lw= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-647-SsZGLmv6MsW6jatUHce-9Q-1; Wed, 26 Feb 2025 08:23:08 -0500 X-MC-Unique: SsZGLmv6MsW6jatUHce-9Q-1 X-Mimecast-MFC-AGG-ID: SsZGLmv6MsW6jatUHce-9Q_1740576187 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43945f32e2dso62331395e9.2 for ; Wed, 26 Feb 2025 05:23:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740576187; x=1741180987; 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=3ayxqWdfZtpuuFLEW5/IWnRh3wjbr3t43oqj3ksvw18=; b=R2s8Np6tVUDaFGu6FmwxCE5/xcpu+naRALUlu+2uea/zym5VK4kjypTII2pIGP1azx 1ko8bdSDL+pAhC8a9CjDgZH+lD0iW3aJFSbRig7PS/mmsuoIjWd/Wck3k9yrhLf6aQRv jrzLAy1bKun5FgW413THbqMEeBYxmF/s+x3ENLXxw390c7H3DKJekrAPygg/awIaioBZ 2IGZNPmzGElwWkkgxijXLIgHCA3suRpH6RpZHwD+PWuXUC+nhL6suF4ra7JIGbMI01p7 lXmylNW2Idxs8qfJ+LPEzgyLY+2rfW4i9oYrbtYVimVGjLbYRb/kwIdxXtGds1ov1YOy LdFg== X-Gm-Message-State: AOJu0YwPUZ/US7exg64vCbDBnmAygKO2xhdtu4NcJY2vRkq3FDPg9GDH olmPYKBLqUS0VjDv9jGwjwJfR3wr36k5vR6fHVGL7+dE3d9MD9vptrXWsN/JYch+nzpgNhWJ0yu sE3vT6PLSk/7TDYpKRR6jPFywiXJbaVohw5+bh1xblNFM67MRKG33IRFUo0hbeX05swT8dfq4xD krNVSGZd7+9A5rb8BUSOjEaU9PZC2/G71HhsXnsNnP+Ly/ X-Gm-Gg: ASbGncszwWiUmtOTGIwtJXl5Mb9nPqMeZ6l0phVPyljFzGfxaR9GiM6kBU0EzgnoMro 4Knik8s4qkNWhaSyKf1K4vnQqOSemzwnchw1bFwjJoSQnL/nKNlpIOkhf5pAgFuFa1Ofhq3OvUp 0pA/STkuCVvHKkLUPsgV5ilxBIiKe1tU32c7vHQ/T/61Heft4MWj2PSzhfIa2xvpbSG5MPWQKux VE4PLpm7a5HQUh0fSpoLqpbsi1pzCElhvPuvDuTAUtI9Vr70sB/l4aj7WScwVgwkSC+NlCqg5HS hg+tedTwLifLjPL4ygbWeUzQkYsQKlRzldZ3t9crm1yOEfnnSqeVjbwma7CiDVZfjBy441eauFT P X-Received: by 2002:a05:600c:1d1a:b0:439:916a:b3db with SMTP id 5b1f17b1804b1-43ab0f28872mr74312735e9.6.1740576187255; Wed, 26 Feb 2025 05:23:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZecayt4WE/OXHMqhCrGeiiVFvJ2H3x+MAoGPf+DIopmjwISLHjYgRgetExDyOwLcEx7l8uw== X-Received: by 2002:a05:600c:1d1a:b0:439:916a:b3db with SMTP id 5b1f17b1804b1-43ab0f28872mr74312325e9.6.1740576186833; Wed, 26 Feb 2025 05:23:06 -0800 (PST) Received: from localhost (p200300cbc747ff009d854afba7df6c45.dip0.t-ipconnect.de. [2003:cb:c747:ff00:9d85:4afb:a7df:6c45]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-43aba544029sm21379795e9.29.2025.02.26.05.23.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Feb 2025 05:23:06 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Simona Vetter , Alistair Popple , Jason Gunthorpe Subject: [PATCH v2 5/5] mm/mmu_notifier: use MMU_NOTIFY_CLEAR in remove_device_exclusive_entry() Date: Wed, 26 Feb 2025 14:22:57 +0100 Message-ID: <20250226132257.2826043-6-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250226132257.2826043-1-david@redhat.com> References: <20250226132257.2826043-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 limit the use of MMU_NOTIFY_EXCLUSIVE to the case where we convert a present PTE to device-exclusive. For the other case, we can simply use MMU_NOTIFY_CLEAR, because it really is clearing the device-exclusive entry first, to then install the present entry. Update the documentation of MMU_NOTIFY_EXCLUSIVE, to document the single use case more thoroughly. If ever required, we could add a separate MMU_NOTIFY_CLEAR_EXCLUSIVE; for now using MMU_NOTIFY_CLEAR seems to be sufficient. Signed-off-by: David Hildenbrand --- include/linux/mmu_notifier.h | 8 ++++---- mm/memory.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index d4e7146618262..bc2402a45741d 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -43,10 +43,10 @@ struct mmu_interval_notifier; * a device driver to possibly ignore the invalidation if the * owner field matches the driver's device private pgmap owner. * - * @MMU_NOTIFY_EXCLUSIVE: to signal a device driver that the device will no - * longer have exclusive access to the page. When sent during creation of = an - * exclusive range the owner will be initialised to the value provided by = the - * caller of make_device_exclusive(), otherwise the owner will be NULL. + * @MMU_NOTIFY_EXCLUSIVE: conversion of a page table entry to device-exclu= sive. + * The owner is initialized to the value provided by the caller of + * make_device_exclusive(), such that this caller can filter out these + * events. */ enum mmu_notifier_event { MMU_NOTIFY_UNMAP =3D 0, diff --git a/mm/memory.c b/mm/memory.c index 50a305d7efcb9..79acd2d95dcff 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4046,7 +4046,7 @@ static vm_fault_t remove_device_exclusive_entry(struc= t vm_fault *vmf) folio_put(folio); return ret; } - mmu_notifier_range_init_owner(&range, MMU_NOTIFY_EXCLUSIVE, 0, + mmu_notifier_range_init_owner(&range, MMU_NOTIFY_CLEAR, 0, vma->vm_mm, vmf->address & PAGE_MASK, (vmf->address & PAGE_MASK) + PAGE_SIZE, NULL); mmu_notifier_invalidate_range_start(&range); --=20 2.48.1