mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-11-01 17:08:10 +00:00
c3e9c04b89
Stable bugfixes: - Revalidate "." and ".." correctly on open - Avoid RCU usage in tracepoints - Fix ugly referral attributes - Fix a typo in nomigration mount option - Revert "NFS: Move the flock open mode check into nfs_flock()" Features: - Implement a stronger send queue accounting system for NFS over RDMA - Switch some atomics to the new refcount_t type Other bugfixes and cleanups: - Clean up access mode bits - Remove special-case revalidations in nfs_opendir() - Improve invalidating NFS over RDMA memory for async operations that time out - Handle NFS over RDMA replies with a worqueue - Handle NFS over RDMA sends with a workqueue - Fix up replaying interrupted requests - Remove dead NFS over RDMA definitions - Update NFS over RDMA copyright information - Be more consistent with bool initialization and comparisons - Mark expected switch fall throughs - Various sunrpc tracepoint cleanups - Fix various OPEN races - Fix a typo in nfs_rename() - Use common error handling code in nfs_lock_and_join_request() - Check that some structures are properly cleaned up during net_exit() - Remove net pointer from dprintk()s -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEnZ5MQTpR7cLU7KEp18tUv7ClQOsFAloPWGwACgkQ18tUv7Cl QOtMVhAAufCkDxqO2lmDH+0JyYUKMcoOMYtI8s2J1HrbEzTW/dVtI28fPAKEEd4m 2JjNqnO516Jiv+g3E6eO4uunZRb4IB3AYT6YaTwmBFE+l7tpMdPb1xybOBP02Hji Y29kzLXwxxvnoxEqFalzCzV2BeRb2kAw6mayY9FxH6AfiEEQZfmxLCYgVuYa2jTC Z/B5E0GxAf28Aj0bIP8lLKbOkFijo851DB88UffEOZQGKUDlAd3GNUSSHb81Rj0N 4ef7bKoGylkIpZ1PdTChdG1+RKqud02zrmQfmEwXui3eUwhOWy8hrKloNykqR5sj pgoDz79euAq4TDVyQKtutnbvVxfCcBeMYAXZhXkZLVcl+39in0kuLj4SxU5AmDhf ErnthG4W7jsLMM96kMvSTaoh4uwioviG1KmZfvuvUoMBSwtiX18hFTWtFKRD6x9e PNOqBdh8nkKYEFbEO4ksfYaWZJ5AuyFIQiIpj1gm+7sf039oN/zEuPV+jaEJG0oa Ef9IqHrQbbCUFYFjpBENr3HjU3igTTaxQ5iq+VYl4zg1pw6m6JTojqZ6qtQzqOYS O3N1ygeShsW934z8QcWjtEyeUXIB3JF9vUS3gEBgWPDyCltGXyq4Cq6Lod4s4JCb pWGI6wJLX1Fg6nq7cj0S4Or3QBgz2q8ZyBxssamhdvON/Ef5ccI= =2Zc1 -----END PGP SIGNATURE----- Merge tag 'nfs-for-4.15-1' of git://git.linux-nfs.org/projects/anna/linux-nfs Pull NFS client updates from Anna Schumaker: "Stable bugfixes: - Revalidate "." and ".." correctly on open - Avoid RCU usage in tracepoints - Fix ugly referral attributes - Fix a typo in nomigration mount option - Revert "NFS: Move the flock open mode check into nfs_flock()" Features: - Implement a stronger send queue accounting system for NFS over RDMA - Switch some atomics to the new refcount_t type Other bugfixes and cleanups: - Clean up access mode bits - Remove special-case revalidations in nfs_opendir() - Improve invalidating NFS over RDMA memory for async operations that time out - Handle NFS over RDMA replies with a worqueue - Handle NFS over RDMA sends with a workqueue - Fix up replaying interrupted requests - Remove dead NFS over RDMA definitions - Update NFS over RDMA copyright information - Be more consistent with bool initialization and comparisons - Mark expected switch fall throughs - Various sunrpc tracepoint cleanups - Fix various OPEN races - Fix a typo in nfs_rename() - Use common error handling code in nfs_lock_and_join_request() - Check that some structures are properly cleaned up during net_exit() - Remove net pointer from dprintk()s" * tag 'nfs-for-4.15-1' of git://git.linux-nfs.org/projects/anna/linux-nfs: (62 commits) NFS: Revert "NFS: Move the flock open mode check into nfs_flock()" NFS: Fix typo in nomigration mount option nfs: Fix ugly referral attributes NFS: super: mark expected switch fall-throughs sunrpc: remove net pointer from messages nfs: remove net pointer from messages sunrpc: exit_net cleanup check added nfs client: exit_net cleanup check added nfs/write: Use common error handling code in nfs_lock_and_join_requests() NFSv4: Replace closed stateids with the "invalid special stateid" NFSv4: nfs_set_open_stateid must not trigger state recovery for closed state NFSv4: Check the open stateid when searching for expired state NFSv4: Clean up nfs4_delegreturn_done NFSv4: cleanup nfs4_close_done NFSv4: Retry NFS4ERR_OLD_STATEID errors in layoutreturn pNFS: Retry NFS4ERR_OLD_STATEID errors in layoutreturn-on-close NFSv4: Don't try to CLOSE if the stateid 'other' field has changed NFSv4: Retry CLOSE and DELEGRETURN on NFS4ERR_OLD_STATEID. NFS: Fix a typo in nfs_rename() NFSv4: Fix open create exclusive when the server reboots ...
319 lines
7.6 KiB
C
319 lines
7.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (c) 2015 Oracle. All rights reserved.
|
|
* Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved.
|
|
*/
|
|
|
|
/* Lightweight memory registration using Fast Memory Regions (FMR).
|
|
* Referred to sometimes as MTHCAFMR mode.
|
|
*
|
|
* FMR uses synchronous memory registration and deregistration.
|
|
* FMR registration is known to be fast, but FMR deregistration
|
|
* can take tens of usecs to complete.
|
|
*/
|
|
|
|
/* Normal operation
|
|
*
|
|
* A Memory Region is prepared for RDMA READ or WRITE using the
|
|
* ib_map_phys_fmr verb (fmr_op_map). When the RDMA operation is
|
|
* finished, the Memory Region is unmapped using the ib_unmap_fmr
|
|
* verb (fmr_op_unmap).
|
|
*/
|
|
|
|
#include "xprt_rdma.h"
|
|
|
|
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
|
|
# define RPCDBG_FACILITY RPCDBG_TRANS
|
|
#endif
|
|
|
|
/* Maximum scatter/gather per FMR */
|
|
#define RPCRDMA_MAX_FMR_SGES (64)
|
|
|
|
/* Access mode of externally registered pages */
|
|
enum {
|
|
RPCRDMA_FMR_ACCESS_FLAGS = IB_ACCESS_REMOTE_WRITE |
|
|
IB_ACCESS_REMOTE_READ,
|
|
};
|
|
|
|
bool
|
|
fmr_is_supported(struct rpcrdma_ia *ia)
|
|
{
|
|
if (!ia->ri_device->alloc_fmr) {
|
|
pr_info("rpcrdma: 'fmr' mode is not supported by device %s\n",
|
|
ia->ri_device->name);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static int
|
|
fmr_op_init_mr(struct rpcrdma_ia *ia, struct rpcrdma_mw *mw)
|
|
{
|
|
static struct ib_fmr_attr fmr_attr = {
|
|
.max_pages = RPCRDMA_MAX_FMR_SGES,
|
|
.max_maps = 1,
|
|
.page_shift = PAGE_SHIFT
|
|
};
|
|
|
|
mw->fmr.fm_physaddrs = kcalloc(RPCRDMA_MAX_FMR_SGES,
|
|
sizeof(u64), GFP_KERNEL);
|
|
if (!mw->fmr.fm_physaddrs)
|
|
goto out_free;
|
|
|
|
mw->mw_sg = kcalloc(RPCRDMA_MAX_FMR_SGES,
|
|
sizeof(*mw->mw_sg), GFP_KERNEL);
|
|
if (!mw->mw_sg)
|
|
goto out_free;
|
|
|
|
sg_init_table(mw->mw_sg, RPCRDMA_MAX_FMR_SGES);
|
|
|
|
mw->fmr.fm_mr = ib_alloc_fmr(ia->ri_pd, RPCRDMA_FMR_ACCESS_FLAGS,
|
|
&fmr_attr);
|
|
if (IS_ERR(mw->fmr.fm_mr))
|
|
goto out_fmr_err;
|
|
|
|
return 0;
|
|
|
|
out_fmr_err:
|
|
dprintk("RPC: %s: ib_alloc_fmr returned %ld\n", __func__,
|
|
PTR_ERR(mw->fmr.fm_mr));
|
|
|
|
out_free:
|
|
kfree(mw->mw_sg);
|
|
kfree(mw->fmr.fm_physaddrs);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
static int
|
|
__fmr_unmap(struct rpcrdma_mw *mw)
|
|
{
|
|
LIST_HEAD(l);
|
|
int rc;
|
|
|
|
list_add(&mw->fmr.fm_mr->list, &l);
|
|
rc = ib_unmap_fmr(&l);
|
|
list_del(&mw->fmr.fm_mr->list);
|
|
return rc;
|
|
}
|
|
|
|
static void
|
|
fmr_op_release_mr(struct rpcrdma_mw *r)
|
|
{
|
|
LIST_HEAD(unmap_list);
|
|
int rc;
|
|
|
|
/* Ensure MW is not on any rl_registered list */
|
|
if (!list_empty(&r->mw_list))
|
|
list_del(&r->mw_list);
|
|
|
|
kfree(r->fmr.fm_physaddrs);
|
|
kfree(r->mw_sg);
|
|
|
|
/* In case this one was left mapped, try to unmap it
|
|
* to prevent dealloc_fmr from failing with EBUSY
|
|
*/
|
|
rc = __fmr_unmap(r);
|
|
if (rc)
|
|
pr_err("rpcrdma: final ib_unmap_fmr for %p failed %i\n",
|
|
r, rc);
|
|
|
|
rc = ib_dealloc_fmr(r->fmr.fm_mr);
|
|
if (rc)
|
|
pr_err("rpcrdma: final ib_dealloc_fmr for %p returned %i\n",
|
|
r, rc);
|
|
|
|
kfree(r);
|
|
}
|
|
|
|
/* Reset of a single FMR.
|
|
*/
|
|
static void
|
|
fmr_op_recover_mr(struct rpcrdma_mw *mw)
|
|
{
|
|
struct rpcrdma_xprt *r_xprt = mw->mw_xprt;
|
|
int rc;
|
|
|
|
/* ORDER: invalidate first */
|
|
rc = __fmr_unmap(mw);
|
|
|
|
/* ORDER: then DMA unmap */
|
|
ib_dma_unmap_sg(r_xprt->rx_ia.ri_device,
|
|
mw->mw_sg, mw->mw_nents, mw->mw_dir);
|
|
if (rc)
|
|
goto out_release;
|
|
|
|
rpcrdma_put_mw(r_xprt, mw);
|
|
r_xprt->rx_stats.mrs_recovered++;
|
|
return;
|
|
|
|
out_release:
|
|
pr_err("rpcrdma: FMR reset failed (%d), %p released\n", rc, mw);
|
|
r_xprt->rx_stats.mrs_orphaned++;
|
|
|
|
spin_lock(&r_xprt->rx_buf.rb_mwlock);
|
|
list_del(&mw->mw_all);
|
|
spin_unlock(&r_xprt->rx_buf.rb_mwlock);
|
|
|
|
fmr_op_release_mr(mw);
|
|
}
|
|
|
|
static int
|
|
fmr_op_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep,
|
|
struct rpcrdma_create_data_internal *cdata)
|
|
{
|
|
ia->ri_max_segs = max_t(unsigned int, 1, RPCRDMA_MAX_DATA_SEGS /
|
|
RPCRDMA_MAX_FMR_SGES);
|
|
return 0;
|
|
}
|
|
|
|
/* FMR mode conveys up to 64 pages of payload per chunk segment.
|
|
*/
|
|
static size_t
|
|
fmr_op_maxpages(struct rpcrdma_xprt *r_xprt)
|
|
{
|
|
return min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS,
|
|
RPCRDMA_MAX_HDR_SEGS * RPCRDMA_MAX_FMR_SGES);
|
|
}
|
|
|
|
/* Use the ib_map_phys_fmr() verb to register a memory region
|
|
* for remote access via RDMA READ or RDMA WRITE.
|
|
*/
|
|
static struct rpcrdma_mr_seg *
|
|
fmr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
|
|
int nsegs, bool writing, struct rpcrdma_mw **out)
|
|
{
|
|
struct rpcrdma_mr_seg *seg1 = seg;
|
|
int len, pageoff, i, rc;
|
|
struct rpcrdma_mw *mw;
|
|
u64 *dma_pages;
|
|
|
|
mw = rpcrdma_get_mw(r_xprt);
|
|
if (!mw)
|
|
return ERR_PTR(-ENOBUFS);
|
|
|
|
pageoff = offset_in_page(seg1->mr_offset);
|
|
seg1->mr_offset -= pageoff; /* start of page */
|
|
seg1->mr_len += pageoff;
|
|
len = -pageoff;
|
|
if (nsegs > RPCRDMA_MAX_FMR_SGES)
|
|
nsegs = RPCRDMA_MAX_FMR_SGES;
|
|
for (i = 0; i < nsegs;) {
|
|
if (seg->mr_page)
|
|
sg_set_page(&mw->mw_sg[i],
|
|
seg->mr_page,
|
|
seg->mr_len,
|
|
offset_in_page(seg->mr_offset));
|
|
else
|
|
sg_set_buf(&mw->mw_sg[i], seg->mr_offset,
|
|
seg->mr_len);
|
|
len += seg->mr_len;
|
|
++seg;
|
|
++i;
|
|
/* Check for holes */
|
|
if ((i < nsegs && offset_in_page(seg->mr_offset)) ||
|
|
offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len))
|
|
break;
|
|
}
|
|
mw->mw_dir = rpcrdma_data_dir(writing);
|
|
|
|
mw->mw_nents = ib_dma_map_sg(r_xprt->rx_ia.ri_device,
|
|
mw->mw_sg, i, mw->mw_dir);
|
|
if (!mw->mw_nents)
|
|
goto out_dmamap_err;
|
|
|
|
for (i = 0, dma_pages = mw->fmr.fm_physaddrs; i < mw->mw_nents; i++)
|
|
dma_pages[i] = sg_dma_address(&mw->mw_sg[i]);
|
|
rc = ib_map_phys_fmr(mw->fmr.fm_mr, dma_pages, mw->mw_nents,
|
|
dma_pages[0]);
|
|
if (rc)
|
|
goto out_maperr;
|
|
|
|
mw->mw_handle = mw->fmr.fm_mr->rkey;
|
|
mw->mw_length = len;
|
|
mw->mw_offset = dma_pages[0] + pageoff;
|
|
|
|
*out = mw;
|
|
return seg;
|
|
|
|
out_dmamap_err:
|
|
pr_err("rpcrdma: failed to DMA map sg %p sg_nents %d\n",
|
|
mw->mw_sg, i);
|
|
rpcrdma_put_mw(r_xprt, mw);
|
|
return ERR_PTR(-EIO);
|
|
|
|
out_maperr:
|
|
pr_err("rpcrdma: ib_map_phys_fmr %u@0x%llx+%i (%d) status %i\n",
|
|
len, (unsigned long long)dma_pages[0],
|
|
pageoff, mw->mw_nents, rc);
|
|
ib_dma_unmap_sg(r_xprt->rx_ia.ri_device,
|
|
mw->mw_sg, mw->mw_nents, mw->mw_dir);
|
|
rpcrdma_put_mw(r_xprt, mw);
|
|
return ERR_PTR(-EIO);
|
|
}
|
|
|
|
/* Invalidate all memory regions that were registered for "req".
|
|
*
|
|
* Sleeps until it is safe for the host CPU to access the
|
|
* previously mapped memory regions.
|
|
*
|
|
* Caller ensures that @mws is not empty before the call. This
|
|
* function empties the list.
|
|
*/
|
|
static void
|
|
fmr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct list_head *mws)
|
|
{
|
|
struct rpcrdma_mw *mw;
|
|
LIST_HEAD(unmap_list);
|
|
int rc;
|
|
|
|
/* ORDER: Invalidate all of the req's MRs first
|
|
*
|
|
* ib_unmap_fmr() is slow, so use a single call instead
|
|
* of one call per mapped FMR.
|
|
*/
|
|
list_for_each_entry(mw, mws, mw_list) {
|
|
dprintk("RPC: %s: unmapping fmr %p\n",
|
|
__func__, &mw->fmr);
|
|
list_add_tail(&mw->fmr.fm_mr->list, &unmap_list);
|
|
}
|
|
r_xprt->rx_stats.local_inv_needed++;
|
|
rc = ib_unmap_fmr(&unmap_list);
|
|
if (rc)
|
|
goto out_reset;
|
|
|
|
/* ORDER: Now DMA unmap all of the req's MRs, and return
|
|
* them to the free MW list.
|
|
*/
|
|
while (!list_empty(mws)) {
|
|
mw = rpcrdma_pop_mw(mws);
|
|
dprintk("RPC: %s: DMA unmapping fmr %p\n",
|
|
__func__, &mw->fmr);
|
|
list_del(&mw->fmr.fm_mr->list);
|
|
ib_dma_unmap_sg(r_xprt->rx_ia.ri_device,
|
|
mw->mw_sg, mw->mw_nents, mw->mw_dir);
|
|
rpcrdma_put_mw(r_xprt, mw);
|
|
}
|
|
|
|
return;
|
|
|
|
out_reset:
|
|
pr_err("rpcrdma: ib_unmap_fmr failed (%i)\n", rc);
|
|
|
|
while (!list_empty(mws)) {
|
|
mw = rpcrdma_pop_mw(mws);
|
|
list_del(&mw->fmr.fm_mr->list);
|
|
fmr_op_recover_mr(mw);
|
|
}
|
|
}
|
|
|
|
const struct rpcrdma_memreg_ops rpcrdma_fmr_memreg_ops = {
|
|
.ro_map = fmr_op_map,
|
|
.ro_unmap_sync = fmr_op_unmap_sync,
|
|
.ro_recover_mr = fmr_op_recover_mr,
|
|
.ro_open = fmr_op_open,
|
|
.ro_maxpages = fmr_op_maxpages,
|
|
.ro_init_mr = fmr_op_init_mr,
|
|
.ro_release_mr = fmr_op_release_mr,
|
|
.ro_displayname = "fmr",
|
|
.ro_send_w_inv_ok = 0,
|
|
};
|