Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2419908ybk; Sun, 17 May 2020 21:18:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXQiR+b6VAHjdBAPjqyY+oBA4y4PRzzCA/soNYzHImLABVIXIkLoF3q56ed7t0D3N7WLTX X-Received: by 2002:a17:906:da1e:: with SMTP id fi30mr12934652ejb.80.1589775500263; Sun, 17 May 2020 21:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589775500; cv=none; d=google.com; s=arc-20160816; b=Dj0o1OJxmXsQ3vu56MYuIk4/q0ABMNmgxb0tvrTYVO7MsFBvn1sFKzKzhS5oqXY+/J ThntyWffLKKPp8hlxvQWLBCyydGBcUm64uITzPLOXq1XiSl+QWXTTIzCt4irktht9ekF MJu6ZzWTKJR8l/iYNZy4fHeNDwXUNzDdpeDI6v31lFyAgkaQ9BsJFsHz3GlnM9MY0p3+ d3kxQiZmWEJYu4DEfRXfx7HK7f2NpsqEbafezysFQDUANY/5a853Y3vygg0M1PfKU1Hf /0LcczHjRVJjiQu+ziBz9j1eQPSj06LGngF3MlNzb9ABJe79Ofutl1LXQTaw8SgeJ5Yj RqoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=cuwLKOTJKSE6e49q/J5ZEuun7K4FWrcNFCi0NALDsCU=; b=r9PPlNPglcPAez/vR48ThNATk8i3Me6gMtfMhEcQyKXXT9e8MiyZxZtNjso7zT0QJe V1NehInXcdavDtjetJenykIX8sBXnuP/xj8vfxqF1sJFLQoMN6WJs6Kufc5lPq2fAjIg zhj64GcicMGwiWmGC0D4ubpHsKAeudhL8z9M/67Y3eK7uXxEfYRgbsyYYR98ZLC6BZSY u8E3rUq6HaCpZ3PSp4PUnqBsCSDicq59XWDBQ2tXnhWzz+cP4cCcIQQPqVIZXfe/6cTa 5VT6Knoz6RuuJBJ2tORH91WwA2J7UU1vvt6r4yP8M6DDlRwgoW+2fwRG11HD+QemqWUc 3h/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=lm2sye2u; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w26si5300337edq.38.2020.05.17.21.17.56; Sun, 17 May 2020 21:18:20 -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=@nvidia.com header.s=n1 header.b=lm2sye2u; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726285AbgERENJ (ORCPT + 99 others); Mon, 18 May 2020 00:13:09 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:5079 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725280AbgERENJ (ORCPT ); Mon, 18 May 2020 00:13:09 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sun, 17 May 2020 21:10:47 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Sun, 17 May 2020 21:13:08 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Sun, 17 May 2020 21:13:08 -0700 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 18 May 2020 04:13:08 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 18 May 2020 04:13:08 +0000 Received: from sandstorm.nvidia.com (Not Verified[10.2.48.175]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Sun, 17 May 2020 21:13:08 -0700 From: John Hubbard To: LKML CC: Sudeep Dutt , Ashutosh Dixit , Arnd Bergmann , Greg Kroah-Hartman , Richard Fontana , Thomas Gleixner , Kate Stewart , Allison Randal , John Hubbard Subject: [PATCH] drivers/mic/scif: convert get_user_pages() --> pin_user_pages() Date: Sun, 17 May 2020 21:13:07 -0700 Message-ID: <20200518041307.1987328-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1589775048; bh=cuwLKOTJKSE6e49q/J5ZEuun7K4FWrcNFCi0NALDsCU=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: MIME-Version:X-NVConfidentiality:Content-Transfer-Encoding: Content-Type; b=lm2sye2uxDAzQsDuz72nrdclnyI+3mSXl54DWnuRzTk+mC20/nJG9pn0GZ45CY3Mn dvPj8WeT0ELbY0UEwItFvN4jcTRLHFhLV4dHfZfqEsp6uWUgOGFYqu0DntiBv5TCQG PUl0MbKAszDT/61TaTs2LM9sG3zpq+N+Dr73UK5uK8y6eOjsZc6pSt/TkFuI0f2Mhi 9Fi0DcmWd8Wwz9D54HyhQ3MIi6axa5MfHzSUiOFFcRF8nf5qweS+mtyjc0YyFP9Lpi 1982EhchbiVi7IjdMF9G7EfYjUc922cdxk162kvHRe4rb2GCna6azhPexEMrx5kE74 ovuORk6R7yPgg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This code was using get_user_pages*(), in a "Case 2" scenario (DMA/RDMA), using the categorization from [1]. That means that it's time to convert the get_user_pages*() + put_page() calls to pin_user_pages*() + unpin_user_pages() calls. There is some helpful background in [2]: basically, this is a small part of fixing a long-standing disconnect between pinning pages, and file systems' use of those pages. Note that this effectively changes the code's behavior as well: it now ultimately calls set_page_dirty_lock(), instead of SetPageDirty(). This is probably more accurate. As Christoph Hellwig put it, "set_page_dirty() is only safe if we are dealing with a file backed page where we have reference on the inode it hangs off." [3] [1] Documentation/core-api/pin_user_pages.rst [2] "Explicit pinning of user-space pages": https://lwn.net/Articles/807108/ [3] https://lore.kernel.org/r/20190723153640.GB720@lst.de Signed-off-by: John Hubbard --- Hi, Note that I have only compile-tested this patch, although that does also include cross-compiling for a few other arches. thanks, John Hubbard NVIDIA drivers/misc/mic/scif/scif_rma.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_= rma.c index 01e27682ea30..406cd5abfa72 100644 --- a/drivers/misc/mic/scif/scif_rma.c +++ b/drivers/misc/mic/scif/scif_rma.c @@ -113,14 +113,17 @@ static int scif_destroy_pinned_pages(struct scif_pinn= ed_pages *pin) int writeable =3D pin->prot & SCIF_PROT_WRITE; int kernel =3D SCIF_MAP_KERNEL & pin->map_flags; =20 - for (j =3D 0; j < pin->nr_pages; j++) { - if (pin->pages[j] && !kernel) { - if (writeable) - SetPageDirty(pin->pages[j]); - put_page(pin->pages[j]); + if (kernel) { + for (j =3D 0; j < pin->nr_pages; j++) { + if (pin->pages[j] && !kernel) { + if (writeable) + set_page_dirty_lock(pin->pages[j]); + put_page(pin->pages[j]); + } } - } - + } else + unpin_user_pages_dirty_lock(pin->pages, pin->nr_pages, + writeable); scif_free(pin->pages, pin->nr_pages * sizeof(*pin->pages)); scif_free(pin, sizeof(*pin)); @@ -1375,7 +1378,7 @@ int __scif_pin_pages(void *addr, size_t len, int *out= _prot, } } =20 - pinned_pages->nr_pages =3D get_user_pages_fast( + pinned_pages->nr_pages =3D pin_user_pages_fast( (u64)addr, nr_pages, (prot & SCIF_PROT_WRITE) ? FOLL_WRITE : 0, @@ -1385,11 +1388,8 @@ int __scif_pin_pages(void *addr, size_t len, int *ou= t_prot, if (ulimit) __scif_dec_pinned_vm_lock(mm, nr_pages); /* Roll back any pinned pages */ - for (i =3D 0; i < pinned_pages->nr_pages; i++) { - if (pinned_pages->pages[i]) - put_page( - pinned_pages->pages[i]); - } + unpin_user_pages(pinned_pages->pages, + pinned_pages->nr_pages); prot &=3D ~SCIF_PROT_WRITE; try_upgrade =3D false; goto retry; --=20 2.26.2