[astro] 16.20231130.3.59 u-boot source

GitOrigin-RevId: c125fe166c759361f54f04d57dd93265e4bb3e17
Change-Id: I2af5d073e2f4217ed8657b08c967163a18d70d38
Reviewed-on: https://turquoise-internal-review.googlesource.com/c/third_party/u-boot/+/815952
Reviewed-by: David Pursell <dpursell@google.com>
diff --git a/Makefile b/Makefile
index d39d900..48b523a 100755
--- a/Makefile
+++ b/Makefile
@@ -256,9 +256,6 @@
 CROSS_COMPILE ?=
 endif
 
-#export CROSS_COMPILE=/opt/gcc-linaro-aarch64-none-elf-4.8-2013.11_linux/bin/aarch64-none-elf-
-#export CROSS_COMPILE_T32=/opt/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-
-
 KCONFIG_CONFIG	?= .config
 export KCONFIG_CONFIG
 
diff --git a/README.fuchsia.md b/README.fuchsia.md
index b273030..45cb4c5 100644
--- a/README.fuchsia.md
+++ b/README.fuchsia.md
@@ -15,11 +15,11 @@
 links below, refer to the included docs for instructions on how to build. You
 may also be able to find prebuilt toolchain binaries online.
 
-* gcc-linaro-4.8-2013.11
-  * Source: https://chrome-infra-packages.appspot.com/p/fuchsia/third_party/source/gcc/linaro/+/vBpgfx_qKIXiyaRgG_4FJCaZpuB5DBggIXbBAEM43bMC
+* gcc-linaro-7.3.1-2018.05
+  * Source: https://chrome-infra-packages.appspot.com/p/fuchsia/third_party/source/gcc/linaro/+/version:7.3-2018.05
   * target architecture: `aarch64-none-elf`
 * gcc-arm-none-eabi-6-2017-q2-update
-  * Source: https://chrome-infra-packages.appspot.com/p/fuchsia/third_party/source/gcc/arm/arm-none-eabi/+/Pg0Ayh3y2Xx538OvmLcmmUon5YDxvk-EjDYVR0JPUSMC
+  * Source: https://chrome-infra-packages.appspot.com/p/fuchsia/third_party/source/gcc/arm/arm-none-eabi/+/version:6-2017-q2-update
   * target architecture: `arm-none-eabi`
 
 Once you have the toolchain binaries, place them in an adjacent directory
@@ -33,7 +33,7 @@
         * `bin/`
         * `lib/`
         * etc.
-      * `gcc-linaro-aarch64-none-elf-4.8-2013.11_linux/`
+      * `gcc-linaro-7.3.1-2018.05-x86_64_aarch64-elf/`
         * `bin/`
         * `lib/`
         * etc.
diff --git a/arch/arm/cpu/armv8/g12a/bl31_apis.c b/arch/arm/cpu/armv8/g12a/bl31_apis.c
index 8a159fa..751a7fc 100644
--- a/arch/arm/cpu/armv8/g12a/bl31_apis.c
+++ b/arch/arm/cpu/armv8/g12a/bl31_apis.c
@@ -68,7 +68,11 @@
 	if (arg->cmd == EFUSE_HAL_API_WRITE)
 		memcpy((void *)sharemem_input_base,
 		       (const void *)arg->buffer_phy, size);
-		asm __volatile__("" : : : "memory");
+
+	/* Unclear if this was supposed to be only in the API_WRITE case or
+	   unconditional. To be safe just do it unconditionally, an extra
+	   memory barrier won't hurt anything. */
+	asm __volatile__("" : : : "memory");
 
 	register uint64_t x0 asm("x0") = cmd;
 	register uint64_t x1 asm("x1") = offset;
diff --git a/arch/arm/include/asm/arch-g12a/ddr_define.h b/arch/arm/include/asm/arch-g12a/ddr_define.h
index dc2a655..3eb5a00 100644
--- a/arch/arm/include/asm/arch-g12a/ddr_define.h
+++ b/arch/arm/include/asm/arch-g12a/ddr_define.h
@@ -269,7 +269,7 @@
 											DDR_FUNC_LPDDR3_CA_TRAINING_CA1_BIT0| \
 											DDR_FUNC_LPDDR3_CA_TRAINING_CA1_BIT1| \
 											DDR_FUNC_LPDDR3_SOC_ODT_ONLY_UP	| \
-											(1 << 31) 						\
+											(1u << 31) 						\
 											)
 
 
diff --git a/board/amlogic/g12a_estelle_bx/firmware/timing.c b/board/amlogic/g12a_estelle_bx/firmware/timing.c
index f519b82..93ea25c 100755
--- a/board/amlogic/g12a_estelle_bx/firmware/timing.c
+++ b/board/amlogic/g12a_estelle_bx/firmware/timing.c
@@ -459,5 +459,5 @@
 	{GPIO_O_REG3,         (1 << 8),                0xffffffff,   0, BL2_INIT_STAGE_1, 0},
 	/* Enable VCCK */
 	{AO_SEC_REG0,         (1 << 0),                0xffffffff,   0, BL2_INIT_STAGE_1, 0},
-	{AO_GPIO_O,           (1 << 31),               0xffffffff,   0, BL2_INIT_STAGE_1, 0},
+	{AO_GPIO_O,           (1u << 31),              0xffffffff,   0, BL2_INIT_STAGE_1, 0},
 };
diff --git a/board/amlogic/g12a_estelle_bx/zircon_partition.c b/board/amlogic/g12a_estelle_bx/zircon_partition.c
index bec8a97..fa07940 100644
--- a/board/amlogic/g12a_estelle_bx/zircon_partition.c
+++ b/board/amlogic/g12a_estelle_bx/zircon_partition.c
@@ -348,9 +348,9 @@
 	return false;
 }
 
-static unsigned char sys_cfg_read_buf[ERASE_GRP_SIZE_MAX];
-static unsigned char sys_cfg_write_buf[ERASE_GRP_SIZE_MAX];
-static unsigned char sys_cfg_erase_buf[ERASE_GRP_SIZE_MAX];
+static unsigned char sys_cfg_read_buf[ERASE_GRP_SIZE_MAX] __aligned(ARCH_DMA_MINALIGN);
+static unsigned char sys_cfg_write_buf[ERASE_GRP_SIZE_MAX] __aligned(ARCH_DMA_MINALIGN);
+static unsigned char sys_cfg_erase_buf[ERASE_GRP_SIZE_MAX] __aligned(ARCH_DMA_MINALIGN);
 
 #define NAND_READ_RETRIES 3
 /**
@@ -712,7 +712,7 @@
 		return sysconfig_header_in_use;
 	}
 
-	uint8_t buf[PAGE_SIZE];
+	uint8_t buf[PAGE_SIZE] __aligned(ARCH_DMA_MINALIGN);
 	int status;
 
 	if ((status = read_from_sys_config(0, buf, PAGE_SIZE,
diff --git a/common/cmd_cpu_temp.c b/common/cmd_cpu_temp.c
index c6da1a5..143490c 100755
--- a/common/cmd_cpu_temp.c
+++ b/common/cmd_cpu_temp.c
@@ -965,10 +965,11 @@
 					for (i = 0; i <= NUM; i ++) {
 						udelay(5000);
 						value_ts = readl(TS_PLL_STAT0) & 0xffff;
-						if ((value_ts >= 0x18a9) && (value_ts <= 0x32a6))
+						if ((value_ts >= 0x18a9) && (value_ts <= 0x32a6)) {
 							value_all_ts += value_ts;
 							cnt ++;
 						}
+					}
 					value_ts =  value_all_ts / cnt;
 					printf("pll tsensor avg: 0x%x\n", value_ts);
 					if (value_ts == 0) {
@@ -1000,10 +1001,11 @@
 					for (i = 0; i <= NUM; i ++) {
 						udelay(5000);
 						value_ts = readl(TS_DDR_STAT0) & 0xffff;
-						if ((value_ts >= 0x18a9) && (value_ts <= 0x32a6))
+						if ((value_ts >= 0x18a9) && (value_ts <= 0x32a6)) {
 							value_all_ts += value_ts;
 							cnt ++;
 						}
+					}
 					value_ts =  value_all_ts / cnt;
 					printf("ddr tsensor avg: 0x%x\n", value_ts);
 					if (value_ts == 0) {
@@ -1112,10 +1114,11 @@
 						udelay(5000);
 						value_ts = readl(TS_PLL_STAT0) & 0xffff;
 						printf("pll tsensor read: 0x%x\n", value_ts);
-						if ((value_ts >= 0x18a9) && (value_ts <= 0x32a6))
+						if ((value_ts >= 0x18a9) && (value_ts <= 0x32a6)) {
 							value_all_ts += value_ts;
 							cnt ++;
 						}
+					}
 					value_ts =  value_all_ts / cnt;
 					printf("pll tsensor avg: 0x%x\n", value_ts);
 					if (value_ts == 0) {
@@ -1149,10 +1152,11 @@
 						udelay(5000);
 						value_ts = readl(TS_DDR_STAT0) & 0xffff;
 						printf("ddr tsensor read: 0x%x\n", value_ts);
-						if ((value_ts >= 0x18a9) && (value_ts <= 0x32a6))
+						if ((value_ts >= 0x18a9) && (value_ts <= 0x32a6)) {
 							value_all_ts += value_ts;
 							cnt ++;
 						}
+					}
 					value_ts =  value_all_ts / cnt;
 					printf("ddr tsensor avg: 0x%x\n", value_ts);
 					if (value_ts == 0) {
diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index 8224218..45d06ff 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -118,14 +118,10 @@
 /* default values for mtdids and mtdparts variables */
 #if defined(MTDIDS_DEFAULT)
 static const char *const mtdids_default = MTDIDS_DEFAULT;
-#else
-static const char *const mtdids_default = NULL;
 #endif
 
 #if defined(MTDPARTS_DEFAULT)
 static const char *const mtdparts_default = MTDPARTS_DEFAULT;
-#else
-static const char *const mtdparts_default = NULL;
 #endif
 
 /* copies of last seen 'mtdids', 'mtdparts' and 'partition' env variables */
diff --git a/drivers/display/lcd/aml_lcd_clk_config.c b/drivers/display/lcd/aml_lcd_clk_config.c
index bb64fe9..6a67ffc 100755
--- a/drivers/display/lcd/aml_lcd_clk_config.c
+++ b/drivers/display/lcd/aml_lcd_clk_config.c
@@ -27,9 +27,6 @@
 static const unsigned int od_table[6] = {
 	1, 2, 4, 8, 16, 32
 };
-static const unsigned int div_pre_table[6] = {
-	1, 2, 3, 4, 5, 6
-};
 static const unsigned int pi_div_table[2] = {2, 4};
 
 static char *lcd_clk_div_sel_table[] = {
diff --git a/drivers/gpio/amlogic_gpio.c b/drivers/gpio/amlogic_gpio.c
index 2054b27..f19c552 100644
--- a/drivers/gpio/amlogic_gpio.c
+++ b/drivers/gpio/amlogic_gpio.c
@@ -66,7 +66,7 @@
 	unsigned int bit = plat->regs[REG_DIR].bit + offset;
 	unsigned int val;
 	val = readl(reg);
-	bool dir = !!(val * BIT(bit));
+	bool dir = !!(val & BIT(bit));
 
 
 	/* GPIOF_FUNC is not implemented yet */
diff --git a/drivers/mmc/aml_emmc_partition.c b/drivers/mmc/aml_emmc_partition.c
index 13ab80d..8023d04 100755
--- a/drivers/mmc/aml_emmc_partition.c
+++ b/drivers/mmc/aml_emmc_partition.c
@@ -1047,7 +1047,6 @@
 	else
 		memcpy(gpt_e->partition_type_guid.b,
 		       &PARTITION_LINUX_DEFAULT_GUID, 16);
-		return;
 }
 
 static uint64_t fill_gpt_entry(gpt_entry *gpt_e, struct _iptbl *p_iptbl_ept)
diff --git a/drivers/mmc/aml_sd_emmc.c b/drivers/mmc/aml_sd_emmc.c
index c795377..f3b602b 100755
--- a/drivers/mmc/aml_sd_emmc.c
+++ b/drivers/mmc/aml_sd_emmc.c
@@ -276,7 +276,7 @@
     }
     if (!sdio->inited_flag)
         sdio->inited_flag = 1;
-	return SD_NO_ERROR;
+    return SD_NO_ERROR;
 }
 
 
diff --git a/drivers/mtd/nand/amlogic_mtd/aml_nand.c b/drivers/mtd/nand/amlogic_mtd/aml_nand.c
index 46526ed..142b475 100644
--- a/drivers/mtd/nand/amlogic_mtd/aml_nand.c
+++ b/drivers/mtd/nand/amlogic_mtd/aml_nand.c
@@ -2701,8 +2701,8 @@
 					NAND_CMD_PAGEPROG,
 					-1, -1, i);
 
-				oob_buf += nand_oob_size;
-				buf += nand_page_size;
+			oob_buf += nand_oob_size;
+			buf += nand_page_size;
 			} else {
 				error = -ENODEV;
 				goto exit;
diff --git a/drivers/mtd/nand/amlogic_mtd/rsv_manage.c b/drivers/mtd/nand/amlogic_mtd/rsv_manage.c
index af489c7..c7c4589 100644
--- a/drivers/mtd/nand/amlogic_mtd/rsv_manage.c
+++ b/drivers/mtd/nand/amlogic_mtd/rsv_manage.c
@@ -243,17 +243,17 @@
 
 				//printk("col0_data =%x\n",col0_data);
 
-				if (aml_chip->mfr_type  != NAND_MFR_SANDISK)
-					aml_chip->aml_nand_command(aml_chip,
-						NAND_CMD_RNDOUT,
-						aml_chip->page_size, -1, i);
-				udelay(2);
+			if (aml_chip->mfr_type  != NAND_MFR_SANDISK)
+				aml_chip->aml_nand_command(aml_chip,
+					NAND_CMD_RNDOUT,
+					aml_chip->page_size, -1, i);
+			udelay(2);
 
-				if (aml_chip->mfr_type  == NAND_MFR_SANDISK)
-					col0_oob = 0x0;
-				else
-					col0_oob = chip->read_byte(mtd);
-				//printk("col0_oob =%x\n",col0_oob);
+			if (aml_chip->mfr_type  == NAND_MFR_SANDISK)
+				col0_oob = 0x0;
+			else
+				col0_oob = chip->read_byte(mtd);
+			//printk("col0_oob =%x\n",col0_oob);
 			}
 
 	if ((aml_chip->mfr_type  == 0xC8 )) {
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 4640df3..650db96 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -216,11 +216,21 @@
 	return s_fastboot_busy;
 }
 
+#ifdef CONFIG_DEV_BUILD
+static void print_usb_request_data(struct usb_request *req);
+#endif
+
 /* cb for bulk in_req->complete */
 static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
 {
 	int status = req->status;
 
+	#ifdef CONFIG_DEV_BUILD
+		printf("An IN-EP request complete: ");
+		print_usb_request_data(req);
+		printf("\n");
+	#endif
+
 	if (fastboot_is_busy() && fastboot_func) {
 		struct usb_ep *out_ep = fastboot_func->out_ep;
 		struct usb_request *out_req = fastboot_func->out_req;
@@ -431,6 +441,111 @@
 
 DECLARE_GADGET_BIND_CALLBACK(usb_dnl_fastboot, fastboot_add);
 
+#ifdef CONFIG_DEV_BUILD
+static void rx_handler_command(struct usb_ep *ep, struct usb_request *req);
+static void fastboot_complete(struct usb_ep *ep, struct usb_request *req);
+static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req);
+static void tx_handler_upload_image(struct usb_ep *ep, struct usb_request *req);
+static void compl_do_reboot_bootloader(struct usb_ep *ep,
+				       struct usb_request *req);
+static void compl_do_reboot_recovery(struct usb_ep *ep,
+				     struct usb_request *req);
+static void compl_do_reset(struct usb_ep *ep, struct usb_request *req);
+static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req);
+
+static const char *complete_cb_name(struct usb_request *req)
+{
+	if (req->complete == rx_handler_command) {
+		return "rx_handler_command";
+	} else if (req->complete == fastboot_complete) {
+		return "fastboot_complete";
+	} else if (req->complete == rx_handler_dl_image) {
+		return "rx_handler_dl_image";
+	} else if (req->complete == tx_handler_upload_image) {
+		return "tx_handler_upload_image";
+	} else if (req->complete == compl_do_reboot_bootloader) {
+		return "compl_do_reboot_bootloader";
+	} else if (req->complete == compl_do_reboot_recovery) {
+		return "compl_do_reboot_recovery";
+	} else if (req->complete == compl_do_reset) {
+		return "compl_do_reset";
+	} else if (req->complete == do_bootm_on_complete) {
+		return "do_bootm_on_complete";
+	}
+
+	printf("unkonwn usb cb: %p\n", req->complete);
+	return "";
+}
+
+static void print_usb_request_data(struct usb_request *req)
+{
+	for (size_t i = 0; i < req->length; i++) {
+		char ch = ((uint8_t *)req->buf)[i];
+		const char *fmt = (ch >= ' ' && ch <= '~') ? "%c" : "\\x%02x";
+		printf(fmt, ch);
+	}
+}
+
+#define INITIAL_LOG_TIMEOUT_MS 3000
+static size_t curr_in_eq_queue_id = 0;
+static int in_eq_queue_log_timeout = INITIAL_LOG_TIMEOUT_MS;
+static size_t curr_out_eq_queue_id = 0;
+static int out_eq_queue_log_timeout = INITIAL_LOG_TIMEOUT_MS;
+
+void fastboot_usb_status_poll(void)
+{
+	if (!fastboot_func || !fastboot_func->in_req ||
+	    !fastboot_func->out_req) {
+		return;
+	}
+
+	struct usb_request *in_req = fastboot_func->in_req;
+	// Reset log timeout if it is a new IN EP request.
+	if (curr_in_eq_queue_id != in_req->queue_id) {
+		curr_in_eq_queue_id = in_req->queue_id;
+		in_eq_queue_log_timeout = INITIAL_LOG_TIMEOUT_MS;
+	}
+
+	if (in_req->status) {
+		if (get_timer(in_req->queue_start_time) >
+		    in_eq_queue_log_timeout) {
+			// Exponential back off timeout
+			in_eq_queue_log_timeout <<= 1;
+			printf("Fastboot: a send has been pending for %lu seconds. ",
+			       get_timer(in_req->queue_start_time) / 1000);
+			printf("Send data is: \"");
+			print_usb_request_data(in_req);
+			printf("\". Send callback: %s\n",
+			       complete_cb_name(in_req));
+		}
+	}
+
+	struct usb_request *out_req = fastboot_func->out_req;
+	// Reset log timeout if it is a new OUT EP request.
+	if (curr_out_eq_queue_id != out_req->queue_id) {
+		curr_out_eq_queue_id = out_req->queue_id;
+		out_eq_queue_log_timeout = INITIAL_LOG_TIMEOUT_MS;
+	}
+
+	if (out_req->status) {
+		if (get_timer(out_req->queue_start_time) >
+		    out_eq_queue_log_timeout) {
+			// Exponential back off timeout
+			out_eq_queue_log_timeout <<= 1;
+			printf("Fastboot: no data received for %lu seconds. ",
+			       get_timer(out_req->queue_start_time) / 1000);
+			printf("Receive callback: %s\n",
+			       complete_cb_name(out_req));
+			if (out_req->complete == rx_handler_dl_image) {
+				printf("download remains: 0x%x, total: 0x%x\n",
+				       download_size - download_bytes,
+				       download_size);
+			}
+		}
+	}
+}
+#endif
+
 static int fastboot_tx_write(const char *buffer, unsigned int buffer_size)
 {
 	struct usb_request *in_req = fastboot_func->in_req;
@@ -2186,7 +2301,13 @@
 		if (req->actual < req->length) {
 			u8 *buf = (u8 *) req->buf;
 			buf[req->actual] = 0;
+#ifdef CONFIG_DEV_BUILD
+			printf("Fastboot command: %s...\n", buf);
+#endif
 			func_cb(ep, req);
+#ifdef CONFIG_DEV_BUILD
+			printf("Fastboot command done.\n");
+#endif
 		} else {
 			error("buffer overflow\n");
 			fastboot_fail("FAILbuffer overflow");
diff --git a/drivers/usb/gadget/fastboot/dwc_pcd_irq.c b/drivers/usb/gadget/fastboot/dwc_pcd_irq.c
index 9d281cc..537127e 100755
--- a/drivers/usb/gadget/fastboot/dwc_pcd_irq.c
+++ b/drivers/usb/gadget/fastboot/dwc_pcd_irq.c
@@ -781,6 +781,14 @@
 					complete_ep(epnum, 0);
 				}
 			}
+
+			// If there are interrupt bits set other than transfer complete and set up,
+			// log it.
+			if (doepint.d32 & ~0x9) {
+				printf("epnum = %d, OUT EP has additional interrupt: %x\n",
+				       epnum, doepint.d32);
+			}
+
 			/* Endpoint disable  */
 			if (doepint.b.epdisabled) {
 				/* Clear the bit in DOEPINTn for this interrupt */
@@ -863,6 +871,13 @@
 						CLEAR_IN_EP_INTR(epnum, nak);
 				}
 			}
+
+			// If there are interrupt bits set other than transfer complete.
+			if (diepint.d32 & ~0x1) {
+				printf("epnum = %d, IN EP has additional interrupt: %x\n",
+				       epnum, diepint.d32);
+			}
+
 			/* Endpoint disable  */
 			if (diepint.b.epdisabled) {
 				/* Clear the bit in DIEPINTn for this interrupt */
@@ -1042,8 +1057,16 @@
 	dwc_write_reg32 (DWC_REG_GINTSTS, gintsts.d32);
 }
 
+#ifdef CONFIG_DEV_BUILD
+void fastboot_usb_status_poll(void);
+#endif
+
 int f_dwc_pcd_irq(void)
 {
+#ifdef CONFIG_DEV_BUILD
+	fastboot_usb_status_poll();
+#endif
+
 	gintsts_data_t  gintr_status;
 	gintsts_data_t  gintr_msk;
 	gotgint_data_t  gotgint;
diff --git a/fip/build_bl33.sh b/fip/build_bl33.sh
index 82e3c67..bb6a55d 100755
--- a/fip/build_bl33.sh
+++ b/fip/build_bl33.sh
@@ -2,8 +2,7 @@
 
 LOCAL_PATH="$(readlink -f $(dirname ${BASH_SOURCE[0]})/)"
 
-
-readonly cross_compile=${LOCAL_PATH}/../../sdk/linaro/gcc-linaro-aarch64-none-elf-4.8-2013.11_linux/bin/aarch64-none-elf-
+readonly cross_compile=${LOCAL_PATH}/../../sdk/linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-elf/bin/aarch64-elf-
 readonly cross_compile_t32=${LOCAL_PATH}/../../sdk/linaro/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-
 
 function pre_build_uboot() {
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index e057bd2..22ab246 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -5,14 +5,28 @@
 /*
  * Common definitions for all gcc versions go here.
  */
-#define GCC_VERSION (__GNUC__ * 10000 \
-		   + __GNUC_MINOR__ * 100 \
-		   + __GNUC_PATCHLEVEL__)
-
+#define GCC_VERSION (__GNUC__ * 10000		\
+		     + __GNUC_MINOR__ * 100	\
+		     + __GNUC_PATCHLEVEL__)
 
 /* Optimization barrier */
+
 /* The "volatile" is due to gcc bugs */
 #define barrier() __asm__ __volatile__("": : :"memory")
+/*
+ * This version is i.e. to prevent dead stores elimination on @ptr
+ * where gcc and llvm may behave differently when otherwise using
+ * normal barrier(): while gcc behavior gets along with a normal
+ * barrier(), llvm needs an explicit input variable to be assumed
+ * clobbered. The issue is as follows: while the inline asm might
+ * access any memory it wants, the compiler could have fit all of
+ * @ptr into memory registers instead, and since @ptr never escaped
+ * from that, it proofed that the inline asm wasn't touching any of
+ * it. This version works well with both compilers, i.e. we're telling
+ * the compiler that the inline asm absolutely may see the contents
+ * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495
+ */
+#define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory")
 
 /*
  * This macro obfuscates arithmetic on a variable address so that gcc
@@ -32,58 +46,63 @@
  * the inline assembly constraint from =g to =r, in this particular
  * case either is valid.
  */
-#define RELOC_HIDE(ptr, off)					\
-  ({ unsigned long __ptr;					\
-    __asm__ ("" : "=r"(__ptr) : "0"(ptr));		\
-    (typeof(ptr)) (__ptr + (off)); })
+#define RELOC_HIDE(ptr, off)						\
+({									\
+	unsigned long __ptr;						\
+	__asm__ ("" : "=r"(__ptr) : "0"(ptr));				\
+	(typeof(ptr)) (__ptr + (off));					\
+})
 
 /* Make the optimizer believe the variable can be manipulated arbitrarily. */
-#define OPTIMIZER_HIDE_VAR(var) __asm__ ("" : "=r" (var) : "0" (var))
+#define OPTIMIZER_HIDE_VAR(var)						\
+	__asm__ ("" : "=r" (var) : "0" (var))
 
 #ifdef __CHECKER__
-#define __must_be_array(arr) 0
+#define __must_be_array(a)	0
 #else
 /* &a[0] degrades to a pointer: a different type from an array */
-#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
+#define __must_be_array(a)	BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
 #endif
 
 /*
  * Force always-inline if the user requests it so via the .config,
  * or if gcc is too old:
  */
-#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
+#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) ||		\
     !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
-# define inline		inline		__attribute__((always_inline)) notrace
-# define __inline__	__inline__	__attribute__((always_inline)) notrace
-# define __inline	__inline	__attribute__((always_inline)) notrace
+#define inline		inline		__attribute__((always_inline)) notrace
+#define __inline__	__inline__	__attribute__((always_inline)) notrace
+#define __inline	__inline	__attribute__((always_inline)) notrace
 #else
 /* A lot of inline functions can cause havoc with function tracing */
-# define inline		inline		notrace
-# define __inline__	__inline__	notrace
-# define __inline	__inline	notrace
+#define inline		inline		notrace
+#define __inline__	__inline__	notrace
+#define __inline	__inline	notrace
 #endif
 
-#define __deprecated			__attribute__((deprecated))
-#ifndef __packed
-#define __packed			__attribute__((packed))
-#endif
-#ifndef __weak
-#define __weak				__attribute__((weak))
-#endif
+#define __always_inline	inline __attribute__((always_inline))
+#define  noinline	__attribute__((noinline))
+
+#define __deprecated	__attribute__((deprecated))
+#define __packed	__attribute__((packed))
+#define __weak		__attribute__((weak))
+#define __alias(symbol)	__attribute__((alias(#symbol)))
 
 /*
- * it doesn't make sense on ARM (currently the only user of __naked) to trace
- * naked functions because then mcount is called without stack and frame pointer
- * being set up and there is no chance to restore the lr register to the value
- * before mcount was called.
+ * it doesn't make sense on ARM (currently the only user of __naked)
+ * to trace naked functions because then mcount is called without
+ * stack and frame pointer being set up and there is no chance to
+ * restore the lr register to the value before mcount was called.
  *
- * The asm() bodies of naked functions often depend on standard calling conventions,
- * therefore they must be noinline and noclone.  GCC 4.[56] currently fail to enforce
- * this, so we must do so ourselves.  See GCC PR44290.
+ * The asm() bodies of naked functions often depend on standard calling
+ * conventions, therefore they must be noinline and noclone.
+ *
+ * GCC 4.[56] currently fail to enforce this, so we must do so ourselves.
+ * See GCC PR44290.
  */
-#define __naked				__attribute__((naked)) noinline __noclone notrace
+#define __naked		__attribute__((naked)) noinline __noclone notrace
 
-#define __noreturn			__attribute__((noreturn))
+#define __noreturn	__attribute__((noreturn))
 
 /*
  * From the GCC manual:
@@ -95,34 +114,170 @@
  * would be.
  * [...]
  */
-#ifndef __pure
-#define __pure				__attribute__((pure))
-#endif
-#ifndef __aligned
-#define __aligned(x)			__attribute__((aligned(x)))
-#endif
-#define __printf(a, b)			__attribute__((format(printf, a, b)))
-#define __scanf(a, b)			__attribute__((format(scanf, a, b)))
-#define  noinline			__attribute__((noinline))
-#define __attribute_const__		__attribute__((__const__))
-#define __maybe_unused			__attribute__((unused))
-#define __always_unused			__attribute__((unused))
+#define __pure			__attribute__((pure))
+#define __aligned(x)		__attribute__((aligned(x)))
+#define __printf(a, b)		__attribute__((format(printf, a, b)))
+#define __scanf(a, b)		__attribute__((format(scanf, a, b)))
+#define __attribute_const__	__attribute__((__const__))
+#define __maybe_unused		__attribute__((unused))
+#define __always_unused		__attribute__((unused))
 
-#define __gcc_header(x) #x
-#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
-#define gcc_header(x) _gcc_header(x)
-#include gcc_header(__GNUC__)
+/* gcc version specific checks */
+
+#if GCC_VERSION < 30200
+# error Sorry, your compiler is too old - please upgrade it.
+#endif
+
+#if GCC_VERSION < 30300
+# define __used			__attribute__((__unused__))
+#else
+# define __used			__attribute__((__used__))
+#endif
+
+#ifdef CONFIG_GCOV_KERNEL
+# if GCC_VERSION < 30400
+#   error "GCOV profiling support for gcc versions below 3.4 not included"
+# endif /* __GNUC_MINOR__ */
+#endif /* CONFIG_GCOV_KERNEL */
+
+#if GCC_VERSION >= 30400
+#define __must_check		__attribute__((warn_unused_result))
+#endif
+
+#if GCC_VERSION >= 40000
+
+/* GCC 4.1.[01] miscompiles __weak */
+#ifdef __KERNEL__
+# if GCC_VERSION >= 40100 &&  GCC_VERSION <= 40101
+#  error Your version of gcc miscompiles the __weak directive
+# endif
+#endif
+
+#define __used			__attribute__((__used__))
+#define __compiler_offsetof(a, b)					\
+	__builtin_offsetof(a, b)
+
+#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
+# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
+#endif
+
+#if GCC_VERSION >= 40300
+/* Mark functions as cold. gcc will assume any path leading to a call
+ * to them will be unlikely.  This means a lot of manual unlikely()s
+ * are unnecessary now for any paths leading to the usual suspects
+ * like BUG(), printk(), panic() etc. [but let's keep them for now for
+ * older compilers]
+ *
+ * Early snapshots of gcc 4.3 don't support this and we can't detect this
+ * in the preprocessor, but we can live with this because they're unreleased.
+ * Maketime probing would be overkill here.
+ *
+ * gcc also has a __attribute__((__hot__)) to move hot functions into
+ * a special section, but I don't see any sense in this right now in
+ * the kernel context
+ */
+#define __cold			__attribute__((__cold__))
+
+#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
+
+#ifndef __CHECKER__
+# define __compiletime_warning(message) __attribute__((warning(message)))
+# define __compiletime_error(message) __attribute__((error(message)))
+#endif /* __CHECKER__ */
+#endif /* GCC_VERSION >= 40300 */
+
+#if GCC_VERSION >= 40500
+/*
+ * Mark a position in code as unreachable.  This can be used to
+ * suppress control flow warnings after asm blocks that transfer
+ * control elsewhere.
+ *
+ * Early snapshots of gcc 4.5 don't support this and we can't detect
+ * this in the preprocessor, but we can live with this because they're
+ * unreleased.  Really, we need to have autoconf for the kernel.
+ */
+#define unreachable() __builtin_unreachable()
+
+/* Mark a function definition as prohibited from being cloned. */
+#define __noclone	__attribute__((__noclone__))
+
+#endif /* GCC_VERSION >= 40500 */
+
+#if GCC_VERSION >= 40600
+/*
+ * When used with Link Time Optimization, gcc can optimize away C functions or
+ * variables which are referenced only from assembly code.  __visible tells the
+ * optimizer that something else uses this function or variable, thus preventing
+ * this.
+ */
+#define __visible	__attribute__((externally_visible))
+#endif
+
+
+#if GCC_VERSION >= 40900 && !defined(__CHECKER__)
+/*
+ * __assume_aligned(n, k): Tell the optimizer that the returned
+ * pointer can be assumed to be k modulo n. The second argument is
+ * optional (default 0), so we use a variadic macro to make the
+ * shorthand.
+ *
+ * Beware: Do not apply this to functions which may return
+ * ERR_PTRs. Also, it is probably unwise to apply it to functions
+ * returning extra information in the low bits (but in that case the
+ * compiler should see some alignment anyway, when the return value is
+ * massaged by 'flags = ptr & 3; ptr &= ~3;').
+ */
+#define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__)))
+#endif
+
+/*
+ * GCC 'asm goto' miscompiles certain code sequences:
+ *
+ *   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
+ *
+ * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
+ *
+ * (asm goto is automatically volatile - the naming reflects this.)
+ */
+#define asm_volatile_goto(x...)	do { asm goto(x); asm (""); } while (0)
+
+#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
+#if GCC_VERSION >= 40400
+#define __HAVE_BUILTIN_BSWAP32__
+#define __HAVE_BUILTIN_BSWAP64__
+#endif
+#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
+#define __HAVE_BUILTIN_BSWAP16__
+#endif
+#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
+
+#if GCC_VERSION >= 50000
+#define KASAN_ABI_VERSION 4
+#elif GCC_VERSION >= 40902
+#define KASAN_ABI_VERSION 3
+#endif
+
+#if GCC_VERSION >= 40902
+/*
+ * Tell the compiler that address safety instrumentation (KASAN)
+ * should not be applied to that function.
+ * Conflicts with inlining: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
+ */
+#define __no_sanitize_address __attribute__((no_sanitize_address))
+#endif
+
+#endif	/* gcc version >= 40000 specific checks */
 
 #if !defined(__noclone)
 #define __noclone	/* not needed */
 #endif
 
+#if !defined(__no_sanitize_address)
+#define __no_sanitize_address
+#endif
+
 /*
  * A trick to suppress uninitialized variable warning without generating any
  * code
  */
 #define uninitialized_var(x) x = x
-
-#ifndef __always_inline
-#define __always_inline		inline __attribute__((always_inline))
-#endif
diff --git a/include/linux/compiler-gcc3.h b/include/linux/compiler-gcc3.h
deleted file mode 100644
index 7d89feb..0000000
--- a/include/linux/compiler-gcc3.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef __LINUX_COMPILER_H
-#error "Please don't include <linux/compiler-gcc3.h> directly, include <linux/compiler.h> instead."
-#endif
-
-#if GCC_VERSION < 30200
-# error Sorry, your compiler is too old - please upgrade it.
-#endif
-
-#if GCC_VERSION >= 30300
-# define __used			__attribute__((__used__))
-#else
-# define __used			__attribute__((__unused__))
-#endif
-
-#if GCC_VERSION >= 30400
-#define __must_check		__attribute__((warn_unused_result))
-#endif
-
-#ifdef CONFIG_GCOV_KERNEL
-# if GCC_VERSION < 30400
-#   error "GCOV profiling support for gcc versions below 3.4 not included"
-# endif /* __GNUC_MINOR__ */
-#endif /* CONFIG_GCOV_KERNEL */
diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
deleted file mode 100644
index 2507fd2..0000000
--- a/include/linux/compiler-gcc4.h
+++ /dev/null
@@ -1,88 +0,0 @@
-#ifndef __LINUX_COMPILER_H
-#error "Please don't include <linux/compiler-gcc4.h> directly, include <linux/compiler.h> instead."
-#endif
-
-/* GCC 4.1.[01] miscompiles __weak */
-#ifdef __KERNEL__
-# if GCC_VERSION >= 40100 &&  GCC_VERSION <= 40101
-#  error Your version of gcc miscompiles the __weak directive
-# endif
-#endif
-
-#define __used			__attribute__((__used__))
-#define __must_check 		__attribute__((warn_unused_result))
-#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
-
-#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
-# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
-#endif
-
-#if GCC_VERSION >= 40300
-/* Mark functions as cold. gcc will assume any path leading to a call
-   to them will be unlikely.  This means a lot of manual unlikely()s
-   are unnecessary now for any paths leading to the usual suspects
-   like BUG(), printk(), panic() etc. [but let's keep them for now for
-   older compilers]
-
-   Early snapshots of gcc 4.3 don't support this and we can't detect this
-   in the preprocessor, but we can live with this because they're unreleased.
-   Maketime probing would be overkill here.
-
-   gcc also has a __attribute__((__hot__)) to move hot functions into
-   a special section, but I don't see any sense in this right now in
-   the kernel context */
-#define __cold			__attribute__((__cold__))
-
-#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
-
-#ifndef __CHECKER__
-# define __compiletime_warning(message) __attribute__((warning(message)))
-# define __compiletime_error(message) __attribute__((error(message)))
-#endif /* __CHECKER__ */
-#endif /* GCC_VERSION >= 40300 */
-
-#if GCC_VERSION >= 40500
-/*
- * Mark a position in code as unreachable.  This can be used to
- * suppress control flow warnings after asm blocks that transfer
- * control elsewhere.
- *
- * Early snapshots of gcc 4.5 don't support this and we can't detect
- * this in the preprocessor, but we can live with this because they're
- * unreleased.  Really, we need to have autoconf for the kernel.
- */
-#define unreachable() __builtin_unreachable()
-
-/* Mark a function definition as prohibited from being cloned. */
-#define __noclone	__attribute__((__noclone__))
-
-#endif /* GCC_VERSION >= 40500 */
-
-#if GCC_VERSION >= 40600
-/*
- * Tell the optimizer that something else uses this function or variable.
- */
-#define __visible __attribute__((externally_visible))
-#endif
-
-/*
- * GCC 'asm goto' miscompiles certain code sequences:
- *
- *   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
- *
- * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
- * Fixed in GCC 4.8.2 and later versions.
- *
- * (asm goto is automatically volatile - the naming reflects this.)
- */
-#define asm_volatile_goto(x...)	do { asm goto(x); asm (""); } while (0)
-
-#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
-#if GCC_VERSION >= 40400
-#define __HAVE_BUILTIN_BSWAP32__
-#define __HAVE_BUILTIN_BSWAP64__
-#endif
-#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
-#define __HAVE_BUILTIN_BSWAP16__
-#endif
-#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
diff --git a/include/linux/compiler-intel.h b/include/linux/compiler-intel.h
index ba147a1..d4c7113 100644
--- a/include/linux/compiler-intel.h
+++ b/include/linux/compiler-intel.h
@@ -13,9 +13,14 @@
 /* Intel ECC compiler doesn't support gcc specific asm stmts.
  * It uses intrinsics to do the equivalent things.
  */
+#undef barrier
+#undef barrier_data
 #undef RELOC_HIDE
 #undef OPTIMIZER_HIDE_VAR
 
+#define barrier() __memory_barrier()
+#define barrier_data(ptr) barrier()
+
 #define RELOC_HIDE(ptr, off)					\
   ({ unsigned long __ptr;					\
      __ptr = (unsigned long) (ptr);				\
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index d5ad7b1..020ad16 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -17,6 +17,7 @@
 # define __release(x)	__context__(x,-1)
 # define __cond_lock(x,c)	((c) ? ({ __acquire(x); 1; }) : 0)
 # define __percpu	__attribute__((noderef, address_space(3)))
+# define __pmem		__attribute__((noderef, address_space(5)))
 #ifdef CONFIG_SPARSE_RCU_POINTER
 # define __rcu		__attribute__((noderef, address_space(4)))
 #else
@@ -42,6 +43,7 @@
 # define __cond_lock(x,c) (c)
 # define __percpu
 # define __rcu
+# define __pmem
 #endif
 
 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
@@ -54,7 +56,11 @@
 #include <linux/compiler-gcc.h>
 #endif
 
+#if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__)
+#define notrace __attribute__((hotpatch(0,0)))
+#else
 #define notrace __attribute__((no_instrument_function))
+#endif
 
 /* Intel compiler defines __GNUC__. So we will overwrite implementations
  * coming from above header files here
@@ -138,7 +144,7 @@
  */
 #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
 #define __trace_if(cond) \
-	if (__builtin_constant_p((cond)) ? !!(cond) :			\
+	if (__builtin_constant_p(!!(cond)) ? !!(cond) :			\
 	({								\
 		int ______r;						\
 		static struct ftrace_branch_data			\
@@ -165,6 +171,10 @@
 # define barrier() __memory_barrier()
 #endif
 
+#ifndef barrier_data
+# define barrier_data(ptr) barrier()
+#endif
+
 /* Unreachable code */
 #ifndef unreachable
 # define unreachable() do { } while (1)
@@ -186,6 +196,126 @@
 # define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__)
 #endif
 
+#include <linux/types.h>
+
+#define __READ_ONCE_SIZE						\
+({									\
+	switch (size) {							\
+	case 1: *(__u8 *)res = *(volatile __u8 *)p; break;		\
+	case 2: *(__u16 *)res = *(volatile __u16 *)p; break;		\
+	case 4: *(__u32 *)res = *(volatile __u32 *)p; break;		\
+	case 8: *(__u64 *)res = *(volatile __u64 *)p; break;		\
+	default:							\
+		barrier();						\
+		__builtin_memcpy((void *)res, (const void *)p, size);	\
+		barrier();						\
+	}								\
+})
+
+static __always_inline
+void __read_once_size(const volatile void *p, void *res, int size)
+{
+	__READ_ONCE_SIZE;
+}
+
+#ifdef CONFIG_KASAN
+/*
+ * This function is not 'inline' because __no_sanitize_address confilcts
+ * with inlining. Attempt to inline it may cause a build failure.
+ * 	https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
+ * '__maybe_unused' allows us to avoid defined-but-not-used warnings.
+ */
+static __no_sanitize_address __maybe_unused
+void __read_once_size_nocheck(const volatile void *p, void *res, int size)
+{
+	__READ_ONCE_SIZE;
+}
+#else
+static __always_inline
+void __read_once_size_nocheck(const volatile void *p, void *res, int size)
+{
+	__READ_ONCE_SIZE;
+}
+#endif
+
+static __always_inline void __write_once_size(volatile void *p, void *res, int size)
+{
+	switch (size) {
+	case 1: *(volatile __u8 *)p = *(__u8 *)res; break;
+	case 2: *(volatile __u16 *)p = *(__u16 *)res; break;
+	case 4: *(volatile __u32 *)p = *(__u32 *)res; break;
+	case 8: *(volatile __u64 *)p = *(__u64 *)res; break;
+	default:
+		barrier();
+		__builtin_memcpy((void *)p, (const void *)res, size);
+		barrier();
+	}
+}
+
+/*
+ * Prevent the compiler from merging or refetching reads or writes. The
+ * compiler is also forbidden from reordering successive instances of
+ * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the
+ * compiler is aware of some particular ordering.  One way to make the
+ * compiler aware of ordering is to put the two invocations of READ_ONCE,
+ * WRITE_ONCE or ACCESS_ONCE() in different C statements.
+ *
+ * In contrast to ACCESS_ONCE these two macros will also work on aggregate
+ * data types like structs or unions. If the size of the accessed data
+ * type exceeds the word size of the machine (e.g., 32 bits or 64 bits)
+ * READ_ONCE() and WRITE_ONCE()  will fall back to memcpy and print a
+ * compile-time warning.
+ *
+ * Their two major use cases are: (1) Mediating communication between
+ * process-level code and irq/NMI handlers, all running on the same CPU,
+ * and (2) Ensuring that the compiler does not  fold, spindle, or otherwise
+ * mutilate accesses that either do not require ordering or that interact
+ * with an explicit memory barrier or atomic instruction that provides the
+ * required ordering.
+ */
+
+#define __READ_ONCE(x, check)						\
+({									\
+	union { typeof(x) __val; char __c[1]; } __u;			\
+	if (check)							\
+		__read_once_size(&(x), __u.__c, sizeof(x));		\
+	else								\
+		__read_once_size_nocheck(&(x), __u.__c, sizeof(x));	\
+	__u.__val;							\
+})
+#define READ_ONCE(x) __READ_ONCE(x, 1)
+
+/*
+ * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need
+ * to hide memory access from KASAN.
+ */
+#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
+
+#define WRITE_ONCE(x, val) \
+({							\
+	union { typeof(x) __val; char __c[1]; } __u =	\
+		{ .__val = (__force typeof(x)) (val) }; \
+	__write_once_size(&(x), __u.__c, sizeof(x));	\
+	__u.__val;					\
+})
+
+/**
+ * smp_cond_acquire() - Spin wait for cond with ACQUIRE ordering
+ * @cond: boolean expression to wait for
+ *
+ * Equivalent to using smp_load_acquire() on the condition variable but employs
+ * the control dependency of the wait to reduce the barrier on many platforms.
+ *
+ * The control dependency provides a LOAD->STORE order, the additional RMB
+ * provides LOAD->LOAD order, together they provide LOAD->{LOAD,STORE} order,
+ * aka. ACQUIRE.
+ */
+#define smp_cond_acquire(cond)	do {		\
+	while (!(cond))				\
+		cpu_relax();			\
+	smp_rmb(); /* ctrl + rmb := acquire */	\
+} while (0)
+
 #endif /* __KERNEL__ */
 
 #endif /* __ASSEMBLY__ */
@@ -304,6 +434,14 @@
 #define __visible
 #endif
 
+/*
+ * Assume alignment of return value.
+ */
+#ifndef __assume_aligned
+#define __assume_aligned(a, ...)
+#endif
+
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #ifndef __same_type
 # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
@@ -311,7 +449,7 @@
 
 /* Is this type a native word size -- useful for atomic operations */
 #ifndef __native_word
-# define __native_word(t) (sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
+# define __native_word(t) (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
 #endif
 
 /* Compile time object size, -1 for unknown */
@@ -373,12 +511,38 @@
  * to make the compiler aware of ordering is to put the two invocations of
  * ACCESS_ONCE() in different C statements.
  *
- * This macro does absolutely -nothing- to prevent the CPU from reordering,
- * merging, or refetching absolutely anything at any time.  Its main intended
- * use is to mediate communication between process-level code and irq/NMI
- * handlers, all running on the same CPU.
+ * ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE
+ * on a union member will work as long as the size of the member matches the
+ * size of the union and the size is smaller than word size.
+ *
+ * The major use cases of ACCESS_ONCE used to be (1) Mediating communication
+ * between process-level code and irq/NMI handlers, all running on the same CPU,
+ * and (2) Ensuring that the compiler does not  fold, spindle, or otherwise
+ * mutilate accesses that either do not require ordering or that interact
+ * with an explicit memory barrier or atomic instruction that provides the
+ * required ordering.
+ *
+ * If possible use READ_ONCE()/WRITE_ONCE() instead.
  */
-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
+#define __ACCESS_ONCE(x) ({ \
+	 __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \
+	(volatile typeof(x) *)&(x); })
+#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x))
+
+/**
+ * lockless_dereference() - safely load a pointer for later dereference
+ * @p: The pointer to load
+ *
+ * Similar to rcu_dereference(), but for situations where the pointed-to
+ * object's lifetime is managed by something other than RCU.  That
+ * "something other" might be reference counting or simple immortality.
+ */
+#define lockless_dereference(p) \
+({ \
+	typeof(p) _________p1 = READ_ONCE(p); \
+	smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
+	(_________p1); \
+})
 
 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
 #ifdef CONFIG_KPROBES
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 9bccd45..96c2a17 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -96,6 +96,9 @@
 
 	int			status;
 	unsigned		actual;
+
+	int queue_start_time;
+	size_t queue_id;
 };
 
 /*-------------------------------------------------------------------------*/
@@ -288,6 +291,9 @@
 static inline int usb_ep_queue(struct usb_ep *ep,
 			       struct usb_request *req, gfp_t gfp_flags)
 {
+	static size_t queue_id = 0;
+	req->queue_start_time = get_timer(0);
+	req->queue_id = queue_id++;
 	return ep->ops->queue(ep, req, gfp_flags);
 }
 
diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c
index 670b9fd..af1a515 100644
--- a/tools/relocate-rela.c
+++ b/tools/relocate-rela.c
@@ -63,11 +63,6 @@
 }
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
-static inline uint64_t be64(uint64_t val)
-{
-	return swap64(val);
-}
-
 static inline uint64_t le64(uint64_t val)
 {
 	return val;
@@ -77,11 +72,6 @@
 {
 	return swap64(val);
 }
-
-static inline uint64_t be64(uint64_t val)
-{
-	return val;
-}
 #endif
 
 static bool read_num(const char *str, uint64_t *num)