From patchwork Tue Jun 22 13:34:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Skakun X-Patchwork-Id: 12337441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E09AC2B9F4 for ; Tue, 22 Jun 2021 13:34:49 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6AE086112D for ; Tue, 22 Jun 2021 13:34:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6AE086112D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.145882.268322 (Exim 4.92) (envelope-from ) id 1lvgXt-00053d-7G; Tue, 22 Jun 2021 13:34:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 145882.268322; Tue, 22 Jun 2021 13:34:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lvgXt-00053W-1O; Tue, 22 Jun 2021 13:34:29 +0000 Received: by outflank-mailman (input) for mailman id 145882; Tue, 22 Jun 2021 13:34:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lvgXr-00053O-5u for xen-devel@lists.xenproject.org; Tue, 22 Jun 2021 13:34:27 +0000 Received: from mail-lf1-x131.google.com (unknown [2a00:1450:4864:20::131]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8b1a62bf-a1d7-4d72-9b82-de0ce5bc0d9a; Tue, 22 Jun 2021 13:34:25 +0000 (UTC) Received: by mail-lf1-x131.google.com with SMTP id f30so36061424lfj.1 for ; Tue, 22 Jun 2021 06:34:25 -0700 (PDT) Received: from localhost ([178.151.124.169]) by smtp.gmail.com with ESMTPSA id l27sm2790583ljb.90.2021.06.22.06.34.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 06:34:23 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8b1a62bf-a1d7-4d72-9b82-de0ce5bc0d9a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VpDilbWjWRuwm2Y0aj2xxaAxAvje8bBd6jPUCV3pOXQ=; b=fMPS6tmNxJ4WajUXO/WI+lAB/0vRCw/g40VCYzUAplHrCiShgYL4/pOWQt53jgsCrf grGcdhQjl09EnXls7tfkPf8x+Ekama0Z44pP8gN135yakp6jJ7WWKkoYaJkmCL6OFLUP nzOd+zztLMvLPOmX/8NCU+Nk6hN+3hpThfa+ReQZO3uaXdRMX34IHf9sOOvRgnLkv9G6 alLI1QKAtA9yVaF6DuEsmIzeEi1WOWG1sjS4RoyJ/m5jVWPmmDB72ai9HnffPCdZGRoU 45nWuPRiQFyqomMSwjaZkjlqTkynSdsmN1sLTW+F35Ra3uJpZOrA6cn28uqXYgBBKVYK yvuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VpDilbWjWRuwm2Y0aj2xxaAxAvje8bBd6jPUCV3pOXQ=; b=MGgbTrGzkdzUk4d323vcR3FbiFbKGZgIadhdaeihjmwZzIG4pTq0VB6SClZQB0XeTE UEzDBnaUv1tmd222TGNLYmOFQ/yYXSEJ+wDeAeWR1/YBH66TGQLaVxjpD+pSbdXWFxUi EWNm0Mmu0AlthbhnPk9FZB5N5AoDiXOwC0HLXAooObekS4OnLqcWk1wkch+2QxK/ej2S kXsOFpZAysfbPGlxTF9IfAHlZv9G56taqmPTPfjW2sHPTIGmbM5+7Fje+EQuAYjrxF+Q QVBMUT+X6O2I6O05XzbOWchxRi2GteC43aXQM8qCvoa1kU5kei0zViIybDYU/E4KTSBq Y2cA== X-Gm-Message-State: AOAM532cvuJXMiLmTocLUerHq3ZoFlF6hTeqsOgUctGIF1Vq7SLsyW4k /IN8Z5j135PSDjWa+MHL+Ok= X-Google-Smtp-Source: ABdhPJyfiEMp266a5Vc5gXIKMSmpRt+IMoLHqhjEwQPGGcLOElP7Q+Iu0ooyEO/TCg6nVx1MPndmrQ== X-Received: by 2002:ac2:5192:: with SMTP id u18mr2841831lfi.619.1624368864308; Tue, 22 Jun 2021 06:34:24 -0700 (PDT) From: Roman Skakun To: Konrad Rzeszutek Wilk , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , xen-devel@lists.xenproject.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: Oleksandr Tyshchenko , Oleksandr Andrushchenko , Volodymyr Babchuk , Roman Skakun , Roman Skakun , Andrii Anisov Subject: [PATCH v2] dma-mapping: use vmalloc_to_page for vmalloc addresses Date: Tue, 22 Jun 2021 16:34:14 +0300 Message-Id: <20210622133414.132754-1-rm.skakun@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210616154436.GA7619@lst.de> References: <20210616154436.GA7619@lst.de> MIME-Version: 1.0 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); +} + /* * 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;