[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] dma-mapping: use vmalloc_to_page for vmalloc addresses


  • To: Roman Skakun <rm.skakun@xxxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
  • From: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
  • Date: Thu, 15 Jul 2021 12:58:53 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PlO+aifXXEIa+z9v4xiUSYXOYqpLk/izVPxxiT30tas=; b=odx+95pMtGjDELlV0HniQHCmErEKFqSWDua0lQojaRysPRqwdTckJCFteJzc6xX9rX4doa/6hz5o6t787680mwe6o1YDlWBSHFkCi1+lGHP8S6J5BHRiHWIuspLc+B84/iWXQm3lspK5Y0aXNnyfDK+Y866ZIuu0mjFs0YbvFLwYx2BjAQRsCHT8sS00fYsW2YEj237u2ROsWhmVlVIRQinPDIgIc0h/m8prcngBENwVaMAFx2/fFBxysL3otqJSRA3yyaJtsyYBVEpqaAUqsyGR48w10DELKTo7F0f7dNBXw3a9Gn/kwYz7UcLGImrReefS3r7QbIa5HJi3IND0Kw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gg0RZaa7YGP/UlNzcolDVEdKn38h/DAbEyHS4agSBqEQVG7WoSpAcv+MiXeNJekqtXg+tXD05O8Bmz8xHIpPtIeL9YP+KZS1cJ82fMKcrRFioHlpRkNY5GLfcTS6qAJYAoQZDdk3HxyklsyXWGP0ul7Gzag/iB/Zx0H4aZBy7HBi6Mn7T38Dgtws9bIPE80Gpdq0pVqfckvBpOh5EgNLY8M6bJzBEwK6tXz1S1aNSIfNbvbyhuwMMQswXP1CEu88FAd6hB+P5AOgYEXy59PFz0FTOcU3RQ+HF7Xxg6hhVuB1XYCAWIqz9onuffraUWmXTp4Ed85qizbJs7C8fVaFEQ==
  • Authentication-results: lst.de; dkim=none (message not signed) header.d=none;lst.de; dmarc=none action=none header.from=oracle.com;
  • Cc: Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, iommu@xxxxxxxxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, Roman Skakun <roman_skakun@xxxxxxxx>, Andrii Anisov <andrii_anisov@xxxxxxxx>, Christoph Hellwig <hch@xxxxxx>
  • Delivery-date: Thu, 15 Jul 2021 16:59:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 7/15/21 3:39 AM, Roman Skakun wrote:
>> This looks like it wasn't picked up? Should it go in rc1?
> Hi, Konrad!
>
> This looks like an unambiguous bug, and should be in rc1.


Looks like you didn't copy Christoph which could be part of the problem. Adding 
him.


-boris



>
> Cheers!
>
> ср, 14 июл. 2021 г. в 03:15, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>:
>> On Tue, Jun 22, 2021 at 04:34:14PM +0300, Roman Skakun wrote:
>>> This commit is dedicated to fix incorrect conversion from
>>> cpu_addr to page address in cases when we get virtual
>>> address which allocated in the vmalloc range.
>>> As the result, virt_to_page() cannot convert this address
>>> properly and return incorrect page address.
>>>
>>> Need to detect such cases and obtains the page address using
>>> vmalloc_to_page() instead.
>>>
>>> Signed-off-by: Roman Skakun <roman_skakun@xxxxxxxx>
>>> Reviewed-by: Andrii Anisov <andrii_anisov@xxxxxxxx>
>>> ---
>>> Hey!
>>> Thanks for suggestions, Christoph!
>>> I updated the patch according to your advice.
>>> But, I'm so surprised because nobody catches this problem
>>> in the common code before. It looks a bit strange as for me.
>> This looks like it wasn't picked up? Should it go in rc1?
>>>
>>>  kernel/dma/ops_helpers.c | 12 ++++++++++--
>>>  1 file changed, 10 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/kernel/dma/ops_helpers.c b/kernel/dma/ops_helpers.c
>>> index 910ae69cae77..782728d8a393 100644
>>> --- a/kernel/dma/ops_helpers.c
>>> +++ b/kernel/dma/ops_helpers.c
>>> @@ -5,6 +5,14 @@
>>>   */
>>>  #include <linux/dma-map-ops.h>
>>>
>>> +static struct page *cpu_addr_to_page(void *cpu_addr)
>>> +{
>>> +     if (is_vmalloc_addr(cpu_addr))
>>> +             return vmalloc_to_page(cpu_addr);
>>> +     else
>>> +             return virt_to_page(cpu_addr);
>>> +}
>>> +
>>>  /*
>>>   * Create scatter-list for the already allocated DMA buffer.
>>>   */
>>> @@ -12,7 +20,7 @@ int dma_common_get_sgtable(struct device *dev, struct 
>>> sg_table *sgt,
>>>                void *cpu_addr, dma_addr_t dma_addr, size_t size,
>>>                unsigned long attrs)
>>>  {
>>> -     struct page *page = virt_to_page(cpu_addr);
>>> +     struct page *page = cpu_addr_to_page(cpu_addr);
>>>       int ret;
>>>
>>>       ret = sg_alloc_table(sgt, 1, GFP_KERNEL);
>>> @@ -43,7 +51,7 @@ int dma_common_mmap(struct device *dev, struct 
>>> vm_area_struct *vma,
>>>               return -ENXIO;
>>>
>>>       return remap_pfn_range(vma, vma->vm_start,
>>> -                     page_to_pfn(virt_to_page(cpu_addr)) + vma->vm_pgoff,
>>> +                     page_to_pfn(cpu_addr_to_page(cpu_addr)) + 
>>> vma->vm_pgoff,
>>>                       user_count << PAGE_SHIFT, vma->vm_page_prot);
>>>  #else
>>>       return -ENXIO;
>>> --
>>> 2.25.1
>>>
>
>



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.