From 96287e1d14048630f4d5fc37031504c1297d111b Mon Sep 17 00:00:00 2001 From: Kalpak Kawadkar Date: Thu, 5 Jan 2023 16:35:27 +0530 Subject: [PATCH 01/14] clk: qcom: Enable ftrace for clock frequency measurement Enable ftrace support for clocks so that clients can measure frequency of the clock through ftraces. Change-Id: Ie923ac538b670598bb1be009e892a68c4f1e2a38 Signed-off-by: Kalpak Kawadkar --- drivers/clk/qcom/clk-debug.c | 6 +++++ drivers/clk/qcom/trace.h | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 drivers/clk/qcom/trace.h diff --git a/drivers/clk/qcom/clk-debug.c b/drivers/clk/qcom/clk-debug.c index aa7855596430..8c7f9d38de7b 100644 --- a/drivers/clk/qcom/clk-debug.c +++ b/drivers/clk/qcom/clk-debug.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2016, 2019-2021 The Linux Foundation. All rights reserved. */ +/* Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved. */ #include #include @@ -11,6 +12,10 @@ #include #include #include +#include + +#define CREATE_TRACE_POINTS +#include "trace.h" #include "clk-regmap.h" #include "clk-debug.h" @@ -271,6 +276,7 @@ static int clk_debug_measure_get(void *data, u64 *val) enable_debug_clks(measure); *val = clk_debug_mux_measure_rate(measure); + trace_clk_measure(clk_hw_get_name(hw), *val); /* recursively calculate actual freq */ *val *= get_mux_divs(measure); disable_debug_clks(measure); diff --git a/drivers/clk/qcom/trace.h b/drivers/clk/qcom/trace.h new file mode 100644 index 000000000000..93ed76187352 --- /dev/null +++ b/drivers/clk/qcom/trace.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-only + * + * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM clk_qcom + +#if !defined(_TRACE_CLOCK_QCOM_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_CLOCK_QCOM + +#include + +DECLARE_EVENT_CLASS(clk_measure_support, + + TP_PROTO(const char *name, unsigned long rate), + + TP_ARGS(name, rate), + + TP_STRUCT__entry( + __string(name, name) + __field(unsigned long, rate) + ), + + TP_fast_assign( + __assign_str(name, name); + __entry->rate = rate; + ), + + TP_printk("%s rate: %lu", + __get_str(name), (unsigned long)__entry->rate) +); + +DEFINE_EVENT(clk_measure_support, clk_measure, + + TP_PROTO(const char *name, unsigned long rate), + + TP_ARGS(name, rate) +); + +#endif /* _TRACE_CLOCK_QCOM */ + +/* This part must be outside protection */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE trace + +#include From 5b284b6c49bf364757cb5d9ea7efa91a3fc79af7 Mon Sep 17 00:00:00 2001 From: Wei Tan Date: Tue, 27 Dec 2022 16:07:19 +0800 Subject: [PATCH 02/14] misc: Add Nordic driver sleep mode support Add HMD nordic driver suspend and sleep mode when standlone or bonded with remote controllers. Change-Id: I0dda7e5d474341f8636b78a07ff70f5a164dd082 Signed-off-by: Wei Tan --- drivers/misc/kxrctrl/aphost.c | 34 +++++++++++++++++++++++++++++++--- drivers/misc/kxrctrl/aphost.h | 1 + 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/misc/kxrctrl/aphost.c b/drivers/misc/kxrctrl/aphost.c index bc6ceebd85ee..92cd21a7c2b6 100644 --- a/drivers/misc/kxrctrl/aphost.c +++ b/drivers/misc/kxrctrl/aphost.c @@ -226,6 +226,10 @@ static ssize_t jsrequest_show(struct device *dev, } else { size = scnprintf(buf, PAGE_SIZE, "no need to ack\n"); } + pinctrl_select_state( + gspi_client->pinctrl_info.pinctrl, + gspi_client->pinctrl_info.active); + gspi_client->js_ledl_state = 0; mutex_unlock(&gspi_client->js_mutex); return size; @@ -244,6 +248,11 @@ static ssize_t jsrequest_store(struct device *dev, return size; } + pinctrl_select_state( + gspi_client->pinctrl_info.pinctrl, + gspi_client->pinctrl_info.suspend); + gspi_client->js_ledl_state = 1; + mutex_lock(&gspi_client->js_mutex); err = kstrtouint(buf, 16, &input); if (err) { @@ -252,9 +261,21 @@ static ssize_t jsrequest_store(struct device *dev, memset(&request, 0, sizeof(request_t)); request.requestHead.requestType = ((input & 0x7f000000) >> 24); - request.requestData[0] = (input & 0x000000ff); - request.requestData[1] = (input & 0x0000ff00); - request.requestData[2] = (input & 0x00ff0000); + if (request.requestHead.requestType == 0xc) { + request.requestData[0] = + (input & 0x000000ff); + request.requestData[1] = + ((input & 0x0000ff00) >> 8); + request.requestData[2] = + ((input & 0x00ff0000) >> 16); + } else { + request.requestData[0] = + (input & 0x000000ff); + request.requestData[1] = + (input & 0x0000ff00); + request.requestData[2] = + (input & 0x00ff0000); + } switch (request.requestHead.requestType) { case setVibStateRequest: @@ -285,6 +306,7 @@ static ssize_t jsrequest_store(struct device *dev, case getRightJoyStickProductNameRequest: case getLeftJoyStickFwVersionRequest: case getRightJoyStickFwVersionRequest: + case setControllerSleepMode: atomic_set(&gspi_client->userRequest, input); atomic_inc(&gspi_client->dataflag); @@ -466,6 +488,12 @@ static int js_thread(void *data) spi_client->txbuffer[2] = (currentRequest.requestData[0]&0x01); break; + case setControllerSleepMode: + spi_client->txbuffer[2] = + currentRequest.requestData[0]; + spi_client->txbuffer[3] = + currentRequest.requestData[1]; + break; default: break; } diff --git a/drivers/misc/kxrctrl/aphost.h b/drivers/misc/kxrctrl/aphost.h index 2d7612fc73f8..cce7927ec512 100644 --- a/drivers/misc/kxrctrl/aphost.h +++ b/drivers/misc/kxrctrl/aphost.h @@ -109,6 +109,7 @@ typedef enum _requestType_t getRightJoyStickProductNameRequest, getLeftJoyStickFwVersionRequest, getRightJoyStickFwVersionRequest, + setControllerSleepMode = 12, invalidRequest, } requestType_t; From 114c9c6cc25b4fd5273cf4993e0a5010972b4092 Mon Sep 17 00:00:00 2001 From: Kalpak Kawadkar Date: Tue, 31 Jan 2023 12:05:23 +0530 Subject: [PATCH 03/14] clk: qcom: clk-debug: Cleanup the tracing code Cleanup the tracing code to print the trace for clk_measure correctly. Change-Id: I66f4382f07fc70fac94f5f478e4467410f72b3e0 Signed-off-by: Kalpak Kawadkar --- drivers/clk/qcom/clk-debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/qcom/clk-debug.c b/drivers/clk/qcom/clk-debug.c index 8c7f9d38de7b..87e60ae9430f 100644 --- a/drivers/clk/qcom/clk-debug.c +++ b/drivers/clk/qcom/clk-debug.c @@ -276,9 +276,10 @@ static int clk_debug_measure_get(void *data, u64 *val) enable_debug_clks(measure); *val = clk_debug_mux_measure_rate(measure); - trace_clk_measure(clk_hw_get_name(hw), *val); /* recursively calculate actual freq */ *val *= get_mux_divs(measure); + /* enable ftrace support */ + trace_clk_measure(clk_hw_get_name(hw), *val); disable_debug_clks(measure); exit: if (meas->bus_cl_id) From 930002f1817b90911085193a9a6d371032c3ece5 Mon Sep 17 00:00:00 2001 From: Kishor Krishna Bhat Date: Thu, 20 Oct 2022 13:27:46 +0530 Subject: [PATCH 04/14] defconfig: msm: Enable dcc in sdm660 config Enable dcc configuration to parse dcc data in dumps to debug crashes. Change-Id: I954696d01ec05f74d6eb38758fc95b4395e7f855 Signed-off-by: Kishor Krishna Bhat --- arch/arm64/configs/vendor/sdm660_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/configs/vendor/sdm660_defconfig b/arch/arm64/configs/vendor/sdm660_defconfig index 4252f63d015c..7a00bc5fcc70 100644 --- a/arch/arm64/configs/vendor/sdm660_defconfig +++ b/arch/arm64/configs/vendor/sdm660_defconfig @@ -623,7 +623,6 @@ CONFIG_MSM_PIL=y CONFIG_MSM_SYSMON_QMI_COMM=y CONFIG_MSM_PIL_SSR_GENERIC=y CONFIG_MSM_BOOT_STATS=y -CONFIG_QCOM_DCC_V2=y CONFIG_QCOM_EUD=y CONFIG_QCOM_MINIDUMP=y CONFIG_MSM_CORE_HANG_DETECT=y @@ -644,6 +643,7 @@ CONFIG_QCOM_SMCINVOKE=y CONFIG_MSM_EVENT_TIMER=y CONFIG_MSM_PM=y CONFIG_QTI_L2_REUSE=y +CONFIG_QCOM_DCC=y CONFIG_QTI_RPM_STATS_LOG=y CONFIG_QTEE_SHM_BRIDGE=y CONFIG_MEM_SHARE_QMI_SERVICE=y From 2eb4c0dd21a13af7d68b445fc67ae694c04c8fd7 Mon Sep 17 00:00:00 2001 From: Vamsi Krishna Gattupalli Date: Thu, 16 Feb 2023 13:01:40 +0530 Subject: [PATCH 05/14] msm: adsprpc: Fix race condition in internal_control Protect add and update qos request with mutex to avoid race condition when multiple threads try to add or update request simultaneously. Change-Id: Id33b81bf85246ec69c72bad59cca068e627bb21d Acked-by: Anand Kulkarni Signed-off-by: Vamsi Krishna Gattupalli --- drivers/char/adsprpc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/char/adsprpc.c b/drivers/char/adsprpc.c index 413614ac4b53..4ad460ce48f0 100644 --- a/drivers/char/adsprpc.c +++ b/drivers/char/adsprpc.c @@ -472,6 +472,7 @@ struct fastrpc_file { struct mutex perf_mutex; struct pm_qos_request pm_qos_req; int qos_request; + struct mutex pm_qos_mutex; struct mutex map_mutex; struct mutex internal_map_mutex; /* Identifies the device (MINOR_NUM_DEV / MINOR_NUM_SECURE_DEV) */ @@ -3859,6 +3860,7 @@ static int fastrpc_file_free(struct fastrpc_file *fl) mutex_destroy(&fl->perf_mutex); mutex_destroy(&fl->map_mutex); mutex_destroy(&fl->internal_map_mutex); + mutex_destroy(&fl->pm_qos_mutex); kfree(fl); return 0; } @@ -4232,6 +4234,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) hlist_add_head(&fl->hn, &me->drivers); spin_unlock(&me->hlock); mutex_init(&fl->perf_mutex); + mutex_init(&fl->pm_qos_mutex); init_completion(&fl->shutdown); return 0; } @@ -4359,12 +4362,14 @@ static int fastrpc_internal_control(struct fastrpc_file *fl, fl->pm_qos_req.type = PM_QOS_REQ_AFFINE_CORES; cpumask_copy(&fl->pm_qos_req.cpus_affine, &mask); + mutex_lock(&fl->pm_qos_mutex); if (!fl->qos_request) { pm_qos_add_request(&fl->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, latency); fl->qos_request = 1; } else pm_qos_update_request(&fl->pm_qos_req, latency); + mutex_unlock(&fl->pm_qos_mutex); /* Ensure CPU feature map updated to DSP for early WakeUp */ fastrpc_send_cpuinfo_to_dsp(fl); From 9968fcdd9d1c853d0c6472307510a81f5db398da Mon Sep 17 00:00:00 2001 From: Kamal Agrawal Date: Mon, 13 Feb 2023 16:51:37 +0530 Subject: [PATCH 06/14] msm: kgsl: Make sure that pool pages don't have any extra references Before putting a page back in the pool be sure that it doesn't have any additional references that would be a signal that somebody else is looking at the page and that it would be a bad idea to keep it around and run the risk of accidentally handing it to a different process. Change-Id: Ic0dedbad0cf2ffb34b76ad23e393c5a911114b82 Signed-off-by: Jordan Crouse Signed-off-by: Kamal Agrawal --- drivers/gpu/msm/kgsl_pool.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/msm/kgsl_pool.c b/drivers/gpu/msm/kgsl_pool.c index ecb05b9b9a06..b5429cbb12ec 100644 --- a/drivers/gpu/msm/kgsl_pool.c +++ b/drivers/gpu/msm/kgsl_pool.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -61,6 +62,15 @@ _kgsl_get_pool_from_order(unsigned int order) static void _kgsl_pool_add_page(struct kgsl_page_pool *pool, struct page *p) { + /* + * Sanity check to make sure we don't re-pool a page that + * somebody else has a reference to. + */ + if (WARN_ON_ONCE(unlikely(page_count(p) > 1))) { + __free_pages(p, pool->pool_order); + return; + } + kgsl_zero_page(p, pool->pool_order); spin_lock(&pool->list_lock); From 86695e1dd101e71571998281541b0b4378f89414 Mon Sep 17 00:00:00 2001 From: Puranam V G Tejaswi Date: Tue, 14 Feb 2023 16:09:02 +0530 Subject: [PATCH 07/14] msm: kgsl: Use dma_buf_get() to get dma_buf structure Currently we don't ensure if vma->vm_file is associated with dma_buf. This can cause issues later when private_data from a non dma_buf file is used as dma_buf structure. Hence get the fd that is associated with vma->vm_file and use dma_buf_get() to get pointer to dma_buf structure. dma_buf_get() ensures that the file from the input fd is associated with dma_buf. Change-Id: Ib78aef8b16bedca5ca86d3a132278ff9f07dce73 Signed-off-by: Puranam V G Tejaswi --- drivers/gpu/msm/kgsl.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/msm/kgsl.c b/drivers/gpu/msm/kgsl.c index 8e6bb0341cb5..f3c37d7a0670 100644 --- a/drivers/gpu/msm/kgsl.c +++ b/drivers/gpu/msm/kgsl.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved. - * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -2677,6 +2677,15 @@ static int kgsl_setup_anon_useraddr(struct kgsl_pagetable *pagetable, } #ifdef CONFIG_DMA_SHARED_BUFFER +static int match_file(const void *p, struct file *file, unsigned int fd) +{ + /* + * We must return fd + 1 because iterate_fd stops searching on + * non-zero return, but 0 is a valid fd. + */ + return (p == file) ? (fd + 1) : 0; +} + static void _setup_cache_mode(struct kgsl_mem_entry *entry, struct vm_area_struct *vma) { @@ -2714,6 +2723,8 @@ static int kgsl_setup_dmabuf_useraddr(struct kgsl_device *device, vma = find_vma(current->mm, hostptr); if (vma && vma->vm_file) { + int fd; + ret = check_vma_flags(vma, entry->memdesc.flags); if (ret) { up_read(¤t->mm->mmap_sem); @@ -2729,13 +2740,27 @@ static int kgsl_setup_dmabuf_useraddr(struct kgsl_device *device, return -EFAULT; } - /* - * Take a refcount because dma_buf_put() decrements the - * refcount - */ - get_file(vma->vm_file); - - dmabuf = vma->vm_file->private_data; + /* Look for the fd that matches this vma file */ + fd = iterate_fd(current->files, 0, match_file, vma->vm_file); + if (fd) { + dmabuf = dma_buf_get(fd - 1); + if (IS_ERR(dmabuf)) { + up_read(¤t->mm->mmap_sem); + return PTR_ERR(dmabuf); + } + /* + * It is possible that the fd obtained from iterate_fd + * was closed before passing the fd to dma_buf_get(). + * Hence dmabuf returned by dma_buf_get() could be + * different from vma->vm_file->private_data. Return + * failure if this happens. + */ + if (dmabuf != vma->vm_file->private_data) { + dma_buf_put(dmabuf); + up_read(¤t->mm->mmap_sem); + return -EBADF; + } + } } if (IS_ERR_OR_NULL(dmabuf)) { From b6a859ef146211e3ad2208137cc2199865973cad Mon Sep 17 00:00:00 2001 From: Yuvaraj Ranganathan Date: Thu, 2 Feb 2023 15:39:39 +0530 Subject: [PATCH 08/14] fs: crypto: Setting IV_INO_LBLK_32 flag only to F2FS Enable IV_INO_LBLK_32 flag only for F2FS and this flag is not required for ext4 as ext4 uses sector number as IV. Tests: 1. File Based Encryption(FBE) on adb remount and normal reboot. 2. File Based Encryption(FBE) properties are set. Change-Id: Ie3fa6fddf7318410324d6a7da3d89326c1d1c6ff Signed-off-by: Yuvaraj Ranganathan --- fs/crypto/policy.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index 9c9ab664befc..f0af749f5fb3 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -626,12 +626,13 @@ EXPORT_SYMBOL(fscrypt_has_permitted_context); #define SDHCI "sdhci" -static int fscrypt_update_context(union fscrypt_context *ctx) +static int fscrypt_update_context(union fscrypt_context *ctx, + const char *file_system_type) { char *boot = "ufs"; if (!fscrypt_find_storage_type(&boot)) { - if (!strcmp(boot, SDHCI)) + if (!strcmp(boot, SDHCI) && !strcmp(file_system_type, "f2fs")) ctx->v1.flags |= FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32; return 0; } @@ -654,6 +655,7 @@ int fscrypt_inherit_context(struct inode *parent, struct inode *child, int ctxsize; struct fscrypt_info *ci; int res; + const char *file_system_type; res = fscrypt_get_encryption_info(parent); if (res < 0) @@ -663,10 +665,14 @@ int fscrypt_inherit_context(struct inode *parent, struct inode *child, if (ci == NULL) return -ENOKEY; + file_system_type = ci->ci_inode->i_sb->s_type->name; + if (!file_system_type) + return -EINVAL; + ctxsize = fscrypt_new_context_from_policy(&ctx, &ci->ci_policy); if (fscrypt_policy_contents_mode(&ci->ci_policy) == FSCRYPT_MODE_PRIVATE) { - res = fscrypt_update_context(&ctx); + res = fscrypt_update_context(&ctx, file_system_type); if (res) return res; } From 9741fb8b3f5e42937454b56cbc58d5b44f2a3d57 Mon Sep 17 00:00:00 2001 From: Wei Tan Date: Fri, 17 Feb 2023 23:07:02 +0800 Subject: [PATCH 09/14] misc: update nordic DFU function check Internal with two kinds of reference devices; One is the Nordic DFU/OTA supported and the other is DFU/OTA not upported. Add this DFU func to check device type to adjust all test cases. Change-Id: I2ae93fa05eff0e332fad30760efbdde5081f1bd8 Signed-off-by: Wei Tan --- drivers/misc/kxrctrl/aphost.c | 94 +++++++++++++++++++++++++++++++++-- drivers/misc/kxrctrl/aphost.h | 11 +++- 2 files changed, 100 insertions(+), 5 deletions(-) diff --git a/drivers/misc/kxrctrl/aphost.c b/drivers/misc/kxrctrl/aphost.c index 92cd21a7c2b6..ce8254139d91 100644 --- a/drivers/misc/kxrctrl/aphost.c +++ b/drivers/misc/kxrctrl/aphost.c @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * - * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. */ #include "aphost.h" @@ -242,17 +242,36 @@ static ssize_t jsrequest_store(struct device *dev, request_t request; int vibState = 0; int err = 0; - +#ifdef COMPATIBLE_NOT_SUPPORT_DFU + unsigned int getNorVersion = 0; +#endif if (gspi_client == NULL) { pr_err("invalid gspi_client\n"); return size; } +#ifdef COMPATIBLE_NOT_SUPPORT_DFU + getNorVersion = (unsigned int) + atomic_read(&gspi_client->probeGetNordicVersion); + if (getNorVersion <= 0x81000101 && getNorVersion > 0) { + pr_debug("%s DFU not supported version number:%d.%d\n", + __func__, (getNorVersion >> 8) & 0xff, + getNorVersion & 0xff); + } else { + pinctrl_select_state( + gspi_client->pinctrl_info.pinctrl, + gspi_client->pinctrl_info.suspend); + gspi_client->js_ledl_state = 1; + pr_debug("%s DFU supported version number:%d.%d\n", + __func__, (getNorVersion >> 8) & 0xff, + getNorVersion & 0xff); + } +#else pinctrl_select_state( gspi_client->pinctrl_info.pinctrl, gspi_client->pinctrl_info.suspend); gspi_client->js_ledl_state = 1; - +#endif mutex_lock(&gspi_client->js_mutex); err = kstrtouint(buf, 16, &input); if (err) { @@ -529,6 +548,18 @@ static int js_thread(void *data) | spi_client->rxbuffer[1]); atomic_set(&spi_client->nordicAcknowledge, input); +#ifdef COMPATIBLE_NOT_SUPPORT_DFU + if ((unsigned int) + atomic_read( + &gspi_client->probeGetNordicVersionFlag)) { + atomic_set( + &spi_client->probeGetNordicVersion, + input); + atomic_set( + &spi_client->probeGetNordicVersionFlag, + 0); + } +#endif } memset(&lastRequest, 0, sizeof(lastRequest)); } @@ -742,6 +773,59 @@ failed: return ret; } +#ifdef COMPATIBLE_NOT_SUPPORT_DFU +static int probe_get_nordic_version(void) +{ + unsigned int getNorVersion = 0; + + atomic_set(&gspi_client->probeGetNordicVersionFlag, 1); + atomic_set(&gspi_client->userRequest, 0x81000000); + atomic_inc(&gspi_client->dataflag); + wake_up_interruptible(&gspi_client->wait_queue); + pinctrl_select_state( + gspi_client->pinctrl_info.pinctrl, + gspi_client->pinctrl_info.suspend); + gspi_client->js_ledl_state = 1; + while (1) { + if (!((unsigned int) + atomic_read(&gspi_client->probeGetNordicVersionFlag))) { + pr_debug("nordic version flag %d userRequest 0x%x\n", + (unsigned int)atomic_read( + &gspi_client->probeGetNordicVersionFlag), + (unsigned int)atomic_read( + &gspi_client->userRequest)); + getNorVersion = (unsigned int)atomic_read( + &gspi_client->probeGetNordicVersion); + pr_debug("nordic version %d.%d getNorVersion 0x%x\n", + (getNorVersion >> 8) & 0xff, + getNorVersion & 0xff, getNorVersion); + pinctrl_select_state( + gspi_client->pinctrl_info.pinctrl, + gspi_client->pinctrl_info.suspend); + gspi_client->js_ledl_state = 0; + } else { + atomic_set(&gspi_client->probeGetNordicVersionFlag, 1); + atomic_set(&gspi_client->userRequest, 0x81000000); + atomic_inc(&gspi_client->dataflag); + wake_up_interruptible(&gspi_client->wait_queue); + pinctrl_select_state( + gspi_client->pinctrl_info.pinctrl, + gspi_client->pinctrl_info.suspend); + gspi_client->js_ledl_state = 1; + + pr_err("Failed to get version flag %d userRequest 0x%x\n", + (unsigned int)atomic_read( + &gspi_client->probeGetNordicVersionFlag), + (unsigned int)atomic_read( + &gspi_client->userRequest)); + + } + break; + } + + return 0; +} +#endif static int js_spi_setup(struct spi_device *spi) { struct js_spi_client *spi_client; @@ -805,6 +889,10 @@ static int js_spi_setup(struct spi_device *spi) js_io_init(spi_client); js_set_power(1); +#ifdef COMPATIBLE_NOT_SUPPORT_DFU + msleep(5000); + probe_get_nordic_version(); +#endif return rc; spi_free: diff --git a/drivers/misc/kxrctrl/aphost.h b/drivers/misc/kxrctrl/aphost.h index cce7927ec512..e9812a4cc2ad 100644 --- a/drivers/misc/kxrctrl/aphost.h +++ b/drivers/misc/kxrctrl/aphost.h @@ -6,7 +6,7 @@ * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * - * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. */ #ifndef __APHOST_H__ @@ -70,12 +70,13 @@ #include #include #include - +#include #include #define MAX_PACK_SIZE 100 #define MAX_DATA_SIZE 32 //#define MANUL_CONTROL_JOYSTICK_RLED +#define COMPATIBLE_NOT_SUPPORT_DFU #define XFR_SIZE 190 /* Protocol commands to interact with firmware */ @@ -154,6 +155,12 @@ struct js_spi_client { atomic_t dataflag; atomic_t userRequest; /* request from userspace */ atomic_t nordicAcknowledge; /* ack from nordic52832 master */ + +#ifdef COMPATIBLE_NOT_SUPPORT_DFU + atomic_t probeGetNordicVersion; /* ack from nordic52832 master */ + atomic_t probeGetNordicVersionFlag; +#endif + unsigned char JoyStickBondState; /* 1:left JoyStick 2:right JoyStick */ bool suspend; wait_queue_head_t wait_queue; From 6166a0a749018464026535cf4c23d75d86a9ea1d Mon Sep 17 00:00:00 2001 From: Charan Teja Kalla Date: Thu, 29 Sep 2022 13:06:24 +0530 Subject: [PATCH 10/14] msm: kgsl: move kgsl shmem pages to unevictable list Kgsl shmem pages are always pinned but still endup in the evictable lru leading to inteference with the reclaim logic making the later spending more time in scanning the pages. This time can result into the PSI events generation leading to oom/lmkd logic to take the wrong decissions. Move such pages to unevictable LRU thus kept out of the reclaimable list. Change-Id: Iee82ce101526f04a8f294a10dce9598356701977 Signed-off-by: Charan Teja Kalla Signed-off-by: Srinivasarao Pathipati --- drivers/gpu/msm/kgsl_reclaim.c | 29 ++++++++++++++++++++++++++++- drivers/gpu/msm/kgsl_sharedmem.c | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/msm/kgsl_reclaim.c b/drivers/gpu/msm/kgsl_reclaim.c index f0bee68705be..845ae23af1fa 100644 --- a/drivers/gpu/msm/kgsl_reclaim.c +++ b/drivers/gpu/msm/kgsl_reclaim.c @@ -5,7 +5,9 @@ #include #include +#include #include +#include #include "kgsl_reclaim.h" #include "kgsl_sharedmem.h" @@ -193,6 +195,12 @@ ssize_t kgsl_proc_max_reclaim_limit_show(struct device *dev, return scnprintf(buf, PAGE_SIZE, "%d\n", kgsl_reclaim_max_page_limit); } +static void kgsl_release_page_vec(struct pagevec *pvec) +{ + check_move_unevictable_pages(pvec->pages, pvec->nr); + __pagevec_release(pvec); +} + static int kgsl_reclaim_callback(struct notifier_block *nb, unsigned long pid, void *data) { @@ -266,20 +274,39 @@ static int kgsl_reclaim_callback(struct notifier_block *nb, if (!kgsl_mmu_unmap(memdesc->pagetable, memdesc)) { int i; + struct pagevec pvec; + /* + * Pages that are first allocated are by default added + * to unevictable list. To reclaim them, we first clear + * the AS_UNEVICTABLE flag of the shmem file address + * space thus check_move_unevictable_pages() places + * them on the evictable list. + * + * Once reclaim is done, hint that further shmem + * allocations will have to be on the unevictable list. + */ + mapping_clear_unevictable( + memdesc->shmem_filp->f_mapping); + pagevec_init(&pvec); for (i = 0; i < memdesc->page_count; i++) { set_page_dirty_lock(memdesc->pages[i]); spin_lock(&memdesc->lock); - put_page(memdesc->pages[i]); + pagevec_add(&pvec, memdesc->pages[i]); memdesc->pages[i] = NULL; spin_unlock(&memdesc->lock); + if (pagevec_count(&pvec) == PAGEVEC_SIZE) + kgsl_release_page_vec(&pvec); } + if (pagevec_count(&pvec)) + kgsl_release_page_vec(&pvec); memdesc->priv |= KGSL_MEMDESC_RECLAIMED; ret = reclaim_address_space (memdesc->shmem_filp->f_mapping, data); + mapping_set_unevictable(memdesc->shmem_filp->f_mapping); memdesc->reclaimed_page_count += memdesc->page_count; atomic_add(memdesc->page_count, &process->reclaimed_page_count); diff --git a/drivers/gpu/msm/kgsl_sharedmem.c b/drivers/gpu/msm/kgsl_sharedmem.c index 621ab3db5a49..019fdb25d34a 100644 --- a/drivers/gpu/msm/kgsl_sharedmem.c +++ b/drivers/gpu/msm/kgsl_sharedmem.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. * Copyright (c) 2002,2007-2021, The Linux Foundation. All rights reserved. */ @@ -974,6 +975,7 @@ static int kgsl_memdesc_file_setup(struct kgsl_memdesc *memdesc, uint64_t size) memdesc->shmem_filp = NULL; return ret; } + mapping_set_unevictable(memdesc->shmem_filp->f_mapping); } return 0; From 7e65f76693e6623f44b7a2d4d24fb0c6f23616a7 Mon Sep 17 00:00:00 2001 From: Puranam V G Tejaswi Date: Tue, 14 Feb 2023 16:09:02 +0530 Subject: [PATCH 11/14] msm: kgsl: Use dma_buf_get() to get dma_buf structure Currently we don't ensure if vma->vm_file is associated with dma_buf. This can cause issues later when private_data from a non dma_buf file is used as dma_buf structure. Hence get the fd that is associated with vma->vm_file and use dma_buf_get() to get pointer to dma_buf structure. dma_buf_get() ensures that the file from the input fd is associated with dma_buf. Change-Id: Ib78aef8b16bedca5ca86d3a132278ff9f07dce73 Signed-off-by: Puranam V G Tejaswi --- drivers/gpu/msm/kgsl.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/msm/kgsl.c b/drivers/gpu/msm/kgsl.c index 8e6bb0341cb5..f3c37d7a0670 100644 --- a/drivers/gpu/msm/kgsl.c +++ b/drivers/gpu/msm/kgsl.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved. - * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -2677,6 +2677,15 @@ static int kgsl_setup_anon_useraddr(struct kgsl_pagetable *pagetable, } #ifdef CONFIG_DMA_SHARED_BUFFER +static int match_file(const void *p, struct file *file, unsigned int fd) +{ + /* + * We must return fd + 1 because iterate_fd stops searching on + * non-zero return, but 0 is a valid fd. + */ + return (p == file) ? (fd + 1) : 0; +} + static void _setup_cache_mode(struct kgsl_mem_entry *entry, struct vm_area_struct *vma) { @@ -2714,6 +2723,8 @@ static int kgsl_setup_dmabuf_useraddr(struct kgsl_device *device, vma = find_vma(current->mm, hostptr); if (vma && vma->vm_file) { + int fd; + ret = check_vma_flags(vma, entry->memdesc.flags); if (ret) { up_read(¤t->mm->mmap_sem); @@ -2729,13 +2740,27 @@ static int kgsl_setup_dmabuf_useraddr(struct kgsl_device *device, return -EFAULT; } - /* - * Take a refcount because dma_buf_put() decrements the - * refcount - */ - get_file(vma->vm_file); - - dmabuf = vma->vm_file->private_data; + /* Look for the fd that matches this vma file */ + fd = iterate_fd(current->files, 0, match_file, vma->vm_file); + if (fd) { + dmabuf = dma_buf_get(fd - 1); + if (IS_ERR(dmabuf)) { + up_read(¤t->mm->mmap_sem); + return PTR_ERR(dmabuf); + } + /* + * It is possible that the fd obtained from iterate_fd + * was closed before passing the fd to dma_buf_get(). + * Hence dmabuf returned by dma_buf_get() could be + * different from vma->vm_file->private_data. Return + * failure if this happens. + */ + if (dmabuf != vma->vm_file->private_data) { + dma_buf_put(dmabuf); + up_read(¤t->mm->mmap_sem); + return -EBADF; + } + } } if (IS_ERR_OR_NULL(dmabuf)) { From 3ec8a25de70864e246c925a01950b365d192861e Mon Sep 17 00:00:00 2001 From: Kamal Agrawal Date: Mon, 13 Feb 2023 16:51:37 +0530 Subject: [PATCH 12/14] msm: kgsl: Make sure that pool pages don't have any extra references Before putting a page back in the pool be sure that it doesn't have any additional references that would be a signal that somebody else is looking at the page and that it would be a bad idea to keep it around and run the risk of accidentally handing it to a different process. Change-Id: Ic0dedbad0cf2ffb34b76ad23e393c5a911114b82 Signed-off-by: Jordan Crouse Signed-off-by: Kamal Agrawal --- drivers/gpu/msm/kgsl_pool.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/msm/kgsl_pool.c b/drivers/gpu/msm/kgsl_pool.c index ecb05b9b9a06..b5429cbb12ec 100644 --- a/drivers/gpu/msm/kgsl_pool.c +++ b/drivers/gpu/msm/kgsl_pool.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -61,6 +62,15 @@ _kgsl_get_pool_from_order(unsigned int order) static void _kgsl_pool_add_page(struct kgsl_page_pool *pool, struct page *p) { + /* + * Sanity check to make sure we don't re-pool a page that + * somebody else has a reference to. + */ + if (WARN_ON_ONCE(unlikely(page_count(p) > 1))) { + __free_pages(p, pool->pool_order); + return; + } + kgsl_zero_page(p, pool->pool_order); spin_lock(&pool->list_lock); From b0d3f9d7c777df4623b56ed856ba66cdb48db8eb Mon Sep 17 00:00:00 2001 From: Surapusetty Naresh Babu Date: Tue, 7 Mar 2023 11:22:28 +0530 Subject: [PATCH 13/14] Revert "msm: kgsl: Make sure that pool pages don't have any extra references" This reverts commit 3ec8a25de70864e246c925a01950b365d192861e. Change-Id: I5fcbd8194118b0b3491f82dc7451566ac2ce57de Signed-off-by: snareshb --- drivers/gpu/msm/kgsl_pool.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/drivers/gpu/msm/kgsl_pool.c b/drivers/gpu/msm/kgsl_pool.c index b5429cbb12ec..ecb05b9b9a06 100644 --- a/drivers/gpu/msm/kgsl_pool.c +++ b/drivers/gpu/msm/kgsl_pool.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. - * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -62,15 +61,6 @@ _kgsl_get_pool_from_order(unsigned int order) static void _kgsl_pool_add_page(struct kgsl_page_pool *pool, struct page *p) { - /* - * Sanity check to make sure we don't re-pool a page that - * somebody else has a reference to. - */ - if (WARN_ON_ONCE(unlikely(page_count(p) > 1))) { - __free_pages(p, pool->pool_order); - return; - } - kgsl_zero_page(p, pool->pool_order); spin_lock(&pool->list_lock); From ff12f4a9bf68fb94c649d797157e757cfecaf8d9 Mon Sep 17 00:00:00 2001 From: snareshb Date: Tue, 7 Mar 2023 14:19:01 +0530 Subject: [PATCH 14/14] Revert "Revert "msm: kgsl: Make sure that pool pages don't have any extra references"" This reverts commit b0d3f9d7c777df4623b56ed856ba66cdb48db8eb. Change-Id: Ie3178dfac9cee2cb68869a752fbdf26422691d54 Signed-off-by: snareshb --- drivers/gpu/msm/kgsl_pool.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/msm/kgsl_pool.c b/drivers/gpu/msm/kgsl_pool.c index ecb05b9b9a06..b5429cbb12ec 100644 --- a/drivers/gpu/msm/kgsl_pool.c +++ b/drivers/gpu/msm/kgsl_pool.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -61,6 +62,15 @@ _kgsl_get_pool_from_order(unsigned int order) static void _kgsl_pool_add_page(struct kgsl_page_pool *pool, struct page *p) { + /* + * Sanity check to make sure we don't re-pool a page that + * somebody else has a reference to. + */ + if (WARN_ON_ONCE(unlikely(page_count(p) > 1))) { + __free_pages(p, pool->pool_order); + return; + } + kgsl_zero_page(p, pool->pool_order); spin_lock(&pool->list_lock);