From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) (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 CE856168AA for ; Fri, 22 Sep 2023 12:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695386880; x=1726922880; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=SJXKFbW5yysENzxXAszyP4/ZxPxPNmpz+BMzxHg+9d4=; b=D8G6NUsqFves0I1Ra9o77ZuE4f9Lfx8plJKrfSSWsGuCQjUdsIe1aDmX c0WPCeWCxnOYiFUfb3U8FVLt4s4qYqq7F6qDJLKLshKmcJA/9/dDD2R3c BfWFES6j9Xs+5qjiXkaACfXzQ6bW8ZPCyn4PgsARHvys8kw2Q0slPI5dL 6DjAPPhLSNu7FeW/F710Su/CGnGoH8ds7eE1vI4FLR4NN0DdsFrUgiicb 0RmIkEp5XQzOFRkHaRWHLv7vK0rnlHnSd1ly8RLXw42zMTyQNoGQCPErd 8jyP61oV36KlqXlu3bdoP+xOMfCun7dB9kIlBxcIDAlcxyi9KOivvsRFu Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="411755282" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="411755282" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 05:47:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="862936012" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="862936012" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.255.30.83]) ([10.255.30.83]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2023 05:47:37 -0700 Message-ID: Date: Fri, 22 Sep 2023 20:47:35 +0800 Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Cc: baolu.lu@linux.intel.com, "Liu, Jingqi" , Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 09/12] iommu: Make iommu_queue_iopf() more generic Content-Language: en-US To: Jason Gunthorpe References: <20230914085638.17307-1-baolu.lu@linux.intel.com> <20230914085638.17307-10-baolu.lu@linux.intel.com> <20230921233402.GC13795@ziepe.ca> <20230922124303.GE13795@ziepe.ca> From: Baolu Lu In-Reply-To: <20230922124303.GE13795@ziepe.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2023/9/22 20:43, Jason Gunthorpe wrote: > On Fri, Sep 22, 2023 at 10:44:45AM +0800, Baolu Lu wrote: > >>>>> @@ -112,6 +110,7 @@ int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev) >>>>> { >>>>> int ret; >>>>> struct iopf_group *group; >>>>> + struct iommu_domain *domain; >>>>> struct iopf_fault *iopf, *next; >>>>> struct iommu_fault_param *iopf_param; >>>>> struct dev_iommu *param = dev->iommu; >>>>> @@ -143,6 +142,19 @@ int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev) >>>>> return 0; >>>>> } >>>>> + if (fault->prm.flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) >>>>> + domain = iommu_get_domain_for_dev_pasid(dev, fault->prm.pasid, 0); >>>>> + else >>>>> + domain = iommu_get_domain_for_dev(dev); >>>>> + >>>>> + if (!domain || !domain->iopf_handler) { >>>> Does it need to check if 'domain' is error ?  Like below: >>>> >>>>          if (!domain || IS_ERR(domain) || !domain->iopf_handler) >>> Urk, yes, but not like that >>> >>> The IF needs to be moved into the else block as each individual >>> function has its own return convention. >> iommu_get_domain_for_dev_pasid() returns an ERR_PTR only if the matching >> domain type is specified (non-zero). >> >> Adding IS_ERR(domain) in the else block will make the code more >> readable. Alternatively we can put a comment around above code to >> explain that ERR_PTR is not a case here. > You should check it because you'll probably get a static tool > complaint otherwise Okay, got you. Best regards, baolu