Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1984637pxx; Sat, 31 Oct 2020 04:51:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPicgPC2U+I6jeR87nRwPZNuqw+70TFOj7Ql2gxcGsiF6VlvkyrIni6CD0LMuhnBqBIC6k X-Received: by 2002:a50:be8f:: with SMTP id b15mr7100629edk.180.1604145090248; Sat, 31 Oct 2020 04:51:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604145090; cv=none; d=google.com; s=arc-20160816; b=ak13qx+OJZJ8dpDgabg7sZxlGGK37FYPeGRYIrMnxUF/nYmIlbSVmN7Ly0Vxzaak7b 95WCSB/D3qSy3q15wdcZ6lKQWRrH3gpzROzdZERdGBL7T1cgJ7MS+9vDKpI882/5tvu1 xj4u8d76Op+Flu5DeA9PFwHJA8cLFewpQxCsG188Hjdm8XAdQnVzboHZ3dd0XetnmwYI 3M67N/eI7/haF1y9MRUboUwBpE4/H4CwGfzdqYK8tCLulBBmf3pBV+4YsUV6poyoVqmG Wc54vvKW+1teIoLtZNiujKv+C25VX4E1Trm3/TE/Hogp4V3ShNHH70NOg+OprmV0Ww7n hfhg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3pE/rq8AApxpZbDg9/Ix2jsogS3HRvU/rw9FGffuix8=; b=L1WKxbgE09mAb88Ti+7IcJrJ+Yf+nGs0D++BLjsnb3430TbI2nCv75eIOBKApcBhMt eJ9fqniTXWRYD+NUetf00eX7F3Z+LC8bedSX/4OLDs6zXx6EdeG5MFQjUWSH+T242ZDa IuYHbm8eKnwBRrf5Ec66JfPaxe65TDDaK/8eS1htCUZ4Oosu5dTbhldyJIMWzVAKq9OO 8neQTBxlYtvreUTgKv71g1O7lWLO3qC0kZuKQd28iloiGSHGK99cuprE5RwjBgtPxNiw E8oqqTw+BpCBgEWgJg1nZyAr4XZd03E8ch3aZgPRtV1zixvtaYtTN+BGURvNFjEoF871 EGhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HI0SCPJ6; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si497134ejf.392.2020.10.31.04.51.07; Sat, 31 Oct 2020 04:51:30 -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=@kernel.org header.s=default header.b=HI0SCPJ6; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728158AbgJaLtU (ORCPT + 99 others); Sat, 31 Oct 2020 07:49:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:42456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726928AbgJaLmp (ORCPT ); Sat, 31 Oct 2020 07:42:45 -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 69925205F4; Sat, 31 Oct 2020 11:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604144564; bh=EJ9LeitW/sDScSg81JqdnN0qFEWoI+F3KiLnatf3fug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HI0SCPJ6LIB0bRtfCVFUt9hRKE4PWaNvJEuQfTuGbuQ6XQmW+BQnEjckkIZ6bBthb q47yaiS4tL7DxcVWII5kzl3WJnB2cBDtPfmcaJPfdURYoti5zu6+YkYc/w464hMgjX znFjJEcq6sy9ebudQZNF1gXSjs1+B/svlyneESN8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Boris Ostrovsky , Souptick Joarder , John Hubbard , Juergen Gross , David Vrabel Subject: [PATCH 5.8 67/70] xen/gntdev.c: Mark pages as dirty Date: Sat, 31 Oct 2020 12:36:39 +0100 Message-Id: <20201031113502.692937855@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201031113459.481803250@linuxfoundation.org> References: <20201031113459.481803250@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: Souptick Joarder commit 779055842da5b2e508f3ccf9a8153cb1f704f566 upstream. There seems to be a bug in the original code when gntdev_get_page() is called with writeable=true then the page needs to be marked dirty before being put. To address this, a bool writeable is added in gnt_dev_copy_batch, set it in gntdev_grant_copy_seg() (and drop `writeable` argument to gntdev_get_page()) and then, based on batch->writeable, use set_page_dirty_lock(). Fixes: a4cdb556cae0 (xen/gntdev: add ioctl for grant copy) Suggested-by: Boris Ostrovsky Signed-off-by: Souptick Joarder Cc: John Hubbard Cc: Boris Ostrovsky Cc: Juergen Gross Cc: David Vrabel Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/1599375114-32360-1-git-send-email-jrdr.linux@gmail.com Reviewed-by: Boris Ostrovsky Signed-off-by: Boris Ostrovsky Signed-off-by: Greg Kroah-Hartman --- drivers/xen/gntdev.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -720,17 +720,18 @@ struct gntdev_copy_batch { s16 __user *status[GNTDEV_COPY_BATCH]; unsigned int nr_ops; unsigned int nr_pages; + bool writeable; }; static int gntdev_get_page(struct gntdev_copy_batch *batch, void __user *virt, - bool writeable, unsigned long *gfn) + unsigned long *gfn) { unsigned long addr = (unsigned long)virt; struct page *page; unsigned long xen_pfn; int ret; - ret = get_user_pages_fast(addr, 1, writeable ? FOLL_WRITE : 0, &page); + ret = get_user_pages_fast(addr, 1, batch->writeable ? FOLL_WRITE : 0, &page); if (ret < 0) return ret; @@ -746,9 +747,13 @@ static void gntdev_put_pages(struct gntd { unsigned int i; - for (i = 0; i < batch->nr_pages; i++) + for (i = 0; i < batch->nr_pages; i++) { + if (batch->writeable && !PageDirty(batch->pages[i])) + set_page_dirty_lock(batch->pages[i]); put_page(batch->pages[i]); + } batch->nr_pages = 0; + batch->writeable = false; } static int gntdev_copy(struct gntdev_copy_batch *batch) @@ -837,8 +842,9 @@ static int gntdev_grant_copy_seg(struct virt = seg->source.virt + copied; off = (unsigned long)virt & ~XEN_PAGE_MASK; len = min(len, (size_t)XEN_PAGE_SIZE - off); + batch->writeable = false; - ret = gntdev_get_page(batch, virt, false, &gfn); + ret = gntdev_get_page(batch, virt, &gfn); if (ret < 0) return ret; @@ -856,8 +862,9 @@ static int gntdev_grant_copy_seg(struct virt = seg->dest.virt + copied; off = (unsigned long)virt & ~XEN_PAGE_MASK; len = min(len, (size_t)XEN_PAGE_SIZE - off); + batch->writeable = true; - ret = gntdev_get_page(batch, virt, true, &gfn); + ret = gntdev_get_page(batch, virt, &gfn); if (ret < 0) return ret;