Re: [PATCH] perf vendor events power10: Add metric events json file for power10 platform
On 10/6/21 11:02 PM, Paul A. Clarke wrote: > Kajol, > > On Wed, Oct 06, 2021 at 01:01:19PM +0530, Kajol Jain wrote: >> Add pmu metric json file for power10 platform. > > Thanks for producing this! A few minor corrections, plus a number of > stylistic comments below... Hi Paul, I will make mentioned nit changes and send a v2. Thanks, Kajol Jain > >> Signed-off-by: Kajol Jain >> --- >> .../arch/powerpc/power10/metrics.json | 772 ++ >> 1 file changed, 772 insertions(+) >> create mode 100644 tools/perf/pmu-events/arch/powerpc/power10/metrics.json >> >> diff --git a/tools/perf/pmu-events/arch/powerpc/power10/metrics.json >> b/tools/perf/pmu-events/arch/powerpc/power10/metrics.json >> new file mode 100644 >> index ..028c9777a516 >> --- /dev/null >> +++ b/tools/perf/pmu-events/arch/powerpc/power10/metrics.json >> @@ -0,0 +1,772 @@ >> +[ >> +{ >> +"BriefDescription": "Percentage of cycles that are run cycles", >> +"MetricExpr": "PM_RUN_CYC / PM_CYC * 100", >> +"MetricGroup": "General", >> +"MetricName": "RUN_CYCLES_RATE", >> +"ScaleUnit": "1%" >> +}, >> +{ >> +"BriefDescription": "Average cycles per completed instruction", >> +"MetricExpr": "PM_CYC / PM_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "CYCLES_PER_INSTRUCTION" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled for any reason", >> +"MetricExpr": "PM_DISP_STALL_CYC / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled because there was a flush", >> +"MetricExpr": "PM_DISP_STALL_FLUSH / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_FLUSH_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled because the MMU was handling a translation miss", >> +"MetricExpr": "PM_DISP_STALL_TRANSLATION / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_TRANSLATION_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled waiting to resolve an instruction ERAT miss", >> +"MetricExpr": "PM_DISP_STALL_IERAT_ONLY_MISS / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_IERAT_ONLY_MISS_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled waiting to resolve an instruction TLB miss", >> +"MetricExpr": "PM_DISP_STALL_ITLB_MISS / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_ITLB_MISS_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled due to an icache miss", >> +"MetricExpr": "PM_DISP_STALL_IC_MISS / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_IC_MISS_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled while the instruction was fetched form the local L2", > > s/form/from/ > >> +"MetricExpr": "PM_DISP_STALL_IC_L2 / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_IC_L2_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled while the instruction was fetched form the local L3", > > s/form/from/ > >> +"MetricExpr": "PM_DISP_STALL_IC_L3 / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_IC_L3_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled while the instruction was fetched from any source beyond the >> local L3", >> +"MetricExpr": "PM_DISP_STALL_IC_L3MISS / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_IC_L3MISS_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled due to an icache miss after a branch mispredict", >> +"MetricExpr": "PM_DISP_STALL_BR_MPRED_ICMISS / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_BR_MPRED_ICMISS_CPI" >> +}, >> +{ >> +"BriefDescription": "Average cycles per instruction when dispatch >> was stalled while instruction was fetched from the local L2 after suffering >> a branch mispredict", >> +"MetricExpr": "PM_DISP_STALL_BR_MPRED_IC_L2 / PM_RUN_INST_CMPL", >> +"MetricGroup": "CPI", >> +"MetricName": "DISPATCHED_BR_MPRED_IC_L2_CPI" >> +}, >> +{ >> +
Re: [PATCH v6 19/22] powerpc/book3s64/hash/kuap: Enable kuap on hash
Le 25/11/2020 à 06:16, Aneesh Kumar K.V a écrit : Reviewed-by: Sandipan Das Signed-off-by: Aneesh Kumar K.V --- arch/powerpc/mm/book3s64/pkeys.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c index f747d66cc87d..84f8664ffc47 100644 --- a/arch/powerpc/mm/book3s64/pkeys.c +++ b/arch/powerpc/mm/book3s64/pkeys.c @@ -257,7 +257,12 @@ void __init setup_kuep(bool disabled) #ifdef CONFIG_PPC_KUAP void __init setup_kuap(bool disabled) { - if (disabled || !early_radix_enabled()) + if (disabled) + return; + /* +* On hash if PKEY feature is not enabled, disable KUAP too. +*/ + if (!early_radix_enabled() && !early_mmu_has_feature(MMU_FTR_PKEY)) pkey_early_init_devtree() bails out without setting MMU_FTR_PKEY with the following: /* * Only P7 and above supports SPRN_AMR update with MSR[PR] = 1 */ if (!early_cpu_has_feature(CPU_FTR_ARCH_206)) return; Why would it be impossible to do KUAP in that case ? KUAP doesn't require updating SPRN_AMR with MSR[PR] = 1 return; if (smp_processor_id() == boot_cpuid) {
Re: [PATCH 07/12] powerpc: Use of_get_cpu_hwid()
Rob Herring writes: > Replace open coded parsing of CPU nodes' 'reg' property with > of_get_cpu_hwid(). > > Cc: Michael Ellerman > Cc: Benjamin Herrenschmidt > Cc: Paul Mackerras > Cc: linuxppc-dev@lists.ozlabs.org > Signed-off-by: Rob Herring > --- > arch/powerpc/kernel/smp.c | 7 +-- > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c > index 9cc7d3dbf439..d96b0e361a73 100644 > --- a/arch/powerpc/kernel/smp.c > +++ b/arch/powerpc/kernel/smp.c > @@ -1313,18 +1313,13 @@ int __cpu_up(unsigned int cpu, struct task_struct > *tidle) > int cpu_to_core_id(int cpu) > { > struct device_node *np; > - const __be32 *reg; > int id = -1; > > np = of_get_cpu_node(cpu, NULL); > if (!np) > goto out; > > - reg = of_get_property(np, "reg", NULL); > - if (!reg) > - goto out; > - > - id = be32_to_cpup(reg); > + id = of_get_cpu_hwid(np, 0); > out: > of_node_put(np); > return id; This looks OK to me. All the systems I can find have a /cpus/#address-cells of 1, so the change to use of_n_addr_cells() in of_get_cpu_hwid() should be fine. I booted it on a bunch of systems with no issues. Acked-by: Michael Ellerman cheers
Re: [PATCH] powerpc/32s: Fix kuap_kernel_restore()
On Wed, 15 Sep 2021 16:12:24 +0200, Christophe Leroy wrote: > At interrupt exit, kuap_kernel_restore() calls kuap_unclok() with the > value contained in regs->kuap. However, when regs->kuap contains > 0x it means that KUAP was not unlocked so calling > kuap_unlock() is unrelevant and results in jeopardising the contents > of kernel space segment registers. > > So check that regs->kuap doesn't contain KUAP_NONE before calling > kuap_unlock(). In the meantime it also means that if KUAP has not > been correcly locked back at interrupt exit, it must be locked > before continuing. This is done by checking the content of > current->thread.kuap which was returned by kuap_get_and_assert_locked() > > [...] Applied to powerpc/fixes. [1/1] powerpc/32s: Fix kuap_kernel_restore() https://git.kernel.org/powerpc/c/d93f9e23744b7bf11a98b2ddb091d129482ae179 cheers
Re: [PATCH] powerpc/pseries/msi: Add an empty irq_write_msi_msg() handler
On Thu, 30 Sep 2021 12:25:35 +0200, Cédric Le Goater wrote: > The IPR drivers tests for MSI support at probe time with MSI vector 0 > and when done, frees the IRQ with free_irq(). This test was introduced > by 95fecd90397e ("ipr: add test for MSI interrupt support") as an > improvement of commit 5a9ef25b14d3 ("[SCSI] ipr: add MSI support") > because a boot failure was reported on a Bimini PowerPC system : > > https://x-lore.kernel.org/all/1242926159.3007.5.camel@localhost.localdomain/ > > [...] Applied to powerpc/fixes. [1/1] powerpc/pseries/msi: Add an empty irq_write_msi_msg() handler https://git.kernel.org/powerpc/c/5a4b0320783a19f877dd595813569b3c25f4ff81 cheers
Re: [PATCH] pseries/eeh: fix the kdump kernel crash during eeh_pseries_init
On Mon, 20 Sep 2021 22:03:26 +0530, Mahesh Salgaonkar wrote: > On pseries lpar when an empty slot is assigned to partition OR on single > lpar mode, kdump kernel crashes during issuing PHB reset. In the kdump > scenario, we traverse all PHBs and issue reset using the pe_config_addr of > first child device present under each PHB. However the code assumes that > none of the PHB slot can be empty and uses list_first_entry() to get first > child device under PHB. Since list_first_entry() expect list to be not > empty, it returns invalid pci_dn entry and ends up accessing NULL phb > pointer under pci_dn->phb causing kdump kernel crash. > > [...] Applied to powerpc/fixes. [1/1] pseries/eeh: fix the kdump kernel crash during eeh_pseries_init https://git.kernel.org/powerpc/c/eb8257a12192f43ffd41bd90932c39dade958042 cheers
Re: [PATCH v2 00/10] powerpc/bpf: Various fixes
On Wed, 6 Oct 2021 01:55:19 +0530, Naveen N. Rao wrote: > This is v2 of the series posted at: > http://lkml.kernel.org/r/cover.1633104510.git.naveen.n@linux.vnet.ibm.com > > Only patches from v1 that need to go into powerpc/fixes are included. > Other patches will be posted as a separate series for inclusion into > powerpc/next. > > [...] Applied to powerpc/fixes. [01/10] powerpc/lib: Add helper to check if offset is within conditional branch range https://git.kernel.org/powerpc/c/4549c3ea3160fa8b3f37dfe2f957657bb265eda9 [02/10] powerpc/bpf: Validate branch ranges https://git.kernel.org/powerpc/c/3832ba4e283d7052b783dab8311df7e3590fed93 [03/10] powerpc/bpf: Fix BPF_MOD when imm == 1 https://git.kernel.org/powerpc/c/8bbc9d822421d9ac8ff9ed26a3713c9afc69d6c8 [04/10] powerpc/bpf: Fix BPF_SUB when imm == 0x8000 https://git.kernel.org/powerpc/c/5855c4c1f415ca3ba1046e77c0b3d3dfc96c9025 [05/10] powerpc/security: Add a helper to query stf_barrier type https://git.kernel.org/powerpc/c/030905920f32e91a52794937f67434ac0b3ea41a [06/10] powerpc/bpf: Emit stf barrier instruction sequences for BPF_NOSPEC https://git.kernel.org/powerpc/c/b7540d62509453263604a155bf2d5f0ed450cba2 [07/10] powerpc/bpf ppc32: Fix ALU32 BPF_ARSH operation https://git.kernel.org/powerpc/c/c9b8da77f22d28348d1f89a6c4d3fec102e9b1c4 [08/10] powerpc/bpf ppc32: Fix JMP32_JSET_K https://git.kernel.org/powerpc/c/e8278d3207bb6609c7b064073f353e6f4978 [09/10] powerpc/bpf ppc32: Do not emit zero extend instruction for 64-bit BPF_END https://git.kernel.org/powerpc/c/48164fccdff6d5cc11308126c050bd25a329df25 [10/10] powerpc/bpf ppc32: Fix BPF_SUB when imm == 0x8000 https://git.kernel.org/powerpc/c/548b762763b885b81850db676258df47c55dd5f9 cheers
Re: [PATCH 0/5] powerpc: various interrupt handling fixes
On Tue, 5 Oct 2021 00:56:37 +1000, Nicholas Piggin wrote: > This fixes a number of bugs found mostly looking at a MCE handler issue, > which should be fixed in patch 5 of the series, previous attempt here > which Ganesh found to be wrong. > > https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20210922020247.209409-1-npig...@gmail.com/ > > I didn't increment to patch v2 because it's a different approach (so I > gave it a different title). > > [...] Applied to powerpc/fixes. [1/5] powerpc/64s: fix program check interrupt emergency stack path https://git.kernel.org/powerpc/c/3e607dc4df180b72a38e75030cb0f94d12808712 [2/5] powerpc/traps: do not enable irqs in _exception https://git.kernel.org/powerpc/c/d0afd44c05f8f4e4c91487c02d43c87a31552462 [3/5] powerpc/64: warn if local irqs are enabled in NMI or hardirq context https://git.kernel.org/powerpc/c/ff058a8ada5df0d84e5537cfaf89d06d71501580 [4/5] powerpc/64/interrupt: Reconcile soft-mask state in NMI and fix false BUG https://git.kernel.org/powerpc/c/768c47010392ece9766a56479b4e0cf04a536916 [5/5] powerpc/64s: Fix unrecoverable MCE calling async handler from NMI https://git.kernel.org/powerpc/c/f08fb25bc66986b0952724530a640d9970fa52c1 cheers
[PATCH v2 12/16] powerpc/kuap: Wire-up KUAP on 44x
This adds KUAP support to 44x. This is done by checking the content of SPRN_PID at the time it is read and written into SPRN_MMUCR. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/head_44x.S | 16 arch/powerpc/platforms/Kconfig.cputype | 1 + 2 files changed, 17 insertions(+) diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S index 02d2928d1e01..cf92a3434acd 100644 --- a/arch/powerpc/kernel/head_44x.S +++ b/arch/powerpc/kernel/head_44x.S @@ -334,6 +334,10 @@ interrupt_base: mfspr r12,SPRN_MMUCR mfspr r13,SPRN_PID/* Get PID */ rlwimi r12,r13,0,24,31 /* Set TID */ +#ifdef CONFIG_PPC_KUAP + cmpwi r13,0 + beq 2f /* KUAP Fault */ +#endif 4: mtspr SPRN_MMUCR,r12 @@ -444,6 +448,10 @@ interrupt_base: mfspr r12,SPRN_MMUCR mfspr r13,SPRN_PID/* Get PID */ rlwimi r12,r13,0,24,31 /* Set TID */ +#ifdef CONFIG_PPC_KUAP + cmpwi r13,0 + beq 2f /* KUAP Fault */ +#endif 4: mtspr SPRN_MMUCR,r12 @@ -575,6 +583,10 @@ finish_tlb_load_44x: 3: mfspr r11,SPRN_SPRG3 lwz r11,PGDIR(r11) mfspr r12,SPRN_PID/* Get PID */ +#ifdef CONFIG_PPC_KUAP + cmpwi r12,0 + beq 2f /* KUAP Fault */ +#endif 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ /* Mask of required permission bits. Note that while we @@ -672,6 +684,10 @@ finish_tlb_load_44x: 3: mfspr r11,SPRN_SPRG_THREAD lwz r11,PGDIR(r11) mfspr r12,SPRN_PID/* Get PID */ +#ifdef CONFIG_PPC_KUAP + cmpwi r12,0 + beq 2f /* KUAP Fault */ +#endif 4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ /* Make up the required permissions */ diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index a66ab0a991f9..30091551ab24 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -62,6 +62,7 @@ config 44x select HAVE_PCI select PHYS_64BIT select PPC_HAVE_KUEP + select PPC_HAVE_KUAP endchoice -- 2.31.1
[PATCH v2 15/16] powerpc/kuap: Wire-up KUAP on book3e/64
This adds KUAP support to book3e/64. This is done by reading the content of SPRN_MAS1 and checking the TID at the time user pgtable is loaded. Signed-off-by: Christophe Leroy --- arch/powerpc/mm/nohash/tlb_low_64e.S | 40 ++ arch/powerpc/platforms/Kconfig.cputype | 1 + 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/mm/nohash/tlb_low_64e.S b/arch/powerpc/mm/nohash/tlb_low_64e.S index bf24451f3e71..b43524ca2b95 100644 --- a/arch/powerpc/mm/nohash/tlb_low_64e.S +++ b/arch/powerpc/mm/nohash/tlb_low_64e.S @@ -128,6 +128,13 @@ END_BTB_FLUSH_SECTION bne tlb_miss_kernel_bolted +tlb_miss_user_bolted: +#ifdef CONFIG_PPC_KUAP + mfspr r10,SPRN_MAS1 + rlwinm. r10,r10,0,0x3fff + beq-tlb_miss_fault_bolted /* KUAP fault */ +#endif + tlb_miss_common_bolted: /* * This is the guts of the TLB miss handler for bolted-linear. @@ -246,7 +253,7 @@ itlb_miss_fault_bolted: cmpldi cr0,r15,0 /* Check for user region */ orisr11,r11,_PAGE_ACCESSED@h - beq tlb_miss_common_bolted + beq tlb_miss_user_bolted b itlb_miss_kernel_bolted #ifdef CONFIG_PPC_FSL_BOOK3E @@ -676,6 +683,11 @@ finish_normal_tlb_miss: /* Check if required permissions are met */ andc. r15,r11,r14 bne-normal_tlb_miss_access_fault +#ifdef CONFIG_PPC_KUAP + mfspr r11,SPRN_MAS1 + rlwinm. r10,r11,0,0x3fff + beq-normal_tlb_miss_access_fault /* KUAP fault */ +#endif /* Now we build the MAS: * @@ -689,15 +701,17 @@ finish_normal_tlb_miss: * * TODO: mix up code below for better scheduling */ - clrrdi r11,r16,12 /* Clear low crap in EA */ - rlwimi r11,r14,32-19,27,31 /* Insert WIMGE */ - mtspr SPRN_MAS2,r11 + clrrdi r10,r16,12 /* Clear low crap in EA */ + rlwimi r10,r14,32-19,27,31 /* Insert WIMGE */ + mtspr SPRN_MAS2,r10 /* Check page size, if not standard, update MAS1 */ - rldicl r11,r14,64-8,64-8 - cmpldi cr0,r11,BOOK3E_PAGESZ_4K + rldicl r10,r14,64-8,64-8 + cmpldi cr0,r10,BOOK3E_PAGESZ_4K beq-1f +#ifndef CONFIG_PPC_KUAP mfspr r11,SPRN_MAS1 +#endif rlwimi r11,r14,31,21,24 rlwinm r11,r11,0,21,19 mtspr SPRN_MAS1,r11 @@ -786,7 +800,16 @@ virt_page_table_tlb_miss: mfspr r10,SPRN_MAS1 rlwinm r10,r10,0,16,1 /* Clear TID */ mtspr SPRN_MAS1,r10 +#ifdef CONFIG_PPC_KUAP + b 2f +1: + mfspr r10,SPRN_MAS1 + rlwinm. r10,r10,0,0x3fff + beq-virt_page_table_tlb_miss_fault /* KUAP fault */ +2: +#else 1: +#endif BEGIN_MMU_FTR_SECTION /* Search if we already have a TLB entry for that virtual address, and * if we do, bail out. @@ -1027,6 +1050,11 @@ virt_page_table_tlb_miss_whacko_fault: * avoid too much complication, it will save/restore things for us */ htw_tlb_miss: +#ifdef CONFIG_PPC_KUAP + mfspr r10,SPRN_MAS1 + rlwinm. r10,r10,0,0x3fff + beq-htw_tlb_miss_fault /* KUAP fault */ +#endif /* Search if we already have a TLB entry for that virtual address, and * if we do, bail out. * diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index 4ac99614d865..d0e52ad45d73 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -118,6 +118,7 @@ config PPC_BOOK3E_64 select PPC_SMP_MUXED_IPI select PPC_DOORBELL select ZONE_DMA + select PPC_HAVE_KUAP endchoice -- 2.31.1
[PATCH v2 08/16] powerpc/config: Add CONFIG_BOOKE_OR_40x
We have many functionnalities common to 40x and BOOKE, it leads to many places with #if defined(CONFIG_BOOKE) || defined(CONFIG_40x). We are going to add a few more with KUAP for booke/40x, so create a new symbol which is defined when either BOOKE or 40x is defined. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/hw_irq.h | 8 arch/powerpc/include/asm/irq.h | 2 +- arch/powerpc/include/asm/ptrace.h | 2 +- arch/powerpc/include/asm/reg.h | 4 ++-- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/entry_32.S | 2 +- arch/powerpc/kernel/irq.c | 2 +- arch/powerpc/kernel/kgdb.c | 4 ++-- arch/powerpc/kernel/setup.h| 2 +- arch/powerpc/kernel/setup_32.c | 2 +- arch/powerpc/kernel/time.c | 2 +- arch/powerpc/platforms/Kconfig.cputype | 5 + 12 files changed, 21 insertions(+), 16 deletions(-) diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h index 21cc571ea9c2..276e9dd7348b 100644 --- a/arch/powerpc/include/asm/hw_irq.h +++ b/arch/powerpc/include/asm/hw_irq.h @@ -61,7 +61,7 @@ static inline void __hard_irq_enable(void) { - if (IS_ENABLED(CONFIG_BOOKE) || IS_ENABLED(CONFIG_40x)) + if (IS_ENABLED(CONFIG_BOOKE_OR_40x)) wrtee(MSR_EE); else if (IS_ENABLED(CONFIG_PPC_8xx)) wrtspr(SPRN_EIE); @@ -73,7 +73,7 @@ static inline void __hard_irq_enable(void) static inline void __hard_irq_disable(void) { - if (IS_ENABLED(CONFIG_BOOKE) || IS_ENABLED(CONFIG_40x)) + if (IS_ENABLED(CONFIG_BOOKE_OR_40x)) wrtee(0); else if (IS_ENABLED(CONFIG_PPC_8xx)) wrtspr(SPRN_EID); @@ -85,7 +85,7 @@ static inline void __hard_irq_disable(void) static inline void __hard_EE_RI_disable(void) { - if (IS_ENABLED(CONFIG_BOOKE) || IS_ENABLED(CONFIG_40x)) + if (IS_ENABLED(CONFIG_BOOKE_OR_40x)) wrtee(0); else if (IS_ENABLED(CONFIG_PPC_8xx)) wrtspr(SPRN_NRI); @@ -97,7 +97,7 @@ static inline void __hard_EE_RI_disable(void) static inline void __hard_RI_enable(void) { - if (IS_ENABLED(CONFIG_BOOKE) || IS_ENABLED(CONFIG_40x)) + if (IS_ENABLED(CONFIG_BOOKE_OR_40x)) return; if (IS_ENABLED(CONFIG_PPC_8xx)) diff --git a/arch/powerpc/include/asm/irq.h b/arch/powerpc/include/asm/irq.h index 2b3278534bc1..13f0409dd617 100644 --- a/arch/powerpc/include/asm/irq.h +++ b/arch/powerpc/include/asm/irq.h @@ -36,7 +36,7 @@ extern int distribute_irqs; struct pt_regs; -#if defined(CONFIG_BOOKE) || defined(CONFIG_40x) +#ifdef CONFIG_BOOKE_OR_40x /* * Per-cpu stacks for handling critical, debug and machine check * level interrupts. diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h index 6e560f035614..42f89e2d8f04 100644 --- a/arch/powerpc/include/asm/ptrace.h +++ b/arch/powerpc/include/asm/ptrace.h @@ -291,7 +291,7 @@ static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc) static inline bool cpu_has_msr_ri(void) { - return !IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x); + return !IS_ENABLED(CONFIG_BOOKE_OR_40x); } static inline bool regs_is_unrecoverable(struct pt_regs *regs) diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h index e9d27265253b..50478738c8f1 100644 --- a/arch/powerpc/include/asm/reg.h +++ b/arch/powerpc/include/asm/reg.h @@ -18,9 +18,9 @@ #include /* Pickup Book E specific registers. */ -#if defined(CONFIG_BOOKE) || defined(CONFIG_40x) +#ifdef CONFIG_BOOKE_OR_40x #include -#endif /* CONFIG_BOOKE || CONFIG_40x */ +#endif #ifdef CONFIG_FSL_EMB_PERFMON #include diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index e563d3222d69..cf4a94891bd0 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -56,7 +56,7 @@ #endif #ifdef CONFIG_PPC32 -#if defined(CONFIG_BOOKE) || defined(CONFIG_40x) +#ifdef CONFIG_BOOKE_OR_40x #include "head_booke.h" #endif #endif diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S index 9d31ba2af901..df01da3ca3fa 100644 --- a/arch/powerpc/kernel/entry_32.S +++ b/arch/powerpc/kernel/entry_32.S @@ -108,7 +108,7 @@ transfer_to_syscall: stw r11, 0(r1) mflrr12 stw r12, _LINK(r1) -#if defined(CONFIG_BOOKE) || defined(CONFIG_40x) +#ifdef CONFIG_BOOKE_OR_40x rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */ #endif lis r12,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */ diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c index c4f1d6b7d992..8207f97d51e8 100644 --- a/arch/powerpc/kernel/irq.c +++ b/arch/powerpc/kernel/irq.c @@ -811,7 +811,7 @@ void __init init_IRQ(void) ppc_md.init_IRQ(); } -#if defined(CONFIG_BOOKE) || defined(CONFIG_4
[PATCH v2 09/16] powerpc/kuap: Prepare for supporting KUAP on BOOK3E/64
Also call kuap_lock() and kuap_save_and_lock() from interrupt functions with CONFIG_PPC64. For book3s/64 we keep them empty as it is done in assembly. Also do the locked assert when switching task unless it is book3s/64. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/64/kup.h | 9 + arch/powerpc/include/asm/interrupt.h | 2 ++ arch/powerpc/include/asm/kup.h | 2 -- arch/powerpc/kernel/process.c| 6 +++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h index 503828709d55..69fcf63eec94 100644 --- a/arch/powerpc/include/asm/book3s/64/kup.h +++ b/arch/powerpc/include/asm/book3s/64/kup.h @@ -298,6 +298,15 @@ static inline unsigned long __kuap_get_and_assert_locked(void) return amr; } +/* Do nothing, book3s/64 does that in ASM */ +static inline void __kuap_lock(void) +{ +} + +static inline void __kuap_save_and_lock(struct pt_regs *regs) +{ +} + /* * We support individually allowing read or write, but we don't support nesting * because that would require an expensive read/modify write of the AMR. diff --git a/arch/powerpc/include/asm/interrupt.h b/arch/powerpc/include/asm/interrupt.h index ae719e200c80..cd78dbca49e5 100644 --- a/arch/powerpc/include/asm/interrupt.h +++ b/arch/powerpc/include/asm/interrupt.h @@ -154,12 +154,14 @@ static inline void interrupt_enter_prepare(struct pt_regs *regs, struct interrup local_paca->irq_happened |= PACA_IRQ_HARD_DIS; if (user_mode(regs)) { + kuap_lock(); CT_WARN_ON(ct_state() != CONTEXT_USER); user_exit_irqoff(); account_cpu_user_entry(); account_stolen_time(); } else { + kuap_save_and_lock(regs); /* * CT_WARN_ON comes here via program_check_exception, * so avoid recursion. diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h index 2e0c2df21b3b..0cafcf8319cd 100644 --- a/arch/powerpc/include/asm/kup.h +++ b/arch/powerpc/include/asm/kup.h @@ -94,7 +94,6 @@ static __always_inline void kuap_assert_locked(void) __kuap_get_and_assert_locked(); } -#ifdef CONFIG_PPC32 static __always_inline void kuap_lock(void) { if (kuap_is_disabled()) @@ -110,7 +109,6 @@ static __always_inline void kuap_save_and_lock(struct pt_regs *regs) __kuap_save_and_lock(regs); } -#endif static __always_inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long amr) { diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 50436b52c213..2c637740c0c2 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -1281,9 +1281,9 @@ struct task_struct *__switch_to(struct task_struct *prev, set_return_regs_changed(); /* _switch changes stack (and regs) */ -#ifdef CONFIG_PPC32 - kuap_assert_locked(); -#endif + if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64)) + kuap_assert_locked(); + last = _switch(old_thread, new_thread); /* -- 2.31.1
[PATCH v2 11/16] powerpc: Add KUAP support for BOOKE and 40x
On booke/40x we don't have segments like book3s/32. On booke/40x we don't have access protection groups like 8xx. Use the PID register to provide user access protection. Kernel address space can be accessed with any PID. User address space has to be accessed with the PID of the user. User PID is always not null. Everytime the kernel is entered, set PID register to 0 and restore PID register when returning to user. Everytime kernel needs to access user data, PID is restored for the access. In TLB miss handlers, check the PID and bail out to data storage exception when PID is 0 and accessed address is in user space. Note that also forbids execution of user text by kernel except when user access is unlocked. But this shouldn't be a problem as the kernel is not supposed to ever run user text. This patch prepares the infrastructure but the real activation of KUAP is done by following patches for each processor type one by one. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/kup.h | 4 + arch/powerpc/include/asm/nohash/kup-booke.h | 110 arch/powerpc/include/asm/processor.h| 3 + arch/powerpc/kernel/process.c | 3 + arch/powerpc/mm/mmu_context.c | 6 ++ arch/powerpc/mm/nohash/mmu_context.c| 6 +- 6 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/include/asm/nohash/kup-booke.h diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h index 0cafcf8319cd..953991d1f7ce 100644 --- a/arch/powerpc/include/asm/kup.h +++ b/arch/powerpc/include/asm/kup.h @@ -14,6 +14,10 @@ #include #endif +#ifdef CONFIG_BOOKE_OR_40x +#include +#endif + #ifdef CONFIG_PPC_BOOK3S_32 #include #endif diff --git a/arch/powerpc/include/asm/nohash/kup-booke.h b/arch/powerpc/include/asm/nohash/kup-booke.h new file mode 100644 index ..49bb41ed0816 --- /dev/null +++ b/arch/powerpc/include/asm/nohash/kup-booke.h @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_POWERPC_KUP_BOOKE_H_ +#define _ASM_POWERPC_KUP_BOOKE_H_ + +#include + +#ifdef CONFIG_PPC_KUAP + +#ifdef __ASSEMBLY__ + +.macro kuap_check_amr gpr1, gpr2 +.endm + +#else + +#include +#include + +#include + +extern struct static_key_false disable_kuap_key; + +static __always_inline bool kuap_is_disabled(void) +{ + return static_branch_unlikely(&disable_kuap_key); +} + +static inline void __kuap_lock(void) +{ + mtspr(SPRN_PID, 0); + isync(); +} + +static inline void __kuap_save_and_lock(struct pt_regs *regs) +{ + regs->kuap = mfspr(SPRN_PID); + mtspr(SPRN_PID, 0); + isync(); +} + +static inline void kuap_user_restore(struct pt_regs *regs) +{ + if (kuap_is_disabled()) + return; + + mtspr(SPRN_PID, current->thread.pid); + + /* Context synchronisation is performed by rfi */ +} + +static inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap) +{ + if (regs->kuap) + mtspr(SPRN_PID, current->thread.pid); + + /* Context synchronisation is performed by rfi */ +} + +static inline unsigned long __kuap_get_and_assert_locked(void) +{ + unsigned long kuap = mfspr(SPRN_PID); + + if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) + WARN_ON_ONCE(kuap); + + return kuap; +} + +static inline void __allow_user_access(void __user *to, const void __user *from, + unsigned long size, unsigned long dir) +{ + mtspr(SPRN_PID, current->thread.pid); + isync(); +} + +static inline void __prevent_user_access(unsigned long dir) +{ + mtspr(SPRN_PID, 0); + isync(); +} + +static inline unsigned long __prevent_user_access_return(void) +{ + unsigned long flags = mfspr(SPRN_PID); + + mtspr(SPRN_PID, 0); + isync(); + + return flags; +} + +static inline void __restore_user_access(unsigned long flags) +{ + if (flags) { + mtspr(SPRN_PID, current->thread.pid); + isync(); + } +} + +static inline bool +__bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) +{ + return !regs->kuap; +} + +#endif /* !__ASSEMBLY__ */ + +#endif /* CONFIG_PPC_KUAP */ + +#endif /* _ASM_POWERPC_KUP_BOOKE_H_ */ diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h index 4b13f94a4f42..2748ae867dbd 100644 --- a/arch/powerpc/include/asm/processor.h +++ b/arch/powerpc/include/asm/processor.h @@ -160,6 +160,9 @@ struct thread_struct { unsigned long sr0; #endif #endif /* CONFIG_PPC32 */ +#if defined(CONFIG_BOOKE_OR_40x) && defined(CONFIG_PPC_KUAP) + unsigned long pid;/* value written in PID reg. at interrupt exit */ +#endif /* Debug Registers */ struct debug_reg debug; #ifdef CONFIG_PPC_FPU_REGS diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 2c637740c0c2..b22d70681a21 1
[PATCH v2 16/16] powerpc: Remove CONFIG_PPC_HAVE_KUAP
All platforms now have KUAP so remove CONFIG_PPC_HAVE_KUAP Signed-off-by: Christophe Leroy --- arch/powerpc/mm/nohash/kup.c | 1 - arch/powerpc/platforms/Kconfig.cputype | 11 --- 2 files changed, 12 deletions(-) diff --git a/arch/powerpc/mm/nohash/kup.c b/arch/powerpc/mm/nohash/kup.c index bbacbd780806..eaea52231dd6 100644 --- a/arch/powerpc/mm/nohash/kup.c +++ b/arch/powerpc/mm/nohash/kup.c @@ -10,7 +10,6 @@ #include #include -#include #include #ifdef CONFIG_PPC_KUAP diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index d0e52ad45d73..d0ae0d6a1384 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -31,20 +31,17 @@ config PPC_BOOK3S_32 imply PPC_FPU select PPC_HAVE_PMU_SUPPORT select PPC_HAVE_KUEP - select PPC_HAVE_KUAP select HAVE_ARCH_VMAP_STACK config PPC_85xx bool "Freescale 85xx" select E500 - select PPC_HAVE_KUAP config PPC_8xx bool "Freescale 8xx" select ARCH_SUPPORTS_HUGETLBFS select FSL_SOC select PPC_HAVE_KUEP - select PPC_HAVE_KUAP select HAVE_ARCH_VMAP_STACK select HUGETLBFS @@ -54,7 +51,6 @@ config 40x select PPC_UDBG_16550 select 4xx_SOC select HAVE_PCI - select PPC_HAVE_KUAP config 44x bool "AMCC 44x, 46x or 47x" @@ -64,7 +60,6 @@ config 44x select HAVE_PCI select PHYS_64BIT select PPC_HAVE_KUEP - select PPC_HAVE_KUAP endchoice @@ -110,7 +105,6 @@ config PPC_BOOK3S_64 select IRQ_WORK select PPC_MM_SLICES select PPC_HAVE_KUEP - select PPC_HAVE_KUAP config PPC_BOOK3E_64 bool "Embedded processors" @@ -118,7 +112,6 @@ config PPC_BOOK3E_64 select PPC_SMP_MUXED_IPI select PPC_DOORBELL select ZONE_DMA - select PPC_HAVE_KUAP endchoice @@ -408,12 +401,8 @@ config PPC_KUEP If you're unsure, say Y. -config PPC_HAVE_KUAP - bool - config PPC_KUAP bool "Kernel Userspace Access Protection" - depends on PPC_HAVE_KUAP default y help Enable support for Kernel Userspace Access Protection (KUAP) -- 2.31.1
[PATCH v2 13/16] powerpc/kuap: Wire-up KUAP on 40x
This adds KUAP support to 40x. This is done by checking the content of SPRN_PID at the time user pgtable is loaded. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/head_40x.S | 8 arch/powerpc/platforms/Kconfig.cputype | 1 + 2 files changed, 9 insertions(+) diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S index 7d72ee5ab387..87d322dbed94 100644 --- a/arch/powerpc/kernel/head_40x.S +++ b/arch/powerpc/kernel/head_40x.S @@ -297,6 +297,10 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt) 3: mfspr r11,SPRN_SPRG_THREAD lwz r11,PGDIR(r11) +#ifdef CONFIG_PPC_KUAP + rlwinm. r9, r9, 0, 0xff + beq 5f /* Kuap fault */ +#endif 4: tophys(r11, r11) rlwimi r11, r10, 12, 20, 29/* Create L1 (pgdir/pmd) address */ @@ -377,6 +381,10 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt) 3: mfspr r11,SPRN_SPRG_THREAD lwz r11,PGDIR(r11) +#ifdef CONFIG_PPC_KUAP + rlwinm. r9, r9, 0, 0xff + beq 5f /* Kuap fault */ +#endif 4: tophys(r11, r11) rlwimi r11, r10, 12, 20, 29/* Create L1 (pgdir/pmd) address */ diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index 30091551ab24..d703fd8e2feb 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -53,6 +53,7 @@ config 40x select PPC_UDBG_16550 select 4xx_SOC select HAVE_PCI + select PPC_HAVE_KUAP config 44x bool "AMCC 44x, 46x or 47x" -- 2.31.1
[PATCH v2 06/16] powerpc/kuap: Add kuap_lock()
Add kuap_lock() and call it when entering interrupts from user. It is called kuap_lock() as it is similar to kuap_save_and_lock() without the save. However book3s/32 already have a kuap_lock(). Rename it kuap_lock_addr(). Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/32/kup.h | 12 arch/powerpc/include/asm/interrupt.h | 5 - arch/powerpc/include/asm/kup.h | 9 + arch/powerpc/include/asm/nohash/32/kup-8xx.h | 4 arch/powerpc/kernel/interrupt.c | 2 ++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/include/asm/book3s/32/kup.h index e273a6d3b6ad..b61a48550e59 100644 --- a/arch/powerpc/include/asm/book3s/32/kup.h +++ b/arch/powerpc/include/asm/book3s/32/kup.h @@ -60,7 +60,7 @@ static inline void kuap_unlock_all(void) void kuap_lock_all_ool(void); void kuap_unlock_all_ool(void); -static inline void kuap_lock(unsigned long addr, bool ool) +static inline void kuap_lock_addr(unsigned long addr, bool ool) { if (likely(addr != KUAP_ALL)) kuap_lock_one(addr); @@ -80,6 +80,10 @@ static inline void kuap_unlock(unsigned long addr, bool ool) kuap_unlock_all_ool(); } +static inline void __kuap_lock(void) +{ +} + static inline void __kuap_save_and_lock(struct pt_regs *regs) { unsigned long kuap = current->thread.kuap; @@ -89,7 +93,7 @@ static inline void __kuap_save_and_lock(struct pt_regs *regs) return; current->thread.kuap = KUAP_NONE; - kuap_lock(kuap, false); + kuap_lock_addr(kuap, false); } static inline void kuap_user_restore(struct pt_regs *regs) @@ -142,7 +146,7 @@ static __always_inline void __prevent_user_access(unsigned long dir) return; current->thread.kuap = KUAP_NONE; - kuap_lock(kuap, true); + kuap_lock_addr(kuap, true); } static inline unsigned long __prevent_user_access_return(void) @@ -151,7 +155,7 @@ static inline unsigned long __prevent_user_access_return(void) if (flags != KUAP_NONE) { current->thread.kuap = KUAP_NONE; - kuap_lock(flags, true); + kuap_lock_addr(flags, true); } return flags; diff --git a/arch/powerpc/include/asm/interrupt.h b/arch/powerpc/include/asm/interrupt.h index 3bbca1fbbe1e..ae719e200c80 100644 --- a/arch/powerpc/include/asm/interrupt.h +++ b/arch/powerpc/include/asm/interrupt.h @@ -140,9 +140,12 @@ static inline void interrupt_enter_prepare(struct pt_regs *regs, struct interrup trace_hardirqs_off(); if (user_mode(regs)) - account_cpu_user_entry(); + kuap_lock(); else kuap_save_and_lock(regs); + + if (user_mode(regs)) + account_cpu_user_entry(); #endif #ifdef CONFIG_PPC64 diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h index 7f0d614c5b8b..2e0c2df21b3b 100644 --- a/arch/powerpc/include/asm/kup.h +++ b/arch/powerpc/include/asm/kup.h @@ -52,6 +52,7 @@ __bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) } static inline void __kuap_assert_locked(void) { } +static inline void __kuap_lock(void) { } static inline void __kuap_save_and_lock(struct pt_regs *regs) { } static inline void kuap_user_restore(struct pt_regs *regs) { } static inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long amr) { } @@ -94,6 +95,14 @@ static __always_inline void kuap_assert_locked(void) } #ifdef CONFIG_PPC32 +static __always_inline void kuap_lock(void) +{ + if (kuap_is_disabled()) + return; + + __kuap_lock(); +} + static __always_inline void kuap_save_and_lock(struct pt_regs *regs) { if (kuap_is_disabled()) diff --git a/arch/powerpc/include/asm/nohash/32/kup-8xx.h b/arch/powerpc/include/asm/nohash/32/kup-8xx.h index 37fe4b32b658..c44d97751723 100644 --- a/arch/powerpc/include/asm/nohash/32/kup-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/kup-8xx.h @@ -20,6 +20,10 @@ static __always_inline bool kuap_is_disabled(void) return static_branch_unlikely(&disable_kuap_key); } +static inline void __kuap_lock(void) +{ +} + static inline void __kuap_save_and_lock(struct pt_regs *regs) { regs->kuap = mfspr(SPRN_MD_AP); diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c index 0d12aa66e1f9..dc56a514df0a 100644 --- a/arch/powerpc/kernel/interrupt.c +++ b/arch/powerpc/kernel/interrupt.c @@ -81,6 +81,8 @@ notrace long system_call_exception(long r3, long r4, long r5, { syscall_fn f; + kuap_lock(); + regs->orig_gpr3 = r3; if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) -- 2.31.1
[PATCH v2 07/16] powerpc/nohash: Move setup_kuap out of 8xx.c
In order to reuse it on booke/4xx, move KUAP setup routine out of 8xx.c Make them usable on SMP by removing the __init tag as it is called for each CPU. And use __prevent_user_access() instead of hard coding initial lock. Signed-off-by: Christophe Leroy --- arch/powerpc/mm/nohash/8xx.c| 21 - arch/powerpc/mm/nohash/Makefile | 2 +- arch/powerpc/mm/nohash/kup.c| 32 3 files changed, 33 insertions(+), 22 deletions(-) create mode 100644 arch/powerpc/mm/nohash/kup.c diff --git a/arch/powerpc/mm/nohash/8xx.c b/arch/powerpc/mm/nohash/8xx.c index 0df9fe29dd56..e12e41eb91c6 100644 --- a/arch/powerpc/mm/nohash/8xx.c +++ b/arch/powerpc/mm/nohash/8xx.c @@ -8,11 +8,7 @@ */ #include -#include #include -#include -#include -#include #include @@ -224,23 +220,6 @@ void __init setup_kuep(bool disabled) } #endif -#ifdef CONFIG_PPC_KUAP -struct static_key_false disable_kuap_key; -EXPORT_SYMBOL(disable_kuap_key); - -void __init setup_kuap(bool disabled) -{ - if (disabled) { - static_branch_enable(&disable_kuap_key); - return; - } - - pr_info("Activating Kernel Userspace Access Protection\n"); - - mtspr(SPRN_MD_AP, MD_APG_KUAP); -} -#endif - int pud_clear_huge(pud_t *pud) { return 0; diff --git a/arch/powerpc/mm/nohash/Makefile b/arch/powerpc/mm/nohash/Makefile index 0424f6ce5bd8..2ffca5f8a169 100644 --- a/arch/powerpc/mm/nohash/Makefile +++ b/arch/powerpc/mm/nohash/Makefile @@ -2,7 +2,7 @@ ccflags-$(CONFIG_PPC64):= $(NO_MINIMAL_TOC) -obj-y += mmu_context.o tlb.o tlb_low.o +obj-y += mmu_context.o tlb.o tlb_low.o kup.o obj-$(CONFIG_PPC_BOOK3E_64)+= tlb_low_64e.o book3e_pgtable.o obj-$(CONFIG_40x) += 40x.o obj-$(CONFIG_44x) += 44x.o diff --git a/arch/powerpc/mm/nohash/kup.c b/arch/powerpc/mm/nohash/kup.c new file mode 100644 index ..bbacbd780806 --- /dev/null +++ b/arch/powerpc/mm/nohash/kup.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * This file contains the routines for initializing kernel userspace protection + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifdef CONFIG_PPC_KUAP +struct static_key_false disable_kuap_key; +EXPORT_SYMBOL(disable_kuap_key); + +void setup_kuap(bool disabled) +{ + if (disabled) { + if (smp_processor_id() == boot_cpuid) + static_branch_enable(&disable_kuap_key); + return; + } + + pr_info("Activating Kernel Userspace Access Protection\n"); + + __prevent_user_access(KUAP_READ_WRITE); +} +#endif -- 2.31.1
[PATCH v2 04/16] powerpc/kuap: Check KUAP activation in generic functions
Today, every platform checks that KUAP is not de-activated before doing the real job. Move the verification out of platform specific functions. Signed-off-by: Christophe Leroy --- v2: Added missing check in bad_kuap_fault() --- arch/powerpc/include/asm/book3s/32/kup.h | 34 +++- arch/powerpc/include/asm/book3s/64/kup.h | 41 ++-- arch/powerpc/include/asm/kup.h | 29 ++ arch/powerpc/include/asm/nohash/32/kup-8xx.h | 28 + 4 files changed, 56 insertions(+), 76 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/include/asm/book3s/32/kup.h index 8f04602d..f1617ba85068 100644 --- a/arch/powerpc/include/asm/book3s/32/kup.h +++ b/arch/powerpc/include/asm/book3s/32/kup.h @@ -16,11 +16,6 @@ extern struct static_key_false disable_kuep_key; extern s32 patch__kuep_lock, patch__kuep_unlock; -static __always_inline bool kuap_is_disabled(void) -{ - return !IS_ENABLED(CONFIG_PPC_KUAP) || static_branch_unlikely(&disable_kuap_key); -} - static __always_inline bool kuep_is_disabled(void) { return !IS_ENABLED(CONFIG_PPC_KUEP) || static_branch_unlikely(&disable_kuep_key); @@ -33,6 +28,11 @@ static __always_inline bool kuep_is_disabled(void) #define KUAP_NONE (~0UL) #define KUAP_ALL (~1UL) +static __always_inline bool kuap_is_disabled(void) +{ + return static_branch_unlikely(&disable_kuap_key); +} + static inline void kuap_lock_one(unsigned long addr) { mtsr(mfsr(addr) | SR_KS, addr); @@ -84,9 +84,6 @@ static inline void __kuap_save_and_lock(struct pt_regs *regs) { unsigned long kuap = current->thread.kuap; - if (kuap_is_disabled()) - return; - regs->kuap = kuap; if (unlikely(kuap == KUAP_NONE)) return; @@ -101,9 +98,6 @@ static inline void kuap_user_restore(struct pt_regs *regs) static inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap) { - if (kuap_is_disabled()) - return; - if (unlikely(kuap != KUAP_NONE)) { current->thread.kuap = KUAP_NONE; kuap_lock(kuap, false); @@ -121,9 +115,6 @@ static inline unsigned long __kuap_get_and_assert_locked(void) { unsigned long kuap = current->thread.kuap; - if (kuap_is_disabled()) - return KUAP_NONE; - WARN_ON_ONCE(IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && kuap != KUAP_NONE); return kuap; @@ -137,9 +128,6 @@ static inline void __kuap_assert_locked(void) static __always_inline void __allow_user_access(void __user *to, const void __user *from, u32 size, unsigned long dir) { - if (kuap_is_disabled()) - return; - BUILD_BUG_ON(!__builtin_constant_p(dir)); if (!(dir & KUAP_WRITE)) @@ -153,9 +141,6 @@ static __always_inline void __prevent_user_access(unsigned long dir) { u32 kuap = current->thread.kuap; - if (kuap_is_disabled()) - return; - BUILD_BUG_ON(!__builtin_constant_p(dir)); if (!(dir & KUAP_WRITE)) @@ -169,9 +154,6 @@ static inline unsigned long __prevent_user_access_return(void) { unsigned long flags = current->thread.kuap; - if (kuap_is_disabled()) - return KUAP_NONE; - if (flags != KUAP_NONE) { current->thread.kuap = KUAP_NONE; kuap_lock(flags, true); @@ -182,9 +164,6 @@ static inline unsigned long __prevent_user_access_return(void) static inline void __restore_user_access(unsigned long flags) { - if (kuap_is_disabled()) - return; - if (flags != KUAP_NONE) { current->thread.kuap = flags; kuap_unlock(flags, true); @@ -196,9 +175,6 @@ __bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) { unsigned long kuap = regs->kuap; - if (kuap_is_disabled()) - return false; - if (!is_write || kuap == KUAP_ALL) return false; if (kuap == KUAP_NONE) diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h index 03d61c5205a4..9f2099790658 100644 --- a/arch/powerpc/include/asm/book3s/64/kup.h +++ b/arch/powerpc/include/asm/book3s/64/kup.h @@ -229,6 +229,11 @@ static inline u64 current_thread_iamr(void) #ifdef CONFIG_PPC_KUAP +static __always_inline bool kuap_is_disabled(void) +{ + return !mmu_has_feature(MMU_FTR_BOOK3S_KUAP); +} + static inline void kuap_user_restore(struct pt_regs *regs) { bool restore_amr = false, restore_iamr = false; @@ -270,36 +275,32 @@ static inline void kuap_user_restore(struct pt_regs *regs) static inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long amr) { - if (mmu_has_feature(MMU_FTR_BOOK3S_KUAP)) { - if (unlikely(regs->amr != amr)) { -
[PATCH v2 10/16] powerpc/kuap: Make PPC_KUAP_DEBUG depend on PPC_KUAP only
PPC_KUAP_DEBUG is supported by all platforms doing PPC_KUAP, it doesn't depend on Radix on book3s/64. This will avoid adding one more dependency when implementing KUAP on book3e/64. Signed-off-by: Christophe Leroy --- v2: New --- arch/powerpc/platforms/Kconfig.cputype | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index dce1cf31047b..a66ab0a991f9 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -418,7 +418,7 @@ config PPC_KUAP config PPC_KUAP_DEBUG bool "Extra debugging for Kernel Userspace Access Protection" - depends on PPC_KUAP && (PPC_RADIX_MMU || PPC32) + depends on PPC_KUAP help Add extra debugging for Kernel Userspace Access Protection (KUAP) If you're unsure, say N. -- 2.31.1
[PATCH v2 14/16] powerpc/kuap: Wire-up KUAP on 85xx in 32 bits mode.
This adds KUAP support to 85xx in 32 bits mode. This is done by reading the content of SPRN_MAS1 and checking the TID at the time user pgtable is loaded. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/head_fsl_booke.S | 12 arch/powerpc/platforms/Kconfig.cputype | 1 + 2 files changed, 13 insertions(+) diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S index 0a9a0f301474..44f7271194e5 100644 --- a/arch/powerpc/kernel/head_fsl_booke.S +++ b/arch/powerpc/kernel/head_fsl_booke.S @@ -462,6 +462,12 @@ END_BTB_FLUSH_SECTION mfspr r11,SPRN_SPRG_THREAD lwz r11,PGDIR(r11) +#ifdef CONFIG_PPC_KUAP + mfspr r12, SPRN_MAS1 + rlwinm. r12,r12,0,0x3fff + beq 2f /* KUAP fault */ +#endif + 4: /* Mask of required permission bits. Note that while we * do copy ESR:ST to _PAGE_RW position as trying to write @@ -571,6 +577,12 @@ END_BTB_FLUSH_SECTION mfspr r11,SPRN_SPRG_THREAD lwz r11,PGDIR(r11) +#ifdef CONFIG_PPC_KUAP + mfspr r12, SPRN_MAS1 + rlwinm. r12,r12,0,0x3fff + beq 2f /* KUAP fault */ +#endif + /* Make up the required permissions for user code */ #ifdef CONFIG_PTE_64BIT li r13,_PAGE_PRESENT | _PAGE_BAP_UX diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype index d703fd8e2feb..4ac99614d865 100644 --- a/arch/powerpc/platforms/Kconfig.cputype +++ b/arch/powerpc/platforms/Kconfig.cputype @@ -37,6 +37,7 @@ config PPC_BOOK3S_32 config PPC_85xx bool "Freescale 85xx" select E500 + select PPC_HAVE_KUAP config PPC_8xx bool "Freescale 8xx" -- 2.31.1
[PATCH v2 05/16] powerpc/kuap: Remove __kuap_assert_locked()
__kuap_assert_locked() is redundant with __kuap_get_and_assert_locked(). Move the verification of CONFIG_PPC_KUAP_DEBUG in kuap_assert_locked() and make it call __kuap_get_and_assert_locked() directly. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/32/kup.h | 5 - arch/powerpc/include/asm/book3s/64/kup.h | 6 -- arch/powerpc/include/asm/kup.h | 3 ++- arch/powerpc/include/asm/nohash/32/kup-8xx.h | 6 -- 4 files changed, 2 insertions(+), 18 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/include/asm/book3s/32/kup.h index f1617ba85068..e273a6d3b6ad 100644 --- a/arch/powerpc/include/asm/book3s/32/kup.h +++ b/arch/powerpc/include/asm/book3s/32/kup.h @@ -120,11 +120,6 @@ static inline unsigned long __kuap_get_and_assert_locked(void) return kuap; } -static inline void __kuap_assert_locked(void) -{ - __kuap_get_and_assert_locked(); -} - static __always_inline void __allow_user_access(void __user *to, const void __user *from, u32 size, unsigned long dir) { diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h index 9f2099790658..503828709d55 100644 --- a/arch/powerpc/include/asm/book3s/64/kup.h +++ b/arch/powerpc/include/asm/book3s/64/kup.h @@ -298,12 +298,6 @@ static inline unsigned long __kuap_get_and_assert_locked(void) return amr; } -static inline void __kuap_assert_locked(void) -{ - if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) - WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED); -} - /* * We support individually allowing read or write, but we don't support nesting * because that would require an expensive read/modify write of the AMR. diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h index ea70e6f1df1e..7f0d614c5b8b 100644 --- a/arch/powerpc/include/asm/kup.h +++ b/arch/powerpc/include/asm/kup.h @@ -89,7 +89,8 @@ static __always_inline void kuap_assert_locked(void) if (kuap_is_disabled()) return; - __kuap_assert_locked(); + if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) + __kuap_get_and_assert_locked(); } #ifdef CONFIG_PPC32 diff --git a/arch/powerpc/include/asm/nohash/32/kup-8xx.h b/arch/powerpc/include/asm/nohash/32/kup-8xx.h index 74f15c386476..37fe4b32b658 100644 --- a/arch/powerpc/include/asm/nohash/32/kup-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/kup-8xx.h @@ -47,12 +47,6 @@ static inline unsigned long __kuap_get_and_assert_locked(void) return kuap; } -static inline void __kuap_assert_locked(void) -{ - if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG)) - __kuap_get_and_assert_locked(); -} - static inline void __allow_user_access(void __user *to, const void __user *from, unsigned long size, unsigned long dir) { -- 2.31.1
[PATCH v2 01/16] powerpc/32s: Do kuep_lock() and kuep_unlock() in assembly
When interrupt and syscall entries where converted to C, KUEP locking and unlocking was also converted. It improved performance by unrolling the loop, and allowed easily implementing boot time deactivation of KUEP. However, null_syscall selftest shows that KUEP is still heavy (361 cycles with KUEP, 212 cycles without). A way to improve more is to group 'mtsr's together, instead of repeating 'addi' + 'mtsr' several times. In order to do that, more registers need to be available. In C, GCC will always be able to provide the requested number of registers, but at the cost of saving some data on the stack, which is counter performant here. So let's do it in assembly, when we have full control of which register can be used. It also has the advantage of locking earlier and unlocking later and it helps GCC generating less tricky code. The only drawback is to make boot time deactivation less straight forward and require 'hand' instruction patching. Group 'mtsr's by 4. With this change, null_syscall selftest reports 336 cycles. Without the change it was 361 cycles, that's a 7% reduction. For the time being, capability to deactivate at boot time is disabled. It will be re-enabled in following patch. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/32/kup.h | 34 arch/powerpc/include/asm/book3s/32/mmu-hash.h | 77 ++- arch/powerpc/include/asm/interrupt.h | 6 +- arch/powerpc/include/asm/kup.h| 5 -- arch/powerpc/kernel/entry_32.S| 31 arch/powerpc/kernel/head_32.h | 6 ++ arch/powerpc/kernel/interrupt.c | 3 - arch/powerpc/mm/book3s32/kuep.c | 7 +- 8 files changed, 121 insertions(+), 48 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/include/asm/book3s/32/kup.h index 9f38040f0641..ff3d0bd39a06 100644 --- a/arch/powerpc/include/asm/book3s/32/kup.h +++ b/arch/powerpc/include/asm/book3s/32/kup.h @@ -24,40 +24,6 @@ static __always_inline bool kuep_is_disabled(void) return !IS_ENABLED(CONFIG_PPC_KUEP) || static_branch_unlikely(&disable_kuep_key); } -static inline void kuep_lock(void) -{ - if (kuep_is_disabled()) - return; - - update_user_segments(mfsr(0) | SR_NX); - /* -* This isync() shouldn't be necessary as the kernel is not excepted to -* run any instruction in userspace soon after the update of segments, -* but hash based cores (at least G3) seem to exhibit a random -* behaviour when the 'isync' is not there. 603 cores don't have this -* behaviour so don't do the 'isync' as it saves several CPU cycles. -*/ - if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) - isync();/* Context sync required after mtsr() */ -} - -static inline void kuep_unlock(void) -{ - if (kuep_is_disabled()) - return; - - update_user_segments(mfsr(0) & ~SR_NX); - /* -* This isync() shouldn't be necessary as a 'rfi' will soon be executed -* to return to userspace, but hash based cores (at least G3) seem to -* exhibit a random behaviour when the 'isync' is not there. 603 cores -* don't have this behaviour so don't do the 'isync' as it saves several -* CPU cycles. -*/ - if (mmu_has_feature(MMU_FTR_HPTE_TABLE)) - isync();/* Context sync required after mtsr() */ -} - #ifdef CONFIG_PPC_KUAP #include diff --git a/arch/powerpc/include/asm/book3s/32/mmu-hash.h b/arch/powerpc/include/asm/book3s/32/mmu-hash.h index f5be185cbdf8..e2f7ccc13edb 100644 --- a/arch/powerpc/include/asm/book3s/32/mmu-hash.h +++ b/arch/powerpc/include/asm/book3s/32/mmu-hash.h @@ -64,7 +64,82 @@ struct ppc_bat { #define SR_KP 0x2000 /* User key */ #define SR_KS 0x4000 /* Supervisor key */ -#ifndef __ASSEMBLY__ +#ifdef __ASSEMBLY__ + +#include + +.macro uus_addi sr reg1 reg2 imm + .if NUM_USER_SEGMENTS > \sr + addi\reg1,\reg2,\imm + .endif +.endm + +.macro uus_mtsr sr reg1 + .if NUM_USER_SEGMENTS > \sr + mtsr\sr, \reg1 + .endif +.endm + +/* + * This isync() shouldn't be necessary as the kernel is not excepted to run + * any instruction in userspace soon after the update of segments and 'rfi' + * instruction is used to return to userspace, but hash based cores + * (at least G3) seem to exhibit a random behaviour when the 'isync' is not + * there. 603 cores don't have this behaviour so don't do the 'isync' as it + * saves several CPU cycles. + */ +.macro uus_isync +#ifdef CONFIG_PPC_BOOK3S_604 +BEGIN_MMU_FTR_SECTION + isync +END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE) +#endif +.endm + +.macro update_user_segments_by_4 tmp1 tmp2 tmp3 tmp4 + uus_addi1, \tmp2, \tmp1, 0x111 + uus_addi2, \tmp3, \tmp1, 0x222 + uus_addi3, \tmp4, \tmp1, 0x333 + + uus_mtsr
[PATCH v2 02/16] powerpc/32s: Save content of sr0 to avoid 'mfsr'
Calling 'mfsr' to get the content of segment registers is heavy, in addition it requires clearing of the 'reserved' bits. In order to avoid this operation, save it in mm context and in thread struct. The saved sr0 is the one used by kernel, this means that on locking entry it can be used as is. For unlocking, the only thing to do is to clear SR_NX. This improves null_syscall selftest by 12 cycles, ie 4%. Capability to deactivate KUEP at boot time is re-enabled by this patch. Signed-off-by: Christophe Leroy --- v3: Simplified patching implied by simplified preceding patch --- arch/powerpc/include/asm/book3s/32/kup.h | 2 ++ arch/powerpc/include/asm/book3s/32/mmu-hash.h | 1 + arch/powerpc/include/asm/processor.h | 1 + arch/powerpc/kernel/entry_32.S| 11 + arch/powerpc/mm/book3s32/kuap.c | 5 +++- arch/powerpc/mm/book3s32/kuep.c | 24 --- arch/powerpc/mm/book3s32/mmu_context.c| 15 ++-- arch/powerpc/mm/mmu_context.c | 3 +++ 8 files changed, 40 insertions(+), 22 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/include/asm/book3s/32/kup.h index ff3d0bd39a06..0923dfcb04f7 100644 --- a/arch/powerpc/include/asm/book3s/32/kup.h +++ b/arch/powerpc/include/asm/book3s/32/kup.h @@ -14,6 +14,8 @@ extern struct static_key_false disable_kuap_key; extern struct static_key_false disable_kuep_key; +extern s32 patch__kuep_lock, patch__kuep_unlock; + static __always_inline bool kuap_is_disabled(void) { return !IS_ENABLED(CONFIG_PPC_KUAP) || static_branch_unlikely(&disable_kuap_key); diff --git a/arch/powerpc/include/asm/book3s/32/mmu-hash.h b/arch/powerpc/include/asm/book3s/32/mmu-hash.h index e2f7ccc13edb..ecc148c1e795 100644 --- a/arch/powerpc/include/asm/book3s/32/mmu-hash.h +++ b/arch/powerpc/include/asm/book3s/32/mmu-hash.h @@ -175,6 +175,7 @@ struct hash_pte { typedef struct { unsigned long id; + unsigned long sr0; void __user *vdso; } mm_context_t; diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h index f348e564f7dd..4b13f94a4f42 100644 --- a/arch/powerpc/include/asm/processor.h +++ b/arch/powerpc/include/asm/processor.h @@ -157,6 +157,7 @@ struct thread_struct { #ifdef CONFIG_PPC_BOOK3S_32 unsigned long r0, r3, r4, r5, r6, r8, r9, r11; unsigned long lr, ctr; + unsigned long sr0; #endif #endif /* CONFIG_PPC32 */ /* Debug Registers */ diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S index 4ba6a8c43475..9d31ba2af901 100644 --- a/arch/powerpc/kernel/entry_32.S +++ b/arch/powerpc/kernel/entry_32.S @@ -33,6 +33,7 @@ #include #include #include +#include #include "head_32.h" @@ -76,17 +77,17 @@ _ASM_NOKPROBE_SYMBOL(prepare_transfer_to_handler) #if defined(CONFIG_PPC_KUEP) && defined(CONFIG_PPC_BOOK3S_32) .globl __kuep_lock __kuep_lock: - mfsrr9,0 - rlwinm r9,r9,0,8,3 - orisr9,r9,SR_NX@h +0: blr /* lwz r9, current->thread.sr0(r2) */ update_user_segments_by_4 r9, r10, r11, r12 blr + patch_site 0b, patch__kuep_lock __kuep_unlock: - mfsrr9,0 - rlwinm r9,r9,0,8,2 +0: blr /* lwz r9, current->thread.sr0(r2) */ + rlwinm r9,r9,0,~SR_NX update_user_segments_by_4 r9, r10, r11, r12 blr + patch_site 0b, patch__kuep_unlock .macro kuep_lock bl __kuep_lock diff --git a/arch/powerpc/mm/book3s32/kuap.c b/arch/powerpc/mm/book3s32/kuap.c index 0f920f09af57..28676cabb005 100644 --- a/arch/powerpc/mm/book3s32/kuap.c +++ b/arch/powerpc/mm/book3s32/kuap.c @@ -20,8 +20,11 @@ EXPORT_SYMBOL(kuap_unlock_all_ool); void setup_kuap(bool disabled) { - if (!disabled) + if (!disabled) { kuap_lock_all_ool(); + init_mm.context.sr0 |= SR_KS; + current->thread.sr0 |= SR_KS; + } if (smp_processor_id() != boot_cpuid) return; diff --git a/arch/powerpc/mm/book3s32/kuep.c b/arch/powerpc/mm/book3s32/kuep.c index 45c9967f9aef..0be25492b42d 100644 --- a/arch/powerpc/mm/book3s32/kuep.c +++ b/arch/powerpc/mm/book3s32/kuep.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later +#include #include #include @@ -7,19 +8,26 @@ struct static_key_false disable_kuep_key; void setup_kuep(bool disabled) { - if (disabled) { - pr_info("KUEP cannot be disabled for the time being\n"); - disabled = false; - } + u32 insn; - if (!disabled) - update_user_segments(mfsr(0) | SR_NX); + if (!disabled) { + init_mm.context.sr0 |= SR_NX; + current->thread.sr0 |= SR_NX; + update_user_segments(init_mm.context.sr0); + } if (smp_processor_id() != boot_cpuid) return;
[PATCH v2 03/16] powerpc/kuap: Add a generic intermediate layer
Make the following functions generic to all platforms. - bad_kuap_fault() - kuap_assert_locked() - kuap_save_and_lock() (PPC32 only) - kuap_kernel_restore() - kuap_get_and_assert_locked() And for all platforms except book3s/64 - allow_user_access() - prevent_user_access() - prevent_user_access_return() - restore_user_access() Prepend __ in front of the name of platform specific ones. For now the generic just calls the platform specific, but next patch will move redundant parts of specific functions into the generic one. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/32/kup.h | 22 +++--- arch/powerpc/include/asm/book3s/64/kup.h | 10 ++- arch/powerpc/include/asm/kup.h | 71 +--- arch/powerpc/include/asm/nohash/32/kup-8xx.h | 20 +++--- 4 files changed, 86 insertions(+), 37 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/include/asm/book3s/32/kup.h index 0923dfcb04f7..8f04602d 100644 --- a/arch/powerpc/include/asm/book3s/32/kup.h +++ b/arch/powerpc/include/asm/book3s/32/kup.h @@ -80,7 +80,7 @@ static inline void kuap_unlock(unsigned long addr, bool ool) kuap_unlock_all_ool(); } -static inline void kuap_save_and_lock(struct pt_regs *regs) +static inline void __kuap_save_and_lock(struct pt_regs *regs) { unsigned long kuap = current->thread.kuap; @@ -99,7 +99,7 @@ static inline void kuap_user_restore(struct pt_regs *regs) { } -static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap) +static inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap) { if (kuap_is_disabled()) return; @@ -117,7 +117,7 @@ static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap) kuap_unlock(regs->kuap, false); } -static inline unsigned long kuap_get_and_assert_locked(void) +static inline unsigned long __kuap_get_and_assert_locked(void) { unsigned long kuap = current->thread.kuap; @@ -129,13 +129,13 @@ static inline unsigned long kuap_get_and_assert_locked(void) return kuap; } -static inline void kuap_assert_locked(void) +static inline void __kuap_assert_locked(void) { - kuap_get_and_assert_locked(); + __kuap_get_and_assert_locked(); } -static __always_inline void allow_user_access(void __user *to, const void __user *from, - u32 size, unsigned long dir) +static __always_inline void __allow_user_access(void __user *to, const void __user *from, + u32 size, unsigned long dir) { if (kuap_is_disabled()) return; @@ -149,7 +149,7 @@ static __always_inline void allow_user_access(void __user *to, const void __user kuap_unlock_one((__force u32)to); } -static __always_inline void prevent_user_access(unsigned long dir) +static __always_inline void __prevent_user_access(unsigned long dir) { u32 kuap = current->thread.kuap; @@ -165,7 +165,7 @@ static __always_inline void prevent_user_access(unsigned long dir) kuap_lock(kuap, true); } -static inline unsigned long prevent_user_access_return(void) +static inline unsigned long __prevent_user_access_return(void) { unsigned long flags = current->thread.kuap; @@ -180,7 +180,7 @@ static inline unsigned long prevent_user_access_return(void) return flags; } -static inline void restore_user_access(unsigned long flags) +static inline void __restore_user_access(unsigned long flags) { if (kuap_is_disabled()) return; @@ -192,7 +192,7 @@ static inline void restore_user_access(unsigned long flags) } static inline bool -bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) +__bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) { unsigned long kuap = regs->kuap; diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h index 170339969b7c..03d61c5205a4 100644 --- a/arch/powerpc/include/asm/book3s/64/kup.h +++ b/arch/powerpc/include/asm/book3s/64/kup.h @@ -268,8 +268,7 @@ static inline void kuap_user_restore(struct pt_regs *regs) */ } -static inline void kuap_kernel_restore(struct pt_regs *regs, - unsigned long amr) +static inline void __kuap_kernel_restore(struct pt_regs *regs, unsigned long amr) { if (mmu_has_feature(MMU_FTR_BOOK3S_KUAP)) { if (unlikely(regs->amr != amr)) { @@ -287,7 +286,7 @@ static inline void kuap_kernel_restore(struct pt_regs *regs, */ } -static inline unsigned long kuap_get_and_assert_locked(void) +static inline unsigned long __kuap_get_and_assert_locked(void) { if (mmu_has_feature(MMU_FTR_BOOK3S_KUAP)) { unsigned long amr = mfspr(SPRN_AMR); @@ -298,7 +297,7 @@ static inline unsigned long kuap_get_and_assert_lo
[PATCH v2 00/16] powerpc: Add KUAP support for BOOKE and 40x
On booke/40x we don't have segments like book3s/32. On booke/40x we don't have access protection groups like 8xx. Use the PID register to provide user access protection. Kernel address space can be accessed with any PID. User address space has to be accessed with the PID of the user. User PID is always not null. Everytime the kernel is entered, set PID register to 0 and restore PID register when returning to user. Everytime kernel needs to access user data, PID is restored for the access. In TLB miss handlers, check the PID and bail out to data storage exception when PID is 0 and accessed address is in user space. Note that also forbids execution of user text by kernel except when user access is unlocked. But this shouldn't be a problem as the kernel is not supposed to ever run user text. This series has: - Two first patches have already been submitted and are not directly related to KUAP but would conflict otherwise - Following patches aim at refactoring the KUAP interface to reduce redundant platform specific code. - Then comes patches 9 and 10 that add generic support frame for booke type processors - Followed by the assembly modification for each of the 4 booke family types - Last patch removes CONFIG_PPC_HAVE_KUAP now that all powerpc platforms have KUAP. Changes in v2: - Rebased on top of today's merge (trivial conflict with d93f9e23744b ("powerpc/32s: Fix kuap_kernel_restore()")) - Fix missing check in bad_kuap_fault() which led to KUAP fault on platforms where KUAP was disabled (CI g5_defconfig) - New patch to fix PPC_KUAP_DEBUG dependency Christophe Leroy (16): powerpc/32s: Do kuep_lock() and kuep_unlock() in assembly powerpc/32s: Save content of sr0 to avoid 'mfsr' powerpc/kuap: Add a generic intermediate layer powerpc/kuap: Check KUAP activation in generic functions powerpc/kuap: Remove __kuap_assert_locked() powerpc/kuap: Add kuap_lock() powerpc/nohash: Move setup_kuap out of 8xx.c powerpc/config: Add CONFIG_BOOKE_OR_40x powerpc/kuap: Prepare for supporting KUAP on BOOK3E/64 powerpc/kuap: Make PPC_KUAP_DEBUG depend on PPC_KUAP only powerpc: Add KUAP support for BOOKE and 40x powerpc/kuap: Wire-up KUAP on 44x powerpc/kuap: Wire-up KUAP on 40x powerpc/kuap: Wire-up KUAP on 85xx in 32 bits mode. powerpc/kuap: Wire-up KUAP on book3e/64 powerpc: Remove CONFIG_PPC_HAVE_KUAP arch/powerpc/include/asm/book3s/32/kup.h | 103 --- arch/powerpc/include/asm/book3s/32/mmu-hash.h | 78 +++- arch/powerpc/include/asm/book3s/64/kup.h | 56 - arch/powerpc/include/asm/hw_irq.h | 8 +- arch/powerpc/include/asm/interrupt.h | 13 +- arch/powerpc/include/asm/irq.h| 2 +- arch/powerpc/include/asm/kup.h| 117 +++--- arch/powerpc/include/asm/nohash/32/kup-8xx.h | 50 ++-- arch/powerpc/include/asm/nohash/kup-booke.h | 110 arch/powerpc/include/asm/processor.h | 4 + arch/powerpc/include/asm/ptrace.h | 2 +- arch/powerpc/include/asm/reg.h| 4 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/entry_32.S| 34 - arch/powerpc/kernel/head_32.h | 6 + arch/powerpc/kernel/head_40x.S| 8 ++ arch/powerpc/kernel/head_44x.S| 16 +++ arch/powerpc/kernel/head_fsl_booke.S | 12 ++ arch/powerpc/kernel/interrupt.c | 3 +- arch/powerpc/kernel/irq.c | 2 +- arch/powerpc/kernel/kgdb.c| 4 +- arch/powerpc/kernel/process.c | 9 +- arch/powerpc/kernel/setup.h | 2 +- arch/powerpc/kernel/setup_32.c| 2 +- arch/powerpc/kernel/time.c| 2 +- arch/powerpc/mm/book3s32/kuap.c | 5 +- arch/powerpc/mm/book3s32/kuep.c | 21 +++- arch/powerpc/mm/book3s32/mmu_context.c| 15 ++- arch/powerpc/mm/mmu_context.c | 9 ++ arch/powerpc/mm/nohash/8xx.c | 21 arch/powerpc/mm/nohash/Makefile | 2 +- arch/powerpc/mm/nohash/kup.c | 31 + arch/powerpc/mm/nohash/mmu_context.c | 6 +- arch/powerpc/mm/nohash/tlb_low_64e.S | 40 +- arch/powerpc/platforms/Kconfig.cputype| 14 +-- 35 files changed, 575 insertions(+), 238 deletions(-) create mode 100644 arch/powerpc/include/asm/nohash/kup-booke.h create mode 100644 arch/powerpc/mm/nohash/kup.c -- 2.31.1
[PATCH 0/3] Update crashkernel offset to allow kernel to boot on large config LPARs
As the crashkernel reserve memory at 128MB offset in the first memory block, it leaves less than 128MB memory to accommodate other essential system resources that need memory reservation in the same block. This creates kernel boot failure on large config LPARs having core count greater than 192. Setting the crashkernel to mid of RMA size which can be 512MB or more instead of capping it to 128MB by default leaves enough space to allocate memory to another system resource in the first memory block. Now keeping the crashkernel at mid of RMA size works fine for the primary kernel but creates boot failure for the kdump kernel when the crashekernel reservation start offset crosses 256MB. The reason is, in the early boot MMU feature of 1T segments support is not detected which restricts the paca allocation for boot CPU below 256MB. When the crashkernel itself is starting at 256MB offset, attempt to allocate paca below 256MB leads to the kdump kernel boot failure. Moving the detection of segment sizes before identifying the boot CPU removes the restriction of 256MB limit for boot CPU paca allocation which allows the kdump kernel to successfully boot and capture vmcore. While allocating paca for boot CPU we found that there is a small window during kernel boot where early_radix_enabled returns True even though the radix is disabled using command-line. This leads to an invalid bolated size calculation on which paca limit of boot CPU is dependent. Patch 0001 closes that window that by fixing the radix bit in mmu_feature. changes in v2: 0001: Rename the function name to update_cpu_features() as per the review comment. 0002: Fixed compilation error reported by kernel test robot. 0003: Added comment and updated commit message Mahesh Salgaonkar (2): fixup mmu_features immediately after getting cpu pa features. Remove 256MB limit restriction for boot cpu paca allocation Sourabh Jain (1): powerpc: Set crashkernel offset to mid of RMA region arch/powerpc/include/asm/book3s/64/mmu.h | 2 ++ arch/powerpc/include/asm/mmu.h | 1 + arch/powerpc/kernel/prom.c | 8 arch/powerpc/kernel/rtas.c | 4 arch/powerpc/kexec/core.c| 15 +++ arch/powerpc/mm/book3s64/hash_utils.c| 5 - arch/powerpc/mm/init_64.c| 5 - 7 files changed, 34 insertions(+), 6 deletions(-) -- 2.31.1
[PATCH 1/3] fixup mmu_features immediately after getting cpu pa features.
From: Mahesh Salgaonkar On system with radix support available, early_radix_enabled() starts returning true for a small window (until mmu_early_init_devtree() is called) even when radix mode disabled on kernel command line. This causes ppc64_bolted_size() to return ULONG_MAX in HPT mode instead of supported segment size, during boot cpu paca allocation. Withi kernel command line = "... disable_radix": early_init_devtree: <- early_radix_enabled() = false early_init_dt_scan_cpus:<- early_radix_enabled() = false ... check_cpu_pa_features: <- early_radix_enabled() = false ... ^ <- early_radix_enabled() = TRUE allocate_paca:| <- early_radix_enabled() = TRUE ... | ppc64_bolted_size:| <- early_radix_enabled() = TRUE if (early_radix_enabled())| <- early_radix_enabled() = TRUE return ULONG_MAX; | ... | ... | <- early_radix_enabled() = TRUE ... | <- early_radix_enabled() = TRUE mmu_early_init_devtree() V ... <- early_radix_enabled() = false So far we have not seen any issue because allocate_paca() takes minimum of ppc64_bolted_size and rma_size while allocating paca. However it is better to close this window by fixing up the mmu features as early as possible. This fixes early_radix_enabled() and ppc64_bolted_size() to return valid values in radix disable mode. This patch will help subsequent patch to depend on early_radix_enabled() check while detecting supported segment size in HPT mode. Signed-off-by: Mahesh Salgaonkar Signed-off-by: Sourabh Jain Reported-and-tested-by: Abdul haleem --- arch/powerpc/include/asm/book3s/64/mmu.h | 1 + arch/powerpc/include/asm/mmu.h | 1 + arch/powerpc/kernel/prom.c | 2 ++ arch/powerpc/mm/init_64.c| 5 - 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/book3s/64/mmu.h b/arch/powerpc/include/asm/book3s/64/mmu.h index c02f42d1031e..d60be5051d60 100644 --- a/arch/powerpc/include/asm/book3s/64/mmu.h +++ b/arch/powerpc/include/asm/book3s/64/mmu.h @@ -197,6 +197,7 @@ extern int mmu_vmemmap_psize; extern int mmu_io_psize; /* MMU initialization */ +void update_cpu_features(void); void mmu_early_init_devtree(void); void hash__early_init_devtree(void); void radix__early_init_devtree(void); diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h index 8abe8e42e045..5eb494ea85d7 100644 --- a/arch/powerpc/include/asm/mmu.h +++ b/arch/powerpc/include/asm/mmu.h @@ -401,6 +401,7 @@ extern void early_init_mmu(void); extern void early_init_mmu_secondary(void); extern void setup_initial_memory_limit(phys_addr_t first_memblock_base, phys_addr_t first_memblock_size); +static inline void update_cpu_features(void) { } static inline void mmu_early_init_devtree(void) { } static inline void pkey_early_init_devtree(void) {} diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 2e67588f6f6e..889c909e4ed4 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -380,6 +380,8 @@ static int __init early_init_dt_scan_cpus(unsigned long node, check_cpu_pa_features(node); } + /* Update cpu features based on kernel command line */ + update_cpu_features(); identical_pvr_fixup(node); init_mmu_slb_size(node); diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c index 386be136026e..19680b42898f 100644 --- a/arch/powerpc/mm/init_64.c +++ b/arch/powerpc/mm/init_64.c @@ -437,12 +437,15 @@ static void __init early_check_vec5(void) } } -void __init mmu_early_init_devtree(void) +void __init update_cpu_features(void) { /* Disable radix mode based on kernel command line. */ if (disable_radix) cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX; +} +void __init mmu_early_init_devtree(void) +{ /* * Check /chosen/ibm,architecture-vec-5 if running as a guest. * When running bare-metal, we can use radix if we like -- 2.31.1
[PATCH 2/3] Remove 256MB limit restriction for boot cpu paca allocation
From: Mahesh Salgaonkar At the time when we detect and allocate paca for boot cpu, we havn't yet detected mmu feature of 1T segments support (not until mmu_early_init_devtree() call). This causes ppc64_bolted_size() to return 256MB as limit forcing boot cpu paca allocation below 256MB always. This works fine for kdump kernel boot as long as crashkernel reservation is at offset below 256MB. But when we move kdump offset to 256MB or above, kdump kernel fails to allocate paca for boot cpu below 256MB and crashes in allocate_paca(). Moving the detection of segment sizes just before paca allocation for boot cpu removes this restriction of 256MB limit. This allows kdump kernel to successfully boot and capture vmcore. Signed-off-by: Mahesh Salgaonkar Signed-off-by: Sourabh Jain Reported-and-tested-by: Abdul haleem --- arch/powerpc/include/asm/book3s/64/mmu.h | 1 + arch/powerpc/kernel/prom.c | 6 ++ arch/powerpc/mm/book3s64/hash_utils.c| 5 - 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/book3s/64/mmu.h b/arch/powerpc/include/asm/book3s/64/mmu.h index d60be5051d60..9b05a84313bb 100644 --- a/arch/powerpc/include/asm/book3s/64/mmu.h +++ b/arch/powerpc/include/asm/book3s/64/mmu.h @@ -199,6 +199,7 @@ extern int mmu_io_psize; /* MMU initialization */ void update_cpu_features(void); void mmu_early_init_devtree(void); +void hash__early_detect_seg_size(void); void hash__early_init_devtree(void); void radix__early_init_devtree(void); #ifdef CONFIG_PPC_PKEY diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 889c909e4ed4..5da2bfff4dea 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -385,6 +385,12 @@ static int __init early_init_dt_scan_cpus(unsigned long node, identical_pvr_fixup(node); init_mmu_slb_size(node); +#ifdef CONFIG_PPC_BOOK3S_64 + /* Initialize segment sizes */ + if (!early_radix_enabled()) + hash__early_detect_seg_size(); +#endif + #ifdef CONFIG_PPC64 if (nthreads == 1) cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT; diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index c145776d3ae5..ef4fc6bb1b30 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -1020,11 +1020,14 @@ static void __init htab_initialize(void) #undef KB #undef MB -void __init hash__early_init_devtree(void) +void __init hash__early_detect_seg_size(void) { /* Initialize segment sizes */ of_scan_flat_dt(htab_dt_scan_seg_sizes, NULL); +} +void __init hash__early_init_devtree(void) +{ /* Initialize page sizes */ htab_scan_page_sizes(); } -- 2.31.1
[PATCH 3/3] powerpc: Set crashkernel offset to mid of RMA region
On large config LPARs (having 192 and more cores), Linux fails to boot due to insufficient memory in the first memblock. It is due to the memory reservation for the crash kernel which starts at 128MB offset of the first memblock. This memory reservation for the crash kernel doesn't leave enough space in the first memblock to accommodate other essential system resources. The crash kernel start address was set to 128MB offset by default to ensure that the crash kernel get some memory below the RMA region which is used to be of size 256MB. But given that the RMA region size can be 512MB or more, setting the crash kernel offset to mid of RMA size will leave enough space for kernel to allocate memory for other system resources. Since the above crash kernel offset change is only applicable to the LPAR platform, the LPAR feature detection is pushed before the crash kernel reservation. The rest of LPAR specific initialization will still be done during pseries_probe_fw_features as usual. Signed-off-by: Sourabh Jain Reported-and-tested-by: Abdul haleem --- arch/powerpc/kernel/rtas.c | 4 arch/powerpc/kexec/core.c | 15 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c index ff80bbad22a5..a49137727370 100644 --- a/arch/powerpc/kernel/rtas.c +++ b/arch/powerpc/kernel/rtas.c @@ -1235,6 +1235,10 @@ int __init early_init_dt_scan_rtas(unsigned long node, entryp = of_get_flat_dt_prop(node, "linux,rtas-entry", NULL); sizep = of_get_flat_dt_prop(node, "rtas-size", NULL); + /* need this feature to decide the crashkernel offset */ + if (of_get_flat_dt_prop(node, "ibm,hypertas-functions", NULL)) + powerpc_firmware_features |= FW_FEATURE_LPAR; + if (basep && entryp && sizep) { rtas.base = *basep; rtas.entry = *entryp; diff --git a/arch/powerpc/kexec/core.c b/arch/powerpc/kexec/core.c index 48525e8b5730..71b1bfdadd76 100644 --- a/arch/powerpc/kexec/core.c +++ b/arch/powerpc/kexec/core.c @@ -147,11 +147,18 @@ void __init reserve_crashkernel(void) if (!crashk_res.start) { #ifdef CONFIG_PPC64 /* -* On 64bit we split the RMO in half but cap it at half of -* a small SLB (128MB) since the crash kernel needs to place -* itself and some stacks to be in the first segment. +* On the LPAR platform place the crash kernel to mid of +* RMA size (512MB or more) to ensure the crash kernel +* gets enough space to place itself and some stack to be +* in the first segment. At the same time normal kernel +* also get enough space to allocate memory for essential +* system resource in the first segment. Keep the crash +* kernel starts at 128MB offset on other platforms. */ - crashk_res.start = min(0x800ULL, (ppc64_rma_size / 2)); + if (firmware_has_feature(FW_FEATURE_LPAR)) + crashk_res.start = ppc64_rma_size / 2; + else + crashk_res.start = min(0x800ULL, (ppc64_rma_size / 2)); #else crashk_res.start = KDUMP_KERNELBASE; #endif -- 2.31.1
[PATCH] lkdtm: Fix content of section containing lkdtm_rodata_do_nothing()
On a kernel without CONFIG_STRICT_KERNEL_RWX, running EXEC_RODATA test leads to "Illegal instruction" failure. Looking at the content of rodata_objcopy.o, we see that the function content zeroes only: Disassembly of section .rodata: <.lkdtm_rodata_do_nothing>: 0: 00 00 00 00 .long 0x0 Add the contents flag in order to keep the content of the section while renaming it. Disassembly of section .rodata: <.lkdtm_rodata_do_nothing>: 0: 4e 80 00 20 blr Fixes: e9e08a07385e ("lkdtm: support llvm-objcopy") Cc: sta...@vger.kernel.org Cc: Kees Cook Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Cc: Nick Desaulniers Cc: Nathan Chancellor Signed-off-by: Christophe Leroy --- drivers/misc/lkdtm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile index aa12097668d3..e2984ce51fe4 100644 --- a/drivers/misc/lkdtm/Makefile +++ b/drivers/misc/lkdtm/Makefile @@ -20,7 +20,7 @@ CFLAGS_REMOVE_rodata.o+= $(CC_FLAGS_LTO) OBJCOPYFLAGS := OBJCOPYFLAGS_rodata_objcopy.o := \ - --rename-section .noinstr.text=.rodata,alloc,readonly,load + --rename-section .noinstr.text=.rodata,alloc,readonly,load,contents targets += rodata.o rodata_objcopy.o $(obj)/rodata_objcopy.o: $(obj)/rodata.o FORCE $(call if_changed,objcopy) -- 2.31.1
Re: Add Apple M1 support to PASemi i2c driver
Hi Michael, Do you have a mbox link for the v2 changes? I would like to test them on my AmigaOne X1000. Thanks, Christian On 27. Sep 2021, at 09:58, Michael Ellerman wrote: Christian, the whole series is downloadable as a single mbox here: https://patchwork.ozlabs.org/series/264134/mbox/ Save that to a file and apply with `git am`. eg: $ wget -O mbox https://patchwork.ozlabs.org/series/264134/mbox/ $ git am mbox It applies cleanly on v5.15-rc3. cheers
[PATCH v2 00/11] Add Apple M1 support to PASemi i2c driver
Hi, v1: https://lore.kernel.org/linux-i2c/20210926095847.38261-1-s...@svenpeter.dev/ Changes for v2: - Added reviewed-by/acks - Switched from ioport_map to pci_iomap as suggested by Arnd Bergmann - Renamed i2c-pasemi-apple.c to i2c-pasemi-platform.c as suggested by Wolfram Sang - Replaced the ioport number in the adapter name with dev_name to be able to identify separate busses in e.g. i2cdetect. I still don't have access to any old PASemi hardware but the changes from v1 are pretty small and I expect them to still work. Would still be nice if someone with access to such hardware could give this a quick test. And for those who didn't see v1 the (almost) unchanged original cover letter: This series adds support for the I2C controller found on Apple Silicon Macs which has quite a bit of history: Apple bought P.A. Semi in 2008 and it looks like a part of its legacy continues to live on in the M1. This controller has actually been used since at least the iPhone 4S and hasn't changed much since then. Essentially, there are only a few differences that matter: - The controller no longer is a PCI device - Starting at some iPhone an additional bit in one register must be set in order to start transmissions. - The reference clock and hence the clock dividers are different In order to add support for a platform device I first replaced PCI-specific bits and split out the PCI driver to its own file. Then I added support to make the clock divider configurable and converted the driver to use managed device resources to make it a bit simpler. The Apple and PASemi driver will never be compiled in the same kernel since the Apple one will run on arm64 while the original PASemi driver will only be useful on powerpc. I've thus followed the octeon (mips)/thunderx(arm64) approach to do the split: I created a -core.c file which contains the shared logic and just compile that one for both the PASemi and the new Apple driver. Best, Sven Sven Peter (11): dt-bindings: i2c: Add Apple I2C controller bindings i2c: pasemi: Use io{read,write}32 i2c: pasemi: Use dev_name instead of port number i2c: pasemi: Remove usage of pci_dev i2c: pasemi: Split off common probing code i2c: pasemi: Split pci driver to its own file i2c: pasemi: Move common reset code to own function i2c: pasemi: Allow to configure bus frequency i2c: pasemi: Refactor _probe to use devm_* i2c: pasemi: Add Apple platform driver i2c: pasemi: Set enable bit for Apple variant .../devicetree/bindings/i2c/apple,i2c.yaml| 61 + MAINTAINERS | 2 + drivers/i2c/busses/Kconfig| 11 ++ drivers/i2c/busses/Makefile | 3 + .../{i2c-pasemi.c => i2c-pasemi-core.c} | 114 +--- drivers/i2c/busses/i2c-pasemi-core.h | 21 +++ drivers/i2c/busses/i2c-pasemi-pci.c | 85 drivers/i2c/busses/i2c-pasemi-platform.c | 122 ++ 8 files changed, 334 insertions(+), 85 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/apple,i2c.yaml rename drivers/i2c/busses/{i2c-pasemi.c => i2c-pasemi-core.c} (77%) create mode 100644 drivers/i2c/busses/i2c-pasemi-core.h create mode 100644 drivers/i2c/busses/i2c-pasemi-pci.c create mode 100644 drivers/i2c/busses/i2c-pasemi-platform.c -- 2.25.1
[PATCH v2 01/11] dt-bindings: i2c: Add Apple I2C controller bindings
The Apple I2C controller is based on the PASemi I2C controller. It is present on Apple SoCs such as the M1. Reviewed-by: Arnd Bergmann Reviewed-by: Rob Herring Signed-off-by: Sven Peter --- v1 -> v2: no changes .../devicetree/bindings/i2c/apple,i2c.yaml| 61 +++ MAINTAINERS | 1 + 2 files changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/apple,i2c.yaml diff --git a/Documentation/devicetree/bindings/i2c/apple,i2c.yaml b/Documentation/devicetree/bindings/i2c/apple,i2c.yaml new file mode 100644 index ..22fc8483256f --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/apple,i2c.yaml @@ -0,0 +1,61 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/i2c/apple,i2c.yaml#"; +$schema: "http://devicetree.org/meta-schemas/core.yaml#"; + +title: Apple/PASemi I2C controller + +maintainers: + - Sven Peter + +description: | + Apple SoCs such as the M1 come with a I2C controller based on the one found + in machines with P. A. Semi's PWRficient processors. + The bus is used to communicate with e.g. USB PD chips or the speaker + amp. + +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +properties: + compatible: +enum: + - apple,t8103-i2c + - apple,i2c + + reg: +maxItems: 1 + + clocks: +items: + - description: I2C bus reference clock + + interrupts: +maxItems: 1 + + clock-frequency: +description: | + Desired I2C bus clock frequency in Hz. If not specified, 100 kHz will be + used. This frequency is generated by dividing the reference clock. + Allowed values are between ref_clk/(16*4) and ref_clk/(16*255). + +required: + - compatible + - reg + - clocks + - interrupts + +unevaluatedProperties: false + +examples: + - | +i2c@3501 { + compatible = "apple,t8103-i2c"; + reg = <0x3501 0x4000>; + interrupt-parent = <&aic>; + interrupts = <0 627 4>; + clocks = <&ref_clk>; + #address-cells = <1>; + #size-cells = <0>; +}; diff --git a/MAINTAINERS b/MAINTAINERS index 7cfd63ce7122..74aa85967ca3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1735,6 +1735,7 @@ B:https://github.com/AsahiLinux/linux/issues C: irc://irc.oftc.net/asahi-dev T: git https://github.com/AsahiLinux/linux.git F: Documentation/devicetree/bindings/arm/apple.yaml +F: Documentation/devicetree/bindings/i2c/apple,i2c.yaml F: Documentation/devicetree/bindings/interrupt-controller/apple,aic.yaml F: Documentation/devicetree/bindings/pci/apple,pcie.yaml F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml -- 2.25.1
[PATCH v2 02/11] i2c: pasemi: Use io{read,write}32
In preparation for splitting this driver up into a platform_driver and a pci_driver, replace outl/inl usage with pci_iomap and ioread32/iowrite32. Reviewed-by: Arnd Bergmann Signed-off-by: Sven Peter --- v1 -> v2: replaced ioport_map with pci_iomap drivers/i2c/busses/i2c-pasemi.c | 16 +--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c index 20f2772c0e79..39fcc584264a 100644 --- a/drivers/i2c/busses/i2c-pasemi.c +++ b/drivers/i2c/busses/i2c-pasemi.c @@ -20,6 +20,7 @@ static struct pci_driver pasemi_smb_driver; struct pasemi_smbus { struct pci_dev *dev; struct i2c_adapter adapter; + void __iomem*ioaddr; unsigned longbase; int size; }; @@ -53,13 +54,13 @@ static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) { dev_dbg(&smbus->dev->dev, "smbus write reg %lx val %08x\n", smbus->base + reg, val); - outl(val, smbus->base + reg); + iowrite32(val, smbus->ioaddr + reg); } static inline int reg_read(struct pasemi_smbus *smbus, int reg) { int ret; - ret = inl(smbus->base + reg); + ret = ioread32(smbus->ioaddr + reg); dev_dbg(&smbus->dev->dev, "smbus read reg %lx val %08x\n", smbus->base + reg, ret); return ret; @@ -351,6 +352,12 @@ static int pasemi_smb_probe(struct pci_dev *dev, goto out_kfree; } + smbus->ioaddr = pci_iomap(dev, 0, 0); + if (!smbus->ioaddr) { + error = -EBUSY; + goto out_release_region; + } + smbus->adapter.owner = THIS_MODULE; snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), "PA Semi SMBus adapter at 0x%lx", smbus->base); @@ -366,12 +373,14 @@ static int pasemi_smb_probe(struct pci_dev *dev, error = i2c_add_adapter(&smbus->adapter); if (error) - goto out_release_region; + goto out_ioport_unmap; pci_set_drvdata(dev, smbus); return 0; + out_ioport_unmap: + pci_iounmap(dev, smbus->ioaddr); out_release_region: release_region(smbus->base, smbus->size); out_kfree: @@ -384,6 +393,7 @@ static void pasemi_smb_remove(struct pci_dev *dev) struct pasemi_smbus *smbus = pci_get_drvdata(dev); i2c_del_adapter(&smbus->adapter); + pci_iounmap(dev, smbus->ioaddr); release_region(smbus->base, smbus->size); kfree(smbus); } -- 2.25.1
[PATCH v2 03/11] i2c: pasemi: Use dev_name instead of port number
Right now the i2c adapter name includes the port number which can indirectly be used to identify the device. Replace that with dev_name to directly identify the device and to also allow this to work correctly once we add platform support. Signed-off-by: Sven Peter --- v1 -> v2: new commit drivers/i2c/busses/i2c-pasemi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c index 39fcc584264a..ca5a86cf53f1 100644 --- a/drivers/i2c/busses/i2c-pasemi.c +++ b/drivers/i2c/busses/i2c-pasemi.c @@ -360,7 +360,7 @@ static int pasemi_smb_probe(struct pci_dev *dev, smbus->adapter.owner = THIS_MODULE; snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), -"PA Semi SMBus adapter at 0x%lx", smbus->base); +"PA Semi SMBus adapter (%s)", dev_name(smbus->dev)); smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; smbus->adapter.algo = &smbus_algorithm; smbus->adapter.algo_data = smbus; -- 2.25.1
[PATCH v2 04/11] i2c: pasemi: Remove usage of pci_dev
Prepare to create a platform driver by removing all usages of pci_dev we can. Reviewed-by: Arnd Bergmann Signed-off-by: Sven Peter --- v1 -> v2: no changes drivers/i2c/busses/i2c-pasemi.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c index ca5a86cf53f1..a018e9376023 100644 --- a/drivers/i2c/busses/i2c-pasemi.c +++ b/drivers/i2c/busses/i2c-pasemi.c @@ -18,7 +18,7 @@ static struct pci_driver pasemi_smb_driver; struct pasemi_smbus { - struct pci_dev *dev; + struct device *dev; struct i2c_adapter adapter; void __iomem*ioaddr; unsigned longbase; @@ -52,7 +52,7 @@ struct pasemi_smbus { static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) { - dev_dbg(&smbus->dev->dev, "smbus write reg %lx val %08x\n", + dev_dbg(smbus->dev, "smbus write reg %lx val %08x\n", smbus->base + reg, val); iowrite32(val, smbus->ioaddr + reg); } @@ -61,7 +61,7 @@ static inline int reg_read(struct pasemi_smbus *smbus, int reg) { int ret; ret = ioread32(smbus->ioaddr + reg); - dev_dbg(&smbus->dev->dev, "smbus read reg %lx val %08x\n", + dev_dbg(smbus->dev, "smbus read reg %lx val %08x\n", smbus->base + reg, ret); return ret; } @@ -94,7 +94,7 @@ static int pasemi_smb_waitready(struct pasemi_smbus *smbus) return -ENXIO; if (timeout < 0) { - dev_warn(&smbus->dev->dev, "Timeout, status 0x%08x\n", status); + dev_warn(smbus->dev, "Timeout, status 0x%08x\n", status); reg_write(smbus, REG_SMSTA, status); return -ETIME; } @@ -342,7 +342,7 @@ static int pasemi_smb_probe(struct pci_dev *dev, if (!smbus) return -ENOMEM; - smbus->dev = dev; + smbus->dev = &dev->dev; smbus->base = pci_resource_start(dev, 0); smbus->size = pci_resource_len(dev, 0); @@ -366,7 +366,7 @@ static int pasemi_smb_probe(struct pci_dev *dev, smbus->adapter.algo_data = smbus; /* set up the sysfs linkage to our parent device */ - smbus->adapter.dev.parent = &dev->dev; + smbus->adapter.dev.parent = smbus->dev; reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | (CLK_100K_DIV & CTL_CLK_M))); -- 2.25.1
[PATCH v2 05/11] i2c: pasemi: Split off common probing code
Split off common probing code that will be used by both the PCI and the platform device. Reviewed-by: Arnd Bergmann Signed-off-by: Sven Peter --- v1 -> v2: no changes drivers/i2c/busses/i2c-pasemi.c | 39 + 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c index a018e9376023..baf338149673 100644 --- a/drivers/i2c/busses/i2c-pasemi.c +++ b/drivers/i2c/busses/i2c-pasemi.c @@ -329,6 +329,30 @@ static const struct i2c_algorithm smbus_algorithm = { .functionality = pasemi_smb_func, }; +static int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) +{ + int error; + + smbus->adapter.owner = THIS_MODULE; + snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), +"PA Semi SMBus adapter (%s)", dev_name(smbus->dev)); + smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; + smbus->adapter.algo = &smbus_algorithm; + smbus->adapter.algo_data = smbus; + + /* set up the sysfs linkage to our parent device */ + smbus->adapter.dev.parent = smbus->dev; + + reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | + (CLK_100K_DIV & CTL_CLK_M))); + + error = i2c_add_adapter(&smbus->adapter); + if (error) + return error; + + return 0; +} + static int pasemi_smb_probe(struct pci_dev *dev, const struct pci_device_id *id) { @@ -358,20 +382,7 @@ static int pasemi_smb_probe(struct pci_dev *dev, goto out_release_region; } - smbus->adapter.owner = THIS_MODULE; - snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), -"PA Semi SMBus adapter (%s)", dev_name(smbus->dev)); - smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; - smbus->adapter.algo = &smbus_algorithm; - smbus->adapter.algo_data = smbus; - - /* set up the sysfs linkage to our parent device */ - smbus->adapter.dev.parent = smbus->dev; - - reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | - (CLK_100K_DIV & CTL_CLK_M))); - - error = i2c_add_adapter(&smbus->adapter); + int error = pasemi_i2c_common_probe(smbus); if (error) goto out_ioport_unmap; -- 2.25.1
[PATCH v2 06/11] i2c: pasemi: Split pci driver to its own file
Split off the PCI driver so that we can reuse common code for the platform driver. Reviewed-by: Arnd Bergmann Signed-off-by: Sven Peter --- v1 -> v2: no changes drivers/i2c/busses/Makefile | 1 + .../{i2c-pasemi.c => i2c-pasemi-core.c} | 88 + drivers/i2c/busses/i2c-pasemi-core.h | 19 drivers/i2c/busses/i2c-pasemi-pci.c | 96 +++ 4 files changed, 118 insertions(+), 86 deletions(-) rename drivers/i2c/busses/{i2c-pasemi.c => i2c-pasemi-core.c} (81%) create mode 100644 drivers/i2c/busses/i2c-pasemi-core.h create mode 100644 drivers/i2c/busses/i2c-pasemi-pci.c diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 1336b04f40e2..0ab1b4cb2228 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -84,6 +84,7 @@ obj-$(CONFIG_I2C_NPCM7XX) += i2c-npcm7xx.o obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o obj-$(CONFIG_I2C_OMAP) += i2c-omap.o obj-$(CONFIG_I2C_OWL) += i2c-owl.o +i2c-pasemi-objs := i2c-pasemi-core.o i2c-pasemi-pci.o obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o obj-$(CONFIG_I2C_PNX) += i2c-pnx.o diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi-core.c similarity index 81% rename from drivers/i2c/busses/i2c-pasemi.c rename to drivers/i2c/busses/i2c-pasemi-core.c index baf338149673..d1cab11a4d50 100644 --- a/drivers/i2c/busses/i2c-pasemi.c +++ b/drivers/i2c/busses/i2c-pasemi-core.c @@ -15,15 +15,7 @@ #include #include -static struct pci_driver pasemi_smb_driver; - -struct pasemi_smbus { - struct device *dev; - struct i2c_adapter adapter; - void __iomem*ioaddr; - unsigned longbase; - int size; -}; +#include "i2c-pasemi-core.h" /* Register offsets */ #define REG_MTXFIFO0x00 @@ -329,7 +321,7 @@ static const struct i2c_algorithm smbus_algorithm = { .functionality = pasemi_smb_func, }; -static int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) +int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) { int error; @@ -352,79 +344,3 @@ static int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) return 0; } - -static int pasemi_smb_probe(struct pci_dev *dev, - const struct pci_device_id *id) -{ - struct pasemi_smbus *smbus; - int error; - - if (!(pci_resource_flags(dev, 0) & IORESOURCE_IO)) - return -ENODEV; - - smbus = kzalloc(sizeof(struct pasemi_smbus), GFP_KERNEL); - if (!smbus) - return -ENOMEM; - - smbus->dev = &dev->dev; - smbus->base = pci_resource_start(dev, 0); - smbus->size = pci_resource_len(dev, 0); - - if (!request_region(smbus->base, smbus->size, - pasemi_smb_driver.name)) { - error = -EBUSY; - goto out_kfree; - } - - smbus->ioaddr = pci_iomap(dev, 0, 0); - if (!smbus->ioaddr) { - error = -EBUSY; - goto out_release_region; - } - - int error = pasemi_i2c_common_probe(smbus); - if (error) - goto out_ioport_unmap; - - pci_set_drvdata(dev, smbus); - - return 0; - - out_ioport_unmap: - pci_iounmap(dev, smbus->ioaddr); - out_release_region: - release_region(smbus->base, smbus->size); - out_kfree: - kfree(smbus); - return error; -} - -static void pasemi_smb_remove(struct pci_dev *dev) -{ - struct pasemi_smbus *smbus = pci_get_drvdata(dev); - - i2c_del_adapter(&smbus->adapter); - pci_iounmap(dev, smbus->ioaddr); - release_region(smbus->base, smbus->size); - kfree(smbus); -} - -static const struct pci_device_id pasemi_smb_ids[] = { - { PCI_DEVICE(0x1959, 0xa003) }, - { 0, } -}; - -MODULE_DEVICE_TABLE(pci, pasemi_smb_ids); - -static struct pci_driver pasemi_smb_driver = { - .name = "i2c-pasemi", - .id_table = pasemi_smb_ids, - .probe = pasemi_smb_probe, - .remove = pasemi_smb_remove, -}; - -module_pci_driver(pasemi_smb_driver); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR ("Olof Johansson "); -MODULE_DESCRIPTION("PA Semi PWRficient SMBus driver"); diff --git a/drivers/i2c/busses/i2c-pasemi-core.h b/drivers/i2c/busses/i2c-pasemi-core.h new file mode 100644 index ..7acc33de6ce1 --- /dev/null +++ b/drivers/i2c/busses/i2c-pasemi-core.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include +#include +#include +#include +#include +#include +#include + +struct pasemi_smbus { + struct device *dev; + struct i2c_adapter adapter; + void __iomem*ioaddr; + unsigned longbase; + int size; +}; + +int pasemi_i2c_common_probe(s
[PATCH v2 07/11] i2c: pasemi: Move common reset code to own function
Split out common reset call to its own function so that we can later add support for selecting the clock frequency and an additional enable bit found in newer revisions. Reviewed-by: Arnd Bergmann Signed-off-by: Sven Peter --- v1 -> v2: no changes drivers/i2c/busses/i2c-pasemi-core.c | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-pasemi-core.c b/drivers/i2c/busses/i2c-pasemi-core.c index d1cab11a4d50..232587c70a38 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.c +++ b/drivers/i2c/busses/i2c-pasemi-core.c @@ -61,6 +61,12 @@ static inline int reg_read(struct pasemi_smbus *smbus, int reg) #define TXFIFO_WR(smbus, reg) reg_write((smbus), REG_MTXFIFO, (reg)) #define RXFIFO_RD(smbus) reg_read((smbus), REG_MRXFIFO) +static void pasemi_reset(struct pasemi_smbus *smbus) +{ + reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | + (CLK_100K_DIV & CTL_CLK_M))); +} + static void pasemi_smb_clear(struct pasemi_smbus *smbus) { unsigned int status; @@ -135,8 +141,7 @@ static int pasemi_i2c_xfer_msg(struct i2c_adapter *adapter, return 0; reset_out: - reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | - (CLK_100K_DIV & CTL_CLK_M))); + pasemi_reset(smbus); return err; } @@ -302,8 +307,7 @@ static int pasemi_smb_xfer(struct i2c_adapter *adapter, return 0; reset_out: - reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | - (CLK_100K_DIV & CTL_CLK_M))); + pasemi_reset(smbus); return err; } @@ -335,8 +339,7 @@ int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) /* set up the sysfs linkage to our parent device */ smbus->adapter.dev.parent = smbus->dev; - reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | - (CLK_100K_DIV & CTL_CLK_M))); + pasemi_reset(smbus); error = i2c_add_adapter(&smbus->adapter); if (error) -- 2.25.1
[PATCH v2 08/11] i2c: pasemi: Allow to configure bus frequency
Right now the bus frequency has always been hardcoded as 100 KHz with the specific reference clock used in the PASemi PCI controllers. Make this configurable to prepare for the platform driver. Reviewed-by: Arnd Bergmann Signed-off-by: Sven Peter --- v1 -> v2: no changes drivers/i2c/busses/i2c-pasemi-core.c | 8 +++- drivers/i2c/busses/i2c-pasemi-core.h | 1 + drivers/i2c/busses/i2c-pasemi-pci.c | 4 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-pasemi-core.c b/drivers/i2c/busses/i2c-pasemi-core.c index 232587c70a38..9fb8fac53f2b 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.c +++ b/drivers/i2c/busses/i2c-pasemi-core.c @@ -39,9 +39,6 @@ #define CTL_MTR0x0200 #define CTL_CLK_M 0x00ff -#define CLK_100K_DIV 84 -#define CLK_400K_DIV 21 - static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) { dev_dbg(smbus->dev, "smbus write reg %lx val %08x\n", @@ -63,8 +60,9 @@ static inline int reg_read(struct pasemi_smbus *smbus, int reg) static void pasemi_reset(struct pasemi_smbus *smbus) { - reg_write(smbus, REG_CTL, (CTL_MTR | CTL_MRR | - (CLK_100K_DIV & CTL_CLK_M))); + u32 val = (CTL_MTR | CTL_MRR | (smbus->clk_div & CTL_CLK_M)); + + reg_write(smbus, REG_CTL, val); } static void pasemi_smb_clear(struct pasemi_smbus *smbus) diff --git a/drivers/i2c/busses/i2c-pasemi-core.h b/drivers/i2c/busses/i2c-pasemi-core.h index 7acc33de6ce1..30a7990825ef 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.h +++ b/drivers/i2c/busses/i2c-pasemi-core.h @@ -14,6 +14,7 @@ struct pasemi_smbus { void __iomem*ioaddr; unsigned longbase; int size; + unsigned int clk_div; }; int pasemi_i2c_common_probe(struct pasemi_smbus *smbus); diff --git a/drivers/i2c/busses/i2c-pasemi-pci.c b/drivers/i2c/busses/i2c-pasemi-pci.c index 644656e28012..96585bbf8c24 100644 --- a/drivers/i2c/busses/i2c-pasemi-pci.c +++ b/drivers/i2c/busses/i2c-pasemi-pci.c @@ -17,6 +17,9 @@ #include "i2c-pasemi-core.h" +#define CLK_100K_DIV 84 +#define CLK_400K_DIV 21 + static struct pci_driver pasemi_smb_pci_driver; static int pasemi_smb_pci_probe(struct pci_dev *dev, @@ -35,6 +38,7 @@ static int pasemi_smb_pci_probe(struct pci_dev *dev, smbus->dev = &dev->dev; smbus->base = pci_resource_start(dev, 0); smbus->size = pci_resource_len(dev, 0); + smbus->clk_div = CLK_100K_DIV; if (!request_region(smbus->base, smbus->size, pasemi_smb_pci_driver.name)) { -- 2.25.1
[PATCH v2 09/11] i2c: pasemi: Refactor _probe to use devm_*
Using managed device resources means there's nothing left to be done in pasemi_smb_pci_remove and also allows to remove base and size from struct pasemi_smbus. Reviewed-by: Arnd Bergmann Signed-off-by: Sven Peter --- v1 -> v2: no changes drivers/i2c/busses/i2c-pasemi-core.c | 8 ++--- drivers/i2c/busses/i2c-pasemi-core.h | 2 -- drivers/i2c/busses/i2c-pasemi-pci.c | 45 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/drivers/i2c/busses/i2c-pasemi-core.c b/drivers/i2c/busses/i2c-pasemi-core.c index 9fb8fac53f2b..3d87b64dd9f7 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.c +++ b/drivers/i2c/busses/i2c-pasemi-core.c @@ -41,8 +41,7 @@ static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) { - dev_dbg(smbus->dev, "smbus write reg %lx val %08x\n", - smbus->base + reg, val); + dev_dbg(smbus->dev, "smbus write reg %x val %08x\n", reg, val); iowrite32(val, smbus->ioaddr + reg); } @@ -50,8 +49,7 @@ static inline int reg_read(struct pasemi_smbus *smbus, int reg) { int ret; ret = ioread32(smbus->ioaddr + reg); - dev_dbg(smbus->dev, "smbus read reg %lx val %08x\n", - smbus->base + reg, ret); + dev_dbg(smbus->dev, "smbus read reg %x val %08x\n", reg, ret); return ret; } @@ -339,7 +337,7 @@ int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) pasemi_reset(smbus); - error = i2c_add_adapter(&smbus->adapter); + error = devm_i2c_add_adapter(smbus->dev, &smbus->adapter); if (error) return error; diff --git a/drivers/i2c/busses/i2c-pasemi-core.h b/drivers/i2c/busses/i2c-pasemi-core.h index 30a7990825ef..aca4e2da9089 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.h +++ b/drivers/i2c/busses/i2c-pasemi-core.h @@ -12,8 +12,6 @@ struct pasemi_smbus { struct device *dev; struct i2c_adapter adapter; void __iomem*ioaddr; - unsigned longbase; - int size; unsigned int clk_div; }; diff --git a/drivers/i2c/busses/i2c-pasemi-pci.c b/drivers/i2c/busses/i2c-pasemi-pci.c index 96585bbf8c24..4251e7b9f177 100644 --- a/drivers/i2c/busses/i2c-pasemi-pci.c +++ b/drivers/i2c/busses/i2c-pasemi-pci.c @@ -26,57 +26,37 @@ static int pasemi_smb_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { struct pasemi_smbus *smbus; + unsigned long base; + int size; int error; if (!(pci_resource_flags(dev, 0) & IORESOURCE_IO)) return -ENODEV; - smbus = kzalloc(sizeof(struct pasemi_smbus), GFP_KERNEL); + smbus = devm_kzalloc(&dev->dev, sizeof(*smbus), GFP_KERNEL); if (!smbus) return -ENOMEM; smbus->dev = &dev->dev; - smbus->base = pci_resource_start(dev, 0); - smbus->size = pci_resource_len(dev, 0); + base = pci_resource_start(dev, 0); + size = pci_resource_len(dev, 0); smbus->clk_div = CLK_100K_DIV; - if (!request_region(smbus->base, smbus->size, - pasemi_smb_pci_driver.name)) { - error = -EBUSY; - goto out_kfree; - } + if (!devm_request_region(&dev->dev, base, size, + pasemi_smb_pci_driver.name)) + return -EBUSY; - smbus->ioaddr = pci_iomap(dev, 0, 0); - if (!smbus->ioaddr) { - error = -EBUSY; - goto out_release_region; - } + smbus->ioaddr = pcim_iomap(dev, 0, 0); + if (!smbus->ioaddr) + return -EBUSY; error = pasemi_i2c_common_probe(smbus); if (error) - goto out_ioport_unmap; + return error; pci_set_drvdata(dev, smbus); return 0; - - out_ioport_unmap: - pci_iounmap(dev, smbus->ioaddr); - out_release_region: - release_region(smbus->base, smbus->size); - out_kfree: - kfree(smbus); - return error; -} - -static void pasemi_smb_pci_remove(struct pci_dev *dev) -{ - struct pasemi_smbus *smbus = pci_get_drvdata(dev); - - i2c_del_adapter(&smbus->adapter); - pci_iounmap(dev, smbus->ioaddr); - release_region(smbus->base, smbus->size); - kfree(smbus); } static const struct pci_device_id pasemi_smb_pci_ids[] = { @@ -90,7 +70,6 @@ static struct pci_driver pasemi_smb_pci_driver = { .name = "i2c-pasemi", .id_table = pasemi_smb_pci_ids, .probe = pasemi_smb_pci_probe, - .remove = pasemi_smb_pci_remove, }; module_pci_driver(pasemi_smb_pci_driver); -- 2.25.1
[PATCH v2 11/11] i2c: pasemi: Set enable bit for Apple variant
Some later revisions after the original PASemi I2C controller introduce what likely is an enable bit to the CTL register. Without setting it the actual i2c transmission is never started. Reviewed-by: Arnd Bergmann Signed-off-by: Sven Peter --- v1 -> v2: no changes drivers/i2c/busses/i2c-pasemi-core.c | 8 drivers/i2c/busses/i2c-pasemi-core.h | 3 +++ drivers/i2c/busses/i2c-pasemi-pci.c | 6 ++ 3 files changed, 17 insertions(+) diff --git a/drivers/i2c/busses/i2c-pasemi-core.c b/drivers/i2c/busses/i2c-pasemi-core.c index 3d87b64dd9f7..4e161a4089d8 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.c +++ b/drivers/i2c/busses/i2c-pasemi-core.c @@ -22,6 +22,7 @@ #define REG_MRXFIFO0x04 #define REG_SMSTA 0x14 #define REG_CTL0x1c +#define REG_REV0x28 /* Register defs */ #define MTXFIFO_READ 0x0400 @@ -37,6 +38,7 @@ #define CTL_MRR0x0400 #define CTL_MTR0x0200 +#define CTL_EN 0x0800 #define CTL_CLK_M 0x00ff static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) @@ -60,6 +62,9 @@ static void pasemi_reset(struct pasemi_smbus *smbus) { u32 val = (CTL_MTR | CTL_MRR | (smbus->clk_div & CTL_CLK_M)); + if (smbus->hw_rev >= 6) + val |= CTL_EN; + reg_write(smbus, REG_CTL, val); } @@ -335,6 +340,9 @@ int pasemi_i2c_common_probe(struct pasemi_smbus *smbus) /* set up the sysfs linkage to our parent device */ smbus->adapter.dev.parent = smbus->dev; + if (smbus->hw_rev != PASEMI_HW_REV_PCI) + smbus->hw_rev = reg_read(smbus, REG_REV); + pasemi_reset(smbus); error = devm_i2c_add_adapter(smbus->dev, &smbus->adapter); diff --git a/drivers/i2c/busses/i2c-pasemi-core.h b/drivers/i2c/busses/i2c-pasemi-core.h index aca4e2da9089..4655124a37f3 100644 --- a/drivers/i2c/busses/i2c-pasemi-core.h +++ b/drivers/i2c/busses/i2c-pasemi-core.h @@ -8,11 +8,14 @@ #include #include +#define PASEMI_HW_REV_PCI -1 + struct pasemi_smbus { struct device *dev; struct i2c_adapter adapter; void __iomem*ioaddr; unsigned int clk_div; + int hw_rev; }; int pasemi_i2c_common_probe(struct pasemi_smbus *smbus); diff --git a/drivers/i2c/busses/i2c-pasemi-pci.c b/drivers/i2c/busses/i2c-pasemi-pci.c index 4251e7b9f177..1ab1f28744fb 100644 --- a/drivers/i2c/busses/i2c-pasemi-pci.c +++ b/drivers/i2c/busses/i2c-pasemi-pci.c @@ -42,6 +42,12 @@ static int pasemi_smb_pci_probe(struct pci_dev *dev, size = pci_resource_len(dev, 0); smbus->clk_div = CLK_100K_DIV; + /* +* The original PASemi PCI controllers don't have a register for +* their HW revision. +*/ + smbus->hw_rev = PASEMI_HW_REV_PCI; + if (!devm_request_region(&dev->dev, base, size, pasemi_smb_pci_driver.name)) return -EBUSY; -- 2.25.1
[PATCH v2 10/11] i2c: pasemi: Add Apple platform driver
With all the previous preparations we can now finally add the platform driver to support the PASemi-based controllers in Apple SoCs. This does not work on the M1 yet but should work on the early iPhones already. Reviewed-by: Arnd Bergmann Signed-off-by: Sven Peter --- v1 -> v2: - renamed i2c-pasemi-apple.c to i2c-pasemi-platform.c and adjusted function names as well - removed unused struct pinctrl *pctrl which snuck into v1 MAINTAINERS | 1 + drivers/i2c/busses/Kconfig | 11 ++ drivers/i2c/busses/Makefile | 2 + drivers/i2c/busses/i2c-pasemi-platform.c | 122 +++ 4 files changed, 136 insertions(+) create mode 100644 drivers/i2c/busses/i2c-pasemi-platform.c diff --git a/MAINTAINERS b/MAINTAINERS index 74aa85967ca3..8e0f1dc94b5b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1740,6 +1740,7 @@ F: Documentation/devicetree/bindings/interrupt-controller/apple,aic.yaml F: Documentation/devicetree/bindings/pci/apple,pcie.yaml F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml F: arch/arm64/boot/dts/apple/ +F: drivers/i2c/busses/i2c-pasemi-platform.c F: drivers/irqchip/irq-apple-aic.c F: include/dt-bindings/interrupt-controller/apple-aic.h F: include/dt-bindings/pinctrl/apple.h diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 1df19ccc310b..dce392839017 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -859,6 +859,17 @@ config I2C_PASEMI help Supports the PA Semi PWRficient on-chip SMBus interfaces. +config I2C_APPLE + tristate "Apple SMBus platform driver" + depends on ARCH_APPLE || COMPILE_TEST + default ARCH_APPLE + help + Say Y here if you want to use the I2C controller present on Apple + Silicon chips such as the M1. + + This driver can also be built as a module. If so, the module + will be called i2c-apple. + config I2C_PCA_PLATFORM tristate "PCA9564/PCA9665 as platform device" select I2C_ALGOPCA diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 0ab1b4cb2228..d85899fef8c7 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -86,6 +86,8 @@ obj-$(CONFIG_I2C_OMAP)+= i2c-omap.o obj-$(CONFIG_I2C_OWL) += i2c-owl.o i2c-pasemi-objs := i2c-pasemi-core.o i2c-pasemi-pci.o obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o +i2c-apple-objs := i2c-pasemi-core.o i2c-pasemi-platform.o +obj-$(CONFIG_I2C_APPLE)+= i2c-apple.o obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o obj-$(CONFIG_I2C_PNX) += i2c-pnx.o obj-$(CONFIG_I2C_PXA) += i2c-pxa.o diff --git a/drivers/i2c/busses/i2c-pasemi-platform.c b/drivers/i2c/busses/i2c-pasemi-platform.c new file mode 100644 index ..88a54aaf7e3c --- /dev/null +++ b/drivers/i2c/busses/i2c-pasemi-platform.c @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2021 The Asahi Linux Contributors + * + * PA Semi PWRficient SMBus host driver for Apple SoCs + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "i2c-pasemi-core.h" + +struct pasemi_platform_i2c_data { + struct pasemi_smbus smbus; + struct clk *clk_ref; +}; + +static int +pasemi_platform_i2c_calc_clk_div(struct pasemi_platform_i2c_data *data, +u32 frequency) +{ + unsigned long clk_rate = clk_get_rate(data->clk_ref); + + if (!clk_rate) + return -EINVAL; + + data->smbus.clk_div = DIV_ROUND_UP(clk_rate, 16 * frequency); + if (data->smbus.clk_div < 4) + return dev_err_probe(data->smbus.dev, -EINVAL, +"Bus frequency %d is too fast.\n", +frequency); + if (data->smbus.clk_div > 0xff) + return dev_err_probe(data->smbus.dev, -EINVAL, +"Bus frequency %d is too slow.\n", +frequency); + + return 0; +} + +static int pasemi_platform_i2c_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct pasemi_platform_i2c_data *data; + struct pasemi_smbus *smbus; + u32 frequency; + int error; + + data = devm_kzalloc(dev, sizeof(struct pasemi_platform_i2c_data), + GFP_KERNEL); + if (!data) + return -ENOMEM; + + smbus = &data->smbus; + smbus->dev = dev; + + smbus->ioaddr = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(smbus->ioaddr)) + return PTR_ERR(smbus->ioaddr); + + if (of_property_read_u32(dev->of_node, "clock-frequency", &frequency)) + frequency = I2C_MAX_STANDARD_MODE_FREQ; + + data->clk_ref = devm_clk_get(dev, NULL); + if (IS_ERR(data->c
Re: Add Apple M1 support to PASemi i2c driver
Christian, Self-service available on lore: https://lore.kernel.org/all/20211008163532.75569-1-s...@svenpeter.dev/ There are links on there to download a whole thread as an mbox if needed. -Olof On Fri, Oct 8, 2021 at 1:20 PM Christian Zigotzky wrote: > > Hi Michael, > > Do you have a mbox link for the v2 changes? > > I would like to test them on my AmigaOne X1000. > > Thanks, > Christian > > On 27. Sep 2021, at 09:58, Michael Ellerman wrote: > > Christian, the whole series is downloadable as a single mbox here: > > https://patchwork.ozlabs.org/series/264134/mbox/ > > Save that to a file and apply with `git am`. > > eg: > > $ wget -O mbox https://patchwork.ozlabs.org/series/264134/mbox/ > $ git am mbox > > It applies cleanly on v5.15-rc3. > > cheers
Re: [PATCH v2 00/11] Add Apple M1 support to PASemi i2c driver
Hi, On Fri, Oct 8, 2021 at 9:36 AM Sven Peter wrote: > > Hi, > > v1: > https://lore.kernel.org/linux-i2c/20210926095847.38261-1-s...@svenpeter.dev/ > > Changes for v2: > - Added reviewed-by/acks > - Switched from ioport_map to pci_iomap as suggested by Arnd Bergmann > - Renamed i2c-pasemi-apple.c to i2c-pasemi-platform.c as suggested by >Wolfram Sang > - Replaced the ioport number in the adapter name with dev_name to be >able to identify separate busses in e.g. i2cdetect. > > I still don't have access to any old PASemi hardware but the changes from > v1 are pretty small and I expect them to still work. Would still be nice > if someone with access to such hardware could give this a quick test. > > > And for those who didn't see v1 the (almost) unchanged original cover letter: > > This series adds support for the I2C controller found on Apple Silicon Macs > which has quite a bit of history: > > Apple bought P.A. Semi in 2008 and it looks like a part of its legacy > continues > to live on in the M1. This controller has actually been used since at least > the > iPhone 4S and hasn't changed much since then. > Essentially, there are only a few differences that matter: > > - The controller no longer is a PCI device > - Starting at some iPhone an additional bit in one register > must be set in order to start transmissions. > - The reference clock and hence the clock dividers are different > > In order to add support for a platform device I first replaced PCI-specific > bits and split out the PCI driver to its own file. Then I added support > to make the clock divider configurable and converted the driver to use > managed device resources to make it a bit simpler. > > The Apple and PASemi driver will never be compiled in the same kernel > since the Apple one will run on arm64 while the original PASemi driver > will only be useful on powerpc. > I've thus followed the octeon (mips)/thunderx(arm64) approach to do the > split: I created a -core.c file which contains the shared logic and just > compile that one for both the PASemi and the new Apple driver. Series: Acked-by: Olof Johansson -Olof
Re: [PATCH] lkdtm: Fix content of section containing lkdtm_rodata_do_nothing()
On Fri, Oct 08, 2021 at 11:09:47AM -0700, Nick Desaulniers wrote: > On Fri, Oct 8, 2021 at 9:59 AM Christophe Leroy > wrote: > > > > On a kernel without CONFIG_STRICT_KERNEL_RWX, running EXEC_RODATA > > test leads to "Illegal instruction" failure. > > > > Looking at the content of rodata_objcopy.o, we see that the > > function content zeroes only: > > > > Disassembly of section .rodata: > > > > <.lkdtm_rodata_do_nothing>: > >0: 00 00 00 00 .long 0x0 > > > > Add the contents flag in order to keep the content of the section > > while renaming it. > > > > Disassembly of section .rodata: > > > > <.lkdtm_rodata_do_nothing>: > >0: 4e 80 00 20 blr > > > > Fixes: e9e08a07385e ("lkdtm: support llvm-objcopy") > > Thanks for the patch; sorry I broke this. > Reviewed-by: Nick Desaulniers Hah! Whoops; sorry I don't have an inverted version of this test! I should have caught this when it broke. :| -Kees -- Kees Cook
Re: [PATCH] lkdtm: Fix content of section containing lkdtm_rodata_do_nothing()
On Fri, 8 Oct 2021 18:58:40 +0200, Christophe Leroy wrote: > On a kernel without CONFIG_STRICT_KERNEL_RWX, running EXEC_RODATA > test leads to "Illegal instruction" failure. > > Looking at the content of rodata_objcopy.o, we see that the > function content zeroes only: > > Disassembly of section .rodata: > > [...] Applied to for-next/lkdtm, thanks! [1/1] lkdtm: Fix content of section containing lkdtm_rodata_do_nothing() https://git.kernel.org/kees/c/19c3069c5f5f Also, can you take a moment and get "patatt" set up[1] for signing your patches? I would appreciate that since b4 yells at me when patches aren't signed. :) -Kees [1] https://github.com/mricon/patatt -- Kees Cook
Re: [PATCH 1/5] dt-bindings: memory: fsl: convert ifc binding to yaml schema
On Mon, Oct 4, 2021 at 4:32 AM Krzysztof Kozlowski wrote: > > On 01/10/2021 18:17, Li Yang wrote: > > On Fri, Oct 1, 2021 at 5:01 AM Krzysztof Kozlowski > > wrote: > >> > > (...) > > >>> + > >>> + interrupts: > >>> +minItems: 1 > >>> +maxItems: 2 > >>> +description: | > >>> + IFC may have one or two interrupts. If two interrupt specifiers > >>> are > >>> + present, the first is the "common" interrupt (CM_EVTER_STAT), and > >>> the > >>> + second is the NAND interrupt (NAND_EVTER_STAT). If there is only > >>> one, > >>> + that interrupt reports both types of event. > >>> + > >>> + little-endian: > >>> +$ref: '/schemas/types.yaml#/definitions/flag' > >> > >> type: boolean > > > > It will not have a true or false value, but only present or not. Is > > the boolean type taking care of this too? > > boolean is for a property which does not accept values and true/false > depends on its presence. > See: > Documentation/devicetree/bindings/phy/lantiq,vrx200-pcie-phy.yaml > Documentation/devicetree/bindings/thermal/qoriq-thermal.yaml >From the dtschema/schemas/types.yaml file, flag type is defined as: flag: oneOf: - type: boolean const: true - type: 'null' It looks like more than the boolean type itself. But if the standard boolean type is actually the same as the flag type we defined. Shouldn't we remove the custom flag type then? Regards, Leo
Re: [PATCH] lkdtm: Fix content of section containing lkdtm_rodata_do_nothing()
On Fri, Oct 8, 2021 at 9:59 AM Christophe Leroy wrote: > > On a kernel without CONFIG_STRICT_KERNEL_RWX, running EXEC_RODATA > test leads to "Illegal instruction" failure. > > Looking at the content of rodata_objcopy.o, we see that the > function content zeroes only: > > Disassembly of section .rodata: > > <.lkdtm_rodata_do_nothing>: >0: 00 00 00 00 .long 0x0 > > Add the contents flag in order to keep the content of the section > while renaming it. > > Disassembly of section .rodata: > > <.lkdtm_rodata_do_nothing>: >0: 4e 80 00 20 blr > > Fixes: e9e08a07385e ("lkdtm: support llvm-objcopy") Thanks for the patch; sorry I broke this. Reviewed-by: Nick Desaulniers > Cc: sta...@vger.kernel.org > Cc: Kees Cook > Cc: Arnd Bergmann > Cc: Greg Kroah-Hartman > Cc: Nick Desaulniers > Cc: Nathan Chancellor > Signed-off-by: Christophe Leroy > --- > drivers/misc/lkdtm/Makefile | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile > index aa12097668d3..e2984ce51fe4 100644 > --- a/drivers/misc/lkdtm/Makefile > +++ b/drivers/misc/lkdtm/Makefile > @@ -20,7 +20,7 @@ CFLAGS_REMOVE_rodata.o+= $(CC_FLAGS_LTO) > > OBJCOPYFLAGS := > OBJCOPYFLAGS_rodata_objcopy.o := \ > - --rename-section > .noinstr.text=.rodata,alloc,readonly,load > + --rename-section > .noinstr.text=.rodata,alloc,readonly,load,contents > targets += rodata.o rodata_objcopy.o > $(obj)/rodata_objcopy.o: $(obj)/rodata.o FORCE > $(call if_changed,objcopy) > -- > 2.31.1 > -- Thanks, ~Nick Desaulniers
Re: [PATCH v3] PCI: Move pci_dev_is/assign_added() to pci.h
On Tue, Jul 20, 2021 at 05:01:45PM +0200, Niklas Schnelle wrote: > The helper function pci_dev_is_added() from drivers/pci/pci.h is used in > PCI arch code of both s390 and powerpc leading to awkward relative > includes. Move it to the global include/linux/pci.h and get rid of these > includes just for that one function. > > Signed-off-by: Niklas Schnelle > --- > Since v1 (and bad v2): > - Fixed accidental removal of PCI_DPC_RECOVERED, PCI_DPC_RECOVERING > defines and also move these to include/linux/pci.h > > arch/powerpc/platforms/powernv/pci-sriov.c | 3 --- > arch/powerpc/platforms/pseries/setup.c | 1 - > arch/s390/pci/pci_sysfs.c | 2 -- > drivers/pci/hotplug/acpiphp_glue.c | 1 - > drivers/pci/pci.h | 15 --- > include/linux/pci.h| 15 +++ > 6 files changed, 15 insertions(+), 22 deletions(-) I dropped this one because I think a subsequent patch removed the use in arch/powerpc, so if you still need this, it probably needs to be updated to at least drop those hunks.
Re: [PATCH 2/5] memory: fsl_ifc: populate child devices without relying on simple-bus
On Mon, Oct 4, 2021 at 12:14 PM Rob Herring wrote: > > On Thu, Sep 30, 2021 at 07:09:21PM -0500, Li Yang wrote: > > After we update the binding to not use simple-bus compatible for the > > controller, we need the driver to populate the child devices explicitly. > > > > Signed-off-by: Li Yang > > --- > > drivers/memory/fsl_ifc.c | 9 + > > 1 file changed, 9 insertions(+) > > > > diff --git a/drivers/memory/fsl_ifc.c b/drivers/memory/fsl_ifc.c > > index d062c2f8250f..251d713cd50b 100644 > > --- a/drivers/memory/fsl_ifc.c > > +++ b/drivers/memory/fsl_ifc.c > > @@ -88,6 +88,7 @@ static int fsl_ifc_ctrl_remove(struct platform_device > > *dev) > > { > > struct fsl_ifc_ctrl *ctrl = dev_get_drvdata(&dev->dev); > > > > + of_platform_depopulate(&dev->dev); > > free_irq(ctrl->nand_irq, ctrl); > > free_irq(ctrl->irq, ctrl); > > > > @@ -285,6 +286,14 @@ static int fsl_ifc_ctrl_probe(struct platform_device > > *dev) > > } > > } > > > > + /* legacy dts may still use "simple-bus" compatible */ > > + if (!of_device_is_compatible(dev->dev.of_node, "simple-bus")) { > > + ret = of_platform_populate(dev->dev.of_node, NULL, NULL, > > + &dev->dev); > > There's no need to make this conditional. of_platform_populate() is safe > to call multiple times. If that doesn't work, it's a bug. I think that it is probably an optimization to avoid re-populate the bus for legacy device trees. But it might be cleaner to just re-populate anyway? Regards, Leo
[powerpc:next-test] BUILD SUCCESS f9473a65719e59c45f1638cc04db7c80de8fcc1a
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next-test branch HEAD: f9473a65719e59c45f1638cc04db7c80de8fcc1a powerpc/pseries/cpuhp: remove obsolete comment from pseries_cpu_die elapsed time: 830m configs tested: 161 configs skipped: 4 The following configs have been built successfully. More configs may be tested in the coming days. gcc tested configs: arm defconfig arm64allyesconfig arm64 defconfig arm allyesconfig arm allmodconfig i386 randconfig-c001-20211008 s390 debug_defconfig pariscgeneric-32bit_defconfig m68k bvme6000_defconfig armhisi_defconfig shhp6xx_defconfig arc haps_hs_defconfig mipsmaltaup_xpa_defconfig mips rb532_defconfig riscv nommu_k210_sdcard_defconfig xtensa iss_defconfig powerpc mpc85xx_cds_defconfig powerpc akebono_defconfig mips cavium_octeon_defconfig sh rsk7269_defconfig sh alldefconfig armoxnas_v6_defconfig arm orion5x_defconfig m68k amcore_defconfig arm pxa255-idp_defconfig mipsgpr_defconfig mips rt305x_defconfig armzeus_defconfig arm socfpga_defconfig arm corgi_defconfig sh rsk7264_defconfig xtensaxip_kc705_defconfig nds32 allnoconfig powerpc mpc8560_ads_defconfig mips lemote2f_defconfig m68kstmark2_defconfig sh sdk7786_defconfig powerpc holly_defconfig arm am200epdkit_defconfig shmigor_defconfig powerpc pasemi_defconfig mips rbtx49xx_defconfig powerpc currituck_defconfig ia64 alldefconfig arm bcm2835_defconfig powerpc mpc832x_mds_defconfig armxcep_defconfig mips rs90_defconfig mipsbcm63xx_defconfig mipsmalta_qemu_32r6_defconfig powerpc g5_defconfig armkeystone_defconfig riscv defconfig mips tb0219_defconfig archsdk_defconfig shapsh4ad0a_defconfig mips decstation_64_defconfig shsh7785lcr_defconfig m68k apollo_defconfig openriscdefconfig powerpc arches_defconfig sh secureedge5410_defconfig m68kmac_defconfig xtensa common_defconfig powerpc lite5200b_defconfig powerpc cm5200_defconfig arm multi_v4t_defconfig armmulti_v7_defconfig powerpc mpc836x_rdk_defconfig xtensageneric_kc705_defconfig mips db1xxx_defconfig arm ep93xx_defconfig powerpc microwatt_defconfig arm u8500_defconfig h8300h8300h-sim_defconfig arm viper_defconfig mips decstation_r4k_defconfig powerpc mpc837x_rdb_defconfig arm s3c6400_defconfig armrealview_defconfig powerpc tqm8560_defconfig x86_64 randconfig-c001-20211008 arm randconfig-c002-20211008 ia64 allmodconfig ia64defconfig ia64 allyesconfig m68k allmodconfig m68kdefconfig m68k allyesconfig nios2 defconfig arc allyesconfig nds32 defconfig nios2allyesconfig cskydefconfig alpha defconfig alphaallyesconfig xtensa allyesconfig h8300allyesconfig arc defconfig sh allmodconfig
[PATCH] powerpc/eeh: Fix docstrings in eeh.c
We fix the following warnings when building kernel with W=1: arch/powerpc/kernel/eeh.c:598: warning: Function parameter or member 'function' not described in 'eeh_pci_enable' arch/powerpc/kernel/eeh.c:774: warning: Function parameter or member 'edev' not described in 'eeh_set_dev_freset' arch/powerpc/kernel/eeh.c:774: warning: expecting prototype for eeh_set_pe_freset(). Prototype was for eeh_set_dev_freset() instead arch/powerpc/kernel/eeh.c:814: warning: Function parameter or member 'include_passed' not described in 'eeh_pe_reset_full' arch/powerpc/kernel/eeh.c:944: warning: Function parameter or member 'ops' not described in 'eeh_init' arch/powerpc/kernel/eeh.c:1451: warning: Function parameter or member 'include_passed' not described in 'eeh_pe_reset' arch/powerpc/kernel/eeh.c:1526: warning: Function parameter or member 'func' not described in 'eeh_pe_inject_err' arch/powerpc/kernel/eeh.c:1526: warning: Excess function parameter 'function' described in 'eeh_pe_inject_err' Signed-off-by: Kai Song Reviewed-by: Daniel Axtens --- arch/powerpc/kernel/eeh.c | 12 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c index e9b597ed423c..91e0f4cf1db3 100644 --- a/arch/powerpc/kernel/eeh.c +++ b/arch/powerpc/kernel/eeh.c @@ -589,6 +589,7 @@ EXPORT_SYMBOL(eeh_check_failure); /** * eeh_pci_enable - Enable MMIO or DMA transfers for this slot * @pe: EEH PE + * @function: EEH option * * This routine should be called to reenable frozen MMIO or DMA * so that it would work correctly again. It's useful while doing @@ -761,8 +762,8 @@ int pcibios_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state stat } /** - * eeh_set_pe_freset - Check the required reset for the indicated device - * @data: EEH device + * eeh_set_dev_freset - Check the required reset for the indicated device + * @edev: EEH device * @flag: return value * * Each device might have its preferred reset type: fundamental or @@ -801,6 +802,7 @@ static void eeh_pe_refreeze_passed(struct eeh_pe *root) /** * eeh_pe_reset_full - Complete a full reset process on the indicated PE * @pe: EEH PE + * @include_passed: include passed-through devices? * * This function executes a full reset procedure on a PE, including setting * the appropriate flags, performing a fundamental or hot reset, and then @@ -937,6 +939,7 @@ static struct notifier_block eeh_device_nb = { /** * eeh_init - System wide EEH initialization + * @ops: struct to trace EEH operation callback functions * * It's the platform's job to call this from an arch_initcall(). */ @@ -1442,6 +1445,7 @@ static int eeh_pe_reenable_devices(struct eeh_pe *pe, bool include_passed) * eeh_pe_reset - Issue PE reset according to specified type * @pe: EEH PE * @option: reset type + * @include_passed: include passed-through devices? * * The routine is called to reset the specified PE with the * indicated type, either fundamental reset or hot reset. @@ -1513,12 +1517,12 @@ EXPORT_SYMBOL_GPL(eeh_pe_configure); * eeh_pe_inject_err - Injecting the specified PCI error to the indicated PE * @pe: the indicated PE * @type: error type - * @function: error function + * @func: error function * @addr: address * @mask: address mask * * The routine is called to inject the specified PCI error, which - * is determined by @type and @function, to the indicated PE for + * is determined by @type and @func, to the indicated PE for * testing purpose. */ int eeh_pe_inject_err(struct eeh_pe *pe, int type, int func, -- 2.27.0
Re: [PATCH] perf vendor events power10: Add metric events json file for power10 platform
On 06/10/2021 08:31, Kajol Jain wrote: > Add pmu metric json file for power10 platform. > > Signed-off-by: Kajol Jain > --- > .../arch/powerpc/power10/metrics.json | 772 ++ I checked this with the new strict JSON parser from "[PATCH 0/3] perf tools: Enable strict JSON parsing" and it seemed fine from that point of view. James
[PATCH 0/2] sched: cleanup CONFIG_SCHED_MC & friends
Hi folks, This stems from Barry introducing a new CONFIG_SCHED_CLUSTER which highlighted the current state of similar Kconfigs isn't great: http://lore.kernel.org/r/cagsj_4xzd0sg0df666f0bvhozupmjnw0dn_marer5k1pj6l...@mail.gmail.com The changes happen all in one big patch; the alternative would be to have one patch per arch that adds the ARCH_SUPPORTS_SCHED_* selection, then a final patch that adds the generic definitions and removes the arch ones (which I can do if that's a preferred approach). Briefly tested by setting ARCH=foo and playing around with menuconfig. Based on top of Peter's queue: git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git -b sched/next Patches are also available at: https://git.gitlab.arm.com/linux-arm/linux-vs.git -b mainline/sched/topo_kconfig_cleanup Cheers, Valentin Valentin Schneider (2): sched: Move Kconfig.preempt to sched/Kconfig sched: Centralize SCHED_{SMT, MC, CLUSTER} definitions arch/arm/Kconfig | 18 ++ arch/arm64/Kconfig| 26 ++ arch/ia64/Kconfig | 9 + arch/mips/Kconfig | 10 +- arch/parisc/Kconfig | 9 + arch/powerpc/Kconfig | 9 + arch/s390/Kconfig | 8 ++--- arch/sh/Kconfig | 1 + arch/sh/mm/Kconfig| 9 - arch/sparc/Kconfig| 20 ++- arch/x86/Kconfig | 26 ++ init/Kconfig | 2 +- kernel/{Kconfig.preempt => sched/Kconfig} | 41 +++ 13 files changed, 59 insertions(+), 129 deletions(-) rename kernel/{Kconfig.preempt => sched/Kconfig} (79%) -- 2.25.1
[PATCH 1/2] sched: Move Kconfig.preempt to sched/Kconfig
Kconfig.preempt already contains more than just preemption configs (see CONFIG_SCHED_CORE), and a subsequent patch will introduce more scheduler-specific configs. Move the file to the scheduler directory. Suggested-by: Peter Zijlstra Signed-off-by: Valentin Schneider --- init/Kconfig | 2 +- kernel/{Kconfig.preempt => sched/Kconfig} | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) rename kernel/{Kconfig.preempt => sched/Kconfig} (99%) diff --git a/init/Kconfig b/init/Kconfig index 11f8a845f259..4caedc821b06 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -460,7 +460,7 @@ config AUDITSYSCALL source "kernel/irq/Kconfig" source "kernel/time/Kconfig" source "kernel/bpf/Kconfig" -source "kernel/Kconfig.preempt" +source "kernel/sched/Kconfig" menu "CPU/Task time and stats accounting" diff --git a/kernel/Kconfig.preempt b/kernel/sched/Kconfig similarity index 99% rename from kernel/Kconfig.preempt rename to kernel/sched/Kconfig index 60f1bfc3c7b2..c8b8e12c9c9c 100644 --- a/kernel/Kconfig.preempt +++ b/kernel/sched/Kconfig @@ -131,5 +131,3 @@ config SCHED_CORE SCHED_CORE is default disabled. When it is enabled and unused, which is the likely usage by Linux distributions, there should be no measurable impact on performance. - - -- 2.25.1
[PATCH 2/2] sched: Centralize SCHED_{SMT, MC, CLUSTER} definitions
Barry recently introduced a new CONFIG_SCHED_CLUSTER, and discussions around that highlighted that every architecture redefines its own help text and dependencies for CONFIG_SCHED_SMT and CONFIG_SCHED_MC. Move the definition of those to scheduler's Kconfig to centralize help text and generic dependencies (i.e. SMP). Make them depend on a matching ARCH_SUPPORTS_SCHED_* which the architectures can select with the relevant architecture-specific dependency. s390 uses its own topology table (set_sched_topology()) and doesn't seem to cope without SCHED_MC or SCHED_SMT, so those remain untogglable. Suggested-by: Barry Song <21cn...@gmail.com> Signed-off-by: Valentin Schneider --- arch/arm/Kconfig | 18 ++ arch/arm64/Kconfig | 26 +++--- arch/ia64/Kconfig| 9 + arch/mips/Kconfig| 10 +- arch/parisc/Kconfig | 9 + arch/powerpc/Kconfig | 9 + arch/s390/Kconfig| 8 ++-- arch/sh/Kconfig | 1 + arch/sh/mm/Kconfig | 9 - arch/sparc/Kconfig | 20 ++-- arch/x86/Kconfig | 26 +++--- kernel/sched/Kconfig | 43 +++ 12 files changed, 60 insertions(+), 128 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index fc196421b2ce..13aac98edf06 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -32,6 +32,8 @@ config ARM select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7 select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_HUGETLBFS if ARM_LPAE + select ARCH_SUPPORTS_SCHED_SMT if ARM_CPU_TOPOLOGY + select ARCH_SUPPORTS_SCHED_MC if ARM_CPU_TOPOLOGY select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF select ARCH_USE_MEMTEST @@ -1166,22 +1168,6 @@ config ARM_CPU_TOPOLOGY affinity between processors which is then used to describe the cpu topology of an ARM System. -config SCHED_MC - bool "Multi-core scheduler support" - depends on ARM_CPU_TOPOLOGY - help - Multi-core scheduler support improves the CPU scheduler's decision - making when dealing with multi-core CPU chips at a cost of slightly - increased overhead in some places. If unsure say N here. - -config SCHED_SMT - bool "SMT scheduler support" - depends on ARM_CPU_TOPOLOGY - help - Improves the CPU scheduler's decision making when dealing with - MultiThreading at a cost of slightly increased overhead in some - places. If unsure say N here. - config HAVE_ARM_SCU bool help diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index d13677f4731d..8a49dd33f5e3 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -88,6 +88,9 @@ config ARM64 select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_SUPPORTS_NUMA_BALANCING + select ARCH_SUPPORTS_SCHED_SMT + select ARCH_SUPPORTS_SCHED_MC + select ARCH_SUPPORTS_SCHED_CLUSTER select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT select ARCH_WANT_DEFAULT_BPF_JIT select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT @@ -982,29 +985,6 @@ config CPU_LITTLE_ENDIAN endchoice -config SCHED_MC - bool "Multi-core scheduler support" - help - Multi-core scheduler support improves the CPU scheduler's decision - making when dealing with multi-core CPU chips at a cost of slightly - increased overhead in some places. If unsure say N here. - -config SCHED_CLUSTER - bool "Cluster scheduler support" - help - Cluster scheduler support improves the CPU scheduler's decision - making when dealing with machines that have clusters of CPUs. - Cluster usually means a couple of CPUs which are placed closely - by sharing mid-level caches, last-level cache tags or internal - busses. - -config SCHED_SMT - bool "SMT scheduler support" - help - Improves the CPU scheduler's decision making when dealing with - MultiThreading at a cost of slightly increased overhead in some - places. If unsure say N here. - config NR_CPUS int "Maximum number of CPUs (2-4096)" range 2 4096 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig index 045792cde481..67f3d84242ae 100644 --- a/arch/ia64/Kconfig +++ b/arch/ia64/Kconfig @@ -18,6 +18,7 @@ config IA64 select ARCH_ENABLE_MEMORY_HOTPLUG select ARCH_ENABLE_MEMORY_HOTREMOVE select ARCH_SUPPORTS_ACPI + select ARCH_SUPPORTS_SCHED_SMT select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI select FORCE_PCI @@ -247,14 +248,6 @@ config HOTPLUG_CPU can be controlled through /sys/devices/system/cpu/cpu#. Say N if you want to disable CPU hotplug. -config SCHED_SMT - bool "SMT scheduler support" - depe
Re: [PATCH 2/2] sched: Centralize SCHED_{SMT, MC, CLUSTER} definitions
On Sat, Oct 9, 2021 at 12:54 AM Valentin Schneider wrote: > > Barry recently introduced a new CONFIG_SCHED_CLUSTER, and discussions > around that highlighted that every architecture redefines its own help text > and dependencies for CONFIG_SCHED_SMT and CONFIG_SCHED_MC. > > Move the definition of those to scheduler's Kconfig to centralize help text > and generic dependencies (i.e. SMP). Make them depend on a matching > ARCH_SUPPORTS_SCHED_* which the architectures can select with the relevant > architecture-specific dependency. > > s390 uses its own topology table (set_sched_topology()) and doesn't seem to > cope without SCHED_MC or SCHED_SMT, so those remain untogglable. > Hi Valentin, Thanks! I believe this is a cleaner way for Kconfig itself. But I am not quite sure this is always beneficial of all platforms. It would be perfect if the patch has no side effects and doesn't change the existing behaviour. But it has side effects by changing the default N to Y on a couple of platforms. > Suggested-by: Barry Song <21cn...@gmail.com> > Signed-off-by: Valentin Schneider > --- > arch/arm/Kconfig | 18 ++ > arch/arm64/Kconfig | 26 +++--- > arch/ia64/Kconfig| 9 + > arch/mips/Kconfig| 10 +- > arch/parisc/Kconfig | 9 + > arch/powerpc/Kconfig | 9 + > arch/s390/Kconfig| 8 ++-- > arch/sh/Kconfig | 1 + > arch/sh/mm/Kconfig | 9 - > arch/sparc/Kconfig | 20 ++-- > arch/x86/Kconfig | 26 +++--- > kernel/sched/Kconfig | 43 +++ > 12 files changed, 60 insertions(+), 128 deletions(-) > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig > index fc196421b2ce..13aac98edf06 100644 > --- a/arch/arm/Kconfig > +++ b/arch/arm/Kconfig > @@ -32,6 +32,8 @@ config ARM > select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7 > select ARCH_SUPPORTS_ATOMIC_RMW > select ARCH_SUPPORTS_HUGETLBFS if ARM_LPAE > + select ARCH_SUPPORTS_SCHED_SMT if ARM_CPU_TOPOLOGY > + select ARCH_SUPPORTS_SCHED_MC if ARM_CPU_TOPOLOGY > select ARCH_USE_BUILTIN_BSWAP > select ARCH_USE_CMPXCHG_LOCKREF > select ARCH_USE_MEMTEST > @@ -1166,22 +1168,6 @@ config ARM_CPU_TOPOLOGY > affinity between processors which is then used to describe the cpu > topology of an ARM System. > > -config SCHED_MC > - bool "Multi-core scheduler support" > - depends on ARM_CPU_TOPOLOGY > - help > - Multi-core scheduler support improves the CPU scheduler's decision > - making when dealing with multi-core CPU chips at a cost of slightly > - increased overhead in some places. If unsure say N here. > - > -config SCHED_SMT > - bool "SMT scheduler support" > - depends on ARM_CPU_TOPOLOGY > - help > - Improves the CPU scheduler's decision making when dealing with > - MultiThreading at a cost of slightly increased overhead in some > - places. If unsure say N here. > - > config HAVE_ARM_SCU > bool > help > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index d13677f4731d..8a49dd33f5e3 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -88,6 +88,9 @@ config ARM64 > select ARCH_SUPPORTS_ATOMIC_RMW > select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 > select ARCH_SUPPORTS_NUMA_BALANCING > + select ARCH_SUPPORTS_SCHED_SMT > + select ARCH_SUPPORTS_SCHED_MC > + select ARCH_SUPPORTS_SCHED_CLUSTER > select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT > select ARCH_WANT_DEFAULT_BPF_JIT > select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT > @@ -982,29 +985,6 @@ config CPU_LITTLE_ENDIAN > > endchoice > > -config SCHED_MC > - bool "Multi-core scheduler support" > - help > - Multi-core scheduler support improves the CPU scheduler's decision > - making when dealing with multi-core CPU chips at a cost of slightly > - increased overhead in some places. If unsure say N here. > - > -config SCHED_CLUSTER > - bool "Cluster scheduler support" > - help > - Cluster scheduler support improves the CPU scheduler's decision > - making when dealing with machines that have clusters of CPUs. > - Cluster usually means a couple of CPUs which are placed closely > - by sharing mid-level caches, last-level cache tags or internal > - busses. > - > -config SCHED_SMT > - bool "SMT scheduler support" > - help > - Improves the CPU scheduler's decision making when dealing with > - MultiThreading at a cost of slightly increased overhead in some > - places. If unsure say N here. > - > config NR_CPUS > int "Maximum number of CPUs (2-4096)" > range 2 4096 > diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig > index 045792cde481..67f3d84242ae 100644
Re: [PATCH 2/2] sched: Centralize SCHED_{SMT, MC, CLUSTER} definitions
On 09/10/21 01:37, Barry Song wrote: > On Sat, Oct 9, 2021 at 12:54 AM Valentin Schneider > wrote: >> >> Barry recently introduced a new CONFIG_SCHED_CLUSTER, and discussions >> around that highlighted that every architecture redefines its own help text >> and dependencies for CONFIG_SCHED_SMT and CONFIG_SCHED_MC. >> >> Move the definition of those to scheduler's Kconfig to centralize help text >> and generic dependencies (i.e. SMP). Make them depend on a matching >> ARCH_SUPPORTS_SCHED_* which the architectures can select with the relevant >> architecture-specific dependency. >> >> s390 uses its own topology table (set_sched_topology()) and doesn't seem to >> cope without SCHED_MC or SCHED_SMT, so those remain untogglable. >> > > Hi Valentin, > Thanks! > I believe this is a cleaner way for Kconfig itself. But I am not quite sure > this > is always beneficial of all platforms. It would be perfect if the patch has no > side effects and doesn't change the existing behaviour. But it has side > effects > by changing the default N to Y on a couple of platforms. > So x86 has it default yes, and a lot of others (e.g. arm64) have it default no. IMO you don't gain much by disabling them. SCHED_MC and SCHED_CLUSTER only control the presence of a sched_domain_topology_level - if it's useless it gets degenerated at domain build time. Some valid reasons for not using them is if the architecture defines its own topology table (e.g. powerpc has CACHE and MC levels which are not gated behind any CONFIG). SCHED_SMT has an impact on code generated in sched/core.c, but that is also gated by a static key. So I'd say having them default yes is sensible. I'd even say we should change the "If unsure say N here." to "Y".
Re: Add Apple M1 support to PASemi i2c driver
Olof, Thank you for the hint. I think I have found them. Link: https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=266104 Mbox: https://patchwork.ozlabs.org/series/266104/mbox/ $ wget -O mbox https://patchwork.ozlabs.org/series/266104/mbox/ $ git am mbox Thanks, Christian On 8. Oct 2021, at 22:47, Olof Johansson wrote: Christian, Self-service available on lore: https://lore.kernel.org/all/20211008163532.75569-1-s...@svenpeter.dev/ There are links on there to download a whole thread as an mbox if needed. -Olof On Fri, Oct 8, 2021 at 1:20 PM Christian Zigotzky wrote: Hi Michael, Do you have a mbox link for the v2 changes? I would like to test them on my AmigaOne X1000. Thanks, Christian On 27. Sep 2021, at 09:58, Michael Ellerman wrote: Christian, the whole series is downloadable as a single mbox here: https://patchwork.ozlabs.org/series/264134/mbox/ Save that to a file and apply with `git am`. eg: $ wget -O mbox https://patchwork.ozlabs.org/series/264134/mbox/ $ git am mbox It applies cleanly on v5.15-rc3. cheers