From nobody Thu Dec 09 01:27:56 2021 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 1FD3A18CEE35; Thu, 9 Dec 2021 01:27:57 +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 4J8by459cjz3GPJ; Thu, 9 Dec 2021 01:27:56 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 92EA41DD51; Thu, 9 Dec 2021 01:27:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1B91RuvB045981; Thu, 9 Dec 2021 01:27:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B91Ru4H045980; Thu, 9 Dec 2021 01:27:56 GMT (envelope-from git) Date: Thu, 9 Dec 2021 01:27:56 GMT Message-Id: <202112090127.1B91Ru4H045980@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 5346570276a5 - main - swapoff: add one more variant of the syscall 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/main X-Git-Reftype: branch X-Git-Commit: 5346570276a5ddfd5f530201fcbf24ddcc53033d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639013276; 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=1F9bHh5FilwySjEzJvddNWP1DzBKbDLGNDmMPt3tw2U=; b=AcXAO+elGjAmbgSDmfezzz7yxYemZ/NX2htrlVw4pYK7lvz1V1S51jEKh0gSYcnUXjoi/t VN+iQjMpvxHpOo7mEURjeMud4PpV80EH6AT1jfvOPgVeU7jjpAqpMjahZKXCcD05sZPwF2 480e+IKHtMjSacAyEQkVHmXHhf89gUhUUi17lCQDuDsn4G9dCUuFr+xIGRmbWuKbgl8hAU WNqYGaJJgFLpn+yzWcbTN4X386G1sx1pCFEGrk1cZex4QxyBFujA7aoRVxKTU2WyP7HKyA CDSgGgQWLRfBRYUlYV+i+jdNtAA5Ey54LXhPDwYmKSDF/kpJOS28+O6iearYrQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639013276; a=rsa-sha256; cv=none; b=rAzqeUY00KsA7oIjjKYJWY89moaf/I+wNQSer/3RKM2HLQMSbR5KFlknFv8II9LRjLVK5j 9B9DoEN+SdGumXjpNQEEVMQ0yaXmMCN5YZWsTu4oZ7Bp5TW2DK5KaLeOb5yBQceHlo/oaz 95f7bK5k9ErihVHRptKq2yG2aSwpWDeKH/r+xQ2r8EcPOuofaKig0jTQ/PGAsp/dFVZbvw Ns6grHgGbf5Seb68yZc1Sua3Epu3PDX+zAdj9wbXiMzpX9BC+MfAIFe/oXE7+rjsxg1Qxv VcWRIrXsOgX90CBy/YN2jlOYlrInnE22FWh1H2wepItqEGI4YbpmuZHSkmePbA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=5346570276a5ddfd5f530201fcbf24ddcc53033d commit 5346570276a5ddfd5f530201fcbf24ddcc53033d Author: Konstantin Belousov AuthorDate: 2021-12-08 21:04:57 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-09 00:48:46 +0000 swapoff: add one more variant of the syscall Requested and reviewed by: brooks Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33343 --- include/unistd.h | 2 +- lib/libc/include/compat.h | 2 ++ lib/libc/sys/Symbol.map | 2 +- sys/kern/syscalls.master | 9 ++++++- sys/sys/unistd.h | 2 ++ sys/vm/swap_pager.c | 60 ++++++++++++++++++++--------------------------- sys/vm/swap_pager.h | 10 -------- 7 files changed, 39 insertions(+), 48 deletions(-) diff --git a/include/unistd.h b/include/unistd.h index 5f358ad72d9a..8e44e472c6d6 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -579,7 +579,7 @@ int setruid(uid_t); void setusershell(void); int strtofflags(char **, u_long *, u_long *); int swapon(const char *); -int swapoff(const char *); +int swapoff(const char *, u_int); int syscall(int, ...); off_t __syscall(quad_t, ...); int undelete(const char *); diff --git a/lib/libc/include/compat.h b/lib/libc/include/compat.h index ccb92c0fd930..e6bc2e7a6612 100644 --- a/lib/libc/include/compat.h +++ b/lib/libc/include/compat.h @@ -69,6 +69,8 @@ __sym_compat(mknodat, freebsd11_mknodat, FBSD_1.1); __sym_compat(kevent, freebsd11_kevent, FBSD_1.0); +__sym_compat(swapoff, freebsd13_swapoff, FBSD_1.0); + #undef __sym_compat #define __weak_reference(sym,alias) \ diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map index a70d14b51f7c..7984f54da697 100644 --- a/lib/libc/sys/Symbol.map +++ b/lib/libc/sys/Symbol.map @@ -260,7 +260,6 @@ FBSD_1.0 { sigwaitinfo; socket; socketpair; - swapoff; swapon; symlink; sync; @@ -420,6 +419,7 @@ FBSD_1.6 { FBSD_1.7 { _Fork; fspacectl; + swapoff; }; FBSDprivate_1.0 { diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 27baced56b7c..38505b3ea012 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -2247,7 +2247,7 @@ _In_ _Contains_long_ptr_ const struct __ucontext *ucp ); } -424 AUE_SWAPOFF STD { +424 AUE_SWAPOFF COMPAT13 { int swapoff( _In_z_ const char *name ); @@ -3300,6 +3300,13 @@ int sched_getcpu(void); } +582 AUE_SWAPOFF STD { + int swapoff( + _In_z_ const char *name, + u_int flags, + ); + } + ; Please copy any additions and changes to the following compatability tables: ; sys/compat/freebsd32/syscalls.master ; vim: syntax=off diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h index ef8835a812d2..be71edbd6e23 100644 --- a/sys/sys/unistd.h +++ b/sys/sys/unistd.h @@ -198,6 +198,8 @@ RFPROCDESC | RFSPAWN | RFPPWAIT) #define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPROCDESC) +#define SWAPOFF_FORCE 0x00000001 + #endif /* __BSD_VISIBLE */ #endif /* !_SYS_UNISTD_H_ */ diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index 99addb2c8e53..01cf9233329f 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -100,6 +100,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -2479,50 +2480,24 @@ swaponsomething(struct vnode *vp, void *id, u_long nblks, * rather than filename as specification. We keep sw_vp around * only to make this work. */ -#ifndef _SYS_SYSPROTO_H_ -struct swapoff_args { - char *name; -}; -#endif - -int -sys_swapoff(struct thread *td, struct swapoff_args *uap) +static int +kern_swapoff(struct thread *td, const char *name, enum uio_seg name_seg, + u_int flags) { struct vnode *vp; struct nameidata nd; struct swdevt *sp; - struct swapoff_new_args sa; - int error, probe_byte; + int error; error = priv_check(td, PRIV_SWAPOFF); - if (error) + if (error != 0) return (error); - - /* - * Detect old vs. new-style swapoff(2) syscall. The first - * pointer in the memory pointed to by uap->name is NULL for - * the new variant. - */ - probe_byte = fubyte(uap->name); - switch (probe_byte) { - case -1: - return (EFAULT); - case 0: - error = copyin(uap->name, &sa, sizeof(sa)); - if (error != 0) - return (error); - if ((sa.flags & ~(SWAPOFF_FORCE)) != 0) - return (EINVAL); - break; - default: - bzero(&sa, sizeof(sa)); - sa.name = uap->name; - break; - } + if ((flags & ~(SWAPOFF_FORCE)) != 0) + return (EINVAL); sx_xlock(&swdev_syscall_lock); - NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, sa.name); + NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, name_seg, name); error = namei(&nd); if (error) goto done; @@ -2539,12 +2514,27 @@ sys_swapoff(struct thread *td, struct swapoff_args *uap) error = EINVAL; goto done; } - error = swapoff_one(sp, td->td_ucred, sa.flags); + error = swapoff_one(sp, td->td_ucred, flags); done: sx_xunlock(&swdev_syscall_lock); return (error); } + +#ifdef COMPAT_FREEBSD13 +int +freebsd13_swapoff(struct thread *td, struct freebsd13_swapoff_args *uap) +{ + return (kern_swapoff(td, uap->name, UIO_USERSPACE, 0)); +} +#endif + +int +sys_swapoff(struct thread *td, struct swapoff_args *uap) +{ + return (kern_swapoff(td, uap->name, UIO_USERSPACE, uap->flags)); +} + static int swapoff_one(struct swdevt *sp, struct ucred *cred, u_int flags) { diff --git a/sys/vm/swap_pager.h b/sys/vm/swap_pager.h index 59322d49cbc9..395fbc9957c4 100644 --- a/sys/vm/swap_pager.h +++ b/sys/vm/swap_pager.h @@ -69,16 +69,6 @@ struct swdevt { #define SW_UNMAPPED 0x01 #define SW_CLOSING 0x04 -struct swapoff_new_args { - const char *name_old_syscall; - const char *name; - u_int flags; - u_int pad0; - uintptr_t pad1[8]; -}; - -#define SWAPOFF_FORCE 0x00000001 - #ifdef _KERNEL extern int swap_pager_avail;