From patchwork Fri Feb 1 20:03:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10793665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06C8814E1 for ; Fri, 1 Feb 2019 20:04:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9273330BE for ; Fri, 1 Feb 2019 20:04:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD01032E44; Fri, 1 Feb 2019 20:04:38 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79E97330C3 for ; Fri, 1 Feb 2019 20:04:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730737AbfBAUEi (ORCPT ); Fri, 1 Feb 2019 15:04:38 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:36285 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730654AbfBAUEi (ORCPT ); Fri, 1 Feb 2019 15:04:38 -0500 Received: by mail-pl1-f193.google.com with SMTP id g9so3755547plo.3 for ; Fri, 01 Feb 2019 12:04:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=1Nqq7VAAKEOUHsQviQI8Zx2ixgo/VkLTI3lblB/sV2E=; b=Eg9Y/SA26LISZRb5iEXR/RygJdaG4LvGeYmlvXoEMi2cwdRRnuYRCL/BIYai/p/m3S eTF7NycA8uB+k4GFwGpnpAEKJeUEFbKeMfZRvCPmzOMq54ZfJRPnl13USI3YMCICeLTS V95DxohCVmUyBUYA3zMrmCs06cbzX6n+he7Ps/iG1hUup6qkWzs3xGa1RSSbmKN3Ya6o /K+BWZVSGJQcVblPwpTWW8ycm2pur8aIfqQeys8CuPdyqwGbcinujFL9Q7mOULkhKscM QrVFQOJjEQBUn4ZckR6+qR/i7nMZk0F1g/DDhyZoNAynGeoQqmkCIXxYlNb+tD9RVRaH tG2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=1Nqq7VAAKEOUHsQviQI8Zx2ixgo/VkLTI3lblB/sV2E=; b=EOsAU4BoiuiPKg9XsMBJnH4pNpDtLXLwKVGKrjFB7sHExeiePTeQdZHrsHkMy7DGH/ Hp2MfsKWIcOmdYJ0opagWCwIMifCFYiwi0CJnWUcv/uo1w4Ro9DJFSrtlrvGRfgRKiE3 LC4Trvm7qXqDQnl1Z4j49tGUrwpOMsUa4mEGTxi0YXolq5RrkTNJOz/tGpWdP6PZCixS +5wZ9U8bIZ2SF4wARhDjQbOCaup/AVyR6Xmio5dpTjjOFxQ2N8dv3pG36G49TzU3Ie7m vGpV3WnRZWI5UHVSfU11AuSXQyJQ+AvC3VZD3Hu/pEPdx4wGb88i3wO3tsbwKK5Oxeq7 ehug== X-Gm-Message-State: AJcUukcrqWvJ9a0kfNntCJCSuzTGrPRstV3yG+fw0KWNWTV3O/l9SNuz 4gIP5hO8GHUdjvgoBl6BYcpT8go= X-Google-Smtp-Source: ALg8bN7c8212Ck3JcngVc38/RHz/5tWBgEif4+fLL54fi4/GSsHc5UOnJJtqPTK1jfR79pWdPxlRiA== X-Received: by 2002:a17:902:2969:: with SMTP id g96mr40724394plb.295.1549051476042; Fri, 01 Feb 2019 12:04:36 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:0:a18e:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id x11sm24247451pfe.72.2019.02.01.12.04.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Feb 2019 12:04:35 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 10/23] CIFS: Mask signals during sock_sendmsg() Date: Fri, 1 Feb 2019 12:03:59 -0800 Message-Id: <1549051452-5968-12-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> References: <1549051452-5968-1-git-send-email-pshilov@microsoft.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We don't want to break a session if we receive a signal during sending a packet through the network. Fix it by masking signals during execution of sock_sendmsg() and then checking for pending signals. Signed-off-by: Pavel Shilovsky Signed-off-by: Steve French --- fs/cifs/transport.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 53532bd..eff9e3c 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "cifspdu.h" #include "cifsglob.h" #include "cifsproto.h" @@ -176,6 +177,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, int rc = 0; int retries = 0; struct socket *ssocket = server->ssocket; + sigset_t mask, oldmask; *sent = 0; @@ -189,6 +191,28 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, smb_msg->msg_flags = MSG_NOSIGNAL; while (msg_data_left(smb_msg)) { + if (signal_pending(current)) { + /* Should we stop sending if we receive SIG_KILL? */ + if (__fatal_signal_pending(current)) + cifs_dbg(FYI, "SIG_KILL signal is pending\n"); + + /* It is safe to return if we haven't sent anything */ + if (*sent == 0) { + cifs_dbg(FYI, "signal is pending before sending any data\n"); + return -EINTR; + } + } + + /* + * We should not allow signals to interrupt the network send + * because any partial send will cause session reconnects thus + * increasing latency of system calls and overload a server + * with unnecessary requests. + */ + + sigfillset(&mask); + sigprocmask(SIG_BLOCK, &mask, &oldmask); + /* * If blocking send, we try 3 times, since each can block * for 5 seconds. For nonblocking we have to try more @@ -208,20 +232,23 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, * reconnect which may clear the network problem. */ rc = sock_sendmsg(ssocket, smb_msg); + + sigprocmask(SIG_SETMASK, &oldmask, NULL); + if (rc == -EAGAIN) { retries++; if (retries >= 14 || (!server->noblocksnd && (retries > 2))) { cifs_dbg(VFS, "sends on sock %p stuck for 15 seconds\n", ssocket); - return -EAGAIN; + return signal_pending(current) ? -EINTR : rc; } msleep(1 << retries); continue; } if (rc < 0) - return rc; + return signal_pending(current) ? -EINTR : rc; if (rc == 0) { /* should never happen, letting socket clear before @@ -235,7 +262,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg, *sent += rc; retries = 0; /* in case we get ENOSPC on the next send */ } - return 0; + return signal_pending(current) ? -EINTR : 0; } unsigned long