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=ECB89uVc2H5cpx5/GzLP3WFlYCSZhCNeB0rHzUeC4TdRSf93wz6XejsNWwx3zZSsU6ho 0jlAw3jF40O6/HbcbrYtpe+FR+y2dxGjiv0fNoMS4RBTF/Yk0SS+2POIKkxCFS/ExejZS f4fkN/WY0KBZmHk+pBXu8fVJH8T96jxnANqH2Ay6qwCXR8uswzpaUPRR0JTfCGZhhWynn UqjPAYuWLmZRqe4G+N9CR/w8gwfDr4RuRZXQ/k2bC/dEMoOc3/OVaT6W3MOi+qdGTvJDb Zgi8YNFggBMkXQFWiEZKHE7Vr71Gl3wcL0sNXxbJ5LQsmSRkiTtYE0SehDM+Hxn8+wA== 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=A3/UF+9wmHJxxA3G+wMTjYcDT21HdHEug4jnmN8H1p9IWqZ3livzZsNH+Ufii2lC96Z5 2Jfdf28U/3jNl4orgtoVY1I0cqvIZ31plR1sF9Ds1VR5EmCmCmmAHE0ENOPr/8zXv0U+R 72Ktpmjzgx5VdMWPREENOMatxx8Bc2jtpmWLrQghYMfIHipgyD2QphTakVYSdTE32ongQ zd2l21V3i1xwug0HtT37o9KIVY4Q8zHHw8IzSvH7ZAemeqy9XLZXlJTMpNSIR9wH0/OYU mIwYyJbI7SPi2/pHvAMQXPtvEyh5uEb27+A1aIh+KlBRMbKUE6zQ5F1GckUhzKsIGnw== 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=X3fbfA4u; 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 5F0CF606A32D; Sat, 5 Dec 2026 02:47:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F0CF606A32D 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=X3fbfA4u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796438842; x=1827974842; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=ocqwuXVioM2zcPoQuszc8MritgFvHTil3okev8zKSAs=; b=X3fbfA4uJwR5062cxCojTYgigkJqL46hAKfv3au2nynaj6ro8faG1XAw T8bRjanG11qVmkJQLoCtLrSenu5Xe798nNg+AdAJZ4Tcx3tO3pUQTnuke 7JUmQsF0VIHvfCbcW6NXjgYdI2qr+dcV9R95xcT5D5oRzjOwohHe3KjeX x8L4r2C5Mu4StxzFBZxs39Ra0PBiCFrHRnRpMmUOUyhH1zFeTmqy+1ME6 SZWx31dYLM7QJT2pXnJXYJplGyPuozLqIqV4sLqW6Dr2lTEE3o7NMfKNC Kq/A2RHzE0CkEFI6cJuSY33wxkrmy1b+NBdmh35HlwVc7Ss1X01kfNe9F Q==; X-CSE-ConnectionGUID: pR8BEOyHQ6KP0K3j4f1fBQ== X-CSE-MsgGUID: EV59iBdLQ8CXW2BhGY4oDA== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="23965" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="23965" 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: 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, 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