Received: by 10.213.65.68 with SMTP id h4csp812108imn; Wed, 4 Apr 2018 07:41:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx48jOV9Dd+ElL4ubQnPYfR8INBJfyOpmf0ZUpAhxxfrXcQtNxu1ARpu87c0FeaMzCwHeR3vT X-Received: by 10.101.83.198 with SMTP id z6mr8247525pgr.105.1522852895372; Wed, 04 Apr 2018 07:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522852895; cv=none; d=google.com; s=arc-20160816; b=urT4E6SkeGMnOfaVNKVR3O4VGKuBL6EcxXqc8vDNduC82LezZftxaPg/ANAhtJcWbr SDDELwahD70an0bBMWcQqp7k5Ch47wX4c13aAEXg2GJhl9gcQx0PD/+yElXeVkSz3sBO 641iE1rFXx/7GrfPRQ2DweCNgylDNKGiERrnByZ1UkUVUhq4Bw0tU9rMDlgclENZLdm+ A9NV4s+alyVZPsnX9oTfqZ7L4JQQV95HxXqfhYHTbWrCpnAirq+Nb/7hVbRvO+sSrNK7 vzubtOCsnSxa3faFCvBuOxh2iX0Nk6QxjsVTFw6dRFEwdiJ1EtqV7QJ/nmEmLm00Hbjo /Ekg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :from:date:dkim-signature:arc-authentication-results; bh=GwV/LERVOKMGuqQ+LyjPWuC+nv1AlTRA7y8g51e/0Vw=; b=ptDp3+tgTtKNaNZwPqHkwmavdB6AwOeMZe8mdCPGXuxT3WHNpUfNU5QEpubZqGMMjo mpqCYe45pCF5AVlYFYmdRPt52JL1ydfINo6zVElcgKzULedu1bZ4TT9fyrtjZgGmMTil 6o+kwOkNPsdzhNkCmhpj6kKgtYeC356ESEk5vs9MNrSQPRRxsqzeQy4oHADl5U5433Jp wdCZRue0ahxI9t4MUz8jXVk19qFbliQHAJvPyG4IrOdtszkIRwFNUVmx3JPriWTNaN9q 7Gyy5nV0gGlpKOiruflpStYs+VZPhvxmmHbPs2b19YP+OiLr57T+wNMpA4gb4hKyA8mH ugXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hUPc0Ci3; 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 x7-v6si1921901pln.266.2018.04.04.07.41.21; Wed, 04 Apr 2018 07:41:35 -0700 (PDT) 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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hUPc0Ci3; 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 S1751418AbeDDOjC (ORCPT + 99 others); Wed, 4 Apr 2018 10:39:02 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:58716 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751255AbeDDOjB (ORCPT ); Wed, 4 Apr 2018 10:39:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:To:From:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GwV/LERVOKMGuqQ+LyjPWuC+nv1AlTRA7y8g51e/0Vw=; b=hUPc0Ci37hkC95PX5c7c17VeE vUN4u0oE10Y0k0Bk7orhTO3lWUbe2ipGu53D7cBlRix2uG50dg/hIQh1V1xU/DicY4FW+JfwxjIic DXRv1XBi6Q2AxWtcHt4TjwuJK44FHFdTIla03LVaLg8mts1x7Ld7dssq6a9KVTGWwPmHOfXknhQmH Ujb7QOz6qUNcLvlj6TsvpyLvaX6bjUGl7Q3T2reGiWhHa1Hhiv/RY/EFWOASk/ST4XuQZ593JgtSX qkj6MYKD5AlBmHIer3Qd99dj70tiyvkmiOv9nHhZFWODu0gnGclk55TGXVZ30ylVnfpbtR6kvJTGT aJztbTGTQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3jYy-0001G7-Uu; Wed, 04 Apr 2018 14:39:00 +0000 Date: Wed, 4 Apr 2018 07:39:00 -0700 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Souptick Joarder , linux-kernel@vger.kernel.org Subject: Re: Signal handling in a page fault handler Message-ID: <20180404143900.GA1777@bombadil.infradead.org> References: <20180402141058.GL13332@bombadil.infradead.org> <20180404093254.GC3881@phenom.ffwll.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180404093254.GC3881@phenom.ffwll.local> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 04, 2018 at 11:32:54AM +0200, Daniel Vetter wrote: > So we've done some experiments for the case where the fault originated > from kernel context (copy_to|from_user and friends). The fixup code seems > to retry the copy once after the fault (in copy_user_handle_tail), if that > fails again we get a short read/write. This might result in an -EFAULT, > short read()/write() or anything else really, depending upon the syscall > api. > > Except in some code paths in gpu drivers where we convert anything into > -ERESTARTSYS/EINTR if there's a signal pending it won't ever result in the > syscall getting restarted (well except maybe short read/writes if > userspace bothers with that). > > So I guess gpu fault handlers indeed break the kernel's expectations, but > then I think we're getting away with that because the inner workings of > gpu memory objects is all heavily abstracted away by opengl/vulkan and > friends. > > I guess what we could do is try to only do killable sleeps if it's a > kernel fault, but that means wiring a flag through all the callchains. Not > pretty. Except when there's a magic set of functions that would convert > all interruptible sleeps to killable ones only for us. I actually have plans to allow mutex_lock_{interruptible,killable} to return -EWOULDBLOCK if a flag is set. So this doesn't seem entirely unrelated. Something like this perhaps: struct task_struct { + unsigned int sleep_state; }; static noinline int __sched -__mutex_lock_interruptible_slowpath(struct mutex *lock) +__mutex_lock_slowpath(struct mutex *lock, long state) { - return __mutex_lock(lock, TASK_INTERRUPTIBLE, 0, NULL, _RET_IP_); + if (state == TASK_NOBLOCK) + return -EWOULDBLOCK; + return __mutex_lock(lock, state, 0, NULL, _RET_IP_); } +int __sched mutex_lock_state(struct mutex *lock, long state) +{ + might_sleep(); + + if (__mutex_trylock_fast(lock)) + return 0; + + return __mutex_lock_slowpath(lock, state); +} +EXPORT_SYMBOL(mutex_lock_state); Then the page fault handler can do something like: old_state = current->sleep_state; current->sleep_state = TASK_INTERRUPTIBLE; ... current->sleep_state = old_state; This has the page-fault-in-a-signal-handler problem. I don't know if there's a way to determine if we're already in a signal handler and use a different sleep_state ...?