lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CY8PR11MB736402AC980408384A213960C43F2@CY8PR11MB7364.namprd11.prod.outlook.com>
Date: Mon, 1 Apr 2024 13:07:56 +0000
From: "D, Lakshmi Sowjanya" <lakshmi.sowjanya.d@...el.com>
To: Thomas Gleixner <tglx@...utronix.de>, "jstultz@...gle.com"
	<jstultz@...gle.com>, "giometti@...eenne.com" <giometti@...eenne.com>,
	"corbet@....net" <corbet@....net>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>
CC: "x86@...nel.org" <x86@...nel.org>, "netdev@...r.kernel.org"
	<netdev@...r.kernel.org>, "linux-doc@...r.kernel.org"
	<linux-doc@...r.kernel.org>, "intel-wired-lan@...ts.osuosl.org"
	<intel-wired-lan@...ts.osuosl.org>, "andriy.shevchenko@...ux.intel.com"
	<andriy.shevchenko@...ux.intel.com>, "Dong, Eddie" <eddie.dong@...el.com>,
	"Hall, Christopher S" <christopher.s.hall@...el.com>, "Brandeburg, Jesse"
	<jesse.brandeburg@...el.com>, "davem@...emloft.net" <davem@...emloft.net>,
	"alexandre.torgue@...s.st.com" <alexandre.torgue@...s.st.com>,
	"joabreu@...opsys.com" <joabreu@...opsys.com>, "mcoquelin.stm32@...il.com"
	<mcoquelin.stm32@...il.com>, "perex@...ex.cz" <perex@...ex.cz>,
	"linux-sound@...r.kernel.org" <linux-sound@...r.kernel.org>, "Nguyen, Anthony
 L" <anthony.l.nguyen@...el.com>, "peter.hilber@...nsynergy.com"
	<peter.hilber@...nsynergy.com>, "N, Pandith" <pandith.n@...el.com>,
	"Sangannavar, Mallikarjunappa" <mallikarjunappa.sangannavar@...el.com>,
	"Mohan, Subramanian" <subramanian.mohan@...el.com>, "Goudar, Basavaraj"
	<basavaraj.goudar@...el.com>, "T R, Thejesh Reddy"
	<thejesh.reddy.t.r@...el.com>
Subject: RE: [PATCH v5 02/11] timekeeping: Add function to convert realtime to
 base clock



> -----Original Message-----
> From: Thomas Gleixner <tglx@...utronix.de>
> Sent: Thursday, March 21, 2024 8:23 PM
> To: D, Lakshmi Sowjanya <lakshmi.sowjanya.d@...el.com>;
> jstultz@...gle.com; giometti@...eenne.com; corbet@....net; linux-
> kernel@...r.kernel.org
> Cc: x86@...nel.org; netdev@...r.kernel.org; linux-doc@...r.kernel.org; intel-
> wired-lan@...ts.osuosl.org; andriy.shevchenko@...ux.intel.com; Dong, Eddie
> <eddie.dong@...el.com>; Hall, Christopher S <christopher.s.hall@...el.com>;
> Brandeburg, Jesse <jesse.brandeburg@...el.com>; davem@...emloft.net;
> alexandre.torgue@...s.st.com; joabreu@...opsys.com;
> mcoquelin.stm32@...il.com; perex@...ex.cz; linux-sound@...r.kernel.org;
> Nguyen, Anthony L <anthony.l.nguyen@...el.com>;
> peter.hilber@...nsynergy.com; N, Pandith <pandith.n@...el.com>;
> Sangannavar, Mallikarjunappa <mallikarjunappa.sangannavar@...el.com>;
> Mohan, Subramanian <subramanian.mohan@...el.com>; Goudar, Basavaraj
> <basavaraj.goudar@...el.com>; T R, Thejesh Reddy
> <thejesh.reddy.t.r@...el.com>; D, Lakshmi Sowjanya
> <lakshmi.sowjanya.d@...el.com>
> Subject: Re: [PATCH v5 02/11] timekeeping: Add function to convert realtime to
> base clock
> 
> On Tue, Mar 19 2024 at 18:35, lakshmi.sowjanya.d@...el.com wrote:
> > +bool ktime_real_to_base_clock(ktime_t treal, enum clocksource_ids
> > +base_id, u64 *cycles) {
> > +	struct timekeeper *tk = &tk_core.timekeeper;
> > +	unsigned int seq;
> > +	u64 delta;
> > +
> > +	do {
> > +		seq = read_seqcount_begin(&tk_core.seq);
> > +		delta = (u64)treal - tk->tkr_mono.base_real;
> > +		if (delta > tk->tkr_mono.clock->max_idle_ns)
> > +			return false;
> 
> I don't think this cutoff is valid. There is no guarantee that this is linear unless:
> 
>        Treal[last timekeeper update] <= treal < Treal[next timekeeper update]
> 
> Look at the dance in get_device_system_crosststamp() and
> adjust_historical_crosststamp() to see why.
> 
> > +		*cycles = tk->tkr_mono.cycle_last + convert_ns_to_cs(delta);
> > +		if (!convert_cs_to_base(cycles, base_id))
> > +			return false;
> > +	} while (read_seqcount_retry(&tk_core.seq, seq));
> > +
> > +	return true;
> > +}
> > +EXPORT_SYMBOL_GPL(ktime_real_to_base_clock);
> 
> Looking at the usage site:
> 
> > +static bool pps_generate_next_pulse(struct pps_tio *tio, ktime_t
> > +expires) {
> > +	u64 art;
> > +
> > +	if (!ktime_real_to_base_clock(expires, CSID_X86_ART, &art)) {
> > +		pps_tio_disable(tio);
> 
> I'm pretty sure this can happen when there is sufficient delay between the check
> for (now - expires < SAFE_TIME_NS) and the delta computation in
> ktime_real_to_base_clock() if there is a timerkeeper update interleaving which
> brings tkr_mono.base_real in front of expires.
> 
> Is that intentional and correct?
> 
> If so, then it's inconsistent with the behaviour of the hrtimer
> callback:
> 
> > +		return false;
> > +	}
> > +
> > +	pps_compv_write(tio, art - ART_HW_DELAY_CYCLES);
> > +	return true;
> > +}
> > +
> > +static enum hrtimer_restart hrtimer_callback(struct hrtimer *timer) {
> > +	struct pps_tio *tio = container_of(timer, struct pps_tio, timer);
> > +	ktime_t expires, now;
> > +
> > +	guard(spinlock)(&tio->lock);
> > +
> > +	expires = hrtimer_get_expires(timer);
> > +	now = ktime_get_real();
> > +
> > +	if (now - expires < SAFE_TIME_NS) {
> > +		if (!pps_generate_next_pulse(tio, expires + SAFE_TIME_NS))
> > +			return HRTIMER_NORESTART;
> > +	}
> 
> This safe guard does not care about time being set. I'm not familiar with the PPS
> logic, but is it expected that the pulse pattern will be like this:
> 
> 
> 
>     ---|-----|-----|-----|----------------->
>        P     P  ^        P
>                 |
>         clock_settime(CLOCK_REALTIME, now - 2 seconds)
> 
>         Obviously the pulse gap will be as big as the time is set
>         backwards, which might be way more than 2 seconds.
> 
> 
>     ---|-----|-----|-----|----------------->
>        P     P  ^  P     P
>                 |
>         clock_settime(CLOCK_REALTIME, now + 2 seconds)
> 
> I don't see anything in this code which cares about CLOCK_REALTIME being set
> via clock_settime() or adjtimex().
> 
> Aside of that I have a question about how the TIO hardware treats this
> case:
> 
>    ktime_real_to_base_clock(expires, &art);
> 
> -> GAP which makes @art get into the past
> 
>    pps_compv_write(tio, art - ART_HW_DELAY_CYCLES);
> 
> Will the hardware ignore that already expired value or just emit a pulse
> immediately? In the latter case the pulse will be at a random point in time, which
> does not sound correct.

Thanks for the review Thomas,

If an expired time is programmed to hardware, it ignores and no pulse is generated.
There is an event counter feature in hardware, this increments on every pulse sent. In next version of driver, we will be monitoring this counter to detect any missed pulse and disable the hardware.

Regards,
Sowjanya

> 
> Thanks,
> 
>         tglx

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ