Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2155534pxb; Fri, 29 Jan 2021 15:02:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJznOdgPIRQjNEwAaVJDX+WkUkVLa4Zvp1/T5z4WLunoY4bd7DxvNIfdHC2s1OfddNfWtyTL X-Received: by 2002:aa7:d401:: with SMTP id z1mr7746063edq.213.1611961377418; Fri, 29 Jan 2021 15:02:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611961377; cv=none; d=google.com; s=arc-20160816; b=nbs0BmNcsST0ZFdtwGbF5MIjBjPx1vNtyHSe6z+tZphxrozFokpOb1vwE4v6E+vilz gjuff1TIT7wuMdPjPZVr9ItWIVi6v0HztJgw56X3XIff5IUZN6IN8AmirW3jQok7+kNZ 9Dmh+YT9Oa1KmFKbrPUjgAOrWaq65wdD9/fivT+xw0GsWKH0rgShZN/Sv03smTjqImVI +b3JyCYl3lQa+S6Dx+a9MHPvxh8PTe2jIvs5Zv7sNRAQpAFg8db7juVGHw37kM0rrUyI 9sJW/lNsPJxEKhCiE8+PSvb6O8P6nEPy8ymaOkKwwAdoHGJjXqtM2HvzcDtcupmXK2u+ cmlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=js3WqeMssgVvObPx3rZpffH/XM/Kj1h1Hr6xcv9t5aw=; b=agjfwtsSPbGu+1UQHoEG09/nJWBi7QKZlRXr0tC1aBPhNeLNF7zCKcDcwUa2Bu1dXb l5F8XQd9JD4RZDXS1yHa1QQ37TaGw01wprLYkLElR/wy6RBSesSoExrF5wlK0Cnivxs7 fTFOvnkE8VjVH4uIOdE2Hro9P0mqOH7MLkvYazGJqHsCYE2moOcBsAB4JcKiTzIN9blG J9Yw8a4AjxI1hWM9rQtQw9LYcFQECs04bSVbUI2+NnOpqZi/oWOW5p3AxbuxuAWEa5hs 8M6YF+4dQoipzK6YjVjNgtCUokeY1RRrbeppdzi4XzSZnInJ5J7Ml3VqXCNXfiU94CQd 1k2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MwbcD6WL; 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 ce20si6163263edb.138.2021.01.29.15.02.33; Fri, 29 Jan 2021 15:02:57 -0800 (PST) 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=MwbcD6WL; 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 S232709AbhA2W7v (ORCPT + 99 others); Fri, 29 Jan 2021 17:59:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39096 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbhA2W7s (ORCPT ); Fri, 29 Jan 2021 17:59:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611961101; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=js3WqeMssgVvObPx3rZpffH/XM/Kj1h1Hr6xcv9t5aw=; b=MwbcD6WLqyna8Eae/AcaAkjTGjHOyBH0RPcfNxu6b01KJmIQoDLFfSlLbB/ykNjayp+Rqy VfpHef+nPfIJ8Tf5mdxQwzrWz0N+e5Gg7qoQSvJlHdq8XrN0CLdaIimh0uHxrO/axURwlB Ojha5A+Ucd4/3Rjitly2gtaGvUbAwIE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-n93dbMiPMMm9gTxMUYLRrQ-1; Fri, 29 Jan 2021 17:58:17 -0500 X-MC-Unique: n93dbMiPMMm9gTxMUYLRrQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5FE4C1005504; Fri, 29 Jan 2021 22:58:16 +0000 (UTC) Received: from omen.home.shazbot.org (ovpn-112-255.phx2.redhat.com [10.3.112.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92FEE5D71B; Fri, 29 Jan 2021 22:58:12 +0000 (UTC) Date: Fri, 29 Jan 2021 15:58:12 -0700 From: Alex Williamson To: Shenming Lu Cc: Cornelia Huck , , , Jean-Philippe Brucker , Eric Auger , Lu Baolu , Kevin Tian , , Subject: Re: [RFC PATCH v1 1/4] vfio/type1: Add a bitmap to track IOPF mapped pages Message-ID: <20210129155812.384cc56e@omen.home.shazbot.org> In-Reply-To: <20210125090402.1429-2-lushenming@huawei.com> References: <20210125090402.1429-1-lushenming@huawei.com> <20210125090402.1429-2-lushenming@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 25 Jan 2021 17:03:59 +0800 Shenming Lu wrote: > When IOPF enabled, the pages are pinned and mapped on demand, we add > a bitmap to track them. > > Signed-off-by: Shenming Lu > --- > drivers/vfio/vfio_iommu_type1.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > index 0b4dedaa9128..f1d4de5ab094 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -95,6 +95,7 @@ struct vfio_dma { > struct task_struct *task; > struct rb_root pfn_list; /* Ex-user pinned pfn list */ > unsigned long *bitmap; > + unsigned long *iommu_mapped_bitmap; /* IOPF mapped bitmap */ > }; > > struct vfio_group { > @@ -143,6 +144,8 @@ struct vfio_regions { > #define DIRTY_BITMAP_PAGES_MAX ((u64)INT_MAX) > #define DIRTY_BITMAP_SIZE_MAX DIRTY_BITMAP_BYTES(DIRTY_BITMAP_PAGES_MAX) > > +#define IOMMU_MAPPED_BITMAP_BYTES(n) DIRTY_BITMAP_BYTES(n) > + > static int put_pfn(unsigned long pfn, int prot); > > static struct vfio_group *vfio_iommu_find_iommu_group(struct vfio_iommu *iommu, > @@ -949,6 +952,7 @@ static void vfio_remove_dma(struct vfio_iommu *iommu, struct vfio_dma *dma) > vfio_unlink_dma(iommu, dma); > put_task_struct(dma->task); > vfio_dma_bitmap_free(dma); > + kfree(dma->iommu_mapped_bitmap); > kfree(dma); > iommu->dma_avail++; > } > @@ -1354,6 +1358,14 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu, > goto out_unlock; > } > > + dma->iommu_mapped_bitmap = kvzalloc(IOMMU_MAPPED_BITMAP_BYTES(size / PAGE_SIZE), > + GFP_KERNEL); This is a lot of bloat for all the platforms that don't support this feature. Thanks, Alex > + if (!dma->iommu_mapped_bitmap) { > + ret = -ENOMEM; > + kfree(dma); > + goto out_unlock; > + } > + > iommu->dma_avail--; > dma->iova = iova; > dma->vaddr = vaddr;