linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] video: hyperv: hyperv_fb: Use physical memory for fb on HyperV Gen 1 VMs.
@ 2020-02-05  5:43 Dan Carpenter
  2020-02-05  7:21 ` Wei Hu
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2020-02-05  5:43 UTC (permalink / raw)
  To: weh; +Cc: linux-hyperv

Hello Wei Hu,

The patch 3a6fb6c4255c: "video: hyperv: hyperv_fb: Use physical
memory for fb on HyperV Gen 1 VMs." from Dec 9, 2019, leads to the
following static checker warning:

	drivers/video/fbdev/hyperv_fb.c:991 hvfb_get_phymem()
	error: 'vmem' came from dma_alloc_coherent() so we can't do virt_to_phys()

drivers/video/fbdev/hyperv_fb.c
   960  static phys_addr_t hvfb_get_phymem(struct hv_device *hdev,
   961                                     unsigned int request_size)
   962  {
   963          struct page *page = NULL;
   964          dma_addr_t dma_handle;
   965          void *vmem;
   966          phys_addr_t paddr = 0;
   967          unsigned int order = get_order(request_size);
   968  
   969          if (request_size == 0)
   970                  return -1;
   971  
   972          if (order < MAX_ORDER) {
   973                  /* Call alloc_pages if the size is less than 2^MAX_ORDER */
   974                  page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
   975                  if (!page)
   976                          return -1;
   977  
   978                  paddr = (page_to_pfn(page) << PAGE_SHIFT);
   979          } else {
   980                  /* Allocate from CMA */
   981                  hdev->device.coherent_dma_mask = DMA_BIT_MASK(64);
   982  
   983                  vmem = dma_alloc_coherent(&hdev->device,
   984                                            round_up(request_size, PAGE_SIZE),
   985                                            &dma_handle,
   986                                            GFP_KERNEL | __GFP_NOWARN);
   987  
   988                  if (!vmem)
   989                          return -1;
   990  
   991                  paddr = virt_to_phys(vmem);

Pretty straight forward that the static checker is right but I can't
give you any hints how to fix it.

   992          }
   993  
   994          return paddr;
   995  }

regards,
dan carpenter

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

* RE: [bug report] video: hyperv: hyperv_fb: Use physical memory for fb on HyperV Gen 1 VMs.
  2020-02-05  5:43 [bug report] video: hyperv: hyperv_fb: Use physical memory for fb on HyperV Gen 1 VMs Dan Carpenter
@ 2020-02-05  7:21 ` Wei Hu
  2020-02-05  8:07   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Wei Hu @ 2020-02-05  7:21 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-hyperv

Hello Dan,

> -----Original Message-----> 
> Hello Wei Hu,
> 
> The patch 3a6fb6c4255c: "video: hyperv: hyperv_fb: Use physical memory for
> fb on HyperV Gen 1 VMs." from Dec 9, 2019, leads to the following static
> checker warning:
> 
> 	drivers/video/fbdev/hyperv_fb.c:991 hvfb_get_phymem()
> 	error: 'vmem' came from dma_alloc_coherent() so we can't do
> virt_to_phys()
> 
> drivers/video/fbdev/hyperv_fb.c
>    960  static phys_addr_t hvfb_get_phymem(struct hv_device *hdev,
>    961                                     unsigned int request_size)
>    962  {
>    963          struct page *page = NULL;
>    964          dma_addr_t dma_handle;
>    965          void *vmem;
>    966          phys_addr_t paddr = 0;
>    967          unsigned int order = get_order(request_size);
>    968
>    969          if (request_size == 0)
>    970                  return -1;
>    971
>    972          if (order < MAX_ORDER) {
>    973                  /* Call alloc_pages if the size is less than 2^MAX_ORDER */
>    974                  page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
>    975                  if (!page)
>    976                          return -1;
>    977
>    978                  paddr = (page_to_pfn(page) << PAGE_SHIFT);
>    979          } else {
>    980                  /* Allocate from CMA */
>    981                  hdev->device.coherent_dma_mask = DMA_BIT_MASK(64);
>    982
>    983                  vmem = dma_alloc_coherent(&hdev->device,
>    984                                            round_up(request_size, PAGE_SIZE),
>    985                                            &dma_handle,
>    986                                            GFP_KERNEL | __GFP_NOWARN);
>    987
>    988                  if (!vmem)
>    989                          return -1;
>    990
>    991                  paddr = virt_to_phys(vmem);
> 
> Pretty straight forward that the static checker is right but I can't give you any
> hints how to fix it.
> 

Thanks for reporting this. Would you let me know how I can reproduce this warning or
Error message? The build on my side runs fine without such message.

Thanks,
Wei

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

* Re: [bug report] video: hyperv: hyperv_fb: Use physical memory for fb on HyperV Gen 1 VMs.
  2020-02-05  7:21 ` Wei Hu
@ 2020-02-05  8:07   ` Dan Carpenter
  2020-02-05 11:33     ` Wei Hu
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2020-02-05  8:07 UTC (permalink / raw)
  To: Wei Hu; +Cc: linux-hyperv


On Wed, Feb 05, 2020 at 07:21:31AM +0000, Wei Hu wrote:
> Hello Dan,
> 
> > -----Original Message-----> 
> > Hello Wei Hu,
> > 
> > The patch 3a6fb6c4255c: "video: hyperv: hyperv_fb: Use physical memory for
> > fb on HyperV Gen 1 VMs." from Dec 9, 2019, leads to the following static
> > checker warning:
> > 
> > 	drivers/video/fbdev/hyperv_fb.c:991 hvfb_get_phymem()
> > 	error: 'vmem' came from dma_alloc_coherent() so we can't do
> > virt_to_phys()
> > 
> > drivers/video/fbdev/hyperv_fb.c
> >    960  static phys_addr_t hvfb_get_phymem(struct hv_device *hdev,
> >    961                                     unsigned int request_size)
> >    962  {
> >    963          struct page *page = NULL;
> >    964          dma_addr_t dma_handle;
> >    965          void *vmem;
> >    966          phys_addr_t paddr = 0;
> >    967          unsigned int order = get_order(request_size);
> >    968
> >    969          if (request_size == 0)
> >    970                  return -1;
> >    971
> >    972          if (order < MAX_ORDER) {
> >    973                  /* Call alloc_pages if the size is less than 2^MAX_ORDER */
> >    974                  page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
> >    975                  if (!page)
> >    976                          return -1;
> >    977
> >    978                  paddr = (page_to_pfn(page) << PAGE_SHIFT);
> >    979          } else {
> >    980                  /* Allocate from CMA */
> >    981                  hdev->device.coherent_dma_mask = DMA_BIT_MASK(64);
> >    982
> >    983                  vmem = dma_alloc_coherent(&hdev->device,
> >    984                                            round_up(request_size, PAGE_SIZE),
> >    985                                            &dma_handle,
> >    986                                            GFP_KERNEL | __GFP_NOWARN);
> >    987
> >    988                  if (!vmem)
> >    989                          return -1;
> >    990
> >    991                  paddr = virt_to_phys(vmem);
> > 
> > Pretty straight forward that the static checker is right but I can't give you any
> > hints how to fix it.
> > 
> 
> Thanks for reporting this. Would you let me know how I can reproduce this warning or
> Error message? The build on my side runs fine without such message.

Hm...  Sorry, I never publish this Smatch check.  I should do that.
Anyway HCH explains the rules a bit in this email:

https://lkml.org/lkml/2019/6/17/155

regards,
dan carpenter


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

* RE: [bug report] video: hyperv: hyperv_fb: Use physical memory for fb on HyperV Gen 1 VMs.
  2020-02-05  8:07   ` Dan Carpenter
@ 2020-02-05 11:33     ` Wei Hu
  0 siblings, 0 replies; 4+ messages in thread
From: Wei Hu @ 2020-02-05 11:33 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-hyperv



> -----Original Message-----
> > Thanks for reporting this. Would you let me know how I can reproduce
> > this warning or Error message? The build on my side runs fine without such
> message.
> 
> Hm...  Sorry, I never publish this Smatch check.  I should do that.
> Anyway HCH explains the rules a bit in this email:
> 
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml.or
> g%2Flkml%2F2019%2F6%2F17%2F155&amp;data=02%7C01%7Cweh%40micro
> soft.com%7Cff5687dc7bb648623d3708d7aa127a4b%7C72f988bf86f141af91a
> b2d7cd011db47%7C1%7C0%7C637164868648450097&amp;sdata=0%2B8Jwe
> 1A%2FtOW0LqF8t2hqymWuzZjVtUxBIKgMyOQdFc%3D&amp;reserved=0
> 

I see. This is virtual frame buffer device on Hyper-V. It would not get address from 
vmap or ioremap. On the other hand, if dma_alloc_coherent() returns address without
page backing, this driver will blow even without calling virt_to_phys. 

Dma_alloc_coherent() is the recommended interface to allocate large contiguous
physical memory, in which case this call is doing so. I think you can ignore this 
in your check.

Thanks,
Wei

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

end of thread, other threads:[~2020-02-05 11:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05  5:43 [bug report] video: hyperv: hyperv_fb: Use physical memory for fb on HyperV Gen 1 VMs Dan Carpenter
2020-02-05  7:21 ` Wei Hu
2020-02-05  8:07   ` Dan Carpenter
2020-02-05 11:33     ` Wei Hu

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).