Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4038210imm; Mon, 20 Aug 2018 08:48:20 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzcMv8jv0LlO5snPygrB3tQxNATXYGzYy3dws8Sm385H7r1P0jkHigsK9G34NUmvBLmLXPo X-Received: by 2002:a17:902:528a:: with SMTP id a10-v6mr46070031pli.199.1534780100340; Mon, 20 Aug 2018 08:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534780100; cv=none; d=google.com; s=arc-20160816; b=Nk8y5Ng7w12g2XgzXmvU4cHSTRQW/JmCItrJ+5FF+VM/I3NP5H51hvieMZXdcdf3r1 IvHkpF3cRk8fmc7qyYNeTf4YQiuRLNMyWW1rmtUwW9cX3E0NpuAMv+4YoV6hdvpJm7h1 ZuFz60/NUo4CFQlzvSRNGQswYaHALMzFAsBMDQXhBO7Lqo7v8zaQTihqHlWXjxejk9Qk ByVE72hQESQBShH+auzPN6ixdEI3zmqnBBUcMg7z9bB0/X0YzAufqeRk5CrU6kCihXKi 2b0MqV76JMOd8rdffUVauBj+XRaZA3k4ejahsBR4ZeS6Qatc6+r94sTevY64kNWdWihk cDbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=7wM8iDX/ZVe7vuVPKoazMrjTjln6b1It8M0TUvVv86E=; b=L6JUkr/ya+JKT/QT6AMuxZXmuEkET3mGOgMSxKBx18l5YdhJn7PU7U2gBRt7w8/6Mt 1MEp7Eh75g/bv3DQ/B6OHmQQYyNDduHt+DspKF+iA7tdzxH4y0ABh9V4237eoG/M4b3o ZAjZKN0u0V9ESyk+djASwRsvkWn+mJk++qZWsKfsmKZdLhcAbzrcGvMMTppPcfV5LSL5 lc4trRQ24UO13ahRymBr09naITipT36FmeL8AszU1fNMPqrwFD6n10oULp0MziWxF9yt Tz6mfVsn+smvKr3i3b7bL/Nz9sYz6lw1jQ8ak2nXYUdRjBjibsA2+5cRJlAg2kbYCyP0 RMgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j2-v6si10408821pfc.102.2018.08.20.08.48.03; Mon, 20 Aug 2018 08:48:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727111AbeHTR5P (ORCPT + 99 others); Mon, 20 Aug 2018 13:57:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:51210 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726735AbeHTR5P (ORCPT ); Mon, 20 Aug 2018 13:57:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BD95BAF3E; Mon, 20 Aug 2018 14:41:17 +0000 (UTC) Date: Mon, 20 Aug 2018 16:41:16 +0200 From: Michal Hocko To: Li RongQing Cc: Andrew Morton , Dan Williams , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, "Kirill A. Shutemov" , Matthew Wilcox , Souptick Joarder , darrick.wong@oracle.com Subject: Re: [PATCH] mm: introduce kvvirt_to_page() helper Message-ID: <20180820144116.GO29735@dhcp22.suse.cz> References: <1534596541-31393-1-git-send-email-lirongqing@baidu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1534596541-31393-1-git-send-email-lirongqing@baidu.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat 18-08-18 20:49:01, Li RongQing wrote: > The new helper returns address mapping page, which has several users > in individual subsystem, like mem_to_page in xfs_buf.c and pgv_to_page > in af_packet.c, unify them kvvirt_to_page is a weird name. I guess you wanted it to fit into kv*alloc, kvfree naming, right? If yes then I guess kvmem_to_page would be slightly better. Other than that the patch makes sense to me. It would be great to add some documentation and be explicit that the call is only safe on directly mapped kernel address and vmalloc areas. > Signed-off-by: Zhang Yu > Signed-off-by: Li RongQing > --- > fs/xfs/xfs_buf.c | 13 +------------ > include/linux/mm.h | 8 ++++++++ > net/9p/trans_virtio.c | 5 +---- > net/ceph/crypto.c | 6 +----- > net/packet/af_packet.c | 31 ++++++++++++------------------- > 5 files changed, 23 insertions(+), 40 deletions(-) > > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c > index e839907e8492..edd22b33f49e 100644 > --- a/fs/xfs/xfs_buf.c > +++ b/fs/xfs/xfs_buf.c > @@ -866,17 +866,6 @@ xfs_buf_set_empty( > bp->b_maps[0].bm_len = bp->b_length; > } > > -static inline struct page * > -mem_to_page( > - void *addr) > -{ > - if ((!is_vmalloc_addr(addr))) { > - return virt_to_page(addr); > - } else { > - return vmalloc_to_page(addr); > - } > -} > - > int > xfs_buf_associate_memory( > xfs_buf_t *bp, > @@ -909,7 +898,7 @@ xfs_buf_associate_memory( > bp->b_offset = offset; > > 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; > } > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 68a5121694ef..bb34a3c71df5 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -599,6 +599,14 @@ static inline void *kvcalloc(size_t n, size_t size, gfp_t flags) > return kvmalloc_array(n, size, flags | __GFP_ZERO); > } > > +static inline struct page *kvvirt_to_page(const void *addr) > +{ > + if (!is_vmalloc_addr(addr)) > + return virt_to_page(addr); > + else > + return vmalloc_to_page(addr); > +} > + > extern void kvfree(const void *addr); > > static inline atomic_t *compound_mapcount_ptr(struct page *page) > diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c > index 05006cbb3361..8f1895f15593 100644 > --- a/net/9p/trans_virtio.c > +++ b/net/9p/trans_virtio.c > @@ -368,10 +368,7 @@ static int p9_get_mapped_pages(struct virtio_chan *chan, > *need_drop = 0; > p -= (*offs = offset_in_page(p)); > 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); > p += PAGE_SIZE; > } > return len; > diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c > index 02172c408ff2..cc5f0723a44d 100644 > --- a/net/ceph/crypto.c > +++ 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; > diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c > index 5610061e7f2e..1bec111122ad 100644 > --- a/net/packet/af_packet.c > +++ b/net/packet/af_packet.c > @@ -359,13 +359,6 @@ static void unregister_prot_hook(struct sock *sk, bool sync) > __unregister_prot_hook(sk, sync); > } > > -static inline struct page * __pure pgv_to_page(void *addr) > -{ > - if (is_vmalloc_addr(addr)) > - return vmalloc_to_page(addr); > - return virt_to_page(addr); > -} > - > static void __packet_set_status(struct packet_sock *po, void *frame, int status) > { > union tpacket_uhdr h; > @@ -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)); > break; > case TPACKET_V2: > h.h2->tp_status = status; > - flush_dcache_page(pgv_to_page(&h.h2->tp_status)); > + flush_dcache_page(kvvirt_to_page(&h.h2->tp_status)); > break; > case TPACKET_V3: > h.h3->tp_status = status; > - flush_dcache_page(pgv_to_page(&h.h3->tp_status)); > + flush_dcache_page(kvvirt_to_page(&h.h3->tp_status)); > break; > default: > WARN(1, "TPACKET version not supported.\n"); > @@ -401,13 +394,13 @@ static int __packet_get_status(struct packet_sock *po, void *frame) > h.raw = frame; > switch (po->tp_version) { > case TPACKET_V1: > - flush_dcache_page(pgv_to_page(&h.h1->tp_status)); > + flush_dcache_page(kvvirt_to_page(&h.h1->tp_status)); > return h.h1->tp_status; > case TPACKET_V2: > - flush_dcache_page(pgv_to_page(&h.h2->tp_status)); > + flush_dcache_page(kvvirt_to_page(&h.h2->tp_status)); > return h.h2->tp_status; > case TPACKET_V3: > - flush_dcache_page(pgv_to_page(&h.h3->tp_status)); > + flush_dcache_page(kvvirt_to_page(&h.h3->tp_status)); > return h.h3->tp_status; > default: > WARN(1, "TPACKET version not supported.\n"); > @@ -462,7 +455,7 @@ static __u32 __packet_set_timestamp(struct packet_sock *po, void *frame, > } > > /* one flush is safe, as both fields always lie on the same cacheline */ > - flush_dcache_page(pgv_to_page(&h.h1->tp_sec)); > + flush_dcache_page(kvvirt_to_page(&h.h1->tp_sec)); > smp_wmb(); > > return ts_status; > @@ -728,7 +721,7 @@ static void prb_flush_block(struct tpacket_kbdq_core *pkc1, > > end = (u8 *)PAGE_ALIGN((unsigned long)pkc1->pkblk_end); > for (; start < end; start += PAGE_SIZE) > - flush_dcache_page(pgv_to_page(start)); > + flush_dcache_page(kvvirt_to_page(start)); > > smp_wmb(); > #endif > @@ -741,7 +734,7 @@ static void prb_flush_block(struct tpacket_kbdq_core *pkc1, > > #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE == 1 > start = (u8 *)pbd1; > - flush_dcache_page(pgv_to_page(start)); > + flush_dcache_page(kvvirt_to_page(start)); > > smp_wmb(); > #endif > @@ -2352,7 +2345,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, > macoff + snaplen); > > for (start = h.raw; start < end; start += PAGE_SIZE) > - flush_dcache_page(pgv_to_page(start)); > + flush_dcache_page(kvvirt_to_page(start)); > } > smp_wmb(); > #endif > @@ -2508,7 +2501,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, > return -EFAULT; > } > > - page = pgv_to_page(data); > + page = kvvirt_to_page(data); > data += len; > flush_dcache_page(page); > get_page(page); > @@ -4385,7 +4378,7 @@ static int packet_mmap(struct file *file, struct socket *sock, > int pg_num; > > for (pg_num = 0; pg_num < rb->pg_vec_pages; pg_num++) { > - page = pgv_to_page(kaddr); > + page = kvvirt_to_page(kaddr); > err = vm_insert_page(vma, start, page); > if (unlikely(err)) > goto out; > -- > 2.16.2 > -- Michal Hocko SUSE Labs