Re: Add Apple M1 support to PASemi i2c driver

2021-09-30 Thread Christian Zigotzky

Typo: Damian

Correct: Damien

On 01 October 2021 at 06:47 am, Christian Zigotzky wrote:

On 27 September 2021 at 07:39 am, Sven Peter wrote:
> Hi Christian,
>
> Thanks already for volunteering to test this!
>
Hello Sven,

Damian (Hypex) has successfully tested the RC3 of kernel 5.15 with 
your modified i2c driver on his Nemo board yesterday. [1]


@Darren
Could you also please check Sven's i2c modifications? He has also 
modified your source code a little bit. [2]


@Olof
Are these i2c modifications OK? Do these work on your P.A. Semi board?

Thanks,
Christian

[1] https://forum.hyperion-entertainment.com/viewtopic.php?p=54098#p54098
[2] 
https://lists.ozlabs.org/pipermail/linuxppc-dev/2017-January/153195.html
[3] Further information about the Nemo board: 
https://en.wikipedia.org/wiki/AmigaOne_X1000
[4] Kernel patches for the Nemo board: 
https://lists.ozlabs.org/pipermail/linuxppc-dev/2018-January/167288.html




Re: Add Apple M1 support to PASemi i2c driver

2021-09-30 Thread Christian Zigotzky

On 27 September 2021 at 07:39 am, Sven Peter wrote:
> Hi Christian,
>
> Thanks already for volunteering to test this!
>
Hello Sven,

Damian (Hypex) has successfully tested the RC3 of kernel 5.15 with your 
modified i2c driver on his Nemo board yesterday. [1]


@Darren
Could you also please check Sven's i2c modifications? He has also 
modified your source code a little bit. [2]


@Olof
Are these i2c modifications OK? Do these work on your P.A. Semi board?

Thanks,
Christian

[1] https://forum.hyperion-entertainment.com/viewtopic.php?p=54098#p54098
[2] https://lists.ozlabs.org/pipermail/linuxppc-dev/2017-January/153195.html
[3] Further information about the Nemo board: 
https://en.wikipedia.org/wiki/AmigaOne_X1000
[4] Kernel patches for the Nemo board: 
https://lists.ozlabs.org/pipermail/linuxppc-dev/2018-January/167288.html


Re: [PATCH] powerpc/eeh:Fix some mistakes in comments

2021-09-30 Thread 宋凯
Hi Daniel,

> Hi Kai,
>
> Thank you for your contribution to the powerpc kernel!
>
> > Get rid of warning:
> > arch/powerpc/kernel/eeh.c:774: warning: expecting prototype for
> > eeh_set_pe_freset(). Prototype was for eeh_set_dev_freset() instead
>
> You haven't said where this warning is from. I thought it might be from sparse
> but I couldn't seem to reproduce it - is my version of sparse too old or are 
> you
> using a different tool?

We can get this warning when building kernel with 'W=1' .
You can refer to this:  https://lwn.net/Articles/683476/
or this: https://lwn.net/Articles/440060/

> >  /**
> > - * eeh_set_pe_freset - Check the required reset for the indicated
> > device
> > - * @data: EEH device
> > + * eeh_set_dev_freset - Check the required reset for the indicated
> > + device
> > + * @edev: EEH device
> >   * @flag: return value
> >   *
> >   * Each device might have its preferred reset type: fundamental or
>
> This looks like a good and correct change.
>
> I checked through git history with git blame to see when the function was
> renamed. There are 2 commits that should have updated the comment:
> one renamed the function and one renamed an argument. So, I think this
> commit could have:
>
> Fixes: d6c4932fbf24 ("powerpc/eeh: Strengthen types of eeh traversal
> functions")
> Fixes: c270a24c59bd ("powerpc/eeh: Do reset based on PE")
>
> But I don't know if an out of date comment is enough of a 'bug' to justify a
> Fixes: tag? (mpe, I'm sure I've asked this before, sorry!)
>
> All up, this is a good correction to the comment.
>
> There are a few other functions in the file that have incorrect
> docstrings:
>
>  - eeh_pci_enable - missing parameter
>
>  - eeh_pe_reset and eeh_pe_reset_full - missing parameter
>
>  - eeh_init - missing parameter
>
>  - eeh_pe_inject_err - wrong name for a parameter
>
> Could you fix all of the docstrings in the file at once?

In fact, there  are other warnings in this file, I will fix them and send a
new patch soon.

Kind regards,
Kai



[PATCH 3/5] ARM: dts: ls1021a: remove "simple-bus" compatible from ifc node

2021-09-30 Thread Li Yang
The binding of ifc device has been updated.  Update dts to match
accordingly.

Signed-off-by: Li Yang 
---
 arch/arm/boot/dts/ls1021a.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index 7cddc05825a1..4aeb804e61b1 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -123,7 +123,7 @@ msi2: msi-controller@1570e08 {
};
 
ifc: ifc@153 {
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
reg = <0x0 0x153 0x0 0x1>;
interrupts = ;
status = "disabled";
-- 
2.25.1



[PATCH 1/5] dt-bindings: memory: fsl: convert ifc binding to yaml schema

2021-09-30 Thread Li Yang
Convert the txt binding to yaml format and add description.  Drop the
"simple-bus" compatible string from the example and not allowed by the
binding any more.  This will help to enforce the correct probe order
between parent device and child devices, but will require the ifc driver
to probe the child devices to work properly.

Signed-off-by: Li Yang 
---
updates from previous submission:
- Drop "simple-bus" from binding and only "fsl,ifc" as compatible
- Fix one identiation problem of "reg"
- Add type restriction to "little-endian" property

 .../bindings/memory-controllers/fsl/ifc.txt   |  82 ---
 .../bindings/memory-controllers/fsl/ifc.yaml  | 137 ++
 2 files changed, 137 insertions(+), 82 deletions(-)
 delete mode 100644 
Documentation/devicetree/bindings/memory-controllers/fsl/ifc.txt
 create mode 100644 
Documentation/devicetree/bindings/memory-controllers/fsl/ifc.yaml

diff --git a/Documentation/devicetree/bindings/memory-controllers/fsl/ifc.txt 
b/Documentation/devicetree/bindings/memory-controllers/fsl/ifc.txt
deleted file mode 100644
index 89427b018ba7..
--- a/Documentation/devicetree/bindings/memory-controllers/fsl/ifc.txt
+++ /dev/null
@@ -1,82 +0,0 @@
-Integrated Flash Controller
-
-Properties:
-- name : Should be ifc
-- compatible : should contain "fsl,ifc". The version of the integrated
-   flash controller can be found in the IFC_REV register at
-   offset zero.
-
-- #address-cells : Should be either two or three.  The first cell is the
-   chipselect number, and the remaining cells are the
-   offset into the chipselect.
-- #size-cells : Either one or two, depending on how large each chipselect
-can be.
-- reg : Offset and length of the register set for the device
-- interrupts: IFC may have one or two interrupts.  If two interrupt
-  specifiers are present, the first is the "common"
-  interrupt (CM_EVTER_STAT), and the second is the NAND
-  interrupt (NAND_EVTER_STAT).  If there is only one,
-  that interrupt reports both types of event.
-
-- little-endian : If this property is absent, the big-endian mode will
-  be in use as default for registers.
-
-- ranges : Each range corresponds to a single chipselect, and covers
-   the entire access window as configured.
-
-Child device nodes describe the devices connected to IFC such as NOR (e.g.
-cfi-flash) and NAND (fsl,ifc-nand). There might be board specific devices
-like FPGAs, CPLDs, etc.
-
-Example:
-
-   ifc@ffe1e000 {
-   compatible = "fsl,ifc", "simple-bus";
-   #address-cells = <2>;
-   #size-cells = <1>;
-   reg = <0x0 0xffe1e000 0 0x2000>;
-   interrupts = <16 2 19 2>;
-   little-endian;
-
-   /* NOR, NAND Flashes and CPLD on board */
-   ranges = <0x0 0x0 0x0 0xee00 0x0200
- 0x1 0x0 0x0 0xffa0 0x0001
- 0x3 0x0 0x0 0xffb0 0x0002>;
-
-   flash@0,0 {
-   #address-cells = <1>;
-   #size-cells = <1>;
-   compatible = "cfi-flash";
-   reg = <0x0 0x0 0x200>;
-   bank-width = <2>;
-   device-width = <1>;
-
-   partition@0 {
-   /* 32MB for user data */
-   reg = <0x0 0x0200>;
-   label = "NOR Data";
-   };
-   };
-
-   flash@1,0 {
-   #address-cells = <1>;
-   #size-cells = <1>;
-   compatible = "fsl,ifc-nand";
-   reg = <0x1 0x0 0x1>;
-
-   partition@0 {
-   /* This location must not be altered  */
-   /* 1MB for u-boot Bootloader Image */
-   reg = <0x0 0x0010>;
-   label = "NAND U-Boot Image";
-   read-only;
-   };
-   };
-
-   cpld@3,0 {
-   #address-cells = <1>;
-   #size-cells = <1>;
-   compatible = "fsl,p1010rdb-cpld";
-   reg = <0x3 0x0 0x01f>;
-   };
-   };
diff --git a/Documentation/devicetree/bindings/memory-controllers/fsl/ifc.yaml 
b/Documentation/devicetree/bindings/memory-controllers/fsl/ifc.yaml
new file mode 100644
index ..19871ce39fe3
--- /dev/null
+++ b/Documentation/devicetree/bindings/memory-controllers/fsl/ifc.yaml
@@ -0,0 +1,137 @@
+# SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/memory-controllers/fsl/ifc.yaml#
+$schema: 

[PATCH 4/5] arm64: dts: remove "simple-bus" compatible from ifc node

2021-09-30 Thread Li Yang
The binding of ifc device has been updated.  Update dts to match
accordingly.

Signed-off-by: Li Yang 
---
 arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi | 2 +-
 arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi | 2 +-
 arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi | 2 +-
 arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
index d856a1f45da1..b19a44204df8 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
@@ -435,7 +435,7 @@ dcfg: dcfg@1ee {
};
 
ifc: ifc@153 {
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
reg = <0x0 0x153 0x0 0x1>;
interrupts = <0 43 0x4>;
};
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
index 41904b8bc85e..1b065f134bd6 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
@@ -283,7 +283,7 @@ ddr: memory-controller@108 {
};
 
ifc: ifc@153 {
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
reg = <0x0 0x153 0x0 0x1>;
interrupts = ;
status = "disabled";
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
index f8f252fdc039..2b1b0adfd340 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
@@ -398,7 +398,7 @@ gpio3: gpio@233 {
};
 
ifc: ifc@224 {
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
reg = <0x0 0x224 0x0 0x2>;
interrupts = <0 21 IRQ_TYPE_LEVEL_HIGH>;
little-endian;
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
index d8590d080c5e..3679f1707048 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
@@ -1037,7 +1037,7 @@ i2c3: i2c@203 {
};
 
ifc: ifc@224 {
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
reg = <0x0 0x224 0x0 0x2>;
interrupts = <0 21 0x4>; /* Level high type */
little-endian;
-- 
2.25.1



[PATCH 5/5] powerpc/mpc85xx: remove "simple-bus" compatible from ifc node

2021-09-30 Thread Li Yang
The binding of ifc device has been updated.  Update dts to match
accordingly.

Signed-off-by: Li Yang 
---
 arch/powerpc/boot/dts/fsl/b4si-post.dtsi  | 2 +-
 arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi | 2 +-
 arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi | 2 +-
 arch/powerpc/boot/dts/fsl/c293si-post.dtsi| 2 +-
 arch/powerpc/boot/dts/fsl/p1010si-post.dtsi   | 2 +-
 arch/powerpc/boot/dts/fsl/t1023si-post.dtsi   | 2 +-
 arch/powerpc/boot/dts/fsl/t1040si-post.dtsi   | 2 +-
 arch/powerpc/boot/dts/fsl/t2081si-post.dtsi   | 2 +-
 arch/powerpc/boot/dts/fsl/t4240si-post.dtsi   | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/boot/dts/fsl/b4si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/b4si-post.dtsi
index 4f044b41a776..fb3200b006ad 100644
--- a/arch/powerpc/boot/dts/fsl/b4si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/b4si-post.dtsi
@@ -50,7 +50,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi
index 2a677fd323eb..5c53cee8755f 100644
--- a/arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi
@@ -35,7 +35,7 @@
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <16 2 0 0 20 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi
index b8e0edd1ac69..4da451e000d9 100644
--- a/arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi
@@ -35,7 +35,7 @@
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
/* FIXME: Test whether interrupts are split */
interrupts = <16 2 0 0 20 2 0 0>;
 };
diff --git a/arch/powerpc/boot/dts/fsl/c293si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/c293si-post.dtsi
index bec0fc36849d..ee3b45806ee3 100644
--- a/arch/powerpc/boot/dts/fsl/c293si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/c293si-post.dtsi
@@ -35,7 +35,7 @@
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <19 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi
index b540e58ff79e..2d2550729dcc 100644
--- a/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi
@@ -35,7 +35,7 @@
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <16 2 0 0 19 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi
index d552044c5afc..c15a49df66e1 100644
--- a/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi
@@ -52,7 +52,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi
index f58eb820eb5e..38703e58dd09 100644
--- a/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi
@@ -52,7 +52,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/t2081si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t2081si-post.dtsi
index ecbb447920bc..58ef8bf6045c 100644
--- a/arch/powerpc/boot/dts/fsl/t2081si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/t2081si-post.dtsi
@@ -50,7 +50,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/t4240si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t4240si-post.dtsi
index fcac73486d48..65f3e17c0d41 100644
--- a/arch/powerpc/boot/dts/fsl/t4240si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/t4240si-post.dtsi
@@ -50,7 +50,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
-- 
2.25.1



[PATCH 0/5] convert ifc binding to yaml and drop "simple-bus"

2021-09-30 Thread Li Yang
Convert the ifc binding to yaml schema, in the mean while remove the
"simple-bus" compatible from the binding to make sure ifc device probes
before any of the child devices.  Update the driver and existing DTSes
accordingly.

DTS changes should be merged together with the driver/binding changes
if DTS maintainer is ok with it or after the driver changes are applied.

Li Yang (5):
  dt-bindings: memory: fsl: convert ifc binding to yaml schema
  memory: fsl_ifc: populate child devices without relying on simple-bus
  ARM: dts: ls1021a: remove "simple-bus" compatible from ifc node
  arm64: dts: remove "simple-bus" compatible from ifc node
  powerpc/mpc85xx: remove "simple-bus" compatible from ifc node

 .../bindings/memory-controllers/fsl/ifc.txt   |  82 ---
 .../bindings/memory-controllers/fsl/ifc.yaml  | 137 ++
 arch/arm/boot/dts/ls1021a.dtsi|   2 +-
 .../arm64/boot/dts/freescale/fsl-ls1043a.dtsi |   2 +-
 .../arm64/boot/dts/freescale/fsl-ls1046a.dtsi |   2 +-
 .../arm64/boot/dts/freescale/fsl-ls1088a.dtsi |   2 +-
 .../arm64/boot/dts/freescale/fsl-ls208xa.dtsi |   2 +-
 arch/powerpc/boot/dts/fsl/b4si-post.dtsi  |   2 +-
 arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi |   2 +-
 arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi |   2 +-
 arch/powerpc/boot/dts/fsl/c293si-post.dtsi|   2 +-
 arch/powerpc/boot/dts/fsl/p1010si-post.dtsi   |   2 +-
 arch/powerpc/boot/dts/fsl/t1023si-post.dtsi   |   2 +-
 arch/powerpc/boot/dts/fsl/t1040si-post.dtsi   |   2 +-
 arch/powerpc/boot/dts/fsl/t2081si-post.dtsi   |   2 +-
 arch/powerpc/boot/dts/fsl/t4240si-post.dtsi   |   2 +-
 drivers/memory/fsl_ifc.c  |   9 ++
 17 files changed, 160 insertions(+), 96 deletions(-)
 delete mode 100644 
Documentation/devicetree/bindings/memory-controllers/fsl/ifc.txt
 create mode 100644 
Documentation/devicetree/bindings/memory-controllers/fsl/ifc.yaml

-- 
2.25.1



[PATCH 2/5] memory: fsl_ifc: populate child devices without relying on simple-bus

2021-09-30 Thread Li Yang
After we update the binding to not use simple-bus compatible for the
controller, we need the driver to populate the child devices explicitly.

Signed-off-by: Li Yang 
---
 drivers/memory/fsl_ifc.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/memory/fsl_ifc.c b/drivers/memory/fsl_ifc.c
index d062c2f8250f..251d713cd50b 100644
--- a/drivers/memory/fsl_ifc.c
+++ b/drivers/memory/fsl_ifc.c
@@ -88,6 +88,7 @@ static int fsl_ifc_ctrl_remove(struct platform_device *dev)
 {
struct fsl_ifc_ctrl *ctrl = dev_get_drvdata(>dev);
 
+   of_platform_depopulate(>dev);
free_irq(ctrl->nand_irq, ctrl);
free_irq(ctrl->irq, ctrl);
 
@@ -285,6 +286,14 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
}
}
 
+   /* legacy dts may still use "simple-bus" compatible */
+   if (!of_device_is_compatible(dev->dev.of_node, "simple-bus")) {
+   ret = of_platform_populate(dev->dev.of_node, NULL, NULL,
+   >dev);
+   if (ret)
+   goto err_nandirq;
+   }
+
return 0;
 
 err_nandirq:
-- 
2.25.1



Re: [PATCH v2 0/6] memblock: cleanup memblock_free interface

2021-09-30 Thread Mike Rapoport
On Thu, Sep 30, 2021 at 02:20:33PM -0700, Linus Torvalds wrote:
> On Thu, Sep 30, 2021 at 11:50 AM Mike Rapoport  wrote:
> >
> > The first patch is a cleanup of numa_distance allocation in arch_numa I've
> > spotted during the conversion.
> > The second patch is a fix for Xen memory freeing on some of the error
> > paths.
> 
> Well, at least patch 2 looks like something that should go into 5.15
> and be marked for stable.
> 
> Patch 1 looks like a trivial local cleanup, and could go in
> immediately. Patch 4 might be in that same category.
> 
> The rest look like "next merge window" to me, since they are spread
> out and neither bugfixes nor tiny localized cleanups (iow renaming
> functions, global resulting search-and-replace things).
> 
> So my gut feel is that two (maybe three) of these patches should go in
> asap, with three (maybe four) be left for 5.16.
> 
> IOW, not trat this as a single series.
> 
> Hmm?

Yes, why not :)
I'd keep patch 4 for the next merge window, does not look urgent to me.

Andrew, can you please take care of this or you'd prefer me resending
everything separately?
 
>  Linus

-- 
Sincerely yours,
Mike.


Re: [PATCH v2 0/6] memblock: cleanup memblock_free interface

2021-09-30 Thread Linus Torvalds
On Thu, Sep 30, 2021 at 11:50 AM Mike Rapoport  wrote:
>
> The first patch is a cleanup of numa_distance allocation in arch_numa I've
> spotted during the conversion.
> The second patch is a fix for Xen memory freeing on some of the error
> paths.

Well, at least patch 2 looks like something that should go into 5.15
and be marked for stable.

Patch 1 looks like a trivial local cleanup, and could go in
immediately. Patch 4 might be in that same category.

The rest look like "next merge window" to me, since they are spread
out and neither bugfixes nor tiny localized cleanups (iow renaming
functions, global resulting search-and-replace things).

So my gut feel is that two (maybe three) of these patches should go in
asap, with three (maybe four) be left for 5.16.

IOW, not trat this as a single series.

Hmm?

 Linus


Re: [PATCH v4 0/8] bpf powerpc: Add BPF_PROBE_MEM support in powerpc JIT compiler

2021-09-30 Thread Daniel Borkmann

On 9/29/21 1:18 PM, Hari Bathini wrote:

Patch #1 & #2 are simple cleanup patches. Patch #3 refactors JIT
compiler code with the aim to simplify adding BPF_PROBE_MEM support.
Patch #4 introduces PPC_RAW_BRANCH() macro instead of open coding
branch instruction. Patch #5 & #7 add BPF_PROBE_MEM support for PPC64
& PPC32 JIT compilers respectively. Patch #6 & #8 handle bad userspace
pointers for PPC64 & PPC32 cases respectively.


Michael, are you planning to pick up the series or shall we route via bpf-next?

Thanks,
Daniel


Changes in v4:
* Addressed all the review comments from Christophe.


Hari Bathini (4):
   bpf powerpc: refactor JIT compiler code
   powerpc/ppc-opcode: introduce PPC_RAW_BRANCH() macro
   bpf ppc32: Add BPF_PROBE_MEM support for JIT
   bpf ppc32: Access only if addr is kernel address

Ravi Bangoria (4):
   bpf powerpc: Remove unused SEEN_STACK
   bpf powerpc: Remove extra_pass from bpf_jit_build_body()
   bpf ppc64: Add BPF_PROBE_MEM support for JIT
   bpf ppc64: Access only if addr is kernel address

  arch/powerpc/include/asm/ppc-opcode.h |   2 +
  arch/powerpc/net/bpf_jit.h|  19 +++--
  arch/powerpc/net/bpf_jit_comp.c   |  72 --
  arch/powerpc/net/bpf_jit_comp32.c | 101 ++
  arch/powerpc/net/bpf_jit_comp64.c |  72 ++
  5 files changed, 224 insertions(+), 42 deletions(-)





Re: [PATCH v4 07/11] mm: kasan: Use is_kernel() helper

2021-09-30 Thread Alexander Potapenko
On Thu, Sep 30, 2021 at 9:09 AM Kefeng Wang  wrote:
>
> Directly use is_kernel() helper in kernel_or_module_addr().
>
> Cc: Andrey Ryabinin 
> Cc: Alexander Potapenko 
> Cc: Andrey Konovalov 
> Cc: Dmitry Vyukov 
> Signed-off-by: Kefeng Wang 
Reviewed-by: Alexander Potapenko 

> ---
>  mm/kasan/report.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> index 3239fd8f8747..1c955e1c98d5 100644
> --- a/mm/kasan/report.c
> +++ b/mm/kasan/report.c
> @@ -226,7 +226,7 @@ static void describe_object(struct kmem_cache *cache, 
> void *object,
>
>  static inline bool kernel_or_module_addr(const void *addr)
>  {
> -   if (addr >= (void *)_stext && addr < (void *)_end)
> +   if (is_kernel((unsigned long)addr))
> return true;
> if (is_module_address((unsigned long)addr))
> return true;
> --
> 2.26.2
>


-- 
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg


[PATCH v2 6/6] memblock: use memblock_free for freeing virtual pointers

2021-09-30 Thread Mike Rapoport
From: Mike Rapoport 

Rename memblock_free_ptr() to memblock_free() and use memblock_free()
when freeing a virtual pointer so that memblock_free() will be a
counterpart of memblock_alloc()

The callers are updated with the below semantic patch and manual addition
of (void *) casting to pointers that are represented by unsigned long
variables.

@@
identifier vaddr;
expression size;
@@
(
- memblock_phys_free(__pa(vaddr), size);
+ memblock_free(vaddr, size);
|
- memblock_free_ptr(vaddr, size);
+ memblock_free(vaddr, size);
)

Signed-off-by: Mike Rapoport 
---
 arch/alpha/kernel/core_irongate.c | 3 +--
 arch/mips/mm/init.c   | 2 +-
 arch/powerpc/kernel/dt_cpu_ftrs.c | 4 ++--
 arch/powerpc/kernel/setup-common.c| 2 +-
 arch/powerpc/kernel/setup_64.c| 2 +-
 arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
 arch/powerpc/platforms/pseries/svm.c  | 3 +--
 arch/riscv/kernel/setup.c | 5 ++---
 arch/sparc/kernel/smp_64.c| 2 +-
 arch/um/kernel/mem.c  | 2 +-
 arch/x86/kernel/setup_percpu.c| 2 +-
 arch/x86/mm/kasan_init_64.c   | 4 ++--
 arch/x86/mm/numa.c| 2 +-
 arch/x86/mm/numa_emulation.c  | 2 +-
 arch/x86/xen/mmu_pv.c | 2 +-
 arch/x86/xen/p2m.c| 2 +-
 drivers/base/arch_numa.c  | 4 ++--
 drivers/macintosh/smu.c   | 2 +-
 drivers/xen/swiotlb-xen.c | 2 +-
 include/linux/memblock.h  | 2 +-
 init/initramfs.c  | 2 +-
 init/main.c   | 2 +-
 kernel/dma/swiotlb.c  | 2 +-
 kernel/printk/printk.c| 4 ++--
 lib/bootconfig.c  | 2 +-
 lib/cpumask.c | 2 +-
 mm/memblock.c | 6 +++---
 mm/percpu.c   | 8 
 mm/sparse.c   | 2 +-
 29 files changed, 39 insertions(+), 42 deletions(-)

diff --git a/arch/alpha/kernel/core_irongate.c 
b/arch/alpha/kernel/core_irongate.c
index ee26dcc49418..6b8ed12936b6 100644
--- a/arch/alpha/kernel/core_irongate.c
+++ b/arch/alpha/kernel/core_irongate.c
@@ -233,8 +233,7 @@ albacore_init_arch(void)
unsigned long size;
 
size = initrd_end - initrd_start;
-   memblock_phys_free(__pa(initrd_start),
-  PAGE_ALIGN(size));
+   memblock_free((void *)initrd_start, PAGE_ALIGN(size));
if (!move_initrd(pci_mem))
printk("irongate_init_arch: initrd too big "
   "(%ldK)\ndisabling initrd\n",
diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 3be1c29084fa..325e1552cbea 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -529,7 +529,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t 
size,
 
 static void __init pcpu_fc_free(void *ptr, size_t size)
 {
-   memblock_phys_free(__pa(ptr), size);
+   memblock_free(ptr, size);
 }
 
 void __init setup_per_cpu_areas(void)
diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c 
b/arch/powerpc/kernel/dt_cpu_ftrs.c
index 42839d6bd486..ba527fb52993 100644
--- a/arch/powerpc/kernel/dt_cpu_ftrs.c
+++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
@@ -1095,8 +1095,8 @@ static int __init dt_cpu_ftrs_scan_callback(unsigned long 
node, const char
 
cpufeatures_setup_finished();
 
-   memblock_phys_free(__pa(dt_cpu_features),
-  sizeof(struct dt_cpu_feature) * nr_dt_cpu_features);
+   memblock_free(dt_cpu_features,
+ sizeof(struct dt_cpu_feature) * nr_dt_cpu_features);
 
return 0;
 }
diff --git a/arch/powerpc/kernel/setup-common.c 
b/arch/powerpc/kernel/setup-common.c
index 5af8993a8e6d..6b1338db8779 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -825,7 +825,7 @@ static void __init smp_setup_pacas(void)
set_hard_smp_processor_id(cpu, cpu_to_phys_id[cpu]);
}
 
-   memblock_phys_free(__pa(cpu_to_phys_id), nr_cpu_ids * sizeof(u32));
+   memblock_free(cpu_to_phys_id, nr_cpu_ids * sizeof(u32));
cpu_to_phys_id = NULL;
 }
 #endif
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 75bc294ac40d..1777e992b20b 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -812,7 +812,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, 
size_t size,
 
 static void __init pcpu_free_bootmem(void *ptr, size_t size)
 {
-   memblock_phys_free(__pa(ptr), size);
+   memblock_free(ptr, size);
 }
 
 static int pcpu_cpu_distance(unsigned int from, unsigned int to)
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 

[PATCH v2 5/6] memblock: rename memblock_free to memblock_phys_free

2021-09-30 Thread Mike Rapoport
From: Mike Rapoport 

Since memblock_free() operates on a physical range, make its name reflect
it and rename it to memblock_phys_free(), so it will be a logical
counterpart to memblock_phys_alloc().

The callers are updated with the below semantic patch:

@@
expression addr;
expression size;
@@
- memblock_free(addr, size);
+ memblock_phys_free(addr, size);

Signed-off-by: Mike Rapoport 
---
 arch/alpha/kernel/core_irongate.c |  3 ++-
 arch/arc/mm/init.c|  2 +-
 arch/arm/mach-hisi/platmcpm.c |  2 +-
 arch/arm/mm/init.c|  2 +-
 arch/arm64/mm/mmu.c   |  4 ++--
 arch/mips/mm/init.c   |  2 +-
 arch/mips/sgi-ip30/ip30-setup.c   |  6 +++---
 arch/powerpc/kernel/dt_cpu_ftrs.c |  4 ++--
 arch/powerpc/kernel/paca.c|  8 
 arch/powerpc/kernel/setup-common.c|  2 +-
 arch/powerpc/kernel/setup_64.c|  2 +-
 arch/powerpc/platforms/powernv/pci-ioda.c |  2 +-
 arch/powerpc/platforms/pseries/svm.c  |  3 ++-
 arch/riscv/kernel/setup.c |  5 +++--
 arch/s390/kernel/setup.c  |  8 
 arch/s390/kernel/smp.c|  4 ++--
 arch/s390/kernel/uv.c |  2 +-
 arch/s390/mm/kasan_init.c |  2 +-
 arch/sh/boards/mach-ap325rxa/setup.c  |  2 +-
 arch/sh/boards/mach-ecovec24/setup.c  |  4 ++--
 arch/sh/boards/mach-kfr2r09/setup.c   |  2 +-
 arch/sh/boards/mach-migor/setup.c |  2 +-
 arch/sh/boards/mach-se/7724/setup.c   |  4 ++--
 arch/sparc/kernel/smp_64.c|  2 +-
 arch/um/kernel/mem.c  |  2 +-
 arch/x86/kernel/setup.c   |  4 ++--
 arch/x86/mm/init.c|  2 +-
 arch/x86/xen/mmu_pv.c |  6 +++---
 arch/x86/xen/setup.c  |  6 +++---
 drivers/base/arch_numa.c  |  2 +-
 drivers/firmware/efi/memmap.c |  2 +-
 drivers/of/kexec.c|  3 +--
 drivers/of/of_reserved_mem.c  |  5 +++--
 drivers/s390/char/sclp_early.c|  2 +-
 drivers/usb/early/xhci-dbc.c  | 10 +-
 drivers/xen/swiotlb-xen.c |  2 +-
 include/linux/memblock.h  |  2 +-
 init/initramfs.c  |  2 +-
 kernel/dma/swiotlb.c  |  2 +-
 lib/cpumask.c |  2 +-
 mm/cma.c  |  2 +-
 mm/memblock.c |  8 
 mm/memory_hotplug.c   |  2 +-
 mm/percpu.c   |  8 
 mm/sparse.c   |  2 +-
 45 files changed, 79 insertions(+), 76 deletions(-)

diff --git a/arch/alpha/kernel/core_irongate.c 
b/arch/alpha/kernel/core_irongate.c
index 72af1e72d833..ee26dcc49418 100644
--- a/arch/alpha/kernel/core_irongate.c
+++ b/arch/alpha/kernel/core_irongate.c
@@ -233,7 +233,8 @@ albacore_init_arch(void)
unsigned long size;
 
size = initrd_end - initrd_start;
-   memblock_free(__pa(initrd_start), PAGE_ALIGN(size));
+   memblock_phys_free(__pa(initrd_start),
+  PAGE_ALIGN(size));
if (!move_initrd(pci_mem))
printk("irongate_init_arch: initrd too big "
   "(%ldK)\ndisabling initrd\n",
diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index 699ecf119641..59408f6a02d4 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -173,7 +173,7 @@ static void __init highmem_init(void)
 #ifdef CONFIG_HIGHMEM
unsigned long tmp;
 
-   memblock_free(high_mem_start, high_mem_sz);
+   memblock_phys_free(high_mem_start, high_mem_sz);
for (tmp = min_high_pfn; tmp < max_high_pfn; tmp++)
free_highmem_page(pfn_to_page(tmp));
 #endif
diff --git a/arch/arm/mach-hisi/platmcpm.c b/arch/arm/mach-hisi/platmcpm.c
index 96a484095194..258586e31333 100644
--- a/arch/arm/mach-hisi/platmcpm.c
+++ b/arch/arm/mach-hisi/platmcpm.c
@@ -339,7 +339,7 @@ static int __init hip04_smp_init(void)
 err_sysctrl:
iounmap(relocation);
 err_reloc:
-   memblock_free(hip04_boot_method[0], hip04_boot_method[1]);
+   memblock_phys_free(hip04_boot_method[0], hip04_boot_method[1]);
 err:
return ret;
 }
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 6162a070a410..6d0cb0f7bc54 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -158,7 +158,7 @@ phys_addr_t __init arm_memblock_steal(phys_addr_t size, 
phys_addr_t align)
panic("Failed to steal %pa bytes at %pS\n",
  , (void *)_RET_IP_);
 
-   memblock_free(phys, size);
+   memblock_phys_free(phys, size);
memblock_remove(phys, size);
 
return phys;
diff 

[PATCH v2 4/6] memblock: stop aliasing __memblock_free_late with memblock_free_late

2021-09-30 Thread Mike Rapoport
From: Mike Rapoport 

memblock_free_late() is a NOP wrapper for __memblock_free_late(), there is
no point to keep this indirection.

Drop the wrapper and rename __memblock_free_late() to memblock_free_late().

Signed-off-by: Mike Rapoport 
---
 include/linux/memblock.h | 7 +--
 mm/memblock.c| 8 
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index fc8183be340c..e25f964fdd60 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -133,7 +133,7 @@ void __next_mem_range_rev(u64 *idx, int nid, enum 
memblock_flags flags,
  struct memblock_type *type_b, phys_addr_t *out_start,
  phys_addr_t *out_end, int *out_nid);
 
-void __memblock_free_late(phys_addr_t base, phys_addr_t size);
+void memblock_free_late(phys_addr_t base, phys_addr_t size);
 
 #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
 static inline void __next_physmem_range(u64 *idx, struct memblock_type *type,
@@ -441,11 +441,6 @@ static inline void *memblock_alloc_node(phys_addr_t size,
  MEMBLOCK_ALLOC_ACCESSIBLE, nid);
 }
 
-static inline void memblock_free_late(phys_addr_t base, phys_addr_t size)
-{
-   __memblock_free_late(base, size);
-}
-
 /*
  * Set the allocation direction to bottom-up or top-down.
  */
diff --git a/mm/memblock.c b/mm/memblock.c
index 184dcd2e5d99..603f4a02be9b 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -366,14 +366,14 @@ void __init memblock_discard(void)
addr = __pa(memblock.reserved.regions);
size = PAGE_ALIGN(sizeof(struct memblock_region) *
  memblock.reserved.max);
-   __memblock_free_late(addr, size);
+   memblock_free_late(addr, size);
}
 
if (memblock.memory.regions != memblock_memory_init_regions) {
addr = __pa(memblock.memory.regions);
size = PAGE_ALIGN(sizeof(struct memblock_region) *
  memblock.memory.max);
-   __memblock_free_late(addr, size);
+   memblock_free_late(addr, size);
}
 
memblock_memory = NULL;
@@ -1586,7 +1586,7 @@ void * __init memblock_alloc_try_nid(
 }
 
 /**
- * __memblock_free_late - free pages directly to buddy allocator
+ * memblock_free_late - free pages directly to buddy allocator
  * @base: phys starting address of the  boot memory block
  * @size: size of the boot memory block in bytes
  *
@@ -1594,7 +1594,7 @@ void * __init memblock_alloc_try_nid(
  * down, but we are still initializing the system.  Pages are released directly
  * to the buddy allocator.
  */
-void __init __memblock_free_late(phys_addr_t base, phys_addr_t size)
+void __init memblock_free_late(phys_addr_t base, phys_addr_t size)
 {
phys_addr_t cursor, end;
 
-- 
2.28.0



[PATCH v2 3/6] memblock: drop memblock_free_early_nid() and memblock_free_early()

2021-09-30 Thread Mike Rapoport
From: Mike Rapoport 

memblock_free_early_nid() is unused and memblock_free_early() is an alias
for memblock_free().

Replace calls to memblock_free_early() with calls to memblock_free() and
remove memblock_free_early() and memblock_free_early_nid().

Signed-off-by: Mike Rapoport 
---
 arch/mips/mm/init.c  |  2 +-
 arch/powerpc/platforms/pseries/svm.c |  3 +--
 arch/s390/kernel/smp.c   |  2 +-
 drivers/base/arch_numa.c |  2 +-
 drivers/s390/char/sclp_early.c   |  2 +-
 include/linux/memblock.h | 12 
 kernel/dma/swiotlb.c |  2 +-
 lib/cpumask.c|  2 +-
 mm/percpu.c  |  8 
 mm/sparse.c  |  2 +-
 10 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 19347dc6bbf8..21a5a7ac0037 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -529,7 +529,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t 
size,
 
 static void __init pcpu_fc_free(void *ptr, size_t size)
 {
-   memblock_free_early(__pa(ptr), size);
+   memblock_free(__pa(ptr), size);
 }
 
 void __init setup_per_cpu_areas(void)
diff --git a/arch/powerpc/platforms/pseries/svm.c 
b/arch/powerpc/platforms/pseries/svm.c
index 87f001b4c4e4..f12229ce7301 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -56,8 +56,7 @@ void __init svm_swiotlb_init(void)
return;
 
 
-   memblock_free_early(__pa(vstart),
-   PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
+   memblock_free(__pa(vstart), PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
panic("SVM: Cannot allocate SWIOTLB buffer");
 }
 
diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
index 1a04e5bdf655..066efd6d9345 100644
--- a/arch/s390/kernel/smp.c
+++ b/arch/s390/kernel/smp.c
@@ -880,7 +880,7 @@ void __init smp_detect_cpus(void)
 
/* Add CPUs present at boot */
__smp_rescan_cpus(info, true);
-   memblock_free_early((unsigned long)info, sizeof(*info));
+   memblock_free((unsigned long)info, sizeof(*info));
 }
 
 /*
diff --git a/drivers/base/arch_numa.c b/drivers/base/arch_numa.c
index f6d0efd01188..e28d9dfe3c20 100644
--- a/drivers/base/arch_numa.c
+++ b/drivers/base/arch_numa.c
@@ -165,7 +165,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t 
size,
 
 static void __init pcpu_fc_free(void *ptr, size_t size)
 {
-   memblock_free_early(__pa(ptr), size);
+   memblock_free(__pa(ptr), size);
 }
 
 void __init setup_per_cpu_areas(void)
diff --git a/drivers/s390/char/sclp_early.c b/drivers/s390/char/sclp_early.c
index f3d5c7f4c13d..f01d942e1c1d 100644
--- a/drivers/s390/char/sclp_early.c
+++ b/drivers/s390/char/sclp_early.c
@@ -139,7 +139,7 @@ int __init sclp_early_get_core_info(struct sclp_core_info 
*info)
}
sclp_fill_core_info(info, sccb);
 out:
-   memblock_free_early((unsigned long)sccb, length);
+   memblock_free((unsigned long)sccb, length);
return rc;
 }
 
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 34de69b3b8ba..fc8183be340c 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -441,18 +441,6 @@ static inline void *memblock_alloc_node(phys_addr_t size,
  MEMBLOCK_ALLOC_ACCESSIBLE, nid);
 }
 
-static inline void memblock_free_early(phys_addr_t base,
- phys_addr_t size)
-{
-   memblock_free(base, size);
-}
-
-static inline void memblock_free_early_nid(phys_addr_t base,
- phys_addr_t size, int nid)
-{
-   memblock_free(base, size);
-}
-
 static inline void memblock_free_late(phys_addr_t base, phys_addr_t size)
 {
__memblock_free_late(base, size);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 87c40517e822..430d2f78d540 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -247,7 +247,7 @@ swiotlb_init(int verbose)
return;
 
 fail_free_mem:
-   memblock_free_early(__pa(tlb), bytes);
+   memblock_free(__pa(tlb), bytes);
 fail:
pr_warn("Cannot allocate buffer");
 }
diff --git a/lib/cpumask.c b/lib/cpumask.c
index c3c76b833384..045779446a18 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -188,7 +188,7 @@ EXPORT_SYMBOL(free_cpumask_var);
  */
 void __init free_bootmem_cpumask_var(cpumask_var_t mask)
 {
-   memblock_free_early(__pa(mask), cpumask_size());
+   memblock_free(__pa(mask), cpumask_size());
 }
 #endif
 
diff --git a/mm/percpu.c b/mm/percpu.c
index e0a986818903..f58318cb04c0 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -2472,7 +2472,7 @@ struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int 
nr_groups,
  */
 void __init pcpu_free_alloc_info(struct pcpu_alloc_info *ai)
 {
-   memblock_free_early(__pa(ai), ai->__ai_size);
+   

[PATCH v2 2/6] xen/x86: free_p2m_page: use memblock_free_ptr() to free a virtual pointer

2021-09-30 Thread Mike Rapoport
From: Mike Rapoport 

free_p2m_page() wrongly passes a virtual pointer to memblock_free() that
treats it as a physical address.

Call memblock_free_ptr() instead that gets a virtual address to free the
memory.

Signed-off-by: Mike Rapoport 
Reviewed-by: Juergen Gross 
---
 arch/x86/xen/p2m.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c
index 5e6e236977c7..141bb9dbd2fb 100644
--- a/arch/x86/xen/p2m.c
+++ b/arch/x86/xen/p2m.c
@@ -197,7 +197,7 @@ static void * __ref alloc_p2m_page(void)
 static void __ref free_p2m_page(void *p)
 {
if (unlikely(!slab_is_available())) {
-   memblock_free((unsigned long)p, PAGE_SIZE);
+   memblock_free_ptr(p, PAGE_SIZE);
return;
}
 
-- 
2.28.0



[PATCH v2 1/6] arch_numa: simplify numa_distance allocation

2021-09-30 Thread Mike Rapoport
From: Mike Rapoport 

Memory allocation of numa_distance uses memblock_phys_alloc_range() without
actual range limits, converts the returned physical address to virtual and
then only uses the virtual address for further initialization.

Simplify this by replacing memblock_phys_alloc_range() with
memblock_alloc().

Signed-off-by: Mike Rapoport 
---
 drivers/base/arch_numa.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/base/arch_numa.c b/drivers/base/arch_numa.c
index 00fb4120a5b3..f6d0efd01188 100644
--- a/drivers/base/arch_numa.c
+++ b/drivers/base/arch_numa.c
@@ -275,15 +275,13 @@ void __init numa_free_distance(void)
 static int __init numa_alloc_distance(void)
 {
size_t size;
-   u64 phys;
int i, j;
 
size = nr_node_ids * nr_node_ids * sizeof(numa_distance[0]);
-   phys = memblock_phys_alloc_range(size, PAGE_SIZE, 0, PFN_PHYS(max_pfn));
-   if (WARN_ON(!phys))
+   numa_distance = memblock_alloc(size, PAGE_SIZE);
+   if (WARN_ON(!numa_distance))
return -ENOMEM;
 
-   numa_distance = __va(phys);
numa_distance_cnt = nr_node_ids;
 
/* fill with the default distances */
-- 
2.28.0



[PATCH v2 0/6] memblock: cleanup memblock_free interface

2021-09-30 Thread Mike Rapoport
From: Mike Rapoport 

Hi,

Following the discussion on [1] this is the fix for memblock freeing APIs
mismatch. 

The first patch is a cleanup of numa_distance allocation in arch_numa I've
spotted during the conversion.
The second patch is a fix for Xen memory freeing on some of the error
paths.

I agree with Christophe that doing step by step makes the thing easier to
review, so the patches 3-6 do the actual cleanup step by step.

This time I used stricter coccinelle scripts so that only straightforward
uses would get converted.

There still a couple of (void *) castings for the cases when a virtual
address has unsigned long type rather than a pointer type, like e.g
initrd_start.

Since scripts/get_maintainer.pl returned more than 100 addresses I've
trimmed the distribution list only to the relevant lists.

Juergen and Shahab, I didn't keep your Reviewed-by because the patches are
a bit different this time.

v2:
* split changes into several patches
* use stricter coccinelle scripts 

[1] 
https://lore.kernel.org/all/CAHk-=wj9k4LZTz+svCxLYs5Y1=+ykrbauarh1+ghyg3old8...@mail.gmail.com

Mike Rapoport (6):
  arch_numa: simplify numa_distance allocation
  xen/x86: free_p2m_page: use memblock_free_ptr() to free a virtual pointer
  memblock: drop memblock_free_early_nid() and memblock_free_early()
  memblock: stop aliasing __memblock_free_late with memblock_free_late
  memblock: rename memblock_free to memblock_phys_free
  memblock: use memblock_free for freeing virtual pointers

 arch/alpha/kernel/core_irongate.c |  2 +-
 arch/arc/mm/init.c|  2 +-
 arch/arm/mach-hisi/platmcpm.c |  2 +-
 arch/arm/mm/init.c|  2 +-
 arch/arm64/mm/mmu.c   |  4 ++--
 arch/mips/mm/init.c   |  2 +-
 arch/mips/sgi-ip30/ip30-setup.c   |  6 +++---
 arch/powerpc/kernel/dt_cpu_ftrs.c |  4 ++--
 arch/powerpc/kernel/paca.c|  8 
 arch/powerpc/kernel/setup-common.c|  2 +-
 arch/powerpc/kernel/setup_64.c|  2 +-
 arch/powerpc/platforms/powernv/pci-ioda.c |  2 +-
 arch/powerpc/platforms/pseries/svm.c  |  3 +--
 arch/riscv/kernel/setup.c |  4 ++--
 arch/s390/kernel/setup.c  |  8 
 arch/s390/kernel/smp.c|  4 ++--
 arch/s390/kernel/uv.c |  2 +-
 arch/s390/mm/kasan_init.c |  2 +-
 arch/sh/boards/mach-ap325rxa/setup.c  |  2 +-
 arch/sh/boards/mach-ecovec24/setup.c  |  4 ++--
 arch/sh/boards/mach-kfr2r09/setup.c   |  2 +-
 arch/sh/boards/mach-migor/setup.c |  2 +-
 arch/sh/boards/mach-se/7724/setup.c   |  4 ++--
 arch/sparc/kernel/smp_64.c|  2 +-
 arch/um/kernel/mem.c  |  2 +-
 arch/x86/kernel/setup.c   |  4 ++--
 arch/x86/kernel/setup_percpu.c|  2 +-
 arch/x86/mm/init.c|  2 +-
 arch/x86/mm/kasan_init_64.c   |  4 ++--
 arch/x86/mm/numa.c|  2 +-
 arch/x86/mm/numa_emulation.c  |  2 +-
 arch/x86/xen/mmu_pv.c |  6 +++---
 arch/x86/xen/p2m.c|  2 +-
 arch/x86/xen/setup.c  |  6 +++---
 drivers/base/arch_numa.c  | 10 --
 drivers/firmware/efi/memmap.c |  2 +-
 drivers/macintosh/smu.c   |  2 +-
 drivers/of/kexec.c|  3 +--
 drivers/of/of_reserved_mem.c  |  5 +++--
 drivers/s390/char/sclp_early.c|  2 +-
 drivers/usb/early/xhci-dbc.c  | 10 +-
 drivers/xen/swiotlb-xen.c |  2 +-
 include/linux/memblock.h  | 23 +++
 init/initramfs.c  |  2 +-
 init/main.c   |  2 +-
 kernel/dma/swiotlb.c  |  2 +-
 kernel/printk/printk.c|  4 ++--
 lib/bootconfig.c  |  2 +-
 lib/cpumask.c |  2 +-
 mm/cma.c  |  2 +-
 mm/memblock.c | 22 +++---
 mm/memory_hotplug.c   |  2 +-
 mm/percpu.c   |  8 
 mm/sparse.c   |  2 +-
 54 files changed, 99 insertions(+), 119 deletions(-)


base-commit: 5816b3e6577eaa676ceb00a848f0fd65fe2adc29
-- 
2.28.0



Re: [RFC PATCH 4/8] powerpc: add CPU field to struct thread_info

2021-09-30 Thread Kees Cook
On Thu, Sep 30, 2021 at 08:46:04AM +1000, Michael Ellerman wrote:
> Ard Biesheuvel  writes:
> > On Tue, 28 Sept 2021 at 02:16, Michael Ellerman  wrote:
> >>
> >> Michael Ellerman  writes:
> >> > Ard Biesheuvel  writes:
> >> >> On Tue, 14 Sept 2021 at 14:11, Ard Biesheuvel  wrote:
> >> >>>
> >> >>> The CPU field will be moved back into thread_info even when
> >> >>> THREAD_INFO_IN_TASK is enabled, so add it back to powerpc's definition
> >> >>> of struct thread_info.
> >> >>>
> >> >>> Signed-off-by: Ard Biesheuvel 
> >> >>
> >> >> Michael,
> >> >>
> >> >> Do you have any objections or issues with this patch or the subsequent
> >> >> ones cleaning up the task CPU kludge for ppc32? Christophe indicated
> >> >> that he was happy with it.
> >> >
> >> > No objections, it looks good to me, thanks for cleaning up that horror :)
> >> >
> >> > It didn't apply cleanly to master so I haven't tested it at all, if you 
> >> > can point me at a
> >> > git tree with the dependencies I'd be happy to run some tests over it.
> >>
> >> Actually I realised I can just drop the last patch.
> >>
> >> So that looks fine, passes my standard quick build & boot on qemu tests,
> >> and builds with/without stack protector enabled.
> >>
> >
> > Thanks.
> >
> > Do you have any opinion on how this series should be merged? Kees Cook
> > is willing to take them via his cross-arch tree, or you could carry
> > them if you prefer. Taking it via multiple trees at the same time is
> > going to be tricky, or take two cycles, with I'd prefer to avoid.
> 
> I don't really mind. If Kees is happy to take it then that's OK by me.
> 
> If Kees put the series in a topic branch based off rc2 then I could
> merge that, and avoid any conflicts.

I've created:

git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git 
for-next/thread_info/cpu

it includes a --no-ff merge commit, which I'm not sure is desirable? Let
me know if I should adjust this, or if Linus will yell about this if I
send him a PR containing a merge commit? I'm not sure what's right here.

Thanks!

-- 
Kees Cook


[PATCH v2 5/9] xen/x86: make "earlyprintk=xen" work for HVM/PVH DomU

2021-09-30 Thread Jan Beulich
xenboot_write_console() is dealing with these quite fine so I don't see
why xenboot_console_setup() would return -ENOENT in this case.

Adjust documentation accordingly.

Signed-off-by: Jan Beulich 
Reviewed-by: Juergen Gross 

--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1266,7 +1266,7 @@
The VGA and EFI output is eventually overwritten by
the real console.
 
-   The xen output can only be used by Xen PV guests.
+   The xen option can only be used in Xen domains.
 
The sclp output can only be used on s390.
 
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -618,10 +618,8 @@ static int __init xenboot_console_setup(
 {
static struct xencons_info xenboot;
 
-   if (xen_initial_domain())
+   if (xen_initial_domain() || !xen_pv_domain())
return 0;
-   if (!xen_pv_domain())
-   return -ENODEV;
 
return xencons_info_pv_init(, 0);
 }



[PATCH v2 3/9] xen/x86: make "earlyprintk=xen" work better for PVH Dom0

2021-09-30 Thread Jan Beulich
The xen_hvm_early_write() path better wouldn't be taken in this case;
while port 0xE9 can be used, the hypercall path is quite a bit more
efficient. Put that first, as it may also work for DomU-s (see also
xen_raw_console_write()).

While there also bail from the function when the first
domU_write_console() failed - later ones aren't going to succeed.

Signed-off-by: Jan Beulich 
Reviewed-by: Juergen Gross 

--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -632,17 +632,16 @@ static void xenboot_write_console(struct
unsigned int linelen, off = 0;
const char *pos;
 
+   if (dom0_write_console(0, string, len) >= 0)
+   return;
+
if (!xen_pv_domain()) {
xen_hvm_early_write(0, string, len);
return;
}
 
-   dom0_write_console(0, string, len);
-
-   if (xen_initial_domain())
+   if (domU_write_console(0, "(early) ", 8) < 0)
return;
-
-   domU_write_console(0, "(early) ", 8);
while (off < len && NULL != (pos = strchr(string+off, '\n'))) {
linelen = pos-string+off;
if (off + linelen > len)



[Bug 206669] Little-endian kernel crashing on POWER8 on heavy big-endian PowerKVM load

2021-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=206669

--- Comment #17 from John Paul Adrian Glaubitz (glaub...@physik.fu-berlin.de) 
---
POWER server crashes with 100% reproducibility when building GCC in a powerpc
chroot and GCC in a ppc64 chroot on the ppc64 KVM instance at the same time.

And I assume it's the testsuite that kills both the KVM instance and the host
system.

-- 
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 v5 10/11] PCI: Replace pci_dev::driver usage by pci_dev::dev.driver

2021-09-30 Thread Frederic Barrat




On 29/09/2021 17:44, Andrew Donnellan wrote:
On 29/9/21 11:43 pm, Uwe Kleine-König wrote:> I'm not a huge fan either, 
I used it to keep the control flow as is and

without introducing several calls to to_pci_driver.

The whole code looks as follows:

list_for_each_entry(afu_dev, >phb->bus->devices, bus_list) {
    struct pci_driver *afu_drv;
    if (afu_dev->dev.driver &&
    (afu_drv = 
to_pci_driver(afu_dev->dev.driver))->err_handler &&

    afu_drv->err_handler->resume)
    afu_drv->err_handler->resume(afu_dev);
}

Without assignment in the if it could look as follows:

list_for_each_entry(afu_dev, >phb->bus->devices, bus_list) {
    struct pci_driver *afu_drv;

    if (!afu_dev->dev.driver)
    continue;

    afu_drv = to_pci_driver(afu_dev->dev.driver));

    if (afu_drv->err_handler && afu_drv->err_handler->resume)
    afu_drv->err_handler->resume(afu_dev);
}

Fine for me.


This looks fine.

As an aside while writing my email I discovered the existence of 
container_of_safe(), a version of container_of() that handles the null 
and err ptr cases... if to_pci_driver() used that, the null check in the 
caller could be moved until after the to_pci_driver() call which would 
be neater.


But then, grep tells me that container_of_safe() is used precisely zero 
times in the entire tree. Interesting.



(Sidenote: What happens if the device is unbound directly after the
check for afu_dev->dev.driver? This is a problem the old code had, too
(assuming it is a real problem, didn't check deeply).)


Looking at any of the cxl PCI error handling paths brings back 
nightmares from a few years ago... Fred: I wonder if we need to add a 
lock here?


Yes, it's indeed a potential issue, there's nothing to prevent the afu 
driver to unbind during that window. Sigh..


  Fred



Re: [PATCH] powerpc/pseries/msi: Add an empty irq_write_msi_msg() handler

2021-09-30 Thread Mahesh J Salgaonkar
On 2021-09-30 12:25:35 Thu, Cédric Le Goater wrote:
> The IPR drivers tests for MSI support at probe time with MSI vector 0
> and when done, frees the IRQ with free_irq(). This test was introduced
> by 95fecd90397e ("ipr: add test for MSI interrupt support") as an
> improvement of commit 5a9ef25b14d3 ("[SCSI] ipr: add MSI support")
> because a boot failure was reported on a Bimini PowerPC system :
> 
>   https://x-lore.kernel.org/all/1242926159.3007.5.camel@localhost.localdomain/
> 
> It was finally decided to remove MSI support on Bimini systems in
> 6eb0ac03899a ("powerpc/maple: Add a quirk to disable MSI for IPR on
> Bimini").
> 
> Linux 5.15-rc1 added MSI domain support to the pseries machine and
> when free_irq is called() in the driver, msi_domain_deactivate() also
> is. This resets the MSI table entry of the associate vector by calling
> __pci_write_msi_msg() with an empty message and breaks any further
> activation of the same vector. In the case of the IPR driver, it
> breaks the initialization sequence of the IOA.
> 
> Introduce an empty irq_write_msi_msg() handler in the MSI domain of
> the pseries machine to avoid clearing the MSI vector entry. Updating
> the entry is not strictly necessary since it is initialized by the
> underlying hypervisor, PowerVM or QEMU/KVM.
> 
> Cc: Wen Xiong 
> Cc: Douglas Miller 
> Cc: Brian King 
> Fixes: a5f3d2c17b07 ("powerpc/pseries/pci: Add MSI domains")
> Signed-off-by: Cédric Le Goater 

Tested-by: Mahesh Salgaonkar 

This fixes the issue reported at
https://lore.kernel.org/linuxppc-dev/65f0085f-c6a9-e3ea-4d60-fcf09b7c7...@linux.vnet.ibm.com/T/#u
by Abdul.

Thanks,
-- 
Mahesh J Salgaonkar


Re: [PATCH] powerpc/pseries/msi: Add an empty irq_write_msi_msg() handler

2021-09-30 Thread Cédric Le Goater

On 9/30/21 12:25, Cédric Le Goater wrote:

The IPR drivers tests for MSI support at probe time with MSI vector 0
and when done, frees the IRQ with free_irq(). This test was introduced
by 95fecd90397e ("ipr: add test for MSI interrupt support") as an
improvement of commit 5a9ef25b14d3 ("[SCSI] ipr: add MSI support")
because a boot failure was reported on a Bimini PowerPC system :

   https://x-lore.kernel.org/all/1242926159.3007.5.camel@localhost.localdomain/

It was finally decided to remove MSI support on Bimini systems in
6eb0ac03899a ("powerpc/maple: Add a quirk to disable MSI for IPR on
Bimini").

Linux 5.15-rc1 added MSI domain support to the pseries machine and
when free_irq is called() in the driver, msi_domain_deactivate() also
is. This resets the MSI table entry of the associate vector by calling
__pci_write_msi_msg() with an empty message and breaks any further
activation of the same vector. In the case of the IPR driver, it
breaks the initialization sequence of the IOA.

Introduce an empty irq_write_msi_msg() handler in the MSI domain of
the pseries machine to avoid clearing the MSI vector entry. Updating
the entry is not strictly necessary since it is initialized by the
underlying hypervisor, PowerVM or QEMU/KVM.

Cc: Wen Xiong 
Cc: Douglas Miller 
Cc: Brian King 
Fixes: a5f3d2c17b07 ("powerpc/pseries/pci: Add MSI domains")
Signed-off-by: Cédric Le Goater 


This is missing :

Reported-by: Abdul Haleem 

Thanks,

C.


---

  We could also revert commit 95fecd90397e ("ipr: add test for MSI
  interrupt support") which doesn't seem very useful nowdays. Or
  rewrite the test to improve how MSI vectors are used.

  Please advise !

  Thanks,


  arch/powerpc/platforms/pseries/msi.c | 15 +++
  1 file changed, 15 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/msi.c 
b/arch/powerpc/platforms/pseries/msi.c
index 1b305e411862..37eb35f5194d 100644
--- a/arch/powerpc/platforms/pseries/msi.c
+++ b/arch/powerpc/platforms/pseries/msi.c
@@ -507,12 +507,27 @@ static void pseries_msi_unmask(struct irq_data *d)
irq_chip_unmask_parent(d);
  }
  
+static void pseries_msi_write_msg(struct irq_data *data, struct msi_msg *msg)

+{
+   struct msi_desc *entry = irq_data_get_msi_desc(data);
+
+   /* Do not update the MSIx vector table. This is not strictly
+* necessary since the table is initialized by the underlying
+* hypervisor, PowerVM or QEMU/KVM. However, if the MSIx
+* vector entry is cleared, any further activation will fail.
+* This can happen in some drivers (IPR) which deactivate the
+* IRQ used for testing MSI support.
+*/
+   entry->msg = *msg;
+}
+
  static struct irq_chip pseries_pci_msi_irq_chip = {
.name   = "pSeries-PCI-MSI",
.irq_shutdown   = pseries_msi_shutdown,
.irq_mask   = pseries_msi_mask,
.irq_unmask = pseries_msi_unmask,
.irq_eoi= irq_chip_eoi_parent,
+   .irq_write_msi_msg  = pseries_msi_write_msg,
  };
  
  static struct msi_domain_info pseries_msi_domain_info = {






[V2 3/4] powerpc/perf: Expose instruction and data address registers as part of extended regs

2021-09-30 Thread Athira Rajeev
Patch adds support to include Sampled Instruction Address Register
(SIAR) and Sampled Data Address Register (SDAR) SPRs as part of extended
registers. Update the definition of PERF_REG_PMU_MASK_300/31 and
PERF_REG_EXTENDED_MAX to include these SPR's.

Signed-off-by: Athira Rajeev 
---
 arch/powerpc/include/uapi/asm/perf_regs.h | 11 +++
 arch/powerpc/perf/perf_regs.c |  4 
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/uapi/asm/perf_regs.h 
b/arch/powerpc/include/uapi/asm/perf_regs.h
index fb1d8a9b4393..e2917710fdab 100644
--- a/arch/powerpc/include/uapi/asm/perf_regs.h
+++ b/arch/powerpc/include/uapi/asm/perf_regs.h
@@ -61,17 +61,19 @@ enum perf_event_powerpc_regs {
PERF_REG_POWERPC_PMC4,
PERF_REG_POWERPC_PMC5,
PERF_REG_POWERPC_PMC6,
+   PERF_REG_POWERPC_SDAR,
+   PERF_REG_POWERPC_SIAR,
/* Max mask value for interrupt regs w/o extended regs */
PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
/* Max mask value for interrupt regs including extended regs */
-   PERF_REG_EXTENDED_MAX = PERF_REG_POWERPC_PMC6 + 1,
+   PERF_REG_EXTENDED_MAX = PERF_REG_POWERPC_SIAR + 1,
 };
 
 #define PERF_REG_PMU_MASK  ((1ULL << PERF_REG_POWERPC_MAX) - 1)
 
 /*
  * PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300
- * includes 9 SPRS from MMCR0 to PMC6 excluding the
+ * includes 11 SPRS from MMCR0 to SIAR excluding the
  * unsupported SPRS MMCR3, SIER2 and SIER3.
  */
 #define PERF_REG_PMU_MASK_300  \
@@ -79,11 +81,12 @@ enum perf_event_powerpc_regs {
(1ul << PERF_REG_POWERPC_MMCR2) | (1ul << PERF_REG_POWERPC_PMC1) | \
(1ul << PERF_REG_POWERPC_PMC2) | (1ul << PERF_REG_POWERPC_PMC3) | \
(1ul << PERF_REG_POWERPC_PMC4) | (1ul << PERF_REG_POWERPC_PMC5) | \
-   (1ul << PERF_REG_POWERPC_PMC6))
+   (1ul << PERF_REG_POWERPC_PMC6) | (1ul << PERF_REG_POWERPC_SDAR) | \
+   (1ul << PERF_REG_POWERPC_SIAR))
 
 /*
  * PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31
- * includes 12 SPRs from MMCR0 to PMC6.
+ * includes 14 SPRs from MMCR0 to SIAR.
  */
 #define PERF_REG_PMU_MASK_31   \
(PERF_REG_PMU_MASK_300 | (1ul << PERF_REG_POWERPC_MMCR3) | \
diff --git a/arch/powerpc/perf/perf_regs.c b/arch/powerpc/perf/perf_regs.c
index b931eed482c9..51d31b65e423 100644
--- a/arch/powerpc/perf/perf_regs.c
+++ b/arch/powerpc/perf/perf_regs.c
@@ -90,7 +90,11 @@ static u64 get_ext_regs_value(int idx)
return mfspr(SPRN_SIER2);
case PERF_REG_POWERPC_SIER3:
return mfspr(SPRN_SIER3);
+   case PERF_REG_POWERPC_SDAR:
+   return mfspr(SPRN_SDAR);
 #endif
+   case PERF_REG_POWERPC_SIAR:
+   return mfspr(SPRN_SIAR);
default: return 0;
}
 }
-- 
2.30.1 (Apple Git-130)



[V2 2/4] tools/perf: Refactor the code definition of perf reg extended mask in tools side header file

2021-09-30 Thread Athira Rajeev
PERF_REG_PMU_MASK_300 and PERF_REG_PMU_MASK_31 defines the mask
value for extended registers. Current definition of these mask values
uses hex constant and does not use registers by name, making it less
readable. Patch refactor the macro values in perf tools side header file
by or'ing together the actual register value constants.

Suggested-by: Michael Ellerman 
Signed-off-by: Athira Rajeev 
---
 .../arch/powerpc/include/uapi/asm/perf_regs.h | 21 ---
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/tools/arch/powerpc/include/uapi/asm/perf_regs.h 
b/tools/arch/powerpc/include/uapi/asm/perf_regs.h
index 578b3ee86105..fb1d8a9b4393 100644
--- a/tools/arch/powerpc/include/uapi/asm/perf_regs.h
+++ b/tools/arch/powerpc/include/uapi/asm/perf_regs.h
@@ -61,27 +61,32 @@ enum perf_event_powerpc_regs {
PERF_REG_POWERPC_PMC4,
PERF_REG_POWERPC_PMC5,
PERF_REG_POWERPC_PMC6,
-   /* Max regs without the extended regs */
+   /* Max mask value for interrupt regs w/o extended regs */
PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
+   /* Max mask value for interrupt regs including extended regs */
+   PERF_REG_EXTENDED_MAX = PERF_REG_POWERPC_PMC6 + 1,
 };
 
 #define PERF_REG_PMU_MASK  ((1ULL << PERF_REG_POWERPC_MAX) - 1)
 
-/* Exclude MMCR3, SIER2, SIER3 for CPU_FTR_ARCH_300 */
-#definePERF_EXCLUDE_REG_EXT_300(7ULL << PERF_REG_POWERPC_MMCR3)
-
 /*
  * PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300
  * includes 9 SPRS from MMCR0 to PMC6 excluding the
- * unsupported SPRS in PERF_EXCLUDE_REG_EXT_300.
+ * unsupported SPRS MMCR3, SIER2 and SIER3.
  */
-#define PERF_REG_PMU_MASK_300   ((0xfffULL << PERF_REG_POWERPC_MMCR0) - 
PERF_EXCLUDE_REG_EXT_300)
+#define PERF_REG_PMU_MASK_300  \
+   ((1ul << PERF_REG_POWERPC_MMCR0) | (1ul << PERF_REG_POWERPC_MMCR1) | \
+   (1ul << PERF_REG_POWERPC_MMCR2) | (1ul << PERF_REG_POWERPC_PMC1) | \
+   (1ul << PERF_REG_POWERPC_PMC2) | (1ul << PERF_REG_POWERPC_PMC3) | \
+   (1ul << PERF_REG_POWERPC_PMC4) | (1ul << PERF_REG_POWERPC_PMC5) | \
+   (1ul << PERF_REG_POWERPC_PMC6))
 
 /*
  * PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31
  * includes 12 SPRs from MMCR0 to PMC6.
  */
-#define PERF_REG_PMU_MASK_31   (0xfffULL << PERF_REG_POWERPC_MMCR0)
+#define PERF_REG_PMU_MASK_31   \
+   (PERF_REG_PMU_MASK_300 | (1ul << PERF_REG_POWERPC_MMCR3) | \
+   (1ul << PERF_REG_POWERPC_SIER2) | (1ul << PERF_REG_POWERPC_SIER3))
 
-#define PERF_REG_EXTENDED_MAX  (PERF_REG_POWERPC_PMC6 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
-- 
2.30.1 (Apple Git-130)



[V2 4/4] tools/perf: Add perf tools support to expose instruction and data address registers as part of extended regs

2021-09-30 Thread Athira Rajeev
Patch enables presenting of Sampled Instruction Address Register (SIAR)
and Sampled Data Address Register (SDAR) SPRs as part of extended regsiters
for perf tool. Add these SPR's to sample_reg_mask in the tool side (to use
with -I? option).

Signed-off-by: Athira Rajeev 
---
 tools/arch/powerpc/include/uapi/asm/perf_regs.h | 11 +++
 tools/perf/arch/powerpc/include/perf_regs.h |  2 ++
 tools/perf/arch/powerpc/util/perf_regs.c|  2 ++
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/arch/powerpc/include/uapi/asm/perf_regs.h 
b/tools/arch/powerpc/include/uapi/asm/perf_regs.h
index fb1d8a9b4393..e2917710fdab 100644
--- a/tools/arch/powerpc/include/uapi/asm/perf_regs.h
+++ b/tools/arch/powerpc/include/uapi/asm/perf_regs.h
@@ -61,17 +61,19 @@ enum perf_event_powerpc_regs {
PERF_REG_POWERPC_PMC4,
PERF_REG_POWERPC_PMC5,
PERF_REG_POWERPC_PMC6,
+   PERF_REG_POWERPC_SDAR,
+   PERF_REG_POWERPC_SIAR,
/* Max mask value for interrupt regs w/o extended regs */
PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
/* Max mask value for interrupt regs including extended regs */
-   PERF_REG_EXTENDED_MAX = PERF_REG_POWERPC_PMC6 + 1,
+   PERF_REG_EXTENDED_MAX = PERF_REG_POWERPC_SIAR + 1,
 };
 
 #define PERF_REG_PMU_MASK  ((1ULL << PERF_REG_POWERPC_MAX) - 1)
 
 /*
  * PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300
- * includes 9 SPRS from MMCR0 to PMC6 excluding the
+ * includes 11 SPRS from MMCR0 to SIAR excluding the
  * unsupported SPRS MMCR3, SIER2 and SIER3.
  */
 #define PERF_REG_PMU_MASK_300  \
@@ -79,11 +81,12 @@ enum perf_event_powerpc_regs {
(1ul << PERF_REG_POWERPC_MMCR2) | (1ul << PERF_REG_POWERPC_PMC1) | \
(1ul << PERF_REG_POWERPC_PMC2) | (1ul << PERF_REG_POWERPC_PMC3) | \
(1ul << PERF_REG_POWERPC_PMC4) | (1ul << PERF_REG_POWERPC_PMC5) | \
-   (1ul << PERF_REG_POWERPC_PMC6))
+   (1ul << PERF_REG_POWERPC_PMC6) | (1ul << PERF_REG_POWERPC_SDAR) | \
+   (1ul << PERF_REG_POWERPC_SIAR))
 
 /*
  * PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31
- * includes 12 SPRs from MMCR0 to PMC6.
+ * includes 14 SPRs from MMCR0 to SIAR.
  */
 #define PERF_REG_PMU_MASK_31   \
(PERF_REG_PMU_MASK_300 | (1ul << PERF_REG_POWERPC_MMCR3) | \
diff --git a/tools/perf/arch/powerpc/include/perf_regs.h 
b/tools/perf/arch/powerpc/include/perf_regs.h
index 04e5dc07e93f..93339d17acc4 100644
--- a/tools/perf/arch/powerpc/include/perf_regs.h
+++ b/tools/perf/arch/powerpc/include/perf_regs.h
@@ -77,6 +77,8 @@ static const char *reg_names[] = {
[PERF_REG_POWERPC_PMC4] = "pmc4",
[PERF_REG_POWERPC_PMC5] = "pmc5",
[PERF_REG_POWERPC_PMC6] = "pmc6",
+   [PERF_REG_POWERPC_SDAR] = "sdar",
+   [PERF_REG_POWERPC_SIAR] = "siar",
 };
 
 static inline const char *__perf_reg_name(int id)
diff --git a/tools/perf/arch/powerpc/util/perf_regs.c 
b/tools/perf/arch/powerpc/util/perf_regs.c
index 8116a253f91f..8d07a78e742a 100644
--- a/tools/perf/arch/powerpc/util/perf_regs.c
+++ b/tools/perf/arch/powerpc/util/perf_regs.c
@@ -74,6 +74,8 @@ const struct sample_reg sample_reg_masks[] = {
SMPL_REG(pmc4, PERF_REG_POWERPC_PMC4),
SMPL_REG(pmc5, PERF_REG_POWERPC_PMC5),
SMPL_REG(pmc6, PERF_REG_POWERPC_PMC6),
+   SMPL_REG(sdar, PERF_REG_POWERPC_SDAR),
+   SMPL_REG(siar, PERF_REG_POWERPC_SIAR),
SMPL_REG_END
 };
 
-- 
2.30.1 (Apple Git-130)



[V2 0/4] powerpc/perf: Add instruction and data address registers to extended regs

2021-09-30 Thread Athira Rajeev
Patch set adds PMU registers namely Sampled Instruction Address Register
(SIAR) and Sampled Data Address Register (SDAR) as part of extended regs
in PowerPC. These registers provides the instruction/data address and
adding these to extended regs helps in debug purposes.

Patch 1/4 and 2/4 refactors the existing macro definition of
PERF_REG_PMU_MASK_300 and PERF_REG_PMU_MASK_31 to make it more
readable.
Patch 3/4 adds SIAR and SDAR as part of the extended regs mask.
Patch 4/4 includes perf tools side changes to add the SPRs to
sample_reg_mask to use with -I? option.

Changelog:
Change from v1 -> v2:
Addressed review comments from Michael Ellerman
- Refactored the perf reg extended mask value macros for
  PERF_REG_PMU_MASK_300 and PERF_REG_PMU_MASK_31 to
  make it more readable. Also moved PERF_REG_EXTENDED_MAX
  along with enum definition similar to PERF_REG_POWERPC_MAX.

Athira Rajeev (4):
  powerpc/perf: Refactor the code definition of perf reg extended mask
  tools/perf: Refactor the code definition of perf reg extended mask in
tools side header file
  powerpc/perf: Expose instruction and data address registers as part of
extended regs
  tools/perf: Add perf tools support to expose instruction and data
address registers as part of extended regs

 arch/powerpc/include/uapi/asm/perf_regs.h | 28 ---
 arch/powerpc/perf/perf_regs.c |  4 +++
 .../arch/powerpc/include/uapi/asm/perf_regs.h | 28 ---
 tools/perf/arch/powerpc/include/perf_regs.h   |  2 ++
 tools/perf/arch/powerpc/util/perf_regs.c  |  2 ++
 5 files changed, 44 insertions(+), 20 deletions(-)

-- 
2.30.1 (Apple Git-130)



[V2 1/4] powerpc/perf: Refactor the code definition of perf reg extended mask

2021-09-30 Thread Athira Rajeev
PERF_REG_PMU_MASK_300 and PERF_REG_PMU_MASK_31 defines the mask
value for extended registers. Current definition of these mask values
uses hex constant and does not use registers by name, making it less
readable. Patch refactor the macro values by or'ing together the actual
register value constants. Also include PERF_REG_EXTENDED_MAX as
part of enum definition.

Suggested-by: Michael Ellerman 
Signed-off-by: Athira Rajeev 
---
 arch/powerpc/include/uapi/asm/perf_regs.h | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/include/uapi/asm/perf_regs.h 
b/arch/powerpc/include/uapi/asm/perf_regs.h
index 578b3ee86105..fb1d8a9b4393 100644
--- a/arch/powerpc/include/uapi/asm/perf_regs.h
+++ b/arch/powerpc/include/uapi/asm/perf_regs.h
@@ -61,27 +61,32 @@ enum perf_event_powerpc_regs {
PERF_REG_POWERPC_PMC4,
PERF_REG_POWERPC_PMC5,
PERF_REG_POWERPC_PMC6,
-   /* Max regs without the extended regs */
+   /* Max mask value for interrupt regs w/o extended regs */
PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
+   /* Max mask value for interrupt regs including extended regs */
+   PERF_REG_EXTENDED_MAX = PERF_REG_POWERPC_PMC6 + 1,
 };
 
 #define PERF_REG_PMU_MASK  ((1ULL << PERF_REG_POWERPC_MAX) - 1)
 
-/* Exclude MMCR3, SIER2, SIER3 for CPU_FTR_ARCH_300 */
-#definePERF_EXCLUDE_REG_EXT_300(7ULL << PERF_REG_POWERPC_MMCR3)
-
 /*
  * PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300
  * includes 9 SPRS from MMCR0 to PMC6 excluding the
- * unsupported SPRS in PERF_EXCLUDE_REG_EXT_300.
+ * unsupported SPRS MMCR3, SIER2 and SIER3.
  */
-#define PERF_REG_PMU_MASK_300   ((0xfffULL << PERF_REG_POWERPC_MMCR0) - 
PERF_EXCLUDE_REG_EXT_300)
+#define PERF_REG_PMU_MASK_300  \
+   ((1ul << PERF_REG_POWERPC_MMCR0) | (1ul << PERF_REG_POWERPC_MMCR1) | \
+   (1ul << PERF_REG_POWERPC_MMCR2) | (1ul << PERF_REG_POWERPC_PMC1) | \
+   (1ul << PERF_REG_POWERPC_PMC2) | (1ul << PERF_REG_POWERPC_PMC3) | \
+   (1ul << PERF_REG_POWERPC_PMC4) | (1ul << PERF_REG_POWERPC_PMC5) | \
+   (1ul << PERF_REG_POWERPC_PMC6))
 
 /*
  * PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31
  * includes 12 SPRs from MMCR0 to PMC6.
  */
-#define PERF_REG_PMU_MASK_31   (0xfffULL << PERF_REG_POWERPC_MMCR0)
+#define PERF_REG_PMU_MASK_31   \
+   (PERF_REG_PMU_MASK_300 | (1ul << PERF_REG_POWERPC_MMCR3) | \
+   (1ul << PERF_REG_POWERPC_SIER2) | (1ul << PERF_REG_POWERPC_SIER3))
 
-#define PERF_REG_EXTENDED_MAX  (PERF_REG_POWERPC_PMC6 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
-- 
2.30.1 (Apple Git-130)



[PATCH v3 4/4] s390: Use generic version of arch_is_kernel_initmem_freed()

2021-09-30 Thread Christophe Leroy
Generic version of arch_is_kernel_initmem_freed() now does the same
as s390 version.

Remove the s390 version.

Cc: Gerald Schaefer 
Cc: Kefeng Wang 
Acked-by: Heiko Carstens 
Signed-off-by: Christophe Leroy 
---
v3: No change
v2: No change
---
 arch/s390/include/asm/sections.h | 12 
 arch/s390/mm/init.c  |  3 ---
 2 files changed, 15 deletions(-)

diff --git a/arch/s390/include/asm/sections.h b/arch/s390/include/asm/sections.h
index 85881dd48022..3fecaa4e8b74 100644
--- a/arch/s390/include/asm/sections.h
+++ b/arch/s390/include/asm/sections.h
@@ -2,20 +2,8 @@
 #ifndef _S390_SECTIONS_H
 #define _S390_SECTIONS_H
 
-#define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed
-
 #include 
 
-extern bool initmem_freed;
-
-static inline int arch_is_kernel_initmem_freed(unsigned long addr)
-{
-   if (!initmem_freed)
-   return 0;
-   return addr >= (unsigned long)__init_begin &&
-  addr < (unsigned long)__init_end;
-}
-
 /*
  * .boot.data section contains variables "shared" between the decompressor and
  * the decompressed kernel. The decompressor will store values in them, and
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index a04faf49001a..8c6f258a6183 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -58,8 +58,6 @@ unsigned long empty_zero_page, zero_page_mask;
 EXPORT_SYMBOL(empty_zero_page);
 EXPORT_SYMBOL(zero_page_mask);
 
-bool initmem_freed;
-
 static void __init setup_zero_pages(void)
 {
unsigned int order;
@@ -214,7 +212,6 @@ void __init mem_init(void)
 
 void free_initmem(void)
 {
-   initmem_freed = true;
__set_memory((unsigned long)_sinittext,
 (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT,
 SET_MEMORY_RW | SET_MEMORY_NX);
-- 
2.31.1



[PATCH v3 2/4] mm: Make generic arch_is_kernel_initmem_freed() do what it says

2021-09-30 Thread Christophe Leroy
Commit 7a5da02de8d6 ("locking/lockdep: check for freed initmem in
static_obj()") added arch_is_kernel_initmem_freed() which is supposed
to report whether an object is part of already freed init memory.

For the time being, the generic version of arch_is_kernel_initmem_freed()
always reports 'false', allthough free_initmem() is generically called
on all architectures.

Therefore, change the generic version of arch_is_kernel_initmem_freed()
to check whether free_initmem() has been called. If so, then check
if a given address falls into init memory.

To ease the use of system_state, move it out of line into its only
caller which is lockdep.c

Cc: Gerald Schaefer 
Cc: Kefeng Wang 
Signed-off-by: Christophe Leroy 
---
v3: Move it out of sections.h into lockdep.c and fix the comment.

v2: Change to using the new SYSTEM_FREEING_INITMEM state
Signed-off-by: Christophe Leroy 
---
 include/asm-generic/sections.h | 14 --
 kernel/locking/lockdep.c   | 15 +++
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index d16302d3eb59..596ab2092289 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -80,20 +80,6 @@ static inline int arch_is_kernel_data(unsigned long addr)
 }
 #endif
 
-/*
- * Check if an address is part of freed initmem. This is needed on 
architectures
- * with virt == phys kernel mapping, for code that wants to check if an address
- * is part of a static object within [_stext, _end]. After initmem is freed,
- * memory can be allocated from it, and such allocations would then have
- * addresses within the range [_stext, _end].
- */
-#ifndef arch_is_kernel_initmem_freed
-static inline int arch_is_kernel_initmem_freed(unsigned long addr)
-{
-   return 0;
-}
-#endif
-
 /**
  * memory_contains - checks if an object is contained within a memory region
  * @begin: virtual address of the beginning of the memory region
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index bf1c00c881e4..8e118caf835e 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -788,6 +788,21 @@ static int very_verbose(struct lock_class *class)
  * Is this the address of a static object:
  */
 #ifdef __KERNEL__
+/*
+ * Check if an address is part of freed initmem. After initmem is freed,
+ * memory can be allocated from it, and such allocations would then have
+ * addresses within the range [_stext, _end].
+ */
+#ifndef arch_is_kernel_initmem_freed
+static int arch_is_kernel_initmem_freed(unsigned long addr)
+{
+   if (system_state < SYSTEM_FREEING_INITMEM)
+   return 0;
+
+   return init_section_contains((void *)addr, 1);
+}
+#endif
+
 static int static_obj(const void *obj)
 {
unsigned long start = (unsigned long) &_stext,
-- 
2.31.1



[PATCH v3 1/4] mm: Create a new system state and fix core_kernel_text()

2021-09-30 Thread Christophe Leroy
core_kernel_text() considers that until system_state in at least
SYSTEM_RUNNING, init memory is valid.

But init memory is freed a few lines before setting SYSTEM_RUNNING,
so we have a small period of time when core_kernel_text() is wrong.

Create an intermediate system state called SYSTEM_FREEING_INIT that
is set before starting freeing init memory, and use it in
core_kernel_text() to report init memory invalid earlier.

Cc: Gerald Schaefer 
Cc: Kefeng Wang 
Signed-off-by: Christophe Leroy 
---
v3: No change
v2: New
---
 include/linux/kernel.h | 1 +
 init/main.c| 2 ++
 kernel/extable.c   | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 2776423a587e..471bc0593679 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -248,6 +248,7 @@ extern bool early_boot_irqs_disabled;
 extern enum system_states {
SYSTEM_BOOTING,
SYSTEM_SCHEDULING,
+   SYSTEM_FREEING_INITMEM,
SYSTEM_RUNNING,
SYSTEM_HALT,
SYSTEM_POWER_OFF,
diff --git a/init/main.c b/init/main.c
index 3f7216934441..c457d393fdd4 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1505,6 +1505,8 @@ static int __ref kernel_init(void *unused)
kernel_init_freeable();
/* need to finish all async __init code before freeing the memory */
async_synchronize_full();
+
+   system_state = SYSTEM_FREEING_INITMEM;
kprobe_free_init_mem();
ftrace_free_init_mem();
kgdb_free_init_mem();
diff --git a/kernel/extable.c b/kernel/extable.c
index b0ea5eb0c3b4..290661f68e6b 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -76,7 +76,7 @@ int notrace core_kernel_text(unsigned long addr)
addr < (unsigned long)_etext)
return 1;
 
-   if (system_state < SYSTEM_RUNNING &&
+   if (system_state < SYSTEM_FREEING_INITMEM &&
init_kernel_text(addr))
return 1;
return 0;
-- 
2.31.1



[PATCH v3 3/4] powerpc: Use generic version of arch_is_kernel_initmem_freed()

2021-09-30 Thread Christophe Leroy
Generic version of arch_is_kernel_initmem_freed() now does the same
as powerpc version.

Remove the powerpc version.

Cc: Kefeng Wang 
Signed-off-by: Christophe Leroy 
---
v3: No change
v2: No change
---
 arch/powerpc/include/asm/sections.h | 13 -
 1 file changed, 13 deletions(-)

diff --git a/arch/powerpc/include/asm/sections.h 
b/arch/powerpc/include/asm/sections.h
index 6e4af4492a14..79cb7a25a5fb 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -6,21 +6,8 @@
 #include 
 #include 
 
-#define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed
-
 #include 
 
-extern bool init_mem_is_free;
-
-static inline int arch_is_kernel_initmem_freed(unsigned long addr)
-{
-   if (!init_mem_is_free)
-   return 0;
-
-   return addr >= (unsigned long)__init_begin &&
-   addr < (unsigned long)__init_end;
-}
-
 extern char __head_end[];
 
 #ifdef __powerpc64__
-- 
2.31.1



[PATCH] powerpc/pseries/msi: Add an empty irq_write_msi_msg() handler

2021-09-30 Thread Cédric Le Goater
The IPR drivers tests for MSI support at probe time with MSI vector 0
and when done, frees the IRQ with free_irq(). This test was introduced
by 95fecd90397e ("ipr: add test for MSI interrupt support") as an
improvement of commit 5a9ef25b14d3 ("[SCSI] ipr: add MSI support")
because a boot failure was reported on a Bimini PowerPC system :

  https://x-lore.kernel.org/all/1242926159.3007.5.camel@localhost.localdomain/

It was finally decided to remove MSI support on Bimini systems in
6eb0ac03899a ("powerpc/maple: Add a quirk to disable MSI for IPR on
Bimini").

Linux 5.15-rc1 added MSI domain support to the pseries machine and
when free_irq is called() in the driver, msi_domain_deactivate() also
is. This resets the MSI table entry of the associate vector by calling
__pci_write_msi_msg() with an empty message and breaks any further
activation of the same vector. In the case of the IPR driver, it
breaks the initialization sequence of the IOA.

Introduce an empty irq_write_msi_msg() handler in the MSI domain of
the pseries machine to avoid clearing the MSI vector entry. Updating
the entry is not strictly necessary since it is initialized by the
underlying hypervisor, PowerVM or QEMU/KVM.

Cc: Wen Xiong 
Cc: Douglas Miller 
Cc: Brian King 
Fixes: a5f3d2c17b07 ("powerpc/pseries/pci: Add MSI domains")
Signed-off-by: Cédric Le Goater 
---

 We could also revert commit 95fecd90397e ("ipr: add test for MSI
 interrupt support") which doesn't seem very useful nowdays. Or
 rewrite the test to improve how MSI vectors are used.

 Please advise !

 Thanks,


 arch/powerpc/platforms/pseries/msi.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/msi.c 
b/arch/powerpc/platforms/pseries/msi.c
index 1b305e411862..37eb35f5194d 100644
--- a/arch/powerpc/platforms/pseries/msi.c
+++ b/arch/powerpc/platforms/pseries/msi.c
@@ -507,12 +507,27 @@ static void pseries_msi_unmask(struct irq_data *d)
irq_chip_unmask_parent(d);
 }
 
+static void pseries_msi_write_msg(struct irq_data *data, struct msi_msg *msg)
+{
+   struct msi_desc *entry = irq_data_get_msi_desc(data);
+
+   /* Do not update the MSIx vector table. This is not strictly
+* necessary since the table is initialized by the underlying
+* hypervisor, PowerVM or QEMU/KVM. However, if the MSIx
+* vector entry is cleared, any further activation will fail.
+* This can happen in some drivers (IPR) which deactivate the
+* IRQ used for testing MSI support.
+*/
+   entry->msg = *msg;
+}
+
 static struct irq_chip pseries_pci_msi_irq_chip = {
.name   = "pSeries-PCI-MSI",
.irq_shutdown   = pseries_msi_shutdown,
.irq_mask   = pseries_msi_mask,
.irq_unmask = pseries_msi_unmask,
.irq_eoi= irq_chip_eoi_parent,
+   .irq_write_msi_msg  = pseries_msi_write_msg,
 };
 
 static struct msi_domain_info pseries_msi_domain_info = {
-- 
2.31.1



Re: [PATCH v4 10/11] microblaze: Use is_kernel_text() helper

2021-09-30 Thread Michal Simek



On 9/30/21 9:11 AM, Kefeng Wang wrote:
> Use is_kernel_text() helper to simplify code.
> 
> Cc: Michal Simek 
> Signed-off-by: Kefeng Wang 
> ---
>  arch/microblaze/mm/pgtable.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c
> index c1833b159d3b..9f73265aad4e 100644
> --- a/arch/microblaze/mm/pgtable.c
> +++ b/arch/microblaze/mm/pgtable.c
> @@ -34,6 +34,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include 
>  #include 
> @@ -171,7 +172,7 @@ void __init mapin_ram(void)
>   for (s = 0; s < lowmem_size; s += PAGE_SIZE) {
>   f = _PAGE_PRESENT | _PAGE_ACCESSED |
>   _PAGE_SHARED | _PAGE_HWEXEC;
> - if ((char *) v < _stext || (char *) v >= _etext)
> + if (!is_kernel_text(v))
>   f |= _PAGE_WRENABLE;
>   else
>   /* On the MicroBlaze, no user access
> 

Acked-by: Michal Simek 

Thanks,
Michal

-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs



[PATCH v4 04/11] sections: Move is_kernel_inittext() into sections.h

2021-09-30 Thread Kefeng Wang
The is_kernel_inittext() and init_kernel_text() are with same
functionality, let's just keep is_kernel_inittext() and move
it into sections.h, then update all the callers.

Cc: Ingo Molnar 
Cc: Thomas Gleixner 
Cc: Arnd Bergmann 
Cc: x...@kernel.org
Signed-off-by: Kefeng Wang 
---
 arch/x86/kernel/unwind_orc.c   |  2 +-
 include/asm-generic/sections.h | 14 ++
 include/linux/kallsyms.h   |  8 
 include/linux/kernel.h |  1 -
 kernel/extable.c   | 12 ++--
 5 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
index a1202536fc57..d92ec2ced059 100644
--- a/arch/x86/kernel/unwind_orc.c
+++ b/arch/x86/kernel/unwind_orc.c
@@ -175,7 +175,7 @@ static struct orc_entry *orc_find(unsigned long ip)
}
 
/* vmlinux .init slow lookup: */
-   if (init_kernel_text(ip))
+   if (is_kernel_inittext(ip))
return __orc_find(__start_orc_unwind_ip, __start_orc_unwind,
  __stop_orc_unwind_ip - __start_orc_unwind_ip, 
ip);
 
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 24780c0f40b1..811583ca8bd0 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -172,4 +172,18 @@ static inline bool is_kernel_rodata(unsigned long addr)
   addr < (unsigned long)__end_rodata;
 }
 
+/**
+ * is_kernel_inittext - checks if the pointer address is located in the
+ *  .init.text section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .init.text, false otherwise.
+ */
+static inline bool is_kernel_inittext(unsigned long addr)
+{
+   return addr >= (unsigned long)_sinittext &&
+  addr < (unsigned long)_einittext;
+}
+
 #endif /* _ASM_GENERIC_SECTIONS_H_ */
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index b016c62f30a6..8a9d329c927c 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -24,14 +24,6 @@
 struct cred;
 struct module;
 
-static inline int is_kernel_inittext(unsigned long addr)
-{
-   if (addr >= (unsigned long)_sinittext
-   && addr < (unsigned long)_einittext)
-   return 1;
-   return 0;
-}
-
 static inline int is_kernel_text(unsigned long addr)
 {
if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e5a9af8a4e20..445d0dceefb8 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -229,7 +229,6 @@ extern bool parse_option_str(const char *str, const char 
*option);
 extern char *next_arg(char *args, char **param, char **val);
 
 extern int core_kernel_text(unsigned long addr);
-extern int init_kernel_text(unsigned long addr);
 extern int __kernel_text_address(unsigned long addr);
 extern int kernel_text_address(unsigned long addr);
 extern int func_ptr_is_kernel_text(void *ptr);
diff --git a/kernel/extable.c b/kernel/extable.c
index da26203841d4..98ca627ac5ef 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -62,14 +62,6 @@ const struct exception_table_entry 
*search_exception_tables(unsigned long addr)
return e;
 }
 
-int init_kernel_text(unsigned long addr)
-{
-   if (addr >= (unsigned long)_sinittext &&
-   addr < (unsigned long)_einittext)
-   return 1;
-   return 0;
-}
-
 int notrace core_kernel_text(unsigned long addr)
 {
if (addr >= (unsigned long)_stext &&
@@ -77,7 +69,7 @@ int notrace core_kernel_text(unsigned long addr)
return 1;
 
if (system_state < SYSTEM_RUNNING &&
-   init_kernel_text(addr))
+   is_kernel_inittext(addr))
return 1;
return 0;
 }
@@ -94,7 +86,7 @@ int __kernel_text_address(unsigned long addr)
 * Since we are after the module-symbols check, there's
 * no danger of address overlap:
 */
-   if (init_kernel_text(addr))
+   if (is_kernel_inittext(addr))
return 1;
return 0;
 }
-- 
2.26.2



[PATCH v4 10/11] microblaze: Use is_kernel_text() helper

2021-09-30 Thread Kefeng Wang
Use is_kernel_text() helper to simplify code.

Cc: Michal Simek 
Signed-off-by: Kefeng Wang 
---
 arch/microblaze/mm/pgtable.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c
index c1833b159d3b..9f73265aad4e 100644
--- a/arch/microblaze/mm/pgtable.c
+++ b/arch/microblaze/mm/pgtable.c
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -171,7 +172,7 @@ void __init mapin_ram(void)
for (s = 0; s < lowmem_size; s += PAGE_SIZE) {
f = _PAGE_PRESENT | _PAGE_ACCESSED |
_PAGE_SHARED | _PAGE_HWEXEC;
-   if ((char *) v < _stext || (char *) v >= _etext)
+   if (!is_kernel_text(v))
f |= _PAGE_WRENABLE;
else
/* On the MicroBlaze, no user access
-- 
2.26.2



[PATCH v4 07/11] mm: kasan: Use is_kernel() helper

2021-09-30 Thread Kefeng Wang
Directly use is_kernel() helper in kernel_or_module_addr().

Cc: Andrey Ryabinin 
Cc: Alexander Potapenko 
Cc: Andrey Konovalov 
Cc: Dmitry Vyukov 
Signed-off-by: Kefeng Wang 
---
 mm/kasan/report.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 3239fd8f8747..1c955e1c98d5 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -226,7 +226,7 @@ static void describe_object(struct kmem_cache *cache, void 
*object,
 
 static inline bool kernel_or_module_addr(const void *addr)
 {
-   if (addr >= (void *)_stext && addr < (void *)_end)
+   if (is_kernel((unsigned long)addr))
return true;
if (is_module_address((unsigned long)addr))
return true;
-- 
2.26.2



[PATCH v4 01/11] kallsyms: Remove arch specific text and data check

2021-09-30 Thread Kefeng Wang
After commit 4ba66a976072 ("arch: remove blackfin port"),
no need arch-specific text/data check.

Cc: Arnd Bergmann 
Signed-off-by: Kefeng Wang 
---
 include/asm-generic/sections.h | 16 
 include/linux/kallsyms.h   |  3 +--
 kernel/locking/lockdep.c   |  3 ---
 3 files changed, 1 insertion(+), 21 deletions(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index d16302d3eb59..817309e289db 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -64,22 +64,6 @@ extern __visible const void __nosave_begin, __nosave_end;
 #define dereference_kernel_function_descriptor(p) ((void *)(p))
 #endif
 
-/* random extra sections (if any).  Override
- * in asm/sections.h */
-#ifndef arch_is_kernel_text
-static inline int arch_is_kernel_text(unsigned long addr)
-{
-   return 0;
-}
-#endif
-
-#ifndef arch_is_kernel_data
-static inline int arch_is_kernel_data(unsigned long addr)
-{
-   return 0;
-}
-#endif
-
 /*
  * Check if an address is part of freed initmem. This is needed on 
architectures
  * with virt == phys kernel mapping, for code that wants to check if an address
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 6851c2313cad..2a241e3f063f 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -34,8 +34,7 @@ static inline int is_kernel_inittext(unsigned long addr)
 
 static inline int is_kernel_text(unsigned long addr)
 {
-   if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
-   arch_is_kernel_text(addr))
+   if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext))
return 1;
return in_gate_area_no_mm(addr);
 }
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 7096384dc60f..dcdbcee391cd 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -803,9 +803,6 @@ static int static_obj(const void *obj)
if ((addr >= start) && (addr < end))
return 1;
 
-   if (arch_is_kernel_data(addr))
-   return 1;
-
/*
 * in-kernel percpu var?
 */
-- 
2.26.2



[PATCH v4 05/11] x86: mm: Rename __is_kernel_text() to is_x86_32_kernel_text()

2021-09-30 Thread Kefeng Wang
Commit b56cd05c55a1 ("x86/mm: Rename is_kernel_text to __is_kernel_text"),
add '__' prefix not to get in conflict with existing is_kernel_text() in
.

We will add __is_kernel_text() for the basic kernel text range check in the
next patch, so use private is_x86_32_kernel_text() naming for x86 special
check.

Cc: Ingo Molnar 
Cc: Borislav Petkov 
Cc: x...@kernel.org
Signed-off-by: Kefeng Wang 
---
 arch/x86/mm/init_32.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index bd90b8fe81e4..523743ee9dea 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -238,11 +238,7 @@ page_table_range_init(unsigned long start, unsigned long 
end, pgd_t *pgd_base)
}
 }
 
-/*
- * The  already defines is_kernel_text,
- * using '__' prefix not to get in conflict.
- */
-static inline int __is_kernel_text(unsigned long addr)
+static inline int is_x86_32_kernel_text(unsigned long addr)
 {
if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
return 1;
@@ -333,8 +329,8 @@ kernel_physical_mapping_init(unsigned long start,
addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
PAGE_OFFSET + PAGE_SIZE-1;
 
-   if (__is_kernel_text(addr) ||
-   __is_kernel_text(addr2))
+   if (is_x86_32_kernel_text(addr) ||
+   is_x86_32_kernel_text(addr2))
prot = PAGE_KERNEL_LARGE_EXEC;
 
pages_2m++;
@@ -359,7 +355,7 @@ kernel_physical_mapping_init(unsigned long start,
 */
pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
 
-   if (__is_kernel_text(addr))
+   if (is_x86_32_kernel_text(addr))
prot = PAGE_KERNEL_EXEC;
 
pages_4k++;
@@ -820,7 +816,7 @@ static void mark_nxdata_nx(void)
 */
unsigned long start = PFN_ALIGN(_etext);
/*
-* This comes from __is_kernel_text upper limit. Also HPAGE where used:
+* This comes from is_x86_32_kernel_text upper limit. Also HPAGE where 
used:
 */
unsigned long size = (((unsigned long)__init_end + HPAGE_SIZE) & 
HPAGE_MASK) - start;
 
-- 
2.26.2



[PATCH v4 02/11] kallsyms: Fix address-checks for kernel related range

2021-09-30 Thread Kefeng Wang
The is_kernel_inittext/is_kernel_text/is_kernel function should not
include the end address(the labels _einittext, _etext and _end) when
check the address range, the issue exists since Linux v2.6.12.

Cc: Arnd Bergmann 
Cc: Sergey Senozhatsky 
Cc: Petr Mladek 
Reviewed-by: Petr Mladek 
Reviewed-by: Steven Rostedt (VMware) 
Acked-by: Sergey Senozhatsky 
Signed-off-by: Kefeng Wang 
---
 include/linux/kallsyms.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 2a241e3f063f..b016c62f30a6 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -27,21 +27,21 @@ struct module;
 static inline int is_kernel_inittext(unsigned long addr)
 {
if (addr >= (unsigned long)_sinittext
-   && addr <= (unsigned long)_einittext)
+   && addr < (unsigned long)_einittext)
return 1;
return 0;
 }
 
 static inline int is_kernel_text(unsigned long addr)
 {
-   if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext))
+   if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
return 1;
return in_gate_area_no_mm(addr);
 }
 
 static inline int is_kernel(unsigned long addr)
 {
-   if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
+   if (addr >= (unsigned long)_stext && addr < (unsigned long)_end)
return 1;
return in_gate_area_no_mm(addr);
 }
-- 
2.26.2



[PATCH v4 08/11] extable: Use is_kernel_text() helper

2021-09-30 Thread Kefeng Wang
The core_kernel_text() should check the gate area, as it is part
of kernel text range, use is_kernel_text() in core_kernel_text().

Cc: Steven Rostedt 
Signed-off-by: Kefeng Wang 
---
 kernel/extable.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/extable.c b/kernel/extable.c
index 98ca627ac5ef..0ba383d850ff 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -64,8 +64,7 @@ const struct exception_table_entry 
*search_exception_tables(unsigned long addr)
 
 int notrace core_kernel_text(unsigned long addr)
 {
-   if (addr >= (unsigned long)_stext &&
-   addr < (unsigned long)_etext)
+   if (is_kernel_text(addr))
return 1;
 
if (system_state < SYSTEM_RUNNING &&
-- 
2.26.2



[PATCH v4 11/11] alpha: Use is_kernel_text() helper

2021-09-30 Thread Kefeng Wang
Use is_kernel_text() helper to simplify code.

Cc: Richard Henderson 
Cc: Ivan Kokshaysky 
Cc: Matt Turner 
Signed-off-by: Kefeng Wang 
---
 arch/alpha/kernel/traps.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index e805106409f7..2ae34702456c 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -129,9 +129,7 @@ dik_show_trace(unsigned long *sp, const char *loglvl)
extern char _stext[], _etext[];
unsigned long tmp = *sp;
sp++;
-   if (tmp < (unsigned long) &_stext)
-   continue;
-   if (tmp >= (unsigned long) &_etext)
+   if (!is_kernel_text(tmp))
continue;
printk("%s[<%lx>] %pSR\n", loglvl, tmp, (void *)tmp);
if (i > 40) {
-- 
2.26.2



[PATCH v4 09/11] powerpc/mm: Use core_kernel_text() helper

2021-09-30 Thread Kefeng Wang
Use core_kernel_text() helper to simplify code, also drop etext,
_stext, _sinittext, _einittext declaration which already declared
in section.h.

Cc: Michael Ellerman 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Christophe Leroy 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Kefeng Wang 
---
 arch/powerpc/mm/pgtable_32.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index dcf5ecca19d9..079abbf45a33 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -33,8 +33,6 @@
 
 #include 
 
-extern char etext[], _stext[], _sinittext[], _einittext[];
-
 static u8 early_fixmap_pagetable[FIXMAP_PTE_SIZE] __page_aligned_data;
 
 notrace void __init early_ioremap_init(void)
@@ -104,14 +102,13 @@ static void __init __mapin_ram_chunk(unsigned long 
offset, unsigned long top)
 {
unsigned long v, s;
phys_addr_t p;
-   int ktext;
+   bool ktext;
 
s = offset;
v = PAGE_OFFSET + s;
p = memstart_addr + s;
for (; s < top; s += PAGE_SIZE) {
-   ktext = ((char *)v >= _stext && (char *)v < etext) ||
-   ((char *)v >= _sinittext && (char *)v < _einittext);
+   ktext = core_kernel_text(v);
map_kernel_page(v, p, ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL);
v += PAGE_SIZE;
p += PAGE_SIZE;
-- 
2.26.2



[PATCH v4 06/11] sections: Provide internal __is_kernel() and __is_kernel_text() helper

2021-09-30 Thread Kefeng Wang
An internal __is_kernel() helper which only check the
kernel address ranges, and an internal __is_kernel_text()
helper which only check text section ranges.

Signed-off-by: Kefeng Wang 
---
 include/asm-generic/sections.h | 29 +
 include/linux/kallsyms.h   |  4 ++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 811583ca8bd0..a7abeadddc7a 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -186,4 +186,33 @@ static inline bool is_kernel_inittext(unsigned long addr)
   addr < (unsigned long)_einittext;
 }
 
+/**
+ * __is_kernel_text - checks if the pointer address is located in the
+ *.text section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .text, false otherwise.
+ * Note: an internal helper, only check the range of _stext to _etext.
+ */
+static inline bool __is_kernel_text(unsigned long addr)
+{
+   return addr >= (unsigned long)_stext &&
+  addr < (unsigned long)_etext;
+}
+
+/**
+ * __is_kernel - checks if the pointer address is located in the kernel range
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in the kernel range, false 
otherwise.
+ * Note: an internal helper, only check the range of _stext to _end.
+ */
+static inline bool __is_kernel(unsigned long addr)
+{
+   return addr >= (unsigned long)_stext &&
+  addr < (unsigned long)_end;
+}
+
 #endif /* _ASM_GENERIC_SECTIONS_H_ */
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 8a9d329c927c..5fb17dd4b6fa 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -26,14 +26,14 @@ struct module;
 
 static inline int is_kernel_text(unsigned long addr)
 {
-   if ((addr >= (unsigned long)_stext && addr < (unsigned long)_etext))
+   if (__is_kernel_text(addr))
return 1;
return in_gate_area_no_mm(addr);
 }
 
 static inline int is_kernel(unsigned long addr)
 {
-   if (addr >= (unsigned long)_stext && addr < (unsigned long)_end)
+   if (__is_kernel(addr))
return 1;
return in_gate_area_no_mm(addr);
 }
-- 
2.26.2



[PATCH v4 03/11] sections: Move and rename core_kernel_data() to is_kernel_core_data()

2021-09-30 Thread Kefeng Wang
Move core_kernel_data() into sections.h and rename it to
is_kernel_core_data(), also make it return bool value, then
update all the callers.

Cc: Arnd Bergmann 
Cc: Steven Rostedt 
Cc: Ingo Molnar 
Cc: "David S. Miller" 
Signed-off-by: Kefeng Wang 
---
 include/asm-generic/sections.h | 16 
 include/linux/kernel.h |  1 -
 kernel/extable.c   | 18 --
 kernel/trace/ftrace.c  |  2 +-
 net/sysctl_net.c   |  2 +-
 5 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 817309e289db..24780c0f40b1 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -142,6 +142,22 @@ static inline bool init_section_intersects(void *virt, 
size_t size)
return memory_intersects(__init_begin, __init_end, virt, size);
 }
 
+/**
+ * is_kernel_core_data - checks if the pointer address is located in the
+ *  .data section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .data, false otherwise.
+ * Note: On some archs it may return true for core RODATA, and false
+ *   for others. But will always be true for core RW data.
+ */
+static inline bool is_kernel_core_data(unsigned long addr)
+{
+   return addr >= (unsigned long)_sdata &&
+  addr < (unsigned long)_edata;
+}
+
 /**
  * is_kernel_rodata - checks if the pointer address is located in the
  *.rodata section
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 2776423a587e..e5a9af8a4e20 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -230,7 +230,6 @@ extern char *next_arg(char *args, char **param, char **val);
 
 extern int core_kernel_text(unsigned long addr);
 extern int init_kernel_text(unsigned long addr);
-extern int core_kernel_data(unsigned long addr);
 extern int __kernel_text_address(unsigned long addr);
 extern int kernel_text_address(unsigned long addr);
 extern int func_ptr_is_kernel_text(void *ptr);
diff --git a/kernel/extable.c b/kernel/extable.c
index b0ea5eb0c3b4..da26203841d4 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -82,24 +82,6 @@ int notrace core_kernel_text(unsigned long addr)
return 0;
 }
 
-/**
- * core_kernel_data - tell if addr points to kernel data
- * @addr: address to test
- *
- * Returns true if @addr passed in is from the core kernel data
- * section.
- *
- * Note: On some archs it may return true for core RODATA, and false
- *  for others. But will always be true for core RW data.
- */
-int core_kernel_data(unsigned long addr)
-{
-   if (addr >= (unsigned long)_sdata &&
-   addr < (unsigned long)_edata)
-   return 1;
-   return 0;
-}
-
 int __kernel_text_address(unsigned long addr)
 {
if (kernel_text_address(addr))
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 7efbc8aaf7f6..f15badf31f52 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -323,7 +323,7 @@ int __register_ftrace_function(struct ftrace_ops *ops)
if (!ftrace_enabled && (ops->flags & FTRACE_OPS_FL_PERMANENT))
return -EBUSY;
 
-   if (!core_kernel_data((unsigned long)ops))
+   if (!is_kernel_core_data((unsigned long)ops))
ops->flags |= FTRACE_OPS_FL_DYNAMIC;
 
add_ftrace_ops(_ops_list, ops);
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index f6cb0d4d114c..4b45ed631eb8 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -144,7 +144,7 @@ static void ensure_safe_net_sysctl(struct net *net, const 
char *path,
addr = (unsigned long)ent->data;
if (is_module_address(addr))
where = "module";
-   else if (core_kernel_data(addr))
+   else if (is_kernel_core_data(addr))
where = "kernel";
else
continue;
-- 
2.26.2



[PATCH v4 00/11] sections: Unify kernel sections range check and use

2021-09-30 Thread Kefeng Wang
There are three head files(kallsyms.h, kernel.h and sections.h) which
include the kernel sections range check, let's make some cleanup and
unify them.

1. cleanup arch specific text/data check and fix address boundary check
   in kallsyms.h
2. make all the basic/core kernel range check function into sections.h
3. update all the callers, and use the helper in sections.h to simplify
   the code

After this series, we have 5 APIs about kernel sections range check in
sections.h

 * is_kernel_rodata()   --- already in sections.h
 * is_kernel_core_data()--- come from core_kernel_data() in kernel.h
 * is_kernel_inittext() --- come from kernel.h and kallsyms.h
 * __is_kernel_text()   --- add new internal helper
 * __is_kernel()--- add new internal helper

Note: For the last two helpers, people should not use directly, consider to
  use corresponding function in kallsyms.h.

v4:
- Use core_kernel_text() in powerpc sugguested Christophe Leroy, build
  test only
- Use is_kernel_text() in alpha and microblaze, build test only on
  next-20210929

v3:
https://lore.kernel.org/linux-arch/20210926072048.190336-1-wangkefeng.w...@huawei.com/
- Add Steven's RB to patch2
- Introduce two internal helper, then use is_kernel_text() in core_kernel_text()
  and is_kernel() in kernel_or_module_addr() suggested by Steven

v2:
https://lore.kernel.org/linux-arch/20210728081320.20394-1-wangkefeng.w...@huawei.com/
- add ACK/RW to patch2, and drop inappropriate fix tag
- keep 'core' to check kernel data, suggestted by Steven Rostedt
  , rename is_kernel_data() to is_kernel_core_data()
- drop patch8 which is merged
- drop patch9 which is resend independently

v1:
https://lore.kernel.org/linux-arch/20210626073439.150586-1-wangkefeng.w...@huawei.com


Kefeng Wang (11):
  kallsyms: Remove arch specific text and data check
  kallsyms: Fix address-checks for kernel related range
  sections: Move and rename core_kernel_data() to is_kernel_core_data()
  sections: Move is_kernel_inittext() into sections.h
  x86: mm: Rename __is_kernel_text() to is_x86_32_kernel_text()
  sections: Provide internal __is_kernel() and __is_kernel_text() helper
  mm: kasan: Use is_kernel() helper
  extable: Use is_kernel_text() helper
  powerpc/mm: Use core_kernel_text() helper
  microblaze: Use is_kernel_text() helper
  alpha: Use is_kernel_text() helper

 arch/alpha/kernel/traps.c  |  4 +-
 arch/microblaze/mm/pgtable.c   |  3 +-
 arch/powerpc/mm/pgtable_32.c   |  7 +---
 arch/x86/kernel/unwind_orc.c   |  2 +-
 arch/x86/mm/init_32.c  | 14 +++
 include/asm-generic/sections.h | 75 ++
 include/linux/kallsyms.h   | 13 +-
 include/linux/kernel.h |  2 -
 kernel/extable.c   | 33 ++-
 kernel/locking/lockdep.c   |  3 --
 kernel/trace/ftrace.c  |  2 +-
 mm/kasan/report.c  |  2 +-
 net/sysctl_net.c   |  2 +-
 13 files changed, 78 insertions(+), 84 deletions(-)

-- 
2.26.2



Re: [PATCH] KVM: PPC: Book3S HV: Use GLOBAL_TOC for kvmppc_h_set_dabr/xdabr()

2021-09-30 Thread Jordan Niethe
On Thu, Sep 30, 2021 at 4:13 PM Daniel Axtens  wrote:
>
> Hi Michael,
>
> > kvmppc_h_set_dabr(), and kvmppc_h_set_xdabr() which jumps into
> > it, need to use _GLOBAL_TOC to setup the kernel TOC pointer, because
> > kvmppc_h_set_dabr() uses LOAD_REG_ADDR() to load dawr_force_enable.
>
> This makes sense. LOAD_REG_ADDR() does ld reg,name@got(r2) and
> _GLOBAL_TOC sets r2 based on r12 and .TOC. .
>
> Looking at
> e.g. https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1610846.html
> it seems that we use GOT and TOC largely interchangeably... so assuming
> I haven't completely misunderstood, the change this patch makes seems to
> make sense to me. :)
>
> > When called from hcall_try_real_mode() we have the kernel TOC in r2,
> > established near the start of kvmppc_interrupt_hv(), so there is no
> > issue.
> >
> > But they can also be called from kvmppc_pseries_do_hcall() which is
> > module code, so the access ends up happening with the kvm-hv module's
> > r2, which will not point at dawr_force_enable and could even cause a
> > fault.
>
> I checked and there isn't anywhere else the functions are called, so
> this will now cover everything.
>
> > With the current code layout and compilers we haven't observed a fault
> > in practice, the load hits somewhere in kvm-hv.ko and silently returns
> > some bogus value.
> >
> > Note that we we expect p8/p9 guests to use the DAWR, but SLOF uses
> > h_set_dabr() to test if sc1 works correctly, see SLOF's
> > lib/libhvcall/brokensc1.c.
>
> I assume that something (the module loader?) patches the callsite to
> restore r2 after the function call? I imagine something must otherwise
> things would fall apart pretty quickly...
>
> > Fixes: c1fe190c0672 ("powerpc: Add force enable of DAWR on P9 option")
>
> That patch seems to only affect the DA_W_R not the DA_B_R - how does it
> cause this bug?

Isn't it that patch which adds the LOAD_REG_ADDR(r11,
dawr_force_enable) to kvmppc_h_set_dabr() which is the problem?

>
> All in all this looks good to me:
> Reviewed-by: Daniel Axtens 
>
> Kind regards,
> Daniel
>
> > Signed-off-by: Michael Ellerman 
> > ---
> >  arch/powerpc/kvm/book3s_hv_rmhandlers.S | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
> > b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> > index 90484425a1e6..30a8a07cff18 100644
> > --- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> > +++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> > @@ -1999,7 +1999,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
> >   .globl  hcall_real_table_end
> >  hcall_real_table_end:
> >
> > -_GLOBAL(kvmppc_h_set_xdabr)
> > +_GLOBAL_TOC(kvmppc_h_set_xdabr)
> >  EXPORT_SYMBOL_GPL(kvmppc_h_set_xdabr)
> >   andi.   r0, r5, DABRX_USER | DABRX_KERNEL
> >   beq 6f
> > @@ -2009,7 +2009,7 @@ EXPORT_SYMBOL_GPL(kvmppc_h_set_xdabr)
> >  6:   li  r3, H_PARAMETER
> >   blr
> >
> > -_GLOBAL(kvmppc_h_set_dabr)
> > +_GLOBAL_TOC(kvmppc_h_set_dabr)
> >  EXPORT_SYMBOL_GPL(kvmppc_h_set_dabr)
> >   li  r5, DABRX_USER | DABRX_KERNEL
> >  3:
> > --
> > 2.25.1


Re: [PATCH] powerpc/eeh:Fix some mistakes in comments

2021-09-30 Thread Daniel Axtens
Hi Kai,

Thank you for your contribution to the powerpc kernel!

> Get rid of warning:
> arch/powerpc/kernel/eeh.c:774: warning: expecting prototype for 
> eeh_set_pe_freset(). Prototype was for eeh_set_dev_freset() instead

You haven't said where this warning is from. I thought it might be from
sparse but I couldn't seem to reproduce it - is my version of sparse too
old or are you using a different tool?

>  /**
> - * eeh_set_pe_freset - Check the required reset for the indicated device
> - * @data: EEH device
> + * eeh_set_dev_freset - Check the required reset for the indicated device
> + * @edev: EEH device
>   * @flag: return value
>   *
>   * Each device might have its preferred reset type: fundamental or

This looks like a good and correct change.

I checked through git history with git blame to see when the function
was renamed. There are 2 commits that should have updated the comment:
one renamed the function and one renamed an argument. So, I think this
commit could have:

Fixes: d6c4932fbf24 ("powerpc/eeh: Strengthen types of eeh traversal functions")
Fixes: c270a24c59bd ("powerpc/eeh: Do reset based on PE")

But I don't know if an out of date comment is enough of a 'bug' to
justify a Fixes: tag? (mpe, I'm sure I've asked this before, sorry!)

All up, this is a good correction to the comment.

There are a few other functions in the file that have incorrect
docstrings:

 - eeh_pci_enable - missing parameter

 - eeh_pe_reset and eeh_pe_reset_full - missing parameter

 - eeh_init - missing parameter

 - eeh_pe_inject_err - wrong name for a parameter

Could you fix all of the docstrings in the file at once?

Kind regards,
Daniel



Re: [PATCH] KVM: PPC: Book3S HV: Use GLOBAL_TOC for kvmppc_h_set_dabr/xdabr()

2021-09-30 Thread Daniel Axtens
Hi Michael,

> kvmppc_h_set_dabr(), and kvmppc_h_set_xdabr() which jumps into
> it, need to use _GLOBAL_TOC to setup the kernel TOC pointer, because
> kvmppc_h_set_dabr() uses LOAD_REG_ADDR() to load dawr_force_enable.

This makes sense. LOAD_REG_ADDR() does ld reg,name@got(r2) and
_GLOBAL_TOC sets r2 based on r12 and .TOC. .

Looking at
e.g. https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1610846.html
it seems that we use GOT and TOC largely interchangeably... so assuming
I haven't completely misunderstood, the change this patch makes seems to
make sense to me. :)

> When called from hcall_try_real_mode() we have the kernel TOC in r2,
> established near the start of kvmppc_interrupt_hv(), so there is no
> issue.
>
> But they can also be called from kvmppc_pseries_do_hcall() which is
> module code, so the access ends up happening with the kvm-hv module's
> r2, which will not point at dawr_force_enable and could even cause a
> fault.

I checked and there isn't anywhere else the functions are called, so
this will now cover everything.

> With the current code layout and compilers we haven't observed a fault
> in practice, the load hits somewhere in kvm-hv.ko and silently returns
> some bogus value.
>
> Note that we we expect p8/p9 guests to use the DAWR, but SLOF uses
> h_set_dabr() to test if sc1 works correctly, see SLOF's
> lib/libhvcall/brokensc1.c.

I assume that something (the module loader?) patches the callsite to
restore r2 after the function call? I imagine something must otherwise
things would fall apart pretty quickly...

> Fixes: c1fe190c0672 ("powerpc: Add force enable of DAWR on P9 option")

That patch seems to only affect the DA_W_R not the DA_B_R - how does it
cause this bug?

All in all this looks good to me:
Reviewed-by: Daniel Axtens 

Kind regards,
Daniel

> Signed-off-by: Michael Ellerman 
> ---
>  arch/powerpc/kvm/book3s_hv_rmhandlers.S | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
> b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> index 90484425a1e6..30a8a07cff18 100644
> --- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> +++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> @@ -1999,7 +1999,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
>   .globl  hcall_real_table_end
>  hcall_real_table_end:
>  
> -_GLOBAL(kvmppc_h_set_xdabr)
> +_GLOBAL_TOC(kvmppc_h_set_xdabr)
>  EXPORT_SYMBOL_GPL(kvmppc_h_set_xdabr)
>   andi.   r0, r5, DABRX_USER | DABRX_KERNEL
>   beq 6f
> @@ -2009,7 +2009,7 @@ EXPORT_SYMBOL_GPL(kvmppc_h_set_xdabr)
>  6:   li  r3, H_PARAMETER
>   blr
>  
> -_GLOBAL(kvmppc_h_set_dabr)
> +_GLOBAL_TOC(kvmppc_h_set_dabr)
>  EXPORT_SYMBOL_GPL(kvmppc_h_set_dabr)
>   li  r5, DABRX_USER | DABRX_KERNEL
>  3:
> -- 
> 2.25.1