From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754163AbbHSOID (ORCPT ); Wed, 19 Aug 2015 10:08:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51221 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753474AbbHSOIB (ORCPT ); Wed, 19 Aug 2015 10:08:01 -0400 Date: Wed, 19 Aug 2015 07:07:58 -0700 From: Greg Kroah-Hartman To: Ankit Jindal Cc: linux-kernel@vger.kernel.org, "Hans J. Koch" , Pranavkumar Sawargaonkar , Jitendra Kanitkar , Tushar Jagad Subject: Re: Unmapping of UIO logical memory causing a trace Message-ID: <20150819140758.GA19776@kroah.com> References: <20150811214545.GA1457@kroah.com> <20150812171136.GB1805@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23+102 (2ca89bed6448) (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 19, 2015 at 03:25:09PM +0530, Ankit Jindal wrote: > Hi Greg, > > On Wed, Aug 12, 2015 at 10:41 PM, Greg Kroah-Hartman > wrote: > > On Wed, Aug 12, 2015 at 01:25:53PM +0530, Ankit Jindal wrote: > >> Hi Greg, > >> > >> On Wed, Aug 12, 2015 at 3:15 AM, Greg Kroah-Hartman > >> wrote: > >> > On Tue, Aug 11, 2015 at 04:39:08PM +0530, Ankit Jindal wrote: > >> >> Hi, > >> >> > >> >> We have observed an issue where kmalloc of a small sized memory causes > >> >> an occasional trace when unmapping the mmaped memory via UIO framework > >> >> This trace is coming when kernel sees a negative value in > >> >> page->_mapcount. Trace is pasted at the end of the mail. > >> >> > >> >> After debugging this issue further, we realized following sequence > >> >> occurs when kmalloc is used to allocate small memory using slub > >> >> allocator: > >> >> 1. Frozen bit (msb) of the page from which memory has been allocated > >> >> is set (which is an union with _mapcount). > >> >> 2. If there are free objects in the the same page then this frozen bit > >> >> remains set even after kernel boots completely. > >> >> 3. When user space calls unmap of this memory, vma_unmap_single() > >> >> treats the _mapcount as a negative (as frozen bit is set), causing a > >> >> trace. > >> >> > >> >> We are not sure whether exposing kernel memory of size > >> >> less than PAGE_SIZE via UIO is a valid use case ? In case this is an invalid > >> >> use case then shouldn't the UIO framework restrict mapping of non > >> >> PAGE_SIZE aligned memory and size not in order of PAGE_SIZE. > >> > > >> > We've had a few discussions about this in the past, and one proposed > >> > patch which had to be reverted because it broke some working systems, so > >> > it's a messy thing. > >> > > >> > What UIO driver are you using that causes this behavior? > >> > >> We have observed this during the development of new UIO driver for our > >> soc. In our driver, we need to parse non probable properties of device > >> and provide these details to our user application. > > > > What exactly do you mean by this? > > There are certain the device specific properties (coming from device > tree) which we are exposing using UIO_LOGICAL_MEM to the user space. Why would you do that? Userspace has the device tree info already through other means. > >> For this we do a kmalloc of device info(approx size 80 bytes) and pass > >> this address to user space via UIO mem logical. > > > > For such tiny sizes, why not just use a normal sysfs file? > > We did not think of sysfs as an option, since UIO_MEM_LOGICAL seems to > address our use case. Not for tiny memory chunks like you have seen :) > > Do you have a pointer to your driver so that I can see exactly what it > > is doing here? > > Below is the code snippet of my driver. How about the whole driver please. thanks, greg k-h