Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1444160ybs; Mon, 25 May 2020 16:37:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUdU6D5cb34g5xMlox7c28Zcw3yb6YXFMktK6d/jTookAr4y3w5La2+79O9rMQtNHspRwp X-Received: by 2002:a05:6402:c11:: with SMTP id co17mr17676699edb.218.1590449838010; Mon, 25 May 2020 16:37:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590449838; cv=none; d=google.com; s=arc-20160816; b=qM6b+1ZWJSQTE119lInzFEAKlSaOZjySesMjMMEvMVgAf1oTRy/z9RhgeQPhzNhBov l8eB6ddFNPZUyMMew9kb8nQE3tLM2x/t10z4qmJQVs9sIgqwFO7s/pzyoKDXKYYqIOvm 4ZSMABpPJnl+iV5iA8N+3aoKBdEYCusU0iuuGAUfBWfx6vEgK0XRyM4yM2yDu/piucrW qNx4XZ09ODxkrsFhG26a/NIWFsdUQGubLwlwbYjJxmVnOGHfl9Ggrk5QKA43ZxrQ1+sw 2kfF6cm01NEiBeqCwvq4rT7zNggRmv3DaFTmPGIf/PzWrQI4VvnLE8AfX3qTE43fmMwG j0gA== 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=VbhMJzzhtLwECOt/zkVs5tvYqSm7aKeF2zHBBFaqTGM=; b=zlFFXXqDAx2I3zzEXrDdStJN1XqeFv8A38ie+XyDm7czv2PrZh7W81BClsK2y+gT3C a+bEIcJH/GCJYheG/ZL42TWMq09I2oI2NwoPuuAVsdB1cNtrwMERiVnuu3HXSjwkAE2y dSOh+Wl8E/h2Up3En41sOsoIlAcOVJrKmMVDpauaPf9LIOi+Scmcr2o2ce0H0hhZx5ye gtyllFn2w7Uu7AE0TbTZOQX+z/0ltf6FweSR8eKXoIFC5nwUCHn4sa53JIRQ+61jI/PI V3K0JeYnRNnc3C8yBs+DclwqSueLmlMVJTTPDJPK55y5A+asC6bhh7XoPye9SH0pEf7s 3png== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=nUf1saWO; 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 l30si12649273edj.293.2020.05.25.16.36.54; Mon, 25 May 2020 16:37:17 -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=nUf1saWO; 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 S2388250AbgEYXcv (ORCPT + 99 others); Mon, 25 May 2020 19:32:51 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:8708 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387766AbgEYXcu (ORCPT ); Mon, 25 May 2020 19:32:50 -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, 25 May 2020 16:31:28 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 25 May 2020 16:32:50 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 25 May 2020 16:32:50 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 25 May 2020 23:32:50 +0000 Received: from rnnvemgw01.nvidia.com (10.128.109.123) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 25 May 2020 23:32:50 +0000 Received: from sandstorm.nvidia.com (Not Verified[10.2.58.199]) by rnnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 25 May 2020 16:32:49 -0700 From: John Hubbard To: LKML CC: John Hubbard , Jens Wiklander , Sumit Semwal , , , , Subject: [PATCH v2] tee: convert get_user_pages() --> pin_user_pages() Date: Mon, 25 May 2020 16:32:48 -0700 Message-ID: <20200525233248.434636-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=1590449488; bh=VbhMJzzhtLwECOt/zkVs5tvYqSm7aKeF2zHBBFaqTGM=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: MIME-Version:X-NVConfidentiality:Content-Transfer-Encoding: Content-Type; b=nUf1saWOS7mb/lnsvWb+B21oDh2NRXZqPgX4xJUgmzam4KPf9nZaCoy/X0bwzBYrY Zebfr779q3I/dmH4EKycVJH1ILsnuGqwlduZbjJIkWAL4XEHE8ydyNlr7S39B+3xbG ZmAMWdFbzBNxH+nqLUULtEyOMt9DIw11bO8iL45LdlOZi9+k1qwzmuPHBu84GIsQ0E OLjifKUXBRiZWydx1RMXL5WoWRtvQylgA6UrUO3JIrn8ONHbBCVcLZMv4AIHtErqV+ 5TGz4dsidr5Ay8zAHeCd69/BvWX3bveRL/gmJmMI8NyPDX8Mi+1BRtFrWTKH1TpdW7 O+gppcemBUZag== 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 --- Hi, This fixes the typo ("convert convert") in the subject line, but otherwise no changes. 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