race with page_referenced_one->ptep_test_and_clear_young and pagetable setup/pulldown
A message that is not in the archive (sent off-list or not yet received): C32B9BEC.E711%[email protected]
Quoted 4 lines
Fortuitously, Jan Beulich has a patch to fix this. It's not going to be directly applicable to 2.6.23-rc series, but should be easily ported:
<http://lists.xensource.com/archives/html/xen-devel/2007-03/msg01200.html>.
Do I misread that patch or does it really walk the complete address space and try to take all possible locks? Isn't that very slow?
-Andi
Quoted 4 lines · Keir Fraser
Hang on! How is the access unlocked? By my reading page_referenced_one()->page_check_address()->spin_lock(pte_lockptr()).
Ah, OK. I'd overlooked that.
Quoted 8 lines
The problem here is most likely insufficient locking in the pin/unpin table-walking code, in light of the fact that you are probably running with
per-page spinlocks (SPLIT_PTLOCK_CPUS). Because we nobble that option in our
own kernel ports it suffices to take thepage_table_lockwhen doing the walk-[un]pin-remap routine. This is *not* true withSPLIT_PTLOCK_CPUS.
Hm, I see.
Quoted 4 lines
Fortuitously, Jan Beulich has a patch to fix this. It's not going to be directly applicable to 2.6.23-rc series, but should be easily ported:
<http://lists.xensource.com/archives/html/xen-devel/2007-03/msg01200.html>.
OK, I can use that.
Andi says:
Quoted 3 lines
Do I misread that patch or does it really walk the complete address space and try to take all possible locks? Isn't that very slow?
That's pretty much what it has to do. Pinning/unpinning walks the whole pagetable anyway, so it shouldn't be much more expensive. And they're relatively rare operations (fork, exec, exit).
J
Quoted 8 lines · Jeremy Fitzhardinge
Andi says:
Quoted 3 lines
Do I misread that patch or does it really walk the complete address space and try to take all possible locks? Isn't that very slow?
That's pretty much what it has to do. Pinning/unpinning walks the whole pagetable anyway, so it shouldn't be much more expensive. And they're relatively rare operations (fork, exec, exit).
It is a shame to do 3x walks per pin or unpin, rather than 1x, though.
One way to improve this, possibly, is to pin the pte tables individually as you go, rather than doing one big pin/unpin just at the root pgd. Then you can lock/unlock the pte's as you go. I'd suggest that as a possible post 2.6.23 improvement, however. Jan's patch has actually had some testing.
-- Keir
Quoted 9 lines · Keir Fraser
Quoted 7 lines · Jeremy Fitzhardinge
Andi says:
Quoted 2 lines
Do I misread that patch or does it really walk the complete address space and try to take all possible locks? Isn't that very slow?
That's pretty much what it has to do. Pinning/unpinning walks the whole pagetable anyway, so it shouldn't be much more expensive. And they're relatively rare operations (fork, exec, exit).
Quoted 6 lines
It is a shame to do 3x walks per pin or unpin, rather than 1x, though.
One way to improve this, possibly, is to pin the pte tables individually as you go, rather than doing one big pin/unpin just at the root pgd. Then you can lock/unlock the pte's as you go. I'd suggest that as a possible post 2.6.23 improvement, however. Jan's patch has actually had some testing.
A few points come to mind looking at Jan's patch:
The comment about nested pagetable locks is wrong: mm/mremap.c does nest pagetable locks; but you wouldn't (as I understand it) be doing this pinning/unpinning anywhere which could race with an mremap() on the same mm, so that's a niggle about a comment, not a real issue.
Yes, it would be greatly preferable to take the locks one by one as needed. As it stands, I think you're in danger of overflowing the PREEMPT_BITS 8 area of preempt_count(), venturing into the SOFTIRQ area: I don't know the real-life consequence of that.
I don't see any protection against hugetlb areas, where the pmd entry may indicate a hugetlb page rather than a pagetable page. I guess you'll be needing to test pte_huge(). I don't know if you want to lock those or skip them: locking is usually just with page_table_lock, but beware there's also sharing of huge page pmds between mms - Ken Chen should be able to help on that.
If a 2.6.23 fix is needed, I suggest simply excluding split ptlocks in the Xen case, as shown by the mm/Kconfig - line in Jan's patch.
Hugh
Quoted 2 lines · Hugh Dickins
If a 2.6.23 fix is needed, I suggest simply excluding split ptlocks in the Xen case, as shown by the mm/Kconfig - line in Jan's patch.
I didn't think that nobbling config options for particular pv_ops implementations was acceptable? I'm rather out of the loop though, and could be wrong.
The PREEMPT_BITS limitation is a good argument for at least taking the pte locks in small batches though (small batches is preferable to one-by-one since we will want to batch the make-readonly-and-pin hypercall requests to amortise the cost of the hypervisor trap).
-- Keir
Quoted 4 lines · Keir Fraser
I didn't think that nobbling config options for particular
pv_opsimplementations was acceptable? I'm rather out of the loop though, and could be wrong.
As a workaround it would be OK. As a dependency, perhaps.
Quoted 5 lines
The
PREEMPT_BITSlimitation is a good argument for at least taking the pte locks in small batches though (small batches is preferable to one-by-one since we will want to batch the make-readonly-and-pin hypercall requests to amortise the cost of the hypervisor trap).
Hm, that's a good point. The pagetable permissions changes are batched more or less asynchronously from the actual loop structure; that will complicate adding the locking.
J
Quoted 4 lines · Keir Fraser
The
PREEMPT_BITSlimitation is a good argument for at least taking the pte locks in small batches though (small batches is preferable to one-by-one since we will want to batch the make-readonly-and-pin hypercall requests to amortise the cost of the hypervisor trap).
Hm, I don't see how we can avoid holding locks for the whole pagetable at once. We need to hold the locks from between marking a particular pte page RO until the whole pagetable is pinned; if we don't, pte updates can come in from other cpus, which will fault on the RO but won't be fixed up by Xen.
Could we avoid it by doing a series of partial pins, locking and unlocking each one in the process, and then pin the whole pagetable?
J