From owner-freebsd-net@freebsd.org Thu Jul 30 19:37:59 2015 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 715DC9AC4AB for ; Thu, 30 Jul 2015 19:37:59 +0000 (UTC) (envelope-from laurie_jennings_1977@yahoo.com) Received: from nm3-vm0.bullet.mail.bf1.yahoo.com (nm3-vm0.bullet.mail.bf1.yahoo.com [98.139.212.154]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2C231ECA for ; Thu, 30 Jul 2015 19:37:58 +0000 (UTC) (envelope-from laurie_jennings_1977@yahoo.com) Received: from [66.196.81.174] by nm3.bullet.mail.bf1.yahoo.com with NNFMP; 30 Jul 2015 19:37:56 -0000 Received: from [98.139.215.230] by tm20.bullet.mail.bf1.yahoo.com with NNFMP; 30 Jul 2015 19:37:56 -0000 Received: from [127.0.0.1] by omp1070.mail.bf1.yahoo.com with NNFMP; 30 Jul 2015 19:37:56 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 852242.45392.bm@omp1070.mail.bf1.yahoo.com Received: (qmail 50419 invoked by uid 60001); 30 Jul 2015 19:37:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1438285076; bh=FPyhqsw9HFLnKr4fIGCzNTERWTIzxXZwZVPRoDJH7WE=; h=Message-ID:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=nMfAIagQ1gDZrUVOH+Vl5pkMhL5uP9W9HKyfdz2D0gyNzLgQW9xW7khmzLzO5+TjFrnyuFTCWojtPKOYpeUDg3B+DRquZNrvYTQbVP2kdzqajSseq4bICNOQCPiN4wU9n35eLrNzAht2mGPaAo9K2uUmpj9zlO/TzJB9LxY1YH4= X-YMail-OSG: lWPIig0VM1nG.WS2WMop4rdUlzod1n1kmBZNtcZGd944eon KyjrimVP3DbKSQHozGet_eOCMWDf5z0ec.eJLsJhniz1KPgIxenyZ5zDa44h Pi3VDZqlsBXHcVTE..8IoqffrZYzTyUhqfwFLIlJkhVuAn17HFx2VCgzfWEW p30OPO518pmsDi62immMX_wJ4Kbnu1FXzFVkb_rHkucZ6OjkY8aAxOlA8zw2 PB0tyVfrBZMPtroX7h3dRfZozm.OeViNzZRPd9hpo8lXWPHY9joPM8t64bHq U8ZB90LxsqasU_WkX1Pi3Loec8C96jz60B3uBlWIwIiy9QZ7065.k5UQ9bKU PStnurb2yeHyhAC3MBHxaseAFJTSnNcbzQVaZPuIIwijQ6yzP9ZOiVHJsn_C pKkTjY3XdVOYAuv_lky49mkzKwy3WlS4uqgpiF1g3J8XZ.XD330ka4XNRBEg raqzfugqdFMSH9WpJBeo5mBom352jATePyokSX8cdtonx7UBeQVe4LSiMf7s ACRfFvw_5JCwg0nUEpHaE.6PeF_.lqO8fxdgUNCQPXg3X9mB2IR6QnrJMTg- - Received: from [73.0.96.254] by web141505.mail.bf1.yahoo.com via HTTP; Thu, 30 Jul 2015 12:37:56 PDT X-Rocket-MIMEInfo: 002.001, DQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQ0KT24gVGh1LCA3LzMwLzE1LCBIb29tYW4gRmF6YWVsaSA8aG9vbWFuZmF6YWVsaUBnbWFpbC5jb20.IHdyb3RlOg0KDQogU3ViamVjdDogUmU6IExvY2tpbmcgTWVtb3J5IFF1ZXN0aW9uDQogVG86ICJMYXVyaWUgSmVubmluZ3MiIDxsYXVyaWVfamVubmluZ3NfMTk3N0B5YWhvby5jb20.DQogQ2M6ICJmcmVlYnNkLW5ldEBmcmVlYnNkLm9yZyIgPGZyZWVic2QtbmV0QGZyZWVic2Qub3JnPg0KIERhdGU6IFRodXJzZGF5LCBKdWwBMAEBAQE- X-Mailer: YahooMailBasic/600 YahooMailWebService/0.8.203.802 Message-ID: <1438285076.38601.YahooMailBasic@web141505.mail.bf1.yahoo.com> Date: Thu, 30 Jul 2015 12:37:56 -0700 From: Laurie Jennings Subject: Re: Locking Memory Question To: Hooman Fazaeli Cc: "freebsd-net@freebsd.org" In-Reply-To: <55BA6E6C.4080304@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jul 2015 19:37:59 -0000 -------------------------------------------- On Thu, 7/30/15, Hooman Fazaeli wrote: Subject: Re: Locking Memory Question To: "Laurie Jennings" Cc: "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 wrote: > >=A0=A0=A0Subject: Re: Locking Memory Question >=A0=A0=A0To: "Laurie Jennings" >=A0=A0=A0Cc: "John Baldwin" , 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