Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5593933ybh; Wed, 7 Aug 2019 08:25:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaxNs/9HymW5g03JUshdfGPF2FreZnqazSmdhPC/a/qLVW4qRDAJ6p/jJfosGAh75fui/R X-Received: by 2002:a63:7e1d:: with SMTP id z29mr8217594pgc.346.1565191527859; Wed, 07 Aug 2019 08:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565191527; cv=none; d=google.com; s=arc-20160816; b=XPQWQ1TubXHpa1QlmdUxAf5Twvx1fUHL20/dDB8z9uXgQOq1rT5rBzA3Q5ayXyh8Pd Qj7cqPVci/VRXTGG9SZ95OvdnRDudFri2de7TNfRhi4xOiNhdJspKr/j58dpQPBTTa3w hXy9WLsMmQ99CFVcGxmB+byXmJF9EmMcg/2GXyxXv2d3rBFq1zLJDpieONMS/trJs03E 521yRA7LYA9EDk00pkk1XK3Ppz0Ihw8xLKyt2zAlXGEjlI7BGUbmW0DjkJPn+HX9Kqzp 327OlmfFjcr72LnwECc3kcRqAAOEHwslOLoKl0bUk5dVgxGDSm8x13pTNj15oXC0TpLk 5Hlw== 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 :references:in-reply-to:date:cc:to:from:subject:message-id; bh=On+WmCOJ4KsUWjoIuD25ItWNXlQlosPzOa88nAkl0a0=; b=sYxSRwrhaJ0g1aTEtgOS0yUnW8Aw5IJ9Y6mpBachjy6dZT8Lk7aQH9B/bNmYe5yegn Ec2aIrnA6pu6HoBYrAeRkfpawR0LbzqIe6NduX0QAqyfPYwou/M25kw8acCSLfa4QnC4 oQAePsOfcZOjeIR/aoSyUNVu+62NjlShWgelbs+AohjgAb52kcMcgJ5fSPQ5i4OEENpc sRe8CelEus10qwJD4DjLD027vN3m6luwngBiT9T6h+Fg1pvK84iNn9qkkx41GV+JhXpn AlOjPsxXcWFHOfXzpU/Z0G3XHZhf+ByVtImn1T4NDI9aFjOUH1Iml4gcXJ7V0v8PXMqA 1TZA== 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 e17si15821562pgt.192.2019.08.07.08.25.12; Wed, 07 Aug 2019 08:25:27 -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 S2388530AbfHGPYX (ORCPT + 99 others); Wed, 7 Aug 2019 11:24:23 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:42421 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387815AbfHGPYW (ORCPT ); Wed, 7 Aug 2019 11:24:22 -0400 Received: from kresse.hi.pengutronix.de ([2001:67c:670:100:1d::2a]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1hvNnX-00089B-00; Wed, 07 Aug 2019 17:24:19 +0200 Message-ID: <1565191457.2323.41.camel@pengutronix.de> Subject: Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code) From: Lucas Stach To: Christoph Hellwig Cc: "Lendacky, Thomas" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , Thiago Jung Bauermann , Halil Pasic Date: Wed, 07 Aug 2019 17:24:17 +0200 In-Reply-To: <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> <20190806154403.GA25050@lst.de> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::2a X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Dienstag, den 06.08.2019, 17:44 +0200 schrieb Christoph Hellwig: > 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)); I would suggest to place this line above the comment, as the comment only really applies to the return value. Other than this nitpick, this matches my understanding of the required changes, so: Reviewed-by: Lucas Stach >   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;