From: Luis Henriques <luis.henriques@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
kernel-team@lists.ubuntu.com
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>,
Luis Henriques <luis.henriques@canonical.com>
Subject: [PATCH 3.5 25/90] SUNRPC: Fix a data corruption issue when retransmitting RPC calls
Date: Thu, 5 Dec 2013 17:35:07 +0000 [thread overview]
Message-ID: <1386264972-5399-26-git-send-email-luis.henriques@canonical.com> (raw)
In-Reply-To: <1386264972-5399-1-git-send-email-luis.henriques@canonical.com>
3.5.7.27 -stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <Trond.Myklebust@netapp.com>
commit a6b31d18b02ff9d7915c5898c9b5ca41a798cd73 upstream.
The following scenario can cause silent data corruption when doing
NFS writes. It has mainly been observed when doing database writes
using O_DIRECT.
1) The RPC client uses sendpage() to do zero-copy of the page data.
2) Due to networking issues, the reply from the server is delayed,
and so the RPC client times out.
3) The client issues a second sendpage of the page data as part of
an RPC call retransmission.
4) The reply to the first transmission arrives from the server
_before_ the client hardware has emptied the TCP socket send
buffer.
5) After processing the reply, the RPC state machine rules that
the call to be done, and triggers the completion callbacks.
6) The application notices the RPC call is done, and reuses the
pages to store something else (e.g. a new write).
7) The client NIC drains the TCP socket send buffer. Since the
page data has now changed, it reads a corrupted version of the
initial RPC call, and puts it on the wire.
This patch fixes the problem in the following manner:
The ordering guarantees of TCP ensure that when the server sends a
reply, then we know that the _first_ transmission has completed. Using
zero-copy in that situation is therefore safe.
If a time out occurs, we then send the retransmission using sendmsg()
(i.e. no zero-copy), We then know that the socket contains a full copy of
the data, and so it will retransmit a faithful reproduction even if the
RPC call completes, and the application reuses the O_DIRECT buffer in
the meantime.
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
---
net/sunrpc/xprtsock.c | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 79064471..31f981d 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -390,8 +390,10 @@ static int xs_send_kvec(struct socket *sock, struct sockaddr *addr, int addrlen,
return kernel_sendmsg(sock, &msg, NULL, 0, 0);
}
-static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned int base, int more)
+static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned int base, int more, bool zerocopy)
{
+ ssize_t (*do_sendpage)(struct socket *sock, struct page *page,
+ int offset, size_t size, int flags);
struct page **ppage;
unsigned int remainder;
int err, sent = 0;
@@ -400,6 +402,9 @@ static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned i
base += xdr->page_base;
ppage = xdr->pages + (base >> PAGE_SHIFT);
base &= ~PAGE_MASK;
+ do_sendpage = sock->ops->sendpage;
+ if (!zerocopy)
+ do_sendpage = sock_no_sendpage;
for(;;) {
unsigned int len = min_t(unsigned int, PAGE_SIZE - base, remainder);
int flags = XS_SENDMSG_FLAGS;
@@ -407,7 +412,7 @@ static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned i
remainder -= len;
if (remainder != 0 || more)
flags |= MSG_MORE;
- err = sock->ops->sendpage(sock, *ppage, base, len, flags);
+ err = do_sendpage(sock, *ppage, base, len, flags);
if (remainder == 0 || err != len)
break;
sent += err;
@@ -428,9 +433,10 @@ static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned i
* @addrlen: UDP only -- length of destination address
* @xdr: buffer containing this request
* @base: starting position in the buffer
+ * @zerocopy: true if it is safe to use sendpage()
*
*/
-static int xs_sendpages(struct socket *sock, struct sockaddr *addr, int addrlen, struct xdr_buf *xdr, unsigned int base)
+static int xs_sendpages(struct socket *sock, struct sockaddr *addr, int addrlen, struct xdr_buf *xdr, unsigned int base, bool zerocopy)
{
unsigned int remainder = xdr->len - base;
int err, sent = 0;
@@ -458,7 +464,7 @@ static int xs_sendpages(struct socket *sock, struct sockaddr *addr, int addrlen,
if (base < xdr->page_len) {
unsigned int len = xdr->page_len - base;
remainder -= len;
- err = xs_send_pagedata(sock, xdr, base, remainder != 0);
+ err = xs_send_pagedata(sock, xdr, base, remainder != 0, zerocopy);
if (remainder == 0 || err != len)
goto out;
sent += err;
@@ -561,7 +567,7 @@ static int xs_local_send_request(struct rpc_task *task)
req->rq_svec->iov_base, req->rq_svec->iov_len);
status = xs_sendpages(transport->sock, NULL, 0,
- xdr, req->rq_bytes_sent);
+ xdr, req->rq_bytes_sent, true);
dprintk("RPC: %s(%u) = %d\n",
__func__, xdr->len - req->rq_bytes_sent, status);
if (likely(status >= 0)) {
@@ -617,7 +623,7 @@ static int xs_udp_send_request(struct rpc_task *task)
status = xs_sendpages(transport->sock,
xs_addr(xprt),
xprt->addrlen, xdr,
- req->rq_bytes_sent);
+ req->rq_bytes_sent, true);
dprintk("RPC: xs_udp_send_request(%u) = %d\n",
xdr->len - req->rq_bytes_sent, status);
@@ -688,6 +694,7 @@ static int xs_tcp_send_request(struct rpc_task *task)
struct rpc_xprt *xprt = req->rq_xprt;
struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
struct xdr_buf *xdr = &req->rq_snd_buf;
+ bool zerocopy = true;
int status;
xs_encode_stream_record_marker(&req->rq_snd_buf);
@@ -695,13 +702,20 @@ static int xs_tcp_send_request(struct rpc_task *task)
xs_pktdump("packet data:",
req->rq_svec->iov_base,
req->rq_svec->iov_len);
+ /* Don't use zero copy if this is a resend. If the RPC call
+ * completes while the socket holds a reference to the pages,
+ * then we may end up resending corrupted data.
+ */
+ if (task->tk_flags & RPC_TASK_SENT)
+ zerocopy = false;
/* Continue transmitting the packet/record. We must be careful
* to cope with writespace callbacks arriving _after_ we have
* called sendmsg(). */
while (1) {
status = xs_sendpages(transport->sock,
- NULL, 0, xdr, req->rq_bytes_sent);
+ NULL, 0, xdr, req->rq_bytes_sent,
+ zerocopy);
dprintk("RPC: xs_tcp_send_request(%u) = %d\n",
xdr->len - req->rq_bytes_sent, status);
--
1.8.3.2
next prev parent reply other threads:[~2013-12-05 17:57 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-05 17:34 [3.5.y.z extended stable] Linux 3.5.7.27 stable review Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 01/90] ACPICA: Interpreter: Fix Store() when implicit conversion is not possible Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 02/90] ACPICA: DeRefOf operator: Update to fully resolve FieldUnit and BufferField refs Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 03/90] ACPICA: Return error if DerefOf resolves to a null package element Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 04/90] ACPICA: Fix for a Store->ArgX when ArgX contains a reference to a field Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 05/90] aacraid: prevent invalid pointer dereference Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 06/90] libertas: potential oops in debugfs Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 07/90] ARM: sa11x0/assabet: ensure CS2 is configured appropriately Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 08/90] dm: allocate buffer for messages with small number of arguments using GFP_NOIO Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 09/90] ext4: avoid bh leak in retry path of ext4_expand_extra_isize_ea() Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 10/90] drm/radeon/si: fix define for MC_SEQ_TRAIN_WAKEUP_CNTL Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 11/90] drm/ttm: Handle in-memory region copies Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 12/90] drm/ttm: Fix ttm_bo_move_memcpy Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 13/90] drm/ttm: Fix memory type compatibility check Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 14/90] PM / hibernate: Avoid overflow in hibernate_preallocate_memory() Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 15/90] mtd: nand: hack ONFI for non-power-of-2 dimensions Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 16/90] mtd: map: fixed bug in 64-bit systems Luis Henriques
2013-12-05 17:34 ` [PATCH 3.5 17/90] mtd: m25p80: fix allocation size Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 18/90] block: fix race between request completion and timeout handling Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 19/90] blk-core: Fix memory corruption if blkcg_init_queue fails Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 20/90] loop: fix crash if blk_alloc_queue fails Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 21/90] block: fix a probe argument to blk_register_region Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 22/90] block: properly stack underlying max_segment_size to DM device Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 23/90] xen/blkback: fix reference counting Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 24/90] loop: fix crash when using unassigned loop device Luis Henriques
2013-12-05 17:35 ` Luis Henriques [this message]
2013-12-05 17:35 ` [PATCH 3.5 26/90] mtd: gpmi: fix kernel BUG due to racing DMA operations Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 27/90] ALSA: msnd: Avoid duplicated driver name Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 28/90] x86/microcode/amd: Tone down printk(), don't treat a missing firmware file as an error Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 29/90] SUNRPC: Avoid deep recursion in rpc_release_client Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 30/90] ALSA: hda - Don't clear the power state at snd_hda_codec_reset() Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 31/90] ASoC: blackfin: Fix missing break Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 32/90] drm/nouveau: when bailing out of a pushbuf ioctl, do not remove previous fence Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 33/90] ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 34/90] ALSA: pcsp: Fix the order of input device unregistration Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 35/90] ASoC: wm8962: Turn on regcache_cache_only before disabling regulator Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 36/90] ARM: integrator_cp: Set LCD{0,1} enable lines when turning on CLCD Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 37/90] hwmon: (lm90) Fix max6696 alarm handling Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 38/90] ASoC: cs42l52: Correct MIC CTL mask Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 39/90] ARM: OMAP2+: omap_device: maintain sane runtime pm status around suspend/resume Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 40/90] setfacl removes part of ACL when setting POSIX ACLs to Samba Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 41/90] IB/ipath: Convert ipath_user_sdma_pin_pages() to use get_user_pages_fast() Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 42/90] rtlwifi: rtl8192se: Fix wrong assignment Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 43/90] rtlwifi: Fix endian error in extracting packet type Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 44/90] rtlwifi: rtl8192se: Fix incorrect signal strength for unassociated AP Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 45/90] rtlwifi: rtl8192cu: " Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 46/90] rtlwifi: rtl8192de: " Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 47/90] mwifiex: correct packet length for packets from SDIO interface Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 48/90] prism54: set netdev type to "wlan" Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 49/90] selinux: correct locking in selinux_netlbl_socket_connect) Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 50/90] Revert "ima: policy for RAMFS" Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 51/90] audit: printk USER_AVC messages when audit isn't enabled Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 52/90] audit: fix info leak in AUDIT_GET requests Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 53/90] audit: use nlmsg_len() to get message payload length Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 54/90] target: Fix delayed Task Aborted Status (TAS) handling bug Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 55/90] md: fix calculation of stacking limits on level change Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 56/90] drm/i915: flush cursors harder Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 57/90] rtlwifi: rtl8192cu: Fix more pointer arithmetic errors Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 58/90] radeon: workaround pinning failure on low ram gpu Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 59/90] drm/radeon: add semaphore trace point Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 60/90] nfsd: split up nfsd_setattr Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 61/90] nfsd: make sure to balance get/put_write_access Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 62/90] nfsd4: fix xdr decoding of large non-write compounds Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 63/90] avr32: setup crt for early panic() Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 64/90] avr32: fix out-of-range jump in large kernels Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 65/90] PCI: Remove duplicate pci_disable_device() from pcie_portdrv_remove() Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 66/90] powerpc/pseries: Duplicate dtl entries sometimes sent to userspace Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 67/90] powerpc/signals: Mark VSX not saved with small contexts Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 68/90] iscsi-target: fix extract_param to handle buffer length corner case Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 69/90] iscsi-target: chap auth shouldn't match username with trailing garbage Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 70/90] configfs: fix race between dentry put and lookup Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 71/90] KVM: perform an invalid memslot step for gpa base change Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 72/90] KVM: Fix iommu map/unmap to handle memory slot moves Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 73/90] ARM: i.MX6q: fix the wrong parent of can_root clock Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 74/90] crypto: s390 - Fix aes-cbc IV corruption Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 75/90] iio:accel:kxsd9 fix missing mutex unlock Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 76/90] PCI: Define macro for Marvell vendor ID Luis Henriques
2013-12-05 17:35 ` [PATCH 3.5 77/90] ahci: add Marvell 9230 to the AHCI PCI device list Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 78/90] powerpc/signals: Improved mark VSX not saved with small contexts fix Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 79/90] staging: zsmalloc: Ensure handle is never 0 on success Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 80/90] ALSA: hda/realtek - Add support of ALC231 codec Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 81/90] ALSA: hda/realtek - Set pcbeep amp for ALC668 Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 82/90] tracing: Allow events to have NULL strings Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 83/90] Staging: tidspbridge: disable driver Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 84/90] cpuset: Fix memory allocator deadlock Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 85/90] staging: vt6656: [BUG] Fix for TX USB resets from vendors driver Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 86/90] exec/ptrace: fix get_dumpable() incorrect tests Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 87/90] SUNRPC: don't map EKEYEXPIRED to EACCES in call_refreshresult Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 88/90] ftrace: Fix function graph with loading of modules Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 89/90] Input: i8042 - add PNP modaliases Luis Henriques
2013-12-05 17:36 ` [PATCH 3.5 90/90] misc: atmel_pwm: add deferred-probing support Luis Henriques
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386264972-5399-26-git-send-email-luis.henriques@canonical.com \
--to=luis.henriques@canonical.com \
--cc=Trond.Myklebust@netapp.com \
--cc=kernel-team@lists.ubuntu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®