From patchwork Mon Mar 23 21:22:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1260316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=IITPmKR3; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48mS5l4x9Kz9sR4 for ; Tue, 24 Mar 2020 08:22:51 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 6B9608681B; Mon, 23 Mar 2020 21:22:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id z65JU7QUSUUL; Mon, 23 Mar 2020 21:22:48 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 6DFB5866F0; Mon, 23 Mar 2020 21:22:48 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 635ADC1AE2; Mon, 23 Mar 2020 21:22:48 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id F0F67C0177 for ; Mon, 23 Mar 2020 21:22:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id ECFFA866FC for ; Mon, 23 Mar 2020 21:22:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PmyxGajNuiAM for ; Mon, 23 Mar 2020 21:22:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by whitealder.osuosl.org (Postfix) with ESMTPS id E7942866F0 for ; Mon, 23 Mar 2020 21:22:45 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id 142so2622438pgf.11 for ; Mon, 23 Mar 2020 14:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=JwjF4qrL87Y0moMt4XvvYT5ZxsBKw2nSJNW8kstcpq0=; b=IITPmKR3airU28GIm4iXLmd7lXqQYbFR+RQrGz2wpDyyLZEMQ3DC8UykyTR2962FHc Y7W8hEocdWY8QeMkJgoQwJNXYA13mfCd1pg1IVibo2KkaAkFBrYhATqzXWEfs8/ZuFjF bnUF6C4dd+OJLYHVmqvN4AKNsmzBpibZelCahuGx8doHrITi3HXQ++wGaodOoxaNUEv2 854VJ1AW7mjjIGoLwdazKhawGF4mNjECvzy8NJbPWxULOaV+Y4iTA+1+2EXR1iSFLmjQ 7wLb7W4TN4/4TecQalS5MhbI+BThsOfegwVsLwJCIUnnWWftQGYgBNHN2aczXXGJsnQw PX0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JwjF4qrL87Y0moMt4XvvYT5ZxsBKw2nSJNW8kstcpq0=; b=A0Y601+MrH65ttX0XJ3DzEhvXQh5WpjeQfy6+8b3moDCDPfmdEKBKvbpFH5eahe53z IorfkN7G1vb45O/zwkU7Cr2zWQhfiJ4yNNXBivAN+ukFTomrJiGfVCKG8pKff/dT8GkB 9WBckQtgB0jsFMfZBL3lVxk5ijvA8tX1uDm/YeBcBnpStyDp2DVdoQ/A4ur/glAAFuRo Yg5sv2Q0Rj3sGB62KoDe/OUjzYuTTbaM7529WO9WB1MQo/yZZDjKNkkw+6hc2UVEmt0d m7lPXVADOj0ZR8waSm7AMizrK1/b/RB45+3ShrxD9rDjq+nXxrvyUtRT6KNS3XGsnhFh XUsA== X-Gm-Message-State: ANhLgQ08LhRmWESJiBhTG8PlXR8c45z931DLJFOMgYY1KhArXzkSnP0c Lrlw1GewK+86oUnkC6QEGknr7KlG X-Google-Smtp-Source: ADFU+vtkhn9C/DLJDndqIw5J2ot5nCIXyGYHYp4Y9/YUnkIR+LlE0HO4w+Fnnf0bGYaFlP5StHUT5A== X-Received: by 2002:aa7:947c:: with SMTP id t28mr24615081pfq.239.1584998565016; Mon, 23 Mar 2020 14:22:45 -0700 (PDT) Received: from sc9-mailhost2.vmware.com (c-76-21-95-192.hsd1.ca.comcast.net. [76.21.95.192]) by smtp.gmail.com with ESMTPSA id s98sm460451pjb.46.2020.03.23.14.22.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Mar 2020 14:22:44 -0700 (PDT) From: William Tu To: dev@openvswitch.org Date: Mon, 23 Mar 2020 14:22:17 -0700 Message-Id: <1584998537-115892-1-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH] fatal-signal: Skip acquiring log fd lock. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Due to not acquiring lock, clang reports: lib/vlog.c:618:12: error: reading variable 'log_fd' requires holding mutex 'log_file_mutex' [-Werror,-Wthread-safety-analysis] return log_fd; The patch fixes by skipping it using OVS_NO_THREAD_SAFETY_ANALYSIS. Tested-at: https://travis-ci.org/github/williamtu/ovs-travis/builds/666051210 Fixex: ecd4a8fcdff2 ("fatal-signal: Log backtrace when no monitor daemon.") Signed-off-by: William Tu --- lib/fatal-signal.c | 55 +++++++++++++++++++++++++++++++++--------------------- lib/vlog.c | 1 + 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index 4965c1ae82c0..44c53e5465a0 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -158,13 +158,43 @@ fatal_signal_add_hook(void (*hook_cb)(void *aux), void (*cancel_cb)(void *aux), } #ifdef HAVE_UNWIND -/* Send the backtrace buffer to monitor thread. +/* Write the backtrace to log file. + * + * Use OVS_NO_THREAD_SAFETY_ANALYSIS to skip acquiring the lock + * of 'vlog_get_fd()'. + */ +static inline void +send_backtrace_to_logfd(struct unw_backtrace *unw_bt, const int dep) + OVS_NO_THREAD_SAFETY_ANALYSIS +{ + char str[] = "SIGSEGV detected, backtrace:\n"; + + if (vlog_get_fd() < 0) { + return; + } + + ignore(write(vlog_get_fd(), str, strlen(str))); + + for (int i = 0; i < dep; i++) { + char line[64]; + + /* snprintf() is not async-signal-safe. */ + snprintf(line, 64, "0x%016"PRIxPTR" <%s+0x%"PRIxPTR">\n", + unw_bt[i].ip, + unw_bt[i].func, + unw_bt[i].offset); + ignore(write(vlog_get_fd(), line, strlen(line))); + } +} + +/* Send the backtrace buffer to main or monitor thread. * * Note that this runs in the signal handling context, any system * library functions used here must be async-signal-safe. */ static inline void -send_backtrace_to_monitor(void) { +send_backtrace_to_monitor(void) +{ /* volatile added to prevent a "clobbered" error on ppc64le with gcc */ volatile int dep; struct unw_backtrace unw_bt[UNW_MAX_DEPTH]; @@ -192,26 +222,9 @@ send_backtrace_to_monitor(void) { dep * sizeof(struct unw_backtrace))); } else { /* Since there is no monitor daemon running, write backtrace - * in current process. This is not asyn-signal-safe due to - * use of snprintf(). + * in current process. This is not asyn-signal-safe. */ - char str[] = "SIGSEGV detected, backtrace:\n"; - - if (vlog_get_fd() < 0) { - return; - } - - ignore(write(vlog_get_fd(), str, strlen(str))); - - for (int i = 0; i < dep; i++) { - char line[64]; - - snprintf(line, 64, "0x%016"PRIxPTR" <%s+0x%"PRIxPTR">\n", - unw_bt[i].ip, - unw_bt[i].func, - unw_bt[i].offset); - ignore(write(vlog_get_fd(), line, strlen(line))); - } + send_backtrace_to_logfd(unw_bt, dep); } } #else diff --git a/lib/vlog.c b/lib/vlog.c index 502b33fc831e..0ea57abadd9e 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -614,6 +614,7 @@ vlog_set_syslog_target(const char *target) int vlog_get_fd(void) + OVS_REQUIRES(log_file_mutex) { return log_fd; }