From owner-freebsd-current@freebsd.org Mon Jul 22 12:03:36 2019 Return-Path: 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 DCF47B03B2 for ; Mon, 22 Jul 2019 12:03:36 +0000 (UTC) (envelope-from ronald-lists@klop.ws) Received: from smtp-relay-int.realworks.nl (smtp-relay-int.realworks.nl [194.109.157.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E235D6C333 for ; Mon, 22 Jul 2019 12:03:34 +0000 (UTC) (envelope-from ronald-lists@klop.ws) Date: Mon, 22 Jul 2019 14:03:26 +0200 (CEST) From: Ronald Klop To: Laurie Jennings Cc: FreeBSD Current , Konstantin Belousov 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> Subject: Re: mmap port from 9 not working MIME-Version: 1.0 X-Mailer: Realworks (467.829.66eb8d40dee) Importance: Normal X-Priority: 3 (Normal) X-Rspamd-Queue-Id: E235D6C333 X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; spf=pass (mx1.freebsd.org: domain of ronald-lists@klop.ws designates 194.109.157.24 as permitted sender) smtp.mailfrom=ronald-lists@klop.ws X-Spamd-Result: default: False [0.23 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.77)[-0.772,0]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_SPF_ALLOW(-0.20)[+ip4:194.109.157.0/24]; NEURAL_HAM_LONG(-0.56)[-0.559,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DMARC_NA(0.00)[klop.ws]; URI_COUNT_ODD(1.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.01)[mx2.greenhost.nl,mx1.greenhost.nl]; RCVD_IN_DNSWL_NONE(0.00)[24.157.109.194.list.dnswl.org : 127.0.15.0]; HAS_X_PRIO_THREE(0.00)[3]; NEURAL_SPAM_SHORT(0.42)[0.420,0]; IP_SCORE(-0.05)[ipnet: 194.109.0.0/16(-0.15), asn: 3265(-0.12), country: NL(0.01)]; FREEMAIL_TO(0.00)[yahoo.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MID_RHS_NOT_FQDN(0.50)[]; ASN(0.00)[asn:3265, ipnet:194.109.0.0/16, country:NL]; MIME_TRACE(0.00)[0:+,1:+]; RCVD_TLS_ALL(0.00)[] Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Jul 2019 12:03:36 -0000 Van: Laurie Jennings Datum: zondag, 21 juli 2019 16:58 Aan: Konstantin Belousov CC: FreeBSD Current Onderwerp: Re: mmap port from 9 not working > > On Sunday, July 21, 2019, 10:44:14 AM EDT, Konstantin Belousov 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: 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 ; 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 ; 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 To: Ronald Klop Cc: Laurie Jennings , FreeBSD Current 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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 > Datum: zondag, 21 juli 2019 16:58 > Aan: Konstantin Belousov > CC: FreeBSD Current > Onderwerp: Re: mmap port from 9 not working > > > > On Sunday, July 21, 2019, 10:44:14 AM EDT, Konstantin Belousov 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.