From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Xu Subject: Re: [RFC][PATCHSET] VM_FAULT_RETRY fixes Date: Wed, 1 Feb 2023 14:48:22 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zotLaka2cZCI1cERJiVZftqrgNzLSMUEuw+YOkqwVYI=; b=SMkT/l/kkkSnQZ sID4B1ZbdarJJdYLuq7rJRrt5ZqvJ6UISUfk+3PqsUXXCOQO8hGwsiWlBLWtHkxXufzu23nzLCw5L A5hL4jlqCi3Mzp3Gdu2YWcwMssXlPiPPPm8gxwj0u6l9ce25zJ+/vyGWxOuZoeh5K3KOVKOquXTX+ 3kJ4YDDFFME0yymywZW65ddKheY4+V0k7UMgYsXsWkufxGsAmYK6lzXOR0a6zYSZo3+mX4keukCPJ NUVE+xIAHJbs1cpXDbdvUC/7W77RNdCb/3yAcZbLaPLf3KY2qSgwmtb+Rl3V8ldHr4oIXZKmUTprh gWd8geTAN5VUAxdFP3Tg==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675280907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+c79xB9zEm9gbVZK1/vCc0nmGWw5K68MnzSgOcRJD38=; b=JcRQbMHJYmeymltSUOs2n1NR6P8Hsh1ihvegc+xryf7yv9qmSoxhY/nFzVk0m/KR1ssE+h RGui/0Z+yN3ne3KCRWAegC4GBFXkMQ8/g4bseIolNYfO+JheLSLfbDi4zHwWfsQgKdOkUd siqFVch9zwjvuQBKKalMm8T0biUFMnE= In-Reply-To: Content-Disposition: inline List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+glpr-linux-riscv=m.gmane-mx.org@lists.infradead.org To: Linus Torvalds Cc: Al Viro , linux-arch@vger.kernel.org, linux-alpha@vger.kernel.org, linux-ia64@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-m68k@lists.linux-m68k.org, Michal Simek , Dinh Nguyen , openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, sparclinux@vger.kernel.org On Tue, Jan 31, 2023 at 04:00:22PM -0800, Linus Torvalds wrote: > So most of the time it's probably not going to matter all that much > which signal gets sent in practice. I do also see a common pattern of the possibility to have a generic fault handler like generic_page_fault(). It probably should start with taking the mmap_sem until providing some retval that is much easier to digest further by the arch-dependent code, so it can directly do something rather than parsing the bitmask in a duplicated way (hence the new retval should hopefully not a bitmask anymore but a "what to do"). Maybe it can be something like: /** * enum page_fault_retval - Higher level fault retval, generalized from * vm_fault_reason above that is only used by hardware page fault handlers. * It generalizes the bitmask-versioned retval into something that the arch * dependent code should react upon. * * @PF_RET_COMPLETED: The page fault is completed successfully * @PF_RET_BAD_AREA: The page fault address falls in a bad area * (e.g., vma not found, expand_stack() fails..) * @PF_RET_ACCESS_ERR: The page fault has access errors * (e.g., write fault on !VM_WRITE vmas) * @PF_RET_KERN_FIXUP: The page fault requires kernel fixups * (e.g., during copy_to_user() but fault failed?) * @PF_RET_HWPOISON: The page fault encountered poisoned pages * @PF_RET_SIGNAL: The page fault encountered poisoned pages * ... */ enum page_fault_retval { PF_RET_DONE = 0, PF_RET_BAD_AREA, PF_RET_ACCESS_ERR, PF_RET_KERN_FIXUP, PF_RET_HWPOISON, PF_RET_SIGNAL, ... }; As a start we may still want to return some more information (perhaps still the vm_fault_t alongside? Or another union that will provide different information based on different PF_RET_*). One major thing is I see how we handle VM_FAULT_HWPOISON and also the fact that we encode something more into the bitmask on page sizes (VM_FAULT_HINDEX_MASK). So the generic helper could, hopefully, hide the complexity of: - Taking and releasing of mmap lock - find_vma(), and also relevant checks on access or stack handling - handle_mm_fault() itself (of course...) - detect signals - handle page fault retries (so, in the new layer of retval there should have nothing telling it to retry; it should always be the ultimate result) - parse different errors into "what the arch code should do", and generalize the common ones, e.g. - OOM, do pagefault_out_of_memory() for user-mode - VM_FAULT_SIGSEGV, which should be able to merge into PF_RET_BAD_AREA? - ... It'll simplify things if we can unify some small details like whether the -EFAULT above should contain a sigbus. A trivial detail I found when I was looking at this is, x86_64 passes in different signals to kernelmode_fixup_or_oops() - in do_user_addr_fault() there're three call sites and each of them pass over a differerent signal. IIUC that will only make a difference if there's a nested page fault during the vsyscall emulation (but I may be wrong too because I'm new to this code), and I have no idea when it'll happen and whether that needs to be strictly followed. Thanks, -- Peter Xu