Some Intel chipsets disconnect the time and date RTC registers when the
clock update is in progress: during this time reads may return bogus
values and writes fail silently. This includes the RTC alarm registers.
[1]
cmos_read_alarm() and cmos_set_alarm() did not take account for that,
which caused alarm time reads to sometimes return bogus values. This can
be shown with a test patch that I am attaching to this patch series.
Setting the alarm clock also probably did fail sometimes.
To make this patch suitable for inclusion in stable kernels, I'm using a
simple method for avoiding the RTC update cycle. This method is used in
mach_set_rtc_mmss() in arch/x86/kernel/rtc.c. A more elaborate algorithm
- as in mc146818_get_time() in drivers/rtc/rtc-mc146818-lib.c - would be
too complcated for stable. [2]
cmos_wait_for_uip_clear() has the rtc_lock taken while waiting for the
UIP bit to become clear. This should be harmless as during the UIP the RTC
cannot be read from anyway. mach_get_cmos_time() in arch/x86/kernel/rtc.c
does things the same way.
[1] 7th Generation Intel ® Processor Family I/O for U/Y Platforms [...]
Datasheet, Volume 1 of 2 (Intel's Document Number: 334658-006)
Page 208
https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/7th…
"If a RAM read from the ten time and date bytes is attempted
during an update cycle, the value read do not necessarily
represent the true contents of those locations. Any RAM writes
under the same conditions are ignored.'
[2] I'm going to submit a unification patch for a later kernel release -
prefer to see this in stable.
Signed-off-by: Mateusz Jończyk <mat.jonczyk(a)o2.pl>
Cc: Alessandro Zummo <a.zummo(a)towertech.it>
Cc: Alexandre Belloni <alexandre.belloni(a)bootlin.com>
Cc: stable(a)vger.kernel.org
---
drivers/rtc/rtc-cmos.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 2cd0fe728ab2..643433d984ab 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -248,6 +248,31 @@ static int cmos_set_time(struct device *dev, struct rtc_time *t)
return mc146818_set_time(t);
}
+/* Some Intel chipsets disconnect the alarm registers when the clock update is
+ * in progress - during this time reads return bogus values and writes may fail
+ * silently. See for example "7th Generation Intel® Processor Family I/O for
+ * U/Y Platforms [...] Datasheet", section 27.7.1
+ *
+ * Check the UIP bit to prevent this, waiting for max 10ms for it to become
+ * clear.
+ *
+ * This function has to be called with rtc_lock taken.
+ */
+static int cmos_wait_for_uip_clear(struct device *dev)
+{
+ int i;
+
+ for (i = 0; i < 100; i++) {
+ if ((CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) == 0)
+ return 0;
+ udelay(100);
+ }
+
+ dev_warn_ratelimited(dev, "UIP bit is stuck, cannot access RTC registers\n");
+
+ return 1;
+}
+
static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
{
struct cmos_rtc *cmos = dev_get_drvdata(dev);
@@ -257,12 +282,17 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
if (!is_valid_irq(cmos->irq))
return -EIO;
+ spin_lock_irq(&rtc_lock);
+
+ if (cmos_wait_for_uip_clear(dev)) {
+ spin_unlock_irq(&rtc_lock);
+ return -EIO;
+ }
+
/* Basic alarms only support hour, minute, and seconds fields.
* Some also support day and month, for alarms up to a year in
* the future.
*/
-
- spin_lock_irq(&rtc_lock);
t->time.tm_sec = CMOS_READ(RTC_SECONDS_ALARM);
t->time.tm_min = CMOS_READ(RTC_MINUTES_ALARM);
t->time.tm_hour = CMOS_READ(RTC_HOURS_ALARM);
@@ -477,6 +507,10 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
}
spin_lock_irq(&rtc_lock);
+ if (cmos_wait_for_uip_clear(dev)) {
+ spin_unlock_irq(&rtc_lock);
+ return -EIO;
+ }
/* next rtc irq must not be from previous alarm setting */
cmos_irq_disable(cmos, RTC_AIE);
--
2.25.1
Reading from the CMOS involves writing to the index register and then
reading from the data register. Therefore access to the CMOS has to be
serialized with rtc_lock. This invocation of CMOS_READ was not
serialized, which could cause trouble when other code is accessing CMOS
at the same time.
Use spin_lock_irq() like the rest of the function.
Nothing in kernel modifies the RTC_DM_BINARY bit, so there could be a
separate pair of spin_lock_irq() / spin_unlock_irq() before doing the
math.
Signed-off-by: Mateusz Jończyk <mat.jonczyk(a)o2.pl>
Reviewed-by: Nobuhiro Iwamatsu <iwamatsu(a)nigauri.org>
Cc: Alessandro Zummo <a.zummo(a)towertech.it>
Cc: Alexandre Belloni <alexandre.belloni(a)bootlin.com>
Cc: stable(a)vger.kernel.org
---
drivers/rtc/rtc-cmos.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 670fd8a2970e..2cd0fe728ab2 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -463,7 +463,10 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
min = t->time.tm_min;
sec = t->time.tm_sec;
+ spin_lock_irq(&rtc_lock);
rtc_control = CMOS_READ(RTC_CONTROL);
+ spin_unlock_irq(&rtc_lock);
+
if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
/* Writing 0xff means "don't care" or "match all". */
mon = (mon <= 12) ? bin2bcd(mon) : 0xff;
--
2.25.1
This is the start of the stable review cycle for the 5.10.64 release.
There are 26 patches in this series, all will be posted as a response
to this one. If anyone has any issues with these being applied, please
let me know.
Responses should be made by Sun, 12 Sep 2021 12:29:07 +0000.
Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.64-rc…
or in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git linux-5.10.y
and the diffstat can be found below.
thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
Greg Kroah-Hartman <gregkh(a)linuxfoundation.org>
Linux 5.10.64-rc1
Marek Behún <kabel(a)kernel.org>
PCI: Call Max Payload Size-related fixup quirks early
Paul Gortmaker <paul.gortmaker(a)windriver.com>
x86/reboot: Limit Dell Optiplex 990 quirk to early BIOS versions
Mathias Nyman <mathias.nyman(a)linux.intel.com>
xhci: fix unsafe memory usage in xhci tracing
Mathias Nyman <mathias.nyman(a)linux.intel.com>
xhci: fix even more unsafe memory usage in xhci tracing
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: mtu3: fix the wrong HS mult value
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: mtu3: use @mult for HS isoc or intr
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: mtu3: restore HS function when set SS/SSP
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: gadget: tegra-xudc: fix the wrong mult value for HS isoc or intr
Yoshihiro Shimoda <yoshihiro.shimoda.uh(a)renesas.com>
usb: host: xhci-rcar: Don't reload firmware after the completion
Alexander Tsoy <alexander(a)tsoy.me>
ALSA: usb-audio: Add registration quirk for JBL Quantum 800
Ming Lei <ming.lei(a)redhat.com>
blk-mq: clearing flush request reference in tags->rqs[]
Pablo Neira Ayuso <pablo(a)netfilter.org>
netfilter: nftables: clone set element expression template
Pablo Neira Ayuso <pablo(a)netfilter.org>
netfilter: nf_tables: initialize set before expression setup
Eric Dumazet <edumazet(a)google.com>
netfilter: nftables: avoid potential overflows on 32bit arches
Ming Lei <ming.lei(a)redhat.com>
blk-mq: fix is_flush_rq
Ming Lei <ming.lei(a)redhat.com>
blk-mq: fix kernel panic during iterating over flush request
Suravee Suthikulpanit <suravee.suthikulpanit(a)amd.com>
x86/events/amd/iommu: Fix invalid Perf result due to IOMMU PMC power-gating
Hayes Wang <hayeswang(a)realtek.com>
Revert "r8169: avoid link-up interrupt issue on RTL8106e if user enables ASPM"
Jiri Slaby <jirislaby(a)kernel.org>
tty: drop termiox user definitions
Randy Dunlap <rdunlap(a)infradead.org>
net: linux/skbuff.h: combine SKB_EXTENSIONS + KCOV handling
Vignesh Raghavendra <vigneshr(a)ti.com>
serial: 8250: 8250_omap: Fix unused variable warning
Randy Dunlap <rdunlap(a)infradead.org>
net: kcov: don't select SKB_EXTENSIONS when there is no NET
Muchun Song <songmuchun(a)bytedance.com>
mm/page_alloc: speed up the iteration of max_order
Esben Haabendal <esben(a)geanix.com>
net: ll_temac: Remove left-over debug message
Tom Rix <trix(a)redhat.com>
USB: serial: mos7720: improve OOM-handling in read_mos_reg()
Liu Jian <liujian56(a)huawei.com>
igmp: Add ip_mc_list lock in ip_check_mc_rcu
-------------
Diffstat:
Makefile | 4 +-
arch/x86/events/amd/iommu.c | 47 ++++++++-------
arch/x86/kernel/reboot.c | 3 +-
block/blk-core.c | 1 -
block/blk-flush.c | 13 +++++
block/blk-mq.c | 37 +++++++++++-
block/blk.h | 6 +-
drivers/net/ethernet/realtek/r8169_main.c | 1 +
drivers/net/ethernet/xilinx/ll_temac_main.c | 4 +-
drivers/pci/quirks.c | 12 ++--
drivers/tty/serial/8250/8250_omap.c | 26 ++++-----
drivers/usb/gadget/udc/tegra-xudc.c | 4 +-
drivers/usb/host/xhci-debugfs.c | 14 +++--
drivers/usb/host/xhci-rcar.c | 7 +++
drivers/usb/host/xhci-ring.c | 3 +-
drivers/usb/host/xhci-trace.h | 26 +++++----
drivers/usb/host/xhci.h | 73 ++++++++++++-----------
drivers/usb/mtu3/mtu3_core.c | 4 +-
drivers/usb/mtu3/mtu3_gadget.c | 6 +-
drivers/usb/serial/mos7720.c | 4 +-
include/linux/skbuff.h | 4 +-
include/uapi/linux/termios.h | 15 -----
lib/Kconfig.debug | 2 +-
mm/page_alloc.c | 8 +--
net/ipv4/igmp.c | 2 +
net/netfilter/nf_tables_api.c | 89 ++++++++++++++++++-----------
net/netfilter/nft_set_hash.c | 10 ++--
sound/usb/quirks.c | 1 +
28 files changed, 252 insertions(+), 174 deletions(-)
This is the start of the stable review cycle for the 5.14.3 release.
There are 23 patches in this series, all will be posted as a response
to this one. If anyone has any issues with these being applied, please
let me know.
Responses should be made by Sun, 12 Sep 2021 12:29:07 +0000.
Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.14.3-rc1…
or in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git linux-5.14.y
and the diffstat can be found below.
thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
Greg Kroah-Hartman <gregkh(a)linuxfoundation.org>
Linux 5.14.3-rc1
Alison Schofield <alison.schofield(a)intel.com>
cxl/acpi: Do not add DSDT disabled ACPI0016 host bridge ports
Dan Williams <dan.j.williams(a)intel.com>
cxl/pci: Fix lockdown level
Li Qiang (Johnny Li) <johnny.li(a)montage-tech.com>
cxl/pci: Fix debug message in cxl_probe_regs()
Marek Behún <kabel(a)kernel.org>
PCI: Call Max Payload Size-related fixup quirks early
Paul Gortmaker <paul.gortmaker(a)windriver.com>
x86/reboot: Limit Dell Optiplex 990 quirk to early BIOS versions
Sergio Paracuellos <sergio.paracuellos(a)gmail.com>
staging: mt7621-pci: fix hang when nothing is connected to pcie ports
Mathias Nyman <mathias.nyman(a)linux.intel.com>
xhci: Fix failure to give back some cached cancelled URBs.
Mathias Nyman <mathias.nyman(a)linux.intel.com>
xhci: fix unsafe memory usage in xhci tracing
Mathias Nyman <mathias.nyman(a)linux.intel.com>
xhci: fix even more unsafe memory usage in xhci tracing
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: mtu3: fix the wrong HS mult value
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: mtu3: use @mult for HS isoc or intr
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: mtu3: restore HS function when set SS/SSP
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: gadget: tegra-xudc: fix the wrong mult value for HS isoc or intr
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: cdnsp: fix the wrong mult value for HS isoc or intr
Chunfeng Yun <chunfeng.yun(a)mediatek.com>
usb: xhci-mtk: fix issue of out-of-bounds array access
Yoshihiro Shimoda <yoshihiro.shimoda.uh(a)renesas.com>
usb: host: xhci-rcar: Don't reload firmware after the completion
Ismael Ferreras Morezuelas <swyterzone(a)gmail.com>
Bluetooth: btusb: Make the CSR clone chip force-suspend workaround more generic
Larry Finger <Larry.Finger(a)lwfinger.net>
Bluetooth: Add additional Bluetooth part for Realtek 8852AE
Alexander Tsoy <alexander(a)tsoy.me>
ALSA: usb-audio: Add registration quirk for JBL Quantum 800
Hayes Wang <hayeswang(a)realtek.com>
Revert "r8169: avoid link-up interrupt issue on RTL8106e if user enables ASPM"
Liu Jian <liujian56(a)huawei.com>
igmp: Add ip_mc_list lock in ip_check_mc_rcu
Tong Zhang <ztong0001(a)gmail.com>
can: c_can: fix null-ptr-deref on ioctl()
Hans de Goede <hdegoede(a)redhat.com>
firmware: dmi: Move product_sku info to the end of the modalias
-------------
Diffstat:
Makefile | 4 +-
arch/x86/kernel/reboot.c | 3 +-
drivers/bluetooth/btusb.c | 59 ++++++++++++++-----------
drivers/cxl/acpi.c | 12 +++--
drivers/cxl/pci.c | 6 +--
drivers/firmware/dmi-id.c | 6 ++-
drivers/net/can/c_can/c_can_ethtool.c | 4 +-
drivers/net/ethernet/realtek/r8169_main.c | 1 +
drivers/pci/quirks.c | 12 ++---
drivers/staging/mt7621-pci/pci-mt7621.c | 13 +++++-
drivers/usb/cdns3/cdnsp-mem.c | 2 +-
drivers/usb/gadget/udc/tegra-xudc.c | 4 +-
drivers/usb/host/xhci-debugfs.c | 14 ++++--
drivers/usb/host/xhci-mtk-sch.c | 10 +++--
drivers/usb/host/xhci-rcar.c | 7 +++
drivers/usb/host/xhci-ring.c | 43 +++++++++++-------
drivers/usb/host/xhci-trace.h | 26 ++++++-----
drivers/usb/host/xhci.h | 73 +++++++++++++++----------------
drivers/usb/mtu3/mtu3_core.c | 4 +-
drivers/usb/mtu3/mtu3_gadget.c | 6 +--
net/ipv4/igmp.c | 2 +
sound/usb/quirks.c | 1 +
22 files changed, 185 insertions(+), 127 deletions(-)