Received: by 10.213.65.68 with SMTP id h4csp3504163imn; Tue, 3 Apr 2018 06:12:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+HbeHyi5L6ueGN0ovrDPA0DXbN/wh0uJHhqaF+PIN852KT2wKmoR8zYEjyWieYV9c+UgFM X-Received: by 10.98.242.6 with SMTP id m6mr10454675pfh.170.1522761122433; Tue, 03 Apr 2018 06:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522761122; cv=none; d=google.com; s=arc-20160816; b=Z43CoH1yW5ZFKSv7B2zddyft3mJtVrpElqKxdAO3gdjECrVWpnK0Uau921r8Qfq9js 8Hjg63vW7iELl93iB04OPHhYMsuTvzNZtyv6R5OHz797GwPbdq7l256UskUYvbPSV6oL /BauVXtRda8pOKIEcAhdLVDkG6cH34O3GOk0w1TGPIp2LPx/jTxi5CEDyLc/lp6qSpio H7JF/0MER6Dp7vRKRxyw2u/JHeY5gZpHGPSsxJgiEHe3AxPbDu6Y+tnnU71hwbnroqTE Fd4OHu+bcjd+LSo0esLPd/9UP60b1qq0l09wKwL71wjhBdcCf1yiKtf49xpd4Wnvp96N B16w== 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:cc :to:from:date:dkim-signature:arc-authentication-results; bh=pZ1VYUF9Kzg3swgnsuymeGHXg3KFD9uQyft+vpmBu1M=; b=YqgvEi+xvaLU9sCDGX+CLAA1Na0ljWnWRebVmIYu8r1/nTTMyXH+WEIGngyEBSvQmY jxpX6UZMhz+78lrg5N82na+GB/o+T1hihBOS6JzI0/MDNb5bz0RIo6FHqSTS//YQOVn5 J87nvgsywKNDHyei0UdrNfvMcgCfjm9zSPREtKAgX1DQWs9lebYw2BAmuS8Kd/L+1Bui CYs3Yk7d6hvRUUtaREApSpTGLZbLTYnNDt1PjStEvAbk5Ae/4fdlUDxzc8NY4l8530N3 e+uHT+3msWaoRQIYNRa6DXPLTER+1T45Q42xl+iLdNqIPubQvket6wwY6bOjBuLdHK9p io9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=OBmN5bh2; 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 v205si1984160pgb.774.2018.04.03.06.11.46; Tue, 03 Apr 2018 06:12:02 -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=OBmN5bh2; 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 S932270AbeDCNKa (ORCPT + 99 others); Tue, 3 Apr 2018 09:10:30 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:58350 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932204AbeDCNK2 (ORCPT ); Tue, 3 Apr 2018 09:10:28 -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:Cc:To:From:Date:Sender:Reply-To: 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=pZ1VYUF9Kzg3swgnsuymeGHXg3KFD9uQyft+vpmBu1M=; b=OBmN5bh2U2PbIYWwC6SCcOmqn M1tb0PnRL8vrTVtsKQMc2PlPUb3H6jXVxIcTxvq6chNBv0A/pf/0lRQFriANkOqD5ALD0cKuerPh/ 1PcP7XODfAiWWNigRgFZIx3vpDn3kQROf8Iv9Q1OUzyhFmbMrWXOtwtL25o3FL9OaLggWj+zsX7f9 UZjAkHmdHNFbtG6mWUKvQlOV+FKpNmfRwjlfpXOYQ+96yKfZUUxxBzrM2xgzlpC8d7wVAdeh9ESR3 OYlJsy2BFTg5FU7g3b55HBzCUFXQAE65ycn/FK1iM8f+Mn7t8VPPZFSkpSbGHi8Fkp5KHT6keZvM8 yQeDO3VlA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3Lhh-00063E-Ub; Tue, 03 Apr 2018 13:10:25 +0000 Date: Tue, 3 Apr 2018 06:10:25 -0700 From: Matthew Wilcox To: Chris Wilson Cc: 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: <20180403131025.GF5832@bombadil.infradead.org> References: <20180402141058.GL13332@bombadil.infradead.org> <152275879566.32747.9293394837417347482@mail.alporthouse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152275879566.32747.9293394837417347482@mail.alporthouse.com> 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 Tue, Apr 03, 2018 at 01:33:15PM +0100, Chris Wilson wrote: > Quoting Matthew Wilcox (2018-04-02 15:10:58) > > Souptick and I have been auditing the various page fault handler routines > > and we've noticed that graphics drivers assume that a signal should be > > able to interrupt a page fault. In contrast, the page cache takes great > > care to allow only fatal signals to interrupt a page fault. > > > > I believe (but have not verified) that a non-fatal signal being delivered > > to a task which is in the middle of a page fault may well end up in an > > infinite loop, attempting to handle the page fault and failing forever. > > > > Here's one of the simpler ones: > > > > ret = mutex_lock_interruptible(&etnaviv_obj->lock); > > if (ret) > > return VM_FAULT_NOPAGE; > > > > (many other drivers do essentially the same thing including i915) > > > > On seeing NOPAGE, the fault handler believes the PTE is in the page > > table, so does nothing before it returns to arch code at which point > > I get lost in the magic assembler macros. I believe it will end up > > returning to userspace if the signal is non-fatal, at which point it'll > > go right back into the page fault handler, and mutex_lock_interruptible() > > will immediately fail. So we've converted a sleeping lock into the most > > expensive spinlock. > > I'll ask the obvious question: why isn't the signal handled on return to > userspace? As I said, I don't know exactly how it works due to getting lost in the assembler parts of kernel entry/exit. But if it did work, then wouldn't the page cache use it, rather than taking such great pains to only handle fatal signals? See commit 37b23e0525d393d48a7d59f870b3bc061a30ccdb which introduced it. One thing I did come up with is: What if the signal handler is the one touching the page that needs to be faulted in? And for the page cache case, what if the page that needs to be faulted in is the page containing the text of the signal handler? (I don't think we support mapping graphics memory PROT_EXEC ;-) > > I don't think the graphics drivers really want to be interrupted by > > any signal. > > Assume the worst case and we may block for 10s. Even a 10ms delay may be > unacceptable to some signal handlers (one presumes). For the number one > ^C usecase, yes that may be reduced to only bother if it's killable, but > I wonder if there are not timing loops (e.g. sigitimer in Xorg < 1.19) > that want to be able to interrupt random blockages. Ah, setitimer / SIGALRM. So what do we want to have happen if that signal handler touches the mmaped device memory?