Commit aa10e3cf authored by Olof Johansson's avatar Olof Johansson

Merge tag 'tee-pin-user-pages-for-5.10' of...

Merge tag 'tee-pin-user-pages-for-5.10' of git://git.linaro.org/people/jens.wiklander/linux-tee into arm/drivers

Converts tee subsystem to use pin_user_pages() instead of get_user_pages()

* tag 'tee-pin-user-pages-for-5.10' of git://git.linaro.org/people/jens.wiklander/linux-tee:
  tee: convert get_user_pages() --> pin_user_pages()

Link: https://lore.kernel.org/r/20200825090715.GA2370775@jadeSigned-off-by: default avatarOlof Johansson <olof@lixom.net>
parents d4ee2d35 4300cd63
...@@ -12,6 +12,22 @@ ...@@ -12,6 +12,22 @@
#include <linux/uio.h> #include <linux/uio.h>
#include "tee_private.h" #include "tee_private.h"
static void release_registered_pages(struct tee_shm *shm)
{
if (shm->pages) {
if (shm->flags & TEE_SHM_USER_MAPPED) {
unpin_user_pages(shm->pages, shm->num_pages);
} else {
size_t n;
for (n = 0; n < shm->num_pages; n++)
put_page(shm->pages[n]);
}
kfree(shm->pages);
}
}
static void tee_shm_release(struct tee_shm *shm) static void tee_shm_release(struct tee_shm *shm)
{ {
struct tee_device *teedev = shm->ctx->teedev; struct tee_device *teedev = shm->ctx->teedev;
...@@ -32,17 +48,13 @@ static void tee_shm_release(struct tee_shm *shm) ...@@ -32,17 +48,13 @@ static void tee_shm_release(struct tee_shm *shm)
poolm->ops->free(poolm, shm); poolm->ops->free(poolm, shm);
} else if (shm->flags & TEE_SHM_REGISTER) { } else if (shm->flags & TEE_SHM_REGISTER) {
size_t n;
int rc = teedev->desc->ops->shm_unregister(shm->ctx, shm); int rc = teedev->desc->ops->shm_unregister(shm->ctx, shm);
if (rc) if (rc)
dev_err(teedev->dev.parent, dev_err(teedev->dev.parent,
"unregister shm %p failed: %d", shm, rc); "unregister shm %p failed: %d", shm, rc);
for (n = 0; n < shm->num_pages; n++) release_registered_pages(shm);
put_page(shm->pages[n]);
kfree(shm->pages);
} }
teedev_ctx_put(shm->ctx); teedev_ctx_put(shm->ctx);
...@@ -228,7 +240,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, ...@@ -228,7 +240,7 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
} }
if (flags & TEE_SHM_USER_MAPPED) { 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); shm->pages);
} else { } else {
struct kvec *kiov; struct kvec *kiov;
...@@ -292,18 +304,12 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, ...@@ -292,18 +304,12 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
return shm; return shm;
err: err:
if (shm) { if (shm) {
size_t n;
if (shm->id >= 0) { if (shm->id >= 0) {
mutex_lock(&teedev->mutex); mutex_lock(&teedev->mutex);
idr_remove(&teedev->idr, shm->id); idr_remove(&teedev->idr, shm->id);
mutex_unlock(&teedev->mutex); mutex_unlock(&teedev->mutex);
} }
if (shm->pages) { release_registered_pages(shm);
for (n = 0; n < shm->num_pages; n++)
put_page(shm->pages[n]);
kfree(shm->pages);
}
} }
kfree(shm); kfree(shm);
teedev_ctx_put(ctx); teedev_ctx_put(ctx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment