Re: [PATCH] dt-bindings: fsl,dpaa2-console: drop unneeded quotes

2023-11-22 Thread Krzysztof Kozlowski
On 22/11/2023 23:44, Rob Herring wrote:
> Drop unneeded quotes over simple string values to fix a soon to be
> enabled yamllint warning:
> 
>   [error] string value is redundantly quoted with any quotes (quoted-strings)
> 
> Signed-off-by: Rob Herring 

Reviewed-by: Krzysztof Kozlowski 

Best regards,
Krzysztof



Re: [PATCH RFC 06/12] mm/gup: Drop folio_fast_pin_allowed() in hugepd processing

2023-11-22 Thread Christoph Hellwig
On Wed, Nov 22, 2023 at 10:22:11AM -0500, Peter Xu wrote:
> The other reason I feel like hugepd may or may not be further developed for
> new features like large folio is that I saw Power9 started to shift to
> radix pgtables, and afaics hugepd is only supported in hash tables
> (hugepd_ok()).  But again, I confess I know nothing about Power at all.

That alone sounds like a good reason to not bother.  So unless more
qualified people have a different opinion I'm fine with this patch
as long as you leave a comment in place, and ammend the commit message
with some of the very useful information from your mail.



[PATCH] powerpc/lib: Validate size for vector operations

2023-11-22 Thread Naveen N Rao
Some of the fp/vmx code in sstep.c assume a certain maximum size for the
instructions being emulated. The size of those operations however is
determined separately in analyse_instr().

Add a check to validate the assumption on the maximum size of the
operations, so as to prevent any unintended kernel stack corruption.

Signed-off-by: Naveen N Rao 
---
 arch/powerpc/lib/sstep.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index a13f05cfc7db..5766180f5380 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -586,6 +586,8 @@ static int do_fp_load(struct instruction_op *op, unsigned 
long ea,
} u;
 
nb = GETSIZE(op->type);
+   if (nb > sizeof(u))
+   return -EINVAL;
if (!address_ok(regs, ea, nb))
return -EFAULT;
rn = op->reg;
@@ -636,6 +638,8 @@ static int do_fp_store(struct instruction_op *op, unsigned 
long ea,
} u;
 
nb = GETSIZE(op->type);
+   if (nb > sizeof(u))
+   return -EINVAL;
if (!address_ok(regs, ea, nb))
return -EFAULT;
rn = op->reg;
@@ -680,6 +684,9 @@ static nokprobe_inline int do_vec_load(int rn, unsigned 
long ea,
u8 b[sizeof(__vector128)];
} u = {};
 
+   if (size > sizeof(u))
+   return -EINVAL;
+
if (!address_ok(regs, ea & ~0xfUL, 16))
return -EFAULT;
/* align to multiple of size */
@@ -707,6 +714,9 @@ static nokprobe_inline int do_vec_store(int rn, unsigned 
long ea,
u8 b[sizeof(__vector128)];
} u;
 
+   if (size > sizeof(u))
+   return -EINVAL;
+
if (!address_ok(regs, ea & ~0xfUL, 16))
return -EFAULT;
/* align to multiple of size */

base-commit: 275f51172646ac48f0c4e690c72183084fd996d1
prerequisite-patch-id: ebc3edfe2b9fce7bdf27098c8631740153249b06
-- 
2.42.0



Re: [PATCH 8/8] CMDLINE: arm64: convert to generic builtin command line

2023-11-22 Thread Christophe Leroy


Le 10/11/2023 à 02:38, Daniel Walker a écrit :
> This removes arm64 from the device tree handling of the
> command line arguments.

You should provide more details on how each existing Kconfig option is 
converted, for instance when CONFIG_CMDLINE_FORCE becomes 
CONFIG_CMDLINE_OVERRIDE.

> 
> The boot_command_line variable is populated inside the earliest
> user of the command line, which is in idreg-override.c.
> 
> The device tree should not be needed to do any further handling
> of the boot command line options.

should not be ? But what's the result at the end, is it needed or not ?

> 
> Cc: xe-linux-exter...@cisco.com
> Signed-off-by: Daniel Walker 
> ---
>   arch/arm64/Kconfig  | 33 +
>   arch/arm64/include/asm/setup.h  |  4 
>   arch/arm64/include/uapi/asm/setup.h |  2 ++
>   arch/arm64/kernel/idreg-override.c  |  9 
>   arch/arm64/kernel/pi/kaslr_early.c  | 14 ++--
>   5 files changed, 19 insertions(+), 43 deletions(-)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 78f20e632712..d3b7fd1080d0 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -131,6 +131,7 @@ config ARM64
>   select GENERIC_ALLOCATOR
>   select GENERIC_ARCH_TOPOLOGY
>   select GENERIC_CLOCKEVENTS_BROADCAST
> + select GENERIC_CMDLINE
>   select GENERIC_CPU_AUTOPROBE
>   select GENERIC_CPU_VULNERABILITIES
>   select GENERIC_EARLY_IOREMAP
> @@ -2217,38 +2218,6 @@ config ARM64_ACPI_PARKING_PROTOCOL
> protocol even if the corresponding data is present in the ACPI
> MADT table.
>   
> -config CMDLINE
> - string "Default kernel command string"
> - default ""
> - help
> -   Provide a set of default command-line options at build time by
> -   entering them here. As a minimum, you should specify the the
> -   root device (e.g. root=/dev/nfs).
> -
> -choice
> - prompt "Kernel command line type" if CMDLINE != ""
> - default CMDLINE_FROM_BOOTLOADER
> - help
> -   Choose how the kernel will handle the provided default kernel
> -   command line string.
> -
> -config CMDLINE_FROM_BOOTLOADER
> - bool "Use bootloader kernel arguments if available"
> - help
> -   Uses the command-line options passed by the boot loader. If
> -   the boot loader doesn't provide any, the default kernel command
> -   string provided in CMDLINE will be used.
> -
> -config CMDLINE_FORCE
> - bool "Always use the default kernel command string"
> - help
> -   Always use the default kernel command string, even if the boot
> -   loader passes other arguments to the kernel.
> -   This is useful if you cannot or don't want to change the
> -   command-line options your boot loader passes to the kernel.
> -
> -endchoice
> -
>   config EFI_STUB
>   bool
>   
> diff --git a/arch/arm64/include/asm/setup.h b/arch/arm64/include/asm/setup.h
> index f4af547ef54c..5a8037262cbb 100644
> --- a/arch/arm64/include/asm/setup.h
> +++ b/arch/arm64/include/asm/setup.h
> @@ -3,10 +3,13 @@
>   #ifndef __ARM64_ASM_SETUP_H
>   #define __ARM64_ASM_SETUP_H
>   
> +#ifndef __ASSEMBLY__
>   #include 
> +#endif
>   
>   #include 
>   
> +#ifndef __ASSEMBLY__
>   void *get_early_fdt_ptr(void);
>   void early_fdt_map(u64 dt_phys);
>   
> @@ -30,5 +33,6 @@ static inline bool arch_parse_debug_rodata(char *arg)
>   return false;
>   }
>   #define arch_parse_debug_rodata arch_parse_debug_rodata
> +#endif /* __ASSEMBLY__ */
>   
>   #endif
> diff --git a/arch/arm64/include/uapi/asm/setup.h 
> b/arch/arm64/include/uapi/asm/setup.h
> index 5d703888f351..f5fc5b806369 100644
> --- a/arch/arm64/include/uapi/asm/setup.h
> +++ b/arch/arm64/include/uapi/asm/setup.h
> @@ -20,7 +20,9 @@
>   #ifndef __ASM_SETUP_H
>   #define __ASM_SETUP_H
>   
> +#ifndef __ASSEMBLY__
>   #include 
> +#endif
>   
>   #define COMMAND_LINE_SIZE   2048
>   
> diff --git a/arch/arm64/kernel/idreg-override.c 
> b/arch/arm64/kernel/idreg-override.c
> index 3addc09f8746..6334a9228909 100644
> --- a/arch/arm64/kernel/idreg-override.c
> +++ b/arch/arm64/kernel/idreg-override.c
> @@ -9,6 +9,7 @@
>   #include 
>   #include 
>   #include 
> +#include 
>   
>   #include 
>   #include 
> @@ -304,11 +305,11 @@ static __init void parse_cmdline(void)
>   {
>   const u8 *prop = get_bootargs_cmdline();
>   
> - if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !prop)
> - __parse_cmdline(CONFIG_CMDLINE, true);
> + strscpy(boot_command_line, prop, COMMAND_LINE_SIZE);
> + cmdline_add_builtin(boot_command_line);
> +
> + __parse_cmdline(boot_command_line, true);
>   
> - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop)
> - __parse_cmdline(prop, true);
>   }
>   
>   /* Keep checkers quiet */
> diff --git a/arch/arm64/kernel/pi/kaslr_early.c 
> b/arch/arm64/kernel/pi/kaslr_early.c
> index 17bff6e399e4..1e00bc01fa7a 100644
> --- a/arch/arm64/kernel/pi/kaslr_early.c
> +++ 

Re: [PATCH 7/8] of: replace command line handling

2023-11-22 Thread Christophe Leroy


Le 10/11/2023 à 02:38, Daniel Walker a écrit :
> Rob Herring has complained about this section of code. I removed the

This kind of considerations shouldn't appear in the commit message, it 
may appear after the --- so that it gets dropped when applying.

> command line handling code to the cmdline.h header. This hopefully makes
> it easier for Rob to maintain it (at least he doesn't have to look at it
> directly anymore). I would like to add a Kconfig option called
> OF_DEPRECATED_CMDLINE which an architecture would set if it uses this code.

Not sure to understand what you want to do and why that is needed. Why 
can't that work for everyone ? Avoid unnecessary options.

> This would allow a platform to use the cmdline.h and the added function
> directly and remove the Kconfig option. This change would be in a subsequent
> patch.

would or will ? Not sure it is worth mentioning if it won't.

> 
> This code was boot tested on powerpc 32bit, powerpc 64bit without
> any generic command line conversion.
> 
> Cc: xe-linux-exter...@cisco.com
> Signed-off-by: Daniel Walker 
> ---
>   drivers/of/fdt.c| 22 +++---
>   include/linux/cmdline.h | 31 +++
>   2 files changed, 34 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index bf502ba8da95..1fc1b17d04dc 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -26,6 +26,7 @@
>   #include 
>   #include 
>   #include 
> +#include 
>   
>   #include   /* for COMMAND_LINE_SIZE */
>   #include 
> @@ -1183,27 +1184,10 @@ int __init early_init_dt_scan_chosen(char *cmdline)
>   
>   /* Retrieve command line */
>   p = of_get_flat_dt_prop(node, "bootargs", );
> - if (p != NULL && l > 0)
> - strscpy(cmdline, p, min(l, COMMAND_LINE_SIZE));
>   
>   handle_cmdline:
> - /*
> -  * CONFIG_CMDLINE is meant to be a default in case nothing else
> -  * managed to set the command line, unless CONFIG_CMDLINE_FORCE
> -  * is set in which case we override whatever was found earlier.
> -  */
> -#ifdef CONFIG_CMDLINE
> -#if defined(CONFIG_CMDLINE_EXTEND)
> - strlcat(cmdline, " ", COMMAND_LINE_SIZE);
> - strlcat(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> -#elif defined(CONFIG_CMDLINE_FORCE)
> - strscpy(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> -#else
> - /* No arguments from boot loader, use kernel's  cmdl*/
> - if (!((char *)cmdline)[0])
> - strscpy(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> -#endif
> -#endif /* CONFIG_CMDLINE */
> +
> + of_deprecated_cmdline_update(cmdline, p, l);
>   
>   pr_debug("Command line is: %s\n", (char *)cmdline);
>   
> diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
> index a94758a0f257..c772afb7340f 100644
> --- a/include/linux/cmdline.h
> +++ b/include/linux/cmdline.h
> @@ -103,4 +103,35 @@ __cmdline_add_builtin(
>   
>   #define cmdline_get_static_builtin(dest) \
>   (CMDLINE_STATIC_PREPEND CMDLINE_STATIC_APPEND)
> +
> +#ifndef CONFIG_GENERIC_CMDLINE
> +static inline bool of_deprecated_cmdline_update(char *cmdline, const char 
> *dt_bootargs, int length)

Add a comment explaining why it is deprecated.

> +{
> + if (dt_bootargs != NULL && length > 0)
> + strlcpy(cmdline, dt_bootargs, min(length, COMMAND_LINE_SIZE));
> + /*
> +  * CONFIG_CMDLINE is meant to be a default in case nothing else
> +  * managed to set the command line, unless CONFIG_CMDLINE_FORCE
> +  * is set in which case we override whatever was found earlier.
> +  */
> +
> +#ifdef CONFIG_CMDLINE
> +#if defined(CONFIG_CMDLINE_EXTEND)
> + strlcat(cmdline, " ", COMMAND_LINE_SIZE);
> + strlcat(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> +#elif defined(CONFIG_CMDLINE_FORCE)
> + strscpy(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
> +#else
> + /* No arguments from boot loader, use kernel's  cmdl*/
> + if (!((char *)cmdline)[0])
> + strscpy(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
>   #endif
> +#endif /* CONFIG_CMDLINE */
> + return true;
> +}
> +#else
> +static inline bool of_deprecated_cmdline_update(char *cmdline, const char 
> *dt_bootargs, int length) { return false; }
> +#endif /* CONFIG_GENERIC_CMDLINE */
> +
> +
> +#endif /* _LINUX_CMDLINE_H */


Re: [PATCH 5/8] drivers: firmware: efi: libstub: enable generic commandline

2023-11-22 Thread Christophe Leroy


Le 10/11/2023 à 02:38, Daniel Walker a écrit :
> This adds code to handle the generic command line changes.
> The efi code appears that it doesn't benefit as much from this design
> as it could.

So what can we do to improve that ?


> 
> For example, if you had a prepend command line with "nokaslr" then
> you might be helpful to re-enable it in the boot loader or dts,

s/you/it

> but there appears to be no way to re-enable kaslr or some of the
> other options.
> 
> The efi command line handling is incorrect. x86 and arm have an append
> system however the efi code prepends the command line.
> 
> For example, you could have a non-upgradable bios which sends
> 
> efi=disable_early_pci_dma
> 
> This hypothetically could have been set because early pci dma caused
> issues on early versions of the product.
> 
> Then later the early pci dma was made to work and the company desired
> to start using it. To override the bios you could set the CONFIG_CMDLINE
> to,
> 
> efi=no_disable_early_pci_dma
> 
> then parsing would normally start with the bios command line, then move
> to the CONFIG_CMDLINE and you would end up with early pci dma turned on.
> 
> however, current efi code keeps early pci dma off because the bios
> arguments always override the built in.
> 
> Per my reading this is different from the main body of x86, arm, and
> arm64.
> 
> The generic command line provides both append and prepend, so it
> alleviates this issue if it's used. However not all architectures use
> it.
> 
> It would be desirable to allow the efi stub to have it's builtin command
> line to be modified after compile, but I don't see a feasible way to do
> that currently.

Would be desirable or is desirable ? Your explanations are unclear.


> 
> Cc: xe-linux-exter...@cisco.com
> Signed-off-by: Daniel Walker 
> ---
>   .../firmware/efi/libstub/efi-stub-helper.c| 29 +++
>   drivers/firmware/efi/libstub/efi-stub.c   |  9 ++
>   drivers/firmware/efi/libstub/efistub.h|  1 +
>   drivers/firmware/efi/libstub/x86-stub.c   | 14 +++--
>   4 files changed, 51 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c 
> b/drivers/firmware/efi/libstub/efi-stub-helper.c
> index bfa30625f5d0..952fa2cdff51 100644
> --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> @@ -11,6 +11,7 @@
>   
>   #include 
>   #include 
> +#include 
>   #include 
>   #include 
>   
> @@ -29,6 +30,34 @@ bool __pure __efi_soft_reserve_enabled(void)
>   return !efi_nosoftreserve;
>   }
>   
> +/**
> + * efi_handle_cmdline() - handle adding in built-in parts of the command line
> + * @cmdline: kernel command line
> + *
> + * Add in the generic parts of the commandline and start the parsing of the
> + * command line.
> + *
> + * Return:   status code
> + */
> +efi_status_t efi_handle_builtin_cmdline(char const *cmdline)
> +{
> + efi_status_t status = EFI_SUCCESS;
> +
> + if (sizeof(CMDLINE_STATIC_PREPEND) > 1)
> + status |= efi_parse_options(CMDLINE_STATIC_PREPEND);
> +
> + if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE))
> + status |= efi_parse_options(cmdline);
> +
> + if (sizeof(CMDLINE_STATIC_APPEND) > 1)
> + status |= efi_parse_options(CMDLINE_STATIC_APPEND);
> +
> + if (status != EFI_SUCCESS)
> + efi_err("Failed to parse options\n");
> +
> + return status;
> +}
> +
>   /**
>* efi_parse_options() - Parse EFI command line options
>* @cmdline:kernel command line
> diff --git a/drivers/firmware/efi/libstub/efi-stub.c 
> b/drivers/firmware/efi/libstub/efi-stub.c
> index f9c1e8a2bd1d..770abe95c0ee 100644
> --- a/drivers/firmware/efi/libstub/efi-stub.c
> +++ b/drivers/firmware/efi/libstub/efi-stub.c
> @@ -127,6 +127,14 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t 
> *image, char **cmdline_ptr)
>   return EFI_OUT_OF_RESOURCES;
>   }
>   
> +#ifdef CONFIG_GENERIC_CMDLINE
> + status = efi_handle_builtin_cmdline(cmdline);
> + if (status != EFI_SUCCESS) {
> + goto fail_free_cmdline;
> + }
> +#endif
> +
> +#ifdef CONFIG_CMDLINE
>   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
>   IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
>   cmdline_size == 0) {
> @@ -144,6 +152,7 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t 
> *image, char **cmdline_ptr)
>   goto fail_free_cmdline;
>   }
>   }
> +#endif
>   
>   *cmdline_ptr = cmdline;
>   return EFI_SUCCESS;
> diff --git a/drivers/firmware/efi/libstub/efistub.h 
> b/drivers/firmware/efi/libstub/efistub.h
> index 212687c30d79..1ac6631905c5 100644
> --- a/drivers/firmware/efi/libstub/efistub.h
> +++ b/drivers/firmware/efi/libstub/efistub.h
> @@ -996,6 +996,7 @@ efi_status_t efi_relocate_kernel(unsigned long 
> *image_addr,
>unsigned long alignment,
>

Re: [PATCH 4/8] CMDLINE: mips: convert to generic builtin command line

2023-11-22 Thread Christophe Leroy


Le 10/11/2023 à 02:38, Daniel Walker a écrit :
> This updates the mips code to use the CONFIG_GENERIC_CMDLINE
> option.
> 
> This deletes the option for MIPS_CMDLINE_BUILTIN_EXTEND
> and replaces the functionality with generic code.
> 
> Of note, the pic32 has some strange handling of the current built
> in command line. It was converted to use the static variant which
> can't be updated after compilation. It should eventually be updated
> to use to append and prepend symbols.
> 
> This includes a scripted mass convert of the config files to use
> the new generic cmdline. There is a bit of a trim effect here.
> It would seems that some of the config haven't been trimmed in
> a while.

trim effect should go in a separate preparatory patch in order to 
clearly see what are the changes implied by this patch.

> 
> The script used is as follows,
> 
> if [[ -z "$1" || -z "$2" ]]; then
>  echo "Two arguments are needed."
>  exit 1
> fi
> mkdir $1
> cp $2 $1/.config
> sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_BOOL=y\nCONFIG_CMDLINE_PREPEND=/g' 
> $1/.config
> make ARCH=$1 O=$1 olddefconfig
> make ARCH=$1 O=$1 savedefconfig
> cp $1/defconfig $2
> rm -Rf $1
> 
> Cc: xe-linux-exter...@cisco.com
> Signed-off-by: Ruslan Ruslichenko 
> Signed-off-by: Ruslan Bilovol 
> Signed-off-by: Daniel Walker 
> ---
>   arch/mips/Kconfig |   4 +-
>   arch/mips/Kconfig.debug   |  44 ---
>   arch/mips/configs/ar7_defconfig   |  12 +-
>   arch/mips/configs/bcm47xx_defconfig   |  10 +-
>   arch/mips/configs/bcm63xx_defconfig   |  21 ++--
>   arch/mips/configs/bmips_be_defconfig  |  17 ++-
>   arch/mips/configs/bmips_stb_defconfig | 139 --
>   arch/mips/configs/ci20_defconfig  |   8 +-
>   arch/mips/configs/cu1000-neo_defconfig|  19 ++-
>   arch/mips/configs/cu1830-neo_defconfig|  19 ++-
>   arch/mips/configs/generic_defconfig   |  15 +--
>   arch/mips/configs/gpr_defconfig   |  33 ++---
>   arch/mips/configs/loongson3_defconfig |  29 ++---
>   arch/mips/include/asm/setup.h |   2 +
>   arch/mips/kernel/relocate.c   |  17 ++-
>   arch/mips/kernel/setup.c  |  36 +-
>   arch/mips/pic32/pic32mzda/early_console.c |   2 +-
>   arch/mips/pic32/pic32mzda/init.c  |   3 +-
>   18 files changed, 144 insertions(+), 286 deletions(-)
> 
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index bc8421859006..65fd3decc6b1 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -31,6 +31,7 @@ config MIPS
>   select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
>   select CPU_PM if CPU_IDLE
>   select GENERIC_ATOMIC64 if !64BIT
> + select GENERIC_CMDLINE
>   select GENERIC_CMOS_UPDATE
>   select GENERIC_CPU_AUTOPROBE
>   select GENERIC_GETTIMEOFDAY
> @@ -2989,9 +2990,6 @@ choice
>   config MIPS_CMDLINE_FROM_BOOTLOADER
>   bool "Bootloader kernel arguments if available"
>   
> - config MIPS_CMDLINE_BUILTIN_EXTEND
> - depends on CMDLINE_BOOL
> - bool "Extend builtin kernel arguments with bootloader arguments"
>   endchoice
>   
>   endmenu
> diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
> index f4ae7900fcd3..f9da53d4ebd2 100644
> --- a/arch/mips/Kconfig.debug
> +++ b/arch/mips/Kconfig.debug
> @@ -26,50 +26,6 @@ config EARLY_PRINTK_8250
>   config USE_GENERIC_EARLY_PRINTK_8250
>   bool
>   
> -config CMDLINE_BOOL
> - bool "Built-in kernel command line"
> - help
> -   For most systems, it is firmware or second stage bootloader that
> -   by default specifies the kernel command line options.  However,
> -   it might be necessary or advantageous to either override the
> -   default kernel command line or add a few extra options to it.
> -   For such cases, this option allows you to hardcode your own
> -   command line options directly into the kernel.  For that, you
> -   should choose 'Y' here, and fill in the extra boot arguments
> -   in CONFIG_CMDLINE.
> -
> -   The built-in options will be concatenated to the default command
> -   line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
> -   command line will be ignored and replaced by the built-in string.
> -
> -   Most MIPS systems will normally expect 'N' here and rely upon
> -   the command line from the firmware or the second-stage bootloader.
> -
> -config CMDLINE
> - string "Default kernel command string"
> - depends on CMDLINE_BOOL
> - help
> -   On some platforms, there is currently no way for the boot loader to
> -   pass arguments to the kernel.  For these platforms, and for the cases
> -   when you want to add some extra options to the command line or ignore
> -   the default command line, you can supply some command-line options at
> -   build time by entering them here.  In other cases you can specify
> -   

Re: [PATCH 3/8] scripts: insert-sys-cert: change name to insert-symbol

2023-11-22 Thread Christophe Leroy


Le 10/11/2023 à 02:38, Daniel Walker a écrit :
> Since the tool is used to update the command line and/or
> to update the certificates, I think it makes sense to
> changes the name of this tool.
> 
> Update the name of the tool to better reflect it's new use.

Should be squashed into previous patch.

> 
> Cc: xe-linux-exter...@cisco.com
> Signed-off-by: Daniel Walker 
> ---
>   scripts/Makefile   | 2 +-
>   scripts/{insert-sys-cert.c => insert-symbol.c} | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
>   rename scripts/{insert-sys-cert.c => insert-symbol.c} (99%)
> 
> diff --git a/scripts/Makefile b/scripts/Makefile
> index 576cf64be667..2d7618fa5d6b 100644
> --- a/scripts/Makefile
> +++ b/scripts/Makefile
> @@ -8,10 +8,10 @@ hostprogs-always-$(BUILD_C_RECORDMCOUNT)+= 
> recordmcount
>   hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT) += sorttable
>   hostprogs-always-$(CONFIG_ASN1) += asn1_compiler
>   hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT)+= sign-file
> -hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE)  += insert-sys-cert
>   hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += 
> rustdoc_test_builder
>   hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += 
> rustdoc_test_gen
>   always-$(CONFIG_RUST)   += target.json
> +hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE)  += insert-symbol
>   
>   filechk_rust_target = $< < include/config/auto.conf
>   
> diff --git a/scripts/insert-sys-cert.c b/scripts/insert-symbol.c
> similarity index 99%
> rename from scripts/insert-sys-cert.c
> rename to scripts/insert-symbol.c
> index 77d3306cfbfb..6866e3a84974 100644
> --- a/scripts/insert-sys-cert.c
> +++ b/scripts/insert-symbol.c
> @@ -7,7 +7,7 @@
>* This software may be used and distributed according to the terms
>* of the GNU General Public License, incorporated herein by reference.
>*
> - * Usage: insert-sys-cert [-s  -b  -c 
> + * Usage: insert-symbol [-s  -b  -c 
>*/
>   
>   #define _GNU_SOURCE


Re: [PATCH 2/8] scripts: insert-sys-cert: add command line insert capability

2023-11-22 Thread Christophe Leroy


Le 10/11/2023 à 02:38, Daniel Walker a écrit :
> This adds changes to the insert-sys-cert tool to allow updating
> the cmdline_prepend and cmdline_append symbols in addition to
> adding certificates.

Nice feature.

> 
> Updating the cmdline symbols was tested on a PVH virtual machine
> with a vmlinux, and with a bzImage which was repackaged on x86.

Can it also work with Uimages from uboot/ppc ?

> 
> This commit intentionally keeps the tool filename the same to allow
> the changes to be seen more easily. The next commit will change
> the name of the tool.

Not sure what you mean.
If I understand correctly, git format-patch -M should do what you want.

> 
> Cc: xe-linux-exter...@cisco.com
> Signed-off-by: Daniel Walker 
> ---
>   scripts/insert-sys-cert.c | 241 +++---
>   1 file changed, 170 insertions(+), 71 deletions(-)
> 
> diff --git a/scripts/insert-sys-cert.c b/scripts/insert-sys-cert.c
> index 8902836c2342..77d3306cfbfb 100644
> --- a/scripts/insert-sys-cert.c
> +++ b/scripts/insert-sys-cert.c
> @@ -30,6 +30,9 @@
>   #define USED_SYM  "system_extra_cert_used"
>   #define LSIZE_SYM "system_certificate_list_size"
>   
> +#define CMDLINE_APPEND "cmdline_append"
> +#define CMDLINE_PREPEND "cmdline_prepend"
> +
>   #define info(format, args...) fprintf(stderr, "INFO:" format, ## args)
>   #define warn(format, args...) fprintf(stdout, "WARNING: " format, ## args)
>   #define  err(format, args...) fprintf(stderr, "ERROR:   " format, ## args)
> @@ -267,95 +270,46 @@ static void print_sym(Elf_Ehdr *hdr, struct sym *s)
>   
>   static void print_usage(char *e)
>   {
> - printf("Usage %s [-s ] -b  -c \n", e);
> + printf("Usage %s [-s ] -b  [ -c  | -p 
>  | -a  ]-\n", e);
>   }
>   
> -int main(int argc, char **argv)
> +static char *cmdline_prepend, *cmdline_append;
> +static char *system_map_file;
> +static char *cert_file;
> +static char *cli_name;
> +
> +static int insert_certificate(Elf_Ehdr *hdr)
>   {
> - char *system_map_file = NULL;
> - char *vmlinux_file = NULL;
> - char *cert_file = NULL;
> - int vmlinux_size;
> + struct sym cert_sym, lsize_sym, used_sym;
> + Elf_Shdr *symtab = NULL;
> + unsigned long *lsize;
> + FILE *system_map;
>   int cert_size;
> - Elf_Ehdr *hdr;
>   char *cert;
> - FILE *system_map;
> - unsigned long *lsize;
>   int *used;
> - int opt;
> - Elf_Shdr *symtab = NULL;
> - struct sym cert_sym, lsize_sym, used_sym;
> -
> - while ((opt = getopt(argc, argv, "b:c:s:")) != -1) {
> - switch (opt) {
> - case 's':
> - system_map_file = optarg;
> - break;
> - case 'b':
> - vmlinux_file = optarg;
> - break;
> - case 'c':
> - cert_file = optarg;
> - break;
> - default:
> - break;
> - }
> - }
>   
> - if (!vmlinux_file || !cert_file) {
> - print_usage(argv[0]);
> - exit(EXIT_FAILURE);
> + if (!cert_file) {
> + print_usage(cli_name);
> + return EXIT_FAILURE;
>   }
>   
>   cert = read_file(cert_file, _size);
>   if (!cert)
> - exit(EXIT_FAILURE);
> -
> - hdr = map_file(vmlinux_file, _size);
> - if (!hdr)
> - exit(EXIT_FAILURE);
> -
> - if (vmlinux_size < sizeof(*hdr)) {
> - err("Invalid ELF file.\n");
> - exit(EXIT_FAILURE);
> - }
> -
> - if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
> - (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
> - (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
> - (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
> - err("Invalid ELF magic.\n");
> - exit(EXIT_FAILURE);
> - }
> -
> - if (hdr->e_ident[EI_CLASS] != CURRENT_ELFCLASS) {
> - err("ELF class mismatch.\n");
> - exit(EXIT_FAILURE);
> - }
> -
> - if (hdr->e_ident[EI_DATA] != endianness()) {
> - err("ELF endian mismatch.\n");
> - exit(EXIT_FAILURE);
> - }
> -
> - if (hdr->e_shoff > vmlinux_size) {
> - err("Could not find section header.\n");
> - exit(EXIT_FAILURE);
> - }
> + return EXIT_FAILURE;
>   
>   symtab = get_symbol_table(hdr);
>   if (!symtab) {
>   warn("Could not find the symbol table.\n");
>   if (!system_map_file) {
>   err("Please provide a System.map file.\n");
> - print_usage(argv[0]);
> - exit(EXIT_FAILURE);
> + print_usage(cli_name);
> + return EXIT_FAILURE;
>   }
>   
>   system_map = fopen(system_map_file, "r");
>   if (!system_map) {
>   perror(system_map_file);
> - exit(EXIT_FAILURE);
> +   

Re: [PATCH 1/8] CMDLINE: add generic builtin command line

2023-11-22 Thread Christophe Leroy


Le 10/11/2023 à 02:38, Daniel Walker a écrit :
> This code allows architectures to use a generic builtin command line.
> The state of the builtin command line options across architecture is
> diverse. MIPS and X86 once has similar systems, then mips added some
> options to allow extending the command line. Powerpc did something
> simiar in adding the ability to extend. Even with mips and powerpc
> enhancement the needs of Cisco are not met on these platforms.

What are those needs, can you list them in the cover letter, and 
probably also in here ?
Are those needs specific to Cisco or can they interest the entire Linux 
community ?

> 
> The code in this commit unifies the code into a generic
> header file under the CONFIG_GENERIC_CMDLINE option. When this
> option is enabled the architecture can call the cmdline_add_builtin()
> to add the builtin command line. The generic code provides both
> append and/or prepend options and provides a way to redefine these
> option after the kernel is compiled.

Explain how.

> 
> This code also includes test's which are meant to confirm
> functionality.

Would be better to have test part as a separate patch if possible.

> 
> This unified implementation offers the same functionality needed by
> Cisco on all platform which we enable it on.

Cisco ... cisco ... cisco ...

> 
> Cc: xe-linux-exter...@cisco.com
> Signed-off-by: Ruslan Bilovol 
> Signed-off-by: Daniel Walker 
> ---
>   include/linux/cmdline.h | 106 ++
>   init/Kconfig|  79 +++
>   lib/Kconfig |   4 ++
>   lib/Makefile|   3 +
>   lib/generic_cmdline.S   |  53 +++
>   lib/test_cmdline1.c | 139 
>   6 files changed, 384 insertions(+)
>   create mode 100644 include/linux/cmdline.h
>   create mode 100644 lib/generic_cmdline.S
>   create mode 100644 lib/test_cmdline1.c
> 
> diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
> new file mode 100644
> index ..a94758a0f257
> --- /dev/null
> +++ b/include/linux/cmdline.h
> @@ -0,0 +1,106 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _LINUX_CMDLINE_H
> +#define _LINUX_CMDLINE_H
> +/*
> + *
> + * Copyright (C) 2006,2021. Cisco Systems, Inc.
> + *
> + * Generic Append/Prepend cmdline support.
> + */
> +
> +
> +#include 
> +#include 
> +#include 
> +
> +#ifdef CONFIG_CMDLINE_BOOL
> +extern char cmdline_prepend[];
> +extern char cmdline_append[];
> +extern char cmdline_tmp[];
> +#define CMDLINE_PREPEND cmdline_prepend
> +#define CMDLINE_APPEND cmdline_append
> +#define CMDLINE_TMP cmdline_tmp
> +#define CMDLINE_STATIC_PREPEND CONFIG_CMDLINE_PREPEND
> +#define CMDLINE_STATIC_APPEND CONFIG_CMDLINE_APPEND

Too many macros reduces the readability of code, avoid them when possible.

> +#else

Explain why this else leg is needed. It should be possible to set 
default values directly in Kconfig.

> +#define CMDLINE_PREPEND ""
> +#define CMDLINE_APPEND ""
> +#define CMDLINE_TMP ""
> +#define CMDLINE_STATIC_PREPEND ""
> +#define CMDLINE_STATIC_APPEND ""
> +#endif
> +
> +#ifndef CMDLINE_STRLCAT
> +#define CMDLINE_STRLCAT strlcat
> +#endif
> +
> +#ifndef CMDLINE_STRLEN
> +#define CMDLINE_STRLEN strlen
> +#endif
> +
> +/*
> + * This function will append or prepend a builtin command line to the command
> + * line provided by the bootloader. Kconfig options can be used to alter
> + * the behavior of this builtin command line.
> + * @dest: The destination of the final appended/prepended string
> + * @tmp: temporary space used for prepending
> + * @prepend: string to prepend to @dest
> + * @append: string to append to @dest
> + * @length: the maximum length of the strings above.
> + * @cmdline_strlen: point to a compatible strlen

Remove that function pointer argument and use macros.

> + * @cmdline_strlcat: point to a compatible strlcat

Same

> + * This function returns true when the builtin command line was copied 
> successfully
> + * and false when there was not enough room to copy all parts of the command 
> line.

What happens when it returns false, is it partially copied or nothing is 
done ?

> + */
> +static inline bool
> +__cmdline_add_builtin(
> + char *dest,
> + char *tmp,
> + char *prepend,
> + char *append,
> + unsigned long length,
> + size_t (*cmdline_strlen)(const char *s),
> + size_t (*cmdline_strlcat)(char *dest, const char *src, size_t 
> count))

This cmdline feature is used in early deep parts of architectures, so in 
a way more or less comparable to linux-mm. Approach with linux-mm has 
always been to define macros that can be overriden by architectures. 
Please do the same and define cmdline_strlen() and cmdline_strlcat() as 
macros that can be overriden by architectures instead of passing 
function pointers. And keep macro names as lower case for this type of 
macros.

> +{
> + size_t total_length = 0, 

Re: [PATCH 0/8] generic command line v6

2023-11-22 Thread Christophe Leroy


Le 10/11/2023 à 02:38, Daniel Walker a écrit :
> This release is an up-rev of the v5 patches. No additional features have
> been added. Some changes were mode to function names and some changes to
> Kconfig dependencies. Also updated the config conversion for mips.
> 
> There are a number of people who have expressed interest in these
> patches either by asking for them to be merge or testing them. If
> people are so inclined please continue to request them to be merge
> or to ask the status of the next release. It's helpful to motivate me to
> release them again and for the maintainers to see the interest
> generated.

Good, then lets work all together and get the best of it.

Your series has good features like the update of the command line addons 
without rebuild, including updating of the signature when applicable. 
However your series still has weaknesses it had in previous versions. I 
was hopping we could work all together to improve it, but you have been 
repeatedly telling that my proposal doesn't fit your needs without 
explaining why. Can we work in a more win-win spirit this time ?

By the way, for the record, here is a link to a series I sent out as an 
exemple of what it could look like. The intention at that time was not 
to have a concurrent series, but just to show what I meant in my 
comments, because exemples are often more explicit than words. That 
series was considered more mature and closer to a mergeable state than 
yours at that time. Link to the said series: 
https://patchwork.ozlabs.org/project/linuxppc-dev/list/?state=*=237158

Your series only converts a few architectures, and I can't see any 
demonstration that it will be possible to convert other architectures as 
a follow-up without too much pain.

> 
> These patches have been used by Cisco Systems, Inc. on millions of
> released products to great effect. Hopefully they can be used by the
> entire Linux eco system.

This is not an argument. Billions of computers are running Micr*s*ft 
Windows, does it make Windows better ? Do IBM or Google claim about the 
million equipment they are sending out with special Linux features ? 
Showing objectively what's the benefit of your features without 
referring to Cisco would be better.

> 
> My apologies on the length between releases. I will try to release more
> often.

Christophe

> 
> 
> Daniel Walker (8):
>CMDLINE: add generic builtin command line
>scripts: insert-sys-cert: add command line insert capability
>scripts: insert-sys-cert: change name to insert-symbol
>CMDLINE: mips: convert to generic builtin command line
>drivers: firmware: efi: libstub: enable generic commandline
>CMDLINE: x86: convert to generic builtin command line
>of: replace command line handling
>CMDLINE: arm64: convert to generic builtin command line
> 
>   arch/arm64/Kconfig|  33 +--
>   arch/arm64/include/asm/setup.h|   4 +
>   arch/arm64/include/uapi/asm/setup.h   |   2 +
>   arch/arm64/kernel/idreg-override.c|   9 +-
>   arch/arm64/kernel/pi/kaslr_early.c|  14 +-
>   arch/mips/Kconfig |   4 +-
>   arch/mips/Kconfig.debug   |  44 
>   arch/mips/configs/ar7_defconfig   |  12 +-
>   arch/mips/configs/bcm47xx_defconfig   |  10 +-
>   arch/mips/configs/bcm63xx_defconfig   |  21 +-
>   arch/mips/configs/bmips_be_defconfig  |  17 +-
>   arch/mips/configs/bmips_stb_defconfig | 139 --
>   arch/mips/configs/ci20_defconfig  |   8 +-
>   arch/mips/configs/cu1000-neo_defconfig|  19 +-
>   arch/mips/configs/cu1830-neo_defconfig|  19 +-
>   arch/mips/configs/generic_defconfig   |  15 +-
>   arch/mips/configs/gpr_defconfig   |  33 +--
>   arch/mips/configs/loongson3_defconfig |  29 +--
>   arch/mips/include/asm/setup.h |   2 +
>   arch/mips/kernel/relocate.c   |  17 +-
>   arch/mips/kernel/setup.c  |  36 +--
>   arch/mips/pic32/pic32mzda/early_console.c |   2 +-
>   arch/mips/pic32/pic32mzda/init.c  |   3 +-
>   arch/x86/Kconfig  |  44 +---
>   arch/x86/kernel/setup.c   |  18 +-
>   .../firmware/efi/libstub/efi-stub-helper.c|  29 +++
>   drivers/firmware/efi/libstub/efi-stub.c   |   9 +
>   drivers/firmware/efi/libstub/efistub.h|   1 +
>   drivers/firmware/efi/libstub/x86-stub.c   |  14 +-
>   drivers/of/fdt.c  |  22 +-
>   include/linux/cmdline.h   | 137 ++
>   init/Kconfig  |  79 ++
>   lib/Kconfig   |   4 +
>   lib/Makefile  |   3 +
>   lib/generic_cmdline.S |  53 
>   lib/test_cmdline1.c   | 139 ++
>   

[PATCH] powerpc/86xx: Drop unused CONFIG_MPC8610

2023-11-22 Thread Michael Ellerman
The MPC8610 symbol used to be default y if MPC8610_HPCD, but since
MPC8610_HPCD was removed MPC8610 is now never used. Remove it.

Fixes: 248667f8bbde ("powerpc: drop HPCD/MPC8610 evaluation platform support")
Signed-off-by: Michael Ellerman 
---
 arch/powerpc/platforms/86xx/Kconfig | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/arch/powerpc/platforms/86xx/Kconfig 
b/arch/powerpc/platforms/86xx/Kconfig
index 67467cd6f34c..06b1e5c49d6f 100644
--- a/arch/powerpc/platforms/86xx/Kconfig
+++ b/arch/powerpc/platforms/86xx/Kconfig
@@ -52,10 +52,3 @@ config MPC8641
select MPIC
default y if GEF_SBC610 || GEF_SBC310 || GEF_PPC9A \
|| MVME7100
-
-config MPC8610
-   bool
-   select HAVE_PCI
-   select FSL_PCI if PCI
-   select PPC_UDBG_16550
-   select MPIC
-- 
2.41.0



[PATCH] ASoC: fsl_xcvr: refine the requested phy clock frequency

2023-11-22 Thread Shengjiu Wang
As the input phy clock frequency will divided by 2 by default
on i.MX8MP with the implementation of clk-imx8mp-audiomix driver,
So the requested frequency need to be updated.

The relation of phy clock is:
sai_pll_ref_sel
   sai_pll
  sai_pll_bypass
 sai_pll_out
sai_pll_out_div2
   earc_phy_cg

Signed-off-by: Shengjiu Wang 
---
 sound/soc/fsl/fsl_xcvr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/fsl/fsl_xcvr.c b/sound/soc/fsl/fsl_xcvr.c
index 77f8e2394bf9..f0fb33d719c2 100644
--- a/sound/soc/fsl/fsl_xcvr.c
+++ b/sound/soc/fsl/fsl_xcvr.c
@@ -358,7 +358,7 @@ static int fsl_xcvr_en_aud_pll(struct fsl_xcvr *xcvr, u32 
freq)
struct device *dev = >pdev->dev;
int ret;
 
-   freq = xcvr->soc_data->spdif_only ? freq / 10 : freq;
+   freq = xcvr->soc_data->spdif_only ? freq / 5 : freq;
clk_disable_unprepare(xcvr->phy_clk);
ret = clk_set_rate(xcvr->phy_clk, freq);
if (ret < 0) {
@@ -409,7 +409,7 @@ static int fsl_xcvr_prepare(struct snd_pcm_substream 
*substream,
bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
u32 m_ctl = 0, v_ctl = 0;
u32 r = substream->runtime->rate, ch = substream->runtime->channels;
-   u32 fout = 32 * r * ch * 10 * 2;
+   u32 fout = 32 * r * ch * 10;
int ret = 0;
 
switch (xcvr->mode) {
-- 
2.34.1



Re: [PATCH v2 1/4] i915: make inject_virtual_interrupt() void

2023-11-22 Thread Zhenyu Wang
On 2023.11.22 13:48:22 +0100, Christian Brauner wrote:
> The single caller of inject_virtual_interrupt() ignores the return value
> anyway. This allows us to simplify eventfd_signal() in follow-up
> patches.
> 
> Signed-off-by: Christian Brauner 
> ---
>  drivers/gpu/drm/i915/gvt/interrupt.c | 14 +++---
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c 
> b/drivers/gpu/drm/i915/gvt/interrupt.c
> index de3f5903d1a7..9665876b4b13 100644
> --- a/drivers/gpu/drm/i915/gvt/interrupt.c
> +++ b/drivers/gpu/drm/i915/gvt/interrupt.c
> @@ -422,7 +422,7 @@ static void init_irq_map(struct intel_gvt_irq *irq)
>  #define MSI_CAP_DATA(offset) (offset + 8)
>  #define MSI_CAP_EN 0x1
>  
> -static int inject_virtual_interrupt(struct intel_vgpu *vgpu)
> +static void inject_virtual_interrupt(struct intel_vgpu *vgpu)
>  {
>   unsigned long offset = vgpu->gvt->device_info.msi_cap_offset;
>   u16 control, data;
> @@ -434,10 +434,10 @@ static int inject_virtual_interrupt(struct intel_vgpu 
> *vgpu)
>  
>   /* Do not generate MSI if MSIEN is disabled */
>   if (!(control & MSI_CAP_EN))
> - return 0;
> + return;
>  
>   if (WARN(control & GENMASK(15, 1), "only support one MSI format\n"))
> - return -EINVAL;
> + return;
>  
>   trace_inject_msi(vgpu->id, addr, data);
>  
> @@ -451,10 +451,10 @@ static int inject_virtual_interrupt(struct intel_vgpu 
> *vgpu)
>* returned and don't inject interrupt into guest.
>*/
>   if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
> - return -ESRCH;
> - if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1)
> - return -EFAULT;
> - return 0;
> + return;
> + if (!vgpu->msi_trigger)
> + return;
> + eventfd_signal(vgpu->msi_trigger, 1);
>  }

I think it's a little simpler to write as
if (vgpu->msi_trigger)
eventfd_signal(vgpu->msi_trigger, 1);

Looks fine with me.

Reviewed-by: Zhenyu Wang 

Thanks!

>  
>  static void propagate_event(struct intel_gvt_irq *irq,
> 
> -- 
> 2.42.0
> 


signature.asc
Description: PGP signature


Re: [PATCH] powerpc: Use ARRAY_SIZE for array length

2023-11-22 Thread Michael Ellerman
Jiapeng Chong  writes:
> Use of macro ARRAY_SIZE to calculate array size minimizes
> the redundant code and improves code reusability.
>
> ./arch/powerpc/xmon/ppc-opc.c:957:67-68: WARNING: Use ARRAY_SIZE.
>
> Reported-by: Abaci Robot 
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=7612
> Signed-off-by: Jiapeng Chong 
> ---
>  arch/powerpc/xmon/ppc-opc.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

This code is copied from binutils, we don't take cleanup patches to it.

See also the at least three times this has already been submitted :)

https://lore.kernel.org/all/4ed43222-17b0-8355-f836-adabb453e...@csgroup.eu/
https://lore.kernel.org/linuxppc-dev/20181004171036.ga1...@embeddedor.com/
https://lore.kernel.org/linuxppc-dev/874lfxjnzl@concordia.ellerman.id.au/

cheers


Re: [PATCH 2/2] ASoC: cs4270: Remove unused codec

2023-11-22 Thread Michael Ellerman
Mark Brown  writes:
> On Wed, Nov 22, 2023 at 05:27:12PM +1100, Michael Ellerman wrote:
>> The only driver to enable SND_SOC_CS4270 was SND_SOC_MPC8610_HPCD, which
>> was dropped in the preceding commit. Remove the codec as unused.
>
> There's no real overhead from having extra drivers and we do have
> generic drivers that people can attach CODECs to.

OK. I have no idea how sound works, I was just cleaning things up. So
whatever you think is best.

cheers


Re: [PATCH v2 4/5] rust: Allow MODVERSIONS

2023-11-22 Thread Khan Baloshi



[PATCH] dt-bindings: fsl,dpaa2-console: drop unneeded quotes

2023-11-22 Thread Rob Herring
Drop unneeded quotes over simple string values to fix a soon to be
enabled yamllint warning:

  [error] string value is redundantly quoted with any quotes (quoted-strings)

Signed-off-by: Rob Herring 
---
 Documentation/devicetree/bindings/misc/fsl,dpaa2-console.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/misc/fsl,dpaa2-console.yaml 
b/Documentation/devicetree/bindings/misc/fsl,dpaa2-console.yaml
index 8cc951feb7df..59b83ea5e05e 100644
--- a/Documentation/devicetree/bindings/misc/fsl,dpaa2-console.yaml
+++ b/Documentation/devicetree/bindings/misc/fsl,dpaa2-console.yaml
@@ -12,7 +12,7 @@ maintainers:
 
 properties:
   compatible:
-const: "fsl,dpaa2-console"
+const: fsl,dpaa2-console
 
   reg:
 maxItems: 1
-- 
2.42.0



Re: [PATCH v2 0/5] MODVERSIONS + RUST Redux

2023-11-22 Thread Matthew Maurer
> So, even if you enable CONFIG_MODVERSIONS,
> nothing is checked for Rust.
> Genksyms computes a CRC from "int foo", and
> the module subsystem confirms it is a "int"
> variable.
>
> We know this check always succeeds.
>
> Why is this useful?
The reason this is immediately useful is that it allows us to have Rust
in use with a kernel where C modules are able to benefit from MODVERSIONS
checking. The check would effectively be a no-op for now, as you have correctly
determined, but we could refine it to make it more restrictive later.
Since the
existing C approach errs on the side of "it could work" rather than "it will
work", I thought being more permissive was the correct initial solution.

If we want to err on the other side (modversions passes, so we're pretty sure
it will work), I could add to the last patch support for using .rmeta files as
the CRC source for Rust symbols. This would essentially say that the interface
for the entire compilation unit has to stay the same rather than just that one
function. We could potentially loosen this requirement in the future.

With regards to future directions that likely won't work for loosening it:
Unfortunately, the .rmeta format itself is not stable, so I wouldn't want to
teach genksyms to open it up and split out the pieces for specific functions.
Extending genksyms to parse Rust would also not solve the situation -
layouts are allowed to differ across compiler versions or even (in rare
cases) seemingly unrelated code changes.

Future directions that might work for loosening it:
* Generating crcs from debuginfo + compiler + flags
* Adding a feature to the rust compiler to dump this information. This
is likely to
  get pushback because Rust's current stance is that there is no ability to load
  object code built against a different library.

Would setting up Rust symbols so that they have a crc built out of .rmeta be
sufficient for you to consider this useful? If not, can you help me understand
what level of precision would be required?


Re: [PATCH] ASoC: fsl_xcvr: Enable 2 * TX bit clock for spdif only case

2023-11-22 Thread Mark Brown
On Wed, 22 Nov 2023 09:42:53 +0800, Shengjiu Wang wrote:
> The bit 10 in TX_DPTH_CTRL register controls the TX clock rate.
> If this bit is set, TX datapath clock should be = 2* TX bit rate.
> If this bit is not set, TX datapath clock should be 10* TX bit rate.
> 
> As the spdif only case, we always use 2 * TX bit clock, so
> this bit need to be set.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: fsl_xcvr: Enable 2 * TX bit clock for spdif only case
  commit: c33fd110424dfcb544cf55a1b312f43fe1918235

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark



Re: [PATCH v2 2/4] eventfd: simplify eventfd_signal()

2023-11-22 Thread Jani Nikula
On Wed, 22 Nov 2023, Christian Brauner  wrote:
> diff --git a/fs/eventfd.c b/fs/eventfd.c
> index 33a918f9566c..dc9e01053235 100644
> --- a/fs/eventfd.c
> +++ b/fs/eventfd.c
> @@ -74,20 +74,17 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 
> n, __poll_t mask)
>  /**
>   * eventfd_signal - Adds @n to the eventfd counter.

This still refers to @n here, and in patch 4.

BR,
Jani.

>   * @ctx: [in] Pointer to the eventfd context.
> - * @n: [in] Value of the counter to be added to the eventfd internal counter.
> - *  The value cannot be negative.
>   *
>   * This function is supposed to be called by the kernel in paths that do not
>   * allow sleeping. In this function we allow the counter to reach the 
> ULLONG_MAX
>   * value, and we signal this as overflow condition by returning a EPOLLERR
>   * to poll(2).
>   *
> - * Returns the amount by which the counter was incremented.  This will be 
> less
> - * than @n if the counter has overflowed.
> + * Returns the amount by which the counter was incremented.
>   */
> -__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n)
> +__u64 eventfd_signal(struct eventfd_ctx *ctx)
>  {
> - return eventfd_signal_mask(ctx, n, 0);
> + return eventfd_signal_mask(ctx, 1, 0);
>  }
>  EXPORT_SYMBOL_GPL(eventfd_signal);
>  

-- 
Jani Nikula, Intel


Re: [PATCH v2 4/4] eventfd: make eventfd_signal{_mask}() void

2023-11-22 Thread Jan Kara
On Wed 22-11-23 13:48:25, Christian Brauner wrote:
> No caller care about the return value.
> 
> Signed-off-by: Christian Brauner 

Yup. Feel free to add:

Reviewed-by: Jan Kara 

Honza

> ---
>  fs/eventfd.c| 40 +++-
>  include/linux/eventfd.h | 16 +++-
>  2 files changed, 22 insertions(+), 34 deletions(-)
> 
> diff --git a/fs/eventfd.c b/fs/eventfd.c
> index a9a6de920fb4..13be2fb7fc96 100644
> --- a/fs/eventfd.c
> +++ b/fs/eventfd.c
> @@ -43,10 +43,19 @@ struct eventfd_ctx {
>   int id;
>  };
>  
> -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask)
> +/**
> + * eventfd_signal - Adds @n to the eventfd counter.
> + * @ctx: [in] Pointer to the eventfd context.
> + * @mask: [in] poll mask
> + *
> + * This function is supposed to be called by the kernel in paths that do not
> + * allow sleeping. In this function we allow the counter to reach the 
> ULLONG_MAX
> + * value, and we signal this as overflow condition by returning a EPOLLERR
> + * to poll(2).
> + */
> +void eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask)
>  {
>   unsigned long flags;
> - __u64 n = 1;
>  
>   /*
>* Deadlock or stack overflow issues can happen if we recurse here
> @@ -57,37 +66,18 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, 
> __poll_t mask)
>* safe context.
>*/
>   if (WARN_ON_ONCE(current->in_eventfd))
> - return 0;
> + return;
>  
>   spin_lock_irqsave(>wqh.lock, flags);
>   current->in_eventfd = 1;
> - if (ULLONG_MAX - ctx->count < n)
> - n = ULLONG_MAX - ctx->count;
> - ctx->count += n;
> + if (ctx->count < ULLONG_MAX)
> + ctx->count++;
>   if (waitqueue_active(>wqh))
>   wake_up_locked_poll(>wqh, EPOLLIN | mask);
>   current->in_eventfd = 0;
>   spin_unlock_irqrestore(>wqh.lock, flags);
> -
> - return n == 1;
> -}
> -
> -/**
> - * eventfd_signal - Adds @n to the eventfd counter.
> - * @ctx: [in] Pointer to the eventfd context.
> - *
> - * This function is supposed to be called by the kernel in paths that do not
> - * allow sleeping. In this function we allow the counter to reach the 
> ULLONG_MAX
> - * value, and we signal this as overflow condition by returning a EPOLLERR
> - * to poll(2).
> - *
> - * Returns the amount by which the counter was incremented.
> - */
> -__u64 eventfd_signal(struct eventfd_ctx *ctx)
> -{
> - return eventfd_signal_mask(ctx, 0);
>  }
> -EXPORT_SYMBOL_GPL(eventfd_signal);
> +EXPORT_SYMBOL_GPL(eventfd_signal_mask);
>  
>  static void eventfd_free_ctx(struct eventfd_ctx *ctx)
>  {
> diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
> index 4f8aac7eb62a..fea7c4eb01d6 100644
> --- a/include/linux/eventfd.h
> +++ b/include/linux/eventfd.h
> @@ -35,8 +35,7 @@ void eventfd_ctx_put(struct eventfd_ctx *ctx);
>  struct file *eventfd_fget(int fd);
>  struct eventfd_ctx *eventfd_ctx_fdget(int fd);
>  struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
> -__u64 eventfd_signal(struct eventfd_ctx *ctx);
> -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask);
> +void eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask);
>  int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, 
> wait_queue_entry_t *wait,
> __u64 *cnt);
>  void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt);
> @@ -58,14 +57,8 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
>   return ERR_PTR(-ENOSYS);
>  }
>  
> -static inline int eventfd_signal(struct eventfd_ctx *ctx)
> +static inline void eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned 
> mask)
>  {
> - return -ENOSYS;
> -}
> -
> -static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask)
> -{
> - return -ENOSYS;
>  }
>  
>  static inline void eventfd_ctx_put(struct eventfd_ctx *ctx)
> @@ -91,5 +84,10 @@ static inline void eventfd_ctx_do_read(struct eventfd_ctx 
> *ctx, __u64 *cnt)
>  
>  #endif
>  
> +static inline void eventfd_signal(struct eventfd_ctx *ctx)
> +{
> + eventfd_signal_mask(ctx, 0);
> +}
> +
>  #endif /* _LINUX_EVENTFD_H */
>  
> 
> -- 
> 2.42.0
> 
-- 
Jan Kara 
SUSE Labs, CR


Re: [PATCH v2 3/4] eventfd: simplify eventfd_signal_mask()

2023-11-22 Thread Jan Kara
On Wed 22-11-23 13:48:24, Christian Brauner wrote:
> The eventfd_signal_mask() helper was introduced for io_uring and similar
> to eventfd_signal() it always passed 1 for @n. So don't bother with that
> argument at all.
> 
> Signed-off-by: Christian Brauner 

Nice. Feel free to add:

Reviewed-by: Jan Kara 

Honza

> ---
>  fs/eventfd.c| 7 ---
>  include/linux/eventfd.h | 5 ++---
>  io_uring/io_uring.c | 4 ++--
>  3 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/eventfd.c b/fs/eventfd.c
> index dc9e01053235..a9a6de920fb4 100644
> --- a/fs/eventfd.c
> +++ b/fs/eventfd.c
> @@ -43,9 +43,10 @@ struct eventfd_ctx {
>   int id;
>  };
>  
> -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask)
> +__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask)
>  {
>   unsigned long flags;
> + __u64 n = 1;
>  
>   /*
>* Deadlock or stack overflow issues can happen if we recurse here
> @@ -68,7 +69,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, 
> __poll_t mask)
>   current->in_eventfd = 0;
>   spin_unlock_irqrestore(>wqh.lock, flags);
>  
> - return n;
> + return n == 1;
>  }
>  
>  /**
> @@ -84,7 +85,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, 
> __poll_t mask)
>   */
>  __u64 eventfd_signal(struct eventfd_ctx *ctx)
>  {
> - return eventfd_signal_mask(ctx, 1, 0);
> + return eventfd_signal_mask(ctx, 0);
>  }
>  EXPORT_SYMBOL_GPL(eventfd_signal);
>  
> diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
> index 562089431551..4f8aac7eb62a 100644
> --- a/include/linux/eventfd.h
> +++ b/include/linux/eventfd.h
> @@ -36,7 +36,7 @@ struct file *eventfd_fget(int fd);
>  struct eventfd_ctx *eventfd_ctx_fdget(int fd);
>  struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
>  __u64 eventfd_signal(struct eventfd_ctx *ctx);
> -__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask);
> +__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask);
>  int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, 
> wait_queue_entry_t *wait,
> __u64 *cnt);
>  void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt);
> @@ -63,8 +63,7 @@ static inline int eventfd_signal(struct eventfd_ctx *ctx)
>   return -ENOSYS;
>  }
>  
> -static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n,
> -   unsigned mask)
> +static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask)
>  {
>   return -ENOSYS;
>  }
> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
> index ed254076c723..70170a41eac4 100644
> --- a/io_uring/io_uring.c
> +++ b/io_uring/io_uring.c
> @@ -558,7 +558,7 @@ static void io_eventfd_ops(struct rcu_head *rcu)
>   int ops = atomic_xchg(_fd->ops, 0);
>  
>   if (ops & BIT(IO_EVENTFD_OP_SIGNAL_BIT))
> - eventfd_signal_mask(ev_fd->cq_ev_fd, 1, EPOLL_URING_WAKE);
> + eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
>  
>   /* IO_EVENTFD_OP_FREE_BIT may not be set here depending on callback
>* ordering in a race but if references are 0 we know we have to free
> @@ -594,7 +594,7 @@ static void io_eventfd_signal(struct io_ring_ctx *ctx)
>   goto out;
>  
>   if (likely(eventfd_signal_allowed())) {
> - eventfd_signal_mask(ev_fd->cq_ev_fd, 1, EPOLL_URING_WAKE);
> + eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
>   } else {
>   atomic_inc(_fd->refs);
>   if (!atomic_fetch_or(BIT(IO_EVENTFD_OP_SIGNAL_BIT), 
> _fd->ops))
> 
> -- 
> 2.42.0
> 
-- 
Jan Kara 
SUSE Labs, CR


Re: [PATCH v2 2/4] eventfd: simplify eventfd_signal()

2023-11-22 Thread Jan Kara
On Wed 22-11-23 13:48:23, Christian Brauner wrote:
> Ever since the evenfd type was introduced back in 2007 in commit
> e1ad7468c77d ("signal/timer/event: eventfd core") the eventfd_signal()
> function only ever passed 1 as a value for @n. There's no point in
> keeping that additional argument.
> 
> Signed-off-by: Christian Brauner 

Looks good. Feel free to add:

Reviewed-by: Jan Kara 
Honza

> ---
>  arch/x86/kvm/hyperv.c |  2 +-
>  arch/x86/kvm/xen.c|  2 +-
>  drivers/accel/habanalabs/common/device.c  |  2 +-
>  drivers/fpga/dfl.c|  2 +-
>  drivers/gpu/drm/drm_syncobj.c |  6 +++---
>  drivers/gpu/drm/i915/gvt/interrupt.c  |  2 +-
>  drivers/infiniband/hw/mlx5/devx.c |  2 +-
>  drivers/misc/ocxl/file.c  |  2 +-
>  drivers/s390/cio/vfio_ccw_chp.c   |  2 +-
>  drivers/s390/cio/vfio_ccw_drv.c   |  4 ++--
>  drivers/s390/cio/vfio_ccw_ops.c   |  6 +++---
>  drivers/s390/crypto/vfio_ap_ops.c |  2 +-
>  drivers/usb/gadget/function/f_fs.c|  4 ++--
>  drivers/vdpa/vdpa_user/vduse_dev.c|  6 +++---
>  drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c|  2 +-
>  drivers/vfio/pci/vfio_pci_core.c  |  6 +++---
>  drivers/vfio/pci/vfio_pci_intrs.c | 12 ++--
>  drivers/vfio/platform/vfio_platform_irq.c |  4 ++--
>  drivers/vhost/vdpa.c  |  4 ++--
>  drivers/vhost/vhost.c | 10 +-
>  drivers/vhost/vhost.h |  2 +-
>  drivers/virt/acrn/ioeventfd.c |  2 +-
>  drivers/xen/privcmd.c |  2 +-
>  fs/aio.c  |  2 +-
>  fs/eventfd.c  |  9 +++--
>  include/linux/eventfd.h   |  4 ++--
>  mm/memcontrol.c   | 10 +-
>  mm/vmpressure.c   |  2 +-
>  samples/vfio-mdev/mtty.c  |  4 ++--
>  virt/kvm/eventfd.c|  4 ++--
>  30 files changed, 60 insertions(+), 63 deletions(-)
> 
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index 238afd7335e4..4943f6b2bbee 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -2388,7 +2388,7 @@ static u16 kvm_hvcall_signal_event(struct kvm_vcpu 
> *vcpu, struct kvm_hv_hcall *h
>   if (!eventfd)
>   return HV_STATUS_INVALID_PORT_ID;
>  
> - eventfd_signal(eventfd, 1);
> + eventfd_signal(eventfd);
>   return HV_STATUS_SUCCESS;
>  }
>  
> diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
> index e53fad915a62..523bb6df5ac9 100644
> --- a/arch/x86/kvm/xen.c
> +++ b/arch/x86/kvm/xen.c
> @@ -2088,7 +2088,7 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu 
> *vcpu, u64 param, u64 *r)
>   if (ret < 0 && ret != -ENOTCONN)
>   return false;
>   } else {
> - eventfd_signal(evtchnfd->deliver.eventfd.ctx, 1);
> + eventfd_signal(evtchnfd->deliver.eventfd.ctx);
>   }
>  
>   *r = 0;
> diff --git a/drivers/accel/habanalabs/common/device.c 
> b/drivers/accel/habanalabs/common/device.c
> index 9711e8fc979d..3a89644f087c 100644
> --- a/drivers/accel/habanalabs/common/device.c
> +++ b/drivers/accel/habanalabs/common/device.c
> @@ -2044,7 +2044,7 @@ static void hl_notifier_event_send(struct 
> hl_notifier_event *notifier_event, u64
>   notifier_event->events_mask |= event_mask;
>  
>   if (notifier_event->eventfd)
> - eventfd_signal(notifier_event->eventfd, 1);
> + eventfd_signal(notifier_event->eventfd);
>  
>   mutex_unlock(_event->lock);
>  }
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index dd7a783d53b5..e73f88050f08 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -1872,7 +1872,7 @@ static irqreturn_t dfl_irq_handler(int irq, void *arg)
>  {
>   struct eventfd_ctx *trigger = arg;
>  
> - eventfd_signal(trigger, 1);
> + eventfd_signal(trigger);
>   return IRQ_HANDLED;
>  }
>  
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index 01da6789d044..b9cc62982196 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -1365,7 +1365,7 @@ static void syncobj_eventfd_entry_fence_func(struct 
> dma_fence *fence,
>   struct syncobj_eventfd_entry *entry =
>   container_of(cb, struct syncobj_eventfd_entry, fence_cb);
>  
> - eventfd_signal(entry->ev_fd_ctx, 1);
> + eventfd_signal(entry->ev_fd_ctx);
>   syncobj_eventfd_entry_free(entry);
>  }
>  
> @@ -1388,13 +1388,13 @@ syncobj_eventfd_entry_func(struct drm_syncobj 
> *syncobj,
>   entry->fence = fence;
>  
>   if (entry->flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE) {
> - eventfd_signal(entry->ev_fd_ctx, 1);
> + eventfd_signal(entry->ev_fd_ctx);
>   

Re: [PATCH v2 1/4] i915: make inject_virtual_interrupt() void

2023-11-22 Thread Jan Kara
On Wed 22-11-23 13:48:22, Christian Brauner wrote:
> The single caller of inject_virtual_interrupt() ignores the return value
> anyway. This allows us to simplify eventfd_signal() in follow-up
> patches.
> 
> Signed-off-by: Christian Brauner 

Looks good. Feel free to add:

Reviewed-by: Jan Kara 

Honza

> ---
>  drivers/gpu/drm/i915/gvt/interrupt.c | 14 +++---
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c 
> b/drivers/gpu/drm/i915/gvt/interrupt.c
> index de3f5903d1a7..9665876b4b13 100644
> --- a/drivers/gpu/drm/i915/gvt/interrupt.c
> +++ b/drivers/gpu/drm/i915/gvt/interrupt.c
> @@ -422,7 +422,7 @@ static void init_irq_map(struct intel_gvt_irq *irq)
>  #define MSI_CAP_DATA(offset) (offset + 8)
>  #define MSI_CAP_EN 0x1
>  
> -static int inject_virtual_interrupt(struct intel_vgpu *vgpu)
> +static void inject_virtual_interrupt(struct intel_vgpu *vgpu)
>  {
>   unsigned long offset = vgpu->gvt->device_info.msi_cap_offset;
>   u16 control, data;
> @@ -434,10 +434,10 @@ static int inject_virtual_interrupt(struct intel_vgpu 
> *vgpu)
>  
>   /* Do not generate MSI if MSIEN is disabled */
>   if (!(control & MSI_CAP_EN))
> - return 0;
> + return;
>  
>   if (WARN(control & GENMASK(15, 1), "only support one MSI format\n"))
> - return -EINVAL;
> + return;
>  
>   trace_inject_msi(vgpu->id, addr, data);
>  
> @@ -451,10 +451,10 @@ static int inject_virtual_interrupt(struct intel_vgpu 
> *vgpu)
>* returned and don't inject interrupt into guest.
>*/
>   if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
> - return -ESRCH;
> - if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1)
> - return -EFAULT;
> - return 0;
> + return;
> + if (!vgpu->msi_trigger)
> + return;
> + eventfd_signal(vgpu->msi_trigger, 1);
>  }
>  
>  static void propagate_event(struct intel_gvt_irq *irq,
> 
> -- 
> 2.42.0
> 
-- 
Jan Kara 
SUSE Labs, CR


Re: [PATCH v2 2/4] eventfd: simplify eventfd_signal()

2023-11-22 Thread Xu Yilun
On Wed, Nov 22, 2023 at 01:48:23PM +0100, Christian Brauner wrote:
> Ever since the evenfd type was introduced back in 2007 in commit
> e1ad7468c77d ("signal/timer/event: eventfd core") the eventfd_signal()
> function only ever passed 1 as a value for @n. There's no point in
> keeping that additional argument.
> 
> Signed-off-by: Christian Brauner 
> ---
>  arch/x86/kvm/hyperv.c |  2 +-
>  arch/x86/kvm/xen.c|  2 +-
>  drivers/accel/habanalabs/common/device.c  |  2 +-
>  drivers/fpga/dfl.c|  2 +-
>  drivers/gpu/drm/drm_syncobj.c |  6 +++---
>  drivers/gpu/drm/i915/gvt/interrupt.c  |  2 +-
>  drivers/infiniband/hw/mlx5/devx.c |  2 +-
>  drivers/misc/ocxl/file.c  |  2 +-
>  drivers/s390/cio/vfio_ccw_chp.c   |  2 +-
>  drivers/s390/cio/vfio_ccw_drv.c   |  4 ++--
>  drivers/s390/cio/vfio_ccw_ops.c   |  6 +++---
>  drivers/s390/crypto/vfio_ap_ops.c |  2 +-
>  drivers/usb/gadget/function/f_fs.c|  4 ++--
>  drivers/vdpa/vdpa_user/vduse_dev.c|  6 +++---
>  drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c|  2 +-
>  drivers/vfio/pci/vfio_pci_core.c  |  6 +++---
>  drivers/vfio/pci/vfio_pci_intrs.c | 12 ++--
>  drivers/vfio/platform/vfio_platform_irq.c |  4 ++--
>  drivers/vhost/vdpa.c  |  4 ++--
>  drivers/vhost/vhost.c | 10 +-
>  drivers/vhost/vhost.h |  2 +-
>  drivers/virt/acrn/ioeventfd.c |  2 +-
>  drivers/xen/privcmd.c |  2 +-
>  fs/aio.c  |  2 +-
>  fs/eventfd.c  |  9 +++--
>  include/linux/eventfd.h   |  4 ++--
>  mm/memcontrol.c   | 10 +-
>  mm/vmpressure.c   |  2 +-
>  samples/vfio-mdev/mtty.c  |  4 ++--
>  virt/kvm/eventfd.c|  4 ++--
>  30 files changed, 60 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index dd7a783d53b5..e73f88050f08 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -1872,7 +1872,7 @@ static irqreturn_t dfl_irq_handler(int irq, void *arg)
>  {
>   struct eventfd_ctx *trigger = arg;
>  
> - eventfd_signal(trigger, 1);
> + eventfd_signal(trigger);

For FPGA part,

Acked-by: Xu Yilun 

>   return IRQ_HANDLED;
>  }


[PATCH v2 4/4] eventfd: make eventfd_signal{_mask}() void

2023-11-22 Thread Christian Brauner
No caller care about the return value.

Signed-off-by: Christian Brauner 
---
 fs/eventfd.c| 40 +++-
 include/linux/eventfd.h | 16 +++-
 2 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/fs/eventfd.c b/fs/eventfd.c
index a9a6de920fb4..13be2fb7fc96 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -43,10 +43,19 @@ struct eventfd_ctx {
int id;
 };
 
-__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask)
+/**
+ * eventfd_signal - Adds @n to the eventfd counter.
+ * @ctx: [in] Pointer to the eventfd context.
+ * @mask: [in] poll mask
+ *
+ * This function is supposed to be called by the kernel in paths that do not
+ * allow sleeping. In this function we allow the counter to reach the 
ULLONG_MAX
+ * value, and we signal this as overflow condition by returning a EPOLLERR
+ * to poll(2).
+ */
+void eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask)
 {
unsigned long flags;
-   __u64 n = 1;
 
/*
 * Deadlock or stack overflow issues can happen if we recurse here
@@ -57,37 +66,18 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t 
mask)
 * safe context.
 */
if (WARN_ON_ONCE(current->in_eventfd))
-   return 0;
+   return;
 
spin_lock_irqsave(>wqh.lock, flags);
current->in_eventfd = 1;
-   if (ULLONG_MAX - ctx->count < n)
-   n = ULLONG_MAX - ctx->count;
-   ctx->count += n;
+   if (ctx->count < ULLONG_MAX)
+   ctx->count++;
if (waitqueue_active(>wqh))
wake_up_locked_poll(>wqh, EPOLLIN | mask);
current->in_eventfd = 0;
spin_unlock_irqrestore(>wqh.lock, flags);
-
-   return n == 1;
-}
-
-/**
- * eventfd_signal - Adds @n to the eventfd counter.
- * @ctx: [in] Pointer to the eventfd context.
- *
- * This function is supposed to be called by the kernel in paths that do not
- * allow sleeping. In this function we allow the counter to reach the 
ULLONG_MAX
- * value, and we signal this as overflow condition by returning a EPOLLERR
- * to poll(2).
- *
- * Returns the amount by which the counter was incremented.
- */
-__u64 eventfd_signal(struct eventfd_ctx *ctx)
-{
-   return eventfd_signal_mask(ctx, 0);
 }
-EXPORT_SYMBOL_GPL(eventfd_signal);
+EXPORT_SYMBOL_GPL(eventfd_signal_mask);
 
 static void eventfd_free_ctx(struct eventfd_ctx *ctx)
 {
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index 4f8aac7eb62a..fea7c4eb01d6 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -35,8 +35,7 @@ void eventfd_ctx_put(struct eventfd_ctx *ctx);
 struct file *eventfd_fget(int fd);
 struct eventfd_ctx *eventfd_ctx_fdget(int fd);
 struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
-__u64 eventfd_signal(struct eventfd_ctx *ctx);
-__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask);
+void eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask);
 int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t 
*wait,
  __u64 *cnt);
 void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt);
@@ -58,14 +57,8 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
return ERR_PTR(-ENOSYS);
 }
 
-static inline int eventfd_signal(struct eventfd_ctx *ctx)
+static inline void eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask)
 {
-   return -ENOSYS;
-}
-
-static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask)
-{
-   return -ENOSYS;
 }
 
 static inline void eventfd_ctx_put(struct eventfd_ctx *ctx)
@@ -91,5 +84,10 @@ static inline void eventfd_ctx_do_read(struct eventfd_ctx 
*ctx, __u64 *cnt)
 
 #endif
 
+static inline void eventfd_signal(struct eventfd_ctx *ctx)
+{
+   eventfd_signal_mask(ctx, 0);
+}
+
 #endif /* _LINUX_EVENTFD_H */
 

-- 
2.42.0



[PATCH v2 3/4] eventfd: simplify eventfd_signal_mask()

2023-11-22 Thread Christian Brauner
The eventfd_signal_mask() helper was introduced for io_uring and similar
to eventfd_signal() it always passed 1 for @n. So don't bother with that
argument at all.

Signed-off-by: Christian Brauner 
---
 fs/eventfd.c| 7 ---
 include/linux/eventfd.h | 5 ++---
 io_uring/io_uring.c | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/eventfd.c b/fs/eventfd.c
index dc9e01053235..a9a6de920fb4 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -43,9 +43,10 @@ struct eventfd_ctx {
int id;
 };
 
-__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask)
+__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask)
 {
unsigned long flags;
+   __u64 n = 1;
 
/*
 * Deadlock or stack overflow issues can happen if we recurse here
@@ -68,7 +69,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, 
__poll_t mask)
current->in_eventfd = 0;
spin_unlock_irqrestore(>wqh.lock, flags);
 
-   return n;
+   return n == 1;
 }
 
 /**
@@ -84,7 +85,7 @@ __u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, 
__poll_t mask)
  */
 __u64 eventfd_signal(struct eventfd_ctx *ctx)
 {
-   return eventfd_signal_mask(ctx, 1, 0);
+   return eventfd_signal_mask(ctx, 0);
 }
 EXPORT_SYMBOL_GPL(eventfd_signal);
 
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index 562089431551..4f8aac7eb62a 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -36,7 +36,7 @@ struct file *eventfd_fget(int fd);
 struct eventfd_ctx *eventfd_ctx_fdget(int fd);
 struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
 __u64 eventfd_signal(struct eventfd_ctx *ctx);
-__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n, __poll_t mask);
+__u64 eventfd_signal_mask(struct eventfd_ctx *ctx, __poll_t mask);
 int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t 
*wait,
  __u64 *cnt);
 void eventfd_ctx_do_read(struct eventfd_ctx *ctx, __u64 *cnt);
@@ -63,8 +63,7 @@ static inline int eventfd_signal(struct eventfd_ctx *ctx)
return -ENOSYS;
 }
 
-static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, __u64 n,
- unsigned mask)
+static inline int eventfd_signal_mask(struct eventfd_ctx *ctx, unsigned mask)
 {
return -ENOSYS;
 }
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index ed254076c723..70170a41eac4 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -558,7 +558,7 @@ static void io_eventfd_ops(struct rcu_head *rcu)
int ops = atomic_xchg(_fd->ops, 0);
 
if (ops & BIT(IO_EVENTFD_OP_SIGNAL_BIT))
-   eventfd_signal_mask(ev_fd->cq_ev_fd, 1, EPOLL_URING_WAKE);
+   eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
 
/* IO_EVENTFD_OP_FREE_BIT may not be set here depending on callback
 * ordering in a race but if references are 0 we know we have to free
@@ -594,7 +594,7 @@ static void io_eventfd_signal(struct io_ring_ctx *ctx)
goto out;
 
if (likely(eventfd_signal_allowed())) {
-   eventfd_signal_mask(ev_fd->cq_ev_fd, 1, EPOLL_URING_WAKE);
+   eventfd_signal_mask(ev_fd->cq_ev_fd, EPOLL_URING_WAKE);
} else {
atomic_inc(_fd->refs);
if (!atomic_fetch_or(BIT(IO_EVENTFD_OP_SIGNAL_BIT), 
_fd->ops))

-- 
2.42.0



[PATCH v2 2/4] eventfd: simplify eventfd_signal()

2023-11-22 Thread Christian Brauner
Ever since the evenfd type was introduced back in 2007 in commit
e1ad7468c77d ("signal/timer/event: eventfd core") the eventfd_signal()
function only ever passed 1 as a value for @n. There's no point in
keeping that additional argument.

Signed-off-by: Christian Brauner 
---
 arch/x86/kvm/hyperv.c |  2 +-
 arch/x86/kvm/xen.c|  2 +-
 drivers/accel/habanalabs/common/device.c  |  2 +-
 drivers/fpga/dfl.c|  2 +-
 drivers/gpu/drm/drm_syncobj.c |  6 +++---
 drivers/gpu/drm/i915/gvt/interrupt.c  |  2 +-
 drivers/infiniband/hw/mlx5/devx.c |  2 +-
 drivers/misc/ocxl/file.c  |  2 +-
 drivers/s390/cio/vfio_ccw_chp.c   |  2 +-
 drivers/s390/cio/vfio_ccw_drv.c   |  4 ++--
 drivers/s390/cio/vfio_ccw_ops.c   |  6 +++---
 drivers/s390/crypto/vfio_ap_ops.c |  2 +-
 drivers/usb/gadget/function/f_fs.c|  4 ++--
 drivers/vdpa/vdpa_user/vduse_dev.c|  6 +++---
 drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c|  2 +-
 drivers/vfio/pci/vfio_pci_core.c  |  6 +++---
 drivers/vfio/pci/vfio_pci_intrs.c | 12 ++--
 drivers/vfio/platform/vfio_platform_irq.c |  4 ++--
 drivers/vhost/vdpa.c  |  4 ++--
 drivers/vhost/vhost.c | 10 +-
 drivers/vhost/vhost.h |  2 +-
 drivers/virt/acrn/ioeventfd.c |  2 +-
 drivers/xen/privcmd.c |  2 +-
 fs/aio.c  |  2 +-
 fs/eventfd.c  |  9 +++--
 include/linux/eventfd.h   |  4 ++--
 mm/memcontrol.c   | 10 +-
 mm/vmpressure.c   |  2 +-
 samples/vfio-mdev/mtty.c  |  4 ++--
 virt/kvm/eventfd.c|  4 ++--
 30 files changed, 60 insertions(+), 63 deletions(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 238afd7335e4..4943f6b2bbee 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -2388,7 +2388,7 @@ static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, 
struct kvm_hv_hcall *h
if (!eventfd)
return HV_STATUS_INVALID_PORT_ID;
 
-   eventfd_signal(eventfd, 1);
+   eventfd_signal(eventfd);
return HV_STATUS_SUCCESS;
 }
 
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index e53fad915a62..523bb6df5ac9 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -2088,7 +2088,7 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu 
*vcpu, u64 param, u64 *r)
if (ret < 0 && ret != -ENOTCONN)
return false;
} else {
-   eventfd_signal(evtchnfd->deliver.eventfd.ctx, 1);
+   eventfd_signal(evtchnfd->deliver.eventfd.ctx);
}
 
*r = 0;
diff --git a/drivers/accel/habanalabs/common/device.c 
b/drivers/accel/habanalabs/common/device.c
index 9711e8fc979d..3a89644f087c 100644
--- a/drivers/accel/habanalabs/common/device.c
+++ b/drivers/accel/habanalabs/common/device.c
@@ -2044,7 +2044,7 @@ static void hl_notifier_event_send(struct 
hl_notifier_event *notifier_event, u64
notifier_event->events_mask |= event_mask;
 
if (notifier_event->eventfd)
-   eventfd_signal(notifier_event->eventfd, 1);
+   eventfd_signal(notifier_event->eventfd);
 
mutex_unlock(_event->lock);
 }
diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index dd7a783d53b5..e73f88050f08 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -1872,7 +1872,7 @@ static irqreturn_t dfl_irq_handler(int irq, void *arg)
 {
struct eventfd_ctx *trigger = arg;
 
-   eventfd_signal(trigger, 1);
+   eventfd_signal(trigger);
return IRQ_HANDLED;
 }
 
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 01da6789d044..b9cc62982196 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -1365,7 +1365,7 @@ static void syncobj_eventfd_entry_fence_func(struct 
dma_fence *fence,
struct syncobj_eventfd_entry *entry =
container_of(cb, struct syncobj_eventfd_entry, fence_cb);
 
-   eventfd_signal(entry->ev_fd_ctx, 1);
+   eventfd_signal(entry->ev_fd_ctx);
syncobj_eventfd_entry_free(entry);
 }
 
@@ -1388,13 +1388,13 @@ syncobj_eventfd_entry_func(struct drm_syncobj *syncobj,
entry->fence = fence;
 
if (entry->flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE) {
-   eventfd_signal(entry->ev_fd_ctx, 1);
+   eventfd_signal(entry->ev_fd_ctx);
syncobj_eventfd_entry_free(entry);
} else {
ret = dma_fence_add_callback(fence, >fence_cb,
 syncobj_eventfd_entry_fence_func);
if (ret == -ENOENT) {
-   eventfd_signal(entry->ev_fd_ctx, 1);
+   

[PATCH v2 1/4] i915: make inject_virtual_interrupt() void

2023-11-22 Thread Christian Brauner
The single caller of inject_virtual_interrupt() ignores the return value
anyway. This allows us to simplify eventfd_signal() in follow-up
patches.

Signed-off-by: Christian Brauner 
---
 drivers/gpu/drm/i915/gvt/interrupt.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/interrupt.c 
b/drivers/gpu/drm/i915/gvt/interrupt.c
index de3f5903d1a7..9665876b4b13 100644
--- a/drivers/gpu/drm/i915/gvt/interrupt.c
+++ b/drivers/gpu/drm/i915/gvt/interrupt.c
@@ -422,7 +422,7 @@ static void init_irq_map(struct intel_gvt_irq *irq)
 #define MSI_CAP_DATA(offset) (offset + 8)
 #define MSI_CAP_EN 0x1
 
-static int inject_virtual_interrupt(struct intel_vgpu *vgpu)
+static void inject_virtual_interrupt(struct intel_vgpu *vgpu)
 {
unsigned long offset = vgpu->gvt->device_info.msi_cap_offset;
u16 control, data;
@@ -434,10 +434,10 @@ static int inject_virtual_interrupt(struct intel_vgpu 
*vgpu)
 
/* Do not generate MSI if MSIEN is disabled */
if (!(control & MSI_CAP_EN))
-   return 0;
+   return;
 
if (WARN(control & GENMASK(15, 1), "only support one MSI format\n"))
-   return -EINVAL;
+   return;
 
trace_inject_msi(vgpu->id, addr, data);
 
@@ -451,10 +451,10 @@ static int inject_virtual_interrupt(struct intel_vgpu 
*vgpu)
 * returned and don't inject interrupt into guest.
 */
if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
-   return -ESRCH;
-   if (vgpu->msi_trigger && eventfd_signal(vgpu->msi_trigger, 1) != 1)
-   return -EFAULT;
-   return 0;
+   return;
+   if (!vgpu->msi_trigger)
+   return;
+   eventfd_signal(vgpu->msi_trigger, 1);
 }
 
 static void propagate_event(struct intel_gvt_irq *irq,

-- 
2.42.0



[PATCH v2 0/4] eventfd: simplify signal helpers

2023-11-22 Thread Christian Brauner
Hey everyone,

This simplifies the eventfd_signal() and eventfd_signal_mask() helpers
significantly. They can be made void and not take any unnecessary
arguments.

I've added a few more simplifications based on Sean's suggestion.

Signed-off-by: Christian Brauner 

Changes in v2:
- further simplify helpers
- Link to v1: 
https://lore.kernel.org/r/20230713-vfs-eventfd-signal-v1-0-7fda6c5d2...@kernel.org

---



---
base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86
change-id: 20230713-vfs-eventfd-signal-0b0d167ad6ec



Re: Potential config regression after 89cde455 ("kexec: consolidate kexec and crash options into kernel/Kconfig.kexec")

2023-11-22 Thread Ignat Korchagin
On Wed, Nov 22, 2023 at 9:34 AM Baoquan He  wrote:
>
> On 11/21/23 at 09:43am, Ignat Korchagin wrote:
> > On Tue, Nov 21, 2023 at 7:53 AM Ignat Korchagin  
> > wrote:
> > >
> > > On Tue, Nov 21, 2023 at 1:50 AM Baoquan He  wrote:
> > > >
> > > > Eric DeVolder's Oracle mail address is not available anymore, add his
> > > > current mail address he told me.
> > >
> > > Thank you!
> > >
> > > > On 11/20/23 at 10:52pm, Ignat Korchagin wrote:
> > > > > Good day!
> > > > >
> > > > > We have recently started to evaluate Linux 6.6 and noticed that we
> > > > > cannot disable CONFIG_KEXEC anymore, but keep CONFIG_CRASH_DUMP
> > > > > enabled. It seems to be related to commit 89cde455 ("kexec:
> > > > > consolidate kexec and crash options into kernel/Kconfig.kexec"), where
> > > > > a CONFIG_KEXEC dependency was added to CONFIG_CRASH_DUMP.
> > > > >
> > > > > In our current kernel (Linux 6.1) we only enable CONFIG_KEXEC_FILE
> > > > > with enforced signature check to support the kernel crash dumping
> > > > > functionality and would like to keep CONFIG_KEXEC disabled for
> > > > > security reasons [1].
> > > > >
> > > > > I was reading the long commit message, but the reason for adding
> > > > > CONFIG_KEXEC as a dependency for CONFIG_CRASH_DUMP evaded me. And I
> > > > > believe from the implementation perspective CONFIG_KEXEC_FILE should
> > > > > suffice here (as we successfully used it for crashdumps on Linux 6.1).
> > > > >
> > > > > Is there a reason for adding this dependency or is it just an
> > > > > oversight? Would some solution of requiring either CONFIG_KEXEC or
> > > > > CONFIG_KEXEC_FILE work here?
> > > >
> > > > I searched the patch history, found Eric didn't add the dependency on
> > > > CONFIG_KEXEC at the beginning. Later a linux-next building failure with
> > > > randconfig was reported, in there CONFIG_CRASH_DUMP enabled, while
> > > > CONFIG_KEXEC is disabled. Finally Eric added the KEXEC dependency for
> > > > CRASH_DUMP. Please see below link for more details:
> > > >
> > > > https://lore.kernel.org/all/3e8eecd1-a277-2cfb-690e-5de2eb7b9...@oracle.com/T/#u
> > >
> > > Thank you for digging this up. However I'm still confused, because
> > > this is exactly how we configure Linux 6.1 (although we do have
> > > CONFIG_KEXEC_FILE enabled) and we don't have any problems. I believe
> > > we did not investigate this issue properly.
> >
> > I did some preliminary investigation for this. If I patch out the
> > dependency on CONFIG_KEXEC the kernel builds just fine for x86
> > (without CONFIG_CRASH_HOTPLUG - which is probably another issue) - so
> > this was the previous behaviour. I can see that the reported error is
> > for arm architecture and was able to reproduce it with a simple cross
> > compiler in Debian. However, I think it is still somehow related to
> > this patchset as the previous kernels (up to 6.5) build fine with just
> > CONFIG_CRASH_DUMP and without CONFIG_KEXEC for arm as well. So even
> > for arm it was introduced in 6.6.
>
> Thanks for the information.
>
> I haven't run the reproducer of issue reported on Eric's old patchset,
> while checkout to kernel 6.1, only s390 selected KEXEC for CRASH_DUMP
> already. And with the ARM building breakage, the simplest idea is
> to select KEXEC only for ARM or S390 CRASH_DUMP. I plan to try the
> reproducer later. If you have any idea or draft patch, please feel free
> to post.

The thing is - before 6.6 even ARM did not require KEXEC for
CRASH_DUMP (at least to successfully compile), so I think we should
understand what changed first before adding a dependency for ARM. I'll
try to investigate more, if I have time.

> diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec
> index 7aff28ded2f4..382dcd8d7a9d 100644
> --- a/kernel/Kconfig.kexec
> +++ b/kernel/Kconfig.kexec
> @@ -97,7 +97,7 @@ config CRASH_DUMP
> depends on ARCH_SUPPORTS_KEXEC
> select CRASH_CORE
> select KEXEC_CORE
> -   select KEXEC
> +   select KEXEC if (ARM || S390)
>
>
> arch/s390/Kconfig in kernel 6.1:
> config CRASH_DUMP
> bool "kernel crash dumps"
> select KEXEC
> help
>   Generate crash dump after being started by kexec.
>   Crash dump kernels are loaded in the main kernel with kexec-tools
>   into a specially reserved region and then later executed after
>   a crash by kdump/kexec.
>   Refer to  for more details on 
> this.
>   This option also enables s390 zfcpdump.
>   See also 
>
> >
> > > > And besides, the newly added CONFIG_CRASH_HOTPLUG also needs
> > > > CONFIG_KEXEC if the elfcorehdr is allowed to be manipulated when
> > > > cpu/memory hotplug hapened.
> > >
> > > This still feels like a regression to me: any crash dump support
> > > should be independent of KEXEC syscalls being present. While probably
> > > the common case (including us) that the crashing kernel and recovery
> > > kernel are the same, they don't have to be. We need kexec syscall in
> 

Re: Potential config regression after 89cde455 ("kexec: consolidate kexec and crash options into kernel/Kconfig.kexec")

2023-11-22 Thread Baoquan He
On 11/21/23 at 09:43am, Ignat Korchagin wrote:
> On Tue, Nov 21, 2023 at 7:53 AM Ignat Korchagin  wrote:
> >
> > On Tue, Nov 21, 2023 at 1:50 AM Baoquan He  wrote:
> > >
> > > Eric DeVolder's Oracle mail address is not available anymore, add his
> > > current mail address he told me.
> >
> > Thank you!
> >
> > > On 11/20/23 at 10:52pm, Ignat Korchagin wrote:
> > > > Good day!
> > > >
> > > > We have recently started to evaluate Linux 6.6 and noticed that we
> > > > cannot disable CONFIG_KEXEC anymore, but keep CONFIG_CRASH_DUMP
> > > > enabled. It seems to be related to commit 89cde455 ("kexec:
> > > > consolidate kexec and crash options into kernel/Kconfig.kexec"), where
> > > > a CONFIG_KEXEC dependency was added to CONFIG_CRASH_DUMP.
> > > >
> > > > In our current kernel (Linux 6.1) we only enable CONFIG_KEXEC_FILE
> > > > with enforced signature check to support the kernel crash dumping
> > > > functionality and would like to keep CONFIG_KEXEC disabled for
> > > > security reasons [1].
> > > >
> > > > I was reading the long commit message, but the reason for adding
> > > > CONFIG_KEXEC as a dependency for CONFIG_CRASH_DUMP evaded me. And I
> > > > believe from the implementation perspective CONFIG_KEXEC_FILE should
> > > > suffice here (as we successfully used it for crashdumps on Linux 6.1).
> > > >
> > > > Is there a reason for adding this dependency or is it just an
> > > > oversight? Would some solution of requiring either CONFIG_KEXEC or
> > > > CONFIG_KEXEC_FILE work here?
> > >
> > > I searched the patch history, found Eric didn't add the dependency on
> > > CONFIG_KEXEC at the beginning. Later a linux-next building failure with
> > > randconfig was reported, in there CONFIG_CRASH_DUMP enabled, while
> > > CONFIG_KEXEC is disabled. Finally Eric added the KEXEC dependency for
> > > CRASH_DUMP. Please see below link for more details:
> > >
> > > https://lore.kernel.org/all/3e8eecd1-a277-2cfb-690e-5de2eb7b9...@oracle.com/T/#u
> >
> > Thank you for digging this up. However I'm still confused, because
> > this is exactly how we configure Linux 6.1 (although we do have
> > CONFIG_KEXEC_FILE enabled) and we don't have any problems. I believe
> > we did not investigate this issue properly.
> 
> I did some preliminary investigation for this. If I patch out the
> dependency on CONFIG_KEXEC the kernel builds just fine for x86
> (without CONFIG_CRASH_HOTPLUG - which is probably another issue) - so
> this was the previous behaviour. I can see that the reported error is
> for arm architecture and was able to reproduce it with a simple cross
> compiler in Debian. However, I think it is still somehow related to
> this patchset as the previous kernels (up to 6.5) build fine with just
> CONFIG_CRASH_DUMP and without CONFIG_KEXEC for arm as well. So even
> for arm it was introduced in 6.6.

Thanks for the information.

I haven't run the reproducer of issue reported on Eric's old patchset,
while checkout to kernel 6.1, only s390 selected KEXEC for CRASH_DUMP
already. And with the ARM building breakage, the simplest idea is 
to select KEXEC only for ARM or S390 CRASH_DUMP. I plan to try the
reproducer later. If you have any idea or draft patch, please feel free
to post.

diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec
index 7aff28ded2f4..382dcd8d7a9d 100644
--- a/kernel/Kconfig.kexec
+++ b/kernel/Kconfig.kexec
@@ -97,7 +97,7 @@ config CRASH_DUMP
depends on ARCH_SUPPORTS_KEXEC
select CRASH_CORE
select KEXEC_CORE
-   select KEXEC
+   select KEXEC if (ARM || S390)


arch/s390/Kconfig in kernel 6.1:
config CRASH_DUMP
bool "kernel crash dumps"
select KEXEC
help
  Generate crash dump after being started by kexec.
  Crash dump kernels are loaded in the main kernel with kexec-tools
  into a specially reserved region and then later executed after
  a crash by kdump/kexec.
  Refer to  for more details on 
this.
  This option also enables s390 zfcpdump.
  See also 

> 
> > > And besides, the newly added CONFIG_CRASH_HOTPLUG also needs
> > > CONFIG_KEXEC if the elfcorehdr is allowed to be manipulated when
> > > cpu/memory hotplug hapened.
> >
> > This still feels like a regression to me: any crash dump support
> > should be independent of KEXEC syscalls being present. While probably
> > the common case (including us) that the crashing kernel and recovery
> > kernel are the same, they don't have to be. We need kexec syscall in
> > the crashing kernel, but crashdump support in the recovery kernel (but
> > the recovery kernel not having the kexec syscalls should be totally
> > fine). If we do require some code definitions from kexec - at most we
> > should put them under CONFIG_KEXEC_CORE.
> >
> > > Thanks
> > > Baoquan
> > >
> 
> Ignat
> 



Re: [PATCH v2 0/5] MODVERSIONS + RUST Redux

2023-11-22 Thread Masahiro Yamada
On Sat, Nov 18, 2023 at 11:58 AM Matthew Maurer  wrote:
>
> The goal of this patch series is to allow MODVERSIONS and RUST to be
> enabled simultaneously. The primary issue with doing this at the moment
> is that Rust uses some extremely long symbol names - for those
> unfamiliar with Rust, it may be helpful to think of some of the mangled
> C++ names you may have seen in binaries in the past.
>
> Previously, Gary Guo attempted to accomplish this by modifying the
> existing modversion format [1] to support variable-length symbol names.
> This was unfortunately considered to be a potential userspace break
> because kmod tools inspect this kernel module metadata. Masahiro Yamada
> suggested [2] that this could instead be done with a section per-field.
> This gives us the ability to be more flexible with this format in the
> future, as a new field or additional information will be in a new
> section which userspace tools will not yet attempt to read.
>
> In the previous version of this patchset, Luis Chamberlain suggested [3]
> I move validation out of the version checking and into the elf validity
> checker, and also add kernel-docs over there. I found
> elf_validity_cached_copy to be fairly dense and difficult to directly
> describe, so I refactored it into easier to explain pieces. In the
> process, I found a few missing checks and added those as well. See
> [PATCH 2/5] for more details. If this is too much, I'm more than happy
> to drop this patch from the series in favor of just adding the
> kernel-doc to the original code, but figured I'd offer it up in case the
> added clarity and checks were valuable.
>
> [1] https://lore.kernel.org/lkml/2023061155.1349375-1-g...@garyguo.net/
> [2] 
> https://lore.kernel.org/lkml/CAK7LNATsuszFR7JB5ZkqVS1W=hWr9=e7btf+mvgj+nxt3az...@mail.gmail.com/
> [3] https://lore.kernel.org/lkml/zvznh%2fpa5hivr...@bombadil.infradead.org/





I want to know why this is useful.


To clarify my question, let me first explain
what the modversion is.



In C, a function callee and callers must agree
with the interface of the function.


This is usually done by having a function prototype
in a header file.


Say, we have a function declaration

int foo(int x, int y);

in include/linux/foo.h


Then, the C file that defines foo() and all C files
that call it must include  so that
argument mismatch can be detected.




Same for EXPORT_SYMBOL; the symbol provider and consumers
must agree with the interface of exported symbols.

In the kernel, however, there is no promise for in-kernel ABI
compatibility across different kernel versions.
The kernel only promises the compatibility of the userspace interface.


To load modules, by principle, vmlinux and modules must have
the same version.

To slightly loosen the limitation, CONFIG_MODVERSIONS was
introduced; when it is enabled, you can load a module
as long as all the prototypes of exported symbols match.

To do this, we need to encode information about prototypes.


This is done by a tool called genksyms (scripts/genksyms/genksyms).



Say, we have this code:


int foo(int x, int y)
{
 // genksyms does not care about
 // the function body.
}
EXPORT_SYMBOL(foo);


Genksyms parses the code and computes a CRC value for 'foo'.
Genksyms is only interested in the function name and its prototype.

It sees

   int foo(int, int)

and it transforms it into a CRC.


Any change to the prototype results in a
different CRC, so the module subsystem
can check the interface compatibility
before loading a module.


It is obvious that this is impossible for Rust source
because scripts/genksyms/genksyms is only able to
parse C code.


Then, what is happening here?

See rust/exports.c


  #define EXPORT_SYMBOL_RUST_GPL(sym) extern int sym; EXPORT_SYMBOL_GPL(sym)


The global scope symbols in Rust (i.e. 'pub) are automatically
exported, and all of them are visible as 'int' variables
from C world.


Genksyms will see this code:

  extern int foo;
  EXPORT_SYMBOL_GPL(foo);

Of course, this is not a true prototype.
The real signature on the Rust side might be:

  fn foo(x: i32, y: i32) -> i32


So, even if you enable CONFIG_MODVERSIONS,
nothing is checked for Rust.
Genksyms computes a CRC from "int foo", and
the module subsystem confirms it is a "int"
variable.

We know this check always succeeds.

Why is this useful?






> Matthew Maurer (5):
>   export_report: Rehabilitate script
>   modules: Refactor + kdoc elf_validity_cached_copy
>   modpost: Extended modversion support
>   rust: Allow MODVERSIONS
>   export_report: Use new version info format
>
>  arch/powerpc/kernel/module_64.c |  25 +-
>  init/Kconfig|   1 -
>  kernel/module/internal.h|  18 +-
>  kernel/module/main.c| 663 +---
>  kernel/module/version.c |  43 +++
>  scripts/export_report.pl|  17 +-
>  scripts/mod/modpost.c   |  37 +-
>  7 files changed, 642 insertions(+), 162 deletions(-)
>
> --
> 

Re: [PATCH RFC 06/12] mm/gup: Drop folio_fast_pin_allowed() in hugepd processing

2023-11-22 Thread Peter Xu
On Wed, Nov 22, 2023 at 12:00:24AM -0800, Christoph Hellwig wrote:
> On Tue, Nov 21, 2023 at 10:59:35AM -0500, Peter Xu wrote:
> > > What prevents us from ever using hugepd with file mappings?  I think
> > > it would naturally fit in with how large folios for the pagecache work.
> > > 
> > > So keeping this check and generalizing it seems like the better idea to
> > > me.
> > 
> > But then it means we're still keeping that dead code for fast-gup even if
> > we know that fact..  Or do we have a plan to add that support very soon, so
> > this code will be destined to add back?
> 
> The question wasn't mean retorical - we support arbitrary power of two
> sized folios for the pagepage, what prevents us from using hugepd with
> them right now?

Ah, didn't catch that point previously.  Hugepd is just not used outside
hugetlb right now, afaiu.

For example, __hugepte_alloc() (and that's the only one calls
hugepd_populate()) should be the function to allocate a hugepd (ppc only),
and it's only called in huge_pte_alloc(), which is part of the current
arch-specific hugetlb api.

And generic mm paths don't normally have hugepd handling, afaics.  For
example, page_vma_mapped_walk() doesn't handle hugepd at all unless in
hugetlb specific path.

There're actually (only) two generic mm paths that can handle hugepd,
namely:

  - fast-gup
  - walk_page_*() apis (aka, __walk_page_range())

For fast-gup I think the hugepd code is in use, however for walk_page_*
apis hugepd code shouldn't be reached iiuc as we have the hugetlb specific
handling (walk_hugetlb_range()), so anything within walk_pgd_range() to hit
a hugepd can be dead code to me (but note that this "dead code" is good
stuff to me, if one would like to merge hugetlb instead into generic mm).

This series tries to add slow gup into that list too, so the 3rd one to
support it.  I plan to look more into this area (e.g., __walk_page_range()
can be another good candidate soon).  I'm not sure whether we should teach
the whole mm to understand hugepd yet, but slow gup and __walk_page_range()
does look like good candidates to already remove the hugetlb specific code
paths - slow-gup has average ~add/~del LOCs (which this series does), and
__walk_page_range() can remove some code logically, no harm I yet see.

Indeed above are based on only my code observations, so I'll be more than
happy to be corrected otherwise, as early as possible.

> 
> > The other option is I can always add a comment above gup_huge_pd()
> > explaining this special bit, so that when someone is adding hugepd support
> > to file large folios we'll hopefully not forget it?  But then that
> > generalization work will only happen when the code will be needed.
> 
> If dropping the check is the right thing for now (and I think the ppc
> maintainers and willy as the large folio guy might have a more useful
> opinions than I do), leaving a comment in would be very useful.

Willy is in the loop, and I just notice I didn't really copy ppc list, even
I planned to..  I am adding the list (linuxppc-dev@lists.ozlabs.org) into
this reply.  I'll remember to do so as long as there's a new version.

The other reason I feel like hugepd may or may not be further developed for
new features like large folio is that I saw Power9 started to shift to
radix pgtables, and afaics hugepd is only supported in hash tables
(hugepd_ok()).  But again, I confess I know nothing about Power at all.

Thanks,

-- 
Peter Xu



Re: [PATCH 12/41] mm: add per-VMA lock and helper functions to control it

2023-11-22 Thread Alexander Gordeev
On Tue, Jan 17, 2023 at 10:45:25PM +0100, Jann Horn wrote:

Hi Jann,

> On Tue, Jan 17, 2023 at 10:28 PM Suren Baghdasaryan  wrote:
> > On Tue, Jan 17, 2023 at 10:03 AM Jann Horn  wrote:
> > >
> > > +locking maintainers
> >
> > Thanks! I'll CC the locking maintainers in the next posting.
> >
> > >
> > > On Mon, Jan 9, 2023 at 9:54 PM Suren Baghdasaryan  
> > > wrote:
> > > > Introduce a per-VMA rw_semaphore to be used during page fault handling
> > > > instead of mmap_lock. Because there are cases when multiple VMAs need
> > > > to be exclusively locked during VMA tree modifications, instead of the
> > > > usual lock/unlock patter we mark a VMA as locked by taking per-VMA lock
> > > > exclusively and setting vma->lock_seq to the current mm->lock_seq. When
> > > > mmap_write_lock holder is done with all modifications and drops 
> > > > mmap_lock,
> > > > it will increment mm->lock_seq, effectively unlocking all VMAs marked as
> > > > locked.
> > > [...]
> > > > +static inline void vma_read_unlock(struct vm_area_struct *vma)
> > > > +{
> > > > +   up_read(>lock);
> > > > +}
> > >
> > > One thing that might be gnarly here is that I think you might not be
> > > allowed to use up_read() to fully release ownership of an object -
> > > from what I remember, I think that up_read() (unlike something like
> > > spin_unlock()) can access the lock object after it's already been
> > > acquired by someone else. So if you want to protect against concurrent
> > > deletion, this might have to be something like:
> > >
> > > rcu_read_lock(); /* keeps vma alive */
> > > up_read(>lock);
> > > rcu_read_unlock();
> >
> > But for deleting VMA one would need to write-lock the vma->lock first,
> > which I assume can't happen until this up_read() is complete. Is that
> > assumption wrong?
> 
> __up_read() does:
> 
> rwsem_clear_reader_owned(sem);
> tmp = atomic_long_add_return_release(-RWSEM_READER_BIAS, >count);
> DEBUG_RWSEMS_WARN_ON(tmp < 0, sem);
> if (unlikely((tmp & (RWSEM_LOCK_MASK|RWSEM_FLAG_WAITERS)) ==
>   RWSEM_FLAG_WAITERS)) {
>   clear_nonspinnable(sem);
>   rwsem_wake(sem);
> }

This sequence is covered by preempt_disable()/preempt_enable().
Would not it preserve the RCU grace period until after __up_read()
exited?

> The atomic_long_add_return_release() is the point where we are doing
> the main lock-releasing.
> 
> So if a reader dropped the read-lock while someone else was waiting on
> the lock (RWSEM_FLAG_WAITERS) and no other readers were holding the
> lock together with it, the reader also does clear_nonspinnable() and
> rwsem_wake() afterwards.
> But in rwsem_down_write_slowpath(), after we've set
> RWSEM_FLAG_WAITERS, we can return successfully immediately once
> rwsem_try_write_lock() sees that there are no active readers or
> writers anymore (if RWSEM_LOCK_MASK is unset and the cmpxchg
> succeeds). We're not necessarily waiting for the "nonspinnable" bit or
> the wake.
> 
> So yeah, I think down_write() can return successfully before up_read()
> is done with its memory accesses.

Thanks!


Re: [PATCH] powerpc/lib: Avoid array bounds warnings in vec ops

2023-11-22 Thread Naveen N Rao
On Wed, Nov 22, 2023 at 03:44:07PM +1100, Michael Ellerman wrote:
> Naveen N Rao  writes:
> > On Tue, Nov 21, 2023 at 10:54:36AM +1100, Michael Ellerman wrote:
> >> Building with GCC 13 (which has -array-bounds enabled) there are several
> >
> > Thanks, gcc13 indeed helps reproduce the warnings.
> 
> Actually that part is no longer true since 0da6e5fd6c37 ("gcc: disable
> '-Warray-bounds' for gcc-13 too").
> 
> >> warnings in sstep.c along the lines of:
> >> 
> >>   In function ‘do_byte_reverse’,
> >>   inlined from ‘do_vec_load’ at arch/powerpc/lib/sstep.c:691:3,
> >>   inlined from ‘emulate_loadstore’ at arch/powerpc/lib/sstep.c:3439:9:
> >>   arch/powerpc/lib/sstep.c:289:23: error: array subscript 2 is outside 
> >> array bounds of ‘u8[16]’ {aka ‘unsigned char[16]’} [-Werror=array-bounds=]
> >> 289 | up[2] = byterev_8(up[1]);
> >> | ~~^~
> >>   arch/powerpc/lib/sstep.c: In function ‘emulate_loadstore’:
> >>   arch/powerpc/lib/sstep.c:681:11: note: at offset 16 into object ‘u’ of 
> >> size 16
> >> 681 | } u = {};
> >> |   ^
> >> 
> >> do_byte_reverse() supports a size up to 32 bytes, but in these cases the
> >> caller is only passing a 16 byte buffer. In practice there is no bug,
> >> do_vec_load() is only called from the LOAD_VMX case in emulate_loadstore().
> >> That in turn is only reached when analyse_instr() recognises VMX ops,
> >> and in all cases the size is no greater than 16:
> >> 
> >>   $ git grep -w LOAD_VMX arch/powerpc/lib/sstep.c
> >>   arch/powerpc/lib/sstep.c:op->type = 
> >> MKOP(LOAD_VMX, 0, 1);
> >>   arch/powerpc/lib/sstep.c:op->type = 
> >> MKOP(LOAD_VMX, 0, 2);
> >>   arch/powerpc/lib/sstep.c:op->type = 
> >> MKOP(LOAD_VMX, 0, 4);
> >>   arch/powerpc/lib/sstep.c:op->type = 
> >> MKOP(LOAD_VMX, 0, 16);
> >> 
> >> Similarly for do_vec_store().
> >> 
> >> Although the warning is incorrect, the code would be safer if it clamped
> >> the size from the caller to the known size of the buffer. Do that using
> >> min_t().
> >
> > But, do_vec_load() and do_vec_store() assume that the maximum size is 16 
> > (the address_ok() check as an example). So, should we be considering a 
> > bigger hammer to help detect future incorrect use?
> 
> Yeah true.
> 
> To be honest I don't know how paranoid we want to get, we could end up
> putting WARN's all over the kernel :)
> 
> In this case I guess if the size is too large we overflow the buffer on
> the kernel stack, so we should at least check the size.
> 
> But does it need a WARN? I'm not sure. If we had a case that was passing
> a out-of-bound size hopefully we would notice in testing? :)

You're right, a simpler check should suffice. I will send an updated 
patch.

Thanks,
Naveen



Re: [PATCH] powerpc: add crtsavres.o to always-y instead of extra-y

2023-11-22 Thread Michael Ellerman
Masahiro Yamada  writes:
> On Tue, Nov 21, 2023 at 6:55 PM Aneesh Kumar K.V
>  wrote:
>>
>> "Nicholas Piggin"  writes:
>>
>> > On Tue Nov 21, 2023 at 9:23 AM AEST, Masahiro Yamada wrote:
>> >> crtsavres.o is linked to modules. However, as explained in commit
>> >> d0e628cd817f ("kbuild: doc: clarify the difference between extra-y
>> >> and always-y"), 'make modules' does not build extra-y.
>> >>
>> >> For example, the following command fails:
>> >>
>> >>   $ make ARCH=powerpc LLVM=1 KBUILD_MODPOST_WARN=1 mrproper ps3_defconfig 
>> >> modules
>> >> [snip]
>> >> LD [M]  arch/powerpc/platforms/cell/spufs/spufs.ko
>> >>   ld.lld: error: cannot open arch/powerpc/lib/crtsavres.o: No such file 
>> >> or directory
>> >>   make[3]: *** [scripts/Makefile.modfinal:56: 
>> >> arch/powerpc/platforms/cell/spufs/spufs.ko] Error 1
>> >>   make[2]: *** [Makefile:1844: modules] Error 2
>> >>   make[1]: *** [/home/masahiro/workspace/linux-kbuild/Makefile:350: 
>> >> __build_one_by_one] Error 2
>> >>   make: *** [Makefile:234: __sub-make] Error 2
>> >>
>> >
>> > Thanks. Is this the correct Fixes tag?
>> >
>> > Fixes: d0e628cd817f ("powerpc/64: Do not link crtsavres.o in vmlinux")
>> >
>>
>> I am finding a different commit ID:
>>
>> commit baa25b571a168aff5a13bfdc973f1229e2b12b63
>> Author: Nicholas Piggin 
>> Date:   Fri May 12 01:56:49 2017 +1000
>>
>> powerpc/64: Do not link crtsavres.o in vmlinux
>>
>> The 64-bit linker creates save/restore functions on demand with final
>> links, so vmlinux does not require crtsavres.o.
>
> Yeah, I think the correct tag is:
>
> Fixes: baa25b571a16 ("powerpc/64: Do not link crtsavres.o in vmlinux")

Yep, I used that when applying.

cheers


Re: [PATCH v5 1/3] powerpc: make fadump resilient with memory add/remove events

2023-11-22 Thread Michael Ellerman
Sourabh Jain  writes:
> On 22/11/23 10:47, Michael Ellerman wrote:
>> Aneesh Kumar K V  writes:
>> ...
>>> I am not sure whether we need to add all the complexity to enable 
>>> supporting different fadump kernel
>>> version. Is that even a possible use case with fadump? Can't we always 
>>> assume that with fadump the
>>> crash kernel and fadump kernel will be same version?
>> How sure are we of that?
>>
>> Don't we go through grub when we boot into the 2nd kernel. And so
>> couldn't it choose to boot a different kernel, for whatever reason.
>>
>> I don't think we need to support different pt_reg / cpumask sizes, but
>> requiring the exact same kernel version is too strict I think.
> Agree.
>>
>> But maybe I'm wrong. Would be good to hear what distro folks think.
>
> How about checking fadump crash info header compatibility in the 
> following way?
>
> static bool is_fadump_header_compatible(struct fadump_crash_info_header 
> *fdh)
> {
>      if (fdh->magic_number == FADUMP_CRASH_INFO_MAGIC_OLD) {
>      pr_err("Old magic number, can't process the dump.");
>      return false;
>      }
>
>      if (fdh->magic_number != FADUMP_CRASH_INFO_MAGIC) {
>      pr_err("Fadump header is corrupted.");
>      return false;
>      }
>
>      /*
>       * If the kernel version of the first/crashed kernel and the 
> second/fadump
>       * kernel is not same, then only collect the dump if the size of all
>       * non-primitive type members of the fadump header is the same 
> across kernels.
>       */
>      if (strcmp(fdh->kernel_version, init_uts_ns.name.release)) {
 
I don't think the kernel version check is necessary?

>      if (fdh->pt_regs_sz != sizeof(struct pt_regs) || fdh->cpu_mask_sz != 
> sizeof(struct cpumask)) {
>          pr_err("Fadump header size mismatch.\n")
>          return false;

Yeah I think that works.

>      } else
>          pr_warn("Kernel version mismatch; dump data is unreliable.\n");
>      }
>
>      return true;
> }
>
> And the new fadump crash info header will be: As suggested by Hari.
>
> /* fadump crash info structure */
> struct fadump_crash_info_header {
>      u64        magic_number;
> +  u32        version;
 
Do we need version? We're effectively using the magic_number as a
version already. Having an actual version would allow us to make
backward compatible changes in future, but it's not clear we'll need or
want to do that.

>      u32        crashing_cpu;
>      u64        elfcorehdr_addr;
> +  u64        elfcorehdr_size;
> +  u64        vmcoreinfo_raddr;
> +  u64        vmcoreinfo_size;
> +  u8          kernel_version[__NEW_UTS_LEN + 1];
> +  u32        pt_regs_sz;
>      struct pt_regs    regs;
> +  u32        cpu_mask_sz;
 
Typically you would put all the size fields before the variable sized
fields, because otherwise the later size fields may not be where you
expect them to be. But because we're bailing out if any of the sizes
don't match it doesn't actually matter.

>      struct cpumask    cpu_mask;
> };

The other issue is endian. I assume we're just declaring that the
1st/2nd kernel must be the same endian? We should still make that
explicit though.

To make it clearer that this struct is somewhat an ABI, I think we
should move the definition into arch/powerpc/include/uapi/asm/fadump.h

We don't expect userspace to actually use the header, but it will
hopefully remind everyone that the struct needs to be changed with care :)

cheers


Re: [PATCH v5 1/3] powerpc: make fadump resilient with memory add/remove events

2023-11-22 Thread Aneesh Kumar K V
On 11/22/23 4:05 PM, Sourabh Jain wrote:
> Hello Michael,
> 
> 
> On 22/11/23 10:47, Michael Ellerman wrote:
>> Aneesh Kumar K V  writes:
>> ...
>>> I am not sure whether we need to add all the complexity to enable 
>>> supporting different fadump kernel
>>> version. Is that even a possible use case with fadump? Can't we always 
>>> assume that with fadump the
>>> crash kernel and fadump kernel will be same version?
>> How sure are we of that?
>>
>> Don't we go through grub when we boot into the 2nd kernel. And so
>> couldn't it choose to boot a different kernel, for whatever reason.
>>
>> I don't think we need to support different pt_reg / cpumask sizes, but
>> requiring the exact same kernel version is too strict I think.
> Agree.
>>
>> But maybe I'm wrong. Would be good to hear what distro folks think.
> 
> How about checking fadump crash info header compatibility in the following 
> way?
> 
> static bool is_fadump_header_compatible(struct fadump_crash_info_header *fdh)
> {
>     if (fdh->magic_number == FADUMP_CRASH_INFO_MAGIC_OLD) {
>     pr_err("Old magic number, can't process the dump.");
>     return false;
>     }
> 
>     if (fdh->magic_number != FADUMP_CRASH_INFO_MAGIC) {
>     pr_err("Fadump header is corrupted.");
>     return false;
>     }
> 
>     /*
>      * If the kernel version of the first/crashed kernel and the second/fadump
>      * kernel is not same, then only collect the dump if the size of all
>      * non-primitive type members of the fadump header is the same across 
> kernels.
>      */
>     if (strcmp(fdh->kernel_version, init_uts_ns.name.release)) {
>     if (fdh->pt_regs_sz != sizeof(struct pt_regs) || fdh->cpu_mask_sz != 
> sizeof(struct cpumask)) {
>         pr_err("Fadump header size mismatch.\n")
>         return false;
>     } else
>         pr_warn("Kernel version mismatch; dump data is unreliable.\n");
>     }
> 

You also want a fdh->version check? I am still not sure you need the 
kernel_version check. IMHO that is too strict
and can hit that check where you have kexec kernel which is not installed in 
/boot crashing? 


>     return true;
> }
> 
> And the new fadump crash info header will be: As suggested by Hari.
> 
> /* fadump crash info structure */
> struct fadump_crash_info_header {
>     u64        magic_number;
> +  u32        version;
>     u32        crashing_cpu;
>     u64        elfcorehdr_addr;
> +  u64        elfcorehdr_size;
> +  u64        vmcoreinfo_raddr;
> +  u64        vmcoreinfo_size;
> +  u8          kernel_version[__NEW_UTS_LEN + 1];
> +  u32        pt_regs_sz;
>     struct pt_regs    regs;
> +  u32        cpu_mask_sz;
>     struct cpumask    cpu_mask;
> };
> 
> Thanks,
> Sourabh Jain



Re: [PATCH 2/2] ASoC: cs4270: Remove unused codec

2023-11-22 Thread Mark Brown
On Wed, Nov 22, 2023 at 05:27:12PM +1100, Michael Ellerman wrote:
> The only driver to enable SND_SOC_CS4270 was SND_SOC_MPC8610_HPCD, which
> was dropped in the preceding commit. Remove the codec as unused.

There's no real overhead from having extra drivers and we do have
generic drivers that people can attach CODECs to.


signature.asc
Description: PGP signature


Re: [PATCH v5 1/3] powerpc: make fadump resilient with memory add/remove events

2023-11-22 Thread Sourabh Jain

Hello Michael,


On 22/11/23 10:47, Michael Ellerman wrote:

Aneesh Kumar K V  writes:
...

I am not sure whether we need to add all the complexity to enable supporting 
different fadump kernel
version. Is that even a possible use case with fadump? Can't we always assume 
that with fadump the
crash kernel and fadump kernel will be same version?

How sure are we of that?

Don't we go through grub when we boot into the 2nd kernel. And so
couldn't it choose to boot a different kernel, for whatever reason.

I don't think we need to support different pt_reg / cpumask sizes, but
requiring the exact same kernel version is too strict I think.

Agree.


But maybe I'm wrong. Would be good to hear what distro folks think.


How about checking fadump crash info header compatibility in the 
following way?


static bool is_fadump_header_compatible(struct fadump_crash_info_header 
*fdh)

{
    if (fdh->magic_number == FADUMP_CRASH_INFO_MAGIC_OLD) {
    pr_err("Old magic number, can't process the dump.");
    return false;
    }

    if (fdh->magic_number != FADUMP_CRASH_INFO_MAGIC) {
    pr_err("Fadump header is corrupted.");
    return false;
    }

    /*
     * If the kernel version of the first/crashed kernel and the 
second/fadump

     * kernel is not same, then only collect the dump if the size of all
     * non-primitive type members of the fadump header is the same 
across kernels.

     */
    if (strcmp(fdh->kernel_version, init_uts_ns.name.release)) {
    if (fdh->pt_regs_sz != sizeof(struct pt_regs) || 
fdh->cpu_mask_sz != sizeof(struct cpumask)) {

        pr_err("Fadump header size mismatch.\n")
        return false;
    } else
        pr_warn("Kernel version mismatch; dump data is unreliable.\n");
    }

    return true;
}

And the new fadump crash info header will be: As suggested by Hari.

/* fadump crash info structure */
struct fadump_crash_info_header {
    u64        magic_number;
+  u32        version;
    u32        crashing_cpu;
    u64        elfcorehdr_addr;
+  u64        elfcorehdr_size;
+  u64        vmcoreinfo_raddr;
+  u64        vmcoreinfo_size;
+  u8          kernel_version[__NEW_UTS_LEN + 1];
+  u32        pt_regs_sz;
    struct pt_regs    regs;
+  u32        cpu_mask_sz;
    struct cpumask    cpu_mask;
};

Thanks,
Sourabh Jain


[PATCH v3] powerpc: Adjust config HOTPLUG_CPU dependency

2023-11-22 Thread Vishal Chourasia
Changed HOTPLUG_CPU dependency to SMP and either ARCH_HIBERNATION_POSSIBLE or
ARCH_SUSPEND_POSSIBLE, aligning with systems' suspend/hibernation capabilities.
This update link CPU hotplugging more logically with platforms' capabilities.

configs ARCH_HIBERNATION_POSSIBLE and ARCH_SUSPEND_POSSIBLE are now selected
only if required platform dependencies are met.

Reported-by: Srikar Dronamraju 
Suggested-by: Aneesh Kumar K V 
Suggested-by: Michael Ellerman 
Signed-off-by: Vishal Chourasia 

v2: https://lore.kernel.org/all/20231122092303.223719-1-vish...@linux.ibm.com
v1: https://lore.kernel.org/all/20231114082046.6018-1-vish...@linux.ibm.com
---
During the configuration process with 'make randconfig' followed by
'make olddefconfig', we observed a warning indicating an unmet direct
dependency for the HOTPLUG_CPU option. The dependency in question relates to
various PowerPC configurations (PPC_PSERIES, PPC_PMAC, PPC_POWERNV,
FSL_SOC_BOOKE) which were not enabled, yet the HOTPLUG_CPU was being
erroneously selected due to an implicit assumption by the PM_SLEEP_SMP option.
This misalignment in dependencies could potentially lead to inconsistent kernel
configuration states, especially when considering the necessary hardware
support for CPU hot-plugging on PowerPC platforms. The patch aims to correct
this by ensuring that ARCH_HIBERNATION_POSSIBLE is contingent upon the
appropriate PowerPC configurations being active.

steps to reproduce (before applying the patch):

Run 'make pseries_le_defconfig'
Run 'make menuconfig'
Enable hibernation [ Kernel options -> Hibernation (aka 'suspend to disk') ] 
Disable [ Platform support -> IBM PowerNV (Non-Virtualized) platform support ]
Disable [ Platform support -> IBM pSeries & new (POWER5-based) iSeries ]
Enable SMP [ Processor support -> Symmetric multi-processing support ]
Save the config
Run 'make olddefconfig'

 arch/powerpc/Kconfig | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 6f105ee4f3cf..87c8134da3da 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -156,6 +156,7 @@ config PPC
select ARCH_HAS_UACCESS_FLUSHCACHE
select ARCH_HAS_UBSAN_SANITIZE_ALL
select ARCH_HAVE_NMI_SAFE_CMPXCHG
+   select ARCH_HIBERNATION_POSSIBLEif (PPC_PSERIES || PPC_PMAC || 
PPC_POWERNV || FSL_SOC_BOOKE)
select ARCH_KEEP_MEMBLOCK
select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE if PPC_RADIX_MMU
select ARCH_MIGHT_HAVE_PC_PARPORT
@@ -166,6 +167,7 @@ config PPC
select ARCH_STACKWALK
select ARCH_SUPPORTS_ATOMIC_RMW
select ARCH_SUPPORTS_DEBUG_PAGEALLOCif PPC_BOOK3S || PPC_8xx || 40x
+   select ARCH_SUSPEND_POSSIBLEif (ADB_PMU || PPC_EFIKA || 
PPC_LITE5200 || PPC_83xx || (PPC_85xx && !PPC_E500MC) || PPC_86xx || 
PPC_PSERIES || 44x || 40x)
select ARCH_USE_BUILTIN_BSWAP
select ARCH_USE_CMPXCHG_LOCKREF if PPC64
select ARCH_USE_MEMTEST
@@ -381,13 +383,9 @@ config DEFAULT_UIMAGE
 
 config ARCH_HIBERNATION_POSSIBLE
bool
-   default y
 
 config ARCH_SUSPEND_POSSIBLE
-   def_bool y
-   depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 || PPC_83xx || \
-  (PPC_85xx && !PPC_E500MC) || PPC_86xx || PPC_PSERIES \
-  || 44x || 40x
+   bool
 
 config ARCH_SUSPEND_NONZERO_CPU
def_bool y
@@ -568,8 +566,7 @@ config ARCH_USING_PATCHABLE_FUNCTION_ENTRY
 
 config HOTPLUG_CPU
bool "Support for enabling/disabling CPUs"
-   depends on SMP && (PPC_PSERIES || \
-   PPC_PMAC || PPC_POWERNV || FSL_SOC_BOOKE)
+   depends on SMP && (ARCH_HIBERNATION_POSSIBLE || ARCH_SUSPEND_POSSIBLE)
help
  Say Y here to be able to disable and re-enable individual
  CPUs at runtime on SMP machines.
-- 
2.41.0



[PATCH] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add

2023-11-22 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/mm/init-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 119ef491f797..0884fc601c46 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -139,6 +139,8 @@ void pgtable_cache_add(unsigned int shift)
 
align = max_t(unsigned long, align, minalign);
name = kasprintf(GFP_KERNEL, "pgtable-2^%d", shift);
+   if (!name)
+   return;
new = kmem_cache_create(name, table_size, align, 0, ctor(shift));
if (!new)
panic("Could not allocate pgtable cache for order %d", shift);
-- 
2.34.1



Re: [PATCH] powerpc: Adjust config HOTPLUG_CPU dependency

2023-11-22 Thread Vishal Chourasia


On 22/11/23 3:03 pm, Aneesh Kumar K V wrote:
> On 11/22/23 2:53 PM, Vishal Chourasia wrote:
>> Changed HOTPLUG_CPU dependency to SMP and either ARCH_HIBERNATION_POSSIBLE or
>> ARCH_SUSPEND_POSSIBLE, aligning with systems' suspend/hibernation 
>> capabilities.
>> This update links CPU hotplugging more logically with platforms' 
>> capabilities.
>>
>> Other changes include
>>
>> 1. configs ARCH_HIBERNATION_POSSIBLE and ARCH_SUSPEND_POSSIBLE are now 
>> selected
>>only if required platform dependencies are met.
>>
>> 2. Defaults for configs ARCH_HIBERNATION_POSSIBLE and
>>ARCH_SUSPEND_POSSIBLE has been set to 'N'
>>
>> Reported-by: Srikar Dronamraju 
>> Suggested-by: Aneesh Kumar K V 
>> Suggested-by: Michael Ellerman 
>> Signed-off-by: Vishal Chourasia 
>>
>> v1: https://lore.kernel.org/all/20231114082046.6018-1-vish...@linux.ibm.com
>> ---
>> During the configuration process with 'make randconfig' followed by
>> 'make olddefconfig', we observed a warning indicating an unmet direct
>> dependency for the HOTPLUG_CPU option. The dependency in question relates to
>> various PowerPC configurations (PPC_PSERIES, PPC_PMAC, PPC_POWERNV,
>> FSL_SOC_BOOKE) which were not enabled, yet the HOTPLUG_CPU was being
>> erroneously selected due to an implicit assumption by the PM_SLEEP_SMP 
>> option.
>> This misalignment in dependencies could potentially lead to inconsistent 
>> kernel
>> configuration states, especially when considering the necessary hardware
>> support for CPU hot-plugging on PowerPC platforms. The patch aims to correct
>> this by ensuring that ARCH_HIBERNATION_POSSIBLE is contingent upon the
>> appropriate PowerPC configurations being active.
>>
>> steps to reproduce (before applying the patch):
>>
>> Run 'make pseries_le_defconfig'
>> Run 'make menuconfig'
>> Enable hibernation [ Kernel options -> Hibernation (aka 'suspend to disk') ] 
>> Disable [ Platform support -> IBM PowerNV (Non-Virtualized) platform support 
>> ]
>> Disable [ Platform support -> IBM pSeries & new (POWER5-based) iSeries ]
>> Enable SMP [ Processor support -> Symmetric multi-processing support ]
>> Save the config
>> Run 'make olddefconfig'
>>
>>  arch/powerpc/Kconfig | 13 +
>>  1 file changed, 5 insertions(+), 8 deletions(-)
>>
>> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
>> index 6f105ee4f3cf..6e7e9af2f0c1 100644
>> --- a/arch/powerpc/Kconfig
>> +++ b/arch/powerpc/Kconfig
>> @@ -155,6 +155,8 @@ config PPC
>>  select ARCH_HAS_TICK_BROADCAST  if GENERIC_CLOCKEVENTS_BROADCAST
>>  select ARCH_HAS_UACCESS_FLUSHCACHE
>>  select ARCH_HAS_UBSAN_SANITIZE_ALL
>> +select ARCH_HIBERNATION_POSSIBLEif (PPC_PSERIES || PPC_PMAC || 
>> PPC_POWERNV || FSL_SOC_BOOKE)
>> +select ARCH_SUSPEND_POSSIBLEif (ADB_PMU || PPC_EFIKA || 
>> PPC_LITE5200 || PPC_83xx || (PPC_85xx && !PPC_E500MC) || PPC_86xx || 
>> PPC_PSERIES || 44x || 40x)
> We should keep that sorted as explained in comment around that. 
Sure. I will send out another patch
>
>>  select ARCH_HAVE_NMI_SAFE_CMPXCHG
>>  select ARCH_KEEP_MEMBLOCK
>>  select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE if PPC_RADIX_MMU
>> @@ -380,14 +382,10 @@ config DEFAULT_UIMAGE
>>Used to allow a board to specify it wants a uImage built by default
>>  
>>  config ARCH_HIBERNATION_POSSIBLE
>> -bool
>> -default y
>> +def_bool n
>
> We should be able to keep this 
> config ARCH_HIBERNATION_POSSIBLE
> bool
>
>
> That is how we have rest of the ARCH_* config. I am not sure we need to 
> explicitly say "def_bool n" 
I believed it improves readability, that all. I can revert it back.
>
>>  
>>  config ARCH_SUSPEND_POSSIBLE
>> -def_bool y
>> -depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 || PPC_83xx || \
>> -   (PPC_85xx && !PPC_E500MC) || PPC_86xx || PPC_PSERIES \
>> -   || 44x || 40x
>> +def_bool n
>>  
>>  config ARCH_SUSPEND_NONZERO_CPU
>>  def_bool y
>> @@ -568,8 +566,7 @@ config ARCH_USING_PATCHABLE_FUNCTION_ENTRY
>>  
>>  config HOTPLUG_CPU
>>  bool "Support for enabling/disabling CPUs"
>> -depends on SMP && (PPC_PSERIES || \
>> -PPC_PMAC || PPC_POWERNV || FSL_SOC_BOOKE)
>> +depends on SMP && (ARCH_HIBERNATION_POSSIBLE || ARCH_SUSPEND_POSSIBLE)
>>  help
>>Say Y here to be able to disable and re-enable individual
>>CPUs at runtime on SMP machines.


Re: [PATCH] powerpc: Adjust config HOTPLUG_CPU dependency

2023-11-22 Thread Aneesh Kumar K V
On 11/22/23 2:53 PM, Vishal Chourasia wrote:
> Changed HOTPLUG_CPU dependency to SMP and either ARCH_HIBERNATION_POSSIBLE or
> ARCH_SUSPEND_POSSIBLE, aligning with systems' suspend/hibernation 
> capabilities.
> This update links CPU hotplugging more logically with platforms' capabilities.
> 
> Other changes include
> 
> 1. configs ARCH_HIBERNATION_POSSIBLE and ARCH_SUSPEND_POSSIBLE are now 
> selected
>only if required platform dependencies are met.
> 
> 2. Defaults for configs ARCH_HIBERNATION_POSSIBLE and
>ARCH_SUSPEND_POSSIBLE has been set to 'N'
> 
> Reported-by: Srikar Dronamraju 
> Suggested-by: Aneesh Kumar K V 
> Suggested-by: Michael Ellerman 
> Signed-off-by: Vishal Chourasia 
> 
> v1: https://lore.kernel.org/all/20231114082046.6018-1-vish...@linux.ibm.com
> ---
> During the configuration process with 'make randconfig' followed by
> 'make olddefconfig', we observed a warning indicating an unmet direct
> dependency for the HOTPLUG_CPU option. The dependency in question relates to
> various PowerPC configurations (PPC_PSERIES, PPC_PMAC, PPC_POWERNV,
> FSL_SOC_BOOKE) which were not enabled, yet the HOTPLUG_CPU was being
> erroneously selected due to an implicit assumption by the PM_SLEEP_SMP option.
> This misalignment in dependencies could potentially lead to inconsistent 
> kernel
> configuration states, especially when considering the necessary hardware
> support for CPU hot-plugging on PowerPC platforms. The patch aims to correct
> this by ensuring that ARCH_HIBERNATION_POSSIBLE is contingent upon the
> appropriate PowerPC configurations being active.
> 
> steps to reproduce (before applying the patch):
> 
> Run 'make pseries_le_defconfig'
> Run 'make menuconfig'
> Enable hibernation [ Kernel options -> Hibernation (aka 'suspend to disk') ] 
> Disable [ Platform support -> IBM PowerNV (Non-Virtualized) platform support ]
> Disable [ Platform support -> IBM pSeries & new (POWER5-based) iSeries ]
> Enable SMP [ Processor support -> Symmetric multi-processing support ]
> Save the config
> Run 'make olddefconfig'
> 
>  arch/powerpc/Kconfig | 13 +
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 6f105ee4f3cf..6e7e9af2f0c1 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -155,6 +155,8 @@ config PPC
>   select ARCH_HAS_TICK_BROADCAST  if GENERIC_CLOCKEVENTS_BROADCAST
>   select ARCH_HAS_UACCESS_FLUSHCACHE
>   select ARCH_HAS_UBSAN_SANITIZE_ALL
> + select ARCH_HIBERNATION_POSSIBLEif (PPC_PSERIES || PPC_PMAC || 
> PPC_POWERNV || FSL_SOC_BOOKE)
> + select ARCH_SUSPEND_POSSIBLEif (ADB_PMU || PPC_EFIKA || 
> PPC_LITE5200 || PPC_83xx || (PPC_85xx && !PPC_E500MC) || PPC_86xx || 
> PPC_PSERIES || 44x || 40x)

We should keep that sorted as explained in comment around that. 

>   select ARCH_HAVE_NMI_SAFE_CMPXCHG
>   select ARCH_KEEP_MEMBLOCK
>   select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE if PPC_RADIX_MMU
> @@ -380,14 +382,10 @@ config DEFAULT_UIMAGE
> Used to allow a board to specify it wants a uImage built by default
>  
>  config ARCH_HIBERNATION_POSSIBLE
> - bool
> - default y
> + def_bool n


We should be able to keep this 
config ARCH_HIBERNATION_POSSIBLE
bool


That is how we have rest of the ARCH_* config. I am not sure we need to 
explicitly say "def_bool n" 

>  
>  config ARCH_SUSPEND_POSSIBLE
> - def_bool y
> - depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 || PPC_83xx || \
> -(PPC_85xx && !PPC_E500MC) || PPC_86xx || PPC_PSERIES \
> -|| 44x || 40x
> + def_bool n
>  
>  config ARCH_SUSPEND_NONZERO_CPU
>   def_bool y
> @@ -568,8 +566,7 @@ config ARCH_USING_PATCHABLE_FUNCTION_ENTRY
>  
>  config HOTPLUG_CPU
>   bool "Support for enabling/disabling CPUs"
> - depends on SMP && (PPC_PSERIES || \
> - PPC_PMAC || PPC_POWERNV || FSL_SOC_BOOKE)
> + depends on SMP && (ARCH_HIBERNATION_POSSIBLE || ARCH_SUSPEND_POSSIBLE)
>   help
> Say Y here to be able to disable and re-enable individual
> CPUs at runtime on SMP machines.



[PATCH] powerpc: Adjust config HOTPLUG_CPU dependency

2023-11-22 Thread Vishal Chourasia
Changed HOTPLUG_CPU dependency to SMP and either ARCH_HIBERNATION_POSSIBLE or
ARCH_SUSPEND_POSSIBLE, aligning with systems' suspend/hibernation capabilities.
This update links CPU hotplugging more logically with platforms' capabilities.

Other changes include

1. configs ARCH_HIBERNATION_POSSIBLE and ARCH_SUSPEND_POSSIBLE are now selected
   only if required platform dependencies are met.

2. Defaults for configs ARCH_HIBERNATION_POSSIBLE and
   ARCH_SUSPEND_POSSIBLE has been set to 'N'

Reported-by: Srikar Dronamraju 
Suggested-by: Aneesh Kumar K V 
Suggested-by: Michael Ellerman 
Signed-off-by: Vishal Chourasia 

v1: https://lore.kernel.org/all/20231114082046.6018-1-vish...@linux.ibm.com
---
During the configuration process with 'make randconfig' followed by
'make olddefconfig', we observed a warning indicating an unmet direct
dependency for the HOTPLUG_CPU option. The dependency in question relates to
various PowerPC configurations (PPC_PSERIES, PPC_PMAC, PPC_POWERNV,
FSL_SOC_BOOKE) which were not enabled, yet the HOTPLUG_CPU was being
erroneously selected due to an implicit assumption by the PM_SLEEP_SMP option.
This misalignment in dependencies could potentially lead to inconsistent kernel
configuration states, especially when considering the necessary hardware
support for CPU hot-plugging on PowerPC platforms. The patch aims to correct
this by ensuring that ARCH_HIBERNATION_POSSIBLE is contingent upon the
appropriate PowerPC configurations being active.

steps to reproduce (before applying the patch):

Run 'make pseries_le_defconfig'
Run 'make menuconfig'
Enable hibernation [ Kernel options -> Hibernation (aka 'suspend to disk') ] 
Disable [ Platform support -> IBM PowerNV (Non-Virtualized) platform support ]
Disable [ Platform support -> IBM pSeries & new (POWER5-based) iSeries ]
Enable SMP [ Processor support -> Symmetric multi-processing support ]
Save the config
Run 'make olddefconfig'

 arch/powerpc/Kconfig | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 6f105ee4f3cf..6e7e9af2f0c1 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -155,6 +155,8 @@ config PPC
select ARCH_HAS_TICK_BROADCAST  if GENERIC_CLOCKEVENTS_BROADCAST
select ARCH_HAS_UACCESS_FLUSHCACHE
select ARCH_HAS_UBSAN_SANITIZE_ALL
+   select ARCH_HIBERNATION_POSSIBLEif (PPC_PSERIES || PPC_PMAC || 
PPC_POWERNV || FSL_SOC_BOOKE)
+   select ARCH_SUSPEND_POSSIBLEif (ADB_PMU || PPC_EFIKA || 
PPC_LITE5200 || PPC_83xx || (PPC_85xx && !PPC_E500MC) || PPC_86xx || 
PPC_PSERIES || 44x || 40x)
select ARCH_HAVE_NMI_SAFE_CMPXCHG
select ARCH_KEEP_MEMBLOCK
select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE if PPC_RADIX_MMU
@@ -380,14 +382,10 @@ config DEFAULT_UIMAGE
  Used to allow a board to specify it wants a uImage built by default
 
 config ARCH_HIBERNATION_POSSIBLE
-   bool
-   default y
+   def_bool n
 
 config ARCH_SUSPEND_POSSIBLE
-   def_bool y
-   depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 || PPC_83xx || \
-  (PPC_85xx && !PPC_E500MC) || PPC_86xx || PPC_PSERIES \
-  || 44x || 40x
+   def_bool n
 
 config ARCH_SUSPEND_NONZERO_CPU
def_bool y
@@ -568,8 +566,7 @@ config ARCH_USING_PATCHABLE_FUNCTION_ENTRY
 
 config HOTPLUG_CPU
bool "Support for enabling/disabling CPUs"
-   depends on SMP && (PPC_PSERIES || \
-   PPC_PMAC || PPC_POWERNV || FSL_SOC_BOOKE)
+   depends on SMP && (ARCH_HIBERNATION_POSSIBLE || ARCH_SUSPEND_POSSIBLE)
help
  Say Y here to be able to disable and re-enable individual
  CPUs at runtime on SMP machines.
-- 
2.41.0



[PATCH] powerpc: Use ARRAY_SIZE for array length

2023-11-22 Thread Jiapeng Chong
Use of macro ARRAY_SIZE to calculate array size minimizes
the redundant code and improves code reusability.

./arch/powerpc/xmon/ppc-opc.c:957:67-68: WARNING: Use ARRAY_SIZE.

Reported-by: Abaci Robot 
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=7612
Signed-off-by: Jiapeng Chong 
---
 arch/powerpc/xmon/ppc-opc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/xmon/ppc-opc.c b/arch/powerpc/xmon/ppc-opc.c
index 0774d711453e..d409d6113f82 100644
--- a/arch/powerpc/xmon/ppc-opc.c
+++ b/arch/powerpc/xmon/ppc-opc.c
@@ -954,8 +954,7 @@ const struct powerpc_operand powerpc_operands[] =
   { 0xff, 11, NULL, NULL, PPC_OPERAND_SIGNOPT },
 };
 
-const unsigned int num_powerpc_operands = (sizeof (powerpc_operands)
-  / sizeof (powerpc_operands[0]));
+const unsigned int num_powerpc_operands = ARRAY_SIZE(powerpc_operands);
 
 /* The functions used to insert and extract complicated operands.  */
 
-- 
2.20.1.7.g153144c



Re: [PATCH 3/3] drm/amd/display: Support DRM_AMD_DC_FP on RISC-V

2023-11-22 Thread Christoph Hellwig
> - select DRM_AMD_DC_FP if (X86 || LOONGARCH || (PPC64 && ALTIVEC) || 
> (ARM64 && KERNEL_MODE_NEON && !CC_IS_CLANG))
> + select DRM_AMD_DC_FP if ARM64 && KERNEL_MODE_NEON && !CC_IS_CLANG
> + select DRM_AMD_DC_FP if PPC64 && ALTIVEC
> + select DRM_AMD_DC_FP if RISCV && FPU
> + select DRM_AMD_DC_FP if LOONGARCH || X86

This really is a mess.  Can you add a ARCH_HAS_KERNEL_FPU_SUPPORT
symbol that all architetures that have it select instead, and them
make DRM_AMD_DC_FP depend on it?

> -#if defined(CONFIG_X86) || defined(CONFIG_LOONGARCH)
> +#if defined(CONFIG_X86) || defined(CONFIG_LOONGARCH) || defined(CONFIG_RISCV)
>   kernel_fpu_begin();
>  #elif defined(CONFIG_PPC64)
>   if (cpu_has_feature(CPU_FTR_VSX_COMP))
> @@ -122,7 +124,7 @@ void dc_fpu_end(const char *function_name, const int line)
>  
>   depth = __this_cpu_dec_return(fpu_recursion_depth);
>   if (depth == 0) {
> -#if defined(CONFIG_X86) || defined(CONFIG_LOONGARCH)
> +#if defined(CONFIG_X86) || defined(CONFIG_LOONGARCH) || defined(CONFIG_RISCV)
>   kernel_fpu_end();
>  #elif defined(CONFIG_PPC64)
>   if (cpu_has_feature(CPU_FTR_VSX_COMP))

And then this mess can go away.  We'll need to decide if we want to
cover all the in-kernel vector support as part of it, which would
seem reasonable to me, or have a separate generic kernel_vector_begin
with it's own option.

> diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile 
> b/drivers/gpu/drm/amd/display/dc/dml/Makefile
> index ea7d60f9a9b4..5c8f840ef323 100644
> --- a/drivers/gpu/drm/amd/display/dc/dml/Makefile
> +++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile
> @@ -43,6 +43,12 @@ dml_ccflags := -mfpu=64
>  dml_rcflags := -msoft-float
>  endif
>  
> +ifdef CONFIG_RISCV
> +include $(srctree)/arch/riscv/Makefile.isa
> +# Remove V from the ISA string, like in arch/riscv/Makefile, but keep F and 
> D.
> +dml_ccflags := -march=$(shell echo $(riscv-march-y) | sed -E 
> 's/(rv32ima|rv64ima)([^v_]*)v?/\1\2/')
> +endif
> +
>  ifdef CONFIG_CC_IS_GCC
>  ifneq ($(call gcc-min-version, 70100),y)
>  IS_OLD_GCC = 1

And this is again not really something we should be doing.
Instead we need a generic way in Kconfig to enable FPU support
for an object file or set of, that the arch support can hook
into.

Btw, I'm also really worried about folks using the FPU instructions
outside the kernel_fpu_begin/end windows in general (not directly
related to the RISC-V support).  Can we have objecttool checks
for that similar to only allowing the unsafe uaccess in the
uaccess begin/end pairs?


[PATCH 2/2] ASoC: cs4270: Remove unused codec

2023-11-22 Thread Michael Ellerman
The only driver to enable SND_SOC_CS4270 was SND_SOC_MPC8610_HPCD, which
was dropped in the preceding commit. Remove the codec as unused.

Signed-off-by: Michael Ellerman 
---
 sound/soc/codecs/Kconfig  |  14 -
 sound/soc/codecs/Makefile |   2 -
 sound/soc/codecs/cs4270.c | 762 --
 3 files changed, 778 deletions(-)
 delete mode 100644 sound/soc/codecs/cs4270.c

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 3429419ca694..412540e0fced 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -85,7 +85,6 @@ config SND_SOC_ALL_CODECS
imply SND_SOC_CS42L73
imply SND_SOC_CS4234
imply SND_SOC_CS4265
-   imply SND_SOC_CS4270
imply SND_SOC_CS4271_I2C
imply SND_SOC_CS4271_SPI
imply SND_SOC_CS42XX8_I2C
@@ -894,19 +893,6 @@ config SND_SOC_CS4265
depends on I2C
select REGMAP_I2C
 
-# Cirrus Logic CS4270 Codec
-config SND_SOC_CS4270
-   tristate "Cirrus Logic CS4270 CODEC"
-   depends on I2C
-
-# Cirrus Logic CS4270 Codec VD = 3.3V Errata
-# Select if you are affected by the errata where the part will not function
-# if MCLK divide-by-1.5 is selected and VD is set to 3.3V.  The driver will
-# not select any sample rates that require MCLK to be divided by 1.5.
-config SND_SOC_CS4270_VD33_ERRATA
-   bool
-   depends on SND_SOC_CS4270
-
 config SND_SOC_CS4271
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 2078bb0d981e..e762e2babc75 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -89,7 +89,6 @@ snd-soc-cs42l73-objs := cs42l73.o
 snd-soc-cs42l83-i2c-objs := cs42l83-i2c.o
 snd-soc-cs4234-objs := cs4234.o
 snd-soc-cs4265-objs := cs4265.o
-snd-soc-cs4270-objs := cs4270.o
 snd-soc-cs4271-objs := cs4271.o
 snd-soc-cs4271-i2c-objs := cs4271-i2c.o
 snd-soc-cs4271-spi-objs := cs4271-spi.o
@@ -478,7 +477,6 @@ obj-$(CONFIG_SND_SOC_CS42L73)   += snd-soc-cs42l73.o
 obj-$(CONFIG_SND_SOC_CS42L83)  += snd-soc-cs42l83-i2c.o
 obj-$(CONFIG_SND_SOC_CS4234)   += snd-soc-cs4234.o
 obj-$(CONFIG_SND_SOC_CS4265)   += snd-soc-cs4265.o
-obj-$(CONFIG_SND_SOC_CS4270)   += snd-soc-cs4270.o
 obj-$(CONFIG_SND_SOC_CS4271)   += snd-soc-cs4271.o
 obj-$(CONFIG_SND_SOC_CS4271_I2C)   += snd-soc-cs4271-i2c.o
 obj-$(CONFIG_SND_SOC_CS4271_SPI)   += snd-soc-cs4271-spi.o
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
deleted file mode 100644
index 3bbb90c827f2..
--- a/sound/soc/codecs/cs4270.c
+++ /dev/null
@@ -1,762 +0,0 @@
-/*
- * CS4270 ALSA SoC (ASoC) codec driver
- *
- * Author: Timur Tabi 
- *
- * Copyright 2007-2009 Freescale Semiconductor, Inc.  This file is licensed
- * under the terms of the GNU General Public License version 2.  This
- * program is licensed "as is" without any warranty of any kind, whether
- * express or implied.
- *
- * This is an ASoC device driver for the Cirrus Logic CS4270 codec.
- *
- * Current features/limitations:
- *
- * - Software mode is supported.  Stand-alone mode is not supported.
- * - Only I2C is supported, not SPI
- * - Support for master and slave mode
- * - The machine driver's 'startup' function must call
- *   cs4270_set_dai_sysclk() with the value of MCLK.
- * - Only I2S and left-justified modes are supported
- * - Power management is supported
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8  | SNDRV_PCM_FMTBIT_S16_LE  | \
-   SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S20_3LE | \
-   SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_LE)
-
-/* CS4270 registers addresses */
-#define CS4270_CHIPID  0x01/* Chip ID */
-#define CS4270_PWRCTL  0x02/* Power Control */
-#define CS4270_MODE0x03/* Mode Control */
-#define CS4270_FORMAT  0x04/* Serial Format, ADC/DAC Control */
-#define CS4270_TRANS   0x05/* Transition Control */
-#define CS4270_MUTE0x06/* Mute Control */
-#define CS4270_VOLA0x07/* DAC Channel A Volume Control */
-#define CS4270_VOLB0x08/* DAC Channel B Volume Control */
-
-#define CS4270_FIRSTREG0x01
-#define CS4270_LASTREG 0x08
-#define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1)
-#define CS4270_I2C_INCR0x80
-
-/* Bit masks for the CS4270 registers */
-#define CS4270_CHIPID_ID   0xF0
-#define CS4270_CHIPID_REV  0x0F
-#define CS4270_PWRCTL_FREEZE   0x80
-#define CS4270_PWRCTL_PDN_ADC  0x20
-#define CS4270_PWRCTL_PDN_DAC  0x02
-#define CS4270_PWRCTL_PDN  0x01
-#define CS4270_PWRCTL_PDN_ALL  \
-   (CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC | CS4270_PWRCTL_PDN)
-#define CS4270_MODE_SPEED_MASK 0x30
-#define CS4270_MODE_1X 0x00
-#define CS4270_MODE_2X 0x10
-#define CS4270_MODE_4X 0x20
-#define CS4270_MODE_SLAVE  0x30
-#define CS4270_MODE_DIV_MASK   0x0E
-#define 

[PATCH 1/2] ASoC: fsl: mpc8610_hpcd: Remove unused driver

2023-11-22 Thread Michael Ellerman
The mpc8610_hpcd.c driver depends on CONFIG_MPC8610_HPCD which was
removed in commit 248667f8bbde ("powerpc: drop HPCD/MPC8610 evaluation
platform support"). That makes the driver unbuildable and unusable, so
remove it.

Depends-on: 248667f8bbde ("powerpc: drop HPCD/MPC8610 evaluation platform 
support")
Signed-off-by: Michael Ellerman 
---
 MAINTAINERS  |   1 -
 sound/soc/fsl/Kconfig|  13 -
 sound/soc/fsl/Makefile   |   4 -
 sound/soc/fsl/mpc8610_hpcd.c | 451 ---
 4 files changed, 469 deletions(-)
 delete mode 100644 sound/soc/fsl/mpc8610_hpcd.c

diff --git a/MAINTAINERS b/MAINTAINERS
index ea790149af79..27b2f5bb2061 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8581,7 +8581,6 @@ L:linuxppc-dev@lists.ozlabs.org
 S: Maintained
 F: sound/soc/fsl/fsl*
 F: sound/soc/fsl/imx*
-F: sound/soc/fsl/mpc8610_hpcd.c
 
 FREESCALE SOC SOUND QMC DRIVER
 M: Herve Codina 
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 725c530a3636..bec2aa561930 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -183,19 +183,6 @@ config SND_SOC_POWERPC_QMC_AUDIO
 
 comment "SoC Audio support for Freescale PPC boards:"
 
-config SND_SOC_MPC8610_HPCD
-   tristate "ALSA SoC support for the Freescale MPC8610 HPCD board"
-   # I2C is necessary for the CS4270 driver
-   depends on MPC8610_HPCD && I2C
-   select SND_SOC_FSL_SSI
-   select SND_SOC_FSL_UTILS
-   select SND_SOC_POWERPC_DMA
-   select SND_SOC_CS4270
-   select SND_SOC_CS4270_VD33_ERRATA
-   default y if MPC8610_HPCD
-   help
- Say Y if you want to enable audio on the Freescale MPC8610 HPCD.
-
 config SND_SOC_P1022_DS
tristate "ALSA SoC support for the Freescale P1022 DS board"
# I2C is necessary for the WM8776 driver
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile
index 8db7e97d0bd5..b45eda80c196 100644
--- a/sound/soc/fsl/Makefile
+++ b/sound/soc/fsl/Makefile
@@ -1,8 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
-# MPC8610 HPCD Machine Support
-snd-soc-mpc8610-hpcd-objs := mpc8610_hpcd.o
-obj-$(CONFIG_SND_SOC_MPC8610_HPCD) += snd-soc-mpc8610-hpcd.o
-
 # P1022 DS Machine Support
 snd-soc-p1022-ds-objs := p1022_ds.o
 obj-$(CONFIG_SND_SOC_P1022_DS) += snd-soc-p1022-ds.o
diff --git a/sound/soc/fsl/mpc8610_hpcd.c b/sound/soc/fsl/mpc8610_hpcd.c
deleted file mode 100644
index 52fb9e7bcca4..
--- a/sound/soc/fsl/mpc8610_hpcd.c
+++ /dev/null
@@ -1,451 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-//
-// Freescale MPC8610HPCD ALSA SoC Machine driver
-//
-// Author: Timur Tabi 
-//
-// Copyright 2007-2010 Freescale Semiconductor, Inc.
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "fsl_dma.h"
-#include "fsl_ssi.h"
-#include "fsl_utils.h"
-
-/* There's only one global utilities register */
-static phys_addr_t guts_phys;
-
-/**
- * mpc8610_hpcd_data: machine-specific ASoC device data
- *
- * This structure contains data for a single sound platform device on an
- * MPC8610 HPCD.  Some of the data is taken from the device tree.
- */
-struct mpc8610_hpcd_data {
-   struct snd_soc_dai_link dai[2];
-   struct snd_soc_card card;
-   unsigned int dai_format;
-   unsigned int codec_clk_direction;
-   unsigned int cpu_clk_direction;
-   unsigned int clk_frequency;
-   unsigned int ssi_id;/* 0 = SSI1, 1 = SSI2, etc */
-   unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */
-   unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/
-   char codec_dai_name[DAI_NAME_SIZE];
-   char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */
-};
-
-/**
- * mpc8610_hpcd_machine_probe: initialize the board
- *
- * This function is used to initialize the board-specific hardware.
- *
- * Here we program the DMACR and PMUXCR registers.
- */
-static int mpc8610_hpcd_machine_probe(struct snd_soc_card *card)
-{
-   struct mpc8610_hpcd_data *machine_data =
-   container_of(card, struct mpc8610_hpcd_data, card);
-   struct ccsr_guts __iomem *guts;
-
-   guts = ioremap(guts_phys, sizeof(struct ccsr_guts));
-   if (!guts) {
-   dev_err(card->dev, "could not map global utilities\n");
-   return -ENOMEM;
-   }
-
-   /* Program the signal routing between the SSI and the DMA */
-   guts_set_dmacr(guts, machine_data->dma_id[0],
-  machine_data->dma_channel_id[0],
-  CCSR_GUTS_DMACR_DEV_SSI);
-   guts_set_dmacr(guts, machine_data->dma_id[1],
-  machine_data->dma_channel_id[1],
-  CCSR_GUTS_DMACR_DEV_SSI);
-
-   guts_set_pmuxcr_dma(guts, machine_data->dma_id[0],
-   machine_data->dma_channel_id[0], 0);
-   guts_set_pmuxcr_dma(guts, machine_data->dma_id[1],
-   machine_data->dma_channel_id[1], 0);
-
-   

[PATCH v11 15/15] media: vim2m-audio: add virtual driver for audio memory to memory

2023-11-22 Thread Shengjiu Wang
Audio memory to memory virtual driver use video memory to memory
virtual driver vim2m.c as example. The main difference is
device type is VFL_TYPE_AUDIO and device cap type is V4L2_CAP_AUDIO_M2M.

The device_run function is a dummy function, which is simply
copy the data from input buffer to output buffer.

Signed-off-by: Shengjiu Wang 
---
 drivers/media/test-drivers/Kconfig   |  11 +
 drivers/media/test-drivers/Makefile  |   1 +
 drivers/media/test-drivers/vim2m-audio.c | 799 +++
 3 files changed, 811 insertions(+)
 create mode 100644 drivers/media/test-drivers/vim2m-audio.c

diff --git a/drivers/media/test-drivers/Kconfig 
b/drivers/media/test-drivers/Kconfig
index 459b433e9fae..55f8af6ee4e2 100644
--- a/drivers/media/test-drivers/Kconfig
+++ b/drivers/media/test-drivers/Kconfig
@@ -17,6 +17,17 @@ config VIDEO_VIM2M
  This is a virtual test device for the memory-to-memory driver
  framework.
 
+config VIDEO_VIM2M_AUDIO
+   tristate "Virtual Memory-to-Memory Driver For Audio"
+   depends on VIDEO_DEV
+   select VIDEOBUF2_VMALLOC
+   select V4L2_MEM2MEM_DEV
+   select MEDIA_CONTROLLER
+   select MEDIA_CONTROLLER_REQUEST_API
+   help
+ This is a virtual audio test device for the memory-to-memory driver
+ framework.
+
 source "drivers/media/test-drivers/vicodec/Kconfig"
 source "drivers/media/test-drivers/vimc/Kconfig"
 source "drivers/media/test-drivers/vivid/Kconfig"
diff --git a/drivers/media/test-drivers/Makefile 
b/drivers/media/test-drivers/Makefile
index 740714a4584d..0c61c9ada3e1 100644
--- a/drivers/media/test-drivers/Makefile
+++ b/drivers/media/test-drivers/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_DVB_VIDTV) += vidtv/
 
 obj-$(CONFIG_VIDEO_VICODEC) += vicodec/
 obj-$(CONFIG_VIDEO_VIM2M) += vim2m.o
+obj-$(CONFIG_VIDEO_VIM2M_AUDIO) += vim2m-audio.o
 obj-$(CONFIG_VIDEO_VIMC) += vimc/
 obj-$(CONFIG_VIDEO_VIVID) += vivid/
 obj-$(CONFIG_VIDEO_VISL) += visl/
diff --git a/drivers/media/test-drivers/vim2m-audio.c 
b/drivers/media/test-drivers/vim2m-audio.c
new file mode 100644
index ..72806ada8628
--- /dev/null
+++ b/drivers/media/test-drivers/vim2m-audio.c
@@ -0,0 +1,799 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * A virtual v4l2-mem2mem example for audio device.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+MODULE_DESCRIPTION("Virtual device for audio mem2mem testing");
+MODULE_LICENSE("GPL");
+
+static unsigned int debug;
+module_param(debug, uint, 0644);
+MODULE_PARM_DESC(debug, "debug level");
+
+#define MEM2MEM_NAME "vim2m-audio"
+
+#define dprintk(dev, lvl, fmt, arg...) \
+   v4l2_dbg(lvl, debug, &(dev)->v4l2_dev, "%s: " fmt, __func__, ## arg)
+
+#define SAMPLE_NUM 4096
+
+static void audm2m_dev_release(struct device *dev)
+{}
+
+static struct platform_device audm2m_pdev = {
+   .name   = MEM2MEM_NAME,
+   .dev.release= audm2m_dev_release,
+};
+
+static u32 formats[] = {
+   V4L2_AUDIO_FMT_S16_LE,
+};
+
+#define NUM_FORMATS ARRAY_SIZE(formats)
+
+/* Per-queue, driver-specific private data */
+struct audm2m_q_data {
+   unsigned intrate;
+   unsigned intchannels;
+   unsigned intbuffersize;
+   unsigned intsequence;
+   u32 fourcc;
+};
+
+enum {
+   V4L2_M2M_SRC = 0,
+   V4L2_M2M_DST = 1,
+};
+
+static snd_pcm_format_t find_format(u32 fourcc)
+{
+   snd_pcm_format_t fmt;
+   unsigned int k;
+
+   for (k = 0; k < NUM_FORMATS; k++) {
+   if (formats[k] == fourcc)
+   break;
+   }
+
+   if (k == NUM_FORMATS)
+   return 0;
+
+   fmt = v4l2_fourcc_to_audfmt(formats[k]);
+
+   return fmt;
+}
+
+struct audm2m_dev {
+   struct v4l2_device  v4l2_dev;
+   struct video_device vfd;
+
+   struct mutexdev_mutex;
+
+   struct v4l2_m2m_dev *m2m_dev;
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct media_device mdev;
+#endif
+};
+
+struct audm2m_ctx {
+   struct v4l2_fh  fh;
+   struct v4l2_ctrl_handlerctrl_handler;
+   struct audm2m_dev   *dev;
+
+   struct mutexvb_mutex;
+
+   /* Source and destination queue data */
+   struct audm2m_q_data   q_data[2];
+};
+
+static inline struct audm2m_ctx *file2ctx(struct file *file)
+{
+   return container_of(file->private_data, struct audm2m_ctx, fh);
+}
+
+static struct audm2m_q_data *get_q_data(struct audm2m_ctx *ctx,
+   enum v4l2_buf_type type)
+{
+   if (type == V4L2_BUF_TYPE_AUDIO_OUTPUT)
+   return >q_data[V4L2_M2M_SRC];
+   return >q_data[V4L2_M2M_DST];
+}
+
+static const char *type_name(enum v4l2_buf_type type)
+{
+   if (type == V4L2_BUF_TYPE_AUDIO_OUTPUT)
+   return "Output";
+   return 

[PATCH v11 14/15] media: imx-asrc: Add memory to memory driver

2023-11-22 Thread Shengjiu Wang
Implement the ASRC memory to memory function using
the v4l2 framework, user can use this function with
v4l2 ioctl interface.

User send the output and capture buffer to driver and
driver store the converted data to the capture buffer.

This feature can be shared by ASRC and EASRC drivers

Signed-off-by: Shengjiu Wang 
---
 drivers/media/platform/nxp/Kconfig|   13 +
 drivers/media/platform/nxp/Makefile   |1 +
 drivers/media/platform/nxp/imx-asrc.c | 1264 +
 3 files changed, 1278 insertions(+)
 create mode 100644 drivers/media/platform/nxp/imx-asrc.c

diff --git a/drivers/media/platform/nxp/Kconfig 
b/drivers/media/platform/nxp/Kconfig
index 40e3436669e2..8d0ca335601f 100644
--- a/drivers/media/platform/nxp/Kconfig
+++ b/drivers/media/platform/nxp/Kconfig
@@ -67,3 +67,16 @@ config VIDEO_MX2_EMMAPRP
 
 source "drivers/media/platform/nxp/dw100/Kconfig"
 source "drivers/media/platform/nxp/imx-jpeg/Kconfig"
+
+config VIDEO_IMX_ASRC
+   tristate "NXP i.MX ASRC M2M support"
+   depends on V4L_MEM2MEM_DRIVERS
+   depends on MEDIA_SUPPORT
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_MEM2MEM_DEV
+   select MEDIA_CONTROLLER
+   help
+   Say Y if you want to add ASRC M2M support for NXP CPUs.
+   It is a complement for ASRC M2P and ASRC P2M features.
+   This option is only useful for out-of-tree drivers since
+   in-tree drivers select it automatically.
diff --git a/drivers/media/platform/nxp/Makefile 
b/drivers/media/platform/nxp/Makefile
index 4d90eb713652..1325675e34f5 100644
--- a/drivers/media/platform/nxp/Makefile
+++ b/drivers/media/platform/nxp/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_VIDEO_IMX8MQ_MIPI_CSI2) += imx8mq-mipi-csi2.o
 obj-$(CONFIG_VIDEO_IMX_MIPI_CSIS) += imx-mipi-csis.o
 obj-$(CONFIG_VIDEO_IMX_PXP) += imx-pxp.o
 obj-$(CONFIG_VIDEO_MX2_EMMAPRP) += mx2_emmaprp.o
+obj-$(CONFIG_VIDEO_IMX_ASRC) += imx-asrc.o
diff --git a/drivers/media/platform/nxp/imx-asrc.c 
b/drivers/media/platform/nxp/imx-asrc.c
new file mode 100644
index ..db4d45d5ba59
--- /dev/null
+++ b/drivers/media/platform/nxp/imx-asrc.c
@@ -0,0 +1,1264 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
+// Copyright (C) 2019-2023 NXP
+//
+// Freescale ASRC Memory to Memory (M2M) driver
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define V4L_CAP OUT
+#define V4L_OUT IN
+
+#define ASRC_xPUT_DMA_CALLBACK(dir) \
+   (((dir) == V4L_OUT) ? asrc_input_dma_callback \
+   : asrc_output_dma_callback)
+
+#define DIR_STR(dir) (dir) == V4L_OUT ? "out" : "cap"
+
+/* Maximum output and capture buffer size */
+#define ASRC_M2M_BUFFER_SIZE (512 * 1024)
+
+/* Maximum output and capture period size */
+#define ASRC_M2M_PERIOD_SIZE (48 * 1024)
+
+struct asrc_pair_m2m {
+   struct fsl_asrc_pair *pair;
+   struct asrc_m2m *m2m;
+   struct v4l2_fh fh;
+   struct v4l2_ctrl_handler ctrl_handler;
+   int channels[2];
+   unsigned int sequence[2];
+   s64 src_rate_off_prev;  /* Q31.32 */
+   s64 dst_rate_off_prev;  /* Q31.32 */
+   s64 src_rate_off_cur;   /* Q31.32 */
+   s64 dst_rate_off_cur;   /* Q31.32 */
+};
+
+struct asrc_m2m {
+   struct fsl_asrc_m2m_pdata pdata;
+   struct v4l2_device v4l2_dev;
+   struct v4l2_m2m_dev *m2m_dev;
+   struct video_device *dec_vdev;
+   struct mutex mlock; /* v4l2 ioctls serialization */
+   struct platform_device *pdev;
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct media_device mdev;
+#endif
+};
+
+static u32 formats[] = {
+   V4L2_AUDIO_FMT_S8,
+   V4L2_AUDIO_FMT_S16_LE,
+   V4L2_AUDIO_FMT_U16_LE,
+   V4L2_AUDIO_FMT_S24_LE,
+   V4L2_AUDIO_FMT_S24_3LE,
+   V4L2_AUDIO_FMT_U24_LE,
+   V4L2_AUDIO_FMT_U24_3LE,
+   V4L2_AUDIO_FMT_S32_LE,
+   V4L2_AUDIO_FMT_U32_LE,
+   V4L2_AUDIO_FMT_S20_3LE,
+   V4L2_AUDIO_FMT_U20_3LE,
+   V4L2_AUDIO_FMT_FLOAT_LE,
+   V4L2_AUDIO_FMT_IEC958_SUBFRAME_LE,
+};
+
+#define NUM_FORMATS ARRAY_SIZE(formats)
+
+static const s64 asrc_v1_m2m_rates[] = {
+   5512, 8000, 11025, 12000, 16000,
+   22050, 24000, 32000, 44100,
+   48000, 64000, 88200, 96000,
+   128000, 176400, 192000,
+};
+
+static const s64 asrc_v2_m2m_rates[] = {
+   8000, 11025, 12000, 16000,
+   22050, 24000, 32000, 44100,
+   48000, 64000, 88200, 96000,
+   128000, 176400, 192000, 256000,
+   352800, 384000, 705600, 768000,
+};
+
+static u32 find_fourcc(snd_pcm_format_t format)
+{
+   snd_pcm_format_t fmt;
+   unsigned int k;
+
+   for (k = 0; k < NUM_FORMATS; k++) {
+   fmt = v4l2_fourcc_to_audfmt(formats[k]);
+   if (fmt == format)
+   return formats[k];
+   }
+
+   return 0;
+}
+
+static snd_pcm_format_t find_format(u32 fourcc)
+{
+   unsigned int k;
+

[PATCH v11 13/15] media: vivid: add fixed point test controls

2023-11-22 Thread Shengjiu Wang
Add fixed point test controls, one is for Q4.16 format
another one is for Q63 format.

Signed-off-by: Shengjiu Wang 
---
 drivers/media/test-drivers/vivid/vivid-core.h |  2 ++
 .../media/test-drivers/vivid/vivid-ctrls.c| 26 +++
 include/media/v4l2-ctrls.h|  3 +++
 3 files changed, 31 insertions(+)

diff --git a/drivers/media/test-drivers/vivid/vivid-core.h 
b/drivers/media/test-drivers/vivid/vivid-core.h
index cfb8e66083f6..f65465191bc9 100644
--- a/drivers/media/test-drivers/vivid/vivid-core.h
+++ b/drivers/media/test-drivers/vivid/vivid-core.h
@@ -222,6 +222,8 @@ struct vivid_dev {
struct v4l2_ctrl*boolean;
struct v4l2_ctrl*int32;
struct v4l2_ctrl*int64;
+   struct v4l2_ctrl*int32_q16;
+   struct v4l2_ctrl*int64_q63;
struct v4l2_ctrl*menu;
struct v4l2_ctrl*string;
struct v4l2_ctrl*bitmask;
diff --git a/drivers/media/test-drivers/vivid/vivid-ctrls.c 
b/drivers/media/test-drivers/vivid/vivid-ctrls.c
index f2b20e25a7a4..2444ea95b285 100644
--- a/drivers/media/test-drivers/vivid/vivid-ctrls.c
+++ b/drivers/media/test-drivers/vivid/vivid-ctrls.c
@@ -38,6 +38,8 @@
 #define VIVID_CID_U8_PIXEL_ARRAY   (VIVID_CID_CUSTOM_BASE + 14)
 #define VIVID_CID_S32_ARRAY(VIVID_CID_CUSTOM_BASE + 15)
 #define VIVID_CID_S64_ARRAY(VIVID_CID_CUSTOM_BASE + 16)
+#define VIVID_CID_INT_Q4_16(VIVID_CID_CUSTOM_BASE + 17)
+#define VIVID_CID_INT64_Q63(VIVID_CID_CUSTOM_BASE + 18)
 
 #define VIVID_CID_VIVID_BASE   (0x00f0 | 0xf000)
 #define VIVID_CID_VIVID_CLASS  (0x00f0 | 1)
@@ -182,6 +184,28 @@ static const struct v4l2_ctrl_config vivid_ctrl_int64 = {
.step = 1,
 };
 
+static const struct v4l2_ctrl_config vivid_ctrl_int32_q16 = {
+   .ops = _user_gen_ctrl_ops,
+   .id = VIVID_CID_INT_Q4_16,
+   .name = "Integer 32 Bits Q4.16",
+   .type = V4L2_CTRL_TYPE_INTEGER,
+   .min = v4l2_ctrl_fp_compose(-16, 0, 16),
+   .max = v4l2_ctrl_fp_compose(15, 0x, 16),
+   .step = 1,
+   .fraction_bits = 16,
+};
+
+static const struct v4l2_ctrl_config vivid_ctrl_int64_q63 = {
+   .ops = _user_gen_ctrl_ops,
+   .id = VIVID_CID_INT64_Q63,
+   .name = "Integer 64 Bits Q63",
+   .type = V4L2_CTRL_TYPE_INTEGER64,
+   .min = v4l2_ctrl_fp_compose(-1, 0, 63),
+   .max = v4l2_ctrl_fp_compose(0, LLONG_MAX, 63),
+   .step = 1,
+   .fraction_bits = 63,
+};
+
 static const struct v4l2_ctrl_config vivid_ctrl_u32_array = {
.ops = _user_gen_ctrl_ops,
.id = VIVID_CID_U32_ARRAY,
@@ -1670,6 +1694,8 @@ int vivid_create_controls(struct vivid_dev *dev, bool 
show_ccs_cap,
dev->button = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_button, 
NULL);
dev->int32 = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_int32, 
NULL);
dev->int64 = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_int64, 
NULL);
+   dev->int32_q16 = v4l2_ctrl_new_custom(hdl_user_gen, 
_ctrl_int32_q16, NULL);
+   dev->int64_q63 = v4l2_ctrl_new_custom(hdl_user_gen, 
_ctrl_int64_q63, NULL);
dev->boolean = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_boolean, 
NULL);
dev->menu = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_menu, NULL);
dev->string = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_string, 
NULL);
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index c35514c5bf88..d18fd116238b 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -1593,4 +1593,7 @@ void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl);
  */
 int v4l2_ctrl_type_op_validate(const struct v4l2_ctrl *ctrl, union 
v4l2_ctrl_ptr ptr);
 
+/* Composite function for integer and fractional bits */
+#define v4l2_ctrl_fp_compose(i, f, fraction_bits) (((s64)(i) << fraction_bits) 
+ (f))
+
 #endif
-- 
2.34.1



[PATCH v11 12/15] media: uapi: Add an entity type for audio resampler

2023-11-22 Thread Shengjiu Wang
Add and document a media entity type for audio resampler.
It is MEDIA_ENT_F_PROC_AUDIO_RESAMPLER.

Signed-off-by: Shengjiu Wang 
---
 Documentation/userspace-api/media/mediactl/media-types.rst | 6 ++
 include/uapi/linux/media.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/Documentation/userspace-api/media/mediactl/media-types.rst 
b/Documentation/userspace-api/media/mediactl/media-types.rst
index f0880aea41d6..abbe515dad76 100644
--- a/Documentation/userspace-api/media/mediactl/media-types.rst
+++ b/Documentation/userspace-api/media/mediactl/media-types.rst
@@ -40,6 +40,7 @@ Types and flags used to represent the media graph elements
 .. _MEDIA-ENT-F-PROC-VIDEO-ENCODER:
 .. _MEDIA-ENT-F-PROC-VIDEO-DECODER:
 .. _MEDIA-ENT-F-PROC-VIDEO-ISP:
+.. _MEDIA-ENT-F-PROC-AUDIO-RESAMPLER:
 .. _MEDIA-ENT-F-VID-MUX:
 .. _MEDIA-ENT-F-VID-IF-BRIDGE:
 .. _MEDIA-ENT-F-DV-DECODER:
@@ -208,6 +209,11 @@ Types and flags used to represent the media graph elements
  combination of custom V4L2 controls and IOCTLs, and parameters
  supplied in a metadata buffer.
 
+*  -  ``MEDIA_ENT_F_PROC_AUDIO_RESAMPLER``
+   -  An Audio Resampler device. An entity capable of
+ resampling a audio stream from one sample rate to another sample
+ rate. Must have one sink pad and at least one source pad.
+
 *  -  ``MEDIA_ENT_F_VID_MUX``
- Video multiplexer. An entity capable of multiplexing must have at
  least two sink pads and one source pad, and must pass the video
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 9ff6dec7393a..a8266eaa8042 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -125,6 +125,7 @@ struct media_device_info {
 #define MEDIA_ENT_F_PROC_VIDEO_ENCODER (MEDIA_ENT_F_BASE + 0x4007)
 #define MEDIA_ENT_F_PROC_VIDEO_DECODER (MEDIA_ENT_F_BASE + 0x4008)
 #define MEDIA_ENT_F_PROC_VIDEO_ISP (MEDIA_ENT_F_BASE + 0x4009)
+#define MEDIA_ENT_F_PROC_AUDIO_RESAMPLER   (MEDIA_ENT_F_BASE + 0x400a)
 
 /*
  * Switch and bridge entity functions
-- 
2.34.1



[PATCH v11 11/15] media: uapi: Declare interface types for Audio

2023-11-22 Thread Shengjiu Wang
Declare the interface types that will be used by Audio.
The type is MEDIA_INTF_T_V4L_AUDIO.

Signed-off-by: Shengjiu Wang 
---
 .../userspace-api/media/mediactl/media-types.rst|  5 +
 drivers/media/v4l2-core/v4l2-dev.c  |  4 
 drivers/media/v4l2-core/v4l2-mem2mem.c  | 13 +
 include/uapi/linux/media.h  |  1 +
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/Documentation/userspace-api/media/mediactl/media-types.rst 
b/Documentation/userspace-api/media/mediactl/media-types.rst
index 0ffeece1e0c8..f0880aea41d6 100644
--- a/Documentation/userspace-api/media/mediactl/media-types.rst
+++ b/Documentation/userspace-api/media/mediactl/media-types.rst
@@ -265,6 +265,7 @@ Types and flags used to represent the media graph elements
 .. _MEDIA-INTF-T-V4L-SUBDEV:
 .. _MEDIA-INTF-T-V4L-SWRADIO:
 .. _MEDIA-INTF-T-V4L-TOUCH:
+.. _MEDIA-INTF-T-V4L-AUDIO:
 .. _MEDIA-INTF-T-ALSA-PCM-CAPTURE:
 .. _MEDIA-INTF-T-ALSA-PCM-PLAYBACK:
 .. _MEDIA-INTF-T-ALSA-CONTROL:
@@ -322,6 +323,10 @@ Types and flags used to represent the media graph elements
-  Device node interface for Touch device (V4L)
-  typically, /dev/v4l-touch?
 
+*  -  ``MEDIA_INTF_T_V4L_AUDIO``
+   -  Device node interface for Audio device (V4L)
+   -  typically, /dev/v4l-audio?
+
 *  -  ``MEDIA_INTF_T_ALSA_PCM_CAPTURE``
-  Device node interface for ALSA PCM Capture
-  typically, /dev/snd/pcmC?D?c
diff --git a/drivers/media/v4l2-core/v4l2-dev.c 
b/drivers/media/v4l2-core/v4l2-dev.c
index b92c760b611a..c3a7d974db26 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -842,6 +842,10 @@ static int video_register_media_controller(struct 
video_device *vdev)
intf_type = MEDIA_INTF_T_V4L_SUBDEV;
/* Entity will be created via v4l2_device_register_subdev() */
break;
+   case VFL_TYPE_AUDIO:
+   intf_type = MEDIA_INTF_T_V4L_AUDIO;
+   /* Entity will be created via v4l2_device_register_subdev() */
+   break;
default:
return 0;
}
diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c 
b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 0cc30397fbad..bf41d112b742 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -1134,10 +1134,15 @@ int v4l2_m2m_register_media_controller(struct 
v4l2_m2m_dev *m2m_dev,
if (ret)
goto err_rm_links0;
 
-   /* Create video interface */
-   m2m_dev->intf_devnode = media_devnode_create(mdev,
-   MEDIA_INTF_T_V4L_VIDEO, 0,
-   VIDEO_MAJOR, vdev->minor);
+   if (vdev->vfl_type == VFL_TYPE_AUDIO)
+   m2m_dev->intf_devnode = media_devnode_create(mdev,
+   MEDIA_INTF_T_V4L_AUDIO, 0,
+   VIDEO_MAJOR, vdev->minor);
+   else
+   /* Create video interface */
+   m2m_dev->intf_devnode = media_devnode_create(mdev,
+   MEDIA_INTF_T_V4L_VIDEO, 0,
+   VIDEO_MAJOR, vdev->minor);
if (!m2m_dev->intf_devnode) {
ret = -ENOMEM;
goto err_rm_links1;
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index 1c80b1d6bbaf..9ff6dec7393a 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -260,6 +260,7 @@ struct media_links_enum {
 #define MEDIA_INTF_T_V4L_SUBDEV(MEDIA_INTF_T_V4L_BASE 
+ 3)
 #define MEDIA_INTF_T_V4L_SWRADIO   (MEDIA_INTF_T_V4L_BASE + 4)
 #define MEDIA_INTF_T_V4L_TOUCH (MEDIA_INTF_T_V4L_BASE + 5)
+#define MEDIA_INTF_T_V4L_AUDIO (MEDIA_INTF_T_V4L_BASE + 6)
 
 #define MEDIA_INTF_T_ALSA_BASE 0x0300
 #define MEDIA_INTF_T_ALSA_PCM_CAPTURE  (MEDIA_INTF_T_ALSA_BASE)
-- 
2.34.1



[PATCH v11 10/15] media: uapi: Add audio rate controls support

2023-11-22 Thread Shengjiu Wang
Add V4L2_CID_M2M_AUDIO_SOURCE_RATE and V4L2_CID_M2M_AUDIO_DEST_RATE
new IDs for rate control.

Add V4L2_CID_M2M_AUDIO_SOURCE_RATE_OFFSET and
V4L2_CID_M2M_AUDIO_DEST_RATE_OFFSET for clock drift.

Signed-off-by: Shengjiu Wang 
---
 .../media/v4l/ext-ctrls-audio-m2m.rst | 20 +++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c |  6 ++
 include/uapi/linux/v4l2-controls.h|  5 +
 3 files changed, 31 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst
index 82d2ecedbfee..a3c06fbb91b9 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst
@@ -19,3 +19,23 @@ Audio M2M Control IDs
 The Audio M2M class descriptor. Calling
 :ref:`VIDIOC_QUERYCTRL` for this control will
 return a description of this control class.
+
+.. _v4l2-audio-asrc:
+
+``V4L2_CID_M2M_AUDIO_SOURCE_RATE (integer menu)``
+Sets the audio source sample rate, unit is Hz
+
+``V4L2_CID_M2M_AUDIO_DEST_RATE (integer menu)``
+Sets the audio destination sample rate, unit is Hz
+
+``V4L2_CID_M2M_AUDIO_SOURCE_RATE_OFFSET (fixed point)``
+Sets the offset from the audio source sample rate, unit is Hz.
+The offset compensates for any clock drift. The actual source audio sample
+rate is the ideal source audio sample rate from
+``V4L2_CID_M2M_AUDIO_SOURCE_RATE`` plus this fixed point offset.
+
+``V4L2_CID_M2M_AUDIO_DEST_RATE_OFFSET (fixed point)``
+Sets the offset from the audio dest sample rate, unit is Hz.
+The offset compensates for any clock drift. The actual dest audio sample
+rate is the ideal source audio sample rate from
+``V4L2_CID_M2M_AUDIO_DEST_RATE`` plus this fixed point offset.
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c 
b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
index 2a85ea3dc92f..4e606d7fd971 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
@@ -1245,6 +1245,8 @@ const char *v4l2_ctrl_get_name(u32 id)
 
/* Audio M2M controls */
case V4L2_CID_M2M_AUDIO_CLASS:  return "Audio M2M Controls";
+   case V4L2_CID_M2M_AUDIO_SOURCE_RATE:return "Audio Source Sample 
Rate";
+   case V4L2_CID_M2M_AUDIO_DEST_RATE:  return "Audio Dest Sample Rate";
default:
return NULL;
}
@@ -1606,6 +1608,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
*type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
break;
+   case V4L2_CID_M2M_AUDIO_SOURCE_RATE:
+   case V4L2_CID_M2M_AUDIO_DEST_RATE:
+   *type = V4L2_CTRL_TYPE_INTEGER_MENU;
+   break;
default:
*type = V4L2_CTRL_TYPE_INTEGER;
break;
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 7d318065a33d..493b59f20a35 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -3489,6 +3489,11 @@ struct v4l2_ctrl_av1_film_grain {
 #define V4L2_CID_M2M_AUDIO_CLASS_BASE  (V4L2_CTRL_CLASS_M2M_AUDIO | 0x900)
 #define V4L2_CID_M2M_AUDIO_CLASS   (V4L2_CTRL_CLASS_M2M_AUDIO | 1)
 
+#define V4L2_CID_M2M_AUDIO_SOURCE_RATE (V4L2_CID_M2M_AUDIO_CLASS_BASE + 0)
+#define V4L2_CID_M2M_AUDIO_DEST_RATE   (V4L2_CID_M2M_AUDIO_CLASS_BASE + 1)
+#define V4L2_CID_M2M_AUDIO_SOURCE_RATE_OFFSET  (V4L2_CID_M2M_AUDIO_CLASS_BASE 
+ 2)
+#define V4L2_CID_M2M_AUDIO_DEST_RATE_OFFSET(V4L2_CID_M2M_AUDIO_CLASS_BASE 
+ 3)
+
 /* MPEG-compression definitions kept for backwards compatibility */
 #ifndef __KERNEL__
 #define V4L2_CTRL_CLASS_MPEGV4L2_CTRL_CLASS_CODEC
-- 
2.34.1



[PATCH v11 09/15] media: uapi: Add V4L2_CTRL_CLASS_M2M_AUDIO

2023-11-22 Thread Shengjiu Wang
The Audio M2M class includes controls for audio memory-to-memory
use cases. The controls can be used for audio codecs, audio
preprocessing, audio postprocessing.

Signed-off-by: Shengjiu Wang 
---
 .../userspace-api/media/v4l/common.rst|  1 +
 .../media/v4l/ext-ctrls-audio-m2m.rst | 21 +++
 .../media/v4l/vidioc-g-ext-ctrls.rst  |  4 
 drivers/media/v4l2-core/v4l2-ctrls-defs.c |  4 
 include/uapi/linux/v4l2-controls.h|  4 
 5 files changed, 34 insertions(+)
 create mode 100644 
Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst

diff --git a/Documentation/userspace-api/media/v4l/common.rst 
b/Documentation/userspace-api/media/v4l/common.rst
index ea0435182e44..d5366e96a596 100644
--- a/Documentation/userspace-api/media/v4l/common.rst
+++ b/Documentation/userspace-api/media/v4l/common.rst
@@ -52,6 +52,7 @@ applicable to all devices.
 ext-ctrls-fm-rx
 ext-ctrls-detect
 ext-ctrls-colorimetry
+ext-ctrls-audio-m2m
 fourcc
 format
 planar-apis
diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst
new file mode 100644
index ..82d2ecedbfee
--- /dev/null
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst
@@ -0,0 +1,21 @@
+.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
+
+.. _audiom2m-controls:
+
+***
+Audio M2M Control Reference
+***
+
+The Audio M2M class includes controls for audio memory-to-memory
+use cases. The controls can be used for audio codecs, audio
+preprocessing, audio postprocessing.
+
+Audio M2M Control IDs
+---
+
+.. _audiom2m-control-id:
+
+``V4L2_CID_M2M_AUDIO_CLASS (class)``
+The Audio M2M class descriptor. Calling
+:ref:`VIDIOC_QUERYCTRL` for this control will
+return a description of this control class.
diff --git a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst 
b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst
index f9f73530a6be..e8475f9fd2cf 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst
@@ -480,6 +480,10 @@ still cause this situation.
   - 0xa5
   - The class containing colorimetry controls. These controls are
described in :ref:`colorimetry-controls`.
+* - ``V4L2_CTRL_CLASS_M2M_AUDIO``
+  - 0xa6
+  - The class containing audio m2m controls. These controls are
+   described in :ref:`audiom2m-controls`.
 
 Return Value
 
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c 
b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
index 8696eb1cdd61..2a85ea3dc92f 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
@@ -1242,6 +1242,9 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_COLORIMETRY_CLASS:return "Colorimetry Controls";
case V4L2_CID_COLORIMETRY_HDR10_CLL_INFO:   return "HDR10 
Content Light Info";
case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:  return "HDR10 
Mastering Display";
+
+   /* Audio M2M controls */
+   case V4L2_CID_M2M_AUDIO_CLASS:  return "Audio M2M Controls";
default:
return NULL;
}
@@ -1451,6 +1454,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_DETECT_CLASS:
case V4L2_CID_CODEC_STATELESS_CLASS:
case V4L2_CID_COLORIMETRY_CLASS:
+   case V4L2_CID_M2M_AUDIO_CLASS:
*type = V4L2_CTRL_TYPE_CTRL_CLASS;
/* You can neither read nor write these */
*flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 68db66d4aae8..7d318065a33d 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -30,6 +30,7 @@
 #define V4L2_CTRL_CLASS_DETECT 0x00a3  /* Detection controls */
 #define V4L2_CTRL_CLASS_CODEC_STATELESS 0x00a4 /* Stateless codecs 
controls */
 #define V4L2_CTRL_CLASS_COLORIMETRY0x00a5  /* Colorimetry controls 
*/
+#define V4L2_CTRL_CLASS_M2M_AUDIO  0x00a6  /* Audio M2M controls */
 
 /* User-class control IDs */
 
@@ -3485,6 +3486,9 @@ struct v4l2_ctrl_av1_film_grain {
__u8 reserved[4];
 };
 
+#define V4L2_CID_M2M_AUDIO_CLASS_BASE  (V4L2_CTRL_CLASS_M2M_AUDIO | 0x900)
+#define V4L2_CID_M2M_AUDIO_CLASS   (V4L2_CTRL_CLASS_M2M_AUDIO | 1)
+
 /* MPEG-compression definitions kept for backwards compatibility */
 #ifndef __KERNEL__
 #define V4L2_CTRL_CLASS_MPEGV4L2_CTRL_CLASS_CODEC
-- 
2.34.1



[PATCH v11 08/15] media: uapi: Define audio sample format fourcc type

2023-11-22 Thread Shengjiu Wang
The audio sample format definition is from alsa,
the header file is include/uapi/sound/asound.h, but
don't include this header file directly, because in
user space, there is another copy in alsa-lib.
There will be conflict in userspace for include
videodev2.h & asound.h and asoundlib.h

Here still use the fourcc format.

Signed-off-by: Shengjiu Wang 
---
 .../userspace-api/media/v4l/pixfmt-audio.rst  | 87 +++
 .../userspace-api/media/v4l/pixfmt.rst|  1 +
 drivers/media/v4l2-core/v4l2-ioctl.c  | 13 +++
 include/uapi/linux/videodev2.h| 23 +
 4 files changed, 124 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-audio.rst

diff --git a/Documentation/userspace-api/media/v4l/pixfmt-audio.rst 
b/Documentation/userspace-api/media/v4l/pixfmt-audio.rst
new file mode 100644
index ..04b4a7fbd8f4
--- /dev/null
+++ b/Documentation/userspace-api/media/v4l/pixfmt-audio.rst
@@ -0,0 +1,87 @@
+.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
+
+.. _pixfmt-audio:
+
+*
+Audio Formats
+*
+
+These formats are used for :ref:`audiomem2mem` interface only.
+
+.. tabularcolumns:: |p{5.8cm}|p{1.2cm}|p{10.3cm}|
+
+.. cssclass:: longtable
+
+.. flat-table:: Audio Format
+:header-rows:  1
+:stub-columns: 0
+:widths:   3 1 4
+
+* - Identifier
+  - Code
+  - Details
+* .. _V4L2-AUDIO-FMT-S8:
+
+  - ``V4L2_AUDIO_FMT_S8``
+  - 'S8'
+  - Corresponds to SNDRV_PCM_FORMAT_S8 in ALSA
+* .. _V4L2-AUDIO-FMT-S16-LE:
+
+  - ``V4L2_AUDIO_FMT_S16_LE``
+  - 'S16_LE'
+  - Corresponds to SNDRV_PCM_FORMAT_S16_LE in ALSA
+* .. _V4L2-AUDIO-FMT-U16-LE:
+
+  - ``V4L2_AUDIO_FMT_U16_LE``
+  - 'U16_LE'
+  - Corresponds to SNDRV_PCM_FORMAT_U16_LE in ALSA
+* .. _V4L2-AUDIO-FMT-S24-LE:
+
+  - ``V4L2_AUDIO_FMT_S24_LE``
+  - 'S24_LE'
+  - Corresponds to SNDRV_PCM_FORMAT_S24_LE in ALSA
+* .. _V4L2-AUDIO-FMT-U24-LE:
+
+  - ``V4L2_AUDIO_FMT_U24_LE``
+  - 'U24_LE'
+  - Corresponds to SNDRV_PCM_FORMAT_U24_LE in ALSA
+* .. _V4L2-AUDIO-FMT-S32-LE:
+
+  - ``V4L2_AUDIO_FMT_S32_LE``
+  - 'S32_LE'
+  - Corresponds to SNDRV_PCM_FORMAT_S32_LE in ALSA
+* .. _V4L2-AUDIO-FMT-U32-LE:
+
+  - ``V4L2_AUDIO_FMT_U32_LE``
+  - 'U32_LE'
+  - Corresponds to SNDRV_PCM_FORMAT_U32_LE in ALSA
+* .. _V4L2-AUDIO-FMT-FLOAT-LE:
+
+  - ``V4L2_AUDIO_FMT_FLOAT_LE``
+  - 'FLOAT_LE'
+  - Corresponds to SNDRV_PCM_FORMAT_FLOAT_LE in ALSA
+* .. _V4L2-AUDIO-FMT-IEC958-SUBFRAME-LE:
+
+  - ``V4L2_AUDIO_FMT_IEC958_SUBFRAME_LE``
+  - 'IEC958_SUBFRAME_LE'
+  - Corresponds to SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE in ALSA
+* .. _V4L2-AUDIO-FMT-S24-3LE:
+
+  - ``V4L2_AUDIO_FMT_S24_3LE``
+  - 'S24_3LE'
+  - Corresponds to SNDRV_PCM_FORMAT_S24_3LE in ALSA
+* .. _V4L2-AUDIO-FMT-U24-3LE:
+
+  - ``V4L2_AUDIO_FMT_U24_3LE``
+  - 'U24_3LE'
+  - Corresponds to SNDRV_PCM_FORMAT_U24_3LE in ALSA
+* .. _V4L2-AUDIO-FMT-S20-3LE:
+
+  - ``V4L2_AUDIO_FMT_S20_3LE``
+  - 'S20_3LE'
+  - Corresponds to SNDRV_PCM_FORMAT_S24_3LE in ALSA
+* .. _V4L2-AUDIO-FMT-U20-3LE:
+
+  - ``V4L2_AUDIO_FMT_U20_3LE``
+  - 'U20_3LE'
+  - Corresponds to SNDRV_PCM_FORMAT_U20_3LE in ALSA
diff --git a/Documentation/userspace-api/media/v4l/pixfmt.rst 
b/Documentation/userspace-api/media/v4l/pixfmt.rst
index 11dab4a90630..2eb6fdd3b43d 100644
--- a/Documentation/userspace-api/media/v4l/pixfmt.rst
+++ b/Documentation/userspace-api/media/v4l/pixfmt.rst
@@ -36,3 +36,4 @@ see also :ref:`VIDIOC_G_FBUF `.)
 colorspaces
 colorspaces-defs
 colorspaces-details
+pixfmt-audio
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 1bb03794922a..c86633b82038 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1471,6 +1471,19 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_Y210: descr = "10-bit YUYV Packed"; break;
case V4L2_PIX_FMT_Y212: descr = "12-bit YUYV Packed"; break;
case V4L2_PIX_FMT_Y216: descr = "16-bit YUYV Packed"; break;
+   case V4L2_AUDIO_FMT_S8: descr = "8-bit Signed"; break;
+   case V4L2_AUDIO_FMT_S16_LE: descr = "16-bit Signed LE"; break;
+   case V4L2_AUDIO_FMT_U16_LE: descr = "16-bit Unsigned LE"; 
break;
+   case V4L2_AUDIO_FMT_S24_LE: descr = "24(32)-bit Signed LE"; 
break;
+   case V4L2_AUDIO_FMT_U24_LE: descr = "24(32)-bit Unsigned 
LE"; break;
+   case V4L2_AUDIO_FMT_S32_LE: descr = "32-bit Signed LE"; 
break;
+   case V4L2_AUDIO_FMT_U32_LE: descr = "32-bit Unsigned LE"; 
break;
+   case V4L2_AUDIO_FMT_FLOAT_LE:   descr = "32-bit Float LE"; 
break;
+   case V4L2_AUDIO_FMT_IEC958_SUBFRAME_LE: descr = 

[PATCH v11 07/15] media: v4l2: Add audio capture and output support

2023-11-22 Thread Shengjiu Wang
Audio signal processing has the requirement for memory to
memory similar as Video.

This patch is to add this support in v4l2 framework, defined
new buffer type V4L2_BUF_TYPE_AUDIO_CAPTURE and
V4L2_BUF_TYPE_AUDIO_OUTPUT, defined new format v4l2_audio_format
for audio case usage.

The created audio device is named "/dev/v4l-audioX".

Signed-off-by: Shengjiu Wang 
---
 .../userspace-api/media/v4l/buffer.rst|  6 ++
 .../media/v4l/dev-audio-mem2mem.rst   | 71 +++
 .../userspace-api/media/v4l/devices.rst   |  1 +
 .../media/v4l/vidioc-enum-fmt.rst |  2 +
 .../userspace-api/media/v4l/vidioc-g-fmt.rst  |  4 ++
 .../media/videodev2.h.rst.exceptions  |  2 +
 .../media/common/videobuf2/videobuf2-v4l2.c   |  4 ++
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c |  9 +++
 drivers/media/v4l2-core/v4l2-dev.c| 17 +
 drivers/media/v4l2-core/v4l2-ioctl.c  | 53 ++
 include/media/v4l2-dev.h  |  2 +
 include/media/v4l2-ioctl.h| 34 +
 include/uapi/linux/videodev2.h| 17 +
 13 files changed, 222 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rst

diff --git a/Documentation/userspace-api/media/v4l/buffer.rst 
b/Documentation/userspace-api/media/v4l/buffer.rst
index 52bbee81c080..a3754ca6f0d6 100644
--- a/Documentation/userspace-api/media/v4l/buffer.rst
+++ b/Documentation/userspace-api/media/v4l/buffer.rst
@@ -438,6 +438,12 @@ enum v4l2_buf_type
 * - ``V4L2_BUF_TYPE_META_OUTPUT``
   - 14
   - Buffer for metadata output, see :ref:`metadata`.
+* - ``V4L2_BUF_TYPE_AUDIO_CAPTURE``
+  - 15
+  - Buffer for audio capture, see :ref:`audio`.
+* - ``V4L2_BUF_TYPE_AUDIO_OUTPUT``
+  - 16
+  - Buffer for audio output, see :ref:`audio`.
 
 
 .. _buffer-flags:
diff --git a/Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rst 
b/Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rst
new file mode 100644
index ..68faecfe3a02
--- /dev/null
+++ b/Documentation/userspace-api/media/v4l/dev-audio-mem2mem.rst
@@ -0,0 +1,71 @@
+.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
+
+.. _audiomem2mem:
+
+
+Audio Memory-To-Memory Interface
+
+
+An audio memory-to-memory device can compress, decompress, transform, or
+otherwise convert audio data from one format into another format, in memory.
+Such memory-to-memory devices set the ``V4L2_CAP_AUDIO_M2M`` capability.
+Examples of memory-to-memory devices are audio codecs, audio preprocessing,
+audio postprocessing.
+
+A memory-to-memory audio node supports both output (sending audio frames from
+memory to the hardware) and capture (receiving the processed audio frames
+from the hardware into memory) stream I/O. An application will have to
+setup the stream I/O for both sides and finally call
+:ref:`VIDIOC_STREAMON ` for both capture and output to
+start the hardware.
+
+Memory-to-memory devices function as a shared resource: you can
+open the audio node multiple times, each application setting up their
+own properties that are local to the file handle, and each can use
+it independently from the others. The driver will arbitrate access to
+the hardware and reprogram it whenever another file handler gets access.
+
+Audio memory-to-memory devices are accessed through character device
+special files named ``/dev/v4l-audio``
+
+Querying Capabilities
+=
+
+Device nodes supporting the audio memory-to-memory interface set the
+``V4L2_CAP_AUDIO_M2M`` flag in the ``device_caps`` field of the
+:c:type:`v4l2_capability` structure returned by the :c:func:`VIDIOC_QUERYCAP`
+ioctl.
+
+Data Format Negotiation
+===
+
+The audio device uses the :ref:`format` ioctls to select the capture format.
+The audio buffer content format is bound to that selected format. In addition
+to the basic :ref:`format` ioctls, the :c:func:`VIDIOC_ENUM_FMT` ioctl must be
+supported as well.
+
+To use the :ref:`format` ioctls applications set the ``type`` field of the
+:c:type:`v4l2_format` structure to ``V4L2_BUF_TYPE_AUDIO_CAPTURE`` or to
+``V4L2_BUF_TYPE_AUDIO_OUTPUT``. Both drivers and applications must set the
+remainder of the :c:type:`v4l2_format` structure to 0.
+
+.. c:type:: v4l2_audio_format
+
+.. tabularcolumns:: |p{1.4cm}|p{2.4cm}|p{13.5cm}|
+
+.. flat-table:: struct v4l2_audio_format
+:header-rows:  0
+:stub-columns: 0
+:widths:   1 1 2
+
+* - __u32
+  - ``pixelformat``
+  - The sample format, set by the application. see :ref:`pixfmt-audio`
+* - __u32
+  - ``channels``
+  - The channel number, set by the application. channel number range is
+[1, 32].
+* - __u32
+  - ``buffersize``
+  - Maximum buffer size in bytes required for data. The value is set by the
+driver.
diff --git 

[PATCH v11 06/15] media: uapi: Add V4L2_CAP_AUDIO_M2M capability flag

2023-11-22 Thread Shengjiu Wang
V4L2_CAP_AUDIO_M2M is similar to V4L2_CAP_VIDEO_M2M flag.

It is used for audio memory to memory case.

Signed-off-by: Shengjiu Wang 
---
 Documentation/userspace-api/media/v4l/vidioc-querycap.rst| 3 +++
 Documentation/userspace-api/media/videodev2.h.rst.exceptions | 1 +
 include/uapi/linux/videodev2.h   | 1 +
 3 files changed, 5 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/vidioc-querycap.rst 
b/Documentation/userspace-api/media/v4l/vidioc-querycap.rst
index 6c57b8428356..1c0d97bf192a 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-querycap.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-querycap.rst
@@ -173,6 +173,9 @@ specification the ioctl returns an ``EINVAL`` error code.
interface. A video overlay device typically stores captured images
directly in the video memory of a graphics card, with hardware
clipping and scaling.
+* - ``V4L2_CAP_AUDIO_M2M``
+  - 0x0008
+  - The device supports the audio Memory-To-Memory interface.
 * - ``V4L2_CAP_VBI_CAPTURE``
   - 0x0010
   - The device supports the :ref:`Raw VBI Capture `
diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions 
b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
index 3e58aac4ef0b..da6d0b8e4c2c 100644
--- a/Documentation/userspace-api/media/videodev2.h.rst.exceptions
+++ b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
@@ -197,6 +197,7 @@ replace define V4L2_CAP_META_OUTPUT device-capabilities
 replace define V4L2_CAP_DEVICE_CAPS device-capabilities
 replace define V4L2_CAP_TOUCH device-capabilities
 replace define V4L2_CAP_IO_MC device-capabilities
+replace define V4L2_CAP_AUDIO_M2M device-capabilities
 
 # V4L2 pix flags
 replace define V4L2_PIX_FMT_PRIV_MAGIC :c:type:`v4l2_pix_format`
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 3813212a5cd3..eb5911719734 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -473,6 +473,7 @@ struct v4l2_capability {
 #define V4L2_CAP_VIDEO_CAPTURE 0x0001  /* Is a video capture 
device */
 #define V4L2_CAP_VIDEO_OUTPUT  0x0002  /* Is a video output device 
*/
 #define V4L2_CAP_VIDEO_OVERLAY 0x0004  /* Can do video overlay */
+#define V4L2_CAP_AUDIO_M2M 0x0008  /* audio memory to memory */
 #define V4L2_CAP_VBI_CAPTURE   0x0010  /* Is a raw VBI capture 
device */
 #define V4L2_CAP_VBI_OUTPUT0x0020  /* Is a raw VBI output 
device */
 #define V4L2_CAP_SLICED_VBI_CAPTURE0x0040  /* Is a sliced VBI capture 
device */
-- 
2.34.1



[PATCH v11 05/15] ASoC: fsl_easrc: register m2m platform device

2023-11-22 Thread Shengjiu Wang
Register m2m platform device,that user can
use M2M feature.

Signed-off-by: Shengjiu Wang 
Acked-by: Mark Brown 
---
 sound/soc/fsl/fsl_easrc.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c
index cf7ad30a323b..ccbf45c7abf4 100644
--- a/sound/soc/fsl/fsl_easrc.c
+++ b/sound/soc/fsl/fsl_easrc.c
@@ -2075,6 +2075,7 @@ MODULE_DEVICE_TABLE(of, fsl_easrc_dt_ids);
 static int fsl_easrc_probe(struct platform_device *pdev)
 {
struct fsl_easrc_priv *easrc_priv;
+   struct fsl_asrc_m2m_pdata m2m_pdata;
struct device *dev = >dev;
struct fsl_asrc *easrc;
struct resource *res;
@@ -2190,6 +2191,19 @@ static int fsl_easrc_probe(struct platform_device *pdev)
goto err_pm_disable;
}
 
+   m2m_pdata.asrc = easrc;
+   m2m_pdata.fmt_in = FSL_EASRC_FORMATS;
+   m2m_pdata.fmt_out = FSL_EASRC_FORMATS | 
SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE;
+   m2m_pdata.rate_min = 8000;
+   m2m_pdata.rate_max = 768000;
+   m2m_pdata.chan_min = 1;
+   m2m_pdata.chan_max = 32;
+   easrc->m2m_pdev = platform_device_register_data(>dev,
+   M2M_DRV_NAME,
+   PLATFORM_DEVID_AUTO,
+   _pdata,
+   sizeof(m2m_pdata));
+
return 0;
 
 err_pm_disable:
@@ -2199,6 +2213,11 @@ static int fsl_easrc_probe(struct platform_device *pdev)
 
 static void fsl_easrc_remove(struct platform_device *pdev)
 {
+   struct fsl_asrc *easrc = dev_get_drvdata(>dev);
+
+   if (easrc->m2m_pdev && !IS_ERR(easrc->m2m_pdev))
+   platform_device_unregister(easrc->m2m_pdev);
+
pm_runtime_disable(>dev);
 }
 
-- 
2.34.1



[PATCH v11 04/15] ASoC: fsl_asrc: register m2m platform device

2023-11-22 Thread Shengjiu Wang
Register m2m platform device, that user can
use M2M feature.

Defined platform data structure and platform
driver name.

Signed-off-by: Shengjiu Wang 
Acked-by: Mark Brown 
---
 include/sound/fsl_asrc_common.h | 23 +++
 sound/soc/fsl/fsl_asrc.c| 18 ++
 2 files changed, 41 insertions(+)

diff --git a/include/sound/fsl_asrc_common.h b/include/sound/fsl_asrc_common.h
index 3b53d366182f..c709b8906929 100644
--- a/include/sound/fsl_asrc_common.h
+++ b/include/sound/fsl_asrc_common.h
@@ -71,6 +71,7 @@ struct fsl_asrc_pair {
  * @dma_params_rx: DMA parameters for receive channel
  * @dma_params_tx: DMA parameters for transmit channel
  * @pdev: platform device pointer
+ * @m2m_pdev: m2m platform device pointer
  * @regmap: regmap handler
  * @paddr: physical address to the base address of registers
  * @mem_clk: clock source to access register
@@ -103,6 +104,7 @@ struct fsl_asrc {
struct snd_dmaengine_dai_dma_data dma_params_rx;
struct snd_dmaengine_dai_dma_data dma_params_tx;
struct platform_device *pdev;
+   struct platform_device *m2m_pdev;
struct regmap *regmap;
unsigned long paddr;
struct clk *mem_clk;
@@ -139,6 +141,27 @@ struct fsl_asrc {
void *private;
 };
 
+/**
+ * struct fsl_asrc_m2m_pdata - platform data
+ * @asrc: pointer to struct fsl_asrc
+ * @fmt_in: input sample format
+ * @fmt_out: output sample format
+ * @chan_min: minimum channel number
+ * @chan_max: maximum channel number
+ * @rate_min: minimum rate
+ * @rate_max: maximum rete
+ */
+struct fsl_asrc_m2m_pdata {
+   struct fsl_asrc *asrc;
+   u64 fmt_in;
+   u64 fmt_out;
+   int chan_min;
+   int chan_max;
+   int rate_min;
+   int rate_max;
+};
+
+#define M2M_DRV_NAME "fsl_asrc_m2m"
 #define DRV_NAME "fsl-asrc-dai"
 extern struct snd_soc_component_driver fsl_asrc_component;
 
diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index 7d8643ee0ba0..5ecb5d869607 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -1187,6 +1187,7 @@ static int fsl_asrc_runtime_suspend(struct device *dev);
 static int fsl_asrc_probe(struct platform_device *pdev)
 {
struct device_node *np = pdev->dev.of_node;
+   struct fsl_asrc_m2m_pdata m2m_pdata;
struct fsl_asrc_priv *asrc_priv;
struct fsl_asrc *asrc;
struct resource *res;
@@ -1368,6 +1369,18 @@ static int fsl_asrc_probe(struct platform_device *pdev)
goto err_pm_get_sync;
}
 
+   m2m_pdata.asrc = asrc;
+   m2m_pdata.fmt_in = FSL_ASRC_FORMATS;
+   m2m_pdata.fmt_out = FSL_ASRC_FORMATS | SNDRV_PCM_FMTBIT_S8;
+   m2m_pdata.rate_min = 5512;
+   m2m_pdata.rate_max = 192000;
+   m2m_pdata.chan_min = 1;
+   m2m_pdata.chan_max = 10;
+   asrc->m2m_pdev = platform_device_register_data(>dev,
+  M2M_DRV_NAME,
+  PLATFORM_DEVID_AUTO,
+  _pdata,
+  sizeof(m2m_pdata));
return 0;
 
 err_pm_get_sync:
@@ -1380,6 +1393,11 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 
 static void fsl_asrc_remove(struct platform_device *pdev)
 {
+   struct fsl_asrc *asrc = dev_get_drvdata(>dev);
+
+   if (asrc->m2m_pdev && !IS_ERR(asrc->m2m_pdev))
+   platform_device_unregister(asrc->m2m_pdev);
+
pm_runtime_disable(>dev);
if (!pm_runtime_status_suspended(>dev))
fsl_asrc_runtime_suspend(>dev);
-- 
2.34.1



[PATCH v11 03/15] ASoC: fsl_asrc: move fsl_asrc_common.h to include/sound

2023-11-22 Thread Shengjiu Wang
Move fsl_asrc_common.h to include/sound that it can be
included from other drivers.

Signed-off-by: Shengjiu Wang 
Acked-by: Mark Brown 
---
 {sound/soc/fsl => include/sound}/fsl_asrc_common.h | 0
 sound/soc/fsl/fsl_asrc.h   | 2 +-
 sound/soc/fsl/fsl_asrc_dma.c   | 2 +-
 sound/soc/fsl/fsl_easrc.h  | 2 +-
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename {sound/soc/fsl => include/sound}/fsl_asrc_common.h (100%)

diff --git a/sound/soc/fsl/fsl_asrc_common.h b/include/sound/fsl_asrc_common.h
similarity index 100%
rename from sound/soc/fsl/fsl_asrc_common.h
rename to include/sound/fsl_asrc_common.h
diff --git a/sound/soc/fsl/fsl_asrc.h b/sound/soc/fsl/fsl_asrc.h
index 1c492eb237f5..66544624de7b 100644
--- a/sound/soc/fsl/fsl_asrc.h
+++ b/sound/soc/fsl/fsl_asrc.h
@@ -10,7 +10,7 @@
 #ifndef _FSL_ASRC_H
 #define _FSL_ASRC_H
 
-#include  "fsl_asrc_common.h"
+#include  
 
 #define ASRC_M2M_INPUTFIFO_WML 0x4
 #define ASRC_M2M_OUTPUTFIFO_WML0x2
diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c
index f501f47242fb..f067bf1ecea7 100644
--- a/sound/soc/fsl/fsl_asrc_dma.c
+++ b/sound/soc/fsl/fsl_asrc_dma.c
@@ -12,7 +12,7 @@
 #include 
 #include 
 
-#include "fsl_asrc_common.h"
+#include 
 
 #define FSL_ASRC_DMABUF_SIZE   (256 * 1024)
 
diff --git a/sound/soc/fsl/fsl_easrc.h b/sound/soc/fsl/fsl_easrc.h
index c9f770862662..a24e540876a4 100644
--- a/sound/soc/fsl/fsl_easrc.h
+++ b/sound/soc/fsl/fsl_easrc.h
@@ -9,7 +9,7 @@
 #include 
 #include 
 
-#include "fsl_asrc_common.h"
+#include 
 
 /* EASRC Register Map */
 
-- 
2.34.1



[PATCH v11 01/15] ASoC: fsl_asrc: define functions for memory to memory usage

2023-11-22 Thread Shengjiu Wang
ASRC can be used on memory to memory case, define several
functions for m2m usage.

m2m_prepare: prepare for the start step
m2m_start: the start step
m2m_unprepare: unprepare for stop step, optional
m2m_stop: stop step
m2m_check_format: check format is supported or not
m2m_calc_out_len: calculate output length according to input length
m2m_get_maxburst: burst size for dma
m2m_pair_suspend: suspend function of pair, optional.
m2m_pair_resume: resume function of pair
get_output_fifo_size: get remaining data size in FIFO

Signed-off-by: Shengjiu Wang 
Acked-by: Mark Brown 
---
 sound/soc/fsl/fsl_asrc.c| 126 
 sound/soc/fsl/fsl_asrc.h|   2 +
 sound/soc/fsl/fsl_asrc_common.h |  37 ++
 3 files changed, 165 insertions(+)

diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index b793263291dc..7d8643ee0ba0 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -1063,6 +1063,124 @@ static int fsl_asrc_get_fifo_addr(u8 dir, enum 
asrc_pair_index index)
return REG_ASRDx(dir, index);
 }
 
+/* Get sample numbers in FIFO */
+static unsigned int fsl_asrc_get_output_fifo_size(struct fsl_asrc_pair *pair)
+{
+   struct fsl_asrc *asrc = pair->asrc;
+   enum asrc_pair_index index = pair->index;
+   u32 val;
+
+   regmap_read(asrc->regmap, REG_ASRFST(index), );
+
+   val &= ASRFSTi_OUTPUT_FIFO_MASK;
+
+   return val >> ASRFSTi_OUTPUT_FIFO_SHIFT;
+}
+
+static int fsl_asrc_m2m_prepare(struct fsl_asrc_pair *pair)
+{
+   struct fsl_asrc_pair_priv *pair_priv = pair->private;
+   struct fsl_asrc *asrc = pair->asrc;
+   struct device *dev = >pdev->dev;
+   struct asrc_config config;
+   int ret;
+
+   /* fill config */
+   config.pair = pair->index;
+   config.channel_num = pair->channels;
+   config.input_sample_rate = pair->rate[IN];
+   config.output_sample_rate = pair->rate[OUT];
+   config.input_format = pair->sample_format[IN];
+   config.output_format = pair->sample_format[OUT];
+   config.inclk = INCLK_NONE;
+   config.outclk = OUTCLK_ASRCK1_CLK;
+
+   pair_priv->config = 
+   ret = fsl_asrc_config_pair(pair, true);
+   if (ret) {
+   dev_err(dev, "failed to config pair: %d\n", ret);
+   return ret;
+   }
+
+   pair->first_convert = 1;
+
+   return 0;
+}
+
+static int fsl_asrc_m2m_start(struct fsl_asrc_pair *pair)
+{
+   if (pair->first_convert) {
+   fsl_asrc_start_pair(pair);
+   pair->first_convert = 0;
+   }
+   /*
+* Clear DMA request during the stall state of ASRC:
+* During STALL state, the remaining in input fifo would never be
+* smaller than the input threshold while the output fifo would not
+* be bigger than output one. Thus the DMA request would be cleared.
+*/
+   fsl_asrc_set_watermarks(pair, ASRC_FIFO_THRESHOLD_MIN,
+   ASRC_FIFO_THRESHOLD_MAX);
+
+   /* Update the real input threshold to raise DMA request */
+   fsl_asrc_set_watermarks(pair, ASRC_M2M_INPUTFIFO_WML,
+   ASRC_M2M_OUTPUTFIFO_WML);
+
+   return 0;
+}
+
+static int fsl_asrc_m2m_stop(struct fsl_asrc_pair *pair)
+{
+   if (!pair->first_convert) {
+   fsl_asrc_stop_pair(pair);
+   pair->first_convert = 1;
+   }
+
+   return 0;
+}
+
+/* calculate capture data length according to output data length and sample 
rate */
+static int fsl_asrc_m2m_calc_out_len(struct fsl_asrc_pair *pair, int 
input_buffer_length)
+{
+   unsigned int in_width, out_width;
+   unsigned int channels = pair->channels;
+   unsigned int in_samples, out_samples;
+   unsigned int out_length;
+
+   in_width = snd_pcm_format_physical_width(pair->sample_format[IN]) / 8;
+   out_width = snd_pcm_format_physical_width(pair->sample_format[OUT]) / 8;
+
+   in_samples = input_buffer_length / in_width / channels;
+   out_samples = pair->rate[OUT] * in_samples / pair->rate[IN];
+   out_length = (out_samples - ASRC_OUTPUT_LAST_SAMPLE) * out_width * 
channels;
+
+   return out_length;
+}
+
+static int fsl_asrc_m2m_get_maxburst(u8 dir, struct fsl_asrc_pair *pair)
+{
+   struct fsl_asrc *asrc = pair->asrc;
+   struct fsl_asrc_priv *asrc_priv = asrc->private;
+   int wml = (dir == IN) ? ASRC_M2M_INPUTFIFO_WML : 
ASRC_M2M_OUTPUTFIFO_WML;
+
+   if (!asrc_priv->soc->use_edma)
+   return wml * pair->channels;
+   else
+   return 1;
+}
+
+static int fsl_asrc_m2m_pair_resume(struct fsl_asrc_pair *pair)
+{
+   struct fsl_asrc *asrc = pair->asrc;
+   int i;
+
+   for (i = 0; i < pair->channels * 4; i++)
+   regmap_write(asrc->regmap, REG_ASRDI(pair->index), 0);
+
+   pair->first_convert = 1;
+   return 0;
+}
+
 static int fsl_asrc_runtime_resume(struct device *dev);
 static int 

[PATCH v11 02/15] ASoC: fsl_easrc: define functions for memory to memory usage

2023-11-22 Thread Shengjiu Wang
ASRC can be used on memory to memory case, define several
functions for m2m usage and export them as function pointer.

Signed-off-by: Shengjiu Wang 
Acked-by: Mark Brown 
---
 sound/soc/fsl/fsl_easrc.c | 214 ++
 sound/soc/fsl/fsl_easrc.h |   4 +
 2 files changed, 218 insertions(+)

diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c
index ec53bda46a46..cf7ad30a323b 100644
--- a/sound/soc/fsl/fsl_easrc.c
+++ b/sound/soc/fsl/fsl_easrc.c
@@ -1861,6 +1861,211 @@ static int fsl_easrc_get_fifo_addr(u8 dir, enum 
asrc_pair_index index)
return REG_EASRC_FIFO(dir, index);
 }
 
+/* Get sample numbers in FIFO */
+static unsigned int fsl_easrc_get_output_fifo_size(struct fsl_asrc_pair *pair)
+{
+   struct fsl_asrc *asrc = pair->asrc;
+   enum asrc_pair_index index = pair->index;
+   u32 val;
+
+   regmap_read(asrc->regmap, REG_EASRC_SFS(index), );
+   val &= EASRC_SFS_NSGO_MASK;
+
+   return val >> EASRC_SFS_NSGO_SHIFT;
+}
+
+static int fsl_easrc_m2m_prepare(struct fsl_asrc_pair *pair)
+{
+   struct fsl_easrc_ctx_priv *ctx_priv = pair->private;
+   struct fsl_asrc *asrc = pair->asrc;
+   struct device *dev = >pdev->dev;
+   int ret;
+
+   ctx_priv->in_params.sample_rate = pair->rate[IN];
+   ctx_priv->in_params.sample_format = pair->sample_format[IN];
+   ctx_priv->out_params.sample_rate = pair->rate[OUT];
+   ctx_priv->out_params.sample_format = pair->sample_format[OUT];
+
+   ctx_priv->in_params.fifo_wtmk = FSL_EASRC_INPUTFIFO_WML;
+   ctx_priv->out_params.fifo_wtmk = FSL_EASRC_OUTPUTFIFO_WML;
+   /* Fill the right half of the re-sampler with zeros */
+   ctx_priv->rs_init_mode = 0x2;
+   /* Zero fill the right half of the prefilter */
+   ctx_priv->pf_init_mode = 0x2;
+
+   ret = fsl_easrc_set_ctx_format(pair,
+  _priv->in_params.sample_format,
+  _priv->out_params.sample_format);
+   if (ret) {
+   dev_err(dev, "failed to set context format: %d\n", ret);
+   return ret;
+   }
+
+   ret = fsl_easrc_config_context(asrc, pair->index);
+   if (ret) {
+   dev_err(dev, "failed to config context %d\n", ret);
+   return ret;
+   }
+
+   ctx_priv->in_params.iterations = 1;
+   ctx_priv->in_params.group_len = pair->channels;
+   ctx_priv->in_params.access_len = pair->channels;
+   ctx_priv->out_params.iterations = 1;
+   ctx_priv->out_params.group_len = pair->channels;
+   ctx_priv->out_params.access_len = pair->channels;
+
+   ret = fsl_easrc_set_ctx_organziation(pair);
+   if (ret) {
+   dev_err(dev, "failed to set fifo organization\n");
+   return ret;
+   }
+
+   /* The context start flag */
+   pair->first_convert = 1;
+   return 0;
+}
+
+static int fsl_easrc_m2m_start(struct fsl_asrc_pair *pair)
+{
+   /* start context once */
+   if (pair->first_convert) {
+   fsl_easrc_start_context(pair);
+   pair->first_convert = 0;
+   }
+
+   return 0;
+}
+
+static int fsl_easrc_m2m_stop(struct fsl_asrc_pair *pair)
+{
+   /* Stop pair/context */
+   if (!pair->first_convert) {
+   fsl_easrc_stop_context(pair);
+   pair->first_convert = 1;
+   }
+
+   return 0;
+}
+
+/* calculate capture data length according to output data length and sample 
rate */
+static int fsl_easrc_m2m_calc_out_len(struct fsl_asrc_pair *pair, int 
input_buffer_length)
+{
+   struct fsl_asrc *easrc = pair->asrc;
+   struct fsl_easrc_priv *easrc_priv = easrc->private;
+   struct fsl_easrc_ctx_priv *ctx_priv = pair->private;
+   unsigned int in_rate = ctx_priv->in_params.norm_rate;
+   unsigned int out_rate = ctx_priv->out_params.norm_rate;
+   unsigned int channels = pair->channels;
+   unsigned int in_samples, out_samples;
+   unsigned int in_width, out_width;
+   unsigned int out_length;
+   unsigned int frac_bits;
+   u64 val1, val2;
+
+   switch (easrc_priv->rs_num_taps) {
+   case EASRC_RS_32_TAPS:
+   /* integer bits = 5; */
+   frac_bits = 39;
+   break;
+   case EASRC_RS_64_TAPS:
+   /* integer bits = 6; */
+   frac_bits = 38;
+   break;
+   case EASRC_RS_128_TAPS:
+   /* integer bits = 7; */
+   frac_bits = 37;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   val1 = (u64)in_rate << frac_bits;
+   do_div(val1, out_rate);
+   val1 += (s64)ctx_priv->ratio_mod << (frac_bits - 31);
+
+   in_width = 
snd_pcm_format_physical_width(ctx_priv->in_params.sample_format) / 8;
+   out_width = 
snd_pcm_format_physical_width(ctx_priv->out_params.sample_format) / 8;
+
+   ctx_priv->in_filled_len += input_buffer_length;
+   

[PATCH v11 00/15] Add audio support in v4l2 framework

2023-11-22 Thread Shengjiu Wang
Audio signal processing also has the requirement for memory to
memory similar as Video.

This asrc memory to memory (memory ->asrc->memory) case is a non
real time use case.

User fills the input buffer to the asrc module, after conversion, then asrc
sends back the output buffer to user. So it is not a traditional ALSA playback
and capture case.

It is a specific use case,  there is no reference in current kernel.
v4l2 memory to memory is the closed implementation,  v4l2 current
support video, image, radio, tuner, touch devices, so it is not
complicated to add support for this specific audio case.

Because we had implemented the "memory -> asrc ->i2s device-> codec"
use case in ALSA.  Now the "memory->asrc->memory" needs
to reuse the code in asrc driver, so the first 3 patches is for refining
the code to make it can be shared by the "memory->asrc->memory"
driver.

The main change is in the v4l2 side, A /dev/vl4-audioX will be created,
user applications only use the ioctl of v4l2 framework.

Other change is to add memory to memory support for two kinds of i.MX ASRC
module.

changes in v11
- add add-fixed-point-test-controls in vivid.
- add v4l2_ctrl_fp_compose() helper function for min and max

changes in v10
- remove FIXED_POINT type
- change code base on media: v4l2-ctrls: add support for fraction_bits
- fix issue reported by kernel test robot
- remove module_alias

changes in v9:
- add MEDIA_ENT_F_PROC_AUDIO_RESAMPLER.
- add MEDIA_INTF_T_V4L_AUDIO
- add media controller support
- refine the vim2m-audio to support 8k<->16k conversion.

changes in v8:
- refine V4L2_CAP_AUDIO_M2M to be 0x0008
- update doc for FIXED_POINT
- address comments for imx-asrc

changes in v7:
- add acked-by from Mark
- separate commit for fixed point, m2m audio class, audio rate controls
- use INTEGER_MENU for rate,  FIXED_POINT for rate offset
- remove used fmts
- address other comments for Hans

changes in v6:
- use m2m_prepare/m2m_unprepare/m2m_start/m2m_stop to replace
  m2m_start_part_one/m2m_stop_part_one, m2m_start_part_two/m2m_stop_part_two.
- change V4L2_CTRL_TYPE_ASRC_RATE to V4L2_CTRL_TYPE_FIXED_POINT
- fix warning by kernel test rebot
- remove some unused format V4L2_AUDIO_FMT_XX
- Get SNDRV_PCM_FORMAT from V4L2_AUDIO_FMT in driver.
- rename audm2m to viaudm2m.

changes in v5:
- remove V4L2_AUDIO_FMT_LPCM
- define audio pixel format like V4L2_AUDIO_FMT_S8...
- remove rate and format in struct v4l2_audio_format.
- Add V4L2_CID_ASRC_SOURCE_RATE and V4L2_CID_ASRC_DEST_RATE controls
- updata document accordingly.

changes in v4:
- update document style
- separate V4L2_AUDIO_FMT_LPCM and V4L2_CAP_AUDIO_M2M in separate commit

changes in v3:
- Modify documents for adding audio m2m support
- Add audio virtual m2m driver
- Defined V4L2_AUDIO_FMT_LPCM format type for audio.
- Defined V4L2_CAP_AUDIO_M2M capability type for audio m2m case.
- with modification in v4l-utils, pass v4l2-compliance test.

changes in v2:
- decouple the implementation in v4l2 and ALSA
- implement the memory to memory driver as a platfrom driver
  and move it to driver/media
- move fsl_asrc_common.h to include/sound folder

Shengjiu Wang (15):
  ASoC: fsl_asrc: define functions for memory to memory usage
  ASoC: fsl_easrc: define functions for memory to memory usage
  ASoC: fsl_asrc: move fsl_asrc_common.h to include/sound
  ASoC: fsl_asrc: register m2m platform device
  ASoC: fsl_easrc: register m2m platform device
  media: uapi: Add V4L2_CAP_AUDIO_M2M capability flag
  media: v4l2: Add audio capture and output support
  media: uapi: Define audio sample format fourcc type
  media: uapi: Add V4L2_CTRL_CLASS_M2M_AUDIO
  media: uapi: Add audio rate controls support
  media: uapi: Declare interface types for Audio
  media: uapi: Add an entity type for audio resampler
  media: vivid: add fixed point test controls
  media: imx-asrc: Add memory to memory driver
  media: vim2m-audio: add virtual driver for audio memory to memory

 .../media/mediactl/media-types.rst|   11 +
 .../userspace-api/media/v4l/buffer.rst|6 +
 .../userspace-api/media/v4l/common.rst|1 +
 .../media/v4l/dev-audio-mem2mem.rst   |   71 +
 .../userspace-api/media/v4l/devices.rst   |1 +
 .../media/v4l/ext-ctrls-audio-m2m.rst |   41 +
 .../userspace-api/media/v4l/pixfmt-audio.rst  |   87 ++
 .../userspace-api/media/v4l/pixfmt.rst|1 +
 .../media/v4l/vidioc-enum-fmt.rst |2 +
 .../media/v4l/vidioc-g-ext-ctrls.rst  |4 +
 .../userspace-api/media/v4l/vidioc-g-fmt.rst  |4 +
 .../media/v4l/vidioc-querycap.rst |3 +
 .../media/videodev2.h.rst.exceptions  |3 +
 .../media/common/videobuf2/videobuf2-v4l2.c   |4 +
 drivers/media/platform/nxp/Kconfig|   13 +
 drivers/media/platform/nxp/Makefile   |1 +
 drivers/media/platform/nxp/imx-asrc.c | 1264 +
 drivers/media/test-drivers/Kconfig|   11 +
 

Re: [PATCH RFC 06/12] mm/gup: Drop folio_fast_pin_allowed() in hugepd processing

2023-11-22 Thread Christoph Hellwig
On Tue, Nov 21, 2023 at 10:59:35AM -0500, Peter Xu wrote:
> > What prevents us from ever using hugepd with file mappings?  I think
> > it would naturally fit in with how large folios for the pagecache work.
> > 
> > So keeping this check and generalizing it seems like the better idea to
> > me.
> 
> But then it means we're still keeping that dead code for fast-gup even if
> we know that fact..  Or do we have a plan to add that support very soon, so
> this code will be destined to add back?

The question wasn't mean retorical - we support arbitrary power of two
sized folios for the pagepage, what prevents us from using hugepd with
them right now?

> The other option is I can always add a comment above gup_huge_pd()
> explaining this special bit, so that when someone is adding hugepd support
> to file large folios we'll hopefully not forget it?  But then that
> generalization work will only happen when the code will be needed.

If dropping the check is the right thing for now (and I think the ppc
maintainers and willy as the large folio guy might have a more useful
opinions than I do), leaving a comment in would be very useful.