Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1019165ybe; Wed, 4 Sep 2019 11:13:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqws4g+HTG4fKOo8cTjXWiw+DQ5zK2kr5ifPaXZIRotPS8kcHBdpnxYTiSsGcZlDesgCg22s X-Received: by 2002:a65:5cca:: with SMTP id b10mr37186923pgt.365.1567620833866; Wed, 04 Sep 2019 11:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620833; cv=none; d=google.com; s=arc-20160816; b=oTgR1hdoIjqPyee615i3dSCV9v+BjuQc0TrPW9lcWxxa90t3Gh6SQbHM+5L/eFqbSd yvoN89JWeAawwjtA6o4ZkF4GzbAGjwjjmNlGOFZt4X2WDbB37Iah+l7MNnRpNPoF0R05 nqbQSk8ejmRHbXbn25MJAQuF1lnIQwZOc6FuM+CrS0gUkd6O7OC+iPpgsToGZEWE6/zZ WKP8Gs+T0SA2g+PAkyYJQoRYDj5N3udfzE94hyxBgl1JvQjV0S1L8JDih350E25BHkwp 5Q3G5nCXZPMMyaw+pz8c98+HwsPTVJjyFL4s9ZgPczkoJT8jPH8LHKDwNqMf67hrRBFF RYYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3F+r7HwimsoOy46nFRR6TgLUz2+Z/+cx1oPfWYMmI6g=; b=t2vTpA+26S86NxuIIT+w64g84A7KP64HZ+OBBlRrW9Qb3xR2+B3bUJcHOkbUMhM3yZ XayQt13Z9PVBK5cn2/c2Y1mAcgwC3ub2qY52gkU2wrjSoNjxQDI3oip9E0Eo0/63+76z rIWeWzVpFVOc+Pe0bvTmy/umL2C+CAIFZ8k/xG8vuRpg+bzwg9kdHsjai5hJaKAfjSmi iHdGtu6SoEK5F4tYVWfb4URXWyVkoVl8eqlVa9+3c76ogIvPzCbyXoqhAioCu0r9dPHL 1353GEvH3jVE6WiHPAHiEH6ldyqy+ww92BkuCCcUm6LqticCMkqaMumn/eibM9aYc4Eh LxHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dNcy2Du8; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y9si20628588pfm.25.2019.09.04.11.13.38; Wed, 04 Sep 2019 11:13:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b=dNcy2Du8; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390184AbfIDSKy (ORCPT + 99 others); Wed, 4 Sep 2019 14:10:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:54664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390170AbfIDSKw (ORCPT ); Wed, 4 Sep 2019 14:10:52 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5DF1B206B8; Wed, 4 Sep 2019 18:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620651; bh=An5nCkic9DIMAchQA8nBNy2dnhyUW1x9ls9wee2wjeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dNcy2Du8an8wu4lCnBTePdGlrkedudBFwBMsgc61bJ4bv9sWVTRVbKXfzbOc4eMNM 3Q4nX/22mwllEjODo3oY1WRDzrRyqytds3gnuQw1NEYdxGBxdHnNaD9t7fSp61YSaQ PdoZ3ksT+y8iUk9/yf8LYmz2wvKAYAKIo4QtKcnY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Stancek , "Peter Zijlstra (Intel)" , Will Deacon , Waiman Long , Linus Torvalds , Thomas Gleixner , dbueso@suse.de, Ingo Molnar , Sasha Levin Subject: [PATCH 5.2 043/143] locking/rwsem: Add missing ACQUIRE to read_slowpath exit when queue is empty Date: Wed, 4 Sep 2019 19:53:06 +0200 Message-Id: <20190904175315.753872440@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit e1b98fa316648420d0434d9ff5b92ad6609ba6c3 ] LTP mtest06 has been observed to occasionally hit "still mapped when deleted" and following BUG_ON on arm64. The extra mapcount originated from pagefault handler, which handled pagefault for vma that has already been detached. vma is detached under mmap_sem write lock by detach_vmas_to_be_unmapped(), which also invalidates vmacache. When the pagefault handler (under mmap_sem read lock) calls find_vma(), vmacache_valid() wrongly reports vmacache as valid. After rwsem down_read() returns via 'queue empty' path (as of v5.2), it does so without an ACQUIRE on sem->count: down_read() __down_read() rwsem_down_read_failed() __rwsem_down_read_failed_common() raw_spin_lock_irq(&sem->wait_lock); if (list_empty(&sem->wait_list)) { if (atomic_long_read(&sem->count) >= 0) { raw_spin_unlock_irq(&sem->wait_lock); return sem; The problem can be reproduced by running LTP mtest06 in a loop and building the kernel (-j $NCPUS) in parallel. It does reproduces since v4.20 on arm64 HPE Apollo 70 (224 CPUs, 256GB RAM, 2 nodes). It triggers reliably in about an hour. The patched kernel ran fine for 10+ hours. Signed-off-by: Jan Stancek Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Will Deacon Acked-by: Waiman Long Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: dbueso@suse.de Fixes: 4b486b535c33 ("locking/rwsem: Exit read lock slowpath if queue empty & no writer") Link: https://lkml.kernel.org/r/50b8914e20d1d62bb2dee42d342836c2c16ebee7.1563438048.git.jstancek@redhat.com Signed-off-by: Ingo Molnar Acked-by: Jan Stancek Signed-off-by: Sasha Levin --- kernel/locking/rwsem-xadd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c index 0b1f779572402..397dedc58432d 100644 --- a/kernel/locking/rwsem-xadd.c +++ b/kernel/locking/rwsem-xadd.c @@ -454,6 +454,8 @@ __rwsem_down_read_failed_common(struct rw_semaphore *sem, int state) * been set in the count. */ if (atomic_long_read(&sem->count) >= 0) { + /* Provide lock ACQUIRE */ + smp_acquire__after_ctrl_dep(); raw_spin_unlock_irq(&sem->wait_lock); rwsem_set_reader_owned(sem); lockevent_inc(rwsem_rlock_fast); -- 2.20.1