From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 3D7643546C6 for ; Wed, 20 May 2026 19:59:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779307168; cv=none; b=LuU/ctzalRr2qu/+GmwEcdasAhV2Q/HRb5pmMq+SVNXEBJcGiBcttZFstG8VKGxmYzcp4dQF8xxi4Egs4OWMbPE185aR/mPLtOL3cFWXOA9BbjiFoKC7qO3x5bRg5lF67SbccqF4cVYyCbf3Ahuph4s2mgMaadV+mVNxMzL8/0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779307168; c=relaxed/simple; bh=S7TAJoU+IMqYQKKwE9M0wXBnMWS7p5Uteu79IW573uY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HxDMwYtFQe7qtucpYtcjUNbki183WIi7WEiXCw6D0fXGAD4rlC7/E9ojOcV6hxusA0kKmV/2QzdmB9KjGjzWM4Q4fat0DCBhDq9SwoxYX4GTSMoUN8FwU7/Im5E66OAAeVrlcWs3gpIWe6aEdOvqIq7RJzi5eViUgQP2/d5ic7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Bodq/T1c; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Bodq/T1c" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2ba3b9bcf69so385ad.0 for ; Wed, 20 May 2026 12:59:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779307165; x=1779911965; 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=6s3nWbufKIAdpd+T1kqQvCCgsvhw2lBrbx69UeZQAOE=; b=Bodq/T1cfD85etDDlX3rnm2vfzJyWhArEnsD2yEWJEFMWB6Cb+eDb8sAQQx1bjfhV2 hJ5iQ/dgl7zg68xNjiWmdkRPYfY4iqKufrEEKONr3Vw4oK+5i1s5ZfxO7+qSgRqTDXhz hcSfQunAWKdWfdAMmAIG2HSi2Ad06gZxuJWianZX5LuK6+gpYrg5D9uo9F6nrtaRBID1 x9dO31Q96kdtmtwTTWRpApLbDX1q4xcV9cRjjeAtGr47QzMPofJW6i+F26NBKnKczrsM KQcmhLXH8LIBJmKKs3iNi0FtWsgDDMlqwN/FK85UKvBhrj0wAgX1A/p5K/BiO+d+Wfua IlMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779307165; x=1779911965; 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=6s3nWbufKIAdpd+T1kqQvCCgsvhw2lBrbx69UeZQAOE=; b=L0xIvtxzUNNuK8wJc50FFFHHO77IQgFfq/O1LRuWP2eWw924Wkgis3diazriUNyZ2z 2zoIiQTFbFjuR/i5npV6uI1mKf9p1m9OfATchmERCS3GqCWqGyS+7MvblzjlMHpSaaH9 VtCGVJ8C2hohRHkcA3RXED8/GWiMMS3exggLE5YMGAeyngYFJX36itJGdLj8YpLH6TIt Sw3I4hTYsng4wgiLda8tl6ccEaocP3reFExjyrytQZ/48VACsU2i2m1vh0vNqiJ3hkkc wPghBqQjJaySbLCrrjUNfS30Y/9uYpN19tsNubMTEOAh3fupzmAKtchf0KoTV8woH3K4 aNzQ== X-Forwarded-Encrypted: i=1; AFNElJ+/xe+jDzko6OwNkA6bWIMK6pxQuwoRoy8IyjUpGtQLw6k5LgvDPRdRmVsqaDSvkxl2tRrXU03MrKIfAKc=@vger.kernel.org X-Gm-Message-State: AOJu0YzohuKfOqE4KkJaMk0Q8kMsQ6J3c8ZNnbHbefzCO4ThxvThLAxS CB4q4wrX79dE5uacTdFikbW+xnpm/NQS6MqHYzpqOKjH7HUNSURrouTaEL5LL/mnug== X-Gm-Gg: Acq92OE8Gip906Y33HiHUwgSYZe4bpMvaabwjKJF1XPAoxQ5WYY4tlFNGpvQRHp9Vx/ USVSv5st5NRdaUmH2pvfdS1sD/ET7/64pjthoi3cPadgrw/AMDCgYjY4Z7bseYITnelqLXsoJa/ GlO8zYAfkplB0m8Rv2k3zZwqxJjGBOwOOVLiomUgAuubz+tQBvvmn5Hwo22P8u+ZLhe04eEdKK3 ICEqnBNP7dGiPiiJQomoVPVZRQnGLni9g5fJj7DOaT03E9O1aPI8dH3Ncutr1lMRHbdT+lJiFpS TaEvDE+mjmgInyU3K+c5+YyxLZRAtEnd+nWma9DqXFur2oRH9hxTeKpkLDMAaS1WVF3NESwP7q2 qPiQWpGmKIQb+QFOuj1ltlB0oCviHBPl9EpPJn2m9Kwl9r8uuDi6m+DHNkQFqx1j60Mjgh3sdMU hNMeJI2CWVDsZOC9WSc/isCXMNwMq3ib59fgBRCq/Spjjpsg3sSVKWKgAvr9Fbz2WjvFbPLA== X-Received: by 2002:a17:902:d487:b0:2bd:907:2ce5 with SMTP id d9443c01a7336-2be9f694c1bmr510145ad.7.1779307164981; Wed, 20 May 2026 12:59:24 -0700 (PDT) Received: from google.com (153.46.83.34.bc.googleusercontent.com. [34.83.46.153]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c82bb1006fbsm19676025a12.21.2026.05.20.12.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 12:59:24 -0700 (PDT) Date: Wed, 20 May 2026 19:59:21 +0000 From: Samiullah Khawaja To: Pranjal Shrivastava Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Jason Gunthorpe , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Chris Li , Vipin Sharma , YiFei Zhu Subject: Re: [PATCH v2 09/16] iommu/vt-d: Restore IOMMU state and reclaimed domain ids Message-ID: References: <20260427175633.1978233-1-skhawaja@google.com> <20260427175633.1978233-10-skhawaja@google.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; format=flowed Content-Disposition: inline In-Reply-To: On Tue, May 19, 2026 at 09:46:52PM +0000, Pranjal Shrivastava wrote: >On Mon, Apr 27, 2026 at 05:56:26PM +0000, Samiullah Khawaja wrote: >> During boot fetch the preserved state of IOMMU unit and if found then >> restore the state. >> >> - Reuse the root_table that was preserved in the previous kernel. >> - Reclaim the domain ids of the preserved domains for each preserved >> devices so these are not acquired by another domain. >> >> Signed-off-by: Samiullah Khawaja >> --- >> drivers/iommu/intel/iommu.c | 55 ++++++++++++++++++++++-------- >> drivers/iommu/intel/iommu.h | 7 ++++ >> drivers/iommu/intel/liveupdate.c | 57 ++++++++++++++++++++++++++++++++ >> 3 files changed, 105 insertions(+), 14 deletions(-) >> >> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c >> index 68fecd4e57fa..4118a0861f38 100644 >> --- a/drivers/iommu/intel/iommu.c >> +++ b/drivers/iommu/intel/iommu.c >> @@ -670,10 +670,17 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, >> #endif >> >> /* iommu handling */ >> -static int iommu_alloc_root_entry(struct intel_iommu *iommu) >> +static int iommu_alloc_root_entry(struct intel_iommu *iommu, >> + struct iommu_hw_ser *iommu_ser) >> { >> struct root_entry *root; >> >> + if (iommu_ser) { >> + intel_iommu_liveupdate_restore_root_table(iommu, iommu_ser); >> + __iommu_flush_cache(iommu, iommu->root_entry, ROOT_SIZE); >> + return 0; >> + } >> + > >Minor nit: I still believe this condition block can be moved into the >caller? Since the called fetches iommu_ser, it can call this as a stand >alone helper and bypass calling iommu_alloc_root_entry if (iommu_ser). Agreed. Also as Baolu suggested the cache flush is not needed, so we can move it out as it is self-contained. Will update this. > >> root = iommu_alloc_pages_node_sz(iommu->node, GFP_ATOMIC, SZ_4K); >> if (!root) { >> pr_err("Allocating root entry for %s failed\n", >> @@ -992,15 +999,16 @@ static void disable_dmar_iommu(struct intel_iommu *iommu) >> iommu_disable_translation(iommu); >> } >> [snip] > >> + >> +static int _restore_used_domain_ids(struct iommu_device_ser *ser, void *arg) >> +{ >> + int id = ser->domain_iommu_ser.attachment_id; >> + struct iommu_hw_ser *iommu_hw_ser; >> + struct intel_iommu *iommu = arg; >> + >> + iommu_hw_ser = phys_to_virt(ser->domain_iommu_ser.iommu_phys); > >We should check for iommu_phys being NULL here.. I know corruptions can >be funnier but a WARN_ON(!iommu_phys) could help catch NULL corruptions Agreed. I will add a WARN_ON here. > >> + if (iommu_hw_ser->type != IOMMU_INTEL) >> + return 0; >> + >> + /* Only allocate domain ID from associated IOMMU HW unit */ >> + if (iommu_hw_ser->intel.phys_addr != iommu->reg_phys) >> + return 0; >> + >> + /* >> + * This can fail as multiple preserved devices can share the same domain >> + * ID. Since this is done during DMAR init so these failures can be >> + * ignored. >> + */ >> + ida_alloc_range(&iommu->domain_ida, id, id, GFP_ATOMIC); >> + return 0; >> +} >> + > >Thanks, >Praan Sami