From patchwork Mon Jan 14 19:41:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 155581 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4040850jaa; Mon, 14 Jan 2019 11:42:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN6/+sY0ZriPr29nVP91MVKttYjrx0lV8ekVDnLKcZYf6Z6mQetLzONOLO+5gELnrGGGbbVQ X-Received: by 2002:a62:5884:: with SMTP id m126mr74430pfb.177.1547494963479; Mon, 14 Jan 2019 11:42:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547494963; cv=none; d=google.com; s=arc-20160816; b=WKmgbplwQkI+bFEN3pI0MZEj/4buP7N8Gq8OErrvfJKKl17r+b0jCYzZeuMfcWph8g zJG7eZoz1mwlSwEnyrxEMSs1Q98UHUoNsGL37nUZA0Ugv5RevACukPrI2w2XY6ukDUR1 /YwVdAy6cf77VN4VPf7Fo6n48YoBEWsvq2469iQgaChZ6gCi2HEqDtG7Qc5gXcnSvy8F +sVczq1Y6IcQ+ULENbfdKe/R1n7PFrDonJiaxMXPAshtOHxch/xFQhnSTCFiWOjLeN5M 7TGoOhcXEgOvsw5TNWkoIWsV7bPo2w9Jcc3kZbA14fyenLMLLCQia4LG6qzvldLIkM5w KPlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TGWMRgUa84leIvqNdPnLVf/SH/izWExH3OfySwLQBtc=; b=J1VJ+eYUn9ormV8vNDkX35oFbKt/K3CGPtUF7m3VcqxC10nV6hXdhRwurkNWwRxlmW lO+svMfSBkK86b1L7tluN8k2uWnR6Boh7I72C5CaLXeOhv/lPaT2TwNwDvEc13SRePHh +iUMAuE2UNastVc4duRJbgg/s7P10NhOfkYmYi8Jln6We4lwP6qRwBXG8B26s3xYAYYf r7NoQlSm73nQODRnezamisxe8+f6nMB4OUiUwoHOYkpA4XZ9jhD7ij56xCOpCyexlgMT SLqIvKW9qMKu0ncZwC4w4z5YU//oiEZyQqE0Mgqix6CGcU/oX32op6qXvI4381kIaxYE byiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=br3FnU4G; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y73si1017425pgd.478.2019.01.14.11.42.43; Mon, 14 Jan 2019 11:42:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=br3FnU4G; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726943AbfANTmW (ORCPT + 15 others); Mon, 14 Jan 2019 14:42:22 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39271 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726910AbfANTmW (ORCPT ); Mon, 14 Jan 2019 14:42:22 -0500 Received: by mail-wm1-f67.google.com with SMTP id y8so827080wmi.4 for ; Mon, 14 Jan 2019 11:42:20 -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=TGWMRgUa84leIvqNdPnLVf/SH/izWExH3OfySwLQBtc=; b=br3FnU4Gy9vKFnmadRUEn+ySuQhx1TLmNcHsX9lSmXToW/fCrcIrVDXVFEAYbDhyc2 onw56Vm7miEoRIvEOQeNDetPuihdNj+CgULgPGEGBbu2rrbjTOa0XsCiXtM/nHkOLSoc WpaKqOYufCBH6wC578d9ZADwvKK30aNXFbfOM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TGWMRgUa84leIvqNdPnLVf/SH/izWExH3OfySwLQBtc=; b=mByP2bYUWwIKe8e4ka0+TuDNZ4LgsMtbE+Wdl0v5cNqZ9n5IWkj7yW626Gxdab2Q5o EFCBLu3UY/YS3XNfUel0zpTsu2Qn6s4L6pfWptqJfgHKkFnIoMo7SGZ1AAxjr+pXivDk pqzYgLGIGgjiv+RZJVV2ziO8ehEVOne6zIDe9KxbmpICWRprYrJKBAt1EW15a7pcnpMD JCQCzLn28wbFx7e6T3ASzqyi8g1VWajIGIQq21MjUWDojHs8hDfhd5G2s9GzNEbQlYL4 mOnVej8jDsUjncsndhOr6pJHrfAfp2HebvlESqo/ufd7uzZdfiIvDvalAk09+1Y+aq52 b9Kw== X-Gm-Message-State: AJcUukeoRy4txRptCB/UPz5/vJUc0IIim41T0OlMe4qtSkH6giudBs3t MRivOuZjfKsnnZrqkGni4eH+CA== X-Received: by 2002:a1c:2902:: with SMTP id p2mr529173wmp.19.1547494939238; Mon, 14 Jan 2019 11:42:19 -0800 (PST) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id b7sm66779996wrs.47.2019.01.14.11.42.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Jan 2019 11:42:18 -0800 (PST) From: Srinivas Kandagatla To: robh+dt@kernel.org, gregkh@linuxfoundation.org, arnd@arndb.de Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, bjorn.andersson@linaro.org, bkumar@qti.qualcomm.com, linux-arm-msm@vger.kernel.org, thierry.escande@linaro.org, Srinivas Kandagatla Subject: [PATCH v3 4/5] misc: fastrpc: Add support for create remote init process Date: Mon, 14 Jan 2019 19:41:11 +0000 Message-Id: <20190114194112.32567-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190114194112.32567-1-srinivas.kandagatla@linaro.org> References: <20190114194112.32567-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This patch adds support to create or attach remote shell process. The shell process called fastrpc_shell_0 is usually loaded on the DSP when a user process is spawned. Most of the work is derived from various downstream Qualcomm kernels. Credits to various Qualcomm authors who have contributed to this code. Specially Tharun Kumar Merugu Co-developed-by: Thierry Escande Signed-off-by: Thierry Escande Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 141 +++++++++++++++++++++++++++++++++++- include/uapi/misc/fastrpc.h | 10 +++ 2 files changed, 150 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 6745e164ef12..c93960b5f3a5 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -29,7 +29,10 @@ #define FASTRPC_MAX_CRCLIST 64 #define FASTRPC_PHYS(p) ((p) & 0xffffffff) #define FASTRPC_CTX_MAX (256) +#define FASTRPC_INIT_HANDLE 1 #define FASTRPC_CTXID_MASK (0xFF0) +#define INIT_FILELEN_MAX (2 * 1024 * 1024) +#define INIT_MEMLEN_MAX (8 * 1024 * 1024) #define FASTRPC_DEVICE_NAME "fastrpc" /* Retrives number of input buffers from the scalars parameter */ @@ -60,6 +63,13 @@ #define FASTRPC_SCALARS(method, in, out) \ FASTRPC_BUILD_SCALARS(0, method, in, out, 0, 0) +/* Remote Method id table */ +#define FASTRPC_RMID_INIT_ATTACH 0 +#define FASTRPC_RMID_INIT_RELEASE 1 +#define FASTRPC_RMID_INIT_CREATE 6 +#define FASTRPC_RMID_INIT_CREATE_ATTR 7 +#define FASTRPC_RMID_INIT_CREATE_STATIC 8 + #define miscdev_to_cctx(d) container_of(d, struct fastrpc_channel_ctx, miscdev) static const char *domains[FASTRPC_DEV_MAX] = { "adsp", "mdsp", @@ -667,7 +677,96 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, fastrpc_context_free(ctx); if (err) - dev_err(fl->sctx->dev, "Error: Invoke Failed %d\n", err); + dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err); + + return err; +} + +static int fastrpc_init_create_process(struct fastrpc_user *fl, + char __user *argp) +{ + struct fastrpc_init_create init; + struct fastrpc_invoke_args args[6]; + struct fastrpc_phy_page pages[1]; + struct fastrpc_map *map = NULL; + struct fastrpc_buf *imem = NULL; + int memlen; + int err; + struct { + int pgid; + u32 namelen; + u32 filelen; + u32 pageslen; + u32 attrs; + u32 siglen; + } inbuf; + u32 sc; + + if (copy_from_user(&init, argp, sizeof(init))) + return -EFAULT; + + if (init.filelen > INIT_FILELEN_MAX) + return -EINVAL; + + inbuf.pgid = fl->tgid; + inbuf.namelen = strlen(current->comm) + 1; + inbuf.filelen = init.filelen; + inbuf.pageslen = 1; + inbuf.attrs = init.attrs; + inbuf.siglen = init.siglen; + fl->pd = 1; + + if (init.filelen && init.filefd) { + err = fastrpc_map_create(fl, init.filefd, init.filelen, &map); + if (err) + goto bail; + } + + memlen = ALIGN(max(INIT_FILELEN_MAX, (int)init.filelen * 4), + 1024 * 1024); + err = fastrpc_buf_alloc(fl, fl->sctx->dev, memlen, + &imem); + if (err) + goto bail; + + fl->init_mem = imem; + args[0].ptr = (u64)(uintptr_t)&inbuf; + args[0].length = sizeof(inbuf); + args[0].fd = -1; + + args[1].ptr = (u64)(uintptr_t)current->comm; + args[1].length = inbuf.namelen; + args[1].fd = -1; + + args[2].ptr = (u64) init.file; + args[2].length = inbuf.filelen; + args[2].fd = init.filefd; + + pages[0].addr = imem->phys; + pages[0].size = imem->size; + + args[3].ptr = (u64)(uintptr_t) pages; + args[3].length = 1 * sizeof(*pages); + args[3].fd = -1; + + args[4].ptr = (u64)(uintptr_t)&inbuf.attrs; + args[4].length = sizeof(inbuf.attrs); + args[4].fd = -1; + + args[5].ptr = (u64)(uintptr_t) &inbuf.siglen; + args[5].length = sizeof(inbuf.siglen); + args[5].fd = -1; + + sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE, 4, 0); + if (init.attrs) + sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE_ATTR, 6, 0); + + err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, + sc, &args[0]); + +bail: + if (map) + fastrpc_map_put(map); return err; } @@ -701,6 +800,22 @@ static void fastrpc_session_free(struct fastrpc_channel_ctx *cctx, spin_unlock(&cctx->lock); } +static int fastrpc_release_current_dsp_process(struct fastrpc_user *fl) +{ + struct fastrpc_invoke_args args[1]; + int tgid = 0; + u32 sc; + + tgid = fl->tgid; + args[0].ptr = (u64)(uintptr_t) &tgid; + args[0].length = sizeof(tgid); + args[0].fd = -1; + sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_RELEASE, 1, 0); + + return fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, + sc, &args[0]); +} + static int fastrpc_device_release(struct inode *inode, struct file *file) { struct fastrpc_user *fl = (struct fastrpc_user *)file->private_data; @@ -708,6 +823,8 @@ static int fastrpc_device_release(struct inode *inode, struct file *file) struct fastrpc_invoke_ctx *ctx, *n; struct fastrpc_map *map, *m; + fastrpc_release_current_dsp_process(fl); + spin_lock(&cctx->lock); list_del(&fl->user); spin_unlock(&cctx->lock); @@ -755,6 +872,22 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) return 0; } +static int fastrpc_init_attach(struct fastrpc_user *fl) +{ + struct fastrpc_invoke_args args[1]; + int tgid = fl->tgid; + u32 sc; + + args[0].ptr = (u64)(uintptr_t) &tgid; + args[0].length = sizeof(tgid); + args[0].fd = -1; + sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_ATTACH, 1, 0); + fl->pd = 0; + + return fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, + sc, &args[0]); +} + static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp) { struct fastrpc_invoke_args *args = NULL; @@ -795,6 +928,12 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd, case FASTRPC_IOCTL_INVOKE: err = fastrpc_invoke(fl, argp); break; + case FASTRPC_IOCTL_INIT_ATTACH: + err = fastrpc_init_attach(fl); + break; + case FASTRPC_IOCTL_INIT_CREATE: + err = fastrpc_init_create_process(fl, argp); + break; default: err = -ENOTTY; dev_err(fl->sctx->dev, "bad ioctl: %d\n", cmd); diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h index a69ef33dc37e..32d191c3b7bc 100644 --- a/include/uapi/misc/fastrpc.h +++ b/include/uapi/misc/fastrpc.h @@ -6,6 +6,8 @@ #include #define FASTRPC_IOCTL_INVOKE _IOWR('R', 3, struct fastrpc_invoke) +#define FASTRPC_IOCTL_INIT_ATTACH _IO('R', 4) +#define FASTRPC_IOCTL_INIT_CREATE _IOWR('R', 5, struct fastrpc_init_create) struct fastrpc_invoke_args { __u64 ptr; @@ -20,4 +22,12 @@ struct fastrpc_invoke { __u64 args; }; +struct fastrpc_init_create { + __u32 filelen; /* elf file length */ + __s32 filefd; /* fd for the file */ + __u32 attrs; + __u32 siglen; + __u64 file; /* pointer to elf file */ +}; + #endif /* __QCOM_FASTRPC_H__ */