From f7bb4f88c566071bb1632ff62fb2cf2f73aa7fa8 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 7 Aug 2020 18:21:48 +0000 Subject: [PATCH 1/5] Remove obsolete part of comment. It was cut and pasted from the old version of this function, and was never relevant to the new version. --- sys/kern/subr_bus.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 4bf772a9a94a..8f3e9f90325d 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -860,8 +860,6 @@ sysctl_devctl_queue(SYSCTL_HANDLER_ARGS) * The devctl protocol relies on quoted strings having matching quotes. * This routine quotes any internal quotes so the resulting string * is safe to pass to snprintf to construct, for example pnp info strings. - * Strings are always terminated with a NUL, but may be truncated if longer - * than @p len bytes after quotes. * * @param sb sbuf to place the characters into * @param src Original buffer. From a45663832633a75995d411ee3a49afdaec059379 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Fri, 7 Aug 2020 18:38:10 +0000 Subject: [PATCH 2/5] Add some more checks to make APEI driver more robust. MFC after: 5 days --- sys/dev/acpica/acpi_apei.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/sys/dev/acpica/acpi_apei.c b/sys/dev/acpica/acpi_apei.c index 5cc08b4137f1..c67b02ca84ac 100644 --- a/sys/dev/acpica/acpi_apei.c +++ b/sys/dev/acpica/acpi_apei.c @@ -348,7 +348,7 @@ apei_ge_handler(struct apei_ge *ge, bool copy) uint32_t sev; int i, c, off; - if (ges->BlockStatus == 0) + if (ges == NULL || ges->BlockStatus == 0) return (0); c = (ges->BlockStatus >> 4) & 0x3ff; @@ -363,7 +363,8 @@ apei_ge_handler(struct apei_ge *ge, bool copy) /* Acknowledge the error has been processed. */ ges->BlockStatus = 0; - if (!copy && ge->v1.Header.Type == ACPI_HEST_TYPE_GENERIC_ERROR_V2) { + if (!copy && ge->v1.Header.Type == ACPI_HEST_TYPE_GENERIC_ERROR_V2 && + ge->res2) { uint64_t val = READ8(ge->res2, 0); val &= ge->v2.ReadAckPreserve; val |= ge->v2.ReadAckWrite; @@ -395,7 +396,7 @@ apei_nmi_handler(void) return (0); ges = (ACPI_HEST_GENERIC_STATUS *)ge->buf; - if (ges->BlockStatus == 0) + if (ges == NULL || ges->BlockStatus == 0) return (0); /* If ACPI told the error is fatal -- make it so. */ @@ -409,7 +410,8 @@ apei_nmi_handler(void) /* Acknowledge the error has been processed. */ ges->BlockStatus = 0; - if (ge->v1.Header.Type == ACPI_HEST_TYPE_GENERIC_ERROR_V2) { + if (ge->v1.Header.Type == ACPI_HEST_TYPE_GENERIC_ERROR_V2 && + ge->res2) { uint64_t val = READ8(ge->res2, 0); val &= ge->v2.ReadAckPreserve; val |= ge->v2.ReadAckWrite; @@ -608,13 +610,19 @@ apei_attach(device_t dev) ge->res_rid = rid++; acpi_bus_alloc_gas(dev, &ge->res_type, &ge->res_rid, &ge->v1.ErrorStatusAddress, &ge->res, 0); + if (ge->res) { + ge->buf = pmap_mapdev_attr(READ8(ge->res, 0), + ge->v1.ErrorBlockLength, VM_MEMATTR_WRITE_COMBINING); + } else { + device_printf(dev, "Can't allocate status resource.\n"); + } if (ge->v1.Header.Type == ACPI_HEST_TYPE_GENERIC_ERROR_V2) { ge->res2_rid = rid++; acpi_bus_alloc_gas(dev, &ge->res2_type, &ge->res2_rid, &ge->v2.ReadAckRegister, &ge->res2, 0); + if (ge->res2 == NULL) + device_printf(dev, "Can't allocate ack resource.\n"); } - ge->buf = pmap_mapdev_attr(READ8(ge->res, 0), - ge->v1.ErrorBlockLength, VM_MEMATTR_WRITE_COMBINING); if (ge->v1.Notify.Type == ACPI_HEST_NOTIFY_POLLED) { callout_init(&ge->poll, 1); callout_reset(&ge->poll, @@ -652,7 +660,10 @@ apei_detach(device_t dev) while ((ge = TAILQ_FIRST(&sc->ges)) != NULL) { TAILQ_REMOVE(&sc->ges, ge, link); - bus_release_resource(dev, ge->res_type, ge->res_rid, ge->res); + if (ge->res) { + bus_release_resource(dev, ge->res_type, + ge->res_rid, ge->res); + } if (ge->res2) { bus_release_resource(dev, ge->res2_type, ge->res2_rid, ge->res2); @@ -663,7 +674,10 @@ apei_detach(device_t dev) swi_remove(&ge->swi_ih); free(ge->copybuf, M_DEVBUF); } - pmap_unmapdev((vm_offset_t)ge->buf, ge->v1.ErrorBlockLength); + if (ge->buf) { + pmap_unmapdev((vm_offset_t)ge->buf, + ge->v1.ErrorBlockLength); + } free(ge, M_DEVBUF); } return (0); From c34e4b5c63f57c3c4d55b3ba419fc563ee4eabf0 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Fri, 7 Aug 2020 18:40:56 +0000 Subject: [PATCH 3/5] Enable hw.pci.enable_aspm tunable by default. While effects on power saving is only a guess, effects on hot-plug are clearly visible. Lets try to enable it and see what happen. MFC after: 3 months --- sys/dev/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 379ad427b6b6..89e484404727 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -408,7 +408,7 @@ static int pci_enable_ari = 1; SYSCTL_INT(_hw_pci, OID_AUTO, enable_ari, CTLFLAG_RDTUN, &pci_enable_ari, 0, "Enable support for PCIe Alternative RID Interpretation"); -int pci_enable_aspm; +int pci_enable_aspm = 1; SYSCTL_INT(_hw_pci, OID_AUTO, enable_aspm, CTLFLAG_RDTUN, &pci_enable_aspm, 0, "Enable support for PCIe Active State Power Management"); From 69bc4fa916a9bd02b44e1e7f8814b12437592401 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Fri, 7 Aug 2020 18:48:56 +0000 Subject: [PATCH 4/5] script: Put the terminal in raw mode when playing back a session. Otherwise recorded sessions of some interactive programs do not play back properly. PR: 248377 Submitted by: Soumendra Ganguly <0.gangzta@gmail.com> MFC after: 1 week --- usr.bin/script/script.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index d05bd3d6040a..8d22ea4251e7 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -427,6 +427,33 @@ consume(FILE *fp, off_t len, char *buf, int reg) } \ } while (0/*CONSTCOND*/) +static void +termset(void) +{ + struct termios traw; + + if (tcgetattr(STDOUT_FILENO, &tt) == -1) { + if (errno == EBADF) + err(1, "%d not valid fd", STDOUT_FILENO); + /* errno == ENOTTY */ + return; + } + ttyflg = 1; + traw = tt; + cfmakeraw(&traw); + traw.c_lflag |= ISIG; + (void)tcsetattr(STDOUT_FILENO, TCSANOW, &traw); +} + +static void +termreset(void) +{ + if (ttyflg) { + tcsetattr(STDOUT_FILENO, TCSADRAIN, &tt); + ttyflg = 0; + } +} + static void playback(FILE *fp) { @@ -470,8 +497,11 @@ playback(FILE *fp) ctime(&tclock)); tsi = tso; (void)consume(fp, stamp.scr_len, buf, reg); + termset(); + atexit(termreset); break; case 'e': + termreset(); if (!qflg) (void)printf("\nScript done on %s", ctime(&tclock)); From 21673cf0bd5bf8aeb683a81cb4c5ee4c7822ffd0 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 7 Aug 2020 19:32:54 +0000 Subject: [PATCH 5/5] Fix clang 11 inline asm constraint error when building powerpc GENERIC64 kernels: sys/powerpc/aim/mmu_radix.c:728:19: error: invalid operand for inline asm constraint 'i' __asm __volatile(PPC_TLBIEL(%0, %1, %2, %3, 1) ^ sys/powerpc/aim/mmu_radix.c:149:3: note: expanded from macro 'PPC_TLBIEL' __XSTRING(.long PPC_INST_TLBIEL | \ ^ sys/sys/cdefs.h:161:22: note: expanded from macro '__XSTRING' #define __XSTRING(x) __STRING(x) /* expand x, then stringify */ ^ sys/sys/cdefs.h:160:21: note: expanded from macro '__STRING' #define __STRING(x) #x /* stringify without expanding x */ ^ :112:1: note: expanded from here ".long 0x7c000224 | (((%0) & 0x1f) << 11) | (((%1) & 0x1f) << 21) | (((%2) & 0x3) << 18) | (((%3) & 0x1) << 17) | (((1) & 0x1) << 16)" ^ This is solved by making the affected inline functions __always_inline. Suggested by: jhibbits MFC after: 3 days --- sys/powerpc/aim/mmu_radix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/powerpc/aim/mmu_radix.c b/sys/powerpc/aim/mmu_radix.c index ee30c3e52b82..1b7d7412b234 100644 --- a/sys/powerpc/aim/mmu_radix.c +++ b/sys/powerpc/aim/mmu_radix.c @@ -183,7 +183,7 @@ ttusync(void) * Invalidate a range of translations */ -static __inline void +static __always_inline void radix_tlbie(uint8_t ric, uint8_t prs, uint16_t is, uint32_t pid, uint32_t lpid, vm_offset_t va, uint16_t ap) { @@ -715,7 +715,7 @@ static struct md_page pv_dummy; static int powernv_enabled = 1; -static inline void +static __always_inline void tlbiel_radix_set_isa300(uint32_t set, uint32_t is, uint32_t pid, uint32_t ric, uint32_t prs) {