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=unavailable 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 7FD9EC56201 for ; Tue, 27 Oct 2020 17:02:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34DF320809 for ; Tue, 27 Oct 2020 17:02:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603818141; bh=4vcFbVa/Vybn0zQxlqjW4uGB44G7cOGwTI67CNqHscM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NY8hcQahRiIcwgY9E4Oe18SXeW3IksXBddSMJ7NyPE6ZSDKRu01JCuqL0yKSAL7HL 4P80NZLKbHk6QjiYNclc4x+CxnKNKlK0HoZJUxxbZK4j9xF3WLz3E1wkMxZ+OMgXVz NREFBSVkgIjR32eLEbITkmsUOMKHuo4Nvyo5NiS0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1815451AbgJ0RCU (ORCPT ); Tue, 27 Oct 2020 13:02:20 -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 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 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, -- 2.25.1