From owner-freebsd-hackers@freebsd.org Sun Feb 19 23:59:26 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 189FFCE5408 for ; Sun, 19 Feb 2017 23:59:26 +0000 (UTC) (envelope-from ctuffli@gmail.com) Received: from mail-ot0-x230.google.com (mail-ot0-x230.google.com [IPv6:2607:f8b0:4003:c0f::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CB5AF121 for ; Sun, 19 Feb 2017 23:59:25 +0000 (UTC) (envelope-from ctuffli@gmail.com) Received: by mail-ot0-x230.google.com with SMTP id x10so19665887otb.1 for ; Sun, 19 Feb 2017 15:59:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=9oimjYOe9EF36DaYSgrUybxQBfuAzI/rZ8UDOZaXGno=; b=vYzcS701MzEgRe9Cnmg6kKbTZn8HHGMwKXEkK6lvJbr+ak7zrTjoNgdRtKL6lCCGuk +ZqmGzbXuJrFLv7hFD99A4UJf3NfvYRlC2TveHieuww5hkBp8+7pcTRpng9kusl6YXHw lygdv3Xb/nSqKsQ2OufOcKEoBpy99s3WmFqcmU6CKstONtfjsDxWruNt0GRDJnmbrmya 0783j247Gtk4ZWKntdtnldj+DSViOORiOmPkQJhwFjQJIdproDaGDDZaHE/quypD3ApD kIqAVQRcNtjotXEpBiXdvL4VPh87wLvtgrMWbqid/wcOswHJa/x2yG6FIYBrF8ePg/nn lyiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=9oimjYOe9EF36DaYSgrUybxQBfuAzI/rZ8UDOZaXGno=; b=RQeWInbgVyfJjDhimgD9pn7KnhrA/bJ3tUeH2j/++2/FrvttpAhIrDKdVm/VG2mP1o 05CHvqjGwRNV1DdYo0dBDZY8XT5g9msV1pptEjW1tLlBLrjNqbHEbi+Vxt/9Awrq5M8M aRvZNCsKmrLVcamaKseYJJ7mGZ2J9E7ceFtjERruMkp6cyk35WSSJy4nSX9ssYrsWTLh itZZmp77kGKDv3hIgYRJpUVA0DeetACHWo8pm0YfsXj5o0tfvrSzsd5WxYcaSthToEwD fXHUXMCyrBib6+PzQD297smNkKuQBFl1zvp75aA21jNJFe5j7AHF2HieptOdVLPxFG4W t3cA== X-Gm-Message-State: AMke39nigz545mqfjRuwZRATnDhHwiLwUIanBjYrWvuyQytjVBnUohT9I1TFmZh9gwwPW85MoLDvmDGVmLvxUg== X-Received: by 10.157.82.13 with SMTP id e13mr1665918oth.50.1487548764909; Sun, 19 Feb 2017 15:59:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.70.137 with HTTP; Sun, 19 Feb 2017 15:59:24 -0800 (PST) From: Chuck Tuffli Date: Sun, 19 Feb 2017 15:59:24 -0800 Message-ID: Subject: how to map kernel memory to user space To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Feb 2017 23:59:26 -0000 I'm trying to work around a problem by mapping the data from a kernel allocated buffer into a user space application. There was a post some time back with a possible way to do this [1], but while this creates a valid buffer in the user space application, the contents is all zeros instead of containing the expected data. Is this approach not possible? Does anything obviously stick out below? TIA. --chuck rc = vm_map_lookup(&kernel_map, kaddr, VM_PROT_ALL, &entry, &obj, &pindex, &prot, &is_wired); vm_map_lookup_done(kernel_map, entry); if (rc) printf("%s: vm_map_lookup() = %d\n", __func__, rc); PROC_LOCK(p); uaddr = round_page((vm_offset_t)vms->vm_daddr + lim_max(td, RLIMIT_DATA)); PROC_UNLOCK(p); objoff = kaddr - (entry->start + entry->offset); vm_object_reference(obj); rc = vm_map_find(map, obj, objoff, &uaddr, sizeof(struct nvme_controller_data), 0, VMFS_OPTIMAL_SPACE, VM_PROT_RW, VM_PROT_RW, MAP_INHERIT_SHARE); [1] http://markmail.org/message/ph5yuonevqjhhbig