Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp987945yba; Thu, 9 May 2019 08:58:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/rBT64RjskdBqM/u4YSmQBhjPJhYxo1WduRp56Ft0HOFRH9jJe/nfzZC5QOsYjRbqfSE9 X-Received: by 2002:a17:902:2e83:: with SMTP id r3mr6290912plb.286.1557417518431; Thu, 09 May 2019 08:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557417518; cv=none; d=google.com; s=arc-20160816; b=gfyXqMjYW4ws9/OQH4BjjImJHz6Eb5MsJnuIZh4Vnl7afhjSZ34UXUgQr2iirEyjdg hRsHz3Po7V23R4CSK1FuePD3RD/crB0JiG0nHWGI/mQEmajkGKu2iPV7c8cbnJRnsuzg VEC4TV+Pt02j2VkBgImV+lI+Rqvu8++f4uQsZ2M6vJkJB7trcQbSgWTD7ogBC09BLmSe ikwPuxNJMTquDIh9uoZ4xR5HhON8Dh6hkHmRQnWhncaUYC82fy551YizzEsM1gWNNfJc pQf5UxBlZ7JS3wVfwuAN3Hb6bq8MldJscDQxZp8ssklrr49thLUkC9txJOkVRhf4d+Um 2Dlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ZZ8fCHB8eclIGo1V1jbuvKP9A8tuFZPXbwG0DpdC7Ww=; b=wMTLoO0YzuHwqmqMO2ckjCVFHVKnXZrO2n/9nR7gJ4jqK6ps5GUxOBLXZbuUHVtYcg d+Xti1mTmKq+G7lQ4Mwzhr4Uzpro7oRt7nKbznm0PZ+GBFh5dFTTwKLeHsu/reZfNlA0 hz59prDMGwVZDkQb3DSBWBafmWaAUQPKnGeuuwkUIhhcR2SytVghhdqa8vjIqtC0pHSi jFepIrqycsWx7jBEFhDoFWDZrFM3atGXmJ2OHYX4pt6p5Bcnk3F6qS019sE/6AGE8F08 Hkv0LmkauOQF/TA/omOV10Y1VFlNdckPUvKoN3jpeOLTXpAuny3Y47pov+KeqZZpOdQh iGPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q14si3351719pls.327.2019.05.09.08.58.21; Thu, 09 May 2019 08:58:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726683AbfEIP4y (ORCPT + 99 others); Thu, 9 May 2019 11:56:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35244 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726187AbfEIP4x (ORCPT ); Thu, 9 May 2019 11:56:53 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF84BDBD6F; Thu, 9 May 2019 15:56:52 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.159]) by smtp.corp.redhat.com (Postfix) with SMTP id 4B9EC27BCD; Thu, 9 May 2019 15:56:48 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 9 May 2019 17:56:51 +0200 (CEST) Date: Thu, 9 May 2019 17:56:46 +0200 From: Oleg Nesterov To: Sultan Alsawaf Cc: Christian Brauner , Daniel Colascione , Suren Baghdasaryan , Steven Rostedt , Tim Murray , Michal Hocko , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Ingo Molnar , Peter Zijlstra , LKML , "open list:ANDROID DRIVERS" , linux-mm , kernel-team , Andy Lutomirski , "Serge E. Hallyn" , Kees Cook , Joel Fernandes Subject: Re: [RFC] simple_lmk: Introduce Simple Low Memory Killer for Android Message-ID: <20190509155646.GB24526@redhat.com> References: <20190318002949.mqknisgt7cmjmt7n@brauner.io> <20190318235052.GA65315@google.com> <20190319221415.baov7x6zoz7hvsno@brauner.io> <20190319231020.tdcttojlbmx57gke@brauner.io> <20190320015249.GC129907@google.com> <20190507021622.GA27300@sultan-box.localdomain> <20190507153154.GA5750@redhat.com> <20190507163520.GA1131@sultan-box.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190507163520.GA1131@sultan-box.localdomain> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 09 May 2019 15:56:53 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/07, Sultan Alsawaf wrote: > > On Tue, May 07, 2019 at 05:31:54PM +0200, Oleg Nesterov wrote: > > > Did you test this patch with lockdep enabled? > > > > If I read the patch correctly, lockdep should complain. vtsk_is_duplicate() > > ensures that we do not take the same ->alloc_lock twice or more, but lockdep > > can't know this. > > Yeah, lockdep is fine with this, at least on 4.4. Impossible ;) I bet lockdep should report the deadlock as soon as find_victims() calls find_lock_task_mm() when you already have a locked victim. Nevermind, I guess this code won't run with lockdep enabled... As for https://github.com/kerneltoast/android_kernel_google_wahoo/commit/afc8c9bf2dbde95941253c168d1adb64cfa2e3ad Well, mmdrop(mm); simple_lmk_mm_freed(mm); looks racy because mmdrop(mm) can free this mm_struct. Yes, simple_lmk_mm_freed() does not dereference this pointer, but the same memory can be re-allocated as another ->mm for the new task which can be found by find_victims(), and _in theory_ this all can happen in between, so the "victims[i].mm == mm" can be false positive. And this also means that simple_lmk_mm_freed() should clear victims[i].mm when it detects "victims[i].mm == mm", otherwise we have the same theoretical race, victims_to_kill is only cleared when the last victim goes away. Another nit... you can drop tasklist_lock right after the 1st "find_victims" loop. And it seems that you do not really need to walk the "victims" array twice after that, you can do everything in a single loop, but this is cosmetic. Oleg.