Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp244492rdb; Fri, 5 Jan 2024 08:25:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IErr+kN2A8C54N49sTc5smDZC408kwmzb6ruJTUO8wAzYEWVL0WbULNXKVh4E6gxRCRzmQY X-Received: by 2002:a05:6512:3b84:b0:50e:7a9e:5c78 with SMTP id g4-20020a0565123b8400b0050e7a9e5c78mr836374lfv.151.1704471952622; Fri, 05 Jan 2024 08:25:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704471952; cv=none; d=google.com; s=arc-20160816; b=ZPha6J1WcqO99Bs/hnjYt+zbAQTfL1pqtKRkrYC0VsNBCBlIogGu3xzgPZLO5+vu+Y Lz+CVwkIZ+/AkT10I/0ySsjwj3C2w8E20SV/M8jhmexAHGSaSnAaYO+F+fCIAFBTG3OF 1cH3iCsrMJ7KmrQHUuXvpvNc9UVyI9RNYLxMnCU/e1+xGdbVNKWfz0ZHHSF2OAHQWOIE P4dWddHKB9z8K+tU57NVeoAlCTQAfiAdof7cj2d3AvZrCUIWtkM8zD8JEdDLeqPgkFxp Ry4m5Qr4MdyN6f6ASgWbPy8gc8oMarK5I7fHyNqTTkVtup6QXIZktHszKSdJXOWsSCxr oh6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Xt6bOKxX4WKSd5QuH7ry/2mZIxNV/j9IGmlac4AQg1Q=; fh=LjrnQdUjVV5X3XIgJYPM443ykgMLMNshafdbFec1v5k=; b=UuXLS9z0FMCXRStIKBYVA6ZPjZqqnLlzcSLHI+XZX9wmaQ8njB1U5Iz8t/a2JwfPFu WiUxcEmmJYqGDtfWpQQaWMTw9tErOgjVNSA+RalBt3JcN1ZBBozAkNav6v4CpbmFrUq6 PGI7AGvJshymzEt9jT8iuz4Trt7f7yOQg1lm2Oq7IBEfEnzsiqQEFbj1fZUQ/qAs6KfQ enOlCSCUZwL1jCdFP0ClysiAIfnglsSvRCLi5lRcdmW98UNVDSPH9dBiqWN/LBW6IGQR RKhE54A51V1Mv25MvzWFZBZO+Dmi8RMRhymt2oeXyuydMSxkkvQQKYasgye/Rg8WMBBN rWWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=X7QrslCm; spf=pass (google.com: domain of linux-kernel+bounces-18061-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18061-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e2-20020a1709062c0200b00a1da6786698si730806ejh.930.2024.01.05.08.25.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:25:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18061-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=@ziepe.ca header.s=google header.b=X7QrslCm; spf=pass (google.com: domain of linux-kernel+bounces-18061-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18061-linux.lists.archive=gmail.com@vger.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 am.mirrors.kernel.org (Postfix) with ESMTPS id EA4D81F221BB for ; Fri, 5 Jan 2024 16:25:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08E553173E; Fri, 5 Jan 2024 16:25:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="X7QrslCm" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91A072E852 for ; Fri, 5 Jan 2024 16:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-5edfcba97e3so18272627b3.2 for ; Fri, 05 Jan 2024 08:25:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1704471941; x=1705076741; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Xt6bOKxX4WKSd5QuH7ry/2mZIxNV/j9IGmlac4AQg1Q=; b=X7QrslCm8Hjgqy4GrPM7QIUCYsRj7QiPrDpw8+cvLZapgFDjYVulbuIbTkc5oOWVh0 edVzaOXBhzXsiNxULvmhF61xSSBhvfng3aZsPU7HNEb+bsJmNhWpxMQDb7aqM/2uSeZG alze4MmOoCon4EAuMZfEftvVb/qCcfQN019KIukNWWLHSCTL0Td6D3BvP23muTn1buCL NpLD/gRuyL9dms28cW1mGr+cHzV5BsYjQ9jMzi5IOlf+3HpjISUsrsXCJkf0J5j7gaqB Z0ZQbBtoq+0M9t7tLMHe+CYB4/zthh13yE9vqoxV1KEn6tb6epCE5T1iO3lTO52Ki4UE OiUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704471941; x=1705076741; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Xt6bOKxX4WKSd5QuH7ry/2mZIxNV/j9IGmlac4AQg1Q=; b=NuIshaZPHHXOLCqw1ctppZwB4wqjVDHdLtkNKVlAXL8FU+w49a9/kPSIAP54EWVC8N ioW8I8z+cbhL6yK3VqL1AJWZNxKmuIq/P6rxW0v1ZYfCmfysEmDXqP19kJhN2Mi0wrhm K+9l9+68r/o6Av7dFZ/cZs9JQ3BYkvbufnQ7rAwq88gvSmIlYT4SPZUACNil5ykqpfm6 Q6gjUciE2PB4hPcZd01EwZsHgyw3XYaIhquSY9X4zfUb603nVCNusEh40UtJiU1dQnPF 7fkEWiZywAcfhz9a4W2kgVe/suLdKLjpcyT051Osf9B4xdrO8WQjQkN7tC8dDG3VVmyY F3ww== X-Gm-Message-State: AOJu0YyJ61dJwp7l1NxbZmbpY0SZnZ3mD3Xzupb2BKK0ba3fmb6qL4y5 r+YJ0Ob4cjVGvdGYFZJ7N/isxIm5+TBWNQ== X-Received: by 2002:a0d:c783:0:b0:5ea:c5d5:6a00 with SMTP id j125-20020a0dc783000000b005eac5d56a00mr2373497ywd.55.1704471941479; Fri, 05 Jan 2024 08:25:41 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-68-80-239.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.80.239]) by smtp.gmail.com with ESMTPSA id da13-20020a05621408cd00b0067f9bbd1689sm720815qvb.76.2024.01.05.08.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 08:25:41 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rLn0u-001Td8-HY; Fri, 05 Jan 2024 12:25:40 -0400 Date: Fri, 5 Jan 2024 12:25:40 -0400 From: Jason Gunthorpe To: Lu Baolu Cc: 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() Message-ID: <20240105162540.GH50608@ziepe.ca> References: <20231220012332.168188-1-baolu.lu@linux.intel.com> <20231220012332.168188-14-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231220012332.168188-14-baolu.lu@linux.intel.com> 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) But this looks fine either way Reviewed-by: Jason Gunthorpe Jason