Skip to content

Commit d1fbbc0

Browse files
authored
Merge pull request #1 from Molyuu/dev
Dev
2 parents 5b37a2f + cfa9f4c commit d1fbbc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+6381
-2761
lines changed

arch/arm64/Kconfig

+9
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,15 @@ config COMPAT_VDSO
11741174
You must have a 32-bit build of glibc 2.22 or later for programs
11751175
to seamlessly take advantage of this.
11761176

1177+
config MITIGATE_SPECTRE_BRANCH_HISTORY
1178+
bool "Mitigate Spectre style attacks against branch history" if EXPERT
1179+
default y
1180+
help
1181+
Speculation attacks against some high-performance processors can
1182+
make use of branch history to influence future speculation.
1183+
When taking an exception from user-space, a sequence of branches
1184+
or a firmware call overwrites the branch history.
1185+
11771186
menuconfig ARMV8_DEPRECATED
11781187
bool "Emulate deprecated/obsolete ARMv8 instructions"
11791188
depends on COMPAT

arch/arm64/configs/vendor/kona-perf_defconfig

+2
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ CONFIG_DUMMY=y
322322
CONFIG_TUN=y
323323
CONFIG_VETH=y
324324
CONFIG_AQFWD=y
325+
CONFIG_IGB=y
325326
CONFIG_SKY2=y
326327
CONFIG_RMNET=y
327328
CONFIG_SMSC911X=y
@@ -719,6 +720,7 @@ CONFIG_CRYPTO_ANSI_CPRNG=y
719720
CONFIG_CRYPTO_DEV_QCOM_MSM_QCE=y
720721
CONFIG_CRYPTO_DEV_QCRYPTO=y
721722
CONFIG_CRYPTO_DEV_QCEDEV=y
723+
CONFIG_CRYPTO_DEV_QCOM_ICE=y
722724
CONFIG_PRINTK_TIME=y
723725
CONFIG_DEBUG_INFO=y
724726
CONFIG_DEBUG_FS=y

arch/arm64/configs/vendor/kona_defconfig

+2
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ CONFIG_DUMMY=y
335335
CONFIG_TUN=y
336336
CONFIG_VETH=y
337337
CONFIG_AQFWD=y
338+
CONFIG_IGB=y
338339
CONFIG_RMNET=y
339340
CONFIG_PPP=y
340341
CONFIG_PPP_BSDCOMP=y
@@ -756,6 +757,7 @@ CONFIG_CRYPTO_ANSI_CPRNG=y
756757
CONFIG_CRYPTO_DEV_QCOM_MSM_QCE=y
757758
CONFIG_CRYPTO_DEV_QCRYPTO=y
758759
CONFIG_CRYPTO_DEV_QCEDEV=y
760+
CONFIG_CRYPTO_DEV_QCOM_ICE=y
759761
CONFIG_XZ_DEC=y
760762
CONFIG_PRINTK_TIME=y
761763
CONFIG_DYNAMIC_DEBUG=y

arch/arm64/include/asm/assembler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU
739739
.Lyield_out_\@ :
740740
.endm
741741

742-
.macro __mitigate_spectre_bhb_loop tmp
742+
.macro __mitigate_spectre_bhb_loop tmp
743743
#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY
744744
alternative_cb spectre_bhb_patch_loop_iter
745745
mov \tmp, #32 // Patched to correct the immediate
@@ -760,7 +760,7 @@ alternative_cb_end
760760
stp x2, x3, [sp, #-16]!
761761
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_3
762762
alternative_cb arm64_update_smccc_conduit
763-
nop // Patched to SMC/HVC #0
763+
nop // Patched to SMC/HVC #0
764764
alternative_cb_end
765765
ldp x2, x3, [sp], #16
766766
ldp x0, x1, [sp], #16

arch/arm64/include/asm/cpucaps.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#define ARM64_WORKAROUND_1188873 35
5757
#define ARM64_WORKAROUND_1542418 36
5858
#define ARM64_WORKAROUND_1542419 37
59-
#define ARM64_SPECTRE_BHB 38
59+
#define ARM64_SPECTRE_BHB 38
6060

6161
/* kabi: reserve 38 - 62 for future cpu capabilities */
6262
#define ARM64_NCAPS 62

arch/arm64/include/asm/cpufeature.h

+1
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ enum mitigation_state arm64_get_spectre_bhb_state(void);
571571
bool is_spectre_bhb_affected(const struct arm64_cpu_capabilities *entry, int scope);
572572
u8 spectre_bhb_loop_affected(int scope);
573573
void spectre_bhb_enable_mitigation(const struct arm64_cpu_capabilities *__unused);
574+
574575
#endif /* __ASSEMBLY__ */
575576

576577
#endif

arch/arm64/include/asm/cputype.h

+14
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
#define ARM_CPU_PART_KRYO2XX_GOLD 0x800
8686
#define ARM_CPU_PART_KRYO2XX_SILVER 0x801
8787
#define ARM_CPU_PART_CORTEX_A77 0xD0D
88+
#define ARM_CPU_PART_NEOVERSE_V1 0xD40
89+
#define ARM_CPU_PART_CORTEX_A78 0xD41
90+
#define ARM_CPU_PART_CORTEX_X1 0xD44
91+
#define ARM_CPU_PART_CORTEX_A710 0xD47
92+
#define ARM_CPU_PART_CORTEX_X2 0xD48
93+
#define ARM_CPU_PART_NEOVERSE_N2 0xD49
94+
#define ARM_CPU_PART_CORTEX_A78C 0xD4B
8895
#define ARM_CPU_PART_NEOVERSE_N1 0xD0C
8996
#define ARM_CPU_PART_CORTEX_A77 0xD0D
9097
#define ARM_CPU_PART_NEOVERSE_V1 0xD40
@@ -124,6 +131,13 @@
124131
#define MIDR_KRYO4G MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, ARM_CPU_PART_KRYO4G)
125132
#define MIDR_KRYO5S MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, ARM_CPU_PART_KRYO5S)
126133
#define MIDR_CORTEX_A77 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A77)
134+
#define MIDR_NEOVERSE_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_V1)
135+
#define MIDR_CORTEX_A78 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A78)
136+
#define MIDR_CORTEX_X1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_X1)
137+
#define MIDR_CORTEX_A710 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A710)
138+
#define MIDR_CORTEX_X2 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_X2)
139+
#define MIDR_NEOVERSE_N2 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N2)
140+
#define MIDR_CORTEX_A78C MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A78C)
127141
#define MIDR_NEOVERSE_N1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N1)
128142
#define MIDR_CORTEX_A77 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A77)
129143
#define MIDR_NEOVERSE_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_V1)

arch/arm64/kernel/cpufeature.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static const struct arm64_ftr_bits ftr_id_aa64isar1[] = {
152152

153153
static const struct arm64_ftr_bits ftr_id_aa64isar2[] = {
154154
ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_HIGHER_SAFE, ID_AA64ISAR2_CLEARBHB_SHIFT, 4, 0),
155-
ARM64_FTR_END,
155+
ARM64_FTR_END,
156156
};
157157

158158
static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = {

arch/arm64/kernel/entry.S

+19-19
Original file line numberDiff line numberDiff line change
@@ -1084,11 +1084,11 @@ alternative_endif
10841084
.if \regsize == 64
10851085
mrs x29, far_el1
10861086
.endif
1087-
add sp, sp, #S_FRAME_SIZE // restore sp
1087+
add sp, sp, #S_FRAME_SIZE //restore sp
10881088
eret
10891089
.endm
10901090

1091-
.macro generate_tramp_vector, kpti, bhb
1091+
.macro generate_tramp_vector, kpti, bhb
10921092
.Lvector_start\@:
10931093
.space 0x400
10941094

@@ -1101,11 +1101,11 @@ alternative_endif
11011101
.endm
11021102

11031103
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1104-
/*
1105-
* Exception vectors trampoline.
1106-
* The order must match __bp_harden_el1_vectors and the
1107-
* arm64_bp_harden_el1_vectors enum.
1108-
*/
1104+
/*
1105+
* Exception vectors trampoline.
1106+
* The order must match __bp_harden_el1_vectors and the
1107+
* arm64_bp_harden_el1_vectors enum.
1108+
*/
11091109
.pushsection ".entry.tramp.text", "ax"
11101110
.align 11
11111111
ENTRY(tramp_vectors)
@@ -1138,7 +1138,7 @@ __entry_tramp_data_vectors:
11381138
__entry_tramp_data___sdei_asm_handler:
11391139
.quad __sdei_asm_handler
11401140
#endif /* CONFIG_ARM_SDE_INTERFACE */
1141-
__entry_tramp_data_this_cpu_vector:
1141+
__entry_tramp_data_this_cpu_vector:
11421142
.quad this_cpu_vector
11431143
.popsection // .rodata
11441144
#endif /* CONFIG_RANDOMIZE_BASE */
@@ -1148,26 +1148,26 @@ __entry_tramp_data_this_cpu_vector:
11481148
* Exception vectors for spectre mitigations on entry from EL1 when
11491149
* kpti is not in use.
11501150
*/
1151+
11511152
.macro generate_el1_vector, bhb
11521153
.Lvector_start\@:
1153-
kernel_ventry 1, sync_invalid // Synchronous EL1t
1154-
kernel_ventry 1, irq_invalid // IRQ EL1t
1155-
kernel_ventry 1, fiq_invalid // FIQ EL1t
1156-
kernel_ventry 1, error_invalid // Error EL1t
1154+
kernel_ventry 1, sync_invalid // Synchronous EL1t
1155+
kernel_ventry 1, irq_invalid // IRQ EL1t
1156+
kernel_ventry 1, fiq_invalid // FIQ EL1t
1157+
kernel_ventry 1, error_invalid // Error EL1t
11571158

1158-
kernel_ventry 1, sync // Synchronous EL1h
1159-
kernel_ventry 1, irq // IRQ EL1h
1160-
kernel_ventry 1, fiq_invalid // FIQ EL1h
1161-
kernel_ventry 1, error // Error EL1h
1159+
kernel_ventry 1, sync // Synchronous EL1h
1160+
kernel_ventry 1, irq // IRQ EL1h
1161+
kernel_ventry 1, fiq_invalid // FIQ EL1h
1162+
kernel_ventry 1, error // Error EL1h
11621163

11631164
.rept 4
11641165
tramp_ventry .Lvector_start\@, 64, 0, \bhb
11651166
.endr
1166-
.rept 4
1167+
.rept 4
11671168
tramp_ventry .Lvector_start\@, 32, 0, \bhb
11681169
.endr
11691170
.endm
1170-
11711171
/* The order must match tramp_vecs and the arm64_bp_harden_el1_vectors enum. */
11721172
.pushsection ".entry.text", "ax"
11731173
.align 11
@@ -1272,7 +1272,7 @@ ENTRY(__sdei_asm_entry_trampoline)
12721272
*/
12731273
1: str x4, [x1, #(SDEI_EVENT_INTREGS + S_ORIG_ADDR_LIMIT)]
12741274

1275-
tramp_data_read_var x4, __sdei_asm_handler
1275+
tramp_data_read_var x4, __sdei_asm_handler
12761276
br x4
12771277
ENDPROC(__sdei_asm_entry_trampoline)
12781278
NOKPROBE(__sdei_asm_entry_trampoline)

arch/arm64/kernel/topology.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
#include <asm/cputype.h>
3232
#include <asm/topology.h>
3333

34+
/*
35+
* This function returns the logic cpu number of the node.
36+
* There are basically three kinds of return values:
37+
* (1) logic cpu number which is > 0.
38+
* (2) -ENODEV when the device tree(DT) node is valid and found in the DT but
39+
* there is no possible logical CPU in the kernel to match. This happens
40+
* when CONFIG_NR_CPUS is configure to be smaller than the number of
41+
* CPU nodes in DT. We need to just ignore this case.
42+
* (3) -1 if the node does not exist in the device tree
43+
*/
3444
static int __init get_cpu_for_node(struct device_node *node)
3545
{
3646
struct device_node *cpu_node;
@@ -44,8 +54,8 @@ static int __init get_cpu_for_node(struct device_node *node)
4454
if (cpu >= 0)
4555
topology_parse_cpu_capacity(cpu_node, cpu);
4656
else
47-
pr_crit("Unable to find CPU node for %pOF\n", cpu_node);
48-
57+
pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n",
58+
cpu_node, cpumask_pr_args(cpu_possible_mask));
4959
of_node_put(cpu_node);
5060
return cpu;
5161
}
@@ -69,7 +79,7 @@ static int __init parse_core(struct device_node *core, int package_id,
6979
cpu_topology[cpu].package_id = package_id;
7080
cpu_topology[cpu].core_id = core_id;
7181
cpu_topology[cpu].thread_id = i;
72-
} else {
82+
} else if (cpu != -ENODEV) {
7383
pr_err("%pOF: Can't get CPU for thread\n",
7484
t);
7585
of_node_put(t);
@@ -90,7 +100,7 @@ static int __init parse_core(struct device_node *core, int package_id,
90100

91101
cpu_topology[cpu].package_id = package_id;
92102
cpu_topology[cpu].core_id = core_id;
93-
} else if (leaf) {
103+
} else if (leaf && cpu != -ENODEV) {
94104
pr_err("%pOF: Can't get CPU for leaf core\n", core);
95105
return -EINVAL;
96106
}

arch/arm64/kvm/hyp/hyp-entry.S

+1
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,5 @@ ENTRY(__spectre_bhb_clearbhb_start)
398398
clearbhb
399399
isb
400400
ENTRY(__spectre_bhb_clearbhb_end)
401+
401402
#endif

arch/arm64/mm/mmu.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,13 @@ static int __init map_entry_trampoline(void)
611611
/* Map only the text into the trampoline page table */
612612
memset(tramp_pg_dir, 0, PGD_SIZE);
613613
__create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS,
614-
entry_tramp_text_size(), prot, pgd_pgtable_alloc,
615-
0);
614+
entry_tramp_text_size(), prot, pgd_pgtable_alloc,
615+
0);
616616

617617
/* Map both the text and data into the kernel page table */
618618
for (i = 0; i < DIV_ROUND_UP(entry_tramp_text_size(), PAGE_SIZE); i++)
619619
__set_fixmap(FIX_ENTRY_TRAMP_TEXT1 - i,
620-
pa_start + i * PAGE_SIZE, prot);
620+
pa_start + i * PAGE_SIZE, prot);
621621

622622
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
623623
extern char __entry_tramp_data_start[];

drivers/android/binder.c

+12
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,18 @@ static int binder_inc_ref_for_node(struct binder_proc *proc,
19831983
}
19841984
ret = binder_inc_ref_olocked(ref, strong, target_list);
19851985
*rdata = ref->data;
1986+
if (ret && ref == new_ref) {
1987+
/*
1988+
* Cleanup the failed reference here as the target
1989+
* could now be dead and have already released its
1990+
* references by now. Calling on the new reference
1991+
* with strong=0 and a tmp_refs will not decrement
1992+
* the node. The new_ref gets kfree'd below.
1993+
*/
1994+
binder_cleanup_ref_olocked(new_ref);
1995+
ref = NULL;
1996+
}
1997+
19861998
binder_proc_unlock(proc);
19871999
if (new_ref && ref != new_ref)
19882000
/*

0 commit comments

Comments
 (0)