From nobody Sat Sep 16 00:41:07 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RnXKv4WF8z4t3dq; Sat, 16 Sep 2023 00:41:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RnXKv44Gyz3Spt; Sat, 16 Sep 2023 00:41:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694824867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fvEZDdZ8iqO1OAIGKbIAYa4dMkloywHjb+0B1WvZ3g4=; b=GauLFcld/XCTb+Rvdnzasy8g4qfV5owr7a5tFuq43HdrWHWTqVwlLLB8qEQUzkpRHoJ2m1 V6PMvC86rHhqvZHHzgLNe31pjehLCrX+vrSwg4cmrsDbiaKLNVXKgCTq8gJGR7S3Sr++KT /U2PB6viMUmhiRYUWCRFeWY0IqPpv6Xx0eFhqE4MJSC57Qc85p0m+apE34jTHOj1rZG6Vq 5B/t/uuFYM7TMMAkhFuR72Xe4758xWbgA+e44aMTF0Ha9ZBaLDPcpVox1MkiSZrYenqYKw HVNhTzIUAZ04Wze7bo+iYycnnBdboa33nkeQflU0dHu+ywQfaY1Im8+Z1SjHoA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694824867; a=rsa-sha256; cv=none; b=h+rJHzb+F7m33ggIm1qgNZHnMqNkobPSOr1zgc4FQGQS0K/fxBgqQ9ldoRi81jFomEp0uM E7JwYwkU8P9L4+Pdqo6HmOR63+4pIM1giKwfNfieyG8SrSJwc4Zm2CyP9fvHey7knOEth8 In94xokRiZhKqcl2gxyjFmyV9HUND5vTDwPysNMXKWiTrWaQ7ZPMGgJGpJkki/Q4pm3XHi VWMmDTp0zUfPUCEcznLleqxUwv1ocAXuF6gepoouN/3QUFL+IEYgPSw4RqTlJ2xfkRONhD Eum51YkmfVMe/CJjvNJKz1ZkBIFhV5jNEAY6xqZb/PboPjUnqyaFMO1LLewXtw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694824867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fvEZDdZ8iqO1OAIGKbIAYa4dMkloywHjb+0B1WvZ3g4=; b=OfuOpvUQ+U2loXFG2nwWteMRuKjbWVQvMDg2gpRZbw/5/5EQ7DZz9xIzHszZoV2lGPHzOe UchQslTCrlggafzSLhq6MWw8QLuV6yu8qfwEt3/NqExj9P4P21ugagixt3hPdAUtjxmCee ypm55yhL7wJ+8CbV04vaLAsUcsf6raJ0mWNN0vBiqZm1WxTF0uvfkMn2rBDkxI4WOnuUJs lwNHfZqTbLTadKcZAeVCxCXZpCgigqhBsGpNwGRsfaQEQVsdTxNiuXVVZWYF2waKlfoyvc UQgwCyWeLFkmbSHolgYYlNuWkOO23wVKL5Gfrp1oK0fiCpSyVkZwzTKxGII2Qw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RnXKv38Mvzlm3; Sat, 16 Sep 2023 00:41:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38G0f7Cs047565; Sat, 16 Sep 2023 00:41:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38G0f75I047562; Sat, 16 Sep 2023 00:41:07 GMT (envelope-from git) Date: Sat, 16 Sep 2023 00:41:07 GMT Message-Id: <202309160041.38G0f75I047562@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 1da381c2bea7 - stable/13 - shmfd: hide direct rangelock(9) use under a wrapper List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1da381c2bea76992a510a48c7a6673a9c64d9c15 Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1da381c2bea76992a510a48c7a6673a9c64d9c15 commit 1da381c2bea76992a510a48c7a6673a9c64d9c15 Author: Konstantin Belousov AuthorDate: 2023-08-18 12:38:28 +0000 Commit: Konstantin Belousov CommitDate: 2023-09-16 00:40:48 +0000 shmfd: hide direct rangelock(9) use under a wrapper (cherry picked from commit 6df6facf44f952f64753bee00831fd93f16c99a9) --- sys/kern/uipc_shm.c | 64 ++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c index f2d883c9c8b7..def8c35025c1 100644 --- a/sys/kern/uipc_shm.c +++ b/sys/kern/uipc_shm.c @@ -178,6 +178,15 @@ SYSCTL_INT(_vm_largepages, OID_AUTO, reclaim_tries, CTLFLAG_RWTUN, &largepage_reclaim_tries, 0, "Number of contig reclaims before giving up for default alloc policy"); +#define shm_rangelock_unlock(shmfd, cookie) \ + rangelock_unlock(&(shmfd)->shm_rl, (cookie), &(shmfd)->shm_mtx) +#define shm_rangelock_rlock(shmfd, start, end) \ + rangelock_rlock(&(shmfd)->shm_rl, (start), (end), &(shmfd)->shm_mtx) +#define shm_rangelock_tryrlock(shmfd, start, end) \ + rangelock_tryrlock(&(shmfd)->shm_rl, (start), (end), &(shmfd)->shm_mtx) +#define shm_rangelock_wlock(shmfd, start, end) \ + rangelock_wlock(&(shmfd)->shm_rl, (start), (end), &(shmfd)->shm_mtx) + static int uiomove_object_page(vm_object_t obj, size_t len, struct uio *uio) { @@ -452,10 +461,10 @@ shm_read(struct file *fp, struct uio *uio, struct ucred *active_cred, return (error); #endif foffset_lock_uio(fp, uio, flags); - rl_cookie = rangelock_rlock(&shmfd->shm_rl, uio->uio_offset, - uio->uio_offset + uio->uio_resid, &shmfd->shm_mtx); + rl_cookie = shm_rangelock_rlock(shmfd, uio->uio_offset, + uio->uio_offset + uio->uio_resid); error = uiomove_object(shmfd->shm_object, shmfd->shm_size, uio); - rangelock_unlock(&shmfd->shm_rl, rl_cookie, &shmfd->shm_mtx); + shm_rangelock_unlock(shmfd, rl_cookie); foffset_unlock_uio(fp, uio, flags); return (error); } @@ -493,13 +502,10 @@ shm_write(struct file *fp, struct uio *uio, struct ucred *active_cred, } else { size = uio->uio_offset + uio->uio_resid; } - if ((flags & FOF_OFFSET) == 0) { - rl_cookie = rangelock_wlock(&shmfd->shm_rl, 0, OFF_MAX, - &shmfd->shm_mtx); - } else { - rl_cookie = rangelock_wlock(&shmfd->shm_rl, uio->uio_offset, - size, &shmfd->shm_mtx); - } + if ((flags & FOF_OFFSET) == 0) + rl_cookie = shm_rangelock_wlock(shmfd, 0, OFF_MAX); + else + rl_cookie = shm_rangelock_wlock(shmfd, uio->uio_offset, size); if ((shmfd->shm_seals & F_SEAL_WRITE) != 0) { error = EPERM; } else { @@ -512,7 +518,7 @@ shm_write(struct file *fp, struct uio *uio, struct ucred *active_cred, error = uiomove_object(shmfd->shm_object, shmfd->shm_size, uio); } - rangelock_unlock(&shmfd->shm_rl, rl_cookie, &shmfd->shm_mtx); + shm_rangelock_unlock(shmfd, rl_cookie); foffset_unlock_uio(fp, uio, flags); return (error); } @@ -567,22 +573,20 @@ shm_ioctl(struct file *fp, u_long com, void *data, struct ucred *active_cred, conf->alloc_policy != SHM_LARGEPAGE_ALLOC_HARD) return (EINVAL); - rl_cookie = rangelock_wlock(&shmfd->shm_rl, 0, OFF_MAX, - &shmfd->shm_mtx); + rl_cookie = shm_rangelock_wlock(shmfd, 0, OFF_MAX); shmfd->shm_lp_psind = conf->psind; shmfd->shm_lp_alloc_policy = conf->alloc_policy; shmfd->shm_object->un_pager.phys.data_val = conf->psind; - rangelock_unlock(&shmfd->shm_rl, rl_cookie, &shmfd->shm_mtx); + shm_rangelock_unlock(shmfd, rl_cookie); return (0); case FIOGSHMLPGCNF: if (!shm_largepage(shmfd)) return (ENOTTY); conf = data; - rl_cookie = rangelock_rlock(&shmfd->shm_rl, 0, OFF_MAX, - &shmfd->shm_mtx); + rl_cookie = shm_rangelock_rlock(shmfd, 0, OFF_MAX); conf->psind = shmfd->shm_lp_psind; conf->alloc_policy = shmfd->shm_lp_alloc_policy; - rangelock_unlock(&shmfd->shm_rl, rl_cookie, &shmfd->shm_mtx); + shm_rangelock_unlock(shmfd, rl_cookie); return (0); default: return (ENOTTY); @@ -899,10 +903,9 @@ shm_dotruncate(struct shmfd *shmfd, off_t length) void *rl_cookie; int error; - rl_cookie = rangelock_wlock(&shmfd->shm_rl, 0, OFF_MAX, - &shmfd->shm_mtx); + rl_cookie = shm_rangelock_wlock(shmfd, 0, OFF_MAX); error = shm_dotruncate_cookie(shmfd, length, rl_cookie); - rangelock_unlock(&shmfd->shm_rl, rl_cookie, &shmfd->shm_mtx); + shm_rangelock_unlock(shmfd, rl_cookie); return (error); } @@ -1240,8 +1243,7 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode, error = ENOENT; } } else { - rl_cookie = rangelock_wlock(&shmfd->shm_rl, 0, OFF_MAX, - &shmfd->shm_mtx); + rl_cookie = shm_rangelock_wlock(shmfd, 0, OFF_MAX); /* * kern_shm_open() likely shouldn't ever error out on @@ -1313,8 +1315,7 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode, shmfd->shm_seals |= initial_seals; shm_hold(shmfd); } - rangelock_unlock(&shmfd->shm_rl, rl_cookie, - &shmfd->shm_mtx); + shm_rangelock_unlock(shmfd, rl_cookie); } sx_xunlock(&shm_dict_lock); @@ -1636,8 +1637,7 @@ shm_mmap(struct file *fp, vm_map_t map, vm_offset_t *addr, vm_size_t objsize, shmfd = fp->f_data; maxprot = VM_PROT_NONE; - rl_cookie = rangelock_rlock(&shmfd->shm_rl, 0, objsize, - &shmfd->shm_mtx); + rl_cookie = shm_rangelock_rlock(shmfd, 0, objsize); /* FREAD should always be set. */ if ((fp->f_flag & FREAD) != 0) maxprot |= VM_PROT_EXECUTE | VM_PROT_READ; @@ -1711,7 +1711,7 @@ shm_mmap(struct file *fp, vm_map_t map, vm_offset_t *addr, vm_size_t objsize, vm_object_deallocate(shmfd->shm_object); } out: - rangelock_unlock(&shmfd->shm_rl, rl_cookie, &shmfd->shm_mtx); + shm_rangelock_unlock(shmfd, rl_cookie); return (error); } @@ -1929,8 +1929,7 @@ shm_add_seals(struct file *fp, int seals) error = 0; shmfd = fp->f_data; - rl_cookie = rangelock_wlock(&shmfd->shm_rl, 0, OFF_MAX, - &shmfd->shm_mtx); + rl_cookie = shm_rangelock_wlock(shmfd, 0, OFF_MAX); /* Even already-set seals should result in EPERM. */ if ((shmfd->shm_seals & F_SEAL_SEAL) != 0) { @@ -1961,7 +1960,7 @@ shm_add_seals(struct file *fp, int seals) } shmfd->shm_seals |= nseals; out: - rangelock_unlock(&shmfd->shm_rl, rl_cookie, &shmfd->shm_mtx); + shm_rangelock_unlock(shmfd, rl_cookie); return (error); } @@ -1997,11 +1996,10 @@ shm_fallocate(struct file *fp, off_t offset, off_t len, struct thread *td) * the shmfd is not necessarily a concern. If other mechanisms are * added to grow a shmfd, this may need to be re-evaluated. */ - rl_cookie = rangelock_wlock(&shmfd->shm_rl, offset, size, - &shmfd->shm_mtx); + rl_cookie = shm_rangelock_wlock(shmfd, offset, size); if (size > shmfd->shm_size) error = shm_dotruncate_cookie(shmfd, size, rl_cookie); - rangelock_unlock(&shmfd->shm_rl, rl_cookie, &shmfd->shm_mtx); + shm_rangelock_unlock(shmfd, rl_cookie); /* Translate to posix_fallocate(2) return value as needed. */ if (error == ENOMEM) error = ENOSPC;