From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.21 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796170980; b=afGe/CvI1zFSk8AkC0Z3Gcf8nhIsz/Jjq3O4mTyqeNiyGejwAiccfzLVbw0fARQ3YluX ngVtgKivBeSJBC7xXbgXhyY92SUXxDrE6FgWmYFIWZk+dQ7AbsYVHN+9id5HBxdskBSkE l5bycEqJdQN5w6GeYijq8Lodrjsv/2UsKQgiatKsnO5U2MhBRk0mzeBYm1K3Z4Ny9f1vm yv4cE8Mval0iAP8OVLMd1v/SvhSQv0Fb7LgGdLWi8F8fPww4PfhpPRV3iZW4UD/UsOWKe Nv1OE6J0hmjRCK0FdJsH0WfxyKf+NsLU+6oUtzQRObCmBNoQTb/IEiaQzle2zaEh4sg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796170980; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Message-ID:Date: MIME-Version:User-Agent:Cc:Subject:To:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=0sKsl6fKtJ47zMW8X6itnS6I+SkjgGT3zAXJ2fJyDv8=; b=wNPDdLCf0rzP92qeisYxmN7M/r976LFtDZ8Asrj5lRpU4pEvbJGj9THrZr1iIvUjhxF9 I83aHs4eF1hwXFMOzXjKuq4todxbmqsqqnED1HrWttyafRv1NGa0tFn/ykPR8BAdcvTcI 848i1nqW7eyHZSnwPleJJPhHraQ0EpfRZMSmzDnQmg8y86N6g4vobXPqHpxXwDfm+OMxc 7AnCzEErlW90z0Tuyt0ts4qdCpJgWAeoniHa5e8hHvlZ1qh1qPSYQsM4u5FD9rqmtiAll +nXdI1UM1HoHUuUe+RWQDxsrFcm5oW2MqQeOcg5pJSCLLb4rAn3QiYtoHqECJKTM7PQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=LiIdbNYH; arc=none smtp.remote-ip=198.175.65.21 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA39A606A327; Wed, 2 Dec 2026 00:22:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA39A606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=LiIdbNYH DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796170980; x=1827706980; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=0sKsl6fKtJ47zMW8X6itnS6I+SkjgGT3zAXJ2fJyDv8=; b=LiIdbNYHMiZfJEJpDzvyuAiezeKmQwd1ECTD2atgfc5COQA2+WIaVWqP 0RsKxr4yIufm86WPORssYt2cWm5Nb6yEb3yDjOeIgolMxatkZitONn8vm 6L97aEHmhWFFzTLB0cvGBUAQ24ng9eiMBdft+pidOLBISRwLnC5DEpxsG dTdUSQUnPLgCNbBgKUkwsCVno2P44+IZRSj0JVszpy8V9RQnA+2vfKk5P L/2+MB2v5YNlFVfsMPGvh6zLKltsRua+HYTL1UCjJZNkpVZE1unaliAPt FSmV1MzrDUCq2WWSjNEPVAkhzVE0BaBLzoIS1pm3Dhet691Jx3WDgxfGR g==; X-CSE-ConnectionGUID: BeW1ZbeITYuSabUxp7pfRQ== X-CSE-MsgGUID: ZgwXzJ3PT4yR3+7DoY6tdQ== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5175576" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5175576" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 16:23:00 -0800 X-CSE-ConnectionGUID: 3aKvHcZbR/mT7cPfCUEndw== X-CSE-MsgGUID: LSzerE+KSPiiq4Ad1ilVfg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13368685" Received: from unknown (HELO [10.238.1.144]) ([10.238.1.144]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 16:22:56 -0800 Message-ID: Date: Wed, 2 Dec 2026 08:22:54 +0800 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, Jason Gunthorpe , Kiryl Shutsemau , "Edgecombe, Rick P" , "yilun.xu@linux.intel.com" , "Li, Xiaoyao" , "Gao, Chao" , Binbin Wu , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v3 4/9] iommu/vt-d: Add interface for tdx-host when enabling trusted DMA To: "Tian, Kevin" , "iommu@lists.linux.dev" , "x86@kernel.org" , "linux-coco@lists.linux.dev" , "kvm@vger.kernel.org" References: <20261112043054.2664857-1-baolu.lu@linux.intel.com> <20261112043054.2664857-5-baolu.lu@linux.intel.com> <9a92bb91-3dac-4fc5-8f38-130b7442bdcc@linux.intel.com> Content-Language: en-US From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/27/2026 3:59 PM, Tian, Kevin wrote: >> From: Baolu Lu >> Sent: Wednesday, November 25, 2026 4:18 PM >> >> On 11/25/2026 11:29 AM, Tian, Kevin wrote: >>>> From: Lu Baolu >>>> Sent: Thursday, November 12, 2026 12:31 PM >>>> >>>> An Intel IOMMU that supports trusted DMA (ECAP.TDXCS) provides a >> second >>>> set of DMA translation resources, managed by the TDX module and used >>>> only for devices assigned to TDs. Before they can be used, the tdx-host >>>> driver issues TDH.IOMMU.SETUP to put the IOMMU into Secure TDX >> Mode, >>>> and >>>> issues TDH.IOMMU.CLEAR to take it out again. >>>> >>>> The VT-d driver owns the hardware state these SEAMCALLs depend on, so >>>> it checks that state and keeps its own use of the IOMMU out of the TDX >>>> module's way. This is cooperation, not enforcement: the TDX module >>>> protects trusted DMA regardless, and a misbehaving host can only cause >>>> failures. >>>> >>>> Add a per-device interface so that an IOMMU is put into Secure TDX Mode >>>> only when a device behind it needs trusted DMA. tdx-host tracks how >> many >>>> devices use each IOMMU and calls into the VT-d driver only for the first >>>> and the last of them: >>>> >>>> - dmar_tdxc_get_params() looks up the DMAR unit translating the device >>>> and returns its register base address, which is how the TDX module >>>> identifies an IOMMU, and its NUMA node, so that tdx-host can allocate >>>> the TDX module's metadata pages local to that IOMMU. >>>> >>>> - dmar_tdxc_acquire() is called right before TDH.IOMMU.SETUP. It checks >>>> the preconditions TDH.IOMMU.SETUP requires (DMA translation, >> queued >>>> invalidation and scalable mode enabled) and confines the host to the >>>> lower half of the domain ID space, since the TDX module owns the half >>>> with the MSB set. >>>> >>>> - dmar_tdxc_release() undoes acquire(). tdx-host calls it if >>>> TDH.IOMMU.SETUP fails, or after TDH.IOMMU.CLEAR succeeds for the >> last >>>> user. If TDH.IOMMU.CLEAR fails, tdx-host doesn't call it, so the upper >>>> half of the domain ID space stays reserved for the TDX module. >>>> >>>> DMAR units advertising ECAP.TDXCS are excluded from DMAR hotplug. No >>>> platform currently supports both trusted DMA and DMAR hotplug, so that >>>> flow can't be validated on hardware. Hot-removing such a unit is also >>>> unsafe, because tdx-host may hold a reference to it and the TDX module >>>> may own its trusted DMA resources. This also keeps the unit handle >>>> returned by dmar_tdxc_get_params() valid for the lifetime of the system. >>> >>> Here we used multiple terms (Intel IOMMU, VT-d, DMAR) to talk about >>> a same thing. Intel IOMMU and VT-d are interchangeable, commonly used >>> in many places. But DMAR is more a term in ACPI structure. Better avoid >>> it in description, especially in exported interface names. >> >> Intel IOMMU and VT-d refer to the hardware that the intel-iommu driver >> drives. DMAR is the ACPI DMA remapping table, and the term is sometimes >> used for the remapping hardware units it describes. > > internally ok, but externally it just adds unnecessary confusion. Agreed. > >> >> The interface here is not an intel-iommu driver interface, since those >> should all go through the iommu core. It's exported from the ACPI/DMAR >> layer instead, so dmar_tdx_* seems the more fitting name. > > it's an interface which intel-iommu driver provides to the tsm driver. > > it's exported from dmar layer because you chose to put it in dmar.c, but > really the logic there is about the general iommu object itself at runtime. It appears not only for the intel-iommu driver; it also affects the interrupt remapping code, where the GCMD register is also used to control interrupt remapping. Currently, dmar, iommu and interrupt remapping are somewhat coupled in the VT-d implementation, but ideally they should be independent. > dmar should be used mostly at boot time. > >>>> + guard(mutex)(&drhd->tdxc_lock); >>>> + /* Still set if TDH.IOMMU.CLEAR failed and tdx-host was reloaded. */ >>>> + if (iommu->tdxc_acquired) >>>> + return -EBUSY; >>> >>> what does "tdx-host was reloaded" actually mean? >> >> It's stale. After a failed TDH.IOMMU.CLEAR, the flag stays set and the >> next acquire() fails, whether or not tdx-host is reloaded. I'll reword >> it to: >> >> /* Still set if a previous TDH.IOMMU.CLEAR failed. */ > > I don't think it's necessary. what about the caller only invokes acquire() > but forgets to do release()? We don't need to describe all possible > reasons why it's left in that state. The code itself is clear enough. Yes. I will remove this comment. Thanks, baolu