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 X-Spam-Level: X-Spam-Status: No, score=-5.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4DC3C433E3 for ; Thu, 23 Jul 2020 12:48:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7D0672086A for ; Thu, 23 Jul 2020 12:48:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="S6hy+M3A" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D0672086A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CECC46B0002; Thu, 23 Jul 2020 08:48:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C76086B0005; Thu, 23 Jul 2020 08:48:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3D286B0006; Thu, 23 Jul 2020 08:48:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 9AA046B0002 for ; Thu, 23 Jul 2020 08:48:00 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3FF5D181AEF3F for ; Thu, 23 Jul 2020 12:48:00 +0000 (UTC) X-FDA: 77069317920.12.house38_4403fc826f3e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 09FBF18056267 for ; Thu, 23 Jul 2020 12:48:00 +0000 (UTC) X-HE-Tag: house38_4403fc826f3e X-Filterd-Recvd-Size: 5033 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Jul 2020 12:47:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595508479; 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=cJcttqDco8CfqD0BegwArNFSC5U6Uee5kSlZI1/HOP0=; b=S6hy+M3A5Jr+ZdS2BN/S+dvRNa79hE0Ayt2voPPz9dAN+Z7+pSmrDFAJ1OeqSn4KWWrE+m ZJBSC7cZUP3XzukrxQqUNIFH5zt6dpW+DXRG/14mqMFpbu2lLPcKoV8ZCDesh13RtzmSLj GUj4i3CkIp1I3/jR3RFbZfa4GnYZh/8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-206-7gB_Oyw4O9adtKtjN-NQ4Q-1; Thu, 23 Jul 2020 08:47:54 -0400 X-MC-Unique: 7gB_Oyw4O9adtKtjN-NQ4Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23E4F8005B0; Thu, 23 Jul 2020 12:47:53 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.194.249]) by smtp.corp.redhat.com (Postfix) with SMTP id 1866074F58; Thu, 23 Jul 2020 12:47:50 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 23 Jul 2020 14:47:52 +0200 (CEST) Date: Thu, 23 Jul 2020 14:47:50 +0200 From: Oleg Nesterov To: Linus Torvalds Cc: Hugh Dickins , Michal Hocko , Linux-MM , LKML , Andrew Morton , Tim Chen , Michal Hocko Subject: Re: [RFC PATCH] mm: silence soft lockups from unlock_page Message-ID: <20200723124749.GA7428@redhat.com> References: <20200721063258.17140-1-mhocko@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Rspamd-Queue-Id: 09FBF18056267 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 07/22, Linus Torvalds wrote: > > Comments? Oleg, this should fix the race you talked about too. Yes. I still can't convince myself thatI fully understand this patch but I see nothing really wrong after a quick glance... > + * We can no longer use 'wait' after we've done the > + * list_del_init(&wait->entry), Yes, but see below, > + * the target may decide it's all done with no > + * other locking, and 'wait' has been allocated on > + * the stack of the target. > */ > - if (test_bit(key->bit_nr, &key->page->flags)) > - return -1; > + target = wait->private; > + smp_mb(); > > - return autoremove_wake_function(wait, mode, sync, key); > + /* > + * Ok, we have successfully done what we're waiting for. > + * > + * Now unconditionally remove the wait entry, so that the > + * waiter can use that to see success or not. > + * > + * We _really_ should have a "list_del_init_careful()" > + * to properly pair with an unlocked "list_empty_careful()". > + */ > + list_del_init(&wait->entry); > + > + /* > + * Theres's another memory barrier in the wakup path, that > + * makes sure the wakup happens after the above is visible > + * to the target. > + */ > + wake_up_state(target, mode); We can no longer use 'target'. If it was already woken up it can notice list_empty_careful(), return without taking q->lock, and exit. Of course, this is purely theoretical... rcu_read_lock() should help but perhaps we can avoid it somehow? Say, can't we abuse WQ_FLAG_WOKEN? wake_page_function: wait->flags |= WQ_FLAG_WOKEN; wmb(); autoremove_wake_function(...); wait_on_page_bit_common: for (;;) { set_current_state(); if (wait.flags & WQ_FLAG_WOKEN) break; schedule(); } finish_wait(); rmb(); return wait.flags & WQ_FLAG_WOKEN ? 0 : -EINTR; Another (cosmetic) problem is that wake_up_state(mode) looks confusing. It is correct but only because we know that mode == TASK_NORMAL and thus wake_up_state() can'fail if the target is still blocked. > + spin_lock_irq(&q->lock); > + SetPageWaiters(page); > + if (!trylock_page_bit_common(page, bit_nr, behavior)) > + __add_wait_queue_entry_tail(q, wait); do we need SetPageWaiters() if trylock() succeeds ? Oleg.