Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2788981pxa; Tue, 25 Aug 2020 03:23:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE+o/wly8xj0Ui7v1aPlASED4vRXKy/GTriPr7rBwCReKuFFeIX669IZq+ZaLafmy7gDLz X-Received: by 2002:a17:906:c304:: with SMTP id s4mr10073429ejz.360.1598351029001; Tue, 25 Aug 2020 03:23:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598351028; cv=none; d=google.com; s=arc-20160816; b=xQD4sxvY9cXCLiQBSxyh+uO0bHBGqowXrJaiUC/0LUMCZSgZAp+fAeOEE/oI7/nHNc 8Wo23/++Gd4yGLBJuyjy0z2mz+IDtrOdiNyPTjB+G2JEQHXXRP0/X20sVO6P76fUNnaC xpP/lFFGWUa43ay9/HWw9lkqQxFnS46pDFKaofPnJSqlc41pjSL2usHTEta2pePxtoD3 1uUcKk5Y1Yh3HMq6gq04FTA3AQojxeWq+ZN2KWqKPKrAUHSVxpNp4OqH/AqFAgLSDz7k /l+1lnI9AL24eSXEPC5rfwDJmHb4Q8hL2J5Sjdk/n5268pw/OJarmsr3AbDc9hLaEgVz 9k3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=LjRa4FQ6fIW8k3lExhbXpv5P4bFiw7U6KH50o8/5jhw=; b=MKY7j2hmtNeBN3oxb5ICPD2laycu3e3nafZ9XjLriwWxshTxZDldhws5KA/HgEqKOr tez/VcV7g/5c5G1dcJ33XcF3nNgCFiYnr6E55OiSPLmQMCci0SxH0ttcnaPYgoUqWJ0i +HWFS1EbF68qhYwfLLDUihUFE06qmg8n2Enrjpz0RRIz1By0d8jcEB7StUgD6Okskk03 eIDb9ZrXcEhJmlaydVZv7pSQkr48nIB53d+dP/UQXf61bYiz6DTHOtCRlDnizCrDClmx i4Y5Nq6NKcM4o0lDB8eXLJ3VQ4+uifxHU1R8aDXQU7Lv0jWRP1hH9tnWp+A2QTELyDE8 0f7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qaGf7SUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si8628146ejt.242.2020.08.25.03.23.25; Tue, 25 Aug 2020 03:23:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qaGf7SUM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729819AbgHYKV2 (ORCPT + 99 others); Tue, 25 Aug 2020 06:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729834AbgHYKVH (ORCPT ); Tue, 25 Aug 2020 06:21:07 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 912C3C061755 for ; Tue, 25 Aug 2020 03:21:06 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id m20so10745176eds.2 for ; Tue, 25 Aug 2020 03:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=LjRa4FQ6fIW8k3lExhbXpv5P4bFiw7U6KH50o8/5jhw=; b=qaGf7SUMf6jQPM2DzTed4vDnvHWuC2vRK/dPvwea/rHQbUw77IgDCVbAM8229duO92 7kAOTXB+zSY1Q5XNRGFwDo22uoTtTYu2rkrcNbWWhk0DPKGZ69s9bGduEvj1ZBkfsFl3 VdugzHIbNr0FBZt+8e45XJkowlpakZNt6/+Ll4XdrQ94Ozn2E++xfsKy6Ex62Vm0dCgI zNEZFlQbjLs8y8QD+qyJEHyscypVntkw5ILvi1n8g9wFAnIHGy1XDxhz2T7+e+DaknMC A1wKh0oPuLqLzoHwRoZrZijBqlG3RzRclnd7B2GJl5G8nvcpnehxLUKu/ce2+KTbMfWh OgbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LjRa4FQ6fIW8k3lExhbXpv5P4bFiw7U6KH50o8/5jhw=; b=HsPgRmRnVI1uzQTpDF6vBNzQeBGvgUarD98csg/4BuBgT8V0hHI/n5hv5aHaIqv5D9 dFRHmZjjzxYYW5hh/WhH+DBFTp4LjqVArvaVRhqLxtTsH1QXN9FKyX5UQeJwQG8cu+hE wA0WKYIrY0Qa7LpOISlzEZOxVsBj0apS0cBc8tf2ACeQa239crQn6PdxC5hLs/B2bjYQ 6i0BuFDVwQI5Pd2wBJDRmGTShP2VnlDznISR6Zh7sM0x2gRzrR26YtrW/njeepKnBoTE Z1dNsarOUSLdV+oZwxorgwEVVT/rI74PYu+dPJut6lZf0lc/dMovKbpF4cXklQEytoAS ZVwQ== X-Gm-Message-State: AOAM533/Vmp0K+tVt9BNF6nf8CRc6qJg2OrBwNaHAYxoqJR3BAJm7spH 3wnpH8XxziiKL2NWqG7gxCjgYg== X-Received: by 2002:a05:6402:b32:: with SMTP id bo18mr9521784edb.201.1598350865212; Tue, 25 Aug 2020 03:21:05 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id t22sm9816317edr.66.2020.08.25.03.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2020 03:21:04 -0700 (PDT) Date: Tue, 25 Aug 2020 12:20:48 +0200 From: Jean-Philippe Brucker To: Lu Baolu Cc: Jacob Pan , iommu@lists.linux-foundation.org, LKML , Jean-Philippe Brucker , Joerg Roedel , David Woodhouse , Yi Liu , "Tian, Kevin" , Raj Ashok , Eric Auger , Wu Hao Subject: Re: [PATCH v2 4/9] iommu/ioasid: Add reference couting functions Message-ID: <20200825102048.GB3252704@myrica> References: <1598070918-21321-1-git-send-email-jacob.jun.pan@linux.intel.com> <1598070918-21321-5-git-send-email-jacob.jun.pan@linux.intel.com> <31af38ba-5cda-5d60-237e-f98cfc87da1b@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <31af38ba-5cda-5d60-237e-f98cfc87da1b@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 24, 2020 at 10:26:55AM +0800, Lu Baolu wrote: > Hi Jacob, > > On 8/22/20 12:35 PM, Jacob Pan wrote: > > There can be multiple users of an IOASID, each user could have hardware > > contexts associated with the IOASID. In order to align lifecycles, > > reference counting is introduced in this patch. It is expected that when > > an IOASID is being freed, each user will drop a reference only after its > > context is cleared. > > > > Signed-off-by: Jacob Pan [...] > > +/** > > * ioasid_find - Find IOASID data > > * @set: the IOASID set > > * @ioasid: the IOASID to find > > Do you need to increase the refcount of the found ioasid and ask the > caller to drop it after use? Otherwise, the ioasid might be freed > elsewhere. ioasid_find() takes a getter function as parameter, which ensures that the returned data is valid. It fetches the IOASID data under rcu_read_lock() and calls the getter on the private data (for example mmget_not_zero() for bare-metal SVA). Given that, I don't think returning with a reference to the IOASID is necessary. The IOASID may be freed once ioasid_find() returns but not the returned data. Thanks, Jean