Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp3210466ybx; Sun, 3 Nov 2019 13:24:50 -0800 (PST) X-Google-Smtp-Source: APXvYqywB0P+cAErJcZSwoGHDufy17jJ90i71ndAHeChmkU7gdKAMtO+Dcf2do549q5Rr8uxcTHG X-Received: by 2002:a50:ac2c:: with SMTP id v41mr25228382edc.11.1572816290215; Sun, 03 Nov 2019 13:24:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572816290; cv=none; d=google.com; s=arc-20160816; b=XncWGCbMkA50nlotekR6fzxjysR9BlphGH4U3qlZa7CS0M7mI01c1BfjUb1AkxKfH6 hB0u3u2hg3S8Ry5QvCL7BHsXR+4SyUSZbHw2F9flR2mBwYn98Ned0cujs9LNb+C633MT 2ZwUmgS77pkT5Brw3QAPHxlrnmMedp8FDU2rahwTHtInXAG+m+qvc1uYYsY4Q7OoELhG qi9Lrc99Pdws91TEINe/AuDttwJhi57aBAftNpD/fF08BpYpqYrnawcfykLEFF+WSHhy v6LDLqjao50Qmd+aFMQwqv0I4js5BeXbMhxVXgBMb/BBczzel5hpD7fgiRzACA2JU11c jE4A== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=s7fqcPpOnu8FKfGfhgVfAy1waz0rDtbaZTRbQ6blVPc=; b=jt9NPsgjzq8lzOJVoqu0IT5aCWC4B0NKH/6gxVaPD5zehi/AzmnsKchC3HMLhg0Lcx Oq6zhvIWCIsiLAJq/WXBHXfgw0qoxwPfD2Sau7e7WaaychiZw/8sbFFu+Ex0CVIay0Bl tkacvm3dA5lRWmrCXdl+ox+529I87/Igu7tW1Qa83yO4E99lFJXVSx5VyVMCxnLLG8qj 2PCSiK1U6/gMGFUmulFftNtfOS3sQ2IABVTVma5AyoT53dVRrEu215RH94gJQprhHsim eRykoOMS+hbaT3voDvdnmsXCHbyKlhEpWDch1wBWplsMmby+EW/IR5Eg8ZEfiSHE6NT5 4guw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=M92XH7Eo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id m19si7472885eje.312.2019.11.03.13.24.26; Sun, 03 Nov 2019 13:24:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=M92XH7Eo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728970AbfKCVU6 (ORCPT + 99 others); Sun, 3 Nov 2019 16:20:58 -0500 Received: from hqemgate16.nvidia.com ([216.228.121.65]:10626 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728342AbfKCVSU (ORCPT ); Sun, 3 Nov 2019 16:18:20 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sun, 03 Nov 2019 13:18:25 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sun, 03 Nov 2019 13:18:19 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sun, 03 Nov 2019 13:18:19 -0800 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; Sun, 3 Nov 2019 21:18:19 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sun, 3 Nov 2019 21:18:18 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sun, 3 Nov 2019 21:18:18 +0000 Received: from blueforge.nvidia.com (Not Verified[10.110.48.28]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Sun, 03 Nov 2019 13:18:18 -0800 From: John Hubbard To: Andrew Morton CC: Al Viro , Alex Williamson , Benjamin Herrenschmidt , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Christoph Hellwig , Dan Williams , Daniel Vetter , Dave Chinner , David Airlie , "David S . Miller" , Ira Weiny , Jan Kara , Jason Gunthorpe , Jens Axboe , Jonathan Corbet , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Magnus Karlsson , "Mauro Carvalho Chehab" , Michael Ellerman , Michal Hocko , Mike Kravetz , "Paul Mackerras" , Shuah Khan , Vlastimil Babka , , , , , , , , , , , , , LKML , John Hubbard Subject: [PATCH v2 15/18] powerpc: book3s64: convert to pin_longterm_pages() and put_user_page() Date: Sun, 3 Nov 2019 13:18:10 -0800 Message-ID: <20191103211813.213227-16-jhubbard@nvidia.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191103211813.213227-1-jhubbard@nvidia.com> References: <20191103211813.213227-1-jhubbard@nvidia.com> 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=1572815905; bh=s7fqcPpOnu8FKfGfhgVfAy1waz0rDtbaZTRbQ6blVPc=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-NVConfidentiality: Content-Transfer-Encoding:Content-Type; b=M92XH7EoTg3RnwFxuX0vW69rhkTc48UxAm1i236kw9kjmBdX5khEYJM3PSu1Glsnv fwGPXubZqw1HIjxiKXstOB01SqQ0M+N+sbIMNdUiWiHNlwyfTXJtMWGs/ODoxXkvoQ N7rp6GK7vX13OFXn3frq2K41zC0IVQ3xViZi7YRFrCBCDml2qZSgjFVBfMoQEsHSyD oIK1l3RNWLrcNxIaY5qRKzHgkz/a6K5HVo8CI7oqYvyv2aToNv0lviPC+RN4tAX+ZD CKk6SYeaMlj7+o1cHYByiDSzIwtGdnq+JEDm42lvPQvAOrfpNaAPS1Um08ksIfh+fh ymyaN1ppyTQGA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 1. Convert from get_user_pages(FOLL_LONGTERM) to pin_longterm_pages(). 2. As required by pin_user_pages(), release these pages via put_user_page(). In this case, do so via put_user_pages_dirty_lock(). That has the side effect of calling set_page_dirty_lock(), instead of set_page_dirty(). 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." [1] 3. Release each page in mem->hpages[] (instead of mem->hpas[]), because that is the array that pin_longterm_pages() filled in. This is more accurate and should be a little safer from a maintenance point of view. [1] https://lore.kernel.org/r/20190723153640.GB720@lst.de Signed-off-by: John Hubbard --- arch/powerpc/mm/book3s64/iommu_api.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s6= 4/iommu_api.c index 56cc84520577..69d79cb50d47 100644 --- a/arch/powerpc/mm/book3s64/iommu_api.c +++ b/arch/powerpc/mm/book3s64/iommu_api.c @@ -103,9 +103,8 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, uns= igned long ua, for (entry =3D 0; entry < entries; entry +=3D chunk) { unsigned long n =3D min(entries - entry, chunk); =20 - ret =3D get_user_pages(ua + (entry << PAGE_SHIFT), n, - FOLL_WRITE | FOLL_LONGTERM, - mem->hpages + entry, NULL); + ret =3D pin_longterm_pages(ua + (entry << PAGE_SHIFT), n, + FOLL_WRITE, mem->hpages + entry, NULL); if (ret =3D=3D n) { pinned +=3D n; continue; @@ -167,9 +166,8 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, uns= igned long ua, return 0; =20 free_exit: - /* free the reference taken */ - for (i =3D 0; i < pinned; i++) - put_page(mem->hpages[i]); + /* free the references taken */ + put_user_pages(mem->hpages, pinned); =20 vfree(mem->hpas); kfree(mem); @@ -212,10 +210,9 @@ static void mm_iommu_unpin(struct mm_iommu_table_group= _mem_t *mem) if (!page) continue; =20 - if (mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY) - SetPageDirty(page); + put_user_pages_dirty_lock(&mem->hpages[i], 1, + MM_IOMMU_TABLE_GROUP_PAGE_DIRTY); =20 - put_page(page); mem->hpas[i] =3D 0; } } --=20 2.23.0