From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 3163148C8A5 for ; Wed, 13 May 2026 17:24:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778693110; cv=none; b=N5UhhyFWqpGEiMibyJi8POjNIJxrMij3kkijUUTyQqJNcv++lstMflZL5K7wTRbS9EjYdXyAumiy+JJKIk+n+z2SGZF5C1wfFcE78LSpv78Ps4OA6dbOqgy+pefwyBvKxEoest0UjAjXfMih1BjEDHJuw+63Em4dOeREdCTbVn0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778693110; c=relaxed/simple; bh=BfC504n+kThMXbLodptWdwF+5sTWwaf4D5wXQNX5RnE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AwJFybSVC3zKkTuJ9rcIowKMuydgSAtsMHBmMHeUpnqW/1bOnC9oLX6Vm/k4fTtUyh9T3qg/tx69bA7Xk/kHGzjXY60YmpN9HbacGfae83cSBtEs/CCA/BKNmyb0zITyeS/m4vlNm3VUAICewzJ9mU5uMddcXeQqT9yXMBkqoDg= 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=Grm08l/c; arc=none smtp.client-ip=209.85.222.181 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="Grm08l/c" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-8cb40149037so653871385a.2 for ; Wed, 13 May 2026 10:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1778693092; x=1779297892; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=fQtwNmxswhQih8gmC6FPDl+zfVKzr3i0rq4YmglfcBk=; b=Grm08l/c2QX0cUK33emAUMJqEP8/C1QHmgP06iVG3PsVSVBDg4DycrWgdqqYLskFUH XMYIPSq9n0YhVFhNSA48SlIC8JM3L0RpBExlf8uY/2nymk4Chbb2UP9UAWdcJSIpU+O6 4APh7F5FQ5swGH8MlbS36UwKs9F5ac91eIT5YcXZ7E9uoxfaqbYfACq1YFSQXHzkf+28 fqQrOH4QJ7Fh4Yi7dOzPfUgT+SnIxWgbDRUK/wPvzFqYYm4Zq0s8F0orUjiepEY4Gxek KMVizDXugein1K8quZdaY4YIeF+gAiXLDUkHJDY5zdYfUdzSyzyZ0MPJ2US4F/227oZ4 +RzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778693092; x=1779297892; h=in-reply-to:content-transfer-encoding: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=fQtwNmxswhQih8gmC6FPDl+zfVKzr3i0rq4YmglfcBk=; b=mkzv8uWK3nU76E8y4YhEx6e1zoTFTU+2bXsfL5WyisRXxEZh+qoqOggI+e7AbN+TYw Ne05dNHu6GjtuH7eKg9xXeQqUz+IbfQvkqeheL6ZeDGnSQOFO5Xy99JdjxxLYwwFs/lP gr65fvNgL2bKV7kwCwPbetzOssqDqn4yIvOdzh6+O4EwvH9B0hGf6pb3VUnQfsNqxbnN hHcN3ps0w7QQ/KRPKua824sS5Rjm1guCstO1u1vV6JBzWIISQ8ZlOsrvH8p4LRfeKBY/ fA4UHYqPsgyaL1wKJEk1LBjvWjVaAomYozqN1c4Cf//b3lqSlyJHA5U2ZpjKmK4zQR5Z f0lw== X-Forwarded-Encrypted: i=1; AFNElJ8hbn9kXlNU3J2gKaO/pfLsz78YNN7X0BA+YefHBO2RhUi9dcFE65UEWc/dWg3O6dG7nv9IK0jXW9bKrSA=@vger.kernel.org X-Gm-Message-State: AOJu0YynDjrJQD8WrtG0Q2KYbN05c/Z3VtiE2Fliyrkd7cCGvy4cTKeJ 7Sjcw/XXzD3gHTcf98iyrgMpFTWBxSyFHAEc68eJijRi8xBlm8cZ5frWbaX1eOSM3ck= X-Gm-Gg: Acq92OGlRytD7eIV0pDYRGbE8GsR153dCGgs56s/rSPmTXwO54hxL3CyPVggQzxRaAR f7CMYgMffDfGw03V0lgWaLMPkdFXU2jE2Vo6yPy8451QbJ7bShaNWN9xxEUxC1OTFPD6R9QDJf7 V3jtW+wUpkVUtTnoqMbIUVq08xe9n7pMDdLbFfcWgo4+cAzVU0iIBHin2WY4QJG4Vo+qptsOh8f WFAgpQhUEnZx2iW1HQiZGvOSjAmxe5crPDpz5cy9gj/ZDSdQsJTcChqPDPqfFFvZ+DnDyT6GoCm d7DDa9pe6zLO0HN6wlSGru+KEJX31v7dS2VgYF78Bt+vXC/SGvBQ5cYHxkCySejDZug5hntRbah qVNCn+a2DcoAOfZnOr2pwYTxg6s3gSovlyQLTv3puopKLQqX14vDL3OjvtOwTxPCotPjo8qrCrA CPv/NuKdTr135u82KhIkCP8M6gq0K+UPOq4AxXq9FAdFJkL3GoSaKWdRbsH7TqCYCvUOHidi7/z +BiBQ== X-Received: by 2002:a05:620a:19a3:b0:8ee:42cc:4d9c with SMTP id af79cd13be357-90f8ac08735mr658592985a.39.1778693092335; Wed, 13 May 2026 10:24:52 -0700 (PDT) Received: from ziepe.ca (crbknf0213w-47-54-130-67.pppoe-dynamic.high-speed.nl.bellaliant.net. [47.54.130.67]) by smtp.gmail.com with ESMTPSA id af79cd13be357-910bc83bbf5sm13598685a.28.2026.05.13.10.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 10:24:50 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wNDKE-00000003dZu-0jxL; Wed, 13 May 2026 14:24:50 -0300 Date: Wed, 13 May 2026 14:24:50 -0300 From: Jason Gunthorpe To: Mostafa Saleh Cc: "Aneesh Kumar K.V (Arm)" , iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, Robin Murphy , Marek Szyprowski , Will Deacon , Marc Zyngier , Steven Price , Suzuki K Poulose , Catalin Marinas , Jiri Pirko , Petr Tesarik , Alexey Kardashevskiy , Dan Williams , Xu Yilun , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , x86@kernel.org Subject: Re: [PATCH v4 04/13] dma: swiotlb: track pool encryption state and honor DMA_ATTR_CC_SHARED Message-ID: <20260513172450.GR7702@ziepe.ca> References: <20260512090408.794195-1-aneesh.kumar@kernel.org> <20260512090408.794195-5-aneesh.kumar@kernel.org> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, May 13, 2026 at 02:27:14PM +0000, Mostafa Saleh wrote: > > + /* > > + * if platform supports memory encryption, > > + * restricted mem pool is decrypted by default > > + */ > > + if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { > > + mem->unencrypted = true; > > + set_memory_decrypted((unsigned long)phys_to_virt(rmem->base), > > + rmem->size >> PAGE_SHIFT); > > + } else { > > + mem->unencrypted = false; > > + } > > This breaks pKVM as it doesn’t set CC_ATTR_MEM_ENCRYPT, so all virtio > traffic now fails. How will pKVM signal what kind of memory the DMA needs then? Does it use set_memory_decrypted()? How can it use set_memory_decrypted() without offering CC_ATTR_MEM_ENCRYPT ? > Also, by design, some drivers are clueless about bouncing, so Oh? What does this mean? We take quite a dim view of drivers mis-using the DMA API.. > I believe that the pool should have a way to control it’s property > (encrypted or decrypted) and that takes priority over whatever > attributes comes from allocation. We should get here because dma_capable() fails, and then swiotlb needs to return something that makes dma_capable() succeed. Yes, it should return details about the thing it decided, but it shouldn't have been pre-created with some idea how to make dma_capable() work. If dma_capable() can fail, then swiotlb should know exactly what to do to fix it. If pkvm wants to use the hacky scheme where you force a swiotlb pool configuration during arch init with force swiotlb that's a somewhat different flow and, sure the forced pool should force do whatever it is forced to. But lets try to keep them seperated in the discussion.. > And that brings us to the same point whether it’s better to return > the memory along with it’s state or we pass the requested state. > I think for other cases it’s fine for the device/DMA-API to dictate > the attrs, but not in restricted-dma case, the firmware just knows better. The memory type must be returned back at some level so downstream things can do the right transformation of the phys_addr_t. One of the aspirational CC things that should work is a T=1 device tries to DMA from a decrypted page, finds the address is above the dma limit of the device, so it bounces it with SWIOTLB to an encrypted low address page and then the DMA API internal flow switiches from working with decrypted to encrypted phys_addr_t. If we can make that work then maybe the flows are designed correctly. Jason