Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1880929lqo; Sun, 19 May 2024 03:09:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUjt3hokclBcqF2dUPbqBISKeIi2NYV4wb2PKFtMnQNsg1HF2TaEgbqoHrpKoVHJGoVCgXbWmRieqB7/v5u4m3j49nwR0xtqbOnTFjd4A== X-Google-Smtp-Source: AGHT+IFeDIGiweKA1bCoZjSAWcCX7VrOsV5qZHMqYS1SBd3OWJwJ+WfswomxQjweJ3EMRQmOJcAP X-Received: by 2002:a05:651c:78e:b0:2e0:a39b:2b25 with SMTP id 38308e7fff4ca-2e5204b2d6bmr149586601fa.48.1716113386174; Sun, 19 May 2024 03:09:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716113386; cv=pass; d=google.com; s=arc-20160816; b=RQZ4qgk2RRNUmdx+7mbMisSM22GBEgoNCQz0D1Nt3CzYzswwKn3IrYW7knPZ0XUyme XxUfHTvU3TguYMjj+AZszQ18wJeN2JQ1YNbzTbZHqfDDm16Xv/V6Yj8JTDnMywxIKyDC NLMinh/l34foQ6qswzBspQne4UbuZvcABa8wyWqpD12gs5Z+6cbOvfPiW5OjHyBAbShZ pkzLtUCnPqB02Jbm5hkBkBLv8Byic3H/grbeySONi1F/NEFdi9PMYX4t6YRawq5qLCZo L/NalzZdwku/RiYl+MlLmwE/iOFKZ8w+hWuUEyVA7/qT3R1k/CKabatA2s4hAtThd4Nh uXog== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=WLnYWkolgvoLflCjwdVIO6CQg5PSM5GVTNiOXH6dJD4=; fh=zee1/DmexK6O20G2HAo839W0G8FAWGWtJrXd39uschA=; b=Dn89G9KxrchxzP+hpFjObj+6vtSu/ws4g87i3KZnXgLtELD37UJmBChZAcsEKIeU13 mSYmdcWZKPl4kDqHvVVY6PYICixTcu6dGsxwlRKuggaICZ7sTsD+YglrHRi2MVaB03ND iSFgwUmag+Fw5n2JvULTmUhw8MnDe6MBk8XMgMkwaSyjEV/kZBTGfTdKbizpfAHBnLoj YdqLNxxGcAPNviNVqvI3/504sP3uDAHoe5viNznOX1RuRSpnVOqKG6ZX4pVR02AHmr8m dGxa2phBv48b/WvbbL9xy9dpb/eZrWNRL4UOTs4+34XxXqXHI9Uk5/Z2T8EY7q+7xjI/ cHfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YRDse6g9; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-183084-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183084-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733bec1952si11891587a12.185.2024.05.19.03.09.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 03:09:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183084-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YRDse6g9; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-183084-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183084-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id D503E1F21553 for ; Sun, 19 May 2024 10:09:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41AF72E417; Sun, 19 May 2024 10:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YRDse6g9" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 091073AC2B for ; Sun, 19 May 2024 10:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716113378; cv=none; b=jgKK4qdkHpFqo3x9MQig18DjXpBxA1VGzx8k7U8agFXquPME8DG1VrGE47xpRVwrMx6oSMHNgZQZJM+sF++SkP9o2mFmjTwjromOA+X1e4kHjlQ37KZja9D0U8+WbH6onW2dDo5MZHl93pUEo3TPDbUdjx/oYfJUsqJlGWsBvGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716113378; c=relaxed/simple; bh=3pqbNvdYRhWc2XQ8kSFBcuNQeXXTsBDv7SxsX1AkypM=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=gwtpPmV/HXQbVggxLJT57hQh2vvKaSIxCap5YG95b6mfKbuhOzjLPtzX0XH4LySc6vXF9/nnlyqhCf+VYx1pAhTz28/IQAiw6nqaxqqXI4LKTiWZUwvaRXBUDK2iJpr6WXrFT5Olfbks/4v1yo9px3svQOa582esDBVfobsgnHI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YRDse6g9; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716113377; x=1747649377; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=3pqbNvdYRhWc2XQ8kSFBcuNQeXXTsBDv7SxsX1AkypM=; b=YRDse6g91xqVnsB8XW8ajG3bVSJVarNLmyn6ZcwooVqvQXTeLG6QZm7U o/FQhxte0AgXoitpmMQuxw/aRAuRq8Kay3gEythScQ3JJNgzm5yyQBrP1 4BKR5ngHvAqXU0qFSiEXIrriNb/OkFABw6wI7OJp/UTuYfSTNyWpBNrG8 iBctL7wUotrFWuzxIXXaQ15fkJE4Y5Lo7VOljNhgdxtMSp2WPQ33t+4tQ uUXOynC5iSeFLNpiQgqq8BDdAla2onLqRxjgaOaYD5pIysB8X7PEFuS+w +dNFy74W5hyt6bk/iXvoTaYA9mBbovduzC8puWaevmguBHlOy5kwBk6vW w==; X-CSE-ConnectionGUID: XO4TfK4tTZmoQRvH80fHcw== X-CSE-MsgGUID: XXJ01MlxRNqnmykjfNtblQ== X-IronPort-AV: E=McAfee;i="6600,9927,11076"; a="12422241" X-IronPort-AV: E=Sophos;i="6.08,172,1712646000"; d="scan'208";a="12422241" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2024 03:09:37 -0700 X-CSE-ConnectionGUID: Fz4KnX5YTNaXWKsOX48Lkg== X-CSE-MsgGUID: TmitfyhdQs++X2CiWV1/2g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,172,1712646000"; d="scan'208";a="37168261" Received: from unknown (HELO [10.239.159.127]) ([10.239.159.127]) by orviesa004.jf.intel.com with ESMTP; 19 May 2024 03:09:33 -0700 Message-ID: <6b0529a9-b1c6-44ba-8c45-ad233de6484e@linux.intel.com> Date: Sun, 19 May 2024 18:07:42 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, "iommu@lists.linux.dev" , "virtualization@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , Jason Gunthorpe Subject: Re: [PATCH v5 1/9] iommu: Introduce domain attachment handle To: "Tian, Kevin" , Jason Gunthorpe , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Nicolin Chen , "Liu, Yi L" , Jacob Pan , Joel Granados References: <20240430145710.68112-1-baolu.lu@linux.intel.com> <20240430145710.68112-2-baolu.lu@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: 7bit On 5/15/24 3:17 PM, Tian, Kevin wrote: >> From: Lu Baolu >> Sent: Tuesday, April 30, 2024 10:57 PM >> >> +/* Add an attach handle to the group's pasid array. */ >> +static struct iommu_attach_handle * >> +iommu_attach_handle_set(struct iommu_domain *domain, >> + struct iommu_group *group, ioasid_t pasid) >> +{ >> + struct iommu_attach_handle *handle; >> + void *curr; >> + >> + handle = kzalloc(sizeof(*handle), GFP_KERNEL); >> + if (!handle) >> + return ERR_PTR(-ENOMEM); >> + >> + handle->domain = domain; >> + curr = xa_cmpxchg(&group->pasid_array, pasid, NULL, handle, >> GFP_KERNEL); > > this could be just xa_insert() which returns -EBUSY if the entry isn't NULL. Yes, exactly. > >> + if (curr) { >> + kfree(handle); >> + return xa_err(curr) ? curr : ERR_PTR(-EBUSY); > > 'curr' is not an error pointer. You need ERR_PTR(xa_err(curr)). Fixed. > >> int iommu_attach_group(struct iommu_domain *domain, struct >> iommu_group *group) >> { >> + struct iommu_attach_handle *handle; >> int ret; >> >> mutex_lock(&group->mutex); >> + handle = iommu_attach_handle_set(domain, group, >> IOMMU_NO_PASID); >> + if (IS_ERR(handle)) { >> + ret = PTR_ERR(handle); >> + goto out_unlock; >> + } >> ret = __iommu_attach_group(domain, group); >> + if (ret) >> + goto out_remove_handle; >> mutex_unlock(&group->mutex); > > It's slightly better to set the handler after __iommu_attach_group(). > > doing so is aligned to the sequence in iommu_group_replace_domain(). I did it in this way because erasing an attach handle is easier than rolling back the group to the previous domain from the perspective of coding. I didn't realize attaching the group and storing the attach handle had to be done in a specific order. > >> @@ -2211,13 +2307,33 @@ EXPORT_SYMBOL_GPL(iommu_attach_group); >> int iommu_group_replace_domain(struct iommu_group *group, >> struct iommu_domain *new_domain) >> { >> + struct iommu_domain *old_domain = group->domain; >> + struct iommu_attach_handle *handle; >> int ret; >> >> if (!new_domain) >> return -EINVAL; >> >> + if (new_domain == old_domain) >> + return 0; >> + > > __iommu_group_set_domain() already does the check. Removed. Best regards, baolu