Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2263688ybh; Fri, 24 Jul 2020 08:25:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXnVzE2Cp0Dcx8sKZ/+L2yLFNsBsFFArKUgwjd7iROKsEhvKZqPjbbVlgXYhUMDFZdVhXT X-Received: by 2002:a17:906:c285:: with SMTP id r5mr9497753ejz.153.1595604315954; Fri, 24 Jul 2020 08:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595604315; cv=none; d=google.com; s=arc-20160816; b=u7v1v/6muP+tHeQx6wCjLhbx1H9Rb6ZFHGPTGL/eQEmlhaMRWEv2GHS1CZnnxL0kB/ fTkUK9d75C8ykWx7gU4GrT5IsGSkyCFfLAh/n055+tHEVv+ujf3VnIooMQJQn4aRSbN5 JG68kYhfsXEzjFmkFUUaryF5ACvg0tuZv3xDpRO/pEwNV9FfDOUDqQPj65gxYWTG9fiT Z0mPnueJyZB5yZ5mYSfMFvsBTd6LlIiurTnkNYxIZkEm1qo+fqI3Ro91E3PbVNK/nLRV xq7DJ8qDph3OauU1EWfzRAsHC2z5ZK0/wMyQlkYLh6v0IuzytEZyWSGmPHjSOtQRaVls m6yw== 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=5S4LFFufUCLzyfla7YE3yrAMSl5PTYaLTnMam8y5Ck0=; b=hSFJrNHr8zpXEmIxK+V4lU4WGaDgK+ylN2kZ1rAbccPKIARi59INrM9E6uLRvmd6Fn AIbKIrsTnDdMvneMXK29S5W26pX+nDfUsN3+g4oKRjcKmK7XjnUxsqc3bwGttu21E3mx L8cYQmjzwGQilmFQtJTxFca0ell09j9K9AG7mxIdWl8QZZ7rNr07mi6YfothasasRwFG ZVm4vPzQ8S9/JYC2x/MYSv2iPXT+qfKqirI4WRQQ/8urPI7xEU0H+464LPAWxqTLA9pq +OfsGLiak1sqdaHDhmRT0h/7vDh7CZl7avCEWO53AzWkKJFabW/WfzquzDrofrm2e7UH KxxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="W3P+ta/1"; 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 h14si686853edv.119.2020.07.24.08.24.53; Fri, 24 Jul 2020 08:25:15 -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="W3P+ta/1"; 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 S1726650AbgGXPYh (ORCPT + 99 others); Fri, 24 Jul 2020 11:24:37 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:50294 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726317AbgGXPYh (ORCPT ); Fri, 24 Jul 2020 11:24:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595604273; 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=5S4LFFufUCLzyfla7YE3yrAMSl5PTYaLTnMam8y5Ck0=; b=W3P+ta/1Pqr+oEObZKHjCT08TOCQ5SLfej4isBqBkj0lgdRR82dVeL0XLt28nOixcHvI0j jPMbfdPYq6dHFMdNME6GuraeRWASRmDnkq4ie3zxfwtSBYvTbevuIy3PheKonKEiBbfMK1 VQgCkbkVaVoKQVo7INpIVLY3w0dJSVI= 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-499-NSHLOZ7cNXi5LB6e4jUxbQ-1; Fri, 24 Jul 2020 11:24:29 -0400 X-MC-Unique: NSHLOZ7cNXi5LB6e4jUxbQ-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4BE2919057A1; Fri, 24 Jul 2020 15:24:28 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.192.121]) by smtp.corp.redhat.com (Postfix) with SMTP id 3F0242DE7F; Fri, 24 Jul 2020 15:24:26 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 24 Jul 2020 17:24:27 +0200 (CEST) Date: Fri, 24 Jul 2020 17:24:25 +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: <20200724152424.GC17209@redhat.com> References: <20200723124749.GA7428@redhat.com> 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.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/23, Linus Torvalds wrote: > > But I'll walk over my patch mentally one more time. Here's the current > version, anyway. Both patches look correct to me, feel free to add Reviewed-by: Oleg Nesterov > @@ -1013,18 +1014,40 @@ static int wake_page_function(wait_queue_entry_t *wait, unsigned mode, int sync, > if (wait_page->bit_nr != key->bit_nr) > return 0; > > + /* Stop walking if it's locked */ > + if (wait->flags & WQ_FLAG_EXCLUSIVE) { > + if (test_and_set_bit(key->bit_nr, &key->page->flags)) > + return -1; > + } else { > + if (test_bit(key->bit_nr, &key->page->flags)) > + return -1; > + } not sure this makes any sense, but this looks like another user of trylock_page_bit_common(), see the patch below on top of 1/2. Oleg. --- mm/filemap.c~ 2020-07-24 17:09:34.728133846 +0200 +++ mm/filemap.c 2020-07-24 17:23:52.279185374 +0200 @@ -1000,6 +1000,14 @@ wait_queue_entry_t wait; }; +static int trylock_page_bit_common(struct page *page, int bit_nr, + struct wait_queue_entry *wait) +{ + return wait->flags & WQ_FLAG_EXCLUSIVE ? + !test_and_set_bit(bit_nr, &page->flags) : + !test_bit(bit_nr, &page->flags); +} + static int wake_page_function(wait_queue_entry_t *wait, unsigned mode, int sync, void *arg) { int ret; @@ -1015,13 +1023,8 @@ return 0; /* Stop walking if it's locked */ - if (wait->flags & WQ_FLAG_EXCLUSIVE) { - if (test_and_set_bit(key->bit_nr, &key->page->flags)) - return -1; - } else { - if (test_bit(key->bit_nr, &key->page->flags)) - return -1; - } + if (!trylock_page_bit_common(key->page, key->bit_nr, wait)) + return -1; /* * Let the waiter know we have done the page flag @@ -1126,14 +1129,6 @@ */ }; -static inline int trylock_page_bit_common(struct page *page, int bit_nr, - enum behavior behavior) -{ - return behavior == EXCLUSIVE ? - !test_and_set_bit(bit_nr, &page->flags) : - !test_bit(bit_nr, &page->flags); -} - static inline int wait_on_page_bit_common(wait_queue_head_t *q, struct page *page, int bit_nr, int state, enum behavior behavior) { @@ -1170,7 +1165,7 @@ */ spin_lock_irq(&q->lock); SetPageWaiters(page); - if (!trylock_page_bit_common(page, bit_nr, behavior)) + if (!trylock_page_bit_common(page, bit_nr, wait)) __add_wait_queue_entry_tail(q, wait); spin_unlock_irq(&q->lock);