From patchwork Thu Jun 13 10:30:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166695 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp908538ilk; Thu, 13 Jun 2019 08:35:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyllYtxYsOl5BS46dYt7KBXxfcCB2C4+tRygBmmeSHo1mKCIEMsghnzvWMyw0JS8w8qEnWV X-Received: by 2002:a17:90a:20e7:: with SMTP id f94mr6096232pjg.68.1560440100306; Thu, 13 Jun 2019 08:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440100; cv=none; d=google.com; s=arc-20160816; b=gjd1D1rcABKy9bVT5zp8KFX+DLXd/13CbJZcZ5k5D1i5FNpiwutpLfsuZw0iYoOvQ/ 2GemFCcqI2wjqi4SmP8Qfa1GULGPTfhgGInPqhC3/VgZGdUXWodek4VF5nWiQJm2E5oP IlFUavjVxaPU3Ekn9QmLbI/PCY0tljZUHoOTo8KE02qO9+LSbJVvEkUD5m1ZQK28IsMM 1DXwzgczGJnqz65Gf1T7nEqvn4CpAvYAL/4eN7HnZZ1OMghVfuEOaCoY2S1kOYLzT7gG x1bRXofTRCH9fOcU6np+2B3NtTZysApVP0t5TlDdDarpSxHjPh23div2TruJWJ0g4m9e 5aJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=X1ybKF8wUkHdnaXcEVMx2e6e4CdYBWVAzo6oWbimFYQ=; b=04xF5lkC/yKNIbQmalWw0PdQqAO9TI3o8xCqnT2U+jad5YaZiJW/9QZraoed4ti8ie zqx5ajVDOsJAScZ7BYpgi9uvy2E3dVeFl5mX6VBhGMJjPhGVNkEDC063pFlb0Aq+XFaG Kq8esMfX6PATY4db/JiJxfFfLoADFnNMFz9Ps+ajYiNB9W9ZO2lZYP/2z5nQXRfRSL57 LF1BRk7f563zPadAvngsQT2ueK5A6l1/ONJbTeJzY9Y29zlojQXLqWBTwN2P9R6aY7G0 ja/9kdWhDpqTpwDmsdoh4wwrDbA2obyU30JanETtR3y675lGnNjx3/J2b+UNMShCDawR 8ncw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qQC72Jqy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id f7si92213pgq.404.2019.06.13.08.35.00; Thu, 13 Jun 2019 08:35:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qQC72Jqy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1732086AbfFMPex (ORCPT + 25 others); Thu, 13 Jun 2019 11:34:53 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33668 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728019AbfFMKbs (ORCPT ); Thu, 13 Jun 2019 06:31:48 -0400 Received: by mail-pf1-f196.google.com with SMTP id x15so11603481pfq.0 for ; Thu, 13 Jun 2019 03:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X1ybKF8wUkHdnaXcEVMx2e6e4CdYBWVAzo6oWbimFYQ=; b=qQC72JqyNS5M5jXNAY8R3qU0KXWZM5lNzLTY1x45KapGIu5nY1kzXvtp8ytpYYAhNe VgEDc2Xb0TO9QjIR1scrGcXdU1EZBuzhgCjzfe7X1+jpmGG6K1x+Pf/9uqbgffhKrmNG wAPT1c1JfaM31idoL06nNamvN48hNPdql4a3HXfHAOdWsQOsfRkD3H3nKJpZB6TPX0ee lVLcpBU+49fTw+3zzRIdis+1cNwUKR2A2T/WWhA/MY121JqRxbEReGNv2toR6GuMHHgy yiSnAlAD6mp1f8mPJKrUvuiGbO6NmXN56mS8pPbZRAPe4I32m2XLpwja0iWkRglQCnZf F3Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X1ybKF8wUkHdnaXcEVMx2e6e4CdYBWVAzo6oWbimFYQ=; b=P0jdWxYU11WFZjM+uPbEr0+VkHA0h23HGYz5gkzya74bYk1olzWbl/I01xL3t2QftM T17H8e1Yu3VWOtwt7Vr108P+P2VseirR1n36jHUp0IU9GjH2AfygY9REAVqqe4T8PvDV LUQlUu9rZ9JAooiuJeXmUmiNgO5a3EzGWsbAOx+Vsd27VYmI2OR5e8M8QOJ+sKGnMTlK /iXpamUZGJj+fi50SHvEi/kYfUzv3vv/RoyLYph18TcYXMN931S363pFweuaK4Nc2he8 08Dg631xwIbuZ3uM9a/7R/nBcr3orHBFcpcnt1kMkoYfbdSsAUAXT6FUz5ZnhipUWx93 zXUA== X-Gm-Message-State: APjAAAVK595017ZESi1z6ijGd3Y+wll1r25kwh1yd0SePnWZveaqERNk lNLtaFaNE7513gIbNTDwVmRacQ== X-Received: by 2002:a63:e24:: with SMTP id d36mr29935015pgl.80.1560421908050; Thu, 13 Jun 2019 03:31:48 -0700 (PDT) Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id a12sm2265078pgq.0.2019.06.13.03.31.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jun 2019 03:31:47 -0700 (PDT) From: Sumit Garg To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: jens.wiklander@linaro.org, corbet@lwn.net, dhowells@redhat.com, jejb@linux.ibm.com, jarkko.sakkinen@linux.intel.com, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tee-dev@lists.linaro.org, Sumit Garg Subject: [RFC 2/7] tee: enable support to register kernel memory Date: Thu, 13 Jun 2019 16:00:28 +0530 Message-Id: <1560421833-27414-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> References: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enable support to register kernel memory reference with TEE. This change will allow TEE bus drivers to register memory references. Signed-off-by: Sumit Garg --- drivers/tee/tee_shm.c | 16 ++++++++++++++-- include/linux/tee_drv.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) -- 2.7.4 Reviewed-by: Jens Wiklander diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 2da026f..5c69b89 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "tee_private.h" static void tee_shm_release(struct tee_shm *shm) @@ -224,13 +225,14 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, { struct tee_device *teedev = ctx->teedev; const u32 req_flags = TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED; + const u32 req_ker_flags = TEE_SHM_DMA_BUF | TEE_SHM_KERNEL_MAPPED; struct tee_shm *shm; void *ret; int rc; int num_pages; unsigned long start; - if (flags != req_flags) + if (flags != req_flags && flags != req_ker_flags) return ERR_PTR(-ENOTSUPP); if (!tee_device_get(teedev)) @@ -264,7 +266,17 @@ 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); + if (flags & TEE_SHM_USER_MAPPED) { + rc = get_user_pages_fast(start, num_pages, FOLL_WRITE, + shm->pages); + } else { + const struct kvec kiov = { + .iov_base = (void *)start, + .iov_len = PAGE_SIZE + }; + + rc = get_kernel_pages(&kiov, num_pages, 0, shm->pages); + } if (rc > 0) shm->num_pages = rc; if (rc != num_pages) { diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index 7a03f68..dedf8fa 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -26,6 +26,7 @@ #define TEE_SHM_REGISTER BIT(3) /* Memory registered in secure world */ #define TEE_SHM_USER_MAPPED BIT(4) /* Memory mapped in user space */ #define TEE_SHM_POOL BIT(5) /* Memory allocated from pool */ +#define TEE_SHM_KERNEL_MAPPED BIT(6) /* Memory mapped in kernel space */ struct device; struct tee_device;