From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19567C433EF for ; Thu, 23 Jun 2022 09:01:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231138AbiFWJBn (ORCPT ); Thu, 23 Jun 2022 05:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbiFWJBm (ORCPT ); Thu, 23 Jun 2022 05:01:42 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4298246B10; Thu, 23 Jun 2022 02:01:40 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BB85912FC; Thu, 23 Jun 2022 02:01:40 -0700 (PDT) Received: from [10.57.85.4] (unknown [10.57.85.4]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 383EF3F792; Thu, 23 Jun 2022 02:01:39 -0700 (PDT) Message-ID: <59c365d8-4b76-4e57-794b-e1d4b3f0e2a5@arm.com> Date: Thu, 23 Jun 2022 10:01:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH] dma-direct: use the correct size for dma_set_encrypted() Content-Language: en-GB To: Dexuan Cui , Christoph Hellwig Cc: "m.szyprowski@samsung.com" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "Michael Kelley (LINUX)" , Andrea Parri , Tianyu Lan References: <20220622191424.15777-1-decui@microsoft.com> <20220623054352.GA12543@lst.de> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-06-23 08:00, Dexuan Cui wrote: >> From: Christoph Hellwig >> Sent: Wednesday, June 22, 2022 10:44 PM >> To: Dexuan Cui >> ... >> On Wed, Jun 22, 2022 at 12:14:24PM -0700, Dexuan Cui wrote: >>> The third parameter of dma_set_encrypted() is a size in bytes rather than >>> the number of pages. >>> >>> Fixes: 4d0564785bb0 ("dma-direct: factor out dma_set_{de,en}crypted >> helpers") >>> Signed-off-by: Dexuan Cui >> >> see: >> >> commit 4a37f3dd9a83186cb88d44808ab35b78375082c9 (tag: >> dma-mapping-5.19-2022-05-25) >> Author: Robin Murphy >> Date: Fri May 20 18:10:13 2022 +0100 >> >> dma-direct: don't over-decrypt memory > > It looks like commit 4a37f3dd9a831 fixed a different issue? > > Here my patch is for the latest mainline: > > In dma_direct_alloc()'s error handling path, we pass 'size' to dma_set_encrypted(): > out_encrypt_pages: > if (dma_set_encrypted(dev, page_address(page), size)) > > However, in dma_direct_free(), we pass ' 1 << page_order ' to dma_set_encrypted(). > I think the ' 1 << page_order' is incorrect and it should be 'size' as well? I think technically you're both right - these instances clearly have a history tracing back to the original bug that my patch addressed, but the refactoring then made them into their own distinct bug in terms of the internal dma_set_encrypted() interface, per the commit message here. Apparently I failed to spot this when forward-porting 4a37f3dd9a831 from 5.10 (as the commit message says, don't ask... ;) ) - I guess I was only looking at where the set_memory_*() callsites had moved to. For this patch, Reviewed-by: Robin Murphy Thanks Robin.