From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8299439002 for ; Tue, 20 Jan 2026 15:11:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768921895; cv=none; b=OinZCr5aKfUy3BhCDWL0Zs09pBfRDP7X8xHSCYhQg9MGSX0JzcLyB71g4P5dCXgPokOPL0+W9Mus7bDJwTmobqd5hhl2sre3PoF0nyNpQZPUBUNp4SVmYtnfI2BA5+WhKUaeMlhnqo7sMs1hM7WP8vCOisQV1Y6kZFfrdmnqEoY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768921895; c=relaxed/simple; bh=z1JAlWdxRfNL4N3zWMO4F4IvA2PNLQmDwYlXJCnUewE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sb87rC4PyIoSc08uLzoV18/gaJOgh9nKXNYdskl6FqVlKeQUmXgtli6C+38hJkcqbU2A3D9YHy7Tijxb5GKUKDgN4Ke0XSFvP1GlfXqO/RjdxtPvbd4GqUNknhXDRpjaUUgTIvPxJjH4hPRSS+RzNGmziZ8jxD+wcYNKN+WnmLw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=M62flchk; arc=none smtp.client-ip=209.85.160.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="M62flchk" Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-5013c912f9fso63499231cf.2 for ; Tue, 20 Jan 2026 07:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1768921892; x=1769526692; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=NlmbI9zXVktAgfsh6c8tsGYEK/T/Ft6rYTRkQgOh0mQ=; b=M62flchkbh8uqfIs+J13lEnUFecFI9DdRioBaaW1TQU4rdBB70WVWdCBAHcyDKh2TW q0P3KW137duUoTwkTAEA0eE6bto/j/ys/+ARo+xbrVcpY4HJ34ZjRt+/LC6ZyuD/bnuC r/ZjewsB6nZvPI7njCkQM/5MEPlozyq75kQoR/MGZRtv7KxC8ZPvSWV75cfcdf4hMhVp bYgcfjfHJ9eJWmqwxQp3K7qEeEWtXpenI6VCNSUXCyoNcuFN1mYozZivH0tKrvzigSZk 7hnLHeXWOKFE2Qq/8Un+Bv7U9OCRXDimhe1KVuezXI+nldf18e4xdcm4qAtoIil6SNqB kfRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768921892; x=1769526692; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NlmbI9zXVktAgfsh6c8tsGYEK/T/Ft6rYTRkQgOh0mQ=; b=XX/GVEVehQv6XXijykTmmJDk5hQ/4Ue54JXej8mKnNxb342AALyCMr3jTW7mo9oHSL yrXY1BUqh4osgs/x9TgMp9MVmcUr7u8/X23TauRrM3LI8R91YQuWozgrFB1+S7iELKRI 3ZbxJ2erc7Ubam9OmciSNHItxMlNkyG6SJasZFcUslBf27TdxBKkVG2rbTCXbpkZ1XQH t0Nbr/Ih6D305iHAVrS/mfk1/j/NtzPWrFMaFVComg0r+evJCrOK/7qKomr8dFU+py5Z 7ukSNGWDd1HAguzJxjwyV0D7p4TTxdWIlVv9ASTWKR44wiQzLqmDmzsDbiQ1HLwYGjZH 4rvg== X-Forwarded-Encrypted: i=1; AJvYcCW0C3fyp0zWkSSozpWUNo6P0UuFv0IHI9xl5KBaU9pn8CrVmN8RHlVh5eFgghLICnxvE2pnl1qVX+xg+pc=@vger.kernel.org X-Gm-Message-State: AOJu0YyEqwGlyIRlBAgvkwpaD49/TQ/x69Elh6EM5dI+fX0VZ2Q8pmN1 3oJKRcAGOnlfjixbL+Qh39EZwx73Qd+D+1MCgUOZ8tAW3BBYP8d3kSxF45BD92icy/o= X-Gm-Gg: AY/fxX4TQITgzJKO2nkEDcaAQIzIMDJfCm/684dBC92J+GoH/B55RWoyBJlnaZCrDI+ nuerP0a8q3hHTZoBgllaIyDqpsB3eAvckI7HzvDVphPtmXiHz0t2T+vhMcIZoO1P7XjjbtG0gNY rl5hqfnLdtempBht7c5qIdzlSfyaZJ0wknTGqLkag3t3ZSkK9ZB2A2+i5qAkXi1zDH2eiEQvKFc trJdqEPPD+/cN0ZtNUpxvR12lzkDwRgwHmq2EKP1ZqW+y1tGAWkI/zwxDjFVpMfU/aOw9YL5iVc IhjGvHxDpytAeQSKzhRQmo6BoaBdWHuhxNE8dB+pKvWekeXaClPRTTsBdEH9J58EGmhMs/HrgQT pjsSeOvZZxtrXscl5Wr4fAIycDqyEPgbQ/V1q6rukdDHs4IG7KeOVdPucbV04xT+qCn09zRCaa9 cLM4vv3VVkRJ1kC0bso+WgVB+Rs2Svj2l1cm/9NqXyzPn154iBJxmot8tU8oruhz1hl4k= X-Received: by 2002:a05:622a:287:b0:4f1:e928:3fda with SMTP id d75a77b69052e-502a1e07c0emr192323241cf.26.1768921888830; Tue, 20 Jan 2026 07:11:28 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8942e6ad0eesm104011586d6.32.2026.01.20.07.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jan 2026 07:11:28 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1viDOB-00000005XsW-2bF7; Tue, 20 Jan 2026 11:11:27 -0400 Date: Tue, 20 Jan 2026 11:11:27 -0400 From: Jason Gunthorpe To: Suzuki K Poulose Cc: "Aneesh Kumar K.V" , linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-coco@lists.linux.dev, Catalin Marinas , will@kernel.org, robin.murphy@arm.com, steven.price@arm.com, Marek Szyprowski Subject: Re: [PATCH 1/2] dma-direct: Validate DMA mask against canonical DMA addresses Message-ID: <20260120151127.GP961572@ziepe.ca> References: <20260120064255.179425-1-aneesh.kumar@kernel.org> <2a0b6d1b-875a-4075-8fc9-a8534afc9168@arm.com> <0da8b73c-5bec-44c3-9902-221a11142c34@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0da8b73c-5bec-44c3-9902-221a11142c34@arm.com> On Tue, Jan 20, 2026 at 02:39:14PM +0000, Suzuki K Poulose wrote: > > > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > > > > index 8e04f72baaa3..a5639e9415f5 100644 > > > > --- a/kernel/dma/direct.c > > > > +++ b/kernel/dma/direct.c > > > > @@ -580,12 +580,12 @@ int dma_direct_supported(struct device *dev, u64 mask) > > > > /* > > > > * This check needs to be against the actual bit mask value, so use > > > > - * phys_to_dma_unencrypted() here so that the SME encryption mask isn't > > > > + * __phys_to_dma() here so that the arch specific encryption mask isn't > > > > * part of the check. > > > > */ > > > > if (IS_ENABLED(CONFIG_ZONE_DMA)) > > > > min_mask = min_t(u64, min_mask, zone_dma_limit); > > > > - return mask >= phys_to_dma_unencrypted(dev, min_mask); > > > > + return mask >= __phys_to_dma(dev, min_mask); > > > > > > This is wrong, isn't it ? For e.g., for CCA, even though the "Flag" is > > > added to the PA, it is really part of the actual "PA" and thus must be > > > checked against the full PA ? > > > > > > > That is true only when the device is operating in untrusted mode?. For a > > trusted device that mask is valid mask right? > > Irrespective of the mode in which the device is operating, the DMA > address must include the fully qualified "{I}PA" address, right ? > i.e., "the Unencrypted" bit is only a software construct and the full > PA must be used, irrespective of the mode of the device. But you could make an argument that a trusted device won't DMA to shared memory, ie it would SWIOTLB to private memory if that is required. Otherwise these two limitations will exclude huge numbers of real devices from working with ARM CCA at all. Jason