Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3216003ybk; Mon, 18 May 2020 21:59:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcGiwAGygZOnDAH8UIJMDohvMOxYd9kbMH0W3UBzTncqVt8UFIEHgPswKXNiB/06yGwKQN X-Received: by 2002:a50:9312:: with SMTP id m18mr15924607eda.252.1589864372974; Mon, 18 May 2020 21:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589864372; cv=none; d=google.com; s=arc-20160816; b=NnssB8m6p9a6mz0im4Xjq79dRp+RnRqfL67ThX93iYZDKNZoYE4pkX7Y0ufUun5O+k Nm4rUpE3ZmPdZqxTOK/kLVewOq/CwVt1AUeSJQRAYp/OnHrjCU4/aNMYQA3mxC6SGRQR uq8w0x2sLgrwhFEYzDTP8y72hHTtNeti82ZSkL3UieOeKi65KJpCoAWTFCOA0K0ynQgF i3YjJdldAJKdaoTCyBMkqfyi+pz0S0ViOk6Qy+IF3La97WTyK/JhvYhID49NU1JgCZvK XddZ7kDZg9cUKLs0XsOeYfSoTFiWWvL4M1MV56u2E0JllVZ3hUfO/XogjFgM7YRwtBh7 ANTQ== 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=y7ZGqZbOGTyig85XFWwJiWU7MUjiGK9+NipTHeZgGFw=; b=w9lU6yXWRcNCTkwZ5MrYpdpRRXx3x7GVU5ANPra6nN2Q6lSnWXEOrFfQeQkcoptfRC U32pWwIeODcxYklYZwB/uNw5ARdaZGNX8a+7Op0NgXHNadjmwDv0Fz0r4BJN+h4cx6tx y+pWCsFUA4Mch0Kq6rBzCv38cyPG0A2RvY8tPiWt8Q8srv3iHGpEw0yVUGNMnVnn0nra yMSCjDXLHNt/AuioArpVLA0XiyHkkN011wfTSu7ePVNGi9/USNWcFzzqzJL+/15oJpMs UvpvtrSpxj0ZVF7WUj3qM+SaXKigiFAf/xp7ay+2N2yb+d2KcedGsqrvszMh33UuiDOw FIlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=Su9d2uKP; 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 g4si7735981ejb.192.2020.05.18.21.59.09; Mon, 18 May 2020 21:59:32 -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=Su9d2uKP; 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 S1726893AbgESEz2 (ORCPT + 99 others); Tue, 19 May 2020 00:55:28 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:19216 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbgESEz2 (ORCPT ); Tue, 19 May 2020 00:55:28 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 18 May 2020 21:54:09 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 18 May 2020 21:55:27 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 18 May 2020 21:55:27 -0700 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 19 May 2020 04:55:27 +0000 Received: from rnnvemgw01.nvidia.com (10.128.109.123) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 19 May 2020 04:55:27 +0000 Received: from sandstorm.nvidia.com (Not Verified[10.2.55.90]) by rnnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 18 May 2020 21:55:27 -0700 From: John Hubbard To: LKML CC: John Hubbard , =?UTF-8?q?Kai=20M=C3=A4kisara?= , "James E . J . Bottomley" , "Martin K . Petersen" , Subject: [PATCH] scsi: st: convert convert get_user_pages() --> pin_user_pages() Date: Mon, 18 May 2020 21:55:25 -0700 Message-ID: <20200519045525.2446851-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-NVConfidentiality: public Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1589864049; bh=y7ZGqZbOGTyig85XFWwJiWU7MUjiGK9+NipTHeZgGFw=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: MIME-Version:X-NVConfidentiality:Content-Type: Content-Transfer-Encoding; b=Su9d2uKPrbXNdMUViNd/L97OsaxGH5Lzxmux/E2Z7MUnViIh8lQIHtnbUnvbqi1j/ 97TS6KfQPJGFKGgdH3XzjOJmm8S2Wg4k+gVIzjb463PrMGc88/xp21URtukEyobu6e b+kt6SjwznwV5S6bDizkhw0JAz6kdKlO9MaHMRNTDTkGwUsZ89KDY4cvtHA/pYYkNx 950uAI5boUlAlxVr7MFFsIfodnuHP8tyf3jOQP0xE6TCycw2MUbjd+KDnjEqXClTIY D5cNLd404vW9JqoTda/1QcPb7kHdq78ZjVC+b7HCOOaRjmDKRoO6wQSyAbaBJLmrUV YoxhrAHMykE0Q== 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] Also, this deletes one of the two FIXME comments (about refcounting), because there is nothing wrong with the refcounting at this point. [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 Cc: "Kai M=C3=A4kisara" Cc: James E.J. Bottomley Cc: Martin K. Petersen Cc: linux-scsi@vger.kernel.org Signed-off-by: John Hubbard --- drivers/scsi/st.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index c5f9b348b438..0369c7edfd94 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -4922,7 +4922,7 @@ static int sgl_map_user_pages(struct st_buffer *STbp, unsigned long end =3D (uaddr + count + PAGE_SIZE - 1) >> PAGE_SHIFT; unsigned long start =3D uaddr >> PAGE_SHIFT; const int nr_pages =3D end - start; - int res, i, j; + int res, i; struct page **pages; struct rq_map_data *mdata =3D &STbp->map_data; =20 @@ -4944,7 +4944,7 @@ static int sgl_map_user_pages(struct st_buffer *STbp, =20 /* Try to fault in all of the necessary pages */ /* rw=3D=3DREAD means read from drive, write into memory area */ - res =3D get_user_pages_fast(uaddr, nr_pages, rw =3D=3D READ ? FOLL_WRITE = : 0, + res =3D pin_user_pages_fast(uaddr, nr_pages, rw =3D=3D READ ? FOLL_WRITE = : 0, pages); =20 /* Errors and no page mapped should return here */ @@ -4964,8 +4964,7 @@ static int sgl_map_user_pages(struct st_buffer *STbp, return nr_pages; out_unmap: if (res > 0) { - for (j=3D0; j < res; j++) - put_page(pages[j]); + unpin_user_pages(pages, res); res =3D 0; } kfree(pages); @@ -4977,18 +4976,10 @@ static int sgl_map_user_pages(struct st_buffer *STb= p, static int sgl_unmap_user_pages(struct st_buffer *STbp, const unsigned int nr_pages, int dirtied) { - int i; + /* FIXME: cache flush missing for rw=3D=3DREAD */ =20 - for (i=3D0; i < nr_pages; i++) { - struct page *page =3D STbp->mapped_pages[i]; + unpin_user_pages_dirty_lock(STbp->mapped_pages, nr_pages, dirtied); =20 - if (dirtied) - SetPageDirty(page); - /* FIXME: cache flush missing for rw=3D=3DREAD - * FIXME: call the correct reference counting function - */ - put_page(page); - } kfree(STbp->mapped_pages); STbp->mapped_pages =3D NULL; =20 --=20 2.26.2