Re: [PATCH v1 0/2] Fix console probe delay when stdout-path isn't set

2022-06-28 Thread Fabio Estevam
we...@gmail.com>, ulf hansson , Neil Armstrong 
, Lorenzo Pieralisi , Al Cooper 
, linux-te...@vger.kernel.org, Jiri Slaby 
, linux-asp...@lists.ozlabs.org, Rob Herring 
, Florian Fainelli , Mateusz Holenko 
, Alexander Shiyan , kevin hilman 
, Broadcom internal kernel review list 
, Joel Stanley , Orson 
Zhai , paolo abeni , Patrice Chotard 
, Ray Jui , Vladimir Zapolskiy 
, linux-snps-...@lists.infradead.org, Timur Tabi 
, hideaki yoshifuji , 
io...@lists.linux-foundation.org, Laxman Dewangan , 
Sudeep Holla , Baolin Wang , Shawn Guo , "David S. Miller" , 
Baruch Siach , Liviu Dudau , Alexandre 
Torgue , Bjorn Andersson 
, Paul Cercueil , 
sparcli...@vger.kernel.org, linux-ri...@lists.infradead.org, joerg roedel 
, Russell King , Andy Gross 
, linux-ser...@vger.kernel.org, jakub kicinski 
, will deacon , Manivannan Sadhasivam 
, linux-media...@lists.infradead.org, Paul Walmsley 
, Matthias Brugger , Andy 
Shevchenko , Laurentiu Tudor 
, Taichi Sugaya , netdev 
, david ahern , Nicolas Ferre 
, Krzysztof Kozlowski , Palmer Dabbelt , Takao 
Orito , linuxppc-dev 
Errors-To: linuxppc-dev-bounces+archive=mail-archive@lists.ozlabs.org
Sender: "Linuxppc-dev" 


Hi Saravana,

On Mon, Jun 27, 2022 at 11:03 PM Saravana Kannan  wrote:
>
> Since the series that fixes console probe delay based on stdout-path[1] got
> pulled into driver-core-next, I made these patches on top of them.
>
> Even if stdout-path isn't set in DT, this patch should take console
> probe times back to how they were before the deferred_probe_timeout
> clean up series[2].
>
> Fabio/Ahmad/Sascha,
>
> Can you give this a shot please?

This series works fine for me (with and without stdout-path), thanks:

Tested-by: Fabio Estevam 


Re: [PATCH RESEND v5 15/18] PCI: dwc: Add dw_ prefix to the pcie_port structure name

2022-06-28 Thread Manivannan Sadhasivam
arbanov , Krzysztof Kozlowski 
, Masami Hiramatsu , 
Pengutronix Kernel Team , Gustavo Pimentel 
, Shawn Guo , Lucas Stach 

Errors-To: linuxppc-dev-bounces+archive=mail-archive@lists.ozlabs.org
Sender: "Linuxppc-dev" 


On Fri, Jun 24, 2022 at 05:34:25PM +0300, Serge Semin wrote:
> All of the DW PCIe core driver entities have names with the dw_ prefix in
> order to easily distinguish local and common PCIe name spaces. All except
> the pcie_port structure which contains the DW PCIe Root Port descriptor.
> For historical reason the structure has retained the original name since
> commit 340cba6092c2 ("pci: Add PCIe driver for Samsung Exynos") when
> the DW PCIe IP-core support was added to the kernel. Let's finally fix
> that by adding the dw_ prefix to the structure name and by adding the _rp
> suffix to be similar to the EP counterpart. Thus the name will be coherent
> with the common driver naming policy. It shall make the driver code more
> readable eliminating visual confusion between the local and generic PCI
> name spaces.
> 
> Signed-off-by: Serge Semin 

Reviewed-by: Manivannan Sadhasivam 

Thanks,
Mani

> Reviewed-by: Rob Herring 
> 
> ---
> 
> Changelog v4:
> - This is a new patch created on the v4 lap of the series.
> ---
>  drivers/pci/controller/dwc/pci-dra7xx.c   | 12 +++
>  drivers/pci/controller/dwc/pci-exynos.c   |  6 ++--
>  drivers/pci/controller/dwc/pci-imx6.c |  6 ++--
>  drivers/pci/controller/dwc/pci-keystone.c | 20 +--
>  drivers/pci/controller/dwc/pci-layerscape.c   |  2 +-
>  drivers/pci/controller/dwc/pci-meson.c|  2 +-
>  drivers/pci/controller/dwc/pcie-al.c  |  6 ++--
>  drivers/pci/controller/dwc/pcie-armada8k.c|  4 +--
>  drivers/pci/controller/dwc/pcie-artpec6.c |  4 +--
>  .../pci/controller/dwc/pcie-designware-host.c | 36 +--
>  .../pci/controller/dwc/pcie-designware-plat.c |  2 +-
>  drivers/pci/controller/dwc/pcie-designware.h  | 30 
>  drivers/pci/controller/dwc/pcie-dw-rockchip.c |  4 +--
>  drivers/pci/controller/dwc/pcie-fu740.c   |  2 +-
>  drivers/pci/controller/dwc/pcie-histb.c   | 10 +++---
>  drivers/pci/controller/dwc/pcie-intel-gw.c|  6 ++--
>  drivers/pci/controller/dwc/pcie-keembay.c |  4 +--
>  drivers/pci/controller/dwc/pcie-kirin.c   |  2 +-
>  drivers/pci/controller/dwc/pcie-qcom.c|  4 +--
>  drivers/pci/controller/dwc/pcie-spear13xx.c   |  6 ++--
>  drivers/pci/controller/dwc/pcie-tegra194.c| 22 ++--
>  drivers/pci/controller/dwc/pcie-uniphier.c| 10 +++---
>  drivers/pci/controller/dwc/pcie-visconti.c|  6 ++--
>  23 files changed, 103 insertions(+), 103 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c 
> b/drivers/pci/controller/dwc/pci-dra7xx.c
> index dfcdeb432dc8..a174b680b2a7 100644
> --- a/drivers/pci/controller/dwc/pci-dra7xx.c
> +++ b/drivers/pci/controller/dwc/pci-dra7xx.c
> @@ -178,7 +178,7 @@ static void dra7xx_pcie_enable_interrupts(struct 
> dra7xx_pcie *dra7xx)
>   dra7xx_pcie_enable_msi_interrupts(dra7xx);
>  }
>  
> -static int dra7xx_pcie_host_init(struct pcie_port *pp)
> +static int dra7xx_pcie_host_init(struct dw_pcie_rp *pp)
>  {
>   struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
>   struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
> @@ -202,7 +202,7 @@ static const struct irq_domain_ops intx_domain_ops = {
>   .xlate = pci_irqd_intx_xlate,
>  };
>  
> -static int dra7xx_pcie_handle_msi(struct pcie_port *pp, int index)
> +static int dra7xx_pcie_handle_msi(struct dw_pcie_rp *pp, int index)
>  {
>   struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
>   unsigned long val;
> @@ -224,7 +224,7 @@ static int dra7xx_pcie_handle_msi(struct pcie_port *pp, 
> int index)
>   return 1;
>  }
>  
> -static void dra7xx_pcie_handle_msi_irq(struct pcie_port *pp)
> +static void dra7xx_pcie_handle_msi_irq(struct dw_pcie_rp *pp)
>  {
>   struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
>   int ret, i, count, num_ctrls;
> @@ -255,8 +255,8 @@ static void dra7xx_pcie_msi_irq_handler(struct irq_desc 
> *desc)
>  {
>   struct irq_chip *chip = irq_desc_get_chip(desc);
>   struct dra7xx_pcie *dra7xx;
> + struct dw_pcie_rp *pp;
>   struct dw_pcie *pci;
> - struct pcie_port *pp;
>   unsigned long reg;
>   u32 bit;
>  
> @@ -344,7 +344,7 @@ static irqreturn_t dra7xx_pcie_irq_handler(int irq, void 
> *arg)
>   return IRQ_HANDLED;
>  }
>  
> -static int dra7xx_pcie_init_irq_domain(struct pcie_port *pp)
> +static int dra7xx_pcie_init_irq_domain(struct dw_pcie_rp *pp)
>  {
>   struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
>   struct device *dev = pci->dev;
> @@ -475,7 +475,7 @@ static int dra7xx_add_pcie_port(struct dra7xx_pcie 
> *dra7xx,
>  {
>   int ret;
>   struct dw_pcie *pci = dra7xx->pci;
> - struct pcie_port *pp = &pci->pp;
> + struct dw_pcie_rp *pp = &pci->pp;
>   struct device *dev = pci->dev;
>  
>   pp->irq

Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Arnd Bergmann
On Tue, Jun 28, 2022 at 5:25 AM Michael Schmitz  wrote:
> Am 28.06.2022 um 09:12 schrieb Michael Schmitz:
>
> Leaving the bounce buffer handling in place, and taking a few other
> liberties - this is what converting the easiest case (a3000 SCSI) might
> look like. Any obvious mistakes? The mvme147 driver would be very
> similar to handle (after conversion to a platform device).
>
> The driver allocates bounce buffers using kmalloc if it hits an
> unaligned data buffer - can such buffers still even happen these days?
> If I understand dma_map_single() correctly, the resulting dma handle
> would be equally misaligned?
>
> To allocate a bounce buffer, would it be OK to use dma_alloc_coherent()
> even though AFAIU memory used for DMA buffers generally isn't consistent
> on m68k?

I think it makes sense to skip the bounce buffering as you do here:
the only standardized way we have for integrating that part is to
use the swiotlb infrastructure, but as you mentioned earlier that
part is probably too resource-heavy here for Amiga.

I see two other problems with your patch though:

a) you still duplicate the cache handling: the cache_clear()/cache_push()
is supposed to already be done by dma_map_single() when the device
is not cache-coherent.

b) The bounce buffer is never mapped here, instead you have the
virt_to_phys() here, which is not the same. I think you need to map
the pointer that actually gets passed down to the device after deciding
to use a bouce buffer or not.

 Arnd


Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Geert Uytterhoeven
Hi Michael,

On Tue, Jun 28, 2022 at 5:26 AM Michael Schmitz  wrote:
> Am 28.06.2022 um 09:12 schrieb Michael Schmitz:
> > On 27/06/22 20:26, Geert Uytterhoeven wrote:
> >> On Sat, Jun 18, 2022 at 3:06 AM Michael Schmitz 
> >> wrote:
> >>> Am 18.06.2022 um 00:57 schrieb Arnd Bergmann:
>  From: Arnd Bergmann 
> 
>  All architecture-independent users of virt_to_bus() and bus_to_virt()
>  have been fixed to use the dma mapping interfaces or have been
>  removed now.  This means the definitions on most architectures, and the
>  CONFIG_VIRT_TO_BUS symbol are now obsolete and can be removed.
> 
>  The only exceptions to this are a few network and scsi drivers for m68k
>  Amiga and VME machines and ppc32 Macintosh. These drivers work
>  correctly
>  with the old interfaces and are probably not worth changing.
> >>> The Amiga SCSI drivers are all old WD33C93 ones, and replacing
> >>> virt_to_bus by virt_to_phys in the dma_setup() function there would
> >>> cause no functional change at all.
> >> FTR, the sgiwd93 driver use dma_map_single().
> >
> > Thanks! From what I see, it doesn't have to deal with bounce buffers
> > though?
>
> Leaving the bounce buffer handling in place, and taking a few other
> liberties - this is what converting the easiest case (a3000 SCSI) might
> look like. Any obvious mistakes? The mvme147 driver would be very
> similar to handle (after conversion to a platform device).

Thanks, looks reasonable.

> The driver allocates bounce buffers using kmalloc if it hits an
> unaligned data buffer - can such buffers still even happen these days?

No idea.

> If I understand dma_map_single() correctly, the resulting dma handle
> would be equally misaligned?
>
> To allocate a bounce buffer, would it be OK to use dma_alloc_coherent()
> even though AFAIU memory used for DMA buffers generally isn't consistent
> on m68k?
>
> Thinking ahead to the other two Amiga drivers - I wonder whether
> allocating a static bounce buffer or a DMA pool at driver init is likely
> to succeed if the kernel runs from the low 16 MB RAM chunk? It certainly
> won't succeed if the kernel runs from a higher memory address, so the
> present bounce buffer logic around amiga_chip_alloc() might still need
> to be used here.
>
> Leaves the question whether converting the gvp11 and a2091 drivers is
> actually worth it, if bounce buffers still have to be handled explicitly.

A2091 should be straight-forward, as A3000 is basically A2091 on the
motherboard (comparing the two drivers, looks like someone's been
sprinkling mb()s over the A3000 driver).

I don't have any of these SCSI host adapters (not counting the A590
(~A2091) expansion of the old A500, which is not Linux-capable, and
 hasn't been powered on for 20 years).

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


[PATCH kernel] KVM: PPC: Do not warn when userspace asked for too big TCE table

2022-06-28 Thread Alexey Kardashevskiy
KVM manages emulated TCE tables for guest LIOBNs by a two level table
which maps up to 128TiB with 16MB IOMMU pages (enabled in QEMU by default)
and MAX_ORDER=11 (the kernel's default). Note that the last level of
the table is allocated when actual TCE is updated.

However these tables are created via ioctl() on kvmfd and the userspace
can trigger WARN_ON_ONCE_GFP(order >= MAX_ORDER, gfp) in mm/page_alloc.c
and flood dmesg.

This adds __GFP_NOWARN.

Signed-off-by: Alexey Kardashevskiy 
---

We could probably switch to vmalloc() to allow even bigger
emulated tables which we do not really want the userspace
to create though.

---
 arch/powerpc/kvm/book3s_64_vio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index d6589c4fe889..40864373ef87 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -307,7 +307,7 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
return ret;
 
ret = -ENOMEM;
-   stt = kzalloc(struct_size(stt, pages, npages), GFP_KERNEL);
+   stt = kzalloc(struct_size(stt, pages, npages), GFP_KERNEL | 
__GFP_NOWARN);
if (!stt)
goto fail_acct;
 
-- 
2.30.2



Re: [PATCH -next v6 02/10] arm64: asm-extable: move data fields

2022-06-28 Thread Will Deacon
On Tue, Jun 21, 2022 at 07:26:30AM +, Tong Tiangen wrote:
> In subsequent patches we'll need to fill in extable data fields in
> regular assembly files. In preparation for this, move the definitions of
> the extable data fields earlier in asm-extable.h so that they are
> defined for both assembly and C files.
> 
> There should be no functional change as a result of this patch.
> 
> Signed-off-by: Mark Rutland 
> Signed-off-by: Tong Tiangen 
> ---
>  arch/arm64/include/asm/asm-extable.h | 22 --
>  1 file changed, 12 insertions(+), 10 deletions(-)

This (and the following) patch should retain Mark's authorship information
as they are taken from his git tree:

https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=arm64/extable/asm-uaccess

I plan to apply the first six patches for now, so I'll fix that up at the
same time.

Will


Re: [PATCH v3 0/3] phase out CONFIG_VIRT_TO_BUS

2022-06-28 Thread Arnd Bergmann
On Tue, Jun 28, 2022 at 4:59 AM Martin K. Petersen
 wrote:
> Hi Arnd!
>
> > If there are no more issues identified with this series, I'll merge it
> > through the asm-generic tree. The SCSI patches can also get merged
> > separately through the SCSI maintainers' tree if they prefer.
>
> I put patches 1 and 2 in scsi-staging to see if anything breaks...

Ok, thanks!

I have just the third patch in the asm-generic tree now. As long as it all
make it into the merge window, this should work out fine without build
issues, though there is a small bisection window during which the buslogic
driver becomes hidden. I think that's ok here.

   Arnd


Re: [PATCH V2] powerpc/memhotplug: Add add_pages override for PPC

2022-06-28 Thread Michael Ellerman
"Aneesh Kumar K.V"  writes:
> With commit ffa0b64e3be5 ("powerpc: Fix virt_addr_valid() for 64-bit Book3E & 
> 32-bit")
> the kernel now validate the addr against high_memory value. This results
> in the below BUG_ON with dax pfns.
>
> [  635.798741][T26531] kernel BUG at mm/page_alloc.c:5521!
> 1:mon> e
> cpu 0x1: Vector: 700 (Program Check) at [c7287630]
> pc: c055ed48: free_pages.part.0+0x48/0x110
> lr: c053ca70: tlb_finish_mmu+0x80/0xd0
> sp: c72878d0
>msr: 8282b033
>   current = 0xcafabe00
>   paca= 0xc0037300   irqmask: 0x03   irq_happened: 0x05
> pid   = 26531, comm = 50-landscape-sy
> kernel BUG at :5521!
> Linux version 5.19.0-rc3-14659-g4ec05be7c2e1 (kvaneesh@ltc-boston8) (gcc 
> (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) 
> #625 SMP Thu Jun 23 00:35:43 CDT 2022
> 1:mon> t
> [link register   ] c053ca70 tlb_finish_mmu+0x80/0xd0
> [c72878d0] c053ca54 tlb_finish_mmu+0x64/0xd0 (unreliable)
> [c7287900] c0539424 exit_mmap+0xe4/0x2a0
> [c72879e0] c019fc1c mmput+0xcc/0x210
> [c7287a20] c0629230 begin_new_exec+0x5e0/0xf40
> [c7287ae0] c070b3cc load_elf_binary+0x3ac/0x1e00
> [c7287c10] c0627af0 bprm_execve+0x3b0/0xaf0
> [c7287cd0] c0628414 do_execveat_common.isra.0+0x1e4/0x310
> [c7287d80] c062858c sys_execve+0x4c/0x60
> [c7287db0] c002c1b0 system_call_exception+0x160/0x2c0
> [c7287e10] c000c53c system_call_common+0xec/0x250
>
> The fix is to make sure we update high_memory on memory hotplug.
> This is similar to what x86 does in commit 3072e413e305 ("mm/memory_hotplug: 
> introduce add_pages")
>
> Fixes: ffa0b64e3be5 ("powerpc: Fix virt_addr_valid() for 64-bit Book3E & 
> 32-bit")
> Cc: Kefeng Wang 
> Cc: Christophe Leroy 
> Signed-off-by: Aneesh Kumar K.V 
 
...

> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
> index 52b77684acda..2a63920c369d 100644
> --- a/arch/powerpc/mm/mem.c
> +++ b/arch/powerpc/mm/mem.c
> @@ -105,6 +105,36 @@ void __ref arch_remove_linear_mapping(u64 start, u64 
> size)
>   vm_unmap_aliases();
>  }
>  
> +/*
> + * After memory hotplug the variables max_pfn, max_low_pfn and high_memory 
> need
> + * updating.
> + */
> +static void update_end_of_memory_vars(u64 start, u64 size)
> +{
> + unsigned long end_pfn = PFN_UP(start + size);
> +
> + if (end_pfn > max_pfn) {
> + max_pfn = end_pfn;
> + max_low_pfn = end_pfn;
> + high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
> + }
> +}
> +
> +int __ref add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
> + struct mhp_params *params)
> +{
> + int ret;
> +
> + ret = __add_pages(nid, start_pfn, nr_pages, params);
> + WARN_ON_ONCE(ret);

What's the justification for making this a WARN_ON_ONCE(), and then
continuing to update the variables anyway?

I realise that's what x86 does, but it seems kind of wrong.

cheers

> + /* update max_pfn, max_low_pfn and high_memory */
> + update_end_of_memory_vars(start_pfn << PAGE_SHIFT,
> +   nr_pages << PAGE_SHIFT);
> +
> + return ret;
> +}


[PATCH v3 00/12] powerpc: Nintendo Wii U support

2022-06-28 Thread Ash Logan
The following patches add basic support for the Nintendo Wii U video
game console, a PowerPC system somewhat similar to the GameCube and
Wii.

This includes:
- devicetree source
- bootwrapper support
- udbg console to bootloader
- early udbg console
- interrupt controllers
- platform support
- recognition of the Espresso processor
- workaround for the discontiguous RAM blocks

This is enough to boot on hardware. dmesg pics (with a small hack to
udbg-immortal, not included):
Link: https://wiki.linux-wiiu.org/images/7/7e/Mainline-initial-dmesg1.png
Link: https://wiki.linux-wiiu.org/images/9/91/Mainline-initial-dmesg2.png

For those who have hardware and would like to try these patches, some
modification is required to the stock OS to allow Linux. For info:
https://wiki.linux-wiiu.org/wiki/AdvancedSetup

Some of the design choices (new platform > embedded6xx) were discussed
previously:
Link: 
https://lore.kernel.org/lkml/0020d47c-0e23-822c-33f5-ccb7ea4c1...@heyquark.com/T/

Turns out even less changes were needed than previously anticipated for
discontiguous memory, and KUAP is yet to give trouble. Thanks to those
who helped and discussed this.

Changes since v2:
 - Fixed some overzealous deleting in the devicetree, oops.
 - Fixed missing declarations for some functions (thanks robots)
 - Fixed some checkpatch warnings.
 - Mark latte as a simple-bus and use of_platform_default_populate.
Changes since v1:
 - Style and formatting tweaks to the devicetree, thanks Rob Herring for
   the review.

Ash Logan (12):
  dt-bindings: wiiu: Document the Nintendo Wii U devicetree
  powerpc: wiiu: device tree
  powerpc: wiiu: bootwrapper support
  powerpc: wiiu: introduce wiiu platform
  powerpc: wiiu: declare as non-coherent
  powerpc: wiiu: udbg support for latteipc
  powerpc: wiiu: espresso interrupt controller support
  powerpc: wiiu: latte interrupt controller support
  powerpc: espresso processor support
  powerpc: wiiu: platform support
  powerpc: wiiu: don't enforce flat memory
  powerpc: wiiu: add minimal default config

 .../bindings/powerpc/nintendo/wiiu.yaml   |  28 ++
 .../powerpc/nintendo/wiiu/espresso-pic.yaml   |  42 +++
 .../bindings/powerpc/nintendo/wiiu/gpu7.yaml  |  41 +++
 .../powerpc/nintendo/wiiu/latte-ahci.yaml |  43 +++
 .../powerpc/nintendo/wiiu/latte-dsp.yaml  |  35 ++
 .../powerpc/nintendo/wiiu/latte-pic.yaml  |  46 +++
 .../powerpc/nintendo/wiiu/latte-sdhci.yaml|  40 +++
 .../bindings/powerpc/nintendo/wiiu/latte.yaml |  25 ++
 arch/powerpc/Kconfig.debug|   9 +
 arch/powerpc/boot/Makefile|   4 +
 arch/powerpc/boot/dts/wiiu.dts| 326 ++
 arch/powerpc/boot/wiiu-head.S | 103 ++
 arch/powerpc/boot/wiiu.c  |  73 
 arch/powerpc/boot/wrapper |   4 +
 arch/powerpc/configs/wiiu_defconfig   |   7 +
 arch/powerpc/include/asm/udbg.h   |   1 +
 arch/powerpc/kernel/cputable.c|  16 +
 arch/powerpc/kernel/head_book3s_32.S  |  20 ++
 arch/powerpc/kernel/udbg.c|   3 +
 arch/powerpc/mm/init_32.c |   4 +-
 arch/powerpc/platforms/Kconfig|   1 +
 arch/powerpc/platforms/Kconfig.cputype|   2 +-
 arch/powerpc/platforms/Makefile   |   1 +
 arch/powerpc/platforms/wiiu/Kconfig   |  22 ++
 arch/powerpc/platforms/wiiu/Makefile  |   4 +
 arch/powerpc/platforms/wiiu/espresso-pic.c| 183 ++
 arch/powerpc/platforms/wiiu/espresso-pic.h|  59 
 arch/powerpc/platforms/wiiu/latte-pic.c   | 259 ++
 arch/powerpc/platforms/wiiu/latte-pic.h   |  23 ++
 arch/powerpc/platforms/wiiu/setup.c   |  60 
 arch/powerpc/platforms/wiiu/udbg_latteipc.c   | 124 +++
 arch/powerpc/platforms/wiiu/udbg_latteipc.h   |  27 ++
 32 files changed, 1632 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/powerpc/nintendo/wiiu.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/espresso-pic.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/gpu7.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte-ahci.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte-dsp.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte-pic.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte-sdhci.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte.yaml
 create mode 100644 arch/powerpc/boot/dts/wiiu.dts
 create mode 100644 arch/powerpc/boot/wiiu-head.S
 create mode 100644 arch/powerpc/boot/wiiu.c
 create mode 100644 arch/powerpc/configs/wiiu_defconfig
 create mode 100644 arch/powerpc/platforms/wiiu/Kconfig
 create mode 100644 arch/powerpc/platforms/wiiu/Makefile
 create mode 100644 ar

[PATCH v3 01/12] dt-bindings: wiiu: Document the Nintendo Wii U devicetree

2022-06-28 Thread Ash Logan
Adds schema for the various Wii U devicetree nodes used.

Signed-off-by: Ash Logan 
---
 .../bindings/powerpc/nintendo/wiiu.yaml   | 28 +++
 .../powerpc/nintendo/wiiu/espresso-pic.yaml   | 42 +
 .../bindings/powerpc/nintendo/wiiu/gpu7.yaml  | 41 +
 .../powerpc/nintendo/wiiu/latte-ahci.yaml | 43 +
 .../powerpc/nintendo/wiiu/latte-dsp.yaml  | 35 ++
 .../powerpc/nintendo/wiiu/latte-pic.yaml  | 46 +++
 .../powerpc/nintendo/wiiu/latte-sdhci.yaml| 40 
 .../bindings/powerpc/nintendo/wiiu/latte.yaml | 25 ++
 8 files changed, 300 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/powerpc/nintendo/wiiu.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/espresso-pic.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/gpu7.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte-ahci.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte-dsp.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte-pic.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte-sdhci.yaml
 create mode 100644 
Documentation/devicetree/bindings/powerpc/nintendo/wiiu/latte.yaml

diff --git a/Documentation/devicetree/bindings/powerpc/nintendo/wiiu.yaml 
b/Documentation/devicetree/bindings/powerpc/nintendo/wiiu.yaml
new file mode 100644
index ..5824b07928f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/powerpc/nintendo/wiiu.yaml
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/powerpc/nintendo/wiiu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nintendo Wii U bindings
+
+maintainers:
+  - Ash Logan 
+  - Emmanuel Gil Peyrot 
+
+description: |
+  Nintendo Wii U video game console binding.
+
+properties:
+  $nodename:
+const: "/"
+  compatible:
+oneOf:
+  - description: Nintendo Wii U video game console
+items:
+  - const: nintendo,wiiu
+
+additionalProperties: true
+
+...
diff --git 
a/Documentation/devicetree/bindings/powerpc/nintendo/wiiu/espresso-pic.yaml 
b/Documentation/devicetree/bindings/powerpc/nintendo/wiiu/espresso-pic.yaml
new file mode 100644
index ..878a81595f5f
--- /dev/null
+++ b/Documentation/devicetree/bindings/powerpc/nintendo/wiiu/espresso-pic.yaml
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/powerpc/nintendo/wiiu/espresso-pic.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nintendo Wii U "Espresso" interrupt controller
+
+maintainers:
+  - Ash Logan 
+  - Emmanuel Gil Peyrot 
+
+description: |
+  Interrupt controller found on the Nintendo Wii U for the "Espresso" 
processor.
+
+properties:
+  compatible:
+oneOf:
+  - description: Nintendo Wii U "Espresso" interrupt controller
+items:
+  - const: nintendo,espresso-pic
+  '#interrupt-cells':
+# Interrupt numbers 0-32 in one cell
+const: 1
+  interrupt-controller: true
+  reg:
+items:
+  - description: Core registers
+
+additionalProperties: false
+
+examples:
+  - |
+espresso_pic: pic@c78 {
+#interrupt-cells = <1>;
+interrupt-controller;
+
+compatible = "nintendo,espresso-pic";
+reg = <0x0c78 0x18>;
+};
+
+...
diff --git a/Documentation/devicetree/bindings/powerpc/nintendo/wiiu/gpu7.yaml 
b/Documentation/devicetree/bindings/powerpc/nintendo/wiiu/gpu7.yaml
new file mode 100644
index ..e54d49015f36
--- /dev/null
+++ b/Documentation/devicetree/bindings/powerpc/nintendo/wiiu/gpu7.yaml
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/powerpc/nintendo/wiiu/gpu7.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nintendo Wii U Latte "GPU7" graphics processor
+
+maintainers:
+  - Ash Logan 
+  - Emmanuel Gil Peyrot 
+
+description: |
+  GPU7 graphics processor, also known as "GX2", found in the Latte 
multifunction chip of the
+  Nintendo Wii U.
+
+properties:
+  compatible:
+oneOf:
+  - description: Nintendo Wii U Latte "GPU7" graphics processor
+items:
+  - const: nintendo,latte-gpu7
+  reg:
+items:
+  - description: GpuF0MMReg registers
+  interrupts:
+items:
+  - description: Main interrupt, connected via Espresso PIC
+
+# This will likely get bound to the Radeon driver one day, which will 
neccesitate extra properties
+additionalProperties: true
+
+examples:
+  - |
+gpu7@c20 {
+compatible = "nintendo,latte-gpu7";
+reg = <0x0c20 0x8>;
+interrupts = <2>;
+interrupt-parent = <&

[PATCH v3 02/12] powerpc: wiiu: device tree

2022-06-28 Thread Ash Logan
Add a device tree source file for the Nintendo Wii U video game console.

Signed-off-by: Ash Logan 
Co-developed-by: Roberto Van Eeden 
Signed-off-by: Roberto Van Eeden 
Co-developed-by: Emmanuel Gil Peyrot 
Signed-off-by: Emmanuel Gil Peyrot 
---
v1->v2: Style and formatting changes suggested by Rob Herring.
 License remains GPL-2.0 as the other powerpc dtses are the same, happy
 to change if there is a different preferred default.
v2->v3: Re-added address-cells accidentally removed in v2.
 Marked latte as a simple-bus, since it is.

 arch/powerpc/boot/dts/wiiu.dts | 326 +
 1 file changed, 326 insertions(+)
 create mode 100644 arch/powerpc/boot/dts/wiiu.dts

diff --git a/arch/powerpc/boot/dts/wiiu.dts b/arch/powerpc/boot/dts/wiiu.dts
new file mode 100644
index ..44a5a1469095
--- /dev/null
+++ b/arch/powerpc/boot/dts/wiiu.dts
@@ -0,0 +1,326 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Nintendo Wii U Device Tree Source
+ *
+ * Copyright (C) 2022 The linux-wiiu Team
+ */
+
+/dts-v1/;
+#include 
+#include 
+
+/ {
+   model = "nintendo,wiiu";
+   compatible = "nintendo,wiiu";
+
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   chosen {
+   bootargs = "root=/dev/sda1 rootwait";
+   };
+
+   memory {
+   device_type = "memory";
+   reg = <0x 0x0200/* MEM1 - 32MiB */
+  0x0800 0x0030/* MEM0 - 3MiB  */
+  0x1000 0x8000>;  /* MEM2 - 2GiB  */
+   };
+
+   cpus {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   /* TODO: Add SMP */
+   PowerPC,espresso@0 {
+   device_type = "cpu";
+   reg = <0>;
+   clock-frequency = <1243125000>; /* 1.243125GHz 
*/
+   bus-frequency = <248625000>;/* 248.625MHz 
core-to-bus 5x */
+   timebase-frequency = <62156250>;/* 1/4 of the 
bus clock */
+   i-cache-size = <32768>; /* 32K icache */
+   i-cache-line-size = <32>;
+   i-cache-block-size = <32>;
+   i-cache-sets = <128>;
+   d-cache-size = <32768>; /* 32K dcache */
+   d-cache-line-size = <32>;
+   d-cache-block-size = <32>;
+   d-cache-sets = <128>;
+   next-level-cache = <&L2_0>;
+   L2_0:l2-cache {
+   compatible = "cache";
+   cache-level = <2>;
+   cache-unified;
+   cache-size = <0x8>; /* 512KB L2 */
+   cache-line-size = <64>;
+   cache-block-size = <32>;
+   cache-sets = <2048>;
+   };
+   };
+   };
+
+   latte {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   compatible = "nintendo,latte", "simple-bus";
+   ranges = <0x0c00 0x0c00 0x0040  /* 
Espresso-only registers */
+ 0x0d00 0x0d00 0x0020  /* Latte AHB 
deivces */
+ 0x0d80 0x0d80 0x0080>;/* Latte SoC 
registers */
+
+   latte_gpu: gpu@c20 {
+   compatible = "nintendo,latte-gpu7";
+   reg = <0x0c20 0x8>;
+   interrupts = <2>;
+   interrupt-parent = <&espresso_pic>;
+   };
+
+   espresso_pic: pic@c78 {
+   #interrupt-cells = <1>;
+   interrupt-controller;
+
+   compatible = "nintendo,espresso-pic";
+   reg = <0x0c78 0x18>;
+   };
+
+   latte_dsp: dsp@c005000 {
+   compatible = "nintendo,latte-dsp";
+   reg = <0x0c005000 0x200>;
+   };
+
+   ehci_0: usb@d04 {
+   compatible = "nintendo,latte-usb-ehci", "usb-ehci";
+   reg = <0x0d04 0x100>;
+   interrupts = <4>;
+   interrupt-parent = <&latte_pic>;
+   big-endian-regs;
+   };
+
+   ohci_0_0: usb@d05 {
+   compatible = "nintendo,latte-usb-ohci";
+   reg = <0x0d05 0x100>;
+   interrupts = <5>;
+   interrupt-parent = <&latte_pic>;
+
+   big-endian-regs;
+   };
+
+   ohci_0_1: usb@d06 {
+   compatible = "nintendo,latte-usb-ohci";
+   reg = <0x0d06 0x100>;
+ 

[PATCH v3 03/12] powerpc: wiiu: bootwrapper support

2022-06-28 Thread Ash Logan
Add support for the Nintendo Wii U game console to the powerpc
bootwrapper.

Signed-off-by: Ash Logan 
Co-developed-by: Emmanuel Gil Peyrot 
Signed-off-by: Emmanuel Gil Peyrot 
---
 arch/powerpc/boot/Makefile|   4 ++
 arch/powerpc/boot/wiiu-head.S | 103 ++
 arch/powerpc/boot/wiiu.c  |  73 
 arch/powerpc/boot/wrapper |   4 ++
 4 files changed, 184 insertions(+)
 create mode 100644 arch/powerpc/boot/wiiu-head.S
 create mode 100644 arch/powerpc/boot/wiiu.c

diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index a9cd2ea4a861..6694f578c447 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -161,6 +161,7 @@ src-plat-$(CONFIG_EMBEDDED6xx) += cuboot-pq2.c 
cuboot-mpc7448hpc2.c \
gamecube-head.S gamecube.c \
wii-head.S wii.c holly.c \
fixed-head.S mvme5100.c
+src-plat-$(CONFIG_WIIU) += wiiu-head.S wiiu.c
 src-plat-$(CONFIG_AMIGAONE) += cuboot-amigaone.c
 src-plat-$(CONFIG_PPC_PS3) += ps3-head.S ps3-hvcall.S ps3.c
 src-plat-$(CONFIG_EPAPR_BOOT) += epapr.c epapr-wrapper.c
@@ -359,6 +360,9 @@ image-$(CONFIG_GAMECUBE)+= dtbImage.gamecube
 image-$(CONFIG_WII)+= dtbImage.wii
 image-$(CONFIG_MVME5100)   += dtbImage.mvme5100
 
+# Board port in arch/powerpc/platform/wiiu/Kconfig
+image-$(CONFIG_WIIU)   += dtbImage.wiiu
+
 # Board port in arch/powerpc/platform/amigaone/Kconfig
 image-$(CONFIG_AMIGAONE)   += cuImage.amigaone
 
diff --git a/arch/powerpc/boot/wiiu-head.S b/arch/powerpc/boot/wiiu-head.S
new file mode 100644
index ..8586e2e992d5
--- /dev/null
+++ b/arch/powerpc/boot/wiiu-head.S
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Entrypoint head asm
+ * This code expects to be called directly after the Espresso BootROM, which 
implies certain MSR
+ * states.
+ *
+ * Nintendo Wii U bootwrapper support
+ * Copyright (C) 2022 The linux-wiiu Team
+ */
+
+#include "ppc_asm.h"
+
+.text
+.global _zimage_start
+_zimage_start:
+   /* Clear out all BATs. MMU is already off. */
+   li r8, 0
+
+   mtspr 0x210, r8 /* IBAT0U */
+   mtspr 0x212, r8 /* IBAT1U */
+   mtspr 0x214, r8 /* IBAT2U */
+   mtspr 0x216, r8 /* IBAT3U */
+   mtspr 0x218, r8 /* DBAT0U */
+   mtspr 0x21a, r8 /* DBAT1U */
+   mtspr 0x21c, r8 /* DBAT2U */
+   mtspr 0x21e, r8 /* DBAT3U */
+
+   mtspr 0x230, r8 /* IBAT4U */
+   mtspr 0x232, r8 /* IBAT5U */
+   mtspr 0x234, r8 /* IBAT6U */
+   mtspr 0x236, r8 /* IBAT7U */
+   mtspr 0x238, r8 /* DBAT4U */
+   mtspr 0x23a, r8 /* DBAT5U */
+   mtspr 0x23c, r8 /* DBAT6U */
+   mtspr 0x23e, r8 /* DBAT7U */
+
+   /* MEM1 */
+   /* 32MB, starting at 0x... */
+   li r8, 0x03ff@l
+   mtspr 0x21a, r8 /* DBAT1U */
+   mtspr 0x212, r8 /* IBAT1U */
+
+   /* mapped into phys 0x; read-write; normal caching. */
+   li r8, 0x0002@l
+   mtspr 0x21b, r8 /* DBAT1L */
+   mtspr 0x213, r8 /* IBAT1L */
+
+   /* Latte MMIO area */
+   /* 64MB, starting at 0x0d80... */
+   lis r8, 0x0d8007ff@h
+   ori r8, r8,0x0d87ff@l
+   mtspr 0x21c, r8 /* DBAT2U */
+
+   /* mapped into phys 0x0d80; read-write; writethrough/nocache/guard*/
+   lis r8, 0x0d80006A@h
+   ori r8, r8,0x0d80006A@l
+   mtspr 0x21d, r8 /* DBAT2L */
+
+   /* Bootloader comms area (actually 0x8920) */
+   /* 128MiB, starting at 0x8800... */
+   lis r8, 0x88000fff@h
+   ori r8, r8, 0x88000fff@l
+   mtspr 0x21e, r8 /* DBAT3U */
+
+   /* mapped into phys 0x8800; read-write; normal caching. */
+   lis r8, 0x8802@h
+   ori r8, r8, 0x8802@l
+   mtspr 0x21f, r8 /* DBAT3L */
+
+   /* Turn on BAT 4 through 7, configure CPU */
+   mfspr r8, 0x3f3 /* HID4 */
+   oris r8, r8, 0x3200 /* L2FM: 64-byte fetch, BPD: max depth is 4, SBE */
+   mtspr 0x3f3, r8
+
+   /* Turn on and invalidate caches */
+   mfspr r8, 0x3f0 /* HID0 */
+   /* HID0_ICE | HID0_ICFI | HID0_DCE | HID0_DCFI */
+   ori r8, r8, (1 << 15) | (1 << 11) | (1 << 14) | (1 << 10)
+   mtspr 0x3f0, r8
+   isync
+
+   li r3, 0
+   li r4, 0
+   li r5, 0
+
+   bl get_lr
+get_lr:
+   mflr r8
+   /* Get absolute address of done */
+   addi r8, r8, done - get_lr
+
+   /* Set up MSR */
+   /* MSR_DR | MSR_IR | MSR_FP */
+   /* Data/instruction MMUs, FPU because why not */
+   ori r9, r3, (1 << 4) | (1 << 5) | (1 << 13)
+
+   /* Apply our new MSR, starting execution at "done" */
+   mtsrr0 r8
+   mtsrr1 r9
+   sync
+   rfi
+done:
+   b _zimage_start_lib
diff --git a/arch/powerpc/boot/wiiu.c b/arch/powerpc/boot/wiiu.c
new file mode 100644
index ..fe88eb2c42ae
--- /dev/n

[PATCH v3 04/12] powerpc: wiiu: introduce wiiu platform

2022-06-28 Thread Ash Logan
Adds empty platforms/wiiu for Nintendo Wii U console

Signed-off-by: Ash Logan 
---
v2->v3: Add help text for CONFIG_WIIU.

 arch/powerpc/platforms/Kconfig   | 1 +
 arch/powerpc/platforms/Makefile  | 1 +
 arch/powerpc/platforms/wiiu/Kconfig  | 8 
 arch/powerpc/platforms/wiiu/Makefile | 1 +
 4 files changed, 11 insertions(+)
 create mode 100644 arch/powerpc/platforms/wiiu/Kconfig
 create mode 100644 arch/powerpc/platforms/wiiu/Makefile

diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index d41dad227de8..c4a9c3c0b409 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -22,6 +22,7 @@ source "arch/powerpc/platforms/40x/Kconfig"
 source "arch/powerpc/platforms/amigaone/Kconfig"
 source "arch/powerpc/platforms/book3s/Kconfig"
 source "arch/powerpc/platforms/microwatt/Kconfig"
+source "arch/powerpc/platforms/wiiu/Kconfig"
 
 config KVM_GUEST
bool "KVM Guest support"
diff --git a/arch/powerpc/platforms/Makefile b/arch/powerpc/platforms/Makefile
index 94470fb27c99..944ddd938711 100644
--- a/arch/powerpc/platforms/Makefile
+++ b/arch/powerpc/platforms/Makefile
@@ -24,3 +24,4 @@ obj-$(CONFIG_EMBEDDED6xx) += embedded6xx/
 obj-$(CONFIG_AMIGAONE) += amigaone/
 obj-$(CONFIG_PPC_BOOK3S)   += book3s/
 obj-$(CONFIG_PPC_MICROWATT)+= microwatt/
+obj-$(CONFIG_WIIU) += wiiu/
diff --git a/arch/powerpc/platforms/wiiu/Kconfig 
b/arch/powerpc/platforms/wiiu/Kconfig
new file mode 100644
index ..3834834c6bd7
--- /dev/null
+++ b/arch/powerpc/platforms/wiiu/Kconfig
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config WIIU
+   bool "Nintendo Wii U"
+   depends on PPC_BOOK3S_32
+   help
+ Select WIIU if configuring for the Nintendo Wii U.
+ More information at: 
diff --git a/arch/powerpc/platforms/wiiu/Makefile 
b/arch/powerpc/platforms/wiiu/Makefile
new file mode 100644
index ..f66554cd5c45
--- /dev/null
+++ b/arch/powerpc/platforms/wiiu/Makefile
@@ -0,0 +1 @@
+# SPDX-License-Identifier: GPL-2.0
-- 
2.36.1



[PATCH v3 05/12] powerpc: wiiu: declare as non-coherent

2022-06-28 Thread Ash Logan
The Nintendo Wii U requires explicit cache handling when interfacing
with DMA devices.

Signed-off-by: Ash Logan 
---
 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 9e2df4b66478..20eef6595a60 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -501,7 +501,7 @@ config NR_CPUS
 config NOT_COHERENT_CACHE
bool
depends on 4xx || PPC_8xx || PPC_MPC512x || \
-   GAMECUBE_COMMON || AMIGAONE
+   GAMECUBE_COMMON || AMIGAONE || WIIU
select ARCH_HAS_DMA_PREP_COHERENT
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
select ARCH_HAS_SYNC_DMA_FOR_CPU
-- 
2.36.1



[PATCH v3 06/12] powerpc: wiiu: udbg support for latteipc

2022-06-28 Thread Ash Logan
Add support for using the Latte chipset IPC for udbg on the Nintendo Wii
U console.
These messages can then be received by a special firmware running on the
"Starbuck" coprocessor.

Signed-off-by: Ash Logan 
---
v2->v3: Fix a missing declaration issue by including latteipc_udbg.h.

 arch/powerpc/Kconfig.debug  |   9 ++
 arch/powerpc/include/asm/udbg.h |   1 +
 arch/powerpc/kernel/head_book3s_32.S|  20 
 arch/powerpc/kernel/udbg.c  |   3 +
 arch/powerpc/platforms/wiiu/Kconfig |  13 ++
 arch/powerpc/platforms/wiiu/Makefile|   2 +
 arch/powerpc/platforms/wiiu/udbg_latteipc.c | 124 
 arch/powerpc/platforms/wiiu/udbg_latteipc.h |  27 +
 8 files changed, 199 insertions(+)
 create mode 100644 arch/powerpc/platforms/wiiu/udbg_latteipc.c
 create mode 100644 arch/powerpc/platforms/wiiu/udbg_latteipc.h

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 9f363c143d86..cee97d21f5fb 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -254,6 +254,15 @@ config PPC_EARLY_DEBUG_USBGECKO
  Select this to enable early debugging for Nintendo GameCube/Wii
  consoles via an external USB Gecko adapter.
 
+config PPC_EARLY_DEBUG_LATTEIPC
+   bool "Early debugging through Latte chipset IPC"
+   depends on WIIU
+   select LATTEIPC_UDBG
+   help
+ Select this to enable early debugging for Nintendo Wii U consoles via
+ chipset IPC to the security coprocessor. This assumes a firmware is
+ running on the coprocessor to receive messages.
+
 config PPC_EARLY_DEBUG_PS3GELIC
bool "Early debugging through the PS3 Ethernet port"
depends on PPC_PS3
diff --git a/arch/powerpc/include/asm/udbg.h b/arch/powerpc/include/asm/udbg.h
index b4aa0d88ce2c..266b0e744ddc 100644
--- a/arch/powerpc/include/asm/udbg.h
+++ b/arch/powerpc/include/asm/udbg.h
@@ -53,6 +53,7 @@ extern void __init udbg_init_ehv_bc(void);
 extern void __init udbg_init_ps3gelic(void);
 extern void __init udbg_init_debug_opal_raw(void);
 extern void __init udbg_init_debug_opal_hvsi(void);
+extern void __init udbg_init_latteipc(void);
 
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_UDBG_H */
diff --git a/arch/powerpc/kernel/head_book3s_32.S 
b/arch/powerpc/kernel/head_book3s_32.S
index 6c739beb938c..48d487efb25c 100644
--- a/arch/powerpc/kernel/head_book3s_32.S
+++ b/arch/powerpc/kernel/head_book3s_32.S
@@ -164,6 +164,9 @@ __after_mmu_off:
 #ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
bl  setup_usbgecko_bat
 #endif
+#ifdef CONFIG_PPC_EARLY_DEBUG_LATTEIPC
+   bl  setup_latteipc_bat
+#endif
 
 /*
  * Call setup_cpu for CPU 0 and initialize 6xx Idle
@@ -1201,4 +1204,21 @@ setup_usbgecko_bat:
blr
 #endif
 
+#ifdef CONFIG_PPC_EARLY_DEBUG_LATTEIPC
+setup_latteipc_bat:
+   /* prepare a BAT for early io */
+   lis r8, 0x0d80
+
+   /*
+* The virtual address used must match the virtual address
+* associated to the fixmap entry FIX_EARLY_DEBUG_BASE.
+*/
+   lis r11, 0xfffe /* top 128K */
+   ori r8, r8, 0x002a  /* uncached, guarded ,rw */
+   ori r11, r11, 0x2   /* 128K, Vs=1, Vp=0 */
+   mtspr   SPRN_DBAT1L, r8
+   mtspr   SPRN_DBAT1U, r11
+   blr
+#endif
+
.data
diff --git a/arch/powerpc/kernel/udbg.c b/arch/powerpc/kernel/udbg.c
index b1544b2f6321..84eae25c195e 100644
--- a/arch/powerpc/kernel/udbg.c
+++ b/arch/powerpc/kernel/udbg.c
@@ -67,6 +67,9 @@ void __init udbg_early_init(void)
udbg_init_debug_opal_raw();
 #elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI)
udbg_init_debug_opal_hvsi();
+#elif defined(CONFIG_PPC_EARLY_DEBUG_LATTEIPC)
+   /* For use on Nintendo Wii U */
+   udbg_init_latteipc();
 #endif
 
 #ifdef CONFIG_PPC_EARLY_DEBUG
diff --git a/arch/powerpc/platforms/wiiu/Kconfig 
b/arch/powerpc/platforms/wiiu/Kconfig
index 3834834c6bd7..8dfd6ac8774d 100644
--- a/arch/powerpc/platforms/wiiu/Kconfig
+++ b/arch/powerpc/platforms/wiiu/Kconfig
@@ -6,3 +6,16 @@ config WIIU
help
  Select WIIU if configuring for the Nintendo Wii U.
  More information at: 
+
+config LATTEIPC_UDBG
+   bool "Chipset IPC udbg console for the Nintendo Wii U"
+   depends on WIIU
+   help
+ If you say yes to this option, support will be included for the
+ Wii U's chipset IPC as a udbg console.
+ These IPC messages can be received by a firmware running on the
+ console's "Starbuck" security coprocessor.
+
+ This driver bypasses the IPC layer completely.
+
+ If in doubt, say N here.
diff --git a/arch/powerpc/platforms/wiiu/Makefile 
b/arch/powerpc/platforms/wiiu/Makefile
index f66554cd5c45..b1e0e1307f6e 100644
--- a/arch/powerpc/platforms/wiiu/Makefile
+++ b/arch/powerpc/platforms/wiiu/Makefile
@@ -1 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_LATTEIPC_

[PATCH v3 07/12] powerpc: wiiu: espresso interrupt controller support

2022-06-28 Thread Ash Logan
Add support for the "Espresso" interrupt controller in the Nintendo Wii
U.

Signed-off-by: Ash Logan 
Co-developed-by: Roberto Van Eeden 
Signed-off-by: Roberto Van Eeden 
---
 arch/powerpc/platforms/wiiu/Makefile   |   1 +
 arch/powerpc/platforms/wiiu/espresso-pic.c | 183 +
 arch/powerpc/platforms/wiiu/espresso-pic.h |  59 +++
 3 files changed, 243 insertions(+)
 create mode 100644 arch/powerpc/platforms/wiiu/espresso-pic.c
 create mode 100644 arch/powerpc/platforms/wiiu/espresso-pic.h

diff --git a/arch/powerpc/platforms/wiiu/Makefile 
b/arch/powerpc/platforms/wiiu/Makefile
index b1e0e1307f6e..aabf4b43e806 100644
--- a/arch/powerpc/platforms/wiiu/Makefile
+++ b/arch/powerpc/platforms/wiiu/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
+obj-$(CONFIG_WIIU) += espresso-pic.o
 obj-$(CONFIG_LATTEIPC_UDBG) += udbg_latteipc.o
diff --git a/arch/powerpc/platforms/wiiu/espresso-pic.c 
b/arch/powerpc/platforms/wiiu/espresso-pic.c
new file mode 100644
index ..1aa5d88002d5
--- /dev/null
+++ b/arch/powerpc/platforms/wiiu/espresso-pic.c
@@ -0,0 +1,183 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Nintendo Wii U "Espresso" interrupt controller support
+ * Copyright (C) 2022 The linux-wiiu Team
+ *
+ * Based on flipper-pic.c
+ * Copyright (C) 2004-2009 The GameCube Linux Team
+ * Copyright (C) 2007-2009 Albert Herranz
+ */
+
+#define DRV_MODULE_NAME "espresso-pic"
+#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "espresso-pic.h"
+
+static DEFINE_PER_CPU(struct espresso_pic *, espresso_pic_cpu);
+
+/*
+ * IRQ chip operations
+ */
+
+static void espresso_pic_mask_and_ack(struct irq_data *d)
+{
+   struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+   u32 mask = 1 << irqd_to_hwirq(d);
+
+   out_be32(&pic->icr, mask);
+   clrbits32(&pic->imr, mask);
+}
+
+static void espresso_pic_ack(struct irq_data *d)
+{
+   struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+   u32 mask = 1 << irqd_to_hwirq(d);
+
+   out_be32(&pic->icr, mask);
+}
+
+static void espresso_pic_mask(struct irq_data *d)
+{
+   struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+   u32 mask = 1 << irqd_to_hwirq(d);
+
+   clrbits32(&pic->imr, mask);
+}
+
+static void espresso_pic_unmask(struct irq_data *d)
+{
+   struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+   u32 mask = 1 << irqd_to_hwirq(d);
+
+   setbits32(&pic->imr, mask);
+}
+
+static struct irq_chip espresso_pic_chip = {
+   .name = "espresso-pic",
+   .irq_ack = espresso_pic_ack,
+   .irq_mask_ack = espresso_pic_mask_and_ack,
+   .irq_mask = espresso_pic_mask,
+   .irq_unmask = espresso_pic_unmask,
+};
+
+/*
+ * Domain Ops
+ */
+
+static int espresso_pic_match(struct irq_domain *h, struct device_node *node,
+ enum irq_domain_bus_token bus_token)
+{
+   if (h->fwnode == &node->fwnode) {
+   pr_debug("espresso-pic: %s IRQ matches with this driver\n",
+node->name);
+   return 1;
+   }
+   return 0;
+}
+
+static int espresso_pic_alloc(struct irq_domain *h, unsigned int virq,
+ unsigned int nr_irqs, void *arg)
+{
+   unsigned int i;
+   struct irq_fwspec *fwspec = arg;
+   irq_hw_number_t hwirq = fwspec->param[0];
+
+   for (i = 0; i < nr_irqs; i++) {
+   irq_set_chip_data(virq + i, h->host_data);
+   irq_set_status_flags(virq + i, IRQ_LEVEL);
+   irq_set_chip_and_handler(virq + i, &espresso_pic_chip,
+handle_level_irq);
+   irq_domain_set_hwirq_and_chip(h, virq + i, hwirq + i,
+ &espresso_pic_chip, h->host_data);
+   }
+   return 0;
+}
+
+static void espresso_pic_free(struct irq_domain *h, unsigned int virq,
+ unsigned int nr_irqs)
+{
+   pr_debug("free\n");
+}
+
+const struct irq_domain_ops espresso_pic_ops = {
+   .match = espresso_pic_match,
+   .alloc = espresso_pic_alloc,
+   .free = espresso_pic_free,
+};
+
+/* Store irq domain for espresso_pic_get_irq (the function gets no arguments) 
*/
+static struct irq_domain *espresso_irq_domain;
+
+unsigned int espresso_pic_get_irq(void)
+{
+   struct espresso_pic *pic = *this_cpu_ptr(&espresso_pic_cpu);
+   u32 irq_status, irq;
+
+   irq_status = in_be32(&pic->icr) & in_be32(&pic->imr);
+
+   if (irq_status == 0)
+   return 0; /* No IRQs pending */
+
+   /* Return first IRQ */
+   irq = __ffs(irq_status);
+   return irq_linear_revmap(espresso_irq_domain, irq);
+}
+
+void __init espresso_pic_init(void)
+{
+   struct device_node *np =
+   of_find_compatible_node(NULL, NULL, "nintendo,espresso-pic");
+   struct irq_domain *host;

[PATCH v3 08/12] powerpc: wiiu: latte interrupt controller support

2022-06-28 Thread Ash Logan
Add support for the "Latte" interrupt controller in the Nintendo Wii U.
This controller is used for the entire SoC and is wired to a cascade
interrupt on the Espresso controller.

Signed-off-by: Ash Logan 
Co-developed-by: Roberto Van Eeden 
Signed-off-by: Roberto Van Eeden 
---
v2->v3: Make latte_pic_get_irq static.

 arch/powerpc/platforms/wiiu/Kconfig |   1 +
 arch/powerpc/platforms/wiiu/Makefile|   2 +-
 arch/powerpc/platforms/wiiu/latte-pic.c | 259 
 arch/powerpc/platforms/wiiu/latte-pic.h |  23 +++
 4 files changed, 284 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/wiiu/latte-pic.c
 create mode 100644 arch/powerpc/platforms/wiiu/latte-pic.h

diff --git a/arch/powerpc/platforms/wiiu/Kconfig 
b/arch/powerpc/platforms/wiiu/Kconfig
index 8dfd6ac8774d..40ecba8396a7 100644
--- a/arch/powerpc/platforms/wiiu/Kconfig
+++ b/arch/powerpc/platforms/wiiu/Kconfig
@@ -3,6 +3,7 @@
 config WIIU
bool "Nintendo Wii U"
depends on PPC_BOOK3S_32
+   select IRQ_DOMAIN_HIERARCHY
help
  Select WIIU if configuring for the Nintendo Wii U.
  More information at: 
diff --git a/arch/powerpc/platforms/wiiu/Makefile 
b/arch/powerpc/platforms/wiiu/Makefile
index aabf4b43e806..fa16c60261e6 100644
--- a/arch/powerpc/platforms/wiiu/Makefile
+++ b/arch/powerpc/platforms/wiiu/Makefile
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-$(CONFIG_WIIU) += espresso-pic.o
+obj-$(CONFIG_WIIU) += espresso-pic.o latte-pic.o
 obj-$(CONFIG_LATTEIPC_UDBG) += udbg_latteipc.o
diff --git a/arch/powerpc/platforms/wiiu/latte-pic.c 
b/arch/powerpc/platforms/wiiu/latte-pic.c
new file mode 100644
index ..7e3f49844166
--- /dev/null
+++ b/arch/powerpc/platforms/wiiu/latte-pic.c
@@ -0,0 +1,259 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Nintendo Wii U "Latte" interrupt controller support.
+ * This is the controller for all the SoC devices, and has a cascade interrupt 
for the Espresso
+ * CPU interrupt controller.
+ *
+ * Copyright (C) 2022 The linux-wiiu Team
+ *
+ * Based on hlwd-pic.c
+ * Copyright (C) 2009 The GameCube Linux Team
+ * Copyright (C) 2009 Albert Herranz
+ */
+
+#define DRV_MODULE_NAME "latte-pic"
+#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "latte-pic.h"
+
+static DEFINE_PER_CPU(struct lt_pic *, lt_pic_cpu);
+
+/*
+ * IRQ chip operations
+ * These handle both AHBALL and AHBLT IRQs, with AHBLT mapped above 32
+ */
+
+static void latte_pic_mask_and_ack(struct irq_data *d)
+{
+   struct lt_pic *pic = *this_cpu_ptr(<_pic_cpu);
+   u32 irq = irqd_to_hwirq(d);
+
+   if (irq < LATTE_AHBALL_NR_IRQS) {
+   u32 mask = 1 << irq;
+
+   out_be32(&pic->ahball_icr, mask);
+   clrbits32(&pic->ahball_imr, mask);
+   } else {
+   u32 mask = 1 << (irq - 32);
+
+   out_be32(&pic->ahblt_icr, mask);
+   clrbits32(&pic->ahblt_imr, mask);
+   }
+}
+
+static void latte_pic_ack(struct irq_data *d)
+{
+   struct lt_pic *pic = *this_cpu_ptr(<_pic_cpu);
+   u32 irq = irqd_to_hwirq(d);
+
+   if (irq < LATTE_AHBALL_NR_IRQS) {
+   u32 mask = 1 << irq;
+
+   out_be32(&pic->ahball_icr, mask);
+   } else {
+   u32 mask = 1 << (irq - 32);
+
+   out_be32(&pic->ahblt_icr, mask);
+   }
+}
+
+static void latte_pic_mask(struct irq_data *d)
+{
+   struct lt_pic *pic = *this_cpu_ptr(<_pic_cpu);
+   u32 irq = irqd_to_hwirq(d);
+
+   if (irq < LATTE_AHBALL_NR_IRQS) {
+   u32 mask = 1 << irq;
+
+   clrbits32(&pic->ahball_imr, mask);
+   } else {
+   u32 mask = 1 << (irq - 32);
+
+   clrbits32(&pic->ahblt_imr, mask);
+   }
+}
+
+static void latte_pic_unmask(struct irq_data *d)
+{
+   struct lt_pic *pic = *this_cpu_ptr(<_pic_cpu);
+   u32 irq = irqd_to_hwirq(d);
+
+   if (irq < LATTE_AHBALL_NR_IRQS) {
+   u32 mask = 1 << irq;
+
+   setbits32(&pic->ahball_imr, mask);
+   } else {
+   u32 mask = 1 << (irq - 32);
+
+   setbits32(&pic->ahblt_imr, mask);
+   }
+}
+
+static struct irq_chip latte_pic = {
+   .name = "latte-pic",
+   .irq_ack = latte_pic_ack,
+   .irq_mask_ack = latte_pic_mask_and_ack,
+   .irq_mask = latte_pic_mask,
+   .irq_unmask = latte_pic_unmask,
+};
+
+/*
+ * Domain ops
+ */
+
+static int latte_pic_match(struct irq_domain *h, struct device_node *node,
+  enum irq_domain_bus_token bus_token)
+{
+   if (h->fwnode == &node->fwnode) {
+   pr_debug("%s IRQ matches with this driver\n", node->name);
+   return 1;
+   }
+   return 0;
+}
+
+static int latte_pic_alloc(struct irq_domain *h, unsigned int virq,
+  unsigned int nr_irqs, void *arg)
+

[PATCH v3 09/12] powerpc: espresso processor support

2022-06-28 Thread Ash Logan
Adds a cputable entry for the "Espresso" processor found on the Nintendo
Wii U, which has a PVR unrelated to other 750CL-like chips.
Only this revision has been seen in the wild.

Signed-off-by: Roberto Van Eeden 
Signed-off-by: Ash Logan 
---
 arch/powerpc/kernel/cputable.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index a5dbfccd2047..3a4e84d1f674 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -736,6 +736,22 @@ static struct cpu_spec __initdata cpu_specs[] = {
.platform   = "ppc750",
.oprofile_cpu_type  = "ppc/750",
},
+   {   /* "Espresso" (750CL-like) */
+   .pvr_mask   = 0x,
+   .pvr_value  = 0x70010201,
+   .cpu_name   = "Espresso",
+   .cpu_features   = CPU_FTRS_750CL,
+   .cpu_user_features  = COMMON_USER | PPC_FEATURE_PPC_LE,
+   .mmu_features   = MMU_FTR_HPTE_TABLE | 
MMU_FTR_USE_HIGH_BATS,
+   .icache_bsize   = 32,
+   .dcache_bsize   = 32,
+   .num_pmcs   = 4,
+   .pmc_type   = PPC_PMC_IBM,
+   .cpu_setup  = __setup_cpu_750,
+   .machine_check  = machine_check_generic,
+   .platform   = "ppc750",
+   .oprofile_cpu_type  = "ppc/750",
+   },
{   /* 745/755 */
.pvr_mask   = 0xf000,
.pvr_value  = 0x00083000,
-- 
2.36.1



[PATCH v3 10/12] powerpc: wiiu: platform support

2022-06-28 Thread Ash Logan
Add platform support for the Nintendo Wii U console.

Signed-off-by: Ash Logan 
Co-developed-by: Roberto Van Eeden 
Signed-off-by: Roberto Van Eeden 
Co-developed-by: Emmanuel Gil Peyrot 
Signed-off-by: Emmanuel Gil Peyrot 
---
v2->v3: Use of_platform_default_populate instead of a custom match table.

 arch/powerpc/platforms/wiiu/Makefile |  2 +-
 arch/powerpc/platforms/wiiu/setup.c  | 60 
 2 files changed, 61 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/wiiu/setup.c

diff --git a/arch/powerpc/platforms/wiiu/Makefile 
b/arch/powerpc/platforms/wiiu/Makefile
index fa16c60261e6..abcb7a1beebf 100644
--- a/arch/powerpc/platforms/wiiu/Makefile
+++ b/arch/powerpc/platforms/wiiu/Makefile
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-$(CONFIG_WIIU) += espresso-pic.o latte-pic.o
+obj-$(CONFIG_WIIU) += setup.o espresso-pic.o latte-pic.o
 obj-$(CONFIG_LATTEIPC_UDBG) += udbg_latteipc.o
diff --git a/arch/powerpc/platforms/wiiu/setup.c 
b/arch/powerpc/platforms/wiiu/setup.c
new file mode 100644
index ..e3f07ce65cad
--- /dev/null
+++ b/arch/powerpc/platforms/wiiu/setup.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Nintendo Wii U board-specific support
+ *
+ * Copyright (C) 2022 The linux-wiiu Team
+ */
+#define DRV_MODULE_NAME "wiiu"
+#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include "espresso-pic.h"
+#include "latte-pic.h"
+#include "udbg_latteipc.h"
+
+static int __init wiiu_probe(void)
+{
+   if (!of_machine_is_compatible("nintendo,wiiu"))
+   return 0;
+
+   latteipc_udbg_init();
+
+   return 1;
+}
+
+static void __noreturn wiiu_halt(void)
+{
+   for (;;)
+   cpu_relax();
+}
+
+static void __init wiiu_init_irq(void)
+{
+   espresso_pic_init();
+   latte_pic_init();
+}
+
+static int __init wiiu_device_probe(void)
+{
+   if (!machine_is(wiiu))
+   return 0;
+
+   of_platform_default_populate(NULL, NULL, NULL);
+   return 0;
+}
+device_initcall(wiiu_device_probe);
+
+define_machine(wiiu) {
+   .name = "wiiu",
+   .probe = wiiu_probe,
+   .halt = wiiu_halt,
+   .progress = udbg_progress,
+   .calibrate_decr = generic_calibrate_decr,
+   .init_IRQ = wiiu_init_irq,
+   .get_irq = espresso_pic_get_irq,
+};
-- 
2.36.1



[PATCH v3 11/12] powerpc: wiiu: don't enforce flat memory

2022-06-28 Thread Ash Logan
pgtable_32.c:mapin_ram loops over each valid memory range, which means
non-contiguous memory just works.

Signed-off-by: Ash Logan 
---
 arch/powerpc/mm/init_32.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index 693a3a7a9463..6cdb561c05c5 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -124,10 +124,10 @@ void __init MMU_init(void)
 * lowmem_end_addr is initialized below.
 */
if (memblock.memory.cnt > 1) {
-#ifndef CONFIG_WII
+#if !defined(CONFIG_WII) && !defined(CONFIG_WIIU)
memblock_enforce_memory_limit(memblock.memory.regions[0].size);
pr_warn("Only using first contiguous memory region\n");
-#else
+#elif defined(CONFIG_WII)
wii_memory_fixups();
 #endif
}
-- 
2.36.1



[PATCH v3 12/12] powerpc: wiiu: add minimal default config

2022-06-28 Thread Ash Logan
Adds a bare-minimum config to get a kernel compiled. Will need some more
interesting options once a storage device to boot from is added.

Signed-off-by: Ash Logan 
---
 arch/powerpc/configs/wiiu_defconfig | 7 +++
 1 file changed, 7 insertions(+)
 create mode 100644 arch/powerpc/configs/wiiu_defconfig

diff --git a/arch/powerpc/configs/wiiu_defconfig 
b/arch/powerpc/configs/wiiu_defconfig
new file mode 100644
index ..a761ebcdd9f2
--- /dev/null
+++ b/arch/powerpc/configs/wiiu_defconfig
@@ -0,0 +1,7 @@
+# CONFIG_PPC_CHRP is not set
+# CONFIG_PPC_PMAC is not set
+CONFIG_WIIU=y
+# CONFIG_PPC_OF_BOOT_TRAMPOLINE is not set
+CONFIG_HIGHMEM=y
+CONFIG_STRICT_KERNEL_RWX=y
+CONFIG_PPC_EARLY_DEBUG=y
-- 
2.36.1



Re: [PATCH -next 1/2] soc: fsl: guts: fix return value check in fsl_guts_init()

2022-06-28 Thread Michael Walle

Am 2022-06-28 16:02, schrieb Yang Yingliang:

In case of error, of_iomap() returns NULL pointer not ERR_PTR().
The IS_ERR() test in the return value check should be replaced
with NULL test and return -ENOMEM as error value.

Fixes: ab4988d6a393 ("soc: fsl: guts: embed fsl_guts_get_svr() in 
probe()")

Reported-by: Hulk Robot 
Signed-off-by: Yang Yingliang 


Thanks!

Reviewed-by: Michael Walle 


Re: [PATCH -next 2/2] soc: fsl: guts: check return value after calling of_iomap() in fsl_guts_get_soc_uid()

2022-06-28 Thread Michael Walle

Am 2022-06-28 16:02, schrieb Yang Yingliang:

of_iomap() may return NULL, so we need check the return value.

Fixes: 786dde1e59d7 ("soc: fsl: guts: add serial_number support")
Reported-by: Hulk Robot 
Signed-off-by: Yang Yingliang 


Reviewed-by: Michael Walle 


Re: [PATCH V2] powerpc/memhotplug: Add add_pages override for PPC

2022-06-28 Thread Aneesh Kumar K V
On 6/28/22 6:26 PM, Michael Ellerman wrote:
> "Aneesh Kumar K.V"  writes:
>> With commit ffa0b64e3be5 ("powerpc: Fix virt_addr_valid() for 64-bit Book3E 
>> & 32-bit")
>> the kernel now validate the addr against high_memory value. This results
>> in the below BUG_ON with dax pfns.
>>
>> [  635.798741][T26531] kernel BUG at mm/page_alloc.c:5521!
>> 1:mon> e
>> cpu 0x1: Vector: 700 (Program Check) at [c7287630]
>> pc: c055ed48: free_pages.part.0+0x48/0x110
>> lr: c053ca70: tlb_finish_mmu+0x80/0xd0
>> sp: c72878d0
>>msr: 8282b033
>>   current = 0xcafabe00
>>   paca= 0xc0037300   irqmask: 0x03   irq_happened: 0x05
>> pid   = 26531, comm = 50-landscape-sy
>> kernel BUG at :5521!
>> Linux version 5.19.0-rc3-14659-g4ec05be7c2e1 (kvaneesh@ltc-boston8) (gcc 
>> (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 
>> 2.34) #625 SMP Thu Jun 23 00:35:43 CDT 2022
>> 1:mon> t
>> [link register   ] c053ca70 tlb_finish_mmu+0x80/0xd0
>> [c72878d0] c053ca54 tlb_finish_mmu+0x64/0xd0 (unreliable)
>> [c7287900] c0539424 exit_mmap+0xe4/0x2a0
>> [c72879e0] c019fc1c mmput+0xcc/0x210
>> [c7287a20] c0629230 begin_new_exec+0x5e0/0xf40
>> [c7287ae0] c070b3cc load_elf_binary+0x3ac/0x1e00
>> [c7287c10] c0627af0 bprm_execve+0x3b0/0xaf0
>> [c7287cd0] c0628414 do_execveat_common.isra.0+0x1e4/0x310
>> [c7287d80] c062858c sys_execve+0x4c/0x60
>> [c7287db0] c002c1b0 system_call_exception+0x160/0x2c0
>> [c7287e10] c000c53c system_call_common+0xec/0x250
>>
>> The fix is to make sure we update high_memory on memory hotplug.
>> This is similar to what x86 does in commit 3072e413e305 ("mm/memory_hotplug: 
>> introduce add_pages")
>>
>> Fixes: ffa0b64e3be5 ("powerpc: Fix virt_addr_valid() for 64-bit Book3E & 
>> 32-bit")
>> Cc: Kefeng Wang 
>> Cc: Christophe Leroy 
>> Signed-off-by: Aneesh Kumar K.V 
>  
> ...
> 
>> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
>> index 52b77684acda..2a63920c369d 100644
>> --- a/arch/powerpc/mm/mem.c
>> +++ b/arch/powerpc/mm/mem.c
>> @@ -105,6 +105,36 @@ void __ref arch_remove_linear_mapping(u64 start, u64 
>> size)
>>  vm_unmap_aliases();
>>  }
>>  
>> +/*
>> + * After memory hotplug the variables max_pfn, max_low_pfn and high_memory 
>> need
>> + * updating.
>> + */
>> +static void update_end_of_memory_vars(u64 start, u64 size)
>> +{
>> +unsigned long end_pfn = PFN_UP(start + size);
>> +
>> +if (end_pfn > max_pfn) {
>> +max_pfn = end_pfn;
>> +max_low_pfn = end_pfn;
>> +high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
>> +}
>> +}
>> +
>> +int __ref add_pages(int nid, unsigned long start_pfn, unsigned long 
>> nr_pages,
>> +struct mhp_params *params)
>> +{
>> +int ret;
>> +
>> +ret = __add_pages(nid, start_pfn, nr_pages, params);
>> +WARN_ON_ONCE(ret);
> 
> What's the justification for making this a WARN_ON_ONCE(), and then
> continuing to update the variables anyway?
> 
> I realise that's what x86 does, but it seems kind of wrong.
> 
>

That is copy paste bug from my side. I guess we should skip updating vars on 
__add_pages failure.
WARN_ON_ONCE() was done as part of fe8b868eccb9f85a0e231e35f0abac5b39bac801. 
The original code 
did print a WARN all the time. So the above commit made it conditional. Later 
in ea0854170c95245a258b386c7a9314399c949fe0
the return value was never checked. So the error path is not handled there at 
all. 

we should do 

if (!ret) update_end_of_memory_vars(...); 

Do you want a v3 with the changes? 

-aneesh




[PATCH] powerpc/ptdump: Fix display of RW pages on FSL_BOOK3E

2022-06-28 Thread Christophe Leroy
On FSL_BOOK3E, _PAGE_RW is defined with two bits, one for user and one
for supervisor. As soon as one of the two bits is set, the page has
to be display as RW. But the way it is implemented today requires both
bits to be set in order to display it as RW.

Instead of display RW when _PAGE_RW bits are set and R otherwise,
reverse the logic and display R when _PAGE_RW bits are all 0 and
RW otherwise.

This change has no impact on other platforms as _PAGE_RW is a single
bit on all of them.

Fixes: 8eb07b187000 ("powerpc/mm: Dump linux pagetables")
Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/mm/ptdump/shared.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/mm/ptdump/shared.c b/arch/powerpc/mm/ptdump/shared.c
index 03607ab90c66..f884760ca5cf 100644
--- a/arch/powerpc/mm/ptdump/shared.c
+++ b/arch/powerpc/mm/ptdump/shared.c
@@ -17,9 +17,9 @@ static const struct flag_info flag_array[] = {
.clear  = "",
}, {
.mask   = _PAGE_RW,
-   .val= _PAGE_RW,
-   .set= "rw",
-   .clear  = "r ",
+   .val= 0,
+   .set= "r ",
+   .clear  = "rw",
}, {
.mask   = _PAGE_EXEC,
.val= _PAGE_EXEC,
-- 
2.36.1



[PATCH v1 3/6] powerpc/64e: Remove unused REGION related macros

2022-06-28 Thread Christophe Leroy
Those macros are not used anywhere. Remove them as they are soon
going to be wrong and are not worth modifying as they are not used.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/nohash/64/pgtable.h | 12 
 1 file changed, 12 deletions(-)

diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h 
b/arch/powerpc/include/asm/nohash/64/pgtable.h
index 57083f95e82b..db9770995f7c 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -57,18 +57,6 @@
 #define IOREMAP_END(KERN_VIRT_START + KERN_VIRT_SIZE - FIXADDR_SIZE)
 #define FIXADDR_SIZE   SZ_32M
 
-
-/*
- * Region IDs
- */
-#define REGION_SHIFT   60UL
-#define REGION_MASK(0xfUL << REGION_SHIFT)
-#define REGION_ID(ea)  (((unsigned long)(ea)) >> REGION_SHIFT)
-
-#define VMALLOC_REGION_ID  (REGION_ID(VMALLOC_START))
-#define KERNEL_REGION_ID   (REGION_ID(PAGE_OFFSET))
-#define USER_REGION_ID (0UL)
-
 /*
  * Defines the address of the vmemap area, in its own region on
  * after the vmalloc space on Book3E
-- 
2.36.1



[PATCH v1 1/6] powerpc/64e: Fix early TLB miss with KUAP

2022-06-28 Thread Christophe Leroy
With KUAP, the TLB miss handler bails out when an access to user
memory is performed with a nul TID.

But the normal TLB miss routine which is only used early during boot
does the check regardless for all memory areas, not only user memory.

By chance there is no early IO or vmalloc access, but when KASAN
come we will start having early TLB misses.

Fix it by creating a special branch for user accesses similar to the
one in the 'bolted' TLB miss handlers. Unfortunately SPRN_MAS1 is
now read too early and there are no registers available to preserve
it so it will be read a second time.

Fixes: 57bc963837f5 ("powerpc/kuap: Wire-up KUAP on book3e/64")
Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/mm/nohash/tlb_low_64e.S | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/mm/nohash/tlb_low_64e.S 
b/arch/powerpc/mm/nohash/tlb_low_64e.S
index 8b97c4acfebf..9e9ab3803fb2 100644
--- a/arch/powerpc/mm/nohash/tlb_low_64e.S
+++ b/arch/powerpc/mm/nohash/tlb_low_64e.S
@@ -583,7 +583,7 @@ itlb_miss_fault_e6500:
 */
rlwimi  r11,r14,32-19,27,27
rlwimi  r11,r14,32-16,19,19
-   beq normal_tlb_miss
+   beq normal_tlb_miss_user
/* XXX replace the RMW cycles with immediate loads + writes */
 1: mfspr   r10,SPRN_MAS1
cmpldi  cr0,r15,8   /* Check for vmalloc region */
@@ -626,7 +626,7 @@ itlb_miss_fault_e6500:
 
cmpldi  cr0,r15,0   /* Check for user region */
std r14,EX_TLB_ESR(r12) /* write crazy -1 to frame */
-   beq normal_tlb_miss
+   beq normal_tlb_miss_user
 
li  r11,_PAGE_PRESENT|_PAGE_BAP_SX  /* Base perm */
orisr11,r11,_PAGE_ACCESSED@h
@@ -653,6 +653,12 @@ itlb_miss_fault_e6500:
  * r11 = PTE permission mask
  * r10 = crap (free to use)
  */
+normal_tlb_miss_user:
+#ifdef CONFIG_PPC_KUAP
+   mfspr   r14,SPRN_MAS1
+   rlwinm. r14,r14,0,0x3fff
+   beq-normal_tlb_miss_access_fault /* KUAP fault */
+#endif
 normal_tlb_miss:
/* So we first construct the page table address. We do that by
 * shifting the bottom of the address (not the region ID) by
@@ -683,11 +689,6 @@ 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:
 *
@@ -709,9 +710,7 @@ finish_normal_tlb_miss:
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
-- 
2.36.1



[PATCH v1 2/6] powerpc/64e: Remove MMU_FTR_USE_TLBRSRV and MMU_FTR_USE_PAIRED_MAS

2022-06-28 Thread Christophe Leroy
Commit fb5a515704d7 ("powerpc: Remove platforms/wsp and associated
pieces") removed the last CPU having features MMU_FTRS_A2 and
commit cd68098bcedd ("powerpc: Clean up MMU_FTRS_A2 and
MMU_FTR_TYPE_3E") removed MMU_FTRS_A2 which was the last user of
MMU_FTR_USE_TLBRSRV and MMU_FTR_USE_PAIRED_MAS.

Remove all code that relies on MMU_FTR_USE_TLBRSRV and
MMU_FTR_USE_PAIRED_MAS.

With this change done, TLB miss can happen before the mmu feature
fixups.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/mmu.h  | 12 
 arch/powerpc/kernel/setup_64.c  |  1 -
 arch/powerpc/mm/nohash/book3e_hugetlbpage.c | 30 +++---
 arch/powerpc/mm/nohash/tlb_low_64e.S| 66 -
 4 files changed, 8 insertions(+), 101 deletions(-)

diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index 5f41565a1e5d..860d0290ca4d 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -96,15 +96,6 @@
  */
 #define MMU_FTR_NEED_DTLB_SW_LRU   ASM_CONST(0x0020)
 
-/* Enable use of TLB reservation.  Processor should support tlbsrx.
- * instruction and MAS0[WQ].
- */
-#define MMU_FTR_USE_TLBRSRVASM_CONST(0x0080)
-
-/* Use paired MAS registers (MAS7||MAS3, etc.)
- */
-#define MMU_FTR_USE_PAIRED_MAS ASM_CONST(0x0100)
-
 /* Doesn't support the B bit (1T segment) in SLBIE
  */
 #define MMU_FTR_NO_SLBIE_B ASM_CONST(0x0200)
@@ -180,9 +171,6 @@ enum {
 #ifdef CONFIG_PPC_83xx
MMU_FTR_NEED_DTLB_SW_LRU |
 #endif
-#ifdef CONFIG_PPC_BOOK3E_64
-   MMU_FTR_USE_TLBRSRV | MMU_FTR_USE_PAIRED_MAS |
-#endif
 #ifdef CONFIG_PPC_BOOK3S_64
MMU_FTR_KERNEL_RO |
 #ifdef CONFIG_PPC_64S_HASH_MMU
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 5761f08dae95..2b2d0b0fbb30 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -113,7 +113,6 @@ void __init setup_tlb_core_data(void)
 * Should we panic instead?
 */
WARN_ONCE(smt_enabled_at_boot >= 2 &&
- !mmu_has_feature(MMU_FTR_USE_TLBRSRV) &&
  book3e_htw_mode != PPC_HTW_E6500,
  "%s: unsupported MMU configuration\n", __func__);
}
diff --git a/arch/powerpc/mm/nohash/book3e_hugetlbpage.c 
b/arch/powerpc/mm/nohash/book3e_hugetlbpage.c
index 307ca919d393..c7d4b317a823 100644
--- a/arch/powerpc/mm/nohash/book3e_hugetlbpage.c
+++ b/arch/powerpc/mm/nohash/book3e_hugetlbpage.c
@@ -103,21 +103,11 @@ static inline int book3e_tlb_exists(unsigned long ea, 
unsigned long pid)
int found = 0;
 
mtspr(SPRN_MAS6, pid << 16);
-   if (mmu_has_feature(MMU_FTR_USE_TLBRSRV)) {
-   asm volatile(
-   "li %0,0\n"
-   "tlbsx. 0,%1\n"
-   "bne1f\n"
-   "li %0,1\n"
-   "1:\n"
-   : "=&r"(found) : "r"(ea));
-   } else {
-   asm volatile(
-   "tlbsx  0,%1\n"
-   "mfspr  %0,0x271\n"
-   "srwi   %0,%0,31\n"
-   : "=&r"(found) : "r"(ea));
-   }
+   asm volatile(
+   "tlbsx  0,%1\n"
+   "mfspr  %0,0x271\n"
+   "srwi   %0,%0,31\n"
+   : "=&r"(found) : "r"(ea));
 
return found;
 }
@@ -169,13 +159,9 @@ book3e_hugetlb_preload(struct vm_area_struct *vma, 
unsigned long ea, pte_t pte)
mtspr(SPRN_MAS1, mas1);
mtspr(SPRN_MAS2, mas2);
 
-   if (mmu_has_feature(MMU_FTR_USE_PAIRED_MAS)) {
-   mtspr(SPRN_MAS7_MAS3, mas7_3);
-   } else {
-   if (mmu_has_feature(MMU_FTR_BIG_PHYS))
-   mtspr(SPRN_MAS7, upper_32_bits(mas7_3));
-   mtspr(SPRN_MAS3, lower_32_bits(mas7_3));
-   }
+   if (mmu_has_feature(MMU_FTR_BIG_PHYS))
+   mtspr(SPRN_MAS7, upper_32_bits(mas7_3));
+   mtspr(SPRN_MAS3, lower_32_bits(mas7_3));
 
asm volatile ("tlbwe");
 
diff --git a/arch/powerpc/mm/nohash/tlb_low_64e.S 
b/arch/powerpc/mm/nohash/tlb_low_64e.S
index 9e9ab3803fb2..a59485c549a7 100644
--- a/arch/powerpc/mm/nohash/tlb_low_64e.S
+++ b/arch/powerpc/mm/nohash/tlb_low_64e.S
@@ -152,16 +152,7 @@ tlb_miss_common_bolted:
clrrdi  r15,r15,3
beq tlb_miss_fault_bolted   /* No PGDIR, bail */
 
-BEGIN_MMU_FTR_SECTION
-   /* Set the TLB reservation and search for existing entry. Then load
-* the entry.
-*/
-   PPC_TLBSRX_DOT(0,R16)
-   ldx r14,r14,r15 /* grab pgd entry */
-   beq tlb_miss_done_bolted/* tlb exists already, bail */
-MMU_FTR_SECTION_ELSE
ldx r14,r14,r15 /* grab pgd entry */
-ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBRSRV)
 
rldicl  r15,r16,64-PUD_SHIFT+3,64-PUD_INDEX_

[PATCH v1 5/6] powerpc/64e: Reorganise virtual memory

2022-06-28 Thread Christophe Leroy
Reduce the size of IO map in order to leave the last
quarter of virtual MAP for KASAN shadow mapping.

This gives the following layout.

   ++  Kernel virtual map end (0xc0002000)
   ||
   |16TB (unused)   |
   ||
   ++  Kernel IO map end
   ||
   |16TB of IO map  |
   ||
   ++  Kernel IO map start
   ||
   |16TB of vmemmap |
   ||
   ++  Kernel vmemmap start
   ||
   |16TB of vmap|
   ||
   ++  Kernel virt start (0xc0001000)
   ||
   |64TB of linear mem  |
   ||
   ++  Kernel linear (0xc.)

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/nohash/64/pgtable.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h 
b/arch/powerpc/include/asm/nohash/64/pgtable.h
index 76a144b58f9b..88906d9194c5 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -38,15 +38,16 @@
 #define VMALLOC_END(VMALLOC_START + VMALLOC_SIZE)
 
 /*
- * The second half of the kernel virtual space is used for IO mappings,
+ * The third quarter of the kernel virtual space is used for IO mappings,
  * it's itself carved into the PIO region (ISA and PHB IO space) and
  * the ioremap space
  *
  *  ISA_IO_BASE = KERN_IO_START, 64K reserved area
  *  PHB_IO_BASE = ISA_IO_BASE + 64K to ISA_IO_BASE + 2G, PHB IO spaces
- * IOREMAP_BASE = ISA_IO_BASE + 2G to VMALLOC_START + PGTABLE_RANGE
+ * IOREMAP_BASE = ISA_IO_BASE + 2G to KERN_IO_START + KERN_IO_SIZE
  */
 #define KERN_IO_START  (KERN_VIRT_START + (KERN_VIRT_SIZE >> 1))
+#define KERN_IO_SIZE   (KERN_VIRT_SIZE >> 2)
 #define FULL_IO_SIZE   0x8000ul
 #define  ISA_IO_BASE   (KERN_IO_START)
 #define  ISA_IO_END(KERN_IO_START + 0x1ul)
@@ -54,7 +55,7 @@
 #define  PHB_IO_END(KERN_IO_START + FULL_IO_SIZE)
 #define IOREMAP_BASE   (PHB_IO_END)
 #define IOREMAP_START  (ioremap_bot)
-#define IOREMAP_END(KERN_VIRT_START + KERN_VIRT_SIZE - FIXADDR_SIZE)
+#define IOREMAP_END(KERN_IO_START + KERN_IO_SIZE - FIXADDR_SIZE)
 #define FIXADDR_SIZE   SZ_32M
 
 /*
-- 
2.36.1



[PATCH v1 6/6] powerpc/64e: KASAN Full support for BOOK3E/64

2022-06-28 Thread Christophe Leroy
We now have memory organised in a way that allows
implementing KASAN.

Unlike book3s/64, book3e always has translation active so the only
thing needed to use KASAN is to setup an early zero shadow mapping
just after setting a stack pointer and before calling early_setup().

The memory layout is now as follows

   ++  Kernel virtual map end (0xc0002000)
   ||
   |16TB of KASAN map   |
   ||
   ++  Kernel KASAN shadow map start
   ||
   |16TB of IO map  |
   ||
   ++  Kernel IO map start
   ||
   |16TB of vmemmap |
   ||
   ++  Kernel vmemmap start
   ||
   |16TB of vmap|
   ||
   ++  Kernel virt start (0xc0001000)
   ||
   |64TB of linear mem  |
   ||
   ++  Kernel linear (0xc.)

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/Kconfig   |   2 +
 arch/powerpc/Kconfig.debug |   3 +-
 arch/powerpc/include/asm/kasan.h   |  13 ++-
 arch/powerpc/kernel/head_64.S  |   3 +
 arch/powerpc/mm/kasan/Makefile |   1 +
 arch/powerpc/mm/kasan/init_book3e_64.c | 133 +
 arch/powerpc/mm/kasan/init_book3s_64.c |   2 +
 arch/powerpc/platforms/Kconfig.cputype |   1 -
 8 files changed, 155 insertions(+), 3 deletions(-)
 create mode 100644 arch/powerpc/mm/kasan/init_book3e_64.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index c2ce2e60c8f0..92e0cad7752d 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -193,6 +193,7 @@ config PPC
select HAVE_ARCH_JUMP_LABEL_RELATIVE
select HAVE_ARCH_KASAN  if PPC32 && PPC_PAGE_SHIFT <= 14
select HAVE_ARCH_KASAN  if PPC_RADIX_MMU
+   select HAVE_ARCH_KASAN  if PPC_BOOK3E_64
select HAVE_ARCH_KASAN_VMALLOC  if HAVE_ARCH_KASAN
select HAVE_ARCH_KFENCE if PPC_BOOK3S_32 || PPC_8xx || 
40x
select HAVE_ARCH_KGDB
@@ -254,6 +255,7 @@ config PPC
select IOMMU_HELPER if PPC64
select IRQ_DOMAIN
select IRQ_FORCED_THREADING
+   select KASAN_VMALLOCif KASAN && MODULES
select MMU_GATHER_PAGE_SIZE
select MMU_GATHER_RCU_TABLE_FREE
select MODULES_USE_ELF_RELA
diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 9f363c143d86..6a8855d45af7 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -375,4 +375,5 @@ config KASAN_SHADOW_OFFSET
hex
depends on KASAN
default 0xe000 if PPC32
-   default 0xa80e if PPC64
+   default 0xa80e if PPC_BOOK3S_64
+   default 0xa8001c00 if PPC_BOOK3E_64
diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h
index a6be4025cba2..92a968202ba7 100644
--- a/arch/powerpc/include/asm/kasan.h
+++ b/arch/powerpc/include/asm/kasan.h
@@ -19,7 +19,7 @@
 
 #define KASAN_SHADOW_SCALE_SHIFT   3
 
-#ifdef CONFIG_MODULES
+#if defined(CONFIG_MODULES) && defined(CONFIG_PPC32)
 #define KASAN_KERN_START   ALIGN_DOWN(PAGE_OFFSET - SZ_256M, SZ_256M)
 #else
 #define KASAN_KERN_START   PAGE_OFFSET
@@ -39,6 +39,17 @@
  * c00e << 3 + a80e = c00fc000
  */
 #define KASAN_SHADOW_END 0xc00fc000UL
+
+#else
+
+/*
+ * The shadow ends before the highest accessible address
+ * because we don't need a shadow for the shadow.
+ * But it doesn't hurt to have a shadow for the shadow,
+ * keep shadow end aligned eases things.
+ */
+#define KASAN_SHADOW_END 0xc0002000UL
+
 #endif
 
 #ifdef CONFIG_KASAN
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index d3eea633d11a..cf2c08902c05 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -965,6 +965,9 @@ start_here_multiplatform:
 * and SLB setup before we turn on relocation.
 */
 
+#ifdef CONFIG_KASAN
+   bl  kasan_early_init
+#endif
/* Restore parameters passed from prom_init/kexec */
mr  r3,r31
LOAD_REG_ADDR(r12, DOTSYM(early_setup))
diff --git a/arch/powerpc/mm/kasan/Makefile b/arch/powerpc/mm/kasan/Makefile
index 4999aadb1867..699eeffd9f55 100644
--- a/arch/powerpc/mm/kasan/Makefile
+++ b/arch/powerpc/mm/kasan/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_PPC32) += init_32.o
 obj-$(CONFIG_PPC_8xx)  += 8xx.o
 obj-$(CONFIG_PPC_BOOK3S_32)+= book3s_32.o
 obj-$(CONFIG_PPC_BOOK3S_64)+= init_book3s_64.o
+obj-$(CONFIG_PPC_BOOK3E_64)+= init_book3e_64.o
diff --git a/arch/powerpc/mm/kasan/init_book3e_64.c 
b/arch/powerpc/m

[PATCH v1 4/6] powerpc/64e: Move virtual memory closer to linear memory

2022-06-28 Thread Christophe Leroy
Today nohash/64 have linear memory based at 0xc000 and
virtual memory based at 0x8000.

In order to implement KASAN, we need to regroup both areas.

Move virtual memmory at 0xc0001000.

This complicates a bit TLB miss handlers. Until now, memory region
was easily identified with the 4 higher bits of address:
- 0 ==> User
- c ==> Linear Memory
- 8 ==> Virtual Memory

Now we need to rely on the 20 higher bits, with:
- 0 ==> User
- c ==> Linear Memory
- c0001 ==> Virtual Memory

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/nohash/64/pgtable.h |  2 +-
 arch/powerpc/mm/nohash/tlb_low_64e.S | 64 +++-
 2 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h 
b/arch/powerpc/include/asm/nohash/64/pgtable.h
index db9770995f7c..76a144b58f9b 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -25,7 +25,7 @@
 /*
  * Define the address range of the kernel non-linear virtual area
  */
-#define KERN_VIRT_START ASM_CONST(0x8000)
+#define KERN_VIRT_START ASM_CONST(0xc0001000)
 #define KERN_VIRT_SIZE ASM_CONST(0x1000)
 
 /*
diff --git a/arch/powerpc/mm/nohash/tlb_low_64e.S 
b/arch/powerpc/mm/nohash/tlb_low_64e.S
index a59485c549a7..68ffbfdba894 100644
--- a/arch/powerpc/mm/nohash/tlb_low_64e.S
+++ b/arch/powerpc/mm/nohash/tlb_low_64e.S
@@ -213,10 +213,11 @@ itlb_miss_kernel_bolted:
 tlb_miss_kernel_bolted:
mfspr   r10,SPRN_MAS1
ld  r14,PACA_KERNELPGD(r13)
-   cmpldi  cr0,r15,8   /* Check for vmalloc region */
+   srdir15,r16,44  /* get kernel region */
+   andi.   r15,r15,1   /* Check for vmalloc region */
rlwinm  r10,r10,0,16,1  /* Clear TID */
mtspr   SPRN_MAS1,r10
-   beq+tlb_miss_common_bolted
+   bne+tlb_miss_common_bolted
 
 tlb_miss_fault_bolted:
/* We need to check if it was an instruction miss */
@@ -498,7 +499,9 @@ tlb_miss_huge_e6500:
 
 tlb_miss_kernel_e6500:
ld  r14,PACA_KERNELPGD(r13)
-   cmpldi  cr1,r15,8   /* Check for vmalloc region */
+   srdir15,r16,44  /* get kernel region */
+   xoris   r15,r15,0xc /* Check for vmalloc region */
+   cmplwi  cr1,r15,1
beq+cr1,tlb_miss_common_e6500
 
 tlb_miss_fault_e6500:
@@ -532,16 +535,18 @@ itlb_miss_fault_e6500:
 */
mfspr   r14,SPRN_ESR
mfspr   r16,SPRN_DEAR   /* get faulting address */
-   srdir15,r16,60  /* get region */
-   cmpldi  cr0,r15,0xc /* linear mapping ? */
+   srdir15,r16,44  /* get region */
+   xoris   r15,r15,0xc
+   cmpldi  cr0,r15,0   /* linear mapping ? */
beq tlb_load_linear /* yes -> go to linear map load */
+   cmpldi  cr1,r15,1   /* vmalloc mapping ? */
 
/* The page tables are mapped virtually linear. At this point, though,
 * we don't know whether we are trying to fault in a first level
 * virtual address or a virtual page table address. We can get that
 * from bit 0x1 of the region ID which we have set for a page table
 */
-   andi.   r10,r15,0x1
+   andis.  r10,r15,0x1
bne-virt_page_table_tlb_miss
 
std r14,EX_TLB_ESR(r12);/* save ESR */
@@ -553,7 +558,7 @@ itlb_miss_fault_e6500:
 
/* We do the user/kernel test for the PID here along with the RW test
 */
-   cmpldi  cr0,r15,0   /* Check for user region */
+   srdi.   r15,r16,60  /* Check for user region */
 
/* We pre-test some combination of permissions to avoid double
 * faults:
@@ -577,10 +582,9 @@ itlb_miss_fault_e6500:
beq normal_tlb_miss_user
/* XXX replace the RMW cycles with immediate loads + writes */
 1: mfspr   r10,SPRN_MAS1
-   cmpldi  cr0,r15,8   /* Check for vmalloc region */
rlwinm  r10,r10,0,16,1  /* Clear TID */
mtspr   SPRN_MAS1,r10
-   beq+normal_tlb_miss
+   beq+cr1,normal_tlb_miss
 
/* We got a crappy address, just fault with whatever DEAR and ESR
 * are here
@@ -606,16 +610,18 @@ itlb_miss_fault_e6500:
 *
 * Faulting address is SRR0 which is already in r16
 */
-   srdir15,r16,60  /* get region */
-   cmpldi  cr0,r15,0xc /* linear mapping ? */
+   srdir15,r16,44  /* get region */
+   xoris   r15,r15,0xc
+   cmpldi  cr0,r15,0   /* linear mapping ? */
beq tlb_load_linear /* yes -> go to linear map load */
+   cmpldi  cr1,r15,1   /* vmalloc mapping ? */
 
/* We do the user/kernel test for the PID here along with the RW test
 */

Re: [PATCH 08/10] scsi/ibmvfc: Replace tasklet with work

2022-06-28 Thread Davidlohr Bueso

On Thu, 09 Jun 2022, Sebastian Andrzej Siewior wrote:


On 2022-05-30 16:15:10 [-0700], Davidlohr Bueso wrote:

diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index d0eab5700dc5..31b1900489e7 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -891,7 +891,7 @@ static void ibmvfc_release_crq_queue(struct ibmvfc_host 
*vhost)

ibmvfc_dbg(vhost, "Releasing CRQ\n");
free_irq(vdev->irq, vhost);
-   tasklet_kill(&vhost->tasklet);
+cancel_work_sync(&vhost->work);

s/ {8}/\t/

is there a reason not to use threaded interrupts?


I went with a workqueue here because the resume from suspend also schedules
async processing, so threaded irqs didn't seem like a good fit. This is also
similar to patch 2 (but in that case I overlooked the resume caller which you
pointed out).

Thanks,
Davidlohr


[PATCH v4.14] kexec_file: drop weak attribute from arch_kexec_apply_relocations[_add]

2022-06-28 Thread Naveen N. Rao
commit 3e35142ef99fe6b4fe5d834ad43ee13cca10a2dc upstream.

Since commit d1bcae833b32f1 ("ELF: Don't generate unused section
symbols") [1], binutils (v2.36+) started dropping section symbols that
it thought were unused.  This isn't an issue in general, but with
kexec_file.c, gcc is placing kexec_arch_apply_relocations[_add] into a
separate .text.unlikely section and the section symbol ".text.unlikely"
is being dropped. Due to this, recordmcount is unable to find a non-weak
symbol in .text.unlikely to generate a relocation record against.

Address this by dropping the weak attribute from these functions.
Instead, follow the existing pattern of having architectures #define the
name of the function they want to override in their headers.

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1

[a...@linux-foundation.org: arch/s390/include/asm/kexec.h needs linux/module.h]
Link: 
https://lkml.kernel.org/r/20220519091237.676736-1-naveen.n@linux.vnet.ibm.com
Signed-off-by: Michael Ellerman 
Signed-off-by: Naveen N. Rao 
Cc: "Eric W. Biederman" 
Cc: 
Signed-off-by: Andrew Morton 
---
 arch/x86/include/asm/kexec.h |  6 ++
 include/linux/kexec.h| 26 ++
 kernel/kexec_file.c  | 18 --
 3 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h
index 5125fca472bb0b..e699819bf7b349 100644
--- a/arch/x86/include/asm/kexec.h
+++ b/arch/x86/include/asm/kexec.h
@@ -21,6 +21,7 @@
 #ifndef __ASSEMBLY__
 
 #include 
+#include 
 
 #include 
 #include 
@@ -217,6 +218,11 @@ extern int arch_kexec_post_alloc_pages(void *vaddr, 
unsigned int pages,
 extern void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages);
 #define arch_kexec_pre_free_pages arch_kexec_pre_free_pages
 
+#ifdef CONFIG_KEXEC_FILE
+int arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr,
+Elf_Shdr *sechdrs, unsigned int relsec);
+#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
+#endif
 #endif
 
 typedef void crash_vmclear_fn(void);
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 1ce6ba5f04077d..07578da0e2f5b1 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -163,6 +163,28 @@ int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
   int (*func)(u64, u64, void *));
 extern int kexec_add_buffer(struct kexec_buf *kbuf);
 int kexec_locate_mem_hole(struct kexec_buf *kbuf);
+
+#ifndef arch_kexec_apply_relocations_add
+/* Apply relocations of type RELA */
+static inline int
+arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr,
+Elf_Shdr *sechdrs, unsigned int relsec)
+{
+   pr_err("RELA relocation unsupported.\n");
+   return -ENOEXEC;
+}
+#endif
+
+#ifndef arch_kexec_apply_relocations
+/* Apply relocations of type REL */
+static inline int
+arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
+unsigned int relsec)
+{
+   pr_err("REL relocation unsupported.\n");
+   return -ENOEXEC;
+}
+#endif
 #endif /* CONFIG_KEXEC_FILE */
 
 struct kimage {
@@ -288,10 +310,6 @@ void * __weak arch_kexec_kernel_image_load(struct kimage 
*image);
 int __weak arch_kimage_file_post_load_cleanup(struct kimage *image);
 int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
unsigned long buf_len);
-int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr,
-   Elf_Shdr *sechdrs, unsigned int relsec);
-int __weak arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr 
*sechdrs,
-   unsigned int relsec);
 void arch_kexec_protect_crashkres(void);
 void arch_kexec_unprotect_crashkres(void);
 
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index 9d979b2954ef7f..4e95641e8dd6ec 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -53,24 +53,6 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage 
*image, void *buf,
 }
 #endif
 
-/* Apply relocations of type RELA */
-int __weak
-arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
-unsigned int relsec)
-{
-   pr_err("RELA relocation unsupported.\n");
-   return -ENOEXEC;
-}
-
-/* Apply relocations of type REL */
-int __weak
-arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
-unsigned int relsec)
-{
-   pr_err("REL relocation unsupported.\n");
-   return -ENOEXEC;
-}
-
 /*
  * Free up memory used by kernel, initrd, and command line. This is temporary
  * memory allocation which is not needed any more after these buffers have

base-commit: f051383ef03bde49ca992f297ec80757a702e774
-- 
2.36.1



[PATCH v4.19] kexec_file: drop weak attribute from arch_kexec_apply_relocations[_add]

2022-06-28 Thread Naveen N. Rao
commit 3e35142ef99fe6b4fe5d834ad43ee13cca10a2dc upstream.

Since commit d1bcae833b32f1 ("ELF: Don't generate unused section
symbols") [1], binutils (v2.36+) started dropping section symbols that
it thought were unused.  This isn't an issue in general, but with
kexec_file.c, gcc is placing kexec_arch_apply_relocations[_add] into a
separate .text.unlikely section and the section symbol ".text.unlikely"
is being dropped. Due to this, recordmcount is unable to find a non-weak
symbol in .text.unlikely to generate a relocation record against.

Address this by dropping the weak attribute from these functions.
Instead, follow the existing pattern of having architectures #define the
name of the function they want to override in their headers.

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1

[a...@linux-foundation.org: arch/s390/include/asm/kexec.h needs linux/module.h]
Link: 
https://lkml.kernel.org/r/20220519091237.676736-1-naveen.n@linux.vnet.ibm.com
Signed-off-by: Michael Ellerman 
Signed-off-by: Naveen N. Rao 
Cc: "Eric W. Biederman" 
Cc: 
Signed-off-by: Andrew Morton 
---
 arch/s390/include/asm/kexec.h | 10 
 arch/x86/include/asm/kexec.h  |  9 +++
 include/linux/kexec.h | 46 +--
 kernel/kexec_file.c   | 34 --
 4 files changed, 57 insertions(+), 42 deletions(-)

diff --git a/arch/s390/include/asm/kexec.h b/arch/s390/include/asm/kexec.h
index 825dd0f7f22118..ba9b0e76470c52 100644
--- a/arch/s390/include/asm/kexec.h
+++ b/arch/s390/include/asm/kexec.h
@@ -9,6 +9,8 @@
 #ifndef _S390_KEXEC_H
 #define _S390_KEXEC_H
 
+#include 
+
 #include 
 #include 
 /*
@@ -69,4 +71,12 @@ int *kexec_file_update_kernel(struct kimage *iamge,
 extern const struct kexec_file_ops s390_kexec_image_ops;
 extern const struct kexec_file_ops s390_kexec_elf_ops;
 
+#ifdef CONFIG_KEXEC_FILE
+struct purgatory_info;
+int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
+Elf_Shdr *section,
+const Elf_Shdr *relsec,
+const Elf_Shdr *symtab);
+#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
+#endif
 #endif /*_S390_KEXEC_H */
diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h
index 5125fca472bb0b..0a41c62369f2cb 100644
--- a/arch/x86/include/asm/kexec.h
+++ b/arch/x86/include/asm/kexec.h
@@ -21,6 +21,7 @@
 #ifndef __ASSEMBLY__
 
 #include 
+#include 
 
 #include 
 #include 
@@ -217,6 +218,14 @@ extern int arch_kexec_post_alloc_pages(void *vaddr, 
unsigned int pages,
 extern void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages);
 #define arch_kexec_pre_free_pages arch_kexec_pre_free_pages
 
+#ifdef CONFIG_KEXEC_FILE
+struct purgatory_info;
+int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
+Elf_Shdr *section,
+const Elf_Shdr *relsec,
+const Elf_Shdr *symtab);
+#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
+#endif
 #endif
 
 typedef void crash_vmclear_fn(void);
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index fe9f6f2dd811d2..29bffbc6d73aa7 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -174,14 +174,6 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, 
const char *name,
   bool get_value);
 void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name);
 
-int __weak arch_kexec_apply_relocations_add(struct purgatory_info *pi,
-   Elf_Shdr *section,
-   const Elf_Shdr *relsec,
-   const Elf_Shdr *symtab);
-int __weak arch_kexec_apply_relocations(struct purgatory_info *pi,
-   Elf_Shdr *section,
-   const Elf_Shdr *relsec,
-   const Elf_Shdr *symtab);
 
 int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
   int (*func)(struct resource *, void *));
@@ -206,6 +198,44 @@ extern int crash_exclude_mem_range(struct crash_mem *mem,
   unsigned long long mend);
 extern int crash_prepare_elf64_headers(struct crash_mem *mem, int kernel_map,
   void **addr, unsigned long *sz);
+
+#ifndef arch_kexec_apply_relocations_add
+/*
+ * arch_kexec_apply_relocations_add - apply relocations of type RELA
+ * @pi:Purgatory to be relocated.
+ * @section:   Section relocations applying to.
+ * @relsec:Section containing RELAs.
+ * @symtab:Corresponding symtab.
+ *
+ * Return: 0 on success, negative errno on error.
+ */
+static inline int
+arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *s

[PATCH v4.9] kexec_file: drop weak attribute from arch_kexec_apply_relocations[_add]

2022-06-28 Thread Naveen N. Rao
commit 3e35142ef99fe6b4fe5d834ad43ee13cca10a2dc upstream.

Since commit d1bcae833b32f1 ("ELF: Don't generate unused section
symbols") [1], binutils (v2.36+) started dropping section symbols that
it thought were unused.  This isn't an issue in general, but with
kexec_file.c, gcc is placing kexec_arch_apply_relocations[_add] into a
separate .text.unlikely section and the section symbol ".text.unlikely"
is being dropped. Due to this, recordmcount is unable to find a non-weak
symbol in .text.unlikely to generate a relocation record against.

Address this by dropping the weak attribute from these functions.
Instead, follow the existing pattern of having architectures #define the
name of the function they want to override in their headers.

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1

[a...@linux-foundation.org: arch/s390/include/asm/kexec.h needs linux/module.h]
Link: 
https://lkml.kernel.org/r/20220519091237.676736-1-naveen.n@linux.vnet.ibm.com
Signed-off-by: Michael Ellerman 
Signed-off-by: Naveen N. Rao 
Cc: "Eric W. Biederman" 
Cc: 
Signed-off-by: Andrew Morton 
---
 arch/x86/include/asm/kexec.h |  7 +++
 include/linux/kexec.h| 26 ++
 kernel/kexec_file.c  | 18 --
 3 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h
index 1624a7ffa95d89..3f1f58c1a9ce63 100644
--- a/arch/x86/include/asm/kexec.h
+++ b/arch/x86/include/asm/kexec.h
@@ -20,6 +20,7 @@
 #ifndef __ASSEMBLY__
 
 #include 
+#include 
 
 #include 
 #include 
@@ -206,6 +207,12 @@ struct kexec_entry64_regs {
uint64_t r15;
uint64_t rip;
 };
+
+#ifdef CONFIG_KEXEC_FILE
+int arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr,
+Elf_Shdr *sechdrs, unsigned int relsec);
+#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
+#endif
 #endif
 
 typedef void crash_vmclear_fn(void);
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 406c33dcae137a..565be657098b0b 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -148,6 +148,28 @@ struct kexec_file_ops {
kexec_verify_sig_t *verify_sig;
 #endif
 };
+
+#ifndef arch_kexec_apply_relocations_add
+/* Apply relocations of type RELA */
+static inline int
+arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr,
+Elf_Shdr *sechdrs, unsigned int relsec)
+{
+   pr_err("RELA relocation unsupported.\n");
+   return -ENOEXEC;
+}
+#endif
+
+#ifndef arch_kexec_apply_relocations
+/* Apply relocations of type REL */
+static inline int
+arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
+unsigned int relsec)
+{
+   pr_err("REL relocation unsupported.\n");
+   return -ENOEXEC;
+}
+#endif
 #endif
 
 struct kimage {
@@ -320,10 +342,6 @@ void * __weak arch_kexec_kernel_image_load(struct kimage 
*image);
 int __weak arch_kimage_file_post_load_cleanup(struct kimage *image);
 int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
unsigned long buf_len);
-int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr,
-   Elf_Shdr *sechdrs, unsigned int relsec);
-int __weak arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr 
*sechdrs,
-   unsigned int relsec);
 void arch_kexec_protect_crashkres(void);
 void arch_kexec_unprotect_crashkres(void);
 
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index 2edaed6803ff79..eb775e699836ad 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -59,24 +59,6 @@ int __weak arch_kexec_kernel_verify_sig(struct kimage 
*image, void *buf,
 }
 #endif
 
-/* Apply relocations of type RELA */
-int __weak
-arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
-unsigned int relsec)
-{
-   pr_err("RELA relocation unsupported.\n");
-   return -ENOEXEC;
-}
-
-/* Apply relocations of type REL */
-int __weak
-arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
-unsigned int relsec)
-{
-   pr_err("REL relocation unsupported.\n");
-   return -ENOEXEC;
-}
-
 /*
  * Free up memory used by kernel, initrd, and command line. This is temporary
  * memory allocation which is not needed any more after these buffers have

base-commit: 4ffa4be5a14beeb008bd2b4fbc681222bfec90c7
-- 
2.36.1



[PATCH v5.4] kexec_file: drop weak attribute from arch_kexec_apply_relocations[_add]

2022-06-28 Thread Naveen N. Rao
commit 3e35142ef99fe6b4fe5d834ad43ee13cca10a2dc upstream.

Since commit d1bcae833b32f1 ("ELF: Don't generate unused section
symbols") [1], binutils (v2.36+) started dropping section symbols that
it thought were unused.  This isn't an issue in general, but with
kexec_file.c, gcc is placing kexec_arch_apply_relocations[_add] into a
separate .text.unlikely section and the section symbol ".text.unlikely"
is being dropped. Due to this, recordmcount is unable to find a non-weak
symbol in .text.unlikely to generate a relocation record against.

Address this by dropping the weak attribute from these functions.
Instead, follow the existing pattern of having architectures #define the
name of the function they want to override in their headers.

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1

[a...@linux-foundation.org: arch/s390/include/asm/kexec.h needs linux/module.h]
Link: 
https://lkml.kernel.org/r/20220519091237.676736-1-naveen.n@linux.vnet.ibm.com
Signed-off-by: Michael Ellerman 
Signed-off-by: Naveen N. Rao 
Cc: "Eric W. Biederman" 
Cc: 
Signed-off-by: Andrew Morton 
---
 arch/s390/include/asm/kexec.h | 10 
 arch/x86/include/asm/kexec.h  |  9 +++
 include/linux/kexec.h | 46 +--
 kernel/kexec_file.c   | 34 --
 4 files changed, 57 insertions(+), 42 deletions(-)

diff --git a/arch/s390/include/asm/kexec.h b/arch/s390/include/asm/kexec.h
index 7f3c9ac34bd8d1..63098df81c9f2a 100644
--- a/arch/s390/include/asm/kexec.h
+++ b/arch/s390/include/asm/kexec.h
@@ -9,6 +9,8 @@
 #ifndef _S390_KEXEC_H
 #define _S390_KEXEC_H
 
+#include 
+
 #include 
 #include 
 #include 
@@ -83,4 +85,12 @@ struct kimage_arch {
 extern const struct kexec_file_ops s390_kexec_image_ops;
 extern const struct kexec_file_ops s390_kexec_elf_ops;
 
+#ifdef CONFIG_KEXEC_FILE
+struct purgatory_info;
+int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
+Elf_Shdr *section,
+const Elf_Shdr *relsec,
+const Elf_Shdr *symtab);
+#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
+#endif
 #endif /*_S390_KEXEC_H */
diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h
index 5e7d6b46de97d6..367da081f7d9d9 100644
--- a/arch/x86/include/asm/kexec.h
+++ b/arch/x86/include/asm/kexec.h
@@ -22,6 +22,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -201,6 +202,14 @@ extern int arch_kexec_post_alloc_pages(void *vaddr, 
unsigned int pages,
 extern void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages);
 #define arch_kexec_pre_free_pages arch_kexec_pre_free_pages
 
+#ifdef CONFIG_KEXEC_FILE
+struct purgatory_info;
+int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
+Elf_Shdr *section,
+const Elf_Shdr *relsec,
+const Elf_Shdr *symtab);
+#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
+#endif
 #endif
 
 typedef void crash_vmclear_fn(void);
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index a1cffce3de8cd7..64f23bab6255da 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -186,14 +186,6 @@ void *kexec_purgatory_get_symbol_addr(struct kimage 
*image, const char *name);
 int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
 unsigned long buf_len);
 void * __weak arch_kexec_kernel_image_load(struct kimage *image);
-int __weak arch_kexec_apply_relocations_add(struct purgatory_info *pi,
-   Elf_Shdr *section,
-   const Elf_Shdr *relsec,
-   const Elf_Shdr *symtab);
-int __weak arch_kexec_apply_relocations(struct purgatory_info *pi,
-   Elf_Shdr *section,
-   const Elf_Shdr *relsec,
-   const Elf_Shdr *symtab);
 
 extern int kexec_add_buffer(struct kexec_buf *kbuf);
 int kexec_locate_mem_hole(struct kexec_buf *kbuf);
@@ -216,6 +208,44 @@ extern int crash_exclude_mem_range(struct crash_mem *mem,
   unsigned long long mend);
 extern int crash_prepare_elf64_headers(struct crash_mem *mem, int kernel_map,
   void **addr, unsigned long *sz);
+
+#ifndef arch_kexec_apply_relocations_add
+/*
+ * arch_kexec_apply_relocations_add - apply relocations of type RELA
+ * @pi:Purgatory to be relocated.
+ * @section:   Section relocations applying to.
+ * @relsec:Section containing RELAs.
+ * @symtab:Corresponding symtab.
+ *
+ * Return: 0 on success, negative errno on error.
+ */
+static inline int
+arch_kexec_apply_relocations_add(struct purgatory_i

[PATCH v3 0/3] tpm: Preserve TPM measurement log across kexec (ppc64)

2022-06-28 Thread Stefan Berger
The of-tree subsystem does not currently preserve the IBM vTPM 1.2 and
vTPM 2.0 measurement logs across a kexec on ppc64. This series fixes this
for the kexec_file_load() syscall using the flattened device tree (fdt) to
carry the measurement log's buffer across kexec.

   Stefan

Stefan Berger (3):
  tpm: of: Make of-tree specific function commonly available
  of: kexec: Refactor IMA buffer related functions to make them reusable
  tpm/kexec: Duplicate TPM measurement log in of-tree for kexec

 drivers/char/Makefile  |   1 +
 drivers/char/tpm/Makefile  |   1 +
 drivers/char/tpm/eventlog/of.c |  31 +--
 drivers/char/tpm/eventlog/tpm_of.c |  27 +++
 drivers/of/kexec.c | 293 +
 include/linux/kexec.h  |   6 +
 include/linux/of.h |   8 +-
 include/linux/tpm.h|   5 +
 kernel/kexec_file.c|   6 +
 9 files changed, 315 insertions(+), 63 deletions(-)
 create mode 100644 drivers/char/tpm/eventlog/tpm_of.c

-- 
2.35.1



[PATCH v3 3/3] tpm/kexec: Duplicate TPM measurement log in of-tree for kexec

2022-06-28 Thread Stefan Berger
The memory area of the TPM measurement log is currently not properly
duplicated for carrying it across kexec when an Open Firmware
Devicetree is used. Therefore, the contents of the log get corrupted.
Fix this for the kexec_file_load() syscall by allocating a buffer and
copying the contents of the existing log into it. The new buffer is
preserved across the kexec and a pointer to it is available when the new
kernel is started. To achieve this, store the allocated buffer's address
in the flattened device tree (fdt) under the name linux,tpm-kexec-buffer
and search for this entry early in the kernel startup before the TPM
subsystem starts up. Adjust the pointer in the of-tree stored under
linux,sml-base to point to this buffer holding the preserved log. The TPM
driver can then read the base address from this entry when making the log
available.

Use postcore_initcall() to call the function to restore the buffer even if
the TPM subsystem or driver are not used. This allows the buffer to be
carried across the next kexec without involvement of the TPM subsystem
and ensures a valid buffer pointed to by the of-tree.

Signed-off-by: Stefan Berger 
Cc: Rob Herring 
Cc: Frank Rowand 
Cc: Eric Biederman 
---
 drivers/of/kexec.c| 198 +-
 include/linux/kexec.h |   6 ++
 include/linux/of.h|   8 +-
 kernel/kexec_file.c   |   6 ++
 4 files changed, 216 insertions(+), 2 deletions(-)

diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
index 601ea9727b0e..efc428b951db 100644
--- a/drivers/of/kexec.c
+++ b/drivers/of/kexec.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RNG_SEED_SIZE  128
 
@@ -220,7 +221,6 @@ static void remove_ima_buffer(void *fdt, int chosen_node)
remove_buffer(fdt, chosen_node, "linux,ima-kexec-buffer");
 }
 
-#ifdef CONFIG_IMA_KEXEC
 static int setup_buffer(void *fdt, int chosen_node, const char *name,
uint64_t addr, uint64_t size)
 {
@@ -242,6 +242,7 @@ static int setup_buffer(void *fdt, int chosen_node, const 
char *name,
 
 }
 
+#ifdef CONFIG_IMA_KEXEC
 /**
  * setup_ima_buffer - add IMA buffer information to the fdt
  * @image: kexec image being loaded.
@@ -274,6 +275,198 @@ static inline int setup_ima_buffer(const struct kimage 
*image, void *fdt,
 }
 #endif /* CONFIG_IMA_KEXEC */
 
+/**
+ * tpm_get_kexec_buffer - get TPM log buffer from the previous kernel
+ * @phyaddr:   On successful return, set to physical address of buffer
+ * @size:  On successful return, set to the buffer size.
+ *
+ * Return: 0 on success, negative errno on error.
+ */
+static int tpm_get_kexec_buffer(void **phyaddr, size_t *size)
+{
+   int ret;
+   unsigned long tmp_addr;
+   size_t tmp_size;
+
+   ret = get_kexec_buffer("linux,tpm-kexec-buffer", &tmp_addr, &tmp_size);
+   if (ret)
+   return ret;
+
+   *phyaddr = (void *)tmp_addr;
+   *size = tmp_size;
+
+   return 0;
+}
+
+/**
+ * tpm_of_remove_kexec_buffer - remove the linux,tpm-kexec-buffer node
+ */
+static int tpm_of_remove_kexec_buffer(void)
+{
+   struct property *prop;
+
+   prop = of_find_property(of_chosen, "linux,tpm-kexec-buffer", NULL);
+   if (!prop)
+   return -ENOENT;
+
+   return of_remove_property(of_chosen, prop);
+}
+
+/**
+ * remove_tpm_buffer - remove the TPM log buffer property and reservation from 
@fdt
+ *
+ * @fdt: Flattened Device Tree to update
+ * @chosen_node: Offset to the chosen node in the device tree
+ *
+ * The TPM log measurement buffer is of no use to a subsequent kernel, so we 
always
+ * remove it from the device tree.
+ */
+static void remove_tpm_buffer(void *fdt, int chosen_node)
+{
+   if (!IS_ENABLED(CONFIG_PPC64))
+   return;
+
+   remove_buffer(fdt, chosen_node, "linux,tpm-kexec-buffer");
+}
+
+/**
+ * setup_tpm_buffer - add TPM measurement log buffer information to the fdt
+ * @image: kexec image being loaded.
+ * @fdt:   Flattened device tree for the next kernel.
+ * @chosen_node:   Offset to the chosen node.
+ *
+ * Return: 0 on success, or negative errno on error.
+ */
+static int setup_tpm_buffer(const struct kimage *image, void *fdt,
+   int chosen_node)
+{
+   if (!IS_ENABLED(CONFIG_PPC64))
+   return 0;
+
+   return setup_buffer(fdt, chosen_node, "linux,tpm-kexec-buffer",
+   image->tpm_buffer_addr, image->tpm_buffer_size);
+}
+
+void tpm_add_kexec_buffer(struct kimage *image)
+{
+   struct kexec_buf kbuf = { .image = image, .buf_align = 1,
+ .buf_min = 0, .buf_max = ULONG_MAX,
+ .top_down = true };
+   struct device_node *np;
+   void *buffer;
+   u32 size;
+   u64 base;
+   int ret;
+
+   if (!IS_ENABLED(CONFIG_PPC64))
+   return;
+
+   np = of_find_node_by_name(NULL, "vtpm");
+   if (!np)
+   

[PATCH v3 1/3] tpm: of: Make of-tree specific function commonly available

2022-06-28 Thread Stefan Berger
Simplify tpm_read_log_of() by moving reusable parts of the code into
its own file to make the code commonly available so it can be used also
for kexec support. Call the new of_tpm_get_sml_parameters() function
from the TPM Open Firmware driver.

Compile the new file when CONFIG_OF is enabled so that
of_tpm_get_sml_parameters() can be called from kexec even if the TPM
subsystem is not enabled.

Signed-off-by: Stefan Berger 
Cc: Jarkko Sakkinen 
Cc: Jason Gunthorpe 
Cc: Rob Herring 
Cc: Frank Rowand 
---
 drivers/char/Makefile  |  1 +
 drivers/char/tpm/Makefile  |  1 +
 drivers/char/tpm/eventlog/of.c | 31 +-
 drivers/char/tpm/eventlog/tpm_of.c | 27 ++
 include/linux/tpm.h|  5 +
 5 files changed, 39 insertions(+), 26 deletions(-)
 create mode 100644 drivers/char/tpm/eventlog/tpm_of.c

diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 264eb398fdd4..af9edafb944e 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_PCMCIA)  += pcmcia/
 
 obj-$(CONFIG_HANGCHECK_TIMER)  += hangcheck-timer.o
 obj-$(CONFIG_TCG_TPM)  += tpm/
+obj-$(CONFIG_OF)   += tpm/
 
 obj-$(CONFIG_PS3_FLASH)+= ps3flash.o
 
diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index 66d39ea6bd10..3c0eaac81f5c 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -19,6 +19,7 @@ tpm-y += eventlog/tpm2.o
 tpm-$(CONFIG_ACPI) += tpm_ppi.o eventlog/acpi.o
 tpm-$(CONFIG_EFI) += eventlog/efi.o
 tpm-$(CONFIG_OF) += eventlog/of.o
+obj-$(CONFIG_OF) += eventlog/tpm_of.o
 obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
 obj-$(CONFIG_TCG_TIS) += tpm_tis.o
 obj-$(CONFIG_TCG_TIS_SYNQUACER) += tpm_tis_synquacer.o
diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c
index a9ce66d09a75..f9462d19632e 100644
--- a/drivers/char/tpm/eventlog/of.c
+++ b/drivers/char/tpm/eventlog/of.c
@@ -12,6 +12,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #include "../tpm.h"
@@ -20,11 +21,10 @@
 int tpm_read_log_of(struct tpm_chip *chip)
 {
struct device_node *np;
-   const u32 *sizep;
-   const u64 *basep;
struct tpm_bios_log *log;
u32 size;
u64 base;
+   int ret;
 
log = &chip->log;
if (chip->dev.parent && chip->dev.parent->of_node)
@@ -35,30 +35,9 @@ int tpm_read_log_of(struct tpm_chip *chip)
if (of_property_read_bool(np, "powered-while-suspended"))
chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;
 
-   sizep = of_get_property(np, "linux,sml-size", NULL);
-   basep = of_get_property(np, "linux,sml-base", NULL);
-   if (sizep == NULL && basep == NULL)
-   return -ENODEV;
-   if (sizep == NULL || basep == NULL)
-   return -EIO;
-
-   /*
-* For both vtpm/tpm, firmware has log addr and log size in big
-* endian format. But in case of vtpm, there is a method called
-* sml-handover which is run during kernel init even before
-* device tree is setup. This sml-handover function takes care
-* of endianness and writes to sml-base and sml-size in little
-* endian format. For this reason, vtpm doesn't need conversion
-* but physical tpm needs the conversion.
-*/
-   if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 &&
-   of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) {
-   size = be32_to_cpup((__force __be32 *)sizep);
-   base = be64_to_cpup((__force __be64 *)basep);
-   } else {
-   size = *sizep;
-   base = *basep;
-   }
+   ret = of_tpm_get_sml_parameters(np, &base, &size);
+   if (ret < 0)
+   return ret;
 
if (size == 0) {
dev_warn(&chip->dev, "%s: Event log area empty\n", __func__);
diff --git a/drivers/char/tpm/eventlog/tpm_of.c 
b/drivers/char/tpm/eventlog/tpm_of.c
new file mode 100644
index ..2e6cfcc87035
--- /dev/null
+++ b/drivers/char/tpm/eventlog/tpm_of.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+
+int of_tpm_get_sml_parameters(struct device_node *np, u64 *base, u32 *size)
+{
+   const u32 *sizep;
+   const u64 *basep;
+
+   sizep = of_get_property(np, "linux,sml-size", NULL);
+   basep = of_get_property(np, "linux,sml-base", NULL);
+   if (sizep == NULL && basep == NULL)
+   return -ENODEV;
+   if (sizep == NULL || basep == NULL)
+   return -EIO;
+
+   if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 &&
+   of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) {
+   *size = be32_to_cpup((__force __be32 *)sizep);
+   *base = be64_to_cpup((__force __be64 *)basep);
+   } else {
+   *size = *sizep;
+   *base = *basep;
+   }
+ 

[PATCH v3 2/3] of: kexec: Refactor IMA buffer related functions to make them reusable

2022-06-28 Thread Stefan Berger
Refactor IMA buffer related functions to make them reusable for carrying
TPM logs across kexec.

Signed-off-by: Stefan Berger 
Cc: Rob Herring 
Cc: Frank Rowand 
Cc: Mimi Zohar 
---
 drivers/of/kexec.c | 99 +-
 1 file changed, 62 insertions(+), 37 deletions(-)

diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
index b9bd1cff1793..601ea9727b0e 100644
--- a/drivers/of/kexec.c
+++ b/drivers/of/kexec.c
@@ -115,6 +115,18 @@ static int do_get_kexec_buffer(const void *prop, int len, 
unsigned long *addr,
return 0;
 }
 
+static int get_kexec_buffer(const char *name, unsigned long *addr, size_t 
*size)
+{
+   const void *prop;
+   int len;
+
+   prop = of_get_property(of_chosen, name, &len);
+   if (!prop)
+   return -ENOENT;
+
+   return do_get_kexec_buffer(prop, len, addr, size);
+}
+
 /**
  * ima_get_kexec_buffer - get IMA buffer from the previous kernel
  * @addr:  On successful return, set to point to the buffer contents.
@@ -124,19 +136,14 @@ static int do_get_kexec_buffer(const void *prop, int len, 
unsigned long *addr,
  */
 int ima_get_kexec_buffer(void **addr, size_t *size)
 {
-   int ret, len;
+   int ret;
unsigned long tmp_addr;
size_t tmp_size;
-   const void *prop;
 
if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC))
return -ENOTSUPP;
 
-   prop = of_get_property(of_chosen, "linux,ima-kexec-buffer", &len);
-   if (!prop)
-   return -ENOENT;
-
-   ret = do_get_kexec_buffer(prop, len, &tmp_addr, &tmp_size);
+   ret = get_kexec_buffer("linux,ima-kexec-buffer", &tmp_addr, &tmp_size);
if (ret)
return ret;
 
@@ -174,6 +181,28 @@ int ima_free_kexec_buffer(void)
return memblock_phys_free(addr, size);
 }
 
+static int remove_buffer(void *fdt, int chosen_node, const char *name)
+{
+   int ret, len;
+   unsigned long addr;
+   size_t size;
+   const void *prop;
+
+   prop = fdt_getprop(fdt, chosen_node, name, &len);
+   if (!prop)
+   return -ENOENT;
+
+   ret = do_get_kexec_buffer(prop, len, &addr, &size);
+   fdt_delprop(fdt, chosen_node, name);
+   if (ret)
+   return ret;
+
+   ret = fdt_find_and_del_mem_rsv(fdt, addr, size);
+   if (!ret)
+   pr_debug("Remove old %s buffer reserveration", name);
+   return ret;
+}
+
 /**
  * remove_ima_buffer - remove the IMA buffer property and reservation from @fdt
  *
@@ -185,29 +214,34 @@ int ima_free_kexec_buffer(void)
  */
 static void remove_ima_buffer(void *fdt, int chosen_node)
 {
-   int ret, len;
-   unsigned long addr;
-   size_t size;
-   const void *prop;
-
if (!IS_ENABLED(CONFIG_HAVE_IMA_KEXEC))
return;
 
-   prop = fdt_getprop(fdt, chosen_node, "linux,ima-kexec-buffer", &len);
-   if (!prop)
-   return;
+   remove_buffer(fdt, chosen_node, "linux,ima-kexec-buffer");
+}
 
-   ret = do_get_kexec_buffer(prop, len, &addr, &size);
-   fdt_delprop(fdt, chosen_node, "linux,ima-kexec-buffer");
+#ifdef CONFIG_IMA_KEXEC
+static int setup_buffer(void *fdt, int chosen_node, const char *name,
+   uint64_t addr, uint64_t size)
+{
+   int ret;
+
+   if (!size)
+   return 0;
+
+   ret = fdt_appendprop_addrrange(fdt, 0, chosen_node,
+  name, addr, size);
+   if (ret < 0)
+   return -EINVAL;
+
+   ret = fdt_add_mem_rsv(fdt, addr, size);
if (ret)
-   return;
+   return -EINVAL;
+
+   return 0;
 
-   ret = fdt_find_and_del_mem_rsv(fdt, addr, size);
-   if (!ret)
-   pr_debug("Removed old IMA buffer reservation.\n");
 }
 
-#ifdef CONFIG_IMA_KEXEC
 /**
  * setup_ima_buffer - add IMA buffer information to the fdt
  * @image: kexec image being loaded.
@@ -221,23 +255,14 @@ static int setup_ima_buffer(const struct kimage *image, 
void *fdt,
 {
int ret;
 
-   if (!image->ima_buffer_size)
-   return 0;
-
-   ret = fdt_appendprop_addrrange(fdt, 0, chosen_node,
-  "linux,ima-kexec-buffer",
-  image->ima_buffer_addr,
-  image->ima_buffer_size);
-   if (ret < 0)
-   return -EINVAL;
-
-   ret = fdt_add_mem_rsv(fdt, image->ima_buffer_addr,
- image->ima_buffer_size);
+   ret = setup_buffer(fdt, chosen_node, "linux,ima-kexec-buffer",
+  image->ima_buffer_addr, image->ima_buffer_size);
if (ret)
-   return -EINVAL;
+   return ret;
 
-   pr_debug("IMA buffer at 0x%llx, size = 0x%zx\n",
-image->ima_buffer_addr, image->ima_buffer_size);
+   if (image->ima_buffer_addr)
+   pr_debug("IMA buffer at 0x%llx, size = 0x%zx\n

Re: [PATCH v3 5/5] powerpc/pseries: use of_property_alloc/free() and of_node_alloc()

2022-06-28 Thread Christophe Leroy


Le 20/06/2022 à 12:41, Clément Léger a écrit :
> Use of_property_alloc/free() and of_node_alloc() to create and free
> device-tree nodes and properties. In order to obtain something cleaner
> and allow using only of_node_put() instead of manual property deletion,
> a rework of the usage of node in reconfig.c has been done.
> 
> Signed-off-by: Clément Léger 
> ---

> diff --git a/arch/powerpc/platforms/pseries/reconfig.c 
> b/arch/powerpc/platforms/pseries/reconfig.c
> index cad7a0c93117..8704c541de3c 100644
> --- a/arch/powerpc/platforms/pseries/reconfig.c
> +++ b/arch/powerpc/platforms/pseries/reconfig.c
> @@ -19,46 +19,29 @@
>   
>   #include "of_helpers.h"
>   
> -static int pSeries_reconfig_add_node(const char *path, struct property 
> *proplist)
> +static struct device_node *pSeries_reconfig_add_node(const char *path)
>   {
> - struct device_node *np;
> - int err = -ENOMEM;
> -
> - np = kzalloc(sizeof(*np), GFP_KERNEL);
> - if (!np)
> - goto out_err;
> -
> - np->full_name = kstrdup(kbasename(path), GFP_KERNEL);
> - if (!np->full_name)
> - goto out_err;
> -
> - np->properties = proplist;
> - of_node_set_flag(np, OF_DYNAMIC);
> - of_node_init(np);
> + struct device_node *np, *parent;
>   
> - np->parent = pseries_of_derive_parent(path);
> - if (IS_ERR(np->parent)) {
> - err = PTR_ERR(np->parent);
> - goto out_err;
> + np = of_find_node_by_path(path)

Missing ;

Did you test build ?

> + if (np) {
> + of_node_put(np);
> + return ERR_PTR(-EINVAL);
>   }
>   
> - err = of_attach_node(np);
> - if (err) {
> - printk(KERN_ERR "Failed to add device node %s\n", path);
> - goto out_err;
> - }
> + parent = pseries_of_derive_parent(path);
> + if (IS_ERR(parent))
> + return parent;
>   
> - of_node_put(np->parent);
> + np = of_node_alloc(kbasename(path));
> + if (!np) {
> + of_node_put(parent);
> + return ERR_PTR(-ENOMEM);
> + }
>   
> - return 0;
> + np->parent = parent;
>   
> -out_err:
> - if (np) {
> - of_node_put(np->parent);
> - kfree(np->full_name);
> - kfree(np);
> - }
> - return err;
> + return np;
>   }
>   
>   static int pSeries_reconfig_remove_node(struct device_node *np)

Re: [PATCH -next v6 00/10]arm64: add machine check safe support

2022-06-28 Thread Will Deacon
On Tue, 21 Jun 2022 07:26:28 +, Tong Tiangen wrote:
> With the increase of memory capacity and density, the probability of
> memory error increases. The increasing size and density of server RAM
> in the data center and cloud have shown increased uncorrectable memory
> errors.
> 
> Currently, the kernel has a mechanism to recover from hardware memory
> errors. This patchset provides an new recovery mechanism.
> 
> [...]

Applied first six patches to arm64 (for-next/extable), thanks!

[01/10] arm64: extable: add new extable type EX_TYPE_KACCESS_ERR_ZERO support
https://git.kernel.org/arm64/c/4953fc3d3270
[02/10] arm64: asm-extable: move data fields
https://git.kernel.org/arm64/c/5519d7de2f8e
[03/10] arm64: asm-extable: add asm uacess helpers
https://git.kernel.org/arm64/c/59e8a1ce8f7b
[04/10] arm64: extable: make uaaccess helper use extable type 
EX_TYPE_UACCESS_ERR_ZERO
https://git.kernel.org/arm64/c/c4ed0d73ede9
[05/10] arm64: extable: move _cond_extable to _cond_uaccess_extable
https://git.kernel.org/arm64/c/e4208e80a353
[06/10] arm64: extable: cleanup redundant extable type EX_TYPE_FIXUP
https://git.kernel.org/arm64/c/bacac637025c

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev



Re: [PATCH v3 0/3] tpm: Preserve TPM measurement log across kexec (ppc64)

2022-06-28 Thread Stefan Berger

On 6/28/22 12:58, Stefan Berger wrote:

The of-tree subsystem does not currently preserve the IBM vTPM 1.2 and
vTPM 2.0 measurement logs across a kexec on ppc64. This series fixes this
for the kexec_file_load() syscall using the flattened device tree (fdt) to
carry the measurement log's buffer across kexec.

Stefan



v3:
 - Moved TPM Open Firmware related function to 
drivers/char/tpm/eventlog/tpm_of.c


v2:
 - rearranged patches
 - fixed compilation issues for x86



Stefan Berger (3):
   tpm: of: Make of-tree specific function commonly available
   of: kexec: Refactor IMA buffer related functions to make them reusable
   tpm/kexec: Duplicate TPM measurement log in of-tree for kexec

  drivers/char/Makefile  |   1 +
  drivers/char/tpm/Makefile  |   1 +
  drivers/char/tpm/eventlog/of.c |  31 +--
  drivers/char/tpm/eventlog/tpm_of.c |  27 +++
  drivers/of/kexec.c | 293 +
  include/linux/kexec.h  |   6 +
  include/linux/of.h |   8 +-
  include/linux/tpm.h|   5 +
  kernel/kexec_file.c|   6 +
  9 files changed, 315 insertions(+), 63 deletions(-)
  create mode 100644 drivers/char/tpm/eventlog/tpm_of.c



Re: [PATCH -next, v2] powerpc: add support for syscall stack randomization

2022-06-28 Thread Christophe Leroy


Le 16/05/2022 à 09:32, Xiu Jianfeng a écrit :
> Add support for adding a random offset to the stack while handling
> syscalls. This patch uses mftb() instead of get_random_int() for better
> performance.
> 
> In order to avoid unconditional stack canaries on syscall entry (due to
> the use of alloca()), also disable stack protector to avoid triggering
> needless checks and slowing down the entry path. As there is no general
> way to control stack protector coverage with a function attribute, this
> must be disabled at the compilation unit level.
> 
> Signed-off-by: Xiu Jianfeng 
> 

Did you see this patch generates sparse warnings ?

See 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220516073225.112875-1-xiujianf...@huawei.com/

It is not directly related to this patch but that's worth a patch to fix it.

> ---
> Changes in v2:
>-move choose choose_random_kstack_offset() to the end of 
> system_call_exception
>-allow full 6 (10) bits of entropy
>-disable stack-protector for interrupt.c
> ---
>   arch/powerpc/Kconfig|  1 +
>   arch/powerpc/kernel/Makefile|  7 +++
>   arch/powerpc/kernel/interrupt.c | 19 ++-
>   3 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 98309eeae09c..2f0019a0054e 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -192,6 +192,7 @@ config PPC
>   select HAVE_ARCH_KASAN  if PPC32 && PPC_PAGE_SHIFT <= 14
>   select HAVE_ARCH_KASAN_VMALLOC  if PPC32 && PPC_PAGE_SHIFT <= 14
>   select HAVE_ARCH_KFENCE if PPC_BOOK3S_32 || PPC_8xx || 
> 40x
> + select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
>   select HAVE_ARCH_KGDB
>   select HAVE_ARCH_MMAP_RND_BITS
>   select HAVE_ARCH_MMAP_RND_COMPAT_BITS   if COMPAT
> diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
> index 4ddd161aef32..5c5e85b8229b 100644
> --- a/arch/powerpc/kernel/Makefile
> +++ b/arch/powerpc/kernel/Makefile
> @@ -40,6 +40,13 @@ CFLAGS_cputable.o += -DDISABLE_BRANCH_PROFILING
>   CFLAGS_btext.o += -DDISABLE_BRANCH_PROFILING
>   endif
>   
> +#ifdef CONFIG_RANDOMIZE_KSTACK_OFFSET
> +# Remove stack protector to avoid triggering unneeded stack canary
> +# checks due to randomize_kstack_offset.
> +CFLAGS_REMOVE_interrupt.o = -fstack-protector -fstack-protector-strong
> +CFLAGS_interrupt.o += -fno-stack-protector
> +#endif
> +
>   obj-y   := cputable.o syscalls.o \
>  irq.o align.o signal_$(BITS).o pmc.o vdso.o \
>  process.o systbl.o idle.o \
> diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
> index 784ea3289c84..d7cdcb6fc336 100644
> --- a/arch/powerpc/kernel/interrupt.c
> +++ b/arch/powerpc/kernel/interrupt.c
> @@ -4,6 +4,7 @@
>   #include 
>   #include 
>   #include  /* for show_regs */
> +#include 
>   
>   #include 
>   #include 
> @@ -78,10 +79,12 @@ notrace long system_call_exception(long r3, long r4, long 
> r5,
>  long r6, long r7, long r8,
>  unsigned long r0, struct pt_regs *regs)
>   {
> + long ret;
>   syscall_fn f;
>   
>   kuap_lock();
>   
> + add_random_kstack_offset();
>   regs->orig_gpr3 = r3;
>   
>   if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG))
> @@ -229,7 +232,21 @@ notrace long system_call_exception(long r3, long r4, 
> long r5,
>   f = (void *)sys_call_table[r0];
>   }
>   
> - return f(r3, r4, r5, r6, r7, r8);
> + ret = f(r3, r4, r5, r6, r7, r8);
> + /*
> +  * Ultimately, this value will get limited by KSTACK_OFFSET_MAX(),
> +  * so the maximum stack offset is 1k bytes(10 bits).
> +  *
> +  * The actual entropy will be further reduced by the compiler when
> +  * applying stack alignment constraints: the powerpc architecture
> +  * may have two kinds of stack alignment(16-bytes and 8-bytes).
> +  *
> +  * So the resulting 6 or 7 bits of entropy is seen in SP[9:4] or 
> SP[9:3].
> +  *
> +  */
> + choose_random_kstack_offset(mftb());
> +
> + return ret;
>   }
>   
>   static notrace void booke_load_dbcr0(void)

RE: [PATCH RESEND v2 0/7] soc: fsl: guts: cleanups and serial_number support

2022-06-28 Thread Leo Li



> -Original Message-
> From: Shawn Guo 
> Sent: Monday, June 27, 2022 1:53 AM
> To: Michael Walle 
> Cc: linuxppc-dev@lists.ozlabs.org; linux-arm-ker...@lists.infradead.org;
> linux-ker...@vger.kernel.org; Leo Li ; Ulf Hansson
> ; Sudeep Holla ; Arnd
> Bergmann ; Dan Carpenter 
> Subject: Re: [PATCH RESEND v2 0/7] soc: fsl: guts: cleanups and
> serial_number support
> 
> On Wed, Jun 22, 2022 at 01:03:33PM +0200, Michael Walle wrote:
> > Am 2022-04-04 11:56, schrieb Michael Walle:
> > > [Resend because of new development cycle. Shawn, can this series get
> > > through your tree? Sorry you weren't on CC on the former
> > > submissions.]
> > >
> > > This series converts the guts driver from a platform driver to just
> > > an core_initcall. The driver itself cannot (or rather should never)
> > > be unloaded because others depends on detecting the current SoC
> > > revision to apply chip errata. Other SoC drivers do it the same way.
> > > Overall I got rid of all the global static variables.
> > >
> > > The last patch finally adds unique id support to the guts driver. DT
> > > binding can be found at:
> > >   Documentation/devicetree/bindings/nvmem/fsl,layerscape-sfp.yaml
> > >
> > > changes since v1:
> > >  - call kfree() in error case, thanks Dan
> > >  - add missing of_node_put(np), thanks Dan
> > >
> > > Michael Walle (7):
> > >   soc: fsl: guts: machine variable might be unset
> > >   soc: fsl: guts: remove module_exit() and fsl_guts_remove()
> > >   soc: fsl: guts: embed fsl_guts_get_svr() in probe()
> > >   soc: fsl: guts: allocate soc_dev_attr on the heap
> > >   soc: fsl: guts: use of_root instead of own reference
> > >   soc: fsl: guts: drop platform driver
> > >   soc: fsl: guts: add serial_number support
> > >
> > >  drivers/soc/fsl/guts.c | 219
> > > ++---
> > >  1 file changed, 118 insertions(+), 101 deletions(-)
> >
> > There goes another kernel release without any comments on this series
> > :(
> >
> > Shawn, can you pick this up and give it some time in linux-next?
> 
> Okay, I just picked the series up to IMX tree.
> 
> Leo, let me know if you want to drop it from IMX tree.

No problem.  You can take these through your tree.  Thanks.

Regards,
Leo


[linux-next:master] BUILD REGRESSION cb71b93c2dc36d18a8b05245973328d018272cdf

2022-06-28 Thread kernel test robot
tree/branch: 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
branch HEAD: cb71b93c2dc36d18a8b05245973328d018272cdf  Add linux-next specific 
files for 20220628

Error/Warning: (recently discovered and may have been fixed)

arch/powerpc/kernel/interrupt.c:542:55: error: suggest braces around empty body 
in an 'if' statement [-Werror=empty-body]
arch/powerpc/kernel/interrupt.c:542:55: warning: suggest braces around empty 
body in an 'if' statement [-Wempty-body]
drivers/gpu/drm/amd/amdgpu/../display/dc/core/dc_link.c:1025:33: warning: 
variable 'pre_connection_type' set but not used [-Wunused-but-set-variable]
drivers/pci/endpoint/functions/pci-epf-vntb.c:975:5: warning: no previous 
prototype for 'pci_read' [-Wmissing-prototypes]
drivers/pci/endpoint/functions/pci-epf-vntb.c:984:5: warning: no previous 
prototype for 'pci_write' [-Wmissing-prototypes]
vmlinux.o: warning: objtool: __ct_user_enter+0x8c: call to 
ftrace_likely_update() leaves .noinstr.text section
vmlinux.o: warning: objtool: ct_idle_enter+0x19: call to ftrace_likely_update() 
leaves .noinstr.text section
vmlinux.o: warning: objtool: ct_idle_exit+0x3e: call to ftrace_likely_update() 
leaves .noinstr.text section
vmlinux.o: warning: objtool: ct_irq_enter+0x6a: call to ftrace_likely_update() 
leaves .noinstr.text section
vmlinux.o: warning: objtool: ct_irq_exit+0x6a: call to ftrace_likely_update() 
leaves .noinstr.text section
vmlinux.o: warning: objtool: ct_kernel_enter.constprop.0+0x2a: call to 
ftrace_likely_update() leaves .noinstr.text section
vmlinux.o: warning: objtool: ct_kernel_enter_state+0x2d: call to 
ftrace_likely_update() leaves .noinstr.text section
vmlinux.o: warning: objtool: ct_kernel_exit.constprop.0+0x53: call to 
ftrace_likely_update() leaves .noinstr.text section
vmlinux.o: warning: objtool: ct_kernel_exit_state+0x2d: call to 
ftrace_likely_update() leaves .noinstr.text section
vmlinux.o: warning: objtool: ct_nmi_enter+0x4b: call to ftrace_likely_update() 
leaves .noinstr.text section

Unverified Error/Warning (likely false positive, please contact us if 
interested):

drivers/net/ethernet/microchip/lan743x_main.c:1238:1: internal compiler error: 
in arc_ifcvt, at config/arc/arc.c:9637
drivers/soc/mediatek/mtk-mutex.c:799:1: internal compiler error: in arc_ifcvt, 
at config/arc/arc.c:9637
drivers/staging/media/zoran/zr36016.c:430:1: internal compiler error: in 
arc_ifcvt, at config/arc/arc.c:9637
drivers/staging/media/zoran/zr36050.c:829:1: internal compiler error: in 
arc_ifcvt, at config/arc/arc.c:9637
drivers/staging/media/zoran/zr36060.c:869:1: internal compiler error: in 
arc_ifcvt, at config/arc/arc.c:9637
drivers/thunderbolt/tmu.c:758:1: internal compiler error: in arc_ifcvt, at 
config/arc/arc.c:9637
sound/soc/sof/intel/mtl.c:547:1: internal compiler error: in arc_ifcvt, at 
config/arc/arc.c:9637

Error/Warning ids grouped by kconfigs:

gcc_recent_errors
|-- alpha-allyesconfig
|   |-- 
drivers-gpu-drm-amd-amdgpu-..-display-dc-core-dc_link.c:warning:variable-pre_connection_type-set-but-not-used
|   |-- 
drivers-pci-endpoint-functions-pci-epf-vntb.c:warning:no-previous-prototype-for-pci_read
|   `-- 
drivers-pci-endpoint-functions-pci-epf-vntb.c:warning:no-previous-prototype-for-pci_write
|-- alpha-randconfig-r002-20220628
|   `-- 
drivers-gpu-drm-amd-amdgpu-..-display-dc-core-dc_link.c:warning:variable-pre_connection_type-set-but-not-used
|-- alpha-randconfig-r003-20220628
|   `-- 
drivers-gpu-drm-amd-amdgpu-..-display-dc-core-dc_link.c:warning:variable-pre_connection_type-set-but-not-used
|-- arc-allyesconfig
|   |-- 
drivers-gpu-drm-amd-amdgpu-..-display-dc-core-dc_link.c:warning:variable-pre_connection_type-set-but-not-used
|   |-- 
drivers-net-ethernet-microchip-lan743x_main.c:internal-compiler-error:in-arc_ifcvt-at-config-arc-arc.c
|   |-- 
drivers-pci-endpoint-functions-pci-epf-vntb.c:warning:no-previous-prototype-for-pci_read
|   |-- 
drivers-pci-endpoint-functions-pci-epf-vntb.c:warning:no-previous-prototype-for-pci_write
|   |-- 
drivers-soc-mediatek-mtk-mutex.c:internal-compiler-error:in-arc_ifcvt-at-config-arc-arc.c
|   |-- 
drivers-staging-media-zoran-zr36016.c:internal-compiler-error:in-arc_ifcvt-at-config-arc-arc.c
|   |-- 
drivers-staging-media-zoran-zr36050.c:internal-compiler-error:in-arc_ifcvt-at-config-arc-arc.c
|   |-- 
drivers-staging-media-zoran-zr36060.c:internal-compiler-error:in-arc_ifcvt-at-config-arc-arc.c
|   |-- 
drivers-thunderbolt-tmu.c:internal-compiler-error:in-arc_ifcvt-at-config-arc-arc.c
|   `-- 
sound-soc-sof-intel-mtl.c:internal-compiler-error:in-arc_ifcvt-at-config-arc-arc.c
|-- arm-allyesconfig
|   |-- 
drivers-gpu-drm-amd-amdgpu-..-display-dc-core-dc_link.c:warning:variable-pre_connection_type-set-but-not-used
|   |-- 
drivers-pci-endpoint-functions-pci-epf-vntb.c:warning:no-previous-prototype-for-pci_read
|   `-- 
drivers-pci-endpoint-functions-pci-epf-vntb.c:warning:no-previous-prototype-for-pci

Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Michael Schmitz

Hi Geert,

On 28/06/22 19:03, Geert Uytterhoeven wrote:



Leaving the bounce buffer handling in place, and taking a few other
liberties - this is what converting the easiest case (a3000 SCSI) might
look like. Any obvious mistakes? The mvme147 driver would be very
similar to handle (after conversion to a platform device).

Thanks, looks reasonable.
Thanks, I'll take care of Arnd's comments and post a corrected version 
later.

The driver allocates bounce buffers using kmalloc if it hits an
unaligned data buffer - can such buffers still even happen these days?

No idea.
Hmmm - I think I'll stick a WARN_ONCE() in there so we know whether this 
code path is still being used.



If I understand dma_map_single() correctly, the resulting dma handle
would be equally misaligned?

To allocate a bounce buffer, would it be OK to use dma_alloc_coherent()
even though AFAIU memory used for DMA buffers generally isn't consistent
on m68k?

Thinking ahead to the other two Amiga drivers - I wonder whether
allocating a static bounce buffer or a DMA pool at driver init is likely
to succeed if the kernel runs from the low 16 MB RAM chunk? It certainly
won't succeed if the kernel runs from a higher memory address, so the
present bounce buffer logic around amiga_chip_alloc() might still need
to be used here.

Leaves the question whether converting the gvp11 and a2091 drivers is
actually worth it, if bounce buffers still have to be handled explicitly.

A2091 should be straight-forward, as A3000 is basically A2091 on the
motherboard (comparing the two drivers, looks like someone's been
sprinkling mb()s over the A3000 driver).


Yep, and at least the ones in the dma_setup() function are there for no 
reason (the compiler won't reorder stores around the cache flush calls, 
I hope?).


Just leaves the 24 bit DMA mask there (and likely need for bounce buffers).


I don't have any of these SCSI host adapters (not counting the A590
(~A2091) expansion of the old A500, which is not Linux-capable, and
  hasn't been powered on for 20 years).


I wonder whether kullervo has survived - that one was an A3000. Should 
have gone to Adrian a few years ago...


Cheers,

    Michael




Gr{oetje,eeting}s,

 Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
 -- Linus Torvalds


Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Michael Schmitz

Hi Arnd,

On 28/06/22 19:08, Arnd Bergmann wrote:

On Tue, Jun 28, 2022 at 5:25 AM Michael Schmitz  wrote:

Am 28.06.2022 um 09:12 schrieb Michael Schmitz:

Leaving the bounce buffer handling in place, and taking a few other
liberties - this is what converting the easiest case (a3000 SCSI) might
look like. Any obvious mistakes? The mvme147 driver would be very
similar to handle (after conversion to a platform device).

The driver allocates bounce buffers using kmalloc if it hits an
unaligned data buffer - can such buffers still even happen these days?
If I understand dma_map_single() correctly, the resulting dma handle
would be equally misaligned?

To allocate a bounce buffer, would it be OK to use dma_alloc_coherent()
even though AFAIU memory used for DMA buffers generally isn't consistent
on m68k?

I think it makes sense to skip the bounce buffering as you do here:
the only standardized way we have for integrating that part is to
use the swiotlb infrastructure, but as you mentioned earlier that
part is probably too resource-heavy here for Amiga.
OK, leaving the old custom logic in place allows to convert the 24 bit 
DMA drivers more easily.


I see two other problems with your patch though:

a) you still duplicate the cache handling: the cache_clear()/cache_push()
is supposed to already be done by dma_map_single() when the device
is not cache-coherent.


That's one of the 'liberties' I alluded to. The reason I left these in 
is that I'm none too certain what device feature the DMA API uses to 
decide a device isn't cache-coherent. If it's dev->coherent_dma_mask, 
the way I set up the device in the a3000 driver should leave the 
coherent mask unchanged. For the Zorro drivers, devices are set up to 
use the same storage to store normal and coherent masks - something we 
most likely want to change. I need to think about the ramifications of 
that.


Note that zorro_esp.c uses dma_sync_single_for_device() and uses a 32 
bit coherent DMA mask which does work OK. I might  ask Adrian to test a 
change to only set dev->dma_mask, and drop the 
dma_sync_single_for_device() calls if there's any doubt on this aspect.



b) The bounce buffer is never mapped here, instead you have the
virt_to_phys() here, which is not the same. I think you need to map
the pointer that actually gets passed down to the device after deciding
to use a bouce buffer or not.


I hadn't realized that I can map the bounce buffer just as it's done for 
the SCp data buffer. Should have been obvious, but I'm still learning 
about the DMA API.


I've updated the patch now, will re-send as part of a complete series 
once done.


Cheers,

    Michael




  Arnd


Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Arnd Bergmann
On Tue, Jun 28, 2022 at 11:03 PM Michael Schmitz  wrote:
> On 28/06/22 19:03, Geert Uytterhoeven wrote:
> >> The driver allocates bounce buffers using kmalloc if it hits an
> >> unaligned data buffer - can such buffers still even happen these days?
> > No idea.
> Hmmm - I think I'll stick a WARN_ONCE() in there so we know whether this
> code path is still being used.

kmalloc() guarantees alignment to the next power-of-two size or
KMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it
is cacheline aligned.

  Arnd


Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Arnd Bergmann
On Tue, Jun 28, 2022 at 11:38 PM Michael Schmitz  wrote:
> On 28/06/22 19:08, Arnd Bergmann wrote:
> > I see two other problems with your patch though:
> >
> > a) you still duplicate the cache handling: the cache_clear()/cache_push()
> > is supposed to already be done by dma_map_single() when the device
> > is not cache-coherent.
>
> That's one of the 'liberties' I alluded to. The reason I left these in
> is that I'm none too certain what device feature the DMA API uses to
> decide a device isn't cache-coherent. If it's dev->coherent_dma_mask,
> the way I set up the device in the a3000 driver should leave the
> coherent mask unchanged. For the Zorro drivers, devices are set up to
> use the same storage to store normal and coherent masks - something we
> most likely want to change. I need to think about the ramifications of
> that.
>
> Note that zorro_esp.c uses dma_sync_single_for_device() and uses a 32
> bit coherent DMA mask which does work OK. I might  ask Adrian to test a
> change to only set dev->dma_mask, and drop the
> dma_sync_single_for_device() calls if there's any doubt on this aspect.

The "coherent_mask" is independent of the cache flushing. On some
architectures, a device can indicate whether it needs cache management
or not to guarantee coherency, but on m68k it appears that we always
assume it does, see arch/m68k/kernel/dma.c

> > b) The bounce buffer is never mapped here, instead you have the
> > virt_to_phys() here, which is not the same. I think you need to map
> > the pointer that actually gets passed down to the device after deciding
> > to use a bouce buffer or not.
>
> I hadn't realized that I can map the bounce buffer just as it's done for
> the SCp data buffer. Should have been obvious, but I'm still learning
> about the DMA API.
>
> I've updated the patch now, will re-send as part of a complete series
> once done.

I suppose you can just drop the bounce buffer if this just comes
from kmalloc().

   Arnd


[Bug 215389] pagealloc: memory corruption at building glibc-2.33 and running its' testsuite

2022-06-28 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=215389

Erhard F. (erhar...@mailbox.org) changed:

   What|Removed |Added

 Attachment #300113|0   |1
is obsolete||
 Attachment #300929|0   |1
is obsolete||

--- Comment #28 from Erhard F. (erhar...@mailbox.org) ---
Created attachment 301302
  --> https://bugzilla.kernel.org/attachment.cgi?id=301302&action=edit
dmesg (5.19-rc4, PowerMac G4 DP)

Re-tried on v5.19-rc4 (without fadditional patches) + KFENCE.

My findings so far:
1. Memory corruption still persists.
2. Even without KASAN I need THREAD_SHIFT=14 or else I get the stack overflow
from bug #216041.
3. Memory corruption also happens with CONFIG_LOWMEM_SIZE=0x2800.
4. But the "neverending build" commit mentioned in comment #9 is gone (be it
with default .config or CONFIG_LOWMEM_SIZE=0x2800).

[...]
pagealloc: memory corruption
fffdfff0: 00 00 00 00  
CPU: 0 PID: 29136 Comm: localedef Not tainted 5.19.0-rc4-PMacG4 #3
Call Trace:
[f39b3c20] [c05eb9c0] dump_stack_lvl+0x60/0x90 (unreliable)
[f39b3c40] [c0232fb0] __kernel_unpoison_pages+0x1a8/0x1ec
[f39b3c90] [c02170dc] get_page_from_freelist+0xc20/0xe70
[f39b3d50] [c0217bdc] __alloc_pages+0x18c/0xe80
[f39b3e10] [c01f46b4] wp_page_copy+0x214/0xa1c
[f39b3e80] [c01fa0b8] handle_mm_fault+0x720/0xd64
[f39b3f00] [c00215dc] do_page_fault+0x1d4/0x830
[f39b3f30] [c000433c] DataAccess_virt+0x124/0x17c
--- interrupt: 300 at 0x669410
NIP:  00669410 LR: 006693e4 CTR: 
REGS: f39b3f40 TRAP: 0300   Not tainted  (5.19.0-rc4-PMacG4)
MSR:  d032   CR: 84002462  XER: 2000
DAR: a7a3cce8 DSISR: 0a00 
GPR00: 0066961c afd34060 a7bd3000 01a069bc 01b76d60 0009 a4e0c05a 0005ccd8 
GPR08: 01b76140 a7a3cce8 a7a43e44 400a713a 44002862 0068fe34 01b8d730 0001 
GPR16:  01a069bc 01a069f8 01a06990 01b8d170 01a06894 000f 0009 
GPR24: 01b76d60 a4e0c05a 018d a7ad9f00 a79e0010 41cb 00697cdc 01a069bc 
NIP [00669410] 0x669410
LR [006693e4] 0x6693e4
--- interrupt: 300
page:ef4bd80c refcount:1 mapcount:0 mapping: index:0x1 pfn:0x310ab
flags: 0x8000(zone=2)
raw: 8000 0100 0122  0001   0001
raw: 
page dumped because: pagealloc: corrupted page details

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 215389] pagealloc: memory corruption at building glibc-2.33 and running its' testsuite

2022-06-28 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=215389

Erhard F. (erhar...@mailbox.org) changed:

   What|Removed |Added

 Attachment #300115|0   |1
is obsolete||
 Attachment #300930|0   |1
is obsolete||

--- Comment #29 from Erhard F. (erhar...@mailbox.org) ---
Created attachment 301303
  --> https://bugzilla.kernel.org/attachment.cgi?id=301303&action=edit
kernel .config (5.19-rc4, PowerMac G4 DP)

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Michael Schmitz

Hi Arnd,

On 29/06/22 09:50, Arnd Bergmann wrote:

On Tue, Jun 28, 2022 at 11:03 PM Michael Schmitz  wrote:

On 28/06/22 19:03, Geert Uytterhoeven wrote:

The driver allocates bounce buffers using kmalloc if it hits an
unaligned data buffer - can such buffers still even happen these days?

No idea.

Hmmm - I think I'll stick a WARN_ONCE() in there so we know whether this
code path is still being used.

kmalloc() guarantees alignment to the next power-of-two size or
KMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it
is cacheline aligned.


And all SCSI buffers are allocated using kmalloc? No way at all for user 
space to pass unaligned data?


(SCSI is a weird beast - I have used a SCSI DAT tape driver many many 
years ago, which broke all sorts of assumptions about transfer block 
sizes ... but that might actually have been in the v0.99 days, many 
rewrites of SCSI midlevel ago).


Just being cautious, as getting any of this tested will be a stretch.

Cheers,

    Michael



   Arnd


Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Michael Schmitz

Hi Arnd,

On 29/06/22 09:55, Arnd Bergmann wrote:

On Tue, Jun 28, 2022 at 11:38 PM Michael Schmitz  wrote:

On 28/06/22 19:08, Arnd Bergmann wrote:

I see two other problems with your patch though:

a) you still duplicate the cache handling: the cache_clear()/cache_push()
is supposed to already be done by dma_map_single() when the device
is not cache-coherent.

That's one of the 'liberties' I alluded to. The reason I left these in
is that I'm none too certain what device feature the DMA API uses to
decide a device isn't cache-coherent. If it's dev->coherent_dma_mask,
the way I set up the device in the a3000 driver should leave the
coherent mask unchanged. For the Zorro drivers, devices are set up to
use the same storage to store normal and coherent masks - something we
most likely want to change. I need to think about the ramifications of
that.

Note that zorro_esp.c uses dma_sync_single_for_device() and uses a 32
bit coherent DMA mask which does work OK. I might  ask Adrian to test a
change to only set dev->dma_mask, and drop the
dma_sync_single_for_device() calls if there's any doubt on this aspect.

The "coherent_mask" is independent of the cache flushing. On some
architectures, a device can indicate whether it needs cache management
or not to guarantee coherency, but on m68k it appears that we always
assume it does, see arch/m68k/kernel/dma.c


Thanks - what I see there indicates that on the relevant platforms, 
pages mapped for DMA have their page table cache bits modified to make 
them non-cacheable (and I suppose unmapping restores the default cache 
bits). That means I should use dma_set_mask_and_coherent() here to take 
advantage of this, and no need to mess around with 
dma_sync_single_for_device() in the drivers' dma_setup() functions.



b) The bounce buffer is never mapped here, instead you have the
virt_to_phys() here, which is not the same. I think you need to map
the pointer that actually gets passed down to the device after deciding
to use a bouce buffer or not.

I hadn't realized that I can map the bounce buffer just as it's done for
the SCp data buffer. Should have been obvious, but I'm still learning
about the DMA API.

I've updated the patch now, will re-send as part of a complete series
once done.

I suppose you can just drop the bounce buffer if this just comes
from kmalloc().


That's only true for a3000 and mvme147 though.

Cheers,

    Michael



Arnd


Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Bart Van Assche

On 6/28/22 16:09, Michael Schmitz wrote:

On 29/06/22 09:50, Arnd Bergmann wrote:
On Tue, Jun 28, 2022 at 11:03 PM Michael Schmitz 
 wrote:

On 28/06/22 19:03, Geert Uytterhoeven wrote:

The driver allocates bounce buffers using kmalloc if it hits an
unaligned data buffer - can such buffers still even happen these days?

No idea.

Hmmm - I think I'll stick a WARN_ONCE() in there so we know whether this
code path is still being used.

kmalloc() guarantees alignment to the next power-of-two size or
KMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it
is cacheline aligned.


And all SCSI buffers are allocated using kmalloc? No way at all for user 
space to pass unaligned data?


(SCSI is a weird beast - I have used a SCSI DAT tape driver many many 
years ago, which broke all sorts of assumptions about transfer block 
sizes ... but that might actually have been in the v0.99 days, many 
rewrites of SCSI midlevel ago).


Just being cautious, as getting any of this tested will be a stretch.


An example of a user space application that passes an SG I/O data buffer 
to the kernel that is aligned to a four byte boundary but not to an 
eight byte boundary if the -s (scattered) command line option is used: 
https://github.com/osandov/blktests/blob/master/src/discontiguous-io.cpp


Bart.


Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Michael Schmitz

Hi Bart,

On 29/06/22 11:50, Bart Van Assche wrote:

On 6/28/22 16:09, Michael Schmitz wrote:

On 29/06/22 09:50, Arnd Bergmann wrote:
On Tue, Jun 28, 2022 at 11:03 PM Michael Schmitz 
 wrote:

On 28/06/22 19:03, Geert Uytterhoeven wrote:

The driver allocates bounce buffers using kmalloc if it hits an
unaligned data buffer - can such buffers still even happen these 
days?

No idea.
Hmmm - I think I'll stick a WARN_ONCE() in there so we know whether 
this

code path is still being used.

kmalloc() guarantees alignment to the next power-of-two size or
KMALLOC_MIN_ALIGN, whichever is bigger. On m68k this means it
is cacheline aligned.


And all SCSI buffers are allocated using kmalloc? No way at all for 
user space to pass unaligned data?


(SCSI is a weird beast - I have used a SCSI DAT tape driver many many 
years ago, which broke all sorts of assumptions about transfer block 
sizes ... but that might actually have been in the v0.99 days, many 
rewrites of SCSI midlevel ago).


Just being cautious, as getting any of this tested will be a stretch.


An example of a user space application that passes an SG I/O data 
buffer to the kernel that is aligned to a four byte boundary but not 
to an eight byte boundary if the -s (scattered) command line option is 
used: 
https://github.com/osandov/blktests/blob/master/src/discontiguous-io.cpp


Thanks - four byte alignment actually wouldn't be an issue for me. It's 
two byte or smaller that would trip up the SCSI DMA.


While I'm sure such an even more pathological test case could be 
written, I was rather worried about st.c and sr.c input ...


Cheers,

    Michael



Bart.


Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Michael Schmitz

Hi Bart,

On 29/06/22 12:01, Michael Schmitz wrote:


An example of a user space application that passes an SG I/O data 
buffer to the kernel that is aligned to a four byte boundary but not 
to an eight byte boundary if the -s (scattered) command line option 
is used: 
https://github.com/osandov/blktests/blob/master/src/discontiguous-io.cpp


Thanks - four byte alignment actually wouldn't be an issue for me. 
It's two byte or smaller that would trip up the SCSI DMA.


While I'm sure such an even more pathological test case could be 
written, I was rather worried about st.c and sr.c input ...
Nevermind - I just see m68k defines ARCH_DMA_MINALIGN to be four bytes. 
Should be safe for all that matters, then.


Cheers,

    Michael




[powerpc:next-test] BUILD SUCCESS cdd235a67deef0ebec5f50928fcf6cf9d48de993

2022-06-28 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git 
next-test
branch HEAD: cdd235a67deef0ebec5f50928fcf6cf9d48de993  selftests/powerpc/pmu: 
Add test for hardware cache events

elapsed time: 746m

configs tested: 70
configs skipped: 2

The following configs have been built successfully.
More configs may be tested in the coming days.

gcc tested configs:
arm defconfig
arm  allyesconfig
arm64allyesconfig
i386 randconfig-c001-20220627
powerpc  ppc40x_defconfig
armrealview_defconfig
armpleb_defconfig
parisc64defconfig
arm  pxa910_defconfig
ia64 bigsur_defconfig
arm   aspeed_g5_defconfig
sh   sh7770_generic_defconfig
archsdk_defconfig
arm cm_x300_defconfig
riscvallyesconfig
ia64 allmodconfig
x86_64   randconfig-k001-20220627
arc  allyesconfig
alphaallyesconfig
m68k allmodconfig
m68k allyesconfig
powerpc   allnoconfig
mips allyesconfig
powerpc  allmodconfig
sh   allmodconfig
i386defconfig
i386 allyesconfig
x86_64   randconfig-a015-20220627
x86_64   randconfig-a012-20220627
x86_64   randconfig-a016-20220627
x86_64   randconfig-a011-20220627
x86_64   randconfig-a013-20220627
x86_64   randconfig-a014-20220627
i386 randconfig-a014-20220627
i386 randconfig-a011-20220627
i386 randconfig-a012-20220627
i386 randconfig-a015-20220627
i386 randconfig-a016-20220627
i386 randconfig-a013-20220627
arc  randconfig-r043-20220627
s390 randconfig-r044-20220627
riscvrandconfig-r042-20220627
um i386_defconfig
um   x86_64_defconfig
x86_64  defconfig
x86_64   rhel-8.3
x86_64   allyesconfig
x86_64 rhel-8.3-kunit
x86_64   rhel-8.3-syz
x86_64  rhel-8.3-func
x86_64rhel-8.3-kselftests

clang tested configs:
arm  pxa255-idp_defconfig
armdove_defconfig
x86_64   randconfig-a004-20220627
x86_64   randconfig-a006-20220627
x86_64   randconfig-a001-20220627
x86_64   randconfig-a005-20220627
x86_64   randconfig-a002-20220627
x86_64   randconfig-a003-20220627
i386 randconfig-a005-20220627
i386 randconfig-a001-20220627
i386 randconfig-a006-20220627
i386 randconfig-a004-20220627
i386 randconfig-a003-20220627
i386 randconfig-a002-20220627
x86_64randconfig-a012
x86_64randconfig-a014
x86_64randconfig-a016
hexagon  randconfig-r041-20220627
hexagon  randconfig-r045-20220627

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


Re: [PATCH v1 0/2] Fix console probe delay when stdout-path isn't set

2022-06-28 Thread Andy Shevchenko
o Pieralisi , Al Cooper , 
linux-te...@vger.kernel.org, Jiri Slaby , 
linux-asp...@lists.ozlabs.org, Rob Herring , Florian Fainelli 
, Mateusz Holenko , Alexander 
Shiyan , kevin hilman , Broadcom internal 
kernel review list , Joel Stanley 
, Orson Zhai , paolo abeni 
, Patrice Chotard , Ray Jui 
, Vladimir Zapolskiy , 
linux-snps-...@lists.infradead.org, Timur Tabi , hideaki 
yoshifuji , io...@lists.linux-foundation.org, Laxman 
Dewangan , Sudeep Holla , Baolin 
Wang , Shawn Guo , "David S. 
Miller" , Baruch Siach , Liviu Dudau , Alexandre Torgue 
, Bjorn Andersson , 
Paul Cercueil , sparcli...@vger.kernel.org, 
linux-ri...@lists.infradead.org, joerg roedel , Russell King 
, Andy Gross , 
linux-ser...@vger.kernel.org, jakub kicinski , will deacon 
, Manivannan Sadhasivam , 
linux-media...@lists.infradead.org, Fabio Estevam , Paul 
Walmsley , Matthias Brugger , 
Laurentiu Tudor , Taichi Sugaya 
, net...@vger.kernel.org, david ahern 
, Nicolas Ferre , Krzysztof 
Kozlowski , Palmer Dabbelt 
, Takao Orito , 
linuxppc-dev@lists.ozlabs.org
Errors-To: linuxppc-dev-bounces+archive=mail-archive@lists.ozlabs.org
Sender: "Linuxppc-dev" 


On Mon, Jun 27, 2022 at 07:01:01PM -0700, Saravana Kannan wrote:
> Since the series that fixes console probe delay based on stdout-path[1] got
> pulled into driver-core-next, I made these patches on top of them.
> 
> Even if stdout-path isn't set in DT, this patch should take console
> probe times back to how they were before the deferred_probe_timeout
> clean up series[2].

Are you sure it's only limited to the serial drivers?
(just asking, I don't know myself the answer)

-- 
With Best Regards,
Andy Shevchenko




Re: [RFC PATCH v2 2/3] fs: define a firmware security filesystem named fwsecurityfs

2022-06-28 Thread Christian Brauner
On Mon, Jun 27, 2022 at 09:37:28AM +0200, Greg Kroah-Hartman wrote:
> On Sun, Jun 26, 2022 at 11:48:06AM -0400, Mimi Zohar wrote:
> > On Thu, 2022-06-23 at 09:23 -0400, James Bottomley wrote:
> > > On Thu, 2022-06-23 at 10:54 +0200, Greg Kroah-Hartman wrote:
> > > [...]
> > > > > diff --git a/fs/fwsecurityfs/inode.c b/fs/fwsecurityfs/inode.c
> > > > > new file mode 100644
> > > > > index ..5d06dc0de059
> > > > > --- /dev/null
> > > > > +++ b/fs/fwsecurityfs/inode.c
> > > > > @@ -0,0 +1,159 @@
> > > > > +// SPDX-License-Identifier: GPL-2.0-only
> > > > > +/*
> > > > > + * Copyright (C) 2022 IBM Corporation
> > > > > + * Author: Nayna Jain 
> > > > > + */
> > > > > +
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +
> > > > > +#include "internal.h"
> > > > > +
> > > > > +int fwsecurityfs_remove_file(struct dentry *dentry)
> > > > > +{
> > > > > + drop_nlink(d_inode(dentry));
> > > > > + dput(dentry);
> > > > > + return 0;
> > > > > +};
> > > > > +EXPORT_SYMBOL_GPL(fwsecurityfs_remove_file);
> > > > > +
> > > > > +int fwsecurityfs_create_file(const char *name, umode_t mode,
> > > > > + u16 filesize, struct dentry
> > > > > *parent,
> > > > > + struct dentry *dentry,
> > > > > + const struct file_operations
> > > > > *fops)
> > > > > +{
> > > > > + struct inode *inode;
> > > > > + int error;
> > > > > + struct inode *dir;
> > > > > +
> > > > > + if (!parent)
> > > > > + return -EINVAL;
> > > > > +
> > > > > + dir = d_inode(parent);
> > > > > + pr_debug("securityfs: creating file '%s'\n", name);
> > > > 
> > > > Did you forget to call simple_pin_fs() here or anywhere else?
> > > > 
> > > > And this can be just one function with the directory creation file,
> > > > just check the mode and you will be fine.  Look at securityfs as an
> > > > example of how to make this simpler.
> > > 
> > > Actually, before you go down this route can you consider the namespace
> > > ramifications.  In fact we're just having to rework securityfs to pull
> > > out all the simple_pin_... calls because simple_pin_... is completely
> > > inimical to namespaces.

I described this at length in the securityfs namespacing thread at
various points. simple_pin_*() should be avoided if possible. Ideally
the filesystem will just be cleaned up on umount. There might be a
reason to make it survive umounts if you have state that stays around
and somehow is intimately tied to that filesystem.

> > > 
> > > The first thing to consider is if you simply use securityfs you'll
> > > inherit all the simple_pin_... removal work and be namespace ready.  It
> > > could be that creating a new filesystem that can't be namespaced is the
> > > right thing to do here, but at least ask the question: would we ever
> > > want any of these files to be presented selectively inside containers? 
> > > If the answer is "yes" then simple_pin_... is the wrong interface.
> > 
> > Greg, the securityfs changes James is referring to are part of the IMA
> > namespacing patch set:
> > https://lore.kernel.org/linux-integrity/20220420140633.753772-1-stef...@linux.ibm.com/
> > 
> > I'd really appreciate your reviewing the first two patches:
> > [PATCH v12 01/26] securityfs: rework dentry creation
> > [PATCH v12 02/26] securityfs: Extend securityfs with namespacing
> > support
> 
> Looks like others have already reviewed them, they seem sane to me if
> they past testing.

Thanks for taking a look.


Re: [PATCH v1 2/2] serial: Set probe_no_timeout for all DT based drivers

2022-06-28 Thread Tobias Klauser
l Cooper , linux-te...@vger.kernel.org, Jiri Slaby 
, linux-asp...@lists.ozlabs.org, Rob Herring 
, Florian Fainelli , Mateusz Holenko 
, Alexander Shiyan , kevin hilman 
, Broadcom internal kernel review list 
, Joel Stanley , Orson 
Zhai , paolo abeni , Patrice Chotard 
, Ray Jui , Vladimir Zapolskiy 
, linux-snps-...@lists.infradead.org, Timur Tabi 
, hideaki yoshifuji , 
io...@lists.linux-foundation.org, Laxman Dewangan , 
Sudeep Holla , Baolin Wang , 
Shawn Guo , "David S. Miller" , 
Baruch Siach , Liviu Dudau , Alexandre Torgue , Bjorn Andersson 
, Paul Cercueil , 
sparcli...@vger.kernel.org, linux-ri...@lists.infradead.org, Ahmad Fatoum 
, joerg roedel , Russell King 
, Andy Gross , 
linux-ser...@vger.kernel.org, jakub kicinski , will deacon 
, Manivannan Sadhasivam , 
linux-media...@lists.infradead.org, Fabio Estevam , Paul 
Walmsley , Matthias Brugger , 
Andy Shevchenko , Laurentiu Tudor 
, Taichi Sugaya , 
net...@vger.kernel.org, david ahern , Nicolas Ferre 
, Krzysztof Kozlowski 
, Palmer Dabbelt , Takao 
Orito , linuxppc-dev@lists.ozlabs.org
Errors-To: linuxppc-dev-bounces+archive=mail-archive@lists.ozlabs.org
Sender: "Linuxppc-dev" 


On 2022-06-28 at 04:01:03 +0200, Saravana Kannan  wrote:
> diff --git a/drivers/tty/serial/8250/8250_acorn.c 
> b/drivers/tty/serial/8250/8250_acorn.c
> index 758c4aa203ab..5a6f2f67de4f 100644
> --- a/drivers/tty/serial/8250/8250_acorn.c
> +++ b/drivers/tty/serial/8250/8250_acorn.c
> @@ -114,7 +114,6 @@ static const struct ecard_id serial_cids[] = {
>  static struct ecard_driver serial_card_driver = {
>   .probe  = serial_card_probe,
>   .remove = serial_card_remove,
> - .id_table   = serial_cids,

Is this change intentional? All other drivers are only changed to set
.probe_no_time and I don't see anything mentioned in the commit message
re. this driver's change.


[PATCH net-next v2 00/35] [RFT] net: dpaa: Convert to phylink

2022-06-28 Thread Sean Anderson
This series converts the DPAA driver to phylink. Additionally,
it also adds a serdes driver to allow for dynamic reconfiguration
between 1g and 10g interfaces (such as in an SFP+ slot). These changes
are submitted together for this RFC, but they will eventually be
submitted separately to the appropriate subsystem maintainers.

I have tried to maintain backwards compatibility with existing device
trees whereever possible. However, one area where I was unable to
achieve this was with QSGMII. Please refer to patch 3 for details.

All mac drivers have now been converted. I would greatly appreciate if
anyone has QorIQ boards they can test/debug this series on. I only have an
LS1046ARDB. Everything but QSGMII should work without breakage; QSGMII
needs patch 33.

The serdes driver is mostly functional (but not quite, see patches 5 and
31).  This series only adds support for the LS1046ARDB SerDes, but it
should be fairly straightforward to add support for other SoCs and
boards (see Documentation/driver-api/phy/qoriq.rst). Patches 34 and 25
should show the typical steps.

This patches in this series can be logically categorized as follows:
- 1, 4, 29, 34-35: SerDes support
- 2, 5-25: Cleanups. These can be applied as-is.
- 3, 26-28, 30-33: Phylink conversion

Patches 5-9 were first submitted as [1].

[1] 
https://lore.kernel.org/netdev/20220531195851.1592220-1-sean.ander...@seco.com/

Changes in v2:
- Add #clock-cells. This will allow using assigned-clocks* to configure
  the PLLs.
- Add CGR update function
- Add helper for sanity checking cgr ops
- Add nodes for QSGMII PCSs
- Add rgmii property to all DPAA MACs
- Adjust queue depth on rate change
- Allow a value of 1 for phy-cells. This allows for compatibility with
  the similar (but according to Ioana Ciornei different enough) lynx-28g
  binding.
- Better document how we select which PCS to use in the default case
- Clear SGMIIaCR1_PCS_EN during probe
- Configure the SerDes in enable/disable
- Convert 10GEC and dTSEC as well
- Convert FMan MAC bindings to yaml
- Disable SerDes by default to prevent breaking boards inadvertently.
- Document phy cells in the description
- Document the structure of the compatible strings
- Fix capitalization of mEMAC in commit messages
- Fix example binding having too many cells in regs
- Fix not clearing group->pll after disabling it
- Fix prototype for dtsec_initialization
- Fix warning if sizeof(void *) != sizeof(resource_size_t)
- Handle 1000Base-KX in lynx_proto_mode_prep
- Move PCS_LYNX dependency to fman Kconfig
- Move compatible first
- Power off lanes during probe
- Properly implement all ethtool ops and ioctls. These were mostly
  stubbed out just enough to compile last time.
- Refer to the device in the documentation, rather than the binding
- Remove minItems
- Remove some unused variables
- Remove unused variable slow_10g_if
- Rename LYNX_PROTO_UNKNOWN to LYNX_PROTO_NONE
- Rename driver to Lynx 10G (etc.)
- Rename to fsl,lynx-10g.yaml
- Restrict valid link modes based on the phy interface. This is easier
  to set up, and mostly captures what I intended to do the first time.
  We now have a custom validate which restricts half-duplex for some SoCs
  for RGMII, but generally just uses the default phylink validate.
- Specify type of mac_dev for exception_cb
- Support 1 and 2 phy-cells
- Use list for clock-names
- Use one phy cell for SerDes1, since no lanes can be grouped

Sean Anderson (35):
  dt-bindings: phy: Add QorIQ SerDes binding
  dt-bindings: net: Convert FMan MAC bindings to yaml
  dt-bindings: net: fman: Add additional interface properties
  [RFC] phy: fsl: Add Lynx 10G SerDes driver
  net: fman: Convert to SPDX identifiers
  net: fman: Don't pass comm_mode to enable/disable
  net: fman: Store en/disable in mac_device instead of mac_priv_s
  net: fman: dtsec: Always gracefully stop/start
  net: fman: Get PCS node in per-mac init
  net: fman: Store initialization function in match data
  net: fman: Move struct dev to mac_device
  net: fman: Configure fixed link in memac_initialization
  net: fman: Export/rename some common functions
  net: fman: memac: Use params instead of priv for max_speed
  net: fman: Move initialization to mac-specific files
  net: fman: Mark mac methods static
  net: fman: Inline several functions into initialization
  net: fman: Remove internal_phy_node from params
  net: fman: Map the base address once
  net: fman: Pass params directly to mac init
  net: fman: Use mac_dev for some params
  net: fman: Specify type of mac_dev for exception_cb
  net: fman: Clean up error handling
  net: fman: Change return type of disable to void
  net: dpaa: Use mac_dev variable in dpaa_netdev_init
  soc: fsl: qbman: Add helper for sanity checking cgr ops
  soc: fsl: qbman: Add CGR update function
  net: dpaa: Adjust queue depth on rate change
  net: fman: memac: Add serdes support
  net: fman: memac: Use lynx pcs driver
  [RFT] net: dpaa: Convert to phylink
  qoriq: Specify which MACs support RGMII
  qoriq

[PATCH net-next v2 26/35] soc: fsl: qbman: Add helper for sanity checking cgr ops

2022-06-28 Thread Sean Anderson
This breaks out/combines get_affine_portal and the cgr sanity check in
preparation for the next commit. No functional change intended.

Signed-off-by: Sean Anderson 
---

Changes in v2:
- New

 drivers/soc/fsl/qbman/qman.c | 29 +++--
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c
index fde4edd83c14..eb6600aab09b 100644
--- a/drivers/soc/fsl/qbman/qman.c
+++ b/drivers/soc/fsl/qbman/qman.c
@@ -2483,13 +2483,8 @@ int qman_create_cgr(struct qman_cgr *cgr, u32 flags,
 }
 EXPORT_SYMBOL(qman_create_cgr);
 
-int qman_delete_cgr(struct qman_cgr *cgr)
+static struct qman_portal *qman_cgr_get_affine_portal(struct qman_cgr *cgr)
 {
-   unsigned long irqflags;
-   struct qm_mcr_querycgr cgr_state;
-   struct qm_mcc_initcgr local_opts;
-   int ret = 0;
-   struct qman_cgr *i;
struct qman_portal *p = get_affine_portal();
 
if (cgr->chan != p->config->channel) {
@@ -2497,10 +2492,25 @@ int qman_delete_cgr(struct qman_cgr *cgr)
dev_err(p->config->dev, "CGR not owned by current portal");
dev_dbg(p->config->dev, " create 0x%x, delete 0x%x\n",
cgr->chan, p->config->channel);
-
-   ret = -EINVAL;
-   goto put_portal;
+   put_affine_portal();
+   return NULL;
}
+
+   return p;
+}
+
+int qman_delete_cgr(struct qman_cgr *cgr)
+{
+   unsigned long irqflags;
+   struct qm_mcr_querycgr cgr_state;
+   struct qm_mcc_initcgr local_opts;
+   int ret = 0;
+   struct qman_cgr *i;
+   struct qman_portal *p = qman_cgr_get_affine_portal(cgr);
+
+   if (!p)
+   return -EINVAL;
+
memset(&local_opts, 0, sizeof(struct qm_mcc_initcgr));
spin_lock_irqsave(&p->cgr_lock, irqflags);
list_del(&cgr->node);
@@ -2528,7 +2538,6 @@ int qman_delete_cgr(struct qman_cgr *cgr)
list_add(&cgr->node, &p->cgr_cbs);
 release_lock:
spin_unlock_irqrestore(&p->cgr_lock, irqflags);
-put_portal:
put_affine_portal();
return ret;
 }
-- 
2.35.1.1320.gc452695387.dirty



[PATCH net-next v2 27/35] soc: fsl: qbman: Add CGR update function

2022-06-28 Thread Sean Anderson
This adds a function to update a CGR with new parameters.
qman_cgr_create can almost be used for this (with flags=0), but it's not
suitable because it also registers the callback function. The _safe
variant was modeled off of qman_cgr_delete_safe. However, we handle
multiple arguments and a return value.

Signed-off-by: Sean Anderson 
---

Changes in v2:
- New

 drivers/soc/fsl/qbman/qman.c | 47 
 include/soc/fsl/qman.h   |  9 +++
 2 files changed, 56 insertions(+)

diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c
index eb6600aab09b..68b825ea10f1 100644
--- a/drivers/soc/fsl/qbman/qman.c
+++ b/drivers/soc/fsl/qbman/qman.c
@@ -2568,6 +2568,53 @@ void qman_delete_cgr_safe(struct qman_cgr *cgr)
 }
 EXPORT_SYMBOL(qman_delete_cgr_safe);
 
+static int qman_update_cgr(struct qman_cgr *cgr, struct qm_mcc_initcgr *opts)
+{
+   int ret;
+   unsigned long irqflags;
+   struct qman_portal *p = qman_cgr_get_affine_portal(cgr);
+
+   if (!p)
+   return -EINVAL;
+
+   spin_lock_irqsave(&p->cgr_lock, irqflags);
+   ret = qm_modify_cgr(cgr, 0, opts);
+   spin_unlock_irqrestore(&p->cgr_lock, irqflags);
+   put_affine_portal();
+   return ret;
+}
+
+struct update_cgr_params {
+   struct qman_cgr *cgr;
+   struct qm_mcc_initcgr *opts;
+   int ret;
+};
+
+static void qman_update_cgr_smp_call(void *p)
+{
+   struct update_cgr_params *params = p;
+
+   params->ret = qman_update_cgr(params->cgr, params->opts);
+}
+
+int qman_update_cgr_safe(struct qman_cgr *cgr, struct qm_mcc_initcgr *opts)
+{
+   struct update_cgr_params params = {
+   .cgr = cgr,
+   .opts = opts,
+   };
+
+   preempt_disable();
+   if (qman_cgr_cpus[cgr->cgrid] != smp_processor_id())
+   smp_call_function_single(qman_cgr_cpus[cgr->cgrid],
+qman_update_cgr_smp_call, ¶ms, 
true);
+   else
+   params.ret = qman_update_cgr(cgr, opts);
+   preempt_enable();
+   return params.ret;
+}
+EXPORT_SYMBOL(qman_update_cgr_safe);
+
 /* Cleanup FQs */
 
 static int _qm_mr_consume_and_match_verb(struct qm_portal *p, int v)
diff --git a/include/soc/fsl/qman.h b/include/soc/fsl/qman.h
index 59eeba31c192..0d3d6beb7fdb 100644
--- a/include/soc/fsl/qman.h
+++ b/include/soc/fsl/qman.h
@@ -1171,6 +1171,15 @@ int qman_delete_cgr(struct qman_cgr *cgr);
  */
 void qman_delete_cgr_safe(struct qman_cgr *cgr);
 
+/**
+ * qman_update_cgr_safe - Modifies a congestion group object from any CPU
+ * @cgr: the 'cgr' object to modify
+ * @opts: state of the CGR settings
+ *
+ * This will select the proper CPU and modify the CGR settings.
+ */
+int qman_update_cgr_safe(struct qman_cgr *cgr, struct qm_mcc_initcgr *opts);
+
 /**
  * qman_query_cgr_congested - Queries CGR's congestion status
  * @cgr: the 'cgr' object to query
-- 
2.35.1.1320.gc452695387.dirty



[PATCH net-next v2 28/35] net: dpaa: Adjust queue depth on rate change

2022-06-28 Thread Sean Anderson
Instead of setting the queue depth once during probe, adjust it on the
fly whenever we configure the link. This is a bit unusal, since usually
the DPAA driver calls into the FMAN driver, but here we do the opposite.
We need to add a netdev to struct mac_device for this, but it will soon
live in the phylink config.

I haven't tested this extensively, but it doesn't seem to break
anything. We could possibly optimize this a bit by keeping track of the
last rate, but for now we just update every time. 10GEC probably doesn't
need to call into this at all, but I've added it for consistency.

Signed-off-by: Sean Anderson 
---

Changes in v2:
- New

 .../net/ethernet/freescale/dpaa/dpaa_eth.c| 38 +--
 .../net/ethernet/freescale/fman/fman_dtsec.c  |  1 +
 .../net/ethernet/freescale/fman/fman_memac.c  |  1 +
 .../net/ethernet/freescale/fman/fman_tgec.c   |  7 +++-
 drivers/net/ethernet/freescale/fman/mac.h |  3 ++
 5 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 2b1fce99c004..fd81ebc7be44 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -197,6 +197,8 @@ static int dpaa_rx_extra_headroom;
 #define dpaa_get_max_mtu() \
(dpaa_max_frm - (VLAN_ETH_HLEN + ETH_FCS_LEN))
 
+static void dpaa_eth_cgr_set_speed(struct mac_device *mac_dev, int speed);
+
 static int dpaa_netdev_init(struct net_device *net_dev,
const struct net_device_ops *dpaa_ops,
u16 tx_timeout)
@@ -262,6 +264,9 @@ static int dpaa_netdev_init(struct net_device *net_dev,
net_dev->needed_headroom = priv->tx_headroom;
net_dev->watchdog_timeo = msecs_to_jiffies(tx_timeout);
 
+   mac_dev->net_dev = net_dev;
+   mac_dev->update_speed = dpaa_eth_cgr_set_speed;
+
/* start without the RUNNING flag, phylib controls it later */
netif_carrier_off(net_dev);
 
@@ -826,10 +831,10 @@ static int dpaa_eth_cgr_init(struct dpaa_priv *priv)
initcgr.we_mask = cpu_to_be16(QM_CGR_WE_CSCN_EN | QM_CGR_WE_CS_THRES);
initcgr.cgr.cscn_en = QM_CGR_EN;
 
-   /* Set different thresholds based on the MAC speed.
-* This may turn suboptimal if the MAC is reconfigured at a speed
-* lower than its max, e.g. if a dTSEC later negotiates a 100Mbps link.
-* In such cases, we ought to reconfigure the threshold, too.
+   /* Set different thresholds based on the configured MAC speed.
+* This may turn suboptimal if the MAC is reconfigured at another
+* speed, so MACs must call dpaa_eth_cgr_set_speed in their adjust_link
+* callback.
 */
if (priv->mac_dev->if_support & SUPPORTED_1baseT_Full)
cs_th = DPAA_CS_THRESHOLD_10G;
@@ -858,6 +863,31 @@ static int dpaa_eth_cgr_init(struct dpaa_priv *priv)
return err;
 }
 
+static void dpaa_eth_cgr_set_speed(struct mac_device *mac_dev, int speed)
+{
+   struct net_device *net_dev = mac_dev->net_dev;
+   struct dpaa_priv *priv = netdev_priv(net_dev);
+   struct qm_mcc_initcgr opts = { };
+   u32 cs_th;
+   int err;
+
+   opts.we_mask = cpu_to_be16(QM_CGR_WE_CS_THRES);
+   switch (speed) {
+   case SPEED_1:
+   cs_th = DPAA_CS_THRESHOLD_10G;
+   break;
+   case SPEED_1000:
+   default:
+   cs_th = DPAA_CS_THRESHOLD_1G;
+   break;
+   }
+   qm_cgr_cs_thres_set64(&opts.cgr.cs_thres, cs_th, 1);
+
+   err = qman_update_cgr_safe(&priv->cgr_data.cgr, &opts);
+   if (err)
+   netdev_err(net_dev, "could not update speed: %d\n", err);
+}
+
 static inline void dpaa_setup_ingress(const struct dpaa_priv *priv,
  struct dpaa_fq *fq,
  const struct qman_fq *template)
diff --git a/drivers/net/ethernet/freescale/fman/fman_dtsec.c 
b/drivers/net/ethernet/freescale/fman/fman_dtsec.c
index f2dd07b714ea..6617932fd3fd 100644
--- a/drivers/net/ethernet/freescale/fman/fman_dtsec.c
+++ b/drivers/net/ethernet/freescale/fman/fman_dtsec.c
@@ -1244,6 +1244,7 @@ static void adjust_link_dtsec(struct mac_device *mac_dev)
}
 
dtsec_adjust_link(fman_mac, phy_dev->speed);
+   mac_dev->update_speed(mac_dev, phy_dev->speed);
fman_get_pause_cfg(mac_dev, &rx_pause, &tx_pause);
err = fman_set_mac_active_pause(mac_dev, rx_pause, tx_pause);
if (err < 0)
diff --git a/drivers/net/ethernet/freescale/fman/fman_memac.c 
b/drivers/net/ethernet/freescale/fman/fman_memac.c
index 8ad93a4c0c21..02b3a0a2d5d1 100644
--- a/drivers/net/ethernet/freescale/fman/fman_memac.c
+++ b/drivers/net/ethernet/freescale/fman/fman_memac.c
@@ -782,6 +782,7 @@ static void adjust_link_memac(struct mac_device *mac_dev)
 
fman_mac = mac_dev->fman_mac;
memac_adjust_li

[PATCH net-next v2 32/35] qoriq: Specify which MACs support RGMII

2022-06-28 Thread Sean Anderson
For more precise link mode support, we can add a property specifying
which MACs support RGMII. This silences the warning

missing 'rgmii' property; assuming supported

Signed-off-by: Sean Anderson 
---

Changes in v2:
- Add rgmii property to all DPAA MACs

 .../boot/dts/freescale/fsl-ls1043-post.dtsi  |  7 +++
 .../boot/dts/freescale/fsl-ls1046-post.dtsi  |  8 
 arch/powerpc/boot/dts/fsl/b4860si-post.dtsi  |  4 
 arch/powerpc/boot/dts/fsl/b4si-post.dtsi |  4 
 arch/powerpc/boot/dts/fsl/t1023si-post.dtsi  |  4 
 arch/powerpc/boot/dts/fsl/t1040si-post.dtsi  |  7 +++
 arch/powerpc/boot/dts/fsl/t2081si-post.dtsi  |  8 
 arch/powerpc/boot/dts/fsl/t4240si-post.dtsi  | 16 
 8 files changed, 58 insertions(+)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1043-post.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1043-post.dtsi
index d237162a8744..f12d860a2ed4 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1043-post.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1043-post.dtsi
@@ -24,23 +24,30 @@ &fman0 {
 
/* these aliases provide the FMan ports mapping */
enet0: ethernet@e {
+   rgmii = <0>;
};
 
enet1: ethernet@e2000 {
+   rgmii = <0>;
};
 
enet2: ethernet@e4000 {
+   rgmii = <1>;
};
 
enet3: ethernet@e6000 {
+   rgmii = <1>;
};
 
enet4: ethernet@e8000 {
+   rgmii = <0>;
};
 
enet5: ethernet@ea000 {
+   rgmii = <0>;
};
 
enet6: ethernet@f {
+   rgmii = <0>;
};
 };
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046-post.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1046-post.dtsi
index d6caaea57d90..4bb314388a72 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1046-post.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1046-post.dtsi
@@ -23,26 +23,34 @@ &soc {
 &fman0 {
/* these aliases provide the FMan ports mapping */
enet0: ethernet@e {
+   rgmii = <0>;
};
 
enet1: ethernet@e2000 {
+   rgmii = <0>;
};
 
enet2: ethernet@e4000 {
+   rgmii = <1>;
};
 
enet3: ethernet@e6000 {
+   rgmii = <1>;
};
 
enet4: ethernet@e8000 {
+   rgmii = <0>;
};
 
enet5: ethernet@ea000 {
+   rgmii = <0>;
};
 
enet6: ethernet@f {
+   rgmii = <0>;
};
 
enet7: ethernet@f2000 {
+   rgmii = <0>;
};
 };
diff --git a/arch/powerpc/boot/dts/fsl/b4860si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/b4860si-post.dtsi
index 868719821106..68f68f8cfa4e 100644
--- a/arch/powerpc/boot/dts/fsl/b4860si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/b4860si-post.dtsi
@@ -264,15 +264,19 @@ rcpm: global-utilities@e2000 {
 /include/ "qoriq-fman3-0-10g-1.dtsi"
fman@40 {
enet4: ethernet@e8000 {
+   rgmii = <0>;
};
 
enet5: ethernet@ea000 {
+   rgmii = <0>;
};
 
enet6: ethernet@f {
+   rgmii = <0>;
};
 
enet7: ethernet@f2000 {
+   rgmii = <0>;
};
};
 
diff --git a/arch/powerpc/boot/dts/fsl/b4si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/b4si-post.dtsi
index 4f044b41a776..5e50b96e6b52 100644
--- a/arch/powerpc/boot/dts/fsl/b4si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/b4si-post.dtsi
@@ -465,15 +465,19 @@ muram@0 {
};
 
enet0: ethernet@e {
+   rgmii = <0>;
};
 
enet1: ethernet@e2000 {
+   rgmii = <0>;
};
 
enet2: ethernet@e4000 {
+   rgmii = <0>;
};
 
enet3: ethernet@e6000 {
+   rgmii = <0>;
};
 
mdio@fc000 {
diff --git a/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi
index d552044c5afc..e2a7bf643393 100644
--- a/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi
@@ -508,15 +508,19 @@ sata@22 {
 /include/ "qoriq-fman3-0-1g-3.dtsi"
fman@40 {
enet0: ethernet@e {
+   rgmii = <0>;
};
 
enet1: ethernet@e2000 {
+   rgmii = <0>;
};
 
enet2: ethernet@e4000 {
+   rgmii = <1>;
};
 
enet3: ethernet@e6000 {
+   rgmii = <1>;
};
};
 };
diff --git a/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi
index f58eb820eb5e..a585f5faaf9e 1

[PATCH net-next v2 33/35] qoriq: Add nodes for QSGMII PCSs

2022-06-28 Thread Sean Anderson
Now that we actually read registers from QSGMII PCSs, it's important
that we have the correct address (instead of hoping that we're the MAC
with all the QSGMII PCSs on its bus). Add nodes for the QSGMII PCSs.

On the PowerPC platforms, all the QSGMII PCSs have the same structure
(e.g. if QSGMIIA is present it's used for MACs 1 through 4). On ARM
platforms, the exact mapping of QSGMII to MACs depends on the SoC.

Since the first QSGMII PCSs share an address with the SGMII and XFI
PCSs, we only add new nodes for PCSs 2-4. This avoids address conflicts
on the bus.

Signed-off-by: Sean Anderson 
---

Changes in v2:
- New

 .../boot/dts/freescale/fsl-ls1043-post.dtsi   | 21 
 .../boot/dts/freescale/fsl-ls1046-post.dtsi   | 25 +++
 .../fsl/qoriq-fman3-0-10g-0-best-effort.dtsi  |  3 ++-
 .../boot/dts/fsl/qoriq-fman3-0-10g-0.dtsi |  9 ++-
 .../fsl/qoriq-fman3-0-10g-1-best-effort.dtsi  |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-0-10g-1.dtsi |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-0-1g-0.dtsi  |  3 ++-
 .../boot/dts/fsl/qoriq-fman3-0-1g-1.dtsi  |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-0-1g-2.dtsi  |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-0-1g-3.dtsi  |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-0-1g-4.dtsi  |  3 ++-
 .../boot/dts/fsl/qoriq-fman3-0-1g-5.dtsi  |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-1-10g-0.dtsi |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-1-10g-1.dtsi |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-1-1g-0.dtsi  |  3 ++-
 .../boot/dts/fsl/qoriq-fman3-1-1g-1.dtsi  |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-1-1g-2.dtsi  |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-1-1g-3.dtsi  |  9 ++-
 .../boot/dts/fsl/qoriq-fman3-1-1g-4.dtsi  |  3 ++-
 .../boot/dts/fsl/qoriq-fman3-1-1g-5.dtsi  |  9 ++-
 20 files changed, 160 insertions(+), 18 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1043-post.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1043-post.dtsi
index f12d860a2ed4..6fd77ce41466 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1043-post.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1043-post.dtsi
@@ -24,10 +24,13 @@ &fman0 {
 
/* these aliases provide the FMan ports mapping */
enet0: ethernet@e {
+   pcs-names = "qsgmii";
rgmii = <0>;
};
 
enet1: ethernet@e2000 {
+   pcsphy-handle = <&pcsphy1>, <&qsgmiib_pcs1>;
+   pcs-names = "sgmii", "qsgmii";
rgmii = <0>;
};
 
@@ -40,14 +43,32 @@ enet3: ethernet@e6000 {
};
 
enet4: ethernet@e8000 {
+   pcsphy-handle = <&pcsphy4>, <&qsgmiib_pcs2>;
+   pcs-names = "sgmii", "qsgmii";
rgmii = <0>;
};
 
enet5: ethernet@ea000 {
+   pcsphy-handle = <&pcsphy5>, <&qsgmiib_pcs3>;
+   pcs-names = "sgmii", "qsgmii";
rgmii = <0>;
};
 
enet6: ethernet@f {
rgmii = <0>;
};
+
+   mdio@e1000 {
+   qsgmiib_pcs1: ethernet-pcs@1 {
+   reg = <0x1>;
+   };
+
+   qsgmiib_pcs2: ethernet-pcs@2 {
+   reg = <0x2>;
+   };
+
+   qsgmiib_pcs3: ethernet-pcs@3 {
+   reg = <0x3>;
+   };
+   };
 };
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046-post.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1046-post.dtsi
index 4bb314388a72..6a80accd4845 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1046-post.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1046-post.dtsi
@@ -23,6 +23,8 @@ &soc {
 &fman0 {
/* these aliases provide the FMan ports mapping */
enet0: ethernet@e {
+   pcsphy-handle = <&qsgmiib_pcs3>;
+   pcs-names = "qsgmii";
rgmii = <0>;
};
 
@@ -39,10 +41,14 @@ enet3: ethernet@e6000 {
};
 
enet4: ethernet@e8000 {
+   pcsphy-handle = <&pcsphy4>, <&qsgmiib_pcs1>;
+   pcs-names = "sgmii", "qsgmii";
rgmii = <0>;
};
 
enet5: ethernet@ea000 {
+   pcsphy-handle = <&pcsphy5>, <&pcsphy5>;
+   pcs-names = "sgmii", "qsgmii";
rgmii = <0>;
};
 
@@ -51,6 +57,25 @@ enet6: ethernet@f {
};
 
enet7: ethernet@f2000 {
+   pcsphy-handle = <&pcsphy7>, <&qsgmiib_pcs2>, <&pcsphy7>;
+   pcs-names = "sgmii", "qsgmii", "xfi";
rgmii = <0>;
};
+
+   mdio@eb000 {
+   qsgmiib_pcs1: ethernet-pcs@1 {
+   compatible = "fsl,lynx-10g-qsgmii-pcs";
+   reg = <0x1>;
+   };
+
+   qsgmiib_pcs2: ethernet-pcs@2 {
+   compatible = "fsl,lynx-10g-qsgmii-pcs";
+   reg = <0x2>;
+   };
+
+   qsgmiib_pcs3: ethernet-pcs@3 {
+  

[PATCH v3] powerpc/memhotplug: Add add_pages override for PPC

2022-06-28 Thread Aneesh Kumar K.V
With commit ffa0b64e3be5 ("powerpc: Fix virt_addr_valid() for 64-bit Book3E & 
32-bit")
the kernel now validate the addr against high_memory value. This results
in the below BUG_ON with dax pfns.

[  635.798741][T26531] kernel BUG at mm/page_alloc.c:5521!
1:mon> e
cpu 0x1: Vector: 700 (Program Check) at [c7287630]
pc: c055ed48: free_pages.part.0+0x48/0x110
lr: c053ca70: tlb_finish_mmu+0x80/0xd0
sp: c72878d0
   msr: 8282b033
  current = 0xcafabe00
  paca= 0xc0037300   irqmask: 0x03   irq_happened: 0x05
pid   = 26531, comm = 50-landscape-sy
kernel BUG at :5521!
Linux version 5.19.0-rc3-14659-g4ec05be7c2e1 (kvaneesh@ltc-boston8) (gcc 
(Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) 
#625 SMP Thu Jun 23 00:35:43 CDT 2022
1:mon> t
[link register   ] c053ca70 tlb_finish_mmu+0x80/0xd0
[c72878d0] c053ca54 tlb_finish_mmu+0x64/0xd0 (unreliable)
[c7287900] c0539424 exit_mmap+0xe4/0x2a0
[c72879e0] c019fc1c mmput+0xcc/0x210
[c7287a20] c0629230 begin_new_exec+0x5e0/0xf40
[c7287ae0] c070b3cc load_elf_binary+0x3ac/0x1e00
[c7287c10] c0627af0 bprm_execve+0x3b0/0xaf0
[c7287cd0] c0628414 do_execveat_common.isra.0+0x1e4/0x310
[c7287d80] c062858c sys_execve+0x4c/0x60
[c7287db0] c002c1b0 system_call_exception+0x160/0x2c0
[c7287e10] c000c53c system_call_common+0xec/0x250

The fix is to make sure we update high_memory on memory hotplug.
This is similar to what x86 does in commit 3072e413e305 ("mm/memory_hotplug: 
introduce add_pages")

Fixes: ffa0b64e3be5 ("powerpc: Fix virt_addr_valid() for 64-bit Book3E & 
32-bit")
Cc: Kefeng Wang 
Cc: Christophe Leroy 
Signed-off-by: Aneesh Kumar K.V 
---
Changes from v2:
* drop WARN_ON_ONCE
* check for error from __add_pages

 arch/powerpc/Kconfig  |  4 
 arch/powerpc/mm/mem.c | 33 -
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index c2ce2e60c8f0..7aa12e88c580 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -358,6 +358,10 @@ config ARCH_SUSPEND_NONZERO_CPU
def_bool y
depends on PPC_POWERNV || PPC_PSERIES
 
+config ARCH_HAS_ADD_PAGES
+   def_bool y
+   depends on ARCH_ENABLE_MEMORY_HOTPLUG
+
 config PPC_DCR_NATIVE
bool
 
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 52b77684acda..a97128a48817 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -105,6 +105,37 @@ void __ref arch_remove_linear_mapping(u64 start, u64 size)
vm_unmap_aliases();
 }
 
+/*
+ * After memory hotplug the variables max_pfn, max_low_pfn and high_memory need
+ * updating.
+ */
+static void update_end_of_memory_vars(u64 start, u64 size)
+{
+   unsigned long end_pfn = PFN_UP(start + size);
+
+   if (end_pfn > max_pfn) {
+   max_pfn = end_pfn;
+   max_low_pfn = end_pfn;
+   high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
+   }
+}
+
+int __ref add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
+   struct mhp_params *params)
+{
+   int ret;
+
+   ret = __add_pages(nid, start_pfn, nr_pages, params);
+   if (ret)
+   return ret;
+
+   /* update max_pfn, max_low_pfn and high_memory */
+   update_end_of_memory_vars(start_pfn << PAGE_SHIFT,
+ nr_pages << PAGE_SHIFT);
+
+   return ret;
+}
+
 int __ref arch_add_memory(int nid, u64 start, u64 size,
  struct mhp_params *params)
 {
@@ -115,7 +146,7 @@ int __ref arch_add_memory(int nid, u64 start, u64 size,
rc = arch_create_linear_mapping(nid, start, size, params);
if (rc)
return rc;
-   rc = __add_pages(nid, start_pfn, nr_pages, params);
+   rc = add_pages(nid, start_pfn, nr_pages, params);
if (rc)
arch_remove_linear_mapping(start, size);
return rc;
-- 
2.36.1



Re: [PATCH] stack: Declare {randomize_,}kstack_offset to fix Sparse warnings

2022-06-28 Thread Christophe Leroy


Le 29/06/2022 à 05:29, GONG, Ruiqi a écrit :
> Fix the following Sparse warnings that got noticed when the PPC-dev
> patchwork was checking another patch (see the link below):
> 
> init/main.c:862:1: warning: symbol 'randomize_kstack_offset' was not 
> declared. Should it be static?
> init/main.c:864:1: warning: symbol 'kstack_offset' was not declared. Should 
> it be static?
> 
> Which in fact are triggered on all architectures that have
> HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET support (for instances x86, arm64
> etc).
> 
> Link: 
> https://lore.kernel.org/lkml/e7b0d68b-914d-7283-827c-101988923...@huawei.com/T/#m49b2d4490121445ce4bf7653500aba59eefcb67f
> Cc: Christophe Leroy 
> Cc: Xiu Jianfeng 
> Signed-off-by: GONG, Ruiqi 
> ---
>   init/main.c | 4 
>   1 file changed, 4 insertions(+)
> 
> diff --git a/init/main.c b/init/main.c
> index e2490387db2b..6aa0fb2340cc 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -101,6 +101,10 @@
>   #include 
>   #include 
> 
> +#ifdef CONFIG_RANDOMIZE_KSTACK_OFFSET

You don't need this #ifdef, there is already one inside 
linux/randomize_kstack.h

> +#include 
> +#endif
> +
>   #include 
>   #include 
>   #include 
> --
> 2.25.1
> 

[Bug 215389] pagealloc: memory corruption at building glibc-2.33 and running its' testsuite

2022-06-28 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=215389

--- Comment #30 from Michael Ellerman (mich...@ellerman.id.au) ---
It's a bit of a stab in the dark, but can you try turning preempt off?

ie. CONFIG_PREEMPT_NONE=y

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

Re: [PATCH -next, v2] powerpc: add support for syscall stack randomization

2022-06-28 Thread Michael Ellerman
Xiu Jianfeng  writes:
> Add support for adding a random offset to the stack while handling
> syscalls. This patch uses mftb() instead of get_random_int() for better
> performance.
>
> In order to avoid unconditional stack canaries on syscall entry (due to
> the use of alloca()), also disable stack protector to avoid triggering
> needless checks and slowing down the entry path. As there is no general
> way to control stack protector coverage with a function attribute, this
> must be disabled at the compilation unit level.
>
> Signed-off-by: Xiu Jianfeng 
>
> ---
> Changes in v2:
>   -move choose choose_random_kstack_offset() to the end of 
> system_call_exception
>   -allow full 6 (10) bits of entropy
>   -disable stack-protector for interrupt.c
> ---
>  arch/powerpc/Kconfig|  1 +
>  arch/powerpc/kernel/Makefile|  7 +++
>  arch/powerpc/kernel/interrupt.c | 19 ++-
>  3 files changed, 26 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 98309eeae09c..2f0019a0054e 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -192,6 +192,7 @@ config PPC
>   select HAVE_ARCH_KASAN  if PPC32 && PPC_PAGE_SHIFT <= 14
>   select HAVE_ARCH_KASAN_VMALLOC  if PPC32 && PPC_PAGE_SHIFT <= 14
>   select HAVE_ARCH_KFENCE if PPC_BOOK3S_32 || PPC_8xx || 
> 40x
> + select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
>   select HAVE_ARCH_KGDB
>   select HAVE_ARCH_MMAP_RND_BITS
>   select HAVE_ARCH_MMAP_RND_COMPAT_BITS   if COMPAT
> diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
> index 4ddd161aef32..5c5e85b8229b 100644
> --- a/arch/powerpc/kernel/Makefile
> +++ b/arch/powerpc/kernel/Makefile
> @@ -40,6 +40,13 @@ CFLAGS_cputable.o += -DDISABLE_BRANCH_PROFILING
>  CFLAGS_btext.o += -DDISABLE_BRANCH_PROFILING
>  endif
>  
> +#ifdef CONFIG_RANDOMIZE_KSTACK_OFFSET
> +# Remove stack protector to avoid triggering unneeded stack canary
> +# checks due to randomize_kstack_offset.
> +CFLAGS_REMOVE_interrupt.o = -fstack-protector -fstack-protector-strong
> +CFLAGS_interrupt.o += -fno-stack-protector
> +#endif

I'm a bit reluctant to remove stack protection from all of interrupt.c
just for this feature.

It's true that none of the functions in interrupt.c currently trigger
stack protection, but that could change in future.

What about splitting system_call_exception() into a separate file as a
lead-up patch, example below. Then we can just exclude stack protection
from that one function.

cheers


diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index f91f0f29a566..ecfd333b95d1 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -61,7 +61,7 @@ obj-y := cputable.o syscalls.o \
   udbg.o misc.o io.o misc_$(BITS).o \
   of_platform.o prom_parse.o firmware.o \
   hw_breakpoint_constraints.o interrupt.o \
-  kdebugfs.o stacktrace.o
+  kdebugfs.o stacktrace.o syscall.o
 obj-y  += ptrace/
 obj-$(CONFIG_PPC64)+= setup_64.o \
   paca.o nvram_64.o note.o
diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index 784ea3289c84..0e75cb03244a 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -24,8 +24,6 @@
 unsigned long global_dbcr0[NR_CPUS];
 #endif
 
-typedef long (*syscall_fn)(long, long, long, long, long, long);
-
 #ifdef CONFIG_PPC_BOOK3S_64
 DEFINE_STATIC_KEY_FALSE(interrupt_exit_not_reentrant);
 static inline bool exit_must_hard_disable(void)
@@ -73,165 +71,6 @@ static notrace __always_inline bool 
prep_irq_for_enabled_exit(bool restartable)
return true;
 }
 
-/* Has to run notrace because it is entered not completely "reconciled" */
-notrace long system_call_exception(long r3, long r4, long r5,
-  long r6, long r7, long r8,
-  unsigned long r0, struct pt_regs *regs)
-{
-   syscall_fn f;
-
-   kuap_lock();
-
-   regs->orig_gpr3 = r3;
-
-   if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG))
-   BUG_ON(irq_soft_mask_return() != IRQS_ALL_DISABLED);
-
-   trace_hardirqs_off(); /* finish reconciling */
-
-   CT_WARN_ON(ct_state() == CONTEXT_KERNEL);
-   user_exit_irqoff();
-
-   BUG_ON(regs_is_unrecoverable(regs));
-   BUG_ON(!(regs->msr & MSR_PR));
-   BUG_ON(arch_irq_disabled_regs(regs));
-
-#ifdef CONFIG_PPC_PKEY
-   if (mmu_has_feature(MMU_FTR_PKEY)) {
-   unsigned long amr, iamr;
-   bool flush_needed = false;
-   /*
-* When entering from userspace we mostly have the AMR/IAMR
-* different from kernel default values. Hence don

[PATCH kernel v2] pseries/iommu/ddw: Fix kdump to work in absence of ibm,dma-window

2022-06-28 Thread Alexey Kardashevskiy
The pseries platform uses 32bit default DMA window (always 4K pages) and
optional 64bit DMA window available via DDW ("Dynamic DMA Windows"),
64K or 2M pages. For ages the default one was not removed and a huge
window was created in addition. Things changed with SRIOV-enabled
PowerVM which creates a default-and-bigger DMA window in 64bit space
(still using 4K pages) for IOV VFs so certain OSes do not need to use
the DDW API in order to utilize all available TCE budget.

Linux on the other hand removes the default window and creates a bigger
one (with more TCEs or/and a bigger page size - 64K/2M) in a bid to map
the entire RAM, and if the new window size is smaller than that - it
still uses this new bigger window. The result is that the default window
is removed but the "ibm,dma-window" property is not.

When kdump is invoked, the existing code tries reusing the existing 64bit
DMA window which location and parameters are stored in the device tree but
this fails as the new property does not make it to the kdump device tree
blob. So the code falls back to the default window which does not exist
anymore although the device tree says that it does. The result of that
is that PCI devices become unusable and cannot be used for kdumping.

This preserves the DMA64 and DIRECT64 properties in the device tree blob
for the crash kernel. Since the crash kernel setup is done after device
drivers are loaded and probed, the proper DMA config is stored at least
for boot time devices.

Because DDW window is optional and the code configures the default window
first, the existing code creates an IOMMU table descriptor for
the non-existing default DMA window. It is harmless for kdump as it does
not touch the actual window (only reads what is mapped and marks those IO
pages as used) but it is bad for kexec which clears it thinking it is
a smaller default window rather than a bigger DDW window.

This removes the "ibm,dma-window" property from the device tree after
a bigger window is created and the crash kernel setup picks it up.

Fixes: 381ceda88c4c ("powerpc/pseries/iommu: Make use of DDW for indirect 
mapping")
Signed-off-by: Alexey Kardashevskiy 
---

Looks like SYSCALL(kexec_file_load) never supported DMA. so it could be:
Fixes: a0458284f062 ("powerpc: Add support code for kexec_file_load()")

---
Changes:
v2:
* reworked enable_ddw() to reuse default_win
* removed @tbl as it was only used once and later on this zeroes it
* undef for xxx64_PROPNAME in file_load_64.c
* renamed new functions in file_load_64.c
---
 arch/powerpc/kexec/file_load_64.c  | 54 
 arch/powerpc/platforms/pseries/iommu.c | 89 ++
 2 files changed, 102 insertions(+), 41 deletions(-)

diff --git a/arch/powerpc/kexec/file_load_64.c 
b/arch/powerpc/kexec/file_load_64.c
index b4981b651d9a..5d2c22aa34fb 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -1038,6 +1038,48 @@ static int update_cpus_node(void *fdt)
return ret;
 }
 
+static int copy_property(void *fdt, int node_offset, const struct device_node 
*dn,
+const char *propname)
+{
+   const void *prop, *fdtprop;
+   int len = 0, fdtlen = 0, ret;
+
+   prop = of_get_property(dn, propname, &len);
+   fdtprop = fdt_getprop(fdt, node_offset, propname, &fdtlen);
+
+   if (fdtprop && !prop)
+   ret = fdt_delprop(fdt, node_offset, propname);
+   else if (prop)
+   ret = fdt_setprop(fdt, node_offset, propname, prop, len);
+
+   return ret;
+}
+
+static int update_pci_dma_nodes(void *fdt, const char *dmapropname)
+{
+   struct device_node *dn;
+   int pci_offset, root_offset, ret = 0;
+
+   if (!firmware_has_feature(FW_FEATURE_LPAR))
+   return 0;
+
+   root_offset = fdt_path_offset(fdt, "/");
+   for_each_node_with_property(dn, dmapropname) {
+   pci_offset = fdt_subnode_offset(fdt, root_offset, 
of_node_full_name(dn));
+   if (pci_offset < 0)
+   continue;
+
+   ret = copy_property(fdt, pci_offset, dn, "ibm,dma-window");
+   if (ret < 0)
+   break;
+   ret = copy_property(fdt, pci_offset, dn, dmapropname);
+   if (ret < 0)
+   break;
+   }
+
+   return ret;
+}
+
 /**
  * setup_new_fdt_ppc64 - Update the flattend device-tree of the kernel
  *   being loaded.
@@ -1099,6 +1141,18 @@ int setup_new_fdt_ppc64(const struct kimage *image, void 
*fdt,
if (ret < 0)
goto out;
 
+#define DIRECT64_PROPNAME "linux,direct64-ddr-window-info"
+#define DMA64_PROPNAME "linux,dma64-ddr-window-info"
+   ret = update_pci_dma_nodes(fdt, DIRECT64_PROPNAME);
+   if (ret < 0)
+   goto out;
+
+   ret = update_pci_dma_nodes(fdt, DMA64_PROPNAME);
+   if (ret < 0)
+   goto out;
+#undef DMA64_PROPNAME
+#undef DIRECT64_PROPNAME
+

[PATCH] powerpc: Update reviewers

2022-06-28 Thread Michael Ellerman
Christophe and Nick have been active in recent years on the mailing list
and making contributions, add them as reviewers.

Paul and Ben are no longer actively reviewing powerpc patches, remove
them from the reviewers, they're still on linuxppc-dev if needed.

Signed-off-by: Michael Ellerman 
---
 MAINTAINERS | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 1fc9ead83d2a..af4cfeec9d0f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11345,8 +11345,8 @@ F:  drivers/macintosh/
 
 LINUX FOR POWERPC (32-BIT AND 64-BIT)
 M: Michael Ellerman 
-R: Benjamin Herrenschmidt 
-R: Paul Mackerras 
+R: Nicholas Piggin 
+R: Christophe Leroy 
 L: linuxppc-dev@lists.ozlabs.org
 S: Supported
 W: https://github.com/linuxppc/wiki/wiki
-- 
2.35.3



Re: [PATCH] powerpc: Update reviewers

2022-06-28 Thread Christophe Leroy


Le 29/06/2022 à 08:08, Michael Ellerman a écrit :
> Christophe and Nick have been active in recent years on the mailing list
> and making contributions, add them as reviewers.
> 
> Paul and Ben are no longer actively reviewing powerpc patches, remove
> them from the reviewers, they're still on linuxppc-dev if needed.
> 
> Signed-off-by: Michael Ellerman 

Acked-by: Christophe Leroy 

> ---
>   MAINTAINERS | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 1fc9ead83d2a..af4cfeec9d0f 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -11345,8 +11345,8 @@ F:drivers/macintosh/
>   
>   LINUX FOR POWERPC (32-BIT AND 64-BIT)
>   M:  Michael Ellerman 
> -R:   Benjamin Herrenschmidt 
> -R:   Paul Mackerras 
> +R:   Nicholas Piggin 
> +R:   Christophe Leroy 
>   L:  linuxppc-dev@lists.ozlabs.org
>   S:  Supported
>   W:  https://github.com/linuxppc/wiki/wiki

Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Christoph Hellwig
On Wed, Jun 29, 2022 at 11:09:00AM +1200, Michael Schmitz wrote:
> And all SCSI buffers are allocated using kmalloc? No way at all for user
> space to pass unaligned data?

Most that you will see actually comes from the page allocator.  But
the block layer has a dma_alignment limit, and when userspace sends
I/O that is not properly aligned it will be bounce buffered before
it it sent to the driver.


Re: [PATCH v2 3/3] arch/*/: remove CONFIG_VIRT_TO_BUS

2022-06-28 Thread Christoph Hellwig
On Wed, Jun 29, 2022 at 09:38:00AM +1200, Michael Schmitz wrote:
> That's one of the 'liberties' I alluded to. The reason I left these in is
> that I'm none too certain what device feature the DMA API uses to decide a
> device isn't cache-coherent.

The DMA API does not look at device features at all.  It needs to be
told so by the platform code.  Once an architecture implements the
hooks to support non-coherent DMA all devices are treated as
non-coherent by default unless overriden by the architecture either
globally (using the global dma_default_coherent variable) or per-device
(using the dev->dma_coherent field, usually set by arch_setup_dma_ops).

> If it's dev->coherent_dma_mask, the way I set
> up the device in the a3000 driver should leave the coherent mask unchanged.
> For the Zorro drivers, devices are set up to use the same storage to store
> normal and coherent masks - something we most likely want to change. I need
> to think about the ramifications of that.

No, the coherent mask is slightly misnamed amd not actually related.


[PATCH] UAPI: fix a spelling mistake

2022-06-28 Thread Zhang Jiaming
Change 'informations' to 'information'.

Signed-off-by: Zhang Jiaming 
---
 arch/powerpc/include/uapi/asm/bootx.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/uapi/asm/bootx.h 
b/arch/powerpc/include/uapi/asm/bootx.h
index 6728c7e24e58..eb0769e50e93 100644
--- a/arch/powerpc/include/uapi/asm/bootx.h
+++ b/arch/powerpc/include/uapi/asm/bootx.h
@@ -60,7 +60,7 @@ typedef struct boot_info_map_entry
 } boot_info_map_entry_t;
 
 
-/* Here are the boot informations that are passed to the bootstrap
+/* Here are the boot information that are passed to the bootstrap
  * Note that the kernel arguments and the device tree are appended
  * at the end of this structure. */
 typedef struct boot_infos
-- 
2.34.1



[Bug 216183] Kernel 5.19-rc4 boots ok with CONFIG_PPC_RADIX_MMU=y but fails to boot with CONFIG_PPC_HASH_MMU_NATIVE=y

2022-06-28 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=216183

Michael Ellerman (mich...@ellerman.id.au) changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 CC||mich...@ellerman.id.au

--- Comment #2 from Michael Ellerman (mich...@ellerman.id.au) ---
I can't repro this on my Talos 2.

I have some different PCI devices, a different GPU and nvme controller. I can't
see an obvious reason for this, will require some more digging.

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.