Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2462821imd; Fri, 2 Nov 2018 11:50:29 -0700 (PDT) X-Google-Smtp-Source: AJdET5e5Ff0FXNeZujuJdPEco8lX5AoJ913oWv/gmGbkG4vSqy/kRpU99WCFXhJSCgFTcwKgzDyL X-Received: by 2002:a63:990a:: with SMTP id d10mr11967598pge.279.1541184629539; Fri, 02 Nov 2018 11:50:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184629; cv=none; d=google.com; s=arc-20160816; b=EuQ6dJGs5NHWNCjrfJT4G5SME6XVTLl3xdpqc5dkSfqunnLz6+k8H1CvUflTFXFGVL 6J28ohmr0jWfJZdqXzxiLUGvDYLthHAfFHz+dlZYn8AWlwfQ/3Pol36PS/vd3zHDxcFL VoqBMRyag7k9EcjoSwtI84224/QVEs+59LrtR8CzyOyJsXmS+gkgoD/sLppt4wS1uje9 A+ff3l2T1t9b3gGviwYOo6n7TsuoZdWz9qahxd3HRCuPgD6Wx6SiNWYD9UIefwKLcBf5 FIxRGm1ZseCDZiC4F8vUKWG9JXF6Vx17oWi8fPSnAoCr+kSYTFtXNFDqD0VW7JkvOaQe /ucw== 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=oxl3dVo/NqG4TEJtI2VB/nacqTdPTwcAFyj6/yAXH6I=; b=jec9n+3LA1Ogoyh3UgrotkBnQyQYPMdWx0VOFS2yxJI+Y+Dzoq0PoBlZ7dKnb1UVE7 asSikZGE+yF9g46QZ0BNJEyqHMAc6KiuSTWtxS/T7b8L0OeJi6Crocs+abq7Nbn7X1Ow G4NFtF/5xYLGQId7lnv8b5uqrzkM7oScR38b3mkrpkoOSDkVU90YpCKeI5h9XxFP6iF1 31bq/vw3mhItA2l+BGdHxSHF5Nt2ADqBB/w7dut6YUGHJdadVDuCSI1swZXDQyq5Mszg wnXcNyLe7W2e5MFHZmrTF9JrxEH/1VbiXTEpTw0nPtar2q3vDa5Lt1eGlYhnYUb8Ekqw jHHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TPONxA+U; 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 n6-v6si15056296pla.245.2018.11.02.11.50.14; Fri, 02 Nov 2018 11:50:29 -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=TPONxA+U; 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 S1730733AbeKCD6J (ORCPT + 99 others); Fri, 2 Nov 2018 23:58:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:53888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728280AbeKCD6J (ORCPT ); Fri, 2 Nov 2018 23:58:09 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.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 BA7C620843; Fri, 2 Nov 2018 18:49:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184594; bh=1sQJllipb2gVZv+nQVc4S4gIw8/sY5SMkD1/tN7gjoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TPONxA+UbIEi6K2XEzHvyNjvp68MwpOCuyecLLGAp1nA+qu31tUYxHqt2E+k8TZFg glJTFBst4Ec1Qf1Bhzowr5pDbQojT3m5ZfABIQU8LVuwghRMhpMfhem73xIgxGi/5T jHQJ3wzfm//EMAipeOo+MsEB47ye43rfb4dHU3FM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guenter Roeck , Chris Wilson , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Will Deacon , Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 045/143] locking/ww_mutex: Fix runtime warning in the WW mutex selftest Date: Fri, 2 Nov 2018 19:33:50 +0100 Message-Id: <20181102182900.658659799@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182857.064326086@linuxfoundation.org> References: <20181102182857.064326086@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit e4a02ed2aaf447fa849e3254bfdb3b9b01e1e520 ] If CONFIG_WW_MUTEX_SELFTEST=y is enabled, booting an image in an arm64 virtual machine results in the following traceback if 8 CPUs are enabled: DEBUG_LOCKS_WARN_ON(__owner_task(owner) != current) WARNING: CPU: 2 PID: 537 at kernel/locking/mutex.c:1033 __mutex_unlock_slowpath+0x1a8/0x2e0 ... Call trace: __mutex_unlock_slowpath() ww_mutex_unlock() test_cycle_work() process_one_work() worker_thread() kthread() ret_from_fork() If requesting b_mutex fails with -EDEADLK, the error variable is reassigned to the return value from calling ww_mutex_lock on a_mutex again. If this call fails, a_mutex is not locked. It is, however, unconditionally unlocked subsequently, causing the reported warning. Fix the problem by using two error variables. With this change, the selftest still fails as follows: cyclic deadlock not resolved, ret[7/8] = -35 However, the traceback is gone. Signed-off-by: Guenter Roeck Cc: Chris Wilson Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Fixes: d1b42b800e5d0 ("locking/ww_mutex: Add kselftests for resolving ww_mutex cyclic deadlocks") Link: http://lkml.kernel.org/r/1538516929-9734-1-git-send-email-linux@roeck-us.net Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/locking/test-ww_mutex.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c index 0e4cd64ad2c0..654977862b06 100644 --- a/kernel/locking/test-ww_mutex.c +++ b/kernel/locking/test-ww_mutex.c @@ -260,7 +260,7 @@ static void test_cycle_work(struct work_struct *work) { struct test_cycle *cycle = container_of(work, typeof(*cycle), work); struct ww_acquire_ctx ctx; - int err; + int err, erra = 0; ww_acquire_init(&ctx, &ww_class); ww_mutex_lock(&cycle->a_mutex, &ctx); @@ -270,17 +270,19 @@ static void test_cycle_work(struct work_struct *work) err = ww_mutex_lock(cycle->b_mutex, &ctx); if (err == -EDEADLK) { + err = 0; ww_mutex_unlock(&cycle->a_mutex); ww_mutex_lock_slow(cycle->b_mutex, &ctx); - err = ww_mutex_lock(&cycle->a_mutex, &ctx); + erra = ww_mutex_lock(&cycle->a_mutex, &ctx); } if (!err) ww_mutex_unlock(cycle->b_mutex); - ww_mutex_unlock(&cycle->a_mutex); + if (!erra) + ww_mutex_unlock(&cycle->a_mutex); ww_acquire_fini(&ctx); - cycle->result = err; + cycle->result = err ?: erra; } static int __test_cycle(unsigned int nthreads) -- 2.17.1