From patchwork Sun Sep 6 06:51:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 11759453 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E41AE112E for ; Sun, 6 Sep 2020 06:53:47 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B10D12080A for ; Sun, 6 Sep 2020 06:53:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bBMF2qL2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B10D12080A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kEoXZ-0007yD-3n; Sun, 06 Sep 2020 06:52:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kEoXX-0007y8-C6 for xen-devel@lists.xenproject.org; Sun, 06 Sep 2020 06:52:39 +0000 X-Inumbo-ID: c65c9d88-36ae-46b0-8ef0-133eb3865884 Received: from mail-pf1-x444.google.com (unknown [2607:f8b0:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c65c9d88-36ae-46b0-8ef0-133eb3865884; Sun, 06 Sep 2020 06:52:38 +0000 (UTC) Received: by mail-pf1-x444.google.com with SMTP id o20so6897685pfp.11 for ; Sat, 05 Sep 2020 23:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=I8rUO5c4QrQRi9NNPvOCt3d+iZWUjwi1tunN9Rub0tk=; b=bBMF2qL2q68MmK+glJEpZUPZMT5jo4AkJIZPACEdTgHHQYds5lYa0HzW4ZqHxulhek kg1UBfq/mFaLo4mOn+pW+Vr2Ub09QHqW8e0PkGGW7AXh2TpyTa73nKEBjxSt3a74KlNC 1C7BDNXH0LpF0QsHSLlfC3icvJnycMKJdKAerK94DBpDlsG0OV/dMQgJRn/DoCBQYdkp KrL3X4uQ8sCo0qSULOuCxy86q9BFzrAgFX3dvOLE74SF2yab+XAfBFLVnQ6SRnF8YZBm 5tUaZAPBx/Mz/D38G/C1aYXVHplqBczDkQnixhFqxwN2Ff/FOOGJSbaD7CVvyjbKRph2 x8+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=I8rUO5c4QrQRi9NNPvOCt3d+iZWUjwi1tunN9Rub0tk=; b=qUFnGgBfQGYVbQC1Y7s6NmOEIXKCVAff4zwwcKE3niw8dY6HoAV7qoEeAnOvPKAjaa UQZQtDWEdCESPvyHyLe+KlbKO/RlY792ENcC0DymBJRX5pyidKS0Quur7i0p2SnKy8C/ 0NbyW+yXglUw6Tfgd0Bp00yrupjBo58Wr32GlcqnGDyC5wY+/LZohe+0SjkvxMuxAJKx QLImj44aVzPaCM4EW1eCIQHp3peeAPA4ecIMrjuR94HpsQRk9ls+PLPdMKJEYKVKAt3L WfuROZtWgqOH2s7/Rlk3DMTCBjXq/HPY5SRF8w7s24kJ7urhVJnqUVsj8/+rOEsH5HDB 67ng== X-Gm-Message-State: AOAM5301ql70bw20/Xxmjox+yA8cBGQ1cSdx1h+NvwVF4ULcljZ5CiIS z6pa9K3ISXyvRr/XwtSM7cA= X-Google-Smtp-Source: ABdhPJwEUgCBR4QoLI3A2rl1Ro4L22TGg8358epQwwM3mEnmQWCqsaTjXqpy9QwbeAFz1ke6Dlv9ug== X-Received: by 2002:aa7:83cf:: with SMTP id j15mr15147634pfn.251.1599375157754; Sat, 05 Sep 2020 23:52:37 -0700 (PDT) Received: from jordon-HP-15-Notebook-PC.domain.name ([122.171.54.54]) by smtp.gmail.com with ESMTPSA id n128sm9199947pga.5.2020.09.05.23.52.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Sep 2020 23:52:36 -0700 (PDT) From: Souptick Joarder To: boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, david.vrabel@citrix.com Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Souptick Joarder , John Hubbard Subject: [PATCH 1/2] xen/gntdev.c: Mark pages as dirty Date: Sun, 6 Sep 2020 12:21:53 +0530 Message-Id: <1599375114-32360-1-git-send-email-jrdr.linux@gmail.com> X-Mailer: git-send-email 1.9.1 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 Reviewed-by: Boris Ostrovsky --- drivers/xen/gntdev.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 64a9025a..5e1411b 100644 --- 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 gntdev_copy_batch *batch) { 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 gntdev_copy_batch *batch, 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 gntdev_copy_batch *batch, 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; From patchwork Sun Sep 6 06:51:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 11759455 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4AECA618 for ; Sun, 6 Sep 2020 06:53:51 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 186A22080A for ; Sun, 6 Sep 2020 06:53:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MszkEUa5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 186A22080A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kEoXi-0007z5-Ce; Sun, 06 Sep 2020 06:52:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kEoXh-0007yx-Oz for xen-devel@lists.xenproject.org; Sun, 06 Sep 2020 06:52:49 +0000 X-Inumbo-ID: b40d6706-da4f-4a1f-828e-e6b319c4c834 Received: from mail-pf1-x443.google.com (unknown [2607:f8b0:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b40d6706-da4f-4a1f-828e-e6b319c4c834; Sun, 06 Sep 2020 06:52:49 +0000 (UTC) Received: by mail-pf1-x443.google.com with SMTP id 17so6897964pfw.9 for ; Sat, 05 Sep 2020 23:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Db0fgXXbzH2p2U25JJ6scSTK1v1Ti17DDq8xS5lR3/w=; b=MszkEUa5ryYy30yaiYP8RoyZtu6DMbERcUxtpSd18pBj6WexOGEKKL7JkkCjeVUYa4 CLPoxhkxomeYAPBFdTEqbgyEnE9h08KH9vh/2zYii0811dV9ABqMr9Y+OOGDR4GbOKWQ DTwpEZ4rNvQ47beCtgBw67QI3/z/j2BUult3VlMTBvtL7D8gc932t9nL1RVNBW0Q2Xql EOvSDVqH3rJH+AbCcVBG9XpMu4jVYzF9TmggKmsf6S17fC4F3G27oREvQ7LQPIXCtV4U 8VXHh/QZPE+IAXJLXGU2l8GBimNhAKcGwVpsPC1+d9MH2dSd3obODmPQiNoIKRnUkMfy Fgzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Db0fgXXbzH2p2U25JJ6scSTK1v1Ti17DDq8xS5lR3/w=; b=luH2F88ghxKHw0D0AseQsVMm5JSHQZK+K8nVh6wSStECHli75YrSvaJAgCG3AWJ5v7 tTZ83LZhC37DXMcNc/CO2sqKAxgrLhkjGBDf9e6m9HcB642uMEJQ2aAaakMWQVQ2AkRO M5aL3rmTWG76lA+jyDj4v4VwrySVjaVGZunAa3dvuIpaOY542XY0l4/+Ko6Uz7ozwjiT sN2prLurT/p0wgxUJ75GTCxvncQ6PrhXeUYI3wQ+h/uU2yZWUyfbllTa4C/vIeeGr7lQ O2avvonH0BGdZevM2cAF9SBn9o38elCgBcwcA0Tf8mRgNXITrz+euufXlE/d5nUZQQP1 reaQ== X-Gm-Message-State: AOAM531eREUME2cK6Ekj2PbbArPNNgPKyhZ/HZc6KTXRQpS8T3JcW+RT j1xDsxaNSlNsuNIQzrvFOkLT2SRsraolSA== X-Google-Smtp-Source: ABdhPJxQeP2UYdkYbiXq2FOVaFF2XXnDUgZOTqlJ7qMyx28A9j6QYQ0Cphyslfl3lZuG6wql4/ZCpQ== X-Received: by 2002:aa7:941a:: with SMTP id x26mr11701444pfo.177.1599375168362; Sat, 05 Sep 2020 23:52:48 -0700 (PDT) Received: from jordon-HP-15-Notebook-PC.domain.name ([122.171.54.54]) by smtp.gmail.com with ESMTPSA id n128sm9199947pga.5.2020.09.05.23.52.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Sep 2020 23:52:47 -0700 (PDT) From: Souptick Joarder To: boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, david.vrabel@citrix.com Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Souptick Joarder , John Hubbard Subject: [PATCH 2/2] xen/gntdev.c: Convert get_user_pages*() to pin_user_pages*() Date: Sun, 6 Sep 2020 12:21:54 +0530 Message-Id: <1599375114-32360-2-git-send-email-jrdr.linux@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1599375114-32360-1-git-send-email-jrdr.linux@gmail.com> References: <1599375114-32360-1-git-send-email-jrdr.linux@gmail.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In 2019, we introduced pin_user_pages*() and now we are converting get_user_pages*() to the new API as appropriate. [1] & [2] could be referred for more information. This is case 5 as per document [1]. [1] Documentation/core-api/pin_user_pages.rst [2] "Explicit pinning of user-space pages": https://lwn.net/Articles/807108/ Signed-off-by: Souptick Joarder Cc: John Hubbard Cc: Boris Ostrovsky Cc: Juergen Gross Cc: David Vrabel Reviewed-by: Boris Ostrovsky --- drivers/xen/gntdev.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 5e1411b..a36b712 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -731,7 +731,7 @@ static int gntdev_get_page(struct gntdev_copy_batch *batch, void __user *virt, unsigned long xen_pfn; int ret; - ret = get_user_pages_fast(addr, 1, batch->writeable ? FOLL_WRITE : 0, &page); + ret = pin_user_pages_fast(addr, 1, batch->writeable ? FOLL_WRITE : 0, &page); if (ret < 0) return ret; @@ -745,13 +745,7 @@ static int gntdev_get_page(struct gntdev_copy_batch *batch, void __user *virt, static void gntdev_put_pages(struct gntdev_copy_batch *batch) { - unsigned int 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]); - } + unpin_user_pages_dirty_lock(batch->pages, batch->nr_pages, batch->writeable); batch->nr_pages = 0; batch->writeable = false; }