Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2852546pxb; Tue, 21 Sep 2021 09:02:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVx4orxmnMPYbqNmh1CwkYv/O6Tbi9W/g9d+C8xD68SLUf7H3zMosVDX6L9Xpb75GBWKhG X-Received: by 2002:a17:906:9ad0:: with SMTP id ah16mr36538182ejc.43.1632240161127; Tue, 21 Sep 2021 09:02:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632240161; cv=none; d=google.com; s=arc-20160816; b=gZzzVm4yXNrwRtOwGMvc2+w/nPSEwKzSzAgL3s+h3At4Wxj3iKFOej6NXBFOmyE0Wf Gx+j2/ODUDdRu5dWuCftsYs3lL78+GdlSOzT7/45CXvg71+8ZiebJH3WFxiYMbmuwVMb GcUFVRr0UZ3lvv/vk4T/f/fo59JztRldNsFNLdOZsyr5+ajc2jq4bKFnrn3dGIeUZ61Y kObKUJE34vFBTkWqvOibdDclAZKxL4xTYyCXW7wkZPcx73iAXVvzyPj3N8x6FraRgr+2 XYykyBhpWfFrdFHxZsRm2XV1zrbtRCYn2iIJx3SHBbbvN6c4JwrDPDFqHtyCy9w6s9QR eVWA== 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=AtZyyTP986q5izPT5lFbv6cJ5CVeOkj7bVUgoAF+aPE=; b=v3b4WMIXRj2z1HZ6lHrqGlPAGWzF65ESxAhDuyPQKs6z6GgTlUbWvGpootbxC3ZLbg mzuI2us868nDlLKMp3sLqEGNMXKbc9dn1egERMACi44r9soPunr20sC+u8EKzHmOhR1z s8F1oT6O22bgl3W4b8NxKt3JudMtf0q/ETGw+YtP+nyWMJilCi53tM5J+6xc2IxRiN5+ gkCMif9NiyRRa4p6c0z9sg9b0xRyCOGCmzG1bz1WsswoM82K86P2niqRHLbjQ7/pYhRJ J4E5bg1U28VGNecGDJ3aQWd4J1yqKBz0Q5q7W/UDa55A/Ad64YoYgf9UMxo6yMnBPe4A NGng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qn8z1Wbk; 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 y4si19797627ejk.622.2021.09.21.09.02.07; Tue, 21 Sep 2021 09:02:40 -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=qn8z1Wbk; 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 S234385AbhIUQBS (ORCPT + 99 others); Tue, 21 Sep 2021 12:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234369AbhIUQBP (ORCPT ); Tue, 21 Sep 2021 12:01:15 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 271FBC061574 for ; Tue, 21 Sep 2021 08:59:47 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id t8so40729028wrq.4 for ; Tue, 21 Sep 2021 08:59:47 -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=AtZyyTP986q5izPT5lFbv6cJ5CVeOkj7bVUgoAF+aPE=; b=qn8z1Wbkql8CqtKixkOZJfHbzjeuBbinRO0kMwKxCb0qOIrbleyJ5e2P2YBme9hhQd npB+D2tprMu7tQ9xPboAPoUxLWvzYj0qtGUdZWjjnX/QACr4MJjk9P6kaSN/NVT4vhSo C9ODmI/mHhyqcDhULh3v0wjFyt8Uu/Elftxsz4cTyqK6mkROt3VFsJtokj4kXciRUZfX OsxZgAgRk2Z8USr6T+8L0LP7KNak3SelmLNRb6o1DuePBxyc0FGr/ZG6/wccXWQhCKg4 fu5VLgQA3b/YaW/POQ2oM8m7kG1gdwq9KHKIwzfrYAYUI2CMm+Wbw7X6yS6nTTRLRwEq 3kZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=AtZyyTP986q5izPT5lFbv6cJ5CVeOkj7bVUgoAF+aPE=; b=uGJOt+fIVvsqW3MifORQRMi4Bvqf6Fw1XQZ3376bc7iTZL4slumGV4o/XdiK3aMsee DqRDKF8zM/GlwDpEBiby3QMLj6SG8cnInsulcHlR1syJKGpdf9qmVwqjgwmxnokFiWNa 8T4ABSAZp8lBwK64lDsAQwyysNUw/cXXN1ut/dhN3R0d+8NF2NgoC8eQ4jB1DGwlV6Ct s8+ac/n26w8ftPLga1gGQ53chnRJLjBWajFW1puLJxwPrveKBflb3hg0QHMhEjizi/HE SLktAZyDQGMsxoCs7k872w+AkPfa8Wb0ARfc7UE/wg1C+OedCxSsPY+kr3xmQ+D2mMvD 2MTw== X-Gm-Message-State: AOAM533lDvzjT97Gj17m2rqkniP5uRQulx2zYuqtEt4+2UnXuzX2zAbM wfCGbg0qIFx5YuDW1ag9b0Qyog== X-Received: by 2002:a5d:4f91:: with SMTP id d17mr36130015wru.285.1632239985681; Tue, 21 Sep 2021 08:59:45 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id o1sm2799031wmq.26.2021.09.21.08.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 08:59:45 -0700 (PDT) Date: Tue, 21 Sep 2021 16:59:23 +0100 From: Jean-Philippe Brucker To: Vivek Gautam Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, virtualization@lists.linux-foundation.org, joro@8bytes.org, will.deacon@arm.com, mst@redhat.com, robin.murphy@arm.com, eric.auger@redhat.com, kevin.tian@intel.com, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, Lorenzo.Pieralisi@arm.com, shameerali.kolothum.thodi@huawei.com Subject: Re: [PATCH RFC v1 02/11] iommu/virtio: Maintain a list of endpoints served by viommu_dev Message-ID: References: <20210423095147.27922-1-vivek.gautam@arm.com> <20210423095147.27922-3-vivek.gautam@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210423095147.27922-3-vivek.gautam@arm.com> X-TUID: +1WeLErnK1xS Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 23, 2021 at 03:21:38PM +0530, Vivek Gautam wrote: > Keeping a record of list of endpoints that are served by the virtio-iommu > device would help in redirecting the requests of page faults to the > correct endpoint device to handle such requests. > > Signed-off-by: Vivek Gautam > --- > drivers/iommu/virtio-iommu.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c > index 50039070e2aa..c970f386f031 100644 > --- a/drivers/iommu/virtio-iommu.c > +++ b/drivers/iommu/virtio-iommu.c > @@ -48,6 +48,7 @@ struct viommu_dev { > spinlock_t request_lock; > struct list_head requests; > void *evts; > + struct list_head endpoints; As we're going to search by ID, an xarray or rb_tree would be more appropriate than a list > > /* Device configuration */ > struct iommu_domain_geometry geometry; > @@ -115,6 +116,12 @@ struct viommu_endpoint { > void *pgtf; > }; > > +struct viommu_ep_entry { > + u32 eid; > + struct viommu_endpoint *vdev; > + struct list_head list; > +}; No need for a separate struct, I think you can just add the list head and id into viommu_endpoint. > + > struct viommu_request { > struct list_head list; > void *writeback; > @@ -573,6 +580,7 @@ static int viommu_probe_endpoint(struct viommu_dev *viommu, struct device *dev) > size_t probe_len; > struct virtio_iommu_req_probe *probe; > struct virtio_iommu_probe_property *prop; > + struct viommu_ep_entry *ep; > struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); > struct viommu_endpoint *vdev = dev_iommu_priv_get(dev); > > @@ -640,6 +648,18 @@ static int viommu_probe_endpoint(struct viommu_dev *viommu, struct device *dev) > prop = (void *)probe->properties + cur; > type = le16_to_cpu(prop->type) & VIRTIO_IOMMU_PROBE_T_MASK; > } > + if (ret) > + goto out_free; > + > + ep = kzalloc(sizeof(*ep), GFP_KERNEL); > + if (!ep) { > + ret = -ENOMEM; > + goto out_free; > + } > + ep->eid = probe->endpoint; > + ep->vdev = vdev; > + > + list_add(&ep->list, &viommu->endpoints); This should be in viommu_probe_device() (viommu_probe_endpoint() is only called if F_PROBE is negotiated). I think we need a lock for this list/xarray Thanks, Jean > > out_free: > kfree(probe); > @@ -1649,6 +1669,7 @@ static int viommu_probe(struct virtio_device *vdev) > viommu->dev = dev; > viommu->vdev = vdev; > INIT_LIST_HEAD(&viommu->requests); > + INIT_LIST_HEAD(&viommu->endpoints); > > ret = viommu_init_vqs(viommu); > if (ret) > -- > 2.17.1 >