From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.6 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796438841; b=xNzNScjOedFU+U5T6wNkOP85hTXU1s+zznxCQmNwNwZ12Qf166qeHJ0HjhpVZ3jTv7a9 pLZymVIRD2SZOwJkhWvX4uyuJ2K5pzbT+d1r7nqEL2mmprgStKs8z7I4SwOFBaL5tZiRP MzoAE1DJCJ6XPddCngDrq8yTTrRS35f+GfirAXwe1k6PjXquJNJem1nqFb3VSR9as20yZ hHcmOt6vbshdwkBEaw3n1uYKrDG+aFuYfziNUuDFa4JYmgQiR32L1YxXE/AXTdi1gDNuW NtEznrVw64kWEVZwiCKV9n3731JLn+UHegnMPANSjA3E05QA2A8kTfq7DcLBFc4Yq1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796438841; 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=xl/Oti4dm7N3wHRg0n0yiiu54f1K+gITgUMIhNiMi1c=; b=bq9StueIOkKtBrFH5Q2RjaQ5eBKyRYojUapU2A1Tfw1lGxaQ9HGzy/t3CZ8KoSBFq9Da oA1sRIFmX0Psb/do2kyYAiamFvBOh149wUUsrsZe1iEAD1Ah3LvalVBfSEhKrUgHEY2A8 LdxkOuWw3aYCroXthR9dUVuoOBWiMEAhyA7YwJznKazwrSjTpHjkU/+5Q29NL/r1gF4Ub yQxXX7iCfhe1KsmOArrwj5lvx14ljkRw2Ags3U7NEi5QimJYWs3g+0Wn7iC552a+e8piL usFzWU26ZRwqf7s0GVxYYLc3Srx7+AODeijyYVh1PfnB2L3M0CU9Dm/9k9/ccd0Ys0A== 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=BJ93kOfH; arc=none smtp.remote-ip=192.198.163.6 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.6]) (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 233EE606A322 for ; Sat, 5 Dec 2026 02:47:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 233EE606A322 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=BJ93kOfH DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796438841; x=1827974841; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=ocqwuXVioM2zcPoQuszc8MritgFvHTil3okev8zKSAs=; b=BJ93kOfHX7p5A0jPP1HIR0mhcELBzC7pbQYYRD9tR0zJ5icK+qDERu2M pnKmNZEMcCU6ZgmrgQN2GwHddjuJWofgoWD4ayOZ8DJfqGZFdiMXGEz60 nxS0OBM3mJHsozVK1l/spKjrCpF9+AmZmok2aCKVsTJ1P1wwyp5J04g7U 6EpXK7xis2V0kSdrowqs8ILpuB6GGzyXouoCnmXH4pEAyhk9wFDZ2f1GC e4ivdglUCJ1vew/pytEEUOobvbHEW71bcTkq+KmT1gYdr9JxCUQfyVkg5 K1I6Z2TBxXC82q8gXjAhyp9rXN87eK3RxUPXKrixJ91REqJ80ugJOQEJi w==; X-CSE-ConnectionGUID: 0fCZPvQyR4mXl6Cxc5em+g== X-CSE-MsgGUID: ehsaq4XtQzaeAdhTB0h7XQ== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="23953" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="23953" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa116.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 18:47:21 -0800 X-CSE-ConnectionGUID: 0T64sqxTRmS/eCDx9jM7RQ== X-CSE-MsgGUID: X7abB7qERJqEvWJvbVokRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14040781" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.124.249.52]) ([10.124.249.52]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 18:47:16 -0800 Message-ID: <8549b820-5898-4981-9c13-78c463137972@linux.intel.com> Date: Sat, 5 Dec 2026 10:47:13 +0800 X-Mailing-List: iommu@lists.linux.dev 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, Joerg Roedel , Will Deacon , Jason Gunthorpe , David Woodhouse , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Pranjal Shrivastava , Vipin Sharma , Ankit Soni , Nicolin Chen , John Starks Subject: Re: [PATCH v8 11/18] iommu/vt-d: Restore IOMMU state and reclaimed domain ids To: Samiullah Khawaja References: <20261123044949.3610702-1-skhawaja@google.com> <20261123044949.3610702-12-skhawaja@google.com> <8f1bb7da-9cca-422c-b046-b053c92ec9c5@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: 8bit On 12/5/2026 8:03 AM, Samiullah Khawaja wrote: >>> diff --git a/drivers/iommu/intel/liveupdate.c b/drivers/iommu/intel/ >>> liveupdate.c >>> index c0c121bc3ea5..d43947879e78 100644 >>> --- a/drivers/iommu/intel/liveupdate.c >>> +++ b/drivers/iommu/intel/liveupdate.c >>> @@ -304,6 +304,145 @@ static int preserve_iommu_context_tables(struct >>> device_domain_info *info) >>>      return 0; >>>  } >>> +static int restore_context_table(struct intel_iommu *iommu, >>> +                 struct iommu_hw_ser *ser, >>> +                 u8 bus, u8 devfn, u64 root_val) >>> +{ >>> +    bool present = root_val & 1; >>> + >>> +    /* >>> +     * The root entries of unpreserved context tables are cleared >>> during >>> +     * shutdown, so the preserved bitmap must match the present bits. >>> +     */ >>> +    if (is_context_table_preserved(iommu, ser, bus, devfn) != present) >>> +        return -EINVAL; >>> + >>> +    if (present) >>> +        iommu_restore_pages(root_val & VTD_PAGE_MASK); >>> + >>> +    return 0; >>> +} >>> + >>> +static int restore_iommu_context(struct intel_iommu *iommu, >>> +                 struct iommu_hw_ser *ser) >>> +{ >>> +    struct root_entry *root; >>> +    int ret; >>> +    int i; >>> + >>> +    for (i = 0; i < ROOT_ENTRY_NR; i++) { >>> +        root = &iommu->root_entry[i]; >>> + >>> +        ret = restore_context_table(iommu, ser, i, 0, root->lo); >>> +        if (ret) >>> +            return ret; >>> + >>> +        if (!sm_supported(iommu)) >>> +            continue; >>> + >>> +        ret = restore_context_table(iommu, ser, i, 0x80, root->hi); >>> +        if (ret) >>> +            return ret; >>> +    } >>> + >>> +    return 0; >>> +} >>> + >>> +static int _restore_used_domain_ids(struct iommu_device_ser *ser, >>> void *arg) >>> +{ >>> +    int id = ser->attachment.attachment_id; >>> +    struct iommu_hw_ser *iommu_hw_ser; >>> +    struct intel_iommu *iommu = arg; >>> + >>> +    if (WARN_ON(!ser->iommu_phys)) >>> +        return 0; >>> + >>> +    iommu_hw_ser = phys_to_virt(ser->iommu_phys); >>> +    if (iommu_hw_ser->type != IOMMU_SER_TYPE_INTEL) >>> +        return 0; >>> + >>> +    /* Only allocate domain ID from associated IOMMU HW unit */ >>> +    if (iommu_hw_ser->intel.phys_addr != iommu->reg_phys) >>> +        return 0; >>> + >>> +    /* An out of range domain ID means the preserved state is >>> corrupt. */ >>> +    if (id < 0 || id >= iommu->max_domain_id) >>> +        return -EINVAL; >>> + >>> +    return reserve_domain_id(iommu, id); >>> +} >>> + >>> +/** >>> + * intel_iommu_liveupdate_restore_root_table() - Restore root table >>> and reclaim domain IDs >>> + * @iommu: Target IOMMU >>> + * @iommu_ser: Serialized IOMMU hardware state from previous kernel >>> + * >>> + * Restores the preserved root table and context tables for the >>> IOMMU hardware >>> + * instance across Live Update, and reclaims all domain IDs >>> previously allocated >>> + * to preserved devices so they are not reused. >>> + * >>> + * The preserved devices keep doing DMA through the preserved >>> translation >>> + * tables, so a failure to restore them is fatal. >>> + */ >>> +void intel_iommu_liveupdate_restore_root_table(struct intel_iommu >>> *iommu, >>> +                           struct iommu_hw_ser *iommu_ser) >> >> The name is not accurate because this function also restores the context >> tables and reclaims domain IDs. >> >> How about intel_iommu_liveupdate_restore()? > > As you suggested above and in my reply, I can move the sanity checks and > other initialization like reclaiming domain ids to a separate function > intel_iommu_liveupdate_restore(). And this function can continue to > restore only root table and context tables? > > Or this function can be renamed and called earlier in the lookup loop, > but that means the root_entry will be set earlier and that is > inconsistent. Yes, either way works for me. Thanks, baolu