From patchwork Mon Jan 22 18:52:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 864394 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zQMmm6yTjz9s4s for ; Tue, 23 Jan 2018 07:03:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fTJH28Gs"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3zQMmm5n7hzDqsn for ; Tue, 23 Jan 2018 07:03:04 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fTJH28Gs"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c0d::243; helo=mail-qt0-x243.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fTJH28Gs"; dkim-atps=neutral Received: from mail-qt0-x243.google.com (mail-qt0-x243.google.com [IPv6:2607:f8b0:400d:c0d::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3zQLF02v3xzF0X6 for ; Tue, 23 Jan 2018 05:53:56 +1100 (AEDT) Received: by mail-qt0-x243.google.com with SMTP id s3so23459225qtb.10 for ; Mon, 22 Jan 2018 10:53:56 -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=NDlRgXUgQ/24rz0oxyDO0fvk5azmBflCOGwwIeVBd53x4xNpyFIIdTuhk4wzdkZfHO cdSXhoVDsL/q6J3rddDxAkRcJbbGi3wgpoRLxNGt7XcjWAXmy7iboct8+PCDZU8O7NQD aZF5EVyt0OrCTSW612IF23L+ZW0S70UgwgfZ7ssJ7SAgSEWBrH+fWoACfJNVU/uNu1uD PXG7OVJaiwOpODvDH068pdjpfUmF5gxwETR8Sq5DgHJ9xHWBAI9JFNKeRT6LY/CMCLSX bEqwQjWrjkSaOR93BjacGhOxwmbEB0aq+8iri4jQb5/FJkb5mHdKlELYrVnEFNi53JAs DgwA== X-Gm-Message-State: AKwxytc3eCv2RdxJeVvPEw72x9wtyN7eK5pDLd6/uFLybArIyfqKyyBg sooViWvw1AU0gQMdCmZZA2I= X-Google-Smtp-Source: AH8x227YsLL8aHkUjfsUb+UApna1KmJi/lciZRcF7ElayEfyxwdxTKQTTGYXdX+ONnMgggTETISRMQ== 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 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> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, ebiederm@xmission.com, arnd@arndb.de, linux-doc@vger.kernel.org, x86@kernel.org, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linuxram@us.ibm.com, mhocko@kernel.org, linux-mm@kvack.org, mingo@redhat.com, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, bauerman@linux.vnet.ibm.com, akpm@linux-foundation.org, linuxppc-dev@lists.ozlabs.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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)