From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 067FEC433DF for ; Mon, 24 Aug 2020 18:46:09 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C7AFF2065F for ; Mon, 24 Aug 2020 18:46:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JFD2PKpz"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="dpQhgZn9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7AFF2065F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8ah+nPDKfIAFHDE06q9G9gfR5SWONft5K/fj4GSfI/M=; b=JFD2PKpz76uNk7x9rJ98w4wbY vLilJshM0NWTpS8GrvJYR/eKWNMCf2r36/V75Z37WTLBt0psbnOHaZFfkNUw1JLbFF7W00/ybPgL4 ajIHd10DHFjpb6GEwALt1UAB7OzfImcgPQkDrWIsHYDzrs8j4yPX9n1w7PVPcyuhnZZEIjOOjOPIb jr35tqipGCVyCDp6HKumJCGpfHAJuJlyPbz6L8EDJT7RxcHQaLFaqaUiCmnbgEdQmy2H7/LK0/PpG iVyR3L2mfYH6vl+b9nG1NbNOybJ6MMkzwdZ4a6qfuPQvEP78pLU0FqakzIbKHbUBVt46yHsKbw8cv CFBlOw3XA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHSA-0007O5-4l; Mon, 24 Aug 2020 18:44:22 +0000 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAHQk-0006li-33 for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2020 18:43:20 +0000 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 24 Aug 2020 11:42:38 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Mon, 24 Aug 2020 11:42:52 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Mon, 24 Aug 2020 11:42:52 -0700 Received: from [10.2.58.8] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 24 Aug 2020 18:42:52 +0000 Subject: Re: [PATCH v2] tee: convert convert get_user_pages() --> pin_user_pages() To: References: <20200824183641.632126-1-jhubbard@nvidia.com> From: John Hubbard Message-ID: Date: Mon, 24 Aug 2020 11:42:51 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200824183641.632126-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-Language: en-US DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1598294558; bh=klGkO69RyKV41kWO8RX/ZqxuPo1xSyXNnZlFSqLUpC0=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=dpQhgZn9rMKgRclkpFkX4O2GVTZdqhj5ePqwQZlzSUp1dsosdVJZLa4kPLRP2sPzU Pw0b/lMHaPUUYRNnZPKOWo3nbGZFeAPPRb/OK78DbPlMyMGBrRL3NjJi/Q1J5GXUep kMpl0WrwaJUcg2OvIUFu5M4f/xg92hzRHyZc3GZlzo2+XKc0Hj4MZjaDgmvocd/6P8 gNdX1yMcJiD0ucJnY3iIjlG9jbplBOX6XxfZEu+cAgrNfR6iNzWfKdRL0jnAYcIvMW RLppo6O8+ft+A6g3PxUZs290J6BKnoV4sYxwMi83F6YwANTWqY5aZQgyGfIki7Ewa3 SRVlGPfHQFiZA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200824_144254_483963_556DB08A X-CRM114-Status: GOOD ( 26.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , List-Id: Cc: linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, tee-dev@lists.linaro.org, soc@kernel.org, arm@kernel.org, olof@lixom.net, Sumit Semwal , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 8/24/20 11:36 AM, John Hubbard wrote: > 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 > --- > > OK, this should be indentical to v1 [1], but now rebased against > Linux 5.9-rc2. > ...ohhh, wait, I should have read the earlier message from Jens more carefully: "The conflict isn't trivial, I guess we need to handle the different types of pages differently when releasing them." So it's not good to have a logically identical patch. argghhh. Let me see how hard it is to track these memory types separately and handle the release accordingly, just a sec. Sorry about the false move here. thanks, -- John Hubbard NVIDIA > As before, I've compile-tested it again with a cross compiler, but that's > the only testing I'm set up for with CONFIG_TEE. > > [1] https://lore.kernel.org/r/20200519051850.2845561-1-jhubbard@nvidia.com > > 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 827ac3d0fea9..3c29e6c3ebe8 100644 > --- a/drivers/tee/tee_shm.c > +++ b/drivers/tee/tee_shm.c > @@ -32,16 +32,13 @@ static void tee_shm_release(struct tee_shm *shm) > > poolm->ops->free(poolm, shm); > } else if (shm->flags & TEE_SHM_REGISTER) { > - size_t n; > int rc = teedev->desc->ops->shm_unregister(shm->ctx, shm); > > if (rc) > dev_err(teedev->dev.parent, > "unregister shm %p failed: %d", shm, rc); > > - for (n = 0; n < shm->num_pages; n++) > - put_page(shm->pages[n]); > - > + unpin_user_pages(shm->pages, shm->num_pages); > kfree(shm->pages); > } > > @@ -228,7 +225,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, > } > > if (flags & TEE_SHM_USER_MAPPED) { > - rc = get_user_pages_fast(start, num_pages, FOLL_WRITE, > + rc = pin_user_pages_fast(start, num_pages, FOLL_WRITE, > shm->pages); > } else { > struct kvec *kiov; > @@ -292,16 +289,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 >= 0) { > mutex_lock(&teedev->mutex); > idr_remove(&teedev->idr, shm->id); > mutex_unlock(&teedev->mutex); > } > if (shm->pages) { > - for (n = 0; n < shm->num_pages; n++) > - put_page(shm->pages[n]); > + unpin_user_pages(shm->pages, shm->num_pages); > kfree(shm->pages); > } > } > v _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel