[FOSS_TLK]security: tlk_driver: add daemon recovery support master
Scott Long [Thu, 26 Mar 2015 00:22:45 +0000 (17:22 -0700)]
If the file system daemon dies we need to fail any intermediate
storage requests while waiting for it to restart.

Change-Id: Ic675a571fab31989869760aba0a8da0ef70c940f
Signed-off-by: Scott Long <scottl@nvidia.com>
Reviewed-on: http://git-master/r/755014
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Varun Wadekar <vwadekar@nvidia.com>
Tested-by: Varun Wadekar <vwadekar@nvidia.com>

security/tlk_driver/ote_comms.c
security/tlk_driver/ote_device.c
security/tlk_driver/ote_fs.c
security/tlk_driver/ote_protocol.h

index 9d353a8..5bf22a6 100644 (file)
@@ -313,6 +313,7 @@ struct tlk_smc_work_args {
 static long tlk_generic_smc_on_cpu0(void *args)
 {
        struct tlk_smc_work_args *work;
+       int callback_status = 0;
        uint32_t retval;
 
        work = (struct tlk_smc_work_args *)args;
@@ -321,8 +322,8 @@ static long tlk_generic_smc_on_cpu0(void *args)
        while (retval == TE_ERROR_PREEMPT_BY_IRQ ||
               retval == TE_ERROR_PREEMPT_BY_FS) {
                if (retval == TE_ERROR_PREEMPT_BY_FS)
-                       tlk_ss_op();
-               retval = _tlk_generic_smc(TE_SMC_RESTART, 0, 0);
+                       callback_status = tlk_ss_op();
+               retval = _tlk_generic_smc(TE_SMC_RESTART, callback_status, 0);
        }
 
        /* Print TLK logs if any */
index d0a4d79..ded08cb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014 NVIDIA Corporation. All rights reserved.
+ * Copyright (c) 2013-2015 NVIDIA Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -242,7 +242,9 @@ static int tlk_device_release(struct inode *inode, struct file *file)
        struct tlk_context *context = file->private_data;
 
        /* close any open sessions */
+       mutex_lock(&smc_lock);
        te_close_sessions(context);
+       mutex_unlock(&smc_lock);
 
        kfree(file->private_data);
        file->private_data = NULL;
index 1c83878..4a0ec2d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014 NVIDIA Corporation. All rights reserved.
+ * Copyright (c) 2013-2015 NVIDIA Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,6 +32,13 @@ static DECLARE_COMPLETION(req_complete);
 
 static struct te_ss_op *ss_op_shmem;
 
+static void tlk_ss_reset(void)
+{
+       /* reset completion vars to default state */
+       INIT_COMPLETION(req_ready);
+       INIT_COMPLETION(req_complete);
+}
+
 int te_handle_ss_ioctl(struct file *file, unsigned int ioctl_num,
        unsigned long ioctl_param)
 {
@@ -64,13 +71,20 @@ int te_handle_ss_ioctl(struct file *file, unsigned int ioctl_num,
        return 0;
 }
 
-void tlk_ss_op(void)
+int tlk_ss_op(void)
 {
        /* signal consumer */
        complete(&req_ready);
 
        /* wait for the consumer's signal */
-       wait_for_completion(&req_complete);
+       if (!wait_for_completion_timeout(&req_complete,
+                                               msecs_to_jiffies(5000))) {
+               /* daemon didn't respond */
+               tlk_ss_reset();
+               return OTE_ERROR_CANCEL;
+       }
+
+       return OTE_SUCCESS;
 }
 
 static int __init tlk_ss_init(void)
index 4cdba76..22e6a24 100644 (file)
@@ -249,7 +249,7 @@ enum ta_event_id {
 int te_handle_ss_ioctl(struct file *file, unsigned int ioctl_num,
                unsigned long ioctl_param);
 void ote_print_logs(void);
-void tlk_ss_op(void);
+int tlk_ss_op(void);
 int ote_property_is_disabled(const char *str);
 
 #endif