Skip to contentSkip to conversation

Should we delete memmove_page?

DISCUSSION Matthew Wilcox 2 participants 4 messages May 26, 2022 – May 27, 2022 Memory management

lore
Share & tools
lore
#0 lore raw

I was looking at memmove_page() and it occurred to me that it can't actually work, so we should probably delete it as being an attractive nuisance. It doesn't have any users.

memmove() isn't magic. It compares the source address, source length, destination address and destination length, and then does either a forwards copy or a backwards copy, depending where the overlap is.

But 'dst' and 'src' are guaranteed to be non-overlapping. They come from different calls to kmap_local_page(), so even if src_page and dst_page are the same, src and dst will be different.

We could fix it up. Include a compare of 'dst_page' and 'src_page' and if they're the same only kmap_local_page() one of them. But since it has no users, perhaps just delete it?

#1 lore raw
Quoted 3 lines · Matthew Wilcox

I was looking at memmove_page() and it occurred to me that it can't actually work,

Oh wow yea. Because you can't unmap that address correctly.

Quoted 8 lines

so we should probably delete it as being an attractive nuisance. It doesn't have any users.

memmove() isn't magic. It compares the source address, source length, destination address and destination length, and then does either a forwards copy or a backwards copy, depending where the overlap is.

Quoted 7 lines

But 'dst' and 'src' are guaranteed to be non-overlapping. They come from different calls to kmap_local_page(), so even if src_page and dst_page are the same, src and dst will be different.

We could fix it up. Include a compare of 'dst_page' and 'src_page' and if they're the same only kmap_local_page() one of them. But since it has no users, perhaps just delete it?

Yes deletion is best. But...

copy_user_highpage()
copy_highpage()

... might suffer from the same potential issue should a user not realize. I think memcpy_page() by virtue of the name.

Still perhaps a kernel doc may be in order.

I could not say anything at LSFmm because the Outreachy interns had not been announced but I've selected Fabio to help with the highmem rework through that program.

Would you like Fabio or I to send a patch? I think the main thing right now is to just drop the memmove_page()

Ira

#2 lore raw
Quoted 6 lines · Ira Weiny
Quoted 3 lines · Matthew Wilcox

I was looking at memmove_page() and it occurred to me that it can't actually work,

Oh wow yea. Because you can't unmap that address correctly.

I don't understand what you mean ... you can unmap the address, it's just that memmove can't know that the two virtual ranges actually overlap physically.

Quoted 7 lines

Yes deletion is best. But...

copy_user_highpage()
copy_highpage()

... might suffer from the same potential issue should a user not realize. I think memcpy_page() by virtue of the name.

Umm? They're all using memcpy(), so the caller must guarantee that the physical addresses are different.

Quoted 3 lines

I could not say anything at LSFmm because the Outreachy interns had not been announced but I've selected Fabio to help with the highmem rework through that program.

Excellent! I advised Fabio last year, and I think he'll do a sterling job this year.

Quoted 2 lines

Would you like Fabio or I to send a patch? I think the main thing right now is to just drop the memmove_page()

Sure, just stick my Reported-by: on it.

#3 lore raw
Quoted 9 lines · Matthew Wilcox
Quoted 6 lines · Ira Weiny
Quoted 3 lines · Matthew Wilcox

I was looking at memmove_page() and it occurred to me that it can't actually work,

Oh wow yea. Because you can't unmap that address correctly.

I don't understand what you mean ...

Nevermind. I missed the fact that arch_kmap_local_map_idx() does not actually use the pfn except on xtensa.

Quoted 3 lines

you can unmap the address, it's
just that memmove can't know that the two virtual ranges actually overlap physically.

I was thinking that the index returned would be the same for both kmaps.

Quoted 11 lines
Quoted 8 lines

Yes deletion is best. But...

copy_user_highpage()
copy_highpage()

... might suffer from the same potential issue should a user not realize. I think memcpy_page() by virtue of the name.

Umm? They're all using memcpy(), so the caller must guarantee that the physical addresses are different.

Exactly. But how does the caller know that? The memcpy() call is buried inside the copy_user_page() and/or copy_page(). Users of these functions should not need to dig that far into an implementation to use this interface IMO. Adding some kdoc helps I think.

Quoted 7 lines
Quoted 4 lines

I could not say anything at LSFmm because the Outreachy interns had not been announced but I've selected Fabio to help with the highmem rework through that program.

Excellent! I advised Fabio last year, and I think he'll do a sterling job this year.

Me too!

Quoted 5 lines
Quoted 3 lines

Would you like Fabio or I to send a patch? I think the main thing right now is to just drop the memmove_page()

Sure, just stick my Reported-by: on it.

Absolutely!

Thanks for the report,
Ira