Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2648379rdb; Fri, 22 Sep 2023 05:06:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHiXfyo7FV1av1ziztlkhsWsbUOW/8EWyEXmqWt6vxOuJgO3qfhuZwpSDL0BNX+fZmsAXy X-Received: by 2002:a17:902:6806:b0:1b9:ea60:cd82 with SMTP id h6-20020a170902680600b001b9ea60cd82mr7347503plk.5.1695384361340; Fri, 22 Sep 2023 05:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695384361; cv=none; d=google.com; s=arc-20160816; b=rWStYztlFgLndVBY2xqieQ2Bd6yyjuq96Evk8CJujGCQjISIWODfKwzpwZRfkB7zKW X6Cb713v3BY7RTsMOWUjHi8LI4eLsPWhAiqkAh/jb5yeo58Ox+rpI6iE1atBYphtj+vw 6Of3VNHBm7H1ay0zkgLOJJ0mARm7+tBdyk6m+1UZbW3FRucyRUlrpz8NjJanVmw1A/m0 skqhTmwJIYcfnxhcUkJo8LiMrmiEategnT+rwzokwAs9fIVvqISGD6uz9a71huERj/39 Qmh3FR6CDdZ0igQVF1vGE/8V7WpFmCorsKSt2z3PuLOF9zeOfkyZUhzc+ndhJ0QhWxgd ZuNg== 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=lGs0xrj93lb4Z2dd7VPQsZ10Csx0oR+Z7nH90laP73A=; fh=M0W2al+OJCqa9tUf/HHWVZcqNKJOwNriXX8a8yeU2PA=; b=EFJ+WXMPnrz6VTGL64QEM4MDk9R9+bSnVxXR0iwXIcu4cuiqaZVYBsmTE3bRI9KigP mWm134p0dcCKSSP54Ogrzg+akeM+sJASZs+UX0LEVIj3a0/87dCksP34CziILVhMsZ96 SsnscosYBF9iooSuzm8AFwy2MdQgWbIlis2Jw1PuEzUH9f9oUfVXv+RvtTiSw8qeYn0F 0ZCKHzQ3Fypur1+trGJzPDLk1TTrfUpcGtrml1VgHdWDtKFHOkVTPDE+XzOTIS8v6skg dkY923/PR+Bn0hDMZxbR4FAuowYX1qCmbhS3TvneRSpH5F+GmVfsjHQW8s4+krXw81Gc xQXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bNlOXjdR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id g14-20020a1709029f8e00b001bbacfdad2fsi3480109plq.291.2023.09.22.05.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 05:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bNlOXjdR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 8129F8451ECA; Thu, 21 Sep 2023 19:48:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbjIVCsH (ORCPT + 99 others); Thu, 21 Sep 2023 22:48:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjIVCsG (ORCPT ); Thu, 21 Sep 2023 22:48:06 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E11CB19E; Thu, 21 Sep 2023 19:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695350879; x=1726886879; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=WjtJKQb906FAD2/Ch7XLbjda8s1yVinX4tQX05erhW4=; b=bNlOXjdRXt783nJXQb+YGuXZeDsxC900HQtzdeHtzEX4iNsXFtu0sZP/ vcsu7ps1XcyoQ7E3jl3I/wC+P6V2MkQGT9QeJs10jLimtQL86hzV6h92o /I77QZvSTNnI/r/5tEwMz0LNlyYo49smcxxj8cfg5/PTcL+LvnJex+GBX EwDBSswRkc1bdIninUBmatkELqdSKy+gooc/QRxSpbLcgmP/DXDMxOeiP p7fSQx7yUw7/oyDifynbsS2mXWCPa7beRJFipKtK20npoVtHa7Tp1JfAL RGre0C5ZHQQfhw0rhSHIl4reBnYcjF86I584mOrneSbbHSVqxkeTgPrKo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="360974368" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="360974368" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 19:47:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="920986298" X-IronPort-AV: E=Sophos;i="6.03,167,1694761200"; d="scan'208";a="920986298" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by orsmga005.jf.intel.com with ESMTP; 21 Sep 2023 19:47:55 -0700 Message-ID: Date: Fri, 22 Sep 2023 10:44:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Cc: baolu.lu@linux.intel.com, 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 , "Liu, Jingqi" References: <20230914085638.17307-1-baolu.lu@linux.intel.com> <20230914085638.17307-10-baolu.lu@linux.intel.com> <20230921233402.GC13795@ziepe.ca> From: Baolu Lu In-Reply-To: <20230921233402.GC13795@ziepe.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 19:48:12 -0700 (PDT) On 9/22/23 7:34 AM, Jason Gunthorpe wrote: > On Thu, Sep 21, 2023 at 11:25:56PM +0800, Liu, Jingqi wrote: >> >> On 9/14/2023 4:56 PM, Lu Baolu wrote: >>> Make iommu_queue_iopf() more generic by making the iopf_group a minimal >>> set of iopf's that an iopf handler of domain should handle and respond >>> to. Add domain parameter to struct iopf_group so that the handler can >>> retrieve and use it directly. >>> >>> Change iommu_queue_iopf() to forward groups of iopf's to the domain's >>> iopf handler. This is also a necessary step to decouple the sva iopf >>> handling code from this interface. >>> >>> Signed-off-by: Lu Baolu >>> --- >>> include/linux/iommu.h | 4 ++-- >>> drivers/iommu/iommu-sva.h | 6 ++--- >>> drivers/iommu/io-pgfault.c | 49 ++++++++++++++++++++++++++++---------- >>> drivers/iommu/iommu-sva.c | 3 +-- >>> 4 files changed, 42 insertions(+), 20 deletions(-) >>> >> ...... >> >>> @@ -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. Best regards, baolu