Received: by 10.223.185.116 with SMTP id b49csp1379334wrg; Wed, 21 Feb 2018 17:58:40 -0800 (PST) X-Google-Smtp-Source: AH8x227Ek33ASbCVUy3tp337JJiDjwTGTnGhUmjzsDZdX9FZs7QUDxG+46FbxbzneeD77ueOyrke X-Received: by 10.101.99.133 with SMTP id h5mr4156521pgv.381.1519264720717; Wed, 21 Feb 2018 17:58:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519264720; cv=none; d=google.com; s=arc-20160816; b=zJ1oQxzFVcLZcV4Rxqt4eABjevkbwlugWh5bmr6WIAFLl4vc4lzl8OBZf4+rK1zN9F oHpnH4MGO0VnK19D86h7Cnxzqqyy8p7I/2hzKhYkphqOtVUYnVOGr0ec5rf+JaxZVKAU sRZnbsioHi7o75D99Mv0SYIUrGpA0201ghahqBLvEDi7VlhB4RfyuRBKZbo2OhsrVBCm Qw5rqv5+MAY/9OEVJwUdPRLw3eLEFFkQwxFH/JnFKhjCtyLnaiaGhnl8sU8pQ/txYg2W 1WG+tOxCe3OV9BNhOsiECjNUIO2xhi61Nq2SSsBMIj68ILScLvFPSsN/aibcBk6MuCks fjjw== 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=KjyUUCOeeX7U2vM2TshjPmb7xIBZmrEfAs2w6J7WOKM=; b=yqePPfIyqkGriJpQebvg9wFd1ijsPorE63QGhhfeVtVNX32lh1lu29QhOfnUcjsua5 aAUYDuPFP+r/0cqCQw3E0HRz7PQJWC+DygC7QrSqaPMpYUWu3fMUkz3N6JIwz8DVCk4o zXTEJfyuf3kT+95cifPsy7IE/EiZYEqHtfkL0wW4U6WdYxKjeDxRmU0R4Xw5A836R/8u YqwLPAn73/vuhgMx6P6G9hSPUrX5JakoTShDFzuten5tfdcG/yJMOSW5cvs0F/qw2NQk J8Hl4ysLh+tUD318BMaRNTqpfMXCc43P8v+z2pOngs2fZWlBhp3UIToIFzXmyZ/Puwwd kmJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=AaK3Derw; 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 r13-v6si692249plj.141.2018.02.21.17.58.26; Wed, 21 Feb 2018 17:58:40 -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=AaK3Derw; 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 S1752255AbeBVB5g (ORCPT + 99 others); Wed, 21 Feb 2018 20:57:36 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:33136 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752210AbeBVB5c (ORCPT ); Wed, 21 Feb 2018 20:57:32 -0500 Received: by mail-qk0-f193.google.com with SMTP id f25so4649036qkm.0; Wed, 21 Feb 2018 17:57:31 -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=KjyUUCOeeX7U2vM2TshjPmb7xIBZmrEfAs2w6J7WOKM=; b=AaK3DerwP2O89SqSaljgVG4/YUnJte55khcaEjgVNPLBW3enVabkhxqiR8eLPFgC8p KEkKpri0Uv3IiVWcoiN/kMhMEJWrfzg+cY2HNn6lcau9NZfyePVxQGEfrA/00oH+Em4Z iosHol+u2OO6pOApI5S+4Ptx0YZVP6moH+Q0TQvPHHj1eWLbbtvk0cqXJL7phHS7ff11 gEFz6oD+fG2dGUQFBw9D10QelyYIJ2OmLO2wMy0A9FOVNOBi7S1lis92d2I6O6mWOTiq CHXWmcFY2hqWejJIPvmi47t0CfpMOOogKy+eTRT2kcqOZHIzSTqFuzuvEMeYrDWZHKXx 0ksg== 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=KjyUUCOeeX7U2vM2TshjPmb7xIBZmrEfAs2w6J7WOKM=; b=QdwpHDAXdR47/Bdto/pUDQjEFmh4OS/kRYYAbdZgsFvUC2m0yoLS38wnqECbkt/hF4 mPC13q+M3eIhBqAVIHNqx6Xl1nytTzMpfkZ00iNFEfgrJE707AMsImn951gLsXHcuLU7 JIXVF/vFT/2YJak23rxci49hITyqNP5tQF63OF+iEPf2X8vjM8ft/oB3nPkeMmr3zzq/ bNEKOCdGGV8awVbaKSnGmCDmPw00TPvzREgAv7IgbFBhXxEwOUAgqNDMHeVokx1J+FZG xMZVzf/GEBhadHytgUlDGJ4gGCl5cT020KnoT4jkU/9PjUswn7Jrsvd+Wjice/WI8XqA IrYQ== X-Gm-Message-State: APf1xPD+UyvZpELn6iRwjdhK2qMfQJh88ecZgfZS6phZFt2i33UXqIJp ur/Q/HHBXQ3dP22t8mbRDFw= X-Received: by 10.55.134.135 with SMTP id i129mr7882592qkd.177.1519264651290; Wed, 21 Feb 2018 17:57:31 -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 n29sm14182630qtf.18.2018.02.21.17.57.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 17:57:30 -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 v12 22/22] selftests/vm: Fix deadlock in protection_keys.c Date: Wed, 21 Feb 2018 17:55:41 -0800 Message-Id: <1519264541-7621-23-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1519264541-7621-1-git-send-email-linuxram@us.ibm.com> References: <1519264541-7621-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. cc: Dave Hansen cc: Florian Weimer 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 67f9b0f..7240598 100644 --- a/tools/testing/selftests/vm/pkey-helpers.h +++ b/tools/testing/selftests/vm/pkey-helpers.h @@ -128,7 +128,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