Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/x86/intel/pmt: Sapphire Rapids PMT errata fix

On Sapphire Rapids, due to a hardware issue affecting the PUNIT telemetry
region, reads that are not done in QWORD quantities and alignment may
return incorrect data. Use a custom 64-bit copy for this region.

Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Link: https://lore.kernel.org/r/20221105034228.1376677-1-david.e.box@linux.intel.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

David E. Box and committed by
Hans de Goede
bcdfa1f7 1598bfa8

+30 -1
+30 -1
drivers/platform/x86/intel/pmt/class.c
··· 9 9 */ 10 10 11 11 #include <linux/kernel.h> 12 + #include <linux/io-64-nonatomic-lo-hi.h> 12 13 #include <linux/module.h> 13 14 #include <linux/mm.h> 14 15 #include <linux/pci.h> ··· 20 19 #define PMT_XA_START 0 21 20 #define PMT_XA_MAX INT_MAX 22 21 #define PMT_XA_LIMIT XA_LIMIT(PMT_XA_START, PMT_XA_MAX) 22 + #define GUID_SPR_PUNIT 0x9956f43f 23 23 24 24 bool intel_pmt_is_early_client_hw(struct device *dev) 25 25 { ··· 34 32 return !!(ivdev->info->quirks & VSEC_QUIRK_EARLY_HW); 35 33 } 36 34 EXPORT_SYMBOL_GPL(intel_pmt_is_early_client_hw); 35 + 36 + static inline int 37 + pmt_memcpy64_fromio(void *to, const u64 __iomem *from, size_t count) 38 + { 39 + int i, remain; 40 + u64 *buf = to; 41 + 42 + if (!IS_ALIGNED((unsigned long)from, 8)) 43 + return -EFAULT; 44 + 45 + for (i = 0; i < count/8; i++) 46 + buf[i] = readq(&from[i]); 47 + 48 + /* Copy any remaining bytes */ 49 + remain = count % 8; 50 + if (remain) { 51 + u64 tmp = readq(&from[i]); 52 + 53 + memcpy(&buf[i], &tmp, remain); 54 + } 55 + 56 + return count; 57 + } 37 58 38 59 /* 39 60 * sysfs ··· 79 54 if (count > entry->size - off) 80 55 count = entry->size - off; 81 56 82 - memcpy_fromio(buf, entry->base + off, count); 57 + if (entry->guid == GUID_SPR_PUNIT) 58 + /* PUNIT on SPR only supports aligned 64-bit read */ 59 + count = pmt_memcpy64_fromio(buf, entry->base + off, count); 60 + else 61 + memcpy_fromio(buf, entry->base + off, count); 83 62 84 63 return count; 85 64 }