Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2726000rdb; Fri, 22 Sep 2023 06:58:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtMc1PkHpUcHUyl6Q78ySpUgRp9XorXQTrXmceVYk0q2ubYhXUnXXUuSD1HvL+6QAU6fqa X-Received: by 2002:a17:90a:fb42:b0:26f:6f2a:a11 with SMTP id iq2-20020a17090afb4200b0026f6f2a0a11mr4214111pjb.12.1695391119210; Fri, 22 Sep 2023 06:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695391119; cv=none; d=google.com; s=arc-20160816; b=M1gbj2UYU03rwBBdUQrYAggMrgb/v16vLbZrsqhI25J8k5svneYKh25eQ6espZG/yy 2loIQvTSIV6a320ZmwpW77dT2lEdWh1xz81xP1w+VEnJVrFNBzOzKF728XxkPmoG1Suh p5Y0guWJP0NZVps6nFZe2BTuQe/uLqsWYTdPaXmkPegU5A6prwxAz1ho5NGnEk1KXD98 Sv6rDyoSSvv4zTVdoqoFDupSRLY4w3ZAtFwATlao1cJIy29w6eDMtaIaaXonepgf5kSP za+EuGx0JxzR/FtgIBobPPmYO2CszkHskRKrcfdrC0L8wfjntuP78XqPeTmvZ6FJS+SD Z4Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=dJYX5wUywumkDIjBBuCsh0129IAPGx0MBB+MpKbn2U4=; fh=nLWawk5zjqj0gOPSMoU9xoh8JsLw6mfKUmlOROmtOns=; b=gD1dcx9XPBRH/78uqKTzhTjhvnhSkNVjXEfMbhSMsExsJQ4Pw6K3u0aZnATtucKmQT W6zVitqcSVu8MWNckMD58lGP4YspuIwCoavxZIeNHgFrVRNbsDKrY4Xkd8ZmHMLLwGBt 4aoIrKLf7gx0Oaurh7y8xPErQbew85kQATKxf74tJEi6v+HPlKZeKeepJ4NOz/fb2+VG tfhdUvGjoZ1AGsSRznA6FDk7Ve7dnBPDNWNO4On2tSLvKIM33EUhuFGljf5viyvogA/n dHHZak/VWtRRwGs2C3roQrLAcZA4jXf8FZKYd49mfgUxCFJZrYJrBgoidg59jwb4kriU YtDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b="S/+WhR0E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id co11-20020a17090afe8b00b0027652755c21si3899061pjb.142.2023.09.22.06.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 06:58:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b="S/+WhR0E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8503A8042D3E; Fri, 22 Sep 2023 05:43:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232813AbjIVMnN (ORCPT + 99 others); Fri, 22 Sep 2023 08:43:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbjIVMnM (ORCPT ); Fri, 22 Sep 2023 08:43:12 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F394C2 for ; Fri, 22 Sep 2023 05:43:06 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-77063481352so166490985a.1 for ; Fri, 22 Sep 2023 05:43:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1695386585; x=1695991385; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=dJYX5wUywumkDIjBBuCsh0129IAPGx0MBB+MpKbn2U4=; b=S/+WhR0EEnJ8PYQjfLxvP/f8zSmaS2TJz8yqoHYbn5vdHZaiYYf26Ob1MkfvPAyqs8 oFSKekKBQ/mU3IC/CGv2bNtSuI0E2q2cIsp9cQMsQ6VMRcQAOibLdgBphE1cx7ezNubB gG5g4o2UxEbb/Rn23c+zj+9JWLw3kA0ubjdblJlIT/+oc+8ECUap29TaOlyzH4Hn59GL qBm58FEiOltgDH71IGtrO3xTlLHtMs1e6vZ4PURnJMPpz11XC+hofEdZzWHlu/vmh3oe 2uIsmQr71MkMohuReFCgLi+L+q+hBH+Zxeh/DwVCHDBlPDWizLecyMlkCZYohhU+cYZS K2NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695386585; x=1695991385; h=in-reply-to:content-transfer-encoding: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=dJYX5wUywumkDIjBBuCsh0129IAPGx0MBB+MpKbn2U4=; b=M0O5G45d7EnXmHUZisB6aM6WO0sbkMyGis35Z3ucHMXiI+kaVgXT9NcVbN/R3DFplf yb/rteVdeATXCRtpqEX2n8LOgP+7YRJ+7rzFe/tz2sLn3B2mJbcXMM0ogM5Jyxhyve2A 1wBNiDKJdXWz2uhASFVuhfkyV7UEcdwVbOkCgWQhTBkZMm05hhriBu4Go/rYyzaOzE4M BAoYvMSVSjdJ7xUJ0ovzhJYEe5JJuMIrcVK783x8MXaf29OLdWi6dHJsaQBhUNV9no09 awF1xOMNGPS+ubn77rTNVkoFmmA/pSoH83in/4xvRxtcseqRSkh5E8qHNijZLD2FOOdz 2nLg== X-Gm-Message-State: AOJu0YzTBjgye8N5b3Zei3t5YDu7LseXiaCLhXm9TDm5maeK5oufAomh WGlt3xvqQ278HmBttWvgaC0pyA== X-Received: by 2002:ad4:5de7:0:b0:656:519c:5a07 with SMTP id jn7-20020ad45de7000000b00656519c5a07mr3118747qvb.25.1695386585198; Fri, 22 Sep 2023 05:43:05 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-26-201.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.26.201]) by smtp.gmail.com with ESMTPSA id t15-20020a0cde0f000000b006588f418323sm1396225qvk.64.2023.09.22.05.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 05:43:04 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1qjfUt-000Y5A-VB; Fri, 22 Sep 2023 09:43:03 -0300 Date: Fri, 22 Sep 2023 09:43:03 -0300 From: Jason Gunthorpe To: Baolu Lu Cc: "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 Message-ID: <20230922124303.GE13795@ziepe.ca> References: <20230914085638.17307-1-baolu.lu@linux.intel.com> <20230914085638.17307-10-baolu.lu@linux.intel.com> <20230921233402.GC13795@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 morse.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 (morse.vger.email [0.0.0.0]); Fri, 22 Sep 2023 05:43:20 -0700 (PDT) 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 Jason