Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2976016rdb; Fri, 22 Sep 2023 14:01:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEELGS77gzWP6eSygoO2ydNlmdBSqPr+X81MTGUqC+vMtNSkudgY48kA5PJQGrapSaTGuy5 X-Received: by 2002:a05:6830:1e64:b0:6b7:4a52:a33a with SMTP id m4-20020a0568301e6400b006b74a52a33amr926322otr.14.1695416461267; Fri, 22 Sep 2023 14:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695416461; cv=none; d=google.com; s=arc-20160816; b=l8Nx0LZMRY2MbO+9mqYTvFwVn+Mditlim2ogO4X9ilV8unZLT+0O+g47SbwQVpfQoa vo9u09PNUKPBVWQ81XUYopLel1rqNUTG97ksy5StYUsqmC0Nc4jgsZMZsVniW+OTzSUg nal3kYamobuZS95BK7oOYRg6oXX22RlI8SyzChK1r4jBvVMCt28rSDckZfVkvLnMinnH 7JwFOCfOWSoEe74UUlwBhKDQw3P8oXNChXwRACixOBPjACTYuGRkTWfH3nje8t/VUyh+ /QkL8oM1uNYKAp/u+AUZqDceSr2mZzlKkkE6dYMSUSOZ14QSgs6m5Z0ehhpeuDzHZ2Qt 5qyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=LK0sei6aawUHa9/wQJr4hhs5sIfyCAshbtkqV4BqVn8=; fh=0bR/sVRDQtplHKrdQ44QlLQfmOfcp0tO0VSD4Fg7Pfc=; b=z6aRN1bgcm7Dpeu6n/APk35UMmxEWyUsZ2jqCvOYEtu+TVd9HRFoOJvyK6wJoMVKyV Sk6ezcB9R0hBw0/1dVcx2VdheZxnxS1Udz/FzPxvNezJvCrNv1BigMAjd9c1ayL5IHLH lpkRasBtmQFW2n4dOkiSbVn7Be1+WQLXa7l46kzi4eYzDJV5DMm+9DS0QVzEn31F3ViD Bqac2DZP9vEN9s1iNIs0PC1/4KNqHvXWdrndJrPjkmMRLC6RceRuEvZ/lVb+L0uYqSdw uKcATw49fXPlRzqQ481H1Ovn9kQ0V1RUwafFFwvk3nR0E0rZnmCTdpYg+60qqE1pASO9 1+Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D8G6NUsq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id m16-20020a63fd50000000b0056c0e3c77f7si4454187pgj.805.2023.09.22.14.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 14:01:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D8G6NUsq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F00588218E4B; Fri, 22 Sep 2023 05:48:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232831AbjIVMsH (ORCPT + 99 others); Fri, 22 Sep 2023 08:48:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbjIVMsF (ORCPT ); Fri, 22 Sep 2023 08:48:05 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25500C2; Fri, 22 Sep 2023 05:48:00 -0700 (PDT) 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="411755281" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="411755281" 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 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 X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 22 Sep 2023 05:48:07 -0700 (PDT) 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