From owner-freebsd-net@freebsd.org Thu Jul 30 18:35:31 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 14C0D9AB3DE for ; Thu, 30 Jul 2015 18:35:31 +0000 (UTC) (envelope-from hoomanfazaeli@gmail.com) Received: from mail-wi0-x235.google.com (mail-wi0-x235.google.com [IPv6:2a00:1450:400c:c05::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A28DF1B14 for ; Thu, 30 Jul 2015 18:35:30 +0000 (UTC) (envelope-from hoomanfazaeli@gmail.com) Received: by wibxm9 with SMTP id xm9so3289029wib.1 for ; Thu, 30 Jul 2015 11:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=0+AH8p4DhtOtoVysdDND4/gxQtNJcaJ22DN6mkuQQuY=; b=j3ufybBuuUyJ1MjK82VTYUcK0WqXKNYNyw53rp1jclpp1XGCRKoJdcIx0pFw73TZ+n hlu9/g0KxibHmbcrKw29dMQeAwbEG4hYQ/Qr/bF3A1wZw3V2QiHk7lReXEWrYlJNFN1o PlXpw2Lr0HqedsZajuYNTWj43Kp6GyCHZIn2D1dlrUpE6OamPDDF75ggxOI2xgq06MWJ 1Tt6khsXYRjxCsEieU49gHyg8zVCT0ohKWriz/aAeShAhjSbWJ0NE8Gc4rCjGQkYHWY2 vGAxa+h+lZrnc3re1u7viRBBt/f4T4QE8D6CdPPpGf1ptLH7pBbIADch8FmDVdQNNj5R AMMg== X-Received: by 10.194.123.4 with SMTP id lw4mr87991598wjb.94.1438281328976; Thu, 30 Jul 2015 11:35:28 -0700 (PDT) Received: from [192.168.2.30] ([2.190.246.160]) by smtp.googlemail.com with ESMTPSA id gc4sm399930wib.23.2015.07.30.11.35.27 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jul 2015 11:35:28 -0700 (PDT) Message-ID: <55BA6E6C.4080304@gmail.com> Date: Thu, 30 Jul 2015 23:05:24 +0430 From: Hooman Fazaeli User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 MIME-Version: 1.0 To: Laurie Jennings CC: "freebsd-net@freebsd.org" Subject: Re: Locking Memory Question References: <1438217542.41867.YahooMailBasic@web141502.mail.bf1.yahoo.com> In-Reply-To: <1438217542.41867.YahooMailBasic@web141502.mail.bf1.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 18:35:31 -0000 On 7/30/2015 5:22 AM, Laurie Jennings via freebsd-net wrote: > -------------------------------------------- > On Wed, 7/29/15, John-Mark Gurney wrote: > > Subject: Re: Locking Memory Question > To: "Laurie Jennings" > Cc: "John Baldwin" , freebsd-net@freebsd.org > Date: Wednesday, July 29, 2015, 7:25 PM > > Laurie Jennings via > freebsd-net wrote this message on Wed, Jul 29, 2015 at 15:26 > -0700: > > > > I have a problem and > I can't quite figure out where to look. This is what Im > doing: > > > > I have an > IOCTL to read a block of data, but the data is too large to > return via ioctl. So to get the data, > > I > allocate a block in a kernel module: > > > > > foo = > malloc(1024000,M_DEVBUF,M_WAITOK); > > > > I pass up a pointer and in user space > map it using /dev/kmem: > > An easier solution would be for your ioctl to > pass in a userland > pointer and then use > copyout(9) to push the data to userland... This > means the userland process doesn't have to > have /dev/kmem access... > > Is > there a reason you need to use kmem? The only reason you > list above > is that it's too large via > ioctl, but a copyout is fine, and would > handle all page faults for you.. > > __________________________________ > 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 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. > _______________________________________________ > freebsd-net@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" -- Best regards Hooman Fazaeli