Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp95482rdd; Mon, 8 Jan 2024 19:41:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFz9/ccti7nSW/k/SQrdjX9mFLnT29vfLXxc/oYb/cZGX4KKaIjybniX1lFVHkgVj85hDXQ X-Received: by 2002:a50:d002:0:b0:558:14e6:ccac with SMTP id j2-20020a50d002000000b0055814e6ccacmr14627edf.20.1704771710218; Mon, 08 Jan 2024 19:41:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704771710; cv=none; d=google.com; s=arc-20160816; b=QC24YHq7UykOwLryMjNql6B2Oxtx8ngbnKoCxP2gtPK7x1JRPkyMhu0gdP6gKzQAwm rNVi6rLHV6SAjf0At7BTGnGvUM4HwTJVaxCiGmiRs3Td7cAVep8OIZ2SIZ3yGXyq+OnG 4IEJ9Pw7pfVs9mT9sNz5bQ0sCqvCqzFVTFtk0k3Nig4JjrstJQoVBO6HG6pY/TivY+My 3571xvbu0oBG438RsnKQa8QChxKwmevrVGv8N59SjsStpA81fu8q8Np+ZQiZcgie24W+ qsnbC3ukLNZMKNAuoHjt1AD+LYR1Adze1LJzbP5lWGkzWtiP5Sx1dze4YtiuP9rg0ziO 8Z+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:cc:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=CFrmz8bKkeSw4HqdfUqUiyMvIVvfWkQDStaNdoflK1o=; fh=uzznn7J+IYAjVbPHItJO5zuzOqyiZAy1PaNe6S3d3bk=; b=eo/uaQiUSEZYekTjjZIxoLvEjXH2PV+PwPGbFki3JF4uzYYMRS/xS6eeQOU3ppPXLW P9CKfpHKVPhJ3bheKsgV2hEDuOkxOxVad2VqUc4yDYH69NC9kMRONGN/O4yKQBcNN8UG sBkdlrPPn+zDGM7SKG59iEXuI5STi36n6WQv2PnZ5F4CXv1hKLCCPf6f1kZSLHnE8/E/ VGgDhKjaKplfSXeuz98MyAucSxCI+TdldkIdsoT3JChJ24TdEeQjAzf73mvfKtjE91T9 uojQWasU6uOiKwQsTZRkHMkx2umN0ey3qiVMwsBWWj5c39cF4B9vb72KkQsVqyFhn6BT 43fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=agEMEu1T; spf=pass (google.com: domain of linux-kernel+bounces-20332-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20332-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. [147.75.80.249]) by mx.google.com with ESMTPS id g9-20020a0564021ec900b00557b08020e5si221960edg.188.2024.01.08.19.41.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 19:41:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20332-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=agEMEu1T; spf=pass (google.com: domain of linux-kernel+bounces-20332-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20332-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 F3D091F242AC for ; Tue, 9 Jan 2024 03:41:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15EA553A8; Tue, 9 Jan 2024 03:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="agEMEu1T" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 F02DD3D86; Tue, 9 Jan 2024 03:41:36 +0000 (UTC) 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=1704771697; x=1736307697; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=0LdLdd5VFFhLorx8pbQnlS22X5wJJoCIwyGO5I6Dq9A=; b=agEMEu1TNril1O3jlbBCjBr6ne98c9odINZ2FWUST+vjAwn6MdnqMiBg xoIp3BdOMd2ziVK14cKmRuEUl4knqkFw4Pz+zyiKKIhgRIFNAhHw2KOxc M/dsnd0sncJkBW/g6C/EX3CTv3ofiXlXNy+70LD9LU2VSovKxjCl6J87T OD0mK1qNC6pZzqRaLUwhc/eTOXy+LHmfbAsswL8hVkELA8QoXUfFxCCuM Hhzw+Doz1zFMwNLmqlhRnxFio93vdumvO1BSenQrprpvkORhCy+pJSDGH 0NSANstjXGkJtkfb0hApieXATjvlAQGRsj6Rrbl9E3DG/UetUF+VZ0xJT A==; X-IronPort-AV: E=McAfee;i="6600,9927,10947"; a="16667563" X-IronPort-AV: E=Sophos;i="6.04,181,1695711600"; d="scan'208";a="16667563" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2024 19:41:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10947"; a="852024581" X-IronPort-AV: E=Sophos;i="6.04,181,1695711600"; d="scan'208";a="852024581" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by fmsmga004.fm.intel.com with ESMTP; 08 Jan 2024 19:41:32 -0800 Message-ID: <91c2add2-3015-4935-9dd5-d4e42aff473a@linux.intel.com> Date: Tue, 9 Jan 2024 11:36:19 +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, Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan , Longfang Liu , Yan Zhao , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 13/14] iommu: Improve iopf_queue_remove_device() Content-Language: en-US To: Jason Gunthorpe References: <20231220012332.168188-1-baolu.lu@linux.intel.com> <20231220012332.168188-14-baolu.lu@linux.intel.com> <20240105162540.GH50608@ziepe.ca> From: Baolu Lu In-Reply-To: <20240105162540.GH50608@ziepe.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/6/24 12:25 AM, Jason Gunthorpe wrote: > On Wed, Dec 20, 2023 at 09:23:31AM +0800, Lu Baolu wrote: >> -int iopf_queue_remove_device(struct iopf_queue *queue, struct device *dev) >> +void iopf_queue_remove_device(struct iopf_queue *queue, struct device *dev) >> { >> - int ret = 0; >> struct iopf_fault *iopf, *next; >> + struct iommu_page_response resp; >> struct dev_iommu *param = dev->iommu; >> struct iommu_fault_param *fault_param; >> + const struct iommu_ops *ops = dev_iommu_ops(dev); >> >> mutex_lock(&queue->lock); >> mutex_lock(¶m->lock); >> fault_param = rcu_dereference_check(param->fault_param, >> lockdep_is_held(¶m->lock)); >> - if (!fault_param) { >> - ret = -ENODEV; >> - goto unlock; >> - } >> - >> - if (fault_param->queue != queue) { >> - ret = -EINVAL; >> - goto unlock; >> - } >> >> - if (!list_empty(&fault_param->faults)) { >> - ret = -EBUSY; >> + if (WARN_ON(!fault_param || fault_param->queue != queue)) >> goto unlock; >> - } >> - >> - list_del(&fault_param->queue_list); >> >> - /* Just in case some faults are still stuck */ >> + mutex_lock(&fault_param->lock); >> list_for_each_entry_safe(iopf, next, &fault_param->partial, list) >> kfree(iopf); >> >> + list_for_each_entry_safe(iopf, next, &fault_param->faults, list) { >> + memset(&resp, 0, sizeof(struct iommu_page_response)); >> + resp.pasid = iopf->fault.prm.pasid; >> + resp.grpid = iopf->fault.prm.grpid; >> + resp.code = IOMMU_PAGE_RESP_INVALID; > > I would probably move the resp and iopf variables into here: > > struct iopf_fault *iopf = &group->last_fault; > struct iommu_page_response resp = { > .pasid = iopf->fault.prm.pasid, > .grpid = iopf->fault.prm.grpid, > .code = IOMMU_PAGE_RESP_INVALID > }; > > (and call the other one partial_iopf) Yours looks better. Done. > > But this looks fine either way > > Reviewed-by: Jason Gunthorpe Thank you very much! Best regards, baolu