Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2216333rwe; Sun, 28 Aug 2022 06:23:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR4yl5E8RhWcZlqpVI341PycV+WgEH57f5lZZpNamqIqMzhL1YeEKBb/1Kr/Ev0qTMvzh69j X-Received: by 2002:a05:6402:2744:b0:446:ab07:eb52 with SMTP id z4-20020a056402274400b00446ab07eb52mr13137374edd.83.1661693030889; Sun, 28 Aug 2022 06:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661693030; cv=none; d=google.com; s=arc-20160816; b=WILduCvoWKTER54Nwcza6uCanzaRXjPuudF+HMNikPY5mtHBRQNVzPmBp6bFRaVq/U FEBG5yJ5ilgSJng03oA6EfIh6/Pw1PaUaMtX13QGVEOjQWW/L6ElvUNNTsBxyhX01OoR SgZ/wHyXkg/xx0WaEwP0db95mSdVhvj25jgN5aJRDkfotZE+wbdUOzGLsCvie3fM7fWf uuHfuGEgdRhvyfGHjO3G4wTCHXICkSzLBuYmaz6ktUgEIZOn3AP+WzUemifAE1Aw+kL5 Iz3R3BGwS0zfKjvu/lCTFQtwp9Ji1kT6W+qUMLftrXS/6mxAlAf/R07S0XuBOjxgb7/g SulA== 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=5VLEEmxqOCcOLgyJJuTxn9Kp3LLzhoDkNPtTvfmgVd4=; b=zBD8DIFblQcvmzapnXt9C3WbClhdTrHhp+rYebxw5/CE6BN5fWOhaNJSqexgGpfAGK YPh1+vIRmDQTcjfqxQpvIGgx2dWl4CcxAJ+5ezXIwgf2VTZ4KS2I81sbpbJjZna3WuKx O0uY2xAh44zXSPQwxOGRuyLA4GYFFCwmwQWmLp4BlTmWXqvYL/bO4aEX2h+ikNI62RYQ iIV4QlHb8w52BZ0wgF/G7RFkA0+3I36QA40im6ReXRvznuSDNfwwKdAHaxVnlD39ntP6 FmH4EkFKpQkh25tDKID3RciB0woJ1pnARynC3TPt542VISr1ejGVdH8ziJdETaEmV1eO fBXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QYHyo0pq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb13-20020a0564020d0d00b00447e593365esi5851469edb.150.2022.08.28.06.23.25; Sun, 28 Aug 2022 06:23:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QYHyo0pq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229530AbiH1MwX (ORCPT + 99 others); Sun, 28 Aug 2022 08:52:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbiH1MwW (ORCPT ); Sun, 28 Aug 2022 08:52:22 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03085EE25; Sun, 28 Aug 2022 05:52:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661691140; x=1693227140; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=YaVpDFcSktopVayCz3BxH2mKjkt04+621MmiMmMBYRs=; b=QYHyo0pqljdwou6lblZmg4Mr1X8jcrNONL92NxoJ+IHc597f0KGC0Gk+ 10PHhzz6ndtmCKPPifTPPbDy0pJbs8K/ZNNUwYL5bszrgLJImRCg+xFiG ff6LGud8YS4yjCrbdsX2iLIJyzr9/+CAUdVHFqPAU22h1MaWLV5ztYwng O0AYyG8rJx33eXEAd0jShMcF7tUbI+gDo93ybDk0Sy/LP6DqXUjyOGoDx h8FGcr+bV3ghSUsSBxEywsh0j4NRmvJmI98vmmUzFHH67Cwhg9vWGfGnZ oIjGps61cMXLFC7FnvbmGX3cOLs9wEBPgQkBNwFmf5uvBKKfdFMvS1eH4 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10453"; a="294746106" X-IronPort-AV: E=Sophos;i="5.93,270,1654585200"; d="scan'208";a="294746106" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Aug 2022 05:52:20 -0700 X-IronPort-AV: E=Sophos;i="5.93,270,1654585200"; d="scan'208";a="672051439" Received: from cyue-mobl1.ccr.corp.intel.com (HELO [10.254.209.98]) ([10.254.209.98]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Aug 2022 05:52:16 -0700 Message-ID: Date: Sun, 28 Aug 2022 20:52:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Cc: baolu.lu@linux.intel.com, Joerg Roedel , Christoph Hellwig , Bjorn Helgaas , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Fenghua Yu , Vinod Koul , Eric Auger , Liu Yi L , Jacob jun Pan , Zhangfei Gao , Zhu Tony , iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Jean-Philippe Brucker Subject: Re: [PATCH v12 05/17] iommu: Add attach/detach_dev_pasid iommu interface Content-Language: en-US To: Jason Gunthorpe References: <20220826121141.50743-1-baolu.lu@linux.intel.com> <20220826121141.50743-6-baolu.lu@linux.intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On 2022/8/26 22:37, Jason Gunthorpe wrote: > On Fri, Aug 26, 2022 at 08:11:29PM +0800, Lu Baolu wrote: > >> + * iommu_get_domain_for_dev_pasid() - Retrieve domain for @pasid of @dev >> + * @dev: the queried device >> + * @pasid: the pasid of the device >> + * @type: matched domain type, 0 for any match >> + * >> + * This is a variant of iommu_get_domain_for_dev(). It returns the existing >> + * domain attached to pasid of a device. It's only for internal use of the >> + * IOMMU subsystem. > > If it is only for external use then why is it exported? > > I would add something like: > > Callers must hold a lock around this function, and both > iommu_attach/detach_dev_pasid() whenever a domain of type is being > manipulated. This API does not internally resolve races with > attach/detach. Yes. Updated. This is what this API expected. > >> + * detaching from the device PASID. >> + * >> + * Return: attached domain on success, NULL otherwise. >> + */ >> +struct iommu_domain *iommu_get_domain_for_dev_pasid(struct device *dev, >> + ioasid_t pasid, >> + unsigned int type) >> +{ >> + struct iommu_domain *domain; >> + struct iommu_group *group; >> + >> + group = iommu_group_get(dev); >> + if (!group) >> + return NULL; >> + /* >> + * The xarray protects its internal state with RCU. Hence the domain >> + * obtained is either NULL or fully formed. >> + */ > > This has nothing to do with RCU > > xa_lock() is used to ensure that the domain pointer remains valid > while we check the type since it blocks concurrent xa_erase(). With xa_lock() added, this comment is not needed anymore. Best regards, baolu