Solved

how to suppress mmap warning in /var/log/messages

Posted on 2010-08-31
11
661 Views
Last Modified: 2012-05-10
I have an application that needs to map several ranges  of physical memory at an offset in order to talk to some RAID controllers.   (It is a x86_64 type image if it makes any difference) The code works, but it gives a tainted kernel message that I wish to suppress every time it executes:
mmap(NULL,256,PROT_READ|PROT_WRITE,MAP_SHARED,handle,portPhysOffset);

Aug 31 19:18:54 DD1SYS kernel: [26931.369509] process "flashcontroller" tried to map 0x000dd310-0x000dd311 on 0000:03:03.0 BAR 1 (size 0x00000004)
(Above corresponds to physical address dd310000h)
 
Another message is "... tried to map 0x000dd500-0x000dd510 on 0000:05:03.0 BAR 0 (size 0x00000001)"

I'm not up on setting a parameter at boot time so the targeted kernel can get this message suppressed before the code is invoked.  How would I do it?

Depending on how many cards / ports there are multiple ports will be mapped.  I want to play nice and just block out the specific areas I need, but don't mind taking the easy way out and trying to suppress reporting for a few MB to cover all the bases.  

0
Comment
Question by:dlethe
  • 6
  • 5
11 Comments
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 33574933
At linux-2.6.33.4, the possible sources of these messages come down to one line:-

./drivers/pci/pci-sysfs.c:701:  WARN(1, "process \"%s\" tried to map 0x%08lx-0x%08lx on %s BAR %d (size 0x%08lx)\n",

You could zap that line of code and rebuild your kernel, but have a look first at why the warning is being emitted.

Incidentally, after that warning, the caller returns an error, so whatever you were trying to do presumably doesn't get done
0
 
LVL 47

Author Comment

by:dlethe
ID: 33576026
Thanks, but I don't have luxury of being able to modify the kernel.  One thing that is necessary, the software needs to look at several memory locations in order to determine the correct offset, which is a function of how many controllers are in the system.  

Is there a way to probe the memory w/o creating the message?    (The port->memPhys changes within a loop)



ioctl(pciHandle, PCIIOC_MMAP_IS_MEM);
errno = 0;
// Below statement creates the kernel warning on some systems, based on specific controller configurations and quantitites
port->memVirt = mmap(NULL, 256, PROT_READ | PROT_WRITE, MAP_SHARED, pciHandle, port->memPhys);

if (errno)  {
 // make other arrangements here
}
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 33576878
perhaps. You could try mmap of entire pages for instance. See the Linux code below - you have to craft your mmap() call to pass the test.
Otherwise the mmap() doesn't work so you are looking at bogus data anyway. Pages are 4096 bytes usually AFAIK
int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma)

{

        unsigned long nr, start, size;



        nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;

        start = vma->vm_pgoff;

        size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;

        if (start < size && size - start >= nr)

                return 1;

        WARN(1, "process \"%s\" tried to map 0x%08lx-0x%08lx on %s BAR %d (size 0x%08lx)\n",

                current->comm, start, start+nr, pci_name(pdev), resno, size);

        return 0;

}

Open in new window

0
 
LVL 47

Author Comment

by:dlethe
ID: 33576988
Thanks, yes, I know it gets the actual pagesize anyway, which doesn't even have to be 4096, just hardcoded the example for sake of brevity.  Glad you threw that in there however.  Nice to have you looking out for such things.
0
 
LVL 47

Author Comment

by:dlethe
ID: 33580159
Got a problem. How in the heck do I do the headers, so I can compile?  The app runs in user space, not kernel space.  I found the vm_area_struct in
/usr/src/linux-headers-2.6-xxxx/include/linux/mm.h

But it is just not as simple as adding -I/usr/src/linux-headers.2.6.32-24/include as one of the gcc options, and I suspect I'll have more headaches with pci_resource_len when it comes to linknig.

Is there a way to see if I can see if the mmap() call will work some other way before invoking it with different parameters first, to prevent me from attempting something that won't work and put the message in the /var/log/messages file?

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 34

Expert Comment

by:Duncan Roe
ID: 33581873
In general you will get errors when including headers from kernel source directly. Some of these headers appear in "sanitised" form in /usr/include/linux - mm.h is not one of them but you may be able to apply the process to it.
At 2.6.33.4, the structure is actually defined in mm_types.h - you don't need to define __KERNEL__ to use it
0
 
LVL 47

Author Comment

by:dlethe
ID: 33588994
Got some followup, this technique isn't working, something else is amiss.

So first, I stepped through the code and hardcoded everything to make sure (to best of my ability) that I am not breaking any rules and opening something that doesn't exist.  

I open /sys/bus/pci/devices/0000:03:03.0  (no errors, here is directory listing)

root@NIMBUS8510:/sys/bus/pci/devices/0000:03:03.0# pwd
/sys/bus/pci/devices/0000:03:03.0
root@NIMBUS8510:/sys/bus/pci/devices/0000:03:03.0# ls -l
total 0
-rw-r--r--  1 root root    4096 2010-09-02 09:25 broken_parity_status
-r--r--r--  1 root root    4096 2010-09-02 08:49 class
-rw-r--r--  1 root root     256 2010-09-02 09:25 config
-r--r--r--  1 root root    4096 2010-09-02 09:25 device
lrwxrwxrwx  1 root root       0 2010-09-02 09:25 driver -> ../../../../../bus/pci/drivers/mptsas
-rw-------  1 root root    4096 2010-09-02 09:25 enable
drwxr-xr-x 22 root root       0 2010-09-02 08:49 host1
-r--r--r--  1 root root    4096 2010-09-02 08:49 irq
-r--r--r--  1 root root    4096 2010-09-02 09:25 local_cpulist
-r--r--r--  1 root root    4096 2010-09-02 08:49 local_cpus
-r--r--r--  1 root root    4096 2010-09-02 09:25 modalias
-rw-r--r--  1 root root    4096 2010-09-02 09:25 msi_bus
-r--r--r--  1 root root    4096 2010-09-02 09:25 numa_node
drwxr-xr-x  2 root root       0 2010-09-02 09:25 power
--w--w----  1 root root    4096 2010-09-02 09:25 remove
--w--w----  1 root root    4096 2010-09-02 09:25 rescan
--w-------  1 root root    4096 2010-09-02 09:25 reset
-r--r--r--  1 root root    4096 2010-09-02 09:11 resource
-rw-------  1 root root     256 2010-09-02 09:25 resource0
-rw-------  1 root root   16384 2010-09-02 09:25 resource1
-rw-------  1 root root   65536 2010-09-02 09:25 resource3
-r--------  1 root root 2097152 2010-09-02 09:25 rom
lrwxrwxrwx  1 root root       0 2010-09-02 08:50 subsystem -> ../../../../../bus/pci
-r--r--r--  1 root root    4096 2010-09-02 09:25 subsystem_device
-r--r--r--  1 root root    4096 2010-09-02 09:25 subsystem_vendor
-rw-r--r--  1 root root    4096 2010-09-02 08:49 uevent
-r--r--r--  1 root root    4096 2010-09-02 09:25 vendor
root@NIMBUS8510:/sys/bus/pci/devices/0000:03:03.0#

=========
what gets added to /var/log/messagesSep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862572] ------------[ cut here ]------------
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862589] WARNING: at /build/buildd/linux-2.6.32/drivers/pci/pci-sysfs.c:675 pci_mmap_fits+0xad/0xe0()
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862593] Hardware name: Thunder I7520
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862597] process "smartmon-ux" tried to map 0x000dd310-0x000dd311 on 0000:03:03.0 BAR 0 (size 0x00000001)
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862600] Modules linked in: mptctl ipmi_devintf ipmi_msghandler ib_iser rdma_cm ib_cm iw_cm ib_sa ib_mad ib_core ib_addr iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi nfsd exportfs nfs lockd nfs_acl auth_rpcgss sunrpc drbd igb dca mptsas mlx4_en mptscsih mptbase mlx4_core e752x_edac scsi_transport_sas tg3 e1000 bonding edac_core shpchp s2io i2c_i801 i2c_dev raid10 raid456 async_raid6_recov async_pq raid6_pq async_xor xor async_memcpy async_tx raid1 raid0 multipath linear usbhid hid scsi_wait_scan vesafb usb_storage fbcon tileblit font bitblit softcursor vga16fb vgastate
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862677] Pid: 28720, comm: smartmon-ux Tainted: G        W  2.6.32-22-server #36-Ubuntu
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862680] Call Trace:
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862689]  [] warn_slowpath_common+0x7b/0xc0
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862694]  [] warn_slowpath_fmt+0x41/0x50
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862700]  [] pci_mmap_fits+0xad/0xe0
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862706]  [] ? capable+0x13/0x50
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862710]  [] proc_bus_pci_mmap+0x79/0xb0
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862715]  [] ? proc_bus_pci_mmap+0x0/0xb0
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862721]  [] proc_reg_mmap+0x70/0xb0
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862728]  [] mmap_region+0x404/0x590
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862733]  [] do_mmap_pgoff+0x335/0x380
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862739]  [] sys_mmap_pgoff+0x1d4/0x2a0
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862746]  [] ? sys_read+0x51/0x80
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862752]  [] sys_mmap+0x29/0x30
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862758]  [] system_call_fastpath+0x16/0x1b
Sep  2 09:31:42 NIMBUS8510 kernel: [ 2551.862762] ---[ end trace f4345dd89c96aa55 ]---

cat /proc/bus/pci/devices (truncated items at the beginning of list)

00ef      808624dd      17              dd000000                     0                     0                     0                     0                     0                     0                   400                     0                     0                     0                     0                     0                     0      ehci_hcd
00f0      8086244e      0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0      
00f8      808624d0      0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0      
00fb      808624d3      11                     0                     0                     0                     0                  1481                     0                     0                     0                     0                     0                     0                    20                     0                     0      i801_smbus
0100      80860329      0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0      
0101      80860326      0              dd100000                     0                     0                     0                     0                     0                     0                  1000                     0                     0                     0                     0                     0                     0      
0102      8086032a      0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0      
0103      80860327      0              dd101000                     0                     0                     0                     0                     0                     0                  1000                     0                     0                     0                     0                     0                     0      
0240      80861010      18              dd200004                     0                     0                     0                  2001                     0                     0                 20000                     0                     0                     0                    40                     0                     0      e1000
0241      80861010      19              dd220004                     0                     0                     0                  2041                     0                     0                 20000                     0                     0                     0                    40                     0                     0      e1000
0318      10000054      30                  3001              dd310004                     0              dd300004                     0                     0              80000000                   100                  4000                     0                 10000                     0                     0                200000      mptsas
0400      80860329      0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0      
0401      80860326      0              dd400000                     0                     0                     0                     0                     0                     0                  1000                     0                     0                     0                     0                     0                     0      
0402      8086032a      0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0      
0403      80860327      0              dd401000                     0                     0                     0                     0                     0                     0                  1000                     0                     0                     0                     0                     0                     0      
0518      10000054      49                  4001              dd510004                     0              dd500004                     0                     0              80200000                   100                  4000                     0                 10000                     0                     0                200000      mptsas
0618      10b56520      0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0                     0      
0720      14e41648      62              dd600004                     0                     0                     0                     0                     0                     0                 10000                     0                     0                     0                     0                     0                     0      tg3
0721      14e41648      63              dd610004                     0                     0                     0                     0                     0                     0                 10000                     0                     0                     0                     0                     0                     0      tg3
0730      14e41648      60              dd620004                     0                     0                     0                     0                     0                     0                 10000                     0                     0                     0                     0                     0                     0      tg3
0731      14e41648      61              dd630004                     0                     0                     0                     0                     0                     0                 10000                     0                     0                     0                     0                     0                     0      tg3
0828      10024752      a              de000000                  5001              dd700000                     0                     0                     0              80400002               1000000                   100                  1000                     0                     0                     0                 20000      
root@NIMBUS8510:/proc/bus/pci#

=========
with debug statements, I confirm it opens
/sys/bus/pci/devices/0000:03:03.0/resource

ioctl(pciHandle,PCIIOC_MMAP_IS_MEM)   returns ok, nothing in kernel log

port->memPhys set to dd310000
mmap(NULL, 256, PROT_READ|PROT_WRITE,MAP_SHARED,pciHandle,port->memPhys)

Reason why I mapped 256 bytes is because both the resource0 file is 256 bytes, and I even called fstat on it to confirm file was 256 bytes (but also tried mapping 4096 so it matched page size).

Still same error.

Got to be missing something here.  Maybe problem isn't issue with accessing non-existent memory?  



0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 33592051
What I would try:
In one window, step through your code with gdb
in another window, tail -f /var/log/messages or some better log (see below)
You should find that each log message corresponds with a particular source line, especially if you force synchronous logging. Carefully consider the source lines thus exposed


# From my /etc/syslog:



# Everything is logged here.

*.debug                                         -/var/log/debug



# Remove the minus sign for your test. It causes buffered logging, so messages can be delayed.

# Reinstate it afterwards if you like - otherwise it can cause excessive disk thrashing

Open in new window

0
 
LVL 47

Author Comment

by:dlethe
ID: 33592113
This is the line, where port->memPhys =  dd310000

port->memVirt = mmap(NULL, 256, PROT_READ | PROT_WRITE, MAP_SHARED, pciHandle, port->memPhys);

It does work, I want to see how to suppress this message w/o building a new kernel.  After digging, the message is there not because the address is no good, or at the wrong offset, but because the mapping creates a security hole.

Any way to suppress it with echoing something to one of the modules, or routing 100% of the kernel warning messages into the bitbucket?  If there is no way to do it other than rebuild the kernel, so be it.  I was hoping that there was a mechanism to suppress specific mapping warnings and thought earlier that root cause was programmer error.
0
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 33595240
You are right, that degree of fine tuning is not available. I think it would be unwise to bitbucket all kernel warnings, as, I suspect, do you. So you are left with a kernel rebuild or live with it
0
 
LVL 47

Author Closing Comment

by:dlethe
ID: 33596475
A "it is not possible" w/o modifying the kernel is as good as an answer that I can expect, as it saves me time I would otherwise waste looking for a work-around.


Thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now