From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alistair Popple Date: Wed, 31 Mar 2021 12:59:28 +0000 Subject: Re: [PATCH v7 5/8] mm: Device exclusive memory access Message-Id: <2521635.masqiumSp9@nvdebian> List-Id: References: <20210326000805.2518-1-apopple@nvidia.com> <20210326000805.2518-6-apopple@nvidia.com> <20210330193234.GA2356281@nvidia.com> In-Reply-To: <20210330193234.GA2356281@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Jason Gunthorpe Cc: linux-mm@kvack.org, nouveau@lists.freedesktop.org, bskeggs@redhat.com, akpm@linux-foundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvm-ppc@vger.kernel.org, dri-devel@lists.freedesktop.org, jhubbard@nvidia.com, rcampbell@nvidia.com, jglisse@redhat.com, hch@infradead.org, daniel@ffwll.ch, willy@infradead.org, Christoph Hellwig On Wednesday, 31 March 2021 6:32:34 AM AEDT Jason Gunthorpe wrote: > On Fri, Mar 26, 2021 at 11:08:02AM +1100, Alistair Popple wrote: > > diff --git a/mm/memory.c b/mm/memory.c > > index 3a5705cfc891..33d11527ef77 100644 > > +++ b/mm/memory.c > > @@ -781,6 +781,27 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, > > pte = pte_swp_mkuffd_wp(pte); > > set_pte_at(src_mm, addr, src_pte, pte); > > } > > + } else if (is_device_exclusive_entry(entry)) { > > + page = pfn_swap_entry_to_page(entry); > > + > > + get_page(page); > > + rss[mm_counter(page)]++; > > + > > + if (is_writable_device_exclusive_entry(entry) && > > + is_cow_mapping(vm_flags)) { > > + /* > > + * COW mappings require pages in both > > + * parent and child to be set to read. > > + */ > > + entry = make_readable_device_exclusive_entry( > > + swp_offset(entry)); > > + pte = swp_entry_to_pte(entry); > > + if (pte_swp_soft_dirty(*src_pte)) > > + pte = pte_swp_mksoft_dirty(pte); > > + if (pte_swp_uffd_wp(*src_pte)) > > + pte = pte_swp_mkuffd_wp(pte); > > + set_pte_at(src_mm, addr, src_pte, pte); > > + } > > This needs to have the same logic as we now have in > copy_present_page(). The page *is* present and we can't copy the PTE > value hidden in a swap entry if we can't copy the PTE normally. You're saying we need to use copy_present_page() to make sure the split goes the right way for pinned pages? I guess that makes sense as the split could go either way at the moment but I should add a check to make sure this isn't used with pinned pages anyway. - Alistair > The code should be shared because nobody is going to remember about > this corner case. > > Jason >