From patchwork Thu Feb 18 15:05:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 62216 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp639355lbl; Thu, 18 Feb 2016 07:06:48 -0800 (PST) X-Received: by 10.98.8.80 with SMTP id c77mr10647040pfd.42.1455807997435; Thu, 18 Feb 2016 07:06:37 -0800 (PST) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id q21si9884244pfi.231.2016.02.18.07.06.37; Thu, 18 Feb 2016 07:06:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 403476EC2C; Thu, 18 Feb 2016 15:06:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x233.google.com (mail-wm0-x233.google.com [IPv6:2a00:1450:400c:c09::233]) by gabe.freedesktop.org (Postfix) with ESMTPS id 76B1A6EC29 for ; Thu, 18 Feb 2016 15:06:34 +0000 (UTC) Received: by mail-wm0-x233.google.com with SMTP id g62so29793920wme.0 for ; Thu, 18 Feb 2016 07:06:34 -0800 (PST) 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=ZEBjA/aqW4E9Rb0SekswKsUh/0gbRFrWAnXCadx5KNU=; b=ZcYf4///kv2RSgkX26z6k+O+irVJPXNUU/ov+L910CGIyi67X97K32S0bVMDX1E5IY NNEeT1LPS/diAucYXDH2c664UULtGzUsm1I5s2urGihOHwVfRh7fYpJMg2h2iQ8YXp+x 66elHstjmv7z4LIH4K3Q0E+rT2JewM3HB38LU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZEBjA/aqW4E9Rb0SekswKsUh/0gbRFrWAnXCadx5KNU=; b=elLugMQdzf+2/BZ7RrT3G9i7MPUu8PdDZ8tUpbweXDBUHjSnLJafZZnGVahAfFqP0k nr0IW9Na17KU/ss/JjkOSsFRJ/vm4FPkKii93KQuNkqBxaqPOi5CX8fKGYAjkCK5dGX3 QMHqqKVElbS1lDks/h9yIB8NGNr/5n/Z1NpA6txPvMJfgvjJKJwMgZDLfpqm/wQ+7umg ZXn6TVNOIGnMSxwI+Iu2yh1MyeIJ1xiw3WwCduk+AIG8qiQ+UwNeIv1Pyx6hZYjpt5SG yt2MDYzwks5Ovmxf5S/XUSBqASQkJQ7WwLJOfMVBpYqdCmeECllbQJs6Yd6w3tEyFWKS JUCg== X-Gm-Message-State: AG10YOSmYha7ax/+hvQBSNN6/S/NrAY99Ew3Dm+5MCmrcODYfO9ZA31RnPDRRHw04H+IKWUQ X-Received: by 10.28.180.84 with SMTP id d81mr4214372wmf.42.1455807992968; Thu, 18 Feb 2016 07:06:32 -0800 (PST) Received: from lmenx321.st.com. ([80.12.39.4]) by smtp.gmail.com with ESMTPSA id z127sm3416247wme.5.2016.02.18.07.06.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Feb 2016 07:06:31 -0800 (PST) From: Benjamin Gaignard To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-security-module@vger.kernel.org, laurent.pinchart@ideasonboard.com, zoltan.kuscsik@linaro.org, sumit.semwal@linaro.org, cc.ma@mediatek.com Subject: [PATCH v6 3/3] SMAF: add fake secure module Date: Thu, 18 Feb 2016 16:05:17 +0100 Message-Id: <1455807917-19901-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455807917-19901-1-git-send-email-benjamin.gaignard@linaro.org> References: <1455807917-19901-1-git-send-email-benjamin.gaignard@linaro.org> Cc: "benjamin.gaignard@linaro.org" X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: "benjamin.gaignard@linaro.org" This module is allow testing secure calls of SMAF. Signed-off-by: Benjamin Gaignard --- drivers/smaf/Kconfig | 6 +++ drivers/smaf/Makefile | 1 + drivers/smaf/smaf-fakesecure.c | 92 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/smaf/smaf-fakesecure.c diff --git a/drivers/smaf/Kconfig b/drivers/smaf/Kconfig index 058ec4c..fd17005 100644 --- a/drivers/smaf/Kconfig +++ b/drivers/smaf/Kconfig @@ -9,3 +9,9 @@ config SMAF_CMA depends on SMAF && HAVE_DMA_ATTRS help Choose this option to enable CMA allocation within SMAF + +config SMAF_FAKE_SECURE + tristate "SMAF fake secure module" + depends on SMAF + help + Choose this option to enable fake secure module for test purpose diff --git a/drivers/smaf/Makefile b/drivers/smaf/Makefile index 05bab01b..00d5cd4 100644 --- a/drivers/smaf/Makefile +++ b/drivers/smaf/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_SMAF) += smaf-core.o obj-$(CONFIG_SMAF_CMA) += smaf-cma.o +obj-$(CONFIG_SMAF_FAKE_SECURE) += smaf-fakesecure.o diff --git a/drivers/smaf/smaf-fakesecure.c b/drivers/smaf/smaf-fakesecure.c new file mode 100644 index 0000000..75e12dd --- /dev/null +++ b/drivers/smaf/smaf-fakesecure.c @@ -0,0 +1,92 @@ +/* + * smaf-fakesecure.c + * + * Copyright (C) Linaro SA 2015 + * Author: Benjamin Gaignard for Linaro. + * License terms: GNU General Public License (GPL), version 2 + */ +#include +#include +#include + +#define MAGIC 0xDEADBEEF + +struct fake_private { + int magic; +}; + +static void *smaf_fakesecure_create(void) +{ + struct fake_private *priv; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv->magic = MAGIC; + + return priv; +} + +static int smaf_fakesecure_destroy(void *ctx) +{ + struct fake_private *priv = (struct fake_private *)ctx; + + WARN_ON(!priv || (priv->magic != MAGIC)); + kfree(priv); + + return 0; +} + +static bool smaf_fakesecure_grant_access(void *ctx, + struct device *dev, + size_t addr, size_t size, + enum dma_data_direction direction) +{ + struct fake_private *priv = (struct fake_private *)ctx; + + WARN_ON(!priv || (priv->magic != MAGIC)); + + return priv->magic == MAGIC; +} + +static void smaf_fakesecure_revoke_access(void *ctx, + struct device *dev, + size_t addr, size_t size, + enum dma_data_direction direction) +{ + struct fake_private *priv = (struct fake_private *)ctx; + + WARN_ON(!priv || (priv->magic != MAGIC)); +} + +static bool smaf_fakesecure_allow_cpu_access(void *ctx, + enum dma_data_direction direction) +{ + struct fake_private *priv = (struct fake_private *)ctx; + + WARN_ON(!priv || (priv->magic != MAGIC)); + + return priv->magic == MAGIC; +} + +static struct smaf_secure fake = { + .create_ctx = smaf_fakesecure_create, + .destroy_ctx = smaf_fakesecure_destroy, + .grant_access = smaf_fakesecure_grant_access, + .revoke_access = smaf_fakesecure_revoke_access, + .allow_cpu_access = smaf_fakesecure_allow_cpu_access, +}; + +static int __init smaf_fakesecure_init(void) +{ + return smaf_register_secure(&fake); +} +module_init(smaf_fakesecure_init); + +static void __exit smaf_fakesecure_deinit(void) +{ + smaf_unregister_secure(&fake); +} +module_exit(smaf_fakesecure_deinit); + +MODULE_DESCRIPTION("SMAF fake secure module for test purpose"); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Benjamin Gaignard ");