From patchwork Tue Oct 27 13:53:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 307230 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 67A33C55179 for ; Tue, 27 Oct 2020 17:02:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C75D218AC for ; Tue, 27 Oct 2020 17:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603818140; bh=4vcFbVa/Vybn0zQxlqjW4uGB44G7cOGwTI67CNqHscM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=peyjbCte7TiZQ/7+YAIn2rzXVMmBU41XHKDPTmB4S7MHua4PwEsRri/+UXt0+vvNZ TPqyX/Wqf4GLDFOVtJIGF7/sGqjg1V0/VlQXOre7S77Yei5uJdfKEXOfp/KzaUQaJc MXu90v6xWbVsSFAUIwLq5X/LTpVBaGua8Df41n7M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1815444AbgJ0RCS (ORCPT ); Tue, 27 Oct 2020 13:02:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:43236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1793757AbgJ0PIJ (ORCPT ); Tue, 27 Oct 2020 11:08:09 -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 7E9372072E; Tue, 27 Oct 2020 15:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811289; bh=4vcFbVa/Vybn0zQxlqjW4uGB44G7cOGwTI67CNqHscM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zvb//mUWPg7tf2+ObeqrYYIR7hI/bRZuyz0sgUBEqiuI0sgsffqAeuTC2rFiUrU/l pVc1a1T566cooE8oXtixzjfo2ekjjZKRR3WIcTe19g99xK9bxN8B+VxPD2E/TzjcKp hzYV/sruO2x/Ek4L2KCc7XzFBkwllzcSS2PZ43vU= 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 440/633] vfio/type1: fix dirty bitmap calculation in vfio_dma_rw Date: Tue, 27 Oct 2020 14:53:03 +0100 Message-Id: <20201027135543.365492736@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 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Yan Zhao [ Upstream commit 2c5af98592f65517170c7bcc714566590d3f7397 ] The count of dirtied pages is not only determined by count of copied pages, but also by the start offset. e.g. if offset = PAGE_SIZE - 1, and *copied=2, the dirty pages count is 2, instead of 1 or 0. Fixes: d6a4c185660c ("vfio iommu: Implementation of ioctl for dirty pages tracking") Signed-off-by: Yan Zhao Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/vfio_iommu_type1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index f48f0db908a46..eb7bb14e4f62a 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -2899,7 +2899,8 @@ static int vfio_iommu_type1_dma_rw_chunk(struct vfio_iommu *iommu, * size */ bitmap_set(dma->bitmap, offset >> pgshift, - *copied >> pgshift); + ((offset + *copied - 1) >> pgshift) - + (offset >> pgshift) + 1); } } else *copied = copy_from_user(data, (void __user *)vaddr,