From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385129; b=mwfXJxV5cv7icVlo2yTsX5JaIw9XtVjy5Bc+HNLcFdMXw8UJu/FxwP1Iksi1pIqeH+V9 Ycdgg1BOEm/MEoAX+LFWO72iLLWSrBRGEHuhY8GBQUD7jI60KWum0vMDjgdrZGsi8taK8 T/ISoFevljQ69K1v8gEAXumH3V+M40JsgUttR53Gid4L3Wm28KlCUuZSzdzbE59g0ynNo 1grPfqBiC8AHuccwSusQ/YtpF9zSQ5bR/YN2PbHWxu9HoHtKs6YabmgLwU3loET5UmXmT WwJ+wBQWiMoC+NbfH//sbZD+ozZryd9ldsYj2vKtTL7NcDzTA2s3LQ3GM+3DqU8lJ1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385129; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=WR23M0vGtohke6mDNo0U5Ub+C9VR1xy3hxleGfbuCHs=; b=RU1SFumHvG8xVBUQ7/o10f6AhHEAsS1n17bkdblyNcG19uKeI976PoXW7FsdcLpgRsSI ODSOPHD+OO9KnUWrKbVIXH0OkqbcCbTJWpsVWOoisQSljnwaVnIYw0WNgtx12eR2l3h4u t4VPQweM6/BYTeyEFdZkokmWU4rKOj2Y/N2TxUN3Nw4mV8l1DDOdPWDcpJpVCfHrMVu8a qrP6ZYGzzOtrLPeGf0SDwQSPacE7rBsUVbvKikf1roBpJ3Z/ArnKe2cRm9U692cimJCk5 y2e7C2JB6N0HrTEvLaA1aOpDGFu0aqAvXVtbI7YN4UEqkCQKip2JjuHz8Rn3zORMZCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=sbIzzyKl; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 248F3606A322; Fri, 4 Dec 2026 11:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=sbIzzyKl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9212B1F000CE; Fri, 4 Dec 2026 11:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385129; bh=WR23M0vGtohke6mDNo0U5Ub+C9VR1xy3hxleGfbuCHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=sbIzzyKliASuXPXeR5M+1mprxd7Oq4iAkva1ms9LrIJvG7I/JdXgF7CbAw6uejfGM izQSrVQ4Pp7H1eGOpVMyRRHIR2s7dG+AsHvVPDeWy9Y1CnZV1D//H6Go+NjVzMtNwI VeTo7qD8ln3wN1KBfpT9UG97PTFhTyFutdcJ9abY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Donggeun Yoo , Jason Gunthorpe , Sasha Levin Subject: [PATCH 6.6 0413/1167] iommufd: Keep reserved IOVA ranges when a replace within one IOAS fails Date: Fri, 4 Dec 2026 18:57:20 +0900 Message-ID: <20261204100712.783338092@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Donggeun Yoo [ Upstream commit 1e67cca28490f897788c128c650a6f2cbb565403 ] iommufd_device_do_replace() installs the group's reserved IOVA ranges in the new hwpt's IOAS only when it differs from the old hwpt's IOAS. If the replace fails in iommufd_device_do_replace() or iommufd_group_do_replace_reserved_iova(), the error paths remove the ranges from the new hwpt's IOAS whether or not the IOAS is shared between the old and new hwpt, which removes the ranges that the old hwpt still needs. For example, on x86 with intel-iommu, after a replace within a shared IOAS fails with -ENODEV, IOMMU_IOAS_IOVA_RANGES goes from 0x0-0xfedfffff 0xfef00000-0xffffffffffff to 0x0-0xffffffffffff and IOMMU_IOAS_MAP at 0xfee00000 succeeds. Remove the ranges on failure only when the replace installed them, and look up the old hwpt_paging before the replace so that the error path can compare the IOAS. Fixes: e88d4ec154a8 ("iommufd: Add iommufd_device_replace()") Assisted-by: LLM Signed-off-by: Donggeun Yoo Link: https://patch.msgid.link/20260929031402.1998253-1-donggeunyoo.kernel@gmail.com Signed-off-by: Jason Gunthorpe [ sashal: Open-coded the fix by guarding the error-path reserved-IOVA removal with hwpt->ioas != old_hwpt->ioas, since the helper functions and hwpt_paging upstream uses don't exist here. ] Signed-off-by: Sasha Levin --- drivers/iommu/iommufd/device.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index ff6386fd1e8fe..127a14ec6733e 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -494,8 +494,10 @@ iommufd_device_do_replace(struct iommufd_device *idev, /* Caller must destroy old_hwpt */ return old_hwpt; err_unresv: - list_for_each_entry(cur, &igroup->device_list, group_item) - iopt_remove_reserved_iova(&hwpt->ioas->iopt, cur->dev); + if (hwpt->ioas != old_hwpt->ioas) { + list_for_each_entry(cur, &igroup->device_list, group_item) + iopt_remove_reserved_iova(&hwpt->ioas->iopt, cur->dev); + } err_unlock: mutex_unlock(&idev->igroup->lock); return ERR_PTR(rc); -- 2.53.0