From patchwork Fri Oct 16 23:09:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 11842447 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A83115E6 for ; Fri, 16 Oct 2020 23:09:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C785A2222B for ; Fri, 16 Oct 2020 23:09:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rClZn7/P" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C785A2222B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AB1026B0070; Fri, 16 Oct 2020 19:09:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A87D66B0071; Fri, 16 Oct 2020 19:09:45 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A4866B0072; Fri, 16 Oct 2020 19:09:45 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0064.hostedemail.com [216.40.44.64]) by kanga.kvack.org (Postfix) with ESMTP id 625486B0070 for ; Fri, 16 Oct 2020 19:09:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E95788249980 for ; Fri, 16 Oct 2020 23:09:44 +0000 (UTC) X-FDA: 77379332688.12.hook04_600acc227220 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id CB8E01801A106 for ; Fri, 16 Oct 2020 23:09:44 +0000 (UTC) X-Spam-Summary: 1,0,0,36d2baceac04a3b9,d41d8cd98f00b204,jannh@google.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1513:1515:1521:1534:1541:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2559:2562:2693:2903:3138:3139:3140:3141:3142:3152:3352:3865:3867:3868:3871:3872:3874:4250:4321:4385:5007:6119:6120:6261:6653:7903:8660:9969:10004:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12895:12986:13069:13148:13161:13229:13230:13255:13311:13357:14096:14181:14384:14721:21080:21433:21444:21627:21939:30054,0,RBL:209.85.221.68:@google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfkabon747hpdm8syxz5ucfhgfrocou11nhwurz5psuipoopz7k9q673ucu6o.uu7o4914mzne3xhpgjqk17bt1qoizqybxwyedqa1ojczskj4bjjczrprxu9bbxg.c-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: hook04_600acc227220 X-Filterd-Recvd-Size: 4671 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Fri, 16 Oct 2020 23:09:44 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id y12so4875466wrp.6 for ; Fri, 16 Oct 2020 16:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J4AQ8wqNpjVt1ykz0FMlQ/Hn0cAH4pxEjRmJmEVEXzM=; b=rClZn7/P2brEcbJ17hk3v5Ov20ONpnJc3N7mscK6TVtzEI4C2dZVcNCjb2UbK3GcrH KOrmC+GfSAgf5CBO5WNij6aH3a293buv1EwV41bQyMSXwzh3MJn0iVkBEv+G7SWWNczj vtzPCkqVAbbr0bjfD35ZzQpr1Lgn5CWWWEo3YXHFLlZ8tkf99ubo03jvazvBLhHOC1xP 8gQ+Xx3eR9NO0/YTyQOT7IdV6mTksrXqZTCaWg2l4hqnPa7E/QS3IEX9eLUnc7yluLWQ xj88YsUnFOCQpCiwuPuGMsh2AevEdExmakr+DPQ/A9NSXLpx5p+Kxfi/o7cfTQtApJEc NN4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J4AQ8wqNpjVt1ykz0FMlQ/Hn0cAH4pxEjRmJmEVEXzM=; b=jLSpeeLxvqnD7abj+8Dpohda7QcSbUYVwvzCyNkVUqEcpn8JXO14dfDZ2SIxpgParL B40ou3VE/JJp3p9BMTUyM2vPDrJqNPmQs8xS4cAMxKI0LlvHr1cYia52VKj9lF8E5RPN +apquSyjskZP8H4EbsW71DEdRck5QNELHnvN5agF2FKl/BwpyiT8Ff5ZdL5RYd8jR0oI hn3fVOaqsfGJoyBnusbgbr3knJEyO+Jw+mG3PTtBej2+pe/NeJxjtG5Uo918mxOlv72y srum12NP+mQBuSpoYpiklOWzUrPH1hW/CIEFOlnOSh63wt2smRndHevmzfP2TJ5m4lR0 AYUQ== X-Gm-Message-State: AOAM530be5K5SuQINUGLEsUgEaEwcPrYSW09N254um2sS7fgb7fly9br SfrdFspDo1VxLSozXddwqpLQGA== X-Google-Smtp-Source: ABdhPJzEacUrzZyN0193KfsbDyP+Nq2E/fuEoba3R3HJmfpoAO6isYjIW2vwr6uW3TdeSSNG7cYQgg== X-Received: by 2002:adf:e6c4:: with SMTP id y4mr6904873wrm.423.1602889783182; Fri, 16 Oct 2020 16:09:43 -0700 (PDT) Received: from localhost ([2a02:168:96c5:1:55ed:514f:6ad7:5bcc]) by smtp.gmail.com with ESMTPSA id q6sm4718202wma.0.2020.10.16.16.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2020 16:09:42 -0700 (PDT) From: Jann Horn To: Andrew Morton , linux-mm@kvack.org, Eric Biederman , Oleg Nesterov Cc: linux-kernel@vger.kernel.org, Will Deacon , Kees Cook , Ingo Molnar Subject: [RFC PATCH resend 4/6] mm, oom: Use mm_ref()/mm_unref() and avoid mmdrop_async() Date: Sat, 17 Oct 2020 01:09:13 +0200 Message-Id: <20201016230915.1972840-5-jannh@google.com> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201016230915.1972840-1-jannh@google.com> References: <20201016230915.1972840-1-jannh@google.com> MIME-Version: 1.0 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: The OOM killer uses MMF_OOM_SKIP to avoid running on an mm that has started __mmput(); it only uses the mmgrab() reference to ensure that the mm_struct itself stays alive. This means that we don't need a full mmgrab() reference, which will keep the pgd (and potentially also some pmd pages) alive and can't be cleaned up from RCU callback context; we can use an mm_ref() reference instead. Signed-off-by: Jann Horn --- kernel/fork.c | 6 +----- mm/oom_kill.c | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index fcdd1ace79e4..59c119b03351 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -686,12 +686,8 @@ static inline void free_signal_struct(struct signal_struct *sig) { taskstats_tgid_free(sig); sched_autogroup_exit(sig); - /* - * __mmdrop is not safe to call from softirq context on x86 due to - * pgd_dtor so postpone it to the async context - */ if (sig->oom_mm) - mmdrop_async(sig->oom_mm); + mm_unref(sig->oom_mm); kmem_cache_free(signal_cachep, sig); } diff --git a/mm/oom_kill.c b/mm/oom_kill.c index e90f25d6385d..12967f54fbcf 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -704,7 +704,7 @@ static void mark_oom_victim(struct task_struct *tsk) /* oom_mm is bound to the signal struct life time. */ if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) { - mmgrab(tsk->signal->oom_mm); + mm_ref(tsk->signal->oom_mm); set_bit(MMF_OOM_VICTIM, &mm->flags); }