Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Apr 2024 22:21:12 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Rocky Hotas <rockyhotas@tilde.team>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: Re: Kernel module: return a number from a device
Message-ID:  <CANCZdfrN3HnqfLLptMF5PBaNGpDDkC-LwGCCzMj6unAw=U-JnQ@mail.gmail.com>
In-Reply-To: <qarvyeobx2iumkc3ae6noaiukffpfgwihap32vi4yaqnkqigbi@3nxb4nmvub32>
References:  <CANCZdfqAUWqp_s8ULhi9A97jrMCxA1CAXJKmUJ307=PSpekKug@mail.gmail.com> <qarvyeobx2iumkc3ae6noaiukffpfgwihap32vi4yaqnkqigbi@3nxb4nmvub32>

next in thread | previous in thread | raw e-mail | index | archive | help
--000000000000a21afa06157a0538
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sat, Apr 6, 2024 at 3:00=E2=80=AFPM Rocky Hotas <rockyhotas@tilde.team> =
wrote:

> On apr 06 14:39, Warner Losh wrote:
> > When this happens, hit ^t (control t). That will give a traceback of th=
e
> > call stack which may help you track down where it is hanging (most like=
ly
> > something is sleeping waiting for an event).
>
> Thanks! It seems that cat itself is hanging (so, uiomove can still be
> the
> culprit...):
>
> $ cat rolld
> Opened device "rolld" successfully.
> load: 0.44  cmd: cat 13392 [running] 7.67r 1.25u 6.39s 38% 1936k
>

running means there's a tight loop somewhere... uiomove doesn't do that. It
is a bunch of ifs that go to a copyout.  Arc4random shouldn't either. I'd
add printf to see where.




> I also tried to modify rolld_read using only char variables:
>
> static int
> rolld_read(struct cdev *dev __unused, struct uio *uio, int ioflag
> __unused)
> {
>         char random_out;
>         char random_item;
>         int error;
>
>         random_item =3D (char) arc4random();
>         random_out =3D random_item % d_size;
>
>         if ((error =3D uiomove(&random_out, 1, uio)) !=3D 0)
>                 uprintf("uiomove failed!\n");
>
>         return (error);
> }
>
>
> But nothing changed with respect to the first version.
>

This should produce an infinite number of chars...  maybe it is and d_size
is 1 and they are all NULs. Try cat -v.

Warner


> Rocky
>
>

--000000000000a21afa06157a0538
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto"><div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div clas=
s=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, Apr 6, 2024=
 at 3:00=E2=80=AFPM Rocky Hotas &lt;rockyhotas@tilde.team&gt; wrote:<br></d=
iv><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bord=
er-left:1px solid rgb(204,204,204);padding-left:1ex">On apr 06 14:39, Warne=
r Losh wrote:<br>
&gt; When this happens, hit ^t (control t). That will give a traceback of t=
he<br>
&gt; call stack which may help you track down where it is hanging (most lik=
ely<br>
&gt; something is sleeping waiting for an event).<br>
<br>
Thanks! It seems that cat itself is hanging (so, uiomove can still be<br>
the<br>
culprit...):<br>
<br>
$ cat rolld <br>
Opened device &quot;rolld&quot; successfully.<br>
load: 0.44=C2=A0 cmd: cat 13392 [running] 7.67r 1.25u 6.39s 38% 1936k<br></=
blockquote><div><br></div><div>running means there&#39;s a tight loop somew=
here... uiomove doesn&#39;t do that. It is a bunch of ifs that go to a copy=
out.=C2=A0 Arc4random shouldn&#39;t either. I&#39;d add printf to see where=
.</div><div><br></div><div><br></div><div>=C2=A0</div><blockquote class=3D"=
gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(20=
4,204,204);padding-left:1ex">
I also tried to modify rolld_read using only char variables:<br>
<br>
static int<br>
rolld_read(struct cdev *dev __unused, struct uio *uio, int ioflag<br>
__unused)<br>
{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 char random_out;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 char random_item;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 int error;<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 random_item =3D (char) arc4random();<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 random_out =3D random_item % d_size;<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if ((error =3D uiomove(&amp;random_out, 1, uio)=
) !=3D 0)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 uprintf(&quot;uiomo=
ve failed!\n&quot;);<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return (error);<br>
}<br>
<br>
<br>
But nothing changed with respect to the first version.<br></blockquote></di=
v></div><div dir=3D"auto"><br></div><div dir=3D"auto">This should produce a=
n infinite number of chars...=C2=A0 maybe it is and d_size is 1 and they ar=
e all NULs. Try cat -v.</div><div dir=3D"auto"><br></div><div dir=3D"auto">=
Warner</div><div dir=3D"auto"><br></div><div dir=3D"ltr"><div class=3D"gmai=
l_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Rocky<br>
<br>
</blockquote></div></div></div>

--000000000000a21afa06157a0538--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfrN3HnqfLLptMF5PBaNGpDDkC-LwGCCzMj6unAw=U-JnQ>