Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1306334ybh; Thu, 23 Jul 2020 05:50:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYLdGHOHeIY1iwHnjUoHGB+j2dmbLLSqwG0T2dzJFmgasEg4Dv39l+shJi4eFDFSOUlpiZ X-Received: by 2002:a17:906:4145:: with SMTP id l5mr4236573ejk.334.1595508633072; Thu, 23 Jul 2020 05:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595508633; cv=none; d=google.com; s=arc-20160816; b=zYMAZtOoNXhzwcgIrkX3ckFXfHNKEkS9ajJhlWVYCf8BmNakLDFbvgV1nAR6yMchwb xBxoUM+CcVehfur8PKOz9hfsdmAA84jNB7Gt/XdDcCHTK5hRIquVOmjbC3Hqm53gE1ns Vcn7dakhB3pV7fXyv+/S4AvVvg/eB+G0yUGQwKI0gOuAC+D3sSdNjw4SRvXn8VHMsDOU FjgBDfhRy1uYBn/SKThzxKqFBSddYXOg/vfA8AXhFmJ6FjqguUO/i0vVaay1bKpS6AYw 3nW0QdfnSis4lt4awnB2CqnrXHJ4s5kqzYLtRsRbbp6NKB5Q6DAzEaHLK+vvLkfviAOL birw== 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:dkim-signature; bh=cJcttqDco8CfqD0BegwArNFSC5U6Uee5kSlZI1/HOP0=; b=mcQOZl9cnwZuVV8NtWuuO9H9DfGKicXIrC4nznoCuiviIn6sJB8GMzw1rd1JM9qObw ImUvnmKEY9jQhYv3MskRy1jMXT45Rit38DACjv6pXUF9kb5yman3JeMi8D8AAjd5Wirj 2mJkYr8UOj8pDkVEMuDO42o/bEQV1Y3gMAoI1yJgl/AMHK8xoc9qkoXMNTvdOQG0oaaz Vx/Hbg9DgvXQcPhhrbemq9gDoBNe0RH9Oygtx42wqeKBk99e8tsFjRovyKDBDe4ieFMn asbpuwcrDfBNqv2dCaBbOeuH3BsPKAsE53j8Egle7+tjlbqJbDrh/GO7AwDGVrROvwI0 5Vyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DwL9kOl2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd13si1919051edb.153.2020.07.23.05.50.10; Thu, 23 Jul 2020 05:50:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DwL9kOl2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728289AbgGWMr6 (ORCPT + 99 others); Thu, 23 Jul 2020 08:47:58 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53756 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726109AbgGWMr6 (ORCPT ); Thu, 23 Jul 2020 08:47:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595508477; 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=DwL9kOl2bRPS7TLVjguQnKWTgznSEDsfA0dARKfvbOPEvby/4/ODtiNqw8etbqwwiH1ZDf jvbFuw1/yj7zkpubL1qszlIp+6y3k4grOUkPVyQbuduqQD+jS+7Zg5xPI6wje1ucFfw1N+ a4S2CSco3/i6u36dGBX7vL2/jNjI7+M= 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.