From nobody Mon Jun 21 04:32:37 2021 X-Original-To: current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 9AC4811CA413 for ; Mon, 21 Jun 2021 04:32:40 +0000 (UTC) (envelope-from nc@FreeBSD.org) Received: from rainpuddle.neelc.org (locks.neelc.org [158.51.84.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4G7c883c9Cz3r0V; Mon, 21 Jun 2021 04:32:40 +0000 (UTC) (envelope-from nc@FreeBSD.org) Received: from mail.neelc.org (locks.neelc.org [IPv6:2602:fed2:7106:25ff::1]) by rainpuddle.neelc.org (Postfix) with ESMTPSA id 43F928924E; Sun, 20 Jun 2021 21:32:37 -0700 (PDT) List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 Date: Sun, 20 Jun 2021 21:32:37 -0700 From: Neel Chauhan To: Hans Petter Selasky Cc: Mark Johnston , current@freebsd.org Subject: Re: Kernel/driver hacking: panic: Assertion vm_object_busied((m->object)) failed at /usr/src/sys/vm/vm_page.c:5455 In-Reply-To: <6df7b46d-26ca-b897-66fd-b6a441475348@selasky.org> References: <8bd27c2a72ebfa9299bca7d930297faf@FreeBSD.org> <389e4560afdc211e9915746b11a0d0d0@FreeBSD.org> <61de965123274866935935bded6c3d58@FreeBSD.org> <6df7b46d-26ca-b897-66fd-b6a441475348@selasky.org> User-Agent: Roundcube Webmail/1.4.11 Message-ID: <18a370deb9efbbb8d20a5eb3f00daf6d@FreeBSD.org> X-Sender: nc@FreeBSD.org Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4G7c883c9Cz3r0V X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N Hi Hans, Sorry if I have to bother you again. On 2021-06-20 01:36, Hans Petter Selasky wrote: > sg_dma_address() is zero, because the memory hasn't been loaded. Makes sense! > You need to handle two cases there: > > When r->iobase is -1 and when it is not. > > I suspect you should add r->iobase to the sg_dma_address() only and > only when it is non -1. I have addressed it in my code. Hans, while your approach is correct (that's also done in Linux), for some reason it still crashes on vm_page_insert(). I must be doing "pa = " wrong. Stacktrace: https://misc.neelc.org/drm-kmod/stacktrace2.txt I have a separate function for getting the physical address: https://github.com/neelchauhan/drm-kmod/blob/5.7-wip/drivers/gpu/drm/i915/intel_freebsd.c#L219 This crash happens when "iobase == -1", so we execute Lines 228-231: - } else { struct sgt_iter sgt = __sgt_iter(sgl, 0); pa = (sgt.pfn + (sgt.curr >> PAGE_SHIFT)) << PAGE_SHIFT; } sgt.curr is zero, since (I believe) it's the first iteration. I have copied the Linux approach and ported what I felt was necessary, I am worried I am doing this wrong. > Also, there is a superfluous "pa = " in the beginning of the function. (Hopefully) I have cleaned it up. > --HPS -Neel (nc@)