Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4334910rwo; Tue, 25 Jul 2023 04:44:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlES2avCrlfu1w8DFXZncvuZcglNTRosj8g3bzslxY4vmj4utHbB810AFnnAZKnmQ0FIF2Re X-Received: by 2002:a05:6a00:1684:b0:64f:7a9c:cb15 with SMTP id k4-20020a056a00168400b0064f7a9ccb15mr9751719pfc.11.1690285450142; Tue, 25 Jul 2023 04:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690285450; cv=none; d=google.com; s=arc-20160816; b=pew4KjbW2HjIIdDCE+pZmeNxna7Y+sJq00BtQhFyrxVHmsMnulWMrWCgxT8Trt5MXX xh+9/O6BbO7jJWAJFQYPByLR59CMiGxd8+5xc/v5mR+szA4ihElTNHIfceuvwi0AULWe w/MYnzwrmn2rdGM4SD/FOz2Ea5+wQq5S94J0PDwvTRhYgZzEoXiFtQR6JELQUzI+yNaC USZJZX9hinBGatU12EfVmW01p40N8sr28fsA9NLkQ3huLEdzo1Hzwm0aKSjk7PBB81E6 7Py1LNExoq9h0rw9UEyJGiLwq4tgzzxgSL9MJwP9yRxH743aemeweS/+RAb5bY4o+lkO hihg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:cc:to:from :content-language:user-agent:mime-version:date:message-id; bh=NPuRthGWakbS6/h4t5EM8I8PmcQRIlx/Kgwpx80RfQI=; fh=m7U+Fwz3MoT40xJWNifpjII9AwUevocA33ENoetHMCQ=; b=V1su0V0y3al1jLRQOfz/WH4xZ0C/N+pUVxv/7GXmb+z+KrnmI039+gdEy5StKGr5Cz xfB5Q09IAAhJZCnoHUViMWGOKDqO94RE7M9JqD3aMx9zKmKPUAPoNbbDnf0IEAprh7CX agZP+GRwpWawnmX8SKUORadmy8ldpmYs0lX8yhAsmVT6BJ8Po4ucVWHoObjpKcnU+TRC dpNnXrQ4ko93FyUwHKBZ6M5YBoWzhynScylkoWFpkC0apFqdVrq5/3u1gIC34T0w913R nQX5XL8ZL7k/778FtCQqcNWlN1YpoWN47Ja+W+hFa5SKLGdwVrK6Lh+V2op/jsHphaRx deig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 130-20020a630088000000b0054201a3f08dsi11345939pga.592.2023.07.25.04.43.57; Tue, 25 Jul 2023 04:44:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234569AbjGYLZN (ORCPT + 99 others); Tue, 25 Jul 2023 07:25:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234564AbjGYLZN (ORCPT ); Tue, 25 Jul 2023 07:25:13 -0400 X-Greylist: delayed 516 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 25 Jul 2023 04:25:11 PDT Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 745869D for ; Tue, 25 Jul 2023 04:25:11 -0700 (PDT) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 183F143CB5; Tue, 25 Jul 2023 13:16:33 +0200 (CEST) Message-ID: <8d063a26-43f5-0bb7-3203-c6a04dc159f8@proxmox.com> Date: Tue, 25 Jul 2023 13:16:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US From: Fiona Ebner To: torvalds@linux-foundation.org, akpm@linux-foundation.org Cc: Thomas Lamprecht , Wolfgang Bumiller , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: segfaults of processes while being killed after commit "mm: make the page fault mmap locking killable" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, we are seeing segfaults from processes while being killed starting with kernels which include commit eda0047296a16d65a7f2bc60a408f70d178b2014 ("mm: make the page fault mmap locking killable") all the way up to v6.5-rc3 which is the kernel I based this report on. I don't have a simple reproducer unfortunately, the one I have is big and quite racy. My working theory for what happens is (see also the bpftrace script and output [0]): Since get_mmap_lock_carefully() now uses mmap_read_lock_killable(), if rwsem_down_write_slowpath() is taken and there is a fatal signal pending, rwsem_down_write_slowpath() will return -EINTR and this is propagated up until get_mmap_lock_carefully() will return its boolean negation with !mmap_read_lock_killable(mm), i.e. 0. Then lock_mm_and_find_vma() returns NULL > if (!get_mmap_lock_carefully(mm, regs)) > return NULL; and so do_user_addr_fault() > vma = lock_mm_and_find_vma(mm, address, regs); > if (unlikely(!vma)) { > bad_area_nosemaphore(regs, error_code, address); > return; > } will end up without a vma and cause/log the segfault. Of course the process is already being killed, but I'd argue it is very confusing to users when apparent segfaults from such processes are being logged by the kernel. Happy to provide other traces or information if required! Best Regards, Fiona [0]: I ended up with the following bpftrace script > #include > #include > > kprobe:down_read_killable { > printf("%s %d %d\n", func, pid, tid); > } > > kprobe:rwsem_down_read_slowpath { > printf("%s %d %d\n", func, pid, tid); > } > > kretprobe:rwsem_down_read_slowpath { > printf("%s %d %d retval 0x%x\n", func, pid, tid, retval); > printf("%s\n", kstack()); > } > > kprobe:bad_area_nosemaphore { > printf("%s %d %d %s pending signal: %d\n", func, pid, tid, comm, > curtask->pending.signal.sig[0] > ); > if (curtask->pending.signal.sig[0]) { > printf("%s\n", kstack()); > } > } and here is a capture of a process running into the segfault. AFAIU, the pending signal translates to SIGKILL and the return value from down_read_killable() is -EINTR. > down_read_killable 987299 987299 > rwsem_down_read_slowpath 987299 987299 > down_read_killable 987299 987299 retval 0xfffffffc > > down_read_killable+72 > lock_mm_and_find_vma+167 > do_user_addr_fault+477 > exc_page_fault+131 > asm_exc_page_fault+39 > > bad_area_nosemaphore 987299 987299 pverados pending signal: 256 > > bad_area_nosemaphore+1 > exc_page_fault+131 > asm_exc_page_fault+39 > > bad_area_nosemaphore 987299 987299 pverados pending signal: 256 > > bad_area_nosemaphore+1 > exc_page_fault+131 > asm_exc_page_fault+39 > rep_movs_alternative+96 > show_opcodes+118 > __bad_area_nosemaphore+640 > bad_area_nosemaphore+22 > do_user_addr_fault+708 > exc_page_fault+131 > asm_exc_page_fault+39 > > bad_area_nosemaphore 987299 987299 pverados pending signal: 256 > > bad_area_nosemaphore+1 > exc_page_fault+131 > asm_exc_page_fault+39 > rep_movs_alternative+15 > show_opcodes+118 > __bad_area_nosemaphore+640 > bad_area_nosemaphore+22 > do_user_addr_fault+708 > exc_page_fault+131 > asm_exc_page_fault+39 >