/*
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *
 * Sensitive Data Protection
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/kthread.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/mutex.h>
#include <linux/swap.h>
#include <linux/pagemap.h>

#include "ecryptfs_kernel.h"
#include "ecryptfs_dek.h"

//extern spinlock_t inode_sb_list_lock;
static int ecryptfs_mm_debug = 0;
DEFINE_MUTEX(ecryptfs_mm_mutex);

struct ecryptfs_mm_drop_cache_param {
	int user_id;
    int engine_id;
};

#define INVALIDATE_MAPPING_RETRY_CNT 3

static unsigned long invalidate_mapping_pages_retry(struct address_space *mapping,
		pgoff_t start, pgoff_t end, int retries) {
	unsigned long ret;

	if(ecryptfs_mm_debug)
		printk("freeing [%s] sensitive inode[mapped pagenum = %lu]\n",
				mapping->host->i_sb->s_type->name,
				mapping->nrpages);
retry:
	ret = invalidate_mapping_pages(mapping, start, end);
	if(ecryptfs_mm_debug)
		printk("invalidate_mapping_pages ret = %lu, [%lu] remained\n",
				ret, mapping->nrpages);

	if(mapping->nrpages != 0) {
		if(retries > 0) {
			printk("[%lu] mapped pages remained in sensitive inode, retry..\n",
					mapping->nrpages);
			retries--;
			msleep(100);
			goto retry;
		}
	}

	return ret;
}

#if defined(CONFIG_FMP_ECRYPT_FS) || defined(CONFIG_MMC_DW_FMP_ECRYPT_FS) || defined(CONFIG_UFS_FMP_ECRYPT_FS)
static unsigned long invalidate_lower_mapping_pages_retry(struct file *lower_file, int retries) {

	unsigned long ret, invalidated = 0;
	struct address_space *mapping;

	mapping = lower_file->f_mapping;

	if(ecryptfs_mm_debug)
		printk("%s:freeing [%s] sensitive inode[mapped pagenum = %lu]\n",__func__,
				mapping->host->i_sb->s_type->name,mapping->nrpages);

	for (; retries > 0; retries--) {

		// !! TODO !!
		//if (lower_file && lower_file->f_op && lower_file->f_op->unlocked_ioctl)
		//	ret = lower_file->f_op->unlocked_ioctl(lower_file, FS_IOC_INVAL_MAPPING, 0);
		ret = do_vfs_ioctl(lower_file,0, FS_IOC_INVAL_MAPPING, 0); // lower_file is sdcardfs file
		invalidated += ret;

		if(ecryptfs_mm_debug)
			printk("invalidate_mapping_pages ret = %lu, [%lu] remained\n",
					ret, mapping->nrpages);

		if (mapping->nrpages == 0)
			break;

		printk("[%lu] mapped pages remained in sensitive inode, retry..\n",
				mapping->nrpages);
		msleep(100);
	} 
	return invalidated;
}
#endif

void ecryptfs_mm_do_sdp_cleanup(struct inode *inode) {
	struct ecryptfs_crypt_stat *crypt_stat;
	struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
	struct ecryptfs_inode_info *inode_info;

	crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
	mount_crypt_stat = &ecryptfs_superblock_to_private(inode->i_sb)->mount_crypt_stat;
	inode_info = ecryptfs_inode_to_private(inode);

	if(crypt_stat->flags & ECRYPTFS_DEK_IS_SENSITIVE) {
		int rc;
		if(S_ISDIR(inode->i_mode)) {
			DEK_LOGD("%s: inode: %p is dir, return\n",__func__, inode);
			return;
		}

		DEK_LOGD("%s: inode: %p  clean up start\n",__func__, inode);
		rc = vfs_fsync(inode_info->lower_file, 0);
		if(rc)
			DEK_LOGE("%s: vfs_sync returned error rc: %d\n", __func__, rc);

		if(ecryptfs_is_sdp_locked(crypt_stat->engine_id)) {
			DEK_LOGD("%s: persona locked inode: %lu useid: %d\n",
			        __func__, inode->i_ino, crypt_stat->engine_id);
			invalidate_mapping_pages_retry(inode->i_mapping, 0, -1, 3);
		}
#if defined(CONFIG_FMP_ECRYPT_FS) || defined(CONFIG_MMC_DW_FMP_ECRYPT_FS) || defined(CONFIG_UFS_FMP_ECRYPT_FS)
		if (mount_crypt_stat->flags & ECRYPTFS_USE_FMP) {
			DEK_LOGD("%s inode: %p calling invalidate_lower_mapping_pages_retry\n",__func__, inode);
			invalidate_lower_mapping_pages_retry(inode_info->lower_file, 3);
		}
#endif
		if(ecryptfs_is_sdp_locked(crypt_stat->engine_id)) {
			ecryptfs_clean_sdp_dek(crypt_stat);
		}
		DEK_LOGD("%s: inode: %p clean up stop\n",__func__, inode);
	}
	return;
}

#ifndef TEMP_SKIP
static unsigned long drop_inode_pagecache(struct inode *inode) {
	int rc = 0;

	spin_lock(&inode->i_lock);
	
	if(ecryptfs_mm_debug)
		printk("%s() cleaning [%s] pages: %lu\n", __func__,
				inode->i_sb->s_type->name,inode->i_mapping->nrpages);

	if ((inode->i_mapping->nrpages == 0)) {
		spin_unlock(&inode->i_lock);
		printk("%s inode having zero nrpages\n", __func__);
		return 0;
	}

	spin_unlock(&inode->i_lock);

	/*
	 * flush mapped dirty pages.
	 */
	rc = filemap_write_and_wait(inode->i_mapping);
	if(rc)
		printk("filemap_flush failed, rc=%d\n", rc);

	if (inode->i_mapping->nrpages != 0)
		lru_add_drain_all();

	rc = invalidate_mapping_pages_retry(inode->i_mapping, 0, -1,
			INVALIDATE_MAPPING_RETRY_CNT);

	if(inode->i_mapping->nrpages)
			printk("%s() uncleaned [%s] pages: %lu\n", __func__,
					inode->i_sb->s_type->name,inode->i_mapping->nrpages);

	return rc;
}
#endif

#ifndef TEMP_SKIP
static void ecryptfs_mm_drop_pagecache(struct super_block *sb, void *arg)
{
	struct inode *inode;
	struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
	struct ecryptfs_mm_drop_cache_param *param = arg;
	
	if(strcmp("ecryptfs", sb->s_type->name)) {
		printk("%s sb:%s is not ecryptfs superblock\n", __func__,
				sb->s_type->name);
		return;
	}
	
	mount_crypt_stat = &ecryptfs_superblock_to_private(sb)->mount_crypt_stat;
	
	printk("%s start() sb:%s [%d], userid:%d\n", __func__,
			sb->s_type->name, mount_crypt_stat->userid, param->user_id);
	
	if (param->user_id >= 100 && param->user_id < 200) {
		if(mount_crypt_stat->userid != param->user_id)
			return;
	}
	
	//spin_lock(&inode_sb_list_lock);
	spin_lock(&sb->s_inode_list_lock);
	list_for_each_entry(inode, &sb->s_inodes, i_sb_list)
	{	
        struct ecryptfs_crypt_stat *crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;

        if(crypt_stat == NULL)
            continue;

        if(crypt_stat->engine_id != param->engine_id) {
			continue;
		}

		if (!inode->i_mapping) {
			continue;
		}
		
		spin_lock(&inode->i_lock);
		if (inode->i_mapping->nrpages == 0) {
			spin_unlock(&inode->i_lock);
			spin_unlock(&sb->s_inode_list_lock);
			
			if(ecryptfs_mm_debug)
				printk("%s() ecryptfs inode [ino:%lu]\n",__func__, inode->i_ino);
				
			if((crypt_stat->flags & ECRYPTFS_DEK_IS_SENSITIVE) &&
					!atomic_read(&ecryptfs_inode_to_private(inode)->lower_file_count))
				ecryptfs_clean_sdp_dek(crypt_stat);

			spin_lock(&sb->s_inode_list_lock);
			continue;
		}
		spin_unlock(&inode->i_lock);

		//spin_unlock(&inode_sb_list_lock);
		spin_unlock(&sb->s_inode_list_lock);

		if(ecryptfs_mm_debug)
			printk(KERN_ERR "inode number: %lu i_mapping: %p [%s] userid:%d\n",inode->i_ino,
					inode->i_mapping,inode->i_sb->s_type->name,inode->i_mapping->userid);

		if(mapping_sensitive(inode->i_mapping) &&
				!atomic_read(&ecryptfs_inode_to_private(inode)->lower_file_count)) {
			drop_inode_pagecache(inode);
				
			if(ecryptfs_mm_debug)
					printk(KERN_ERR "lower inode: %p lower inode: %p nrpages: %lu\n",ecryptfs_inode_to_lower(inode),
							ecryptfs_inode_to_private(inode), ecryptfs_inode_to_lower(inode)->i_mapping->nrpages);
			
			if(crypt_stat->flags & ECRYPTFS_DEK_IS_SENSITIVE)
				ecryptfs_clean_sdp_dek(crypt_stat);	
		}
		//spin_lock(&inode_sb_list_lock);
		spin_lock(&sb->s_inode_list_lock);
	}
	//spin_unlock(&inode_sb_list_lock);
	spin_unlock(&sb->s_inode_list_lock);
}
#endif

static int ecryptfs_mm_task(void *arg)
{
#ifndef TEMP_SKIP
	struct file_system_type *type;
	struct ecryptfs_mm_drop_cache_param *param = arg;
	
	type = get_fs_type("ecryptfs");
	
	if(type) {
		if(ecryptfs_mm_debug)
			printk("%s type name: %s flags: %d\n", __func__, type->name, type->fs_flags);
		
		mutex_lock(&ecryptfs_mm_mutex);
		iterate_supers_type(type,ecryptfs_mm_drop_pagecache, param);
		mutex_unlock(&ecryptfs_mm_mutex);
		
		put_filesystem(type);
	}
	
	kfree(param);
#endif
	return 0;
}

void ecryptfs_mm_drop_cache(int userid, int engineid) {
#ifndef TEMP_SKIP
	struct task_struct *task;
	struct ecryptfs_mm_drop_cache_param *param =
			kzalloc(sizeof(*param), GFP_KERNEL);

	if (!param) {
		printk("%s :: skip. no memory to alloc param\n", __func__);
		return;
	}
    param->user_id = userid;
    param->engine_id = engineid;

	printk("running cache cleanup thread - sdp-id : %d\n", userid);
	task = kthread_run(ecryptfs_mm_task, param, "sdp_cached");

	if (IS_ERR(task)) {
		printk(KERN_ERR "SDP : unable to create kernel thread: %ld\n",
				PTR_ERR(task));
	}
#else
	//Temporal for other DreamQ testing
	printk("running cache cleanup - userid : %d\n", userid);
	ecryptfs_mm_task(&userid);
#endif
}

#include <linux/pagevec.h>
#include <linux/pagemap.h>
#include <linux/memcontrol.h>
#include <linux/atomic.h>

static void __page_dump(unsigned char *buf, int len, const char* str)
{
	unsigned int     i;
	char	s[512];

	s[0] = 0;
	for(i=0;i<len && i<16;++i) {
		char tmp[8];
		sprintf(tmp, " %02x", buf[i]);
		strcat(s, tmp);
	}

	if (len > 16) {
		char tmp[8];
		sprintf(tmp, " ...");
		strcat(s, tmp);
	}

	DEK_LOGD("%s [%s len=%d]\n", s, str, len);
}

#ifdef DEK_DEBUG
/*
 * This dump will appear in ramdump
 */
void page_dump (struct page *p) {
	void *d;
	d = kmap_atomic(p);
	if(d) {
		__page_dump((unsigned char *)d, PAGE_SIZE, "freeing");
		kunmap_atomic(d);
	}
}
#else
void page_dump (struct page *p) {
	// Do nothing
}
#endif
