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

2023-11-09 Thread kernel test robot
Hi Daniel,

kernel test robot noticed the following build warnings:

[auto build test WARNING on v6.6]
[cannot apply to arm64/for-next/core efi/next tip/x86/core robh/for-next 
linus/master next-20231110]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Daniel-Walker/CMDLINE-add-generic-builtin-command-line/20231110-094423
base:   v6.6
patch link:
https://lore.kernel.org/r/20231110013817.2378507-7-danielwa%40cisco.com
patch subject: [PATCH 6/8] CMDLINE: x86: convert to generic builtin command line
config: x86_64-kismet-CONFIG_SYSTEM_EXTRA_CERTIFICATE-CONFIG_CMDLINE_EXTRA-0-0 
(https://download.01.org/0day-ci/archive/20231110/202311101507.q12gpuvs-...@intel.com/config)
reproduce: 
(https://download.01.org/0day-ci/archive/20231110/202311101507.q12gpuvs-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202311101507.q12gpuvs-...@intel.com/

kismet warnings: (new ones prefixed by >>)
>> kismet: WARNING: unmet direct dependencies detected for 
>> SYSTEM_EXTRA_CERTIFICATE when selected by CMDLINE_EXTRA
   
   WARNING: unmet direct dependencies detected for SYSTEM_EXTRA_CERTIFICATE
 Depends on [n]: CRYPTO [=y] && SYSTEM_TRUSTED_KEYRING [=n]
 Selected by [y]:
 - CMDLINE_EXTRA [=y] && GENERIC_CMDLINE [=y] && CMDLINE_BOOL [=y]

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


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

2023-11-09 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 ..0124368fe0be
--- /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 &ctx->q_data[V4L2_M2M_SRC];
+   return &ctx->q_data[V4L2_M2M_DST];
+}
+
+static const char *type_name(enum v4l2_buf_type type)
+{
+   if (type == V4L2_BUF_TYPE_AUDIO_OUTPUT)
+   return "Output";
+   

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

2023-11-09 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|   14 +
 drivers/media/platform/nxp/Makefile   |1 +
 drivers/media/platform/nxp/imx-asrc.c | 1235 +
 3 files changed, 1250 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..6d55977977d6 100644
--- a/drivers/media/platform/nxp/Kconfig
+++ b/drivers/media/platform/nxp/Kconfig
@@ -67,3 +67,17 @@ 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
+   select MEDIA_CONTROLLER_REQUEST_API
+   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 ..689e3cfa34d4
--- /dev/null
+++ b/drivers/media/platform/nxp/imx-asrc.c
@@ -0,0 +1,1235 @@
+// 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_form

[PATCH v9 13/15] media: uapi: Add an entity type for audio resampler

2023-11-09 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 | 5 +
 include/uapi/linux/media.h | 1 +
 2 files changed, 6 insertions(+)

diff --git a/Documentation/userspace-api/media/mediactl/media-types.rst 
b/Documentation/userspace-api/media/mediactl/media-types.rst
index 3f0bcb18a5ca..2977d8723f11 100644
--- a/Documentation/userspace-api/media/mediactl/media-types.rst
+++ b/Documentation/userspace-api/media/mediactl/media-types.rst
@@ -208,6 +208,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 v9 12/15] media: uapi: Declare interface types for Audio

2023-11-09 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|  4 
 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, 18 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..3f0bcb18a5ca 100644
--- a/Documentation/userspace-api/media/mediactl/media-types.rst
+++ b/Documentation/userspace-api/media/mediactl/media-types.rst
@@ -322,6 +322,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 v9 11/15] media: uapi: Add audio rate controls support

2023-11-09 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 | 12 +++
 include/uapi/linux/v4l2-controls.h|  5 +
 3 files changed, 37 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..b695cbdd1f6e 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
@@ -1245,6 +1245,10 @@ 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";
+   case V4L2_CID_M2M_AUDIO_SOURCE_RATE_OFFSET: return "Audio Source 
Sample Rate Offset";
+   case V4L2_CID_M2M_AUDIO_DEST_RATE_OFFSET:   return "Audio Dest 
Sample Rate Offset";
default:
return NULL;
}
@@ -1606,6 +1610,14 @@ 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;
+   case V4L2_CID_M2M_AUDIO_SOURCE_RATE_OFFSET:
+   case V4L2_CID_M2M_AUDIO_DEST_RATE_OFFSET:
+   *type = V4L2_CTRL_TYPE_FIXED_POINT;
+   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 v9 10/15] media: uapi: Add V4L2_CTRL_TYPE_FIXED_POINT

2023-11-09 Thread Shengjiu Wang
Fixed point controls are used by the user to configure
a fixed point value in 64bits, which Q31.32 format.

Signed-off-by: Shengjiu Wang 
---
 .../userspace-api/media/v4l/vidioc-g-ext-ctrls.rst  | 13 +++--
 .../userspace-api/media/v4l/vidioc-queryctrl.rst|  9 -
 .../userspace-api/media/videodev2.h.rst.exceptions  |  1 +
 drivers/media/v4l2-core/v4l2-ctrls-api.c|  5 -
 drivers/media/v4l2-core/v4l2-ctrls-core.c   |  2 ++
 include/uapi/linux/videodev2.h  |  1 +
 6 files changed, 23 insertions(+), 8 deletions(-)

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 e8475f9fd2cf..e7e5d78dc11e 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst
@@ -162,13 +162,13 @@ still cause this situation.
 * - __s32
   - ``value``
   - New value or current value. Valid if this control is not of type
-   ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
-   not set.
+   ``V4L2_CTRL_TYPE_INTEGER64``, ``V4L2_CTRL_TYPE_FIXED_POINT`` and
+   ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is not set.
 * - __s64
   - ``value64``
   - New value or current value. Valid if this control is of type
-   ``V4L2_CTRL_TYPE_INTEGER64`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is
-   not set.
+   ``V4L2_CTRL_TYPE_INTEGER64``, ``V4L2_CTRL_TYPE_FIXED_POINT`` and
+   ``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is not set.
 * - char *
   - ``string``
   - A pointer to a string. Valid if this control is of type
@@ -193,8 +193,9 @@ still cause this situation.
 * - __s64 *
   - ``p_s64``
   - A pointer to a matrix control of signed 64-bit values. Valid if
-this control is of type ``V4L2_CTRL_TYPE_INTEGER64`` and
-``V4L2_CTRL_FLAG_HAS_PAYLOAD`` is set.
+this control is of type ``V4L2_CTRL_TYPE_INTEGER64``,
+``V4L2_CTRL_TYPE_FIXED_POINT`` and ``V4L2_CTRL_FLAG_HAS_PAYLOAD``
+is set.
 * - struct :c:type:`v4l2_area` *
   - ``p_area``
   - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
diff --git a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst 
b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst
index 4d38acafe8e1..f3995ec57044 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst
@@ -235,7 +235,8 @@ See also the examples in :ref:`control`.
   - ``default_value``
   - The default value of a ``V4L2_CTRL_TYPE_INTEGER``, ``_INTEGER64``,
``_BOOLEAN``, ``_BITMASK``, ``_MENU``, ``_INTEGER_MENU``, ``_U8``
-   or ``_U16`` control. Not valid for other types of controls.
+   ``_FIXED_POINT`` or ``_U16`` control. Not valid for other types of
+   controls.
 
.. note::
 
@@ -549,6 +550,12 @@ See also the examples in :ref:`control`.
   - n/a
   - A struct :c:type:`v4l2_ctrl_av1_film_grain`, containing AV1 Film Grain
 parameters for stateless video decoders.
+* - ``V4L2_CTRL_TYPE_FIXED_POINT``
+  - any
+  - any
+  - any
+  - A 64-bit integer valued control, containing parameter which is
+Q31.32 format.
 
 .. raw:: latex
 
diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions 
b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
index e61152bb80d1..2faa5a2015eb 100644
--- a/Documentation/userspace-api/media/videodev2.h.rst.exceptions
+++ b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
@@ -167,6 +167,7 @@ replace symbol V4L2_CTRL_TYPE_AV1_SEQUENCE 
:c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AV1_TILE_GROUP_ENTRY :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AV1_FRAME :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AV1_FILM_GRAIN :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_FIXED_POINT :c:type:`v4l2_ctrl_type`
 
 # V4L2 capability defines
 replace define V4L2_CAP_VIDEO_CAPTURE device-capabilities
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c 
b/drivers/media/v4l2-core/v4l2-ctrls-api.c
index 002ea6588edf..e6a0fb8d6791 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-api.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c
@@ -57,6 +57,7 @@ static int ptr_to_user(struct v4l2_ext_control *c,
return copy_to_user(c->string, ptr.p_char, len + 1) ?
   -EFAULT : 0;
case V4L2_CTRL_TYPE_INTEGER64:
+   case V4L2_CTRL_TYPE_FIXED_POINT:
c->value64 = *ptr.p_s64;
break;
default:
@@ -132,6 +133,7 @@ static int user_to_new(struct v4l2_ext_control *c, struct 
v4l2_ctrl *ctrl)
 
switch (ctrl->type) {
case V4L2_CTRL_TYPE_INTEGER64:
+   case V4L2_CTRL_TYPE_FIXED_POINT:
*ctrl->p_new.p_s64 = c->value64;
break;
  

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

2023-11-09 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 v9 08/15] media: uapi: Define audio sample format fourcc type

2023-11-09 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 = "32-bi

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

2023-11-09 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-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 +
 12 files changed, 213 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 a/Documentation/userspace-api/media/v4l/devices.rst 
b/Documentation/userspace-a

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

2023-11-09 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 c3d4e490ce7c..5053f66c501a 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 v9 05/15] ASoC: fsl_easrc: register m2m platform device

2023-11-09 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 0b9f3df8efc2..07e7475db7f3 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 = &pdev->dev;
struct fsl_asrc *easrc;
struct resource *res;
@@ -2190,11 +2191,29 @@ static int fsl_easrc_probe(struct platform_device *pdev)
return ret;
}
 
+   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(&pdev->dev,
+   M2M_DRV_NAME,
+   PLATFORM_DEVID_AUTO,
+   &m2m_pdata,
+   sizeof(m2m_pdata));
+
return 0;
 }
 
 static void fsl_easrc_remove(struct platform_device *pdev)
 {
+   struct fsl_asrc *easrc = dev_get_drvdata(&pdev->dev);
+
+   if (easrc->m2m_pdev && !IS_ERR(easrc->m2m_pdev))
+   platform_device_unregister(easrc->m2m_pdev);
+
pm_runtime_disable(&pdev->dev);
 }
 
-- 
2.34.1



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

2023-11-09 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(&pdev->dev,
+  M2M_DRV_NAME,
+  PLATFORM_DEVID_AUTO,
+  &m2m_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(&pdev->dev);
+
+   if (asrc->m2m_pdev && !IS_ERR(asrc->m2m_pdev))
+   platform_device_unregister(asrc->m2m_pdev);
+
pm_runtime_disable(&pdev->dev);
if (!pm_runtime_status_suspended(&pdev->dev))
fsl_asrc_runtime_suspend(&pdev->dev);
-- 
2.34.1



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

2023-11-09 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 v9 02/15] ASoC: fsl_easrc: define functions for memory to memory usage

2023-11-09 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 ba62995c909a..0b9f3df8efc2 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);
+   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 = &asrc->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,
+  &ctx_priv->in_params.sample_format,
+  &ctx_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_b

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

2023-11-09 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);
+
+   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 = &asrc->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 = &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 in

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

2023-11-09 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 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 V4L2_CTRL_TYPE_FIXED_POINT
  media: uapi: Add audio rate controls support
  media: uapi: Declare interface types for Audio
  media: uapi: Add an entity type for audio resampler
  media: imx-asrc: Add memory to memory driver
  media: vim2m-audio: add virtual driver for audio memory to memory

 .../media/mediactl/media-types.rst|9 +
 .../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  |   17 +-
 .../userspace-api/media/v4l/vidioc-g-fmt.rst  |4 +
 .../media/v4l/vidioc-querycap.rst |3 +
 .../media/v4l/vidioc-queryctrl.rst|9 +-
 .../media/videodev2.h.rst.exceptions  |4 +
 .../media/common/videobuf2/videobuf2-v4l2.c   |4 +
 drivers/media/platform/nxp/Kconfig|   14 +
 drivers/media/platform/nxp/Makefile   |1 +
 drivers/media/platform/nxp/imx-asrc.c | 1235 +
 drivers/media/test-drivers/Kconfig|   11 +
 drivers/media/test-drivers/Makefile   |1 +
 drivers/media/test-drivers/vim2m-audio.c  |  799 +++
 drivers/media/v4l2-core/v4l2-ctrls-api.c  |5 +-
 drivers/media/v4l2-core/v4l2-ctrls-core.c |2 +
 drivers/media/v4l2-core/v4l2-

Re: [PATCH] powerpc: Fix signature of pfn_to_kaddr()

2023-11-09 Thread Michael Ellerman
Linus Walleij  writes:
> On Tue, Nov 7, 2023 at 6:57 AM Michael Ellerman  wrote:
>
>> I'm struggling to connect the removal of const with those bug reports.
>> It looks like all those warnings are about 0xc000 being
>> outside the range of unsigned long when building 32-bit.
>
> Aha right. I wonder what actually causes that.

It is the 32-bit VDSO being built:

  VDSO32C arch/powerpc/kernel/vdso/vgettimeofday-32.o
In file included from :4:
In file included from /home/michael/linux/lib/vdso/gettimeofday.c:5:
In file included from ../include/vdso/datapage.h:137:
In file included from ../arch/powerpc/include/asm/vdso/gettimeofday.h:7:
../arch/powerpc/include/asm/page.h:230:9: warning: result of comparison of 
constant 13835058055282163712 with expression of type 'unsigned long' is always 
true [-Wtautological-constant-out-of-range-compare]
  230 | return __pa(kaddr) >> PAGE_SHIFT;
  |^~~
../arch/powerpc/include/asm/page.h:217:37: note: expanded from macro '__pa'
  217 | VIRTUAL_WARN_ON((unsigned long)(x) < PAGE_OFFSET);  
\
  | ~~~^~
../arch/powerpc/include/asm/page.h:202:73: note: expanded from macro 
'VIRTUAL_WARN_ON'
  202 | #define VIRTUAL_WARN_ON(x)  
WARN_ON(IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && (x))
  | 
~^~~
../arch/powerpc/include/asm/bug.h:88:25: note: expanded from macro 'WARN_ON'
   88 | int __ret_warn_on = !!(x);  \
  |^


Which is a bit of a frankenstein, because we're building 32-bit VDSO
code for a 64-bit kernel, and using some of the kernel headers for that.

So the warning is correct, we are doing a tautological comparison.
Except that we're not actually using that code in the VDSO, it's just
included in the VDSO because it needs PAGE_SHIFT.

Anyway none of that is your fault, you just had the misfortune of
touching page.h :)

I think I see a way to clean it up. Will send a patch.

cheers


Ping? Re: [PATCH rc] kvm: Prevent compiling virt/kvm/vfio.c unless VFIO is selected

2023-11-09 Thread Michael Ellerman
Jason Gunthorpe  writes:
> There are a bunch of reported randconfig failures now because of this,
> something like:
>
>>> arch/powerpc/kvm/../../../virt/kvm/vfio.c:89:7: warning: attribute 
>>> declaration must precede definition [-Wignored-attributes]
>fn = symbol_get(vfio_file_iommu_group);
> ^
>include/linux/module.h:805:60: note: expanded from macro 'symbol_get'
>#define symbol_get(x) ({ extern typeof(x) x 
> __attribute__((weak,visibility("hidden"))); &(x); })
>
> It happens because the arch forces KVM_VFIO without knowing if VFIO is
> even enabled.

This is still breaking some builds. Can we get this fix in please?

cheers

> Split the kconfig so the arch selects the usual HAVE_KVM_ARCH_VFIO and
> then KVM_VFIO is only enabled if the arch wants it and VFIO is turned on.
>
> Reported-by: kernel test robot 
> Closes: 
> https://lore.kernel.org/oe-kbuild-all/202308251949.5iiav0sz-...@intel.com/
> Closes: 
> https://lore.kernel.org/oe-kbuild-all/202309030741.82alacdg-...@intel.com/
> Closes: 
> https://lore.kernel.org/oe-kbuild-all/202309110914.qlh0lu6l-...@intel.com/
> Cc: Nick Desaulniers 
> Fixes: c1cce6d079b8 ("vfio: Compile vfio_group infrastructure optionally")
> Signed-off-by: Jason Gunthorpe 
> ---
>  arch/arm64/kvm/Kconfig   | 2 +-
>  arch/powerpc/kvm/Kconfig | 2 +-
>  arch/s390/kvm/Kconfig| 2 +-
>  arch/x86/kvm/Kconfig | 2 +-
>  virt/kvm/Kconfig | 7 ++-
>  5 files changed, 10 insertions(+), 5 deletions(-)
>
> Sean's large series will also address this:
>
> https://lore.kernel.org/kvm/20230916003118.2540661-7-sea...@google.com/
>
> I don't know if it is sever enough to fix in the rc cycle, but here is the
> patch.
>
> diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig
> index 83c1e09be42e5b..7c43eaea51ce05 100644
> --- a/arch/arm64/kvm/Kconfig
> +++ b/arch/arm64/kvm/Kconfig
> @@ -28,7 +28,7 @@ menuconfig KVM
>   select KVM_MMIO
>   select KVM_GENERIC_DIRTYLOG_READ_PROTECT
>   select KVM_XFER_TO_GUEST_WORK
> - select KVM_VFIO
> + select HAVE_KVM_ARCH_VFIO
>   select HAVE_KVM_EVENTFD
>   select HAVE_KVM_IRQFD
>   select HAVE_KVM_DIRTY_RING_ACQ_REL
> diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
> index 902611954200df..b64824e4cbc1eb 100644
> --- a/arch/powerpc/kvm/Kconfig
> +++ b/arch/powerpc/kvm/Kconfig
> @@ -22,7 +22,7 @@ config KVM
>   select PREEMPT_NOTIFIERS
>   select HAVE_KVM_EVENTFD
>   select HAVE_KVM_VCPU_ASYNC_IOCTL
> - select KVM_VFIO
> + select HAVE_KVM_ARCH_VFIO
>   select IRQ_BYPASS_MANAGER
>   select HAVE_KVM_IRQ_BYPASS
>   select INTERVAL_TREE
> diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
> index 45fdf2a9b2e326..d206ad3a777d5d 100644
> --- a/arch/s390/kvm/Kconfig
> +++ b/arch/s390/kvm/Kconfig
> @@ -31,7 +31,7 @@ config KVM
>   select HAVE_KVM_IRQ_ROUTING
>   select HAVE_KVM_INVALID_WAKEUPS
>   select HAVE_KVM_NO_POLL
> - select KVM_VFIO
> + select HAVE_KVM_ARCH_VFIO
>   select INTERVAL_TREE
>   select MMU_NOTIFIER
>   help
> diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
> index ed90f148140dfe..8e70e693f90e30 100644
> --- a/arch/x86/kvm/Kconfig
> +++ b/arch/x86/kvm/Kconfig
> @@ -45,7 +45,7 @@ config KVM
>   select HAVE_KVM_NO_POLL
>   select KVM_XFER_TO_GUEST_WORK
>   select KVM_GENERIC_DIRTYLOG_READ_PROTECT
> - select KVM_VFIO
> + select HAVE_KVM_ARCH_VFIO
>   select INTERVAL_TREE
>   select HAVE_KVM_PM_NOTIFIER if PM
>   select KVM_GENERIC_HARDWARE_ENABLING
> diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
> index 484d0873061ca5..0bf34809e1bbfe 100644
> --- a/virt/kvm/Kconfig
> +++ b/virt/kvm/Kconfig
> @@ -59,9 +59,14 @@ config HAVE_KVM_MSI
>  config HAVE_KVM_CPU_RELAX_INTERCEPT
> bool
>  
> -config KVM_VFIO
> +config HAVE_KVM_ARCH_VFIO
> bool
>  
> +config KVM_VFIO
> +   def_bool y
> +   depends on HAVE_KVM_ARCH_VFIO
> +   depends on VFIO
> +
>  config HAVE_KVM_INVALID_WAKEUPS
> bool
>  
>
> base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
> -- 
> 2.42.0


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

2023-11-09 Thread kernel test robot
Hi Daniel,

kernel test robot noticed the following build warnings:

[auto build test WARNING on v6.6]
[cannot apply to arm64/for-next/core efi/next tip/x86/core robh/for-next 
linus/master next-20231110]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Daniel-Walker/CMDLINE-add-generic-builtin-command-line/20231110-094423
base:   v6.6
patch link:
https://lore.kernel.org/r/20231110013817.2378507-6-danielwa%40cisco.com
patch subject: [PATCH 5/8] drivers: firmware: efi: libstub: enable generic 
commandline
config: loongarch-randconfig-002-20231110 
(https://download.01.org/0day-ci/archive/20231110/202311101224.evyh4zgy-...@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20231110/202311101224.evyh4zgy-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202311101224.evyh4zgy-...@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/firmware/efi/libstub/efi-stub-helper.c:43: warning: expecting 
>> prototype for efi_handle_cmdline(). Prototype was for 
>> efi_handle_builtin_cmdline() instead
   drivers/firmware/efi/libstub/efi-stub-helper.c:592: warning: Function 
parameter or member 'out' not described in 'efi_load_initrd'


vim +43 drivers/firmware/efi/libstub/efi-stub-helper.c

32  
33  /**
34   * efi_handle_cmdline() - handle adding in built-in parts of the 
command line
35   * @cmdline:kernel command line
36   *
37   * Add in the generic parts of the commandline and start the parsing of 
the
38   * command line.
39   *
40   * Return:  status code
41   */
42  efi_status_t efi_handle_builtin_cmdline(char const *cmdline)
  > 43  {
44  efi_status_t status = EFI_SUCCESS;
45  
46  if (sizeof(CMDLINE_STATIC_PREPEND) > 1)
47  status |= efi_parse_options(CMDLINE_STATIC_PREPEND);
48  
49  if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE))
50  status |= efi_parse_options(cmdline);
51  
52  if (sizeof(CMDLINE_STATIC_APPEND) > 1)
53  status |= efi_parse_options(CMDLINE_STATIC_APPEND);
54  
55  if (status != EFI_SUCCESS)
56  efi_err("Failed to parse options\n");
57  
58  return status;
59  }
60  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


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

2023-11-09 Thread Andrew Morton
On Fri, 10 Nov 2023 02:22:27 + "Daniel Walker (danielwa)" 
 wrote:

> On Thu, Nov 09, 2023 at 05:51:42PM -0800, Andrew Morton wrote:
> > On Thu,  9 Nov 2023 17:38:04 -0800 Daniel Walker  wrote:
> > 
> > > 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.
> > > 
> > > 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.
> > > 
> > 
> > fyi, none of the above is suitable for a [0/N] changelog - it's all
> > transitory stuff which tells readers nothing much about what the
> > patchset does.
>  
> I did not think about it this way. It's because I've submitted this so many
> times. I guess I assume everyone knows what it is.

This is all on the path to the mainline git history.  Think about how
we want it presented to future readers.  10 years from now nobody will
remember the v5 series email spray.

> 
> > In [1/8] I see "Even with mips and powerpc enhancement the needs of
> > Cisco are not met on these platforms" and "This unified implementation
> > offers the same functionality needed by Cisco on all platform which we
> > enable it on".
> > 
> > Well OK, what are these needs?   What functionality changes does this
> > patchset offer which Cisco finds useful?  IOW, what were the
> > requirements?  What's wrong with the old code and how does this
> > patchset fix/enhance that?
> 
> The limitation is that you can't append and prepend to the command line at the
> same time in any of the architectures. Having access to both allows OEMs to 
> deal
> with broken bootloaders which can't easily be upgraded.

I would never ever have guessed that from the emails I received!

> Others have responded
> that they also use these patches for this same reason.

Citing this info in the [0/N] would be useful.

> In 2/8 and 3/8 I modify the insert-sys-cert tool to allow modification of the
> command line append and prepend after the build. This allow for an SDK
> provided with a binary kernel and for the command line append/prepend to still
> be modified identically to how that's done with certificates.

And this.

> Making all this generic means each platform has a unified set of command line
> services. Cisco uses x86/arm32/arm64/mips/powerpc , and it's nice to have all
> the same features across platforms.

Sounds good.

> > 
> > I see the patchset updates nothing under Documentation/.  Should it do
> > so?  Could it do so?
> 
> The only documentation is Kconfig descriptions and commit messages. I suppose 
> it
> could have something under Documentation/. The only part which could use more
> documentation are the changes in 2/8 and 3/8. That feature is maybe confusing
> and has limitations which are maybe not clear. Although the same limitation 
> exist for
> inserting certificates.

Perhaps the new functionality could be described in
Documentation/admin-guide/kernel-parameters.rst

> > 
> > I don't know what is the expected merge patch for this work.  I can
> > grab them if no other maintainer is in the firing line.
> 
> merge patch ?

"path", sorry.

> Do you mean merge description ? I think your the maintainer in the
> firing line for this one.

OK.  


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

2023-11-09 Thread Daniel Walker (danielwa)
On Thu, Nov 09, 2023 at 05:51:42PM -0800, Andrew Morton wrote:
> On Thu,  9 Nov 2023 17:38:04 -0800 Daniel Walker  wrote:
> 
> > 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.
> > 
> > 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.
> > 
> 
> fyi, none of the above is suitable for a [0/N] changelog - it's all
> transitory stuff which tells readers nothing much about what the
> patchset does.
 
I did not think about it this way. It's because I've submitted this so many
times. I guess I assume everyone knows what it is.

> And that info is sorely missed.  I can see that it's a code cleanup,
> but I'm sure Cisco wouldn't expend resources to maintain such a thing. 
> There's something else here.

I think the prior submissions there was no cover letter, maybe I should just
achoo that entirely.

> In [1/8] I see "Even with mips and powerpc enhancement the needs of
> Cisco are not met on these platforms" and "This unified implementation
> offers the same functionality needed by Cisco on all platform which we
> enable it on".
> 
> Well OK, what are these needs?   What functionality changes does this
> patchset offer which Cisco finds useful?  IOW, what were the
> requirements?  What's wrong with the old code and how does this
> patchset fix/enhance that?

The limitation is that you can't append and prepend to the command line at the
same time in any of the architectures. Having access to both allows OEMs to deal
with broken bootloaders which can't easily be upgraded. Others have responded
that they also use these patches for this same reason.

In 2/8 and 3/8 I modify the insert-sys-cert tool to allow modification of the
command line append and prepend after the build. This allow for an SDK
provided with a binary kernel and for the command line append/prepend to still
be modified identically to how that's done with certificates.

Making all this generic means each platform has a unified set of command line
services. Cisco uses x86/arm32/arm64/mips/powerpc , and it's nice to have all
the same features across platforms.

> 
> I see the patchset updates nothing under Documentation/.  Should it do
> so?  Could it do so?

The only documentation is Kconfig descriptions and commit messages. I suppose it
could have something under Documentation/. The only part which could use more
documentation are the changes in 2/8 and 3/8. That feature is maybe confusing
and has limitations which are maybe not clear. Although the same limitation 
exist for
inserting certificates.

> 
> I don't know what is the expected merge patch for this work.  I can
> grab them if no other maintainer is in the firing line.

merge patch ? Do you mean merge description ? I think your the maintainer in the
firing line for this one.

Daniel

Re: [PATCH 15/34] KVM: Add KVM_CREATE_GUEST_MEMFD ioctl() for guest-specific backing memory

2023-11-09 Thread Xiaoyao Li

On 11/6/2023 12:30 AM, Paolo Bonzini wrote:

From: Sean Christopherson 

Introduce an ioctl(), KVM_CREATE_GUEST_MEMFD, to allow creating file-based
memory that is tied to a specific KVM virtual machine and whose primary
purpose is to serve guest memory.

A guest-first memory subsystem allows for optimizations and enhancements
that are kludgy or outright infeasible to implement/support in a generic
memory subsystem.  With guest_memfd, guest protections and mapping sizes
are fully decoupled from host userspace mappings.   E.g. KVM currently
doesn't support mapping memory as writable in the guest without it also
being writable in host userspace, as KVM's ABI uses VMA protections to
define the allow guest protection.  Userspace can fudge this by
establishing two mappings, a writable mapping for the guest and readable
one for itself, but that’s suboptimal on multiple fronts.

Similarly, KVM currently requires the guest mapping size to be a strict
subset of the host userspace mapping size, e.g. KVM doesn’t support
creating a 1GiB guest mapping unless userspace also has a 1GiB guest
mapping.  Decoupling the mappings sizes would allow userspace to precisely
map only what is needed without impacting guest performance, e.g. to
harden against unintentional accesses to guest memory.

Decoupling guest and userspace mappings may also allow for a cleaner
alternative to high-granularity mappings for HugeTLB, which has reached a
bit of an impasse and is unlikely to ever be merged.

A guest-first memory subsystem also provides clearer line of sight to
things like a dedicated memory pool (for slice-of-hardware VMs) and
elimination of "struct page" (for offload setups where userspace _never_
needs to mmap() guest memory).

More immediately, being able to map memory into KVM guests without mapping
said memory into the host is critical for Confidential VMs (CoCo VMs), the
initial use case for guest_memfd.  While AMD's SEV and Intel's TDX prevent
untrusted software from reading guest private data by encrypting guest
memory with a key that isn't usable by the untrusted host, projects such
as Protected KVM (pKVM) provide confidentiality and integrity *without*
relying on memory encryption.  And with SEV-SNP and TDX, accessing guest
private memory can be fatal to the host, i.e. KVM must be prevent host
userspace from accessing guest memory irrespective of hardware behavior.

Attempt #1 to support CoCo VMs was to add a VMA flag to mark memory as
being mappable only by KVM (or a similarly enlightened kernel subsystem).
That approach was abandoned largely due to it needing to play games with
PROT_NONE to prevent userspace from accessing guest memory.

Attempt #2 to was to usurp PG_hwpoison to prevent the host from mapping
guest private memory into userspace, but that approach failed to meet
several requirements for software-based CoCo VMs, e.g. pKVM, as the kernel
wouldn't easily be able to enforce a 1:1 page:guest association, let alone
a 1:1 pfn:gfn mapping.  And using PG_hwpoison does not work for memory
that isn't backed by 'struct page', e.g. if devices gain support for
exposing encrypted memory regions to guests.

Attempt #3 was to extend the memfd() syscall and wrap shmem to provide
dedicated file-based guest memory.  That approach made it as far as v10
before feedback from Hugh Dickins and Christian Brauner (and others) led
to it demise.

Hugh's objection was that piggybacking shmem made no sense for KVM's use
case as KVM didn't actually *want* the features provided by shmem.  I.e.
KVM was using memfd() and shmem to avoid having to manage memory directly,
not because memfd() and shmem were the optimal solution, e.g. things like
read/write/mmap in shmem were dead weight.

Christian pointed out flaws with implementing a partial overlay (wrapping
only _some_ of shmem), e.g. poking at inode_operations or super_operations
would show shmem stuff, but address_space_operations and file_operations
would show KVM's overlay.  Paraphrashing heavily, Christian suggested KVM
stop being lazy and create a proper API.

Link: 
https://lore.kernel.org/all/20201020061859.18385-1-kirill.shute...@linux.intel.com
Link: 
https://lore.kernel.org/all/20210416154106.23721-1-kirill.shute...@linux.intel.com
Link: https://lore.kernel.org/all/20210824005248.200037-1-sea...@google.com
Link: 
https://lore.kernel.org/all/2021141352.26311-1-chao.p.p...@linux.intel.com
Link: 
https://lore.kernel.org/all/20221202061347.1070246-1-chao.p.p...@linux.intel.com
Link: 
https://lore.kernel.org/all/ff5c5b97-acdf-9745-ebe5-c6609dd63...@google.com
Link: https://lore.kernel.org/all/20230418-anfallen-irdisch-6993a61be10b@brauner
Link: https://lore.kernel.org/all/zem5zq8oo+xna...@google.com
Link: https://lore.kernel.org/linux-mm/20230306191944.GA15773@monkey
Link: https://lore.kernel.org/linux-mm/zii1p8zhlhaq3...@casper.infradead.org
Cc: Fuad Tabba 
Cc: Vishal Annapurve 
Cc: Ackerley Tng 
Cc: Jarkko Sakkinen 
Cc: Maciej Szmigiero 
Cc: Vlastimil Babka 
Cc: David Hildenbra

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

2023-11-09 Thread Andrew Morton
On Thu,  9 Nov 2023 17:38:04 -0800 Daniel Walker  wrote:

> 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.
> 
> 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.
> 

fyi, none of the above is suitable for a [0/N] changelog - it's all
transitory stuff which tells readers nothing much about what the
patchset does.

And that info is sorely missed.  I can see that it's a code cleanup,
but I'm sure Cisco wouldn't expend resources to maintain such a thing. 
There's something else here.

In [1/8] I see "Even with mips and powerpc enhancement the needs of
Cisco are not met on these platforms" and "This unified implementation
offers the same functionality needed by Cisco on all platform which we
enable it on".

Well OK, what are these needs?   What functionality changes does this
patchset offer which Cisco finds useful?  IOW, what were the
requirements?  What's wrong with the old code and how does this
patchset fix/enhance that?


I see the patchset updates nothing under Documentation/.  Should it do
so?  Could it do so?


I don't know what is the expected merge patch for this work.  I can
grab them if no other maintainer is in the firing line.


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

2023-11-09 Thread Daniel Walker
Rob Herring has complained about this section of code. I removed the
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.
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.

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", &l);
-   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)
+{
+   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 */
-- 
2.39.2



[PATCH 6/8] CMDLINE: x86: convert to generic builtin command line

2023-11-09 Thread Daniel Walker
This updates the x86 code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/x86/Kconfig| 44 +
 arch/x86/kernel/setup.c | 18 ++---
 2 files changed, 3 insertions(+), 59 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 66bfabae8814..390ffaa743df 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -145,6 +145,7 @@ config X86
select EDAC_SUPPORT
select GENERIC_CLOCKEVENTS_BROADCASTif X86_64 || (X86_32 && 
X86_LOCAL_APIC)
select GENERIC_CLOCKEVENTS_MIN_ADJUST
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
@@ -2309,49 +2310,6 @@ choice
 
 endchoice
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- Allow for specifying boot arguments to the kernel at
- build time.  On some systems (e.g. embedded ones), it is
- necessary or convenient to provide some or all of the
- kernel boot arguments with the kernel itself (that is,
- to not rely on the boot loader to provide them.)
-
- To compile command line arguments into the kernel,
- set this option to 'Y', then fill in the
- boot arguments in CONFIG_CMDLINE.
-
- Systems with fully functional boot loaders (i.e. non-embedded)
- should leave this option set to 'N'.
-
-config CMDLINE
-   string "Built-in kernel command string"
-   depends on CMDLINE_BOOL
-   default ""
-   help
- Enter arguments here that should be compiled into the kernel
- image and used at boot time.  If the boot loader provides a
- command line at boot time, it is appended to this string to
- form the full kernel command line, when the system boots.
-
- However, you can use the CONFIG_CMDLINE_OVERRIDE option to
- change this behavior.
-
- In most cases, the command line (whether built-in or provided
- by the boot loader) should specify the device for the root
- file system.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides boot loader arguments"
-   depends on CMDLINE_BOOL && CMDLINE != ""
-   help
- Set this option to 'Y' to have the kernel ignore the boot loader
- command line, and use ONLY the built-in command line.
-
- This is used to work around broken boot loaders.  This should
- be set to 'N' under normal conditions.
-
 config MODIFY_LDT_SYSCALL
bool "Enable the LDT (local descriptor table)" if EXPERT
default y
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index b098b1fa2470..bd025c003f32 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -55,6 +55,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
@@ -162,9 +163,6 @@ unsigned long saved_video_mode;
 #define RAMDISK_LOAD_FLAG  0x4000
 
 static char __initdata command_line[COMMAND_LINE_SIZE];
-#ifdef CONFIG_CMDLINE_BOOL
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-#endif
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
 struct edd edd;
@@ -959,19 +957,7 @@ void __init setup_arch(char **cmdline_p)
bss_resource.start = __pa_symbol(__bss_start);
bss_resource.end = __pa_symbol(__bss_stop)-1;
 
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
-   strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-#else
-   if (builtin_cmdline[0]) {
-   /* append boot loader cmdline to builtin */
-   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-   strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-   strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   }
-#endif
-#endif
-
+   cmdline_add_builtin(boot_command_line);
strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
 
-- 
2.39.2



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

2023-11-09 Thread Daniel Walker
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.

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
- kernel args so that you don't have to set them up in board prom
- initialization routines.
-
- For more information, see the CMDLINE_BOOL and CMDLINE_OVERRIDE
- options.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides firmware arguments"
-   depends on CMDLINE_BOOL
-   help
- By setting 

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

2023-11-09 Thread Daniel Walker
This removes arm64 from the device tree handling of the
command line arguments.

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.

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
+++ b/arch/arm64/kernel/pi/kaslr_early.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -42,7 +43,7 @@ static bool cmdline_contains_nokaslr(const u8 *cmdline)
 
 static bool is_kaslr_disabled_cmdline(void *fdt)
 {
-   if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
+   if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
int node;
const u8 *prop;
 
@@ -54,16 +55,15 @@ static bool is_kaslr_disabled_cmdline(void *fdt)
if (!prop)
goto out;
 
+ 

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

2023-11-09 Thread Daniel Walker
This adds changes to the insert-sys-cert tool to allow updating
the cmdline_prepend and cmdline_append symbols in addition to
adding certificates.

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

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.

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, &cert_size);
if (!cert)
-   exit(EXIT_FAILURE);
-
-   hdr = map_file(vmlinux_file, &vmlinux_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);
+   return EXIT_FAILURE;
}
get_symbol_from_map(hdr, system_map, CERT_SYM, &cert_sym);
get_symbol_from_map(hdr, system_map, USED_SYM, &used_sym);
@@ -371,7 +325,7 @@ int main(int argc, char **argv)
}
 
if (!cert_sym.offset || !lsize_sym.offset || !used_sym.offset)
-

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

2023-11-09 Thread Daniel Walker
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.

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,
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.

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,
 unsigned long min_addr);
 
+efi_status_t efi_handle_builtin_cmdline(char const *cmdline);
 efi_status_t efi_parse_options(char const *cmdline);
 
 void efi_parse_option_graphics(char *option);
diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
b/drivers/firmware/efi/libstub/x86-stub.c
index 9d5df683f882..273a8a9c8bbb 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-st

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

2023-11-09 Thread Daniel Walker
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.

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
-- 
2.39.2



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

2023-11-09 Thread Daniel Walker
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.

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.

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

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

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
+#else
+#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
+ * @cmdline_strlcat: point to a compatible strlcat
+ * 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.
+ */
+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))
+{
+   size_t total_length = 0, tmp_length;
+
+   if (!IS_ENABLED(CONFIG_GENERIC_CMDLINE))
+   return true;
+
+   if (!IS_ENABLED(CONFIG_CMDLINE_BOOL))
+   return true;
+
+   if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE))
+   dest[0] = '\0';
+   else
+   total_length += cmdline_strlen(dest);
+
+   tmp_length = cmdline_strlen(append);
+   if (tmp_length > 0) {
+   cmdline_strlcat(dest, append, length);
+   total_length += tmp_length;
+   }
+
+   tmp_length = cmdline_strlen(prepend);
+   if (tmp_length > 0) {
+   cmdline_strlcat(tmp, prepend, length);
+   cmdline_strlcat(tmp, dest, length);
+   dest[0] = '\0';
+   cmdline_strlcat(dest, tmp, length);
+   total_length += tmp_length;
+   }
+
+   tmp[0] = '\0';
+
+   if (total_length > length)
+   return false;
+
+   return true;
+}
+
+#define cmdline_add_builtin(dest) \
+   __cmdline_add_builtin(dest, CMDLINE_TMP, CMDLINE_PREPEND, 
CMDLINE_APPEND, COMMAND_LINE_SIZE, CMDLINE_STRLEN, CMDLINE_STRLCAT)
+
+#define cmdline_get_static_builtin(dest) \
+   (CMDLINE_STATIC_PREPEND CMDLINE_STATIC_APPEND)
+#endif
diff --git a/init/Kconfig b/init/Kconfig
index 6d35728b94b2..703eed88d140 100644
--- a/init

[PATCH 0/8] generic command line v6

2023-11-09 Thread Daniel Walker
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.

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.

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


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 ++
 scripts/Makefile  |   2 +-
 .../{insert-sys-cert.c => insert-symbol.c}| 243 --
 38 files changed, 807 insertions(+), 482 deletions(-)
 create mode 100644 include/linux/cmdline.h
 create mode 100644 lib/generic_cmdline.S
 create mode 100644 lib/test_cmdline1.c
 rename scripts/{insert-sys-cert.c => insert-symbol.c} (72%)

-- 
2.39.2



Re: [PATCH 2/8] leds: nic78bx: explicitly unregister LEDs at module's shutdown

2023-11-09 Thread George Stark

Hello Christophe.

Thanks for the review.


On 11/6/23 11:13, Christophe Leroy wrote:
>
>
> Le 25/10/2023 à 15:07, George Stark a écrit :
>> LEDs are registered using devm_led_classdev_register() and automatically
>> unregistered after module's remove(). led_classdev_unregister() calls
>> led_set_brightness() to turn off the LEDs and module's appropriate 
callback

>> uses resources those were destroyed already in module's remove().
>> So explicitly unregister LEDs at module shutdown.
>>
>> Signed-off-by: George Stark 
>> ---
>>drivers/leds/leds-nic78bx.c | 4 
>>1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/leds/leds-nic78bx.c b/drivers/leds/leds-nic78bx.c
>> index f196f52eec1e..12b70fcad37f 100644
>> --- a/drivers/leds/leds-nic78bx.c
>> +++ b/drivers/leds/leds-nic78bx.c
>> @@ -170,6 +170,10 @@ static int nic78bx_probe(struct platform_device 
*pdev)

>>static int nic78bx_remove(struct platform_device *pdev)
>>{
>>struct nic78bx_led_data *led_data = platform_get_drvdata(pdev);
>> +  int i;
>> +
>> +  for (i = 0; i < ARRAY_SIZE(nic78bx_leds); i++)
>> +  devm_led_classdev_unregister(&pdev->dev, 
&nic78bx_leds[i].cdev);
>
> The whole purpose of devm_ functions is that you don't need to call
> unregister when removing the driver as the dev core will do it for you.
> I understand your problem but I think this is not the solution.

I agree my solution is questionable although 
devm_led_classdev_unregister() is exists for some reason.


Probably it's not the best solution to remove led_set_brightness() from 
led_classdev_unregister() either.
Or we'll have to patch a lot of drivers which use led subsystem to call 
led_set_brightness() manually to keep leds' previous behavior.


Well if we can't easily unregister leds before module's remove() 
callback is completed may be we can get rid of remove() itself and 
manage all resources using devm API. In that case by the time 
led_set_brightness() is called from led_classdev_unregister() all 
dependent resources will be alive.

I'll try it in the next patch series.

>
>>
>>/* Lock LED register */
>>outb(NIC78BX_LOCK_VALUE,
--
Best regards
George


Re: [PATCH 15/22] arch: vdso: consolidate gettime prototypes

2023-11-09 Thread Michael Ellerman
Christophe Leroy  writes:
> Le 09/11/2023 à 11:18, Michael Ellerman a écrit :
>> "Arnd Bergmann"  writes:
>>> On Wed, Nov 8, 2023, at 19:31, Christophe Leroy wrote:
 Le 08/11/2023 à 13:58, Arnd Bergmann a écrit :
>>>
 powerpc has functions doing more or less the same, they are called
 __c_kernel_clock_gettime() and alike with their prototypes siting in
 arch/powerpc/include/asm/vdso/gettimeofday.h

 Should those prototypes be moved to include/vdso/gettime.h too and
 eventually renamed, or are they considered too powerpc specific ?
>>>
>>> I don't actually know, my initial interpretation was that
>>> these function names are part of the user ABI for the vdso,
>>> but I never looked closely enough at how vdso works to
>>> be sure what the actual ABI is.
>> 
>> AFAIK the ABI is just the symbols we export, as defined in the linker
>> script:
>> 
>> /*
>>   * This controls what symbols we export from the DSO.
>>   */
>> VERSION
>> {
>>  VDSO_VERSION_STRING {
>>  global:
>>  __kernel_get_syscall_map;
>>  __kernel_gettimeofday;
>>  __kernel_clock_gettime;
>>  __kernel_clock_getres;
>>  __kernel_get_tbfreq;
>>  __kernel_sync_dicache;
>>  __kernel_sigtramp_rt64;
>>  __kernel_getcpu;
>>  __kernel_time;
>> 
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/kernel/vdso/vdso64.lds.S?h=v6.6&#n117
>> 
>>> If __c_kernel_clock_gettime() etc are not part of the user-facing
>>> ABI, I think renaming them for consistency with the other
>>> architectures would be best.
>> 
>> The __c symbols are not part of the ABI, so we could rename them.
>> 
>> At the moment though they don't have the same prototype as the generic
>> versions, because we find the VDSO data in asm and pass it to the C
>> functions, eg:
>> 
>> int __c_kernel_gettimeofday(struct __kernel_old_timeval *tv, struct timezone 
>> *tz,
>>  const struct vdso_data *vd);
>> 
>> I think we can rework that though, by implementing
>> __arch_get_vdso_data() and getting the vdso_data in C. Then we'd be able
>> to share the prototypes.
>
> I think it would not a been good idea, it would be less performant, for 
> explanation see commit 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e876f0b69dc993e86ca7795e63e98385aa9a7ef3

Ah thanks. I was wondering why you had done it in asm.

It's a pity but you're right that's probably a measurable performance
hit for some of those calls.

cheers


Re: [PATCH v2 29/37] powerpc/nohash: Replace pte_user() by pte_read()

2023-11-09 Thread Christophe Leroy


Le 07/11/2023 à 14:34, Aneesh Kumar K.V a écrit :
> Christophe Leroy  writes:
> 
>> Le 31/10/2023 à 11:15, Aneesh Kumar K.V a écrit :
>>> Christophe Leroy  writes:
>>>
 pte_user() is now only used in pte_access_permitted() to check
 access on vmas. User flag is cleared to make a page unreadable.

 So rename it pte_read() and remove pte_user() which isn't used
 anymore.

 For the time being it checks _PAGE_USER but in the near futur
 all plateforms will be converted to _PAGE_READ so lets support
 both for now.

 Signed-off-by: Christophe Leroy 
 ---
arch/powerpc/include/asm/nohash/32/pte-8xx.h |  7 ---
arch/powerpc/include/asm/nohash/pgtable.h| 13 +++--
arch/powerpc/mm/ioremap.c|  4 
3 files changed, 7 insertions(+), 17 deletions(-)

 diff --git a/arch/powerpc/include/asm/nohash/32/pte-8xx.h 
 b/arch/powerpc/include/asm/nohash/32/pte-8xx.h
 index 62c965a4511a..1ee38befd29a 100644
 --- a/arch/powerpc/include/asm/nohash/32/pte-8xx.h
 +++ b/arch/powerpc/include/asm/nohash/32/pte-8xx.h
 @@ -112,13 +112,6 @@ static inline pte_t pte_mkwrite_novma(pte_t pte)

#define pte_mkwrite_novma pte_mkwrite_novma

 -static inline bool pte_user(pte_t pte)
 -{
 -  return !(pte_val(pte) & _PAGE_SH);
 -}
 -
 -#define pte_user pte_user
 -
static inline pte_t pte_mkhuge(pte_t pte)
{
return __pte(pte_val(pte) | _PAGE_SPS | _PAGE_HUGE);
 diff --git a/arch/powerpc/include/asm/nohash/pgtable.h 
 b/arch/powerpc/include/asm/nohash/pgtable.h
 index ee677162f9e6..aba56fe3b1c6 100644
 --- a/arch/powerpc/include/asm/nohash/pgtable.h
 +++ b/arch/powerpc/include/asm/nohash/pgtable.h
 @@ -160,9 +160,6 @@ static inline int pte_write(pte_t pte)
return pte_val(pte) & _PAGE_WRITE;
}
#endif
 -#ifndef pte_read
 -static inline int pte_read(pte_t pte) { return 1; }
 -#endif
static inline int pte_dirty(pte_t pte)  { return pte_val(pte) & 
 _PAGE_DIRTY; }
static inline int pte_special(pte_t pte){ return pte_val(pte) & 
 _PAGE_SPECIAL; }
static inline int pte_none(pte_t pte)   { return (pte_val(pte) 
 & ~_PTE_NONE_MASK) == 0; }
 @@ -190,10 +187,14 @@ static inline int pte_young(pte_t pte)
 * and PTE_64BIT, PAGE_KERNEL_X contains _PAGE_BAP_SR which is also in
 * _PAGE_USER.  Need to explicitly match _PAGE_BAP_UR bit in that case 
 too.
 */
 -#ifndef pte_user
 -static inline bool pte_user(pte_t pte)
 +#ifndef pte_read
 +static inline bool pte_read(pte_t pte)
{
 +#ifdef _PAGE_READ
 +  return (pte_val(pte) & _PAGE_READ) == _PAGE_READ;
 +#else
return (pte_val(pte) & _PAGE_USER) == _PAGE_USER;
 +#endif
}
#endif

 @@ -208,7 +209,7 @@ static inline bool pte_access_permitted(pte_t pte, 
 bool write)
 * A read-only access is controlled by _PAGE_USER bit.
 * We have _PAGE_READ set for WRITE and EXECUTE
 */
 -  if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte))
 +  if (!pte_present(pte) || !pte_read(pte))
return false;

if (write && !pte_write(pte))
 diff --git a/arch/powerpc/mm/ioremap.c b/arch/powerpc/mm/ioremap.c
 index 7823c38f09de..7b0afcabd89f 100644
 --- a/arch/powerpc/mm/ioremap.c
 +++ b/arch/powerpc/mm/ioremap.c
 @@ -50,10 +50,6 @@ void __iomem *ioremap_prot(phys_addr_t addr, size_t 
 size, unsigned long flags)
if (pte_write(pte))
pte = pte_mkdirty(pte);

 -  /* we don't want to let _PAGE_USER leak out */
 -  if (WARN_ON(pte_user(pte)))
 -  return NULL;

>>>
>>> This check is still valid right? I understand that we want to remove
>>> _PAGE_USER. But then loosing this check is ok?
>>
>> Well, we may have to think about it for book3s/64. For all others
>> _PAGE_USER is gone and replaced by a check of addresses versus TASK_SIZE.
>>
>> As ioremap() will map into vmalloc space that address is necesserally
>> correct.
>>
>>
> 
> We are adding the pte flags check not the map addr check there. Something 
> like this?

Well, ok, but then why do we want to do that check for ioremap() and not 
for everything else ? vmap() for instance will not perform any such 
check. All it does is to clear the EXEC bit.

As far as I can see, no other architecture does such a check, so why is 
it needed on powerpc at all ?

Regardless, comments below.

> 
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
> b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index 7c7de7b56df0..b053b86e0069 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s

Re: [PATCH v2 37/37] powerpc: Support execute-only on all powerpc

2023-11-09 Thread Christophe Leroy


Le 07/11/2023 à 07:15, Aneesh Kumar K V a écrit :
> On 11/6/23 6:53 PM, Christophe Leroy wrote:
>>
>>
>> Le 02/11/2023 à 06:39, Aneesh Kumar K.V a écrit :
>>> Christophe Leroy  writes:
>>>
 Introduce PAGE_EXECONLY_X macro which provides exec-only rights.
 The _X may be seen as redundant with the EXECONLY but it helps
 keep consistancy, all macros having the EXEC right have _X.

 And put it next to PAGE_NONE as PAGE_EXECONLY_X is
 somehow PAGE_NONE + EXEC just like all other SOMETHING_X are
 just SOMETHING + EXEC.

 On book3s/64 PAGE_EXECONLY becomes PAGE_READONLY_X.

 On book3s/64, as PAGE_EXECONLY is only valid for Radix add
 VM_READ flag in vm_get_page_prot() for non-Radix.

 And update access_error() so that a non exec fault on a VM_EXEC only
 mapping is always invalid, even when the underlying layer don't
 always generate a fault for that.

 For 8xx, set PAGE_EXECONLY_X as _PAGE_NA | _PAGE_EXEC.
 For others, only set it as just _PAGE_EXEC

 With that change, 8xx, e500 and 44x fully honor execute-only
 protection.

 On 40x that is a partial implementation of execute-only. The
 implementation won't be complete because once a TLB has been loaded
 via the Instruction TLB miss handler, it will be possible to read
 the page. But at least it can't be read unless it is executed first.

 On 603 MMU, TLB missed are handled by SW and there are separate
 DTLB and ITLB. Execute-only is therefore now supported by not loading
 DTLB when read access is not permitted.

 On hash (604) MMU it is more tricky because hash table is common to
 load/store and execute. Nevertheless it is still possible to check
 whether _PAGE_READ is set before loading hash table for a load/store
 access. At least it can't be read unless it is executed first.

 Signed-off-by: Christophe Leroy 
 Cc: Russell Currey 
 Cc: Kees Cook 
 ---
arch/powerpc/include/asm/book3s/32/pgtable.h |  2 +-
arch/powerpc/include/asm/book3s/64/pgtable.h |  4 +---
arch/powerpc/include/asm/nohash/32/pte-8xx.h |  1 +
arch/powerpc/include/asm/nohash/pgtable.h|  2 +-
arch/powerpc/include/asm/nohash/pte-e500.h   |  1 +
arch/powerpc/include/asm/pgtable-masks.h |  2 ++
arch/powerpc/mm/book3s64/pgtable.c   | 10 --
arch/powerpc/mm/fault.c  |  9 +
arch/powerpc/mm/pgtable.c|  4 ++--
9 files changed, 18 insertions(+), 17 deletions(-)

 diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h 
 b/arch/powerpc/include/asm/book3s/32/pgtable.h
 index 244621c88510..52971ee30717 100644
 --- a/arch/powerpc/include/asm/book3s/32/pgtable.h
 +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
 @@ -425,7 +425,7 @@ static inline bool pte_access_permitted(pte_t pte, 
 bool write)
{
/*
 * A read-only access is controlled by _PAGE_READ bit.
 -   * We have _PAGE_READ set for WRITE and EXECUTE
 +   * We have _PAGE_READ set for WRITE
 */
if (!pte_present(pte) || !pte_read(pte))
return false;

>>>
>>> Should this now be updated to check for EXEC bit ?
>>
>> I don't think so based on what I see in arm64:
>> https://elixir.bootlin.com/linux/v6.6/source/arch/arm64/include/asm/pgtable.h#L146
>>
> 
> But then there can be a get_user_pages() (FOLL_GET) on an exec only pte right?
> if we are going to access the page data(FOLL_PIN), then yes exec only mapping 
> should
> fail for that. But if we using it to do struct page manipulation we need 
> pte_access_permitted
> to return true for exec only mapping?
> 

I don't know enough the details of GUP to understand what you mean. I 
understand you think there is a problem, do you mean ARM64 did it wrong ?

The core mm only has two call sites for pte_access_permitted() which are 
gup_pte_range() and gup_hugepte(). pte_access_permitted() is not 
documented in Documentation/mm/arch_pgtable_helpers.rst

So, what do those two callers expect ?

Christophe


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

2023-11-09 Thread Michael Ellerman
Hi Sourabh,

This seems like a good change to the design, but I'm confused by
some things, more below ...

Sourabh Jain  writes:
>
...
>
> Table 1 below illustrates kernel's ability to collect dump if either the
> first/crashed kernel or the second/fadump kernel does not have the
> changes introduced here. Consider the 'old kernel' as the kernel without
> this patch, and the 'new kernel' as the kernel with this patch included.
>
> +--+++---+
> | scenario |  first/crashed kernel  |  second/fadump kernel  |  Dump |
> +--+++---+
> |1 |   old kernel   |new kernel  |  Yes  |
> +--+++---+
> |2 |   new kernel   |old kernel  |  No   |
> +--+++---+
>
> Table 1
>
> Scenario 1:
> ---
> Since the magic number of fadump header is updated, the second kernel
> can differentiate the crashed kernel is of type 'new kernel' or
> 'old kernel' and act accordingly. In this scenario, since the crashed
> kernel is of type 'old kernel,' the fadump kernel skips elfcorehdr
> creation and uses the one prepared in the first kernel itself to collect
> the dump.
>
> Scenario 2:
> ---
> Since 'old kernel' as the fadump kernel is NOT capable of processing
> fadump header with updated magic number from 'new kernel' hence it
> gracefully fails with the below error and dump collection fails in this
> scenario.
>
> [0.007365] rtas fadump: Crash info header is not valid.
>
> Add a version field to the fadump_crash_info_header structure to avoid
> the need to change its magic number in the future. Adding a version
> field to the fadump header was one of the TODO items listed in
> Documentation/powerpc/firmware-assisted-dump.rst.

This is a good analysis of the issues with different kernel versions,
and seems like an OK trade off, ie. that old kernels can't process dumps
from new kernels.

But do we actually support using different kernel versions for the
crash/dump kernel?

Because AFAICS the fadump_crash_info_header is not safe across kernel
versions, in its current form or with your changes.

> diff --git a/arch/powerpc/include/asm/fadump-internal.h 
> b/arch/powerpc/include/asm/fadump-internal.h
> index 27f9e11eda28..7be3d8894520 100644
> --- a/arch/powerpc/include/asm/fadump-internal.h
> +++ b/arch/powerpc/include/asm/fadump-internal.h
> @@ -42,7 +42,25 @@ static inline u64 fadump_str_to_u64(const char *str)
>  
>  #define FADUMP_CPU_UNKNOWN   (~((u32)0))
>  
> -#define FADUMP_CRASH_INFO_MAGIC  fadump_str_to_u64("FADMPINF")
> +/*
> + * The introduction of new fields in the fadump crash info header has
> + * led to a change in the magic key, from `FADMPINF` to `FADMPSIG`.
> + * This alteration ensures backward compatibility, enabling the kernel
> + * with the updated fadump crash info to handle kernel dumps from older
> + * kernels.
> + *
> + * To prevent the need for further changes to the magic number in the
> + * event of future modifications to the fadump header, a version field
> + * has been introduced to track the fadump crash info header version.
> + *
> + * Historically, there was no connection between the magic number and
> + * the fadump crash info header version. However, moving forward, the
> + * `FADMPINF` magic number in header will be treated as version 0, while
> + * the `FADMPSIG` magic number in header will include a version field to
> + * determine its version.
> + */
> +#define FADUMP_CRASH_INFO_MAGIC  fadump_str_to_u64("FADMPSIG")
> +#define FADUMP_VERSION   1
>  
>  /* fadump crash info structure */
>  struct fadump_crash_info_header {
> @@ -51,6 +69,10 @@ struct fadump_crash_info_header {
> 
struct fadump_crash_info_header {
u64 magic_number;
u64 elfcorehdr_addr;

>   u32 crashing_cpu;
>   struct pt_regs  regs;
>   struct cpumask  cpu_mask;
> + u32 version;
> + u64 elfcorehdr_size;
> + u64 vmcoreinfo_raddr;
> + u64 vmcoreinfo_size;
>  };

The reason I say it's not safe is because pt_regs and especially cpumask
can change size depending on the kernel configuration.

pt_regs probably doesn't change size in practice for common kernel
configurations, but some of the fields are under #ifdef.

cpumask on the other hand is directly controlled by CONFIG_NR_CPUS. So
if the first and second kernel have a different value for NR_CPUS they
will disagree on the size of the struct.

That has presumably worked OK so far because folks tend to use the same, or
similar kernels for the first/second kernel. And also the cpumask is the
last element of the struct, so a disagreement about it size doesn't
affect the location of 

Re: [PATCH 15/22] arch: vdso: consolidate gettime prototypes

2023-11-09 Thread Christophe Leroy


Le 09/11/2023 à 11:18, Michael Ellerman a écrit :
> "Arnd Bergmann"  writes:
>> On Wed, Nov 8, 2023, at 19:31, Christophe Leroy wrote:
>>> Le 08/11/2023 à 13:58, Arnd Bergmann a écrit :
>>
>>> powerpc has functions doing more or less the same, they are called
>>> __c_kernel_clock_gettime() and alike with their prototypes siting in
>>> arch/powerpc/include/asm/vdso/gettimeofday.h
>>>
>>> Should those prototypes be moved to include/vdso/gettime.h too and
>>> eventually renamed, or are they considered too powerpc specific ?
>>
>> I don't actually know, my initial interpretation was that
>> these function names are part of the user ABI for the vdso,
>> but I never looked closely enough at how vdso works to
>> be sure what the actual ABI is.
> 
> AFAIK the ABI is just the symbols we export, as defined in the linker
> script:
> 
> /*
>   * This controls what symbols we export from the DSO.
>   */
> VERSION
> {
>   VDSO_VERSION_STRING {
>   global:
>   __kernel_get_syscall_map;
>   __kernel_gettimeofday;
>   __kernel_clock_gettime;
>   __kernel_clock_getres;
>   __kernel_get_tbfreq;
>   __kernel_sync_dicache;
>   __kernel_sigtramp_rt64;
>   __kernel_getcpu;
>   __kernel_time;
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/kernel/vdso/vdso64.lds.S?h=v6.6&#n117
> 
>> If __c_kernel_clock_gettime() etc are not part of the user-facing
>> ABI, I think renaming them for consistency with the other
>> architectures would be best.
> 
> The __c symbols are not part of the ABI, so we could rename them.
> 
> At the moment though they don't have the same prototype as the generic
> versions, because we find the VDSO data in asm and pass it to the C
> functions, eg:
> 
> int __c_kernel_gettimeofday(struct __kernel_old_timeval *tv, struct timezone 
> *tz,
>   const struct vdso_data *vd);
> 
> I think we can rework that though, by implementing
> __arch_get_vdso_data() and getting the vdso_data in C. Then we'd be able
> to share the prototypes.

I think it would not a been good idea, it would be less performant, for 
explanation see commit 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e876f0b69dc993e86ca7795e63e98385aa9a7ef3

Christophe


Re: [PATCH 15/22] arch: vdso: consolidate gettime prototypes

2023-11-09 Thread Michael Ellerman
"Arnd Bergmann"  writes:
> On Wed, Nov 8, 2023, at 19:31, Christophe Leroy wrote:
>> Le 08/11/2023 à 13:58, Arnd Bergmann a écrit :
>
>> powerpc has functions doing more or less the same, they are called 
>> __c_kernel_clock_gettime() and alike with their prototypes siting in 
>> arch/powerpc/include/asm/vdso/gettimeofday.h
>>
>> Should those prototypes be moved to include/vdso/gettime.h too and 
>> eventually renamed, or are they considered too powerpc specific ?
>
> I don't actually know, my initial interpretation was that
> these function names are part of the user ABI for the vdso,
> but I never looked closely enough at how vdso works to
> be sure what the actual ABI is.

AFAIK the ABI is just the symbols we export, as defined in the linker
script:

/*
 * This controls what symbols we export from the DSO.
 */
VERSION
{
VDSO_VERSION_STRING {
global:
__kernel_get_syscall_map;
__kernel_gettimeofday;
__kernel_clock_gettime;
__kernel_clock_getres;
__kernel_get_tbfreq;
__kernel_sync_dicache;
__kernel_sigtramp_rt64;
__kernel_getcpu;
__kernel_time;

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/kernel/vdso/vdso64.lds.S?h=v6.6&#n117

> If __c_kernel_clock_gettime() etc are not part of the user-facing
> ABI, I think renaming them for consistency with the other
> architectures would be best.

The __c symbols are not part of the ABI, so we could rename them.

At the moment though they don't have the same prototype as the generic
versions, because we find the VDSO data in asm and pass it to the C
functions, eg:

int __c_kernel_gettimeofday(struct __kernel_old_timeval *tv, struct timezone 
*tz,
const struct vdso_data *vd);

I think we can rework that though, by implementing
__arch_get_vdso_data() and getting the vdso_data in C. Then we'd be able
to share the prototypes.

cheers


Re: [PATCH 15/22] arch: vdso: consolidate gettime prototypes

2023-11-09 Thread Christophe Leroy


Le 08/11/2023 à 20:37, Arnd Bergmann a écrit :
> On Wed, Nov 8, 2023, at 19:31, Christophe Leroy wrote:
>> Le 08/11/2023 à 13:58, Arnd Bergmann a écrit :
> 
>> powerpc has functions doing more or less the same, they are called
>> __c_kernel_clock_gettime() and alike with their prototypes siting in
>> arch/powerpc/include/asm/vdso/gettimeofday.h
>>
>> Should those prototypes be moved to include/vdso/gettime.h too and
>> eventually renamed, or are they considered too powerpc specific ?
> 
> I don't actually know, my initial interpretation was that
> these function names are part of the user ABI for the vdso,
> but I never looked closely enough at how vdso works to
> be sure what the actual ABI is.
> 
> If __c_kernel_clock_gettime() etc are not part of the user-facing
> ABI, I think renaming them for consistency with the other
> architectures would be best.
> 

User-facing ABI function is __kernel_clock_gettime(), defined in 
arch/powerpc/kernel/vdso/gettimeofday.S , see man vdso.
There is no prototype defined for it anywhere, obviously that's 
undetected because it is assembly. Should a prototype be added somewhere 
anyway ?

__kernel_clock_gettime() sets up a stack frame, retrieves the address of 
the datapage then calls __c_kernel_clock_gettime() which then calls 
__cvdso_clock_gettime_data() which is part of the generic CVDSO.

Maybe that's too different from what other architectures do ?

Christophe


Re: [PATCH 34/34] KVM: selftests: Add a memory region subtest to validate invalid flags

2023-11-09 Thread Fuad Tabba
Hi Anish,

On Thu, Nov 9, 2023 at 1:08 AM Anish Moorthy  wrote:
>
> Applying [1] and [2] reveals that this also breaks non-x86 builds- the
> MEM_REGION_GPA/SLOT definitions are guarded behind an #ifdef
> __x86_64__, while the usages introduced here aren't.
>
> Should
>
> On Sun, Nov 5, 2023 at 8:35 AM Paolo Bonzini  wrote:
> >
> > +   test_invalid_memory_region_flags();
>
> be #ifdef'd, perhaps? I'm not quite sure what the intent is.
>
> Side note: I wasn't able to get [2] to apply by copy-pasting the diff
> and trying "git apply", and that was after checking out the relevant
> commit. Eventually I just did it manually. If anyone can successfully
> apply it, please let me know what you did so I can see what I was
> doing wrong :)

For me I applied the whole series as follows:

Checkout kvm-x86-next-2023.11.01 (45b890f7689e) from
https://github.com/kvm-x86/linux.git . Then use b4:
b4 am -o -  20231105163040.14904-1-pbonz...@redhat.com  | git am -3

Cheers,
/fuad

>
> [1] https://lore.kernel.org/kvm/20231108233723.3380042-1-amoor...@google.com/
> [2] 
> https://lore.kernel.org/kvm/affca7a8-116e-4b0f-9edf-6cdc05ba6...@redhat.com/


Re: [PATCH 27/34] KVM: selftests: Introduce VM "shape" to allow tests to specify the VM type

2023-11-09 Thread Paolo Bonzini

On 11/9/23 00:37, Anish Moorthy wrote:

On Wed, Nov 8, 2023 at 9:00 AM Anish Moorthy  wrote:


This commit breaks the arm64 selftests build btw: looks like a simple oversight?


Yup, fix is a one-liner. Posted below.

diff --git a/tools/testing/selftests/kvm/aarch64/page_fault_test.c 
b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
index eb4217b7c768..08a5ca5bed56 100644
--- a/tools/testing/selftests/kvm/aarch64/page_fault_test.c
+++ b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
@@ -705,7 +705,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
  
  	print_test_banner(mode, p);
  
-	vm = vm_create(mode);

+   vm = vm_create(VM_SHAPE(mode));


Yes, this is similar to the s390 patch I sent yesterday 
(https://patchew.org/linux/20231108094055.221234-1-pbonz...@redhat.com/).


Paolo