Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp381671ybl; Tue, 7 Jan 2020 07:44:23 -0800 (PST) X-Google-Smtp-Source: APXvYqywBTwJDLFtMOZTg3hfo/6ZIChdU0IvRUwOJWeqkdHAiInsxB+C/UyRBhpH0m9E8sCakR6N X-Received: by 2002:a9d:68cc:: with SMTP id i12mr340402oto.207.1578411863620; Tue, 07 Jan 2020 07:44:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578411863; cv=none; d=google.com; s=arc-20160816; b=0BfPKGfDIYISN3gTb3Vkkvw3tjViH3WGby2JP1WlvYucCQFpSrC6ci3mXrkUDnhfkZ pstnEwv2KtTM2uJO8eOTQfULX9bZZbERKfiCIGzxZtYjnyBNMQmBneCrB+Qsw+HbP195 Qppv9x3Iq3rBqcIZhy99mrBmZVLRV5zQd6QL4DfKw5PLzgyC1rE0RjkX22nu5/W+QD47 /IXTLrNfOIkJ+497fHB7Ssj0rj3RQfR5wVjLdimX46lqTU46XEwkDxqwTAHRI1j82Vt1 d2Zm6p2gbS0jF1u31+nATuAcADqtwqZbLz9pd2ab4IEqycYeXqxIJSIrhL6AA17K+g6+ TTFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date:dkim-signature; bh=e3JSrkA31lPQjM0qXrRZGQXu9t0TvJbA8jjtu6S4Kws=; b=ywvVbG3SrFdP+Yw1qoIlfcGWRWPyLHNxN+/U6kJ1jZdV1zf0ShWdtimikgmjlMeKEy GM0I23KL5KyCprmeTaN2fKrMMZzt3ifq2rCcZlxm/pKUDm5le+5rwGZunPIsUt517W+Y KSDYqkT0kA6KA9WxxRu8/xgeADbv9a2yiPWf40s7Cjbj/OrErWs1ck95N4JkhXW2MJNi l/j4V0wDgD2KQ7NL6nA45vHgs72lAsY7RPE+NSaX9e5wABjOI31yUdXgRfx6pD2Yej1m WBu+HBHia6O0gWewwlZNJSwPp4SfCAxSVELnAzOusc9PKfGX5ueuVWzc3WNYCAvENzA+ IVbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=J5AV37YM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l10si46520otr.159.2020.01.07.07.44.10; Tue, 07 Jan 2020 07:44:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=J5AV37YM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728395AbgAGPmx (ORCPT + 99 others); Tue, 7 Jan 2020 10:42:53 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38231 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727559AbgAGPmx (ORCPT ); Tue, 7 Jan 2020 10:42:53 -0500 Received: by mail-wr1-f65.google.com with SMTP id y17so54497234wrh.5 for ; Tue, 07 Jan 2020 07:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=e3JSrkA31lPQjM0qXrRZGQXu9t0TvJbA8jjtu6S4Kws=; b=J5AV37YMJnHJ3RXFwlcgkZbwnjesyNWZCGcGQ9HbGoN2/KGcUJWMYOHJ644L/6842G fvzBovUsbr46GGogb+jON8VfUPJWTsgksfQX3FM7MP1Z0QKoY+4D80AMiPLsLyT5D/+i ZuBWwdoFgmGgy3oleSv4YP/oJ2Un2Z0W9tkpU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=e3JSrkA31lPQjM0qXrRZGQXu9t0TvJbA8jjtu6S4Kws=; b=jIhv4eERN18FyXDtF97vf69ywPrqtpftiPjXHUJsnLDF6DKqp5UMRHG1dx7Q4p4SpM xhXOKVPCb3QJOzFFXziWpEyj4DwlbMwKGk0l9SePSmD11R2B2SgsQgmurPq8VmCpqwfy vYh/Zj4pxXc/WwLI/D/Ct4FnW/a9C9p6rEPkdEbvVcxEmjkf3vM1g6hReGI3lKhZEaWI im90E1Qry6X15qun4Y4lV02usMCmk2QmGVMYa781v3tKduyU5Qj2tQ2QSYOSSx1mRltr Ck4MaBiJ21cXd8lsMwckdVC2xFLHbyYukc8YzYH28emJYVKezLg5HlbpRvsr1yErHqYv amEA== X-Gm-Message-State: APjAAAX9cu/AG+V0sG7PT4FB86/UBrI6lPMjG6/CUd/OPn1BV3ThV4P9 5tyWOrHkZdQIrCZ1zLM43upD4A== X-Received: by 2002:a5d:558d:: with SMTP id i13mr110929908wrv.364.1578411771762; Tue, 07 Jan 2020 07:42:51 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:564b:0:7567:bb67:3d7f:f863]) by smtp.gmail.com with ESMTPSA id g199sm21778wmg.12.2020.01.07.07.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 07:42:50 -0800 (PST) Date: Tue, 7 Jan 2020 16:42:43 +0100 From: Daniel Vetter To: Pekka Paalanen Cc: Daniel Vetter , Gerd Hoffmann , dbueso@suse.de, "airlied@linux.ie" , "Chenfeng (puck)" , John Garry , Linuxarm , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "kongxinwei (A)" , Thomas Zimmermann , Ezequiel Garcia Subject: Re: SIGBUS on device disappearance (Re: Warnings in DRM code when removing/unbinding a driver) Message-ID: <20200107154243.GA43062@phenom.ffwll.local> Mail-Followup-To: Pekka Paalanen , Gerd Hoffmann , dbueso@suse.de, "airlied@linux.ie" , "Chenfeng (puck)" , John Garry , Linuxarm , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "kongxinwei (A)" , Thomas Zimmermann , Ezequiel Garcia References: <07899bd5-e9a5-cff0-395f-b4fb3f0f7f6c@huawei.com> <20191219113151.sytkoi3m7rrxzps2@sirius.home.kraxel.org> <20191223110015.0e04ea25@ferris.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191223110015.0e04ea25@ferris.localdomain> X-Operating-System: Linux phenom 5.3.0-3-amd64 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 23, 2019 at 11:00:15AM +0200, Pekka Paalanen wrote: > On Thu, 19 Dec 2019 13:42:33 +0100 > Daniel Vetter wrote: > > > On Thu, Dec 19, 2019 at 12:32 PM Gerd Hoffmann wrote: > > > > > > While being at it: How would a driver cleanup properly cleanup gem > > > objects created by userspace on hotunbind? Specifically a gem object > > > pinned to vram? > > > > Two things: > > - the mmap needs to be torn down and replaced by something which will > > sigbus. Probably should have that as a helper (plus vram fault code > > should use drm_dev_enter/exit to plug races). > > Hi, > > I assume SIGBUS is the traditional way to say "oops, the memory you > mmapped and tried to access no longer exists". Is there nothing > else for this? > > I'm asking, because SIGBUS is really hard to handle right in > userspace. It can be caused by any number of wildly different > reasons, yet being a signal means that a userspace process can only > have a single global handler for it. That makes it almost > impossible to use safely in libraries, because you would want to > register independent handlers from multiple libraries in the same > process. Some libraries may also be using threads. > > How to handle a SIGBUS completely depends on what triggered it. > Almost always userspace wants it to be a non-fatal error. A Wayland > compositor can hit SIGBUS on accessing wl_shm-based client buffers > (regular mmapped files), and then it just wants to continue with > garbage data as if nothing happened and possibly send a protocol > error to the client provoking it. For drm drivers that you actually want to hotunplug (as opposed to more just for driver development) they all use system memory/shmem, so shouldn't sigbus. I think at least, I haven't tested anything. This is for udl, or the tiny displays behind an spi bridge. For pci drivers where the mmap often points at a pci bridge the mmio range will be gone, so not SIGBUSing is going to be a tough order. Not impossible, but before we enshrine this into uapi someont will have to do some serious typing. > I would also imagine that Mesa, when it starts looking into > supporting GPU hotunplug, needs to handle vanished mmaps. I don't > think Mesa can ever install signal handlers, because that would > mess with the applications that may already be using SIGBUS for > handling disappearing mmapped files. It needs to start returning > errors via API calls. I cannot imagine a way to reliably prevent > such SIGBUS either by e.g. ensuring Mesa gets notified of removal > before it actually starts failing. Mesa already blows up in all kinds of interesting ways when it gets an EIO at execbuf. I think. Robust handling of gpu hotunplug for gl/vk contexts is going to be more work on top (and mmap is probably the least issue there, at least right now). > For now, I'm just looking for a simple "yes" or "no" here for the > something else. If it's "no" like I expect, creating something else > is probably in the order of years to get into a usable state. Does > anyone already have plans towards that? I agree with you that SIGBUS for mmap of hotunplugged devices is essentially unusable because sighandlers and all what you point out (would make it impossible to have robust vk/gl contexts, at least robuts against hotunplug). So in principle I'm open to have some other uapi for this, but it's going to be serios amounts of work across the stack. For display only udl-style devices otoh I think we should be mostly there, +/- driver bugs as usual. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch