Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4131220yba; Wed, 17 Apr 2019 05:22:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqziSYfBoAISrvQd+lrpe6ggOzCKFFoT1cUEve0ALp2lXBvP0hFdgeX3PQ6J7jucikQIMI23 X-Received: by 2002:aa7:8c86:: with SMTP id p6mr90467389pfd.37.1555503777611; Wed, 17 Apr 2019 05:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555503777; cv=none; d=google.com; s=arc-20160816; b=g0HjGrOY8fx/5/Z/92HD6ody0hYiGiUvX7A2B+bm//AgX/QRgOdYeyxujFZua144ay cZVVd92qRkzlfltauhNnituIHDPCzLw+v+MU+JH3IMXI+Bk/CeEJqm+ONQO7PxTdxWQG toupNSWM7Eyr1KyfGI3raxnY0mvRcJmLT2GJd0XL60r42WP2iooXjKCDLGzv+VuHaE8S YfaV3Bsn6eFm/fPbh5WNaVf4zI752VZCNGzX2TG3ulyWYn10kHrGMVKBs7nZcXW3wc8V qf1t9k4DPYROZbBIBZdotg5KABts/sqG0cyWbx0D/iMoOez83h/2HZBi014hLkTuRHFj cI8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=CC+tRpdsI+a3D0fI2iQ23XwuzqysafA+XUzauMHmBi0=; b=OUHDxOn0/y+OPv+KHHM0QEObVwYoikgXCQ657jOiBuloYKQhWBl5v7Yj488VermNmH GpYZgLrPodMf3h0juIx44JWAHp1KzOL70DmGsZ17Cj4p8y04cL+K5zRKdEiCHAnVmVfJ ChlVDtNll6/8w5pEQiNhQc6QyyN96KpT2VBMfDdGJHbJnJzz9zGh8onq9Pt+WMv4MqCi SN783XFOE7p3v96nm9NFP8NXQg05Uf160/2tfubC0yGSKDMDtpLUkEEd5Q/WtjaQTumR 1mSgvaZdNF0FOF+LGtiZmXBf9LrlY0zbylF71X3Uzf9cs3gk/VzrgHw7YjkLdGjGYwSV t6tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Rqj5p3VN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 19si49494939pgl.402.2019.04.17.05.22.37; Wed, 17 Apr 2019 05:22:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@gmail.com header.s=20161025 header.b=Rqj5p3VN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732063AbfDQMVl (ORCPT + 99 others); Wed, 17 Apr 2019 08:21:41 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46327 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731790AbfDQMVj (ORCPT ); Wed, 17 Apr 2019 08:21:39 -0400 Received: by mail-wr1-f68.google.com with SMTP id t17so31617588wrw.13 for ; Wed, 17 Apr 2019 05:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CC+tRpdsI+a3D0fI2iQ23XwuzqysafA+XUzauMHmBi0=; b=Rqj5p3VNASRM06zPVlRTzFfUIjzAjXGZwJAu0OmYVenyW9vPoLe8JTGWrdzHe4qYTh 1FegmSYnwoLWm0X16D6GKrljGDOnwkSocx5kHMMLV+vzFJKEYLKH3R/p5hZ4vW7CW4CE Lkr4GOzSt9ItSNCKJtD0L8VNuULcoRFSHp5+WWDEKv/3BbjSICv6JnymQjd+d2Mh1/tq ODDcWrHXVJ7OXv/woePmbvV9fwMOk0E2srwQFvB2poOBXusDe55zLKHGtCYJQGSBMArL sAlB9CiYGVI4h7CEb7oYH/6p5b1lD1wtaOVqkCmjq7Dlqu4tqUqBTjUbZSxKIPrH5zem Lz8Q== 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; bh=CC+tRpdsI+a3D0fI2iQ23XwuzqysafA+XUzauMHmBi0=; b=AYY/hcovXDIDb7kymU6W1KmRiwZ83FoMDjb5pI3zY2G+J6HcYYeTDtG15Dvhscpz8I 133joOo7YZEjBfL8mCG1cp3iE6aK5vVlTOTdRduceGxDyyELZeiNZGkH+mGHpmfl/ntD rcSMkpz/YebbEqBActvr/5fRd9zLqcl4yY1Unh0g/vDjspQqdV4+zv3fTmHL1BPKkR4c y0m6gwqIKFNCcOi4ut0WGdzggh2Rb9Kk+g46Fhlg0mnNPNXL6DR1OFnOoZXHpmc2XHXy NQYpCBZkWlKTun948qIC9jMzTKzJjN61zuPoD3e/dqU7hvyQPDbi+RmjZu0MeNFGJ/5x ta1g== X-Gm-Message-State: APjAAAV4xw7GukDT6DnL9DXg0NVUybp1le+KGpJi5aFR8JYv35wA/aTL gPVmViUD5uPgpZnFI7RhjGo= X-Received: by 2002:adf:dd82:: with SMTP id x2mr17003768wrl.214.1555503698147; Wed, 17 Apr 2019 05:21:38 -0700 (PDT) Received: from ghost.lan ([94.11.212.240]) by smtp.gmail.com with ESMTPSA id g84sm3810696wmf.25.2019.04.17.05.21.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 05:21:37 -0700 (PDT) From: Okash Khawaja To: Greg Kroah-Hartman , Samuel Thibault , Gregory Nowak , linux-kernel@vger.kernel.org Cc: Jiri Slaby , Alan Cox , Ben Hutchings , William Hubbs , Chris Brannon , Kirk Reiser , John Covici , Peter Hurley , devel@driverdev.osuosl.org, speakup@linux-speakup.org, Okash Khawaja Subject: [PATCH v2 1/2] vt: selection: allow functions to be called from inside kernel Date: Wed, 17 Apr 2019 13:21:13 +0100 Message-Id: <1555503674-8219-2-git-send-email-okash.khawaja@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1555503674-8219-1-git-send-email-okash.khawaja@gmail.com> References: <1555503674-8219-1-git-send-email-okash.khawaja@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch breaks set_selection() into two functions so that when called from kernel, copy_from_user() can be avoided. The two functions are called set_selection_user() and set_selection_kernel() in order to be explicit about their purposes. This also means updating any references to set_selection() and fixing for name change. It also exports set_selection_kernel() and paste_selection(). These changes are used the following patch where speakup's selection functionality calls into the above functions, thereby doing away with parallel implementation. Signed-off-by: Okash Khawaja Reviewed-by: Samuel Thibault Tested-by: Gregory Nowak --- drivers/tty/vt/selection.c | 46 ++++++++++++++++++++++++++++++---------------- drivers/tty/vt/vt.c | 7 ++++--- include/linux/selection.h | 7 ++++--- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c index 07496c7..78732fe 100644 --- a/drivers/tty/vt/selection.c +++ b/drivers/tty/vt/selection.c @@ -2,7 +2,9 @@ /* * This module exports the functions: * - * 'int set_selection(struct tiocl_selection __user *, struct tty_struct *)' + * 'int set_selection_user(struct tiocl_selection __user *, + * struct tty_struct *)' + * 'int set_selection_kernel(struct tiocl_selection *, struct tty_struct *)' * 'void clear_selection(void)' * 'int paste_selection(struct tty_struct *)' * 'int sel_loadlut(char __user *)' @@ -80,6 +82,7 @@ void clear_selection(void) sel_start = -1; } } +EXPORT_SYMBOL_GPL(clear_selection); /* * User settable table: what characters are to be considered alphabetic? @@ -154,7 +157,7 @@ static int store_utf8(u32 c, char *p) } /** - * set_selection - set the current selection. + * set_selection_user - set the current selection. * @sel: user selection info * @tty: the console tty * @@ -163,35 +166,44 @@ static int store_utf8(u32 c, char *p) * The entire selection process is managed under the console_lock. It's * a lot under the lock but its hardly a performance path */ -int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty) +int set_selection_user(const struct tiocl_selection __user *sel, + struct tty_struct *tty) +{ + struct tiocl_selection v; + + if (copy_from_user(&v, sel, sizeof(*sel))) + return -EFAULT; + + return set_selection_kernel(&v, tty); +} + +int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty) { struct vc_data *vc = vc_cons[fg_console].d; int new_sel_start, new_sel_end, spc; - struct tiocl_selection v; char *bp, *obp; int i, ps, pe, multiplier; u32 c; int mode; poke_blanked_console(); - if (copy_from_user(&v, sel, sizeof(*sel))) - return -EFAULT; - v.xs = min_t(u16, v.xs - 1, vc->vc_cols - 1); - v.ys = min_t(u16, v.ys - 1, vc->vc_rows - 1); - v.xe = min_t(u16, v.xe - 1, vc->vc_cols - 1); - v.ye = min_t(u16, v.ye - 1, vc->vc_rows - 1); - ps = v.ys * vc->vc_size_row + (v.xs << 1); - pe = v.ye * vc->vc_size_row + (v.xe << 1); + v->xs = min_t(u16, v->xs - 1, vc->vc_cols - 1); + v->ys = min_t(u16, v->ys - 1, vc->vc_rows - 1); + v->xe = min_t(u16, v->xe - 1, vc->vc_cols - 1); + v->ye = min_t(u16, v->ye - 1, vc->vc_rows - 1); + ps = v->ys * vc->vc_size_row + (v->xs << 1); + pe = v->ye * vc->vc_size_row + (v->xe << 1); - if (v.sel_mode == TIOCL_SELCLEAR) { + if (v->sel_mode == TIOCL_SELCLEAR) { /* useful for screendump without selection highlights */ clear_selection(); return 0; } - if (mouse_reporting() && (v.sel_mode & TIOCL_SELMOUSEREPORT)) { - mouse_report(tty, v.sel_mode & TIOCL_SELBUTTONMASK, v.xs, v.ys); + if (mouse_reporting() && (v->sel_mode & TIOCL_SELMOUSEREPORT)) { + mouse_report(tty, v->sel_mode & TIOCL_SELBUTTONMASK, v->xs, + v->ys); return 0; } @@ -208,7 +220,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t else use_unicode = 0; - switch (v.sel_mode) + switch (v->sel_mode) { case TIOCL_SELCHAR: /* character-by-character selection */ new_sel_start = ps; @@ -322,6 +334,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t sel_buffer_lth = bp - sel_buffer; return 0; } +EXPORT_SYMBOL_GPL(set_selection_kernel); /* Insert the contents of the selection buffer into the * queue of the tty associated with the current console. @@ -367,3 +380,4 @@ int paste_selection(struct tty_struct *tty) tty_ldisc_deref(ld); return 0; } +EXPORT_SYMBOL_GPL(paste_selection); diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index d34984a..f3c369a 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -1804,7 +1804,7 @@ void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry) respond_string(buf, tty->port); } -/* invoked via ioctl(TIOCLINUX) and through set_selection */ +/* invoked via ioctl(TIOCLINUX) and through set_selection_user */ int mouse_reporting(void) { return vc_cons[fg_console].d->vc_report_mouse; @@ -3008,7 +3008,7 @@ static struct tty_driver *vt_console_device(struct console *c, int *index) * There are some functions which can sleep for arbitrary periods * (paste_selection) but we don't need the lock there anyway. * - * set_selection has locking, and definitely needs it + * set_selection_user has locking, and definitely needs it */ int tioclinux(struct tty_struct *tty, unsigned long arg) @@ -3028,7 +3028,8 @@ int tioclinux(struct tty_struct *tty, unsigned long arg) { case TIOCL_SETSEL: console_lock(); - ret = set_selection((struct tiocl_selection __user *)(p+1), tty); + ret = set_selection_user((struct tiocl_selection + __user *)(p+1), tty); console_unlock(); break; case TIOCL_PASTESEL: diff --git a/include/linux/selection.h b/include/linux/selection.h index a8f5b97..e2c1f96 100644 --- a/include/linux/selection.h +++ b/include/linux/selection.h @@ -11,13 +11,14 @@ #include #include -struct tty_struct; - extern struct vc_data *sel_cons; struct tty_struct; extern void clear_selection(void); -extern int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty); +extern int set_selection_user(const struct tiocl_selection __user *sel, + struct tty_struct *tty); +extern int set_selection_kernel(struct tiocl_selection *v, + struct tty_struct *tty); extern int paste_selection(struct tty_struct *tty); extern int sel_loadlut(char __user *p); extern int mouse_reporting(void); -- 1.8.3.1