Received: by 2002:a9a:4c47:0:b029:116:c383:538 with SMTP id u7csp1159177lko; Tue, 13 Jul 2021 18:25:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLfkifyLVbFzfG8XqxROJteUWLWVlssYX6th0bF0PFN9fBNSEgg76L8RTee3wHaFOX1AMk X-Received: by 2002:a17:906:851:: with SMTP id f17mr9172215ejd.244.1626225915567; Tue, 13 Jul 2021 18:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626225915; cv=none; d=google.com; s=arc-20160816; b=HCGYS++LIVAqP8TiOHIqV15dPVEjljhPyBiIdKYzcAAiaMPpqzV6zDMUNAkzV++bpL rBG29aHrCrZy0q1XOR7IPP73jCXKXyYI8uXDOHW1nBqqbKxAG6LuRyEwoY7VjyvjBrSI Ksn+7gvLhYVDn8HYX5a9967J+F+yez/JQUU093zOcmwdxisnDng0sMQiavefrCd/8zr1 fVCQ3SQw8zJdF8Je8nSEYRsjk6ooqnxcT1oGbCASyvNoavZAr7pLB70+YtaOiTrK8Nfn oI2HMbVo5rBBpkoltd4c/8m7wKmhLnRIajlY6AxNObvAH4DYO4E1QxaWktRlGcuZ1ZbC CkvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=Bu5xRPY4oHwTNS4kgo2zpxMLDVAJ8iD37H0KcwUGlvE=; b=WljemkLD2FXe+LGg1JPd3d9giutWlOLYbdadPGzC3nawOXRXyuxqJt5r6qvPybPxvi PvALWPgGz+QuwYOYiEtCyXX+0HsnTFqX4HSqRSp3NNkpX9CZOCZjxaKbq2Vh204RBTHW 1EA8RgVioWQFSxBSZASs4T4OFbY8NoL6jDDPu0jc+uran4nIsmrFHNTkQxx0idkyvY8j RFc5e4A78+SdY0c18zvQD+dtV8BN3QPlndQ32LeWisF+f6Pw1XdF54oKmz3JcKqgQxMa Ra3y4w0/ED2cQDzIdoL5OydA/tnDVE6mwNH2kiMz+noPDU7p5xpCWsXPkE7wG9nKyopF OfhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q3qZdS2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si748239edy.320.2021.07.13.18.24.53; Tue, 13 Jul 2021 18:25:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q3qZdS2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237249AbhGNB0s (ORCPT + 99 others); Tue, 13 Jul 2021 21:26:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:37778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237223AbhGNB0s (ORCPT ); Tue, 13 Jul 2021 21:26:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0403361370; Wed, 14 Jul 2021 01:23:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626225837; bh=2OW+dl69IwJaUv/Dmdi8sG6wLihedmiyxIbS3TwfP04=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=Q3qZdS2d4flDx1JSLjNZe47joSZ8PBHHE2iEbusngkyxL8Gkm33IKFBE22c9vYib5 7JX4HwyUm4Ilyc/irup/kJuTMxx8RnYTSL1uDRk73cJYniNN5+7UvwQEIj7o2pEtvq 6MXThixra3HZZ5Xv8tNwihJvoLA7pXLspeRn2Ww6VGGOvVQV5vstLzOUhEZ0TjIIJC XcJigFfxuMArpu1dlgu3ExFnVqoikjLLw61cTnFgCRo4Rju2HX84URuDHviWRNZG9T geGiIPCQs3uWcxJgJGoqlGrRjLqtPNsKvwLiXWyyGvWdHvZOOYcU6sVRM/PifcBpZl AvG51cEPzwg5g== Date: Tue, 13 Jul 2021 18:23:56 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Roman Skakun cc: Konrad Rzeszutek Wilk , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , xen-devel@lists.xenproject.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Oleksandr Tyshchenko , Oleksandr Andrushchenko , Volodymyr Babchuk , Roman Skakun , Andrii Anisov Subject: Re: [PATCH v2] dma-mapping: use vmalloc_to_page for vmalloc addresses In-Reply-To: <20210622133414.132754-1-rm.skakun@gmail.com> Message-ID: References: <20210616154436.GA7619@lst.de> <20210622133414.132754-1-rm.skakun@gmail.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 22 Jun 2021, 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 > Reviewed-by: Andrii Anisov > --- > 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. > > > 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 > > +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); > +} We have the same thing in xen_swiotlb_free_coherent. Can we find a way to call cpu_addr_to_page() from xen_swiotlb_free_coherent? Maybe we can make cpu_addr_to_page non-static? No problem if it is too much trouble. > /* > * 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 >