From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 0B2483FE366 for ; Fri, 24 Apr 2026 22:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777070494; cv=none; b=VkuPM6+knDb2ttofgTHUmw3B+m7IIVBEyqGGRbJMHxZU1k4x0jLTIPZLwdDnDwun3FDcPyirX3rvYIOnjPDBVWwx8V2VpzHFUUAid7unlesyDGyRzrKFv2GzkPdykWcbE3VXfsSpun6BlWaRRy3mo1IVy50+Md6Ml69JLdqSIII= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777070494; c=relaxed/simple; bh=0wbebf2HPx9TeEtYpz9WSEST6/aBh9LpgQNb5KW7e/M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=n8atfP91gN9aD9+ytk2jhzwr+ngAe/Tz16Vk7GxuOKLzstaw8TpJYPa/swAPDciHnhTDz68hjZzsOXziH9wfIedsqVDS0s6alF4zOyJhP40TKhwWDrEyutrYtG3Q6iNnq3XpkfM5Z8GPPGEeoX71P0weVd/ESv9HHBeMiUqTykY= 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=kK4cXsbx; arc=none smtp.client-ip=209.85.222.169 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="kK4cXsbx" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-8ee7ffd738dso480423285a.1 for ; Fri, 24 Apr 2026 15:41:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1777070489; x=1777675289; 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=7nigELrq2iU48oxK96NCIrHW0Yy445jx+Cu1pez2xaU=; b=kK4cXsbxEe46XCqnAp/dqf/Gru1ASb6c+DdtUwQ7JlQ7TJ2L8Bd35ymmO5paXjwHm5 2XzuV6mnXDun/Hdyznzfszv17L+z5j2AVfyD7wy3/EJfK+9MoG7ocUfZGFn5Q8HcMiE0 64NwZlz+BUg6aNTjHum2pCMatNRczOWUalpDW+wFEZrkWvECCMw7TWdaqrryQFAdldRB GSCkN66mxCnL7xXRlW9ILaolL77OBoM6pZXjnnV3MnQwljUS6C51xjyaRjDANJIUwyBu i1CPY0Gz63KL4YL+Xo5t9aeVdW7kOG41aOD3VYvfPNgxNM0gCcbHazBF9uGAPXEuy/bP bXGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777070489; x=1777675289; 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=7nigELrq2iU48oxK96NCIrHW0Yy445jx+Cu1pez2xaU=; b=Y4YUAMTwKNf7uRmkIEd+Zpgq/VhoPHw5TsP5OO4UtH/6MvAViS1Uc+uUo72sfoiLg2 1FGQwjHxT44R2qwsbWkswvMl68aaBf88x4oeizseaY31LuH6P41zPMRhFM/UJCUaaiMY lELwF66+4FyHOckYkdN9U1uJKh4MODcABP/zbFlH9G7mcjiXaTOC6vfTwqAqTLVeDf8V bSqqYK40WHA6j3izZpOOBQHiuhLBu6QXmsTl+XW3NnMPJbdyTITDsrie+dD5AgxeKfAG xsJmRgwE1AUowXUZtGx2DrAi0rqKl84tKJZoUOc2k41cr+jgXX86CLG91XRoO6BiWikX L7uA== X-Forwarded-Encrypted: i=1; AFNElJ+Hj9hMgdP8hicKmwyI3EbD+ahurBUBxDas1sK9P3CHmFQWH73PwFfxaCXm8QRANCNQt0VNd6nIzeq8cG0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5wy+16LsS23lg2Cs0CcwWVAzpHI5ZK6uTuUnMiOZSqTT4QLUe +q3ZhSXMbLJ9dP4vkIgxO9g48a0syr/oLlkKEnFdfxjyINd0nyS4r8YIx0bQtEwRvAg= X-Gm-Gg: AeBDietCzdCjPyYxh5OieCp14BOrjCMGQMrZkPeXl7BWeYszoUjbFHJhtYqcYGqv1MT FTmBawXqXSofNnhb7TLxw+wT0IjlU/W8rCIuCp3UyKaWovgkSv15J8sM42MjYKjzY5m21ts8ReS A61+maX6876DVcGtMhnYx6MpKZ2dqU/v5c3FLcpk1Aq22akArsLaWoXxcAAC9ACP9HLpPcYwdWn OfrRXJzkQQfEukr6cLKWrYiAkh5xQZbPzYKrPC5wu6lxR6vOLsRHe1pxS+K4+ihUsjLvwk9SDJ+ qR8/fGz1rcwMXenbpowD+/EuYmPz8dY/TAeGCzJtyg6tbL6967GNBe7elnOaDvJb6qeN3SK4C68 x1slKbliefUvXrMwVlbzMbGmhTPX1hbZshq7AUmHi8NbnQ30nQuz7xHWZlsIocW+LO5TB0kI74k VbokbouRZimVVKjmzoVki3/uWt54lNfFhIir6b1y9roK/N8Vm3JPmJbinSPB6JGKZVZozwCGUcu 6dCKChx8Ly8bgDE X-Received: by 2002:ac8:5a0f:0:b0:50d:a8f5:fa94 with SMTP id d75a77b69052e-50e36738adfmr435612941cf.21.1777070489381; Fri, 24 Apr 2026 15:41:29 -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 d75a77b69052e-50e5d5ecffdsm147416631cf.29.2026.04.24.15.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2026 15:41:28 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wGPDD-00000004sdv-3EBS; Fri, 24 Apr 2026 19:41:27 -0300 Date: Fri, 24 Apr 2026 19:41:27 -0300 From: Jason Gunthorpe To: "Aneesh Kumar K.V" Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, robin.murphy@arm.com, m.szyprowski@samsung.com, will@kernel.org, maz@kernel.org, suzuki.poulose@arm.com, catalin.marinas@arm.com, jiri@resnulli.us, Mostafa Saleh Subject: Re: [PATCH v2 6/8] dma-direct: make dma_direct_map_phys() honor DMA_ATTR_CC_SHARED Message-ID: <20260424224127.GC804026@ziepe.ca> References: <20260420061415.3650870-1-aneesh.kumar@kernel.org> <20260420061415.3650870-7-aneesh.kumar@kernel.org> <20260421122924.GB3611611@ziepe.ca> 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: On Wed, Apr 22, 2026 at 11:20:28AM +0530, Aneesh Kumar K.V wrote: > >> - if (is_swiotlb_active(dev) && > >> - !(attrs & DMA_ATTR_REQUIRE_COHERENT)) > >> - return swiotlb_map(dev, phys, size, dir, attrs); > >> + dma_addr = phys_to_dma_encrypted(dev, phys); > >> + } > >> > >> - goto err_overflow; > >> - } > >> + if (unlikely(!dma_capable(dev, dma_addr, size, true)) || > >> + dma_kmalloc_needs_bounce(dev, size, dir)) { > >> + if (is_swiotlb_active(dev) && > >> + !(attrs & DMA_ATTR_REQUIRE_COHERENT)) > >> + return swiotlb_map(dev, phys, size, dir, attrs); > >> + goto err_overflow; > >> } > > > > Then this movement shouldn't be needed? > > I am still not clear about the use of DMA_ATTR_CC_SHARED here. If the > resulting DMA address is not dma_capable, I was expecting that we should > fall back to swiotlb_map(). "resulting" ? From what? The user provides an address. If the provided address is marked DMA_ATTR_CC_SHARED, then dma_capable should succeed on a CC system. Otherwise if !DMA_ATTR_CC_SHARED dma_capable must require T=1, or fail if T=0. > That was the intention behind this change. > However, the other email thread suggests that DMA_ATTR_CC_SHARED is > always used with swiotlb_force_bounce(). I think we should address that. > If we do, the goal here would be to check dma_capable for both shared > and private addresses. The flow I think should be if (force swiotlb) then do swiotlb if (!dma_capable()) then do swiotlb if (kmalloc_needs_bounce()) then do swiotlb otherwise use the provided phys_addr directly ie stop using force swiotlb to handle T=0, instead have dma_capable directly check T together with DMA_ATTR_CC_SHARED. > For private/protected addresses, swiotlb_map() will currently fail with > DMA_MAPPING_ERROR because the default io_tlb_mem (dev->dma_io_tlb_mem) > is decrypted by default This is a bug in swiotlb. swiotlb must *always* returns something that is usable by the device, or it is broken. ie the pa it picks must pass dma_capable: It must return a buffer that falls within the dma mask It must return an unprotected buffer if the device is T=0 It must return a protected buffer if the device is T=1 (ie it should not choose an unprotected buffer just because DMA_ATTR_CC_SHARED, we might be bouncing because the device dma mask can't reach the unprotected adress space) So, when the device is switched to T=1 something also has to go and fix swiotlb so it is using T=1 memory too, and there should be defensive WARN_ONs in the swiotlb path that the memory it picked is suitable. Jason