Received: by 10.223.176.46 with SMTP id f43csp3255921wra; Mon, 22 Jan 2018 10:55:02 -0800 (PST) X-Google-Smtp-Source: AH8x224Sd3CJgtx8kN4vmAv5AzCATL3Ji25YFaKcFFqzlegJRrAJG28QDcAMfl+g1fe80LdNNBRK X-Received: by 10.36.29.81 with SMTP id 78mr9334203itj.53.1516647302497; Mon, 22 Jan 2018 10:55:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516647302; cv=none; d=google.com; s=arc-20160816; b=jUxBzr0JVHFwEM7AJ0WNhZKlhQEgKzDVirBGRMOmr5VWR6OgNsbr1rB9AOHOjJg0+w aUptlx2K4C9vysALs6Qx8/vgO/GNBL4XH4Nv8Xk6XqqchPz26SyHAjI0LZRYkuyflzHA 4AoDamgx6rAQ/9vzW0FtIs3XaALPvyQOEJmb4NsQV9PZyA+rGE9SEtu89ayMqPcLZccB rDzLPlveQ+18wu4ZIIbSnw6pMFW43dVazleaj8uD7PCoWj5VOrRBwRHaWmElR8jy6snU tn61N9+cDqXvqZgM25IoiSM6PmPDaNi5BexT2QAhv25IkqaQaeo5g7zCmM5dISiPGuKL /zpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=AY1Ef4AujOIWCHzAdrpHZGSyyr83FgnuQ8TSP6V3mmU=; b=XNbezkO9NsH/X+PTOl8bCDXyubriDNo2ep3ykxI00s/KiICnEcYJHi7/xuNdxLNx1t +Py1rpFUkE8jHdF54s4DKkWCAlwQv68tvVu/40kJvPzna5pnf9dlI8775zQLlit1akQ5 M8CSj4xKbvni9x+LAgU5pdHUTF/n1xItqdyZ+wkFKEX9jHJCBwLivlz02/IffV6Yeb9x 1DbAlsoOID5WzjU2Y6mw9tEnnyFnCt+5ndZ1C7k6xAAdgpAVXOW8+MWXXMj6D13hj67T E5GEXM2FAZ0muk48RoJaHyZP56Kmw9Gp4NkfXU2EW5OIE3KWrwl6Fx0WMxAbZ14FMU+6 SY7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fTJH28Gs; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 83si6177428itb.92.2018.01.22.10.54.49; Mon, 22 Jan 2018 10:55:02 -0800 (PST) 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=fail header.i=@gmail.com header.s=20161025 header.b=fTJH28Gs; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751643AbeAVSyA (ORCPT + 99 others); Mon, 22 Jan 2018 13:54:00 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:35379 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751571AbeAVSxz (ORCPT ); Mon, 22 Jan 2018 13:53:55 -0500 Received: by mail-qt0-f196.google.com with SMTP id g14so14273216qti.2; Mon, 22 Jan 2018 10:53:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=AY1Ef4AujOIWCHzAdrpHZGSyyr83FgnuQ8TSP6V3mmU=; b=fTJH28GsywZzo1AKJxiS11MVwrkgQIef2c2IntRZQlQblUTqW/HAuu1iuQSsdULJAX wWM0tgqx+mmtg6C6XrvNUa+VgEjSqpRh3+eSsiv7XioJme3sH3pWp6G7nSroEUu1M3yn CgcCvH8SLS6Wx5YXK+Xh71Qa9Hkwq/D9a5AOM8vURzEoZNezerx4JjQ8gYpuCR1fzBav zeh2o9akGI8g11Y5GreqqbK+m1y7Xy6j15Jaet4XDYNTwhvQR95xFvC+HB2V8hfvUKuV hS9vSNLI9vIvthpTZGMSj9wzFSoif/yeurXb9ZTYsOCydmj9fE//8SI/Gy4uo70Ptox3 fstw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=AY1Ef4AujOIWCHzAdrpHZGSyyr83FgnuQ8TSP6V3mmU=; b=cP/L2jR4PDHDhVkusbcI0vr8UiIU5JdaMBZMUQCBK55ba05LAVNea4r9PIF/x7TvEx 6btvHhM+arRK7abri+q9eN/v7OmyRHF8e2w++X8IgU5gL07xBxMf+4jxrubNyCk2wPVR WP9bneSVRZB9etOVMQHF8F7EDVId5Wig6pdokmGtaIltC4G09ncaxZPmJYJOBS10Kfr+ u7z6iVMBrVFYmWcdEyNKIlcw/dOxQ+wuxnr1IQDiKSMIT7EHhg0k7HLucXYbvyC2JKuP RTM/yrsubG9fVYMVZUsZ3TVASAgFiBGGcao3lNixAYI2T2MxRL+JMmJy1hDu8zbbnWpr FL/Q== X-Gm-Message-State: AKwxytfC3L0uhSA4AWjDqbSYamRpt6xV4+TJTvFti5VWYO1Ka1iviqS6 iuD90S/PAn0HH+MK7y7SR8g= X-Received: by 10.237.32.225 with SMTP id 88mr3767357qtb.99.1516647234507; Mon, 22 Jan 2018 10:53:54 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id o20sm10790061qkl.14.2018.01.22.10.53.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 10:53:53 -0800 (PST) From: Ram Pai To: shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, akpm@linux-foundation.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com, arnd@arndb.de Subject: [PATCH v10 22/24] selftests/vm: Fix deadlock in protection_keys.c Date: Mon, 22 Jan 2018 10:52:15 -0800 Message-Id: <1516647137-11174-23-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1516647137-11174-1-git-send-email-linuxram@us.ibm.com> References: <1516647137-11174-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thiago Jung Bauermann The sig_chld() handler calls dprintf2() taking care of setting dprint_in_signal so that sigsafe_printf() won't call printf(). Unfortunately, this precaution is is negated by dprintf_level(), which has a call to fflush(). This function acquires a lock, which means that if the signal interrupts an ongoing fflush() the process will deadlock. At least on powerpc this is easy to trigger, resulting in the following backtrace when attaching to the frozen process: (gdb) bt #0 0x00007fff9f96c7d8 in __lll_lock_wait_private () from /lib64/power8/libc.so.6 #1 0x00007fff9f8cba4c in _IO_flush_all_lockp () from /lib64/power8/libc.so.6 #2 0x00007fff9f8cbd1c in __GI__IO_flush_all () from /lib64/power8/libc.so.6 #3 0x00007fff9f8b7424 in fflush () from /lib64/power8/libc.so.6 #4 0x00000000100504f8 in sig_chld (x=17) at protection_keys.c:283 #5 #6 0x00007fff9f8cb8ac in _IO_flush_all_lockp () from /lib64/power8/libc.so.6 #7 0x00007fff9f8cbd1c in __GI__IO_flush_all () from /lib64/power8/libc.so.6 #8 0x00007fff9f8b7424 in fflush () from /lib64/power8/libc.so.6 #9 0x0000000010050b50 in pkey_get (pkey=7, flags=0) at protection_keys.c:379 #10 0x0000000010050dc0 in pkey_disable_set (pkey=7, flags=2) at protection_keys.c:423 #11 0x0000000010051414 in pkey_write_deny (pkey=7) at protection_keys.c:486 #12 0x00000000100556bc in test_ptrace_of_child (ptr=0x7fff9f7f0000, pkey=7) at protection_keys.c:1288 #13 0x0000000010055f60 in run_tests_once () at protection_keys.c:1414 #14 0x00000000100561a4 in main () at protection_keys.c:1459 The fix is to refrain from calling fflush() when inside a signal handler. The output may not be as pretty but at least the testcase will be able to move on. Signed-off-by: Ram Pai Signed-off-by: Thiago Jung Bauermann tools/testing/selftests/vm/pkey-helpers.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- tools/testing/selftests/vm/pkey-helpers.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-helpers.h b/tools/testing/selftests/vm/pkey-helpers.h index 9d06b4a..965cfcd 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -131,7 +131,8 @@ static inline void sigsafe_printf(const char *format, ...) #define dprintf_level(level, args...) do { \ if (level <= DEBUG_LEVEL) \ sigsafe_printf(args); \ - fflush(NULL); \ + if (!dprint_in_signal) \ + fflush(NULL); \ } while (0) #define dprintf0(args...) dprintf_level(0, args) #define dprintf1(args...) dprintf_level(1, args) -- 1.7.1