From patchwork Wed May 9 17:13:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 10390239 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 28DA160236 for ; Wed, 9 May 2018 17:18:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 181862851A for ; Wed, 9 May 2018 17:18:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C2D12851E; Wed, 9 May 2018 17:18:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B4852851A for ; Wed, 9 May 2018 17:18:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F1186B0540; Wed, 9 May 2018 13:18:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8A13D6B0541; Wed, 9 May 2018 13:18:52 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 741206B0542; Wed, 9 May 2018 13:18:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 235306B0540 for ; Wed, 9 May 2018 13:18:52 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id t5-v6so4066207ply.13 for ; Wed, 09 May 2018 10:18:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:to:cc :from:date:references:in-reply-to:message-id; bh=d2fepnHBqsj4MJn9HXARK/Piz8Px4mICLmtyP93drbg=; b=rkV4KPhwgmEVQeiHzjw4DHaNZ8rMwM9pqW0hAqabNYIvPkpnph8pYNedyNruLblprm GTQSllBcUHaT+LTOz4bGncFccUfdpF5NYdl2afSNYN8V8c76OGQB2ilqq/mAkxkyTqQL JGnxLVhoLMTr+/GDeLaoeLqAWZkP8JQVHs2tUSNLAv7/bRXgGK4y3Wk0XxVrTmUazcXy QpxUn+hsfMYoYL17LjV4nw6njFsuEnuAQGoUhH2zXOFLPxoCTEOK9rLX6Is8J1JLZihJ dsw2DXr3jM9Au9J8IRfeECIYe+tGZ02+LmPd9/gtlhf4GTPKgDBbJjjnt4tU13X+sEk+ vVOw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com X-Gm-Message-State: ALQs6tAjJ5qgNZgWT1jbPnqFad+ncxPQ0jeTFIQ31I9Gebq6k8ErH2Q2 DfGAU/sbS0YUQgee+aN+Fw0dvy7vDZJrsrpKUeY+Zs1bOpiOVbPbbUDOulWShnbD5kqL4qwa3Rq ALV40aHHfamxKCkcESVKGiaGxuVGRDrfBMt4BlL2hsgHyO2Td0/VCHdVNYBylm3Kzdg== X-Received: by 2002:a63:7c01:: with SMTP id x1-v6mr36442529pgc.286.1525886331797; Wed, 09 May 2018 10:18:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo8c+rquKlP0iijj3Yg6Yhb2JkqPJHTyfOvqfIP0npi9lY8emDdANLXDTZEje/kZi+ITLpd X-Received: by 2002:a63:7c01:: with SMTP id x1-v6mr36442500pgc.286.1525886331016; Wed, 09 May 2018 10:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525886330; cv=none; d=google.com; s=arc-20160816; b=Bx/04ECMeTFYt7hWc2XgqzbvJ72GBCJ+JGubLvyrlHyV8NWNEsKmF+im/rGzoAAtY9 S5ovEls/OZP4b124E9clI+swm1Hpd+QmISRXArhxOwXm19eq4tVMz2KMYPwGLQ0J6HVC 1yAS6pwFlYR/Aoj1X5+awL1GnSmcjAYrpuhsTNJZniIp9fHyV5Hc6ZACO1iE/w19GbyO aF4zQZQ8UyhURwtAwOWYxj5zh8bOi3WiUP3x/NfIKOdD9zt7OF1lCrBKHHWn8D4DKVEy rjQ1hIN3YiQ520qnA0dfJCDrtGqh3+Ra+ojDRlba/lnTmNWmgd7Os/odMq5jtjRFWQCV QdOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:in-reply-to:references:date:from:cc:to:subject :arc-authentication-results; bh=d2fepnHBqsj4MJn9HXARK/Piz8Px4mICLmtyP93drbg=; b=DHrF/nF8BetWzhFbWvUSFj0dDrLa2J6T8gD6jhkdrj1ywgiKHInWqALOamm+cAYWKe 2lUZRMesaxkOGeRwjaaxNpWKgzj62z73FQIXDwTdb1fFnFtW2/kB1QPSAd7LiDyDAmDu S+iCx67QqJ4kEAtZ75220eMWAfDR9/xKiYgi6lb09UTbKGqkNfwwMm6Wfj0exkjyI2S8 g264Q6ROeqcBT5cUCV5lS8Ou/TfVEV5E7V28Svk1u3Zkg2F6ZtmDoewQ3RHKX+srCvJG BnPnVHfzJg5I/uhTH6OpinOS0DxaYbKInWVKYYv4KqZDHwBvfPOiPeyqQz+yYi1VPSv9 tP+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com Received: from mga05.intel.com (mga05.intel.com. [192.55.52.43]) by mx.google.com with ESMTPS id o9-v6si15900013pgn.199.2018.05.09.10.18.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 10:18:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 192.55.52.43 as permitted sender) client-ip=192.55.52.43; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 10:18:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,382,1520924400"; d="scan'208";a="52900932" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.119]) by fmsmga004.fm.intel.com with ESMTP; 09 May 2018 10:18:49 -0700 Subject: [PATCH 04/13] x86/pkeys/selftests: Avoid printf-in-signal deadlocks To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Dave Hansen , linuxram@us.ibm.com, tglx@linutronix.de, dave.hansen@intel.com, mpe@ellerman.id.au, mingo@kernel.org, akpm@linux-foundation.org, shuah@kernel.org From: Dave Hansen Date: Wed, 09 May 2018 10:13:44 -0700 References: <20180509171336.76636D88@viggo.jf.intel.com> In-Reply-To: <20180509171336.76636D88@viggo.jf.intel.com> Message-Id: <20180509171344.C53FD2F3@viggo.jf.intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Hansen printf() and friends are unusable in signal handlers. They deadlock. The pkey selftest does not do any normal printing in signal handlers, only extra debugging. So, just print the format string so we get *some* output when debugging. Signed-off-by: Dave Hansen Cc: Ram Pai Cc: Thomas Gleixner Cc: Dave Hansen Cc: Michael Ellermen Cc: Ingo Molnar Cc: Andrew Morton Cc: Shuah Khan --- b/tools/testing/selftests/x86/pkey-helpers.h | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff -puN tools/testing/selftests/x86/pkey-helpers.h~pkeys-selftests-avoid-print-in-signal-deadlocks tools/testing/selftests/x86/pkey-helpers.h --- a/tools/testing/selftests/x86/pkey-helpers.h~pkeys-selftests-avoid-print-in-signal-deadlocks 2018-05-09 09:20:19.738698404 -0700 +++ b/tools/testing/selftests/x86/pkey-helpers.h 2018-05-09 09:20:19.742698404 -0700 @@ -26,30 +26,26 @@ static inline void sigsafe_printf(const { va_list ap; - va_start(ap, format); if (!dprint_in_signal) { + va_start(ap, format); vprintf(format, ap); + va_end(ap); } else { int ret; - int len = vsnprintf(dprint_in_signal_buffer, - DPRINT_IN_SIGNAL_BUF_SIZE, - format, ap); /* - * len is amount that would have been printed, - * but actual write is truncated at BUF_SIZE. + * No printf() functions are signal-safe. + * They deadlock easily. Write the format + * string to get some output, even if + * incomplete. */ - if (len > DPRINT_IN_SIGNAL_BUF_SIZE) - len = DPRINT_IN_SIGNAL_BUF_SIZE; - ret = write(1, dprint_in_signal_buffer, len); + ret = write(1, format, strlen(format)); if (ret < 0) - abort(); + exit(1); } - va_end(ap); } #define dprintf_level(level, args...) do { \ if (level <= DEBUG_LEVEL) \ sigsafe_printf(args); \ - fflush(NULL); \ } while (0) #define dprintf0(args...) dprintf_level(0, args) #define dprintf1(args...) dprintf_level(1, args)