LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] ASoC: fsl: audmix: fix two issues
From: Viorel Suman @ 2019-04-09  8:35 UTC (permalink / raw)
  To: Timur Tabi, Nicolin Chen, Xiubo Li, Fabio Estevam, Liam Girdwood,
	Mark Brown, Jaroslav Kysela, Takashi Iwai, Shawn Guo,
	Sascha Hauer, Julia Lawall
  Cc: alsa-devel@alsa-project.org, Viorel Suman,
	linux-kernel@vger.kernel.org, Viorel Suman, dl-linux-imx,
	Pengutronix Kernel Team, linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org

The latest audmix patch-set (v5) had the "model" attribute
removed as requested by Nicolin Chen, but looks like (v4)
version of DAI driver reached "for-next" branch - fix this.
Asside of this fix object reference leaks in machine probe reported
by Julia Lawall.

Viorel Suman (2):
  ASoC: fsl_audmix: remove "model" attribute
  ASoC: imx-audmix: fix object reference leaks in probe

 sound/soc/fsl/fsl_audmix.c | 61 ++++++++++++++++++++++++----------------------
 sound/soc/fsl/imx-audmix.c | 31 +++++++++--------------
 2 files changed, 43 insertions(+), 49 deletions(-)

-- 
2.7.4


^ permalink raw reply

* [PATCH 2/2] ASoC: imx-audmix: fix object reference leaks in probe
From: Viorel Suman @ 2019-04-09  8:35 UTC (permalink / raw)
  To: Timur Tabi, Nicolin Chen, Xiubo Li, Fabio Estevam, Liam Girdwood,
	Mark Brown, Jaroslav Kysela, Takashi Iwai, Shawn Guo,
	Sascha Hauer, Julia Lawall
  Cc: alsa-devel@alsa-project.org, Viorel Suman,
	linux-kernel@vger.kernel.org, Viorel Suman, dl-linux-imx,
	Pengutronix Kernel Team, linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org
In-Reply-To: <1554798876-20653-1-git-send-email-viorel.suman@nxp.com>

Release the reference to the underlying device taken
by of_find_device_by_node() call.

Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
---
 sound/soc/fsl/imx-audmix.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/sound/soc/fsl/imx-audmix.c b/sound/soc/fsl/imx-audmix.c
index 7983bd3..7c24095 100644
--- a/sound/soc/fsl/imx-audmix.c
+++ b/sound/soc/fsl/imx-audmix.c
@@ -20,10 +20,7 @@
 #include "fsl_audmix.h"
 
 struct imx_audmix {
-	struct platform_device *pdev;
 	struct snd_soc_card card;
-	struct platform_device *audmix_pdev;
-	struct platform_device *out_pdev;
 	struct clk *cpu_mclk;
 	int num_dai;
 	struct snd_soc_dai_link *dai;
@@ -144,7 +141,7 @@ static struct snd_soc_ops imx_audmix_be_ops = {
 static int imx_audmix_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
-	struct device_node *audmix_np = NULL, *out_cpu_np = NULL;
+	struct device_node *audmix_np = NULL;
 	struct platform_device *audmix_pdev = NULL;
 	struct platform_device *cpu_pdev;
 	struct of_phandle_args args;
@@ -171,6 +168,7 @@ static int imx_audmix_probe(struct platform_device *pdev)
 			np->full_name);
 		return -EINVAL;
 	}
+	put_device(&audmix_pdev->dev);
 
 	num_dai = of_count_phandle_with_args(audmix_np, "dais", NULL);
 	if (num_dai != FSL_AUDMIX_MAX_DAIS) {
@@ -216,6 +214,7 @@ static int imx_audmix_probe(struct platform_device *pdev)
 			dev_err(&pdev->dev, "failed to find SAI platform device\n");
 			return -EINVAL;
 		}
+		put_device(&cpu_pdev->dev);
 
 		dai_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s%s",
 					  fe_name_pref, args.np->full_name + 1);
@@ -223,7 +222,14 @@ static int imx_audmix_probe(struct platform_device *pdev)
 		dev_info(pdev->dev.parent, "DAI FE name:%s\n", dai_name);
 
 		if (i == 0) {
-			out_cpu_np = args.np;
+			priv->cpu_mclk = devm_clk_get(&cpu_pdev->dev, "mclk1");
+			if (IS_ERR(priv->cpu_mclk)) {
+				ret = PTR_ERR(priv->cpu_mclk);
+				dev_err(&cpu_pdev->dev,
+					"failed to get DAI mclk1: %d\n", ret);
+				return -EINVAL;
+			}
+
 			capture_dai_name =
 				devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s %s",
 					       dai_name, "CPU-Capture");
@@ -275,21 +281,6 @@ static int imx_audmix_probe(struct platform_device *pdev)
 		priv->dapm_routes[2 * num_dai + i].sink   = capture_dai_name;
 	}
 
-	cpu_pdev = of_find_device_by_node(out_cpu_np);
-	if (!cpu_pdev) {
-		dev_err(&pdev->dev, "failed to find SAI platform device\n");
-		return -EINVAL;
-	}
-	priv->cpu_mclk = devm_clk_get(&cpu_pdev->dev, "mclk1");
-	if (IS_ERR(priv->cpu_mclk)) {
-		ret = PTR_ERR(priv->cpu_mclk);
-		dev_err(&cpu_pdev->dev, "failed to get DAI mclk1: %d\n", ret);
-		return -EINVAL;
-	}
-
-	priv->audmix_pdev = audmix_pdev;
-	priv->out_pdev  = cpu_pdev;
-
 	priv->card.dai_link = priv->dai;
 	priv->card.num_links = priv->num_dai;
 	priv->card.codec_conf = priv->dai_conf;
-- 
2.7.4


^ permalink raw reply related

* Re: [PATCH] powerpc/mm: Define MAX_PHYSMEM_BITS for all 64-bit configs
From: Aneesh Kumar K.V @ 2019-04-09  8:18 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: schwab, hughd, aneesh.kumar, ben
In-Reply-To: <20190409060324.16941-1-mpe@ellerman.id.au>

Michael Ellerman <mpe@ellerman.id.au> writes:

> The recent commit 8bc086899816 ("powerpc/mm: Only define
> MAX_PHYSMEM_BITS in SPARSEMEM configurations") removed our definition
> of MAX_PHYSMEM_BITS when SPARSEMEM is disabled.
>
> This inadvertently broke some 64-bit FLATMEM using configs with eg:
>
>   arch/powerpc/include/asm/book3s/64/mmu-hash.h:584:6: error: "MAX_PHYSMEM_BITS" is not defined, evaluates to 0
>    #if (MAX_PHYSMEM_BITS > MAX_EA_BITS_PER_CONTEXT)
>         ^~~~~~~~~~~~~~~~
>
> Fix it by making sure we define MAX_PHYSMEM_BITS for all 64-bit
> configs regardless of SPARSEMEM.


Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>

But I still like the patch I posted which move this to the correct
platform header.

>
> Fixes: 8bc086899816 ("powerpc/mm: Only define MAX_PHYSMEM_BITS in SPARSEMEM configurations")
> Reported-by: Andreas Schwab <schwab@linux-m68k.org>
> Reported-by: Hugh Dickins <hughd@google.com>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>  arch/powerpc/include/asm/mmu.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
> index 598cdcdd1355..8ddd4a91bdc1 100644
> --- a/arch/powerpc/include/asm/mmu.h
> +++ b/arch/powerpc/include/asm/mmu.h
> @@ -352,7 +352,7 @@ static inline bool strict_kernel_rwx_enabled(void)
>  #if defined(CONFIG_SPARSEMEM_VMEMMAP) && defined(CONFIG_SPARSEMEM_EXTREME) &&	\
>  	defined (CONFIG_PPC_64K_PAGES)
>  #define MAX_PHYSMEM_BITS        51
> -#elif defined(CONFIG_SPARSEMEM)
> +#elif defined(CONFIG_PPC64)
>  #define MAX_PHYSMEM_BITS        46
>  #endif
>
> -- 
> 2.20.1


^ permalink raw reply

* Re: [PATCH v2] powerpc/64s/radix: Fix radix segment exception handling
From: Aneesh Kumar K.V @ 2019-04-09  8:15 UTC (permalink / raw)
  To: Nicholas Piggin, linuxppc-dev
  Cc: Aneesh Kumar K . V, Nicholas Piggin, Anton Blanchard
In-Reply-To: <20190409031643.20405-1-npiggin@gmail.com>

Nicholas Piggin <npiggin@gmail.com> writes:

> Commit 48e7b76957 ("powerpc/64s/hash: Convert SLB miss handlers to C")
> broke the radix-mode segment exception handler. In radix mode, this is
> exception is not an SLB miss, rather it signals that the EA is outside
> the range translated by any page table.
>
> The commit lost the radix feature alternate code patch, which can
> cause faults to some EAs to kernel BUG at arch/powerpc/mm/slb.c:639!
>
> The original radix code would send faults to slb_miss_large_addr,
> which would end up faulting due to slb_addr_limit being 0. This patch
> sends radix directly to do_bad_slb_fault, which is a bit clearer.
>

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>

> Fixes: 48e7b76957 ("powerpc/64s/hash: Convert SLB miss handlers to C")
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Reported-by: Anton Blanchard <anton@samba.org>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> - Add a selftests that triggers the crash
>
>  arch/powerpc/kernel/exceptions-64s.S          | 12 +++
>  tools/testing/selftests/powerpc/mm/Makefile   |  3 +-
>  .../selftests/powerpc/mm/access_tests.c       | 94 +++++++++++++++++++
>  3 files changed, 108 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/powerpc/mm/access_tests.c
>
> diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
> index a5b8fbae56a0..9481a117e242 100644
> --- a/arch/powerpc/kernel/exceptions-64s.S
> +++ b/arch/powerpc/kernel/exceptions-64s.S
> @@ -656,11 +656,17 @@ EXC_COMMON_BEGIN(data_access_slb_common)
>  	ld	r4,PACA_EXSLB+EX_DAR(r13)
>  	std	r4,_DAR(r1)
>  	addi	r3,r1,STACK_FRAME_OVERHEAD
> +BEGIN_MMU_FTR_SECTION
> +	/* HPT case, do SLB fault */
>  	bl	do_slb_fault
>  	cmpdi	r3,0
>  	bne-	1f
>  	b	fast_exception_return
>  1:	/* Error case */
> +MMU_FTR_SECTION_ELSE
> +	/* Radix case, access is outside page table range */
> +	li	r3,-EFAULT
> +ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
>  	std	r3,RESULT(r1)
>  	bl	save_nvgprs
>  	RECONCILE_IRQ_STATE(r10, r11)
> @@ -705,11 +711,17 @@ EXC_COMMON_BEGIN(instruction_access_slb_common)
>  	EXCEPTION_PROLOG_COMMON(0x480, PACA_EXSLB)
>  	ld	r4,_NIP(r1)
>  	addi	r3,r1,STACK_FRAME_OVERHEAD
> +BEGIN_MMU_FTR_SECTION
> +	/* HPT case, do SLB fault */
>  	bl	do_slb_fault
>  	cmpdi	r3,0
>  	bne-	1f
>  	b	fast_exception_return
>  1:	/* Error case */
> +MMU_FTR_SECTION_ELSE
> +	/* Radix case, access is outside page table range */
> +	li	r3,-EFAULT
> +ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
>  	std	r3,RESULT(r1)
>  	bl	save_nvgprs
>  	RECONCILE_IRQ_STATE(r10, r11)
> diff --git a/tools/testing/selftests/powerpc/mm/Makefile b/tools/testing/selftests/powerpc/mm/Makefile
> index 43d68420e363..68b7add5086d 100644
> --- a/tools/testing/selftests/powerpc/mm/Makefile
> +++ b/tools/testing/selftests/powerpc/mm/Makefile
> @@ -2,7 +2,7 @@
>  noarg:
>  	$(MAKE) -C ../
>  
> -TEST_GEN_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao segv_errors wild_bctr
> +TEST_GEN_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao segv_errors wild_bctr access_tests
>  TEST_GEN_FILES := tempfile
>  
>  top_srcdir = ../../../../..
> @@ -13,6 +13,7 @@ $(TEST_GEN_PROGS): ../harness.c
>  $(OUTPUT)/prot_sao: ../utils.c
>  
>  $(OUTPUT)/wild_bctr: CFLAGS += -m64
> +$(OUTPUT)/access_tests: CFLAGS += -m64
>  
>  $(OUTPUT)/tempfile:
>  	dd if=/dev/zero of=$@ bs=64k count=1
> diff --git a/tools/testing/selftests/powerpc/mm/access_tests.c b/tools/testing/selftests/powerpc/mm/access_tests.c
> new file mode 100644
> index 000000000000..ad300d7d9d43
> --- /dev/null
> +++ b/tools/testing/selftests/powerpc/mm/access_tests.c
> @@ -0,0 +1,94 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +/*
> + * Copyright 2017 John Sperbeck
> + *
> + * Test faults to "interesting" locations.
> + */
> +
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <signal.h>
> +#include <sys/mman.h>
> +#include <assert.h>
> +#include <ucontext.h>
> +
> +#include "utils.h"
> +
> +#define PAGE_SIZE	(64*1024)
> +#define TB		(1024ULL*1024*1024*1024)
> +static volatile bool faulted;
> +static volatile int si_code;
> +
> +static void segv_handler(int n, siginfo_t *info, void *ctxt_v)
> +{
> +	ucontext_t *ctxt = (ucontext_t *)ctxt_v;
> +	struct pt_regs *regs = ctxt->uc_mcontext.regs;
> +
> +	faulted = true;
> +	si_code = info->si_code;
> +	regs->nip += 4;
> +}
> +
> +int test_segv_errors(void)
> +{
> +	struct sigaction act = {
> +		.sa_sigaction = segv_handler,
> +		.sa_flags = SA_SIGINFO,
> +	};
> +	static unsigned long ptrs[] = {
> +		0x0f00000000000000ULL, /* Radix Q0 out of pgtable range */
> +		0x4000000000000000ULL, /* Radix Q1 */
> +		0x4f00000000000000ULL, /* Radix Q1 out of pgtable range */
> +		0x8000000000000000ULL, /* Radix Q2 */
> +		0x8f00000000000000ULL, /* Radix Q2 out of pgtable range */
> +		0xc000000000000000ULL, /* Radix Q3 */
> +		0xcf00000000000000ULL, /* Radix Q3 out of pgtable range */
> +		0xc000000000000000ULL, /* Hash kernel region */
> +		0xc000000000000000ULL + TB, /* Hash kernel region + 1 segment */
> +		0xc000000000000000ULL + TB - 1,
> +		0xd000000000000000ULL, /* Hash vmalloc region */
> +		0xd000000000000000ULL + TB,
> +		0xd000000000000000ULL + TB - 1,
> +		0xe000000000000000ULL,
> +		0xe000000000000000ULL + TB,
> +		0xe000000000000000ULL + TB - 1,
> +		0xf000000000000000ULL, /* Hash vmemmap region */
> +		0xf000000000000000ULL + TB,
> +		0xf000000000000000ULL + TB - 1,
> +	};
> +	size_t i;
> +
> +	FAIL_IF(sigaction(SIGSEGV, &act, NULL) != 0);
> +
> +	for (i = 0; i < sizeof(ptrs)/sizeof(ptrs[0]); i++) {
> +		volatile char *p = (void *)ptrs[i];
> +
> +		/*
> +		 * We just need a compiler barrier, but mb() works and has the
> +		 * nice property of being easy to spot in the disassembly.
> +		 */
> +		printf("testing %p...\n", p);
> +		faulted = false;
> +		si_code = 0;
> +		mb();
> +		(void)*p;
> +		mb();
> +		FAIL_IF(!faulted);
> +		FAIL_IF(si_code != SEGV_MAPERR && si_code != SEGV_BNDERR);
> +		/*
> +		 * Some accesses throw MAPERR, others BNDERR. Possibly all
> +		 * Q>0 accesses should cause BNDERR.
> +		 */
> +	}
> +
> +	return 0;
> +}
> +
> +int main(void)
> +{
> +	return test_harness(test_segv_errors, "segv_errors");
> +}
> -- 
> 2.20.1


^ permalink raw reply

* Re: [PATCH v4 10/17] KVM: PPC: Book3S HV: XIVE: add get/set accessors for the VP XIVE state
From: Paul Mackerras @ 2019-04-09  6:19 UTC (permalink / raw)
  To: Cédric Le Goater; +Cc: linuxppc-dev, kvm, kvm-ppc, David Gibson
In-Reply-To: <20190320083751.27001-11-clg@kaod.org>

On Wed, Mar 20, 2019 at 09:37:44AM +0100, Cédric Le Goater wrote:
> The state of the thread interrupt management registers needs to be
> collected for migration. These registers are cached under the
> 'xive_saved_state.w01' field of the VCPU when the VPCU context is
> pulled from the HW thread. An OPAL call retrieves the backup of the
> IPB register in the underlying XIVE NVT structure and merges it in the
> KVM state.

Since you're adding a new one_reg identifier value, you need to update
the list in Documentation/virtual/kvm/api.txt.

Paul.

^ permalink raw reply

* Re: [PATCH] powerpc/mm/radix: Do slb preload only with hash translation mode
From: Nicholas Piggin @ 2019-04-09  8:10 UTC (permalink / raw)
  To: Aneesh Kumar K.V, benh, mpe, paulus; +Cc: linuxppc-dev
In-Reply-To: <20190409040328.6038-1-aneesh.kumar@linux.ibm.com>

Aneesh Kumar K.V's on April 9, 2019 2:03 pm:
> Add radix_enabled check to avoid slb preload with radix translation.
> 
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>

Acked-by: Nicholas Piggin <npiggin@gmail.com>

> ---
> 
> Without this we result in kernel crash as we move hash related variables
> out of mm_context_t
> 
>  arch/powerpc/kernel/process.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> index dd9e0d5386ee..f7b2e3b3db28 100644
> --- a/arch/powerpc/kernel/process.c
> +++ b/arch/powerpc/kernel/process.c
> @@ -1729,7 +1729,8 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)
>  	unsigned long load_addr = regs->gpr[2];	/* saved by ELF_PLAT_INIT */
>  
>  #ifdef CONFIG_PPC_BOOK3S_64
> -	preload_new_slb_context(start, sp);
> +	if (!radix_enabled())
> +		preload_new_slb_context(start, sp);
>  #endif
>  #endif
>  
> -- 
> 2.20.1
> 
> 

^ permalink raw reply

* [PATCH] powerpc/mm: Define MAX_PHYSMEM_BITS for all 64-bit configs
From: Michael Ellerman @ 2019-04-09  6:03 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: schwab, hughd, aneesh.kumar, ben

The recent commit 8bc086899816 ("powerpc/mm: Only define
MAX_PHYSMEM_BITS in SPARSEMEM configurations") removed our definition
of MAX_PHYSMEM_BITS when SPARSEMEM is disabled.

This inadvertently broke some 64-bit FLATMEM using configs with eg:

  arch/powerpc/include/asm/book3s/64/mmu-hash.h:584:6: error: "MAX_PHYSMEM_BITS" is not defined, evaluates to 0
   #if (MAX_PHYSMEM_BITS > MAX_EA_BITS_PER_CONTEXT)
        ^~~~~~~~~~~~~~~~

Fix it by making sure we define MAX_PHYSMEM_BITS for all 64-bit
configs regardless of SPARSEMEM.

Fixes: 8bc086899816 ("powerpc/mm: Only define MAX_PHYSMEM_BITS in SPARSEMEM configurations")
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Reported-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/include/asm/mmu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index 598cdcdd1355..8ddd4a91bdc1 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -352,7 +352,7 @@ static inline bool strict_kernel_rwx_enabled(void)
 #if defined(CONFIG_SPARSEMEM_VMEMMAP) && defined(CONFIG_SPARSEMEM_EXTREME) &&	\
 	defined (CONFIG_PPC_64K_PAGES)
 #define MAX_PHYSMEM_BITS        51
-#elif defined(CONFIG_SPARSEMEM)
+#elif defined(CONFIG_PPC64)
 #define MAX_PHYSMEM_BITS        46
 #endif
 
-- 
2.20.1


^ permalink raw reply related

* Re: [PATCH v10 02/18] counter: Documentation: Add Generic Counter sysfs documentation
From: William Breathitt Gray @ 2019-04-09  5:07 UTC (permalink / raw)
  To: Pavel Machek
  Cc: mark.rutland, benjamin.gaignard, linux-pwm, linux-iio,
	patrick.havelange, thierry.reding, pmeerw, lars, daniel.lezcano,
	linux-arm-kernel, devicetree, david, linuxppc-dev, robh+dt,
	Jonathan Cameron, tglx, fabrice.gasnier, esben, gregkh,
	linux-kernel, leoyang.li, knaack.h, akpm, shawnguo, jic23
In-Reply-To: <20190408215531.GB27592@amd>

On Mon, Apr 08, 2019 at 11:55:31PM +0200, Pavel Machek wrote:
> On Tue 2019-04-02 15:30:37, William Breathitt Gray wrote:
> > This patch adds standard documentation for the userspace sysfs
> > attributes of the Generic Counter interface.
> > 
> > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
> > ---
> >  Documentation/ABI/testing/sysfs-bus-counter | 230 ++++++++++++++++++++
> >  MAINTAINERS                                 |   1 +
> >  2 files changed, 231 insertions(+)
> >  create mode 100644 Documentation/ABI/testing/sysfs-bus-counter
> > 
> > diff --git a/Documentation/ABI/testing/sysfs-bus-counter b/Documentation/ABI/testing/sysfs-bus-counter
> > new file mode 100644
> > index 000000000000..566bd99fe0a5
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-bus-counter
> > @@ -0,0 +1,230 @@
> > +What:		/sys/bus/counter/devices/counterX/countY/count
> > +KernelVersion:	5.2
> > +Contact:	linux-iio@vger.kernel.org
> > +Description:
> > +		Count data of Count Y represented as a string.
> > +
> > +What:		/sys/bus/counter/devices/counterX/countY/ceiling
> > +KernelVersion:	5.2
> > +Contact:	linux-iio@vger.kernel.org
> > +Description:
> > +		Count value ceiling for Count Y. This is the upper limit for the
> > +		respective counter.
> > +
> > +What:		/sys/bus/counter/devices/counterX/countY/floor
> > +KernelVersion:	5.2
> > +Contact:	linux-iio@vger.kernel.org
> > +Description:
> > +		Count value floor for Count Y. This is the lower limit for the
> > +		respective counter.
> > +
> > +What:		/sys/bus/counter/devices/counterX/countY/count_mode
> > +KernelVersion:	5.2
> > +Contact:	linux-iio@vger.kernel.org
> > +Description:
> > +		Count mode for channel Y. The ceiling and floor values for
> > +		Count Y are used by the count mode where required. The following
> > +		count modes are available:
> > +
> > +		normal:
> > +			Counting is continuous in either direction.
> > +
> > +		range limit:
> > +			An upper or lower limit is set, mimicking limit switches
> > +			in the mechanical counterpart. The upper limit is set to
> > +			the Count Y ceiling value, while the lower limit is set
> > +			to the Count Y floor value. The counter freezes at
> > +			count = ceiling when counting up, and at count = floor
> > +			when counting down. At either of these limits, the
> > +			counting is resumed only when the count direction is
> > +			reversed.
> > +
> > +		non-recycle:
> > +			The counter is disabled whenever a counter overflow or
> > +			underflow takes place. The counter is re-enabled when a
> > +			new count value is loaded to the counter via a preset
> > +			operation or direct write.
> > +
> > +		modulo-n:
> > +			A count value boundary is set between the Count Y floor
> > +			value and the Count Y ceiling value. The counter is
> > +			reset to the Count Y floor value at count = ceiling when
> > +			counting up, while the counter is set to the Count Y
> > +			ceiling value at count = floor when counting down; the
> > +			counter does not freeze at the boundary points, but
> > +			counts continuously throughout.
> > +
> > +What:		/sys/bus/counter/devices/counterX/countY/count_mode_available
> > +What:		/sys/bus/counter/devices/counterX/countY/error_noise_available
> > +What:		/sys/bus/counter/devices/counterX/countY/function_available
> > +What:		/sys/bus/counter/devices/counterX/countY/signalZ_action_available
> > +KernelVersion:	5.2
> > +Contact:	linux-iio@vger.kernel.org
> > +Description:
> > +		Discrete set of available values for the respective Count Y
> > +		configuration are listed in this file. Values are delimited by
> > +		newline characters.
> 
> Elsewhere in sysfs we do space-separated:
> 
> pavel@amd:~$ cat /sys/power/state
> freeze mem disk
> 
> And we use [] to mark current selection:
> 
> pavel@amd:~$ cat /sys/class/leds/tpacpi\:\:thinkvantage/trigger
> [none] bluetooth-power rfkill-any rfkill-none kbd-scrolllock
> kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock
> kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock
> kbd-ctrlrlock AC-online BAT0-charging-or-full BAT0-charging BAT0-full
> BAT0-charging-blink-full-solid rfkill0 phy0rx phy0tx phy0assoc
> phy0radio phy0tpt mmc0 timer heartbeat audio-mute audio-micmute
> rfkill1
> 
> Note this only works if you have less than PAGE_SIZE of entries... and
> will never have more.
> 
> 									Pavel
> -- 
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Marking the current selection with [] or similar does seem useful. But
delimiting by space does seem to cause confusion in cases where the
values also include spaces (e.g. "quadrature x1 a"). I see that in these
cases a "-" is used in place of a space, but that wouldn't work very
well when values can also contain hyphens (e.g. "pulse-direction").

William Breathitt Gray

^ permalink raw reply

* Re: [PATCH v10 01/18] counter: Introduce the Generic Counter interface
From: William Breathitt Gray @ 2019-04-09  4:57 UTC (permalink / raw)
  To: Pavel Machek
  Cc: mark.rutland, benjamin.gaignard, linux-pwm, linux-iio,
	patrick.havelange, thierry.reding, pmeerw, lars, daniel.lezcano,
	linux-arm-kernel, devicetree, david, linuxppc-dev, robh+dt,
	Jonathan Cameron, tglx, fabrice.gasnier, esben, gregkh,
	linux-kernel, leoyang.li, knaack.h, akpm, shawnguo, jic23
In-Reply-To: <20190408215515.GA27592@amd>

On Mon, Apr 08, 2019 at 11:55:15PM +0200, Pavel Machek wrote:
> Hi!
> 
> > +const char *const counter_count_direction_str[2] = {
> > +	[COUNTER_COUNT_DIRECTION_FORWARD] = "forward",
> > +	[COUNTER_COUNT_DIRECTION_BACKWARD] = "backward"
> > +};
> > +EXPORT_SYMBOL_GPL(counter_count_direction_str);
> > +
> > +const char *const counter_count_mode_str[4] = {
> > +	[COUNTER_COUNT_MODE_NORMAL] = "normal",
> > +	[COUNTER_COUNT_MODE_RANGE_LIMIT] = "range limit",
> > +	[COUNTER_COUNT_MODE_NON_RECYCLE] = "non-recycle",
> > +	[COUNTER_COUNT_MODE_MODULO_N] = "modulo-n"
> > +};
> > +EXPORT_SYMBOL_GPL(counter_count_mode_str);
> 
> Dunno. Exporting const tables saying "forward" and "backward". Can we
> ... somehow make it work without need to export this?
> 
> -- 
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Right now there are only have 4 counter devices supported in this
patchset, but it is expected that support for a greater variety of
devices will be added. For these future cases, new count directions will
be added to match their functionality.

For example, suppose support for a rotary encoder device is added. These
type of devices do not move forward/backward but rather rotate. In these
cases, the following count directions may be added:

    [COUNTER_COUNT_DIRECTION_CLOCKWISE] = "clockwise",
    [COUNTER_COUNT_DIRECTION_COUNTERCLOCKWISE] = "counterclockwise"

Or as another example, suppose support for a two-axis precision
positioning table is added. These devices support positioning in a
cartesian coordinate system. In these cases, spatial direction may serve
as useful count directions:

    [COUNTER_COUNT_DIRECTION_NORTH] = "north",
    [COUNTER_COUNT_DIRECTION_NORTHEAST] = "northeast",
    [COUNTER_COUNT_DIRECTION_EAST] = "east",
    [COUNTER_COUNT_DIRECTION_SOUTHEAST] = "southeast",
    [COUNTER_COUNT_DIRECTION_SOUTH] = "south",
    [COUNTER_COUNT_DIRECTION_SOUTHWEST] = "southwest",
    [COUNTER_COUNT_DIRECTION_WEST] = "west",
    [COUNTER_COUNT_DIRECTION_NORTHWEST] = "northwest"

A const table is conveinent in these scenarios because support for new
count directions may be easily added by simple entry into the table.

William Breathitt Gray

^ permalink raw reply

* [PATCH v2] powerpc/watchdog: Use hrtimers for per-CPU heartbeat
From: Nicholas Piggin @ 2019-04-09  4:40 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gautham R . Shenoy, Ravikumar Bangoria, Nicholas Piggin

Using a jiffies timer creates a dependency on the tick_do_timer_cpu
incrementing jiffies. If that CPU has locked up and jiffies is not
incrementing, the watchdog heartbeat timer for all CPUs stops and
creates false positives and confusing warnings on local CPUs, and
also causes the SMP detector to stop, so the root cause is never
detected.

Fix this by using hrtimer based timers for the watchdog heartbeat,
like the generic kernel hardlockup detector.

Cc: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Reported-by: Ravikumar Bangoria <ravi.bangoria@in.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
v2: Fix per-CPU hrtimer startup noticed by Gautham

 arch/powerpc/kernel/watchdog.c | 81 +++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 41 deletions(-)

diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c
index 3c6ab22a0c4e..af3c15a1d41e 100644
--- a/arch/powerpc/kernel/watchdog.c
+++ b/arch/powerpc/kernel/watchdog.c
@@ -77,7 +77,7 @@ static u64 wd_smp_panic_timeout_tb __read_mostly; /* panic other CPUs */
 
 static u64 wd_timer_period_ms __read_mostly;  /* interval between heartbeat */
 
-static DEFINE_PER_CPU(struct timer_list, wd_timer);
+static DEFINE_PER_CPU(struct hrtimer, wd_hrtimer);
 static DEFINE_PER_CPU(u64, wd_timer_tb);
 
 /* SMP checker bits */
@@ -293,21 +293,21 @@ void soft_nmi_interrupt(struct pt_regs *regs)
 	nmi_exit();
 }
 
-static void wd_timer_reset(unsigned int cpu, struct timer_list *t)
-{
-	t->expires = jiffies + msecs_to_jiffies(wd_timer_period_ms);
-	if (wd_timer_period_ms > 1000)
-		t->expires = __round_jiffies_up(t->expires, cpu);
-	add_timer_on(t, cpu);
-}
-
-static void wd_timer_fn(struct timer_list *t)
+static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
 {
 	int cpu = smp_processor_id();
 
+	if (!(watchdog_enabled & NMI_WATCHDOG_ENABLED))
+		return HRTIMER_NORESTART;
+
+	if (!cpumask_test_cpu(cpu, &watchdog_cpumask))
+		return HRTIMER_NORESTART;
+
 	watchdog_timer_interrupt(cpu);
 
-	wd_timer_reset(cpu, t);
+	hrtimer_forward_now(hrtimer, ms_to_ktime(wd_timer_period_ms));
+
+	return HRTIMER_RESTART;
 }
 
 void arch_touch_nmi_watchdog(void)
@@ -323,37 +323,22 @@ void arch_touch_nmi_watchdog(void)
 }
 EXPORT_SYMBOL(arch_touch_nmi_watchdog);
 
-static void start_watchdog_timer_on(unsigned int cpu)
-{
-	struct timer_list *t = per_cpu_ptr(&wd_timer, cpu);
-
-	per_cpu(wd_timer_tb, cpu) = get_tb();
-
-	timer_setup(t, wd_timer_fn, TIMER_PINNED);
-	wd_timer_reset(cpu, t);
-}
-
-static void stop_watchdog_timer_on(unsigned int cpu)
-{
-	struct timer_list *t = per_cpu_ptr(&wd_timer, cpu);
-
-	del_timer_sync(t);
-}
-
-static int start_wd_on_cpu(unsigned int cpu)
+static void start_watchdog(void *arg)
 {
+	struct hrtimer *hrtimer = this_cpu_ptr(&wd_hrtimer);
+	int cpu = smp_processor_id();
 	unsigned long flags;
 
 	if (cpumask_test_cpu(cpu, &wd_cpus_enabled)) {
 		WARN_ON(1);
-		return 0;
+		return;
 	}
 
 	if (!(watchdog_enabled & NMI_WATCHDOG_ENABLED))
-		return 0;
+		return;
 
 	if (!cpumask_test_cpu(cpu, &watchdog_cpumask))
-		return 0;
+		return;
 
 	wd_smp_lock(&flags);
 	cpumask_set_cpu(cpu, &wd_cpus_enabled);
@@ -363,27 +348,40 @@ static int start_wd_on_cpu(unsigned int cpu)
 	}
 	wd_smp_unlock(&flags);
 
-	start_watchdog_timer_on(cpu);
+	*this_cpu_ptr(&wd_timer_tb) = get_tb();
 
-	return 0;
+	hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+	hrtimer->function = watchdog_timer_fn;
+	hrtimer_start(hrtimer, ms_to_ktime(wd_timer_period_ms),
+		      HRTIMER_MODE_REL_PINNED);
 }
 
-static int stop_wd_on_cpu(unsigned int cpu)
+static int start_watchdog_on_cpu(unsigned int cpu)
 {
+	return smp_call_function_single(cpu, start_watchdog, NULL, true);
+}
+
+static void stop_watchdog(void *arg)
+{
+	struct hrtimer *hrtimer = this_cpu_ptr(&wd_hrtimer);
+	int cpu = smp_processor_id();
 	unsigned long flags;
 
 	if (!cpumask_test_cpu(cpu, &wd_cpus_enabled))
-		return 0; /* Can happen in CPU unplug case */
+		return; /* Can happen in CPU unplug case */
 
-	stop_watchdog_timer_on(cpu);
+	hrtimer_cancel(hrtimer);
 
 	wd_smp_lock(&flags);
 	cpumask_clear_cpu(cpu, &wd_cpus_enabled);
 	wd_smp_unlock(&flags);
 
 	wd_smp_clear_cpu_pending(cpu, get_tb());
+}
 
-	return 0;
+static int stop_watchdog_on_cpu(unsigned int cpu)
+{
+	return smp_call_function_single(cpu, stop_watchdog, NULL, true);
 }
 
 static void watchdog_calc_timeouts(void)
@@ -402,7 +400,7 @@ void watchdog_nmi_stop(void)
 	int cpu;
 
 	for_each_cpu(cpu, &wd_cpus_enabled)
-		stop_wd_on_cpu(cpu);
+		stop_watchdog_on_cpu(cpu);
 }
 
 void watchdog_nmi_start(void)
@@ -411,7 +409,7 @@ void watchdog_nmi_start(void)
 
 	watchdog_calc_timeouts();
 	for_each_cpu_and(cpu, cpu_online_mask, &watchdog_cpumask)
-		start_wd_on_cpu(cpu);
+		start_watchdog_on_cpu(cpu);
 }
 
 /*
@@ -423,7 +421,8 @@ int __init watchdog_nmi_probe(void)
 
 	err = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
 					"powerpc/watchdog:online",
-					start_wd_on_cpu, stop_wd_on_cpu);
+					start_watchdog_on_cpu,
+					stop_watchdog_on_cpu);
 	if (err < 0) {
 		pr_warn("could not be initialized");
 		return err;
-- 
2.20.1


^ permalink raw reply related

* [PATCH] powerpc/mm/radix: Do slb preload only with hash translation mode
From: Aneesh Kumar K.V @ 2019-04-09  4:03 UTC (permalink / raw)
  To: npiggin, benh, paulus, mpe; +Cc: Aneesh Kumar K.V, linuxppc-dev

Add radix_enabled check to avoid slb preload with radix translation.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---

Without this we result in kernel crash as we move hash related variables
out of mm_context_t

 arch/powerpc/kernel/process.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index dd9e0d5386ee..f7b2e3b3db28 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1729,7 +1729,8 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)
 	unsigned long load_addr = regs->gpr[2];	/* saved by ELF_PLAT_INIT */
 
 #ifdef CONFIG_PPC_BOOK3S_64
-	preload_new_slb_context(start, sp);
+	if (!radix_enabled())
+		preload_new_slb_context(start, sp);
 #endif
 #endif
 
-- 
2.20.1


^ permalink raw reply related

* Re: [EXT] Re: [PATCH V1] ASoC: fsl_esai: replace fall-through with break
From: Nicolin Chen @ 2019-04-09  3:54 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: alsa-devel@alsa-project.org, timur@kernel.org,
	Xiubo.Lee@gmail.com, linuxppc-dev@lists.ozlabs.org, S.j. Wang,
	broonie@kernel.org, festevam@gmail.com
In-Reply-To: <eba6372b-618c-4633-f0a9-06c034cf2f9c@embeddedor.com>

Hi Gustavo,

On Mon, Apr 08, 2019 at 10:20:25PM -0500, Gustavo A. R. Silva wrote:
> >>> diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c index
> >>> c7410bbfd2af..bad0dfed6b68 100644
> >>> --- a/sound/soc/fsl/fsl_esai.c
> >>> +++ b/sound/soc/fsl/fsl_esai.c
> >>> @@ -251,7 +251,7 @@ static int fsl_esai_set_dai_sysclk(struct
> >> snd_soc_dai *dai, int clk_id,
> >>>               break;
> >>>       case ESAI_HCKT_EXTAL:
> >>>               ecr |= ESAI_ECR_ETI;
> >>
> >> Also, you should use a simple assignment operator "=" instead of "|=" in
> >> both cases.
> > 
> > The result is same for "=" and "|=", because there is "ecr = 0" in beginning of
> > This function. 
> > 
> 
> Following that same logic, then why not use "+=" instead?
> 
> The point is: is "|=" or any other assignment operator other than "=" necessary?
> The answer in this case is: no, it is not.  So, go for the simple one and avoid
> any unnecessary confusion.

I would like to keep "|=" here, just in case that someday it'd be easier
to insert something to ecr before this chunk. So please get easy on this
one.

Thanks
Nicolin

^ permalink raw reply

* Re: [EXT] Re: [PATCH V1] ASoC: fsl_esai: replace fall-through with break
From: Gustavo A. R. Silva @ 2019-04-09  3:20 UTC (permalink / raw)
  To: S.j. Wang, timur@kernel.org, nicoleotsuka@gmail.com,
	Xiubo.Lee@gmail.com, festevam@gmail.com, broonie@kernel.org,
	alsa-devel@alsa-project.org
  Cc: linuxppc-dev@lists.ozlabs.org
In-Reply-To: <VE1PR04MB6479C16BB1C92E1AE291BB12E32D0@VE1PR04MB6479.eurprd04.prod.outlook.com>

Hi Shengjiu,

On 4/8/19 9:54 PM, S.j. Wang wrote:
> Hi Gustavo
> 
>>
>>
>> On 4/8/19 4:28 AM, S.j. Wang wrote:
>>> case ESAI_HCKT_EXTAL and case ESAI_HCKR_EXTAL should be
>> independent of
>>> each other, so replace fall-through with break.
>>>
>> If this is correct, then you should use the following "Fixes" tag instead,
>> which is the one that introduced the bug:
>>
>> Fixes: 43d24e76b698 ("ASoC: fsl_esai: Add ESAI CPU DAI driver")
>>
>>> Fixes: 16bbeb2b43c3 ("ASoC: fsl_esai: Mark expected switch
>>> fall-through")
>>>
>>         ^^^^
>> because this didn't change any functionality.
> 
> Ok, this will be updated.
> 
>>
>>> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
>>> ---
>>>  sound/soc/fsl/fsl_esai.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c index
>>> c7410bbfd2af..bad0dfed6b68 100644
>>> --- a/sound/soc/fsl/fsl_esai.c
>>> +++ b/sound/soc/fsl/fsl_esai.c
>>> @@ -251,7 +251,7 @@ static int fsl_esai_set_dai_sysclk(struct
>> snd_soc_dai *dai, int clk_id,
>>>               break;
>>>       case ESAI_HCKT_EXTAL:
>>>               ecr |= ESAI_ECR_ETI;
>>
>> Also, you should use a simple assignment operator "=" instead of "|=" in
>> both cases.
> 
> The result is same for "=" and "|=", because there is "ecr = 0" in beginning of
> This function. 
> 

Following that same logic, then why not use "+=" instead?

The point is: is "|=" or any other assignment operator other than "=" necessary?
The answer in this case is: no, it is not.  So, go for the simple one and avoid
any unnecessary confusion.

Also, there is no need for versioning a patch for it's first revision.  If you
receive feedback on a patch and are asked to update it, then you do need to
version the patches that you re-send.

Thanks
--
Gustavo

>>
>>> -             /* fall through */
>>> +             break;
>>>       case ESAI_HCKR_EXTAL:
>>>               ecr |= esai_priv->synchronous ? ESAI_ECR_ETI : ESAI_ECR_ERI;
>>>               break;
>>>
>>
>> Thanks
>> --
>> Gustavo

^ permalink raw reply

* Re: [PATCH 8/8] powerpc/eeh: Remove eeh_probe_devices() and eeh_addr_cache_build()
From: Sam Bobroff @ 2019-04-09  3:31 UTC (permalink / raw)
  To: Alexey Kardashevskiy; +Cc: linuxppc-dev
In-Reply-To: <f3acd337-3222-0cdd-4784-b71cbaa44566@ozlabs.ru>

[-- Attachment #1: Type: text/plain, Size: 6295 bytes --]

On Wed, Mar 20, 2019 at 05:05:49PM +1100, Alexey Kardashevskiy wrote:
> 
> 
> On 20/03/2019 13:58, Sam Bobroff wrote:
> > Now that EEH support for all devices (on PowerNV and pSeries) is
> > provided by the pcibios bus add device hooks, eeh_probe_devices() and
> > eeh_addr_cache_build() are redundant and can be removed.
> > 
> > Note that previously on pSeries, useless EEH sysfs files were created
> > for some devices that did not have EEH support and this change
> > prevents them from being created.
> > 
> > Signed-off-by: Sam Bobroff <sbobroff@linux.ibm.com>
> > ---
> >  arch/powerpc/include/asm/eeh.h               |  6 ----
> >  arch/powerpc/kernel/eeh.c                    | 13 --------
> >  arch/powerpc/kernel/eeh_cache.c              | 32 --------------------
> >  arch/powerpc/platforms/powernv/eeh-powernv.c |  5 ++-
> >  arch/powerpc/platforms/pseries/pci.c         |  3 +-
> >  5 files changed, 3 insertions(+), 56 deletions(-)
> > 
> > diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
> > index 791b9e6fcc45..f1eca1757cbc 100644
> > --- a/arch/powerpc/include/asm/eeh.h
> > +++ b/arch/powerpc/include/asm/eeh.h
> > @@ -290,13 +290,11 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe);
> >  struct eeh_dev *eeh_dev_init(struct pci_dn *pdn);
> >  void eeh_dev_phb_init_dynamic(struct pci_controller *phb);
> >  void eeh_show_enabled(void);
> > -void eeh_probe_devices(void);
> >  int __init eeh_ops_register(struct eeh_ops *ops);
> >  int __exit eeh_ops_unregister(const char *name);
> >  int eeh_check_failure(const volatile void __iomem *token);
> >  int eeh_dev_check_failure(struct eeh_dev *edev);
> >  void eeh_addr_cache_init(void);
> > -void eeh_addr_cache_build(void);
> >  void eeh_add_device_early(struct pci_dn *);
> >  void eeh_add_device_tree_early(struct pci_dn *);
> >  void eeh_add_device_late(struct pci_dev *);
> > @@ -347,8 +345,6 @@ static inline bool eeh_phb_enabled(void)
> >  	return false;
> >  }
> >  
> > -static inline void eeh_probe_devices(void) { }
> > -
> >  static inline void *eeh_dev_init(struct pci_dn *pdn, void *data)
> >  {
> >  	return NULL;
> > @@ -365,8 +361,6 @@ static inline int eeh_check_failure(const volatile void __iomem *token)
> >  
> >  static inline void eeh_addr_cache_init(void) { }
> >  
> > -static inline void eeh_addr_cache_build(void) { }
> > -
> >  static inline void eeh_add_device_early(struct pci_dn *pdn) { }
> >  
> >  static inline void eeh_add_device_tree_early(struct pci_dn *pdn) { }
> > diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
> > index 217e14bb1fb6..cd2abbe41497 100644
> > --- a/arch/powerpc/kernel/eeh.c
> > +++ b/arch/powerpc/kernel/eeh.c
> > @@ -1166,19 +1166,6 @@ static struct notifier_block eeh_reboot_nb = {
> >  	.notifier_call = eeh_reboot_notifier,
> >  };
> >  
> > -void eeh_probe_devices(void)
> > -{
> > -	struct pci_controller *hose, *tmp;
> > -	struct pci_dn *pdn;
> > -
> > -	/* Enable EEH for all adapters */
> > -	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
> > -		pdn = hose->pci_data;
> > -		traverse_pci_dn(pdn, eeh_ops->probe, NULL);
> > -	}
> > -	eeh_show_enabled();
> > -}
> > -
> >  /**
> >   * eeh_init - EEH initialization
> >   *
> > diff --git a/arch/powerpc/kernel/eeh_cache.c b/arch/powerpc/kernel/eeh_cache.c
> > index f93dd5cf6a39..c40078d036af 100644
> > --- a/arch/powerpc/kernel/eeh_cache.c
> > +++ b/arch/powerpc/kernel/eeh_cache.c
> > @@ -278,38 +278,6 @@ void eeh_addr_cache_init(void)
> >  	spin_lock_init(&pci_io_addr_cache_root.piar_lock);
> >  }
> >  
> > -/**
> > - * eeh_addr_cache_build - Build a cache of I/O addresses
> > - *
> > - * Build a cache of pci i/o addresses.  This cache will be used to
> > - * find the pci device that corresponds to a given address.
> > - * This routine scans all pci busses to build the cache.
> > - * Must be run late in boot process, after the pci controllers
> > - * have been scanned for devices (after all device resources are known).
> > - */
> > -void eeh_addr_cache_build(void)
> > -{
> > -	struct pci_dn *pdn;
> > -	struct eeh_dev *edev;
> > -	struct pci_dev *dev = NULL;
> > -
> > -	for_each_pci_dev(dev) {
> > -		pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn);
> > -		if (!pdn)
> > -			continue;
> > -
> > -		edev = pdn_to_eeh_dev(pdn);
> > -		if (!edev)
> > -			continue;
> > -
> > -		dev->dev.archdata.edev = edev;
> > -		edev->pdev = dev;
> > -
> > -		eeh_addr_cache_insert_dev(dev);
> > -		eeh_sysfs_add_device(dev);
> > -	}
> > -}
> > -
> >  static int eeh_addr_cache_show(struct seq_file *s, void *v)
> >  {
> >  	struct pci_io_addr_range *piar;
> > diff --git a/arch/powerpc/platforms/powernv/eeh-powernv.c b/arch/powerpc/platforms/powernv/eeh-powernv.c
> > index 81b0923cc55f..6a08f4fab255 100644
> > --- a/arch/powerpc/platforms/powernv/eeh-powernv.c
> > +++ b/arch/powerpc/platforms/powernv/eeh-powernv.c
> > @@ -240,9 +240,7 @@ int pnv_eeh_post_init(void)
> >  	struct pnv_phb *phb;
> >  	int ret = 0;
> >  
> > -	/* Probe devices & build address cache */
> > -	eeh_probe_devices();
> > -	eeh_addr_cache_build();
> > +	eeh_show_enabled();
> >  
> >  	/* Register OPAL event notifier */
> >  	eeh_event_irq = opal_event_request(ilog2(OPAL_EVENT_PCI_ERROR));
> > @@ -360,6 +358,7 @@ static int pnv_eeh_find_ecap(struct pci_dn *pdn, int cap)
> >  	return 0;
> >  }
> >  
> > +
> 
> Unrelated new line. Otherwise

Thanks, I'll fix it as part of merging in patch #5.

> 
> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> 
> 
> 
> 
> >  /**
> >   * pnv_eeh_probe - Do probe on PCI device
> >   * @pdn: PCI device node
> > diff --git a/arch/powerpc/platforms/pseries/pci.c b/arch/powerpc/platforms/pseries/pci.c
> > index 7be80882c08d..7c781b04fb15 100644
> > --- a/arch/powerpc/platforms/pseries/pci.c
> > +++ b/arch/powerpc/platforms/pseries/pci.c
> > @@ -242,8 +242,7 @@ void __init pSeries_final_fixup(void)
> >  
> >  	pSeries_request_regions();
> >  
> > -	eeh_probe_devices();
> > -	eeh_addr_cache_build();
> > +	eeh_show_enabled();
> >  #ifdef CONFIG_EEH
> >  	if (eeh_enabled())
> >  		eeh_add_flag(EEH_PHB_ENABLED);
> > 
> 
> -- 
> Alexey
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply

* Re: [PATCH 5/8] powerpc/eeh: Add eeh_show_enabled()
From: Sam Bobroff @ 2019-04-09  3:30 UTC (permalink / raw)
  To: Alexey Kardashevskiy; +Cc: linuxppc-dev
In-Reply-To: <26b7c0de-4192-eae5-f8aa-94073b3e768e@ozlabs.ru>

[-- Attachment #1: Type: text/plain, Size: 3274 bytes --]

On Wed, Mar 20, 2019 at 05:02:23PM +1100, Alexey Kardashevskiy wrote:
> 
> 
> On 20/03/2019 13:58, Sam Bobroff wrote:
> > Move the EEH enabled message into it's own function so that future
> > work can call it from multiple places.
> > 
> > Signed-off-by: Sam Bobroff <sbobroff@linux.ibm.com>
> > ---
> >  arch/powerpc/include/asm/eeh.h |  3 +++
> >  arch/powerpc/kernel/eeh.c      | 16 +++++++++++-----
> >  2 files changed, 14 insertions(+), 5 deletions(-)
> > 
> > diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
> > index fe4cf7208890..e217ccda55d0 100644
> > --- a/arch/powerpc/include/asm/eeh.h
> > +++ b/arch/powerpc/include/asm/eeh.h
> > @@ -289,6 +289,7 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe);
> >  
> >  struct eeh_dev *eeh_dev_init(struct pci_dn *pdn);
> >  void eeh_dev_phb_init_dynamic(struct pci_controller *phb);
> > +void eeh_show_enabled(void);
> >  void eeh_probe_devices(void);
> >  int __init eeh_ops_register(struct eeh_ops *ops);
> >  int __exit eeh_ops_unregister(const char *name);
> > @@ -338,6 +339,8 @@ static inline bool eeh_enabled(void)
> >          return false;
> >  }
> >  
> > +static inline void eeh_show_enabled(void) { }
> > +
> >  static inline bool eeh_phb_enabled(void)
> >  {
> >  	return false;
> > diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
> > index b14d89547895..3dcff29cb9b3 100644
> > --- a/arch/powerpc/kernel/eeh.c
> > +++ b/arch/powerpc/kernel/eeh.c
> > @@ -163,6 +163,16 @@ static int __init eeh_setup(char *str)
> >  }
> >  __setup("eeh=", eeh_setup);
> >  
> > +void eeh_show_enabled(void)
> > +{
> > +	if (eeh_has_flag(EEH_FORCE_DISABLED))
> > +		pr_info("EEH: PCI Enhanced I/O Error Handling DISABLED (by eeh=off)\n");
> > +	else if (eeh_enabled())
> 
> 
> I'd make it eeh_has_flag(EEH_ENABLED) for clarity.

OK, sounds good.

> 
> > +		pr_info("EEH: PCI Enhanced I/O Error Handling ENABLED (capable adapter found)\n");
> > +	else
> > +		pr_info("EEH: PCI Enhanced I/O Error Handling DISABLED (no capable adapter found)\n");
> > +}
> > +
> >  /*
> >   * This routine captures assorted PCI configuration space data
> >   * for the indicated PCI device, and puts them into a buffer
> > @@ -1166,11 +1176,7 @@ void eeh_probe_devices(void)
> >  		pdn = hose->pci_data;
> >  		traverse_pci_dn(pdn, eeh_ops->probe, NULL);
> >  	}
> > -	if (eeh_enabled())
> > -		pr_info("EEH: PCI Enhanced I/O Error Handling Enabled\n");
> > -	else
> > -		pr_info("EEH: No capable adapters found\n");
> > -
> > +	eeh_show_enabled();
> 
> 
> This line moves later in the series so I'd just merge this patch into
> 8/8 to reduce number of lines moving withing the patchset.

Oh, good idea. I'll do it.

> In general the whole point of the EEH_ENABLED flag is fading away. Its
> meaning now is that "at least somewhere in the box for at least one
> device with enabled EEH" which does not seem extremely useful as we have
> a pci_dev or pe pretty much everywhere we look at eeh_enabled() and
> pdev->dev.archdata.edev can tell if eeh is enabled for a device.
> Although I am pretty sure this is in your list already :)

Yes. :-)

> 
> >  }
> >  
> >  /**
> > 
> 
> -- 
> Alexey
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply

* [PATCH v2] powerpc/64s/radix: Fix radix segment exception handling
From: Nicholas Piggin @ 2019-04-09  3:16 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Aneesh Kumar K . V, Nicholas Piggin, Anton Blanchard

Commit 48e7b76957 ("powerpc/64s/hash: Convert SLB miss handlers to C")
broke the radix-mode segment exception handler. In radix mode, this is
exception is not an SLB miss, rather it signals that the EA is outside
the range translated by any page table.

The commit lost the radix feature alternate code patch, which can
cause faults to some EAs to kernel BUG at arch/powerpc/mm/slb.c:639!

The original radix code would send faults to slb_miss_large_addr,
which would end up faulting due to slb_addr_limit being 0. This patch
sends radix directly to do_bad_slb_fault, which is a bit clearer.

Fixes: 48e7b76957 ("powerpc/64s/hash: Convert SLB miss handlers to C")
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
- Add a selftests that triggers the crash

 arch/powerpc/kernel/exceptions-64s.S          | 12 +++
 tools/testing/selftests/powerpc/mm/Makefile   |  3 +-
 .../selftests/powerpc/mm/access_tests.c       | 94 +++++++++++++++++++
 3 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/mm/access_tests.c

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index a5b8fbae56a0..9481a117e242 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -656,11 +656,17 @@ EXC_COMMON_BEGIN(data_access_slb_common)
 	ld	r4,PACA_EXSLB+EX_DAR(r13)
 	std	r4,_DAR(r1)
 	addi	r3,r1,STACK_FRAME_OVERHEAD
+BEGIN_MMU_FTR_SECTION
+	/* HPT case, do SLB fault */
 	bl	do_slb_fault
 	cmpdi	r3,0
 	bne-	1f
 	b	fast_exception_return
 1:	/* Error case */
+MMU_FTR_SECTION_ELSE
+	/* Radix case, access is outside page table range */
+	li	r3,-EFAULT
+ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
 	std	r3,RESULT(r1)
 	bl	save_nvgprs
 	RECONCILE_IRQ_STATE(r10, r11)
@@ -705,11 +711,17 @@ EXC_COMMON_BEGIN(instruction_access_slb_common)
 	EXCEPTION_PROLOG_COMMON(0x480, PACA_EXSLB)
 	ld	r4,_NIP(r1)
 	addi	r3,r1,STACK_FRAME_OVERHEAD
+BEGIN_MMU_FTR_SECTION
+	/* HPT case, do SLB fault */
 	bl	do_slb_fault
 	cmpdi	r3,0
 	bne-	1f
 	b	fast_exception_return
 1:	/* Error case */
+MMU_FTR_SECTION_ELSE
+	/* Radix case, access is outside page table range */
+	li	r3,-EFAULT
+ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
 	std	r3,RESULT(r1)
 	bl	save_nvgprs
 	RECONCILE_IRQ_STATE(r10, r11)
diff --git a/tools/testing/selftests/powerpc/mm/Makefile b/tools/testing/selftests/powerpc/mm/Makefile
index 43d68420e363..68b7add5086d 100644
--- a/tools/testing/selftests/powerpc/mm/Makefile
+++ b/tools/testing/selftests/powerpc/mm/Makefile
@@ -2,7 +2,7 @@
 noarg:
 	$(MAKE) -C ../
 
-TEST_GEN_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao segv_errors wild_bctr
+TEST_GEN_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao segv_errors wild_bctr access_tests
 TEST_GEN_FILES := tempfile
 
 top_srcdir = ../../../../..
@@ -13,6 +13,7 @@ $(TEST_GEN_PROGS): ../harness.c
 $(OUTPUT)/prot_sao: ../utils.c
 
 $(OUTPUT)/wild_bctr: CFLAGS += -m64
+$(OUTPUT)/access_tests: CFLAGS += -m64
 
 $(OUTPUT)/tempfile:
 	dd if=/dev/zero of=$@ bs=64k count=1
diff --git a/tools/testing/selftests/powerpc/mm/access_tests.c b/tools/testing/selftests/powerpc/mm/access_tests.c
new file mode 100644
index 000000000000..ad300d7d9d43
--- /dev/null
+++ b/tools/testing/selftests/powerpc/mm/access_tests.c
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Copyright 2017 John Sperbeck
+ *
+ * Test faults to "interesting" locations.
+ */
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/mman.h>
+#include <assert.h>
+#include <ucontext.h>
+
+#include "utils.h"
+
+#define PAGE_SIZE	(64*1024)
+#define TB		(1024ULL*1024*1024*1024)
+static volatile bool faulted;
+static volatile int si_code;
+
+static void segv_handler(int n, siginfo_t *info, void *ctxt_v)
+{
+	ucontext_t *ctxt = (ucontext_t *)ctxt_v;
+	struct pt_regs *regs = ctxt->uc_mcontext.regs;
+
+	faulted = true;
+	si_code = info->si_code;
+	regs->nip += 4;
+}
+
+int test_segv_errors(void)
+{
+	struct sigaction act = {
+		.sa_sigaction = segv_handler,
+		.sa_flags = SA_SIGINFO,
+	};
+	static unsigned long ptrs[] = {
+		0x0f00000000000000ULL, /* Radix Q0 out of pgtable range */
+		0x4000000000000000ULL, /* Radix Q1 */
+		0x4f00000000000000ULL, /* Radix Q1 out of pgtable range */
+		0x8000000000000000ULL, /* Radix Q2 */
+		0x8f00000000000000ULL, /* Radix Q2 out of pgtable range */
+		0xc000000000000000ULL, /* Radix Q3 */
+		0xcf00000000000000ULL, /* Radix Q3 out of pgtable range */
+		0xc000000000000000ULL, /* Hash kernel region */
+		0xc000000000000000ULL + TB, /* Hash kernel region + 1 segment */
+		0xc000000000000000ULL + TB - 1,
+		0xd000000000000000ULL, /* Hash vmalloc region */
+		0xd000000000000000ULL + TB,
+		0xd000000000000000ULL + TB - 1,
+		0xe000000000000000ULL,
+		0xe000000000000000ULL + TB,
+		0xe000000000000000ULL + TB - 1,
+		0xf000000000000000ULL, /* Hash vmemmap region */
+		0xf000000000000000ULL + TB,
+		0xf000000000000000ULL + TB - 1,
+	};
+	size_t i;
+
+	FAIL_IF(sigaction(SIGSEGV, &act, NULL) != 0);
+
+	for (i = 0; i < sizeof(ptrs)/sizeof(ptrs[0]); i++) {
+		volatile char *p = (void *)ptrs[i];
+
+		/*
+		 * We just need a compiler barrier, but mb() works and has the
+		 * nice property of being easy to spot in the disassembly.
+		 */
+		printf("testing %p...\n", p);
+		faulted = false;
+		si_code = 0;
+		mb();
+		(void)*p;
+		mb();
+		FAIL_IF(!faulted);
+		FAIL_IF(si_code != SEGV_MAPERR && si_code != SEGV_BNDERR);
+		/*
+		 * Some accesses throw MAPERR, others BNDERR. Possibly all
+		 * Q>0 accesses should cause BNDERR.
+		 */
+	}
+
+	return 0;
+}
+
+int main(void)
+{
+	return test_harness(test_segv_errors, "segv_errors");
+}
-- 
2.20.1


^ permalink raw reply related

* RE: [EXT] Re: [PATCH V1] ASoC: fsl_esai: replace fall-through with break
From: S.j. Wang @ 2019-04-09  2:54 UTC (permalink / raw)
  To: Gustavo A. R. Silva, timur@kernel.org, nicoleotsuka@gmail.com,
	Xiubo.Lee@gmail.com, festevam@gmail.com, broonie@kernel.org,
	alsa-devel@alsa-project.org
  Cc: linuxppc-dev@lists.ozlabs.org
In-Reply-To: <38a6d36e-0f8e-fe3d-202b-30371042e248@embeddedor.com>

Hi Gustavo

> 
> 
> On 4/8/19 4:28 AM, S.j. Wang wrote:
> > case ESAI_HCKT_EXTAL and case ESAI_HCKR_EXTAL should be
> independent of
> > each other, so replace fall-through with break.
> >
> If this is correct, then you should use the following "Fixes" tag instead,
> which is the one that introduced the bug:
> 
> Fixes: 43d24e76b698 ("ASoC: fsl_esai: Add ESAI CPU DAI driver")
> 
> > Fixes: 16bbeb2b43c3 ("ASoC: fsl_esai: Mark expected switch
> > fall-through")
> >
>         ^^^^
> because this didn't change any functionality.

Ok, this will be updated.

> 
> > Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> > ---
> >  sound/soc/fsl/fsl_esai.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c index
> > c7410bbfd2af..bad0dfed6b68 100644
> > --- a/sound/soc/fsl/fsl_esai.c
> > +++ b/sound/soc/fsl/fsl_esai.c
> > @@ -251,7 +251,7 @@ static int fsl_esai_set_dai_sysclk(struct
> snd_soc_dai *dai, int clk_id,
> >               break;
> >       case ESAI_HCKT_EXTAL:
> >               ecr |= ESAI_ECR_ETI;
> 
> Also, you should use a simple assignment operator "=" instead of "|=" in
> both cases.

The result is same for "=" and "|=", because there is "ecr = 0" in beginning of
This function. 

> 
> > -             /* fall through */
> > +             break;
> >       case ESAI_HCKR_EXTAL:
> >               ecr |= esai_priv->synchronous ? ESAI_ECR_ETI : ESAI_ECR_ERI;
> >               break;
> >
> 
> Thanks
> --
> Gustavo

^ permalink raw reply

* Re: [RFC PATCH v2 10/14] kernel/watchdog: Add a function to obtain the watchdog_allowed_mask
From: Ricardo Neri @ 2019-04-09  2:05 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Rafael J. Wysocki, Peter Zijlstra, Alexei Starovoitov,
	Kai-Heng Feng, Paul Mackerras, H. Peter Anvin, sparclinux,
	Ingo Molnar, Christoffer Dall, Davidlohr Bueso, Ashok Raj, x86,
	David Rientjes, Andi Kleen, Waiman Long, Borislav Petkov,
	Don Zickus, Ravi V. Shankar, Konrad Rzeszutek Wilk, Marc Zyngier,
	Frederic Weisbecker, Nicholas Piggin, Ricardo Neri,
	Byungchul Park, Mathieu Desnoyers, Josh Poimboeuf,
	Paul E. McKenney, Tony Luck, Babu Moger, Randy Dunlap,
	linux-kernel, Luis R. Rodriguez, Masami Hiramatsu,
	Philippe Ombredanne, Colin Ian King, Andrew Morton, linuxppc-dev,
	David S. Miller
In-Reply-To: <alpine.DEB.2.21.1903262221140.1789@nanos.tec.linutronix.de>

On Tue, Mar 26, 2019 at 10:22:40PM +0100, Thomas Gleixner wrote:
> On Wed, 27 Feb 2019, Ricardo Neri wrote:
> >  
> > -struct cpumask watchdog_allowed_mask __read_mostly;
> > +static struct cpumask watchdog_allowed_mask __read_mostly;
> 
> That hunk is correct.

I'll send a separate patch with this hunk only.
> 
> >  struct cpumask watchdog_cpumask __read_mostly;
> >  unsigned long *watchdog_cpumask_bits = cpumask_bits(&watchdog_cpumask);
> > @@ -92,6 +92,11 @@ static int __init hardlockup_all_cpu_backtrace_setup(char *str)
> >  }
> >  __setup("hardlockup_all_cpu_backtrace=", hardlockup_all_cpu_backtrace_setup);
> >  # endif /* CONFIG_SMP */
> > +
> > +struct cpumask *watchdog_get_allowed_cpumask(void)
> > +{
> > +	return &watchdog_allowed_mask;
> > +}
> 
> That part is pointless as I showed you in the other reply. You don't need
> that mask in your code at all.

Yes. I'll remove this hunk and follow the approach you suggested in your
reply to patch 11.

Thanks and BR,
Ricardo
> 
> Thanks,
> 
> 	tglx
> 
> 

^ permalink raw reply

* Re: [RFC PATCH v2 09/14] watchdog/hardlockup: Make arch_touch_nmi_watchdog() to hpet-based implementation
From: Ricardo Neri @ 2019-04-09  2:05 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Rafael J. Wysocki, Peter Zijlstra, Alexei Starovoitov,
	Kai-Heng Feng, Paul Mackerras, H. Peter Anvin, sparclinux,
	Paul E. McKenney, Ingo Molnar, Christoffer Dall, Davidlohr Bueso,
	Ashok Raj, x86, David Rientjes, Andi Kleen, Waiman Long,
	Borislav Petkov, Don Zickus, Ravi V. Shankar,
	Konrad Rzeszutek Wilk, Marc Zyngier, Frederic Weisbecker,
	Nicholas Piggin, Ricardo Neri, Byungchul Park, Mathieu Desnoyers,
	Josh Poimboeuf, Tony Luck, Babu Moger, Randy Dunlap, linux-kernel,
	Luis R. Rodriguez, Masami Hiramatsu, Philippe Ombredanne,
	Colin Ian King, Andrew Morton, linuxppc-dev, David S. Miller
In-Reply-To: <alpine.DEB.2.21.1903262219100.1789@nanos.tec.linutronix.de>

On Tue, Mar 26, 2019 at 10:20:41PM +0100, Thomas Gleixner wrote:
> On Thu, 28 Feb 2019, Ricardo Neri wrote:
> > > > 
> > > > -#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
> > > > +#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF) || \
> > > > +    defined(CONFIG_X86_HARDLOCKUP_DETECTOR_HPET)
> > > 
> > > Why not instead make CONFIG_X86_HARDLOCKUP_DETECTOR_HPET select
> > > CONFIG_HARDLOCKUP_DETECTOR_PERF?  Keep the arch-specific details
> > > in the arch-specific files and all that.
> > 
> > Thanks for your feedback, Paul! The HPET implementation does not use
> > perf. Thus, in my opinion is not correct for the HPET HLD to select
> > the perf implementation. Patch 8 of this series splits the perf-specific
> > code and the generic hardlockup detector code. Does this make sense?
> 
> That's what intermediate config symbols are for.
> 
> config HARDLOCKUP_DETECTOR_CORE
>        bool
> 
> And make both PERF and HPET select it.

I'll implement it in this manner.

Thanks and BR,
Ricardo

^ permalink raw reply

* Re: [RFC PATCH v2 08/14] watchdog/hardlockup: Decouple the hardlockup detector from perf
From: Ricardo Neri @ 2019-04-09  2:05 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Peter Zijlstra, Ricardo Neri, Paul Mackerras, H. Peter Anvin,
	sparclinux, Ingo Molnar, Ashok Raj, x86, Andi Kleen,
	Borislav Petkov, Don Zickus, Ravi V. Shankar, Frederic Weisbecker,
	Nicholas Piggin, Mathieu Desnoyers, Tony Luck, Babu Moger,
	linux-kernel, Luis R. Rodriguez, Masami Hiramatsu,
	Philippe Ombredanne, Colin Ian King, Andrew Morton, linuxppc-dev,
	David S. Miller
In-Reply-To: <alpine.DEB.2.21.1903262213470.1789@nanos.tec.linutronix.de>

On Tue, Mar 26, 2019 at 10:18:32PM +0100, Thomas Gleixner wrote:
> On Wed, 27 Feb 2019, Ricardo Neri wrote:
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Detect hard lockups on a system
> > + *
> > + * Copyright (C) Intel Corporation 2019
> > + *
> > + * Note: All of this code comes from the original perf-specific hardlockup
> > + * detector.
> 
> And because you copied it from there without modification this becomes
> automatically Copyrighted by Intel?

Yes, it does not look correct.

> 
> May I recommend that you talk to your legal departement about this.
> 
> Aside of that there is really no value in creating yet another file. The
> code in question can simply wrapped into a large #ifdef PERF in the old
> file.

Sure, I'll implement the change in this manner.

Thanks and BR,
Ricardo

^ permalink raw reply

* Re: [PATCH 3/8] powerpc/eeh: Convert PNV_PHB_FLAG_EEH to global flag
From: Sam Bobroff @ 2019-04-09  1:41 UTC (permalink / raw)
  To: Alexey Kardashevskiy; +Cc: linuxppc-dev
In-Reply-To: <680b2264-93a8-6c75-88c1-ad0520b8e8a7@ozlabs.ru>

[-- Attachment #1: Type: text/plain, Size: 6774 bytes --]

On Wed, Mar 20, 2019 at 05:02:44PM +1100, Alexey Kardashevskiy wrote:
> 
> 
> On 20/03/2019 13:58, Sam Bobroff wrote:
> > The PHB flag, PNV_PHB_FLAG_EEH, is set (on PowerNV) individually on
> > each PHB once the EEH subsystem is ready. It is the only use of the
> > flags member of the phb struct.
> 
> 
> Then why to keep pnv_phb::flags?

No reason. I'll remove it in the next version.

> > However there is no need to store this separately on each PHB, so
> > convert it to a global flag. For symmetry, the flag is now also set
> > for pSeries; although it is currently unused it may be useful in the
> > future.
> 
> Just using eeh_enabled() instead of (phb->flags & PNV_PHB_FLAG_EEH)
> seems easier and cleaner; also pseries does not use it so there is no
> point defining it there either.

I do want to do that. However, eeh_enabled() seems to be slightly
different from PNV_PHB_FLAG_EEH:

- eeh_enabled() is true as soon as the first device with EEH support is
  detected.
- eeh_phb_enabled() is true after EEH support has been enabled on every
  device that supports it.

So I was concerned that using eeh_enabled() would cause problems in
pnv_pci_config_check_eeh() if EEH was detected *during* the initial PCI
scanning phase when eeh_enabled() was true but EEH had not yet been set
up on the device or PHB where it was detected.

Does that make sense?

Would it be reasonable to keep this patch as it is for now and
investigate cleaning it up in a future patch?

> > 
> > Signed-off-by: Sam Bobroff <sbobroff@linux.ibm.com>
> > ---
> >  arch/powerpc/include/asm/eeh.h               | 11 +++++++++++
> >  arch/powerpc/platforms/powernv/eeh-powernv.c | 14 +++-----------
> >  arch/powerpc/platforms/powernv/pci.c         |  7 +++----
> >  arch/powerpc/platforms/powernv/pci.h         |  2 --
> >  arch/powerpc/platforms/pseries/pci.c         |  4 ++++
> >  5 files changed, 21 insertions(+), 17 deletions(-)
> > 
> > diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
> > index 3613a56281f2..fe4cf7208890 100644
> > --- a/arch/powerpc/include/asm/eeh.h
> > +++ b/arch/powerpc/include/asm/eeh.h
> > @@ -43,6 +43,7 @@ struct pci_dn;
> >  #define EEH_VALID_PE_ZERO	0x10	/* PE#0 is valid		     */
> >  #define EEH_ENABLE_IO_FOR_LOG	0x20	/* Enable IO for log		     */
> >  #define EEH_EARLY_DUMP_LOG	0x40	/* Dump log immediately		     */
> > +#define EEH_PHB_ENABLED		0x80	/* PHB recovery uses EEH	     */
> >  
> >  /*
> >   * Delay for PE reset, all in ms
> > @@ -245,6 +246,11 @@ static inline bool eeh_enabled(void)
> >  	return eeh_has_flag(EEH_ENABLED) && !eeh_has_flag(EEH_FORCE_DISABLED);
> >  }
> >  
> > +static inline bool eeh_phb_enabled(void)
> > +{
> > +	return eeh_has_flag(EEH_PHB_ENABLED);
> > +}
> > +
> >  static inline void eeh_serialize_lock(unsigned long *flags)
> >  {
> >  	raw_spin_lock_irqsave(&confirm_error_lock, *flags);
> > @@ -332,6 +338,11 @@ static inline bool eeh_enabled(void)
> >          return false;
> >  }
> >  
> > +static inline bool eeh_phb_enabled(void)
> > +{
> > +	return false;
> > +}
> > +
> >  static inline void eeh_probe_devices(void) { }
> >  
> >  static inline void *eeh_dev_init(struct pci_dn *pdn, void *data)
> > diff --git a/arch/powerpc/platforms/powernv/eeh-powernv.c b/arch/powerpc/platforms/powernv/eeh-powernv.c
> > index 6fc1a463b796..f0a95f663810 100644
> > --- a/arch/powerpc/platforms/powernv/eeh-powernv.c
> > +++ b/arch/powerpc/platforms/powernv/eeh-powernv.c
> > @@ -264,22 +264,14 @@ int pnv_eeh_post_init(void)
> >  		return ret;
> >  	}
> >  
> > -	if (!eeh_enabled())
> > +	if (eeh_enabled())
> > +		eeh_add_flag(EEH_PHB_ENABLED);
> > +	else
> >  		disable_irq(eeh_event_irq);
> >  
> >  	list_for_each_entry(hose, &hose_list, list_node) {
> >  		phb = hose->private_data;
> >  
> > -		/*
> > -		 * If EEH is enabled, we're going to rely on that.
> > -		 * Otherwise, we restore to conventional mechanism
> > -		 * to clear frozen PE during PCI config access.
> > -		 */
> > -		if (eeh_enabled())
> > -			phb->flags |= PNV_PHB_FLAG_EEH;
> > -		else
> > -			phb->flags &= ~PNV_PHB_FLAG_EEH;
> > -
> >  		/* Create debugfs entries */
> >  #ifdef CONFIG_DEBUG_FS
> >  		if (phb->has_dbgfs || !phb->dbgfs)
> > diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
> > index 307181fd8a17..d2b50f3bf6b1 100644
> > --- a/arch/powerpc/platforms/powernv/pci.c
> > +++ b/arch/powerpc/platforms/powernv/pci.c
> > @@ -717,10 +717,9 @@ int pnv_pci_cfg_write(struct pci_dn *pdn,
> >  static bool pnv_pci_cfg_check(struct pci_dn *pdn)
> >  {
> >  	struct eeh_dev *edev = NULL;
> > -	struct pnv_phb *phb = pdn->phb->private_data;
> >  
> >  	/* EEH not enabled ? */
> > -	if (!(phb->flags & PNV_PHB_FLAG_EEH))
> > +	if (!eeh_phb_enabled())
> >  		return true;
> >  
> >  	/* PE reset or device removed ? */
> > @@ -761,7 +760,7 @@ static int pnv_pci_read_config(struct pci_bus *bus,
> >  
> >  	ret = pnv_pci_cfg_read(pdn, where, size, val);
> >  	phb = pdn->phb->private_data;
> > -	if (phb->flags & PNV_PHB_FLAG_EEH && pdn->edev) {
> > +	if (eeh_phb_enabled() && pdn->edev) {
> >  		if (*val == EEH_IO_ERROR_VALUE(size) &&
> >  		    eeh_dev_check_failure(pdn->edev))
> >                          return PCIBIOS_DEVICE_NOT_FOUND;
> > @@ -789,7 +788,7 @@ static int pnv_pci_write_config(struct pci_bus *bus,
> >  
> >  	ret = pnv_pci_cfg_write(pdn, where, size, val);
> >  	phb = pdn->phb->private_data;
> > -	if (!(phb->flags & PNV_PHB_FLAG_EEH))
> > +	if (!eeh_phb_enabled())
> >  		pnv_pci_config_check_eeh(pdn);
> >  
> >  	return ret;
> > diff --git a/arch/powerpc/platforms/powernv/pci.h b/arch/powerpc/platforms/powernv/pci.h
> > index 8e36da379252..eb0add61397b 100644
> > --- a/arch/powerpc/platforms/powernv/pci.h
> > +++ b/arch/powerpc/platforms/powernv/pci.h
> > @@ -85,8 +85,6 @@ struct pnv_ioda_pe {
> >  	struct list_head	list;
> >  };
> >  
> > -#define PNV_PHB_FLAG_EEH	(1 << 0)
> > -
> >  struct pnv_phb {
> >  	struct pci_controller	*hose;
> >  	enum pnv_phb_type	type;
> > diff --git a/arch/powerpc/platforms/pseries/pci.c b/arch/powerpc/platforms/pseries/pci.c
> > index 37a77e57893e..7be80882c08d 100644
> > --- a/arch/powerpc/platforms/pseries/pci.c
> > +++ b/arch/powerpc/platforms/pseries/pci.c
> > @@ -244,6 +244,10 @@ void __init pSeries_final_fixup(void)
> >  
> >  	eeh_probe_devices();
> >  	eeh_addr_cache_build();
> > +#ifdef CONFIG_EEH
> > +	if (eeh_enabled())
> > +		eeh_add_flag(EEH_PHB_ENABLED);
> > +#endif
> >  
> >  #ifdef CONFIG_PCI_IOV
> >  	ppc_md.pcibios_sriov_enable = pseries_pcibios_sriov_enable;
> > 
> 
> -- 
> Alexey
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply

* Re: [PATCH V3 0/7] Add FOLL_LONGTERM to GUP fast and use it
From: Ira Weiny @ 2019-04-09  0:13 UTC (permalink / raw)
  To: Andrew Morton, John Hubbard, Michal Hocko, Kirill A. Shutemov,
	Peter Zijlstra, Jason Gunthorpe, Benjamin Herrenschmidt,
	Paul Mackerras, David S. Miller, Martin Schwidefsky,
	Heiko Carstens, Rich Felker, Yoshinori Sato, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Ralf Baechle, James Hogan
  Cc: linux-s390, linux-sh, linux-rdma, netdev, linux-kernel,
	linux-mips, linux-mm, sparclinux, linuxppc-dev
In-Reply-To: <20190328084422.29911-1-ira.weiny@intel.com>

On Thu, Mar 28, 2019 at 01:44:15AM -0700, 'Ira Weiny' wrote:
> From: Ira Weiny <ira.weiny@intel.com>
> 
> Following discussion and review[1] here are the cleanups requested.
> 
> The biggest change for V3 was the disabling of the ability to use FOLL_LONGTERM
> in get_user_pages[unlocked|locked|remote]
> 
> Comments were also enhanced throughout to show potential users what
> FOLL_LONGTERM is all about and limitations it has.

Does anyone have any problems with these changes?

I would like to get official Reviewed-by tags if possible.

Thanks,
Ira

> 
> Minor review comments were fixed
> 
> Original cover letter:
> 
> HFI1, qib, and mthca, use get_user_pages_fast() due to it performance
> advantages.  These pages can be held for a significant time.  But
> get_user_pages_fast() does not protect against mapping FS DAX pages.
> 
> Introduce FOLL_LONGTERM and use this flag in get_user_pages_fast() which
> retains the performance while also adding the FS DAX checks.  XDP has also
> shown interest in using this functionality.[1]
> 
> In addition we change get_user_pages() to use the new FOLL_LONGTERM flag and
> remove the specialized get_user_pages_longterm call.
> 
> [1] https://lkml.org/lkml/2019/3/19/939
> 
> 
> 
> Ira Weiny (7):
>   mm/gup: Replace get_user_pages_longterm() with FOLL_LONGTERM
>   mm/gup: Change write parameter to flags in fast walk
>   mm/gup: Change GUP fast to use flags rather than a write 'bool'
>   mm/gup: Add FOLL_LONGTERM capability to GUP fast
>   IB/hfi1: Use the new FOLL_LONGTERM flag to get_user_pages_fast()
>   IB/qib: Use the new FOLL_LONGTERM flag to get_user_pages_fast()
>   IB/mthca: Use the new FOLL_LONGTERM flag to get_user_pages_fast()
> 
>  arch/mips/mm/gup.c                          |  11 +-
>  arch/powerpc/kvm/book3s_64_mmu_hv.c         |   4 +-
>  arch/powerpc/kvm/e500_mmu.c                 |   2 +-
>  arch/powerpc/mm/mmu_context_iommu.c         |   3 +-
>  arch/s390/kvm/interrupt.c                   |   2 +-
>  arch/s390/mm/gup.c                          |  12 +-
>  arch/sh/mm/gup.c                            |  11 +-
>  arch/sparc/mm/gup.c                         |   9 +-
>  arch/x86/kvm/paging_tmpl.h                  |   2 +-
>  arch/x86/kvm/svm.c                          |   2 +-
>  drivers/fpga/dfl-afu-dma-region.c           |   2 +-
>  drivers/gpu/drm/via/via_dmablit.c           |   3 +-
>  drivers/infiniband/core/umem.c              |   5 +-
>  drivers/infiniband/hw/hfi1/user_pages.c     |   3 +-
>  drivers/infiniband/hw/mthca/mthca_memfree.c |   3 +-
>  drivers/infiniband/hw/qib/qib_user_pages.c  |   8 +-
>  drivers/infiniband/hw/qib/qib_user_sdma.c   |   2 +-
>  drivers/infiniband/hw/usnic/usnic_uiom.c    |   9 +-
>  drivers/media/v4l2-core/videobuf-dma-sg.c   |   6 +-
>  drivers/misc/genwqe/card_utils.c            |   2 +-
>  drivers/misc/vmw_vmci/vmci_host.c           |   2 +-
>  drivers/misc/vmw_vmci/vmci_queue_pair.c     |   6 +-
>  drivers/platform/goldfish/goldfish_pipe.c   |   3 +-
>  drivers/rapidio/devices/rio_mport_cdev.c    |   4 +-
>  drivers/sbus/char/oradax.c                  |   2 +-
>  drivers/scsi/st.c                           |   3 +-
>  drivers/staging/gasket/gasket_page_table.c  |   4 +-
>  drivers/tee/tee_shm.c                       |   2 +-
>  drivers/vfio/vfio_iommu_spapr_tce.c         |   3 +-
>  drivers/vfio/vfio_iommu_type1.c             |   3 +-
>  drivers/vhost/vhost.c                       |   2 +-
>  drivers/video/fbdev/pvr2fb.c                |   2 +-
>  drivers/virt/fsl_hypervisor.c               |   2 +-
>  drivers/xen/gntdev.c                        |   2 +-
>  fs/io_uring.c                               |   5 +-
>  fs/orangefs/orangefs-bufmap.c               |   2 +-
>  include/linux/mm.h                          |  45 ++-
>  kernel/futex.c                              |   2 +-
>  lib/iov_iter.c                              |   7 +-
>  mm/gup.c                                    | 288 +++++++++++++-------
>  mm/gup_benchmark.c                          |   5 +-
>  mm/util.c                                   |   8 +-
>  net/ceph/pagevec.c                          |   2 +-
>  net/rds/info.c                              |   2 +-
>  net/rds/rdma.c                              |   3 +-
>  net/xdp/xdp_umem.c                          |   4 +-
>  46 files changed, 314 insertions(+), 200 deletions(-)
> 
> -- 
> 2.20.1
> 

^ permalink raw reply

* [PATCH v2 3/3] powerpc: Add support to initialize ima policy rules
From: Nayna Jain @ 2019-04-08 22:52 UTC (permalink / raw)
  To: linuxppc-dev, linux-efi, linux-integrity, linux-kernel
  Cc: Ard Biesheuvel, Nayna Jain, Claudio Carvalho, Mimi Zohar,
	Matthew Garret, Paul Mackerras, Jeremy Kerr
In-Reply-To: <1554763954-11795-1-git-send-email-nayna@linux.ibm.com>

PowerNV secure boot relies on the kernel IMA security subsystem to
perform the OS kernel image signature verification. Since each secure
boot mode has different IMA policy requirements, dynamic definition of
the policy rules based on the runtime secure boot mode of the system is
required. On systems that support secure boot, but have it disabled,
only measurement policy rules of the kernel image and modules are
defined.

This patch defines the arch-specific implementation to retrieve the
secure boot mode of the system and accordingly configures the IMA policy
rules.

This patch provides arch-specific IMA policies if PPC_SECURE_BOOT
config is enabled.

Signed-off-by: Nayna Jain <nayna@linux.ibm.com>
---
 arch/powerpc/Kconfig           | 14 +++++++++
 arch/powerpc/kernel/Makefile   |  1 +
 arch/powerpc/kernel/ima_arch.c | 54 ++++++++++++++++++++++++++++++++++
 include/linux/ima.h            |  3 +-
 4 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/kernel/ima_arch.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 2d0be82c3061..7407af79ed8a 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -901,6 +901,20 @@ config PPC_MEM_KEYS
 
 	  If unsure, say y.
 
+config PPC_SECURE_BOOT
+	prompt "Enable PowerPC Secure Boot"
+	bool
+	default n
+	depends on PPC64
+	depends on OPAL_SECVAR
+	depends on IMA
+	depends on IMA_ARCH_POLICY
+	help
+	  Linux on POWER with firmware secure boot enabled needs to define
+	  security policies to extend secure boot to the OS.
+	  This config allows user to enable OS Secure Boot on PowerPC systems
+	  that have firmware secure boot support.
+
 endmenu
 
 config ISA_DMA_API
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index cddadccf551d..fcbc7a94888b 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -119,6 +119,7 @@ ifdef CONFIG_IMA
 obj-y				+= ima_kexec.o
 endif
 endif
+obj-$(CONFIG_PPC_SECURE_BOOT)	+= ima_arch.o
 
 obj-$(CONFIG_AUDIT)		+= audit.o
 obj64-$(CONFIG_AUDIT)		+= compat_audit.o
diff --git a/arch/powerpc/kernel/ima_arch.c b/arch/powerpc/kernel/ima_arch.c
new file mode 100644
index 000000000000..871b321656fb
--- /dev/null
+++ b/arch/powerpc/kernel/ima_arch.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 IBM Corporation
+ * Author: Nayna Jain <nayna@linux.ibm.com>
+ *
+ * ima_arch.c
+ *      - initialize ima policies for PowerPC Secure Boot
+ */
+
+#include <linux/ima.h>
+#include <asm/secboot.h>
+
+bool arch_ima_get_secureboot(void)
+{
+	bool sb_mode;
+
+	sb_mode = get_powerpc_sb_mode();
+	if (sb_mode)
+		return true;
+	else
+		return false;
+}
+
+/*
+ * File signature verification is not needed, include only measurements
+ */
+static const char *const default_arch_rules[] = {
+	"measure func=KEXEC_KERNEL_CHECK",
+	"measure func=MODULE_CHECK",
+	NULL
+};
+
+/* Both file signature verification and measurements are needed */
+static const char *const sb_arch_rules[] = {
+	"measure func=KEXEC_KERNEL_CHECK",
+	"measure func=MODULE_CHECK",
+	"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",
+#if !IS_ENABLED(CONFIG_MODULE_SIG)
+	"appraise func=MODULE_CHECK appraise_type=imasig",
+#endif
+	NULL
+};
+
+/*
+ * On PowerPC, file measurements are to be added to the IMA measurement list
+ * irrespective of the secure boot state of the system. Signature verification
+ * is conditionally enabled based on the secure boot state.
+ */
+const char *const *arch_get_ima_policy(void)
+{
+	if (IS_ENABLED(CONFIG_IMA_ARCH_POLICY) && arch_ima_get_secureboot())
+		return sb_arch_rules;
+	return default_arch_rules;
+}
diff --git a/include/linux/ima.h b/include/linux/ima.h
index dc12fbcf484c..ab81a204cf4c 100644
--- a/include/linux/ima.h
+++ b/include/linux/ima.h
@@ -31,7 +31,8 @@ extern void ima_post_path_mknod(struct dentry *dentry);
 extern void ima_add_kexec_buffer(struct kimage *image);
 #endif
 
-#if defined(CONFIG_X86) && defined(CONFIG_EFI)
+#if (defined(CONFIG_X86) && defined(CONFIG_EFI)) \
+			 || defined(CONFIG_PPC_SECURE_BOOT)
 extern bool arch_ima_get_secureboot(void);
 extern const char * const *arch_get_ima_policy(void);
 #else
-- 
2.20.1


^ permalink raw reply related

* [PATCH v2 2/3] powerpc/powernv: detect the secure boot mode of the system
From: Nayna Jain @ 2019-04-08 22:52 UTC (permalink / raw)
  To: linuxppc-dev, linux-efi, linux-integrity, linux-kernel
  Cc: Ard Biesheuvel, Nayna Jain, Claudio Carvalho, Mimi Zohar,
	Matthew Garret, Paul Mackerras, Jeremy Kerr
In-Reply-To: <1554763954-11795-1-git-send-email-nayna@linux.ibm.com>

PowerNV secure boot defines different IMA policies based on the secure
boot state of the system.

This patch defines a function to detect the secure boot state of the
system.

Signed-off-by: Nayna Jain <nayna@linux.ibm.com>
---
 arch/powerpc/include/asm/secboot.h       | 21 +++++++++
 arch/powerpc/platforms/powernv/Makefile  |  3 +-
 arch/powerpc/platforms/powernv/secboot.c | 54 ++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/include/asm/secboot.h
 create mode 100644 arch/powerpc/platforms/powernv/secboot.c

diff --git a/arch/powerpc/include/asm/secboot.h b/arch/powerpc/include/asm/secboot.h
new file mode 100644
index 000000000000..1904fb4a3352
--- /dev/null
+++ b/arch/powerpc/include/asm/secboot.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * PowerPC secure boot definitions
+ *
+ * Copyright (C) 2019 IBM Corporation
+ * Author: Nayna Jain <nayna@linux.ibm.com>
+ *
+ */
+#ifndef POWERPC_SECBOOT_H
+#define POWERPC_SECBOOT_H
+
+#if defined(CONFIG_OPAL_SECVAR)
+extern bool get_powerpc_sb_mode(void);
+#else
+static inline bool get_powerpc_sb_mode(void)
+{
+	return false;
+}
+#endif
+
+#endif
diff --git a/arch/powerpc/platforms/powernv/Makefile b/arch/powerpc/platforms/powernv/Makefile
index 1511d836fd19..e3224f1019eb 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -4,6 +4,7 @@ obj-y			+= idle.o opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o
 obj-y			+= rng.o opal-elog.o opal-dump.o opal-sysparam.o opal-sensor.o
 obj-y			+= opal-msglog.o opal-hmi.o opal-power.o opal-irqchip.o
 obj-y			+= opal-kmsg.o opal-powercap.o opal-psr.o opal-sensor-groups.o
+obj-y			+= secboot.o
 
 obj-$(CONFIG_SMP)	+= smp.o subcore.o subcore-asm.o
 obj-$(CONFIG_PCI)	+= pci.o pci-ioda.o npu-dma.o pci-ioda-tce.o
@@ -16,4 +17,4 @@ obj-$(CONFIG_PERF_EVENTS) += opal-imc.o
 obj-$(CONFIG_PPC_MEMTRACE)	+= memtrace.o
 obj-$(CONFIG_PPC_VAS)	+= vas.o vas-window.o vas-debug.o
 obj-$(CONFIG_OCXL_BASE)	+= ocxl.o
-obj-$(CONFIG_OPAL_SECVAR)	+= opal-secvar.o
+obj-$(CONFIG_OPAL_SECVAR)	+= opal-secvar.o secboot.o
diff --git a/arch/powerpc/platforms/powernv/secboot.c b/arch/powerpc/platforms/powernv/secboot.c
new file mode 100644
index 000000000000..a9c5717bb78e
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/secboot.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 IBM Corporation
+ * Author: Nayna Jain <nayna@linux.ibm.com>
+ *
+ * secboot.c
+ *      - util functions to get powerpc secboot state
+ */
+#include <linux/efi.h>
+#include <asm/secboot.h>
+#include <asm/opal-secvar.h>
+
+bool get_powerpc_sb_mode(void)
+{
+	efi_char16_t efi_SecureBoot_name[] = L"SecureBoot";
+	efi_char16_t efi_SetupMode_name[] = L"SetupMode";
+	efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
+	efi_status_t status;
+	u8 secboot, setupmode;
+	unsigned long size = sizeof(secboot);
+
+	status = opal_get_variable(efi_SecureBoot_name, &efi_variable_guid,
+				  NULL, &size, &secboot);
+
+	/*
+	 * For now assume all failures reading the SecureBoot variable implies
+	 * secure boot is not enabled. Later differentiate failure types.
+	 */
+	if (status != EFI_SUCCESS) {
+		secboot = 0;
+		setupmode = 0;
+		goto out;
+	}
+
+	size = sizeof(setupmode);
+	status = opal_get_variable(efi_SetupMode_name, &efi_variable_guid,
+				  NULL, &size, &setupmode);
+
+	/*
+	 * Failure to read the SetupMode variable does not prevent
+	 * secure boot mode
+	 */
+	if (status != EFI_SUCCESS)
+		setupmode = 0;
+
+out:
+	if ((secboot == 0) || (setupmode == 1)) {
+		pr_info("secboot: secureboot mode disabled\n");
+		return false;
+	}
+
+	pr_info("secboot: secureboot mode enabled\n");
+	return true;
+}
-- 
2.20.1


^ permalink raw reply related

* [PATCH v2 1/3] powerpc/powernv: Add support for OPAL_SECVAR_GET
From: Nayna Jain @ 2019-04-08 22:52 UTC (permalink / raw)
  To: linuxppc-dev, linux-efi, linux-integrity, linux-kernel
  Cc: Ard Biesheuvel, Nayna Jain, Claudio Carvalho, Mimi Zohar,
	Matthew Garret, Paul Mackerras, Jeremy Kerr
In-Reply-To: <1554763954-11795-1-git-send-email-nayna@linux.ibm.com>

From: Claudio Carvalho <cclaudio@linux.ibm.com>

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.

This patch adds support to read OPAL secure variables through
OPAL_SECVAR_GET call. It returns the data for a given secure variable
and vendor GUID. It can be configured using CONFIG_OPAL_SECVAR.

Signed-off-by: Claudio Carvalho <cclaudio@linux.ibm.com>

---
This patch depends on a new OPAL call that is being added to skiboot.
The patch set that implements the new call has been posted to
https://patchwork.ozlabs.org/project/skiboot/list/?series=99805
---
 arch/powerpc/include/asm/opal-api.h          |   3 +-
 arch/powerpc/include/asm/opal-secvar.h       |  18 ++++
 arch/powerpc/include/asm/opal.h              |   2 +
 arch/powerpc/platforms/powernv/Kconfig       |   6 ++
 arch/powerpc/platforms/powernv/Makefile      |   1 +
 arch/powerpc/platforms/powernv/opal-call.c   |   1 +
 arch/powerpc/platforms/powernv/opal-secvar.c | 107 +++++++++++++++++++
 7 files changed, 137 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/include/asm/opal-secvar.h
 create mode 100644 arch/powerpc/platforms/powernv/opal-secvar.c

diff --git a/arch/powerpc/include/asm/opal-api.h b/arch/powerpc/include/asm/opal-api.h
index 870fb7b239ea..782eb20a08a7 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -210,7 +210,8 @@
 #define OPAL_PCI_GET_PBCQ_TUNNEL_BAR		164
 #define OPAL_PCI_SET_PBCQ_TUNNEL_BAR		165
 #define	OPAL_NX_COPROC_INIT			167
-#define OPAL_LAST				167
+#define OPAL_SECVAR_GET				170
+#define OPAL_LAST				171
 
 #define QUIESCE_HOLD			1 /* Spin all calls at entry */
 #define QUIESCE_REJECT			2 /* Fail all calls with OPAL_BUSY */
diff --git a/arch/powerpc/include/asm/opal-secvar.h b/arch/powerpc/include/asm/opal-secvar.h
new file mode 100644
index 000000000000..e3d5e4cbf3bc
--- /dev/null
+++ b/arch/powerpc/include/asm/opal-secvar.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * PowerNV definitions for secure variables OPAL API.
+ *
+ * Copyright (C) 2019 IBM Corporation
+ * Author: Claudio Carvalho <cclaudio@linux.ibm.com>
+ *
+ */
+#ifndef OPAL_SECVAR_H
+#define OPAL_SECVAR_H
+
+#include <linux/efi.h>
+
+extern efi_status_t
+opal_get_variable(efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
+		  unsigned long *data_size, void *data);
+
+#endif
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index a55b01c90bb1..eb654baf8764 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -385,6 +385,8 @@ void opal_powercap_init(void);
 void opal_psr_init(void);
 void opal_sensor_groups_init(void);
 
+extern int opal_secvar_get(uint64_t name, uint64_t vendor, uint64_t attr,
+			   uint64_t data_size, uint64_t data);
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_OPAL_H */
diff --git a/arch/powerpc/platforms/powernv/Kconfig b/arch/powerpc/platforms/powernv/Kconfig
index 850eee860cf2..65b060539b5c 100644
--- a/arch/powerpc/platforms/powernv/Kconfig
+++ b/arch/powerpc/platforms/powernv/Kconfig
@@ -47,3 +47,9 @@ config PPC_VAS
 	  VAS adapters are found in POWER9 based systems.
 
 	  If unsure, say N.
+
+config OPAL_SECVAR
+	bool "OPAL Secure Variables"
+	depends on PPC_POWERNV
+	help
+	  This enables the kernel to access OPAL secure variables.
diff --git a/arch/powerpc/platforms/powernv/Makefile b/arch/powerpc/platforms/powernv/Makefile
index da2e99efbd04..1511d836fd19 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -16,3 +16,4 @@ obj-$(CONFIG_PERF_EVENTS) += opal-imc.o
 obj-$(CONFIG_PPC_MEMTRACE)	+= memtrace.o
 obj-$(CONFIG_PPC_VAS)	+= vas.o vas-window.o vas-debug.o
 obj-$(CONFIG_OCXL_BASE)	+= ocxl.o
+obj-$(CONFIG_OPAL_SECVAR)	+= opal-secvar.o
diff --git a/arch/powerpc/platforms/powernv/opal-call.c b/arch/powerpc/platforms/powernv/opal-call.c
index daad8c45c8e7..eafd8f690b7a 100644
--- a/arch/powerpc/platforms/powernv/opal-call.c
+++ b/arch/powerpc/platforms/powernv/opal-call.c
@@ -282,3 +282,4 @@ OPAL_CALL(opal_pci_set_pbcq_tunnel_bar,		OPAL_PCI_SET_PBCQ_TUNNEL_BAR);
 OPAL_CALL(opal_sensor_read_u64,			OPAL_SENSOR_READ_U64);
 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);
diff --git a/arch/powerpc/platforms/powernv/opal-secvar.c b/arch/powerpc/platforms/powernv/opal-secvar.c
new file mode 100644
index 000000000000..3ba02c9503f7
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/opal-secvar.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PowerNV code for secure variables
+ *
+ * Copyright (C) 2019 IBM Corporation
+ * Author: Claudio Carvalho <cclaudio@linux.ibm.com>
+ *
+ */
+
+/*
+ * The opal wrappers in this file treat the @name, @vendor, and @data
+ * parameters as little endian blobs.
+ * @name is a ucs2 string
+ * @vendor is the vendor GUID. It is converted to LE in the kernel
+ * @data variable data, which layout may be different for each variable
+ */
+
+#define pr_fmt(fmt) "secvar: "fmt
+
+#include <linux/efi.h>
+#include <asm/machdep.h>
+#include <asm/opal.h>
+#include <asm/opal-secvar.h>
+
+static bool is_opal_secvar_supported(void)
+{
+	static bool opal_secvar_supported;
+	static bool initialized;
+
+	if (initialized)
+		return opal_secvar_supported;
+
+	if (opal_check_token(OPAL_SECVAR_GET))
+		opal_secvar_supported = true;
+	else
+		opal_secvar_supported = false;
+
+	initialized = true;
+
+	return opal_secvar_supported;
+}
+
+efi_status_t opal_to_efi_status_log(int rc, const char *func_name)
+{
+	efi_status_t status;
+
+	switch (rc) {
+	case OPAL_EMPTY:
+		status = EFI_NOT_FOUND;
+		break;
+	case OPAL_HARDWARE:
+		status = EFI_DEVICE_ERROR;
+		break;
+	case OPAL_NO_MEM:
+		pr_err("%s: No space in the volatile storage\n", func_name);
+		status = EFI_OUT_OF_RESOURCES;
+		break;
+	case OPAL_PARAMETER:
+		status = EFI_INVALID_PARAMETER;
+		break;
+	case OPAL_PARTIAL:
+		status = EFI_BUFFER_TOO_SMALL;
+		break;
+	case OPAL_PERMISSION:
+		status = EFI_WRITE_PROTECTED;
+		break;
+	case OPAL_RESOURCE:
+		pr_err("%s: No space in the non-volatile storage\n", func_name);
+		status = EFI_OUT_OF_RESOURCES;
+		break;
+	case OPAL_SUCCESS:
+		status = EFI_SUCCESS;
+		break;
+	default:
+		pr_err("%s: Unknown OPAL error %d\n", func_name, rc);
+		status = EFI_DEVICE_ERROR;
+		break;
+	}
+
+	return status;
+}
+
+#define opal_to_efi_status(rc) opal_to_efi_status_log(rc, __func__)
+
+efi_status_t
+opal_get_variable(efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
+		  unsigned long *data_size, void *data)
+{
+	int rc;
+
+	if (!is_opal_secvar_supported())
+		return EFI_UNSUPPORTED;
+
+	*data_size = cpu_to_be64(*data_size);
+
+	rc = opal_secvar_get(__pa(name), __pa(vendor), __pa(attr),
+			     __pa(data_size), __pa(data));
+	/*
+	 * The @attr is an optional output parameter. It is returned in
+	 * big-endian.
+	 */
+	if (attr)
+		*attr = be32_to_cpup(attr);
+	*data_size = be64_to_cpu(*data_size);
+
+	return opal_to_efi_status(rc);
+}
-- 
2.20.1


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox