From nobody Tue Jan 07 23:37:12 2025 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 4YSSBl3LnXz5k9hG; Tue, 07 Jan 2025 23:37:19 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YSSBl16Lqz4Ltw; Tue, 7 Jan 2025 23:37:19 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-7b6f7d7e128so28375485a.1; Tue, 07 Jan 2025 15:37:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736293037; x=1736897837; darn=freebsd.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=7ihSRgA7/ifvdJJ8avXnMfnFD4sLB6o/6k55ckvtuQM=; b=YpwyE4MCvWQI1p5RXRI98wDoAbJKGNAYSWzU91dapX8YdJ/x0tXejf+XIf0GOtjOTh 4sRoB6KlT9UtIakssBX8ndw/9Gvzs5EjdJIyqVCzDdW/Zk5pH+WDNiz8fjvMSzsK9hKi kfm44PS0agGWab2Pl/1+02ZXWJEIFzOOdKRlt+Vcv4lZhmmQnkT38nw6+osxsvjrkj5m pkNPLpYrk1nkbfXotVTnRAmFCRxKgvsg22I6O+Da4PLrRi06rL4GbS83OAthrJCFmniY kEoZI3SNjfqIeYU7nOanvZVhF2bdC8z+/91DQNkfvJ0mwkhQYARXVg+9of4543b3cHMU ilsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736293037; x=1736897837; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7ihSRgA7/ifvdJJ8avXnMfnFD4sLB6o/6k55ckvtuQM=; b=sRv3CybEWWwkhatWdl74A6VbPxv8m2m06eaBLYdteJkg/PUhrCPg25G2OMjjRfhrpK pjTkD7H1Jf9c1a0MQQGMXLFrDYOb7WuwZn6zJguVoXt5Z+VQRpE9Jr/upoZ1KttXMXYv RIxMAE/F8rBYaiOs6w57PMNEbYxf/KCYA8I/e1FZ5rgLB3jdZcRTLJFnZFFwDK1LtvcQ wTgKm+NTseaV4l8e3sUno8XTCcN49cugoL5hLAuAZZSuPqxjS/YsEdLwHK4VZjnY480n h2FEvUw0eBAyjvXB3Z6tswMHfYPTd3fu/YxpjHgguaSaFvw8J89wa2/ls4pf7akRyYPr SlUQ== X-Forwarded-Encrypted: i=1; AJvYcCUiAxHEiXj3NH3H7RU83YQC3CiBjjl0PEMUK63OZ7hiqykNoPUFZpZzBPQEdaWlckKNJojGf3ZpQaHrxGJj/B6Glw/JBXg=@freebsd.org, AJvYcCWJnpMG+fivZpi1mTMdschxIebMUhOZU/kZlRPf/xwpTi+qDxU5GWvwWnYrs/RAoBz61C7M+XKny3BiJ846cnhRdnyz@freebsd.org X-Gm-Message-State: AOJu0YxmUW/UbgS8y1HDxinTnZQGSDjKbjx6Dk9CzuLjizJqXWZuOYk8 VAmB9J5kBnYd7osQ0RxtjtDaC6SarfsXC0o50/uPfgzHI9c+nBHtDk4iWg== X-Gm-Gg: ASbGncuizCtv/PfAqseiPQ688UU6ilzq70EC4UcnFa+AUlWZf6Tj4mrk/vr20nA8KSt VBejXmY9BHffym1Ryn1RNr3QvQCItv0Z0HHNZ+pPaHfBU2Ab0r4OP5z+6XGVqDLGcClJGbltnQv T5z4rRU8Ipu8uXH1qBJ9WVKxuR61mTyDFa5B1HYfLI3WXhwJ8sNHK7zsxlRtlMDc+6Vdsl+fWvA 5tEmrdw5mWdhgAbZRfnBxcMiwdAJBzMDHKHXxw9HiDPb2dFvoiFp+94ThS5w7ZlGjjzHZU= X-Google-Smtp-Source: AGHT+IFwp5iIick905ywLQC0ve3V6TVDZHLlJr8M2Dhi9jAzF3av7c0tvajK7RnWtfOThu+kpodQfw== X-Received: by 2002:ad4:4eec:0:b0:6d8:94f4:d2aa with SMTP id 6a1803df08f44-6df8e822bddmr86311196d6.13.1736293035975; Tue, 07 Jan 2025 15:37:15 -0800 (PST) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd181bb525sm185598206d6.97.2025.01.07.15.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 15:37:15 -0800 (PST) Date: Tue, 7 Jan 2025 18:37:12 -0500 From: Mark Johnston To: "Bjoern A. Zeeb" Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: fd27f86dd71b - main - LinuxKPI: switch jiffies and timer->expire to unsigned long Message-ID: References: <202501072247.507MlsLu036332@gitrepo.freebsd.org> 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202501072247.507MlsLu036332@gitrepo.freebsd.org> X-Rspamd-Queue-Id: 4YSSBl16Lqz4Ltw X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] On Tue, Jan 07, 2025 at 10:47:54PM +0000, Bjoern A. Zeeb wrote: > The branch main has been updated by bz: > > URL: https://cgit.FreeBSD.org/src/commit/?id=fd27f86dd71b7ff1df6981297095b88d1d29652e > > commit fd27f86dd71b7ff1df6981297095b88d1d29652e > Author: Bjoern A. Zeeb > AuthorDate: 2024-12-28 09:57:56 +0000 > Commit: Bjoern A. Zeeb > CommitDate: 2025-01-07 20:00:20 +0000 > > LinuxKPI: switch jiffies and timer->expire to unsigned long > > It seems these functions work with unsigned long and not int in Linux. > Start simply replacing the int where I came across it while debugging > a wireless driver timer modification. Also sprinkle in some "const". > > Sponsored by: The FreeBSD Foundation > MFC after: 2 weeks > Reviewed by: emaste > Differential Revision: https://reviews.freebsd.org/D48318 > --- > sys/compat/linuxkpi/common/include/linux/jiffies.h | 28 +++++++++++----------- > sys/compat/linuxkpi/common/include/linux/timer.h | 4 ++-- > sys/compat/linuxkpi/common/src/linux_compat.c | 2 +- > 3 files changed, 17 insertions(+), 17 deletions(-) > > diff --git a/sys/compat/linuxkpi/common/include/linux/jiffies.h b/sys/compat/linuxkpi/common/include/linux/jiffies.h > index bd05a0db0767..8346e74fb830 100644 > --- a/sys/compat/linuxkpi/common/include/linux/jiffies.h > +++ b/sys/compat/linuxkpi/common/include/linux/jiffies.h > @@ -38,7 +38,7 @@ > > #define jiffies ticks There is a fundamental incompatibility here: jiffies is an unsigned long but ticks is an int. Historically that was the source of some very painful-to-find bugs in the IB stack, since the difference mostly arises when one has to deal with ticks rollover, a rare event. It doesn't make a lot of sense to me to partially convert some routines to using unsigned long if we're not going to do it everywhere, especially if there isn't a concrete bug being fixed. With this diff, jiffies is still an int, and various macros like time_after() still cast their result to a 32-bit value, so at a glance it seems incomplete. I also suspect that the delta < 1 check in linux_timer_jiffies_until() is now broken. I'd advise against a change like this unless you're very confident in it: it's easy to introduce rare bugs. The real solution IMO is have a native 64-bit tick counter that we can use directly in the linuxkpi layer. > #define jiffies_64 ticks > -#define jiffies_to_msecs(x) ((unsigned int)(((int64_t)(int)(x)) * 1000 / hz)) > +#define jiffies_to_msecs(x) ((unsigned int)(((int64_t)(unsigned long)(x)) * 1000 / hz)) > > #define MAX_JIFFY_OFFSET ((INT_MAX >> 1) - 1) > > @@ -68,7 +68,7 @@ extern uint64_t lkpi_msec2hz_rem; > extern uint64_t lkpi_msec2hz_div; > extern uint64_t lkpi_msec2hz_max; > > -static inline int > +static inline unsigned long > timespec_to_jiffies(const struct timespec *ts) > { > u64 result; > @@ -78,10 +78,10 @@ timespec_to_jiffies(const struct timespec *ts) > if (result > MAX_JIFFY_OFFSET) > result = MAX_JIFFY_OFFSET; > > - return ((int)result); > + return ((unsigned long)result); > } > > -static inline int > +static inline unsigned long > msecs_to_jiffies(uint64_t msec) > { > uint64_t result; > @@ -92,10 +92,10 @@ msecs_to_jiffies(uint64_t msec) > if (result > MAX_JIFFY_OFFSET) > result = MAX_JIFFY_OFFSET; > > - return ((int)result); > + return ((unsigned long)result); > } > > -static inline int > +static inline unsigned long > usecs_to_jiffies(uint64_t usec) > { > uint64_t result; > @@ -106,7 +106,7 @@ usecs_to_jiffies(uint64_t usec) > if (result > MAX_JIFFY_OFFSET) > result = MAX_JIFFY_OFFSET; > > - return ((int)result); > + return ((unsigned long)result); > } > > static inline uint64_t > @@ -133,17 +133,17 @@ nsecs_to_jiffies(uint64_t nsec) > } > > static inline uint64_t > -jiffies_to_nsecs(int j) > +jiffies_to_nsecs(const unsigned long j) > { > > - return ((1000000000ULL / hz) * (uint64_t)(unsigned int)j); > + return ((1000000000ULL / hz) * (const uint64_t)j); > } > > static inline uint64_t > -jiffies_to_usecs(int j) > +jiffies_to_usecs(const unsigned long j) > { > > - return ((1000000ULL / hz) * (uint64_t)(unsigned int)j); > + return ((1000000ULL / hz) * (const uint64_t)j); > } > > static inline uint64_t > @@ -153,10 +153,10 @@ get_jiffies_64(void) > return ((uint64_t)(unsigned int)ticks); > } > > -static inline int > -linux_timer_jiffies_until(int expires) > +static inline unsigned long > +linux_timer_jiffies_until(unsigned long expires) > { > - int delta = expires - jiffies; > + unsigned long delta = expires - jiffies; > /* guard against already expired values */ > if (delta < 1) > delta = 1; > diff --git a/sys/compat/linuxkpi/common/include/linux/timer.h b/sys/compat/linuxkpi/common/include/linux/timer.h > index 8bea082c3e6c..f9c76222795c 100644 > --- a/sys/compat/linuxkpi/common/include/linux/timer.h > +++ b/sys/compat/linuxkpi/common/include/linux/timer.h > @@ -42,7 +42,7 @@ struct timer_list { > void (*function_415) (struct timer_list *); > }; > unsigned long data; > - int expires; > + unsigned long expires; > }; > > extern unsigned long linux_timer_hz_mask; > @@ -76,7 +76,7 @@ extern unsigned long linux_timer_hz_mask; > callout_init(&(timer)->callout, 1); \ > } while (0) > > -extern int mod_timer(struct timer_list *, int); > +extern int mod_timer(struct timer_list *, unsigned long); > extern void add_timer(struct timer_list *); > extern void add_timer_on(struct timer_list *, int cpu); > extern int del_timer(struct timer_list *); > diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c > index ec3ccb16b47d..35cb2fc2f3d7 100644 > --- a/sys/compat/linuxkpi/common/src/linux_compat.c > +++ b/sys/compat/linuxkpi/common/src/linux_compat.c > @@ -1938,7 +1938,7 @@ linux_timer_callback_wrapper(void *context) > } > > int > -mod_timer(struct timer_list *timer, int expires) > +mod_timer(struct timer_list *timer, unsigned long expires) > { > int ret; >