Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp899554ybt; Fri, 10 Jul 2020 15:37:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBlJLp4HdvA43ADVC/riGv9v60LZUrITRSRr4Z/E08iscAiQwlPPijbDJupcNCrA1po9lG X-Received: by 2002:a17:906:7e04:: with SMTP id e4mr56069518ejr.83.1594420633308; Fri, 10 Jul 2020 15:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594420633; cv=none; d=google.com; s=arc-20160816; b=r0jkXMqqvq2s9pRQKsWlxnkZB0/8Ig3whTNxOIhenJMxZ7S6wzz6ATq3+lfKNkmWvZ noxaJVneKtpPH9q20SOisvPZH50WMNAvdefupzwmih4Gt9mZavSKiWIIGjKuddk1cnRb lWfMisNyXPPopsOsXLmYD8J7FSwf9IL/zkqONr2HF91l3At9qTQWDvwdfee1EOlr/QtZ t5NZvyt4gefvq8ToNewGaTCIOpRTn6qwg+fXyjm5tSYe2Qh1dtiwDarHWxzQUdC9s4yg OMBW3sEDDeu/+7kInafGwi5y02eyzp9XMsQpnFL/D+/xAXd1EkVqSSrrOL58fSw8Vb7H Qm6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=613WbYQy3VVFlZOF3eLN5xkyOMlBNhcO+Ea9HraLr88=; b=kVwKETQMxUEXpQ+pPKcUIykmjsPUPtELq5Z6wwzlZPeRgObvcb8BDlc+mZE6OIqpdQ xFfHPTOzUHJC/MZ9Muf1dFqISbVBpS2HxZn30C7fGiYmBljQ1TWzWAeVK2vFB34J/p+P zmCIpjzhPo7TwqwiXPgnmS7KZywvwk29ZUYGhi9qF3lGs9L0i91r80sLauafN6MApk21 rVTtCzRzB/rMi7FRHsUwK7sMuSCeYcUFDO1yxHAhNjwJ4b7KS5Hlyd8OC6Q+PIwlCMN9 dc3o91tN3mnJr4XKKSQ4d4GtpRVCXEJCNXtFYqNIik/Dv3Q/ZY/r2/VlGMA8R5p+S6NW cuaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xBZEktMj; 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 n10si4758924ejb.539.2020.07.10.15.36.50; Fri, 10 Jul 2020 15:37:13 -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=default header.b=xBZEktMj; 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 S1726736AbgGJWe3 (ORCPT + 99 others); Fri, 10 Jul 2020 18:34:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:45872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbgGJWe3 (ORCPT ); Fri, 10 Jul 2020 18:34:29 -0400 Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D0AB420720; Fri, 10 Jul 2020 22:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594420469; bh=N98sE0T1Wenp2xz8bU/9CGFuY0Q14hRpLDV1a8rPTfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xBZEktMj9lnVDi/7jRtBJyqzvM+VU07KDo+xAU1ggFMejrQ8eI7uVu68ssBJqz8/v jU0AhafpNHvkm+ms4tzTwIRAUwK4dasKLn3QWRlddk04NZE7OFbCS72Z+GL8Q0gOKr Bp3wgOG/f+MMbp/16nLGwlEHAFA3ZaldiMRJ5hP8= From: Stefano Stabellini To: jgross@suse.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Cc: sstabellini@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, hch@infradead.org, Stefano Stabellini Subject: [PATCH v3 01/11] swiotlb-xen: use vmalloc_to_page on vmalloc virt addresses Date: Fri, 10 Jul 2020 15:34:17 -0700 Message-Id: <20200710223427.6897-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Boris Ostrovsky xen_alloc_coherent_pages might return pages for which virt_to_phys and virt_to_page don't work, e.g. ioremap'ed pages. So in xen_swiotlb_free_coherent we can't assume that virt_to_page works. Instead add a is_vmalloc_addr check and use vmalloc_to_page on vmalloc virt addresses. This patch fixes the following crash at boot on RPi4 (the underlying issue is not RPi4 specific): https://marc.info/?l=xen-devel&m=158862573216800 Signed-off-by: Boris Ostrovsky Signed-off-by: Stefano Stabellini Reviewed-by: Boris Ostrovsky Tested-by: Corey Minyard Tested-by: Roman Shaposhnik --- Changes in v3: - style improvements Changes in v2: - update commit message --- drivers/xen/swiotlb-xen.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index b6d27762c6f8..5fbadd07819b 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -335,6 +335,7 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, int order = get_order(size); phys_addr_t phys; u64 dma_mask = DMA_BIT_MASK(32); + struct page *page; if (hwdev && hwdev->coherent_dma_mask) dma_mask = hwdev->coherent_dma_mask; @@ -346,9 +347,14 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, /* Convert the size to actually allocated. */ size = 1UL << (order + XEN_PAGE_SHIFT); + if (is_vmalloc_addr(vaddr)) + page = vmalloc_to_page(vaddr); + else + page = virt_to_page(vaddr); + if (!WARN_ON((dev_addr + size - 1 > dma_mask) || range_straddles_page_boundary(phys, size)) && - TestClearPageXenRemapped(virt_to_page(vaddr))) + TestClearPageXenRemapped(page)) xen_destroy_contiguous_region(phys, order); xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs); -- 2.17.1