* fix on rt-tests of backfire kernel module
@ 2017-09-27 7:15 Michele Dionisio
2017-09-27 16:12 ` Julia Cartwright
2017-09-29 7:24 ` Uwe Kleine-König
0 siblings, 2 replies; 4+ messages in thread
From: Michele Dionisio @ 2017-09-27 7:15 UTC (permalink / raw)
To: linux-rt-users
[-- Attachment #1: Type: text/plain, Size: 208 bytes --]
Hi all,
I'm new in this mailing list. I start to work/test PREEPT_RT and
making some test I seee that there is a bug on backfire module in
rt-tests repository.
I'm attaching my patch.
best regards.
Michele
[-- Attachment #2: backfire_copyto_from_userspace.patch --]
[-- Type: text/x-patch, Size: 2513 bytes --]
From cd94ede8cf9eb8c26a196ea0111220969451cbb2 Mon Sep 17 00:00:00 2001
From: Michele Dionisio <michele.dionisio@powersoft.it>
Date: Tue, 26 Sep 2017 14:32:51 +0200
Subject: [FIX] fix copy data to and from userspace
diff --git a/src/backfire/backfire.c b/src/backfire/backfire.c
index aaf9c4a..b38651b 100644
--- a/src/backfire/backfire.c
+++ b/src/backfire/backfire.c
@@ -20,11 +20,9 @@
*/
#include <linux/module.h>
-
#include <linux/sched.h>
#include <linux/cpumask.h>
#include <linux/time.h>
-#include <linux/smp_lock.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
@@ -32,25 +30,33 @@
#include <linux/spinlock.h>
#include <asm/uaccess.h>
-#include <asm/system.h>
#define BACKFIRE_MINOR MISC_DYNAMIC_MINOR
-static spinlock_t backfire_state_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(backfire_state_lock);
static int backfire_open_cnt; /* #times opened */
static int backfire_open_mode; /* special open modes */
static struct timeval sendtime; /* when the most recent signal was sent */
#define BACKFIRE_WRITE 1 /* opened for writing (exclusive) */
#define BACKFIRE_EXCL 2 /* opened with O_EXCL */
+#define MAX_SIZE_DATA_RW 512
+
/*
* These are the file operation function for user access to /dev/backfire
*/
static ssize_t
backfire_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
- return snprintf(buf, count, "%d,%d\n", (int) sendtime.tv_sec,
+ char kbuf[MAX_SIZE_DATA_RW];
+ ssize_t res;
+ if (count > MAX_SIZE_DATA_RW) {
+ count = MAX_SIZE_DATA_RW;
+ }
+ res = snprintf(kbuf, count, "%d,%d\n", (int) sendtime.tv_sec,
(int) sendtime.tv_usec);
+ copy_to_user(buf, kbuf, res+1);
+ return res;
}
static ssize_t
@@ -58,16 +64,28 @@ backfire_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
{
int signo;
struct pid *pid;
-
- if (sscanf(buf, "%d", &signo) >= 1) {
+ char kbuf[MAX_SIZE_DATA_RW+1];
+ ssize_t retval = 0;
+
+ if (count == 0) {
+ return 0;
+ }
+ if (count > MAX_SIZE_DATA_RW) {
+ count = MAX_SIZE_DATA_RW;
+ }
+ copy_from_user(kbuf, buf, count);
+ kbuf[count] = '\0';
+
+ if (sscanf(kbuf, "%d", &signo) >= 1) {
if (signo > 0 && signo < 32) {
pid = get_pid(task_pid(current));
do_gettimeofday(&sendtime);
kill_pid(pid, signo, 1);
+ retval = strlen(kbuf);
} else
printk(KERN_ERR "Invalid signal no. %d\n", signo);
}
- return strlen(buf);
+ return retval;
}
static int
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: fix on rt-tests of backfire kernel module
2017-09-27 7:15 fix on rt-tests of backfire kernel module Michele Dionisio
@ 2017-09-27 16:12 ` Julia Cartwright
2017-09-29 7:24 ` Uwe Kleine-König
1 sibling, 0 replies; 4+ messages in thread
From: Julia Cartwright @ 2017-09-27 16:12 UTC (permalink / raw)
To: Michele Dionisio; +Cc: linux-rt-users, John Kacur, Clark Williams
On Wed, Sep 27, 2017 at 09:15:11AM +0200, Michele Dionisio wrote:
> Hi all,
>
> I'm new in this mailing list.
Welcome!
> I start to work/test PREEPT_RT and making some test I seee that there
> is a bug on backfire module in rt-tests repository.
At the very least, you'll want to elaborate on the bug you were seeing.
What broke? What did you expect to see? What did you see instead? Is
this a build time problem? A run-time problem? How does your fix
prevent this problem from occurring?
Also, for rt-tests patches, you'll want to ensure to CC John Kacur and
Clark Williams, who are maintaining the project.
> I'm attaching my patch.
>
> best regards.
> Michele
> From cd94ede8cf9eb8c26a196ea0111220969451cbb2 Mon Sep 17 00:00:00 2001
> From: Michele Dionisio <michele.dionisio@powersoft.it>
> Date: Tue, 26 Sep 2017 14:32:51 +0200
> Subject: [FIX] fix copy data to and from userspace
You'll want to include a changelog here, describing the above. This is
what will go into the git permanent history.
> diff --git a/src/backfire/backfire.c b/src/backfire/backfire.c
> index aaf9c4a..b38651b 100644
> --- a/src/backfire/backfire.c
> +++ b/src/backfire/backfire.c
> @@ -20,11 +20,9 @@
[..]
> +#define MAX_SIZE_DATA_RW 512
> +
> /*
> * These are the file operation function for user access to /dev/backfire
> */
> static ssize_t
> backfire_read(struct file *file, char *buf, size_t count, loff_t *ppos)
> {
> - return snprintf(buf, count, "%d,%d\n", (int) sendtime.tv_sec,
> + char kbuf[MAX_SIZE_DATA_RW];
> + ssize_t res;
> + if (count > MAX_SIZE_DATA_RW) {
> + count = MAX_SIZE_DATA_RW;
> + }
> + res = snprintf(kbuf, count, "%d,%d\n", (int) sendtime.tv_sec,
> (int) sendtime.tv_usec);
> + copy_to_user(buf, kbuf, res+1);
> + return res;
Your patch is also whitespace damaged. You'll want to ensure to follow
the kernel's CodingStyle here (which is 8-space tabstops).
Julia
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fix on rt-tests of backfire kernel module
2017-09-27 7:15 fix on rt-tests of backfire kernel module Michele Dionisio
2017-09-27 16:12 ` Julia Cartwright
@ 2017-09-29 7:24 ` Uwe Kleine-König
2017-09-29 8:11 ` michele.dionisio
1 sibling, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2017-09-29 7:24 UTC (permalink / raw)
To: Michele Dionisio; +Cc: linux-rt-users
Hello Michele,
On Wed, Sep 27, 2017 at 09:15:11AM +0200, Michele Dionisio wrote:
> Hi all,
> I'm new in this mailing list. I start to work/test PREEPT_RT and
> making some test I seee that there is a bug on backfire module in
> rt-tests repository.
>
> I'm attaching my patch.
I didn't look in detail into your patch, but I guess most of your stuff
was already addressed before in a thread here. See
https://marc.info/?t=131384496800001&r=1&w=2
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: fix on rt-tests of backfire kernel module
2017-09-29 7:24 ` Uwe Kleine-König
@ 2017-09-29 8:11 ` michele.dionisio
0 siblings, 0 replies; 4+ messages in thread
From: michele.dionisio @ 2017-09-29 8:11 UTC (permalink / raw)
To: u.kleine-koenig; +Cc: linux-rt-users
Ok. It is true. The only missing part is copy from/to userspace.
If you suggest me a git repo from where i can start to work I will prepare a better patch with only that fix.
Regards
Il Venerdì 29 settembre 2017, Uwe Kleine-König scrive:
> Hello Michele,
>
> On Wed, Sep 27, 2017 at 09:15:11AM +0200, Michele Dionisio wrote:
> > Hi all,
> > I'm new in this mailing list. I start to work/test PREEPT_RT and
> > making some test I seee that there is a bug on backfire module in
> > rt-tests repository.
> >
> > I'm attaching my patch.
>
> I didn't look in detail into your patch, but I guess most of your stuff
> was already addressed before in a thread here. See
>
> https://marc.info/?t=131384496800001&r=1&w=2
>
> Best regards
> Uwe
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | http://www.pengutronix.de/ |
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-09-29 8:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-27 7:15 fix on rt-tests of backfire kernel module Michele Dionisio
2017-09-27 16:12 ` Julia Cartwright
2017-09-29 7:24 ` Uwe Kleine-König
2017-09-29 8:11 ` michele.dionisio
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).