From patchwork Tue Jul 30 12:23:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 170053 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp2574508ile; Tue, 30 Jul 2019 05:24:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyigWzx5Xz0r2KifrOmToaK69IHvGUJaDzYFMN3mlBgpu0tMNrj4RHxaTAmzUsAMSemlIPQ X-Received: by 2002:a17:902:8b82:: with SMTP id ay2mr71831191plb.164.1564489484786; Tue, 30 Jul 2019 05:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564489484; cv=none; d=google.com; s=arc-20160816; b=SM1tDXALBULdPdEGThaoXkqMlOdOiFphi1WaE24zGD4HiZJmiICAiZgGeNS6N+0CcK kzQWx5Qkji67FP9YDlAaQeJydaXYpJLZkKIeko6aOAgWtRKjad0auc+ItCl3rQr7SvL7 jeki/MaecZB7VJFgdAKdnAEwnWfJDXpUdBzzuOqAJ/bBTFwDuRTdoMkRduJG+jmNWbdq 4ttHqQI7u5RuHnOnIGc457mZKiPGb3GtOjGm4KN9eQbPHrhm6rjyIyZ0JRSt8MEWivGk cgCdduG/T8d4aLBwM1StTYwIGKboxbofHfWw6o20fqHygaTQRz0wBUxgbBbWBKTxz2Dj XPZA== 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=F6RVSFR3EtlCJ6lvWs5T4vKHtTJAwPryiatLZ1M1aSY=; b=Ilsgm4XvIA/jQSOtSreYJU8aP14nKMbkrLHekIXSUVStwweQ9xU4lt4XUcaQ8eqzaV fN+MEJymjVpVVELrEzfCZrNyi5/5jHff1cFNMPxiqRY88ntnyl6PxTNqCV8ViBSOpB+q qoN+rw3gYGZPcc7CtNxOa27L9Oih4oF4FWC8Ur4kX17htbhDHy4JbBqd924KVFmdCg9w fn/GzMpzDqB8cijaivUljCBlmKoMO22UOdTrXbwn1FXgbTOhJNpQwWAVeoeGRB8/iTnk aNOIHmP++0pL4rDluo6JUP8DRZzhwOpdYVA3rGXiMcdq5XkbPaSMvxRtPOrM8xD1ga+d ISiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tfILgsUT; 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 q18si21101416pgk.31.2019.07.30.05.24.44; Tue, 30 Jul 2019 05:24:44 -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=tfILgsUT; 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 S1729648AbfG3MYn (ORCPT + 29 others); Tue, 30 Jul 2019 08:24:43 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42123 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728219AbfG3MYm (ORCPT ); Tue, 30 Jul 2019 08:24:42 -0400 Received: by mail-pf1-f193.google.com with SMTP id q10so29749899pff.9 for ; Tue, 30 Jul 2019 05:24:42 -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=F6RVSFR3EtlCJ6lvWs5T4vKHtTJAwPryiatLZ1M1aSY=; b=tfILgsUTF754qwTkDQPJD0rCNoaw5Uefc9p9gu+bUyOB285QrfyyfBMXVCuakpWXxU HICwYDIoYTjs/+ornlvVNUoij4mg9ij8bxODX+c7q02mHaK7IrzMH1R7ecmTkMo4+2xO Us9rLCt7owepUui89bfkEE/+tfrGjWsmuEK7kWBlWuXdpLhbvxXU6dLLp7egHq3QfEOx EAnFbfA73EDc7EvI/7xV2L+LruWbM8T/aZwxfA/Fok9dNyUsOb1nZjkFl2ZhnvrgF20f tcRKcSqCuXR5PmdwOUIpurnXSTsuhM16BUhSnW79IuqvzINcCDhZiAimeJCJ/3aEVT/+ Skzg== 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=F6RVSFR3EtlCJ6lvWs5T4vKHtTJAwPryiatLZ1M1aSY=; b=Rzq8oOpwF/96W//pc+Vq7iVwUQepV2COzLmlHcN+W9NvM+Fpx9n87FlDqD4Ak+RphT yk86xnOId83jEH6b41pFxk/6BFE/gT9g1t0YeSa86Be9JKVMIN8ADHwZtlJ7I6Z1oz1Z 1l/spMf14STg+TnIjrLNtF/tYUxVsUEMJNg6Uytn9XCNlaLXFVE/URPYu2nL+tURQ4et vO6qVKt/ZaNt6eDFg3bYUrS1pK+QV+ddb0ZQ2fKHS9ZWn5QBRzic41talLY9tS5OY02b mVvQO3gphraUj6JOoovMx7S1VwwnAiKj5Bw4jCDHnETV2MA6Mc+L2thL4FbLUCyy/rED 5c7g== X-Gm-Message-State: APjAAAXpVbIIE8ZcIQ4pOwyBeX19P70VU/YBEQ3yQfhOHxeeJZO2wpcw aFkjij5jcEAp8tWOvtAIPuamiQ== X-Received: by 2002:a63:d04e:: with SMTP id s14mr103689463pgi.189.1564489481707; Tue, 30 Jul 2019 05:24:41 -0700 (PDT) Received: from localhost.localdomain ([45.114.72.197]) by smtp.gmail.com with ESMTPSA id v8sm54895462pgs.82.2019.07.30.05.24.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jul 2019 05:24:40 -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, casey@schaufler-ca.com, ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org, Sumit Garg Subject: [RFC v2 2/6] tee: enable support to register kernel memory Date: Tue, 30 Jul 2019 17:53:36 +0530 Message-Id: <1564489420-677-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1564489420-677-1-git-send-email-sumit.garg@linaro.org> References: <1564489420-677-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 Reviewed-by: Jarkko Sakkinen Reviewed-by: Jens Wiklander --- drivers/tee/tee_shm.c | 16 ++++++++++++++-- include/linux/tee_drv.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) -- 2.7.4 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;