Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Jul 2015 12:37:56 -0700
From:      Laurie Jennings <laurie_jennings_1977@yahoo.com>
To:        Hooman Fazaeli <hoomanfazaeli@gmail.com>
Cc:        "freebsd-net@freebsd.org" <freebsd-net@freebsd.org>
Subject:   Re: Locking Memory Question
Message-ID:  <1438285076.38601.YahooMailBasic@web141505.mail.bf1.yahoo.com>
In-Reply-To: <55BA6E6C.4080304@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--------------------------------------------
On Thu, 7/30/15, Hooman Fazaeli <hoomanfazaeli@gmail.com> wrote:

 Subject: Re: Locking Memory Question
 To: "Laurie Jennings" <laurie_jennings_1977@yahoo.com>
 Cc: "freebsd-net@freebsd.org" <freebsd-net@freebsd.org>
 Date: Thursday, July 30, 2015, 2:35 PM
=20
 On 7/30/2015 5:22 AM,
 Laurie Jennings via freebsd-net wrote:
 >
 --------------------------------------------
 > On Wed, 7/29/15, John-Mark Gurney <jmg@funkthat.com>
 wrote:
 >
 >=A0=A0=A0Subject: Re: Locking Memory
 Question
 >=A0=A0=A0To: "Laurie
 Jennings" <laurie_jennings_1977@yahoo.com>
 >=A0=A0=A0Cc: "John Baldwin"
 <jhb@freebsd.org>,
 freebsd-net@freebsd.org
 >=A0=A0=A0Date: Wednesday, July 29,
 2015, 7:25 PM
 >=A0=A0=A0
 >=A0=A0=A0Laurie Jennings via
 >=A0=A0=A0freebsd-net wrote this
 message on Wed, Jul 29, 2015 at 15:26
 >=A0=A0=A0-0700:
 >=A0=A0=A0>
 >=A0=A0=A0> I have a problem and
 >=A0=A0=A0I can't quite figure out
 where to look. This is what Im
 >=A0=A0=A0doing:
 >=A0=A0=A0>
 >=A0=A0=A0> I have an
 >=A0=A0=A0IOCTL to read a block of
 data, but the data is too large to
 >=A0=A0=A0return via ioctl. So to get
 the data,
 >=A0=A0=A0> I
 >=A0=A0=A0allocate a block in a kernel
 module:
 >=A0=A0=A0>
 >=A0=A0=A0
 >=A0=A0=A0> foo =3D
 >=A0=A0=A0malloc(1024000,M_DEVBUF,M_WAITOK);
 >=A0=A0=A0>
 >=A0=A0=A0>=A0 I pass up a pointer
 and in user space
 >=A0=A0=A0map it
 using /dev/kmem:
 >=A0=A0=A0
 >=A0=A0=A0An easier solution would be
 for your ioctl to
 >=A0=A0=A0pass in
 a userland
 >=A0=A0=A0pointer and
 then use
 >=A0=A0=A0copyout(9) to
 push the data to userland...=A0 This
 >=A0=A0=A0means the userland process
 doesn't have to
 >=A0=A0=A0have
 /dev/kmem access...
 >=A0=A0=A0
 >=A0=A0=A0Is
 >=A0=A0=A0there a reason you need to
 use kmem?=A0 The only reason you
 >=A0=A0=A0list above
 >=A0=A0=A0is that it's too large
 via
 >=A0=A0=A0ioctl, but a copyout
 is fine, and would
 >=A0=A0=A0handle
 all page faults for you..
 >=A0=A0=A0
 >=A0=A0=A0__________________________________
 > I'm using kmem because the only
 options I could think of was to
 >
 > 1) use shared memory
 >
 2) use kmem
 > 3) use a huge ioctl
 structure.
 >
 > Im not
 clear how I'd do that. the data being passed up from the
 kernel is a variable size. To use copyout I'd have to
 pass a
 > pointer with a static buffer,
 right? Is there a way to malloc user space memory from
 within an ioctl call? Or
 > would I just
 have to pass down a pointer to a huge buffer large enough
 for the largest possible answer?
 >
 > thanks
 >
 > Laurie
=20
 You can use two IOCTLs. Get the block size from
 kernel module with the first ioctl,
 and
 malloc(3) a buffer in userland with that size. Then use a
 second ioctl to pass the
 address of
 allocated buffer to kernel module. The module may use
 copyout(9) to copy
 in-kernel data to user
 space buffer.
=20
=20
 __________________

I sort of did that. I pass a buffer large enough for 99% of the cases, and =
if its too small I return the required
size and pass a bigger buffer. Its a low volume operation so I'm not too co=
ncerned about performance, but doing
2 IOCTLs every time would be particular inefficient. Its cleaner than kmem =
for sure.

Laurie



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1438285076.38601.YahooMailBasic>