From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 637CCC4363A for ; Tue, 27 Oct 2020 17:02:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B9DC206DB for ; Tue, 27 Oct 2020 17:02:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603818161; bh=580iR/LT0UQ8d0Sl0XgJEyh4AV79dWMBlN48KRQ84PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=uKSc0usMVLq1H8HXKcU/YHMzoo/AnkoN0NdB2DumqzO/KhVun4dmAhL5UkUamRnTc aAFDDnSY+OHW6q0tO3QSHaCkXXu5m7jITJqK2Ui7NBizn1Ru9dUYlv7k5H1nm1Nfod evDEP2Bls3iWMo2U9olgSiCMvc7KCovHwOXhHLxE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1815498AbgJ0RCk (ORCPT ); Tue, 27 Oct 2020 13:02:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:42964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1793714AbgJ0PH6 (ORCPT ); Tue, 27 Oct 2020 11:07:58 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8EEB92072E; Tue, 27 Oct 2020 15:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811278; bh=580iR/LT0UQ8d0Sl0XgJEyh4AV79dWMBlN48KRQ84PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=erQLdUfuUJKuXiYmWDl6sEPtbRPIIOcGPGducDAfKZrio9BMwfsUutRrhZUmcM7bu GpW8+rcjEtGFDYcXhPBDxemI9mFIlXuTdPpc/IzKRrOTfy0SEM9YwgnXD4lutfWPHK 7ul/ygOXgb2B61Wrkp7PKZwfWRNafA5q/KJt9qOI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yan Zhao , Alex Williamson , Sasha Levin Subject: [PATCH 5.8 436/633] vfio: add a singleton check for vfio_group_pin_pages Date: Tue, 27 Oct 2020 14:52:59 +0100 Message-Id: <20201027135543.174799020@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yan Zhao [ Upstream commit 7ef32e52368f62a4e041a4f0abefb4fb64e7fd4a ] Page pinning is used both to translate and pin device mappings for DMA purpose, as well as to indicate to the IOMMU backend to limit the dirty page scope to those pages that have been pinned, in the case of an IOMMU backed device. To support this, the vfio_pin_pages() interface limits itself to only singleton groups such that the IOMMU backend can consider dirty page scope only at the group level. Implement the same requirement for the vfio_group_pin_pages() interface. Fixes: 95fc87b44104 ("vfio: Selective dirty page tracking if IOMMU backed device pins pages") Signed-off-by: Yan Zhao Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/vfio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 580099afeaffa..2a70e25cfe954 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -2050,6 +2050,9 @@ int vfio_group_pin_pages(struct vfio_group *group, if (!group || !user_iova_pfn || !phys_pfn || !npage) return -EINVAL; + if (group->dev_counter > 1) + return -EINVAL; + if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) return -E2BIG; -- 2.25.1