Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4035000ybh; Tue, 6 Aug 2019 05:21:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNEGBdFdT30eh6RHeSzPkvHQoTh3l7PqgRiOj6C8cjSj4kUySlrzvV35EeXChvHIN4SC4j X-Received: by 2002:a17:90a:d80b:: with SMTP id a11mr2802179pjv.53.1565094116893; Tue, 06 Aug 2019 05:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565094116; cv=none; d=google.com; s=arc-20160816; b=KgbeYb51D4kjFshwkb6sFoIt+fKairhp4ecMcdDDKMngnZEeNKjw7DW1lj8pqGGGuj PJ4tJ0BxfoLoo+cuKeFmcqoRp//2IUbLsJZZWLZg1i1jmkzKiWoQsMQc+jlepoypCP3u 6INDTfxZB6seaJLOZTPnbFkHuySePMPHtcguB5NuLrm03kFHBOC5LnT0z0bX6bBBz8XR WdIuw7WTT/U6NiD15tbxIR9gK+2Kog7j+cDzOywQnk3YtycUvk/VSf/Z9gWreOQjEtbA rp9xEjkK8HnAPcLTSTQTLNKM2X2SM1Mt1LoGBwzdHwlYnMiIihFQD2+m3e2rusvfAbop va/g== 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=aIK+gSX5Hg2uX7a14sv2tepGovq4tvS4GiJbR+eorrc=; b=UKUwAvKNkjjaG+jicALJQjGMOXtSo8ITj2s3G25N35CPyVYaOsDduJjC4lr5MkN/7Z wpY3OE7KXnZbaJkZjLstyL+a/ZqwoRcnbeFuSPh1n8d2kr5uFZKT+GJvZMyMsUbxmwOy fqq8GmEt1dIhW9fhEvHW3bjCbrxkxCODllPj2fJhct5R1OX0G3JyUtUkCpQk49FVqXEO nO2sailYfQo7aVL9HqDzV6VkN8XPIlPNMVTJ/6Wq1YcthY8N+8mCFj+C+UsPSF1eMf69 rNPOYPp7CJAePyCxN6nmcitBdHEpQJxjYXH4VwJnX+ysd4hKLx1ANcox9nhsKxJ8Bkqd mQqg== 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 i8si14470382pju.32.2019.08.06.05.21.40; Tue, 06 Aug 2019 05:21:56 -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 S1728797AbfHFMVA (ORCPT + 99 others); Tue, 6 Aug 2019 08:21:00 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:33443 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726877AbfHFMVA (ORCPT ); Tue, 6 Aug 2019 08:21:00 -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 1huySY-0006uH-1d; Tue, 06 Aug 2019 14:20:58 +0200 Message-ID: <1565094057.2323.28.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: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Tom Lendacky Date: Tue, 06 Aug 2019 14:20:57 +0200 In-Reply-To: <20190806113318.GA20215@lst.de> References: <1565082809.2323.24.camel@pengutronix.de> <20190806113318.GA20215@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, 13:33 +0200 schrieb Christoph Hellwig: > On Tue, Aug 06, 2019 at 11:13:29AM +0200, Lucas Stach wrote: > > Hi Christoph, > > > > I just found a regression where my NVMe device is no longer able to > > set > > up its HMB. > > > > After subject commit dma_direct_alloc_pages() is no longer > > initializing > > dma_handle properly when DMA_ATTR_NO_KERNEL_MAPPING is set, as the > > function is now returning too early. > > > > Now this could easily be fixed by adding the phy_to_dma translation > > to > > the NO_KERNEL_MAPPING code path, but I'm not sure how this stuff > > interacts with the memory encryption stuff set up later in the > > function, so I guess this should be looked at by someone with more > > experience with this code than me. > > There is not much we can do about the memory encryption case here, Which I would guess means we need to ignore DMA_ATTR_NO_KERNEL_MAPPING in that case instead of dropping out early? > as that requires a kernel address to mark the memory as unencrypted. > > So the obvious trivial fix is probably the right one: > > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > index 59bdceea3737..c49120193309 100644 > --- a/kernel/dma/direct.c > +++ b/kernel/dma/direct.c > @@ -135,6 +135,7 @@ void *dma_direct_alloc_pages(struct device *dev, > size_t size, >   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; >   } >