Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4351376ybh; Tue, 6 Aug 2019 10:09:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPjyrKMA5cRacZxnqK0jC248LHrZgRJNnmT/PnNVmYZTxQ9Y8J0DKGT1mD5HhsmFG/RdW0 X-Received: by 2002:a63:4c5c:: with SMTP id m28mr2625260pgl.333.1565111387971; Tue, 06 Aug 2019 10:09:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565111387; cv=none; d=google.com; s=arc-20160816; b=0RCfu4fjm7wMC5NnSxfqbSb74HWUQrO9K8HreadRmGxCy61Tzdko5L+PSjKLTYZbp0 G/JzfhQe2N/qMjTB5jUxo+5zVRPkWGki5K+nbujXiJPkUVonD7Q/8fpxq7RfsFWU4SbK ck3r6j01dgUdecJ1ZsztS3bCYEnu1YETX750M0wuH/6IHp84pmfemgXpSw8EEU62s0uy lG8KOtqAPq8vdQ9c2V836dkhst+cAlMhX5UnhIpuTQhvmPVnGK9xTLKLLySanED90FFl oXj1LBebF7vF/vtjiPAbe4MkKjby3bDbCp7gm4795LwfvvgXszaQjKA7zIrSaijq5+bw cp4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=5KdpW+24Mman5x68fOWsBMlwbbwiBZkdgK9fCtZuosY=; b=ZXck9SxspBDqUJ2tJXg2h4JVshtR8H06bzlvEh7jATL7l/t69RkHdYlBVDXxfpMkyt SJQTi7Dw4KZisaKrdkhhtBOblpk0Ctn839XXAU01H7GI+cJrptCZgpXsHt6pADiXfQoX FkvDKTrMTaNNazecskfQ8HZG1+yqRKYPjCdjP+/8b8xmG62b041SthjtMlSDfKX5vD3F D//t3DbntnUvz+gYC01F3xwY0s7vC0QfY4FsOmbid9EzY/RyRNgRX/iVn1CFRSASg+0m B6WiqDLGhxqmk14q9guldVJF1HsXj+pCAc+/d8CR9GjrOmFuCly2wd1yy9V97C4ds1Ft 1+iA== ARC-Authentication-Results: i=1; mx.google.com; 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 64si41661316ply.15.2019.08.06.10.09.30; Tue, 06 Aug 2019 10:09:47 -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; 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 S1732437AbfHFPoJ (ORCPT + 99 others); Tue, 6 Aug 2019 11:44:09 -0400 Received: from verein.lst.de ([213.95.11.211]:57434 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728558AbfHFPoJ (ORCPT ); Tue, 6 Aug 2019 11:44:09 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 9842B227A8A; Tue, 6 Aug 2019 17:44:03 +0200 (CEST) Date: Tue, 6 Aug 2019 17:44:03 +0200 From: Christoph Hellwig To: Lucas Stach Cc: Christoph Hellwig , "Lendacky, Thomas" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , Thiago Jung Bauermann , Halil Pasic Subject: Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code) Message-ID: <20190806154403.GA25050@lst.de> References: <1565082809.2323.24.camel@pengutronix.de> <20190806113318.GA20215@lst.de> <41cc93b1-62b5-7fb6-060d-01982e68503b@amd.com> <20190806140408.GA22902@lst.de> <1565100418.2323.32.camel@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1565100418.2323.32.camel@pengutronix.de> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 06, 2019 at 04:06:58PM +0200, Lucas Stach wrote: > > dma_direct_free_pages() then needs the same check, as otherwise the cpu > address is treated as a cookie instead of a real address and the > encryption needs to be re-enabled. Ok, lets try this one instead: -- From 3a7aa9fe38a5eae5d879831b4f8c1032e735a0b6 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Tue, 6 Aug 2019 14:33:23 +0300 Subject: dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign a dma_addr to work. Also skip it if the architecture needs forced decryption handling, as that needs a kernel virtual address. Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code) Signed-off-by: Christoph Hellwig --- kernel/dma/direct.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 59bdceea3737..4c211c87a719 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -130,11 +130,13 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size, if (!page) return NULL; - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) { + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) && + !force_dma_unencrypted(dev)) { /* remove any dirty cache lines on the kernel alias */ if (!PageHighMem(page)) arch_dma_prep_coherent(page, size); /* return the page pointer as the opaque cookie */ + *dma_handle = phys_to_dma(dev, page_to_phys(page)); return page; } @@ -178,7 +180,8 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr, { unsigned int page_order = get_order(size); - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) { + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) && + !force_dma_unencrypted(dev)) { /* cpu_addr is a struct page cookie, not a kernel address */ __dma_direct_free_pages(dev, size, cpu_addr); return; -- 2.20.1