Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp564794ybm; Wed, 27 May 2020 02:27:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzE7TUM2jc8VTqEnDVaddzdlIajfKbMKO6VU4Mhsg0kH5LzHoLtKTQXSMe1NOXKcpLQ5qh8 X-Received: by 2002:a17:906:6841:: with SMTP id a1mr5224280ejs.271.1590571658285; Wed, 27 May 2020 02:27:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590571658; cv=none; d=google.com; s=arc-20160816; b=SYvS78dd3l81UI+ha7hTw1weymMQKWK13Xy10AdZX3/Ap/eiKIE5KPibGTfOF1sCs9 5JXcR0PMD8DesyIuvaHTiycJzGndc1XsyQgTi8N4L2Fi5k8HkDGiVREASXjQTG210RIP Tk8p8VI85Qi1OKBdBW9+NaFiPJSNYfmAUmbDMMh4z+hnhbJ6XgCM5O1xpKcstZtwMA06 WI90f3HTw3iYPcNCYctfuSPqZyg/xSDLDzRCnaxJsq3XQTswxqCTtrnCEcLZEM6reotz moAmdY2bYp6Wc/cmWFosGUwBCsnKfJxJDCqmS62BiFDKaFGSmRc4Ln1WHtlo+WXuZFoX ly8w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=k+7tPPYD5h+NdS6yysmsG/8IjYDDmjMzwUUxALLypYA=; b=RhOYFUj+GRCDkf9gFrruzdVDF0otlEZLAssvihQvFCJx8Q5Z1I2cb3DrZrG4qJipqS w2+W1MZ+otTR3bJX4Tr4emsO54A7OXmd77QmfAn1Yjq/14l0VedqGXEldYNFFwIX3j2D Vav6nrEun2oPobC1c4BWQJO2+9yWOo0CFwLcPnj/9Fa0xsSNW/m7yetrvMi2yK155fBv lWhKyJv9OM0GwsgAeG7s1jUeqziIIWkJAFDD3aK5CVEQAD5CYHup3UHI9A4AfXv/iL1C 1YRiKVBvxLKU15CVIvOgvZ72f0ivcHslVKJRsS0G0V7jZJCbr971crtlRaZc0DKbMjbu YxBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=Bzlg9uee; 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 e24si1561591ejh.298.2020.05.27.02.27.15; Wed, 27 May 2020 02:27:38 -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=Bzlg9uee; 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 S1727926AbgE0BFD (ORCPT + 99 others); Tue, 26 May 2020 21:05:03 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:7594 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727774AbgE0BFD (ORCPT ); Tue, 26 May 2020 21:05:03 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 26 May 2020 18:04:50 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 26 May 2020 18:05:02 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 26 May 2020 18:05:02 -0700 Received: from [10.2.50.17] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 27 May 2020 01:05:02 +0000 Subject: Re: [PATCH v2] scsi: st: convert convert get_user_pages() --> pin_user_pages() To: LKML CC: Souptick Joarder , =?UTF-8?Q?Kai_M=c3=a4kisara_=28Kolumbus=29?= , Bart Van Assche , "James E . J . Bottomley" , "Martin K . Petersen" , References: <20200526182709.99599-1-jhubbard@nvidia.com> X-Nvconfidentiality: public From: John Hubbard Message-ID: <98b7f283-b208-d222-1d65-8a2e34d0a1af@nvidia.com> Date: Tue, 26 May 2020 18:05:01 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: <20200526182709.99599-1-jhubbard@nvidia.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1590541490; bh=k+7tPPYD5h+NdS6yysmsG/8IjYDDmjMzwUUxALLypYA=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=Bzlg9ueeG2PtNpxgtAnl9vhkNsA/2V64twVVFa9EQJ/2hDldvz6fLHZHTYGOAcqc2 o/fcQ51QmX+myM2Y2L4IVB7qN7bxPlTwtxb2WhrnFk8jbQ8nawxtJW8d0Kj+xFkOCK Lw3LJzevYUoUMsTp9O/nklufJ6azyZ8EbsCSUUP5+Wz6xMcbEE32XWvOIU9DM27l63 cdC5vyamBCbdt4LaXnldV2SiZOuvh0XJN9ackoPzJD/MkbbrdLiiSJlHot20PNSKKs Bg1dx3b9Amu4f6ybnWMr0rQdaOr9LGP8DcsxNGuYcGZ0GP4DxIwUI3t8XbGIhtlI6z 633pBOPVpiY0A== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For some reason, the "convert convert" subject line is really hard to get r= id of from my scsi st patch. In this case, I'd dropped the patch entirely, and recreated it with the old subject line somehow. Sorry about that persistent typo! I'll send a v3 if necessary, to correct that. thanks, John Hubbard NVIDIA On 2020-05-26 11:27, John Hubbard wrote: > This code was using get_user_pages*(), in a "Case 1" scenario > (Direct IO), 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. >=20 > 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. >=20 > 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. >=20 > 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] >=20 > Also, this deletes one of the two FIXME comments (about refcounting), > because there is nothing wrong with the refcounting at this point. >=20 > [1] Documentation/core-api/pin_user_pages.rst >=20 > [2] "Explicit pinning of user-space pages": > https://lwn.net/Articles/807108/ >=20 > [3] https://lore.kernel.org/r/20190723153640.GB720@lst.de >=20 > Cc: "Kai M=C3=A4kisara (Kolumbus)" > Cc: Bart Van Assche > Cc: James E.J. Bottomley > Cc: Martin K. Petersen > Cc: linux-scsi@vger.kernel.org > Signed-off-by: John Hubbard > --- >=20 > Hi, >=20 > As mentioned in the v1 review thread, we probably still want/need > this. Or so I claim. :) Please see what you think... >=20 > Changes since v1: changed the commit log, to refer to Direct IO > (Case 1), instead of DMA/RDMA (Case 2). And added Bart to Cc. >=20 > v1: > https://lore.kernel.org/linux-scsi/20200519045525.2446851-1-jhubbard@nvid= ia.com/ >=20 > thanks, > John Hubbard > NVIDIA >=20 >=20 > drivers/scsi/st.c | 20 +++++--------------- > 1 file changed, 5 insertions(+), 15 deletions(-) >=20 > diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c > index c5f9b348b438..1e3eda9fa231 100644 > --- a/drivers/scsi/st.c > +++ b/drivers/scsi/st.c > @@ -4922,7 +4922,7 @@ static int sgl_map_user_pages(struct st_buffer *STb= p, > 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 *STb= p, > =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_WRIT= E : 0, > + res =3D pin_user_pages_fast(uaddr, nr_pages, rw =3D=3D READ ? FOLL_WRIT= E : 0, > pages); > =20 > /* Errors and no page mapped should return here */ > @@ -4964,8 +4964,7 @@ static int sgl_map_user_pages(struct st_buffer *STb= p, > 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,9 @@ static int sgl_map_user_pages(struct st_buffer *ST= bp, > static int sgl_unmap_user_pages(struct st_buffer *STbp, > const unsigned int nr_pages, int dirtied) > { > - int i; > - > - for (i=3D0; i < nr_pages; i++) { > - struct page *page =3D STbp->mapped_pages[i]; > + /* FIXME: cache flush missing for rw=3D=3DREAD */ > + 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