Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2069045pxb; Thu, 28 Oct 2021 15:37:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrIp8FBvij3nGYZ0DdokF39nrLxZ+LwriqVgIDDpdwzooz+c1a/D3/GT4HaqUB++jsZQNs X-Received: by 2002:a05:6402:26c5:: with SMTP id x5mr9822694edd.297.1635460652248; Thu, 28 Oct 2021 15:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635460652; cv=none; d=google.com; s=arc-20160816; b=ERMk6Of3GP7AthswRMUWn6LRthSASRd+TWXxTeuKQvwTknKskdH3YASQJPR50npS8K I3evbvY2E6LjdZwp/BeqJQtuf59Y1suUs6aFCTasOsPw5UA1kmQ73MjmoVO+3efG+7Sb svsNMuDdDlThCks/Ni2VDFp7kVIYRU1MSIlP+cCULS1G/XGdy8t9V9EMNMppjKGoEEng 02gDU8H37/FrfTEGPeeevXGY++YOpj3a+7Y0JXqfjLnyqXq4S18AKjo0RejQ2wd3KefU G94FzeAyYQe8wDRcb6iRzMMJDv9/7x08acc6rzTpgydVHMkuvmXHoZ+XD6nW4o+cx/y9 vIAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=P2oA0jP1wTViA9d0b6XSu2m2Y7tBKqkUPBuDKDK703M=; b=Zx5E+akv3VA5/oSxVmHvL3Osp0gkToW0QKhHZ/DmFkj9phaNab5fz2GR3A/HMzIF5i kn46CXLwFO0GT9E/ZlHmAimLV/jsL4xCS4cmlPqATEv+RwCjz9pZeh7ifHitMgzkMksw b2U9XCGRm+wWKhZXqnbmPPVnkPyWRI819XBmR0gab6YPIfNO2S292s63zcw4a4LQzucM 5A3m6uWQ+xzki489V0qw/xCBgWRAeZJw++MZ1+bGfJlxTmIF+lcIypB/6SzzAzkShZDi QDvyDgkcVo8N+hwheqohg6GEajP2Mf7LNh4Etw89iP3JEJImvFI06YHVttl0G/nJF54e uU/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=HzbuQnUz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o3si7764104ejy.753.2021.10.28.15.37.07; Thu, 28 Oct 2021 15:37:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=HzbuQnUz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231546AbhJ1Wf0 (ORCPT + 99 others); Thu, 28 Oct 2021 18:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbhJ1WfK (ORCPT ); Thu, 28 Oct 2021 18:35:10 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00D9EC0613B9 for ; Thu, 28 Oct 2021 15:32:43 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id y26so16661305lfa.11 for ; Thu, 28 Oct 2021 15:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P2oA0jP1wTViA9d0b6XSu2m2Y7tBKqkUPBuDKDK703M=; b=HzbuQnUzqbVH0zR+CZxMx/jYbjOwSKkqX9v1Ii3J+JA3hprq4SQBq/oq1XV2WHbboW GM6mCzsEY8CYnDKile42NhDWBAMmGmwAtNFEXySLaWKfRUD8V0FHk+7TYyOvdi/ZUvfX rOFaS1m2I/gKNLQEoFvUh9TDMESUKJVjJQ7lU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P2oA0jP1wTViA9d0b6XSu2m2Y7tBKqkUPBuDKDK703M=; b=XtDFia/NeUCTdvxDmDjadq2jcza5bACcTVKUy+Qwl19zQaNvGxzYCsK7jHaBSnrxAd TCsJuecHVJEy+iqlzrbOeWbtdYbLxww+UbLHgZA2LbiN/cCgElGO+z0+IlFWk6ULaDNi 8gLWv6PmAJOyB67sYTxKHXhmBa5aspT8kf9pwokV8f7mssfdHUVnAByOZ6iqARP+61mG CAbxAVT2H8Xes6fYYcjzva9DXfOdoEVHgsxvH/xtI5tb88e2+igPVebRz/zIp0FGdOyZ +f4HJilDNVHSdBoLr92XwJjTSnFIQVDmau3+wmcCWh5W8wHCXVX765cv11fyLN0WCRrt CyLQ== X-Gm-Message-State: AOAM533x50P5bGhsoGzMFq7jnLopDNTu1zQNrCvpuVaOCIfR/4Em7rPO rg0RIfHXc/kbNHXRZSvV3k6oOU/XhTfogg== X-Received: by 2002:a05:6512:15a9:: with SMTP id bp41mr7104806lfb.552.1635460361124; Thu, 28 Oct 2021 15:32:41 -0700 (PDT) Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com. [209.85.208.180]) by smtp.gmail.com with ESMTPSA id c9sm396479lfc.23.2021.10.28.15.32.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Oct 2021 15:32:40 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id e2so13233245ljg.13 for ; Thu, 28 Oct 2021 15:32:39 -0700 (PDT) X-Received: by 2002:a2e:89d4:: with SMTP id c20mr7772843ljk.191.1635460359642; Thu, 28 Oct 2021 15:32:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Torvalds Date: Thu, 28 Oct 2021 15:32:23 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v8 00/17] gfs2: Fix mmap + page fault deadlocks To: Catalin Marinas Cc: Andreas Gruenbacher , Paul Mackerras , Alexander Viro , Christoph Hellwig , "Darrick J. Wong" , Jan Kara , Matthew Wilcox , cluster-devel , linux-fsdevel , Linux Kernel Mailing List , ocfs2-devel@oss.oracle.com, kvm-ppc@vger.kernel.org, linux-btrfs Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 28, 2021 at 2:21 PM Catalin Marinas wrote: > > They do look fairly similar but we should have the information in the > fault handler to distinguish: not a page fault (pte permission or p*d > translation), in_task(), user address, fixup handler. But I agree the > logic looks fragile. So thinking about this a bit more, I think I have a possible suggestion for how to handle this.. The pointer color fault (or whatever some other architecture may do to generate sub-page faults) is not only not recoverable in the sense that we can't fix it up, it also ends up being a forced SIGSEGV (ie it can't be blocked - it has to either be caught or cause the process to be killed). And the thing is, I think we could just make the rule be that kernel code that has this kind of retry loop with fault_in_pages() would force an EFAULT on a pending SIGSEGV. IOW, the pending SIGSEGV could effectively be exactly that "thread flag". And that means that fault_in_xyz() wouldn't need to worry about this situation at all: the regular copy_from_user() (or whatever flavor it is - to/from/iter/whatever) would take the fault. And if it's a regular page fault,. it would act exactly like it does now, so no changes. If it's a sub-page fault, we'd just make the rule be that we send a SIGSEGV even if the instruction in question has a user exception fixup. Then we just need to add the logic somewhere that does "if active pending SIGSEGV, return -EFAULT". Of course, that logic might be in fault_in_xyz(), but it migth also be a separate function entirely. So this does effectively end up being a thread flag, but it's also slightly more than that - it's that a sub-page fault from kernel mode has semantics that a regular page fault does not. The whole "kernel access doesn't cause SIGSEGV, but returns -EFAULT instead" has always been an odd and somewhat wrong-headed thing. Of course it should cause a SIGSEGV, but that's not how Unix traditionall worked. We would just say "color faults always raise a signal, even if the color fault was triggered in a system call". (And I didn't check: I say "SIGSEGV" above, but maybe the pointer color faults are actually SIGBUS? Doesn't change the end result). Linus