From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2FEBC433EF for ; Thu, 21 Apr 2022 16:26:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D4A16B0078; Thu, 21 Apr 2022 12:26:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55C586B007B; Thu, 21 Apr 2022 12:26:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AED16B007D; Thu, 21 Apr 2022 12:26:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 261D16B0078 for ; Thu, 21 Apr 2022 12:26:03 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E5A3F27825 for ; Thu, 21 Apr 2022 16:26:02 +0000 (UTC) X-FDA: 79381412964.31.B1C07D1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 849DB40027 for ; Thu, 21 Apr 2022 16:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650558361; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YzLMHYGlgJV6x+Dcp/1+CizAxcwBiXBL5GAr+2klJbY=; b=hHLqFigHP37DE4+KbAcI9vDLLIKHZEhm/H6m0HdSYjzI+S+Rn3uYk7JOqyf9vxV5MXroKX Om2Ui2aUYNueXDJIJy8FcUbHGMEMY11Im49DZbn6jPX3elNICA+3PuVFQF4R2NneL74ZDd eg7uqKKcBY+VVCh4ilqOZfhavAAs1kA= Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-53-xqiJHv6TN9yvSWReCYyQMA-1; Thu, 21 Apr 2022 12:26:00 -0400 X-MC-Unique: xqiJHv6TN9yvSWReCYyQMA-1 Received: by mail-ua1-f69.google.com with SMTP id a22-20020ab06316000000b00350e4845386so2088896uap.3 for ; Thu, 21 Apr 2022 09:26:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=YzLMHYGlgJV6x+Dcp/1+CizAxcwBiXBL5GAr+2klJbY=; b=f5mF/XfvRkNpmex8QAXV8wmtPyNiIVBzcrojNQuIZa5Q3HTxGAjrJJH9qsY2sD57Vb 1nxtS2YbHWyA+/4fA35SiDZuZwDDpAMtigN5rhS8PItewoPqTg9wAXzcIZKFLi87+jxZ 6WLh/TJvqAjcKlFnWUNQVrH2PC7oyu/mTuo6+lv5AMR8vyYnj5jy47y5OwecWjcafmMw 7kbRn+gOC5064pf2HhcpGGEc174lLIUsf2QiZV0cS/3IEvznlwgHvLyBduS8SAz1b6mC Bxpw9/Eaj8iSG2laNIg0YhXtE7QBeuzcgw1VRtmcKWDWeUd665H24j6Hz3CERIcEHBzo r95A== X-Gm-Message-State: AOAM533biParSfZV6mSfHkSKk2SLU3CJz4ysUi3ILAY+MdIQ3RSCeyNa 93Q6xoivny8bRtlhXPWhLmTTX0hho5Fx2RCcj+FVZpCdf9vhfSVT6hLoAtHpQrR7zgTUn0OTMlW 74BNRjPHUaZI= X-Received: by 2002:a05:6102:a8e:b0:325:aa27:35a7 with SMTP id n14-20020a0561020a8e00b00325aa2735a7mr162589vsg.50.1650558359894; Thu, 21 Apr 2022 09:25:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7HGoMlorFMIObliYFXOddYMZmP70gzc5sATCpn4GK7fzm1tWeggKSpCdKocttoO72C1q7wQ== X-Received: by 2002:a05:6102:a8e:b0:325:aa27:35a7 with SMTP id n14-20020a0561020a8e00b00325aa2735a7mr162579vsg.50.1650558359671; Thu, 21 Apr 2022 09:25:59 -0700 (PDT) Received: from [192.168.169.241] ([216.239.164.83]) by smtp.gmail.com with ESMTPSA id m6-20020a0561023e8600b0031bb1803345sm757470vsv.6.2022.04.21.09.25.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Apr 2022 09:25:59 -0700 (PDT) Message-ID: <5653e751-f81d-f64e-b4b5-b251949d13d9@redhat.com> Date: Thu, 21 Apr 2022 12:25:58 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v9] oom_kill.c: futex: Delay the OOM reaper to allow time for proper futex cleanup To: Thomas Gleixner , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Rafael Aquini , Waiman Long , "Herton R . Krzesinski" , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , David Rientjes , Michal Hocko , Andrea Arcangeli , Davidlohr Bueso , Peter Zijlstra , Ingo Molnar , Joel Savitz , Darren Hart , stable@kernel.org References: <20220414144042.677008-1-npache@redhat.com> <874k2mts8p.ffs@tglx> From: Nico Pache In-Reply-To: <874k2mts8p.ffs@tglx> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hHLqFigH; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf04.hostedemail.com: domain of npache@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=npache@redhat.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 849DB40027 X-Stat-Signature: 41hpaetmn3odqnsxwupnd886sxtj574n X-HE-Tag: 1650558360-297710 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 4/21/22 10:40, Thomas Gleixner wrote: > On Thu, Apr 14 2022 at 10:40, Nico Pache wrote: >> The pthread struct is allocated on PRIVATE|ANONYMOUS memory [1] which can >> be targeted by the oom reaper. This mapping is used to store the futex >> robust list head; the kernel does not keep a copy of the robust list and >> instead references a userspace address to maintain the robustness during >> a process death. A race can occur between exit_mm and the oom reaper that >> allows the oom reaper to free the memory of the futex robust list before >> the exit path has handled the futex death: >> >> CPU1 CPU2 >> ------------------------------------------------------------------------ >> page_fault >> do_exit "signal" >> wake_oom_reaper >> oom_reaper >> oom_reap_task_mm (invalidates mm) >> exit_mm >> exit_mm_release >> futex_exit_release >> futex_cleanup >> exit_robust_list >> get_user (EFAULT- can't access memory) >> >> If the get_user EFAULT's, the kernel will be unable to recover the >> waiters on the robust_list, leaving userspace mutexes hung indefinitely. >> >> Delay the OOM reaper, allowing more time for the exit path to perform >> the futex cleanup. >> >> Reproducer: https://gitlab.com/jsavitz/oom_futex_reproducer >> >> [1] https://elixir.bootlin.com/glibc/latest/source/nptl/allocatestack.c#L370 > > A link to the original discussion about this would be more useful than a > code reference which is stale tomorrow. The above explanation is good > enough to describe the problem. Hi Andrew, can you please update the link when you add the ACKs. Here is a more stable link: [1] https://elixir.bootlin.com/glibc/glibc-2.35/source/nptl/allocatestack.c#L370 > >> >> +/* >> + * Give the OOM victim time to exit naturally before invoking the oom_reaping. >> + * The timers timeout is arbitrary... the longer it is, the longer the worst >> + * case scenario for the OOM can take. If it is too small, the oom_reaper can >> + * get in the way and release resources needed by the process exit path. >> + * e.g. The futex robust list can sit in Anon|Private memory that gets reaped >> + * before the exit path is able to wake the futex waiters. >> + */ >> +#define OOM_REAPER_DELAY (2*HZ) >> +static void queue_oom_reaper(struct task_struct *tsk) > > Bah. Did you run out of newlines? Glueing that define between the > comment and the function is unreadable. My Enter key hit its cgroup limit for newlines. Andrew, would it be possible to also add a new line when you make the other changes. Sorry about that. > > Other than that. > > Acked-by: Thomas Gleixner Thanks!