Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756780AbcJ1Xrx (ORCPT ); Fri, 28 Oct 2016 19:47:53 -0400 Received: from smtp29.i.mail.ru ([94.100.177.89]:58619 "EHLO smtp29.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752851AbcJ1Xrv (ORCPT ); Fri, 28 Oct 2016 19:47:51 -0400 Subject: Re: /dev/mem and PCI memory = EFAULT (regression?) To: Linus Torvalds References: <52478c6c-39cb-35b1-0517-33d9f6e99a5a@list.ru> <89281ddd-ea21-6de8-b4dd-57ff4b0d2040@list.ru> Cc: Andy Lutomirski , Linux kernel , dosemu-devel , Bart Oldeman , "Eric W. Biederman" From: Stas Sergeev Message-ID: <39321cd2-c2c7-8595-cba1-218dd685f29e@list.ru> Date: Sat, 29 Oct 2016 02:47:42 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Authentication-Results: smtp29.i.mail.ru; auth=pass smtp.auth=stsp@list.ru smtp.mailfrom=stsp@list.ru X-E1FCDC63: 26BB07C17A5E6E6EB8557E7C02D2BB0CF8D9167951635F18 X-E1FCDC64: 881B1C61D2C901C6244D175245618A980A72D1E8B72F254E33212804916E606F4C4DA9DF1BAA9670 X-Mailru-Sender: CD12F6D16A91A659C71BA12F480A5E3E5B52C47AB858CB72D1A9E93230E6EA7F98CCE1E5BE20339324DAF05A372A3159 X-Mras: OK Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2020 Lines: 43 29.10.2016 02:26, Linus Torvalds пишет: > On Fri, Oct 28, 2016 at 2:36 PM, Stas Sergeev wrote: >>>>> On Fri, Oct 28, 2016 at 2:03 PM, Stas Sergeev wrote: >> Hello. >> >> For the long time dosemu used /dev/mem for vga pass-through. >> Now it appears /dev/mem has this check: >> http://lxr.free-electrons.com/source/drivers/char/mem.c#L51 >> which prevents an accesses to PCI memory regions if the >> "high_memory" points low enough. It seems "high_memory" >> just points to the end of the physical ram, so depending on >> the ram size you either can access PCI devices or you get >> EFAULT. >> Was it wrong to use /dev/mem for accessing the PCI devices? >> How should I do that now? > Has it ever worked for you? Well, yes, even today: if the ram size is large enough to last beyond the PCI space, then I am not getting EFAULT (i've yet to check if the results are as expected, but at least no error returned). It is exactly that ram size envolvement made me think this is a bug (and regression). > That code is ancient, going back in some > form or another at least ten years. Yes, indeed, I can see that on lxr now... > So /dev/mem does not allow "read()/write()" on IO memory, and really > hasn't in a long long time (maybe ever, quite frankly). It does allow > it on regular RAM, but STRICT_DEV_MEM then disallows that too for > security reasons (and realistically, everybody uses STRICT_DEV_MEM > these days). > > What people do use /dev/mem for is to mmap() PCI memory, and then you > can access it from user space. That's the traditional model that X.org > used to do etc. Yes, thanks, I was confused. mmap() is indeed unaffected, only read and write are. So the only problem I have, is the test-case I was trying, that does read/write and works depending on the ram size (under qemu). But there is no any problem for dosemu. Perhaps for consistency it would be good to make things independent of the ram size, but then there is no real problem here. So sorry for the noise!