Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1405410pxk; Fri, 4 Sep 2020 08:36:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1NeoxP4t7+sRaSQgf9lhE/hBkGJ6bgwaSNf0RdWE7uR9EnvknDN+8yCEPrRVqsVffIlsp X-Received: by 2002:a17:906:941a:: with SMTP id q26mr7975777ejx.496.1599233760293; Fri, 04 Sep 2020 08:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599233760; cv=none; d=google.com; s=arc-20160816; b=oqpBLI48hvHCf5s6AUHES5FGrTChaT64jLtlYgY7OB+JVt06Pw64YNFnBkXpsa3GBU obLnvufY4H8JO453v5/xOWwAVuc5xQAEl5p6Qg4vbgcAQXmtRn53CJS/uzsV7ArXMLmw E7+Fu6weUSu2tWaTZaSf1b5U70q2xBr0JortIfkT1IodntnD3bp3gF0puZvrFlMVlGhW qkfD4B+pg5Epu0g7Ii/1cVHaZtit5Rx74xGUPIdvq4cl2+DSKEcNdUBKf+GK3TBKSNQx tWOYE/a1DMXEeNBf8hhbCYUCYUgZEgCfGXHj06PCF3lNr5lBI4IupHfsfGX+lVa4dzf5 DxPA== 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=N5is4++o+cZpLltQz160G/KsGwk93Vbd0f89QEMtCy8=; b=HnB5/HsPbYL5i4vpUHADiEGG6PGuMZu/lQzV7gDwqOK3/DiQUlwiUFpY57qQ8YWYaM ZoDmczhx1eZr6VqVgR1cX/1yQrwh+4QZ6vXM5TwwqtFnWCrhX3BGNAhtrILfex3LEIr+ 6b9zi9frkEyAYtyG0cSED0kJCK1ZTeuYfhxnOU1WEloIMsfxWQpECsAvH7Kv0U8BHwGN be75rUP2D5YRvT8XOluBZim9SwFlsZdfmlYeSL7L713L8TvLIk7KG+Tqndb+Ra2RtGS9 /5sMbS2R/NstMcleD3X7yA7HKQvvB8+vrFD5Xdm7VjT1/rVrHVzEQ7oNxuc6gbHRpB4a A5yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=OSKCiZVY; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=OSKCiZVY; 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 12si4414034edv.587.2020.09.04.08.35.36; Fri, 04 Sep 2020 08:36:00 -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=OSKCiZVY; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=OSKCiZVY; 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 S1726871AbgIDPep (ORCPT + 99 others); Fri, 4 Sep 2020 11:34:45 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:47250 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726111AbgIDPem (ORCPT ); Fri, 4 Sep 2020 11:34:42 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id E23378EE112; Fri, 4 Sep 2020 08:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1599233681; bh=aqBYVVDxSPcR+4WRGd2XXdbYUrXI1R2tpGt8e2CxOqk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=OSKCiZVY/HICluT+E+gBea2klKfGTnSyh+e5emDR2r1NB8op0pvrrhFcgY6WpLXfi BgwwbeRb5VG2jPAx3sUPZQpMPsfm8M1dAfUAh8brrNXhqqe8gVtdtzwSB3orIrDD7l YoD02xMi9/Vnz3qACuvRNiD5YpaTVrPCKQCyS0ro= 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 0lY_VcvizQiN; Fri, 4 Sep 2020 08:34:41 -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 432438EE064; Fri, 4 Sep 2020 08:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1599233681; bh=aqBYVVDxSPcR+4WRGd2XXdbYUrXI1R2tpGt8e2CxOqk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=OSKCiZVY/HICluT+E+gBea2klKfGTnSyh+e5emDR2r1NB8op0pvrrhFcgY6WpLXfi BgwwbeRb5VG2jPAx3sUPZQpMPsfm8M1dAfUAh8brrNXhqqe8gVtdtzwSB3orIrDD7l YoD02xMi9/Vnz3qACuvRNiD5YpaTVrPCKQCyS0ro= Message-ID: <1599233679.5231.4.camel@HansenPartnership.com> Subject: Re: [PATCH] dma-direct: zero out DMA_ATTR_NO_KERNEL_MAPPING buf From: James Bottomley To: Hillf Danton , Christoph Hellwig Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Kees Cook , Matthew Wilcox , Marek Szyprowski Date: Fri, 04 Sep 2020 08:34:39 -0700 In-Reply-To: <20200904152550.17964-1-hdanton@sina.com> References: <20200904152550.17964-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 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); This is massively expensive on PARISC and likely other VIPT/VIVT architectures. What's the reason for clearing it? This could also be 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. James