From patchwork Wed Oct 21 09:22:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 55351 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id C37EB23024 for ; Wed, 21 Oct 2015 09:22:53 +0000 (UTC) Received: by lbcao8 with SMTP id ao8sf15293777lbc.1 for ; Wed, 21 Oct 2015 02:22:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:subject:date :message-id:in-reply-to:references:cc:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=xw4OoaHI6qTt1icJK96gWNqIQsWdteYGUwmgx2zkoWY=; b=YlhSlju3gm9uH/gVwOsCboMqCvZypoD7DIo/ngbgR0GFklPFtLVuyUP5yNUMBD4BhV lpsvula82/KcCPgeLkLPwoENi707HiI9KIJTDDSuS/Zdcih4zq9jA0YNhku5R2VlkK/n S6eo0kl6vo9/fkXTlgRg1dm5tJ9x+BUkp6ipxwQe7mtLLdvJFxt8O2A4I0sJ3Y0NYomQ MPF5+h1zQmh0KSu6uRLHfWjzq1CPg4foMyG8Voyb+UF2roNLUegsDS5+r1M5ZgDlZHGD ozAudv1mBt2Dj0b4qaFx+zRvu4N1B4iHTuSJJWRW9iotMa3zM12QDmX058GieQjC61UU EL9g== X-Gm-Message-State: ALoCoQl+/tyoKBbViRyB3rtAd5c+sKA7qQr90dDuqCAq6g6aPMbXKzU3fft8gT1/8zUJHrUwCQK9 X-Received: by 10.194.109.233 with SMTP id hv9mr1872905wjb.1.1445419372733; Wed, 21 Oct 2015 02:22:52 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.213.66 with SMTP id m63ls170203lfg.102.gmail; Wed, 21 Oct 2015 02:22:52 -0700 (PDT) X-Received: by 10.25.15.163 with SMTP id 35mr2960682lfp.98.1445419372581; Wed, 21 Oct 2015 02:22:52 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id e141si5657052lfe.84.2015.10.21.02.22.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Oct 2015 02:22:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbes7 with SMTP id es7so33818334lbb.2 for ; Wed, 21 Oct 2015 02:22:52 -0700 (PDT) X-Received: by 10.112.129.202 with SMTP id ny10mr4470227lbb.112.1445419372424; Wed, 21 Oct 2015 02:22:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2569817lbq; Wed, 21 Oct 2015 02:22:51 -0700 (PDT) X-Received: by 10.66.189.232 with SMTP id gl8mr9619044pac.52.1445419367282; Wed, 21 Oct 2015 02:22:47 -0700 (PDT) Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id if3si11978741pbc.192.2015.10.21.02.22.47; Wed, 21 Oct 2015 02:22:47 -0700 (PDT) Received-SPF: pass (google.com: domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2A8886ED8B; Wed, 21 Oct 2015 02:22:46 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by gabe.freedesktop.org (Postfix) with ESMTPS id E4F986ED88 for ; Wed, 21 Oct 2015 02:22:42 -0700 (PDT) Received: by wicfx6 with SMTP id fx6so81884317wic.1 for ; Wed, 21 Oct 2015 02:22:41 -0700 (PDT) X-Received: by 10.180.198.233 with SMTP id jf9mr27516651wic.66.1445419361433; Wed, 21 Oct 2015 02:22:41 -0700 (PDT) Received: from LMENX321.lme.st.com (LPuteaux-656-1-48-212.w82-127.abo.wanadoo.fr. [82.127.83.212]) by smtp.gmail.com with ESMTPSA id z4sm9119481wjz.29.2015.10.21.02.22.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Oct 2015 02:22:40 -0700 (PDT) From: Benjamin Gaignard To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, daniel.vetter@ffwll.ch, robdclark@gmail.com, treding@nvidia.com, sumit.semwal@linaro.org, tom.cooksey@arm.com, daniel.stone@collabora.com, linux-security-module@vger.kernel.org, xiaoquan.li@vivantecorp.com, labbott@redhat.com Subject: [PATCH v5 3/3] SMAF: add fake secure module Date: Wed, 21 Oct 2015 11:22:20 +0200 Message-Id: <1445419340-11471-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445419340-11471-1-git-send-email-benjamin.gaignard@linaro.org> References: <1445419340-11471-1-git-send-email-benjamin.gaignard@linaro.org> Cc: linaro-mm-sig@lists.linaro.org, Benjamin Gaignard , tom.gall@linaro.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: benjamin.gaignard@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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 05bab01..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 ");