Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Aug 2018 21:19:07 +0000 (UTC)
From:      Breno Leitao <leitao@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r337503 - head/sys/powerpc/powernv
Message-ID:  <201808082119.w78LJ7Zv021006@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: leitao
Date: Wed Aug  8 21:19:07 2018
New Revision: 337503
URL: https://svnweb.freebsd.org/changeset/base/337503

Log:
  powerpc64/powernv: re-read RTC after polling
  
  If OPAL_RTC_READ is busy and does not return the information on the first run,
  as returning OPAL_BUSY_EVENT, the system will crash since ymd and hmsm variable
  will contain junk values.
  
  This is happening because we were not calling OPAL_RTC_READ again after
  OPAL_POLL_EVENTS' return, which would finally replace the old/junk hmsm and ymd
  values.
  
  The code was also mixing OPAL_RTC_READ and OPAL_POLL_EVENTS return values.
  
  This patch fix this logic and guarantee that we call OPAL_RTC_READ after
  OPAL_POLL_EVENTS return, and guarantee the code will only proceed if
  OPAL_RTC_READ returns OPAL_SUCCESS.
  
  Reviewed by: jhibbits
  Approved by: jhibbits (mentor)
  Differential Revision: https://reviews.freebsd.org/D16617

Modified:
  head/sys/powerpc/powernv/opal_dev.c

Modified: head/sys/powerpc/powernv/opal_dev.c
==============================================================================
--- head/sys/powerpc/powernv/opal_dev.c	Wed Aug  8 20:30:12 2018	(r337502)
+++ head/sys/powerpc/powernv/opal_dev.c	Wed Aug  8 21:19:07 2018	(r337503)
@@ -218,13 +218,12 @@ opal_gettime(device_t dev, struct timespec *ts)
 	uint32_t ymd;
 	uint64_t hmsm;
 
-	do {
+	rv = opal_call(OPAL_RTC_READ, vtophys(&ymd), vtophys(&hmsm));
+	while (rv == OPAL_BUSY_EVENT)  {
+		opal_call(OPAL_POLL_EVENTS, 0);
+		pause("opalrtc", 1);
 		rv = opal_call(OPAL_RTC_READ, vtophys(&ymd), vtophys(&hmsm));
-		if (rv == OPAL_BUSY_EVENT) {
-			rv = opal_call(OPAL_POLL_EVENTS, 0);
-			pause("opalrtc", 1);
-		}
-	} while (rv == OPAL_BUSY_EVENT);
+	}
 
 	if (rv != OPAL_SUCCESS)
 		return (ENXIO);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808082119.w78LJ7Zv021006>