Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3226252ybk; Mon, 18 May 2020 22:21:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlELr7umAInQ4V9zX4oSiG1st0Bywh4Yi5m51D+wyIoBuQvW9rCia8YHZgr3O24F81Qa3i X-Received: by 2002:a50:9e48:: with SMTP id z66mr386556ede.388.1589865667246; Mon, 18 May 2020 22:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589865667; cv=none; d=google.com; s=arc-20160816; b=qCKRymwr1vB1f7C7MbvZ6xFPwNw1V6lbd6uW0dKpFpJuIvswVGxi46YD8y75I/Tcmy QPIlaucqbo7KQkqz0iLHpJLmGuw/O04ZEDOEp1eUwyuTWhv2VDgSvsKfm06cc5PsBUtg HQUyxbB7+o7dowgN5IYIXH4OSzl+w+K17pywlNw9hqvuXYQz8Vh9FsQ56fMGlQ97VqX4 DnDXnRfS118XtMx/0iJTjVk58af+U/JLAguF2Gzx2FL5iTfWDBJpFGYtwqMT8FFkLCBP ret0faF3/aaqz6sVHAxJUNakpQDGl7tXBW1lwfxGIEjmHNjufqoz+JCoTYQOW2bb7eWt XIkw== 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=HOuCeH00Hb2OOmtkXh64pdeD2QbQHkyVvjYj2E3uEb0=; b=a/x0estkxTCpYV6f1bnhFwo8tLPqiJnHG3W7eQVCFA89bBgzKimvPdh4j0l36+JZoc 8pB9kTopVQRrqrzYintyC1/9M15xW1Tai+qN1RFVwvJ2ER5Ce2bOGEK4uF6mKQu67Dkd BtfRzjwEhvh+YA0RDB9ystsEmyNI+c5nyCXMoYya6PS+2vrVtqZqusURfiJ50hKA5Hbv 3roaK2R/obD5AeDIACMy1c1DD6Cr3PKguZex1YGjoP2ORrLXG8ZVukSKn7oogf1Z9TKd KMUavnw3nh6LYuj5PS3jFv1YsRcOnLw+p2Fe8VYD8iiMr/HdZ7lrFDHyvdsmm2iedhQg moVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=mb3OaNFQ; 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 m5si7407844edq.498.2020.05.18.22.20.44; Mon, 18 May 2020 22:21:07 -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=mb3OaNFQ; 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 S1727068AbgESFSy (ORCPT + 99 others); Tue, 19 May 2020 01:18:54 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:1575 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726323AbgESFSy (ORCPT ); Tue, 19 May 2020 01:18:54 -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 22:17:35 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 18 May 2020 22:18:53 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 18 May 2020 22:18:53 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 19 May 2020 05:18:53 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 19 May 2020 05:18:53 +0000 Received: from sandstorm.nvidia.com (Not Verified[10.2.55.90]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 18 May 2020 22:18:53 -0700 From: John Hubbard To: LKML CC: John Hubbard , Jens Wiklander , Sumit Semwal , , , , Subject: [PATCH] tee: convert convert get_user_pages() --> pin_user_pages() Date: Mon, 18 May 2020 22:18:50 -0700 Message-ID: <20200519051850.2845561-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=1589865455; bh=HOuCeH00Hb2OOmtkXh64pdeD2QbQHkyVvjYj2E3uEb0=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: MIME-Version:X-NVConfidentiality:Content-Transfer-Encoding: Content-Type; b=mb3OaNFQ10WkB15WwAhedhrO8Cgn+eMbUGC71oOyJQQXRvPYSnq9gXNLB1ikmE8bz 1mE5oay3UAzRAgWTVrQ1i992uuXlZTpE3UQBDBJ0vpEymxONKvuK/TC3Rqz4xcyggs iBxOA4w7qcMZieTQxzG7CPELd/ht3j8JcfF1BfVup3xxZVvem4q7JXUynr5MNRQp1F UIMTmBPigzGmw0nL490aNS8MZSIgotf3eoLqW2FtBGGYrMlTG66weF8FwIeobdZehk 2WSppxHXytUZkdQu1VMcdSGY030X6vV4qN0fUWSbFPTyDLnYLo2truFc5w7EeqHv2Q iG6MlgGNrcg1g== 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. [1] Documentation/core-api/pin_user_pages.rst [2] "Explicit pinning of user-space pages": https://lwn.net/Articles/807108/ Cc: Jens Wiklander Cc: Sumit Semwal Cc: tee-dev@lists.linaro.org Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Signed-off-by: John Hubbard --- 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/tee/tee_shm.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index bd679b72bd05..7dffc42d8d5a 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -31,16 +31,13 @@ static void tee_shm_release(struct tee_shm *shm) =20 poolm->ops->free(poolm, shm); } else if (shm->flags & TEE_SHM_REGISTER) { - size_t n; int rc =3D teedev->desc->ops->shm_unregister(shm->ctx, shm); =20 if (rc) dev_err(teedev->dev.parent, "unregister shm %p failed: %d", shm, rc); =20 - for (n =3D 0; n < shm->num_pages; n++) - put_page(shm->pages[n]); - + unpin_user_pages(shm->pages, shm->num_pages); kfree(shm->pages); } =20 @@ -226,7 +223,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ct= x, unsigned long addr, goto err; } =20 - rc =3D get_user_pages_fast(start, num_pages, FOLL_WRITE, shm->pages); + rc =3D pin_user_pages_fast(start, num_pages, FOLL_WRITE, shm->pages); if (rc > 0) shm->num_pages =3D rc; if (rc !=3D num_pages) { @@ -271,16 +268,13 @@ struct tee_shm *tee_shm_register(struct tee_context *= ctx, unsigned long addr, return shm; err: if (shm) { - size_t n; - if (shm->id >=3D 0) { mutex_lock(&teedev->mutex); idr_remove(&teedev->idr, shm->id); mutex_unlock(&teedev->mutex); } if (shm->pages) { - for (n =3D 0; n < shm->num_pages; n++) - put_page(shm->pages[n]); + unpin_user_pages(shm->pages, shm->num_pages); kfree(shm->pages); } } --=20 2.26.2