From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (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 78E4D1AF0A6 for ; Tue, 21 Jan 2025 20:48:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737492483; cv=none; b=CVdzDQOCNXcxt98/uEkg8+Ey7sHuyI8leQUIPsE+dPQ7AMOo3KtrxYvgxZmdn/jSqq/0TA7gsl+Gi/i2Uk0vh4dQYTo7haaQE19VR1DqJGYKRbPCAXRbeM2kGK/yTUNn4wI3sX2fuXp7KT+WrkFTJHMB1L+WIgF5ijIm7epBTmQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737492483; c=relaxed/simple; bh=g6gsRKJh7V7n8xwdh+JPKCk0Lq/C+rb/lPQNDYRoAx0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZmEcN7DZKLOdn9U/TKauhLBzlbAsCbdHuzYajb/wZY/c8A9VFfvAV/uVW2LCZCKsX7D2c+g3aHKxlP+vwpMEETqp0gVUeTIw/3cT9AgLAZM1D5Z+R7bDE0ewh8h/RPzWoBzuq3fXBY8RYBXfW9vuMjbiwdO9ef2bufeYH/5RVR0= 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=PK9ALH2C; arc=none smtp.client-ip=209.85.219.50 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="PK9ALH2C" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6dcd4f1aaccso91232546d6.2 for ; Tue, 21 Jan 2025 12:48:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1737492480; x=1738097280; 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=ow8OnSOBUAvF1sR6NsRcQ1mD4Budky7KnwU2LvfpPWA=; b=PK9ALH2CTpxIquPHRrKlIFzCv4C0a9qLPFP2xvEL2ML0hneKUJ38EeputpInMz4tT2 mAfD5ckrYzU9r4K6c3HyUq8rmBy2JMERXnWR1Jr0ECTS7WQ8/UcRIhDKN3KAbzzn/AvM evj7pa8a2USTESwwXhdKUCcyPoLSMCHrGWveqKHzVPQsKFlcFtGTBStPsiRpqVXelLKH 9D4uFdE4/3+HpuKcKTsRg1THPfparzEN8IFD80yNVkvrbsagTs07yY0sGCg7PyanDPxB CCXPJQ8KA2z8EZXOXSFOZqEK3qQCn9a7k11n2PlwwxeebZgZ9BKHNBT2sx8AJpldPXDA Tq7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737492480; x=1738097280; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ow8OnSOBUAvF1sR6NsRcQ1mD4Budky7KnwU2LvfpPWA=; b=f8qR7PniZ+hQeihiaN179hva+dVKChcyJGon+S4A0GsJaMW5WHfH1SRubcObxF2Nle nKU3WYTmK9xte/DdOr2GLUWs3CbDA5HvY8ndJGL4w5q+ie7XXZMdQ+UApYEcUV79c1U6 Y3AkqyWvIFS3dbCfbg7nxBoptVRA99BvflY0WTeZ4ex5kuLFx57VVrxKRZ3WHIJ3chPZ PiQ/TQxFaGBrkgP8RBP4Vb2fOmgS+8dnRts5RpIrTwec18Hn3OrU8J6XVZPtYSsba0xR 5a7ArYDrDT+t9LEZTBGdOwp3GMafARj3SYofjtloZp9P+A1g/Be6fFLh+2dHB8ObsSoq bs0g== X-Forwarded-Encrypted: i=1; AJvYcCVBMbo+KUTiQ+HJ3pX1utFQ2hXjxOe7ctnRq7P0PU1oY5uEkiF1oGcVdaYJ0gv8zxhKxJZTbCulf4BWM9Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxD5Z3RSQBs2hiw2oWJSD3Aq4tET0yo+8BT0xiFyzp/JgTE6QK2 LrxespQlVhwFRYEtlJfTkmz5YYqSg15Rn39oaRFkmDX0ZI6aeyBvx+7kFmi4RdY= X-Gm-Gg: ASbGncvepmAdjpt4zIh9Q/DojP3AbjFwYQSN3lk3N0bDHzxMumGLb+AYliw9hYq8P7y FbOBejMzVNqgG/c7GPWYrUpXIMBQVY/LqGuwUuMu0fXJyHmB7Fn7xqpZbKqvzvv/aE2qjFvULUQ /hjpyZA/stUniOdeSPCsUvIRITEdO5t2PBeLR7cQ8kBzOPpcVnFNl+YwsNcLTSpuQCbjFAYbAxH 3jsDBEyWadQxZEqssLOd/SqN+c0m4ryQsnXdgRySSGQ X-Google-Smtp-Source: AGHT+IGpzHbNEy913KwGqLDga7j8XCPTIu+0UlJOC0stjfVReFdRGhjNtDFMtiwPVLFCCekg9fkq/A== X-Received: by 2002:a05:6214:1cc7:b0:6e1:697c:d9b8 with SMTP id 6a1803df08f44-6e1b216efb9mr307486706d6.9.1737492480304; Tue, 21 Jan 2025 12:48:00 -0800 (PST) Received: from ziepe.ca ([130.41.10.206]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e1afcd388asm54445966d6.92.2025.01.21.12.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 12:47:59 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1taLAE-00000003k34-2XRy; Tue, 21 Jan 2025 16:47:58 -0400 Date: Tue, 21 Jan 2025 16:47:58 -0400 From: Jason Gunthorpe To: Alex Williamson Cc: Wencheng Yang , Joerg Roedel , Suravee Suthikulpanit , Will Deacon , Robin Murphy , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v2] drviers/iommu/amd: support P2P access through IOMMU when SME is enabled Message-ID: <20250121204758.GR674319@ziepe.ca> References: <20250117071423.469880-1-east.moutain.yang@gmail.com> <20250117084449.6cfd68b3.alex.williamson@redhat.com> <20250121083443.3984579a.alex.williamson@redhat.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: <20250121083443.3984579a.alex.williamson@redhat.com> On Tue, Jan 21, 2025 at 08:34:43AM -0700, Alex Williamson wrote: > This description is unclear to me. As others have noted, we probably > need to look at whether the flag should be automatically applied by the > kernel. We certainly know in the vfio IOMMU layer whether we're > mapping a page or a pfnmap. It is not page or pfnmap.. When vfio is using follow_pte() it should extract information from the PTE and then relay it to the IOMMU. The iommu page table and the CPU page table should have the same PTE flags. So, a pte that is pgprot_cached() should be IOMMU_CACHE, otherwise IOMMU_MMIO. The encrypted bit in the PTE should be mapped to some new IOMMU_ENCRYPTED. I suspect AMD has created a troublesome issue that IOMMU_CACHE conditionally implies encrypted depending on their platform features (meaning cachable decrypted is impossible). Arguably a higher level should be deciding this and the iommu page table code should simply follow IOMMU_ENCRYPTED always. That might be something for later, but I would note it :\ > In any case, we're in the process of phasing out the vfio type1 > IOMMU backend for iommufd, so whatever the implementation, and > especially if there's a uapi component, it needs to be implemented > in iommufd first. Since iommufd won't be using follow_pte() it will have to get this meta information from the FD, eg through DMABUf, and there is a huge thread on how to go about doing that.. There should be no uapi component. Jason