Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp844254ybg; Wed, 3 Jun 2020 15:29:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjJ08sTnAzEpnwjfEvAf+MYEOqt9KDS7a/25krYB6odo16oCyzQx2f0xJ1tOogwcigEnGI X-Received: by 2002:a50:b5c3:: with SMTP id a61mr1634527ede.80.1591223339935; Wed, 03 Jun 2020 15:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591223339; cv=none; d=google.com; s=arc-20160816; b=Dnt0ld3GCSppas81HlCbaVG7Md1TN3q3BHkCQiPXobzhquta7PAjCYEHGDVCPZajgi GXRhoqZmKY+a8xHV2N5peO8C9PbOYhLHgGNy4AA90c7yOWaWjLrPcPuqGwbW/RQfxcoc 8aDgDfs1Va1fGZWTaRmhjuWGChgUMGr700DTywICDUtARWOx+BiwK3INrUcE3Rt95r6y EnE75ClQLu10qopGRudCseJ3/LtxeHH+rPRqCz+jrNWCqvT68eNRdTKWSWrhYBBTxwQr JN4EhaxVueQNSQS+EmcGPcJTx9sCAAHlaZBtYyBqKgiemCEC4Q4TtcjOL4DKak6ZJ1gv FRAQ== 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=di9L3FYuPBWzwFudkBEbAHGpkskeBuF3hNTauVPFo4Y=; b=KSBtFpTUNOJOU+cAePpuoCPKKcbWfsGLElLIPSPDMTIe/O2K+PirTb0DHDg+o+chLZ 7aFkYrYqZg+57VZR6AEOv0ZuJwokFag+c+o7jKXcuj7SVr7Qo2bHo43O2/l4gJ9sbqY4 zRak2SFG5SL+kQhDGykn3Ti4OdlF+SgRVlUTFjQjLT0S5i9sTJ4k56R0e2P8leG3QfsF HaRFUbU9JVDWy5vuQVYNVUNaV2tdWrD/mpSZgkZ4rMhydVa9+sGYVsTl7hYwYcZlhbBb 5xS6AB+g7HjoQ6B2Syw+XoOxq6R+qI8P4e85QBKRhsGMThkW7VD8SqAaqcLNUngiaBqt epaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="iS/9d1NE"; 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 r8si497522edi.43.2020.06.03.15.28.36; Wed, 03 Jun 2020 15:28:59 -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="iS/9d1NE"; 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 S1726865AbgFCWWu (ORCPT + 99 others); Wed, 3 Jun 2020 18:22:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:56546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbgFCWWt (ORCPT ); Wed, 3 Jun 2020 18:22:49 -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 D431C2067B; Wed, 3 Jun 2020 22:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591222969; bh=KkHGhoUNVUm6PPU2Wc3n69d1PFrjoUPau99hvQGcD1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iS/9d1NEK4nODfzf/8QcScf3N+hmvvrgLTCxl91JpBRBcydxeV138kYdTqiJMEt9b nhYp1DoW/P0X+h2Do5xbSeYfbg7p+rgwfDoq04oiBlfmzPiGObo11WusHd99feCP+G hdz7+XBkfDJCmzl8jFCi1R+GtcVCvV0kGA2FLHcQ= 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, tamas@tklengyel.com, roman@zededa.com, Stefano Stabellini Subject: [PATCH v2 01/11] swiotlb-xen: use vmalloc_to_page on vmalloc virt addresses Date: Wed, 3 Jun 2020 15:22:37 -0700 Message-Id: <20200603222247.11681-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: https://marc.info/?l=xen-devel&m=158862573216800 Signed-off-by: Boris Ostrovsky Signed-off-by: Stefano Stabellini Tested-by: Corey Minyard Tested-by: Roman Shaposhnik --- Changes in v2: - update commit message --- drivers/xen/swiotlb-xen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index b6d27762c6f8..a42129cba36e 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 *pg; if (hwdev && hwdev->coherent_dma_mask) dma_mask = hwdev->coherent_dma_mask; @@ -346,9 +347,11 @@ xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, /* Convert the size to actually allocated. */ size = 1UL << (order + XEN_PAGE_SHIFT); + pg = is_vmalloc_addr(vaddr) ? vmalloc_to_page(vaddr) : + 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(pg)) xen_destroy_contiguous_region(phys, order); xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs); -- 2.17.1