From owner-freebsd-hackers@freebsd.org Tue Feb 19 01:12:57 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0167214F345F for ; Tue, 19 Feb 2019 01:12:56 +0000 (UTC) (envelope-from amshafer64@gmail.com) Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C6D428F2A7 for ; Tue, 19 Feb 2019 01:12:55 +0000 (UTC) (envelope-from amshafer64@gmail.com) Received: by mail-qt1-x831.google.com with SMTP id p25so21098218qtb.3 for ; Mon, 18 Feb 2019 17:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=dst250wxz11f8W3fyKPiTbhDo/FW2ZZbumMK+2LeK4I=; b=kwFykdXOL9eMUjBJY1lAJhXjAmcHSiPQ+rSuOFYBmavWQAPPtFV6lt45alSpeZAR7N WVL2FIUxc6EuxP7blM/Pg/6tHDQbSdOXhQBC325QeLfbX/poMJO1oiXAa7BdGccs2/7Z 15n23biEMOCE1+MyKKidRhRYfKS76OaXWQXzIeGyGN6drybMTFO6bBye4Zdw4AtBkS2G F9wyL/vJiwqi2DzsA0ozy3jwPEIbNG2nqw8PdcnXqrh5hwWaaf8/uJXfz7vfRnCs+07D 525cI/a68FEuAineebuiGfrD5BfDnAlC4FJK2gXDko9SG5aCavor3y0qUm6PSZtTMsZz P22Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=dst250wxz11f8W3fyKPiTbhDo/FW2ZZbumMK+2LeK4I=; b=nWxs97YK6aurwdOAz1UzBKMpFU+pgW1fgLuBa79/dqf0MLbHYUxTLR/Elnmd/JMeQp npPSkx64ZMGa1LCulPCRHmDjklUL4i4/b32+CawWfGqYf6Gg30v61Ly9P9Ny9dDU0uwJ vmfCmEpmIrkM5a7BpFV5Lgy++ho1rBn4+CWiIzICUi7RYTTa9+ZJPOw+rz4+8nEUODpp PMa2mNRIvaPNWiV7N86w56cGu07L3whCER0hLLmDDkguxmgdd22+IiZhRNBSX3CeEkAM oH8aYCbXWgnx0LR3hnLDWKN9LFhoZf6VxCSHKKL5MDav1ny5h+tpTKGi4VCmqQNbteTp O6qw== X-Gm-Message-State: AHQUAuZMEUB4s5cPNicUSKnOTfybuG1LaB6jBQ52deuAwyet8tJllgD4 Eb9R/nNuYy78c4oatF5vq1ujlWFh X-Google-Smtp-Source: AHgI3IZMe9E8XfsEP6l/RyVRH11B0vIU48+Eew6FPxbs/IZlek14jxRgcqDsyP9DDrV2J+yPWUVjGA== X-Received: by 2002:ac8:2d0b:: with SMTP id n11mr20208852qta.143.1550538774878; Mon, 18 Feb 2019 17:12:54 -0800 (PST) Received: from localhost ([178.128.156.9]) by smtp.gmail.com with ESMTPSA id e21sm9046737qkj.90.2019.02.18.17.12.53 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 17:12:53 -0800 (PST) From: Austin Shafer To: freebsd-hackers@freebsd.org Subject: vm_page_t's do not appear initialized Date: Tue, 19 Feb 2019 01:12:52 -0500 Message-ID: <86lg2cz4pn.fsf@triplebuff.com> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: C6D428F2A7 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=kwFykdXO; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of amshafer64@gmail.com designates 2607:f8b0:4864:20::831 as permitted sender) smtp.mailfrom=amshafer64@gmail.com X-Spamd-Result: default: False [-2.68 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_NONE(0.00)[]; DATE_IN_FUTURE(4.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; MX_GOOD(-0.01)[alt3.gmail-smtp-in.l.google.com,alt4.gmail-smtp-in.l.google.com,gmail-smtp-in.l.google.com,alt2.gmail-smtp-in.l.google.com,alt1.gmail-smtp-in.l.google.com]; NEURAL_HAM_SHORT(-0.97)[-0.966,0]; FROM_EQ_ENVFROM(0.00)[]; IP_SCORE(-2.71)[ip: (-8.89), ipnet: 2607:f8b0::/32(-2.59), asn: 15169(-1.98), country: US(-0.07)]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; RCVD_TLS_LAST(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[1.3.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2019 01:12:57 -0000 Hi freebsd-hackers, While trying to write a DRM buffer page fault handler, I've run into an issue where vm_page_t structs appear to be uninitialized and contain random data. Most of These "random" fields in the structures remain the same after rebooting, which makes me think that I have missed something and am misinterpreting the fields. After a little over a week reading through source code and trying different things, I wanted to see if anyone had any insight that could help me learn whats going on. Thanks in advance! (For context, here is the project this is from) https://github.com/aritger/eglstreams-kms-example/issues/7 I have more verbose examples below, but some quick examples of what I'm seeing are: - vm_page_t->phys_addr does not match expected - vm_page_t->flags has values not in the PG_* macros - same for busy_lock and other entries - kgdb can't read memory at vm_page_t->object - etc... It looks like vm_page_init_page was not called on these vm_page_t's I am interacting with, but I can't seem to figure out why that would not be the case? I've also booted into single user mode so I can look at things before any graphics drivers can mess with them, but the pages still look the same. While writing the fault handler I've been using the i915kms driver's handler as a reference, and I've included page structs from an intel laptop as an example of what I expected to see. _____________________________________________________________________ Here is an example of a vm_page_t I get for the start of device memory on an NVIDIA 1070: _____________________________________________________________________ # uname -a FreeBSD wolfgang 12.0-RELEASE FreeBSD 12.0-RELEASE #5 r343025M: Sun Feb 10 14:29:01 EST 2019 ashafer@wolfgang:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64 ---------------- pciconf -lbv: ... vgapci0@pci0:1:0:0: class=0x030000 card=0x33011462 chip=0x1b8110de rev=0xa1 hdr=0x00 vendor = 'NVIDIA Corporation' device = 'GP104 [GeForce GTX 1070]' class = display subclass = VGA bar [10] = type Memory, range 32, base 0xee000000, size 16777216, enabled bar [14] = type Prefetchable Memory, range 64, base 0xd0000000, size 268435456, enabled bar [1c] = type Prefetchable Memory, range 64, base 0xe0000000, size 33554432, enabled bar [24] = type I/O Port, range 32, base 0xe000, size 128, enabled ... ---------------- /* get the page corresponding device mem */ vm_page_t page = PHYS_TO_VM_PAGE(0xd0000000) <--- page == 0xfffff802266a5980 ---------------- (kgdb) p/x *(vm_page_t)0xfffff802266a5980 $1 = {plinks = {q = {tqe_next = 0x2c43b579e62bf7ae, tqe_prev = 0xb47eac47a195af64}, s = {ss = { sle_next = 0x2c43b579e62bf7ae}, pv = 0xb47eac47a195af64}, memguard = { p = 0x2c43b579e62bf7ae, v = 0xb47eac47a195af64}}, listq = { tqe_next = 0x6d4683b13bdc1486, tqe_prev = 0x3666c2179bcddb1d}, object = 0xff2e12d8cc36710b, pindex = 0xb5bd170e69b840a2, phys_addr = 0xaad51419a796c44d, md = {pv_list = {tqh_first = 0x38d208abcf6951ec, tqh_last = 0x850ca846e9f2d9f3}, pv_gen = 0xf277ff0c, pat_mode = 0x564e1542}, wire_count = 0xc810bbe0, busy_lock = 0x4ee4b98f, hold_count = 0xbcda, flags = 0x3f53, aflags = 0x37, oflags = 0x66, queue = 0xa, psind = 0xc1, segind = 0x23, order = 0xb7, pool = 0x12, act_count = 0x9c, valid = 0x22, dirty = 0x71} ---------------- just in case this is related... I think vm_phys_segs drives which pages get initialized during system boot? ---------------- (kgdb) p/x vm_phys_segs $2 = {{start = 0x10000, end = 0x6f000, first_page = 0xfffff80443776000, domain = 0x0, free_queues = 0xffffffff82057670}, {start = 0x70000, end = 0x87000, first_page = 0xfffff80443778700, domain = 0x0, free_queues = 0xffffffff82057670}, { start = 0x100000, end = 0x1000000, first_page = 0xfffff8044377c180, domain = 0x0, free_queues = 0xffffffff82057670}, {start = 0x1000000, end = 0x2c6b000, first_page = 0xfffff804437dd980, domain = 0x0, free_queues = 0xffffffff82057400}, { start = 0x2c73000, end = 0x2cab000, first_page = 0xfffff80443896838, domain = 0x0, free_queues = 0xffffffff82057400}, {start = 0x2e00000, end = 0x96c80000, first_page = 0xfffff804438a0980, domain = 0x0, free_queues = 0xffffffff82057400}, { start = 0x98083000, end = 0x9c68f000, first_page = 0xfffff80447538eb8, domain = 0x0, free_queues = 0xffffffff82057400}, {start = 0x9cfff000, end = 0x9d000000, first_page = 0xfffff8044773d918, domain = 0x0, free_queues = 0xffffffff82057400}, { start = 0x100000000, end = 0x44360f000, first_page = 0xfffff80449f75980, domain = 0x0, free_queues = 0xffffffff82057400}, {start = 0x100000000, end = 0x44360f000, first_page = 0xfffff80449f75980, domain = 0x0, free_queues = 0xffffffff82057400}, { start = 0x0, end = 0x0, first_page = 0x0, domain = 0x0, free_queues = 0x0} } _____________________________________________________________________ EXPECTED: This is what the vm_page_t for device memory on a intel laptop (Different computer, this looks like what I should be getting) _____________________________________________________________________ pciconf -lbv: ... vgapci0@pci0:0:2:0: class=0x030000 card=0xfa121179 chip=0x04168086 rev=0x06 hdr=0x00 vendor = 'Intel Corporation' device = '4th Gen Core Processor Integrated Graphics Controller' class = display subclass = VGA bar [10] = type Memory, range 64, base 0xb0000000, size 4194304, enabled bar [18] = type Prefetchable Memory, range 64, base 0xa0000000, size 268435456, enabled bar [20] = type I/O Port, range 32, base 0x4000, size 64, enabled ... ---------------- vm_page_t page = PHYS_TO_VM_PAGE(0xa0000000) <--- page == ---------------- (kgdb) p/x *(vm_page_t)0xfffff80447875980 $1 = {plinks = {q = {tqe_next = 0x0, tqe_prev = 0x0}, s = {ss = {sle_next = 0x0}, pv = 0x0}, memguard = {p = 0x0, v = 0x0}}, listq = {tqe_next = 0x0, tqe_prev = 0x0}, object = 0x0, pindex = 0x0, phys_addr = 0xa0000000, md = {pv_list = {tqh_first = 0x0, tqh_last = 0xfffff804478759b8}, pv_gen = 0x0, pat_mode = 0x1}, wire_count = 0x1, busy_lock = 0x1, hold_count = 0x0, flags = 0x4, aflags = 0x0, oflags = 0x0, queue = 0xff, psind = 0x0, segind = 0x0, order = 0x0, pool = 0x0, act_count = 0x0, valid = 0x0, dirty = 0x0} _____________________________________________________________________ Again I'm not really sure what I'm running into. I've had to try to learn the FreeBSD vm system while working on this, so I'm sorry if I missed anything obvious to those who have more experience. I'm more than happy to provide any information or test anything and I'd appreciate any pointers to what can explain this. Thank you so much for your time! Austin Shafer