Merge Official Source

This commit is contained in:
AmadeusGhost 2020-05-28 11:50:15 +08:00
commit a4cf1e067d
30 changed files with 632 additions and 175 deletions

View File

@ -56,7 +56,8 @@ netgear,wndr3700-v2)
ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x10000"
;;
netgear,wndr3700-v4|\
netgear,wndr4300)
netgear,wndr4300|\
netgear,wndr4300sw)
ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x20000"
;;
qihoo,c301)

View File

@ -8,14 +8,14 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=rpcd
PKG_RELEASE:=2
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/rpcd.git
PKG_SOURCE_DATE:=2020-01-05
PKG_SOURCE_VERSION:=efe51f41d6288fa8503cc4f2efb37a777767d505
PKG_SOURCE_DATE:=2020-05-26
PKG_SOURCE_VERSION:=078bb57e0769c987c05244abe1f7d8d53e0e323e
PKG_MAINTAINER:=Jo-Philipp Wich <jo@mein.io>
PKG_MIRROR_HASH:=cf4bd4670ce8d49f5fb97f0e74a817324c1a503c90527282e30365d8b9a2e17a
PKG_MIRROR_HASH:=7f626efd95eccc7b8262a7e533341e17fe765d99cfa2fafde978190cb834fced
PKG_LICENSE:=ISC
PKG_LICENSE_FILES:=

View File

@ -116,7 +116,7 @@
#address-cells = <1>;
#size-cells = <1>;
uboot: partition@0 {
uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;

View File

@ -81,7 +81,7 @@
#address-cells = <1>;
#size-cells = <1>;
uboot: partition@0 {
uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x040000>;
read-only;

View File

@ -128,7 +128,7 @@
#address-cells = <1>;
#size-cells = <1>;
uboot: partition@0 {
uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;

View File

@ -123,7 +123,7 @@
#address-cells = <1>;
#size-cells = <1>;
uboot: partition@0 {
uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;

View File

@ -0,0 +1,150 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/dts-v1/;
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include "qca953x.dtsi"
/ {
compatible = "comfast,cf-e130n-v2", "qca,qca9531";
model = "COMFAST CF-E130N v2";
aliases {
serial0 = &uart;
led-boot = &led_rssihigh;
led-failsafe = &led_rssihigh;
led-upgrade = &led_rssihigh;
label-mac-device = &eth1;
};
leds {
compatible = "gpio-leds";
pinctrl-names = "default";
wlan {
label = "cf-e130n-v2:green:wlan";
gpios = <&gpio 0 GPIO_ACTIVE_LOW>;
linux,default-trigger = "phy0tpt";
};
lan {
label = "cf-e130n-v2:green:lan";
gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
};
unused {
label = "cf-e130n-v2:green:unused";
gpios = <&gpio 3 GPIO_ACTIVE_LOW>;
};
rssilow {
label = "cf-e130n-v2:red:rssilow";
gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
};
rssimediumlow {
label = "cf-e130n-v2:red:rssimediumlow";
gpios = <&gpio 12 GPIO_ACTIVE_LOW>;
};
rssimediumhigh {
label = "cf-e130n-v2:green:rssimediumhigh";
gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
};
led_rssihigh: rssihigh {
label = "cf-e130n-v2:green:rssihigh";
gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
};
};
keys {
compatible = "gpio-keys";
reset {
label = "reset";
linux,code = <KEY_RESTART>;
gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
debounce-interval = <60>;
};
};
};
&spi {
status = "okay";
num-cs = <1>;
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <25000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x000000 0x010000>;
read-only;
};
art: partition@10000 {
label = "art";
reg = <0x010000 0x010000>;
read-only;
};
partition@20000 {
compatible = "denx,uimage";
label = "firmware";
reg = <0x020000 0x7c0000>;
};
partition@7e0000 {
label = "configs";
reg = <0x7e0000 0x010000>;
read-only;
};
partition@7f0000 {
label = "nvram";
reg = <0x7f0000 0x010000>;
read-only;
};
};
};
};
&uart {
status = "okay";
};
&eth0 {
compatible = "syscon", "simple-mfd";
};
&eth1 {
status = "okay";
phy-handle = <&swphy0>;
mtd-mac-address = <&art 0x0>;
gmac-config {
device = <&gmac>;
switch-phy-swap = <1>;
};
};
&wmac {
status = "okay";
mtd-mac-address = <&art 0x0>;
mtd-cal-data = <&art 0x1000>;
};

View File

@ -92,7 +92,7 @@
#address-cells = <1>;
#size-cells = <1>;
uboot: partition@0 {
uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;

View File

@ -74,7 +74,7 @@
#address-cells = <1>;
#size-cells = <1>;
uboot: partition@0 {
uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;

View File

@ -113,7 +113,7 @@
#address-cells = <1>;
#size-cells = <1>;
uboot: partition@0 {
uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;

View File

@ -25,14 +25,6 @@
debounce-interval = <60>;
};
};
// Pull up on boot - otherwise the reset button won't work
reset-button {
gpio-hog;
output-high;
gpios = <11 GPIO_ACTIVE_LOW>;
line-name = "reset-button";
};
};
&uart {
@ -45,12 +37,13 @@
&spi {
status = "okay";
num-cs = <1>;
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <30000000>;
spi-max-frequency = <50000000>;
partitions {
compatible = "fixed-partitions";
@ -116,6 +109,7 @@
phy0: ethernet-phy@0 {
reg = <0>;
qca,mib-poll-interval = <500>;
reset-gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
qca,ar8327-initvals = <
0x04 0x00080080 /* PORT0 PAD MODE CTRL */
@ -140,5 +134,6 @@
&wmac {
status = "okay";
qca,no-eeprom;
};

View File

@ -17,21 +17,16 @@
leds {
compatible = "gpio-leds";
led_power: power {
label = "dir-842-c1:green:power";
gpios = <&gpio 5 GPIO_ACTIVE_LOW>;
};
wps {
label = "dir-842-c1:green:wps";
gpios = <&gpio 8 GPIO_ACTIVE_LOW>;
};
led_power: power {
label = "dir-842-c1:green:power";
gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
};
internet {
label = "dir-842-c1:green:internet";
gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
};
wlan {
label = "dir-842-c1:green:wlan";
gpios = <&gpio 19 GPIO_ACTIVE_LOW>;

View File

@ -17,21 +17,16 @@
leds {
compatible = "gpio-leds";
led_power: power {
label = "dir-842-c2:green:power";
gpios = <&gpio 5 GPIO_ACTIVE_LOW>;
};
wps {
label = "dir-842-c2:green:wps";
gpios = <&gpio 8 GPIO_ACTIVE_LOW>;
};
led_power: power {
label = "dir-842-c2:green:power";
gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
};
internet {
label = "dir-842-c2:green:internet";
gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
};
wlan {
label = "dir-842-c2:green:wlan";
gpios = <&gpio 19 GPIO_ACTIVE_LOW>;

View File

@ -17,21 +17,16 @@
leds {
compatible = "gpio-leds";
led_power: power {
label = "dir-842-c3:green:power";
gpios = <&gpio 5 GPIO_ACTIVE_LOW>;
};
wps {
label = "dir-842-c3:green:wps";
gpios = <&gpio 8 GPIO_ACTIVE_LOW>;
};
led_power: power {
label = "dir-842-c3:green:power";
gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
};
internet {
label = "dir-842-c3:green:internet";
gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
};
wlan {
label = "dir-842-c3:green:wlan";
gpios = <&gpio 19 GPIO_ACTIVE_LOW>;

View File

@ -30,7 +30,7 @@
#address-cells = <1>;
#size-cells = <1>;
uboot: partition@0 {
uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;

View File

@ -57,6 +57,14 @@ comfast,cf-e120a-v3)
ucidef_set_led_rssi "rssimediumhigh" "RSSIMEDIUMHIGH" "$boardname:green:rssimediumhigh" "wlan0" "51" "100"
ucidef_set_led_rssi "rssihigh" "RSSIHIGH" "$boardname:green:rssihigh" "wlan0" "76" "100"
;;
comfast,cf-e130n-v2)
ucidef_set_led_netdev "lan" "LAN" "$boardname:green:lan" "eth0"
ucidef_set_rssimon "wlan0" "200000" "1"
ucidef_set_led_rssi "rssilow" "RSSILOW" "$boardname:red:rssilow" "wlan0" "1" "100"
ucidef_set_led_rssi "rssimediumlow" "RSSIMEDIUMLOW" "$boardname:red:rssimediumlow" "wlan0" "26" "100"
ucidef_set_led_rssi "rssimediumhigh" "RSSIMEDIUMHIGH" "$boardname:green:rssimediumhigh" "wlan0" "51" "100"
ucidef_set_led_rssi "rssihigh" "RSSIHIGH" "$boardname:green:rssihigh" "wlan0" "76" "100"
;;
comfast,cf-e313ac)
ucidef_set_led_switch "lan" "LAN" "$boardname:green:lan" "switch0" "0x02"
ucidef_set_led_netdev "wan" "WAN" "$boardname:green:wan" "eth1"
@ -102,9 +110,6 @@ enterasys,ws-ap3705i)
devolo,magic-2-wifi)
ucidef_set_led_netdev "plcw" "dLAN" "devolo:white:dlan" "eth0.1" "rx"
;;
dlink,dir-842-c1|\
dlink,dir-842-c2|\
dlink,dir-842-c3|\
dlink,dir-859-a1)
ucidef_set_led_switch "internet" "WAN" "$boardname:green:internet" "switch0" "0x20"
;;

View File

@ -16,6 +16,7 @@ ath79_setup_interfaces()
avm,fritz1750e|\
avm,fritz300e|\
comfast,cf-wr752ac-v1|\
comfast,cf-e130n-v2|\
devolo,dvl1200i|\
devolo,dvl1750c|\
devolo,dvl1750i|\

View File

@ -304,6 +304,16 @@ define Device/comfast_cf-e120a-v3
endef
TARGET_DEVICES += comfast_cf-e120a-v3
define Device/comfast_cf-e130n-v2
SOC := qca9531
DEVICE_VENDOR := COMFAST
DEVICE_MODEL := CF-E130N
DEVICE_VARIANT := v2
DEVICE_PACKAGES := rssileds kmod-leds-gpio -swconfig -uboot-envtools
IMAGE_SIZE := 7936k
endef
TARGET_DEVICES += comfast_cf-e130n-v2
define Device/comfast_cf-e313ac
SOC := qca9531
DEVICE_VENDOR := COMFAST

View File

@ -0,0 +1,116 @@
//SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "mt7620a.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
/ {
keys {
compatible = "gpio-keys";
reset {
label = "reset";
gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
linux,code = <KEY_RESTART>;
};
wps {
label = "wps";
gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
linux,code = <KEY_WPS_BUTTON>;
};
};
};
&spi0 {
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <50000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x0 0x30000>;
read-only;
};
partition@30000 {
label = "u-boot-env";
reg = <0x30000 0x10000>;
read-only;
};
factory: partition@40000 {
label = "factory";
reg = <0x40000 0x10000>;
read-only;
};
factory5g: partition@50000 {
label = "factory5g";
reg = <0x50000 0x10000>;
read-only;
};
partition@60000 {
label = "Wolf_Config";
reg = <0x60000 0x10000>;
read-only;
};
partition@70000 {
label = "MyDlink";
reg = <0x70000 0x80000>;
read-only;
};
partition@f0000 {
label = "Jffs2";
reg = <0xf0000 0x80000>;
read-only;
};
partition@170000 {
compatible = "denx,uimage";
label = "firmware";
reg = <0x170000 0x690000>;
};
};
};
};
&ethernet {
mtd-mac-address = <&factory 0x28>;
mediatek,portmap = "llllw";
};
&wmac {
pinctrl-names = "default";
pinctrl-0 = <&pa_pins>;
ralink,mtd-eeprom = <&factory 0x0>;
mtd-mac-address = <&factory 0x28>;
};
&pcie {
status = "okay";
};
&pcie0 {
wifi@0,0 {
reg = <0x0000 0 0 0 0>;
mediatek,mtd-eeprom = <&factory 0x8000>;
ieee80211-freq-limit = <5000000 6000000>;
mtd-mac-address = <&factory 0x28>;
mtd-mac-address-increment = <2>;
};
};

View File

@ -1,9 +1,6 @@
/dts-v1/;
#include "mt7620a.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include "mt7620a_cameo_810.dtsi"
/ {
compatible = "dlink,dir-810l", "ralink,mt7620a-soc";
@ -17,22 +14,6 @@
label-mac-device = &ethernet;
};
keys {
compatible = "gpio-keys";
reset {
label = "reset";
gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
linux,code = <KEY_RESTART>;
};
wps {
label = "wps";
gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
linux,code = <KEY_WPS_BUTTON>;
};
};
leds {
compatible = "gpio-leds";
@ -53,70 +34,6 @@
};
};
&spi0 {
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <50000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x0 0x30000>;
read-only;
};
partition@30000 {
label = "u-boot-env";
reg = <0x30000 0x10000>;
read-only;
};
factory: partition@40000 {
label = "factory";
reg = <0x40000 0x10000>;
read-only;
};
factory5g: partition@50000 {
label = "factory5g";
reg = <0x50000 0x10000>;
read-only;
};
partition@60000 {
label = "Wolf_Config";
reg = <0x60000 0x10000>;
read-only;
};
partition@70000 {
label = "MyDlink";
reg = <0x70000 0x80000>;
read-only;
};
partition@f0000 {
label = "Jffs2";
reg = <0xf0000 0x80000>;
read-only;
};
partition@170000 {
compatible = "denx,uimage";
label = "firmware";
reg = <0x170000 0x690000>;
};
};
};
};
&state_default {
gpio {
groups = "i2c", "uartf";
@ -124,37 +41,9 @@
};
};
&ethernet {
mtd-mac-address = <&factory 0x28>;
mediatek,portmap = "llllw";
};
&gsw {
pinctrl-names = "default";
pinctrl-0 = <&ephy_pins>;
mediatek,port4 = "ephy";
};
&pcie {
status = "okay";
};
&wmac {
pinctrl-names = "default";
pinctrl-0 = <&pa_pins>;
ralink,mtd-eeprom = <&factory 0x0>;
mtd-mac-address = <&factory 0x28>;
};
&pcie0 {
wifi@0,0 {
reg = <0x0000 0 0 0 0>;
mediatek,mtd-eeprom = <&factory 0x8000>;
ieee80211-freq-limit = <5000000 6000000>;
mtd-mac-address = <&factory 0x28>;
mtd-mac-address-increment = <2>;
};
};

View File

@ -0,0 +1,56 @@
//SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/dts-v1/;
#include "mt7620a_cameo_810.dtsi"
/ {
compatible = "trendnet,tew-810dr", "ralink,mt7620a-soc";
model = "TRENDnet TEW-810DR";
aliases {
led-boot = &led_power_green;
led-failsafe = &led_power_green;
led-running = &led_power_green;
led-upgrade = &led_power_green;
label-mac-device = &ethernet;
};
leds {
compatible = "gpio-leds";
led_power_green: power_green {
label = "tew-810dr:green:power";
gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>;
};
wan_orange {
label = "tew-810dr:orange:wan";
gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
};
wan_green {
label = "tew-810dr:green:wan";
gpios = <&gpio2 0 GPIO_ACTIVE_LOW>;
};
power_orange {
label = "tew-810dr:orange:power";
gpios = <&gpio0 13 GPIO_ACTIVE_HIGH>;
};
};
};
&state_default {
gpio {
groups = "i2c", "uartf", "ephy";
function = "gpio";
};
};
&gsw {
mediatek,port4 = "ephy";
};
&gpio2 {
status = "okay";
};

View File

@ -11,17 +11,17 @@
model = "ZyXEL Keenetic Start";
aliases {
led-boot = &led_status;
led-failsafe = &led_status;
led-running = &led_status;
led-upgrade = &led_status;
led-boot = &led_power;
led-failsafe = &led_power;
led-running = &led_power;
led-upgrade = &led_power;
label-mac-device = &ethernet;
};
leds {
compatible = "gpio-leds";
led_status: power {
led_power: power {
label = "zyxel:green:power";
gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
};

View File

@ -1005,6 +1005,15 @@ define Device/tplink_re210-v1
endef
TARGET_DEVICES += tplink_re210-v1
define Device/trendnet_tew-810dr
SOC := mt7620a
DEVICE_PACKAGES := kmod-mt76x0e
DEVICE_VENDOR := TRENDnet
DEVICE_MODEL := TEW-810DR
IMAGE_SIZE := 6720k
endef
TARGET_DEVICES += trendnet_tew-810dr
define Device/vonets_var11n-300
SOC := mt7620n
IMAGE_SIZE := 3776k

View File

@ -191,6 +191,9 @@ tplink,archer-mr200)
tplink,re200-v1)
ucidef_set_led_netdev "lan" "lan" "$boardname:green:lan" "eth0"
;;
trendnet,tew-810dr)
ucidef_set_led_netdev "wan" "wan" "$boardname:green:wan" "eth0.2"
;;
youku,yk1)
set_wifi_led "$boardname:blue:air"
ucidef_set_led_switch "wan" "wan" "$boardname:blue:wan" "switch0" "0x10"

View File

@ -26,6 +26,7 @@ ramips_setup_interfaces()
ralink,mt7620a-mt7610e-evb|\
ralink,mt7620a-v22sg-evb|\
sanlinking,d240|\
trendnet,tew-810dr|\
youku,yk1|\
zbtlink,zbt-ape522ii|\
zbtlink,zbt-we826-16m|\
@ -259,7 +260,8 @@ ramips_setup_macs()
alfa-network,ac1200rm|\
dlink,dir-810l|\
phicomm,psg1218a|\
phicomm,psg1218b)
phicomm,psg1218b|\
trendnet,tew-810dr)
wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x28)" 1)
;;
alfa-network,r36m-e4g|\

View File

@ -11,8 +11,8 @@ PKG_VERSION:=2.31
PKG_SOURCE_PROTO:=git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=109474122400ca7d60782b131dc867a5c1f2fe55
PKG_MIRROR_HASH:=5a04a24e69eace9eb892f0b48b869d31d4900ad656099064b6a9d8a342c13d8c
PKG_SOURCE_VERSION:=3a44844c97a8ca1d0798c45b5252e6a49f9cf8e1
PKG_MIRROR_HASH:=d7206510e494b3c723173d8ec0dd2e41314da59075871c5642324688001b3f6e
PKG_SOURCE_URL:=https://sourceware.org/git/glibc.git
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.xz

View File

@ -0,0 +1,51 @@
From 4d5aa20a94a2d3fae3e69289dc23ecafbd0c16c4 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Fri, 22 May 2020 17:35:14 -0400
Subject: [PATCH 1/4] reorder thread list unlink in pthread_exit after all
locks
since the backend for LOCK() skips locking if single-threaded, it's
unsafe to make the process appear single-threaded before the last use
of lock.
this fixes potential unsynchronized access to a linked list via
__dl_thread_cleanup.
---
src/thread/pthread_create.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -90,14 +90,7 @@ _Noreturn void __pthread_exit(void *resu
exit(0);
}
- /* At this point we are committed to thread termination. Unlink
- * the thread from the list. This change will not be visible
- * until the lock is released, which only happens after SYS_exit
- * has been called, via the exit futex address pointing at the lock. */
- libc.threads_minus_1--;
- self->next->prev = self->prev;
- self->prev->next = self->next;
- self->prev = self->next = self;
+ /* At this point we are committed to thread termination. */
/* Process robust list in userspace to handle non-pshared mutexes
* and the detached thread case where the robust list head will
@@ -121,6 +114,16 @@ _Noreturn void __pthread_exit(void *resu
__do_orphaned_stdio_locks();
__dl_thread_cleanup();
+ /* Last, unlink thread from the list. This change will not be visible
+ * until the lock is released, which only happens after SYS_exit
+ * has been called, via the exit futex address pointing at the lock.
+ * This needs to happen after any possible calls to LOCK() that might
+ * skip locking if libc.threads_minus_1 is zero. */
+ libc.threads_minus_1--;
+ self->next->prev = self->prev;
+ self->prev->next = self->next;
+ self->prev = self->next = self;
+
/* This atomic potentially competes with a concurrent pthread_detach
* call; the loser is responsible for freeing thread resources. */
int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING);

View File

@ -0,0 +1,69 @@
From e01b5939b38aea5ecbe41670643199825874b26c Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Thu, 21 May 2020 23:32:45 -0400
Subject: [PATCH 2/4] don't use libc.threads_minus_1 as relaxed atomic for
skipping locks
after all but the last thread exits, the next thread to observe
libc.threads_minus_1==0 and conclude that it can skip locking fails to
synchronize with any changes to memory that were made by the
last-exiting thread. this can produce data races.
on some archs, at least x86, memory synchronization is unlikely to be
a problem; however, with the inline locks in malloc, skipping the lock
also eliminated the compiler barrier, and caused code that needed to
re-check chunk in-use bits after obtaining the lock to reuse a stale
value, possibly from before the process became single-threaded. this
in turn produced corruption of the heap state.
some uses of libc.threads_minus_1 remain, especially for allocation of
new TLS in the dynamic linker; otherwise, it could be removed
entirely. it's made non-volatile to reflect that the remaining
accesses are only made under lock on the thread list.
instead of libc.threads_minus_1, libc.threaded is now used for
skipping locks. the difference is that libc.threaded is permanently
true once an additional thread has been created. this will produce
some performance regression in processes that are mostly
single-threaded but occasionally creating threads. in the future it
may be possible to bring back the full lock-skipping, but more care
needs to be taken to produce a safe design.
---
src/internal/libc.h | 2 +-
src/malloc/malloc.c | 2 +-
src/thread/__lock.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -21,7 +21,7 @@ struct __libc {
int can_do_threads;
int threaded;
int secure;
- volatile int threads_minus_1;
+ int threads_minus_1;
size_t *auxv;
struct tls_module *tls_head;
size_t tls_size, tls_align, tls_cnt;
--- a/src/malloc/malloc.c
+++ b/src/malloc/malloc.c
@@ -26,7 +26,7 @@ int __malloc_replaced;
static inline void lock(volatile int *lk)
{
- if (libc.threads_minus_1)
+ if (libc.threaded)
while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
}
--- a/src/thread/__lock.c
+++ b/src/thread/__lock.c
@@ -18,7 +18,7 @@
void __lock(volatile int *l)
{
- if (!libc.threads_minus_1) return;
+ if (!libc.threaded) return;
/* fast path: INT_MIN for the lock, +1 for the congestion */
int current = a_cas(l, 0, INT_MIN + 1);
if (!current) return;

View File

@ -0,0 +1,25 @@
From f12888e9eb9eed60cc266b899dcafecb4752964a Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Fri, 22 May 2020 17:25:38 -0400
Subject: [PATCH 3/4] cut down size of some libc struct members
these are all flags that can be single-byte values.
---
src/internal/libc.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -18,9 +18,9 @@ struct tls_module {
};
struct __libc {
- int can_do_threads;
- int threaded;
- int secure;
+ char can_do_threads;
+ char threaded;
+ char secure;
int threads_minus_1;
size_t *auxv;
struct tls_module *tls_head;

View File

@ -0,0 +1,90 @@
From 8d81ba8c0bc6fe31136cb15c9c82ef4c24965040 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Fri, 22 May 2020 17:45:47 -0400
Subject: [PATCH 4/4] restore lock-skipping for processes that return to
single-threaded state
the design used here relies on the barrier provided by the first lock
operation after the process returns to single-threaded state to
synchronize with actions by the last thread that exited. by storing
the intent to change modes in the same object used to detect whether
locking is needed, it's possible to avoid an extra (possibly costly)
memory load after the lock is taken.
---
src/internal/libc.h | 1 +
src/malloc/malloc.c | 5 ++++-
src/thread/__lock.c | 4 +++-
src/thread/pthread_create.c | 8 ++++----
4 files changed, 12 insertions(+), 6 deletions(-)
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -21,6 +21,7 @@ struct __libc {
char can_do_threads;
char threaded;
char secure;
+ volatile signed char need_locks;
int threads_minus_1;
size_t *auxv;
struct tls_module *tls_head;
--- a/src/malloc/malloc.c
+++ b/src/malloc/malloc.c
@@ -26,8 +26,11 @@ int __malloc_replaced;
static inline void lock(volatile int *lk)
{
- if (libc.threaded)
+ int need_locks = libc.need_locks;
+ if (need_locks) {
while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
+ if (need_locks < 0) libc.need_locks = 0;
+ }
}
static inline void unlock(volatile int *lk)
--- a/src/thread/__lock.c
+++ b/src/thread/__lock.c
@@ -18,9 +18,11 @@
void __lock(volatile int *l)
{
- if (!libc.threaded) return;
+ int need_locks = libc.need_locks;
+ if (!need_locks) return;
/* fast path: INT_MIN for the lock, +1 for the congestion */
int current = a_cas(l, 0, INT_MIN + 1);
+ if (need_locks < 0) libc.need_locks = 0;
if (!current) return;
/* A first spin loop, for medium congestion. */
for (unsigned i = 0; i < 10; ++i) {
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -118,8 +118,8 @@ _Noreturn void __pthread_exit(void *resu
* until the lock is released, which only happens after SYS_exit
* has been called, via the exit futex address pointing at the lock.
* This needs to happen after any possible calls to LOCK() that might
- * skip locking if libc.threads_minus_1 is zero. */
- libc.threads_minus_1--;
+ * skip locking if process appears single-threaded. */
+ if (!--libc.threads_minus_1) libc.need_locks = -1;
self->next->prev = self->prev;
self->prev->next = self->next;
self->prev = self->next = self;
@@ -339,7 +339,7 @@ int __pthread_create(pthread_t *restrict
~(1UL<<((SIGCANCEL-1)%(8*sizeof(long))));
__tl_lock();
- libc.threads_minus_1++;
+ if (!libc.threads_minus_1++) libc.need_locks = 1;
ret = __clone((c11 ? start_c11 : start), stack, flags, args, &new->tid, TP_ADJ(new), &__thread_list_lock);
/* All clone failures translate to EAGAIN. If explicit scheduling
@@ -363,7 +363,7 @@ int __pthread_create(pthread_t *restrict
new->next->prev = new;
new->prev->next = new;
} else {
- libc.threads_minus_1--;
+ if (!--libc.threads_minus_1) libc.need_locks = 0;
}
__tl_unlock();
__restore_sigs(&set);