From patchwork Wed Jan 23 21:10:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 10777899 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 D0C466C2 for ; Wed, 23 Jan 2019 21:11:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C12032D7AB for ; Wed, 23 Jan 2019 21:11:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B57442D7B2; Wed, 23 Jan 2019 21:11:07 +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 57E502D7AB for ; Wed, 23 Jan 2019 21:11:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbfAWVLH (ORCPT ); Wed, 23 Jan 2019 16:11:07 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37233 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfAWVLG (ORCPT ); Wed, 23 Jan 2019 16:11:06 -0500 Received: by mail-pg1-f195.google.com with SMTP id c25so1636242pgb.4 for ; Wed, 23 Jan 2019 13:11:06 -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=Sx9H6OIv2BWkH1Rt0bikKAfYWn3SmyLndmDST7LdEc0=; b=EGCKCEIG6tzWFTuAJw+HgQRabMmAzwS22CP8r/awcRVspLbKy/TrANnafq0QBTsMe8 7dCdxz4HvWc4DXVy+45q29RQ8SCu0AzltPsSGQYYqqnWCiViWf2VuV6+I4C156l3q0qv mz5uEAh/A+Dt5coZ+tbczyAYB3TSi33eZ7vM/oLWJAwjbFm+FCOqNlxG2bh8Flm81s58 ySBGSQtR5vKLBJYx8+kiMBIlf8PY1T2CI+A3xMmmeYeY/+IlFP3uDSvxfPzrS11/dwn4 gjjuIaHkFiqY5W3j11akw10N5eJnlpx+Hai2w2qGUXgAMV4vBTeviybZxLpxkrzFyDGA npWg== 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=Sx9H6OIv2BWkH1Rt0bikKAfYWn3SmyLndmDST7LdEc0=; b=Z6sMFjkkQmlRUFmFBmjD1i5c05l9H/SPWJAMmGW42FNwinRpk2M5/2n9GBsrqdqaJX na1F3ooh/EKPUjxrL+Q9G2+st1LUzFe5LI9p952CNNw0ICb6fpwpqx8TWzjeCv/5KK66 gicS71xjv0RqjeVb2FJN3Sn/hGxk0SfXpvWqAysccdYWixQip3X+m3BLC78qd+1aGnnu goL8L7dsUq7HIi9gfY5pjC7ZI0aZQKk2+EAODZpc25LKX3g2AovUXl8vTrhSa1weiMow qRGzrFBPtyc5glsRJ2YTjn7L6pS+URXNL3MpKQMkUE/i9tfUxxen+rhigMkJPiXoG2hp YfHA== X-Gm-Message-State: AJcUukeQi1xcfB7KO2QSWU5SZKsUXy86uhSJPAJ54XQvtIA659NpQqat Ep6kSfPQvU0e6dac7ffWalHYgh4= X-Google-Smtp-Source: ALg8bN6szVaNsTLWV18bwn59Yeo/OG704u/smv6J7vQ5MZxKR7ld7bVpLLtbAvyyTRjQENkPufiw6g== X-Received: by 2002:a62:c505:: with SMTP id j5mr3612276pfg.149.1548277865327; Wed, 23 Jan 2019 13:11:05 -0800 (PST) Received: from ubuntu-vm.corp.microsoft.com ([2001:4898:80e8:f:a17f:4e9f:6b7c:507d]) by smtp.gmail.com with ESMTPSA id n73sm28063714pfj.148.2019.01.23.13.11.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jan 2019 13:11:04 -0800 (PST) From: Pavel Shilovsky X-Google-Original-From: Pavel Shilovsky To: linux-cifs@vger.kernel.org, Steve French , Ronnie Sahlberg Subject: [PATCH 10/15] CIFS: Mask signals during sock_sendmsg() Date: Wed, 23 Jan 2019 13:10:40 -0800 Message-Id: <1548277845-6746-11-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548277845-6746-1-git-send-email-pshilov@microsoft.com> References: <1548277845-6746-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 --- 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