From patchwork Wed Jan 26 13:52:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 537705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80BAAC6369B for ; Wed, 26 Jan 2022 13:54:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241724AbiAZNyb (ORCPT ); Wed, 26 Jan 2022 08:54:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241717AbiAZNya (ORCPT ); Wed, 26 Jan 2022 08:54:30 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3652FC06173B for ; Wed, 26 Jan 2022 05:54:30 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id f202-20020a1c1fd3000000b0034dd403f4fbso4328626wmf.1 for ; Wed, 26 Jan 2022 05:54:30 -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 :mime-version:content-transfer-encoding; bh=xCYXvajSPn9motpDNNaOC8f2agY2/ynvhbQJNwf12vc=; b=gNq/nBXOBz4Cj9jFVtqfipAeTJ9VWaxPpGJ7hhmyLoDjwo54DMuDgkO1smcDcxqmTG +s3ILxzWuYFnhQv/iLS1itrAdZEfetYyLxYDNM9zjP/wVLlJgqvNs29ULba2jhqh/l+M fE9Ro+phV/ds1ianxWTn4ZugyrYOuXslH3m2oGlCIe30ubOp2OU4wzs359L4LwGzGaF1 frQ1BN2RY43K4nv7a2YhySThX6jUyFLh46EJxNajeY5uTKUJn7AFmcXCZWMUEjbPramH Wh5UZLzu0MH1q7l+mKHcjvQZyT5BpsQpTBdEgTbwLOTdyMrfihHPviXbHljtwmUJuhQi A/zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xCYXvajSPn9motpDNNaOC8f2agY2/ynvhbQJNwf12vc=; b=kEs3RSNK2bTXxHRuadjmxIyq9n/tyv6/u5r52OX8XL13ZWETAzscpIa/Ku0QvGE/GG 9wAKwIK5pYCyLVgdejzQYMkguWGhX0Sr4D2LTCEGwfna2NtE/3A6pFr1Rj5cHMSUT1JR E9JO8YMtuNqfegzRH8xu7DMC+dZcEqqS2YJVaczkAlDuQw0bpQyIhZHlaQkG+NYZ0K5P q00FayCMLWKl1J6Vu1XPXPfkPJHewUObPsP9tqosEtYu2X3IzCQCtM8jbUz+vE2CDRbe 2SNae5oYb7KvPDNhDpoiO4M0qQGU2Fl7AauT2I7NmjrAhI4vkbi34XPIJuZnCFZCIOX1 HuZg== X-Gm-Message-State: AOAM5336jTKbvfncU5GuLIyv8nK6VgdJ2CrG/0KIiYI653AU8EGRdmi9 crVbnvGeu4PxvfejpYrnnLH9qA== X-Google-Smtp-Source: ABdhPJxuURiygMhaMWKcGSq8WFNpulIgKKlsIOquUzgZhkD1MwBiuquvxU9nrdubxuJXzyvxINSniQ== X-Received: by 2002:a05:600c:34c6:: with SMTP id d6mr7497064wmq.86.1643205268831; Wed, 26 Jan 2022 05:54:28 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n15sm3356593wmr.26.2022.01.26.05.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 05:54:28 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org Cc: devicetree@vger.kernel.org, ekangupt@qti.qualcomm.com, bkumar@qti.qualcomm.com, linux-kernel@vger.kernel.org, srini@kernel.org, bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, Jeya R , Srinivas Kandagatla Subject: [PATCH v3 03/12] misc: fastrpc: Add support to get DSP capabilities Date: Wed, 26 Jan 2022 13:52:55 +0000 Message-Id: <20220126135304.16340-4-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> References: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Jeya R Add support to get DSP capabilities. The capability information is cached on driver. Signed-off-by: Jeya R Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 105 ++++++++++++++++++++++++++++++++++++ include/uapi/misc/fastrpc.h | 8 +++ 2 files changed, 113 insertions(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index a840b8dabf0e..d5fafbe3c709 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -31,10 +31,14 @@ #define FASTRPC_PHYS(p) ((p) & 0xffffffff) #define FASTRPC_CTX_MAX (256) #define FASTRPC_INIT_HANDLE 1 +#define FASTRPC_DSP_UTILITIES_HANDLE 2 #define FASTRPC_CTXID_MASK (0xFF0) #define INIT_FILELEN_MAX (2 * 1024 * 1024) #define FASTRPC_DEVICE_NAME "fastrpc" #define ADSP_MMAP_ADD_PAGES 0x1000 +#define DSP_UNSUPPORTED_API (0x80000414) +/* MAX NUMBER of DSP ATTRIBUTES SUPPORTED */ +#define FASTRPC_MAX_DSP_ATTRIBUTES (256) /* Retrives number of input buffers from the scalars parameter */ #define REMOTE_SCALARS_INBUFS(sc) (((sc) >> 16) & 0x0ff) @@ -233,6 +237,9 @@ struct fastrpc_channel_ctx { struct idr ctx_idr; struct list_head users; struct kref refcount; + /* Flag if dsp attributes are cached */ + bool valid_attributes; + u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES]; struct fastrpc_device *fdevice; }; @@ -1371,6 +1378,101 @@ static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp) return err; } +static int fastrpc_get_info_from_dsp(struct fastrpc_user *fl, uint32_t *dsp_attr_buf, + uint32_t dsp_attr_buf_len) +{ + struct fastrpc_invoke_args args[2] = { 0 }; + + /* Capability filled in userspace */ + dsp_attr_buf[0] = 0; + + args[0].ptr = (u64)(uintptr_t)&dsp_attr_buf_len; + args[0].length = sizeof(dsp_attr_buf_len); + args[0].fd = -1; + args[1].ptr = (u64)(uintptr_t)&dsp_attr_buf[1]; + args[1].length = dsp_attr_buf_len * sizeof(uint32_t); + args[1].fd = -1; + fl->pd = 1; + + return fastrpc_internal_invoke(fl, true, FASTRPC_DSP_UTILITIES_HANDLE, + FASTRPC_SCALARS(0, 1, 1), args); +} + +static int fastrpc_get_info_from_kernel(struct fastrpc_ioctl_capability *cap, + struct fastrpc_user *fl) +{ + struct fastrpc_channel_ctx *cctx = fl->cctx; + uint32_t attribute_id = cap->attribute_id; + uint32_t dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES]; + unsigned long flags; + uint32_t domain = cap->domain; + int err; + + spin_lock_irqsave(&cctx->lock, flags); + /* check if we already have queried dsp for attributes */ + if (cctx->valid_attributes) { + spin_unlock_irqrestore(&cctx->lock, flags); + goto done; + } + spin_unlock_irqrestore(&cctx->lock, flags); + + err = fastrpc_get_info_from_dsp(fl, &dsp_attributes[0], FASTRPC_MAX_DSP_ATTRIBUTES); + if (err == DSP_UNSUPPORTED_API) { + dev_info(&cctx->rpdev->dev, + "Warning: DSP capabilities not supported on domain: %d\n", domain); + return -EOPNOTSUPP; + } else if (err) { + dev_err(&cctx->rpdev->dev, "Error: dsp information is incorrect err: %d\n", err); + return err; + } + + spin_lock_irqsave(&cctx->lock, flags); + memcpy(cctx->dsp_attributes, dsp_attributes, sizeof(u32) * FASTRPC_MAX_DSP_ATTRIBUTES); + cctx->valid_attributes = true; + spin_unlock_irqrestore(&cctx->lock, flags); +done: + cap->capability = cctx->dsp_attributes[attribute_id]; + + return 0; +} + +static int fastrpc_get_dsp_info(struct fastrpc_user *fl, char __user *argp) +{ + struct fastrpc_ioctl_capability cap = {0}; + int err = 0; + + if (copy_from_user(&cap, argp, sizeof(cap))) + return -EFAULT; + + cap.capability = 0; + if (cap.domain >= FASTRPC_DEV_MAX) { + dev_err(&fl->cctx->rpdev->dev, "Error: Invalid domain id:%d, err:%d\n", + cap.domain, err); + return -ECHRNG; + } + + /* Fastrpc Capablities does not support modem domain */ + if (cap.domain == MDSP_DOMAIN_ID) { + dev_err(&fl->cctx->rpdev->dev, "Error: modem not supported %d\n", err); + return -ECHRNG; + } + + if (cap.attribute_id >= FASTRPC_MAX_DSP_ATTRIBUTES) { + dev_err(&fl->cctx->rpdev->dev, "Error: invalid attribute: %d, err: %d\n", + cap.attribute_id, err); + return -EOVERFLOW; + } + + err = fastrpc_get_info_from_kernel(&cap, fl); + if (err) + return err; + + if (copy_to_user(argp, &cap.capability, sizeof(cap.capability))) + return -EFAULT; + + return 0; +} + static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_req_munmap *req) { @@ -1677,6 +1779,9 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd, case FASTRPC_IOCTL_MEM_UNMAP: err = fastrpc_req_mem_unmap(fl, argp); break; + case FASTRPC_IOCTL_GET_DSP_INFO: + err = fastrpc_get_dsp_info(fl, argp); + break; default: err = -ENOTTY; break; diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index d248eeb20e67..7cc9d342078a 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -15,6 +15,7 @@ #define FASTRPC_IOCTL_INIT_ATTACH_SNS _IO('R', 8) #define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 10, struct fastrpc_mem_map) #define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 11, struct fastrpc_mem_unmap) +#define FASTRPC_IOCTL_GET_DSP_INFO _IOWR('R', 13, struct fastrpc_ioctl_capability) /** * enum fastrpc_map_flags - control flags for mapping memory on DSP user process @@ -105,4 +106,11 @@ struct fastrpc_mem_unmap { __s32 reserved[5]; }; +struct fastrpc_ioctl_capability { + __u32 domain; + __u32 attribute_id; + __u32 capability; /* dsp capability */ + __u32 reserved[4]; +}; + #endif /* __QCOM_FASTRPC_H__ */ From patchwork Wed Jan 26 13:52:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 537704 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 559B1C28CF5 for ; Wed, 26 Jan 2022 13:54:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241726AbiAZNyc (ORCPT ); Wed, 26 Jan 2022 08:54:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241729AbiAZNyb (ORCPT ); Wed, 26 Jan 2022 08:54:31 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D7DC06161C for ; Wed, 26 Jan 2022 05:54:31 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id u15so25948450wrt.3 for ; Wed, 26 Jan 2022 05:54:31 -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 :mime-version:content-transfer-encoding; bh=Z5AnMORgB0aa+xiAll7F0CRVY0oWDotsOZG4NUiDGN0=; b=NdW3yfIwrbjsYzOF1RonPMYJ0WpfZTFxuHuQxBM/dVV9Ezhl2+SeHHs6yoaIX8C0hy kaQzfRS4Cv/aIaxNI13XhtW+QBB12IbukOsEnmkeAILaSCT+8EzmnizAqSds4mKCYHbP QO9wRoQLxzIm0ZJkiWxg3aLbG2X7H7aqyR0eJSsbMjffMUG+vLkJgD5BkUowRQrp2Biy 0nPMLYA5BTxmvVEZopjPMurq6WrIzYtc5zReiZB0wfE98dXUMNiuzVZZm73TgjmK8jP8 B0DrAxSf/jAXaA/H7Z1fJZB/3bBRK0AwHucn0uREPTaW/9fn+pf3wmBqCuYvlA/4j+H+ rKeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z5AnMORgB0aa+xiAll7F0CRVY0oWDotsOZG4NUiDGN0=; b=zzS77CRWQ9SkgjqDnBcOs4213zfGNmjyqCYSiBdx2peYWOWjfXZ97X6MvTZW31lONV AJx9fWTWHU+N8djSNdHsN6AajEm0lwJaaGZs65iPeB1lIfeCNXgg+7mkNqiVuOVLclpT 2byZSl7takYFnjm9NMTgxi0TDYarR5shumGeFQTv6JTCE2Ym6yAz4XRQwkVN8kHn6qNU 1ejGpo7juejW452ACH3zTc8b1QfDEBkECxK+OoI96CRKZhN+v7XRIKTyWOSMUzkLFAdq Le5uPcfkBm/LJtlwmckeacd6NDEY9G5OMmgZIy3Fg85AnrXHVm5ZraJ+oGOQzequbruQ ZjWg== X-Gm-Message-State: AOAM532JTk4Hm07RPWaCv+C4GRwQORhSsjD9ccoeLYma2dZqKWYHY08C /ctUB4IDaJNEazF1sAR1KgfUXw== X-Google-Smtp-Source: ABdhPJymzELD6H/RrVSkXF0UApF80RbqrMriC5qEG36lxHjhh0tFfDjthzRNG7rS5Tlrp0AgnnLy4w== X-Received: by 2002:a5d:6c68:: with SMTP id r8mr11040893wrz.406.1643205270062; Wed, 26 Jan 2022 05:54:30 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n15sm3356593wmr.26.2022.01.26.05.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 05:54:29 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org Cc: devicetree@vger.kernel.org, ekangupt@qti.qualcomm.com, bkumar@qti.qualcomm.com, linux-kernel@vger.kernel.org, srini@kernel.org, bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, Jeya R , Srinivas Kandagatla Subject: [PATCH v3 04/12] dt-bindings: misc: add property to support non-secure DSP Date: Wed, 26 Jan 2022 13:52:56 +0000 Message-Id: <20220126135304.16340-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> References: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Jeya R Add property to set DSP domain as non-secure. ADSP/MDSP/SDSP are by default secured, where as CDSP can be either be secured/unsecured. non-secured Compute DSP would allow users to load unsigned process and run hexagon instructions, but limiting access to secured hardware within the DSP. Based on this flag device nodes for secured and unsecured are created. Signed-off-by: Jeya R Signed-off-by: Srinivas Kandagatla Acked-by: Rob Herring --- Documentation/devicetree/bindings/misc/qcom,fastrpc.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt b/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt index 2a1827ab50d2..f9a01e2b4c96 100644 --- a/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt +++ b/Documentation/devicetree/bindings/misc/qcom,fastrpc.txt @@ -17,6 +17,11 @@ other tasks. Definition: should specify the dsp domain name this fastrpc corresponds to. must be one of this: "adsp", "mdsp", "sdsp", "cdsp" +- qcom,non-secure-domain: + Usage: required + Value type: + Definition: Property to specify that dsp domain is non-secure. + - #address-cells Usage: required Value type: From patchwork Wed Jan 26 13:52:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 537703 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A4FAC63684 for ; Wed, 26 Jan 2022 13:54:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241782AbiAZNyk (ORCPT ); Wed, 26 Jan 2022 08:54:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241766AbiAZNyf (ORCPT ); Wed, 26 Jan 2022 08:54:35 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B56FCC06175C for ; Wed, 26 Jan 2022 05:54:33 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id u15so25948625wrt.3 for ; Wed, 26 Jan 2022 05:54: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 :mime-version:content-transfer-encoding; bh=zs0E5gUaoruQJ3cvVtoptNZo64os9iwjHdiVALNxOr4=; b=wKtTYdgoKS4YdUkgnSSv/91lyaiD39hzcOjJGllpmzOWgF6COeYRWEUOkKTfcoR3Vx E7ZIbKOh3J9XX+ny0VMmWyglPdecWqV1XFzsRya/HPdPw3LN2QFIYpRHxBzxWBJnmx7w d6mEo49zL/h+xBYKWCKed8IftTWCYzwMfknijh37/JydP28QOB1W38nPr7AP1BJHwT9s yxT4MFB125P0RnsbC1zxg0s0FA8igzNVUyLHjx0548bUVmlSH8NVb+W5kDLSsGLog3Z/ sqBeavfiJunAiA3YaLyxnCBGHx7EVL0o5973cWe3f+M68y9GU721NvwClgArts+69v7K LKMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zs0E5gUaoruQJ3cvVtoptNZo64os9iwjHdiVALNxOr4=; b=bNq9vEwtJtT6InjSwQeGOLjDwR5DQszN2hNJbFeCq4JvjrvSLYgdzFSHAAdKgaov9c xGePZL3eSnxxwx1kC4KFrrfrc2Vqyp4ziwFlSvRxmAMBpawljiuo88pjApcyI/Ag1IUg V3Pk0mQ40unV5N74JVyJlFqpc6igqwGSVQO6qYHY/oXvomp8dzm01wgFZbhCWLuucZAq 7qGg9eyowqwkiAl/kajhSh/CQ1qLGrVr0v4dcN+oPDilohLWEaVvsFFrPsqjqZ3iH49U V4mvxHjdlOC5SrHxVODh1SBh6WNje3kqrBGKex5W/8jAHTEWXvfUG7UvPqqY33YwR0uA ol/w== X-Gm-Message-State: AOAM5331kzdjnkpSRCwj3HnT7YNKSP4Xrig9pHO1mRRhPDq84iFexFGw O8nmqAivR/gnUPt23jLU4eyRBA== X-Google-Smtp-Source: ABdhPJxKg62TfJnWibTrVuqUbQxrbH2rHYfToqzIo0ek+w8ZseYSjA78Je9MQAq/fy/AaXlM+fRKDg== X-Received: by 2002:a5d:6d09:: with SMTP id e9mr11621086wrq.37.1643205272298; Wed, 26 Jan 2022 05:54:32 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n15sm3356593wmr.26.2022.01.26.05.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 05:54:31 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org Cc: devicetree@vger.kernel.org, ekangupt@qti.qualcomm.com, bkumar@qti.qualcomm.com, linux-kernel@vger.kernel.org, srini@kernel.org, bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, Jeya R , Srinivas Kandagatla Subject: [PATCH v3 06/12] misc: fastrpc: check before loading process to the DSP Date: Wed, 26 Jan 2022 13:52:58 +0000 Message-Id: <20220126135304.16340-7-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> References: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Jeya R Reject session if DSP domain is secure, device node is non-secure and signed PD is requested. Secure device node can access DSP without any restriction. Unsigned PD offload is only allowed for the DSP domain that can support unsigned offloading. Signed-off-by: Jeya R Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 33 +++++++++++++++++++++++++++++++++ include/uapi/misc/fastrpc.h | 17 +++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 9eadbcf451ef..8e780e2d5d9d 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -243,6 +243,7 @@ struct fastrpc_channel_ctx { struct fastrpc_device *secure_fdevice; struct fastrpc_device *fdevice; bool secure; + bool unsigned_support; }; struct fastrpc_device { @@ -263,6 +264,7 @@ struct fastrpc_user { int tgid; int pd; + bool is_secure_dev; /* Lock for lists */ spinlock_t lock; /* lock for allocations */ @@ -1051,6 +1053,24 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, return err; } +static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_request) +{ + /* Check if the device node is non-secure and channel is secure*/ + if (!fl->is_secure_dev && fl->cctx->secure) { + /* + * Allow untrusted applications to offload only to Unsigned PD when + * channel is configured as secure and block untrusted apps on channel + * that does not support unsigned PD offload + */ + if (!fl->cctx->unsigned_support || !unsigned_pd_request) { + dev_err(&fl->cctx->rpdev->dev, "Error: Untrusted application trying to offload to signed PD"); + return true; + } + } + + return false; +} + static int fastrpc_init_create_process(struct fastrpc_user *fl, char __user *argp) { @@ -1070,6 +1090,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, u32 siglen; } inbuf; u32 sc; + bool unsigned_module = false; args = kcalloc(FASTRPC_CREATE_PROCESS_NARGS, sizeof(*args), GFP_KERNEL); if (!args) @@ -1080,6 +1101,14 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, goto err; } + if (init.attrs & FASTRPC_MODE_UNSIGNED_MODULE) + unsigned_module = true; + + if (is_session_rejected(fl, unsigned_module)) { + err = -ECONNREFUSED; + goto err; + } + if (init.filelen > INIT_FILELEN_MAX) { err = -EINVAL; goto err; @@ -1279,6 +1308,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) INIT_LIST_HEAD(&fl->user); fl->tgid = current->tgid; fl->cctx = cctx; + fl->is_secure_dev = fdevice->secure; fl->sctx = fastrpc_session_alloc(cctx); if (!fl->sctx) { @@ -1947,11 +1977,14 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) case ADSP_DOMAIN_ID: case MDSP_DOMAIN_ID: case SDSP_DOMAIN_ID: + /* Unsigned PD offloading is only supported on CDSP*/ + data->unsigned_support = false; err = fastrpc_device_register(rdev, data, secure_dsp, domains[domain_id]); if (err) goto fdev_error; break; case CDSP_DOMAIN_ID: + data->unsigned_support = true; /* Create both device nodes so that we can allow both Signed and Unsigned PD */ err = fastrpc_device_register(rdev, data, true, domains[domain_id]); if (err) diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index 7cc9d342078a..f39edac20305 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -46,6 +46,23 @@ enum fastrpc_map_flags { FASTRPC_MAP_MAX, }; +enum fastrpc_proc_attr { + /* Macro for Debug attr */ + FASTRPC_MODE_DEBUG = (1 << 0), + /* Macro for Ptrace */ + FASTRPC_MODE_PTRACE = (1 << 1), + /* Macro for CRC Check */ + FASTRPC_MODE_CRC = (1 << 2), + /* Macro for Unsigned PD */ + FASTRPC_MODE_UNSIGNED_MODULE = (1 << 3), + /* Macro for Adaptive QoS */ + FASTRPC_MODE_ADAPTIVE_QOS = (1 << 4), + /* Macro for System Process */ + FASTRPC_MODE_SYSTEM_PROCESS = (1 << 5), + /* Macro for Prvileged Process */ + FASTRPC_MODE_PRIVILEGED = (1 << 6), +}; + struct fastrpc_invoke_args { __u64 ptr; __u64 length; From patchwork Wed Jan 26 13:53:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 537702 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CD8BC2BA4C for ; Wed, 26 Jan 2022 13:54:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241904AbiAZNyw (ORCPT ); Wed, 26 Jan 2022 08:54:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241798AbiAZNyj (ORCPT ); Wed, 26 Jan 2022 08:54:39 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12EF1C06173B for ; Wed, 26 Jan 2022 05:54:36 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id w11so13747913wra.4 for ; Wed, 26 Jan 2022 05:54:36 -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 :mime-version:content-transfer-encoding; bh=gJKSsAudCW68wjBcYmZkvSQLNXWe4kcfjmLMXs7MAJs=; b=n5LCe9S0O2aMl5iGp+938ABzdGFiNe5O++WgkYnc0QabXJQtECb78QWn+JXKiL69u8 iG1RvIxZehD4+3EjqZ3Y+3HTXLvxxb6I00AeFmsTq1gU4qO8dbdFkC/CUldRKjeW67Qb NMkE+wsLeNwrv4R9clzgwX/LwaPhsOwVQNuTCmYlOBn3dyBn3LRzE2/S/y04oU35PREB FqQfqLn/BLeiXOEpQET20mxpYEHZO4NHN1Yh5ZSwl43JiZO2STEeJhj9wMQMc5ap/659 TzCP3gXkf/heF4LOw3wh0YrXg/li4mfK2svDRHyw50Ur0gwUgMYXlLi4+8Fj21WcDN/l lx3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gJKSsAudCW68wjBcYmZkvSQLNXWe4kcfjmLMXs7MAJs=; b=B9tJ43dyWt+eozv5WXnMvlcwBYafJLUDXsvR35MWeeFB4BjqO38yfRT/+ki5lrIHJm zp0/CKf9+0aCywI182VR5ofpPnOo5hOF+78tkkoguKlWQ6aSXMu36QGvNS0msudQbjod 7YLEfztzzahfV2GnzHo8rX3HkqXSh9tajH2e4lO+XmUxkP5vPnamGY/fH+FX4ZIn8F/8 Ji8u7WQG7jEUdjyCKeyTMp/Acru2jNnCqEY6/ySOvGWd/Lg2FBWLcf3XYQqznkwuj0Rf BOVFuKdCRgwwwi2/ebvLpwIHkeXVXemrh5Z33uWBmkwy6qkfTot7sefd2mPHW0gxj/JU gYMA== X-Gm-Message-State: AOAM533UPnx3PLXERnOT3Lpj8hsZ8N311NqCHPeKG7xUs+6f5fZnVYod /fPktjKQTnNBqJFAysUs70tZvw== X-Google-Smtp-Source: ABdhPJy0gbhkanA/nbVs20EytxbtdtXUIJFn7tAbb+200yZNQwNPUlvam3ouo3kk+bqjI5u2zXZ+Lg== X-Received: by 2002:adf:efcd:: with SMTP id i13mr22951487wrp.343.1643205274661; Wed, 26 Jan 2022 05:54:34 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n15sm3356593wmr.26.2022.01.26.05.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 05:54:34 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org Cc: devicetree@vger.kernel.org, ekangupt@qti.qualcomm.com, bkumar@qti.qualcomm.com, linux-kernel@vger.kernel.org, srini@kernel.org, bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, Vamsi Krishna Gattupalli , Srinivas Kandagatla Subject: [PATCH v3 08/12] misc: fastrpc: Add support to secure memory map Date: Wed, 26 Jan 2022 13:53:00 +0000 Message-Id: <20220126135304.16340-9-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> References: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Vamsi Krishna Gattupalli This patch adds support to secure memory allocations for DSP. It repurposes the reserved field in struct fastrpc_invoke_args to add attributes to invoke request, for example to setup a secure memory map for dsp. Secure memory is assigned to DSP Virtual Machine IDs using Qualcomm SCM calls. Signed-off-by: Vamsi Krishna Gattupalli Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 65 ++++++++++++++++++++++++++++++++----- include/uapi/misc/fastrpc.h | 5 ++- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 8e780e2d5d9d..0090085bfbb9 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #define ADSP_DOMAIN_ID (0) @@ -25,6 +26,7 @@ #define CDSP_DOMAIN_ID (3) #define FASTRPC_DEV_MAX 4 /* adsp, mdsp, slpi, cdsp*/ #define FASTRPC_MAX_SESSIONS 13 /*12 compute, 1 cpz*/ +#define FASTRPC_MAX_VMIDS 16 #define FASTRPC_ALIGN 128 #define FASTRPC_MAX_FDLIST 16 #define FASTRPC_MAX_CRCLIST 64 @@ -194,6 +196,7 @@ struct fastrpc_map { void *va; u64 len; u64 raddr; + u32 attr; struct kref refcount; }; @@ -231,6 +234,9 @@ struct fastrpc_session_ctx { struct fastrpc_channel_ctx { int domain_id; int sesscount; + int vmcount; + u32 perms; + struct qcom_scm_vmperm vmperms[FASTRPC_MAX_VMIDS]; struct rpmsg_device *rpdev; struct fastrpc_session_ctx session[FASTRPC_MAX_SESSIONS]; spinlock_t lock; @@ -278,6 +284,20 @@ static void fastrpc_free_map(struct kref *ref) map = container_of(ref, struct fastrpc_map, refcount); if (map->table) { + if (map->attr & FASTRPC_ATTR_SECUREMAP) { + struct qcom_scm_vmperm perm; + int err = 0; + + perm.vmid = QCOM_SCM_VMID_HLOS; + perm.perm = QCOM_SCM_PERM_RWX; + err = qcom_scm_assign_mem(map->phys, map->size, + &(map->fl->cctx->vmperms[0].vmid), &perm, 1); + if (err) { + dev_err(map->fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d", + map->phys, map->size, err); + return; + } + } dma_buf_unmap_attachment(map->attach, map->table, DMA_BIDIRECTIONAL); dma_buf_detach(map->buf, map->attach); @@ -654,7 +674,7 @@ static const struct dma_buf_ops fastrpc_dma_buf_ops = { }; static int fastrpc_map_create(struct fastrpc_user *fl, int fd, - u64 len, struct fastrpc_map **ppmap) + u64 len, u32 attr, struct fastrpc_map **ppmap) { struct fastrpc_session_ctx *sess = fl->sctx; struct fastrpc_map *map = NULL; @@ -696,6 +716,22 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd, map->len = len; kref_init(&map->refcount); + if (attr & FASTRPC_ATTR_SECUREMAP) { + /* + * If subsystem VMIDs are defined in DTSI, then do + * hyp_assign from HLOS to those VM(s) + */ + unsigned int perms = BIT(QCOM_SCM_VMID_HLOS); + + map->attr = attr; + err = qcom_scm_assign_mem(map->phys, (u64)map->size, &perms, + fl->cctx->vmperms, fl->cctx->vmcount); + if (err) { + dev_err(sess->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d", + map->phys, map->size, err); + goto map_err; + } + } spin_lock(&fl->lock); list_add_tail(&map->node, &fl->maps); spin_unlock(&fl->lock); @@ -780,16 +816,13 @@ static int fastrpc_create_maps(struct fastrpc_invoke_ctx *ctx) int i, err; for (i = 0; i < ctx->nscalars; ++i) { - /* Make sure reserved field is set to 0 */ - if (ctx->args[i].reserved) - return -EINVAL; if (ctx->args[i].fd == 0 || ctx->args[i].fd == -1 || ctx->args[i].length == 0) continue; err = fastrpc_map_create(ctx->fl, ctx->args[i].fd, - ctx->args[i].length, &ctx->maps[i]); + ctx->args[i].length, ctx->args[i].attr, &ctx->maps[i]); if (err) { dev_err(dev, "Error Creating map %d\n", err); return -EINVAL; @@ -1123,7 +1156,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl, fl->pd = USER_PD; if (init.filelen && init.filefd) { - err = fastrpc_map_create(fl, init.filefd, init.filelen, &map); + err = fastrpc_map_create(fl, init.filefd, init.filelen, 0, &map); if (err) goto err; } @@ -1232,7 +1265,6 @@ static int fastrpc_release_current_dsp_process(struct fastrpc_user *fl) args[0].ptr = (u64)(uintptr_t) &tgid; args[0].length = sizeof(tgid); args[0].fd = -1; - args[0].reserved = 0; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_RELEASE, 1, 0); return fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, @@ -1373,7 +1405,6 @@ static int fastrpc_init_attach(struct fastrpc_user *fl, int pd) args[0].ptr = (u64)(uintptr_t) &tgid; args[0].length = sizeof(tgid); args[0].fd = -1; - args[0].reserved = 0; sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_ATTACH, 1, 0); fl->pd = pd; @@ -1943,9 +1974,10 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) { struct device *rdev = &rpdev->dev; struct fastrpc_channel_ctx *data; - int i, err, domain_id = -1; + int i, err, domain_id = -1, vmcount; const char *domain; bool secure_dsp; + unsigned int vmids[FASTRPC_MAX_VMIDS]; err = of_property_read_string(rdev->of_node, "label", &domain); if (err) { @@ -1965,10 +1997,25 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) return -EINVAL; } + vmcount = of_property_read_variable_u32_array(rdev->of_node, + "qcom,vmids", &vmids[0], 0, FASTRPC_MAX_VMIDS); + if (vmcount < 0) + vmcount = 0; + else if (!qcom_scm_is_available()) + return -EPROBE_DEFER; + data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; + if (vmcount) { + data->vmcount = vmcount; + data->perms = BIT(QCOM_SCM_VMID_HLOS); + for (i = 0; i < data->vmcount; i++) { + data->vmperms[i].vmid = vmids[i]; + data->vmperms[i].perm = QCOM_SCM_PERM_RWX; + } + } secure_dsp = !(of_property_read_bool(rdev->of_node, "qcom,non-secure-domain")); data->secure = secure_dsp; diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index f39edac20305..5e29f2cfa42d 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -63,11 +63,14 @@ enum fastrpc_proc_attr { FASTRPC_MODE_PRIVILEGED = (1 << 6), }; +/* Fastrpc attribute for memory protection of buffers */ +#define FASTRPC_ATTR_SECUREMAP (1) + struct fastrpc_invoke_args { __u64 ptr; __u64 length; __s32 fd; - __u32 reserved; + __u32 attr; }; struct fastrpc_invoke { From patchwork Wed Jan 26 13:53:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 537701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50244C3526D for ; Wed, 26 Jan 2022 13:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241753AbiAZNyy (ORCPT ); Wed, 26 Jan 2022 08:54:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241737AbiAZNyk (ORCPT ); Wed, 26 Jan 2022 08:54:40 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 763C7C06176F for ; Wed, 26 Jan 2022 05:54:38 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id f17so25925769wrx.1 for ; Wed, 26 Jan 2022 05:54:38 -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 :mime-version:content-transfer-encoding; bh=BKsf6dGO619i7ojy2wbleRyI3TRP+wgyPNagaXmtvTU=; b=c7yiZrG4/TyIvSNHYNZnb10q3lmZMebSVvAJlr3i5scF1Hj/EfHqt/z/P5a4ROFfKD X/HgALPBPiHcpqCGJO/MOhRCv+Pu6OyK1llbwcHnJHvHvgjLdP77TacG714tWZNxz4ox KEUsg396RWk1eZ+xniAh2m4X2ctOJb/cFnJ1HZ6HmJcz+8IMJrWfeydYDfoM8KYuy3aV y9VXFq0SDfmhdClORdVj6TNW/8YiUyTBR8XD5VTfyerOBtTWBoM0wPmfOju4u/nNWCY8 jth/Ripzl5I52L6jb9Kh8aAVS+xJ5PIGg9AstgepmSP7RH8aI9TXJHqFxNEVqyeW5l5r w+lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BKsf6dGO619i7ojy2wbleRyI3TRP+wgyPNagaXmtvTU=; b=OQlt2Q96Ke26FCZuXI2OhrlVG6QkBAjOWC5TTaA/ycurLTUnpiYS2hhPXf3ktH9C7Y pnwf893Q85aJ+EA8UmoN1W7Qzbi0UJuwI1eHGyJ+3uJjo4/5V3USsZ28Q18c0UuFaQIq DJP6Q7luYdGIw7z/tBXVnZhOC3GwF0RWOQcOHKHpgFT+IPQA3QVFgEgNNFMdWTaIVSym x23FMpXmcYoorK/hQt1zOenBCGmhIfUhHFtYPaoAxV2WCHG86L8zAIs3MPLSTTp6wt6g YFf0tEDDWFa+p6YQ9oVbeje9iGqFpjLQ/KqDpNQeB9bcUBgWIRIx4zTarqiXJvAomSke laMQ== X-Gm-Message-State: AOAM5330cX9pUZcBHGEpEK7c936EVH39eLjlu6qfNUPPbKZGqcny3icg eJIylZCEGzyjVITSJ4KQBO98Jw== X-Google-Smtp-Source: ABdhPJzeRGH+zsgttK1iV0aSGOWXWhbvvWfYyqpBupgxLD/fRvNMwITNpQYK76Ot2fpf1trlYB0Vnw== X-Received: by 2002:adf:f7cd:: with SMTP id a13mr7502095wrq.517.1643205277045; Wed, 26 Jan 2022 05:54:37 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n15sm3356593wmr.26.2022.01.26.05.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 05:54:36 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org Cc: devicetree@vger.kernel.org, ekangupt@qti.qualcomm.com, bkumar@qti.qualcomm.com, linux-kernel@vger.kernel.org, srini@kernel.org, bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, Vamsi Krishna Gattupalli , Srinivas Kandagatla Subject: [PATCH v3 10/12] misc: fastrpc: Add fdlist implementation Date: Wed, 26 Jan 2022 13:53:02 +0000 Message-Id: <20220126135304.16340-11-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> References: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Vamsi Krishna Gattupalli Add fdlist implementation to support dma handles. fdlist is populated by DSP if any map is no longer used and it is freed during put_args. Signed-off-by: Vamsi Krishna Gattupalli Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 1c1815bed2c2..6052a9cb9e2c 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -319,7 +319,8 @@ static void fastrpc_map_get(struct fastrpc_map *map) kref_get(&map->refcount); } -static int fastrpc_map_find(struct fastrpc_user *fl, int fd, + +static int fastrpc_map_lookup(struct fastrpc_user *fl, int fd, struct fastrpc_map **ppmap) { struct fastrpc_map *map = NULL; @@ -327,7 +328,6 @@ static int fastrpc_map_find(struct fastrpc_user *fl, int fd, mutex_lock(&fl->mutex); list_for_each_entry(map, &fl->maps, node) { if (map->fd == fd) { - fastrpc_map_get(map); *ppmap = map; mutex_unlock(&fl->mutex); return 0; @@ -338,6 +338,17 @@ static int fastrpc_map_find(struct fastrpc_user *fl, int fd, return -ENOENT; } +static int fastrpc_map_find(struct fastrpc_user *fl, int fd, + struct fastrpc_map **ppmap) +{ + int ret = fastrpc_map_lookup(fl, fd, ppmap); + + if (!ret) + fastrpc_map_get(*ppmap); + + return ret; +} + static void fastrpc_buf_free(struct fastrpc_buf *buf) { dma_free_coherent(buf->dev, buf->size, buf->virt, @@ -410,7 +421,7 @@ static void fastrpc_context_free(struct kref *ref) ctx = container_of(ref, struct fastrpc_invoke_ctx, refcount); cctx = ctx->cctx; - for (i = 0; i < ctx->nscalars; i++) + for (i = 0; i < ctx->nbufs; i++) fastrpc_map_put(ctx->maps[i]); if (ctx->buf) @@ -968,9 +979,19 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, u32 kernel) { struct fastrpc_remote_arg *rpra = ctx->rpra; - int i, inbufs; + struct fastrpc_user *fl = ctx->fl; + struct fastrpc_map *mmap = NULL; + struct fastrpc_invoke_buf *list; + struct fastrpc_phy_page *pages; + u64 *fdlist; + int i, inbufs, outbufs, handles; inbufs = REMOTE_SCALARS_INBUFS(ctx->sc); + outbufs = REMOTE_SCALARS_OUTBUFS(ctx->sc); + handles = REMOTE_SCALARS_INHANDLES(ctx->sc) + REMOTE_SCALARS_OUTHANDLES(ctx->sc); + list = fastrpc_invoke_buf_start(rpra, ctx->nscalars); + pages = fastrpc_phy_page_start(list, ctx->nscalars); + fdlist = (uint64_t *)(pages + inbufs + outbufs + handles); for (i = inbufs; i < ctx->nbufs; ++i) { if (!ctx->maps[i]) { @@ -987,6 +1008,13 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, } } + for (i = 0; i < FASTRPC_MAX_FDLIST; i++) { + if (!fdlist[i]) + break; + if (!fastrpc_map_lookup(fl, (int)fdlist[i], &mmap)) + fastrpc_map_put(mmap); + } + return 0; } From patchwork Wed Jan 26 13:53:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 537700 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC242C63686 for ; Wed, 26 Jan 2022 13:54:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241776AbiAZNy6 (ORCPT ); Wed, 26 Jan 2022 08:54:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241817AbiAZNyk (ORCPT ); Wed, 26 Jan 2022 08:54:40 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BBC5C06175D for ; Wed, 26 Jan 2022 05:54:39 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id s9so10099933wrb.6 for ; Wed, 26 Jan 2022 05:54:39 -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 :mime-version:content-transfer-encoding; bh=WiXyCfzx1/PxAADkZ89dPGp+bj7MoZkCRUrA9uccdQg=; b=jHhnKjNsPFzZO3rYA2Aat5q+VtxegiMsAaAq28uxHXaRUTBoeFijZa7ktj8cU7Mttf 1MAnvOBAbL4xpbvFqYK8xC8DebFuKfKEtrXOG9d648lUeP2WP4x1fmQl648lLEbMLPlI 5ftOgr/k/+BKPAk5Y+PRiI3GewznMpis4fhlqAMxaX7LQxl98G9jxw/iX4YKY0e7IxFM 1ixXZET+upkKm7OBcJa3gcKOgQMPNn84Lb+qykYy+oborzfd3g9M5o86VnhAmL55lcF0 tE6JfJ6RnADLKR0CzNWAPYAGSHvZvSNmEp6qt/Em0rvCNniLJ1qi5x49RQY45QHX8Aaw BZyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WiXyCfzx1/PxAADkZ89dPGp+bj7MoZkCRUrA9uccdQg=; b=IVZ7SELmMLo6kje20640bcc+ZcFrVyc9vPXP73qCBLIp9yrvFkt8I6lEXKrh+A4UQ+ 3afSJtPYkEtmAF4uBP1Hizcm1Kj8iv6Amik1HTTsK8KvjlbKckApUyb2KjI1cacrl7LW z/ccgJGTA7ujqyMRpiA5kYYW8I3XQZnN9i0OIlxH8ijepE6K94/ljAjiVH9eixmQ5IT6 I39Yio1nM1DOkv1P1ckyVtJFGo0pYgPllkhtcsCTQjQv34L5+87AVMaAN/xTA1Hrug2W uMTcwDn1MJUcerLxrxFGis8iY/1p1d2/Q7f2eLD9W6SEj/EdMoXdjpu8mkZnRWHiD3IM 0HRg== X-Gm-Message-State: AOAM530Q6+HH4dvUiClFC11TMY63Z5j6X01FFC+CSvg1imAemFVzyPb8 Kcs5CHgl8Anq+eTdnj/RdIvpqw== X-Google-Smtp-Source: ABdhPJyFC1EVf4ldevQ+b8/qXFk6SWSXEaoSZVE8eBaCf6cJqFZEGpQ5SdB88HZsUlsoL5SnWYOPFA== X-Received: by 2002:a5d:4c87:: with SMTP id z7mr22378536wrs.185.1643205278185; Wed, 26 Jan 2022 05:54:38 -0800 (PST) Received: from srini-hackbox.lan (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.gmail.com with ESMTPSA id n15sm3356593wmr.26.2022.01.26.05.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 05:54:37 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org Cc: devicetree@vger.kernel.org, ekangupt@qti.qualcomm.com, bkumar@qti.qualcomm.com, linux-kernel@vger.kernel.org, srini@kernel.org, bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, Vamsi Krishna Gattupalli , Srinivas Kandagatla Subject: [PATCH v3 11/12] misc: fastrpc: Add dma handle implementation Date: Wed, 26 Jan 2022 13:53:03 +0000 Message-Id: <20220126135304.16340-12-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> References: <20220126135304.16340-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Vamsi Krishna Gattupalli The remote arguments carry both remote buffers and dma handles. Add proper dma handle instructions to make it compatible with DSP implementation. Signed-off-by: Vamsi Krishna Gattupalli Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 52 +++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 6052a9cb9e2c..56ec7170b698 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -100,9 +100,20 @@ struct fastrpc_invoke_buf { u32 pgidx; /* index to start of contiguous region */ }; -struct fastrpc_remote_arg { - u64 pv; - u64 len; +struct fastrpc_remote_dmahandle { + s32 fd; /* dma handle fd */ + u32 offset; /* dma handle offset */ + u32 len; /* dma handle length */ +}; + +struct fastrpc_remote_buf { + u64 pv; /* buffer pointer */ + u64 len; /* length of buffer */ +}; + +union fastrpc_remote_arg { + struct fastrpc_remote_buf buf; + struct fastrpc_remote_dmahandle dma; }; struct fastrpc_mmap_rsp_msg { @@ -216,7 +227,7 @@ struct fastrpc_invoke_ctx { struct work_struct put_work; struct fastrpc_msg msg; struct fastrpc_user *fl; - struct fastrpc_remote_arg *rpra; + union fastrpc_remote_arg *rpra; struct fastrpc_map **maps; struct fastrpc_buf *buf; struct fastrpc_invoke_args *args; @@ -766,7 +777,7 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd, * >>>>>> START of METADATA <<<<<<<<< * +---------------------------------+ * | Arguments | - * | type:(struct fastrpc_remote_arg)| + * | type:(union fastrpc_remote_arg)| * | (0 - N) | * +---------------------------------+ * | Invoke Buffer list | @@ -791,7 +802,7 @@ static int fastrpc_get_meta_size(struct fastrpc_invoke_ctx *ctx) { int size = 0; - size = (sizeof(struct fastrpc_remote_arg) + + size = (sizeof(struct fastrpc_remote_buf) + sizeof(struct fastrpc_invoke_buf) + sizeof(struct fastrpc_phy_page)) * ctx->nscalars + sizeof(u64) * FASTRPC_MAX_FDLIST + @@ -856,7 +867,7 @@ static struct fastrpc_phy_page *fastrpc_phy_page_start(struct fastrpc_invoke_buf static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) { struct device *dev = ctx->fl->sctx->dev; - struct fastrpc_remote_arg *rpra; + union fastrpc_remote_arg *rpra; struct fastrpc_invoke_buf *list; struct fastrpc_phy_page *pages; int inbufs, i, oix, err = 0; @@ -892,8 +903,8 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) i = ctx->olaps[oix].raix; len = ctx->args[i].length; - rpra[i].pv = 0; - rpra[i].len = len; + rpra[i].buf.pv = 0; + rpra[i].buf.len = len; list[i].num = len ? 1 : 0; list[i].pgidx = i; @@ -903,7 +914,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) if (ctx->maps[i]) { struct vm_area_struct *vma = NULL; - rpra[i].pv = (u64) ctx->args[i].ptr; + rpra[i].buf.pv = (u64) ctx->args[i].ptr; pages[i].addr = ctx->maps[i]->phys; mmap_read_lock(current->mm); @@ -930,7 +941,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) if (rlen < mlen) goto bail; - rpra[i].pv = args - ctx->olaps[oix].offset; + rpra[i].buf.pv = args - ctx->olaps[oix].offset; pages[i].addr = ctx->buf->phys - ctx->olaps[oix].offset + (pkt_size - rlen); @@ -944,7 +955,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) } if (i < inbufs && !ctx->maps[i]) { - void *dst = (void *)(uintptr_t)rpra[i].pv; + void *dst = (void *)(uintptr_t)rpra[i].buf.pv; void *src = (void *)(uintptr_t)ctx->args[i].ptr; if (!kernel) { @@ -960,12 +971,15 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) } for (i = ctx->nbufs; i < ctx->nscalars; ++i) { - rpra[i].pv = (u64) ctx->args[i].ptr; - rpra[i].len = ctx->args[i].length; list[i].num = ctx->args[i].length ? 1 : 0; list[i].pgidx = i; - pages[i].addr = ctx->maps[i]->phys; - pages[i].size = ctx->maps[i]->size; + if (ctx->maps[i]) { + pages[i].addr = ctx->maps[i]->phys; + pages[i].size = ctx->maps[i]->size; + } + rpra[i].dma.fd = ctx->args[i].fd; + rpra[i].dma.len = ctx->args[i].length; + rpra[i].dma.offset = (u64) ctx->args[i].ptr; } bail: @@ -978,7 +992,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, u32 kernel) { - struct fastrpc_remote_arg *rpra = ctx->rpra; + union fastrpc_remote_arg *rpra = ctx->rpra; struct fastrpc_user *fl = ctx->fl; struct fastrpc_map *mmap = NULL; struct fastrpc_invoke_buf *list; @@ -995,9 +1009,9 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx, for (i = inbufs; i < ctx->nbufs; ++i) { if (!ctx->maps[i]) { - void *src = (void *)(uintptr_t)rpra[i].pv; + void *src = (void *)(uintptr_t)rpra[i].buf.pv; void *dst = (void *)(uintptr_t)ctx->args[i].ptr; - u64 len = rpra[i].len; + u64 len = rpra[i].buf.len; if (!kernel) { if (copy_to_user((void __user *)dst, src, len))