Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2377132lqp; Sun, 24 Mar 2024 16:39:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUMXz9Y8TIYUAzcXu2hwqZSK9tinooGJIwNUc4bdBYs3HtZnuIy2r26YgWlEABrFAWFaElsjiVd1NAwjFU45YW5S5TGWZHAoeV1WMCIUA== X-Google-Smtp-Source: AGHT+IFL2K58Ur8y3ONuUnyKmdSGQKSU1P19bwbDfY9a2Kk5a9rxSw6KsNGMHTDxn1xZ+opLjPmN X-Received: by 2002:ac8:5a8c:0:b0:430:d0b6:e814 with SMTP id c12-20020ac85a8c000000b00430d0b6e814mr6607355qtc.19.1711323588204; Sun, 24 Mar 2024 16:39:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711323588; cv=pass; d=google.com; s=arc-20160816; b=Lr7Wx3/qV5/k7NuYCdomUCWLcgr4+7vw6nYaUWbh05duh7b0wLE6j3YU+gxFdTjuf6 4e3NQz6+T0DSTK8MG2C3wzrwyx3Dx//249dkts5tz841gP2K53wvwr2ygnFyH+qKoQYX KwnFLXvfV8LrUI4WLd+ifxwrIifPHnOX68hl7T8lfGAZqzOHnwwaOTrcGanU2PWWdiDX Q4QF5jZekwc1KD1ox2/yV/azg6E2FpxSMdNT5P62xEftTWtfRESEMSXDjvTUT7Yqytq+ j/VHytGygCuH2+me4RDl8DH8NgYqG8FMevJ3MuQY+7XCks7G83bSmts5MoOTs8FFqGTz Uotw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=J4CUvw1CHA1/CFaPVP3MDaC9t410/mB+oL0CSjNSXh4=; fh=/6hw8OK96Rsih0MWh+IiDz+RSI2/FAThEpKKMtCJzbU=; b=Ak/AuG/Rg8WbMItA74SpSdXa2KWWsF1LRnYV+/G4LKekoAznNmXQRkhEirTWI2cHg7 amSFCmaEDfrVvC9t5NuQ2IVq/8vXvIZkMpmDtFzbUBurfJ8Dhb82kAWv93EzO0PMbUsl wrCjE5WBLL1NxJhVfA4f37i8fUzdFv+HiCywoTHPUObK2wz46mHj4BdKVEUj9Z0prwXs WT5pYtGt8GboPaWF956Ydc/uDIdnoPCSiXdrOrlEeVWyvdslCoCVt48CHLvk3m8ZnLHT gq8u4ziei+2nsYceJ6GbBQdfVM812B9gd7RrLPpoOagIPSTn9hMXrFEbVr7kejj0OQOd JaYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GxsHbRC0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w8-20020ac87e88000000b004314823f9dbsi3049637qtj.609.2024.03.24.16.39.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:39:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GxsHbRC0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E10D71C2251F for ; Sun, 24 Mar 2024 23:39:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96D62178CF6; Sun, 24 Mar 2024 22:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GxsHbRC0" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E8AA178CCF; Sun, 24 Mar 2024 22:39:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319991; cv=none; b=d4E3gEKCAko/PiXTHqY+UluoQAykzqYvWC6oT5HnMLzrMUilCkiyx3TLwMLoP7kADKbmT6dP8YHXUcFVvl1rp8+FRQ5JqVE+IuwP5zfPwFqmYYTBxjBGK3Chuf2rF+OUyQjgnTWsZq/qI2s7JXsa1EXdRBU/G2hqQKabtmSX4Fc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319991; c=relaxed/simple; bh=3IZlNOzBqHQHY4gQvWgHcGXr5SgHDQHzF++1kUXuWEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pRaOSAITMB+6asD63D1qe8Qf0MIXjGJkRh80UhsYgcKBCljm6qLaAUCzp08hxWAPRNQDFFRjugb9UOuPm7n9YYQmi7EQq5NpNFFKFkG0COsgXUwSCTXnuddtTeYcl2NQbB8/VvXPvzps4plq9xBj/uXQARpJMwNvq2Tyb6QgE4Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GxsHbRC0; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8419EC433F1; Sun, 24 Mar 2024 22:39:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319991; bh=3IZlNOzBqHQHY4gQvWgHcGXr5SgHDQHzF++1kUXuWEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GxsHbRC0ORk50Gr5c1nJyJvSwmVTZNOXwdmuRSL5uuhmY4JL4Sy7DnTupEAaFu+P0 823zcy0pI54mtBp2YZyabgPhW2bbykILbDkbdDVF8n7PZ/K0hJ1mTITpSZQvF9192H WN4lKwGvmXwOB/nMRGuhvFLMFMh/96k9/TxPyeQ/pEfuIZycVU0THCq79R01k90V9Q /Pg7NKhoR1tsdKYBMqzdQQeoU/kigDdDF7488Fjo0lsPsTdsxXG7a5ywc/Ry8OtWwc 1C9Kghq3cBF9V1GzwVZeOc7oBpTVZ3Q2d5jFS0AwbVqFuSfcDfuJytN2JOIAUZZqGT tytkB9wB0nHKw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lu Baolu , Jason Gunthorpe , Kevin Tian , Joerg Roedel , Sasha Levin Subject: [PATCH 6.8 297/715] iommu: Add static iommu_ops->release_domain Date: Sun, 24 Mar 2024 18:27:56 -0400 Message-ID: <20240324223455.1342824-298-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Lu Baolu [ Upstream commit 0061ffe289e19caabeea8103e69cb0f1896e34d8 ] The current device_release callback for individual iommu drivers does the following: 1) Silent IOMMU DMA translation: It detaches any existing domain from the device and puts it into a blocking state (some drivers might use the identity state). 2) Resource release: It releases resources allocated during the device_probe callback and restores the device to its pre-probe state. Step 1 is challenging for individual iommu drivers because each must check if a domain is already attached to the device. Additionally, if a deferred attach never occurred, the device_release should avoid modifying hardware configuration regardless of the reason for its call. To simplify this process, introduce a static release_domain within the iommu_ops structure. It can be either a blocking or identity domain depending on the iommu hardware. The iommu core will decide whether to attach this domain before the device_release callback, eliminating the need for repetitive code in various drivers. Consequently, the device_release callback can focus solely on the opposite operations of device_probe, including releasing all resources allocated during that callback. Co-developed-by: Jason Gunthorpe Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20240305013305.204605-2-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Stable-dep-of: 81e921fd3216 ("iommu/vt-d: Fix NULL domain on device release") Signed-off-by: Sasha Levin --- drivers/iommu/iommu.c | 19 +++++++++++++++---- include/linux/iommu.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d14413916f93a..cd1210026ac53 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -463,13 +463,24 @@ static void iommu_deinit_device(struct device *dev) /* * release_device() must stop using any attached domain on the device. - * If there are still other devices in the group they are not effected + * If there are still other devices in the group, they are not affected * by this callback. * - * The IOMMU driver must set the device to either an identity or - * blocking translation and stop using any domain pointer, as it is - * going to be freed. + * If the iommu driver provides release_domain, the core code ensures + * that domain is attached prior to calling release_device. Drivers can + * use this to enforce a translation on the idle iommu. Typically, the + * global static blocked_domain is a good choice. + * + * Otherwise, the iommu driver must set the device to either an identity + * or a blocking translation in release_device() and stop using any + * domain pointer, as it is going to be freed. + * + * Regardless, if a delayed attach never occurred, then the release + * should still avoid touching any hardware configuration either. */ + if (!dev->iommu->attach_deferred && ops->release_domain) + ops->release_domain->ops->attach_dev(ops->release_domain, dev); + if (ops->release_device) ops->release_device(dev); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 5e27cb3a3be99..c948289f64d08 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -487,6 +487,7 @@ struct iommu_ops { struct module *owner; struct iommu_domain *identity_domain; struct iommu_domain *blocked_domain; + struct iommu_domain *release_domain; struct iommu_domain *default_domain; }; -- 2.43.0