Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp122137ybs; Tue, 26 May 2020 05:20:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAAJ1+3BxIy6OAyHdu0pFMwNcltVJZgjh04vFLeIGprB7yLIN/Sd7Z2oaGuAwQQLDFljOI X-Received: by 2002:aa7:da8c:: with SMTP id q12mr19777106eds.334.1590495604217; Tue, 26 May 2020 05:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590495604; cv=none; d=google.com; s=arc-20160816; b=OO2NtgyxRBm/mnfWwHiEy5foNhpCIs/h6/2e5ZIkQ+/E/mNk+F4GbU9BcOkU+oq+FR qSgtGdI6TMrKO0i7HNkxW8pHChAqe4QExCPZcXwLgTvW/CCUWUfIpfk1dXLAI3n2jtcB WsbpXGSTETArUJkHUzUUHz2G0hMsMTc/mGxrdowJJnppZn9gJI0dRf5NuaMPo0RRJvk1 cx1Rtf+8cKoBFnVu4hLyaDeY8tw6Ud+0SvrdgimUYeKBlhxjxfZ6+vqicbM2iqC/OaAP Wuc96mpkvYCCVfdwYuV36bxn0nsnit/G41kx52qjBXAsLWUXNjOonQcnxwMe8vpmdxyi ja0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5GNEdvxv7mdO2rvUKQ7g7CQMFrgCJQETUzHF+R0Pghk=; b=Giz2cOGSQf0lMFZ7sr9/9nTmLdlz4C/Dk3QHfVJavU+X+aLc6pNzi0DgwDUa768JGr Wwtz9MnWTiGcZBTnXJG+cP+MNIzsGyh1xnytBJY567hM+TLP402IQqHh9hwNL9MJLYyw sv5S+uKj8FoWvFlCJRGlCRwkkyj/OPiW+6NAPAP/sjfr6rT6CyAksaxLoIPJPMq//6vS Ne8yvZWfYdgcx3c/LXA7IsfPti5vwpulExusMzTnadXKLWxN+g85goO8RvqalpDLPBoY CU6SThq8rkqeZTxJDEeWjt5l+p3vIPi09SeODVnvrFCkW/XaVYlD8Dm6QAxGj+gfLFrI sybQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cWoK90ub; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n4si11450790eje.295.2020.05.26.05.19.40; Tue, 26 May 2020 05:20:04 -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=@linaro.org header.s=google header.b=cWoK90ub; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731580AbgEZItD (ORCPT + 99 others); Tue, 26 May 2020 04:49:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725771AbgEZItC (ORCPT ); Tue, 26 May 2020 04:49:02 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A449CC03E97E for ; Tue, 26 May 2020 01:49:02 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id d191so17975773oib.12 for ; Tue, 26 May 2020 01:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5GNEdvxv7mdO2rvUKQ7g7CQMFrgCJQETUzHF+R0Pghk=; b=cWoK90ubt9Zt16ipNusgGtcCLXrJQ2KdR/4phuhXvAOBzyAjlrj1sUOBhNckRmjkFf vCbJwaUvP43Z5uJjNjr99Bs3afD//vOVkLzNqQqu3XEqHOEd7YT3O1eJp/N6jbU6ZVD5 HYK7nHgGjnBIk5uShaJqd5S+fTE941jBuBrRly2RCz4KQfp7xW91XiCB76WmQH2i72oj UQQLe/a8+HSy51vBlJA8KkrrpOp1oyfuvMdryQKkY7Y0tuoO8HBa1TlDKXBjD5snNVWH WFxuMmECDi/u9csMxvBLqA0UHZuCUpf+NtuyvlNk22vp5aXTvSYN32WL7Uz3sr6wAyYl SCiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5GNEdvxv7mdO2rvUKQ7g7CQMFrgCJQETUzHF+R0Pghk=; b=KfwbeR15mLJwj/uD+MQ3gQns2cqt8bygZeEQbpxH7pN0Oq8qvyyuow79rUvq9/ciER 6KoVBktdj7Yv/sIoIOlRf4a0Uj4WqhCI07znu9puIUOZE+lCfYufvnG4BedH/7gV9cqX fV5AusbqtD0XsWHtf8DyAuicqrfwKJwQjICeY0knQrLKV82KKBKn1T4viL4P9im3wQYY i8Rcx4C+e7PAvH8Odw+DCaKXZDvjhSfnknf3w7X2gwR8kSeorSwK9kYCsYy3Tr8zOhs0 Yyv/gW5AYW9Fe3OlN4AToGpzgLiLrhiueWgB56qBmIFEZ11sVoI9djQVu1uX87uXBGrL Hknw== X-Gm-Message-State: AOAM533hJbuXTdSaGgLj/6XAHTk8OXrIq2xGX5UUPiOF4LoGGZV0Jg/Y 07R+XMMtE2tthgYhWpnrk2ydwXp0euCet1aMNJv68HGp X-Received: by 2002:a05:6808:3dc:: with SMTP id o28mr14010604oie.149.1590482941983; Tue, 26 May 2020 01:49:01 -0700 (PDT) MIME-Version: 1.0 References: <20200525233248.434636-1-jhubbard@nvidia.com> In-Reply-To: <20200525233248.434636-1-jhubbard@nvidia.com> From: Jens Wiklander Date: Tue, 26 May 2020 10:48:50 +0200 Message-ID: Subject: Re: [PATCH v2] tee: convert get_user_pages() --> pin_user_pages() To: John Hubbard Cc: LKML , Sumit Semwal , "tee-dev @ lists . linaro . org" , linux-media@vger.kernel.org, DRI Development , linaro-mm-sig@lists.linaro.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi John, On Tue, May 26, 2020 at 1:32 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 > --- > > 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(-) Looks good. I've tested this on a HiKey 620 board, no regressions. I'm picking up this patch. Thanks, Jens > > 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) > > 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); > } > > @@ -226,7 +223,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, > goto err; > } > > - rc = get_user_pages_fast(start, num_pages, FOLL_WRITE, shm->pages); > + rc = pin_user_pages_fast(start, num_pages, FOLL_WRITE, shm->pages); > if (rc > 0) > shm->num_pages = rc; > if (rc != 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 >= 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); > } > } > -- > 2.26.2 >