Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2776587ybk; Tue, 12 May 2020 07:55:54 -0700 (PDT) X-Google-Smtp-Source: APiQypKeurWJ17C8UqtDFjudD2r+9IND//zyr9Sp/1pjYtKcFMUNKSOpOi+oDxG1plfcF10AObIP X-Received: by 2002:a17:906:3605:: with SMTP id q5mr18375037ejb.363.1589295354458; Tue, 12 May 2020 07:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589295354; cv=none; d=google.com; s=arc-20160816; b=DvmaYMS/q32wkrTGiiSM1tNDxmCE/TLqzrLUMggCtG/JzEIB0sXO10JuoU1AgHmgaE +nphHHI1iSjT0mlk8gVVN6HGwEzqbDE+scxRxAENgwdbilClr95JNtg2+OmHhXQe//QZ wybt7065L9eM/mpDmqOGBRgyDdTaigIkby3uP1UFLuXoEj2+EdPMTOCT5nG1h+mug6qI xLG9VFH/fpN0xI4OH4wSFBACgWHirIMZYsx5iTsWVE/YPn3GjVYe6YogezYMuxrMxb0Q ToQNvucJXxErEAGNt/o1UoITWjRuZS9emN20rFe/kv9lP+bReVKQtQTZ58OrOhOwXjgz orvQ== 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=YZOs/bxxTbikpapKhWDX3v8GWxjINqQOFJaU3KA5ktI=; b=ZAP0rkCQR8hZtQJzA8FMs8VoKoGmNu37oHDrNT/6lcydEEak1WRvhMO9TjZPniFvzG A4i4y2KE0bErIVigRBoMWqVmxaDqaklQkL3aM0G0NUyALwkE4Drc8lwyEeJ2nEkWp4D/ gJ9fdJvGTG9z8Lvq0tOgZWPMFwjcLcRCkLyqx0wf4hI6FSRwFDgm4OTPCqJaHL1HkJag ddO4mlQzzfdp3EU1opmSlD68tnS1kXeqW8dUDEl2zB4UyXNCxgSfkb7LQrXJ743off6b bLjLCaYTuLfwPCpH+ZWK6JqLM24Gg1ifg1OdBw6OC5QRwaxHfgJSFxbPzlbnFJ++Wewy z0aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FDOhFiBk; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si185935eji.262.2020.05.12.07.55.31; Tue, 12 May 2020 07:55:54 -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=@redhat.com header.s=mimecast20190719 header.b=FDOhFiBk; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730247AbgELOyF (ORCPT + 99 others); Tue, 12 May 2020 10:54:05 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:29836 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727850AbgELOyE (ORCPT ); Tue, 12 May 2020 10:54:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589295242; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YZOs/bxxTbikpapKhWDX3v8GWxjINqQOFJaU3KA5ktI=; b=FDOhFiBkaGnfCd5a6YQuC+eKq29L6ejIDulwOKPjXqJH5BHFBE276iJvBktGbfNoLZJkKB 5HHkARwp+1XGK7hOQjvkDXWbLxhR135YnxIscJTQhj9VrBVdvSduUg+DUXYvHnAwd4Vw4m efjgtxK+6CmLvkDw0+5hA0fzzg8LHQo= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-113-BOsHana_NwyMgPasZ30MqA-1; Tue, 12 May 2020 10:53:44 -0400 X-MC-Unique: BOsHana_NwyMgPasZ30MqA-1 Received: by mail-wr1-f70.google.com with SMTP id q13so7067270wrn.14 for ; Tue, 12 May 2020 07:53:43 -0700 (PDT) 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=YZOs/bxxTbikpapKhWDX3v8GWxjINqQOFJaU3KA5ktI=; b=L5kbWd6MJprYSA8DLfOSMKQpwuVqFD3H/oyhxF4GGbouZOmKdbaZong74rqUZExjLS u0ASqxPScHsHni8ftpiq4sfelEXyz/9QBO17wJJodFLulg3f+q+r2KIfrfkCEhk10xl6 Y+NJJ1S5biwbQPJtrSs5254g7cKCyJ/y09l0mVW9OC4mURykI801tAuL7LLvCqfi7eOp bvBd+mRRB2T0eEFVvs8C2hElBKg83h1xWdVnreo05cHZybpq6Msi1xnkCfPEG2jJqY07 AXKL5Jjl6AwKpgA3FQ9n4N2fwBZqb7WBVaPeY31Oqx7Tx/MnM4WSMB97GmDeP0nZhQTQ eaFw== X-Gm-Message-State: AGi0PuZFdcukb3VAOz0fSCRtdB9Shjcs78LZD3hvOyy9zMbg5pXSOLuh Xr6taGDtWRC3jyjjNcGsx/aQrxe4pCVBrsyKFGPOu9fWxTuOnihFG/yvlymDahQDtsjiZeUzxL3 12/jSohZ61vd3YCl2f5KAS4TN X-Received: by 2002:adf:e4cf:: with SMTP id v15mr24982840wrm.43.1589295223008; Tue, 12 May 2020 07:53:43 -0700 (PDT) X-Received: by 2002:adf:e4cf:: with SMTP id v15mr24982818wrm.43.1589295222757; Tue, 12 May 2020 07:53:42 -0700 (PDT) Received: from redhat.com (bzq-79-179-68-225.red.bezeqint.net. [79.179.68.225]) by smtp.gmail.com with ESMTPSA id v131sm4782950wmb.27.2020.05.12.07.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 07:53:42 -0700 (PDT) Date: Tue, 12 May 2020 10:53:39 -0400 From: "Michael S. Tsirkin" To: Bharat Bhushan Cc: jean-philippe@linaro.org, joro@8bytes.org, jasowang@redhat.com, virtualization@lists.linux-foundation.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, eric.auger.pro@gmail.com, eric.auger@redhat.com Subject: Re: [PATCH v5] iommu/virtio: Use page size bitmap supported by endpoint Message-ID: <20200512105149-mutt-send-email-mst@kernel.org> References: <20200505093004.1935-1-bbhushan2@marvell.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200505093004.1935-1-bbhushan2@marvell.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 05, 2020 at 03:00:04PM +0530, Bharat Bhushan wrote: > Different endpoint can support different page size, probe > endpoint if it supports specific page size otherwise use > global page sizes. > > Signed-off-by: Bharat Bhushan > --- > v4->v5: > - Rebase to Linux v5.7-rc4 > > v3->v4: > - Fix whitespace error > > v2->v3: > - Fixed error return for incompatible endpoint > - __u64 changed to __le64 in header file > > drivers/iommu/virtio-iommu.c | 48 ++++++++++++++++++++++++++++--- > include/uapi/linux/virtio_iommu.h | 7 +++++ > 2 files changed, 51 insertions(+), 4 deletions(-) > > diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c > index d5cac4f46ca5..9513d2ab819e 100644 > --- a/drivers/iommu/virtio-iommu.c > +++ b/drivers/iommu/virtio-iommu.c > @@ -78,6 +78,7 @@ struct viommu_endpoint { > struct viommu_dev *viommu; > struct viommu_domain *vdomain; > struct list_head resv_regions; > + u64 pgsize_bitmap; > }; > > struct viommu_request { > @@ -415,6 +416,19 @@ static int viommu_replay_mappings(struct viommu_domain *vdomain) > return ret; > } > > +static int viommu_set_pgsize_bitmap(struct viommu_endpoint *vdev, > + struct virtio_iommu_probe_pgsize_mask *mask, > + size_t len) > +{ > + u64 pgsize_bitmap = le64_to_cpu(mask->pgsize_bitmap); > + > + if (len < sizeof(*mask)) > + return -EINVAL; > + > + vdev->pgsize_bitmap = pgsize_bitmap; > + return 0; > +} > + > static int viommu_add_resv_mem(struct viommu_endpoint *vdev, > struct virtio_iommu_probe_resv_mem *mem, > size_t len) > @@ -499,6 +513,9 @@ static int viommu_probe_endpoint(struct viommu_dev *viommu, struct device *dev) > case VIRTIO_IOMMU_PROBE_T_RESV_MEM: > ret = viommu_add_resv_mem(vdev, (void *)prop, len); > break; > + case VIRTIO_IOMMU_PROBE_T_PAGE_SIZE_MASK: > + ret = viommu_set_pgsize_bitmap(vdev, (void *)prop, len); > + break; > default: > dev_err(dev, "unknown viommu prop 0x%x\n", type); > } So given this is necessary early in boot, how about we add this in the config space? And maybe ACPI too ... > @@ -630,7 +647,7 @@ static int viommu_domain_finalise(struct viommu_endpoint *vdev, > > vdomain->id = (unsigned int)ret; > > - domain->pgsize_bitmap = viommu->pgsize_bitmap; > + domain->pgsize_bitmap = vdev->pgsize_bitmap; > domain->geometry = viommu->geometry; > > vdomain->map_flags = viommu->map_flags; > @@ -654,6 +671,29 @@ static void viommu_domain_free(struct iommu_domain *domain) > kfree(vdomain); > } > > +/* > + * Check whether the endpoint's capabilities are compatible with other > + * endpoints in the domain. Report any inconsistency. > + */ > +static bool viommu_endpoint_is_compatible(struct viommu_endpoint *vdev, > + struct viommu_domain *vdomain) > +{ > + struct device *dev = vdev->dev; > + > + if (vdomain->viommu != vdev->viommu) { > + dev_err(dev, "cannot attach to foreign vIOMMU\n"); > + return false; > + } > + > + if (vdomain->domain.pgsize_bitmap != vdev->pgsize_bitmap) { > + dev_err(dev, "incompatible domain bitmap 0x%lx != 0x%llx\n", > + vdomain->domain.pgsize_bitmap, vdev->pgsize_bitmap); > + return false; > + } > + > + return true; > +} > + > static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev) > { > int i; > @@ -670,9 +710,8 @@ static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev) > * owns it. > */ > ret = viommu_domain_finalise(vdev, domain); > - } else if (vdomain->viommu != vdev->viommu) { > - dev_err(dev, "cannot attach to foreign vIOMMU\n"); > - ret = -EXDEV; > + } else if (!viommu_endpoint_is_compatible(vdev, vdomain)) { > + ret = -EINVAL; > } > mutex_unlock(&vdomain->mutex); > > @@ -886,6 +925,7 @@ static int viommu_add_device(struct device *dev) > > vdev->dev = dev; > vdev->viommu = viommu; > + vdev->pgsize_bitmap = viommu->pgsize_bitmap; > INIT_LIST_HEAD(&vdev->resv_regions); > dev_iommu_priv_set(dev, vdev); > > diff --git a/include/uapi/linux/virtio_iommu.h b/include/uapi/linux/virtio_iommu.h > index 48e3c29223b5..2cced7accc99 100644 > --- a/include/uapi/linux/virtio_iommu.h > +++ b/include/uapi/linux/virtio_iommu.h > @@ -111,6 +111,7 @@ struct virtio_iommu_req_unmap { > > #define VIRTIO_IOMMU_PROBE_T_NONE 0 > #define VIRTIO_IOMMU_PROBE_T_RESV_MEM 1 > +#define VIRTIO_IOMMU_PROBE_T_PAGE_SIZE_MASK 2 > > #define VIRTIO_IOMMU_PROBE_T_MASK 0xfff > > @@ -119,6 +120,12 @@ struct virtio_iommu_probe_property { > __le16 length; > }; > > +struct virtio_iommu_probe_pgsize_mask { > + struct virtio_iommu_probe_property head; > + __u8 reserved[4]; > + __le64 pgsize_bitmap; > +}; > + > #define VIRTIO_IOMMU_RESV_MEM_T_RESERVED 0 > #define VIRTIO_IOMMU_RESV_MEM_T_MSI 1 > > -- > 2.17.1