Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2148608ybm; Thu, 23 May 2019 12:09:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaTRChSf1+IlBdkZOKVIy3CstOquyT8LnosgTDoCvXLffTmPkR3Aac/2hUenYj/BK6j5DQ X-Received: by 2002:a17:902:446:: with SMTP id 64mr100445150ple.322.1558638598209; Thu, 23 May 2019 12:09:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558638598; cv=none; d=google.com; s=arc-20160816; b=gBYsTTjV/oFJSgOYRRqIkRsKhjK8a+x2iD0tHInSBeaFK4bXHBtw49lE3d6oHxHS61 wrdQUGP2TY9bORfUG+X6GsdRjDrJhtOP9ZUmVwGwHrEuDC4gatD66Xh5NANsus8aUAb0 SVaCDPAiAe+P6LRtXXgcwT2atwRPXR/Xs7lirbtFo2HMs824ia+wrqTpjRZu4sKbCZqF p1IRMZG/Qm3OXQwiBB3ZYbmgo/UBAKZ3nYxAHAgxnn1Chm8ud1rbjIZNRGtrjS4S4ULv m/uL4zos24bLoeBq4SmctnOHJKiJhTNxQPFRUBzkt1On6B2K+69JoNkvo4Nz91wgdcQd 3ssg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R4wkpTKKgI271wcYqK+F/k6QOTpyzEbY8zKzApXBX3s=; b=cYlRBBk4qpdLZ8Fh+57ea6PZVcXRfq1p28lO8H4lx9LXoNGYeap7hhCrng4DZ5JHLz 9AQjrKg53QDeNSM3iV+eSxTD7pFnXkoSg6PEbjHAU/gTNKQaJT/1dlRDKmfyERDIeQAz MnQYh7QdVnrlXhf7XUvUjT9LZOKfISQrb5N3CV23VwDL7sFaEQYeS8imspo8U/gHsom0 eB3uySFDMqF5ujNoyVu0ELRato17WerVV/heGGLceFAqEOcdkSkR8+uYDavTXwYv6tKZ d0kJB+BE61BBaacGXt2+FB2+ZYLOt18J2YEO8DCnPXA7/9MG1qLnP40mu6X+y9HLMCgl pK0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GcwADktI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u133si357138pfc.72.2019.05.23.12.09.43; Thu, 23 May 2019 12:09:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GcwADktI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731730AbfEWTI0 (ORCPT + 99 others); Thu, 23 May 2019 15:08:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:41166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731464AbfEWTIZ (ORCPT ); Thu, 23 May 2019 15:08:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B7E70217D7; Thu, 23 May 2019 19:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558638504; bh=Ial3fphRF7+fx0HeHk/iihCGNqhGfW0Xc8IFSzHi/mY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GcwADktIp/7/Ei+Mxe91DSfLyIe4ZaPDDwtNbeTd5ZAQzqIvFgCGiqbxPZi1zaxgz MvDRDPpQzMVILLiqyOVG4ncpmbOR72yapF3F3ESk7KcoV5c+LIc3R6xu4Tj2NvS4RZ mfwiaCZR5WkgOJzE+MW1Zu1BY5v7+nx4lEsgdqFE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Shishkin Subject: [PATCH 4.9 13/53] intel_th: msu: Fix single mode with IOMMU Date: Thu, 23 May 2019 21:05:37 +0200 Message-Id: <20190523181713.011377416@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181710.981455400@linuxfoundation.org> References: <20190523181710.981455400@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Shishkin commit 4e0eaf239fb33ebc671303e2b736fa043462e2f4 upstream. Currently, the pages that are allocated for the single mode of MSC are not mapped into the device's dma space and the code is incorrectly using *_to_phys() in place of a dma address. This fails with IOMMU enabled and is otherwise bad practice. Fix the single mode buffer allocation to map the pages into the device's DMA space. Signed-off-by: Alexander Shishkin Fixes: ba82664c134e ("intel_th: Add Memory Storage Unit driver") Cc: stable@vger.kernel.org # v4.4+ Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/intel_th/msu.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) --- a/drivers/hwtracing/intel_th/msu.c +++ b/drivers/hwtracing/intel_th/msu.c @@ -90,6 +90,7 @@ struct msc_iter { * @reg_base: register window base address * @thdev: intel_th_device pointer * @win_list: list of windows in multiblock mode + * @single_sgt: single mode buffer * @nr_pages: total number of pages allocated for this buffer * @single_sz: amount of data in single mode * @single_wrap: single mode wrap occurred @@ -110,6 +111,7 @@ struct msc { struct intel_th_device *thdev; struct list_head win_list; + struct sg_table single_sgt; unsigned long nr_pages; unsigned long single_sz; unsigned int single_wrap : 1; @@ -623,22 +625,45 @@ static void intel_th_msc_deactivate(stru */ static int msc_buffer_contig_alloc(struct msc *msc, unsigned long size) { + unsigned long nr_pages = size >> PAGE_SHIFT; unsigned int order = get_order(size); struct page *page; + int ret; if (!size) return 0; + ret = sg_alloc_table(&msc->single_sgt, 1, GFP_KERNEL); + if (ret) + goto err_out; + + ret = -ENOMEM; page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order); if (!page) - return -ENOMEM; + goto err_free_sgt; split_page(page, order); - msc->nr_pages = size >> PAGE_SHIFT; + sg_set_buf(msc->single_sgt.sgl, page_address(page), size); + + ret = dma_map_sg(msc_dev(msc)->parent->parent, msc->single_sgt.sgl, 1, + DMA_FROM_DEVICE); + if (ret < 0) + goto err_free_pages; + + msc->nr_pages = nr_pages; msc->base = page_address(page); - msc->base_addr = page_to_phys(page); + msc->base_addr = sg_dma_address(msc->single_sgt.sgl); return 0; + +err_free_pages: + __free_pages(page, order); + +err_free_sgt: + sg_free_table(&msc->single_sgt); + +err_out: + return ret; } /** @@ -649,6 +674,10 @@ static void msc_buffer_contig_free(struc { unsigned long off; + dma_unmap_sg(msc_dev(msc)->parent->parent, msc->single_sgt.sgl, + 1, DMA_FROM_DEVICE); + sg_free_table(&msc->single_sgt); + for (off = 0; off < msc->nr_pages << PAGE_SHIFT; off += PAGE_SIZE) { struct page *page = virt_to_page(msc->base + off);