Re: [PATCH] mm: introduce kvvirt_to_page() helper

From: Matthew Wilcox
Date: Mon Aug 20 2018 - 13:38:24 EST


On Mon, Aug 20, 2018 at 04:41:16PM +0200, Michal Hocko wrote:
> > +++ b/fs/xfs/xfs_buf.c
> > for (i = 0; i < bp->b_page_count; i++) {
> > - bp->b_pages[i] = mem_to_page((void *)pageaddr);
> > + bp->b_pages[i] = kvvirt_to_page((void *)pageaddr);
> > pageaddr += PAGE_SIZE;

This wants mem_range_to_page_array().

> > +++ b/net/9p/trans_virtio.c
> > for (index = 0; index < nr_pages; index++) {
> > - if (is_vmalloc_addr(p))
> > - (*pages)[index] = vmalloc_to_page(p);
> > - else
> > - (*pages)[index] = kmap_to_page(p);
> > + (*pages)[index] = kvvirt_to_page(p);

Also mem_range_to_page_array().

> > +++ b/net/ceph/crypto.c
> > @@ -191,11 +191,7 @@ static int setup_sgtable(struct sg_table *sgt, struct scatterlist *prealloc_sg,
> > struct page *page;
> > unsigned int len = min(chunk_len - off, buf_len);
> >
> > - if (is_vmalloc)
> > - page = vmalloc_to_page(buf);
> > - else
> > - page = virt_to_page(buf);
> > -
> > + page = kvvirt_to_page(buf);
> > sg_set_page(sg, page, len, off);
> >
> > off = 0;

This whole function wants to move into the core and be called something like
sg_alloc_table_from_virt().

> > +++ b/net/packet/af_packet.c
> > @@ -374,15 +367,15 @@ static void __packet_set_status(struct packet_sock *po, void *frame, int status)
> > switch (po->tp_version) {
> > case TPACKET_V1:
> > h.h1->tp_status = status;
> > - flush_dcache_page(pgv_to_page(&h.h1->tp_status));
> > + flush_dcache_page(kvvirt_to_page(&h.h1->tp_status));

This driver really wants flush_dcache_range(start, len).