sync code with last fixes and improvements from OpenBSD

This commit is contained in:
purplerain 2023-08-11 09:11:00 +00:00
parent 371ae113c6
commit 454dab66ed
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
95 changed files with 1784 additions and 2042 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: identcpu.c,v 1.135 2023/07/27 01:51:35 guenther Exp $ */
/* $OpenBSD: identcpu.c,v 1.136 2023/08/09 00:01:44 jsg Exp $ */
/* $NetBSD: identcpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $ */
/*
@ -650,6 +650,21 @@ identifycpu(struct cpu_info *ci)
printf(", %02x-%02x-%02x", ci->ci_family, ci->ci_model,
ci->ci_signature & 0x0f);
if ((cpu_ecxfeature & CPUIDECX_HV) == 0) {
uint64_t level = 0;
uint32_t dummy;
if (strcmp(cpu_vendor, "AuthenticAMD") == 0) {
level = rdmsr(MSR_PATCH_LEVEL);
} else if (strcmp(cpu_vendor, "GenuineIntel") == 0) {
wrmsr(MSR_BIOS_SIGN, 0);
CPUID(1, dummy, dummy, dummy, dummy);
level = rdmsr(MSR_BIOS_SIGN) >> 32;
}
if (level != 0)
printf(", patch %08llx", level);
}
printf("\n%s: ", ci->ci_dev->dv_xname);
for (i = 0; i < nitems(cpu_cpuid_features); i++)

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ucode.c,v 1.6 2023/07/23 01:46:37 jsg Exp $ */
/* $OpenBSD: ucode.c,v 1.7 2023/08/09 02:59:41 jsg Exp $ */
/*
* Copyright (c) 2018 Stefan Fritsch <fritsch@genua.de>
* Copyright (c) 2018 Patrick Wildt <patrick@blueri.se>
@ -261,7 +261,7 @@ out:
struct intel_ucode_header *
cpu_ucode_intel_find(char *data, size_t left, uint32_t current)
{
uint64_t platform_id = (rdmsr(MSR_PLATFORM_ID) >> 50) & 0xff;
uint64_t platform_id = (rdmsr(MSR_PLATFORM_ID) >> 50) & 7;
uint32_t sig, dummy1, dummy2, dummy3;
uint32_t mask = 1UL << platform_id;
struct intel_ucode_header *hdr;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: cpu.c,v 1.97 2023/07/16 16:13:46 kettenis Exp $ */
/* $OpenBSD: cpu.c,v 1.98 2023/08/10 19:29:32 kettenis Exp $ */
/*
* Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
@ -919,6 +919,16 @@ cpu_attach(struct device *parent, struct device *dev, void *aux)
cpu_id_aa64pfr0 &= ~ID_AA64PFR0_EL2_MASK;
cpu_id_aa64pfr0 &= ~ID_AA64PFR0_EL3_MASK;
/*
* Lenovo X13s ships with broken EL2 firmware that
* hangs the machine if we enable PAuth.
*/
if (hw_vendor && strcmp(hw_vendor, "LENOVO") == 0 &&
hw_prod && strncmp(hw_prod, "21BX", 4) == 0) {
cpu_id_aa64isar1 &= ~ID_AA64ISAR1_APA_MASK;
cpu_id_aa64isar1 &= ~ID_AA64ISAR1_GPA_MASK;
}
cpu_identify(ci);
if (OF_getproplen(ci->ci_node, "clocks") > 0) {
@ -945,7 +955,6 @@ cpu_init(void)
{
uint64_t id_aa64mmfr1, sctlr;
uint64_t id_aa64pfr0;
uint64_t id_aa64isar1;
uint64_t tcr;
WRITE_SPECIALREG(ttbr0_el1, pmap_kernel()->pm_pt0pa);
@ -971,8 +980,8 @@ cpu_init(void)
__asm volatile (".arch armv8.4-a; msr dit, #1");
/* Enable PAuth. */
id_aa64isar1 = READ_SPECIALREG(id_aa64isar1_el1);
if (ID_AA64ISAR1_API(id_aa64isar1) >= ID_AA64ISAR1_API_BASE) {
if (ID_AA64ISAR1_APA(cpu_id_aa64isar1) >= ID_AA64ISAR1_APA_BASE ||
ID_AA64ISAR1_API(cpu_id_aa64isar1) >= ID_AA64ISAR1_API_BASE) {
sctlr = READ_SPECIALREG(sctlr_el1);
sctlr |= SCTLR_EnIA | SCTLR_EnDA;
sctlr |= SCTLR_EnIB | SCTLR_EnDB;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: machdep.c,v 1.83 2023/07/13 08:33:36 kettenis Exp $ */
/* $OpenBSD: machdep.c,v 1.84 2023/08/10 21:01:50 kettenis Exp $ */
/*
* Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
* Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org>
@ -209,6 +209,7 @@ consinit(void)
void
cpu_idle_enter(void)
{
disable_irq_daif();
}
void (*cpu_idle_cycle_fcn)(void) = cpu_wfi;
@ -216,13 +217,15 @@ void (*cpu_idle_cycle_fcn)(void) = cpu_wfi;
void
cpu_idle_cycle(void)
{
enable_irq_daif();
cpu_idle_cycle_fcn();
enable_irq_daif();
disable_irq_daif();
}
void
cpu_idle_leave(void)
{
enable_irq_daif();
}
/* Dummy trapframe for proc0. */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: pmap.c,v 1.98 2023/06/11 21:42:01 kettenis Exp $ */
/* $OpenBSD: pmap.c,v 1.99 2023/08/10 19:29:32 kettenis Exp $ */
/*
* Copyright (c) 2008-2009,2014-2016 Dale Rahn <drahn@dalerahn.com>
*
@ -2231,7 +2231,8 @@ pmap_show_mapping(uint64_t va)
void
pmap_setpauthkeys(struct pmap *pm)
{
if (ID_AA64ISAR1_API(cpu_id_aa64isar1) >= ID_AA64ISAR1_API_BASE) {
if (ID_AA64ISAR1_APA(cpu_id_aa64isar1) >= ID_AA64ISAR1_APA_BASE ||
ID_AA64ISAR1_API(cpu_id_aa64isar1) >= ID_AA64ISAR1_API_BASE) {
__asm volatile (".arch armv8.3-a; msr apiakeylo_el1, %0"
:: "r"(pm->pm_apiakey[0]));
__asm volatile (".arch armv8.3-a; msr apiakeyhi_el1, %0"
@ -2250,7 +2251,8 @@ pmap_setpauthkeys(struct pmap *pm)
:: "r"(pm->pm_apdbkey[1]));
}
if (ID_AA64ISAR1_GPI(cpu_id_aa64isar1) >= ID_AA64ISAR1_GPI_IMPL) {
if (ID_AA64ISAR1_GPA(cpu_id_aa64isar1) >= ID_AA64ISAR1_GPA_IMPL ||
ID_AA64ISAR1_GPI(cpu_id_aa64isar1) >= ID_AA64ISAR1_GPI_IMPL) {
__asm volatile (".arch armv8.3-a; msr apgakeylo_el1, %0"
:: "r"(pm->pm_apgakey[0]));
__asm volatile (".arch armv8.3-a; msr apgakeyhi_el1, %0"

View file

@ -1,4 +1,4 @@
/* $OpenBSD: agtimer.c,v 1.23 2023/07/25 18:16:19 cheloha Exp $ */
/* $OpenBSD: agtimer.c,v 1.25 2023/08/11 01:28:19 cheloha Exp $ */
/*
* Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
* Copyright (c) 2013 Patrick Wildt <patrick@blueri.se>
@ -323,32 +323,12 @@ agtimer_cpu_initclocks(void)
void
agtimer_delay(u_int usecs)
{
uint64_t clock, oclock, delta, delaycnt;
uint64_t csec, usec;
volatile int j;
uint64_t cycles, start;
if (usecs > (0x80000000 / agtimer_frequency)) {
csec = usecs / 10000;
usec = usecs % 10000;
delaycnt = (agtimer_frequency / 100) * csec +
(agtimer_frequency / 100) * usec / 10000;
} else {
delaycnt = agtimer_frequency * usecs / 1000000;
}
if (delaycnt <= 1)
for (j = 100; j > 0; j--)
;
oclock = agtimer_readcnt64();
while (1) {
for (j = 100; j > 0; j--)
;
clock = agtimer_readcnt64();
delta = clock - oclock;
if (delta > delaycnt)
break;
}
start = agtimer_readcnt64();
cycles = (uint64_t)usecs * agtimer_frequency / 1000000;
while (agtimer_readcnt64() - start < cycles)
CPU_BUSY_CYCLE();
}
void

View file

@ -1,4 +1,4 @@
/* $OpenBSD: mainbus.c,v 1.27 2023/07/19 21:52:55 kettenis Exp $ */
/* $OpenBSD: mainbus.c,v 1.28 2023/08/10 19:29:32 kettenis Exp $ */
/*
* Copyright (c) 2016 Patrick Wildt <patrick@blueri.se>
* Copyright (c) 2017 Mark Kettenis <kettenis@openbsd.org>
@ -133,6 +133,7 @@ mainbus_attach(struct device *parent, struct device *self, void *aux)
}
mainbus_attach_psci(self);
mainbus_attach_efi(self);
/* Attach primary CPU first. */
mainbus_attach_cpus(self, mainbus_match_primary);
@ -140,7 +141,6 @@ mainbus_attach(struct device *parent, struct device *self, void *aux)
/* Attach secondary CPUs. */
mainbus_attach_cpus(self, mainbus_match_secondary);
mainbus_attach_efi(self);
mainbus_attach_firmware(self);
mainbus_attach_resvmem(self);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: machdep.c,v 1.665 2023/07/25 04:42:02 deraadt Exp $ */
/* $OpenBSD: machdep.c,v 1.666 2023/08/09 00:01:44 jsg Exp $ */
/* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */
/*-
@ -1859,6 +1859,21 @@ identifycpu(struct cpu_info *ci)
printf(", %02x-%02x-%02x", ci->ci_family, ci->ci_model,
step);
if ((cpu_ecxfeature & CPUIDECX_HV) == 0) {
uint64_t level = 0;
uint32_t dummy;
if (strcmp(cpu_vendor, "AuthenticAMD") == 0) {
level = rdmsr(MSR_PATCH_LEVEL);
} else if (strcmp(cpu_vendor, "GenuineIntel") == 0) {
wrmsr(MSR_BIOS_SIGN, 0);
CPUID(1, dummy, dummy, dummy, dummy);
level = rdmsr(MSR_BIOS_SIGN) >> 32;
}
if (level != 0)
printf(", patch %08llx", level);
}
printf("\n");
if (ci->ci_feature_flags) {

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ucode.c,v 1.4 2023/07/23 02:59:53 jsg Exp $ */
/* $OpenBSD: ucode.c,v 1.5 2023/08/09 02:59:41 jsg Exp $ */
/*
* Copyright (c) 2018 Stefan Fritsch <fritsch@genua.de>
* Copyright (c) 2018 Patrick Wildt <patrick@blueri.se>
@ -284,7 +284,7 @@ out:
struct intel_ucode_header *
cpu_ucode_intel_find(char *data, size_t left, uint32_t current)
{
uint64_t platform_id = (rdmsr(MSR_PLATFORM_ID) >> 50) & 0xff;
uint64_t platform_id = (rdmsr(MSR_PLATFORM_ID) >> 50) & 7;
uint32_t sig, dummy1, dummy2, dummy3;
uint32_t mask = 1UL << platform_id;
struct intel_ucode_header *hdr;

View file

@ -1,4 +1,4 @@
# $OpenBSD: GENERIC,v 1.288 2023/03/27 09:39:21 naddy Exp $
# $OpenBSD: GENERIC,v 1.289 2023/08/11 02:35:38 dlg Exp $
#
# Machine-independent option; used by all architectures for their
# GENERIC kernel
@ -90,6 +90,7 @@ pseudo-device veb # virtual Ethernet bridge
pseudo-device carp # CARP protocol support
pseudo-device etherip # EtherIP (RFC 3378)
pseudo-device gif # IPv[46] over IPv[46] tunnel (RFC1933)
pseudo-device sec # route based IPsec VPN interface
pseudo-device gre # GRE encapsulation interface
pseudo-device loop # network loopback
pseudo-device mpe # MPLS PE interface

View file

@ -205,7 +205,12 @@ i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj,
int i915_gem_object_pwrite_phys(struct drm_i915_gem_object *obj,
const struct drm_i915_gem_pwrite *args)
{
#ifdef __linux__
void *vaddr = sg_page(obj->mm.pages->sgl) + args->offset;
#else
struct drm_dmamem *dmah = (void *)sg_page(obj->mm.pages->sgl);
void *vaddr = dmah->kva + args->offset;
#endif
char __user *user_data = u64_to_user_ptr(args->data_ptr);
struct drm_i915_private *i915 = to_i915(obj->base.dev);
int err;
@ -236,7 +241,12 @@ int i915_gem_object_pwrite_phys(struct drm_i915_gem_object *obj,
int i915_gem_object_pread_phys(struct drm_i915_gem_object *obj,
const struct drm_i915_gem_pread *args)
{
#ifdef __linux__
void *vaddr = sg_page(obj->mm.pages->sgl) + args->offset;
#else
struct drm_dmamem *dmah = (void *)sg_page(obj->mm.pages->sgl);
void *vaddr = dmah->kva + args->offset;
#endif
char __user *user_data = u64_to_user_ptr(args->data_ptr);
int err;

View file

@ -1,4 +1,4 @@
$OpenBSD: pcidevs,v 1.2044 2023/08/06 14:40:25 jsg Exp $
$OpenBSD: pcidevs,v 1.2045 2023/08/09 21:27:47 kmos Exp $
/* $NetBSD: pcidevs,v 1.30 1997/06/24 06:20:24 thorpej Exp $ */
/*
@ -386,6 +386,7 @@ vendor ATRONICS 0x907f Atronics
vendor NETMOS 0x9710 NetMos
vendor 3COM2 0xa727 3Com
vendor PARALLELS 0xaaaa Parallels
vendor CRUCIAL 0xc0a9 Crucial
vendor TIGERJET 0xe159 TigerJet Network
vendor ENDACE 0xeace Endace
vendor BELKIN 0xec80 Belkin Components
@ -2875,6 +2876,9 @@ product CREATIVELABS SBJOY3 0x7005 PCI Gameport Joystick
product CREATIVELABS PPB 0x7006 PCIE-PCI
product CREATIVELABS EV1938 0x8938 Ectiva 1938
/* Crucial products */
product CRUCIAL P5PLUS 0x5407 P5 Plus
/* Cyclades products */
product CYCLADES CYCLOMY_1 0x0100 Cyclom-Y below 1M
product CYCLADES CYCLOMY_2 0x0101 Cyclom-Y

View file

@ -2,7 +2,7 @@
* THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.
*
* generated from:
* OpenBSD: pcidevs,v 1.2044 2023/08/06 14:40:25 jsg Exp
* OpenBSD: pcidevs,v 1.2045 2023/08/09 21:27:47 kmos Exp
*/
/* $NetBSD: pcidevs,v 1.30 1997/06/24 06:20:24 thorpej Exp $ */
@ -391,6 +391,7 @@
#define PCI_VENDOR_NETMOS 0x9710 /* NetMos */
#define PCI_VENDOR_3COM2 0xa727 /* 3Com */
#define PCI_VENDOR_PARALLELS 0xaaaa /* Parallels */
#define PCI_VENDOR_CRUCIAL 0xc0a9 /* Crucial */
#define PCI_VENDOR_TIGERJET 0xe159 /* TigerJet Network */
#define PCI_VENDOR_ENDACE 0xeace /* Endace */
#define PCI_VENDOR_BELKIN 0xec80 /* Belkin Components */
@ -2880,6 +2881,9 @@
#define PCI_PRODUCT_CREATIVELABS_PPB 0x7006 /* PCIE-PCI */
#define PCI_PRODUCT_CREATIVELABS_EV1938 0x8938 /* Ectiva 1938 */
/* Crucial products */
#define PCI_PRODUCT_CRUCIAL_P5PLUS 0x5407 /* P5 Plus */
/* Cyclades products */
#define PCI_PRODUCT_CYCLADES_CYCLOMY_1 0x0100 /* Cyclom-Y below 1M */
#define PCI_PRODUCT_CYCLADES_CYCLOMY_2 0x0101 /* Cyclom-Y */

View file

@ -2,7 +2,7 @@
* THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.
*
* generated from:
* OpenBSD: pcidevs,v 1.2044 2023/08/06 14:40:25 jsg Exp
* OpenBSD: pcidevs,v 1.2045 2023/08/09 21:27:47 kmos Exp
*/
/* $NetBSD: pcidevs,v 1.30 1997/06/24 06:20:24 thorpej Exp $ */
@ -9327,6 +9327,10 @@ static const struct pci_known_product pci_known_products[] = {
PCI_VENDOR_CREATIVELABS, PCI_PRODUCT_CREATIVELABS_EV1938,
"Ectiva 1938",
},
{
PCI_VENDOR_CRUCIAL, PCI_PRODUCT_CRUCIAL_P5PLUS,
"P5 Plus",
},
{
PCI_VENDOR_CYCLADES, PCI_PRODUCT_CYCLADES_CYCLOMY_1,
"Cyclom-Y below 1M",
@ -36335,6 +36339,10 @@ static const struct pci_known_vendor pci_known_vendors[] = {
PCI_VENDOR_PARALLELS,
"Parallels",
},
{
PCI_VENDOR_CRUCIAL,
"Crucial",
},
{
PCI_VENDOR_TIGERJET,
"TigerJet Network",

View file

@ -1,4 +1,4 @@
/* $OpenBSD: kern_synch.c,v 1.195 2023/07/14 07:07:08 claudio Exp $ */
/* $OpenBSD: kern_synch.c,v 1.196 2023/08/10 20:44:52 claudio Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
@ -397,12 +397,15 @@ sleep_finish(int timo, int do_sleep)
*/
if (p->p_wchan == NULL)
do_sleep = 0;
atomic_clearbits_int(&p->p_flag, P_WSLEEP);
if (do_sleep) {
KASSERT(p->p_stat == SSLEEP || p->p_stat == SSTOP);
p->p_ru.ru_nvcsw++;
mi_switch();
} else {
KASSERT(p->p_stat == SONPROC || p->p_stat == SSLEEP ||
p->p_stat == SSTOP);
unsleep(p);
p->p_stat = SONPROC;
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: uipc_socket.c,v 1.307 2023/08/03 09:49:08 mvs Exp $ */
/* $OpenBSD: uipc_socket.c,v 1.309 2023/08/08 22:07:25 mvs Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
@ -1799,13 +1799,6 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m)
}
error = ENOPROTOOPT;
} else {
switch (optname) {
case SO_BINDANY:
if ((error = suser(curproc)) != 0) /* XXX */
return (error);
break;
}
switch (optname) {
case SO_LINGER:
@ -1824,6 +1817,10 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m)
break;
case SO_BINDANY:
if ((error = suser(curproc)) != 0) /* XXX */
return (error);
/* FALLTHROUGH */
case SO_DEBUG:
case SO_KEEPALIVE:
case SO_USELOOPBACK:
@ -1856,6 +1853,9 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m)
case SO_SNDLOWAT:
case SO_RCVLOWAT:
{
struct sockbuf *sb = (optname == SO_SNDBUF ||
optname == SO_SNDLOWAT ?
&so->so_snd : &so->so_rcv);
u_long cnt;
if (m == NULL || m->m_len < sizeof (int))
@ -1867,40 +1867,23 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m)
solock(so);
switch (optname) {
case SO_SNDBUF:
if (so->so_snd.sb_state & SS_CANTSENDMORE) {
error = EINVAL;
break;
}
if (sbcheckreserve(cnt, so->so_snd.sb_wat) ||
sbreserve(so, &so->so_snd, cnt)) {
error = ENOBUFS;
break;
}
so->so_snd.sb_wat = cnt;
break;
case SO_RCVBUF:
if (so->so_rcv.sb_state & SS_CANTRCVMORE) {
if (sb->sb_state &
(SS_CANTSENDMORE | SS_CANTRCVMORE)) {
error = EINVAL;
break;
}
if (sbcheckreserve(cnt, so->so_rcv.sb_wat) ||
sbreserve(so, &so->so_rcv, cnt)) {
if (sbcheckreserve(cnt, sb->sb_wat) ||
sbreserve(so, sb, cnt)) {
error = ENOBUFS;
break;
}
so->so_rcv.sb_wat = cnt;
sb->sb_wat = cnt;
break;
case SO_SNDLOWAT:
so->so_snd.sb_lowat =
(cnt > so->so_snd.sb_hiwat) ?
so->so_snd.sb_hiwat : cnt;
break;
case SO_RCVLOWAT:
so->so_rcv.sb_lowat =
(cnt > so->so_rcv.sb_hiwat) ?
so->so_rcv.sb_hiwat : cnt;
sb->sb_lowat = (cnt > sb->sb_hiwat) ?
sb->sb_hiwat : cnt;
break;
}
sounlock(so);
@ -1910,6 +1893,8 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m)
case SO_SNDTIMEO:
case SO_RCVTIMEO:
{
struct sockbuf *sb = (optname == SO_SNDTIMEO ?
&so->so_snd : &so->so_rcv);
struct timeval tv;
uint64_t nsecs;
@ -1925,14 +1910,7 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m)
nsecs = INFSLP;
solock(so);
switch (optname) {
case SO_SNDTIMEO:
so->so_snd.sb_timeo_nsecs = nsecs;
break;
case SO_RCVTIMEO:
so->so_rcv.sb_timeo_nsecs = nsecs;
break;
}
sb->sb_timeo_nsecs = nsecs;
sounlock(so);
break;
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: if_sec.c,v 1.1 2023/08/07 01:57:33 dlg Exp $ */
/* $OpenBSD: if_sec.c,v 1.5 2023/08/11 02:34:56 dlg Exp $ */
/*
* Copyright (c) 2022 The University of Queensland
@ -34,41 +34,26 @@
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/timeout.h>
#include <sys/queue.h>
#include <sys/tree.h>
#include <sys/pool.h>
#include <sys/smr.h>
#include <sys/refcnt.h>
#include <sys/task.h>
#include <sys/mutex.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_types.h>
#include <net/if_media.h>
#include <net/route.h>
#include <net/toeplitz.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
#include <netinet/if_ether.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <netinet/ip_ecn.h>
#include <netinet/ip_ipsp.h>
#ifdef INET6
#include <netinet/ip6.h>
#include <netinet6/ip6_var.h>
#include <netinet6/in6_var.h>
#endif
#ifdef MPLS
#include <netmpls/mpls.h>
#endif /* MPLS */
#if NBPFILTER > 0
#include <net/bpf.h>
#endif
@ -83,6 +68,8 @@
struct sec_softc {
struct ifnet sc_if;
unsigned int sc_dead;
unsigned int sc_up;
struct task sc_send;
@ -97,7 +84,7 @@ static int sec_output(struct ifnet *, struct mbuf *, struct sockaddr *,
struct rtentry *);
static int sec_enqueue(struct ifnet *, struct mbuf *);
static void sec_send(void *);
static void sec_start(struct ifnet *);
static void sec_start(struct ifqueue *);
static int sec_ioctl(struct ifnet *, u_long, caddr_t);
static int sec_up(struct sec_softc *);
@ -148,12 +135,12 @@ sec_clone_create(struct if_clone *ifc, int unit)
ifp->if_type = IFT_TUNNEL;
ifp->if_mtu = SEC_MTU;
ifp->if_flags = IFF_POINTOPOINT|IFF_MULTICAST;
ifp->if_xflags = IFXF_CLONED;
ifp->if_xflags = IFXF_CLONED | IFXF_MPSAFE;
ifp->if_bpf_mtap = p2p_bpf_mtap;
ifp->if_input = p2p_input;
ifp->if_output = sec_output;
ifp->if_enqueue = sec_enqueue;
ifp->if_start = sec_start;
ifp->if_qstart = sec_start;
ifp->if_ioctl = sec_ioctl;
ifp->if_rtrequest = p2p_rtrequest;
@ -174,6 +161,7 @@ sec_clone_destroy(struct ifnet *ifp)
struct sec_softc *sc = ifp->if_softc;
NET_LOCK();
sc->sc_dead = 1;
if (ISSET(ifp->if_flags, IFF_RUNNING))
sec_down(sc);
NET_UNLOCK();
@ -237,10 +225,22 @@ sec_up(struct sec_softc *sc)
unsigned int idx = stoeplitz_h32(sc->sc_unit) % nitems(sec_map);
NET_ASSERT_LOCKED();
KASSERT(!ISSET(ifp->if_flags, IFF_RUNNING));
if (sc->sc_dead)
return (ENXIO);
/*
* coordinate with sec_down(). if sc_up is still up and
* we're here then something else is running sec_down.
*/
if (sc->sc_up)
return (EBUSY);
sc->sc_up = 1;
SET(ifp->if_flags, IFF_RUNNING);
refcnt_init(&sc->sc_refs);
SET(ifp->if_flags, IFF_RUNNING);
SMR_SLIST_INSERT_HEAD_LOCKED(&sec_map[idx], sc, sc_entry);
return (0);
@ -253,16 +253,28 @@ sec_down(struct sec_softc *sc)
unsigned int idx = stoeplitz_h32(sc->sc_unit) % nitems(sec_map);
NET_ASSERT_LOCKED();
KASSERT(ISSET(ifp->if_flags, IFF_RUNNING));
/*
* taking sec down involves waiting for it to stop running
* in various contexts. this thread cannot hold netlock
* while waiting for a barrier for a task that could be trying
* to take netlock itself. so give up netlock, but don't clear
* sc_up to prevent sec_up from running.
*/
CLR(ifp->if_flags, IFF_RUNNING);
SMR_SLIST_REMOVE_LOCKED(&sec_map[idx], sc, sec_softc, sc_entry);
NET_UNLOCK();
smr_barrier();
taskq_del_barrier(systq, &sc->sc_send);
refcnt_finalize(&sc->sc_refs, "secdown");
NET_LOCK();
SMR_SLIST_REMOVE_LOCKED(&sec_map[idx], sc, sec_softc, sc_entry);
sc->sc_up = 0;
return (0);
}
@ -369,9 +381,13 @@ purge:
}
static void
sec_start(struct ifnet *ifp)
sec_start(struct ifqueue *ifq)
{
counters_add(ifp->if_counters, ifc_oerrors, ifq_purge(&ifp->if_snd));
struct ifnet *ifp = ifq->ifq_if;
struct sec_softc *sc = ifp->if_softc;
/* move this back to systq for KERNEL_LOCK */
task_add(systq, &sc->sc_send);
}
/*

View file

@ -1,4 +1,4 @@
/* $OpenBSD: pf_table.c,v 1.144 2023/01/05 10:06:58 sashan Exp $ */
/* $OpenBSD: pf_table.c,v 1.145 2023/08/10 16:44:04 sashan Exp $ */
/*
* Copyright (c) 2002 Cedric Berger
@ -1565,8 +1565,10 @@ pfr_add_tables(struct pfr_table *tbl, int size, int *nadd, int flags)
xadd++;
} else if (!(flags & PFR_FLAG_DUMMY) &&
!(p->pfrkt_flags & PFR_TFLAG_ACTIVE)) {
p->pfrkt_nflags = (p->pfrkt_flags &
~PFR_TFLAG_USRMASK) | PFR_TFLAG_ACTIVE;
p->pfrkt_nflags =
(p->pfrkt_flags & ~PFR_TFLAG_USRMASK) |
(n->pfrkt_flags & PFR_TFLAG_USRMASK) |
PFR_TFLAG_ACTIVE;
SLIST_INSERT_HEAD(&changeq, p, pfrkt_workq);
}
}