Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2108114pxk; Sat, 5 Sep 2020 08:49:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGn9J202ptM9pswyeoRLFE/FoW99E4iOwGj6zcBUkxCvMxPe7stcPC9ayyj009+YTiOW2H X-Received: by 2002:a17:906:4b4a:: with SMTP id j10mr8329383ejv.498.1599320998449; Sat, 05 Sep 2020 08:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599320998; cv=none; d=google.com; s=arc-20160816; b=wLcpqtYZ90ZrrBTwGpCESyHe0/VJnR+oeCrFSd3IKNt/MG/0elu41VcUMtJQzsbqIs pGwm5ejeWdLwsEHKpzOTb9aFWxLZJgXA3Tla2swI5jJ03Y5COR06aXgMnaNirhpfsGBK EaF9HKvNxlfq8Kxjv9ueIn6UkumSJlnLUTvZUTNPAFWxJU8QPfHAJy11N1cjt8FC8Vwm qcjuP5ffIHdYF1y7btV/y/gne8aOFII4xDDA3YPFio9SLIKyJWjul4hOyTOeniiJg3Z+ KRUSe7Lg7dhATh5q82pZ/AtPjYEUFKLnTes/LcxQ7xIIPuRAjjzaQdKWaGM4UBGrWxK1 P0eg== 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 :dkim-signature:dkim-signature; bh=nNIN/fO5ScDfqlxnkEYI7au/E+sNivrjD4V1zUF5rA8=; b=YWCYxlmpV2kYjxLb50QAZiCKNv54kDXPrvBwoVdI7CmhSIWu3wapE+S3oWuFIBjCTi MLWeOCF7+zpCDSuQN+vVOmIbVnKcKqXUCmc9T04WegXO/NZUH7JVsUndNlO96Z+a8zaA AN/j+nMkh//uPFynOa4+yUTFvTo77mlWuATv6EYuYJCnSeVbJyoZiGrdFFSUnZUAIJcu dF/fxgaYw8sk3crXAqkvzwP9eudSQybK+iszLSmkC1tyBCrFyV4+SMgDCpa4guIFzT+W u2jA0aP5eMitcSPO0ECo64YOW+L2ruvluJVd6hgceuLqr9knKkXM74UxECkaiAdFNdUB 17RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b="IPcOeu/n"; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=mke0N8Gm; 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=fail (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c25si6276288edr.545.2020.09.05.08.49.34; Sat, 05 Sep 2020 08:49:58 -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=fail header.i=@hansenpartnership.com header.s=20151216 header.b="IPcOeu/n"; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=mke0N8Gm; 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=fail (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728248AbgIEPqu (ORCPT + 99 others); Sat, 5 Sep 2020 11:46:50 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:46572 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbgIEPqk (ORCPT ); Sat, 5 Sep 2020 11:46:40 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 1F5638EE112; Sat, 5 Sep 2020 08:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1599320799; bh=uuZwcuWqye3Jc50GpB/RasDOKF7Bok/BlMWQ3nC8shA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=IPcOeu/nD8EEaTOanrSjdimEprZPoxMXq+HbxBPlWLjLXBUHVzSjaXACgrHe+4Jy+ aEA8fhvxKFQjuoWylT7lwvB4zCsht2sCqNnw4bvED9g5hxODMpsg6k6iUFJm9jkS/4 5M0Ug4oKqKBSUPmoEbfMV2wu4jr7PzXO8iFTOkD0= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xRcJOAM4hkOC; Sat, 5 Sep 2020 08:46:38 -0700 (PDT) Received: from [153.66.254.174] (c-73-35-198-56.hsd1.wa.comcast.net [73.35.198.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id C87418EE100; Sat, 5 Sep 2020 08:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1599320798; bh=uuZwcuWqye3Jc50GpB/RasDOKF7Bok/BlMWQ3nC8shA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=mke0N8GmVsaGqDCnDo1Xevave0JV+Ok2cWL6w8idVDY1Ot0Fj/AbNErCQQRg3ESYs 3jgSfrtRZagN7f0a8PfMR2oRtAz3nSfMt+fuXzkKruqdGOJlDSNW72Stg7HclqO/N+ JuyCutuhMmqqeGaf7bkGnnUGnkZe/XQ336n3uKRs= Message-ID: <1599320796.11726.5.camel@HansenPartnership.com> Subject: Re: [PATCH] dma-direct: zero out DMA_ATTR_NO_KERNEL_MAPPING buf From: James Bottomley To: Hillf Danton Cc: Christoph Hellwig , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Kees Cook , Matthew Wilcox , Marek Szyprowski , linux-arch@vger.kernel.come Date: Sat, 05 Sep 2020 08:46:36 -0700 In-Reply-To: <20200905073528.9464-1-hdanton@sina.com> References: <20200904152550.17964-1-hdanton@sina.com> <20200905073528.9464-1-hdanton@sina.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2020-09-05 at 15:35 +0800, Hillf Danton wrote: > On Fri, 04 Sep 2020 08:34:39 -0700 James Bottomley wrote: > > On Fri, 2020-09-04 at 23:25 +0800, Hillf Danton wrote: > > > The DMA buffer allocated is always cleared in DMA core and this > > > is making DMA_ATTR_NO_KERNEL_MAPPING non-special. > > > > > > Fixes: d98849aff879 ("dma-direct: handle > > > DMA_ATTR_NO_KERNEL_MAPPING > > > in common code") > > > Cc: Kees Cook > > > Cc: Matthew Wilcox > > > Cc: Marek Szyprowski > > > Cc: James Bottomley > > > Signed-off-by: Hillf Danton > > > --- > > > > > > --- a/kernel/dma/direct.c > > > +++ b/kernel/dma/direct.c > > > @@ -178,9 +178,17 @@ void *dma_direct_alloc_pages(struct devi > > > > > > if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) && > > > !force_dma_unencrypted(dev)) { > > > + int i; > > > + > > > /* remove any dirty cache lines on the kernel > > > alias > > > */ > > > if (!PageHighMem(page)) > > > arch_dma_prep_coherent(page, size); > > > + > > > + for (i = 0; i < size/PAGE_SIZE; i++) { > > > + ret = kmap_atomic(page + i); > > > + memset(ret, 0, PAGE_SIZE); > > > + kunmap_atomic(ret); > > Hi James > > > > This is massively expensive on PARISC and likely other VIPT/VIVT > > architectures. > > Correct. > > > What's the reason for clearing it? This could also be > > /* we always manually zero the memory once we are done: */ > gfp &= ~__GFP_ZERO; > gfp |= dma_direct_optimal_gfp_mask(dev, dev->coherent_dma_mask, > &phys_limit); That's not a reason ... that comment was put in for coherent mappings. What is the reason we should incur all this expense for clearing pages which aren't unmapped in the kernel, because we can update the comment? The usual rationale for kernel mapped pages is security, because they may leak information but unmapped pages shouldn't have this problem. > > really inefficient even on PIPT architectures if the memory is > > device remote. > > > > If we really have to do this, it should likely be done in the arch > > or driver hooks because there are potentially more efficient ways > > we can do this knowing how the architecture behaves. > > I'm open to any vintage ideas in your mind wrt clearing dma buf e.g > on platforms like PARISC. Or feel free to offload me the work if it > makes sense to you who are rich of PARISC knowledge. OK, I've cc'd linux-arch because this is a problem for more than just parisc. However, not having to do it is the best solution ... sort of the doctor, doctor it hurts when I do this answer. James