MTRR ioctls don't work as documented

Bug #253204 reported by D. Hugh Redelmeier
2
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

The kernel's Documentation/x86/mtrr.txt
or Documentation/mtrr.txt
describes the ioctl interface to the MTRRs.

The sample code for printing out the MTRRs ("mtrr-show.c") fails to print many of the values. I think that this is a bug in the ioctl implementation, not the documentation since the same code works on Fedora 9.

/proc/mttr shows:
reg00: base=0xd0000000 (3328MB), size= 256MB: uncachable, count=1
reg01: base=0xe0000000 (3584MB), size= 512MB: uncachable, count=1
reg02: base=0x00000000 ( 0MB), size=4096MB: write-back, count=1
reg03: base=0x100000000 (4096MB), size=2048MB: write-back, count=1
reg04: base=0x180000000 (6144MB), size= 512MB: write-back, count=1
reg05: base=0x1a0000000 (6656MB), size= 256MB: write-back, count=1

The sample code prints:
Register: 0 base: 0xd0000000 size: 0x10000000 type: uncachable
Register: 1 base: 0xe0000000 size: 0x20000000 type: uncachable
Register: 2 disabled
Register: 3 disabled
Register: 4 disabled
Register: 5 disabled
Register: 6 disabled
Register: 7 disabled

If I remove the disabled check, it prints:
Register: 0 base: 0xd0000000 size: 0x10000000 type: uncachable
Register: 1 base: 0xe0000000 size: 0x20000000 type: uncachable
Register: 2 base: 0x0 size: 0x0 type: uncachable
Register: 3 base: 0x0 size: 0x0 type: uncachable
Register: 4 base: 0x0 size: 0x0 type: uncachable
Register: 5 base: 0x0 size: 0x0 type: uncachable
Register: 6 base: 0x0 size: 0x0 type: uncachable
Register: 7 base: 0x0 size: 0x0 type: uncachable

Note: the architecture is AMD64. The code is native (according to file(1)).

The same code seems to work on a Fedora 9 x86-64 system, albeit one with less than 4G of RAM.

BTW, the reason I care is that the MTRRs need to be rearranged for X to work on my system and I want to do that programmatically.

Revision history for this message
D. Hugh Redelmeier (hugh-mimosa) wrote :
Revision history for this message
D. Hugh Redelmeier (hugh-mimosa) wrote :

I guess I should have stated the version information. Why isn't this asked?

I'm running 8.04.1. /proc/version says:
Linux version 2.6.24-19-generic (buildd@king) (gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)) #1 SMP Fri Jul 11 21:01:46 UTC 2008
My system was updated a couple of days ago. Funny thing: the kernel changed but all I noticed changing in /proc/version was the build machine and date.

dmesg shows that the kernel is Ubuntu 2.6.24-19.36-generic

====================================

cc -E shows that the x86-64 version of struct mtrr_gentry is being used.

Revision history for this message
D. Hugh Redelmeier (hugh-mimosa) wrote :

[I got some help from BenC and mjg59 on freenode's #ubuntu-kernel]

It turns out that the kernel's IOCTL code just bails (returns an all-0 struct) if the MTRR size field is >=4G. There is no room in the size field of struct mtrr_gentry (defined in /usr/include/asm/mtrr.h).

See case MTRRIOC_GET_ENTRY in arch/x86/kernel/cpu/mtrr/if.c

I think that the struct field should be widened. But that may be an ABI change.

Otherwise, the IOCTL should return an error. Perhaps EOVERFLOW or ERANGE.

This seems to be a general Linux problem and not specific to Ubuntu.

Revision history for this message
Leann Ogasawara (leannogasawara) wrote :

[This is an automated message. Apologies if it has reached you inappropriately.]

This bug was reported against the linux-meta package when it likely should have been reported against the linux package instead. We are automatically transitioning this to the linux kernel package so that the appropriate teams are notified and made aware of this issue. Thanks.

affects: linux-meta (Ubuntu) → linux (Ubuntu)
Revision history for this message
kernel-janitor (kernel-janitor) wrote :

Hi D.,

Please be sure to confirm this issue exists with the latest development release of Ubuntu. ISO CD images are available from http://cdimage.ubuntu.com/releases/ . Please then run following command from a Terminal (Applications->Accessories->Terminal). It will automatically gather and attach updated debug information to this report.

apport-collect -p linux-image-`uname -r` 253204

Also, if you could test the latest upstream kernel available that would be great. It will allow additional upstream developers to examine the issue. Refer to https://wiki.ubuntu.com/KernelMainlineBuilds . Once you've tested the upstream kernel, please remove the 'needs-upstream-testing' tag. This can be done by clicking on the yellow pencil icon next to the tag located at the bottom of the bug description and deleting the 'needs-upstream-testing' text. Please let us know your results.

Thanks in advance.

[This is an automated message. Apologies if it has reached you inappropriately; please just reply to this message indicating so.]

tags: added: needs-kernel-logs
tags: added: needs-upstream-testing
tags: added: kj-triage
Changed in linux (Ubuntu):
status: New → Incomplete
Revision history for this message
D. Hugh Redelmeier (hugh-mimosa) wrote :

I tried to use apport-collect but it required more access rights than I am willing to give it.

Please read #3 -- #1 is confusing.

This bug still exists in 9.04. It also exists in Fedora 11. It is in upstream (I'm sure, by code inspection).

Note: I said that MTRRs with length >=4GiB were not reported. This also applies to ones with starting address >= 4G.

Revision history for this message
Eric Miao (eric.y.miao) wrote :

Hi Hugh,

We will constantly sync with stable tree for our stock kernel, please make sure <email address hidden> is CC'ed in your patch and has been merged there. OTH, you may check our latest kernel to see if that has been merged.

Revision history for this message
Jeremy Foshee (jeremyfoshee) wrote :

This bug report was marked as Incomplete and has not had any updated comments for quite some time. As a result this bug is being closed. Please reopen if this is still an issue in the current Ubuntu release http://www.ubuntu.com/getubuntu/download . Also, please be sure to provide any requested information that may have been missing. To reopen the bug, click on the current status under the Status column and change the status back to "New". Thanks.

[This is an automated message. Apologies if it has reached you inappropriately; please just reply to this message indicating so.]

tags: added: kj-expired
Changed in linux (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.