Received: by 10.213.65.68 with SMTP id h4csp2416500imn; Mon, 2 Apr 2018 07:13:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx49BBmwgp6RWRTJr6d79aW4RS2uISxP3Ms6gxCNdHjsXCiarI3/O5gk38kK6voc6srW4KH/3 X-Received: by 10.167.128.71 with SMTP id y7mr7534980pfm.12.1522678381806; Mon, 02 Apr 2018 07:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522678381; cv=none; d=google.com; s=arc-20160816; b=DCW1xdx/yh/oPb/H6mv8pYZ+Go0WjqBpk7cgoZLPKT7HgmvmJpiyIYenZA5gFifbxX k59r9cNPWU8rzw3JmGTGiXJWuZ/Z4Uy7iVt4O3FG+6ZslhKmOCYh/LAc4o0M8ldOrNLr c3c5LOI27hkTRiFEdiRCpwI6a157IYW0j4LvLvsj3jhWVqDUqgibaZKWW0sO8CqryJoU OUBlCvEz6KDW03x4SesbEuh77EQ29HgbBgAsNz1HsHuAN0Dm1XAp2Ed9FpcNSka5LgQY IqQklvmIV82PkhR/mevoJyp7NOCLXKtR7V9xMma+F1ArThPJZ98O0CfvJFHbW55/9Bx5 XC0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=MQLiXGwUg+4M4542oVGo0cXZ0kmEWuDUufP1sO42ibw=; b=oB2oJIAbgukyixeY2877kkjqY1SdFi+gXiBi/Gv37ZZFKOj6v6lEpFAHouNpZjXmFt fjwMrlT6SAjJfz+DPd9k2L4uiNfocLMUtkNNtryfzirkp3Bn22GWZ3MyxOMp3LblSUw0 rEkYA6FOGgYFwkUATx8nXLNNmiB/cqabRUK5eHZqP4KmT6FYvlOlFwbOwI4LRmJVlzNp djag5GQOUILE7VO4OAUZspzgaw6nriDtbZDXVYLqkn4WmYmDolbiA3uOhpub01lS3qmd p78k0RJLof71DG/c9smEU0IBuEqUSjcPTxd6Ylqjn/WNO7KR+dcUTtp7hx1phHLJ6RLI iWgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=jKHdz+Aj; 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 n10-v6si378402plp.388.2018.04.02.07.12.46; Mon, 02 Apr 2018 07:13:01 -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=jKHdz+Aj; 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 S1751442AbeDBOLD (ORCPT + 99 others); Mon, 2 Apr 2018 10:11:03 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:52142 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750724AbeDBOLA (ORCPT ); Mon, 2 Apr 2018 10:11:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Type:MIME-Version: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=MQLiXGwUg+4M4542oVGo0cXZ0kmEWuDUufP1sO42ibw=; b=jKHdz+AjsBo80+sE9gROyF+G58 dEFjxk4hbtj4q5rAB0TE5QQFqCEBdBpVE22F+qLfkvZHV/ldE3NzxGl13onYx5qRA7hlSFbs8qPOg UoKIRlwzrWYHp1RT7IStJ6G1Re1mmpQxoybIZOAYbka9WHE+rp/DZaMY4fSNbjliF21vm4M7ll3p0 g1/i8kcCtPtxFKbI0pJ7cX+wr5k2HQkhfLIPdL+aQ20hd01HUVFdYRx4YaQc1rPmv2tUivE5Uihdu sXkvyGzGeCktVz+Rmhyp9p2Qj5HMCKXuLsxV6O83NjwhAorLwPCCwE4VrCv3lvQsR5i0Z3nnp+cJH 22o5TM6g==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f30Ak-0006HQ-Hu; Mon, 02 Apr 2018 14:10:58 +0000 Date: Mon, 2 Apr 2018 07:10:58 -0700 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Souptick Joarder Cc: linux-kernel@vger.kernel.org Subject: Signal handling in a page fault handler Message-ID: <20180402141058.GL13332@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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 don't think the graphics drivers really want to be interrupted by any signal. I think they want to be interruptible by fatal signals and should use the mutex_lock_killable / fatal_signal_pending family of functions. That's going to be a bit of churn, funnelling TASK_KILLABLE / TASK_INTERRUPTIBLE all the way down into the dma-fence code. Before anyone gets started on that, I want to be sure that my analysis is correct, and the drivers are doing the wrong thing by using interruptible waits in a page fault handler.