Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5298175pxu; Wed, 21 Oct 2020 20:45:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyex6/3uGe+lQQoOPLzzykOTgSPukKKOIJPHh5BxycbFLpsXdFrUjEiDZQcLKoSyHzqWRIT X-Received: by 2002:a50:eb8e:: with SMTP id y14mr479073edr.285.1603338323814; Wed, 21 Oct 2020 20:45:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603338323; cv=none; d=google.com; s=arc-20160816; b=jWE5OvhnFih2cDoDI0dj8zLr9Ju3wG0NkKqnaEoXuH00/TfrfazNP83MslhaliMXXe ebLvoPLuRFZlK6zai3vNZPDru8AQ0UloxIFeVEGULK0M2azfDAEvj9aej/Lo1TuJgUXY 7BggP++Hi5hdesTEo8DNgzGWJXrrszvYcZeGnvbcUCS3JdrB0mWqq4m9fnzlmKWqEgIu RGC1c6LnV85v+MFUHVP6ocfRfgX7axtsnmb0zVB2MWrsdzCnHm5qlKfjI2NUm8FeGRvk vw+8pm29lBqsfLHZP79iSvjTmjafqV2nFl8xmBGaTl9V9+9aHcyDq0gQ4vW58AQLBYUJ QNAg== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8fS1Un7tm4hoyXJsqhftc1rCjizgyzgSNGUCjm2e3M8=; b=aEjkeaIe8Z+4NfUjSixxf8RDGjQLCMNOSEfZQTx33nedFPl7UNAsC7w7hS22imr2o1 JtpkSjiiogweDqG+dfMDI53CiTke0nihwUOJlmWcqOYgK34YNECJ4U1Nv51FgXxrdmsc QqCoKNCOo5bp1UXuoEua5fxVlvJg3RJyWb9TUsd16CfAWKcdn45ahggAP+n5wTpkIhi2 a7m+ii/AiKEXzEbBDR4ijS38hUJFmRRuSYdHemj+Od4S1imTbcc3j2ZWa8uDd/axap7h eCvAd9ohFp12FnSACbQ2vL93jFSDEBB8xVRrnT06q4robXt4cdvU6IKIZzcGKt+Viym2 rNWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HAnWHjuq; 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 dp13si148110ejc.122.2020.10.21.20.45.02; Wed, 21 Oct 2020 20:45:23 -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=HAnWHjuq; 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 S2443817AbgJUO54 (ORCPT + 99 others); Wed, 21 Oct 2020 10:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2443811AbgJUO5z (ORCPT ); Wed, 21 Oct 2020 10:57:55 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67832C0613CF for ; Wed, 21 Oct 2020 07:57:55 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id dg9so2852527edb.12 for ; Wed, 21 Oct 2020 07:57:55 -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=8fS1Un7tm4hoyXJsqhftc1rCjizgyzgSNGUCjm2e3M8=; b=HAnWHjuqdAkDysqsuCVv7ZNFRz7Ch50Tyt8VWUH2yRgrGlTtpJXjd7/SOCjBdy54bp zCQT702zaGQKAAysikG0BrM62ZC2oIDeC8vEb1MpcUnSDt3TUf5wMhZR2W2BTPFIpfl0 WJlD/dTSlRPUB4wKY4BQ5DGENmf8ydHKzAg3QJ96R5ex4dSW/OM6xVihfR2VoabVmOLP fM59T04L84Zg54APbj4xzZs7HK1uAufQWPFwAlR7tbs45adHVXqDtJJub2jg74rf7WRI KXPB8tECXuaEsx7b10fQhYnjzm3G4eEYxxSdZgbUalugBEQpvJUdsakkdHlZsA/6nwjD 1QRA== 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=8fS1Un7tm4hoyXJsqhftc1rCjizgyzgSNGUCjm2e3M8=; b=Rp09E3+77pRQW/NWxN3o0vjz6Hq5TfDU2ZTLxvkCpeWIBMqcsgv+A5cMnsaiQUPCqc WgE4B4ONe9WCORlStWJDNeiApd9vwf9obeIx3XAoFIkmvCPdQ4ceSC0J2HNiuX6xBfVs qnYJ6tOuH7WK8tPzuVCF9PweDZR9bp3KHZDLcHEHOU7KIt4XqAvRhTfXNYhvfqFblyZ1 9mWrftVOuvTagZcQ9mOErcidtESwBubvwMwFuPq/5gLJePIK/jArKJYxOUe4U0YBYvB1 1i9dIBCQ3GMMKJw5Xi2W3nsSitEjgTimV3b44uwdcmThuzneYUgjezgrwdZJ/JVrAMhC H90g== X-Gm-Message-State: AOAM533+1KhfkWJ+Adgd8NB4Pw+u1oG/gaArAtKoN2b1Xpp/DCUyBAY0 ul1qrpevrFLeh4g6DkLJsZZG8A== X-Received: by 2002:a05:6402:151a:: with SMTP id f26mr3587638edw.386.1603292274101; Wed, 21 Oct 2020 07:57:54 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id r9sm1973753edt.3.2020.10.21.07.57.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 07:57:53 -0700 (PDT) Date: Wed, 21 Oct 2020 16:57:34 +0200 From: Jean-Philippe Brucker To: Jacob Pan Cc: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , Alex Williamson , Lu Baolu , David Woodhouse , Jonathan Corbet , linux-api@vger.kernel.org, Jean-Philippe Brucker , Eric Auger , Jacob Pan , Yi Liu , "Tian, Kevin" , Raj Ashok , Wu Hao , Yi Sun , Dave Jiang , Randy Dunlap Subject: Re: [PATCH v3 07/14] iommu/ioasid: Add an iterator API for ioasid_set Message-ID: <20201021145734.GE1653231@myrica> References: <1601329121-36979-1-git-send-email-jacob.jun.pan@linux.intel.com> <1601329121-36979-8-git-send-email-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1601329121-36979-8-git-send-email-jacob.jun.pan@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 28, 2020 at 02:38:34PM -0700, Jacob Pan wrote: > Users of an ioasid_set may not keep track of all the IOASIDs allocated > under the set. When collective actions are needed for each IOASIDs, it > is useful to iterate over all the IOASIDs within the set. For example, > when the ioasid_set is freed, the user might perform the same cleanup > operation on each IOASID. > > This patch adds an API to iterate all the IOASIDs within the set. > > Signed-off-by: Jacob Pan Could add a short description of the function parameters, but Reviewed-by: Jean-Philippe Brucker > --- > drivers/iommu/ioasid.c | 17 +++++++++++++++++ > include/linux/ioasid.h | 9 +++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/drivers/iommu/ioasid.c b/drivers/iommu/ioasid.c > index cf8c7d34e2de..9628e78b2ab4 100644 > --- a/drivers/iommu/ioasid.c > +++ b/drivers/iommu/ioasid.c > @@ -701,6 +701,23 @@ int ioasid_adjust_set(struct ioasid_set *set, int quota) > EXPORT_SYMBOL_GPL(ioasid_adjust_set); > > /** > + * ioasid_set_for_each_ioasid - Iterate over all the IOASIDs within the set > + * > + * Caller must hold a reference of the set and handles its own locking. > + */ > +void ioasid_set_for_each_ioasid(struct ioasid_set *set, > + void (*fn)(ioasid_t id, void *data), > + void *data) > +{ > + struct ioasid_data *entry; > + unsigned long index; > + > + xa_for_each(&set->xa, index, entry) > + fn(index, data); > +} > +EXPORT_SYMBOL_GPL(ioasid_set_for_each_ioasid); > + > +/** > * ioasid_find - Find IOASID data > * @set: the IOASID set > * @ioasid: the IOASID to find > diff --git a/include/linux/ioasid.h b/include/linux/ioasid.h > index 0a5e82148eb9..aab58bc26714 100644 > --- a/include/linux/ioasid.h > +++ b/include/linux/ioasid.h > @@ -75,6 +75,9 @@ int ioasid_register_allocator(struct ioasid_allocator_ops *allocator); > void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator); > int ioasid_attach_data(ioasid_t ioasid, void *data); > void ioasid_detach_data(ioasid_t ioasid); > +void ioasid_set_for_each_ioasid(struct ioasid_set *sdata, > + void (*fn)(ioasid_t id, void *data), > + void *data); > #else /* !CONFIG_IOASID */ > static inline void ioasid_install_capacity(ioasid_t total) > { > @@ -131,5 +134,11 @@ static inline int ioasid_attach_data(ioasid_t ioasid, void *data) > static inline void ioasid_detach_data(ioasid_t ioasid) > { > } > + > +static inline void ioasid_set_for_each_ioasid(struct ioasid_set *sdata, > + void (*fn)(ioasid_t id, void *data), > + void *data) > +{ > +} > #endif /* CONFIG_IOASID */ > #endif /* __LINUX_IOASID_H */ > -- > 2.7.4 >