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: 8351441 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C1E9A9F38B for ; Thu, 18 Feb 2016 15:06:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E245420254 for ; Thu, 18 Feb 2016 15:06:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DD1C9201EF for ; Thu, 18 Feb 2016 15:06:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946635AbcBRPGv (ORCPT ); Thu, 18 Feb 2016 10:06:51 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:35689 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1946607AbcBRPGe (ORCPT ); Thu, 18 Feb 2016 10:06:34 -0500 Received: by mail-wm0-f44.google.com with SMTP id c200so32127724wme.0 for ; Thu, 18 Feb 2016 07:06:33 -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=dOrwDrln/zTokIoMU65jYrWt9C8rRnJAggLHWyGSfZV8U0cPYsuI0W5skN3xUnkEA4 9Lg+6CmS1vjUcQ+gAWEsiJpgBY0tW7fgcsdo4yegTeOJWqtyWfxnBDS3Vzl4YhSWCVOX P5tZhrF7WWYZ5QM4EgbHN67pFjsBM4i449RGAUm4u7vHzYqvIYnhEQSa25zx3YYoxLkF G8ZT8o5Vh4kFuCc57cuq0I6dQjM61W4WN9u5uaKeQThPOTp1xgnqvBsT7wyvzOTs2yNX 0hgjGDS90SrXJMRv5doonsxSCIq1QY2dpWAV1tFtDhW5PFjHxXRGZcIGyv/pEZEycbvT swZQ== X-Gm-Message-State: AG10YORMggB5q3jXohDJXjfSC4Z3FzciEUmyAJhBX6NSCF+lGB1XKFn80WprQ+wEeZ+5kH9w 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 Cc: "benjamin.gaignard@linaro.org" 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> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 ");