Date: Mon, 22 Jul 2019 14:03:26 +0200 (CEST) From: Ronald Klop <ronald-lists@klop.ws> To: Laurie Jennings <laurie_jennings_1977@yahoo.com> Cc: FreeBSD Current <freebsd-current@freebsd.org>, Konstantin Belousov <kostikbel@gmail.com> Subject: Re: mmap port from 9 not working Message-ID: <1027101659.12.1563797006919@localhost> In-Reply-To: <550659871.4389820.1563721133104@mail.yahoo.com> References: <446145008.4396329.1563680883838.ref@mail.yahoo.com> <446145008.4396329.1563680883838@mail.yahoo.com> <20190721144404.GJ47193@kib.kiev.ua> <550659871.4389820.1563721133104@mail.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Van: Laurie Jennings <laurie_jennings_1977@yahoo.com>
Datum: zondag, 21 juli 2019 16:58
Aan: Konstantin Belousov <kostikbel@gmail.com>
CC: FreeBSD Current <freebsd-current@freebsd.org>
Onderwerp: Re: mmap port from 9 not working
>
> On Sunday, July 21, 2019, 10:44:14 AM EDT, Konstantin Belousov <kostikbel@gmail.com> wrote:
>
> On Sun, Jul 21, 2019 at 03:48:03AM +0000, Laurie Jennings wrote:
> > I have some custom stuff I'm porting from Freebsd 9.x using mmap. I get a pointer from the kernel via an ioctl and I map it into a shared buffer.
> > char *kptr; // mem ptr from kernel
> > fd=open("/dev/kmem",O_RDWR);memp=mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,(off_t) ptr);
> >
> > This worked perfectly in 9; memp I had a shared block of memory between the kernel and user space.
> > In 11.3 this returns an errno 22, which is pretty murky. I did notice that off_t doesnt yield an actual offset; I've tried putting in the correct value manuallybut it just fails and fails.I've tried read only also.
> > Please Help!
>
> | Start with providing (and looking yourself) at the output of kdump/ktrace
> | around the failing mmap. The checks for correctness of the mmap(2) arguments
> | were greatly improved during years after FreeBSD 9.
> Since posting this I found a thread that said something about mmap no longer supporting /dev/kmem. If that's that case I need to find another method. No sense spending a day debugging something thatisn't supposed to work.
> SHOULD this still work? This always worked fine with non-wired memory but maybe things have changed since 9.
>
It looks like this is not possible anymore. Here is the code change with some explanation.
https://svnweb.freebsd.org/base?view=revision&revision=307332
https://reviews.freebsd.org/D8248
Just a question of my site out of interest to people who know more about this than I do. Does Page Table Isolation (PTI) also prevent mapping /dev/kmem in user space?
https://wiki.freebsd.org/SpeculativeExecutionVulnerabilities#Meltdown_.28CVE-2017-5754.29
Regards,
Ronald.
From owner-freebsd-current@freebsd.org Mon Jul 22 12:12:17 2019
Return-Path: <owner-freebsd-current@freebsd.org>
Delivered-To: freebsd-current@mailman.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
by mailman.nyi.freebsd.org (Postfix) with ESMTP id E0F8CB07E8
for <freebsd-current@mailman.nyi.freebsd.org>;
Mon, 22 Jul 2019 12:12:17 +0000 (UTC)
(envelope-from kostikbel@gmail.com)
Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
server-signature RSA-PSS (4096 bits))
(Client did not present a certificate)
by mx1.freebsd.org (Postfix) with ESMTPS id 409706CA8D
for <freebsd-current@freebsd.org>; Mon, 22 Jul 2019 12:12:17 +0000 (UTC)
(envelope-from kostikbel@gmail.com)
Received: from tom.home (kib@localhost [127.0.0.1])
by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id x6MCC9ee009163
(version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO);
Mon, 22 Jul 2019 15:12:12 +0300 (EEST)
(envelope-from kostikbel@gmail.com)
DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua x6MCC9ee009163
Received: (from kostik@localhost)
by tom.home (8.15.2/8.15.2/Submit) id x6MCC9J7009162;
Mon, 22 Jul 2019 15:12:09 +0300 (EEST)
(envelope-from kostikbel@gmail.com)
X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com
using -f
Date: Mon, 22 Jul 2019 15:12:09 +0300
From: Konstantin Belousov <kostikbel@gmail.com>
To: Ronald Klop <ronald-lists@klop.ws>
Cc: Laurie Jennings <laurie_jennings_1977@yahoo.com>,
FreeBSD Current <freebsd-current@freebsd.org>
Subject: Re: mmap port from 9 not working
Message-ID: <20190722121209.GL47193@kib.kiev.ua>
References: <446145008.4396329.1563680883838.ref@mail.yahoo.com>
<446145008.4396329.1563680883838@mail.yahoo.com>
<20190721144404.GJ47193@kib.kiev.ua>
<550659871.4389820.1563721133104@mail.yahoo.com>
<1027101659.12.1563797006919@localhost>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1027101659.12.1563797006919@localhost>
User-Agent: Mutt/1.12.1 (2019-06-15)
X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM,
NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home
X-BeenThere: freebsd-current@freebsd.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Discussions about the use of FreeBSD-current
<freebsd-current.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-current>,
<mailto:freebsd-current-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-current/>
List-Post: <mailto:freebsd-current@freebsd.org>
List-Help: <mailto:freebsd-current-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-current>,
<mailto:freebsd-current-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Jul 2019 12:12:17 -0000
On Mon, Jul 22, 2019 at 02:03:26PM +0200, Ronald Klop wrote:
>
> Van: Laurie Jennings <laurie_jennings_1977@yahoo.com>
> Datum: zondag, 21 juli 2019 16:58
> Aan: Konstantin Belousov <kostikbel@gmail.com>
> CC: FreeBSD Current <freebsd-current@freebsd.org>
> Onderwerp: Re: mmap port from 9 not working
> >
> > On Sunday, July 21, 2019, 10:44:14 AM EDT, Konstantin Belousov <kostikbel@gmail.com> wrote:
> >
> > On Sun, Jul 21, 2019 at 03:48:03AM +0000, Laurie Jennings wrote:
> > > I have some custom stuff I'm porting from Freebsd 9.x using mmap. I get a pointer from the kernel via an ioctl and I map it into a shared buffer.
> > > char *kptr; // mem ptr from kernel
> > > fd=open("/dev/kmem",O_RDWR);memp=mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,(off_t) ptr);
> > >
> > > This worked perfectly in 9; memp I had a shared block of memory between the kernel and user space.
> > > In 11.3 this returns an errno 22, which is pretty murky. I did notice that off_t doesnt yield an actual offset; I've tried putting in the correct value manuallybut it just fails and fails.I've tried read only also.
> > > Please Help!
> >
> > | Start with providing (and looking yourself) at the output of kdump/ktrace
> > | around the failing mmap. The checks for correctness of the mmap(2) arguments
> > | were greatly improved during years after FreeBSD 9.
> > Since posting this I found a thread that said something about mmap no longer supporting /dev/kmem. If that's that case I need to find another method. No sense spending a day debugging something thatisn't supposed to work.
> > SHOULD this still work? This always worked fine with non-wired memory but maybe things have changed since 9.
> >
> It looks like this is not possible anymore. Here is the code change with some explanation.
> https://svnweb.freebsd.org/base?view=revision&revision=307332
> https://reviews.freebsd.org/D8248
>
> Just a question of my site out of interest to people who know more about this than I do. Does Page Table Isolation (PTI) also prevent mapping /dev/kmem in user space?
> https://wiki.freebsd.org/SpeculativeExecutionVulnerabilities#Meltdown_.28CVE-2017-5754.29
KPTI has nothing to do with that.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1027101659.12.1563797006919>
