Re: [PATCH v12 7/7] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

2024-10-26 Thread kernel test robot
Hi Arnaud,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 42f7652d3eb527d03665b09edac47f85fb600924]

url:
https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-core-Introduce-rproc_pa_to_va-helper/20241026-050443
base:   42f7652d3eb527d03665b09edac47f85fb600924
patch link:
https://lore.kernel.org/r/20241025205924.2087768-8-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH v12 7/7] remoteproc: stm32: Add support of an OP-TEE TA 
to load the firmware
config: alpha-allyesconfig 
(https://download.01.org/0day-ci/archive/20241026/202410262040.pwnrkv2q-...@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.3.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20241026/202410262040.pwnrkv2q-...@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/202410262040.pwnrkv2q-...@intel.com/

All warnings (new ones prefixed by >>):

   drivers/remoteproc/stm32_rproc.c: In function 'stm32_rproc_probe':
>> drivers/remoteproc/stm32_rproc.c:904:21: warning: assignment to 'int' from 
>> 'struct rproc_tee *' makes integer from pointer without a cast 
>> [-Wint-conversion]
 904 | ret = rproc_tee_register(dev, rproc, proc_id);
 | ^
   drivers/remoteproc/stm32_rproc.c:963:30: error: passing argument 1 of 
'rproc_tee_unregister' from incompatible pointer type 
[-Werror=incompatible-pointer-types]
 963 | rproc_tee_unregister(rproc);
 |  ^
 |  |
 |  struct rproc *
   In file included from drivers/remoteproc/stm32_rproc.c:21:
   include/linux/remoteproc_tee.h:59:58: note: expected 'struct rproc_tee *' 
but argument is of type 'struct rproc *'
  59 | static inline int rproc_tee_unregister(struct rproc_tee *trproc)
 |~~^~
   drivers/remoteproc/stm32_rproc.c: In function 'stm32_rproc_remove':
   drivers/remoteproc/stm32_rproc.c:986:30: error: passing argument 1 of 
'rproc_tee_unregister' from incompatible pointer type 
[-Werror=incompatible-pointer-types]
 986 | rproc_tee_unregister(rproc);
 |  ^
 |  |
 |  struct rproc *
   include/linux/remoteproc_tee.h:59:58: note: expected 'struct rproc_tee *' 
but argument is of type 'struct rproc *'
  59 | static inline int rproc_tee_unregister(struct rproc_tee *trproc)
 |~~^~
   cc1: some warnings being treated as errors


vim +904 drivers/remoteproc/stm32_rproc.c

   874  
   875  static int stm32_rproc_probe(struct platform_device *pdev)
   876  {
   877  struct device *dev = &pdev->dev;
   878  struct stm32_rproc *ddata;
   879  struct device_node *np = dev->of_node;
   880  struct rproc *rproc;
   881  unsigned int state;
   882  u32 proc_id;
   883  int ret;
   884  
   885  ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
   886  if (ret)
   887  return ret;
   888  
   889  if (of_device_is_compatible(np, "st,stm32mp1-m4-tee")) {
   890  /*
   891   * Delegate the firmware management to the secure 
context.
   892   * The firmware loaded has to be signed.
   893   */
   894  ret = of_property_read_u32(np, "st,proc-id", &proc_id);
   895  if (ret) {
   896  dev_err(dev, "failed to read st,rproc-id 
property\n");
   897  return ret;
   898  }
   899  
   900  rproc = devm_rproc_alloc(dev, np->name, 
&st_rproc_tee_ops, NULL, sizeof(*ddata));
   901  if (!rproc)
   902  return -ENOMEM;
   903  
 > 904  ret = rproc_tee_register(dev, rproc, proc_id);
   905  if (ret)
   906  return dev_err_probe(dev, ret,  "signed 
firmware not supported by TEE\n");
   907  } else {
   908  rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, 
NULL, sizeof(*ddata));
   909  if (!rproc)
   910  return -ENOMEM;
   911  }
   912  
   913  ddata = rproc->priv;
   914  
   915  rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);
   916  
   917

Re: [PATCH v12 7/7] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

2024-10-26 Thread kernel test robot
Hi Arnaud,

kernel test robot noticed the following build errors:

[auto build test ERROR on 42f7652d3eb527d03665b09edac47f85fb600924]

url:
https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-core-Introduce-rproc_pa_to_va-helper/20241026-050443
base:   42f7652d3eb527d03665b09edac47f85fb600924
patch link:
https://lore.kernel.org/r/20241025205924.2087768-8-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH v12 7/7] remoteproc: stm32: Add support of an OP-TEE TA 
to load the firmware
config: x86_64-buildonly-randconfig-004-20241026 
(https://download.01.org/0day-ci/archive/20241026/202410261837.ermjahkz-...@intel.com/config)
compiler: clang version 19.1.2 (https://github.com/llvm/llvm-project 
7ba7d8e2f7b6445b60679da826210cdde29eaf8b)
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20241026/202410261837.ermjahkz-...@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/202410261837.ermjahkz-...@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/remoteproc/stm32_rproc.c:9:
   In file included from include/linux/dma-mapping.h:11:
   In file included from include/linux/scatterlist.h:8:
   In file included from include/linux/mm.h:2213:
   include/linux/vmstat.h:518:36: warning: arithmetic between different 
enumeration types ('enum node_stat_item' and 'enum lru_list') 
[-Wenum-enum-conversion]
 518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
 |   ~~~ ^ ~~~
>> drivers/remoteproc/stm32_rproc.c:904:7: error: incompatible pointer to 
>> integer conversion assigning to 'int' from 'struct rproc_tee *' 
>> [-Wint-conversion]
 904 | ret = rproc_tee_register(dev, rproc, proc_id);
 | ^ ~~~
>> drivers/remoteproc/stm32_rproc.c:963:23: error: incompatible pointer types 
>> passing 'struct rproc *' to parameter of type 'struct rproc_tee *' 
>> [-Werror,-Wincompatible-pointer-types]
 963 | rproc_tee_unregister(rproc);
 |  ^
   include/linux/remoteproc_tee.h:59:58: note: passing argument to parameter 
'trproc' here
  59 | static inline int rproc_tee_unregister(struct rproc_tee *trproc)
 |  ^
   drivers/remoteproc/stm32_rproc.c:986:23: error: incompatible pointer types 
passing 'struct rproc *' to parameter of type 'struct rproc_tee *' 
[-Werror,-Wincompatible-pointer-types]
 986 | rproc_tee_unregister(rproc);
 |  ^
   include/linux/remoteproc_tee.h:59:58: note: passing argument to parameter 
'trproc' here
  59 | static inline int rproc_tee_unregister(struct rproc_tee *trproc)
 |  ^
   1 warning and 3 errors generated.


vim +904 drivers/remoteproc/stm32_rproc.c

   874  
   875  static int stm32_rproc_probe(struct platform_device *pdev)
   876  {
   877  struct device *dev = &pdev->dev;
   878  struct stm32_rproc *ddata;
   879  struct device_node *np = dev->of_node;
   880  struct rproc *rproc;
   881  unsigned int state;
   882  u32 proc_id;
   883  int ret;
   884  
   885  ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
   886  if (ret)
   887  return ret;
   888  
   889  if (of_device_is_compatible(np, "st,stm32mp1-m4-tee")) {
   890  /*
   891   * Delegate the firmware management to the secure 
context.
   892   * The firmware loaded has to be signed.
   893   */
   894  ret = of_property_read_u32(np, "st,proc-id", &proc_id);
   895  if (ret) {
   896  dev_err(dev, "failed to read st,rproc-id 
property\n");
   897  return ret;
   898  }
   899  
   900  rproc = devm_rproc_alloc(dev, np->name, 
&st_rproc_tee_ops, NULL, sizeof(*ddata));
   901  if (!rproc)
   902  return -ENOMEM;
   903  
 > 904  ret = rproc_tee_register(dev, rproc, proc_id);
   905  if (ret)
   906  return dev_err_probe(dev, ret,  "signed 
firmware not supported by TEE\n");
   907  } else {
   908  rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, 
NULL, sizeof(*ddata));
   9

Re: [PATCH v12 7/7] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

2024-10-26 Thread kernel test robot
Hi Arnaud,

kernel test robot noticed the following build errors:

[auto build test ERROR on 42f7652d3eb527d03665b09edac47f85fb600924]

url:
https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-core-Introduce-rproc_pa_to_va-helper/20241026-050443
base:   42f7652d3eb527d03665b09edac47f85fb600924
patch link:
https://lore.kernel.org/r/20241025205924.2087768-8-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH v12 7/7] remoteproc: stm32: Add support of an OP-TEE TA 
to load the firmware
config: m68k-allyesconfig 
(https://download.01.org/0day-ci/archive/20241026/202410261701.jz99xf8b-...@intel.com/config)
compiler: m68k-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20241026/202410261701.jz99xf8b-...@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/202410261701.jz99xf8b-...@intel.com/

All errors (new ones prefixed by >>):

   drivers/remoteproc/stm32_rproc.c: In function 'stm32_rproc_probe':
>> drivers/remoteproc/stm32_rproc.c:904:21: error: assignment to 'int' from 
>> 'struct rproc_tee *' makes integer from pointer without a cast 
>> [-Wint-conversion]
 904 | ret = rproc_tee_register(dev, rproc, proc_id);
 | ^
>> drivers/remoteproc/stm32_rproc.c:963:30: error: passing argument 1 of 
>> 'rproc_tee_unregister' from incompatible pointer type 
>> [-Wincompatible-pointer-types]
 963 | rproc_tee_unregister(rproc);
 |  ^
 |  |
 |  struct rproc *
   In file included from drivers/remoteproc/stm32_rproc.c:21:
   include/linux/remoteproc_tee.h:59:58: note: expected 'struct rproc_tee *' 
but argument is of type 'struct rproc *'
  59 | static inline int rproc_tee_unregister(struct rproc_tee *trproc)
 |~~^~
   drivers/remoteproc/stm32_rproc.c: In function 'stm32_rproc_remove':
   drivers/remoteproc/stm32_rproc.c:986:30: error: passing argument 1 of 
'rproc_tee_unregister' from incompatible pointer type 
[-Wincompatible-pointer-types]
 986 | rproc_tee_unregister(rproc);
 |  ^
 |  |
 |  struct rproc *
   include/linux/remoteproc_tee.h:59:58: note: expected 'struct rproc_tee *' 
but argument is of type 'struct rproc *'
  59 | static inline int rproc_tee_unregister(struct rproc_tee *trproc)
 |~~^~

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for GET_FREE_REGION
   Depends on [n]: SPARSEMEM [=n]
   Selected by [y]:
   - RESOURCE_KUNIT_TEST [=y] && RUNTIME_TESTING_MENU [=y] && KUNIT [=y]


vim +904 drivers/remoteproc/stm32_rproc.c

   874  
   875  static int stm32_rproc_probe(struct platform_device *pdev)
   876  {
   877  struct device *dev = &pdev->dev;
   878  struct stm32_rproc *ddata;
   879  struct device_node *np = dev->of_node;
   880  struct rproc *rproc;
   881  unsigned int state;
   882  u32 proc_id;
   883  int ret;
   884  
   885  ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
   886  if (ret)
   887  return ret;
   888  
   889  if (of_device_is_compatible(np, "st,stm32mp1-m4-tee")) {
   890  /*
   891   * Delegate the firmware management to the secure 
context.
   892   * The firmware loaded has to be signed.
   893   */
   894  ret = of_property_read_u32(np, "st,proc-id", &proc_id);
   895  if (ret) {
   896  dev_err(dev, "failed to read st,rproc-id 
property\n");
   897  return ret;
   898  }
   899  
   900  rproc = devm_rproc_alloc(dev, np->name, 
&st_rproc_tee_ops, NULL, sizeof(*ddata));
   901  if (!rproc)
   902  return -ENOMEM;
   903  
 > 904  ret = rproc_tee_register(dev, rproc, proc_id);
   905  if (ret)
   906  return dev_err_probe(dev, ret,  "signed 
firmware not supported by TEE\n");
   907  } else {
   908  rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, 
NULL, sizeof(*ddata));
   909  if (!rproc)
   910  

[PATCH v6 2/5] pidfd: add PIDFD_SELF_* sentinels to refer to own thread/process

2024-10-26 Thread Lorenzo Stoakes
It is useful to be able to utilise the pidfd mechanism to reference the
current thread or process (from a userland point of view - thread group
leader from the kernel's point of view).

Therefore introduce PIDFD_SELF_THREAD to refer to the current thread, and
PIDFD_SELF_THREAD_GROUP to refer to the current thread group leader.

For convenience and to avoid confusion from userland's perspective we alias
these:

* PIDFD_SELF is an alias for PIDFD_SELF_THREAD - This is nearly always what
  the user will want to use, as they would find it surprising if for
  instance fd's were unshared()'d and they wanted to invoke pidfd_getfd()
  and that failed.

* PIDFD_SELF_PROCESS is an alias for PIDFD_SELF_THREAD_GROUP - Most users
  have no concept of thread groups or what a thread group leader is, and
  from userland's perspective and nomenclature this is what userland
  considers to be a process.

Due to the refactoring of the central __pidfd_get_pid() function we can
implement this functionality centrally, providing the use of this sentinel
in most functionality which utilises pidfd's.

We need to explicitly adjust kernel_waitid_prepare() to permit this (though
it wouldn't really make sense to use this there, we provide the ability for
consistency).

We explicitly disallow use of this in setns(), which would otherwise have
required explicit custom handling, as it doesn't make sense to set the
current calling thread to join the namespace of itself.

As the callers of pidfd_get_pid() expect an increased reference count on
the pid we do so in the self case, reducing churn and avoiding any breakage
from existing logic which decrements this reference count.

This change implicitly provides PIDFD_SELF_* support in the waitid(P_PIDFS,
...), process_madvise(), process_mrelease(), pidfd_send_signal(), and
pidfd_getfd() system calls.

Things such as polling a pidfs and general fd operations are not supported,
this strictly provides the sentinel for APIs which explicitly accept a
pidfd.

Suggested-by: Pedro Falcato 
Reviewed-by: Shakeel Butt 
Signed-off-by: Lorenzo Stoakes 
---
 include/linux/pid.h|  8 --
 include/uapi/linux/pidfd.h | 10 
 kernel/exit.c  |  4 ++-
 kernel/nsproxy.c   |  1 +
 kernel/pid.c   | 51 --
 5 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/include/linux/pid.h b/include/linux/pid.h
index d466890e1b35..3b2ac7567a88 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -78,11 +78,15 @@ struct file;
  * __pidfd_get_pid() - Retrieve a pid associated with the specified pidfd.
  *
  * @pidfd:  The pidfd whose pid we want, or the fd of a /proc/ file if
- *  @alloc_proc is also set.
+ *  @alloc_proc is also set, or PIDFD_SELF_* to refer to the 
current
+ *  thread or thread group leader.
  * @allow_proc: If set, then an fd of a /proc/ file can be passed instead
  *  of a pidfd, and this will be used to determine the pid.
+
  * @flags:  Output variable, if non-NULL, then the file->f_flags of the
- *  pidfd will be set here.
+ *  pidfd will be set here or If PIDFD_SELF_THREAD is set, this is
+ *  set to PIDFD_THREAD, otherwise if PIDFD_SELF_THREAD_GROUP then
+ *  this is set to zero.
  *
  * Returns: If successful, the pid associated with the pidfd, otherwise an
  *  error.
diff --git a/include/uapi/linux/pidfd.h b/include/uapi/linux/pidfd.h
index 565fc0629fff..6fe1d63b2086 100644
--- a/include/uapi/linux/pidfd.h
+++ b/include/uapi/linux/pidfd.h
@@ -29,4 +29,14 @@
 #define PIDFD_GET_USER_NAMESPACE  _IO(PIDFS_IOCTL_MAGIC, 9)
 #define PIDFD_GET_UTS_NAMESPACE   _IO(PIDFS_IOCTL_MAGIC, 10)

+/*
+ * Special sentinel values which can be used to refer to the current thread or
+ * thread group leader (which from a userland perspective is the process).
+ */
+#define PIDFD_SELF PIDFD_SELF_THREAD
+#define PIDFD_SELF_PROCESS PIDFD_SELF_THREAD_GROUP
+
+#define PIDFD_SELF_THREAD  -1 /* Current thread. */
+#define PIDFD_SELF_THREAD_GROUP-2 /* Current thread group leader. 
*/
+
 #endif /* _UAPI_LINUX_PIDFD_H */
diff --git a/kernel/exit.c b/kernel/exit.c
index 619f0014c33b..e4f85ec4ba78 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -71,6 +71,7 @@
 #include 
 #include 

+#include 
 #include 

 #include 
@@ -1739,7 +1740,8 @@ int kernel_waitid_prepare(struct wait_opts *wo, int 
which, pid_t upid,
break;
case P_PIDFD:
type = PIDTYPE_PID;
-   if (upid < 0)
+   if (upid < 0 && upid != PIDFD_SELF_THREAD &&
+   upid != PIDFD_SELF_THREAD_GROUP)
return -EINVAL;

pid = pidfd_get_pid(upid, &f_flags);
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index dc952c3b05af..d239f7eeaa1f 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -550,6 +

Re: [PATCH] kvm: selftest: fix noop test in guest_memfd_test.c

2024-10-26 Thread Muhammad Usama Anjum
On 10/24/24 2:59 PM, Patrick Roy wrote:
> The loop in test_create_guest_memfd_invalid that is supposed to test
> that nothing is accepted as a valid flag to KVM_CREATE_GUEST_MEMFD was
> initializing `flag` as 0 instead of BIT(0). This caused the loop to
> immediately exit instead of iterating over BIT(0), BIT(1), ... .
> 
> Fixes: 8a89efd43423 ("KVM: selftests: Add basic selftest for guest_memfd()")
> Signed-off-by: Patrick Roy 
> ---
>  tools/testing/selftests/kvm/guest_memfd_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c 
> b/tools/testing/selftests/kvm/guest_memfd_test.c
> index ba0c8e9960358..ce687f8d248fc 100644
> --- a/tools/testing/selftests/kvm/guest_memfd_test.c
> +++ b/tools/testing/selftests/kvm/guest_memfd_test.c
> @@ -134,7 +134,7 @@ static void test_create_guest_memfd_invalid(struct kvm_vm 
> *vm)
>   size);
>   }
>  
> - for (flag = 0; flag; flag <<= 1) {
> + for (flag = BIT(0); flag; flag <<= 1) {
>   fd = __vm_create_guest_memfd(vm, page_size, flag);
>   TEST_ASSERT(fd == -1 && errno == EINVAL,
>   "guest_memfd() with flag '0x%lx' should fail with 
> EINVAL",
Reviewed-by: Muhammad Usama Anjum 

-- 
BR,
Muhammad Usama Anjum




[RESEND PATCH] x86/sgx: Use vmalloc_array() instead of vmalloc()

2024-10-26 Thread Thorsten Blum
Use vmalloc_array() instead of vmalloc() to calculate the number of
bytes to allocate.

Reviewed-by: Jarkko Sakkinen 
Signed-off-by: Thorsten Blum 
---
 arch/x86/kernel/cpu/sgx/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 9ace84486499..1a59e5956f4b 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -630,7 +630,7 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 
size,
if (!section->virt_addr)
return false;
 
-   section->pages = vmalloc(nr_pages * sizeof(struct sgx_epc_page));
+   section->pages = vmalloc_array(nr_pages, sizeof(struct sgx_epc_page));
if (!section->pages) {
memunmap(section->virt_addr);
return false;
-- 
2.47.0




[PATCH 0/3] remoteproc: qcom: pas: enable ADSP support on Qualcomm SAR2130P

2024-10-26 Thread Dmitry Baryshkov
Enable Audio DSP support on the Qualcomm SAR2130P platform. The CDSP,
also present on this SoC, crashes the device during the start and is
thus omitted from the series.

Signed-off-by: Dmitry Baryshkov 
---
Dmitry Baryshkov (3):
  dt-bindings: remoteproc: qcom,sm8350-pas: add SAR2130P aDSP compatible
  remoteproc: qcom: pas: add minidump_id to SM8350 resources
  remoteproc: qcom: pas: enable SAR2130P audio DSP support

 Documentation/devicetree/bindings/remoteproc/qcom,sm8350-pas.yaml | 3 +++
 drivers/remoteproc/qcom_q6v5_pas.c| 3 +++
 2 files changed, 6 insertions(+)
---
base-commit: a39230ecf6b3057f5897bc4744a790070cfbe7a8
change-id: 20241027-sar2130p-adsp-fc3fad54ded3

Best regards,
-- 
Dmitry Baryshkov 




[PATCH 1/3] dt-bindings: remoteproc: qcom,sm8350-pas: add SAR2130P aDSP compatible

2024-10-26 Thread Dmitry Baryshkov
Document compatible for audio DSP on Qualcomm SAR2130P platform.

Signed-off-by: Dmitry Baryshkov 
---
 Documentation/devicetree/bindings/remoteproc/qcom,sm8350-pas.yaml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,sm8350-pas.yaml 
b/Documentation/devicetree/bindings/remoteproc/qcom,sm8350-pas.yaml
index 
4b9fb74fb9e966b61d51fe578b636f967e4c6af8..fd3423e6051bc8bb0e783479360a7b38e5fa1358
 100644
--- a/Documentation/devicetree/bindings/remoteproc/qcom,sm8350-pas.yaml
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,sm8350-pas.yaml
@@ -16,6 +16,7 @@ description:
 properties:
   compatible:
 enum:
+  - qcom,sar2130p-adsp-pas
   - qcom,sm8350-adsp-pas
   - qcom,sm8350-cdsp-pas
   - qcom,sm8350-slpi-pas
@@ -61,6 +62,7 @@ allOf:
   properties:
 compatible:
   enum:
+- qcom,sar2130p-adsp-pas
 - qcom,sm8350-adsp-pas
 - qcom,sm8350-cdsp-pas
 - qcom,sm8350-slpi-pas
@@ -101,6 +103,7 @@ allOf:
   properties:
 compatible:
   enum:
+- qcom,sar2130p-adsp-pas
 - qcom,sm8350-adsp-pas
 - qcom,sm8350-slpi-pas
 - qcom,sm8450-adsp-pas

-- 
2.39.5




[PATCH 2/3] remoteproc: qcom: pas: add minidump_id to SM8350 resources

2024-10-26 Thread Dmitry Baryshkov
Specify minidump_id for the SM8350 DSPs. It was omitted for in the
original commit e8b4e9a21af7 ("remoteproc: qcom: pas: Add SM8350 PAS
remoteprocs").

Fixes: e8b4e9a21af7 ("remoteproc: qcom: pas: Add SM8350 PAS remoteprocs")
Signed-off-by: Dmitry Baryshkov 
---
 drivers/remoteproc/qcom_q6v5_pas.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/remoteproc/qcom_q6v5_pas.c 
b/drivers/remoteproc/qcom_q6v5_pas.c
index 
ef82835e98a4efd4bc603cff604d531a51fe9f9c..b10b4fc84f14eb40d64b278a339f2ceb45250a62
 100644
--- a/drivers/remoteproc/qcom_q6v5_pas.c
+++ b/drivers/remoteproc/qcom_q6v5_pas.c
@@ -923,6 +923,7 @@ static const struct adsp_data sm8350_adsp_resource = {
.crash_reason_smem = 423,
.firmware_name = "adsp.mdt",
.pas_id = 1,
+   .minidump_id = 5,
.auto_boot = true,
.proxy_pd_names = (char*[]){
"lcx",
@@ -1124,6 +1125,7 @@ static const struct adsp_data sm8350_cdsp_resource = {
.crash_reason_smem = 601,
.firmware_name = "cdsp.mdt",
.pas_id = 18,
+   .minidump_id = 7,
.auto_boot = true,
.proxy_pd_names = (char*[]){
"cx",

-- 
2.39.5




Re: [PATCH v2] selftests: tmpfs: Add kselftest support to tmpfs

2024-10-26 Thread Shuah Khan

On 10/26/24 13:16, Shivam Chaudhary wrote:

Add kselftest support for open, linkat, unshare, mount tests

- Replace direct error handling with
  `ksft_test_result_*` macros for better reporting
   of test outcomes.

- Add `ksft_print_header()` and `ksft_set_plan()`
  to structure test outputs more effectively.

- Introduce the helper function `is_unshare()` to
   handle unshare() related checks.

- Improve the test flow by adding more detailed pass/fail
   reporting for unshare, mounting, file opening, and linking
   operations.

- Skip the test if it's not run as root, providing an
   appropriate Warning.

Test logs:

Before change:

- Without root
  error: unshare, errno 1

- With root
  No, output

After change:

- Without root
  TAP version 13
  1..1
  ok 1 # SKIP This test needs root to run

- With root
  TAP version 13
  1..1
  ok 1 unshare(): we have a new mount namespace.
  1..2
  ok 2 mount(): Root filesystem private mount: Success
  1..3
  ok 3 mount(): Mounting tmpfs on /tmp: Success
  1..4
  ok 4 openat(): Open first temporary file: Success
  1..5
  ok 5 linkat(): Linking the temporary file: Success
  1..6
  ok 6 openat(): Opening the second temporary file: Success
  # Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0

Signed-off-by: Shivam Chaudhary 
---
Notes:
Changes in v2:
- Make the commit message more clear.
 
	link to v1: https://lore.kernel.org/all/20241024200228.1075840-1-cvam0...@gmail.com/T/#u


  .../selftests/tmpfs/bug-link-o-tmpfile.c  | 72 +++
  1 file changed, 58 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c 
b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
index b5c3ddb90942..26dea19c1614 100644
--- a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
+++ b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
@@ -23,45 +23,89 @@
  #include 
  #include 
  
-int main(void)

-{
-   int fd;
+#include "../kselftest.h"
  
-	if (unshare(CLONE_NEWNS) == -1) {

+static int is_unshare(int flag)


Why do you need a new routine for this? Looks at
other tests that do root check. You can use getuid
in the main*( before trying unshare.


+{
+   if (unshare(flag) == -1) {
if (errno == ENOSYS || errno == EPERM) {
-   fprintf(stderr, "error: unshare, errno %d\n", errno);
-   return 4;
+   ksft_test_result_fail("error: unshare, errno %d\n", 
errno);
+   return -1; // Return -1 for failure


Match the comment style in the file which /*


}
fprintf(stderr, "error: unshare, errno %d\n", errno);
+   return -1;
+   }
+
+   return 0; // Return 0 for success


Same comment here.


+}
+
+int main(void)
+{
+   int fd;
+
+   // Setting up kselftest framework
+   ksft_print_header();
+   ksft_set_plan(1);
+
+   // Check if test is run as root
+   if (geteuid()) {
+   ksft_test_result_skip("This test needs root to run!\n");
return 1;
}
-   if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) {
-   fprintf(stderr, "error: mount '/', errno %d\n", errno);
+
+   if (is_unshare(CLONE_NEWNS) == 0) {
+   ksft_test_result_pass("unshare(): we have a new mount 
namespace.\n");
+   } else {
+   ksft_test_result_fail("unshare(): failed\n");
return 1;
}
  
+	ksft_set_plan(2);


Move set_plan up to the top


+
+   if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) == -1) {
+   ksft_test_result_fail("mount(): Root filesystem private mount: Fail 
%d\n", errno);
+   return 1;
+   } else {
+   ksft_test_result_pass("mount(): Root filesystem private mount: 
Success\n");
+   }
+
+   ksft_set_plan(3);


Hmm. Why add another set_plan - one plan for all tests is sufficient.


/* Our heroes: 1 root inode, 1 O_TMPFILE inode, 1 permanent inode. */
if (mount(NULL, "/tmp", "tmpfs", 0, "nr_inodes=3") == -1) {
-   fprintf(stderr, "error: mount tmpfs, errno %d\n", errno);
+   ksft_test_result_fail("mount(): Mounting tmpfs on /tmp: Fail 
%d\n", errno);
return 1;
+   } else {
+   ksft_test_result_pass("mount(): Mounting tmpfs on /tmp: 
Success\n");
}
  
-	fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600);

+   ksft_set_plan(4);


Too many set_plans - check the usage in other tests.


+   fd = openat(AT_FDCWD, "/tmp", O_WRONLY | O_TMPFILE, 0600);
if (fd == -1) {
-   fprintf(stderr, "error: open 1, errno %d\n", errno);
+   ksft_test_result_fail("openat(): Open first temporary file: Fail 
%d\n", errno);
return 1;
+   } else {
+   ksft_test_result_pass("openat(): Open first temporary file: 
Success\n");
}
+
+   ksft_set_plan(5);


Ag

Re: [PATCH for-next 1/3] selftests/watchdog: add count parameter for watchdog-test

2024-10-26 Thread Shuah Khan

On 10/24/24 19:39, Li Zhijian wrote:

Currently, watchdog-test keep running until it gets a SIGINT. However,
when watchdog-test is executed from the kselftests framework, where it
launches test via timeout which will send SIGTERM in time up. This could
lead to
1. watchdog haven't stop, a watchdog reset is triggered to reboot the OS
in silent.
2. kselftests gets an timeout exit code, and judge watchdog-test as
   'not ok'


This test isn't really supposed to be run from kselftest framework.
This is the reason why it isn't included in the default run.


This patch is prepare to fix above 2 issues


This series needs a separate cover letter explaining how this problem is
being fixed.



Signed-off-by: Li Zhijian 
---
Hey,
Cover letter is here.

It's notice that a OS reboot was triggerred after ran the watchdog-test
in kselftests framwork 'make run_tests', that's because watchdog-test
didn't stop feeding the watchdog after enable it.

In addition, current watchdog-test didn't adapt to the kselftests
framework which launchs the test with /usr/bin/timeout and no timeout
is expected.
---
  tools/testing/selftests/watchdog/watchdog-test.c | 13 +
  1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/watchdog/watchdog-test.c 
b/tools/testing/selftests/watchdog/watchdog-test.c
index bc71cbca0dde..2f8fd2670897 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -27,7 +27,7 @@
  
  int fd;

  const char v = 'V';
-static const char sopts[] = "bdehp:st:Tn:NLf:i";
+static const char sopts[] = "bdehp:st:Tn:NLf:c:i";
  static const struct option lopts[] = {
{"bootstatus",  no_argument, NULL, 'b'},
{"disable", no_argument, NULL, 'd'},
@@ -42,6 +42,7 @@ static const struct option lopts[] = {
{"gettimeleft",   no_argument, NULL, 'L'},
{"file",  required_argument, NULL, 'f'},
{"info",  no_argument, NULL, 'i'},
+   {"count", required_argument, NULL, 'c'},
{NULL,  no_argument, NULL, 0x0}
  };
  
@@ -95,6 +96,7 @@ static void usage(char *progname)

printf(" -n, --pretimeout=T\tSet the pretimeout to T seconds\n");
printf(" -N, --getpretimeout\tGet the pretimeout\n");
printf(" -L, --gettimeleft\tGet the time left until timer expires\n");
+   printf(" -c, --count\tStop after feeding the watchdog count times\n");
printf("\n");
printf("Parameters are parsed left-to-right in real-time.\n");
printf("Example: %s -d -t 10 -p 5 -e\n", progname);
@@ -174,7 +176,7 @@ int main(int argc, char *argv[])
unsigned int ping_rate = DEFAULT_PING_RATE;
int ret;
int c;
-   int oneshot = 0;
+   int oneshot = 0, stop = 1, count = 0;
char *file = "/dev/watchdog";
struct watchdog_info info;
int temperature;
@@ -307,6 +309,9 @@ int main(int argc, char *argv[])
else
printf("WDIOC_GETTIMELEFT error '%s'\n", 
strerror(errno));
break;
+   case 'c':
+   stop = 0;
+   count = strtoul(optarg, NULL, 0);
case 'f':
/* Handled above */
break;
@@ -336,8 +341,8 @@ int main(int argc, char *argv[])
  
  	signal(SIGINT, term);
  
-	while (1) {

-   keep_alive();
+   while (stop || count--) {
+   exit_code = keep_alive();
sleep(ping_rate);
}
  end:





[PATCH 3/3] remoteproc: qcom: pas: enable SAR2130P audio DSP support

2024-10-26 Thread Dmitry Baryshkov
Enable support for the Audio DSP on the Qualcomm SAR2130P platform,
reusing the SM8350 resources.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/remoteproc/qcom_q6v5_pas.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/remoteproc/qcom_q6v5_pas.c 
b/drivers/remoteproc/qcom_q6v5_pas.c
index 
b10b4fc84f14eb40d64b278a339f2ceb45250a62..5944272bc2e414ea2258eb382452a74c1a742d13
 100644
--- a/drivers/remoteproc/qcom_q6v5_pas.c
+++ b/drivers/remoteproc/qcom_q6v5_pas.c
@@ -1423,6 +1423,7 @@ static const struct of_device_id adsp_of_match[] = {
{ .compatible = "qcom,sa8775p-cdsp1-pas", .data = 
&sa8775p_cdsp1_resource},
{ .compatible = "qcom,sa8775p-gpdsp0-pas", .data = 
&sa8775p_gpdsp0_resource},
{ .compatible = "qcom,sa8775p-gpdsp1-pas", .data = 
&sa8775p_gpdsp1_resource},
+   { .compatible = "qcom,sar2130p-adsp-pas", .data = 
&sm8350_adsp_resource},
{ .compatible = "qcom,sc7180-adsp-pas", .data = &sm8250_adsp_resource},
{ .compatible = "qcom,sc7180-mpss-pas", .data = &mpss_resource_init},
{ .compatible = "qcom,sc7280-adsp-pas", .data = &sm8350_adsp_resource},

-- 
2.39.5




Re: [PATCH net-next v10 23/23] testing/selftests: add test tool and scripts for ovpn module

2024-10-26 Thread Shuah Khan

On 10/25/24 03:14, Antonio Quartulli wrote:

The ovpn-cli tool can be compiled and used as selftest for the ovpn
kernel module.

It implements the netlink API and can thus be integrated in any
script for more automated testing.

Along with the tool, 4 scripts are added that perform basic
functionality tests by means of network namespaces.

Cc: sh...@kernel.org
Cc: linux-kselft...@vger.kernel.org
Signed-off-by: Antonio Quartulli 
---
  MAINTAINERS|1 +
  tools/testing/selftests/Makefile   |1 +
  tools/testing/selftests/net/ovpn/.gitignore|2 +
  tools/testing/selftests/net/ovpn/Makefile  |   17 +
  tools/testing/selftests/net/ovpn/config|   10 +
  tools/testing/selftests/net/ovpn/data64.key|5 +
  tools/testing/selftests/net/ovpn/ovpn-cli.c| 2370 
  tools/testing/selftests/net/ovpn/tcp_peers.txt |5 +
  .../testing/selftests/net/ovpn/test-chachapoly.sh  |9 +
  tools/testing/selftests/net/ovpn/test-float.sh |9 +
  tools/testing/selftests/net/ovpn/test-tcp.sh   |9 +
  tools/testing/selftests/net/ovpn/test.sh   |  183 ++
  tools/testing/selftests/net/ovpn/udp_peers.txt |5 +
  13 files changed, 2626 insertions(+)



What does the test output look like? Add that to the change log.


diff --git a/MAINTAINERS b/MAINTAINERS
index 
cf3d55c3e98aaea8f8817faed99dd7499cd59a71..110485aec73ae5bfeef4f228490ed76e28e01870
 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17295,6 +17295,7 @@ T:  git 
https://github.com/OpenVPN/linux-kernel-ovpn.git
  F:Documentation/netlink/specs/ovpn.yaml
  F:drivers/net/ovpn/
  F:include/uapi/linux/ovpn.h
+F: tools/testing/selftests/net/ovpn/
  
  OPENVSWITCH

  M:Pravin B Shelar 
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 
363d031a16f7e14152c904e6b68dab1f90c98392..be42906ecb11d4b0f9866d2c04b0e8fb27a2b995
 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -68,6 +68,7 @@ TARGETS += net/hsr
  TARGETS += net/mptcp
  TARGETS += net/netfilter
  TARGETS += net/openvswitch
+TARGETS += net/ovpn
  TARGETS += net/packetdrill
  TARGETS += net/rds
  TARGETS += net/tcp_ao
diff --git a/tools/testing/selftests/net/ovpn/.gitignore 
b/tools/testing/selftests/net/ovpn/.gitignore
new file mode 100644
index 
..ee44c081ca7c089933659689303c303a9fa9713b
--- /dev/null
+++ b/tools/testing/selftests/net/ovpn/.gitignore
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0+
+ovpn-cli
diff --git a/tools/testing/selftests/net/ovpn/Makefile 
b/tools/testing/selftests/net/ovpn/Makefile
new file mode 100644
index 
..c76d8fd953c5674941c8c2787813063b1bce180f
--- /dev/null
+++ b/tools/testing/selftests/net/ovpn/Makefile
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020-2024 OpenVPN, Inc.
+#
+CFLAGS = -pedantic -Wextra -Wall -Wl,--no-as-needed -g -O0 -ggdb 
$(KHDR_INCLUDES)
+CFLAGS += $(shell pkg-config --cflags libnl-3.0 libnl-genl-3.0)
+
+LDFLAGS = -lmbedtls -lmbedcrypto
+LDFLAGS += $(shell pkg-config --libs libnl-3.0 libnl-genl-3.0)
+
+TEST_PROGS = test.sh \
+   test-chachapoly.sh \
+   test-tcp.sh \
+   test-float.sh
+
+TEST_GEN_FILES = ovpn-cli
+
+include ../../lib.mk
diff --git a/tools/testing/selftests/net/ovpn/config 
b/tools/testing/selftests/net/ovpn/config
new file mode 100644
index 
..71946ba9fa175c191725e369eb9b973503d9d9c4
--- /dev/null
+++ b/tools/testing/selftests/net/ovpn/config
@@ -0,0 +1,10 @@
+CONFIG_NET=y
+CONFIG_INET=y
+CONFIG_STREAM_PARSER=y
+CONFIG_NET_UDP_TUNNEL=y
+CONFIG_DST_CACHE=y
+CONFIG_CRYPTO=y
+CONFIG_CRYPTO_AES=y
+CONFIG_CRYPTO_GCM=y
+CONFIG_CRYPTO_CHACHA20POLY1305=y
+CONFIG_OVPN=m
diff --git a/tools/testing/selftests/net/ovpn/data64.key 
b/tools/testing/selftests/net/ovpn/data64.key
new file mode 100644
index 
..a99e88c4e290f58b12f399b857b873f308d9ba09
--- /dev/null
+++ b/tools/testing/selftests/net/ovpn/data64.key
@@ -0,0 +1,5 @@
+jRqMACN7d7/aFQNT8S7jkrBD8uwrgHbG5OQZP2eu4R1Y7tfpS2bf5RHv06Vi163CGoaIiTX99R3B
+ia9ycAH8Wz1+9PWv51dnBLur9jbShlgZ2QHLtUc4a/gfT7zZwULXuuxdLnvR21DDeMBaTbkgbai9
+uvAa7ne1liIgGFzbv+Bas4HDVrygxIxuAnP5Qgc3648IJkZ0QEXPF+O9f0n5+QIvGCxkAUVx+5K6
+KIs+SoeWXnAopELmoGSjUpFtJbagXK82HfdqpuUxT2Tnuef0/14SzVE/vNleBNu2ZbyrSAaah8tE
+BofkPJUBFY+YQcfZNM5Dgrw3i+Bpmpq/gpdg5w==
diff --git a/tools/testing/selftests/net/ovpn/ovpn-cli.c 
b/tools/testing/selftests/net/ovpn/ovpn-cli.c
new file mode 100644
index 
..046dd069aaaf4e5b091947bd57ed79f8519a780f
--- /dev/null
+++ b/tools/testing/selftests/net/ovpn/ovpn-cli.c
@@ -0,0 +1,2370 @@
+// SPDX-License-Identifier: GPL-2.0
+/*  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2020-2024 OpenVPN, Inc.
+ *
+ *  Author:Antonio Quartull

Re: [PATCH] selftests/mount_setattr: fix idmap_mount_tree_invalid failed to run

2024-10-26 Thread Shuah Khan

On 10/25/24 02:08, zhouyuhang wrote:



在 2024/10/24 22:26, Shuah Khan 写道:

On 10/24/24 03:50, zhouyuhang wrote:

From: zhouyuhang 

Test case idmap_mount_tree_invalid failed to run on the newer kernel
with the following output:

  #  RUN mount_setattr_idmapped.idmap_mount_tree_invalid ...
  # mount_setattr_test.c:1428:idmap_mount_tree_invalid:Expected 
sys_mount_setattr(open_tree_fd, "", AT_EMPTY_PATH, &attr, sizeof(attr)) (0) ! = 
0 (0)
  # idmap_mount_tree_invalid: Test terminated by assertion

This is because tmpfs is mounted at "/mnt/A", and tmpfs already
contains the flag FS_ALLOW_IDMAP after the commit 7a80e5b8c6fa ("shmem:
support idmapped mounts for tmpfs"). So calling sys_mount_setattr here
returns 0 instead of -EINVAL as expected.

Ramfs is mounted at "/mnt/B" and does not support idmap mounts.
So we can use "/mnt/B" instead of "/mnt/A" to make the test run
successfully with the following output:

  # Starting 1 tests from 1 test cases.
  #  RUN mount_setattr_idmapped.idmap_mount_tree_invalid ...
  #    OK mount_setattr_idmapped.idmap_mount_tree_invalid
  ok 1 mount_setattr_idmapped.idmap_mount_tree_invalid
  # PASSED: 1 / 1 tests passed.



Sounds like this code is testing this very condition passing
in invalid mount to see what happens. If that is the intent
this patch is incorrect.



I think I probably understand what you mean, what you're saying is that the 
output of this line of errors is the condition,
and the main purpose of the test case is to see what happens when it invalid 
mount. But it's valid now, isn't it?
So we need to fix it. I don't think that constructing this error with ramfs 
will have any impact on the code that follows.
If you feel that using "/mnt/B" is unreliable, I think we can temporarily mount ramfs to 
"/mnt/A" here and continue using "/mnt/A".
Do you think this is feasible? Looking forward to your reply, thank you.



What I am saying is if this test is intended to test invalid mounts, passing
"/mnt/A" makes perfect sense.


Signed-off-by: zhouyuhang 
---
  tools/testing/selftests/mount_setattr/mount_setattr_test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/mount_setattr/mount_setattr_test.c 
b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
index c6a8c732b802..54552c19bc24 100644
--- a/tools/testing/selftests/mount_setattr/mount_setattr_test.c
+++ b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
@@ -1414,7 +1414,7 @@ TEST_F(mount_setattr_idmapped, idmap_mount_tree_invalid)
  ASSERT_EQ(expected_uid_gid(-EBADF, "/tmp/B/b", 0, 0, 0), 0);
  ASSERT_EQ(expected_uid_gid(-EBADF, "/tmp/B/BB/b", 0, 0, 0), 0);
  -    open_tree_fd = sys_open_tree(-EBADF, "/mnt/A",
+    open_tree_fd = sys_open_tree(-EBADF, "/mnt/B",
   AT_RECURSIVE |
   AT_EMPTY_PATH |
   AT_NO_AUTOMOUNT |


thanks,
-- Shuah




thanks,
-- Shuah



[PATCH v2] selftests: tmpfs: Add kselftest support to tmpfs

2024-10-26 Thread Shivam Chaudhary
Add kselftest support for open, linkat, unshare, mount tests

- Replace direct error handling with
 `ksft_test_result_*` macros for better reporting
  of test outcomes.

- Add `ksft_print_header()` and `ksft_set_plan()`
 to structure test outputs more effectively.

- Introduce the helper function `is_unshare()` to
  handle unshare() related checks.

- Improve the test flow by adding more detailed pass/fail
  reporting for unshare, mounting, file opening, and linking
  operations.

- Skip the test if it's not run as root, providing an
  appropriate Warning.

Test logs:

Before change:

- Without root
 error: unshare, errno 1

- With root
 No, output

After change:

- Without root
 TAP version 13
 1..1
 ok 1 # SKIP This test needs root to run

- With root
 TAP version 13
 1..1
 ok 1 unshare(): we have a new mount namespace.
 1..2
 ok 2 mount(): Root filesystem private mount: Success
 1..3
 ok 3 mount(): Mounting tmpfs on /tmp: Success
 1..4
 ok 4 openat(): Open first temporary file: Success
 1..5
 ok 5 linkat(): Linking the temporary file: Success
 1..6
 ok 6 openat(): Opening the second temporary file: Success
 # Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0

Signed-off-by: Shivam Chaudhary 
---
Notes:
Changes in v2:
- Make the commit message more clear.

link to v1: 
https://lore.kernel.org/all/20241024200228.1075840-1-cvam0...@gmail.com/T/#u

 .../selftests/tmpfs/bug-link-o-tmpfile.c  | 72 +++
 1 file changed, 58 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c 
b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
index b5c3ddb90942..26dea19c1614 100644
--- a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
+++ b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
@@ -23,45 +23,89 @@
 #include 
 #include 
 
-int main(void)
-{
-   int fd;
+#include "../kselftest.h"
 
-   if (unshare(CLONE_NEWNS) == -1) {
+static int is_unshare(int flag)
+{
+   if (unshare(flag) == -1) {
if (errno == ENOSYS || errno == EPERM) {
-   fprintf(stderr, "error: unshare, errno %d\n", errno);
-   return 4;
+   ksft_test_result_fail("error: unshare, errno %d\n", 
errno);
+   return -1; // Return -1 for failure
}
fprintf(stderr, "error: unshare, errno %d\n", errno);
+   return -1;
+   }
+
+   return 0; // Return 0 for success
+}
+
+int main(void)
+{
+   int fd;
+
+   // Setting up kselftest framework
+   ksft_print_header();
+   ksft_set_plan(1);
+
+   // Check if test is run as root
+   if (geteuid()) {
+   ksft_test_result_skip("This test needs root to run!\n");
return 1;
}
-   if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) {
-   fprintf(stderr, "error: mount '/', errno %d\n", errno);
+
+   if (is_unshare(CLONE_NEWNS) == 0) {
+   ksft_test_result_pass("unshare(): we have a new mount 
namespace.\n");
+   } else {
+   ksft_test_result_fail("unshare(): failed\n");
return 1;
}
 
+   ksft_set_plan(2);
+
+   if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) == -1) {
+   ksft_test_result_fail("mount(): Root filesystem private mount: 
Fail %d\n", errno);
+   return 1;
+   } else {
+   ksft_test_result_pass("mount(): Root filesystem private mount: 
Success\n");
+   }
+
+   ksft_set_plan(3);
/* Our heroes: 1 root inode, 1 O_TMPFILE inode, 1 permanent inode. */
if (mount(NULL, "/tmp", "tmpfs", 0, "nr_inodes=3") == -1) {
-   fprintf(stderr, "error: mount tmpfs, errno %d\n", errno);
+   ksft_test_result_fail("mount(): Mounting tmpfs on /tmp: Fail 
%d\n", errno);
return 1;
+   } else {
+   ksft_test_result_pass("mount(): Mounting tmpfs on /tmp: 
Success\n");
}
 
-   fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600);
+   ksft_set_plan(4);
+   fd = openat(AT_FDCWD, "/tmp", O_WRONLY | O_TMPFILE, 0600);
if (fd == -1) {
-   fprintf(stderr, "error: open 1, errno %d\n", errno);
+   ksft_test_result_fail("openat(): Open first temporary file: 
Fail %d\n", errno);
return 1;
+   } else {
+   ksft_test_result_pass("openat(): Open first temporary file: 
Success\n");
}
+
+   ksft_set_plan(5);
if (linkat(fd, "", AT_FDCWD, "/tmp/1", AT_EMPTY_PATH) == -1) {
-   fprintf(stderr, "error: linkat, errno %d\n", errno);
+   ksft_test_result_fail("linkat(): Linking the temporary file: 
Fail %d\n", errno);
+   close(fd); // Ensure fd is closed on failure
return 1;
+   } else {
+   ksft_test_result_pass("linkat(): Linking the temporary file: 
Success\n");
 

Re: [PATCH v5 2/5] pidfd: add PIDFD_SELF_* sentinels to refer to own thread/process

2024-10-26 Thread Lorenzo Stoakes
On Fri, Oct 25, 2024 at 01:31:49PM -0700, John Hubbard wrote:
> On 10/25/24 12:49 PM, Lorenzo Stoakes wrote:
> > On Fri, Oct 25, 2024 at 11:44:34AM -0700, John Hubbard wrote:
> > > On 10/25/24 11:38 AM, Pedro Falcato wrote:
> > > > On Fri, Oct 25, 2024 at 6:41 PM John Hubbard  
> > > > wrote:
> ...
> > > > That seems to only apply to the kernel internally, uapi headers are
> > >
> > > Yes.
> > >
> > > > included from userspace too (-std=c89 -pedantic doesn't know what a
> > > > gnu extension is). And uapi headers _generally_ keep to defining
> > > > constants and structs, nothing more.
> > >
> > > OK
> >
> > Because a lot of people using -ANSI- C89 are importing a very new linux
> > feature header.
>
> I'll admit to being easily cowed by "you're breaking userspace" arguments.
> Even when they start to get rather absurd. Because I can't easily tell where
> the line is.
>
> Maybe "-std=c89 -pedantic" is on the other side of the line. I'd like it
> to be! :)

Well, apparently not...

>
> >
> > And let's ignore the hundreds of existing uses... OK.
> >
> > The rules, unstated anywhere, are that we must support 1972-era C in an
> > optional header for a feature available only in new kernels because
> > somebody somewhere is using a VAX-11 and gosh darn it they can't change
> > their toolchain!
> >
> > And you had better make sure you don't wear out those tape drums...
> >
> > >
> > > > I don't know what the guidelines for uapi headers are nowadays, but we
> > > > generally want to not break userspace.
> > > >
> > > > >
> > > > > I think it's quite clear at this point, that we should not hold up new
> > > > > work, based on concerns about handling the inline keyword, nor about
> > > > > C89.
> > > >
> > > > Right, but the correct solution is probably to move
> > > > pidfd_is_self_sentinel to some other place, since it's not even
> > > > supposed to be used by userspace (it's semantically useless to
> > > > userspace, and it's only two users are in the kernel, kernel/pid.c and
> > > > exit.c).
> > > >
> > >
> > > Yes, if userspace absolutely doesn't need nor want this, then putting
> > > it in a non-uapi header does sound like the right move.
> >
> > The bike shed should be blue! Wait no no, it should be red... Hang on
> > yellow yes! Yellow's great!
>
> Putting a header in the right location, so as to avoid breakage here or
> there, is not bikeshedding. Sorry.

There are 312 uses of "static inline" already in UAPI headers, not all
quite as obscure as claimed.

Specifically requiring me and only me to support ansi C89 for a theorised
scenario is in my opinion bikeshedding, but I don't want to get into an
argument about something so petty :)

>
> >
> > No wait - did we _test_ yellow in the way I wanted...
> >
> > I mean for me this isn't a big deal - we declare the defines here, it makes
> > sense to have a very very simple inline function.
> >
> > It's not like userspace is overly hurt by this...
> >
> > Also I did explain there's no obvious header to put this in in the kernel
> > and I'm not introducing one sorry.
> >
> > ANyway if you guys feel strong enough about this, I'll respin again and
> > just open-code this trivial check where it's used.
>
> No strong feelings, just hoping to help make a choice that gets you
> closer to getting your patches committed.

I mean, you are saying I am breaking things and implying the series is
blocked on this, that sounds like a strong opinion, but again I'm not going
to argue.

As with the requirement that I, only for my part of the change, must fix up
test header import, while I disagree I should be doing the fix, I did it
anyway as I am accommodating and reasonable.

So fine - I'll respin and just open-code this as it's trivial and there's
no (other) sensible place to put it anyway.

A P.S. though - a very NOT theoretical issue with userspace is the import
of linux/fcntl.h in pidfd.h which seems to me to have been imported solely
for the kernel's sake.

A gentle suggestion (it seems I can't win - gentle suggestions are ignored,
tongue-in-cheek parody is taken to be mean... but anyway) is to do
something like:

#ifdef __KERNEL__
#include 
#else
#include 
#endif

At the top of the pidfd.h header. This must surely sting a _lot_ of people
in userland otherwise.

But this is out of scope for this change.



[PATCH v6 5/5] selftests: pidfd: add tests for PIDFD_SELF_*

2024-10-26 Thread Lorenzo Stoakes
Add tests to assert that PIDFD_SELF_* correctly refers to the current
thread and process.

This is only practically meaningful to pidfd_send_signal() and
pidfd_getfd(), but also explicitly test that we disallow this feature for
setns() where it would make no sense.

We cannot reasonably wait on ourself using waitid(P_PIDFD, ...) so while in
theory PIDFD_SELF_* would work here, we'd be left blocked if we tried it.

We defer testing of mm-specific functionality which uses pidfd, namely
process_madvise() and process_mrelease() to mm testing (though note the
latter can not be sensibly tested as it would require the testing process
to be dying).

Reviewed-by: Shuah Khan 
Signed-off-by: Lorenzo Stoakes 
---
 tools/testing/selftests/pidfd/pidfd.h |   2 +
 .../selftests/pidfd/pidfd_getfd_test.c| 141 ++
 .../selftests/pidfd/pidfd_setns_test.c|  11 ++
 tools/testing/selftests/pidfd/pidfd_test.c|  76 --
 4 files changed, 218 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/pidfd/pidfd.h 
b/tools/testing/selftests/pidfd/pidfd.h
index 0f3fc51cec73..1dbe48c1cf46 100644
--- a/tools/testing/selftests/pidfd/pidfd.h
+++ b/tools/testing/selftests/pidfd/pidfd.h
@@ -16,6 +16,8 @@
 #include 
 #include 
 
+#include 
+
 #include "../kselftest.h"
 #include "pidfd_helpers.h"
 
diff --git a/tools/testing/selftests/pidfd/pidfd_getfd_test.c 
b/tools/testing/selftests/pidfd/pidfd_getfd_test.c
index cd51d547b751..48d224b13c01 100644
--- a/tools/testing/selftests/pidfd/pidfd_getfd_test.c
+++ b/tools/testing/selftests/pidfd/pidfd_getfd_test.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -114,6 +116,94 @@ static int child(int sk)
return ret;
 }
 
+static int __pidfd_self_thread_worker(unsigned long page_size)
+{
+   int memfd;
+   int newfd;
+   char *ptr;
+   int err = 0;
+
+   /*
+* Unshare our FDs so we have our own set. This means
+* PIDFD_SELF_THREAD_GROUP will fal.
+*/
+   if (unshare(CLONE_FILES) < 0) {
+   err = -errno;
+   goto exit;
+   }
+
+   /* Truncate, map in and write to our memfd. */
+   memfd = sys_memfd_create("test_self_child", 0);
+   if (memfd < 0) {
+   err = -errno;
+   goto exit;
+   }
+
+   if (ftruncate(memfd, page_size)) {
+   err = -errno;
+   goto exit_close_memfd;
+   }
+
+   ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
+  MAP_SHARED, memfd, 0);
+   if (ptr == MAP_FAILED) {
+   err = -errno;
+   goto exit_close_memfd;
+   }
+   ptr[0] = 'y';
+   if (munmap(ptr, page_size)) {
+   err = -errno;
+   goto exit_close_memfd;
+   }
+
+   /* Get a thread-local duplicate of our memfd. */
+   newfd = sys_pidfd_getfd(PIDFD_SELF_THREAD, memfd, 0);
+   if (newfd < 0) {
+   err = -errno;
+   goto exit_close_memfd;
+   }
+
+   if (memfd == newfd) {
+   err = -EINVAL;
+   goto exit_close_fds;
+   }
+
+   /* Map in new fd and make sure that the data is as expected. */
+   ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
+  MAP_SHARED, newfd, 0);
+   if (ptr == MAP_FAILED) {
+   err = -errno;
+   goto exit_close_fds;
+   }
+
+   if (ptr[0] != 'y') {
+   err = -EINVAL;
+   goto exit_close_fds;
+   }
+
+   if (munmap(ptr, page_size)) {
+   err = -errno;
+   goto exit_close_fds;
+   }
+
+exit_close_fds:
+   close(newfd);
+exit_close_memfd:
+   close(memfd);
+exit:
+   return err;
+}
+
+static void *pidfd_self_thread_worker(void *arg)
+{
+   unsigned long page_size = (unsigned long)arg;
+   int ret;
+
+   /* We forward any errors for the caller to handle. */
+   ret = __pidfd_self_thread_worker(page_size);
+   return (void *)(intptr_t)ret;
+}
+
 FIXTURE(child)
 {
/*
@@ -264,6 +354,57 @@ TEST_F(child, no_strange_EBADF)
EXPECT_EQ(errno, ESRCH);
 }
 
+TEST(pidfd_self)
+{
+   int memfd = sys_memfd_create("test_self", 0);
+   unsigned long page_size = sysconf(_SC_PAGESIZE);
+   int newfd;
+   char *ptr;
+   pthread_t thread;
+   void *res;
+   int err;
+
+   ASSERT_GE(memfd, 0);
+   ASSERT_EQ(ftruncate(memfd, page_size), 0);
+
+   /*
+* Map so we can assert that the duplicated fd references the same
+* memory.
+*/
+   ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
+  MAP_SHARED, memfd, 0);
+   ASSERT_NE(ptr, MAP_FAILED);
+   ptr[0] = 'x';
+   ASSERT_EQ(munmap(ptr, page_size), 0);
+
+   /* Now get a duplicate of our memfd. */
+   newfd = sy

[PATCH v6 0/5] introduce PIDFD_SELF* sentinels

2024-10-26 Thread Lorenzo Stoakes
If you wish to utilise a pidfd interface to refer to the current process or
thread it is rather cumbersome, requiring something like:

int pidfd = pidfd_open(getpid(), 0 or PIDFD_THREAD);

...

close(pidfd);

Or the equivalent call opening /proc/self. It is more convenient to use a
sentinel value to indicate to an interface that accepts a pidfd that we
simply wish to refer to the current process thread.

This series introduces sentinels for this purposes which can be passed as
the pidfd in this instance rather than having to establish a dummy fd for
this purpose.

It is useful to refer to both the current thread from the userland's
perspective for which we use PIDFD_SELF, and the current process from the
userland's perspective, for which we use PIDFD_SELF_PROCESS.

There is unfortunately some confusion between the kernel and userland as to
what constitutes a process - a thread from the userland perspective is a
process in userland, and a userland process is a thread group (more
specifically the thread group leader from the kernel perspective). We
therefore alias things thusly:

* PIDFD_SELF_THREAD aliased by PIDFD_SELF - use PIDTYPE_PID.
* PIDFD_SELF_THREAD_GROUP alised by PIDFD_SELF_PROCESS - use PIDTYPE_TGID.

In all of the kernel code we refer to PIDFD_SELF_THREAD and
PIDFD_SELF_THREAD_GROUP. However we expect users to use PIDFD_SELF and
PIDFD_SELF_PROCESS.

This matters for cases where, for instance, a user unshare()'s FDs or does
thread-specific signal handling and where the user would be hugely confused
if the FDs referenced or signal processed referred to the thread group
leader rather than the individual thread.

We ensure that pidfd_send_signal() and pidfd_getfd() work correctly, and
assert as much in selftests. All other interfaces except setns() will work
implicitly with this new interface, however it doesn't make sense to test
waitid(P_PIDFD, ...) as waiting on ourselves is a blocking operation.

In the case of setns() we explicitly disallow use of PIDFD_SELF* as it
doesn't make sense to obtain the namespaces of our own process, and it
would require work to implement this functionality there that would be of
no use.

We also do not provide the ability to utilise PIDFD_SELF* in ordinary fd
operations such as open() or poll(), as this would require extensive work
and be of no real use.

v6:
* Avoid static inline in UAPI header as suggested by Pedro.
* Place PIDFD_SELF values out of range of errors and any other sentinel as
  suggested by Pedro.

v5:
* Fixup self test dependencies on pidfd/pidfd.h.
https://lore.kernel.org/linux-mm/cover.1729848252.git.lorenzo.stoa...@oracle.com/

v4:
* Avoid returning an fd in the __pidfd_get_pid() function as pointed out by
  Christian, instead simply always pin the pid and maintain fd scope in the
  helper alone.
* Add wrapper header file in tools/include/linux to allow for import of
  UAPI pidfd.h header without encountering the collision between system
  fcntl.h and linux/fcntl.h as discussed with Shuah and John.
* Fixup tests to import the UAPI pidfd.h header working around conflicts
  between system fcntl.h and linux/fcntl.h which the UAPI pidfd.h imports,
  as reported by Shuah.
* Use an int for pidfd_is_self_sentinel() to avoid any dependency on
  stdbool.h in userland.
https://lore.kernel.org/linux-mm/cover.1729198898.git.lorenzo.stoa...@oracle.com/

v3:
* Do not fput() an invalid fd as reported by kernel test bot.
* Fix unintended churn from moving variable declaration.
https://lore.kernel.org/linux-mm/cover.1729073310.git.lorenzo.stoa...@oracle.com/

v2:
* Fix tests as reported by Shuah.
* Correct RFC version lore link.
https://lore.kernel.org/linux-mm/cover.1728643714.git.lorenzo.stoa...@oracle.com/

Non-RFC v1:
* Removed RFC tag - there seems to be general consensus that this change is
  a good idea, but perhaps some debate to be had on implementation. It
  seems sensible then to move forward with the RFC flag removed.
* Introduced PIDFD_SELF_THREAD, PIDFD_SELF_THREAD_GROUP and their aliases
  PIDFD_SELF and PIDFD_SELF_PROCESS respectively.
* Updated testing accordingly.
https://lore.kernel.org/linux-mm/cover.1728578231.git.lorenzo.stoa...@oracle.com/

RFC version:
https://lore.kernel.org/linux-mm/cover.1727644404.git.lorenzo.stoa...@oracle.com/

Lorenzo Stoakes (5):
  pidfd: extend pidfd_get_pid() and de-duplicate pid lookup
  pidfd: add PIDFD_SELF_* sentinels to refer to own thread/process
  tools: testing: separate out wait_for_pid() into helper header
  selftests: pidfd: add pidfd.h UAPI wrapper
  selftests: pidfd: add tests for PIDFD_SELF_*

 include/linux/pid.h   |  34 -
 include/uapi/linux/pidfd.h|  10 ++
 kernel/exit.c |   4 +-
 kernel/nsproxy.c  |   1 +
 kernel/pid.c  |  65 +---
 kernel/signal.c   |  29 +---
 tools/include/linux/pidfd.h  

[PATCH v6 3/5] tools: testing: separate out wait_for_pid() into helper header

2024-10-26 Thread Lorenzo Stoakes
It seems tests other than the pidfd tests use the wait_for_pid() function
declared in pidfd.h.

Since we will shortly be modifying pidfd.h in a way that might clash with
other tests, separate this out and update tests accordingly.

Signed-off-by: Lorenzo Stoakes 
---
 tools/testing/selftests/cgroup/test_kill.c|  2 +-
 .../pid_namespace/regression_enomem.c |  2 +-
 tools/testing/selftests/pidfd/pidfd.h | 26 +
 tools/testing/selftests/pidfd/pidfd_helpers.h | 39 +++
 4 files changed, 42 insertions(+), 27 deletions(-)
 create mode 100644 tools/testing/selftests/pidfd/pidfd_helpers.h

diff --git a/tools/testing/selftests/cgroup/test_kill.c 
b/tools/testing/selftests/cgroup/test_kill.c
index 0e5bb6c7307a..2367f645fe89 100644
--- a/tools/testing/selftests/cgroup/test_kill.c
+++ b/tools/testing/selftests/cgroup/test_kill.c
@@ -10,7 +10,7 @@
 #include 
 
 #include "../kselftest.h"
-#include "../pidfd/pidfd.h"
+#include "../pidfd/pidfd_helpers.h"
 #include "cgroup_util.h"
 
 /*
diff --git a/tools/testing/selftests/pid_namespace/regression_enomem.c 
b/tools/testing/selftests/pid_namespace/regression_enomem.c
index 7d84097ad45c..f3e6989c8069 100644
--- a/tools/testing/selftests/pid_namespace/regression_enomem.c
+++ b/tools/testing/selftests/pid_namespace/regression_enomem.c
@@ -12,7 +12,7 @@
 #include 
 
 #include "../kselftest_harness.h"
-#include "../pidfd/pidfd.h"
+#include "../pidfd/pidfd_helpers.h"
 
 /*
  * Regression test for:
diff --git a/tools/testing/selftests/pidfd/pidfd.h 
b/tools/testing/selftests/pidfd/pidfd.h
index 88d6830ee004..0f3fc51cec73 100644
--- a/tools/testing/selftests/pidfd/pidfd.h
+++ b/tools/testing/selftests/pidfd/pidfd.h
@@ -17,6 +17,7 @@
 #include 
 
 #include "../kselftest.h"
+#include "pidfd_helpers.h"
 
 #ifndef P_PIDFD
 #define P_PIDFD 3
@@ -68,31 +69,6 @@
 #define PIDFD_SKIP 3
 #define PIDFD_XFAIL 4
 
-static inline int wait_for_pid(pid_t pid)
-{
-   int status, ret;
-
-again:
-   ret = waitpid(pid, &status, 0);
-   if (ret == -1) {
-   if (errno == EINTR)
-   goto again;
-
-   ksft_print_msg("waitpid returned -1, errno=%d\n", errno);
-   return -1;
-   }
-
-   if (!WIFEXITED(status)) {
-   ksft_print_msg(
-  "waitpid !WIFEXITED, WIFSIGNALED=%d, WTERMSIG=%d\n",
-  WIFSIGNALED(status), WTERMSIG(status));
-   return -1;
-   }
-
-   ret = WEXITSTATUS(status);
-   return ret;
-}
-
 static inline int sys_pidfd_open(pid_t pid, unsigned int flags)
 {
return syscall(__NR_pidfd_open, pid, flags);
diff --git a/tools/testing/selftests/pidfd/pidfd_helpers.h 
b/tools/testing/selftests/pidfd/pidfd_helpers.h
new file mode 100644
index ..5637bfe888de
--- /dev/null
+++ b/tools/testing/selftests/pidfd/pidfd_helpers.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __PIDFD_HELPERS_H
+#define __PIDFD_HELPERS_H
+
+#define _GNU_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../kselftest.h"
+
+static inline int wait_for_pid(pid_t pid)
+{
+   int status, ret;
+
+again:
+   ret = waitpid(pid, &status, 0);
+   if (ret == -1) {
+   if (errno == EINTR)
+   goto again;
+
+   ksft_print_msg("waitpid returned -1, errno=%d\n", errno);
+   return -1;
+   }
+
+   if (!WIFEXITED(status)) {
+   ksft_print_msg(
+  "waitpid !WIFEXITED, WIFSIGNALED=%d, WTERMSIG=%d\n",
+  WIFSIGNALED(status), WTERMSIG(status));
+   return -1;
+   }
+
+   ret = WEXITSTATUS(status);
+   return ret;
+}
+
+#endif /* __PIDFD_HELPERS_H */
-- 
2.47.0




[PATCH v6 4/5] selftests: pidfd: add pidfd.h UAPI wrapper

2024-10-26 Thread Lorenzo Stoakes
Conflicts can arise between system fcntl.h and linux/fcntl.h, imported by
the linux/pidfd.h UAPI header.

Work around this by adding a wrapper for linux/pidfd.h to
tools/include/ which sets the linux/fcntl.h header guard ahead of
importing the pidfd.h header file.

Adjust the pidfd selftests Makefile to reference this include directory and
put it at a higher precidence than any make header installed headers to
ensure the wrapper is preferred.

This way we can directly import the UAPI header file without issue, use the
latest system header file without having to duplicate anything.

Reviewed-by: Shuah Khan 
Signed-off-by: Lorenzo Stoakes 
---
 tools/include/linux/pidfd.h| 14 ++
 tools/testing/selftests/pidfd/Makefile |  3 +--
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 tools/include/linux/pidfd.h

diff --git a/tools/include/linux/pidfd.h b/tools/include/linux/pidfd.h
new file mode 100644
index ..113c8023072d
--- /dev/null
+++ b/tools/include/linux/pidfd.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _TOOLS_LINUX_PIDFD_H
+#define _TOOLS_LINUX_PIDFD_H
+
+/*
+ * Some systems have issues with the linux/fcntl.h import in linux/pidfd.h, so
+ * work around this by setting the header guard.
+ */
+#define _LINUX_FCNTL_H
+#include "../../../include/uapi/linux/pidfd.h"
+#undef _LINUX_FCNTL_H
+
+#endif /* _TOOLS_LINUX_PIDFD_H */
diff --git a/tools/testing/selftests/pidfd/Makefile 
b/tools/testing/selftests/pidfd/Makefile
index d731e3e76d5b..f5038c9dae14 100644
--- a/tools/testing/selftests/pidfd/Makefile
+++ b/tools/testing/selftests/pidfd/Makefile
@@ -1,8 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
-CFLAGS += -g $(KHDR_INCLUDES) -pthread -Wall
+CFLAGS += -g -isystem $(top_srcdir)/tools/include $(KHDR_INCLUDES) -pthread 
-Wall
 
 TEST_GEN_PROGS := pidfd_test pidfd_fdinfo_test pidfd_open_test \
pidfd_poll_test pidfd_wait pidfd_getfd_test pidfd_setns_test
 
 include ../lib.mk
-
-- 
2.47.0




[PATCH v6 1/5] pidfd: extend pidfd_get_pid() and de-duplicate pid lookup

2024-10-26 Thread Lorenzo Stoakes
The means by which a pid is determined from a pidfd is duplicated, with
some callers holding a reference to the (pid)fd, and others explicitly
pinning the pid.

Introduce __pidfd_get_pid() which narrows this to one approach of pinning
the pid, with an optional output parameters for file->f_flags to avoid the
need to hold onto a file to retrieve this.

Additionally, allow the ability to open a pidfd by opening a /proc/
directory, utilised by the pidfd_send_signal() system call, providing a
pidfd_get_pid_proc() helper function to do so.

Doing this allows us to eliminate open-coded pidfd pid lookup and to
consistently handle this in one place.

This lays the groundwork for a subsequent patch which adds a new sentinel
pidfd to explicitly reference the current process (i.e. thread group
leader) without the need for a pidfd.

Reviewed-by: Shakeel Butt 
Signed-off-by: Lorenzo Stoakes 
---
 include/linux/pid.h | 30 +-
 kernel/pid.c| 42 --
 kernel/signal.c | 29 ++---
 3 files changed, 59 insertions(+), 42 deletions(-)

diff --git a/include/linux/pid.h b/include/linux/pid.h
index a3aad9b4074c..d466890e1b35 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -2,6 +2,7 @@
 #ifndef _LINUX_PID_H
 #define _LINUX_PID_H
 
+#include 
 #include 
 #include 
 #include 
@@ -72,8 +73,35 @@ extern struct pid init_struct_pid;
 
 struct file;
 
+
+/**
+ * __pidfd_get_pid() - Retrieve a pid associated with the specified pidfd.
+ *
+ * @pidfd:  The pidfd whose pid we want, or the fd of a /proc/ file if
+ *  @alloc_proc is also set.
+ * @allow_proc: If set, then an fd of a /proc/ file can be passed instead
+ *  of a pidfd, and this will be used to determine the pid.
+ * @flags:  Output variable, if non-NULL, then the file->f_flags of the
+ *  pidfd will be set here.
+ *
+ * Returns: If successful, the pid associated with the pidfd, otherwise an
+ *  error.
+ */
+struct pid *__pidfd_get_pid(unsigned int pidfd, bool allow_proc,
+   unsigned int *flags);
+
+static inline struct pid *pidfd_get_pid(unsigned int pidfd, unsigned int 
*flags)
+{
+   return __pidfd_get_pid(pidfd, /* allow_proc = */ false, flags);
+}
+
+static inline struct pid *pidfd_get_pid_proc(unsigned int pidfd,
+unsigned int *flags)
+{
+   return __pidfd_get_pid(pidfd, /* allow_proc = */ true, flags);
+}
+
 struct pid *pidfd_pid(const struct file *file);
-struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags);
 struct task_struct *pidfd_get_task(int pidfd, unsigned int *flags);
 int pidfd_prepare(struct pid *pid, unsigned int flags, struct file **ret);
 void do_notify_pidfd(struct task_struct *task);
diff --git a/kernel/pid.c b/kernel/pid.c
index 2715afb77eab..94c97559e5c5 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -534,22 +535,32 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns)
 }
 EXPORT_SYMBOL_GPL(find_ge_pid);
 
-struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags)
+struct pid *__pidfd_get_pid(unsigned int pidfd, bool allow_proc,
+   unsigned int *flags)
 {
-   struct fd f;
struct pid *pid;
+   struct fd f = fdget(pidfd);
+   struct file *file = fd_file(f);
 
-   f = fdget(fd);
-   if (!fd_file(f))
+   if (!file)
return ERR_PTR(-EBADF);
 
-   pid = pidfd_pid(fd_file(f));
-   if (!IS_ERR(pid)) {
-   get_pid(pid);
-   *flags = fd_file(f)->f_flags;
+   pid = pidfd_pid(file);
+   /* If we allow opening a pidfd via /proc/, do so. */
+   if (IS_ERR(pid) && allow_proc)
+   pid = tgid_pidfd_to_pid(file);
+
+   if (IS_ERR(pid)) {
+   fdput(f);
+   return pid;
}
 
+   /* Pin pid before we release fd. */
+   get_pid(pid);
+   if (flags)
+   *flags = file->f_flags;
fdput(f);
+
return pid;
 }
 
@@ -747,23 +758,18 @@ SYSCALL_DEFINE3(pidfd_getfd, int, pidfd, int, fd,
unsigned int, flags)
 {
struct pid *pid;
-   struct fd f;
int ret;
 
/* flags is currently unused - make sure it's unset */
if (flags)
return -EINVAL;
 
-   f = fdget(pidfd);
-   if (!fd_file(f))
-   return -EBADF;
-
-   pid = pidfd_pid(fd_file(f));
+   pid = pidfd_get_pid(pidfd, NULL);
if (IS_ERR(pid))
-   ret = PTR_ERR(pid);
-   else
-   ret = pidfd_getfd(pid, fd);
+   return PTR_ERR(pid);
 
-   fdput(f);
+   ret = pidfd_getfd(pid, fd);
+
+   put_pid(pid);
return ret;
 }
diff --git a/kernel/signal.c b/kernel/signal.c
index 4344860ffcac..9a35b1cf40ad 100644
--- a/kernel/signal.c
+++ b/kerne

Re: [PATCH net-next v10 09/23] ovpn: implement basic RX path (UDP)

2024-10-26 Thread kernel test robot
Hi Antonio,

kernel test robot noticed the following build errors:

[auto build test ERROR on 03fc07a24735e0be8646563913abf5f5cb71ad19]

url:
https://github.com/intel-lab-lkp/linux/commits/Antonio-Quartulli/netlink-add-NLA_POLICY_MAX_LEN-macro/20241025-173611
base:   03fc07a24735e0be8646563913abf5f5cb71ad19
patch link:
https://lore.kernel.org/r/20241025-b4-ovpn-v10-9-b87530777be7%40openvpn.net
patch subject: [PATCH net-next v10 09/23] ovpn: implement basic RX path (UDP)
config: m68k-randconfig-r072-20241027 
(https://download.01.org/0day-ci/archive/20241027/202410270433.eqtw7j8w-...@intel.com/config)
compiler: m68k-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20241027/202410270433.eqtw7j8w-...@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/202410270433.eqtw7j8w-...@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/asm-generic/bug.h:5,
from arch/m68k/include/asm/bug.h:32,
from include/linux/bug.h:5,
from include/linux/random.h:6,
from include/linux/net.h:18,
from drivers/net/ovpn/socket.c:10:
   drivers/net/ovpn/socket.c: In function 'ovpn_from_udp_sock':
>> drivers/net/ovpn/socket.c:84:32: error: implicit declaration of function 
>> 'udp_sk' [-Wimplicit-function-declaration]
  84 | if (unlikely(READ_ONCE(udp_sk(sk)->encap_type) != 
UDP_ENCAP_OVPNINUDP))
 |^~
   include/linux/compiler.h:77:45: note: in definition of macro 'unlikely'
  77 | # define unlikely(x)__builtin_expect(!!(x), 0)
 | ^
   include/linux/compiler_types.h:505:9: note: in expansion of macro 
'__compiletime_assert'
 505 | __compiletime_assert(condition, msg, prefix, suffix)
 | ^~~~
   include/linux/compiler_types.h:517:9: note: in expansion of macro 
'_compiletime_assert'
 517 | _compiletime_assert(condition, msg, __compiletime_assert_, 
__COUNTER__)
 | ^~~
   include/asm-generic/rwonce.h:36:9: note: in expansion of macro 
'compiletime_assert'
  36 | compiletime_assert(__native_word(t) || sizeof(t) == 
sizeof(long long),  \
 | ^~
   include/asm-generic/rwonce.h:36:28: note: in expansion of macro 
'__native_word'
  36 | compiletime_assert(__native_word(t) || sizeof(t) == 
sizeof(long long),  \
 |^
   include/asm-generic/rwonce.h:49:9: note: in expansion of macro 
'compiletime_assert_rwonce_type'
  49 | compiletime_assert_rwonce_type(x);   
   \
 | ^~
   drivers/net/ovpn/socket.c:84:22: note: in expansion of macro 'READ_ONCE'
  84 | if (unlikely(READ_ONCE(udp_sk(sk)->encap_type) != 
UDP_ENCAP_OVPNINUDP))
 |  ^
>> drivers/net/ovpn/socket.c:84:42: error: invalid type argument of '->' (have 
>> 'int')
  84 | if (unlikely(READ_ONCE(udp_sk(sk)->encap_type) != 
UDP_ENCAP_OVPNINUDP))
 |  ^~
   include/linux/compiler.h:77:45: note: in definition of macro 'unlikely'
  77 | # define unlikely(x)__builtin_expect(!!(x), 0)
 | ^
   include/linux/compiler_types.h:505:9: note: in expansion of macro 
'__compiletime_assert'
 505 | __compiletime_assert(condition, msg, prefix, suffix)
 | ^~~~
   include/linux/compiler_types.h:517:9: note: in expansion of macro 
'_compiletime_assert'
 517 | _compiletime_assert(condition, msg, __compiletime_assert_, 
__COUNTER__)
 | ^~~
   include/asm-generic/rwonce.h:36:9: note: in expansion of macro 
'compiletime_assert'
  36 | compiletime_assert(__native_word(t) || sizeof(t) == 
sizeof(long long),  \
 | ^~
   include/asm-generic/rwonce.h:36:28: note: in expansion of macro 
'__native_word'
  36 | compiletime_assert(__native_word(t) || sizeof(t) == 
sizeof(long long),  \
 |^
   include/asm-generic/rwonce.h:49:9: note: in expansion of macro 
'compiletime_assert_rwonce_type'
  49 | compiletime_assert_rwonce_type(x);   
   \
 | ^~
   drivers/net/ovpn/socket.c:84:22: note: in expansion of macro 'READ_ONCE'
  84 | if (unlikely(READ_ONCE(udp_sk(sk)->encap_type) != 
UDP_ENCAP_OVPNINUDP))
 |  ^
>> drive