From owner-svn-src-all@freebsd.org Fri Dec 11 00:35:05 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 225574BDD8D; Fri, 11 Dec 2020 00:35:05 +0000 (UTC) (envelope-from kib@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CsWyd0R6xz4YcQ; Fri, 11 Dec 2020 00:35:05 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 01BAB2210D; Fri, 11 Dec 2020 00:35:05 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0BB0Z4lm084420; Fri, 11 Dec 2020 00:35:04 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0BB0Z4rk084419; Fri, 11 Dec 2020 00:35:04 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202012110035.0BB0Z4rk084419@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 11 Dec 2020 00:35:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r368539 - in stable/12/sys: kern sys X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in stable/12/sys: kern sys X-SVN-Commit-Revision: 368539 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Dec 2020 00:35:05 -0000 Author: kib Date: Fri Dec 11 00:35:04 2020 New Revision: 368539 URL: https://svnweb.freebsd.org/changeset/base/368539 Log: MFC r368342: Add kern_ntp_adjtime(9). Modified: stable/12/sys/kern/kern_ntptime.c stable/12/sys/sys/syscallsubr.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/kern/kern_ntptime.c ============================================================================== --- stable/12/sys/kern/kern_ntptime.c Fri Dec 11 00:30:41 2020 (r368538) +++ stable/12/sys/kern/kern_ntptime.c Fri Dec 11 00:35:04 2020 (r368539) @@ -337,24 +337,13 @@ SYSCTL_S64(_kern_ntp_pll, OID_AUTO, time_freq, CTLFLAG * the timex.constant structure member has a dual purpose to set the time * constant and to set the TAI offset. */ -#ifndef _SYS_SYSPROTO_H_ -struct ntp_adjtime_args { - struct timex *tp; -}; -#endif - int -sys_ntp_adjtime(struct thread *td, struct ntp_adjtime_args *uap) +kern_ntp_adjtime(struct thread *td, struct timex *ntv, int *retvalp) { - struct timex ntv; /* temporary structure */ long freq; /* frequency ns/s) */ int modes; /* mode bits from structure */ int error, retval; - error = copyin((caddr_t)uap->tp, (caddr_t)&ntv, sizeof(ntv)); - if (error) - return (error); - /* * Update selected clock variables - only the superuser can * change anything. Note that there is no error checking here on @@ -364,18 +353,19 @@ sys_ntp_adjtime(struct thread *td, struct ntp_adjtime_ * the STA_PLL bit in the status word is cleared, the state and * status words are reset to the initial values at boot. */ - modes = ntv.modes; + modes = ntv->modes; + error = 0; if (modes) error = priv_check(td, PRIV_NTP_ADJTIME); if (error != 0) return (error); NTP_LOCK(); if (modes & MOD_MAXERROR) - time_maxerror = ntv.maxerror; + time_maxerror = ntv->maxerror; if (modes & MOD_ESTERROR) - time_esterror = ntv.esterror; + time_esterror = ntv->esterror; if (modes & MOD_STATUS) { - if (time_status & STA_PLL && !(ntv.status & STA_PLL)) { + if (time_status & STA_PLL && !(ntv->status & STA_PLL)) { time_state = TIME_OK; time_status = STA_UNSYNC; #ifdef PPS_SYNC @@ -383,28 +373,28 @@ sys_ntp_adjtime(struct thread *td, struct ntp_adjtime_ #endif /* PPS_SYNC */ } time_status &= STA_RONLY; - time_status |= ntv.status & ~STA_RONLY; + time_status |= ntv->status & ~STA_RONLY; } if (modes & MOD_TIMECONST) { - if (ntv.constant < 0) + if (ntv->constant < 0) time_constant = 0; - else if (ntv.constant > MAXTC) + else if (ntv->constant > MAXTC) time_constant = MAXTC; else - time_constant = ntv.constant; + time_constant = ntv->constant; } if (modes & MOD_TAI) { - if (ntv.constant > 0) /* XXX zero & negative numbers ? */ - time_tai = ntv.constant; + if (ntv->constant > 0) /* XXX zero & negative numbers ? */ + time_tai = ntv->constant; } #ifdef PPS_SYNC if (modes & MOD_PPSMAX) { - if (ntv.shift < PPS_FAVG) + if (ntv->shift < PPS_FAVG) pps_shiftmax = PPS_FAVG; - else if (ntv.shift > PPS_FAVGMAX) + else if (ntv->shift > PPS_FAVGMAX) pps_shiftmax = PPS_FAVGMAX; else - pps_shiftmax = ntv.shift; + pps_shiftmax = ntv->shift; } #endif /* PPS_SYNC */ if (modes & MOD_NANO) @@ -416,17 +406,17 @@ sys_ntp_adjtime(struct thread *td, struct ntp_adjtime_ if (modes & MOD_CLKA) time_status &= ~STA_CLK; if (modes & MOD_FREQUENCY) { - freq = (ntv.freq * 1000LL) >> 16; + freq = (ntv->freq * 1000LL) >> 16; if (freq > MAXFREQ) L_LINT(time_freq, MAXFREQ); else if (freq < -MAXFREQ) L_LINT(time_freq, -MAXFREQ); else { /* - * ntv.freq is [PPM * 2^16] = [us/s * 2^16] + * ntv->freq is [PPM * 2^16] = [us/s * 2^16] * time_freq is [ns/s * 2^32] */ - time_freq = ntv.freq * 1000LL * 65536LL; + time_freq = ntv->freq * 1000LL * 65536LL; } #ifdef PPS_SYNC pps_freq = time_freq; @@ -434,9 +424,9 @@ sys_ntp_adjtime(struct thread *td, struct ntp_adjtime_ } if (modes & MOD_OFFSET) { if (time_status & STA_NANO) - hardupdate(ntv.offset); + hardupdate(ntv->offset); else - hardupdate(ntv.offset * 1000); + hardupdate(ntv->offset * 1000); } /* @@ -444,38 +434,60 @@ sys_ntp_adjtime(struct thread *td, struct ntp_adjtime_ * returned only by ntp_gettime(); */ if (time_status & STA_NANO) - ntv.offset = L_GINT(time_offset); + ntv->offset = L_GINT(time_offset); else - ntv.offset = L_GINT(time_offset) / 1000; /* XXX rounding ? */ - ntv.freq = L_GINT((time_freq / 1000LL) << 16); - ntv.maxerror = time_maxerror; - ntv.esterror = time_esterror; - ntv.status = time_status; - ntv.constant = time_constant; + ntv->offset = L_GINT(time_offset) / 1000; /* XXX rounding ? */ + ntv->freq = L_GINT((time_freq / 1000LL) << 16); + ntv->maxerror = time_maxerror; + ntv->esterror = time_esterror; + ntv->status = time_status; + ntv->constant = time_constant; if (time_status & STA_NANO) - ntv.precision = time_precision; + ntv->precision = time_precision; else - ntv.precision = time_precision / 1000; - ntv.tolerance = MAXFREQ * SCALE_PPM; + ntv->precision = time_precision / 1000; + ntv->tolerance = MAXFREQ * SCALE_PPM; #ifdef PPS_SYNC - ntv.shift = pps_shift; - ntv.ppsfreq = L_GINT((pps_freq / 1000LL) << 16); + ntv->shift = pps_shift; + ntv->ppsfreq = L_GINT((pps_freq / 1000LL) << 16); if (time_status & STA_NANO) - ntv.jitter = pps_jitter; + ntv->jitter = pps_jitter; else - ntv.jitter = pps_jitter / 1000; - ntv.stabil = pps_stabil; - ntv.calcnt = pps_calcnt; - ntv.errcnt = pps_errcnt; - ntv.jitcnt = pps_jitcnt; - ntv.stbcnt = pps_stbcnt; + ntv->jitter = pps_jitter / 1000; + ntv->stabil = pps_stabil; + ntv->calcnt = pps_calcnt; + ntv->errcnt = pps_errcnt; + ntv->jitcnt = pps_jitcnt; + ntv->stbcnt = pps_stbcnt; #endif /* PPS_SYNC */ retval = ntp_is_time_error(time_status) ? TIME_ERROR : time_state; NTP_UNLOCK(); - error = copyout((caddr_t)&ntv, (caddr_t)uap->tp, sizeof(ntv)); - if (error == 0) - td->td_retval[0] = retval; + *retvalp = retval; + return (0); +} + +#ifndef _SYS_SYSPROTO_H_ +struct ntp_adjtime_args { + struct timex *tp; +}; +#endif + +int +sys_ntp_adjtime(struct thread *td, struct ntp_adjtime_args *uap) +{ + struct timex ntv; + int error, retval; + + error = copyin(uap->tp, &ntv, sizeof(ntv)); + if (error == 0) { + error = kern_ntp_adjtime(td, &ntv, &retval); + if (error == 0) { + error = copyout(&ntv, uap->tp, sizeof(ntv)); + if (error == 0) + td->td_retval[0] = retval; + } + } return (error); } Modified: stable/12/sys/sys/syscallsubr.h ============================================================================== --- stable/12/sys/sys/syscallsubr.h Fri Dec 11 00:30:41 2020 (r368538) +++ stable/12/sys/sys/syscallsubr.h Fri Dec 11 00:35:04 2020 (r368539) @@ -61,6 +61,7 @@ union semun; struct sockaddr; struct stat; struct thr_param; +struct timex; struct uio; struct vm_map; struct vmspace; @@ -198,6 +199,7 @@ int kern_munlock(struct thread *td, uintptr_t addr, si int kern_munmap(struct thread *td, uintptr_t addr, size_t size); int kern_nanosleep(struct thread *td, struct timespec *rqt, struct timespec *rmt); +int kern_ntp_adjtime(struct thread *td, struct timex *ntv, int *retvalp); int kern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap, long *ploff); int kern_openat(struct thread *td, int fd, char *path,