linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] uio-hv-generic: store physical addresses instead of virtual
@ 2016-12-09 11:44 Arnd Bergmann
  2016-12-09 17:28 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2016-12-09 11:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: netdev, Arnd Bergmann, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, devel, linux-kernel

gcc warns about the newly added driver when phys_addr_t is wider than
a pointer:

drivers/uio/uio_hv_generic.c: In function 'hv_uio_mmap':
drivers/uio/uio_hv_generic.c:71:17: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
    virt_to_phys((void *)info->mem[mi].addr) >> PAGE_SHIFT,
drivers/uio/uio_hv_generic.c: In function 'hv_uio_probe':
drivers/uio/uio_hv_generic.c:140:5: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
   = (phys_addr_t)dev->channel->ringbuffer_pages;
drivers/uio/uio_hv_generic.c:147:3: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
   (phys_addr_t)vmbus_connection.int_page;
drivers/uio/uio_hv_generic.c:153:3: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
   (phys_addr_t)vmbus_connection.monitor_pages[1];

I can't see why we store a virtual address in a phys_addr_t here,
as the only user of that variable converts it into a physical
address anyway, so this moves the conversion to where it logically
fits according to the types.

Fixes: 95096f2fbd10 ("uio-hv-generic: new userspace i/o driver for VMBus")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/uio/uio_hv_generic.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
index ad3ab5805ad8..50958f167305 100644
--- a/drivers/uio/uio_hv_generic.c
+++ b/drivers/uio/uio_hv_generic.c
@@ -68,7 +68,7 @@ hv_uio_mmap(struct uio_info *info, struct vm_area_struct *vma)
 	mi = (int)vma->vm_pgoff;
 
 	return remap_pfn_range(vma, vma->vm_start,
-			virt_to_phys((void *)info->mem[mi].addr) >> PAGE_SHIFT,
+			info->mem[mi].addr >> PAGE_SHIFT,
 			vma->vm_end - vma->vm_start, vma->vm_page_prot);
 }
 
@@ -137,20 +137,20 @@ hv_uio_probe(struct hv_device *dev,
 	/* mem resources */
 	pdata->info.mem[TXRX_RING_MAP].name = "txrx_rings";
 	pdata->info.mem[TXRX_RING_MAP].addr
-		= (phys_addr_t)dev->channel->ringbuffer_pages;
+		= virt_to_phys(dev->channel->ringbuffer_pages);
 	pdata->info.mem[TXRX_RING_MAP].size
 		= dev->channel->ringbuffer_pagecount * PAGE_SIZE;
 	pdata->info.mem[TXRX_RING_MAP].memtype = UIO_MEM_LOGICAL;
 
 	pdata->info.mem[INT_PAGE_MAP].name = "int_page";
 	pdata->info.mem[INT_PAGE_MAP].addr =
-		(phys_addr_t)vmbus_connection.int_page;
+		virt_to_phys(vmbus_connection.int_page);
 	pdata->info.mem[INT_PAGE_MAP].size = PAGE_SIZE;
 	pdata->info.mem[INT_PAGE_MAP].memtype = UIO_MEM_LOGICAL;
 
 	pdata->info.mem[MON_PAGE_MAP].name = "monitor_pages";
 	pdata->info.mem[MON_PAGE_MAP].addr =
-		(phys_addr_t)vmbus_connection.monitor_pages[1];
+		virt_to_phys(vmbus_connection.monitor_pages[1]);
 	pdata->info.mem[MON_PAGE_MAP].size = PAGE_SIZE;
 	pdata->info.mem[MON_PAGE_MAP].memtype = UIO_MEM_LOGICAL;
 
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] uio-hv-generic: store physical addresses instead of virtual
  2016-12-09 11:44 [PATCH] uio-hv-generic: store physical addresses instead of virtual Arnd Bergmann
@ 2016-12-09 17:28 ` Stephen Hemminger
  2016-12-09 20:38   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2016-12-09 17:28 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Greg Kroah-Hartman, Stephen Hemminger, netdev, Haiyang Zhang,
	linux-kernel, devel

On Fri,  9 Dec 2016 12:44:40 +0100
Arnd Bergmann <arnd@arndb.de> wrote:

> gcc warns about the newly added driver when phys_addr_t is wider than
> a pointer:
> 
> drivers/uio/uio_hv_generic.c: In function 'hv_uio_mmap':
> drivers/uio/uio_hv_generic.c:71:17: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
>     virt_to_phys((void *)info->mem[mi].addr) >> PAGE_SHIFT,
> drivers/uio/uio_hv_generic.c: In function 'hv_uio_probe':
> drivers/uio/uio_hv_generic.c:140:5: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
>    = (phys_addr_t)dev->channel->ringbuffer_pages;
> drivers/uio/uio_hv_generic.c:147:3: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
>    (phys_addr_t)vmbus_connection.int_page;
> drivers/uio/uio_hv_generic.c:153:3: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
>    (phys_addr_t)vmbus_connection.monitor_pages[1];
> 
> I can't see why we store a virtual address in a phys_addr_t here,
> as the only user of that variable converts it into a physical
> address anyway, so this moves the conversion to where it logically
> fits according to the types.
> 
> Fixes: 95096f2fbd10 ("uio-hv-generic: new userspace i/o driver for VMBus")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks, the code was inherited from outside, and only tested on x86_64.
Not sure which platform and GCC version generates the warning, was this just W=1?

Acked-by: Stephen Hemminger <sthemmin@microsoft.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] uio-hv-generic: store physical addresses instead of virtual
  2016-12-09 17:28 ` Stephen Hemminger
@ 2016-12-09 20:38   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2016-12-09 20:38 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Greg Kroah-Hartman, Stephen Hemminger, netdev, Haiyang Zhang,
	linux-kernel, devel

On Friday, December 9, 2016 9:28:44 AM CET Stephen Hemminger wrote:
> On Fri,  9 Dec 2016 12:44:40 +0100
> Arnd Bergmann <arnd@arndb.de> wrote:

> > Fixes: 95096f2fbd10 ("uio-hv-generic: new userspace i/o driver for VMBus")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 
> Thanks, the code was inherited from outside, and only tested on x86_64.
> Not sure which platform and GCC version generates the warning, was this just W=1?
> 
> Acked-by: Stephen Hemminger <sthemmin@microsoft.com>

This was a regular warning with a randconfig build on arm32, but
it happens on any 32-bit architecture when CONFIG_PHYS_ADDR_T_64BIT
is enabled.

	Arnd

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-12-09 20:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-09 11:44 [PATCH] uio-hv-generic: store physical addresses instead of virtual Arnd Bergmann
2016-12-09 17:28 ` Stephen Hemminger
2016-12-09 20:38   ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).