Skip to content

Commit

Permalink
N770FXXU9HWI2
Browse files Browse the repository at this point in the history
* Skip security FIVE/DEFEX/DSMS/MZ/PROCA

* Skip sensorhub patch files
  • Loading branch information
ananjaser1211 committed Dec 16, 2023
1 parent 885e3b2 commit c346445
Show file tree
Hide file tree
Showing 20 changed files with 424 additions and 84 deletions.
140 changes: 97 additions & 43 deletions drivers/char/hw_random/exyswd-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ static int hwrng_disabled;
#endif
static int start_up_test;

atomic_t hwrng_suspend_flag;
atomic_t hwrng_running_flag;

/* Protects exyswd read functions */
static DEFINE_SPINLOCK(rng_running_lock);

#ifdef CONFIG_EXYRNG_DEBUG
#define exyrng_debug(args...) printk(KERN_INFO args)
#else
Expand All @@ -64,8 +70,33 @@ void exynos_swd_test_fail(void)
#endif
}

static int exynos_cm_smc(uint64_t *arg0, uint64_t *arg1,
uint64_t *arg2, uint64_t *arg3)
{
register uint64_t reg0 __asm__("x0") = *arg0;
register uint64_t reg1 __asm__("x1") = *arg1;
register uint64_t reg2 __asm__("x2") = *arg2;
register uint64_t reg3 __asm__("x3") = *arg3;

__asm__ volatile (
"smc 0\n"
: "+r"(reg0), "+r"(reg1), "+r"(reg2), "+r"(reg3)
);

*arg0 = reg0;
*arg1 = reg1;
*arg2 = reg2;
*arg3 = reg3;

return *arg0;
}

static int exynos_swd_startup_test(void)
{
uint64_t reg0;
uint64_t reg1;
uint64_t reg2;
uint64_t reg3;
uint32_t start_up_size;
uint32_t retry_cnt;
uint32_t test_cnt;
Expand All @@ -76,7 +107,12 @@ static int exynos_swd_startup_test(void)
retry_cnt = 0;
test_cnt = 1;
while (start_up_size) {
ret = exynos_smc(SMC_CMD_RANDOM, HWRNG_GET_DATA, 1, 0);
reg0 = SMC_CMD_RANDOM;
reg1 = HWRNG_GET_DATA;
reg2 = 1;
reg3 = 0;

ret = exynos_cm_smc(&reg0, &reg1, &reg2, &reg3);
if (ret == HWRNG_RET_RETRY_ERROR) {
if (retry_cnt++ > EXYRNG_RETRY_MAX_COUNT) {
printk("[ExyRNG] exceed retry in start-up test\n");
Expand Down Expand Up @@ -128,33 +164,42 @@ static int exynos_swd_startup_test(void)

static int exynos_swd_read(struct hwrng *rng, void *data, size_t max, bool wait)
{
uint64_t reg0;
uint64_t reg1;
uint64_t reg2;
uint64_t reg3;
uint32_t *read_buf = data;
uint32_t read_size = max;
uint32_t r_data[2];
unsigned long flag;
unsigned long running_flag;
uint32_t retry_cnt;
int ret = HWRNG_RET_OK;

register u64 reg0 __asm__("x0");
register u64 reg1 __asm__("x1");
register u64 reg2 __asm__("x2");
register u64 reg3 __asm__("x3");

#if defined(CONFIG_EXYRNG_FAIL_POLICY_DISABLE)
if (hwrng_disabled)
return -EPERM;
#endif
spin_lock_irqsave(&rng_running_lock, running_flag);
if (atomic_read(&hwrng_suspend_flag) == 1) {
atomic_set(&hwrng_running_flag, 0);
spin_unlock_irqrestore(&rng_running_lock, running_flag);
printk("[ExyRNG] exynos_swd_read is failed because of suspend flag\n");
return -EFAULT;
}

reg0 = 0;
reg1 = 0;
reg2 = 0;
reg3 = 0;
atomic_set(&hwrng_running_flag, 1);
spin_unlock_irqrestore(&rng_running_lock, running_flag);

retry_cnt = 0;
do {
spin_lock_irqsave(&hwrandom_lock, flag);
if (hwrng_read_flag == 0) {
ret = exynos_smc(SMC_CMD_RANDOM, HWRNG_INIT, 0, 0);
reg0 = SMC_CMD_RANDOM;
reg1 = HWRNG_INIT;
reg2 = 0;
reg3 = 0;

ret = exynos_cm_smc(&reg0, &reg1, &reg2, &reg3);
if (ret == HWRNG_RET_OK)
hwrng_read_flag = 1;
spin_unlock_irqrestore(&hwrandom_lock, flag);
Expand All @@ -177,7 +222,8 @@ static int exynos_swd_read(struct hwrng *rng, void *data, size_t max, bool wait)
} while (ret == HWRNG_RET_RETRY_ERROR);
if (ret != HWRNG_RET_OK) {
msleep(1);
return -EFAULT;
ret = -EFAULT;
goto err;
}

if (start_up_test) {
Expand All @@ -192,13 +238,14 @@ static int exynos_swd_read(struct hwrng *rng, void *data, size_t max, bool wait)
retry_cnt = 0;
while (read_size) {
spin_lock_irqsave(&hwrandom_lock, flag);
ret = __exynos_smc(SMC_CMD_RANDOM, HWRNG_GET_DATA, 0, 0);
__asm__ volatile(
"\t"
: "+r"(reg0), "+r"(reg1), "+r"(reg2), "+r"(reg3)
);
r_data[0] = (uint32_t)reg2;
r_data[1] = (uint32_t)reg3;

reg0 = SMC_CMD_RANDOM;
reg1 = HWRNG_GET_DATA;
reg2 = 0;
reg3 = 0;

ret = exynos_cm_smc(&reg0, &reg1, &reg2, &reg3);

spin_unlock_irqrestore(&hwrandom_lock, flag);

if (ret == HWRNG_RET_RETRY_ERROR) {
Expand All @@ -222,8 +269,8 @@ static int exynos_swd_read(struct hwrng *rng, void *data, size_t max, bool wait)
goto out;
}

*(uint32_t*)(read_buf++) = r_data[0];
*(uint32_t*)(read_buf++) = r_data[1];
*(uint32_t*)(read_buf++) = (uint32_t)reg2;
*(uint32_t*)(read_buf++) = (uint32_t)reg3;

read_size -= 8;
retry_cnt = 0;
Expand All @@ -235,7 +282,13 @@ static int exynos_swd_read(struct hwrng *rng, void *data, size_t max, bool wait)
retry_cnt = 0;
do {
spin_lock_irqsave(&hwrandom_lock, flag);
if (!exynos_smc(SMC_CMD_RANDOM, HWRNG_EXIT, 0, 0)) {

reg0 = SMC_CMD_RANDOM;
reg1 = HWRNG_EXIT;
reg2 = 0;
reg3 = 0;

if (!exynos_cm_smc(&reg0, &reg1, &reg2, &reg3)) {
hwrng_read_flag = 0;
spin_unlock_irqrestore(&hwrandom_lock, flag);
break;
Expand All @@ -249,6 +302,11 @@ static int exynos_swd_read(struct hwrng *rng, void *data, size_t max, bool wait)
usleep_range(50, 100);
} while(1);

err:
spin_lock_irqsave(&rng_running_lock, running_flag);
atomic_set(&hwrng_running_flag, 0);
spin_unlock_irqrestore(&rng_running_lock, running_flag);

return ret;
}

Expand All @@ -265,6 +323,9 @@ static int exyswd_rng_probe(struct platform_device *pdev)
start_up_test = 1;
#endif

atomic_set(&hwrng_suspend_flag, 0);
atomic_set(&hwrng_running_flag, 0);

ret = hwrng_register(&rng);
if (ret)
return ret;
Expand All @@ -287,36 +348,29 @@ static int exyswd_rng_suspend(struct device *dev)
unsigned long flag;
int ret = HWRNG_RET_OK;

spin_lock_irqsave(&hwrandom_lock, flag);
if (hwrng_read_flag) {
ret = exynos_smc(SMC_CMD_RANDOM, HWRNG_EXIT, 0, 0);
if (ret != HWRNG_RET_OK)
printk("[ExyRNG] failed to enter suspend with %d\n", ret);
spin_lock_irqsave(&rng_running_lock, flag);
if (atomic_read(&hwrng_running_flag) == 1) {
printk("[ExyRNG] exyswd_rng_suspend: hwrng_running_flag is 1.\n");
ret = -EFAULT;
goto out;
}
spin_unlock_irqrestore(&hwrandom_lock, flag);

atomic_set(&hwrng_suspend_flag, 1);
out:
spin_unlock_irqrestore(&rng_running_lock, flag);

return ret;
}

static int exyswd_rng_resume(struct device *dev)
{
unsigned long flag;
int ret = HWRNG_RET_OK;

spin_lock_irqsave(&hwrandom_lock, flag);
#if defined(CONFIG_EXYRNG_FIPS_COMPLIANCE)
ret = exynos_smc(SMC_CMD_RANDOM, HWRNG_RESUME, 0, 0);
if (ret != HWRNG_RET_OK)
printk("[ExyRNG] failed to resume with %d\n", ret);
#endif
if (hwrng_read_flag) {
ret = exynos_smc(SMC_CMD_RANDOM, HWRNG_INIT, 0, 0);
if (ret != HWRNG_RET_OK)
printk("[ExyRNG] failed to resume with %d\n", ret);
}
spin_unlock_irqrestore(&hwrandom_lock, flag);
spin_lock_irqsave(&rng_running_lock, flag);
atomic_set(&hwrng_suspend_flag, 0);
spin_unlock_irqrestore(&rng_running_lock, flag);

return ret;
return HWRNG_RET_OK;
}
#endif

Expand Down
22 changes: 18 additions & 4 deletions drivers/gpu/arm/bv_r26p0/mali_kbase_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ int kbase_remove_va_region(struct kbase_va_region *reg)
struct rb_node *rbnext;
struct kbase_va_region *next = NULL;
struct rb_root *reg_rbtree = NULL;
struct kbase_va_region *orig_reg = reg;

int merged_front = 0;
int merged_back = 0;
Expand Down Expand Up @@ -422,6 +423,12 @@ int kbase_remove_va_region(struct kbase_va_region *reg)
}
rb_replace_node(&(reg->rblink), &(free_reg->rblink), reg_rbtree);
}
/* This operation is always safe because the function never frees
* the region. If the region has been merged to both front and back,
* then it's the previous region that is supposed to be freed.
*/
orig_reg->start_pfn = 0;


out:
return err;
Expand Down Expand Up @@ -1453,7 +1460,7 @@ int kbase_gpu_mmap(struct kbase_context *kctx, struct kbase_va_region *reg,
kctx->as_nr,
group_id, mmu_sync_info);
if (err)
goto bad_insert;
goto bad_aliased_insert;

/* Note: mapping count is tracked at alias
* creation time
Expand All @@ -1468,7 +1475,7 @@ int kbase_gpu_mmap(struct kbase_context *kctx, struct kbase_va_region *reg,


if (err)
goto bad_insert;
goto bad_aliased_insert;
}
}
} else {
Expand Down Expand Up @@ -1512,9 +1519,16 @@ int kbase_gpu_mmap(struct kbase_context *kctx, struct kbase_va_region *reg,

return err;

bad_aliased_insert:
while (i-- > 0) {

kbase_mmu_teardown_pages(kctx->kbdev, &kctx->mmu, reg->start_pfn, alloc->pages,
reg->nr_pages, kctx->as_nr);

}


bad_insert:
kbase_mmu_teardown_pages(kctx->kbdev, &kctx->mmu, reg->start_pfn, alloc->pages,
reg->nr_pages, kctx->as_nr);

kbase_remove_va_region(reg);

Expand Down
15 changes: 11 additions & 4 deletions drivers/gpu/arm/bv_r26p0/mali_kbase_sync_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,14 @@ int kbase_sync_fence_out_create(struct kbase_jd_atom *katom, int tl_fd)
fd = get_unused_fd_flags(O_RDWR | O_CLOEXEC);
if (fd < 0) {
sync_fence_put(fence);
katom->fence = NULL;
goto out;
}
#else
fd = get_unused_fd();
if (fd < 0) {
sync_fence_put(fence);
katom->fence = NULL;
goto out;
}

Expand All @@ -283,13 +285,18 @@ int kbase_sync_fence_out_create(struct kbase_jd_atom *katom, int tl_fd)
spin_unlock(&files->file_lock);
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0) */

/* Take an extra reference count on the created fence file */
get_file(fence->file);
/* bind fence to the new fd */
sync_fence_install(fence, fd);

katom->fence = sync_fence_fdget(fd);
if (katom->fence == NULL) {
/* The only way the fence can be NULL is if userspace closed it
* for us, so we don't need to clear it up */
/* Drop the extra reference count */
fput(fence->file);

if (katom->fence != fence) {
if (katom->fence)
sync_fence_put(katom->fence);
katom->fence = NULL;
fd = -EINVAL;
goto out;
}
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/arm/bv_r26p0/tl/mali_kbase_timeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ int kbase_timeline_io_acquire(struct kbase_device *kbdev, u32 flags)

if (!atomic_cmpxchg(timeline->timeline_flags, 0, timeline_flags)) {
int rcode;
if (!timeline_is_permitted())
return -EPERM;

ret = anon_inode_getfd(
"[mali_tlstream]",
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/arm/bv_r26p0/tl/mali_kbase_timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,6 @@ void kbase_timeline_test(
void kbase_timeline_stats(struct kbase_timeline *timeline, u32 *bytes_collected, u32 *bytes_generated);
#endif /* MALI_UNIT_TEST */

bool timeline_is_permitted(void);

#endif /* _KBASE_TIMELINE_H */
Loading

0 comments on commit c346445

Please sign in to comment.