From owner-freebsd-current@freebsd.org Thu Dec 7 15:35:49 2017 Return-Path: Delivered-To: freebsd-current@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 0EC25E8A52D; Thu, 7 Dec 2017 15:35:49 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-lf0-x22c.google.com (mail-lf0-x22c.google.com [IPv6:2a00:1450:4010:c07::22c]) (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 81B5A68A64; Thu, 7 Dec 2017 15:35:48 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-lf0-x22c.google.com with SMTP id a12so8609322lfe.4; Thu, 07 Dec 2017 07:35:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=0xXnogy0dgxGVvel8hclkxs0Zi0brXreI5z7rNweKqc=; b=HFfdDakLbpjnMtIUqF6QW8nNkQfUWPObOqFEli7wbjP5odfZjCV1hAJSj7m0QKYxMl 4/Myx3ZvI2gSOvgPtM4Xxv03C6rwirnVM3lrxwJeLOno6G/cgJLWI/1ZaAGGXR8r8cCQ 4FOHgUGSEthhazzt8OYomV/peNFFgx/pelOF2ZYgomLtbQKHGIXPhoMqUgPpoTQoqElv wrdMBRyjQzBvmMoQpRB4qw5O9o/FtqX89BK7Tko0YESXUNfft+9xMhRmUkoYW3kNJwqY 23euePtPo2rSDyjZ/oEC6Ep/PYeLpVhBhmKyIIPhimarUZOCysVeICNuBwhUhc15aqhR FN2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=0xXnogy0dgxGVvel8hclkxs0Zi0brXreI5z7rNweKqc=; b=CjpZ9wGwchc3VrN95OzwTn0TjwzwGqlbz+l82NWs4/I7CUNagbbqkcgq6yc9Ozsb5D fr1gjs6an0mdWFRzPteuoXzwarMs3qe8AGGLHOE9bCz/0/JXNx6qJFL+FwuUbcOkTbCO UvbjQlmtY2UHOMe1OobX2SadrZ9ySzk1AbsgOpphh2WS+0jp5VGrWAn0/1HR06gWiits KRosxhQlXN5zov6+CH01Sa8Bv+LAQhVzIlUdMsT5LyDIVKYdq34S5lziLSI5Sd7vy0NH /ieojMftSgIY2q6rCq+cgaxdwSbwRZamnaJLiWU5oRdAyctL1s2HWt0B/v3IckjaCzNJ 2aSw== X-Gm-Message-State: AJaThX7Q/c13jP9XVCu8T7yzOQebEDLu11BbLseiUEXHDrskDvHo09hl nWuz4SnPjvoKkkbzu6X+ISRgbRurYPCsyyfHtEI= X-Google-Smtp-Source: AGs4zMYEilIn5ZdB0LT5lu00HR4iYe76UIVFgemS62ZovSPdY3DPcA8nAPFbhhOlkhWJM/AThYvSBD/4vkW6FBqc3Ic= X-Received: by 10.25.196.202 with SMTP id u193mr12707409lff.169.1512660945720; Thu, 07 Dec 2017 07:35:45 -0800 (PST) MIME-Version: 1.0 Sender: asomers@gmail.com Received: by 10.179.76.19 with HTTP; Thu, 7 Dec 2017 07:35:45 -0800 (PST) In-Reply-To: <5e95dc14-9d3b-e2eb-b89c-f66f7857eb58@FreeBSD.org> References: <07b9dbda-60ef-3643-308f-18a05e8ca958@FreeBSD.org> <20171205140308.GA94043@FreeBSD.org> <5e95dc14-9d3b-e2eb-b89c-f66f7857eb58@FreeBSD.org> From: Alan Somers Date: Thu, 7 Dec 2017 08:35:45 -0700 X-Google-Sender-Auth: 9y2go0WvCUUnyHF8oKSYDUt1Iyo Message-ID: Subject: Re: couple of nvidia-driver issues To: Andriy Gapon Cc: Alexey Dokuchaev , freebsd-x11 , FreeBSD Current , Aaron Plattner Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.25 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.25 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: Thu, 07 Dec 2017 15:35:49 -0000 On Thu, Dec 7, 2017 at 2:33 AM, Andriy Gapon wrote: > > [cc-ing current@ to raise more awareness] > > On 05/12/2017 16:03, Alexey Dokuchaev wrote: > > On Fri, Nov 24, 2017 at 11:31:51AM +0200, Andriy Gapon wrote: > >> > >> I have reported a couple of nvidia-driver issues in the FreeBSD section > >> of the nVidia developer forum, but no replies so far. > >> > >> Well, the first issue is not with the driver, but with a utility that > >> comes with it, nvidia-smi: > >> https://devtalk.nvidia.com/default/topic/1026589/freebsd/ > nvidia-smi-query-gpu-spins-forever-on-freebsd-head-amd64-/ > >> I wonder if I am the only one affected or if I see the problem because > >> I am on head or something else. > >> I am pretty sure that the problem is caused by a programming bug related > >> to strtok_r. > > > > I'll try to reproduce it and report back. > > I've done some work with a debugger and it seems that there is code that > does > something like this: > > char *last = NULL; > > while (1) { > if (last == NULL) > p = strtok_r(str, sep, &last); > else > p = strtok_r(NULL, sep, &last); > if (p == NULL) > break; > ... > } > > The problem is that when 'p' points to the last token, 'last' is NULL (in > FreeBSD implementation of strtok_r). That means that when we go to the > next > iteration the parsing starts all over again leading to the endless loop. > The code is incorrect from the standards point of view, because the value > of > 'last' is completely opaque and should not be used for anything else but > passing > it back to strtok_r. > > I used gdb -w to change the logic to: > > char *last = 1; > > While (1) { > if (last == 1) > p = strtok_r(str, sep, &last); > else > p = strtok_r(NULL, sep, &last); > ... > } > > Where 1 is used as an "impossible" pointer value which is neither NULL nor > a > valid pointer that can be set by strtok_r. It's not ideal, but binary code > editing is not as easy as that of source code. > > The binary patch is here: https://people.freebsd.org/~ > avg/nvidia-smi.bsdiff > > >> The second issue is with the FreeBSD support for the kernel driver: > >> https://devtalk.nvidia.com/default/topic/1026645/freebsd/ > panic-related-to-nvkms_timers-lock-sx-lock-/ > >> I would like to get some feedback on my analysis. > >> I am testing this patch right now: > >> https://people.freebsd.org/~avg/extra-patch-src_nvidia- > modeset_nvidia-modeset-freebsd.c > > > > Unfortunately, I'm not an expert on kernel locking primitives to give you > > a proper review, let's see what others have to say. > > It's been a while since I posted the patch and there are no comments yet. > I can only add that I am running an INVARIANTS and WITNESS enabled kernel > all > the time and before the patch I was getting kernel panics every now and > then. > Since I started using the patch I haven't had a single nvidia panic yet. > > >> Also, what's the best place or who are the best people with whom to > >> discuss such issues? > > > > Yes, this is a problem now: since Christian Zander had left nVidia, he > > could not tell me who'd be their next liaison to talk to from FreeBSD > > community. :-( > > Oh, I didn't know about Christian's departure. > So, we are not in a very good position now. How about Aaron Plattner (CC'd). Aaron, are you still working on FreeBSD driver issues? -Alan