Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966179AbcJ1X0Q (ORCPT ); Fri, 28 Oct 2016 19:26:16 -0400 Received: from mail-oi0-f46.google.com ([209.85.218.46]:34420 "EHLO mail-oi0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965976AbcJ1X0P (ORCPT ); Fri, 28 Oct 2016 19:26:15 -0400 MIME-Version: 1.0 In-Reply-To: <89281ddd-ea21-6de8-b4dd-57ff4b0d2040@list.ru> References: <52478c6c-39cb-35b1-0517-33d9f6e99a5a@list.ru> <89281ddd-ea21-6de8-b4dd-57ff4b0d2040@list.ru> From: Linus Torvalds Date: Fri, 28 Oct 2016 16:26:13 -0700 X-Google-Sender-Auth: KCS5M1AG8YoSe6DLf-_a1-BdGKc Message-ID: Subject: Re: /dev/mem and PCI memory = EFAULT (regression?) To: Stas Sergeev Cc: Andy Lutomirski , Linux kernel , dosemu-devel , Bart Oldeman , "Eric W. Biederman" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1737 Lines: 41 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? That code is ancient, going back in some form or another at least ten years. 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. I'm surprised if there is a regression here, because I think read/write really hasn't been supported in like forever. It's fundamentally impossible to do on some architectures: the physical access depends on the _size_ of the access on at least some alpha CPU's, so you can't just do a random access to PCI address X, you need to have a real size etc. But if you can point to a particular commit that broke something (eg with bisection), I'll certainly take a second look. I might have missed something. Linus