Hi all,
Today's linux-next merge of the block tree got a conflict in:
mm/gup.c
between commit:
0f3f569eca46 ("mm/gup.c: reorganize try_get_folio()")
from the mm tree and commit:
c8070b787519 ("mm: Don't pin ZERO_PAGE in pin_user_pages()")
from the block tree.
I fixed it up (I think - see below) and can carry the fix as necessary.
This is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging. You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.
--
Cheers,
Stephen Rothwell
diff --cc mm/gup.c
index ce14d4d28503,0814576b7366..000000000000
--- a/mm/gup.c
+++ b/mm/gup.c
@@@ -132,50 -127,62 +133,57 @@@ struct folio *try_grab_folio(struct pag
if (unlikely(!(flags & FOLL_PCI_P2PDMA) && is_pci_p2pdma_page(page)))
return NULL;
+ folio = try_get_folio(page, refs);
+
if (flags & FOLL_GET)
- return try_get_folio(page, refs);
- else if (flags & FOLL_PIN) {
- struct folio *folio;
-
- /*
- * Don't take a pin on the zero page - it's not going anywhere
- * and it is used in a *lot* of places.
- */
- if (is_zero_page(page))
- return page_folio(page);
-
- /*
- * Can't do FOLL_LONGTERM + FOLL_PIN gup fast path if not in a
- * right zone, so fail and let the caller fall back to the slow
- * path.
- */
- if (unlikely((flags & FOLL_LONGTERM) &&
- !is_longterm_pinnable_page(page)))
- return NULL;
-
- /*
- * CAUTION: Don't use compound_head() on the page before this
- * point, the result won't be stable.
- */
- folio = try_get_folio(page, refs);
- if (!folio)
- return NULL;
-
- /*
- * When pinning a large folio, use an exact count to track it.
- *
- * However, be sure to *also* increment the normal folio
- * refcount field at least once, so that the folio really
- * is pinned. That's why the refcount from the earlier
- * try_get_folio() is left intact.
- */
- if (folio_test_large(folio))
- atomic_add(refs, &folio->_pincount);
- else
- folio_ref_add(folio,
- refs * (GUP_PIN_COUNTING_BIAS - 1));
- /*
- * Adjust the pincount before re-checking the PTE for changes.
- * This is essentially a smp_mb() and is paired with a memory
- * barrier in page_try_share_anon_rmap().
- */
- smp_mb__after_atomic();
-
- node_stat_mod_folio(folio, NR_FOLL_PIN_ACQUIRED, refs);
-
return folio;
+
+ /* FOLL_PIN is set */
+ if (!folio)
+ return NULL;
+
++ /*
++ * Don't take a pin on the zero page - it's not going anywhere
++ * and it is used in a *lot* of places.
++ */
++ if (is_zero_page(page))
++ return page_folio(page);
++
+ /*
+ * Can't do FOLL_LONGTERM + FOLL_PIN gup fast path if not in a
+ * right zone, so fail and let the caller fall back to the slow
+ * path.
+ */
+ if (unlikely((flags & FOLL_LONGTERM) &&
+ !folio_is_longterm_pinnable(folio))) {
+ if (!put_devmap_managed_page_refs(&folio->page, refs))
+ folio_put_refs(folio, refs);
+ return NULL;
}
- WARN_ON_ONCE(1);
- return NULL;
+ /*
+ * When pinning a large folio, use an exact count to track it.
+ *
+ * However, be sure to *also* increment the normal folio
+ * refcount field at least once, so that the folio really
+ * is pinned. That's why the refcount from the earlier
+ * try_get_folio() is left intact.
+ */
+ if (folio_test_large(folio))
+ atomic_add(refs, &folio->_pincount);
+ else
+ folio_ref_add(folio,
+ refs * (GUP_PIN_COUNTING_BIAS - 1));
+ /*
+ * Adjust the pincount before re-checking the PTE for changes.
+ * This is essentially a smp_mb() and is paired with a memory
+ * barrier in page_try_share_anon_rmap().
+ */
+ smp_mb__after_atomic();
+
+ node_stat_mod_folio(folio, NR_FOLL_PIN_ACQUIRED, refs);
+
+ return folio;
}
static void gup_put_folio(struct folio *folio, int refs, unsigned int flags)
@@@ -3250,9 -3193,13 +3300,12 @@@ EXPORT_SYMBOL(pin_user_pages_remote)
*
* FOLL_PIN means that the pages must be released via unpin_user_page(). Please
* see Documentation/core-api/pin_user_pages.rst for details.
+ *
+ * Note that if a zero_page is amongst the returned pages, it will not have
+ * pins in it and unpin_user_page*() will not remove pins from it.
*/
long pin_user_pages(unsigned long start, unsigned long nr_pages,
- unsigned int gup_flags, struct page **pages,
- struct vm_area_struct **vmas)
+ unsigned int gup_flags, struct page **pages)
{
int locked = 1;
On Fri, 16 Jun 2023 11:58:56 +1000 Stephen Rothwell <[email protected]> wrote:
> Today's linux-next merge of the block tree got a conflict in:
>
> mm/gup.c
>
> between commit:
>
> 0f3f569eca46 ("mm/gup.c: reorganize try_get_folio()")
>
> from the mm tree and commit:
>
> c8070b787519 ("mm: Don't pin ZERO_PAGE in pin_user_pages()")
>
> from the block tree.
>
> I fixed it up (I think - see below) and can carry the fix as necessary.
> This is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging. You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.
That's getting a bit nasty. Maybe David's patches are in the wrong tree.
Andrew Morton <[email protected]> wrote:
> That's getting a bit nasty. Maybe David's patches are in the wrong tree.
You'd need to discuss that one with Jens. The patches you'd have to transfer
also touch a number of block-related files. Looking at block/for-next, there
don't seem to be many other patches touching those files, but I've seen
patches from Christoph that will need to be applied on top of mine.
David
On 6/16/23 3:56?AM, David Howells wrote:
> Andrew Morton <[email protected]> wrote:
>
>> That's getting a bit nasty. Maybe David's patches are in the wrong
>> tree.
>
> You'd need to discuss that one with Jens. The patches you'd have to
> transfer also touch a number of block-related files. Looking at
> block/for-next, there don't seem to be many other patches touching
> those files, but I've seen patches from Christoph that will need to be
> applied on top of mine.
It's definitely a bit of a mess now, but for-6.5/block also depends on
these changes and make further tweaks on the block front.
for-6.5/splice is stable, so just pull that in?
--
Jens Axboe
On Thu, Jun 15, 2023 at 6:59 PM Stephen Rothwell <[email protected]> wrote:
>
> Hi all,
>
> Today's linux-next merge of the block tree got a conflict in:
>
> mm/gup.c
>
> between commit:
>
> 0f3f569eca46 ("mm/gup.c: reorganize try_get_folio()")
>
> from the mm tree and commit:
>
> c8070b787519 ("mm: Don't pin ZERO_PAGE in pin_user_pages()")
>
> from the block tree.
>
> I fixed it up (I think - see below) and can carry the fix as necessary.
> This is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging. You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.
Thanks for fixing these up. I'll keep an eye out for conflicts in
linux-next as well
in the future.