[PATCH v3 10/10] powerpc/8xx: Add microcode patch to move SMC parameter RAM.

2019-06-13 Thread Christophe Leroy
Some SCC functions like the QMC requires an extended parameter RAM.
On modern 8xx (ie 866 and 885), SPI area can already be relocated,
allowing the use of those functions on SCC2. But SCC3 and SCC4
parameter RAM collide with SMC1 and SMC2 parameter RAMs.

This patch adds microcode to allow the relocation of both SMC1 and
SMC2, and relocate them at offsets 0x1ec0 and 0x1fc0.
Those offsets are by default for the CPM1 DSP1 and DSP2, but there
is no kernel driver using them at the moment so this area can be
reused.

This microcode is provided by Freescale/NXP in Engineering Bulletin
EB662 ("MPC8xx I2C/SPI and SMC Relocation Microcode Packages")
dated 2006. The binary code is public. The source is not available.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/Kconfig  |  7 +++
 arch/powerpc/platforms/8xx/micropatch.c | 97 +
 2 files changed, 104 insertions(+)

diff --git a/arch/powerpc/platforms/8xx/Kconfig 
b/arch/powerpc/platforms/8xx/Kconfig
index d408162d5af4..e0fe670f06f6 100644
--- a/arch/powerpc/platforms/8xx/Kconfig
+++ b/arch/powerpc/platforms/8xx/Kconfig
@@ -157,6 +157,13 @@ config I2C_SPI_SMC1_UCODE_PATCH
help
  Help not implemented yet, coming soon.
 
+config SMC_UCODE_PATCH
+   bool "SMC relocation patch"
+   help
+ This microcode relocates SMC1 and SMC2 parameter RAMs at
+ offset 0x1ec0 and 0x1fc0 to allow extended parameter RAM
+ for SCC3 and SCC4.
+
 endchoice
 
 config UCODE_PATCH
diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 986aa6978ab7..c571555c12d3 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -233,6 +233,94 @@ static uint patch_2f00[] __initdata = {
 static uint patch_2e00[] __initdata = {};
 #endif
 
+/*
+ * SMC relocation patch arrays.
+ */
+
+#ifdef CONFIG_SMC_UCODE_PATCH
+
+static char patch_name[] __initdata = "SMC";
+
+static struct patch_params patch_params __initdata = {
+   2, 0x8080, 0x8088,
+};
+
+static uint patch_2000[] __initdata = {
+   0x3fff, 0x3ffd, 0x3ffb, 0x3ff9,
+   0x5fefeff8, 0x5f91eff8, 0x3ff3, 0x3ff1,
+   0x3a11e710, 0xedf0ccb9, 0xf318ed66, 0x7f0e5fe2,
+   0x7fedbb38, 0x3afe7468, 0x7fedf4d8, 0x8ffbb92d,
+   0xb83b77fd, 0xb0bb5eb9, 0xdfda7fed, 0x90bde74d,
+   0x6f0dcbd3, 0xe7decfed, 0xcb50cfed, 0xcfeddf6d,
+   0x914d4f74, 0x5eaedfcb, 0x9ee0e7df, 0xefbb6ffb,
+   0xe7ef7f0e, 0x9ee57fed, 0xebb7effa, 0xeb30affb,
+   0x7fea90b3, 0x7e0cf09f, 0xb318, 0x5fffdfff,
+   0xac35efea, 0x7fce1fc1, 0xe2ff5fbd, 0xaffbe2ff,
+   0x5fbfaffb, 0xf9a87d0f, 0xaef8770f, 0x7d0fb0a2,
+   0xeffbbfff, 0xcfef5fba, 0x7d0fbfff, 0x5fba4cf8,
+   0x7fddd09b, 0x49f847fd, 0x7efdf097, 0x7fedfffd,
+   0x7dfdf093, 0xef7e7e1e, 0x5fba7f0e, 0x3a11e710,
+   0xedf0cc87, 0xfb18ad0a, 0x1f85bbb8, 0x74283b7e,
+   0x7375e4bb, 0x2ab64fb8, 0x5c7de4bb, 0x32fdffbf,
+   0x5f0843f8, 0x7ce3e1bb, 0xe74f7ded, 0x6f0f4fe8,
+   0xc7ba32be, 0x73f2efeb, 0x600b4f78, 0xe5bb760b,
+   0x5388aef8, 0x4ef80b6a, 0xcfef9ee5, 0xabf8751f,
+   0xefef5b88, 0x741f4fe8, 0x751e760d, 0x7fdb70dd,
+   0x741cafce, 0xefcc7fce, 0x751e7088, 0x741ce7bb,
+   0x334ecfed, 0xafdbefeb, 0xe5bb760b, 0x53ceaef8,
+   0xafe8e7eb, 0x4bf8771e, 0x7e007fed, 0x4fcbe2cc,
+   0x7fbc3085, 0x7b0f7a0f, 0x34b177fd, 0xb0e75e93,
+   0xdf313e3b, 0xaf78741f, 0x741f30cc, 0xcfef5f08,
+   0x741f3e88, 0xafb8771e, 0x5f437fed, 0x0bafe2cc,
+   0x741ccfec, 0xe5ca53a9, 0x6fcb4f74, 0x5e89df27,
+   0x2a923d14, 0x4b8fdf0c, 0x751f741c, 0x6c1eeffa,
+   0xefea7fce, 0x6ffc309a, 0xefec3fca, 0x308fdf0a,
+   0xadf85e7a, 0xaf7daefd, 0x5e7adf0a, 0x5e7aafdd,
+   0x761f1088, 0x1e7c7efd, 0x3089fffe, 0x4908fb18,
+   0x5fffdfff, 0xafbbf0f7, 0x4ef85f43, 0xadf81489,
+   0x7a0f7089, 0xcfef5089, 0x7a0fdf0c, 0x5e7cafed,
+   0xbc6e780f, 0xefef780f, 0xefef790f, 0xa7f85eeb,
+   0xffef790f, 0xefef790f, 0x1489df0a, 0x5e7aadfd,
+   0x5f09fffb, 0xe79aded9, 0xeff96079, 0x607ae79a,
+   0xded8eff9, 0x60795edb, 0x607acfef, 0xefefefdf,
+   0xefbfef7f, 0xeeffedff, 0xebffe7ff, 0xafefafdf,
+   0xafbfaf7f, 0xaeffadff, 0xabffa7ff, 0x6fef6fdf,
+   0x6fbf6f7f, 0x6eff6dff, 0x6bff67ff, 0x2fef2fdf,
+   0x2fbf2f7f, 0x2eff2dff, 0x2bff27ff, 0x4e08fd1f,
+   0xe5ff6e0f, 0xaff87eef, 0x7e0ffdef, 0xf11f6079,
+   0xabf8f51e, 0x7e0af11c, 0x37cfae16, 0x7fec909a,
+   0xadf8efdc, 0xcfeae52f, 0x7d0fe12b, 0xf11c6079,
+   0x7e0a4df8, 0xcfea5ea0, 0x7d0befec, 0xcfea5ea2,
+   0xe522efdc, 0x5ea2cfda, 0x4e08fd1f, 0x6e0faff8,
+   0x7c1f761f, 0xfdeff91f, 0x6079abf8, 0x761cee00,
+   0xf91f2bfb, 0xefefcfec, 0xf91f6079, 0x761c27fb,
+   0xefdf5e83, 0xcfdc7fdd, 0x50f84bf8, 0x47fd7c1f,
+   0x761ccfcf, 0x7eef7fed, 0x7dfd70ef, 0xef7e7f1e,
+   0x771efb18, 0x6079e722, 0xe6bbe5bb, 0x2e66e5bb,
+   0x600b2ee1, 0xe2bbe2

[PATCH v3 09/10] powerpc/8xx: Use IO accessors in microcode programming.

2019-06-13 Thread Christophe Leroy
Change microcode functions to use IO accessors and get rid
of volatile attributes.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 34 -
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 252db7c90599..986aa6978ab7 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -242,13 +242,7 @@ static void __init cpm_write_patch(cpm8xx_t *cp, int 
offset, uint *patch, int le
 
 void __init cpm_load_patch(cpm8xx_t *cp)
 {
-   volatile cpm8xx_t   *commproc;
-   volatile iic_t  *iip;
-   volatile struct spi_pram *spp;
-   volatile smc_uart_t *smp;
-   commproc = cp;
-
-   commproc->cp_rccr = 0;
+   out_be16(&cp->cp_rccr, 0);
 
cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
@@ -257,26 +251,30 @@ void __init cpm_load_patch(cpm8xx_t *cp)
if (IS_ENABLED(CONFIG_I2C_SPI_UCODE_PATCH) ||
IS_ENABLED(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)) {
u16 rpbase = 0x500;
+   iic_t *iip;
+   struct spi_pram *spp;
 
-   iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
-   iip->iic_rpbase = rpbase;
+   iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
+   out_be16(&iip->iic_rpbase, rpbase);
 
/* Put SPI above the IIC, also 32-byte aligned. */
-   spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
-   spp->rpbase = (rpbase + sizeof(iic_t) + 31) & ~31;
+   spp = (struct spi_pram *)&cp->cp_dparam[PROFF_SPI];
+   out_be16(&spp->rpbase, (rpbase + sizeof(iic_t) + 31) & ~31);
 
if (IS_ENABLED(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)) {
-   smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
-   smp->smc_rpbase = 0x1FC0;
+   smc_uart_t *smp;
+
+   smp = (smc_uart_t *)&cp->cp_dparam[PROFF_SMC1];
+   out_be16(&smp->smc_rpbase, 0x1FC0);
}
}
 
-   commproc->cp_cpmcr1 = patch_params.cpmcr1;
-   commproc->cp_cpmcr2 = patch_params.cpmcr2;
-   commproc->cp_cpmcr3 = patch_params.cpmcr3;
-   commproc->cp_cpmcr4 = patch_params.cpmcr4;
+   out_be16(&cp->cp_cpmcr1, patch_params.cpmcr1);
+   out_be16(&cp->cp_cpmcr2, patch_params.cpmcr2);
+   out_be16(&cp->cp_cpmcr3, patch_params.cpmcr3);
+   out_be16(&cp->cp_cpmcr4, patch_params.cpmcr4);
 
-   commproc->cp_rccr = patch_params.rccr;
+   out_be16(&cp->cp_rccr, patch_params.rccr);
 
pr_info("%s microcode patch installed\n", patch_name);
 }
-- 
2.13.3



[PATCH v3 08/10] powerpc/8xx: replace #ifdefs by IS_ENABLED() in microcode.c

2019-06-13 Thread Christophe Leroy
Reduce #ifdef mess by using IS_ENABLED() instead.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 33 +
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 02490c54ebac..252db7c90599 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -243,14 +243,9 @@ static void __init cpm_write_patch(cpm8xx_t *cp, int 
offset, uint *patch, int le
 void __init cpm_load_patch(cpm8xx_t *cp)
 {
volatile cpm8xx_t   *commproc;
-#if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
-defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
volatile iic_t  *iip;
volatile struct spi_pram *spp;
-#ifdef CONFIG_I2C_SPI_SMC1_UCODE_PATCH
volatile smc_uart_t *smp;
-#endif
-#endif
commproc = cp;
 
commproc->cp_rccr = 0;
@@ -259,24 +254,22 @@ void __init cpm_load_patch(cpm8xx_t *cp)
cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
 
-#if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
-defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
-
-   iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
-# define RPBASE 0x0500
-   iip->iic_rpbase = RPBASE;
+   if (IS_ENABLED(CONFIG_I2C_SPI_UCODE_PATCH) ||
+   IS_ENABLED(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)) {
+   u16 rpbase = 0x500;
 
-   /* Put SPI above the IIC, also 32-byte aligned.
-   */
-   spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
-   spp->rpbase = (RPBASE + sizeof(iic_t) + 31) & ~31;
+   iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
+   iip->iic_rpbase = rpbase;
 
-# if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
-   smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
-   smp->smc_rpbase = 0x1FC0;
-# endif /* CONFIG_I2C_SPI_SMC1_UCODE_PATCH) */
+   /* Put SPI above the IIC, also 32-byte aligned. */
+   spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
+   spp->rpbase = (rpbase + sizeof(iic_t) + 31) & ~31;
 
-#endif /* some variation of the I2C/SPI patch was selected */
+   if (IS_ENABLED(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)) {
+   smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
+   smp->smc_rpbase = 0x1FC0;
+   }
+   }
 
commproc->cp_cpmcr1 = patch_params.cpmcr1;
commproc->cp_cpmcr2 = patch_params.cpmcr2;
-- 
2.13.3



[PATCH v3 07/10] powerpc/8xx: refactor programming of microcode CPM params.

2019-06-13 Thread Christophe Leroy
The CPM registers RCCR and CPMCR1..4 registers has to be set in
accordance with the microcode patch beeing programmed. Lets
define them as part of the patch set and refactor their
programming from that definition.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 45 -
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 5e5ac2378d3f..02490c54ebac 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -20,6 +20,14 @@
 #include 
 #include 
 
+struct patch_params {
+   ushort rccr;
+   ushort cpmcr1;
+   ushort cpmcr2;
+   ushort cpmcr3;
+   ushort cpmcr4;
+};
+
 /*
  * I2C/SPI relocation patch arrays.
  */
@@ -28,6 +36,10 @@
 
 static char patch_name[] __initdata = "I2C/SPI";
 
+static struct patch_params patch_params __initdata = {
+   1, 0x802a, 0x8028, 0x802e, 0x802c,
+};
+
 static uint patch_2000[] __initdata = {
0x7FFFEFD9, 0x3FFD, 0x7FFB49F7, 0x7FF9,
0x5FEFADF7, 0x5F89ADF7, 0x5FEFAFF7, 0x5F89AFF7,
@@ -82,6 +94,10 @@ static uint patch_2e00[] __initdata = {};
 
 static char patch_name[] __initdata = "I2C/SPI/SMC1";
 
+static struct patch_params patch_params __initdata = {
+   3, 0x8080, 0x808a, 0x8028, 0x802a,
+};
+
 static uint patch_2000[] __initdata = {
0x3fff, 0x3ffd, 0x3ffb, 0x3ff9,
0x5f13eff8, 0x5eb5eff8, 0x5f88adf7, 0x5fefadf7,
@@ -200,6 +216,10 @@ static uint patch_2e00[] __initdata = {
 
 static char patch_name[] __initdata = "USB SOF";
 
+static struct patch_params patch_params __initdata = {
+   9,
+};
+
 static uint patch_2000[] __initdata = {
0x7fff, 0x7ffd, 0x7ffb, 0x49f7ba5b,
0xba383ffb, 0xf9b8b46d, 0xe5ab4e07, 0xaf77bffe,
@@ -239,10 +259,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
 
-#ifdef CONFIG_USB_SOF_UCODE_PATCH
-   commproc->cp_rccr = 0x0009;
-#endif /* CONFIG_USB_SOF_UCODE_PATCH */
-
 #if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
 defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
 
@@ -255,26 +271,19 @@ void __init cpm_load_patch(cpm8xx_t *cp)
spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
spp->rpbase = (RPBASE + sizeof(iic_t) + 31) & ~31;
 
-# if defined(CONFIG_I2C_SPI_UCODE_PATCH)
-   commproc->cp_cpmcr1 = 0x802a;
-   commproc->cp_cpmcr2 = 0x8028;
-   commproc->cp_cpmcr3 = 0x802e;
-   commproc->cp_cpmcr4 = 0x802c;
-   commproc->cp_rccr = 1;
-# endif /* CONFIG_I2C_SPI_UCODE_PATCH */
-
 # if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
-   commproc->cp_cpmcr1 = 0x8080;
-   commproc->cp_cpmcr2 = 0x808a;
-   commproc->cp_cpmcr3 = 0x8028;
-   commproc->cp_cpmcr4 = 0x802a;
-   commproc->cp_rccr = 3;
-
smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
smp->smc_rpbase = 0x1FC0;
 # endif /* CONFIG_I2C_SPI_SMC1_UCODE_PATCH) */
 
 #endif /* some variation of the I2C/SPI patch was selected */
 
+   commproc->cp_cpmcr1 = patch_params.cpmcr1;
+   commproc->cp_cpmcr2 = patch_params.cpmcr2;
+   commproc->cp_cpmcr3 = patch_params.cpmcr3;
+   commproc->cp_cpmcr4 = patch_params.cpmcr4;
+
+   commproc->cp_rccr = patch_params.rccr;
+
pr_info("%s microcode patch installed\n", patch_name);
 }
-- 
2.13.3



[PATCH v3 06/10] powerpc/8xx: refactor printing of microcode patch name.

2019-06-13 Thread Christophe Leroy
Define patch name together with the patch code, and refactor
the associated printk() while replacing it by a pr_info()

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 410968a0b177..5e5ac2378d3f 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -26,6 +26,8 @@
 
 #ifdef CONFIG_I2C_SPI_UCODE_PATCH
 
+static char patch_name[] __initdata = "I2C/SPI";
+
 static uint patch_2000[] __initdata = {
0x7FFFEFD9, 0x3FFD, 0x7FFB49F7, 0x7FF9,
0x5FEFADF7, 0x5F89ADF7, 0x5FEFAFF7, 0x5F89AFF7,
@@ -78,6 +80,8 @@ static uint patch_2e00[] __initdata = {};
 
 #ifdef CONFIG_I2C_SPI_SMC1_UCODE_PATCH
 
+static char patch_name[] __initdata = "I2C/SPI/SMC1";
+
 static uint patch_2000[] __initdata = {
0x3fff, 0x3ffd, 0x3ffb, 0x3ff9,
0x5f13eff8, 0x5eb5eff8, 0x5f88adf7, 0x5fefadf7,
@@ -194,6 +198,8 @@ static uint patch_2e00[] __initdata = {
 
 #ifdef CONFIG_USB_SOF_UCODE_PATCH
 
+static char patch_name[] __initdata = "USB SOF";
+
 static uint patch_2000[] __initdata = {
0x7fff, 0x7ffd, 0x7ffb, 0x49f7ba5b,
0xba383ffb, 0xf9b8b46d, 0xe5ab4e07, 0xaf77bffe,
@@ -235,8 +241,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
 #ifdef CONFIG_USB_SOF_UCODE_PATCH
commproc->cp_rccr = 0x0009;
-
-   printk("USB SOF microcode patch installed\n");
 #endif /* CONFIG_USB_SOF_UCODE_PATCH */
 
 #if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
@@ -257,8 +261,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
commproc->cp_cpmcr3 = 0x802e;
commproc->cp_cpmcr4 = 0x802c;
commproc->cp_rccr = 1;
-
-   printk("I2C/SPI microcode patch installed.\n");
 # endif /* CONFIG_I2C_SPI_UCODE_PATCH */
 
 # if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
@@ -270,9 +272,9 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
smp->smc_rpbase = 0x1FC0;
-
-   printk("I2C/SPI/SMC1 microcode patch installed.\n");
 # endif /* CONFIG_I2C_SPI_SMC1_UCODE_PATCH) */
 
 #endif /* some variation of the I2C/SPI patch was selected */
+
+   pr_info("%s microcode patch installed\n", patch_name);
 }
-- 
2.13.3



[PATCH v3 05/10] powerpc/8xx: Refactor microcode write

2019-06-13 Thread Christophe Leroy
Add empty microcode tables so that all tables are defined
all the time. Regroup the writing of the 3 tables regardless
of the selected microcode.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 2abc226d1139..410968a0b177 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -68,6 +68,8 @@ static uint patch_2f00[] __initdata = {
0x31497353, 0x76956D69, 0x7B9D9693, 0x13131979,
0x79376935
 };
+
+static uint patch_2e00[] __initdata = {};
 #endif
 
 /*
@@ -201,6 +203,8 @@ static uint patch_2000[] __initdata = {
 static uint patch_2f00[] __initdata = {
0x3030304c, 0xcab9e441, 0xa1aaf220
 };
+
+static uint patch_2e00[] __initdata = {};
 #endif
 
 static void __init cpm_write_patch(cpm8xx_t *cp, int offset, uint *patch, int 
len)
@@ -223,12 +227,13 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 #endif
commproc = cp;
 
-#ifdef CONFIG_USB_SOF_UCODE_PATCH
commproc->cp_rccr = 0;
 
cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
+   cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
 
+#ifdef CONFIG_USB_SOF_UCODE_PATCH
commproc->cp_rccr = 0x0009;
 
printk("USB SOF microcode patch installed\n");
@@ -237,11 +242,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 #if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
 defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
 
-   commproc->cp_rccr = 0;
-
-   cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
-   cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
-
iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
 # define RPBASE 0x0500
iip->iic_rpbase = RPBASE;
@@ -262,9 +262,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 # endif /* CONFIG_I2C_SPI_UCODE_PATCH */
 
 # if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
-
-   cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
-
commproc->cp_cpmcr1 = 0x8080;
commproc->cp_cpmcr2 = 0x808a;
commproc->cp_cpmcr3 = 0x8028;
-- 
2.13.3



[PATCH v3 04/10] powerpc/8xx: refactor writing of CPM microcode arrays

2019-06-13 Thread Christophe Leroy
Create a function to refactor the writing of CPM microcode arrays.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 35 -
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index e14b6bcadce3..2abc226d1139 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -203,9 +203,15 @@ static uint patch_2f00[] __initdata = {
 };
 #endif
 
+static void __init cpm_write_patch(cpm8xx_t *cp, int offset, uint *patch, int 
len)
+{
+   if (!len)
+   return;
+   memcpy_toio(cp->cp_dpmem + offset, patch, len);
+}
+
 void __init cpm_load_patch(cpm8xx_t *cp)
 {
-   volatile uint   *dp;/* Dual-ported RAM. */
volatile cpm8xx_t   *commproc;
 #if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
 defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
@@ -215,20 +221,13 @@ void __init cpm_load_patch(cpm8xx_t *cp)
volatile smc_uart_t *smp;
 #endif
 #endif
-   int i;
-
commproc = cp;
 
 #ifdef CONFIG_USB_SOF_UCODE_PATCH
commproc->cp_rccr = 0;
 
-   dp = (uint *)(commproc->cp_dpmem);
-   for (i=0; i<(sizeof(patch_2000)/4); i++)
-   *dp++ = patch_2000[i];
-
-   dp = (uint *)&(commproc->cp_dpmem[0x0f00]);
-   for (i=0; i<(sizeof(patch_2f00)/4); i++)
-   *dp++ = patch_2f00[i];
+   cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
+   cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
 
commproc->cp_rccr = 0x0009;
 
@@ -240,13 +239,8 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
commproc->cp_rccr = 0;
 
-   dp = (uint *)(commproc->cp_dpmem);
-   for (i=0; i<(sizeof(patch_2000)/4); i++)
-   *dp++ = patch_2000[i];
-
-   dp = (uint *)&(commproc->cp_dpmem[0x0f00]);
-   for (i=0; i<(sizeof(patch_2f00)/4); i++)
-   *dp++ = patch_2f00[i];
+   cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
+   cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
 
iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
 # define RPBASE 0x0500
@@ -254,9 +248,8 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
/* Put SPI above the IIC, also 32-byte aligned.
*/
-   i = (RPBASE + sizeof(iic_t) + 31) & ~31;
spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
-   spp->rpbase = i;
+   spp->rpbase = (RPBASE + sizeof(iic_t) + 31) & ~31;
 
 # if defined(CONFIG_I2C_SPI_UCODE_PATCH)
commproc->cp_cpmcr1 = 0x802a;
@@ -270,9 +263,7 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
 # if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
 
-   dp = (uint *)&(commproc->cp_dpmem[0x0e00]);
-   for (i=0; i<(sizeof(patch_2e00)/4); i++)
-   *dp++ = patch_2e00[i];
+   cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
 
commproc->cp_cpmcr1 = 0x8080;
commproc->cp_cpmcr2 = 0x808a;
-- 
2.13.3



[PATCH v3 03/10] powerpc/8xx: compact microcode arrays

2019-06-13 Thread Christophe Leroy
Compact obscure microcode arrays by putting 4 values per line
in order to reduce number of lines in the file to increase
readability.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 699 +++-
 1 file changed, 140 insertions(+), 559 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 7bbaf9914f32..e14b6bcadce3 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -27,153 +27,45 @@
 #ifdef CONFIG_I2C_SPI_UCODE_PATCH
 
 static uint patch_2000[] __initdata = {
-   0x7FFFEFD9,
-   0x3FFD,
-   0x7FFB49F7,
-   0x7FF9,
-   0x5FEFADF7,
-   0x5F89ADF7,
-   0x5FEFAFF7,
-   0x5F89AFF7,
-   0x3A9CFBC8,
-   0xE7C0EDF0,
-   0x77C1E1BB,
-   0xF4DC7F1D,
-   0xABAD932F,
-   0x4E08FDCF,
-   0x6E0FAFF8,
-   0x7CCF76CF,
-   0xFD1FF9CF,
-   0xABF88DC6,
-   0xAB5679F7,
-   0xB0937383,
-   0xDFCE79F7,
-   0xB091E6BB,
-   0xE5BBE74F,
-   0xB3FA6F0F,
-   0x6FFB76CE,
-   0xEE0DF9CF,
-   0x2BFBEFEF,
-   0xCFEEF9CF,
-   0x76CEAD24,
-   0x90B2DF9A,
-   0x7FDDD0BF,
-   0x4BF847FD,
-   0x7CCF76CE,
-   0xCFEF7E1F,
-   0x7F1D7DFD,
-   0xF0B6EF71,
-   0x7FC177C1,
-   0xFBC86079,
-   0xE722FBC8,
-   0x5FFFDFFF,
-   0x5FB2FFFB,
-   0xFBC8F3C8,
-   0x94A67F01,
-   0x7F1D5F39,
-   0xAFE85F5E,
-   0xFFDFDF96,
-   0xCB9FAF7D,
-   0x5FC1AFED,
-   0x8C1C5FC1,
-   0xAFDD5FC3,
-   0xDF9A7EFD,
-   0xB0B25FB2,
-   0xFFFEABAD,
-   0x5FB2FFFE,
-   0x5FCE600B,
-   0xE6BB600B,
-   0x5FCEDFC6,
-   0x27FBEFDF,
-   0x5FC8CFDE,
-   0x3A9CE7C0,
-   0xEDF0F3C8,
-   0x7F0154CD,
-   0x7F1D2D3D,
-   0x363A7570,
-   0x7E0AF1CE,
-   0x37EF2E68,
-   0x7FEE10EC,
-   0xADF8EFDE,
-   0xCFEAE52F,
-   0x7D0FE12B,
-   0xF1CE5F65,
-   0x7E0A4DF8,
-   0xCFEA5F72,
-   0x7D0BEFEE,
-   0xCFEA5F74,
-   0xE522EFDE,
-   0x5F74CFDA,
-   0x0B627385,
-   0xDF627E0A,
-   0x30D8145B,
-   0xB3C8,
-   0x5FFFDFFF,
-   0xA7F85F5E,
-   0xBFFE7F7D,
-   0x10D31450,
-   0x5F36BFFF,
-   0xAF785F5E,
-   0xBFFDA7F8,
-   0x5F36BFFE,
-   0x77FD30C0,
-   0x4E08FDCF,
-   0xE5FF6E0F,
-   0xAFF87E1F,
-   0x7E0FFD1F,
-   0xF1CF5F1B,
-   0xABF80D5E,
-   0x5F5EFFEF,
-   0x79F730A2,
-   0xAFDD5F34,
-   0x47F85F34,
-   0xAFED7FDD,
-   0x50B24978,
-   0x47FD7F1D,
-   0x7DFD70AD,
-   0xEF717EC1,
-   0x6BA47F01,
-   0x2D267EFD,
-   0x30DE5F5E,
-   0xFFFD5F5E,
-   0xFFEF5F5E,
-   0xFFDF0CA0,
-   0xAFED0A9E,
-   0xAFDD0C3A,
-   0x5F3AAFBD,
-   0x7FBDB082,
-   0x5F8247F8
+   0x7FFFEFD9, 0x3FFD, 0x7FFB49F7, 0x7FF9,
+   0x5FEFADF7, 0x5F89ADF7, 0x5FEFAFF7, 0x5F89AFF7,
+   0x3A9CFBC8, 0xE7C0EDF0, 0x77C1E1BB, 0xF4DC7F1D,
+   0xABAD932F, 0x4E08FDCF, 0x6E0FAFF8, 0x7CCF76CF,
+   0xFD1FF9CF, 0xABF88DC6, 0xAB5679F7, 0xB0937383,
+   0xDFCE79F7, 0xB091E6BB, 0xE5BBE74F, 0xB3FA6F0F,
+   0x6FFB76CE, 0xEE0DF9CF, 0x2BFBEFEF, 0xCFEEF9CF,
+   0x76CEAD24, 0x90B2DF9A, 0x7FDDD0BF, 0x4BF847FD,
+   0x7CCF76CE, 0xCFEF7E1F, 0x7F1D7DFD, 0xF0B6EF71,
+   0x7FC177C1, 0xFBC86079, 0xE722FBC8, 0x5FFFDFFF,
+   0x5FB2FFFB, 0xFBC8F3C8, 0x94A67F01, 0x7F1D5F39,
+   0xAFE85F5E, 0xFFDFDF96, 0xCB9FAF7D, 0x5FC1AFED,
+   0x8C1C5FC1, 0xAFDD5FC3, 0xDF9A7EFD, 0xB0B25FB2,
+   0xFFFEABAD, 0x5FB2FFFE, 0x5FCE600B, 0xE6BB600B,
+   0x5FCEDFC6, 0x27FBEFDF, 0x5FC8CFDE, 0x3A9CE7C0,
+   0xEDF0F3C8, 0x7F0154CD, 0x7F1D2D3D, 0x363A7570,
+   0x7E0AF1CE, 0x37EF2E68, 0x7FEE10EC, 0xADF8EFDE,
+   0xCFEAE52F, 0x7D0FE12B, 0xF1CE5F65, 0x7E0A4DF8,
+   0xCFEA5F72, 0x7D0BEFEE, 0xCFEA5F74, 0xE522EFDE,
+   0x5F74CFDA, 0x0B627385, 0xDF627E0A, 0x30D8145B,
+   0xB3C8, 0x5FFFDFFF, 0xA7F85F5E, 0xBFFE7F7D,
+   0x10D31450, 0x5F36BFFF, 0xAF785F5E, 0xBFFDA7F8,
+   0x5F36BFFE, 0x77FD30C0, 0x4E08FDCF, 0xE5FF6E0F,
+   0xAFF87E1F, 0x7E0FFD1F, 0xF1CF5F1B, 0xABF80D5E,
+   0x5F5EFFEF, 0x79F730A2, 0xAFDD5F34, 0x47F85F34,
+   0xAFED7FDD, 0x50B24978, 0x47FD7F1D, 0x7DFD70AD,
+   0xEF717EC1, 0x6BA47F01, 0x2D267EFD, 0x30DE5F5E,
+   0xFFFD5F5E, 0xFFEF5F5E, 0xFFDF0CA0, 0xAFED0A9E,
+   0xAFDD0C3A, 0x5F3AAFBD, 0x7FBDB082, 0x5F8247F8
 };
 
 static uint patch_2f00[] __initdata = {
-   0x3E303430,
-   0x34343737,
-   0xABF7BF9B,
-   0x994B4FBD,
-   0xBD599493,
-   0x349FFF37,
-   0xFB9B177D,
-   0xD9936956,
-   0xBBFDD697,
-   0xBDD2FD11,
-   0x31DB9BB3,
-   0x63139637,
-   0x93733693,
-   0x193137F7,
-   0x331737AF,
-   0x7BB9B999,
-   0xBB197957,
-   0x7FDFD3D5,
-   0x73B773F

[PATCH v3 01/10] powerpc/8xx: move CPM1 related files from sysdev/ to platforms/8xx

2019-06-13 Thread Christophe Leroy
Only 8xx selects CPM1 and related CONFIG options are already
in platforms/8xx/Kconfig

Move the related C files to platforms/8xx/.

Signed-off-by: Christophe Leroy 
---
 v3: cpm_gpio is also used by CPM2, so it has to remain in sysdev for now ; no 
change to other patches of the series.
 v2: added several patches in the series to clean up the microcode patching.

 arch/powerpc/platforms/8xx/Makefile | 2 ++
 arch/powerpc/{sysdev => platforms/8xx}/cpm1.c   | 0
 arch/powerpc/{sysdev => platforms/8xx}/micropatch.c | 0
 arch/powerpc/sysdev/Makefile| 2 --
 4 files changed, 2 insertions(+), 2 deletions(-)
 rename arch/powerpc/{sysdev => platforms/8xx}/cpm1.c (100%)
 rename arch/powerpc/{sysdev => platforms/8xx}/micropatch.c (100%)

diff --git a/arch/powerpc/platforms/8xx/Makefile 
b/arch/powerpc/platforms/8xx/Makefile
index 708ab099e886..27a7c6f828e0 100644
--- a/arch/powerpc/platforms/8xx/Makefile
+++ b/arch/powerpc/platforms/8xx/Makefile
@@ -3,6 +3,8 @@
 # Makefile for the PowerPC 8xx linux kernel.
 #
 obj-y  += m8xx_setup.o machine_check.o pic.o
+obj-$(CONFIG_CPM1) += cpm1.o
+obj-$(CONFIG_UCODE_PATCH)  += micropatch.o
 obj-$(CONFIG_MPC885ADS)   += mpc885ads_setup.o
 obj-$(CONFIG_MPC86XADS)   += mpc86xads_setup.o
 obj-$(CONFIG_PPC_EP88XC)  += ep88xc.o
diff --git a/arch/powerpc/sysdev/cpm1.c b/arch/powerpc/platforms/8xx/cpm1.c
similarity index 100%
rename from arch/powerpc/sysdev/cpm1.c
rename to arch/powerpc/platforms/8xx/cpm1.c
diff --git a/arch/powerpc/sysdev/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
similarity index 100%
rename from arch/powerpc/sysdev/micropatch.c
rename to arch/powerpc/platforms/8xx/micropatch.c
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index aaf23283ba0c..9d73dfddf060 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -37,12 +37,10 @@ obj-$(CONFIG_XILINX_PCI)+= xilinx_pci.o
 obj-$(CONFIG_OF_RTC)   += of_rtc.o
 
 obj-$(CONFIG_CPM)  += cpm_common.o
-obj-$(CONFIG_CPM1) += cpm1.o
 obj-$(CONFIG_CPM2) += cpm2.o cpm2_pic.o cpm_gpio.o
 obj-$(CONFIG_8xx_GPIO) += cpm_gpio.o
 obj-$(CONFIG_QUICC_ENGINE) += cpm_common.o
 obj-$(CONFIG_PPC_DCR)  += dcr.o
-obj-$(CONFIG_UCODE_PATCH)  += micropatch.o
 
 obj-$(CONFIG_PPC_MPC512x)  += mpc5xxx_clocks.o
 obj-$(CONFIG_PPC_MPC52xx)  += mpc5xxx_clocks.o
-- 
2.13.3



[PATCH v3 02/10] powerpc/8xx: drop verify_patch()

2019-06-13 Thread Christophe Leroy
verify_patch() has been opted out since many years, and
the comment suggests it doesn't work. So drop it.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 40 -
 1 file changed, 40 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 33a9042fca80..7bbaf9914f32 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -707,43 +707,3 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
 #endif /* some variation of the I2C/SPI patch was selected */
 }
-
-/*
- *  Take this entire routine out, since no one calls it and its
- * logic is suspect.
- */
-
-#if 0
-void
-verify_patch(volatile immap_t *immr)
-{
-   volatile uint   *dp;
-   volatile cpm8xx_t   *commproc;
-   int i;
-
-   commproc = (cpm8xx_t *)&immr->im_cpm;
-
-   printk("cp_rccr %x\n", commproc->cp_rccr);
-   commproc->cp_rccr = 0;
-
-   dp = (uint *)(commproc->cp_dpmem);
-   for (i=0; i<(sizeof(patch_2000)/4); i++)
-   if (*dp++ != patch_2000[i]) {
-   printk("patch_2000 bad at %d\n", i);
-   dp--;
-   printk("found 0x%X, wanted 0x%X\n", *dp, patch_2000[i]);
-   break;
-   }
-
-   dp = (uint *)&(commproc->cp_dpmem[0x0f00]);
-   for (i=0; i<(sizeof(patch_2f00)/4); i++)
-   if (*dp++ != patch_2f00[i]) {
-   printk("patch_2f00 bad at %d\n", i);
-   dp--;
-   printk("found 0x%X, wanted 0x%X\n", *dp, patch_2f00[i]);
-   break;
-   }
-
-   commproc->cp_rccr = 0x0009;
-}
-#endif
-- 
2.13.3



Re: [PATCH 2/2] powerpc: expose secure variables via sysfs

2019-06-13 Thread Greg Kroah-Hartman
On Thu, Jun 13, 2019 at 04:50:27PM -0400, Nayna Jain wrote:
> As part of PowerNV secure boot support, OS verification keys are stored
> and controlled by OPAL as secure variables. These need to be exposed to
> the userspace so that sysadmins can perform key management tasks.
> 
> This patch adds the support to expose secure variables via a sysfs
> interface It reuses the the existing efi defined hooks and backend in
> order to maintain the compatibility with the userspace tools.
> 
> Though it reuses a great deal of efi, POWER platforms do not use EFI.
> A new config, POWER_SECVAR_SYSFS, is defined to enable this new sysfs
> interface.
> 
> Signed-off-by: Nayna Jain 
> ---
>  arch/powerpc/Kconfig |   2 +
>  drivers/firmware/Makefile|   1 +
>  drivers/firmware/efi/efivars.c   |   2 +-
>  drivers/firmware/powerpc/Kconfig |  12 +
>  drivers/firmware/powerpc/Makefile|   3 +
>  drivers/firmware/powerpc/efi_error.c |  46 
>  drivers/firmware/powerpc/secvar.c| 326 +++
>  7 files changed, 391 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/firmware/powerpc/Kconfig
>  create mode 100644 drivers/firmware/powerpc/Makefile
>  create mode 100644 drivers/firmware/powerpc/efi_error.c
>  create mode 100644 drivers/firmware/powerpc/secvar.c

If you add/remove/modify sysfs files, you also need to update the
relevant Documentation/ABI/ entry as well.  Please add something there
to describe your new files when you resend the next version of this
patch series.

> diff --git a/drivers/firmware/powerpc/Kconfig 
> b/drivers/firmware/powerpc/Kconfig
> new file mode 100644
> index ..e0303fc517d5
> --- /dev/null
> +++ b/drivers/firmware/powerpc/Kconfig
> @@ -0,0 +1,12 @@
> +config POWER_SECVAR_SYSFS
> + tristate "Enable sysfs interface for POWER secure variables"
> + default n

default is always n, no need to list it.

> --- /dev/null
> +++ b/drivers/firmware/powerpc/efi_error.c
> @@ -0,0 +1,46 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2019 IBM Corporation
> + * Author: Nayna Jain 
> + *
> + * efi_error.c
> + *  - Error codes as understood by efi based tools
> + *  Taken from drivers/firmware/efi/efi.c

Why not just export the symbol from the original file instead of
duplicating it here?

> +static int convert_buffer_to_efi_guid(u8 *buffer, efi_guid_t *guid)
> +{
> + u32 *a1;
> + u16 *a2;
> + u16 *a3;
> +
> + a1 = kzalloc(4, GFP_KERNEL);

No error checking in this function for memory issues at all?

> + memcpy(a1, buffer, 4);
> + *a1 = be32_to_cpu(*a1);
> +
> + a2 = kzalloc(2, GFP_KERNEL);
> + memcpy(a2, buffer+4, 2);
> + *a2 = be16_to_cpu(*a2);
> +
> + a3 = kzalloc(2, GFP_KERNEL);
> + memcpy(a3, buffer+6, 2);
> + *a3 = be16_to_cpu(*a3);
> +
> + *guid = EFI_GUID(*a1, *a2, *a3, *(buffer + 8),
> + *(buffer + 9),
> + *(buffer + 10),
> + *(buffer + 11),
> + *(buffer + 12),
> + *(buffer + 13),
> + *(buffer + 14),
> + *(buffer + 15));
> +
> + kfree(a1);
> + kfree(a2);
> + kfree(a3);
> + return 0;
> +}
> +static efi_status_t powerpc_get_next_variable(unsigned long *name_size,
> +   efi_char16_t *name,
> +   efi_guid_t *vendor)
> +{
> + int rc;
> + u8 *key;
> + int namesize;
> + unsigned long keylen;
> + unsigned long keysize = 1024;
> + unsigned long *mdsize;
> + u8 *mdata = NULL;
> + efi_guid_t guid;
> +
> + if (ucs2_strnlen(name, 1024) > 0) {
> + createkey(name, &key, &keylen);
> + } else {
> + keylen = 0;
> + key = kzalloc(1024, GFP_KERNEL);
> + }
> +
> + pr_info("%s: powerpc get next variable, key is %s\n", __func__, key);

Don't put debugging info like this in the kernel log of everyone :(

> +
> + rc = opal_get_next_variable(key, &keylen, keysize);
> + if (rc) {
> + kfree(key);
> + return opal_to_efi_status(rc);
> + }
> +
> + mdsize = kzalloc(sizeof(unsigned long), GFP_KERNEL);

No error checking?

> + rc = opal_get_variable_size(key, keylen, mdsize, NULL);
> + if (rc)
> + goto out;
> +
> + if (*mdsize <= 0)
> + goto out;
> +
> + mdata = kzalloc(*mdsize, GFP_KERNEL);
> +
> + rc = opal_get_variable(key, keylen, mdata, mdsize, NULL, NULL);
> + if (rc)
> + goto out;
> +
> + if (*mdsize > 0) {
> + namesize = *mdsize - sizeof(efi_guid_t) - sizeof(u32);
> + if (namesize > 0) {
> + memset(&guid, 0, sizeof(efi_guid_t));
> + convert_buffer_to_efi_guid(mdata + namesize, &guid);
> + memcpy(vendor, &guid, sizeof(efi_guid_t));
> + memset(name,

Re: [PATCH 3/3] powerpc/pseries/mobility: rebuild cacheinfo hierarchy post-migration

2019-06-13 Thread Gautham R Shenoy
On Wed, Jun 12, 2019 at 10:17 AM Nathan Lynch  wrote:
>
> It's common for the platform to replace the cache device nodes after a
> migration. Since the cacheinfo code is never informed about this, it
> never drops its references to the source system's cache nodes, causing
> it to wind up in an inconsistent state resulting in warnings and oopses
> as soon as CPU online/offline occurs after the migration, e.g.
>
> cache for /cpus/l3-cache@3113(Unified) refers to cache for 
> /cpus/l2-cache@200d(Unified)
> WARNING: CPU: 15 PID: 86 at arch/powerpc/kernel/cacheinfo.c:176 
> release_cache+0x1bc/0x1d0
> [...]
> NIP [c002d9bc] release_cache+0x1bc/0x1d0
> LR [c002d9b8] release_cache+0x1b8/0x1d0
> Call Trace:
> [c001fc99fa70] [c002d9b8] release_cache+0x1b8/0x1d0 (unreliable)
> [c001fc99fb10] [c002ebf4] cacheinfo_cpu_offline+0x1c4/0x2c0
> [c001fc99fbe0] [c002ae58] unregister_cpu_online+0x1b8/0x260
> [c001fc99fc40] [c0165a64] cpuhp_invoke_callback+0x114/0xf40
> [c001fc99fcd0] [c0167450] cpuhp_thread_fun+0x270/0x310
> [c001fc99fd40] [c01a8bb8] smpboot_thread_fn+0x2c8/0x390
> [c001fc99fdb0] [c01a1cd8] kthread+0x1b8/0x1c0
> [c001fc99fe20] [c000c2d4] ret_from_kernel_thread+0x5c/0x68
>
> Using device tree notifiers won't work since we want to rebuild the
> hierarchy only after all the removals and additions have occurred and
> the device tree is in a consistent state. Call cacheinfo_teardown()
> before processing device tree updates, and rebuild the hierarchy
> afterward.
>
> Fixes: 410bccf97881 ("powerpc/pseries: Partition migration in the kernel")
> Signed-off-by: Nathan Lynch 

Reviewed-by: Gautham R. Shenoy 

> ---
>  arch/powerpc/platforms/pseries/mobility.c | 10 ++
>  1 file changed, 10 insertions(+)
>
> diff --git a/arch/powerpc/platforms/pseries/mobility.c 
> b/arch/powerpc/platforms/pseries/mobility.c
> index edc1ec408589..b8c8096907d4 100644
> --- a/arch/powerpc/platforms/pseries/mobility.c
> +++ b/arch/powerpc/platforms/pseries/mobility.c
> @@ -23,6 +23,7 @@
>  #include 
>  #include 
>  #include "pseries.h"
> +#include "../../kernel/cacheinfo.h"
>
>  static struct kobject *mobility_kobj;
>
> @@ -345,11 +346,20 @@ void post_mobility_fixup(void)
>  */
> cpus_read_lock();
>
> +   /*
> +* It's common for the destination firmware to replace cache
> +* nodes.  Release all of the cacheinfo hierarchy's references
> +* before updating the device tree.
> +*/
> +   cacheinfo_teardown();
> +
> rc = pseries_devicetree_update(MIGRATION_SCOPE);
> if (rc)
> printk(KERN_ERR "Post-mobility device tree update "
> "failed: %d\n", rc);
>
> +   cacheinfo_rebuild();
> +
> cpus_read_unlock();
>
> /* Possibly switch to a new RFI flush type */
> --
> 2.20.1
>


-- 
Thanks and Regards
gautham.


Re: [PATCH 1/3] powerpc/cacheinfo: add cacheinfo_teardown, cacheinfo_rebuild

2019-06-13 Thread Gautham R Shenoy
On Wed, Jun 12, 2019 at 10:15 AM Nathan Lynch  wrote:
>
> Allow external callers to force the cacheinfo code to release all its
> references to cache nodes, e.g. before processing device tree updates
> post-migration, and to rebuild the hierarchy afterward.
>
> CPU online/offline must be blocked by callers; enforce this.
>
> Fixes: 410bccf97881 ("powerpc/pseries: Partition migration in the kernel")
> Signed-off-by: Nathan Lynch 

Reviewed-by: Gautham R. Shenoy 
> ---
>  arch/powerpc/kernel/cacheinfo.c | 21 +
>  arch/powerpc/kernel/cacheinfo.h |  4 
>  2 files changed, 25 insertions(+)
>
> diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c
> index 862e2890bd3d..42c559efe060 100644
> --- a/arch/powerpc/kernel/cacheinfo.c
> +++ b/arch/powerpc/kernel/cacheinfo.c
> @@ -896,4 +896,25 @@ void cacheinfo_cpu_offline(unsigned int cpu_id)
> if (cache)
> cache_cpu_clear(cache, cpu_id);
>  }
> +
> +void cacheinfo_teardown(void)
> +{
> +   unsigned int cpu;
> +
> +   lockdep_assert_cpus_held();
> +
> +   for_each_online_cpu(cpu)
> +   cacheinfo_cpu_offline(cpu);
> +}
> +
> +void cacheinfo_rebuild(void)
> +{
> +   unsigned int cpu;
> +
> +   lockdep_assert_cpus_held();
> +
> +   for_each_online_cpu(cpu)
> +   cacheinfo_cpu_online(cpu);
> +}
> +
>  #endif /* (CONFIG_PPC_PSERIES && CONFIG_SUSPEND) || CONFIG_HOTPLUG_CPU */
> diff --git a/arch/powerpc/kernel/cacheinfo.h b/arch/powerpc/kernel/cacheinfo.h
> index 955f5e999f1b..52bd3fc6642d 100644
> --- a/arch/powerpc/kernel/cacheinfo.h
> +++ b/arch/powerpc/kernel/cacheinfo.h
> @@ -6,4 +6,8 @@
>  extern void cacheinfo_cpu_online(unsigned int cpu_id);
>  extern void cacheinfo_cpu_offline(unsigned int cpu_id);
>
> +/* Allow migration/suspend to tear down and rebuild the hierarchy. */
> +extern void cacheinfo_teardown(void);
> +extern void cacheinfo_rebuild(void);
> +
>  #endif /* _PPC_CACHEINFO_H */
> --
> 2.20.1
>


-- 
Thanks and Regards
gautham.


[PATCH v2] powerpc/mm: Implement STRICT_MODULE_RWX

2019-06-13 Thread Russell Currey
Strict module RWX is just like strict kernel RWX, but for modules - so
loadable modules aren't marked both writable and executable at the same
time.  This is handled by the generic code in kernel/module.c, and
simply requires the architecture to implement the set_memory() set of
functions, declared with ARCH_HAS_SET_MEMORY.

There's nothing other than these functions required to turn
ARCH_HAS_STRICT_MODULE_RWX on, so turn that on too.

With STRICT_MODULE_RWX enabled, there are as many W+X pages at runtime
as there are with CONFIG_MODULES=n (none), so in Russel's testing it works
well on both Hash and Radix book3s64.

There's a TODO in the code for also applying the page permission changes
to the backing pages in the linear mapping: this is pretty simple for
Radix and (seemingly) a lot harder for Hash, so I've left it for now
since there's still a notable security benefit for the patch as-is.

Technically can be enabled without STRICT_KERNEL_RWX, but
that doesn't gets you a whole lot, so we should leave it off by default
until we can get STRICT_KERNEL_RWX to the point where it's enabled by
default.

Signed-off-by: Russell Currey 
Signed-off-by: Christophe Leroy 
---
Changes from v1 (sent by Christophe):
 - return if VM_FLUSH_RESET_PERMS is set

 arch/powerpc/Kconfig  |  2 +
 arch/powerpc/include/asm/set_memory.h | 32 ++
 arch/powerpc/mm/Makefile  |  2 +-
 arch/powerpc/mm/pageattr.c| 85 +++
 4 files changed, 120 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/include/asm/set_memory.h
 create mode 100644 arch/powerpc/mm/pageattr.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 8c1c636308c8..3d98240ce965 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -131,7 +131,9 @@ config PPC
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_MEMBARRIER_CALLBACKS
select ARCH_HAS_SCALED_CPUTIME  if VIRT_CPU_ACCOUNTING_NATIVE 
&& PPC64
+   select ARCH_HAS_SET_MEMORY
select ARCH_HAS_STRICT_KERNEL_RWX   if ((PPC_BOOK3S_64 || PPC32) && 
!RELOCATABLE && !HIBERNATION)
+   select ARCH_HAS_STRICT_MODULE_RWX   if PPC_BOOK3S_64 || PPC32
select ARCH_HAS_TICK_BROADCAST  if GENERIC_CLOCKEVENTS_BROADCAST
select ARCH_HAS_UACCESS_FLUSHCACHE  if PPC64
select ARCH_HAS_UBSAN_SANITIZE_ALL
diff --git a/arch/powerpc/include/asm/set_memory.h 
b/arch/powerpc/include/asm/set_memory.h
new file mode 100644
index ..4b9683f3b3dd
--- /dev/null
+++ b/arch/powerpc/include/asm/set_memory.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+#ifndef _ASM_POWERPC_SET_MEMORY_H
+#define _ASM_POWERPC_SET_MEMORY_H
+
+#define SET_MEMORY_RO  1
+#define SET_MEMORY_RW  2
+#define SET_MEMORY_NX  3
+#define SET_MEMORY_X   4
+
+int change_memory(unsigned long addr, int numpages, int action);
+
+static inline int set_memory_ro(unsigned long addr, int numpages)
+{
+   return change_memory(addr, numpages, SET_MEMORY_RO);
+}
+
+static inline int set_memory_rw(unsigned long addr, int numpages)
+{
+   return change_memory(addr, numpages, SET_MEMORY_RW);
+}
+
+static inline int set_memory_nx(unsigned long addr, int numpages)
+{
+   return change_memory(addr, numpages, SET_MEMORY_NX);
+}
+
+static inline int set_memory_x(unsigned long addr, int numpages)
+{
+   return change_memory(addr, numpages, SET_MEMORY_X);
+}
+
+#endif
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index 0f499db315d6..b683d1c311b3 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -7,7 +7,7 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC)
 
 obj-y  := fault.o mem.o pgtable.o mmap.o \
   init_$(BITS).o pgtable_$(BITS).o \
-  pgtable-frag.o \
+  pgtable-frag.o pageattr.o \
   init-common.o mmu_context.o drmem.o
 obj-$(CONFIG_PPC_MMU_NOHASH)   += nohash/
 obj-$(CONFIG_PPC_BOOK3S_32)+= book3s32/
diff --git a/arch/powerpc/mm/pageattr.c b/arch/powerpc/mm/pageattr.c
new file mode 100644
index ..41baf92f632b
--- /dev/null
+++ b/arch/powerpc/mm/pageattr.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Page attribute and set_memory routines
+ *
+ * Derived from the arm64 implementation.
+ *
+ * Author: Russell Currey 
+ *
+ * Copyright 2019, IBM Corporation.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+static int change_page_ro(pte_t *ptep, pgtable_t token, unsigned long addr, 
void *data)
+{
+   set_pte_at(&init_mm, addr, ptep, pte_wrprotect(READ_ONCE(*ptep)));
+   return 0;
+}
+
+static int change_page_rw(pte_t *ptep, pgtable_t token, unsigned long addr, 
void *data)
+{
+   set_pte_at(&init_mm, addr, ptep, pte_mkwrite(READ_ONCE(*ptep)));
+   return 0;
+}
+
+static int change_page_nx(pte_t *ptep, pgtable_t t

Re: [PATCH] mm: Generalize and rename notify_page_fault() as kprobe_page_fault()

2019-06-13 Thread Anshuman Khandual


On 06/14/2019 01:34 AM, Andrew Morton wrote:
> On Thu, 13 Jun 2019 15:37:24 +0530 Anshuman Khandual 
>  wrote:
> 
>> Architectures which support kprobes have very similar boilerplate around
>> calling kprobe_fault_handler(). Use a helper function in kprobes.h to unify
>> them, based on the x86 code.
>>
>> This changes the behaviour for other architectures when preemption is
>> enabled. Previously, they would have disabled preemption while calling the
>> kprobe handler. However, preemption would be disabled if this fault was
>> due to a kprobe, so we know the fault was not due to a kprobe handler and
>> can simply return failure.
>>
>> This behaviour was introduced in the commit a980c0ef9f6d ("x86/kprobes:
>> Refactor kprobes_fault() like kprobe_exceptions_notify()")
>>
>> ...
>>
>> --- a/arch/arm/mm/fault.c
>> +++ b/arch/arm/mm/fault.c
>> @@ -30,28 +30,6 @@
>>  
>>  #ifdef CONFIG_MMU
>>  
>> -#ifdef CONFIG_KPROBES
>> -static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr)
> 
> Some architectures make this `static inline'.  Others make it
> `nokprobes_inline', others make it `static inline __kprobes'.  The
> latter seems weird - why try to put an inline function into
> .kprobes.text?
> 
> So..  what's the best thing to do here?  You chose `static
> nokprobe_inline' - is that the best approach, if so why?  Does
> kprobe_page_fault() actually need to be inlined?

Matthew had suggested that (nokprobe_-inline) based on current x86
implementation. But every architecture already had an inlined definition
which I did not want to deviate from.

> 
> Also, some architectures had notify_page_fault returning int, others
> bool.  You chose bool and that seems appropriate and all callers are OK
> with that.

I would believe so. No one has complained yet :)


Re: [PATCH kernel] powerpc/pci/of: Parse unassigned resources

2019-06-13 Thread Alexey Kardashevskiy



On 14/06/2019 12:59, Alexey Kardashevskiy wrote:
> The pseries platform uses the PCI_PROBE_DEVTREE method of PCI probing
> which is basically reading "assigned-addresses" of every PCI device.
> However if the property is missing or zero sized, then there is
> no fallback of any kind and the PCI resources remain undiscovered, i.e.
> pdev->resource[] array is empty.
> 
> This adds a fallback which parses the "reg" property in pretty much same
> way except it marks resources as "unset" which later makes Linux assign
> those resources with proper addresses.
> 
> Signed-off-by: Alexey Kardashevskiy 
> ---
> 
> This is an attempts to boot linux directly under QEMU without slof/rtas;
> the aim is to use petitboot instead and let the guest kernel configure
> devices.
> 
> QEMU does not allocate resources, it creates correct "reg" and zero length
> "assigned-addresses" (which is probably a bug on its own) which is
> normally populated by SLOF later but not during this exercise.
> 
> ---
>  arch/powerpc/kernel/pci_of_scan.c | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/powerpc/kernel/pci_of_scan.c 
> b/arch/powerpc/kernel/pci_of_scan.c
> index 64ad92016b63..cfe6ec3c6aaf 100644
> --- a/arch/powerpc/kernel/pci_of_scan.c
> +++ b/arch/powerpc/kernel/pci_of_scan.c
> @@ -82,10 +82,18 @@ static void of_pci_parse_addrs(struct device_node *node, 
> struct pci_dev *dev)
>   const __be32 *addrs;
>   u32 i;
>   int proplen;
> + bool unset = false;
>  
>   addrs = of_get_property(node, "assigned-addresses", &proplen);
>   if (!addrs)
>   return;


Ah. Of course, these 2 lines above should go, my bad. I'll repost if
there are no other (and bigger) problems with this.



> + if (!addrs || !proplen) {
> + addrs = of_get_property(node, "reg", &proplen);
> + if (!addrs || !proplen)
> + return;
> + unset = true;
> + }
> +
>   pr_debug("parse addresses (%d bytes) @ %p\n", proplen, addrs);
>   for (; proplen >= 20; proplen -= 20, addrs += 5) {
>   flags = pci_parse_of_flags(of_read_number(addrs, 1), 0);
> @@ -110,6 +118,8 @@ static void of_pci_parse_addrs(struct device_node *node, 
> struct pci_dev *dev)
>   continue;
>   }
>   res->flags = flags;
> + if (unset)
> + res->flags |= IORESOURCE_UNSET;
>   res->name = pci_name(dev);
>   region.start = base;
>   region.end = base + size - 1;
> 

-- 
Alexey


[PATCH kernel] powerpc/pci/of: Parse unassigned resources

2019-06-13 Thread Alexey Kardashevskiy
The pseries platform uses the PCI_PROBE_DEVTREE method of PCI probing
which is basically reading "assigned-addresses" of every PCI device.
However if the property is missing or zero sized, then there is
no fallback of any kind and the PCI resources remain undiscovered, i.e.
pdev->resource[] array is empty.

This adds a fallback which parses the "reg" property in pretty much same
way except it marks resources as "unset" which later makes Linux assign
those resources with proper addresses.

Signed-off-by: Alexey Kardashevskiy 
---

This is an attempts to boot linux directly under QEMU without slof/rtas;
the aim is to use petitboot instead and let the guest kernel configure
devices.

QEMU does not allocate resources, it creates correct "reg" and zero length
"assigned-addresses" (which is probably a bug on its own) which is
normally populated by SLOF later but not during this exercise.

---
 arch/powerpc/kernel/pci_of_scan.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/kernel/pci_of_scan.c 
b/arch/powerpc/kernel/pci_of_scan.c
index 64ad92016b63..cfe6ec3c6aaf 100644
--- a/arch/powerpc/kernel/pci_of_scan.c
+++ b/arch/powerpc/kernel/pci_of_scan.c
@@ -82,10 +82,18 @@ static void of_pci_parse_addrs(struct device_node *node, 
struct pci_dev *dev)
const __be32 *addrs;
u32 i;
int proplen;
+   bool unset = false;
 
addrs = of_get_property(node, "assigned-addresses", &proplen);
if (!addrs)
return;
+   if (!addrs || !proplen) {
+   addrs = of_get_property(node, "reg", &proplen);
+   if (!addrs || !proplen)
+   return;
+   unset = true;
+   }
+
pr_debug("parse addresses (%d bytes) @ %p\n", proplen, addrs);
for (; proplen >= 20; proplen -= 20, addrs += 5) {
flags = pci_parse_of_flags(of_read_number(addrs, 1), 0);
@@ -110,6 +118,8 @@ static void of_pci_parse_addrs(struct device_node *node, 
struct pci_dev *dev)
continue;
}
res->flags = flags;
+   if (unset)
+   res->flags |= IORESOURCE_UNSET;
res->name = pci_name(dev);
region.start = base;
region.end = base + size - 1;
-- 
2.17.1



[PATCH 01/14] ABI: fix some syntax issues at the ABI database

2019-06-13 Thread Mauro Carvalho Chehab
From: Mauro Carvalho Chehab 

On those three files, the ABI representation described at
README are violated.

- at sysfs-bus-iio-proximity-as3935:
a ':' character is missing after "What"

- at sysfs-class-devfreq:
there's a typo at Description

- at sysfs-class-cxl, it is using the ":" character at a
file preamble, causing it to be misinterpreted as a
tag.

- On the other files, instead of "What", they use "Where".

Signed-off-by: Mauro Carvalho Chehab 
Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/ABI/testing/pstore  |  2 +-
 .../sysfs-bus-event_source-devices-format |  2 +-
 .../ABI/testing/sysfs-bus-i2c-devices-hm6352  |  6 ++---
 .../ABI/testing/sysfs-bus-iio-distance-srf08  |  4 ++--
 .../testing/sysfs-bus-iio-proximity-as3935|  4 ++--
 .../ABI/testing/sysfs-bus-pci-devices-cciss   | 22 +--
 .../testing/sysfs-bus-usb-devices-usbsevseg   | 12 +-
 Documentation/ABI/testing/sysfs-class-cxl |  6 ++---
 Documentation/ABI/testing/sysfs-class-devfreq |  2 +-
 .../ABI/testing/sysfs-class-powercap  |  2 +-
 Documentation/ABI/testing/sysfs-kernel-fscaps |  2 +-
 .../ABI/testing/sysfs-kernel-vmcoreinfo   |  2 +-
 12 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/Documentation/ABI/testing/pstore b/Documentation/ABI/testing/pstore
index 5fca9f5e10a3..8d6e48f4e8ef 100644
--- a/Documentation/ABI/testing/pstore
+++ b/Documentation/ABI/testing/pstore
@@ -1,4 +1,4 @@
-Where: /sys/fs/pstore/... (or /dev/pstore/...)
+What:  /sys/fs/pstore/... (or /dev/pstore/...)
 Date:  March 2011
 Kernel Version: 2.6.39
 Contact:   tony.l...@intel.com
diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-format 
b/Documentation/ABI/testing/sysfs-bus-event_source-devices-format
index 77f47ff5ee02..b6f8748e0200 100644
--- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-format
+++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-format
@@ -1,4 +1,4 @@
-Where: /sys/bus/event_source/devices//format
+What:  /sys/bus/event_source/devices//format
 Date:  January 2012
 Kernel Version: 3.3
 Contact:   Jiri Olsa 
diff --git a/Documentation/ABI/testing/sysfs-bus-i2c-devices-hm6352 
b/Documentation/ABI/testing/sysfs-bus-i2c-devices-hm6352
index feb2e4a87075..29bd447e50a0 100644
--- a/Documentation/ABI/testing/sysfs-bus-i2c-devices-hm6352
+++ b/Documentation/ABI/testing/sysfs-bus-i2c-devices-hm6352
@@ -1,18 +1,18 @@
-Where: /sys/bus/i2c/devices/.../heading0_input
+What:  /sys/bus/i2c/devices/.../heading0_input
 Date:  April 2010
 Kernel Version: 2.6.36?
 Contact:   alan@intel.com
 Description:   Reports the current heading from the compass as a floating
point value in degrees.
 
-Where: /sys/bus/i2c/devices/.../power_state
+What:  /sys/bus/i2c/devices/.../power_state
 Date:  April 2010
 Kernel Version: 2.6.36?
 Contact:   alan@intel.com
 Description:   Sets the power state of the device. 0 sets the device into
sleep mode, 1 wakes it up.
 
-Where: /sys/bus/i2c/devices/.../calibration
+What:  /sys/bus/i2c/devices/.../calibration
 Date:  April 2010
 Kernel Version: 2.6.36?
 Contact:   alan@intel.com
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-distance-srf08 
b/Documentation/ABI/testing/sysfs-bus-iio-distance-srf08
index 0a1ca1487fa9..a133fd8d081a 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-distance-srf08
+++ b/Documentation/ABI/testing/sysfs-bus-iio-distance-srf08
@@ -1,4 +1,4 @@
-What   /sys/bus/iio/devices/iio:deviceX/sensor_sensitivity
+What:  /sys/bus/iio/devices/iio:deviceX/sensor_sensitivity
 Date:  January 2017
 KernelVersion: 4.11
 Contact:   linux-...@vger.kernel.org
@@ -6,7 +6,7 @@ Description:
Show or set the gain boost of the amp, from 0-31 range.
default 31
 
-What   /sys/bus/iio/devices/iio:deviceX/sensor_max_range
+What:  /sys/bus/iio/devices/iio:deviceX/sensor_max_range
 Date:  January 2017
 KernelVersion: 4.11
 Contact:   linux-...@vger.kernel.org
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-proximity-as3935 
b/Documentation/ABI/testing/sysfs-bus-iio-proximity-as3935
index 9a17ab5036a4..c59d95346341 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-proximity-as3935
+++ b/Documentation/ABI/testing/sysfs-bus-iio-proximity-as3935
@@ -1,4 +1,4 @@
-What   /sys/bus/iio/devices/iio:deviceX/in_proximity_input
+What:  /sys/bus/iio/devices/iio:deviceX/in_proximity_input
 Date:  March 2014
 KernelVersion: 3.15
 Contact:   Matt Ranostay 
@@ -6,7 +6,7 @@ Description:
Get the current distance in meters of storm (1km steps)
1000-4 = distance in meters
 
-What   /sys/bus/iio/devices/iio:deviceX/sensor_sensitivity
+What:  /sy

[PATCH 00/14] Add support to generate ABI documentation at admin-guide

2019-06-13 Thread Mauro Carvalho Chehab
Greg,

As promised, I'm resending the patch series with adds the Kernel ABI to
Documentation/admin-guide.

Those patches are basically the version 3 patchset I sent back in 2017,
rebased on the top of linux-next (next-20190613), and with some fixes
in order for it to work.

- The 4 initial patches to fix some ABI descriptions that are violating 
  the syntax described at Documentation/ABI/README;

- The next 6 patches are the ones originally written in 2017 with a
  script with parses the ABI files;

- The 11th patch is a new one: it relaxes a little bit the parser in 
  order to parse file headers that contains colons on it;

- The 12th patch adds the new script to the documentation build
  system, together with a new python Sphinx extension with calls it;

- The 13th patch fixes the python script when running with newer
  Sphinx versions (1.7 and upper);

- The final patch fixes an UTF-8 trouble. I noticed it only with Sphinx
  1.4, but it could affect other versions too. So, I ended by changing
  the UTF-8 encoding logit to work version-independent, just like
  what happens with kerneldoc.py extension.

Mauro Carvalho Chehab (14):
  ABI: fix some syntax issues at the ABI database
  ABI: sysfs-driver-hid: the "What" field doesn't parse fine
  ABI: sysfs-class-uwb_rc: remove a duplicated incomplete entry
  ABI: better identificate tables
  scripts: add an script to parse the ABI files
  scripts/get_abi.pl: parse files with text at beginning
  scripts/get_abi.pl: avoid use literal blocks when not needed
  scripts/get_abi.pl: split label naming from xref logic
  scripts/get_abi.pl: add support for searching for ABI symbols
  scripts/get_abi.pl: represent what in tables
  scripts/get_abi.pl: fix parse issues with some files
  doc-rst: add ABI documentation to the admin-guide book
  sphinx/kernel_abi.py: make it compatible with Sphinx 1.7+
  docs: sphinx/kernel_abi.py: fix UTF-8 support

 .../ABI/obsolete/sysfs-driver-hid-roccat-pyra |   2 +-
 Documentation/ABI/testing/pstore  |   2 +-
 .../sysfs-bus-event_source-devices-format |   2 +-
 .../ABI/testing/sysfs-bus-i2c-devices-hm6352  |   6 +-
 .../ABI/testing/sysfs-bus-iio-distance-srf08  |   4 +-
 .../testing/sysfs-bus-iio-proximity-as3935|   4 +-
 .../ABI/testing/sysfs-bus-pci-devices-cciss   |  22 +-
 .../testing/sysfs-bus-usb-devices-usbsevseg   |  12 +-
 .../sysfs-class-backlight-driver-lm3533   |   6 +-
 Documentation/ABI/testing/sysfs-class-cxl |   6 +-
 Documentation/ABI/testing/sysfs-class-devfreq |   2 +-
 .../ABI/testing/sysfs-class-led-driver-lm3533 |   8 +-
 .../ABI/testing/sysfs-class-leds-gt683r   |   4 +-
 .../ABI/testing/sysfs-class-powercap  |   2 +-
 Documentation/ABI/testing/sysfs-class-uwb_rc  |   6 -
 Documentation/ABI/testing/sysfs-driver-hid|  12 +-
 .../ABI/testing/sysfs-driver-hid-roccat-kone  |   2 +-
 Documentation/ABI/testing/sysfs-kernel-fscaps |   2 +-
 .../ABI/testing/sysfs-kernel-vmcoreinfo   |   2 +-
 Documentation/admin-guide/abi-obsolete.rst|  10 +
 Documentation/admin-guide/abi-removed.rst |   4 +
 Documentation/admin-guide/abi-stable.rst  |  13 +
 Documentation/admin-guide/abi-testing.rst |  19 +
 Documentation/admin-guide/abi.rst |  11 +
 Documentation/admin-guide/index.rst   |   1 +
 Documentation/conf.py |   2 +-
 Documentation/sphinx/kernel_abi.py| 172 +++
 scripts/get_abi.pl| 450 ++
 28 files changed, 731 insertions(+), 57 deletions(-)
 create mode 100644 Documentation/admin-guide/abi-obsolete.rst
 create mode 100644 Documentation/admin-guide/abi-removed.rst
 create mode 100644 Documentation/admin-guide/abi-stable.rst
 create mode 100644 Documentation/admin-guide/abi-testing.rst
 create mode 100644 Documentation/admin-guide/abi.rst
 create mode 100644 Documentation/sphinx/kernel_abi.py
 create mode 100755 scripts/get_abi.pl

-- 
2.21.0




RE: [EXT] Re: [PATCH 1/3] dt-bindings: pci: layerscape-pci: add compatible strings "fsl,ls1028a-pcie"

2019-06-13 Thread Xiaowei Bao


> -Original Message-
> From: Rob Herring 
> Sent: 2019年6月14日 5:00
> To: Xiaowei Bao 
> Cc: bhelg...@google.com; robh...@kernel.org; mark.rutl...@arm.com;
> shawn...@kernel.org; Leo Li ; kis...@ti.com;
> lorenzo.pieral...@arm.com; a...@arndb.de; gre...@linuxfoundation.org;
> M.h. Lian ; Mingkai Hu ;
> Roy Zang ; kstew...@linuxfoundation.org;
> pombreda...@nexb.com; shawn@rock-chips.com;
> linux-...@vger.kernel.org; devicet...@vger.kernel.org;
> linux-ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
> linuxppc-dev@lists.ozlabs.org; Xiaowei Bao 
> Subject: [EXT] Re: [PATCH 1/3] dt-bindings: pci: layerscape-pci: add
> compatible strings "fsl,ls1028a-pcie"
> 
> Caution: EXT Email
> 
> On Wed, 15 May 2019 15:27:45 +0800, Xiaowei Bao wrote:
> > Add the PCIe compatible string for LS1028A
> >
> > Signed-off-by: Xiaowei Bao 
> > ---
> >  .../devicetree/bindings/pci/layerscape-pci.txt |1 +
> >  1 files changed, 1 insertions(+), 0 deletions(-)
> >
> 
> Reviewed-by: Rob Herring 
[Xiaowei Bao] thanks a lot for your review.


Re: [PATCH] powerpc/pseries: fix oops in hotplug memory notifier

2019-06-13 Thread Nathan Lynch
Nathan Lynch  writes:

> Tyrel Datwyler  writes:
>
>> Maybe we are ok with this behavior as I haven't dug deep enough into the 
>> memory
>> subsystem here to really understand what the memory code is updating, but it 
>> is
>> concerning that we are doing it in some cases, but not all.
>
> I hope I've made a good case above that the notifier does not do any
> useful work, and a counterpart for the v2 format isn't needed.  Do you
> agree?
>
> If so, I'll send a patch later to remove the notifier altogether. In the
> near term I would still like this minimal fix to go in.

Tyrel, ack?



Re: [PATCH v4 2/3] Documentation: dt: binding: fsl: Add 'little-endian' and update Chassis define

2019-06-13 Thread Rob Herring
On Mon, 20 May 2019 17:52:37 +0800, Ran Wang wrote:
> By default, QorIQ SoC's RCPM register block is Big Endian. But
> there are some exceptions, such as LS1088A and LS2088A, are Little
> Endian. So add this optional property to help identify them.
> 
> Actually LS2021A and other Layerscapes won't totally follow Chassis
> 2.1, so separate them from powerpc SoC.
> 
> Signed-off-by: Ran Wang 
> ---
> Change in v4:
>   - Adjust indectation of 'ls1021a, ls1012a, ls1043a, ls1046a'.
> 
> Change in v3:
>   - None.
> 
> Change in v2:
>   - None.
> 
>  Documentation/devicetree/bindings/soc/fsl/rcpm.txt |8 +++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 

Reviewed-by: Rob Herring 


Re: [PATCH 2/3] Documentation: dt: binding: fsl: Add 'little-endian' and update Chassis define

2019-06-13 Thread Rob Herring
On Fri, 17 May 2019 10:47:47 +0800, Ran Wang wrote:
> By default, QorIQ SoC's RCPM register block is Big Endian. But
> there are some exceptions, such as LS1088A and LS2088A, are Little
> Endian. So add this optional property to help identify them.
> 
> Actually LS2021A and other Layerscapes won't totally follow Chassis
> 2.1, so separate them from powerpc SoC.
> 
> Signed-off-by: Ran Wang 
> ---
>  Documentation/devicetree/bindings/soc/fsl/rcpm.txt |8 +++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 

Reviewed-by: Rob Herring 


sys_exit: NR 0 (was "sys_exit: NR -1")

2019-06-13 Thread Paul Clarke
I'm seeing another asymmetry, this one is on powerpc:
--
  perf 30179 [001] 10374622.667436: raw_syscalls:sys_enter: NR 11 
(3fffe16ef55e, [...])
ls 30179 [002] 10374622.667921:  raw_syscalls:sys_exit: NR 0 = 0
--

Syscall "11" is "execve", but is it expected that the sys_exit will report the 
ID as 0?  Is that because of the nature of "execve", to overlay the entire 
contents of the process?

This does not seem to occur on x86.

PC



Re: sys_exit: NR -1

2019-06-13 Thread Paul Clarke
On 6/13/19 4:00 PM, Paul Clarke wrote:
> On 6/12/19 1:32 AM, Naveen N. Rao wrote:
>> Paul Clarke wrote:
>>> What are the circumstances in which raw_syscalls:sys_exit reports "-1" for 
>>> the syscall ID?
>>>
>>>     perf  5375 [007] 59632.478528:   raw_syscalls:sys_enter: NR 1 (3, 
>>> 9fb888, 8, 2d83740, 1, 7)
>>>     perf  5375 [007] 59632.478532:    raw_syscalls:sys_exit: NR 1 = 8
>>>     perf  5375 [007] 59632.478538:   raw_syscalls:sys_enter: NR 15 (11, 
>>> 7ca734b0, 7ca73380, 2d83740, 1, 7)
>>>     perf  5375 [007] 59632.478539:    raw_syscalls:sys_exit: NR -1 = 8
>>>     perf  5375 [007] 59632.478543:   raw_syscalls:sys_enter: NR 16 (4, 
>>> 2401, 0, 2d83740, 1, 0)
>>>     perf  5375 [007] 59632.478551:    raw_syscalls:sys_exit: NR 16 = 0
>>
>> Which architecture?
>> For powerpc, see:
>>
>> static inline int syscall_get_nr(struct task_struct *task, struct pt_regs 
>> *regs)
>> {
>> /*
>>  * Note that we are returning an int here. That means 0x, ie.
>>  * 32-bit negative 1, will be interpreted as -1 on a 64-bit kernel.
>>  * This is important for seccomp so that compat tasks can set r0 = -1
>>  * to reject the syscall.
>>  */
>> return TRAP(regs) == 0xc00 ? regs->gpr[0] : -1;
>> }
> 
> So, that's intentional?  And has some special meaning?  (I confess I don't 
> understand what the comment is saying exactly.)
> 
> Is this documented?  Does something depend on this ABI?
> 
> To me, it just makes parsing more difficult, both by humans and machines.

I should've noted that the instance I encountered was on x86.

PC



Re: [PATCH 0/2] powerpc/bpf: DIV64 instruction fix

2019-06-13 Thread Daniel Borkmann
On 06/12/2019 08:51 PM, Naveen N. Rao wrote:
> The first patch updates DIV64 overflow tests to properly detect error 
> conditions. The second patch fixes powerpc64 JIT to generate the proper 
> unsigned division instruction for BPF_ALU64.
> 
> - Naveen
> 
> Naveen N. Rao (2):
>   bpf: fix div64 overflow tests to properly detect errors
>   powerpc/bpf: use unsigned division instruction for 64-bit operations
> 
>  arch/powerpc/include/asm/ppc-opcode.h  |  1 +
>  arch/powerpc/net/bpf_jit.h |  2 +-
>  arch/powerpc/net/bpf_jit_comp64.c  |  8 
>  .../testing/selftests/bpf/verifier/div_overflow.c  | 14 ++
>  4 files changed, 16 insertions(+), 9 deletions(-)
> 

LGTM, applied to bpf, thanks!


Re: sys_exit: NR -1

2019-06-13 Thread Paul Clarke
On 6/12/19 1:32 AM, Naveen N. Rao wrote:
> Paul Clarke wrote:
>> What are the circumstances in which raw_syscalls:sys_exit reports "-1" for 
>> the syscall ID?
>>
>>     perf  5375 [007] 59632.478528:   raw_syscalls:sys_enter: NR 1 (3, 
>> 9fb888, 8, 2d83740, 1, 7)
>>     perf  5375 [007] 59632.478532:    raw_syscalls:sys_exit: NR 1 = 8
>>     perf  5375 [007] 59632.478538:   raw_syscalls:sys_enter: NR 15 (11, 
>> 7ca734b0, 7ca73380, 2d83740, 1, 7)
>>     perf  5375 [007] 59632.478539:    raw_syscalls:sys_exit: NR -1 = 8
>>     perf  5375 [007] 59632.478543:   raw_syscalls:sys_enter: NR 16 (4, 2401, 
>> 0, 2d83740, 1, 0)
>>     perf  5375 [007] 59632.478551:    raw_syscalls:sys_exit: NR 16 = 0
> 
> Which architecture?
> For powerpc, see:
> 
> static inline int syscall_get_nr(struct task_struct *task, struct pt_regs 
> *regs)
> {
> /*
>  * Note that we are returning an int here. That means 0x, ie.
>  * 32-bit negative 1, will be interpreted as -1 on a 64-bit kernel.
>  * This is important for seccomp so that compat tasks can set r0 = -1
>  * to reject the syscall.
>  */
> return TRAP(regs) == 0xc00 ? regs->gpr[0] : -1;
> }

So, that's intentional?  And has some special meaning?  (I confess I don't 
understand what the comment is saying exactly.)

Is this documented?  Does something depend on this ABI?

To me, it just makes parsing more difficult, both by humans and machines.

PC



Re: [PATCH 1/3] dt-bindings: pci: layerscape-pci: add compatible strings "fsl,ls1028a-pcie"

2019-06-13 Thread Rob Herring
On Wed, 15 May 2019 15:27:45 +0800, Xiaowei Bao wrote:
> Add the PCIe compatible string for LS1028A
> 
> Signed-off-by: Xiaowei Bao 
> ---
>  .../devicetree/bindings/pci/layerscape-pci.txt |1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 

Reviewed-by: Rob Herring 


[PATCH 2/2] powerpc: expose secure variables via sysfs

2019-06-13 Thread Nayna Jain
As part of PowerNV secure boot support, OS verification keys are stored
and controlled by OPAL as secure variables. These need to be exposed to
the userspace so that sysadmins can perform key management tasks.

This patch adds the support to expose secure variables via a sysfs
interface It reuses the the existing efi defined hooks and backend in
order to maintain the compatibility with the userspace tools.

Though it reuses a great deal of efi, POWER platforms do not use EFI.
A new config, POWER_SECVAR_SYSFS, is defined to enable this new sysfs
interface.

Signed-off-by: Nayna Jain 
---
 arch/powerpc/Kconfig |   2 +
 drivers/firmware/Makefile|   1 +
 drivers/firmware/efi/efivars.c   |   2 +-
 drivers/firmware/powerpc/Kconfig |  12 +
 drivers/firmware/powerpc/Makefile|   3 +
 drivers/firmware/powerpc/efi_error.c |  46 
 drivers/firmware/powerpc/secvar.c| 326 +++
 7 files changed, 391 insertions(+), 1 deletion(-)
 create mode 100644 drivers/firmware/powerpc/Kconfig
 create mode 100644 drivers/firmware/powerpc/Makefile
 create mode 100644 drivers/firmware/powerpc/efi_error.c
 create mode 100644 drivers/firmware/powerpc/secvar.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 9de77bb14f54..1548dd8cf1a0 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -916,6 +916,8 @@ config PPC_SECURE_BOOT
  allows user to enable OS Secure Boot on PowerPC systems that
  have firmware secure boot support.
 
+source "drivers/firmware/powerpc/Kconfig"
+
 endmenu
 
 config ISA_DMA_API
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 3fa0b34eb72f..8cfaf7e6769d 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -33,3 +33,4 @@ obj-$(CONFIG_UEFI_CPER)   += efi/
 obj-y  += imx/
 obj-y  += tegra/
 obj-y  += xilinx/
+obj-$(CONFIG_POWER_SECVAR_SYSFS) += powerpc/
diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
index 7576450c8254..30ef53003c24 100644
--- a/drivers/firmware/efi/efivars.c
+++ b/drivers/firmware/efi/efivars.c
@@ -664,7 +664,7 @@ int efivars_sysfs_init(void)
struct kobject *parent_kobj = efivars_kobject();
int error = 0;
 
-   if (!efi_enabled(EFI_RUNTIME_SERVICES))
+   if (IS_ENABLED(CONFIG_EFI) && !efi_enabled(EFI_RUNTIME_SERVICES))
return -ENODEV;
 
/* No efivars has been registered yet */
diff --git a/drivers/firmware/powerpc/Kconfig b/drivers/firmware/powerpc/Kconfig
new file mode 100644
index ..e0303fc517d5
--- /dev/null
+++ b/drivers/firmware/powerpc/Kconfig
@@ -0,0 +1,12 @@
+config POWER_SECVAR_SYSFS
+   tristate "Enable sysfs interface for POWER secure variables"
+   default n
+   depends on PPC_SECURE_BOOT
+   select UCS2_STRING
+   help
+ POWER secure variables are managed and controlled by OPAL.
+ These variables are exposed to userspace via sysfs to allow
+ user to read/write these variables. Say Y if you have secure
+ boot enabled and want to expose variables to userspace.
+
+source "drivers/firmware/efi/Kconfig"
diff --git a/drivers/firmware/powerpc/Makefile 
b/drivers/firmware/powerpc/Makefile
new file mode 100644
index ..d5fa3b007315
--- /dev/null
+++ b/drivers/firmware/powerpc/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_POWER_SECVAR_SYSFS) += ../efi/efivars.o efi_error.o ../efi/vars.o 
secvar.o
diff --git a/drivers/firmware/powerpc/efi_error.c 
b/drivers/firmware/powerpc/efi_error.c
new file mode 100644
index ..b5cabd52e6b4
--- /dev/null
+++ b/drivers/firmware/powerpc/efi_error.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 IBM Corporation
+ * Author: Nayna Jain 
+ *
+ * efi_error.c
+ *  - Error codes as understood by efi based tools
+ *  Taken from drivers/firmware/efi/efi.c
+ */
+#include
+
+int efi_status_to_err(efi_status_t status)
+{
+   int err;
+
+   switch (status) {
+   case EFI_SUCCESS:
+   err = 0;
+   break;
+   case EFI_INVALID_PARAMETER:
+   err = -EINVAL;
+   break;
+   case EFI_OUT_OF_RESOURCES:
+   err = -ENOSPC;
+   break;
+   case EFI_DEVICE_ERROR:
+   err = -EIO;
+   break;
+   case EFI_WRITE_PROTECTED:
+   err = -EROFS;
+   break;
+   case EFI_SECURITY_VIOLATION:
+   err = -EACCES;
+   break;
+   case EFI_NOT_FOUND:
+   err = -ENOENT;
+   break;
+   case EFI_ABORTED:
+   err = -EINTR;
+   break;
+   default:
+   err = -EINVAL;
+   }
+
+   return err;
+}
diff --git a/drivers/firmware/powerpc/secvar.c 
b/drivers/firmware/powerpc/secvar.c
new file mode 100644

[PATCH 1/2] powerpc/powernv: add OPAL APIs for secure variables

2019-06-13 Thread Nayna Jain
From: Claudio Carvalho 

The X.509 certificates trusted by the platform and other information
required to secure boot the OS kernel are wrapped in secure variables,
which are controlled by OPAL. These variables are manipulated by
userspace tools using filesystem interface. This patch adds support
for the OPAL APIs required to expose variables to userspace.

OPAL_SECVAR_GET_NEXT:
For a given secure variable, it returns the name and vendor GUID
of the next variable.

OPAL_SECVAR_ENQUEUE_UPDATE:
Enqueue the supplied secure variable update so that it can be processed
by OPAL in the next boot. Variable updates cannot be be processed right
away because the variable storage is write locked at runtime.

OPAL_SECVAR_GET_SIZE:
Returns size information about the variable.

Signed-off-by: Claudio Carvalho 
Signed-off-by: Nayna Jain 
---
 arch/powerpc/include/asm/opal-api.h  |  3 +
 arch/powerpc/include/asm/opal-secvar.h   |  9 +++
 arch/powerpc/include/asm/opal.h  |  8 +++
 arch/powerpc/platforms/powernv/opal-call.c   |  3 +
 arch/powerpc/platforms/powernv/opal-secvar.c | 60 +++-
 5 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/opal-api.h 
b/arch/powerpc/include/asm/opal-api.h
index a505e669b4b6..fa3083966efc 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -213,6 +213,9 @@
 #defineOPAL_NX_COPROC_INIT 167
 #define OPAL_XIVE_GET_VP_STATE 170
 #define OPAL_SECVAR_GET 173
+#define OPAL_SECVAR_GET_SIZE174
+#define OPAL_SECVAR_GET_NEXT175
+#define OPAL_SECVAR_ENQUEUE_UPDATE  176
 #define OPAL_SECVAR_BACKEND 177
 #define OPAL_LAST  177
 
diff --git a/arch/powerpc/include/asm/opal-secvar.h 
b/arch/powerpc/include/asm/opal-secvar.h
index b677171a0368..26ebbc63dd70 100644
--- a/arch/powerpc/include/asm/opal-secvar.h
+++ b/arch/powerpc/include/asm/opal-secvar.h
@@ -20,4 +20,13 @@ extern int opal_get_variable(u8 *key, unsigned long ksize,
 
 extern int opal_variable_version(unsigned long *backend);
 
+extern int opal_get_variable_size(u8 *key, unsigned long ksize,
+ unsigned long *mdsize, unsigned long *dsize);
+
+extern int opal_get_next_variable(u8 *key, unsigned long *keylen,
+ unsigned long keysize);
+
+extern int opal_set_variable(u8 *key, unsigned long ksize, u8 *metadata,
+unsigned long mdsize, u8 *data,
+unsigned long dsize);
 #endif
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 57d2c2356eda..a6fcb59c91cc 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -399,6 +399,14 @@ extern int opal_secvar_get(uint64_t k_key, uint64_t 
k_key_len,
   uint64_t k_data, uint64_t k_data_size);
 
 extern int opal_secvar_backend(uint64_t k_backend);
+extern int opal_secvar_get_size(uint64_t k_key, uint64_t k_key_len,
+   uint64_t k_metadata_size, uint64_t k_data_size);
+extern int opal_secvar_get_next(uint64_t k_key, uint64_t k_key_len,
+   uint64_t k_key_size);
+extern int opal_secvar_enqueue_update(uint64_t k_key, uint64_t k_key_len,
+ uint64_t k_metadata,
+ uint64_t k_metadata_size,
+ uint64_t k_data, uint64_t k_data_size);
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/arch/powerpc/platforms/powernv/opal-call.c 
b/arch/powerpc/platforms/powernv/opal-call.c
index 0445980f294f..dda3a4c5bb79 100644
--- a/arch/powerpc/platforms/powernv/opal-call.c
+++ b/arch/powerpc/platforms/powernv/opal-call.c
@@ -290,3 +290,6 @@ OPAL_CALL(opal_sensor_group_enable, 
OPAL_SENSOR_GROUP_ENABLE);
 OPAL_CALL(opal_nx_coproc_init, OPAL_NX_COPROC_INIT);
 OPAL_CALL(opal_secvar_get,  OPAL_SECVAR_GET);
 OPAL_CALL(opal_secvar_backend,  OPAL_SECVAR_BACKEND);
+OPAL_CALL(opal_secvar_get_size, OPAL_SECVAR_GET_SIZE);
+OPAL_CALL(opal_secvar_get_next, OPAL_SECVAR_GET_NEXT);
+OPAL_CALL(opal_secvar_enqueue_update,   OPAL_SECVAR_ENQUEUE_UPDATE);
diff --git a/arch/powerpc/platforms/powernv/opal-secvar.c 
b/arch/powerpc/platforms/powernv/opal-secvar.c
index dba441dd5af1..afa67b87ad7a 100644
--- a/arch/powerpc/platforms/powernv/opal-secvar.c
+++ b/arch/powerpc/platforms/powernv/opal-secvar.c
@@ -30,7 +30,10 @@ static bool is_opal_secvar_supported(void)
return opal_secvar_supported;
 
if (!opal_check_token(OPAL_SECVAR_GET)
-   || !opal_check_token(OPAL_SECVAR_BACKEND)) {
+   || !opal_check_token(OPAL_SECVAR_BACKEND)
+   || !opal_check_token(OPAL_SECVAR_GET_SIZE)
+   

[PATCH 0/2] powerpc/powernv: expose secure variables to userspace

2019-06-13 Thread Nayna Jain
This patch set is part of a series that implements secure boot on PowerNV
systems[1]. The original series had been split into two patchsets:
1. powerpc: enable ima arch specific policies[2]
2. powerpc/powernv: expose secure variables to userspace, which is this
patchset.

Since there are major changes in this patchset compared to the previous
one[1], I am posting it as new series rather than v2.

As part of PowerNV secure boot support, NV OS verification keys are stored
and controlled by OPAL as secure variables. However, to allow users to
manage these keys, the secure variables need to be exposed to userspace.

OPAL provides the runtime services for the kernel to be able to access the
secure variables[3]. This patchset defines the kernel interface for the
OPAL APIs. These APIs are used by the hooks, which expose these variables
to userspace for reading/writing.

In order to reuse the existing tools, we currently use the efi hooks to
expose the secure variables via sysfs. Keeping the usability and
maintainability in mind, we are starting with this scheme as simple sysfs
implementation. We expect to refine it over time as we incorporate the
feedback.

The patchset makes substantial reuse of drivers/firmware/efi/efivars.c and
drivers/firmware/efi/vars.c, however because POWER platforms do not use
EFI, a new config, POWER_SECVAR_SYSFS, is defined to enable this sysfs
interface in POWER.

This patchset has a pre-requisiste of other OPAL APIs which are posted as
part of ima arch specific patches[2].

[1]https://patchwork.kernel.org/cover/10882149/  
[2]https://lkml.org/lkml/2019/6/11/868
[3]https://patchwork.ozlabs.org/project/skiboot/list/?series=112868 

Claudio Carvalho (1):
  powerpc/powernv: add OPAL APIs for secure variables

Nayna Jain (1):
  powerpc: expose secure variables via sysfs

 arch/powerpc/Kconfig |   2 +
 arch/powerpc/include/asm/opal-api.h  |   3 +
 arch/powerpc/include/asm/opal-secvar.h   |   9 +
 arch/powerpc/include/asm/opal.h  |   8 +
 arch/powerpc/platforms/powernv/opal-call.c   |   3 +
 arch/powerpc/platforms/powernv/opal-secvar.c |  60 +++-
 drivers/firmware/Makefile|   1 +
 drivers/firmware/efi/efivars.c   |   2 +-
 drivers/firmware/powerpc/Kconfig |  12 +
 drivers/firmware/powerpc/Makefile|   3 +
 drivers/firmware/powerpc/efi_error.c |  46 +++
 drivers/firmware/powerpc/secvar.c| 326 +++
 12 files changed, 473 insertions(+), 2 deletions(-)
 create mode 100644 drivers/firmware/powerpc/Kconfig
 create mode 100644 drivers/firmware/powerpc/Makefile
 create mode 100644 drivers/firmware/powerpc/efi_error.c
 create mode 100644 drivers/firmware/powerpc/secvar.c

-- 
2.20.1



Re: [RFC PATCH] Replaces long number representation by BIT() macro

2019-06-13 Thread Leonardo Bras
Sorry, there is a typo on my commit message.
's/BIT_MASK/BIT/'

On Thu, 2019-06-13 at 15:02 -0300, Leonardo Bras wrote:
> The main reason of this change is to make these bitmasks more readable.
> 
> The macro ASM_CONST() just appends an UL to it's parameter, so it can be
> easily replaced by BIT_MASK, that already uses a UL representation.
> 
> ASM_CONST() in this file may behave different if __ASSEMBLY__ is defined,
> as it is used on .S files, just leaving the parameter as is.
> 
> However, I have noticed no difference in the generated binary after this
> change.
> 
> Signed-off-by: Leonardo Bras 
> ---
>  arch/powerpc/include/asm/firmware.h | 75 ++---
>  1 file changed, 37 insertions(+), 38 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/firmware.h 
> b/arch/powerpc/include/asm/firmware.h
> index 00bc42d95679..7a5b0cc0bc85 100644
> --- a/arch/powerpc/include/asm/firmware.h
> +++ b/arch/powerpc/include/asm/firmware.h
> @@ -14,46 +14,45 @@
>  
>  #ifdef __KERNEL__
>  
> -#include 
> -
> +#include 
>  /* firmware feature bitmask values */
>  
> -#define FW_FEATURE_PFT   ASM_CONST(0x0001)
> -#define FW_FEATURE_TCE   ASM_CONST(0x0002)
> -#define FW_FEATURE_SPRG0 ASM_CONST(0x0004)
> -#define FW_FEATURE_DABR  ASM_CONST(0x0008)
> -#define FW_FEATURE_COPY  ASM_CONST(0x0010)
> -#define FW_FEATURE_ASR   ASM_CONST(0x0020)
> -#define FW_FEATURE_DEBUG ASM_CONST(0x0040)
> -#define FW_FEATURE_TERM  ASM_CONST(0x0080)
> -#define FW_FEATURE_PERF  ASM_CONST(0x0100)
> -#define FW_FEATURE_DUMP  ASM_CONST(0x0200)
> -#define FW_FEATURE_INTERRUPT ASM_CONST(0x0400)
> -#define FW_FEATURE_MIGRATE   ASM_CONST(0x0800)
> -#define FW_FEATURE_PERFMON   ASM_CONST(0x1000)
> -#define FW_FEATURE_CRQ   ASM_CONST(0x2000)
> -#define FW_FEATURE_VIO   ASM_CONST(0x4000)
> -#define FW_FEATURE_RDMA  ASM_CONST(0x8000)
> -#define FW_FEATURE_LLAN  ASM_CONST(0x0001)
> -#define FW_FEATURE_BULK_REMOVE   ASM_CONST(0x0002)
> -#define FW_FEATURE_XDABR ASM_CONST(0x0004)
> -#define FW_FEATURE_MULTITCE  ASM_CONST(0x0008)
> -#define FW_FEATURE_SPLPARASM_CONST(0x0010)
> -#define FW_FEATURE_LPAR  ASM_CONST(0x0040)
> -#define FW_FEATURE_PS3_LV1   ASM_CONST(0x0080)
> -#define FW_FEATURE_HPT_RESIZEASM_CONST(0x0100)
> -#define FW_FEATURE_CMO   ASM_CONST(0x0200)
> -#define FW_FEATURE_VPHN  ASM_CONST(0x0400)
> -#define FW_FEATURE_XCMO  ASM_CONST(0x0800)
> -#define FW_FEATURE_OPAL  ASM_CONST(0x1000)
> -#define FW_FEATURE_SET_MODE  ASM_CONST(0x4000)
> -#define FW_FEATURE_BEST_ENERGY   ASM_CONST(0x8000)
> -#define FW_FEATURE_TYPE1_AFFINITY ASM_CONST(0x0001)
> -#define FW_FEATURE_PRRN  ASM_CONST(0x0002)
> -#define FW_FEATURE_DRMEM_V2  ASM_CONST(0x0004)
> -#define FW_FEATURE_DRC_INFO  ASM_CONST(0x0008)
> -#define FW_FEATURE_BLOCK_REMOVE ASM_CONST(0x0010)
> -#define FW_FEATURE_PAPR_SCM  ASM_CONST(0x0020)
> +#define FW_FEATURE_PFT   BIT(0)
> +#define FW_FEATURE_TCE   BIT(1)
> +#define FW_FEATURE_SPRG0 BIT(2)
> +#define FW_FEATURE_DABR  BIT(3)
> +#define FW_FEATURE_COPY  BIT(4)
> +#define FW_FEATURE_ASR   BIT(5)
> +#define FW_FEATURE_DEBUG BIT(6)
> +#define FW_FEATURE_TERM  BIT(7)
> +#define FW_FEATURE_PERF  BIT(8)
> +#define FW_FEATURE_DUMP  BIT(9)
> +#define FW_FEATURE_INTERRUPT BIT(10)
> +#define FW_FEATURE_MIGRATE   BIT(11)
> +#define FW_FEATURE_PERFMON   BIT(12)
> +#define FW_FEATURE_CRQ   BIT(13)
> +#define FW_FEATURE_VIO   BIT(14)
> +#define FW_FEATURE_RDMA  BIT(15)
> +#define FW_FEATURE_LLAN  BIT(16)
> +#define FW_FEATURE_BULK_REMOVE   BIT(17)
> +#define FW_FEATURE_XDABR BIT(18)
> +#define FW_FEATURE_MULTITCE  BIT(19)
> +#define FW_FEATURE_SPLPARBIT(20)
> +#define FW_FEATURE_LPAR  BIT(22)
> +#define FW_FEATURE_PS3_LV1   BIT(23)
> +#define FW_FEATURE_HPT_RESIZEBIT(24)
> +#define FW_FEATURE_CMO   BIT(25)
> +#define FW_FEATURE_VPHN  BIT(26)
> +#define FW_FEATURE_XCMO  BIT(27)
> +#define FW_FEATURE_OPAL  BIT(28)
> +#define FW_FEATURE_SET_MODE  BIT(30)
> +#define FW_FEATURE_BEST_ENERGY   BIT(31)
> +#define FW_FEATURE_TYPE1_AFFINITY BIT(32)
> +#define FW_FEATURE_PRRN  BIT(33)
> +#define FW_FEATURE_DRMEM_V2  B

Re: [PATCH] mm: Generalize and rename notify_page_fault() as kprobe_page_fault()

2019-06-13 Thread Andrew Morton
On Thu, 13 Jun 2019 15:37:24 +0530 Anshuman Khandual 
 wrote:

> Architectures which support kprobes have very similar boilerplate around
> calling kprobe_fault_handler(). Use a helper function in kprobes.h to unify
> them, based on the x86 code.
> 
> This changes the behaviour for other architectures when preemption is
> enabled. Previously, they would have disabled preemption while calling the
> kprobe handler. However, preemption would be disabled if this fault was
> due to a kprobe, so we know the fault was not due to a kprobe handler and
> can simply return failure.
> 
> This behaviour was introduced in the commit a980c0ef9f6d ("x86/kprobes:
> Refactor kprobes_fault() like kprobe_exceptions_notify()")
> 
> ...
>
> --- a/arch/arm/mm/fault.c
> +++ b/arch/arm/mm/fault.c
> @@ -30,28 +30,6 @@
>  
>  #ifdef CONFIG_MMU
>  
> -#ifdef CONFIG_KPROBES
> -static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr)

Some architectures make this `static inline'.  Others make it
`nokprobes_inline', others make it `static inline __kprobes'.  The
latter seems weird - why try to put an inline function into
.kprobes.text?

So..  what's the best thing to do here?  You chose `static
nokprobe_inline' - is that the best approach, if so why?  Does
kprobe_page_fault() actually need to be inlined?

Also, some architectures had notify_page_fault returning int, others
bool.  You chose bool and that seems appropriate and all callers are OK
with that.


Re: [PATCH v3 2/4] crypto: talitos - fix hash on SEC1.

2019-06-13 Thread Horia Geanta
On 6/13/2019 3:48 PM, Christophe Leroy wrote:
> On SEC1, hash provides wrong result when performing hashing in several
> steps with input data SG list has more than one element. This was
> detected with CONFIG_CRYPTO_MANAGER_EXTRA_TESTS:
> 
> [   44.185947] alg: hash: md5-talitos test failed (wrong result) on test 
> vector 6, cfg="random: may_sleep use_finup src_divs=[25.88%@+8063, 
> 24.19%@+9588, 28.63%@+16333, 4.60%@+6756, 16.70%@+16281] 
> dst_divs=[71.61%@alignmask+16361, 14.36%@+7756, 14.3%@+"
> [   44.325122] alg: hash: sha1-talitos test failed (wrong result) on test 
> vector 3, cfg="random: inplace use_final 
> src_divs=[16.56%@+16378, 52.0%@+16329, 
> 21.42%@alignmask+16380, 10.2%@alignmask+16380] iv_offset=39"
> [   44.493500] alg: hash: sha224-talitos test failed (wrong result) on test 
> vector 4, cfg="random: use_final nosimd src_divs=[52.27%@+7401, 
> 17.34%@+16285, 17.71%@+26, 12.68%@+10644] iv_offset=43"
> [   44.673262] alg: hash: sha256-talitos test failed (wrong result) on test 
> vector 4, cfg="random: may_sleep use_finup src_divs=[60.6%@+12790, 
> 17.86%@+1329, 12.64%@alignmask+16300, 8.29%@+15, 0.40%@+13506, 
> 0.51%@+16322, 0.24%@+16339] dst_divs"
> 
> This is due to two issues:
> - We have an overlap between the buffer used for copying the input
> data (SEC1 doesn't do scatter/gather) and the chained descriptor.
> - Data copy is wrong when the previous hash left less than one
> blocksize of data to hash, implying a complement of the previous
> block with a few bytes from the new request.
> 
I fail to spot these issues.

IIUC in case of SEC1, the variable part of talitos_edesc structure contains
a 2nd "chained" descriptor (talitos_desc struct) followed by an area
dedicated to linearizing the input (in case input is scattered).

Where is the overlap?

> Fix it by:
> - Moving the second descriptor after the buffer, as moving the buffer
> after the descriptor would make it more complex for other cipher
> operations (AEAD, ABLKCIPHER)
> - Rebuiding a new data SG list without the bytes taken from the new
> request to complete the previous one.
> 
> Preceding patch ("crypto: talitos - move struct talitos_edesc into
> talitos.h") as required for this change to build properly.
> 
> Fixes: 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on 
> SEC1")
> Cc: sta...@vger.kernel.org
> Signed-off-by: Christophe Leroy 
> ---
>  drivers/crypto/talitos.c | 63 
> ++--
>  1 file changed, 40 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
> index 5b401aec6c84..4f03baef952b 100644
> --- a/drivers/crypto/talitos.c
> +++ b/drivers/crypto/talitos.c
> @@ -336,15 +336,18 @@ static void flush_channel(struct device *dev, int ch, 
> int error, int reset_ch)
>   tail = priv->chan[ch].tail;
>   while (priv->chan[ch].fifo[tail].desc) {
>   __be32 hdr;
> + struct talitos_edesc *edesc;
>  
>   request = &priv->chan[ch].fifo[tail];
> + edesc = container_of(request->desc, struct talitos_edesc, desc);
>  
>   /* descriptors with their done bits set don't get the error */
>   rmb();
>   if (!is_sec1)
>   hdr = request->desc->hdr;
>   else if (request->desc->next_desc)
> - hdr = (request->desc + 1)->hdr1;
> + hdr = ((struct talitos_desc *)
> +(edesc->buf + edesc->dma_len))->hdr1;
>   else
>   hdr = request->desc->hdr1;
>  
> @@ -476,8 +479,14 @@ static u32 current_desc_hdr(struct device *dev, int ch)
>   }
>   }
>  
> - if (priv->chan[ch].fifo[iter].desc->next_desc == cur_desc)
> - return (priv->chan[ch].fifo[iter].desc + 1)->hdr;
> + if (priv->chan[ch].fifo[iter].desc->next_desc == cur_desc) {
> + struct talitos_edesc *edesc;
> +
> + edesc = container_of(priv->chan[ch].fifo[iter].desc,
> +  struct talitos_edesc, desc);
> + return ((struct talitos_desc *)
> + (edesc->buf + edesc->dma_len))->hdr;
> + }
>  
>   return priv->chan[ch].fifo[iter].desc->hdr;
>  }
> @@ -1402,15 +1411,11 @@ static struct talitos_edesc 
> *talitos_edesc_alloc(struct device *dev,
>   edesc->dst_nents = dst_nents;
>   edesc->iv_dma = iv_dma;
>   edesc->dma_len = dma_len;
> - if (dma_len) {
> - void *addr = &edesc->link_tbl[0];
> -
> - if (is_sec1 && !dst)
> - addr += sizeof(struct talitos_desc);
> - edesc->dma_link_tbl = dma_map_single(dev, addr,
> + if (dma_len)
> + edesc->dma_link_tbl = dma_map_single(dev, &edesc->link_tbl[0],
>edesc->dma_len,
>DMA_BIDIRECTIONAL);
> - }
> +
>   return ede

Re: [PATCH] powerpc: enable a 30-bit ZONE_DMA for 32-bit pmac

2019-06-13 Thread Larry Finger

On 6/13/19 3:24 AM, Christoph Hellwig wrote:

With the strict dma mask checking introduced with the switch to
the generic DMA direct code common wifi chips on 32-bit powerbooks
stopped working.  Add a 30-bit ZONE_DMA to the 32-bit pmac builds
to allow them to reliably allocate dma coherent memory.

Fixes: 65a21b71f948 ("powerpc/dma: remove dma_nommu_dma_supported")
Reported-by: Aaro Koskinen 
Signed-off-by: Christoph Hellwig 


As expected, it works. The patch needs
Cc: Stable  # v5.1+

Tested-by: Larry Finger 
Acked-by: Larry Finger 

Thanks for the help, and the patience with my debugging problems with u64 
variables.

Larry


[RFC PATCH] Replaces long number representation by BIT() macro

2019-06-13 Thread Leonardo Bras
The main reason of this change is to make these bitmasks more readable.

The macro ASM_CONST() just appends an UL to it's parameter, so it can be
easily replaced by BIT_MASK, that already uses a UL representation.

ASM_CONST() in this file may behave different if __ASSEMBLY__ is defined,
as it is used on .S files, just leaving the parameter as is.

However, I have noticed no difference in the generated binary after this
change.

Signed-off-by: Leonardo Bras 
---
 arch/powerpc/include/asm/firmware.h | 75 ++---
 1 file changed, 37 insertions(+), 38 deletions(-)

diff --git a/arch/powerpc/include/asm/firmware.h 
b/arch/powerpc/include/asm/firmware.h
index 00bc42d95679..7a5b0cc0bc85 100644
--- a/arch/powerpc/include/asm/firmware.h
+++ b/arch/powerpc/include/asm/firmware.h
@@ -14,46 +14,45 @@
 
 #ifdef __KERNEL__
 
-#include 
-
+#include 
 /* firmware feature bitmask values */
 
-#define FW_FEATURE_PFT ASM_CONST(0x0001)
-#define FW_FEATURE_TCE ASM_CONST(0x0002)
-#define FW_FEATURE_SPRG0   ASM_CONST(0x0004)
-#define FW_FEATURE_DABRASM_CONST(0x0008)
-#define FW_FEATURE_COPYASM_CONST(0x0010)
-#define FW_FEATURE_ASR ASM_CONST(0x0020)
-#define FW_FEATURE_DEBUG   ASM_CONST(0x0040)
-#define FW_FEATURE_TERMASM_CONST(0x0080)
-#define FW_FEATURE_PERFASM_CONST(0x0100)
-#define FW_FEATURE_DUMPASM_CONST(0x0200)
-#define FW_FEATURE_INTERRUPT   ASM_CONST(0x0400)
-#define FW_FEATURE_MIGRATE ASM_CONST(0x0800)
-#define FW_FEATURE_PERFMON ASM_CONST(0x1000)
-#define FW_FEATURE_CRQ ASM_CONST(0x2000)
-#define FW_FEATURE_VIO ASM_CONST(0x4000)
-#define FW_FEATURE_RDMAASM_CONST(0x8000)
-#define FW_FEATURE_LLANASM_CONST(0x0001)
-#define FW_FEATURE_BULK_REMOVE ASM_CONST(0x0002)
-#define FW_FEATURE_XDABR   ASM_CONST(0x0004)
-#define FW_FEATURE_MULTITCEASM_CONST(0x0008)
-#define FW_FEATURE_SPLPAR  ASM_CONST(0x0010)
-#define FW_FEATURE_LPARASM_CONST(0x0040)
-#define FW_FEATURE_PS3_LV1 ASM_CONST(0x0080)
-#define FW_FEATURE_HPT_RESIZE  ASM_CONST(0x0100)
-#define FW_FEATURE_CMO ASM_CONST(0x0200)
-#define FW_FEATURE_VPHNASM_CONST(0x0400)
-#define FW_FEATURE_XCMOASM_CONST(0x0800)
-#define FW_FEATURE_OPALASM_CONST(0x1000)
-#define FW_FEATURE_SET_MODEASM_CONST(0x4000)
-#define FW_FEATURE_BEST_ENERGY ASM_CONST(0x8000)
-#define FW_FEATURE_TYPE1_AFFINITY ASM_CONST(0x0001)
-#define FW_FEATURE_PRRNASM_CONST(0x0002)
-#define FW_FEATURE_DRMEM_V2ASM_CONST(0x0004)
-#define FW_FEATURE_DRC_INFOASM_CONST(0x0008)
-#define FW_FEATURE_BLOCK_REMOVE ASM_CONST(0x0010)
-#define FW_FEATURE_PAPR_SCMASM_CONST(0x0020)
+#define FW_FEATURE_PFT BIT(0)
+#define FW_FEATURE_TCE BIT(1)
+#define FW_FEATURE_SPRG0   BIT(2)
+#define FW_FEATURE_DABRBIT(3)
+#define FW_FEATURE_COPYBIT(4)
+#define FW_FEATURE_ASR BIT(5)
+#define FW_FEATURE_DEBUG   BIT(6)
+#define FW_FEATURE_TERMBIT(7)
+#define FW_FEATURE_PERFBIT(8)
+#define FW_FEATURE_DUMPBIT(9)
+#define FW_FEATURE_INTERRUPT   BIT(10)
+#define FW_FEATURE_MIGRATE BIT(11)
+#define FW_FEATURE_PERFMON BIT(12)
+#define FW_FEATURE_CRQ BIT(13)
+#define FW_FEATURE_VIO BIT(14)
+#define FW_FEATURE_RDMABIT(15)
+#define FW_FEATURE_LLANBIT(16)
+#define FW_FEATURE_BULK_REMOVE BIT(17)
+#define FW_FEATURE_XDABR   BIT(18)
+#define FW_FEATURE_MULTITCEBIT(19)
+#define FW_FEATURE_SPLPAR  BIT(20)
+#define FW_FEATURE_LPARBIT(22)
+#define FW_FEATURE_PS3_LV1 BIT(23)
+#define FW_FEATURE_HPT_RESIZE  BIT(24)
+#define FW_FEATURE_CMO BIT(25)
+#define FW_FEATURE_VPHNBIT(26)
+#define FW_FEATURE_XCMOBIT(27)
+#define FW_FEATURE_OPALBIT(28)
+#define FW_FEATURE_SET_MODEBIT(30)
+#define FW_FEATURE_BEST_ENERGY BIT(31)
+#define FW_FEATURE_TYPE1_AFFINITY BIT(32)
+#define FW_FEATURE_PRRNBIT(33)
+#define FW_FEATURE_DRMEM_V2BIT(34)
+#define FW_FEATURE_DRC_INFOBIT(35)
+#define FW_FEATURE_BLOCK_REMOVEBIT(36)
+#define FW_FEATURE_PAPR_SCMBIT(37)
 
 #ifndef __ASSEMBLY__
 
-- 
2.17.1



Re: [PATCH v2] cxl: no need to check return value of debugfs_create functions

2019-06-13 Thread Frederic Barrat




Le 12/06/2019 à 17:54, Greg Kroah-Hartman a écrit :

When calling debugfs functions, there is no need to ever check the
return value.  The function can work or not, but the code logic should
never do something different based on this.

Because there's no need to check, also make the return value of the
local debugfs_create_io_x64() call void, as no one ever did anything
with the return value (as they did not need to.)

And make the cxl_debugfs_* calls return void as no one was even checking
their return value at all.

Cc: Frederic Barrat 
Cc: Andrew Donnellan 
Cc: Arnd Bergmann 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Greg Kroah-Hartman 
---


Thanks!
Reviewed-by: Frederic Barrat 



v2: make the return value of all of the cxl_debugfs_* calls void as no
 one was checking the return values of them.

  drivers/misc/cxl/cxl.h | 15 ++-
  drivers/misc/cxl/debugfs.c | 36 +++-
  2 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index a73c9e669d78..5dc0f6093f9d 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -908,11 +908,11 @@ void cxl_update_dedicated_ivtes_psl8(struct cxl_context 
*ctx);
  
  #ifdef CONFIG_DEBUG_FS
  
-int cxl_debugfs_init(void);

+void cxl_debugfs_init(void);
  void cxl_debugfs_exit(void);
-int cxl_debugfs_adapter_add(struct cxl *adapter);
+void cxl_debugfs_adapter_add(struct cxl *adapter);
  void cxl_debugfs_adapter_remove(struct cxl *adapter);
-int cxl_debugfs_afu_add(struct cxl_afu *afu);
+void cxl_debugfs_afu_add(struct cxl_afu *afu);
  void cxl_debugfs_afu_remove(struct cxl_afu *afu);
  void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry 
*dir);
  void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry 
*dir);
@@ -921,27 +921,24 @@ void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, 
struct dentry *dir);
  
  #else /* CONFIG_DEBUG_FS */
  
-static inline int __init cxl_debugfs_init(void)

+static inline void __init cxl_debugfs_init(void)
  {
-   return 0;
  }
  
  static inline void cxl_debugfs_exit(void)

  {
  }
  
-static inline int cxl_debugfs_adapter_add(struct cxl *adapter)

+static inline void cxl_debugfs_adapter_add(struct cxl *adapter)
  {
-   return 0;
  }
  
  static inline void cxl_debugfs_adapter_remove(struct cxl *adapter)

  {
  }
  
-static inline int cxl_debugfs_afu_add(struct cxl_afu *afu)

+static inline void cxl_debugfs_afu_add(struct cxl_afu *afu)
  {
-   return 0;
  }
  
  static inline void cxl_debugfs_afu_remove(struct cxl_afu *afu)

diff --git a/drivers/misc/cxl/debugfs.c b/drivers/misc/cxl/debugfs.c
index 1fda22c24c93..7b987bf498b5 100644
--- a/drivers/misc/cxl/debugfs.c
+++ b/drivers/misc/cxl/debugfs.c
@@ -26,11 +26,11 @@ static int debugfs_io_u64_set(void *data, u64 val)
  DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
 "0x%016llx\n");
  
-static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,

-   struct dentry *parent, u64 __iomem 
*value)
+static void debugfs_create_io_x64(const char *name, umode_t mode,
+ struct dentry *parent, u64 __iomem *value)
  {
-   return debugfs_create_file_unsafe(name, mode, parent,
- (void __force *)value, &fops_io_x64);
+   debugfs_create_file_unsafe(name, mode, parent, (void __force *)value,
+  &fops_io_x64);
  }
  
  void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)

@@ -54,25 +54,22 @@ void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, 
struct dentry *dir)
debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, 
_cxl_p1_addr(adapter, CXL_PSL_TRACE));
  }
  
-int cxl_debugfs_adapter_add(struct cxl *adapter)

+void cxl_debugfs_adapter_add(struct cxl *adapter)
  {
struct dentry *dir;
char buf[32];
  
  	if (!cxl_debugfs)

-   return -ENODEV;
+   return;
  
  	snprintf(buf, 32, "card%i", adapter->adapter_num);

dir = debugfs_create_dir(buf, cxl_debugfs);
-   if (IS_ERR(dir))
-   return PTR_ERR(dir);
adapter->debugfs = dir;
  
  	debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
  
  	if (adapter->native->sl_ops->debugfs_add_adapter_regs)

adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
-   return 0;
  }
  
  void cxl_debugfs_adapter_remove(struct cxl *adapter)

@@ -96,18 +93,16 @@ void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, 
struct dentry *dir)
debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, 
_cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
  }
  
-int cxl_debugfs_afu_add(struct cxl_afu *afu)

+void cxl_debugfs_afu_add(struct cxl_afu *afu)
  {
struct dentry *dir;
char buf[32];
  
  

Re: [PATCH 2/3] powerpc/pseries/mobility: prevent cpu hotplug during DT update

2019-06-13 Thread Gautham R Shenoy
Hello Nathan,

On Wed, Jun 12, 2019 at 10:19 AM Nathan Lynch  wrote:
>
> CPU online/offline code paths are sensitive to parts of the device
> tree (various cpu node properties, cache nodes) that can be changed as
> a result of a migration.
>
> Prevent CPU hotplug while the device tree potentially is inconsistent.
>
> Fixes: 410bccf97881 ("powerpc/pseries: Partition migration in the kernel")
> Signed-off-by: Nathan Lynch 

Audited the callbacks of of_reconfig_notify(). We are fine with
respect to CPU-Hotplug locking.

Reviewed-by: Gautham R. Shenoy 

> ---
>  arch/powerpc/platforms/pseries/mobility.c | 9 +
>  1 file changed, 9 insertions(+)
>
> diff --git a/arch/powerpc/platforms/pseries/mobility.c 
> b/arch/powerpc/platforms/pseries/mobility.c
> index 88925f8ca8a0..edc1ec408589 100644
> --- a/arch/powerpc/platforms/pseries/mobility.c
> +++ b/arch/powerpc/platforms/pseries/mobility.c
> @@ -9,6 +9,7 @@
>   * 2 as published by the Free Software Foundation.
>   */
>
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -338,11 +339,19 @@ void post_mobility_fixup(void)
> if (rc)
> printk(KERN_ERR "Post-mobility activate-fw failed: %d\n", rc);
>
> +   /*
> +* We don't want CPUs to go online/offline while the device
> +* tree is being updated.
> +*/
> +   cpus_read_lock();
> +
> rc = pseries_devicetree_update(MIGRATION_SCOPE);
> if (rc)
> printk(KERN_ERR "Post-mobility device tree update "
> "failed: %d\n", rc);
>
> +   cpus_read_unlock();
> +
> /* Possibly switch to a new RFI flush type */
> pseries_setup_rfi_flush();
>
> --
> 2.20.1
>


-- 
Thanks and Regards
gautham.


Re: [PATCH v4 3/3] kselftest: Extend vDSO selftest to clock_getres

2019-06-13 Thread Vincenzo Frascino
Hi Michael,

I wanted to check with you if you had time to have a look at my new version (v5)
of the patches with the fixed test, and if they are ready to be merged or if
there is anything else I can do.

Thanks and Regards,
Vincenzo

On 28/05/2019 12:57, Vincenzo Frascino wrote:
> Hi Michael,
> 
> thank you for your reply.
> 
> On 28/05/2019 07:19, Michael Ellerman wrote:
>> Vincenzo Frascino  writes:
>>
>>> The current version of the multiarch vDSO selftest verifies only
>>> gettimeofday.
>>>
>>> Extend the vDSO selftest to clock_getres, to verify that the
>>> syscall and the vDSO library function return the same information.
>>>
>>> The extension has been used to verify the hrtimer_resoltion fix.
>>
>> This is passing for me even without patch 1 applied, shouldn't it fail
>> without the fix? What am I missing?
>>
> 
> This is correct, because during the refactoring process I missed an "n" :)
> 
> if·((x.tv_sec·!=·y.tv_sec)·||·(x.tv_sec·!=·y.tv_sec))
> 
> Should be:
> 
> if·((x.tv_sec·!=·y.tv_sec)·||·(x.tv_nsec·!=·y.tv_nsec))
> 
> My mistake, I am going to fix the test and re-post v5 of this set.
> 
> Without my patch if you pass "highres=off" to the kernel (as a command line
> parameter) it leads to a broken implementation of clock_getres since the value
> of CLOCK_REALTIME_RES does not change at runtime.
> 
> Expected result (with highres=off):
> 
> # uname -r
> 5.2.0-rc2
> # ./vdso_clock_getres
> clock_id: CLOCK_REALTIME [FAIL]
> clock_id: CLOCK_BOOTTIME [PASS]
> clock_id: CLOCK_TAI [PASS]
> clock_id: CLOCK_REALTIME_COARSE [PASS]
> clock_id: CLOCK_MONOTONIC [FAIL]
> clock_id: CLOCK_MONOTONIC_RAW [PASS]
> clock_id: CLOCK_MONOTONIC_COARSE [PASS]
> 
> The reason of this behavior is that the only clocks supported by getres on
> powerpc are CLOCK_REALTIME and CLOCK_MONOTONIC, the rest on the clocks use
> always syscalls.
> 
>> # uname -r
>> 5.2.0-rc2-gcc-8.2.0
>>
>> # ./vdso_clock_getres
>> clock_id: CLOCK_REALTIME [PASS]
>> clock_id: CLOCK_BOOTTIME [PASS]
>> clock_id: CLOCK_TAI [PASS]
>> clock_id: CLOCK_REALTIME_COARSE [PASS]
>> clock_id: CLOCK_MONOTONIC [PASS]
>> clock_id: CLOCK_MONOTONIC_RAW [PASS]
>> clock_id: CLOCK_MONOTONIC_COARSE [PASS]
>>
>> cheers
>>
>>> Cc: Shuah Khan 
>>> Signed-off-by: Vincenzo Frascino 
>>> ---
>>>
>>> Note: This patch is independent from the others in this series, hence it
>>> can be merged singularly by the kselftest maintainers.
>>>
>>>  tools/testing/selftests/vDSO/Makefile |   2 +
>>>  .../selftests/vDSO/vdso_clock_getres.c| 124 ++
>>>  2 files changed, 126 insertions(+)
>>>  create mode 100644 tools/testing/selftests/vDSO/vdso_clock_getres.c
> 


Re: [PATCH 1/2] powerpc/8xx: move CPM1 related files from sysdev/ to platforms/8xx

2019-06-13 Thread kbuild test robot
Hi Christophe,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on v5.2-rc4 next-20190612]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Christophe-Leroy/powerpc-8xx-move-CPM1-related-files-from-sysdev-to-platforms-8xx/20190613-182651
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-ep8248e_defconfig (attached as .config)
compiler: powerpc-linux-gcc (GCC) 7.4.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot 

All errors (new ones prefixed by >>):

>> make[3]: *** No rule to make target 'arch/powerpc/sysdev/cpm_gpio.o', needed 
>> by 'arch/powerpc/sysdev/built-in.a'.
   make[3]: Target '__build' not remade because of errors.

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH] powerpc/booke: fix fast syscall entry on SMP

2019-06-13 Thread Christophe Leroy
Use r10 instead of r9 to calculate CPU offset as r9 contains
the value from SRR1 which is used later.

Fixes: 1a4b739bbb4f ("powerpc/32: implement fast entry for syscalls on BOOKE")
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_booke.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index dec0912a6508..2ae635df9026 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -145,9 +145,9 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
tophys(r11,r11)
addir11,r11,global_dbcr0@l
 #ifdef CONFIG_SMP
-   lwz r9,TASK_CPU(r2)
-   slwir9,r9,3
-   add r11,r11,r9
+   lwz r10, TASK_CPU(r2)
+   slwir10, r10, 3
+   add r11, r11, r10
 #endif
lwz r12,0(r11)
mtspr   SPRN_DBCR0,r12
-- 
2.13.3



Re: [PATCH v2 4/4] crypto: talitos - drop icv_ool

2019-06-13 Thread Herbert Xu
On Thu, Jun 13, 2019 at 02:28:51PM +0200, Christophe Leroy wrote:
> 
> 
> Le 13/06/2019 à 14:21, Horia Geanta a écrit :
> > On 6/11/2019 5:39 PM, Christophe Leroy wrote:
> > > icv_ool is not used anymore, drop it.
> > > 
> > > Fixes: 9cc87bc3613b ("crypto: talitos - fix AEAD processing")
> > I can't find this SHA1.
> > 
> > Are you referring to commit e345177ded17 ("crypto: talitos - fix AEAD 
> > processing.")?
> > 
> > Horia
> > 
> 
> Oops yes, that's the sha1 it had in my tree before it got merged.
> 
> Do I have to resend it or can Herbert just drop the wrong reference and take
> the following one:

Please resend since you're going to change the other patches too.

Thanks,
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [PATCH v3 1/4] crypto: talitos - move struct talitos_edesc into talitos.h

2019-06-13 Thread Christophe Leroy




Le 13/06/2019 à 14:48, Christophe Leroy a écrit :

Moves it into talitos.h so that it can be used
from any place in talitos.c

This will be required for next
patch ("crypto: talitos - fix hash on SEC1")

Signed-off-by: Christophe Leroy 


Cc: sta...@vger.kernel.org


---
  drivers/crypto/talitos.c | 30 --
  drivers/crypto/talitos.h | 30 ++
  2 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 3b3e99f1cddb..5b401aec6c84 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -951,36 +951,6 @@ static int aead_des3_setkey(struct crypto_aead *authenc,
goto out;
  }
  
-/*

- * talitos_edesc - s/w-extended descriptor
- * @src_nents: number of segments in input scatterlist
- * @dst_nents: number of segments in output scatterlist
- * @icv_ool: whether ICV is out-of-line
- * @iv_dma: dma address of iv for checking continuity and link table
- * @dma_len: length of dma mapped link_tbl space
- * @dma_link_tbl: bus physical address of link_tbl/buf
- * @desc: h/w descriptor
- * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1) (SEC2)
- * @buf: input and output buffeur (if {src,dst}_nents > 1) (SEC1)
- *
- * if decrypting (with authcheck), or either one of src_nents or dst_nents
- * is greater than 1, an integrity check value is concatenated to the end
- * of link_tbl data
- */
-struct talitos_edesc {
-   int src_nents;
-   int dst_nents;
-   bool icv_ool;
-   dma_addr_t iv_dma;
-   int dma_len;
-   dma_addr_t dma_link_tbl;
-   struct talitos_desc desc;
-   union {
-   struct talitos_ptr link_tbl[0];
-   u8 buf[0];
-   };
-};
-
  static void talitos_sg_unmap(struct device *dev,
 struct talitos_edesc *edesc,
 struct scatterlist *src,
diff --git a/drivers/crypto/talitos.h b/drivers/crypto/talitos.h
index 32ad4fc679ed..95f78c6d9206 100644
--- a/drivers/crypto/talitos.h
+++ b/drivers/crypto/talitos.h
@@ -42,6 +42,36 @@ struct talitos_desc {
  
  #define TALITOS_DESC_SIZE	(sizeof(struct talitos_desc) - sizeof(__be32))
  
+/*

+ * talitos_edesc - s/w-extended descriptor
+ * @src_nents: number of segments in input scatterlist
+ * @dst_nents: number of segments in output scatterlist
+ * @icv_ool: whether ICV is out-of-line
+ * @iv_dma: dma address of iv for checking continuity and link table
+ * @dma_len: length of dma mapped link_tbl space
+ * @dma_link_tbl: bus physical address of link_tbl/buf
+ * @desc: h/w descriptor
+ * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1) (SEC2)
+ * @buf: input and output buffeur (if {src,dst}_nents > 1) (SEC1)
+ *
+ * if decrypting (with authcheck), or either one of src_nents or dst_nents
+ * is greater than 1, an integrity check value is concatenated to the end
+ * of link_tbl data
+ */
+struct talitos_edesc {
+   int src_nents;
+   int dst_nents;
+   bool icv_ool;
+   dma_addr_t iv_dma;
+   int dma_len;
+   dma_addr_t dma_link_tbl;
+   struct talitos_desc desc;
+   union {
+   struct talitos_ptr link_tbl[0];
+   u8 buf[0];
+   };
+};
+
  /**
   * talitos_request - descriptor submission request
   * @desc: descriptor pointer (kernel virtual)



Re: [PATCH v2 1/4] crypto: talitos - move struct talitos_edesc into talitos.h

2019-06-13 Thread Christophe Leroy




Le 13/06/2019 à 14:39, Horia Geanta a écrit :

On 6/13/2019 3:32 PM, Christophe Leroy wrote:



Le 13/06/2019 à 14:24, Horia Geanta a écrit :

On 6/13/2019 3:16 PM, Christophe Leroy wrote:



Le 13/06/2019 à 14:13, Horia Geanta a écrit :

On 6/11/2019 5:39 PM, Christophe Leroy wrote:

Next patch will require struct talitos_edesc to be defined
earlier in talitos.c

This patch moves it into talitos.h so that it can be used
from any place in talitos.c

Fixes: 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on 
SEC1")
Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Leroy 

Again, this patch does not qualify as a fix.



But as I said, the following one is a fix and require that one, you told
me to add stable in Cc: to make it explicit it was to go into stable.

Yes, but you should remove the Fixes tag.
And probably replace "Next patch" with the commit headline.


If someone tries to merge following one into stable with taking that one
first, build will fail.

This shouldn't happen, order from main tree should be preserved.



When they pick up fixes, AFAIK they don't take all the preceeding commits.


This is not about Fixes tag, but Cc tag:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1



Ah, ok. So I need to keep the Cc tag. I misunderstood sorry.


[PATCH v3 4/4] crypto: talitos - drop icv_ool

2019-06-13 Thread Christophe Leroy
icv_ool is not used anymore, drop it.

Fixes: e345177ded17 ("crypto: talitos - fix AEAD processing.")
Signed-off-by: Christophe Leroy 
---
 drivers/crypto/talitos.c | 3 ---
 drivers/crypto/talitos.h | 2 --
 2 files changed, 5 deletions(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index b2de931de623..03b7a5d28fb0 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1278,9 +1278,6 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct 
aead_request *areq,
 is_ipsec_esp && !encrypt);
tbl_off += ret;
 
-   /* ICV data */
-   edesc->icv_ool = !encrypt;
-
if (!encrypt && is_ipsec_esp) {
struct talitos_ptr *tbl_ptr = &edesc->link_tbl[tbl_off];
 
diff --git a/drivers/crypto/talitos.h b/drivers/crypto/talitos.h
index 95f78c6d9206..1469b956948a 100644
--- a/drivers/crypto/talitos.h
+++ b/drivers/crypto/talitos.h
@@ -46,7 +46,6 @@ struct talitos_desc {
  * talitos_edesc - s/w-extended descriptor
  * @src_nents: number of segments in input scatterlist
  * @dst_nents: number of segments in output scatterlist
- * @icv_ool: whether ICV is out-of-line
  * @iv_dma: dma address of iv for checking continuity and link table
  * @dma_len: length of dma mapped link_tbl space
  * @dma_link_tbl: bus physical address of link_tbl/buf
@@ -61,7 +60,6 @@ struct talitos_desc {
 struct talitos_edesc {
int src_nents;
int dst_nents;
-   bool icv_ool;
dma_addr_t iv_dma;
int dma_len;
dma_addr_t dma_link_tbl;
-- 
2.13.3



[PATCH v3 2/4] crypto: talitos - fix hash on SEC1.

2019-06-13 Thread Christophe Leroy
On SEC1, hash provides wrong result when performing hashing in several
steps with input data SG list has more than one element. This was
detected with CONFIG_CRYPTO_MANAGER_EXTRA_TESTS:

[   44.185947] alg: hash: md5-talitos test failed (wrong result) on test vector 
6, cfg="random: may_sleep use_finup src_divs=[25.88%@+8063, 
24.19%@+9588, 28.63%@+16333, 4.60%@+6756, 16.70%@+16281] 
dst_divs=[71.61%@alignmask+16361, 14.36%@+7756, 14.3%@+"
[   44.325122] alg: hash: sha1-talitos test failed (wrong result) on test 
vector 3, cfg="random: inplace use_final src_divs=[16.56%@+16378, 
52.0%@+16329, 21.42%@alignmask+16380, 10.2%@alignmask+16380] 
iv_offset=39"
[   44.493500] alg: hash: sha224-talitos test failed (wrong result) on test 
vector 4, cfg="random: use_final nosimd src_divs=[52.27%@+7401, 
17.34%@+16285, 17.71%@+26, 12.68%@+10644] iv_offset=43"
[   44.673262] alg: hash: sha256-talitos test failed (wrong result) on test 
vector 4, cfg="random: may_sleep use_finup src_divs=[60.6%@+12790, 
17.86%@+1329, 12.64%@alignmask+16300, 8.29%@+15, 0.40%@+13506, 
0.51%@+16322, 0.24%@+16339] dst_divs"

This is due to two issues:
- We have an overlap between the buffer used for copying the input
data (SEC1 doesn't do scatter/gather) and the chained descriptor.
- Data copy is wrong when the previous hash left less than one
blocksize of data to hash, implying a complement of the previous
block with a few bytes from the new request.

Fix it by:
- Moving the second descriptor after the buffer, as moving the buffer
after the descriptor would make it more complex for other cipher
operations (AEAD, ABLKCIPHER)
- Rebuiding a new data SG list without the bytes taken from the new
request to complete the previous one.

Preceding patch ("crypto: talitos - move struct talitos_edesc into
talitos.h") as required for this change to build properly.

Fixes: 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on 
SEC1")
Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Leroy 
---
 drivers/crypto/talitos.c | 63 ++--
 1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 5b401aec6c84..4f03baef952b 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -336,15 +336,18 @@ static void flush_channel(struct device *dev, int ch, int 
error, int reset_ch)
tail = priv->chan[ch].tail;
while (priv->chan[ch].fifo[tail].desc) {
__be32 hdr;
+   struct talitos_edesc *edesc;
 
request = &priv->chan[ch].fifo[tail];
+   edesc = container_of(request->desc, struct talitos_edesc, desc);
 
/* descriptors with their done bits set don't get the error */
rmb();
if (!is_sec1)
hdr = request->desc->hdr;
else if (request->desc->next_desc)
-   hdr = (request->desc + 1)->hdr1;
+   hdr = ((struct talitos_desc *)
+  (edesc->buf + edesc->dma_len))->hdr1;
else
hdr = request->desc->hdr1;
 
@@ -476,8 +479,14 @@ static u32 current_desc_hdr(struct device *dev, int ch)
}
}
 
-   if (priv->chan[ch].fifo[iter].desc->next_desc == cur_desc)
-   return (priv->chan[ch].fifo[iter].desc + 1)->hdr;
+   if (priv->chan[ch].fifo[iter].desc->next_desc == cur_desc) {
+   struct talitos_edesc *edesc;
+
+   edesc = container_of(priv->chan[ch].fifo[iter].desc,
+struct talitos_edesc, desc);
+   return ((struct talitos_desc *)
+   (edesc->buf + edesc->dma_len))->hdr;
+   }
 
return priv->chan[ch].fifo[iter].desc->hdr;
 }
@@ -1402,15 +1411,11 @@ static struct talitos_edesc *talitos_edesc_alloc(struct 
device *dev,
edesc->dst_nents = dst_nents;
edesc->iv_dma = iv_dma;
edesc->dma_len = dma_len;
-   if (dma_len) {
-   void *addr = &edesc->link_tbl[0];
-
-   if (is_sec1 && !dst)
-   addr += sizeof(struct talitos_desc);
-   edesc->dma_link_tbl = dma_map_single(dev, addr,
+   if (dma_len)
+   edesc->dma_link_tbl = dma_map_single(dev, &edesc->link_tbl[0],
 edesc->dma_len,
 DMA_BIDIRECTIONAL);
-   }
+
return edesc;
 }
 
@@ -1722,14 +1727,16 @@ static void common_nonsnoop_hash_unmap(struct device 
*dev,
struct talitos_private *priv = dev_get_drvdata(dev);
bool is_sec1 = has_ftr_sec1(priv);
struct talitos_desc *desc = &edesc->desc;
-   struct talitos_desc *desc2 = desc + 1;
+   struct talitos_desc *desc2 = (struct talitos_desc *)
+(edesc->buf + edesc->dma_len);
 
unmap_

[PATCH v3 1/4] crypto: talitos - move struct talitos_edesc into talitos.h

2019-06-13 Thread Christophe Leroy
Moves it into talitos.h so that it can be used
from any place in talitos.c

This will be required for next
patch ("crypto: talitos - fix hash on SEC1")

Signed-off-by: Christophe Leroy 
---
 drivers/crypto/talitos.c | 30 --
 drivers/crypto/talitos.h | 30 ++
 2 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 3b3e99f1cddb..5b401aec6c84 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -951,36 +951,6 @@ static int aead_des3_setkey(struct crypto_aead *authenc,
goto out;
 }
 
-/*
- * talitos_edesc - s/w-extended descriptor
- * @src_nents: number of segments in input scatterlist
- * @dst_nents: number of segments in output scatterlist
- * @icv_ool: whether ICV is out-of-line
- * @iv_dma: dma address of iv for checking continuity and link table
- * @dma_len: length of dma mapped link_tbl space
- * @dma_link_tbl: bus physical address of link_tbl/buf
- * @desc: h/w descriptor
- * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1) (SEC2)
- * @buf: input and output buffeur (if {src,dst}_nents > 1) (SEC1)
- *
- * if decrypting (with authcheck), or either one of src_nents or dst_nents
- * is greater than 1, an integrity check value is concatenated to the end
- * of link_tbl data
- */
-struct talitos_edesc {
-   int src_nents;
-   int dst_nents;
-   bool icv_ool;
-   dma_addr_t iv_dma;
-   int dma_len;
-   dma_addr_t dma_link_tbl;
-   struct talitos_desc desc;
-   union {
-   struct talitos_ptr link_tbl[0];
-   u8 buf[0];
-   };
-};
-
 static void talitos_sg_unmap(struct device *dev,
 struct talitos_edesc *edesc,
 struct scatterlist *src,
diff --git a/drivers/crypto/talitos.h b/drivers/crypto/talitos.h
index 32ad4fc679ed..95f78c6d9206 100644
--- a/drivers/crypto/talitos.h
+++ b/drivers/crypto/talitos.h
@@ -42,6 +42,36 @@ struct talitos_desc {
 
 #define TALITOS_DESC_SIZE  (sizeof(struct talitos_desc) - sizeof(__be32))
 
+/*
+ * talitos_edesc - s/w-extended descriptor
+ * @src_nents: number of segments in input scatterlist
+ * @dst_nents: number of segments in output scatterlist
+ * @icv_ool: whether ICV is out-of-line
+ * @iv_dma: dma address of iv for checking continuity and link table
+ * @dma_len: length of dma mapped link_tbl space
+ * @dma_link_tbl: bus physical address of link_tbl/buf
+ * @desc: h/w descriptor
+ * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1) (SEC2)
+ * @buf: input and output buffeur (if {src,dst}_nents > 1) (SEC1)
+ *
+ * if decrypting (with authcheck), or either one of src_nents or dst_nents
+ * is greater than 1, an integrity check value is concatenated to the end
+ * of link_tbl data
+ */
+struct talitos_edesc {
+   int src_nents;
+   int dst_nents;
+   bool icv_ool;
+   dma_addr_t iv_dma;
+   int dma_len;
+   dma_addr_t dma_link_tbl;
+   struct talitos_desc desc;
+   union {
+   struct talitos_ptr link_tbl[0];
+   u8 buf[0];
+   };
+};
+
 /**
  * talitos_request - descriptor submission request
  * @desc: descriptor pointer (kernel virtual)
-- 
2.13.3



[PATCH v3 0/4] Additional fixes on Talitos driver

2019-06-13 Thread Christophe Leroy
This series is the last set of fixes for the Talitos driver.

We now get a fully clean boot on both SEC1 (SEC1.2 on mpc885) and
SEC2 (SEC2.2 on mpc8321E) with CONFIG_CRYPTO_MANAGER_EXTRA_TESTS:

[3.385197] bus: 'platform': really_probe: probing driver talitos with 
device ff02.crypto
[3.450982] random: fast init done
[   12.252548] alg: No test for authenc(hmac(md5),cbc(aes)) 
(authenc-hmac-md5-cbc-aes-talitos-hsna)
[   12.262226] alg: No test for authenc(hmac(md5),cbc(des3_ede)) 
(authenc-hmac-md5-cbc-3des-talitos-hsna)
[   43.310737] Bug in SEC1, padding ourself
[   45.603318] random: crng init done
[   54.612333] talitos ff02.crypto: fsl,sec1.2 algorithms registered in 
/proc/crypto
[   54.620232] driver: 'talitos': driver_bound: bound to device 
'ff02.crypto'

[1.193721] bus: 'platform': really_probe: probing driver talitos with 
device b003.crypto
[1.229197] random: fast init done
[2.714920] alg: No test for authenc(hmac(sha224),cbc(aes)) 
(authenc-hmac-sha224-cbc-aes-talitos)
[2.724312] alg: No test for authenc(hmac(sha224),cbc(aes)) 
(authenc-hmac-sha224-cbc-aes-talitos-hsna)
[4.482045] alg: No test for authenc(hmac(md5),cbc(aes)) 
(authenc-hmac-md5-cbc-aes-talitos)
[4.490940] alg: No test for authenc(hmac(md5),cbc(aes)) 
(authenc-hmac-md5-cbc-aes-talitos-hsna)
[4.500280] alg: No test for authenc(hmac(md5),cbc(des3_ede)) 
(authenc-hmac-md5-cbc-3des-talitos)
[4.509727] alg: No test for authenc(hmac(md5),cbc(des3_ede)) 
(authenc-hmac-md5-cbc-3des-talitos-hsna)
[6.631781] random: crng init done
[   11.521795] talitos b003.crypto: fsl,sec2.2 algorithms registered in 
/proc/crypto
[   11.529803] driver: 'talitos': driver_bound: bound to device 
'b003.crypto'

v2: dropped patch 1 which was irrelevant due to a rebase weirdness. Added Cc to 
stable on the 2 first patches.

v3:
 - removed stable reference in patch 1
 - reworded patch 1 to include name of patch 2 for the dependency.
 - mentionned this dependency in patch 2 as well.
 - corrected the Fixes: sha1 in patch 4

Christophe Leroy (4):
  crypto: talitos - move struct talitos_edesc into talitos.h
  crypto: talitos - fix hash on SEC1.
  crypto: talitos - eliminate unneeded 'done' functions at build time
  crypto: talitos - drop icv_ool

 drivers/crypto/talitos.c | 98 
 drivers/crypto/talitos.h | 28 ++
 2 files changed, 69 insertions(+), 57 deletions(-)

-- 
2.13.3



[PATCH v3 3/4] crypto: talitos - eliminate unneeded 'done' functions at build time

2019-06-13 Thread Christophe Leroy
When building for SEC1 only, talitos2_done functions are unneeded
and should go away.

For this, use has_ftr_sec1() which will always return true when only
SEC1 support is being built, allowing GCC to drop TALITOS2 functions.

Signed-off-by: Christophe Leroy 
Reviewed-by: Horia Geantă 
---
 drivers/crypto/talitos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 4f03baef952b..b2de931de623 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -3401,7 +3401,7 @@ static int talitos_probe(struct platform_device *ofdev)
if (err)
goto err_out;
 
-   if (of_device_is_compatible(np, "fsl,sec1.0")) {
+   if (has_ftr_sec1(priv)) {
if (priv->num_channels == 1)
tasklet_init(&priv->done_task[0], talitos1_done_ch0,
 (unsigned long)dev);
-- 
2.13.3



Re: [PATCH v2 1/4] crypto: talitos - move struct talitos_edesc into talitos.h

2019-06-13 Thread Horia Geanta
On 6/13/2019 3:32 PM, Christophe Leroy wrote:
> 
> 
> Le 13/06/2019 à 14:24, Horia Geanta a écrit :
>> On 6/13/2019 3:16 PM, Christophe Leroy wrote:
>>>
>>>
>>> Le 13/06/2019 à 14:13, Horia Geanta a écrit :
 On 6/11/2019 5:39 PM, Christophe Leroy wrote:
> Next patch will require struct talitos_edesc to be defined
> earlier in talitos.c
>
> This patch moves it into talitos.h so that it can be used
> from any place in talitos.c
>
> Fixes: 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash 
> on SEC1")
> Cc: sta...@vger.kernel.org
> Signed-off-by: Christophe Leroy 
 Again, this patch does not qualify as a fix.

>>>
>>> But as I said, the following one is a fix and require that one, you told
>>> me to add stable in Cc: to make it explicit it was to go into stable.
>> Yes, but you should remove the Fixes tag.
>> And probably replace "Next patch" with the commit headline.
>>
>>> If someone tries to merge following one into stable with taking that one
>>> first, build will fail.
>> This shouldn't happen, order from main tree should be preserved.
>>
> 
> When they pick up fixes, AFAIK they don't take all the preceeding commits.
> 
This is not about Fixes tag, but Cc tag:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1

Horia


Re: [PATCH v2 1/4] crypto: talitos - move struct talitos_edesc into talitos.h

2019-06-13 Thread Christophe Leroy




Le 13/06/2019 à 14:24, Horia Geanta a écrit :

On 6/13/2019 3:16 PM, Christophe Leroy wrote:



Le 13/06/2019 à 14:13, Horia Geanta a écrit :

On 6/11/2019 5:39 PM, Christophe Leroy wrote:

Next patch will require struct talitos_edesc to be defined
earlier in talitos.c

This patch moves it into talitos.h so that it can be used
from any place in talitos.c

Fixes: 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on 
SEC1")
Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Leroy 

Again, this patch does not qualify as a fix.



But as I said, the following one is a fix and require that one, you told
me to add stable in Cc: to make it explicit it was to go into stable.

Yes, but you should remove the Fixes tag.
And probably replace "Next patch" with the commit headline.


If someone tries to merge following one into stable with taking that one
first, build will fail.

This shouldn't happen, order from main tree should be preserved.



When they pick up fixes, AFAIK they don't take all the preceeding commits.

But ok, I'll resend.

Christophe


Re: [PATCH v2 4/4] crypto: talitos - drop icv_ool

2019-06-13 Thread Christophe Leroy




Le 13/06/2019 à 14:21, Horia Geanta a écrit :

On 6/11/2019 5:39 PM, Christophe Leroy wrote:

icv_ool is not used anymore, drop it.

Fixes: 9cc87bc3613b ("crypto: talitos - fix AEAD processing")

I can't find this SHA1.

Are you referring to commit e345177ded17 ("crypto: talitos - fix AEAD 
processing.")?

Horia



Oops yes, that's the sha1 it had in my tree before it got merged.

Do I have to resend it or can Herbert just drop the wrong reference and 
take the following one:


Fixes: e345177ded17 ("crypto: talitos - fix AEAD processing.")


Christophe


Re: [PATCH v2 1/4] crypto: talitos - move struct talitos_edesc into talitos.h

2019-06-13 Thread Horia Geanta
On 6/13/2019 3:16 PM, Christophe Leroy wrote:
> 
> 
> Le 13/06/2019 à 14:13, Horia Geanta a écrit :
>> On 6/11/2019 5:39 PM, Christophe Leroy wrote:
>>> Next patch will require struct talitos_edesc to be defined
>>> earlier in talitos.c
>>>
>>> This patch moves it into talitos.h so that it can be used
>>> from any place in talitos.c
>>>
>>> Fixes: 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on 
>>> SEC1")
>>> Cc: sta...@vger.kernel.org
>>> Signed-off-by: Christophe Leroy 
>> Again, this patch does not qualify as a fix.
>>
> 
> But as I said, the following one is a fix and require that one, you told 
> me to add stable in Cc: to make it explicit it was to go into stable.
Yes, but you should remove the Fixes tag.
And probably replace "Next patch" with the commit headline.

> If someone tries to merge following one into stable with taking that one 
> first, build will fail.
This shouldn't happen, order from main tree should be preserved.

Horia


Re: [PATCH v2 4/4] crypto: talitos - drop icv_ool

2019-06-13 Thread Horia Geanta
On 6/11/2019 5:39 PM, Christophe Leroy wrote:
> icv_ool is not used anymore, drop it.
> 
> Fixes: 9cc87bc3613b ("crypto: talitos - fix AEAD processing")
I can't find this SHA1.

Are you referring to commit e345177ded17 ("crypto: talitos - fix AEAD 
processing.")?

Horia


Re: [PATCH v2 3/4] crypto: talitos - eliminate unneeded 'done' functions at build time

2019-06-13 Thread Horia Geanta
On 6/11/2019 5:39 PM, Christophe Leroy wrote:
> When building for SEC1 only, talitos2_done functions are unneeded
> and should go away.
> 
> For this, use has_ftr_sec1() which will always return true when only
> SEC1 support is being built, allowing GCC to drop TALITOS2 functions.
> 
> Signed-off-by: Christophe Leroy 
Reviewed-by: Horia Geantă 

Thanks,
Horia


Re: [PATCH v2 1/4] crypto: talitos - move struct talitos_edesc into talitos.h

2019-06-13 Thread Christophe Leroy




Le 13/06/2019 à 14:13, Horia Geanta a écrit :

On 6/11/2019 5:39 PM, Christophe Leroy wrote:

Next patch will require struct talitos_edesc to be defined
earlier in talitos.c

This patch moves it into talitos.h so that it can be used
from any place in talitos.c

Fixes: 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on 
SEC1")
Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Leroy 

Again, this patch does not qualify as a fix.



But as I said, the following one is a fix and require that one, you told 
me to add stable in Cc: to make it explicit it was to go into stable.
If someone tries to merge following one into stable with taking that one 
first, build will fail.


Christophe


Re: [PATCH v2 1/4] crypto: talitos - move struct talitos_edesc into talitos.h

2019-06-13 Thread Horia Geanta
On 6/11/2019 5:39 PM, Christophe Leroy wrote:
> Next patch will require struct talitos_edesc to be defined
> earlier in talitos.c
> 
> This patch moves it into talitos.h so that it can be used
> from any place in talitos.c
> 
> Fixes: 37b5e8897eb5 ("crypto: talitos - chain in buffered data for ahash on 
> SEC1")
> Cc: sta...@vger.kernel.org
> Signed-off-by: Christophe Leroy 
Again, this patch does not qualify as a fix.

Horia


Re: [PATCH] powerpc: Enable kernel XZ compression option on PPC_85xx

2019-06-13 Thread Michael Ellerman
Daniel Axtens  writes:
> Pawel Dembicki  writes:
>
>> Enable kernel XZ compression option on PPC_85xx. Tested with
>> simpleImage on TP-Link TL-WDR4900 (Freescale P1014 processor).
>>
>> Suggested-by: Christian Lamparter 
>> Signed-off-by: Pawel Dembicki 
>> ---
>>  arch/powerpc/Kconfig | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
>> index 8c1c636308c8..daf4cb968922 100644
>> --- a/arch/powerpc/Kconfig
>> +++ b/arch/powerpc/Kconfig
>> @@ -196,7 +196,7 @@ config PPC
>>  select HAVE_IOREMAP_PROT
>>  select HAVE_IRQ_EXIT_ON_IRQ_STACK
>>  select HAVE_KERNEL_GZIP
>> -select HAVE_KERNEL_XZ   if PPC_BOOK3S || 44x
>> +select HAVE_KERNEL_XZ   if PPC_BOOK3S || 44x || PPC_85xx
>
> (I'm not super well versed in the compression stuff, so apologies if
> this is a dumb question.) If it's this simple, is there any reason we
> can't turn it on generally, or convert it to a blacklist of platforms
> known not to work?

For some platforms enabling XZ requires that your u-boot has XZ support,
and I'm not very clear on when that support landed in u-boot and what
boards have it. And there are boards out there with old/custom u-boots
that effectively can't be updated.

But as a server guy I don't really know the details of all that very
well. So if someone tells me that we should enable XZ for everything, or
as you say just black list some platforms, then that's fine by me.

cheers


[PATCH] mm: Generalize and rename notify_page_fault() as kprobe_page_fault()

2019-06-13 Thread Anshuman Khandual
Architectures which support kprobes have very similar boilerplate around
calling kprobe_fault_handler(). Use a helper function in kprobes.h to unify
them, based on the x86 code.

This changes the behaviour for other architectures when preemption is
enabled. Previously, they would have disabled preemption while calling the
kprobe handler. However, preemption would be disabled if this fault was
due to a kprobe, so we know the fault was not due to a kprobe handler and
can simply return failure.

This behaviour was introduced in the commit a980c0ef9f6d ("x86/kprobes:
Refactor kprobes_fault() like kprobe_exceptions_notify()")

Cc: linux-snps-...@lists.infradead.org
Cc: linux-m...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-i...@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: x...@kernel.org
Cc: Andrew Morton 
Cc: Michal Hocko 
Cc: Matthew Wilcox 
Cc: Mark Rutland 
Cc: Christophe Leroy 
Cc: Stephen Rothwell 
Cc: Andrey Konovalov 
Cc: Michael Ellerman 
Cc: Paul Mackerras 
Cc: Russell King 
Cc: Catalin Marinas 
Cc: Will Deacon 
Cc: Tony Luck 
Cc: Fenghua Yu 
Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: Yoshinori Sato 
Cc: "David S. Miller" 
Cc: Thomas Gleixner 
Cc: Peter Zijlstra 
Cc: Ingo Molnar 
Cc: Andy Lutomirski 
Cc: Dave Hansen 
Cc: Vineet Gupta 
Cc: James Hogan 
Cc: Paul Burton 
Cc: Ralf Baechle 

Reviewed-by: Dave Hansen 
Signed-off-by: Anshuman Khandual 
---
Questions:

AFAICT there is no equivalent of erstwhile notify_page_fault() during page
fault handling in arc and mips archs which can call this generic function.
Please let me know if that is not the case.

Testing:

- Build and boot tested on arm64 and x86
- Build tested on some other archs (arm, sparc64, alpha, powerpc etc)

Changes in V1:

- Updated commit message per Matthew
- Changed kprobe_page_fault() to return bool per Stephen/Dave/Christophe/Matthew
- Changed kprobe_page_fault() to follow x86 code flow per Dave/Matthew
- Changed kprobe_fault variable as bool in powerpc __do_page_fault()
- Added a comment to kprobe_page_fault() per Dave

Changes in RFC V3: (https://patchwork.kernel.org/patch/10981353/)

- Updated the commit message with an explanation for new preemption behaviour
- Moved notify_page_fault() to kprobes.h with 'static nokprobe_inline' per 
Matthew
- Changed notify_page_fault() return type from int to bool per Michael Ellerman
- Renamed notify_page_fault() as kprobe_page_fault() per Peterz

Changes in RFC V2: (https://patchwork.kernel.org/patch/10974221/)

- Changed generic notify_page_fault() per Mathew Wilcox
- Changed x86 to use new generic notify_page_fault()
- s/must not/need not/ in commit message per Matthew Wilcox

Changes in RFC V1: (https://patchwork.kernel.org/patch/10968273/)

 arch/arm/mm/fault.c  | 24 +---
 arch/arm64/mm/fault.c| 24 +---
 arch/ia64/mm/fault.c | 24 +---
 arch/powerpc/mm/fault.c  | 23 ++-
 arch/s390/mm/fault.c | 16 +---
 arch/sh/mm/fault.c   | 18 ++
 arch/sparc/mm/fault_64.c | 16 +---
 arch/x86/mm/fault.c  | 21 ++---
 include/linux/kprobes.h  | 19 +++
 9 files changed, 30 insertions(+), 155 deletions(-)

diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
index 58f69fa..94a97a4 100644
--- a/arch/arm/mm/fault.c
+++ b/arch/arm/mm/fault.c
@@ -30,28 +30,6 @@
 
 #ifdef CONFIG_MMU
 
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr)
-{
-   int ret = 0;
-
-   if (!user_mode(regs)) {
-   /* kprobe_running() needs smp_processor_id() */
-   preempt_disable();
-   if (kprobe_running() && kprobe_fault_handler(regs, fsr))
-   ret = 1;
-   preempt_enable();
-   }
-
-   return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr)
-{
-   return 0;
-}
-#endif
-
 /*
  * This is useful to dump out the page tables associated with
  * 'addr' in mm 'mm'.
@@ -266,7 +244,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct 
pt_regs *regs)
vm_fault_t fault;
unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
 
-   if (notify_page_fault(regs, fsr))
+   if (kprobe_page_fault(regs, fsr))
return 0;
 
tsk = current;
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index a30818e..8fe4bbc 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -70,28 +70,6 @@ static inline const struct fault_info 
*esr_to_debug_fault_info(unsigned int esr)
return debug_fault_info + DBG_ESR_EVT(esr);
 }
 
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs, unsigned int esr)
-{
-   int ret = 0;
-
-   /* kprobe_running() needs smp_processor_id() *

Re: [PATCH 1/2] powerpc/8xx: move CPM1 related files from sysdev/ to platforms/8xx

2019-06-13 Thread Christophe Leroy

Oops, I resent v1 together with v2. Sorry for the noise.

Le 13/06/2019 à 11:11, Christophe Leroy a écrit :

Only 8xx selects CPM1 and related CONFIG options are already
in platforms/8xx/Kconfig

This patch moves the related C files to platforms/8xx/.

Signed-off-by: Christophe Leroy 
---
  arch/powerpc/platforms/8xx/Makefile | 3 +++
  arch/powerpc/{sysdev => platforms/8xx}/cpm1.c   | 0
  arch/powerpc/{sysdev => platforms/8xx}/cpm_gpio.c   | 0
  arch/powerpc/{sysdev => platforms/8xx}/micropatch.c | 0
  arch/powerpc/sysdev/Makefile| 3 ---
  5 files changed, 3 insertions(+), 3 deletions(-)
  rename arch/powerpc/{sysdev => platforms/8xx}/cpm1.c (100%)
  rename arch/powerpc/{sysdev => platforms/8xx}/cpm_gpio.c (100%)
  rename arch/powerpc/{sysdev => platforms/8xx}/micropatch.c (100%)

diff --git a/arch/powerpc/platforms/8xx/Makefile 
b/arch/powerpc/platforms/8xx/Makefile
index 708ab099e886..10b338436655 100644
--- a/arch/powerpc/platforms/8xx/Makefile
+++ b/arch/powerpc/platforms/8xx/Makefile
@@ -3,6 +3,9 @@
  # Makefile for the PowerPC 8xx linux kernel.
  #
  obj-y += m8xx_setup.o machine_check.o pic.o
+obj-$(CONFIG_CPM1) += cpm1.o
+obj-$(CONFIG_UCODE_PATCH)  += micropatch.o
+obj-$(CONFIG_8xx_GPIO) += cpm_gpio.o
  obj-$(CONFIG_MPC885ADS)   += mpc885ads_setup.o
  obj-$(CONFIG_MPC86XADS)   += mpc86xads_setup.o
  obj-$(CONFIG_PPC_EP88XC)  += ep88xc.o
diff --git a/arch/powerpc/sysdev/cpm1.c b/arch/powerpc/platforms/8xx/cpm1.c
similarity index 100%
rename from arch/powerpc/sysdev/cpm1.c
rename to arch/powerpc/platforms/8xx/cpm1.c
diff --git a/arch/powerpc/sysdev/cpm_gpio.c 
b/arch/powerpc/platforms/8xx/cpm_gpio.c
similarity index 100%
rename from arch/powerpc/sysdev/cpm_gpio.c
rename to arch/powerpc/platforms/8xx/cpm_gpio.c
diff --git a/arch/powerpc/sysdev/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
similarity index 100%
rename from arch/powerpc/sysdev/micropatch.c
rename to arch/powerpc/platforms/8xx/micropatch.c
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index aaf23283ba0c..cfcade8270a9 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -37,12 +37,9 @@ obj-$(CONFIG_XILINX_PCI) += xilinx_pci.o
  obj-$(CONFIG_OF_RTC)  += of_rtc.o
  
  obj-$(CONFIG_CPM)		+= cpm_common.o

-obj-$(CONFIG_CPM1) += cpm1.o
  obj-$(CONFIG_CPM2)+= cpm2.o cpm2_pic.o cpm_gpio.o
-obj-$(CONFIG_8xx_GPIO) += cpm_gpio.o
  obj-$(CONFIG_QUICC_ENGINE)+= cpm_common.o
  obj-$(CONFIG_PPC_DCR) += dcr.o
-obj-$(CONFIG_UCODE_PATCH)  += micropatch.o
  
  obj-$(CONFIG_PPC_MPC512x)	+= mpc5xxx_clocks.o

  obj-$(CONFIG_PPC_MPC52xx) += mpc5xxx_clocks.o



Re: [PATCH] block/ps3vram: Use %llu to format sector_t after LBDAF removal

2019-06-13 Thread Jens Axboe
On 6/13/19 1:30 AM, Geert Uytterhoeven wrote:
> The removal of CONFIG_LBDAF changed the type of sector_t from "unsigned
> long" to "u64" aka "unsigned long long" on 64-bit platforms, leading to
> a compiler warning regression:
> 
>  drivers/block/ps3vram.c: In function ‘ps3vram_probe’:
>  drivers/block/ps3vram.c:770:23: warning: format ‘%lu’ expects argument 
> of type ‘long unsigned int’, but argument 4 has type ‘sector_t {aka long long 
> unsigned int}’ [-Wformat=]
> 
> Fix this by using "%llu" instead.

Applied, thanks.

-- 
Jens Axboe



[PATCH v2 10/10] powerpc/8xx: Add microcode patch to move SMC parameter RAM.

2019-06-13 Thread Christophe Leroy
Some SCC functions like the QMC requires an extended parameter RAM.
On modern 8xx (ie 866 and 885), SPI area can already be relocated,
allowing the use of those functions on SCC2. But SCC3 and SCC4
parameter RAM collide with SMC1 and SMC2 parameter RAMs.

This patch adds microcode to allow the relocation of both SMC1 and
SMC2, and relocate them at offsets 0x1ec0 and 0x1fc0.
Those offsets are by default for the CPM1 DSP1 and DSP2, but there
is no kernel driver using them at the moment so this area can be
reused.

This microcode is provided by Freescale/NXP in Engineering Bulletin
EB662 ("MPC8xx I2C/SPI and SMC Relocation Microcode Packages")
dated 2006. The binary code is public. The source is not available.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/Kconfig  |  7 +++
 arch/powerpc/platforms/8xx/micropatch.c | 97 +
 2 files changed, 104 insertions(+)

diff --git a/arch/powerpc/platforms/8xx/Kconfig 
b/arch/powerpc/platforms/8xx/Kconfig
index d408162d5af4..e0fe670f06f6 100644
--- a/arch/powerpc/platforms/8xx/Kconfig
+++ b/arch/powerpc/platforms/8xx/Kconfig
@@ -157,6 +157,13 @@ config I2C_SPI_SMC1_UCODE_PATCH
help
  Help not implemented yet, coming soon.
 
+config SMC_UCODE_PATCH
+   bool "SMC relocation patch"
+   help
+ This microcode relocates SMC1 and SMC2 parameter RAMs at
+ offset 0x1ec0 and 0x1fc0 to allow extended parameter RAM
+ for SCC3 and SCC4.
+
 endchoice
 
 config UCODE_PATCH
diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 986aa6978ab7..c571555c12d3 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -233,6 +233,94 @@ static uint patch_2f00[] __initdata = {
 static uint patch_2e00[] __initdata = {};
 #endif
 
+/*
+ * SMC relocation patch arrays.
+ */
+
+#ifdef CONFIG_SMC_UCODE_PATCH
+
+static char patch_name[] __initdata = "SMC";
+
+static struct patch_params patch_params __initdata = {
+   2, 0x8080, 0x8088,
+};
+
+static uint patch_2000[] __initdata = {
+   0x3fff, 0x3ffd, 0x3ffb, 0x3ff9,
+   0x5fefeff8, 0x5f91eff8, 0x3ff3, 0x3ff1,
+   0x3a11e710, 0xedf0ccb9, 0xf318ed66, 0x7f0e5fe2,
+   0x7fedbb38, 0x3afe7468, 0x7fedf4d8, 0x8ffbb92d,
+   0xb83b77fd, 0xb0bb5eb9, 0xdfda7fed, 0x90bde74d,
+   0x6f0dcbd3, 0xe7decfed, 0xcb50cfed, 0xcfeddf6d,
+   0x914d4f74, 0x5eaedfcb, 0x9ee0e7df, 0xefbb6ffb,
+   0xe7ef7f0e, 0x9ee57fed, 0xebb7effa, 0xeb30affb,
+   0x7fea90b3, 0x7e0cf09f, 0xb318, 0x5fffdfff,
+   0xac35efea, 0x7fce1fc1, 0xe2ff5fbd, 0xaffbe2ff,
+   0x5fbfaffb, 0xf9a87d0f, 0xaef8770f, 0x7d0fb0a2,
+   0xeffbbfff, 0xcfef5fba, 0x7d0fbfff, 0x5fba4cf8,
+   0x7fddd09b, 0x49f847fd, 0x7efdf097, 0x7fedfffd,
+   0x7dfdf093, 0xef7e7e1e, 0x5fba7f0e, 0x3a11e710,
+   0xedf0cc87, 0xfb18ad0a, 0x1f85bbb8, 0x74283b7e,
+   0x7375e4bb, 0x2ab64fb8, 0x5c7de4bb, 0x32fdffbf,
+   0x5f0843f8, 0x7ce3e1bb, 0xe74f7ded, 0x6f0f4fe8,
+   0xc7ba32be, 0x73f2efeb, 0x600b4f78, 0xe5bb760b,
+   0x5388aef8, 0x4ef80b6a, 0xcfef9ee5, 0xabf8751f,
+   0xefef5b88, 0x741f4fe8, 0x751e760d, 0x7fdb70dd,
+   0x741cafce, 0xefcc7fce, 0x751e7088, 0x741ce7bb,
+   0x334ecfed, 0xafdbefeb, 0xe5bb760b, 0x53ceaef8,
+   0xafe8e7eb, 0x4bf8771e, 0x7e007fed, 0x4fcbe2cc,
+   0x7fbc3085, 0x7b0f7a0f, 0x34b177fd, 0xb0e75e93,
+   0xdf313e3b, 0xaf78741f, 0x741f30cc, 0xcfef5f08,
+   0x741f3e88, 0xafb8771e, 0x5f437fed, 0x0bafe2cc,
+   0x741ccfec, 0xe5ca53a9, 0x6fcb4f74, 0x5e89df27,
+   0x2a923d14, 0x4b8fdf0c, 0x751f741c, 0x6c1eeffa,
+   0xefea7fce, 0x6ffc309a, 0xefec3fca, 0x308fdf0a,
+   0xadf85e7a, 0xaf7daefd, 0x5e7adf0a, 0x5e7aafdd,
+   0x761f1088, 0x1e7c7efd, 0x3089fffe, 0x4908fb18,
+   0x5fffdfff, 0xafbbf0f7, 0x4ef85f43, 0xadf81489,
+   0x7a0f7089, 0xcfef5089, 0x7a0fdf0c, 0x5e7cafed,
+   0xbc6e780f, 0xefef780f, 0xefef790f, 0xa7f85eeb,
+   0xffef790f, 0xefef790f, 0x1489df0a, 0x5e7aadfd,
+   0x5f09fffb, 0xe79aded9, 0xeff96079, 0x607ae79a,
+   0xded8eff9, 0x60795edb, 0x607acfef, 0xefefefdf,
+   0xefbfef7f, 0xeeffedff, 0xebffe7ff, 0xafefafdf,
+   0xafbfaf7f, 0xaeffadff, 0xabffa7ff, 0x6fef6fdf,
+   0x6fbf6f7f, 0x6eff6dff, 0x6bff67ff, 0x2fef2fdf,
+   0x2fbf2f7f, 0x2eff2dff, 0x2bff27ff, 0x4e08fd1f,
+   0xe5ff6e0f, 0xaff87eef, 0x7e0ffdef, 0xf11f6079,
+   0xabf8f51e, 0x7e0af11c, 0x37cfae16, 0x7fec909a,
+   0xadf8efdc, 0xcfeae52f, 0x7d0fe12b, 0xf11c6079,
+   0x7e0a4df8, 0xcfea5ea0, 0x7d0befec, 0xcfea5ea2,
+   0xe522efdc, 0x5ea2cfda, 0x4e08fd1f, 0x6e0faff8,
+   0x7c1f761f, 0xfdeff91f, 0x6079abf8, 0x761cee00,
+   0xf91f2bfb, 0xefefcfec, 0xf91f6079, 0x761c27fb,
+   0xefdf5e83, 0xcfdc7fdd, 0x50f84bf8, 0x47fd7c1f,
+   0x761ccfcf, 0x7eef7fed, 0x7dfd70ef, 0xef7e7f1e,
+   0x771efb18, 0x6079e722, 0xe6bbe5bb, 0x2e66e5bb,
+   0x600b2ee1, 0xe2bbe2

[PATCH v2 08/10] powerpc/8xx: replace #ifdefs by IS_ENABLED() in microcode.c

2019-06-13 Thread Christophe Leroy
Reduce #ifdef mess by using IS_ENABLED() instead.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 33 +
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 02490c54ebac..252db7c90599 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -243,14 +243,9 @@ static void __init cpm_write_patch(cpm8xx_t *cp, int 
offset, uint *patch, int le
 void __init cpm_load_patch(cpm8xx_t *cp)
 {
volatile cpm8xx_t   *commproc;
-#if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
-defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
volatile iic_t  *iip;
volatile struct spi_pram *spp;
-#ifdef CONFIG_I2C_SPI_SMC1_UCODE_PATCH
volatile smc_uart_t *smp;
-#endif
-#endif
commproc = cp;
 
commproc->cp_rccr = 0;
@@ -259,24 +254,22 @@ void __init cpm_load_patch(cpm8xx_t *cp)
cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
 
-#if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
-defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
-
-   iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
-# define RPBASE 0x0500
-   iip->iic_rpbase = RPBASE;
+   if (IS_ENABLED(CONFIG_I2C_SPI_UCODE_PATCH) ||
+   IS_ENABLED(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)) {
+   u16 rpbase = 0x500;
 
-   /* Put SPI above the IIC, also 32-byte aligned.
-   */
-   spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
-   spp->rpbase = (RPBASE + sizeof(iic_t) + 31) & ~31;
+   iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
+   iip->iic_rpbase = rpbase;
 
-# if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
-   smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
-   smp->smc_rpbase = 0x1FC0;
-# endif /* CONFIG_I2C_SPI_SMC1_UCODE_PATCH) */
+   /* Put SPI above the IIC, also 32-byte aligned. */
+   spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
+   spp->rpbase = (rpbase + sizeof(iic_t) + 31) & ~31;
 
-#endif /* some variation of the I2C/SPI patch was selected */
+   if (IS_ENABLED(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)) {
+   smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
+   smp->smc_rpbase = 0x1FC0;
+   }
+   }
 
commproc->cp_cpmcr1 = patch_params.cpmcr1;
commproc->cp_cpmcr2 = patch_params.cpmcr2;
-- 
2.13.3



[PATCH v2 09/10] powerpc/8xx: Use IO accessors in microcode programming.

2019-06-13 Thread Christophe Leroy
Change microcode functions to use IO accessors and get rid
of volatile attributes.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 34 -
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 252db7c90599..986aa6978ab7 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -242,13 +242,7 @@ static void __init cpm_write_patch(cpm8xx_t *cp, int 
offset, uint *patch, int le
 
 void __init cpm_load_patch(cpm8xx_t *cp)
 {
-   volatile cpm8xx_t   *commproc;
-   volatile iic_t  *iip;
-   volatile struct spi_pram *spp;
-   volatile smc_uart_t *smp;
-   commproc = cp;
-
-   commproc->cp_rccr = 0;
+   out_be16(&cp->cp_rccr, 0);
 
cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
@@ -257,26 +251,30 @@ void __init cpm_load_patch(cpm8xx_t *cp)
if (IS_ENABLED(CONFIG_I2C_SPI_UCODE_PATCH) ||
IS_ENABLED(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)) {
u16 rpbase = 0x500;
+   iic_t *iip;
+   struct spi_pram *spp;
 
-   iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
-   iip->iic_rpbase = rpbase;
+   iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
+   out_be16(&iip->iic_rpbase, rpbase);
 
/* Put SPI above the IIC, also 32-byte aligned. */
-   spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
-   spp->rpbase = (rpbase + sizeof(iic_t) + 31) & ~31;
+   spp = (struct spi_pram *)&cp->cp_dparam[PROFF_SPI];
+   out_be16(&spp->rpbase, (rpbase + sizeof(iic_t) + 31) & ~31);
 
if (IS_ENABLED(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)) {
-   smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
-   smp->smc_rpbase = 0x1FC0;
+   smc_uart_t *smp;
+
+   smp = (smc_uart_t *)&cp->cp_dparam[PROFF_SMC1];
+   out_be16(&smp->smc_rpbase, 0x1FC0);
}
}
 
-   commproc->cp_cpmcr1 = patch_params.cpmcr1;
-   commproc->cp_cpmcr2 = patch_params.cpmcr2;
-   commproc->cp_cpmcr3 = patch_params.cpmcr3;
-   commproc->cp_cpmcr4 = patch_params.cpmcr4;
+   out_be16(&cp->cp_cpmcr1, patch_params.cpmcr1);
+   out_be16(&cp->cp_cpmcr2, patch_params.cpmcr2);
+   out_be16(&cp->cp_cpmcr3, patch_params.cpmcr3);
+   out_be16(&cp->cp_cpmcr4, patch_params.cpmcr4);
 
-   commproc->cp_rccr = patch_params.rccr;
+   out_be16(&cp->cp_rccr, patch_params.rccr);
 
pr_info("%s microcode patch installed\n", patch_name);
 }
-- 
2.13.3



[PATCH v2 06/10] powerpc/8xx: refactor printing of microcode patch name.

2019-06-13 Thread Christophe Leroy
Define patch name together with the patch code, and refactor
the associated printk() while replacing it by a pr_info()

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 410968a0b177..5e5ac2378d3f 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -26,6 +26,8 @@
 
 #ifdef CONFIG_I2C_SPI_UCODE_PATCH
 
+static char patch_name[] __initdata = "I2C/SPI";
+
 static uint patch_2000[] __initdata = {
0x7FFFEFD9, 0x3FFD, 0x7FFB49F7, 0x7FF9,
0x5FEFADF7, 0x5F89ADF7, 0x5FEFAFF7, 0x5F89AFF7,
@@ -78,6 +80,8 @@ static uint patch_2e00[] __initdata = {};
 
 #ifdef CONFIG_I2C_SPI_SMC1_UCODE_PATCH
 
+static char patch_name[] __initdata = "I2C/SPI/SMC1";
+
 static uint patch_2000[] __initdata = {
0x3fff, 0x3ffd, 0x3ffb, 0x3ff9,
0x5f13eff8, 0x5eb5eff8, 0x5f88adf7, 0x5fefadf7,
@@ -194,6 +198,8 @@ static uint patch_2e00[] __initdata = {
 
 #ifdef CONFIG_USB_SOF_UCODE_PATCH
 
+static char patch_name[] __initdata = "USB SOF";
+
 static uint patch_2000[] __initdata = {
0x7fff, 0x7ffd, 0x7ffb, 0x49f7ba5b,
0xba383ffb, 0xf9b8b46d, 0xe5ab4e07, 0xaf77bffe,
@@ -235,8 +241,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
 #ifdef CONFIG_USB_SOF_UCODE_PATCH
commproc->cp_rccr = 0x0009;
-
-   printk("USB SOF microcode patch installed\n");
 #endif /* CONFIG_USB_SOF_UCODE_PATCH */
 
 #if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
@@ -257,8 +261,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
commproc->cp_cpmcr3 = 0x802e;
commproc->cp_cpmcr4 = 0x802c;
commproc->cp_rccr = 1;
-
-   printk("I2C/SPI microcode patch installed.\n");
 # endif /* CONFIG_I2C_SPI_UCODE_PATCH */
 
 # if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
@@ -270,9 +272,9 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
smp->smc_rpbase = 0x1FC0;
-
-   printk("I2C/SPI/SMC1 microcode patch installed.\n");
 # endif /* CONFIG_I2C_SPI_SMC1_UCODE_PATCH) */
 
 #endif /* some variation of the I2C/SPI patch was selected */
+
+   pr_info("%s microcode patch installed\n", patch_name);
 }
-- 
2.13.3



[PATCH v2 07/10] powerpc/8xx: refactor programming of microcode CPM params.

2019-06-13 Thread Christophe Leroy
The CPM registers RCCR and CPMCR1..4 registers has to be set in
accordance with the microcode patch beeing programmed. Lets
define them as part of the patch set and refactor their
programming from that definition.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 45 -
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 5e5ac2378d3f..02490c54ebac 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -20,6 +20,14 @@
 #include 
 #include 
 
+struct patch_params {
+   ushort rccr;
+   ushort cpmcr1;
+   ushort cpmcr2;
+   ushort cpmcr3;
+   ushort cpmcr4;
+};
+
 /*
  * I2C/SPI relocation patch arrays.
  */
@@ -28,6 +36,10 @@
 
 static char patch_name[] __initdata = "I2C/SPI";
 
+static struct patch_params patch_params __initdata = {
+   1, 0x802a, 0x8028, 0x802e, 0x802c,
+};
+
 static uint patch_2000[] __initdata = {
0x7FFFEFD9, 0x3FFD, 0x7FFB49F7, 0x7FF9,
0x5FEFADF7, 0x5F89ADF7, 0x5FEFAFF7, 0x5F89AFF7,
@@ -82,6 +94,10 @@ static uint patch_2e00[] __initdata = {};
 
 static char patch_name[] __initdata = "I2C/SPI/SMC1";
 
+static struct patch_params patch_params __initdata = {
+   3, 0x8080, 0x808a, 0x8028, 0x802a,
+};
+
 static uint patch_2000[] __initdata = {
0x3fff, 0x3ffd, 0x3ffb, 0x3ff9,
0x5f13eff8, 0x5eb5eff8, 0x5f88adf7, 0x5fefadf7,
@@ -200,6 +216,10 @@ static uint patch_2e00[] __initdata = {
 
 static char patch_name[] __initdata = "USB SOF";
 
+static struct patch_params patch_params __initdata = {
+   9,
+};
+
 static uint patch_2000[] __initdata = {
0x7fff, 0x7ffd, 0x7ffb, 0x49f7ba5b,
0xba383ffb, 0xf9b8b46d, 0xe5ab4e07, 0xaf77bffe,
@@ -239,10 +259,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
 
-#ifdef CONFIG_USB_SOF_UCODE_PATCH
-   commproc->cp_rccr = 0x0009;
-#endif /* CONFIG_USB_SOF_UCODE_PATCH */
-
 #if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
 defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
 
@@ -255,26 +271,19 @@ void __init cpm_load_patch(cpm8xx_t *cp)
spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
spp->rpbase = (RPBASE + sizeof(iic_t) + 31) & ~31;
 
-# if defined(CONFIG_I2C_SPI_UCODE_PATCH)
-   commproc->cp_cpmcr1 = 0x802a;
-   commproc->cp_cpmcr2 = 0x8028;
-   commproc->cp_cpmcr3 = 0x802e;
-   commproc->cp_cpmcr4 = 0x802c;
-   commproc->cp_rccr = 1;
-# endif /* CONFIG_I2C_SPI_UCODE_PATCH */
-
 # if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
-   commproc->cp_cpmcr1 = 0x8080;
-   commproc->cp_cpmcr2 = 0x808a;
-   commproc->cp_cpmcr3 = 0x8028;
-   commproc->cp_cpmcr4 = 0x802a;
-   commproc->cp_rccr = 3;
-
smp = (smc_uart_t *)&commproc->cp_dparam[PROFF_SMC1];
smp->smc_rpbase = 0x1FC0;
 # endif /* CONFIG_I2C_SPI_SMC1_UCODE_PATCH) */
 
 #endif /* some variation of the I2C/SPI patch was selected */
 
+   commproc->cp_cpmcr1 = patch_params.cpmcr1;
+   commproc->cp_cpmcr2 = patch_params.cpmcr2;
+   commproc->cp_cpmcr3 = patch_params.cpmcr3;
+   commproc->cp_cpmcr4 = patch_params.cpmcr4;
+
+   commproc->cp_rccr = patch_params.rccr;
+
pr_info("%s microcode patch installed\n", patch_name);
 }
-- 
2.13.3



[PATCH v2 04/10] powerpc/8xx: refactor writing of CPM microcode arrays

2019-06-13 Thread Christophe Leroy
Create a function to refactor the writing of CPM microcode arrays.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 35 -
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index e14b6bcadce3..2abc226d1139 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -203,9 +203,15 @@ static uint patch_2f00[] __initdata = {
 };
 #endif
 
+static void __init cpm_write_patch(cpm8xx_t *cp, int offset, uint *patch, int 
len)
+{
+   if (!len)
+   return;
+   memcpy_toio(cp->cp_dpmem + offset, patch, len);
+}
+
 void __init cpm_load_patch(cpm8xx_t *cp)
 {
-   volatile uint   *dp;/* Dual-ported RAM. */
volatile cpm8xx_t   *commproc;
 #if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
 defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
@@ -215,20 +221,13 @@ void __init cpm_load_patch(cpm8xx_t *cp)
volatile smc_uart_t *smp;
 #endif
 #endif
-   int i;
-
commproc = cp;
 
 #ifdef CONFIG_USB_SOF_UCODE_PATCH
commproc->cp_rccr = 0;
 
-   dp = (uint *)(commproc->cp_dpmem);
-   for (i=0; i<(sizeof(patch_2000)/4); i++)
-   *dp++ = patch_2000[i];
-
-   dp = (uint *)&(commproc->cp_dpmem[0x0f00]);
-   for (i=0; i<(sizeof(patch_2f00)/4); i++)
-   *dp++ = patch_2f00[i];
+   cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
+   cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
 
commproc->cp_rccr = 0x0009;
 
@@ -240,13 +239,8 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
commproc->cp_rccr = 0;
 
-   dp = (uint *)(commproc->cp_dpmem);
-   for (i=0; i<(sizeof(patch_2000)/4); i++)
-   *dp++ = patch_2000[i];
-
-   dp = (uint *)&(commproc->cp_dpmem[0x0f00]);
-   for (i=0; i<(sizeof(patch_2f00)/4); i++)
-   *dp++ = patch_2f00[i];
+   cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
+   cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
 
iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
 # define RPBASE 0x0500
@@ -254,9 +248,8 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
/* Put SPI above the IIC, also 32-byte aligned.
*/
-   i = (RPBASE + sizeof(iic_t) + 31) & ~31;
spp = (struct spi_pram *)&commproc->cp_dparam[PROFF_SPI];
-   spp->rpbase = i;
+   spp->rpbase = (RPBASE + sizeof(iic_t) + 31) & ~31;
 
 # if defined(CONFIG_I2C_SPI_UCODE_PATCH)
commproc->cp_cpmcr1 = 0x802a;
@@ -270,9 +263,7 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
 # if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
 
-   dp = (uint *)&(commproc->cp_dpmem[0x0e00]);
-   for (i=0; i<(sizeof(patch_2e00)/4); i++)
-   *dp++ = patch_2e00[i];
+   cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
 
commproc->cp_cpmcr1 = 0x8080;
commproc->cp_cpmcr2 = 0x808a;
-- 
2.13.3



[PATCH v2 05/10] powerpc/8xx: Refactor microcode write

2019-06-13 Thread Christophe Leroy
Add empty microcode tables so that all tables are defined
all the time. Regroup the writing of the 3 tables regardless
of the selected microcode.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 2abc226d1139..410968a0b177 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -68,6 +68,8 @@ static uint patch_2f00[] __initdata = {
0x31497353, 0x76956D69, 0x7B9D9693, 0x13131979,
0x79376935
 };
+
+static uint patch_2e00[] __initdata = {};
 #endif
 
 /*
@@ -201,6 +203,8 @@ static uint patch_2000[] __initdata = {
 static uint patch_2f00[] __initdata = {
0x3030304c, 0xcab9e441, 0xa1aaf220
 };
+
+static uint patch_2e00[] __initdata = {};
 #endif
 
 static void __init cpm_write_patch(cpm8xx_t *cp, int offset, uint *patch, int 
len)
@@ -223,12 +227,13 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 #endif
commproc = cp;
 
-#ifdef CONFIG_USB_SOF_UCODE_PATCH
commproc->cp_rccr = 0;
 
cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
+   cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
 
+#ifdef CONFIG_USB_SOF_UCODE_PATCH
commproc->cp_rccr = 0x0009;
 
printk("USB SOF microcode patch installed\n");
@@ -237,11 +242,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 #if defined(CONFIG_I2C_SPI_UCODE_PATCH) || \
 defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
 
-   commproc->cp_rccr = 0;
-
-   cpm_write_patch(cp, 0, patch_2000, sizeof(patch_2000));
-   cpm_write_patch(cp, 0xf00, patch_2f00, sizeof(patch_2f00));
-
iip = (iic_t *)&commproc->cp_dparam[PROFF_IIC];
 # define RPBASE 0x0500
iip->iic_rpbase = RPBASE;
@@ -262,9 +262,6 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 # endif /* CONFIG_I2C_SPI_UCODE_PATCH */
 
 # if defined(CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
-
-   cpm_write_patch(cp, 0xe00, patch_2e00, sizeof(patch_2e00));
-
commproc->cp_cpmcr1 = 0x8080;
commproc->cp_cpmcr2 = 0x808a;
commproc->cp_cpmcr3 = 0x8028;
-- 
2.13.3



[PATCH v2 03/10] powerpc/8xx: compact microcode arrays

2019-06-13 Thread Christophe Leroy
Compact obscure microcode arrays by putting 4 values per line
in order to reduce number of lines in the file to increase
readability.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 699 +++-
 1 file changed, 140 insertions(+), 559 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 7bbaf9914f32..e14b6bcadce3 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -27,153 +27,45 @@
 #ifdef CONFIG_I2C_SPI_UCODE_PATCH
 
 static uint patch_2000[] __initdata = {
-   0x7FFFEFD9,
-   0x3FFD,
-   0x7FFB49F7,
-   0x7FF9,
-   0x5FEFADF7,
-   0x5F89ADF7,
-   0x5FEFAFF7,
-   0x5F89AFF7,
-   0x3A9CFBC8,
-   0xE7C0EDF0,
-   0x77C1E1BB,
-   0xF4DC7F1D,
-   0xABAD932F,
-   0x4E08FDCF,
-   0x6E0FAFF8,
-   0x7CCF76CF,
-   0xFD1FF9CF,
-   0xABF88DC6,
-   0xAB5679F7,
-   0xB0937383,
-   0xDFCE79F7,
-   0xB091E6BB,
-   0xE5BBE74F,
-   0xB3FA6F0F,
-   0x6FFB76CE,
-   0xEE0DF9CF,
-   0x2BFBEFEF,
-   0xCFEEF9CF,
-   0x76CEAD24,
-   0x90B2DF9A,
-   0x7FDDD0BF,
-   0x4BF847FD,
-   0x7CCF76CE,
-   0xCFEF7E1F,
-   0x7F1D7DFD,
-   0xF0B6EF71,
-   0x7FC177C1,
-   0xFBC86079,
-   0xE722FBC8,
-   0x5FFFDFFF,
-   0x5FB2FFFB,
-   0xFBC8F3C8,
-   0x94A67F01,
-   0x7F1D5F39,
-   0xAFE85F5E,
-   0xFFDFDF96,
-   0xCB9FAF7D,
-   0x5FC1AFED,
-   0x8C1C5FC1,
-   0xAFDD5FC3,
-   0xDF9A7EFD,
-   0xB0B25FB2,
-   0xFFFEABAD,
-   0x5FB2FFFE,
-   0x5FCE600B,
-   0xE6BB600B,
-   0x5FCEDFC6,
-   0x27FBEFDF,
-   0x5FC8CFDE,
-   0x3A9CE7C0,
-   0xEDF0F3C8,
-   0x7F0154CD,
-   0x7F1D2D3D,
-   0x363A7570,
-   0x7E0AF1CE,
-   0x37EF2E68,
-   0x7FEE10EC,
-   0xADF8EFDE,
-   0xCFEAE52F,
-   0x7D0FE12B,
-   0xF1CE5F65,
-   0x7E0A4DF8,
-   0xCFEA5F72,
-   0x7D0BEFEE,
-   0xCFEA5F74,
-   0xE522EFDE,
-   0x5F74CFDA,
-   0x0B627385,
-   0xDF627E0A,
-   0x30D8145B,
-   0xB3C8,
-   0x5FFFDFFF,
-   0xA7F85F5E,
-   0xBFFE7F7D,
-   0x10D31450,
-   0x5F36BFFF,
-   0xAF785F5E,
-   0xBFFDA7F8,
-   0x5F36BFFE,
-   0x77FD30C0,
-   0x4E08FDCF,
-   0xE5FF6E0F,
-   0xAFF87E1F,
-   0x7E0FFD1F,
-   0xF1CF5F1B,
-   0xABF80D5E,
-   0x5F5EFFEF,
-   0x79F730A2,
-   0xAFDD5F34,
-   0x47F85F34,
-   0xAFED7FDD,
-   0x50B24978,
-   0x47FD7F1D,
-   0x7DFD70AD,
-   0xEF717EC1,
-   0x6BA47F01,
-   0x2D267EFD,
-   0x30DE5F5E,
-   0xFFFD5F5E,
-   0xFFEF5F5E,
-   0xFFDF0CA0,
-   0xAFED0A9E,
-   0xAFDD0C3A,
-   0x5F3AAFBD,
-   0x7FBDB082,
-   0x5F8247F8
+   0x7FFFEFD9, 0x3FFD, 0x7FFB49F7, 0x7FF9,
+   0x5FEFADF7, 0x5F89ADF7, 0x5FEFAFF7, 0x5F89AFF7,
+   0x3A9CFBC8, 0xE7C0EDF0, 0x77C1E1BB, 0xF4DC7F1D,
+   0xABAD932F, 0x4E08FDCF, 0x6E0FAFF8, 0x7CCF76CF,
+   0xFD1FF9CF, 0xABF88DC6, 0xAB5679F7, 0xB0937383,
+   0xDFCE79F7, 0xB091E6BB, 0xE5BBE74F, 0xB3FA6F0F,
+   0x6FFB76CE, 0xEE0DF9CF, 0x2BFBEFEF, 0xCFEEF9CF,
+   0x76CEAD24, 0x90B2DF9A, 0x7FDDD0BF, 0x4BF847FD,
+   0x7CCF76CE, 0xCFEF7E1F, 0x7F1D7DFD, 0xF0B6EF71,
+   0x7FC177C1, 0xFBC86079, 0xE722FBC8, 0x5FFFDFFF,
+   0x5FB2FFFB, 0xFBC8F3C8, 0x94A67F01, 0x7F1D5F39,
+   0xAFE85F5E, 0xFFDFDF96, 0xCB9FAF7D, 0x5FC1AFED,
+   0x8C1C5FC1, 0xAFDD5FC3, 0xDF9A7EFD, 0xB0B25FB2,
+   0xFFFEABAD, 0x5FB2FFFE, 0x5FCE600B, 0xE6BB600B,
+   0x5FCEDFC6, 0x27FBEFDF, 0x5FC8CFDE, 0x3A9CE7C0,
+   0xEDF0F3C8, 0x7F0154CD, 0x7F1D2D3D, 0x363A7570,
+   0x7E0AF1CE, 0x37EF2E68, 0x7FEE10EC, 0xADF8EFDE,
+   0xCFEAE52F, 0x7D0FE12B, 0xF1CE5F65, 0x7E0A4DF8,
+   0xCFEA5F72, 0x7D0BEFEE, 0xCFEA5F74, 0xE522EFDE,
+   0x5F74CFDA, 0x0B627385, 0xDF627E0A, 0x30D8145B,
+   0xB3C8, 0x5FFFDFFF, 0xA7F85F5E, 0xBFFE7F7D,
+   0x10D31450, 0x5F36BFFF, 0xAF785F5E, 0xBFFDA7F8,
+   0x5F36BFFE, 0x77FD30C0, 0x4E08FDCF, 0xE5FF6E0F,
+   0xAFF87E1F, 0x7E0FFD1F, 0xF1CF5F1B, 0xABF80D5E,
+   0x5F5EFFEF, 0x79F730A2, 0xAFDD5F34, 0x47F85F34,
+   0xAFED7FDD, 0x50B24978, 0x47FD7F1D, 0x7DFD70AD,
+   0xEF717EC1, 0x6BA47F01, 0x2D267EFD, 0x30DE5F5E,
+   0xFFFD5F5E, 0xFFEF5F5E, 0xFFDF0CA0, 0xAFED0A9E,
+   0xAFDD0C3A, 0x5F3AAFBD, 0x7FBDB082, 0x5F8247F8
 };
 
 static uint patch_2f00[] __initdata = {
-   0x3E303430,
-   0x34343737,
-   0xABF7BF9B,
-   0x994B4FBD,
-   0xBD599493,
-   0x349FFF37,
-   0xFB9B177D,
-   0xD9936956,
-   0xBBFDD697,
-   0xBDD2FD11,
-   0x31DB9BB3,
-   0x63139637,
-   0x93733693,
-   0x193137F7,
-   0x331737AF,
-   0x7BB9B999,
-   0xBB197957,
-   0x7FDFD3D5,
-   0x73B773F

[PATCH v2 02/10] powerpc/8xx: drop verify_patch()

2019-06-13 Thread Christophe Leroy
verify_patch() has been opted out since many years, and
the comment suggests it doesn't work. So drop it.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/micropatch.c | 40 -
 1 file changed, 40 deletions(-)

diff --git a/arch/powerpc/platforms/8xx/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
index 33a9042fca80..7bbaf9914f32 100644
--- a/arch/powerpc/platforms/8xx/micropatch.c
+++ b/arch/powerpc/platforms/8xx/micropatch.c
@@ -707,43 +707,3 @@ void __init cpm_load_patch(cpm8xx_t *cp)
 
 #endif /* some variation of the I2C/SPI patch was selected */
 }
-
-/*
- *  Take this entire routine out, since no one calls it and its
- * logic is suspect.
- */
-
-#if 0
-void
-verify_patch(volatile immap_t *immr)
-{
-   volatile uint   *dp;
-   volatile cpm8xx_t   *commproc;
-   int i;
-
-   commproc = (cpm8xx_t *)&immr->im_cpm;
-
-   printk("cp_rccr %x\n", commproc->cp_rccr);
-   commproc->cp_rccr = 0;
-
-   dp = (uint *)(commproc->cp_dpmem);
-   for (i=0; i<(sizeof(patch_2000)/4); i++)
-   if (*dp++ != patch_2000[i]) {
-   printk("patch_2000 bad at %d\n", i);
-   dp--;
-   printk("found 0x%X, wanted 0x%X\n", *dp, patch_2000[i]);
-   break;
-   }
-
-   dp = (uint *)&(commproc->cp_dpmem[0x0f00]);
-   for (i=0; i<(sizeof(patch_2f00)/4); i++)
-   if (*dp++ != patch_2f00[i]) {
-   printk("patch_2f00 bad at %d\n", i);
-   dp--;
-   printk("found 0x%X, wanted 0x%X\n", *dp, patch_2f00[i]);
-   break;
-   }
-
-   commproc->cp_rccr = 0x0009;
-}
-#endif
-- 
2.13.3



[PATCH v2 01/10] powerpc/8xx: move CPM1 related files from sysdev/ to platforms/8xx

2019-06-13 Thread Christophe Leroy
Only 8xx selects CPM1 and related CONFIG options are already
in platforms/8xx/Kconfig

Move the related C files to platforms/8xx/.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/8xx/Makefile | 3 +++
 arch/powerpc/{sysdev => platforms/8xx}/cpm1.c   | 0
 arch/powerpc/{sysdev => platforms/8xx}/cpm_gpio.c   | 0
 arch/powerpc/{sysdev => platforms/8xx}/micropatch.c | 0
 arch/powerpc/sysdev/Makefile| 3 ---
 5 files changed, 3 insertions(+), 3 deletions(-)
 rename arch/powerpc/{sysdev => platforms/8xx}/cpm1.c (100%)
 rename arch/powerpc/{sysdev => platforms/8xx}/cpm_gpio.c (100%)
 rename arch/powerpc/{sysdev => platforms/8xx}/micropatch.c (100%)

diff --git a/arch/powerpc/platforms/8xx/Makefile 
b/arch/powerpc/platforms/8xx/Makefile
index 708ab099e886..10b338436655 100644
--- a/arch/powerpc/platforms/8xx/Makefile
+++ b/arch/powerpc/platforms/8xx/Makefile
@@ -3,6 +3,9 @@
 # Makefile for the PowerPC 8xx linux kernel.
 #
 obj-y  += m8xx_setup.o machine_check.o pic.o
+obj-$(CONFIG_CPM1) += cpm1.o
+obj-$(CONFIG_UCODE_PATCH)  += micropatch.o
+obj-$(CONFIG_8xx_GPIO) += cpm_gpio.o
 obj-$(CONFIG_MPC885ADS)   += mpc885ads_setup.o
 obj-$(CONFIG_MPC86XADS)   += mpc86xads_setup.o
 obj-$(CONFIG_PPC_EP88XC)  += ep88xc.o
diff --git a/arch/powerpc/sysdev/cpm1.c b/arch/powerpc/platforms/8xx/cpm1.c
similarity index 100%
rename from arch/powerpc/sysdev/cpm1.c
rename to arch/powerpc/platforms/8xx/cpm1.c
diff --git a/arch/powerpc/sysdev/cpm_gpio.c 
b/arch/powerpc/platforms/8xx/cpm_gpio.c
similarity index 100%
rename from arch/powerpc/sysdev/cpm_gpio.c
rename to arch/powerpc/platforms/8xx/cpm_gpio.c
diff --git a/arch/powerpc/sysdev/micropatch.c 
b/arch/powerpc/platforms/8xx/micropatch.c
similarity index 100%
rename from arch/powerpc/sysdev/micropatch.c
rename to arch/powerpc/platforms/8xx/micropatch.c
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index aaf23283ba0c..cfcade8270a9 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -37,12 +37,9 @@ obj-$(CONFIG_XILINX_PCI) += xilinx_pci.o
 obj-$(CONFIG_OF_RTC)   += of_rtc.o
 
 obj-$(CONFIG_CPM)  += cpm_common.o
-obj-$(CONFIG_CPM1) += cpm1.o
 obj-$(CONFIG_CPM2) += cpm2.o cpm2_pic.o cpm_gpio.o
-obj-$(CONFIG_8xx_GPIO) += cpm_gpio.o
 obj-$(CONFIG_QUICC_ENGINE) += cpm_common.o
 obj-$(CONFIG_PPC_DCR)  += dcr.o
-obj-$(CONFIG_UCODE_PATCH)  += micropatch.o
 
 obj-$(CONFIG_PPC_MPC512x)  += mpc5xxx_clocks.o
 obj-$(CONFIG_PPC_MPC52xx)  += mpc5xxx_clocks.o
-- 
2.13.3



[PATCH] block/ps3vram: Use %llu to format sector_t after LBDAF removal

2019-06-13 Thread Geert Uytterhoeven
The removal of CONFIG_LBDAF changed the type of sector_t from "unsigned
long" to "u64" aka "unsigned long long" on 64-bit platforms, leading to
a compiler warning regression:

drivers/block/ps3vram.c: In function ‘ps3vram_probe’:
drivers/block/ps3vram.c:770:23: warning: format ‘%lu’ expects argument of 
type ‘long unsigned int’, but argument 4 has type ‘sector_t {aka long long 
unsigned int}’ [-Wformat=]

Fix this by using "%llu" instead.

Fixes: 72deb455b5ec619f ("block: remove CONFIG_LBDAF")
Signed-off-by: Geert Uytterhoeven 
---
 drivers/block/ps3vram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
index 4c7f51b1eda94727..4628e1a27a2b7133 100644
--- a/drivers/block/ps3vram.c
+++ b/drivers/block/ps3vram.c
@@ -767,7 +767,7 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
strlcpy(gendisk->disk_name, DEVICE_NAME, sizeof(gendisk->disk_name));
set_capacity(gendisk, priv->size >> 9);
 
-   dev_info(&dev->core, "%s: Using %lu MiB of GPU memory\n",
+   dev_info(&dev->core, "%s: Using %llu MiB of GPU memory\n",
 gendisk->disk_name, get_capacity(gendisk) >> 11);
 
device_add_disk(&dev->core, gendisk, NULL);
-- 
2.17.1



[PATCH 5.1 038/155] EDAC/mpc85xx: Prevent building as a module

2019-06-13 Thread Greg Kroah-Hartman
[ Upstream commit 2b8358a951b1e2a534a54924cd8245e58a1c5fb8 ]

The mpc85xx EDAC driver can be configured as a module but then fails to
build because it uses two unexported symbols:

  ERROR: ".pci_find_hose_for_OF_device" [drivers/edac/mpc85xx_edac_mod.ko] 
undefined!
  ERROR: ".early_find_capability" [drivers/edac/mpc85xx_edac_mod.ko] undefined!

We don't want to export those symbols just for this driver, so make the
driver only configurable as a built-in.

This seems to have been broken since at least

  c92132f59806 ("edac/85xx: Add PCIe error interrupt edac support")

(Nov 2013).

 [ bp: make it depend on EDAC=y so that the EDAC core doesn't get built
   as a module. ]

Signed-off-by: Michael Ellerman 
Signed-off-by: Borislav Petkov 
Acked-by: Johannes Thumshirn 
Cc: James Morse 
Cc: Mauro Carvalho Chehab 
Cc: linux-edac 
Cc: linuxppc-...@ozlabs.org
Cc: morbid...@gmail.com
Link: https://lkml.kernel.org/r/20190502141941.12927-1-...@ellerman.id.au
Signed-off-by: Sasha Levin 
---
 drivers/edac/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 47eb4d13ed5f..5e2e0348d460 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -263,8 +263,8 @@ config EDAC_PND2
  micro-server but may appear on others in the future.
 
 config EDAC_MPC85XX
-   tristate "Freescale MPC83xx / MPC85xx"
-   depends on FSL_SOC
+   bool "Freescale MPC83xx / MPC85xx"
+   depends on FSL_SOC && EDAC=y
help
  Support for error detection and correction on the Freescale
  MPC8349, MPC8560, MPC8540, MPC8548, T4240
-- 
2.20.1





[PATCH v9 6/7] iommu/amd: add support for IOMMU default DMA mode build options

2019-06-13 Thread Zhen Lei
The default DMA mode of AMD IOMMU is LAZY, this patch make it can be set
to STRICT at build time. It can be overridden by boot option.

There is no functional change.

Signed-off-by: Zhen Lei 
---
 drivers/iommu/Kconfig  | 2 +-
 drivers/iommu/amd_iommu_init.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index fd297b0e0330d27..70741fd73b07785 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -79,7 +79,7 @@ choice
prompt "IOMMU default DMA mode"
depends on IOMMU_API
default IOMMU_DEFAULT_PASSTHROUGH if (PPC_POWERNV && PCI)
-   default IOMMU_DEFAULT_LAZY if (INTEL_IOMMU || S390_IOMMU)
+   default IOMMU_DEFAULT_LAZY if (AMD_IOMMU || INTEL_IOMMU || S390_IOMMU)
default IOMMU_DEFAULT_STRICT
help
  This option allows an IOMMU DMA mode to be chosen at build time, to
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 07d84dbab564e4d..b7d5c1757425946 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -154,7 +154,7 @@ struct ivmd_header {
   to handle */
 LIST_HEAD(amd_iommu_unity_map);/* a list of required unity 
mappings
   we find in ACPI */
-bool amd_iommu_unmap_flush;/* if true, flush on every unmap */
+bool amd_iommu_unmap_flush = IS_ENABLED(CONFIG_IOMMU_DEFAULT_STRICT);  /* if 
true, flush on every unmap */
 
 LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the
   system */
-- 
1.8.3




[PATCH v9 7/7] ia64: hide build option IOMMU_DEFAULT_PASSTHROUGH

2019-06-13 Thread Zhen Lei
The DMA mode PASSTHROUGH is not used on ia64.

Signed-off-by: Zhen Lei 
---
 drivers/iommu/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 70741fd73b07785..63506f1cad3d149 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -91,7 +91,7 @@ choice
 
 config IOMMU_DEFAULT_PASSTHROUGH
bool "passthrough"
-   depends on !S390_IOMMU
+   depends on (!S390_IOMMU && !IA64)
help
  In this mode, the DMA access through IOMMU without any addresses
  translation. That means, the wrong or illegal DMA access can not
-- 
1.8.3




[PATCH v9 5/7] iommu/vt-d: add support for IOMMU default DMA mode build options

2019-06-13 Thread Zhen Lei
The default DMA mode of INTEL IOMMU is LAZY, this patch make it can be
set to STRICT at build time. It can be overridden by boot option.

There is no functional change.

Signed-off-by: Zhen Lei 
---
 drivers/iommu/Kconfig   | 2 +-
 drivers/iommu/intel-iommu.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index bfbcaa24e283aad..fd297b0e0330d27 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -79,7 +79,7 @@ choice
prompt "IOMMU default DMA mode"
depends on IOMMU_API
default IOMMU_DEFAULT_PASSTHROUGH if (PPC_POWERNV && PCI)
-   default IOMMU_DEFAULT_LAZY if S390_IOMMU
+   default IOMMU_DEFAULT_LAZY if (INTEL_IOMMU || S390_IOMMU)
default IOMMU_DEFAULT_STRICT
help
  This option allows an IOMMU DMA mode to be chosen at build time, to
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 162b3236e72c3c8..ec5515b7831b23f 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -354,7 +354,7 @@ static int domain_detach_iommu(struct dmar_domain *domain,
 
 static int dmar_map_gfx = 1;
 static int dmar_forcedac;
-static int intel_iommu_strict;
+static int intel_iommu_strict = IS_ENABLED(CONFIG_IOMMU_DEFAULT_STRICT);
 static int intel_iommu_superpage = 1;
 static int intel_iommu_sm;
 static int iommu_identity_mapping;
-- 
1.8.3




[PATCH v9 3/7] s390/pci: add support for IOMMU default DMA mode build options

2019-06-13 Thread Zhen Lei
The default DMA mode is LAZY on s390, this patch make it can be set to
STRICT at build time. It can be overridden by boot option.

There is no functional change.

Signed-off-by: Zhen Lei 
Acked-by: Sebastian Ott 
---
 arch/s390/pci/pci_dma.c | 2 +-
 drivers/iommu/Kconfig   | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/s390/pci/pci_dma.c b/arch/s390/pci/pci_dma.c
index 9e52d1527f71495..784ad1e0acecfb1 100644
--- a/arch/s390/pci/pci_dma.c
+++ b/arch/s390/pci/pci_dma.c
@@ -17,7 +17,7 @@
 
 static struct kmem_cache *dma_region_table_cache;
 static struct kmem_cache *dma_page_table_cache;
-static int s390_iommu_strict;
+static int s390_iommu_strict = IS_ENABLED(CONFIG_IOMMU_DEFAULT_STRICT);
 
 static int zpci_refresh_global(struct zpci_dev *zdev)
 {
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index fe715fb295c6ed2..a8dd69d175fb3c6 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -78,6 +78,7 @@ config IOMMU_DEBUGFS
 choice
prompt "IOMMU default DMA mode"
depends on IOMMU_API
+   default IOMMU_DEFAULT_LAZY if S390_IOMMU
default IOMMU_DEFAULT_STRICT
help
  This option allows an IOMMU DMA mode to be chosen at build time, to
@@ -89,6 +90,7 @@ choice
 
 config IOMMU_DEFAULT_PASSTHROUGH
bool "passthrough"
+   depends on !S390_IOMMU
help
  In this mode, the DMA access through IOMMU without any addresses
  translation. That means, the wrong or illegal DMA access can not
-- 
1.8.3




[PATCH v9 4/7] powernv/iommu: add support for IOMMU default DMA mode build options

2019-06-13 Thread Zhen Lei
The default DMA mode is PASSTHROUGH on powernv, this patch make it can be
set to STRICT at build time. It can be overridden by boot option.

There is no functional change.

Signed-off-by: Zhen Lei 
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 3 ++-
 drivers/iommu/Kconfig | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index 10cc42b9e541c46..27e25e8e3a9c637 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -81,7 +81,8 @@ void pe_level_printk(const struct pnv_ioda_pe *pe, const char 
*level,
va_end(args);
 }
 
-static bool pnv_iommu_bypass_disabled __read_mostly;
+static bool pnv_iommu_bypass_disabled __read_mostly =
+   !IS_ENABLED(CONFIG_IOMMU_DEFAULT_PASSTHROUGH);
 static bool pci_reset_phbs __read_mostly;
 
 static int __init iommu_setup(char *str)
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index a8dd69d175fb3c6..bfbcaa24e283aad 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -78,6 +78,7 @@ config IOMMU_DEBUGFS
 choice
prompt "IOMMU default DMA mode"
depends on IOMMU_API
+   default IOMMU_DEFAULT_PASSTHROUGH if (PPC_POWERNV && PCI)
default IOMMU_DEFAULT_LAZY if S390_IOMMU
default IOMMU_DEFAULT_STRICT
help
@@ -98,6 +99,7 @@ config IOMMU_DEFAULT_PASSTHROUGH
 
 config IOMMU_DEFAULT_LAZY
bool "lazy"
+   depends on !PPC_POWERNV
help
  Support lazy mode, where for every IOMMU DMA unmap operation, the
  flush operation of IOTLB and the free operation of IOVA are deferred.
-- 
1.8.3




[PATCH v9 2/7] x86/dma: use IS_ENABLED() to simplify the code

2019-06-13 Thread Zhen Lei
Remove the ifdefs around CONFIG_IOMMU_DEFAULT_PASSTHROUGH to improve
readablity.

Signed-off-by: Zhen Lei 
---
 arch/x86/kernel/pci-dma.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index dcd272dbd0a9330..8c82b2e28a0fe2d 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -43,11 +43,7 @@
  * It is also possible to disable by default in kernel config, and enable with
  * iommu=nopt at boot time.
  */
-#ifdef CONFIG_IOMMU_DEFAULT_PASSTHROUGH
-int iommu_pass_through __read_mostly = 1;
-#else
-int iommu_pass_through __read_mostly;
-#endif
+int iommu_pass_through __read_mostly = 
IS_ENABLED(CONFIG_IOMMU_DEFAULT_PASSTHROUGH);
 
 extern struct iommu_table_entry __iommu_table[], __iommu_table_end[];
 
-- 
1.8.3




[PATCH v9 0/7] iommu: enhance IOMMU default DMA mode build options

2019-06-13 Thread Zhen Lei
v8--> v9
1. Fix some text editing errors

v7--> v8
1. Split into multiple small patches base on ARCHs or IOMMU drivers.
2. Hide the unsupported build options on the related ARCH or IOMMU.

v6 --> v7:
1. Fix some text editing errors

v5 --> v6:
1. give up adding boot option iommu.dma_mode

v4 --> v5:
As Hanjun and Thomas Gleixner's suggestion:
1. Keep the old ARCH specific boot options no change.
2. Keep build option CONFIG_IOMMU_DEFAULT_PASSTHROUGH no change.

v4:
As Robin Murphy's suggestion:
"It's also not necessarily obvious to the user how this interacts with
IOMMU_DEFAULT_PASSTHROUGH, so if we really do go down this route, maybe it
would be better to refactor the whole lot into a single selection of something
like IOMMU_DEFAULT_MODE anyway."

In this version, I tried to normalize the IOMMU dma mode boot options for all
ARCHs. When IOMMU is enabled, there are 3 dma modes: paasthrough(bypass),
lazy(mapping but defer the IOTLB invalidation), strict. But currently each
ARCHs defined their private boot options, different with each other. For
example, to enable/disable "passthrough", ARM64 use iommu.passthrough=1/0,
X86 use iommu=pt/nopt, PPC/POWERNV use iommu=nobypass.

Zhen Lei (7):
  iommu: enhance IOMMU default DMA mode build options
  x86/dma: use IS_ENABLED() to simplify the code
  s390/pci: add support for IOMMU default DMA mode build options
  powernv/iommu: add support for IOMMU default DMA mode build options
  iommu/vt-d: add support for IOMMU default DMA mode build options
  iommu/amd: add support for IOMMU default DMA mode build options
  ia64: hide build option IOMMU_DEFAULT_PASSTHROUGH

 arch/powerpc/platforms/powernv/pci-ioda.c |  3 +-
 arch/s390/pci/pci_dma.c   |  2 +-
 arch/x86/kernel/pci-dma.c |  6 +---
 drivers/iommu/Kconfig | 48 +--
 drivers/iommu/amd_iommu_init.c|  2 +-
 drivers/iommu/intel-iommu.c   |  2 +-
 drivers/iommu/iommu.c |  3 +-
 7 files changed, 48 insertions(+), 18 deletions(-)

-- 
1.8.3




[PATCH v9 1/7] iommu: enhance IOMMU default DMA mode build options

2019-06-13 Thread Zhen Lei
First, add build option IOMMU_DEFAULT_{LAZY|STRICT}, so that we have the
opportunity to set {lazy|strict} mode as default at build time. Then put
the three config options in an choice, make people can only choose one of
the three at a time.

Signed-off-by: Zhen Lei 
---
 drivers/iommu/Kconfig | 44 
 drivers/iommu/iommu.c |  3 ++-
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 83664db5221df02..fe715fb295c6ed2 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -75,16 +75,44 @@ config IOMMU_DEBUGFS
  debug/iommu directory, and then populate a subdirectory with
  entries as required.
 
-config IOMMU_DEFAULT_PASSTHROUGH
-   bool "IOMMU passthrough by default"
+choice
+   prompt "IOMMU default DMA mode"
depends on IOMMU_API
-help
- Enable passthrough by default, removing the need to pass in
- iommu.passthrough=on or iommu=pt through command line. If this
- is enabled, you can still disable with iommu.passthrough=off
- or iommu=nopt depending on the architecture.
+   default IOMMU_DEFAULT_STRICT
+   help
+ This option allows an IOMMU DMA mode to be chosen at build time, to
+ override the default DMA mode of each ARCH, removing the need to
+ pass in kernel parameters through command line. You can still use
+ ARCH specific boot options to override this option again.
 
- If unsure, say N here.
+ If unsure, keep the default.
+
+config IOMMU_DEFAULT_PASSTHROUGH
+   bool "passthrough"
+   help
+ In this mode, the DMA access through IOMMU without any addresses
+ translation. That means, the wrong or illegal DMA access can not
+ be caught, no error information will be reported.
+
+config IOMMU_DEFAULT_LAZY
+   bool "lazy"
+   help
+ Support lazy mode, where for every IOMMU DMA unmap operation, the
+ flush operation of IOTLB and the free operation of IOVA are deferred.
+ They are only guaranteed to be done before the related IOVA will be
+ reused.
+
+config IOMMU_DEFAULT_STRICT
+   bool "strict"
+   help
+ For every IOMMU DMA unmap operation, the flush operation of IOTLB and
+ the free operation of IOVA are guaranteed to be done in the unmap
+ function.
+
+ This mode is safer than the two above, but it maybe slower in some
+ high performace scenarios.
+
+endchoice
 
 config OF_IOMMU
def_bool y
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index f9cacce909d3ae9..05171dd0bd03aee 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -31,7 +31,8 @@
 #else
 static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_DMA;
 #endif
-static bool iommu_dma_strict __read_mostly = true;
+static bool iommu_dma_strict __read_mostly =
+   IS_ENABLED(CONFIG_IOMMU_DEFAULT_STRICT);
 
 struct iommu_group {
struct kobject kobj;
-- 
1.8.3




[PATCH 4.19 029/118] EDAC/mpc85xx: Prevent building as a module

2019-06-13 Thread Greg Kroah-Hartman
[ Upstream commit 2b8358a951b1e2a534a54924cd8245e58a1c5fb8 ]

The mpc85xx EDAC driver can be configured as a module but then fails to
build because it uses two unexported symbols:

  ERROR: ".pci_find_hose_for_OF_device" [drivers/edac/mpc85xx_edac_mod.ko] 
undefined!
  ERROR: ".early_find_capability" [drivers/edac/mpc85xx_edac_mod.ko] undefined!

We don't want to export those symbols just for this driver, so make the
driver only configurable as a built-in.

This seems to have been broken since at least

  c92132f59806 ("edac/85xx: Add PCIe error interrupt edac support")

(Nov 2013).

 [ bp: make it depend on EDAC=y so that the EDAC core doesn't get built
   as a module. ]

Signed-off-by: Michael Ellerman 
Signed-off-by: Borislav Petkov 
Acked-by: Johannes Thumshirn 
Cc: James Morse 
Cc: Mauro Carvalho Chehab 
Cc: linux-edac 
Cc: linuxppc-...@ozlabs.org
Cc: morbid...@gmail.com
Link: https://lkml.kernel.org/r/20190502141941.12927-1-...@ellerman.id.au
Signed-off-by: Sasha Levin 
---
 drivers/edac/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 57304b2e989f..b00cc03ad6b6 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -250,8 +250,8 @@ config EDAC_PND2
  micro-server but may appear on others in the future.
 
 config EDAC_MPC85XX
-   tristate "Freescale MPC83xx / MPC85xx"
-   depends on FSL_SOC
+   bool "Freescale MPC83xx / MPC85xx"
+   depends on FSL_SOC && EDAC=y
help
  Support for error detection and correction on the Freescale
  MPC8349, MPC8560, MPC8540, MPC8548, T4240
-- 
2.20.1





[PATCH 4.14 23/81] EDAC/mpc85xx: Prevent building as a module

2019-06-13 Thread Greg Kroah-Hartman
[ Upstream commit 2b8358a951b1e2a534a54924cd8245e58a1c5fb8 ]

The mpc85xx EDAC driver can be configured as a module but then fails to
build because it uses two unexported symbols:

  ERROR: ".pci_find_hose_for_OF_device" [drivers/edac/mpc85xx_edac_mod.ko] 
undefined!
  ERROR: ".early_find_capability" [drivers/edac/mpc85xx_edac_mod.ko] undefined!

We don't want to export those symbols just for this driver, so make the
driver only configurable as a built-in.

This seems to have been broken since at least

  c92132f59806 ("edac/85xx: Add PCIe error interrupt edac support")

(Nov 2013).

 [ bp: make it depend on EDAC=y so that the EDAC core doesn't get built
   as a module. ]

Signed-off-by: Michael Ellerman 
Signed-off-by: Borislav Petkov 
Acked-by: Johannes Thumshirn 
Cc: James Morse 
Cc: Mauro Carvalho Chehab 
Cc: linux-edac 
Cc: linuxppc-...@ozlabs.org
Cc: morbid...@gmail.com
Link: https://lkml.kernel.org/r/20190502141941.12927-1-...@ellerman.id.au
Signed-off-by: Sasha Levin 
---
 drivers/edac/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 96afb2aeed18..8ce8d3fd 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -246,8 +246,8 @@ config EDAC_PND2
  micro-server but may appear on others in the future.
 
 config EDAC_MPC85XX
-   tristate "Freescale MPC83xx / MPC85xx"
-   depends on FSL_SOC
+   bool "Freescale MPC83xx / MPC85xx"
+   depends on FSL_SOC && EDAC=y
help
  Support for error detection and correction on the Freescale
  MPC8349, MPC8560, MPC8540, MPC8548, T4240
-- 
2.20.1





Re: [PATCH v8 1/7] iommu: enhance IOMMU default DMA mode build options

2019-06-13 Thread Leizhen (ThunderTown)



On 2019/5/31 18:42, John Garry wrote:
> 
 -config IOMMU_DEFAULT_PASSTHROUGH
 -    bool "IOMMU passthrough by default"
 +choice
 +    prompt "IOMMU default DMA mode"
  depends on IOMMU_API
 -    help
 -  Enable passthrough by default, removing the need to pass in
 -  iommu.passthrough=on or iommu=pt through command line. If this
 -  is enabled, you can still disable with iommu.passthrough=off
 -  or iommu=nopt depending on the architecture.
 +    default IOMMU_DEFAULT_STRICT
 +    help
 +  This option allows IOMMU DMA mode to be chose at build time, to
>>>
>>> As before:
>>> /s/chose/chosen/, /s/allows IOMMU/allows an IOMMU/
>> I'm sorry that the previous version was not modified.
>>
>>>
 +  override the default DMA mode of each ARCHs, removing the need to
>>>
>>> Again, as before:
>>> ARCHs should be singular
>> OK
>>
>>>
 +  pass in kernel parameters through command line. You can still use
 +  ARCHs specific boot options to override this option again.
> 
> *
> 
 +
 +config IOMMU_DEFAULT_PASSTHROUGH
 +    bool "passthrough"
 +    help
 +  In this mode, the DMA access through IOMMU without any addresses
 +  translation. That means, the wrong or illegal DMA access can not
 +  be caught, no error information will be reported.

    If unsure, say N here.

 +config IOMMU_DEFAULT_LAZY
 +    bool "lazy"
 +    help
 +  Support lazy mode, where for every IOMMU DMA unmap operation, the
 +  flush operation of IOTLB and the free operation of IOVA are 
 deferred.
 +  They are only guaranteed to be done before the related IOVA will be
 +  reused.
>>>
>>> why no advisory on how to set if unsure?
>> Because the LAZY and STRICT have their own advantages and disadvantages.
>>
>> Should I say: If unsure, keep the default。
> 
> Maybe. So you could put this in the help for the choice, * above, and remove 
> the advisory on IOMMU_DEFAULT_PASSTHROUGH.

OK, I'll revise it according to this idea in v9.

> 
> However the maintainer may have a different view.
> 
> Thanks,
> John
> 
>>
>>>
 +
 +config IOMMU_DEFAULT_STRICT
 +    bool "strict"
 +    help
 +  For every IOMMU DMA unmap operation, the flush operation of IOTLB 
 and
 +  the free operation of IOVA are guaranteed to be done in the unmap
 +  function.
 +
 +  This mode is safer than the two above, but it maybe slower in some
 +  high performace scenarios.
>>>
>>> and here?
> 
> 
> .
> 



[PATCH] powerpc: enable a 30-bit ZONE_DMA for 32-bit pmac

2019-06-13 Thread Christoph Hellwig
With the strict dma mask checking introduced with the switch to
the generic DMA direct code common wifi chips on 32-bit powerbooks
stopped working.  Add a 30-bit ZONE_DMA to the 32-bit pmac builds
to allow them to reliably allocate dma coherent memory.

Fixes: 65a21b71f948 ("powerpc/dma: remove dma_nommu_dma_supported")
Reported-by: Aaro Koskinen 
Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/include/asm/page.h | 7 +++
 arch/powerpc/mm/mem.c   | 3 ++-
 arch/powerpc/platforms/powermac/Kconfig | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index b8286a2013b4..0d52f57fca04 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -319,6 +319,13 @@ struct vm_area_struct;
 #endif /* __ASSEMBLY__ */
 #include 
 
+/*
+ * Allow 30-bit DMA for very limited Broadcom wifi chips on many powerbooks.
+ */
+#ifdef CONFIG_PPC32
+#define ARCH_ZONE_DMA_BITS 30
+#else
 #define ARCH_ZONE_DMA_BITS 31
+#endif
 
 #endif /* _ASM_POWERPC_PAGE_H */
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index cba29131bccc..2540d3b2588c 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -248,7 +248,8 @@ void __init paging_init(void)
   (long int)((top_of_ram - total_ram) >> 20));
 
 #ifdef CONFIG_ZONE_DMA
-   max_zone_pfns[ZONE_DMA] = min(max_low_pfn, 0x7fffUL >> PAGE_SHIFT);
+   max_zone_pfns[ZONE_DMA] = min(max_low_pfn,
+   ((1UL << ARCH_ZONE_DMA_BITS) - 1) >> PAGE_SHIFT);
 #endif
max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
 #ifdef CONFIG_HIGHMEM
diff --git a/arch/powerpc/platforms/powermac/Kconfig 
b/arch/powerpc/platforms/powermac/Kconfig
index f834a19ed772..c02d8c503b29 100644
--- a/arch/powerpc/platforms/powermac/Kconfig
+++ b/arch/powerpc/platforms/powermac/Kconfig
@@ -7,6 +7,7 @@ config PPC_PMAC
select PPC_INDIRECT_PCI if PPC32
select PPC_MPC106 if PPC32
select PPC_NATIVE
+   select ZONE_DMA if PPC32
default y
 
 config PPC_PMAC64
-- 
2.20.1



Re: [PATCH 0/1] PPC32: fix ptrace() access to FPU registers

2019-06-13 Thread Daniel Axtens
Radu Rendec  writes:

> Hi Everyone,
>
> I'm following up on the ptrace() problem that I reported a few days ago.
> I believe my version of the code handles all cases correctly. While the
> problem essentially boils down to dividing the fpidx by 2 on PPC32, it
> becomes tricky when the same code must work correctly on both PPC32 and
> PPC64.
>
> One other thing that I believe was handled incorrectly in the previous
> version is the unused half of fpscr on PPC32. Note that while PT_FPSCR
> is defined as (PT_FPR0 + 2*32 + 1), making only the upper half visible,
> PT_FPR0 + 2*32 still corresponds to a possible address that userspace
> can pass. In that case, comparing fpidx to (PT_FPSCR - PT_FPR0) would
> cause an invalid access to the FPU registers array.
>
> I tested the patch on 4.9.179, but that part of the code is identical in
> recent kernels so it should work just the same.

I've been looking into this. Something is definitely up, but I'm not
sure that we want to fix it in exactly the way you identified. I'll keep
you updated.

Regards,
Daniel

>
> I wrote a simple test program than can be used to quickly test (on an
> x86_64 host) that all cases are handled correctly for both PPC32/PPC64.
> The code is included below.
>
> I also tested with gdbserver (test patch included below) and verified
> that it generates two ptrace() calls for each FPU register, with
> addresses between 0xc0 and 0x1bc.
>
> 8<--- Makefile -
> .PHONY: all clean
>
> all: ptrace-fpregs-32 ptrace-fpregs-64
>
> ptrace-fpregs-32: ptrace-fpregs.c
>   $(CC) -o ptrace-fpregs-32 -Wall -O2 -m32 ptrace-fpregs.c
>
> ptrace-fpregs-64: ptrace-fpregs.c
>   $(CC) -o ptrace-fpregs-64 -Wall -O2 ptrace-fpregs.c
>
> clean:
>   rm -f ptrace-fpregs-32 ptrace-fpregs-64
> 8<--- ptrace-fpregs.c --
> #include 
> #include 
>
> #define PT_FPR0   48
>
> #ifndef __x86_64
>
> #define PT_FPR31 (PT_FPR0 + 2*31)
> #define PT_FPSCR (PT_FPR0 + 2*32 + 1)
>
> #else
>
> #define PT_FPSCR (PT_FPR0 + 32)
>
> #endif
>
> int test_access(unsigned long addr)
> {
>   int ret;
>
>   do {
>   unsigned long index, fpidx;
>
>   ret = -EIO;
>
>   /* convert to index and check */
>   index = addr / sizeof(long);
>   if ((addr & (sizeof(long) - 1)) || (index > PT_FPSCR))
>   break;
>
>   if (index < PT_FPR0) {
>   ret = printf("ptrace_put_reg(%lu)", index);
>   break;
>   }
>
>   ret = 0;
> #ifndef __x86_64
>   if (index == PT_FPSCR - 1) {
>   /* corner case for PPC32; do nothing */
>   printf("corner_case");
>   break;
>   }
> #endif
>   if (index == PT_FPSCR) {
>   printf("fpscr");
>   break;
>   }
>
>   /*
>* FPR is always 64-bit; on PPC32, userspace does two 32-bit
>* accesses. Add bit2 to allow accessing the upper half on
>* 32-bit; on 64-bit, bit2 is always 0 (we validate it above).
>*/
>   fpidx = (addr - PT_FPR0 * sizeof(long)) / 8;
>   printf("TS_FPR[%lu] + %lu", fpidx, addr & 4);
>   break;
>   } while (0);
>
>   return ret;
> }
>
> int main(void)
> {
>   unsigned long addr;
>   int rc;
>
>   for (addr = 0; addr < PT_FPSCR * sizeof(long) + 16; addr++) {
>   printf("0x%04lx: ", addr);
>   rc = test_access(addr);
>   if (rc < 0)
>   printf("!err!");
>   printf("\t<%d>\n", rc);
>   }
>
>   return 0;
> }
> 8<--- gdb.patch 
> --- gdb/gdbserver/linux-low.c.orig2019-06-10 11:45:53.810882669 -0400
> +++ gdb/gdbserver/linux-low.c 2019-06-10 11:49:32.272929766 -0400
> @@ -4262,6 +4262,8 @@ store_register (struct regcache *regcach
>pid = lwpid_of (get_thread_lwp (current_inferior));
>for (i = 0; i < size; i += sizeof (PTRACE_XFER_TYPE))
>  {
> +  printf("writing register #%d offset %d at address %#x\n",
> + regno, i, (unsigned int)regaddr);
>errno = 0;
>ptrace (PTRACE_POKEUSER, pid,
>   /* Coerce to a uintptr_t first to avoid potential gcc warning
> 8<--
>
> Radu Rendec (1):
>   PPC32: fix ptrace() access to FPU registers
>
>  arch/powerpc/kernel/ptrace.c | 85 ++--
>  1 file changed, 52 insertions(+), 33 deletions(-)
>
> -- 
> 2.20.1


Re: [BISECTED REGRESSION] b43legacy broken on G4 PowerBook

2019-06-13 Thread Christoph Hellwig
On Thu, Jun 13, 2019 at 07:59:51AM +1000, Benjamin Herrenschmidt wrote:
> > With the patch for Kconfig above, and the original patch setting 
> > ARCH_ZONE_DMA_BITS to 30, everything works.
> > 
> > Do you have any ideas on what should trigger the change in ARCH_ZONE_BITS? 
> > Should it be CONFIG_PPC32 defined, or perhaps CONFIG_G4_CPU defined?
> 
> I think CONFIG_PPC32 is fine

I'll cook up a patch unless someone beats me to it.